@fairmint/canton-node-sdk 0.0.278 → 0.0.280
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 +147 -23
- 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 +93 -0
- package/build/src/utils/external-signing/wallet-ownership-challenger.d.ts.map +1 -0
- package/build/src/utils/external-signing/wallet-ownership-challenger.js +253 -0
- package/build/src/utils/external-signing/wallet-ownership-challenger.js.map +1 -0
- package/build/src/utils/external-signing/wallet-ownership.d.ts +3 -24
- package/build/src/utils/external-signing/wallet-ownership.d.ts.map +1 -1
- package/build/src/utils/external-signing/wallet-ownership.js.map +1 -1
- package/build/src/wallets/cip103.d.ts +17 -1
- package/build/src/wallets/cip103.d.ts.map +1 -1
- package/build/src/wallets/cip103.js +8 -0
- package/build/src/wallets/cip103.js.map +1 -1
- package/build/src/wallets/{token-standard-wallet.d.ts → cip56-core.d.ts} +66 -37
- package/build/src/wallets/cip56-core.d.ts.map +1 -0
- package/build/src/wallets/{token-standard-wallet.js → cip56-core.js} +85 -29
- package/build/src/wallets/cip56-core.js.map +1 -0
- package/build/src/wallets/da-utilities/client.d.ts +7 -0
- package/build/src/wallets/da-utilities/client.d.ts.map +1 -1
- package/build/src/wallets/da-utilities/client.js +21 -0
- package/build/src/wallets/da-utilities/client.js.map +1 -1
- package/build/src/wallets/errors.d.ts +43 -5
- package/build/src/wallets/errors.d.ts.map +1 -1
- package/build/src/wallets/errors.js +57 -4
- package/build/src/wallets/errors.js.map +1 -1
- package/build/src/wallets/holdings.d.ts +25 -0
- package/build/src/wallets/holdings.d.ts.map +1 -1
- package/build/src/wallets/holdings.js +47 -3
- package/build/src/wallets/holdings.js.map +1 -1
- package/build/src/wallets/index.d.ts +16 -11
- package/build/src/wallets/index.d.ts.map +1 -1
- package/build/src/wallets/index.js +22 -10
- package/build/src/wallets/index.js.map +1 -1
- package/build/src/wallets/notify.d.ts +7 -0
- package/build/src/wallets/notify.d.ts.map +1 -0
- package/build/src/wallets/notify.js +21 -0
- package/build/src/wallets/notify.js.map +1 -0
- package/build/src/wallets/ownership.d.ts +77 -0
- package/build/src/wallets/ownership.d.ts.map +1 -1
- package/build/src/wallets/ownership.js +72 -5
- package/build/src/wallets/ownership.js.map +1 -1
- package/build/src/wallets/session.d.ts +107 -0
- package/build/src/wallets/session.d.ts.map +1 -0
- package/build/src/wallets/session.js +371 -0
- package/build/src/wallets/session.js.map +1 -0
- package/build/src/wallets/store.d.ts +135 -0
- package/build/src/wallets/store.d.ts.map +1 -0
- package/build/src/wallets/store.js +272 -0
- package/build/src/wallets/store.js.map +1 -0
- package/build/src/wallets/token-registry.d.ts +4 -2
- package/build/src/wallets/token-registry.d.ts.map +1 -1
- package/build/src/wallets/token-registry.js.map +1 -1
- package/build/src/wallets/wallet.d.ts +110 -0
- package/build/src/wallets/wallet.d.ts.map +1 -0
- package/build/src/wallets/wallet.js +268 -0
- package/build/src/wallets/wallet.js.map +1 -0
- package/package.json +1 -1
- package/build/src/wallets/token-standard-wallet.d.ts.map +0 -1
- package/build/src/wallets/token-standard-wallet.js.map +0 -1
- package/build/src/wallets/token-wallet.d.ts +0 -50
- package/build/src/wallets/token-wallet.d.ts.map +0 -1
- package/build/src/wallets/token-wallet.js +0 -175
- package/build/src/wallets/token-wallet.js.map +0 -1
package/README.md
CHANGED
|
@@ -71,41 +71,54 @@ See
|
|
|
71
71
|
|
|
72
72
|
## Token actions through a CIP-0103 wallet
|
|
73
73
|
|
|
74
|
-
`Wallets` runs token standard (CIP-56) holder actions
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
- read the wallet's state in one snapshot
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
74
|
+
`Wallets` runs token standard (CIP-56) holder actions through any CIP-0103 (Canton dApp API) wallet
|
|
75
|
+
provider. One wallet, `createWallet`, does it all:
|
|
76
|
+
|
|
77
|
+
- with any `TokenRegistry`, the CIP-56 actions: read the wallet's state in one snapshot
|
|
78
|
+
(`loadState`: holdings and their `balances` per instrument, and transfer offers), or each list on
|
|
79
|
+
its own; preview and send a transfer (`planTransfer`, then `submit` once the user confirmed the
|
|
80
|
+
kind); accept, reject or withdraw a transfer offer (`answerTransferOffer`, or
|
|
81
|
+
`acceptTransferOffer`, `rejectTransferOffer`, `withdrawTransferOffer`);
|
|
82
|
+
- with Digital Asset's Utility Registry client (`network`, or
|
|
83
|
+
`registry: createDaUtilitiesClient(...)`), DA's actions as well: mint offers and burn requests in
|
|
84
|
+
`loadState`, accept a mint offer (`acceptMintOffer`), propose a burn (`requestBurn`: a burn
|
|
85
|
+
request the registrar accepts or rejects; without a `reference` it files a generated
|
|
86
|
+
`holder-burn-…` one and returns it), and create a transfer preapproval (experimental). With
|
|
87
|
+
another registry, `loadState`'s mint offers and burn requests are empty and DA's actions are
|
|
88
|
+
refused with `unsupported-by-registry` before anything is read or signed;
|
|
89
|
+
`isDaUtilitiesClient(registry)` tells which you have;
|
|
90
|
+
- prove that the user controls the wallet's party by signing a message
|
|
91
|
+
(`requestWalletOwnershipVerdict`, or `proveWalletOwnership` alone), verified on your server with
|
|
92
|
+
`createWalletOwnershipChallenger` (or `verifyWalletOwnership` alone).
|
|
86
93
|
|
|
87
94
|
It reads choice contexts from DA's public Utilities API with an injectable `fetch`, and talks to the
|
|
88
95
|
wallet only through CIP-0103 (`getPrimaryAccount`, `ledgerApi`, `prepareExecuteAndWait`,
|
|
89
|
-
`signMessage`), so no wallet SDK is
|
|
96
|
+
`signMessage`, and for the session `connect`, `disconnect` and `isConnected`), so no wallet SDK is
|
|
97
|
+
involved.
|
|
90
98
|
|
|
91
99
|
It is browser-safe: import `@fairmint/canton-node-sdk/build/src/wallets/index.js`, which loads none
|
|
92
100
|
of the SDK's Node dependencies. The package root also exports it as the `Wallets` namespace.
|
|
93
101
|
|
|
94
102
|
```ts
|
|
95
103
|
import {
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
createWallet,
|
|
105
|
+
describeWalletError,
|
|
98
106
|
type Cip103Provider,
|
|
99
107
|
} from '@fairmint/canton-node-sdk/build/src/wallets/index.js';
|
|
100
108
|
|
|
101
|
-
async function send(provider: Cip103Provider, receiver: string): Promise<
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
registry: createDaUtilitiesClient({ network: 'devnet' }),
|
|
105
|
-
});
|
|
109
|
+
async function send(provider: Cip103Provider, receiver: string): Promise<string> {
|
|
110
|
+
// Any connected CIP-0103 provider; `network` builds DA's registry client (or pass `registry`).
|
|
111
|
+
const tokens = createWallet({ provider, network: 'devnet' });
|
|
106
112
|
const instrumentId = { admin: 'registrar::1220...', id: 'XMPL' };
|
|
107
|
-
|
|
108
|
-
|
|
113
|
+
try {
|
|
114
|
+
const plan = await tokens.planTransfer({ receiver, instrumentId, amount: '10' });
|
|
115
|
+
// Show plan.kind and the sender plan.partyId; submit refuses with `kind-changed` if the registry now answers
|
|
116
|
+
// another kind, and with `invalid-input` if the wallet has switched to another account since.
|
|
117
|
+
await plan.submit();
|
|
118
|
+
return 'Sent.';
|
|
119
|
+
} catch (error) {
|
|
120
|
+
return describeWalletError(error).message; // says whether anything was submitted
|
|
121
|
+
}
|
|
109
122
|
}
|
|
110
123
|
```
|
|
111
124
|
|
|
@@ -129,6 +142,9 @@ async function send(provider: Cip103Provider, receiver: string): Promise<void> {
|
|
|
129
142
|
`failed` (-32003, or a request the wallet refused before taking it on) or `unknown` (session
|
|
130
143
|
errors 4100/4900/4901 during a submit, timeouts, anything else): check the wallet before
|
|
131
144
|
resubmitting.
|
|
145
|
+
- `describeWalletError(error)` turns any error into a user-facing `message` that says whether
|
|
146
|
+
anything was submitted, and a `kind` to branch on (`declined`, `not-committed`, `outcome-unknown`,
|
|
147
|
+
`refused`, `rate-limited`, `read-failed`, `sign-failed`, `registry`, `other`).
|
|
132
148
|
- One write at a time per token wallet: a write started while another is in progress is refused with
|
|
133
149
|
`busy` before any read, so two writes never pick the same holdings.
|
|
134
150
|
- Holdings count only when their registrar signed them, and offers and requests only when a trusted
|
|
@@ -137,7 +153,99 @@ async function send(provider: Cip103Provider, receiver: string): Promise<void> {
|
|
|
137
153
|
other provider are never listed or acted on.
|
|
138
154
|
- Amounts are exact decimals (at most 10 places, within Daml `Numeric 10`); inputs are picked
|
|
139
155
|
deterministically. `requirePreapproval: true` sends only when the receiver pre-approved the
|
|
140
|
-
transfer, and `expectedKind` refuses a transfer whose kind changed since the preview.
|
|
156
|
+
transfer, and `expectedKind` refuses a transfer whose kind changed since the preview. An `offer`
|
|
157
|
+
keeps the sender's tokens locked until it is accepted, rejected or withdrawn; expiry alone does
|
|
158
|
+
not unlock them.
|
|
159
|
+
|
|
160
|
+
### A whole dApp: session, store and the ownership routes
|
|
161
|
+
|
|
162
|
+
`createCip103Session()` tracks which wallet is connected, as which party, and drops replies from
|
|
163
|
+
sessions that have since ended. `createWalletStore({ session })` builds on it: one token wallet per
|
|
164
|
+
connected wallet, its `loadState` snapshot, one wallet call at a time, a reload after every write
|
|
165
|
+
attempt (failed ones too: a failed write may have committed), and outcomes tagged with the session
|
|
166
|
+
they ran for. Both are framework-agnostic (`subscribe`/`getSnapshot`). The ownership check has two
|
|
167
|
+
halves: `requestWalletOwnershipVerdict` in the page, and `createWalletOwnershipChallenger` (Node
|
|
168
|
+
only, from the package root) behind two routes.
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
// wallet.ts (browser): one session and one store per tab, at module level.
|
|
172
|
+
import { useSyncExternalStore } from 'react';
|
|
173
|
+
import {
|
|
174
|
+
createCip103Session,
|
|
175
|
+
createWalletStore,
|
|
176
|
+
requestWalletOwnershipVerdict,
|
|
177
|
+
type Cip103Provider,
|
|
178
|
+
} from '@fairmint/canton-node-sdk/build/src/wallets/index.js';
|
|
179
|
+
|
|
180
|
+
const network = 'devnet';
|
|
181
|
+
const session = createCip103Session();
|
|
182
|
+
// Default open: createWallet({ provider, partyId, network, isActive: () => session.isCurrent(wallet) })
|
|
183
|
+
const store = createWalletStore({ session });
|
|
184
|
+
|
|
185
|
+
// The wallet's own callbacks (Loop: onAccept, onReject) and the buttons.
|
|
186
|
+
export const onAccept = (provider: Cip103Provider) => session.connected(provider, { network });
|
|
187
|
+
export const connect = (provider: Cip103Provider) => session.connect(provider, { network });
|
|
188
|
+
export const onReject = () => session.end('wallet');
|
|
189
|
+
export const disconnect = () => session.end('user'); // CIP-0103 disconnect
|
|
190
|
+
|
|
191
|
+
// state, loadError (kind 'rate-limited': offer store.refresh()), busy, outcome, unknownOutcomeParty
|
|
192
|
+
export const useWallet = () =>
|
|
193
|
+
useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
194
|
+
|
|
195
|
+
// Actions: refused (false) while another runs or any load is pending (one wallet call at a time).
|
|
196
|
+
export const accept = (cid: string) =>
|
|
197
|
+
store.run(`accept:${cid}`, ({ tokens }) => tokens.acceptMintOffer(cid).then(() => 'Accepted.'));
|
|
198
|
+
const urls = { challengeUrl: '/api/ownership/challenge', verifyUrl: '/api/ownership/verify' };
|
|
199
|
+
export const prove = () =>
|
|
200
|
+
store.run(
|
|
201
|
+
'ownership',
|
|
202
|
+
async ({ wallet: { provider, partyId } }) => {
|
|
203
|
+
const verdict = await requestWalletOwnershipVerdict(provider, {
|
|
204
|
+
partyId,
|
|
205
|
+
network,
|
|
206
|
+
fetch,
|
|
207
|
+
...urls,
|
|
208
|
+
});
|
|
209
|
+
return verdict.verified ? 'Verified.' : `Not verified: ${verdict.message}`;
|
|
210
|
+
},
|
|
211
|
+
{ readOnly: true } // signs a message, commits nothing: no reload
|
|
212
|
+
);
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
// app/api/ownership/challenge/route.ts and verify/route.ts (Node). Authenticate first.
|
|
217
|
+
import { createWalletOwnershipChallenger } from '@fairmint/canton-node-sdk';
|
|
218
|
+
|
|
219
|
+
const challenger = createWalletOwnershipChallenger({
|
|
220
|
+
secret,
|
|
221
|
+
purpose: 'my-dapp:wallet-ownership:v1',
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
export async function POST(request: Request): Promise<Response> {
|
|
225
|
+
const user = await requireUser(request); // yours: session, CSRF
|
|
226
|
+
return challenger.handleChallenge(request, { subject: user.id });
|
|
227
|
+
// verify/route.ts: challenger.handleVerify(request, { subject: user.id, onVerdict: (verdict, partyId) => log(...) })
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
- `connect()` always reads the primary account again after CIP-0103 `connect` resolves, also when
|
|
232
|
+
the wallet was already connected, so a failed party lookup recovers without a reload.
|
|
233
|
+
- While connected the session follows the provider's `accountsChanged` (another party is a new
|
|
234
|
+
`ConnectedWallet`) and `statusChanged` (disconnected ends the session); wallets that never emit
|
|
235
|
+
them lose nothing.
|
|
236
|
+
- A write that settles after its session ended (disconnect, wallet end, account switch) records
|
|
237
|
+
`interrupted`, never `succeeded`. A new wallet clears other outcomes, but keeps a write whose
|
|
238
|
+
outcome is unknown (`interrupted`, or `failed` with kind `outcome-unknown`) and names its party in
|
|
239
|
+
`unknownOutcomeParty`. Run previews and `signMessage` with `{ readOnly: true }`: no reload, and no
|
|
240
|
+
unknown outcome when the session ends first.
|
|
241
|
+
- A `TransferPlan` (and any token wallet kept from an earlier run) is bound to the wallet session
|
|
242
|
+
that made it. The store's token wallets refuse every write once their `ConnectedWallet` is no
|
|
243
|
+
longer the session's, with `invalid-input` before anything is read or signed, so a plan made for
|
|
244
|
+
one account is never submitted after the wallet switched to another: plan again. A custom `open`
|
|
245
|
+
gets this as its second argument (`{ isActive }`) and passes it on to `createWallet`.
|
|
246
|
+
- A wallet whose account reports another network than `{ network }` is refused, and each
|
|
247
|
+
`ConnectedWallet` has a `key` for UI keys (a new session remounts what the old one rendered).
|
|
248
|
+
- Wallet discovery (finding the providers a browser offers) is future work: its CIP is a draft.
|
|
141
249
|
|
|
142
250
|
### Proving wallet ownership
|
|
143
251
|
|
|
@@ -156,6 +264,22 @@ signature. A check in the browser proves nothing.
|
|
|
156
264
|
`verifyWalletOwnership(proof, { expectedNonce, expectedDomain, expectedNetwork })` (Node only,
|
|
157
265
|
from the package root, not the browser entry), then marks the nonce used.
|
|
158
266
|
|
|
267
|
+
`createWalletOwnershipChallenger({ secret, purpose })` does the server's part, and
|
|
268
|
+
`requestWalletOwnershipVerdict` the browser's (both shown above):
|
|
269
|
+
|
|
270
|
+
- The challenge is stateless: a token `v1.<claims>.<MAC>`, HMAC-SHA256 under the key
|
|
271
|
+
`HMAC-SHA256(secret, purpose)`, binds it to the subject (your signed-in user), the host and the
|
|
272
|
+
party for 5 minutes (`ttlMs`), compared in constant time.
|
|
273
|
+
- The nonce is spent before the signature is checked, so each challenge gets exactly one verdict.
|
|
274
|
+
`createMemoryNonceStore()` (the default) enforces that on one server instance only; pass a shared
|
|
275
|
+
`nonceStore` for more.
|
|
276
|
+
- The host is the browser's `Origin` host only when it is the request's own host or one of
|
|
277
|
+
`trustedOrigins` (`walletOwnershipDomain`); `x-forwarded-host` is never read.
|
|
278
|
+
- `handleChallenge` and `handleVerify` take a Fetch API `Request` and answer `{ data }`, or 400
|
|
279
|
+
`{ error }` for bad JSON, a bad body or an untrusted `Origin`, always `no-store`. Check the
|
|
280
|
+
caller's session and your CSRF rules before calling them. `issue` and `verify` serve callers that
|
|
281
|
+
do their own HTTP. The verdict reports the signed network only as `claimedNetwork`.
|
|
282
|
+
|
|
159
283
|
`verified: true` means: the message is exactly canonical, for this domain, nonce and network, and
|
|
160
284
|
within its window; the Ed25519 signature over its UTF-8 bytes verifies; and the key's Canton
|
|
161
285
|
fingerprint (`1220` + SHA-256 of purpose 12 and the raw key) is the party's namespace, which is how
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/external-signing/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/external-signing/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,+BAA+B,CAAC"}
|
|
@@ -27,4 +27,5 @@ __exportStar(require("./generate-external-party"), exports);
|
|
|
27
27
|
__exportStar(require("./prepare-external-transaction"), exports);
|
|
28
28
|
__exportStar(require("./stellar-utils"), exports);
|
|
29
29
|
__exportStar(require("./wallet-ownership"), exports);
|
|
30
|
+
__exportStar(require("./wallet-ownership-challenger"), exports);
|
|
30
31
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/external-signing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,0DAAwC;AACxC,oDAAkC;AAClC,0DAAwC;AACxC,iEAA+C;AAC/C,6DAA2C;AAC3C,8DAA4C;AAC5C,0DAAwC;AACxC,4DAA0C;AAC1C,4DAA0C;AAC1C,iEAA+C;AAC/C,kDAAgC;AAChC,qDAAmC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/external-signing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,0DAAwC;AACxC,oDAAkC;AAClC,0DAAwC;AACxC,iEAA+C;AAC/C,6DAA2C;AAC3C,8DAA4C;AAC5C,0DAAwC;AACxC,4DAA0C;AAC1C,4DAA0C;AAC1C,iEAA+C;AAC/C,kDAAgC;AAChC,qDAAmC;AACnC,gEAA8C"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { DaNetwork } from '../../wallets/da-utilities/client';
|
|
2
|
+
import { type WalletOwnershipChallengeFailure, type WalletOwnershipChallengeResponse, type WalletOwnershipVerdict } from '../../wallets/ownership';
|
|
3
|
+
export type { WalletOwnershipChallengeFailure, WalletOwnershipChallengeResponse, WalletOwnershipVerdict };
|
|
4
|
+
/** How long a challenge may be signed and verified, by default. */
|
|
5
|
+
export declare const DEFAULT_WALLET_OWNERSHIP_CHALLENGE_TTL_MS: number;
|
|
6
|
+
/** Spent nonces. */
|
|
7
|
+
export interface WalletOwnershipNonceStore {
|
|
8
|
+
/**
|
|
9
|
+
* Spend `nonce` until `expiresAtMs` (its challenge's expiry; it may be forgotten after that). False when it was
|
|
10
|
+
* already spent. A shared store must make this atomic (for example `SET NX` with an expiry).
|
|
11
|
+
*/
|
|
12
|
+
spend(nonce: string, expiresAtMs: number, nowMs: number): boolean | Promise<boolean>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Spent nonces in this process, pruned on expiry. Enforces single use on one server instance only (see the module
|
|
16
|
+
* comment).
|
|
17
|
+
*/
|
|
18
|
+
export declare function createMemoryNonceStore(): WalletOwnershipNonceStore;
|
|
19
|
+
export interface WalletOwnershipChallengerOptions {
|
|
20
|
+
/** The MAC secret. */
|
|
21
|
+
readonly secret: string | Uint8Array;
|
|
22
|
+
/** Key label: the MAC key is `HMAC-SHA256(secret, purpose)`, so a challenge token is never valid as another MAC. */
|
|
23
|
+
readonly purpose: string;
|
|
24
|
+
/** Challenge lifetime; default 5 minutes. Also `verifyWalletOwnership`'s `maxAgeMs`. */
|
|
25
|
+
readonly ttlMs?: number;
|
|
26
|
+
/** Default: `createMemoryNonceStore()`. */
|
|
27
|
+
readonly nonceStore?: WalletOwnershipNonceStore;
|
|
28
|
+
/** Defaults to the system clock. */
|
|
29
|
+
readonly now?: () => Date;
|
|
30
|
+
}
|
|
31
|
+
export interface WalletOwnershipIssueArgs {
|
|
32
|
+
/** Who asks: your signed-in user's stable id. Only the same subject can have the proof verified. */
|
|
33
|
+
readonly subject: string;
|
|
34
|
+
/** Your host, as the browser reaches it (`walletOwnershipDomain`). */
|
|
35
|
+
readonly domain: string;
|
|
36
|
+
readonly partyId: string;
|
|
37
|
+
readonly network: DaNetwork;
|
|
38
|
+
}
|
|
39
|
+
export interface WalletOwnershipVerifyArgs {
|
|
40
|
+
/** The challenge's token, as the browser sent it back. */
|
|
41
|
+
readonly token: unknown;
|
|
42
|
+
/** The proof, as the browser sent it; `verifyWalletOwnership` checks its shape. */
|
|
43
|
+
readonly proof: unknown;
|
|
44
|
+
readonly subject: string;
|
|
45
|
+
readonly domain: string;
|
|
46
|
+
}
|
|
47
|
+
export interface WalletOwnershipHandlerArgs {
|
|
48
|
+
/** Your signed-in user's stable id. Authenticate the request before calling a handler. */
|
|
49
|
+
readonly subject: string;
|
|
50
|
+
/**
|
|
51
|
+
* Origins besides the request's own (`request.url`) whose host the message may name, as absolute URLs
|
|
52
|
+
* (`https://app.example.com`). A malformed entry makes the handler throw `TypeError` instead of answering 400.
|
|
53
|
+
*/
|
|
54
|
+
readonly trustedOrigins?: readonly string[];
|
|
55
|
+
}
|
|
56
|
+
export interface WalletOwnershipVerifyHandlerArgs extends WalletOwnershipHandlerArgs {
|
|
57
|
+
/** For logging: the verdict and the party from the challenge token (never from the unparsed proof). */
|
|
58
|
+
readonly onVerdict?: (verdict: WalletOwnershipVerdict, partyId: string | null) => void;
|
|
59
|
+
}
|
|
60
|
+
export interface WalletOwnershipChallenger {
|
|
61
|
+
/** A challenge for `partyId`. Throws `TypeError` for a party id, domain or network the message rules refuse. */
|
|
62
|
+
issue(args: WalletOwnershipIssueArgs): WalletOwnershipChallengeResponse;
|
|
63
|
+
/**
|
|
64
|
+
* The verdict on a proof. The checks run in this order: the token's MAC (constant time), then the subject and domain,
|
|
65
|
+
* then expiry, then the nonce spend (before the signature, so each challenge gets one verdict), then
|
|
66
|
+
* `verifyWalletOwnership` with the challenge's nonce, domain, network, party and exact window. `token` must be a
|
|
67
|
+
* string of at most 4096 characters. Never throws for a bad token or proof.
|
|
68
|
+
*/
|
|
69
|
+
verify(args: WalletOwnershipVerifyArgs): Promise<WalletOwnershipVerdict>;
|
|
70
|
+
/**
|
|
71
|
+
* Fetch-API handler for the challenge request, body `{ network, partyId }`. 200 answers `{ data:
|
|
72
|
+
* WalletOwnershipChallengeResponse }`; bad JSON, a bad body or an untrusted `Origin` answer 400 `{ error }`. Every
|
|
73
|
+
* response is `no-store`. Check the caller's session (and your CSRF rules) first.
|
|
74
|
+
*/
|
|
75
|
+
handleChallenge(request: Request, args: WalletOwnershipHandlerArgs): Promise<Response>;
|
|
76
|
+
/**
|
|
77
|
+
* Fetch-API handler for the verify request, body `{ token, proof }`. 200 answers `{ data: WalletOwnershipVerdict }`,
|
|
78
|
+
* verified or not; 400 `{ error }` only for bad JSON, a body that is not a token and a proof object, or an untrusted
|
|
79
|
+
* `Origin`. Every response is `no-store`.
|
|
80
|
+
*/
|
|
81
|
+
handleVerify(request: Request, args: WalletOwnershipVerifyHandlerArgs): Promise<Response>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The host the ownership message is bound to: the host of the browser's `Origin`, when it is the request's own host
|
|
85
|
+
* (`request.url`) or the host of one of `trustedOrigins`. Null without an `Origin` (a non-browser caller), with an
|
|
86
|
+
* opaque (`null`) one, or for any other host. `x-forwarded-host` is never read: a non-browser caller can set it, and
|
|
87
|
+
* `Origin` too, so only hosts the server itself names are accepted. Throws `TypeError` when a `trustedOrigins` entry is
|
|
88
|
+
* not an absolute URL: one bad entry must not silently refuse every caller.
|
|
89
|
+
*/
|
|
90
|
+
export declare function walletOwnershipDomain(request: Request, trustedOrigins?: readonly string[]): string | null;
|
|
91
|
+
/** A challenger: issues challenges and verifies proofs against them (see the module comment). */
|
|
92
|
+
export declare function createWalletOwnershipChallenger(options: WalletOwnershipChallengerOptions): WalletOwnershipChallenger;
|
|
93
|
+
//# sourceMappingURL=wallet-ownership-challenger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-ownership-challenger.d.ts","sourceRoot":"","sources":["../../../../src/utils/external-signing/wallet-ownership-challenger.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAKL,KAAK,+BAA+B,EACpC,KAAK,gCAAgC,EACrC,KAAK,sBAAsB,EAC5B,MAAM,yBAAyB,CAAC;AAGjC,YAAY,EAAE,+BAA+B,EAAE,gCAAgC,EAAE,sBAAsB,EAAE,CAAC;AAE1G,mEAAmE;AACnE,eAAO,MAAM,yCAAyC,QAAgB,CAAC;AAevE,oBAAoB;AACpB,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACtF;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,yBAA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,KAAK,CAAC,IAAI,EAAE,wBAAwB,GAAG,gCAAgC,CAAC;IACxE;;;;;OAKG;IACH,MAAM,CAAC,IAAI,EAAE,yBAAyB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACzE;;;;OAIG;IACH,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,0BAA0B,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvF;;;;OAIG;IACH,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,gCAAgC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC3F;AAgBD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,GAAE,SAAS,MAAM,EAAO,GAAG,MAAM,GAAG,IAAI,CAY7G;AAiCD,iGAAiG;AACjG,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,gCAAgC,GAAG,yBAAyB,CAkIpH"}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_WALLET_OWNERSHIP_CHALLENGE_TTL_MS = void 0;
|
|
4
|
+
exports.createMemoryNonceStore = createMemoryNonceStore;
|
|
5
|
+
exports.walletOwnershipDomain = walletOwnershipDomain;
|
|
6
|
+
exports.createWalletOwnershipChallenger = createWalletOwnershipChallenger;
|
|
7
|
+
/**
|
|
8
|
+
* Server half of a wallet ownership check, for a dApp whose page calls `requestWalletOwnershipVerdict` (browser-safe
|
|
9
|
+
* wallets module). Node only: it uses `node:crypto`, so it is exported from the package root and never from the wallets
|
|
10
|
+
* entry.
|
|
11
|
+
*
|
|
12
|
+
* The challenge is stateless: its fields travel in a token (`v1.<base64url JSON claims>.<base64url MAC>`) MACed with
|
|
13
|
+
* HMAC-SHA256 under a key derived from your secret and a purpose label (`HMAC-SHA256(secret, purpose)`), so a challenge
|
|
14
|
+
* token is never valid as another of your MACs, such as a session cookie. The token binds the challenge to the subject
|
|
15
|
+
* (your signed-in user), the host it was issued for and the party, and lives `ttlMs` (5 minutes by default).
|
|
16
|
+
*
|
|
17
|
+
* Each challenge gets exactly one verdict: its nonce is spent before the signature is checked. The default nonce store
|
|
18
|
+
* keeps spent nonces in this process only, so on several server instances a replay within the TTL could reach another
|
|
19
|
+
* instance; pass a shared `nonceStore` (Redis, Postgres) to enforce single use across them.
|
|
20
|
+
*
|
|
21
|
+
* The network in the message is a label, not something this proves: a party id is derived from its key and is the same
|
|
22
|
+
* on every network, so the verdict reports it only as `claimedNetwork` (see `verifyWalletOwnership`).
|
|
23
|
+
*
|
|
24
|
+
* The message's domain is the browser's `Origin` host, and only when the server names that host itself (the request's
|
|
25
|
+
* own URL, or a configured trusted origin). `x-forwarded-host`, which any non-browser caller sets, is never read.
|
|
26
|
+
*/
|
|
27
|
+
const node_crypto_1 = require("node:crypto");
|
|
28
|
+
const type_guards_1 = require("../../core/utils/type-guards");
|
|
29
|
+
const cip103_1 = require("../../wallets/cip103");
|
|
30
|
+
const ownership_1 = require("../../wallets/ownership");
|
|
31
|
+
const wallet_ownership_1 = require("./wallet-ownership");
|
|
32
|
+
/** How long a challenge may be signed and verified, by default. */
|
|
33
|
+
exports.DEFAULT_WALLET_OWNERSHIP_CHALLENGE_TTL_MS = 5 * 60 * 1000;
|
|
34
|
+
const NETWORKS = new Set(['devnet', 'mainnet']);
|
|
35
|
+
const TOKEN_VERSION = 'v1';
|
|
36
|
+
const MAX_TOKEN_LENGTH = 4096;
|
|
37
|
+
const CHALLENGE_FAILURE_TEXT = {
|
|
38
|
+
'challenge-invalid': 'The challenge was not issued by this server.',
|
|
39
|
+
'challenge-expired': 'The challenge expired. Ask for a new one.',
|
|
40
|
+
'challenge-used': 'The challenge was already used. Each one is accepted once.',
|
|
41
|
+
'challenge-not-yours': 'The challenge was issued to another session, party or host.',
|
|
42
|
+
};
|
|
43
|
+
const UNTRUSTED_ORIGIN = "Ownership checks accept only requests from this site's own pages.";
|
|
44
|
+
/**
|
|
45
|
+
* Spent nonces in this process, pruned on expiry. Enforces single use on one server instance only (see the module
|
|
46
|
+
* comment).
|
|
47
|
+
*/
|
|
48
|
+
function createMemoryNonceStore() {
|
|
49
|
+
const spent = new Map();
|
|
50
|
+
return {
|
|
51
|
+
spend(nonce, expiresAtMs, nowMs) {
|
|
52
|
+
for (const [key, until] of spent) {
|
|
53
|
+
if (until <= nowMs)
|
|
54
|
+
spent.delete(key);
|
|
55
|
+
}
|
|
56
|
+
if (spent.has(nonce))
|
|
57
|
+
return false;
|
|
58
|
+
spent.set(nonce, expiresAtMs);
|
|
59
|
+
return true;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const CLAIM_KEYS = ['domain', 'nonce', 'issuedAt', 'expiresAt', 'network', 'partyId', 'sub'];
|
|
64
|
+
/**
|
|
65
|
+
* The host the ownership message is bound to: the host of the browser's `Origin`, when it is the request's own host
|
|
66
|
+
* (`request.url`) or the host of one of `trustedOrigins`. Null without an `Origin` (a non-browser caller), with an
|
|
67
|
+
* opaque (`null`) one, or for any other host. `x-forwarded-host` is never read: a non-browser caller can set it, and
|
|
68
|
+
* `Origin` too, so only hosts the server itself names are accepted. Throws `TypeError` when a `trustedOrigins` entry is
|
|
69
|
+
* not an absolute URL: one bad entry must not silently refuse every caller.
|
|
70
|
+
*/
|
|
71
|
+
function walletOwnershipDomain(request, trustedOrigins = []) {
|
|
72
|
+
// A server misconfiguration, not a caller's fault: fail loudly instead of refusing every request with a 400.
|
|
73
|
+
const trusted = new Set(trustedOrigins.map(trustedHost));
|
|
74
|
+
const origin = request.headers.get('origin');
|
|
75
|
+
if (origin === null || origin === '' || origin === 'null')
|
|
76
|
+
return null;
|
|
77
|
+
try {
|
|
78
|
+
const host = new URL(origin).host.toLowerCase();
|
|
79
|
+
trusted.add(new URL(request.url).host.toLowerCase());
|
|
80
|
+
return (0, ownership_1.isWalletOwnershipDomain)(host) && trusted.has(host) ? host : null;
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** The host of a configured trusted origin. Throws `TypeError` naming an entry that is not an absolute URL. */
|
|
87
|
+
function trustedHost(origin) {
|
|
88
|
+
let url;
|
|
89
|
+
try {
|
|
90
|
+
url = new URL(origin);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
throw new TypeError(`trustedOrigins entry ${JSON.stringify(origin)} is not an absolute URL (https://host)`);
|
|
94
|
+
}
|
|
95
|
+
return url.host.toLowerCase();
|
|
96
|
+
}
|
|
97
|
+
function jsonResponse(status, body) {
|
|
98
|
+
return new Response(JSON.stringify(body), {
|
|
99
|
+
status,
|
|
100
|
+
headers: { 'content-type': 'application/json', 'cache-control': 'no-store' },
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const badRequest = (error) => jsonResponse(400, { error });
|
|
104
|
+
/** The request's JSON body, or a 400 response. */
|
|
105
|
+
async function readBody(request) {
|
|
106
|
+
let body;
|
|
107
|
+
try {
|
|
108
|
+
body = JSON.parse(await request.text());
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return badRequest('Invalid JSON request body');
|
|
112
|
+
}
|
|
113
|
+
return (0, type_guards_1.isRecord)(body) ? { body } : badRequest('Expected a JSON object.');
|
|
114
|
+
}
|
|
115
|
+
/** A challenger: issues challenges and verifies proofs against them (see the module comment). */
|
|
116
|
+
function createWalletOwnershipChallenger(options) {
|
|
117
|
+
const { secret, purpose } = options;
|
|
118
|
+
const ttlMs = options.ttlMs ?? exports.DEFAULT_WALLET_OWNERSHIP_CHALLENGE_TTL_MS;
|
|
119
|
+
const nonceStore = options.nonceStore ?? createMemoryNonceStore();
|
|
120
|
+
const now = options.now ?? (() => new Date());
|
|
121
|
+
if (!(typeof secret === 'string' ? secret.length > 0 : secret instanceof Uint8Array && secret.byteLength > 0)) {
|
|
122
|
+
throw new TypeError('secret is required');
|
|
123
|
+
}
|
|
124
|
+
if (typeof purpose !== 'string' || purpose.length === 0)
|
|
125
|
+
throw new TypeError('purpose is required');
|
|
126
|
+
if (!Number.isFinite(ttlMs) || !(ttlMs > 0))
|
|
127
|
+
throw new TypeError('ttlMs must be a positive number');
|
|
128
|
+
const macKey = (0, node_crypto_1.createHmac)('sha256', secret).update(purpose).digest();
|
|
129
|
+
const mac = (body) => (0, node_crypto_1.createHmac)('sha256', macKey).update(`${TOKEN_VERSION}.${body}`).digest('base64url');
|
|
130
|
+
/** The claims of a token this challenger MACed, or null for any other text. */
|
|
131
|
+
function readClaims(token) {
|
|
132
|
+
if (typeof token !== 'string' || token.length > MAX_TOKEN_LENGTH)
|
|
133
|
+
return null;
|
|
134
|
+
const [version, body, signature, extra] = token.split('.');
|
|
135
|
+
if (version !== TOKEN_VERSION || !body || !signature || extra !== undefined)
|
|
136
|
+
return null;
|
|
137
|
+
const expected = Buffer.from(mac(body));
|
|
138
|
+
const given = Buffer.from(signature);
|
|
139
|
+
if (expected.length !== given.length || !(0, node_crypto_1.timingSafeEqual)(expected, given))
|
|
140
|
+
return null;
|
|
141
|
+
let parsed;
|
|
142
|
+
try {
|
|
143
|
+
parsed = JSON.parse(Buffer.from(body, 'base64url').toString('utf8'));
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
if (!(0, type_guards_1.isRecord)(parsed) || !CLAIM_KEYS.every((key) => typeof parsed[key] === 'string'))
|
|
149
|
+
return null;
|
|
150
|
+
return parsed;
|
|
151
|
+
}
|
|
152
|
+
function issue({ subject, domain, partyId, network }) {
|
|
153
|
+
if (typeof subject !== 'string' || subject.length === 0)
|
|
154
|
+
throw new TypeError('subject is required');
|
|
155
|
+
if (!NETWORKS.has(network))
|
|
156
|
+
throw new TypeError('network must be devnet or mainnet');
|
|
157
|
+
const issuedAt = now();
|
|
158
|
+
const challenge = {
|
|
159
|
+
domain,
|
|
160
|
+
nonce: (0, node_crypto_1.randomBytes)(24).toString('base64url'),
|
|
161
|
+
issuedAt: issuedAt.toISOString(),
|
|
162
|
+
expiresAt: new Date(issuedAt.getTime() + ttlMs).toISOString(),
|
|
163
|
+
network: (0, cip103_1.cip103NetworkId)(network),
|
|
164
|
+
};
|
|
165
|
+
// The message rules decide which domains and party ids are valid: throws TypeError for any other.
|
|
166
|
+
(0, ownership_1.buildWalletOwnershipMessage)({ ...challenge, partyId });
|
|
167
|
+
const claims = { ...challenge, partyId, sub: subject };
|
|
168
|
+
const body = Buffer.from(JSON.stringify(claims)).toString('base64url');
|
|
169
|
+
return { challenge, token: `${TOKEN_VERSION}.${body}.${mac(body)}` };
|
|
170
|
+
}
|
|
171
|
+
/** The verdict, and the party of a token this challenger issued (null for any other token). */
|
|
172
|
+
async function check(args) {
|
|
173
|
+
const refuse = (reason) => ({
|
|
174
|
+
verified: false,
|
|
175
|
+
reason,
|
|
176
|
+
message: CHALLENGE_FAILURE_TEXT[reason],
|
|
177
|
+
});
|
|
178
|
+
const claims = readClaims(args.token);
|
|
179
|
+
if (claims === null)
|
|
180
|
+
return { verdict: refuse('challenge-invalid'), partyId: null };
|
|
181
|
+
const { partyId } = claims;
|
|
182
|
+
if (claims.sub !== args.subject || claims.domain !== args.domain) {
|
|
183
|
+
return { verdict: refuse('challenge-not-yours'), partyId };
|
|
184
|
+
}
|
|
185
|
+
const at = now();
|
|
186
|
+
const expiresAtMs = Date.parse(claims.expiresAt);
|
|
187
|
+
if (!(at.getTime() < expiresAtMs))
|
|
188
|
+
return { verdict: refuse('challenge-expired'), partyId };
|
|
189
|
+
if (!(await nonceStore.spend(claims.nonce, expiresAtMs, at.getTime()))) {
|
|
190
|
+
return { verdict: refuse('challenge-used'), partyId };
|
|
191
|
+
}
|
|
192
|
+
const result = (0, wallet_ownership_1.verifyWalletOwnership)(args.proof, {
|
|
193
|
+
expectedNonce: claims.nonce,
|
|
194
|
+
expectedDomain: claims.domain,
|
|
195
|
+
expectedNetwork: claims.network,
|
|
196
|
+
expectedPartyId: claims.partyId,
|
|
197
|
+
expectedIssuedAt: claims.issuedAt,
|
|
198
|
+
expectedExpiresAt: claims.expiresAt,
|
|
199
|
+
maxAgeMs: ttlMs,
|
|
200
|
+
now: at,
|
|
201
|
+
});
|
|
202
|
+
if (!result.verified) {
|
|
203
|
+
return { verdict: { verified: false, reason: result.reason, message: result.message }, partyId };
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
verdict: {
|
|
207
|
+
verified: true,
|
|
208
|
+
partyId: result.partyId,
|
|
209
|
+
publicKeyFingerprint: result.publicKeyFingerprint,
|
|
210
|
+
claimedNetwork: result.network ?? null,
|
|
211
|
+
verifiedAt: at.toISOString(),
|
|
212
|
+
},
|
|
213
|
+
partyId,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
issue,
|
|
218
|
+
verify: async (args) => (await check(args)).verdict,
|
|
219
|
+
async handleChallenge(request, { subject, trustedOrigins }) {
|
|
220
|
+
const domain = walletOwnershipDomain(request, trustedOrigins);
|
|
221
|
+
if (domain === null)
|
|
222
|
+
return badRequest(UNTRUSTED_ORIGIN);
|
|
223
|
+
const read = await readBody(request);
|
|
224
|
+
if (read instanceof Response)
|
|
225
|
+
return read;
|
|
226
|
+
const { network, partyId } = read.body;
|
|
227
|
+
if (network !== 'devnet' && network !== 'mainnet')
|
|
228
|
+
return badRequest('network must be devnet or mainnet.');
|
|
229
|
+
if (!(0, ownership_1.isWalletOwnershipPartyId)(partyId)) {
|
|
230
|
+
return badRequest('partyId must be a Canton party id (hint::namespace).');
|
|
231
|
+
}
|
|
232
|
+
return jsonResponse(200, { data: issue({ subject, domain, partyId, network }) });
|
|
233
|
+
},
|
|
234
|
+
async handleVerify(request, { subject, trustedOrigins, onVerdict }) {
|
|
235
|
+
const domain = walletOwnershipDomain(request, trustedOrigins);
|
|
236
|
+
if (domain === null)
|
|
237
|
+
return badRequest(UNTRUSTED_ORIGIN);
|
|
238
|
+
const read = await readBody(request);
|
|
239
|
+
if (read instanceof Response)
|
|
240
|
+
return read;
|
|
241
|
+
const { token, proof } = read.body;
|
|
242
|
+
if (typeof token !== 'string' || token.length === 0 || token.length > MAX_TOKEN_LENGTH) {
|
|
243
|
+
return badRequest('token must be the challenge token.');
|
|
244
|
+
}
|
|
245
|
+
if (!(0, type_guards_1.isRecord)(proof))
|
|
246
|
+
return badRequest('proof must be an object.');
|
|
247
|
+
const { verdict, partyId } = await check({ token, proof, subject, domain });
|
|
248
|
+
onVerdict?.(verdict, partyId);
|
|
249
|
+
return jsonResponse(200, { data: verdict });
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=wallet-ownership-challenger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-ownership-challenger.js","sourceRoot":"","sources":["../../../../src/utils/external-signing/wallet-ownership-challenger.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,6CAAuE;AACvE,8DAAwD;AACxD,iDAAuD;AAEvD,uDAQiC;AACjC,yDAA2D;AAI3D,mEAAmE;AACtD,QAAA,yCAAyC,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAEvE,MAAM,QAAQ,GAAwB,IAAI,GAAG,CAAY,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAChF,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,MAAM,sBAAsB,GAA8D;IACxF,mBAAmB,EAAE,8CAA8C;IACnE,mBAAmB,EAAE,2CAA2C;IAChE,gBAAgB,EAAE,4DAA4D;IAC9E,qBAAqB,EAAE,6DAA6D;CACrF,CAAC;AAEF,MAAM,gBAAgB,GAAG,mEAAmE,CAAC;AAW7F;;;GAGG;AACH;IACE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;IACxC,O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ownership message. */
|
|
6
|
-
| 'malformed-message' | 'domain-mismatch' | 'nonce-mismatch'
|
|
7
|
-
/** The message, the proof and the expected party do not all name the same party, or the namespace differs. */
|
|
8
|
-
| 'party-mismatch' | 'network-mismatch'
|
|
9
|
-
/** The message's `Issued At` or `Expiration Time` is not the one the server issued. */
|
|
10
|
-
| 'window-mismatch'
|
|
11
|
-
/** Issued in the future (beyond the allowed clock skew). */
|
|
12
|
-
| 'not-yet-valid'
|
|
13
|
-
/** Past its expiration time. */
|
|
14
|
-
| 'expired'
|
|
15
|
-
/** The message allows a longer validity window than `maxAgeMs`. */
|
|
16
|
-
| 'lifetime-too-long'
|
|
17
|
-
/** The public key is not an Ed25519 key in an encoding this verifier accepts. */
|
|
18
|
-
| 'unsupported-public-key'
|
|
19
|
-
/** The key's fingerprint is not the party's namespace (see the module comment). */
|
|
20
|
-
| 'key-not-bound-to-party'
|
|
21
|
-
/** The signature is not 64 bytes of hex or base64. */
|
|
22
|
-
| 'malformed-signature'
|
|
23
|
-
/** The signature does not verify. */
|
|
24
|
-
| 'bad-signature';
|
|
1
|
+
import type { WalletOwnershipFailure } from '../../wallets/ownership';
|
|
2
|
+
/** Why a proof did not verify. Defined in the browser-safe wallets module, which shares it; re-exported here. */
|
|
3
|
+
export type { WalletOwnershipFailure };
|
|
25
4
|
export type WalletOwnershipVerification = {
|
|
26
5
|
readonly verified: true;
|
|
27
6
|
readonly partyId: string;
|