@fairmint/canton-node-sdk 0.0.294 → 0.0.296
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 +43 -0
- 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/connector.d.ts.map +1 -1
- package/build/src/wallets/connector.js +102 -19
- package/build/src/wallets/connector.js.map +1 -1
- 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/session.d.ts.map +1 -1
- package/build/src/wallets/session.js +34 -5
- package/build/src/wallets/session.js.map +1 -1
- 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 +1 -1
|
@@ -28,45 +28,10 @@ exports.verifyWalletOwnership = verifyWalletOwnership;
|
|
|
28
28
|
* hosted on that network; a caller that needs that must look the party up on the network (Scan, or the ledger's party
|
|
29
29
|
* and topology APIs).
|
|
30
30
|
*/
|
|
31
|
-
const canton_protocol_1 = require("./canton-protocol");
|
|
32
|
-
const canton_ed25519_signer_1 = require("./canton-ed25519-signer");
|
|
33
31
|
const ownership_1 = require("../../wallets/ownership");
|
|
32
|
+
const wallet_ownership_checks_1 = require("./wallet-ownership-checks");
|
|
34
33
|
exports.DEFAULT_WALLET_OWNERSHIP_MAX_AGE_MS = 10 * 60 * 1000;
|
|
35
34
|
exports.DEFAULT_WALLET_OWNERSHIP_CLOCK_SKEW_MS = 60 * 1000;
|
|
36
|
-
/**
|
|
37
|
-
* The key as base64 for the Canton helpers: 64 hex characters (the raw key, as Loop reports it), else base64 of the raw
|
|
38
|
-
* or DER SubjectPublicKeyInfo key (as Privy's provider reports it), which the helpers accept as is.
|
|
39
|
-
*/
|
|
40
|
-
function publicKeyBase64(value) {
|
|
41
|
-
return /^[0-9a-fA-F]{64}$/.test(value) ? Buffer.from(value, 'hex').toString('base64') : value;
|
|
42
|
-
}
|
|
43
|
-
/** The signature as base64: 128 hex characters (Loop), else base64 (Privy); 64 bytes either way. */
|
|
44
|
-
function signatureBase64(value) {
|
|
45
|
-
return /^[0-9a-fA-F]{128}$/.test(value)
|
|
46
|
-
? (0, canton_ed25519_signer_1.normalizeCantonEd25519Signature)({ signatureHex: value })
|
|
47
|
-
: (0, canton_ed25519_signer_1.normalizeCantonEd25519Signature)({ signatureBase64: value });
|
|
48
|
-
}
|
|
49
|
-
function readProof(proof) {
|
|
50
|
-
if (typeof proof !== 'object' || proof === null)
|
|
51
|
-
return null;
|
|
52
|
-
const record = proof;
|
|
53
|
-
const { partyId, publicKey, namespace, message, signature } = record;
|
|
54
|
-
if (typeof partyId !== 'string' ||
|
|
55
|
-
typeof publicKey !== 'string' ||
|
|
56
|
-
typeof message !== 'string' ||
|
|
57
|
-
typeof signature !== 'string' ||
|
|
58
|
-
(namespace !== undefined && typeof namespace !== 'string') ||
|
|
59
|
-
publicKey.length > 1024 ||
|
|
60
|
-
signature.length > 1024) {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
return { partyId, publicKey, message, signature, ...(namespace !== undefined && { namespace }) };
|
|
64
|
-
}
|
|
65
|
-
const fail = (reason, message) => ({
|
|
66
|
-
verified: false,
|
|
67
|
-
reason,
|
|
68
|
-
message,
|
|
69
|
-
});
|
|
70
35
|
/**
|
|
71
36
|
* Verify a wallet ownership proof (see the module comment for what this does and does not establish). Never throws for
|
|
72
37
|
* a bad proof: the result says why it failed. Throws `TypeError` for invalid options.
|
|
@@ -81,84 +46,45 @@ function verifyWalletOwnership(proof, options) {
|
|
|
81
46
|
if (typeof options.expectedDomain !== 'string' || options.expectedDomain.length === 0) {
|
|
82
47
|
throw new TypeError('expectedDomain is required');
|
|
83
48
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
const read = readProof(proof);
|
|
49
|
+
(0, wallet_ownership_checks_1.assertWindowOptions)(now, maxAgeMs, skewMs, 'now, maxAgeMs and clockSkewMs');
|
|
50
|
+
const read = (0, wallet_ownership_checks_1.readWalletOwnershipProof)(proof);
|
|
88
51
|
if (read === null)
|
|
89
|
-
return
|
|
52
|
+
return (0, wallet_ownership_checks_1.checkFailure)('malformed-proof', 'The proof is not { partyId, publicKey, message, signature }');
|
|
90
53
|
const fields = (0, ownership_1.parseWalletOwnershipMessage)(read.message);
|
|
91
54
|
if (fields === null)
|
|
92
|
-
return
|
|
55
|
+
return (0, wallet_ownership_checks_1.checkFailure)('malformed-message', 'The signed text is not a canonical wallet ownership message');
|
|
93
56
|
if (fields.partyId !== read.partyId) {
|
|
94
|
-
return
|
|
57
|
+
return (0, wallet_ownership_checks_1.checkFailure)('party-mismatch', 'The signed message names another party than the proof');
|
|
95
58
|
}
|
|
96
59
|
if (options.expectedPartyId !== undefined && read.partyId !== options.expectedPartyId) {
|
|
97
|
-
return
|
|
60
|
+
return (0, wallet_ownership_checks_1.checkFailure)('party-mismatch', 'The proof is for another party than expected');
|
|
98
61
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return fail('party-mismatch', "The wallet's namespace is not the party id's namespace");
|
|
62
|
+
if (read.namespace !== undefined && read.namespace !== (0, wallet_ownership_checks_1.partyNamespace)(read.partyId)) {
|
|
63
|
+
return (0, wallet_ownership_checks_1.checkFailure)('party-mismatch', "The wallet's namespace is not the party id's namespace");
|
|
102
64
|
}
|
|
103
65
|
if (fields.domain !== options.expectedDomain) {
|
|
104
|
-
return
|
|
66
|
+
return (0, wallet_ownership_checks_1.checkFailure)('domain-mismatch', `The message was signed for ${fields.domain}, not ${options.expectedDomain}`);
|
|
105
67
|
}
|
|
106
68
|
if (fields.nonce !== options.expectedNonce) {
|
|
107
|
-
return
|
|
69
|
+
return (0, wallet_ownership_checks_1.checkFailure)('nonce-mismatch', 'The message was signed for another challenge');
|
|
108
70
|
}
|
|
109
71
|
if (options.expectedNetwork !== undefined && fields.network !== options.expectedNetwork) {
|
|
110
|
-
return
|
|
72
|
+
return (0, wallet_ownership_checks_1.checkFailure)('network-mismatch', `The message names network ${fields.network ?? '(none)'}, not ${options.expectedNetwork}`);
|
|
111
73
|
}
|
|
112
74
|
if ((options.expectedIssuedAt !== undefined && fields.issuedAt !== options.expectedIssuedAt) ||
|
|
113
75
|
(options.expectedExpiresAt !== undefined && fields.expiresAt !== options.expectedExpiresAt)) {
|
|
114
|
-
return
|
|
115
|
-
}
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (
|
|
121
|
-
return
|
|
122
|
-
}
|
|
123
|
-
// With the lifetime bounded above, this also bounds the message's age by maxAgeMs.
|
|
124
|
-
if (now >= expiresAt)
|
|
125
|
-
return fail('expired', 'The message has expired');
|
|
126
|
-
let fingerprint;
|
|
127
|
-
let keyBase64;
|
|
128
|
-
try {
|
|
129
|
-
keyBase64 = publicKeyBase64(read.publicKey);
|
|
130
|
-
fingerprint = (0, canton_protocol_1.deriveCantonEd25519PublicKeyFingerprint)(keyBase64);
|
|
131
|
-
}
|
|
132
|
-
catch {
|
|
133
|
-
return fail('unsupported-public-key', 'The public key is not an Ed25519 key in hex (raw 32 bytes) or base64 (raw 32 bytes or DER SubjectPublicKeyInfo)');
|
|
134
|
-
}
|
|
135
|
-
let partyFingerprint;
|
|
136
|
-
try {
|
|
137
|
-
partyFingerprint = (0, canton_protocol_1.extractPublicKeyFingerprint)(read.partyId);
|
|
138
|
-
}
|
|
139
|
-
catch {
|
|
140
|
-
return fail('party-mismatch', 'The party id is not of the form hint::namespace');
|
|
141
|
-
}
|
|
142
|
-
if (partyFingerprint !== fingerprint) {
|
|
143
|
-
return fail('key-not-bound-to-party', "The public key's Canton fingerprint is not the party's namespace, so the key does not prove control of the party (a participant-hosted party, or a rotated or delegated key, needs a topology lookup)");
|
|
144
|
-
}
|
|
145
|
-
let signature;
|
|
146
|
-
try {
|
|
147
|
-
signature = signatureBase64(read.signature);
|
|
148
|
-
}
|
|
149
|
-
catch {
|
|
150
|
-
return fail('malformed-signature', 'The signature is not 64 bytes of hex or base64');
|
|
151
|
-
}
|
|
152
|
-
try {
|
|
153
|
-
(0, canton_protocol_1.assertEd25519Signature)({ publicKeyBase64: keyBase64, payload: read.message, signatureBase64: signature });
|
|
154
|
-
}
|
|
155
|
-
catch {
|
|
156
|
-
return fail('bad-signature', 'The signature does not verify against the public key');
|
|
157
|
-
}
|
|
76
|
+
return (0, wallet_ownership_checks_1.checkFailure)('window-mismatch', 'The message names another validity window than the server issued');
|
|
77
|
+
}
|
|
78
|
+
const windowFailure = (0, wallet_ownership_checks_1.checkWindow)(fields.issuedAt, fields.expiresAt, now, maxAgeMs, skewMs);
|
|
79
|
+
if (windowFailure !== null)
|
|
80
|
+
return windowFailure;
|
|
81
|
+
const bound = (0, wallet_ownership_checks_1.checkKeyAndSignature)(read);
|
|
82
|
+
if ('verified' in bound)
|
|
83
|
+
return bound;
|
|
158
84
|
return {
|
|
159
85
|
verified: true,
|
|
160
86
|
partyId: read.partyId,
|
|
161
|
-
publicKeyFingerprint: fingerprint,
|
|
87
|
+
publicKeyFingerprint: bound.fingerprint,
|
|
162
88
|
domain: fields.domain,
|
|
163
89
|
nonce: fields.nonce,
|
|
164
90
|
...(fields.network !== undefined && { network: fields.network }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-ownership.js","sourceRoot":"","sources":["../../../../src/utils/external-signing/wallet-ownership.ts"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,
|
|
1
|
+
{"version":3,"file":"wallet-ownership.js","sourceRoot":"","sources":["../../../../src/utils/external-signing/wallet-ownership.ts"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,uDAAsE;AAEtE,uEAOmC;AA8CtB,QAAA,mCAAmC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CA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B,EAAE,kEAAkE,CAAC,CAAC;IACrG,CAAC;IAED,MAAM,aAAa,GAAG,IAAA,qCAAW,EAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC5F,IAAI,aAAa,KAAK,IAAI;QAAE,OAAO,aAAa,CAAC;IACjD,MAAM,KAAK,GAAG,IAAA,8CAAoB,EAAC,IAAI,CAAC,CAAC;IACzC,IAAI,UAAU,IAAI,KAAK;QAAE,OAAO,KAAK,CAAC;IAEtC,OAAO;QACL,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,oBAAoB,EAAE,KAAK,CAAC,WAAW;QACvC,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,GAAG,CAAC,MAAM,CAAC,OAAO,KAAK,SAAS,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;QAChE,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,SAAS,EAAE,MAAM,CAAC,SAAS;KAC5B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { DaNetwork } from '../../wallets/da-utilities/client';
|
|
2
|
+
import type { WalletOwnershipFailure } from '../../wallets/ownership';
|
|
3
|
+
import { type WalletProofFields } from '../../wallets/wallet-proof';
|
|
4
|
+
/** What the server expects the message to name. Optional fields are not checked when omitted. */
|
|
5
|
+
export interface WalletProofExpectation {
|
|
6
|
+
/** The purpose tag (`fairmint:tokenization-wallet-proof:v1`). */
|
|
7
|
+
readonly domain: string;
|
|
8
|
+
readonly network: DaNetwork;
|
|
9
|
+
/** The party the user claims; the proof and its message must both name it. */
|
|
10
|
+
readonly partyId: string;
|
|
11
|
+
readonly investorContext?: string;
|
|
12
|
+
readonly idempotencyKey?: string;
|
|
13
|
+
/** The `issuedAt` the server issued, when it built the message; the message must repeat it exactly. */
|
|
14
|
+
readonly issuedAt?: string;
|
|
15
|
+
/** The `expiresAt` the server issued, when it built the message; the message must repeat it exactly. */
|
|
16
|
+
readonly expiresAt?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface VerifyWalletProofArgs {
|
|
19
|
+
/** `{ partyId, publicKey, message, signature }` (and optional `namespace`), as the browser sent it. */
|
|
20
|
+
readonly proof: unknown;
|
|
21
|
+
readonly expected: WalletProofExpectation;
|
|
22
|
+
/** Defaults to the system clock. */
|
|
23
|
+
readonly now?: Date;
|
|
24
|
+
/** The longest validity window accepted (`expiresAt - issuedAt`). Defaults to 10 minutes. */
|
|
25
|
+
readonly maxLifetimeMs?: number;
|
|
26
|
+
/** How far in the future `issuedAt` may be. Defaults to 60 seconds. */
|
|
27
|
+
readonly maxSkewMs?: number;
|
|
28
|
+
}
|
|
29
|
+
export type WalletProofVerification = ({
|
|
30
|
+
readonly verified: true;
|
|
31
|
+
/** The party's namespace, which is the key's Canton fingerprint. */
|
|
32
|
+
readonly publicKeyFingerprint: string;
|
|
33
|
+
} & WalletProofFields) | {
|
|
34
|
+
readonly verified: false;
|
|
35
|
+
readonly reason: WalletOwnershipFailure;
|
|
36
|
+
/** A sentence for logs or the user; it never echoes the submitted values. */
|
|
37
|
+
readonly message: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Verify a wallet proof (see the module comment). Never throws for a bad proof: the result says why it failed. Throws
|
|
41
|
+
* `TypeError` for invalid arguments (an expectation without domain, network or party, or a bad clock or bound).
|
|
42
|
+
*/
|
|
43
|
+
export declare function verifyWalletProof(args: VerifyWalletProofArgs): WalletProofVerification;
|
|
44
|
+
//# sourceMappingURL=wallet-proof.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-proof.d.ts","sourceRoot":"","sources":["../../../../src/utils/external-signing/wallet-proof.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mC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AAC;AAEN;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,GAAG,uBAAuB,CA8CtF"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyWalletProof = verifyWalletProof;
|
|
4
|
+
/**
|
|
5
|
+
* Server-side verification of a wallet proof message (`wallet-proof-v1`, `buildWalletProofMessage` in the browser-safe
|
|
6
|
+
* wallets module): the compact JSON form apiv2's CNTN tokenization flow uses. Node only, like `verifyWalletOwnership`,
|
|
7
|
+
* whose key and signature checks it shares.
|
|
8
|
+
*
|
|
9
|
+
* A `verified` result means the party's own key signed exactly the canonical message naming the expected domain,
|
|
10
|
+
* network, party (and, when given, account and request) within its validity window: the message parses strictly
|
|
11
|
+
* (`parseWalletProofMessage`), each field equals the server's value, `issuedAt <= now + maxSkewMs`, `expiresAt > now`,
|
|
12
|
+
* `expiresAt - issuedAt <= maxLifetimeMs`, the key's Canton fingerprint is the party's namespace, and the Ed25519
|
|
13
|
+
* signature over the message's UTF-8 bytes verifies. The same limits as `verifyWalletOwnership` apply: the network is a
|
|
14
|
+
* label, a party not namespaced by its key fails `key-not-bound-to-party`, and the caller must accept each
|
|
15
|
+
* `idempotencyKey` once (this function cannot tell a replay from a fresh proof).
|
|
16
|
+
*/
|
|
17
|
+
const cip103_1 = require("../../wallets/cip103");
|
|
18
|
+
const wallet_proof_1 = require("../../wallets/wallet-proof");
|
|
19
|
+
const wallet_ownership_1 = require("./wallet-ownership");
|
|
20
|
+
const wallet_ownership_checks_1 = require("./wallet-ownership-checks");
|
|
21
|
+
/**
|
|
22
|
+
* Verify a wallet proof (see the module comment). Never throws for a bad proof: the result says why it failed. Throws
|
|
23
|
+
* `TypeError` for invalid arguments (an expectation without domain, network or party, or a bad clock or bound).
|
|
24
|
+
*/
|
|
25
|
+
function verifyWalletProof(args) {
|
|
26
|
+
const { expected } = args;
|
|
27
|
+
const maxLifetimeMs = args.maxLifetimeMs ?? wallet_ownership_1.DEFAULT_WALLET_OWNERSHIP_MAX_AGE_MS;
|
|
28
|
+
const maxSkewMs = args.maxSkewMs ?? wallet_ownership_1.DEFAULT_WALLET_OWNERSHIP_CLOCK_SKEW_MS;
|
|
29
|
+
const now = (args.now ?? new Date()).getTime();
|
|
30
|
+
for (const key of ['domain', 'network', 'partyId']) {
|
|
31
|
+
if (typeof expected[key] !== 'string' || expected[key].length === 0) {
|
|
32
|
+
throw new TypeError(`expected.${key} is required`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!(0, cip103_1.isDaNetwork)(expected.network))
|
|
36
|
+
throw new TypeError('expected.network must be devnet or mainnet');
|
|
37
|
+
(0, wallet_ownership_checks_1.assertWindowOptions)(now, maxLifetimeMs, maxSkewMs, 'now, maxLifetimeMs and maxSkewMs');
|
|
38
|
+
const read = (0, wallet_ownership_checks_1.readWalletOwnershipProof)(args.proof);
|
|
39
|
+
if (read === null)
|
|
40
|
+
return (0, wallet_ownership_checks_1.checkFailure)('malformed-proof', 'The proof is not { partyId, publicKey, message, signature }');
|
|
41
|
+
const fields = (0, wallet_proof_1.parseWalletProofMessage)(read.message);
|
|
42
|
+
if (fields === null)
|
|
43
|
+
return (0, wallet_ownership_checks_1.checkFailure)('malformed-message', 'The signed text is not a canonical wallet proof message');
|
|
44
|
+
if (fields.partyId !== read.partyId) {
|
|
45
|
+
return (0, wallet_ownership_checks_1.checkFailure)('party-mismatch', 'The signed message names another party than the proof');
|
|
46
|
+
}
|
|
47
|
+
if (read.partyId !== expected.partyId)
|
|
48
|
+
return (0, wallet_ownership_checks_1.checkFailure)('party-mismatch', 'The proof is for another party than expected');
|
|
49
|
+
if (read.namespace !== undefined && read.namespace !== (0, wallet_ownership_checks_1.partyNamespace)(read.partyId)) {
|
|
50
|
+
return (0, wallet_ownership_checks_1.checkFailure)('party-mismatch', "The wallet's namespace is not the party id's namespace");
|
|
51
|
+
}
|
|
52
|
+
if (fields.domain !== expected.domain)
|
|
53
|
+
return (0, wallet_ownership_checks_1.checkFailure)('domain-mismatch', 'The message was signed for another purpose');
|
|
54
|
+
if (fields.network !== expected.network)
|
|
55
|
+
return (0, wallet_ownership_checks_1.checkFailure)('network-mismatch', 'The message names another network');
|
|
56
|
+
if (expected.investorContext !== undefined && fields.investorContext !== expected.investorContext) {
|
|
57
|
+
return (0, wallet_ownership_checks_1.checkFailure)('investor-context-mismatch', 'The message names another account');
|
|
58
|
+
}
|
|
59
|
+
if (expected.idempotencyKey !== undefined && fields.idempotencyKey !== expected.idempotencyKey) {
|
|
60
|
+
return (0, wallet_ownership_checks_1.checkFailure)('idempotency-key-mismatch', 'The message was signed for another request');
|
|
61
|
+
}
|
|
62
|
+
if ((expected.issuedAt !== undefined && fields.issuedAt !== expected.issuedAt) ||
|
|
63
|
+
(expected.expiresAt !== undefined && fields.expiresAt !== expected.expiresAt)) {
|
|
64
|
+
return (0, wallet_ownership_checks_1.checkFailure)('window-mismatch', 'The message names another validity window than the server issued');
|
|
65
|
+
}
|
|
66
|
+
const windowFailure = (0, wallet_ownership_checks_1.checkWindow)(fields.issuedAt, fields.expiresAt, now, maxLifetimeMs, maxSkewMs);
|
|
67
|
+
if (windowFailure !== null)
|
|
68
|
+
return windowFailure;
|
|
69
|
+
const bound = (0, wallet_ownership_checks_1.checkKeyAndSignature)(read);
|
|
70
|
+
if ('verified' in bound)
|
|
71
|
+
return bound;
|
|
72
|
+
return { verified: true, ...fields, publicKeyFingerprint: bound.fingerprint };
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=wallet-proof.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-proof.js","sourceRoot":"","sources":["../../../../src/utils/external-signing/wallet-proof.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACH,iDAAmD;AAGnD,6DAA6F;AAC7F,yDAAiH;AACjH,uEAOmC;AA0CnC;;;GAGG;AAC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AG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACnD;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC;IACpC;;;OAGG;IACH,OAAO,CAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC;IAC9C,wEAAwE;IACxE,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B;;;;;;;;OAQG;IACH,MAAM,IAAI,IAAI,CAAC;IACf,oHAAoH;IACpH,UAAU,IAAI,IAAI,CAAC;IACnB;;;;;OAKG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,iEAAiE;AACjE,eAAO,MAAM,0BAA0B,QAAS,CAAC;AA2DjD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,oBAAoB,GAAG,eAAe,CAi6BlF"}
|
|
@@ -71,6 +71,17 @@ function createWalletConnector(input) {
|
|
|
71
71
|
let discovery = null;
|
|
72
72
|
let discovering = false;
|
|
73
73
|
let disposed = false;
|
|
74
|
+
// Set while the connector bumps the latch itself: its own latch listener then does not evaluate the wanted live
|
|
75
|
+
// option, so a deferred change cannot move the session before the caller decides (a latch subscriber may start a
|
|
76
|
+
// write during the bump). The caller's own path decides instead, or the latch's release evaluates later.
|
|
77
|
+
// A depth, not a flag: a latch subscriber may re-enter connect() during the bump, and the inner bump ending must not
|
|
78
|
+
// end the outer one's suppression.
|
|
79
|
+
let bumping = 0;
|
|
80
|
+
// The provider a connect of the latest attempt is starting the session on, during the synchronous part of
|
|
81
|
+
// `session.connect` (the session leaves the previous wallet, and only then publishes `connecting`). A withdrawal
|
|
82
|
+
// heard in this window stops that sign-in with a plain `session.disconnect()`: the run took its epoch before the
|
|
83
|
+
// previous wallet's call-outs, so the disconnect supersedes it.
|
|
84
|
+
let starting = null;
|
|
74
85
|
// Per key, the option object subscribed to and its unsubscribe: a replacement with the same key is subscribed anew.
|
|
75
86
|
const liveSubscriptions = new Map();
|
|
76
87
|
/** Want `next`, unsubscribing the earlier object the previous wanted option kept, unless `next` keeps it too. */
|
|
@@ -92,8 +103,23 @@ function createWalletConnector(input) {
|
|
|
92
103
|
wanted.former?.unsubscribe();
|
|
93
104
|
wanted.former = null;
|
|
94
105
|
}
|
|
95
|
-
/**
|
|
106
|
+
/** Bump the latch without the connector's own latch listener evaluating the wanted live option meanwhile. */
|
|
107
|
+
function bumpQuietly() {
|
|
108
|
+
bumping += 1;
|
|
109
|
+
try {
|
|
110
|
+
latch.bump();
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
bumping -= 1;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Whether the session is on `provider`, connected or connecting. Also while the connector's current attempt is
|
|
118
|
+
* starting a connect to it: the session still shows the previous wallet while it signs that one out.
|
|
119
|
+
*/
|
|
96
120
|
function sessionOn(provider) {
|
|
121
|
+
if (starting?.provider === provider && starting.attempt === attempts && !disposed)
|
|
122
|
+
return true;
|
|
97
123
|
const state = sessionState();
|
|
98
124
|
return ((state.status === 'connected' && state.wallet.provider === provider) ||
|
|
99
125
|
(state.status === 'connecting' && via?.provider === provider));
|
|
@@ -344,8 +370,18 @@ function createWalletConnector(input) {
|
|
|
344
370
|
async function connectProvider(forSession, option, provider, retainKey, remember = false) {
|
|
345
371
|
const attempt = nextAttempt();
|
|
346
372
|
via = { provider, option, retainKey, party: null };
|
|
347
|
-
// Started synchronously: inside the user's click when nothing was awaited before.
|
|
348
|
-
|
|
373
|
+
// Started synchronously: inside the user's click when nothing was awaited before. A notification the session's
|
|
374
|
+
// sign-out of the previous wallet sets off finds the session on `provider` already.
|
|
375
|
+
const outer = starting;
|
|
376
|
+
starting = { provider, attempt };
|
|
377
|
+
let pending;
|
|
378
|
+
try {
|
|
379
|
+
// It never rejects without a signal; the catch only keeps a surprise from going unhandled.
|
|
380
|
+
pending = forSession.connect(provider).catch(() => undefined);
|
|
381
|
+
}
|
|
382
|
+
finally {
|
|
383
|
+
starting = outer;
|
|
384
|
+
}
|
|
349
385
|
publish();
|
|
350
386
|
// A superseded connect reports at once; the session drops its late answer itself.
|
|
351
387
|
let wake = () => undefined;
|
|
@@ -362,8 +398,15 @@ function createWalletConnector(input) {
|
|
|
362
398
|
* object no longer listed (heard through its stray listener) can only tear the wallet down, never connect one.
|
|
363
399
|
*/
|
|
364
400
|
function evaluateLive() {
|
|
365
|
-
|
|
401
|
+
// Quiet while the connector bumps the latch itself; an explicit reconcileLive() (connect()'s own) still runs.
|
|
402
|
+
if (bumping > 0)
|
|
366
403
|
return;
|
|
404
|
+
void reconcileLive();
|
|
405
|
+
}
|
|
406
|
+
/** {@link evaluateLive}, returning the attempt it starts (null when it starts none). */
|
|
407
|
+
function reconcileLive() {
|
|
408
|
+
if (disposed || session === null || live === null)
|
|
409
|
+
return null;
|
|
367
410
|
const wanted = live;
|
|
368
411
|
const listed = fixed.includes(wanted.option) || discovered.includes(wanted.option);
|
|
369
412
|
let provider;
|
|
@@ -376,7 +419,12 @@ function createWalletConnector(input) {
|
|
|
376
419
|
provider = null;
|
|
377
420
|
retainKey = null;
|
|
378
421
|
}
|
|
379
|
-
if (provider === null && wanted.former !== null) {
|
|
422
|
+
if (provider === null && wanted.former !== null && (wanted.connected === null || !sessionOn(wanted.connected))) {
|
|
423
|
+
// The session left the earlier object's provider (a cancelled sign-in): it no longer speaks for anything, and the
|
|
424
|
+
// replacement's empty answer clears the wallet below, so offering that provider again connects it.
|
|
425
|
+
dropFormer(wanted);
|
|
426
|
+
}
|
|
427
|
+
else if (provider === null && wanted.former !== null) {
|
|
380
428
|
// A rediscovered replacement that has not offered yet: the earlier object speaks for the wallet. The same
|
|
381
429
|
// provider keeps it, another one is a change, and only its empty answer (or a throw) is a withdrawal.
|
|
382
430
|
try {
|
|
@@ -397,7 +445,7 @@ function createWalletConnector(input) {
|
|
|
397
445
|
if (provider === null) {
|
|
398
446
|
const previous = wanted.connected;
|
|
399
447
|
if (previous === null)
|
|
400
|
-
return;
|
|
448
|
+
return null;
|
|
401
449
|
// Torn down (logout, another wallet or party): leave it. An unlisted object is no longer wanted either: it can
|
|
402
450
|
// never connect again, so keeping it would leave the connector 'preparing' a wallet it no longer lists.
|
|
403
451
|
dropFormer(wanted);
|
|
@@ -405,27 +453,33 @@ function createWalletConnector(input) {
|
|
|
405
453
|
held = null;
|
|
406
454
|
if (!listed)
|
|
407
455
|
setLive(null);
|
|
408
|
-
|
|
456
|
+
// A sign-in the connector is starting on that provider is superseded, so it never reports `connected` for a
|
|
457
|
+
// wallet the option no longer offers, and the disconnect below stops it. Whether the session is on it is read
|
|
458
|
+
// first: the new attempt ends `starting`, and the session may still show the previous wallet.
|
|
459
|
+
const on = sessionOn(previous);
|
|
460
|
+
if (starting?.provider === previous && starting.attempt === attempts)
|
|
461
|
+
nextAttempt();
|
|
462
|
+
if (on)
|
|
409
463
|
session.disconnect();
|
|
410
464
|
publish();
|
|
411
|
-
return;
|
|
465
|
+
return null;
|
|
412
466
|
}
|
|
413
467
|
if (provider === wanted.connected)
|
|
414
|
-
return;
|
|
468
|
+
return null;
|
|
415
469
|
// The user's connect to a loaded option is loading: it decides first (a failure evaluates again).
|
|
416
470
|
if (pendingLoad !== null)
|
|
417
|
-
return;
|
|
471
|
+
return null;
|
|
418
472
|
// An option that cannot connect here offers nothing: its next change evaluates again.
|
|
419
473
|
if (!availability(wanted.option).available)
|
|
420
|
-
return;
|
|
474
|
+
return null;
|
|
421
475
|
// Never reconnect under a write: the latch's release evaluates again.
|
|
422
476
|
if (latch.getSnapshot().holder !== null)
|
|
423
|
-
return;
|
|
477
|
+
return null;
|
|
424
478
|
wanted.connected = provider;
|
|
425
479
|
const current = currentConnection();
|
|
426
480
|
held =
|
|
427
481
|
current !== null && retainKey !== null && current.key === `${wanted.option.key}:${retainKey}` ? current : null;
|
|
428
|
-
|
|
482
|
+
return connectProvider(session, wanted.option, provider, retainKey);
|
|
429
483
|
}
|
|
430
484
|
function stopPendingLoad() {
|
|
431
485
|
if (pendingLoad === null)
|
|
@@ -640,13 +694,18 @@ function createWalletConnector(input) {
|
|
|
640
694
|
publish();
|
|
641
695
|
return { status: 'refused', reason: 'unavailable' };
|
|
642
696
|
}
|
|
643
|
-
latch.bump();
|
|
644
697
|
// The bump notifies the latch's subscribers synchronously, and one may start a write: the previous wallet, its
|
|
645
|
-
// restore and its remembered key then stay, as for the busy check above.
|
|
698
|
+
// restore and its remembered key then stay, as for the busy check above. The connector's own listener does not
|
|
699
|
+
// evaluate during it, so a deferred live change cannot have moved the session either.
|
|
700
|
+
bumpQuietly();
|
|
646
701
|
if (latch.getSnapshot().holder !== null)
|
|
647
702
|
return { status: 'refused', reason: 'busy' };
|
|
648
703
|
retireRestore();
|
|
649
704
|
error = null;
|
|
705
|
+
// A connect still loading its provider is superseded, whichever path this call takes (the wallet already on
|
|
706
|
+
// included): its load then ends `cancelled`, never reporting a failure or connecting late.
|
|
707
|
+
if (pendingLoad !== null)
|
|
708
|
+
nextAttempt();
|
|
650
709
|
stopPendingLoad();
|
|
651
710
|
held = null;
|
|
652
711
|
if (option.mode === 'live') {
|
|
@@ -656,11 +715,22 @@ function createWalletConnector(input) {
|
|
|
656
715
|
setSelected(null);
|
|
657
716
|
// Already on this option's wallet (perhaps kept by an earlier object while a rediscovered replacement has not
|
|
658
717
|
// offered yet): nothing to do, and rebuilding the wanted state would drop that earlier object and disconnect.
|
|
718
|
+
// A change the option offered while it could not connect is heard first, as the bump would have: this call
|
|
719
|
+
// reports the sign-in that change starts (one sign-in, not a second that supersedes it), and a withdrawal moves
|
|
720
|
+
// the session, so the check below fails and a new attempt follows.
|
|
721
|
+
if (live?.option === option) {
|
|
722
|
+
const started = reconcileLive();
|
|
723
|
+
if (started !== null)
|
|
724
|
+
return started;
|
|
725
|
+
}
|
|
726
|
+
// The session's own snapshot, not sessionOn(): a connect the connector is starting to that provider has not
|
|
727
|
+
// signed it in yet.
|
|
659
728
|
const current = live;
|
|
729
|
+
const state = sessionState();
|
|
660
730
|
if (current?.option === option &&
|
|
661
731
|
current.connected !== null &&
|
|
662
|
-
|
|
663
|
-
|
|
732
|
+
state.status === 'connected' &&
|
|
733
|
+
state.wallet.provider === current.connected) {
|
|
664
734
|
publish();
|
|
665
735
|
return { status: 'connected' };
|
|
666
736
|
}
|
|
@@ -703,6 +773,8 @@ function createWalletConnector(input) {
|
|
|
703
773
|
const attempt = nextAttempt();
|
|
704
774
|
const controller = new AbortController();
|
|
705
775
|
pendingLoad = { option, controller };
|
|
776
|
+
// A withdrawal the bump suppressed is heard now: the session leaves a torn-down wallet while this one loads.
|
|
777
|
+
evaluateLive();
|
|
706
778
|
publish();
|
|
707
779
|
let provider;
|
|
708
780
|
try {
|
|
@@ -835,8 +907,12 @@ function createWalletConnector(input) {
|
|
|
835
907
|
held = null;
|
|
836
908
|
if (loadingOnly)
|
|
837
909
|
evaluateLive();
|
|
838
|
-
else
|
|
910
|
+
else {
|
|
911
|
+
// The sign-in ends: an earlier object kept for it no longer speaks for the wallet.
|
|
912
|
+
if (live !== null)
|
|
913
|
+
dropFormer(live);
|
|
839
914
|
session?.disconnect();
|
|
915
|
+
}
|
|
840
916
|
}
|
|
841
917
|
else if (current === 'preparing') {
|
|
842
918
|
const dismissed = live;
|
|
@@ -855,15 +931,22 @@ function createWalletConnector(input) {
|
|
|
855
931
|
if (disposed)
|
|
856
932
|
return;
|
|
857
933
|
retireRestore();
|
|
858
|
-
latch.bump();
|
|
859
934
|
nextAttempt();
|
|
860
935
|
stopPendingLoad();
|
|
861
936
|
setLive(null);
|
|
862
937
|
held = null;
|
|
938
|
+
const epochBefore = latch.getSnapshot().epoch;
|
|
863
939
|
session?.disconnect();
|
|
864
940
|
setSelected(null);
|
|
865
941
|
(0, storage_1.writeStorage)(local, walletStorageKey, null);
|
|
866
942
|
error = null;
|
|
943
|
+
// Bumped once the wallet is left: the bump notifies the latch's subscribers synchronously, and a write one starts
|
|
944
|
+
// then (in the new epoch, so not abandoned) finds no wallet rather than having it disconnected underneath it.
|
|
945
|
+
// Nothing is wanted any more, so the connector's own listener starts no deferred live change either. A store on
|
|
946
|
+
// this latch already bumped when the session left its wallet: bumping again would abandon a run a subscriber
|
|
947
|
+
// started in that new epoch, so the epoch moves once.
|
|
948
|
+
if (latch.getSnapshot().epoch === epochBefore)
|
|
949
|
+
latch.bump();
|
|
867
950
|
publish();
|
|
868
951
|
},
|
|
869
952
|
dispose() {
|