@fairmint/canton-node-sdk 0.0.287 → 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 (59) hide show
  1. package/README.md +42 -7
  2. package/build/src/clients/scan-api/ScanApiClient.d.ts.map +1 -1
  3. package/build/src/clients/scan-api/ScanApiClient.js +2 -1
  4. package/build/src/clients/scan-api/ScanApiClient.js.map +1 -1
  5. package/build/src/core/http/HttpClient.d.ts.map +1 -1
  6. package/build/src/core/http/HttpClient.js +2 -1
  7. package/build/src/core/http/HttpClient.js.map +1 -1
  8. package/build/src/core/http/abort.d.ts +1 -3
  9. package/build/src/core/http/abort.d.ts.map +1 -1
  10. package/build/src/core/http/abort.js +6 -4
  11. package/build/src/core/http/abort.js.map +1 -1
  12. package/build/src/utils/external-signing/execute-external-transaction.d.ts +43 -10
  13. package/build/src/utils/external-signing/execute-external-transaction.d.ts.map +1 -1
  14. package/build/src/utils/external-signing/execute-external-transaction.js +42 -11
  15. package/build/src/utils/external-signing/execute-external-transaction.js.map +1 -1
  16. package/build/src/utils/external-signing/external-signing-client.d.ts +4 -0
  17. package/build/src/utils/external-signing/external-signing-client.d.ts.map +1 -1
  18. package/build/src/utils/external-signing/external-signing-client.js.map +1 -1
  19. package/build/src/wallets/abort.d.ts +17 -0
  20. package/build/src/wallets/abort.d.ts.map +1 -0
  21. package/build/src/wallets/abort.js +98 -0
  22. package/build/src/wallets/abort.js.map +1 -0
  23. package/build/src/wallets/cip103.d.ts +23 -2
  24. package/build/src/wallets/cip103.d.ts.map +1 -1
  25. package/build/src/wallets/cip103.js +107 -4
  26. package/build/src/wallets/cip103.js.map +1 -1
  27. package/build/src/wallets/da-utilities/client.d.ts +18 -9
  28. package/build/src/wallets/da-utilities/client.d.ts.map +1 -1
  29. package/build/src/wallets/da-utilities/client.js +33 -21
  30. package/build/src/wallets/da-utilities/client.js.map +1 -1
  31. package/build/src/wallets/discovery.d.ts +78 -0
  32. package/build/src/wallets/discovery.d.ts.map +1 -0
  33. package/build/src/wallets/discovery.js +364 -0
  34. package/build/src/wallets/discovery.js.map +1 -0
  35. package/build/src/wallets/errors.d.ts +64 -7
  36. package/build/src/wallets/errors.d.ts.map +1 -1
  37. package/build/src/wallets/errors.js +105 -9
  38. package/build/src/wallets/errors.js.map +1 -1
  39. package/build/src/wallets/index.d.ts +13 -5
  40. package/build/src/wallets/index.d.ts.map +1 -1
  41. package/build/src/wallets/index.js +21 -4
  42. package/build/src/wallets/index.js.map +1 -1
  43. package/build/src/wallets/ownership.d.ts +12 -0
  44. package/build/src/wallets/ownership.d.ts.map +1 -1
  45. package/build/src/wallets/ownership.js +29 -13
  46. package/build/src/wallets/ownership.js.map +1 -1
  47. package/build/src/wallets/session.d.ts +10 -2
  48. package/build/src/wallets/session.d.ts.map +1 -1
  49. package/build/src/wallets/session.js +186 -61
  50. package/build/src/wallets/session.js.map +1 -1
  51. package/build/src/wallets/store.d.ts +11 -3
  52. package/build/src/wallets/store.d.ts.map +1 -1
  53. package/build/src/wallets/store.js +25 -15
  54. package/build/src/wallets/store.js.map +1 -1
  55. package/build/src/wallets/wallet.d.ts +23 -12
  56. package/build/src/wallets/wallet.d.ts.map +1 -1
  57. package/build/src/wallets/wallet.js +76 -59
  58. package/build/src/wallets/wallet.js.map +1 -1
  59. package/package.json +107 -1
@@ -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;;;OAGG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAEhC,YACE,OAAO,EAAE,mBAAmB,EAC5B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAO,EAQ5E;CACF;AAKD,mHAAmH;AACnH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,4GAA4G;IAC5G,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAE9B,YAAY,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAKzC;CACF;AAED;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG,mBAAmB,GAAG,kBAAkB,GAAG,QAAQ,CAAC;AAExF,qDAAqD;AACrD,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;IACvC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C,+GAA+G;IAC/G,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,qGAAqG;IACrG,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,2GAA2G;IAC3G,QAAQ,CAAC,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IACzC,+EAA+E;IAC/E,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AAwBD,2GAA2G;AAC3G,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,sBAAsB,CAsD1E"}
@@ -1,8 +1,39 @@
1
1
  "use strict";
2
- /** Errors the wallets module throws. Each carries enough to decide whether a retry is safe. */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.WalletError = exports.RegistryResponseError = exports.RegistryApiError = exports.WalletSignError = exports.WalletReadError = exports.WalletSubmitError = void 0;
4
+ exports.isWalletError = isWalletError;
5
+ exports.isWalletSubmitError = isWalletSubmitError;
6
+ exports.isWalletReadError = isWalletReadError;
7
+ exports.isWalletSignError = isWalletSignError;
8
+ exports.isRegistryApiError = isRegistryApiError;
9
+ exports.isRegistryResponseError = isRegistryResponseError;
10
+ exports.isWalletCancellation = isWalletCancellation;
5
11
  exports.describeWalletError = describeWalletError;
12
+ /**
13
+ * Errors the wallets module throws. Each carries enough to decide whether a retry is safe.
14
+ *
15
+ * Match them with the guards (`isWalletError`, `isWalletSubmitError`, …), not `instanceof`: a page can load two copies
16
+ * of this module (two bundles, or two versions of the SDK), and an error thrown by one copy is not an `instanceof` the
17
+ * other copy's class. Every error class here carries a brand under a global symbol, which the guards check.
18
+ */
19
+ const abort_1 = require("../core/http/abort");
20
+ const abort_2 = require("./abort");
21
+ /** The brand every wallets error carries: a non-enumerable property under a global (`Symbol.for`) symbol. */
22
+ const WALLET_ERROR_BRAND = Symbol.for('@fairmint/canton-node-sdk/wallets.error');
23
+ function brand(error, name) {
24
+ Object.defineProperty(error, WALLET_ERROR_BRAND, { value: name, enumerable: false });
25
+ }
26
+ /** Whether `error` carries the brand `name`; never throws (a hostile proxy or getter answers false). */
27
+ function branded(error, name) {
28
+ if (typeof error !== 'object' || error === null)
29
+ return false;
30
+ try {
31
+ return error[WALLET_ERROR_BRAND] === name;
32
+ }
33
+ catch {
34
+ return false;
35
+ }
36
+ }
6
37
  const UNKNOWN_HINT = 'The outcome is unknown: do not resubmit blindly; check the wallet for the result first.';
7
38
  /** An `unknown` outcome's message: it warns against resubmitting and names the command id to look up, once each. */
8
39
  function unknownMessage(message, commandId) {
@@ -15,7 +46,11 @@ class WalletSubmitError extends Error {
15
46
  constructor(outcome, message, details = {}) {
16
47
  super(outcome === 'unknown' ? unknownMessage(message, details.commandId) : message);
17
48
  this.name = 'WalletSubmitError';
49
+ brand(this, 'WalletSubmitError');
18
50
  this.outcome = outcome;
51
+ this.category = details.category ?? (outcome === 'rejected-by-user' ? 'user-rejected' : 'unknown');
52
+ if (details.cantonErrorId !== undefined)
53
+ this.cantonErrorId = details.cantonErrorId;
19
54
  if (details.code !== undefined)
20
55
  this.code = details.code;
21
56
  if (details.commandId !== undefined)
@@ -32,6 +67,7 @@ class WalletReadError extends Error {
32
67
  constructor(message, code) {
33
68
  super(message);
34
69
  this.name = 'WalletReadError';
70
+ brand(this, 'WalletReadError');
35
71
  if (code !== undefined)
36
72
  this.code = code;
37
73
  this.rateLimited = code === LIMIT_EXCEEDED;
@@ -43,6 +79,7 @@ class WalletSignError extends Error {
43
79
  constructor(reason, message, code) {
44
80
  super(message);
45
81
  this.name = 'WalletSignError';
82
+ brand(this, 'WalletSignError');
46
83
  this.reason = reason;
47
84
  if (code !== undefined)
48
85
  this.code = code;
@@ -54,6 +91,7 @@ class RegistryApiError extends Error {
54
91
  constructor(status, body, url) {
55
92
  super(`Registry API ${status} for ${url}: ${body.slice(0, 500)}`);
56
93
  this.name = 'RegistryApiError';
94
+ brand(this, 'RegistryApiError');
57
95
  this.status = status;
58
96
  this.body = body;
59
97
  this.url = url;
@@ -65,6 +103,7 @@ class RegistryResponseError extends Error {
65
103
  constructor(message) {
66
104
  super(message);
67
105
  this.name = 'RegistryResponseError';
106
+ brand(this, 'RegistryResponseError');
68
107
  }
69
108
  }
70
109
  exports.RegistryResponseError = RegistryResponseError;
@@ -73,10 +112,53 @@ class WalletError extends Error {
73
112
  constructor(code, message) {
74
113
  super(message);
75
114
  this.name = 'WalletError';
115
+ brand(this, 'WalletError');
76
116
  this.code = code;
77
117
  }
78
118
  }
79
119
  exports.WalletError = WalletError;
120
+ /** Whether `error` is a {@link WalletError} of any copy of this module (a brand check, not `instanceof`). */
121
+ function isWalletError(error) {
122
+ return error instanceof WalletError || branded(error, 'WalletError');
123
+ }
124
+ /** Whether `error` is a {@link WalletSubmitError} of any copy of this module (a brand check, not `instanceof`). */
125
+ function isWalletSubmitError(error) {
126
+ return error instanceof WalletSubmitError || branded(error, 'WalletSubmitError');
127
+ }
128
+ /** Whether `error` is a {@link WalletReadError} of any copy of this module (a brand check, not `instanceof`). */
129
+ function isWalletReadError(error) {
130
+ return error instanceof WalletReadError || branded(error, 'WalletReadError');
131
+ }
132
+ /** Whether `error` is a {@link WalletSignError} of any copy of this module (a brand check, not `instanceof`). */
133
+ function isWalletSignError(error) {
134
+ return error instanceof WalletSignError || branded(error, 'WalletSignError');
135
+ }
136
+ /** Whether `error` is a {@link RegistryApiError} of any copy of this module (a brand check, not `instanceof`). */
137
+ function isRegistryApiError(error) {
138
+ return error instanceof RegistryApiError || branded(error, 'RegistryApiError');
139
+ }
140
+ /** Whether `error` is a {@link RegistryResponseError} of any copy of this module (a brand check, not `instanceof`). */
141
+ function isRegistryResponseError(error) {
142
+ return error instanceof RegistryResponseError || branded(error, 'RegistryResponseError');
143
+ }
144
+ /**
145
+ * Whether `error` is a cancellation: the `AbortError` an aborted `signal` makes a wallets call throw (also a
146
+ * `TimeoutError` from `AbortSignal.timeout`, which `fetch` passes through).
147
+ */
148
+ function isWalletCancellation(error) {
149
+ if ((0, abort_1.isAbortError)(error))
150
+ return true;
151
+ // A `DOMException` from `AbortController` or `fetch`, possibly of another realm, so not matched by `instanceof`.
152
+ if (typeof error !== 'object' || error === null)
153
+ return false;
154
+ try {
155
+ const { name } = error;
156
+ return name === 'AbortError' || name === 'TimeoutError';
157
+ }
158
+ catch {
159
+ return false;
160
+ }
161
+ }
80
162
  /** How many characters of a registry error body {@link describeWalletError} shows. */
81
163
  const REGISTRY_BODY_CHARS = 300;
82
164
  function described(kind, message, code) {
@@ -95,38 +177,52 @@ function thrownText(error) {
95
177
  }
96
178
  /** A user-facing sentence and a kind for any error the wallets module throws (or anything else thrown). */
97
179
  function describeWalletError(error) {
98
- if (error instanceof WalletSubmitError) {
180
+ if (isWalletSubmitError(error)) {
181
+ const submit = {
182
+ category: error.category,
183
+ ...(error.cantonErrorId !== undefined && { cantonErrorId: error.cantonErrorId }),
184
+ };
99
185
  switch (error.outcome) {
100
186
  case 'rejected-by-user':
101
- return described('declined', 'You declined in the wallet. Nothing was submitted.', error.code);
187
+ return {
188
+ ...described('declined', 'You declined in the wallet. Nothing was submitted.', error.code),
189
+ ...submit,
190
+ };
102
191
  case 'failed':
103
- return described('not-committed', `Not committed: ${error.message}`, error.code);
192
+ return { ...described('not-committed', `Not committed: ${error.message}`, error.code), ...submit };
104
193
  case 'unknown':
105
194
  // The message already says not to resubmit blindly, and names the command id.
106
195
  return {
107
196
  ...described('outcome-unknown', error.message, error.code),
108
197
  ...(error.commandId !== undefined && { commandId: error.commandId }),
109
198
  ...(error.burnReference !== undefined && { burnReference: error.burnReference }),
199
+ ...submit,
110
200
  };
111
201
  }
112
202
  }
113
- if (error instanceof WalletReadError) {
203
+ if (isWalletReadError(error)) {
114
204
  return error.rateLimited
115
205
  ? described('rate-limited', `The wallet is limiting how often this page reads the ledger (CIP-0103 -32005), and it still refused after a few retries. Wait a moment, then retry. Details: ${error.message}`, error.code)
116
206
  : described('read-failed', `The wallet did not answer a read: ${error.message}`, error.code);
117
207
  }
118
- if (error instanceof WalletSignError) {
208
+ if (isWalletSignError(error)) {
119
209
  return error.reason === 'rejected-by-user'
120
210
  ? described('declined', 'You declined to sign in the wallet. Nothing was verified.', error.code)
121
211
  : described('sign-failed', `The wallet did not sign: ${error.message}`, error.code);
122
212
  }
123
- if (error instanceof RegistryApiError) {
213
+ if (isRegistryApiError(error)) {
124
214
  return described('registry', `DA's registry answered ${error.status}: ${error.body.slice(0, REGISTRY_BODY_CHARS)}`, error.status);
125
215
  }
126
- if (error instanceof RegistryResponseError)
216
+ if (isRegistryResponseError(error))
127
217
  return described('registry', error.message);
128
- if (error instanceof WalletError)
218
+ if (isWalletError(error))
129
219
  return described('refused', error.message, error.code);
220
+ if ((0, abort_2.isCancelledBeforeSubmit)(error))
221
+ return described('cancelled', 'Cancelled. Nothing was submitted.');
222
+ // A foreign `AbortError` or `TimeoutError` (a wallet's, or `fetch`'s) may have been raised after a submission was sent.
223
+ if (isWalletCancellation(error)) {
224
+ return described('cancelled', 'Cancelled; this does not say whether anything was submitted.');
225
+ }
130
226
  if (error instanceof Error)
131
227
  return described('other', error.message);
132
228
  return described('other', thrownText(error));
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/wallets/errors.ts"],"names":[],"mappings":";AAAA,+FAA+F;;;;AAS/F,MAAM,YAAY,GAAG,yFAAyF,CAAC;AAE/G,oHAAoH;AACpH,SAAS,cAAc,CAAC,OAAe,EAAE,SAA6B;IACpE,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,IAAI,YAAY,EAAE,CAAC;IACvF,MAAM,WAAW,GAAG,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,SAAS,GAAG,CAAC;IAC/E,OAAO,WAAW,KAAK,EAAE,IAAI,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,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ACvG,wHAAwH;IACxH,IAAI,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO,SAAS,CAAC,WAAW,EAAE,8DAA8D,CAAC,CAAC;IAChG,CAAC;IACD,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACrE,OAAO,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/C,CAAC"}
@@ -1,22 +1,30 @@
1
1
  /**
2
2
  * Browser-safe DA Utility Registry holder actions through any CIP-0103 (Canton dApp API) wallet provider. In a browser
3
- * bundle import `@fairmint/canton-node-sdk/build/src/wallets/index.js`, which loads none of the SDK's Node
4
- * dependencies; the package root also exports it as the `Wallets` namespace (for Node).
3
+ * bundle import `@fairmint/canton-node-sdk/wallets`, which loads none of the SDK's Node dependencies (the deep path
4
+ * `@fairmint/canton-node-sdk/build/src/wallets/index.js` still works); the package root also exports it as the
5
+ * `Wallets` namespace (for Node).
5
6
  *
7
+ * - `discoverCip103Wallets()`: the CIP-0103 wallet extensions installed in the browser, each with `load(network)` that
8
+ * resolves its provider (the dApp SDK's announce handshake and message channel, no dependency).
6
9
  * - `createCip103Session({ network })`: which wallet is connected, as which party (`connect`, `restore`, `disconnect`).
7
10
  * - `createWalletStore({ session })`: the page's observable state, typed actions (`act`), notices to show.
8
11
  * - `createWallet(...)`: one party's token actions, for code that does not need the store.
9
12
  * - The ownership proof's browser half (`requestWalletOwnershipVerdict`); the server half
10
13
  * (`createWalletOwnershipChallenger`, `verifyWalletOwnership`) is Node-only and exported from the package root.
11
- * - The errors, their user-facing descriptions (`describeWalletError`), and the data types.
14
+ * - The errors, their guards (`isWalletError`, `isWalletSubmitError`, …: they match errors of any copy of this module,
15
+ * where `instanceof` does not), their user-facing descriptions (`describeWalletError`), and the data types.
16
+ * - Cancellation: every call that reads, fetches or acts takes an optional `signal` (`WalletCallOptions`):
17
+ * `WalletStore.act`, `Cip103Session.connect` and `restore`, `DiscoveredWallet.load` included. `WalletStore.dispose()`
18
+ * cancels the store's own work in flight the same way.
12
19
  */
13
20
  export { createCip103Session, type Cip103Session, type Cip103SessionOptions, type Cip103SessionState, type ConnectedWallet, } from './session';
14
21
  export { canAct, createWalletStore, walletActionKey, type ActionOutcome, type ActionResultOf, type UnknownOutcome, type WalletAction, type WalletActionResults, type WalletNotice, type WalletStore, type WalletStoreOptions, type WalletView, } from './store';
15
- export { createWallet, type BurnRequestOptions, type BurnRequestResult, type TransferOffers, type TransferPlan, type TransferPreapprovalOptions, type TransferRequest, type TransferResult, type Wallet, type WalletOptions, type WalletState, } from './wallet';
22
+ export { createWallet, type BurnRequestOptions, type BurnRequestResult, type TransferOffers, type TransferPlan, type TransferPreapprovalOptions, type TransferRequest, type TransferResult, type Wallet, type WalletCallOptions, type WalletOptions, type WalletState, } from './wallet';
16
23
  export type { Cip103Connection, Cip103EventListener, Cip103Provider, Cip103Request } from './cip103';
24
+ export { discoverCip103Wallets, INJECTED_WALLET_ID, type Cip103DiscoveryHost, type DiscoverCip103WalletsOptions, type DiscoveredWallet, } from './discovery';
17
25
  export { buildWalletOwnershipMessage, proveWalletOwnership, requestWalletOwnershipVerdict, type ProveWalletOwnershipOptions, type RequestWalletOwnershipVerdictOptions, type WalletOwnershipChallenge, type WalletOwnershipChallengeFailure, type WalletOwnershipChallengeResponse, type WalletOwnershipFailure, type WalletOwnershipMessageFields, type WalletOwnershipProof, type WalletOwnershipVerdict, } from './ownership';
18
26
  export type { DaNetwork, DaRegistryOptions, FetchLike, TransferKind } from './da-utilities/client';
19
- export { describeWalletError, RegistryApiError, RegistryResponseError, WalletError, WalletReadError, WalletSignError, WalletSubmitError, type WalletErrorCode, type WalletErrorDescription, type WalletSignErrorReason, type WalletSubmitOutcome, } from './errors';
27
+ export { describeWalletError, isRegistryApiError, isRegistryResponseError, isWalletCancellation, isWalletError, isWalletReadError, isWalletSignError, isWalletSubmitError, RegistryApiError, RegistryResponseError, WalletError, WalletReadError, WalletSignError, WalletSubmitError, type WalletErrorCode, type WalletErrorDescription, type WalletSignErrorReason, type WalletSubmitCategory, type WalletSubmitErrorDetails, type WalletSubmitOutcome, } from './errors';
20
28
  export type { BurnRequest, MintOffer, TransferOffer, TransferPreapproval } from './contracts';
21
29
  export type { Holding, InstrumentBalance, InstrumentMetadata } from './holdings';
22
30
  export type { InstrumentId, SubmitResult } from './types';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/wallets/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,eAAe,GACrB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,MAAM,EACN,iBAAiB,EACjB,eAAe,EACf,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,UAAU,GAChB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,YAAY,EACZ,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,0BAA0B,EAC/B,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,WAAW,GACjB,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACrG,OAAO,EACL,2BAA2B,EAC3B,oBAAoB,EACpB,6BAA6B,EAC7B,KAAK,2BAA2B,EAChC,KAAK,oCAAoC,EACzC,KAAK,wBAAwB,EAC7B,KAAK,+BAA+B,EACpC,KAAK,gCAAgC,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B,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACjF,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC"}
@@ -1,17 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseDecimalUnits = exports.formatDecimalUnits = exports.WalletSubmitError = exports.WalletSignError = exports.WalletReadError = exports.WalletError = exports.RegistryResponseError = exports.RegistryApiError = exports.describeWalletError = exports.requestWalletOwnershipVerdict = exports.proveWalletOwnership = exports.buildWalletOwnershipMessage = exports.createWallet = exports.walletActionKey = exports.createWalletStore = exports.canAct = exports.createCip103Session = void 0;
3
+ exports.parseDecimalUnits = exports.formatDecimalUnits = exports.WalletSubmitError = exports.WalletSignError = exports.WalletReadError = exports.WalletError = exports.RegistryResponseError = exports.RegistryApiError = exports.isWalletSubmitError = exports.isWalletSignError = exports.isWalletReadError = exports.isWalletError = exports.isWalletCancellation = exports.isRegistryResponseError = exports.isRegistryApiError = exports.describeWalletError = exports.requestWalletOwnershipVerdict = exports.proveWalletOwnership = exports.buildWalletOwnershipMessage = exports.INJECTED_WALLET_ID = exports.discoverCip103Wallets = exports.createWallet = exports.walletActionKey = exports.createWalletStore = exports.canAct = exports.createCip103Session = void 0;
4
4
  /**
5
5
  * Browser-safe DA Utility Registry holder actions through any CIP-0103 (Canton dApp API) wallet provider. In a browser
6
- * bundle import `@fairmint/canton-node-sdk/build/src/wallets/index.js`, which loads none of the SDK's Node
7
- * dependencies; the package root also exports it as the `Wallets` namespace (for Node).
6
+ * bundle import `@fairmint/canton-node-sdk/wallets`, which loads none of the SDK's Node dependencies (the deep path
7
+ * `@fairmint/canton-node-sdk/build/src/wallets/index.js` still works); the package root also exports it as the
8
+ * `Wallets` namespace (for Node).
8
9
  *
10
+ * - `discoverCip103Wallets()`: the CIP-0103 wallet extensions installed in the browser, each with `load(network)` that
11
+ * resolves its provider (the dApp SDK's announce handshake and message channel, no dependency).
9
12
  * - `createCip103Session({ network })`: which wallet is connected, as which party (`connect`, `restore`, `disconnect`).
10
13
  * - `createWalletStore({ session })`: the page's observable state, typed actions (`act`), notices to show.
11
14
  * - `createWallet(...)`: one party's token actions, for code that does not need the store.
12
15
  * - The ownership proof's browser half (`requestWalletOwnershipVerdict`); the server half
13
16
  * (`createWalletOwnershipChallenger`, `verifyWalletOwnership`) is Node-only and exported from the package root.
14
- * - The errors, their user-facing descriptions (`describeWalletError`), and the data types.
17
+ * - The errors, their guards (`isWalletError`, `isWalletSubmitError`, …: they match errors of any copy of this module,
18
+ * where `instanceof` does not), their user-facing descriptions (`describeWalletError`), and the data types.
19
+ * - Cancellation: every call that reads, fetches or acts takes an optional `signal` (`WalletCallOptions`):
20
+ * `WalletStore.act`, `Cip103Session.connect` and `restore`, `DiscoveredWallet.load` included. `WalletStore.dispose()`
21
+ * cancels the store's own work in flight the same way.
15
22
  */
16
23
  var session_1 = require("./session");
17
24
  Object.defineProperty(exports, "createCip103Session", { enumerable: true, get: function () { return session_1.createCip103Session; } });
@@ -21,12 +28,22 @@ Object.defineProperty(exports, "createWalletStore", { enumerable: true, get: fun
21
28
  Object.defineProperty(exports, "walletActionKey", { enumerable: true, get: function () { return store_1.walletActionKey; } });
22
29
  var wallet_1 = require("./wallet");
23
30
  Object.defineProperty(exports, "createWallet", { enumerable: true, get: function () { return wallet_1.createWallet; } });
31
+ var discovery_1 = require("./discovery");
32
+ Object.defineProperty(exports, "discoverCip103Wallets", { enumerable: true, get: function () { return discovery_1.discoverCip103Wallets; } });
33
+ Object.defineProperty(exports, "INJECTED_WALLET_ID", { enumerable: true, get: function () { return discovery_1.INJECTED_WALLET_ID; } });
24
34
  var ownership_1 = require("./ownership");
25
35
  Object.defineProperty(exports, "buildWalletOwnershipMessage", { enumerable: true, get: function () { return ownership_1.buildWalletOwnershipMessage; } });
26
36
  Object.defineProperty(exports, "proveWalletOwnership", { enumerable: true, get: function () { return ownership_1.proveWalletOwnership; } });
27
37
  Object.defineProperty(exports, "requestWalletOwnershipVerdict", { enumerable: true, get: function () { return ownership_1.requestWalletOwnershipVerdict; } });
28
38
  var errors_1 = require("./errors");
29
39
  Object.defineProperty(exports, "describeWalletError", { enumerable: true, get: function () { return errors_1.describeWalletError; } });
40
+ Object.defineProperty(exports, "isRegistryApiError", { enumerable: true, get: function () { return errors_1.isRegistryApiError; } });
41
+ Object.defineProperty(exports, "isRegistryResponseError", { enumerable: true, get: function () { return errors_1.isRegistryResponseError; } });
42
+ Object.defineProperty(exports, "isWalletCancellation", { enumerable: true, get: function () { return errors_1.isWalletCancellation; } });
43
+ Object.defineProperty(exports, "isWalletError", { enumerable: true, get: function () { return errors_1.isWalletError; } });
44
+ Object.defineProperty(exports, "isWalletReadError", { enumerable: true, get: function () { return errors_1.isWalletReadError; } });
45
+ Object.defineProperty(exports, "isWalletSignError", { enumerable: true, get: function () { return errors_1.isWalletSignError; } });
46
+ Object.defineProperty(exports, "isWalletSubmitError", { enumerable: true, get: function () { return errors_1.isWalletSubmitError; } });
30
47
  Object.defineProperty(exports, "RegistryApiError", { enumerable: true, get: function () { return errors_1.RegistryApiError; } });
31
48
  Object.defineProperty(exports, "RegistryResponseError", { enumerable: true, get: function () { return errors_1.RegistryResponseError; } });
32
49
  Object.defineProperty(exports, "WalletError", { enumerable: true, get: function () { return errors_1.WalletError; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/wallets/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;GAWG;AACH,qCAMmB;AALjB,8GAAA,mBAAmB,OAAA;AAMrB,iCAaiB;AAZf,+FAAA,MAAM,OAAA;AACN,0GAAA,iBAAiB,OAAA;AACjB,wGAAA,eAAe,OAAA;AAWjB,mCAYkB;AAXhB,sGAAA,YAAY,OAAA;AAad,yCAaqB;AAZnB,wHAAA,2BAA2B,OAAA;AAC3B,iHAAA,oBAAo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6 +70,12 @@ export interface ProveWalletOwnershipOptions {
70
70
  readonly challenge: WalletOwnershipChallenge;
71
71
  /** Defaults to the system clock; an expired challenge is refused before anything is signed. */
72
72
  readonly now?: () => Date;
73
+ /**
74
+ * Cancels the proof: once aborted, the call rejects with an `AbortError` and the wallet is not asked to sign. A
75
+ * signature request already shown to the user is not withdrawn (CIP-0103 has no cancellation); its answer is
76
+ * ignored.
77
+ */
78
+ readonly signal?: AbortSignal;
73
79
  }
74
80
  /**
75
81
  * Ask the wallet to sign the ownership message for the challenge, as the connection's party. CIP-0103 wallets sign with
@@ -138,6 +144,12 @@ export interface RequestWalletOwnershipVerdictOptions {
138
144
  readonly challengeUrl: string;
139
145
  /** Answers `POST { token, proof }` with `{ data: WalletOwnershipVerdict }`. */
140
146
  readonly verifyUrl: string;
147
+ /**
148
+ * Cancels the check (for example when the user leaves the page): once aborted, the call rejects with an `AbortError`,
149
+ * the requests in flight get the signal, and nothing more is sent. A signature request already shown to the user is
150
+ * not withdrawn (CIP-0103 has no cancellation); a proof signed after the abort is never sent.
151
+ */
152
+ readonly signal?: AbortSignal;
141
153
  }
142
154
  /**
143
155
  * The browser half of an ownership check, against a server that uses the SDK's challenger (or the same wire format: a
@@ -1 +1 @@
1
- {"version":3,"file":"ownership.d.ts","sourceRoot":"","sources":["../../../src/wallets/ownership.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAOL,KAAK,gBAAgB,EACtB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAIpE,iDAAiD;AACjD,eAAO,MAAM,sBAAsB,kCAAkC,CAAC;AACtE,uDAAuD;AACvD,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAE5C,kHAAkH;AAClH,MAAM,WAAW,wBAAwB;IACvC,oGAAoG;IACpG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,kFAAkF;IAClF,QAAQ,CAAC,KAAK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;;;GAMG;AACH,wBAAsB,6BAA6B,CACjD,UAAU,EAAE,gBAAgB,EAC5B,OAAO,EAAE,oCAAoC,GAC5C,OAAO,CAAC,sBAAsB,CAAC,CAuBjC"}
@@ -24,6 +24,8 @@ exports.requestWalletOwnershipVerdict = requestWalletOwnershipVerdict;
24
24
  * network proven must look the party up on that network (its Scan or ledger party and topology APIs).
25
25
  */
26
26
  const cip103_1 = require("./cip103");
27
+ const abort_1 = require("./abort");
28
+ const abort_2 = require("../core/http/abort");
27
29
  const client_1 = require("./da-utilities/client");
28
30
  const errors_1 = require("./errors");
29
31
  const json_1 = require("./json");
@@ -156,8 +158,9 @@ function readSignature(raw) {
156
158
  */
157
159
  async function proveWalletOwnership(connection, options) {
158
160
  const { provider, partyId, network } = connection;
159
- const { challenge } = options;
160
- const account = await (0, cip103_1.primaryAccount)(provider);
161
+ const { challenge, signal } = options;
162
+ (0, abort_1.throwIfAborted)(signal);
163
+ const account = await (0, abort_1.awaitWithAbort)(async () => (0, cip103_1.primaryAccount)(provider, { signal }), signal);
161
164
  if (account.partyId !== partyId) {
162
165
  throw new errors_1.WalletSignError('invalid-challenge', `The wallet's primary account is ${account.partyId}, not ${partyId}; switch accounts in the wallet first`);
163
166
  }
@@ -189,11 +192,14 @@ async function proveWalletOwnership(connection, options) {
189
192
  if (!(now < Date.parse(challenge.expiresAt))) {
190
193
  throw new errors_1.WalletSignError('invalid-challenge', 'The ownership challenge has expired; ask the server for a new one');
191
194
  }
195
+ (0, abort_1.throwIfAborted)(signal);
192
196
  let raw;
193
197
  try {
194
- raw = await provider.request({ method: 'signMessage', params: { message } });
198
+ raw = await (0, abort_2.awaitWithAbort)(async () => provider.request({ method: 'signMessage', params: { message } }, { signal }), signal);
195
199
  }
196
200
  catch (error) {
201
+ if (signal?.aborted === true)
202
+ throw error;
197
203
  const code = (0, cip103_1.cip103ErrorCode)(error);
198
204
  if (code === cip103_1.CIP103_ERROR_CODES.userRejected) {
199
205
  throw new errors_1.WalletSignError('rejected-by-user', `The user declined to sign the ownership message: ${(0, cip103_1.describeError)(error)}`, code);
@@ -226,15 +232,23 @@ function isWalletOwnershipVerdict(value, partyId) {
226
232
  return value['verified'] === false && typeof value['reason'] === 'string' && typeof value['message'] === 'string';
227
233
  }
228
234
  /** POST `body` as JSON and return the response's `data`; throws on a non-2xx answer or one without `data`. */
229
- async function postForData(fetch, url, body) {
230
- const response = await fetch(url, {
231
- method: 'POST',
232
- headers: { 'content-type': 'application/json' },
233
- body: JSON.stringify(body),
234
- });
235
+ async function postForData(fetch, url, body, signal,
236
+ /** Whether the request carries the signed proof: an abort after it is sent is not a cancellation before submit. */
237
+ carriesProof) {
238
+ (0, abort_1.throwIfAborted)(signal);
239
+ const race = carriesProof ? abort_2.awaitWithAbort : abort_1.awaitWithAbort;
240
+ const { response, text } = await race(async () => {
241
+ const answer = await fetch(url, {
242
+ method: 'POST',
243
+ headers: { 'content-type': 'application/json' },
244
+ body: JSON.stringify(body),
245
+ ...(signal !== undefined && { signal }),
246
+ });
247
+ return { response: answer, text: await answer.text() };
248
+ }, signal);
235
249
  let json;
236
250
  try {
237
- json = JSON.parse(await response.text());
251
+ json = JSON.parse(text);
238
252
  }
239
253
  catch {
240
254
  json = undefined;
@@ -256,7 +270,9 @@ async function postForData(fetch, url, body) {
256
270
  async function requestWalletOwnershipVerdict(connection, options) {
257
271
  const { partyId, network } = connection;
258
272
  const send = options.fetch ?? (0, client_1.globalFetch)('{ fetch } to requestWalletOwnershipVerdict');
259
- const issued = await postForData(send, options.challengeUrl, { network, partyId });
273
+ const { signal } = options;
274
+ (0, abort_1.throwIfAborted)(signal);
275
+ const issued = await postForData(send, options.challengeUrl, { network, partyId }, signal, false);
260
276
  if (!(0, json_1.isRecord)(issued) || !(0, json_1.isRecord)(issued['challenge']) || typeof issued['token'] !== 'string') {
261
277
  throw new Error('The server answered the ownership challenge request without { challenge, token }');
262
278
  }
@@ -265,8 +281,8 @@ async function requestWalletOwnershipVerdict(connection, options) {
265
281
  if (challenge.network !== (0, cip103_1.cip103NetworkId)(network)) {
266
282
  throw new errors_1.WalletSignError('invalid-challenge', `The server issued a challenge for ${String(challenge.network)}, not ${(0, cip103_1.cip103NetworkId)(network)}`);
267
283
  }
268
- const proof = await proveWalletOwnership(connection, { challenge });
269
- const verdict = await postForData(send, options.verifyUrl, { token: issued['token'], proof });
284
+ const proof = await proveWalletOwnership(connection, { challenge, ...(signal !== undefined && { signal }) });
285
+ const verdict = await postForData(send, options.verifyUrl, { token: issued['token'], proof }, signal, true);
270
286
  if (!isWalletOwnershipVerdict(verdict, partyId)) {
271
287
  throw new Error('The server answered the ownership proof without a well-formed verdict for the party');
272
288
  }