@fairmint/canton-node-sdk 0.0.295 → 0.0.297
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.
- package/README.md +86 -0
- package/build/src/external-parties/directory.d.ts +96 -0
- package/build/src/external-parties/directory.d.ts.map +1 -0
- package/build/src/external-parties/directory.js +238 -0
- package/build/src/external-parties/directory.js.map +1 -0
- package/build/src/external-parties/discovery.d.ts +72 -0
- package/build/src/external-parties/discovery.d.ts.map +1 -0
- package/build/src/external-parties/discovery.js +160 -0
- package/build/src/external-parties/discovery.js.map +1 -0
- package/build/src/external-parties/errors.d.ts +28 -0
- package/build/src/external-parties/errors.d.ts.map +1 -0
- package/build/src/external-parties/errors.js +33 -0
- package/build/src/external-parties/errors.js.map +1 -0
- package/build/src/external-parties/hints.d.ts +42 -0
- package/build/src/external-parties/hints.d.ts.map +1 -0
- package/build/src/external-parties/hints.js +83 -0
- package/build/src/external-parties/hints.js.map +1 -0
- package/build/src/external-parties/index.d.ts +20 -0
- package/build/src/external-parties/index.d.ts.map +1 -0
- package/build/src/external-parties/index.js +43 -0
- package/build/src/external-parties/index.js.map +1 -0
- package/build/src/external-parties/keys.d.ts +34 -0
- package/build/src/external-parties/keys.d.ts.map +1 -0
- package/build/src/external-parties/keys.js +209 -0
- package/build/src/external-parties/keys.js.map +1 -0
- package/build/src/index.d.ts +1 -0
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +2 -1
- package/build/src/index.js.map +1 -1
- package/build/src/utils/external-signing/canton-protocol.d.ts.map +1 -1
- package/build/src/utils/external-signing/canton-protocol.js +11 -14
- package/build/src/utils/external-signing/canton-protocol.js.map +1 -1
- package/build/src/utils/external-signing/index.d.ts +1 -0
- package/build/src/utils/external-signing/index.d.ts.map +1 -1
- package/build/src/utils/external-signing/index.js +1 -0
- package/build/src/utils/external-signing/index.js.map +1 -1
- package/build/src/utils/external-signing/wallet-ownership-challenger.d.ts +51 -10
- package/build/src/utils/external-signing/wallet-ownership-challenger.d.ts.map +1 -1
- package/build/src/utils/external-signing/wallet-ownership-challenger.js +85 -18
- package/build/src/utils/external-signing/wallet-ownership-challenger.js.map +1 -1
- package/build/src/utils/external-signing/wallet-ownership-checks.d.ts +27 -0
- package/build/src/utils/external-signing/wallet-ownership-checks.d.ts.map +1 -0
- package/build/src/utils/external-signing/wallet-ownership-checks.js +117 -0
- package/build/src/utils/external-signing/wallet-ownership-checks.js.map +1 -0
- package/build/src/utils/external-signing/wallet-ownership.d.ts.map +1 -1
- package/build/src/utils/external-signing/wallet-ownership.js +21 -95
- package/build/src/utils/external-signing/wallet-ownership.js.map +1 -1
- package/build/src/utils/external-signing/wallet-proof.d.ts +44 -0
- package/build/src/utils/external-signing/wallet-proof.d.ts.map +1 -0
- package/build/src/utils/external-signing/wallet-proof.js +74 -0
- package/build/src/utils/external-signing/wallet-proof.js.map +1 -0
- package/build/src/wallets/index.d.ts +5 -2
- package/build/src/wallets/index.d.ts.map +1 -1
- package/build/src/wallets/index.js +12 -3
- package/build/src/wallets/index.js.map +1 -1
- package/build/src/wallets/ownership-fields.d.ts +4 -0
- package/build/src/wallets/ownership-fields.d.ts.map +1 -0
- package/build/src/wallets/ownership-fields.js +11 -0
- package/build/src/wallets/ownership-fields.js.map +1 -0
- package/build/src/wallets/ownership.d.ts +44 -7
- package/build/src/wallets/ownership.d.ts.map +1 -1
- package/build/src/wallets/ownership.js +137 -47
- package/build/src/wallets/ownership.js.map +1 -1
- package/build/src/wallets/proof-encoding.d.ts +17 -0
- package/build/src/wallets/proof-encoding.d.ts.map +1 -0
- package/build/src/wallets/proof-encoding.js +63 -0
- package/build/src/wallets/proof-encoding.js.map +1 -0
- package/build/src/wallets/store.d.ts +12 -4
- package/build/src/wallets/store.d.ts.map +1 -1
- package/build/src/wallets/store.js +8 -1
- package/build/src/wallets/store.js.map +1 -1
- package/build/src/wallets/wallet-proof.d.ts +50 -0
- package/build/src/wallets/wallet-proof.d.ts.map +1 -0
- package/build/src/wallets/wallet-proof.js +141 -0
- package/build/src/wallets/wallet-proof.js.map +1 -0
- package/package.json +10 -1
package/README.md
CHANGED
|
@@ -69,6 +69,49 @@ same way; it requires an explicit `userId` and a non-empty `parties` list, as th
|
|
|
69
69
|
See
|
|
70
70
|
[`examples/read-any-party.ts`](https://github.com/Fairmint/canton-node-sdk/blob/main/examples/read-any-party.ts).
|
|
71
71
|
|
|
72
|
+
## Finding every party a key controls
|
|
73
|
+
|
|
74
|
+
An external party's ID is `hint::fingerprint`, where the fingerprint is Canton's SHA-256 multihash
|
|
75
|
+
of the Ed25519 key: `1220` + hex(sha256(int32be(12) || rawKey)). Nothing about it depends on the
|
|
76
|
+
signer, so one module serves any wallet. It is browser-safe: import
|
|
77
|
+
`@fairmint/canton-node-sdk/external-parties` (it loads `@noble/hashes` and none of the SDK's Node
|
|
78
|
+
dependencies); the package root also exports it as the `ExternalParties` namespace.
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import {
|
|
82
|
+
createExternalPartyDirectory,
|
|
83
|
+
suggestExternalPartyHint,
|
|
84
|
+
validateExternalPartyHint,
|
|
85
|
+
} from '@fairmint/canton-node-sdk/external-parties';
|
|
86
|
+
|
|
87
|
+
// One directory per participant: one scan of its party store answers every key for 30 s.
|
|
88
|
+
const directory = createExternalPartyDirectory({ ledgerClient }); // a LedgerJsonApiClient
|
|
89
|
+
const { parties, complete } = await directory.listPartiesForKey({
|
|
90
|
+
publicKeyBase64, // raw or DER Ed25519 key; or pass publicKeyFingerprint
|
|
91
|
+
hints: ['wallet'], // looked up exactly when the scan does not show them
|
|
92
|
+
signal,
|
|
93
|
+
});
|
|
94
|
+
// parties: [{ partyId, partyHint, hostedHere }], sorted by hint
|
|
95
|
+
const hint = suggestExternalPartyHint({ base: 'My app', taken: parties.map((p) => p.partyHint) });
|
|
96
|
+
validateExternalPartyHint(hint); // null, or 'empty' | 'too-long' | 'charset' | 'taken'
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The participant API has no namespace filter, so a scan reads `GET /v2/parties` page by page and
|
|
100
|
+
keeps the parties ending in `::fingerprint`. Each scan is bounded (`pageSize` 1000, `maxPages` 10,
|
|
101
|
+
`timeoutMs` 10 s, a stalled page included) and cached for every key (`cacheMs` 30 s; concurrent
|
|
102
|
+
callers share one scan). When a bound stops it first the answer is `complete: false`, and the hints
|
|
103
|
+
asked for are still looked up with `GET /v2/parties/{party}` (also when the scan is complete, since
|
|
104
|
+
a cached scan can predate a newer party). `noteAllocated(partyId)` lists a party you just allocated
|
|
105
|
+
at once; `findParty({ partyId })` is the exact lookup on its own. `discoverExternalParties` is the
|
|
106
|
+
same list-plus-lookups logic over your own `listParties` / `findParty` callbacks. Errors are
|
|
107
|
+
`ExternalPartyError` with a `code` (`INVALID_INPUT`, `INVALID_RESPONSE`, `ABORTED`, `LIST_FAILED`,
|
|
108
|
+
`LOOKUP_FAILED`); a ledger failure is its `cause`.
|
|
109
|
+
|
|
110
|
+
The same module has the identity helpers: `deriveCantonEd25519PublicKeyFingerprint`,
|
|
111
|
+
`buildExternalPartyId`, `parseExternalPartyId`, `readPartyNamespace`,
|
|
112
|
+
`normalizeEd25519PublicKeyForCanton` and `decodeEd25519PublicKey`. The Node helpers of the same
|
|
113
|
+
names under the package root (which throw `ValidationError`) derive the fingerprint through it.
|
|
114
|
+
|
|
72
115
|
## Token actions through a CIP-0103 wallet
|
|
73
116
|
|
|
74
117
|
`Wallets` runs Digital Asset Utility Registry holder actions through any CIP-0103 (Canton dApp API)
|
|
@@ -477,6 +520,49 @@ export async function POST(request: Request): Promise<Response> {
|
|
|
477
520
|
}
|
|
478
521
|
```
|
|
479
522
|
|
|
523
|
+
### The wallet proof format (`wallet-proof-v1`)
|
|
524
|
+
|
|
525
|
+
A second message format, the same shape as apiv2's CNTN tokenization wallet proof, so a page signs
|
|
526
|
+
one format whichever Fairmint server checks it: one line of JSON with the keys in this order.
|
|
527
|
+
|
|
528
|
+
```json
|
|
529
|
+
{
|
|
530
|
+
"domain": "fairmint:tokenization-wallet-proof:v1",
|
|
531
|
+
"network": "devnet",
|
|
532
|
+
"partyId": "hint::1220…",
|
|
533
|
+
"investorContext": "user-1",
|
|
534
|
+
"idempotencyKey": "<nonce>",
|
|
535
|
+
"issuedAt": "2026-11-24T10:00:00.000Z",
|
|
536
|
+
"expiresAt": "2026-11-24T10:05:00.000Z"
|
|
537
|
+
}
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
- `buildWalletProofMessage(fields)` and `parseWalletProofMessage(text)` (browser-safe, from
|
|
541
|
+
`@fairmint/canton-node-sdk/wallets`) write and read it. Parsing is strict: the exact key set and
|
|
542
|
+
order, string values, ISO-8601 times with an offset, `expiresAt` after `issuedAt`, and the text
|
|
543
|
+
must be byte for byte what `JSON.stringify` writes for those fields.
|
|
544
|
+
- `verifyWalletProof({ proof, expected: { domain, network, partyId, investorContext?, idempotencyKey? }, now?, maxLifetimeMs?, maxSkewMs? })`
|
|
545
|
+
(Node only, package root) checks the fields against the server's values, `issuedAt <= now + 60 s`,
|
|
546
|
+
`expiresAt > now`, a lifetime of at most 10 minutes, the key's fingerprint against the party's
|
|
547
|
+
namespace, and the Ed25519 signature over the exact bytes. It answers like
|
|
548
|
+
`verifyWalletOwnership`: `{ verified: true, ...fields, publicKeyFingerprint }` or
|
|
549
|
+
`{ verified: false, reason, message }`.
|
|
550
|
+
- The challenger issues it on request: `issue({ ..., format: 'wallet-proof-v1', proofDomain })` or
|
|
551
|
+
`handleChallenge(request, { subject, format: 'wallet-proof-v1', proofDomain })` (`proofDomain`
|
|
552
|
+
defaults to `purpose`). The challenge answer is
|
|
553
|
+
`{ format: 'wallet-proof-v1', message, fields, token }`: `idempotencyKey` is the challenge's nonce
|
|
554
|
+
(its reference) and `investorContext` the subject. The token says which format a challenge used,
|
|
555
|
+
so `handleVerify` and `verify` need no option. The text format stays the default.
|
|
556
|
+
- In the browser, `requestWalletOwnershipVerdict` (and the store's `proveOwnership`) accepts either
|
|
557
|
+
answer. For `wallet-proof-v1` it calls `proveWalletProof(connection, { message, fields })`, which
|
|
558
|
+
refuses a message that does not parse, names another party or network, differs from `fields`, or
|
|
559
|
+
has expired, and then signs exactly `message`. The signed
|
|
560
|
+
`{ partyId, publicKey, message, signature }` reaches a page through `onProof`, or as `proof` on
|
|
561
|
+
the store's `proveOwnership` result. `proveWalletProof` returns `publicKey` and `signature` as
|
|
562
|
+
standard base64 whatever the wallet gave (Loop's hex, or base64), a raw 32-byte key or a DER key
|
|
563
|
+
alike, so the proof a page shows for copying verifies with a server that decodes base64 only
|
|
564
|
+
(apiv2's CNTN verifier); `verifyWalletProof` still accepts hex or base64.
|
|
565
|
+
|
|
480
566
|
### Proving wallet ownership
|
|
481
567
|
|
|
482
568
|
A connected wallet only tells the dApp a party id, which anyone can claim. To know the user controls
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every party a key controls on one participant, over the Ledger JSON API: a bounded, cached read of `GET /v2/parties`
|
|
3
|
+
* filtered to the key's namespace, plus exact `GET /v2/parties/{party}` lookups of the hints the read may not show.
|
|
4
|
+
* Browser-safe: it takes the ledger client by its shape (node-sdk's `LedgerJsonApiClient` fits), and loads nothing
|
|
5
|
+
* else.
|
|
6
|
+
*/
|
|
7
|
+
import { type ExternalPartyListing } from './discovery';
|
|
8
|
+
/** The request options the directory passes to the ledger client. */
|
|
9
|
+
export interface ExternalPartyDirectoryRequestConfig {
|
|
10
|
+
readonly contentType?: 'application/json';
|
|
11
|
+
readonly includeBearerToken?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The part of node-sdk's `LedgerJsonApiClient` the directory uses: its base URL and its authenticated JSON GET, which
|
|
15
|
+
* throws an error carrying the participant's HTTP `status` (node-sdk's `ApiError`) on a failure.
|
|
16
|
+
*/
|
|
17
|
+
export interface ExternalPartyDirectoryLedgerClient {
|
|
18
|
+
getApiUrl(): string;
|
|
19
|
+
makeGetRequest<T>(url: string, config?: ExternalPartyDirectoryRequestConfig,
|
|
20
|
+
/** `signal` aborts the request (an older client may ignore it). */
|
|
21
|
+
options?: {
|
|
22
|
+
readonly signal?: AbortSignal;
|
|
23
|
+
}): Promise<T>;
|
|
24
|
+
}
|
|
25
|
+
export interface ExternalPartyDirectoryOptions {
|
|
26
|
+
readonly ledgerClient: ExternalPartyDirectoryLedgerClient;
|
|
27
|
+
/** The identity provider parties are read under. Defaults to "" (the participant's default). */
|
|
28
|
+
readonly identityProviderId?: string;
|
|
29
|
+
/** Parties per `GET /v2/parties` page. Defaults to 1000; 1 to 10000. */
|
|
30
|
+
readonly pageSize?: number;
|
|
31
|
+
/** Pages one scan reads at most. Defaults to 10; 1 to 1000. */
|
|
32
|
+
readonly maxPages?: number;
|
|
33
|
+
/** How long one scan may take, in milliseconds, a stalled page included. Defaults to 10 seconds; 100 to 120000. */
|
|
34
|
+
readonly timeoutMs?: number;
|
|
35
|
+
/** How long one scan answers for every key, in milliseconds. Defaults to 30 seconds; 0 (no cache) to 600000. */
|
|
36
|
+
readonly cacheMs?: number;
|
|
37
|
+
/** The clock, for tests. Defaults to `Date.now`. */
|
|
38
|
+
readonly now?: () => number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The key whose parties are asked for: its public key (raw or DER, base64), or its Canton fingerprint. With both, they
|
|
42
|
+
* must match.
|
|
43
|
+
*/
|
|
44
|
+
export type ExternalPartyKey = {
|
|
45
|
+
readonly publicKeyBase64: string;
|
|
46
|
+
readonly publicKeyFingerprint?: string;
|
|
47
|
+
} | {
|
|
48
|
+
readonly publicKeyFingerprint: string;
|
|
49
|
+
readonly publicKeyBase64?: undefined;
|
|
50
|
+
};
|
|
51
|
+
/** What {@link ExternalPartyDirectory.findParty} answers. */
|
|
52
|
+
export type ExternalPartyFound = {
|
|
53
|
+
readonly exists: false;
|
|
54
|
+
} | {
|
|
55
|
+
readonly exists: true;
|
|
56
|
+
readonly hostedHere: boolean;
|
|
57
|
+
};
|
|
58
|
+
export interface ExternalPartyDirectory {
|
|
59
|
+
/**
|
|
60
|
+
* Every party of the key: the scan's parties in the key's namespace and the parties {@link noteAllocated} recorded,
|
|
61
|
+
* plus an exact {@link findParty} of each of `hints` (at most 16) they do not show, sorted by hint. `complete` is the
|
|
62
|
+
* scan's: false when a page or time bound stopped it first. With a complete scan a failed lookup is skipped; with an
|
|
63
|
+
* incomplete one it fails the call. `signal` stops this caller's wait, not the shared scan.
|
|
64
|
+
*
|
|
65
|
+
* Throws {@link ExternalPartyError}: `INVALID_INPUT`, `ABORTED`, `INVALID_RESPONSE`, `LIST_FAILED` (the scan's request
|
|
66
|
+
* failed: the ledger client's error is `cause`) or `LOOKUP_FAILED`.
|
|
67
|
+
*/
|
|
68
|
+
listPartiesForKey(request: ExternalPartyKey & {
|
|
69
|
+
readonly hints?: readonly string[];
|
|
70
|
+
readonly signal?: AbortSignal;
|
|
71
|
+
}): Promise<ExternalPartyListing>;
|
|
72
|
+
/**
|
|
73
|
+
* One party by ID (`GET /v2/parties/{party}`): 404 or an answer that does not list it is not found; else it exists,
|
|
74
|
+
* and `hostedHere` is its `isLocal`. The ledger client's errors pass through; an unreadable answer is
|
|
75
|
+
* `INVALID_RESPONSE`.
|
|
76
|
+
*/
|
|
77
|
+
findParty(request: {
|
|
78
|
+
readonly partyId: string;
|
|
79
|
+
readonly signal?: AbortSignal;
|
|
80
|
+
}): Promise<ExternalPartyFound>;
|
|
81
|
+
/**
|
|
82
|
+
* Records a party allocated (or confirmed to exist) on this participant, so {@link listPartiesForKey} lists it as
|
|
83
|
+
* hosted here at once, even from a scan read before it. Kept for one cache window plus one scan timeout.
|
|
84
|
+
*/
|
|
85
|
+
noteAllocated(partyId: string): void;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A directory of the external parties on one participant. The participant API has no namespace filter, so a scan reads
|
|
89
|
+
* the participant's whole party store: one scan serves every key and caller for `cacheMs` (concurrent calls share one
|
|
90
|
+
* scan), and parties recorded with `noteAllocated` are added to it at once. Each scan is bounded: at most `maxPages`
|
|
91
|
+
* pages of `pageSize` and `timeoutMs` overall, a stalled page included (its request is aborted at the deadline); when a
|
|
92
|
+
* bound stops it first, the listing is `complete: false` with what was read. At the defaults one scan is at most 10
|
|
93
|
+
* requests of 1000 parties.
|
|
94
|
+
*/
|
|
95
|
+
export declare function createExternalPartyDirectory(options: ExternalPartyDirectoryOptions): ExternalPartyDirectory;
|
|
96
|
+
//# sourceMappingURL=directory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory.d.ts","sourceRoot":"","sources":["../../../src/external-parties/directory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAML,KAAK,oBAAoB,EAC1B,MAAM,aAAa,CAAC;AAIrB,qEAAqE;AACrE,MAAM,WAAW,mCAAmC;IAClD,QAAQ,CAAC,WAAW,CAAC,EAAE,kBAAkB,CAAC;IAC1C,QAAQ,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC;CACvC;AAED;;;GAGG;AACH,MAAM,WAAW,kCAAkC;IACjD,SAAS,IAAI,MAAM,CAAC;IACpB,cAAc,CAAC,CAAC,EACd,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,mCAAmC;IAC5C,mEAAmE;IACnE,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAC1C,OAAO,CAAC,CAAC,CAAC,CAAC;CACf;AAED,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,YAAY,EAAE,kCAAkC,CAAC;IAC1D,gGAAgG;IAChG,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IACrC,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,+DAA+D;IAC/D,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,mHAAmH;IACnH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,C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|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createExternalPartyDirectory = createExternalPartyDirectory;
|
|
4
|
+
/**
|
|
5
|
+
* Every party a key controls on one participant, over the Ledger JSON API: a bounded, cached read of `GET /v2/parties`
|
|
6
|
+
* filtered to the key's namespace, plus exact `GET /v2/parties/{party}` lookups of the hints the read may not show.
|
|
7
|
+
* Browser-safe: it takes the ledger client by its shape (node-sdk's `LedgerJsonApiClient` fits), and loads nothing
|
|
8
|
+
* else.
|
|
9
|
+
*/
|
|
10
|
+
const discovery_1 = require("./discovery");
|
|
11
|
+
const errors_1 = require("./errors");
|
|
12
|
+
const keys_1 = require("./keys");
|
|
13
|
+
const CONFIG = Object.freeze({
|
|
14
|
+
contentType: 'application/json',
|
|
15
|
+
includeBearerToken: true,
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* A directory of the external parties on one participant. The participant API has no namespace filter, so a scan reads
|
|
19
|
+
* the participant's whole party store: one scan serves every key and caller for `cacheMs` (concurrent calls share one
|
|
20
|
+
* scan), and parties recorded with `noteAllocated` are added to it at once. Each scan is bounded: at most `maxPages`
|
|
21
|
+
* pages of `pageSize` and `timeoutMs` overall, a stalled page included (its request is aborted at the deadline); when a
|
|
22
|
+
* bound stops it first, the listing is `complete: false` with what was read. At the defaults one scan is at most 10
|
|
23
|
+
* requests of 1000 parties.
|
|
24
|
+
*/
|
|
25
|
+
function createExternalPartyDirectory(options) {
|
|
26
|
+
const { ledgerClient } = options;
|
|
27
|
+
// Checked as untyped input: a JavaScript caller may pass anything.
|
|
28
|
+
const shape = ledgerClient;
|
|
29
|
+
if (!isRecord(shape) || typeof shape['getApiUrl'] !== 'function' || typeof shape['makeGetRequest'] !== 'function') {
|
|
30
|
+
throw (0, errors_1.invalidInput)("ledgerClient must be @fairmint/canton-node-sdk's LedgerJsonApiClient.");
|
|
31
|
+
}
|
|
32
|
+
const identityProviderId = options.identityProviderId ?? '';
|
|
33
|
+
if (typeof identityProviderId !== 'string')
|
|
34
|
+
throw (0, errors_1.invalidInput)('identityProviderId must be a string.');
|
|
35
|
+
const pageSize = bounded(options.pageSize, 1000, 1, 10000, 'pageSize');
|
|
36
|
+
const maxPages = bounded(options.maxPages, 10, 1, 1000, 'maxPages');
|
|
37
|
+
const timeoutMs = bounded(options.timeoutMs, 10000, 100, 120000, 'timeoutMs');
|
|
38
|
+
const cacheMs = bounded(options.cacheMs, 30000, 0, 600000, 'cacheMs');
|
|
39
|
+
const now = options.now ?? Date.now;
|
|
40
|
+
const url = (path) => `${ledgerClient.getApiUrl()}${path}`;
|
|
41
|
+
const invalidResponse = (message, partyId) => new errors_1.ExternalPartyError('INVALID_RESPONSE', message, partyId === undefined ? {} : { partyId });
|
|
42
|
+
let cachedScan;
|
|
43
|
+
let scanInFlight;
|
|
44
|
+
/** Parties recorded here, by ID, with when: a scan that started earlier may not hold them. */
|
|
45
|
+
const allocatedHere = new Map();
|
|
46
|
+
/** Entries older than any scan that could still answer: a scan read after them holds those parties. */
|
|
47
|
+
const allocationHorizon = () => now() - cacheMs - timeoutMs;
|
|
48
|
+
async function scanParties() {
|
|
49
|
+
const startedAt = now();
|
|
50
|
+
const deadline = startedAt + timeoutMs;
|
|
51
|
+
const byNamespace = new Map();
|
|
52
|
+
const controller = new AbortController();
|
|
53
|
+
let expire = () => undefined;
|
|
54
|
+
const expired = new Promise((resolve) => {
|
|
55
|
+
expire = () => resolve('expired');
|
|
56
|
+
});
|
|
57
|
+
const timer = setTimeout(() => {
|
|
58
|
+
expire();
|
|
59
|
+
controller.abort();
|
|
60
|
+
}, timeoutMs);
|
|
61
|
+
const finish = (complete) => ({ startedAt, byNamespace, complete });
|
|
62
|
+
try {
|
|
63
|
+
let pageToken = '';
|
|
64
|
+
for (let page = 0; page < maxPages; page += 1) {
|
|
65
|
+
if (page > 0 && now() >= deadline)
|
|
66
|
+
break;
|
|
67
|
+
const query = new URLSearchParams({ pageSize: String(pageSize) });
|
|
68
|
+
if (pageToken !== '')
|
|
69
|
+
query.set('pageToken', pageToken);
|
|
70
|
+
if (identityProviderId.length > 0)
|
|
71
|
+
query.set('identity-provider-id', identityProviderId);
|
|
72
|
+
const request = ledgerClient.makeGetRequest(url(`/v2/parties?${query.toString()}`), CONFIG, {
|
|
73
|
+
signal: controller.signal,
|
|
74
|
+
});
|
|
75
|
+
// Read below when it wins; once the deadline wins, its (abort) failure is not ours to report.
|
|
76
|
+
request.catch(() => undefined);
|
|
77
|
+
const response = await Promise.race([request, expired]);
|
|
78
|
+
if (response === 'expired')
|
|
79
|
+
break;
|
|
80
|
+
const record = isRecord(response) ? response : undefined;
|
|
81
|
+
const details = Array.isArray(record?.['partyDetails']) ? record['partyDetails'] : null;
|
|
82
|
+
const next = record?.['nextPageToken'];
|
|
83
|
+
if (details === null || (next !== undefined && typeof next !== 'string')) {
|
|
84
|
+
throw invalidResponse('The participant returned an invalid party list.');
|
|
85
|
+
}
|
|
86
|
+
for (const detail of details) {
|
|
87
|
+
if (!isRecord(detail))
|
|
88
|
+
continue;
|
|
89
|
+
const { party } = detail;
|
|
90
|
+
// `hint::namespace` only: one separator, a non-empty hint and namespace.
|
|
91
|
+
// And one a listing may answer (at most 255 characters, trimmed, one line), so one odd party in the store
|
|
92
|
+
// never fails every key's listing.
|
|
93
|
+
const parsed = (0, keys_1.parseExternalPartyId)(party);
|
|
94
|
+
if (parsed === null || !(0, discovery_1.isBoundedIdentifier)(party))
|
|
95
|
+
continue;
|
|
96
|
+
let parties = byNamespace.get(parsed.namespace);
|
|
97
|
+
if (parties === undefined) {
|
|
98
|
+
parties = new Map();
|
|
99
|
+
byNamespace.set(parsed.namespace, parties);
|
|
100
|
+
}
|
|
101
|
+
parties.set(party, (parties.get(party) ?? false) || detail['isLocal'] === true);
|
|
102
|
+
}
|
|
103
|
+
if (next === undefined || next === '')
|
|
104
|
+
return finish(true);
|
|
105
|
+
if (next === pageToken)
|
|
106
|
+
break;
|
|
107
|
+
pageToken = next;
|
|
108
|
+
}
|
|
109
|
+
return finish(false);
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
clearTimeout(timer);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** The cached scan while it is fresh, else the scan in flight, else a new one. */
|
|
116
|
+
async function currentScan() {
|
|
117
|
+
if (cachedScan !== undefined && now() - cachedScan.startedAt < cacheMs)
|
|
118
|
+
return Promise.resolve(cachedScan);
|
|
119
|
+
if (scanInFlight === undefined) {
|
|
120
|
+
const scan = scanParties().then((result) => {
|
|
121
|
+
if (cacheMs > 0)
|
|
122
|
+
cachedScan = result;
|
|
123
|
+
return result;
|
|
124
|
+
});
|
|
125
|
+
scanInFlight = scan;
|
|
126
|
+
const clear = () => {
|
|
127
|
+
if (scanInFlight === scan)
|
|
128
|
+
scanInFlight = undefined;
|
|
129
|
+
};
|
|
130
|
+
scan.then(clear, clear);
|
|
131
|
+
}
|
|
132
|
+
return scanInFlight;
|
|
133
|
+
}
|
|
134
|
+
/** The key's parties from the current scan and the recorded allocations, without lookups. */
|
|
135
|
+
async function scannedParties(publicKeyFingerprint, signal) {
|
|
136
|
+
const scan = await (0, discovery_1.raceAbort)(currentScan, signal, 'The party listing was aborted.');
|
|
137
|
+
const parties = new Map(scan.byNamespace.get(publicKeyFingerprint) ?? []);
|
|
138
|
+
const suffix = `::${publicKeyFingerprint}`;
|
|
139
|
+
const horizon = allocationHorizon();
|
|
140
|
+
for (const [partyId, at] of allocatedHere) {
|
|
141
|
+
if (at < horizon) {
|
|
142
|
+
allocatedHere.delete(partyId);
|
|
143
|
+
}
|
|
144
|
+
else if (partyId.endsWith(suffix)) {
|
|
145
|
+
// Allocated here, so hosted here, whether or not this scan (or its pages) reached it yet.
|
|
146
|
+
parties.set(partyId, true);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return { parties: (0, discovery_1.sortedEntries)(parties), complete: scan.complete };
|
|
150
|
+
}
|
|
151
|
+
const directory = {
|
|
152
|
+
async listPartiesForKey(request) {
|
|
153
|
+
const publicKeyFingerprint = keyFingerprint(request);
|
|
154
|
+
const { signal } = request;
|
|
155
|
+
return (0, discovery_1.discoverExternalParties)({
|
|
156
|
+
publicKeyFingerprint,
|
|
157
|
+
...(request.hints === undefined ? {} : { hints: request.hints }),
|
|
158
|
+
...(signal === undefined ? {} : { signal }),
|
|
159
|
+
listParties: async () => scannedParties(publicKeyFingerprint, signal),
|
|
160
|
+
findParty: async ({ partyId }) => directory.findParty(signal === undefined ? { partyId } : { partyId, signal }),
|
|
161
|
+
}).then(({ parties, complete }) => Object.freeze({ parties, complete }));
|
|
162
|
+
},
|
|
163
|
+
async findParty(request) {
|
|
164
|
+
const { partyId, signal } = request;
|
|
165
|
+
if (typeof partyId !== 'string' || partyId.trim() === '')
|
|
166
|
+
throw (0, errors_1.invalidInput)('partyId is required.');
|
|
167
|
+
let response;
|
|
168
|
+
try {
|
|
169
|
+
// Same identity provider as the scan, as node-sdk's GetPartyDetails sends it.
|
|
170
|
+
const query = identityProviderId.length > 0
|
|
171
|
+
? `?${new URLSearchParams({ 'identity-provider-id': identityProviderId }).toString()}`
|
|
172
|
+
: '';
|
|
173
|
+
response = await ledgerClient.makeGetRequest(url(`/v2/parties/${encodeURIComponent(partyId)}${query}`), CONFIG, ...(signal === undefined ? [] : [{ signal }]));
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
if (readStatus(error) === 404)
|
|
177
|
+
return { exists: false };
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
const record = isRecord(response) ? response : undefined;
|
|
181
|
+
const details = Array.isArray(record?.['partyDetails']) ? record['partyDetails'] : null;
|
|
182
|
+
if (details === null)
|
|
183
|
+
throw invalidResponse('The participant returned invalid party details.', partyId);
|
|
184
|
+
const entry = details.find((detail) => isRecord(detail) && detail['party'] === partyId);
|
|
185
|
+
if (!isRecord(entry))
|
|
186
|
+
return { exists: false };
|
|
187
|
+
return { exists: true, hostedHere: entry['isLocal'] === true };
|
|
188
|
+
},
|
|
189
|
+
noteAllocated(partyId) {
|
|
190
|
+
// Only an ID a listing may answer: one it refuses would fail every listing of its key until it expired.
|
|
191
|
+
if ((0, keys_1.parseExternalPartyId)(partyId) === null || !(0, discovery_1.isBoundedIdentifier)(partyId)) {
|
|
192
|
+
throw (0, errors_1.invalidInput)('partyId must be a hint::namespace party ID of at most 255 characters, trimmed, on one line.');
|
|
193
|
+
}
|
|
194
|
+
// Drops expired entries as it records one, so the map holds one cache window, not the process lifetime.
|
|
195
|
+
const horizon = allocationHorizon();
|
|
196
|
+
for (const [id, at] of allocatedHere) {
|
|
197
|
+
if (at < horizon)
|
|
198
|
+
allocatedHere.delete(id);
|
|
199
|
+
}
|
|
200
|
+
allocatedHere.set(partyId, now());
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
return Object.freeze(directory);
|
|
204
|
+
}
|
|
205
|
+
function keyFingerprint(key) {
|
|
206
|
+
if (typeof key.publicKeyBase64 === 'string') {
|
|
207
|
+
const fingerprint = (0, keys_1.deriveCantonEd25519PublicKeyFingerprint)(key.publicKeyBase64);
|
|
208
|
+
if (key.publicKeyFingerprint !== undefined && key.publicKeyFingerprint !== fingerprint) {
|
|
209
|
+
throw (0, errors_1.invalidInput)('publicKeyFingerprint does not match publicKeyBase64.');
|
|
210
|
+
}
|
|
211
|
+
return fingerprint;
|
|
212
|
+
}
|
|
213
|
+
if ((0, keys_1.isCantonPublicKeyFingerprint)(key.publicKeyFingerprint))
|
|
214
|
+
return key.publicKeyFingerprint;
|
|
215
|
+
throw (0, errors_1.invalidInput)('Pass publicKeyBase64 or a Canton publicKeyFingerprint.');
|
|
216
|
+
}
|
|
217
|
+
function bounded(value, fallback, min, max, label) {
|
|
218
|
+
const resolved = value ?? fallback;
|
|
219
|
+
if (!Number.isSafeInteger(resolved) || resolved < min || resolved > max) {
|
|
220
|
+
throw (0, errors_1.invalidInput)(`${label} must be an integer from ${min} to ${max}.`);
|
|
221
|
+
}
|
|
222
|
+
return resolved;
|
|
223
|
+
}
|
|
224
|
+
/** The HTTP status on an error or (for wrappers) its `cause`, at most three levels down. */
|
|
225
|
+
function readStatus(error) {
|
|
226
|
+
let next = error;
|
|
227
|
+
for (let depth = 0; depth <= 3 && isRecord(next); depth += 1) {
|
|
228
|
+
const status = next['status'] ?? next['statusCode'];
|
|
229
|
+
if (typeof status === 'number')
|
|
230
|
+
return status;
|
|
231
|
+
next = next['cause'];
|
|
232
|
+
}
|
|
233
|
+
return undefined;
|
|
234
|
+
}
|
|
235
|
+
function isRecord(value) {
|
|
236
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=directory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory.js","sourceRoot":"","sources":["../../../src/external-parties/directory.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,2CAOqB;AACrB,qCAA4D;AAC5D,iCAAqH;AA2ErH,MAAM,MAAM,GAAwC,MAAM,CAAC,MAAM,CAAC;IAChE,WAAW,EAAE,kBAAkB;IAC/B,kBAAkB,EAAE,IAAI;CACzB,CAAC,CAAC;AASH;;;;;;;GAOG;AACH,sCAA6C,OAAsC;IACjF,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IACjC,mEAAmE;IACnE,MAAM,KAAK,GAAY,YAAY,CAAC;IACpC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,WAAW,CAAC,KAAK,UAAU,IAAI,OAAO,KAAK,CAAC,gBAAgB,CAAC,KAAK,UAAU,EAAE,CAAC;QAClH,MAAM,IAAA,qBAAY,EAAC,uEAAuE,CAAC,CAAC;IAC9F,CAAC;IACD,MAAM,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,IAAI,EAAE,CAAC;IAC5D,IAAI,OAAO,kBAAkB,KAAK,QAAQ;QAAE,MAAM,IAAA,qBAAY,EAAC,sCAA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AClB,CAAC;AAED,4FAA4F;AAC5F,SAAS,UAAU,CAAC,KAAc;IAChC,IAAI,IAAI,GAAY,KAAK,CAAC;IAC1B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QAC7D,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC;QACpD,IAAI,OAAO,MAAM,KAAK,QAAQ;YAAE,OAAO,MAAM,CAAC;QAC9C,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** One of a key's parties. */
|
|
2
|
+
export interface ExternalPartyEntry {
|
|
3
|
+
readonly partyId: string;
|
|
4
|
+
/** What precedes `::` in the party ID. */
|
|
5
|
+
readonly partyHint: string;
|
|
6
|
+
/** Whether this participant hosts the party (it can prepare and submit for it here). */
|
|
7
|
+
readonly hostedHere: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** A key's parties, sorted by hint, and whether the party list they came from was read to its end. */
|
|
10
|
+
export interface ExternalPartyListing {
|
|
11
|
+
readonly parties: readonly ExternalPartyEntry[];
|
|
12
|
+
/**
|
|
13
|
+
* False when the list was cut short (a page or time bound, or no list at all): a party the list and the exact lookups
|
|
14
|
+
* did not show may still exist.
|
|
15
|
+
*/
|
|
16
|
+
readonly complete: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** {@link discoverExternalParties}' answer. */
|
|
19
|
+
export interface ExternalPartyDiscovery extends ExternalPartyListing {
|
|
20
|
+
/**
|
|
21
|
+
* False when hints were asked for, the list was not complete and there was no `findParty` to look them up: a hint
|
|
22
|
+
* outside `parties` may then be taken. True otherwise.
|
|
23
|
+
*/
|
|
24
|
+
readonly hintsChecked: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** What a party list answers: party IDs (any namespace; only the key's are kept) and whether it was read to its end. */
|
|
27
|
+
export interface ExternalPartyListAnswer {
|
|
28
|
+
readonly parties: ReadonlyArray<{
|
|
29
|
+
readonly partyId: string;
|
|
30
|
+
readonly hostedHere: boolean;
|
|
31
|
+
}>;
|
|
32
|
+
readonly complete: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** What an exact party lookup answers. `hostedHere` omitted counts as hosted. */
|
|
35
|
+
export interface ExternalPartyLookupAnswer {
|
|
36
|
+
readonly exists: boolean;
|
|
37
|
+
readonly hostedHere?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** The most hints {@link discoverExternalParties} looks up in one call. */
|
|
40
|
+
export declare const MAX_EXTERNAL_PARTY_LOOKUP_HINTS = 16;
|
|
41
|
+
/**
|
|
42
|
+
* A key's parties: what `listParties` answers in the key's namespace, plus an exact `findParty` of each of `hints` the
|
|
43
|
+
* list did not show. The lookups run even when the list says complete (a cached list can predate a party allocated
|
|
44
|
+
* since); with a complete list a failed lookup is skipped, with an incomplete one it fails the call (`LOOKUP_FAILED`).
|
|
45
|
+
* Either callback may be left out: without `listParties` the answer is never complete; without `findParty` the hints
|
|
46
|
+
* are not checked (`hintsChecked: false` when the list is incomplete).
|
|
47
|
+
*
|
|
48
|
+
* `signal` goes to each callback and each call is raced against it, so a callback that ignores it does not hold the
|
|
49
|
+
* call open (`ABORTED`). A callback's failure is `LIST_FAILED` or `LOOKUP_FAILED` with its error as `cause` (an
|
|
50
|
+
* {@link ExternalPartyError} `ABORTED` or `INVALID_RESPONSE` it throws passes through as it is), and an unreadable
|
|
51
|
+
* answer is `INVALID_RESPONSE`. Nothing is recorded or allocated.
|
|
52
|
+
*/
|
|
53
|
+
export declare function discoverExternalParties(input: {
|
|
54
|
+
readonly publicKeyFingerprint: string;
|
|
55
|
+
/** Hints to look up exactly (each non-empty, trimmed, without `::`); duplicates are looked up once. */
|
|
56
|
+
readonly hints?: readonly string[];
|
|
57
|
+
readonly signal?: AbortSignal;
|
|
58
|
+
readonly listParties?: (request: {
|
|
59
|
+
readonly signal?: AbortSignal;
|
|
60
|
+
}) => Promise<ExternalPartyListAnswer>;
|
|
61
|
+
readonly findParty?: (request: {
|
|
62
|
+
readonly partyId: string;
|
|
63
|
+
readonly signal?: AbortSignal;
|
|
64
|
+
}) => Promise<ExternalPartyLookupAnswer>;
|
|
65
|
+
}): Promise<ExternalPartyDiscovery>;
|
|
66
|
+
/** `parties` (party ID → hosted here) as frozen entries, sorted by hint (then party ID), in code-unit order. */
|
|
67
|
+
export declare function sortedEntries(parties: ReadonlyMap<string, boolean>): readonly ExternalPartyEntry[];
|
|
68
|
+
/** Awaits `start()`, unless `signal` aborts first (`ABORTED`); an already-aborted signal never starts it. */
|
|
69
|
+
export declare function raceAbort<T>(start: () => Promise<T>, signal: AbortSignal | undefined, message: string, partyId?: string): Promise<T>;
|
|
70
|
+
/** A string of 1 to 255 characters (a Daml-LF Party at most), trimmed, on one line: what a listing may answer. */
|
|
71
|
+
export declare function isBoundedIdentifier(value: unknown): value is string;
|
|
72
|
+
//# sourceMappingURL=discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../../src/external-parties/discovery.ts"],"names":[],"mappings":"AAaA,8BAA8B;AAC9B,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,0CAA0C;IAC1C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,wFAAwF;IACxF,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC9B;AAED,sGAAsG;AACtG,MAAM,WAAW,oBAAoB;IACnC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