DappSession

class DappSession(peer: DappPeer, accounts: DappAccountsSource, approver: DappApprovalDelegate, network: DappNetworkConfig, provider: DappProvider = DEFAULT_PROVIDER, messageSigner: DappMessageSigner? = null, prepareExecute: PrepareExecutePipeline? = null, ledgerApi: LedgerApiProxy? = null, ledgerApiPolicy: LedgerApiPolicy = LedgerApiPolicy.ReadOnly, signMessageMinInterval: Duration = 1.seconds, timeSource: TimeSource = TimeSource.Monotonic, spendPolicy: () -> DappSpendPolicy? = { null }, spendLedger: SpendLedger = InMemorySpendLedger(), wallClock: () -> Instant = java.time.Instant::now, activityObserver: DappActivityObserver? = null) : DappRequestHandler

One dApp's session with the wallet: the CIP-0103 provider side.

A session is per-peer and holds that peer's grant — the accounts the user approved for it. Two dApps talking to the same wallet get two sessions and cannot see each other's accounts, which is the reason grants live here rather than in a global store.

val session = DappSession(peer, accounts, approver, network)
val response = session.handle(incomingFrame)

handle never throws for protocol-level failures — it returns a JSON-RPC error response, because a transport needs something to send back. It will propagate genuinely unexpected exceptions only after wrapping them as -32603.

Constructors

Link copied to clipboard
constructor(peer: DappPeer, accounts: DappAccountsSource, approver: DappApprovalDelegate, network: DappNetworkConfig, provider: DappProvider = DEFAULT_PROVIDER, messageSigner: DappMessageSigner? = null, prepareExecute: PrepareExecutePipeline? = null, ledgerApi: LedgerApiProxy? = null, ledgerApiPolicy: LedgerApiPolicy = LedgerApiPolicy.ReadOnly, signMessageMinInterval: Duration = 1.seconds, timeSource: TimeSource = TimeSource.Monotonic, spendPolicy: () -> DappSpendPolicy? = { null }, spendLedger: SpendLedger = InMemorySpendLedger(), wallClock: () -> Instant = java.time.Instant::now, activityObserver: DappActivityObserver? = null)

Types

Link copied to clipboard

Properties

Link copied to clipboard
open override val events: Flow<DappEvent>

Events for this peer only.

Functions

Link copied to clipboard

The accounts this peer may currently see. Empty until DappMethod.CONNECT is approved.

Link copied to clipboard
open suspend override fun handle(request: JsonRpcRequest): JsonRpcResponse

Dispatches one JSON-RPC frame.

open suspend override fun handle(request: JsonRpcRequest, context: DappRequestContext): JsonRpcResponse