@orangecheck/auth-client 2.49.0 → 2.50.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.
- package/dist/bond.mjs +6 -6
- package/dist/{chunk-GQK4LWZT.mjs → chunk-33ZCBA2C.mjs} +5 -5
- package/dist/{chunk-NLWGBAJL.mjs → chunk-6IUIO5QX.mjs} +11 -11
- package/dist/{chunk-F7O4OREM.mjs → chunk-FNGBJD4S.mjs} +2 -2
- package/dist/{chunk-X4IFJDCV.mjs → chunk-IKNAIRW5.mjs} +14 -2
- package/dist/chunk-IKNAIRW5.mjs.map +1 -0
- package/dist/{chunk-UHQCVPT4.mjs → chunk-MIBVEZLP.mjs} +15 -12
- package/dist/chunk-MIBVEZLP.mjs.map +1 -0
- package/dist/{chunk-RKTFPO23.mjs → chunk-OKIFTNEO.mjs} +15 -1
- package/dist/chunk-OKIFTNEO.mjs.map +1 -0
- package/dist/{chunk-GZDZ45I7.mjs → chunk-UTR42EZW.mjs} +5 -5
- package/dist/{chunk-PQHFAVVM.mjs → chunk-X4PPXI3K.mjs} +1 -1
- package/dist/chunk-X4PPXI3K.mjs.map +1 -0
- package/dist/{chunk-YGXMLIQ3.mjs → chunk-XVLOTOCX.mjs} +3 -3
- package/dist/components.mjs +5 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +99 -80
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -10
- package/dist/linked-identities.mjs +5 -5
- package/dist/provider.mjs +4 -2
- package/dist/refusal.mjs +7 -1
- package/dist/signin.mjs +7 -7
- package/dist/sudo.mjs +2 -2
- package/dist/types.mjs +1 -1
- package/dist/webauthn.mjs +5 -3
- package/package.json +1 -1
- package/dist/chunk-PQHFAVVM.mjs.map +0 -1
- package/dist/chunk-RKTFPO23.mjs.map +0 -1
- package/dist/chunk-UHQCVPT4.mjs.map +0 -1
- package/dist/chunk-X4IFJDCV.mjs.map +0 -1
- /package/dist/{chunk-GQK4LWZT.mjs.map → chunk-33ZCBA2C.mjs.map} +0 -0
- /package/dist/{chunk-NLWGBAJL.mjs.map → chunk-6IUIO5QX.mjs.map} +0 -0
- /package/dist/{chunk-F7O4OREM.mjs.map → chunk-FNGBJD4S.mjs.map} +0 -0
- /package/dist/{chunk-GZDZ45I7.mjs.map → chunk-UTR42EZW.mjs.map} +0 -0
- /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(
|
|
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(
|
|
953
|
-
void trySignOut().then((r) => setSignOutFailed(
|
|
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(
|
|
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(
|
|
1052
|
-
void trySignOut().then((r) => setSignOutFailed(
|
|
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;
|