@orangecheck/me-client 0.41.0 → 0.42.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/popup.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/popup.ts"],"names":[],"mappings":";;;AA0BA,IAAM,oBAAA,GAAuB,oBAAA;AAC7B,IAAM,kBAAA,GAAqB,eAAA;AAC3B,IAAM,gBAAA,GAAmB,mDAAA;AA2ElB,SAAS,mBAAA,CAAoB,OAAA,GAA+B,EAAC,EAA4B;AAC5F,EAAA,MAAM,WAAA,GAAc,QAAQ,WAAA,IAAe,oBAAA;AAC3C,EAAA,MAAM,SAAA,GAAY,QAAQ,SAAA,IAAa,kBAAA;AACvC,EAAA,MAAM,QAAA,GAAW,QAAQ,QAAA,IAAY,gBAAA;AAErC,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,KAAY;AAC5B,IAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AAC/B,MAAA,OAAA,CAAQ,EAAE,MAAA,EAAQ,QAAA,EAAU,CAAA;AAC5B,MAAA;AAAA,IACJ;AAEA,IAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,SAAA,EAAW,WAAW,CAAA;AAC1C,IAAA,GAAA,CAAI,YAAA,CAAa,GAAA,CAAI,eAAA,EAAiB,MAAA,CAAO,SAAS,MAAM,CAAA;AAC5D,IAAA,MAAM,QAAQ,MAAA,CAAO,IAAA,CAAK,IAAI,QAAA,EAAS,EAAG,aAAa,QAAQ,CAAA;AAC/D,IAAA,IAAI,CAAC,KAAA,EAAO;AACR,MAAA,OAAA,CAAQ,EAAE,MAAA,EAAQ,SAAA,EAAW,CAAA;AAC7B,MAAA;AAAA,IACJ;AACA,IAAA,KAAA,CAAM,KAAA,EAAM;AAEZ,IAAA,IAAI,OAAA,GAAU,KAAA;AACd,IAAA,MAAM,UAAU,MAAM;AAClB,MAAA,MAAA,CAAO,mBAAA,CAAoB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AAI,OAAA,CAAQ,OAAO,OAAA,EAAS;AACxB,QAAA,MAAA,CAAO,EAAE,MAAA,EAAQ,SAAA,EAAW,CAAA;AAC5B,QAAA;AAAA,MACJ;AACA,MAAA,OAAA,CAAQ,MAAA,CAAO,gBAAA,CAAiB,OAAA,EAAS,OAAO,CAAA;AAAA,IACpD;AAGA,IAAA,MAAM,WAAA,GAAc,YAAY,MAAM;AAClC,MAAA,IAAI,SAAS,KAAA,CAAM,MAAA,SAAe,EAAE,MAAA,EAAQ,UAAU,CAAA;AAAA,IAC1D,GAAG,GAAG,CAAA;AAAA,EACV,CAAC,CAAA;AACL;AAWA,eAAsB,YAAA,CAAa,OAAA,GAA+B,EAAC,EAAkC;AACjG,EAAA,MAAM,OAAA,GAAU,MAAM,mBAAA,CAAoB,OAAO,CAAA;AACjD,EAAA,OAAO,OAAA,CAAQ,MAAA,KAAW,WAAA,GAAc,EAAE,OAAA,EAAS,QAAQ,OAAA,EAAS,KAAA,EAAO,OAAA,CAAQ,KAAA,EAAM,GAAI,IAAA;AACjG","file":"popup.js","sourcesContent":["/**\n * @orangecheck/me-client/popup\n *\n * Browser-side helper that opens the OC sign-in popup, listens for the\n * postMessage from me.ochk.io, and resolves with the verified session.\n *\n * import { signInWithOc } from '@orangecheck/me-client/popup';\n *\n * document.querySelector('#oc-signin')!.addEventListener('click', async () => {\n * const result = await signInWithOc();\n * if (!result) return;\n * // Your server verifies it and keeps it in an httpOnly cookie.\n * const r = await fetch('/api/auth/session', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ token: result.token }),\n * });\n * if (r.ok) location.assign('/app');\n * });\n *\n * Why this lives in a separate entry point: it's browser-only (uses\n * window.open / addEventListener) and integrators that only need the\n * server-side verifier shouldn't pull popup orchestration into their\n * server bundle.\n */\n\nconst DEFAULT_POPUP_ORIGIN = 'https://me.ochk.io';\nconst DEFAULT_POPUP_PATH = '/popup/signin';\nconst DEFAULT_FEATURES = 'width=480,height=720,resizable=yes,scrollbars=yes';\n\nexport interface OcPopupAccount {\n id?: string;\n /** Opaque public identity · `did:oc:<32-hex>`. Stable across linking\n * events. The canonical identifier post auth-refactor (Dec 2025\n * +). */\n did_oc?: string;\n /** Primary linked Bitcoin address, if the user has one and is\n * surfacing it (same-origin family integrators get it inline;\n * cross-domain integrators need the bitcoin_address scope). */\n primary_btc?: string | null;\n /** Whether the user has a primary email linked (plaintext stays\n * on auth host; only the boolean reaches integrators). */\n has_email?: boolean;\n /** Legacy fields kept for back-compat with pre-refactor consumers.\n * Prefer did_oc + primary_btc. Removed in a future major. */\n address?: string;\n btc_address?: string;\n display_name?: string | null;\n nostr_npub?: string | null;\n wallet_provisioned?: boolean;\n email?: string;\n}\n\nexport interface OcPopupResult {\n /** Account payload from the auth host, unsigned: trust only the\n * verified token. `did_oc` is the account's opaque identifier, the\n * same at every site; the email and Bitcoin address stay private\n * unless the user grants a scope. */\n account: OcPopupAccount;\n /** The session JWT, bound to your origin. Hand it once to your own\n * server, which verifies it and keeps it in an httpOnly cookie; never\n * in localStorage, where any script on the page can read it. Family\n * sites (*.ochk.io) can ignore it: the Domain=.ochk.io cookie rides\n * home on its own. */\n token: string;\n}\n\nexport interface SignInWithOcOptions {\n /** Origin of the OC popup page. Defaults to https://me.ochk.io.\n * Override only for staging / preview environments. */\n popupOrigin?: string;\n /** Path on the popup origin. Defaults to /popup/signin. */\n popupPath?: string;\n /** window.open features string. Defaults to a 480x720 resizable\n * popup with scrollbars. */\n features?: string;\n /** AbortSignal that cancels the wait and closes the popup. */\n signal?: AbortSignal;\n}\n\n/**\n * How a sign-in popup ended:\n * - `signed_in` · the person signed in; `account` and `token` as from signInWithOc.\n * - `blocked` · the browser refused to open the window. Ask the person to\n * allow pop-ups for your site, then try again from a click.\n * - `closed` · the person closed the window without signing in.\n * - `aborted` · your AbortSignal fired.\n * - `failed` · not in a browser, or the popup's answer was malformed.\n */\nexport type OcPopupOutcome =\n | ({ status: 'signed_in' } & OcPopupResult)\n | { status: 'blocked' }\n | { status: 'closed' }\n | { status: 'aborted' }\n | { status: 'failed' };\n\n/**\n * Open the OC signin popup and resolve with how it ended (OcPopupOutcome),\n * so a blocked window and a closed one can be told apart.\n *\n * MUST be called inside a user-gesture handler (e.g. a button onClick).\n * Browsers block `window.open` outside of user gestures.\n */\nexport function signInWithOcOutcome(options: SignInWithOcOptions = {}): Promise<OcPopupOutcome> {\n const popupOrigin = options.popupOrigin ?? DEFAULT_POPUP_ORIGIN;\n const popupPath = options.popupPath ?? DEFAULT_POPUP_PATH;\n const features = options.features ?? DEFAULT_FEATURES;\n\n return new Promise((resolve) => {\n if (typeof window === 'undefined') {\n resolve({ status: 'failed' });\n return;\n }\n\n const url = new URL(popupPath, popupOrigin);\n url.searchParams.set('opener_origin', window.location.origin);\n const popup = window.open(url.toString(), 'oc-signin', features);\n if (!popup) {\n resolve({ status: 'blocked' });\n return;\n }\n popup.focus();\n\n let settled = false;\n const cleanup = () => {\n window.removeEventListener('message', onMessage);\n clearInterval(closedTimer);\n if (options.signal) options.signal.removeEventListener('abort', onAbort);\n };\n\n function settle(value: OcPopupOutcome) {\n if (settled) return;\n settled = true;\n cleanup();\n try {\n if (popup && !popup.closed) popup.close();\n } catch {\n /* popup may have closed itself first */\n }\n resolve(value);\n }\n\n function onMessage(event: MessageEvent) {\n // Origin pinning is necessary but not sufficient — same-origin\n // pages other than our popup can post the same shape. Pin both\n // origin AND source window so only the popup we opened can\n // settle this promise.\n if (event.origin !== popupOrigin) return;\n if (event.source !== popup) return;\n const data = event.data as\n | { type?: string; account?: OcPopupAccount; token?: string }\n | null;\n if (!data || data.type !== 'oc-signin-success') return;\n if (!data.account || !data.token) {\n settle({ status: 'failed' });\n return;\n }\n settle({ status: 'signed_in', account: data.account, token: data.token });\n }\n\n function onAbort() {\n settle({ status: 'aborted' });\n }\n\n window.addEventListener('message', onMessage);\n if (options.signal) {\n if (options.signal.aborted) {\n settle({ status: 'aborted' });\n return;\n }\n options.signal.addEventListener('abort', onAbort);\n }\n\n // Detect the person closing the popup without completing signin.\n const closedTimer = setInterval(() => {\n if (popup && popup.closed) settle({ status: 'closed' });\n }, 500);\n });\n}\n\n/**\n * Open the OC signin popup and resolve with the session result. Returns\n * `null` if the user closed the popup without completing signin, if the\n * browser blocked it, or if the AbortSignal fired. To tell those apart,\n * use signInWithOcOutcome.\n *\n * MUST be called inside a user-gesture handler (e.g. a button onClick).\n * Browsers block `window.open` outside of user gestures.\n */\nexport async function signInWithOc(options: SignInWithOcOptions = {}): Promise<OcPopupResult | null> {\n const outcome = await signInWithOcOutcome(options);\n return outcome.status === 'signed_in' ? { account: outcome.account, token: outcome.token } : null;\n}\n"]}
1
+ {"version":3,"sources":["../src/popup.ts"],"names":[],"mappings":";;;AAmCA,IAAM,oBAAA,GAAuB,oBAAA;AAC7B,IAAM,kBAAA,GAAqB,eAAA;AAC3B,IAAM,gBAAA,GAAmB,mDAAA;AA2ElB,SAAS,mBAAA,CAAoB,OAAA,GAA+B,EAAC,EAA4B;AAC5F,EAAA,MAAM,WAAA,GAAc,QAAQ,WAAA,IAAe,oBAAA;AAC3C,EAAA,MAAM,SAAA,GAAY,QAAQ,SAAA,IAAa,kBAAA;AACvC,EAAA,MAAM,QAAA,GAAW,QAAQ,QAAA,IAAY,gBAAA;AAErC,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,KAAY;AAC5B,IAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AAC/B,MAAA,OAAA,CAAQ,EAAE,MAAA,EAAQ,QAAA,EAAU,CAAA;AAC5B,MAAA;AAAA,IACJ;AAEA,IAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,SAAA,EAAW,WAAW,CAAA;AAC1C,IAAA,GAAA,CAAI,YAAA,CAAa,GAAA,CAAI,eAAA,EAAiB,MAAA,CAAO,SAAS,MAAM,CAAA;AAC5D,IAAA,MAAM,QAAQ,MAAA,CAAO,IAAA,CAAK,IAAI,QAAA,EAAS,EAAG,aAAa,QAAQ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AS,KAAA,EAAO,IAAA,CAAK,KAAA,EAAO,CAAA;AAAA,IAC5E;AAEA,IAAA,SAAS,OAAA,GAAU;AACf,MAAA,MAAA,CAAO,EAAE,MAAA,EAAQ,SAAA,EAAW,CAAA;AAAA,IAChC;AAEA,IAAA,MAAA,CAAO,gBAAA,CAAiB,WAAW,SAAS,CAAA;AAC5C,IAAA,IAAI,QAAQ,MAAA,EAAQ;AAChB,MAAA,IAAI,OAAA,CAAQ,OAAO,OAAA,EAAS;AACxB,QAAA,MAAA,CAAO,EAAE,MAAA,EAAQ,SAAA,EAAW,CAAA;AAC5B,QAAA;AAAA,MACJ;AACA,MAAA,OAAA,CAAQ,MAAA,CAAO,gBAAA,CAAiB,OAAA,EAAS,OAAO,CAAA;AAAA,IACpD;AAGA,IAAA,MAAM,WAAA,GAAc,YAAY,MAAM;AAClC,MAAA,IAAI,SAAS,KAAA,CAAM,MAAA,SAAe,EAAE,MAAA,EAAQ,UAAU,CAAA;AAAA,IAC1D,GAAG,GAAG,CAAA;AAAA,EACV,CAAC,CAAA;AACL;AAWA,eAAsB,YAAA,CAAa,OAAA,GAA+B,EAAC,EAAkC;AACjG,EAAA,MAAM,OAAA,GAAU,MAAM,mBAAA,CAAoB,OAAO,CAAA;AACjD,EAAA,OAAO,OAAA,CAAQ,MAAA,KAAW,WAAA,GAAc,EAAE,OAAA,EAAS,QAAQ,OAAA,EAAS,KAAA,EAAO,OAAA,CAAQ,KAAA,EAAM,GAAI,IAAA;AACjG","file":"popup.js","sourcesContent":["/**\n * Browser only: `signInWithOc` opens the orangecheck sign-in popup and resolves\n * with a token bound to your origin; `signInWithOcOutcome` says why when it\n * does not. Verify the token on your server with\n * [`@orangecheck/me-client/server`](/sdk/me-client/server/README).\n *\n * @packageDocumentation\n */\n\n/**\n * @orangecheck/me-client/popup\n *\n * Browser-side helper that opens the OC sign-in popup, listens for the\n * postMessage from me.ochk.io, and resolves with the verified session.\n *\n * import { signInWithOc } from '@orangecheck/me-client/popup';\n *\n * document.querySelector('#oc-signin')!.addEventListener('click', async () => {\n * const result = await signInWithOc();\n * if (!result) return;\n * // Your server verifies it and keeps it in an httpOnly cookie.\n * const r = await fetch('/api/auth/session', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ token: result.token }),\n * });\n * if (r.ok) location.assign('/app');\n * });\n *\n * Why this lives in a separate entry point: it's browser-only (uses\n * window.open / addEventListener) and integrators that only need the\n * server-side verifier shouldn't pull popup orchestration into their\n * server bundle.\n */\n\nconst DEFAULT_POPUP_ORIGIN = 'https://me.ochk.io';\nconst DEFAULT_POPUP_PATH = '/popup/signin';\nconst DEFAULT_FEATURES = 'width=480,height=720,resizable=yes,scrollbars=yes';\n\nexport interface OcPopupAccount {\n id?: string;\n /** Opaque public identity · `did:oc:<32-hex>`. Stable across linking\n * events. The canonical identifier post auth-refactor (Dec 2025\n * +). */\n did_oc?: string;\n /** Primary linked Bitcoin address, if the user has one and is\n * surfacing it (same-origin family integrators get it inline;\n * cross-domain integrators need the bitcoin_address scope). */\n primary_btc?: string | null;\n /** Whether the user has a primary email linked (plaintext stays\n * on auth host; only the boolean reaches integrators). */\n has_email?: boolean;\n /** Legacy fields kept for back-compat with pre-refactor consumers.\n * Prefer did_oc + primary_btc. Removed in a future major. */\n address?: string;\n btc_address?: string;\n display_name?: string | null;\n nostr_npub?: string | null;\n wallet_provisioned?: boolean;\n email?: string;\n}\n\nexport interface OcPopupResult {\n /** Account payload from the auth host, unsigned: trust only the\n * verified token. `did_oc` is the account's opaque identifier, the\n * same at every site; the email and Bitcoin address stay private\n * unless the user grants a scope. */\n account: OcPopupAccount;\n /** The session JWT, bound to your origin. Hand it once to your own\n * server, which verifies it and keeps it in an httpOnly cookie; never\n * in localStorage, where any script on the page can read it. Family\n * sites (*.ochk.io) can ignore it: the Domain=.ochk.io cookie rides\n * home on its own. */\n token: string;\n}\n\nexport interface SignInWithOcOptions {\n /** Origin of the OC popup page. Defaults to https://me.ochk.io.\n * Override only for staging / preview environments. */\n popupOrigin?: string;\n /** Path on the popup origin. Defaults to /popup/signin. */\n popupPath?: string;\n /** window.open features string. Defaults to a 480x720 resizable\n * popup with scrollbars. */\n features?: string;\n /** AbortSignal that cancels the wait and closes the popup. */\n signal?: AbortSignal;\n}\n\n/**\n * How a sign-in popup ended:\n * - `signed_in` · the person signed in; `account` and `token` as from signInWithOc.\n * - `blocked` · the browser refused to open the window. Ask the person to\n * allow pop-ups for your site, then try again from a click.\n * - `closed` · the person closed the window without signing in.\n * - `aborted` · your AbortSignal fired.\n * - `failed` · not in a browser, or the popup's answer was malformed.\n */\nexport type OcPopupOutcome =\n | ({ status: 'signed_in' } & OcPopupResult)\n | { status: 'blocked' }\n | { status: 'closed' }\n | { status: 'aborted' }\n | { status: 'failed' };\n\n/**\n * Open the OC signin popup and resolve with how it ended (OcPopupOutcome),\n * so a blocked window and a closed one can be told apart.\n *\n * MUST be called inside a user-gesture handler (e.g. a button onClick).\n * Browsers block `window.open` outside of user gestures.\n */\nexport function signInWithOcOutcome(options: SignInWithOcOptions = {}): Promise<OcPopupOutcome> {\n const popupOrigin = options.popupOrigin ?? DEFAULT_POPUP_ORIGIN;\n const popupPath = options.popupPath ?? DEFAULT_POPUP_PATH;\n const features = options.features ?? DEFAULT_FEATURES;\n\n return new Promise((resolve) => {\n if (typeof window === 'undefined') {\n resolve({ status: 'failed' });\n return;\n }\n\n const url = new URL(popupPath, popupOrigin);\n url.searchParams.set('opener_origin', window.location.origin);\n const popup = window.open(url.toString(), 'oc-signin', features);\n if (!popup) {\n resolve({ status: 'blocked' });\n return;\n }\n popup.focus();\n\n let settled = false;\n const cleanup = () => {\n window.removeEventListener('message', onMessage);\n clearInterval(closedTimer);\n if (options.signal) options.signal.removeEventListener('abort', onAbort);\n };\n\n function settle(value: OcPopupOutcome) {\n if (settled) return;\n settled = true;\n cleanup();\n try {\n if (popup && !popup.closed) popup.close();\n } catch {\n /* popup may have closed itself first */\n }\n resolve(value);\n }\n\n function onMessage(event: MessageEvent) {\n // Origin pinning is necessary but not sufficient — same-origin\n // pages other than our popup can post the same shape. Pin both\n // origin AND source window so only the popup we opened can\n // settle this promise.\n if (event.origin !== popupOrigin) return;\n if (event.source !== popup) return;\n const data = event.data as\n | { type?: string; account?: OcPopupAccount; token?: string }\n | null;\n if (!data || data.type !== 'oc-signin-success') return;\n if (!data.account || !data.token) {\n settle({ status: 'failed' });\n return;\n }\n settle({ status: 'signed_in', account: data.account, token: data.token });\n }\n\n function onAbort() {\n settle({ status: 'aborted' });\n }\n\n window.addEventListener('message', onMessage);\n if (options.signal) {\n if (options.signal.aborted) {\n settle({ status: 'aborted' });\n return;\n }\n options.signal.addEventListener('abort', onAbort);\n }\n\n // Detect the person closing the popup without completing signin.\n const closedTimer = setInterval(() => {\n if (popup && popup.closed) settle({ status: 'closed' });\n }, 500);\n });\n}\n\n/**\n * Open the OC signin popup and resolve with the session result. Returns\n * `null` if the user closed the popup without completing signin, if the\n * browser blocked it, or if the AbortSignal fired. To tell those apart,\n * use signInWithOcOutcome.\n *\n * MUST be called inside a user-gesture handler (e.g. a button onClick).\n * Browsers block `window.open` outside of user gestures.\n */\nexport async function signInWithOc(options: SignInWithOcOptions = {}): Promise<OcPopupResult | null> {\n const outcome = await signInWithOcOutcome(options);\n return outcome.status === 'signed_in' ? { account: outcome.account, token: outcome.token } : null;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/popup.ts"],"names":[],"mappings":";AA0BA,IAAM,oBAAA,GAAuB,oBAAA;AAC7B,IAAM,kBAAA,GAAqB,eAAA;AAC3B,IAAM,gBAAA,GAAmB,mDAAA;AA2ElB,SAAS,mBAAA,CAAoB,OAAA,GAA+B,EAAC,EAA4B;AAC5F,EAAA,MAAM,WAAA,GAAc,QAAQ,WAAA,IAAe,oBAAA;AAC3C,EAAA,MAAM,SAAA,GAAY,QAAQ,SAAA,IAAa,kBAAA;AACvC,EAAA,MAAM,QAAA,GAAW,QAAQ,QAAA,IAAY,gBA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O,OAAA,CAAQ,MAAA,KAAW,WAAA,GAAc,EAAE,OAAA,EAAS,QAAQ,OAAA,EAAS,KAAA,EAAO,OAAA,CAAQ,KAAA,EAAM,GAAI,IAAA;AACjG","file":"popup.mjs","sourcesContent":["/**\n * @orangecheck/me-client/popup\n *\n * Browser-side helper that opens the OC sign-in popup, listens for the\n * postMessage from me.ochk.io, and resolves with the verified session.\n *\n * import { signInWithOc } from '@orangecheck/me-client/popup';\n *\n * document.querySelector('#oc-signin')!.addEventListener('click', async () => {\n * const result = await signInWithOc();\n * if (!result) return;\n * // Your server verifies it and keeps it in an httpOnly cookie.\n * const r = await fetch('/api/auth/session', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ token: result.token }),\n * });\n * if (r.ok) location.assign('/app');\n * });\n *\n * Why this lives in a separate entry point: it's browser-only (uses\n * window.open / addEventListener) and integrators that only need the\n * server-side verifier shouldn't pull popup orchestration into their\n * server bundle.\n */\n\nconst DEFAULT_POPUP_ORIGIN = 'https://me.ochk.io';\nconst DEFAULT_POPUP_PATH = '/popup/signin';\nconst DEFAULT_FEATURES = 'width=480,height=720,resizable=yes,scrollbars=yes';\n\nexport interface OcPopupAccount {\n id?: string;\n /** Opaque public identity · `did:oc:<32-hex>`. Stable across linking\n * events. The canonical identifier post auth-refactor (Dec 2025\n * +). */\n did_oc?: string;\n /** Primary linked Bitcoin address, if the user has one and is\n * surfacing it (same-origin family integrators get it inline;\n * cross-domain integrators need the bitcoin_address scope). */\n primary_btc?: string | null;\n /** Whether the user has a primary email linked (plaintext stays\n * on auth host; only the boolean reaches integrators). */\n has_email?: boolean;\n /** Legacy fields kept for back-compat with pre-refactor consumers.\n * Prefer did_oc + primary_btc. Removed in a future major. */\n address?: string;\n btc_address?: string;\n display_name?: string | null;\n nostr_npub?: string | null;\n wallet_provisioned?: boolean;\n email?: string;\n}\n\nexport interface OcPopupResult {\n /** Account payload from the auth host, unsigned: trust only the\n * verified token. `did_oc` is the account's opaque identifier, the\n * same at every site; the email and Bitcoin address stay private\n * unless the user grants a scope. */\n account: OcPopupAccount;\n /** The session JWT, bound to your origin. Hand it once to your own\n * server, which verifies it and keeps it in an httpOnly cookie; never\n * in localStorage, where any script on the page can read it. Family\n * sites (*.ochk.io) can ignore it: the Domain=.ochk.io cookie rides\n * home on its own. */\n token: string;\n}\n\nexport interface SignInWithOcOptions {\n /** Origin of the OC popup page. Defaults to https://me.ochk.io.\n * Override only for staging / preview environments. */\n popupOrigin?: string;\n /** Path on the popup origin. Defaults to /popup/signin. */\n popupPath?: string;\n /** window.open features string. Defaults to a 480x720 resizable\n * popup with scrollbars. */\n features?: string;\n /** AbortSignal that cancels the wait and closes the popup. */\n signal?: AbortSignal;\n}\n\n/**\n * How a sign-in popup ended:\n * - `signed_in` · the person signed in; `account` and `token` as from signInWithOc.\n * - `blocked` · the browser refused to open the window. Ask the person to\n * allow pop-ups for your site, then try again from a click.\n * - `closed` · the person closed the window without signing in.\n * - `aborted` · your AbortSignal fired.\n * - `failed` · not in a browser, or the popup's answer was malformed.\n */\nexport type OcPopupOutcome =\n | ({ status: 'signed_in' } & OcPopupResult)\n | { status: 'blocked' }\n | { status: 'closed' }\n | { status: 'aborted' }\n | { status: 'failed' };\n\n/**\n * Open the OC signin popup and resolve with how it ended (OcPopupOutcome),\n * so a blocked window and a closed one can be told apart.\n *\n * MUST be called inside a user-gesture handler (e.g. a button onClick).\n * Browsers block `window.open` outside of user gestures.\n */\nexport function signInWithOcOutcome(options: SignInWithOcOptions = {}): Promise<OcPopupOutcome> {\n const popupOrigin = options.popupOrigin ?? DEFAULT_POPUP_ORIGIN;\n const popupPath = options.popupPath ?? DEFAULT_POPUP_PATH;\n const features = options.features ?? DEFAULT_FEATURES;\n\n return new Promise((resolve) => {\n if (typeof window === 'undefined') {\n resolve({ status: 'failed' });\n return;\n }\n\n const url = new URL(popupPath, popupOrigin);\n url.searchParams.set('opener_origin', window.location.origin);\n const popup = window.open(url.toString(), 'oc-signin', features);\n if (!popup) {\n resolve({ status: 'blocked' });\n return;\n }\n popup.focus();\n\n let settled = false;\n const cleanup = () => {\n window.removeEventListener('message', onMessage);\n clearInterval(closedTimer);\n if (options.signal) options.signal.removeEventListener('abort', onAbort);\n };\n\n function settle(value: OcPopupOutcome) {\n if (settled) return;\n settled = true;\n cleanup();\n try {\n if (popup && !popup.closed) popup.close();\n } catch {\n /* popup may have closed itself first */\n }\n resolve(value);\n }\n\n function onMessage(event: MessageEvent) {\n // Origin pinning is necessary but not sufficient — same-origin\n // pages other than our popup can post the same shape. Pin both\n // origin AND source window so only the popup we opened can\n // settle this promise.\n if (event.origin !== popupOrigin) return;\n if (event.source !== popup) return;\n const data = event.data as\n | { type?: string; account?: OcPopupAccount; token?: string }\n | null;\n if (!data || data.type !== 'oc-signin-success') return;\n if (!data.account || !data.token) {\n settle({ status: 'failed' });\n return;\n }\n settle({ status: 'signed_in', account: data.account, token: data.token });\n }\n\n function onAbort() {\n settle({ status: 'aborted' });\n }\n\n window.addEventListener('message', onMessage);\n if (options.signal) {\n if (options.signal.aborted) {\n settle({ status: 'aborted' });\n return;\n }\n options.signal.addEventListener('abort', onAbort);\n }\n\n // Detect the person closing the popup without completing signin.\n const closedTimer = setInterval(() => {\n if (popup && popup.closed) settle({ status: 'closed' });\n }, 500);\n });\n}\n\n/**\n * Open the OC signin popup and resolve with the session result. Returns\n * `null` if the user closed the popup without completing signin, if the\n * browser blocked it, or if the AbortSignal fired. To tell those apart,\n * use signInWithOcOutcome.\n *\n * MUST be called inside a user-gesture handler (e.g. a button onClick).\n * Browsers block `window.open` outside of user gestures.\n */\nexport async function signInWithOc(options: SignInWithOcOptions = {}): Promise<OcPopupResult | null> {\n const outcome = await signInWithOcOutcome(options);\n return outcome.status === 'signed_in' ? { account: outcome.account, token: outcome.token } : null;\n}\n"]}
1
+ {"version":3,"sources":["../src/popup.ts"],"names":[],"mappings":";AAmCA,IAAM,oBAAA,GAAuB,oBAAA;AAC7B,IAAM,kBAAA,G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M;AAClC,MAAA,IAAI,SAAS,KAAA,CAAM,MAAA,SAAe,EAAE,MAAA,EAAQ,UAAU,CAAA;AAAA,IAC1D,GAAG,GAAG,CAAA;AAAA,EACV,CAAC,CAAA;AACL;AAWA,eAAsB,YAAA,CAAa,OAAA,GAA+B,EAAC,EAAkC;AACjG,EAAA,MAAM,OAAA,GAAU,MAAM,mBAAA,CAAoB,OAAO,CAAA;AACjD,EAAA,OAAO,OAAA,CAAQ,MAAA,KAAW,WAAA,GAAc,EAAE,OAAA,EAAS,QAAQ,OAAA,EAAS,KAAA,EAAO,OAAA,CAAQ,KAAA,EAAM,GAAI,IAAA;AACjG","file":"popup.mjs","sourcesContent":["/**\n * Browser only: `signInWithOc` opens the orangecheck sign-in popup and resolves\n * with a token bound to your origin; `signInWithOcOutcome` says why when it\n * does not. Verify the token on your server with\n * [`@orangecheck/me-client/server`](/sdk/me-client/server/README).\n *\n * @packageDocumentation\n */\n\n/**\n * @orangecheck/me-client/popup\n *\n * Browser-side helper that opens the OC sign-in popup, listens for the\n * postMessage from me.ochk.io, and resolves with the verified session.\n *\n * import { signInWithOc } from '@orangecheck/me-client/popup';\n *\n * document.querySelector('#oc-signin')!.addEventListener('click', async () => {\n * const result = await signInWithOc();\n * if (!result) return;\n * // Your server verifies it and keeps it in an httpOnly cookie.\n * const r = await fetch('/api/auth/session', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ token: result.token }),\n * });\n * if (r.ok) location.assign('/app');\n * });\n *\n * Why this lives in a separate entry point: it's browser-only (uses\n * window.open / addEventListener) and integrators that only need the\n * server-side verifier shouldn't pull popup orchestration into their\n * server bundle.\n */\n\nconst DEFAULT_POPUP_ORIGIN = 'https://me.ochk.io';\nconst DEFAULT_POPUP_PATH = '/popup/signin';\nconst DEFAULT_FEATURES = 'width=480,height=720,resizable=yes,scrollbars=yes';\n\nexport interface OcPopupAccount {\n id?: string;\n /** Opaque public identity · `did:oc:<32-hex>`. Stable across linking\n * events. The canonical identifier post auth-refactor (Dec 2025\n * +). */\n did_oc?: string;\n /** Primary linked Bitcoin address, if the user has one and is\n * surfacing it (same-origin family integrators get it inline;\n * cross-domain integrators need the bitcoin_address scope). */\n primary_btc?: string | null;\n /** Whether the user has a primary email linked (plaintext stays\n * on auth host; only the boolean reaches integrators). */\n has_email?: boolean;\n /** Legacy fields kept for back-compat with pre-refactor consumers.\n * Prefer did_oc + primary_btc. Removed in a future major. */\n address?: string;\n btc_address?: string;\n display_name?: string | null;\n nostr_npub?: string | null;\n wallet_provisioned?: boolean;\n email?: string;\n}\n\nexport interface OcPopupResult {\n /** Account payload from the auth host, unsigned: trust only the\n * verified token. `did_oc` is the account's opaque identifier, the\n * same at every site; the email and Bitcoin address stay private\n * unless the user grants a scope. */\n account: OcPopupAccount;\n /** The session JWT, bound to your origin. Hand it once to your own\n * server, which verifies it and keeps it in an httpOnly cookie; never\n * in localStorage, where any script on the page can read it. Family\n * sites (*.ochk.io) can ignore it: the Domain=.ochk.io cookie rides\n * home on its own. */\n token: string;\n}\n\nexport interface SignInWithOcOptions {\n /** Origin of the OC popup page. Defaults to https://me.ochk.io.\n * Override only for staging / preview environments. */\n popupOrigin?: string;\n /** Path on the popup origin. Defaults to /popup/signin. */\n popupPath?: string;\n /** window.open features string. Defaults to a 480x720 resizable\n * popup with scrollbars. */\n features?: string;\n /** AbortSignal that cancels the wait and closes the popup. */\n signal?: AbortSignal;\n}\n\n/**\n * How a sign-in popup ended:\n * - `signed_in` · the person signed in; `account` and `token` as from signInWithOc.\n * - `blocked` · the browser refused to open the window. Ask the person to\n * allow pop-ups for your site, then try again from a click.\n * - `closed` · the person closed the window without signing in.\n * - `aborted` · your AbortSignal fired.\n * - `failed` · not in a browser, or the popup's answer was malformed.\n */\nexport type OcPopupOutcome =\n | ({ status: 'signed_in' } & OcPopupResult)\n | { status: 'blocked' }\n | { status: 'closed' }\n | { status: 'aborted' }\n | { status: 'failed' };\n\n/**\n * Open the OC signin popup and resolve with how it ended (OcPopupOutcome),\n * so a blocked window and a closed one can be told apart.\n *\n * MUST be called inside a user-gesture handler (e.g. a button onClick).\n * Browsers block `window.open` outside of user gestures.\n */\nexport function signInWithOcOutcome(options: SignInWithOcOptions = {}): Promise<OcPopupOutcome> {\n const popupOrigin = options.popupOrigin ?? DEFAULT_POPUP_ORIGIN;\n const popupPath = options.popupPath ?? DEFAULT_POPUP_PATH;\n const features = options.features ?? DEFAULT_FEATURES;\n\n return new Promise((resolve) => {\n if (typeof window === 'undefined') {\n resolve({ status: 'failed' });\n return;\n }\n\n const url = new URL(popupPath, popupOrigin);\n url.searchParams.set('opener_origin', window.location.origin);\n const popup = window.open(url.toString(), 'oc-signin', features);\n if (!popup) {\n resolve({ status: 'blocked' });\n return;\n }\n popup.focus();\n\n let settled = false;\n const cleanup = () => {\n window.removeEventListener('message', onMessage);\n clearInterval(closedTimer);\n if (options.signal) options.signal.removeEventListener('abort', onAbort);\n };\n\n function settle(value: OcPopupOutcome) {\n if (settled) return;\n settled = true;\n cleanup();\n try {\n if (popup && !popup.closed) popup.close();\n } catch {\n /* popup may have closed itself first */\n }\n resolve(value);\n }\n\n function onMessage(event: MessageEvent) {\n // Origin pinning is necessary but not sufficient — same-origin\n // pages other than our popup can post the same shape. Pin both\n // origin AND source window so only the popup we opened can\n // settle this promise.\n if (event.origin !== popupOrigin) return;\n if (event.source !== popup) return;\n const data = event.data as\n | { type?: string; account?: OcPopupAccount; token?: string }\n | null;\n if (!data || data.type !== 'oc-signin-success') return;\n if (!data.account || !data.token) {\n settle({ status: 'failed' });\n return;\n }\n settle({ status: 'signed_in', account: data.account, token: data.token });\n }\n\n function onAbort() {\n settle({ status: 'aborted' });\n }\n\n window.addEventListener('message', onMessage);\n if (options.signal) {\n if (options.signal.aborted) {\n settle({ status: 'aborted' });\n return;\n }\n options.signal.addEventListener('abort', onAbort);\n }\n\n // Detect the person closing the popup without completing signin.\n const closedTimer = setInterval(() => {\n if (popup && popup.closed) settle({ status: 'closed' });\n }, 500);\n });\n}\n\n/**\n * Open the OC signin popup and resolve with the session result. Returns\n * `null` if the user closed the popup without completing signin, if the\n * browser blocked it, or if the AbortSignal fired. To tell those apart,\n * use signInWithOcOutcome.\n *\n * MUST be called inside a user-gesture handler (e.g. a button onClick).\n * Browsers block `window.open` outside of user gestures.\n */\nexport async function signInWithOc(options: SignInWithOcOptions = {}): Promise<OcPopupResult | null> {\n const outcome = await signInWithOcOutcome(options);\n return outcome.status === 'signed_in' ? { account: outcome.account, token: outcome.token } : null;\n}\n"]}
package/dist/server.d.mts CHANGED
@@ -67,6 +67,17 @@ interface VerifyOcTokenOptions extends VerifyOcOptions {
67
67
  requireHandle?: boolean;
68
68
  }
69
69
  declare function verifyOcToken(token: string, options?: VerifyOcTokenOptions): Promise<SessionPayload | null>;
70
+ type OcTokenCheck = {
71
+ status: 'valid';
72
+ session: SessionPayload;
73
+ } | {
74
+ status: 'invalid';
75
+ reason?: OcSessionRefusal;
76
+ } | {
77
+ status: 'unavailable';
78
+ reason: 'key_set_unavailable';
79
+ };
80
+ declare function checkOcToken(token: string, options?: VerifyOcTokenOptions): Promise<OcTokenCheck>;
70
81
 
71
82
  interface OcSessionOptions extends VerifyOcTokenOptions {
72
83
  method?: string;
@@ -158,4 +169,4 @@ interface HonoContextLike {
158
169
  type HonoNextLike = () => Promise<void>;
159
170
  declare function ocAuthHono(options?: WithOcAuthOptions): (c: HonoContextLike, next: HonoNextLike) => Promise<unknown>;
160
171
 
161
- export { BACK_ACCOUNT_URL, type ConnectClaimLinkRefusal, type ConnectClaimLinkResult, type ConnectDeleteRefusal, type ConnectDeleteResult, type ConnectOptions, type ConnectProvisionOptions, type ConnectProvisionRefusal, type ConnectProvisionResult, type ConnectRefused, type JtiStore, MemoryJtiStore, type OcHonoEnv, type OcSessionCheck, type OcSessionOptions, type OcSessionRefusal, type OcSessionUnavailable, type RevokeTokenOptions, type RevokeTokenRefusal, type RevokeTokenResult, type VerifyOcTokenOptions, type WithOcAuthOptions, type WithOcSession, _resetSessionChecksForTests, checkOcSession, connectClaimLink, connectDelete, connectProvision, getOcSession, ocAuthExpress, ocAuthHono, revokeToken, spendOnce, verifyOcToken, withOcAuth };
172
+ export { BACK_ACCOUNT_URL, type ConnectClaimLinkRefusal, type ConnectClaimLinkResult, type ConnectDeleteRefusal, type ConnectDeleteResult, type ConnectOptions, type ConnectProvisionOptions, type ConnectProvisionRefusal, type ConnectProvisionResult, type ConnectRefused, type JtiStore, MemoryJtiStore, type OcHonoEnv, type OcSessionCheck, type OcSessionOptions, type OcSessionRefusal, type OcSessionUnavailable, type OcTokenCheck, type RevokeTokenOptions, type RevokeTokenRefusal, type RevokeTokenResult, type VerifyOcTokenOptions, type WithOcAuthOptions, type WithOcSession, _resetSessionChecksForTests, checkOcSession, checkOcToken, connectClaimLink, connectDelete, connectProvision, getOcSession, ocAuthExpress, ocAuthHono, revokeToken, spendOnce, verifyOcToken, withOcAuth };
package/dist/server.d.ts CHANGED
@@ -67,6 +67,17 @@ interface VerifyOcTokenOptions extends VerifyOcOptions {
67
67
  requireHandle?: boolean;
68
68
  }
69
69
  declare function verifyOcToken(token: string, options?: VerifyOcTokenOptions): Promise<SessionPayload | null>;
70
+ type OcTokenCheck = {
71
+ status: 'valid';
72
+ session: SessionPayload;
73
+ } | {
74
+ status: 'invalid';
75
+ reason?: OcSessionRefusal;
76
+ } | {
77
+ status: 'unavailable';
78
+ reason: 'key_set_unavailable';
79
+ };
80
+ declare function checkOcToken(token: string, options?: VerifyOcTokenOptions): Promise<OcTokenCheck>;
70
81
 
71
82
  interface OcSessionOptions extends VerifyOcTokenOptions {
72
83
  method?: string;
@@ -158,4 +169,4 @@ interface HonoContextLike {
158
169
  type HonoNextLike = () => Promise<void>;
159
170
  declare function ocAuthHono(options?: WithOcAuthOptions): (c: HonoContextLike, next: HonoNextLike) => Promise<unknown>;
160
171
 
161
- export { BACK_ACCOUNT_URL, type ConnectClaimLinkRefusal, type ConnectClaimLinkResult, type ConnectDeleteRefusal, type ConnectDeleteResult, type ConnectOptions, type ConnectProvisionOptions, type ConnectProvisionRefusal, type ConnectProvisionResult, type ConnectRefused, type JtiStore, MemoryJtiStore, type OcHonoEnv, type OcSessionCheck, type OcSessionOptions, type OcSessionRefusal, type OcSessionUnavailable, type RevokeTokenOptions, type RevokeTokenRefusal, type RevokeTokenResult, type VerifyOcTokenOptions, type WithOcAuthOptions, type WithOcSession, _resetSessionChecksForTests, checkOcSession, connectClaimLink, connectDelete, connectProvision, getOcSession, ocAuthExpress, ocAuthHono, revokeToken, spendOnce, verifyOcToken, withOcAuth };
172
+ export { BACK_ACCOUNT_URL, type ConnectClaimLinkRefusal, type ConnectClaimLinkResult, type ConnectDeleteRefusal, type ConnectDeleteResult, type ConnectOptions, type ConnectProvisionOptions, type ConnectProvisionRefusal, type ConnectProvisionResult, type ConnectRefused, type JtiStore, MemoryJtiStore, type OcHonoEnv, type OcSessionCheck, type OcSessionOptions, type OcSessionRefusal, type OcSessionUnavailable, type OcTokenCheck, type RevokeTokenOptions, type RevokeTokenRefusal, type RevokeTokenResult, type VerifyOcTokenOptions, type WithOcAuthOptions, type WithOcSession, _resetSessionChecksForTests, checkOcSession, checkOcToken, connectClaimLink, connectDelete, connectProvision, getOcSession, ocAuthExpress, ocAuthHono, revokeToken, spendOnce, verifyOcToken, withOcAuth };
package/dist/server.js CHANGED
@@ -871,6 +871,21 @@ async function verifyOcToken(token, options = {}) {
871
871
  }
872
872
  return session;
873
873
  }
874
+ async function checkOcToken(token, options = {}) {
875
+ if (options === null || typeof options !== "object") {
876
+ throw new TypeError("@orangecheck/me-client: options must be an object");
877
+ }
878
+ const { requireHandle, ...core } = options;
879
+ checkRequireHandle(requireHandle);
880
+ const checked = await authCore.checkOcToken(token, core);
881
+ if (checked.status === "unavailable") return { status: "unavailable", reason: "key_set_unavailable" };
882
+ if (checked.status === "invalid") return { status: "invalid" };
883
+ if (lacksHandle(checked.session, requireHandle)) {
884
+ warnNoHandle(checked.session);
885
+ return { status: "invalid", reason: "no_session_handle" };
886
+ }
887
+ return { status: "valid", session: checked.session };
888
+ }
874
889
  var sessionChecks = /* @__PURE__ */ new Map();
875
890
  var warnedUnchecked = false;
876
891
  function revocationFor(options) {
@@ -1176,6 +1191,7 @@ exports.CONNECT_CONSENT_LABEL = CONNECT_CONSENT_LABEL;
1176
1191
  exports.MemoryJtiStore = MemoryJtiStore;
1177
1192
  exports._resetSessionChecksForTests = _resetSessionChecksForTests;
1178
1193
  exports.checkOcSession = checkOcSession;
1194
+ exports.checkOcToken = checkOcToken;
1179
1195
  exports.connectClaimLink = connectClaimLink;
1180
1196
  exports.connectDelete = connectDelete;
1181
1197
  exports.connectProvision = connectProvision;