@bootnodedev/canton-connect 0.3.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/LICENSE +21 -0
- package/README.md +155 -0
- package/dist/CantonConnectProvider-CJ1yWGXz.js +777 -0
- package/dist/index.d.ts +342 -0
- package/dist/index.js +444 -0
- package/dist/testing/index.d.ts +127 -0
- package/dist/testing/index.js +291 -0
- package/dist/types-Deu_03jh.d.ts +385 -0
- package/package.json +86 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { a as Party, c as WalletSdk, i as ConnectionSubscription, l as ConnectionInput, n as CantonConnectContextValue, o as PartyType, r as ConnectionStatus, s as TxStatusSnapshot, t as CantonConnectConfig, u as InitOptions } from "./types-Deu_03jh.js";
|
|
2
|
+
import { LedgerApiParams, PrepareExecuteParams, ProviderAdapter } from "@canton-network/dapp-sdk";
|
|
3
|
+
import { JSX, ReactNode } from "react";
|
|
4
|
+
//#region src/CantonConnectProvider/index.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The whole context in one read, and the escape hatch behind every other hook here. Reach for a
|
|
7
|
+
* narrower hook unless a component needs several slices at once; this one hands back the config,
|
|
8
|
+
* the connection to select off, and the three actions.
|
|
9
|
+
*
|
|
10
|
+
* @throws with no {@link CantonConnectProvider} above it.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const { config, connection } = useCantonConnectContext()
|
|
14
|
+
* const snapshot = connection.getSnapshot()
|
|
15
|
+
*
|
|
16
|
+
* @category Hooks
|
|
17
|
+
*/
|
|
18
|
+
declare const useCantonConnectContext: () => CantonConnectContextValue;
|
|
19
|
+
/**
|
|
20
|
+
* Props for {@link CantonConnectProvider}. `config` is read once, when the connection actor is
|
|
21
|
+
* created: a `walletPicker` or `additionalAdapters` swapped later reaches `config` on the context,
|
|
22
|
+
* never the connection, which keeps the adapters it booted with. Pass the final values first.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* <CantonConnectProvider config={{ appName: 'Vesting' }}>{children}</CantonConnectProvider>
|
|
26
|
+
*
|
|
27
|
+
* @category Components
|
|
28
|
+
*/
|
|
29
|
+
interface CantonConnectProviderProps {
|
|
30
|
+
config: CantonConnectConfig;
|
|
31
|
+
children: ReactNode;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Hands the connection machine what it needs to build its own `DappSDK`, and publishes the actor
|
|
35
|
+
* that goes through the states, plus the two bridges that drive it. Nothing here selects: a
|
|
36
|
+
* provider that pre-selected the whole session re-rendered every consumer on every tick of it.
|
|
37
|
+
* The hooks mirror wagmi's naming, not its TanStack Query result shapes.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* <CantonConnectProvider config={{ appName: 'Vesting', networkId: 'canton:local' }}>
|
|
41
|
+
* <App />
|
|
42
|
+
* </CantonConnectProvider>
|
|
43
|
+
*
|
|
44
|
+
* @category Components
|
|
45
|
+
*/
|
|
46
|
+
declare const CantonConnectProvider: ({ config, children }: CantonConnectProviderProps) => JSX.Element;
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/connectError.d.ts
|
|
49
|
+
/**
|
|
50
|
+
* A connect the user walked away from: the picker was closed rather than a wallet failing.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* if (error !== undefined && !(error instanceof ConnectCancelledError)) {
|
|
54
|
+
* toast.error(error.message)
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* @category Errors
|
|
58
|
+
*/
|
|
59
|
+
declare class ConnectCancelledError extends Error {
|
|
60
|
+
constructor(cause?: unknown);
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/hooks/useConnect.d.ts
|
|
64
|
+
/**
|
|
65
|
+
* Return shape of {@link useConnect}.
|
|
66
|
+
*
|
|
67
|
+
* `connect` resolves once the party lands; `cancelConnect` abandons one in flight, rejecting it
|
|
68
|
+
* with {@link ConnectCancelledError}; `reset` forgets the error.
|
|
69
|
+
*
|
|
70
|
+
* @category Hooks
|
|
71
|
+
*/
|
|
72
|
+
interface UseConnectResult {
|
|
73
|
+
cancelConnect: () => void;
|
|
74
|
+
connect: () => Promise<void>;
|
|
75
|
+
isPending: boolean;
|
|
76
|
+
isConnected: boolean;
|
|
77
|
+
error: Error | undefined;
|
|
78
|
+
reset: () => void;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Connects the wallet and reports that transition. `connect` takes no argument: the picker chooses
|
|
82
|
+
* the wallet, so there is no mode to pass. Gate a pending face on `isPending` and
|
|
83
|
+
* session-dependent content on `useParty().party`, not on `isConnected`.
|
|
84
|
+
*
|
|
85
|
+
* @throws with no {@link CantonConnectProvider} above it, as every hook here does.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* const { connect, isPending } = useConnect()
|
|
89
|
+
* <button onClick={() => void connect().catch(() => undefined)} disabled={isPending}>
|
|
90
|
+
* Connect
|
|
91
|
+
* </button>
|
|
92
|
+
*
|
|
93
|
+
* @category Hooks
|
|
94
|
+
*/
|
|
95
|
+
declare const useConnect: () => UseConnectResult;
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/hooks/useDisconnect.d.ts
|
|
98
|
+
/**
|
|
99
|
+
* Return shape of {@link useDisconnect}. `disconnect` settles within 10 s even unanswered.
|
|
100
|
+
*
|
|
101
|
+
* @category Hooks
|
|
102
|
+
*/
|
|
103
|
+
interface UseDisconnectResult {
|
|
104
|
+
disconnect: () => Promise<void>;
|
|
105
|
+
isPending: boolean;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Disconnects the wallet and reports that transition. No `error`: a disconnect always settles, by
|
|
109
|
+
* the timeout if the wallet never answers.
|
|
110
|
+
*
|
|
111
|
+
* @throws with no {@link CantonConnectProvider} above it, as every hook here does.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* const { disconnect, isPending } = useDisconnect()
|
|
115
|
+
* <button onClick={() => void disconnect()} disabled={isPending}>
|
|
116
|
+
* Disconnect
|
|
117
|
+
* </button>
|
|
118
|
+
*
|
|
119
|
+
* @category Hooks
|
|
120
|
+
*/
|
|
121
|
+
declare const useDisconnect: () => UseDisconnectResult;
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/hooks/useExecute.d.ts
|
|
124
|
+
/**
|
|
125
|
+
* Return shape of {@link useExecute}. `execute` resolves once the ledger has executed rather than
|
|
126
|
+
* at submission, and throws when nothing is connected or no party is reported; `lastTx` follows
|
|
127
|
+
* the wallet's own `txChanged` pushes, so it moves even while `execute` is still pending.
|
|
128
|
+
*
|
|
129
|
+
* @category Hooks
|
|
130
|
+
*/
|
|
131
|
+
interface UseExecuteResult {
|
|
132
|
+
execute: (params: PrepareExecuteParams) => Promise<unknown>;
|
|
133
|
+
lastTx: TxStatusSnapshot | undefined;
|
|
134
|
+
isPending: boolean;
|
|
135
|
+
error: Error | undefined;
|
|
136
|
+
reset: () => void;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Submits ledger commands and tracks the transaction in `lastTx`, fed by the SDK's `txChanged`
|
|
140
|
+
* event. `actAs` defaults to the party `useParty` reports, so a submit acts as the party the UI
|
|
141
|
+
* shows rather than the wallet's own primary.
|
|
142
|
+
*
|
|
143
|
+
* @throws with no {@link CantonConnectProvider} above it, and from `execute` where nothing is
|
|
144
|
+
* connected or no party is reported. A command that fails throws too, and lands in `error`.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* const { execute, lastTx } = useExecute()
|
|
148
|
+
* await execute({ commandId: 'claim-1', commands })
|
|
149
|
+
* lastTx?.status // 'pending' | 'signed' | 'executed' | 'failed'
|
|
150
|
+
*
|
|
151
|
+
* @category Hooks
|
|
152
|
+
*/
|
|
153
|
+
declare const useExecute: () => UseExecuteResult;
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/hooks/useLedger.d.ts
|
|
156
|
+
/**
|
|
157
|
+
* Return shape of {@link useLedger}. `ledgerApi` throws when nothing is connected, which `isReady`
|
|
158
|
+
* is there to check first.
|
|
159
|
+
*
|
|
160
|
+
* @category Hooks
|
|
161
|
+
*/
|
|
162
|
+
interface UseLedgerResult {
|
|
163
|
+
ledgerApi: (params: LedgerApiParams) => Promise<unknown>;
|
|
164
|
+
isReady: boolean;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Escape hatch for ledger reads `useExecute` and `useSignMessage` do not cover: the participant's
|
|
168
|
+
* JSON API, passed through untyped.
|
|
169
|
+
*
|
|
170
|
+
* @throws with no {@link CantonConnectProvider} above it, and from `ledgerApi` itself where nothing
|
|
171
|
+
* is connected, which `isReady` is there to check first.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* const { ledgerApi } = useLedger()
|
|
175
|
+
* await ledgerApi({ requestMethod: 'get', resource: '/v2/state/ledger-end' })
|
|
176
|
+
*
|
|
177
|
+
* @category Hooks
|
|
178
|
+
*/
|
|
179
|
+
declare const useLedger: () => UseLedgerResult;
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/hooks/useParty.d.ts
|
|
182
|
+
/**
|
|
183
|
+
* Return shape of {@link useParty}. `party` is the primary among the accounts that can act on the
|
|
184
|
+
* ledger, so it need not be the one the wallet flags primary, and it changes under a live session.
|
|
185
|
+
*
|
|
186
|
+
* @category Hooks
|
|
187
|
+
*/
|
|
188
|
+
interface UsePartyResult {
|
|
189
|
+
party: Party | undefined;
|
|
190
|
+
status: ConnectionStatus;
|
|
191
|
+
isConnected: boolean;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* The connected account and status. `party` is `undefined` until a connect succeeds, and again
|
|
195
|
+
* whenever a restored session is locked.
|
|
196
|
+
*
|
|
197
|
+
* @throws with no {@link CantonConnectProvider} above it.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* const { party, isConnected } = useParty()
|
|
201
|
+
* isConnected && <span>{party?.partyId}</span>
|
|
202
|
+
*
|
|
203
|
+
* @category Hooks
|
|
204
|
+
*/
|
|
205
|
+
declare const useParty: () => UsePartyResult;
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/hooks/usePartyType.d.ts
|
|
208
|
+
/**
|
|
209
|
+
* Return shape of {@link usePartyType}. `readPartyType` throws when nothing is connected or no
|
|
210
|
+
* party is reported, which `isReady` is there to check first.
|
|
211
|
+
*
|
|
212
|
+
* @category Hooks
|
|
213
|
+
*/
|
|
214
|
+
interface UsePartyTypeResult {
|
|
215
|
+
readPartyType: () => Promise<PartyType>;
|
|
216
|
+
isReady: boolean;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Tells a local party from an external one when asked. Each `readPartyType` call is one
|
|
220
|
+
* `ledgerApi` read of the participant id, its namespace compared with the party's; nothing is
|
|
221
|
+
* cached, so hold the answer where several components need it. Reach for it before an action a
|
|
222
|
+
* local party cannot take, such as `signMessage`, which the reference gateway refuses.
|
|
223
|
+
*
|
|
224
|
+
* @throws with no {@link CantonConnectProvider} above it, and from `readPartyType` where nothing
|
|
225
|
+
* is connected or no party is reported, which `isReady` is there to check first.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* const { readPartyType } = usePartyType()
|
|
229
|
+
* if ((await readPartyType()) === 'local') {
|
|
230
|
+
* toast.error('This wallet cannot sign messages for a local party')
|
|
231
|
+
* }
|
|
232
|
+
*
|
|
233
|
+
* @category Hooks
|
|
234
|
+
*/
|
|
235
|
+
declare const usePartyType: () => UsePartyTypeResult;
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region src/hooks/useSignMessage.d.ts
|
|
238
|
+
/**
|
|
239
|
+
* Return shape of {@link useSignMessage}. `signMessage` throws when nothing is connected or no
|
|
240
|
+
* party is reported, and `reset` clears the last signature and error without touching the session.
|
|
241
|
+
*
|
|
242
|
+
* @category Hooks
|
|
243
|
+
*/
|
|
244
|
+
interface UseSignMessageResult {
|
|
245
|
+
signMessage: (message: string) => Promise<string>;
|
|
246
|
+
signature: string | undefined;
|
|
247
|
+
isPending: boolean;
|
|
248
|
+
error: Error | undefined;
|
|
249
|
+
reset: () => void;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Signs an arbitrary message with the connected wallet; the SDK owns the encoding.
|
|
253
|
+
*
|
|
254
|
+
* @throws with no {@link CantonConnectProvider} above it, and from `signMessage` where nothing is
|
|
255
|
+
* connected or no party is reported. A wallet refusal throws too, and lands in `error`.
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* const { signMessage } = useSignMessage()
|
|
259
|
+
* const signed = await signMessage('Approve vesting claim')
|
|
260
|
+
*
|
|
261
|
+
* @category Hooks
|
|
262
|
+
*/
|
|
263
|
+
declare const useSignMessage: () => UseSignMessageResult;
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region src/hooks/useWalletStatus.d.ts
|
|
266
|
+
/**
|
|
267
|
+
* Return shape of {@link useWalletStatus}: connected-but-locked is a real pair.
|
|
268
|
+
*
|
|
269
|
+
* In CIP-0103 terms, locked is an unauthenticated session: it stands, but the wallet pushed
|
|
270
|
+
* `isConnected: false` and answers no requests until it pushes true again.
|
|
271
|
+
*
|
|
272
|
+
* @category Hooks
|
|
273
|
+
*/
|
|
274
|
+
interface UseWalletStatusResult {
|
|
275
|
+
isLocked: boolean;
|
|
276
|
+
isConnected: boolean;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Reports the session and lock state from the wallet's own pushes. A wallet that disconnected on
|
|
280
|
+
* its own pushed the same thing as a lock, so `isLocked` cannot tell them apart.
|
|
281
|
+
*
|
|
282
|
+
* @throws with no {@link CantonConnectProvider} above it.
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* const { isConnected, isLocked } = useWalletStatus()
|
|
286
|
+
* if (!isConnected) return <p>No session.</p>
|
|
287
|
+
* return isLocked ? <p>Unlock your wallet to continue.</p> : <p>Ready.</p>
|
|
288
|
+
*
|
|
289
|
+
* @category Hooks
|
|
290
|
+
*/
|
|
291
|
+
declare const useWalletStatus: () => UseWalletStatusResult;
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region src/mock/mockAdapter.d.ts
|
|
294
|
+
/**
|
|
295
|
+
* One canned account the mock adapter reports. Only `partyId` is required; the rest is filled with
|
|
296
|
+
* obviously fake values, so nothing downstream mistakes a mock account for a real one.
|
|
297
|
+
*
|
|
298
|
+
* @category Utilities
|
|
299
|
+
*/
|
|
300
|
+
interface MockAccount {
|
|
301
|
+
partyId: string;
|
|
302
|
+
name?: string;
|
|
303
|
+
publicKey?: string;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Wiring for {@link createMockAdapter}. `id` defaults to `'mock'`, which is the provider id
|
|
307
|
+
* `createAutoPicker('mock')` matches; `accounts` defaults to one generated account and treats the
|
|
308
|
+
* first entry as primary; omitting `networkId` lets `CantonConnectConfig.networkId` apply instead.
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* const options: CreateMockAdapterOptions = { id: 'mock', accounts: [{ partyId }] }
|
|
312
|
+
*
|
|
313
|
+
* @category Utilities
|
|
314
|
+
*/
|
|
315
|
+
interface CreateMockAdapterOptions {
|
|
316
|
+
id?: string;
|
|
317
|
+
accounts?: MockAccount[];
|
|
318
|
+
networkId?: string;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* What {@link createMockAdapter} returns: a `ProviderAdapter` plus `emit`, which simulates the
|
|
322
|
+
* wallet pushing an event to subscribers of `provider().on(...)`.
|
|
323
|
+
*
|
|
324
|
+
* @category Utilities
|
|
325
|
+
*/
|
|
326
|
+
interface MockAdapter extends ProviderAdapter {
|
|
327
|
+
emit: (event: string, payload: unknown) => void;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Answers the connect flow with canned data, so `CantonConnectProvider` runs with no wallet
|
|
331
|
+
* installed; pass it via `CantonConnectConfig.additionalAdapters`. Anything outside that flow
|
|
332
|
+
* throws naming the method; a canned result would be indistinguishable from a real one. Reach for
|
|
333
|
+
* `createFakeWallet` instead to exercise the SDK's real extension transport.
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* const config = { appName: 'Vesting', additionalAdapters: [createMockAdapter()] }
|
|
337
|
+
*
|
|
338
|
+
* @category Utilities
|
|
339
|
+
*/
|
|
340
|
+
declare const createMockAdapter: (options?: CreateMockAdapterOptions) => MockAdapter;
|
|
341
|
+
//#endregion
|
|
342
|
+
export { type CantonConnectConfig, type CantonConnectContextValue, CantonConnectProvider, type CantonConnectProviderProps, ConnectCancelledError, type ConnectionInput, type ConnectionStatus, type ConnectionSubscription, type CreateMockAdapterOptions, type InitOptions, type LedgerApiParams, type MockAccount, type MockAdapter, type Party, type PartyType, type PrepareExecuteParams, type TxStatusSnapshot, type UseConnectResult, type UseDisconnectResult, type UseExecuteResult, type UseLedgerResult, type UsePartyResult, type UsePartyTypeResult, type UseSignMessageResult, type UseWalletStatusResult, type WalletSdk, createMockAdapter, useCantonConnectContext, useConnect, useDisconnect, useExecute, useLedger, useParty, usePartyType, useSignMessage, useWalletStatus };
|