@fairmint/canton-node-sdk 0.0.286 → 0.0.288

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.
Files changed (66) hide show
  1. package/README.md +42 -7
  2. package/build/src/clients/ledger-json-api/index.d.ts +1 -1
  3. package/build/src/clients/ledger-json-api/index.d.ts.map +1 -1
  4. package/build/src/clients/ledger-json-api/index.js.map +1 -1
  5. package/build/src/clients/ledger-json-api/operations/v2/utils/raw-frame-stream.d.ts +21 -1
  6. package/build/src/clients/ledger-json-api/operations/v2/utils/raw-frame-stream.d.ts.map +1 -1
  7. package/build/src/clients/ledger-json-api/operations/v2/utils/raw-frame-stream.js +13 -3
  8. package/build/src/clients/ledger-json-api/operations/v2/utils/raw-frame-stream.js.map +1 -1
  9. package/build/src/clients/scan-api/ScanApiClient.d.ts.map +1 -1
  10. package/build/src/clients/scan-api/ScanApiClient.js +2 -1
  11. package/build/src/clients/scan-api/ScanApiClient.js.map +1 -1
  12. package/build/src/core/http/HttpClient.d.ts.map +1 -1
  13. package/build/src/core/http/HttpClient.js +2 -1
  14. package/build/src/core/http/HttpClient.js.map +1 -1
  15. package/build/src/core/http/abort.d.ts +1 -3
  16. package/build/src/core/http/abort.d.ts.map +1 -1
  17. package/build/src/core/http/abort.js +6 -4
  18. package/build/src/core/http/abort.js.map +1 -1
  19. package/build/src/utils/external-signing/execute-external-transaction.d.ts +43 -10
  20. package/build/src/utils/external-signing/execute-external-transaction.d.ts.map +1 -1
  21. package/build/src/utils/external-signing/execute-external-transaction.js +42 -11
  22. package/build/src/utils/external-signing/execute-external-transaction.js.map +1 -1
  23. package/build/src/utils/external-signing/external-signing-client.d.ts +4 -0
  24. package/build/src/utils/external-signing/external-signing-client.d.ts.map +1 -1
  25. package/build/src/utils/external-signing/external-signing-client.js.map +1 -1
  26. package/build/src/wallets/abort.d.ts +17 -0
  27. package/build/src/wallets/abort.d.ts.map +1 -0
  28. package/build/src/wallets/abort.js +98 -0
  29. package/build/src/wallets/abort.js.map +1 -0
  30. package/build/src/wallets/cip103.d.ts +23 -2
  31. package/build/src/wallets/cip103.d.ts.map +1 -1
  32. package/build/src/wallets/cip103.js +107 -4
  33. package/build/src/wallets/cip103.js.map +1 -1
  34. package/build/src/wallets/da-utilities/client.d.ts +18 -9
  35. package/build/src/wallets/da-utilities/client.d.ts.map +1 -1
  36. package/build/src/wallets/da-utilities/client.js +33 -21
  37. package/build/src/wallets/da-utilities/client.js.map +1 -1
  38. package/build/src/wallets/discovery.d.ts +78 -0
  39. package/build/src/wallets/discovery.d.ts.map +1 -0
  40. package/build/src/wallets/discovery.js +364 -0
  41. package/build/src/wallets/discovery.js.map +1 -0
  42. package/build/src/wallets/errors.d.ts +64 -7
  43. package/build/src/wallets/errors.d.ts.map +1 -1
  44. package/build/src/wallets/errors.js +105 -9
  45. package/build/src/wallets/errors.js.map +1 -1
  46. package/build/src/wallets/index.d.ts +13 -5
  47. package/build/src/wallets/index.d.ts.map +1 -1
  48. package/build/src/wallets/index.js +21 -4
  49. package/build/src/wallets/index.js.map +1 -1
  50. package/build/src/wallets/ownership.d.ts +12 -0
  51. package/build/src/wallets/ownership.d.ts.map +1 -1
  52. package/build/src/wallets/ownership.js +29 -13
  53. package/build/src/wallets/ownership.js.map +1 -1
  54. package/build/src/wallets/session.d.ts +10 -2
  55. package/build/src/wallets/session.d.ts.map +1 -1
  56. package/build/src/wallets/session.js +186 -61
  57. package/build/src/wallets/session.js.map +1 -1
  58. package/build/src/wallets/store.d.ts +11 -3
  59. package/build/src/wallets/store.d.ts.map +1 -1
  60. package/build/src/wallets/store.js +25 -15
  61. package/build/src/wallets/store.js.map +1 -1
  62. package/build/src/wallets/wallet.d.ts +23 -12
  63. package/build/src/wallets/wallet.d.ts.map +1 -1
  64. package/build/src/wallets/wallet.js +76 -59
  65. package/build/src/wallets/wallet.js.map +1 -1
  66. package/package.json +107 -1
@@ -0,0 +1,364 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.INJECTED_WALLET_ID = void 0;
4
+ exports.channelProvider = channelProvider;
5
+ exports.discoverCip103Wallets = discoverCip103Wallets;
6
+ /**
7
+ * Discovery of the CIP-0103 wallets installed in the browser as extensions: one call, `discoverCip103Wallets()`, lists
8
+ * them as `{ id, name, icon?, load(network) }`, and `load` resolves a {@link Cip103Provider} that the session, the store
9
+ * and `createWallet` take like any other.
10
+ *
11
+ * - Handshake (the Canton dApp SDK's): the page dispatches `canton:requestProvider`, and each installed wallet answers
12
+ * `canton:announceProvider` with `{ id, name, icon?, target? }` within 300 ms. Several wallets may answer; the user
13
+ * picks one. The page's `canton` global holds one wallet only (the last extension to write it), so it is offered only
14
+ * when no wallet announced itself.
15
+ * - Channel: an announced wallet is reached over the dApp SDK's message channel: a `SPLICE_WALLET_REQUEST` message `{
16
+ * type, target, request: { jsonrpc: '2.0', id, method, params } }` posted to the page, answered by a
17
+ * `SPLICE_WALLET_RESPONSE` `{ type, response: { jsonrpc, id, result | error } }` with the same id; a request without
18
+ * an id addressed to the target is an event (`on`). This is the wire format of `@canton-network/core-rpc-transport`'s
19
+ * `WindowTransport` (1.18.0), implemented here so the wallets module keeps no runtime dependency.
20
+ * - Corrections, which change nothing for a wallet that follows CIP-0103:
21
+ *
22
+ * - `ledgerApi`: a result `{ response: '<raw body>' }` is answered as the parsed body (Console Wallet answers `{
23
+ * ...parsedBody, response }`, which turns a list body into an object).
24
+ * - `getPrimaryAccount`: network ids `CANTON_NETWORK_DEV`, `CANTON_NETWORK_TEST` and `CANTON_NETWORK` become
25
+ * `canton:devnet`, `canton:testnet` and `canton:mainnet`; an account on another network than the one loaded is
26
+ * refused with 4901 (an extension serves the network selected in the wallet, not one the page picks); a -32002
27
+ * read (a sleeping extension worker) is retried twice.
28
+ * - Console Wallet (1.15): its channel answers successes only, so an error (a declined connect) would hang. It is reached
29
+ * through the page's `canton` global instead (`source: 'consoleWallet'`), and its `signMessage` is sent the base64 of
30
+ * the message's UTF-8 bytes, which it decodes and signs (it signs exactly the message's bytes).
31
+ */
32
+ const cip103_1 = require("./cip103");
33
+ const abort_1 = require("../core/http/abort");
34
+ const abort_2 = require("./abort");
35
+ const REQUEST_EVENT = 'canton:requestProvider';
36
+ const ANNOUNCE_EVENT = 'canton:announceProvider';
37
+ const DEFAULT_WAIT_MS = 300;
38
+ const REQUEST_MESSAGE = 'SPLICE_WALLET_REQUEST';
39
+ const RESPONSE_MESSAGE = 'SPLICE_WALLET_RESPONSE';
40
+ const CONSOLE_NAME = 'Console Wallet';
41
+ const CONSOLE_SOURCE = 'consoleWallet';
42
+ /** The id of a wallet found through the page's `canton` global only (`injected:console` for Console Wallet). */
43
+ exports.INJECTED_WALLET_ID = 'injected';
44
+ const INJECTED_CONSOLE_ID = 'injected:console';
45
+ const NETWORK_IDS = {
46
+ CANTON_NETWORK_DEV: 'canton:devnet',
47
+ CANTON_NETWORK_TEST: 'canton:testnet',
48
+ CANTON_NETWORK: 'canton:mainnet',
49
+ };
50
+ /** -32002: an extension's account read that timed out (a sleeping worker); retried after these waits. */
51
+ const RESOURCE_UNAVAILABLE = -32002;
52
+ const ACCOUNT_READ_RETRY_DELAYS_MS = [300, 1000];
53
+ const CHAIN_DISCONNECTED = 4901;
54
+ function isObject(value) {
55
+ return typeof value === 'object' && value !== null;
56
+ }
57
+ function isProvider(value) {
58
+ return (isObject(value) &&
59
+ typeof value['request'] === 'function' &&
60
+ typeof value['on'] === 'function' &&
61
+ typeof value['removeListener'] === 'function');
62
+ }
63
+ function isHost(value) {
64
+ return (isObject(value) &&
65
+ typeof value['addEventListener'] === 'function' &&
66
+ typeof value['removeEventListener'] === 'function' &&
67
+ typeof value['dispatchEvent'] === 'function' &&
68
+ typeof value['postMessage'] === 'function');
69
+ }
70
+ function injectedProvider(host) {
71
+ const candidate = host.canton;
72
+ return isProvider(candidate) ? candidate : undefined;
73
+ }
74
+ /** A provider error as CIP-0103 shapes it: an `Error` with a numeric `code` (and the wallet's `data`). */
75
+ function providerError(code, message, data) {
76
+ return Object.assign(new Error(message), { code }, data !== undefined && { data });
77
+ }
78
+ function utf8ToBase64(text) {
79
+ let binary = '';
80
+ for (const byte of new TextEncoder().encode(text))
81
+ binary += String.fromCharCode(byte);
82
+ return btoa(binary);
83
+ }
84
+ /** The Ledger API body: the raw `response` text, parsed, when the wallet sent one. */
85
+ function ledgerApiBody(result) {
86
+ return isObject(result) && typeof result['response'] === 'string'
87
+ ? JSON.parse(result['response'])
88
+ : result;
89
+ }
90
+ /** The account with a CIP-0103 network id; refused when the wallet is on another network than `network`. */
91
+ function accountOn(account, network, name) {
92
+ if (!isObject(account) || typeof account['networkId'] !== 'string')
93
+ return account;
94
+ const networkId = NETWORK_IDS[account['networkId']] ?? account['networkId'];
95
+ if (networkId.startsWith('canton:') && networkId !== `canton:${network}`) {
96
+ throw providerError(CHAIN_DISCONNECTED, `${name} is on ${networkId.slice('canton:'.length)}, not ${network}: switch networks in the wallet, then connect again.`);
97
+ }
98
+ return { ...account, networkId };
99
+ }
100
+ async function readAccount(wallet, request, options) {
101
+ for (let attempt = 0;; attempt += 1) {
102
+ try {
103
+ return await wallet.request(request, options);
104
+ }
105
+ catch (error) {
106
+ const delay = ACCOUNT_READ_RETRY_DELAYS_MS[attempt];
107
+ if (!isObject(error) || error['code'] !== RESOURCE_UNAVAILABLE || delay === undefined)
108
+ throw error;
109
+ await (0, abort_1.abortableSleep)(delay, options?.signal);
110
+ }
111
+ }
112
+ }
113
+ /** `wallet` with the corrections above; `signsBase64` for Console's `signMessage`. */
114
+ function adapt(wallet, network, name, signsBase64) {
115
+ return {
116
+ async request(request, options) {
117
+ switch (request.method) {
118
+ case 'ledgerApi':
119
+ return ledgerApiBody(await wallet.request(request, options));
120
+ case 'signMessage':
121
+ return wallet.request(signsBase64
122
+ ? { method: 'signMessage', params: { message: utf8ToBase64(request.params.message) } }
123
+ : request, options);
124
+ case 'getPrimaryAccount':
125
+ return accountOn(await readAccount(wallet, request, options), network, name);
126
+ case 'connect':
127
+ case 'disconnect':
128
+ case 'isConnected':
129
+ case 'prepareExecuteAndWait':
130
+ return wallet.request(request, options);
131
+ }
132
+ },
133
+ on: (event, listener) => wallet.on(event, listener),
134
+ removeListener: (event, listener) => wallet.removeListener(event, listener),
135
+ };
136
+ }
137
+ /** Whether `event` is a message posted by `host` itself: another window (a cross-origin iframe) cannot speak for it. */
138
+ function fromHost(host, event) {
139
+ return isObject(event) && event.source === host;
140
+ }
141
+ function messageData(event) {
142
+ return isObject(event) ? event.data : undefined;
143
+ }
144
+ /** How long a request that submits nothing waits for an answer before its pending state is freed. */
145
+ const UNANSWERED_TIMEOUT_MS = 5 * 60 * 1000;
146
+ const UNANSWERED_TIMEOUT_METHODS = new Set([
147
+ 'connect',
148
+ 'disconnect',
149
+ 'isConnected',
150
+ 'getPrimaryAccount',
151
+ ]);
152
+ /**
153
+ * A CIP-0103 provider over the dApp SDK's message channel to `target`. Requests carry a fresh random id and resolve
154
+ * with the response of that id; requests without an id addressed to `target` are events. A wallet that announced no
155
+ * target is untargeted, as in the dApp SDK's extension adapter: requests carry no `target` and notifications are not
156
+ * filtered by one.
157
+ */
158
+ function channelProvider(host, target) {
159
+ const listeners = new Map();
160
+ const onNotification = (event) => {
161
+ if (!fromHost(host, event))
162
+ return;
163
+ const data = messageData(event);
164
+ if (!isObject(data) || data['type'] !== REQUEST_MESSAGE)
165
+ return;
166
+ if (target !== undefined && data['target'] !== target)
167
+ return;
168
+ const { request } = data;
169
+ if (!isObject(request) || request['id'] != null || typeof request['method'] !== 'string')
170
+ return;
171
+ listeners.get(request['method'])?.forEach((listener) => listener(request['params']));
172
+ };
173
+ return {
174
+ request: async (request, options) => new Promise((resolve, reject) => {
175
+ const signal = options?.signal;
176
+ if (signal?.aborted === true) {
177
+ reject((0, abort_1.createAbortError)(signal));
178
+ return;
179
+ }
180
+ const id = (0, cip103_1.newCommandId)();
181
+ let timer;
182
+ // Frees the pending request: its listeners and timer. Safe to run twice.
183
+ const settle = () => {
184
+ host.removeEventListener('message', onResponse);
185
+ signal?.removeEventListener('abort', onAbort);
186
+ if (timer !== undefined)
187
+ clearTimeout(timer);
188
+ };
189
+ function onAbort() {
190
+ settle();
191
+ reject((0, abort_1.createAbortError)(signal));
192
+ }
193
+ function onResponse(event) {
194
+ if (!fromHost(host, event))
195
+ return;
196
+ const data = messageData(event);
197
+ const response = isObject(data) && data['type'] === RESPONSE_MESSAGE ? data['response'] : undefined;
198
+ if (!isObject(response) || response['id'] !== id)
199
+ return;
200
+ settle();
201
+ const { error } = response;
202
+ if (error === undefined) {
203
+ resolve(response['result']);
204
+ return;
205
+ }
206
+ const { code, message, data: details } = isObject(error) ? error : {};
207
+ reject(providerError(typeof code === 'number' ? code : -32603, typeof message === 'string' ? message : 'The wallet answered with an error', details));
208
+ }
209
+ host.addEventListener('message', onResponse);
210
+ signal?.addEventListener('abort', onAbort, { once: true });
211
+ // A wallet that never answers must not hold a listener for good. Only requests that submit nothing time out:
212
+ // a submission may still be completed by the wallet after any deadline.
213
+ if (UNANSWERED_TIMEOUT_METHODS.has(request.method)) {
214
+ timer = setTimeout(() => {
215
+ settle();
216
+ reject(providerError(-32603, `The wallet did not answer ${request.method} within ${UNANSWERED_TIMEOUT_MS / 1000}s`));
217
+ }, UNANSWERED_TIMEOUT_MS);
218
+ // Never keeps a Node process alive (a browser's timer id has no unref).
219
+ timer.unref?.();
220
+ }
221
+ host.postMessage({
222
+ type: REQUEST_MESSAGE,
223
+ ...(target !== undefined && { target }),
224
+ request: {
225
+ jsonrpc: '2.0',
226
+ id,
227
+ method: request.method,
228
+ ...('params' in request && { params: request.params }),
229
+ },
230
+ }, '*');
231
+ }),
232
+ on: (event, listener) => {
233
+ if (listeners.size === 0)
234
+ host.addEventListener('message', onNotification);
235
+ const set = listeners.get(event) ?? new Set();
236
+ set.add(listener);
237
+ listeners.set(event, set);
238
+ },
239
+ removeListener: (event, listener) => {
240
+ const set = listeners.get(event);
241
+ set?.delete(listener);
242
+ if (set?.size === 0)
243
+ listeners.delete(event);
244
+ if (listeners.size === 0)
245
+ host.removeEventListener('message', onNotification);
246
+ },
247
+ };
248
+ }
249
+ /** A wallet whose providers are made once per network. */
250
+ function walletOf(identity, connect, signsBase64) {
251
+ const providers = new Map();
252
+ return Object.freeze({
253
+ ...identity,
254
+ // Async so a wallet that cannot be reached (another extension holds Console's global) rejects, never throws.
255
+ load: async (network, { signal } = {}) => {
256
+ (0, abort_2.throwIfAborted)(signal);
257
+ let provider = providers.get(network);
258
+ if (provider === undefined) {
259
+ provider = adapt(connect(), network, identity.name, signsBase64);
260
+ providers.set(network, provider);
261
+ }
262
+ return Promise.resolve(provider);
263
+ },
264
+ });
265
+ }
266
+ function consoleWallet(host, identity) {
267
+ return walletOf(identity, () => {
268
+ const canton = injectedProvider(host);
269
+ if (canton?.source !== CONSOLE_SOURCE) {
270
+ throw new Error(`Another wallet extension holds the page's canton provider, which ${CONSOLE_NAME} needs: turn the other extension off, then reload.`);
271
+ }
272
+ return canton;
273
+ }, true);
274
+ }
275
+ function readAnnounced(detail) {
276
+ if (!isObject(detail))
277
+ return undefined;
278
+ const { id, name, icon, target } = detail;
279
+ if (typeof id !== 'string' || id === '' || typeof name !== 'string')
280
+ return undefined;
281
+ return {
282
+ id,
283
+ name,
284
+ ...(typeof icon === 'string' && icon !== '' && { icon }),
285
+ ...(typeof target === 'string' && target !== '' && { target }),
286
+ };
287
+ }
288
+ async function announcedWallets(host, waitMs, signal) {
289
+ const found = new Map();
290
+ const onAnnounce = (event) => {
291
+ const announced = readAnnounced(isObject(event) ? event.detail : undefined);
292
+ if (announced !== undefined && !found.has(announced.id))
293
+ found.set(announced.id, announced);
294
+ };
295
+ host.addEventListener(ANNOUNCE_EVENT, onAnnounce);
296
+ try {
297
+ host.dispatchEvent(new CustomEvent(REQUEST_EVENT, { detail: {} }));
298
+ await (0, abort_2.awaitWithAbort)(async () => new Promise((resolve) => {
299
+ setTimeout(resolve, waitMs);
300
+ }), signal);
301
+ }
302
+ finally {
303
+ host.removeEventListener(ANNOUNCE_EVENT, onAnnounce);
304
+ }
305
+ return [...found.values()];
306
+ }
307
+ // One wallet object per host and id, so its providers (and a session's view of them) survive another discovery.
308
+ const remembered = new WeakMap();
309
+ function rememberedWallet(host, id, make) {
310
+ let byId = remembered.get(host);
311
+ if (byId === undefined) {
312
+ byId = new Map();
313
+ remembered.set(host, byId);
314
+ }
315
+ let wallet = byId.get(id);
316
+ if (wallet === undefined) {
317
+ wallet = make();
318
+ byId.set(id, wallet);
319
+ }
320
+ return wallet;
321
+ }
322
+ /**
323
+ * The CIP-0103 wallet extensions installed in this browser, in the order they announced themselves; the wallet behind
324
+ * the page's `canton` global when none announced; none outside a browser. A wallet found again is the same object.
325
+ */
326
+ async function discoverCip103Wallets(options = {}) {
327
+ const { signal } = options;
328
+ (0, abort_2.throwIfAborted)(signal);
329
+ const host = options.host ?? globalThis;
330
+ if (!isHost(host) || typeof CustomEvent !== 'function')
331
+ return [];
332
+ const waitMs = options.waitMs ?? DEFAULT_WAIT_MS;
333
+ if (!Number.isFinite(waitMs) || waitMs < 0)
334
+ throw new TypeError('waitMs must be a non-negative number');
335
+ const announced = await announcedWallets(host, waitMs, signal);
336
+ if (signal?.aborted === true)
337
+ throw (0, abort_2.cancelledBeforeSubmit)(signal);
338
+ if (announced.length > 0) {
339
+ return announced.map((wallet) => rememberedWallet(host, wallet.id, () => {
340
+ const identity = {
341
+ id: wallet.id,
342
+ name: wallet.name,
343
+ ...(wallet.icon !== undefined && { icon: wallet.icon }),
344
+ };
345
+ return wallet.name === CONSOLE_NAME
346
+ ? consoleWallet(host, identity)
347
+ : walletOf(identity, () => channelProvider(host, wallet.target), false);
348
+ }));
349
+ }
350
+ // No announcement: a wallet that only injected the `canton` global.
351
+ const canton = injectedProvider(host);
352
+ if (canton === undefined)
353
+ return [];
354
+ if (canton.source === CONSOLE_SOURCE) {
355
+ return [
356
+ rememberedWallet(host, INJECTED_CONSOLE_ID, () => consoleWallet(host, { id: INJECTED_CONSOLE_ID, name: CONSOLE_NAME })),
357
+ ];
358
+ }
359
+ const name = typeof canton.source === 'string' && canton.source !== '' ? canton.source : 'Browser wallet';
360
+ return [
361
+ rememberedWallet(host, exports.INJECTED_WALLET_ID, () => walletOf({ id: exports.INJECTED_WALLET_ID, name }, () => canton, false)),
362
+ ];
363
+ }
364
+ //# sourceMappingURL=discovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../../src/wallets/discovery.ts"],"names":[],"mappings":";;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qCAA2G;AAG3G,8CAAsE;AACtE,mCAAgF;AAuChF,MAAM,aAAa,GAAG,wBAAwB,CAAC;AAC/C,MAAM,cAAc,GAAG,yBAAyB,CAAC;AACjD,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,eAAe,GAAG,uBAAuB,CAAC;AAChD,MAAM,gBAAgB,GAAG,wBAAwB,CAAC;AAElD,MAAM,YAAY,GAAG,gBAAgB,CAAC;AACtC,MAAM,cAAc,GAAG,eAAe,CAAC;AACvC,gHAAgH;AACnG,QAAA,kBAAkB,GAAG,UAAU,CAAC;AAC7C,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AAE/C,MAAM,WAAW,GAAqC;IACpD,kBAAkB,EAAE,eAAe;IACnC,mBAAmB,EAAE,gBAAgB;IACrC,cAAc,EAAE,gBAAgB;CACjC,CAAC;AAEF,yGAAyG;AACzG,MAAM,oBAAoB,GAAG,CAAC,KAAK,CAAC;AACpC,MAAM,4BAA4B,GAAsB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACpE,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAIhC,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,CACL,QAAQ,CAAC,KAAK,CAAC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CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,gBAAgB,CAAC;IAC1G,OAAO;QACL,gBAAgB,CAAC,IAAI,EAAE,QAAA,kBAAkB,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,QAAA,kBAAkB,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;KAClH,CAAC;AACJ,CAAC"}
@@ -1,15 +1,53 @@
1
- /** Errors the wallets module throws. Each carries enough to decide whether a retry is safe. */
2
1
  /**
3
2
  * - `rejected-by-user`: the user declined in the wallet; nothing was submitted.
4
3
  * - `failed`: nothing was committed (the ledger rejected it, or the wallet refused the request before taking it on).
5
4
  * - `unknown`: the outcome is not known. Do not resubmit blindly: check the wallet or ledger first.
6
5
  */
7
6
  export type WalletSubmitOutcome = 'rejected-by-user' | 'failed' | 'unknown';
7
+ /**
8
+ * Why a submission did not commit (or may not have), as far as the wallet's answer tells: a bounded category to log,
9
+ * count or branch on. It never changes `outcome`, which alone says whether a retry is safe.
10
+ *
11
+ * - `user-rejected`: the user declined in the wallet (CIP-0103 4001).
12
+ * - `wallet-refused`: the wallet refused the request before taking it on (4200, -32700, -32600, -32601, -32602, -32000,
13
+ * -32004).
14
+ * - `session`: the wallet was not, or no longer, connected or authorized (4100, 4900, 4901).
15
+ * - `rate-limited`: the wallet rate-limited the submission (-32005).
16
+ * - `ledger-rejected`: the ledger rejected the transaction (-32003, or a `failed` status) and named no Canton error.
17
+ * - From the Canton error the wallet passed on (its category, see `cantonErrorId`):
18
+ *
19
+ * - `contention`: a contract it uses was locked or changed by another transaction meanwhile (category 2).
20
+ * - `not-found`: a contract, party or package it names does not exist or was archived (category 11).
21
+ * - `duplicate`: it was already submitted, or what it creates already exists (category 10).
22
+ * - `invalid`: malformed, whatever the ledger state (category 8, 5).
23
+ * - `precondition`: refused in the current ledger state: a Daml assertion, an unvetted package, … (category 9, 12).
24
+ * - `permission`: the participant refused the wallet's credentials or rights (category 6, 7).
25
+ * - `timeout`: a deadline passed before the outcome was known (category 3).
26
+ * - `unavailable`: the participant or synchronizer was unavailable, or the wallet answered -32002 (category 1, 13).
27
+ * - `internal`: an internal error of the wallet or participant (-32603, category 4, 14).
28
+ * - `unknown`: the answer gives nothing to go by.
29
+ */
30
+ export type WalletSubmitCategory = 'user-rejected' | 'wallet-refused' | 'session' | 'rate-limited' | 'ledger-rejected' | 'contention' | 'not-found' | 'duplicate' | 'invalid' | 'precondition' | 'permission' | 'timeout' | 'unavailable' | 'internal' | 'unknown';
31
+ /** Details of a {@link WalletSubmitError} beside its outcome and message. */
32
+ export interface WalletSubmitErrorDetails {
33
+ readonly code?: number;
34
+ readonly commandId?: string;
35
+ readonly burnReference?: string;
36
+ readonly category?: WalletSubmitCategory;
37
+ readonly cantonErrorId?: string;
38
+ }
8
39
  /** A submission did not commit, or its outcome is unknown. The SDK never retries. */
9
40
  export declare class WalletSubmitError extends Error {
10
41
  readonly outcome: WalletSubmitOutcome;
11
42
  /** The wallet's CIP-0103 error code, when it gave one. */
12
43
  readonly code?: number;
44
+ /** Why, as a bounded category (see {@link WalletSubmitCategory}); `unknown` when the answer gives nothing to go by. */
45
+ readonly category: WalletSubmitCategory;
46
+ /**
47
+ * The Canton error id the wallet passed on, when its answer carried one (`LOCAL_VERDICT_LOCKED_CONTRACTS`,
48
+ * `DAML_INTERPRETATION_ERROR`, `CONTRACT_NOT_FOUND`, …): the id to look up in Canton's error code reference.
49
+ */
50
+ readonly cantonErrorId?: string;
13
51
  /** The command id the submission was sent with; an `unknown` outcome's message names it. */
14
52
  readonly commandId?: string;
15
53
  /**
@@ -17,11 +55,7 @@ export declare class WalletSubmitError extends Error {
17
55
  * `unknown` outcome, look the burn request up by it before filing another.
18
56
  */
19
57
  readonly burnReference?: string;
20
- constructor(outcome: WalletSubmitOutcome, message: string, details?: {
21
- code?: number;
22
- commandId?: string;
23
- burnReference?: string;
24
- });
58
+ constructor(outcome: WalletSubmitOutcome, message: string, details?: WalletSubmitErrorDetails);
25
59
  }
26
60
  /** The wallet could not read the ledger or its account, or answered in a shape this module does not understand. */
27
61
  export declare class WalletReadError extends Error {
@@ -72,6 +106,23 @@ export declare class WalletError extends Error {
72
106
  readonly code: WalletErrorCode;
73
107
  constructor(code: WalletErrorCode, message: string);
74
108
  }
109
+ /** Whether `error` is a {@link WalletError} of any copy of this module (a brand check, not `instanceof`). */
110
+ export declare function isWalletError(error: unknown): error is WalletError;
111
+ /** Whether `error` is a {@link WalletSubmitError} of any copy of this module (a brand check, not `instanceof`). */
112
+ export declare function isWalletSubmitError(error: unknown): error is WalletSubmitError;
113
+ /** Whether `error` is a {@link WalletReadError} of any copy of this module (a brand check, not `instanceof`). */
114
+ export declare function isWalletReadError(error: unknown): error is WalletReadError;
115
+ /** Whether `error` is a {@link WalletSignError} of any copy of this module (a brand check, not `instanceof`). */
116
+ export declare function isWalletSignError(error: unknown): error is WalletSignError;
117
+ /** Whether `error` is a {@link RegistryApiError} of any copy of this module (a brand check, not `instanceof`). */
118
+ export declare function isRegistryApiError(error: unknown): error is RegistryApiError;
119
+ /** Whether `error` is a {@link RegistryResponseError} of any copy of this module (a brand check, not `instanceof`). */
120
+ export declare function isRegistryResponseError(error: unknown): error is RegistryResponseError;
121
+ /**
122
+ * Whether `error` is a cancellation: the `AbortError` an aborted `signal` makes a wallets call throw (also a
123
+ * `TimeoutError` from `AbortSignal.timeout`, which `fetch` passes through).
124
+ */
125
+ export declare function isWalletCancellation(error: unknown): boolean;
75
126
  /**
76
127
  * Any error the wallets module throws, as a sentence a dApp can show (it says whether anything was submitted) and a
77
128
  * `kind` to branch on.
@@ -88,10 +139,12 @@ export interface WalletErrorDescription {
88
139
  * - `read-failed`: any other failed read.
89
140
  * - `sign-failed`: the wallet did not sign (an invalid challenge, or a wallet failure).
90
141
  * - `registry`: the registry API answered with an error status or a body the SDK refuses.
142
+ * - `cancelled`: the call's `signal` aborted it. The message says "Nothing was submitted" only for the cancellation
143
+ * this module throws before it submits; any other `AbortError` or `TimeoutError` gets a neutral sentence.
91
144
  * - `not-verified`: the server did not verify a wallet ownership proof (its verdict; never from `describeWalletError`).
92
145
  * - `other`: anything else.
93
146
  */
94
- readonly kind: 'declined' | 'not-committed' | 'outcome-unknown' | 'refused' | 'rate-limited' | 'read-failed' | 'sign-failed' | 'registry' | 'not-verified' | 'other';
147
+ readonly kind: 'declined' | 'not-committed' | 'outcome-unknown' | 'refused' | 'rate-limited' | 'read-failed' | 'sign-failed' | 'registry' | 'cancelled' | 'not-verified' | 'other';
95
148
  /**
96
149
  * The `WalletError` code of a `refused` error, the wallet's CIP-0103 code of a wallet error when it gave one, or the
97
150
  * HTTP status of a registry API error.
@@ -101,6 +154,10 @@ export interface WalletErrorDescription {
101
154
  readonly commandId?: string;
102
155
  /** An `outcome-unknown` burn request's reference, to look the request up before another is filed. */
103
156
  readonly burnReference?: string;
157
+ /** A submission's {@link WalletSubmitCategory} (for `declined`, `not-committed` and `outcome-unknown`). */
158
+ readonly category?: WalletSubmitCategory;
159
+ /** The Canton error id a submission's failure carried, when it carried one. */
160
+ readonly cantonErrorId?: string;
104
161
  }
105
162
  /** A user-facing sentence and a kind for any error the wallets module throws (or anything else thrown). */
106
163
  export declare function describeWalletError(error: unknown): WalletErrorDescription;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/wallets/errors.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAE/F;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,kBAAkB,GAAG,QAAQ,GAAG,SAAS,CAAC;AAW5E,qFAAqF;AACrF,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAC;IACtC,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,4FAA4F;IAC5F,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B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