@dexterai/connect 0.25.1 → 0.26.2

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 CHANGED
@@ -41,7 +41,7 @@ npm install @dexterai/connect @dexterai/vault react
41
41
  ```
42
42
 
43
43
  `@solana/web3.js` and `@worldcoin/idkit` are optional peers: the first for
44
- agent-spend signing, the second only if you use the World ID button.
44
+ passkey and agent-spend signing, the second only if you use the World ID button.
45
45
 
46
46
  ## Quick start
47
47
 
@@ -67,9 +67,27 @@ the wallet chip: address plus **"$X.XX available."**
67
67
 
68
68
  The ceremony is not limited to dexter.cash. On a foreign origin, `passkeyLogin`
69
69
  opens a hosted popup on `dexter.cash/connect`, runs the ceremony there, and
70
- posts the result back to your page (origin-checked and nonce-bound on both
71
- sides). The default `transport: 'auto'` picks the right mode; `'popup'` and
72
- `'inline'` force it.
70
+ posts the result back to your page. A browser-stamped hello/ack binds the exact
71
+ popup window, hosted origin, caller origin, request nonce, and requested
72
+ operation; the caller-origin may be any HTTPS website and is not allowlisted.
73
+ The default `transport: 'auto'` picks the right mode; `'popup'` and `'inline'`
74
+ force it.
75
+
76
+ The connected `passkeySigner.signOperation(rawOperation)` follows the same
77
+ cross-origin rule. On an unrelated website it opens the pinned Dexter consent
78
+ window and sends the raw operation plus the selected vault identity only after
79
+ the exact hello/ack handshake. Those bytes are structured-cloned in a
80
+ `sign-request`; they are never put in the URL. The Dexter window displays the
81
+ requesting origin and operation-specific consent before returning the
82
+ on-chain-ready assertion bytes.
83
+
84
+ WebAuthn challenge and verification calls are pinned to
85
+ `https://api.dexter.cash`. The legacy `apiBase` option remains source-compatible
86
+ only for that exact value (an optional trailing slash is normalized); any other
87
+ server fails before a popup, fetch, or authenticator call. `apiBase` is never
88
+ placed in the hosted popup URL. The legacy `connectHost` option is likewise
89
+ compatibility-only and may name only `https://dexter.cash/connect`; this pins
90
+ the credential-handling window without restricting the embedding website.
73
91
 
74
92
  ```ts
75
93
  import { passkeyLogin } from '@dexterai/connect';
@@ -209,8 +227,8 @@ React: `<SignInWithDexter mode="recover" preferImmediate onRecovered={…} />`
209
227
  | Peer | Required | Why |
210
228
  |---|---|---|
211
229
  | `react` >=18 | yes | the `/react` and `/worldid` surfaces |
212
- | `@dexterai/vault` >=0.30 | yes | signer + agent-spend message builders (0.30 matches the deployed program's account layout) |
213
- | `@solana/web3.js` | optional | agent-spend signing paths |
230
+ | `@dexterai/vault` ^0.43 | yes | hardened signer envelope validation + agent-spend message builders |
231
+ | `@solana/web3.js` | optional | passkey and agent-spend signing paths |
214
232
  | `@worldcoin/idkit` | optional | only for `/worldid` |
215
233
 
216
234
  The `/server` entry has none of these peers; it depends only on `jose`.
@@ -145,8 +145,40 @@ function authoredPolicy(usdInput) {
145
145
  // src/enroll.ts
146
146
  import { startRegistration } from "@simplewebauthn/browser";
147
147
 
148
+ // src/trust.ts
149
+ var DEXTER_API_BASE = "https://api.dexter.cash";
150
+ var DEXTER_CONNECT_HOST = "https://dexter.cash/connect";
151
+ var DEXTER_RP_ID = "dexter.cash";
152
+ function resolveDexterApiBase(apiBase) {
153
+ if (apiBase === void 0 || typeof apiBase === "string" && apiBase.replace(/\/+$/, "") === DEXTER_API_BASE) {
154
+ return DEXTER_API_BASE;
155
+ }
156
+ throw new ConnectError(
157
+ "untrusted_api_base",
158
+ `Dexter WebAuthn is pinned to ${DEXTER_API_BASE}`
159
+ );
160
+ }
161
+ function resolveDexterConnectHost(connectHost) {
162
+ if (connectHost === void 0 || typeof connectHost === "string" && connectHost.replace(/\/+$/, "") === DEXTER_CONNECT_HOST) {
163
+ return DEXTER_CONNECT_HOST;
164
+ }
165
+ throw new ConnectError(
166
+ "untrusted_connect_host",
167
+ `Dexter WebAuthn ceremonies are pinned to ${DEXTER_CONNECT_HOST}`
168
+ );
169
+ }
170
+ function resolveDexterRpId(rpId) {
171
+ if (rpId === void 0 || rpId === DEXTER_RP_ID) return DEXTER_RP_ID;
172
+ throw new ConnectError("untrusted_rp_id", `Dexter WebAuthn is pinned to ${DEXTER_RP_ID}`);
173
+ }
174
+ function bytesEqual(a, b) {
175
+ if (a.byteLength !== b.byteLength) return false;
176
+ let difference = 0;
177
+ for (let i = 0; i < a.byteLength; i += 1) difference |= a[i] ^ b[i];
178
+ return difference === 0;
179
+ }
180
+
148
181
  // src/popup.ts
149
- var DEFAULT_CONNECT_HOST = "https://dexter.cash/connect";
150
182
  var POPUP_TIMEOUT_MS = 12e4;
151
183
  var CANONICAL_ORIGIN = "https://dexter.cash";
152
184
  function shouldUsePopup(transport) {
@@ -159,13 +191,13 @@ function openCeremonyPopup(op, config = {}) {
159
191
  if (typeof window === "undefined") {
160
192
  return Promise.reject(new ConnectError("not_browser", "popup ceremony requires a browser"));
161
193
  }
162
- const host = (config.connectHost ?? DEFAULT_CONNECT_HOST).replace(/\/$/, "");
194
+ const host = resolveDexterConnectHost(config.connectHost);
163
195
  const hostOrigin = new URL(host).origin;
164
196
  const openerOrigin = window.location.origin;
165
197
  const requestId = makeNonce();
198
+ const signRequest = snapshotSignRequest(op, config.signRequest);
166
199
  const params = new URLSearchParams({ v: "1", op, requestId, origin: openerOrigin });
167
200
  if (config.name) params.set("name", config.name);
168
- if (config.apiBase) params.set("apiBase", config.apiBase);
169
201
  if (config.preferImmediate) params.set("preferImmediate", "1");
170
202
  const url = `${host}?${params.toString()}`;
171
203
  return new Promise((resolve, reject) => {
@@ -177,10 +209,46 @@ function openCeremonyPopup(op, config = {}) {
177
209
  return;
178
210
  }
179
211
  let settled = false;
212
+ let handshakeComplete = false;
180
213
  const onMessage = (event) => {
181
214
  if (event.origin !== hostOrigin) return;
215
+ if (event.source !== popup) return;
182
216
  const data = event.data;
183
- if (!data || data.type !== "dexter-connect:result" || data.requestId !== requestId) return;
217
+ if (!data || data.v !== 1 || data.requestId !== requestId || data.op !== op) return;
218
+ if (data.type === "dexter-connect:hello") {
219
+ if (handshakeComplete) return;
220
+ const ack = {
221
+ v: 1,
222
+ type: "dexter-connect:hello-ack",
223
+ requestId,
224
+ op
225
+ };
226
+ try {
227
+ popup.postMessage(ack, event.origin);
228
+ if (signRequest) {
229
+ const request = {
230
+ v: 1,
231
+ type: "dexter-connect:sign-request",
232
+ requestId,
233
+ op: "sign",
234
+ payload: signRequest
235
+ };
236
+ popup.postMessage(request, event.origin);
237
+ }
238
+ handshakeComplete = true;
239
+ } catch (err) {
240
+ finish(
241
+ () => reject(
242
+ new ConnectError(
243
+ "popup_handshake_failed",
244
+ err instanceof Error ? err.message : String(err)
245
+ )
246
+ )
247
+ );
248
+ }
249
+ return;
250
+ }
251
+ if (data.type !== "dexter-connect:result" || !handshakeComplete) return;
184
252
  if (data.ok) finish(() => resolve(data.result));
185
253
  else
186
254
  finish(
@@ -209,6 +277,47 @@ function openCeremonyPopup(op, config = {}) {
209
277
  window.addEventListener("message", onMessage);
210
278
  });
211
279
  }
280
+ function snapshotSignRequest(op, request) {
281
+ if (op !== "sign") {
282
+ if (request !== void 0) {
283
+ throw new ConnectError("unexpected_sign_request", "sign payload requires op=sign");
284
+ }
285
+ return void 0;
286
+ }
287
+ if (!request || !(request.operationMessage instanceof Uint8Array) || request.operationMessage.length === 0 || request.operationMessage.length > 4096) {
288
+ throw new ConnectError("missing_sign_request", "hosted signing requires raw operation bytes");
289
+ }
290
+ if (isAccountProofOperation(request.operationMessage)) {
291
+ throw new ConnectError(
292
+ "unsupported_operation",
293
+ "account-claim proofs cannot be requested by a third-party website"
294
+ );
295
+ }
296
+ const vault = request.vault;
297
+ if (!vault || !vault.vaultPda || !vault.publicKey || !vault.userHandle || !vault.credentialId) {
298
+ throw new ConnectError("invalid_sign_identity", "hosted signing requires a complete vault identity");
299
+ }
300
+ return {
301
+ // Snapshot before opening the window so caller mutation cannot change what
302
+ // the user sees/signs after the ceremony begins.
303
+ operationMessage: new Uint8Array(request.operationMessage),
304
+ vault: {
305
+ vaultPda: vault.vaultPda,
306
+ publicKey: vault.publicKey,
307
+ userHandle: vault.userHandle,
308
+ credentialId: vault.credentialId,
309
+ ...vault.walletLabel !== void 0 ? { walletLabel: vault.walletLabel } : {}
310
+ }
311
+ };
312
+ }
313
+ function isAccountProofOperation(operation) {
314
+ const prefix = new TextEncoder().encode("siwx_login");
315
+ if (operation.length !== prefix.length + 32) return false;
316
+ for (let i = 0; i < prefix.length; i += 1) {
317
+ if (operation[i] !== prefix[i]) return false;
318
+ }
319
+ return true;
320
+ }
212
321
  function popupFeatures() {
213
322
  const w = 420;
214
323
  const h = 660;
@@ -242,15 +351,14 @@ async function readErrorCode(res) {
242
351
  }
243
352
 
244
353
  // src/enroll.ts
245
- var DEFAULT_API_BASE = "https://api.dexter.cash";
246
- var DEFAULT_RP_ID = "dexter.cash";
247
354
  var DEFAULT_WALLET_NAME = "Dexter Wallet";
248
355
  async function createWallet(config = {}) {
356
+ const apiBase = resolveDexterApiBase(config.apiBase);
357
+ resolveDexterRpId(config.rpId);
249
358
  if (shouldUsePopup(config.transport)) {
250
359
  const result = await openCeremonyPopup("create", {
251
360
  connectHost: config.connectHost,
252
- name: config.name,
253
- apiBase: config.apiBase
361
+ name: config.name
254
362
  });
255
363
  setActiveHandle(result.handle, result.label ?? config.name, result.credentialId);
256
364
  return result;
@@ -258,15 +366,13 @@ async function createWallet(config = {}) {
258
366
  if (typeof navigator === "undefined" || !navigator.credentials) {
259
367
  throw new ConnectError("webauthn_unsupported", "WebAuthn unavailable in this environment");
260
368
  }
261
- const apiBase = (config.apiBase ?? DEFAULT_API_BASE).replace(/\/$/, "");
262
- const rpId = config.rpId ?? DEFAULT_RP_ID;
263
369
  const name = config.name && config.name.trim() || DEFAULT_WALLET_NAME;
264
370
  config.onPhase?.("challenge");
265
371
  const options = await fetchEnrollChallenge(apiBase);
266
372
  config.onPhase?.("passkey");
267
373
  const optionsJSON = {
268
374
  ...options,
269
- rp: { ...options.rp, id: options.rp.id ?? rpId, name: "Dexter" },
375
+ rp: { ...options.rp, id: DEXTER_RP_ID, name: "Dexter" },
270
376
  user: { ...options.user, name, displayName: name }
271
377
  };
272
378
  let regResponse;
@@ -316,6 +422,7 @@ async function fetchEnrollChallenge(apiBase) {
316
422
  if (!data?.options?.challenge) {
317
423
  throw new ConnectError("enroll_challenge_malformed", "no creation options in response");
318
424
  }
425
+ resolveDexterRpId(data.options.rp?.id);
319
426
  return data.options;
320
427
  }
321
428
  async function submitEnrollComplete(apiBase, response) {
@@ -366,10 +473,6 @@ function bytesToBase64(bytes) {
366
473
  function bytesToBase64url(bytes) {
367
474
  return bytesToBase64(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
368
475
  }
369
- function base64urlToBase64(s) {
370
- const t = s.replace(/-/g, "+").replace(/_/g, "/");
371
- return t + "=".repeat((4 - t.length % 4) % 4);
372
- }
373
476
  function compactSignatureToDer(compact) {
374
477
  if (compact.length !== 64) {
375
478
  throw new Error(`expected 64-byte compact signature, got ${compact.length}`);
@@ -463,14 +566,13 @@ function classifyWebAuthnRejection(err) {
463
566
  }
464
567
 
465
568
  // src/relay.ts
466
- var DEFAULT_API_BASE2 = "https://api.dexter.cash";
467
569
  var ANON_SIGN_BASE = "/api/passkey-anon/sign";
468
570
  primeImmediateSupport();
469
571
  async function passkeyLogin(config = {}, onPhase) {
572
+ const apiBase = resolveDexterApiBase(config.apiBase);
470
573
  if (shouldUsePopup(config.transport)) {
471
574
  const result2 = await openCeremonyPopup("signin", {
472
- connectHost: config.connectHost,
473
- apiBase: config.apiBase
575
+ connectHost: config.connectHost
474
576
  });
475
577
  if (result2.vault) {
476
578
  setActiveHandle(result2.vault.userHandle, result2.vault.walletLabel ?? void 0, result2.vault.credentialId);
@@ -480,7 +582,6 @@ async function passkeyLogin(config = {}, onPhase) {
480
582
  if (!browserSupportsWebAuthn()) {
481
583
  throw new ConnectError("webauthn_unsupported", "WebAuthn unavailable in this environment");
482
584
  }
483
- const apiBase = (config.apiBase ?? DEFAULT_API_BASE2).replace(/\/$/, "");
484
585
  onPhase?.("challenge");
485
586
  const options = await fetchLoginChallenge(apiBase);
486
587
  onPhase?.("passkey");
@@ -498,11 +599,11 @@ async function passkeyLogin(config = {}, onPhase) {
498
599
  return result;
499
600
  }
500
601
  async function continueWithDexter(config = {}, onPhase) {
602
+ resolveDexterApiBase(config.apiBase);
501
603
  if (shouldUsePopup(config.transport)) {
502
604
  const result = await openCeremonyPopup("continue", {
503
605
  connectHost: config.connectHost,
504
- name: config.name,
505
- apiBase: config.apiBase
606
+ name: config.name
506
607
  });
507
608
  if (result.kind === "create") {
508
609
  setActiveHandle(result.handle, result.label ?? config.name, result.credentialId);
@@ -526,7 +627,7 @@ async function continueWithDexter(config = {}, onPhase) {
526
627
  return { kind: "needs_choice" };
527
628
  }
528
629
  async function immediatePasskeyLogin(config, onPhase) {
529
- const apiBase = (config.apiBase ?? DEFAULT_API_BASE2).replace(/\/$/, "");
630
+ const apiBase = resolveDexterApiBase(config.apiBase);
530
631
  onPhase?.("challenge");
531
632
  const options = await fetchLoginChallenge(apiBase);
532
633
  onPhase?.("passkey");
@@ -563,7 +664,7 @@ async function fetchLoginChallenge(apiBase) {
563
664
  if (!data?.options?.challenge) {
564
665
  throw new ConnectError("login_challenge_malformed", "no challenge in response");
565
666
  }
566
- return data.options;
667
+ return { ...data.options, rpId: resolveDexterRpId(data.options.rpId) };
567
668
  }
568
669
  async function submitLogin(apiBase, response) {
569
670
  const res = await fetch(`${apiBase}${ANON_SIGN_BASE}/passkey-login`, {
@@ -586,18 +687,19 @@ async function submitLogin(apiBase, response) {
586
687
  }
587
688
 
588
689
  // src/anon-policy.ts
589
- var DEFAULT_API_BASE3 = "https://api.dexter.cash";
590
690
  var ANON_SIGN_BASE2 = "/api/passkey-anon/sign";
591
- function createAnonServerPolicy(apiBase = DEFAULT_API_BASE3) {
592
- const base = apiBase.replace(/\/$/, "");
691
+ function createAnonServerPolicy(apiBase) {
692
+ const base = resolveDexterApiBase(apiBase);
593
693
  return {
594
- async issueChallenge({ userHandle, operationHash }) {
694
+ async issueChallenge({ userHandle, operationMessage, operationHash }) {
595
695
  const res = await fetch(`${base}${ANON_SIGN_BASE2}/challenge`, {
596
696
  method: "POST",
597
697
  headers: { "content-type": "application/json" },
598
698
  body: JSON.stringify({
599
699
  userHandle: bytesToBase64url(userHandle),
600
- operationHash: bytesToBase64url(operationHash)
700
+ operationHash: bytesToBase64url(operationHash),
701
+ operationMessage: bytesToBase64url(operationMessage),
702
+ operation: "vault_operation"
601
703
  })
602
704
  });
603
705
  if (!res.ok) throw new ConnectError(await readErrorCode(res), `challenge ${res.status}`);
@@ -606,14 +708,15 @@ function createAnonServerPolicy(apiBase = DEFAULT_API_BASE3) {
606
708
  if (!options?.challenge) {
607
709
  throw new ConnectError("challenge_malformed", "no challenge in response");
608
710
  }
711
+ const challenge = base64urlToBytes(options.challenge);
609
712
  const cred = options.allowCredentials?.[0];
610
713
  if (!cred?.id) {
611
714
  throw new ConnectError("no_credential", "no allow-listed credential for this userHandle");
612
715
  }
613
716
  return {
614
- challenge: base64urlToBytes(options.challenge),
717
+ challenge,
615
718
  credentialId: base64urlToBytes(cred.id),
616
- rpId: options.rpId,
719
+ rpId: resolveDexterRpId(options.rpId),
617
720
  transports: cred.transports
618
721
  };
619
722
  },
@@ -625,7 +728,7 @@ function createAnonServerPolicy(apiBase = DEFAULT_API_BASE3) {
625
728
  response: {
626
729
  clientDataJSON: bytesToBase64url(clientDataJSON),
627
730
  authenticatorData: bytesToBase64url(authenticatorData),
628
- // SDK 0.19 passes the COMPACT sig; dexter-api's verifier wants DER.
731
+ // The SDK passes the COMPACT sig; dexter-api's verifier wants DER.
629
732
  signature: bytesToBase64url(compactSignatureToDer(signature)),
630
733
  userHandle: null
631
734
  },
@@ -639,8 +742,8 @@ function createAnonServerPolicy(apiBase = DEFAULT_API_BASE3) {
639
742
  });
640
743
  if (!res.ok) throw new ConnectError(await readErrorCode(res), `verify ${res.status}`);
641
744
  const data = await res.json();
642
- if (data?.verified === false) {
643
- throw new ConnectError("verification_failed", "server returned verified=false");
745
+ if (data?.verified !== true) {
746
+ throw new ConnectError("verification_failed", "server did not return verified=true");
644
747
  }
645
748
  }
646
749
  };
@@ -648,14 +751,106 @@ function createAnonServerPolicy(apiBase = DEFAULT_API_BASE3) {
648
751
 
649
752
  // src/signer.ts
650
753
  import { DexterApiBrowserPasskeySigner } from "@dexterai/vault/signers/browser";
754
+ import {
755
+ parseStrictCollectedClientData,
756
+ validatePasskeyAuthorizationChallenge
757
+ } from "@dexterai/vault";
758
+ import { PublicKey } from "@solana/web3.js";
759
+ var HostedPopupPasskeySigner = class {
760
+ constructor(vault, expectedVault, connectHost) {
761
+ this.expectedVault = expectedVault;
762
+ this.connectHost = connectHost;
763
+ this.vault = { ...vault };
764
+ this.credentialId = base64urlToBytes(vault.credentialId);
765
+ this.publicKey = base64ToBytes(vault.publicKey);
766
+ }
767
+ expectedVault;
768
+ connectHost;
769
+ credentialId;
770
+ publicKey;
771
+ vault;
772
+ async signOperation(operationMessage) {
773
+ if (!(operationMessage instanceof Uint8Array) || operationMessage.length === 0) {
774
+ throw new ConnectError("invalid_operation", "signOperation requires non-empty bytes");
775
+ }
776
+ const exactOperationMessage = new Uint8Array(operationMessage);
777
+ const result = await openCeremonyPopup("sign", {
778
+ ...this.connectHost ? { connectHost: this.connectHost } : {},
779
+ signRequest: {
780
+ operationMessage: exactOperationMessage,
781
+ vault: {
782
+ vaultPda: this.vault.vaultPda,
783
+ publicKey: this.vault.publicKey,
784
+ userHandle: this.vault.userHandle,
785
+ credentialId: this.vault.credentialId,
786
+ ...this.vault.walletLabel !== void 0 ? { walletLabel: this.vault.walletLabel } : {}
787
+ }
788
+ }
789
+ });
790
+ return validateHostedSignResult(result, exactOperationMessage, this.expectedVault);
791
+ }
792
+ };
651
793
  function createPasskeySigner(vault, apiBase, opts = {}) {
794
+ resolveDexterApiBase(apiBase);
795
+ const expectedVault = new PublicKey(vault.vaultPda);
796
+ if (shouldUsePopup()) {
797
+ return new HostedPopupPasskeySigner(vault, expectedVault, opts.connectHost);
798
+ }
652
799
  return new DexterApiBrowserPasskeySigner({
653
800
  identity: { kind: "guest", userHandle: base64urlToBytes(vault.userHandle) },
654
801
  publicKey: base64ToBytes(vault.publicKey),
655
802
  anonPolicy: createAnonServerPolicy(apiBase),
803
+ // The API resolves the authorization envelope, but this browser still
804
+ // knows which connected vault the caller selected. Pin that exact PDA so a
805
+ // valid Dexter envelope for another vault cannot reach WebAuthn.
806
+ expectedVault,
656
807
  ...opts.__assertion ? { __assertion: opts.__assertion } : {}
657
808
  });
658
809
  }
810
+ async function validateHostedSignResult(result, operationMessage, expectedVault) {
811
+ if (!result || !(result.signature instanceof Uint8Array) || result.signature.length !== 64 || !(result.clientDataJSON instanceof Uint8Array) || result.clientDataJSON.length === 0 || !(result.authenticatorData instanceof Uint8Array) || result.authenticatorData.length < 37) {
812
+ throw new ConnectError("popup_result_malformed", "hosted signer returned malformed assertion bytes");
813
+ }
814
+ let clientData;
815
+ try {
816
+ clientData = parseStrictCollectedClientData(result.clientDataJSON);
817
+ } catch {
818
+ throw new ConnectError("popup_result_malformed", "hosted signer returned invalid clientDataJSON");
819
+ }
820
+ if (clientData.type !== "webauthn.get" || clientData.origin !== "https://dexter.cash" || clientData.crossOrigin !== false || !/^[A-Za-z0-9_-]+$/.test(clientData.challenge)) {
821
+ throw new ConnectError("popup_result_malformed", "hosted signer returned invalid WebAuthn client data");
822
+ }
823
+ const expectedRpHash = new Uint8Array(
824
+ await crypto.subtle.digest("SHA-256", new TextEncoder().encode("dexter.cash"))
825
+ );
826
+ const flags = result.authenticatorData[32] ?? 0;
827
+ if (!bytesEqual(result.authenticatorData.subarray(0, 32), expectedRpHash) || (flags & 1) === 0 || (flags & 4) === 0) {
828
+ throw new ConnectError("popup_result_malformed", "hosted signer returned invalid authenticator context");
829
+ }
830
+ let challenge;
831
+ try {
832
+ challenge = base64urlToBytes(clientData.challenge);
833
+ if (bytesToBase64url(challenge) !== clientData.challenge) throw new Error("non-canonical");
834
+ } catch {
835
+ throw new ConnectError("popup_result_malformed", "hosted signer returned an invalid challenge encoding");
836
+ }
837
+ try {
838
+ const operationHash = new Uint8Array(
839
+ await crypto.subtle.digest("SHA-256", new Uint8Array(operationMessage))
840
+ );
841
+ validatePasskeyAuthorizationChallenge({ challenge, operationHash, expectedVault });
842
+ } catch {
843
+ throw new ConnectError(
844
+ "popup_result_unbound",
845
+ "hosted signer returned an assertion for a different operation or vault"
846
+ );
847
+ }
848
+ return {
849
+ signature: new Uint8Array(result.signature),
850
+ clientDataJSON: new Uint8Array(result.clientDataJSON),
851
+ authenticatorData: new Uint8Array(result.authenticatorData)
852
+ };
853
+ }
659
854
 
660
855
  // src/identity.ts
661
856
  function presentOrNull(value) {
@@ -674,16 +869,20 @@ function resolveIdentity(input) {
674
869
 
675
870
  // src/recover.ts
676
871
  import { startAuthentication as startAuthentication2, browserSupportsWebAuthn as browserSupportsWebAuthn2 } from "@simplewebauthn/browser";
677
- var DEFAULT_API_BASE4 = "https://api.dexter.cash";
678
872
  var ANON_SIGN_BASE3 = "/api/passkey-anon/sign";
679
873
  primeImmediateSupport();
680
874
  async function recoverWallet(config = {}) {
875
+ let apiBase;
876
+ try {
877
+ apiBase = resolveDexterApiBase(config.apiBase);
878
+ } catch (err) {
879
+ return netError("untrusted_api_base", err);
880
+ }
681
881
  if (shouldUsePopup(config.transport)) {
682
882
  let outcome;
683
883
  try {
684
884
  outcome = await openCeremonyPopup("recover", {
685
885
  connectHost: config.connectHost,
686
- apiBase: config.apiBase,
687
886
  preferImmediate: config.preferImmediate
688
887
  });
689
888
  } catch (err) {
@@ -703,7 +902,6 @@ async function recoverWallet(config = {}) {
703
902
  error: new ConnectError("webauthn_unsupported", "WebAuthn unavailable in this environment")
704
903
  };
705
904
  }
706
- const apiBase = (config.apiBase ?? DEFAULT_API_BASE4).replace(/\/$/, "");
707
905
  const onPhase = config.onPhase;
708
906
  onPhase?.("challenge");
709
907
  let options;
@@ -714,8 +912,19 @@ async function recoverWallet(config = {}) {
714
912
  body: "{}"
715
913
  });
716
914
  if (!res.ok) return { ok: false, reason: "error", error: new ConnectError(await readErrorCode(res)) };
717
- options = (await res.json()).options;
915
+ const serverOptions = (await res.json()).options;
916
+ if (!serverOptions?.challenge) {
917
+ return {
918
+ ok: false,
919
+ reason: "error",
920
+ error: new ConnectError("recover_challenge_malformed", "no challenge in response")
921
+ };
922
+ }
923
+ options = { ...serverOptions, rpId: resolveDexterRpId(serverOptions.rpId) };
718
924
  } catch (err) {
925
+ if (err instanceof ConnectError && err.code === "untrusted_rp_id") {
926
+ return { ok: false, reason: "error", error: err };
927
+ }
719
928
  return netError("recover_challenge_failed", err);
720
929
  }
721
930
  onPhase?.("passkey");
@@ -858,6 +1067,10 @@ async function syncAcceptedPasskeys(args) {
858
1067
 
859
1068
  export {
860
1069
  ConnectError,
1070
+ resolveDexterApiBase,
1071
+ resolveDexterRpId,
1072
+ bytesEqual,
1073
+ shouldUsePopup,
861
1074
  getActiveHandle,
862
1075
  setActiveHandle,
863
1076
  getCredentialId,
@@ -871,8 +1084,9 @@ export {
871
1084
  usdToAtomic,
872
1085
  authoredPolicy,
873
1086
  createWallet,
1087
+ base64urlToBytes,
1088
+ bytesToBase64,
874
1089
  bytesToBase64url,
875
- base64urlToBase64,
876
1090
  passkeyLogin,
877
1091
  continueWithDexter,
878
1092
  createAnonServerPolicy,
@@ -7,7 +7,7 @@ var BUTTON_CSS = `
7
7
  @keyframes dx-pulse { 0%,100% { opacity: 1; } 50% { opacity: .6; } }
8
8
  .dx-btn{
9
9
  position:relative; display:inline-flex; align-items:center; justify-content:center; gap:10px;
10
- padding:11px 22px; border:1px solid color-mix(in srgb,var(--dx-ember,#f26c18) 55%,transparent);
10
+ min-height:48px; padding:11px 22px; border:1px solid color-mix(in srgb,var(--dx-ember,#f26c18) 55%,transparent);
11
11
  border-radius:var(--dx-radius,0px);
12
12
  background:linear-gradient(135deg,var(--dx-ember,#f26c18),var(--dx-ember-2,#ba3a00));
13
13
  color:var(--dx-fg,#fff4ea); font:inherit; font-weight:600; font-size:.78rem; letter-spacing:.12em;
@@ -44,7 +44,7 @@ var BUTTON_CSS = `
44
44
  .dx-btn--danger:focus-visible{ box-shadow:0 0 0 3px color-mix(in srgb,var(--dx-danger,#b3261e) 38%,transparent); }
45
45
  .dx-btn--block{ width:100%; }
46
46
  .dx-btn--sm{
47
- padding:7px 14px; gap:7px; font-size:.66rem; letter-spacing:.1em;
47
+ min-height:40px; padding:7px 14px; gap:7px; font-size:.66rem; letter-spacing:.1em;
48
48
  box-shadow:0 8px 16px color-mix(in srgb,var(--dx-ember,#f26c18) 18%,transparent);
49
49
  }
50
50
  .dx-btn--sm:hover{ box-shadow:0 12px 22px color-mix(in srgb,var(--dx-ember,#f26c18) 26%,transparent); }
@@ -62,6 +62,11 @@ var BUTTON_CSS = `
62
62
  .dx-chip__bal{ font-weight:600; opacity:.85; }
63
63
  .dx-chip__x{ margin-left:2px; border:none; background:transparent; color:inherit; cursor:pointer; font-size:16px; line-height:1; opacity:.6; }
64
64
  .dx-chip__x:hover{ opacity:1; }
65
+ @media (prefers-reduced-motion:reduce){
66
+ .dx-btn{ transition:none; }
67
+ .dx-btn:hover,.dx-btn:active{ transform:none; }
68
+ .dx-btn__spin,.dx-btn__doing{ animation:none; }
69
+ }
65
70
  `;
66
71
  function ensureDexterButtonStyles() {
67
72
  if (typeof document === "undefined") return;