{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "auth-passkey-handshake",
  "type": "registry:component",
  "title": "Auth Passkey Handshake",
  "description": "A passkey sign-in built around a dial of sixty ticks: a sweep while the browser looks for a passkey, a draining countdown ring while you confirm on your device, then every tick lights up as the signature is verified. A live checklist shows each step of the ceremony.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "auth",
    "auth",
    "passkey",
    "webauthn",
    "passwordless",
    "countdown",
    "security"
  ],
  "docs": "https://hyperblur.dev/effects/auth-passkey-handshake",
  "files": [
    {
      "path": "registry/hyperblur/auth-passkey-handshake.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/auth-passkey-handshake.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type AuthPasskeyHandshakeStage = \"idle\" | \"searching\" | \"confirm\" | \"verified\" | \"failed\";\n\nexport interface AuthPasskeyHandshakeProps extends Omit<React.HTMLAttributes<HTMLElement>, \"title\"> {\n  title?: string;\n  subtitle?: string;\n  account?: { name: string; email: string };\n  device?: string;\n  timeoutSeconds?: number;\n  defaultStage?: AuthPasskeyHandshakeStage;\n  onPasskey?: () => boolean | void | Promise<boolean | void>;\n  onFallback?: () => void;\n  onSwitchAccount?: () => void;\n  onStageChange?: (stage: AuthPasskeyHandshakeStage) => void;\n  accent?: string;\n}\n\nconst css = `\n.hb-vf4 {\n  --hb-vf4-accent: #3dd68c;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  min-height: 600px;\n  display: grid;\n  place-items: center;\n  padding: 52px 20px;\n  overflow: hidden;\n  background: radial-gradient(ellipse 55% 45% at 50% 40%, color-mix(in srgb, var(--hb-vf4-accent) 10%, transparent), transparent 70%), #0a0a0a;\n  color: #ededed;\n  font-family: inherit;\n}\n.hb-vf4 *, .hb-vf4 *::before, .hb-vf4 *::after { box-sizing: border-box; }\n.hb-vf4-card { width: 100%; max-width: 420px; text-align: center; }\n.hb-vf4-chip { display: inline-flex; align-items: center; gap: 10px; height: 38px; padding: 0 6px 0 4px; border-radius: 999px; border: 1px solid #262626; background: #111; font-size: 13px; }\n.hb-vf4-ava { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 11.5px; font-weight: 600; color: #0a0a0a; background: linear-gradient(135deg, #fde68a, #f472b6); }\n.hb-vf4-chip b { font-weight: 500; }\n.hb-vf4-chip span { color: #8f8f8f; }\n.hb-vf4-swap { height: 28px; padding: 0 10px; border-radius: 999px; border: 0; background: #1c1c1c; color: #a1a1a1; font: inherit; font-size: 12px; cursor: pointer; transition: background .2s, color .2s; }\n.hb-vf4-swap:hover { background: #262626; color: #ededed; }\n.hb-vf4-dial { position: relative; width: 190px; height: 190px; margin: 22px auto 18px; }\n.hb-vf4-ticks { position: absolute; inset: 0; }\n.hb-vf4-tick { position: absolute; left: 50%; top: 0; width: 2px; height: 14px; margin-left: -1px; border-radius: 2px; background: #2a2a2a; transform-origin: 1px 95px; transition: background .35s, height .35s; }\n.hb-vf4[data-stage=\"searching\"] .hb-vf4-tick { animation: hb-vf4-sweep 1.2s linear infinite; }\n.hb-vf4[data-stage=\"confirm\"] .hb-vf4-tick[data-on=\"true\"] { background: var(--hb-vf4-accent); }\n.hb-vf4[data-stage=\"verified\"] .hb-vf4-tick { background: var(--hb-vf4-accent); height: 18px; transition-delay: var(--hb-vf4-d); }\n.hb-vf4[data-stage=\"failed\"] .hb-vf4-tick { background: #4a1f22; }\n.hb-vf4-core { position: absolute; inset: 28px; border-radius: 50%; display: grid; place-items: center; background: radial-gradient(circle at 50% 35%, #1a1a1a, #0e0e0e 70%); border: 1px solid #222; box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 20px 50px -20px rgba(0,0,0,.9); }\n.hb-vf4-core::after { content: \"\"; position: absolute; inset: -1px; border-radius: 50%; box-shadow: 0 0 0 0 color-mix(in srgb, var(--hb-vf4-accent) 45%, transparent); }\n.hb-vf4[data-stage=\"confirm\"] .hb-vf4-core::after { animation: hb-vf4-ping 1.8s cubic-bezier(.2,.7,.2,1) infinite; }\n.hb-vf4[data-stage=\"verified\"] .hb-vf4-core { border-color: color-mix(in srgb, var(--hb-vf4-accent) 50%, #222); box-shadow: 0 0 60px -10px var(--hb-vf4-accent); transition: box-shadow .6s .4s, border-color .6s .4s; }\n.hb-vf4-glyph { position: absolute; display: grid; place-items: center; opacity: 0; transform: scale(.7); transition: opacity .35s, transform .5s cubic-bezier(.3,1.5,.5,1); }\n.hb-vf4-glyph[data-on=\"true\"] { opacity: 1; transform: scale(1); }\n.hb-vf4-arc { position: absolute; inset: 0; transform: rotate(-90deg); pointer-events: none; }\n.hb-vf4-arc circle { fill: none; stroke: var(--hb-vf4-accent); stroke-width: 2; stroke-linecap: round; transition: stroke-dashoffset 1s linear, opacity .3s; }\n.hb-vf4-count { position: absolute; bottom: 22px; left: 0; right: 0; font-family: var(--font-mono), ui-monospace, monospace; font-size: 11px; color: #8f8f8f; letter-spacing: .04em; }\n.hb-vf4-check path { stroke-dasharray: 36; stroke-dashoffset: 36; animation: hb-vf4-draw .5s .5s cubic-bezier(.65,0,.35,1) forwards; }\n.hb-vf4-title { margin: 0; font-size: 24px; letter-spacing: -.025em; font-weight: 600; line-height: 1.2; }\n.hb-vf4-sub { margin: 8px auto 22px; max-width: 340px; color: #8f8f8f; font-size: 14px; line-height: 1.55; min-height: 44px; }\n.hb-vf4-btn { width: 100%; height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 10px; border: 0; border-radius: 13px; font: inherit; font-size: 14.5px; font-weight: 600; cursor: pointer; color: #04140b; background: var(--hb-vf4-accent); box-shadow: inset 0 1px 0 rgba(255,255,255,.45), 0 14px 34px -16px var(--hb-vf4-accent); transition: filter .2s, transform .2s cubic-bezier(.2,.8,.2,1), opacity .2s; }\n.hb-vf4-btn:hover { filter: brightness(1.06); }\n.hb-vf4-btn:active { transform: scale(.985); }\n.hb-vf4-btn:disabled { cursor: default; opacity: .55; filter: grayscale(.3); }\n.hb-vf4-steps { list-style: none; margin: 20px 0 0; padding: 14px 16px; border-radius: 14px; border: 1px solid #1f1f1f; background: #0f0f0f; display: grid; gap: 10px; text-align: left; }\n.hb-vf4-step { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #6b6b6b; transition: color .3s; }\n.hb-vf4-step[data-s=\"active\"] { color: #ededed; }\n.hb-vf4-step[data-s=\"done\"] { color: #a1a1a1; }\n.hb-vf4-step[data-s=\"error\"] { color: #f58a8b; }\n.hb-vf4-dot { flex: none; width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid #333; display: grid; place-items: center; transition: border-color .3s, background .3s; }\n.hb-vf4-step[data-s=\"active\"] .hb-vf4-dot { border-color: var(--hb-vf4-accent); border-top-color: transparent; animation: hb-vf4-rot .8s linear infinite; }\n.hb-vf4-step[data-s=\"done\"] .hb-vf4-dot { border-color: var(--hb-vf4-accent); background: var(--hb-vf4-accent); }\n.hb-vf4-step[data-s=\"error\"] .hb-vf4-dot { border-color: #f05d5e; background: #f05d5e; }\n.hb-vf4-step em { margin-left: auto; font-style: normal; font-family: var(--font-mono), ui-monospace, monospace; font-size: 11px; color: #5c5c5c; }\n.hb-vf4-alt { margin: 18px 0 0; font-size: 13px; color: #8f8f8f; }\n.hb-vf4-alt button { border: 0; background: none; padding: 0; font: inherit; color: #ededed; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,.25); }\n.hb-vf4 :is(.hb-vf4-btn, .hb-vf4-swap, .hb-vf4-alt button):focus-visible { outline: 2px solid var(--hb-vf4-accent); outline-offset: 3px; }\n@keyframes hb-vf4-sweep { 0% { background: var(--hb-vf4-accent); height: 18px; } 30%, 100% { background: #2a2a2a; height: 14px; } }\n@keyframes hb-vf4-ping { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--hb-vf4-accent) 45%, transparent); } 100% { box-shadow: 0 0 0 22px transparent; } }\n@keyframes hb-vf4-draw { to { stroke-dashoffset: 0; } }\n@keyframes hb-vf4-rot { to { transform: rotate(360deg); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-vf4 *, .hb-vf4 *::before, .hb-vf4 *::after { animation: none !important; transition: none !important; }\n  .hb-vf4-check path { stroke-dashoffset: 0; }\n}\n`;\n\nconst TICKS = 60;\n\nexport function AuthPasskeyHandshake({\n  title = \"Sign in with your passkey\",\n  subtitle = \"No password needed. Your device signs a one-time challenge, and nothing secret leaves it.\",\n  account = { name: \"Maya Okafor\", email: \"maya@lumen.dev\" },\n  device = \"MacBook Pro\",\n  timeoutSeconds = 60,\n  defaultStage = \"idle\",\n  onPasskey,\n  onFallback,\n  onSwitchAccount,\n  onStageChange,\n  accent = \"#3dd68c\",\n  className,\n  style,\n  ...rest\n}: AuthPasskeyHandshakeProps) {\n  const [stage, setStageState] = React.useState<AuthPasskeyHandshakeStage>(defaultStage);\n  const [left, setLeft] = React.useState(timeoutSeconds);\n  const [failReason, setFailReason] = React.useState(\"The request was cancelled on your device.\");\n  const runRef = React.useRef(0);\n\n  const setStage = React.useCallback((s: AuthPasskeyHandshakeStage) => {\n    setStageState(s);\n    onStageChange?.(s);\n  }, [onStageChange]);\n\n  React.useEffect(() => {\n    if (stage !== \"confirm\") return;\n    const run = runRef.current;\n    const deadline = performance.now() + timeoutSeconds * 1000;\n    const t = window.setInterval(() => {\n      const remaining = Math.max(0, Math.ceil((deadline - performance.now()) / 1000));\n      setLeft(remaining);\n      if (remaining === 0 && run === runRef.current) {\n        runRef.current += 1;\n        setFailReason(\"The request timed out before your device answered.\");\n        setStage(\"failed\");\n      }\n    }, 250);\n    return () => window.clearInterval(t);\n  }, [stage, timeoutSeconds, setStage]);\n\n  React.useEffect(() => () => { runRef.current += 1; }, []);\n\n  const start = async () => {\n    const run = ++runRef.current;\n    setLeft(timeoutSeconds);\n    setStage(\"searching\");\n    await new Promise((r) => setTimeout(r, 900));\n    if (run !== runRef.current) return;\n    setStage(\"confirm\");\n    try {\n      const r = onPasskey ? await onPasskey() : await new Promise<boolean>((res) => setTimeout(() => res(true), 2200));\n      if (run !== runRef.current) return;\n      if (r === false) {\n        setFailReason(\"The request was cancelled on your device.\");\n        setStage(\"failed\");\n        return;\n      }\n      setStage(\"verified\");\n    } catch (err) {\n      if (run !== runRef.current) return;\n      setFailReason(err instanceof Error ? err.message : \"Your device could not sign the challenge.\");\n      setStage(\"failed\");\n    }\n  };\n\n  const busy = stage === \"searching\" || stage === \"confirm\";\n  const fraction = left / Math.max(1, timeoutSeconds);\n  const lit = Math.round(fraction * TICKS);\n  const circ = 2 * Math.PI * 82;\n  const initials = account.name.split(\" \").map((p) => p[0]).slice(0, 2).join(\"\");\n\n  const headline: Record<AuthPasskeyHandshakeStage, string> = {\n    idle: title,\n    searching: \"Looking for your passkey\",\n    confirm: `Confirm on ${device}`,\n    verified: `Welcome back, ${account.name.split(\" \")[0]}`,\n    failed: \"That did not go through\",\n  };\n  const copy: Record<AuthPasskeyHandshakeStage, string> = {\n    idle: subtitle,\n    searching: \"Asking your browser for a passkey saved for this site.\",\n    confirm: `Use Touch ID or your security key on ${device} to approve this sign-in.`,\n    verified: \"Signature verified. Opening your workspace now.\",\n    failed: failReason,\n  };\n\n  const stepState = (i: number) => {\n    const order = { idle: -1, searching: 0, confirm: 1, verified: 3, failed: 1 }[stage];\n    if (stage === \"failed\" && i === 1) return \"error\";\n    if (i < order) return \"done\";\n    if (i === order) return stage === \"failed\" ? \"idle\" : \"active\";\n    return \"idle\";\n  };\n  const steps = [\n    { label: \"Request challenge\", meta: stepState(0) === \"done\" ? \"84 ms\" : \"\" },\n    { label: `Sign with ${device}`, meta: stage === \"confirm\" ? `${left}s` : stepState(1) === \"done\" ? \"ok\" : \"\" },\n    { label: \"Verify signature\", meta: stepState(2) === \"done\" ? \"ES256\" : \"\" },\n  ];\n\n  return (\n    <section className={[\"hb-vf4\", className].filter(Boolean).join(\" \")} data-stage={stage} style={{ \"--hb-vf4-accent\": accent, ...style } as React.CSSProperties} {...rest}>\n      <style href=\"hb-auth-passkey-handshake\" precedence=\"default\">{css}</style>\n      <div className=\"hb-vf4-card\">\n        <div className=\"hb-vf4-chip\">\n          <span className=\"hb-vf4-ava\" aria-hidden=\"true\">{initials}</span>\n          <b>{account.name}</b>\n          <span>{account.email}</span>\n          <button type=\"button\" className=\"hb-vf4-swap\" onClick={() => onSwitchAccount?.()} disabled={busy}>Switch</button>\n        </div>\n        <div className=\"hb-vf4-dial\" aria-hidden=\"true\">\n          <div className=\"hb-vf4-ticks\">\n            {Array.from({ length: TICKS }, (_, i) => (\n              <span key={i} className=\"hb-vf4-tick\" data-on={i < lit} style={{ transform: `rotate(${(i * 360 / TICKS).toFixed(2)}deg)`, animationDelay: `${(i * 1.2 / TICKS - 1.2).toFixed(3)}s`, \"--hb-vf4-d\": `${(i * 12).toFixed(0)}ms` } as React.CSSProperties} />\n            ))}\n          </div>\n          <div className=\"hb-vf4-core\">\n            <span className=\"hb-vf4-glyph\" data-on={stage === \"idle\" || stage === \"searching\"}>\n              <svg width=\"54\" height=\"54\" viewBox=\"0 0 48 48\" fill=\"none\">\n                <circle cx=\"17\" cy=\"16\" r=\"8\" stroke=\"#ededed\" strokeWidth=\"2.2\" />\n                <path d=\"M4 38c0-7 6-11 13-11 3 0 6 .8 8 2.2\" stroke=\"#ededed\" strokeWidth=\"2.2\" strokeLinecap=\"round\" />\n                <circle cx=\"35\" cy=\"27\" r=\"5.5\" stroke={accent} strokeWidth=\"2.2\" />\n                <path d=\"M35 32.5V43m0-4h4m-4-3h3\" stroke={accent} strokeWidth=\"2.2\" strokeLinecap=\"round\" />\n              </svg>\n            </span>\n            <span className=\"hb-vf4-glyph\" data-on={stage === \"confirm\"}>\n              <svg width=\"58\" height=\"58\" viewBox=\"0 0 48 48\" fill=\"none\">\n                <rect x=\"9\" y=\"11\" width=\"30\" height=\"20\" rx=\"2.5\" stroke=\"#ededed\" strokeWidth=\"2\" />\n                <path d=\"M5 35h38l-2.5 3h-33Z\" stroke=\"#ededed\" strokeWidth=\"2\" strokeLinejoin=\"round\" />\n                <circle cx=\"24\" cy=\"21\" r=\"5\" stroke={accent} strokeWidth=\"2\" />\n                <path d=\"M24 18.5v2.5\" stroke={accent} strokeWidth=\"2\" strokeLinecap=\"round\" />\n              </svg>\n            </span>\n            <span className=\"hb-vf4-glyph\" data-on={stage === \"verified\"}>\n              {stage === \"verified\" ? (\n                <svg className=\"hb-vf4-check\" width=\"56\" height=\"56\" viewBox=\"0 0 48 48\" fill=\"none\"><path d=\"M13 25l7.5 7.5L36 17\" stroke={accent} strokeWidth=\"3.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" /></svg>\n              ) : null}\n            </span>\n            <span className=\"hb-vf4-glyph\" data-on={stage === \"failed\"}>\n              <svg width=\"50\" height=\"50\" viewBox=\"0 0 48 48\" fill=\"none\"><path d=\"M24 14v13m0 6.5v.5\" stroke=\"#f05d5e\" strokeWidth=\"3.2\" strokeLinecap=\"round\" /><circle cx=\"24\" cy=\"24\" r=\"16\" stroke=\"#f05d5e\" strokeWidth=\"2\" opacity=\".5\" /></svg>\n            </span>\n            {stage === \"confirm\" ? <span className=\"hb-vf4-count\">00:{String(left).padStart(2, \"0\")}</span> : null}\n          </div>\n          <svg className=\"hb-vf4-arc\" viewBox=\"0 0 190 190\">\n            <circle cx=\"95\" cy=\"95\" r=\"82\" strokeDasharray={circ.toFixed(2)} strokeDashoffset={(circ * (1 - fraction)).toFixed(2)} style={{ opacity: stage === \"confirm\" ? 0.55 : 0 }} />\n          </svg>\n        </div>\n        <h2 className=\"hb-vf4-title\" aria-live=\"polite\">{headline[stage]}</h2>\n        <p className=\"hb-vf4-sub\">{copy[stage]}</p>\n        {stage === \"verified\" ? null : (\n          <button type=\"button\" className=\"hb-vf4-btn\" onClick={start} disabled={busy} aria-busy={busy}>\n            <svg width=\"17\" height=\"17\" viewBox=\"0 0 24 24\" fill=\"none\" aria-hidden=\"true\"><circle cx=\"8.5\" cy=\"9\" r=\"4\" stroke=\"currentColor\" strokeWidth=\"2\" /><path d=\"M11.5 11.5 20 20m-3-3 2-2m-4.5-.5 2-2\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" /></svg>\n            {stage === \"failed\" ? \"Try again\" : busy ? \"Waiting for device\" : \"Use passkey\"}\n          </button>\n        )}\n        <ol className=\"hb-vf4-steps\">\n          {steps.map((s, i) => (\n            <li key={s.label} className=\"hb-vf4-step\" data-s={stepState(i)}>\n              <span className=\"hb-vf4-dot\" aria-hidden=\"true\" />\n              {s.label}\n              <em>{s.meta}</em>\n            </li>\n          ))}\n        </ol>\n        <p className=\"hb-vf4-alt\">Lost your device? <button type=\"button\" onClick={() => onFallback?.()}>Sign in with an email code</button></p>\n      </div>\n    </section>\n  );\n}\n"
    }
  ]
}