@partylayer/sdk 0.19.0 → 0.20.1
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 +70 -228
- package/dist/index.d.mts +96 -86
- package/dist/index.d.ts +96 -86
- package/dist/index.js +1105 -148
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1107 -151
- package/dist/index.mjs.map +1 -1
- package/package.json +29 -13
package/README.md
CHANGED
|
@@ -1,30 +1,10 @@
|
|
|
1
1
|
# @partylayer/sdk
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
[
|
|
8
|
-
[](https://www.typescriptlang.org/)
|
|
9
|
-
[](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,260 +12,122 @@
|
|
|
32
12
|
npm install @partylayer/sdk
|
|
33
13
|
```
|
|
34
14
|
|
|
35
|
-
|
|
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/
|
|
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
|
-
|
|
23
|
+
## Quick start
|
|
46
24
|
|
|
47
|
-
```
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
38
|
+
// Render these entries in your picker. Start connect from its click handler:
|
|
39
|
+
// await client.connect({ walletId: selectedWallet.walletId });
|
|
69
40
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
//
|
|
77
|
-
const
|
|
78
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
console.log('Transaction status:', event.status);
|
|
102
|
-
});
|
|
55
|
+
```ts
|
|
56
|
+
const walletConnect = { projectId: 'YOUR_PROJECT_ID' };
|
|
103
57
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
58
|
+
const client = createPartyLayer({
|
|
59
|
+
network: 'devnet',
|
|
60
|
+
app: { name: 'My dApp' },
|
|
61
|
+
channel: 'stable',
|
|
62
|
+
walletConnect,
|
|
107
63
|
});
|
|
108
64
|
```
|
|
109
65
|
|
|
110
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 |
|
|
84
|
+
| Wallet | Networks | Capabilities | Opt-in | Additional setup |
|
|
122
85
|
|--------|----------|--------------|--------|---------|
|
|
123
|
-
| Console Wallet | devnet, testnet, mainnet | signMessage,
|
|
124
|
-
| 5N Loop | devnet, mainnet | signMessage, submitTransaction,
|
|
125
|
-
| Cantor8 | devnet, mainnet | submitTransaction,
|
|
126
|
-
| Bron | devnet, testnet, mainnet | signMessage, signTransaction | Yes |
|
|
127
|
-
| Nightly | devnet, testnet, mainnet | signMessage, submitTransaction | No |
|
|
128
|
-
| Cauri Wallet | devnet, mainnet | signMessage,
|
|
129
|
-
| OneSwap V2 Wallet | devnet, mainnet | signMessage, submitTransaction | No |
|
|
130
|
-
| Send | mainnet | signMessage, submitTransaction,
|
|
131
|
-
| Walley | mainnet, testnet, devnet | signMessage, submitTransaction
|
|
132
|
-
| WalletConnect | devnet, testnet, mainnet | signMessage, submitTransaction | Yes |
|
|
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 |
|
|
133
96
|
<!-- WALLETS:END -->
|
|
134
97
|
|
|
135
|
-
|
|
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.
|
|
136
99
|
|
|
137
|
-
|
|
100
|
+
## Message signing and authentication
|
|
138
101
|
|
|
139
|
-
|
|
102
|
+
Call `signMessage` only when the connected session supports it:
|
|
140
103
|
|
|
141
|
-
```
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
name: 'My dApp',
|
|
147
|
-
origin: 'https://mydapp.com', // Optional, defaults to window.location.origin
|
|
148
|
-
},
|
|
149
|
-
|
|
150
|
-
// Optional
|
|
151
|
-
registryUrl: 'https://registry.partylayer.xyz/v1/wallets.json', // Default
|
|
152
|
-
channel: 'stable', // 'stable' | 'beta'
|
|
153
|
-
|
|
154
|
-
// Advanced: Custom adapters
|
|
155
|
-
adapters: [
|
|
156
|
-
...getBuiltinAdapters(),
|
|
157
|
-
new BronAdapter({ auth: {...}, api: {...} }),
|
|
158
|
-
],
|
|
159
|
-
});
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
---
|
|
163
|
-
|
|
164
|
-
## API Reference
|
|
165
|
-
|
|
166
|
-
### `createPartyLayer(config)`
|
|
167
|
-
|
|
168
|
-
Creates a new PartyLayer client instance.
|
|
169
|
-
|
|
170
|
-
### Client Methods
|
|
171
|
-
|
|
172
|
-
| Method | Description | Returns |
|
|
173
|
-
|--------|-------------|---------|
|
|
174
|
-
| `listWallets(filter?)` | List available wallets | `Promise<WalletInfo[]>` |
|
|
175
|
-
| `connect(options?)` | Connect to a wallet | `Promise<Session>` |
|
|
176
|
-
| `disconnect()` | Disconnect current session | `Promise<void>` |
|
|
177
|
-
| `getActiveSession()` | Get active session | `Promise<Session \| null>` |
|
|
178
|
-
| `signMessage(params)` | Sign an arbitrary message | `Promise<SignedMessage>` |
|
|
179
|
-
| `signTransaction(params)` | Sign a transaction | `Promise<SignedTransaction>` |
|
|
180
|
-
| `submitTransaction(params)` | Submit signed transaction | `Promise<TxReceipt>` |
|
|
181
|
-
| `on(event, handler)` | Subscribe to events | `() => void` (unsubscribe) |
|
|
182
|
-
| `off(event, handler)` | Unsubscribe from events | `void` |
|
|
183
|
-
| `destroy()` | Cleanup client resources | `void` |
|
|
184
|
-
|
|
185
|
-
### Events
|
|
186
|
-
|
|
187
|
-
| Event | Description |
|
|
188
|
-
|-------|-------------|
|
|
189
|
-
| `session:connected` | Wallet connected successfully |
|
|
190
|
-
| `session:disconnected` | Wallet disconnected |
|
|
191
|
-
| `session:expired` | Session has expired |
|
|
192
|
-
| `tx:status` | Transaction status update |
|
|
193
|
-
| `registry:status` | Registry status change |
|
|
194
|
-
| `error` | Error occurred |
|
|
195
|
-
|
|
196
|
-
---
|
|
197
|
-
|
|
198
|
-
## Error Handling
|
|
199
|
-
|
|
200
|
-
```typescript
|
|
201
|
-
import {
|
|
202
|
-
WalletNotFoundError,
|
|
203
|
-
WalletNotInstalledError,
|
|
204
|
-
UserRejectedError,
|
|
205
|
-
SessionExpiredError,
|
|
206
|
-
TimeoutError,
|
|
207
|
-
} from '@partylayer/sdk';
|
|
208
|
-
|
|
209
|
-
try {
|
|
210
|
-
await client.connect({ walletId: 'console' });
|
|
211
|
-
} catch (error) {
|
|
212
|
-
if (error instanceof WalletNotInstalledError) {
|
|
213
|
-
console.log('Please install the wallet extension');
|
|
214
|
-
} else if (error instanceof UserRejectedError) {
|
|
215
|
-
console.log('User rejected the connection request');
|
|
216
|
-
} else if (error instanceof TimeoutError) {
|
|
217
|
-
console.log('Connection timed out');
|
|
218
|
-
}
|
|
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);
|
|
219
109
|
}
|
|
220
110
|
```
|
|
221
111
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
## Using Bron (Enterprise Wallet)
|
|
225
|
-
|
|
226
|
-
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).
|
|
227
113
|
|
|
228
|
-
|
|
229
|
-
import { createPartyLayer, BronAdapter, getBuiltinAdapters } from '@partylayer/sdk';
|
|
114
|
+
## Transactions
|
|
230
115
|
|
|
231
|
-
|
|
232
|
-
network: 'devnet',
|
|
233
|
-
app: { name: 'My dApp' },
|
|
234
|
-
adapters: [
|
|
235
|
-
...getBuiltinAdapters(),
|
|
236
|
-
new BronAdapter({
|
|
237
|
-
auth: {
|
|
238
|
-
clientId: 'your-client-id',
|
|
239
|
-
redirectUri: 'https://your-app.com/auth/callback',
|
|
240
|
-
authorizationUrl: 'https://auth.bron.example/authorize',
|
|
241
|
-
tokenUrl: 'https://auth.bron.example/token',
|
|
242
|
-
},
|
|
243
|
-
api: {
|
|
244
|
-
baseUrl: 'https://api.bron.example',
|
|
245
|
-
getAccessToken: async () => getStoredAccessToken(),
|
|
246
|
-
},
|
|
247
|
-
}),
|
|
248
|
-
],
|
|
249
|
-
});
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
---
|
|
253
|
-
|
|
254
|
-
## TypeScript
|
|
255
|
-
|
|
256
|
-
This package is written in TypeScript and includes type definitions. All types are exported:
|
|
257
|
-
|
|
258
|
-
```typescript
|
|
259
|
-
import type {
|
|
260
|
-
Session,
|
|
261
|
-
WalletInfo,
|
|
262
|
-
SignedMessage,
|
|
263
|
-
SignedTransaction,
|
|
264
|
-
TxReceipt,
|
|
265
|
-
PartyLayerConfig,
|
|
266
|
-
ConnectOptions,
|
|
267
|
-
} from '@partylayer/sdk';
|
|
268
|
-
```
|
|
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.
|
|
269
117
|
|
|
270
|
-
|
|
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).
|
|
271
119
|
|
|
272
|
-
##
|
|
120
|
+
## Native CIP-0103 provider and migration
|
|
273
121
|
|
|
274
|
-
|
|
275
|
-
|---------|-------------|
|
|
276
|
-
| [@partylayer/react](https://www.npmjs.com/package/@partylayer/react) | React hooks and components |
|
|
277
|
-
| [@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.
|
|
278
123
|
|
|
279
|
-
|
|
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).
|
|
280
125
|
|
|
281
|
-
##
|
|
126
|
+
## Errors and cleanup
|
|
282
127
|
|
|
283
|
-
|
|
284
|
-
- [Documentation](https://github.com/PartyLayer/PartyLayer#readme)
|
|
285
|
-
- [Report Issues](https://github.com/PartyLayer/PartyLayer/issues)
|
|
286
|
-
- [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).
|
|
287
129
|
|
|
288
|
-
|
|
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.
|
|
289
131
|
|
|
290
132
|
## License
|
|
291
133
|
|