@orangecheck/auth-client 2.33.4 → 2.35.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/appearance.mjs +23 -0
- package/dist/appearance.mjs.map +1 -0
- package/dist/bond.mjs +20 -0
- package/dist/bond.mjs.map +1 -0
- package/dist/chunk-4E7GJ5IB.mjs +1184 -0
- package/dist/chunk-4E7GJ5IB.mjs.map +1 -0
- package/dist/chunk-7ST4Q5KR.mjs +346 -0
- package/dist/chunk-7ST4Q5KR.mjs.map +1 -0
- package/dist/chunk-7UYPMTAV.mjs +652 -0
- package/dist/chunk-7UYPMTAV.mjs.map +1 -0
- package/dist/chunk-BYAF2P2L.mjs +253 -0
- package/dist/chunk-BYAF2P2L.mjs.map +1 -0
- package/dist/chunk-CYR7J4UY.mjs +118 -0
- package/dist/chunk-CYR7J4UY.mjs.map +1 -0
- package/dist/chunk-H2TXOCXH.mjs +23 -0
- package/dist/chunk-H2TXOCXH.mjs.map +1 -0
- package/dist/chunk-HZ4FJMF3.mjs +490 -0
- package/dist/chunk-HZ4FJMF3.mjs.map +1 -0
- package/dist/chunk-TJJNTITX.mjs +187 -0
- package/dist/chunk-TJJNTITX.mjs.map +1 -0
- package/dist/chunk-UFRU3I3D.mjs +913 -0
- package/dist/chunk-UFRU3I3D.mjs.map +1 -0
- package/dist/chunk-VRLFZAGK.mjs +37 -0
- package/dist/chunk-VRLFZAGK.mjs.map +1 -0
- package/dist/chunk-XCZVSE7M.mjs +40 -0
- package/dist/chunk-XCZVSE7M.mjs.map +1 -0
- package/dist/components.mjs +19 -0
- package/dist/components.mjs.map +1 -0
- package/dist/index.js +77 -67
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +112 -4001
- package/dist/index.mjs.map +1 -1
- package/dist/linked-identities.mjs +41 -0
- package/dist/linked-identities.mjs.map +1 -0
- package/dist/provider.mjs +17 -0
- package/dist/provider.mjs.map +1 -0
- package/dist/return-to.mjs +18 -0
- package/dist/return-to.mjs.map +1 -0
- package/dist/signin.mjs +23 -0
- package/dist/signin.mjs.map +1 -0
- package/dist/sudo.mjs +16 -0
- package/dist/sudo.mjs.map +1 -0
- package/dist/tab-session.mjs +29 -0
- package/dist/tab-session.mjs.map +1 -0
- package/dist/types.mjs +17 -0
- package/dist/types.mjs.map +1 -0
- package/dist/webauthn.mjs +15 -0
- package/dist/webauthn.mjs.map +1 -0
- package/package.json +2 -1
- package/dist/index.d.mts +0 -303
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/linked-identities.tsx"],"sourcesContent":["'use client';\n\n/**\n * @orangecheck/auth-client · OcLinkedIdentities\n *\n * The shared linked-identities management surface for every `X.ochk.io`\n * consumer. A signed-in user sees their linked email + Bitcoin address,\n * can reveal/hide each raw value, unlink a non-primary identity, and\n * link a new one. Linking a Bitcoin address that's already on another\n * OC account offers a dual-proof transfer; the same is now true for\n * email (auth host F4). Consolidated (`merged_from`) accounts render in\n * a tombstone panel.\n *\n * This generalizes me.ochk.io's bespoke `LinkedIdentitiesPanel` so\n * linking is no longer a single-product, one-tab feature — any family\n * site can drop in `<OcLinkedIdentities />`. See AUTH-PLAN.md §5.\n *\n * All endpoints live on the auth host (`ochk.io`); calls are\n * cross-origin with `credentials: 'include'` and rely on the auth\n * host's family-CORS — the same posture `OcSignIn` uses. No local\n * proxy route is needed (AUTH-AUDIT.md F6: direct-to-host is the\n * intended design).\n *\n * Style: inline, CSS-variable-themed (same approach as `OcSignIn`), so\n * the component carries zero CSS dependency and themes to each site.\n * Every block carries a `data-oc-li-*` attribute so a site may\n * override via its own stylesheet.\n */\n\nimport * as React from 'react';\nimport {\n handleSudoRequired,\n isSudoAccountMismatch,\n SUDO_ACCOUNT_MISMATCH_MESSAGE,\n} from './sudo';\n\nimport {\n SIGNIN_BUTTON_RADIUS,\n SIGNIN_CASE,\n SIGNIN_FONT,\n signinRadius,\n signinSize,\n signinTracking,\n} from './appearance';\nimport { tabSessionHeader } from './tab-session';\n\nconst DEFAULT_AUTH_ORIGIN = 'https://ochk.io';\n\n/* --- types --- */\n\nexport interface OcLinkedIdentity {\n id: string;\n kind: 'email' | 'btc';\n /** Raw value · null when the identity is pending recovery. */\n value: string | null;\n verified_at: string | null;\n verification_method: 'email-otp' | 'bip322' | null;\n /** The signup-time identity for its kind · cannot be unlinked here. */\n is_primary: boolean;\n}\n\ninterface MergedFromEntry {\n did_oc: string;\n created_at: string;\n last_signed_in_at: string | null;\n}\n\ninterface IdentitiesResp {\n ok: boolean;\n account_id?: string;\n did_oc?: string | null;\n linked?: OcLinkedIdentity[];\n merged_from?: MergedFromEntry[];\n reason?: string;\n}\n\n/**\n * Fetch the signed-in user's linked identities from the auth host —\n * the same data `<OcLinkedIdentities>` renders, exposed as a plain\n * function for surfaces that need the list without the full\n * management UI (notably `<OcAccountMenu>`'s badge-identity promote\n * list). Returns `[]` when anonymous; throws on network / server\n * error so the caller can show a deferred state.\n */\nexport async function fetchOcLinkedIdentities(opts?: {\n authOrigin?: string;\n}): Promise<OcLinkedIdentity[]> {\n const authOrigin = opts?.authOrigin ?? DEFAULT_AUTH_ORIGIN;\n // Per-tab pinning: forward the tab's session JWT so the host resolves\n // the SAME account this tab displays (its chip reads /api/auth/me\n // tab-aware). Without this, a pinned tab's show-as list is the shared\n // cookie account's identities — a menu that disagrees with itself.\n // Unpinned tabs send no header → unchanged cookie-default behavior.\n const r = await fetch(`${authOrigin}/api/auth/identities`, {\n credentials: 'include',\n headers: { ...tabSessionHeader() },\n });\n if (r.status === 401) return [];\n if (!r.ok) throw new Error(`identities fetch failed: http_${r.status}`);\n const body = (await r.json()) as IdentitiesResp;\n return body.linked ?? [];\n}\n\nexport interface OcLinkedIdentitiesProps {\n /** Auth host origin. Defaults to `https://ochk.io`. */\n authOrigin?: string;\n /** Outer container className. */\n className?: string;\n /** Called after every successful link / unlink / transfer. */\n onChange?: () => void;\n /**\n * Show the \"portable attestation\" card that links out to attest.ochk.io.\n * Defaults to `true`. Pass `false` on a page that already hosts its own\n * attestation builder (ochk.io's dashboard), or the same action is offered\n * twice, one panel apart.\n */\n attestationLink?: boolean;\n}\n\n/* --- main --- */\n\nexport function OcLinkedIdentities({\n authOrigin = DEFAULT_AUTH_ORIGIN,\n className,\n onChange,\n attestationLink = true,\n}: OcLinkedIdentitiesProps): React.ReactElement {\n const [resp, setResp] = React.useState<IdentitiesResp | null>(null);\n const [error, setError] = React.useState<string | null>(null);\n const [showEmailLink, setShowEmailLink] = React.useState(false);\n const [showBtcLink, setShowBtcLink] = React.useState(false);\n\n const refresh = React.useCallback(async () => {\n setError(null);\n try {\n const r = await fetch(`${authOrigin}/api/auth/identities`, {\n credentials: 'include',\n headers: { ...tabSessionHeader() },\n });\n if (!r.ok) {\n if (r.status === 401) {\n setError('not signed in');\n return;\n }\n throw new Error(`http_${r.status}`);\n }\n setResp((await r.json()) as IdentitiesResp);\n } catch (e) {\n setError(e instanceof Error ? e.message : 'load failed');\n }\n }, [authOrigin]);\n\n React.useEffect(() => {\n void refresh();\n }, [refresh]);\n\n const afterChange = React.useCallback(() => {\n setShowEmailLink(false);\n setShowBtcLink(false);\n void refresh();\n onChange?.();\n }, [refresh, onChange]);\n\n if (error) {\n return (\n <div className={className} data-oc-li=\"\" style={panelStyle('warn')} role=\"alert\">\n <SectionLabel tone=\"warn\">§ identities · load deferred</SectionLabel>\n <p style={bodyStyle}>\n Couldn't reach the auth host ({error}). Linking is temporarily\n unavailable; your signed-in identity still works as normal.\n </p>\n <button type=\"button\" onClick={() => void refresh()} style={ghostBtnStyle(false)}>\n retry\n </button>\n </div>\n );\n }\n\n if (!resp) {\n return (\n <div className={className} data-oc-li=\"\" style={panelStyle()}>\n <span style={hintStyle}>loading…</span>\n </div>\n );\n }\n\n const linked = resp.linked ?? [];\n const emailRows = linked.filter((i) => i.kind === 'email');\n const btcRows = linked.filter((i) => i.kind === 'btc');\n const hasEmail = emailRows.some((i) => i.value);\n const hasBtc = btcRows.some((i) => i.value);\n const mergedFrom = resp.merged_from ?? [];\n\n return (\n <div className={className} data-oc-li=\"\" style={{ display: 'grid', gap: 16 }}>\n <div style={panelStyle()}>\n <SectionLabel>§ what this is</SectionLabel>\n <p style={bodyStyle}>\n These are the ways you can sign in to this account. An app you sign in to\n sees one only if you grant it. Linking a second one is also your way back\n in: lose one, and the other still signs you in.\n </p>\n </div>\n\n {mergedFrom.length > 0 && <ConsolidationPanel entries={mergedFrom} />}\n\n <div style={panelStyle('plain')} data-oc-li-rows=\"\">\n <IdentityGroup\n kind=\"email\"\n title=\"email\"\n rows={emailRows}\n authOrigin={authOrigin}\n onChange={afterChange}\n addCta={hasEmail ? null : 'link an email'}\n onAdd={() => {\n setShowEmailLink((v) => !v);\n setShowBtcLink(false);\n }}\n />\n <div style={{ borderTop: `1px solid ${V.border}` }} />\n <IdentityGroup\n kind=\"btc\"\n title=\"bitcoin address\"\n rows={btcRows}\n authOrigin={authOrigin}\n onChange={afterChange}\n addCta={hasBtc ? null : 'link a Bitcoin address'}\n onAdd={() => {\n setShowBtcLink((v) => !v);\n setShowEmailLink(false);\n }}\n />\n </div>\n\n {showEmailLink && (\n <EmailLinkForm\n authOrigin={authOrigin}\n onDone={afterChange}\n onCancel={() => setShowEmailLink(false)}\n />\n )}\n {showBtcLink && (\n <BtcLinkForm\n authOrigin={authOrigin}\n didOc={resp.did_oc ?? null}\n onDone={afterChange}\n onCancel={() => setShowBtcLink(false)}\n />\n )}\n\n {hasBtc && attestationLink && <AttestationLink />}\n </div>\n );\n}\n\n/* --- identity group (rows for one kind, or an empty-state add CTA) --- */\n\nfunction IdentityGroup({\n kind,\n title,\n rows,\n authOrigin,\n onChange,\n addCta,\n onAdd,\n}: {\n kind: 'email' | 'btc';\n title: string;\n rows: OcLinkedIdentity[];\n authOrigin: string;\n onChange: () => void;\n addCta: string | null;\n onAdd: () => void;\n}): React.ReactElement {\n if (rows.length === 0) {\n return (\n <div style={rowStyle}>\n <div>\n <div style={rowLabelStyle}>§ {title}</div>\n <div style={{ ...bodyStyle, marginTop: 4 }}>none linked</div>\n </div>\n {addCta && (\n <button type=\"button\" onClick={onAdd} style={primaryChipStyle}>\n + {addCta}\n </button>\n )}\n </div>\n );\n }\n return (\n <>\n {rows.map((r) => (\n <IdentityRow\n key={r.id}\n row={r}\n kind={kind}\n authOrigin={authOrigin}\n onChange={onChange}\n />\n ))}\n </>\n );\n}\n\n/* --- single identity row --- */\n\nfunction IdentityRow({\n row,\n kind,\n authOrigin,\n onChange,\n}: {\n row: OcLinkedIdentity;\n kind: 'email' | 'btc';\n authOrigin: string;\n onChange: () => void;\n}): React.ReactElement {\n const [shown, setShown] = React.useState(false);\n const [confirming, setConfirming] = React.useState(false);\n const [busy, setBusy] = React.useState(false);\n const [err, setErr] = React.useState<string | null>(null);\n\n const masked = row.value ? mask(row.value, kind) : '— pending recovery —';\n const display = shown && row.value ? row.value : masked;\n\n async function unlink(): Promise<void> {\n if (row.is_primary) return;\n setBusy(true);\n setErr(null);\n try {\n const r = await fetch(\n `${authOrigin}/api/auth/identities?id=${encodeURIComponent(row.id)}`,\n { method: 'DELETE', credentials: 'include' }\n );\n if (!r.ok) {\n const j = (await r.json().catch(() => ({}))) as { reason?: string };\n throw new Error(j.reason ?? `http_${r.status}`);\n }\n onChange();\n } catch (e) {\n setErr(e instanceof Error ? e.message : 'unlink failed');\n setBusy(false);\n setConfirming(false);\n }\n }\n\n return (\n <div style={rowStyle} data-oc-li-row={kind}>\n <div style={{ minWidth: 0, flex: 1 }}>\n <div style={{ display: 'flex', flexWrap: 'wrap', gap: '4px 12px' }}>\n <span style={rowLabelStyle}>\n § {kind === 'email' ? 'email' : 'bitcoin address'}\n </span>\n {row.is_primary && (\n <span style={{ ...rowLabelStyle, color: V.primary }}>\n primary · signup-time\n </span>\n )}\n </div>\n <div\n style={{\n marginTop: 4,\n color: V.foreground,\n fontFamily: SIGNIN_FONT,\n fontSize: signinSize(12),\n wordBreak: 'break-all',\n }}\n >\n {display}\n </div>\n {row.verified_at && (\n <div style={{ ...hintStyle, marginTop: 4 }}>\n verified · {new Date(row.verified_at).toUTCString()}\n </div>\n )}\n {err && <ErrorLine>{err}</ErrorLine>}\n </div>\n <div style={{ display: 'flex', flexShrink: 0, gap: 8, flexWrap: 'wrap' }}>\n {row.value && (\n <button\n type=\"button\"\n onClick={() => setShown((s) => !s)}\n style={ghostBtnStyle(false)}\n >\n {shown ? 'hide' : 'show'}\n </button>\n )}\n {!row.is_primary && !confirming && (\n <button\n type=\"button\"\n onClick={() => setConfirming(true)}\n style={dangerBtnStyle(false)}\n >\n unlink\n </button>\n )}\n {!row.is_primary && confirming && (\n <>\n <button\n type=\"button\"\n onClick={() => void unlink()}\n disabled={busy}\n style={dangerBtnStyle(busy)}\n >\n {busy ? 'unlinking…' : 'confirm unlink'}\n </button>\n <button\n type=\"button\"\n onClick={() => setConfirming(false)}\n disabled={busy}\n style={ghostBtnStyle(busy)}\n >\n cancel\n </button>\n </>\n )}\n </div>\n </div>\n );\n}\n\n/* --- consolidated-accounts tombstone panel --- */\n\nfunction ConsolidationPanel({ entries }: { entries: MergedFromEntry[] }): React.ReactElement {\n return (\n <div style={panelStyle('success')} data-oc-li-consolidated=\"\">\n <SectionLabel tone=\"success\">\n § consolidated accounts · {entries.length}\n </SectionLabel>\n <p style={bodyStyle}>\n {entries.length === 1 ? 'A previous OC account' : 'Previous OC accounts'} you\n signed up with, folded into this one under dual proof of control. Historical\n activity is unioned into this account automatically;{' '}\n {entries.length === 1 ? 'it' : 'they'} can no longer sign in.\n </p>\n <ul style={{ listStyle: 'none', margin: '12px 0 0', padding: 0 }}>\n {entries.map((e) => (\n <li\n key={e.did_oc}\n style={{\n display: 'flex',\n flexWrap: 'wrap',\n gap: 8,\n padding: '8px 0',\n borderTop: `1px solid ${V.border}`,\n fontFamily: SIGNIN_FONT,\n fontSize: signinSize(11),\n }}\n >\n <code style={{ color: V.foreground, wordBreak: 'break-all' }}>\n {e.did_oc}\n </code>\n <span style={{ ...hintStyle, marginLeft: 'auto' }}>\n created {new Date(e.created_at).toLocaleDateString()}\n </span>\n </li>\n ))}\n </ul>\n </div>\n );\n}\n\n/* --- portable-attestation pointer --- */\n\n/**\n * A thin pointer to the OC Attest builder. The portable, self-sovereign\n * form of identity linking is a standard OrangeCheck attestation — one\n * BIP-322 signature by the Bitcoin address binding it to its handles,\n * published to Nostr. That ceremony already lives at\n * `attest.ochk.io/create` (which pre-fills the address from the signed-in\n * session); this panel routes the user there rather than re-implementing\n * it. Shown once the account has a linked Bitcoin address to attest with.\n */\nfunction AttestationLink(): React.ReactElement {\n return (\n <div style={panelStyle()} data-oc-li-attest=\"\">\n <SectionLabel>§ portable attestation</SectionLabel>\n <p style={bodyStyle}>\n Make your identity links portable: publish a standard OrangeCheck\n attestation — one Bitcoin-wallet signature (BIP-322) binding your address\n to your handles (Nostr, GitHub, …). It is published to Nostr and verifies\n with zero trust in OrangeCheck, so it outlives any single service.\n </p>\n <a\n href=\"https://attest.ochk.io/create\"\n target=\"_blank\"\n rel=\"noreferrer\"\n style={{ ...primaryChipStyle, textDecoration: 'none', display: 'inline-block' }}\n data-oc-li-attest-link=\"\"\n >\n open the attestation builder ↗\n </a>\n </div>\n );\n}\n\n/* --- post-sign-in link prompt (used by OcSignIn) --- */\n\n/** Where the ways to sign in are managed: ochk.app, which replaces me.ochk.io's pages. */\nconst ACCOUNT_WAYS_URL = 'https://ochk.app/me/account#ways';\n\n/**\n * Shown by `<OcSignIn>` after a successful sign-in *when the user ticked\n * the \"also link my other identity\" checkbox on the sign-in form*. It runs\n * the complementary identity's link ceremony inline — BIP-322 for a\n * Bitcoin address, OTP for an email.\n *\n * Skipping is first-class: even though the user opted in at the form, they\n * may change their mind here — an explicit \"skip, I'll do this later\"\n * control exits cleanly and tells them where to link later. `onResolved`\n * (linked, or skipped) hands control back to OcSignIn's post-sign-in\n * navigation.\n */\nexport function LinkPromptStep({\n method,\n didOc,\n authOrigin,\n onResolved,\n}: {\n /** The complementary identity to link — the opposite of the sign-in method. */\n method: 'btc' | 'email';\n didOc: string;\n authOrigin: string;\n /** Called once the user has linked the identity, or skipped. */\n onResolved: () => void;\n}): React.ReactElement {\n const what = method === 'btc' ? 'a Bitcoin address' : 'an email';\n return (\n <div data-oc-linkprompt={method}>\n <div style={{ ...panelStyle('success'), marginBottom: 16 }}>\n <SectionLabel tone=\"success\">§ signed in</SectionLabel>\n <p style={{ ...bodyStyle, margin: 0 }}>\n You chose to also link {what}. Complete it below — or skip for now; it is\n entirely optional and changes nothing about the sign-in you just completed.\n </p>\n </div>\n {method === 'btc' ? (\n <BtcLinkForm\n authOrigin={authOrigin}\n didOc={didOc}\n onDone={onResolved}\n onCancel={onResolved}\n />\n ) : (\n <EmailLinkForm authOrigin={authOrigin} onDone={onResolved} onCancel={onResolved} />\n )}\n <div\n data-oc-linkprompt-skip=\"\"\n style={{ marginTop: 14, paddingTop: 14, borderTop: `1px solid ${V.border}` }}\n >\n <button type=\"button\" onClick={onResolved} style={ghostBtnStyle(false)}>\n skip — I'll do this later\n </button>\n <p style={{ ...hintStyle, marginTop: 8 }}>\n Changed your mind? Skipping continues you straight on — your sign-in is\n unaffected. You can link {what} anytime later from your account page,{' '}\n <a\n href={ACCOUNT_WAYS_URL}\n target=\"_blank\"\n rel=\"noreferrer\"\n style={{ color: 'inherit' }}\n data-oc-linkprompt-account=\"\"\n >\n ochk.app/me/account\n </a>\n .\n </p>\n </div>\n </div>\n );\n}\n\n/* --- email link form --- */\n\nfunction EmailLinkForm({\n authOrigin,\n onDone,\n onCancel,\n}: {\n authOrigin: string;\n onDone: () => void;\n onCancel: () => void;\n}): React.ReactElement {\n const [step, setStep] = React.useState<'email' | 'code'>('email');\n const [email, setEmail] = React.useState('');\n const [code, setCode] = React.useState('');\n const [token, setToken] = React.useState('');\n const [busy, setBusy] = React.useState(false);\n const [err, setErr] = React.useState<string | null>(null);\n // Set when the auth host reports the email is linked elsewhere — the\n // user can confirm a dual-proof transfer (session + verified OTP).\n const [transfer, setTransfer] = React.useState(false);\n\n async function start(): Promise<void> {\n setBusy(true);\n setErr(null);\n try {\n const r = await fetch(`${authOrigin}/api/auth/email-otp/start`, {\n method: 'POST',\n credentials: 'include',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ email: email.trim().toLowerCase() }),\n });\n const j = (await r.json()) as { ok?: boolean; token?: string; reason?: string };\n if (!r.ok || !j.token) throw new Error(j.reason ?? `http_${r.status}`);\n setToken(j.token);\n setStep('code');\n } catch (e) {\n setErr(e instanceof Error ? e.message : 'could not send code');\n } finally {\n setBusy(false);\n }\n }\n\n async function verify(confirmTransfer: boolean): Promise<void> {\n setBusy(true);\n setErr(null);\n try {\n const r = await fetch(`${authOrigin}/api/auth/link/email`, {\n method: 'POST',\n credentials: 'include',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n email: email.trim().toLowerCase(),\n code: code.trim(),\n token,\n ...(confirmTransfer ? { confirm_transfer: true } : {}),\n }),\n });\n const j = (await r.json()) as { ok?: boolean; reason?: string };\n if (r.status === 409 && j.reason === 'email_linked_elsewhere') {\n setTransfer(true);\n setBusy(false);\n return;\n }\n if (handleSudoRequired(j, { purpose: 'link an email' })) return;\n if (isSudoAccountMismatch(j)) {\n setErr(SUDO_ACCOUNT_MISMATCH_MESSAGE);\n setBusy(false);\n return;\n }\n if (!r.ok || !j.ok) throw new Error(j.reason ?? `http_${r.status}`);\n onDone();\n } catch (e) {\n setErr(e instanceof Error ? e.message : 'link failed');\n setBusy(false);\n }\n }\n\n return (\n <div style={panelStyle('accent')} data-oc-li-form=\"email\">\n <SectionLabel>§ link an email</SectionLabel>\n {step === 'email' ? (\n <>\n <input\n type=\"email\"\n autoComplete=\"email\"\n value={email}\n onChange={(e) => setEmail(e.target.value)}\n placeholder=\"you@example.com\"\n style={inputStyle}\n />\n {err && <ErrorLine>{err}</ErrorLine>}\n <FormButtons>\n <button\n type=\"button\"\n onClick={() => void start()}\n disabled={busy || email.trim().length < 5}\n style={primaryBtnStyle(busy || email.trim().length < 5)}\n >\n {busy ? 'sending…' : 'send code'}\n </button>\n <button type=\"button\" onClick={onCancel} style={ghostBtnStyle(busy)}>\n cancel\n </button>\n </FormButtons>\n </>\n ) : transfer ? (\n <TransferConfirm\n what=\"email\"\n busy={busy}\n onConfirm={() => void verify(true)}\n onCancel={onCancel}\n err={err}\n />\n ) : (\n <>\n <p style={bodyStyle}>Enter the 6-digit code sent to {email}.</p>\n <input\n type=\"text\"\n inputMode=\"numeric\"\n autoComplete=\"one-time-code\"\n maxLength={6}\n value={code}\n onChange={(e) => setCode(e.target.value.replace(/\\D/g, '').slice(0, 6))}\n placeholder=\"123456\"\n style={{ ...inputStyle, letterSpacing: '0.3em' }}\n />\n {err && <ErrorLine>{err}</ErrorLine>}\n <FormButtons>\n <button\n type=\"button\"\n onClick={() => void verify(false)}\n disabled={busy || code.length !== 6}\n style={primaryBtnStyle(busy || code.length !== 6)}\n >\n {busy ? 'linking…' : 'verify + link'}\n </button>\n <button\n type=\"button\"\n onClick={() => setStep('email')}\n disabled={busy}\n style={ghostBtnStyle(busy)}\n >\n back\n </button>\n </FormButtons>\n </>\n )}\n </div>\n );\n}\n\n/* --- btc link form --- */\n\nfunction BtcLinkForm({\n authOrigin,\n didOc,\n onDone,\n onCancel,\n}: {\n authOrigin: string;\n didOc: string | null;\n onDone: () => void;\n onCancel: () => void;\n}): React.ReactElement {\n const [step, setStep] = React.useState<'request' | 'sign'>('request');\n const [addr, setAddr] = React.useState('');\n const [challenge, setChallenge] = React.useState('');\n const [busy, setBusy] = React.useState(false);\n const [err, setErr] = React.useState<string | null>(null);\n // Holds the signature awaiting transfer confirmation when the\n // address is already linked to another account.\n const [pendingSig, setPendingSig] = React.useState<string | null>(null);\n\n async function getChallenge(): Promise<void> {\n if (!didOc) {\n setErr('session not loaded yet · refresh and retry');\n return;\n }\n setBusy(true);\n setErr(null);\n try {\n // /api/challenge is a public primitive — no session needed.\n // audience MUST be the caller's did_oc: the link endpoint\n // verifies expectedAudience=session.did_oc, so a signature\n // obtained here can't be replayed against another account.\n const r = await fetch(\n `${authOrigin}/api/challenge?addr=${encodeURIComponent(addr)}` +\n `&purpose=link&audience=${encodeURIComponent(didOc)}`\n );\n const j = (await r.json()) as { message?: string; reason?: string };\n if (!r.ok || !j.message) throw new Error(j.reason ?? `http_${r.status}`);\n setChallenge(j.message);\n setStep('sign');\n } catch (e) {\n setErr(e instanceof Error ? e.message : 'challenge failed');\n } finally {\n setBusy(false);\n }\n }\n\n async function postLink(sig: string, confirmTransfer: boolean): Promise<void> {\n setBusy(true);\n setErr(null);\n try {\n const r = await fetch(`${authOrigin}/api/auth/link/btc`, {\n method: 'POST',\n credentials: 'include',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n message: challenge,\n signature: sig,\n ...(confirmTransfer ? { confirm_transfer: true } : {}),\n }),\n });\n const j = (await r.json()) as { ok?: boolean; reason?: string };\n if (r.status === 409 && j.reason === 'address_linked_elsewhere') {\n setPendingSig(sig);\n setBusy(false);\n return;\n }\n if (handleSudoRequired(j, { purpose: 'link a Bitcoin address' })) return;\n if (isSudoAccountMismatch(j)) {\n setErr(SUDO_ACCOUNT_MISMATCH_MESSAGE);\n setBusy(false);\n return;\n }\n if (!r.ok || !j.ok) throw new Error(j.reason ?? `http_${r.status}`);\n onDone();\n } catch (e) {\n setErr(e instanceof Error ? e.message : 'link failed');\n setBusy(false);\n }\n }\n\n return (\n <div style={panelStyle('accent')} data-oc-li-form=\"btc\">\n <SectionLabel>§ link a Bitcoin address</SectionLabel>\n {step === 'request' ? (\n <>\n <p style={bodyStyle}>\n Enter a Bitcoin address you control. We generate a challenge and your\n wallet signs it (BIP-322).\n </p>\n <input\n type=\"text\"\n value={addr}\n onChange={(e) => setAddr(e.target.value.trim())}\n placeholder=\"bc1q…\"\n autoCapitalize=\"none\"\n spellCheck={false}\n style={{ ...inputStyle, fontFamily: SIGNIN_FONT }}\n />\n {err && <ErrorLine>{err}</ErrorLine>}\n <FormButtons>\n <button\n type=\"button\"\n onClick={() => void getChallenge()}\n disabled={busy || addr.length < 14}\n style={primaryBtnStyle(busy || addr.length < 14)}\n >\n {busy ? 'requesting…' : 'get challenge'}\n </button>\n <button type=\"button\" onClick={onCancel} style={ghostBtnStyle(busy)}>\n cancel\n </button>\n </FormButtons>\n </>\n ) : pendingSig ? (\n <TransferConfirm\n what=\"bitcoin address\"\n busy={busy}\n onConfirm={() => void postLink(pendingSig, true)}\n onCancel={onCancel}\n err={err}\n />\n ) : (\n <>\n <p style={bodyStyle}>\n Sign the challenge with the wallet that controls{' '}\n <span style={{ fontFamily: SIGNIN_FONT, wordBreak: 'break-all' }}>{addr}</span>.\n </p>\n <LazyWalletButton\n address={addr}\n message={challenge}\n showManual\n layout=\"list\"\n heading={null}\n onSigned={(sig: string) => void postLink(sig, false)}\n onError={(e: { message?: string }) =>\n setErr(e?.message ?? 'wallet rejected')\n }\n />\n {err && <ErrorLine>{err}</ErrorLine>}\n <FormButtons>\n <button\n type=\"button\"\n onClick={() => {\n setStep('request');\n setErr(null);\n }}\n disabled={busy}\n style={ghostBtnStyle(busy)}\n >\n back\n </button>\n </FormButtons>\n </>\n )}\n </div>\n );\n}\n\n/* --- transfer-under-dual-proof confirm --- */\n\nfunction TransferConfirm({\n what,\n busy,\n onConfirm,\n onCancel,\n err,\n}: {\n what: string;\n busy: boolean;\n onConfirm: () => void;\n onCancel: () => void;\n err: string | null;\n}): React.ReactElement {\n return (\n <>\n <p style={bodyStyle}>\n This {what} is already linked to another OrangeCheck account. You've just\n proven control of it — you can transfer the link to this account under dual proof\n of control. The other account loses this sign-in path; its history stays\n verifiable. Continue?\n </p>\n {err && <ErrorLine>{err}</ErrorLine>}\n <FormButtons>\n <button\n type=\"button\"\n onClick={onConfirm}\n disabled={busy}\n style={dangerBtnStyle(busy)}\n >\n {busy ? 'transferring…' : 'transfer link here'}\n </button>\n <button type=\"button\" onClick={onCancel} disabled={busy} style={ghostBtnStyle(busy)}>\n cancel\n </button>\n </FormButtons>\n </>\n );\n}\n\n/* --- lazy wallet button · wallet-adapter loads on demand, not with the page --- */\n\ninterface WalletButtonProps {\n address: string;\n message: string;\n showManual?: boolean;\n layout?: string;\n heading?: React.ReactNode;\n onSigned: (sig: string) => void;\n onError: (err: { message?: string }, walletId?: string) => void;\n}\n\nexport function LazyWalletButton(props: WalletButtonProps): React.ReactElement {\n const [Comp, setComp] = React.useState<React.ComponentType<WalletButtonProps> | null>(null);\n const [failed, setFailed] = React.useState(false);\n\n React.useEffect(() => {\n let alive = true;\n // A bundler resolves this specifier at build time, so wallet-adapter\n // is a real dependency; only the chunk is deferred.\n import('@orangecheck/wallet-adapter/react')\n .then((m) => {\n if (alive) {\n setComp(\n () => (m as { OcWalletButton: React.ComponentType<WalletButtonProps> })\n .OcWalletButton\n );\n }\n })\n .catch(() => {\n if (alive) setFailed(true);\n });\n return () => {\n alive = false;\n };\n }, []);\n\n if (failed) {\n return (\n <ErrorLine>\n could not load wallet support · refresh to try again\n </ErrorLine>\n );\n }\n if (!Comp) return <span style={hintStyle}>loading wallet options…</span>;\n return <Comp {...props} />;\n}\n\n/* --- helpers --- */\n\nfunction mask(value: string, kind: 'email' | 'btc'): string {\n if (kind === 'email') {\n const [user, host] = value.split('@');\n if (!user || !host) return '••••';\n const m =\n user.length <= 2\n ? '•'.repeat(user.length)\n : user[0] + '•'.repeat(user.length - 2) + user.slice(-1);\n return `${m}@${host}`;\n }\n if (value.length <= 12) return '•'.repeat(value.length);\n return `${value.slice(0, 6)}…${value.slice(-4)}`;\n}\n\n/* --- presentational atoms · also used by bond.tsx; not re-exported from index --- */\n\nexport function SectionLabel({\n children,\n tone = 'primary',\n}: {\n children: React.ReactNode;\n tone?: 'primary' | 'success' | 'warn';\n}): React.ReactElement {\n const color = tone === 'success' ? V.success : tone === 'warn' ? V.warn : V.primary;\n return (\n <div\n style={{\n color,\n fontFamily: SIGNIN_FONT,\n fontSize: signinSize(10),\n letterSpacing: signinTracking('0.18em'),\n textTransform: SIGNIN_CASE,\n marginBottom: 8,\n }}\n >\n {children}\n </div>\n );\n}\n\nexport function ErrorLine({ children }: { children: React.ReactNode }): React.ReactElement {\n return (\n <p\n role=\"alert\"\n style={{\n margin: '8px 0 0',\n color: V.destructive,\n fontFamily: SIGNIN_FONT,\n fontSize: signinSize(11),\n }}\n >\n {children}\n </p>\n );\n}\n\nexport function FormButtons({ children }: { children: React.ReactNode }): React.ReactElement {\n return (\n <div style={{ display: 'flex', flexWrap: 'wrap', gap: 8, marginTop: 12 }}>{children}</div>\n );\n}\n\n/* --- style tokens (CSS-variable-themed, same approach as OcSignIn) --- */\n\n\nexport const V = {\n primary: 'var(--primary, #f97316)',\n foreground: 'var(--foreground, #fafafa)',\n muted: 'var(--muted-foreground, #a1a1aa)',\n background: 'var(--background, #0a0a0a)',\n card: 'var(--card, #111113)',\n border: 'var(--border, #27272a)',\n destructive: 'var(--destructive, #ef4444)',\n success: 'var(--success, #22c55e)',\n warn: 'var(--warning, #eab308)',\n} as const;\n\nexport function panelStyle(tone: 'plain' | 'accent' | 'success' | 'warn' | 'default' = 'default'): React.CSSProperties {\n const base: React.CSSProperties = {\n background: V.card,\n border: `1px solid ${V.border}`,\n padding: '1.25rem',\n };\n if (tone === 'plain') return { ...base, padding: 0 };\n if (tone === 'accent') return { ...base, borderColor: V.primary, background: 'var(--card, #111113)' };\n if (tone === 'success') return { ...base, borderColor: V.success };\n if (tone === 'warn') return { ...base, borderColor: V.warn };\n return base;\n}\n\nexport const bodyStyle: React.CSSProperties = {\n color: V.muted,\n fontSize: 13,\n lineHeight: 1.55,\n margin: '0 0 12px',\n};\n\nexport const hintStyle: React.CSSProperties = {\n color: V.muted,\n fontFamily: SIGNIN_FONT,\n fontSize: signinSize(10.5),\n opacity: 0.8,\n};\n\nconst rowStyle: React.CSSProperties = {\n display: 'flex',\n flexWrap: 'wrap',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: 12,\n padding: '1rem',\n};\n\nconst rowLabelStyle: React.CSSProperties = {\n color: V.foreground,\n fontFamily: SIGNIN_FONT,\n fontSize: signinSize(10.5),\n letterSpacing: signinTracking('0.12em'),\n textTransform: SIGNIN_CASE,\n opacity: 0.8,\n};\n\nexport const inputStyle: React.CSSProperties = {\n width: '100%',\n padding: '0.55rem 0.75rem',\n background: V.background,\n color: V.foreground,\n border: `1px solid ${V.border}`,\n borderRadius: signinRadius(6),\n fontFamily: SIGNIN_FONT,\n // 16px — never lower · suppresses iOS Safari focus auto-zoom.\n fontSize: 16,\n boxSizing: 'border-box',\n};\n\nfunction btnBase(disabled: boolean): React.CSSProperties {\n return {\n padding: '0.5rem 0.875rem',\n borderRadius: SIGNIN_BUTTON_RADIUS,\n fontFamily: SIGNIN_FONT,\n fontSize: signinSize(10.5),\n letterSpacing: signinTracking('0.12em'),\n textTransform: SIGNIN_CASE,\n cursor: disabled ? 'not-allowed' : 'pointer',\n opacity: disabled ? 0.5 : 1,\n };\n}\n\nexport function primaryBtnStyle(disabled: boolean): React.CSSProperties {\n return {\n ...btnBase(disabled),\n background: V.primary,\n color: 'var(--primary-foreground, #0a0a0a)',\n border: `1px solid ${V.primary}`,\n fontWeight: 600,\n };\n}\n\nexport function ghostBtnStyle(disabled: boolean): React.CSSProperties {\n return {\n ...btnBase(disabled),\n background: V.background,\n color: V.foreground,\n border: `1px solid ${V.border}`,\n };\n}\n\nexport function dangerBtnStyle(disabled: boolean): React.CSSProperties {\n return {\n ...btnBase(disabled),\n background: 'transparent',\n color: V.destructive,\n border: `1px solid ${V.destructive}`,\n };\n}\n\nconst primaryChipStyle: React.CSSProperties = {\n ...btnBase(false),\n background: 'transparent',\n color: V.primary,\n border: `1px solid ${V.primary}`,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AA6BA,YAAY,WAAW;AAyIP,SA4HR,UA5HQ,KACA,YADA;AAxHhB,IAAM,sBAAsB;AAsC5B,eAAsB,wBAAwB,MAEd;AAC5B,QAAM,aAAa,MAAM,cAAc;AAMvC,QAAM,IAAI,MAAM,MAAM,GAAG,UAAU,wBAAwB;A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A,IACH,SAAS;AAAA,IACT,cAAc;AAAA,IACd,YAAY;AAAA,IACZ,UAAU,WAAW,IAAI;AAAA,IACzB,eAAe,eAAe,QAAQ;AAAA,IACtC,eAAe;AAAA,IACf,QAAQ,WAAW,gBAAgB;AAAA,IACnC,SAAS,WAAW,MAAM;AAAA,EAC9B;AACJ;AAEO,SAAS,gBAAgB,UAAwC;AACpE,SAAO;AAAA,IACH,GAAG,QAAQ,QAAQ;AAAA,IACnB,YAAY,EAAE;AAAA,IACd,OAAO;AAAA,IACP,QAAQ,aAAa,EAAE,OAAO;AAAA,IAC9B,YAAY;AAAA,EAChB;AACJ;AAEO,SAAS,cAAc,UAAwC;AAClE,SAAO;AAAA,IACH,GAAG,QAAQ,QAAQ;AAAA,IACnB,YAAY,EAAE;AAAA,IACd,OAAO,EAAE;AAAA,IACT,QAAQ,aAAa,EAAE,MAAM;AAAA,EACjC;AACJ;AAEO,SAAS,eAAe,UAAwC;AACnE,SAAO;AAAA,IACH,GAAG,QAAQ,QAAQ;AAAA,IACnB,YAAY;AAAA,IACZ,OAAO,EAAE;AAAA,IACT,QAAQ,aAAa,EAAE,WAAW;AAAA,EACtC;AACJ;AAEA,IAAM,mBAAwC;AAAA,EAC1C,GAAG,QAAQ,KAAK;AAAA,EAChB,YAAY;AAAA,EACZ,OAAO,EAAE;AAAA,EACT,QAAQ,aAAa,EAAE,OAAO;AAClC;","names":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
stripFragment
|
|
3
|
+
} from "./chunk-CYR7J4UY.mjs";
|
|
4
|
+
|
|
5
|
+
// src/types.ts
|
|
6
|
+
var DISPLAY_IDENTITY_KINDS = ["did", "btc", "email", "nostr"];
|
|
7
|
+
var DEFAULT_CONFIG = {
|
|
8
|
+
authOrigin: "https://ochk.io",
|
|
9
|
+
signInPath: "/signin",
|
|
10
|
+
mePath: "/api/auth/me",
|
|
11
|
+
logoutPath: "/api/auth/logout",
|
|
12
|
+
multiAccount: true
|
|
13
|
+
};
|
|
14
|
+
function resolveConfig(cfg) {
|
|
15
|
+
return { ...DEFAULT_CONFIG, ...cfg ?? {} };
|
|
16
|
+
}
|
|
17
|
+
function buildSignInUrl(cfg, returnTo) {
|
|
18
|
+
const base = `${cfg.authOrigin}${cfg.signInPath}`;
|
|
19
|
+
if (!returnTo) return base;
|
|
20
|
+
const u = new URL(base);
|
|
21
|
+
u.searchParams.set("return_to", stripFragment(returnTo));
|
|
22
|
+
return u.toString();
|
|
23
|
+
}
|
|
24
|
+
function buildAddAccountUrl(cfg, returnTo) {
|
|
25
|
+
const u = new URL(buildSignInUrl(cfg, returnTo));
|
|
26
|
+
u.searchParams.set("add", "1");
|
|
27
|
+
return u.toString();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
DISPLAY_IDENTITY_KINDS,
|
|
32
|
+
DEFAULT_CONFIG,
|
|
33
|
+
resolveConfig,
|
|
34
|
+
buildSignInUrl,
|
|
35
|
+
buildAddAccountUrl
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=chunk-VRLFZAGK.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 * Slug of the federation this user is bound to (their \"home\"\n * federation). Multi-federation routing reads this; null/undefined\n * means \"not yet bound — fall back to the directory default at\n * /api/federations\". v1 has one live federation, so this is set on\n * first signin and rarely changes.\n */\n homeFederation?: string | null;\n /**\n * Where this user is on the custody-state graph:\n *\n * - 'fedimint_threshold' — federation custody (OC-introduced)\n * - 'fedimint_client' — federation custody (user-picked)\n * - 'bip322' — full self-custody\n *\n * Graduation is the product thesis. Treat undefined as\n * 'fedimint_threshold' for `did:email:` addresses and 'bip322' for\n * Bitcoin addresses (the default-by-construction mapping for\n * tokens minted before this field shipped).\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\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.\n */\n signOut: (opts?: { scope?: OcSignOutScope }) => Promise<void>;\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 */\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;AAqO9D,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":[]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveConfig
|
|
3
|
+
} from "./chunk-VRLFZAGK.mjs";
|
|
4
|
+
import {
|
|
5
|
+
withoutFragment
|
|
6
|
+
} from "./chunk-CYR7J4UY.mjs";
|
|
7
|
+
|
|
8
|
+
// src/sudo.tsx
|
|
9
|
+
function redirectToSudo(args = {}) {
|
|
10
|
+
if (typeof window === "undefined") {
|
|
11
|
+
throw new Error(
|
|
12
|
+
"[@orangecheck/auth-client] redirectToSudo() requires a browser environment"
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
const cfg = resolveConfig(args.config);
|
|
16
|
+
const url = new URL("/sudo", cfg.authOrigin);
|
|
17
|
+
const returnTo = withoutFragment(args.returnTo ?? window.location.href);
|
|
18
|
+
if (returnTo) url.searchParams.set("return_to", returnTo);
|
|
19
|
+
if (args.purpose) url.searchParams.set("purpose", args.purpose);
|
|
20
|
+
window.location.assign(url.toString());
|
|
21
|
+
}
|
|
22
|
+
function handleSudoRequired(body, args = {}) {
|
|
23
|
+
if (body && body.reason === "sudo_required") {
|
|
24
|
+
redirectToSudo(args);
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
var SUDO_ACCOUNT_MISMATCH_MESSAGE = "Switch this tab to that account first \u2014 the confirmation on file is for a different one.";
|
|
30
|
+
function isSudoAccountMismatch(body) {
|
|
31
|
+
return body?.reason === "sudo_account_mismatch";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
redirectToSudo,
|
|
36
|
+
handleSudoRequired,
|
|
37
|
+
SUDO_ACCOUNT_MISMATCH_MESSAGE,
|
|
38
|
+
isSudoAccountMismatch
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=chunk-XCZVSE7M.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sudo.tsx"],"sourcesContent":["/**\n * Inline sudo-mode helpers · the consumer-side counterpart to the\n * ochk.io `/sudo` page.\n *\n * Pattern: when a consumer-side action hits a `401 sudo_required`\n * response from the auth host, call `redirectToSudo()` to bounce the\n * user to `https://ochk.io/sudo?return_to=<current>&purpose=<tag>`.\n * The user completes the email-OTP or BIP-322 re-authentication\n * inline on ochk.io; ochk.io re-issues the session JWT with a fresh\n * `sudo_at` claim; the browser is redirected back; the consumer's\n * original action succeeds on retry.\n *\n * No React hook needed for v1 · this is a one-shot navigation. A\n * future inline-modal version (no redirect) lives behind the same\n * function name so consumers don't have to change call-sites when we\n * upgrade.\n *\n * Server-side, gate sensitive endpoints with `verifySudoClaim()` from\n * @orangecheck/auth-core@^2.2.0.\n */\n\nimport { withoutFragment } from './return-to';\nimport { resolveConfig, type OcAuthConfig } from './types';\n\nexport interface RedirectToSudoArgs {\n /** Where to send the browser after the user finishes the sudo\n * ceremony. Defaults to this page at call-time. Its fragment is\n * never sent: it is kept in this tab and restored on return (see\n * ./return-to). Must be a family origin (`*.ochk.io`) or a relative\n * path; the /sudo page coerces unsafe values to /dashboard. */\n returnTo?: string;\n /** Free-form tag echoed in the /sudo page UI — e.g. `\"register a\n * hardware key\"`. The user sees \"To <purpose>, confirm with the\n * one-time code…\" so the prompt is framed by the action that\n * triggered it. Not security-relevant. */\n purpose?: string;\n /** Optional auth-client config override · same shape as\n * `<OcSessionProvider config={…} />`. Defaults to\n * `authOrigin: 'https://ochk.io'`. */\n config?: OcAuthConfig;\n}\n\n/**\n * Redirect the current browser to the auth host's `/sudo` page,\n * preserving `return_to` and `purpose` query parameters. The auth\n * host runs the ceremony and bounces back on success.\n *\n * Throws on SSR — call this only inside a click handler or effect\n * after a `'sudo_required'` response.\n */\nexport function redirectToSudo(args: RedirectToSudoArgs = {}): void {\n if (typeof window === 'undefined') {\n throw new Error(\n '[@orangecheck/auth-client] redirectToSudo() requires a browser environment'\n );\n }\n const cfg = resolveConfig(args.config);\n const url = new URL('/sudo', cfg.authOrigin);\n const returnTo = withoutFragment(args.returnTo ?? window.location.href);\n if (returnTo) url.searchParams.set('return_to', returnTo);\n if (args.purpose) url.searchParams.set('purpose', args.purpose);\n window.location.assign(url.toString());\n}\n\n/**\n * Convenience wrapper · the most common consumer pattern is \"if the\n * fetch response's body has `reason === 'sudo_required'`, redirect.\"\n * Use this to keep that idiom one line:\n *\n * const r = await fetch(...);\n * const j = await r.json();\n * if (handleSudoRequired(j, { purpose: 'register hardware key' })) return;\n *\n * Returns `true` if a redirect happened (and the caller should\n * short-circuit), `false` otherwise.\n */\nexport function handleSudoRequired(\n body: { reason?: string } | null | undefined,\n args: Omit<RedirectToSudoArgs, 'returnTo'> & { returnTo?: string } = {}\n): boolean {\n if (body && body.reason === 'sudo_required') {\n redirectToSudo(args);\n return true;\n }\n return false;\n}\n\n/**\n * The message for `sudo_account_mismatch` — a fresh sudo proof exists, but for\n * a different account than this tab is acting as.\n *\n * Deliberately NOT a redirect. The ceremony runs on ochk.io for the cookie's\n * default account and cannot reach this tab's pinned account, so bouncing there\n * re-proves the wrong one forever. Callers must show this and stop.\n */\nexport const SUDO_ACCOUNT_MISMATCH_MESSAGE =\n 'Switch this tab to that account first — the confirmation on file is for a different one.';\n\n/**\n * True when the response says a sudo ceremony cannot resolve this request.\n * Pairs with {@link handleSudoRequired}: try the redirect first, then this.\n */\nexport function isSudoAccountMismatch(body: { reason?: string } | null | undefined): boolean {\n return body?.reason === 'sudo_account_mismatch';\n}\n"],"mappings":";;;;;;;;AAkDO,SAAS,eAAe,OAA2B,CAAC,GAAS;AAChE,MAAI,OAAO,WAAW,aAAa;AAC/B,UAAM,IAAI;AAAA,MACN;AAAA,IACJ;AAAA,EACJ;AACA,QAAM,MAAM,cAAc,KAAK,MAAM;AACrC,QAAM,MAAM,IAAI,IAAI,SAAS,IAAI,UAAU;AAC3C,QAAM,WAAW,gBAAgB,KAAK,YAAY,OAAO,SAAS,IAAI;AACtE,MAAI,SAAU,KAAI,aAAa,IAAI,aAAa,QAAQ;AACxD,MAAI,KAAK,QAAS,KAAI,aAAa,IAAI,WAAW,KAAK,OAAO;AAC9D,SAAO,SAAS,OAAO,IAAI,SAAS,CAAC;AACzC;AAcO,SAAS,mBACZ,MACA,OAAqE,CAAC,GAC/D;AACP,MAAI,QAAQ,KAAK,WAAW,iBAAiB;AACzC,mBAAe,IAAI;AACnB,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAUO,IAAM,gCACT;AAMG,SAAS,sBAAsB,MAAuD;AACzF,SAAO,MAAM,WAAW;AAC5B;","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OcAccountChip,
|
|
3
|
+
OcAccountPill,
|
|
4
|
+
OcAddressInput,
|
|
5
|
+
OcSignInButton,
|
|
6
|
+
useOcAddressSuggestion
|
|
7
|
+
} from "./chunk-7UYPMTAV.mjs";
|
|
8
|
+
import "./chunk-7ST4Q5KR.mjs";
|
|
9
|
+
import "./chunk-VRLFZAGK.mjs";
|
|
10
|
+
import "./chunk-CYR7J4UY.mjs";
|
|
11
|
+
import "./chunk-TJJNTITX.mjs";
|
|
12
|
+
export {
|
|
13
|
+
OcAccountChip,
|
|
14
|
+
OcAccountPill,
|
|
15
|
+
OcAddressInput,
|
|
16
|
+
OcSignInButton,
|
|
17
|
+
useOcAddressSuggestion
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=components.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -2144,7 +2144,6 @@ var inputStyle = {
|
|
|
2144
2144
|
fontFamily: SIGNIN_FONT,
|
|
2145
2145
|
// 16px — never lower · suppresses iOS Safari focus auto-zoom.
|
|
2146
2146
|
fontSize: 16,
|
|
2147
|
-
outline: "none",
|
|
2148
2147
|
boxSizing: "border-box"
|
|
2149
2148
|
};
|
|
2150
2149
|
function btnBase(disabled) {
|
|
@@ -2251,15 +2250,22 @@ var EMAIL_ERRORS = {
|
|
|
2251
2250
|
var SUBMIT_ERRORS = {
|
|
2252
2251
|
bad_request: "That signature couldn't be read. Copy it again, whole."
|
|
2253
2252
|
};
|
|
2254
|
-
|
|
2253
|
+
function networkError(authOrigin) {
|
|
2254
|
+
let host = authOrigin;
|
|
2255
|
+
try {
|
|
2256
|
+
host = new URL(authOrigin).host;
|
|
2257
|
+
} catch {
|
|
2258
|
+
}
|
|
2259
|
+
return `We couldn't reach the orangecheck sign-in service at ${host}. Check your connection, then try again.`;
|
|
2260
|
+
}
|
|
2255
2261
|
function humanSigninError(reason, path, step = "challenge") {
|
|
2256
2262
|
if (!/^[a-z0-9_]+$/.test(reason)) return reason;
|
|
2257
2263
|
if (path === "wallet" && step === "submit" && SUBMIT_ERRORS[reason]) return SUBMIT_ERRORS[reason];
|
|
2258
2264
|
if (path === "email" && EMAIL_ERRORS[reason]) return EMAIL_ERRORS[reason];
|
|
2259
2265
|
return SIGNIN_ERRORS[reason] ?? (path === "email" ? "That didn't work. Try again, or send a new code." : "That didn't work. Try again.");
|
|
2260
2266
|
}
|
|
2261
|
-
function failureMessage(err, path, step) {
|
|
2262
|
-
if (err instanceof TypeError || err instanceof SyntaxError) return
|
|
2267
|
+
function failureMessage(err, path, step, authOrigin) {
|
|
2268
|
+
if (err instanceof TypeError || err instanceof SyntaxError) return networkError(authOrigin);
|
|
2263
2269
|
return humanSigninError(err instanceof Error ? err.message : "failed", path, step);
|
|
2264
2270
|
}
|
|
2265
2271
|
var BECH32_ADDRESS = /^(bc1|tb1|bcrt1)[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{8,87}$/i;
|
|
@@ -2318,6 +2324,19 @@ function OcSignIn({
|
|
|
2318
2324
|
const [path, setPath] = React4__namespace.useState(
|
|
2319
2325
|
initialPath ?? (providersFirst ? "email" : "wallet")
|
|
2320
2326
|
);
|
|
2327
|
+
const tabsId = React4__namespace.useId();
|
|
2328
|
+
const tabOrder = providersFirst ? ["email", "wallet"] : ["wallet", "email"];
|
|
2329
|
+
const tabRefs = React4__namespace.useRef({});
|
|
2330
|
+
const onTabKey = (e) => {
|
|
2331
|
+
const i = tabOrder.indexOf(path);
|
|
2332
|
+
const last = tabOrder.length - 1;
|
|
2333
|
+
const to = e.key === "ArrowRight" ? (i + 1) % tabOrder.length : e.key === "ArrowLeft" ? (i + last) % tabOrder.length : e.key === "Home" ? 0 : e.key === "End" ? last : -1;
|
|
2334
|
+
if (to < 0) return;
|
|
2335
|
+
e.preventDefault();
|
|
2336
|
+
const next = tabOrder[to];
|
|
2337
|
+
setPath(next);
|
|
2338
|
+
tabRefs.current[next]?.focus();
|
|
2339
|
+
};
|
|
2321
2340
|
const [signedIn, setSignedIn] = React4__namespace.useState(null);
|
|
2322
2341
|
const [linkAlso, setLinkAlso] = React4__namespace.useState(false);
|
|
2323
2342
|
const [oauthError, setOauthError] = React4__namespace.useState(false);
|
|
@@ -2481,7 +2500,7 @@ function OcSignIn({
|
|
|
2481
2500
|
"div",
|
|
2482
2501
|
{
|
|
2483
2502
|
role: "tablist",
|
|
2484
|
-
"aria-label": "
|
|
2503
|
+
"aria-label": "Sign-in method",
|
|
2485
2504
|
"data-oc-signin-tabs": "",
|
|
2486
2505
|
style: {
|
|
2487
2506
|
display: "flex",
|
|
@@ -2489,64 +2508,55 @@ function OcSignIn({
|
|
|
2489
2508
|
marginBottom: 16,
|
|
2490
2509
|
borderBottom: "1px solid var(--border, #27272a)"
|
|
2491
2510
|
},
|
|
2492
|
-
children:
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
{
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2511
|
+
children: tabOrder.map((p) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2512
|
+
SigninTab,
|
|
2513
|
+
{
|
|
2514
|
+
id: `${tabsId}-${p}`,
|
|
2515
|
+
controls: `${tabsId}-panel`,
|
|
2516
|
+
active: path === p,
|
|
2517
|
+
onClick: () => setPath(p),
|
|
2518
|
+
onKeyDown: onTabKey,
|
|
2519
|
+
ref: (el) => {
|
|
2520
|
+
tabRefs.current[p] = el;
|
|
2521
|
+
},
|
|
2522
|
+
children: p === "email" ? "Email" : "Bitcoin wallet"
|
|
2523
|
+
},
|
|
2524
|
+
p
|
|
2525
|
+
))
|
|
2526
|
+
}
|
|
2527
|
+
),
|
|
2528
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2529
|
+
"div",
|
|
2530
|
+
{
|
|
2531
|
+
"data-oc-signin-panel": "",
|
|
2532
|
+
...bothEnabled ? {
|
|
2533
|
+
id: `${tabsId}-panel`,
|
|
2534
|
+
role: "tabpanel",
|
|
2535
|
+
"aria-labelledby": `${tabsId}-${path}`
|
|
2536
|
+
} : {},
|
|
2537
|
+
children: [
|
|
2538
|
+
showWallet && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2539
|
+
WalletFlow,
|
|
2512
2540
|
{
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2541
|
+
authOrigin,
|
|
2542
|
+
audience,
|
|
2543
|
+
add: addMode,
|
|
2544
|
+
credentials,
|
|
2545
|
+
onSuccess: (a, t) => void handleSuccess(a, t, "wallet")
|
|
2516
2546
|
}
|
|
2517
2547
|
),
|
|
2518
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2519
|
-
|
|
2548
|
+
showEmail && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2549
|
+
EmailFlow,
|
|
2520
2550
|
{
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2551
|
+
authOrigin,
|
|
2552
|
+
add: addMode,
|
|
2553
|
+
credentials,
|
|
2554
|
+
onSuccess: (a, t) => void handleSuccess(a, t, "email")
|
|
2524
2555
|
}
|
|
2525
2556
|
)
|
|
2526
|
-
]
|
|
2557
|
+
]
|
|
2527
2558
|
}
|
|
2528
2559
|
),
|
|
2529
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { "data-oc-signin-panel": "", role: "tabpanel", children: [
|
|
2530
|
-
showWallet && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2531
|
-
WalletFlow,
|
|
2532
|
-
{
|
|
2533
|
-
authOrigin,
|
|
2534
|
-
audience,
|
|
2535
|
-
add: addMode,
|
|
2536
|
-
credentials,
|
|
2537
|
-
onSuccess: (a, t) => void handleSuccess(a, t, "wallet")
|
|
2538
|
-
}
|
|
2539
|
-
),
|
|
2540
|
-
showEmail && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2541
|
-
EmailFlow,
|
|
2542
|
-
{
|
|
2543
|
-
authOrigin,
|
|
2544
|
-
add: addMode,
|
|
2545
|
-
credentials,
|
|
2546
|
-
onSuccess: (a, t) => void handleSuccess(a, t, "email")
|
|
2547
|
-
}
|
|
2548
|
-
)
|
|
2549
|
-
] }),
|
|
2550
2560
|
!providersFirst && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2551
2561
|
ProviderSignIn,
|
|
2552
2562
|
{
|
|
@@ -2578,18 +2588,19 @@ function OcSignIn({
|
|
|
2578
2588
|
] })
|
|
2579
2589
|
] });
|
|
2580
2590
|
}
|
|
2581
|
-
|
|
2582
|
-
active,
|
|
2583
|
-
onClick,
|
|
2584
|
-
children
|
|
2585
|
-
}) {
|
|
2591
|
+
var SigninTab = React4__namespace.forwardRef(function SigninTab2({ id, controls, active, onClick, onKeyDown, children }, ref) {
|
|
2586
2592
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2587
2593
|
"button",
|
|
2588
2594
|
{
|
|
2595
|
+
ref,
|
|
2589
2596
|
type: "button",
|
|
2590
2597
|
role: "tab",
|
|
2598
|
+
id,
|
|
2591
2599
|
"aria-selected": active,
|
|
2600
|
+
"aria-controls": controls,
|
|
2601
|
+
tabIndex: active ? 0 : -1,
|
|
2592
2602
|
onClick,
|
|
2603
|
+
onKeyDown,
|
|
2593
2604
|
"data-oc-signin-tab": active ? "active" : "inactive",
|
|
2594
2605
|
style: {
|
|
2595
2606
|
minHeight: 44,
|
|
@@ -2608,7 +2619,7 @@ function SigninTab({
|
|
|
2608
2619
|
children
|
|
2609
2620
|
}
|
|
2610
2621
|
);
|
|
2611
|
-
}
|
|
2622
|
+
});
|
|
2612
2623
|
function ProviderIcon({ id }) {
|
|
2613
2624
|
const common = {
|
|
2614
2625
|
width: 14,
|
|
@@ -2847,7 +2858,7 @@ function WalletFlow({
|
|
|
2847
2858
|
step = "submit";
|
|
2848
2859
|
await submitSignature(challenge.message, challenge.nonce, signature, "bip322");
|
|
2849
2860
|
} catch (err) {
|
|
2850
|
-
setError(failureMessage(err, "wallet", step));
|
|
2861
|
+
setError(failureMessage(err, "wallet", step, authOrigin));
|
|
2851
2862
|
setSubmitting(false);
|
|
2852
2863
|
}
|
|
2853
2864
|
}
|
|
@@ -2864,7 +2875,7 @@ function WalletFlow({
|
|
|
2864
2875
|
try {
|
|
2865
2876
|
await submitSignature(manual.message, manual.nonce, sig, void 0);
|
|
2866
2877
|
} catch (err) {
|
|
2867
|
-
setError(failureMessage(err, "wallet", "submit"));
|
|
2878
|
+
setError(failureMessage(err, "wallet", "submit", authOrigin));
|
|
2868
2879
|
setSubmitting(false);
|
|
2869
2880
|
}
|
|
2870
2881
|
}
|
|
@@ -3016,7 +3027,7 @@ function EmailFlow({ authOrigin, add, credentials, onSuccess }) {
|
|
|
3016
3027
|
setToken(json.token);
|
|
3017
3028
|
return null;
|
|
3018
3029
|
} catch {
|
|
3019
|
-
return
|
|
3030
|
+
return networkError(authOrigin);
|
|
3020
3031
|
}
|
|
3021
3032
|
}
|
|
3022
3033
|
async function start(e) {
|
|
@@ -3077,7 +3088,7 @@ function EmailFlow({ authOrigin, add, credentials, onSuccess }) {
|
|
|
3077
3088
|
}
|
|
3078
3089
|
onSuccess(json.account, json.token);
|
|
3079
3090
|
} catch (err) {
|
|
3080
|
-
setCodeError(failureMessage(err, "email", "submit"));
|
|
3091
|
+
setCodeError(failureMessage(err, "email", "submit", authOrigin));
|
|
3081
3092
|
} finally {
|
|
3082
3093
|
setSubmitting(false);
|
|
3083
3094
|
}
|
|
@@ -3260,8 +3271,7 @@ var inputStyle2 = {
|
|
|
3260
3271
|
// 16px — never below it. A sub-16px font-size makes iOS Safari
|
|
3261
3272
|
// auto-zoom the viewport on focus; the family rule is >=16px on
|
|
3262
3273
|
// every form field. Desktop reads fine at 16 too.
|
|
3263
|
-
fontSize: 16
|
|
3264
|
-
outline: "none"
|
|
3274
|
+
fontSize: 16
|
|
3265
3275
|
};
|
|
3266
3276
|
var linkAlsoStyle = {
|
|
3267
3277
|
display: "flex",
|