@fairmint/canton-node-sdk 0.0.287 → 0.0.289

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 (135) hide show
  1. package/README.md +131 -12
  2. package/build/src/clients/ledger-json-api/operations/v2/parties/external/allocate-external-party.d.ts +10 -2
  3. package/build/src/clients/ledger-json-api/operations/v2/parties/external/allocate-external-party.d.ts.map +1 -1
  4. package/build/src/clients/ledger-json-api/operations/v2/parties/external/allocate-external-party.js +27 -3
  5. package/build/src/clients/ledger-json-api/operations/v2/parties/external/allocate-external-party.js.map +1 -1
  6. package/build/src/clients/ledger-json-api/operations/v2/users/delete-user.js +1 -1
  7. package/build/src/clients/ledger-json-api/operations/v2/users/delete-user.js.map +1 -1
  8. package/build/src/clients/ledger-json-api/operations/v2/users/get-user.js +1 -1
  9. package/build/src/clients/ledger-json-api/operations/v2/users/get-user.js.map +1 -1
  10. package/build/src/clients/ledger-json-api/operations/v2/users/grant-user-rights.d.ts +2 -0
  11. package/build/src/clients/ledger-json-api/operations/v2/users/grant-user-rights.d.ts.map +1 -1
  12. package/build/src/clients/ledger-json-api/operations/v2/users/grant-user-rights.js +5 -6
  13. package/build/src/clients/ledger-json-api/operations/v2/users/grant-user-rights.js.map +1 -1
  14. package/build/src/clients/ledger-json-api/operations/v2/users/list-user-rights.d.ts +3 -0
  15. package/build/src/clients/ledger-json-api/operations/v2/users/list-user-rights.d.ts.map +1 -1
  16. package/build/src/clients/ledger-json-api/operations/v2/users/list-user-rights.js +5 -3
  17. package/build/src/clients/ledger-json-api/operations/v2/users/list-user-rights.js.map +1 -1
  18. package/build/src/clients/ledger-json-api/operations/v2/users/revoke-user-rights.js +1 -1
  19. package/build/src/clients/ledger-json-api/operations/v2/users/revoke-user-rights.js.map +1 -1
  20. package/build/src/clients/ledger-json-api/operations/v2/users/update-user-identity-provider.js +1 -1
  21. package/build/src/clients/ledger-json-api/operations/v2/users/update-user-identity-provider.js.map +1 -1
  22. package/build/src/clients/ledger-json-api/operations/v2/users/update-user.js +1 -1
  23. package/build/src/clients/ledger-json-api/operations/v2/users/update-user.js.map +1 -1
  24. package/build/src/clients/ledger-json-api/schemas/operations/users.d.ts +2 -0
  25. package/build/src/clients/ledger-json-api/schemas/operations/users.d.ts.map +1 -1
  26. package/build/src/clients/ledger-json-api/schemas/operations/users.js +4 -0
  27. package/build/src/clients/ledger-json-api/schemas/operations/users.js.map +1 -1
  28. package/build/src/clients/scan-api/ScanApiClient.d.ts.map +1 -1
  29. package/build/src/clients/scan-api/ScanApiClient.js +2 -1
  30. package/build/src/clients/scan-api/ScanApiClient.js.map +1 -1
  31. package/build/src/core/http/HttpClient.d.ts.map +1 -1
  32. package/build/src/core/http/HttpClient.js +2 -1
  33. package/build/src/core/http/HttpClient.js.map +1 -1
  34. package/build/src/core/http/abort.d.ts +1 -3
  35. package/build/src/core/http/abort.d.ts.map +1 -1
  36. package/build/src/core/http/abort.js +6 -4
  37. package/build/src/core/http/abort.js.map +1 -1
  38. package/build/src/utils/external-signing/allocate-external-party.d.ts +2 -0
  39. package/build/src/utils/external-signing/allocate-external-party.d.ts.map +1 -1
  40. package/build/src/utils/external-signing/allocate-external-party.js +1 -0
  41. package/build/src/utils/external-signing/allocate-external-party.js.map +1 -1
  42. package/build/src/utils/external-signing/allocation-user-id.d.ts +6 -0
  43. package/build/src/utils/external-signing/allocation-user-id.d.ts.map +1 -0
  44. package/build/src/utils/external-signing/allocation-user-id.js +18 -0
  45. package/build/src/utils/external-signing/allocation-user-id.js.map +1 -0
  46. package/build/src/utils/external-signing/create-external-party.d.ts +6 -0
  47. package/build/src/utils/external-signing/create-external-party.d.ts.map +1 -1
  48. package/build/src/utils/external-signing/create-external-party.js +4 -1
  49. package/build/src/utils/external-signing/create-external-party.js.map +1 -1
  50. package/build/src/utils/external-signing/execute-external-transaction.d.ts +43 -10
  51. package/build/src/utils/external-signing/execute-external-transaction.d.ts.map +1 -1
  52. package/build/src/utils/external-signing/execute-external-transaction.js +42 -11
  53. package/build/src/utils/external-signing/execute-external-transaction.js.map +1 -1
  54. package/build/src/utils/external-signing/external-party-onboarding.d.ts +24 -0
  55. package/build/src/utils/external-signing/external-party-onboarding.d.ts.map +1 -1
  56. package/build/src/utils/external-signing/external-party-onboarding.js +71 -0
  57. package/build/src/utils/external-signing/external-party-onboarding.js.map +1 -1
  58. package/build/src/utils/external-signing/external-party-wallet.d.ts +110 -0
  59. package/build/src/utils/external-signing/external-party-wallet.d.ts.map +1 -1
  60. package/build/src/utils/external-signing/external-party-wallet.js +173 -1
  61. package/build/src/utils/external-signing/external-party-wallet.js.map +1 -1
  62. package/build/src/utils/external-signing/external-signing-client.d.ts +10 -0
  63. package/build/src/utils/external-signing/external-signing-client.d.ts.map +1 -1
  64. package/build/src/utils/external-signing/external-signing-client.js +4 -0
  65. package/build/src/utils/external-signing/external-signing-client.js.map +1 -1
  66. package/build/src/utils/token-standard/v1/holdings.d.ts +3 -9
  67. package/build/src/utils/token-standard/v1/holdings.d.ts.map +1 -1
  68. package/build/src/utils/token-standard/v1/holdings.js +6 -74
  69. package/build/src/utils/token-standard/v1/holdings.js.map +1 -1
  70. package/build/src/wallets/abort.d.ts +17 -0
  71. package/build/src/wallets/abort.d.ts.map +1 -0
  72. package/build/src/wallets/abort.js +98 -0
  73. package/build/src/wallets/abort.js.map +1 -0
  74. package/build/src/wallets/acs.d.ts.map +1 -1
  75. package/build/src/wallets/acs.js +21 -0
  76. package/build/src/wallets/acs.js.map +1 -1
  77. package/build/src/wallets/amulet/constants.d.ts +33 -0
  78. package/build/src/wallets/amulet/constants.d.ts.map +1 -0
  79. package/build/src/wallets/amulet/constants.js +34 -0
  80. package/build/src/wallets/amulet/constants.js.map +1 -0
  81. package/build/src/wallets/amulet/registry.d.ts +65 -0
  82. package/build/src/wallets/amulet/registry.d.ts.map +1 -0
  83. package/build/src/wallets/amulet/registry.js +187 -0
  84. package/build/src/wallets/amulet/registry.js.map +1 -0
  85. package/build/src/wallets/cip103.d.ts +40 -5
  86. package/build/src/wallets/cip103.d.ts.map +1 -1
  87. package/build/src/wallets/cip103.js +126 -10
  88. package/build/src/wallets/cip103.js.map +1 -1
  89. package/build/src/wallets/contracts.d.ts +32 -3
  90. package/build/src/wallets/contracts.d.ts.map +1 -1
  91. package/build/src/wallets/contracts.js +48 -11
  92. package/build/src/wallets/contracts.js.map +1 -1
  93. package/build/src/wallets/da-utilities/client.d.ts +22 -9
  94. package/build/src/wallets/da-utilities/client.d.ts.map +1 -1
  95. package/build/src/wallets/da-utilities/client.js +35 -21
  96. package/build/src/wallets/da-utilities/client.js.map +1 -1
  97. package/build/src/wallets/discovery.d.ts +78 -0
  98. package/build/src/wallets/discovery.d.ts.map +1 -0
  99. package/build/src/wallets/discovery.js +364 -0
  100. package/build/src/wallets/discovery.js.map +1 -0
  101. package/build/src/wallets/errors.d.ts +67 -8
  102. package/build/src/wallets/errors.d.ts.map +1 -1
  103. package/build/src/wallets/errors.js +108 -11
  104. package/build/src/wallets/errors.js.map +1 -1
  105. package/build/src/wallets/holding-view.d.ts +47 -0
  106. package/build/src/wallets/holding-view.d.ts.map +1 -0
  107. package/build/src/wallets/holding-view.js +121 -0
  108. package/build/src/wallets/holding-view.js.map +1 -0
  109. package/build/src/wallets/holdings.d.ts +38 -5
  110. package/build/src/wallets/holdings.d.ts.map +1 -1
  111. package/build/src/wallets/holdings.js +84 -15
  112. package/build/src/wallets/holdings.js.map +1 -1
  113. package/build/src/wallets/index.d.ts +25 -7
  114. package/build/src/wallets/index.d.ts.map +1 -1
  115. package/build/src/wallets/index.js +38 -4
  116. package/build/src/wallets/index.js.map +1 -1
  117. package/build/src/wallets/ownership.d.ts +12 -0
  118. package/build/src/wallets/ownership.d.ts.map +1 -1
  119. package/build/src/wallets/ownership.js +29 -13
  120. package/build/src/wallets/ownership.js.map +1 -1
  121. package/build/src/wallets/session.d.ts +10 -2
  122. package/build/src/wallets/session.d.ts.map +1 -1
  123. package/build/src/wallets/session.js +186 -61
  124. package/build/src/wallets/session.js.map +1 -1
  125. package/build/src/wallets/store.d.ts +14 -3
  126. package/build/src/wallets/store.d.ts.map +1 -1
  127. package/build/src/wallets/store.js +36 -16
  128. package/build/src/wallets/store.js.map +1 -1
  129. package/build/src/wallets/types.d.ts +14 -0
  130. package/build/src/wallets/types.d.ts.map +1 -1
  131. package/build/src/wallets/wallet.d.ts +53 -16
  132. package/build/src/wallets/wallet.d.ts.map +1 -1
  133. package/build/src/wallets/wallet.js +271 -93
  134. package/build/src/wallets/wallet.js.map +1 -1
  135. 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 {
@@ -52,7 +86,9 @@ export declare class RegistryApiError extends Error {
52
86
  readonly status: number;
53
87
  readonly body: string;
54
88
  readonly url: string;
55
- constructor(status: number, body: string, url: string);
89
+ /** Which registry answered, as `describeWalletError` names it (`DA's registry`, `The Canton Coin registry`). */
90
+ readonly registry: string;
91
+ constructor(status: number, body: string, url: string, registry?: string);
56
92
  }
57
93
  /** A registry API answered 2xx with a body this module refuses (wrong shape, unexpected factory). */
58
94
  export declare class RegistryResponseError extends Error {
@@ -72,6 +108,23 @@ export declare class WalletError extends Error {
72
108
  readonly code: WalletErrorCode;
73
109
  constructor(code: WalletErrorCode, message: string);
74
110
  }
111
+ /** Whether `error` is a {@link WalletError} of any copy of this module (a brand check, not `instanceof`). */
112
+ export declare function isWalletError(error: unknown): error is WalletError;
113
+ /** Whether `error` is a {@link WalletSubmitError} of any copy of this module (a brand check, not `instanceof`). */
114
+ export declare function isWalletSubmitError(error: unknown): error is WalletSubmitError;
115
+ /** Whether `error` is a {@link WalletReadError} of any copy of this module (a brand check, not `instanceof`). */
116
+ export declare function isWalletReadError(error: unknown): error is WalletReadError;
117
+ /** Whether `error` is a {@link WalletSignError} of any copy of this module (a brand check, not `instanceof`). */
118
+ export declare function isWalletSignError(error: unknown): error is WalletSignError;
119
+ /** Whether `error` is a {@link RegistryApiError} of any copy of this module (a brand check, not `instanceof`). */
120
+ export declare function isRegistryApiError(error: unknown): error is RegistryApiError;
121
+ /** Whether `error` is a {@link RegistryResponseError} of any copy of this module (a brand check, not `instanceof`). */
122
+ export declare function isRegistryResponseError(error: unknown): error is RegistryResponseError;
123
+ /**
124
+ * Whether `error` is a cancellation: the `AbortError` an aborted `signal` makes a wallets call throw (also a
125
+ * `TimeoutError` from `AbortSignal.timeout`, which `fetch` passes through).
126
+ */
127
+ export declare function isWalletCancellation(error: unknown): boolean;
75
128
  /**
76
129
  * Any error the wallets module throws, as a sentence a dApp can show (it says whether anything was submitted) and a
77
130
  * `kind` to branch on.
@@ -88,10 +141,12 @@ export interface WalletErrorDescription {
88
141
  * - `read-failed`: any other failed read.
89
142
  * - `sign-failed`: the wallet did not sign (an invalid challenge, or a wallet failure).
90
143
  * - `registry`: the registry API answered with an error status or a body the SDK refuses.
144
+ * - `cancelled`: the call's `signal` aborted it. The message says "Nothing was submitted" only for the cancellation
145
+ * this module throws before it submits; any other `AbortError` or `TimeoutError` gets a neutral sentence.
91
146
  * - `not-verified`: the server did not verify a wallet ownership proof (its verdict; never from `describeWalletError`).
92
147
  * - `other`: anything else.
93
148
  */
94
- readonly kind: 'declined' | 'not-committed' | 'outcome-unknown' | 'refused' | 'rate-limited' | 'read-failed' | 'sign-failed' | 'registry' | 'not-verified' | 'other';
149
+ readonly kind: 'declined' | 'not-committed' | 'outcome-unknown' | 'refused' | 'rate-limited' | 'read-failed' | 'sign-failed' | 'registry' | 'cancelled' | 'not-verified' | 'other';
95
150
  /**
96
151
  * The `WalletError` code of a `refused` error, the wallet's CIP-0103 code of a wallet error when it gave one, or the
97
152
  * HTTP status of a registry API error.
@@ -101,6 +156,10 @@ export interface WalletErrorDescription {
101
156
  readonly commandId?: string;
102
157
  /** An `outcome-unknown` burn request's reference, to look the request up before another is filed. */
103
158
  readonly burnReference?: string;
159
+ /** A submission's {@link WalletSubmitCategory} (for `declined`, `not-committed` and `outcome-unknown`). */
160
+ readonly category?: WalletSubmitCategory;
161
+ /** The Canton error id a submission's failure carried, when it carried one. */
162
+ readonly cantonErrorId?: string;
104
163
  }
105
164
  /** A user-facing sentence and a kind for any error the wallets module throws (or anything else thrown). */
106
165
  export declare function describeWalletError(error: unknown): WalletErrorDescription;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/wallets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AAC,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;
@@ -51,12 +88,14 @@ class WalletSignError extends Error {
51
88
  exports.WalletSignError = WalletSignError;
52
89
  /** A registry API answered with a non-2xx status. `body` is the raw response text. */
53
90
  class RegistryApiError extends Error {
54
- constructor(status, body, url) {
91
+ constructor(status, body, url, registry = "DA's registry") {
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;
98
+ this.registry = registry;
60
99
  }
61
100
  }
62
101
  exports.RegistryApiError = RegistryApiError;
@@ -65,6 +104,7 @@ class RegistryResponseError extends Error {
65
104
  constructor(message) {
66
105
  super(message);
67
106
  this.name = 'RegistryResponseError';
107
+ brand(this, 'RegistryResponseError');
68
108
  }
69
109
  }
70
110
  exports.RegistryResponseError = RegistryResponseError;
@@ -73,10 +113,53 @@ class WalletError extends Error {
73
113
  constructor(code, message) {
74
114
  super(message);
75
115
  this.name = 'WalletError';
116
+ brand(this, 'WalletError');
76
117
  this.code = code;
77
118
  }
78
119
  }
79
120
  exports.WalletError = WalletError;
121
+ /** Whether `error` is a {@link WalletError} of any copy of this module (a brand check, not `instanceof`). */
122
+ function isWalletError(error) {
123
+ return error instanceof WalletError || branded(error, 'WalletError');
124
+ }
125
+ /** Whether `error` is a {@link WalletSubmitError} of any copy of this module (a brand check, not `instanceof`). */
126
+ function isWalletSubmitError(error) {
127
+ return error instanceof WalletSubmitError || branded(error, 'WalletSubmitError');
128
+ }
129
+ /** Whether `error` is a {@link WalletReadError} of any copy of this module (a brand check, not `instanceof`). */
130
+ function isWalletReadError(error) {
131
+ return error instanceof WalletReadError || branded(error, 'WalletReadError');
132
+ }
133
+ /** Whether `error` is a {@link WalletSignError} of any copy of this module (a brand check, not `instanceof`). */
134
+ function isWalletSignError(error) {
135
+ return error instanceof WalletSignError || branded(error, 'WalletSignError');
136
+ }
137
+ /** Whether `error` is a {@link RegistryApiError} of any copy of this module (a brand check, not `instanceof`). */
138
+ function isRegistryApiError(error) {
139
+ return error instanceof RegistryApiError || branded(error, 'RegistryApiError');
140
+ }
141
+ /** Whether `error` is a {@link RegistryResponseError} of any copy of this module (a brand check, not `instanceof`). */
142
+ function isRegistryResponseError(error) {
143
+ return error instanceof RegistryResponseError || branded(error, 'RegistryResponseError');
144
+ }
145
+ /**
146
+ * Whether `error` is a cancellation: the `AbortError` an aborted `signal` makes a wallets call throw (also a
147
+ * `TimeoutError` from `AbortSignal.timeout`, which `fetch` passes through).
148
+ */
149
+ function isWalletCancellation(error) {
150
+ if ((0, abort_1.isAbortError)(error))
151
+ return true;
152
+ // A `DOMException` from `AbortController` or `fetch`, possibly of another realm, so not matched by `instanceof`.
153
+ if (typeof error !== 'object' || error === null)
154
+ return false;
155
+ try {
156
+ const { name } = error;
157
+ return name === 'AbortError' || name === 'TimeoutError';
158
+ }
159
+ catch {
160
+ return false;
161
+ }
162
+ }
80
163
  /** How many characters of a registry error body {@link describeWalletError} shows. */
81
164
  const REGISTRY_BODY_CHARS = 300;
82
165
  function described(kind, message, code) {
@@ -95,38 +178,52 @@ function thrownText(error) {
95
178
  }
96
179
  /** A user-facing sentence and a kind for any error the wallets module throws (or anything else thrown). */
97
180
  function describeWalletError(error) {
98
- if (error instanceof WalletSubmitError) {
181
+ if (isWalletSubmitError(error)) {
182
+ const submit = {
183
+ category: error.category,
184
+ ...(error.cantonErrorId !== undefined && { cantonErrorId: error.cantonErrorId }),
185
+ };
99
186
  switch (error.outcome) {
100
187
  case 'rejected-by-user':
101
- return described('declined', 'You declined in the wallet. Nothing was submitted.', error.code);
188
+ return {
189
+ ...described('declined', 'You declined in the wallet. Nothing was submitted.', error.code),
190
+ ...submit,
191
+ };
102
192
  case 'failed':
103
- return described('not-committed', `Not committed: ${error.message}`, error.code);
193
+ return { ...described('not-committed', `Not committed: ${error.message}`, error.code), ...submit };
104
194
  case 'unknown':
105
195
  // The message already says not to resubmit blindly, and names the command id.
106
196
  return {
107
197
  ...described('outcome-unknown', error.message, error.code),
108
198
  ...(error.commandId !== undefined && { commandId: error.commandId }),
109
199
  ...(error.burnReference !== undefined && { burnReference: error.burnReference }),
200
+ ...submit,
110
201
  };
111
202
  }
112
203
  }
113
- if (error instanceof WalletReadError) {
204
+ if (isWalletReadError(error)) {
114
205
  return error.rateLimited
115
206
  ? 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
207
  : described('read-failed', `The wallet did not answer a read: ${error.message}`, error.code);
117
208
  }
118
- if (error instanceof WalletSignError) {
209
+ if (isWalletSignError(error)) {
119
210
  return error.reason === 'rejected-by-user'
120
211
  ? described('declined', 'You declined to sign in the wallet. Nothing was verified.', error.code)
121
212
  : described('sign-failed', `The wallet did not sign: ${error.message}`, error.code);
122
213
  }
123
- if (error instanceof RegistryApiError) {
124
- return described('registry', `DA's registry answered ${error.status}: ${error.body.slice(0, REGISTRY_BODY_CHARS)}`, error.status);
214
+ if (isRegistryApiError(error)) {
215
+ return described('registry', `${typeof error.registry === 'string' ? error.registry : "DA's registry"} answered ${error.status}: ${error.body.slice(0, REGISTRY_BODY_CHARS)}`, error.status);
125
216
  }
126
- if (error instanceof RegistryResponseError)
217
+ if (isRegistryResponseError(error))
127
218
  return described('registry', error.message);
128
- if (error instanceof WalletError)
219
+ if (isWalletError(error))
129
220
  return described('refused', error.message, error.code);
221
+ if ((0, abort_2.isCancelledBeforeSubmit)(error))
222
+ return described('cancelled', 'Cancelled. Nothing was submitted.');
223
+ // A foreign `AbortError` or `TimeoutError` (a wallet's, or `fetch`'s) may have been raised after a submission was sent.
224
+ if (isWalletCancellation(error)) {
225
+ return described('cancelled', 'Cancelled; this does not say whether anything was submitted.');
226
+ }
130
227
  if (error instanceof Error)
131
228
  return described('other', error.message);
132
229
  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,K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,CAAC;IACJ,CAAC;IACD,IAAI,uBAAuB,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAChF,IAAI,aAAa,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACjF,IAAI,IAAA,+BAAuB,EAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC,WAAW,EAAE,mCAAmC,CAAC,CAAC;IACvG,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"}
@@ -0,0 +1,47 @@
1
+ import type { ActiveContract, InstrumentId } from './types';
2
+ /** The `HoldingV1` interface id in package-name form, as an ACS read filters on it. */
3
+ export declare const HOLDING_V1_INTERFACE_ID = "#splice-api-token-holding-v1:Splice.Api.Token.HoldingV1:Holding";
4
+ /** `HoldingV1.Lock`: who holds the lock and until when. */
5
+ export interface HoldingViewLock {
6
+ readonly holders: readonly string[];
7
+ /** ISO 8601, or null when the lock has no absolute expiry. */
8
+ readonly expiresAt: string | null;
9
+ /** Duration from the holding's createdAt ledger time after which the lock expires. */
10
+ readonly expiresAfter: {
11
+ readonly microseconds: string;
12
+ } | null;
13
+ readonly context: string | null;
14
+ }
15
+ /** `MetadataV1.Metadata`: string values by key. */
16
+ export interface HoldingViewMetadata {
17
+ readonly values: Readonly<Record<string, string>>;
18
+ }
19
+ /** A `HoldingV1.HoldingView`, its fields checked for shape only. */
20
+ export interface HoldingView {
21
+ readonly owner: string;
22
+ readonly instrumentId: InstrumentId;
23
+ /** Decimal string as the view reports it (not yet checked as a decimal). */
24
+ readonly amount: string;
25
+ /** Null when the holding is unlocked. */
26
+ readonly lock: HoldingViewLock | null;
27
+ readonly meta: HoldingViewMetadata;
28
+ }
29
+ /** An ISO 8601 ledger timestamp of a real calendar day, or undefined. */
30
+ export declare function readLedgerTimestamp(value: unknown): string | undefined;
31
+ /**
32
+ * `MetadataV1.Metadata` (`{values: {key: string}}`), or undefined when it is not of that shape. The values live in a
33
+ * null-prototype, read-only record, so a key such as `__proto__` stays plain data.
34
+ */
35
+ export declare function readHoldingViewMetadata(value: unknown): HoldingViewMetadata | undefined;
36
+ /** `Optional HoldingV1.Lock`: null for None, the lock, or undefined when it is not readable. */
37
+ export declare function readHoldingViewLock(value: unknown): HoldingViewLock | null | undefined;
38
+ /** A `HoldingV1.HoldingView` value, or undefined when any field is missing or malformed. */
39
+ export declare function readHoldingView(value: unknown): HoldingView | undefined;
40
+ /** Whether an interface id (either form) is `HoldingV1`'s, by `Module:Entity`. */
41
+ export declare function isHoldingV1InterfaceId(interfaceId: string): boolean;
42
+ /**
43
+ * The contract's `HoldingV1` view, or undefined when the read did not include exactly one successfully computed view of
44
+ * that interface (a view whose computation failed, `viewStatus.code` not 0, counts as none).
45
+ */
46
+ export declare function holdingViewOf(contract: Pick<ActiveContract, 'interfaceViews'>): HoldingView | undefined;
47
+ //# sourceMappingURL=holding-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"holding-view.d.ts","sourceRoot":"","sources":["../../../src/wallets/holding-view.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAiB,MAAM,SAAS,CAAC;AAG3E,uFAAuF;AACvF,eAAO,MAAM,uBAAuB,oEAAyC,CAAC;AAE9E,2DAA2D;AAC3D,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC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CAAC,GAAG,WAAW,GAAG,SAAS,CAOvG"}
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HOLDING_V1_INTERFACE_ID = void 0;
4
+ exports.readLedgerTimestamp = readLedgerTimestamp;
5
+ exports.readHoldingViewMetadata = readHoldingViewMetadata;
6
+ exports.readHoldingViewLock = readHoldingViewLock;
7
+ exports.readHoldingView = readHoldingView;
8
+ exports.isHoldingV1InterfaceId = isHoldingV1InterfaceId;
9
+ exports.holdingViewOf = holdingViewOf;
10
+ /**
11
+ * The CIP-56 token standard `HoldingV1` interface view (`Splice.Api.Token.HoldingV1:HoldingView`), read from untrusted
12
+ * JSON as the Ledger JSON API v2 returns it in a created event's `interfaceViews`. Browser-safe: it imports nothing but
13
+ * this module's own JSON guards, so the wallet layer and the Node-side `utils/token-standard/v1/holdings` share it.
14
+ *
15
+ * A view says what a contract claims about itself; it proves nothing. Trust comes from who signed the contract (see
16
+ * `parseHolding` in `./holdings`).
17
+ */
18
+ const instrument_1 = require("./instrument");
19
+ const json_1 = require("./json");
20
+ const templates_1 = require("./templates");
21
+ const constants_1 = require("../utils/token-standard/v1/constants");
22
+ /** The `HoldingV1` interface id in package-name form, as an ACS read filters on it. */
23
+ exports.HOLDING_V1_INTERFACE_ID = constants_1.TOKEN_STANDARD_V1_HOLDING_INTERFACE_ID;
24
+ const ISO_8601_TIMESTAMP_PATTERN = /^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d{1,9})?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/;
25
+ const SIGNED_INTEGER_PATTERN = /^-?\d+$/;
26
+ /** An ISO 8601 ledger timestamp of a real calendar day, or undefined. */
27
+ function readLedgerTimestamp(value) {
28
+ if (typeof value !== 'string')
29
+ return undefined;
30
+ const match = ISO_8601_TIMESTAMP_PATTERN.exec(value);
31
+ if (!match || Number.isNaN(Date.parse(value)))
32
+ return undefined;
33
+ const year = Number(match[1]);
34
+ const month = Number(match[2]);
35
+ const day = Number(match[3]);
36
+ const isLeapYear = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
37
+ const daysInMonth = month === 2 ? (isLeapYear ? 29 : 28) : [4, 6, 9, 11].includes(month) ? 30 : 31;
38
+ return day <= daysInMonth ? value : undefined;
39
+ }
40
+ /** A non-empty string, null, or undefined when the value is neither. */
41
+ function readNullableString(value) {
42
+ if (value === null)
43
+ return null;
44
+ return (0, json_1.nonEmptyString)(value);
45
+ }
46
+ /**
47
+ * `MetadataV1.Metadata` (`{values: {key: string}}`), or undefined when it is not of that shape. The values live in a
48
+ * null-prototype, read-only record, so a key such as `__proto__` stays plain data.
49
+ */
50
+ function readHoldingViewMetadata(value) {
51
+ if (!(0, json_1.isRecord)(value) || !(0, json_1.isRecord)(value['values']))
52
+ return undefined;
53
+ const values = Object.create(null);
54
+ for (const [key, metadataValue] of Object.entries(value['values'])) {
55
+ if (typeof metadataValue !== 'string')
56
+ return undefined;
57
+ Object.defineProperty(values, key, { value: metadataValue, enumerable: true, configurable: true, writable: false });
58
+ }
59
+ return { values };
60
+ }
61
+ /** `Optional HoldingV1.Lock`: null for None, the lock, or undefined when it is not readable. */
62
+ function readHoldingViewLock(value) {
63
+ if (value === null)
64
+ return null;
65
+ if (!(0, json_1.isRecord)(value) || !Array.isArray(value['holders']))
66
+ return undefined;
67
+ const { holders } = value;
68
+ if (!holders.every((holder) => (0, json_1.nonEmptyString)(holder) !== undefined))
69
+ return undefined;
70
+ const expiresAt = readNullableString(value['expiresAt']);
71
+ // Descriptive Optional Text: an empty context is valid (Splice copies it into the view as is).
72
+ const rawContext = value['context'];
73
+ const context = rawContext === null || typeof rawContext === 'string' ? rawContext : undefined;
74
+ const rawExpiresAfter = value['expiresAfter'];
75
+ let expiresAfter;
76
+ if (rawExpiresAfter === null) {
77
+ expiresAfter = null;
78
+ }
79
+ else if ((0, json_1.isRecord)(rawExpiresAfter) &&
80
+ typeof rawExpiresAfter['microseconds'] === 'string' &&
81
+ SIGNED_INTEGER_PATTERN.test(rawExpiresAfter['microseconds'])) {
82
+ expiresAfter = { microseconds: rawExpiresAfter['microseconds'] };
83
+ }
84
+ else {
85
+ return undefined;
86
+ }
87
+ if (expiresAt === undefined || context === undefined)
88
+ return undefined;
89
+ return { holders: holders, expiresAt, expiresAfter, context };
90
+ }
91
+ /** A `HoldingV1.HoldingView` value, or undefined when any field is missing or malformed. */
92
+ function readHoldingView(value) {
93
+ if (!(0, json_1.isRecord)(value))
94
+ return undefined;
95
+ const owner = (0, json_1.nonEmptyString)(value['owner']);
96
+ const instrumentId = (0, instrument_1.readInstrumentId)(value['instrumentId']);
97
+ const amount = (0, json_1.nonEmptyString)(value['amount']);
98
+ const lock = readHoldingViewLock(value['lock']);
99
+ const meta = readHoldingViewMetadata(value['meta']);
100
+ if (owner === undefined || instrumentId === null || amount === undefined || lock === undefined || !meta) {
101
+ return undefined;
102
+ }
103
+ return { owner, instrumentId, amount, lock, meta };
104
+ }
105
+ /** Whether an interface id (either form) is `HoldingV1`'s, by `Module:Entity`. */
106
+ function isHoldingV1InterfaceId(interfaceId) {
107
+ const name = (0, templates_1.qualifiedName)(interfaceId);
108
+ return name !== null && name === (0, templates_1.qualifiedName)(exports.HOLDING_V1_INTERFACE_ID);
109
+ }
110
+ /**
111
+ * The contract's `HoldingV1` view, or undefined when the read did not include exactly one successfully computed view of
112
+ * that interface (a view whose computation failed, `viewStatus.code` not 0, counts as none).
113
+ */
114
+ function holdingViewOf(contract) {
115
+ const views = (contract.interfaceViews ?? []).filter((view) => isHoldingV1InterfaceId(view.interfaceId));
116
+ const [view] = views;
117
+ if (views.length !== 1 || view?.viewStatusCode !== 0)
118
+ return undefined;
119
+ return readHoldingView(view.viewValue);
120
+ }
121
+ //# sourceMappingURL=holding-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"holding-view.js","sourceRoot":"","sources":["../../../src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AAC,CAAC;IAC7D,MAAM,MAAM,GAAG,IAAA,qBAAc,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC/C,MAAM,IAAI,GAAG,mBAAmB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAChD,MAAM,IAAI,GAAG,uBAAuB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IACpD,IAAI,KAAK,KAAK,SAAS,IAAI,YAAY,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,IAAI,EAAE,CAAC;QACxG,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACrD,CAAC;AAED,kFAAkF;AAClF,gCAAuC,WAAmB;IACxD,MAAM,IAAI,GAAG,IAAA,yBAAa,EAAC,WAAW,CAAC,CAAC;IACxC,OAAO,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAA,yBAAa,EAAC,QAAA,uBAAuB,CAAC,CAAC;AAC1E,CAAC;AAED;;;GAGG;AACH,uBAA8B,QAAgD;IAC5E,MAAM,KAAK,GAAG,CAAC,QAAQ,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,IAAmB,EAAE,EAAE,CAC3E,sBAAsB,CAAC,IAAI,CAAC,WAAW,CAAC,CACzC,CAAC;IACF,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IACrB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,EAAE,cAAc,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACvE,OAAO,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACzC,CAAC"}
@@ -1,20 +1,42 @@
1
1
  import type { ActiveContract, InstrumentId } from './types';
2
+ /**
3
+ * Which kind of holding contract a holding was read from, and so whose signatures made it genuine:
4
+ *
5
+ * - `da-registry`: a DA Utility Registry `Holding`, signed by its registrar (the instrument admin) and its owner;
6
+ * - `amulet`: Canton Coin, a Splice `Amulet` or `LockedAmulet`, signed by the DSO (the instrument admin) and its owner
7
+ * (and, for a `LockedAmulet`, by every lock holder).
8
+ */
9
+ export type HoldingSource = 'da-registry' | 'amulet';
2
10
  export interface Holding {
3
11
  readonly contractId: string;
4
12
  readonly owner: string;
5
13
  readonly instrumentId: InstrumentId;
6
- /** Decimal string as the ledger reports it. */
14
+ /**
15
+ * Decimal string as the ledger reports it. For Canton Coin this is the amount the holding was created with (the
16
+ * `HoldingV1` view's `amount`); holding fees accrued since are not deducted.
17
+ */
7
18
  readonly amount: string;
8
19
  /** Locked to an allocation, a burn request or a transfer in flight: it cannot be spent. */
9
20
  readonly locked: boolean;
10
21
  /** The synchronizer the holding is assigned to, when the ledger reported it. Inputs never mix synchronizers. */
11
22
  readonly synchronizerId?: string;
23
+ /**
24
+ * Which kind of holding contract it is (see {@link HoldingSource}). The wallet always sets it; optional so an object
25
+ * built without it (a test double, a cached state) still type-checks, and absent reads as `'da-registry'`.
26
+ */
27
+ readonly source?: HoldingSource;
28
+ /**
29
+ * The `HoldingV1` view's metadata, for a holding read through its view (Canton Coin: the round it was created in and
30
+ * its holding fee rate, `amulet.splice.lfdecentralizedtrust.org/created-in-round` and `.../rate-per-round`).
31
+ */
32
+ readonly meta?: Readonly<Record<string, string>>;
12
33
  }
13
34
  /**
14
- * A genuine DA Registry `Holding`, read from its create argument (`owner`, `instrument {source, id}`, `amount`,
15
- * `lock`), or null. Genuine: of DA's holding package, and signed by its registrar (the instrument admin, `source`) and
16
- * its owner. Any party can create a look-alike from its own package, with the wallet party as an observer, so only
17
- * those signatures make a holding real. An unreadable holding is never spendable.
35
+ * A genuine holding, or null: a DA Registry `Holding` (read from its create argument) or a Canton Coin `Amulet` or
36
+ * `LockedAmulet` (read from its `HoldingV1` view). Genuine: of a template in the trust table above, and signed by its
37
+ * instrument admin (DA's registrar, or the DSO) and its owner, and a `LockedAmulet` by every lock holder. Any party can
38
+ * create a look-alike from its own package, with the wallet party as an observer, so only those signatures make a
39
+ * holding real. An unreadable holding is never spendable.
18
40
  */
19
41
  export declare function parseHolding(contract: ActiveContract): Holding | null;
20
42
  export interface HoldingSelection {
@@ -66,7 +88,18 @@ export interface InstrumentBalance {
66
88
  readonly holdingCount: number;
67
89
  /** The registry's metadata of the instrument; absent when the registry did not answer it. */
68
90
  readonly metadata?: InstrumentMetadata;
91
+ /**
92
+ * Where the holdings come from: `amulet` for Canton Coin (see {@link HoldingSource}). The wallet always sets it;
93
+ * optional like `Holding.source`, and absent reads as `'da-registry'`.
94
+ */
95
+ readonly source?: HoldingSource;
69
96
  }
97
+ /**
98
+ * Whether a holding or balance is Canton Coin (`source: 'amulet'`). Canton Coin is listed but not transferred, burnt or
99
+ * pre-approved through the wallet: filter it out of pickers for those actions (`balances.filter((b) =>
100
+ * !isCantonCoin(b))`).
101
+ */
102
+ export declare function isCantonCoin(entry: Holding | InstrumentBalance): boolean;
70
103
  /**
71
104
  * A stable, unambiguous key for an instrument: `<id>@<admin>`, with `%` and `@` in each component percent-escaped
72
105
  * (`%25`, `%40`), so the one bare `@` always separates id from admin and distinct instruments never share a key