@partylayer/sdk 0.2.4
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/LICENSE +21 -0
- package/README.md +282 -0
- package/dist/index.d.mts +343 -0
- package/dist/index.d.ts +343 -0
- package/dist/index.js +767 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +692 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 CantonConnect
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
# @partylayer/sdk
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
**The official SDK for connecting dApps to Canton Network wallets**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@partylayer/sdk)
|
|
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. Similar to WalletConnect, it abstracts wallet-specific implementations behind a simple, type-safe API.
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
- **Multi-Wallet Support**: Console, 5N Loop, Cantor8, and Bron wallets
|
|
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
|
+
---
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install @partylayer/sdk
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
For React applications, also install the React integration:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install @partylayer/sdk @partylayer/react
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Quick Start
|
|
44
|
+
|
|
45
|
+
### 1. Create a Client
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { createPartyLayer } from '@partylayer/sdk';
|
|
49
|
+
|
|
50
|
+
const client = createPartyLayer({
|
|
51
|
+
network: 'devnet',
|
|
52
|
+
app: { name: 'My dApp' },
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 2. Connect to a Wallet
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
// List available wallets
|
|
60
|
+
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
|
+
```
|
|
67
|
+
|
|
68
|
+
### 3. Sign Messages & Transactions
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
// Sign a message
|
|
72
|
+
const { signature } = await client.signMessage({
|
|
73
|
+
message: 'Authorize login to My dApp',
|
|
74
|
+
});
|
|
75
|
+
|
|
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
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 4. Listen to Events
|
|
88
|
+
|
|
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
|
+
});
|
|
98
|
+
|
|
99
|
+
// Transaction events
|
|
100
|
+
client.on('tx:status', (event) => {
|
|
101
|
+
console.log('Transaction status:', event.status);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Error events
|
|
105
|
+
client.on('error', (event) => {
|
|
106
|
+
console.error('Error:', event.error.message);
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 5. Disconnect
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
await client.disconnect();
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Supported Wallets
|
|
119
|
+
|
|
120
|
+
| Wallet | ID | Type | Auto-Registered |
|
|
121
|
+
|--------|-----|------|-----------------|
|
|
122
|
+
| Console Wallet | `console` | Browser Extension | ✅ Yes |
|
|
123
|
+
| 5N Loop | `loop` | Mobile / Web | ✅ Yes |
|
|
124
|
+
| Cantor8 | `cantor8` | Browser Extension | ✅ Yes |
|
|
125
|
+
| Bron | `bron` | Enterprise (OAuth) | ⚙️ Requires config |
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Configuration
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
const client = createPartyLayer({
|
|
133
|
+
// Required
|
|
134
|
+
network: 'devnet', // 'devnet' | 'testnet' | 'mainnet'
|
|
135
|
+
app: {
|
|
136
|
+
name: 'My dApp',
|
|
137
|
+
origin: 'https://mydapp.com', // Optional, defaults to window.location.origin
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
// Optional
|
|
141
|
+
registryUrl: 'https://registry.cantonconnect.xyz/v1/wallets.json', // Default
|
|
142
|
+
channel: 'stable', // 'stable' | 'beta'
|
|
143
|
+
|
|
144
|
+
// Advanced: Custom adapters
|
|
145
|
+
adapters: [
|
|
146
|
+
...getBuiltinAdapters(),
|
|
147
|
+
new BronAdapter({ auth: {...}, api: {...} }),
|
|
148
|
+
],
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## API Reference
|
|
155
|
+
|
|
156
|
+
### `createPartyLayer(config)`
|
|
157
|
+
|
|
158
|
+
Creates a new PartyLayer client instance.
|
|
159
|
+
|
|
160
|
+
### Client Methods
|
|
161
|
+
|
|
162
|
+
| Method | Description | Returns |
|
|
163
|
+
|--------|-------------|---------|
|
|
164
|
+
| `listWallets(filter?)` | List available wallets | `Promise<WalletInfo[]>` |
|
|
165
|
+
| `connect(options?)` | Connect to a wallet | `Promise<Session>` |
|
|
166
|
+
| `disconnect()` | Disconnect current session | `Promise<void>` |
|
|
167
|
+
| `getActiveSession()` | Get active session | `Promise<Session \| null>` |
|
|
168
|
+
| `signMessage(params)` | Sign an arbitrary message | `Promise<SignedMessage>` |
|
|
169
|
+
| `signTransaction(params)` | Sign a transaction | `Promise<SignedTransaction>` |
|
|
170
|
+
| `submitTransaction(params)` | Submit signed transaction | `Promise<TxReceipt>` |
|
|
171
|
+
| `on(event, handler)` | Subscribe to events | `() => void` (unsubscribe) |
|
|
172
|
+
| `off(event, handler)` | Unsubscribe from events | `void` |
|
|
173
|
+
| `destroy()` | Cleanup client resources | `void` |
|
|
174
|
+
|
|
175
|
+
### Events
|
|
176
|
+
|
|
177
|
+
| Event | Description |
|
|
178
|
+
|-------|-------------|
|
|
179
|
+
| `session:connected` | Wallet connected successfully |
|
|
180
|
+
| `session:disconnected` | Wallet disconnected |
|
|
181
|
+
| `session:expired` | Session has expired |
|
|
182
|
+
| `tx:status` | Transaction status update |
|
|
183
|
+
| `registry:status` | Registry status change |
|
|
184
|
+
| `error` | Error occurred |
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## Error Handling
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
import {
|
|
192
|
+
WalletNotFoundError,
|
|
193
|
+
WalletNotInstalledError,
|
|
194
|
+
UserRejectedError,
|
|
195
|
+
SessionExpiredError,
|
|
196
|
+
TimeoutError,
|
|
197
|
+
} from '@partylayer/sdk';
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
await client.connect({ walletId: 'console' });
|
|
201
|
+
} catch (error) {
|
|
202
|
+
if (error instanceof WalletNotInstalledError) {
|
|
203
|
+
console.log('Please install the wallet extension');
|
|
204
|
+
} else if (error instanceof UserRejectedError) {
|
|
205
|
+
console.log('User rejected the connection request');
|
|
206
|
+
} else if (error instanceof TimeoutError) {
|
|
207
|
+
console.log('Connection timed out');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Using Bron (Enterprise Wallet)
|
|
215
|
+
|
|
216
|
+
Bron requires OAuth2 configuration:
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
import { createPartyLayer, BronAdapter, getBuiltinAdapters } from '@partylayer/sdk';
|
|
220
|
+
|
|
221
|
+
const client = createPartyLayer({
|
|
222
|
+
network: 'devnet',
|
|
223
|
+
app: { name: 'My dApp' },
|
|
224
|
+
adapters: [
|
|
225
|
+
...getBuiltinAdapters(),
|
|
226
|
+
new BronAdapter({
|
|
227
|
+
auth: {
|
|
228
|
+
clientId: 'your-client-id',
|
|
229
|
+
redirectUri: 'https://your-app.com/auth/callback',
|
|
230
|
+
authorizationUrl: 'https://auth.bron.example/authorize',
|
|
231
|
+
tokenUrl: 'https://auth.bron.example/token',
|
|
232
|
+
},
|
|
233
|
+
api: {
|
|
234
|
+
baseUrl: 'https://api.bron.example',
|
|
235
|
+
getAccessToken: async () => getStoredAccessToken(),
|
|
236
|
+
},
|
|
237
|
+
}),
|
|
238
|
+
],
|
|
239
|
+
});
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## TypeScript
|
|
245
|
+
|
|
246
|
+
This package is written in TypeScript and includes type definitions. All types are exported:
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
import type {
|
|
250
|
+
Session,
|
|
251
|
+
WalletInfo,
|
|
252
|
+
SignedMessage,
|
|
253
|
+
SignedTransaction,
|
|
254
|
+
TxReceipt,
|
|
255
|
+
PartyLayerConfig,
|
|
256
|
+
ConnectOptions,
|
|
257
|
+
} from '@partylayer/sdk';
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## Related Packages
|
|
263
|
+
|
|
264
|
+
| Package | Description |
|
|
265
|
+
|---------|-------------|
|
|
266
|
+
| [@partylayer/react](https://www.npmjs.com/package/@partylayer/react) | React hooks and components |
|
|
267
|
+
| [@partylayer/core](https://www.npmjs.com/package/@partylayer/core) | Core types and abstractions |
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## Links
|
|
272
|
+
|
|
273
|
+
- [GitHub Repository](https://github.com/cayvox/PartyLayer)
|
|
274
|
+
- [Documentation](https://github.com/cayvox/PartyLayer#readme)
|
|
275
|
+
- [Report Issues](https://github.com/cayvox/PartyLayer/issues)
|
|
276
|
+
- [Canton Network](https://www.canton.network/)
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## License
|
|
281
|
+
|
|
282
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { WalletAdapter, NetworkId, StorageAdapter, CryptoAdapter, TelemetryAdapter, LoggerAdapter, WalletId, Session, SessionId, TransactionHash, TransactionStatus, WalletInfo, SignMessageParams, SignedMessage, SignTransactionParams, SignedTransaction, SubmitTransactionParams, TxReceipt } from '@partylayer/core';
|
|
2
|
+
export { AdapterConnectResult, AdapterContext, AdapterDetectResult, PartyLayerError as CantonConnectError, CapabilityKey, CapabilityNotSupportedError, ErrorCode, InternalError, NetworkId, OriginNotAllowedError, PartyId, PartyLayerError, RegistryFetchFailedError, RegistrySchemaInvalidError, RegistryVerificationFailedError, Session, SessionExpiredError, SessionId, SignMessageParams, SignTransactionParams, SignedMessage, SignedTransaction, SubmitTransactionParams, TimeoutError, TransactionStatus, TransportError, TxReceipt, UserRejectedError, WalletAdapter, WalletId, WalletInfo, WalletNotFoundError, WalletNotInstalledError } from '@partylayer/core';
|
|
3
|
+
import { RegistryClient, RegistryStatus } from '@partylayer/registry-client';
|
|
4
|
+
export { RegistryStatus } from '@partylayer/registry-client';
|
|
5
|
+
export { BronAdapter, BronAdapterConfig, BronApiConfig, BronAuthConfig } from '@partylayer/adapter-bron';
|
|
6
|
+
export { Cantor8Adapter } from '@partylayer/adapter-cantor8';
|
|
7
|
+
export { ConsoleAdapter } from '@partylayer/adapter-console';
|
|
8
|
+
export { LoopAdapter } from '@partylayer/adapter-loop';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Configuration types for PartyLayer SDK
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Default registry URL for PartyLayer
|
|
16
|
+
* This points to the official registry endpoint.
|
|
17
|
+
*/
|
|
18
|
+
declare const DEFAULT_REGISTRY_URL = "https://registry.partylayer.xyz";
|
|
19
|
+
/**
|
|
20
|
+
* Adapter class type (for instantiation)
|
|
21
|
+
*/
|
|
22
|
+
type AdapterClass = new () => WalletAdapter;
|
|
23
|
+
/**
|
|
24
|
+
* PartyLayer configuration
|
|
25
|
+
*/
|
|
26
|
+
interface PartyLayerConfig {
|
|
27
|
+
/**
|
|
28
|
+
* Registry URL (optional)
|
|
29
|
+
* @default 'https://registry.partylayer.xyz/v1/wallets.json'
|
|
30
|
+
*/
|
|
31
|
+
registryUrl?: string;
|
|
32
|
+
/** Registry channel */
|
|
33
|
+
channel?: 'stable' | 'beta';
|
|
34
|
+
/** Default network */
|
|
35
|
+
network: NetworkId;
|
|
36
|
+
/**
|
|
37
|
+
* Wallet adapters to register (OPTIONAL)
|
|
38
|
+
*
|
|
39
|
+
* By default, ALL built-in adapters are automatically registered:
|
|
40
|
+
* - ConsoleAdapter (Console Wallet - browser extension)
|
|
41
|
+
* - LoopAdapter (5N Loop - QR code / popup)
|
|
42
|
+
* - Cantor8Adapter (Cantor8 - deep link transport)
|
|
43
|
+
*
|
|
44
|
+
* Note: BronAdapter requires OAuth config and is NOT included by default.
|
|
45
|
+
*
|
|
46
|
+
* Only provide this if you want to customize which adapters to use.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // Default: all adapters (recommended)
|
|
51
|
+
* const client = createCantonConnect({
|
|
52
|
+
* network: 'devnet',
|
|
53
|
+
* app: { name: 'My dApp' },
|
|
54
|
+
* // adapters not specified = all built-in adapters (Console, Loop, Cantor8)
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* // Custom: only specific adapters
|
|
58
|
+
* import { ConsoleAdapter } from '@partylayer/sdk';
|
|
59
|
+
* const client = createPartyLayer({
|
|
60
|
+
* adapters: [new ConsoleAdapter()], // Only Console Wallet
|
|
61
|
+
* // ...
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* // With Bron (enterprise wallet with OAuth)
|
|
65
|
+
* import { BronAdapter, getBuiltinAdapters } from '@partylayer/sdk';
|
|
66
|
+
* const client = createCantonConnect({
|
|
67
|
+
* adapters: [
|
|
68
|
+
* ...getBuiltinAdapters(),
|
|
69
|
+
* new BronAdapter({ auth: {...}, api: {...} }),
|
|
70
|
+
* ],
|
|
71
|
+
* // ...
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
adapters?: (WalletAdapter | AdapterClass)[];
|
|
76
|
+
/** Storage adapter (default: browser localStorage-based encrypted) */
|
|
77
|
+
storage?: StorageAdapter;
|
|
78
|
+
/** Crypto adapter (default: WebCrypto) */
|
|
79
|
+
crypto?: CryptoAdapter;
|
|
80
|
+
/** Registry public keys for signature verification (ed25519) */
|
|
81
|
+
registryPublicKeys?: string[];
|
|
82
|
+
/** Telemetry adapter (optional) */
|
|
83
|
+
telemetry?: TelemetryAdapter;
|
|
84
|
+
/** Logger adapter (optional) */
|
|
85
|
+
logger?: LoggerAdapter;
|
|
86
|
+
/** Application metadata */
|
|
87
|
+
app: {
|
|
88
|
+
/** Application name */
|
|
89
|
+
name: string;
|
|
90
|
+
/** Origin (for origin binding checks, defaults to window.location.origin) */
|
|
91
|
+
origin?: string;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Connect options
|
|
96
|
+
*/
|
|
97
|
+
interface ConnectOptions {
|
|
98
|
+
/** Specific wallet ID to connect to */
|
|
99
|
+
walletId?: WalletId;
|
|
100
|
+
/** Prefer installed wallets */
|
|
101
|
+
preferInstalled?: boolean;
|
|
102
|
+
/** Allow only specific wallets */
|
|
103
|
+
allowWallets?: WalletId[];
|
|
104
|
+
/** Required capabilities */
|
|
105
|
+
requiredCapabilities?: string[];
|
|
106
|
+
/** Timeout in milliseconds */
|
|
107
|
+
timeoutMs?: number;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Wallet filter options
|
|
111
|
+
*/
|
|
112
|
+
interface WalletFilter {
|
|
113
|
+
/** Required capabilities */
|
|
114
|
+
requiredCapabilities?: string[];
|
|
115
|
+
/** Include experimental wallets */
|
|
116
|
+
includeExperimental?: boolean;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Event types for PartyLayer SDK
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Registry updated event
|
|
125
|
+
*/
|
|
126
|
+
interface RegistryUpdatedEvent {
|
|
127
|
+
type: 'registry:updated';
|
|
128
|
+
channel: 'stable' | 'beta';
|
|
129
|
+
version: string;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Registry status event
|
|
133
|
+
*/
|
|
134
|
+
interface RegistryStatusEvent {
|
|
135
|
+
type: 'registry:status';
|
|
136
|
+
status: {
|
|
137
|
+
source: 'network' | 'cache';
|
|
138
|
+
verified: boolean;
|
|
139
|
+
channel: 'stable' | 'beta';
|
|
140
|
+
sequence: number;
|
|
141
|
+
stale: boolean;
|
|
142
|
+
fetchedAt: number;
|
|
143
|
+
etag?: string;
|
|
144
|
+
error?: Error;
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Session connected event
|
|
149
|
+
*/
|
|
150
|
+
interface SessionConnectedEvent {
|
|
151
|
+
type: 'session:connected';
|
|
152
|
+
session: Session;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Session disconnected event
|
|
156
|
+
*/
|
|
157
|
+
interface SessionDisconnectedEvent {
|
|
158
|
+
type: 'session:disconnected';
|
|
159
|
+
sessionId: SessionId;
|
|
160
|
+
reason?: string;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Session expired event
|
|
164
|
+
*/
|
|
165
|
+
interface SessionExpiredEvent {
|
|
166
|
+
type: 'session:expired';
|
|
167
|
+
sessionId: SessionId;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Transaction status event
|
|
171
|
+
*/
|
|
172
|
+
interface TxStatusEvent {
|
|
173
|
+
type: 'tx:status';
|
|
174
|
+
sessionId: SessionId;
|
|
175
|
+
txId: TransactionHash;
|
|
176
|
+
status: TransactionStatus;
|
|
177
|
+
raw?: unknown;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Error event
|
|
181
|
+
*/
|
|
182
|
+
interface ErrorEvent {
|
|
183
|
+
type: 'error';
|
|
184
|
+
error: Error;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* All event types
|
|
188
|
+
*/
|
|
189
|
+
type PartyLayerEvent = RegistryUpdatedEvent | RegistryStatusEvent | SessionConnectedEvent | SessionDisconnectedEvent | SessionExpiredEvent | TxStatusEvent | ErrorEvent;
|
|
190
|
+
/**
|
|
191
|
+
* Event handler type
|
|
192
|
+
*/
|
|
193
|
+
type EventHandler<T extends PartyLayerEvent = PartyLayerEvent> = (event: T) => void | Promise<void>;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* PartyLayer Client - Public API Implementation
|
|
197
|
+
*
|
|
198
|
+
* This is the main public API for PartyLayer SDK.
|
|
199
|
+
* All dApps should use this API exclusively.
|
|
200
|
+
*
|
|
201
|
+
* References:
|
|
202
|
+
* - Wallet Integration Guide: https://docs.digitalasset.com/integrate/devnet/index.html
|
|
203
|
+
* - Signing transactions from dApps: https://docs.digitalasset.com/integrate/devnet/signing-transactions-from-dapps/index.html
|
|
204
|
+
* - OpenRPC dApp API spec: https://github.com/hyperledger-labs/splice-wallet-kernel/blob/main/api-specs/openrpc-dapp-api.json
|
|
205
|
+
*/
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* PartyLayer Client
|
|
209
|
+
*
|
|
210
|
+
* Main client interface for dApps to interact with Canton wallets.
|
|
211
|
+
*/
|
|
212
|
+
declare class PartyLayerClient {
|
|
213
|
+
private config;
|
|
214
|
+
private adapters;
|
|
215
|
+
private eventHandlers;
|
|
216
|
+
private activeSession;
|
|
217
|
+
readonly registryClient: RegistryClient;
|
|
218
|
+
private logger;
|
|
219
|
+
private crypto;
|
|
220
|
+
private storage;
|
|
221
|
+
private telemetry?;
|
|
222
|
+
private origin;
|
|
223
|
+
constructor(config: PartyLayerConfig);
|
|
224
|
+
/**
|
|
225
|
+
* Register a wallet adapter
|
|
226
|
+
*
|
|
227
|
+
* @internal
|
|
228
|
+
* This is used internally by the SDK to register adapters.
|
|
229
|
+
* In production, adapters would be auto-registered via registry.
|
|
230
|
+
*/
|
|
231
|
+
registerAdapter(adapter: WalletAdapter): void;
|
|
232
|
+
/**
|
|
233
|
+
* List available wallets
|
|
234
|
+
*/
|
|
235
|
+
listWallets(filter?: WalletFilter): Promise<WalletInfo[]>;
|
|
236
|
+
/**
|
|
237
|
+
* Connect to a wallet
|
|
238
|
+
*/
|
|
239
|
+
connect(options?: ConnectOptions): Promise<Session>;
|
|
240
|
+
/**
|
|
241
|
+
* Disconnect from wallet
|
|
242
|
+
*/
|
|
243
|
+
disconnect(): Promise<void>;
|
|
244
|
+
/**
|
|
245
|
+
* Get active session
|
|
246
|
+
*/
|
|
247
|
+
getActiveSession(): Promise<Session | null>;
|
|
248
|
+
/**
|
|
249
|
+
* Sign a message
|
|
250
|
+
*/
|
|
251
|
+
signMessage(params: SignMessageParams): Promise<SignedMessage>;
|
|
252
|
+
/**
|
|
253
|
+
* Sign a transaction
|
|
254
|
+
*/
|
|
255
|
+
signTransaction(params: SignTransactionParams): Promise<SignedTransaction>;
|
|
256
|
+
/**
|
|
257
|
+
* Submit a transaction
|
|
258
|
+
*/
|
|
259
|
+
submitTransaction(params: SubmitTransactionParams): Promise<TxReceipt>;
|
|
260
|
+
/**
|
|
261
|
+
* Subscribe to events
|
|
262
|
+
*/
|
|
263
|
+
on<T extends PartyLayerEvent>(event: T['type'], handler: EventHandler<T>): () => void;
|
|
264
|
+
/**
|
|
265
|
+
* Unsubscribe from events
|
|
266
|
+
*/
|
|
267
|
+
off<T extends PartyLayerEvent>(event: T['type'], handler: EventHandler<T>): void;
|
|
268
|
+
/**
|
|
269
|
+
* Destroy client and cleanup
|
|
270
|
+
*/
|
|
271
|
+
destroy(): void;
|
|
272
|
+
/**
|
|
273
|
+
* Create adapter context
|
|
274
|
+
*/
|
|
275
|
+
private createAdapterContext;
|
|
276
|
+
/**
|
|
277
|
+
* Persist session to storage
|
|
278
|
+
*/
|
|
279
|
+
private persistSession;
|
|
280
|
+
/**
|
|
281
|
+
* Remove session from storage
|
|
282
|
+
*/
|
|
283
|
+
private removeSession;
|
|
284
|
+
/**
|
|
285
|
+
* Restore session from storage
|
|
286
|
+
*/
|
|
287
|
+
private restoreSession;
|
|
288
|
+
/**
|
|
289
|
+
* Update registry status and emit event
|
|
290
|
+
*/
|
|
291
|
+
private updateRegistryStatus;
|
|
292
|
+
/**
|
|
293
|
+
* Get registry status
|
|
294
|
+
*/
|
|
295
|
+
getRegistryStatus(): RegistryStatus | null;
|
|
296
|
+
/**
|
|
297
|
+
* Emit event to handlers
|
|
298
|
+
*/
|
|
299
|
+
private emit;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Create CantonConnect client
|
|
303
|
+
*
|
|
304
|
+
* This is the main entry point for dApps.
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```typescript
|
|
308
|
+
* const client = createPartyLayer({
|
|
309
|
+
* registryUrl: 'https://registry.partylayer.xyz',
|
|
310
|
+
* channel: 'stable',
|
|
311
|
+
* network: 'devnet',
|
|
312
|
+
* app: { name: 'My dApp' }
|
|
313
|
+
* });
|
|
314
|
+
*
|
|
315
|
+
* const session = await client.connect();
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
declare function createPartyLayer(config: PartyLayerConfig): PartyLayerClient;
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Built-in wallet adapters
|
|
322
|
+
*
|
|
323
|
+
* These adapters are automatically registered when creating a PartyLayer client.
|
|
324
|
+
* dApp developers don't need to install or configure these separately.
|
|
325
|
+
*/
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Get all built-in adapters
|
|
329
|
+
*
|
|
330
|
+
* This function returns instances of all supported wallet adapters.
|
|
331
|
+
* Called automatically by createPartyLayer() unless custom adapters are provided.
|
|
332
|
+
*
|
|
333
|
+
* Included adapters:
|
|
334
|
+
* - ConsoleAdapter: Console Wallet browser extension
|
|
335
|
+
* - LoopAdapter: 5N Loop mobile/web wallet
|
|
336
|
+
* - Cantor8Adapter: Cantor8 wallet with deep link transport
|
|
337
|
+
*
|
|
338
|
+
* Note: BronAdapter is NOT included by default because it requires OAuth configuration.
|
|
339
|
+
* To use Bron, install @partylayer/adapter-bron and register it manually.
|
|
340
|
+
*/
|
|
341
|
+
declare function getBuiltinAdapters(): WalletAdapter[];
|
|
342
|
+
|
|
343
|
+
export { type AdapterClass, PartyLayerClient as CantonConnectClient, type PartyLayerConfig as CantonConnectConfig, type PartyLayerEvent as CantonConnectEvent, type ConnectOptions, DEFAULT_REGISTRY_URL, type ErrorEvent, type EventHandler, PartyLayerClient, type PartyLayerConfig, type PartyLayerEvent, type RegistryUpdatedEvent, type SessionConnectedEvent, type SessionDisconnectedEvent, type SessionExpiredEvent, type TxStatusEvent, type WalletFilter, PartyLayerClient as _PartyLayerClientInternal, createPartyLayer as createCantonConnect, createPartyLayer, getBuiltinAdapters };
|