@fairmint/canton-node-sdk 0.0.296 → 0.0.298

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 (41) hide show
  1. package/README.md +44 -2
  2. package/build/src/clients/ledger-json-api/index.d.ts +2 -2
  3. package/build/src/clients/ledger-json-api/index.d.ts.map +1 -1
  4. package/build/src/clients/ledger-json-api/index.js +5 -1
  5. package/build/src/clients/ledger-json-api/index.js.map +1 -1
  6. package/build/src/external-parties/directory.d.ts +96 -0
  7. package/build/src/external-parties/directory.d.ts.map +1 -0
  8. package/build/src/external-parties/directory.js +238 -0
  9. package/build/src/external-parties/directory.js.map +1 -0
  10. package/build/src/external-parties/discovery.d.ts +72 -0
  11. package/build/src/external-parties/discovery.d.ts.map +1 -0
  12. package/build/src/external-parties/discovery.js +160 -0
  13. package/build/src/external-parties/discovery.js.map +1 -0
  14. package/build/src/external-parties/errors.d.ts +28 -0
  15. package/build/src/external-parties/errors.d.ts.map +1 -0
  16. package/build/src/external-parties/errors.js +33 -0
  17. package/build/src/external-parties/errors.js.map +1 -0
  18. package/build/src/external-parties/hints.d.ts +42 -0
  19. package/build/src/external-parties/hints.d.ts.map +1 -0
  20. package/build/src/external-parties/hints.js +83 -0
  21. package/build/src/external-parties/hints.js.map +1 -0
  22. package/build/src/external-parties/index.d.ts +20 -0
  23. package/build/src/external-parties/index.d.ts.map +1 -0
  24. package/build/src/external-parties/index.js +43 -0
  25. package/build/src/external-parties/index.js.map +1 -0
  26. package/build/src/external-parties/keys.d.ts +34 -0
  27. package/build/src/external-parties/keys.d.ts.map +1 -0
  28. package/build/src/external-parties/keys.js +209 -0
  29. package/build/src/external-parties/keys.js.map +1 -0
  30. package/build/src/index.d.ts +1 -0
  31. package/build/src/index.d.ts.map +1 -1
  32. package/build/src/index.js +2 -1
  33. package/build/src/index.js.map +1 -1
  34. package/build/src/utils/external-signing/canton-protocol.d.ts.map +1 -1
  35. package/build/src/utils/external-signing/canton-protocol.js +11 -14
  36. package/build/src/utils/external-signing/canton-protocol.js.map +1 -1
  37. package/build/src/wallets/index.d.ts +2 -3
  38. package/build/src/wallets/index.d.ts.map +1 -1
  39. package/build/src/wallets/index.js +2 -3
  40. package/build/src/wallets/index.js.map +1 -1
  41. package/package.json +16 -88
@@ -0,0 +1,160 @@
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
@@ -0,0 +1 @@
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;AAElD;;;;;;;;;;;GAWG;AACI,KAAK,kCAAkC,KAU7C;IACC,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IACvE,IAAI,CAAC,IAAA,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 * 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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,33 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,42 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,83 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hints.js","sourceRoot":"","sources":["../../../src/external-parties/hints.ts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,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,SAAS,CAAC;IAC5D,IAAI,KAAK,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"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Browser-safe Canton external-party discovery: "find every party this key controls". Import
3
+ * `@fairmint/canton-node-sdk/external-parties` in a browser bundle (it loads `@noble/hashes` and none of the SDK's Node
4
+ * dependencies); the package root also exports it as the `ExternalParties` namespace.
5
+ *
6
+ * - Identity: {@link deriveCantonEd25519PublicKeyFingerprint} (`1220` + hex(sha256(int32be(12) || rawKey))),
7
+ * {@link buildExternalPartyId} (`hint::fingerprint`), {@link readPartyNamespace}, {@link parseExternalPartyId},
8
+ * {@link normalizeEd25519PublicKeyForCanton} and {@link decodeEd25519PublicKey}.
9
+ * - Discovery: {@link createExternalPartyDirectory} over a Ledger JSON API client (bounded, cached `GET /v2/parties` scans
10
+ * filtered to the key's namespace, exact `GET /v2/parties/{party}` lookups of the hints asked for), and
11
+ * {@link discoverExternalParties}, the same orchestration over any list and lookup callbacks.
12
+ * - Hints for new parties: {@link suggestExternalPartyHint} and {@link validateExternalPartyHint}.
13
+ * - Errors: {@link ExternalPartyError} and {@link isExternalPartyError}.
14
+ */
15
+ export { createExternalPartyDirectory, type ExternalPartyDirectory, type ExternalPartyDirectoryLedgerClient, type ExternalPartyDirectoryOptions, type ExternalPartyDirectoryRequestConfig, type ExternalPartyFound, type ExternalPartyKey, } from './directory';
16
+ export { discoverExternalParties, MAX_EXTERNAL_PARTY_LOOKUP_HINTS, type ExternalPartyDiscovery, type ExternalPartyEntry, type ExternalPartyListAnswer, type ExternalPartyListing, type ExternalPartyLookupAnswer, } from './discovery';
17
+ export { ExternalPartyError, isExternalPartyError, type ExternalPartyErrorCode } from './errors';
18
+ export { DEFAULT_EXTERNAL_PARTY_HINT, MAX_NEW_EXTERNAL_PARTY_HINT_LENGTH, MAX_SUGGESTED_EXTERNAL_PARTY_HINT_BASE_LENGTH, suggestExternalPartyHint, validateExternalPartyHint, type ExternalPartyHintError, } from './hints';
19
+ export { buildExternalPartyId, decodeEd25519PublicKey, deriveCantonEd25519PublicKeyFingerprint, fingerprintRawEd25519PublicKey, isCantonPublicKeyFingerprint, isExternalPartyHint, MAX_EXTERNAL_PARTY_ID_LENGTH, normalizeEd25519PublicKeyForCanton, parseExternalPartyId, readPartyNamespace, } from './keys';
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/external-parties/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EACL,4BAA4B,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,kCAAkC,EACvC,KAAK,6BAA6B,EAClC,KAAK,mCAAmC,EACxC,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,uBAAuB,EACvB,+BAA+B,EAC/B,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,GAC/B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,KAAK,sBAAsB,EAAE,MAAM,UAAU,CAAC;AACjG,OAAO,EACL,2BAA2B,EAC3B,kCAAkC,EAClC,6CAA6C,EAC7C,wBAAwB,EACxB,yBAAyB,EACzB,KAAK,sBAAsB,GAC5B,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,uCAAuC,EACvC,8BAA8B,EAC9B,4BAA4B,EAC5B,mBAAmB,EACnB,4BAA4B,EAC5B,kCAAkC,EAClC,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,QAAQ,CAAC"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readPartyNamespace = exports.parseExternalPartyId = exports.normalizeEd25519PublicKeyForCanton = exports.MAX_EXTERNAL_PARTY_ID_LENGTH = exports.isExternalPartyHint = exports.isCantonPublicKeyFingerprint = exports.fingerprintRawEd25519PublicKey = exports.deriveCantonEd25519PublicKeyFingerprint = exports.decodeEd25519PublicKey = exports.buildExternalPartyId = exports.validateExternalPartyHint = exports.suggestExternalPartyHint = exports.MAX_SUGGESTED_EXTERNAL_PARTY_HINT_BASE_LENGTH = exports.MAX_NEW_EXTERNAL_PARTY_HINT_LENGTH = exports.DEFAULT_EXTERNAL_PARTY_HINT = exports.isExternalPartyError = exports.ExternalPartyError = exports.MAX_EXTERNAL_PARTY_LOOKUP_HINTS = exports.discoverExternalParties = exports.createExternalPartyDirectory = void 0;
4
+ /**
5
+ * Browser-safe Canton external-party discovery: "find every party this key controls". Import
6
+ * `@fairmint/canton-node-sdk/external-parties` in a browser bundle (it loads `@noble/hashes` and none of the SDK's Node
7
+ * dependencies); the package root also exports it as the `ExternalParties` namespace.
8
+ *
9
+ * - Identity: {@link deriveCantonEd25519PublicKeyFingerprint} (`1220` + hex(sha256(int32be(12) || rawKey))),
10
+ * {@link buildExternalPartyId} (`hint::fingerprint`), {@link readPartyNamespace}, {@link parseExternalPartyId},
11
+ * {@link normalizeEd25519PublicKeyForCanton} and {@link decodeEd25519PublicKey}.
12
+ * - Discovery: {@link createExternalPartyDirectory} over a Ledger JSON API client (bounded, cached `GET /v2/parties` scans
13
+ * filtered to the key's namespace, exact `GET /v2/parties/{party}` lookups of the hints asked for), and
14
+ * {@link discoverExternalParties}, the same orchestration over any list and lookup callbacks.
15
+ * - Hints for new parties: {@link suggestExternalPartyHint} and {@link validateExternalPartyHint}.
16
+ * - Errors: {@link ExternalPartyError} and {@link isExternalPartyError}.
17
+ */
18
+ var directory_1 = require("./directory");
19
+ Object.defineProperty(exports, "createExternalPartyDirectory", { enumerable: true, get: function () { return directory_1.createExternalPartyDirectory; } });
20
+ var discovery_1 = require("./discovery");
21
+ Object.defineProperty(exports, "discoverExternalParties", { enumerable: true, get: function () { return discovery_1.discoverExternalParties; } });
22
+ Object.defineProperty(exports, "MAX_EXTERNAL_PARTY_LOOKUP_HINTS", { enumerable: true, get: function () { return discovery_1.MAX_EXTERNAL_PARTY_LOOKUP_HINTS; } });
23
+ var errors_1 = require("./errors");
24
+ Object.defineProperty(exports, "ExternalPartyError", { enumerable: true, get: function () { return errors_1.ExternalPartyError; } });
25
+ Object.defineProperty(exports, "isExternalPartyError", { enumerable: true, get: function () { return errors_1.isExternalPartyError; } });
26
+ var hints_1 = require("./hints");
27
+ Object.defineProperty(exports, "DEFAULT_EXTERNAL_PARTY_HINT", { enumerable: true, get: function () { return hints_1.DEFAULT_EXTERNAL_PARTY_HINT; } });
28
+ Object.defineProperty(exports, "MAX_NEW_EXTERNAL_PARTY_HINT_LENGTH", { enumerable: true, get: function () { return hints_1.MAX_NEW_EXTERNAL_PARTY_HINT_LENGTH; } });
29
+ Object.defineProperty(exports, "MAX_SUGGESTED_EXTERNAL_PARTY_HINT_BASE_LENGTH", { enumerable: true, get: function () { return hints_1.MAX_SUGGESTED_EXTERNAL_PARTY_HINT_BASE_LENGTH; } });
30
+ Object.defineProperty(exports, "suggestExternalPartyHint", { enumerable: true, get: function () { return hints_1.suggestExternalPartyHint; } });
31
+ Object.defineProperty(exports, "validateExternalPartyHint", { enumerable: true, get: function () { return hints_1.validateExternalPartyHint; } });
32
+ var keys_1 = require("./keys");
33
+ Object.defineProperty(exports, "buildExternalPartyId", { enumerable: true, get: function () { return keys_1.buildExternalPartyId; } });
34
+ Object.defineProperty(exports, "decodeEd25519PublicKey", { enumerable: true, get: function () { return keys_1.decodeEd25519PublicKey; } });
35
+ Object.defineProperty(exports, "deriveCantonEd25519PublicKeyFingerprint", { enumerable: true, get: function () { return keys_1.deriveCantonEd25519PublicKeyFingerprint; } });
36
+ Object.defineProperty(exports, "fingerprintRawEd25519PublicKey", { enumerable: true, get: function () { return keys_1.fingerprintRawEd25519PublicKey; } });
37
+ Object.defineProperty(exports, "isCantonPublicKeyFingerprint", { enumerable: true, get: function () { return keys_1.isCantonPublicKeyFingerprint; } });
38
+ Object.defineProperty(exports, "isExternalPartyHint", { enumerable: true, get: function () { return keys_1.isExternalPartyHint; } });
39
+ Object.defineProperty(exports, "MAX_EXTERNAL_PARTY_ID_LENGTH", { enumerable: true, get: function () { return keys_1.MAX_EXTERNAL_PARTY_ID_LENGTH; } });
40
+ Object.defineProperty(exports, "normalizeEd25519PublicKeyForCanton", { enumerable: true, get: function () { return keys_1.normalizeEd25519PublicKeyForCanton; } });
41
+ Object.defineProperty(exports, "parseExternalPartyId", { enumerable: true, get: function () { return keys_1.parseExternalPartyId; } });
42
+ Object.defineProperty(exports, "readPartyNamespace", { enumerable: true, get: function () { return keys_1.readPartyNamespace; } });
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/external-parties/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;GAaG;AACH,yCAQqB;AAPnB,yHAAA,4BAA4B,OAAA;AAQ9B,yCAQqB;AAPnB,oHAAA,uBAAuB,OAAA;AACvB,4HAAA,+BAA+B,OAAA;AAOjC,mCAAiG;AAAxF,4GAAA,kBAAkB,OAAA;AAAE,8GAAA,oBAAoB,OAAA;AACjD,iCAOiB;AANf,oHAAA,2BAA2B,OAAA;AAC3B,2HAAA,kCAAkC,OAAA;AAClC,sIAAA,6CAA6C,OAAA;AAC7C,iHAAA,wBAAwB,OAAA;AACxB,kHAAA,yBAAyB,OAAA;AAG3B,+BAWgB;AAVd,4GAAA,oBAAoB,OAAA;AACpB,8GAAA,sBAAsB,OAAA;AACtB,+HAAA,uCAAuC,OAAA;AACvC,sHAAA,8BAA8B,OAAA;AAC9B,oHAAA,4BAA4B,OAAA;AAC5B,2GAAA,mBAAmB,OAAA;AACnB,oHAAA,4BAA4B,OAAA;AAC5B,0HAAA,kCAAkC,OAAA;AAClC,4GAAA,oBAAoB,OAAA;AACpB,0GAAA,kBAAkB,OAAA"}
@@ -0,0 +1,34 @@
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
@@ -0,0 +1 @@
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"}