@orangecheck/auth-client 2.48.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-PBDOIRFF.mjs → chunk-33ZCBA2C.mjs} +5 -5
- package/dist/{chunk-MEN6WL3W.mjs → chunk-6IUIO5QX.mjs} +36 -10
- package/dist/chunk-6IUIO5QX.mjs.map +1 -0
- 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-KD4XTVFV.mjs → chunk-OKIFTNEO.mjs} +26 -3
- package/dist/chunk-OKIFTNEO.mjs.map +1 -0
- package/dist/{chunk-KL4QKCE3.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 +3 -2
- package/dist/index.js +122 -75
- 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 +11 -1
- package/dist/signin.mjs +7 -6
- 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-KD4XTVFV.mjs.map +0 -1
- package/dist/chunk-MEN6WL3W.mjs.map +0 -1
- package/dist/chunk-PQHFAVVM.mjs.map +0 -1
- package/dist/chunk-UHQCVPT4.mjs.map +0 -1
- package/dist/chunk-X4IFJDCV.mjs.map +0 -1
- /package/dist/{chunk-PBDOIRFF.mjs.map → chunk-33ZCBA2C.mjs.map} +0 -0
- /package/dist/{chunk-F7O4OREM.mjs.map → chunk-FNGBJD4S.mjs.map} +0 -0
- /package/dist/{chunk-KL4QKCE3.mjs.map → chunk-UTR42EZW.mjs.map} +0 -0
- /package/dist/{chunk-YGXMLIQ3.mjs.map → chunk-XVLOTOCX.mjs.map} +0 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useOcSession
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IKNAIRW5.mjs";
|
|
4
|
+
import {
|
|
5
|
+
SIGN_OUT_SEVERAL_SESSIONS_TEXT
|
|
6
|
+
} from "./chunk-OKIFTNEO.mjs";
|
|
4
7
|
|
|
5
8
|
// src/components.tsx
|
|
6
9
|
import * as React from "react";
|
|
@@ -33,7 +36,7 @@ function OcAccountChip({
|
|
|
33
36
|
const { status, account, signInUrl: sessionSignInUrl, trySignOut } = useOcSession();
|
|
34
37
|
const signInUrl = signInUrlOverride ?? sessionSignInUrl;
|
|
35
38
|
const [open, setOpen] = React.useState(false);
|
|
36
|
-
const [signOutFailed, setSignOutFailed] = React.useState(
|
|
39
|
+
const [signOutFailed, setSignOutFailed] = React.useState(null);
|
|
37
40
|
const wrapRef = React.useRef(null);
|
|
38
41
|
React.useEffect(() => {
|
|
39
42
|
if (!open) return;
|
|
@@ -245,8 +248,8 @@ function OcAccountChip({
|
|
|
245
248
|
role: "menuitem",
|
|
246
249
|
onClick: () => {
|
|
247
250
|
setOpen(false);
|
|
248
|
-
setSignOutFailed(
|
|
249
|
-
void trySignOut().then((r) => setSignOutFailed(
|
|
251
|
+
setSignOutFailed(null);
|
|
252
|
+
void trySignOut().then((r) => setSignOutFailed(r.ok ? null : r.reason));
|
|
250
253
|
},
|
|
251
254
|
className: menuItemClassName,
|
|
252
255
|
"data-oc-account-chip-item": "",
|
|
@@ -282,19 +285,19 @@ function OcAccountChip({
|
|
|
282
285
|
]
|
|
283
286
|
}
|
|
284
287
|
),
|
|
285
|
-
signOutFailed ? /* @__PURE__ */ jsx(SignOutFailed, {}) : null
|
|
288
|
+
signOutFailed ? /* @__PURE__ */ jsx(SignOutFailed, { reason: signOutFailed }) : null
|
|
286
289
|
]
|
|
287
290
|
}
|
|
288
291
|
);
|
|
289
292
|
}
|
|
290
|
-
function SignOutFailed() {
|
|
293
|
+
function SignOutFailed({ reason }) {
|
|
291
294
|
return /* @__PURE__ */ jsx(
|
|
292
295
|
"span",
|
|
293
296
|
{
|
|
294
297
|
role: "alert",
|
|
295
298
|
"data-oc-signout-failed": "",
|
|
296
299
|
style: { display: "block", marginTop: 4, fontSize: 12, color: "var(--destructive, #dc2626)" },
|
|
297
|
-
children: "Couldn\u2019t sign out. You\u2019re still signed in; try again."
|
|
300
|
+
children: reason === "several_sessions" ? SIGN_OUT_SEVERAL_SESSIONS_TEXT : "Couldn\u2019t sign out. You\u2019re still signed in; try again."
|
|
298
301
|
}
|
|
299
302
|
);
|
|
300
303
|
}
|
|
@@ -327,7 +330,7 @@ function OcAccountPill({
|
|
|
327
330
|
...rest
|
|
328
331
|
}) {
|
|
329
332
|
const { status, account, trySignOut } = useOcSession();
|
|
330
|
-
const [signOutFailed, setSignOutFailed] = React.useState(
|
|
333
|
+
const [signOutFailed, setSignOutFailed] = React.useState(null);
|
|
331
334
|
if (status !== "authenticated" || !account) return null;
|
|
332
335
|
const label = render ? render({ address: account.didOc, displayName: account.displayName }) : account.displayName ?? shortenAddress(account.didOc);
|
|
333
336
|
return /* @__PURE__ */ jsxs(
|
|
@@ -344,8 +347,8 @@ function OcAccountPill({
|
|
|
344
347
|
{
|
|
345
348
|
type: "button",
|
|
346
349
|
onClick: () => {
|
|
347
|
-
setSignOutFailed(
|
|
348
|
-
void trySignOut().then((r) => setSignOutFailed(
|
|
350
|
+
setSignOutFailed(null);
|
|
351
|
+
void trySignOut().then((r) => setSignOutFailed(r.ok ? null : r.reason));
|
|
349
352
|
},
|
|
350
353
|
"aria-label": "Sign out",
|
|
351
354
|
style: {
|
|
@@ -359,7 +362,7 @@ function OcAccountPill({
|
|
|
359
362
|
children: "sign out"
|
|
360
363
|
}
|
|
361
364
|
),
|
|
362
|
-
signOutFailed ? /* @__PURE__ */ jsx(SignOutFailed, {}) : null
|
|
365
|
+
signOutFailed ? /* @__PURE__ */ jsx(SignOutFailed, { reason: signOutFailed }) : null
|
|
363
366
|
]
|
|
364
367
|
}
|
|
365
368
|
);
|
|
@@ -666,4 +669,4 @@ export {
|
|
|
666
669
|
useOcAddressSuggestion,
|
|
667
670
|
OcAddressInput
|
|
668
671
|
};
|
|
669
|
-
//# sourceMappingURL=chunk-
|
|
672
|
+
//# sourceMappingURL=chunk-MIBVEZLP.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { useOcSession } from './provider';\nimport { SIGN_OUT_SEVERAL_SESSIONS_TEXT } from './refusal';\nimport type { OcAccount, OcSignOutResult } from './types';\n\nfunction shortenAddress(addr: string): string {\n if (addr.length <= 12) return addr;\n return `${addr.slice(0, 6)}…${addr.slice(-4)}`;\n}\n\nfunction shortenAddressMid(addr: string): string {\n if (addr.length <= 16) return addr;\n return `${addr.slice(0, 8)}…${addr.slice(-6)}`;\n}\n\nfunction isPrefixOf(value: string, target: string): boolean {\n return target.toLowerCase().startsWith(value.toLowerCase());\n}\n\nlet listboxIdCounter = 0;\nfunction useUniqueId(prefix: string): string {\n const [id] = React.useState(() => `${prefix}-${++listboxIdCounter}`);\n return id;\n}\n\nexport interface OcAccountChipProps {\n /**\n * URL to the user's account page. Defaults to `https://ochk.app/me/account`,\n * the family's account page (ochk.io/dashboard only redirects there).\n */\n dashboardUrl?: string;\n /**\n * Override the sign-in URL shown to anonymous visitors. Defaults to\n * the session's `signInUrl` (which points at the auth host's\n * /signin?return_to=… page). Set this to a local path like `'/signin'`\n * when the consumer site mounts its own in-place `<OcSignIn />` —\n * skips the redirect-bounce entirely.\n */\n signInUrl?: string;\n /**\n * Label for the sign-in link shown to anonymous visitors.\n * Defaults to `sign in`.\n */\n signInLabel?: string;\n /** className for the wrapper `<div>`. */\n className?: string;\n /** className for the trigger pill button. */\n triggerClassName?: string;\n /** className for the dropdown popover. */\n popoverClassName?: string;\n /** className for menu items (dashboard link + sign-out button). */\n menuItemClassName?: string;\n}\n\n/**\n * Single header-account affordance for every ochk.io subdomain.\n *\n * anonymous → \"sign in\" link\n * signed in → pill `bc1q…7ke3 ▾` that opens a popover with:\n * • § signed in (label)\n * • full address (monospace, break-all)\n * • → dashboard\n * • → sign out\n *\n * The popover closes on outside click or Escape. Reasonable inline styles\n * cover the dark-mode default; override per-part via the className props\n * or via the `[data-oc-account-chip-*]` data attributes.\n */\nexport function OcAccountChip({\n dashboardUrl = 'https://ochk.app/me/account',\n signInUrl: signInUrlOverride,\n signInLabel = 'sign in',\n className,\n triggerClassName,\n popoverClassName,\n menuItemClassName,\n}: OcAccountChipProps): React.ReactElement | null {\n const { status, account, signInUrl: sessionSignInUrl, trySignOut } = useOcSession();\n const signInUrl = signInUrlOverride ?? sessionSignInUrl;\n const [open, setOpen] = React.useState(false);\n // The auth host did not end the session: say so, and keep showing the account.\n const [signOutFailed, setSignOutFailed] = React.useState<SignOutRefusal | null>(null);\n const wrapRef = React.useRef<HTMLDivElement | null>(null);\n\n React.useEffect(() => {\n if (!open) return;\n function handleClickOutside(e: MouseEvent) {\n if (wrapRef.current && !wrapRef.current.contains(e.target as Node)) {\n setOpen(false);\n }\n }\n function handleEscape(e: KeyboardEvent) {\n if (e.key === 'Escape') setOpen(false);\n }\n document.addEventListener('mousedown', handleClickOutside);\n document.addEventListener('keydown', handleEscape);\n return () => {\n document.removeEventListener('mousedown', handleClickOutside);\n document.removeEventListener('keydown', handleEscape);\n };\n }, [open]);\n\n if (status === 'loading') return null;\n\n if (status !== 'authenticated' || !account) {\n return (\n <a\n href={signInUrl}\n className={triggerClassName ?? className}\n data-oc-account-chip-signin=\"\"\n >\n {signInLabel}\n </a>\n );\n }\n\n return (\n <div\n ref={wrapRef}\n className={className}\n data-oc-account-chip=\"\"\n style={{ position: 'relative', display: 'inline-block' }}\n >\n <button\n type=\"button\"\n onClick={() => setOpen((v) => !v)}\n aria-haspopup=\"menu\"\n aria-expanded={open}\n aria-label={`Signed in as ${account.didOc}. Open account menu.`}\n className={triggerClassName}\n data-oc-account-chip-trigger=\"\"\n style={\n triggerClassName\n ? undefined\n : {\n display: 'inline-flex',\n alignItems: 'center',\n gap: '0.4rem',\n padding: '0.25rem 0.625rem',\n borderRadius: '9999px',\n border: '1px solid var(--border, #27272a)',\n background:\n 'color-mix(in oklch, var(--muted, #27272a) 40%, transparent)',\n color: 'var(--foreground, #fafafa)',\n fontFamily: 'ui-monospace, SFMono-Regular, monospace',\n fontSize: 12,\n cursor: 'pointer',\n }\n }\n >\n <span aria-hidden=\"true\" style={{ color: '#22c55e', fontSize: 8 }}>\n ●\n </span>\n <span>{account.displayName ?? shortenAddress(account.didOc)}</span>\n <svg\n width=\"9\"\n height=\"9\"\n viewBox=\"0 0 10 10\"\n aria-hidden=\"true\"\n style={{\n transition: 'transform 120ms',\n transform: open ? 'rotate(180deg)' : 'rotate(0)',\n opacity: 0.6,\n }}\n >\n <path\n d=\"M2 4 L5 7 L8 4\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n fill=\"none\"\n strokeLinecap=\"round\"\n />\n </svg>\n </button>\n\n {open && (\n <div\n role=\"menu\"\n aria-label=\"Account menu\"\n className={popoverClassName}\n data-oc-account-chip-popover=\"\"\n style={\n popoverClassName\n ? { position: 'absolute', zIndex: 50, top: 'calc(100% + 6px)', right: 0 }\n : {\n position: 'absolute',\n zIndex: 50,\n top: 'calc(100% + 6px)',\n right: 0,\n minWidth: 240,\n background: 'var(--popover, #0a0a0a)',\n color: 'var(--popover-foreground, #fafafa)',\n border: '1px solid var(--border, #27272a)',\n boxShadow: '0 10px 32px -4px rgba(0,0,0,0.35)',\n fontFamily: 'ui-monospace, SFMono-Regular, monospace',\n }\n }\n >\n <div\n data-oc-account-chip-header=\"\"\n style={{\n padding: '0.75rem 0.75rem 0.625rem',\n borderBottom: '1px solid var(--border, #27272a)',\n }}\n >\n <div\n data-oc-account-chip-label=\"\"\n style={{\n color: 'var(--primary, #f97316)',\n fontSize: 10,\n letterSpacing: '0.18em',\n textTransform: 'uppercase',\n marginBottom: 4,\n }}\n >\n § signed in\n </div>\n <div\n data-oc-account-chip-address=\"\"\n style={{\n color: 'var(--popover-foreground, #fafafa)',\n fontSize: 11,\n wordBreak: 'break-all',\n lineHeight: 1.35,\n }}\n >\n {account.didOc}\n </div>\n {account.displayName ? (\n <div\n style={{\n color: 'var(--muted-foreground, #a1a1aa)',\n fontSize: 10,\n marginTop: 4,\n letterSpacing: '0.06em',\n }}\n >\n {account.displayName}\n </div>\n ) : null}\n </div>\n <div role=\"none\" style={{ padding: '0.25rem' }}>\n {dashboardUrl ? (\n <a\n role=\"menuitem\"\n href={dashboardUrl}\n onClick={() => setOpen(false)}\n className={menuItemClassName}\n data-oc-account-chip-item=\"\"\n style={\n menuItemClassName\n ? undefined\n : {\n display: 'flex',\n alignItems: 'center',\n gap: '0.5rem',\n padding: '0.5rem 0.625rem',\n fontSize: 12,\n color: 'var(--popover-foreground, #fafafa)',\n textDecoration: 'none',\n cursor: 'pointer',\n }\n }\n >\n <span\n aria-hidden=\"true\"\n style={{ color: 'var(--muted-foreground, #a1a1aa)' }}\n >\n →\n </span>\n <span style={{ flex: 1 }}>dashboard</span>\n <span\n style={{\n color: 'var(--muted-foreground, #a1a1aa)',\n fontSize: 10,\n }}\n >\n ↗\n </span>\n </a>\n ) : null}\n <button\n type=\"button\"\n role=\"menuitem\"\n onClick={() => {\n setOpen(false);\n setSignOutFailed(null);\n void trySignOut().then((r) => setSignOutFailed(r.ok ? null : r.reason));\n }}\n className={menuItemClassName}\n data-oc-account-chip-item=\"\"\n data-oc-account-chip-signout=\"\"\n style={\n menuItemClassName\n ? undefined\n : {\n display: 'flex',\n alignItems: 'center',\n gap: '0.5rem',\n width: '100%',\n padding: '0.5rem 0.625rem',\n fontSize: 12,\n color: 'var(--popover-foreground, #fafafa)',\n background: 'transparent',\n border: 0,\n fontFamily: 'inherit',\n textAlign: 'left',\n cursor: 'pointer',\n }\n }\n >\n <span\n aria-hidden=\"true\"\n style={{ color: 'var(--muted-foreground, #a1a1aa)' }}\n >\n →\n </span>\n <span style={{ flex: 1 }}>sign out</span>\n </button>\n </div>\n </div>\n )}\n {signOutFailed ? <SignOutFailed reason={signOutFailed} /> : null}\n </div>\n );\n}\n\ntype SignOutRefusal = Extract<OcSignOutResult, { ok: false }>['reason'];\n\n/** Said when the auth host did not end the session, so the person is still signed in. */\nfunction SignOutFailed({ reason }: { reason: SignOutRefusal }): React.ReactElement {\n return (\n <span\n role=\"alert\"\n data-oc-signout-failed=\"\"\n style={{ display: 'block', marginTop: 4, fontSize: 12, color: 'var(--destructive, #dc2626)' }}\n >\n {reason === 'several_sessions'\n ? SIGN_OUT_SEVERAL_SESSIONS_TEXT\n : 'Couldn’t sign out. You’re still signed in; try again.'}\n </span>\n );\n}\n\nexport interface OcSignInButtonProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {\n /** Label shown when no user is signed in. Defaults to `sign in`. */\n label?: string;\n /**\n * When `true`, render an `<a>` even while the session is loading, to\n * avoid layout shift. Defaults to `false` (renders nothing while loading).\n */\n eager?: boolean;\n /**\n * Override the destination URL. Defaults to the session's `signInUrl`\n * (the auth host's redirect-style /signin). Set this to a local path\n * like `'/signin'` when the consumer site has its own in-place\n * `<OcSignIn />` page — keeps the user in-tab.\n */\n signInUrl?: string;\n}\n\n/**\n * Drop-in sign-in button. Renders an anchor that points at either:\n *\n * - the consumer's local `/signin` page (when `signInUrl` prop is set\n * — recommended; works with `<OcSignIn />`), or\n * - the auth host's `/signin?return_to=…` (default fallback)\n *\n * When the user is already authenticated it renders nothing.\n */\nexport function OcSignInButton({\n label = 'sign in',\n eager = false,\n className,\n signInUrl: signInUrlOverride,\n ...rest\n}: OcSignInButtonProps): React.ReactElement | null {\n const { status, signInUrl: sessionSignInUrl } = useOcSession();\n const href = signInUrlOverride ?? sessionSignInUrl;\n if (status === 'authenticated') return null;\n if (!eager && status === 'loading') return null;\n\n return (\n <a\n {...rest}\n href={href}\n className={className}\n data-oc-sign-in-button=\"\"\n >\n {label}\n </a>\n );\n}\n\nexport interface OcAccountPillProps extends React.HTMLAttributes<HTMLDivElement> {\n /** URL to link the address to. With none, the label is plain text. */\n dashboardUrl?: string;\n /** Override the display text. Defaults to the shortened address. */\n render?: (account: { address: string; displayName?: string | null }) => React.ReactNode;\n}\n\n/**\n * Shows the signed-in user as a short pill: `bc1q…abcd sign out`.\n *\n * Renders nothing while loading or when no user is signed in — pair with\n * `<OcSignInButton>` for the anonymous case.\n */\nexport function OcAccountPill({\n dashboardUrl,\n render,\n className,\n ...rest\n}: OcAccountPillProps): React.ReactElement | null {\n const { status, account, trySignOut } = useOcSession();\n // The auth host did not end the session: say so, and keep showing the account.\n const [signOutFailed, setSignOutFailed] = React.useState<SignOutRefusal | null>(null);\n\n if (status !== 'authenticated' || !account) return null;\n\n const label = render\n ? render({ address: account.didOc, displayName: account.displayName })\n : (account.displayName ?? shortenAddress(account.didOc));\n\n return (\n <div\n {...rest}\n className={className}\n data-oc-account-pill=\"\"\n style={{ display: 'inline-flex', alignItems: 'center', gap: '0.5rem', ...(rest.style ?? {}) }}\n >\n {dashboardUrl ? (\n <a href={dashboardUrl}>{label}</a>\n ) : (\n <span>{label}</span>\n )}\n <button\n type=\"button\"\n onClick={() => {\n setSignOutFailed(null);\n void trySignOut().then((r) => setSignOutFailed(r.ok ? null : r.reason));\n }}\n aria-label=\"Sign out\"\n style={{\n background: 'none',\n border: 'none',\n cursor: 'pointer',\n color: 'inherit',\n font: 'inherit',\n padding: 0,\n }}\n >\n sign out\n </button>\n {signOutFailed ? <SignOutFailed reason={signOutFailed} /> : null}\n </div>\n );\n}\n\nexport interface OcAddressInputProps\n extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange'> {\n /** Controlled value. */\n value: string;\n /** Called when value changes — typed by the user OR selected from the popover. */\n onValueChange: (value: string) => void;\n /** Label shown above the suggested address in the popover. Defaults to `use your address`. */\n suggestionLabel?: string;\n /** className applied to the wrapper `<div>`. */\n wrapperClassName?: string;\n /** className applied to the suggestion popover. Style with `[data-oc-address-popover]` otherwise. */\n popoverClassName?: string;\n /** className applied to the suggestion button. Style with `[data-oc-address-suggestion]` otherwise. */\n suggestionClassName?: string;\n}\n\n/**\n * Bitcoin-address `<input>` that, when the user is signed in via `oc_session`,\n * surfaces their address as a one-click suggestion on focus.\n *\n * Behaviour:\n * - On focus, if logged-in AND the typed value is a prefix of the session\n * address (or empty), show a small popover with `bc1q…7ke3` as a clickable\n * suggestion.\n * - Click / Enter on the suggestion fills the field with the full address.\n * - Down-arrow from the input highlights the suggestion; Up-arrow clears the\n * highlight; Escape closes the popover; clicking outside closes the popover.\n * - When the user types something that's no longer a prefix of the session\n * address, the popover hides itself out of the way.\n * - When the field already contains the session address exactly, no popover.\n *\n * Style-agnostic: minimal inline styles for positioning only. Style the parts\n * via `wrapperClassName` / `popoverClassName` / `suggestionClassName`, or via\n * the `[data-oc-address-input]`, `[data-oc-address-popover]`, and\n * `[data-oc-address-suggestion]` data attributes.\n */\nexport interface UseOcAddressSuggestionOptions {\n /** Current value of the input. */\n value: string;\n /** Called when the user selects the suggestion (or you may also call it from the input's onChange). */\n onValueChange: (value: string) => void;\n /** Label shown above the suggested address in the popover. Defaults to `use your address`. */\n suggestionLabel?: string;\n /** className applied to the suggestion popover. Style with `[data-oc-address-popover]` otherwise. */\n popoverClassName?: string;\n /** className applied to the suggestion button. Style with `[data-oc-address-suggestion]` otherwise. */\n suggestionClassName?: string;\n}\n\nexport interface UseOcAddressSuggestionReturn {\n /**\n * Props to spread onto your `<input>` element. Adds focus/blur/keydown\n * handlers and the combobox ARIA attributes. Combine with your existing\n * `value`/`onChange` props — this hook does NOT control them.\n */\n inputProps: {\n onFocus: (e: React.FocusEvent<HTMLInputElement>) => void;\n onBlur: (e: React.FocusEvent<HTMLInputElement>) => void;\n onKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void;\n role: 'combobox';\n 'aria-haspopup': 'listbox';\n 'aria-expanded': boolean;\n 'aria-controls': string | undefined;\n 'aria-activedescendant': string | undefined;\n autoComplete: 'off';\n spellCheck: false;\n };\n /**\n * The suggestion popover. Render directly after your `<input>`, inside a\n * `position: relative` container so the popover anchors below the input.\n * Returns `null` when there's no suggestion to show.\n */\n popover: React.ReactNode;\n}\n\n/**\n * Hook variant of `OcAddressInput`. Use when you want to keep your existing\n * styled `<input>` (e.g. shadcn `<Input>`) and just bolt on the\n * session-address suggestion behaviour.\n *\n * Wrap your input in a `position: relative` container, spread `inputProps`\n * onto the input, and render `{popover}` immediately after. The hook's\n * focus / blur / keydown handlers are composed via `inputProps` — they call\n * any handlers you've already passed to your input only when you wire them\n * yourself in addition to spreading `inputProps`.\n *\n * Example:\n * ```tsx\n * const { inputProps, popover } = useOcAddressSuggestion({\n * value: addr,\n * onValueChange: setAddr,\n * });\n * return (\n * <div className=\"relative\">\n * <Input\n * value={addr}\n * onChange={(e) => setAddr(e.target.value)}\n * {...inputProps}\n * placeholder=\"bc1q…\"\n * />\n * {popover}\n * </div>\n * );\n * ```\n */\n/**\n * The address to offer: the account's primary one, else the Bitcoin address it\n * shows. Consumer sites verify the session locally and have no primary address\n * (`primary_btc` is null), but a wallet sign-in shows its address.\n */\nfunction accountAddress(account: OcAccount | null | undefined): string | null {\n if (account?.primaryBtc) return account.primaryBtc;\n return account?.displayIdentity?.kind === 'btc' ? account.displayIdentity.value : null;\n}\n\nexport function useOcAddressSuggestion(\n options: UseOcAddressSuggestionOptions\n): UseOcAddressSuggestionReturn {\n const {\n value,\n onValueChange,\n suggestionLabel = 'use your address',\n popoverClassName,\n suggestionClassName,\n } = options;\n\n const { status, account } = useOcSession();\n const sessionAddress = status === 'authenticated' ? accountAddress(account) : null;\n\n const [open, setOpen] = React.useState(false);\n const [highlighted, setHighlighted] = React.useState(false);\n const blurTimer = React.useRef<number | null>(null);\n\n const listboxId = useUniqueId('oc-addr-listbox');\n const optionId = `${listboxId}-opt`;\n\n const valueMatchesSession =\n sessionAddress != null && value.toLowerCase() === sessionAddress.toLowerCase();\n const canSuggest =\n sessionAddress != null &&\n sessionAddress.length > 0 &&\n !valueMatchesSession &&\n isPrefixOf(value, sessionAddress);\n const showPopover = open && canSuggest;\n\n function selectSuggestion() {\n if (!sessionAddress) return;\n onValueChange(sessionAddress);\n setOpen(false);\n setHighlighted(false);\n }\n\n React.useEffect(() => {\n return () => {\n if (blurTimer.current != null) window.clearTimeout(blurTimer.current);\n };\n }, []);\n\n const inputProps: UseOcAddressSuggestionReturn['inputProps'] = {\n onFocus: () => {\n if (blurTimer.current != null) {\n window.clearTimeout(blurTimer.current);\n blurTimer.current = null;\n }\n setOpen(true);\n },\n onBlur: () => {\n blurTimer.current = window.setTimeout(() => {\n setOpen(false);\n setHighlighted(false);\n }, 120);\n },\n onKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (!showPopover) return;\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setHighlighted(true);\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setHighlighted(false);\n } else if (e.key === 'Escape') {\n e.preventDefault();\n setOpen(false);\n setHighlighted(false);\n } else if (e.key === 'Enter' && highlighted) {\n e.preventDefault();\n selectSuggestion();\n }\n },\n role: 'combobox',\n 'aria-haspopup': 'listbox',\n 'aria-expanded': showPopover,\n 'aria-controls': showPopover ? listboxId : undefined,\n 'aria-activedescendant': highlighted ? optionId : undefined,\n autoComplete: 'off',\n spellCheck: false,\n };\n\n const popover = showPopover && sessionAddress ? (\n <div\n id={listboxId}\n role=\"listbox\"\n data-oc-address-popover=\"\"\n className={popoverClassName}\n style={{\n position: 'absolute',\n zIndex: 50,\n top: 'calc(100% + 4px)',\n left: 0,\n right: 0,\n }}\n onMouseDown={(e) => e.preventDefault()}\n >\n <button\n type=\"button\"\n id={optionId}\n role=\"option\"\n aria-selected={highlighted}\n data-oc-address-suggestion=\"\"\n data-highlighted={highlighted ? '' : undefined}\n className={suggestionClassName}\n onClick={selectSuggestion}\n onMouseEnter={() => setHighlighted(true)}\n onMouseLeave={() => setHighlighted(false)}\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: '0.75rem',\n width: '100%',\n textAlign: 'left',\n cursor: 'pointer',\n font: 'inherit',\n background: 'inherit',\n color: 'inherit',\n border: 0,\n padding: 'inherit',\n }}\n >\n <span data-oc-address-suggestion-label=\"\">{suggestionLabel}</span>\n <span\n data-oc-address-suggestion-value=\"\"\n style={{ fontFamily: 'ui-monospace, monospace' }}\n >\n {shortenAddressMid(sessionAddress)}\n </span>\n </button>\n </div>\n ) : null;\n\n return { inputProps, popover };\n}\n\nexport const OcAddressInput = React.forwardRef<HTMLInputElement, OcAddressInputProps>(\n function OcAddressInput(\n {\n value,\n onValueChange,\n suggestionLabel = 'use your address',\n wrapperClassName,\n popoverClassName,\n suggestionClassName,\n onFocus,\n onBlur,\n onKeyDown,\n ...rest\n },\n forwardedRef\n ): React.ReactElement {\n const { status, account } = useOcSession();\n const sessionAddress = status === 'authenticated' ? accountAddress(account) : null;\n\n const [open, setOpen] = React.useState(false);\n const [highlighted, setHighlighted] = React.useState(false);\n\n const innerRef = React.useRef<HTMLInputElement | null>(null);\n const setRef = (node: HTMLInputElement | null) => {\n innerRef.current = node;\n if (typeof forwardedRef === 'function') forwardedRef(node);\n else if (forwardedRef) forwardedRef.current = node;\n };\n const blurTimer = React.useRef<number | null>(null);\n\n const listboxId = useUniqueId('oc-addr-listbox');\n const optionId = `${listboxId}-opt`;\n\n const valueMatchesSession =\n sessionAddress != null && value.toLowerCase() === sessionAddress.toLowerCase();\n const canSuggest =\n sessionAddress != null &&\n sessionAddress.length > 0 &&\n !valueMatchesSession &&\n isPrefixOf(value, sessionAddress);\n const showPopover = open && canSuggest;\n\n function selectSuggestion() {\n if (!sessionAddress) return;\n onValueChange(sessionAddress);\n setOpen(false);\n setHighlighted(false);\n // Re-focus so the next Tab moves on naturally.\n innerRef.current?.focus();\n }\n\n function handleFocus(e: React.FocusEvent<HTMLInputElement>) {\n if (blurTimer.current != null) {\n window.clearTimeout(blurTimer.current);\n blurTimer.current = null;\n }\n setOpen(true);\n onFocus?.(e);\n }\n\n function handleBlur(e: React.FocusEvent<HTMLInputElement>) {\n // Defer close so a click on the suggestion can register first.\n blurTimer.current = window.setTimeout(() => {\n setOpen(false);\n setHighlighted(false);\n }, 120);\n onBlur?.(e);\n }\n\n function handleKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {\n if (showPopover) {\n if (e.key === 'ArrowDown') {\n e.preventDefault();\n setHighlighted(true);\n } else if (e.key === 'ArrowUp') {\n e.preventDefault();\n setHighlighted(false);\n } else if (e.key === 'Escape') {\n e.preventDefault();\n setOpen(false);\n setHighlighted(false);\n } else if (e.key === 'Enter' && highlighted) {\n e.preventDefault();\n selectSuggestion();\n }\n }\n onKeyDown?.(e);\n }\n\n React.useEffect(() => {\n return () => {\n if (blurTimer.current != null) window.clearTimeout(blurTimer.current);\n };\n }, []);\n\n return (\n <div\n data-oc-address-input=\"\"\n className={wrapperClassName}\n style={{ position: 'relative' }}\n >\n <input\n {...rest}\n ref={setRef}\n value={value}\n onChange={(e) => onValueChange(e.target.value)}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onKeyDown={handleKeyDown}\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n aria-expanded={showPopover}\n aria-controls={showPopover ? listboxId : undefined}\n aria-activedescendant={highlighted ? optionId : undefined}\n autoComplete=\"off\"\n spellCheck={false}\n />\n {showPopover && sessionAddress && (\n <div\n id={listboxId}\n role=\"listbox\"\n data-oc-address-popover=\"\"\n className={popoverClassName}\n style={{\n position: 'absolute',\n zIndex: 50,\n top: 'calc(100% + 4px)',\n left: 0,\n right: 0,\n }}\n // Prevent the input from blurring before the click on the suggestion lands.\n onMouseDown={(e) => e.preventDefault()}\n >\n <button\n type=\"button\"\n id={optionId}\n role=\"option\"\n aria-selected={highlighted}\n data-oc-address-suggestion=\"\"\n data-highlighted={highlighted ? '' : undefined}\n className={suggestionClassName}\n onClick={selectSuggestion}\n onMouseEnter={() => setHighlighted(true)}\n onMouseLeave={() => setHighlighted(false)}\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: '0.75rem',\n width: '100%',\n textAlign: 'left',\n cursor: 'pointer',\n font: 'inherit',\n background: 'inherit',\n color: 'inherit',\n border: 'inherit',\n padding: 'inherit',\n }}\n >\n <span data-oc-address-suggestion-label=\"\">{suggestionLabel}</span>\n <span\n data-oc-address-suggestion-value=\"\"\n style={{ fontFamily: 'ui-monospace, monospace' }}\n >\n {shortenAddressMid(sessionAddress)}\n </span>\n </button>\n </div>\n )}\n </div>\n );\n }\n);\n"],"mappings":";;;;;;;;AAAA,YAAY,WAAW;AA2GX,cAiBA,YAjBA;AArGZ,SAAS,eAAe,MAAsB;AAC1C,MAAI,KAAK,UAAU,GAAI,QAAO;AAC9B,SAAO,GAAG,KAAK,MAAM,GAAG,CAAC,CAAC,SAAI,KAAK,MAAM,EAAE,CAAC;AAChD;AAEA,SAAS,kBAAkB,MAAsB;AAC7C,MAAI,KAAK,UAAU,GAAI,QAAO;AAC9B,SAAO,GAAG,KAAK,MAAM,GAAG,CAAC,CAAC,SAAI,KAAK,MAAM,EAAE,CAAC;AAChD;AAEA,SAAS,WAAW,OAAe,QAAyB;AACxD,SAAO,OAAO,YAAY,EAAE,WAAW,MAAM,YAAY,CAAC;AAC9D;AAEA,IAAI,mBAAmB;AACvB,SAAS,YAAY,QAAwB;AACzC,QAAM,CAAC,EAAE,IAAU,eAAS,MAAM,GAAG,MAAM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AA,kBACT,cAAc,MAAM,eAAe,IAAI;AAAA,kBACvC,cAAc,MAAM,eAAe,KAAK;AAAA,kBACxC,OAAO;AAAA,oBACH,SAAS;AAAA,oBACT,YAAY;AAAA,oBACZ,gBAAgB;AAAA,oBAChB,KAAK;AAAA,oBACL,OAAO;AAAA,oBACP,WAAW;AAAA,oBACX,QAAQ;AAAA,oBACR,MAAM;AAAA,oBACN,YAAY;AAAA,oBACZ,OAAO;AAAA,oBACP,QAAQ;AAAA,oBACR,SAAS;AAAA,kBACb;AAAA,kBAEA;AAAA,wCAAC,UAAK,oCAAiC,IAAI,2BAAgB;AAAA,oBAC3D;AAAA,sBAAC;AAAA;AAAA,wBACG,oCAAiC;AAAA,wBACjC,OAAO,EAAE,YAAY,0BAA0B;AAAA,wBAE9C,4BAAkB,cAAc;AAAA;AAAA,oBACrC;AAAA;AAAA;AAAA,cACJ;AAAA;AAAA,UACJ;AAAA;AAAA;AAAA,IAER;AAAA,EAER;AACJ;","names":["OcAddressInput"]}
|
|
@@ -5,11 +5,27 @@ import {
|
|
|
5
5
|
// src/refusal.ts
|
|
6
6
|
var ENDED_ERRORS = {
|
|
7
7
|
signed_out: "You were signed out while signing in. Sign in again.",
|
|
8
|
-
account_deleted: "This account is being deleted, so you can't sign in to it."
|
|
8
|
+
account_deleted: "This account is being deleted, so you can't sign in to it.",
|
|
9
|
+
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."
|
|
9
10
|
};
|
|
10
11
|
function endedSigninText(reason) {
|
|
11
12
|
return ownWord(ENDED_ERRORS, reason);
|
|
12
13
|
}
|
|
14
|
+
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.";
|
|
15
|
+
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.";
|
|
16
|
+
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.";
|
|
17
|
+
async function isSeveralSessionsAnswer(res) {
|
|
18
|
+
if (res.status !== 409) return false;
|
|
19
|
+
try {
|
|
20
|
+
const body = await res.clone().json();
|
|
21
|
+
return body?.reason === "several_sessions";
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function isSeveralSessions(err) {
|
|
27
|
+
return err instanceof Error && err.message === "several_sessions";
|
|
28
|
+
}
|
|
13
29
|
var SIGNIN_ERRORS = {
|
|
14
30
|
bad_request: "That doesn't look like a Bitcoin address.",
|
|
15
31
|
invalid_challenge: "That signature doesn't match this address. Sign with the wallet that holds it.",
|
|
@@ -32,11 +48,13 @@ var SIGNIN_ERRORS = {
|
|
|
32
48
|
replay: "That code was already used. Send a new one.",
|
|
33
49
|
invalid_token: "That code is no longer valid. Send a new one.",
|
|
34
50
|
email_mismatch: "That code was sent to a different address. Send a new one.",
|
|
51
|
+
several_sessions: SEVERAL_SESSIONS_TEXT,
|
|
35
52
|
...ENDED_ERRORS
|
|
36
53
|
};
|
|
37
54
|
var EMAIL_ERRORS = {
|
|
38
55
|
expired: "That code expired. Send a new one.",
|
|
39
|
-
signed_out: "You were signed out while signing in. Send a new code to sign in again."
|
|
56
|
+
signed_out: "You were signed out while signing in. Send a new code to sign in again.",
|
|
57
|
+
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."
|
|
40
58
|
};
|
|
41
59
|
var SUBMIT_ERRORS = {
|
|
42
60
|
bad_request: "That signature couldn't be read. Copy it again, whole."
|
|
@@ -62,8 +80,13 @@ function failureMessage(err, path, step, authOrigin) {
|
|
|
62
80
|
|
|
63
81
|
export {
|
|
64
82
|
endedSigninText,
|
|
83
|
+
SEVERAL_SESSIONS_TEXT,
|
|
84
|
+
SIGN_OUT_SEVERAL_SESSIONS_TEXT,
|
|
85
|
+
SWITCH_SEVERAL_SESSIONS_TEXT,
|
|
86
|
+
isSeveralSessionsAnswer,
|
|
87
|
+
isSeveralSessions,
|
|
65
88
|
networkError,
|
|
66
89
|
humanSigninError,
|
|
67
90
|
failureMessage
|
|
68
91
|
};
|
|
69
|
-
//# sourceMappingURL=chunk-
|
|
92
|
+
//# sourceMappingURL=chunk-OKIFTNEO.mjs.map
|
|
@@ -0,0 +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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AS,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,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
failureMessage
|
|
3
|
-
} from "./chunk-KD4XTVFV.mjs";
|
|
4
1
|
import {
|
|
5
2
|
SUDO_ACCOUNT_MISMATCH_MESSAGE,
|
|
6
3
|
handleSudoRequired,
|
|
7
4
|
isSudoAccountMismatch
|
|
8
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-FNGBJD4S.mjs";
|
|
9
6
|
import {
|
|
10
7
|
addressInputValue
|
|
11
8
|
} from "./chunk-U7IUGDLW.mjs";
|
|
@@ -20,6 +17,9 @@ import {
|
|
|
20
17
|
import {
|
|
21
18
|
capText
|
|
22
19
|
} from "./chunk-5KQ36QNH.mjs";
|
|
20
|
+
import {
|
|
21
|
+
failureMessage
|
|
22
|
+
} from "./chunk-OKIFTNEO.mjs";
|
|
23
23
|
import {
|
|
24
24
|
tabSessionHeader
|
|
25
25
|
} from "./chunk-4BOO7EQR.mjs";
|
|
@@ -954,4 +954,4 @@ export {
|
|
|
954
954
|
ghostBtnStyle,
|
|
955
955
|
dangerBtnStyle
|
|
956
956
|
};
|
|
957
|
-
//# sourceMappingURL=chunk-
|
|
957
|
+
//# sourceMappingURL=chunk-UTR42EZW.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import { stripFragment } from './return-to';\n\n/**\n * The kinds of identity a user can surface as their account-badge\n * label. `did` is the canonical `did:oc` identifier — always available\n * and the ultimate fallback; the other three are linked identities a\n * user may or may not have.\n */\nexport const DISPLAY_IDENTITY_KINDS = ['did', 'btc', 'email', 'nostr'] as const;\nexport type DisplayIdentityKind = (typeof DISPLAY_IDENTITY_KINDS)[number];\n\n/**\n * The identity a user has chosen to show in their account badge — the\n * collapsed label every family site renders instead of the raw\n * `did:oc`. Carried as a JWT claim by the auth host, so the choice is\n * consistent across every `.ochk.io` subdomain with no round-trip.\n *\n * `kind` is which identity; `value` is the full, renderable value (the\n * `did:oc`, the Bitcoin address, the email, or the npub). Integrators\n * rendering their own chip read `useOcSession().account.displayIdentity`\n * — it is always populated (it defaults to the `did`).\n */\nexport interface DisplayIdentity {\n kind: DisplayIdentityKind;\n value: string;\n}\n\nexport interface OcAccount {\n accountId: string;\n /**\n * Opaque public-facing identifier · `did:oc:<32-hex>`. The sole\n * user identifier post auth-refactor. Stable across linking\n * events. Per AUTH-REFACTOR-PLAN.md §2.1.\n */\n didOc: string;\n /**\n * Primary linked Bitcoin address, plaintext, when the user has\n * one — null for email-OTP users until they link a btc address.\n * Surfaced inline by the auth host's /api/auth/me so consumer\n * dashboards can render the user's own footprint without a\n * second round-trip through /api/auth/identities.\n */\n primaryBtc?: string | null;\n /**\n * True when the user has a primary email linked. Plaintext is\n * fetchable on demand via /api/auth/identities; not surfaced\n * here.\n */\n hasEmail?: boolean;\n displayName?: string | null;\n nostrNpub?: string | null;\n /**\n * @deprecated Always null: the auth host no longer sets it. Where a\n * person's sats sit is me.ochk.io's to say (`/api/me/balance`).\n */\n homeFederation?: string | null;\n /**\n * Whether the account signs with its own Bitcoin key, derived by the\n * auth host from its verified linked identities; no one can set it.\n * 'bip322' when a BIP-322-verified address is linked, otherwise\n * 'fedimint_threshold'. 'fedimint_client' is reserved and never set.\n * It says who holds the signing key, never who holds the sats.\n */\n signingMethod?: 'fedimint_threshold' | 'fedimint_client' | 'bip322' | null;\n /**\n * Best-effort owner-flag · true when the user's `did_oc` was on\n * the auth host's `OWNER_OC_ADDRESSES` env at the time the JWT\n * was minted. Surfaced so the family-switcher and other low-\n * stakes UX can render owner-only affordances (e.g. an\n * analytics.ochk.io entry visible only to owners).\n *\n * **NOT A SECURITY BOUNDARY.** Sensitive surfaces — including\n * analytics.ochk.io itself — re-check the live env against\n * `session.did_oc` server-side on every request. If an owner is\n * removed from the env, their JWT may keep `isOwner: true` for\n * up to the JWT lifetime (~30d) but every gated action they\n * attempt re-fails. The flag exists purely so we can show or\n * hide UX hints without an extra round-trip on every page load.\n *\n * Treat absence as `false`.\n */\n isOwner?: boolean;\n /**\n * The identity the user has chosen to show as their account-badge\n * label — `{ kind, value }`. **Always populated**: when the user\n * has never promoted an identity (and on sessions minted before\n * the feature shipped) this is `{ kind:'did', value:didOc }`.\n *\n * `<OcAccountMenu>` renders `value` (shortened) as the collapsed\n * badge label. Integrators rendering their own chip read this\n * directly; change it with `useOcSession().setDisplayIdentity()`.\n */\n displayIdentity: DisplayIdentity;\n}\n\nexport type OcSessionStatus = 'loading' | 'authenticated' | 'anonymous' | 'error';\n\n/**\n * Multi-account roster · summary of another account this browser has\n * signed into and can switch to without re-authenticating. Surfaced by\n * `<OcAccountMenu>` in the `§ accounts` section. Returned by the auth\n * host's `/api/auth/me` as `roster: [...]` (an empty array on single-\n * account or pre-multi-account sessions).\n *\n * Sessions for peer accounts stay alive in the auth host's DB for the\n * normal 30-day window; once expired, the peer falls out of the roster\n * and the user must re-authenticate to bring it back in.\n */\nexport interface OcAccountSummary {\n didOc: string;\n displayName: string | null;\n primaryBtc: string | null;\n displayIdentity: DisplayIdentity;\n /** ISO timestamp of the last verified request on this account's\n * session row, or null if never touched. */\n lastSeenAt: string | null;\n}\n\n/**\n * Scope hint for `signOut()` in a multi-account browser.\n *\n * - 'all' · sign out of every account in this browser's roster\n * (the default; matches the historical single-account\n * behavior of \"clear the cookie\").\n * - 'current' · sign out of just the active account; if the roster\n * has other accounts, the auth host hands you off to\n * the next-most-recent one without a re-auth.\n */\nexport type OcSignOutScope = 'all' | 'current';\n\n/**\n * What `signOut()` did. `ok: false` means the session may still be live: the\n * auth host did not answer (`'unreachable'`) or refused (`'refused'`, with its\n * HTTP status). The provider then changes nothing, so the page still shows the\n * signed-in account; tell the person it did not work and let them try again.\n * `'several_sessions'` (409): the browser sent more than one ochk.io sign-in.\n * ochk.io cleared the extra cookies and ended nothing, and the provider has\n * read the session again, so the page shows the account left signed in.\n */\nexport type OcSignOutResult =\n | { ok: true }\n | { ok: false; reason: 'unreachable' | 'refused' | 'several_sessions'; status?: number };\n\nexport interface OcSessionState {\n status: OcSessionStatus;\n account: OcAccount | null;\n /**\n * Multi-account · other accounts the user has signed into in this\n * browser. `[]` for single-account sessions and for tokens minted\n * before multi-account shipped. The active account (`account`\n * above) is NOT included — these are the *switch targets*.\n */\n roster: OcAccountSummary[];\n /**\n * Per-tab pinning · `true` when this tab holds its own session\n * token (sessionStorage) and operates as `account` independently of\n * the shared `.ochk.io` cookie — i.e. switching accounts in another\n * tab will NOT change this tab's identity. `false` on hosts that\n * predate `/api/auth/tab`, in privacy modes without sessionStorage,\n * and while anonymous.\n */\n tabPinned: boolean;\n /** `null` while loading; an `Error` instance when `status === 'error'`. */\n error: Error | null;\n /** Re-fetch the session. Useful after sign-in/sign-out happens elsewhere. */\n refresh: () => Promise<void>;\n /**\n * Trigger a sign-out. By default signs out of EVERY account in the\n * roster (back-compat); pass `{ scope: 'current' }` to sign out of\n * just the active account and stay logged into the next peer. When the\n * auth host does not end the session (no answer, or an error status),\n * nothing changes locally and the account stays shown; it never rejects.\n * Use {@link trySignOut} to learn which, and tell the person.\n */\n signOut: (opts?: { scope?: OcSignOutScope }) => Promise<void>;\n /**\n * `signOut`, resolving to what the auth host did: `{ ok: true }` once the\n * session has ended, else `{ ok: false, reason }` with the session still live.\n */\n trySignOut: (opts?: { scope?: OcSignOutScope }) => Promise<OcSignOutResult>;\n /**\n * Multi-account · flip the active session to a different account\n * in the roster. Resolves once the new cookie has been set and\n * the session has been re-fetched. Throws if the target `did_oc`\n * isn't in the current roster (the user must add it via\n * {@link addAccount} first) or if the auth host is unreachable.\n * When ochk.io refused because the browser sent more than one ochk.io\n * sign-in, it reads the session again first and throws an Error whose\n * message is a sentence to show the person.\n */\n switchAccount: (didOc: string) => Promise<void>;\n /**\n * Multi-account · open the sign-in flow in \"add\" mode — the new\n * account joins the current browser's roster instead of replacing\n * it. Returns the URL to navigate to (so callers can mount it in\n * a popup or hard-navigate as they prefer); pass `returnTo` to\n * route back to a specific page after the add completes.\n */\n addAccountUrl: (returnTo?: string) => string;\n /**\n * Promote a linked identity to be the account-badge label across\n * every `.ochk.io` site. PATCHes the auth host, which re-mints the\n * session cookie with the new `display_identity` claim, then\n * `refresh()`es this session. Rejects if the chosen kind is not a\n * verified identity on the account (`btc` / `email` / `nostr` must\n * actually be linked; `did` is always valid).\n */\n setDisplayIdentity: (kind: DisplayIdentityKind) => Promise<void>;\n /** URL to navigate to for sign-in on the auth host. */\n signInUrl: string;\n}\n\nexport interface OcAuthConfig {\n /**\n * Origin of the auth host — the subdomain that runs the sign-in UI,\n * issues session cookies, and exposes `/api/auth/me` + `/api/auth/logout`.\n *\n * Defaults to `https://ochk.io`. Override in preview/dev.\n */\n authOrigin?: string;\n /**\n * Path on the auth host that accepts `?return_to=<url>` and drives the\n * sign-in flow. The page offers two paths in-place:\n *\n * - email + OTP (default — no wallet and no key of the user's own;\n * identity is `did:email:<sha256(email)>`)\n * - BIP-322 wallet sign (paste address → in-page wallet sign;\n * identity is the Bitcoin address itself)\n *\n * Defaults to `/signin`.\n */\n signInPath?: string;\n /**\n * Local path (same origin as the current app) that exposes the\n * crypto-verified session. If your app ships one at `/api/auth/me`,\n * leave as default. Returns 200 `{ account }` or 401.\n */\n mePath?: string;\n /**\n * Path on the auth host to hit to clear the session cookie.\n * Defaults to `/api/auth/logout`. Called with `credentials: 'include'`\n * so the `.ochk.io` cookie is sent along.\n */\n logoutPath?: string;\n /**\n * Multi-account and per-tab pinning against the auth host. Defaults to\n * `true`. A site that holds its own single session cookie (ochk.app)\n * sets `false`: no tab pins, no account hints or link stamping, and no\n * roster fetched from the host.\n */\n multiAccount?: boolean;\n}\n\nexport const DEFAULT_CONFIG: Required<OcAuthConfig> = {\n authOrigin: 'https://ochk.io',\n signInPath: '/signin',\n mePath: '/api/auth/me',\n logoutPath: '/api/auth/logout',\n multiAccount: true,\n};\n\nexport function resolveConfig(cfg: OcAuthConfig | undefined): Required<OcAuthConfig> {\n return { ...DEFAULT_CONFIG, ...(cfg ?? {}) };\n}\n\n/**\n * The sign-in URL on the auth host. `returnTo` goes without its fragment;\n * OcSessionProvider keeps the fragment when the link is followed.\n */\nexport function buildSignInUrl(cfg: Required<OcAuthConfig>, returnTo?: string): string {\n const base = `${cfg.authOrigin}${cfg.signInPath}`;\n if (!returnTo) return base;\n const u = new URL(base);\n u.searchParams.set('return_to', stripFragment(returnTo));\n return u.toString();\n}\n\n/**\n * Multi-account · build the URL for the \"add another account\" entry\n * point. Same as {@link buildSignInUrl} but appends `?add=1` so the\n * sign-in page knows to preserve the current roster (the new account\n * is appended; the previously-active account stays signed in too and\n * remains switch-target reachable).\n */\nexport function buildAddAccountUrl(cfg: Required<OcAuthConfig>, returnTo?: string): string {\n const u = new URL(buildSignInUrl(cfg, returnTo));\n u.searchParams.set('add', '1');\n return u.toString();\n}\n"],"mappings":";;;;;AAQO,IAAM,yBAAyB,CAAC,OAAO,OAAO,SAAS,OAAO;AAqP9D,IAAM,iBAAyC;AAAA,EAClD,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,cAAc;AAClB;AAEO,SAAS,cAAc,KAAuD;AACjF,SAAO,EAAE,GAAG,gBAAgB,GAAI,OAAO,CAAC,EAAG;AAC/C;AAMO,SAAS,eAAe,KAA6B,UAA2B;AACnF,QAAM,OAAO,GAAG,IAAI,UAAU,GAAG,IAAI,UAAU;AAC/C,MAAI,CAAC,SAAU,QAAO;AACtB,QAAM,IAAI,IAAI,IAAI,IAAI;AACtB,IAAE,aAAa,IAAI,aAAa,cAAc,QAAQ,CAAC;AACvD,SAAO,EAAE,SAAS;AACtB;AASO,SAAS,mBAAmB,KAA6B,UAA2B;AACvF,QAAM,IAAI,IAAI,IAAI,eAAe,KAAK,QAAQ,CAAC;AAC/C,IAAE,aAAa,IAAI,OAAO,GAAG;AAC7B,SAAO,EAAE,SAAS;AACtB;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useOcSession
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IKNAIRW5.mjs";
|
|
4
4
|
import {
|
|
5
5
|
resolveConfig
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-X4PPXI3K.mjs";
|
|
7
7
|
|
|
8
8
|
// src/webauthn.tsx
|
|
9
9
|
import * as React from "react";
|
|
@@ -250,4 +250,4 @@ export {
|
|
|
250
250
|
useWebAuthnList,
|
|
251
251
|
useStepUpAuth
|
|
252
252
|
};
|
|
253
|
-
//# sourceMappingURL=chunk-
|
|
253
|
+
//# sourceMappingURL=chunk-XVLOTOCX.mjs.map
|
package/dist/components.mjs
CHANGED
|
@@ -4,9 +4,11 @@ import {
|
|
|
4
4
|
OcAddressInput,
|
|
5
5
|
OcSignInButton,
|
|
6
6
|
useOcAddressSuggestion
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-MIBVEZLP.mjs";
|
|
8
|
+
import "./chunk-IKNAIRW5.mjs";
|
|
9
|
+
import "./chunk-OKIFTNEO.mjs";
|
|
10
|
+
import "./chunk-E3QI365E.mjs";
|
|
11
|
+
import "./chunk-X4PPXI3K.mjs";
|
|
10
12
|
import "./chunk-JTT77LMU.mjs";
|
|
11
13
|
import "./chunk-4BOO7EQR.mjs";
|
|
12
14
|
export {
|
package/dist/index.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ type OcSignOutResult = {
|
|
|
31
31
|
ok: true;
|
|
32
32
|
} | {
|
|
33
33
|
ok: false;
|
|
34
|
-
reason: 'unreachable' | 'refused';
|
|
34
|
+
reason: 'unreachable' | 'refused' | 'several_sessions';
|
|
35
35
|
status?: number;
|
|
36
36
|
};
|
|
37
37
|
interface OcSessionState {
|
|
@@ -144,6 +144,7 @@ interface OcSignInBaseProps {
|
|
|
144
144
|
};
|
|
145
145
|
linkPrompt?: boolean;
|
|
146
146
|
add?: boolean;
|
|
147
|
+
onSeveralSessions?: () => unknown;
|
|
147
148
|
className?: string;
|
|
148
149
|
}
|
|
149
150
|
type OcSignInProps = OcSignInBaseProps & ({
|
|
@@ -156,7 +157,7 @@ type OcSignInProps = OcSignInBaseProps & ({
|
|
|
156
157
|
});
|
|
157
158
|
declare function safeReturnTo(input: string | undefined): string;
|
|
158
159
|
declare function familyReturnTarget(input: string | undefined | null): string | undefined;
|
|
159
|
-
declare function OcSignIn({ audience, returnTo, onSuccess, resolveReturnTo, linkPrompt: linkPromptProp, add: addProp, authOrigin, initialPath, providersFirst, paths, className, mode, providerHref, }: OcSignInProps): React.ReactElement;
|
|
160
|
+
declare function OcSignIn({ audience, returnTo, onSuccess, resolveReturnTo, linkPrompt: linkPromptProp, add: addProp, onSeveralSessions, authOrigin, initialPath, providersFirst, paths, className, mode, providerHref, }: OcSignInProps): React.ReactElement;
|
|
160
161
|
|
|
161
162
|
declare function otpNetworkCapText(retryAt: unknown, instead?: string): string;
|
|
162
163
|
declare function newAccountsCapText(retryAt: unknown): string;
|