@orangecheck/auth-client 2.49.0 → 2.50.1

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 (36) hide show
  1. package/dist/bond.mjs +6 -6
  2. package/dist/{chunk-GZDZ45I7.mjs → chunk-2NCLRIVO.mjs} +18 -12
  3. package/dist/{chunk-GZDZ45I7.mjs.map → chunk-2NCLRIVO.mjs.map} +1 -1
  4. package/dist/{chunk-F7O4OREM.mjs → chunk-FNGBJD4S.mjs} +2 -2
  5. package/dist/{chunk-X4IFJDCV.mjs → chunk-IKNAIRW5.mjs} +14 -2
  6. package/dist/chunk-IKNAIRW5.mjs.map +1 -0
  7. package/dist/{chunk-GQK4LWZT.mjs → chunk-MGZ4NVXW.mjs} +5 -5
  8. package/dist/{chunk-UHQCVPT4.mjs → chunk-MIBVEZLP.mjs} +15 -12
  9. package/dist/chunk-MIBVEZLP.mjs.map +1 -0
  10. package/dist/{chunk-NLWGBAJL.mjs → chunk-NJEQHNVI.mjs} +11 -11
  11. package/dist/{chunk-RKTFPO23.mjs → chunk-OKIFTNEO.mjs} +15 -1
  12. package/dist/chunk-OKIFTNEO.mjs.map +1 -0
  13. package/dist/{chunk-PQHFAVVM.mjs → chunk-X4PPXI3K.mjs} +1 -1
  14. package/dist/chunk-X4PPXI3K.mjs.map +1 -0
  15. package/dist/{chunk-YGXMLIQ3.mjs → chunk-XVLOTOCX.mjs} +3 -3
  16. package/dist/components.mjs +5 -3
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +112 -87
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.mjs +10 -10
  21. package/dist/linked-identities.mjs +5 -5
  22. package/dist/provider.mjs +4 -2
  23. package/dist/refusal.mjs +7 -1
  24. package/dist/signin.mjs +7 -7
  25. package/dist/sudo.mjs +2 -2
  26. package/dist/types.mjs +1 -1
  27. package/dist/webauthn.mjs +5 -3
  28. package/package.json +2 -2
  29. package/dist/chunk-PQHFAVVM.mjs.map +0 -1
  30. package/dist/chunk-RKTFPO23.mjs.map +0 -1
  31. package/dist/chunk-UHQCVPT4.mjs.map +0 -1
  32. package/dist/chunk-X4IFJDCV.mjs.map +0 -1
  33. /package/dist/{chunk-F7O4OREM.mjs.map → chunk-FNGBJD4S.mjs.map} +0 -0
  34. /package/dist/{chunk-GQK4LWZT.mjs.map → chunk-MGZ4NVXW.mjs.map} +0 -0
  35. /package/dist/{chunk-NLWGBAJL.mjs.map → chunk-NJEQHNVI.mjs.map} +0 -0
  36. /package/dist/{chunk-YGXMLIQ3.mjs.map → chunk-XVLOTOCX.mjs.map} +0 -0
package/dist/index.js CHANGED
@@ -325,6 +325,87 @@ function buildAddAccountUrl(cfg, returnTo) {
325
325
  u.searchParams.set("add", "1");
326
326
  return u.toString();
327
327
  }
328
+
329
+ // src/own-word.ts
330
+ function ownWord(table, code) {
331
+ return Object.prototype.hasOwnProperty.call(table, code) ? table[code] : void 0;
332
+ }
333
+
334
+ // src/refusal.ts
335
+ var ENDED_ERRORS = {
336
+ signed_out: "You were signed out while signing in. Sign in again.",
337
+ account_deleted: "This account is being deleted, so you can't sign in to it.",
338
+ no_roster: "An account in this browser was signed out while you were signing in, so this sign-in wasn't kept. Sign in again."
339
+ };
340
+ function endedSigninText(reason) {
341
+ return ownWord(ENDED_ERRORS, reason);
342
+ }
343
+ var SEVERAL_SESSIONS_TEXT = "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.";
344
+ var SIGN_OUT_SEVERAL_SESSIONS_TEXT = "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.";
345
+ var SWITCH_SEVERAL_SESSIONS_TEXT = "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.";
346
+ async function isSeveralSessionsAnswer(res) {
347
+ if (res.status !== 409) return false;
348
+ try {
349
+ const body = await res.clone().json();
350
+ return body?.reason === "several_sessions";
351
+ } catch {
352
+ return false;
353
+ }
354
+ }
355
+ function isSeveralSessions(err) {
356
+ return err instanceof Error && err.message === "several_sessions";
357
+ }
358
+ var SIGNIN_ERRORS = {
359
+ bad_request: "That doesn't look like a Bitcoin address.",
360
+ invalid_challenge: "That signature doesn't match this address. Sign with the wallet that holds it.",
361
+ sig_invalid: "That signature doesn't match this address. Sign with the wallet that holds it.",
362
+ sig_unsupported_scheme: "We can't check this wallet's signature format yet. Try another wallet, or use email.",
363
+ expired: "That request timed out. Try again for a fresh one.",
364
+ not_yet_valid: "That request is not valid yet. Check your device clock, then try again.",
365
+ nonce_mismatch: "That request didn't match. Try again for a fresh one.",
366
+ audience_mismatch: "That request didn't match this site. Reload the page and try again.",
367
+ purpose_mismatch: "That request didn't match. Try again for a fresh one.",
368
+ malformed: "That signature couldn't be read. Copy it again, whole.",
369
+ challenge_mismatch: "That sign-in message changed after it was issued. Get a new one and sign it again.",
370
+ mainnet_only: "Sign in with a mainnet Bitcoin address.",
371
+ cross_site_blocked: "Your browser blocked this request. Reload the page and try again.",
372
+ rate_limited: "Too many tries. Wait a minute, then try again.",
373
+ invalid_email: "That email address doesn't look right.",
374
+ mailer_unavailable: "We couldn't send the email right now. Try again in a minute.",
375
+ mailer_error: "We couldn't send the email right now. Try again in a minute.",
376
+ wrong_code: "That code isn't right. Check the newest email from us.",
377
+ replay: "That code was already used. Send a new one.",
378
+ invalid_token: "That code is no longer valid. Send a new one.",
379
+ email_mismatch: "That code was sent to a different address. Send a new one.",
380
+ several_sessions: SEVERAL_SESSIONS_TEXT,
381
+ ...ENDED_ERRORS
382
+ };
383
+ var EMAIL_ERRORS = {
384
+ expired: "That code expired. Send a new one.",
385
+ signed_out: "You were signed out while signing in. Send a new code to sign in again.",
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
+ };
388
+ var SUBMIT_ERRORS = {
389
+ bad_request: "That signature couldn't be read. Copy it again, whole."
390
+ };
391
+ function networkError(authOrigin) {
392
+ let host = authOrigin;
393
+ try {
394
+ host = new URL(authOrigin).host;
395
+ } catch {
396
+ }
397
+ return `We couldn't reach the orangecheck sign-in service at ${host}. Check your connection, then try again.`;
398
+ }
399
+ function humanSigninError(reason, path, step = "challenge") {
400
+ 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);
402
+ if (own) return own;
403
+ 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
+ }
405
+ function failureMessage(err, path, step, authOrigin) {
406
+ if (err instanceof TypeError || err instanceof SyntaxError) return networkError(authOrigin);
407
+ return humanSigninError(err instanceof Error ? err.message : "failed", path, step);
408
+ }
328
409
  var SessionContext = React4__namespace.createContext(null);
329
410
  function onHistory(change) {
330
411
  window.addEventListener("popstate", change);
@@ -574,6 +655,10 @@ function OcSessionProvider({
574
655
  return { ok: false, reason: "unreachable" };
575
656
  }
576
657
  if (!res.ok && res.status !== 401) {
658
+ if (await isSeveralSessionsAnswer(res)) {
659
+ await refresh();
660
+ return { ok: false, reason: "several_sessions", status: 409 };
661
+ }
577
662
  return { ok: false, reason: "refused", status: res.status };
578
663
  }
579
664
  clearTabSession();
@@ -605,6 +690,10 @@ function OcSessionProvider({
605
690
  body: JSON.stringify({ did_oc: didOc })
606
691
  });
607
692
  if (!res.ok) {
693
+ if (await isSeveralSessionsAnswer(res)) {
694
+ await refresh();
695
+ throw new Error(SWITCH_SEVERAL_SESSIONS_TEXT);
696
+ }
608
697
  let reason = `http_${res.status}`;
609
698
  try {
610
699
  const body = await res.json();
@@ -737,7 +826,7 @@ function OcAccountChip({
737
826
  const { status, account, signInUrl: sessionSignInUrl, trySignOut } = useOcSession();
738
827
  const signInUrl = signInUrlOverride ?? sessionSignInUrl;
739
828
  const [open, setOpen] = React4__namespace.useState(false);
740
- const [signOutFailed, setSignOutFailed] = React4__namespace.useState(false);
829
+ const [signOutFailed, setSignOutFailed] = React4__namespace.useState(null);
741
830
  const wrapRef = React4__namespace.useRef(null);
742
831
  React4__namespace.useEffect(() => {
743
832
  if (!open) return;
@@ -949,8 +1038,8 @@ function OcAccountChip({
949
1038
  role: "menuitem",
950
1039
  onClick: () => {
951
1040
  setOpen(false);
952
- setSignOutFailed(false);
953
- void trySignOut().then((r) => setSignOutFailed(!r.ok));
1041
+ setSignOutFailed(null);
1042
+ void trySignOut().then((r) => setSignOutFailed(r.ok ? null : r.reason));
954
1043
  },
955
1044
  className: menuItemClassName,
956
1045
  "data-oc-account-chip-item": "",
@@ -986,19 +1075,19 @@ function OcAccountChip({
986
1075
  ]
987
1076
  }
988
1077
  ),
989
- signOutFailed ? /* @__PURE__ */ jsxRuntime.jsx(SignOutFailed, {}) : null
1078
+ signOutFailed ? /* @__PURE__ */ jsxRuntime.jsx(SignOutFailed, { reason: signOutFailed }) : null
990
1079
  ]
991
1080
  }
992
1081
  );
993
1082
  }
994
- function SignOutFailed() {
1083
+ function SignOutFailed({ reason }) {
995
1084
  return /* @__PURE__ */ jsxRuntime.jsx(
996
1085
  "span",
997
1086
  {
998
1087
  role: "alert",
999
1088
  "data-oc-signout-failed": "",
1000
1089
  style: { display: "block", marginTop: 4, fontSize: 12, color: "var(--destructive, #dc2626)" },
1001
- children: "Couldn\u2019t sign out. You\u2019re still signed in; try again."
1090
+ children: reason === "several_sessions" ? SIGN_OUT_SEVERAL_SESSIONS_TEXT : "Couldn\u2019t sign out. You\u2019re still signed in; try again."
1002
1091
  }
1003
1092
  );
1004
1093
  }
@@ -1031,7 +1120,7 @@ function OcAccountPill({
1031
1120
  ...rest
1032
1121
  }) {
1033
1122
  const { status, account, trySignOut } = useOcSession();
1034
- const [signOutFailed, setSignOutFailed] = React4__namespace.useState(false);
1123
+ const [signOutFailed, setSignOutFailed] = React4__namespace.useState(null);
1035
1124
  if (status !== "authenticated" || !account) return null;
1036
1125
  const label = render ? render({ address: account.didOc, displayName: account.displayName }) : account.displayName ?? shortenAddress(account.didOc);
1037
1126
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -1048,8 +1137,8 @@ function OcAccountPill({
1048
1137
  {
1049
1138
  type: "button",
1050
1139
  onClick: () => {
1051
- setSignOutFailed(false);
1052
- void trySignOut().then((r) => setSignOutFailed(!r.ok));
1140
+ setSignOutFailed(null);
1141
+ void trySignOut().then((r) => setSignOutFailed(r.ok ? null : r.reason));
1053
1142
  },
1054
1143
  "aria-label": "Sign out",
1055
1144
  style: {
@@ -1063,7 +1152,7 @@ function OcAccountPill({
1063
1152
  children: "sign out"
1064
1153
  }
1065
1154
  ),
1066
- signOutFailed ? /* @__PURE__ */ jsxRuntime.jsx(SignOutFailed, {}) : null
1155
+ signOutFailed ? /* @__PURE__ */ jsxRuntime.jsx(SignOutFailed, { reason: signOutFailed }) : null
1067
1156
  ]
1068
1157
  }
1069
1158
  );
@@ -1486,76 +1575,6 @@ var SIGNIN_BUTTON_RADIUS = "var(--oc-signin-button-radius, 6px)";
1486
1575
  var SIGNIN_STRONG = "var(--oc-signin-strong, 600)";
1487
1576
  var SIGNIN_ARROW = "var(--oc-signin-arrow, inline)";
1488
1577
  var signinRoleSize = (role, fallback) => `var(--oc-signin-${role}-size, ${fallback})`;
1489
-
1490
- // src/own-word.ts
1491
- function ownWord(table, code) {
1492
- return Object.prototype.hasOwnProperty.call(table, code) ? table[code] : void 0;
1493
- }
1494
-
1495
- // src/refusal.ts
1496
- var ENDED_ERRORS = {
1497
- signed_out: "You were signed out while signing in. Sign in again.",
1498
- account_deleted: "This account is being deleted, so you can't sign in to it.",
1499
- no_roster: "An account in this browser was signed out while you were signing in, so this sign-in wasn't kept. Sign in again."
1500
- };
1501
- function endedSigninText(reason) {
1502
- return ownWord(ENDED_ERRORS, reason);
1503
- }
1504
- var SEVERAL_SESSIONS_TEXT = "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.";
1505
- function isSeveralSessions(err) {
1506
- return err instanceof Error && err.message === "several_sessions";
1507
- }
1508
- var SIGNIN_ERRORS = {
1509
- bad_request: "That doesn't look like a Bitcoin address.",
1510
- invalid_challenge: "That signature doesn't match this address. Sign with the wallet that holds it.",
1511
- sig_invalid: "That signature doesn't match this address. Sign with the wallet that holds it.",
1512
- sig_unsupported_scheme: "We can't check this wallet's signature format yet. Try another wallet, or use email.",
1513
- expired: "That request timed out. Try again for a fresh one.",
1514
- not_yet_valid: "That request is not valid yet. Check your device clock, then try again.",
1515
- nonce_mismatch: "That request didn't match. Try again for a fresh one.",
1516
- audience_mismatch: "That request didn't match this site. Reload the page and try again.",
1517
- purpose_mismatch: "That request didn't match. Try again for a fresh one.",
1518
- malformed: "That signature couldn't be read. Copy it again, whole.",
1519
- challenge_mismatch: "That sign-in message changed after it was issued. Get a new one and sign it again.",
1520
- mainnet_only: "Sign in with a mainnet Bitcoin address.",
1521
- cross_site_blocked: "Your browser blocked this request. Reload the page and try again.",
1522
- rate_limited: "Too many tries. Wait a minute, then try again.",
1523
- invalid_email: "That email address doesn't look right.",
1524
- mailer_unavailable: "We couldn't send the email right now. Try again in a minute.",
1525
- mailer_error: "We couldn't send the email right now. Try again in a minute.",
1526
- wrong_code: "That code isn't right. Check the newest email from us.",
1527
- replay: "That code was already used. Send a new one.",
1528
- invalid_token: "That code is no longer valid. Send a new one.",
1529
- email_mismatch: "That code was sent to a different address. Send a new one.",
1530
- several_sessions: SEVERAL_SESSIONS_TEXT,
1531
- ...ENDED_ERRORS
1532
- };
1533
- var EMAIL_ERRORS = {
1534
- expired: "That code expired. Send a new one.",
1535
- signed_out: "You were signed out while signing in. Send a new code to sign in again.",
1536
- 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."
1537
- };
1538
- var SUBMIT_ERRORS = {
1539
- bad_request: "That signature couldn't be read. Copy it again, whole."
1540
- };
1541
- function networkError(authOrigin) {
1542
- let host = authOrigin;
1543
- try {
1544
- host = new URL(authOrigin).host;
1545
- } catch {
1546
- }
1547
- return `We couldn't reach the orangecheck sign-in service at ${host}. Check your connection, then try again.`;
1548
- }
1549
- function humanSigninError(reason, path, step = "challenge") {
1550
- if (!/^[a-z0-9_]+$/.test(reason)) return reason;
1551
- const own = path === "wallet" && step === "submit" && ownWord(SUBMIT_ERRORS, reason) || path === "email" && ownWord(EMAIL_ERRORS, reason);
1552
- if (own) return own;
1553
- return ownWord(SIGNIN_ERRORS, reason) ?? (path === "email" ? "That didn't work. Try again, or send a new code." : "That didn't work. Try again.");
1554
- }
1555
- function failureMessage(err, path, step, authOrigin) {
1556
- if (err instanceof TypeError || err instanceof SyntaxError) return networkError(authOrigin);
1557
- return humanSigninError(err instanceof Error ? err.message : "failed", path, step);
1558
- }
1559
1578
  var DEFAULT_AUTH_ORIGIN = "https://ochk.io";
1560
1579
  async function fetchOcLinkedIdentities(opts) {
1561
1580
  const authOrigin = opts?.authOrigin ?? DEFAULT_AUTH_ORIGIN;
@@ -2287,15 +2306,19 @@ function TransferConfirm({
2287
2306
  ] });
2288
2307
  }
2289
2308
  function LazyWalletButton(props) {
2290
- const [Comp, setComp] = React4__namespace.useState(null);
2309
+ const [loaded, setLoaded] = React4__namespace.useState(null);
2291
2310
  const [failed, setFailed] = React4__namespace.useState(false);
2292
2311
  React4__namespace.useEffect(() => {
2293
2312
  let alive = true;
2294
- import('@orangecheck/wallet-adapter/react').then((m) => {
2313
+ Promise.all([
2314
+ import('@orangecheck/wallet-adapter/react'),
2315
+ import('@orangecheck/wallet-adapter')
2316
+ ]).then(([r, m]) => {
2295
2317
  if (alive) {
2296
- setComp(
2297
- () => m.OcWalletButton
2298
- );
2318
+ setLoaded({
2319
+ Button: r.OcWalletButton,
2320
+ text: m.walletFailureText
2321
+ });
2299
2322
  }
2300
2323
  }).catch(() => {
2301
2324
  if (alive) setFailed(true);
@@ -2307,8 +2330,10 @@ function LazyWalletButton(props) {
2307
2330
  if (failed) {
2308
2331
  return /* @__PURE__ */ jsxRuntime.jsx(ErrorLine, { children: "could not load wallet support \xB7 refresh to try again" });
2309
2332
  }
2310
- if (!Comp) return /* @__PURE__ */ jsxRuntime.jsx("span", { style: hintStyle, children: "loading wallet options\u2026" });
2311
- return /* @__PURE__ */ jsxRuntime.jsx(Comp, { ...props }, props.message);
2333
+ if (!loaded) return /* @__PURE__ */ jsxRuntime.jsx("span", { style: hintStyle, children: "loading wallet options\u2026" });
2334
+ const { Button, text } = loaded;
2335
+ const onError = (err, walletId) => props.onError({ message: text(err, { paste: !!props.showManual }) }, walletId);
2336
+ return /* @__PURE__ */ jsxRuntime.jsx(Button, { ...props, onError }, props.message);
2312
2337
  }
2313
2338
  function mask(value, kind) {
2314
2339
  if (kind === "email") {