@seams/wallet 0.10.2 → 0.11.0
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/THIRD_PARTY_NOTICES.md +33 -1812
- package/dist/.build-inputs.sha256 +1 -1
- package/dist/esm/SeamsWeb/operations/recovery/walletRecoveryCodeBackup.js +100 -0
- package/dist/esm/SeamsWeb/walletIframe/host/ui/auth-menu/AuthMenuSurface.js +127 -71
- package/dist/esm/core/signingEngine/uiConfirm/ui/preact/RecoveryCodeBackupSurface.js +558 -0
- package/dist/esm/core/signingEngine/uiConfirm/ui/preact/mountRecoveryCodeBackupSurface.js +82 -0
- package/dist/esm/core/types/sdkSentEvents.js +9 -0
- package/dist/esm/react/components/AccountMenuButton/AccountMenuButtonMock.js +189 -0
- package/dist/esm/react/components/AccountMenuButton/AccountMenuButtonView.js +137 -0
- package/dist/esm/react/components/AccountMenuButton/AccountMenuDeviceDetails.js +39 -0
- package/dist/esm/react/components/AccountMenuButton/AccountMenuDialog.js +39 -13
- package/dist/esm/react/components/AccountMenuButton/AccountMenuMockScreens.js +247 -0
- package/dist/esm/react/components/AccountMenuButton/AccountMenuScreen.js +41 -0
- package/dist/esm/react/components/AccountMenuButton/AuthenticationMethodRow.js +79 -0
- package/dist/esm/react/components/AccountMenuButton/AuthenticationMethodsModal.js +168 -174
- package/dist/esm/react/components/AccountMenuButton/AuthenticationMethodsView.js +19 -0
- package/dist/esm/react/components/AccountMenuButton/ExportKeysScreen.js +30 -0
- package/dist/esm/react/components/AccountMenuButton/LinkedDevicesModal.css +148 -87
- package/dist/esm/react/components/AccountMenuButton/LinkedDevicesModal.js +26 -5
- package/dist/esm/react/components/AccountMenuButton/MenuItem.js +28 -13
- package/dist/esm/react/components/AccountMenuButton/ProfileDropdown.css +73 -69
- package/dist/esm/react/components/AccountMenuButton/ProfileDropdown.js +56 -68
- package/dist/esm/react/components/AccountMenuButton/RecoveryCodeAcknowledgement.js +27 -0
- package/dist/esm/react/components/AccountMenuButton/RecoveryCodeActions.js +53 -0
- package/dist/esm/react/components/AccountMenuButton/TransactionSettingsSection.css +3 -1
- package/dist/esm/react/components/AccountMenuButton/TransactionSettingsSection.js +2 -8
- package/dist/esm/react/components/AccountMenuButton/UserAccountButton.css +1 -1
- package/dist/esm/react/components/AccountMenuButton/UserAccountButton.js +6 -3
- package/dist/esm/react/components/AccountMenuButton/WalletRegionSection.js +4 -4
- package/dist/esm/react/components/AccountMenuButton/Web3AuthProfileButton.css +443 -12
- package/dist/esm/react/components/AccountMenuButton/hooks/useProfileState.js +1 -1
- package/dist/esm/react/components/AccountMenuButton/icons/LayersIcon.js +8 -0
- package/dist/esm/react/components/AccountMenuButton/icons/LockKeyholeIcon.js +22 -0
- package/dist/esm/react/components/AccountMenuButton/icons/PlusIcon.js +8 -0
- package/dist/esm/react/components/AccountMenuButton/icons/SunIcon.js +2 -2
- package/dist/esm/react/components/AccountMenuButton/icons/TouchIcon.css +0 -8
- package/dist/esm/react/components/AccountMenuButton/index.js +135 -115
- package/dist/esm/react/components/QRCodeScanner.js +64 -40
- package/dist/esm/react/components/QRCodeScannerCamera.js +16 -0
- package/dist/esm/react/components/ShowQRCode.js +2 -2
- package/dist/esm/react/externalEvm.js +2 -2
- package/dist/esm/react/index.js +2 -1
- package/dist/esm/react/styles/styles.css +520 -91
- package/dist/esm/react/transactionReview/TransactionReviewHost.js +3 -3
- package/dist/esm/sdk/{adapters-DYPu0nK9.js → adapters-CGvNLOfZ.js} +1 -1
- package/dist/{public/sdk/display-DjoWrSgE.js → esm/sdk/display-DTbGoX4e.js} +1 -1
- package/dist/{public/sdk/exportKeypairOperation-DYCzCbqL.js → esm/sdk/exportKeypairOperation-BHXMSA3v.js} +1 -1
- package/dist/{public/sdk/host-D5b19B_h.js → esm/sdk/host-Bqmmy8Ts.js} +1 -1
- package/dist/esm/sdk/{localOnly-KvZeKkH5.js → localOnly-CUVRoMy2.js} +1 -1
- package/dist/esm/sdk/{mountRecoveryCodeBackupSurface-BA2ttbTM.js → mountRecoveryCodeBackupSurface-D1G-iCPI.js} +2 -2
- package/dist/esm/sdk/{pendingWalletRecoveryCodeBackup-BkIrbd6Q.js → pendingWalletRecoveryCodeBackup-CMCOUuA-.js} +1 -1
- package/dist/esm/sdk/{recovery-entrypoint-DoXswV9I.js → recovery-entrypoint-QxTiyx-o.js} +1 -1
- package/dist/esm/sdk/{registration-BFHEYmgh.js → registration-Drtkzrlc.js} +1 -1
- package/dist/esm/sdk/registration-eyzHqLHi.js +1 -0
- package/dist/esm/sdk/{requireStepUpAuth-C67sluoC.js → requireStepUpAuth-FqZSU021.js} +1 -1
- package/dist/esm/sdk/router_ab_ed25519_yao_client_bg.wasm +0 -0
- package/dist/esm/sdk/runtime-auth-CbveTM2_.js +1 -0
- package/dist/esm/sdk/{runtime-device-link-pf-a_-3u.js → runtime-device-link-CHsqrEQ9.js} +1 -1
- package/dist/esm/sdk/{runtime-ecdsa-tempo-Ddnuti6f.js → runtime-ecdsa-tempo-MgmnU9g-.js} +1 -1
- package/dist/esm/sdk/{runtime-email-otp-BAG8ZC1J.js → runtime-email-otp-Cj96n102.js} +1 -1
- package/dist/esm/sdk/{runtime-export-DxL99xfn.js → runtime-export-mcwZRxKk.js} +1 -1
- package/dist/esm/sdk/{runtime-near-BrWP4IxC.js → runtime-near-BMdTtu7D.js} +1 -1
- package/dist/esm/sdk/{runtime-preferences-BjVdHYL0.js → runtime-preferences-CBlhE8bX.js} +1 -1
- package/dist/esm/sdk/{runtime-recovery-codes-Dn-NccpU.js → runtime-recovery-codes-B1gixZsp.js} +1 -1
- package/dist/esm/sdk/{runtime-recovery-BNd_GX5q.js → runtime-recovery-mJp3MLeG.js} +1 -1
- package/dist/esm/sdk/sdkSentEvents-Dl8fOL50.js +1 -0
- package/dist/esm/sdk/shared-8Qe7Nxgg.js +6 -0
- package/dist/{public/sdk/signEvmFamily-DjD3tn8e.js → esm/sdk/signEvmFamily-M0trbeZe.js} +1 -1
- package/dist/esm/sdk/{signEvmFamilyWithUiConfirmForTempo-CwRFbaLM.js → signEvmFamilyWithUiConfirmForTempo-Bo25SwuV.js} +1 -1
- package/dist/esm/sdk/{signEvmWithUiConfirm-BHG0dwVG.js → signEvmWithUiConfirm-CFcqJRj3.js} +1 -1
- package/dist/{public/sdk/signNear-D0tlQXb9.js → esm/sdk/signNear-DGUQZ44s.js} +1 -1
- package/dist/esm/sdk/{signingFlow-Mym5j6aw.js → signingFlow-DZvV4AgG.js} +1 -1
- package/dist/esm/sdk/{transaction-activity-Cb2JyYKv.js → transaction-activity-xfeHKJoq.js} +1 -1
- 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/sdk/wallet-ui.css +1 -1
- package/dist/{public/sdk/walletCustodyEcdsaContinuity-B8aO2NFb.js → esm/sdk/walletCustodyEcdsaContinuity-_IKoCUBO.js} +1 -1
- package/dist/{public/sdk/walletRecoveryCommit-C3EgMjo-.js → esm/sdk/walletRecoveryCommit-DDPa1rAJ.js} +1 -1
- package/dist/esm/wasm/near_signer/pkg/wasm_signer_worker_bg.wasm +0 -0
- package/dist/esm/wasm/router_ab_ecdsa_client/pkg/router_ab_ecdsa_client_bg.wasm +0 -0
- package/dist/esm/wasm/router_ab_ed25519_yao_client/pkg/router_ab_ed25519_yao_client_bg.wasm +0 -0
- package/dist/public/headers.manifest.json +1 -1
- package/dist/public/sdk/{adapters-DYPu0nK9.js → adapters-CGvNLOfZ.js} +1 -1
- package/dist/{esm/sdk/display-DjoWrSgE.js → public/sdk/display-DTbGoX4e.js} +1 -1
- package/dist/{esm/sdk/exportKeypairOperation-DYCzCbqL.js → public/sdk/exportKeypairOperation-BHXMSA3v.js} +1 -1
- package/dist/{esm/sdk/host-D5b19B_h.js → public/sdk/host-Bqmmy8Ts.js} +1 -1
- package/dist/public/sdk/{localOnly-KvZeKkH5.js → localOnly-CUVRoMy2.js} +1 -1
- package/dist/public/sdk/{mountRecoveryCodeBackupSurface-BA2ttbTM.js → mountRecoveryCodeBackupSurface-D1G-iCPI.js} +2 -2
- package/dist/public/sdk/{pendingWalletRecoveryCodeBackup-BkIrbd6Q.js → pendingWalletRecoveryCodeBackup-CMCOUuA-.js} +1 -1
- package/dist/public/sdk/{recovery-entrypoint-DoXswV9I.js → recovery-entrypoint-QxTiyx-o.js} +1 -1
- package/dist/public/sdk/{registration-BFHEYmgh.js → registration-Drtkzrlc.js} +1 -1
- package/dist/public/sdk/registration-eyzHqLHi.js +1 -0
- package/dist/public/sdk/{requireStepUpAuth-C67sluoC.js → requireStepUpAuth-FqZSU021.js} +1 -1
- package/dist/public/sdk/router_ab_ed25519_yao_client_bg.wasm +0 -0
- package/dist/public/sdk/runtime-auth-CbveTM2_.js +1 -0
- package/dist/public/sdk/{runtime-device-link-pf-a_-3u.js → runtime-device-link-CHsqrEQ9.js} +1 -1
- package/dist/public/sdk/{runtime-ecdsa-tempo-Ddnuti6f.js → runtime-ecdsa-tempo-MgmnU9g-.js} +1 -1
- package/dist/public/sdk/{runtime-email-otp-BAG8ZC1J.js → runtime-email-otp-Cj96n102.js} +1 -1
- package/dist/public/sdk/{runtime-export-DxL99xfn.js → runtime-export-mcwZRxKk.js} +1 -1
- package/dist/public/sdk/{runtime-near-BrWP4IxC.js → runtime-near-BMdTtu7D.js} +1 -1
- package/dist/public/sdk/{runtime-preferences-BjVdHYL0.js → runtime-preferences-CBlhE8bX.js} +1 -1
- package/dist/public/sdk/{runtime-recovery-codes-Dn-NccpU.js → runtime-recovery-codes-B1gixZsp.js} +1 -1
- package/dist/public/sdk/{runtime-recovery-BNd_GX5q.js → runtime-recovery-mJp3MLeG.js} +1 -1
- package/dist/public/sdk/sdkSentEvents-Dl8fOL50.js +1 -0
- package/dist/public/sdk/shared-8Qe7Nxgg.js +6 -0
- package/dist/{esm/sdk/signEvmFamily-DjD3tn8e.js → public/sdk/signEvmFamily-M0trbeZe.js} +1 -1
- package/dist/public/sdk/{signEvmFamilyWithUiConfirmForTempo-CwRFbaLM.js → signEvmFamilyWithUiConfirmForTempo-Bo25SwuV.js} +1 -1
- package/dist/public/sdk/{signEvmWithUiConfirm-BHG0dwVG.js → signEvmWithUiConfirm-CFcqJRj3.js} +1 -1
- package/dist/{esm/sdk/signNear-D0tlQXb9.js → public/sdk/signNear-DGUQZ44s.js} +1 -1
- package/dist/public/sdk/{signingFlow-Mym5j6aw.js → signingFlow-DZvV4AgG.js} +1 -1
- package/dist/public/sdk/{transaction-activity-Cb2JyYKv.js → transaction-activity-xfeHKJoq.js} +1 -1
- 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/sdk/wallet-ui.css +1 -1
- package/dist/{esm/sdk/walletCustodyEcdsaContinuity-B8aO2NFb.js → public/sdk/walletCustodyEcdsaContinuity-_IKoCUBO.js} +1 -1
- package/dist/{esm/sdk/walletRecoveryCommit-C3EgMjo-.js → public/sdk/walletRecoveryCommit-DDPa1rAJ.js} +1 -1
- package/dist/public/sdk/workers/email_otp_runtime_bg.wasm +0 -0
- package/dist/public/sdk/workers/evm_crypto_bg.wasm +0 -0
- package/dist/public/sdk/workers/router_ab_ecdsa_client_bg.wasm +0 -0
- package/dist/public/sdk/workers/router_ab_ed25519_yao_client_bg.wasm +0 -0
- package/dist/public/sdk/workers/shamir3pass_runtime_bg.wasm +0 -0
- package/dist/public/sdk/workers/tempo_signer_bg.wasm +0 -0
- package/dist/public/sdk/workers/wallet_custody_ceremony_bg.wasm +0 -0
- package/dist/public/sdk/workers/wasm_signer_worker_bg.wasm +0 -0
- package/dist/public/wallet-assets.manifest.json +62 -62
- package/dist/public/wallet-service/index.html +4 -4
- package/dist/types/wallet/src/SeamsWeb/walletIframe/host/auth-menu/domain.d.ts +4 -0
- package/dist/types/wallet/src/SeamsWeb/walletIframe/host/auth-menu/session.d.ts +4 -2
- package/dist/types/wallet/src/core/types/sdkSentEvents.d.ts +4 -0
- package/dist/types/wallet/src/react/components/AccountMenuButton/AccountMenuButtonMock.d.ts +17 -0
- package/dist/types/wallet/src/react/components/AccountMenuButton/AccountMenuButtonView.d.ts +17 -0
- package/dist/types/wallet/src/react/components/AccountMenuButton/AccountMenuDeviceDetails.d.ts +13 -0
- package/dist/types/wallet/src/react/components/AccountMenuButton/AccountMenuDialog.d.ts +1 -1
- package/dist/types/wallet/src/react/components/AccountMenuButton/AccountMenuMockScreens.d.ts +43 -0
- package/dist/types/wallet/src/react/components/AccountMenuButton/AccountMenuScreen.d.ts +9 -0
- package/dist/types/wallet/src/react/components/AccountMenuButton/AuthenticationMethodRow.d.ts +14 -0
- package/dist/types/wallet/src/react/components/AccountMenuButton/AuthenticationMethodsModal.d.ts +1 -1
- package/dist/types/wallet/src/react/components/AccountMenuButton/AuthenticationMethodsView.d.ts +8 -0
- package/dist/types/wallet/src/react/components/AccountMenuButton/ExportKeysScreen.d.ts +7 -0
- package/dist/types/wallet/src/react/components/AccountMenuButton/LinkedDevicesModal.d.ts +1 -1
- package/dist/types/wallet/src/react/components/AccountMenuButton/ProfileDropdown.d.ts +2 -14
- package/dist/types/wallet/src/react/components/AccountMenuButton/RecoveryCodeAcknowledgement.d.ts +5 -0
- package/dist/types/wallet/src/react/components/AccountMenuButton/RecoveryCodeActions.d.ts +5 -0
- package/dist/types/wallet/src/react/components/AccountMenuButton/icons/LayersIcon.d.ts +2 -0
- package/dist/types/wallet/src/react/components/AccountMenuButton/icons/LockKeyholeIcon.d.ts +2 -0
- package/dist/types/wallet/src/react/components/AccountMenuButton/icons/PlusIcon.d.ts +2 -0
- package/dist/types/wallet/src/react/components/AccountMenuButton/index.d.ts +2 -0
- package/dist/types/wallet/src/react/components/AccountMenuButton/types.d.ts +1 -14
- package/dist/types/wallet/src/react/components/QRCodeScanner.d.ts +1 -0
- package/dist/types/wallet/src/react/components/QRCodeScannerCamera.d.ts +5 -0
- package/dist/types/wallet/src/react/index.d.ts +2 -1
- package/dist/workers/email_otp_runtime_bg.wasm +0 -0
- package/dist/workers/evm_crypto_bg.wasm +0 -0
- package/dist/workers/router_ab_ecdsa_client_bg.wasm +0 -0
- package/dist/workers/router_ab_ed25519_yao_client_bg.wasm +0 -0
- package/dist/workers/shamir3pass_runtime_bg.wasm +0 -0
- package/dist/workers/tempo_signer_bg.wasm +0 -0
- package/dist/workers/wallet_custody_ceremony_bg.wasm +0 -0
- package/dist/workers/wasm_signer_worker_bg.wasm +0 -0
- package/package.json +1 -1
- package/dist/esm/sdk/registration-Cx_f58rb.js +0 -1
- package/dist/esm/sdk/runtime-auth-CKUleRYA.js +0 -1
- package/dist/esm/sdk/sdkSentEvents-DiQ3YVlj.js +0 -1
- package/dist/esm/sdk/shared-CSfgTVcf.js +0 -6
- package/dist/public/sdk/registration-Cx_f58rb.js +0 -1
- package/dist/public/sdk/runtime-auth-CKUleRYA.js +0 -1
- package/dist/public/sdk/sdkSentEvents-DiQ3YVlj.js +0 -1
- package/dist/public/sdk/shared-CSfgTVcf.js +0 -6
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{M as e,O as t}from"./domainIds-BzkGsRqO.js";import{k as n}from"./chains-C_X_fNuS.js";import"./primitives-CqrjmIAH.js";import"./sessionPolicy-CBTZQe1n.js";import"./signingSessionSeal-DX41aXUL.js";import{c as r,l as i,o as a,r as o,s}from"./messages-DgJlG9NU.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-CSfgTVcf.js";import"./activeWalletSession-WdZkhtBB.js";import"./capabilityKinds-N8xo_IEh.js";import{t as _e}from"./walletIframeIdentity-Cz82I_Uh.js";import"./errors-DIWY1KR9.js";import{en as ve,i as ye,n as be,nn as xe,r as Se,s as Ce}from"./registration-Cx_f58rb.js";import"./accountIds-BzZs7YoX.js";import"./registrationSignerPlan-dY9Rp0m_.js";import{a as p}from"./signerDomain-DqLCvI-D.js";import"./registrationIntent-BHU5k2Q-.js";import"./singletons-8UH3gOnZ.js";import"./walletAuthority-BWvfaKIX.js";import"./emailOtpEcdsaDerivationIdentity-p0C1CQva.js";import{t as we}from"./challengeDelivery-5lIu9spR.js";import"./digestEncoding-CkUc5vtR.js";import{a as Te,n as Ee}from"./registrationIds-ByuReLUc.js";import"./passkey-custody-Cd_yyoRa.js";import{c as De,s as Oe}from"./sdkSentEvents-DiQ3YVlj.js";import"./walletCustodyEcdsaContinuity-B8aO2NFb.js";import"./keccak-BArcwgbj.js";import"./wallet-recovery-D7ywcIHw.js";import"./nearEd25519YaoMaterialActivation-DMGPKrn8.js";import{t as ke}from"./walletSessionAuthorizationStatus-BLyzJbU8.js";import"./signNear-D0tlQXb9.js";import{a as Ae,i as je}from"./adapters-DYPu0nK9.js";import{t as Me}from"./surface-measurement-reporter-DvVHPu_O.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-C8JOKu_4.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(e,r){let i=n(r.payload,`Wallet placement request`),a=t(i.walletId);if(!a.ok||Object.keys(i).length!==1)throw Error(`Wallet placement identity is invalid`);let o=await e.getWalletRuntime().placement.get(a.value);e.respondIfCancelled(r.requestId)||f(e,r.requestId,o)}async function Be(e,r){let i=n(r.payload,`Wallet move request`),a=t(i.walletId),o=ce(i.moveId);if(!a.ok||Object.keys(i).length!==2)throw Error(`Wallet move request is invalid`);let s=await e.getWalletRuntime().placement.getMove(a.value,o);e.respondIfCancelled(r.requestId)||f(e,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(e,r){let i=n(r.payload,`Wallet move locator request`),a=t(i.walletId);if(!a.ok||Object.keys(i).length!==1)throw Error(`Wallet move locator identity is invalid`);let o=await e.getWalletRuntime().placement.getLastMoveRequest(a.value);e.respondIfCancelled(r.requestId)||f(e,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(e,n,r){let i=this.stateValue;if(e!==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=t(Z(i.viewModel));if(!a.ok)return;this.rejectRecoveredLoginPreparation(e,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 e=this.stateValue;if(e.kind!==`recovery`||e.stage!==`sign_in_ready`)return;if(e.viewModel.target.kind===`google_email_otp`){this.requestExternalAuth(`google`);return}let n=this.recoveryLoginPrepared;if(!n){let n=t(Z(e.viewModel));if(!n.ok)return;this.prepareRecoveredPasskeyLogin(n.value,e.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(e){if(!e.success||e.kind!==`wallet_registered`&&e.kind!==`ecdsa_wallet_registered_near_pending`){this.fail({kind:`error`,error:Error(e.success?`Hosted registration returned an unexpected result`:e.error)});return}let n=t(String(e.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(e){let n=e.result;if(!n.success){this.fail(e.cancelledByUser?{kind:`dismissed`}:{kind:`error`,error:Error(n.error)});return}let r=t(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(e){if(!e.success){this.fail({kind:`error`,error:Error(e.error)});return}let n=t(String(e.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-DoXswV9I.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(t){if(t===`google_email_otp`)return{kind:t,googleProvider:`google`};let n=e(this.getWalletRuntime().getContext().signingEngine.getRpId());if(!n.ok)throw Error(`wallet recovery RP ID ${n.error.message}`);return{kind:t,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(t,n,r,i,a){let o=this.deps.getWalletRuntime().getContext(),s=e(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:t.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 +0,0 @@
|
|
|
1
|
-
import{O as e,u as t}from"./domainIds-BzkGsRqO.js";const n={restore:`restore`,visibility:`visibility`,focus:`focus`,operationPreflight:`operation_preflight`,serverRejection:`server_rejection`};function r(e){return{version:1,event:`registration.near_provisioning_changed`,walletId:e.walletId,state:e.state}}function i(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>0}function a(e){return typeof e==`string`&&e.trim().length>0}function o(e){switch(e){case`near_provisioning_interrupted`:case`near_finalize_failed`:case`near_capability_persist_failed`:case`near_seal_failed`:case`near_provisioning_failed`:return e;default:return null}}function s(e){if(typeof e!=`object`||!e||Array.isArray(e))return null;let t=Reflect.get(e,`updatedAtMs`);if(!i(t))return null;switch(Reflect.get(e,`status`)){case`near_pending`:return{status:`near_pending`,updatedAtMs:t};case`near_provisioning`:return{status:`near_provisioning`,updatedAtMs:t};case`near_ready`:{let n=Reflect.get(e,`nearAccountId`);return a(n)?{status:`near_ready`,updatedAtMs:t,nearAccountId:n}:null}case`near_failed_retryable`:{let n=Reflect.get(e,`error`);if(!a(n))return null;let r=o(Reflect.get(e,`errorCode`));return r?{status:`near_failed_retryable`,updatedAtMs:t,error:n,errorCode:r}:null}default:return null}}function c(e){if(!i(e.expiresAtMs))throw Error(`signing_session.expired expiresAtMs must be a positive safe integer`);if(!i(e.detectedAtMs))throw Error(`signing_session.expired detectedAtMs must be a positive safe integer`);if(e.expiresAtMs>e.detectedAtMs)throw Error(`signing_session.expired timeline is invalid`);return{version:1,event:`signing_session.expired`,walletId:e.walletId,walletSessionId:e.walletSessionId,authMethod:e.authMethod,expiresAtMs:e.expiresAtMs,detectedAtMs:e.detectedAtMs,source:e.source}}let l=function(e){return e.STEP_01_STARTED=`registration.started`,e.STEP_02_ACCOUNT_PREFLIGHT_STARTED=`registration.account.preflight.started`,e.STEP_02_ACCOUNT_PREFLIGHT_SUCCEEDED=`registration.account.preflight.succeeded`,e.STEP_03_SESSION_EXCHANGE_STARTED=`registration.session.exchange.started`,e.STEP_03_SESSION_EXCHANGE_SUCCEEDED=`registration.session.exchange.succeeded`,e.STEP_04_PASSKEY_CREATE_STARTED=`registration.auth.passkey.create.started`,e.STEP_04_PASSKEY_CREATE_SUCCEEDED=`registration.auth.passkey.create.succeeded`,e.STEP_04_OTP_CHALLENGE_STARTED=`registration.otp.challenge.started`,e.STEP_04_OTP_CHALLENGE_SENT=`registration.otp.challenge.sent`,e.STEP_04_OTP_INPUT_REQUIRED=`registration.otp.input.required`,e.STEP_04_OTP_VERIFY_STARTED=`registration.otp.verify.started`,e.STEP_04_OTP_VERIFY_SUCCEEDED=`registration.otp.verify.succeeded`,e.STEP_05_ED25519_SIGNER_PREPARE_STARTED=`registration.signer.ed25519.prepare.started`,e.STEP_05_ED25519_SIGNER_PREPARE_SUCCEEDED=`registration.signer.ed25519.prepare.succeeded`,e.STEP_05_ED25519_SIGNER_PROVISION_STARTED=`registration.signer.ed25519.provision.started`,e.STEP_05_ED25519_SIGNER_PROVISION_SUCCEEDED=`registration.signer.ed25519.provision.succeeded`,e.STEP_05_ED25519_SIGNER_PROVISION_SKIPPED=`registration.signer.ed25519.provision.skipped`,e.STEP_06_RELAY_BOOTSTRAP_STARTED=`registration.relay.bootstrap.started`,e.STEP_06_RELAY_BOOTSTRAP_SUCCEEDED=`registration.relay.bootstrap.succeeded`,e.STEP_07_ACCOUNT_VERIFY_STARTED=`registration.account.verify.started`,e.STEP_07_ACCOUNT_VERIFY_SUCCEEDED=`registration.account.verify.succeeded`,e.STEP_08_STORAGE_PERSIST_STARTED=`registration.storage.persist.started`,e.STEP_08_STORAGE_PERSIST_SUCCEEDED=`registration.storage.persist.succeeded`,e.STEP_09_EMAIL_OTP_SIGNER_ENROLL_STARTED=`registration.signer.email_otp.enroll.started`,e.STEP_09_EMAIL_OTP_SIGNER_ENROLL_SUCCEEDED=`registration.signer.email_otp.enroll.succeeded`,e.STEP_10_ECDSA_SIGNER_PROVISION_STARTED=`registration.signer.ecdsa.provision.started`,e.STEP_10_ECDSA_SIGNER_PROVISION_SUCCEEDED=`registration.signer.ecdsa.provision.succeeded`,e.STEP_10_ECDSA_SIGNER_PROVISION_SKIPPED=`registration.signer.ecdsa.provision.skipped`,e.STEP_10_ECDSA_SIGNER_BOOTSTRAP_STARTED=`registration.signer.ecdsa.bootstrap.started`,e.STEP_10_ECDSA_SIGNER_BOOTSTRAP_SUCCEEDED=`registration.signer.ecdsa.bootstrap.succeeded`,e.STEP_11_COMPLETED=`registration.completed`,e.FAILED=`registration.failed`,e.CANCELLED=`registration.cancelled`,e}({}),u=function(e){return e.STEP_01_STARTED=`unlock.started`,e.STEP_02_ACCOUNT_LOOKUP_STARTED=`unlock.account.lookup.started`,e.STEP_02_ACCOUNT_LOOKUP_SUCCEEDED=`unlock.account.lookup.succeeded`,e.STEP_03_PASSKEY_CHALLENGE_STARTED=`unlock.auth.passkey.challenge.started`,e.STEP_03_PASSKEY_PROMPT_STARTED=`unlock.auth.passkey.prompt.started`,e.STEP_03_PASSKEY_PROMPT_SUCCEEDED=`unlock.auth.passkey.prompt.succeeded`,e.STEP_03_EMAIL_OTP_CHALLENGE_STARTED=`unlock.auth.email_otp.challenge.started`,e.STEP_03_EMAIL_OTP_CHALLENGE_SENT=`unlock.auth.email_otp.challenge.sent`,e.STEP_03_EMAIL_OTP_INPUT_REQUIRED=`unlock.auth.email_otp.input.required`,e.STEP_03_EMAIL_OTP_VERIFY_STARTED=`unlock.auth.email_otp.verify.started`,e.STEP_03_EMAIL_OTP_VERIFY_SUCCEEDED=`unlock.auth.email_otp.verify.succeeded`,e.STEP_04_WALLET_UNLOCK_EXCHANGE_STARTED=`unlock.wallet.exchange.started`,e.STEP_04_WALLET_UNLOCK_EXCHANGE_SUCCEEDED=`unlock.wallet.exchange.succeeded`,e.STEP_04_WALLET_UNLOCK_EXCHANGE_SKIPPED=`unlock.wallet.exchange.skipped`,e.STEP_05_SIGNING_SESSION_WARMUP_STARTED=`unlock.signing_session.warmup.started`,e.STEP_05_ED25519_SIGNING_SESSION_READY=`unlock.signing_session.ed25519.ready`,e.STEP_05_ECDSA_SIGNING_SESSION_READY=`unlock.signing_session.ecdsa.ready`,e.STEP_06_SESSION_READY=`unlock.session.ready`,e.STEP_07_COMPLETED=`unlock.completed`,e.FAILED=`unlock.failed`,e.CANCELLED=`unlock.cancelled`,e}({}),d=function(e){return e.STEP_01_STARTED=`signing.started`,e.STEP_02_REQUEST_PREPARED=`signing.request.prepared`,e.STEP_03_NONCE_RESERVE_STARTED=`signing.nonce.reserve.started`,e.STEP_03_NONCE_RESERVE_SUCCEEDED=`signing.nonce.reserve.succeeded`,e.STEP_04_ACCOUNT_READINESS_STARTED=`signing.account.readiness.started`,e.STEP_04_ACCOUNT_READINESS_SUCCEEDED=`signing.account.readiness.succeeded`,e.STEP_04_ACCOUNT_READINESS_SKIPPED=`signing.account.readiness.skipped`,e.STEP_05_CONFIRMATION_DISPLAYED=`signing.confirmation.displayed`,e.STEP_05_CONFIRMATION_APPROVED=`signing.confirmation.approved`,e.STEP_05_CONFIRMATION_CANCELLED=`signing.confirmation.cancelled`,e.STEP_06_AUTH_WARM_SESSION_CLAIMED=`signing.auth.warm_session.claimed`,e.STEP_06_AUTH_PASSKEY_PROMPT_STARTED=`signing.auth.passkey.prompt.started`,e.STEP_06_AUTH_PASSKEY_PROMPT_SUCCEEDED=`signing.auth.passkey.prompt.succeeded`,e.STEP_06_AUTH_EMAIL_OTP_CHALLENGE_STARTED=`signing.auth.email_otp.challenge.started`,e.STEP_06_AUTH_EMAIL_OTP_CHALLENGE_SENT=`signing.auth.email_otp.challenge.sent`,e.STEP_06_AUTH_EMAIL_OTP_INPUT_REQUIRED=`signing.auth.email_otp.input.required`,e.STEP_06_AUTH_EMAIL_OTP_VERIFY_STARTED=`signing.auth.email_otp.verify.started`,e.STEP_06_AUTH_EMAIL_OTP_VERIFY_SUCCEEDED=`signing.auth.email_otp.verify.succeeded`,e.STEP_07_AUTHENTICATION_COMPLETE=`signing.authentication.complete`,e.STEP_08_SIGNER_PREPARE_STARTED=`signing.signer.prepare.started`,e.STEP_08_SIGNER_PREPARE_SUCCEEDED=`signing.signer.prepare.succeeded`,e.STEP_08_PRESIGN_REFILL_SCHEDULED=`signing.presign.refill.scheduled`,e.STEP_09_THRESHOLD_SESSION_RECONNECT_STARTED=`signing.threshold_session.reconnect.started`,e.STEP_09_THRESHOLD_SESSION_RECONNECT_SUCCEEDED=`signing.threshold_session.reconnect.succeeded`,e.STEP_10_COMMIT_QUEUED=`signing.commit.queued`,e.STEP_10_COMMIT_STARTED=`signing.commit.started`,e.STEP_10_COMMIT_SUCCEEDED=`signing.commit.succeeded`,e.STEP_11_TRANSACTION_SIGNED=`signing.transaction.signed`,e.STEP_11_REMAINING_SPEND_UPDATED=`signing.remaining_spend.updated`,e.STEP_12_BROADCAST_STARTED=`signing.broadcast.started`,e.STEP_12_BROADCAST_ACCEPTED=`signing.broadcast.accepted`,e.STEP_12_BROADCAST_REJECTED=`signing.broadcast.rejected`,e.STEP_13_NONCE_RECONCILE_STARTED=`signing.nonce.reconcile.started`,e.STEP_13_NONCE_RECONCILE_SUCCEEDED=`signing.nonce.reconcile.succeeded`,e.STEP_13_RECEIPT_FINALIZED=`signing.receipt.finalized`,e.STEP_13_RECEIPT_REVERTED=`signing.receipt.reverted`,e.STEP_13_TRANSACTION_DROPPED=`signing.transaction.dropped`,e.STEP_13_TRANSACTION_REPLACED=`signing.transaction.replaced`,e.STEP_13_BROADCAST_SKIPPED=`signing.broadcast.skipped`,e.STEP_14_APP_STATE_SYNC_STARTED=`signing.app_state.sync.started`,e.STEP_14_APP_STATE_SYNC_SUCCEEDED=`signing.app_state.sync.succeeded`,e.STEP_15_COMPLETED=`signing.completed`,e.FAILED=`signing.failed`,e.CANCELLED=`signing.cancelled`,e}({}),f=function(e){return e.STEP_01_QR_PREPARE_STARTED=`link_device.qr.prepare.started`,e.STEP_02_QR_SCAN_STARTED=`link_device.qr.scan.started`,e.FAILED=`link_device.failed`,e.CANCELLED=`link_device.cancelled`,e}({}),p=function(e){return e.STEP_01_STARTED=`account_sync.started`,e.STEP_02_PASSKEY_PROMPT_STARTED=`account_sync.auth.passkey.prompt.started`,e.STEP_02_PASSKEY_PROMPT_SUCCEEDED=`account_sync.auth.passkey.prompt.succeeded`,e.STEP_03_RELAY_VERIFY_STARTED=`account_sync.relay.verify.started`,e.STEP_03_RELAY_VERIFY_SUCCEEDED=`account_sync.relay.verify.succeeded`,e.STEP_04_AUTHENTICATOR_SAVED=`account_sync.authenticator.saved`,e.STEP_05_THRESHOLD_SESSION_READY=`account_sync.threshold_session.ready`,e.STEP_06_COMPLETED=`account_sync.completed`,e.FAILED=`account_sync.failed`,e.CANCELLED=`account_sync.cancelled`,e}({}),m=function(e){return e.STEP_01_STARTED=`key_export.started`,e.STEP_02_AUTH_PASSKEY_PROMPT_STARTED=`key_export.auth.passkey.prompt.started`,e.STEP_02_AUTH_PASSKEY_PROMPT_SUCCEEDED=`key_export.auth.passkey.prompt.succeeded`,e.STEP_02_AUTH_EMAIL_OTP_INPUT_REQUIRED=`key_export.auth.email_otp.input.required`,e.STEP_03_MATERIAL_PREPARE_STARTED=`key_export.material.prepare.started`,e.STEP_03_MATERIAL_PREPARE_SUCCEEDED=`key_export.material.prepare.succeeded`,e.STEP_04_VIEWER_OPENED=`key_export.viewer.opened`,e.STEP_05_VIEWER_CLOSED=`key_export.viewer.closed`,e.STEP_06_COMPLETED=`key_export.completed`,e.FAILED=`key_export.failed`,e.CANCELLED=`key_export.cancelled`,e}({});function h(n){if(n.phase===f.FAILED||n.status===`failed`)return{kind:`failed`};if(n.phase===f.CANCELLED||n.status===`cancelled`)return{kind:`cancelled`};if(n.phase!==f.STEP_02_QR_SCAN_STARTED||n.status!==`succeeded`)return{kind:`pending`};let r=e(String(n.walletId??``)),i=t(n.data?.enrollmentId);return r.ok&&i.ok?{kind:`active`,walletId:r.value}:{kind:`invalid_active`}}const g={[l.STEP_01_STARTED]:1,[l.STEP_02_ACCOUNT_PREFLIGHT_STARTED]:2,[l.STEP_02_ACCOUNT_PREFLIGHT_SUCCEEDED]:2,[l.STEP_03_SESSION_EXCHANGE_STARTED]:3,[l.STEP_03_SESSION_EXCHANGE_SUCCEEDED]:3,[l.STEP_04_PASSKEY_CREATE_STARTED]:4,[l.STEP_04_PASSKEY_CREATE_SUCCEEDED]:4,[l.STEP_04_OTP_CHALLENGE_STARTED]:4,[l.STEP_04_OTP_CHALLENGE_SENT]:4,[l.STEP_04_OTP_INPUT_REQUIRED]:4,[l.STEP_04_OTP_VERIFY_STARTED]:4,[l.STEP_04_OTP_VERIFY_SUCCEEDED]:4,[l.STEP_05_ED25519_SIGNER_PREPARE_STARTED]:5,[l.STEP_05_ED25519_SIGNER_PREPARE_SUCCEEDED]:5,[l.STEP_05_ED25519_SIGNER_PROVISION_STARTED]:5,[l.STEP_05_ED25519_SIGNER_PROVISION_SUCCEEDED]:5,[l.STEP_05_ED25519_SIGNER_PROVISION_SKIPPED]:5,[l.STEP_06_RELAY_BOOTSTRAP_STARTED]:6,[l.STEP_06_RELAY_BOOTSTRAP_SUCCEEDED]:6,[l.STEP_07_ACCOUNT_VERIFY_STARTED]:7,[l.STEP_07_ACCOUNT_VERIFY_SUCCEEDED]:7,[l.STEP_08_STORAGE_PERSIST_STARTED]:8,[l.STEP_08_STORAGE_PERSIST_SUCCEEDED]:8,[l.STEP_09_EMAIL_OTP_SIGNER_ENROLL_STARTED]:9,[l.STEP_09_EMAIL_OTP_SIGNER_ENROLL_SUCCEEDED]:9,[l.STEP_10_ECDSA_SIGNER_PROVISION_STARTED]:10,[l.STEP_10_ECDSA_SIGNER_PROVISION_SUCCEEDED]:10,[l.STEP_10_ECDSA_SIGNER_PROVISION_SKIPPED]:10,[l.STEP_10_ECDSA_SIGNER_BOOTSTRAP_STARTED]:10,[l.STEP_10_ECDSA_SIGNER_BOOTSTRAP_SUCCEEDED]:10,[l.STEP_11_COMPLETED]:11,[l.FAILED]:0,[l.CANCELLED]:0,[u.STEP_01_STARTED]:1,[u.STEP_02_ACCOUNT_LOOKUP_STARTED]:2,[u.STEP_02_ACCOUNT_LOOKUP_SUCCEEDED]:2,[u.STEP_03_PASSKEY_CHALLENGE_STARTED]:3,[u.STEP_03_PASSKEY_PROMPT_STARTED]:3,[u.STEP_03_PASSKEY_PROMPT_SUCCEEDED]:3,[u.STEP_03_EMAIL_OTP_CHALLENGE_STARTED]:3,[u.STEP_03_EMAIL_OTP_CHALLENGE_SENT]:3,[u.STEP_03_EMAIL_OTP_INPUT_REQUIRED]:3,[u.STEP_03_EMAIL_OTP_VERIFY_STARTED]:3,[u.STEP_03_EMAIL_OTP_VERIFY_SUCCEEDED]:3,[u.STEP_04_WALLET_UNLOCK_EXCHANGE_STARTED]:4,[u.STEP_04_WALLET_UNLOCK_EXCHANGE_SUCCEEDED]:4,[u.STEP_04_WALLET_UNLOCK_EXCHANGE_SKIPPED]:4,[u.STEP_05_SIGNING_SESSION_WARMUP_STARTED]:5,[u.STEP_05_ED25519_SIGNING_SESSION_READY]:5,[u.STEP_05_ECDSA_SIGNING_SESSION_READY]:5,[u.STEP_06_SESSION_READY]:6,[u.STEP_07_COMPLETED]:7,[u.FAILED]:0,[u.CANCELLED]:0,[d.STEP_01_STARTED]:1,[d.STEP_02_REQUEST_PREPARED]:2,[d.STEP_03_NONCE_RESERVE_STARTED]:3,[d.STEP_03_NONCE_RESERVE_SUCCEEDED]:3,[d.STEP_04_ACCOUNT_READINESS_STARTED]:4,[d.STEP_04_ACCOUNT_READINESS_SUCCEEDED]:4,[d.STEP_04_ACCOUNT_READINESS_SKIPPED]:4,[d.STEP_05_CONFIRMATION_DISPLAYED]:5,[d.STEP_05_CONFIRMATION_APPROVED]:5,[d.STEP_05_CONFIRMATION_CANCELLED]:5,[d.STEP_06_AUTH_WARM_SESSION_CLAIMED]:6,[d.STEP_06_AUTH_PASSKEY_PROMPT_STARTED]:6,[d.STEP_06_AUTH_PASSKEY_PROMPT_SUCCEEDED]:6,[d.STEP_06_AUTH_EMAIL_OTP_CHALLENGE_STARTED]:6,[d.STEP_06_AUTH_EMAIL_OTP_CHALLENGE_SENT]:6,[d.STEP_06_AUTH_EMAIL_OTP_INPUT_REQUIRED]:6,[d.STEP_06_AUTH_EMAIL_OTP_VERIFY_STARTED]:6,[d.STEP_06_AUTH_EMAIL_OTP_VERIFY_SUCCEEDED]:6,[d.STEP_07_AUTHENTICATION_COMPLETE]:7,[d.STEP_08_SIGNER_PREPARE_STARTED]:8,[d.STEP_08_SIGNER_PREPARE_SUCCEEDED]:8,[d.STEP_08_PRESIGN_REFILL_SCHEDULED]:8,[d.STEP_09_THRESHOLD_SESSION_RECONNECT_STARTED]:9,[d.STEP_09_THRESHOLD_SESSION_RECONNECT_SUCCEEDED]:9,[d.STEP_10_COMMIT_QUEUED]:10,[d.STEP_10_COMMIT_STARTED]:10,[d.STEP_10_COMMIT_SUCCEEDED]:10,[d.STEP_11_TRANSACTION_SIGNED]:11,[d.STEP_11_REMAINING_SPEND_UPDATED]:11,[d.STEP_12_BROADCAST_STARTED]:12,[d.STEP_12_BROADCAST_ACCEPTED]:12,[d.STEP_12_BROADCAST_REJECTED]:12,[d.STEP_13_NONCE_RECONCILE_STARTED]:13,[d.STEP_13_NONCE_RECONCILE_SUCCEEDED]:13,[d.STEP_13_RECEIPT_FINALIZED]:13,[d.STEP_13_RECEIPT_REVERTED]:13,[d.STEP_13_TRANSACTION_DROPPED]:13,[d.STEP_13_TRANSACTION_REPLACED]:13,[d.STEP_13_BROADCAST_SKIPPED]:13,[d.STEP_14_APP_STATE_SYNC_STARTED]:14,[d.STEP_14_APP_STATE_SYNC_SUCCEEDED]:14,[d.STEP_15_COMPLETED]:15,[d.FAILED]:0,[d.CANCELLED]:0,[f.STEP_01_QR_PREPARE_STARTED]:1,[f.STEP_02_QR_SCAN_STARTED]:2,[f.FAILED]:0,[f.CANCELLED]:0,[p.STEP_01_STARTED]:1,[p.STEP_02_PASSKEY_PROMPT_STARTED]:2,[p.STEP_02_PASSKEY_PROMPT_SUCCEEDED]:2,[p.STEP_03_RELAY_VERIFY_STARTED]:3,[p.STEP_03_RELAY_VERIFY_SUCCEEDED]:3,[p.STEP_04_AUTHENTICATOR_SAVED]:4,[p.STEP_05_THRESHOLD_SESSION_READY]:5,[p.STEP_06_COMPLETED]:6,[p.FAILED]:0,[p.CANCELLED]:0,[m.STEP_01_STARTED]:1,[m.STEP_02_AUTH_PASSKEY_PROMPT_STARTED]:2,[m.STEP_02_AUTH_PASSKEY_PROMPT_SUCCEEDED]:2,[m.STEP_02_AUTH_EMAIL_OTP_INPUT_REQUIRED]:2,[m.STEP_03_MATERIAL_PREPARE_STARTED]:3,[m.STEP_03_MATERIAL_PREPARE_SUCCEEDED]:3,[m.STEP_04_VIEWER_OPENED]:4,[m.STEP_05_VIEWER_CLOSED]:5,[m.STEP_06_COMPLETED]:6,[m.FAILED]:0,[m.CANCELLED]:0},_={[l.STEP_01_STARTED]:`Starting registration`,[l.STEP_02_ACCOUNT_PREFLIGHT_STARTED]:`Checking account details`,[l.STEP_02_ACCOUNT_PREFLIGHT_SUCCEEDED]:`Account details ready`,[l.STEP_03_SESSION_EXCHANGE_STARTED]:`Checking registration session`,[l.STEP_03_SESSION_EXCHANGE_SUCCEEDED]:`Registration session ready`,[l.STEP_04_PASSKEY_CREATE_STARTED]:`Create your passkey`,[l.STEP_04_PASSKEY_CREATE_SUCCEEDED]:`Passkey created`,[l.STEP_04_OTP_CHALLENGE_STARTED]:`Sending registration email code`,[l.STEP_04_OTP_CHALLENGE_SENT]:`Registration email code sent`,[l.STEP_04_OTP_INPUT_REQUIRED]:`Enter the registration code`,[l.STEP_04_OTP_VERIFY_STARTED]:`Verifying registration code`,[l.STEP_04_OTP_VERIFY_SUCCEEDED]:`Registration email verified`,[l.STEP_05_ED25519_SIGNER_PREPARE_STARTED]:`Preparing NEAR signer`,[l.STEP_05_ED25519_SIGNER_PREPARE_SUCCEEDED]:`NEAR signer ready`,[l.STEP_05_ED25519_SIGNER_PROVISION_STARTED]:`Preparing NEAR signer`,[l.STEP_05_ED25519_SIGNER_PROVISION_SUCCEEDED]:`NEAR signer ready`,[l.STEP_05_ED25519_SIGNER_PROVISION_SKIPPED]:`NEAR signer setup skipped`,[l.STEP_06_RELAY_BOOTSTRAP_STARTED]:`Creating wallet account`,[l.STEP_06_RELAY_BOOTSTRAP_SUCCEEDED]:`Wallet account created`,[l.STEP_07_ACCOUNT_VERIFY_STARTED]:`Verifying wallet account`,[l.STEP_07_ACCOUNT_VERIFY_SUCCEEDED]:`Wallet account verified`,[l.STEP_08_STORAGE_PERSIST_STARTED]:`Saving wallet metadata`,[l.STEP_08_STORAGE_PERSIST_SUCCEEDED]:`Wallet metadata saved`,[l.STEP_09_EMAIL_OTP_SIGNER_ENROLL_STARTED]:`Securing Email OTP registration`,[l.STEP_09_EMAIL_OTP_SIGNER_ENROLL_SUCCEEDED]:`Email OTP registration secured`,[l.STEP_10_ECDSA_SIGNER_PROVISION_STARTED]:`Preparing EVM signing session`,[l.STEP_10_ECDSA_SIGNER_PROVISION_SUCCEEDED]:`EVM signing session ready`,[l.STEP_10_ECDSA_SIGNER_PROVISION_SKIPPED]:`EVM signer setup skipped`,[l.STEP_10_ECDSA_SIGNER_BOOTSTRAP_STARTED]:`Preparing EVM signer`,[l.STEP_10_ECDSA_SIGNER_BOOTSTRAP_SUCCEEDED]:`EVM signer ready`,[l.STEP_11_COMPLETED]:`Registration complete`,[l.FAILED]:`Registration failed`,[l.CANCELLED]:`Registration cancelled`,[u.STEP_01_STARTED]:`Unlocking wallet`,[u.STEP_02_ACCOUNT_LOOKUP_STARTED]:`Finding wallet account`,[u.STEP_02_ACCOUNT_LOOKUP_SUCCEEDED]:`Wallet account found`,[u.STEP_03_PASSKEY_CHALLENGE_STARTED]:`Preparing passkey check`,[u.STEP_03_PASSKEY_PROMPT_STARTED]:`Confirm with passkey`,[u.STEP_03_PASSKEY_PROMPT_SUCCEEDED]:`Passkey confirmed`,[u.STEP_03_EMAIL_OTP_CHALLENGE_STARTED]:`Sending email code`,[u.STEP_03_EMAIL_OTP_CHALLENGE_SENT]:`Email code sent`,[u.STEP_03_EMAIL_OTP_INPUT_REQUIRED]:`Enter the email code`,[u.STEP_03_EMAIL_OTP_VERIFY_STARTED]:`Verifying email code`,[u.STEP_03_EMAIL_OTP_VERIFY_SUCCEEDED]:`Email verified`,[u.STEP_04_WALLET_UNLOCK_EXCHANGE_STARTED]:`Creating wallet session`,[u.STEP_04_WALLET_UNLOCK_EXCHANGE_SUCCEEDED]:`Wallet session ready`,[u.STEP_04_WALLET_UNLOCK_EXCHANGE_SKIPPED]:`Wallet session skipped`,[u.STEP_05_SIGNING_SESSION_WARMUP_STARTED]:`Preparing transaction signing`,[u.STEP_05_ED25519_SIGNING_SESSION_READY]:`NEAR signing authorization ready`,[u.STEP_05_ECDSA_SIGNING_SESSION_READY]:`EVM signing session ready`,[u.STEP_06_SESSION_READY]:`Wallet session ready`,[u.STEP_07_COMPLETED]:`Wallet unlocked`,[u.FAILED]:`Wallet unlock failed`,[u.CANCELLED]:`Wallet unlock cancelled`,[d.STEP_01_STARTED]:`Preparing transaction`,[d.STEP_02_REQUEST_PREPARED]:`Transaction ready for review`,[d.STEP_03_NONCE_RESERVE_STARTED]:`Reserving nonce`,[d.STEP_03_NONCE_RESERVE_SUCCEEDED]:`Nonce reserved`,[d.STEP_04_ACCOUNT_READINESS_STARTED]:`Checking account setup`,[d.STEP_04_ACCOUNT_READINESS_SUCCEEDED]:`Account setup verified`,[d.STEP_04_ACCOUNT_READINESS_SKIPPED]:`Account setup check skipped`,[d.STEP_05_CONFIRMATION_DISPLAYED]:`Review transaction`,[d.STEP_05_CONFIRMATION_APPROVED]:`Transaction approved`,[d.STEP_05_CONFIRMATION_CANCELLED]:`Transaction rejected`,[d.STEP_06_AUTH_WARM_SESSION_CLAIMED]:`Signing session authorized`,[d.STEP_06_AUTH_PASSKEY_PROMPT_STARTED]:`Confirm with passkey`,[d.STEP_06_AUTH_PASSKEY_PROMPT_SUCCEEDED]:`Passkey confirmed`,[d.STEP_06_AUTH_EMAIL_OTP_CHALLENGE_STARTED]:`Sending email code`,[d.STEP_06_AUTH_EMAIL_OTP_CHALLENGE_SENT]:`Email code sent`,[d.STEP_06_AUTH_EMAIL_OTP_INPUT_REQUIRED]:`Enter the email code`,[d.STEP_06_AUTH_EMAIL_OTP_VERIFY_STARTED]:`Verifying email code`,[d.STEP_06_AUTH_EMAIL_OTP_VERIFY_SUCCEEDED]:`Email verified`,[d.STEP_07_AUTHENTICATION_COMPLETE]:`Authentication complete`,[d.STEP_08_SIGNER_PREPARE_STARTED]:`Preparing secure signer`,[d.STEP_08_SIGNER_PREPARE_SUCCEEDED]:`Secure signer ready`,[d.STEP_08_PRESIGN_REFILL_SCHEDULED]:`Preparing future signatures`,[d.STEP_09_THRESHOLD_SESSION_RECONNECT_STARTED]:`Preparing signing session`,[d.STEP_09_THRESHOLD_SESSION_RECONNECT_SUCCEEDED]:`Secure signer loaded`,[d.STEP_10_COMMIT_QUEUED]:`Waiting to sign`,[d.STEP_10_COMMIT_STARTED]:`Signing transaction`,[d.STEP_10_COMMIT_SUCCEEDED]:`Transaction signature ready`,[d.STEP_11_TRANSACTION_SIGNED]:`Transaction signed`,[d.STEP_11_REMAINING_SPEND_UPDATED]:`Signing spend updated`,[d.STEP_12_BROADCAST_STARTED]:`Broadcasting transaction`,[d.STEP_12_BROADCAST_ACCEPTED]:`Transaction submitted`,[d.STEP_12_BROADCAST_REJECTED]:`Transaction broadcast failed`,[d.STEP_13_NONCE_RECONCILE_STARTED]:`Checking nonce state`,[d.STEP_13_NONCE_RECONCILE_SUCCEEDED]:`Nonce state updated`,[d.STEP_13_RECEIPT_FINALIZED]:`Transaction finalized`,[d.STEP_13_RECEIPT_REVERTED]:`Transaction reverted`,[d.STEP_13_TRANSACTION_DROPPED]:`Transaction dropped`,[d.STEP_13_TRANSACTION_REPLACED]:`Transaction replaced`,[d.STEP_13_BROADCAST_SKIPPED]:`Broadcast skipped`,[d.STEP_14_APP_STATE_SYNC_STARTED]:`Refreshing app state`,[d.STEP_14_APP_STATE_SYNC_SUCCEEDED]:`App state refreshed`,[d.STEP_15_COMPLETED]:`Transaction complete`,[d.FAILED]:`Transaction signing failed`,[d.CANCELLED]:`Transaction signing cancelled`,[f.STEP_01_QR_PREPARE_STARTED]:`Preparing device link`,[f.STEP_02_QR_SCAN_STARTED]:`Scanning QR code`,[f.FAILED]:`Device link failed`,[f.CANCELLED]:`Device link cancelled`,[p.STEP_01_STARTED]:`Starting account sync`,[p.STEP_02_PASSKEY_PROMPT_STARTED]:`Confirm with passkey`,[p.STEP_02_PASSKEY_PROMPT_SUCCEEDED]:`Passkey confirmed`,[p.STEP_03_RELAY_VERIFY_STARTED]:`Verifying account access`,[p.STEP_03_RELAY_VERIFY_SUCCEEDED]:`Account access verified`,[p.STEP_04_AUTHENTICATOR_SAVED]:`Passkey saved locally`,[p.STEP_05_THRESHOLD_SESSION_READY]:`Signing session ready`,[p.STEP_06_COMPLETED]:`Account synced`,[p.FAILED]:`Account sync failed`,[p.CANCELLED]:`Account sync cancelled`,[m.STEP_01_STARTED]:`Preparing key export`,[m.STEP_02_AUTH_PASSKEY_PROMPT_STARTED]:`Confirm with passkey`,[m.STEP_02_AUTH_PASSKEY_PROMPT_SUCCEEDED]:`Passkey confirmed`,[m.STEP_02_AUTH_EMAIL_OTP_INPUT_REQUIRED]:`Enter the email code`,[m.STEP_03_MATERIAL_PREPARE_STARTED]:`Preparing key material`,[m.STEP_03_MATERIAL_PREPARE_SUCCEEDED]:`Key material ready`,[m.STEP_04_VIEWER_OPENED]:`Review private key`,[m.STEP_05_VIEWER_CLOSED]:`Key export closed`,[m.STEP_06_COMPLETED]:`Key export complete`,[m.FAILED]:`Key export failed`,[m.CANCELLED]:`Key export cancelled`};function v(e){let t=e.interaction??(e.status===`failed`||e.status===`cancelled`?{kind:`none`,overlay:`hide`}:void 0);return{...e,...t?{interaction:t}:{},version:2,step:g[e.phase],message:e.message??_[e.phase]}}function y(e){return v({...e,flow:`registration`})}function b(e){return v({...e,flow:`unlock`})}function x(e){return v({...e,flow:`link_device`})}function S(e){return v({...e,flow:`account_sync`})}function C(e){return v({...e,flow:`key_export`})}function w(e){return v({...e,flow:`signing`})}function T(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.version===2&&typeof t.flow==`string`}export{T as _,n as a,h as c,x as d,r as f,b as g,c as h,l as i,S as l,w as m,m as n,d as o,y as p,f as r,u as s,p as t,C as u,s as v};
|