{"version":3,"file":"passkeys-BDJozKyA-sec20261128.js","names":["FIRST_SESSION_WINDOW_MS","shouldOfferPasskey","input","userCreatedAt","Date","sessionCreatedAt","passkeyCount","dismissed","gap","getTime","Number","isFinite","passkeyOfferDismissedKey","userId","hostMatchesPasskeyRpId","host","rpId","normalized","toLowerCase","rp","endsWith","__iconData","AuthCapabilities","authCapabilitiesSchema","legacyAuthCapabilitiesSchema","ResponseBodyTooLargeError","readBoundedJsonResponse","TIMEOUT_MS","MAX_RESPONSE_BYTES","capabilitiesRequest","Promise","fetchAuthCapabilities","loadAuthCapabilities","then","capabilities","sso","availability","undefined","error","controller","AbortController","timer","setTimeout","abort","response","fetch","signal","ok","Error","length","Number","headers","get","NaN","body","type","has","isSafeInteger","bytes","arrayBuffer","byteLength","JSON","parse","TextDecoder","decode","or","clearTimeout","i18n","_i18n","hostMatchesPasskeyRpId","WebAuthnAbortService","useEffect","useState","useSyncExternalStore","RakazoDesktop","desktopBridge","authErrorText","fetchAuthCapabilities","PasskeyBrowser","host","credential","isUserVerifyingPlatformAuthenticatorAvailable","Promise","desktop","Pick","currentBrowser","window","location","hostname","PublicKeyCredential","undefined","systemPasskeysDesktop","platform","desktopAssociated","rpId","passkeys","rpIds","includes","toLowerCase","passkeysSupported","browser","usePasskeysSupported","supported","setSupported","active","then","capabilities","passkeyRpId","value","catch","passkeysVersion","passkeyListeners","Set","passkeysChanged","listener","usePasskeysVersion","add","delete","cancelPasskeyRequest","cancelCeremony","conditionalPasskeyAvailable","isConditionalMediationAvailable","CANCELLED_CODES","passkeyErrorText","error","fallback","code","has","_","id","startsWith","useState","useSyncExternalStore","_i18n","__toESM","authCapabilitiesSchema","legacyAuthCapabilitiesSchema","i18n","WebAuthnAbortService","createLucideIcon","authErrorText","desktopBridge","require_react","ResponseBodyTooLargeError","readBoundedJsonResponse","FIRST_SESSION_WINDOW_MS","shouldOfferPasskey","input","gap","passkeyOfferDismissedKey","userId","hostMatchesPasskeyRpId","rpId","normalized","host","rp","__iconData$1","KeyRound","__iconData","Mail","import_react","TIMEOUT_MS","MAX_RESPONSE_BYTES","capabilitiesRequest","fetchAuthCapabilities","loadAuthCapabilities","capabilities","error","controller","timer","response","length","body","bytes","currentBrowser","systemPasskeysDesktop","desktop","desktopAssociated","passkeysSupported","browser","usePasskeysSupported","supported","setSupported","active","value","passkeysVersion","passkeyListeners","passkeysChanged","listener","usePasskeysVersion","cancelPasskeyRequest","conditionalPasskeyAvailable","CANCELLED_CODES","passkeyErrorText","code","fallback"],"sources":["../../../../packages/core/src/account/passkey-offer.ts","../../../../node_modules/.pnpm/lucide-react@1.70.0_@types+react@19.3.0_react@19.3.1/node_modules/lucide-react/dist/esm/icons/key-round.mjs","../../../../node_modules/.pnpm/lucide-react@1.70.0_@types+react@19.3.0_react@19.3.1/node_modules/lucide-react/dist/esm/icons/mail.mjs","../../src/lib/auth/auth-capabilities.ts","../../src/lib/auth/passkeys.ts"],"sourcesContent":["/** A session opened this soon after the account was created is its first one. */\nconst FIRST_SESSION_WINDOW_MS = 60 * 60_000;\n\n/**\n * Whether to offer adding a passkey once, right after signup: the first\n * session of a new account that has no passkey and has not dismissed the offer.\n */\nexport function shouldOfferPasskey(input: {\n  userCreatedAt: Date | string;\n  sessionCreatedAt: Date | string;\n  passkeyCount: number;\n  dismissed: boolean;\n}): boolean {\n  if (input.dismissed || input.passkeyCount > 0) return false;\n  const gap = new Date(input.sessionCreatedAt).getTime() - new Date(input.userCreatedAt).getTime();\n  return Number.isFinite(gap) && gap >= 0 && gap < FIRST_SESSION_WINDOW_MS;\n}\n\n/** Storage key that remembers a dismissed offer for one account on this device. */\nexport function passkeyOfferDismissedKey(userId: string): string {\n  return `rakazo.passkey-offer-dismissed.${userId}`;\n}\n\n/** WebAuthn requires the page host to equal the relying party ID or be a subdomain of it. */\nexport function hostMatchesPasskeyRpId(host: string, rpId: string | null | undefined): boolean {\n  if (!rpId) return false;\n  const normalized = host.toLowerCase();\n  const rp = rpId.toLowerCase();\n  return normalized === rp || normalized.endsWith(`.${rp}`);\n}\n","/**\n * @license lucide-react v1.70.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.mjs';\n\nconst __iconData = {\n  name: \"key-round\",\n  size: 24,\n  node: [\n    [\n      \"path\",\n      {\n        d: \"M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z\",\n        key: \"1s6t7t\"\n      }\n    ],\n    [\"circle\", { cx: \"16.5\", cy: \"7.5\", r: \".5\", fill: \"currentColor\", key: \"w0ekpg\" }]\n  ]\n};\n__iconData.node;\nconst KeyRound = createLucideIcon(__iconData);\n\nexport { __iconData, KeyRound as default };\n//# sourceMappingURL=key-round.mjs.map\n","/**\n * @license lucide-react v1.70.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.mjs';\n\nconst __iconData = {\n  name: \"mail\",\n  size: 24,\n  node: [\n    [\"path\", { d: \"m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7\", key: \"132q7q\" }],\n    [\"rect\", { x: \"2\", y: \"4\", width: \"20\", height: \"16\", rx: \"2\", key: \"izxlao\" }]\n  ]\n};\n__iconData.node;\nconst Mail = createLucideIcon(__iconData);\n\nexport { __iconData, Mail as default };\n//# sourceMappingURL=mail.mjs.map\n","import type { AuthCapabilities } from \"@rakazo/contracts\";\nimport { authCapabilitiesSchema, legacyAuthCapabilitiesSchema } from \"@rakazo/contracts\";\nimport { ResponseBodyTooLargeError, readBoundedJsonResponse } from \"@rakazo/core\";\n\nexport type { AuthCapabilities } from \"@rakazo/contracts\";\n\nconst TIMEOUT_MS = 8_000;\nconst MAX_RESPONSE_BYTES = 64 * 1024;\n\nlet capabilitiesRequest: Promise<AuthCapabilities> | undefined;\n\nexport function fetchAuthCapabilities(): Promise<AuthCapabilities> {\n  // Auth can briefly remount during session refresh; the gate uses the same deployment lookup.\n  capabilitiesRequest ??= loadAuthCapabilities().then(\n    (capabilities) => {\n      if (capabilities.sso && capabilities.sso.availability !== \"available\") {\n        capabilitiesRequest = undefined;\n      }\n      return capabilities;\n    },\n    (error: unknown) => {\n      capabilitiesRequest = undefined;\n      throw error;\n    },\n  );\n  return capabilitiesRequest;\n}\n\n/** Public deployment capabilities, bounded in time and size so a stalled API cannot hang the UI. */\nasync function loadAuthCapabilities(): Promise<AuthCapabilities> {\n  const controller = new AbortController();\n  const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);\n  try {\n    const response = await fetch(\"/api/auth/capabilities\", { signal: controller.signal });\n    if (!response.ok) throw new Error(\"Could not load authentication capabilities\");\n    const length = Number(response.headers.get(\"content-length\") ?? Number.NaN);\n    let body: unknown;\n    if (\n      response.type === \"basic\" &&\n      !response.headers.has(\"content-encoding\") &&\n      Number.isSafeInteger(length) &&\n      length >= 0 &&\n      length <= MAX_RESPONSE_BYTES\n    ) {\n      // For an uncompressed same-origin fetch, HTTP framing bounds the body by Content-Length.\n      // Native consumption avoids Chromium cancelling a completed manually read response stream.\n      const bytes = await response.arrayBuffer();\n      if (bytes.byteLength > MAX_RESPONSE_BYTES) {\n        throw new ResponseBodyTooLargeError(MAX_RESPONSE_BYTES);\n      }\n      body = JSON.parse(new TextDecoder().decode(bytes));\n    } else {\n      body = await readBoundedJsonResponse<unknown>(\n        response,\n        MAX_RESPONSE_BYTES,\n        controller.signal,\n      );\n    }\n    return authCapabilitiesSchema.or(legacyAuthCapabilitiesSchema).parse(body);\n  } finally {\n    clearTimeout(timer);\n  }\n}\n","import { t } from \"@lingui/core/macro\";\nimport { hostMatchesPasskeyRpId } from \"@rakazo/core\";\nimport { WebAuthnAbortService } from \"@simplewebauthn/browser\";\nimport { useEffect, useState, useSyncExternalStore } from \"react\";\nimport type { RakazoDesktop } from \"../platform/desktop\";\nimport { desktopBridge } from \"../platform/desktop\";\nimport { authErrorText } from \"../query/user-error\";\nimport { fetchAuthCapabilities } from \"./auth-capabilities\";\n\ntype PasskeyBrowser = {\n  host: string;\n  credential?: {\n    isUserVerifyingPlatformAuthenticatorAvailable?: () => Promise<boolean>;\n  };\n  desktop?: Pick<RakazoDesktop, \"platform\" | \"passkeys\">;\n};\n\nfunction currentBrowser(): PasskeyBrowser {\n  return {\n    host: window.location.hostname,\n    credential: typeof PublicKeyCredential === \"undefined\" ? undefined : PublicKeyCredential,\n    desktop: desktopBridge(),\n  };\n}\n\n/** The macOS app reaches passkeys through the system sheet, which serves only its associated domains. */\nfunction systemPasskeysDesktop(desktop: PasskeyBrowser[\"desktop\"]): boolean {\n  return desktop?.platform === \"darwin\";\n}\n\nasync function desktopAssociated(desktop: PasskeyBrowser[\"desktop\"], rpId: string) {\n  if (!systemPasskeysDesktop(desktop)) return true;\n  try {\n    return (await desktop?.passkeys?.rpIds())?.includes(rpId.toLowerCase()) === true;\n  } catch {\n    return false;\n  }\n}\n\n/**\n * Whether this page can use passkeys: the server offers a relying party this host\n * belongs to, and the browser has a ready platform authenticator. The macOS app also\n * needs to be associated with that relying party, or the system sheet refuses it.\n */\nexport async function passkeysSupported(\n  rpId: string | null | undefined,\n  browser: PasskeyBrowser = currentBrowser(),\n): Promise<boolean> {\n  if (!browser.credential?.isUserVerifyingPlatformAuthenticatorAvailable) return false;\n  if (!rpId || !hostMatchesPasskeyRpId(browser.host, rpId)) return false;\n  if (!(await desktopAssociated(browser.desktop, rpId))) return false;\n  try {\n    return await browser.credential.isUserVerifyingPlatformAuthenticatorAvailable();\n  } catch {\n    return false;\n  }\n}\n\n/** False until the deployment and browser are known to support passkeys. */\nexport function usePasskeysSupported(): boolean {\n  const [supported, setSupported] = useState(false);\n  useEffect(() => {\n    let active = true;\n    void fetchAuthCapabilities()\n      .then((capabilities) => passkeysSupported(capabilities.passkeyRpId))\n      .then((value) => {\n        if (active) setSupported(value);\n      })\n      .catch(() => undefined);\n    return () => {\n      active = false;\n    };\n  }, []);\n  return supported;\n}\n\nlet passkeysVersion = 0;\nconst passkeyListeners = new Set<() => void>();\n\n/** Tells every passkey view on the page that the account's passkeys changed. */\nexport function passkeysChanged() {\n  passkeysVersion += 1;\n  for (const listener of passkeyListeners) listener();\n}\n\n/** Changes whenever this page adds or removes a passkey, so views can reload their list. */\nexport function usePasskeysVersion(): number {\n  return useSyncExternalStore(\n    (listener) => {\n      passkeyListeners.add(listener);\n      return () => passkeyListeners.delete(listener);\n    },\n    () => passkeysVersion,\n  );\n}\n\n/** Cancels a pending WebAuthn request, such as browser autofill, when its view goes away. */\nexport function cancelPasskeyRequest() {\n  WebAuthnAbortService.cancelCeremony();\n}\n\n/**\n * Electron's system passkey sheet is modal and has no autofill mode, so on macOS a\n * conditional request would open it as soon as the form appears. The button opens it instead.\n */\nexport async function conditionalPasskeyAvailable(\n  desktop: PasskeyBrowser[\"desktop\"] = desktopBridge(),\n): Promise<boolean> {\n  if (typeof PublicKeyCredential === \"undefined\" || systemPasskeysDesktop(desktop)) return false;\n  try {\n    return (await PublicKeyCredential.isConditionalMediationAvailable?.()) === true;\n  } catch {\n    return false;\n  }\n}\n\n// The OS dialog was dismissed, timed out, or replaced by another ceremony.\nconst CANCELLED_CODES = new Set([\n  \"AUTH_CANCELLED\",\n  \"ERROR_CEREMONY_ABORTED\",\n  \"ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY\",\n]);\n\n/** Text for a failed passkey result, or null when the user closed the dialog. */\nexport function passkeyErrorText(error: unknown, fallback: string): string | null {\n  const code = error && typeof error === \"object\" && \"code\" in error ? error.code : undefined;\n  if (typeof code === \"string\" && CANCELLED_CODES.has(code)) return null;\n  // Adding a passkey needs a recent sign-in.\n  if (code === \"SESSION_NOT_FRESH\") return t`Sign in again`;\n  // Other browser WebAuthn errors carry implementation detail.\n  if (typeof code === \"string\" && code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