@fairmint/canton-node-sdk 0.0.277 → 0.0.279
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 +197 -14
- package/build/src/utils/external-signing/index.d.ts +2 -0
- package/build/src/utils/external-signing/index.d.ts.map +1 -1
- package/build/src/utils/external-signing/index.js +2 -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 +48 -0
- package/build/src/utils/external-signing/wallet-ownership.d.ts.map +1 -0
- package/build/src/utils/external-signing/wallet-ownership.js +179 -0
- package/build/src/utils/external-signing/wallet-ownership.js.map +1 -0
- package/build/src/wallets/cip103.d.ts +100 -6
- package/build/src/wallets/cip103.d.ts.map +1 -1
- package/build/src/wallets/cip103.js +237 -107
- package/build/src/wallets/cip103.js.map +1 -1
- package/build/src/wallets/da-utilities/client.d.ts.map +1 -1
- package/build/src/wallets/da-utilities/client.js +3 -0
- package/build/src/wallets/da-utilities/client.js.map +1 -1
- package/build/src/wallets/errors.d.ts +51 -0
- package/build/src/wallets/errors.d.ts.map +1 -1
- package/build/src/wallets/errors.js +68 -1
- 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 +44 -0
- package/build/src/wallets/holdings.js.map +1 -1
- package/build/src/wallets/index.d.ts +14 -7
- package/build/src/wallets/index.d.ts.map +1 -1
- package/build/src/wallets/index.js +22 -3
- 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 +156 -0
- package/build/src/wallets/ownership.d.ts.map +1 -0
- package/build/src/wallets/ownership.js +269 -0
- package/build/src/wallets/ownership.js.map +1 -0
- 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 +138 -0
- package/build/src/wallets/store.d.ts.map +1 -0
- package/build/src/wallets/store.js +262 -0
- package/build/src/wallets/store.js.map +1 -0
- package/build/src/wallets/templates.d.ts +15 -0
- package/build/src/wallets/templates.d.ts.map +1 -1
- package/build/src/wallets/templates.js +33 -9
- package/build/src/wallets/templates.js.map +1 -1
- package/build/src/wallets/token-registry.d.ts +15 -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/token-standard-wallet.d.ts +94 -9
- package/build/src/wallets/token-standard-wallet.d.ts.map +1 -1
- package/build/src/wallets/token-standard-wallet.js +160 -19
- package/build/src/wallets/token-standard-wallet.js.map +1 -1
- package/build/src/wallets/token-wallet.d.ts +43 -7
- package/build/src/wallets/token-wallet.d.ts.map +1 -1
- package/build/src/wallets/token-wallet.js +113 -35
- package/build/src/wallets/token-wallet.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,11 +72,24 @@ See
|
|
|
72
72
|
## Token actions through a CIP-0103 wallet
|
|
73
73
|
|
|
74
74
|
`Wallets` runs token standard (CIP-56) holder actions on Digital Asset Utility Registry instruments
|
|
75
|
-
through any CIP-0103 (Canton dApp API) wallet provider:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
through any CIP-0103 (Canton dApp API) wallet provider:
|
|
76
|
+
|
|
77
|
+
- read the wallet's state in one snapshot (`loadState`: holdings and their `balances` per
|
|
78
|
+
instrument, mint offers, transfer offers and burn requests), or each list on its own;
|
|
79
|
+
- accept a mint offer (`acceptMintOffer`);
|
|
80
|
+
- preview and send a transfer (`planTransfer`, then `submit` once the user confirmed the kind), and
|
|
81
|
+
accept, reject or withdraw a transfer offer (`answerTransferOffer`, or `acceptTransferOffer`,
|
|
82
|
+
`rejectTransferOffer`, `withdrawTransferOffer`);
|
|
83
|
+
- propose a burn (`requestBurn`: a burn request the registrar accepts or rejects; without a
|
|
84
|
+
`reference` it files a generated `holder-burn-…` one and returns it);
|
|
85
|
+
- create a transfer preapproval (experimental);
|
|
86
|
+
- prove that the user controls the wallet's party by signing a message
|
|
87
|
+
(`requestWalletOwnershipVerdict`, or `proveWalletOwnership` alone), verified on your server with
|
|
88
|
+
`createWalletOwnershipChallenger` (or `verifyWalletOwnership` alone).
|
|
89
|
+
|
|
90
|
+
It reads choice contexts from DA's public Utilities API with an injectable `fetch`, and talks to the
|
|
91
|
+
wallet only through CIP-0103 (`getPrimaryAccount`, `ledgerApi`, `prepareExecuteAndWait`,
|
|
92
|
+
`signMessage`, and for the session `connect`, `disconnect` and `isConnected`), so no wallet SDK is
|
|
80
93
|
involved.
|
|
81
94
|
|
|
82
95
|
It is browser-safe: import `@fairmint/canton-node-sdk/build/src/wallets/index.js`, which loads none
|
|
@@ -84,26 +97,50 @@ of the SDK's Node dependencies. The package root also exports it as the `Wallets
|
|
|
84
97
|
|
|
85
98
|
```ts
|
|
86
99
|
import {
|
|
87
|
-
createDaUtilitiesClient,
|
|
88
100
|
createTokenWallet,
|
|
101
|
+
describeWalletError,
|
|
89
102
|
type Cip103Provider,
|
|
90
103
|
} from '@fairmint/canton-node-sdk/build/src/wallets/index.js';
|
|
91
104
|
|
|
92
|
-
async function send(provider: Cip103Provider, receiver: string): Promise<
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
registry: createDaUtilitiesClient({ network: 'devnet' }),
|
|
96
|
-
});
|
|
105
|
+
async function send(provider: Cip103Provider, receiver: string): Promise<string> {
|
|
106
|
+
// Any connected CIP-0103 provider; `network` builds DA's registry client (or pass `registry`).
|
|
107
|
+
const tokens = createTokenWallet({ provider, network: 'devnet' });
|
|
97
108
|
const instrumentId = { admin: 'registrar::1220...', id: 'XMPL' };
|
|
98
|
-
|
|
99
|
-
|
|
109
|
+
try {
|
|
110
|
+
const plan = await tokens.planTransfer({ receiver, instrumentId, amount: '10' });
|
|
111
|
+
// Show plan.kind and the sender plan.partyId; submit refuses with `kind-changed` if the registry now answers
|
|
112
|
+
// another kind, and with `invalid-input` if the wallet has switched to another account since.
|
|
113
|
+
await plan.submit();
|
|
114
|
+
return 'Sent.';
|
|
115
|
+
} catch (error) {
|
|
116
|
+
return describeWalletError(error).message; // says whether anything was submitted
|
|
117
|
+
}
|
|
100
118
|
}
|
|
101
119
|
```
|
|
102
120
|
|
|
121
|
+
- Load a page with one `loadState()` call: one `/v2/state/ledger-end` call and one paged
|
|
122
|
+
`/v2/state/active-contracts-page` stream whose cumulative filter carries every template and
|
|
123
|
+
interface. Concurrent `loadState` and `list*` calls on one token wallet share the snapshot in
|
|
124
|
+
flight (unless a write settled since it started). Writes do their own fresh reads.
|
|
125
|
+
- Wallets rate-limit `ledgerApi` (Loop answers CIP-0103 -32005 for an HTTP 429). Loop also makes a
|
|
126
|
+
session check and a provider status check before every `ledgerApi` call, so each call is three
|
|
127
|
+
HTTP requests against Loop's limit; a 429 of the session check arrives as -32603 "Session
|
|
128
|
+
verification failed with status 429." and counts as a rate limit too. Rate-limited reads are
|
|
129
|
+
retried after 0.5, 1, 2 and 4 s (jittered; `readRetry` changes it); then they fail with a
|
|
130
|
+
`WalletReadError` whose `rateLimited` is true, so a UI can offer a retry.
|
|
131
|
+
- The unpaged `/v2/state/active-contracts` is read once instead only when the first paged call is
|
|
132
|
+
refused as not offered or malformed (4200, -32601, -32004, -32602), or when Loop answers -32002
|
|
133
|
+
"Ledger access unavailable", which is how Loop reports any non-429 HTTP failure of its ledger
|
|
134
|
+
proxy (an endpoint not in its allowlist, a Canton 3.5 participant serving the paged endpoint only
|
|
135
|
+
as GET, but also a server error). If the fallback fails too, the error names both failures. A rate
|
|
136
|
+
limit or a timeout never falls back.
|
|
103
137
|
- Writes never retry. A `WalletSubmitError` has `outcome` `rejected-by-user` (CIP-0103 4001),
|
|
104
138
|
`failed` (-32003, or a request the wallet refused before taking it on) or `unknown` (session
|
|
105
139
|
errors 4100/4900/4901 during a submit, timeouts, anything else): check the wallet before
|
|
106
140
|
resubmitting.
|
|
141
|
+
- `describeWalletError(error)` turns any error into a user-facing `message` that says whether
|
|
142
|
+
anything was submitted, and a `kind` to branch on (`declined`, `not-committed`, `outcome-unknown`,
|
|
143
|
+
`refused`, `rate-limited`, `read-failed`, `sign-failed`, `registry`, `other`).
|
|
107
144
|
- One write at a time per token wallet: a write started while another is in progress is refused with
|
|
108
145
|
`busy` before any read, so two writes never pick the same holdings.
|
|
109
146
|
- Holdings count only when their registrar signed them, and offers and requests only when a trusted
|
|
@@ -112,7 +149,153 @@ async function send(provider: Cip103Provider, receiver: string): Promise<void> {
|
|
|
112
149
|
other provider are never listed or acted on.
|
|
113
150
|
- Amounts are exact decimals (at most 10 places, within Daml `Numeric 10`); inputs are picked
|
|
114
151
|
deterministically. `requirePreapproval: true` sends only when the receiver pre-approved the
|
|
115
|
-
transfer, and `expectedKind` refuses a transfer whose kind changed since the preview.
|
|
152
|
+
transfer, and `expectedKind` refuses a transfer whose kind changed since the preview. An `offer`
|
|
153
|
+
keeps the sender's tokens locked until it is accepted, rejected or withdrawn; expiry alone does
|
|
154
|
+
not unlock them.
|
|
155
|
+
|
|
156
|
+
### A whole dApp: session, store and the ownership routes
|
|
157
|
+
|
|
158
|
+
`createCip103Session()` tracks which wallet is connected, as which party, and drops replies from
|
|
159
|
+
sessions that have since ended. `createTokenWalletStore({ session })` builds on it: one token wallet
|
|
160
|
+
per connected wallet, its `loadState` snapshot, one wallet call at a time, a reload after every
|
|
161
|
+
write attempt (failed ones too: a failed write may have committed), and outcomes tagged with the
|
|
162
|
+
session they ran for. Both are framework-agnostic (`subscribe`/`getSnapshot`). The ownership check
|
|
163
|
+
has two halves: `requestWalletOwnershipVerdict` in the page, and `createWalletOwnershipChallenger`
|
|
164
|
+
(Node only, from the package root) behind two routes.
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
// wallet.ts (browser): one session and one store per tab, at module level.
|
|
168
|
+
import { useSyncExternalStore } from 'react';
|
|
169
|
+
import {
|
|
170
|
+
createCip103Session,
|
|
171
|
+
createTokenWalletStore,
|
|
172
|
+
requestWalletOwnershipVerdict,
|
|
173
|
+
type Cip103Provider,
|
|
174
|
+
} from '@fairmint/canton-node-sdk/build/src/wallets/index.js';
|
|
175
|
+
|
|
176
|
+
const network = 'devnet';
|
|
177
|
+
const session = createCip103Session();
|
|
178
|
+
// Default open: createTokenWallet({ provider, partyId, network, isActive: () => session.isCurrent(wallet) })
|
|
179
|
+
const store = createTokenWalletStore({ session });
|
|
180
|
+
|
|
181
|
+
// The wallet's own callbacks (Loop: onAccept, onReject) and the buttons.
|
|
182
|
+
export const onAccept = (provider: Cip103Provider) => session.connected(provider, { network });
|
|
183
|
+
export const connect = (provider: Cip103Provider) => session.connect(provider, { network });
|
|
184
|
+
export const onReject = () => session.end('wallet');
|
|
185
|
+
export const disconnect = () => session.end('user'); // CIP-0103 disconnect
|
|
186
|
+
|
|
187
|
+
// state, loadError (kind 'rate-limited': offer store.refresh()), busy, outcome, unknownOutcomeParty
|
|
188
|
+
export const useWallet = () =>
|
|
189
|
+
useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
190
|
+
|
|
191
|
+
// Actions: refused (false) while another runs or any load is pending (one wallet call at a time).
|
|
192
|
+
export const accept = (cid: string) =>
|
|
193
|
+
store.run(`accept:${cid}`, ({ tokens }) => tokens.acceptMintOffer(cid).then(() => 'Accepted.'));
|
|
194
|
+
const urls = { challengeUrl: '/api/ownership/challenge', verifyUrl: '/api/ownership/verify' };
|
|
195
|
+
export const prove = () =>
|
|
196
|
+
store.run(
|
|
197
|
+
'ownership',
|
|
198
|
+
async ({ wallet: { provider, partyId } }) => {
|
|
199
|
+
const verdict = await requestWalletOwnershipVerdict(provider, {
|
|
200
|
+
partyId,
|
|
201
|
+
network,
|
|
202
|
+
fetch,
|
|
203
|
+
...urls,
|
|
204
|
+
});
|
|
205
|
+
return verdict.verified ? 'Verified.' : `Not verified: ${verdict.message}`;
|
|
206
|
+
},
|
|
207
|
+
{ readOnly: true } // signs a message, commits nothing: no reload
|
|
208
|
+
);
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
// app/api/ownership/challenge/route.ts and verify/route.ts (Node). Authenticate first.
|
|
213
|
+
import { createWalletOwnershipChallenger } from '@fairmint/canton-node-sdk';
|
|
214
|
+
|
|
215
|
+
const challenger = createWalletOwnershipChallenger({
|
|
216
|
+
secret,
|
|
217
|
+
purpose: 'my-dapp:wallet-ownership:v1',
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
export async function POST(request: Request): Promise<Response> {
|
|
221
|
+
const user = await requireUser(request); // yours: session, CSRF
|
|
222
|
+
return challenger.handleChallenge(request, { subject: user.id });
|
|
223
|
+
// verify/route.ts: challenger.handleVerify(request, { subject: user.id, onVerdict: (verdict, partyId) => log(...) })
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
- `connect()` always reads the primary account again after CIP-0103 `connect` resolves, also when
|
|
228
|
+
the wallet was already connected, so a failed party lookup recovers without a reload.
|
|
229
|
+
- While connected the session follows the provider's `accountsChanged` (another party is a new
|
|
230
|
+
`ConnectedWallet`) and `statusChanged` (disconnected ends the session); wallets that never emit
|
|
231
|
+
them lose nothing.
|
|
232
|
+
- A write that settles after its session ended (disconnect, wallet end, account switch) records
|
|
233
|
+
`interrupted`, never `succeeded`. A new wallet clears other outcomes, but keeps a write whose
|
|
234
|
+
outcome is unknown (`interrupted`, or `failed` with kind `outcome-unknown`) and names its party in
|
|
235
|
+
`unknownOutcomeParty`. Run previews and `signMessage` with `{ readOnly: true }`: no reload, and no
|
|
236
|
+
unknown outcome when the session ends first.
|
|
237
|
+
- A `TransferPlan` (and any token wallet kept from an earlier run) is bound to the wallet session
|
|
238
|
+
that made it. The store's token wallets refuse every write once their `ConnectedWallet` is no
|
|
239
|
+
longer the session's, with `invalid-input` before anything is read or signed, so a plan made for
|
|
240
|
+
one account is never submitted after the wallet switched to another: plan again. A custom `open`
|
|
241
|
+
gets this as its second argument (`{ isActive }`) and passes it on to `createTokenWallet`.
|
|
242
|
+
- A wallet whose account reports another network than `{ network }` is refused, and each
|
|
243
|
+
`ConnectedWallet` has a `key` for UI keys (a new session remounts what the old one rendered).
|
|
244
|
+
- Wallet discovery (finding the providers a browser offers) is future work: its CIP is a draft.
|
|
245
|
+
|
|
246
|
+
### Proving wallet ownership
|
|
247
|
+
|
|
248
|
+
A connected wallet only tells the dApp a party id, which anyone can claim. To know the user controls
|
|
249
|
+
the party, the server issues a challenge, the wallet signs it, and the server verifies the
|
|
250
|
+
signature. A check in the browser proves nothing.
|
|
251
|
+
|
|
252
|
+
1. The server issues `{ domain, nonce, issuedAt, expiresAt, network? }`: its own host, a random
|
|
253
|
+
single-use nonce it stores, and a short validity window (at most 10 minutes by default).
|
|
254
|
+
2. The browser calls `proveWalletOwnership(provider, { challenge })`. The wallet signs, as its
|
|
255
|
+
primary account, a canonical text message: a fixed title, a statement that it is not a
|
|
256
|
+
transaction and authorizes nothing, then the domain, party, network, nonce and times. Plain text
|
|
257
|
+
with a fixed prefix can never be a Canton transaction or topology hash (34 binary bytes), which
|
|
258
|
+
the same key signs.
|
|
259
|
+
3. The server calls
|
|
260
|
+
`verifyWalletOwnership(proof, { expectedNonce, expectedDomain, expectedNetwork })` (Node only,
|
|
261
|
+
from the package root, not the browser entry), then marks the nonce used.
|
|
262
|
+
|
|
263
|
+
`createWalletOwnershipChallenger({ secret, purpose })` does the server's part, and
|
|
264
|
+
`requestWalletOwnershipVerdict` the browser's (both shown above):
|
|
265
|
+
|
|
266
|
+
- The challenge is stateless: a token `v1.<claims>.<MAC>`, HMAC-SHA256 under the key
|
|
267
|
+
`HMAC-SHA256(secret, purpose)`, binds it to the subject (your signed-in user), the host and the
|
|
268
|
+
party for 5 minutes (`ttlMs`), compared in constant time.
|
|
269
|
+
- The nonce is spent before the signature is checked, so each challenge gets exactly one verdict.
|
|
270
|
+
`createMemoryNonceStore()` (the default) enforces that on one server instance only; pass a shared
|
|
271
|
+
`nonceStore` for more.
|
|
272
|
+
- The host is the browser's `Origin` host only when it is the request's own host or one of
|
|
273
|
+
`trustedOrigins` (`walletOwnershipDomain`); `x-forwarded-host` is never read.
|
|
274
|
+
- `handleChallenge` and `handleVerify` take a Fetch API `Request` and answer `{ data }`, or 400
|
|
275
|
+
`{ error }` for bad JSON, a bad body or an untrusted `Origin`, always `no-store`. Check the
|
|
276
|
+
caller's session and your CSRF rules before calling them. `issue` and `verify` serve callers that
|
|
277
|
+
do their own HTTP. The verdict reports the signed network only as `claimedNetwork`.
|
|
278
|
+
|
|
279
|
+
`verified: true` means: the message is exactly canonical, for this domain, nonce and network, and
|
|
280
|
+
within its window; the Ed25519 signature over its UTF-8 bytes verifies; and the key's Canton
|
|
281
|
+
fingerprint (`1220` + SHA-256 of purpose 12 and the raw key) is the party's namespace, which is how
|
|
282
|
+
an external party's id is derived from its key. Otherwise the result gives a `reason`. A party not
|
|
283
|
+
namespaced by its signing key (a participant-hosted party, or an external party whose key was
|
|
284
|
+
rotated or delegated) fails with `key-not-bound-to-party`: proving it would need a ledger topology
|
|
285
|
+
lookup (its `PartyToKeyMapping` and namespace delegations), which the verifier does not do.
|
|
286
|
+
|
|
287
|
+
CIP-0103 does not fix the signature format. The verifier accepts what the known wallets send and
|
|
288
|
+
refuses anything else:
|
|
289
|
+
|
|
290
|
+
- Loop (from its wallet code, not its documentation): Ed25519 over the UTF-8 message bytes, a
|
|
291
|
+
lowercase hex signature, and a lowercase hex raw 32-byte public key. Not yet confirmed against a
|
|
292
|
+
live DevNet signature: that Loop's backend relays the hex signature unchanged and that
|
|
293
|
+
`getPrimaryAccount` returns the key in the same hex form.
|
|
294
|
+
- The CIP-0103 reference wallet (splice-wallet-kernel): the same signature scheme, with base64
|
|
295
|
+
signature and key.
|
|
296
|
+
- Keys: 64 hex characters, base64 or base64url of the raw key or of its DER SubjectPublicKeyInfo, 88
|
|
297
|
+
hex characters of DER, or PEM. Signatures: 128 hex characters, or base64/base64url of 64 bytes.
|
|
298
|
+
ECDSA keys are refused.
|
|
116
299
|
|
|
117
300
|
## Repository setup and checks
|
|
118
301
|
|
|
@@ -10,4 +10,6 @@ export * from './external-signing-client';
|
|
|
10
10
|
export * from './generate-external-party';
|
|
11
11
|
export * from './prepare-external-transaction';
|
|
12
12
|
export * from './stellar-utils';
|
|
13
|
+
export * from './wallet-ownership';
|
|
14
|
+
export * from './wallet-ownership-challenger';
|
|
13
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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"}
|
|
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"}
|
|
@@ -26,4 +26,6 @@ __exportStar(require("./external-signing-client"), exports);
|
|
|
26
26
|
__exportStar(require("./generate-external-party"), exports);
|
|
27
27
|
__exportStar(require("./prepare-external-transaction"), exports);
|
|
28
28
|
__exportStar(require("./stellar-utils"), exports);
|
|
29
|
+
__exportStar(require("./wallet-ownership"), exports);
|
|
30
|
+
__exportStar(require("./wallet-ownership-challenger"), exports);
|
|
29
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"}
|
|
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,yBAAyB,CAYlE;AAED,MAAM,WAAW,gCAAgC;IAC/C,sBAAsB;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC;IACrC,oHAAoH;IACpH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,wFAAwF;IACxF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,2CAA2C;IAC3C,QAAQ,CAAC,UAAU,CAAC,EAAE,yBAAyB,CAAC;IAChD,oCAAoC;IACpC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,wBAAwB;IACvC,oGAAoG;IACpG,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;CAC7B;AAED,MAAM,WAA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,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;;;;;;;;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