/* Vault recovery confirmation: prove it is you with a passkey of the account being recovered. Uses the @simplewebauthn/browser UMD bundle (/vendor). */ (function () { var btn = document.getElementById("stepup-passkey"); var msg = document.getElementById("stepup-msg"); if (!btn) return; var base = "/recover/confirm/" + encodeURIComponent(btn.getAttribute("data-stepup")); function csrf() { var m = document.cookie.match(/(?:^|; )mc_csrf=([^;]+)/); return m ? decodeURIComponent(m[1]) : ""; } function post(url, body) { return fetch(url, { method: "POST", headers: { "content-type": "application/json", "x-csrf-token": csrf() }, body: JSON.stringify(body || {}), }); } function say(t) { if (msg) msg.textContent = t; } btn.addEventListener("click", async function () { btn.disabled = true; say("Waiting for your passkey…"); try { var optsRes = await post(base + "/passkey/options"); var opts = await optsRes.json(); if (!optsRes.ok) throw new Error(opts.error || "Could not start."); var asr = await SimpleWebAuthnBrowser.startAuthentication({ optionsJSON: opts }); var r = await post(base + "/passkey/verify", asr); var out = await r.json(); if (!r.ok || !out.ok) throw new Error(out.error || "The passkey did not verify."); location.reload(); } catch (e) { say(e && e.message ? e.message : "Could not confirm with a passkey."); btn.disabled = false; } }); })();