DappJson

object DappJson

Wire codec for the CIP-0103 types, written against OpenRPC 0.5.0.

Hand-written over kotlinx-serialization's JsonElement API rather than generated from @Serializable: no compiler plugin, no reflection, and therefore nothing for R8 to strip on Android — the same choice :canton-wallet-sdk made for the registry APIs.

Encoding rule, applied throughout: omit absent optionals, never emit null for them. A wallet that emits "reason": null is not wrong by JSON-RPC, but round-tripping it changes the document, and the golden vectors in testdata/dapp/ assert that decode-then-encode is a fixpoint. Decoding is the tolerant direction — an explicit null reads as absent.

Every decode… throws DappException with DappErrorCode.INVALID_PARAMS, naming the field that was missing or of the wrong shape; every encode… is total.

Functions

Link copied to clipboard
fun decodeAccounts(json: JsonElement): List<DappWallet>

Decodes a ListAccountsResult.

Link copied to clipboard
fun decodeConnectResult(json: JsonElement): ConnectResult

Decodes a ConnectResult.

Link copied to clipboard
fun decodeEvent(notification: JsonRpcRequest): DappEvent?

Decodes a notification into a DappEvent, or null when notification names a method that is not an event. Null rather than an exception: an unknown notification is something to ignore, not something to fail a session over.

Link copied to clipboard

Decodes a prepareExecuteAndWaitResult, insisting the nested tx is in the executed state — any other state there is a protocol error.

Link copied to clipboard

Decodes LedgerApiRequest params. An unknown requestMethod is rejected.

Link copied to clipboard

Decodes a MessageSignatureEvent, picking the sealed case from status. An unknown status is rejected.

Link copied to clipboard
fun decodeNetwork(json: JsonElement): DappNetwork

Decodes a Network.

Link copied to clipboard

Decodes JsPrepareSubmissionRequest params; absent lists read as empty.

Link copied to clipboard

Decodes a JsPrepareSubmissionResponse.

Link copied to clipboard
fun decodeProvider(json: JsonElement): DappProvider

Decodes a Provider. An unknown providerType is rejected rather than dropped.

Link copied to clipboard
fun decodeSessionInfo(json: JsonElement): DappSessionInfo

Decodes a Session.

Link copied to clipboard

Decodes SignMessageRequest params.

Link copied to clipboard

Decodes a SignMessageResult.

Link copied to clipboard
fun decodeStatus(json: JsonElement): DappStatus

Decodes a StatusEvent.

Link copied to clipboard
fun decodeTxChanged(json: JsonElement): TxChangedEvent

Decodes a TxChangedEvent, picking the sealed case from status. An unknown status is rejected.

Link copied to clipboard
fun decodeWallet(json: JsonElement): DappWallet

Decodes one Wallet. An unknown status is rejected rather than dropped.

Link copied to clipboard
fun encode(value: ConnectResult): JsonObject

Encodes a ConnectResult.

fun encode(value: DappNetwork): JsonObject

Encodes a Network.

fun encode(value: DappProvider): JsonObject

Encodes a Provider.

fun encode(value: DappSessionInfo): JsonObject

Encodes a Session.

fun encode(value: DappStatus): JsonObject

Encodes a StatusEvent, nesting the provider, connection, network and session shapes.

fun encode(value: DappWallet): JsonObject

Encodes one Wallet.

fun encode(value: LedgerApiRequest): JsonObject

Encodes LedgerApiRequest params; body, query and path are passed through as raw JSON.

fun encode(value: MessageSignatureEvent): JsonObject

Encodes a MessageSignatureEvent; signature is present only for signed.

fun encode(value: PrepareSubmission): JsonObject

Encodes JsPrepareSubmissionRequest params. Empty party and package lists are omitted, not emitted as [].

fun encode(value: PrepareSubmissionResult): JsonObject

Encodes a JsPrepareSubmissionResponse.

fun encode(value: SignMessageRequest): JsonObject

Encodes SignMessageRequest params.

fun encode(value: SignMessageResult): JsonObject

Encodes a SignMessageResult.

fun encode(value: TxChangedEvent): JsonObject

Encodes a TxChangedEvent: status and commandId always, payload only for signed and executed.

Link copied to clipboard
fun encodeAccounts(value: List<DappWallet>): JsonArray

Encodes a ListAccountsResult: an array of Wallet.

Link copied to clipboard

A wallet-to-dApp event as a JSON-RPC notification. The event name is the notification's method, and its payload is params.

Link copied to clipboard

prepareExecuteAndWaitResult — an executed txChanged under tx.