@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
|
@@ -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;AACH,2BAAkC,IAA2B;IAC3D,MAA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AC;IACrG,CAAC;IAED,MAAM,aAAa,GAAG,IAAA,qCAAW,EAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,SAAS,EAAE,GAAG,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;IACpG,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,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,MAAM,EAAE,oBAAoB,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC;AAChF,CAAC"}
|
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
* (`InstrumentBalance.lockedInExpiredLocks`), and the `reclaimLockedTokens` action that unlocks both
|
|
24
24
|
* (`WalletToken.canReclaim` says when it applies).
|
|
25
25
|
* - The ownership proof's browser half (`requestWalletOwnershipVerdict`); the server half
|
|
26
|
-
* (`createWalletOwnershipChallenger`, `verifyWalletOwnership`) is Node-only and exported from the package root.
|
|
26
|
+
* (`createWalletOwnershipChallenger`, `verifyWalletOwnership`) is Node-only and exported from the package root. The
|
|
27
|
+
* compact wallet proof message (`buildWalletProofMessage`, `parseWalletProofMessage`, `proveWalletProof`; verified by
|
|
28
|
+
* `verifyWalletProof` at the package root) is apiv2's CNTN tokenization wallet proof format.
|
|
27
29
|
* - The errors, their guards (`isWalletError`, `isWalletSubmitError`, …: they match errors of any copy of this module,
|
|
28
30
|
* where `instanceof` does not), their user-facing descriptions (`describeWalletError`), and the data types.
|
|
29
31
|
* - Display helpers that return codes, not sentences: `selectWalletToken`, `formatTokenAmount`, `formatOfferExpiry`,
|
|
@@ -43,7 +45,8 @@ export { actionState, canAct, createWalletStore, walletActionKey, type ActionOut
|
|
|
43
45
|
export { createWallet, type BurnRequestOptions, type BurnRequestResult, type TransferOffers, type TransferPlan, type TransferPreapprovalOptions, type TransferRequest, type TransferResult, type Wallet, type WalletCallOptions, type WalletOptions, type WalletState, type WithdrawExpiredResult, type WithdrawnOffer, type ReleasedLock, type ReclaimLockedTokensResult, } from './wallet';
|
|
44
46
|
export type { Cip103Connection, Cip103EventListener, Cip103Provider, Cip103Request } from './cip103';
|
|
45
47
|
export { discoverCip103Wallets, INJECTED_WALLET_ID, type Cip103DiscoveryHost, type DiscoverCip103WalletsOptions, type DiscoveredWallet, } from './discovery';
|
|
46
|
-
export { buildWalletOwnershipMessage, proveWalletOwnership, requestWalletOwnershipVerdict, type ProveWalletOwnershipOptions, type RequestWalletOwnershipVerdictOptions, type WalletOwnershipChallenge, type WalletOwnershipChallengeFailure, type WalletOwnershipChallengeResponse, type WalletOwnershipFailure, type WalletOwnershipMessageFields, type WalletOwnershipProof, type WalletOwnershipVerdict, } from './ownership';
|
|
48
|
+
export { buildWalletOwnershipMessage, proveWalletOwnership, proveWalletProof, requestWalletOwnershipVerdict, type ProveWalletOwnershipOptions, type ProveWalletProofOptions, type RequestWalletOwnershipVerdictOptions, type WalletOwnershipChallenge, type WalletOwnershipChallengeFailure, type WalletOwnershipChallengeResponse, type WalletOwnershipFailure, type WalletOwnershipMessageFields, type WalletOwnershipProof, type WalletOwnershipVerdict, } from './ownership';
|
|
49
|
+
export { buildWalletProofMessage, parseWalletProofMessage, WALLET_PROOF_FORMAT, WALLET_PROOF_MAX_MESSAGE_BYTES, WALLET_PROOF_MAX_MESSAGE_LENGTH, type WalletProofChallengeResponse, type WalletProofFields, type WalletProofFormat, } from './wallet-proof';
|
|
47
50
|
export { DA_REGISTRY_REQUEST_TIMEOUT_MS, type DaNetwork, type DaRegistryOptions, type FetchLike, type TransferKind, } from './da-utilities/client';
|
|
48
51
|
export { describeWalletError, isRegistryApiError, isRegistryResponseError, isWalletCancellation, isWalletError, isWalletOptionError, isWalletReadError, isWalletSignError, isWalletSubmitError, RegistryApiError, RegistryResponseError, WalletError, WalletOptionError, WalletReadError, WalletSignError, WalletSubmitError, type WalletErrorCode, type WalletErrorDescription, type WalletOptionErrorCode, type WalletSignErrorReason, type WalletSubmitCategory, type WalletSubmitErrorDetails, type WalletSubmitOutcome, } from './errors';
|
|
49
52
|
export { coveringPreapproval, type BurnRequest, type MintOffer, type PreapprovalScope, type TransferOffer, type TransferOfferRegistry, type TransferPreapproval, } from './contracts';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/wallets/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/wallets/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,EACL,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,eAAe,GACrB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,qBAAqB,EACrB,0BAA0B,EAC1B,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,gBAAgB,EAChB,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,eAAe,GACrB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,gBAAgB,EAAE,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,MAAM,QAAQ,CAAC;AAC/G,OAAO,EACL,sBAAsB,EACtB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,gBAAgB,GACtB,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,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K,kBAAkB,EACvB,KAAK,0BAA0B,GAChC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EACL,YAAY,EACZ,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,GACxB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EACL,uBAAuB,EACvB,eAAe,EACf,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,mBAAmB,GACzB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.parseDecimalUnits = exports.formatDecimalUnits = exports.readHoldingView = exports.HOLDING_V1_INTERFACE_ID = exports.CANTON_COIN_METADATA = exports.AMULET_TEMPLATES = exports.AMULET_REGISTRY_BASE_URLS = exports.AMULET_INSTRUMENT_ID = void 0;
|
|
3
|
+
exports.readSignature = exports.shortCantonId = exports.OFFER_EXPIRY_SOON_MS = exports.formatTokenAmount = exports.formatOfferExpiry = exports.describePreapprovalScope = exports.walletTokens = exports.selectWalletToken = exports.expiredUnclaimedLocks = exports.isTransferOfferExpired = exports.coveringPreapproval = exports.WalletSubmitError = exports.WalletSignError = exports.WalletReadError = exports.WalletOptionError = exports.WalletError = exports.RegistryResponseError = exports.RegistryApiError = exports.isWalletSubmitError = exports.isWalletSignError = exports.isWalletReadError = exports.isWalletOptionError = exports.isWalletError = exports.isWalletCancellation = exports.isRegistryResponseError = exports.isRegistryApiError = exports.describeWalletError = exports.DA_REGISTRY_REQUEST_TIMEOUT_MS = exports.WALLET_PROOF_MAX_MESSAGE_LENGTH = exports.WALLET_PROOF_MAX_MESSAGE_BYTES = exports.WALLET_PROOF_FORMAT = exports.parseWalletProofMessage = exports.buildWalletProofMessage = exports.requestWalletOwnershipVerdict = exports.proveWalletProof = exports.proveWalletOwnership = exports.buildWalletOwnershipMessage = exports.INJECTED_WALLET_ID = exports.discoverCip103Wallets = exports.createWallet = exports.walletActionKey = exports.createWalletStore = exports.canAct = exports.actionState = exports.extensionWalletOptions = exports.loopWalletOption = exports.createWriteLatch = exports.DEFAULT_RESTORE_TIMEOUT_MS = exports.createWalletConnector = exports.createCip103Session = void 0;
|
|
4
|
+
exports.parseDecimalUnits = exports.formatDecimalUnits = exports.readHoldingView = exports.HOLDING_V1_INTERFACE_ID = exports.CANTON_COIN_METADATA = exports.AMULET_TEMPLATES = exports.AMULET_REGISTRY_BASE_URLS = exports.AMULET_INSTRUMENT_ID = exports.isCantonCoin = exports.withTimeout = exports.MAX_TIMER_MS = exports.validateSignMessage = exports.SIGN_MESSAGE_MIN_BYTES = exports.SIGN_MESSAGE_MAX_BYTES = void 0;
|
|
5
5
|
/**
|
|
6
6
|
* Browser-safe DA Utility Registry holder actions through any CIP-0103 (Canton dApp API) wallet provider. In a browser
|
|
7
7
|
* bundle import `@fairmint/canton-node-sdk/wallets`, which loads none of the SDK's Node dependencies (the deep path
|
|
@@ -27,7 +27,9 @@ exports.parseDecimalUnits = exports.formatDecimalUnits = exports.readHoldingView
|
|
|
27
27
|
* (`InstrumentBalance.lockedInExpiredLocks`), and the `reclaimLockedTokens` action that unlocks both
|
|
28
28
|
* (`WalletToken.canReclaim` says when it applies).
|
|
29
29
|
* - The ownership proof's browser half (`requestWalletOwnershipVerdict`); the server half
|
|
30
|
-
* (`createWalletOwnershipChallenger`, `verifyWalletOwnership`) is Node-only and exported from the package root.
|
|
30
|
+
* (`createWalletOwnershipChallenger`, `verifyWalletOwnership`) is Node-only and exported from the package root. The
|
|
31
|
+
* compact wallet proof message (`buildWalletProofMessage`, `parseWalletProofMessage`, `proveWalletProof`; verified by
|
|
32
|
+
* `verifyWalletProof` at the package root) is apiv2's CNTN tokenization wallet proof format.
|
|
31
33
|
* - The errors, their guards (`isWalletError`, `isWalletSubmitError`, …: they match errors of any copy of this module,
|
|
32
34
|
* where `instanceof` does not), their user-facing descriptions (`describeWalletError`), and the data types.
|
|
33
35
|
* - Display helpers that return codes, not sentences: `selectWalletToken`, `formatTokenAmount`, `formatOfferExpiry`,
|
|
@@ -61,7 +63,14 @@ Object.defineProperty(exports, "INJECTED_WALLET_ID", { enumerable: true, get: fu
|
|
|
61
63
|
var ownership_1 = require("./ownership");
|
|
62
64
|
Object.defineProperty(exports, "buildWalletOwnershipMessage", { enumerable: true, get: function () { return ownership_1.buildWalletOwnershipMessage; } });
|
|
63
65
|
Object.defineProperty(exports, "proveWalletOwnership", { enumerable: true, get: function () { return ownership_1.proveWalletOwnership; } });
|
|
66
|
+
Object.defineProperty(exports, "proveWalletProof", { enumerable: true, get: function () { return ownership_1.proveWalletProof; } });
|
|
64
67
|
Object.defineProperty(exports, "requestWalletOwnershipVerdict", { enumerable: true, get: function () { return ownership_1.requestWalletOwnershipVerdict; } });
|
|
68
|
+
var wallet_proof_1 = require("./wallet-proof");
|
|
69
|
+
Object.defineProperty(exports, "buildWalletProofMessage", { enumerable: true, get: function () { return wallet_proof_1.buildWalletProofMessage; } });
|
|
70
|
+
Object.defineProperty(exports, "parseWalletProofMessage", { enumerable: true, get: function () { return wallet_proof_1.parseWalletProofMessage; } });
|
|
71
|
+
Object.defineProperty(exports, "WALLET_PROOF_FORMAT", { enumerable: true, get: function () { return wallet_proof_1.WALLET_PROOF_FORMAT; } });
|
|
72
|
+
Object.defineProperty(exports, "WALLET_PROOF_MAX_MESSAGE_BYTES", { enumerable: true, get: function () { return wallet_proof_1.WALLET_PROOF_MAX_MESSAGE_BYTES; } });
|
|
73
|
+
Object.defineProperty(exports, "WALLET_PROOF_MAX_MESSAGE_LENGTH", { enumerable: true, get: function () { return wallet_proof_1.WALLET_PROOF_MAX_MESSAGE_LENGTH; } });
|
|
65
74
|
var client_1 = require("./da-utilities/client");
|
|
66
75
|
Object.defineProperty(exports, "DA_REGISTRY_REQUEST_TIMEOUT_MS", { enumerable: true, get: function () { return client_1.DA_REGISTRY_REQUEST_TIMEOUT_MS; } });
|
|
67
76
|
var errors_1 = require("./errors");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/wallets/index.ts"],"names":[],"mappings":";;;;AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/wallets/index.ts"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,qCAMmB;AALjB,8GAAA,mBAAmB,OAAA;AAMrB,yCAWqB;AAVnB,kHAAA,qBAAqB,OAAA;AACrB,uHAAA,0BAA0B,OAAA;AAU5B,iCAOiB;AANf,yGAAA,gBAAgB,OAAA;AAOlB,+BAA+G;AAAtG,wGAAA,gBAAgB,OAAA;AACzB,qCAOmB;AANjB,iHAAA,sBAAsB,OAAA;AAQxB,iCAiBiB;AAhBf,oGAAA,WAAW,OAAA;AACX,+FAAA,MAAM,OAAA;AACN,0GAAA,iBAAiB,OAAA;AACjB,wGAAA,eAAe,OAAA;AAcjB,mCAiBkB;AAhBhB,sGAAA,YAAY,OAAA;AAkBd,yCAMqB;AALnB,kHAAA,qBAAqB,OAAA;AACrB,+GAAA,kBAAkB,OAAA;AAKpB,yCAeqB;AAdnB,wHAAA,2BAA2B,OAAA;AAC3B,iHAAA,oBAAoB,OAAA;AACpB,6GAAA,gBAAgB,OAAA;AAChB,0HAAA,6BAA6B,OAAA;AAY/B,+CASwB;AARtB,uHAAA,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OAAA;AACzB,6GAAA,gBAAgB,OAAA;AAChB,iHAAA,oBAAoB,OAAA;AAGtB,+CAMwB;AALtB,uHAAA,uBAAuB,OAAA;AACvB,+GAAA,eAAe,OAAA;AAMjB,qCAAkE;AAAzD,6GAAA,kBAAkB,OAAA;AAAE,4GAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Field rules shared by the text ownership message (`./ownership`) and the wallet proof message (`./wallet-proof`). */
|
|
2
|
+
/** Whether `value` may be a message's party: a Canton party id (`hint::namespace`) of printable ASCII. */
|
|
3
|
+
export declare function isWalletOwnershipPartyId(value: unknown): value is string;
|
|
4
|
+
//# sourceMappingURL=ownership-fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ownership-fields.d.ts","sourceRoot":"","sources":["../../../src/wallets/ownership-fields.ts"],"names":[],"mappings":"AAAA,wHAAwH;AAKxH,0GAA0G;AAC1G,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAIxE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Field rules shared by the text ownership message (`./ownership`) and the wallet proof message (`./wallet-proof`). */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.isWalletOwnershipPartyId = isWalletOwnershipPartyId;
|
|
5
|
+
/** Printable ASCII without spaces. */
|
|
6
|
+
const TOKEN_PATTERN = /^[!-~]+$/;
|
|
7
|
+
/** Whether `value` may be a message's party: a Canton party id (`hint::namespace`) of printable ASCII. */
|
|
8
|
+
function isWalletOwnershipPartyId(value) {
|
|
9
|
+
return (typeof value === 'string' && value.length <= 512 && TOKEN_PATTERN.test(value) && value.split('::').length === 2);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=ownership-fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ownership-fields.js","sourceRoot":"","sources":["../../../src/wallets/ownership-fields.ts"],"names":[],"mappings":";AAAA,wHAAwH;;;AAExH,sCAAsC;AACtC,MAAM,aAAa,GAAG,UAAU,CAAC;AAEjC,0GAA0G;AAC1G,kCAAyC,KAAc;IACrD,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAChH,CAAC;AACJ,CAAC"}
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { type Cip103Connection } from './cip103';
|
|
18
18
|
import { type FetchLike } from './da-utilities/client';
|
|
19
|
+
import { isWalletOwnershipPartyId } from './ownership-fields';
|
|
20
|
+
import { type WalletProofFields } from './wallet-proof';
|
|
19
21
|
/** The first line of every ownership message. */
|
|
20
22
|
export declare const WALLET_OWNERSHIP_TITLE = "Canton wallet ownership proof";
|
|
21
23
|
/** The message format version, its `Version:` line. */
|
|
@@ -52,8 +54,7 @@ export interface WalletOwnershipProof {
|
|
|
52
54
|
}
|
|
53
55
|
/** Whether `value` may be a message's domain: a host name, optionally with a port. */
|
|
54
56
|
export declare function isWalletOwnershipDomain(value: unknown): value is string;
|
|
55
|
-
|
|
56
|
-
export declare function isWalletOwnershipPartyId(value: unknown): value is string;
|
|
57
|
+
export { isWalletOwnershipPartyId };
|
|
57
58
|
/**
|
|
58
59
|
* The canonical message for these fields. Throws `TypeError` on a field that is not valid. The same fields always give
|
|
59
60
|
* the same text, so the server rebuilds it from the fields it parses and refuses anything else.
|
|
@@ -84,15 +85,39 @@ export interface ProveWalletOwnershipOptions {
|
|
|
84
85
|
* verified it (`verifyWalletOwnership`).
|
|
85
86
|
*/
|
|
86
87
|
export declare function proveWalletOwnership(connection: Cip103Connection, options: ProveWalletOwnershipOptions): Promise<WalletOwnershipProof>;
|
|
88
|
+
export interface ProveWalletProofOptions {
|
|
89
|
+
/** The exact wallet proof message to sign (`buildWalletProofMessage`), as the server built it. */
|
|
90
|
+
readonly message: string;
|
|
91
|
+
/** The fields the server sent with the message, when it did: they must be exactly the message's. */
|
|
92
|
+
readonly fields?: WalletProofFields;
|
|
93
|
+
/** Defaults to the system clock; an expired message is refused before anything is signed. */
|
|
94
|
+
readonly now?: () => Date;
|
|
95
|
+
/** As in {@link ProveWalletOwnershipOptions.signal}. */
|
|
96
|
+
readonly signal?: AbortSignal;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Ask the wallet to sign a server-built wallet proof message (`wallet-proof-v1`, see `buildWalletProofMessage`) as the
|
|
100
|
+
* connection's party. Before anything is signed, the message must parse as a wallet proof (`parseWalletProofMessage`)
|
|
101
|
+
* naming the connection's party and network, match `fields` when given, and not have expired; the wallet's primary
|
|
102
|
+
* account must be the connection's party, on its network. The wallet signs exactly `message`. Returns `{ partyId,
|
|
103
|
+
* publicKey, message, signature }` (and `namespace` when the wallet reported it), which a page may show for copying; it
|
|
104
|
+
* proves nothing until the server verified it (`verifyWalletProof`). The key and signature are standard base64 whatever
|
|
105
|
+
* the wallet returned (hex or base64), so the proof verifies with servers that decode base64 only.
|
|
106
|
+
*/
|
|
107
|
+
export declare function proveWalletProof(connection: Cip103Connection, options: ProveWalletProofOptions): Promise<WalletOwnershipProof>;
|
|
87
108
|
/** Why a proof did not verify (`verifyWalletOwnership`, Node only). */
|
|
88
109
|
export type WalletOwnershipFailure =
|
|
89
110
|
/** The proof is not an object of string fields. */
|
|
90
111
|
'malformed-proof'
|
|
91
|
-
/** The message is not exactly a canonical ownership message. */
|
|
112
|
+
/** The message is not exactly a canonical ownership message (or wallet proof message, for `verifyWalletProof`). */
|
|
92
113
|
| 'malformed-message' | 'domain-mismatch' | 'nonce-mismatch'
|
|
93
114
|
/** The message, the proof and the expected party do not all name the same party, or the namespace differs. */
|
|
94
115
|
| 'party-mismatch' | 'network-mismatch'
|
|
95
|
-
/**
|
|
116
|
+
/** A wallet proof message (`verifyWalletProof`) names another `investorContext` than expected. */
|
|
117
|
+
| 'investor-context-mismatch'
|
|
118
|
+
/** A wallet proof message (`verifyWalletProof`) names another `idempotencyKey` than expected. */
|
|
119
|
+
| 'idempotency-key-mismatch'
|
|
120
|
+
/** The message's issue or expiry time is not the one the server issued. */
|
|
96
121
|
| 'window-mismatch'
|
|
97
122
|
/** Issued in the future (beyond the allowed clock skew). */
|
|
98
123
|
| 'not-yet-valid'
|
|
@@ -116,7 +141,10 @@ export type WalletOwnershipChallengeFailure =
|
|
|
116
141
|
| 'challenge-used'
|
|
117
142
|
/** Issued to another subject (signed-in user) or for another host. */
|
|
118
143
|
| 'challenge-not-yours';
|
|
119
|
-
/**
|
|
144
|
+
/**
|
|
145
|
+
* A challenger's answer to a challenge request in the default text format: what the wallet signs, and the token to send
|
|
146
|
+
* back with the proof. The `wallet-proof-v1` format answers `WalletProofChallengeResponse` instead.
|
|
147
|
+
*/
|
|
120
148
|
export interface WalletOwnershipChallengeResponse {
|
|
121
149
|
readonly challenge: WalletOwnershipChallenge;
|
|
122
150
|
/** Opaque to the browser: the server's MACed record of the challenge. */
|
|
@@ -140,10 +168,18 @@ export type WalletOwnershipVerdict = {
|
|
|
140
168
|
export interface RequestWalletOwnershipVerdictOptions {
|
|
141
169
|
/** Sends the requests; defaults to the global `fetch` (same-origin requests carry the user's session cookie). */
|
|
142
170
|
readonly fetch?: FetchLike;
|
|
143
|
-
/**
|
|
171
|
+
/**
|
|
172
|
+
* Answers `POST { network, partyId }` with `{ data: WalletOwnershipChallengeResponse }` (the text message) or `{
|
|
173
|
+
* data: WalletProofChallengeResponse }` (`format: 'wallet-proof-v1'`, a server-built message); the server picks.
|
|
174
|
+
*/
|
|
144
175
|
readonly challengeUrl: string;
|
|
145
176
|
/** Answers `POST { token, proof }` with `{ data: WalletOwnershipVerdict }`. */
|
|
146
177
|
readonly verifyUrl: string;
|
|
178
|
+
/**
|
|
179
|
+
* Called with the signed proof (`{ partyId, publicKey, message, signature }`) before it is sent to `verifyUrl`, for a
|
|
180
|
+
* page that shows it. Not called when the wallet did not sign.
|
|
181
|
+
*/
|
|
182
|
+
readonly onProof?: (proof: WalletOwnershipProof) => void;
|
|
147
183
|
/**
|
|
148
184
|
* Cancels the check (for example when the user leaves the page): once aborted, the call rejects with an `AbortError`,
|
|
149
185
|
* the requests in flight get the signal, and nothing more is sent. A signature request already shown to the user is
|
|
@@ -154,7 +190,8 @@ export interface RequestWalletOwnershipVerdictOptions {
|
|
|
154
190
|
/**
|
|
155
191
|
* The browser half of an ownership check, against a server that uses the SDK's challenger (or the same wire format: a
|
|
156
192
|
* 2xx answer is `{ data }`, any other `{ error: string }`): POST `challengeUrl` with the connection's `{ network,
|
|
157
|
-
* partyId }`, have the wallet sign the challenge (`proveWalletOwnership`
|
|
193
|
+
* partyId }`, have the wallet sign the challenge (`proveWalletOwnership` for the text message, `proveWalletProof` for a
|
|
194
|
+
* `wallet-proof-v1` challenge, whose server-built message it signs exactly), POST `verifyUrl` with `{ token, proof }`,
|
|
158
195
|
* and return the server's verdict. Throws when no verdict was reached: the server refused (a non-2xx answer, or one
|
|
159
196
|
* without `data`), or the wallet did not sign (`WalletSignError`).
|
|
160
197
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ownership.d.ts","sourceRoot":"","sources":["../../../src/wallets/ownership.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"ownership.d.ts","sourceRoot":"","sources":["../../../src/wallets/ownership.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAQL,KAAK,gBAAgB,EACtB,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAKpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAIL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CACjD,UAAU,EAAE,gBAAgB,EAC5B,OAAO,EAAE,oCAAoC,GAC5C,OAAO,CAAC,sBAAsB,CAAC,CA0CjC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WALLET_OWNERSHIP_VERSION = exports.WALLET_OWNERSHIP_TITLE = void 0;
|
|
3
|
+
exports.isWalletOwnershipPartyId = exports.WALLET_OWNERSHIP_VERSION = exports.WALLET_OWNERSHIP_TITLE = void 0;
|
|
4
4
|
exports.isWalletOwnershipDomain = isWalletOwnershipDomain;
|
|
5
|
-
exports.isWalletOwnershipPartyId = isWalletOwnershipPartyId;
|
|
6
5
|
exports.buildWalletOwnershipMessage = buildWalletOwnershipMessage;
|
|
7
6
|
exports.parseWalletOwnershipMessage = parseWalletOwnershipMessage;
|
|
8
7
|
exports.proveWalletOwnership = proveWalletOwnership;
|
|
8
|
+
exports.proveWalletProof = proveWalletProof;
|
|
9
9
|
exports.requestWalletOwnershipVerdict = requestWalletOwnershipVerdict;
|
|
10
10
|
/**
|
|
11
11
|
* Proof that the user controls a wallet's party, not just its party id: the wallet signs a canonical, human-readable
|
|
@@ -29,7 +29,11 @@ const abort_2 = require("../core/http/abort");
|
|
|
29
29
|
const client_1 = require("./da-utilities/client");
|
|
30
30
|
const errors_1 = require("./errors");
|
|
31
31
|
const json_1 = require("./json");
|
|
32
|
+
const proof_encoding_1 = require("./proof-encoding");
|
|
32
33
|
const sign_message_1 = require("./sign-message");
|
|
34
|
+
const ownership_fields_1 = require("./ownership-fields");
|
|
35
|
+
Object.defineProperty(exports, "isWalletOwnershipPartyId", { enumerable: true, get: function () { return ownership_fields_1.isWalletOwnershipPartyId; } });
|
|
36
|
+
const wallet_proof_1 = require("./wallet-proof");
|
|
33
37
|
/** The first line of every ownership message. */
|
|
34
38
|
exports.WALLET_OWNERSHIP_TITLE = 'Canton wallet ownership proof';
|
|
35
39
|
/** The message format version, its `Version:` line. */
|
|
@@ -43,10 +47,6 @@ const ISO_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
|
43
47
|
function isWalletOwnershipDomain(value) {
|
|
44
48
|
return typeof value === 'string' && DOMAIN_PATTERN.test(value);
|
|
45
49
|
}
|
|
46
|
-
/** Whether `value` may be a message's party: a Canton party id (`hint::namespace`) of printable ASCII. */
|
|
47
|
-
function isWalletOwnershipPartyId(value) {
|
|
48
|
-
return (typeof value === 'string' && value.length <= 512 && TOKEN_PATTERN.test(value) && value.split('::').length === 2);
|
|
49
|
-
}
|
|
50
50
|
/** The reason a field is not valid in a message, or null. */
|
|
51
51
|
function fieldProblem(fields) {
|
|
52
52
|
if (!isWalletOwnershipDomain(fields.domain)) {
|
|
@@ -55,7 +55,7 @@ function fieldProblem(fields) {
|
|
|
55
55
|
if (typeof fields.nonce !== 'string' || !NONCE_PATTERN.test(fields.nonce)) {
|
|
56
56
|
return 'nonce must be 16-512 characters of letters, digits and . _ ~ -';
|
|
57
57
|
}
|
|
58
|
-
if (!isWalletOwnershipPartyId(fields.partyId)) {
|
|
58
|
+
if (!(0, ownership_fields_1.isWalletOwnershipPartyId)(fields.partyId)) {
|
|
59
59
|
return 'partyId must be a Canton party id (hint::namespace)';
|
|
60
60
|
}
|
|
61
61
|
if (fields.network !== undefined &&
|
|
@@ -147,15 +147,9 @@ function parseWalletOwnershipMessage(message) {
|
|
|
147
147
|
return null;
|
|
148
148
|
return buildWalletOwnershipMessage(fields) === message ? fields : null;
|
|
149
149
|
}
|
|
150
|
-
/**
|
|
151
|
-
|
|
152
|
-
* the primary account, so another primary account, or a wallet or challenge on the other DA network, is refused before
|
|
153
|
-
* anything is signed. Returns what the server needs to verify; it is not itself proof of anything until the server
|
|
154
|
-
* verified it (`verifyWalletOwnership`).
|
|
155
|
-
*/
|
|
156
|
-
async function proveWalletOwnership(connection, options) {
|
|
150
|
+
/** The connection's primary account, after the checks every proof makes before anything is signed. */
|
|
151
|
+
async function signingAccount(connection, signal) {
|
|
157
152
|
const { provider, partyId, network } = connection;
|
|
158
|
-
const { challenge, signal } = options;
|
|
159
153
|
(0, abort_1.throwIfAborted)(signal);
|
|
160
154
|
const account = await (0, abort_1.awaitWithAbort)(async () => (0, cip103_1.primaryAccount)(provider, { signal }), signal);
|
|
161
155
|
if (account.partyId !== partyId) {
|
|
@@ -165,30 +159,23 @@ async function proveWalletOwnership(connection, options) {
|
|
|
165
159
|
if (account.networkId !== undefined && (0, cip103_1.reportsOtherNetwork)(account.networkId, network)) {
|
|
166
160
|
throw new errors_1.WalletSignError('invalid-challenge', `The wallet is on ${account.networkId}, not ${(0, cip103_1.cip103NetworkId)(network)}; switch networks in the wallet first`);
|
|
167
161
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
162
|
+
return account;
|
|
163
|
+
}
|
|
164
|
+
/** The account's public key; throws when the wallet did not report one. */
|
|
165
|
+
function requirePublicKey(account) {
|
|
171
166
|
if (account.publicKey === undefined) {
|
|
172
167
|
throw new errors_1.WalletReadError('The wallet returned a primary account without publicKey, so ownership cannot be proven');
|
|
173
168
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
issuedAt: challenge.issuedAt,
|
|
181
|
-
expiresAt: challenge.expiresAt,
|
|
182
|
-
...(challenge.network !== undefined && { network: challenge.network }),
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
catch (error) {
|
|
186
|
-
throw new errors_1.WalletSignError('invalid-challenge', error instanceof Error ? error.message : String(error));
|
|
187
|
-
}
|
|
188
|
-
const now = (options.now ?? (() => new Date()))().getTime();
|
|
189
|
-
if (!(now < Date.parse(challenge.expiresAt))) {
|
|
190
|
-
throw new errors_1.WalletSignError('invalid-challenge', 'The ownership challenge has expired; ask the server for a new one');
|
|
169
|
+
return account.publicKey;
|
|
170
|
+
}
|
|
171
|
+
/** Refuses an expired message before anything is signed. */
|
|
172
|
+
function requireUnexpired(expiresAt, now, what) {
|
|
173
|
+
if (!((now ?? (() => new Date()))().getTime() < Date.parse(expiresAt))) {
|
|
174
|
+
throw new errors_1.WalletSignError('invalid-challenge', `The ${what} has expired; ask the server for a new one`);
|
|
191
175
|
}
|
|
176
|
+
}
|
|
177
|
+
/** Have the wallet sign exactly `message` (CIP-0103 `signMessage`); the signature as the wallet returned it. */
|
|
178
|
+
async function signText(provider, message, signal, what) {
|
|
192
179
|
(0, abort_1.throwIfAborted)(signal);
|
|
193
180
|
let raw;
|
|
194
181
|
try {
|
|
@@ -199,22 +186,104 @@ async function proveWalletOwnership(connection, options) {
|
|
|
199
186
|
throw error;
|
|
200
187
|
const code = (0, cip103_1.cip103ErrorCode)(error);
|
|
201
188
|
if (code === cip103_1.CIP103_ERROR_CODES.userRejected) {
|
|
202
|
-
throw new errors_1.WalletSignError('rejected-by-user', `The user declined to sign the
|
|
189
|
+
throw new errors_1.WalletSignError('rejected-by-user', `The user declined to sign the ${what}: ${(0, cip103_1.describeError)(error)}`, code);
|
|
203
190
|
}
|
|
204
|
-
throw new errors_1.WalletSignError('failed', `The wallet did not sign the
|
|
191
|
+
throw new errors_1.WalletSignError('failed', `The wallet did not sign the ${what}: ${(0, cip103_1.describeError)(error)}`, code);
|
|
205
192
|
}
|
|
206
193
|
const signature = (0, sign_message_1.readSpecSignature)(raw);
|
|
207
194
|
if (signature === undefined) {
|
|
208
195
|
throw new errors_1.WalletSignError('failed', 'The wallet answered signMessage without a signature');
|
|
209
196
|
}
|
|
197
|
+
return signature;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Ask the wallet to sign the ownership message for the challenge, as the connection's party. CIP-0103 wallets sign with
|
|
201
|
+
* the primary account, so another primary account, or a wallet or challenge on the other DA network, is refused before
|
|
202
|
+
* anything is signed. Returns what the server needs to verify; it is not itself proof of anything until the server
|
|
203
|
+
* verified it (`verifyWalletOwnership`).
|
|
204
|
+
*/
|
|
205
|
+
async function proveWalletOwnership(connection, options) {
|
|
206
|
+
const { network } = connection;
|
|
207
|
+
const { challenge, signal } = options;
|
|
208
|
+
const account = await signingAccount(connection, signal);
|
|
209
|
+
if (challenge.network !== undefined && (0, cip103_1.reportsOtherNetwork)(challenge.network, network)) {
|
|
210
|
+
throw new errors_1.WalletSignError('invalid-challenge', `The challenge is for ${challenge.network}, not ${(0, cip103_1.cip103NetworkId)(network)}`);
|
|
211
|
+
}
|
|
212
|
+
const publicKey = requirePublicKey(account);
|
|
213
|
+
let message;
|
|
214
|
+
try {
|
|
215
|
+
message = buildWalletOwnershipMessage({
|
|
216
|
+
domain: challenge.domain,
|
|
217
|
+
partyId: account.partyId,
|
|
218
|
+
nonce: challenge.nonce,
|
|
219
|
+
issuedAt: challenge.issuedAt,
|
|
220
|
+
expiresAt: challenge.expiresAt,
|
|
221
|
+
...(challenge.network !== undefined && { network: challenge.network }),
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
throw new errors_1.WalletSignError('invalid-challenge', error instanceof Error ? error.message : String(error));
|
|
226
|
+
}
|
|
227
|
+
requireUnexpired(challenge.expiresAt, options.now, 'ownership challenge');
|
|
228
|
+
const signature = await signText(connection.provider, message, signal, 'ownership message');
|
|
210
229
|
return {
|
|
211
230
|
partyId: account.partyId,
|
|
212
|
-
publicKey
|
|
231
|
+
publicKey,
|
|
213
232
|
...(account.namespace !== undefined && { namespace: account.namespace }),
|
|
214
233
|
message,
|
|
215
234
|
signature,
|
|
216
235
|
};
|
|
217
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Ask the wallet to sign a server-built wallet proof message (`wallet-proof-v1`, see `buildWalletProofMessage`) as the
|
|
239
|
+
* connection's party. Before anything is signed, the message must parse as a wallet proof (`parseWalletProofMessage`)
|
|
240
|
+
* naming the connection's party and network, match `fields` when given, and not have expired; the wallet's primary
|
|
241
|
+
* account must be the connection's party, on its network. The wallet signs exactly `message`. Returns `{ partyId,
|
|
242
|
+
* publicKey, message, signature }` (and `namespace` when the wallet reported it), which a page may show for copying; it
|
|
243
|
+
* proves nothing until the server verified it (`verifyWalletProof`). The key and signature are standard base64 whatever
|
|
244
|
+
* the wallet returned (hex or base64), so the proof verifies with servers that decode base64 only.
|
|
245
|
+
*/
|
|
246
|
+
async function proveWalletProof(connection, options) {
|
|
247
|
+
const { partyId, network } = connection;
|
|
248
|
+
const { message, signal } = options;
|
|
249
|
+
(0, abort_1.throwIfAborted)(signal);
|
|
250
|
+
const parsed = (0, wallet_proof_1.parseWalletProofMessage)(message);
|
|
251
|
+
if (parsed === null) {
|
|
252
|
+
throw new errors_1.WalletSignError('invalid-challenge', 'The server sent a message that is not a wallet proof message');
|
|
253
|
+
}
|
|
254
|
+
if (parsed.partyId !== partyId) {
|
|
255
|
+
throw new errors_1.WalletSignError('invalid-challenge', `The wallet proof message names ${parsed.partyId}, not ${partyId}`);
|
|
256
|
+
}
|
|
257
|
+
if (parsed.network !== network) {
|
|
258
|
+
throw new errors_1.WalletSignError('invalid-challenge', `The wallet proof message is for ${parsed.network}, not ${network}`);
|
|
259
|
+
}
|
|
260
|
+
const { fields } = options;
|
|
261
|
+
if (fields !== undefined && !sameWalletProofFields(fields, message)) {
|
|
262
|
+
throw new errors_1.WalletSignError('invalid-challenge', 'The fields the server sent are not the message it asks to sign');
|
|
263
|
+
}
|
|
264
|
+
const account = await signingAccount(connection, signal);
|
|
265
|
+
const publicKey = requirePublicKey(account);
|
|
266
|
+
requireUnexpired(parsed.expiresAt, options.now, 'wallet proof message');
|
|
267
|
+
const signature = await signText(connection.provider, message, signal, 'wallet proof message');
|
|
268
|
+
return {
|
|
269
|
+
partyId: account.partyId,
|
|
270
|
+
publicKey: (0, proof_encoding_1.publicKeyToBase64)(publicKey),
|
|
271
|
+
...(account.namespace !== undefined && { namespace: account.namespace }),
|
|
272
|
+
message,
|
|
273
|
+
signature: (0, proof_encoding_1.signatureToBase64)(signature),
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
/** Whether `given` holds exactly the fields of `message` (keys beyond the message's are ignored). */
|
|
277
|
+
function sameWalletProofFields(given, message) {
|
|
278
|
+
if (!(0, json_1.isRecord)(given))
|
|
279
|
+
return false;
|
|
280
|
+
try {
|
|
281
|
+
return (0, wallet_proof_1.buildWalletProofMessage)(given) === message;
|
|
282
|
+
}
|
|
283
|
+
catch {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
218
287
|
/** Whether `value` is a whole verdict: a verified one names `partyId`, a refused one gives its reason and message. */
|
|
219
288
|
function isWalletOwnershipVerdict(value, partyId) {
|
|
220
289
|
if (!(0, json_1.isRecord)(value))
|
|
@@ -260,7 +329,8 @@ carriesProof) {
|
|
|
260
329
|
/**
|
|
261
330
|
* The browser half of an ownership check, against a server that uses the SDK's challenger (or the same wire format: a
|
|
262
331
|
* 2xx answer is `{ data }`, any other `{ error: string }`): POST `challengeUrl` with the connection's `{ network,
|
|
263
|
-
* partyId }`, have the wallet sign the challenge (`proveWalletOwnership`
|
|
332
|
+
* partyId }`, have the wallet sign the challenge (`proveWalletOwnership` for the text message, `proveWalletProof` for a
|
|
333
|
+
* `wallet-proof-v1` challenge, whose server-built message it signs exactly), POST `verifyUrl` with `{ token, proof }`,
|
|
264
334
|
* and return the server's verdict. Throws when no verdict was reached: the server refused (a non-2xx answer, or one
|
|
265
335
|
* without `data`), or the wallet did not sign (`WalletSignError`).
|
|
266
336
|
*/
|
|
@@ -270,16 +340,36 @@ async function requestWalletOwnershipVerdict(connection, options) {
|
|
|
270
340
|
const { signal } = options;
|
|
271
341
|
(0, abort_1.throwIfAborted)(signal);
|
|
272
342
|
const issued = await postForData(send, options.challengeUrl, { network, partyId }, signal, false);
|
|
273
|
-
|
|
274
|
-
|
|
343
|
+
let proof;
|
|
344
|
+
let token;
|
|
345
|
+
if ((0, json_1.isRecord)(issued) && issued['format'] === wallet_proof_1.WALLET_PROOF_FORMAT) {
|
|
346
|
+
const { message, fields, token: issuedToken } = issued;
|
|
347
|
+
if (typeof message !== 'string' || !(0, json_1.isRecord)(fields) || typeof issuedToken !== 'string') {
|
|
348
|
+
throw new Error('The server answered the wallet proof challenge request without { message, fields, token }');
|
|
349
|
+
}
|
|
350
|
+
token = issuedToken;
|
|
351
|
+
// proveWalletProof checks the message names this party and network, and matches the fields, before signing.
|
|
352
|
+
proof = await proveWalletProof(connection, {
|
|
353
|
+
message,
|
|
354
|
+
fields: fields,
|
|
355
|
+
...(signal !== undefined && { signal }),
|
|
356
|
+
});
|
|
275
357
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
358
|
+
else {
|
|
359
|
+
const { format, challenge: issuedChallenge, token: issuedToken } = (0, json_1.isRecord)(issued) ? issued : {};
|
|
360
|
+
if (format !== undefined || !(0, json_1.isRecord)(issuedChallenge) || typeof issuedToken !== 'string') {
|
|
361
|
+
throw new Error('The server answered the ownership challenge request without { challenge, token }');
|
|
362
|
+
}
|
|
363
|
+
token = issuedToken;
|
|
364
|
+
// proveWalletOwnership checks every field before anything is signed.
|
|
365
|
+
const challenge = issuedChallenge;
|
|
366
|
+
if (challenge.network !== (0, cip103_1.cip103NetworkId)(network)) {
|
|
367
|
+
throw new errors_1.WalletSignError('invalid-challenge', `The server issued a challenge for ${String(challenge.network)}, not ${(0, cip103_1.cip103NetworkId)(network)}`);
|
|
368
|
+
}
|
|
369
|
+
proof = await proveWalletOwnership(connection, { challenge, ...(signal !== undefined && { signal }) });
|
|
280
370
|
}
|
|
281
|
-
|
|
282
|
-
const verdict = await postForData(send, options.verifyUrl, { token
|
|
371
|
+
options.onProof?.(proof);
|
|
372
|
+
const verdict = await postForData(send, options.verifyUrl, { token, proof }, signal, true);
|
|
283
373
|
if (!isWalletOwnershipVerdict(verdict, partyId)) {
|
|
284
374
|
throw new Error('The server answered the ownership proof without a well-formed verdict for the party');
|
|
285
375
|
}
|