@k2flabs/walley-dapp-sdk
v1.0.2
Published
Walley provider adapter for @canton-network/dapp-sdk. Lets dapps connect to the Walley self-custodial wallet on Canton Network.
Readme
@k2flabs/walley-dapp-sdk
A provider adapter that lets dapps connect to Walley, a self-custodial wallet for Canton Network.
This package plugs into @canton-network/dapp-sdk as a provider. It opens a popup to walley.cc to handle connect, sign, and prepare/execute flows.
Install
npm install @k2flabs/walley-dapp-sdk @canton-network/dapp-sdkUsage
Register the adapter with the dapp-sdk discovery registry:
import { WalleyAdapter } from "@k2flabs/walley-dapp-sdk";
import { DiscoveryRegistry } from "@canton-network/dapp-sdk";
const registry = new DiscoveryRegistry();
registry.register(new WalleyAdapter());To point at a non-default Walley host (for example a local instance):
new WalleyAdapter({ host: "http://localhost:5173" });API Reference
All methods are called via provider.request({ method, params? }) using the standard Canton Provider interface.
connect
Opens a popup to Walley where the user approves the connection. Returns connection status and persists the session to localStorage.
const result = await provider.request({ method: "connect" });
// { isConnected: true, isNetworkConnected: true }disconnect
Clears the active session and removes it from localStorage. Returns null.
await provider.request({ method: "disconnect" });status
Returns the current provider, connection, network, and session state without opening a popup.
const status = await provider.request({ method: "status" });
// {
// provider: { id: "walley", providerType: "browser", userUrl: string },
// connection: { isConnected: boolean, isNetworkConnected: boolean },
// network?: { networkId: string },
// session?: { accessToken: string, userId: string }
// }listAccounts
Returns an array of wallets. When connected, contains a single wallet entry; empty when disconnected.
const accounts = await provider.request({ method: "listAccounts" });
// Wallet[]getPrimaryAccount
Returns the connected wallet. Throws rpcErrors.internal if not connected.
const wallet = await provider.request({ method: "getPrimaryAccount" });
// {
// primary: true,
// partyId: string,
// status: "allocated",
// hint: string,
// publicKey: string,
// namespace: string,
// networkId: string,
// signingProviderId: "walley"
// }getActiveNetwork
Returns the network the wallet is connected to. Throws rpcErrors.internal if not connected.
const network = await provider.request({ method: "getActiveNetwork" });
// { networkId: string }signMessage
Opens a popup for the user to sign an arbitrary message.
const result = await provider.request({
method: "signMessage",
params: { message: "Hello from my dApp!" },
});
// SignMessageResultprepareExecute
Opens a popup for the user to review, sign, and submit Daml commands. Returns null on success (fire-and-forget).
await provider.request({
method: "prepareExecute",
params: { commands: [{ type: "create", templateId: "...", argument: { ... } }] },
});prepareExecuteAndWait
Same as prepareExecute but waits for the transaction to be committed and returns the result.
const result = await provider.request({
method: "prepareExecuteAndWait",
params: { commands: [{ type: "create", templateId: "...", argument: { ... } }] },
});
// PrepareExecuteAndWaitResultTypes
The SDK exports the following:
| Export | Kind | Description |
|---|---|---|
| WalleyAdapter | class | ProviderAdapter implementation — register with DiscoveryRegistry |
| WalleyAdapterConfig | type | { host?: string } — defaults to https://walley.cc |
| WalleyProvider | class | The underlying Provider<DappRpcTypes> — rarely used directly |
| ConnectResult | type | Session data: partyId, partyHint, publicKeyFingerprint, publicKeyBase64, networkId |
Notes
- All interactions go through a popup window. Dapps should call adapter methods in response to a user gesture so the popup is not blocked by the browser.
- Sessions are persisted to
localStorageand restored automatically on the next page load, until the dapp callsdisconnect().
