@seams/wallet 0.9.0 → 0.9.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/README.md +3 -3
- package/dist/.build-inputs.sha256 +1 -1
- package/dist/esm/core/signingEngine/chains/evm/bytes.js +15 -1
- package/dist/esm/core/signingEngine/flows/signEvmFamily/signingFlow.js +1 -1
- package/dist/esm/core/signingEngine/flows/signNear/shared/ed25519YaoNormalSigning.js +84 -38
- package/dist/esm/core/signingEngine/flows/signNear/signTransactions.js +49 -2
- package/dist/esm/core/signingEngine/uiConfirm/ui/transaction-display/abi/abiDecode.js +315 -0
- package/dist/esm/core/signingEngine/uiConfirm/ui/transaction-display/abi/enrichDisplayModelWithAbi.js +77 -0
- package/dist/esm/core/signingEngine/uiConfirm/ui/transaction-display/formatters.js +10 -1
- package/dist/esm/core/signingEngine/uiConfirm/ui/transaction-display/renderers/fallback.js +52 -0
- package/dist/esm/core/signingEngine/uiConfirm/ui/transaction-display/renderers/types.js +62 -0
- package/dist/esm/core/signingEngine/uiConfirm/ui/transaction-display/tree.js +249 -0
- package/dist/esm/sdk/{host-B1CdRGoI.js → host-c1__wJwz.js} +1 -1
- package/dist/esm/sdk/{runtime-auth-tgfe70hU.js → runtime-auth-BKFyLISf.js} +1 -1
- package/dist/{public/sdk/runtime-device-link-BUxuQupR.js → esm/sdk/runtime-device-link-ENxdEXQW.js} +1 -1
- package/dist/{public/sdk/runtime-ecdsa-tempo-DOBk_EtI.js → esm/sdk/runtime-ecdsa-tempo-DhGEb9U7.js} +1 -1
- package/dist/esm/sdk/{runtime-email-otp-CsAJKvYC.js → runtime-email-otp-dgsP7XZi.js} +1 -1
- package/dist/esm/sdk/{runtime-export-7REbcnBl.js → runtime-export-D2RCm5Gk.js} +1 -1
- package/dist/esm/sdk/{runtime-near-BA0DQf6H.js → runtime-near-Bf-9MFBQ.js} +1 -1
- package/dist/esm/sdk/{runtime-preferences-cRViPE8a.js → runtime-preferences-LQ8SPE7o.js} +1 -1
- package/dist/esm/sdk/{runtime-recovery-RRc8Yz1y.js → runtime-recovery-BuEzJzuZ.js} +1 -1
- package/dist/esm/sdk/shared-8ffIBYw2.js +6 -0
- package/dist/esm/sdk/signNear-BhTkDm2-.js +1 -0
- package/dist/esm/sdk/wallet-iframe-host-ecdsa.js +1 -1
- package/dist/esm/sdk/wallet-iframe-host-full.js +1 -1
- package/dist/esm/sdk/wallet-iframe-host-near.js +1 -1
- package/dist/esm/sdk/wallet-iframe-host-runtime.js +1 -1
- package/dist/esm/utils/intentDigest.js +59 -1
- package/dist/public/headers.manifest.json +1 -1
- package/dist/public/sdk/{host-B1CdRGoI.js → host-c1__wJwz.js} +1 -1
- package/dist/public/sdk/{runtime-auth-tgfe70hU.js → runtime-auth-BKFyLISf.js} +1 -1
- package/dist/{esm/sdk/runtime-device-link-BUxuQupR.js → public/sdk/runtime-device-link-ENxdEXQW.js} +1 -1
- package/dist/{esm/sdk/runtime-ecdsa-tempo-DOBk_EtI.js → public/sdk/runtime-ecdsa-tempo-DhGEb9U7.js} +1 -1
- package/dist/public/sdk/{runtime-email-otp-CsAJKvYC.js → runtime-email-otp-dgsP7XZi.js} +1 -1
- package/dist/public/sdk/{runtime-export-7REbcnBl.js → runtime-export-D2RCm5Gk.js} +1 -1
- package/dist/public/sdk/{runtime-near-BA0DQf6H.js → runtime-near-Bf-9MFBQ.js} +1 -1
- package/dist/public/sdk/{runtime-preferences-cRViPE8a.js → runtime-preferences-LQ8SPE7o.js} +1 -1
- package/dist/public/sdk/{runtime-recovery-RRc8Yz1y.js → runtime-recovery-BuEzJzuZ.js} +1 -1
- package/dist/public/sdk/shared-8ffIBYw2.js +6 -0
- package/dist/public/sdk/signNear-BhTkDm2-.js +1 -0
- package/dist/public/sdk/wallet-iframe-host-ecdsa.js +1 -1
- package/dist/public/sdk/wallet-iframe-host-full.js +1 -1
- package/dist/public/sdk/wallet-iframe-host-near.js +1 -1
- package/dist/public/sdk/wallet-iframe-host-runtime.js +1 -1
- package/dist/public/wallet-assets.manifest.json +26 -26
- package/dist/public/wallet-service/index.html +4 -4
- package/dist/types/wallet/src/core/signingEngine/flows/signNear/shared/ed25519YaoNormalSigning.d.ts +16 -4
- package/dist/types/wallet/src/core/signingEngine/flows/signNear/shared/signatureOnlySigning.d.ts +3 -3
- package/dist/types/wallet/src/core/signingEngine/nonce/nearTransactionReadiness.d.ts +3 -0
- package/dist/types/wallet/src/core/signingEngine/stepUpConfirmation/confirmOperation.d.ts +3 -1
- package/dist/types/wallet/src/core/signingEngine/uiConfirm/handlers/flows/signing.d.ts +2 -0
- package/dist/types/wallet/src/core/signingEngine/uiConfirm/handlers/handlePromptFromWorker.d.ts +2 -0
- package/dist/types/wallet/src/core/signingEngine/uiConfirm/uiConfirm.types.d.ts +3 -0
- package/package.json +1 -1
- package/dist/esm/sdk/shared-DdfxBUGY.js +0 -6
- package/dist/esm/sdk/signNear-CO5bx24Z.js +0 -1
- package/dist/public/sdk/shared-DdfxBUGY.js +0 -6
- package/dist/public/sdk/signNear-CO5bx24Z.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{L as e,V as t}from"./normalize-kUDm5zfS.js";import{k as n}from"./chains-CiYQT1K4.js";import"./primitives-CAcl7ON7.js";import"./sessionPolicy-J-RrlPZQ.js";import"./signingSessionSeal-CDLUmAFY.js";import{c as r,l as i,o as a,r as o,s}from"./messages-vxz27Way.js";import{C as c,S as l,T as ee,_ as te,a as ne,b as re,c as ie,d as ae,f as u,g as oe,h as se,l as ce,m as d,n as f,r as le,s as ue,t as de,u as fe,v as pe,w as me,x as he,y as ge}from"./shared-DdfxBUGY.js";import"./activeWalletSession-DiZcKjB_.js";import"./capabilityKinds-CKQ4Uqnv.js";import{t as _e}from"./walletIframeIdentity-DJ0KOBHg.js";import"./errors-BZO3LF6G.js";import"./digestEncoding-Dzc1rzWV.js";import{en as ve,i as ye,n as be,nn as xe,r as Se,s as Ce}from"./registration-CEqVAgNJ.js";import"./accountIds-BzZs7YoX.js";import"./registrationSignerPlan-B9GCvpTV.js";import{a as p}from"./signerDomain-vQmlnsbF.js";import"./registrationIntent-DOkZcKSP.js";import"./singletons-8UH3gOnZ.js";import"./walletAuthority-B5hXHWpK.js";import"./emailOtpEcdsaDerivationIdentity-B8HzTh4T.js";import{t as we}from"./challengeDelivery-DxXAkOfS.js";import{a as Te,n as Ee}from"./registrationIds-CdPqm-Ya.js";import"./passkey-custody-BQj44jEM.js";import{c as De,s as Oe}from"./sdkSentEvents-D3q1h-Uo.js";import"./walletCustodyEcdsaContinuity-abNZ_dvX.js";import"./keccak-B02Fekdh.js";import"./wallet-recovery-C1kesLCF.js";import"./nearEd25519YaoMaterialActivation-fWQI3rYj.js";import{t as ke}from"./walletSessionAuthorizationStatus-o1VgsLhA.js";import"./signNear-CO5bx24Z.js";import{a as Ae,i as je}from"./adapters-DdDOQzl4.js";import{t as Me}from"./surface-measurement-reporter-IlPOI3QK.js";import{a as Ne,c as Pe,i as Fe,l as m,n as Ie,o as Le,t as h}from"./jsxRuntime.module-BcZNe_OA.js";function Re(e){return{PM_GET_LAST_WALLET_MOVE_REQUEST:He.bind(null,e),PM_MOVE_WALLET:Ve.bind(null,e),PM_GET_WALLET_PLACEMENT:ze.bind(null,e),PM_GET_WALLET_MOVE:Be.bind(null,e)}}async function ze(t,r){let i=n(r.payload,`Wallet placement request`),a=e(i.walletId);if(!a.ok||Object.keys(i).length!==1)throw Error(`Wallet placement identity is invalid`);let o=await t.getWalletRuntime().placement.get(a.value);t.respondIfCancelled(r.requestId)||f(t,r.requestId,o)}async function Be(t,r){let i=n(r.payload,`Wallet move request`),a=e(i.walletId),o=ce(i.moveId);if(!a.ok||Object.keys(i).length!==2)throw Error(`Wallet move request is invalid`);let s=await t.getWalletRuntime().placement.getMove(a.value,o);t.respondIfCancelled(r.requestId)||f(t,r.requestId,s)}async function Ve(e,t){let n=fe(t.payload),r=await e.getWalletRuntime().placement.move(n);e.respondIfCancelled(t.requestId)||f(e,t.requestId,r)}async function He(t,r){let i=n(r.payload,`Wallet move locator request`),a=e(i.walletId);if(!a.ok||Object.keys(i).length!==1)throw Error(`Wallet move locator identity is invalid`);let o=await t.getWalletRuntime().placement.getLastMoveRequest(a.value);t.respondIfCancelled(r.requestId)||f(t,r.requestId,o)}function Ue(e){if(!e)throw Error(`PM_UNLOCK payload is required`);return e}function We(e){switch(e.kind){case`default_options`:return{};case`custom_options`:return{...g(`signerSlot`,e.options.signerSlot),...g(`signingSession`,e.options.signingSession),...g(`unlockSelection`,e.options.unlockSelection),...Ge(e.options.ecdsaKeyFactsInventory)}}}function Ge(e){switch(e.kind){case`default`:return{};case`value`:return{ecdsaKeyFactsInventory:e.value}}}function g(e,t){switch(t.kind){case`default`:return{};case`value`:return{[e]:t.value}}}function Ke(e){return e===`register`?`Creating passkey wallet…`:`Unlocking wallet…`}const qe=/\bHTTP 429\b|too many requests|rate limit/i,Je=/\bHTTP 5\d\d\b|failed to fetch|load failed|networkerror|network request failed|connection ?closed/i,Ye=/timed out|timeout/i;function Xe(e){return qe.test(e)?`Too many attempts. Wait a moment.`:Je.test(e)?`Can’t reach Seams right now.`:Ye.test(e)?`That took too long.`:`Something went wrong.`}function _(e){return{kind:`recoverable`,reason:`error`,message:Xe(e),detail:e}}function v(e,t){let n=t?e.find(e=>e.walletId===t.walletId&&e.authMethod===t.authMethod):null,r=t?e.find(e=>e.walletId===t.walletId):null,i=n??r??e[0];if(!i)return{kind:`discoverable`,selectedAccount:null,loginTarget:{kind:`discoverable`}};let a=e.filter(e=>e.walletId===i.walletId),o=a.some(e=>e.authMethod===`passkey`),s=a.some(e=>e.authMethod===`email_otp`),c={selectedAccount:i,walletId:i.walletId,loginTarget:{kind:`wallet`,walletId:i.walletId}};if(o&&s)return{kind:`passkey_and_email_otp`,...c};if(o)return{kind:`passkey`,...c};if(s)return{kind:`email_otp`,...c};throw Error(`Selected auth-menu account has no supported authentication method`)}function y(e){switch(e.kind){case`discoverable`:case`passkey`:case`passkey_and_email_otp`:return!0;case`email_otp`:return!1}}function Ze(e){switch(e.kind){case`discoverable`:case`email_otp`:case`passkey_and_email_otp`:return!0;case`passkey`:return!1}}function b(e){return e.kind===`busy`}function Qe(e){let t=e.status;return t.kind===`idle`&&t.interaction===`actionable`}function $e(e){let t=e.status;return t.kind===`recoverable`?!0:t.kind===`idle`&&t.interaction===`actionable`}function x(e){if(!$e(e))return!1;switch(e.kind){case`google_otp_login`:return!e.submitBusy&&/^\d{6}$/.test(e.otpCode);case`google_registration`:return!e.rerollBusy&&!e.submitBusy;case`link_device`:return!1;case`recovery`:return e.stage===`passkey_ready`||e.stage===`google_ready`||e.stage===`sign_in_ready`||e.stage===`email_code_required`&&/^\d{6}$/.test(e.otpCode);case`passkey`:return e.mode===`login`?y(v(e.accountOptions,e.selectedAccount)):!e.showRegistrationInput||e.passkeyName.trim().length>0}}function S(e){return $e(e)?e.kind!==`passkey`||e.mode!==`login`?!0:Ze(v(e.accountOptions,e.selectedAccount)):!1}const et=()=>new Promise(e=>setTimeout(e,90));function tt(e){return e.dataset.blink?null:(e.dataset.blink=`off`,et().then(()=>(e.dataset.blink=`on`,et())).then(()=>{delete e.dataset.blink}))}function C(e,t,...n){return h(m,{children:h(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":t,"stroke-linecap":`round`,"stroke-linejoin":`round`,"aria-hidden":`true`,children:n})})}function w(){return C(`22`,`1.5`,h(`path`,{d:`M6.405 19.048c.184-.443.353-.894.507-1.351`}),h(`path`,{d:`M14.343 20.693c.266-.751.502-1.516.707-2.294.186-.706.346-1.422.478-2.147`}),h(`path`,{d:`M19.448 17.058c.364-1.964.555-3.989.555-6.058 0-4.418-3.582-8-8-8-1.255 0-2.443.289-3.501.805`}),h(`path`,{d:`M3.523 15.025c.314-1.29.48-2.638.48-4.025 0-1.74.556-3.351 1.499-4.664`}),h(`path`,{d:`M12.003 11c0 2.76-.447 5.416-1.273 7.899-.213.639-.451 1.266-.712 1.881`}),h(`path`,{d:`M7.712 14.5c.191-1.138.291-2.308.291-3.5 0-2.209 1.791-4 4-4s4 1.791 4 4c0 .617-.02 1.229-.058 1.836`}))}function nt(){return h(m,{children:h(`svg`,{class:`seams-account-dropdown-arrow`,viewBox:`0 0 24 24`,"aria-hidden":`true`,focusable:`false`,children:h(`path`,{d:`M9.75 3h4.5v10.28l4.3-4.3 3.18 3.18L12 21.9l-9.73-9.74 3.18-3.18 4.3 4.3V3Z`})})})}function rt(){return C(`18`,`2.25`,h(`path`,{d:`m15 18-6-6 6-6`}))}function it(){return C(`18`,`2`,h(`rect`,{width:`5`,height:`5`,x:`3`,y:`3`,rx:`1`}),h(`rect`,{width:`5`,height:`5`,x:`16`,y:`3`,rx:`1`}),h(`rect`,{width:`5`,height:`5`,x:`3`,y:`16`,rx:`1`}),h(`path`,{d:`M21 16h-3a2 2 0 0 0-2 2v3`}),h(`path`,{d:`M21 21v.01`}),h(`path`,{d:`M12 7v3a2 2 0 0 1-2 2H7`}),h(`path`,{d:`M3 12h.01`}),h(`path`,{d:`M12 3h.01`}),h(`path`,{d:`M12 16v.01`}),h(`path`,{d:`M16 12h1`}),h(`path`,{d:`M21 12v.01`}),h(`path`,{d:`M12 21v-1`}))}function at(){return C(`18`,`2`,h(`path`,{d:`M20 11v6`}),h(`path`,{d:`M20 13h2`}),h(`path`,{d:`M3 21v-2a4 4 0 0 1 4-4h6a4 4 0 0 1 2.072.578`}),h(`circle`,{cx:`10`,cy:`7`,r:`4`}),h(`circle`,{cx:`20`,cy:`19`,r:`2`}))}function ot(){return C(`21`,`1.75`,h(`rect`,{x:`2.75`,y:`5`,width:`18.5`,height:`14`,rx:`2.75`}),h(`path`,{d:`m3.75 7.75 6.94 4.86a2.25 2.25 0 0 0 2.62 0l6.94-4.86`}))}function st(){return C(`22`,`1.75`,h(`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`}),h(`path`,{d:`M15 7h2a5 5 0 0 1 3.54 8.54`}),h(`path`,{d:`m2 2 20 20`}),h(`path`,{d:`M8 12h3`}))}function ct(){return h(m,{children:h(`svg`,{class:`seams-input-action-icon`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"aria-hidden":`true`,children:[h(`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`}),h(`path`,{d:`M21 3v5h-5`}),h(`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`}),h(`path`,{d:`M8 16H3v5`})]})})}function T(){return h(`svg`,{width:`18`,height:`18`,viewBox:`0 0 48 48`,"aria-hidden":`true`,children:[h(`path`,{fill:`#EA4335`,d:`M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z`}),h(`path`,{fill:`#4285F4`,d:`M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z`}),h(`path`,{fill:`#FBBC05`,d:`M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z`}),h(`path`,{fill:`#34A853`,d:`M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z`})]})}function E(){return C(`13`,`1.75`,h(`path`,{d:`m9 6 6 6-6 6`}))}function lt(){return C(`14`,`1.6`,h(`path`,{d:`M12 3 4.5 6v5.5c0 4.2 2.7 7.4 7.5 9.5 4.8-2.1 7.5-5.3 7.5-9.5V6L12 3Z`}),h(`path`,{d:`m8.5 11.5 2.5 2.5 4.5-5`}))}function ut(){return C(`15`,`1.6`,h(`path`,{d:`M12 8v5`}),h(`path`,{d:`M12 16v.1`}),h(`circle`,{cx:`12`,cy:`12`,r:`9`}))}var dt=class extends Le{constructor(...e){super(...e),this.shownNotice=``}render(){let{notice:e,onRetry:t}=this.props;return e&&(this.shownNotice=e),h(`div`,{class:`seams-auth-footer`,"data-state":e?`notice`:`brand`,children:[h(`div`,{class:`seams-auth-footer-brand`,"aria-hidden":e?`true`:void 0,children:[lt(),` `,h(`span`,{children:`Secured by`}),` `,h(je,{})]}),h(`div`,{class:`seams-auth-footer-notice`,children:[ut(),h(`span`,{class:`seams-auth-footer-text`,"aria-hidden":`true`,children:this.shownNotice}),h(`button`,{class:`seams-auth-footer-action`,type:`button`,disabled:!e,onClick:t,children:`Try again`})]}),e?h(`p`,{class:`sr-only`,role:`alert`,children:e}):null]})}};function D(e){let t=we(e);return t===null?null:h(`p`,{class:`seams-otp-description`,children:[`Demo email code: `,h(`code`,{children:t})]})}const O=`seams-auth-menu-title`,k=`seams-auth-menu-account-list`;function A(e){return e.padEnd(6,` `).slice(0,6).split(``)}function j(e){return h(m,{children:h(`span`,{class:`seams-otp-slot ${e.trim()?`is-filled`:``}`,children:e})})}function ft(e){let t=e.kind===`recovery`?`:${e.stage}`:``;return`${e.kind}:${e.mode}:${e.status.kind}${t}`}function pt(e){return e.status.kind===`busy`?e.status.headline:e.status.kind===`recoverable`?e.status.message:e.stage===`passkey_ready`?`Recovery code accepted.`:e.stage===`sign_in_ready`?`Wallet recovered. Unlock it to continue.`:``}function M(e){return e.kind===`recovery`&&e.stage===`finalizing`}function mt(e){return e===`register`?{prompt:`Already have a wallet?`,action:`Unlock wallet`,nextMode:`login`}:{prompt:`Don't have a wallet?`,action:`Create a wallet`,nextMode:`register`}}function ht(e){return e===`register`?`Create a wallet`:`Unlock wallet`}function gt(e){return e===`register`?`Create wallet with passkey`:`Unlock with passkey`}function _t(e){return e.kind===`google_otp_login`||e.kind===`google_registration`?e.error||null:e.kind===`passkey`&&e.status.kind===`recoverable`&&e.status.reason===`error`?e.status.message:null}function vt(e,t){return h(m,{children:h(`div`,{class:`seams-link-device-dot-ring is-${e}`,"aria-hidden":`true`,children:[Array.from({length:12},(e,t)=>h(m,{children:h(`span`,{"data-dot-index":t})})),t?h(m,{children:h(`div`,{class:`seams-link-device-dot-ring-glyph`,children:t})}):null,h(`svg`,{class:`seams-link-device-dot-ring-check`,viewBox:`0 0 52 52`,fill:`none`,stroke:`currentColor`,"stroke-width":`2.5`,"stroke-linecap":`round`,"stroke-linejoin":`round`,children:h(`path`,{d:`m18.5 27 5 5 10-11`})})]})})}function yt(e){switch(e.kind){case`sending`:return{ring:`waiting`,heading:`Sending your code`,status:`Emailing a 6-digit code`,pending:!0,tone:`neutral`};case`resending`:return{ring:`waiting`,heading:`Sending a new code`,status:`Emailing a fresh 6-digit code`,pending:!0,tone:`neutral`};case`submitting`:return{ring:`waiting`,heading:`Checking your code`,status:`Verifying the code you entered`,pending:!0,tone:`neutral`};case`code_input`:return{ring:`idle`,heading:`Verify your email`,status:`Enter the 6-digit code we just sent.`,pending:!1,tone:`neutral`};case`incorrect`:return{ring:`idle`,heading:`Verify your email`,status:e.message,pending:!1,tone:`error`};case`expired`:return{ring:`idle`,heading:`That code expired`,status:e.message,pending:!1,tone:`error`};case`unavailable`:return{ring:`idle`,heading:`Email code unavailable`,status:e.message,pending:!1,tone:`error`};case`completed`:return{ring:`approved`,heading:`Email verified`,status:`Finishing linking this device`,pending:!0,tone:`neutral`}}}function bt(e){return v(e.accountOptions,e.selectedAccount).selectedAccount}function xt(e){return e.walletId}function N(e){return e.authMethod===`email_otp`?e.emailAddress:null}function St(e){if(!e)return`Saved wallets`;let t=N(e);return t?`Saved wallets. Selected wallet ID ${e.walletId}, email ${t}`:`Saved wallets. Selected ${e.walletId}`}function Ct(e){let t=e.filter(e=>e.authMethod===`passkey`),n=e.filter(e=>e.authMethod===`email_otp`);return[{authMethod:`passkey`,label:`Passkey`,accounts:t},{authMethod:`email_otp`,label:`Email OTP`,accounts:n}].filter(e=>e.accounts.length>0)}var wt=class extends Le{constructor(...e){super(...e),this.state={accountMenu:`closed`},this.accountMenuExitTimer=null,this.accountMenuChoice=null,this.previouslyFocusedElement=null,this.shouldFocusInitialControl=!0,this.contentResizeObserver=null,this.contentHeightFrame=null,this.previousLinkDeviceStateKind=null,this.previousRecoveryStage=null,this.lastMethod=`passkey`,this.queueContentHeightSync=()=>{this.contentHeightFrame!==null&&cancelAnimationFrame(this.contentHeightFrame),this.contentHeightFrame=requestAnimationFrame(this.syncContentHeight)},this.syncContentHeight=()=>{this.contentHeightFrame=null;let e=this.props.element.querySelector(`.seams-content-switcher`),t=this.props.element.querySelector(`.seams-content-sizer`);!e||!t||this.props.styles.setDynamicDeclarations(this.props.element.id+`-height`,`#`+this.props.element.id+` .seams-content-switcher`,{height:t.scrollHeight+`px`})},this.onKeydown=e=>{if(e.key===`Escape`){if(e.preventDefault(),this.viewModel&&M(this.viewModel))return;if(this.accountMenuOpen){this.closeAccountMenu();return}this.emitIntent({kind:`close`,reason:`escape`});return}if(e.key!==`Tab`)return;let t=this.focusableElements();if(t.length===0)return;let n=document.activeElement,r=t.indexOf(n instanceof HTMLElement?n:t[0]);e.shiftKey&&r<=0?(e.preventDefault(),t[t.length-1]?.focus()):!e.shiftKey&&r===t.length-1&&(e.preventDefault(),t[0]?.focus())},this.onBackClick=()=>{this.emitIntent({kind:`back`})},this.onKeyDown=e=>{if(e.key!==`Escape`||e.defaultPrevented)return;let t=this.viewModel;!t||t.kind!==`recovery`&&!b(t.status)||(e.preventDefault(),e.stopPropagation(),!M(t)&&this.emitIntent({kind:`back`}))},this.onIntentSwitchClick=()=>{let e=this.viewModel;e&&this.emitIntent({kind:`mode_selected`,mode:mt(e.mode).nextMode})},this.onRegistrationReroll=()=>{this.emitIntent({kind:`registration_reroll`})},this.onPasskeyNameInput=e=>{e.currentTarget instanceof HTMLInputElement&&this.emitIntent({kind:`passkey_name_changed`,passkeyName:e.currentTarget.value})},this.onLoginAccountSelect=e=>{let t=e.currentTarget;if(!(t instanceof HTMLButtonElement))return;let n=t.dataset.walletId,r=t.dataset.authMethod,i=this.viewModel;if(!n||i.kind!==`passkey`||i.mode!==`login`)return;let a=i.accountOptions.find(e=>e.walletId===n&&e.authMethod===r),o=bt(i);if(!a||!o||this.accountMenuChoice)return;let s=tt(t);if(!s)return;let c={chosen:a,previous:o};this.accountMenuChoice=c,this.emitIntent({kind:`login_account_selected`,walletId:a.walletId,authMethod:a.authMethod}),s.then(()=>{this.accountMenuChoice===c&&this.closeAccountMenu()})},this.onAccountMenuToggle=()=>{this.accountMenuOpen?this.closeAccountMenu():this.openAccountMenu()},this.onDocumentPointerDown=e=>{!this.accountMenuOpen||!(e.target instanceof Node)||this.props.element.querySelector(`.seams-account-menu`)?.contains(e.target)||this.closeAccountMenu()},this.onPrimaryClick=()=>{let e=this.viewModel;if(!e||!x(e)||e.kind===`link_device`)return;if(e.kind===`google_otp_login`){this.emitIntent({kind:`google_otp_submit`});return}if(e.kind===`google_registration`){this.emitIntent({kind:`google_registration_complete`});return}let t=e.mode===`register`?{kind:`submit`,mode:`register`,passkeyName:e.passkeyName}:{kind:`submit`,mode:`login`};this.lastMethod=`passkey`,this.emitIntent(t)},this.onGoogleOtpCodeInput=e=>{e.currentTarget instanceof HTMLInputElement&&this.emitIntent({kind:`google_otp_code_changed`,code:e.currentTarget.value})},this.onGoogleOtpKeydown=e=>{e.key===`Enter`&&(e.preventDefault(),this.emitIntent({kind:`google_otp_submit`}))},this.onGoogleOtpResend=()=>{this.emitIntent({kind:`google_otp_resend`})},this.onGoogleRegistrationReroll=()=>{this.emitIntent({kind:`google_registration_reroll`})},this.onGoogleClick=()=>{this.lastMethod=`google`,this.emitIntent({kind:`external_auth`,provider:`google`})},this.onNoticeRetry=()=>{this.lastMethod===`google`&&S(this.viewModel)?this.onGoogleClick():this.onPrimaryClick()},this.onLinkDeviceOpen=()=>{this.emitIntent({kind:`link_device_open`})},this.onRecoveryOpen=()=>{this.emitIntent({kind:`recovery_open`})},this.onRecoveryCodeInput=e=>{e.currentTarget instanceof HTMLInputElement&&this.emitIntent({kind:`recovery_code_changed`,recoveryCode:e.currentTarget.value})},this.onRecoverySubmit=e=>{e.preventDefault()},this.onRecoveryPasskeySelected=()=>{this.emitIntent({kind:`recovery_passkey_selected`})},this.onRecoveryGoogleSelected=()=>{this.emitIntent({kind:`recovery_google_selected`})},this.onRecoveryGoogleOtpCodeInput=e=>{e.currentTarget instanceof HTMLInputElement&&this.emitIntent({kind:`recovery_google_otp_code_changed`,code:e.currentTarget.value})},this.onRecoveryGoogleOtpKeydown=e=>{e.key===`Enter`&&(e.preventDefault(),this.emitIntent({kind:`recovery_google_otp_submit`}))},this.onRecoveryGoogleOtpSubmit=()=>{this.emitIntent({kind:`recovery_google_otp_submit`})},this.onRecoveryCreatePasskey=()=>{this.emitIntent({kind:`recovery_create_passkey`})},this.onRecoverySignIn=()=>{this.emitIntent({kind:`recovery_sign_in`})},this.onLinkDeviceCreatePasskey=()=>{this.emitIntent({kind:`link_device_create_passkey`})},this.onLinkDeviceFactorChange=e=>{if(!(e.currentTarget instanceof HTMLInputElement))return;let t=e.currentTarget.value===`email_otp`?{kind:`email_otp`}:{kind:`passkey_prf`};this.emitIntent({kind:`link_device_factor_selected`,targetFactor:t})},this.onLinkDeviceTargetEmailInput=e=>{e.currentTarget instanceof HTMLInputElement&&this.emitIntent({kind:`link_device_target_email_changed`,emailAddress:e.currentTarget.value})},this.onLinkDeviceStart=()=>{this.emitIntent({kind:`link_device_start`})},this.onLinkDeviceEmailOtpCodeInput=e=>{e.currentTarget instanceof HTMLInputElement&&this.emitIntent({kind:`link_device_email_otp_code_changed`,code:e.currentTarget.value})},this.onLinkDeviceEmailOtpKeydown=e=>{e.key===`Enter`&&(e.preventDefault(),this.emitIntent({kind:`link_device_email_otp_submit`}))},this.onLinkDeviceEmailOtpResend=()=>{this.emitIntent({kind:`link_device_email_otp_resend`})},this.onLinkDeviceEmailOtpSubmit=()=>{this.emitIntent({kind:`link_device_email_otp_submit`})}}get viewModel(){return this.props.viewModel}get accountMenuOpen(){return this.state.accountMenu===`open`}openAccountMenu(){this.endAccountMenuExit(),this.setState({accountMenu:`open`})}closeAccountMenu(){this.accountMenuOpen&&(this.setState({accountMenu:`closing`}),this.accountMenuExitTimer=setTimeout(()=>{this.endAccountMenuExit(),this.setState({accountMenu:`closed`})},160))}endAccountMenuExit(){this.accountMenuExitTimer!==null&&clearTimeout(this.accountMenuExitTimer),this.accountMenuExitTimer=null,this.accountMenuChoice=null}componentDidMount(){let e=document.activeElement;e instanceof HTMLElement&&!this.props.element.contains(e)&&(this.previouslyFocusedElement=e),document.addEventListener(`pointerdown`,this.onDocumentPointerDown),document.addEventListener(`keydown`,this.onKeyDown,!0),this.afterRender()}componentDidUpdate(e){this.afterRender(e.viewModel)}componentWillUnmount(){this.contentResizeObserver?.disconnect(),this.contentResizeObserver=null,this.contentHeightFrame!==null&&cancelAnimationFrame(this.contentHeightFrame),this.contentHeightFrame=null,this.endAccountMenuExit(),window.removeEventListener(`resize`,this.queueContentHeightSync),document.removeEventListener(`pointerdown`,this.onDocumentPointerDown),document.removeEventListener(`keydown`,this.onKeyDown,!0),this.props.styles.deleteDynamicRule(this.props.element.id+`-height`),this.restoreFocus()}afterRender(e){this.shouldFocusInitialControl&&this.focusInitialControl(),this.focusRecoveryControl(e),this.focusLinkDevicePasskeyAction(),this.observeContentSize(),this.queueContentHeightSync()}focusRecoveryControl(e){let t=this.viewModel;if(e?.kind===`recovery`&&t.kind!==`recovery`){this.previousRecoveryStage=null,this.props.element.querySelector(`[data-recovery-action]`)?.focus();return}if(t.kind!==`recovery`)return;let n=this.previousRecoveryStage!==t.stage;if(this.previousRecoveryStage=t.stage,t.stage===`enter_code`){let t=this.props.element.querySelector(`[aria-invalid="true"]`);if(t){t.focus();return}(e?.kind!==`recovery`||e.stage!==`enter_code`)&&this.props.element.querySelector(`[data-recovery-code]`)?.focus();return}let r=t.status.kind===`recoverable`&&e?.kind===`recovery`&&e.status.kind!==`recoverable`;(n||r)&&(t.stage===`passkey_ready`||t.stage===`finalizing`||t.stage===`sign_in_ready`)&&this.props.element.querySelector(`[data-auth-menu-primary]`)?.focus()}focusLinkDevicePasskeyAction(){let e=this.viewModel.kind===`link_device`?this.viewModel.linkDevice.kind:null,t=e===`passkey_required`&&this.previousLinkDeviceStateKind!==e;this.previousLinkDeviceStateKind=e,t&&this.props.element.querySelector(`[data-link-device-passkey-action]`)?.focus()}observeContentSize(){if(this.contentResizeObserver)return;let e=this.props.element.querySelector(`.seams-content-sizer`);e&&(this.contentResizeObserver=new ResizeObserver(this.queueContentHeightSync),this.contentResizeObserver.observe(e),window.addEventListener(`resize`,this.queueContentHeightSync))}focusInitialControl(){if(!this.props.element.isConnected||!this.shouldFocusInitialControl)return;this.shouldFocusInitialControl=!1;let e=document.activeElement;e instanceof HTMLElement&&this.props.element.contains(e)||this.props.element.querySelector(`[data-auth-menu-input], [data-auth-menu-primary]`)?.focus()}restoreFocus(){let e=this.previouslyFocusedElement;this.previouslyFocusedElement=null,e?.isConnected&&e.focus()}focusableElements(){return Array.from(this.props.element.querySelectorAll(`button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])`))}emitIntent(e){this.props.onIntent(e)}render(){let e=this.viewModel;if(!e)return h(m,{});let t=b(e.status),n=e.kind===`link_device`,r=e.kind===`google_otp_login`,i=e.kind===`google_registration`,a=e.kind===`recovery`;return h(m,{children:h(`div`,{class:`seams-signup-menu-root auth-menu-root`,"data-mode":e.mode,"data-waiting":t?`true`:`false`,"data-scan-device":n?`true`:`false`,"data-otp-prompt":r?`true`:`false`,"data-registration-prompt":i?`true`:`false`,"data-recovery":a?`true`:`false`,"aria-labelledby":O,"aria-busy":t?`true`:`false`,tabIndex:-1,onKeyDown:this.onKeydown,children:[h(`div`,{class:`seams-content-switcher`,children:[h(`button`,{class:`seams-back-button ${t||n||r||i||a?`is-visible`:``}`,type:`button`,"aria-label":a?`Back to unlock wallet`:`Back`,"data-auth-menu-close":!0,disabled:M(e),onClick:this.onBackClick,children:rt()}),a?h(`div`,{class:`sr-only`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:pt(e)}):null,h(`div`,{class:`seams-content-area`,children:h(`div`,{class:`seams-content-sizer`,children:t?this.renderWaiting(e):h(m,{children:h(`div`,{class:`seams-signin-menu`,children:h(m,{children:this.renderActiveView(e)},ft(e))})})})})]}),h(dt,{notice:_t(e),onRetry:this.onNoticeRetry})]})})}renderActiveView(e){return e.kind===`recovery`?this.renderRecovery(e):e.kind===`link_device`?this.renderLinkDevice(e):e.kind===`google_otp_login`?this.renderGoogleOtp(e):e.kind===`google_registration`?this.renderGoogleRegistration(e):h(m,{children:[this.renderMenuHeader(e),` `,this.renderPasskeyInput(e),this.renderAuthMethods(e),` `,this.renderOtherOptions(),this.renderIntentSwitch(e)]})}renderMenuHeader(e){let t=ht(e.mode);return h(`div`,{class:`seams-menu-header`,children:[h(`div`,{class:`seams-menu-origin`,children:[h(Ae,{}),` `,h(`span`,{children:e.hostname})]}),t===e.heading?null:h(`div`,{class:`seams-menu-eyebrow`,children:t}),h(`div`,{class:`seams-title`,id:O,children:e.heading}),e.subtitle?h(`div`,{class:`seams-subhead`,children:e.subtitle}):null]})}renderHeader(e){return h(m,{children:h(`div`,{class:`seams-header`,children:h(`div`,{children:[h(`div`,{class:`seams-title`,id:O,children:e.heading}),h(`div`,{class:`seams-subhead`,children:e.subtitle})]})})})}renderPasskeyInput(e){if(e.mode===`login`){let t=bt(e);if(!t)return h(m,{});let n=Ct(e.accountOptions),r=this.state.accountMenu,i=this.accountMenuChoice,a=i?.previous??t;return h(m,{children:h(`div`,{class:`seams-passkey-row`,children:h(`div`,{class:`seams-input-pill`,children:[h(`div`,{class:`seams-input-wrap`,children:h(`div`,{class:`seams-account-menu-account seams-selected-account`,"aria-hidden":`true`,children:[h(`span`,{class:`seams-account-menu-account-primary`,children:xt(t)}),N(t)?h(m,{children:h(`span`,{class:`seams-account-menu-account-secondary`,children:N(t)})}):null]})}),h(`div`,{class:`seams-account-menu ${r===`closed`?``:`is-open`}`,children:[h(`button`,{class:`seams-account-menu-trigger`,type:`button`,"data-auth-menu-input":!0,"aria-label":St(t),"aria-haspopup":`listbox`,"aria-expanded":this.accountMenuOpen?`true`:`false`,"aria-controls":k,onClick:this.onAccountMenuToggle,children:nt()}),r===`closed`?null:h(m,{children:h(`div`,{id:k,class:`seams-account-menu-popover ${r===`closing`?`is-closing`:``}`,role:`listbox`,children:n.map(e=>{let t=`${k}-${e.authMethod}`;return h(m,{children:h(`div`,{class:`seams-account-menu-group`,role:`group`,"aria-labelledby":t,children:[h(`div`,{id:t,class:`seams-account-menu-group-label`,children:e.label}),e.accounts.map(e=>{let t=e.walletId===a.walletId&&e.authMethod===a.authMethod,n=!t&&e.walletId===i?.chosen.walletId&&e.authMethod===i.chosen.authMethod,r=N(e);return h(m,{children:h(`button`,{class:`seams-account-menu-option ${t?`is-selected`:``} ${n?`is-chosen`:``}`,type:`button`,role:`option`,"aria-selected":t?`true`:`false`,title:r?`${e.walletId} ${r}`:e.walletId,"data-wallet-id":e.walletId,"data-auth-method":e.authMethod,onClick:this.onLoginAccountSelect,children:[h(`span`,{class:`seams-account-menu-check`,"aria-hidden":`true`}),h(`span`,{class:`seams-account-menu-account`,children:[h(`span`,{class:`seams-account-menu-account-primary`,children:e.walletId}),r?h(m,{children:h(`span`,{class:`seams-account-menu-account-secondary`,children:r})}):null]})]})})})]})})})})})]})]})})})}return e.showRegistrationInput?h(m,{children:h(`div`,{class:`seams-passkey-row`,children:h(`div`,{class:`seams-input-pill`,children:[h(`div`,{class:`seams-input-wrap`,children:h(`input`,{id:`seams-auth-menu-passkey-name`,class:`seams-input`,"data-auth-menu-input":!0,type:`text`,autocomplete:`nickname`,placeholder:e.passkeyNameLabel,value:e.passkeyName,readonly:e.passkeyNameReadOnly,disabled:b(e.status),onInput:this.onPasskeyNameInput})}),e.passkeyNameReadOnly?h(m,{children:h(`button`,{class:`seams-input-action-trigger auth-menu-registration-reroll`,type:`button`,title:`Generate another name`,"aria-label":`Generate another name`,onClick:this.onRegistrationReroll,disabled:!Qe(e),children:ct()})}):null]})})}):h(m,{})}renderAuthMethods(e){let t=e.enabledExternalProviders?.includes(`google`)??!1;return h(m,{children:h(`div`,{class:`seams-auth-methods`,children:[h(`button`,{class:`seams-auth-method-btn seams-auth-method-btn-primary`,type:`button`,"data-auth-menu-primary":!0,disabled:!x(e),onClick:this.onPrimaryClick,children:[w(),h(`span`,{children:gt(e.mode)})]}),t?h(`button`,{class:`seams-auth-method-btn`,type:`button`,"data-auth-menu-provider":`google`,disabled:!S(e),onClick:this.onGoogleClick,children:[T(),h(`span`,{children:`Continue with Google`})]}):null]})})}renderOtherOptions(){return h(m,{children:[h(`div`,{class:`seams-menu-options-label`,children:`Other options`}),h(`div`,{class:`seams-menu-options`,children:[h(`button`,{class:`seams-menu-option`,type:`button`,onClick:this.onLinkDeviceOpen,children:[h(`span`,{class:`seams-menu-option-icon`,children:it()}),h(`span`,{class:`seams-menu-option-text`,children:[`Link this device `,h(`small`,{children:`Scan a code with your other device`})]}),E()]}),h(`button`,{class:`seams-menu-option`,type:`button`,"data-recovery-action":!0,onClick:this.onRecoveryOpen,children:[h(`span`,{class:`seams-menu-option-icon`,children:at()}),h(`span`,{class:`seams-menu-option-text`,children:[`Recover wallet `,h(`small`,{children:`Use your recovery code`})]}),E()]})]})]})}renderRecovery(e){if(e.stage===`enter_code`){let t=e.status.kind===`recoverable`?e.status.message:``,n=e.recoveryCodeError??t,r=n.length>0;return h(m,{children:[this.renderHeader(e),h(`p`,{id:`seams-recovery-code-feedback`,class:`seams-recovery-status ${r?`seams-recovery-error`:``}`,"aria-hidden":r?`false`:`true`,role:r?`alert`:`status`,children:n}),h(`form`,{class:`seams-recovery-form`,novalidate:!0,onSubmit:this.onRecoverySubmit,children:[h(`div`,{class:`seams-recovery-field`,children:[h(`label`,{class:`seams-field-label`,for:`seams-recovery-code`,children:`Recovery code`}),h(`input`,{id:`seams-recovery-code`,class:`seams-recovery-input seams-recovery-code-input`,"data-recovery-code":!0,name:`recoveryCode`,type:`text`,autocomplete:`one-time-code`,autocapitalize:`characters`,autocorrect:`off`,spellcheck:!1,"aria-invalid":e.recoveryCodeError?`true`:`false`,"aria-describedby":e.recoveryCodeError?`seams-recovery-code-feedback`:``,value:e.recoveryCode,onInput:this.onRecoveryCodeInput})]}),h(`div`,{class:`seams-secondary-actions`,children:[h(`button`,{class:`seams-link-device-btn seams-auth-method-choice-btn`,type:`button`,"data-recovery-target":`passkey`,onClick:this.onRecoveryPasskeySelected,children:[h(`span`,{class:`seams-auth-method-choice-icon`,children:w()}),h(`span`,{children:`Recover with Passkey`})]}),h(`button`,{class:`seams-link-device-btn seams-auth-method-choice-btn`,type:`button`,"data-recovery-target":`google_email_otp`,onClick:this.onRecoveryGoogleSelected,children:[h(`span`,{class:`seams-auth-method-choice-icon`,children:T()}),h(`span`,{children:`Recover with Google`})]})]})]})]})}if(e.stage===`email_code_required`){let t=A(e.otpCode),n=/^\d{6}$/.test(e.otpCode)&&e.status.kind!==`busy`,r=e.delivery.status===`reused`?`Use the code already sent to ${e.emailHint}.`:`A 6-digit code was sent to ${e.emailHint}.`;return h(m,{children:[this.renderHeader(e),h(`div`,{class:`seams-otp-prompt`,"aria-live":`polite`,children:[h(`p`,{class:`seams-otp-description`,children:r}),D(e.delivery),h(`label`,{class:`seams-field-label`,for:`seams-recovery-google-otp`,children:`Email code`}),h(`div`,{class:`seams-otp-code-field`,"data-disabled":e.status.kind===`busy`?`true`:`false`,children:[h(`input`,{class:`seams-otp-input`,id:`seams-recovery-google-otp`,"data-auth-menu-input":!0,"data-email-otp-challenge-id":e.challengeId,"data-email-otp-wallet-id":e.walletId,name:`recoveryEmailOtpCode`,type:`text`,inputmode:`numeric`,autocomplete:`one-time-code`,spellcheck:!1,pattern:`[0-9]*`,maxLength:6,"aria-invalid":e.status.kind===`recoverable`?`true`:`false`,"aria-describedby":e.status.kind===`recoverable`?`seams-recovery-google-otp-error`:``,value:e.otpCode,disabled:e.status.kind===`busy`,onInput:this.onRecoveryGoogleOtpCodeInput,onKeyDown:this.onRecoveryGoogleOtpKeydown}),h(`div`,{class:`seams-otp-slots`,"aria-hidden":`true`,children:t.map(j)})]}),e.status.kind===`recoverable`?h(m,{children:h(`p`,{id:`seams-recovery-google-otp-error`,class:`seams-recovery-status seams-recovery-error`,role:`alert`,children:e.status.message})}):null,h(`button`,{class:`seams-link-device-btn seams-link-device-btn-primary`,type:`button`,"data-auth-menu-primary":!0,disabled:!n,onClick:this.onRecoveryGoogleOtpSubmit,children:`Verify email code`})]})]})}let t=e.stage===`finalizing`&&e.status.kind===`recoverable`,n=e.stage===`sign_in_ready`,r=e.target.kind===`google_email_otp`,i=e.status.kind===`recoverable`?e.status.message:n?null:e.stage===`google_ready`?`Continue with Google, then verify the code sent to your email.`:r?`Finishing recovery with Google…`:`Create a new passkey to finish recovering this wallet.`,a=n?this.onRecoverySignIn:r?t?this.onRecoveryGoogleOtpSubmit:this.onGoogleClick:this.onRecoveryCreatePasskey;return h(m,{children:[this.renderHeader(e),h(`div`,{class:`seams-recovery-confirmation`,children:[i===null?null:h(m,{children:h(`p`,{class:`seams-recovery-status`,children:i})}),h(`button`,{class:`seams-link-device-btn seams-link-device-btn-primary`,type:`button`,"data-auth-menu-primary":!0,onClick:a,children:[r&&!t?T():null,n?r?`Unlock with Google`:`Unlock with new passkey`:t?`Retry finalization`:r?`Continue with Google`:`Create new passkey`]})]})]})}renderIntentSwitch(e){let t=mt(e.mode);return h(m,{children:h(`div`,{class:`seams-auth-intent-switch`,children:[h(`span`,{children:t.prompt}),h(`button`,{type:`button`,"data-auth-menu-mode":t.nextMode,onClick:this.onIntentSwitchClick,children:t.action})]})})}renderWaiting(e){let t=e.status;if(t.kind!==`busy`)return h(m,{});let n=t.headline;return h(m,{children:h(`div`,{class:`seams-waiting`,role:`status`,"aria-live":`polite`,children:[h(`div`,{class:`seams-waiting-message`,children:[h(`span`,{class:`seams-waiting-text`,children:n}),e.showProgress&&t.detail&&t.detail!==n?h(m,{children:h(`span`,{class:`seams-waiting-sdk-events`,children:t.detail})}):null]}),h(`div`,{"aria-label":`Loading`,class:`seams-spinner`})]})})}renderLinkDevice(e){let t=e.linkDevice;if(t.kind===`select_factor`)return this.renderLinkDeviceFactorSelection(t);if(t.kind===`passkey_required`||t.kind===`creating_passkey`)return this.renderLinkDevicePasskeyConfirmation(t);if(t.kind===`email_otp_required`)return this.renderLinkDeviceEmailOtp(t);if(t.kind===`activating`)return this.renderLinkedDeviceActivation(t);if(t.kind===`expired`)return this.renderLinkDeviceFailurePanel({dismiss:`expired`,title:`Linking expired`,detail:t.message,action:`Try again`});if(t.kind===`cancelled`)return this.renderLinkDeviceFailurePanel({dismiss:`cancelled`,title:`Linking cancelled`,detail:t.message,action:`Return to unlock wallet`});if(t.kind===`error`||t.kind===`activation_error`)return this.renderLinkDeviceFailure(t);let n=t.kind===`ready`;return h(m,{children:h(`div`,{class:`seams-scan-device-content`,children:h(`div`,{class:`qr-code-container`,children:h(`div`,{class:`qr-body`,children:h(`div`,{class:`qr-code-section`,children:[h(`div`,{class:`qr-code-display`,children:n?h(m,{children:h(`img`,{src:t.qrCodeDataURL,alt:`QR code to link this device`,class:`qr-code-image`})}):h(m,{children:h(`div`,{class:`qr-code-placeholder`,children:h(`span`,{class:`seams-spinner`,"aria-hidden":`true`})})})}),h(`div`,{class:`qr-header`,children:h(`h2`,{class:`qr-title`,id:O,children:e.heading})}),h(`div`,{class:`qr-instruction`,children:n?e.subtitle:`Preparing a one-time code for your other device.`}),h(`div`,{class:`qr-status`,role:`status`,"aria-live":`polite`,children:[n?t.message:`Generating QR code`,h(`span`,{class:`animated-ellipsis`})]})]})})})})})}renderLinkDeviceFactorSelection(e){let t=e.targetFactor.kind===`email_otp`,n=e.targetFactor.kind===`email_otp`&&typeof e.targetEmail==`string`?e.targetEmail:``,r=!t||me(n);return h(m,{children:h(`div`,{class:`seams-link-device-confirmation`,children:[h(`h2`,{class:`qr-title`,id:O,children:`Match your other device`}),h(`p`,{class:`seams-link-device-confirmation-copy`,children:`Choose the unlock method for Device 2. Email code sends a one-time code to the address you enter.`}),h(`fieldset`,{class:`seams-link-device-factor-options`,children:[h(`legend`,{class:`sr-only`,children:`Wallet unlock method`}),h(`label`,{children:[h(`span`,{class:`seams-auth-method-choice-icon`,children:w()}),h(`span`,{class:`seams-auth-method-choice-label`,children:`Passkey`}),h(`input`,{type:`radio`,name:`linked-device-factor`,value:`passkey_prf`,checked:e.targetFactor.kind===`passkey_prf`,onChange:this.onLinkDeviceFactorChange})]}),h(`label`,{children:[h(`span`,{class:`seams-auth-method-choice-icon`,children:ot()}),h(`span`,{class:`seams-auth-method-choice-label`,children:`Email code`}),h(`input`,{type:`radio`,name:`linked-device-factor`,value:`email_otp`,checked:e.targetFactor.kind===`email_otp`,onChange:this.onLinkDeviceFactorChange})]})]}),t?h(m,{children:h(`label`,{class:`seams-link-device-target-email`,children:[h(`span`,{class:`seams-field-label`,children:`Email address`}),h(`input`,{type:`email`,name:`linked-device-target-email`,autocomplete:`email`,value:n,"aria-label":`Email address`,"aria-invalid":n.length>0&&!r?`true`:`false`,onInput:this.onLinkDeviceTargetEmailInput})]})}):null,e.error?h(m,{children:h(`p`,{class:`seams-link-device-inline-error`,role:`alert`,children:e.error})}):null,h(`button`,{class:`seams-link-device-btn seams-link-device-btn-primary`,type:`button`,"data-auth-menu-primary":!0,disabled:!r,onClick:this.onLinkDeviceStart,children:`Continue`})]})})}renderLinkDeviceEmailOtp(e){let t=e.state,n=yt(t),r=t.kind===`sending`||t.kind===`submitting`||t.kind===`resending`,i=e.otpCode.length===6&&(t.kind===`code_input`||t.kind===`incorrect`),a=t.kind!==`completed`&&t.kind!==`expired`&&t.kind!==`unavailable`,o=`maskedEmailHint`in t?t.maskedEmailHint:``,s=A(e.otpCode);return h(m,{children:h(`div`,{class:`seams-link-device-confirmation seams-link-device-email-otp`,"data-tone":n.tone,"data-otp-phase":t.kind,children:[vt(n.ring,ot()),h(`h2`,{class:`qr-title`,id:O,children:n.heading}),o?h(m,{children:h(`div`,{class:`seams-link-device-email-chip`,title:o,children:h(`span`,{children:o})})}):null,h(`p`,{class:`seams-link-device-email-status`,id:`seams-linked-device-otp-status`,role:`status`,"aria-live":`polite`,children:[n.status,n.pending?h(m,{children:h(`span`,{class:`animated-ellipsis`,"aria-hidden":`true`})}):null]}),a?h(m,{children:[h(`label`,{class:`sr-only`,for:`seams-linked-device-email-otp`,children:`Email code`}),h(`div`,{class:`seams-otp-code-field`,"data-disabled":r?`true`:`false`,children:[h(`input`,{class:`seams-otp-input`,id:`seams-linked-device-email-otp`,"data-auth-menu-input":!0,type:`text`,inputmode:`numeric`,autocomplete:`one-time-code`,pattern:`[0-9]*`,maxLength:6,"aria-label":`Email verification code`,"aria-describedby":`seams-linked-device-otp-status`,"aria-invalid":t.kind===`incorrect`?`true`:`false`,value:e.otpCode,disabled:r,onInput:this.onLinkDeviceEmailOtpCodeInput,onKeyDown:this.onLinkDeviceEmailOtpKeydown}),h(`div`,{class:`seams-otp-slots`,"aria-hidden":`true`,children:s.map(j)})]})]}):null,this.renderLinkDeviceEmailOtpActions(t,{busy:r,canSubmit:i})]})})}renderLinkDeviceEmailOtpActions(e,t){return e.kind===`completed`?null:e.kind===`unavailable`?h(m,{children:h(`button`,{class:`seams-link-device-btn`,type:`button`,"data-link-device-error-dismiss":!0,onClick:this.onBackClick,children:`Return to unlock wallet`})}):e.kind===`expired`?h(m,{children:h(`button`,{class:`seams-link-device-btn seams-link-device-btn-primary`,type:`button`,onClick:this.onLinkDeviceEmailOtpResend,children:`Send a new code`})}):h(m,{children:[h(`button`,{class:`seams-link-device-btn seams-link-device-btn-primary`,type:`button`,disabled:!t.canSubmit,onClick:this.onLinkDeviceEmailOtpSubmit,children:e.kind===`submitting`?`Verifying`:`Verify code`}),h(`button`,{class:`seams-otp-resend`,type:`button`,disabled:t.busy,onClick:this.onLinkDeviceEmailOtpResend,children:`Send another code`})]})}renderLinkDeviceFailure(e){let t=e.kind===`activation_error`;return this.renderLinkDeviceFailurePanel({dismiss:`error`,title:t?`Device linked`:`Couldn't link device`,detail:t?h(m,{children:[`Unable to open the wallet. Go back and try again. `,e.message]}):e.message,action:`Return to unlock wallet`})}renderLinkDeviceFailurePanel(e){return h(m,{children:h(`div`,{class:`seams-link-device-confirmation seams-link-device-failure`,children:[h(`div`,{class:`seams-link-device-failure-icon`,children:st()}),h(`h2`,{class:`qr-title`,id:O,children:e.title}),h(`p`,{class:`seams-link-device-failure-detail`,role:`alert`,children:e.detail}),h(`button`,{class:`seams-link-device-btn`,type:`button`,"data-auth-menu-primary":!0,[`data-link-device-${e.dismiss}-dismiss`]:!0,onClick:this.onBackClick,children:e.action})]})})}renderLinkedDeviceActivation(e){return h(m,{children:h(`div`,{class:`seams-link-device-confirmation`,children:[h(`span`,{class:`seams-spinner`,"aria-hidden":`true`}),h(`h2`,{class:`qr-title`,id:O,children:`Opening linked wallet`}),h(`p`,{class:`seams-link-device-confirmation-copy`,role:`status`,"aria-live":`polite`,children:e.message})]})})}renderLinkDevicePasskeyConfirmation(e){let t=e.kind===`creating_passkey`;return h(m,{children:h(`div`,{class:`seams-link-device-confirmation`,children:[vt(t?`waiting`:`approved`),h(`h2`,{class:`qr-title`,id:O,"aria-live":`polite`,children:e.message}),h(`button`,{class:`seams-link-device-btn seams-link-device-btn-primary`,type:`button`,"data-auth-menu-primary":!0,"data-link-device-passkey-action":!0,disabled:t,onClick:this.onLinkDeviceCreatePasskey,children:t?`Waiting for passkey`:`Create passkey`})]})})}renderGoogleOtp(e){let t=e.delivery.status===`reused`?`Use the code already sent to ${e.emailHint}.`:`A 6-digit code was sent to ${e.emailHint}.`,n=A(e.otpCode);return h(m,{children:h(`div`,{class:`seams-otp-prompt`,"aria-live":`polite`,children:[h(`div`,{class:`seams-otp-prompt-copy`,children:[h(`div`,{class:`seams-otp-title`,id:O,children:e.heading}),h(`p`,{class:`seams-otp-description`,children:t}),D(e.delivery),h(`div`,{class:`seams-otp-account`,title:e.walletId,children:[h(`span`,{class:`seams-otp-account-label`,children:`Wallet`}),h(`span`,{class:`seams-otp-account-value`,children:e.walletId})]})]}),h(`label`,{class:`seams-field-label`,for:`seams-auth-menu-google-otp`,children:`Email code`}),h(`div`,{class:`seams-otp-code-field`,"data-disabled":e.submitBusy?`true`:`false`,children:[h(`input`,{class:`seams-otp-input`,id:`seams-auth-menu-google-otp`,"data-auth-menu-input":!0,"data-email-otp-challenge-id":e.challengeId,"data-email-otp-wallet-id":e.walletId,type:`text`,inputmode:`numeric`,autocomplete:`one-time-code`,pattern:`[0-9]*`,maxLength:6,value:e.otpCode,disabled:e.submitBusy,onInput:this.onGoogleOtpCodeInput,onKeyDown:this.onGoogleOtpKeydown}),h(`div`,{class:`seams-otp-slots`,"aria-hidden":`true`,children:n.map(j)})]}),h(`p`,{class:`seams-otp-helper`,children:e.prompt.helperText??``}),h(`button`,{class:`seams-auth-method-btn seams-auth-method-btn-primary`,type:`button`,"data-auth-menu-primary":!0,disabled:!x(e),onClick:this.onPrimaryClick,children:e.submitBusy?`Unlocking…`:e.ctaLabel}),h(`button`,{class:`seams-otp-resend auth-menu-google-resend`,type:`button`,disabled:e.resendBusy||e.submitBusy,onClick:this.onGoogleOtpResend,children:e.resendBusy?`Sending…`:`Resend Code`})]})})}renderGoogleRegistration(e){return h(m,{children:h(`div`,{class:`seams-otp-prompt`,"aria-live":`polite`,children:[h(`div`,{class:`seams-otp-prompt-copy`,children:[h(`div`,{class:`seams-otp-title`,id:O,children:e.heading}),h(`p`,{class:`seams-otp-description`,children:e.subtitle}),h(`div`,{class:`seams-otp-account`,title:e.walletId,children:[h(`span`,{class:`seams-otp-account-label`,children:`Wallet`}),h(`span`,{class:`seams-otp-account-value`,children:e.walletId})]}),h(`button`,{class:`seams-otp-reroll`,type:`button`,disabled:e.rerollBusy||e.submitBusy,onClick:this.onGoogleRegistrationReroll,children:e.rerollBusy?`Generating…`:`Generate another name`})]}),h(`button`,{class:`seams-auth-method-btn seams-auth-method-btn-primary`,type:`button`,"data-auth-menu-primary":!0,disabled:!x(e),onClick:this.onPrimaryClick,children:e.submitBusy?`Creating...`:e.ctaLabel})]})})}};const P=new WeakMap;let Tt=0;function Et(e){let t=P.get(e);return t||(t=Fe({doc:e,baseCss:``,dynamicStyleDataAttr:`data-seams-auth-menu-dynamic`,nonce:Ne}),P.set(e,t)),t}var Dt=class{constructor(e){this.cancel=()=>{this.state.kind===`mounted`&&this.state.onIntent({kind:`close`,reason:`close_button`})};let t=e.parent.ownerDocument;this.styles=Et(t),this.element=t.createElement(`div`),this.element.className=`seams-wallet-ui seams-auth-menu-surface`,this.element.id=`seams-auth-menu-${++Tt}`,this.state={kind:`mounted`,onIntent:e.onIntent},this.element.addEventListener(`cancel`,this.cancel),e.parent.appendChild(this.element);try{this.update(e.viewModel)}catch(e){throw this.dispose(),e}}update(e){this.state.kind!==`disposed`&&(this.element.dataset.theme=e.appearance.theme.mode,this.styles.setDynamicRule(this.element.id+`-appearance`,Ie(this.element.id,e.appearance)),Pe(h(wt,{element:this.element,viewModel:e,onIntent:this.state.onIntent,styles:this.styles}),this.element))}dispose(){this.state.kind!==`disposed`&&(this.state={kind:`disposed`},this.element.removeEventListener(`cancel`,this.cancel),Pe(null,this.element),this.styles.deleteDynamicRule(this.element.id+`-appearance`),this.element.remove())}};function Ot(e){return new Dt(e)}const F=Symbol(`hostedPasskeyLoginPrepared`),kt=Symbol(`hostedPasskeyAccountSyncPrepared`),I=300*1e3;function L(e){return{signingEngine:e.signingEngine,nearClient:e.nearClient,configs:e.configs,theme:e.theme,resumePendingAcknowledgementsV1:e.resumePendingAcknowledgementsV1}}const R=new WeakMap;function At(e){return e.signal}function z(e){if(At(e).aborted)throw Error(`Hosted auth-menu passkey preparation was cancelled`)}function jt(e){if(Date.now()>=e.expiresAtMs)throw W(e),Error(`Hosted auth-menu passkey preparation expired`)}function B(e){let t=R.get(e);if(!t)throw Error(`Hosted auth-menu passkey preparation is unknown`);if(t.lifecycle!==`ready`)throw Error(`Hosted auth-menu passkey preparation is no longer usable`);if(Date.now()>=e.expiresAtMs)throw W(e),Error(`Hosted auth-menu passkey preparation expired`);return z(e.cancellation),t}function Mt(e){return{id:String(e.credentialId||``).trim(),type:`public-key`,transports:Array.isArray(e.transports)?e.transports:[]}}function V(e){return{authMenuSessionId:e.authMenuSessionId,requestId:e.requestId}}async function H(e){z(e.cancellation);let t=Te(e.walletId),n=await se(String(t));if(n){z(e.cancellation);let r=Object.freeze({kind:`hosted_passkey_linked_authority_login_prepared_v1`,...V(e),walletId:t,selection:n,expiresAtMs:Date.now()+I,cancellation:e.cancellation,[F]:!0});return R.set(r,{context:e.context,loginOptions:{},syncOptions:{},lifecycle:`ready`,authority:null}),r}let r=await ge({walletId:String(t),requestedCapabilityFamilies:{kind:`all_registered_mpc`}}),i=r.kind===`resolved`?r.subjectSet:await oe(String(t));if(!i)return await U({context:e.context,walletId:null,authMenuSessionId:e.authMenuSessionId,requestId:e.requestId,cancellation:e.cancellation});z(e.cancellation);let a=Object.freeze({kind:`hosted_passkey_owner_login_prepared_v1`,...V(e),walletId:t,subjectSet:i,expiresAtMs:Date.now()+I,cancellation:e.cancellation,[F]:!0});return R.set(a,{context:e.context,loginOptions:{},syncOptions:{},lifecycle:`ready`,authority:null}),a}async function U(e){z(e.cancellation);let t=await ue(e.context,e.walletId);z(e.cancellation);let n=Object.freeze({kind:`hosted_passkey_account_sync_prepared_v1`,authMenuSessionId:e.authMenuSessionId,requestId:e.requestId,challenge:t,expiresAtMs:Date.now()+I,cancellation:e.cancellation,[kt]:!0});return R.set(n,{context:e.context,loginOptions:{},syncOptions:{},lifecycle:`ready`,authority:null}),n}function Nt(e){let t=B(e);t.lifecycle=`consuming`;let n={subjectId:e.challenge.walletId||`account-sync`,challengeB64u:e.challenge.syncOptions.challengeB64u,allowCredentials:e.challenge.syncOptions.credentialIds.map(e=>Mt({credentialId:e}))},r;try{r=t.context.signingEngine.getAuthenticationCredentialsSerialized({...n,includeSecondPrfOutput:!1})}catch(e){throw t.lifecycle=`cancelled`,e}return t.authority=r,r.then(()=>{t.lifecycle===`consuming`&&(t.lifecycle=`consumed`)},()=>{t.lifecycle===`consuming`&&(t.lifecycle=`cancelled`)}),r}function Pt(e){let t=R.get(e);if(!t)throw Error(`Hosted auth-menu passkey preparation is unknown`);if(t.lifecycle!==`consuming`&&t.lifecycle!==`consumed`||!t.authority)throw Error(`Hosted auth-menu passkey credential must be started by its CTA`);return t.lifecycle=`completing`,t}async function Ft(e){let t=B(e);t.lifecycle=`completing`;let n=!1,r=e=>{e.phase===Oe.CANCELLED&&(n=!0)};try{let i=t.loginOptions.onEvent,a={...t.loginOptions,onEvent:e=>{r(e),i?.(e)}},o=e.kind===`hosted_passkey_linked_authority_login_prepared_v1`?await te(t.context,String(e.walletId),a):await pe(t.context,e.subjectSet,a);return o.success?t.context.resumePendingAcknowledgementsV1():u(),{result:o,cancelledByUser:n}}finally{t.lifecycle=`finished`}}async function It(e){let t=Pt(e),n=t.authority;if(!n)throw Error(`Hosted auth-menu passkey credential is missing`);try{let r=await n;return jt(e),z(e.cancellation),await ie(t.context,e.challenge,r,t.syncOptions)}finally{t.lifecycle=`finished`}}function W(e){let t=R.get(e);!t||t.lifecycle===`finished`||t.lifecycle===`cancelled`||(t.lifecycle=`cancelled`)}function G(e){if(e.kind===`hosted_passkey_registration_prepared_v1`){be(e);return}W(e)}function K(){}function Lt(e){return e.target.kind===`passkey`}function Rt(e){return e.kind===`recovery`&&e.stage===`finalizing`&&(e.operation.kind===`hosted_recovery_credential_created`||e.operation.kind===`hosted_recovery_email_otp_verified`)}function zt(e){return e.targetFactor.kind===`email_otp`?{targetFactor:e.targetFactor,targetEmail:ee(e.targetEmail)}:{targetFactor:e.targetFactor}}const Bt={kind:`recoverable`,reason:`error`,message:`Google sign-in was cancelled.`};function q(e){let t=e.mode??e.request.initialMode,n=e.request.copy[t],r={kind:`passkey`,appearance:e.appearance,hostname:e.hostname,closeLabel:e.request.copy.common.closeLabel,heading:n.title,subtitle:n.subtitle,ctaLabel:n.passkeyCta,showProgress:e.request.showProgress,enabledExternalProviders:e.request.enabledExternalProviders,status:{kind:`idle`,interaction:`arming`}};return t===`register`?{...r,mode:t,showRegistrationInput:e.request.showRegistrationInput||e.request.registrationAccountInput===`sponsored_named_near_account`,passkeyNameReadOnly:e.request.registrationAccountInput===`implicit_wallet`,passkeyName:e.request.registrationAccountInput===`implicit_wallet`?String(Ee()):``,passkeyNameLabel:e.request.copy.register.passkeyNameLabel}:{...r,mode:t,accountOptions:[],selectedAccount:null}}function Vt(e){let t=q({...e,mode:`login`});if(t.kind!==`passkey`||t.mode!==`login`)throw Error(`login view model construction failed`);return t}async function Ht(e){let[t]=await Promise.allSettled([e,new Promise(e=>setTimeout(e,500))]);if(t.status===`rejected`)throw t.reason;return t.value}function Ut(e){return e.trim()||`Wallet`}function Wt(e){return`close_button`}function J(){try{let e=globalThis.crypto?.randomUUID?.();if(e)return`auth-menu-external-${e}`}catch{}return`auth-menu-external-${Date.now()}-${Math.random().toString(36).slice(2)}`}function Gt(e){return{appearance:e.base.appearance,hostname:e.base.hostname,closeLabel:e.base.closeLabel,heading:e.flow.prompt.title,subtitle:e.flow.prompt.description,ctaLabel:e.flow.prompt.submitLabel,showProgress:e.base.showProgress,enabledExternalProviders:e.base.enabledExternalProviders,status:e.status}}function Kt(e){let t=`google-email-otp-login:${e.flow.walletId}:`;if(!e.flow.flowId.startsWith(t))throw Error(`Google Email OTP login flow identity is invalid`);return{...Gt({base:e.base,flow:e.flow,status:e.status??{kind:`idle`,interaction:`actionable`}}),kind:`google_otp_login`,mode:`login`,emailHint:e.flow.emailHint,walletId:String(e.flow.walletId),challengeId:e.flow.flowId.slice(t.length),prompt:e.flow.prompt,delivery:e.flow.delivery,otpCode:e.otpCode??``,resendBusy:e.resendBusy??!1,submitBusy:e.submitBusy??!1,...e.error?{error:e.error}:{}}}function qt(e){return{...Gt({base:e.base,flow:e.flow,status:e.status??{kind:`idle`,interaction:`actionable`}}),kind:`google_registration`,mode:`register`,emailHint:e.flow.emailHint,walletId:String(e.flow.walletId),prompt:e.flow.prompt,rerollBusy:e.rerollBusy??!1,submitBusy:e.submitBusy??!1,...e.error?{error:e.error}:{}}}function Y(e){return e instanceof Error&&e.message.trim()?e.message.trim():String(e)}function Jt(e){switch(e.kind){case`passkey`:return e.status.kind===`recoverable`?{mode:e.mode,message:e.status.detail??e.status.message}:null;case`google_otp_login`:case`google_registration`:return e.error?{mode:e.mode,message:e.error}:e.status.kind===`recoverable`?{mode:e.mode,message:e.status.message}:null;case`link_device`:return null;case`recovery`:return e.stage===`sign_in_ready`&&e.status.kind===`recoverable`?{mode:`login`,message:e.status.detail??e.status.message}:null;default:{let t=e;throw Error(`Unknown auth-menu view model: ${JSON.stringify(t)}`)}}}function Yt(e){return{kind:`link_device`,appearance:e.appearance,hostname:e.hostname,closeLabel:e.closeLabel,heading:`Scan and link device`,subtitle:`Scan this code with your other device.`,ctaLabel:``,showProgress:e.showProgress,enabledExternalProviders:e.enabledExternalProviders,status:{kind:`idle`,interaction:`actionable`},mode:e.mode,linkDevice:{kind:`select_factor`,targetFactor:{kind:`passkey_prf`}}}}function X(e){let t={kind:`recovery`,mode:`login`,appearance:e.base.appearance,hostname:e.base.hostname,closeLabel:e.base.closeLabel,heading:`Recover wallet`,subtitle:e.stage===`sign_in_ready`?e.target.kind===`google_email_otp`?`Your Google account is ready to unlock your wallet.`:`Your wallet is ready. Unlock it with your passkey.`:`Enter a recovery code to recover your wallet.`,ctaLabel:e.stage===`passkey_ready`?`Create new passkey`:e.stage===`google_ready`?`Continue with Google`:e.stage===`email_code_required`?`Verify email code`:e.stage===`sign_in_ready`?e.target.kind===`google_email_otp`?`Unlock with Google`:`Unlock with new passkey`:e.stage===`preparing`?e.target.kind===`google_email_otp`?`Recover with Google`:`Recover with Passkey`:`Continue`,showProgress:e.base.showProgress,enabledExternalProviders:e.base.enabledExternalProviders,recoveryCode:e.recoveryCode??``,recoveryCodeError:e.recoveryCodeError??null};switch(e.stage){case void 0:case`enter_code`:return{...t,stage:`enter_code`,status:e.status??{kind:`idle`,interaction:`actionable`}};case`preparing`:return{...t,stage:e.stage,target:e.target,status:e.status};case`passkey_ready`:return{...t,target:e.target,walletId:e.walletId,stage:e.stage,status:e.status??{kind:`idle`,interaction:`actionable`}};case`google_ready`:return{...t,target:e.target,walletId:e.walletId,stage:e.stage,status:e.status??{kind:`idle`,interaction:`actionable`}};case`email_code_required`:return{...t,target:e.target,walletId:e.walletId,stage:e.stage,challengeId:e.challengeId,emailHint:e.emailHint,delivery:e.delivery,otpCode:e.otpCode??``,status:e.status??{kind:`idle`,interaction:`awaiting_input`}};case`finalizing`:return{...t,target:e.target,walletId:e.walletId,stage:e.stage,status:e.status};case`sign_in_ready`:return{...t,target:e.target,walletId:e.walletId,stage:e.stage,status:e.status??{kind:`idle`,interaction:`actionable`}}}}function Z(e){if(e.stage===`enter_code`||e.stage===`preparing`)throw Error(`recovery wallet id is unavailable before preparation`);return e.walletId}function Q(e){if(e.stage===`enter_code`)throw Error(`recovery target is unavailable before preparation`);return e.target}function $(e){return e.kind===`dismissed`?{kind:`idle`,interaction:`actionable`}:{kind:`recoverable`,reason:`error`,message:e.kind===`consumed`?`That recovery code has already been used. Use another code.`:`That recovery code can’t be used. Check the code and try again.`}}function Xt(){return{kind:`recoverable`,reason:`error`,message:`Recovery couldn’t be completed. Try again.`}}function Zt(e){return e.kind===`dismissed`?{kind:`idle`,interaction:`actionable`}:{kind:`recoverable`,reason:`error`,message:`A passkey couldn’t be created. Try again.`}}var Qt=class{constructor(e){this.surface=null,this.outcomeResolver=null,this.outcomePromise=null,this.cleanedUp=!1,this.prepared=null,this.preparePasskey=null,this.registrationPreparation=null,this.preparationCancellation=null,this.googleCancellation=null,this.loginPreparation=null,this.loginAccountOptions=[],this.selectedLoginAccount=null,this.modeSelectionSource=`initial`,this.measurementReporter=null,this.preparationGeneration=0,this.googleGeneration=0,this.deviceLinkGeneration=0,this.linkedDeviceActivationInProgress=!1,this.targetPasskeyActivation=null,this.targetEmailOtpActivation=null,this.linkedDeviceEmailOtpSendStarted=!1,this.linkedDeviceTargetFactor={kind:`passkey_prf`},this.linkedDeviceTargetEmailAddress=``,this.preparationDeadlineTimer=null,this.preparationExpiryTimer=null,this.lastReportedError=null,this.recoveryGeneration=0,this.recoveryCancellation=null,this.recoveryLoginPrepared=null,this.recoveryReturnState=null,this.prepareSelectedLogin=e=>{if(!this.loginPreparation)throw Error(`Hosted login preparation is unavailable`);let t=v(this.loginAccountOptions,this.selectedLoginAccount);if(!y(t))throw Error(`Email OTP accounts require Google sign-in`);return this.loginPreparation(t.kind===`discoverable`?null:t.walletId,e)},this.postSurfaceMeasurement=e=>{this.sendToParent({type:`SURFACE_MEASUREMENT`,payload:e})},this.onIntent=e=>{switch(e.kind){case`mode_selected`:this.selectMode(e.mode);return;case`back`:this.back();return;case`link_device_open`:this.openLinkDevice();return;case`recovery_open`:this.openRecovery();return;case`recovery_code_changed`:this.changeRecoveryCode(e.recoveryCode);return;case`recovery_passkey_selected`:this.prepareRecovery(`passkey`);return;case`recovery_google_selected`:this.prepareRecovery(`google_email_otp`);return;case`recovery_google_otp_code_changed`:this.changeRecoveryGoogleOtpCode(e.code);return;case`recovery_google_otp_submit`:this.submitRecoveryGoogleOtp();return;case`recovery_create_passkey`:this.createRecoveryPasskey();return;case`recovery_sign_in`:this.signInRecoveredWallet();return;case`link_device_factor_selected`:this.selectLinkedDeviceTargetFactor(e.targetFactor);return;case`link_device_target_email_changed`:this.changeLinkedDeviceTargetEmailAddress(e.emailAddress);return;case`link_device_start`:this.startSelectedDeviceLinking();return;case`link_device_create_passkey`:this.createLinkedDevicePasskey();return;case`link_device_email_otp_code_changed`:this.changeLinkedDeviceEmailOtpCode(e.code);return;case`link_device_email_otp_resend`:this.resendLinkedDeviceEmailOtp();return;case`link_device_email_otp_submit`:this.submitLinkedDeviceEmailOtp();return;case`registration_reroll`:this.rerollRegistrationWallet();return;case`close`:this.cancel(Wt(e));return;case`passkey_name_changed`:{let t=this.stateValue.kind===`preparing`||this.stateValue.kind===`ready`?this.stateValue.viewModel:null;t?.kind===`passkey`&&t.mode===`register`&&!t.passkeyNameReadOnly&&(this.invalidatePreparation(),this.stateValue={kind:`preparing`,viewModel:{...t,passkeyName:e.passkeyName,status:{kind:`idle`,interaction:`arming`}}},this.updateElement(),this.startPasskeyPreparation());return}case`login_account_selected`:this.selectLoginAccount(e.walletId,e.authMethod);return;case`submit`:if(this.stateValue.kind===`preparing`&&this.stateValue.viewModel.status.kind===`recoverable`){this.retryPreparation();return}this.stateValue.kind===`ready`&&this.prepared===this.stateValue.prepared&&(e.mode===`register`&&this.stateValue.prepared.kind===`hosted_passkey_registration_prepared_v1`||e.mode===`login`&&(this.stateValue.prepared.kind===`hosted_passkey_owner_login_prepared_v1`||this.stateValue.prepared.kind===`hosted_passkey_linked_authority_login_prepared_v1`||this.stateValue.prepared.kind===`hosted_passkey_account_sync_prepared_v1`))&&this.performPreparedPasskey(this.stateValue.prepared);return;case`external_auth`:this.requestExternalAuth(e.provider);return;case`google_otp_code_changed`:this.updateGoogleOtpCode(e.code);return;case`google_otp_resend`:this.resendGoogleOtp();return;case`google_otp_submit`:this.submitGoogleOtp();return;case`google_registration_reroll`:this.rerollGoogleRegistration();return;case`google_registration_complete`:this.completeGoogleRegistration();return;case`retry`:this.retryPreparation();return;default:return $t(e)}},this.identity={authMenuSessionId:e.request.authMenuSessionId,requestId:e.requestId},this.request=e.request,this.beginGoogleEmailOtp=e.beginGoogleEmailOtp,this.startDeviceLinking=e.startDeviceLinking,this.cancelDeviceLinking=e.cancelDeviceLinking,this.recoveryPort=e.recoveryPort,this.prepareRecoveredLogin=e.prepareRecoveredLogin,this.sendToParent=e.sendToParent,this.stateValue={kind:`preparing`,viewModel:q({request:e.request,appearance:e.appearance,hostname:Ut(e.hostname)})}}get state(){return this.stateValue}setRegistrationPreparation(e){this.registrationPreparation=e,this.stateValue.kind!==`complete`&&this.currentViewModel().mode===`register`&&(this.preparePasskey=null,this.startPasskeyPreparation())}setPasskeyPreparation(e){this.preparePasskey=e,this.startPasskeyPreparation()}setLoginPreparation(e){let t=this.stateValue.kind===`complete`?null:this.currentViewModel();t?.kind===`passkey`&&t.mode===`login`&&(this.stateValue.kind===`preparing`||this.stateValue.kind===`ready`)&&this.invalidatePreparation(),this.loginPreparation=e.prepare,this.loginAccountOptions=e.accountOptions,this.selectedLoginAccount=e.selectedAccount,this.updateLoginSelectionViewModel(),(this.stateValue.kind===`preparing`||this.stateValue.kind===`ready`)&&this.currentViewModel().mode===`login`&&this.activateSelectedLoginMethod()}defaultToLoginForDetectedLocalWallet(){if(this.modeSelectionSource!==`initial`||this.stateValue.kind===`complete`)return;let e=this.currentViewModel();e.kind!==`passkey`||e.mode!==`register`||this.showPasskeyMode(`login`)}activateSelectedLoginMethod(){if(y(v(this.loginAccountOptions,this.selectedLoginAccount))){this.setPasskeyPreparation(this.prepareSelectedLogin);return}this.preparePasskey=null;let e=this.stateValue;e.kind!==`preparing`&&e.kind!==`ready`||e.viewModel.kind!==`passkey`||e.viewModel.mode!==`login`||(this.stateValue={kind:`preparing`,viewModel:{...e.viewModel,status:{kind:`idle`,interaction:`actionable`}}},this.updateElement())}updateLoginSelectionViewModel(){let e=this.stateValue;e.kind!==`preparing`&&e.kind!==`ready`||e.viewModel.kind!==`passkey`||e.viewModel.mode!==`login`||(this.stateValue={...e,viewModel:{...e.viewModel,accountOptions:this.loginAccountOptions,selectedAccount:this.selectedLoginAccount}})}mount(){if(this.surface||this.cleanedUp)throw Error(`Hosted auth-menu session is already mounted`);if(document.querySelectorAll(`.seams-auth-menu-surface`).length>0)throw Error(`A hosted auth-menu surface is already mounted`);let e=document.body||document.documentElement;if(!e)throw Error(`Wallet host document has no mount root`);this.surface=Ot({parent:e,viewModel:this.currentViewModel(),onIntent:this.onIntent}),this.measurementReporter=Me({kind:`auth_menu_surface`,element:this.surface.element,requestId:this.identity.requestId,authMenuSessionId:this.identity.authMenuSessionId,postMeasurement:this.postSurfaceMeasurement})}waitForOutcome(){return this.stateValue.kind===`complete`?Promise.resolve(this.stateValue.outcome):(this.outcomePromise||=new Promise(e=>{this.outcomeResolver=e}),this.outcomePromise)}cancel(e){if(Rt(this.stateValue)){if(e===`close_button`)return;this.complete({kind:`cancelled`,authMenuSessionId:this.identity.authMenuSessionId,reason:e});return}this.stateValue.kind===`link_device`&&console.error(`[Device2Linking] auth menu cancelled`,{reason:e}),this.invalidatePreparation(),this.complete({kind:`cancelled`,authMenuSessionId:this.identity.authMenuSessionId,reason:e})}startPasskeyPreparation(){if(this.stateValue.kind===`complete`)return;let e=this.currentViewModel();if(e.kind!==`passkey`)return;let t=e.mode===`register`?this.registrationPreparation:null,n=e.mode===`login`?this.preparePasskey:null;if(!n&&!t)return;if(t&&e.mode===`register`&&e.showRegistrationInput&&e.passkeyName.trim().length===0){this.invalidatePreparation(),this.stateValue={kind:`preparing`,viewModel:{...e,status:{kind:`idle`,interaction:`awaiting_input`}}},this.updateElement();return}this.clearPreparationExpiryTimer();let r=++this.preparationGeneration,i=new AbortController;this.preparationCancellation=i;let a={kind:`abort_signal`,signal:i.signal};this.stateValue={kind:`preparing`,viewModel:{...e,status:{kind:`idle`,interaction:`arming`}}},this.updateElement(),this.schedulePreparationDeadline(r,i),Promise.resolve().then(()=>t?t(this.registrationValue(),a):n(a)).then(t=>{if(r!==this.preparationGeneration||this.stateValue.kind===`complete`){G(t);return}this.clearPreparationDeadlineTimer(),this.prepared=t,this.stateValue={kind:`ready`,prepared:t,viewModel:{...e,status:{kind:`idle`,interaction:`actionable`}}},this.schedulePreparationExpiry(t),this.updateElement()},t=>{r!==this.preparationGeneration||this.stateValue.kind===`complete`||(this.clearPreparationDeadlineTimer(),this.stateValue={kind:`preparing`,viewModel:{...e,status:_(Y(t))}},this.updateElement())})}invalidatePreparation(){this.invalidateRecovery(),this.stateValue.kind===`link_device`&&(this.deviceLinkGeneration+=1,this.cancelDeviceLinking().catch(()=>{})),this.clearPreparationDeadlineTimer(),this.clearPreparationExpiryTimer(),this.preparationGeneration+=1,this.preparationCancellation?.abort(),this.preparationCancellation=null,this.googleGeneration+=1,this.googleCancellation?.abort(),this.googleCancellation=null;let e=this.prepared;this.prepared=null,e&&G(e),this.stateValue.kind===`performing`&&G(this.stateValue.prepared),(this.stateValue.kind===`google_login`||this.stateValue.kind===`google_registration`)&&this.stateValue.flow.cancel().catch(()=>{})}invalidateRecovery(){this.recoveryGeneration+=1,this.recoveryCancellation?.abort(),this.recoveryCancellation=null;let e=this.recoveryLoginPrepared;this.recoveryLoginPrepared=null,e&&G(e);let t=this.stateValue;t.kind!==`recovery`||!t.operation||Rt(t)||this.recoveryPort.cancel(t.operation).catch(()=>{})}registrationValue(){let e=this.stateValue;return(e.kind===`preparing`||e.kind===`ready`)&&e.viewModel.kind===`passkey`&&e.viewModel.mode===`register`?e.viewModel.passkeyName:``}clearPreparationExpiryTimer(){this.preparationExpiryTimer!==null&&(clearTimeout(this.preparationExpiryTimer),this.preparationExpiryTimer=null)}clearPreparationDeadlineTimer(){this.preparationDeadlineTimer!==null&&(clearTimeout(this.preparationDeadlineTimer),this.preparationDeadlineTimer=null)}schedulePreparationDeadline(e,t){this.clearPreparationDeadlineTimer(),this.preparationDeadlineTimer=setTimeout(this.expirePasskeyPreparation.bind(this,e,t),2e4)}expirePasskeyPreparation(e,t){let n=this.stateValue;e!==this.preparationGeneration||t!==this.preparationCancellation||n.kind!==`preparing`||n.viewModel.kind!==`passkey`||n.viewModel.status.kind!==`idle`||n.viewModel.status.interaction!==`arming`||(this.clearPreparationDeadlineTimer(),this.preparationGeneration+=1,this.preparationCancellation=null,t.abort(),this.stateValue={kind:`preparing`,viewModel:{...n.viewModel,status:_(`Passkey preparation timed out`)}},this.updateElement())}schedulePreparationExpiry(e){this.clearPreparationExpiryTimer();let t=Math.max(0,e.expiresAtMs-Date.now());this.preparationExpiryTimer=setTimeout(()=>{this.preparationExpiryTimer=null,!(this.stateValue.kind!==`ready`||this.stateValue.prepared!==e||this.prepared!==e||this.stateValue.viewModel.kind!==`passkey`)&&(G(e),this.prepared=null,this.stateValue={kind:`preparing`,viewModel:{...this.stateValue.viewModel,status:{kind:`recoverable`,reason:`expired`,message:`Passkey preparation expired. Retry to continue.`}}},this.updateElement())},t)}startGoogleFlow(e,t){this.invalidatePreparation();let n=++this.googleGeneration,r=new AbortController;this.googleCancellation=r;let i=this.currentViewModel();i.kind===`recovery`||i.kind===`link_device`||(this.stateValue={kind:`preparing`,viewModel:{...i,status:{kind:`busy`,headline:`Waiting for Google SSO authentication…`,detail:`Starting Google sign-in`}}},this.updateElement(),this.beginGoogleEmailOtp({idToken:e,authTarget:t,signal:r.signal}).then(e=>{if(n!==this.googleGeneration||r.signal.aborted||this.stateValue.kind===`complete`){e.cancel().catch(()=>{});return}this.googleCancellation=null,e.mode===`login`?this.stateValue={kind:`google_login`,flow:e,viewModel:Kt({base:i,flow:e})}:this.stateValue={kind:`google_registration`,flow:e,viewModel:qt({base:i,flow:e})},this.updateElement()},e=>{n!==this.googleGeneration||r.signal.aborted||this.stateValue.kind===`complete`||(this.googleCancellation=null,this.stateValue={kind:`preparing`,viewModel:{...i,status:_(Y(e))}},this.updateElement())}))}requestExternalAuth(e){if(this.stateValue.kind===`complete`)return null;if(this.stateValue.kind===`recovery`&&this.stateValue.stage===`google_ready`)return this.requestRecoveryGoogleVerification(e,this.stateValue);if(this.stateValue.kind===`recovery`&&this.stateValue.stage===`sign_in_ready`&&this.stateValue.viewModel.target.kind===`google_email_otp`)return this.requestRecoveredGoogleSignIn(e,this.stateValue);let t=this.currentViewModel();if(t.kind!==`passkey`||!this.request.enabledExternalProviders.includes(e)||this.stateValue.kind===`awaiting_external_auth`)return null;let n;if(t.mode===`register`)n={mode:`register`};else{let e=v(t.accountOptions,t.selectedAccount);if(!Ze(e))return null;n={mode:`login`,loginTarget:e.loginTarget}}this.invalidatePreparation();let r=o(J());if(!r)return null;let i={kind:`hosted_auth_menu_external_auth_request_v1`,authMenuSessionId:this.identity.authMenuSessionId,externalAuthRequestId:r,provider:e,mode:t.mode};return this.stateValue={kind:`awaiting_external_auth`,viewModel:{...t,status:{kind:`busy`,headline:`Waiting for Google SSO authentication…`,detail:`Waiting for Google sign-in`}},request:i,authTarget:n},this.updateElement(),this.sendToParent({type:`AUTH_MENU_EXTERNAL_AUTH_REQUEST`,requestId:this.identity.requestId,payload:i}),i}acceptExternalAuthResolution(e){let t=this.stateValue;if(t.kind===`recovery`&&t.stage===`google_external_auth`){if(t.request.authMenuSessionId!==e.authMenuSessionId||t.request.externalAuthRequestId!==e.externalAuthRequestId||this.identity.requestId!==e.requestId)return!1;if(e.evidence.kind===`google_id_token`)return this.startRecoveryGoogleVerification(t,e.evidence.idToken),!0;let n=e.evidence.kind===`cancelled`?Bt:_(e.evidence.message);return this.stateValue={kind:`recovery`,stage:`google_ready`,operation:t.operation,returnState:t.returnState,viewModel:X({base:t.viewModel,walletId:Z(t.viewModel),stage:`google_ready`,target:t.operation.target,status:n})},this.updateElement(),!0}if(t.kind!==`awaiting_external_auth`||t.viewModel.kind!==`passkey`||t.request.authMenuSessionId!==e.authMenuSessionId||t.request.externalAuthRequestId!==e.externalAuthRequestId||this.identity.requestId!==e.requestId)return!1;switch(e.evidence.kind){case`google_id_token`:return this.startGoogleFlow(e.evidence.idToken,t.authTarget),!0;case`cancelled`:case`failed`:{let n=e.evidence.kind===`cancelled`?Bt:_(e.evidence.message);return this.stateValue={kind:`preparing`,viewModel:{...t.viewModel,status:n}},this.updateElement(),!0}default:return rn(e.evidence)}}requestRecoveryGoogleVerification(e,t){if(!this.request.enabledExternalProviders.includes(e))return null;let n=o(J());if(!n)return null;let r={kind:`hosted_auth_menu_external_auth_request_v1`,authMenuSessionId:this.identity.authMenuSessionId,externalAuthRequestId:n,provider:e,mode:`login`};return this.stateValue={kind:`recovery`,stage:`google_external_auth`,operation:t.operation,returnState:t.returnState,request:r,viewModel:X({base:t.viewModel,walletId:Z(t.viewModel),stage:`finalizing`,target:t.operation.target,status:{kind:`busy`,headline:`Waiting for Google SSO authentication…`,detail:`Waiting for Google sign-in`}})},this.updateElement(),this.sendToParent({type:`AUTH_MENU_EXTERNAL_AUTH_REQUEST`,requestId:this.identity.requestId,payload:r}),r}requestRecoveredGoogleSignIn(e,t){if(!this.request.enabledExternalProviders.includes(e))return null;let n=o(J());if(!n)return null;let r={kind:`hosted_auth_menu_external_auth_request_v1`,authMenuSessionId:this.identity.authMenuSessionId,externalAuthRequestId:n,provider:e,mode:`login`};return this.stateValue={kind:`awaiting_external_auth`,request:r,authTarget:{mode:`login`,loginTarget:{kind:`wallet`,walletId:Z(t.viewModel)}},viewModel:{...Vt({request:this.request,appearance:t.viewModel.appearance,hostname:t.viewModel.hostname}),status:{kind:`busy`,headline:`Waiting for Google SSO authentication…`,detail:`Waiting for Google sign-in`}}},this.updateElement(),this.sendToParent({type:`AUTH_MENU_EXTERNAL_AUTH_REQUEST`,requestId:this.identity.requestId,payload:r}),r}cleanup(){this.cleanedUp||(this.cleanedUp=!0,this.invalidatePreparation(),this.measurementReporter?.disconnect(),this.measurementReporter=null,this.surface?.dispose(),this.surface=null)}currentViewModel(){switch(this.stateValue.kind){case`preparing`:case`awaiting_external_auth`:case`ready`:case`performing`:return this.stateValue.viewModel;case`google_login`:case`google_registration`:case`link_device`:case`recovery`:return this.stateValue.viewModel;case`complete`:throw Error(`Completed auth-menu session has no view model`)}}updateElement(){let e=this.currentViewModel();this.reportPresentedError(e),this.surface?.update(e)}reportPresentedError(e){let t=Jt(e);if(!t){this.lastReportedError=null;return}let n=`${t.mode}:${t.message}`;if(n===this.lastReportedError)return;this.lastReportedError=n;let r=s({kind:`hosted_auth_menu_error_v1`,authMenuSessionId:this.identity.authMenuSessionId,mode:t.mode,message:t.message});if(!r)throw Error(`Unable to emit hosted auth-menu error event`);this.sendToParent({type:`AUTH_MENU_ERROR`,requestId:this.identity.requestId,payload:r})}selectMode(e){let t=this.stateValue;t.kind===`complete`||t.kind===`performing`||t.kind===`link_device`||(this.modeSelectionSource=`user`,this.currentViewModel().mode!==e&&this.showPasskeyMode(e))}showPasskeyMode(e){if(this.stateValue.kind===`complete`||this.stateValue.kind===`link_device`)return;let t=this.currentViewModel();this.invalidatePreparation();let n=q({request:{...this.request,initialMode:e},appearance:t.appearance,hostname:t.hostname,mode:e});this.stateValue={kind:`preparing`,viewModel:n.kind===`passkey`&&n.mode===`login`?{...n,accountOptions:this.loginAccountOptions,selectedAccount:this.selectedLoginAccount}:n},this.updateElement(),e===`login`?this.activateSelectedLoginMethod():(this.preparePasskey=null,this.startPasskeyPreparation())}back(){if(this.stateValue.kind===`recovery`){if(this.stateValue.stage===`finalizing`)return;this.closeRecovery();return}if(this.stateValue.kind===`link_device`){this.closeLinkDevice();return}(this.stateValue.kind===`performing`||this.stateValue.kind===`awaiting_external_auth`||this.stateValue.kind===`google_login`||this.stateValue.kind===`google_registration`)&&this.showPasskeyMode(this.stateValue.viewModel.mode)}openRecovery(){let e=this.stateValue;if(e.kind!==`preparing`&&e.kind!==`ready`||e.viewModel.kind!==`passkey`)return;let t={kind:`preparing`,viewModel:{...e.viewModel,status:{kind:`idle`,interaction:`arming`}}};this.invalidatePreparation(),this.recoveryReturnState=t,this.stateValue={kind:`recovery`,stage:`enter_code`,returnState:t,viewModel:X({base:e.viewModel})},this.updateElement()}closeRecovery(){let e=this.stateValue;if(e.kind!==`recovery`)return;let t=e.returnState;this.invalidateRecovery(),this.recoveryReturnState=null,this.stateValue=t,this.updateElement(),this.preparePasskey=t.viewModel.mode===`login`?this.prepareSelectedLogin:null,this.startPasskeyPreparation()}changeRecoveryCode(e){let t=this.stateValue;t.kind!==`recovery`||t.stage!==`enter_code`||(this.stateValue={...t,viewModel:{...t.viewModel,recoveryCode:e,recoveryCodeError:null}},this.updateElement())}prepareRecovery(e=`passkey`){let t=this.stateValue;if(t.kind!==`recovery`||t.stage!==`enter_code`)return;let n=t.viewModel.recoveryCode.trim();if(!n){this.stateValue={...t,viewModel:{...t.viewModel,recoveryCodeError:`Enter a recovery code.`}},this.updateElement();return}let r;try{r=this.recoveryPort.targetFor(e)}catch{this.stateValue={...t,viewModel:X({base:t.viewModel,recoveryCode:t.viewModel.recoveryCode,status:$({kind:`refused`})})},this.updateElement();return}let i=++this.recoveryGeneration,a=new AbortController;this.recoveryCancellation=a,this.stateValue={...t,stage:`preparing`,viewModel:X({base:t.viewModel,recoveryCode:t.viewModel.recoveryCode,stage:`preparing`,target:r,status:{kind:`busy`,headline:`Checking recovery code…`}})},this.updateElement();let o;try{o=this.recoveryPort.prepare({recoveryCode:n,target:r,signal:a.signal})}catch{this.rejectRecoveryPreparation(i);return}o.then(this.completeRecoveryPreparation.bind(this,i),this.rejectRecoveryPreparation.bind(this,i))}completeRecoveryPreparation(e,t){let n=this.stateValue;if(e!==this.recoveryGeneration||n.kind!==`recovery`){t.kind===`hosted_recovery_prepared`&&this.recoveryPort.cancel(t).catch(K);return}if(this.recoveryCancellation=null,t.kind!==`hosted_recovery_prepared`){this.stateValue={kind:`recovery`,stage:`enter_code`,returnState:n.returnState,viewModel:X({base:n.viewModel,recoveryCode:n.viewModel.recoveryCode,status:$(t)})},this.updateElement();return}if(Lt(t)){this.stateValue={kind:`recovery`,stage:`passkey_ready`,operation:t,returnState:n.returnState,viewModel:X({base:n.viewModel,walletId:String(t.walletId),recoveryCode:``,stage:`passkey_ready`,target:t.target})},this.createRecoveryPasskey();return}let r={kind:`recovery`,stage:`google_ready`,operation:t,returnState:n.returnState,viewModel:X({base:n.viewModel,walletId:String(t.walletId),recoveryCode:``,stage:`google_ready`,target:t.target})};this.stateValue=r,this.requestRecoveryGoogleVerification(`google`,r)||(this.stateValue={...r,viewModel:X({base:r.viewModel,walletId:Z(r.viewModel),stage:`google_ready`,target:r.operation.target,status:{kind:`recoverable`,reason:`error`,message:`Google sign-in is unavailable. Try again.`}})},this.updateElement())}rejectRecoveryPreparation(e){let t=this.stateValue;e!==this.recoveryGeneration||t.kind!==`recovery`||(this.recoveryCancellation=null,this.stateValue={kind:`recovery`,stage:`enter_code`,returnState:t.returnState,viewModel:X({base:t.viewModel,recoveryCode:t.viewModel.recoveryCode,status:$({kind:`transport_uncertain`})})},this.updateElement())}startRecoveryGoogleVerification(e,t){let n=++this.recoveryGeneration;this.recoveryPort.verifyGoogle(e.operation,t).then(this.completeRecoveryGoogleVerification.bind(this,n),this.rejectRecoveryGoogleVerification.bind(this,n))}completeRecoveryGoogleVerification(e,t){let n=this.stateValue;if(e!==this.recoveryGeneration||n.kind!==`recovery`||n.stage!==`google_external_auth`){t.kind===`hosted_recovery_google_verified`&&this.recoveryPort.cancel(t).catch(K);return}if(t.kind!==`hosted_recovery_google_verified`){this.showRecoveryGoogleVerificationFailure(n,t);return}this.stateValue={kind:`recovery`,stage:`email_code_required`,operation:t,returnState:n.returnState,viewModel:X({base:n.viewModel,walletId:String(t.walletId),stage:`email_code_required`,target:t.target,challengeId:t.challengeId,emailHint:t.delivery.emailHint,delivery:t.delivery})},this.updateElement()}rejectRecoveryGoogleVerification(e){let t=this.stateValue;e!==this.recoveryGeneration||t.kind!==`recovery`||t.stage!==`google_external_auth`||this.showRecoveryGoogleVerificationFailure(t,{kind:`transport_uncertain`})}showRecoveryGoogleVerificationFailure(e,t){this.stateValue={kind:`recovery`,stage:`google_ready`,operation:e.operation,returnState:e.returnState,viewModel:X({base:e.viewModel,walletId:Z(e.viewModel),stage:`google_ready`,target:e.operation.target,status:$(t)})},this.updateElement()}changeRecoveryGoogleOtpCode(e){let t=this.stateValue;if(t.kind!==`recovery`||t.stage!==`email_code_required`)return;let n=e.replace(/\D/g,``).slice(0,6);this.stateValue={...t,viewModel:X({base:t.viewModel,walletId:Z(t.viewModel),stage:`email_code_required`,target:t.operation.target,challengeId:t.operation.challengeId,emailHint:t.operation.delivery.emailHint,delivery:t.operation.delivery,otpCode:n})},this.updateElement(),/^\d{6}$/.test(n)&&this.submitRecoveryGoogleOtp()}submitRecoveryGoogleOtp(){let e=this.stateValue;if(e.kind===`recovery`&&e.stage===`finalizing`&&e.operation.kind===`hosted_recovery_email_otp_verified`&&e.viewModel.status.kind===`recoverable`){this.finishRecovery(e.operation);return}if(e.kind!==`recovery`||e.stage!==`email_code_required`)return;let t=e.viewModel.otpCode.trim();if(!/^\d{6}$/.test(t))return;let n=++this.recoveryGeneration;this.stateValue={...e,viewModel:X({base:e.viewModel,walletId:Z(e.viewModel),stage:`email_code_required`,target:e.operation.target,challengeId:e.operation.challengeId,emailHint:e.operation.delivery.emailHint,delivery:e.operation.delivery,otpCode:t,status:{kind:`busy`,headline:`Verifying email code…`}})},this.updateElement(),this.recoveryPort.verifyEmailOtp(e.operation,{challengeId:e.operation.challengeId,otpCode:t}).then(this.completeRecoveryEmailOtpVerification.bind(this,n),this.rejectRecoveryEmailOtpVerification.bind(this,n))}completeRecoveryEmailOtpVerification(e,t){let n=this.stateValue;if(e!==this.recoveryGeneration||n.kind!==`recovery`||n.stage!==`email_code_required`){t.kind===`hosted_recovery_email_otp_verified`&&this.recoveryPort.cancel(t).catch(K);return}if(t.kind!==`hosted_recovery_email_otp_verified`){this.showRecoveryEmailOtpFailure(n,t);return}this.finishRecovery(t)}rejectRecoveryEmailOtpVerification(e){let t=this.stateValue;e!==this.recoveryGeneration||t.kind!==`recovery`||t.stage!==`email_code_required`||this.showRecoveryEmailOtpFailure(t,{kind:`transport_uncertain`})}showRecoveryEmailOtpFailure(e,t){this.stateValue={...e,viewModel:X({base:e.viewModel,walletId:Z(e.viewModel),stage:`email_code_required`,target:e.operation.target,challengeId:e.operation.challengeId,emailHint:e.operation.delivery.emailHint,delivery:e.operation.delivery,otpCode:e.viewModel.otpCode,status:$(t)})},this.updateElement()}createRecoveryPasskey(){let e=this.stateValue;if(e.kind!==`recovery`)return;if(e.stage===`finalizing`&&e.operation.kind===`hosted_recovery_credential_created`&&e.viewModel.status.kind===`recoverable`){this.finishRecovery(e.operation);return}if(e.stage!==`passkey_ready`)return;let t=++this.recoveryGeneration,n;try{n=this.recoveryPort.createPasskey(e.operation)}catch{this.showRecoveryCreateFailure(e,{kind:`refused`});return}this.stateValue={...e,stage:`finalizing`,viewModel:X({base:e.viewModel,walletId:Z(e.viewModel),stage:`finalizing`,target:Q(e.viewModel),status:{kind:`busy`,headline:`Creating new passkey…`}})},this.updateElement(),n.then(this.completeRecoveryCredentialCreation.bind(this,t),this.rejectRecoveryCredentialCreation.bind(this,t))}completeRecoveryCredentialCreation(e,t){let n=this.stateValue;if(e!==this.recoveryGeneration||n.kind!==`recovery`||n.stage!==`finalizing`||n.operation.kind!==`hosted_recovery_prepared`){t.kind===`hosted_recovery_credential_created`&&this.recoveryPort.cancel(t).catch(K);return}if(t.kind!==`hosted_recovery_credential_created`){this.showRecoveryCreateFailure({returnState:n.returnState,viewModel:n.viewModel,operation:n.operation},t);return}this.finishRecovery(t)}rejectRecoveryCredentialCreation(e){let t=this.stateValue;e!==this.recoveryGeneration||t.kind!==`recovery`||t.stage!==`finalizing`||t.operation.kind!==`hosted_recovery_prepared`||this.showRecoveryCreateFailure({returnState:t.returnState,viewModel:t.viewModel,operation:t.operation},{kind:`refused`})}showRecoveryCreateFailure(e,t){if(!Lt(e.operation)){this.recoveryPort.cancel(e.operation).catch(K),this.stateValue={kind:`recovery`,stage:`enter_code`,returnState:e.returnState,viewModel:X({base:e.viewModel,recoveryCode:``,status:$(t)})},this.updateElement();return}if(t.kind===`refused`){this.recoveryPort.cancel(e.operation).catch(K),this.stateValue={kind:`recovery`,stage:`enter_code`,returnState:e.returnState,viewModel:X({base:e.viewModel,recoveryCode:``,status:$(t)})},this.updateElement();return}this.stateValue={kind:`recovery`,stage:`passkey_ready`,operation:e.operation,returnState:e.returnState,viewModel:X({base:e.viewModel,walletId:Z(e.viewModel),stage:`passkey_ready`,target:e.operation.target,status:Zt(t)})},this.updateElement()}finishRecovery(e){let t=this.stateValue;if(t.kind!==`recovery`)return;let n=++this.recoveryGeneration;this.stateValue={kind:`recovery`,stage:`finalizing`,operation:e,returnState:t.returnState,viewModel:X({base:t.viewModel,walletId:Z(t.viewModel),stage:`finalizing`,target:Q(t.viewModel),status:{kind:`busy`,headline:`Finishing recovery…`}})},this.updateElement();let r;try{r=this.recoveryPort.finalize(e)}catch{this.rejectRecoveryFinalization(n);return}r.then(this.completeRecoveryFinalization.bind(this,n),this.rejectRecoveryFinalization.bind(this,n))}completeRecoveryFinalization(e,t){let n=this.stateValue;if(!(e!==this.recoveryGeneration||n.kind!==`recovery`||n.stage!==`finalizing`||n.operation.kind!==`hosted_recovery_credential_created`&&n.operation.kind!==`hosted_recovery_email_otp_verified`)){if(t.kind!==`ready_for_sign_in`){t.kind===`refused`?(this.recoveryPort.cancel(n.operation).catch(()=>{}),this.stateValue={kind:`recovery`,stage:`enter_code`,returnState:n.returnState,viewModel:X({base:n.viewModel,status:$(t)})}):this.stateValue={...n,viewModel:X({base:n.viewModel,walletId:Z(n.viewModel),stage:`finalizing`,target:Q(n.viewModel),status:Xt()})},this.updateElement();return}if(n.operation.target.kind===`passkey`){this.prepareRecoveredPasskeyLogin(t.walletId,n.returnState);return}this.stateValue={kind:`recovery`,stage:`sign_in_ready`,returnState:n.returnState,viewModel:X({base:n.viewModel,walletId:String(t.walletId),stage:`sign_in_ready`,target:n.operation.target})},this.updateElement()}}rejectRecoveryFinalization(e){let t=this.stateValue;e!==this.recoveryGeneration||t.kind!==`recovery`||t.stage!==`finalizing`||t.operation.kind!==`hosted_recovery_credential_created`&&t.operation.kind!==`hosted_recovery_email_otp_verified`||(this.stateValue={...t,viewModel:X({base:t.viewModel,walletId:Z(t.viewModel),stage:`finalizing`,target:Q(t.viewModel),status:Xt()})},this.updateElement())}prepareRecoveredPasskeyLogin(e,t){let n=this.stateValue;if(n.kind!==`recovery`)return;let r=++this.recoveryGeneration,i=new AbortController;this.recoveryCancellation=i;let a=this.prepareRecoveredLogin(e,{kind:`abort_signal`,signal:i.signal});this.stateValue={kind:`recovery`,stage:`sign_in_ready`,returnState:t,viewModel:X({base:n.viewModel,walletId:String(e),stage:`sign_in_ready`,target:Q(n.viewModel),status:{kind:`busy`,headline:`Preparing to unlock…`}})},this.updateElement(),a.then(this.completeRecoveredLoginPreparation.bind(this,r,t),this.rejectRecoveredLoginPreparation.bind(this,r,e,t))}completeRecoveredLoginPreparation(t,n,r){let i=this.stateValue;if(t!==this.recoveryGeneration||i.kind!==`recovery`){G(r);return}if(this.recoveryCancellation=null,r.kind!==`hosted_passkey_owner_login_prepared_v1`&&r.kind!==`hosted_passkey_linked_authority_login_prepared_v1`){G(r);let a=e(Z(i.viewModel));if(!a.ok)return;this.rejectRecoveredLoginPreparation(t,a.value,n);return}this.recoveryLoginPrepared=r,this.stateValue={kind:`recovery`,stage:`sign_in_ready`,returnState:n,viewModel:X({base:i.viewModel,walletId:Z(i.viewModel),stage:`sign_in_ready`,target:Q(i.viewModel)})},this.updateElement()}rejectRecoveredLoginPreparation(e,t,n){let r=this.stateValue;e!==this.recoveryGeneration||r.kind!==`recovery`||(this.recoveryCancellation=null,this.stateValue={kind:`recovery`,stage:`sign_in_ready`,returnState:n,viewModel:X({base:r.viewModel,walletId:String(t),stage:`sign_in_ready`,target:Q(r.viewModel),status:{kind:`recoverable`,reason:`error`,message:`Your wallet was recovered. Unlock it again to continue.`}})},this.updateElement())}signInRecoveredWallet(){let t=this.stateValue;if(t.kind!==`recovery`||t.stage!==`sign_in_ready`)return;if(t.viewModel.target.kind===`google_email_otp`){this.requestExternalAuth(`google`);return}let n=this.recoveryLoginPrepared;if(!n){let n=e(Z(t.viewModel));if(!n.ok)return;this.prepareRecoveredPasskeyLogin(n.value,t.returnState);return}this.recoveryLoginPrepared=null,this.performPreparedPasskey(n)}openLinkDevice(){let e=this.stateValue;if(e.kind!==`preparing`&&e.kind!==`ready`||e.viewModel.kind!==`passkey`)return;let t={kind:`preparing`,viewModel:{...e.viewModel,status:{kind:`idle`,interaction:`arming`}}};this.invalidatePreparation(),this.linkedDeviceActivationInProgress=!1,this.targetPasskeyActivation=null,this.targetEmailOtpActivation=null,this.linkedDeviceEmailOtpSendStarted=!1,this.linkedDeviceTargetFactor={kind:`passkey_prf`},this.linkedDeviceTargetEmailAddress=``,this.stateValue={kind:`link_device`,returnState:t,viewModel:Yt(e.viewModel)},this.updateElement()}selectLinkedDeviceTargetFactor(e){let t=this.stateValue;t.kind!==`link_device`||t.viewModel.linkDevice.kind!==`select_factor`||(this.linkedDeviceTargetFactor=e,this.stateValue={...t,viewModel:{...t.viewModel,linkDevice:e.kind===`email_otp`?{kind:`select_factor`,targetFactor:e,targetEmail:this.linkedDeviceTargetEmailAddress}:{kind:`select_factor`,targetFactor:e}}},this.updateElement())}changeLinkedDeviceTargetEmailAddress(e){let t=this.stateValue;t.kind!==`link_device`||t.viewModel.linkDevice.kind!==`select_factor`||t.viewModel.linkDevice.targetFactor.kind!==`email_otp`||(this.linkedDeviceTargetEmailAddress=e,this.stateValue={...t,viewModel:{...t.viewModel,linkDevice:{kind:`select_factor`,targetFactor:t.viewModel.linkDevice.targetFactor,targetEmail:e}}},this.updateElement())}startSelectedDeviceLinking(){let e=this.stateValue;if(e.kind!==`link_device`||e.viewModel.linkDevice.kind!==`select_factor`)return;let t=e.viewModel.linkDevice,n;try{if(t.targetFactor.kind===`email_otp`){let e=t.targetEmail;if(typeof e!=`string`)throw Error(`linked-device target email address is unavailable`);n=zt({targetFactor:t.targetFactor,targetEmail:e})}else n=zt({targetFactor:t.targetFactor})}catch(t){this.stateValue={...e,viewModel:{...e.viewModel,linkDevice:{...e.viewModel.linkDevice,error:Y(t)}}},this.updateElement();return}let r=++this.deviceLinkGeneration;this.stateValue={...e,viewModel:{...e.viewModel,linkDevice:{kind:`loading`,message:`Generating QR code...`}}},this.updateElement(),this.startDeviceLinking(n,{onEvent:this.onLinkDeviceEvent.bind(this,r),onTargetFactorRequired:this.onTargetFactorRequired.bind(this,r)}).then(this.completeLinkDeviceOpen.bind(this,r)).catch(this.failLinkDeviceOpen.bind(this,r))}onLinkDeviceEvent(e,t){let n=this.stateValue;if(e!==this.deviceLinkGeneration||n.kind!==`link_device`)return;let r=De(t);switch(r.kind){case`active`:if(this.linkedDeviceActivationInProgress)return;this.linkedDeviceActivationInProgress=!0,this.complete({kind:`authenticated`,authMenuSessionId:this.identity.authMenuSessionId,walletId:r.walletId,method:this.linkedDeviceTargetFactor.kind===`email_otp`?`google_email_otp`:`passkey`});return;case`invalid_active`:this.showLinkedDeviceActivationError(n,Error(`Linked-device activation omitted its wallet identity`));return;case`failed`:if(t.error?.code===c.SESSION_EXPIRED){this.stateValue={...n,viewModel:{...n.viewModel,linkDevice:{kind:`expired`,message:`This linking request expired. Start again to link this device.`}}},this.updateElement();return}if(t.error?.code===c.DELIVERY_RECOVERY_REQUIRED){this.showLinkedDeviceActivationError(n,Error(t.message||`Go back and unlock the new linked method to finish setup.`));return}break;case`cancelled`:this.targetPasskeyActivation=null,this.targetEmailOtpActivation=null,this.linkedDeviceEmailOtpSendStarted=!1,this.stateValue={...n,viewModel:{...n.viewModel,linkDevice:{kind:`cancelled`,message:`The other device cancelled this linking request. Go back to try again.`}}},this.updateElement();return;case`pending`:break;default:return en(r)}let i=t.message?.trim();if(!i)return;let a=n.viewModel.linkDevice,o=a.kind===`email_otp_required`?a:a.kind===`ready`||a.kind===`passkey_required`||a.kind===`creating_passkey`?{...a,message:i}:{kind:`loading`,message:i};this.stateValue={...n,viewModel:{...n.viewModel,linkDevice:o}},this.updateElement()}showLinkedDeviceActivationError(e,t){this.stateValue={...e,viewModel:{...e.viewModel,linkDevice:{kind:`activation_error`,message:Y(t)}}},this.updateElement()}completeLinkDeviceOpen(e,t){let n=this.stateValue;e!==this.deviceLinkGeneration||n.kind!==`link_device`||this.linkedDeviceActivationInProgress||n.viewModel.linkDevice.kind!==`loading`||(this.stateValue={...n,viewModel:{...n.viewModel,linkDevice:this.targetPasskeyActivation?{kind:`passkey_required`,message:`Create a passkey to finish linking this device`}:{kind:`ready`,qrCodeDataURL:t.qrCodeDataURL,message:`Waiting for device to scan`}}},this.updateElement())}onTargetFactorRequired(e,t){switch(t.kind){case`linked_device_target_passkey_activation_v1`:this.onTargetPasskeyActivation(e,t);return;case`linked_device_target_email_otp_activation_v1`:this.onTargetEmailOtpActivation(e,t);return;default:return tn(t)}}onTargetPasskeyActivation(e,t){let n=this.stateValue;e!==this.deviceLinkGeneration||n.kind!==`link_device`||(this.targetPasskeyActivation=t,n.viewModel.linkDevice.kind===`ready`&&(this.stateValue={...n,viewModel:{...n.viewModel,linkDevice:{kind:`passkey_required`,message:`Create a passkey to finish linking this device`}}},this.updateElement()))}onTargetEmailOtpActivation(e,t){let n=this.stateValue;e!==this.deviceLinkGeneration||n.kind!==`link_device`||(this.targetEmailOtpActivation=t,this.stateValue={...n,viewModel:{...n.viewModel,linkDevice:{kind:`email_otp_required`,state:t.state,otpCode:n.viewModel.linkDevice.kind===`email_otp_required`?n.viewModel.linkDevice.otpCode:``}}},this.updateElement(),t.state.kind===`sending`&&!this.linkedDeviceEmailOtpSendStarted&&(this.linkedDeviceEmailOtpSendStarted=!0,t.sendCode().catch(this.failLinkedDeviceEmailOtp.bind(this))))}changeLinkedDeviceEmailOtpCode(e){let t=this.stateValue;if(t.kind!==`link_device`||t.viewModel.linkDevice.kind!==`email_otp_required`)return;let n=e.replace(/\D/g,``).slice(0,6),r=t.viewModel.linkDevice.otpCode,i=t.viewModel.linkDevice.state;this.stateValue={...t,viewModel:{...t.viewModel,linkDevice:{...t.viewModel.linkDevice,otpCode:n}}},this.updateElement(),n.length===6&&n!==r&&(i.kind===`code_input`||i.kind===`incorrect`)&&this.submitLinkedDeviceEmailOtpCode(n)}resendLinkedDeviceEmailOtp(){let e=this.targetEmailOtpActivation;e&&e.resendCode().catch(this.failLinkedDeviceEmailOtp.bind(this))}submitLinkedDeviceEmailOtp(){let e=this.stateValue;e.kind!==`link_device`||e.viewModel.linkDevice.kind!==`email_otp_required`||e.viewModel.linkDevice.otpCode.length!==6||this.submitLinkedDeviceEmailOtpCode(e.viewModel.linkDevice.otpCode)}submitLinkedDeviceEmailOtpCode(e){let t=this.targetEmailOtpActivation;t&&t.submitCode(e).catch(this.failLinkedDeviceEmailOtp.bind(this))}failLinkedDeviceEmailOtp(e){let t=this.stateValue;t.kind===`link_device`&&this.showLinkedDeviceActivationError(t,e)}createLinkedDevicePasskey(){let e=this.stateValue,t=this.targetPasskeyActivation;!t||e.kind!==`link_device`||e.viewModel.linkDevice.kind!==`passkey_required`||(this.targetPasskeyActivation=null,this.stateValue={...e,viewModel:{...e.viewModel,linkDevice:{kind:`creating_passkey`,message:`Follow the passkey prompt on your screen`}}},this.updateElement(),t.createPasskey().catch(this.failTargetPasskeyCreation.bind(this)))}failTargetPasskeyCreation(e){let t=this.stateValue;t.kind===`link_device`&&(this.stateValue={...t,viewModel:{...t.viewModel,linkDevice:{kind:`error`,message:Y(e)}}},this.updateElement())}failLinkDeviceOpen(e,t){let n=this.stateValue;e!==this.deviceLinkGeneration||n.kind!==`link_device`||this.linkedDeviceActivationInProgress||n.viewModel.linkDevice.kind!==`loading`||(this.stateValue={...n,viewModel:{...n.viewModel,linkDevice:{kind:`error`,message:Y(t)}}},this.updateElement())}closeLinkDevice(){let e=this.stateValue;e.kind===`link_device`&&(this.deviceLinkGeneration+=1,this.targetPasskeyActivation=null,this.targetEmailOtpActivation=null,this.linkedDeviceEmailOtpSendStarted=!1,this.cancelDeviceLinking().catch(()=>{}),this.stateValue=e.returnState,this.updateElement(),this.startPasskeyPreparation())}rerollRegistrationWallet(){let e=this.stateValue;e.kind!==`ready`&&e.kind!==`preparing`||e.viewModel.kind!==`passkey`||e.viewModel.mode!==`register`||!e.viewModel.passkeyNameReadOnly||!e.viewModel.showRegistrationInput||(this.invalidatePreparation(),this.stateValue={kind:`preparing`,viewModel:{...e.viewModel,passkeyName:String(Ee()),status:{kind:`idle`,interaction:`arming`}}},this.updateElement(),this.startPasskeyPreparation())}selectLoginAccount(e,t){let n=this.loginAccountOptions.find(n=>n.walletId===e&&n.authMethod===t);if(!n||n.walletId===this.selectedLoginAccount?.walletId&&n.authMethod===this.selectedLoginAccount.authMethod)return;let r=this.stateValue;if(r.kind!==`preparing`&&r.kind!==`ready`||r.viewModel.kind!==`passkey`||r.viewModel.mode!==`login`)return;let i=n.walletId!==this.selectedLoginAccount?.walletId;if(this.selectedLoginAccount=n,!i){this.updateLoginSelectionViewModel(),this.updateElement();return}this.invalidatePreparation(),this.stateValue={kind:`preparing`,viewModel:{...r.viewModel,selectedAccount:n,status:{kind:`idle`,interaction:`arming`}}},this.updateElement(),this.activateSelectedLoginMethod()}retryPreparation(){let e=this.stateValue;e.kind!==`preparing`||e.viewModel.kind!==`passkey`||e.viewModel.status.kind!==`recoverable`||(this.invalidatePreparation(),this.stateValue={kind:`preparing`,viewModel:{...e.viewModel,status:{kind:`idle`,interaction:`arming`}}},this.updateElement(),this.startPasskeyPreparation())}updateGoogleOtpCode(e){let t=this.stateValue;if(t.kind!==`google_login`||t.viewModel.submitBusy)return;let n=e.replace(/\D/g,``).slice(0,6);this.stateValue={...t,viewModel:{...t.viewModel,otpCode:n,error:``}},this.updateElement(),/^\d{6}$/.test(n)&&this.submitGoogleOtp()}resendGoogleOtp(){let e=this.stateValue;if(e.kind!==`google_login`||e.viewModel.resendBusy)return;let t=e.flow;this.stateValue={...e,viewModel:{...e.viewModel,status:{kind:`busy`,headline:`Sending a new email code`},resendBusy:!0,error:``}},this.updateElement(),Ht(t.resend()).then(n=>{if(this.stateValue.kind!==`google_login`||this.stateValue.flow!==t){n.ok&&n.value.cancel().catch(()=>{});return}if(!n.ok){this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},resendBusy:!1,error:n.error.message}},this.updateElement();return}if(n.value.mode!==`login`){n.value.cancel().catch(()=>{}),this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},resendBusy:!1,error:`Google returned an unexpected registration flow.`}},this.updateElement();return}let r=n.value;this.stateValue={kind:`google_login`,flow:r,viewModel:Kt({base:e.viewModel,flow:r})},this.updateElement()},e=>{this.stateValue.kind!==`google_login`||this.stateValue.flow!==t||(this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},resendBusy:!1,error:Y(e)}},this.updateElement())})}submitGoogleOtp(){let e=this.stateValue;if(e.kind!==`google_login`||e.viewModel.submitBusy)return;let t=e.viewModel.otpCode;if(!/^\d{6}$/.test(t)){this.stateValue={...e,viewModel:{...e.viewModel,status:{kind:`idle`,interaction:`actionable`},error:`Enter the 6-digit code from your email.`}},this.updateElement();return}let n=e.flow;this.stateValue={...e,viewModel:{...e.viewModel,status:{kind:`busy`,headline:`Verifying your email code`},submitBusy:!0,error:``}},this.updateElement(),n.submit({otpCode:t}).then(e=>{if(!(this.stateValue.kind!==`google_login`||this.stateValue.flow!==n)){if(!e.ok){this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},submitBusy:!1,error:e.error.message}},this.updateElement();return}if(e.value.mode!==`login`){this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},submitBusy:!1,error:`Google returned an unexpected registration result.`}},this.updateElement();return}this.complete({kind:`authenticated`,authMenuSessionId:this.identity.authMenuSessionId,walletId:e.value.walletId,method:`google_email_otp`})}},e=>{this.stateValue.kind!==`google_login`||this.stateValue.flow!==n||(this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},submitBusy:!1,error:Y(e)}},this.updateElement())})}rerollGoogleRegistration(){let e=this.stateValue;if(e.kind!==`google_registration`||e.viewModel.rerollBusy)return;let t=e.flow;this.stateValue={...e,viewModel:{...e.viewModel,status:{kind:`busy`,headline:`Generating another wallet name`},rerollBusy:!0,error:``}},this.updateElement(),t.rerollWalletId().then(n=>{if(this.stateValue.kind!==`google_registration`||this.stateValue.flow!==t){n.ok&&n.value.cancel().catch(()=>{});return}if(!n.ok){this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},rerollBusy:!1,error:n.error.message}},this.updateElement();return}if(n.value.mode!==`register`){n.value.cancel().catch(()=>{}),this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},rerollBusy:!1,error:`Google returned an unexpected login flow.`}},this.updateElement();return}let r=n.value;this.stateValue={kind:`google_registration`,flow:r,viewModel:qt({base:e.viewModel,flow:r})},this.updateElement()},e=>{this.stateValue.kind!==`google_registration`||this.stateValue.flow!==t||(this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},rerollBusy:!1,error:Y(e)}},this.updateElement())})}completeGoogleRegistration(){let e=this.stateValue;if(e.kind!==`google_registration`||e.viewModel.submitBusy)return;let t=e.flow;this.stateValue={...e,viewModel:{...e.viewModel,status:{kind:`busy`,headline:`Creating your wallet`},submitBusy:!0,error:``}},this.updateElement(),t.completeRegistration().then(e=>{if(!(this.stateValue.kind!==`google_registration`||this.stateValue.flow!==t)){if(!e.ok){this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},submitBusy:!1,error:e.error.message}},this.updateElement();return}this.complete({kind:`registered`,authMenuSessionId:this.identity.authMenuSessionId,walletId:e.value.walletId,method:`google_email_otp`})}},e=>{this.stateValue.kind!==`google_registration`||this.stateValue.flow!==t||(this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},submitBusy:!1,error:Y(e)}},this.updateElement())})}complete(e){if(this.stateValue.kind===`complete`)return;this.stateValue={kind:`complete`,outcome:e},this.cleanup();let t=this.outcomeResolver;this.outcomeResolver=null,t?.(e)}performPreparedPasskey(e){this.prepared=null;let t=this.currentViewModel();if(this.stateValue={kind:`performing`,prepared:e,viewModel:t.kind===`recovery`?X({base:t,walletId:Z(t),stage:`sign_in_ready`,target:Q(t),status:{kind:`busy`,headline:Ke(`login`),detail:`Continue with your passkey`}}):{...t,status:{kind:`busy`,headline:Ke(t.mode),detail:`Continue with your passkey`}}},e.kind===`hosted_passkey_owner_login_prepared_v1`||e.kind===`hosted_passkey_linked_authority_login_prepared_v1`){this.updateElement(),this.finishPreparedPasskey(e);return}let n;try{n=this.startPreparedCredential(e)}catch(t){this.updateElement(),this.failPreparedPasskey(e,t);return}this.updateElement(),n.then(()=>this.finishPreparedPasskey(e),t=>this.failPreparedPasskey(e,t))}startPreparedCredential(e){return e.kind===`hosted_passkey_registration_prepared_v1`?Ce(e):Nt(e)}async finishPreparedPasskey(e){try{switch(e.kind){case`hosted_passkey_registration_prepared_v1`:{let t=await ye({prepared:e});this.completeRegistrationResult(t);return}case`hosted_passkey_owner_login_prepared_v1`:case`hosted_passkey_linked_authority_login_prepared_v1`:{let t=await Ft(e);this.completeLoginResult(t);return}case`hosted_passkey_account_sync_prepared_v1`:{let t=await It(e);this.completeAccountSyncResult(t);return}default:return nn(e)}}catch(t){this.failPreparedPasskey(e,t)}}completeRegistrationResult(t){if(!t.success||t.kind!==`wallet_registered`&&t.kind!==`ecdsa_wallet_registered_near_pending`){this.fail({kind:`error`,error:Error(t.success?`Hosted registration returned an unexpected result`:t.error)});return}let n=e(String(t.walletId));if(!n.ok){this.fail({kind:`error`,error:Error(`Hosted registration returned an invalid wallet id`)});return}this.complete({kind:`registered`,authMenuSessionId:this.identity.authMenuSessionId,walletId:n.value,method:`passkey`})}completeLoginResult(t){let n=t.result;if(!n.success){this.fail(t.cancelledByUser?{kind:`dismissed`}:{kind:`error`,error:Error(n.error)});return}let r=e(String(n.walletId));if(!r.ok){this.fail({kind:`error`,error:Error(`Hosted login returned an invalid wallet id`)});return}this.complete({kind:`authenticated`,authMenuSessionId:this.identity.authMenuSessionId,walletId:r.value,method:`passkey`})}completeAccountSyncResult(t){if(!t.success){this.fail({kind:`error`,error:Error(t.error)});return}let n=e(String(t.walletId));if(!n.ok){this.fail({kind:`error`,error:Error(`Hosted account sync returned an invalid wallet id`)});return}this.complete({kind:`account_synced`,authMenuSessionId:this.identity.authMenuSessionId,walletId:n.value})}failPreparedPasskey(e,t){if(this.stateValue.kind!==`performing`||this.stateValue.prepared!==e)return;if(this.preparationCancellation?.signal.aborted){this.fail({kind:`dismissed`});return}let n=t instanceof Error?t.name:``;if(n===`NotAllowedError`||n===`AbortError`){this.fail({kind:`dismissed`});return}this.fail({kind:`error`,error:t})}fail(e){if(this.stateValue.kind!==`performing`)return;let t=this.stateValue.viewModel;if(G(this.stateValue.prepared),this.prepared=null,t.kind===`recovery`){let n=this.recoveryReturnState;if(!n)return;this.recoveryLoginPrepared=null,this.stateValue={kind:`recovery`,stage:`sign_in_ready`,returnState:n,viewModel:X({base:t,walletId:Z(t),stage:`sign_in_ready`,target:Q(t),status:e.kind===`dismissed`?{kind:`idle`,interaction:`actionable`}:_(Y(e.error))})},this.updateElement();return}if(e.kind===`dismissed`){this.invalidatePreparation(),this.stateValue={kind:`preparing`,viewModel:{...t,status:{kind:`idle`,interaction:`arming`}}},this.updateElement(),this.startPasskeyPreparation();return}this.stateValue={kind:`preparing`,viewModel:{...t,status:_(Y(e.error))}},this.updateElement()}};function $t(e){throw Error(`Unhandled auth-menu intent: ${String(e)}`)}function en(e){throw Error(`Unhandled link-device flow outcome: ${String(e)}`)}function tn(e){throw Error(`Unhandled linked-device target-factor activation: ${String(e)}`)}function nn(e){throw Error(`Unhandled hosted passkey preparation: ${String(e)}`)}function rn(e){throw Error(`Unhandled hosted external-auth evidence: ${String(e)}`)}function an(e){return`${e.walletId}:${e.authMethod}`}function on(e,t){let n=String(e.walletId);switch(e.authMethod){case`passkey`:return{walletId:n,authMethod:`passkey`};case`email_otp`:return{walletId:n,authMethod:`email_otp`,emailAddress:e.emailAddress??(t?.authMethod===`email_otp`?t.emailAddress:null)}}}function sn(e,t=[]){let n=new Map;for(let t of e?.accounts??[]){if(t.authMethod!==p.passkey&&t.authMethod!==p.emailOtp)continue;let e=String(t.walletId||``).trim();if(!e)continue;let r=t.authMethod===p.passkey?{walletId:e,authMethod:`passkey`}:{walletId:e,authMethod:`email_otp`,emailAddress:null};n.set(an(r),r)}for(let e of t){let t=String(e.walletId||``).trim();if(!t)continue;let r=`${t}:${e.authMethod}`,i=on(e,n.get(r));n.set(r,i)}return[...n.values()]}function cn(e,t){let n=e?.lastUsedAccount;if(n?.authMethod===p.passkey||n?.authMethod===p.emailOtp){let e=String(n.walletId||``).trim(),r=t.find(t=>t.walletId===e&&t.authMethod===n.authMethod);if(r)return r}return t[0]??null}function ln(e){let t=e?.lastUsedAccount;return!t||t.authMethod!==p.passkey&&t.authMethod!==`linked_device`?null:String(t.walletId||``).trim()||null}async function un(e){let t=await import(`./recovery-entrypoint-Bl5GgbW9.js`),n=e();return t.createHostedRecoveryPort({context:n.getContext(),relayUrl:String(n.configs.network.relayer.url)})}var dn=class{constructor(e){this.getWalletRuntime=e,this.portPromise=null}targetFor(e){if(e===`google_email_otp`)return{kind:e,googleProvider:`google`};let n=t(this.getWalletRuntime().getContext().signingEngine.getRpId());if(!n.ok)throw Error(`wallet recovery RP ID ${n.error.message}`);return{kind:e,rpId:n.value}}async prepare(e){return await(await this.port()).prepare(e)}async createPasskey(e){return await(await this.port()).createPasskey(e)}async verifyGoogle(e,t){return await(await this.port()).verifyGoogle(e,t)}async verifyEmailOtp(e,t){return await(await this.port()).verifyEmailOtp(e,t)}async finalize(e){return await(await this.port()).finalize(e)}async cancel(e){await(await this.port()).cancel(e)}port(){return this.portPromise??=un(this.getWalletRuntime),this.portPromise}};function fn(){try{let e=document.referrer.trim();if(e){let t=new URL(e).hostname.trim();if(t)return t}}catch{}return window.location.hostname||`Wallet`}function pn(e){switch(e.kind){case`discoverable`:return null;case`wallet`:case`wallet_sync`:return String(e.walletId)}}function mn(e){window.setTimeout(e,0)}function hn(){return new Promise(mn)}var gn=class{constructor(e){this.deps=e,this.sessions=new Map,this.startDeviceLinking=async(e,t)=>await this.deps.getWalletRuntime().devices.startLinking({...e,options:t}),this.cancelDeviceLinking=async()=>await this.deps.getWalletRuntime().devices.cancelLinking()}async open(e){if(!e.requestId)throw Error(`Hosted auth-menu open request requires requestId`);let t=_e(e.requestId);if(this.sessions.has(e.request.authMenuSessionId))throw Error(`Hosted auth-menu session is already active`);let n=new Qt({request:e.request,requestId:t,appearance:this.deps.getAppearance(),hostname:fn(),beginGoogleEmailOtp:async({idToken:e,authTarget:t,signal:n})=>await this.beginGoogleEmailOtp({idToken:e,authTarget:t,signal:n}),startDeviceLinking:this.startDeviceLinking,cancelDeviceLinking:this.cancelDeviceLinking,recoveryPort:new dn(this.deps.getWalletRuntime),prepareRecoveredLogin:this.prepareRecoveredLogin.bind(this,t,e.request.authMenuSessionId),sendToParent:this.deps.send}),r=n.waitForOutcome(),i=pn(e.request.loginTarget);this.sessions.set(e.request.authMenuSessionId,n);try{return n.mount(),await hn(),n.setRegistrationPreparation((r,i)=>this.prepareRegistration(e.request,t,n.identity.authMenuSessionId,r,i)),i?await this.bootstrapLoginAccounts(n,t,e.request.loginTarget):(n.setLoginPreparation({accountOptions:[],selectedAccount:null,prepare:(r,i)=>this.prepareLogin(t,n.identity.authMenuSessionId,i,r,null,e.request.loginTarget)}),this.bootstrapLoginAccounts(n,t,e.request.loginTarget)),await r}finally{n.cleanup(),this.sessions.delete(e.request.authMenuSessionId)}}async bootstrapLoginAccounts(e,t,n){let[r,i]=await Promise.all([this.deps.getWalletRuntime().auth.getRecentUnlocks().catch(()=>null),d().catch(()=>[])]);if(e.state.kind===`complete`)return;let a=pn(n),o=sn(r,i),s=a?o.filter(e=>e.walletId===a):o,c=s.length>0||!a?s:[{walletId:a,authMethod:p.passkey}];e.setLoginPreparation({accountOptions:c,selectedAccount:a?c[0]??null:cn(r,c),prepare:(i,a)=>this.prepareLogin(t,e.identity.authMenuSessionId,a,i,r,n)}),i.length>0&&e.defaultToLoginForDetectedLocalWallet()}async prepareLogin(e,t,n,r,i,a){let o=L(this.deps.getWalletRuntime().getContext()),s=i??await this.deps.getWalletRuntime().auth.getRecentUnlocks().catch(()=>null),c=(await d().catch(()=>[])).find(e=>e.authMethod===p.passkey),l=r||ln(s)||c?.walletId||null;return a.kind===`wallet_sync`?await U({context:o,walletId:String(a.walletId),authMenuSessionId:t,requestId:e,cancellation:n}):l?await H({context:o,walletId:l,authMenuSessionId:t,requestId:e,cancellation:n}):await U({context:o,walletId:l,authMenuSessionId:t,requestId:e,cancellation:n})}async prepareRecoveredLogin(e,t,n,r){return await H({context:L(this.deps.getWalletRuntime().getContext()),walletId:String(n),authMenuSessionId:t,requestId:e,cancellation:r})}async beginGoogleEmailOtp(e){if(e.signal.aborted)throw Error(`Google sign-in was cancelled`);let t=await this.deps.getWalletRuntime().auth.startGoogleSignIn({idToken:e.idToken,...e.authTarget});if(!t.ok)throw Error(t.error.message);let n=t.value;if(e.signal.aborted)throw await n.cancel().catch(()=>{}),Error(`Google sign-in was cancelled`);return n}async prepareRegistration(e,n,r,i,a){let o=this.deps.getWalletRuntime().getContext(),s=t(String(o.signingEngine.getRpId()||``));if(!s.ok)throw Error(s.error.message);let c={kind:`provided`,walletId:Te(i)},l=xe({configs:o.configs,wallet:c,preference:e.registrationAccountInput===`sponsored_named_near_account`?{kind:`relayer_named_subaccount`}:{kind:`implicit_account`}});return await Se({context:o,wallet:c,signerSelection:ve({configs:o.configs,accountProvisioning:l,options:{}}),authMethod:{kind:`passkey`,rpId:s.value},authMenuSessionId:r,requestId:n,cancellation:a,options:{}})}cancel(e){let t=this.sessions.get(e.authMenuSessionId);return!t||t.identity.requestId!==e.requestId?!1:(t.cancel(e.reason),!0)}resolveExternalAuth(e){let t=this.sessions.get(e.authMenuSessionId);return!t||t.identity.requestId!==e.requestId?!1:t.acceptExternalAuthResolution(e)}};function _n(e,t=new gn({getWalletRuntime:e.getWalletRuntime,getAppearance:()=>e.getWalletRuntime().configs.ui.appearance,send:e.post})){return{PM_OPEN_AUTH_MENU:async n=>{let r=i(n.payload);if(!r)throw Error(`Hosted auth-menu open request is invalid`);let a=await t.open({request:r,requestId:n.requestId});(a.kind===`authenticated`||a.kind===`registered`||a.kind===`account_synced`)&&await e.publishCurrentSession(),!e.respondIfCancelled(n.requestId)&&f(e,n.requestId,a)},PM_CANCEL_AUTH_MENU:async n=>{let r=a(n.payload);if(!r)throw Error(`Hosted auth-menu cancellation is invalid`);let i=t.cancel(r);f(e,n.requestId,{cancelled:i})},PM_RESOLVE_AUTH_MENU_EXTERNAL_AUTH:async n=>{let i=r(n.payload);if(!i)throw Error(`Hosted auth-menu external-auth resolution is invalid`);let a=t.resolveExternalAuth(i);f(e,n.requestId,{accepted:a})}}}function vn(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e,n=t.options&&typeof t.options==`object`&&!Array.isArray(t.options)?t.options:null,r=n?.ecdsaKeyFactsInventory&&typeof n.ecdsaKeyFactsInventory==`object`&&!Array.isArray(n.ecdsaKeyFactsInventory)?n.ecdsaKeyFactsInventory:null,i=r?.value&&typeof r.value==`object`&&!Array.isArray(r.value)?r.value:null;if(i&&(Object.prototype.hasOwnProperty.call(i,`walletSessionToken`)||Object.prototype.hasOwnProperty.call(i,`operationCredential`)))throw Error(`wallet iframe unlock requests must not carry a Wallet Session bearer`)}function yn(e,t){let n=e.ecdsaKeyFactsInventory,{ecdsaKeyFactsInventory:r,...i}=e;if(!n)return i;if(n.mode===`webauthn`)return{...i,ecdsaKeyFactsInventory:n};let a=ae(t);if(!a)throw Error(`Hosted-wallet Wallet Session is required for opaque key-facts lookup`);return{...i,ecdsaKeyFactsInventory:{mode:`wallet_session_operation_credential_v1`,operationCredential:a}}}function bn(e,t){return String(t?.walletId||``).trim()||String(e.preferences.getCurrentWalletId()||``).trim()||void 0}function xn(e){console.warn(`[WalletIframeHost] Restored-session presignature prefill failed:`,e)}function Sn(e,t,n,r,i){e.respondIfCancelled(n)||(f(e,n,i),r.authenticationRead===`restore`&&t.prefillRestoredWalletSession(i.state).catch(xn))}function Cn(e){return{..._n(e),PM_UNLOCK:async t=>{let n=e.getWalletRuntime();vn(t.payload);let r=Ue(t.payload),i=yn(We(r),n.configs.network.relayer.url);if(e.respondIfCancelled(t.requestId))return;let a=await n.auth.unlock(r.walletId,le(e,t.requestId,i));e.respondIfCancelled(t.requestId)||(a.success||u(),await e.publishCurrentSession(),!e.respondIfCancelled(t.requestId)&&f(e,t.requestId,a))},PM_LOCK:async t=>{let n=e.getWalletRuntime();u(),await n.auth.lock(),de(e,t.requestId)},PM_LOCK_EXACT_WALLET_SESSION:async t=>{let n=e.getWalletRuntime(),r=l(t.payload),i=await re(n,{authenticationRead:`current`,wallet:{kind:`current`}},new ke);if(i.kind!==`active_session`&&i.kind!==`expired_session`||!he(i,r)){f(e,t.requestId,{kind:`stale_session`,expected:r,current:i});return}u(),await n.auth.lock(),f(e,t.requestId,{kind:`locked`,identity:r})},...Re(e),PM_GET_WALLET_SESSION:async t=>{let n=e.getWalletRuntime(),r=bn(n,t.payload),i=await n.auth.getSession(r);f(e,t.requestId,i)},PM_GET_EXACT_WALLET_SESSION_STATE:async t=>{let n=e.getWalletRuntime(),r=t.payload;if(!r||r.authenticationRead!==`restore`&&r.authenticationRead!==`current`||!r.wallet||r.wallet.kind!==`current`&&r.wallet.kind!==`exact`||r.authenticationRead===`restore`&&r.wallet.kind!==`current`)throw Error(`Wallet iframe exact session read mode is invalid`);await e.observeSession(r,Sn.bind(null,e,n,t.requestId,r))},PM_GET_RECENT_UNLOCKS:async t=>{let n=await e.getWalletRuntime().auth.getRecentUnlocks();f(e,t.requestId,n)}}}async function wn(e){await ne(e,Cn)}export{wn as handleWalletHostRuntimeRequest};
|
|
1
|
+
import{L as e,V as t}from"./normalize-kUDm5zfS.js";import{k as n}from"./chains-CiYQT1K4.js";import"./primitives-CAcl7ON7.js";import"./sessionPolicy-J-RrlPZQ.js";import"./signingSessionSeal-CDLUmAFY.js";import{c as r,l as i,o as a,r as o,s}from"./messages-vxz27Way.js";import{C as c,S as l,T as ee,_ as te,a as ne,b as re,c as ie,d as ae,f as u,g as oe,h as se,l as ce,m as d,n as f,r as le,s as ue,t as de,u as fe,v as pe,w as me,x as he,y as ge}from"./shared-8ffIBYw2.js";import"./activeWalletSession-DiZcKjB_.js";import"./capabilityKinds-CKQ4Uqnv.js";import{t as _e}from"./walletIframeIdentity-DJ0KOBHg.js";import"./errors-BZO3LF6G.js";import"./digestEncoding-Dzc1rzWV.js";import{en as ve,i as ye,n as be,nn as xe,r as Se,s as Ce}from"./registration-CEqVAgNJ.js";import"./accountIds-BzZs7YoX.js";import"./registrationSignerPlan-B9GCvpTV.js";import{a as p}from"./signerDomain-vQmlnsbF.js";import"./registrationIntent-DOkZcKSP.js";import"./singletons-8UH3gOnZ.js";import"./walletAuthority-B5hXHWpK.js";import"./emailOtpEcdsaDerivationIdentity-B8HzTh4T.js";import{t as we}from"./challengeDelivery-DxXAkOfS.js";import{a as Te,n as Ee}from"./registrationIds-CdPqm-Ya.js";import"./passkey-custody-BQj44jEM.js";import{c as De,s as Oe}from"./sdkSentEvents-D3q1h-Uo.js";import"./walletCustodyEcdsaContinuity-abNZ_dvX.js";import"./keccak-B02Fekdh.js";import"./wallet-recovery-C1kesLCF.js";import"./nearEd25519YaoMaterialActivation-fWQI3rYj.js";import{t as ke}from"./walletSessionAuthorizationStatus-o1VgsLhA.js";import"./signNear-BhTkDm2-.js";import{a as Ae,i as je}from"./adapters-DdDOQzl4.js";import{t as Me}from"./surface-measurement-reporter-IlPOI3QK.js";import{a as Ne,c as Pe,i as Fe,l as m,n as Ie,o as Le,t as h}from"./jsxRuntime.module-BcZNe_OA.js";function Re(e){return{PM_GET_LAST_WALLET_MOVE_REQUEST:He.bind(null,e),PM_MOVE_WALLET:Ve.bind(null,e),PM_GET_WALLET_PLACEMENT:ze.bind(null,e),PM_GET_WALLET_MOVE:Be.bind(null,e)}}async function ze(t,r){let i=n(r.payload,`Wallet placement request`),a=e(i.walletId);if(!a.ok||Object.keys(i).length!==1)throw Error(`Wallet placement identity is invalid`);let o=await t.getWalletRuntime().placement.get(a.value);t.respondIfCancelled(r.requestId)||f(t,r.requestId,o)}async function Be(t,r){let i=n(r.payload,`Wallet move request`),a=e(i.walletId),o=ce(i.moveId);if(!a.ok||Object.keys(i).length!==2)throw Error(`Wallet move request is invalid`);let s=await t.getWalletRuntime().placement.getMove(a.value,o);t.respondIfCancelled(r.requestId)||f(t,r.requestId,s)}async function Ve(e,t){let n=fe(t.payload),r=await e.getWalletRuntime().placement.move(n);e.respondIfCancelled(t.requestId)||f(e,t.requestId,r)}async function He(t,r){let i=n(r.payload,`Wallet move locator request`),a=e(i.walletId);if(!a.ok||Object.keys(i).length!==1)throw Error(`Wallet move locator identity is invalid`);let o=await t.getWalletRuntime().placement.getLastMoveRequest(a.value);t.respondIfCancelled(r.requestId)||f(t,r.requestId,o)}function Ue(e){if(!e)throw Error(`PM_UNLOCK payload is required`);return e}function We(e){switch(e.kind){case`default_options`:return{};case`custom_options`:return{...g(`signerSlot`,e.options.signerSlot),...g(`signingSession`,e.options.signingSession),...g(`unlockSelection`,e.options.unlockSelection),...Ge(e.options.ecdsaKeyFactsInventory)}}}function Ge(e){switch(e.kind){case`default`:return{};case`value`:return{ecdsaKeyFactsInventory:e.value}}}function g(e,t){switch(t.kind){case`default`:return{};case`value`:return{[e]:t.value}}}function Ke(e){return e===`register`?`Creating passkey wallet…`:`Unlocking wallet…`}const qe=/\bHTTP 429\b|too many requests|rate limit/i,Je=/\bHTTP 5\d\d\b|failed to fetch|load failed|networkerror|network request failed|connection ?closed/i,Ye=/timed out|timeout/i;function Xe(e){return qe.test(e)?`Too many attempts. Wait a moment.`:Je.test(e)?`Can’t reach Seams right now.`:Ye.test(e)?`That took too long.`:`Something went wrong.`}function _(e){return{kind:`recoverable`,reason:`error`,message:Xe(e),detail:e}}function v(e,t){let n=t?e.find(e=>e.walletId===t.walletId&&e.authMethod===t.authMethod):null,r=t?e.find(e=>e.walletId===t.walletId):null,i=n??r??e[0];if(!i)return{kind:`discoverable`,selectedAccount:null,loginTarget:{kind:`discoverable`}};let a=e.filter(e=>e.walletId===i.walletId),o=a.some(e=>e.authMethod===`passkey`),s=a.some(e=>e.authMethod===`email_otp`),c={selectedAccount:i,walletId:i.walletId,loginTarget:{kind:`wallet`,walletId:i.walletId}};if(o&&s)return{kind:`passkey_and_email_otp`,...c};if(o)return{kind:`passkey`,...c};if(s)return{kind:`email_otp`,...c};throw Error(`Selected auth-menu account has no supported authentication method`)}function y(e){switch(e.kind){case`discoverable`:case`passkey`:case`passkey_and_email_otp`:return!0;case`email_otp`:return!1}}function Ze(e){switch(e.kind){case`discoverable`:case`email_otp`:case`passkey_and_email_otp`:return!0;case`passkey`:return!1}}function b(e){return e.kind===`busy`}function Qe(e){let t=e.status;return t.kind===`idle`&&t.interaction===`actionable`}function $e(e){let t=e.status;return t.kind===`recoverable`?!0:t.kind===`idle`&&t.interaction===`actionable`}function x(e){if(!$e(e))return!1;switch(e.kind){case`google_otp_login`:return!e.submitBusy&&/^\d{6}$/.test(e.otpCode);case`google_registration`:return!e.rerollBusy&&!e.submitBusy;case`link_device`:return!1;case`recovery`:return e.stage===`passkey_ready`||e.stage===`google_ready`||e.stage===`sign_in_ready`||e.stage===`email_code_required`&&/^\d{6}$/.test(e.otpCode);case`passkey`:return e.mode===`login`?y(v(e.accountOptions,e.selectedAccount)):!e.showRegistrationInput||e.passkeyName.trim().length>0}}function S(e){return $e(e)?e.kind!==`passkey`||e.mode!==`login`?!0:Ze(v(e.accountOptions,e.selectedAccount)):!1}const et=()=>new Promise(e=>setTimeout(e,90));function tt(e){return e.dataset.blink?null:(e.dataset.blink=`off`,et().then(()=>(e.dataset.blink=`on`,et())).then(()=>{delete e.dataset.blink}))}function C(e,t,...n){return h(m,{children:h(`svg`,{width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":t,"stroke-linecap":`round`,"stroke-linejoin":`round`,"aria-hidden":`true`,children:n})})}function w(){return C(`22`,`1.5`,h(`path`,{d:`M6.405 19.048c.184-.443.353-.894.507-1.351`}),h(`path`,{d:`M14.343 20.693c.266-.751.502-1.516.707-2.294.186-.706.346-1.422.478-2.147`}),h(`path`,{d:`M19.448 17.058c.364-1.964.555-3.989.555-6.058 0-4.418-3.582-8-8-8-1.255 0-2.443.289-3.501.805`}),h(`path`,{d:`M3.523 15.025c.314-1.29.48-2.638.48-4.025 0-1.74.556-3.351 1.499-4.664`}),h(`path`,{d:`M12.003 11c0 2.76-.447 5.416-1.273 7.899-.213.639-.451 1.266-.712 1.881`}),h(`path`,{d:`M7.712 14.5c.191-1.138.291-2.308.291-3.5 0-2.209 1.791-4 4-4s4 1.791 4 4c0 .617-.02 1.229-.058 1.836`}))}function nt(){return h(m,{children:h(`svg`,{class:`seams-account-dropdown-arrow`,viewBox:`0 0 24 24`,"aria-hidden":`true`,focusable:`false`,children:h(`path`,{d:`M9.75 3h4.5v10.28l4.3-4.3 3.18 3.18L12 21.9l-9.73-9.74 3.18-3.18 4.3 4.3V3Z`})})})}function rt(){return C(`18`,`2.25`,h(`path`,{d:`m15 18-6-6 6-6`}))}function it(){return C(`18`,`2`,h(`rect`,{width:`5`,height:`5`,x:`3`,y:`3`,rx:`1`}),h(`rect`,{width:`5`,height:`5`,x:`16`,y:`3`,rx:`1`}),h(`rect`,{width:`5`,height:`5`,x:`3`,y:`16`,rx:`1`}),h(`path`,{d:`M21 16h-3a2 2 0 0 0-2 2v3`}),h(`path`,{d:`M21 21v.01`}),h(`path`,{d:`M12 7v3a2 2 0 0 1-2 2H7`}),h(`path`,{d:`M3 12h.01`}),h(`path`,{d:`M12 3h.01`}),h(`path`,{d:`M12 16v.01`}),h(`path`,{d:`M16 12h1`}),h(`path`,{d:`M21 12v.01`}),h(`path`,{d:`M12 21v-1`}))}function at(){return C(`18`,`2`,h(`path`,{d:`M20 11v6`}),h(`path`,{d:`M20 13h2`}),h(`path`,{d:`M3 21v-2a4 4 0 0 1 4-4h6a4 4 0 0 1 2.072.578`}),h(`circle`,{cx:`10`,cy:`7`,r:`4`}),h(`circle`,{cx:`20`,cy:`19`,r:`2`}))}function ot(){return C(`21`,`1.75`,h(`rect`,{x:`2.75`,y:`5`,width:`18.5`,height:`14`,rx:`2.75`}),h(`path`,{d:`m3.75 7.75 6.94 4.86a2.25 2.25 0 0 0 2.62 0l6.94-4.86`}))}function st(){return C(`22`,`1.75`,h(`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`}),h(`path`,{d:`M15 7h2a5 5 0 0 1 3.54 8.54`}),h(`path`,{d:`m2 2 20 20`}),h(`path`,{d:`M8 12h3`}))}function ct(){return h(m,{children:h(`svg`,{class:`seams-input-action-icon`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":`2`,"stroke-linecap":`round`,"stroke-linejoin":`round`,"aria-hidden":`true`,children:[h(`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`}),h(`path`,{d:`M21 3v5h-5`}),h(`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`}),h(`path`,{d:`M8 16H3v5`})]})})}function T(){return h(`svg`,{width:`18`,height:`18`,viewBox:`0 0 48 48`,"aria-hidden":`true`,children:[h(`path`,{fill:`#EA4335`,d:`M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z`}),h(`path`,{fill:`#4285F4`,d:`M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z`}),h(`path`,{fill:`#FBBC05`,d:`M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z`}),h(`path`,{fill:`#34A853`,d:`M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z`})]})}function E(){return C(`13`,`1.75`,h(`path`,{d:`m9 6 6 6-6 6`}))}function lt(){return C(`14`,`1.6`,h(`path`,{d:`M12 3 4.5 6v5.5c0 4.2 2.7 7.4 7.5 9.5 4.8-2.1 7.5-5.3 7.5-9.5V6L12 3Z`}),h(`path`,{d:`m8.5 11.5 2.5 2.5 4.5-5`}))}function ut(){return C(`15`,`1.6`,h(`path`,{d:`M12 8v5`}),h(`path`,{d:`M12 16v.1`}),h(`circle`,{cx:`12`,cy:`12`,r:`9`}))}var dt=class extends Le{constructor(...e){super(...e),this.shownNotice=``}render(){let{notice:e,onRetry:t}=this.props;return e&&(this.shownNotice=e),h(`div`,{class:`seams-auth-footer`,"data-state":e?`notice`:`brand`,children:[h(`div`,{class:`seams-auth-footer-brand`,"aria-hidden":e?`true`:void 0,children:[lt(),` `,h(`span`,{children:`Secured by`}),` `,h(je,{})]}),h(`div`,{class:`seams-auth-footer-notice`,children:[ut(),h(`span`,{class:`seams-auth-footer-text`,"aria-hidden":`true`,children:this.shownNotice}),h(`button`,{class:`seams-auth-footer-action`,type:`button`,disabled:!e,onClick:t,children:`Try again`})]}),e?h(`p`,{class:`sr-only`,role:`alert`,children:e}):null]})}};function D(e){let t=we(e);return t===null?null:h(`p`,{class:`seams-otp-description`,children:[`Demo email code: `,h(`code`,{children:t})]})}const O=`seams-auth-menu-title`,k=`seams-auth-menu-account-list`;function A(e){return e.padEnd(6,` `).slice(0,6).split(``)}function j(e){return h(m,{children:h(`span`,{class:`seams-otp-slot ${e.trim()?`is-filled`:``}`,children:e})})}function ft(e){let t=e.kind===`recovery`?`:${e.stage}`:``;return`${e.kind}:${e.mode}:${e.status.kind}${t}`}function pt(e){return e.status.kind===`busy`?e.status.headline:e.status.kind===`recoverable`?e.status.message:e.stage===`passkey_ready`?`Recovery code accepted.`:e.stage===`sign_in_ready`?`Wallet recovered. Unlock it to continue.`:``}function M(e){return e.kind===`recovery`&&e.stage===`finalizing`}function mt(e){return e===`register`?{prompt:`Already have a wallet?`,action:`Unlock wallet`,nextMode:`login`}:{prompt:`Don't have a wallet?`,action:`Create a wallet`,nextMode:`register`}}function ht(e){return e===`register`?`Create a wallet`:`Unlock wallet`}function gt(e){return e===`register`?`Create wallet with passkey`:`Unlock with passkey`}function _t(e){return e.kind===`google_otp_login`||e.kind===`google_registration`?e.error||null:e.kind===`passkey`&&e.status.kind===`recoverable`&&e.status.reason===`error`?e.status.message:null}function vt(e,t){return h(m,{children:h(`div`,{class:`seams-link-device-dot-ring is-${e}`,"aria-hidden":`true`,children:[Array.from({length:12},(e,t)=>h(m,{children:h(`span`,{"data-dot-index":t})})),t?h(m,{children:h(`div`,{class:`seams-link-device-dot-ring-glyph`,children:t})}):null,h(`svg`,{class:`seams-link-device-dot-ring-check`,viewBox:`0 0 52 52`,fill:`none`,stroke:`currentColor`,"stroke-width":`2.5`,"stroke-linecap":`round`,"stroke-linejoin":`round`,children:h(`path`,{d:`m18.5 27 5 5 10-11`})})]})})}function yt(e){switch(e.kind){case`sending`:return{ring:`waiting`,heading:`Sending your code`,status:`Emailing a 6-digit code`,pending:!0,tone:`neutral`};case`resending`:return{ring:`waiting`,heading:`Sending a new code`,status:`Emailing a fresh 6-digit code`,pending:!0,tone:`neutral`};case`submitting`:return{ring:`waiting`,heading:`Checking your code`,status:`Verifying the code you entered`,pending:!0,tone:`neutral`};case`code_input`:return{ring:`idle`,heading:`Verify your email`,status:`Enter the 6-digit code we just sent.`,pending:!1,tone:`neutral`};case`incorrect`:return{ring:`idle`,heading:`Verify your email`,status:e.message,pending:!1,tone:`error`};case`expired`:return{ring:`idle`,heading:`That code expired`,status:e.message,pending:!1,tone:`error`};case`unavailable`:return{ring:`idle`,heading:`Email code unavailable`,status:e.message,pending:!1,tone:`error`};case`completed`:return{ring:`approved`,heading:`Email verified`,status:`Finishing linking this device`,pending:!0,tone:`neutral`}}}function bt(e){return v(e.accountOptions,e.selectedAccount).selectedAccount}function xt(e){return e.walletId}function N(e){return e.authMethod===`email_otp`?e.emailAddress:null}function St(e){if(!e)return`Saved wallets`;let t=N(e);return t?`Saved wallets. Selected wallet ID ${e.walletId}, email ${t}`:`Saved wallets. Selected ${e.walletId}`}function Ct(e){let t=e.filter(e=>e.authMethod===`passkey`),n=e.filter(e=>e.authMethod===`email_otp`);return[{authMethod:`passkey`,label:`Passkey`,accounts:t},{authMethod:`email_otp`,label:`Email OTP`,accounts:n}].filter(e=>e.accounts.length>0)}var wt=class extends Le{constructor(...e){super(...e),this.state={accountMenu:`closed`},this.accountMenuExitTimer=null,this.accountMenuChoice=null,this.previouslyFocusedElement=null,this.shouldFocusInitialControl=!0,this.contentResizeObserver=null,this.contentHeightFrame=null,this.previousLinkDeviceStateKind=null,this.previousRecoveryStage=null,this.lastMethod=`passkey`,this.queueContentHeightSync=()=>{this.contentHeightFrame!==null&&cancelAnimationFrame(this.contentHeightFrame),this.contentHeightFrame=requestAnimationFrame(this.syncContentHeight)},this.syncContentHeight=()=>{this.contentHeightFrame=null;let e=this.props.element.querySelector(`.seams-content-switcher`),t=this.props.element.querySelector(`.seams-content-sizer`);!e||!t||this.props.styles.setDynamicDeclarations(this.props.element.id+`-height`,`#`+this.props.element.id+` .seams-content-switcher`,{height:t.scrollHeight+`px`})},this.onKeydown=e=>{if(e.key===`Escape`){if(e.preventDefault(),this.viewModel&&M(this.viewModel))return;if(this.accountMenuOpen){this.closeAccountMenu();return}this.emitIntent({kind:`close`,reason:`escape`});return}if(e.key!==`Tab`)return;let t=this.focusableElements();if(t.length===0)return;let n=document.activeElement,r=t.indexOf(n instanceof HTMLElement?n:t[0]);e.shiftKey&&r<=0?(e.preventDefault(),t[t.length-1]?.focus()):!e.shiftKey&&r===t.length-1&&(e.preventDefault(),t[0]?.focus())},this.onBackClick=()=>{this.emitIntent({kind:`back`})},this.onKeyDown=e=>{if(e.key!==`Escape`||e.defaultPrevented)return;let t=this.viewModel;!t||t.kind!==`recovery`&&!b(t.status)||(e.preventDefault(),e.stopPropagation(),!M(t)&&this.emitIntent({kind:`back`}))},this.onIntentSwitchClick=()=>{let e=this.viewModel;e&&this.emitIntent({kind:`mode_selected`,mode:mt(e.mode).nextMode})},this.onRegistrationReroll=()=>{this.emitIntent({kind:`registration_reroll`})},this.onPasskeyNameInput=e=>{e.currentTarget instanceof HTMLInputElement&&this.emitIntent({kind:`passkey_name_changed`,passkeyName:e.currentTarget.value})},this.onLoginAccountSelect=e=>{let t=e.currentTarget;if(!(t instanceof HTMLButtonElement))return;let n=t.dataset.walletId,r=t.dataset.authMethod,i=this.viewModel;if(!n||i.kind!==`passkey`||i.mode!==`login`)return;let a=i.accountOptions.find(e=>e.walletId===n&&e.authMethod===r),o=bt(i);if(!a||!o||this.accountMenuChoice)return;let s=tt(t);if(!s)return;let c={chosen:a,previous:o};this.accountMenuChoice=c,this.emitIntent({kind:`login_account_selected`,walletId:a.walletId,authMethod:a.authMethod}),s.then(()=>{this.accountMenuChoice===c&&this.closeAccountMenu()})},this.onAccountMenuToggle=()=>{this.accountMenuOpen?this.closeAccountMenu():this.openAccountMenu()},this.onDocumentPointerDown=e=>{!this.accountMenuOpen||!(e.target instanceof Node)||this.props.element.querySelector(`.seams-account-menu`)?.contains(e.target)||this.closeAccountMenu()},this.onPrimaryClick=()=>{let e=this.viewModel;if(!e||!x(e)||e.kind===`link_device`)return;if(e.kind===`google_otp_login`){this.emitIntent({kind:`google_otp_submit`});return}if(e.kind===`google_registration`){this.emitIntent({kind:`google_registration_complete`});return}let t=e.mode===`register`?{kind:`submit`,mode:`register`,passkeyName:e.passkeyName}:{kind:`submit`,mode:`login`};this.lastMethod=`passkey`,this.emitIntent(t)},this.onGoogleOtpCodeInput=e=>{e.currentTarget instanceof HTMLInputElement&&this.emitIntent({kind:`google_otp_code_changed`,code:e.currentTarget.value})},this.onGoogleOtpKeydown=e=>{e.key===`Enter`&&(e.preventDefault(),this.emitIntent({kind:`google_otp_submit`}))},this.onGoogleOtpResend=()=>{this.emitIntent({kind:`google_otp_resend`})},this.onGoogleRegistrationReroll=()=>{this.emitIntent({kind:`google_registration_reroll`})},this.onGoogleClick=()=>{this.lastMethod=`google`,this.emitIntent({kind:`external_auth`,provider:`google`})},this.onNoticeRetry=()=>{this.lastMethod===`google`&&S(this.viewModel)?this.onGoogleClick():this.onPrimaryClick()},this.onLinkDeviceOpen=()=>{this.emitIntent({kind:`link_device_open`})},this.onRecoveryOpen=()=>{this.emitIntent({kind:`recovery_open`})},this.onRecoveryCodeInput=e=>{e.currentTarget instanceof HTMLInputElement&&this.emitIntent({kind:`recovery_code_changed`,recoveryCode:e.currentTarget.value})},this.onRecoverySubmit=e=>{e.preventDefault()},this.onRecoveryPasskeySelected=()=>{this.emitIntent({kind:`recovery_passkey_selected`})},this.onRecoveryGoogleSelected=()=>{this.emitIntent({kind:`recovery_google_selected`})},this.onRecoveryGoogleOtpCodeInput=e=>{e.currentTarget instanceof HTMLInputElement&&this.emitIntent({kind:`recovery_google_otp_code_changed`,code:e.currentTarget.value})},this.onRecoveryGoogleOtpKeydown=e=>{e.key===`Enter`&&(e.preventDefault(),this.emitIntent({kind:`recovery_google_otp_submit`}))},this.onRecoveryGoogleOtpSubmit=()=>{this.emitIntent({kind:`recovery_google_otp_submit`})},this.onRecoveryCreatePasskey=()=>{this.emitIntent({kind:`recovery_create_passkey`})},this.onRecoverySignIn=()=>{this.emitIntent({kind:`recovery_sign_in`})},this.onLinkDeviceCreatePasskey=()=>{this.emitIntent({kind:`link_device_create_passkey`})},this.onLinkDeviceFactorChange=e=>{if(!(e.currentTarget instanceof HTMLInputElement))return;let t=e.currentTarget.value===`email_otp`?{kind:`email_otp`}:{kind:`passkey_prf`};this.emitIntent({kind:`link_device_factor_selected`,targetFactor:t})},this.onLinkDeviceTargetEmailInput=e=>{e.currentTarget instanceof HTMLInputElement&&this.emitIntent({kind:`link_device_target_email_changed`,emailAddress:e.currentTarget.value})},this.onLinkDeviceStart=()=>{this.emitIntent({kind:`link_device_start`})},this.onLinkDeviceEmailOtpCodeInput=e=>{e.currentTarget instanceof HTMLInputElement&&this.emitIntent({kind:`link_device_email_otp_code_changed`,code:e.currentTarget.value})},this.onLinkDeviceEmailOtpKeydown=e=>{e.key===`Enter`&&(e.preventDefault(),this.emitIntent({kind:`link_device_email_otp_submit`}))},this.onLinkDeviceEmailOtpResend=()=>{this.emitIntent({kind:`link_device_email_otp_resend`})},this.onLinkDeviceEmailOtpSubmit=()=>{this.emitIntent({kind:`link_device_email_otp_submit`})}}get viewModel(){return this.props.viewModel}get accountMenuOpen(){return this.state.accountMenu===`open`}openAccountMenu(){this.endAccountMenuExit(),this.setState({accountMenu:`open`})}closeAccountMenu(){this.accountMenuOpen&&(this.setState({accountMenu:`closing`}),this.accountMenuExitTimer=setTimeout(()=>{this.endAccountMenuExit(),this.setState({accountMenu:`closed`})},160))}endAccountMenuExit(){this.accountMenuExitTimer!==null&&clearTimeout(this.accountMenuExitTimer),this.accountMenuExitTimer=null,this.accountMenuChoice=null}componentDidMount(){let e=document.activeElement;e instanceof HTMLElement&&!this.props.element.contains(e)&&(this.previouslyFocusedElement=e),document.addEventListener(`pointerdown`,this.onDocumentPointerDown),document.addEventListener(`keydown`,this.onKeyDown,!0),this.afterRender()}componentDidUpdate(e){this.afterRender(e.viewModel)}componentWillUnmount(){this.contentResizeObserver?.disconnect(),this.contentResizeObserver=null,this.contentHeightFrame!==null&&cancelAnimationFrame(this.contentHeightFrame),this.contentHeightFrame=null,this.endAccountMenuExit(),window.removeEventListener(`resize`,this.queueContentHeightSync),document.removeEventListener(`pointerdown`,this.onDocumentPointerDown),document.removeEventListener(`keydown`,this.onKeyDown,!0),this.props.styles.deleteDynamicRule(this.props.element.id+`-height`),this.restoreFocus()}afterRender(e){this.shouldFocusInitialControl&&this.focusInitialControl(),this.focusRecoveryControl(e),this.focusLinkDevicePasskeyAction(),this.observeContentSize(),this.queueContentHeightSync()}focusRecoveryControl(e){let t=this.viewModel;if(e?.kind===`recovery`&&t.kind!==`recovery`){this.previousRecoveryStage=null,this.props.element.querySelector(`[data-recovery-action]`)?.focus();return}if(t.kind!==`recovery`)return;let n=this.previousRecoveryStage!==t.stage;if(this.previousRecoveryStage=t.stage,t.stage===`enter_code`){let t=this.props.element.querySelector(`[aria-invalid="true"]`);if(t){t.focus();return}(e?.kind!==`recovery`||e.stage!==`enter_code`)&&this.props.element.querySelector(`[data-recovery-code]`)?.focus();return}let r=t.status.kind===`recoverable`&&e?.kind===`recovery`&&e.status.kind!==`recoverable`;(n||r)&&(t.stage===`passkey_ready`||t.stage===`finalizing`||t.stage===`sign_in_ready`)&&this.props.element.querySelector(`[data-auth-menu-primary]`)?.focus()}focusLinkDevicePasskeyAction(){let e=this.viewModel.kind===`link_device`?this.viewModel.linkDevice.kind:null,t=e===`passkey_required`&&this.previousLinkDeviceStateKind!==e;this.previousLinkDeviceStateKind=e,t&&this.props.element.querySelector(`[data-link-device-passkey-action]`)?.focus()}observeContentSize(){if(this.contentResizeObserver)return;let e=this.props.element.querySelector(`.seams-content-sizer`);e&&(this.contentResizeObserver=new ResizeObserver(this.queueContentHeightSync),this.contentResizeObserver.observe(e),window.addEventListener(`resize`,this.queueContentHeightSync))}focusInitialControl(){if(!this.props.element.isConnected||!this.shouldFocusInitialControl)return;this.shouldFocusInitialControl=!1;let e=document.activeElement;e instanceof HTMLElement&&this.props.element.contains(e)||this.props.element.querySelector(`[data-auth-menu-input], [data-auth-menu-primary]`)?.focus()}restoreFocus(){let e=this.previouslyFocusedElement;this.previouslyFocusedElement=null,e?.isConnected&&e.focus()}focusableElements(){return Array.from(this.props.element.querySelectorAll(`button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])`))}emitIntent(e){this.props.onIntent(e)}render(){let e=this.viewModel;if(!e)return h(m,{});let t=b(e.status),n=e.kind===`link_device`,r=e.kind===`google_otp_login`,i=e.kind===`google_registration`,a=e.kind===`recovery`;return h(m,{children:h(`div`,{class:`seams-signup-menu-root auth-menu-root`,"data-mode":e.mode,"data-waiting":t?`true`:`false`,"data-scan-device":n?`true`:`false`,"data-otp-prompt":r?`true`:`false`,"data-registration-prompt":i?`true`:`false`,"data-recovery":a?`true`:`false`,"aria-labelledby":O,"aria-busy":t?`true`:`false`,tabIndex:-1,onKeyDown:this.onKeydown,children:[h(`div`,{class:`seams-content-switcher`,children:[h(`button`,{class:`seams-back-button ${t||n||r||i||a?`is-visible`:``}`,type:`button`,"aria-label":a?`Back to unlock wallet`:`Back`,"data-auth-menu-close":!0,disabled:M(e),onClick:this.onBackClick,children:rt()}),a?h(`div`,{class:`sr-only`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:pt(e)}):null,h(`div`,{class:`seams-content-area`,children:h(`div`,{class:`seams-content-sizer`,children:t?this.renderWaiting(e):h(m,{children:h(`div`,{class:`seams-signin-menu`,children:h(m,{children:this.renderActiveView(e)},ft(e))})})})})]}),h(dt,{notice:_t(e),onRetry:this.onNoticeRetry})]})})}renderActiveView(e){return e.kind===`recovery`?this.renderRecovery(e):e.kind===`link_device`?this.renderLinkDevice(e):e.kind===`google_otp_login`?this.renderGoogleOtp(e):e.kind===`google_registration`?this.renderGoogleRegistration(e):h(m,{children:[this.renderMenuHeader(e),` `,this.renderPasskeyInput(e),this.renderAuthMethods(e),` `,this.renderOtherOptions(),this.renderIntentSwitch(e)]})}renderMenuHeader(e){let t=ht(e.mode);return h(`div`,{class:`seams-menu-header`,children:[h(`div`,{class:`seams-menu-origin`,children:[h(Ae,{}),` `,h(`span`,{children:e.hostname})]}),t===e.heading?null:h(`div`,{class:`seams-menu-eyebrow`,children:t}),h(`div`,{class:`seams-title`,id:O,children:e.heading}),e.subtitle?h(`div`,{class:`seams-subhead`,children:e.subtitle}):null]})}renderHeader(e){return h(m,{children:h(`div`,{class:`seams-header`,children:h(`div`,{children:[h(`div`,{class:`seams-title`,id:O,children:e.heading}),h(`div`,{class:`seams-subhead`,children:e.subtitle})]})})})}renderPasskeyInput(e){if(e.mode===`login`){let t=bt(e);if(!t)return h(m,{});let n=Ct(e.accountOptions),r=this.state.accountMenu,i=this.accountMenuChoice,a=i?.previous??t;return h(m,{children:h(`div`,{class:`seams-passkey-row`,children:h(`div`,{class:`seams-input-pill`,children:[h(`div`,{class:`seams-input-wrap`,children:h(`div`,{class:`seams-account-menu-account seams-selected-account`,"aria-hidden":`true`,children:[h(`span`,{class:`seams-account-menu-account-primary`,children:xt(t)}),N(t)?h(m,{children:h(`span`,{class:`seams-account-menu-account-secondary`,children:N(t)})}):null]})}),h(`div`,{class:`seams-account-menu ${r===`closed`?``:`is-open`}`,children:[h(`button`,{class:`seams-account-menu-trigger`,type:`button`,"data-auth-menu-input":!0,"aria-label":St(t),"aria-haspopup":`listbox`,"aria-expanded":this.accountMenuOpen?`true`:`false`,"aria-controls":k,onClick:this.onAccountMenuToggle,children:nt()}),r===`closed`?null:h(m,{children:h(`div`,{id:k,class:`seams-account-menu-popover ${r===`closing`?`is-closing`:``}`,role:`listbox`,children:n.map(e=>{let t=`${k}-${e.authMethod}`;return h(m,{children:h(`div`,{class:`seams-account-menu-group`,role:`group`,"aria-labelledby":t,children:[h(`div`,{id:t,class:`seams-account-menu-group-label`,children:e.label}),e.accounts.map(e=>{let t=e.walletId===a.walletId&&e.authMethod===a.authMethod,n=!t&&e.walletId===i?.chosen.walletId&&e.authMethod===i.chosen.authMethod,r=N(e);return h(m,{children:h(`button`,{class:`seams-account-menu-option ${t?`is-selected`:``} ${n?`is-chosen`:``}`,type:`button`,role:`option`,"aria-selected":t?`true`:`false`,title:r?`${e.walletId} ${r}`:e.walletId,"data-wallet-id":e.walletId,"data-auth-method":e.authMethod,onClick:this.onLoginAccountSelect,children:[h(`span`,{class:`seams-account-menu-check`,"aria-hidden":`true`}),h(`span`,{class:`seams-account-menu-account`,children:[h(`span`,{class:`seams-account-menu-account-primary`,children:e.walletId}),r?h(m,{children:h(`span`,{class:`seams-account-menu-account-secondary`,children:r})}):null]})]})})})]})})})})})]})]})})})}return e.showRegistrationInput?h(m,{children:h(`div`,{class:`seams-passkey-row`,children:h(`div`,{class:`seams-input-pill`,children:[h(`div`,{class:`seams-input-wrap`,children:h(`input`,{id:`seams-auth-menu-passkey-name`,class:`seams-input`,"data-auth-menu-input":!0,type:`text`,autocomplete:`nickname`,placeholder:e.passkeyNameLabel,value:e.passkeyName,readonly:e.passkeyNameReadOnly,disabled:b(e.status),onInput:this.onPasskeyNameInput})}),e.passkeyNameReadOnly?h(m,{children:h(`button`,{class:`seams-input-action-trigger auth-menu-registration-reroll`,type:`button`,title:`Generate another name`,"aria-label":`Generate another name`,onClick:this.onRegistrationReroll,disabled:!Qe(e),children:ct()})}):null]})})}):h(m,{})}renderAuthMethods(e){let t=e.enabledExternalProviders?.includes(`google`)??!1;return h(m,{children:h(`div`,{class:`seams-auth-methods`,children:[h(`button`,{class:`seams-auth-method-btn seams-auth-method-btn-primary`,type:`button`,"data-auth-menu-primary":!0,disabled:!x(e),onClick:this.onPrimaryClick,children:[w(),h(`span`,{children:gt(e.mode)})]}),t?h(`button`,{class:`seams-auth-method-btn`,type:`button`,"data-auth-menu-provider":`google`,disabled:!S(e),onClick:this.onGoogleClick,children:[T(),h(`span`,{children:`Continue with Google`})]}):null]})})}renderOtherOptions(){return h(m,{children:[h(`div`,{class:`seams-menu-options-label`,children:`Other options`}),h(`div`,{class:`seams-menu-options`,children:[h(`button`,{class:`seams-menu-option`,type:`button`,onClick:this.onLinkDeviceOpen,children:[h(`span`,{class:`seams-menu-option-icon`,children:it()}),h(`span`,{class:`seams-menu-option-text`,children:[`Link this device `,h(`small`,{children:`Scan a code with your other device`})]}),E()]}),h(`button`,{class:`seams-menu-option`,type:`button`,"data-recovery-action":!0,onClick:this.onRecoveryOpen,children:[h(`span`,{class:`seams-menu-option-icon`,children:at()}),h(`span`,{class:`seams-menu-option-text`,children:[`Recover wallet `,h(`small`,{children:`Use your recovery code`})]}),E()]})]})]})}renderRecovery(e){if(e.stage===`enter_code`){let t=e.status.kind===`recoverable`?e.status.message:``,n=e.recoveryCodeError??t,r=n.length>0;return h(m,{children:[this.renderHeader(e),h(`p`,{id:`seams-recovery-code-feedback`,class:`seams-recovery-status ${r?`seams-recovery-error`:``}`,"aria-hidden":r?`false`:`true`,role:r?`alert`:`status`,children:n}),h(`form`,{class:`seams-recovery-form`,novalidate:!0,onSubmit:this.onRecoverySubmit,children:[h(`div`,{class:`seams-recovery-field`,children:[h(`label`,{class:`seams-field-label`,for:`seams-recovery-code`,children:`Recovery code`}),h(`input`,{id:`seams-recovery-code`,class:`seams-recovery-input seams-recovery-code-input`,"data-recovery-code":!0,name:`recoveryCode`,type:`text`,autocomplete:`one-time-code`,autocapitalize:`characters`,autocorrect:`off`,spellcheck:!1,"aria-invalid":e.recoveryCodeError?`true`:`false`,"aria-describedby":e.recoveryCodeError?`seams-recovery-code-feedback`:``,value:e.recoveryCode,onInput:this.onRecoveryCodeInput})]}),h(`div`,{class:`seams-secondary-actions`,children:[h(`button`,{class:`seams-link-device-btn seams-auth-method-choice-btn`,type:`button`,"data-recovery-target":`passkey`,onClick:this.onRecoveryPasskeySelected,children:[h(`span`,{class:`seams-auth-method-choice-icon`,children:w()}),h(`span`,{children:`Recover with Passkey`})]}),h(`button`,{class:`seams-link-device-btn seams-auth-method-choice-btn`,type:`button`,"data-recovery-target":`google_email_otp`,onClick:this.onRecoveryGoogleSelected,children:[h(`span`,{class:`seams-auth-method-choice-icon`,children:T()}),h(`span`,{children:`Recover with Google`})]})]})]})]})}if(e.stage===`email_code_required`){let t=A(e.otpCode),n=/^\d{6}$/.test(e.otpCode)&&e.status.kind!==`busy`,r=e.delivery.status===`reused`?`Use the code already sent to ${e.emailHint}.`:`A 6-digit code was sent to ${e.emailHint}.`;return h(m,{children:[this.renderHeader(e),h(`div`,{class:`seams-otp-prompt`,"aria-live":`polite`,children:[h(`p`,{class:`seams-otp-description`,children:r}),D(e.delivery),h(`label`,{class:`seams-field-label`,for:`seams-recovery-google-otp`,children:`Email code`}),h(`div`,{class:`seams-otp-code-field`,"data-disabled":e.status.kind===`busy`?`true`:`false`,children:[h(`input`,{class:`seams-otp-input`,id:`seams-recovery-google-otp`,"data-auth-menu-input":!0,"data-email-otp-challenge-id":e.challengeId,"data-email-otp-wallet-id":e.walletId,name:`recoveryEmailOtpCode`,type:`text`,inputmode:`numeric`,autocomplete:`one-time-code`,spellcheck:!1,pattern:`[0-9]*`,maxLength:6,"aria-invalid":e.status.kind===`recoverable`?`true`:`false`,"aria-describedby":e.status.kind===`recoverable`?`seams-recovery-google-otp-error`:``,value:e.otpCode,disabled:e.status.kind===`busy`,onInput:this.onRecoveryGoogleOtpCodeInput,onKeyDown:this.onRecoveryGoogleOtpKeydown}),h(`div`,{class:`seams-otp-slots`,"aria-hidden":`true`,children:t.map(j)})]}),e.status.kind===`recoverable`?h(m,{children:h(`p`,{id:`seams-recovery-google-otp-error`,class:`seams-recovery-status seams-recovery-error`,role:`alert`,children:e.status.message})}):null,h(`button`,{class:`seams-link-device-btn seams-link-device-btn-primary`,type:`button`,"data-auth-menu-primary":!0,disabled:!n,onClick:this.onRecoveryGoogleOtpSubmit,children:`Verify email code`})]})]})}let t=e.stage===`finalizing`&&e.status.kind===`recoverable`,n=e.stage===`sign_in_ready`,r=e.target.kind===`google_email_otp`,i=e.status.kind===`recoverable`?e.status.message:n?null:e.stage===`google_ready`?`Continue with Google, then verify the code sent to your email.`:r?`Finishing recovery with Google…`:`Create a new passkey to finish recovering this wallet.`,a=n?this.onRecoverySignIn:r?t?this.onRecoveryGoogleOtpSubmit:this.onGoogleClick:this.onRecoveryCreatePasskey;return h(m,{children:[this.renderHeader(e),h(`div`,{class:`seams-recovery-confirmation`,children:[i===null?null:h(m,{children:h(`p`,{class:`seams-recovery-status`,children:i})}),h(`button`,{class:`seams-link-device-btn seams-link-device-btn-primary`,type:`button`,"data-auth-menu-primary":!0,onClick:a,children:[r&&!t?T():null,n?r?`Unlock with Google`:`Unlock with new passkey`:t?`Retry finalization`:r?`Continue with Google`:`Create new passkey`]})]})]})}renderIntentSwitch(e){let t=mt(e.mode);return h(m,{children:h(`div`,{class:`seams-auth-intent-switch`,children:[h(`span`,{children:t.prompt}),h(`button`,{type:`button`,"data-auth-menu-mode":t.nextMode,onClick:this.onIntentSwitchClick,children:t.action})]})})}renderWaiting(e){let t=e.status;if(t.kind!==`busy`)return h(m,{});let n=t.headline;return h(m,{children:h(`div`,{class:`seams-waiting`,role:`status`,"aria-live":`polite`,children:[h(`div`,{class:`seams-waiting-message`,children:[h(`span`,{class:`seams-waiting-text`,children:n}),e.showProgress&&t.detail&&t.detail!==n?h(m,{children:h(`span`,{class:`seams-waiting-sdk-events`,children:t.detail})}):null]}),h(`div`,{"aria-label":`Loading`,class:`seams-spinner`})]})})}renderLinkDevice(e){let t=e.linkDevice;if(t.kind===`select_factor`)return this.renderLinkDeviceFactorSelection(t);if(t.kind===`passkey_required`||t.kind===`creating_passkey`)return this.renderLinkDevicePasskeyConfirmation(t);if(t.kind===`email_otp_required`)return this.renderLinkDeviceEmailOtp(t);if(t.kind===`activating`)return this.renderLinkedDeviceActivation(t);if(t.kind===`expired`)return this.renderLinkDeviceFailurePanel({dismiss:`expired`,title:`Linking expired`,detail:t.message,action:`Try again`});if(t.kind===`cancelled`)return this.renderLinkDeviceFailurePanel({dismiss:`cancelled`,title:`Linking cancelled`,detail:t.message,action:`Return to unlock wallet`});if(t.kind===`error`||t.kind===`activation_error`)return this.renderLinkDeviceFailure(t);let n=t.kind===`ready`;return h(m,{children:h(`div`,{class:`seams-scan-device-content`,children:h(`div`,{class:`qr-code-container`,children:h(`div`,{class:`qr-body`,children:h(`div`,{class:`qr-code-section`,children:[h(`div`,{class:`qr-code-display`,children:n?h(m,{children:h(`img`,{src:t.qrCodeDataURL,alt:`QR code to link this device`,class:`qr-code-image`})}):h(m,{children:h(`div`,{class:`qr-code-placeholder`,children:h(`span`,{class:`seams-spinner`,"aria-hidden":`true`})})})}),h(`div`,{class:`qr-header`,children:h(`h2`,{class:`qr-title`,id:O,children:e.heading})}),h(`div`,{class:`qr-instruction`,children:n?e.subtitle:`Preparing a one-time code for your other device.`}),h(`div`,{class:`qr-status`,role:`status`,"aria-live":`polite`,children:[n?t.message:`Generating QR code`,h(`span`,{class:`animated-ellipsis`})]})]})})})})})}renderLinkDeviceFactorSelection(e){let t=e.targetFactor.kind===`email_otp`,n=e.targetFactor.kind===`email_otp`&&typeof e.targetEmail==`string`?e.targetEmail:``,r=!t||me(n);return h(m,{children:h(`div`,{class:`seams-link-device-confirmation`,children:[h(`h2`,{class:`qr-title`,id:O,children:`Match your other device`}),h(`p`,{class:`seams-link-device-confirmation-copy`,children:`Choose the unlock method for Device 2. Email code sends a one-time code to the address you enter.`}),h(`fieldset`,{class:`seams-link-device-factor-options`,children:[h(`legend`,{class:`sr-only`,children:`Wallet unlock method`}),h(`label`,{children:[h(`span`,{class:`seams-auth-method-choice-icon`,children:w()}),h(`span`,{class:`seams-auth-method-choice-label`,children:`Passkey`}),h(`input`,{type:`radio`,name:`linked-device-factor`,value:`passkey_prf`,checked:e.targetFactor.kind===`passkey_prf`,onChange:this.onLinkDeviceFactorChange})]}),h(`label`,{children:[h(`span`,{class:`seams-auth-method-choice-icon`,children:ot()}),h(`span`,{class:`seams-auth-method-choice-label`,children:`Email code`}),h(`input`,{type:`radio`,name:`linked-device-factor`,value:`email_otp`,checked:e.targetFactor.kind===`email_otp`,onChange:this.onLinkDeviceFactorChange})]})]}),t?h(m,{children:h(`label`,{class:`seams-link-device-target-email`,children:[h(`span`,{class:`seams-field-label`,children:`Email address`}),h(`input`,{type:`email`,name:`linked-device-target-email`,autocomplete:`email`,value:n,"aria-label":`Email address`,"aria-invalid":n.length>0&&!r?`true`:`false`,onInput:this.onLinkDeviceTargetEmailInput})]})}):null,e.error?h(m,{children:h(`p`,{class:`seams-link-device-inline-error`,role:`alert`,children:e.error})}):null,h(`button`,{class:`seams-link-device-btn seams-link-device-btn-primary`,type:`button`,"data-auth-menu-primary":!0,disabled:!r,onClick:this.onLinkDeviceStart,children:`Continue`})]})})}renderLinkDeviceEmailOtp(e){let t=e.state,n=yt(t),r=t.kind===`sending`||t.kind===`submitting`||t.kind===`resending`,i=e.otpCode.length===6&&(t.kind===`code_input`||t.kind===`incorrect`),a=t.kind!==`completed`&&t.kind!==`expired`&&t.kind!==`unavailable`,o=`maskedEmailHint`in t?t.maskedEmailHint:``,s=A(e.otpCode);return h(m,{children:h(`div`,{class:`seams-link-device-confirmation seams-link-device-email-otp`,"data-tone":n.tone,"data-otp-phase":t.kind,children:[vt(n.ring,ot()),h(`h2`,{class:`qr-title`,id:O,children:n.heading}),o?h(m,{children:h(`div`,{class:`seams-link-device-email-chip`,title:o,children:h(`span`,{children:o})})}):null,h(`p`,{class:`seams-link-device-email-status`,id:`seams-linked-device-otp-status`,role:`status`,"aria-live":`polite`,children:[n.status,n.pending?h(m,{children:h(`span`,{class:`animated-ellipsis`,"aria-hidden":`true`})}):null]}),a?h(m,{children:[h(`label`,{class:`sr-only`,for:`seams-linked-device-email-otp`,children:`Email code`}),h(`div`,{class:`seams-otp-code-field`,"data-disabled":r?`true`:`false`,children:[h(`input`,{class:`seams-otp-input`,id:`seams-linked-device-email-otp`,"data-auth-menu-input":!0,type:`text`,inputmode:`numeric`,autocomplete:`one-time-code`,pattern:`[0-9]*`,maxLength:6,"aria-label":`Email verification code`,"aria-describedby":`seams-linked-device-otp-status`,"aria-invalid":t.kind===`incorrect`?`true`:`false`,value:e.otpCode,disabled:r,onInput:this.onLinkDeviceEmailOtpCodeInput,onKeyDown:this.onLinkDeviceEmailOtpKeydown}),h(`div`,{class:`seams-otp-slots`,"aria-hidden":`true`,children:s.map(j)})]})]}):null,this.renderLinkDeviceEmailOtpActions(t,{busy:r,canSubmit:i})]})})}renderLinkDeviceEmailOtpActions(e,t){return e.kind===`completed`?null:e.kind===`unavailable`?h(m,{children:h(`button`,{class:`seams-link-device-btn`,type:`button`,"data-link-device-error-dismiss":!0,onClick:this.onBackClick,children:`Return to unlock wallet`})}):e.kind===`expired`?h(m,{children:h(`button`,{class:`seams-link-device-btn seams-link-device-btn-primary`,type:`button`,onClick:this.onLinkDeviceEmailOtpResend,children:`Send a new code`})}):h(m,{children:[h(`button`,{class:`seams-link-device-btn seams-link-device-btn-primary`,type:`button`,disabled:!t.canSubmit,onClick:this.onLinkDeviceEmailOtpSubmit,children:e.kind===`submitting`?`Verifying`:`Verify code`}),h(`button`,{class:`seams-otp-resend`,type:`button`,disabled:t.busy,onClick:this.onLinkDeviceEmailOtpResend,children:`Send another code`})]})}renderLinkDeviceFailure(e){let t=e.kind===`activation_error`;return this.renderLinkDeviceFailurePanel({dismiss:`error`,title:t?`Device linked`:`Couldn't link device`,detail:t?h(m,{children:[`Unable to open the wallet. Go back and try again. `,e.message]}):e.message,action:`Return to unlock wallet`})}renderLinkDeviceFailurePanel(e){return h(m,{children:h(`div`,{class:`seams-link-device-confirmation seams-link-device-failure`,children:[h(`div`,{class:`seams-link-device-failure-icon`,children:st()}),h(`h2`,{class:`qr-title`,id:O,children:e.title}),h(`p`,{class:`seams-link-device-failure-detail`,role:`alert`,children:e.detail}),h(`button`,{class:`seams-link-device-btn`,type:`button`,"data-auth-menu-primary":!0,[`data-link-device-${e.dismiss}-dismiss`]:!0,onClick:this.onBackClick,children:e.action})]})})}renderLinkedDeviceActivation(e){return h(m,{children:h(`div`,{class:`seams-link-device-confirmation`,children:[h(`span`,{class:`seams-spinner`,"aria-hidden":`true`}),h(`h2`,{class:`qr-title`,id:O,children:`Opening linked wallet`}),h(`p`,{class:`seams-link-device-confirmation-copy`,role:`status`,"aria-live":`polite`,children:e.message})]})})}renderLinkDevicePasskeyConfirmation(e){let t=e.kind===`creating_passkey`;return h(m,{children:h(`div`,{class:`seams-link-device-confirmation`,children:[vt(t?`waiting`:`approved`),h(`h2`,{class:`qr-title`,id:O,"aria-live":`polite`,children:e.message}),h(`button`,{class:`seams-link-device-btn seams-link-device-btn-primary`,type:`button`,"data-auth-menu-primary":!0,"data-link-device-passkey-action":!0,disabled:t,onClick:this.onLinkDeviceCreatePasskey,children:t?`Waiting for passkey`:`Create passkey`})]})})}renderGoogleOtp(e){let t=e.delivery.status===`reused`?`Use the code already sent to ${e.emailHint}.`:`A 6-digit code was sent to ${e.emailHint}.`,n=A(e.otpCode);return h(m,{children:h(`div`,{class:`seams-otp-prompt`,"aria-live":`polite`,children:[h(`div`,{class:`seams-otp-prompt-copy`,children:[h(`div`,{class:`seams-otp-title`,id:O,children:e.heading}),h(`p`,{class:`seams-otp-description`,children:t}),D(e.delivery),h(`div`,{class:`seams-otp-account`,title:e.walletId,children:[h(`span`,{class:`seams-otp-account-label`,children:`Wallet`}),h(`span`,{class:`seams-otp-account-value`,children:e.walletId})]})]}),h(`label`,{class:`seams-field-label`,for:`seams-auth-menu-google-otp`,children:`Email code`}),h(`div`,{class:`seams-otp-code-field`,"data-disabled":e.submitBusy?`true`:`false`,children:[h(`input`,{class:`seams-otp-input`,id:`seams-auth-menu-google-otp`,"data-auth-menu-input":!0,"data-email-otp-challenge-id":e.challengeId,"data-email-otp-wallet-id":e.walletId,type:`text`,inputmode:`numeric`,autocomplete:`one-time-code`,pattern:`[0-9]*`,maxLength:6,value:e.otpCode,disabled:e.submitBusy,onInput:this.onGoogleOtpCodeInput,onKeyDown:this.onGoogleOtpKeydown}),h(`div`,{class:`seams-otp-slots`,"aria-hidden":`true`,children:n.map(j)})]}),h(`p`,{class:`seams-otp-helper`,children:e.prompt.helperText??``}),h(`button`,{class:`seams-auth-method-btn seams-auth-method-btn-primary`,type:`button`,"data-auth-menu-primary":!0,disabled:!x(e),onClick:this.onPrimaryClick,children:e.submitBusy?`Unlocking…`:e.ctaLabel}),h(`button`,{class:`seams-otp-resend auth-menu-google-resend`,type:`button`,disabled:e.resendBusy||e.submitBusy,onClick:this.onGoogleOtpResend,children:e.resendBusy?`Sending…`:`Resend Code`})]})})}renderGoogleRegistration(e){return h(m,{children:h(`div`,{class:`seams-otp-prompt`,"aria-live":`polite`,children:[h(`div`,{class:`seams-otp-prompt-copy`,children:[h(`div`,{class:`seams-otp-title`,id:O,children:e.heading}),h(`p`,{class:`seams-otp-description`,children:e.subtitle}),h(`div`,{class:`seams-otp-account`,title:e.walletId,children:[h(`span`,{class:`seams-otp-account-label`,children:`Wallet`}),h(`span`,{class:`seams-otp-account-value`,children:e.walletId})]}),h(`button`,{class:`seams-otp-reroll`,type:`button`,disabled:e.rerollBusy||e.submitBusy,onClick:this.onGoogleRegistrationReroll,children:e.rerollBusy?`Generating…`:`Generate another name`})]}),h(`button`,{class:`seams-auth-method-btn seams-auth-method-btn-primary`,type:`button`,"data-auth-menu-primary":!0,disabled:!x(e),onClick:this.onPrimaryClick,children:e.submitBusy?`Creating...`:e.ctaLabel})]})})}};const P=new WeakMap;let Tt=0;function Et(e){let t=P.get(e);return t||(t=Fe({doc:e,baseCss:``,dynamicStyleDataAttr:`data-seams-auth-menu-dynamic`,nonce:Ne}),P.set(e,t)),t}var Dt=class{constructor(e){this.cancel=()=>{this.state.kind===`mounted`&&this.state.onIntent({kind:`close`,reason:`close_button`})};let t=e.parent.ownerDocument;this.styles=Et(t),this.element=t.createElement(`div`),this.element.className=`seams-wallet-ui seams-auth-menu-surface`,this.element.id=`seams-auth-menu-${++Tt}`,this.state={kind:`mounted`,onIntent:e.onIntent},this.element.addEventListener(`cancel`,this.cancel),e.parent.appendChild(this.element);try{this.update(e.viewModel)}catch(e){throw this.dispose(),e}}update(e){this.state.kind!==`disposed`&&(this.element.dataset.theme=e.appearance.theme.mode,this.styles.setDynamicRule(this.element.id+`-appearance`,Ie(this.element.id,e.appearance)),Pe(h(wt,{element:this.element,viewModel:e,onIntent:this.state.onIntent,styles:this.styles}),this.element))}dispose(){this.state.kind!==`disposed`&&(this.state={kind:`disposed`},this.element.removeEventListener(`cancel`,this.cancel),Pe(null,this.element),this.styles.deleteDynamicRule(this.element.id+`-appearance`),this.element.remove())}};function Ot(e){return new Dt(e)}const F=Symbol(`hostedPasskeyLoginPrepared`),kt=Symbol(`hostedPasskeyAccountSyncPrepared`),I=300*1e3;function L(e){return{signingEngine:e.signingEngine,nearClient:e.nearClient,configs:e.configs,theme:e.theme,resumePendingAcknowledgementsV1:e.resumePendingAcknowledgementsV1}}const R=new WeakMap;function At(e){return e.signal}function z(e){if(At(e).aborted)throw Error(`Hosted auth-menu passkey preparation was cancelled`)}function jt(e){if(Date.now()>=e.expiresAtMs)throw W(e),Error(`Hosted auth-menu passkey preparation expired`)}function B(e){let t=R.get(e);if(!t)throw Error(`Hosted auth-menu passkey preparation is unknown`);if(t.lifecycle!==`ready`)throw Error(`Hosted auth-menu passkey preparation is no longer usable`);if(Date.now()>=e.expiresAtMs)throw W(e),Error(`Hosted auth-menu passkey preparation expired`);return z(e.cancellation),t}function Mt(e){return{id:String(e.credentialId||``).trim(),type:`public-key`,transports:Array.isArray(e.transports)?e.transports:[]}}function V(e){return{authMenuSessionId:e.authMenuSessionId,requestId:e.requestId}}async function H(e){z(e.cancellation);let t=Te(e.walletId),n=await se(String(t));if(n){z(e.cancellation);let r=Object.freeze({kind:`hosted_passkey_linked_authority_login_prepared_v1`,...V(e),walletId:t,selection:n,expiresAtMs:Date.now()+I,cancellation:e.cancellation,[F]:!0});return R.set(r,{context:e.context,loginOptions:{},syncOptions:{},lifecycle:`ready`,authority:null}),r}let r=await ge({walletId:String(t),requestedCapabilityFamilies:{kind:`all_registered_mpc`}}),i=r.kind===`resolved`?r.subjectSet:await oe(String(t));if(!i)return await U({context:e.context,walletId:null,authMenuSessionId:e.authMenuSessionId,requestId:e.requestId,cancellation:e.cancellation});z(e.cancellation);let a=Object.freeze({kind:`hosted_passkey_owner_login_prepared_v1`,...V(e),walletId:t,subjectSet:i,expiresAtMs:Date.now()+I,cancellation:e.cancellation,[F]:!0});return R.set(a,{context:e.context,loginOptions:{},syncOptions:{},lifecycle:`ready`,authority:null}),a}async function U(e){z(e.cancellation);let t=await ue(e.context,e.walletId);z(e.cancellation);let n=Object.freeze({kind:`hosted_passkey_account_sync_prepared_v1`,authMenuSessionId:e.authMenuSessionId,requestId:e.requestId,challenge:t,expiresAtMs:Date.now()+I,cancellation:e.cancellation,[kt]:!0});return R.set(n,{context:e.context,loginOptions:{},syncOptions:{},lifecycle:`ready`,authority:null}),n}function Nt(e){let t=B(e);t.lifecycle=`consuming`;let n={subjectId:e.challenge.walletId||`account-sync`,challengeB64u:e.challenge.syncOptions.challengeB64u,allowCredentials:e.challenge.syncOptions.credentialIds.map(e=>Mt({credentialId:e}))},r;try{r=t.context.signingEngine.getAuthenticationCredentialsSerialized({...n,includeSecondPrfOutput:!1})}catch(e){throw t.lifecycle=`cancelled`,e}return t.authority=r,r.then(()=>{t.lifecycle===`consuming`&&(t.lifecycle=`consumed`)},()=>{t.lifecycle===`consuming`&&(t.lifecycle=`cancelled`)}),r}function Pt(e){let t=R.get(e);if(!t)throw Error(`Hosted auth-menu passkey preparation is unknown`);if(t.lifecycle!==`consuming`&&t.lifecycle!==`consumed`||!t.authority)throw Error(`Hosted auth-menu passkey credential must be started by its CTA`);return t.lifecycle=`completing`,t}async function Ft(e){let t=B(e);t.lifecycle=`completing`;let n=!1,r=e=>{e.phase===Oe.CANCELLED&&(n=!0)};try{let i=t.loginOptions.onEvent,a={...t.loginOptions,onEvent:e=>{r(e),i?.(e)}},o=e.kind===`hosted_passkey_linked_authority_login_prepared_v1`?await te(t.context,String(e.walletId),a):await pe(t.context,e.subjectSet,a);return o.success?t.context.resumePendingAcknowledgementsV1():u(),{result:o,cancelledByUser:n}}finally{t.lifecycle=`finished`}}async function It(e){let t=Pt(e),n=t.authority;if(!n)throw Error(`Hosted auth-menu passkey credential is missing`);try{let r=await n;return jt(e),z(e.cancellation),await ie(t.context,e.challenge,r,t.syncOptions)}finally{t.lifecycle=`finished`}}function W(e){let t=R.get(e);!t||t.lifecycle===`finished`||t.lifecycle===`cancelled`||(t.lifecycle=`cancelled`)}function G(e){if(e.kind===`hosted_passkey_registration_prepared_v1`){be(e);return}W(e)}function K(){}function Lt(e){return e.target.kind===`passkey`}function Rt(e){return e.kind===`recovery`&&e.stage===`finalizing`&&(e.operation.kind===`hosted_recovery_credential_created`||e.operation.kind===`hosted_recovery_email_otp_verified`)}function zt(e){return e.targetFactor.kind===`email_otp`?{targetFactor:e.targetFactor,targetEmail:ee(e.targetEmail)}:{targetFactor:e.targetFactor}}const Bt={kind:`recoverable`,reason:`error`,message:`Google sign-in was cancelled.`};function q(e){let t=e.mode??e.request.initialMode,n=e.request.copy[t],r={kind:`passkey`,appearance:e.appearance,hostname:e.hostname,closeLabel:e.request.copy.common.closeLabel,heading:n.title,subtitle:n.subtitle,ctaLabel:n.passkeyCta,showProgress:e.request.showProgress,enabledExternalProviders:e.request.enabledExternalProviders,status:{kind:`idle`,interaction:`arming`}};return t===`register`?{...r,mode:t,showRegistrationInput:e.request.showRegistrationInput||e.request.registrationAccountInput===`sponsored_named_near_account`,passkeyNameReadOnly:e.request.registrationAccountInput===`implicit_wallet`,passkeyName:e.request.registrationAccountInput===`implicit_wallet`?String(Ee()):``,passkeyNameLabel:e.request.copy.register.passkeyNameLabel}:{...r,mode:t,accountOptions:[],selectedAccount:null}}function Vt(e){let t=q({...e,mode:`login`});if(t.kind!==`passkey`||t.mode!==`login`)throw Error(`login view model construction failed`);return t}async function Ht(e){let[t]=await Promise.allSettled([e,new Promise(e=>setTimeout(e,500))]);if(t.status===`rejected`)throw t.reason;return t.value}function Ut(e){return e.trim()||`Wallet`}function Wt(e){return`close_button`}function J(){try{let e=globalThis.crypto?.randomUUID?.();if(e)return`auth-menu-external-${e}`}catch{}return`auth-menu-external-${Date.now()}-${Math.random().toString(36).slice(2)}`}function Gt(e){return{appearance:e.base.appearance,hostname:e.base.hostname,closeLabel:e.base.closeLabel,heading:e.flow.prompt.title,subtitle:e.flow.prompt.description,ctaLabel:e.flow.prompt.submitLabel,showProgress:e.base.showProgress,enabledExternalProviders:e.base.enabledExternalProviders,status:e.status}}function Kt(e){let t=`google-email-otp-login:${e.flow.walletId}:`;if(!e.flow.flowId.startsWith(t))throw Error(`Google Email OTP login flow identity is invalid`);return{...Gt({base:e.base,flow:e.flow,status:e.status??{kind:`idle`,interaction:`actionable`}}),kind:`google_otp_login`,mode:`login`,emailHint:e.flow.emailHint,walletId:String(e.flow.walletId),challengeId:e.flow.flowId.slice(t.length),prompt:e.flow.prompt,delivery:e.flow.delivery,otpCode:e.otpCode??``,resendBusy:e.resendBusy??!1,submitBusy:e.submitBusy??!1,...e.error?{error:e.error}:{}}}function qt(e){return{...Gt({base:e.base,flow:e.flow,status:e.status??{kind:`idle`,interaction:`actionable`}}),kind:`google_registration`,mode:`register`,emailHint:e.flow.emailHint,walletId:String(e.flow.walletId),prompt:e.flow.prompt,rerollBusy:e.rerollBusy??!1,submitBusy:e.submitBusy??!1,...e.error?{error:e.error}:{}}}function Y(e){return e instanceof Error&&e.message.trim()?e.message.trim():String(e)}function Jt(e){switch(e.kind){case`passkey`:return e.status.kind===`recoverable`?{mode:e.mode,message:e.status.detail??e.status.message}:null;case`google_otp_login`:case`google_registration`:return e.error?{mode:e.mode,message:e.error}:e.status.kind===`recoverable`?{mode:e.mode,message:e.status.message}:null;case`link_device`:return null;case`recovery`:return e.stage===`sign_in_ready`&&e.status.kind===`recoverable`?{mode:`login`,message:e.status.detail??e.status.message}:null;default:{let t=e;throw Error(`Unknown auth-menu view model: ${JSON.stringify(t)}`)}}}function Yt(e){return{kind:`link_device`,appearance:e.appearance,hostname:e.hostname,closeLabel:e.closeLabel,heading:`Scan and link device`,subtitle:`Scan this code with your other device.`,ctaLabel:``,showProgress:e.showProgress,enabledExternalProviders:e.enabledExternalProviders,status:{kind:`idle`,interaction:`actionable`},mode:e.mode,linkDevice:{kind:`select_factor`,targetFactor:{kind:`passkey_prf`}}}}function X(e){let t={kind:`recovery`,mode:`login`,appearance:e.base.appearance,hostname:e.base.hostname,closeLabel:e.base.closeLabel,heading:`Recover wallet`,subtitle:e.stage===`sign_in_ready`?e.target.kind===`google_email_otp`?`Your Google account is ready to unlock your wallet.`:`Your wallet is ready. Unlock it with your passkey.`:`Enter a recovery code to recover your wallet.`,ctaLabel:e.stage===`passkey_ready`?`Create new passkey`:e.stage===`google_ready`?`Continue with Google`:e.stage===`email_code_required`?`Verify email code`:e.stage===`sign_in_ready`?e.target.kind===`google_email_otp`?`Unlock with Google`:`Unlock with new passkey`:e.stage===`preparing`?e.target.kind===`google_email_otp`?`Recover with Google`:`Recover with Passkey`:`Continue`,showProgress:e.base.showProgress,enabledExternalProviders:e.base.enabledExternalProviders,recoveryCode:e.recoveryCode??``,recoveryCodeError:e.recoveryCodeError??null};switch(e.stage){case void 0:case`enter_code`:return{...t,stage:`enter_code`,status:e.status??{kind:`idle`,interaction:`actionable`}};case`preparing`:return{...t,stage:e.stage,target:e.target,status:e.status};case`passkey_ready`:return{...t,target:e.target,walletId:e.walletId,stage:e.stage,status:e.status??{kind:`idle`,interaction:`actionable`}};case`google_ready`:return{...t,target:e.target,walletId:e.walletId,stage:e.stage,status:e.status??{kind:`idle`,interaction:`actionable`}};case`email_code_required`:return{...t,target:e.target,walletId:e.walletId,stage:e.stage,challengeId:e.challengeId,emailHint:e.emailHint,delivery:e.delivery,otpCode:e.otpCode??``,status:e.status??{kind:`idle`,interaction:`awaiting_input`}};case`finalizing`:return{...t,target:e.target,walletId:e.walletId,stage:e.stage,status:e.status};case`sign_in_ready`:return{...t,target:e.target,walletId:e.walletId,stage:e.stage,status:e.status??{kind:`idle`,interaction:`actionable`}}}}function Z(e){if(e.stage===`enter_code`||e.stage===`preparing`)throw Error(`recovery wallet id is unavailable before preparation`);return e.walletId}function Q(e){if(e.stage===`enter_code`)throw Error(`recovery target is unavailable before preparation`);return e.target}function $(e){return e.kind===`dismissed`?{kind:`idle`,interaction:`actionable`}:{kind:`recoverable`,reason:`error`,message:e.kind===`consumed`?`That recovery code has already been used. Use another code.`:`That recovery code can’t be used. Check the code and try again.`}}function Xt(){return{kind:`recoverable`,reason:`error`,message:`Recovery couldn’t be completed. Try again.`}}function Zt(e){return e.kind===`dismissed`?{kind:`idle`,interaction:`actionable`}:{kind:`recoverable`,reason:`error`,message:`A passkey couldn’t be created. Try again.`}}var Qt=class{constructor(e){this.surface=null,this.outcomeResolver=null,this.outcomePromise=null,this.cleanedUp=!1,this.prepared=null,this.preparePasskey=null,this.registrationPreparation=null,this.preparationCancellation=null,this.googleCancellation=null,this.loginPreparation=null,this.loginAccountOptions=[],this.selectedLoginAccount=null,this.modeSelectionSource=`initial`,this.measurementReporter=null,this.preparationGeneration=0,this.googleGeneration=0,this.deviceLinkGeneration=0,this.linkedDeviceActivationInProgress=!1,this.targetPasskeyActivation=null,this.targetEmailOtpActivation=null,this.linkedDeviceEmailOtpSendStarted=!1,this.linkedDeviceTargetFactor={kind:`passkey_prf`},this.linkedDeviceTargetEmailAddress=``,this.preparationDeadlineTimer=null,this.preparationExpiryTimer=null,this.lastReportedError=null,this.recoveryGeneration=0,this.recoveryCancellation=null,this.recoveryLoginPrepared=null,this.recoveryReturnState=null,this.prepareSelectedLogin=e=>{if(!this.loginPreparation)throw Error(`Hosted login preparation is unavailable`);let t=v(this.loginAccountOptions,this.selectedLoginAccount);if(!y(t))throw Error(`Email OTP accounts require Google sign-in`);return this.loginPreparation(t.kind===`discoverable`?null:t.walletId,e)},this.postSurfaceMeasurement=e=>{this.sendToParent({type:`SURFACE_MEASUREMENT`,payload:e})},this.onIntent=e=>{switch(e.kind){case`mode_selected`:this.selectMode(e.mode);return;case`back`:this.back();return;case`link_device_open`:this.openLinkDevice();return;case`recovery_open`:this.openRecovery();return;case`recovery_code_changed`:this.changeRecoveryCode(e.recoveryCode);return;case`recovery_passkey_selected`:this.prepareRecovery(`passkey`);return;case`recovery_google_selected`:this.prepareRecovery(`google_email_otp`);return;case`recovery_google_otp_code_changed`:this.changeRecoveryGoogleOtpCode(e.code);return;case`recovery_google_otp_submit`:this.submitRecoveryGoogleOtp();return;case`recovery_create_passkey`:this.createRecoveryPasskey();return;case`recovery_sign_in`:this.signInRecoveredWallet();return;case`link_device_factor_selected`:this.selectLinkedDeviceTargetFactor(e.targetFactor);return;case`link_device_target_email_changed`:this.changeLinkedDeviceTargetEmailAddress(e.emailAddress);return;case`link_device_start`:this.startSelectedDeviceLinking();return;case`link_device_create_passkey`:this.createLinkedDevicePasskey();return;case`link_device_email_otp_code_changed`:this.changeLinkedDeviceEmailOtpCode(e.code);return;case`link_device_email_otp_resend`:this.resendLinkedDeviceEmailOtp();return;case`link_device_email_otp_submit`:this.submitLinkedDeviceEmailOtp();return;case`registration_reroll`:this.rerollRegistrationWallet();return;case`close`:this.cancel(Wt(e));return;case`passkey_name_changed`:{let t=this.stateValue.kind===`preparing`||this.stateValue.kind===`ready`?this.stateValue.viewModel:null;t?.kind===`passkey`&&t.mode===`register`&&!t.passkeyNameReadOnly&&(this.invalidatePreparation(),this.stateValue={kind:`preparing`,viewModel:{...t,passkeyName:e.passkeyName,status:{kind:`idle`,interaction:`arming`}}},this.updateElement(),this.startPasskeyPreparation());return}case`login_account_selected`:this.selectLoginAccount(e.walletId,e.authMethod);return;case`submit`:if(this.stateValue.kind===`preparing`&&this.stateValue.viewModel.status.kind===`recoverable`){this.retryPreparation();return}this.stateValue.kind===`ready`&&this.prepared===this.stateValue.prepared&&(e.mode===`register`&&this.stateValue.prepared.kind===`hosted_passkey_registration_prepared_v1`||e.mode===`login`&&(this.stateValue.prepared.kind===`hosted_passkey_owner_login_prepared_v1`||this.stateValue.prepared.kind===`hosted_passkey_linked_authority_login_prepared_v1`||this.stateValue.prepared.kind===`hosted_passkey_account_sync_prepared_v1`))&&this.performPreparedPasskey(this.stateValue.prepared);return;case`external_auth`:this.requestExternalAuth(e.provider);return;case`google_otp_code_changed`:this.updateGoogleOtpCode(e.code);return;case`google_otp_resend`:this.resendGoogleOtp();return;case`google_otp_submit`:this.submitGoogleOtp();return;case`google_registration_reroll`:this.rerollGoogleRegistration();return;case`google_registration_complete`:this.completeGoogleRegistration();return;case`retry`:this.retryPreparation();return;default:return $t(e)}},this.identity={authMenuSessionId:e.request.authMenuSessionId,requestId:e.requestId},this.request=e.request,this.beginGoogleEmailOtp=e.beginGoogleEmailOtp,this.startDeviceLinking=e.startDeviceLinking,this.cancelDeviceLinking=e.cancelDeviceLinking,this.recoveryPort=e.recoveryPort,this.prepareRecoveredLogin=e.prepareRecoveredLogin,this.sendToParent=e.sendToParent,this.stateValue={kind:`preparing`,viewModel:q({request:e.request,appearance:e.appearance,hostname:Ut(e.hostname)})}}get state(){return this.stateValue}setRegistrationPreparation(e){this.registrationPreparation=e,this.stateValue.kind!==`complete`&&this.currentViewModel().mode===`register`&&(this.preparePasskey=null,this.startPasskeyPreparation())}setPasskeyPreparation(e){this.preparePasskey=e,this.startPasskeyPreparation()}setLoginPreparation(e){let t=this.stateValue.kind===`complete`?null:this.currentViewModel();t?.kind===`passkey`&&t.mode===`login`&&(this.stateValue.kind===`preparing`||this.stateValue.kind===`ready`)&&this.invalidatePreparation(),this.loginPreparation=e.prepare,this.loginAccountOptions=e.accountOptions,this.selectedLoginAccount=e.selectedAccount,this.updateLoginSelectionViewModel(),(this.stateValue.kind===`preparing`||this.stateValue.kind===`ready`)&&this.currentViewModel().mode===`login`&&this.activateSelectedLoginMethod()}defaultToLoginForDetectedLocalWallet(){if(this.modeSelectionSource!==`initial`||this.stateValue.kind===`complete`)return;let e=this.currentViewModel();e.kind!==`passkey`||e.mode!==`register`||this.showPasskeyMode(`login`)}activateSelectedLoginMethod(){if(y(v(this.loginAccountOptions,this.selectedLoginAccount))){this.setPasskeyPreparation(this.prepareSelectedLogin);return}this.preparePasskey=null;let e=this.stateValue;e.kind!==`preparing`&&e.kind!==`ready`||e.viewModel.kind!==`passkey`||e.viewModel.mode!==`login`||(this.stateValue={kind:`preparing`,viewModel:{...e.viewModel,status:{kind:`idle`,interaction:`actionable`}}},this.updateElement())}updateLoginSelectionViewModel(){let e=this.stateValue;e.kind!==`preparing`&&e.kind!==`ready`||e.viewModel.kind!==`passkey`||e.viewModel.mode!==`login`||(this.stateValue={...e,viewModel:{...e.viewModel,accountOptions:this.loginAccountOptions,selectedAccount:this.selectedLoginAccount}})}mount(){if(this.surface||this.cleanedUp)throw Error(`Hosted auth-menu session is already mounted`);if(document.querySelectorAll(`.seams-auth-menu-surface`).length>0)throw Error(`A hosted auth-menu surface is already mounted`);let e=document.body||document.documentElement;if(!e)throw Error(`Wallet host document has no mount root`);this.surface=Ot({parent:e,viewModel:this.currentViewModel(),onIntent:this.onIntent}),this.measurementReporter=Me({kind:`auth_menu_surface`,element:this.surface.element,requestId:this.identity.requestId,authMenuSessionId:this.identity.authMenuSessionId,postMeasurement:this.postSurfaceMeasurement})}waitForOutcome(){return this.stateValue.kind===`complete`?Promise.resolve(this.stateValue.outcome):(this.outcomePromise||=new Promise(e=>{this.outcomeResolver=e}),this.outcomePromise)}cancel(e){if(Rt(this.stateValue)){if(e===`close_button`)return;this.complete({kind:`cancelled`,authMenuSessionId:this.identity.authMenuSessionId,reason:e});return}this.stateValue.kind===`link_device`&&console.error(`[Device2Linking] auth menu cancelled`,{reason:e}),this.invalidatePreparation(),this.complete({kind:`cancelled`,authMenuSessionId:this.identity.authMenuSessionId,reason:e})}startPasskeyPreparation(){if(this.stateValue.kind===`complete`)return;let e=this.currentViewModel();if(e.kind!==`passkey`)return;let t=e.mode===`register`?this.registrationPreparation:null,n=e.mode===`login`?this.preparePasskey:null;if(!n&&!t)return;if(t&&e.mode===`register`&&e.showRegistrationInput&&e.passkeyName.trim().length===0){this.invalidatePreparation(),this.stateValue={kind:`preparing`,viewModel:{...e,status:{kind:`idle`,interaction:`awaiting_input`}}},this.updateElement();return}this.clearPreparationExpiryTimer();let r=++this.preparationGeneration,i=new AbortController;this.preparationCancellation=i;let a={kind:`abort_signal`,signal:i.signal};this.stateValue={kind:`preparing`,viewModel:{...e,status:{kind:`idle`,interaction:`arming`}}},this.updateElement(),this.schedulePreparationDeadline(r,i),Promise.resolve().then(()=>t?t(this.registrationValue(),a):n(a)).then(t=>{if(r!==this.preparationGeneration||this.stateValue.kind===`complete`){G(t);return}this.clearPreparationDeadlineTimer(),this.prepared=t,this.stateValue={kind:`ready`,prepared:t,viewModel:{...e,status:{kind:`idle`,interaction:`actionable`}}},this.schedulePreparationExpiry(t),this.updateElement()},t=>{r!==this.preparationGeneration||this.stateValue.kind===`complete`||(this.clearPreparationDeadlineTimer(),this.stateValue={kind:`preparing`,viewModel:{...e,status:_(Y(t))}},this.updateElement())})}invalidatePreparation(){this.invalidateRecovery(),this.stateValue.kind===`link_device`&&(this.deviceLinkGeneration+=1,this.cancelDeviceLinking().catch(()=>{})),this.clearPreparationDeadlineTimer(),this.clearPreparationExpiryTimer(),this.preparationGeneration+=1,this.preparationCancellation?.abort(),this.preparationCancellation=null,this.googleGeneration+=1,this.googleCancellation?.abort(),this.googleCancellation=null;let e=this.prepared;this.prepared=null,e&&G(e),this.stateValue.kind===`performing`&&G(this.stateValue.prepared),(this.stateValue.kind===`google_login`||this.stateValue.kind===`google_registration`)&&this.stateValue.flow.cancel().catch(()=>{})}invalidateRecovery(){this.recoveryGeneration+=1,this.recoveryCancellation?.abort(),this.recoveryCancellation=null;let e=this.recoveryLoginPrepared;this.recoveryLoginPrepared=null,e&&G(e);let t=this.stateValue;t.kind!==`recovery`||!t.operation||Rt(t)||this.recoveryPort.cancel(t.operation).catch(()=>{})}registrationValue(){let e=this.stateValue;return(e.kind===`preparing`||e.kind===`ready`)&&e.viewModel.kind===`passkey`&&e.viewModel.mode===`register`?e.viewModel.passkeyName:``}clearPreparationExpiryTimer(){this.preparationExpiryTimer!==null&&(clearTimeout(this.preparationExpiryTimer),this.preparationExpiryTimer=null)}clearPreparationDeadlineTimer(){this.preparationDeadlineTimer!==null&&(clearTimeout(this.preparationDeadlineTimer),this.preparationDeadlineTimer=null)}schedulePreparationDeadline(e,t){this.clearPreparationDeadlineTimer(),this.preparationDeadlineTimer=setTimeout(this.expirePasskeyPreparation.bind(this,e,t),2e4)}expirePasskeyPreparation(e,t){let n=this.stateValue;e!==this.preparationGeneration||t!==this.preparationCancellation||n.kind!==`preparing`||n.viewModel.kind!==`passkey`||n.viewModel.status.kind!==`idle`||n.viewModel.status.interaction!==`arming`||(this.clearPreparationDeadlineTimer(),this.preparationGeneration+=1,this.preparationCancellation=null,t.abort(),this.stateValue={kind:`preparing`,viewModel:{...n.viewModel,status:_(`Passkey preparation timed out`)}},this.updateElement())}schedulePreparationExpiry(e){this.clearPreparationExpiryTimer();let t=Math.max(0,e.expiresAtMs-Date.now());this.preparationExpiryTimer=setTimeout(()=>{this.preparationExpiryTimer=null,!(this.stateValue.kind!==`ready`||this.stateValue.prepared!==e||this.prepared!==e||this.stateValue.viewModel.kind!==`passkey`)&&(G(e),this.prepared=null,this.stateValue={kind:`preparing`,viewModel:{...this.stateValue.viewModel,status:{kind:`recoverable`,reason:`expired`,message:`Passkey preparation expired. Retry to continue.`}}},this.updateElement())},t)}startGoogleFlow(e,t){this.invalidatePreparation();let n=++this.googleGeneration,r=new AbortController;this.googleCancellation=r;let i=this.currentViewModel();i.kind===`recovery`||i.kind===`link_device`||(this.stateValue={kind:`preparing`,viewModel:{...i,status:{kind:`busy`,headline:`Waiting for Google SSO authentication…`,detail:`Starting Google sign-in`}}},this.updateElement(),this.beginGoogleEmailOtp({idToken:e,authTarget:t,signal:r.signal}).then(e=>{if(n!==this.googleGeneration||r.signal.aborted||this.stateValue.kind===`complete`){e.cancel().catch(()=>{});return}this.googleCancellation=null,e.mode===`login`?this.stateValue={kind:`google_login`,flow:e,viewModel:Kt({base:i,flow:e})}:this.stateValue={kind:`google_registration`,flow:e,viewModel:qt({base:i,flow:e})},this.updateElement()},e=>{n!==this.googleGeneration||r.signal.aborted||this.stateValue.kind===`complete`||(this.googleCancellation=null,this.stateValue={kind:`preparing`,viewModel:{...i,status:_(Y(e))}},this.updateElement())}))}requestExternalAuth(e){if(this.stateValue.kind===`complete`)return null;if(this.stateValue.kind===`recovery`&&this.stateValue.stage===`google_ready`)return this.requestRecoveryGoogleVerification(e,this.stateValue);if(this.stateValue.kind===`recovery`&&this.stateValue.stage===`sign_in_ready`&&this.stateValue.viewModel.target.kind===`google_email_otp`)return this.requestRecoveredGoogleSignIn(e,this.stateValue);let t=this.currentViewModel();if(t.kind!==`passkey`||!this.request.enabledExternalProviders.includes(e)||this.stateValue.kind===`awaiting_external_auth`)return null;let n;if(t.mode===`register`)n={mode:`register`};else{let e=v(t.accountOptions,t.selectedAccount);if(!Ze(e))return null;n={mode:`login`,loginTarget:e.loginTarget}}this.invalidatePreparation();let r=o(J());if(!r)return null;let i={kind:`hosted_auth_menu_external_auth_request_v1`,authMenuSessionId:this.identity.authMenuSessionId,externalAuthRequestId:r,provider:e,mode:t.mode};return this.stateValue={kind:`awaiting_external_auth`,viewModel:{...t,status:{kind:`busy`,headline:`Waiting for Google SSO authentication…`,detail:`Waiting for Google sign-in`}},request:i,authTarget:n},this.updateElement(),this.sendToParent({type:`AUTH_MENU_EXTERNAL_AUTH_REQUEST`,requestId:this.identity.requestId,payload:i}),i}acceptExternalAuthResolution(e){let t=this.stateValue;if(t.kind===`recovery`&&t.stage===`google_external_auth`){if(t.request.authMenuSessionId!==e.authMenuSessionId||t.request.externalAuthRequestId!==e.externalAuthRequestId||this.identity.requestId!==e.requestId)return!1;if(e.evidence.kind===`google_id_token`)return this.startRecoveryGoogleVerification(t,e.evidence.idToken),!0;let n=e.evidence.kind===`cancelled`?Bt:_(e.evidence.message);return this.stateValue={kind:`recovery`,stage:`google_ready`,operation:t.operation,returnState:t.returnState,viewModel:X({base:t.viewModel,walletId:Z(t.viewModel),stage:`google_ready`,target:t.operation.target,status:n})},this.updateElement(),!0}if(t.kind!==`awaiting_external_auth`||t.viewModel.kind!==`passkey`||t.request.authMenuSessionId!==e.authMenuSessionId||t.request.externalAuthRequestId!==e.externalAuthRequestId||this.identity.requestId!==e.requestId)return!1;switch(e.evidence.kind){case`google_id_token`:return this.startGoogleFlow(e.evidence.idToken,t.authTarget),!0;case`cancelled`:case`failed`:{let n=e.evidence.kind===`cancelled`?Bt:_(e.evidence.message);return this.stateValue={kind:`preparing`,viewModel:{...t.viewModel,status:n}},this.updateElement(),!0}default:return rn(e.evidence)}}requestRecoveryGoogleVerification(e,t){if(!this.request.enabledExternalProviders.includes(e))return null;let n=o(J());if(!n)return null;let r={kind:`hosted_auth_menu_external_auth_request_v1`,authMenuSessionId:this.identity.authMenuSessionId,externalAuthRequestId:n,provider:e,mode:`login`};return this.stateValue={kind:`recovery`,stage:`google_external_auth`,operation:t.operation,returnState:t.returnState,request:r,viewModel:X({base:t.viewModel,walletId:Z(t.viewModel),stage:`finalizing`,target:t.operation.target,status:{kind:`busy`,headline:`Waiting for Google SSO authentication…`,detail:`Waiting for Google sign-in`}})},this.updateElement(),this.sendToParent({type:`AUTH_MENU_EXTERNAL_AUTH_REQUEST`,requestId:this.identity.requestId,payload:r}),r}requestRecoveredGoogleSignIn(e,t){if(!this.request.enabledExternalProviders.includes(e))return null;let n=o(J());if(!n)return null;let r={kind:`hosted_auth_menu_external_auth_request_v1`,authMenuSessionId:this.identity.authMenuSessionId,externalAuthRequestId:n,provider:e,mode:`login`};return this.stateValue={kind:`awaiting_external_auth`,request:r,authTarget:{mode:`login`,loginTarget:{kind:`wallet`,walletId:Z(t.viewModel)}},viewModel:{...Vt({request:this.request,appearance:t.viewModel.appearance,hostname:t.viewModel.hostname}),status:{kind:`busy`,headline:`Waiting for Google SSO authentication…`,detail:`Waiting for Google sign-in`}}},this.updateElement(),this.sendToParent({type:`AUTH_MENU_EXTERNAL_AUTH_REQUEST`,requestId:this.identity.requestId,payload:r}),r}cleanup(){this.cleanedUp||(this.cleanedUp=!0,this.invalidatePreparation(),this.measurementReporter?.disconnect(),this.measurementReporter=null,this.surface?.dispose(),this.surface=null)}currentViewModel(){switch(this.stateValue.kind){case`preparing`:case`awaiting_external_auth`:case`ready`:case`performing`:return this.stateValue.viewModel;case`google_login`:case`google_registration`:case`link_device`:case`recovery`:return this.stateValue.viewModel;case`complete`:throw Error(`Completed auth-menu session has no view model`)}}updateElement(){let e=this.currentViewModel();this.reportPresentedError(e),this.surface?.update(e)}reportPresentedError(e){let t=Jt(e);if(!t){this.lastReportedError=null;return}let n=`${t.mode}:${t.message}`;if(n===this.lastReportedError)return;this.lastReportedError=n;let r=s({kind:`hosted_auth_menu_error_v1`,authMenuSessionId:this.identity.authMenuSessionId,mode:t.mode,message:t.message});if(!r)throw Error(`Unable to emit hosted auth-menu error event`);this.sendToParent({type:`AUTH_MENU_ERROR`,requestId:this.identity.requestId,payload:r})}selectMode(e){let t=this.stateValue;t.kind===`complete`||t.kind===`performing`||t.kind===`link_device`||(this.modeSelectionSource=`user`,this.currentViewModel().mode!==e&&this.showPasskeyMode(e))}showPasskeyMode(e){if(this.stateValue.kind===`complete`||this.stateValue.kind===`link_device`)return;let t=this.currentViewModel();this.invalidatePreparation();let n=q({request:{...this.request,initialMode:e},appearance:t.appearance,hostname:t.hostname,mode:e});this.stateValue={kind:`preparing`,viewModel:n.kind===`passkey`&&n.mode===`login`?{...n,accountOptions:this.loginAccountOptions,selectedAccount:this.selectedLoginAccount}:n},this.updateElement(),e===`login`?this.activateSelectedLoginMethod():(this.preparePasskey=null,this.startPasskeyPreparation())}back(){if(this.stateValue.kind===`recovery`){if(this.stateValue.stage===`finalizing`)return;this.closeRecovery();return}if(this.stateValue.kind===`link_device`){this.closeLinkDevice();return}(this.stateValue.kind===`performing`||this.stateValue.kind===`awaiting_external_auth`||this.stateValue.kind===`google_login`||this.stateValue.kind===`google_registration`)&&this.showPasskeyMode(this.stateValue.viewModel.mode)}openRecovery(){let e=this.stateValue;if(e.kind!==`preparing`&&e.kind!==`ready`||e.viewModel.kind!==`passkey`)return;let t={kind:`preparing`,viewModel:{...e.viewModel,status:{kind:`idle`,interaction:`arming`}}};this.invalidatePreparation(),this.recoveryReturnState=t,this.stateValue={kind:`recovery`,stage:`enter_code`,returnState:t,viewModel:X({base:e.viewModel})},this.updateElement()}closeRecovery(){let e=this.stateValue;if(e.kind!==`recovery`)return;let t=e.returnState;this.invalidateRecovery(),this.recoveryReturnState=null,this.stateValue=t,this.updateElement(),this.preparePasskey=t.viewModel.mode===`login`?this.prepareSelectedLogin:null,this.startPasskeyPreparation()}changeRecoveryCode(e){let t=this.stateValue;t.kind!==`recovery`||t.stage!==`enter_code`||(this.stateValue={...t,viewModel:{...t.viewModel,recoveryCode:e,recoveryCodeError:null}},this.updateElement())}prepareRecovery(e=`passkey`){let t=this.stateValue;if(t.kind!==`recovery`||t.stage!==`enter_code`)return;let n=t.viewModel.recoveryCode.trim();if(!n){this.stateValue={...t,viewModel:{...t.viewModel,recoveryCodeError:`Enter a recovery code.`}},this.updateElement();return}let r;try{r=this.recoveryPort.targetFor(e)}catch{this.stateValue={...t,viewModel:X({base:t.viewModel,recoveryCode:t.viewModel.recoveryCode,status:$({kind:`refused`})})},this.updateElement();return}let i=++this.recoveryGeneration,a=new AbortController;this.recoveryCancellation=a,this.stateValue={...t,stage:`preparing`,viewModel:X({base:t.viewModel,recoveryCode:t.viewModel.recoveryCode,stage:`preparing`,target:r,status:{kind:`busy`,headline:`Checking recovery code…`}})},this.updateElement();let o;try{o=this.recoveryPort.prepare({recoveryCode:n,target:r,signal:a.signal})}catch{this.rejectRecoveryPreparation(i);return}o.then(this.completeRecoveryPreparation.bind(this,i),this.rejectRecoveryPreparation.bind(this,i))}completeRecoveryPreparation(e,t){let n=this.stateValue;if(e!==this.recoveryGeneration||n.kind!==`recovery`){t.kind===`hosted_recovery_prepared`&&this.recoveryPort.cancel(t).catch(K);return}if(this.recoveryCancellation=null,t.kind!==`hosted_recovery_prepared`){this.stateValue={kind:`recovery`,stage:`enter_code`,returnState:n.returnState,viewModel:X({base:n.viewModel,recoveryCode:n.viewModel.recoveryCode,status:$(t)})},this.updateElement();return}if(Lt(t)){this.stateValue={kind:`recovery`,stage:`passkey_ready`,operation:t,returnState:n.returnState,viewModel:X({base:n.viewModel,walletId:String(t.walletId),recoveryCode:``,stage:`passkey_ready`,target:t.target})},this.createRecoveryPasskey();return}let r={kind:`recovery`,stage:`google_ready`,operation:t,returnState:n.returnState,viewModel:X({base:n.viewModel,walletId:String(t.walletId),recoveryCode:``,stage:`google_ready`,target:t.target})};this.stateValue=r,this.requestRecoveryGoogleVerification(`google`,r)||(this.stateValue={...r,viewModel:X({base:r.viewModel,walletId:Z(r.viewModel),stage:`google_ready`,target:r.operation.target,status:{kind:`recoverable`,reason:`error`,message:`Google sign-in is unavailable. Try again.`}})},this.updateElement())}rejectRecoveryPreparation(e){let t=this.stateValue;e!==this.recoveryGeneration||t.kind!==`recovery`||(this.recoveryCancellation=null,this.stateValue={kind:`recovery`,stage:`enter_code`,returnState:t.returnState,viewModel:X({base:t.viewModel,recoveryCode:t.viewModel.recoveryCode,status:$({kind:`transport_uncertain`})})},this.updateElement())}startRecoveryGoogleVerification(e,t){let n=++this.recoveryGeneration;this.recoveryPort.verifyGoogle(e.operation,t).then(this.completeRecoveryGoogleVerification.bind(this,n),this.rejectRecoveryGoogleVerification.bind(this,n))}completeRecoveryGoogleVerification(e,t){let n=this.stateValue;if(e!==this.recoveryGeneration||n.kind!==`recovery`||n.stage!==`google_external_auth`){t.kind===`hosted_recovery_google_verified`&&this.recoveryPort.cancel(t).catch(K);return}if(t.kind!==`hosted_recovery_google_verified`){this.showRecoveryGoogleVerificationFailure(n,t);return}this.stateValue={kind:`recovery`,stage:`email_code_required`,operation:t,returnState:n.returnState,viewModel:X({base:n.viewModel,walletId:String(t.walletId),stage:`email_code_required`,target:t.target,challengeId:t.challengeId,emailHint:t.delivery.emailHint,delivery:t.delivery})},this.updateElement()}rejectRecoveryGoogleVerification(e){let t=this.stateValue;e!==this.recoveryGeneration||t.kind!==`recovery`||t.stage!==`google_external_auth`||this.showRecoveryGoogleVerificationFailure(t,{kind:`transport_uncertain`})}showRecoveryGoogleVerificationFailure(e,t){this.stateValue={kind:`recovery`,stage:`google_ready`,operation:e.operation,returnState:e.returnState,viewModel:X({base:e.viewModel,walletId:Z(e.viewModel),stage:`google_ready`,target:e.operation.target,status:$(t)})},this.updateElement()}changeRecoveryGoogleOtpCode(e){let t=this.stateValue;if(t.kind!==`recovery`||t.stage!==`email_code_required`)return;let n=e.replace(/\D/g,``).slice(0,6);this.stateValue={...t,viewModel:X({base:t.viewModel,walletId:Z(t.viewModel),stage:`email_code_required`,target:t.operation.target,challengeId:t.operation.challengeId,emailHint:t.operation.delivery.emailHint,delivery:t.operation.delivery,otpCode:n})},this.updateElement(),/^\d{6}$/.test(n)&&this.submitRecoveryGoogleOtp()}submitRecoveryGoogleOtp(){let e=this.stateValue;if(e.kind===`recovery`&&e.stage===`finalizing`&&e.operation.kind===`hosted_recovery_email_otp_verified`&&e.viewModel.status.kind===`recoverable`){this.finishRecovery(e.operation);return}if(e.kind!==`recovery`||e.stage!==`email_code_required`)return;let t=e.viewModel.otpCode.trim();if(!/^\d{6}$/.test(t))return;let n=++this.recoveryGeneration;this.stateValue={...e,viewModel:X({base:e.viewModel,walletId:Z(e.viewModel),stage:`email_code_required`,target:e.operation.target,challengeId:e.operation.challengeId,emailHint:e.operation.delivery.emailHint,delivery:e.operation.delivery,otpCode:t,status:{kind:`busy`,headline:`Verifying email code…`}})},this.updateElement(),this.recoveryPort.verifyEmailOtp(e.operation,{challengeId:e.operation.challengeId,otpCode:t}).then(this.completeRecoveryEmailOtpVerification.bind(this,n),this.rejectRecoveryEmailOtpVerification.bind(this,n))}completeRecoveryEmailOtpVerification(e,t){let n=this.stateValue;if(e!==this.recoveryGeneration||n.kind!==`recovery`||n.stage!==`email_code_required`){t.kind===`hosted_recovery_email_otp_verified`&&this.recoveryPort.cancel(t).catch(K);return}if(t.kind!==`hosted_recovery_email_otp_verified`){this.showRecoveryEmailOtpFailure(n,t);return}this.finishRecovery(t)}rejectRecoveryEmailOtpVerification(e){let t=this.stateValue;e!==this.recoveryGeneration||t.kind!==`recovery`||t.stage!==`email_code_required`||this.showRecoveryEmailOtpFailure(t,{kind:`transport_uncertain`})}showRecoveryEmailOtpFailure(e,t){this.stateValue={...e,viewModel:X({base:e.viewModel,walletId:Z(e.viewModel),stage:`email_code_required`,target:e.operation.target,challengeId:e.operation.challengeId,emailHint:e.operation.delivery.emailHint,delivery:e.operation.delivery,otpCode:e.viewModel.otpCode,status:$(t)})},this.updateElement()}createRecoveryPasskey(){let e=this.stateValue;if(e.kind!==`recovery`)return;if(e.stage===`finalizing`&&e.operation.kind===`hosted_recovery_credential_created`&&e.viewModel.status.kind===`recoverable`){this.finishRecovery(e.operation);return}if(e.stage!==`passkey_ready`)return;let t=++this.recoveryGeneration,n;try{n=this.recoveryPort.createPasskey(e.operation)}catch{this.showRecoveryCreateFailure(e,{kind:`refused`});return}this.stateValue={...e,stage:`finalizing`,viewModel:X({base:e.viewModel,walletId:Z(e.viewModel),stage:`finalizing`,target:Q(e.viewModel),status:{kind:`busy`,headline:`Creating new passkey…`}})},this.updateElement(),n.then(this.completeRecoveryCredentialCreation.bind(this,t),this.rejectRecoveryCredentialCreation.bind(this,t))}completeRecoveryCredentialCreation(e,t){let n=this.stateValue;if(e!==this.recoveryGeneration||n.kind!==`recovery`||n.stage!==`finalizing`||n.operation.kind!==`hosted_recovery_prepared`){t.kind===`hosted_recovery_credential_created`&&this.recoveryPort.cancel(t).catch(K);return}if(t.kind!==`hosted_recovery_credential_created`){this.showRecoveryCreateFailure({returnState:n.returnState,viewModel:n.viewModel,operation:n.operation},t);return}this.finishRecovery(t)}rejectRecoveryCredentialCreation(e){let t=this.stateValue;e!==this.recoveryGeneration||t.kind!==`recovery`||t.stage!==`finalizing`||t.operation.kind!==`hosted_recovery_prepared`||this.showRecoveryCreateFailure({returnState:t.returnState,viewModel:t.viewModel,operation:t.operation},{kind:`refused`})}showRecoveryCreateFailure(e,t){if(!Lt(e.operation)){this.recoveryPort.cancel(e.operation).catch(K),this.stateValue={kind:`recovery`,stage:`enter_code`,returnState:e.returnState,viewModel:X({base:e.viewModel,recoveryCode:``,status:$(t)})},this.updateElement();return}if(t.kind===`refused`){this.recoveryPort.cancel(e.operation).catch(K),this.stateValue={kind:`recovery`,stage:`enter_code`,returnState:e.returnState,viewModel:X({base:e.viewModel,recoveryCode:``,status:$(t)})},this.updateElement();return}this.stateValue={kind:`recovery`,stage:`passkey_ready`,operation:e.operation,returnState:e.returnState,viewModel:X({base:e.viewModel,walletId:Z(e.viewModel),stage:`passkey_ready`,target:e.operation.target,status:Zt(t)})},this.updateElement()}finishRecovery(e){let t=this.stateValue;if(t.kind!==`recovery`)return;let n=++this.recoveryGeneration;this.stateValue={kind:`recovery`,stage:`finalizing`,operation:e,returnState:t.returnState,viewModel:X({base:t.viewModel,walletId:Z(t.viewModel),stage:`finalizing`,target:Q(t.viewModel),status:{kind:`busy`,headline:`Finishing recovery…`}})},this.updateElement();let r;try{r=this.recoveryPort.finalize(e)}catch{this.rejectRecoveryFinalization(n);return}r.then(this.completeRecoveryFinalization.bind(this,n),this.rejectRecoveryFinalization.bind(this,n))}completeRecoveryFinalization(e,t){let n=this.stateValue;if(!(e!==this.recoveryGeneration||n.kind!==`recovery`||n.stage!==`finalizing`||n.operation.kind!==`hosted_recovery_credential_created`&&n.operation.kind!==`hosted_recovery_email_otp_verified`)){if(t.kind!==`ready_for_sign_in`){t.kind===`refused`?(this.recoveryPort.cancel(n.operation).catch(()=>{}),this.stateValue={kind:`recovery`,stage:`enter_code`,returnState:n.returnState,viewModel:X({base:n.viewModel,status:$(t)})}):this.stateValue={...n,viewModel:X({base:n.viewModel,walletId:Z(n.viewModel),stage:`finalizing`,target:Q(n.viewModel),status:Xt()})},this.updateElement();return}if(n.operation.target.kind===`passkey`){this.prepareRecoveredPasskeyLogin(t.walletId,n.returnState);return}this.stateValue={kind:`recovery`,stage:`sign_in_ready`,returnState:n.returnState,viewModel:X({base:n.viewModel,walletId:String(t.walletId),stage:`sign_in_ready`,target:n.operation.target})},this.updateElement()}}rejectRecoveryFinalization(e){let t=this.stateValue;e!==this.recoveryGeneration||t.kind!==`recovery`||t.stage!==`finalizing`||t.operation.kind!==`hosted_recovery_credential_created`&&t.operation.kind!==`hosted_recovery_email_otp_verified`||(this.stateValue={...t,viewModel:X({base:t.viewModel,walletId:Z(t.viewModel),stage:`finalizing`,target:Q(t.viewModel),status:Xt()})},this.updateElement())}prepareRecoveredPasskeyLogin(e,t){let n=this.stateValue;if(n.kind!==`recovery`)return;let r=++this.recoveryGeneration,i=new AbortController;this.recoveryCancellation=i;let a=this.prepareRecoveredLogin(e,{kind:`abort_signal`,signal:i.signal});this.stateValue={kind:`recovery`,stage:`sign_in_ready`,returnState:t,viewModel:X({base:n.viewModel,walletId:String(e),stage:`sign_in_ready`,target:Q(n.viewModel),status:{kind:`busy`,headline:`Preparing to unlock…`}})},this.updateElement(),a.then(this.completeRecoveredLoginPreparation.bind(this,r,t),this.rejectRecoveredLoginPreparation.bind(this,r,e,t))}completeRecoveredLoginPreparation(t,n,r){let i=this.stateValue;if(t!==this.recoveryGeneration||i.kind!==`recovery`){G(r);return}if(this.recoveryCancellation=null,r.kind!==`hosted_passkey_owner_login_prepared_v1`&&r.kind!==`hosted_passkey_linked_authority_login_prepared_v1`){G(r);let a=e(Z(i.viewModel));if(!a.ok)return;this.rejectRecoveredLoginPreparation(t,a.value,n);return}this.recoveryLoginPrepared=r,this.stateValue={kind:`recovery`,stage:`sign_in_ready`,returnState:n,viewModel:X({base:i.viewModel,walletId:Z(i.viewModel),stage:`sign_in_ready`,target:Q(i.viewModel)})},this.updateElement()}rejectRecoveredLoginPreparation(e,t,n){let r=this.stateValue;e!==this.recoveryGeneration||r.kind!==`recovery`||(this.recoveryCancellation=null,this.stateValue={kind:`recovery`,stage:`sign_in_ready`,returnState:n,viewModel:X({base:r.viewModel,walletId:String(t),stage:`sign_in_ready`,target:Q(r.viewModel),status:{kind:`recoverable`,reason:`error`,message:`Your wallet was recovered. Unlock it again to continue.`}})},this.updateElement())}signInRecoveredWallet(){let t=this.stateValue;if(t.kind!==`recovery`||t.stage!==`sign_in_ready`)return;if(t.viewModel.target.kind===`google_email_otp`){this.requestExternalAuth(`google`);return}let n=this.recoveryLoginPrepared;if(!n){let n=e(Z(t.viewModel));if(!n.ok)return;this.prepareRecoveredPasskeyLogin(n.value,t.returnState);return}this.recoveryLoginPrepared=null,this.performPreparedPasskey(n)}openLinkDevice(){let e=this.stateValue;if(e.kind!==`preparing`&&e.kind!==`ready`||e.viewModel.kind!==`passkey`)return;let t={kind:`preparing`,viewModel:{...e.viewModel,status:{kind:`idle`,interaction:`arming`}}};this.invalidatePreparation(),this.linkedDeviceActivationInProgress=!1,this.targetPasskeyActivation=null,this.targetEmailOtpActivation=null,this.linkedDeviceEmailOtpSendStarted=!1,this.linkedDeviceTargetFactor={kind:`passkey_prf`},this.linkedDeviceTargetEmailAddress=``,this.stateValue={kind:`link_device`,returnState:t,viewModel:Yt(e.viewModel)},this.updateElement()}selectLinkedDeviceTargetFactor(e){let t=this.stateValue;t.kind!==`link_device`||t.viewModel.linkDevice.kind!==`select_factor`||(this.linkedDeviceTargetFactor=e,this.stateValue={...t,viewModel:{...t.viewModel,linkDevice:e.kind===`email_otp`?{kind:`select_factor`,targetFactor:e,targetEmail:this.linkedDeviceTargetEmailAddress}:{kind:`select_factor`,targetFactor:e}}},this.updateElement())}changeLinkedDeviceTargetEmailAddress(e){let t=this.stateValue;t.kind!==`link_device`||t.viewModel.linkDevice.kind!==`select_factor`||t.viewModel.linkDevice.targetFactor.kind!==`email_otp`||(this.linkedDeviceTargetEmailAddress=e,this.stateValue={...t,viewModel:{...t.viewModel,linkDevice:{kind:`select_factor`,targetFactor:t.viewModel.linkDevice.targetFactor,targetEmail:e}}},this.updateElement())}startSelectedDeviceLinking(){let e=this.stateValue;if(e.kind!==`link_device`||e.viewModel.linkDevice.kind!==`select_factor`)return;let t=e.viewModel.linkDevice,n;try{if(t.targetFactor.kind===`email_otp`){let e=t.targetEmail;if(typeof e!=`string`)throw Error(`linked-device target email address is unavailable`);n=zt({targetFactor:t.targetFactor,targetEmail:e})}else n=zt({targetFactor:t.targetFactor})}catch(t){this.stateValue={...e,viewModel:{...e.viewModel,linkDevice:{...e.viewModel.linkDevice,error:Y(t)}}},this.updateElement();return}let r=++this.deviceLinkGeneration;this.stateValue={...e,viewModel:{...e.viewModel,linkDevice:{kind:`loading`,message:`Generating QR code...`}}},this.updateElement(),this.startDeviceLinking(n,{onEvent:this.onLinkDeviceEvent.bind(this,r),onTargetFactorRequired:this.onTargetFactorRequired.bind(this,r)}).then(this.completeLinkDeviceOpen.bind(this,r)).catch(this.failLinkDeviceOpen.bind(this,r))}onLinkDeviceEvent(e,t){let n=this.stateValue;if(e!==this.deviceLinkGeneration||n.kind!==`link_device`)return;let r=De(t);switch(r.kind){case`active`:if(this.linkedDeviceActivationInProgress)return;this.linkedDeviceActivationInProgress=!0,this.complete({kind:`authenticated`,authMenuSessionId:this.identity.authMenuSessionId,walletId:r.walletId,method:this.linkedDeviceTargetFactor.kind===`email_otp`?`google_email_otp`:`passkey`});return;case`invalid_active`:this.showLinkedDeviceActivationError(n,Error(`Linked-device activation omitted its wallet identity`));return;case`failed`:if(t.error?.code===c.SESSION_EXPIRED){this.stateValue={...n,viewModel:{...n.viewModel,linkDevice:{kind:`expired`,message:`This linking request expired. Start again to link this device.`}}},this.updateElement();return}if(t.error?.code===c.DELIVERY_RECOVERY_REQUIRED){this.showLinkedDeviceActivationError(n,Error(t.message||`Go back and unlock the new linked method to finish setup.`));return}break;case`cancelled`:this.targetPasskeyActivation=null,this.targetEmailOtpActivation=null,this.linkedDeviceEmailOtpSendStarted=!1,this.stateValue={...n,viewModel:{...n.viewModel,linkDevice:{kind:`cancelled`,message:`The other device cancelled this linking request. Go back to try again.`}}},this.updateElement();return;case`pending`:break;default:return en(r)}let i=t.message?.trim();if(!i)return;let a=n.viewModel.linkDevice,o=a.kind===`email_otp_required`?a:a.kind===`ready`||a.kind===`passkey_required`||a.kind===`creating_passkey`?{...a,message:i}:{kind:`loading`,message:i};this.stateValue={...n,viewModel:{...n.viewModel,linkDevice:o}},this.updateElement()}showLinkedDeviceActivationError(e,t){this.stateValue={...e,viewModel:{...e.viewModel,linkDevice:{kind:`activation_error`,message:Y(t)}}},this.updateElement()}completeLinkDeviceOpen(e,t){let n=this.stateValue;e!==this.deviceLinkGeneration||n.kind!==`link_device`||this.linkedDeviceActivationInProgress||n.viewModel.linkDevice.kind!==`loading`||(this.stateValue={...n,viewModel:{...n.viewModel,linkDevice:this.targetPasskeyActivation?{kind:`passkey_required`,message:`Create a passkey to finish linking this device`}:{kind:`ready`,qrCodeDataURL:t.qrCodeDataURL,message:`Waiting for device to scan`}}},this.updateElement())}onTargetFactorRequired(e,t){switch(t.kind){case`linked_device_target_passkey_activation_v1`:this.onTargetPasskeyActivation(e,t);return;case`linked_device_target_email_otp_activation_v1`:this.onTargetEmailOtpActivation(e,t);return;default:return tn(t)}}onTargetPasskeyActivation(e,t){let n=this.stateValue;e!==this.deviceLinkGeneration||n.kind!==`link_device`||(this.targetPasskeyActivation=t,n.viewModel.linkDevice.kind===`ready`&&(this.stateValue={...n,viewModel:{...n.viewModel,linkDevice:{kind:`passkey_required`,message:`Create a passkey to finish linking this device`}}},this.updateElement()))}onTargetEmailOtpActivation(e,t){let n=this.stateValue;e!==this.deviceLinkGeneration||n.kind!==`link_device`||(this.targetEmailOtpActivation=t,this.stateValue={...n,viewModel:{...n.viewModel,linkDevice:{kind:`email_otp_required`,state:t.state,otpCode:n.viewModel.linkDevice.kind===`email_otp_required`?n.viewModel.linkDevice.otpCode:``}}},this.updateElement(),t.state.kind===`sending`&&!this.linkedDeviceEmailOtpSendStarted&&(this.linkedDeviceEmailOtpSendStarted=!0,t.sendCode().catch(this.failLinkedDeviceEmailOtp.bind(this))))}changeLinkedDeviceEmailOtpCode(e){let t=this.stateValue;if(t.kind!==`link_device`||t.viewModel.linkDevice.kind!==`email_otp_required`)return;let n=e.replace(/\D/g,``).slice(0,6),r=t.viewModel.linkDevice.otpCode,i=t.viewModel.linkDevice.state;this.stateValue={...t,viewModel:{...t.viewModel,linkDevice:{...t.viewModel.linkDevice,otpCode:n}}},this.updateElement(),n.length===6&&n!==r&&(i.kind===`code_input`||i.kind===`incorrect`)&&this.submitLinkedDeviceEmailOtpCode(n)}resendLinkedDeviceEmailOtp(){let e=this.targetEmailOtpActivation;e&&e.resendCode().catch(this.failLinkedDeviceEmailOtp.bind(this))}submitLinkedDeviceEmailOtp(){let e=this.stateValue;e.kind!==`link_device`||e.viewModel.linkDevice.kind!==`email_otp_required`||e.viewModel.linkDevice.otpCode.length!==6||this.submitLinkedDeviceEmailOtpCode(e.viewModel.linkDevice.otpCode)}submitLinkedDeviceEmailOtpCode(e){let t=this.targetEmailOtpActivation;t&&t.submitCode(e).catch(this.failLinkedDeviceEmailOtp.bind(this))}failLinkedDeviceEmailOtp(e){let t=this.stateValue;t.kind===`link_device`&&this.showLinkedDeviceActivationError(t,e)}createLinkedDevicePasskey(){let e=this.stateValue,t=this.targetPasskeyActivation;!t||e.kind!==`link_device`||e.viewModel.linkDevice.kind!==`passkey_required`||(this.targetPasskeyActivation=null,this.stateValue={...e,viewModel:{...e.viewModel,linkDevice:{kind:`creating_passkey`,message:`Follow the passkey prompt on your screen`}}},this.updateElement(),t.createPasskey().catch(this.failTargetPasskeyCreation.bind(this)))}failTargetPasskeyCreation(e){let t=this.stateValue;t.kind===`link_device`&&(this.stateValue={...t,viewModel:{...t.viewModel,linkDevice:{kind:`error`,message:Y(e)}}},this.updateElement())}failLinkDeviceOpen(e,t){let n=this.stateValue;e!==this.deviceLinkGeneration||n.kind!==`link_device`||this.linkedDeviceActivationInProgress||n.viewModel.linkDevice.kind!==`loading`||(this.stateValue={...n,viewModel:{...n.viewModel,linkDevice:{kind:`error`,message:Y(t)}}},this.updateElement())}closeLinkDevice(){let e=this.stateValue;e.kind===`link_device`&&(this.deviceLinkGeneration+=1,this.targetPasskeyActivation=null,this.targetEmailOtpActivation=null,this.linkedDeviceEmailOtpSendStarted=!1,this.cancelDeviceLinking().catch(()=>{}),this.stateValue=e.returnState,this.updateElement(),this.startPasskeyPreparation())}rerollRegistrationWallet(){let e=this.stateValue;e.kind!==`ready`&&e.kind!==`preparing`||e.viewModel.kind!==`passkey`||e.viewModel.mode!==`register`||!e.viewModel.passkeyNameReadOnly||!e.viewModel.showRegistrationInput||(this.invalidatePreparation(),this.stateValue={kind:`preparing`,viewModel:{...e.viewModel,passkeyName:String(Ee()),status:{kind:`idle`,interaction:`arming`}}},this.updateElement(),this.startPasskeyPreparation())}selectLoginAccount(e,t){let n=this.loginAccountOptions.find(n=>n.walletId===e&&n.authMethod===t);if(!n||n.walletId===this.selectedLoginAccount?.walletId&&n.authMethod===this.selectedLoginAccount.authMethod)return;let r=this.stateValue;if(r.kind!==`preparing`&&r.kind!==`ready`||r.viewModel.kind!==`passkey`||r.viewModel.mode!==`login`)return;let i=n.walletId!==this.selectedLoginAccount?.walletId;if(this.selectedLoginAccount=n,!i){this.updateLoginSelectionViewModel(),this.updateElement();return}this.invalidatePreparation(),this.stateValue={kind:`preparing`,viewModel:{...r.viewModel,selectedAccount:n,status:{kind:`idle`,interaction:`arming`}}},this.updateElement(),this.activateSelectedLoginMethod()}retryPreparation(){let e=this.stateValue;e.kind!==`preparing`||e.viewModel.kind!==`passkey`||e.viewModel.status.kind!==`recoverable`||(this.invalidatePreparation(),this.stateValue={kind:`preparing`,viewModel:{...e.viewModel,status:{kind:`idle`,interaction:`arming`}}},this.updateElement(),this.startPasskeyPreparation())}updateGoogleOtpCode(e){let t=this.stateValue;if(t.kind!==`google_login`||t.viewModel.submitBusy)return;let n=e.replace(/\D/g,``).slice(0,6);this.stateValue={...t,viewModel:{...t.viewModel,otpCode:n,error:``}},this.updateElement(),/^\d{6}$/.test(n)&&this.submitGoogleOtp()}resendGoogleOtp(){let e=this.stateValue;if(e.kind!==`google_login`||e.viewModel.resendBusy)return;let t=e.flow;this.stateValue={...e,viewModel:{...e.viewModel,status:{kind:`busy`,headline:`Sending a new email code`},resendBusy:!0,error:``}},this.updateElement(),Ht(t.resend()).then(n=>{if(this.stateValue.kind!==`google_login`||this.stateValue.flow!==t){n.ok&&n.value.cancel().catch(()=>{});return}if(!n.ok){this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},resendBusy:!1,error:n.error.message}},this.updateElement();return}if(n.value.mode!==`login`){n.value.cancel().catch(()=>{}),this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},resendBusy:!1,error:`Google returned an unexpected registration flow.`}},this.updateElement();return}let r=n.value;this.stateValue={kind:`google_login`,flow:r,viewModel:Kt({base:e.viewModel,flow:r})},this.updateElement()},e=>{this.stateValue.kind!==`google_login`||this.stateValue.flow!==t||(this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},resendBusy:!1,error:Y(e)}},this.updateElement())})}submitGoogleOtp(){let e=this.stateValue;if(e.kind!==`google_login`||e.viewModel.submitBusy)return;let t=e.viewModel.otpCode;if(!/^\d{6}$/.test(t)){this.stateValue={...e,viewModel:{...e.viewModel,status:{kind:`idle`,interaction:`actionable`},error:`Enter the 6-digit code from your email.`}},this.updateElement();return}let n=e.flow;this.stateValue={...e,viewModel:{...e.viewModel,status:{kind:`busy`,headline:`Verifying your email code`},submitBusy:!0,error:``}},this.updateElement(),n.submit({otpCode:t}).then(e=>{if(!(this.stateValue.kind!==`google_login`||this.stateValue.flow!==n)){if(!e.ok){this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},submitBusy:!1,error:e.error.message}},this.updateElement();return}if(e.value.mode!==`login`){this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},submitBusy:!1,error:`Google returned an unexpected registration result.`}},this.updateElement();return}this.complete({kind:`authenticated`,authMenuSessionId:this.identity.authMenuSessionId,walletId:e.value.walletId,method:`google_email_otp`})}},e=>{this.stateValue.kind!==`google_login`||this.stateValue.flow!==n||(this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},submitBusy:!1,error:Y(e)}},this.updateElement())})}rerollGoogleRegistration(){let e=this.stateValue;if(e.kind!==`google_registration`||e.viewModel.rerollBusy)return;let t=e.flow;this.stateValue={...e,viewModel:{...e.viewModel,status:{kind:`busy`,headline:`Generating another wallet name`},rerollBusy:!0,error:``}},this.updateElement(),t.rerollWalletId().then(n=>{if(this.stateValue.kind!==`google_registration`||this.stateValue.flow!==t){n.ok&&n.value.cancel().catch(()=>{});return}if(!n.ok){this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},rerollBusy:!1,error:n.error.message}},this.updateElement();return}if(n.value.mode!==`register`){n.value.cancel().catch(()=>{}),this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},rerollBusy:!1,error:`Google returned an unexpected login flow.`}},this.updateElement();return}let r=n.value;this.stateValue={kind:`google_registration`,flow:r,viewModel:qt({base:e.viewModel,flow:r})},this.updateElement()},e=>{this.stateValue.kind!==`google_registration`||this.stateValue.flow!==t||(this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},rerollBusy:!1,error:Y(e)}},this.updateElement())})}completeGoogleRegistration(){let e=this.stateValue;if(e.kind!==`google_registration`||e.viewModel.submitBusy)return;let t=e.flow;this.stateValue={...e,viewModel:{...e.viewModel,status:{kind:`busy`,headline:`Creating your wallet`},submitBusy:!0,error:``}},this.updateElement(),t.completeRegistration().then(e=>{if(!(this.stateValue.kind!==`google_registration`||this.stateValue.flow!==t)){if(!e.ok){this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},submitBusy:!1,error:e.error.message}},this.updateElement();return}this.complete({kind:`registered`,authMenuSessionId:this.identity.authMenuSessionId,walletId:e.value.walletId,method:`google_email_otp`})}},e=>{this.stateValue.kind!==`google_registration`||this.stateValue.flow!==t||(this.stateValue={...this.stateValue,viewModel:{...this.stateValue.viewModel,status:{kind:`idle`,interaction:`actionable`},submitBusy:!1,error:Y(e)}},this.updateElement())})}complete(e){if(this.stateValue.kind===`complete`)return;this.stateValue={kind:`complete`,outcome:e},this.cleanup();let t=this.outcomeResolver;this.outcomeResolver=null,t?.(e)}performPreparedPasskey(e){this.prepared=null;let t=this.currentViewModel();if(this.stateValue={kind:`performing`,prepared:e,viewModel:t.kind===`recovery`?X({base:t,walletId:Z(t),stage:`sign_in_ready`,target:Q(t),status:{kind:`busy`,headline:Ke(`login`),detail:`Continue with your passkey`}}):{...t,status:{kind:`busy`,headline:Ke(t.mode),detail:`Continue with your passkey`}}},e.kind===`hosted_passkey_owner_login_prepared_v1`||e.kind===`hosted_passkey_linked_authority_login_prepared_v1`){this.updateElement(),this.finishPreparedPasskey(e);return}let n;try{n=this.startPreparedCredential(e)}catch(t){this.updateElement(),this.failPreparedPasskey(e,t);return}this.updateElement(),n.then(()=>this.finishPreparedPasskey(e),t=>this.failPreparedPasskey(e,t))}startPreparedCredential(e){return e.kind===`hosted_passkey_registration_prepared_v1`?Ce(e):Nt(e)}async finishPreparedPasskey(e){try{switch(e.kind){case`hosted_passkey_registration_prepared_v1`:{let t=await ye({prepared:e});this.completeRegistrationResult(t);return}case`hosted_passkey_owner_login_prepared_v1`:case`hosted_passkey_linked_authority_login_prepared_v1`:{let t=await Ft(e);this.completeLoginResult(t);return}case`hosted_passkey_account_sync_prepared_v1`:{let t=await It(e);this.completeAccountSyncResult(t);return}default:return nn(e)}}catch(t){this.failPreparedPasskey(e,t)}}completeRegistrationResult(t){if(!t.success||t.kind!==`wallet_registered`&&t.kind!==`ecdsa_wallet_registered_near_pending`){this.fail({kind:`error`,error:Error(t.success?`Hosted registration returned an unexpected result`:t.error)});return}let n=e(String(t.walletId));if(!n.ok){this.fail({kind:`error`,error:Error(`Hosted registration returned an invalid wallet id`)});return}this.complete({kind:`registered`,authMenuSessionId:this.identity.authMenuSessionId,walletId:n.value,method:`passkey`})}completeLoginResult(t){let n=t.result;if(!n.success){this.fail(t.cancelledByUser?{kind:`dismissed`}:{kind:`error`,error:Error(n.error)});return}let r=e(String(n.walletId));if(!r.ok){this.fail({kind:`error`,error:Error(`Hosted login returned an invalid wallet id`)});return}this.complete({kind:`authenticated`,authMenuSessionId:this.identity.authMenuSessionId,walletId:r.value,method:`passkey`})}completeAccountSyncResult(t){if(!t.success){this.fail({kind:`error`,error:Error(t.error)});return}let n=e(String(t.walletId));if(!n.ok){this.fail({kind:`error`,error:Error(`Hosted account sync returned an invalid wallet id`)});return}this.complete({kind:`account_synced`,authMenuSessionId:this.identity.authMenuSessionId,walletId:n.value})}failPreparedPasskey(e,t){if(this.stateValue.kind!==`performing`||this.stateValue.prepared!==e)return;if(this.preparationCancellation?.signal.aborted){this.fail({kind:`dismissed`});return}let n=t instanceof Error?t.name:``;if(n===`NotAllowedError`||n===`AbortError`){this.fail({kind:`dismissed`});return}this.fail({kind:`error`,error:t})}fail(e){if(this.stateValue.kind!==`performing`)return;let t=this.stateValue.viewModel;if(G(this.stateValue.prepared),this.prepared=null,t.kind===`recovery`){let n=this.recoveryReturnState;if(!n)return;this.recoveryLoginPrepared=null,this.stateValue={kind:`recovery`,stage:`sign_in_ready`,returnState:n,viewModel:X({base:t,walletId:Z(t),stage:`sign_in_ready`,target:Q(t),status:e.kind===`dismissed`?{kind:`idle`,interaction:`actionable`}:_(Y(e.error))})},this.updateElement();return}if(e.kind===`dismissed`){this.invalidatePreparation(),this.stateValue={kind:`preparing`,viewModel:{...t,status:{kind:`idle`,interaction:`arming`}}},this.updateElement(),this.startPasskeyPreparation();return}this.stateValue={kind:`preparing`,viewModel:{...t,status:_(Y(e.error))}},this.updateElement()}};function $t(e){throw Error(`Unhandled auth-menu intent: ${String(e)}`)}function en(e){throw Error(`Unhandled link-device flow outcome: ${String(e)}`)}function tn(e){throw Error(`Unhandled linked-device target-factor activation: ${String(e)}`)}function nn(e){throw Error(`Unhandled hosted passkey preparation: ${String(e)}`)}function rn(e){throw Error(`Unhandled hosted external-auth evidence: ${String(e)}`)}function an(e){return`${e.walletId}:${e.authMethod}`}function on(e,t){let n=String(e.walletId);switch(e.authMethod){case`passkey`:return{walletId:n,authMethod:`passkey`};case`email_otp`:return{walletId:n,authMethod:`email_otp`,emailAddress:e.emailAddress??(t?.authMethod===`email_otp`?t.emailAddress:null)}}}function sn(e,t=[]){let n=new Map;for(let t of e?.accounts??[]){if(t.authMethod!==p.passkey&&t.authMethod!==p.emailOtp)continue;let e=String(t.walletId||``).trim();if(!e)continue;let r=t.authMethod===p.passkey?{walletId:e,authMethod:`passkey`}:{walletId:e,authMethod:`email_otp`,emailAddress:null};n.set(an(r),r)}for(let e of t){let t=String(e.walletId||``).trim();if(!t)continue;let r=`${t}:${e.authMethod}`,i=on(e,n.get(r));n.set(r,i)}return[...n.values()]}function cn(e,t){let n=e?.lastUsedAccount;if(n?.authMethod===p.passkey||n?.authMethod===p.emailOtp){let e=String(n.walletId||``).trim(),r=t.find(t=>t.walletId===e&&t.authMethod===n.authMethod);if(r)return r}return t[0]??null}function ln(e){let t=e?.lastUsedAccount;return!t||t.authMethod!==p.passkey&&t.authMethod!==`linked_device`?null:String(t.walletId||``).trim()||null}async function un(e){let t=await import(`./recovery-entrypoint-Bl5GgbW9.js`),n=e();return t.createHostedRecoveryPort({context:n.getContext(),relayUrl:String(n.configs.network.relayer.url)})}var dn=class{constructor(e){this.getWalletRuntime=e,this.portPromise=null}targetFor(e){if(e===`google_email_otp`)return{kind:e,googleProvider:`google`};let n=t(this.getWalletRuntime().getContext().signingEngine.getRpId());if(!n.ok)throw Error(`wallet recovery RP ID ${n.error.message}`);return{kind:e,rpId:n.value}}async prepare(e){return await(await this.port()).prepare(e)}async createPasskey(e){return await(await this.port()).createPasskey(e)}async verifyGoogle(e,t){return await(await this.port()).verifyGoogle(e,t)}async verifyEmailOtp(e,t){return await(await this.port()).verifyEmailOtp(e,t)}async finalize(e){return await(await this.port()).finalize(e)}async cancel(e){await(await this.port()).cancel(e)}port(){return this.portPromise??=un(this.getWalletRuntime),this.portPromise}};function fn(){try{let e=document.referrer.trim();if(e){let t=new URL(e).hostname.trim();if(t)return t}}catch{}return window.location.hostname||`Wallet`}function pn(e){switch(e.kind){case`discoverable`:return null;case`wallet`:case`wallet_sync`:return String(e.walletId)}}function mn(e){window.setTimeout(e,0)}function hn(){return new Promise(mn)}var gn=class{constructor(e){this.deps=e,this.sessions=new Map,this.startDeviceLinking=async(e,t)=>await this.deps.getWalletRuntime().devices.startLinking({...e,options:t}),this.cancelDeviceLinking=async()=>await this.deps.getWalletRuntime().devices.cancelLinking()}async open(e){if(!e.requestId)throw Error(`Hosted auth-menu open request requires requestId`);let t=_e(e.requestId);if(this.sessions.has(e.request.authMenuSessionId))throw Error(`Hosted auth-menu session is already active`);let n=new Qt({request:e.request,requestId:t,appearance:this.deps.getAppearance(),hostname:fn(),beginGoogleEmailOtp:async({idToken:e,authTarget:t,signal:n})=>await this.beginGoogleEmailOtp({idToken:e,authTarget:t,signal:n}),startDeviceLinking:this.startDeviceLinking,cancelDeviceLinking:this.cancelDeviceLinking,recoveryPort:new dn(this.deps.getWalletRuntime),prepareRecoveredLogin:this.prepareRecoveredLogin.bind(this,t,e.request.authMenuSessionId),sendToParent:this.deps.send}),r=n.waitForOutcome(),i=pn(e.request.loginTarget);this.sessions.set(e.request.authMenuSessionId,n);try{return n.mount(),await hn(),n.setRegistrationPreparation((r,i)=>this.prepareRegistration(e.request,t,n.identity.authMenuSessionId,r,i)),i?await this.bootstrapLoginAccounts(n,t,e.request.loginTarget):(n.setLoginPreparation({accountOptions:[],selectedAccount:null,prepare:(r,i)=>this.prepareLogin(t,n.identity.authMenuSessionId,i,r,null,e.request.loginTarget)}),this.bootstrapLoginAccounts(n,t,e.request.loginTarget)),await r}finally{n.cleanup(),this.sessions.delete(e.request.authMenuSessionId)}}async bootstrapLoginAccounts(e,t,n){let[r,i]=await Promise.all([this.deps.getWalletRuntime().auth.getRecentUnlocks().catch(()=>null),d().catch(()=>[])]);if(e.state.kind===`complete`)return;let a=pn(n),o=sn(r,i),s=a?o.filter(e=>e.walletId===a):o,c=s.length>0||!a?s:[{walletId:a,authMethod:p.passkey}];e.setLoginPreparation({accountOptions:c,selectedAccount:a?c[0]??null:cn(r,c),prepare:(i,a)=>this.prepareLogin(t,e.identity.authMenuSessionId,a,i,r,n)}),i.length>0&&e.defaultToLoginForDetectedLocalWallet()}async prepareLogin(e,t,n,r,i,a){let o=L(this.deps.getWalletRuntime().getContext()),s=i??await this.deps.getWalletRuntime().auth.getRecentUnlocks().catch(()=>null),c=(await d().catch(()=>[])).find(e=>e.authMethod===p.passkey),l=r||ln(s)||c?.walletId||null;return a.kind===`wallet_sync`?await U({context:o,walletId:String(a.walletId),authMenuSessionId:t,requestId:e,cancellation:n}):l?await H({context:o,walletId:l,authMenuSessionId:t,requestId:e,cancellation:n}):await U({context:o,walletId:l,authMenuSessionId:t,requestId:e,cancellation:n})}async prepareRecoveredLogin(e,t,n,r){return await H({context:L(this.deps.getWalletRuntime().getContext()),walletId:String(n),authMenuSessionId:t,requestId:e,cancellation:r})}async beginGoogleEmailOtp(e){if(e.signal.aborted)throw Error(`Google sign-in was cancelled`);let t=await this.deps.getWalletRuntime().auth.startGoogleSignIn({idToken:e.idToken,...e.authTarget});if(!t.ok)throw Error(t.error.message);let n=t.value;if(e.signal.aborted)throw await n.cancel().catch(()=>{}),Error(`Google sign-in was cancelled`);return n}async prepareRegistration(e,n,r,i,a){let o=this.deps.getWalletRuntime().getContext(),s=t(String(o.signingEngine.getRpId()||``));if(!s.ok)throw Error(s.error.message);let c={kind:`provided`,walletId:Te(i)},l=xe({configs:o.configs,wallet:c,preference:e.registrationAccountInput===`sponsored_named_near_account`?{kind:`relayer_named_subaccount`}:{kind:`implicit_account`}});return await Se({context:o,wallet:c,signerSelection:ve({configs:o.configs,accountProvisioning:l,options:{}}),authMethod:{kind:`passkey`,rpId:s.value},authMenuSessionId:r,requestId:n,cancellation:a,options:{}})}cancel(e){let t=this.sessions.get(e.authMenuSessionId);return!t||t.identity.requestId!==e.requestId?!1:(t.cancel(e.reason),!0)}resolveExternalAuth(e){let t=this.sessions.get(e.authMenuSessionId);return!t||t.identity.requestId!==e.requestId?!1:t.acceptExternalAuthResolution(e)}};function _n(e,t=new gn({getWalletRuntime:e.getWalletRuntime,getAppearance:()=>e.getWalletRuntime().configs.ui.appearance,send:e.post})){return{PM_OPEN_AUTH_MENU:async n=>{let r=i(n.payload);if(!r)throw Error(`Hosted auth-menu open request is invalid`);let a=await t.open({request:r,requestId:n.requestId});(a.kind===`authenticated`||a.kind===`registered`||a.kind===`account_synced`)&&await e.publishCurrentSession(),!e.respondIfCancelled(n.requestId)&&f(e,n.requestId,a)},PM_CANCEL_AUTH_MENU:async n=>{let r=a(n.payload);if(!r)throw Error(`Hosted auth-menu cancellation is invalid`);let i=t.cancel(r);f(e,n.requestId,{cancelled:i})},PM_RESOLVE_AUTH_MENU_EXTERNAL_AUTH:async n=>{let i=r(n.payload);if(!i)throw Error(`Hosted auth-menu external-auth resolution is invalid`);let a=t.resolveExternalAuth(i);f(e,n.requestId,{accepted:a})}}}function vn(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e,n=t.options&&typeof t.options==`object`&&!Array.isArray(t.options)?t.options:null,r=n?.ecdsaKeyFactsInventory&&typeof n.ecdsaKeyFactsInventory==`object`&&!Array.isArray(n.ecdsaKeyFactsInventory)?n.ecdsaKeyFactsInventory:null,i=r?.value&&typeof r.value==`object`&&!Array.isArray(r.value)?r.value:null;if(i&&(Object.prototype.hasOwnProperty.call(i,`walletSessionToken`)||Object.prototype.hasOwnProperty.call(i,`operationCredential`)))throw Error(`wallet iframe unlock requests must not carry a Wallet Session bearer`)}function yn(e,t){let n=e.ecdsaKeyFactsInventory,{ecdsaKeyFactsInventory:r,...i}=e;if(!n)return i;if(n.mode===`webauthn`)return{...i,ecdsaKeyFactsInventory:n};let a=ae(t);if(!a)throw Error(`Hosted-wallet Wallet Session is required for opaque key-facts lookup`);return{...i,ecdsaKeyFactsInventory:{mode:`wallet_session_operation_credential_v1`,operationCredential:a}}}function bn(e,t){return String(t?.walletId||``).trim()||String(e.preferences.getCurrentWalletId()||``).trim()||void 0}function xn(e){console.warn(`[WalletIframeHost] Restored-session presignature prefill failed:`,e)}function Sn(e,t,n,r,i){e.respondIfCancelled(n)||(f(e,n,i),r.authenticationRead===`restore`&&t.prefillRestoredWalletSession(i.state).catch(xn))}function Cn(e){return{..._n(e),PM_UNLOCK:async t=>{let n=e.getWalletRuntime();vn(t.payload);let r=Ue(t.payload),i=yn(We(r),n.configs.network.relayer.url);if(e.respondIfCancelled(t.requestId))return;let a=await n.auth.unlock(r.walletId,le(e,t.requestId,i));e.respondIfCancelled(t.requestId)||(a.success||u(),await e.publishCurrentSession(),!e.respondIfCancelled(t.requestId)&&f(e,t.requestId,a))},PM_LOCK:async t=>{let n=e.getWalletRuntime();u(),await n.auth.lock(),de(e,t.requestId)},PM_LOCK_EXACT_WALLET_SESSION:async t=>{let n=e.getWalletRuntime(),r=l(t.payload),i=await re(n,{authenticationRead:`current`,wallet:{kind:`current`}},new ke);if(i.kind!==`active_session`&&i.kind!==`expired_session`||!he(i,r)){f(e,t.requestId,{kind:`stale_session`,expected:r,current:i});return}u(),await n.auth.lock(),f(e,t.requestId,{kind:`locked`,identity:r})},...Re(e),PM_GET_WALLET_SESSION:async t=>{let n=e.getWalletRuntime(),r=bn(n,t.payload),i=await n.auth.getSession(r);f(e,t.requestId,i)},PM_GET_EXACT_WALLET_SESSION_STATE:async t=>{let n=e.getWalletRuntime(),r=t.payload;if(!r||r.authenticationRead!==`restore`&&r.authenticationRead!==`current`||!r.wallet||r.wallet.kind!==`current`&&r.wallet.kind!==`exact`||r.authenticationRead===`restore`&&r.wallet.kind!==`current`)throw Error(`Wallet iframe exact session read mode is invalid`);await e.observeSession(r,Sn.bind(null,e,n,t.requestId,r))},PM_GET_RECENT_UNLOCKS:async t=>{let n=await e.getWalletRuntime().auth.getRecentUnlocks();f(e,t.requestId,n)}}}async function wn(e){await ne(e,Cn)}export{wn as handleWalletHostRuntimeRequest};
|
package/dist/{esm/sdk/runtime-device-link-BUxuQupR.js → public/sdk/runtime-device-link-ENxdEXQW.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./primitives-CAcl7ON7.js";import"./sessionPolicy-J-RrlPZQ.js";import"./signingSessionSeal-CDLUmAFY.js";import{a as e,i as t}from"./messages-vxz27Way.js";import{a as n,n as r,r as i,t as a}from"./shared-
|
|
1
|
+
import"./primitives-CAcl7ON7.js";import"./sessionPolicy-J-RrlPZQ.js";import"./signingSessionSeal-CDLUmAFY.js";import{a as e,i as t}from"./messages-vxz27Way.js";import{a as n,n as r,r as i,t as a}from"./shared-8ffIBYw2.js";import"./activeWalletSession-DiZcKjB_.js";import"./capabilityKinds-CKQ4Uqnv.js";import"./errors-BZO3LF6G.js";import"./digestEncoding-Dzc1rzWV.js";import"./accountIds-BzZs7YoX.js";import"./registrationSignerPlan-B9GCvpTV.js";import"./signerDomain-vQmlnsbF.js";import{A as o,N as s,j as c,ot as l}from"./registrationIntent-DOkZcKSP.js";import"./singletons-8UH3gOnZ.js";import"./walletAuthority-B5hXHWpK.js";import"./emailOtpEcdsaDerivationIdentity-B8HzTh4T.js";import"./challengeDelivery-DxXAkOfS.js";import"./registrationIds-CdPqm-Ya.js";import"./passkey-custody-BQj44jEM.js";import{c as u}from"./sdkSentEvents-D3q1h-Uo.js";import"./walletCustodyEcdsaContinuity-abNZ_dvX.js";import"./keccak-B02Fekdh.js";import"./wallet-recovery-C1kesLCF.js";import"./nearEd25519YaoMaterialActivation-fWQI3rYj.js";import"./signNear-BhTkDm2-.js";import"./jsxRuntime.module-BcZNe_OA.js";function d(e,t,n,r){return n?(e.get(n)?.reject(Error(`A newer Email OTP method selection is required`)),new Promise((i,a)=>{let o=setTimeout(()=>f(e,n,Error(`Email OTP method selection timed out`)),9e5);e.set(n,{choices:r,resolve:e=>{clearTimeout(o),i(e)},reject:e=>{clearTimeout(o),a(e instanceof Error?e:Error(String(e)))}}),t.postProgress(n,{event:`wallet_device_link_email_otp_base_factor_selection_required_v1`,choices:r})})):Promise.reject(Error(`Device-link request id is required`))}function f(e,t,n){if(!t)return;let r=e.get(t);r&&(e.delete(t),r.reject(n))}function p(e,t){let n=e.get(t.scanRequestId);if(!n)throw Error(`Email OTP method selection is unavailable`);switch(t.action.kind){case`cancel`:e.delete(t.scanRequestId),n.reject(Error(`Device linking was cancelled`));return;case`select`:{let r=t.action.baseWalletAuthMethodId;if(!n.choices.some(e=>e.baseWalletAuthMethodId===r))throw Error(`The selected Email OTP method is unavailable for this linked device`);e.delete(t.scanRequestId),n.resolve(r);return}default:throw t.action,Error(`Unsupported Email OTP method selection action`)}}function m(e){switch(e.activation.kind){case`linked_device_target_passkey_activation_v1`:return{event:`wallet_device_link_target_factor_activation_v1`,activationId:e.activationId,activation:{kind:e.activation.kind}};case`linked_device_target_email_otp_activation_v1`:return{event:`wallet_device_link_target_factor_activation_v1`,activationId:e.activationId,activation:{kind:e.activation.kind,state:e.activation.state}};default:throw e.activation,Error(`Unsupported linked-device target-factor activation`)}}async function h(e){switch(e.action.kind){case`create_passkey`:if(e.active.activation.kind!==`linked_device_target_passkey_activation_v1`)throw Error(`linked-device Passkey activation is unavailable`);await e.active.activation.createPasskey();return;case`send_email_otp`:if(e.active.activation.kind!==`linked_device_target_email_otp_activation_v1`)throw Error(`linked-device Email OTP activation is unavailable`);await e.active.activation.sendCode();return;case`resend_email_otp`:if(e.active.activation.kind!==`linked_device_target_email_otp_activation_v1`)throw Error(`linked-device Email OTP activation is unavailable`);await e.active.activation.resendCode();return;case`submit_email_otp`:if(e.active.activation.kind!==`linked_device_target_email_otp_activation_v1`)throw Error(`linked-device Email OTP activation is unavailable`);await e.active.activation.submitCode(e.action.otpCode);return;default:throw e.action,Error(`Unsupported linked-device target-factor action`)}}function g(e,t,n,r,i){e.current={activationId:r,activation:i},t.postProgress(n,m(e.current))}function _(e,t,n,r){t.postProgress(n,r);let i=u(r);(i.kind===`active`||i.kind===`failed`||i.kind===`invalid_active`||i.kind===`cancelled`)&&(e.current=null)}function v(n){let u={current:null},m=new Map;return{PM_START_DEVICE2_LINKING_FLOW:async e=>{let t=n.getWalletRuntime(),i=e.payload;if(!i)throw Error(`PM_START_DEVICE2_LINKING_FLOW requires a payload`);let{ui:a,cameraId:o,options:s}=i,c;if(i.targetFactor.kind===`email_otp`){if(typeof i.targetEmail!=`string`)throw Error(`PM_START_DEVICE2_LINKING_FLOW requires targetEmail for Email OTP`);c={targetFactor:i.targetFactor,targetEmail:i.targetEmail}}else c={targetFactor:i.targetFactor};if(n.respondIfCancelled(e.requestId))return;let l=String(e.requestId||``).trim();if(!l)throw Error(`Device-link target-factor activation id is required`);let d=await t.devices.startLinking({...c,...a?{ui:a}:{},...o?{cameraId:o}:{},options:{...s||{},onEvent:_.bind(null,u,n,e.requestId),onTargetFactorRequired:g.bind(null,u,n,e.requestId,l)}});n.respondIfCancelled(e.requestId)||r(n,e.requestId,d)},PM_DEVICE_LINK_TARGET_FACTOR_ACTION:async t=>{let r=e(t.payload);if(!r)throw Error(`PM_DEVICE_LINK_TARGET_FACTOR_ACTION payload is invalid`);let i=u.current;if(!i||i.activationId!==r.activationId)throw Error(`linked-device target-factor activation is unavailable`);await h({active:i,action:r.action}),a(n,t.requestId)},PM_DEVICE_LINK_EMAIL_OTP_BASE_FACTOR_ACTION:async e=>{let r=t(e.payload);if(!r)throw Error(`Email OTP method selection payload is invalid`);p(m,r),a(n,e.requestId)},PM_CANCEL_DEVICE_LINKING:async e=>{let t=n.getWalletRuntime();if(!n.respondIfCancelled(e.requestId)){await t.devices.cancelLinking(),u.current=null;for(let e of[...m.keys()])f(m,e,Error(`Device linking was cancelled`));n.respondIfCancelled(e.requestId)||a(n,e.requestId)}},PM_SCAN_AND_LINK_DEVICE:async e=>{let t=n.getWalletRuntime(),{qrData:a,options:o}=e.payload;if(!n.respondIfCancelled(e.requestId))try{let s=await t.devices.approveLinking(l(a),{...i(n,e.requestId,o||{}),onEmailOtpBaseFactorRequired:t=>d(m,n,e.requestId,t)});if(n.respondIfCancelled(e.requestId))return;r(n,e.requestId,s)}finally{f(m,e.requestId,Error(`Device-link request ended before Email OTP method selection completed`))}},PM_HAS_PASSKEY:async e=>{let t=n.getWalletRuntime(),{walletId:i}=e.payload,a=await t.auth.hasPasskey(i);r(n,e.requestId,a)},PM_LIST_LINKED_DEVICES:async e=>{let t=n.getWalletRuntime(),i=e.payload;if(!i)throw Error(`PM_LIST_LINKED_DEVICES requires a payload`);let a=o({kind:`linked_device_list_request_v1`,walletId:i.walletId,limit:i.limit,cursor:i.cursor}),s=await t.devices.list({walletId:String(a.walletId),limit:a.limit,cursor:a.cursor});r(n,e.requestId,c(s))},PM_REVOKE_LINKED_DEVICE:async e=>{let t=n.getWalletRuntime(),i=e.payload;if(!i)throw Error(`PM_REVOKE_LINKED_DEVICE requires a payload`);if(n.respondIfCancelled(e.requestId))return;let a=await t.devices.remove({walletId:i.walletId,walletAuthMethodId:i.walletAuthMethodId});n.respondIfCancelled(e.requestId)||r(n,e.requestId,s(a))}}}async function y(e){await n(e,v)}export{y as handleWalletHostRuntimeRequest};
|