@partylayer/sdk 0.18.2 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,30 +1,10 @@
1
1
  # @partylayer/sdk
2
2
 
3
- <div align="center">
3
+ The framework-independent Canton wallet client. Discover supported wallets, connect through a shared API and use the connected wallet's capabilities. Reviewed wallet runtimes are included and load as needed.
4
4
 
5
- **The unified SDK for connecting dApps to Canton Network wallets**
5
+ [Documentation](https://partylayer.xyz/docs/vanilla-js) · [API reference](https://github.com/PartyLayer/PartyLayer/blob/main/docs/api.md) · [Wallets](https://partylayer.xyz/wallets)
6
6
 
7
- [![npm version](https://img.shields.io/npm/v/@partylayer/sdk.svg?style=flat-square)](https://www.npmjs.com/package/@partylayer/sdk)
8
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg?style=flat-square)](https://www.typescriptlang.org/)
9
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
10
-
11
- </div>
12
-
13
- ---
14
-
15
- ## Overview
16
-
17
- `@partylayer/sdk` provides a unified interface for connecting your decentralized application (dApp) to multiple Canton Network wallets. It abstracts wallet-specific implementations behind a simple, type-safe API, one integration for every Canton wallet.
18
-
19
- ### Features
20
-
21
- - **Multi-Wallet Support**: one integration for every wallet in the Canton registry (eight today, including Console, Send, 5N Loop, Cantor8, Nightly, Bron, Walley, and WalletConnect)
22
- - **Zero Configuration**: Works out of the box with sensible defaults
23
- - **Type-Safe**: Full TypeScript support with strict mode
24
- - **Secure**: Encrypted session storage with origin binding
25
- - **Event-Driven**: Subscribe to connection, transaction, and error events
26
-
27
- ---
7
+ > This guide covers **0.20.0+**. See [release validation](https://github.com/PartyLayer/PartyLayer/blob/main/docs/releasing.md#default-wallet-release-validation) for acceptance scope and release status.
28
8
 
29
9
  ## Installation
30
10
 
@@ -32,258 +12,122 @@
32
12
  npm install @partylayer/sdk
33
13
  ```
34
14
 
35
- For React applications, also install the React integration:
15
+ React apps should use the ready-made kit instead. This single command includes the SDK and wallet runtimes:
36
16
 
37
17
  ```bash
38
- npm install @partylayer/sdk @partylayer/react
18
+ npm install @partylayer/react @tanstack/react-query
39
19
  ```
40
20
 
41
- ---
42
-
43
- ## Quick Start
21
+ See [the React quick start](https://partylayer.xyz/docs/quick-start). No separate PartyLayer wallet packages are required.
44
22
 
45
- ### 1. Create a Client
23
+ ## Quick start
46
24
 
47
- ```typescript
25
+ ```ts
48
26
  import { createPartyLayer } from '@partylayer/sdk';
49
27
 
50
28
  const client = createPartyLayer({
51
29
  network: 'devnet',
52
30
  app: { name: 'My dApp' },
53
31
  });
54
- ```
55
32
 
56
- ### 2. Connect to a Wallet
57
-
58
- ```typescript
59
- // List available wallets
60
33
  const wallets = await client.listWallets();
61
- console.log('Available wallets:', wallets.map(w => w.name));
62
-
63
- // Connect to a specific wallet
64
- const session = await client.connect({ walletId: 'console' });
65
- console.log('Connected! Party ID:', session.partyId);
66
- ```
34
+ for (const wallet of wallets) {
35
+ console.log(wallet.walletId, wallet.name, wallet.capabilities);
36
+ }
67
37
 
68
- ### 3. Sign Messages & Transactions
38
+ // Render these entries in your picker. Start connect from its click handler:
39
+ // await client.connect({ walletId: selectedWallet.walletId });
69
40
 
70
- ```typescript
71
- // Sign a message
72
- const { signature } = await client.signMessage({
73
- message: 'Authorize login to My dApp',
41
+ client.on('session:connected', ({ session }) => {
42
+ console.log('Party:', session.partyId);
43
+ console.log('Capabilities:', session.capabilitiesSnapshot);
74
44
  });
75
45
 
76
- // Sign a transaction
77
- const { signedTx, transactionHash } = await client.signTransaction({
78
- tx: myTransaction,
79
- });
80
-
81
- // Submit a transaction
82
- const receipt = await client.submitTransaction({
83
- signedTx,
84
- });
46
+ // Read current/restored state; a cache alone does not establish a live connection.
47
+ const session = await client.getActiveSession();
48
+ console.log(session?.partyId);
85
49
  ```
86
50
 
87
- ### 4. Listen to Events
51
+ Use one client for the lifetime of your application integration. Call `await client.disconnect()` for an explicit logout and `client.destroy()` when disposing an application-owned client. `PartyLayerKit` handles client disposal for React.
88
52
 
89
- ```typescript
90
- // Connection events
91
- client.on('session:connected', (event) => {
92
- console.log('Connected:', event.session.partyId);
93
- });
94
-
95
- client.on('session:disconnected', () => {
96
- console.log('Disconnected');
97
- });
53
+ ## Configuration
98
54
 
99
- // Transaction events
100
- client.on('tx:status', (event) => {
101
- console.log('Transaction status:', event.status);
102
- });
55
+ ```ts
56
+ const walletConnect = { projectId: 'YOUR_PROJECT_ID' };
103
57
 
104
- // Error events
105
- client.on('error', (event) => {
106
- console.error('Error:', event.error.message);
58
+ const client = createPartyLayer({
59
+ network: 'devnet',
60
+ app: { name: 'My dApp' },
61
+ channel: 'stable',
62
+ walletConnect,
107
63
  });
108
64
  ```
109
65
 
110
- ### 5. Disconnect
66
+ | Option | Effect |
67
+ | --- | --- |
68
+ | `network` | Required: `devnet`, `testnet` or `mainnet`; filters the catalog |
69
+ | `app.name` | Required: application name presented during connection |
70
+ | `channel` | `stable` by default; `beta` on Devnet includes Vala |
71
+ | `walletConnect` | Project ID and optional pairing metadata; omitted means hidden |
72
+ | `bron` | Application-owned OAuth/API configuration; omitted means hidden |
73
+ | `additionalAdapters` | Extends the included catalog |
74
+ | `adapters` | Replaces the included catalog |
75
+ | `registryUrl` | Defaults to `https://registry.partylayer.xyz` |
111
76
 
112
- ```typescript
113
- await client.disconnect();
114
- ```
77
+ Hosted wallets require the user's own login and approval. Send is Mainnet-only in the catalog. See [configuration and wallet limits](https://partylayer.xyz/docs/wallets).
115
78
 
116
- ---
79
+ ## Supported wallets
117
80
 
118
- ## Supported Wallets
81
+ Generated from the stable registry and active SDK integrations. This is capability metadata, not evidence that every live wallet journey passed.
119
82
 
120
83
  <!-- WALLETS:START (generated by scripts/gen-readme.mjs, do not edit) -->
121
- | Wallet | Networks | Capabilities | Opt-in | Adapter |
84
+ | Wallet | Networks | Capabilities | Opt-in | Additional setup |
122
85
  |--------|----------|--------------|--------|---------|
123
- | Console Wallet | devnet, testnet, mainnet | signMessage, signTransaction, submitTransaction, transactionStatus | No | `@partylayer/adapter-console` |
124
- | 5N Loop | devnet, mainnet | signMessage, submitTransaction, transactionStatus | No | `@partylayer/adapter-loop` |
125
- | Cantor8 | devnet, mainnet | submitTransaction, transactionStatus | No | `@partylayer/adapter-cantor8` |
126
- | Bron | devnet, testnet, mainnet | signMessage, signTransaction | Yes | `@partylayer/adapter-bron` |
127
- | Nightly | devnet, testnet, mainnet | signMessage, submitTransaction | No | `@partylayer/adapter-nightly` |
128
- | Send | mainnet | signMessage, submitTransaction, transactionStatus | No | `@partylayer/adapter-send` |
129
- | Walley | mainnet, testnet, devnet | signMessage, submitTransaction, transactionStatus | No | `@k2flabs/walley-dapp-sdk` |
130
- | WalletConnect | devnet, testnet, mainnet | signMessage, submitTransaction | Yes | `@partylayer/adapter-walletconnect` |
86
+ | Console Wallet | devnet, testnet, mainnet | signMessage, submitTransaction, restore | No | Included |
87
+ | 5N Loop | devnet, mainnet | signMessage, submitTransaction, ledgerApi, restore, events | No | Included |
88
+ | Cantor8 | devnet, mainnet | submitTransaction, events | No | Included |
89
+ | Bron | devnet, testnet, mainnet | signMessage, signTransaction, ledgerApi, restore | Yes | Your OAuth/API configuration |
90
+ | Nightly | devnet, testnet, mainnet | signMessage, submitTransaction, ledgerApi, restore, events | No | Included |
91
+ | Cauri Wallet | devnet, mainnet | signMessage, submitTransaction | No | Included |
92
+ | OneSwap V2 Wallet | devnet, mainnet | signMessage, submitTransaction | No | Included |
93
+ | Send | mainnet | signMessage, submitTransaction, ledgerApi, restore, events | No | Included |
94
+ | Walley | mainnet, testnet, devnet | signMessage, submitTransaction | No | Included |
95
+ | WalletConnect | devnet, testnet, mainnet | signMessage, submitTransaction, ledgerApi, restore, events | Yes | Your project ID |
131
96
  <!-- WALLETS:END -->
132
97
 
133
- > **Try it live:** [PartyLayer Studio](https://studio.partylayer.xyz), runnable, editable scenarios · [Pattern Cookbook](https://partylayer.xyz/docs/cookbook), copy-paste recipes.
98
+ Vala is an additional Devnet **beta** entry, enabled with `channel: 'beta'`. The [integration matrix](https://github.com/PartyLayer/PartyLayer/blob/main/docs/wallet-cip0103-matrix.md) records integration paths, reviewed versions and restrictions.
134
99
 
135
- ---
100
+ ## Message signing and authentication
136
101
 
137
- ## Configuration
102
+ Call `signMessage` only when the connected session supports it:
138
103
 
139
- ```typescript
140
- const client = createPartyLayer({
141
- // Required
142
- network: 'devnet', // 'devnet' | 'testnet' | 'mainnet'
143
- app: {
144
- name: 'My dApp',
145
- origin: 'https://mydapp.com', // Optional, defaults to window.location.origin
146
- },
147
-
148
- // Optional
149
- registryUrl: 'https://registry.partylayer.xyz/v1/wallets.json', // Default
150
- channel: 'stable', // 'stable' | 'beta'
151
-
152
- // Advanced: Custom adapters
153
- adapters: [
154
- ...getBuiltinAdapters(),
155
- new BronAdapter({ auth: {...}, api: {...} }),
156
- ],
157
- });
158
- ```
159
-
160
- ---
161
-
162
- ## API Reference
163
-
164
- ### `createPartyLayer(config)`
165
-
166
- Creates a new PartyLayer client instance.
167
-
168
- ### Client Methods
169
-
170
- | Method | Description | Returns |
171
- |--------|-------------|---------|
172
- | `listWallets(filter?)` | List available wallets | `Promise<WalletInfo[]>` |
173
- | `connect(options?)` | Connect to a wallet | `Promise<Session>` |
174
- | `disconnect()` | Disconnect current session | `Promise<void>` |
175
- | `getActiveSession()` | Get active session | `Promise<Session \| null>` |
176
- | `signMessage(params)` | Sign an arbitrary message | `Promise<SignedMessage>` |
177
- | `signTransaction(params)` | Sign a transaction | `Promise<SignedTransaction>` |
178
- | `submitTransaction(params)` | Submit signed transaction | `Promise<TxReceipt>` |
179
- | `on(event, handler)` | Subscribe to events | `() => void` (unsubscribe) |
180
- | `off(event, handler)` | Unsubscribe from events | `void` |
181
- | `destroy()` | Cleanup client resources | `void` |
182
-
183
- ### Events
184
-
185
- | Event | Description |
186
- |-------|-------------|
187
- | `session:connected` | Wallet connected successfully |
188
- | `session:disconnected` | Wallet disconnected |
189
- | `session:expired` | Session has expired |
190
- | `tx:status` | Transaction status update |
191
- | `registry:status` | Registry status change |
192
- | `error` | Error occurred |
193
-
194
- ---
195
-
196
- ## Error Handling
197
-
198
- ```typescript
199
- import {
200
- WalletNotFoundError,
201
- WalletNotInstalledError,
202
- UserRejectedError,
203
- SessionExpiredError,
204
- TimeoutError,
205
- } from '@partylayer/sdk';
206
-
207
- try {
208
- await client.connect({ walletId: 'console' });
209
- } catch (error) {
210
- if (error instanceof WalletNotInstalledError) {
211
- console.log('Please install the wallet extension');
212
- } else if (error instanceof UserRejectedError) {
213
- console.log('User rejected the connection request');
214
- } else if (error instanceof TimeoutError) {
215
- console.log('Connection timed out');
216
- }
104
+ ```ts
105
+ const session = await client.getActiveSession();
106
+ if (session?.capabilitiesSnapshot.includes('signMessage')) {
107
+ const result = await client.signMessage({ message: 'Hello, Canton!' });
108
+ console.log(result.signature);
217
109
  }
218
110
  ```
219
111
 
220
- ---
221
-
222
- ## Using Bron (Enterprise Wallet)
223
-
224
- Bron requires OAuth2 configuration:
112
+ A returned signature is not a server login. Authentication needs a backend-generated challenge, single-use nonce, origin binding and independent verification against an authorized party key. See [authentication](https://partylayer.xyz/docs/authentication).
225
113
 
226
- ```typescript
227
- import { createPartyLayer, BronAdapter, getBuiltinAdapters } from '@partylayer/sdk';
114
+ ## Transactions
228
115
 
229
- const client = createPartyLayer({
230
- network: 'devnet',
231
- app: { name: 'My dApp' },
232
- adapters: [
233
- ...getBuiltinAdapters(),
234
- new BronAdapter({
235
- auth: {
236
- clientId: 'your-client-id',
237
- redirectUri: 'https://your-app.com/auth/callback',
238
- authorizationUrl: 'https://auth.bron.example/authorize',
239
- tokenUrl: 'https://auth.bron.example/token',
240
- },
241
- api: {
242
- baseUrl: 'https://api.bron.example',
243
- getAccessToken: async () => getStoredAccessToken(),
244
- },
245
- }),
246
- ],
247
- });
248
- ```
249
-
250
- ---
251
-
252
- ## TypeScript
253
-
254
- This package is written in TypeScript and includes type definitions. All types are exported:
255
-
256
- ```typescript
257
- import type {
258
- Session,
259
- WalletInfo,
260
- SignedMessage,
261
- SignedTransaction,
262
- TxReceipt,
263
- PartyLayerConfig,
264
- ConnectOptions,
265
- } from '@partylayer/sdk';
266
- ```
116
+ There is no universal sign-then-submit sequence across Canton wallets. Some wallets combine approval and submission; others expose a separate signing operation or native CIP-0103 `prepareExecute`. Inspect capabilities and follow the wallet's command contract.
267
117
 
268
- ---
118
+ Your app constructs valid commands and independently confirms ledger settlement. A command ID, a resolved Promise or message signature is not proof of a successful transfer/swap. Uncertain outcomes must be reconciled without automatically submitting again. See [transaction lifecycle](https://partylayer.xyz/docs/transaction-lifecycle) and [token transfers](https://partylayer.xyz/docs/token-transfers).
269
119
 
270
- ## Related Packages
120
+ ## Native CIP-0103 provider and migration
271
121
 
272
- | Package | Description |
273
- |---------|-------------|
274
- | [@partylayer/react](https://www.npmjs.com/package/@partylayer/react) | React hooks and components |
275
- | [@partylayer/core](https://www.npmjs.com/package/@partylayer/core) | Core types and abstractions |
122
+ Use `client.asProvider()` for the connected provider surface. Native connections use official Canton discovery and forward native accounts, events and Ledger API requests through a stable facade. Native Ledger API responses are **raw JSON**. Existing `client.ledgerApi()` and explicit `createProviderBridge(client)` compatibility paths retain their documented wrapper/limits.
276
123
 
277
- ---
124
+ Existing native caches without the official provider hint need one explicit reconnect. Restored state must agree with the wallet's live party, network, origin and expiry. See [protocol ownership and migration](https://github.com/PartyLayer/PartyLayer/blob/main/docs/protocol-ownership.md).
278
125
 
279
- ## Links
126
+ ## Errors and cleanup
280
127
 
281
- - [GitHub Repository](https://github.com/PartyLayer/PartyLayer)
282
- - [Documentation](https://github.com/PartyLayer/PartyLayer#readme)
283
- - [Report Issues](https://github.com/PartyLayer/PartyLayer/issues)
284
- - [Canton Network](https://www.canton.network/)
128
+ Handle user rejection, unavailable wallets, timeouts, network mismatch and unsupported capabilities as separate application states. Do not silently retry a ledger write after an ambiguous error. See [error handling](https://partylayer.xyz/docs/error-handling).
285
129
 
286
- ---
130
+ `client.on(event, handler)` returns an unsubscribe function. Release subscriptions and destroy clients you create when their owner is disposed. Never call `destroy()` on the client managed by a still-mounted React kit.
287
131
 
288
132
  ## License
289
133