@fairmint/canton-node-sdk 0.0.300 → 0.0.301

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 (98) hide show
  1. package/README.md +108 -22
  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/external-parties/directory.d.ts +22 -10
  7. package/build/src/external-parties/directory.d.ts.map +1 -1
  8. package/build/src/external-parties/directory.js +42 -27
  9. package/build/src/external-parties/directory.js.map +1 -1
  10. package/build/src/external-parties/index.d.ts +9 -16
  11. package/build/src/external-parties/index.d.ts.map +1 -1
  12. package/build/src/external-parties/index.js +9 -35
  13. package/build/src/external-parties/index.js.map +1 -1
  14. package/build/src/utils/amulet/external-party-cc-token-standard-transfer.d.ts +1 -1
  15. package/build/src/utils/amulet/external-party-cc-token-standard-transfer.d.ts.map +1 -1
  16. package/build/src/utils/amulet/external-party-cc-token-standard-transfer.js +16 -5
  17. package/build/src/utils/amulet/external-party-cc-token-standard-transfer.js.map +1 -1
  18. package/build/src/utils/amulet/external-party-transfer-offer.d.ts +5 -3
  19. package/build/src/utils/amulet/external-party-transfer-offer.d.ts.map +1 -1
  20. package/build/src/utils/amulet/external-party-transfer-offer.js +21 -7
  21. package/build/src/utils/amulet/external-party-transfer-offer.js.map +1 -1
  22. package/build/src/utils/amulet/external-party-transfer-preapproval.d.ts +8 -1
  23. package/build/src/utils/amulet/external-party-transfer-preapproval.d.ts.map +1 -1
  24. package/build/src/utils/amulet/external-party-transfer-preapproval.js +30 -7
  25. package/build/src/utils/amulet/external-party-transfer-preapproval.js.map +1 -1
  26. package/build/src/utils/amulet/index.d.ts +0 -1
  27. package/build/src/utils/amulet/index.d.ts.map +1 -1
  28. package/build/src/utils/amulet/index.js +0 -1
  29. package/build/src/utils/amulet/index.js.map +1 -1
  30. package/build/src/utils/external-signing/canton-ed25519-signer.d.ts +7 -1
  31. package/build/src/utils/external-signing/canton-ed25519-signer.d.ts.map +1 -1
  32. package/build/src/utils/external-signing/canton-ed25519-signer.js +15 -7
  33. package/build/src/utils/external-signing/canton-ed25519-signer.js.map +1 -1
  34. package/build/src/utils/external-signing/canton-protocol.d.ts +5 -37
  35. package/build/src/utils/external-signing/canton-protocol.d.ts.map +1 -1
  36. package/build/src/utils/external-signing/canton-protocol.js +10 -217
  37. package/build/src/utils/external-signing/canton-protocol.js.map +1 -1
  38. package/build/src/utils/external-signing/create-external-party.d.ts +27 -6
  39. package/build/src/utils/external-signing/create-external-party.d.ts.map +1 -1
  40. package/build/src/utils/external-signing/create-external-party.js +39 -11
  41. package/build/src/utils/external-signing/create-external-party.js.map +1 -1
  42. package/build/src/utils/external-signing/execute-external-party-signed-transaction.d.ts +7 -3
  43. package/build/src/utils/external-signing/execute-external-party-signed-transaction.d.ts.map +1 -1
  44. package/build/src/utils/external-signing/execute-external-party-signed-transaction.js +17 -7
  45. package/build/src/utils/external-signing/execute-external-party-signed-transaction.js.map +1 -1
  46. package/build/src/utils/external-signing/external-party-lifecycle.js +2 -2
  47. package/build/src/utils/external-signing/external-party-lifecycle.js.map +1 -1
  48. package/build/src/utils/external-signing/external-party-onboarding.d.ts +56 -14
  49. package/build/src/utils/external-signing/external-party-onboarding.d.ts.map +1 -1
  50. package/build/src/utils/external-signing/external-party-onboarding.js +71 -26
  51. package/build/src/utils/external-signing/external-party-onboarding.js.map +1 -1
  52. package/build/src/utils/external-signing/external-party-wallet.d.ts +23 -6
  53. package/build/src/utils/external-signing/external-party-wallet.d.ts.map +1 -1
  54. package/build/src/utils/external-signing/external-party-wallet.js +52 -18
  55. package/build/src/utils/external-signing/external-party-wallet.js.map +1 -1
  56. package/build/src/utils/external-signing/external-signing-client.d.ts.map +1 -1
  57. package/build/src/utils/external-signing/external-signing-client.js +17 -16
  58. package/build/src/utils/external-signing/external-signing-client.js.map +1 -1
  59. package/build/src/utils/external-signing/hash-signature.d.ts +20 -0
  60. package/build/src/utils/external-signing/hash-signature.d.ts.map +1 -0
  61. package/build/src/utils/external-signing/hash-signature.js +63 -0
  62. package/build/src/utils/external-signing/hash-signature.js.map +1 -0
  63. package/build/src/utils/external-signing/onboarding-topology.d.ts +82 -0
  64. package/build/src/utils/external-signing/onboarding-topology.d.ts.map +1 -0
  65. package/build/src/utils/external-signing/onboarding-topology.js +213 -0
  66. package/build/src/utils/external-signing/onboarding-topology.js.map +1 -0
  67. package/build/src/utils/external-signing/party-identity.d.ts +43 -0
  68. package/build/src/utils/external-signing/party-identity.d.ts.map +1 -0
  69. package/build/src/utils/external-signing/party-identity.js +120 -0
  70. package/build/src/utils/external-signing/party-identity.js.map +1 -0
  71. package/build/src/utils/external-signing/prepared-transaction.d.ts +58 -0
  72. package/build/src/utils/external-signing/prepared-transaction.d.ts.map +1 -0
  73. package/build/src/utils/external-signing/prepared-transaction.js +158 -0
  74. package/build/src/utils/external-signing/prepared-transaction.js.map +1 -0
  75. package/build/src/utils/external-signing/wallet-ownership-checks.d.ts.map +1 -1
  76. package/build/src/utils/external-signing/wallet-ownership-checks.js +8 -5
  77. package/build/src/utils/external-signing/wallet-ownership-checks.js.map +1 -1
  78. package/package.json +5 -3
  79. package/build/src/external-parties/discovery.d.ts +0 -72
  80. package/build/src/external-parties/discovery.d.ts.map +0 -1
  81. package/build/src/external-parties/discovery.js +0 -160
  82. package/build/src/external-parties/discovery.js.map +0 -1
  83. package/build/src/external-parties/errors.d.ts +0 -28
  84. package/build/src/external-parties/errors.d.ts.map +0 -1
  85. package/build/src/external-parties/errors.js +0 -33
  86. package/build/src/external-parties/errors.js.map +0 -1
  87. package/build/src/external-parties/hints.d.ts +0 -42
  88. package/build/src/external-parties/hints.d.ts.map +0 -1
  89. package/build/src/external-parties/hints.js +0 -83
  90. package/build/src/external-parties/hints.js.map +0 -1
  91. package/build/src/external-parties/keys.d.ts +0 -34
  92. package/build/src/external-parties/keys.d.ts.map +0 -1
  93. package/build/src/external-parties/keys.js +0 -209
  94. package/build/src/external-parties/keys.js.map +0 -1
  95. package/build/src/utils/amulet/external-party-cc-transfer.d.ts +0 -67
  96. package/build/src/utils/amulet/external-party-cc-transfer.d.ts.map +0 -1
  97. package/build/src/utils/amulet/external-party-cc-transfer.js +0 -148
  98. package/build/src/utils/amulet/external-party-cc-transfer.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-signature.d.ts","sourceRoot":"","sources":["../../../../src/utils/external-signing/hash-signature.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,wBAAwB;IACvC,wFAAwF;IACxF,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,oHAAoH;IACpH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,8DAA8D;IAC9D,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,4FAA4F;IAC5F,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CAc3F;AAED,kHAAkH;AAClH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAGpD;AAED,mFAAmF;AACnF,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAWjE"}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertCantonHashSigned = assertCantonHashSigned;
4
+ exports.isSignedHashHex = isSignedHashHex;
5
+ exports.decodeBase64 = decodeBase64;
6
+ /**
7
+ * Node-sdk's check of an external party's signature over a Canton hash. Internal: not exported from the package.
8
+ *
9
+ * The verification is `@fairmint/canton-protocol/signature`'s `verifyCantonHashSignature` (WebCrypto Ed25519), which
10
+ * resolves `false` on a signature that does not verify and rejects on malformed input. This wrapper fails closed on
11
+ * both: `false` is a {@link ValidationError}, malformed caller input (`INVALID_INPUT`) is a {@link ValidationError}
12
+ * carrying canton-protocol's refusal as `cause`, and any other rejection (`UNSUPPORTED`: no Ed25519 in this platform's
13
+ * WebCrypto) propagates as it is. Callers must await it before they allocate, execute or submit anything.
14
+ */
15
+ const signature_1 = require("@fairmint/canton-protocol/signature");
16
+ const errors_1 = require("../../core/errors");
17
+ const party_identity_1 = require("./party-identity");
18
+ const HASH_HEX_PATTERN = /^(?:[0-9a-fA-F]{64}|[0-9a-fA-F]{68})$/;
19
+ /**
20
+ * Resolves when `signatureBase64` is `publicKeyBase64`'s Ed25519 signature over `hashHex`; rejects otherwise (see the
21
+ * module comment for the error contract).
22
+ */
23
+ async function assertCantonHashSigned(input) {
24
+ // Decode here so the hex and base64 contracts of the names hold: canton-protocol would also read a hex signature or
25
+ // a base64 hash.
26
+ const hash = decodeHashHex(input.hashHex);
27
+ const signature = Uint8Array.from(decodeBase64(input.signatureBase64, 'signatureBase64'));
28
+ let valid;
29
+ try {
30
+ valid = await (0, signature_1.verifyCantonHashSignature)({ hash, signature, publicKey: input.publicKeyBase64 });
31
+ }
32
+ catch (error) {
33
+ throw (0, party_identity_1.callerInputError)(error);
34
+ }
35
+ if (!valid) {
36
+ throw new errors_1.ValidationError(input.failureMessage ?? 'Invalid Canton hash signature');
37
+ }
38
+ }
39
+ /** Whether `hex` (trimmed, either case) is a hash an external party signs: 32 bytes, or a 34-byte Canton hash. */
40
+ function isSignedHashHex(hex) {
41
+ const normalized = hex.trim();
42
+ return HASH_HEX_PATTERN.test(normalized) && (normalized.length === 64 || normalized.startsWith('1220'));
43
+ }
44
+ /** The bytes of strict base64 or base64url `value` (trimmed; padding optional). */
45
+ function decodeBase64(value, label) {
46
+ const normalized = value.trim().replace(/-/g, '+').replace(/_/g, '/');
47
+ if (!/^[A-Za-z0-9+/]+={0,2}$/.test(normalized) || normalized.length % 4 === 1) {
48
+ throw new errors_1.ValidationError(`${label} must be base64-encoded`, { [label]: value });
49
+ }
50
+ const padded = normalized.padEnd(normalized.length + ((4 - (normalized.length % 4)) % 4), '=');
51
+ const decoded = Buffer.from(padded, 'base64');
52
+ if (decoded.toString('base64').replace(/=+$/, '') !== normalized.replace(/=+$/, '')) {
53
+ throw new errors_1.ValidationError(`${label} must be base64-encoded`, { [label]: value });
54
+ }
55
+ return decoded;
56
+ }
57
+ function decodeHashHex(hashHex) {
58
+ if (!isSignedHashHex(hashHex)) {
59
+ throw new errors_1.ValidationError('Expected a hex-encoded Canton hash (34 bytes, 1220…) or prepared-transaction hash (32 bytes)', { hashHex });
60
+ }
61
+ return Uint8Array.from(Buffer.from(hashHex.trim(), 'hex'));
62
+ }
63
+ //# sourceMappingURL=hash-signature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-signature.js","sourceRoot":"","sources":["../../../../src/utils/external-signing/hash-signature.ts"],"names":[],"mappings":";;;;;AAAA;;;;;;;;GAQG;AACH,mEAAgF;AAChF,8CAAoD;AACpD,qDAAoD;AAEpD,MAAM,gBAAgB,GAAG,uCAAuC,CAAC;AAajE;;;GAGG;AACI,KAAK,iCAAiC,KAA+B;IAC1E,oHAAoH;IACpH,iBAAiB;IACjB,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAC1F,IAAI,KAAc,CAAC;IACnB,IAAI,CAAC;QACH,KAAK,GAAG,MAAM,IAAA,qCAAyB,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,eAAe,EAAE,CAAC,CAAC;IACjG,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,M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U,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC;QACpF,MAAM,IAAI,wBAAe,CAAC,GAAG,KAAK,yBAAyB,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IACnF,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,aAAa,CAAC,OAAe;IACpC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,wBAAe,CACvB,8FAA8F,EAC9F,EAAE,OAAO,EAAE,CACZ,CAAC;IACJ,CAAC;IACD,OAAO,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,82 @@
1
+ import { type HostingParticipantExpectation, type SigningKeyUsage } from '@fairmint/canton-protocol/topology';
2
+ import { type LedgerJsonApiClient } from '../../clients/ledger-json-api';
3
+ /** The usages Canton (3.4 and later) gives an external party's signing key in its generated onboarding topology. */
4
+ export declare const EXTERNAL_PARTY_KEY_USAGES: readonly SigningKeyUsage[];
5
+ /** The hosting a caller asks generate-topology for. */
6
+ export interface OnboardingHostingRequest {
7
+ readonly localParticipantObservationOnly?: boolean | undefined;
8
+ readonly otherConfirmingParticipantUids?: readonly string[] | undefined;
9
+ readonly confirmationThreshold?: number | undefined;
10
+ readonly observingParticipantUids?: readonly string[] | undefined;
11
+ /** The local participant's unique identifier as the caller knows it; the participant's own answer must match it. */
12
+ readonly expectedLocalParticipantUid?: string | undefined;
13
+ }
14
+ /** A hosting request whose own values are valid; the local participant is not known yet. */
15
+ export interface CheckedOnboardingHosting {
16
+ readonly localPermission: 'CONFIRMATION' | 'OBSERVATION';
17
+ readonly otherConfirming: readonly string[];
18
+ readonly observing: readonly string[];
19
+ readonly threshold: number;
20
+ readonly expectedLocalParticipantUid: string | undefined;
21
+ }
22
+ /** The fields of an {@link OnboardingHostingRequest} that are set. */
23
+ export interface OnboardingHostingFields {
24
+ readonly localParticipantObservationOnly?: boolean;
25
+ readonly otherConfirmingParticipantUids?: readonly string[];
26
+ readonly confirmationThreshold?: number;
27
+ readonly observingParticipantUids?: readonly string[];
28
+ readonly expectedLocalParticipantUid?: string;
29
+ }
30
+ /** The fields of {@link OnboardingHostingRequest} that `options` sets, to forward to another onboarding call. */
31
+ export declare function onboardingHostingOptions(options: OnboardingHostingRequest): OnboardingHostingFields;
32
+ /** The hosting the generated topology must state, exactly. */
33
+ export interface OnboardingHostingExpectation {
34
+ readonly participants: readonly HostingParticipantExpectation[];
35
+ readonly threshold: number;
36
+ }
37
+ /**
38
+ * Checks the caller's hosting options before anything is sent: every participant UID is a participant's unique
39
+ * identifier (`name::1220…`, no `PAR::` prefix; `expectedLocalParticipantUid` too), none is listed twice,
40
+ * `confirmationThreshold` is a non-negative integer, and at least one participant confirms, at least as many as the
41
+ * threshold. Throws a {@link ValidationError}.
42
+ */
43
+ export declare function checkOnboardingHosting(request: OnboardingHostingRequest): CheckedOnboardingHosting;
44
+ /**
45
+ * The exact hosting the topology must state, with the local participant's UID added. Throws a {@link ValidationError}
46
+ * when the caller listed the local participant among the other participants.
47
+ */
48
+ export declare function onboardingHostingExpectation(hosting: CheckedOnboardingHosting, localParticipantUid: string): OnboardingHostingExpectation;
49
+ /**
50
+ * The exact hosting the topology must state: {@link onboardingHostingExpectation} with the local participant's unique
51
+ * identifier read from `GET /v2/parties/participant-id`. An answer that is not one (`name::1220…`), or not the caller's
52
+ * `expectedLocalParticipantUid` when it is set, fails the operation. Without `expectedLocalParticipantUid` the local
53
+ * participant's identity is the participant's own word.
54
+ */
55
+ export declare function resolveOnboardingHosting(ledgerClient: LedgerJsonApiClient, hosting: CheckedOnboardingHosting): Promise<OnboardingHostingExpectation>;
56
+ /** The input of {@link verifyGeneratedOnboardingTopology}. */
57
+ export interface GeneratedOnboardingTopology {
58
+ /** The participant's topology transactions, base64. */
59
+ readonly transactions: readonly string[];
60
+ /** The participant's multi-hash of them, hex or base64. */
61
+ readonly multiHash: string;
62
+ /** The party requested: `hint::fingerprint` built from the request, never the participant's own value. */
63
+ readonly partyId: string;
64
+ /** The party's Ed25519 public key, raw or DER, base64. */
65
+ readonly publicKeyBase64: string;
66
+ readonly hosting: OnboardingHostingExpectation;
67
+ }
68
+ /**
69
+ * Checks the participant's generated topology against the requested onboarding and returns the multi-hash recomputed
70
+ * from it (canonical hex), the only hash to sign. A topology that differs, does not decode, or whose multi-hash is not
71
+ * the participant's fails the operation with an {@link OperationError} (`TRANSACTION_FAILED`) whose `cause` is
72
+ * canton-protocol's refusal and whose context names its `code` and `field`. A refusal of the expectation itself
73
+ * (`INVALID_INPUT` on `expected.*`) is the caller's input: a {@link ValidationError}.
74
+ */
75
+ export declare function verifyGeneratedOnboardingTopology(input: GeneratedOnboardingTopology): string;
76
+ /**
77
+ * Checks topology transactions a caller submits for allocation against the onboarding they must state (the party, its
78
+ * key, the hosting) and returns their recomputed multi-hash. Every refusal is the caller's input: a
79
+ * {@link ValidationError} whose `cause` is canton-protocol's refusal and whose context names its `code` and `field`.
80
+ */
81
+ export declare function verifySubmittedOnboardingTopology(input: GeneratedOnboardingTopology): string;
82
+ //# sourceMappingURL=onboarding-topology.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onboarding-topology.d.ts","sourceRoot":"","sources":["../../../../src/utils/external-signing/onboarding-topology.ts"],"names":[],"mappings":"AAkBA,OAAO,EACL,KAAK,6BAA6B,EAElC,KAAK,eAAe,EAErB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAKzE,oHAAoH;AACpH,eAAO,MAAM,yBAAyB,EAAE,SAAS,eAAe,EAI9D,CAAC;AAEH,uDAAuD;AACvD,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,+BAA+B,CAAC,EAAE,OAAO,GAAG,SAAS,CA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,OAAO,EAAE,wBAAwB,GAAG,wBAAwB,CAsClG;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,wBAAwB,EACjC,mBAAmB,EAAE,MAAM,GAC1B,4BAA4B,CAc9B;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,YAAY,EAAE,mBAAmB,EACjC,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,4BAA4B,CAAC,CAiBvC;AAED,8DAA8D;AAC9D,MAAM,WAAW,2BAA2B;IAC1C,uDAAuD;IACvD,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,0GAA0G;IAC1G,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,0DAA0D;IAC1D,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,4BAA4B,CAAC;CAChD;AAED;;;;;;GAMG;AACH,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,2BAA2B,GAAG,MAAM,CA0B5F;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,2BAA2B,GAAG,MAAM,CAyB5F"}
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EXTERNAL_PARTY_KEY_USAGES = void 0;
4
+ exports.onboardingHostingOptions = onboardingHostingOptions;
5
+ exports.checkOnboardingHosting = checkOnboardingHosting;
6
+ exports.onboardingHostingExpectation = onboardingHostingExpectation;
7
+ exports.resolveOnboardingHosting = resolveOnboardingHosting;
8
+ exports.verifyGeneratedOnboardingTopology = verifyGeneratedOnboardingTopology;
9
+ exports.verifySubmittedOnboardingTopology = verifySubmittedOnboardingTopology;
10
+ /**
11
+ * Node-sdk's check of the onboarding topology a participant generates for an external party. Internal: not exported
12
+ * from the package.
13
+ *
14
+ * A participant answers `/v2/parties/external/generate-topology` with topology transactions and their multi-hash, which
15
+ * the party's key signs. Node-sdk signs neither on the participant's word: `@fairmint/canton-protocol/topology` decodes
16
+ * the transaction, checks it states exactly the onboarding node-sdk asked for (the party, its one key with the usages
17
+ * Canton gives an external party's key, the hosting participants with their permissions, and the confirmation
18
+ * threshold), recomputes the multi-hash and compares it with the participant's. Only the recomputed multi-hash is
19
+ * handed to a signer.
20
+ *
21
+ * The expectation is derived from the request: the local participant (its unique identifier read from `GET
22
+ * /v2/parties/participant-id`, which must be `expectedLocalParticipantUid` when the caller pins it) hosts the party
23
+ * with `CONFIRMATION`, or `OBSERVATION` when `localParticipantObservationOnly`; each of
24
+ * `otherConfirmingParticipantUids` with `CONFIRMATION`; each of `observingParticipantUids` with `OBSERVATION`; the
25
+ * threshold is `confirmationThreshold`, or every confirming participant when it is omitted or 0 (Canton's default).
26
+ */
27
+ const party_1 = require("@fairmint/canton-protocol/party");
28
+ const topology_1 = require("@fairmint/canton-protocol/topology");
29
+ const errors_1 = require("../../core/errors");
30
+ const utils_1 = require("../../core/utils");
31
+ const party_identity_1 = require("./party-identity");
32
+ /** The usages Canton (3.4 and later) gives an external party's signing key in its generated onboarding topology. */
33
+ exports.EXTERNAL_PARTY_KEY_USAGES = Object.freeze([
34
+ 'NAMESPACE',
35
+ 'PROTOCOL',
36
+ 'PROOF_OF_OWNERSHIP',
37
+ ]);
38
+ /** The fields of {@link OnboardingHostingRequest} that `options` sets, to forward to another onboarding call. */
39
+ function onboardingHostingOptions(options) {
40
+ return {
41
+ ...(options.localParticipantObservationOnly !== undefined
42
+ ? { localParticipantObservationOnly: options.localParticipantObservationOnly }
43
+ : {}),
44
+ ...(options.otherConfirmingParticipantUids !== undefined
45
+ ? { otherConfirmingParticipantUids: options.otherConfirmingParticipantUids }
46
+ : {}),
47
+ ...(options.confirmationThreshold !== undefined ? { confirmationThreshold: options.confirmationThreshold } : {}),
48
+ ...(options.observingParticipantUids !== undefined
49
+ ? { observingParticipantUids: options.observingParticipantUids }
50
+ : {}),
51
+ ...(options.expectedLocalParticipantUid !== undefined
52
+ ? { expectedLocalParticipantUid: options.expectedLocalParticipantUid }
53
+ : {}),
54
+ };
55
+ }
56
+ /**
57
+ * Checks the caller's hosting options before anything is sent: every participant UID is a participant's unique
58
+ * identifier (`name::1220…`, no `PAR::` prefix; `expectedLocalParticipantUid` too), none is listed twice,
59
+ * `confirmationThreshold` is a non-negative integer, and at least one participant confirms, at least as many as the
60
+ * threshold. Throws a {@link ValidationError}.
61
+ */
62
+ function checkOnboardingHosting(request) {
63
+ const otherConfirming = readParticipantUids('otherConfirmingParticipantUids', request.otherConfirmingParticipantUids);
64
+ const observing = readParticipantUids('observingParticipantUids', request.observingParticipantUids);
65
+ const { expectedLocalParticipantUid } = request;
66
+ if (expectedLocalParticipantUid !== undefined && !(0, topology_1.isParticipantUid)(expectedLocalParticipantUid)) {
67
+ throw new errors_1.ValidationError('expectedLocalParticipantUid must be a participant unique identifier (name::1220 and 64 lowercase hex, no PAR:: prefix)', { expectedLocalParticipantUid });
68
+ }
69
+ const seen = new Set();
70
+ for (const uid of [...otherConfirming, ...observing]) {
71
+ if (seen.has(uid)) {
72
+ throw new errors_1.ValidationError('A hosting participant UID is listed more than once', { participantUid: uid });
73
+ }
74
+ seen.add(uid);
75
+ }
76
+ const localPermission = request.localParticipantObservationOnly === true ? 'OBSERVATION' : 'CONFIRMATION';
77
+ const confirmers = otherConfirming.length + (localPermission === 'CONFIRMATION' ? 1 : 0);
78
+ if (confirmers === 0) {
79
+ throw new errors_1.ValidationError('An external party needs at least one confirming participant: the local participant observes only and no other confirming participant is given');
80
+ }
81
+ const requested = request.confirmationThreshold;
82
+ if (requested !== undefined && (!Number.isSafeInteger(requested) || requested < 0)) {
83
+ throw new errors_1.ValidationError('confirmationThreshold must be a non-negative integer', {
84
+ confirmationThreshold: requested,
85
+ });
86
+ }
87
+ const threshold = requested === undefined || requested === 0 ? confirmers : requested;
88
+ if (threshold > confirmers) {
89
+ throw new errors_1.ValidationError('confirmationThreshold exceeds the number of confirming participants', {
90
+ confirmationThreshold: threshold,
91
+ confirmingParticipants: confirmers,
92
+ });
93
+ }
94
+ return { localPermission, otherConfirming, observing, threshold, expectedLocalParticipantUid };
95
+ }
96
+ /**
97
+ * The exact hosting the topology must state, with the local participant's UID added. Throws a {@link ValidationError}
98
+ * when the caller listed the local participant among the other participants.
99
+ */
100
+ function onboardingHostingExpectation(hosting, localParticipantUid) {
101
+ if (hosting.otherConfirming.includes(localParticipantUid) || hosting.observing.includes(localParticipantUid)) {
102
+ throw new errors_1.ValidationError('The local participant must not be listed among the other hosting participants', {
103
+ participantUid: localParticipantUid,
104
+ });
105
+ }
106
+ return {
107
+ participants: [
108
+ { participantUid: localParticipantUid, permission: hosting.localPermission },
109
+ ...hosting.otherConfirming.map((participantUid) => ({ participantUid, permission: 'CONFIRMATION' })),
110
+ ...hosting.observing.map((participantUid) => ({ participantUid, permission: 'OBSERVATION' })),
111
+ ],
112
+ threshold: hosting.threshold,
113
+ };
114
+ }
115
+ /**
116
+ * The exact hosting the topology must state: {@link onboardingHostingExpectation} with the local participant's unique
117
+ * identifier read from `GET /v2/parties/participant-id`. An answer that is not one (`name::1220…`), or not the caller's
118
+ * `expectedLocalParticipantUid` when it is set, fails the operation. Without `expectedLocalParticipantUid` the local
119
+ * participant's identity is the participant's own word.
120
+ */
121
+ async function resolveOnboardingHosting(ledgerClient, hosting) {
122
+ const response = await ledgerClient.getParticipantId();
123
+ const participantId = (0, utils_1.isRecord)(response) ? response['participantId'] : undefined;
124
+ if (!(0, topology_1.isParticipantUid)(participantId)) {
125
+ throw new errors_1.OperationError('Canton participant-id response did not include a participant unique identifier (name::1220…)', errors_1.OperationErrorCode.TRANSACTION_FAILED);
126
+ }
127
+ if (hosting.expectedLocalParticipantUid !== undefined && participantId !== hosting.expectedLocalParticipantUid) {
128
+ throw new errors_1.OperationError('Canton participant-id response is not the expected local participant', errors_1.OperationErrorCode.TRANSACTION_FAILED, { expectedLocalParticipantUid: hosting.expectedLocalParticipantUid, participantId });
129
+ }
130
+ return onboardingHostingExpectation(hosting, participantId);
131
+ }
132
+ /**
133
+ * Checks the participant's generated topology against the requested onboarding and returns the multi-hash recomputed
134
+ * from it (canonical hex), the only hash to sign. A topology that differs, does not decode, or whose multi-hash is not
135
+ * the participant's fails the operation with an {@link OperationError} (`TRANSACTION_FAILED`) whose `cause` is
136
+ * canton-protocol's refusal and whose context names its `code` and `field`. A refusal of the expectation itself
137
+ * (`INVALID_INPUT` on `expected.*`) is the caller's input: a {@link ValidationError}.
138
+ */
139
+ function verifyGeneratedOnboardingTopology(input) {
140
+ try {
141
+ return (0, topology_1.verifyPartyOnboardingTopology)({
142
+ transactions: input.transactions,
143
+ multiHash: input.multiHash,
144
+ expected: {
145
+ partyId: input.partyId,
146
+ publicKey: input.publicKeyBase64,
147
+ threshold: input.hosting.threshold,
148
+ participants: input.hosting.participants,
149
+ keyUsages: exports.EXTERNAL_PARTY_KEY_USAGES,
150
+ },
151
+ }).multiHash;
152
+ }
153
+ catch (error) {
154
+ if (!(0, party_1.isCantonProtocolError)(error))
155
+ throw error;
156
+ if (error.code === 'INVALID_INPUT' && error.field?.startsWith('expected.') === true) {
157
+ throw (0, party_identity_1.callerInputError)(error);
158
+ }
159
+ const operationError = new errors_1.OperationError(generatedTopologyRefusalMessage(error.code, error.field), errors_1.OperationErrorCode.TRANSACTION_FAILED, { code: error.code, ...(error.field === undefined ? {} : { field: error.field }) });
160
+ Object.defineProperty(operationError, 'cause', { value: error, enumerable: false, writable: true });
161
+ throw operationError;
162
+ }
163
+ }
164
+ /**
165
+ * Checks topology transactions a caller submits for allocation against the onboarding they must state (the party, its
166
+ * key, the hosting) and returns their recomputed multi-hash. Every refusal is the caller's input: a
167
+ * {@link ValidationError} whose `cause` is canton-protocol's refusal and whose context names its `code` and `field`.
168
+ */
169
+ function verifySubmittedOnboardingTopology(input) {
170
+ try {
171
+ return (0, topology_1.verifyPartyOnboardingTopology)({
172
+ transactions: input.transactions,
173
+ multiHash: input.multiHash,
174
+ expected: {
175
+ partyId: input.partyId,
176
+ publicKey: input.publicKeyBase64,
177
+ threshold: input.hosting.threshold,
178
+ participants: input.hosting.participants,
179
+ keyUsages: exports.EXTERNAL_PARTY_KEY_USAGES,
180
+ },
181
+ }).multiHash;
182
+ }
183
+ catch (error) {
184
+ if (!(0, party_1.isCantonProtocolError)(error))
185
+ throw error;
186
+ if (error.code === 'INVALID_INPUT')
187
+ throw (0, party_identity_1.callerInputError)(error);
188
+ const validationError = new errors_1.ValidationError(error.code === 'HASH_MISMATCH'
189
+ ? 'multiHashHex is not the multi-hash of topologyTransactions'
190
+ : 'topologyTransactions do not state the onboarding of partyId with this key and the requested hosting', { code: error.code, ...(error.field === undefined ? {} : { field: error.field }) });
191
+ Object.defineProperty(validationError, 'cause', { value: error, enumerable: false, writable: true });
192
+ throw validationError;
193
+ }
194
+ }
195
+ function generatedTopologyRefusalMessage(code, field) {
196
+ if (field === 'multiHash') {
197
+ return code === 'HASH_MISMATCH'
198
+ ? 'Canton topology generation response multiHash is not the multi-hash of its topology transactions'
199
+ : 'Canton topology generation response did not include a valid SHA-256 multihash';
200
+ }
201
+ return 'Canton topology generation response does not match the requested external-party onboarding';
202
+ }
203
+ function readParticipantUids(name, uids) {
204
+ if (uids === undefined)
205
+ return [];
206
+ return uids.map((uid, index) => {
207
+ if (!(0, topology_1.isParticipantUid)(uid)) {
208
+ throw new errors_1.ValidationError(`${name}[${index}] must be a participant unique identifier (name::1220 and 64 lowercase hex, no PAR:: prefix)`, { [name]: uid });
209
+ }
210
+ return uid;
211
+ });
212
+ }
213
+ //# sourceMappingURL=onboarding-topology.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onboarding-topology.js","sourceRoot":"","sources":["../../../../src/utils/external-signing/onboarding-topology.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,2DAAwE;AACxE,iEAK4C;AAE5C,8C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AAe;YAC5B,CAAC,CAAC,4DAA4D;YAC9D,CAAC,CAAC,qGAAqG,EACzG,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,EAAE,CACnF,CAAC;QACF,MAAM,CAAC,cAAc,CAAC,eAAe,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QACrG,MAAM,eAAe,CAAC;IACxB,CAAC;AACH,CAAC;AAED,SAAS,+BAA+B,CAAC,IAAY,EAAE,KAAyB;IAC9E,IAAI,KAAK,KAAK,WAAW,EAAE,CAAC;QAC1B,OAAO,IAAI,KAAK,eAAe;YAC7B,CAAC,CAAC,kGAAkG;YACpG,CAAC,CAAC,+EAA+E,CAAC;IACtF,CAAC;IACD,OAAO,4FAA4F,CAAC;AACtG,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAY,EAAE,IAAmC;IAC5E,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IAClC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAC7B,IAAI,CAAC,IAAA,2BAAgB,EAAC,GAAG,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,wBAAe,CACvB,GAAG,IAAI,IAAI,KAAK,8FAA8F,EAC9G,EAAE,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,CAChB,CAAC;QACJ,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,43 @@
1
+ /** A party ID, the Ed25519 public key that should control it, and optionally the key's fingerprint as the caller has it. */
2
+ export interface PartyKeyInput {
3
+ readonly partyId: string;
4
+ readonly publicKeyBase64: string;
5
+ readonly publicKeyFingerprint?: string | null;
6
+ }
7
+ /** Runs a canton-protocol call on caller input: its `INVALID_INPUT` refusal becomes a {@link ValidationError}. */
8
+ export declare function onCallerInput<T>(call: () => T): T;
9
+ /**
10
+ * The error to throw for `error`, raised by canton-protocol on caller input: its `INVALID_INPUT` refusal becomes a
11
+ * {@link ValidationError} carrying it as `cause`; anything else is returned as it is.
12
+ */
13
+ export declare function callerInputError(error: unknown): unknown;
14
+ /** Canton's encoding (DER X.509 SubjectPublicKeyInfo, base64) of a raw or DER Ed25519 public key. */
15
+ export declare function cantonPublicKeyBase64(publicKeyBase64: string): string;
16
+ /** The raw 32 bytes of a raw or DER Ed25519 public key. */
17
+ export declare function rawEd25519PublicKey(publicKeyBase64: string): Uint8Array;
18
+ /** The Canton fingerprint of a raw or DER Ed25519 public key. */
19
+ export declare function publicKeyFingerprintOf(publicKeyBase64: string): string;
20
+ /** The external party ID `hint::fingerprint`. */
21
+ export declare function externalPartyIdOf(partyHint: string, publicKeyFingerprint: string): string;
22
+ /**
23
+ * The party ID Canton allocates for `partyHint` on `publicKeyBase64` (`hint::fingerprint`), built from the request so a
24
+ * participant's answer can be compared with it. Canton uses the hint exactly as sent, so a hint with leading or
25
+ * trailing whitespace is refused rather than trimmed, as is any hint canton-protocol's `buildExternalPartyId` refuses.
26
+ */
27
+ export declare function requestedExternalPartyId(partyHint: string, publicKeyBase64: string): string;
28
+ /**
29
+ * Whether `partyId` has whitespace around it. A party ID is never trimmed: a space is a Daml-LF Party character, so `
30
+ * alice::…` would otherwise parse with ` alice` as its hint. Whitespace next to `::` is left to the ID's rules, as
31
+ * Canton reads it: a space before `::` is part of the hint (Canton allocates such a hint), and one after `::` is part
32
+ * of the namespace, which then is no key's fingerprint.
33
+ */
34
+ export declare function hasSurroundingWhitespace(partyId: string): boolean;
35
+ /**
36
+ * Checks that `partyId` is an external party of `publicKeyBase64` (its namespace is the key's fingerprint) and that a
37
+ * caller-supplied fingerprint, if any, is the key's; returns the key's fingerprint. An ID with whitespace around it is
38
+ * refused, never trimmed ({@link hasSurroundingWhitespace}).
39
+ */
40
+ export declare function assertPartyKey(input: PartyKeyInput): string;
41
+ /** A Canton hash (`1220` and 64 hex characters, either case) the caller passed as hex, in canonical lowercase form. */
42
+ export declare function cantonHashHexOf(value: string): string;
43
+ //# sourceMappingURL=party-identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"party-identity.d.ts","sourceRoot":"","sources":["../../../../src/utils/external-signing/party-identity.ts"],"names":[],"mappings":"AAkBA,4HAA4H;AAC5H,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/C;AAED,kHAAkH;AAClH,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAMjD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAOxD;AAED,qGAAqG;AACrG,wBAAgB,qBAAqB,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,2DAA2D;AAC3D,wBAAgB,mBAAmB,CAAC,eAAe,EAAE,MAAM,GAAG,UAAU,CAEvE;AAED,iEAAiE;AACjE,wBAAgB,sBAAsB,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,iDAAiD;AACjD,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,GAAG,MAAM,CAEzF;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,CAK3F;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEjE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,CA2B3D;AAED,uHAAuH;AACvH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMrD"}
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.onCallerInput = onCallerInput;
4
+ exports.callerInputError = callerInputError;
5
+ exports.cantonPublicKeyBase64 = cantonPublicKeyBase64;
6
+ exports.rawEd25519PublicKey = rawEd25519PublicKey;
7
+ exports.publicKeyFingerprintOf = publicKeyFingerprintOf;
8
+ exports.externalPartyIdOf = externalPartyIdOf;
9
+ exports.requestedExternalPartyId = requestedExternalPartyId;
10
+ exports.hasSurroundingWhitespace = hasSurroundingWhitespace;
11
+ exports.assertPartyKey = assertPartyKey;
12
+ exports.cantonHashHexOf = cantonHashHexOf;
13
+ /**
14
+ * Node-sdk's use of `@fairmint/canton-protocol/party` on caller input. Internal: not exported from the package.
15
+ *
16
+ * The key, fingerprint, party-ID and hash rules are canton-protocol's. These wrappers keep node-sdk's error contract
17
+ * for its own functions: input canton-protocol refuses (`INVALID_INPUT`) becomes a {@link ValidationError} carrying the
18
+ * refusal as `cause`, and a party/key mismatch keeps the SDK's messages.
19
+ */
20
+ const party_1 = require("@fairmint/canton-protocol/party");
21
+ const errors_1 = require("../../core/errors");
22
+ /** Runs a canton-protocol call on caller input: its `INVALID_INPUT` refusal becomes a {@link ValidationError}. */
23
+ function onCallerInput(call) {
24
+ try {
25
+ return call();
26
+ }
27
+ catch (error) {
28
+ throw callerInputError(error);
29
+ }
30
+ }
31
+ /**
32
+ * The error to throw for `error`, raised by canton-protocol on caller input: its `INVALID_INPUT` refusal becomes a
33
+ * {@link ValidationError} carrying it as `cause`; anything else is returned as it is.
34
+ */
35
+ function callerInputError(error) {
36
+ if ((0, party_1.isCantonProtocolError)(error, 'INVALID_INPUT')) {
37
+ const validation = new errors_1.ValidationError(error.message, error.field === undefined ? {} : { field: error.field });
38
+ Object.defineProperty(validation, 'cause', { value: error, enumerable: false, writable: true });
39
+ return validation;
40
+ }
41
+ return error;
42
+ }
43
+ /** Canton's encoding (DER X.509 SubjectPublicKeyInfo, base64) of a raw or DER Ed25519 public key. */
44
+ function cantonPublicKeyBase64(publicKeyBase64) {
45
+ return onCallerInput(() => (0, party_1.normalizeEd25519PublicKeyForCanton)(publicKeyBase64));
46
+ }
47
+ /** The raw 32 bytes of a raw or DER Ed25519 public key. */
48
+ function rawEd25519PublicKey(publicKeyBase64) {
49
+ return onCallerInput(() => (0, party_1.decodeEd25519PublicKey)(publicKeyBase64));
50
+ }
51
+ /** The Canton fingerprint of a raw or DER Ed25519 public key. */
52
+ function publicKeyFingerprintOf(publicKeyBase64) {
53
+ return onCallerInput(() => (0, party_1.fingerprintEd25519PublicKey)(publicKeyBase64));
54
+ }
55
+ /** The external party ID `hint::fingerprint`. */
56
+ function externalPartyIdOf(partyHint, publicKeyFingerprint) {
57
+ return onCallerInput(() => (0, party_1.buildExternalPartyId)(partyHint, publicKeyFingerprint));
58
+ }
59
+ /**
60
+ * The party ID Canton allocates for `partyHint` on `publicKeyBase64` (`hint::fingerprint`), built from the request so a
61
+ * participant's answer can be compared with it. Canton uses the hint exactly as sent, so a hint with leading or
62
+ * trailing whitespace is refused rather than trimmed, as is any hint canton-protocol's `buildExternalPartyId` refuses.
63
+ */
64
+ function requestedExternalPartyId(partyHint, publicKeyBase64) {
65
+ if (typeof partyHint === 'string' && partyHint !== partyHint.trim()) {
66
+ throw new errors_1.ValidationError('partyHint must not start or end with whitespace', { partyHint });
67
+ }
68
+ return externalPartyIdOf(partyHint, publicKeyFingerprintOf(publicKeyBase64));
69
+ }
70
+ /**
71
+ * Whether `partyId` has whitespace around it. A party ID is never trimmed: a space is a Daml-LF Party character, so `
72
+ * alice::…` would otherwise parse with ` alice` as its hint. Whitespace next to `::` is left to the ID's rules, as
73
+ * Canton reads it: a space before `::` is part of the hint (Canton allocates such a hint), and one after `::` is part
74
+ * of the namespace, which then is no key's fingerprint.
75
+ */
76
+ function hasSurroundingWhitespace(partyId) {
77
+ return partyId !== partyId.trim();
78
+ }
79
+ /**
80
+ * Checks that `partyId` is an external party of `publicKeyBase64` (its namespace is the key's fingerprint) and that a
81
+ * caller-supplied fingerprint, if any, is the key's; returns the key's fingerprint. An ID with whitespace around it is
82
+ * refused, never trimmed ({@link hasSurroundingWhitespace}).
83
+ */
84
+ function assertPartyKey(input) {
85
+ if (typeof input.partyId === 'string' && hasSurroundingWhitespace(input.partyId)) {
86
+ throw new errors_1.ValidationError('Canton party ID must not have whitespace around it', {
87
+ partyId: input.partyId,
88
+ });
89
+ }
90
+ const parsed = (0, party_1.parsePartyId)(input.partyId);
91
+ if (parsed === null) {
92
+ throw new errors_1.ValidationError('Expected a Canton party ID with one public key fingerprint suffix', {
93
+ partyId: input.partyId,
94
+ });
95
+ }
96
+ const keyFingerprint = publicKeyFingerprintOf(input.publicKeyBase64);
97
+ const suppliedFingerprint = input.publicKeyFingerprint?.trim();
98
+ if (suppliedFingerprint && suppliedFingerprint !== keyFingerprint) {
99
+ throw new errors_1.ValidationError('Submitted public key fingerprint does not match the public key', {
100
+ suppliedFingerprint,
101
+ keyFingerprint,
102
+ });
103
+ }
104
+ if (parsed.namespace !== keyFingerprint) {
105
+ throw new errors_1.ValidationError('Canton party ID does not match the submitted public key', {
106
+ partyFingerprint: parsed.namespace,
107
+ keyFingerprint,
108
+ });
109
+ }
110
+ return keyFingerprint;
111
+ }
112
+ /** A Canton hash (`1220` and 64 hex characters, either case) the caller passed as hex, in canonical lowercase form. */
113
+ function cantonHashHexOf(value) {
114
+ const normalized = value.trim().toLowerCase();
115
+ if (!(0, party_1.isCantonHash)(normalized)) {
116
+ throw new errors_1.ValidationError('Expected a Canton SHA-256 multihash hex string', { value });
117
+ }
118
+ return normalized;
119
+ }
120
+ //# sourceMappingURL=party-identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"party-identity.js","sourceRoot":"","sources":["../../../../src/utils/external-signing/party-identity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;GAMG;AACH,2DAQyC;AACzC,8CAAoD;AASpD,kHAAkH;AAClH,uBAAiC,IAAa;IAC5C,IAAI,CAAC;QACH,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,0BAAiC,KAAc;IAC7C,IAAI,IAAA,6BAAqB,EAAC,KAAK,EAAE,eAAe,CAAC,EAAE,CAAC;QAClD,MAAM,UAAU,GAAG,IAAI,wBAAe,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;QAC/G,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QAChG,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,qGAAqG;AACrG,+BAAsC,eAAuB;IAC3D,OAAO,aAAa,CAAC,GAAG,EAAE,CAAC,IAAA,0CAAkC,EAAC,eAAe,CAAC,CAAC,CAAC;AAClF,CAAC;AAED,2DAA2D;AAC3D,6BAAoC,eAAuB;IACzD,OAAO,aAAa,CAAC,GAAG,EAAE,CAAC,IAAA,8BAAsB,EAAC,eAAe,CAAC,CAAC,CAAC;AACtE,CAAC;AAED,iEAAiE;AACjE,gCAAuC,eAAuB;IAC5D,OAAO,aAAa,CAAC,GAAG,EAAE,CAAC,IAAA,mCAA2B,EAAC,eAAe,CAAC,CAAC,CAAC;AA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,IAAI,mBAAmB,KAAK,cAAc,EAAE,CAAC;QAClE,MAAM,IAAI,wBAAe,CAAC,gEAAgE,EAAE;YAC1F,mBAAmB;YACnB,cAAc;SACf,CAAC,CAAC;IACL,CAAC;IACD,IAAI,MAAM,CAAC,SAAS,KAAK,cAAc,EAAE,CAAC;QACxC,MAAM,IAAI,wBAAe,CAAC,yDAAyD,EAAE;YACnF,gBAAgB,EAAE,MAAM,CAAC,SAAS;YAClC,cAAc;SACf,CAAC,CAAC;IACL,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,uHAAuH;AACvH,yBAAgC,KAAa;IAC3C,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC9C,IAAI,CAAC,IAAA,oBAAY,EAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,wBAAe,CAAC,gDAAgD,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { type HashingScheme } from '@fairmint/canton-protocol/transaction';
2
+ /** What the prepared transaction must state. */
3
+ export interface PreparedTransactionExpectation {
4
+ /** The parties it must act as: the exact set. */
5
+ readonly actAs: readonly string[];
6
+ /** The command id requested. Omitted: the one the transaction states (when another party chose it). */
7
+ readonly commandId?: string | undefined;
8
+ /** The synchronizer requested. Omitted: the one the transaction states (when another party chose it). */
9
+ readonly synchronizerId?: string | undefined;
10
+ }
11
+ /** A participant's answer to a prepare request, with what node-sdk asked for. */
12
+ export interface ParticipantPreparedTransaction {
13
+ /** Names the request in error messages, e.g. `interactive submission prepare`. */
14
+ readonly operation: string;
15
+ readonly preparedTransaction: unknown;
16
+ /** The participant's hash of it: hex or base64, 32 bytes. */
17
+ readonly preparedTransactionHash: unknown;
18
+ /** The scheme node-sdk asked the transaction to be prepared under. */
19
+ readonly hashingScheme: HashingScheme;
20
+ /**
21
+ * The scheme the answer names. Omit only for an answer that names none (a validator's): an answer naming another
22
+ * scheme than the one requested is refused, so a participant cannot downgrade V3 to V2.
23
+ */
24
+ readonly answeredHashingScheme?: unknown;
25
+ readonly expected: PreparedTransactionExpectation;
26
+ }
27
+ /** A prepared transaction whose hash node-sdk recomputed. */
28
+ export interface VerifiedPreparedTransaction {
29
+ readonly preparedTransaction: string;
30
+ /** The recomputed hash, 64 lowercase hex characters: what the party signs. */
31
+ readonly preparedTransactionHashHex: string;
32
+ readonly hashingSchemeVersion: HashingScheme;
33
+ }
34
+ /** A signed prepared transaction a caller submits. */
35
+ export interface SubmittedPreparedTransaction {
36
+ readonly preparedTransaction: string;
37
+ /** The hash the party signed: 32 bytes, hex. */
38
+ readonly preparedTransactionHashHex: string;
39
+ /** The scheme it is executed under. */
40
+ readonly hashingScheme: HashingScheme;
41
+ readonly expected: PreparedTransactionExpectation;
42
+ }
43
+ /**
44
+ * Verifies a participant's prepared transaction and resolves its recomputed hash. A refusal of the participant's answer
45
+ * (another scheme, no transaction, a hash that is not the transaction's, a transaction that cannot be hashed or that
46
+ * does not state what was asked) is an {@link OperationError} (`TRANSACTION_FAILED`) with canton-protocol's refusal as
47
+ * `cause` and its `code` and `field` in the context; an invalid expectation (caller input) is a {@link ValidationError}.
48
+ * Nothing may be signed when it rejects.
49
+ */
50
+ export declare function verifyParticipantPreparedTransaction(input: ParticipantPreparedTransaction): Promise<VerifiedPreparedTransaction>;
51
+ /**
52
+ * Checks, before a signed prepared transaction is submitted, that the signed hash is the hash of the transaction bytes
53
+ * under the scheme it is executed with, and that the transaction states what is expected. Every refusal is a
54
+ * {@link ValidationError} (caller input) with canton-protocol's refusal as `cause` where it made it; nothing may be
55
+ * submitted when it rejects.
56
+ */
57
+ export declare function assertSubmittedPreparedTransaction(input: SubmittedPreparedTransaction): Promise<void>;
58
+ //# sourceMappingURL=prepared-transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepared-transaction.d.ts","sourceRoot":"","sources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