@orangecheck/auth-client 2.50.1 → 2.52.0

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.
Files changed (37) hide show
  1. package/dist/bond.mjs +4 -4
  2. package/dist/{chunk-NJEQHNVI.mjs → chunk-2FBI2M6N.mjs} +324 -41
  3. package/dist/chunk-2FBI2M6N.mjs.map +1 -0
  4. package/dist/{chunk-XVLOTOCX.mjs → chunk-6UIOGWHT.mjs} +96 -4
  5. package/dist/chunk-6UIOGWHT.mjs.map +1 -0
  6. package/dist/{chunk-MIBVEZLP.mjs → chunk-7VBIHZVF.mjs} +3 -3
  7. package/dist/chunk-F6XAMBPI.mjs +107 -0
  8. package/dist/chunk-F6XAMBPI.mjs.map +1 -0
  9. package/dist/{chunk-IKNAIRW5.mjs → chunk-FDN374RW.mjs} +2 -2
  10. package/dist/{chunk-OKIFTNEO.mjs → chunk-HQ6APBHF.mjs} +8 -2
  11. package/dist/{chunk-OKIFTNEO.mjs.map → chunk-HQ6APBHF.mjs.map} +1 -1
  12. package/dist/{chunk-MGZ4NVXW.mjs → chunk-LKYBT4Q7.mjs} +5 -5
  13. package/dist/chunk-QHZ6E64O.mjs +61 -0
  14. package/dist/chunk-QHZ6E64O.mjs.map +1 -0
  15. package/dist/{chunk-2NCLRIVO.mjs → chunk-W6YYHOYL.mjs} +3 -3
  16. package/dist/chunk-W6YYHOYL.mjs.map +1 -0
  17. package/dist/components.mjs +3 -3
  18. package/dist/held-link.mjs +19 -0
  19. package/dist/held-link.mjs.map +1 -0
  20. package/dist/index.d.ts +34 -2
  21. package/dist/index.js +547 -37
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +22 -18
  24. package/dist/linked-identities.mjs +2 -2
  25. package/dist/passkey.mjs +9 -0
  26. package/dist/passkey.mjs.map +1 -0
  27. package/dist/provider.mjs +2 -2
  28. package/dist/refusal.mjs +1 -1
  29. package/dist/signin.mjs +7 -5
  30. package/dist/webauthn.mjs +6 -3
  31. package/package.json +1 -1
  32. package/dist/chunk-2NCLRIVO.mjs.map +0 -1
  33. package/dist/chunk-NJEQHNVI.mjs.map +0 -1
  34. package/dist/chunk-XVLOTOCX.mjs.map +0 -1
  35. /package/dist/{chunk-MIBVEZLP.mjs.map → chunk-7VBIHZVF.mjs.map} +0 -0
  36. /package/dist/{chunk-IKNAIRW5.mjs.map → chunk-FDN374RW.mjs.map} +0 -0
  37. /package/dist/{chunk-MGZ4NVXW.mjs.map → chunk-LKYBT4Q7.mjs.map} +0 -0
package/dist/index.js CHANGED
@@ -4,8 +4,8 @@ var React4 = require('react');
4
4
  var familyOrigins = require('@orangecheck/auth-core/family-origins');
5
5
  var identifiers = require('@orangecheck/auth-core/identifiers');
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
- var bip322 = require('@orangecheck/bip322');
8
7
  var browser = require('@simplewebauthn/browser');
8
+ var bip322 = require('@orangecheck/bip322');
9
9
 
10
10
  function _interopNamespace(e) {
11
11
  if (e && e.__esModule) return e;
@@ -385,6 +385,12 @@ var EMAIL_ERRORS = {
385
385
  signed_out: "You were signed out while signing in. Send a new code to sign in again.",
386
386
  no_roster: "An account in this browser was signed out while you were signing in, so this sign-in wasn't kept. Send a new code to sign in again."
387
387
  };
388
+ var PASSKEY_ERRORS = {
389
+ passkey_not_for_signin: "That passkey isn't set up to sign in. Sign in another way, then turn it on for sign-in in your account.",
390
+ passkey_not_recognised: "That passkey isn't on any orangecheck account. It may have been removed. Sign in another way.",
391
+ cancelled: "The passkey prompt closed. Try again when you are ready.",
392
+ passkey_failed: "Your device couldn't use a passkey. Try again, or sign in another way."
393
+ };
388
394
  var SUBMIT_ERRORS = {
389
395
  bad_request: "That signature couldn't be read. Copy it again, whole."
390
396
  };
@@ -398,7 +404,7 @@ function networkError(authOrigin) {
398
404
  }
399
405
  function humanSigninError(reason, path, step = "challenge") {
400
406
  if (!/^[a-z0-9_]+$/.test(reason)) return reason;
401
- const own = path === "wallet" && step === "submit" && ownWord(SUBMIT_ERRORS, reason) || path === "email" && ownWord(EMAIL_ERRORS, reason);
407
+ const own = path === "wallet" && step === "submit" && ownWord(SUBMIT_ERRORS, reason) || path === "email" && ownWord(EMAIL_ERRORS, reason) || path === "passkey" && ownWord(PASSKEY_ERRORS, reason);
402
408
  if (own) return own;
403
409
  return ownWord(SIGNIN_ERRORS, reason) ?? (path === "email" ? "That didn't work. Try again, or send a new code." : "That didn't work. Try again.");
404
410
  }
@@ -1539,6 +1545,103 @@ function DesignRadio({ checked, disabled, ...props }) {
1539
1545
  ] });
1540
1546
  }
1541
1547
 
1548
+ // src/held-link.ts
1549
+ var KEY_STORAGE = "oc-signin-link-key";
1550
+ var KEY_RE = /^[A-Za-z0-9_-]{43}$/;
1551
+ var SECRET_RE = /^[A-Za-z0-9_-]{43}$/;
1552
+ var PART_RE = /^[A-Za-z0-9_-]+$/;
1553
+ var LINK_FRAGMENT = "#oc-link=";
1554
+ function storage() {
1555
+ try {
1556
+ return typeof window === "undefined" ? null : window.localStorage;
1557
+ } catch {
1558
+ return null;
1559
+ }
1560
+ }
1561
+ function base64url(bytes) {
1562
+ let s = "";
1563
+ for (const b of bytes) s += String.fromCharCode(b);
1564
+ return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
1565
+ }
1566
+ function readLinkKey() {
1567
+ try {
1568
+ const v = storage()?.getItem(KEY_STORAGE);
1569
+ return v && KEY_RE.test(v) ? v : void 0;
1570
+ } catch {
1571
+ return void 0;
1572
+ }
1573
+ }
1574
+ async function linkBind() {
1575
+ const store2 = storage();
1576
+ if (!store2 || !globalThis.crypto?.subtle) return void 0;
1577
+ let key = readLinkKey();
1578
+ try {
1579
+ if (!key) {
1580
+ key = base64url(crypto.getRandomValues(new Uint8Array(32)));
1581
+ store2.setItem(KEY_STORAGE, key);
1582
+ if (store2.getItem(KEY_STORAGE) !== key) return void 0;
1583
+ }
1584
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(key));
1585
+ return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
1586
+ } catch {
1587
+ return void 0;
1588
+ }
1589
+ }
1590
+ function parseHeldLink(hash) {
1591
+ if (!hash.startsWith(LINK_FRAGMENT)) return null;
1592
+ const raw = hash.slice(LINK_FRAGMENT.length);
1593
+ const cut = raw.lastIndexOf(".");
1594
+ if (cut < 0) return null;
1595
+ const token = raw.slice(0, cut);
1596
+ const secret = raw.slice(cut + 1);
1597
+ if (!SECRET_RE.test(secret)) return null;
1598
+ const parts = token.split(".");
1599
+ if (parts.length !== 3 || !parts.every((p) => PART_RE.test(p))) return null;
1600
+ let payload;
1601
+ try {
1602
+ const b64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
1603
+ payload = JSON.parse(atob(b64 + "=".repeat((4 - b64.length % 4) % 4)));
1604
+ } catch {
1605
+ return null;
1606
+ }
1607
+ const { email, exp } = payload;
1608
+ if (payload.purpose !== "email-otp" || payload.ceremony !== "signin") return null;
1609
+ if (typeof email !== "string" || typeof exp !== "number") return null;
1610
+ return { token, secret, email, exp };
1611
+ }
1612
+ function maskEmail(email) {
1613
+ const at = email.lastIndexOf("@");
1614
+ if (at < 1) return email;
1615
+ return `${email[0]}***${email.slice(at)}`;
1616
+ }
1617
+ var FINAL_LINK_REFUSALS = /* @__PURE__ */ new Set([
1618
+ "wrong_browser",
1619
+ "replay",
1620
+ "expired",
1621
+ "invalid_token",
1622
+ "email_mismatch",
1623
+ "wrong_link"
1624
+ ]);
1625
+ function heldLinkRefusalText(reason) {
1626
+ switch (reason) {
1627
+ case "wrong_browser":
1628
+ return "This link works only in the browser where you asked to sign in. Open it there, or ask for a new link here.";
1629
+ case "replay":
1630
+ return "This link was already used. Ask for a new one.";
1631
+ case "expired":
1632
+ return "This link has expired. Ask for a new one.";
1633
+ case "invalid_token":
1634
+ case "email_mismatch":
1635
+ return "This link has expired or is not complete. Ask for a new one.";
1636
+ case "wrong_link":
1637
+ return "This link is not complete. Open it from the email again.";
1638
+ case "rate_limited":
1639
+ return "Too many tries just now. Wait a minute, then press it again.";
1640
+ default:
1641
+ return "That didn't work. Press it again in a minute.";
1642
+ }
1643
+ }
1644
+
1542
1645
  // src/sudo.tsx
1543
1646
  function redirectToSudo(args = {}) {
1544
1647
  if (typeof window === "undefined") {
@@ -1972,7 +2075,7 @@ function EmailLinkForm({
1972
2075
  setBusy(true);
1973
2076
  setErr(null);
1974
2077
  try {
1975
- const r = await fetch(`${authOrigin}/api/auth/email-otp/start`, {
2078
+ const r = await fetch(`${authOrigin}/api/auth/link/email-code`, {
1976
2079
  method: "POST",
1977
2080
  credentials: "include",
1978
2081
  headers: { "Content-Type": "application/json" },
@@ -2489,6 +2592,56 @@ var primaryChipStyle = {
2489
2592
  color: V.primary,
2490
2593
  border: `1px solid ${V.primary}`
2491
2594
  };
2595
+ var prompting = 0;
2596
+ function cancelPasskeyAutofill() {
2597
+ if (prompting === 0) browser.WebAuthnAbortService.cancelCeremony();
2598
+ }
2599
+ function isCancel(err) {
2600
+ return err instanceof Error && /NotAllowed|Abort|aborted|cancel/i.test(`${err.name} ${err.message}`);
2601
+ }
2602
+ function signalUnknown(rpId, credentialId) {
2603
+ const pkc = globalThis.PublicKeyCredential;
2604
+ if (!rpId || typeof pkc?.signalUnknownCredential !== "function") return;
2605
+ void pkc.signalUnknownCredential({ rpId, credentialId }).catch(() => {
2606
+ });
2607
+ }
2608
+ async function passkeyCeremony(args) {
2609
+ const { authOrigin, kind, credentials } = args;
2610
+ const optsRes = await fetch(`${authOrigin}/api/auth/passkey/options`, {
2611
+ method: "POST",
2612
+ credentials,
2613
+ headers: { "Content-Type": "application/json" },
2614
+ body: JSON.stringify({ kind, ...args.add ? { add: true } : {} })
2615
+ });
2616
+ const opts = await optsRes.json();
2617
+ if (!optsRes.ok || !opts.ok || !opts.options || !opts.challenge_token) {
2618
+ return { ok: false, reason: opts.reason ?? `options_failed_${optsRes.status}`, step: "options" };
2619
+ }
2620
+ const autofill = args.autofill === true;
2621
+ if (autofill && prompting > 0) return { ok: false, reason: "cancelled", step: "prompt" };
2622
+ let response;
2623
+ if (!autofill) prompting++;
2624
+ try {
2625
+ response = await browser.startAuthentication({ optionsJSON: opts.options, useBrowserAutofill: autofill });
2626
+ } catch (err) {
2627
+ return { ok: false, reason: isCancel(err) ? "cancelled" : "passkey_failed", step: "prompt" };
2628
+ } finally {
2629
+ if (!autofill) prompting--;
2630
+ }
2631
+ const verifyRes = await fetch(`${authOrigin}/api/auth/passkey/verify`, {
2632
+ method: "POST",
2633
+ credentials,
2634
+ headers: { "Content-Type": "application/json" },
2635
+ body: JSON.stringify({ challenge_token: opts.challenge_token, response })
2636
+ });
2637
+ const body = await verifyRes.json();
2638
+ if (!verifyRes.ok || !body.ok || !body.account) {
2639
+ const reason = body.reason ?? `verify_failed_${verifyRes.status}`;
2640
+ if (reason === "passkey_not_recognised") signalUnknown(opts.options.rpId, response.id);
2641
+ return { ok: false, reason, step: "verify" };
2642
+ }
2643
+ return { ok: true, account: body.account, ...body.token ? { token: body.token } : {} };
2644
+ }
2492
2645
  function isSameOriginPath(candidate, origin) {
2493
2646
  try {
2494
2647
  return new URL(candidate, origin).origin === origin;
@@ -2565,13 +2718,17 @@ function OcSignIn({
2565
2718
  paths,
2566
2719
  className,
2567
2720
  mode,
2568
- providerHref
2721
+ providerHref,
2722
+ passkey = "off"
2569
2723
  }) {
2570
- const walletEnabled = paths?.wallet ?? true;
2571
- const emailEnabled = paths?.email ?? true;
2724
+ const passkeyOnly = passkey === "only";
2725
+ const layered = passkey === "layered";
2726
+ const walletEnabled = !passkeyOnly && (paths?.wallet ?? true);
2727
+ const emailEnabled = !passkeyOnly && !layered && (paths?.email ?? true);
2572
2728
  const firstParty = mode === "first-party";
2573
2729
  const credentials = firstParty ? "omit" : "include";
2574
- const linkPrompt = linkPromptProp && !firstParty;
2730
+ const linkPrompt = linkPromptProp && !firstParty && !passkeyOnly && !layered;
2731
+ const [layering, setLayering] = React4__namespace.useState(false);
2575
2732
  const providerSession = useOptionalOcSession();
2576
2733
  const recheck = onSeveralSessions ?? providerSession?.refresh;
2577
2734
  const [resolvedReturn, setResolvedReturn] = React4__namespace.useState(
@@ -2633,6 +2790,14 @@ function OcSignIn({
2633
2790
  });
2634
2791
  if (OAUTH_EMAIL_CODE_REASONS.has(reason) && emailEnabled) setPath("email");
2635
2792
  }, [emailEnabled]);
2793
+ const [heldLink, setHeldLink] = React4__namespace.useState(null);
2794
+ React4__namespace.useEffect(() => {
2795
+ if (!firstParty || typeof window === "undefined") return;
2796
+ const { hash, pathname, search } = window.location;
2797
+ if (!hash.startsWith(LINK_FRAGMENT)) return;
2798
+ window.history.replaceState(window.history.state, "", `${pathname}${search}`);
2799
+ setHeldLink({ link: parseHeldLink(hash) });
2800
+ }, [firstParty]);
2636
2801
  const navigate = React4__namespace.useCallback(
2637
2802
  async (account) => {
2638
2803
  if (resolveReturnTo) {
@@ -2654,7 +2819,7 @@ function OcSignIn({
2654
2819
  if (onSuccess) onSuccess(account, token);
2655
2820
  else void navigate(account);
2656
2821
  };
2657
- if (!linkPrompt || !linkAlso) {
2822
+ if (!linkPrompt || !linkAlso || via === "passkey") {
2658
2823
  proceed();
2659
2824
  return;
2660
2825
  }
@@ -2679,30 +2844,58 @@ function OcSignIn({
2679
2844
  },
2680
2845
  [onSuccess, linkPrompt, linkAlso, navigate, authOrigin]
2681
2846
  );
2847
+ const onPasskey = (a, t) => void handleSuccess(a, t, "passkey");
2848
+ if (passkeyOnly) {
2849
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className, "data-oc-signin": "", children: /* @__PURE__ */ jsxRuntime.jsx(
2850
+ PasskeyButton,
2851
+ {
2852
+ authOrigin,
2853
+ add: addMode,
2854
+ credentials,
2855
+ onSuccess: onPasskey
2856
+ }
2857
+ ) });
2858
+ }
2859
+ if (layered && firstParty) {
2860
+ return /* @__PURE__ */ jsxRuntime.jsxs(ConfigNote, { className, children: [
2861
+ /* @__PURE__ */ jsxRuntime.jsx("code", { children: 'passkey="layered"' }),
2862
+ " adds to a family session; a first-party site uses ",
2863
+ /* @__PURE__ */ jsxRuntime.jsx("code", { children: '"with"' }),
2864
+ " or ",
2865
+ /* @__PURE__ */ jsxRuntime.jsx("code", { children: '"only"' })
2866
+ ] });
2867
+ }
2868
+ if (layering) {
2869
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className, "data-oc-signin": "", children: /* @__PURE__ */ jsxRuntime.jsx(
2870
+ PasskeyLayerStep,
2871
+ {
2872
+ authOrigin,
2873
+ credentials,
2874
+ onSuccess: onPasskey
2875
+ }
2876
+ ) });
2877
+ }
2682
2878
  if (!walletEnabled && !emailEnabled) {
2683
- return /* @__PURE__ */ jsxRuntime.jsxs(
2684
- "div",
2879
+ return /* @__PURE__ */ jsxRuntime.jsxs(ConfigNote, { className, children: [
2880
+ "no signin paths enabled \u2014 set ",
2881
+ /* @__PURE__ */ jsxRuntime.jsx("code", { children: "paths.wallet" }),
2882
+ " or",
2883
+ " ",
2884
+ /* @__PURE__ */ jsxRuntime.jsx("code", { children: "paths.email" }),
2885
+ " to ",
2886
+ /* @__PURE__ */ jsxRuntime.jsx("code", { children: "true" })
2887
+ ] });
2888
+ }
2889
+ if (heldLink) {
2890
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className, "data-oc-signin": "", children: /* @__PURE__ */ jsxRuntime.jsx(
2891
+ HeldLinkStep,
2685
2892
  {
2686
- className,
2687
- "data-oc-signin": "",
2688
- style: {
2689
- padding: "1rem",
2690
- border: "1px solid var(--border, #27272a)",
2691
- color: "var(--foreground, #fafafa)",
2692
- fontFamily: SIGNIN_FONT,
2693
- fontSize: signinSize(12)
2694
- },
2695
- children: [
2696
- "no signin paths enabled \u2014 set ",
2697
- /* @__PURE__ */ jsxRuntime.jsx("code", { children: "paths.wallet" }),
2698
- " or",
2699
- " ",
2700
- /* @__PURE__ */ jsxRuntime.jsx("code", { children: "paths.email" }),
2701
- " to ",
2702
- /* @__PURE__ */ jsxRuntime.jsx("code", { children: "true" })
2703
- ]
2893
+ link: heldLink.link,
2894
+ authOrigin,
2895
+ onSuccess: (a, t) => void handleSuccess(a, t, "email"),
2896
+ onBack: () => setHeldLink(null)
2704
2897
  }
2705
- );
2898
+ ) });
2706
2899
  }
2707
2900
  if (signedIn) {
2708
2901
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className, "data-oc-signin": "", children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -2772,7 +2965,17 @@ function OcSignIn({
2772
2965
  ]
2773
2966
  }
2774
2967
  ),
2775
- providersFirst && /* @__PURE__ */ jsxRuntime.jsx(
2968
+ passkey === "with" && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginBottom: 16 }, children: /* @__PURE__ */ jsxRuntime.jsx(
2969
+ PasskeyButton,
2970
+ {
2971
+ authOrigin,
2972
+ add: addMode,
2973
+ credentials,
2974
+ onSuccess: onPasskey,
2975
+ quiet: true
2976
+ }
2977
+ ) }),
2978
+ providersFirst && !layered && /* @__PURE__ */ jsxRuntime.jsx(
2776
2979
  ProviderSignIn,
2777
2980
  {
2778
2981
  authOrigin,
@@ -2831,7 +3034,7 @@ function OcSignIn({
2831
3034
  add: addMode,
2832
3035
  credentials,
2833
3036
  onSeveralSessions: recheck,
2834
- onSuccess: (a, t) => void handleSuccess(a, t, "wallet")
3037
+ onSuccess: layered ? () => setLayering(true) : (a, t) => void handleSuccess(a, t, "wallet")
2835
3038
  }
2836
3039
  ),
2837
3040
  showEmail && /* @__PURE__ */ jsxRuntime.jsx(
@@ -2840,14 +3043,16 @@ function OcSignIn({
2840
3043
  authOrigin,
2841
3044
  add: addMode,
2842
3045
  credentials,
3046
+ firstParty,
2843
3047
  onSeveralSessions: recheck,
2844
- onSuccess: (a, t) => void handleSuccess(a, t, "email")
3048
+ onSuccess: (a, t) => void handleSuccess(a, t, "email"),
3049
+ onPasskey: passkey === "with" ? onPasskey : void 0
2845
3050
  }
2846
3051
  )
2847
3052
  ]
2848
3053
  }
2849
3054
  ),
2850
- !providersFirst && /* @__PURE__ */ jsxRuntime.jsx(
3055
+ !providersFirst && !layered && /* @__PURE__ */ jsxRuntime.jsx(
2851
3056
  ProviderSignIn,
2852
3057
  {
2853
3058
  authOrigin,
@@ -2870,6 +3075,26 @@ function OcSignIn({
2870
3075
  ] })
2871
3076
  ] });
2872
3077
  }
3078
+ function ConfigNote({
3079
+ className,
3080
+ children
3081
+ }) {
3082
+ return /* @__PURE__ */ jsxRuntime.jsx(
3083
+ "div",
3084
+ {
3085
+ className,
3086
+ "data-oc-signin": "",
3087
+ style: {
3088
+ padding: "1rem",
3089
+ border: "1px solid var(--border, #27272a)",
3090
+ color: "var(--foreground, #fafafa)",
3091
+ fontFamily: SIGNIN_FONT,
3092
+ fontSize: signinSize(12)
3093
+ },
3094
+ children
3095
+ }
3096
+ );
3097
+ }
2873
3098
  var SigninTab = React4__namespace.forwardRef(function SigninTab2({ id, controls, active, onClick, onKeyDown, children }, ref) {
2874
3099
  return /* @__PURE__ */ jsxRuntime.jsx(
2875
3100
  "button",
@@ -3031,6 +3256,104 @@ function ProviderSignIn({
3031
3256
  }
3032
3257
  );
3033
3258
  }
3259
+ var quietPasskeyStyle = {
3260
+ boxSizing: "border-box",
3261
+ width: "100%",
3262
+ minHeight: 44,
3263
+ padding: "0.6rem 0.875rem",
3264
+ border: "1px solid var(--border, #27272a)",
3265
+ borderRadius: SIGNIN_BUTTON_RADIUS,
3266
+ background: "transparent",
3267
+ color: "var(--foreground, #fafafa)",
3268
+ fontFamily: SIGNIN_FONT,
3269
+ fontSize: signinSize(12),
3270
+ cursor: "pointer"
3271
+ };
3272
+ function PasskeyButton({
3273
+ authOrigin,
3274
+ add,
3275
+ credentials,
3276
+ onSuccess,
3277
+ quiet = false
3278
+ }) {
3279
+ const uid = React4__namespace.useId();
3280
+ const [busy, setBusy] = React4__namespace.useState(false);
3281
+ const [error, setError] = React4__namespace.useState(null);
3282
+ async function run() {
3283
+ if (busy) return;
3284
+ setError(null);
3285
+ setBusy(true);
3286
+ try {
3287
+ const r = await passkeyCeremony({ authOrigin, kind: "signin", credentials, add });
3288
+ if (r.ok) {
3289
+ onSuccess(r.account, r.token);
3290
+ return;
3291
+ }
3292
+ setError(humanSigninError(r.reason, "passkey"));
3293
+ } catch (err) {
3294
+ setError(failureMessage(err, "passkey", "submit", authOrigin));
3295
+ } finally {
3296
+ setBusy(false);
3297
+ }
3298
+ }
3299
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-oc-signin-passkey": "", children: [
3300
+ /* @__PURE__ */ jsxRuntime.jsx(
3301
+ "button",
3302
+ {
3303
+ type: "button",
3304
+ onClick: () => void run(),
3305
+ "aria-disabled": busy || void 0,
3306
+ "aria-describedby": describedBy(error && `${uid}-error`),
3307
+ style: quiet ? { ...quietPasskeyStyle, opacity: busy ? 0.5 : 1 } : { ...submitStyle(busy), marginTop: 0 },
3308
+ children: busy ? "Waiting for your passkey\u2026" : quiet ? "Sign in with a passkey" : /* @__PURE__ */ jsxRuntime.jsx(Submit, { children: "Sign in with a passkey" })
3309
+ }
3310
+ ),
3311
+ error && /* @__PURE__ */ jsxRuntime.jsx(ErrorLine2, { id: `${uid}-error`, children: error }),
3312
+ /* @__PURE__ */ jsxRuntime.jsx(Busy, { children: busy ? "Waiting for your passkey\u2026" : null })
3313
+ ] });
3314
+ }
3315
+ function PasskeyLayerStep({
3316
+ authOrigin,
3317
+ credentials,
3318
+ onSuccess
3319
+ }) {
3320
+ const uid = React4__namespace.useId();
3321
+ const [busy, setBusy] = React4__namespace.useState(false);
3322
+ const [error, setError] = React4__namespace.useState(null);
3323
+ async function run() {
3324
+ if (busy) return;
3325
+ setError(null);
3326
+ setBusy(true);
3327
+ try {
3328
+ const r = await passkeyCeremony({ authOrigin, kind: "layer", credentials });
3329
+ if (r.ok) {
3330
+ onSuccess(r.account, r.token);
3331
+ return;
3332
+ }
3333
+ setError(humanSigninError(r.reason, "passkey"));
3334
+ } catch (err) {
3335
+ setError(failureMessage(err, "passkey", "submit", authOrigin));
3336
+ } finally {
3337
+ setBusy(false);
3338
+ }
3339
+ }
3340
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-oc-signin-passkey-layer": "", children: [
3341
+ /* @__PURE__ */ jsxRuntime.jsx(FlowHeader, { children: "Your wallet signed you in. This site also asks for your passkey." }),
3342
+ /* @__PURE__ */ jsxRuntime.jsx(
3343
+ "button",
3344
+ {
3345
+ type: "button",
3346
+ onClick: () => void run(),
3347
+ "aria-disabled": busy || void 0,
3348
+ "aria-describedby": describedBy(error && `${uid}-error`),
3349
+ style: submitStyle(busy),
3350
+ children: busy ? "Waiting for your passkey\u2026" : /* @__PURE__ */ jsxRuntime.jsx(Submit, { children: "Confirm with your passkey" })
3351
+ }
3352
+ ),
3353
+ error && /* @__PURE__ */ jsxRuntime.jsx(ErrorLine2, { id: `${uid}-error`, children: error }),
3354
+ /* @__PURE__ */ jsxRuntime.jsx(Busy, { children: busy ? "Waiting for your passkey\u2026" : null })
3355
+ ] });
3356
+ }
3034
3357
  function recheckAfter(err, recheck) {
3035
3358
  if (!recheck || !isSeveralSessions(err)) return;
3036
3359
  void Promise.resolve().then(recheck).catch(() => {
@@ -3319,8 +3642,10 @@ function EmailFlow({
3319
3642
  authOrigin,
3320
3643
  add,
3321
3644
  credentials,
3645
+ firstParty,
3322
3646
  onSuccess,
3323
- onSeveralSessions
3647
+ onSeveralSessions,
3648
+ onPasskey
3324
3649
  }) {
3325
3650
  const uid = React4__namespace.useId();
3326
3651
  const [stage, setStage] = React4__namespace.useState("enter");
@@ -3340,13 +3665,36 @@ function EmailFlow({
3340
3665
  codeError: `${uid}-code-error`,
3341
3666
  listed: `${uid}-listed`
3342
3667
  };
3668
+ const onPasskeyRef = React4__namespace.useRef(onPasskey);
3669
+ React4__namespace.useEffect(() => {
3670
+ onPasskeyRef.current = onPasskey;
3671
+ });
3672
+ const autofill = onPasskey !== void 0 && stage === "enter";
3673
+ React4__namespace.useEffect(() => {
3674
+ if (!autofill) return;
3675
+ let live = true;
3676
+ void (async () => {
3677
+ try {
3678
+ if (!await browser.browserSupportsWebAuthnAutofill() || !live) return;
3679
+ const r = await passkeyCeremony({ authOrigin, kind: "signin", credentials, add, autofill: true });
3680
+ if (r.ok) onPasskeyRef.current?.(r.account, r.token);
3681
+ else if (live && r.step === "verify") setEmailError(humanSigninError(r.reason, "passkey"));
3682
+ } catch {
3683
+ }
3684
+ })();
3685
+ return () => {
3686
+ live = false;
3687
+ cancelPasskeyAutofill();
3688
+ };
3689
+ }, [autofill, authOrigin, credentials, add]);
3343
3690
  async function sendCode(address) {
3344
3691
  try {
3692
+ const bind = firstParty ? await linkBind() : void 0;
3345
3693
  const res = await fetch(`${authOrigin}/api/auth/email-otp/start`, {
3346
3694
  method: "POST",
3347
3695
  credentials,
3348
3696
  headers: { "Content-Type": "application/json" },
3349
- body: JSON.stringify({ email: address })
3697
+ body: JSON.stringify({ email: address, ...bind ? { link_bind: bind } : {} })
3350
3698
  });
3351
3699
  const json = await res.json();
3352
3700
  if (json.reason === "otp_network_cap") return otpNetworkCapText(json.retry_at);
@@ -3452,7 +3800,7 @@ function EmailFlow({
3452
3800
  "data-oca-field": "",
3453
3801
  id: `${uid}-email`,
3454
3802
  type: "email",
3455
- autoComplete: "email",
3803
+ autoComplete: onPasskey ? "username webauthn" : "email",
3456
3804
  value: email,
3457
3805
  onChange: (e) => {
3458
3806
  setEmail(e.target.value);
@@ -3550,6 +3898,80 @@ function EmailFlow({
3550
3898
  ] })
3551
3899
  ] }, "code");
3552
3900
  }
3901
+ function HeldLinkStep({
3902
+ link,
3903
+ authOrigin,
3904
+ onSuccess,
3905
+ onBack
3906
+ }) {
3907
+ const uid = React4__namespace.useId();
3908
+ const [press, setPress] = React4__namespace.useState(() => {
3909
+ if (!link) return { kind: "final", text: heldLinkRefusalText("wrong_link") };
3910
+ if (link.exp * 1e3 <= Date.now()) {
3911
+ return { kind: "final", text: heldLinkRefusalText("expired") };
3912
+ }
3913
+ if (!readLinkKey()) return { kind: "final", text: heldLinkRefusalText("wrong_browser") };
3914
+ return { kind: "idle" };
3915
+ });
3916
+ async function signIn(l) {
3917
+ setPress({ kind: "sending" });
3918
+ let reason;
3919
+ try {
3920
+ const res = await fetch(`${authOrigin}/api/auth/email-otp/verify`, {
3921
+ method: "POST",
3922
+ credentials: "omit",
3923
+ headers: { "Content-Type": "application/json" },
3924
+ body: JSON.stringify({
3925
+ email: l.email,
3926
+ token: l.token,
3927
+ link_secret: l.secret,
3928
+ link_key: readLinkKey()
3929
+ })
3930
+ });
3931
+ const json = await res.json().catch(() => ({}));
3932
+ if (res.ok && "ok" in json && json.ok && json.account) {
3933
+ onSuccess(json.account, json.token);
3934
+ return;
3935
+ }
3936
+ reason = json.reason;
3937
+ } catch {
3938
+ reason = void 0;
3939
+ }
3940
+ const text = heldLinkRefusalText(reason);
3941
+ const final = reason !== void 0 && FINAL_LINK_REFUSALS.has(reason);
3942
+ setPress(final ? { kind: "final", text } : { kind: "refused", text });
3943
+ }
3944
+ if (press.kind === "final" || !link) {
3945
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-oc-signin-held-link": "", children: [
3946
+ /* @__PURE__ */ jsxRuntime.jsx(ErrorLine2, { id: `${uid}-error`, children: press.kind === "final" ? press.text : heldLinkRefusalText("wrong_link") }),
3947
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: onBack, style: submitStyle(false), children: /* @__PURE__ */ jsxRuntime.jsx(Submit, { children: "Ask for a new link" }) })
3948
+ ] });
3949
+ }
3950
+ const sending = press.kind === "sending";
3951
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-oc-signin-held-link": "", children: [
3952
+ /* @__PURE__ */ jsxRuntime.jsxs(FlowHeader, { children: [
3953
+ "Sign in as",
3954
+ " ",
3955
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: "var(--foreground, #fafafa)" }, children: maskEmail(link.email) }),
3956
+ " ",
3957
+ "with the link from your email. Nothing happens until you press the button."
3958
+ ] }),
3959
+ /* @__PURE__ */ jsxRuntime.jsx(
3960
+ "button",
3961
+ {
3962
+ type: "button",
3963
+ onClick: () => void signIn(link),
3964
+ "aria-disabled": sending || void 0,
3965
+ "aria-describedby": press.kind === "refused" ? `${uid}-error` : void 0,
3966
+ disabled: sending,
3967
+ style: submitStyle(sending),
3968
+ children: sending ? "Signing in\u2026" : /* @__PURE__ */ jsxRuntime.jsx(Submit, { children: "Sign in" })
3969
+ }
3970
+ ),
3971
+ press.kind === "refused" && /* @__PURE__ */ jsxRuntime.jsx(ErrorLine2, { id: `${uid}-error`, children: press.text }),
3972
+ /* @__PURE__ */ jsxRuntime.jsx(Busy, { children: sending ? "Signing in\u2026" : null })
3973
+ ] });
3974
+ }
3553
3975
  function Submit({ children }) {
3554
3976
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3555
3977
  children,
@@ -4204,6 +4626,51 @@ function isAbortError(err) {
4204
4626
  if (!(err instanceof Error)) return false;
4205
4627
  return /NotAllowed|aborted|cancel|user cancelled/i.test(err.message);
4206
4628
  }
4629
+ var BINDING_PREFIX = "oc-passkey:bind:v1\n";
4630
+ function bindingAddress(statement, credentialId) {
4631
+ if (!statement.startsWith(BINDING_PREFIX) || !statement.endsWith("\n")) return null;
4632
+ const lines = statement.slice(0, -1).split("\n");
4633
+ if (lines.length !== 8 || lines[4] !== `credential_id: ${credentialId}`) return null;
4634
+ const address = /^address: ([A-Za-z0-9]{14,90})$/.exec(lines[1] ?? "")?.[1];
4635
+ return address ?? null;
4636
+ }
4637
+ var SIGNER_REFUSAL = {
4638
+ rejected: "cancelled",
4639
+ "wrong-account": "wrong_account",
4640
+ "not-found": "wallet_not_found",
4641
+ "timed-out": "timed_out",
4642
+ trimmed: "signature_trimmed"
4643
+ };
4644
+ async function signerRefusal(err) {
4645
+ try {
4646
+ const { walletFailure } = await import('@orangecheck/wallet-adapter');
4647
+ return SIGNER_REFUSAL[walletFailure(err)] ?? "sign_failed";
4648
+ } catch {
4649
+ return isAbortError(err) ? "cancelled" : "sign_failed";
4650
+ }
4651
+ }
4652
+ async function bindKey(authOrigin, statement, credentialId, sign) {
4653
+ const address = bindingAddress(statement, credentialId);
4654
+ if (!address) return { ok: false, reason: "binding_statement_mismatch" };
4655
+ let signature;
4656
+ try {
4657
+ signature = await sign(statement, address);
4658
+ } catch (e) {
4659
+ return { ok: false, reason: await signerRefusal(e) };
4660
+ }
4661
+ try {
4662
+ const r = await fetch(`${authOrigin}/api/auth/webauthn/bind`, {
4663
+ method: "POST",
4664
+ credentials: "include",
4665
+ headers: { "Content-Type": "application/json" },
4666
+ body: JSON.stringify({ credential_id: credentialId, address, signature })
4667
+ });
4668
+ const j = await r.json();
4669
+ return r.ok && j.ok ? { ok: true } : { ok: false, reason: j.reason ?? `bind_failed_${r.status}` };
4670
+ } catch (e) {
4671
+ return { ok: false, reason: e instanceof Error ? e.message : String(e) };
4672
+ }
4673
+ }
4207
4674
  function useWebAuthnRegister(opts) {
4208
4675
  const authOrigin = resolveAuthOrigin(opts);
4209
4676
  const [status, setStatus] = React4__namespace.useState("idle");
@@ -4258,8 +4725,10 @@ function useWebAuthnRegister(opts) {
4258
4725
  setStatus("error");
4259
4726
  return { ok: false, reason };
4260
4727
  }
4728
+ const statement = verifyBody.binding_statement;
4729
+ const binding = typeof statement !== "string" ? void 0 : args?.bind ? await bindKey(authOrigin, statement, attestation.id, args.bind) : { ok: false, reason: "not_bound" };
4261
4730
  setStatus("success");
4262
- return { ok: true, credential: verifyBody.credential };
4731
+ return { ok: true, credential: verifyBody.credential, ...binding ? { binding } : {} };
4263
4732
  } catch (e) {
4264
4733
  const reason = e instanceof Error ? e.message : String(e);
4265
4734
  setError(new Error(reason));
@@ -4271,6 +4740,46 @@ function useWebAuthnRegister(opts) {
4271
4740
  );
4272
4741
  return { status, error, register, reset };
4273
4742
  }
4743
+ function usePasskeySignIn(opts) {
4744
+ const authOrigin = resolveAuthOrigin(opts);
4745
+ const refresh = useOptionalOcSession()?.refresh;
4746
+ const [status, setStatus] = React4__namespace.useState("idle");
4747
+ const [error, setError] = React4__namespace.useState(null);
4748
+ const reset = React4__namespace.useCallback(() => {
4749
+ setStatus("idle");
4750
+ setError(null);
4751
+ }, []);
4752
+ const signIn = React4__namespace.useCallback(
4753
+ async (args) => {
4754
+ setError(null);
4755
+ setStatus("authenticating");
4756
+ const credentials = args?.credentials ?? "include";
4757
+ try {
4758
+ const r = await passkeyCeremony({
4759
+ authOrigin,
4760
+ kind: args?.kind ?? "signin",
4761
+ credentials,
4762
+ add: args?.add
4763
+ });
4764
+ if (!r.ok) {
4765
+ setError(new Error(r.reason));
4766
+ setStatus("error");
4767
+ return { ok: false, reason: r.reason };
4768
+ }
4769
+ if (credentials !== "omit") await refresh?.();
4770
+ setStatus("success");
4771
+ return { ok: true, account: r.account, ...r.token ? { token: r.token } : {} };
4772
+ } catch (e) {
4773
+ const reason = e instanceof Error ? e.message : String(e);
4774
+ setError(new Error(reason));
4775
+ setStatus("error");
4776
+ return { ok: false, reason };
4777
+ }
4778
+ },
4779
+ [authOrigin, refresh]
4780
+ );
4781
+ return { status, error, signIn, reset };
4782
+ }
4274
4783
  function useWebAuthnList(opts) {
4275
4784
  const authOrigin = resolveAuthOrigin(opts);
4276
4785
  const { status: sessionStatus } = useOcSession();
@@ -4473,6 +4982,7 @@ exports.tabSessionHeader = tabSessionHeader;
4473
4982
  exports.useOcAddressSuggestion = useOcAddressSuggestion;
4474
4983
  exports.useOcSession = useOcSession;
4475
4984
  exports.useOptionalOcSession = useOptionalOcSession;
4985
+ exports.usePasskeySignIn = usePasskeySignIn;
4476
4986
  exports.useStepUpAuth = useStepUpAuth;
4477
4987
  exports.useWebAuthnList = useWebAuthnList;
4478
4988
  exports.useWebAuthnRegister = useWebAuthnRegister;