@fairmint/canton-node-sdk 0.0.300 → 0.0.302

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 (102) hide show
  1. package/README.md +116 -26
  2. package/build/src/clients/ledger-json-api/operations/v2/parties/external/generate-topology.d.ts +8 -6
  3. package/build/src/clients/ledger-json-api/operations/v2/parties/external/generate-topology.d.ts.map +1 -1
  4. package/build/src/clients/ledger-json-api/operations/v2/parties/external/generate-topology.js +8 -6
  5. package/build/src/clients/ledger-json-api/operations/v2/parties/external/generate-topology.js.map +1 -1
  6. package/build/src/clients/ledger-json-api/schemas/api/interactive-submission.d.ts +4 -1
  7. package/build/src/clients/ledger-json-api/schemas/api/interactive-submission.d.ts.map +1 -1
  8. package/build/src/clients/ledger-json-api/schemas/api/interactive-submission.js +1 -0
  9. package/build/src/clients/ledger-json-api/schemas/api/interactive-submission.js.map +1 -1
  10. package/build/src/external-parties/directory.d.ts +22 -10
  11. package/build/src/external-parties/directory.d.ts.map +1 -1
  12. package/build/src/external-parties/directory.js +42 -27
  13. package/build/src/external-parties/directory.js.map +1 -1
  14. package/build/src/external-parties/index.d.ts +9 -16
  15. package/build/src/external-parties/index.d.ts.map +1 -1
  16. package/build/src/external-parties/index.js +9 -35
  17. package/build/src/external-parties/index.js.map +1 -1
  18. package/build/src/utils/amulet/external-party-cc-token-standard-transfer.d.ts +1 -1
  19. package/build/src/utils/amulet/external-party-cc-token-standard-transfer.d.ts.map +1 -1
  20. package/build/src/utils/amulet/external-party-cc-token-standard-transfer.js +16 -5
  21. package/build/src/utils/amulet/external-party-cc-token-standard-transfer.js.map +1 -1
  22. package/build/src/utils/amulet/external-party-transfer-offer.d.ts +5 -3
  23. package/build/src/utils/amulet/external-party-transfer-offer.d.ts.map +1 -1
  24. package/build/src/utils/amulet/external-party-transfer-offer.js +21 -7
  25. package/build/src/utils/amulet/external-party-transfer-offer.js.map +1 -1
  26. package/build/src/utils/amulet/external-party-transfer-preapproval.d.ts +8 -1
  27. package/build/src/utils/amulet/external-party-transfer-preapproval.d.ts.map +1 -1
  28. package/build/src/utils/amulet/external-party-transfer-preapproval.js +30 -7
  29. package/build/src/utils/amulet/external-party-transfer-preapproval.js.map +1 -1
  30. package/build/src/utils/amulet/index.d.ts +0 -1
  31. package/build/src/utils/amulet/index.d.ts.map +1 -1
  32. package/build/src/utils/amulet/index.js +0 -1
  33. package/build/src/utils/amulet/index.js.map +1 -1
  34. package/build/src/utils/external-signing/canton-ed25519-signer.d.ts +7 -1
  35. package/build/src/utils/external-signing/canton-ed25519-signer.d.ts.map +1 -1
  36. package/build/src/utils/external-signing/canton-ed25519-signer.js +15 -7
  37. package/build/src/utils/external-signing/canton-ed25519-signer.js.map +1 -1
  38. package/build/src/utils/external-signing/canton-protocol.d.ts +5 -37
  39. package/build/src/utils/external-signing/canton-protocol.d.ts.map +1 -1
  40. package/build/src/utils/external-signing/canton-protocol.js +10 -217
  41. package/build/src/utils/external-signing/canton-protocol.js.map +1 -1
  42. package/build/src/utils/external-signing/create-external-party.d.ts +27 -6
  43. package/build/src/utils/external-signing/create-external-party.d.ts.map +1 -1
  44. package/build/src/utils/external-signing/create-external-party.js +39 -11
  45. package/build/src/utils/external-signing/create-external-party.js.map +1 -1
  46. package/build/src/utils/external-signing/execute-external-party-signed-transaction.d.ts +7 -3
  47. package/build/src/utils/external-signing/execute-external-party-signed-transaction.d.ts.map +1 -1
  48. package/build/src/utils/external-signing/execute-external-party-signed-transaction.js +17 -7
  49. package/build/src/utils/external-signing/execute-external-party-signed-transaction.js.map +1 -1
  50. package/build/src/utils/external-signing/external-party-lifecycle.js +2 -2
  51. package/build/src/utils/external-signing/external-party-lifecycle.js.map +1 -1
  52. package/build/src/utils/external-signing/external-party-onboarding.d.ts +56 -14
  53. package/build/src/utils/external-signing/external-party-onboarding.d.ts.map +1 -1
  54. package/build/src/utils/external-signing/external-party-onboarding.js +71 -26
  55. package/build/src/utils/external-signing/external-party-onboarding.js.map +1 -1
  56. package/build/src/utils/external-signing/external-party-wallet.d.ts +23 -6
  57. package/build/src/utils/external-signing/external-party-wallet.d.ts.map +1 -1
  58. package/build/src/utils/external-signing/external-party-wallet.js +52 -18
  59. package/build/src/utils/external-signing/external-party-wallet.js.map +1 -1
  60. package/build/src/utils/external-signing/external-signing-client.d.ts.map +1 -1
  61. package/build/src/utils/external-signing/external-signing-client.js +17 -16
  62. package/build/src/utils/external-signing/external-signing-client.js.map +1 -1
  63. package/build/src/utils/external-signing/hash-signature.d.ts +20 -0
  64. package/build/src/utils/external-signing/hash-signature.d.ts.map +1 -0
  65. package/build/src/utils/external-signing/hash-signature.js +63 -0
  66. package/build/src/utils/external-signing/hash-signature.js.map +1 -0
  67. package/build/src/utils/external-signing/onboarding-topology.d.ts +82 -0
  68. package/build/src/utils/external-signing/onboarding-topology.d.ts.map +1 -0
  69. package/build/src/utils/external-signing/onboarding-topology.js +213 -0
  70. package/build/src/utils/external-signing/onboarding-topology.js.map +1 -0
  71. package/build/src/utils/external-signing/party-identity.d.ts +43 -0
  72. package/build/src/utils/external-signing/party-identity.d.ts.map +1 -0
  73. package/build/src/utils/external-signing/party-identity.js +120 -0
  74. package/build/src/utils/external-signing/party-identity.js.map +1 -0
  75. package/build/src/utils/external-signing/prepared-transaction.d.ts +58 -0
  76. package/build/src/utils/external-signing/prepared-transaction.d.ts.map +1 -0
  77. package/build/src/utils/external-signing/prepared-transaction.js +158 -0
  78. package/build/src/utils/external-signing/prepared-transaction.js.map +1 -0
  79. package/build/src/utils/external-signing/wallet-ownership-checks.d.ts.map +1 -1
  80. package/build/src/utils/external-signing/wallet-ownership-checks.js +8 -5
  81. package/build/src/utils/external-signing/wallet-ownership-checks.js.map +1 -1
  82. package/package.json +6 -4
  83. package/build/src/external-parties/discovery.d.ts +0 -72
  84. package/build/src/external-parties/discovery.d.ts.map +0 -1
  85. package/build/src/external-parties/discovery.js +0 -160
  86. package/build/src/external-parties/discovery.js.map +0 -1
  87. package/build/src/external-parties/errors.d.ts +0 -28
  88. package/build/src/external-parties/errors.d.ts.map +0 -1
  89. package/build/src/external-parties/errors.js +0 -33
  90. package/build/src/external-parties/errors.js.map +0 -1
  91. package/build/src/external-parties/hints.d.ts +0 -42
  92. package/build/src/external-parties/hints.d.ts.map +0 -1
  93. package/build/src/external-parties/hints.js +0 -83
  94. package/build/src/external-parties/hints.js.map +0 -1
  95. package/build/src/external-parties/keys.d.ts +0 -34
  96. package/build/src/external-parties/keys.d.ts.map +0 -1
  97. package/build/src/external-parties/keys.js +0 -209
  98. package/build/src/external-parties/keys.js.map +0 -1
  99. package/build/src/utils/amulet/external-party-cc-transfer.d.ts +0 -67
  100. package/build/src/utils/amulet/external-party-cc-transfer.d.ts.map +0 -1
  101. package/build/src/utils/amulet/external-party-cc-transfer.js +0 -148
  102. package/build/src/utils/amulet/external-party-cc-transfer.js.map +0 -1
@@ -1,160 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MAX_EXTERNAL_PARTY_LOOKUP_HINTS = void 0;
4
- exports.discoverExternalParties = discoverExternalParties;
5
- exports.sortedEntries = sortedEntries;
6
- exports.raceAbort = raceAbort;
7
- exports.isBoundedIdentifier = isBoundedIdentifier;
8
- /**
9
- * "Find every party this key controls": a key's parties from a party list, plus exact lookups of the hints the list may
10
- * not show. Pure orchestration over two callbacks, so it serves {@link createExternalPartyDirectory} and any other party
11
- * store (an app's own port, a test double) alike. Browser-safe.
12
- */
13
- const errors_1 = require("./errors");
14
- const keys_1 = require("./keys");
15
- /** The most hints {@link discoverExternalParties} looks up in one call. */
16
- exports.MAX_EXTERNAL_PARTY_LOOKUP_HINTS = 16;
17
- /**
18
- * A key's parties: what `listParties` answers in the key's namespace, plus an exact `findParty` of each of `hints` the
19
- * list did not show. The lookups run even when the list says complete (a cached list can predate a party allocated
20
- * since); with a complete list a failed lookup is skipped, with an incomplete one it fails the call (`LOOKUP_FAILED`).
21
- * Either callback may be left out: without `listParties` the answer is never complete; without `findParty` the hints
22
- * are not checked (`hintsChecked: false` when the list is incomplete).
23
- *
24
- * `signal` goes to each callback and each call is raced against it, so a callback that ignores it does not hold the
25
- * call open (`ABORTED`). A callback's failure is `LIST_FAILED` or `LOOKUP_FAILED` with its error as `cause` (an
26
- * {@link ExternalPartyError} `ABORTED` or `INVALID_RESPONSE` it throws passes through as it is), and an unreadable
27
- * answer is `INVALID_RESPONSE`. Nothing is recorded or allocated.
28
- */
29
- async function discoverExternalParties(input) {
30
- const { publicKeyFingerprint, signal, listParties, findParty } = input;
31
- if (!(0, keys_1.isCantonPublicKeyFingerprint)(publicKeyFingerprint)) {
32
- throw (0, errors_1.invalidInput)('publicKeyFingerprint must be a Canton SHA-256 multihash (1220 and 64 lowercase hex characters)');
33
- }
34
- const hints = input.hints ?? [];
35
- if (!Array.isArray(hints) ||
36
- hints.length > exports.MAX_EXTERNAL_PARTY_LOOKUP_HINTS ||
37
- !hints.every((hint) => isBoundedIdentifier(hint) && (0, keys_1.isExternalPartyHint)(hint))) {
38
- throw (0, errors_1.invalidInput)(`hints must be at most ${exports.MAX_EXTERNAL_PARTY_LOOKUP_HINTS} trimmed party hints of Daml-LF Party characters, without "::" or a trailing ":"`);
39
- }
40
- const found = new Map();
41
- let complete = false;
42
- if (listParties !== undefined) {
43
- let listed;
44
- try {
45
- listed = await raceAbort(async () => listParties(signal ? { signal } : {}), signal, 'The party listing was aborted.');
46
- }
47
- catch (error) {
48
- if ((0, errors_1.isExternalPartyError)(error, 'ABORTED', 'INVALID_RESPONSE'))
49
- throw error;
50
- throw new errors_1.ExternalPartyError('LIST_FAILED', 'The participant could not list the parties.', { cause: error });
51
- }
52
- if (!isListAnswer(listed)) {
53
- throw new errors_1.ExternalPartyError('INVALID_RESPONSE', 'The party list is invalid.');
54
- }
55
- for (const entry of listed.parties) {
56
- // Only the key's own parties, whatever the list answered.
57
- if ((0, keys_1.parseExternalPartyId)(entry.partyId)?.namespace === publicKeyFingerprint) {
58
- found.set(entry.partyId, entry.hostedHere);
59
- }
60
- }
61
- ({ complete } = listed);
62
- }
63
- const hintsChecked = !(!complete && findParty === undefined && hints.length > 0);
64
- if (findParty !== undefined) {
65
- for (const hint of new Set(hints)) {
66
- const partyId = `${hint}::${publicKeyFingerprint}`;
67
- if (found.has(partyId) || partyId.length > keys_1.MAX_EXTERNAL_PARTY_ID_LENGTH)
68
- continue;
69
- let lookup;
70
- try {
71
- lookup = await raceAbort(async () => findParty(signal ? { partyId, signal } : { partyId }), signal, 'The party lookup was aborted.', partyId);
72
- }
73
- catch (error) {
74
- // An unreadable answer fails the call however it arrives (thrown, or returned and checked below).
75
- if ((0, errors_1.isExternalPartyError)(error, 'ABORTED', 'INVALID_RESPONSE'))
76
- throw error;
77
- // With a complete list the lookups only add to it: a failed one is skipped, unless the call was aborted.
78
- if (complete && !signal?.aborted)
79
- continue;
80
- throw new errors_1.ExternalPartyError('LOOKUP_FAILED', 'The participant could not look up the party.', {
81
- cause: error,
82
- partyId,
83
- });
84
- }
85
- if (!isLookupAnswer(lookup)) {
86
- throw new errors_1.ExternalPartyError('INVALID_RESPONSE', 'The party lookup is invalid.', { partyId });
87
- }
88
- if (lookup.exists)
89
- found.set(partyId, lookup.hostedHere !== false);
90
- }
91
- }
92
- return Object.freeze({
93
- parties: sortedEntries(found),
94
- complete,
95
- hintsChecked,
96
- });
97
- }
98
- /** `parties` (party ID → hosted here) as frozen entries, sorted by hint (then party ID), in code-unit order. */
99
- function sortedEntries(parties) {
100
- const entries = [...parties].map(([partyId, hostedHere]) => Object.freeze({ partyId, partyHint: partyId.slice(0, partyId.indexOf('::')), hostedHere }));
101
- entries.sort((a, b) => compare(a.partyHint, b.partyHint) || compare(a.partyId, b.partyId));
102
- return Object.freeze(entries);
103
- }
104
- /** Awaits `start()`, unless `signal` aborts first (`ABORTED`); an already-aborted signal never starts it. */
105
- async function raceAbort(start, signal, message, partyId) {
106
- const aborted = () => new errors_1.ExternalPartyError('ABORTED', message, {
107
- cause: signal?.reason,
108
- ...(partyId === undefined ? {} : { partyId }),
109
- });
110
- if (!signal)
111
- return start();
112
- if (signal.aborted)
113
- throw aborted();
114
- const promise = start();
115
- let onAbort = () => undefined;
116
- const abortedWait = new Promise((_, reject) => {
117
- onAbort = () => reject(aborted());
118
- signal.addEventListener('abort', onAbort, { once: true });
119
- // `start()` may itself have aborted the signal, before the listener could hear it.
120
- if (signal.aborted)
121
- onAbort();
122
- });
123
- abortedWait.catch(() => undefined);
124
- promise.catch(() => undefined);
125
- try {
126
- return await Promise.race([promise, abortedWait]);
127
- }
128
- finally {
129
- signal.removeEventListener('abort', onAbort);
130
- }
131
- }
132
- /** A string of 1 to 255 characters (a Daml-LF Party at most), trimmed, on one line: what a listing may answer. */
133
- function isBoundedIdentifier(value) {
134
- return (typeof value === 'string' &&
135
- value.length > 0 &&
136
- value.length <= keys_1.MAX_EXTERNAL_PARTY_ID_LENGTH &&
137
- value.trim() === value &&
138
- !/[\r\n]/u.test(value));
139
- }
140
- function isListAnswer(value) {
141
- if (typeof value !== 'object' || value === null)
142
- return false;
143
- const { parties, complete } = value;
144
- return (typeof complete === 'boolean' &&
145
- Array.isArray(parties) &&
146
- parties.every((entry) => typeof entry === 'object' &&
147
- entry !== null &&
148
- isBoundedIdentifier(entry['partyId']) &&
149
- typeof entry['hostedHere'] === 'boolean'));
150
- }
151
- function isLookupAnswer(value) {
152
- if (typeof value !== 'object' || value === null)
153
- return false;
154
- const { exists, hostedHere } = value;
155
- return typeof exists === 'boolean' && (hostedHere === undefined || typeof hostedHere === 'boolean');
156
- }
157
- function compare(a, b) {
158
- return a < b ? -1 : a > b ? 1 : 0;
159
- }
160
- //# sourceMappingURL=discovery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../../src/external-parties/discovery.ts"],"names":[],"mappings":";;;;;;;AAAA;;;;GAIG;AACH,qCAAkF;AAClF,iCAKgB;AA0ChB,2EAA2E;AAC9D,QAAA,+BAA+B,GAAG,EAAE,CAAC;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CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpC,CAAC"}
@@ -1,28 +0,0 @@
1
- /**
2
- * The external-party module's one error type. Browser-safe: no Node or SDK dependency, and matched by a brand rather
3
- * than `instanceof`, so it is recognised across copies of this module.
4
- */
5
- /**
6
- * Why an external-party call failed:
7
- *
8
- * - `INVALID_INPUT`: a key, fingerprint, hint, option or argument the caller passed is not valid.
9
- * - `INVALID_RESPONSE`: the participant (or a `listParties` / `findParty` callback) answered something unreadable.
10
- * - `ABORTED`: the caller's `signal` aborted the call.
11
- * - `LIST_FAILED`: reading the participant's party list failed; `cause` is the ledger client's error.
12
- * - `LOOKUP_FAILED`: an exact party lookup failed; `cause` is the ledger client's error.
13
- */
14
- export type ExternalPartyErrorCode = 'INVALID_INPUT' | 'INVALID_RESPONSE' | 'ABORTED' | 'LIST_FAILED' | 'LOOKUP_FAILED';
15
- export declare class ExternalPartyError extends Error {
16
- readonly name = "ExternalPartyError";
17
- readonly code: ExternalPartyErrorCode;
18
- /** For `LOOKUP_FAILED`, and `ABORTED` or `INVALID_RESPONSE` of a lookup: the party ID that was looked up. */
19
- readonly partyId: string | undefined;
20
- constructor(code: ExternalPartyErrorCode, message: string, options?: {
21
- readonly cause?: unknown;
22
- readonly partyId?: string;
23
- });
24
- }
25
- /** Whether `error` is an {@link ExternalPartyError} (of any copy of this module), optionally with one of `codes`. */
26
- export declare function isExternalPartyError(error: unknown, ...codes: readonly ExternalPartyErrorCode[]): error is ExternalPartyError;
27
- export declare function invalidInput(message: string): ExternalPartyError;
28
- //# sourceMappingURL=errors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/external-parties/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;GAQG;AACH,MAAM,MAAM,sBAAsB,GAAG,eAAe,GAAG,kBAAkB,GAAG,SAAS,GAAG,aAAa,GAAG,eAAe,CAAC;AAIxH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,SAAyB,IAAI,wBAAwB;IACrD,SAAgB,IAAI,EAAE,sBAAsB,CAAC;IAC7C,6GAA6G;IAC7G,SAAgB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5C,YACE,IAAI,EAAE,sBAAsB,EAC5B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;QAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAO,EAStE;CACF;AAED,qHAAqH;AACrH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EACd,GAAG,KAAK,EAAE,SAAS,sBAAsB,EAAE,GAC1C,KAAK,IAAI,kBAAkB,CAG7B;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,CAEhE"}
@@ -1,33 +0,0 @@
1
- "use strict";
2
- /**
3
- * The external-party module's one error type. Browser-safe: no Node or SDK dependency, and matched by a brand rather
4
- * than `instanceof`, so it is recognised across copies of this module.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ExternalPartyError = void 0;
8
- exports.isExternalPartyError = isExternalPartyError;
9
- exports.invalidInput = invalidInput;
10
- const BRAND = Symbol.for('@fairmint/canton-node-sdk/ExternalPartyError');
11
- class ExternalPartyError extends Error {
12
- constructor(code, message, options = {}) {
13
- super(message);
14
- this.name = 'ExternalPartyError';
15
- this.code = code;
16
- this.partyId = options.partyId;
17
- if ('cause' in options) {
18
- Object.defineProperty(this, 'cause', { value: options.cause, enumerable: false, writable: true });
19
- }
20
- Object.defineProperty(this, BRAND, { value: true });
21
- }
22
- }
23
- exports.ExternalPartyError = ExternalPartyError;
24
- /** Whether `error` is an {@link ExternalPartyError} (of any copy of this module), optionally with one of `codes`. */
25
- function isExternalPartyError(error, ...codes) {
26
- if (typeof error !== 'object' || error === null || error[BRAND] !== true)
27
- return false;
28
- return codes.length === 0 || codes.includes(error.code);
29
- }
30
- function invalidInput(message) {
31
- return new ExternalPartyError('INVALID_INPUT', message);
32
- }
33
- //# sourceMappingURL=errors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/external-parties/errors.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAaH,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;AAEzE,wBAAgC,SAAQ,KAAK;IAM3C,YACE,IAA4B,EAC5B,OAAe,EACf,OAAO,GAA4D,EAAE;QAErE,KAAK,CAAC,OAAO,CAAC,CAAC;QAVQ,SAAI,GAAG,oBAAoB,CAAC;QAWnD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,OAAO,IAAI,OAAO,EAAE,CAAC;YACvB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QACpG,CAAC;QACD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;CACF;;AAED,qHAAqH;AACrH,8BACE,KAAc,EACd,GAAG,KAAwC;IAE3C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAK,KAAiC,CAAC,KAAK,CAAC,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IACpH,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAE,KAA4B,CAAC,IAAI,CAAC,CAAC;AAClF,CAAC;AAED,sBAA6B,OAAe;IAC1C,OAAO,IAAI,kBAAkB,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;AAC1D,CAAC"}
@@ -1,42 +0,0 @@
1
- /**
2
- * Party hints for new external parties: a short, readable suggestion, and the check of a hint a user typed. Pure and
3
- * browser-safe. A party ID already carries its key's fingerprint, so a hint only has to be unique among that key's own
4
- * parties. The hint is public and permanent on the ledger (every counterparty, Scan and explorers see the party ID):
5
- * never a name, email or other personal data.
6
- */
7
- /** The hint {@link suggestExternalPartyHint} uses when given no base name. */
8
- export declare const DEFAULT_EXTERNAL_PARTY_HINT = "wallet";
9
- /** The longest base {@link suggestExternalPartyHint} keeps, before any `-2`, `-3`, ... suffix. */
10
- export declare const MAX_SUGGESTED_EXTERNAL_PARTY_HINT_BASE_LENGTH = 24;
11
- /** The longest new party hint {@link validateExternalPartyHint} accepts. */
12
- export declare const MAX_NEW_EXTERNAL_PARTY_HINT_LENGTH = 40;
13
- /**
14
- * Why a new party hint is refused:
15
- *
16
- * - `empty`: nothing but whitespace.
17
- * - `too-long`: more than {@link MAX_NEW_EXTERNAL_PARTY_HINT_LENGTH} characters.
18
- * - `charset`: not a letter or digit followed by letters, digits, `-` and `_`.
19
- * - `taken`: one of the key's parties already has it (use that party instead).
20
- */
21
- export type ExternalPartyHintError = 'empty' | 'too-long' | 'charset' | 'taken';
22
- /**
23
- * A short, readable party hint, unique among the key's parties: `base` reduced to lowercase letters, digits and dashes
24
- * (at most {@link MAX_SUGGESTED_EXTERNAL_PARTY_HINT_BASE_LENGTH} characters), else `fallback` reduced the same way
25
- * ({@link DEFAULT_EXTERNAL_PARTY_HINT} by default), then `-2`, `-3`, ... until it is not one of `taken` (the hints of
26
- * the key's parties). Pass an app label or a nickname the user picks as `base`.
27
- */
28
- export declare function suggestExternalPartyHint(options?: {
29
- readonly base?: string;
30
- readonly taken?: Iterable<string>;
31
- readonly fallback?: string;
32
- }): string;
33
- /**
34
- * Checks a hint the user typed for a **new** party, after trimming it: null when it is fine, else why not. `taken` is
35
- * the hints the key's parties already have.
36
- *
37
- * Only for new names: an existing party keeps its hint, which may be longer or use other characters, so check `taken`
38
- * first and use an existing party by its own hint without validating it. The rule is deliberately narrower than what
39
- * the participant accepts, so a hint is short, readable and safe in a URL.
40
- */
41
- export declare function validateExternalPartyHint(hint: string, taken?: readonly string[]): ExternalPartyHintError | null;
42
- //# sourceMappingURL=hints.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hints.d.ts","sourceRoot":"","sources":["../../../src/external-parties/hints.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,8EAA8E;AAC9E,eAAO,MAAM,2BAA2B,WAAW,CAAC;AAEpD,kGAAkG;AAClG,eAAO,MAAM,6CAA6C,KAAK,CAAC;AAEhE,4EAA4E;AAC5E,eAAO,MAAM,kCAAkC,KAAK,CAAC;AAOrD;;;;;;;GAOG;AACH,MAAM,MAAM,sBAAsB,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC;AAEhF;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,GAAE;IACP,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAClC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACvB,GACL,MAAM,CASR;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,SAAS,MAAM,EAAO,GAAG,sBAAsB,GAAG,IAAI,CAOpH"}
@@ -1,83 +0,0 @@
1
- "use strict";
2
- /**
3
- * Party hints for new external parties: a short, readable suggestion, and the check of a hint a user typed. Pure and
4
- * browser-safe. A party ID already carries its key's fingerprint, so a hint only has to be unique among that key's own
5
- * parties. The hint is public and permanent on the ledger (every counterparty, Scan and explorers see the party ID):
6
- * never a name, email or other personal data.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.MAX_NEW_EXTERNAL_PARTY_HINT_LENGTH = exports.MAX_SUGGESTED_EXTERNAL_PARTY_HINT_BASE_LENGTH = exports.DEFAULT_EXTERNAL_PARTY_HINT = void 0;
10
- exports.suggestExternalPartyHint = suggestExternalPartyHint;
11
- exports.validateExternalPartyHint = validateExternalPartyHint;
12
- /** The hint {@link suggestExternalPartyHint} uses when given no base name. */
13
- exports.DEFAULT_EXTERNAL_PARTY_HINT = 'wallet';
14
- /** The longest base {@link suggestExternalPartyHint} keeps, before any `-2`, `-3`, ... suffix. */
15
- exports.MAX_SUGGESTED_EXTERNAL_PARTY_HINT_BASE_LENGTH = 24;
16
- /** The longest new party hint {@link validateExternalPartyHint} accepts. */
17
- exports.MAX_NEW_EXTERNAL_PARTY_HINT_LENGTH = 40;
18
- /** The most characters of `base` {@link suggestExternalPartyHint} reads: far more than it keeps. */
19
- const MAX_BASE_INPUT_LENGTH = 1000;
20
- const NEW_PARTY_HINT_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]*$/u;
21
- /**
22
- * A short, readable party hint, unique among the key's parties: `base` reduced to lowercase letters, digits and dashes
23
- * (at most {@link MAX_SUGGESTED_EXTERNAL_PARTY_HINT_BASE_LENGTH} characters), else `fallback` reduced the same way
24
- * ({@link DEFAULT_EXTERNAL_PARTY_HINT} by default), then `-2`, `-3`, ... until it is not one of `taken` (the hints of
25
- * the key's parties). Pass an app label or a nickname the user picks as `base`.
26
- */
27
- function suggestExternalPartyHint(options = {}) {
28
- // A base, or the fallback, reduced to lowercase letters, digits and dashes and bounded; '' when nothing is left.
29
- const base = reduceHintBase(options.base) || reduceHintBase(options.fallback) || exports.DEFAULT_EXTERNAL_PARTY_HINT;
30
- const taken = new Set(options.taken ?? []);
31
- if (!taken.has(base))
32
- return base;
33
- for (let suffix = 2;; suffix += 1) {
34
- const hint = `${base}-${suffix}`;
35
- if (!taken.has(hint))
36
- return hint;
37
- }
38
- }
39
- /**
40
- * Checks a hint the user typed for a **new** party, after trimming it: null when it is fine, else why not. `taken` is
41
- * the hints the key's parties already have.
42
- *
43
- * Only for new names: an existing party keeps its hint, which may be longer or use other characters, so check `taken`
44
- * first and use an existing party by its own hint without validating it. The rule is deliberately narrower than what
45
- * the participant accepts, so a hint is short, readable and safe in a URL.
46
- */
47
- function validateExternalPartyHint(hint, taken = []) {
48
- const trimmed = typeof hint === 'string' ? hint.trim() : '';
49
- if (trimmed === '')
50
- return 'empty';
51
- if (trimmed.length > exports.MAX_NEW_EXTERNAL_PARTY_HINT_LENGTH)
52
- return 'too-long';
53
- if (!NEW_PARTY_HINT_PATTERN.test(trimmed))
54
- return 'charset';
55
- if (taken.includes(trimmed))
56
- return 'taken';
57
- return null;
58
- }
59
- /** `value` without leading and trailing dashes. */
60
- function trimDashes(value) {
61
- let start = 0;
62
- let end = value.length;
63
- while (start < end && value[start] === '-')
64
- start += 1;
65
- while (end > start && value[end - 1] === '-')
66
- end -= 1;
67
- return value.slice(start, end);
68
- }
69
- /**
70
- * `value` reduced to a suggestion base: lowercase letters, digits and dashes, at most
71
- * {@link MAX_SUGGESTED_EXTERNAL_PARTY_HINT_BASE_LENGTH} characters, no leading or trailing dash; '' when nothing is
72
- * left. Linear time: the input is bounded first, and dashes are trimmed without a backtracking pattern.
73
- */
74
- function reduceHintBase(value) {
75
- const reduced = (typeof value === 'string' ? value : '')
76
- .slice(0, MAX_BASE_INPUT_LENGTH)
77
- .normalize('NFKD')
78
- .replace(/[\u0300-\u036f]/gu, '')
79
- .toLowerCase()
80
- .replace(/[^a-z0-9]+/gu, '-');
81
- return trimDashes(trimDashes(reduced).slice(0, exports.MAX_SUGGESTED_EXTERNAL_PARTY_HINT_BASE_LENGTH));
82
- }
83
- //# sourceMappingURL=hints.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hints.js","sourceRoot":"","sources":["../../../src/external-parties/hints.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAEH,8EAA8E;AACjE,QAAA,2BAA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CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IAC5C,OAAO,IAAI,CAAC;AACd,CAAC;AAED,mDAAmD;AACnD,SAAS,UAAU,CAAC,KAAa;IAC/B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC;IACvB,OAAO,KAAK,GAAG,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG;QAAE,KAAK,IAAI,CAAC,CAAC;IACvD,OAAO,GAAG,GAAG,KAAK,IAAI,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,GAAG;QAAE,GAAG,IAAI,CAAC,CAAC;IACvD,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACjC,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc,CAAC,KAAc;IACpC,MAAM,OAAO,GAAG,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;SACrD,KAAK,CAAC,CAAC,EAAE,qBAAqB,CAAC;SAC/B,SAAS,CAAC,MAAM,CAAC;SACjB,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;SAChC,WAAW,EAAE;SACb,OAAO,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;IAChC,OAAO,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,QAAA,6CAA6C,CAAC,CAAC,CAAC;AACjG,CAAC"}
@@ -1,34 +0,0 @@
1
- /** The longest party ID this module builds: a Daml-LF Party is at most 255 characters (`LedgerPartyIdSchema`). */
2
- export declare const MAX_EXTERNAL_PARTY_ID_LENGTH = 255;
3
- /**
4
- * Whether `hint` can start a party ID: non-empty, only Daml-LF Party characters, no `::` and no trailing `:` (which
5
- * would run into the separator). Not trimmed.
6
- */
7
- export declare function isExternalPartyHint(hint: unknown): hint is string;
8
- /**
9
- * The raw 32-byte Ed25519 key of a raw (32 bytes) or DER X.509 SubjectPublicKeyInfo (44 bytes) key, base64 or
10
- * base64url. Refuses a non-canonical encoding and the small-order points, as Canton does.
11
- */
12
- export declare function decodeEd25519PublicKey(publicKeyBase64: string): Uint8Array;
13
- /** Canton's DER X.509 SubjectPublicKeyInfo encoding (base64) of a raw or DER Ed25519 public key. */
14
- export declare function normalizeEd25519PublicKeyForCanton(publicKeyBase64: string): string;
15
- /** The Canton fingerprint of a raw 32-byte Ed25519 key: `1220` + hex(sha256(int32be(12) || rawKey)). */
16
- export declare function fingerprintRawEd25519PublicKey(rawPublicKey: Uint8Array): string;
17
- /** The Canton fingerprint (`1220…`, 68 lowercase hex characters) of a raw or DER Ed25519 public key in base64. */
18
- export declare function deriveCantonEd25519PublicKeyFingerprint(publicKeyBase64: string): string;
19
- /** Whether `value` is a Canton SHA-256 multihash fingerprint: `1220` and 64 lowercase hex characters. */
20
- export declare function isCantonPublicKeyFingerprint(value: unknown): value is string;
21
- /**
22
- * The party ID `hint::fingerprint`. The hint is trimmed; it must be non-empty, hold only Daml-LF Party characters, no
23
- * `::` and no trailing `:`, and leave the ID within {@link MAX_EXTERNAL_PARTY_ID_LENGTH} characters. The fingerprint
24
- * must be a lowercase SHA-256 multihash.
25
- */
26
- export declare function buildExternalPartyId(partyHint: string, publicKeyFingerprint: string): string;
27
- /** The parts of a `hint::namespace` party ID (exactly one `::`, both sides non-empty), or null. Not trimmed. */
28
- export declare function parseExternalPartyId(partyId: unknown): {
29
- readonly partyHint: string;
30
- readonly namespace: string;
31
- } | null;
32
- /** The namespace of a `hint::namespace` party ID (for an external party, its key's fingerprint), or null. */
33
- export declare function readPartyNamespace(partyId: unknown): string | null;
34
- //# sourceMappingURL=keys.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../src/external-parties/keys.ts"],"names":[],"mappings":"AAoBA,kHAAkH;AAClH,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAIhD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAQjE;AAYD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,eAAe,EAAE,MAAM,GAAG,UAAU,CAiB1E;AAED,oGAAoG;AACpG,wBAAgB,kCAAkC,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAMlF;AAED,wGAAwG;AACxG,wBAAgB,8BAA8B,CAAC,YAAY,EAAE,UAAU,GAAG,MAAM,CAQ/E;AAED,kHAAkH;AAClH,wBAAgB,uCAAuC,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAEvF;AAED,yGAAyG;AACzG,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE5E;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,GAAG,MAAM,CAoB5F;AAED,gHAAgH;AAChH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,GACf;IAAE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAKnE;AAED,6GAA6G;AAC7G,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAElE"}
@@ -1,209 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MAX_EXTERNAL_PARTY_ID_LENGTH = void 0;
4
- exports.isExternalPartyHint = isExternalPartyHint;
5
- exports.decodeEd25519PublicKey = decodeEd25519PublicKey;
6
- exports.normalizeEd25519PublicKeyForCanton = normalizeEd25519PublicKeyForCanton;
7
- exports.fingerprintRawEd25519PublicKey = fingerprintRawEd25519PublicKey;
8
- exports.deriveCantonEd25519PublicKeyFingerprint = deriveCantonEd25519PublicKeyFingerprint;
9
- exports.isCantonPublicKeyFingerprint = isCantonPublicKeyFingerprint;
10
- exports.buildExternalPartyId = buildExternalPartyId;
11
- exports.parseExternalPartyId = parseExternalPartyId;
12
- exports.readPartyNamespace = readPartyNamespace;
13
- /**
14
- * Canton external-party identity for an Ed25519 key, browser-safe (Uint8Array and `@noble/hashes`, no `Buffer`, no
15
- * `node:crypto`):
16
- *
17
- * - Fingerprint = `1220` + hex(sha256(int32be(12) || rawKey)): Canton's SHA-256 multihash of the key, hash purpose 12;
18
- * - Party ID = `hint::fingerprint`;
19
- * - A party's namespace is what follows its one `::`.
20
- *
21
- * The Node helpers of the same names under `utils/external-signing` (`canton-protocol.ts`) hash through this module and
22
- * throw the SDK's `ValidationError`; these throw {@link ExternalPartyError} (`INVALID_INPUT`).
23
- */
24
- const sha2_1 = require("@noble/hashes/sha2");
25
- const errors_1 = require("./errors");
26
- const ED25519_DER_X509_PREFIX = Uint8Array.of(0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x03, 0x21, 0x00);
27
- const ED25519_RAW_PUBLIC_KEY_LENGTH = 32;
28
- const ED25519_DER_X509_PUBLIC_KEY_LENGTH = ED25519_DER_X509_PREFIX.length + ED25519_RAW_PUBLIC_KEY_LENGTH;
29
- const CANTON_PUBLIC_KEY_FINGERPRINT_HASH_PURPOSE = 12;
30
- const CANTON_SHA256_MULTIHASH_PREFIX_HEX = '1220';
31
- const CANTON_FINGERPRINT_PATTERN = /^1220[0-9a-f]{64}$/;
32
- /** The longest party ID this module builds: a Daml-LF Party is at most 255 characters (`LedgerPartyIdSchema`). */
33
- exports.MAX_EXTERNAL_PARTY_ID_LENGTH = 255;
34
- /** The characters a Daml-LF Party may hold (`LedgerPartyIdSchema`): ASCII letters, digits, space, `:`, `-` and `_`. */
35
- const DAML_PARTY_CHARACTERS = /^[A-Za-z0-9:_ -]+$/;
36
- /**
37
- * Whether `hint` can start a party ID: non-empty, only Daml-LF Party characters, no `::` and no trailing `:` (which
38
- * would run into the separator). Not trimmed.
39
- */
40
- function isExternalPartyHint(hint) {
41
- return (typeof hint === 'string' &&
42
- hint.length > 0 &&
43
- DAML_PARTY_CHARACTERS.test(hint) &&
44
- !hint.includes('::') &&
45
- !hint.endsWith(':'));
46
- }
47
- const ED25519_FIELD_PRIME_LE = hexToBytes('edffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f');
48
- const ED25519_SMALL_ORDER_PUBLIC_KEYS_HEX = new Set([
49
- // The eight small-order points (the torsion subgroup), compared with the sign bit cleared: the identity (order 1),
50
- // y = -1 (order 2), y = 0 (order 4) and the two order-8 y coordinates. Their sign-bit twins match the same entries.
51
- '0100000000000000000000000000000000000000000000000000000000000000',
52
- 'ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f',
53
- '0000000000000000000000000000000000000000000000000000000000000000',
54
- 'c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a',
55
- '26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05',
56
- ]);
57
- /**
58
- * The raw 32-byte Ed25519 key of a raw (32 bytes) or DER X.509 SubjectPublicKeyInfo (44 bytes) key, base64 or
59
- * base64url. Refuses a non-canonical encoding and the small-order points, as Canton does.
60
- */
61
- function decodeEd25519PublicKey(publicKeyBase64) {
62
- const key = decodeBase64(publicKeyBase64);
63
- let raw;
64
- if (key.length === ED25519_RAW_PUBLIC_KEY_LENGTH) {
65
- raw = key;
66
- }
67
- else if (key.length === ED25519_DER_X509_PUBLIC_KEY_LENGTH &&
68
- ED25519_DER_X509_PREFIX.every((byte, index) => key[index] === byte)) {
69
- raw = key.slice(ED25519_DER_X509_PREFIX.length);
70
- }
71
- else {
72
- throw (0, errors_1.invalidInput)(`Invalid Ed25519 public key length: ${key.length}; expected raw 32 bytes or DER-wrapped 44 bytes`);
73
- }
74
- assertCanonicalEd25519PublicKey(raw);
75
- return raw;
76
- }
77
- /** Canton's DER X.509 SubjectPublicKeyInfo encoding (base64) of a raw or DER Ed25519 public key. */
78
- function normalizeEd25519PublicKeyForCanton(publicKeyBase64) {
79
- const raw = decodeEd25519PublicKey(publicKeyBase64);
80
- const der = new Uint8Array(ED25519_DER_X509_PUBLIC_KEY_LENGTH);
81
- der.set(ED25519_DER_X509_PREFIX);
82
- der.set(raw, ED25519_DER_X509_PREFIX.length);
83
- return bytesToBase64(der);
84
- }
85
- /** The Canton fingerprint of a raw 32-byte Ed25519 key: `1220` + hex(sha256(int32be(12) || rawKey)). */
86
- function fingerprintRawEd25519PublicKey(rawPublicKey) {
87
- if (rawPublicKey.length !== ED25519_RAW_PUBLIC_KEY_LENGTH) {
88
- throw (0, errors_1.invalidInput)(`Invalid Ed25519 public key length: ${rawPublicKey.length}; expected raw 32 bytes`);
89
- }
90
- const payload = new Uint8Array(4 + ED25519_RAW_PUBLIC_KEY_LENGTH);
91
- new DataView(payload.buffer).setInt32(0, CANTON_PUBLIC_KEY_FINGERPRINT_HASH_PURPOSE, false);
92
- payload.set(rawPublicKey, 4);
93
- return `${CANTON_SHA256_MULTIHASH_PREFIX_HEX}${bytesToHex((0, sha2_1.sha256)(payload))}`;
94
- }
95
- /** The Canton fingerprint (`1220…`, 68 lowercase hex characters) of a raw or DER Ed25519 public key in base64. */
96
- function deriveCantonEd25519PublicKeyFingerprint(publicKeyBase64) {
97
- return fingerprintRawEd25519PublicKey(decodeEd25519PublicKey(publicKeyBase64));
98
- }
99
- /** Whether `value` is a Canton SHA-256 multihash fingerprint: `1220` and 64 lowercase hex characters. */
100
- function isCantonPublicKeyFingerprint(value) {
101
- return typeof value === 'string' && CANTON_FINGERPRINT_PATTERN.test(value);
102
- }
103
- /**
104
- * The party ID `hint::fingerprint`. The hint is trimmed; it must be non-empty, hold only Daml-LF Party characters, no
105
- * `::` and no trailing `:`, and leave the ID within {@link MAX_EXTERNAL_PARTY_ID_LENGTH} characters. The fingerprint
106
- * must be a lowercase SHA-256 multihash.
107
- */
108
- function buildExternalPartyId(partyHint, publicKeyFingerprint) {
109
- const hint = typeof partyHint === 'string' ? partyHint.trim() : '';
110
- if (hint === '')
111
- throw (0, errors_1.invalidInput)('partyHint is required');
112
- // A trailing ':' would run into the separator (`wallet:` gives `wallet:::…`, which no reader parses).
113
- if (hint.includes('::') || hint.endsWith(':')) {
114
- throw (0, errors_1.invalidInput)('partyHint cannot include the reserved "::" separator or end with ":"');
115
- }
116
- if (!isExternalPartyHint(hint)) {
117
- throw (0, errors_1.invalidInput)('partyHint may hold only ASCII letters, digits, spaces, ":", "-" and "_"');
118
- }
119
- if (!isCantonPublicKeyFingerprint(publicKeyFingerprint)) {
120
- throw (0, errors_1.invalidInput)('publicKeyFingerprint must be a Canton SHA-256 multihash (1220 and 64 lowercase hex characters)');
121
- }
122
- const partyId = `${hint}::${publicKeyFingerprint}`;
123
- if (partyId.length > exports.MAX_EXTERNAL_PARTY_ID_LENGTH) {
124
- throw (0, errors_1.invalidInput)(`partyHint is too long: the party id would exceed ${exports.MAX_EXTERNAL_PARTY_ID_LENGTH} characters`);
125
- }
126
- return partyId;
127
- }
128
- /** The parts of a `hint::namespace` party ID (exactly one `::`, both sides non-empty), or null. Not trimmed. */
129
- function parseExternalPartyId(partyId) {
130
- if (typeof partyId !== 'string')
131
- return null;
132
- const separator = partyId.indexOf('::');
133
- if (separator <= 0 || separator !== partyId.lastIndexOf('::') || separator + 2 >= partyId.length)
134
- return null;
135
- return { partyHint: partyId.slice(0, separator), namespace: partyId.slice(separator + 2) };
136
- }
137
- /** The namespace of a `hint::namespace` party ID (for an external party, its key's fingerprint), or null. */
138
- function readPartyNamespace(partyId) {
139
- return parseExternalPartyId(partyId)?.namespace ?? null;
140
- }
141
- function assertCanonicalEd25519PublicKey(raw) {
142
- // Compared with the sign bit cleared, so both x signs of a small-order y (00..80 is the order-4 point) are refused.
143
- const encodedY = Uint8Array.from(raw);
144
- encodedY[ED25519_RAW_PUBLIC_KEY_LENGTH - 1] = (encodedY[ED25519_RAW_PUBLIC_KEY_LENGTH - 1] ?? 0) & 0x7f;
145
- if (ED25519_SMALL_ORDER_PUBLIC_KEYS_HEX.has(bytesToHex(encodedY))) {
146
- throw (0, errors_1.invalidInput)('Invalid Ed25519 public key: a small-order point is not safe for Canton signing');
147
- }
148
- // The encoded y coordinate (sign bit cleared) must be below the field prime.
149
- for (let index = ED25519_RAW_PUBLIC_KEY_LENGTH - 1; index >= 0; index -= 1) {
150
- const byte = (raw[index] ?? 0) & (index === ED25519_RAW_PUBLIC_KEY_LENGTH - 1 ? 0x7f : 0xff);
151
- const prime = ED25519_FIELD_PRIME_LE[index] ?? 0;
152
- if (byte < prime)
153
- return;
154
- if (byte > prime)
155
- break;
156
- }
157
- throw (0, errors_1.invalidInput)('Invalid Ed25519 public key: not canonically encoded');
158
- }
159
- function decodeBase64(value) {
160
- const normalized = typeof value === 'string' ? value.trim().replace(/-/g, '+').replace(/_/g, '/') : '';
161
- const unpadded = trimTrailingPadding(normalized);
162
- // Padding is optional, but when present it must complete the last quantum (as the Node decoder requires).
163
- if (!/^[A-Za-z0-9+/]+={0,2}$/.test(normalized) ||
164
- unpadded.length % 4 === 1 ||
165
- (unpadded.length !== normalized.length && normalized.length % 4 !== 0)) {
166
- throw (0, errors_1.invalidInput)('publicKeyBase64 must be base64-encoded');
167
- }
168
- const padded = unpadded.padEnd(unpadded.length + ((4 - (unpadded.length % 4)) % 4), '=');
169
- let binary;
170
- try {
171
- binary = atob(padded);
172
- }
173
- catch {
174
- throw (0, errors_1.invalidInput)('publicKeyBase64 must be base64-encoded');
175
- }
176
- const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
177
- // Refuse trailing bits that do not round-trip (a non-canonical encoding).
178
- if (trimTrailingPadding(bytesToBase64(bytes)) !== unpadded) {
179
- throw (0, errors_1.invalidInput)('publicKeyBase64 must be base64-encoded');
180
- }
181
- return bytes;
182
- }
183
- /** `value` without trailing `=`, in linear time (no backtracking pattern on caller input). */
184
- function trimTrailingPadding(value) {
185
- let end = value.length;
186
- while (end > 0 && value[end - 1] === '=')
187
- end -= 1;
188
- return value.slice(0, end);
189
- }
190
- function bytesToBase64(bytes) {
191
- let binary = '';
192
- for (const byte of bytes)
193
- binary += String.fromCharCode(byte);
194
- return btoa(binary);
195
- }
196
- function bytesToHex(bytes) {
197
- let hex = '';
198
- for (const byte of bytes)
199
- hex += byte.toString(16).padStart(2, '0');
200
- return hex;
201
- }
202
- function hexToBytes(hex) {
203
- const bytes = new Uint8Array(hex.length / 2);
204
- for (let index = 0; index < bytes.length; index += 1) {
205
- bytes[index] = parseInt(hex.slice(index * 2, index * 2 + 2), 16);
206
- }
207
- return bytes;
208
- }
209
- //# sourceMappingURL=keys.js.map