@orangecheck/auth-client 2.51.0 → 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 (32) hide show
  1. package/dist/bond.mjs +3 -3
  2. package/dist/{chunk-F3QPJLWF.mjs → chunk-2FBI2M6N.mjs} +215 -37
  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-IKNAIRW5.mjs → chunk-FDN374RW.mjs} +2 -2
  8. package/dist/{chunk-OKIFTNEO.mjs → chunk-HQ6APBHF.mjs} +8 -2
  9. package/dist/{chunk-OKIFTNEO.mjs.map → chunk-HQ6APBHF.mjs.map} +1 -1
  10. package/dist/{chunk-VU4DDRCO.mjs → chunk-LKYBT4Q7.mjs} +2 -2
  11. package/dist/chunk-QHZ6E64O.mjs +61 -0
  12. package/dist/chunk-QHZ6E64O.mjs.map +1 -0
  13. package/dist/{chunk-OI64DUVC.mjs → chunk-W6YYHOYL.mjs} +2 -2
  14. package/dist/components.mjs +3 -3
  15. package/dist/index.d.ts +34 -2
  16. package/dist/index.js +353 -36
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +10 -7
  19. package/dist/linked-identities.mjs +2 -2
  20. package/dist/passkey.mjs +9 -0
  21. package/dist/passkey.mjs.map +1 -0
  22. package/dist/provider.mjs +2 -2
  23. package/dist/refusal.mjs +1 -1
  24. package/dist/signin.mjs +5 -4
  25. package/dist/webauthn.mjs +6 -3
  26. package/package.json +1 -1
  27. package/dist/chunk-F3QPJLWF.mjs.map +0 -1
  28. package/dist/chunk-XVLOTOCX.mjs.map +0 -1
  29. /package/dist/{chunk-MIBVEZLP.mjs.map → chunk-7VBIHZVF.mjs.map} +0 -0
  30. /package/dist/{chunk-IKNAIRW5.mjs.map → chunk-FDN374RW.mjs.map} +0 -0
  31. /package/dist/{chunk-VU4DDRCO.mjs.map → chunk-LKYBT4Q7.mjs.map} +0 -0
  32. /package/dist/{chunk-OI64DUVC.mjs.map → chunk-W6YYHOYL.mjs.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/refusal.ts"],"sourcesContent":["/**\n * What a refused or failed call to the auth host says to a person. Sign-in\n * and linking read the same reasons from the same host, so they share these.\n */\n\nimport { ownWord } from './own-word';\n\n/**\n * A sign-in the person's own sign-out or account deletion ended while it ran,\n * by any way in. `no_roster`: a sign-out elsewhere in this browser replaced\n * the account list this sign-in was joining, so the host kept no session.\n */\nconst ENDED_ERRORS: Record<string, string> = {\n signed_out: 'You were signed out while signing in. Sign in again.',\n account_deleted: \"This account is being deleted, so you can't sign in to it.\",\n no_roster:\n \"An account in this browser was signed out while you were signing in, so this sign-in wasn't kept. Sign in again.\",\n};\n\nexport function endedSigninText(reason: string): string | undefined {\n return ownWord(ENDED_ERRORS, reason);\n}\n\n/**\n * An add refused because this browser sent more than one ochk.io sign-in. The\n * host cleared the extra cookies and spent nothing, so the same try can go\n * again once the person sees which account is signed in now.\n */\nexport const SEVERAL_SESSIONS_TEXT =\n \"Your browser sent more than one ochk.io sign-in, so this account wasn't added. Check which account is signed in now, then try again.\";\n\n/**\n * A sign-out or an account switch ochk.io refused for the same reason. It\n * cleared the extra cookies and ended or switched nothing, so the provider\n * reads the session again and the page shows the account left signed in.\n */\nexport const SIGN_OUT_SEVERAL_SESSIONS_TEXT =\n \"Your browser sent more than one ochk.io sign-in, so you weren't signed out. Check which account is signed in now, then try again.\";\nexport const SWITCH_SEVERAL_SESSIONS_TEXT =\n \"Your browser sent more than one ochk.io sign-in, so the account wasn't switched. Check which account is signed in now, then try again.\";\n\n/** True when an auth host answer is ochk.io's 409 `several_sessions`. */\nexport async function isSeveralSessionsAnswer(res: Response): Promise<boolean> {\n if (res.status !== 409) return false;\n try {\n const body = (await res.clone().json()) as { reason?: unknown } | null;\n return body?.reason === 'several_sessions';\n } catch {\n return false;\n }\n}\n\n/** True when a sign-in call threw ochk.io's `several_sessions` refusal. */\nexport function isSeveralSessions(err: unknown): boolean {\n return err instanceof Error && err.message === 'several_sessions';\n}\n\n/**\n * The auth host answers with machine reasons. Its /api/auth/signin says it\n * exposes them \"so the /signin UI can give an actionable message\", and this\n * form printed them verbatim instead: typing \"hello\" as an address showed\n * `bad_request`. Each reason maps to what happened and what to do next.\n */\nconst SIGNIN_ERRORS: Record<string, string> = {\n bad_request: \"That doesn't look like a Bitcoin address.\",\n invalid_challenge:\n \"That signature doesn't match this address. Sign with the wallet that holds it.\",\n sig_invalid: \"That signature doesn't match this address. Sign with the wallet that holds it.\",\n sig_unsupported_scheme:\n \"We can't check this wallet's signature format yet. Try another wallet, or use email.\",\n expired: 'That request timed out. Try again for a fresh one.',\n not_yet_valid: 'That request is not valid yet. Check your device clock, then try again.',\n nonce_mismatch: \"That request didn't match. Try again for a fresh one.\",\n audience_mismatch: \"That request didn't match this site. Reload the page and try again.\",\n purpose_mismatch: \"That request didn't match. Try again for a fresh one.\",\n malformed: \"That signature couldn't be read. Copy it again, whole.\",\n challenge_mismatch:\n 'That sign-in message changed after it was issued. Get a new one and sign it again.',\n mainnet_only: 'Sign in with a mainnet Bitcoin address.',\n cross_site_blocked: 'Your browser blocked this request. Reload the page and try again.',\n rate_limited: 'Too many tries. Wait a minute, then try again.',\n invalid_email: \"That email address doesn't look right.\",\n mailer_unavailable: \"We couldn't send the email right now. Try again in a minute.\",\n mailer_error: \"We couldn't send the email right now. Try again in a minute.\",\n wrong_code: \"That code isn't right. Check the newest email from us.\",\n replay: 'That code was already used. Send a new one.',\n invalid_token: 'That code is no longer valid. Send a new one.',\n email_mismatch: 'That code was sent to a different address. Send a new one.',\n several_sessions: SEVERAL_SESSIONS_TEXT,\n ...ENDED_ERRORS,\n};\n\nconst EMAIL_ERRORS: Record<string, string> = {\n expired: 'That code expired. Send a new one.',\n signed_out: 'You were signed out while signing in. Send a new code to sign in again.',\n no_roster:\n \"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.\",\n};\n\n/**\n * `bad_request` means the host's body schema failed. Fetching a challenge\n * that is the address; submitting a signature it is the pasted signature\n * (under 10 characters, say), which is not an address problem at all.\n */\nconst SUBMIT_ERRORS: Record<string, string> = {\n bad_request: \"That signature couldn't be read. Copy it again, whole.\",\n};\n\n/** The auth host by name, so an outage reads as theirs and not the page's. */\nexport function networkError(authOrigin: string): string {\n let host = authOrigin;\n try {\n host = new URL(authOrigin).host;\n } catch {\n // not a URL: name it as given\n }\n return `We couldn't reach the orangecheck sign-in service at ${host}. Check your connection, then try again.`;\n}\n\nexport function humanSigninError(\n reason: string,\n path: 'wallet' | 'email',\n step: 'challenge' | 'submit' = 'challenge'\n): string {\n // A reason that is not a code is already a sentence.\n if (!/^[a-z0-9_]+$/.test(reason)) return reason;\n const own =\n (path === 'wallet' && step === 'submit' && ownWord(SUBMIT_ERRORS, reason)) ||\n (path === 'email' && ownWord(EMAIL_ERRORS, reason));\n if (own) return own;\n return (\n ownWord(SIGNIN_ERRORS, reason) ??\n (path === 'email'\n ? \"That didn't work. Try again, or send a new code.\"\n : \"That didn't work. Try again.\")\n );\n}\n\n/**\n * A failed fetch (\"Failed to fetch\") or an HTML error page parsed as JSON\n * (a SyntaxError) is not prose meant for a person; everything else thrown\n * here carries a host reason code. A wallet's failure never comes here.\n */\nexport function failureMessage(\n err: unknown,\n path: 'wallet' | 'email',\n step: 'challenge' | 'submit',\n authOrigin: string\n): string {\n if (err instanceof TypeError || err instanceof SyntaxError) return networkError(authOrigin);\n return humanSigninError(err instanceof Error ? err.message : 'failed', path, step);\n}\n"],"mappings":";;;;;AAYA,IAAM,eAAuC;AAAA,EACzC,YAAY;AAAA,EACZ,iBAAiB;AAAA,EACjB,WACI;AACR;AAEO,SAAS,gBAAgB,QAAoC;AAChE,SAAO,QAAQ,cAAc,MAAM;AACvC;AAOO,IAAM,wBACT;AAOG,IAAM,iCACT;AACG,IAAM,+BACT;AAGJ,eAAsB,wBAAwB,KAAiC;AAC3E,MAAI,IAAI,WAAW,IAAK,QAAO;AAC/B,MAAI;AACA,UAAM,OAAQ,MAAM,IAAI,MAAM,EAAE,KAAK;AACrC,WAAO,MAAM,WAAW;AAAA,EAC5B,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;AAGO,SAAS,kBAAkB,KAAuB;AACrD,SAAO,eAAe,SAAS,IAAI,YAAY;AACnD;AAQA,IAAM,gBAAwC;AAAA,EAC1C,aAAa;AAAA,EACb,mBACI;AAAA,EACJ,aAAa;AAAA,EACb,wBACI;AAAA,EACJ,SAAS;AAAA,EACT,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,WAAW;AAAA,EACX,oBACI;AAAA,EACJ,cAAc;AAAA,EACd,oBAAoB;AAAA,EACpB,cAAc;AAAA,EACd,eAAe;AAAA,EACf,oBAAoB;AAAA,EACpB,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB,GAAG;AACP;AAEA,IAAM,eAAuC;AAAA,EACzC,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,WACI;AACR;AAOA,IAAM,gBAAwC;AAAA,EAC1C,aAAa;AACjB;AAGO,SAAS,aAAa,YAA4B;AACrD,MAAI,OAAO;AACX,MAAI;AACA,WAAO,IAAI,IAAI,UAAU,EAAE;AAAA,EAC/B,QAAQ;AAAA,EAER;AACA,SAAO,wDAAwD,IAAI;AACvE;AAEO,SAAS,iBACZ,QACA,MACA,OAA+B,aACzB;AAEN,MAAI,CAAC,eAAe,KAAK,MAAM,EAAG,QAAO;AACzC,QAAM,MACD,SAAS,YAAY,SAAS,YAAY,QAAQ,eAAe,MAAM,KACvE,SAAS,WAAW,QAAQ,cAAc,MAAM;AACrD,MAAI,IAAK,QAAO;AAChB,SACI,QAAQ,eAAe,MAAM,MAC5B,SAAS,UACJ,qDACA;AAEd;AAOO,SAAS,eACZ,KACA,MACA,MACA,YACM;AACN,MAAI,eAAe,aAAa,eAAe,YAAa,QAAO,aAAa,UAAU;AAC1F,SAAO,iBAAiB,eAAe,QAAQ,IAAI,UAAU,UAAU,MAAM,IAAI;AACrF;","names":[]}
1
+ {"version":3,"sources":["../src/refusal.ts"],"sourcesContent":["/**\n * What a refused or failed call to the auth host says to a person. Sign-in\n * and linking read the same reasons from the same host, so they share these.\n */\n\nimport { ownWord } from './own-word';\n\n/**\n * A sign-in the person's own sign-out or account deletion ended while it ran,\n * by any way in. `no_roster`: a sign-out elsewhere in this browser replaced\n * the account list this sign-in was joining, so the host kept no session.\n */\nconst ENDED_ERRORS: Record<string, string> = {\n signed_out: 'You were signed out while signing in. Sign in again.',\n account_deleted: \"This account is being deleted, so you can't sign in to it.\",\n no_roster:\n \"An account in this browser was signed out while you were signing in, so this sign-in wasn't kept. Sign in again.\",\n};\n\nexport function endedSigninText(reason: string): string | undefined {\n return ownWord(ENDED_ERRORS, reason);\n}\n\n/**\n * An add refused because this browser sent more than one ochk.io sign-in. The\n * host cleared the extra cookies and spent nothing, so the same try can go\n * again once the person sees which account is signed in now.\n */\nexport const SEVERAL_SESSIONS_TEXT =\n \"Your browser sent more than one ochk.io sign-in, so this account wasn't added. Check which account is signed in now, then try again.\";\n\n/**\n * A sign-out or an account switch ochk.io refused for the same reason. It\n * cleared the extra cookies and ended or switched nothing, so the provider\n * reads the session again and the page shows the account left signed in.\n */\nexport const SIGN_OUT_SEVERAL_SESSIONS_TEXT =\n \"Your browser sent more than one ochk.io sign-in, so you weren't signed out. Check which account is signed in now, then try again.\";\nexport const SWITCH_SEVERAL_SESSIONS_TEXT =\n \"Your browser sent more than one ochk.io sign-in, so the account wasn't switched. Check which account is signed in now, then try again.\";\n\n/** True when an auth host answer is ochk.io's 409 `several_sessions`. */\nexport async function isSeveralSessionsAnswer(res: Response): Promise<boolean> {\n if (res.status !== 409) return false;\n try {\n const body = (await res.clone().json()) as { reason?: unknown } | null;\n return body?.reason === 'several_sessions';\n } catch {\n return false;\n }\n}\n\n/** True when a sign-in call threw ochk.io's `several_sessions` refusal. */\nexport function isSeveralSessions(err: unknown): boolean {\n return err instanceof Error && err.message === 'several_sessions';\n}\n\n/**\n * The auth host answers with machine reasons. Its /api/auth/signin says it\n * exposes them \"so the /signin UI can give an actionable message\", and this\n * form printed them verbatim instead: typing \"hello\" as an address showed\n * `bad_request`. Each reason maps to what happened and what to do next.\n */\nconst SIGNIN_ERRORS: Record<string, string> = {\n bad_request: \"That doesn't look like a Bitcoin address.\",\n invalid_challenge:\n \"That signature doesn't match this address. Sign with the wallet that holds it.\",\n sig_invalid: \"That signature doesn't match this address. Sign with the wallet that holds it.\",\n sig_unsupported_scheme:\n \"We can't check this wallet's signature format yet. Try another wallet, or use email.\",\n expired: 'That request timed out. Try again for a fresh one.',\n not_yet_valid: 'That request is not valid yet. Check your device clock, then try again.',\n nonce_mismatch: \"That request didn't match. Try again for a fresh one.\",\n audience_mismatch: \"That request didn't match this site. Reload the page and try again.\",\n purpose_mismatch: \"That request didn't match. Try again for a fresh one.\",\n malformed: \"That signature couldn't be read. Copy it again, whole.\",\n challenge_mismatch:\n 'That sign-in message changed after it was issued. Get a new one and sign it again.',\n mainnet_only: 'Sign in with a mainnet Bitcoin address.',\n cross_site_blocked: 'Your browser blocked this request. Reload the page and try again.',\n rate_limited: 'Too many tries. Wait a minute, then try again.',\n invalid_email: \"That email address doesn't look right.\",\n mailer_unavailable: \"We couldn't send the email right now. Try again in a minute.\",\n mailer_error: \"We couldn't send the email right now. Try again in a minute.\",\n wrong_code: \"That code isn't right. Check the newest email from us.\",\n replay: 'That code was already used. Send a new one.',\n invalid_token: 'That code is no longer valid. Send a new one.',\n email_mismatch: 'That code was sent to a different address. Send a new one.',\n several_sessions: SEVERAL_SESSIONS_TEXT,\n ...ENDED_ERRORS,\n};\n\nconst EMAIL_ERRORS: Record<string, string> = {\n expired: 'That code expired. Send a new one.',\n signed_out: 'You were signed out while signing in. Send a new code to sign in again.',\n no_roster:\n \"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.\",\n};\n\nconst PASSKEY_ERRORS: Record<string, string> = {\n passkey_not_for_signin:\n \"That passkey isn't set up to sign in. Sign in another way, then turn it on for sign-in in your account.\",\n passkey_not_recognised:\n \"That passkey isn't on any orangecheck account. It may have been removed. Sign in another way.\",\n cancelled: 'The passkey prompt closed. Try again when you are ready.',\n passkey_failed: \"Your device couldn't use a passkey. Try again, or sign in another way.\",\n};\n\n/**\n * `bad_request` means the host's body schema failed. Fetching a challenge\n * that is the address; submitting a signature it is the pasted signature\n * (under 10 characters, say), which is not an address problem at all.\n */\nconst SUBMIT_ERRORS: Record<string, string> = {\n bad_request: \"That signature couldn't be read. Copy it again, whole.\",\n};\n\n/** The auth host by name, so an outage reads as theirs and not the page's. */\nexport function networkError(authOrigin: string): string {\n let host = authOrigin;\n try {\n host = new URL(authOrigin).host;\n } catch {\n // not a URL: name it as given\n }\n return `We couldn't reach the orangecheck sign-in service at ${host}. Check your connection, then try again.`;\n}\n\nexport function humanSigninError(\n reason: string,\n path: 'wallet' | 'email' | 'passkey',\n step: 'challenge' | 'submit' = 'challenge'\n): string {\n // A reason that is not a code is already a sentence.\n if (!/^[a-z0-9_]+$/.test(reason)) return reason;\n const own =\n (path === 'wallet' && step === 'submit' && ownWord(SUBMIT_ERRORS, reason)) ||\n (path === 'email' && ownWord(EMAIL_ERRORS, reason)) ||\n (path === 'passkey' && ownWord(PASSKEY_ERRORS, reason));\n if (own) return own;\n return (\n ownWord(SIGNIN_ERRORS, reason) ??\n (path === 'email'\n ? \"That didn't work. Try again, or send a new code.\"\n : \"That didn't work. Try again.\")\n );\n}\n\n/**\n * A failed fetch (\"Failed to fetch\") or an HTML error page parsed as JSON\n * (a SyntaxError) is not prose meant for a person; everything else thrown\n * here carries a host reason code. A wallet's failure never comes here.\n */\nexport function failureMessage(\n err: unknown,\n path: 'wallet' | 'email' | 'passkey',\n step: 'challenge' | 'submit',\n authOrigin: string\n): string {\n if (err instanceof TypeError || err instanceof SyntaxError) return networkError(authOrigin);\n return humanSigninError(err instanceof Error ? err.message : 'failed', path, step);\n}\n"],"mappings":";;;;;AAYA,IAAM,eAAuC;AAAA,EACzC,YAAY;AAAA,EACZ,iBAAiB;AAAA,EACjB,WACI;AACR;AAEO,SAAS,gBAAgB,QAAoC;AAChE,SAAO,QAAQ,cAAc,MAAM;AACvC;AAOO,IAAM,wBACT;AAOG,IAAM,iCACT;AACG,IAAM,+BACT;AAGJ,eAAsB,wBAAwB,KAAiC;AAC3E,MAAI,IAAI,WAAW,IAAK,QAAO;AAC/B,MAAI;AACA,UAAM,OAAQ,MAAM,IAAI,MAAM,EAAE,KAAK;AACrC,WAAO,MAAM,WAAW;AAAA,EAC5B,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;AAGO,SAAS,kBAAkB,KAAuB;AACrD,SAAO,eAAe,SAAS,IAAI,YAAY;AACnD;AAQA,IAAM,gBAAwC;AAAA,EAC1C,aAAa;AAAA,EACb,mBACI;AAAA,EACJ,aAAa;AAAA,EACb,wBACI;AAAA,EACJ,SAAS;AAAA,EACT,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,WAAW;AAAA,EACX,oBACI;AAAA,EACJ,cAAc;AAAA,EACd,oBAAoB;AAAA,EACpB,cAAc;AAAA,EACd,eAAe;AAAA,EACf,oBAAoB;AAAA,EACpB,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB,GAAG;AACP;AAEA,IAAM,eAAuC;AAAA,EACzC,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,WACI;AACR;AAEA,IAAM,iBAAyC;AAAA,EAC3C,wBACI;AAAA,EACJ,wBACI;AAAA,EACJ,WAAW;AAAA,EACX,gBAAgB;AACpB;AAOA,IAAM,gBAAwC;AAAA,EAC1C,aAAa;AACjB;AAGO,SAAS,aAAa,YAA4B;AACrD,MAAI,OAAO;AACX,MAAI;AACA,WAAO,IAAI,IAAI,UAAU,EAAE;AAAA,EAC/B,QAAQ;AAAA,EAER;AACA,SAAO,wDAAwD,IAAI;AACvE;AAEO,SAAS,iBACZ,QACA,MACA,OAA+B,aACzB;AAEN,MAAI,CAAC,eAAe,KAAK,MAAM,EAAG,QAAO;AACzC,QAAM,MACD,SAAS,YAAY,SAAS,YAAY,QAAQ,eAAe,MAAM,KACvE,SAAS,WAAW,QAAQ,cAAc,MAAM,KAChD,SAAS,aAAa,QAAQ,gBAAgB,MAAM;AACzD,MAAI,IAAK,QAAO;AAChB,SACI,QAAQ,eAAe,MAAM,MAC5B,SAAS,UACJ,qDACA;AAEd;AAOO,SAAS,eACZ,KACA,MACA,MACA,YACM;AACN,MAAI,eAAe,aAAa,eAAe,YAAa,QAAO,aAAa,UAAU;AAC1F,SAAO,iBAAiB,eAAe,QAAQ,IAAI,UAAU,UAAU,MAAM,IAAI;AACrF;","names":[]}
@@ -11,7 +11,7 @@ import {
11
11
  inputStyle,
12
12
  panelStyle,
13
13
  primaryBtnStyle
14
- } from "./chunk-OI64DUVC.mjs";
14
+ } from "./chunk-W6YYHOYL.mjs";
15
15
  import {
16
16
  addressInputValue
17
17
  } from "./chunk-U7IUGDLW.mjs";
@@ -498,4 +498,4 @@ export {
498
498
  fetchOcBond,
499
499
  OcBond
500
500
  };
501
- //# sourceMappingURL=chunk-VU4DDRCO.mjs.map
501
+ //# sourceMappingURL=chunk-LKYBT4Q7.mjs.map
@@ -0,0 +1,61 @@
1
+ // src/passkey.ts
2
+ import {
3
+ startAuthentication,
4
+ WebAuthnAbortService
5
+ } from "@simplewebauthn/browser";
6
+ var prompting = 0;
7
+ function cancelPasskeyAutofill() {
8
+ if (prompting === 0) WebAuthnAbortService.cancelCeremony();
9
+ }
10
+ function isCancel(err) {
11
+ return err instanceof Error && /NotAllowed|Abort|aborted|cancel/i.test(`${err.name} ${err.message}`);
12
+ }
13
+ function signalUnknown(rpId, credentialId) {
14
+ const pkc = globalThis.PublicKeyCredential;
15
+ if (!rpId || typeof pkc?.signalUnknownCredential !== "function") return;
16
+ void pkc.signalUnknownCredential({ rpId, credentialId }).catch(() => {
17
+ });
18
+ }
19
+ async function passkeyCeremony(args) {
20
+ const { authOrigin, kind, credentials } = args;
21
+ const optsRes = await fetch(`${authOrigin}/api/auth/passkey/options`, {
22
+ method: "POST",
23
+ credentials,
24
+ headers: { "Content-Type": "application/json" },
25
+ body: JSON.stringify({ kind, ...args.add ? { add: true } : {} })
26
+ });
27
+ const opts = await optsRes.json();
28
+ if (!optsRes.ok || !opts.ok || !opts.options || !opts.challenge_token) {
29
+ return { ok: false, reason: opts.reason ?? `options_failed_${optsRes.status}`, step: "options" };
30
+ }
31
+ const autofill = args.autofill === true;
32
+ if (autofill && prompting > 0) return { ok: false, reason: "cancelled", step: "prompt" };
33
+ let response;
34
+ if (!autofill) prompting++;
35
+ try {
36
+ response = await startAuthentication({ optionsJSON: opts.options, useBrowserAutofill: autofill });
37
+ } catch (err) {
38
+ return { ok: false, reason: isCancel(err) ? "cancelled" : "passkey_failed", step: "prompt" };
39
+ } finally {
40
+ if (!autofill) prompting--;
41
+ }
42
+ const verifyRes = await fetch(`${authOrigin}/api/auth/passkey/verify`, {
43
+ method: "POST",
44
+ credentials,
45
+ headers: { "Content-Type": "application/json" },
46
+ body: JSON.stringify({ challenge_token: opts.challenge_token, response })
47
+ });
48
+ const body = await verifyRes.json();
49
+ if (!verifyRes.ok || !body.ok || !body.account) {
50
+ const reason = body.reason ?? `verify_failed_${verifyRes.status}`;
51
+ if (reason === "passkey_not_recognised") signalUnknown(opts.options.rpId, response.id);
52
+ return { ok: false, reason, step: "verify" };
53
+ }
54
+ return { ok: true, account: body.account, ...body.token ? { token: body.token } : {} };
55
+ }
56
+
57
+ export {
58
+ cancelPasskeyAutofill,
59
+ passkeyCeremony
60
+ };
61
+ //# sourceMappingURL=chunk-QHZ6E64O.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/passkey.ts"],"sourcesContent":["/**\n * The passkey sign-in ceremony against ochk.io's `/api/auth/passkey/*`.\n *\n * - `signin` needs no session: the passkey is discoverable and names its account.\n * - `layer` adds a passkey to the wallet sign-in this browser just made.\n *\n * Only a passkey its account's Bitcoin address has signed for can sign in.\n * ochk.io answers `passkey_not_for_signin` for a key it holds that has no such\n * signature, which still steps up, and `passkey_not_recognised` for a key it\n * does not hold or has removed. Only the second tells the browser the key is unknown.\n */\n\nimport {\n startAuthentication,\n WebAuthnAbortService,\n type AuthenticationResponseJSON,\n type PublicKeyCredentialRequestOptionsJSON,\n} from '@simplewebauthn/browser';\n\nimport type { OcAccount } from './types';\n\n/** Which passkey a site asks for. `off` asks for none. */\nexport type PasskeyPath = 'off' | 'with' | 'layered' | 'only';\n\nexport type PasskeyKind = 'signin' | 'layer';\n\nexport type PasskeyCeremonyResult =\n | { ok: true; account: OcAccount; token?: string }\n /** `step` says where it stopped: a refusal at `verify` came after the person chose a passkey. */\n | { ok: false; reason: string; step: 'options' | 'prompt' | 'verify' };\n\n// A page runs one WebAuthn ceremony at a time, and starting one aborts the\n// last: autofill waits on the fetch, so it must not start over a prompt.\nlet prompting = 0;\n\n/** Stop the email field's passkey autofill, and never a passkey prompt the person opened. */\nexport function cancelPasskeyAutofill(): void {\n if (prompting === 0) WebAuthnAbortService.cancelCeremony();\n}\n\nfunction isCancel(err: unknown): boolean {\n return err instanceof Error && /NotAllowed|Abort|aborted|cancel/i.test(`${err.name} ${err.message}`);\n}\n\n/**\n * Tell the browser's passkey manager a key ochk.io does not hold, where it has the call (WebAuthn L3 §5.1.10.2).\n * The manager may hide or delete it, so this is never sent for a key ochk.io still holds.\n */\nfunction signalUnknown(rpId: string | undefined, credentialId: string): void {\n const pkc = (globalThis as { PublicKeyCredential?: unknown }).PublicKeyCredential as\n | { signalUnknownCredential?: (o: { rpId: string; credentialId: string }) => Promise<void> }\n | undefined;\n if (!rpId || typeof pkc?.signalUnknownCredential !== 'function') return;\n void pkc.signalUnknownCredential({ rpId, credentialId }).catch(() => {});\n}\n\n/**\n * Run one passkey ceremony. Resolves a refusal or a cancel; throws only when\n * ochk.io cannot be reached or answers something that is not JSON.\n */\nexport async function passkeyCeremony(args: {\n authOrigin: string;\n kind: PasskeyKind;\n credentials: RequestCredentials;\n add?: boolean;\n /** Offer the passkey in the email field's autofill (conditional mediation) rather than a prompt. */\n autofill?: boolean;\n}): Promise<PasskeyCeremonyResult> {\n const { authOrigin, kind, credentials } = args;\n const optsRes = await fetch(`${authOrigin}/api/auth/passkey/options`, {\n method: 'POST',\n credentials,\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ kind, ...(args.add ? { add: true } : {}) }),\n });\n const opts = (await optsRes.json()) as {\n ok?: boolean;\n options?: PublicKeyCredentialRequestOptionsJSON;\n challenge_token?: string;\n reason?: string;\n };\n if (!optsRes.ok || !opts.ok || !opts.options || !opts.challenge_token) {\n return { ok: false, reason: opts.reason ?? `options_failed_${optsRes.status}`, step: 'options' };\n }\n const autofill = args.autofill === true;\n if (autofill && prompting > 0) return { ok: false, reason: 'cancelled', step: 'prompt' };\n let response: AuthenticationResponseJSON;\n if (!autofill) prompting++;\n try {\n response = await startAuthentication({ optionsJSON: opts.options, useBrowserAutofill: autofill });\n } catch (err) {\n return { ok: false, reason: isCancel(err) ? 'cancelled' : 'passkey_failed', step: 'prompt' };\n } finally {\n if (!autofill) prompting--;\n }\n const verifyRes = await fetch(`${authOrigin}/api/auth/passkey/verify`, {\n method: 'POST',\n credentials,\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ challenge_token: opts.challenge_token, response }),\n });\n const body = (await verifyRes.json()) as {\n ok?: boolean;\n account?: OcAccount;\n token?: string;\n reason?: string;\n };\n if (!verifyRes.ok || !body.ok || !body.account) {\n const reason = body.reason ?? `verify_failed_${verifyRes.status}`;\n if (reason === 'passkey_not_recognised') signalUnknown(opts.options.rpId, response.id);\n return { ok: false, reason, step: 'verify' };\n }\n return { ok: true, account: body.account, ...(body.token ? { token: body.token } : {}) };\n}\n"],"mappings":";AAYA;AAAA,EACI;AAAA,EACA;AAAA,OAGG;AAgBP,IAAI,YAAY;AAGT,SAAS,wBAA8B;AAC1C,MAAI,cAAc,EAAG,sBAAqB,eAAe;AAC7D;AAEA,SAAS,SAAS,KAAuB;AACrC,SAAO,eAAe,SAAS,mCAAmC,KAAK,GAAG,IAAI,IAAI,IAAI,IAAI,OAAO,EAAE;AACvG;AAMA,SAAS,cAAc,MAA0B,cAA4B;AACzE,QAAM,MAAO,WAAiD;AAG9D,MAAI,CAAC,QAAQ,OAAO,KAAK,4BAA4B,WAAY;AACjE,OAAK,IAAI,wBAAwB,EAAE,MAAM,aAAa,CAAC,EAAE,MAAM,MAAM;AAAA,EAAC,CAAC;AAC3E;AAMA,eAAsB,gBAAgB,MAOH;AAC/B,QAAM,EAAE,YAAY,MAAM,YAAY,IAAI;AAC1C,QAAM,UAAU,MAAM,MAAM,GAAG,UAAU,6BAA6B;AAAA,IAClE,QAAQ;AAAA,IACR;AAAA,IACA,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,IAC9C,MAAM,KAAK,UAAU,EAAE,MAAM,GAAI,KAAK,MAAM,EAAE,KAAK,KAAK,IAAI,CAAC,EAAG,CAAC;AAAA,EACrE,CAAC;AACD,QAAM,OAAQ,MAAM,QAAQ,KAAK;AAMjC,MAAI,CAAC,QAAQ,MAAM,CAAC,KAAK,MAAM,CAAC,KAAK,WAAW,CAAC,KAAK,iBAAiB;AACnE,WAAO,EAAE,IAAI,OAAO,QAAQ,KAAK,UAAU,kBAAkB,QAAQ,MAAM,IAAI,MAAM,UAAU;AAAA,EACnG;AACA,QAAM,WAAW,KAAK,aAAa;AACnC,MAAI,YAAY,YAAY,EAAG,QAAO,EAAE,IAAI,OAAO,QAAQ,aAAa,MAAM,SAAS;AACvF,MAAI;AACJ,MAAI,CAAC,SAAU;AACf,MAAI;AACA,eAAW,MAAM,oBAAoB,EAAE,aAAa,KAAK,SAAS,oBAAoB,SAAS,CAAC;AAAA,EACpG,SAAS,KAAK;AACV,WAAO,EAAE,IAAI,OAAO,QAAQ,SAAS,GAAG,IAAI,cAAc,kBAAkB,MAAM,SAAS;AAAA,EAC/F,UAAE;AACE,QAAI,CAAC,SAAU;AAAA,EACnB;AACA,QAAM,YAAY,MAAM,MAAM,GAAG,UAAU,4BAA4B;AAAA,IACnE,QAAQ;AAAA,IACR;AAAA,IACA,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,IAC9C,MAAM,KAAK,UAAU,EAAE,iBAAiB,KAAK,iBAAiB,SAAS,CAAC;AAAA,EAC5E,CAAC;AACD,QAAM,OAAQ,MAAM,UAAU,KAAK;AAMnC,MAAI,CAAC,UAAU,MAAM,CAAC,KAAK,MAAM,CAAC,KAAK,SAAS;AAC5C,UAAM,SAAS,KAAK,UAAU,iBAAiB,UAAU,MAAM;AAC/D,QAAI,WAAW,yBAA0B,eAAc,KAAK,QAAQ,MAAM,SAAS,EAAE;AACrF,WAAO,EAAE,IAAI,OAAO,QAAQ,MAAM,SAAS;AAAA,EAC/C;AACA,SAAO,EAAE,IAAI,MAAM,SAAS,KAAK,SAAS,GAAI,KAAK,QAAQ,EAAE,OAAO,KAAK,MAAM,IAAI,CAAC,EAAG;AAC3F;","names":[]}
@@ -19,7 +19,7 @@ import {
19
19
  } from "./chunk-5KQ36QNH.mjs";
20
20
  import {
21
21
  failureMessage
22
- } from "./chunk-OKIFTNEO.mjs";
22
+ } from "./chunk-HQ6APBHF.mjs";
23
23
  import {
24
24
  tabSessionHeader
25
25
  } from "./chunk-4BOO7EQR.mjs";
@@ -960,4 +960,4 @@ export {
960
960
  ghostBtnStyle,
961
961
  dangerBtnStyle
962
962
  };
963
- //# sourceMappingURL=chunk-OI64DUVC.mjs.map
963
+ //# sourceMappingURL=chunk-W6YYHOYL.mjs.map
@@ -4,9 +4,9 @@ import {
4
4
  OcAddressInput,
5
5
  OcSignInButton,
6
6
  useOcAddressSuggestion
7
- } from "./chunk-MIBVEZLP.mjs";
8
- import "./chunk-IKNAIRW5.mjs";
9
- import "./chunk-OKIFTNEO.mjs";
7
+ } from "./chunk-7VBIHZVF.mjs";
8
+ import "./chunk-FDN374RW.mjs";
9
+ import "./chunk-HQ6APBHF.mjs";
10
10
  import "./chunk-E3QI365E.mjs";
11
11
  import "./chunk-X4PPXI3K.mjs";
12
12
  import "./chunk-JTT77LMU.mjs";
package/dist/index.d.ts CHANGED
@@ -130,6 +130,9 @@ interface UseOcAddressSuggestionReturn {
130
130
  declare function useOcAddressSuggestion(options: UseOcAddressSuggestionOptions): UseOcAddressSuggestionReturn;
131
131
  declare const OcAddressInput: React.ForwardRefExoticComponent<OcAddressInputProps & React.RefAttributes<HTMLInputElement>>;
132
132
 
133
+ type PasskeyPath = 'off' | 'with' | 'layered' | 'only';
134
+ type PasskeyKind = 'signin' | 'layer';
135
+
133
136
  interface OcSignInBaseProps {
134
137
  audience: string;
135
138
  returnTo?: string;
@@ -142,6 +145,7 @@ interface OcSignInBaseProps {
142
145
  wallet?: boolean;
143
146
  email?: boolean;
144
147
  };
148
+ passkey?: PasskeyPath;
145
149
  linkPrompt?: boolean;
146
150
  add?: boolean;
147
151
  onSeveralSessions?: () => unknown;
@@ -154,10 +158,11 @@ type OcSignInProps = OcSignInBaseProps & ({
154
158
  mode: 'first-party';
155
159
  onSuccess: (account: OcAccount, token?: string) => void;
156
160
  providerHref?: (providerId: string) => string;
161
+ passkey?: Exclude<PasskeyPath, 'layered'>;
157
162
  });
158
163
  declare function safeReturnTo(input: string | undefined): string;
159
164
  declare function familyReturnTarget(input: string | undefined | null): string | undefined;
160
- declare function OcSignIn({ audience, returnTo, onSuccess, resolveReturnTo, linkPrompt: linkPromptProp, add: addProp, onSeveralSessions, authOrigin, initialPath, providersFirst, paths, className, mode, providerHref, }: OcSignInProps): React.ReactElement;
165
+ declare function OcSignIn({ audience, returnTo, onSuccess, resolveReturnTo, linkPrompt: linkPromptProp, add: addProp, onSeveralSessions, authOrigin, initialPath, providersFirst, paths, className, mode, providerHref, passkey, }: OcSignInProps): React.ReactElement;
161
166
 
162
167
  declare function otpNetworkCapText(retryAt: unknown, instead?: string): string;
163
168
  declare function newAccountsCapText(retryAt: unknown): string;
@@ -248,19 +253,46 @@ interface UseHostOptions {
248
253
  type WebAuthnRegisterResult = {
249
254
  ok: true;
250
255
  credential: WebAuthnCredentialPublic;
256
+ binding?: {
257
+ ok: true;
258
+ } | {
259
+ ok: false;
260
+ reason: string;
261
+ };
251
262
  } | {
252
263
  ok: false;
253
264
  reason: string;
254
265
  };
266
+ type BindSigner = (statement: string, address: string) => Promise<string>;
255
267
  interface UseWebAuthnRegisterReturn {
256
268
  status: WebAuthnRegisterStatus;
257
269
  error: Error | null;
258
270
  register: (args?: {
259
271
  label?: string;
272
+ bind?: BindSigner;
260
273
  }) => Promise<WebAuthnRegisterResult>;
261
274
  reset: () => void;
262
275
  }
263
276
  declare function useWebAuthnRegister(opts?: UseHostOptions): UseWebAuthnRegisterReturn;
277
+ type PasskeySignInResult = {
278
+ ok: true;
279
+ account: OcAccount;
280
+ token?: string;
281
+ } | {
282
+ ok: false;
283
+ reason: string;
284
+ };
285
+ interface UsePasskeySignInReturn {
286
+ status: WebAuthnAssertionStatus;
287
+ error: Error | null;
288
+ signIn: (args?: {
289
+ kind?: PasskeyKind;
290
+ add?: boolean;
291
+ credentials?: RequestCredentials;
292
+ }) => Promise<PasskeySignInResult>;
293
+ reset: () => void;
294
+ }
295
+ declare function usePasskeySignIn(opts?: UseHostOptions): UsePasskeySignInReturn;
264
296
  type WebAuthnRenameResult = {
265
297
  ok: true;
266
298
  credential: WebAuthnCredentialPublic;
@@ -316,4 +348,4 @@ declare function isSudoAccountMismatch(body: {
316
348
  reason?: string;
317
349
  } | null | undefined): boolean;
318
350
 
319
- export { DEFAULT_CONFIG, DISPLAY_IDENTITY_KINDS, type DisplayIdentity, type DisplayIdentityKind, FRAGMENT_TTL_MS, type OcAccount, OcAccountChip, type OcAccountChipProps, OcAccountPill, type OcAccountPillProps, type OcAccountSummary, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcBond, type OcBondProps, type OcBondView, OcLinkedIdentities, type OcLinkedIdentitiesProps, type OcLinkedIdentity, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignIn, OcSignInButton, type OcSignInButtonProps, type OcSignInProps, type OcSignOutResult, type OcSignOutScope, type OcTabSession, type RedirectToSudoArgs, SUDO_ACCOUNT_MISMATCH_MESSAGE, TAB_ACCOUNT_HINT_KEY, TAB_ADOPT_HASH, TAB_SESSION_HEADER, TAB_SESSION_STORAGE_KEY, type UseOcAddressSuggestionOptions, type UseOcAddressSuggestionReturn, type UseStepUpAuthReturn, type UseWebAuthnListReturn, type UseWebAuthnRegisterReturn, type WebAuthnAssertionStatus, type WebAuthnCredentialPublic, type WebAuthnListStatus, type WebAuthnRegisterResult, type WebAuthnRegisterStatus, type WebAuthnRemoveResult, type WebAuthnRenameResult, type WebAuthnStepUpResult, bondFloorsText, buildAddAccountUrl, buildSignInUrl, capText, clearTabSession, consumeTabAccountHint, consumeTabAdoptMarker, familyReturnTarget, fetchOcBond, fetchOcLinkedIdentities, handleSudoRequired, installTabFetchInterceptor, installTabLinkDecorator, isSudoAccountMismatch, keepFragmentOnReturnLinks, newAccountsCapText, otpNetworkCapText, readTabSession, redirectToSudo, restoreReturnFragment, returnToHere, safeReturnTo, stripFragment, tabSessionHeader, useOcAddressSuggestion, useOcSession, useOptionalOcSession, useStepUpAuth, useWebAuthnList, useWebAuthnRegister, withoutFragment, writeTabSession };
351
+ export { type BindSigner, DEFAULT_CONFIG, DISPLAY_IDENTITY_KINDS, type DisplayIdentity, type DisplayIdentityKind, FRAGMENT_TTL_MS, type OcAccount, OcAccountChip, type OcAccountChipProps, OcAccountPill, type OcAccountPillProps, type OcAccountSummary, OcAddressInput, type OcAddressInputProps, type OcAuthConfig, OcBond, type OcBondProps, type OcBondView, OcLinkedIdentities, type OcLinkedIdentitiesProps, type OcLinkedIdentity, OcSessionProvider, type OcSessionState, type OcSessionStatus, OcSignIn, OcSignInButton, type OcSignInButtonProps, type OcSignInProps, type OcSignOutResult, type OcSignOutScope, type OcTabSession, type PasskeyPath, type PasskeySignInResult, type RedirectToSudoArgs, SUDO_ACCOUNT_MISMATCH_MESSAGE, TAB_ACCOUNT_HINT_KEY, TAB_ADOPT_HASH, TAB_SESSION_HEADER, TAB_SESSION_STORAGE_KEY, type UseOcAddressSuggestionOptions, type UseOcAddressSuggestionReturn, type UsePasskeySignInReturn, type UseStepUpAuthReturn, type UseWebAuthnListReturn, type UseWebAuthnRegisterReturn, type WebAuthnAssertionStatus, type WebAuthnCredentialPublic, type WebAuthnListStatus, type WebAuthnRegisterResult, type WebAuthnRegisterStatus, type WebAuthnRemoveResult, type WebAuthnRenameResult, type WebAuthnStepUpResult, bondFloorsText, buildAddAccountUrl, buildSignInUrl, capText, clearTabSession, consumeTabAccountHint, consumeTabAdoptMarker, familyReturnTarget, fetchOcBond, fetchOcLinkedIdentities, handleSudoRequired, installTabFetchInterceptor, installTabLinkDecorator, isSudoAccountMismatch, keepFragmentOnReturnLinks, newAccountsCapText, otpNetworkCapText, readTabSession, redirectToSudo, restoreReturnFragment, returnToHere, safeReturnTo, stripFragment, tabSessionHeader, useOcAddressSuggestion, useOcSession, useOptionalOcSession, usePasskeySignIn, useStepUpAuth, useWebAuthnList, useWebAuthnRegister, withoutFragment, writeTabSession };