@fairmint/canton-node-sdk 0.0.276 → 0.0.278

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 (92) hide show
  1. package/README.md +108 -0
  2. package/build/src/da-registry/setup/steps.js +2 -1
  3. package/build/src/da-registry/setup/steps.js.map +1 -1
  4. package/build/src/da-registry/templates.d.ts +4 -0
  5. package/build/src/da-registry/templates.d.ts.map +1 -1
  6. package/build/src/da-registry/templates.js +4 -0
  7. package/build/src/da-registry/templates.js.map +1 -1
  8. package/build/src/index.d.ts +1 -0
  9. package/build/src/index.d.ts.map +1 -1
  10. package/build/src/index.js +24 -1
  11. package/build/src/index.js.map +1 -1
  12. package/build/src/utils/external-signing/index.d.ts +1 -0
  13. package/build/src/utils/external-signing/index.d.ts.map +1 -1
  14. package/build/src/utils/external-signing/index.js +1 -0
  15. package/build/src/utils/external-signing/index.js.map +1 -1
  16. package/build/src/utils/external-signing/wallet-ownership.d.ts +69 -0
  17. package/build/src/utils/external-signing/wallet-ownership.d.ts.map +1 -0
  18. package/build/src/utils/external-signing/wallet-ownership.js +179 -0
  19. package/build/src/utils/external-signing/wallet-ownership.js.map +1 -0
  20. package/build/src/utils/token-standard/v1/constants.d.ts +2 -0
  21. package/build/src/utils/token-standard/v1/constants.d.ts.map +1 -1
  22. package/build/src/utils/token-standard/v1/constants.js +3 -1
  23. package/build/src/utils/token-standard/v1/constants.js.map +1 -1
  24. package/build/src/wallets/acs.d.ts +9 -0
  25. package/build/src/wallets/acs.d.ts.map +1 -0
  26. package/build/src/wallets/acs.js +87 -0
  27. package/build/src/wallets/acs.js.map +1 -0
  28. package/build/src/wallets/cip103.d.ts +174 -0
  29. package/build/src/wallets/cip103.d.ts.map +1 -0
  30. package/build/src/wallets/cip103.js +452 -0
  31. package/build/src/wallets/cip103.js.map +1 -0
  32. package/build/src/wallets/commands.d.ts +60 -0
  33. package/build/src/wallets/commands.d.ts.map +1 -0
  34. package/build/src/wallets/commands.js +121 -0
  35. package/build/src/wallets/commands.js.map +1 -0
  36. package/build/src/wallets/contracts.d.ts +63 -0
  37. package/build/src/wallets/contracts.d.ts.map +1 -0
  38. package/build/src/wallets/contracts.js +117 -0
  39. package/build/src/wallets/contracts.js.map +1 -0
  40. package/build/src/wallets/da-utilities/client.d.ts +75 -0
  41. package/build/src/wallets/da-utilities/client.d.ts.map +1 -0
  42. package/build/src/wallets/da-utilities/client.js +238 -0
  43. package/build/src/wallets/da-utilities/client.js.map +1 -0
  44. package/build/src/wallets/decimal.d.ts +9 -0
  45. package/build/src/wallets/decimal.d.ts.map +1 -0
  46. package/build/src/wallets/decimal.js +29 -0
  47. package/build/src/wallets/decimal.js.map +1 -0
  48. package/build/src/wallets/errors.d.ts +66 -0
  49. package/build/src/wallets/errors.d.ts.map +1 -0
  50. package/build/src/wallets/errors.js +71 -0
  51. package/build/src/wallets/errors.js.map +1 -0
  52. package/build/src/wallets/holdings.d.ts +48 -0
  53. package/build/src/wallets/holdings.d.ts.map +1 -0
  54. package/build/src/wallets/holdings.js +198 -0
  55. package/build/src/wallets/holdings.js.map +1 -0
  56. package/build/src/wallets/index.d.ts +23 -0
  57. package/build/src/wallets/index.d.ts.map +1 -0
  58. package/build/src/wallets/index.js +36 -0
  59. package/build/src/wallets/index.js.map +1 -0
  60. package/build/src/wallets/instrument.d.ts +5 -0
  61. package/build/src/wallets/instrument.d.ts.map +1 -0
  62. package/build/src/wallets/instrument.js +18 -0
  63. package/build/src/wallets/instrument.js.map +1 -0
  64. package/build/src/wallets/json.d.ts +16 -0
  65. package/build/src/wallets/json.d.ts.map +1 -0
  66. package/build/src/wallets/json.js +27 -0
  67. package/build/src/wallets/json.js.map +1 -0
  68. package/build/src/wallets/ownership.d.ts +79 -0
  69. package/build/src/wallets/ownership.d.ts.map +1 -0
  70. package/build/src/wallets/ownership.js +202 -0
  71. package/build/src/wallets/ownership.js.map +1 -0
  72. package/build/src/wallets/templates.d.ts +36 -0
  73. package/build/src/wallets/templates.d.ts.map +1 -0
  74. package/build/src/wallets/templates.js +70 -0
  75. package/build/src/wallets/templates.js.map +1 -0
  76. package/build/src/wallets/token-registry.d.ts +95 -0
  77. package/build/src/wallets/token-registry.d.ts.map +1 -0
  78. package/build/src/wallets/token-registry.js +19 -0
  79. package/build/src/wallets/token-registry.js.map +1 -0
  80. package/build/src/wallets/token-standard-wallet.d.ts +146 -0
  81. package/build/src/wallets/token-standard-wallet.d.ts.map +1 -0
  82. package/build/src/wallets/token-standard-wallet.js +269 -0
  83. package/build/src/wallets/token-standard-wallet.js.map +1 -0
  84. package/build/src/wallets/token-wallet.d.ts +50 -0
  85. package/build/src/wallets/token-wallet.d.ts.map +1 -0
  86. package/build/src/wallets/token-wallet.js +175 -0
  87. package/build/src/wallets/token-wallet.js.map +1 -0
  88. package/build/src/wallets/types.d.ts +74 -0
  89. package/build/src/wallets/types.d.ts.map +1 -0
  90. package/build/src/wallets/types.js +3 -0
  91. package/build/src/wallets/types.js.map +1 -0
  92. package/package.json +1 -1
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRecord = void 0;
4
+ exports.isJsonValue = isJsonValue;
5
+ exports.isJsonObject = isJsonObject;
6
+ exports.nonEmptyString = nonEmptyString;
7
+ /** JSON values as the Ledger JSON API and DA's registry API encode them, with guards for untrusted input. */
8
+ const type_guards_1 = require("../core/utils/type-guards");
9
+ Object.defineProperty(exports, "isRecord", { enumerable: true, get: function () { return type_guards_1.isRecord; } });
10
+ /** Whether `value` is a JSON value: finite numbers, no `undefined`, functions or class instances beyond plain data. */
11
+ function isJsonValue(value) {
12
+ if (value === null || typeof value === 'string' || typeof value === 'boolean')
13
+ return true;
14
+ if (typeof value === 'number')
15
+ return Number.isFinite(value);
16
+ if (typeof value !== 'object')
17
+ return false;
18
+ return Array.isArray(value) ? value.every(isJsonValue) : Object.values(value).every(isJsonValue);
19
+ }
20
+ function isJsonObject(value) {
21
+ return (0, type_guards_1.isRecord)(value) && isJsonValue(value);
22
+ }
23
+ /** A non-empty string, or undefined. */
24
+ function nonEmptyString(value) {
25
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
26
+ }
27
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/wallets/json.ts"],"names":[],"mappings":";;;;;;AAAA,6GAA6G;AAC7G,2DAAqD;yFAA5C,sBAAQ;AAYjB,uHAAuH;AACvH,qBAA4B,KAAc;IACxC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAC3F,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC7D,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AACnG,CAAC;AAED,sBAA6B,KAAc;IACzC,OAAO,IAAA,sBAAQ,EAAC,KAAK,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;AAC/C,CAAC;AAED,wCAAwC;AACxC,wBAA+B,KAAc;IAC3C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3E,CAAC"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Proof that the user controls a wallet's party, not just its party id: the wallet signs a canonical, human-readable
3
+ * message (CIP-0103 `signMessage`) built from a challenge the dApp's server issued, and the server verifies it with
4
+ * `verifyWalletOwnership` (Node only, exported from the package root). A check in the browser proves nothing: anyone
5
+ * can call this code with a made-up provider, so only the server's verification counts.
6
+ *
7
+ * The message is plain text with a fixed first line and a statement that it is not a transaction, so a dApp cannot use
8
+ * it to get a transaction hash (34 binary bytes) signed. Wallets sign the raw message bytes with the party's key (Loop:
9
+ * Ed25519 over the UTF-8 bytes; the CIP-0103 reference wallet: the same), so the text form is the only protection. The
10
+ * nonce must come from the server, be random, and be accepted once.
11
+ *
12
+ * The `Network:` line is a label, not proof: a party id is derived from its key and is the same on every network, so a
13
+ * verified proof says nothing about the party existing or being hosted on that network. `proveWalletOwnership` refuses
14
+ * a wallet that reports another network as a guard against mistakes; a server that needs the network proven must look
15
+ * the party up on that network (its Scan or ledger party and topology APIs).
16
+ */
17
+ import { type Cip103Provider } from './cip103';
18
+ /** The first line of every ownership message. */
19
+ export declare const WALLET_OWNERSHIP_TITLE = "Canton wallet ownership proof";
20
+ /** The message format version, its `Version:` line. */
21
+ export declare const WALLET_OWNERSHIP_VERSION = "1";
22
+ /** What the dApp's server issues for one proof. Times are ISO-8601 in UTC with milliseconds (`toISOString()`). */
23
+ export interface WalletOwnershipChallenge {
24
+ /** The dApp's host (`app.example.com`, `localhost:3000`): the site the user proves ownership to. */
25
+ readonly domain: string;
26
+ /** Single-use, server-generated, unguessable: 16-512 of `A-Z a-z 0-9 . _ ~ -`. */
27
+ readonly nonce: string;
28
+ readonly issuedAt: string;
29
+ readonly expiresAt: string;
30
+ /**
31
+ * The Canton network the dApp expects the wallet on (for example the wallet's CIP-0103 `networkId`, `canton:devnet`).
32
+ * A label in the message: signing it does not prove the party is on that network (see the module comment).
33
+ */
34
+ readonly network?: string;
35
+ }
36
+ /** Every field of an ownership message. */
37
+ export interface WalletOwnershipMessageFields extends WalletOwnershipChallenge {
38
+ readonly partyId: string;
39
+ }
40
+ /** What the browser sends to the server to verify. */
41
+ export interface WalletOwnershipProof {
42
+ readonly partyId: string;
43
+ /** The account's `publicKey`, as the wallet reported it. */
44
+ readonly publicKey: string;
45
+ /** The account's `namespace`, when the wallet reported it. */
46
+ readonly namespace?: string;
47
+ /** The exact text the wallet signed. */
48
+ readonly message: string;
49
+ /** The signature as the wallet returned it (Loop: hex; the CIP-0103 reference wallet: base64). */
50
+ readonly signature: string;
51
+ }
52
+ /**
53
+ * The canonical message for these fields. Throws `TypeError` on a field that is not valid. The same fields always give
54
+ * the same text, so the server rebuilds it from the fields it parses and refuses anything else.
55
+ */
56
+ export declare function buildWalletOwnershipMessage(fields: WalletOwnershipMessageFields): string;
57
+ /**
58
+ * The fields of a canonical ownership message, or null for any text that is not exactly what
59
+ * {@link buildWalletOwnershipMessage} gives for its fields (another version, an extra line or space, a reordered
60
+ * field).
61
+ */
62
+ export declare function parseWalletOwnershipMessage(message: string): WalletOwnershipMessageFields | null;
63
+ export interface ProveWalletOwnershipOptions {
64
+ /** The challenge the dApp's server issued. */
65
+ readonly challenge: WalletOwnershipChallenge;
66
+ /**
67
+ * The party the dApp expects. CIP-0103 wallets sign with the primary account, so a different primary account is
68
+ * refused before anything is signed.
69
+ */
70
+ readonly partyId?: string;
71
+ /** Defaults to the system clock; an expired challenge is refused before anything is signed. */
72
+ readonly now?: () => Date;
73
+ }
74
+ /**
75
+ * Ask the wallet to sign the ownership message for the challenge, as its primary account. Returns what the server needs
76
+ * to verify; it is not itself proof of anything until the server verified it (`verifyWalletOwnership`).
77
+ */
78
+ export declare function proveWalletOwnership(provider: Cip103Provider, options: ProveWalletOwnershipOptions): Promise<WalletOwnershipProof>;
79
+ //# sourceMappingURL=ownership.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ownership.d.ts","sourceRoot":"","sources":["../../../src/wallets/ownership.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAsE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAInH,iDAAiD;AACjD,eAAO,MAAM,sBAAsB,kCAAkC,CAAC;AACtE,uDAAuD;AACvD,e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,CACxC,QAAQ,EAAE,cAAc,EACxB,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,oBAAoB,CAAC,CA8D/B"}
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WALLET_OWNERSHIP_VERSION = exports.WALLET_OWNERSHIP_TITLE = void 0;
4
+ exports.buildWalletOwnershipMessage = buildWalletOwnershipMessage;
5
+ exports.parseWalletOwnershipMessage = parseWalletOwnershipMessage;
6
+ exports.proveWalletOwnership = proveWalletOwnership;
7
+ /**
8
+ * Proof that the user controls a wallet's party, not just its party id: the wallet signs a canonical, human-readable
9
+ * message (CIP-0103 `signMessage`) built from a challenge the dApp's server issued, and the server verifies it with
10
+ * `verifyWalletOwnership` (Node only, exported from the package root). A check in the browser proves nothing: anyone
11
+ * can call this code with a made-up provider, so only the server's verification counts.
12
+ *
13
+ * The message is plain text with a fixed first line and a statement that it is not a transaction, so a dApp cannot use
14
+ * it to get a transaction hash (34 binary bytes) signed. Wallets sign the raw message bytes with the party's key (Loop:
15
+ * Ed25519 over the UTF-8 bytes; the CIP-0103 reference wallet: the same), so the text form is the only protection. The
16
+ * nonce must come from the server, be random, and be accepted once.
17
+ *
18
+ * The `Network:` line is a label, not proof: a party id is derived from its key and is the same on every network, so a
19
+ * verified proof says nothing about the party existing or being hosted on that network. `proveWalletOwnership` refuses
20
+ * a wallet that reports another network as a guard against mistakes; a server that needs the network proven must look
21
+ * the party up on that network (its Scan or ledger party and topology APIs).
22
+ */
23
+ const cip103_1 = require("./cip103");
24
+ const errors_1 = require("./errors");
25
+ const json_1 = require("./json");
26
+ /** The first line of every ownership message. */
27
+ exports.WALLET_OWNERSHIP_TITLE = 'Canton wallet ownership proof';
28
+ /** The message format version, its `Version:` line. */
29
+ exports.WALLET_OWNERSHIP_VERSION = '1';
30
+ const DOMAIN_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9.-]{0,251}[A-Za-z0-9])?(?::[0-9]{1,5})?$/;
31
+ const NONCE_PATTERN = /^[A-Za-z0-9._~-]{16,512}$/;
32
+ /** Printable ASCII without spaces. */
33
+ const TOKEN_PATTERN = /^[!-~]+$/;
34
+ const ISO_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
35
+ /** The reason a field is not valid in a message, or null. */
36
+ function fieldProblem(fields) {
37
+ if (typeof fields.domain !== 'string' || !DOMAIN_PATTERN.test(fields.domain)) {
38
+ return 'domain must be a host name, optionally with a port';
39
+ }
40
+ if (typeof fields.nonce !== 'string' || !NONCE_PATTERN.test(fields.nonce)) {
41
+ return 'nonce must be 16-512 characters of letters, digits and . _ ~ -';
42
+ }
43
+ if (typeof fields.partyId !== 'string' ||
44
+ fields.partyId.length > 512 ||
45
+ !TOKEN_PATTERN.test(fields.partyId) ||
46
+ fields.partyId.split('::').length !== 2) {
47
+ return 'partyId must be a Canton party id (hint::namespace)';
48
+ }
49
+ if (fields.network !== undefined &&
50
+ (typeof fields.network !== 'string' || fields.network.length > 128 || !TOKEN_PATTERN.test(fields.network))) {
51
+ return 'network must be 1-128 printable characters without spaces';
52
+ }
53
+ for (const key of ['issuedAt', 'expiresAt']) {
54
+ const value = fields[key];
55
+ // An out-of-range date (month 13) is an Invalid Date, whose toISOString() throws: check it first.
56
+ if (typeof value !== 'string' ||
57
+ !ISO_PATTERN.test(value) ||
58
+ Number.isNaN(Date.parse(value)) ||
59
+ new Date(value).toISOString() !== value) {
60
+ return `${key} must be an ISO-8601 UTC time with milliseconds (Date.toISOString())`;
61
+ }
62
+ }
63
+ if (Date.parse(fields.expiresAt) <= Date.parse(fields.issuedAt)) {
64
+ return 'expiresAt must be after issuedAt';
65
+ }
66
+ return null;
67
+ }
68
+ /**
69
+ * The canonical message for these fields. Throws `TypeError` on a field that is not valid. The same fields always give
70
+ * the same text, so the server rebuilds it from the fields it parses and refuses anything else.
71
+ */
72
+ function buildWalletOwnershipMessage(fields) {
73
+ const problem = fieldProblem(fields);
74
+ if (problem !== null)
75
+ throw new TypeError(`Invalid wallet ownership message: ${problem}`);
76
+ return [
77
+ exports.WALLET_OWNERSHIP_TITLE,
78
+ `Sign this message only to prove to ${fields.domain} that you control the Canton party below. It is not a transaction: it moves no assets and authorizes nothing on the ledger.`,
79
+ '',
80
+ `Version: ${exports.WALLET_OWNERSHIP_VERSION}`,
81
+ `Domain: ${fields.domain}`,
82
+ `Party: ${fields.partyId}`,
83
+ ...(fields.network !== undefined ? [`Network: ${fields.network}`] : []),
84
+ `Nonce: ${fields.nonce}`,
85
+ `Issued At: ${fields.issuedAt}`,
86
+ `Expiration Time: ${fields.expiresAt}`,
87
+ ].join('\n');
88
+ }
89
+ const FIELD_LINES = new Map([
90
+ ['Version', 'version'],
91
+ ['Domain', 'domain'],
92
+ ['Party', 'partyId'],
93
+ ['Network', 'network'],
94
+ ['Nonce', 'nonce'],
95
+ ['Issued At', 'issuedAt'],
96
+ ['Expiration Time', 'expiresAt'],
97
+ ]);
98
+ /**
99
+ * The fields of a canonical ownership message, or null for any text that is not exactly what
100
+ * {@link buildWalletOwnershipMessage} gives for its fields (another version, an extra line or space, a reordered
101
+ * field).
102
+ */
103
+ function parseWalletOwnershipMessage(message) {
104
+ if (typeof message !== 'string' || message.length > 4096)
105
+ return null;
106
+ const lines = message.split('\n');
107
+ if (lines[0] !== exports.WALLET_OWNERSHIP_TITLE)
108
+ return null;
109
+ const found = {};
110
+ for (const line of lines.slice(3)) {
111
+ const separator = line.indexOf(': ');
112
+ const key = separator > 0 ? FIELD_LINES.get(line.slice(0, separator)) : undefined;
113
+ if (key === undefined || found[key] !== undefined)
114
+ return null;
115
+ found[key] = line.slice(separator + 2);
116
+ }
117
+ const { version, domain, partyId, network, nonce, issuedAt, expiresAt } = found;
118
+ if (version !== exports.WALLET_OWNERSHIP_VERSION ||
119
+ domain === undefined ||
120
+ partyId === undefined ||
121
+ nonce === undefined ||
122
+ issuedAt === undefined ||
123
+ expiresAt === undefined) {
124
+ return null;
125
+ }
126
+ const fields = {
127
+ domain,
128
+ partyId,
129
+ nonce,
130
+ issuedAt,
131
+ expiresAt,
132
+ ...(network !== undefined && { network }),
133
+ };
134
+ if (fieldProblem(fields) !== null)
135
+ return null;
136
+ return buildWalletOwnershipMessage(fields) === message ? fields : null;
137
+ }
138
+ /** The signature from a `signMessage` result: `{signature}` (CIP-0103) or a bare string (some wallets). */
139
+ function readSignature(raw) {
140
+ if (typeof raw === 'string')
141
+ return (0, json_1.nonEmptyString)(raw);
142
+ return (0, json_1.isRecord)(raw) ? (0, json_1.nonEmptyString)(raw['signature']) : undefined;
143
+ }
144
+ /**
145
+ * Ask the wallet to sign the ownership message for the challenge, as its primary account. Returns what the server needs
146
+ * to verify; it is not itself proof of anything until the server verified it (`verifyWalletOwnership`).
147
+ */
148
+ async function proveWalletOwnership(provider, options) {
149
+ const account = await (0, cip103_1.primaryAccount)(provider);
150
+ if (options.partyId !== undefined && options.partyId !== account.partyId) {
151
+ throw new errors_1.WalletSignError('invalid-challenge', `The wallet's primary account is ${account.partyId}, not ${options.partyId}; switch accounts in the wallet first`);
152
+ }
153
+ if (account.publicKey === undefined) {
154
+ throw new errors_1.WalletReadError('The wallet returned a primary account without publicKey, so ownership cannot be proven');
155
+ }
156
+ const { challenge } = options;
157
+ // A guard against signing for the wrong network, not proof: the wallet reports its network itself.
158
+ if (challenge.network !== undefined && account.networkId !== undefined && account.networkId !== challenge.network) {
159
+ throw new errors_1.WalletSignError('invalid-challenge', `The wallet is on ${account.networkId}, not ${challenge.network}; switch networks in the wallet first`);
160
+ }
161
+ let message;
162
+ try {
163
+ message = buildWalletOwnershipMessage({
164
+ domain: challenge.domain,
165
+ partyId: account.partyId,
166
+ nonce: challenge.nonce,
167
+ issuedAt: challenge.issuedAt,
168
+ expiresAt: challenge.expiresAt,
169
+ ...(challenge.network !== undefined && { network: challenge.network }),
170
+ });
171
+ }
172
+ catch (error) {
173
+ throw new errors_1.WalletSignError('invalid-challenge', error instanceof Error ? error.message : String(error));
174
+ }
175
+ const now = (options.now ?? (() => new Date()))().getTime();
176
+ if (!(now < Date.parse(challenge.expiresAt))) {
177
+ throw new errors_1.WalletSignError('invalid-challenge', 'The ownership challenge has expired; ask the server for a new one');
178
+ }
179
+ let raw;
180
+ try {
181
+ raw = await provider.request({ method: 'signMessage', params: { message } });
182
+ }
183
+ catch (error) {
184
+ const code = (0, cip103_1.cip103ErrorCode)(error);
185
+ if (code === cip103_1.CIP103_ERROR_CODES.userRejected) {
186
+ throw new errors_1.WalletSignError('rejected-by-user', `The user declined to sign the ownership message: ${(0, cip103_1.describeError)(error)}`, code);
187
+ }
188
+ throw new errors_1.WalletSignError('failed', `The wallet did not sign the ownership message: ${(0, cip103_1.describeError)(error)}`, code);
189
+ }
190
+ const signature = readSignature(raw);
191
+ if (signature === undefined) {
192
+ throw new errors_1.WalletSignError('failed', 'The wallet answered signMessage without a signature');
193
+ }
194
+ return {
195
+ partyId: account.partyId,
196
+ publicKey: account.publicKey,
197
+ ...(account.namespace !== undefined && { namespace: account.namespace }),
198
+ message,
199
+ signature,
200
+ };
201
+ }
202
+ //# sourceMappingURL=ownership.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ownership.js","sourceRoot":"","sources":["../../../src/wallets/ownership.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;;;;GAeG;AACH,qCAAmH;AACnH,qCAA4D;AAC5D,iCAAkD;AAElD,iDAAiD;AACpC,QAAA,sBAAsB,GAAG,+BAA+B,CAAC;AACtE,uDAAuD;AAC1C,QAAA,wBAAwB,GAAG,GAAG,CAAC;AAmC5C,MAAM,cAAc,GAAG,mEAAmE,CAAC;AAC3F,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAClD,sCAAsC;AACtC,MAAM,aAAa,GAAG,UAAU,CAAC;AACjC,MAAM,WAAW,GAAG,+CAA+C,CAAC;AAEpE,6DAA6D;AAC7D,SAAS,YAAY,CAAC,MAAoC;IACxD,IAAI,OAAO,MAAM,CA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,EAAE,CAAC;QACf,MAAM,IAAI,GAAG,IAAA,wBAAe,EAAC,KAAK,CAAC,CAAC;QACpC,IAAI,IAAI,KAAK,2BAAkB,CAAC,YAAY,EAAE,CAAC;YAC7C,MAAM,IAAI,wBAAe,CACvB,kBAAkB,EAClB,oDAAoD,IAAA,sBAAa,EAAC,KAAK,CAAC,EAAE,EAC1E,IAAI,CACL,CAAC;QACJ,CAAC;QACD,MAAM,IAAI,wBAAe,CAAC,QAAQ,EAAE,kDAAkD,IAAA,sBAAa,EAAC,KAAK,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACtH,CAAC;IACD,MAAM,SAAS,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,MAAM,IAAI,wBAAe,CAAC,QAAQ,EAAE,qDAAqD,CAAC,CAAC;IAC7F,CAAC;IACD,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;QACxE,OAAO;QACP,SAAS;KACV,CAAC;AACJ,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Comparing template and interface ids across their two forms: package-name (`#package-name:Module:Entity`, as the
3
+ * SDK's constants spell them so they survive DAR upgrades) and package-id (`pkgId:Module:Entity`, as the ledger reports
4
+ * them).
5
+ *
6
+ * The ids themselves are the SDK's own: `DA_REGISTRY_TEMPLATES` (`da-registry/templates`) and the token standard V1
7
+ * interface ids (`utils/token-standard/v1/constants`). Both modules are dependency-free, so this module can import them
8
+ * and stay browser-safe.
9
+ */
10
+ import type { ActiveContract, ContractFilter } from './types';
11
+ /**
12
+ * `Module:Entity` of a template or interface id in either form (`#pkg-name:M:E` or `pkgId:M:E`), or null when the id is
13
+ * not of that shape.
14
+ */
15
+ export declare function qualifiedName(id: string): string | null;
16
+ /** Whether two ids name the same template or interface, whatever package version or id form each uses. */
17
+ export declare function sameQualifiedName(left: string, right: string): boolean;
18
+ /** The package name of a package-name form id (`#package-name:Module:Entity`), or null for any other form. */
19
+ export declare function packageNameOf(id: string): string | null;
20
+ /** `Module:Entity` of one of the SDK's own id constants; throws on a malformed constant rather than matching nothing. */
21
+ export declare function requireQualifiedName(id: string): string;
22
+ /** A stable key of a filter: `t:<templateId>` or `i:<interfaceId>`. */
23
+ export declare function contractFilterKey(filter: ContractFilter): string;
24
+ /**
25
+ * Whether a contract of a snapshot read with several filters at once is one the given filter would have returned on its
26
+ * own: of the template, or carrying a view of the interface (the ledger computes views only for the interfaces the read
27
+ * asked for).
28
+ *
29
+ * A template match needs proven package identity, not just the same `Module:Entity`: a cumulative read also returns
30
+ * contracts matched only by one of its interface filters, and any party can create a template of that name in its own
31
+ * package. So a package-name filter (`#pkg:M:E`) matches only a contract whose `packageName` is that package; the
32
+ * Ledger JSON API v2 (Canton 3.x) always reports `createdEvent.packageName` (a required field), so a contract without
33
+ * one is not classified at all (fail closed). A package-id filter matches only the exact template id.
34
+ */
35
+ export declare function contractMatchesFilter(contract: ActiveContract, filter: ContractFilter): boolean;
36
+ //# sourceMappingURL=templates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../../src/wallets/templates.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9D;;;GAGG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKvD;AAED,0GAA0G;AAC1G,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAGtE;AAED,8GAA8G;AAC9G,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIvD;AAED,yHAAyH;AACzH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAIvD;AAED,uEAAuE;AACvE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAEhE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAgB/F"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.qualifiedName = qualifiedName;
4
+ exports.sameQualifiedName = sameQualifiedName;
5
+ exports.packageNameOf = packageNameOf;
6
+ exports.requireQualifiedName = requireQualifiedName;
7
+ exports.contractFilterKey = contractFilterKey;
8
+ exports.contractMatchesFilter = contractMatchesFilter;
9
+ /**
10
+ * `Module:Entity` of a template or interface id in either form (`#pkg-name:M:E` or `pkgId:M:E`), or null when the id is
11
+ * not of that shape.
12
+ */
13
+ function qualifiedName(id) {
14
+ const separator = id.indexOf(':');
15
+ if (separator <= 0)
16
+ return null;
17
+ const rest = id.slice(separator + 1);
18
+ return /^[A-Za-z0-9_.]+:[A-Za-z0-9_.]+$/.test(rest) ? rest : null;
19
+ }
20
+ /** Whether two ids name the same template or interface, whatever package version or id form each uses. */
21
+ function sameQualifiedName(left, right) {
22
+ const name = qualifiedName(left);
23
+ return name !== null && name === qualifiedName(right);
24
+ }
25
+ /** The package name of a package-name form id (`#package-name:Module:Entity`), or null for any other form. */
26
+ function packageNameOf(id) {
27
+ if (!id.startsWith('#'))
28
+ return null;
29
+ const separator = id.indexOf(':');
30
+ return separator > 1 ? id.slice(1, separator) : null;
31
+ }
32
+ /** `Module:Entity` of one of the SDK's own id constants; throws on a malformed constant rather than matching nothing. */
33
+ function requireQualifiedName(id) {
34
+ const name = qualifiedName(id);
35
+ if (name === null)
36
+ throw new TypeError(`Malformed template id ${id}`);
37
+ return name;
38
+ }
39
+ /** A stable key of a filter: `t:<templateId>` or `i:<interfaceId>`. */
40
+ function contractFilterKey(filter) {
41
+ return 'templateId' in filter ? `t:${filter.templateId}` : `i:${filter.interfaceId}`;
42
+ }
43
+ /**
44
+ * Whether a contract of a snapshot read with several filters at once is one the given filter would have returned on its
45
+ * own: of the template, or carrying a view of the interface (the ledger computes views only for the interfaces the read
46
+ * asked for).
47
+ *
48
+ * A template match needs proven package identity, not just the same `Module:Entity`: a cumulative read also returns
49
+ * contracts matched only by one of its interface filters, and any party can create a template of that name in its own
50
+ * package. So a package-name filter (`#pkg:M:E`) matches only a contract whose `packageName` is that package; the
51
+ * Ledger JSON API v2 (Canton 3.x) always reports `createdEvent.packageName` (a required field), so a contract without
52
+ * one is not classified at all (fail closed). A package-id filter matches only the exact template id.
53
+ */
54
+ function contractMatchesFilter(contract, filter) {
55
+ if ('templateId' in filter) {
56
+ if (!sameQualifiedName(contract.templateId, filter.templateId))
57
+ return false;
58
+ const filterPackage = packageNameOf(filter.templateId);
59
+ return filterPackage === null
60
+ ? contract.templateId === filter.templateId
61
+ : contract.packageName !== undefined && contract.packageName === filterPackage;
62
+ }
63
+ // Same rule for interfaces: a package-id filter (`pkgId:M:E`) matches only that exact interface id, so two
64
+ // same-named interfaces from different packages in one cumulative read are never mixed up; a package-name filter
65
+ // (`#pkg:M:E`) matches by name (the ledger reports a view's interface id with the package id it resolved).
66
+ return contract.interfaceViews.some((view) => packageNameOf(filter.interfaceId) === null
67
+ ? view.interfaceId === filter.interfaceId
68
+ : sameQualifiedName(view.interfaceId, filter.interfaceId));
69
+ }
70
+ //# sourceMappingURL=templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/wallets/templates.ts"],"names":[],"mappings":";;;;;;;;AAWA;;;GAGG;AACH,uBAA8B,EAAU;IACtC,MAAM,SAAS,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,SAAS,IA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;QAC3B,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC;YAAE,OAAO,KAAK,CAAC;QAC7E,MAAM,aAAa,GAAG,aAAa,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACvD,OAAO,aAAa,KAAK,IAAI;YAC3B,CAAC,CAAC,QAAQ,CAAC,UAAU,KAAK,MAAM,CAAC,UAAU;YAC3C,CAAC,CAAC,QAAQ,CAAC,WAAW,KAAK,SAAS,IAAI,QAAQ,CAAC,WAAW,KAAK,aAAa,CAAC;IACnF,CAAC;IACD,2GAA2G;IAC3G,iHAAiH;IACjH,2GAA2G;IAC3G,OAAO,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAC3C,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,IAAI;QACxC,CAAC,CAAC,IAAI,CAAC,WAAW,KAAK,MAAM,CAAC,WAAW;QACzC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,CAC5D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * The CIP-56 (token standard V1) registry seam: what a transfer, or an answer to a pending transfer, needs from the
3
+ * instrument's registry off ledger. DA's Utility Registry implements it today (`createDaUtilitiesClient`); another
4
+ * registry (for example Canton Coin) is a new implementation of this interface.
5
+ */
6
+ import type { TransferOffer } from './contracts';
7
+ import type { JsonObject } from './json';
8
+ import type { ActiveContract, ContractFilter, DisclosedContract, InstrumentId } from './types';
9
+ /** Splice `ChoiceContext` data: passed through unchanged as `extraArgs.context`. */
10
+ export interface ChoiceContextData {
11
+ readonly values: JsonObject;
12
+ }
13
+ /** What the registry returns for a choice: its context, and the contracts to disclose with the submission. */
14
+ export interface ChoiceContext {
15
+ readonly choiceContextData: ChoiceContextData;
16
+ readonly disclosedContracts: readonly DisclosedContract[];
17
+ }
18
+ /** A factory to exercise, with its choice context. */
19
+ export interface FactoryWithChoiceContext extends ChoiceContext {
20
+ readonly factoryId: string;
21
+ }
22
+ /**
23
+ * How the registry will run a transfer:
24
+ *
25
+ * - `offer`: a pending transfer the receiver must accept;
26
+ * - `direct`: the receiver pre-approved transfers, so the holdings move at once;
27
+ * - `self`: sender and receiver are the same party.
28
+ */
29
+ export type TransferKind = 'offer' | 'direct' | 'self';
30
+ export interface TransferFactory extends FactoryWithChoiceContext {
31
+ readonly transferKind: TransferKind;
32
+ }
33
+ /** The CIP-56 `Transfer` record. */
34
+ export interface TransferSpec {
35
+ readonly sender: string;
36
+ readonly receiver: string;
37
+ /** Decimal string. */
38
+ readonly amount: string;
39
+ readonly instrumentId: InstrumentId;
40
+ /** ISO-8601. */
41
+ readonly requestedAt: string;
42
+ /** ISO-8601. */
43
+ readonly executeBefore: string;
44
+ readonly inputHoldingCids: readonly string[];
45
+ readonly meta: {
46
+ readonly values: Readonly<Record<string, string>>;
47
+ };
48
+ }
49
+ export interface TransferFactoryArgs {
50
+ readonly expectedAdmin: string;
51
+ readonly transfer: TransferSpec;
52
+ }
53
+ /** An action on a pending transfer: the receiver accepts or rejects, the sender withdraws. */
54
+ export type TransferInstructionAction = 'accept' | 'reject' | 'withdraw';
55
+ /** Reads the wallet party's active contracts matching a filter (the wallet's own ACS). */
56
+ export type ReadContracts = (filter: ContractFilter) => Promise<ActiveContract[]>;
57
+ export interface TokenRegistry {
58
+ /**
59
+ * Whether a holding read through the CIP-56 HoldingV1 interface is one of this registry's, and genuine: of its
60
+ * template and signed by the party that issues it (any party can create a look-alike with the wallet party as
61
+ * observer). A wallet also holds other registries' holdings (Canton Coin, other registries' tokens); the token wallet
62
+ * lists and spends only the ones this returns true for.
63
+ */
64
+ servesHolding(contract: ActiveContract): boolean;
65
+ /**
66
+ * Filters a token wallet reads holdings with besides the CIP-56 HoldingV1 interface, for example the registry's own
67
+ * holding template, whose create argument still reads when the ledger could not compute a HoldingV1 view. Every read
68
+ * of holdings (a write's fresh read and the state snapshot) uses the same filters, and the same `servesHolding`.
69
+ */
70
+ readonly holdingFilters?: readonly ContractFilter[];
71
+ /**
72
+ * This registry's pending transfers (CIP-56 TransferInstructions) visible to the wallet, read through `read` and
73
+ * checked to be genuine (made by the registry, not a look-alike any party could create). Both directions: the caller
74
+ * splits them by sender and receiver.
75
+ */
76
+ pendingTransfers(read: ReadContracts): Promise<TransferOffer[]>;
77
+ /**
78
+ * The filters `pendingTransfers` reads. A token wallet adds them to its one state snapshot, so listing pending
79
+ * transfers costs no ledger read of its own; a read of any other filter goes to the wallet separately.
80
+ */
81
+ readonly pendingTransferFilters?: readonly ContractFilter[];
82
+ /**
83
+ * `Module:Entity` names of the templates this registry's transfer factory may have. A factory of any other template
84
+ * is refused before anything is signed.
85
+ */
86
+ readonly expectedTransferFactoryTemplates: readonly string[];
87
+ transferFactory(args: TransferFactoryArgs): Promise<TransferFactory>;
88
+ transferInstructionContext(registrar: string, instructionCid: string, action: TransferInstructionAction): Promise<ChoiceContext>;
89
+ }
90
+ /**
91
+ * Null when `factoryId` is one of the disclosed contracts and its template is expected; otherwise why not. A registry
92
+ * that names any other contract is refused before anything is signed.
93
+ */
94
+ export declare function factoryTemplateError(factory: FactoryWithChoiceContext, expectedTemplates: readonly string[]): string | null;
95
+ //# sourceMappingURL=token-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-registry.d.ts","sourceRoot":"","sources":["../../../src/wallets/token-registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEzC,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE/F,oFAAoF;AACpF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;CAC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a,GAAG,CAAC,MAAM,EAAE,cAAc,KAAK,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;AAElF,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,aAAa,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC;IACjD;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IACpD;;;;OAIG;IACH,gBAAgB,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAChE;;;OAGG;IACH,QAAQ,CAAC,sBAAsB,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IAC5D;;;OAGG;IACH,QAAQ,CAAC,gCAAgC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7D,eAAe,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IACrE,0BAA0B,CACxB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,aAAa,CAAC,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,wBAAwB,EACjC,iBAAiB,EAAE,SAAS,MAAM,EAAE,GACnC,MAAM,GAAG,IAAI,CASf"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.factoryTemplateError = factoryTemplateError;
4
+ const templates_1 = require("./templates");
5
+ /**
6
+ * Null when `factoryId` is one of the disclosed contracts and its template is expected; otherwise why not. A registry
7
+ * that names any other contract is refused before anything is signed.
8
+ */
9
+ function factoryTemplateError(factory, expectedTemplates) {
10
+ const disclosed = factory.disclosedContracts.find((contract) => contract.contractId === factory.factoryId);
11
+ if (!disclosed) {
12
+ return 'The registry named a factory it did not disclose.';
13
+ }
14
+ const name = (0, templates_1.qualifiedName)(disclosed.templateId);
15
+ return name !== null && expectedTemplates.includes(name)
16
+ ? null
17
+ : `The registry named a factory of an unexpected template (${disclosed.templateId}).`;
18
+ }
19
+ //# sourceMappingURL=token-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-registry.js","sourceRoot":"","sources":["../../../src/wallets/token-registry.ts"],"names":[],"mappings":";;;AAOA,2CAA4C;AAgG5C;;;GAGG;AACH,8BACE,OAAiC,EACjC,iBAAoC;IAEpC,MAAM,SAAS,GAAG,OAAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;IAC3G,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,mDAAmD,CAAC;IAC7D,CAAC;IACD,MAAM,IAAI,GAAG,IAAA,yBAAa,EAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IACjD,OAAO,IAAI,KAAK,IAAI,IAAI,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC;QACtD,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,2DAA2D,SAAS,CAAC,UAAU,IAAI,CAAC;AAC1F,CAAC"}