@seams/wallet 0.27.0 → 0.29.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 +29 -4
- package/dist/.build-inputs.sha256 +1 -1
- package/dist/esm/SeamsWeb/publicApi/createPublicApi.js +11 -0
- package/dist/esm/SeamsWeb/publicApi/near.js +3 -0
- package/dist/esm/SeamsWeb/publicApi/ownerNearOperation.js +175 -0
- package/dist/esm/SeamsWeb/walletIframe/client/nearCommands.js +4 -0
- package/dist/esm/SeamsWeb/walletIframe/client/ownerNearOperation.js +67 -0
- package/dist/esm/SeamsWeb/walletIframe/client/progress/on-events-progress-bus.js +27 -17
- package/dist/esm/SeamsWeb/walletIframe/client/router.js +63 -2
- package/dist/esm/SeamsWeb/walletIframe/client/sessionCommands.js +20 -0
- package/dist/esm/SeamsWeb/walletIframe/host/walletMutationGuard.js +6 -0
- package/dist/esm/SeamsWeb/walletIframe/shared/exactSessionState.js +42 -5
- package/dist/esm/SeamsWeb/walletIframe/shared/messages.js +1 -1
- package/dist/esm/SeamsWeb/walletIframe/shared/ownerNearOperation.js +152 -0
- package/dist/esm/core/accountData/near/accountProjection.js +1 -1
- package/dist/esm/core/authMethods/plugins.js +8 -2
- package/dist/esm/core/indexedDB/seamsWalletDB/repositories.js +4 -3
- package/dist/esm/core/rpcClients/relayer/walletRegistration.js +1 -1
- package/dist/esm/core/signingEngine/flows/registration/accountLifecycle.js +1 -1
- package/dist/esm/core/signingEngine/flows/shared/signingConfirmation.js +1 -1
- package/dist/esm/core/signingEngine/flows/signEvmFamily/signEvmFamily.js +1 -1
- package/dist/esm/core/signingEngine/flows/signEvmFamily/signingFlow.js +1 -1
- package/dist/esm/core/signingEngine/flows/signNear/shared/ed25519YaoNormalSigning.js +2 -2
- package/dist/esm/core/signingEngine/flows/signNear/signDelegate.js +2 -2
- package/dist/esm/core/signingEngine/flows/signNear/signNear.js +3 -8
- package/dist/esm/core/signingEngine/flows/signNear/signNep413.js +1 -1
- package/dist/esm/core/signingEngine/flows/signNear/signTransactions.js +3 -4
- package/dist/esm/core/signingEngine/session/identity/exactSigningLaneIdentity.js +1 -1
- package/dist/esm/core/ui/messages.js +5 -0
- package/dist/esm/index.js +3 -2
- package/dist/esm/react/boundWallet.js +24 -0
- package/dist/esm/react/components/AccountMenuButton/AccountMenuButtonView.js +35 -22
- package/dist/esm/react/components/AccountMenuButton/AccountSettingsDialog.js +157 -0
- package/dist/esm/react/components/AccountMenuButton/AuthenticationMethodsModal.js +13 -1
- package/dist/esm/react/components/AccountMenuButton/ExternalWalletSettings.js +46 -0
- package/dist/esm/react/components/AccountMenuButton/LinkedDevicesModal.js +14 -2
- package/dist/esm/react/components/AccountMenuButton/WalletSettingsLayout.js +1 -1
- package/dist/esm/react/components/AccountMenuButton/Web3AuthProfileButton.css +154 -5
- package/dist/esm/react/components/AccountMenuButton/index.js +7 -3
- package/dist/esm/react/context/reactLoginStateBuilders.js +20 -0
- package/dist/esm/react/context/useLoginStateRefresher.js +1 -0
- package/dist/esm/react/hooks/useAccountInput.js +1 -1
- package/dist/esm/react/hooks/useOwnerNearOperation.js +10 -0
- package/dist/esm/react/index.js +3 -2
- package/dist/esm/react/styles/styles.css +154 -5
- package/dist/esm/sdk/{ConfirmationDrawer-AZruQmhP.js → ConfirmationDrawer-BRnd5SEf.js} +1 -1
- package/dist/esm/sdk/NonceCoordinator-CNXYrOoy.js +1 -0
- package/dist/{public/sdk/SeamsWordmark-DwvPx2UA.js → esm/sdk/SeamsWordmark-CeEi2RlU.js} +1 -1
- package/dist/esm/sdk/accountLifecycle-B5a9SCM7.js +1 -0
- package/dist/esm/sdk/{adapters-d9yh1bdC.js → adapters-B2k8y0MB.js} +1 -1
- package/dist/esm/sdk/appearance-token-vars-DkF3EBbF.js +1 -0
- package/dist/esm/sdk/authorization-gVWwKwav.js +1 -0
- package/dist/esm/sdk/clientSessionPersistenceState-BxpITYM_.js +1 -0
- package/dist/esm/sdk/{collectAuthenticationCredentialForChallengeB64u-I4wq8OGq.js → collectAuthenticationCredentialForChallengeB64u-BoFVpdRS.js} +1 -1
- package/dist/esm/sdk/{commitQueue-CYruPlkm.js → commitQueue-C1wkey4q.js} +1 -1
- package/dist/esm/sdk/configBuilder-DpChXfDO.js +1 -0
- package/dist/esm/sdk/{configuration-DBEc3bsj.js → configuration-BAad7ngq.js} +1 -1
- package/dist/esm/sdk/confirm-ui-Dx6c4-Rk.js +2 -0
- package/dist/esm/sdk/{device-linking-DiCNt3iA.js → device-linking-_o3_fgiG.js} +1 -1
- package/dist/esm/sdk/{deviceLinkApproval-CfEiotVt.js → deviceLinkApproval-CObsEWBa.js} +1 -1
- package/dist/esm/sdk/{display-D0EPmU4w.js → display-CUWg48tD.js} +1 -1
- package/dist/{public/sdk/ecdsaCapabilityManifest-DAJEVjlP.js → esm/sdk/ecdsaCapabilityManifest--1Ztngfx.js} +1 -1
- package/dist/{public/sdk/ecdsaDerivationClientWasm-AYOJgTJm.js → esm/sdk/ecdsaDerivationClientWasm-DJh2uN-q.js} +1 -1
- package/dist/esm/sdk/ecdsaDerivationExport-BUUUGc6o.js +1 -0
- package/dist/esm/sdk/{ecdsaWalletRecords-WLyq414E.js → ecdsaWalletRecords-CKaXfsVu.js} +1 -1
- package/dist/esm/sdk/ed25519OperationFingerprint-Dev4P6Og.js +1 -0
- package/dist/{public/sdk/emailOtpEcdsaDerivationIdentity-HFQXc1Yw.js → esm/sdk/emailOtpEcdsaDerivationIdentity-Qd4pBwHv.js} +1 -1
- package/dist/esm/sdk/{enrichDisplayModelWithAbi-O6Mw4i2E.js → enrichDisplayModelWithAbi-JeAcpa7r.js} +1 -1
- package/dist/esm/sdk/{evmCryptoWasm-BUPb4hBH.js → evmCryptoWasm-CeH6Qeaa.js} +1 -1
- package/dist/esm/sdk/{export-viewer-host-BtrKVXxu.js → export-viewer-host-O0OV1Oou.js} +1 -1
- package/dist/esm/sdk/exportKeypairOperation-DkqY9Bpf.js +1 -0
- package/dist/esm/sdk/host-BeE2dIU4.js +1 -0
- package/dist/{public/sdk/icons-BlMXolHv.js → esm/sdk/icons-pSZJ5Xrm.js} +1 -1
- package/dist/esm/sdk/indexedDB-CA4tGqkr.js +1 -0
- package/dist/esm/sdk/{intentDigest-HvRsBQ1z.js → intentDigest-gM3r4SVX.js} +1 -1
- package/dist/esm/sdk/{lanes-BU-fGqY4.js → lanes-vBKm6yBJ.js} +1 -1
- package/dist/esm/sdk/{localOnly-BATWJj78.js → localOnly-U_MucUAe.js} +1 -1
- package/dist/{public/sdk/mountExportPrivateKeySurface-CyHU8bVc.js → esm/sdk/mountExportPrivateKeySurface-C2-fnvP6.js} +1 -1
- package/dist/{public/sdk/mountRecoveryCodeBackupSurface-C7aglQxf.js → esm/sdk/mountRecoveryCodeBackupSurface-C_tJNPJX.js} +1 -1
- package/dist/esm/sdk/nearEd25519YaoSigningPreparation-CnbgQfZc.js +1 -0
- package/dist/esm/sdk/{nonceLaneKeys-BF_UpvIy.js → nonceLaneKeys-DtBpxubF.js} +1 -1
- package/dist/esm/sdk/{normalization-Df9fZWJC.js → normalization-DmfGvZ_3.js} +1 -1
- package/dist/esm/sdk/ownerNearOperation-DjNDxW3_.js +1 -0
- package/dist/{public/sdk/pendingWalletRecoveryCodeBackup-Cjx-X-pP.js → esm/sdk/pendingWalletRecoveryCodeBackup-DXFrQmO5.js} +1 -1
- package/dist/esm/sdk/{presignaturePool-BbvqRWYw.js → presignaturePool-Dq4RhzXn.js} +1 -1
- package/dist/{public/sdk/recovery-entrypoint-DJbMDC_m.js → esm/sdk/recovery-entrypoint-s9OoKBcl.js} +1 -1
- package/dist/esm/sdk/registration-CTtTocyo.js +1 -0
- package/dist/esm/sdk/{registration-HSwOHZOo.js → registration-D3p7muCc.js} +1 -1
- package/dist/esm/sdk/{registrationAccounts-4r74gX1l.js → registrationAccounts-Bso0ntMs.js} +1 -1
- package/dist/{public/sdk/registrationIntent-Do1tD1V7.js → esm/sdk/registrationIntent-C1-Kyx_-.js} +1 -1
- package/dist/esm/sdk/{registrationSignerPlan-DK2b3N_p.js → registrationSignerPlan-CeMidFme.js} +1 -1
- package/dist/{public/sdk/requireStepUpAuth-COqCGb1i.js → esm/sdk/requireStepUpAuth-iVo6h_U-.js} +1 -1
- package/dist/esm/sdk/resealedEnvelopeResult-DXDo-72P.js +1 -0
- package/dist/esm/sdk/{routerAbNormalSigning-D-UZmCBS.js → routerAbNormalSigning-DVFFkNhJ.js} +1 -1
- package/dist/esm/sdk/runtime-auth-Dsmw_dUA.js +1 -0
- package/dist/esm/sdk/runtime-device-link-qmYvGep9.js +1 -0
- package/dist/esm/sdk/runtime-ecdsa-tempo-Zh95TuLV.js +1 -0
- package/dist/esm/sdk/runtime-email-otp-CnLuW4H1.js +1 -0
- package/dist/esm/sdk/runtime-export-m8lvrXtw.js +1 -0
- package/dist/esm/sdk/runtime-near-BiXzXXhH.js +1 -0
- package/dist/esm/sdk/runtime-preferences-DlKHDIjb.js +1 -0
- package/dist/esm/sdk/runtime-recovery-C6lS71Jp.js +1 -0
- package/dist/esm/sdk/{runtime-recovery-codes-DeUjQsxZ.js → runtime-recovery-codes-B033ake_.js} +1 -1
- package/dist/esm/sdk/runtimeContext-RNS2E5wy.js +7 -0
- package/dist/{public/sdk/secp256k1-CE7-q9Sn.js → esm/sdk/secp256k1-DPeaOjM0.js} +1 -1
- package/dist/esm/sdk/signEvmFamily-Cksw3RpU.js +1 -0
- package/dist/esm/sdk/{signEvmFamilyWithUiConfirmForTempo-CrMIAXUe.js → signEvmFamilyWithUiConfirmForTempo-B7p9UVix.js} +1 -1
- package/dist/esm/sdk/{signEvmWithUiConfirm-CGrLtMV6.js → signEvmWithUiConfirm-B14zYdwE.js} +1 -1
- package/dist/esm/sdk/signNear-D0rFEYP1.js +1 -0
- package/dist/esm/sdk/{signatureUses-kSrUHSSH.js → signatureUses-BLOoPRsb.js} +1 -1
- package/dist/{public/sdk/signingFlow-BcetvUeS.js → esm/sdk/signingFlow-Bd1X0e-1.js} +2 -2
- package/dist/{public/sdk/signingQueue-dMFOFOP5.js → esm/sdk/signingQueue-DoUBeaCv.js} +1 -1
- package/dist/esm/sdk/{thresholdEcdsa-CqR1fFA-.js → thresholdEcdsa-BxfOZmiR.js} +1 -1
- package/dist/esm/sdk/{trace--mRP2OQc.js → trace-BnhLKxcu.js} +1 -1
- package/dist/esm/sdk/{transaction-activity-DCzHGg3b.js → transaction-activity-BXSxMp1E.js} +1 -1
- package/dist/{public/sdk/transactionState-29T9xfvL.js → esm/sdk/transactionState-G_FPe-U8.js} +1 -1
- package/dist/esm/sdk/tx-confirm-ui.js +8 -0
- package/dist/esm/sdk/{types-f7dyj5N6.js → types-A-w1cYlJ.js} +1 -1
- package/dist/esm/sdk/{unlockedEd25519ExportRootCapability-yzxQjIFd.js → unlockedEd25519ExportRootCapability-5F1egCSv.js} +1 -1
- package/dist/esm/sdk/voiceid-host.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-recovery-BZB2Vu3X.js → wallet-recovery-DXdm68_Q.js} +1 -1
- package/dist/{public/sdk/walletAuthMethodRecord-DLBB5fez.js → esm/sdk/walletAuthMethodRecord-BW-XV4fv.js} +1 -1
- package/dist/esm/sdk/{walletAuthority-BTGAuOi8.js → walletAuthority-DbGaSw7D.js} +1 -1
- package/dist/esm/sdk/{walletCapabilityBindings-D5YYB7nN.js → walletCapabilityBindings-mPx-6_r-.js} +1 -1
- package/dist/{public/sdk/walletCustodyEcdsaContinuity-C31YQ9av.js → esm/sdk/walletCustodyEcdsaContinuity-BnyL1Ryu.js} +1 -1
- package/dist/esm/sdk/{walletOwnershipGeneration-CgjCtPrV.js → walletOwnershipGeneration-BZc6UKqX.js} +1 -1
- package/dist/esm/sdk/walletRecoveryAdminProof-DdwikrW3.js +1 -0
- package/dist/esm/sdk/walletRecoveryCommit-DbAoiJp5.js +1 -0
- package/dist/{public/sdk/walletSessionAuthorizationStore-B9Vwkshr.js → esm/sdk/walletSessionAuthorizationStore-BivTUoKY.js} +1 -1
- package/dist/esm/sdk/{webauthnP256-BsQQPurm.js → webauthnP256-BGHikiNl.js} +1 -1
- package/dist/esm/shared-ts/src/auth/externalAuth.js +53 -0
- package/dist/esm/shared-ts/src/utils/index.js +2 -2
- package/dist/esm/voiceid-host.js +2 -2
- package/dist/public/headers.manifest.json +1 -1
- package/dist/public/sdk/{ConfirmationDrawer-AZruQmhP.js → ConfirmationDrawer-BRnd5SEf.js} +1 -1
- package/dist/public/sdk/NonceCoordinator-CNXYrOoy.js +1 -0
- package/dist/{esm/sdk/SeamsWordmark-DwvPx2UA.js → public/sdk/SeamsWordmark-CeEi2RlU.js} +1 -1
- package/dist/public/sdk/accountLifecycle-B5a9SCM7.js +1 -0
- package/dist/public/sdk/{adapters-d9yh1bdC.js → adapters-B2k8y0MB.js} +1 -1
- package/dist/public/sdk/appearance-token-vars-DkF3EBbF.js +1 -0
- package/dist/public/sdk/authorization-gVWwKwav.js +1 -0
- package/dist/public/sdk/clientSessionPersistenceState-BxpITYM_.js +1 -0
- package/dist/public/sdk/{collectAuthenticationCredentialForChallengeB64u-I4wq8OGq.js → collectAuthenticationCredentialForChallengeB64u-BoFVpdRS.js} +1 -1
- package/dist/public/sdk/{commitQueue-CYruPlkm.js → commitQueue-C1wkey4q.js} +1 -1
- package/dist/public/sdk/configBuilder-DpChXfDO.js +1 -0
- package/dist/public/sdk/{configuration-DBEc3bsj.js → configuration-BAad7ngq.js} +1 -1
- package/dist/public/sdk/confirm-ui-Dx6c4-Rk.js +2 -0
- package/dist/public/sdk/{device-linking-DiCNt3iA.js → device-linking-_o3_fgiG.js} +1 -1
- package/dist/public/sdk/{deviceLinkApproval-CfEiotVt.js → deviceLinkApproval-CObsEWBa.js} +1 -1
- package/dist/public/sdk/{display-D0EPmU4w.js → display-CUWg48tD.js} +1 -1
- package/dist/{esm/sdk/ecdsaCapabilityManifest-DAJEVjlP.js → public/sdk/ecdsaCapabilityManifest--1Ztngfx.js} +1 -1
- package/dist/{esm/sdk/ecdsaDerivationClientWasm-AYOJgTJm.js → public/sdk/ecdsaDerivationClientWasm-DJh2uN-q.js} +1 -1
- package/dist/public/sdk/ecdsaDerivationExport-BUUUGc6o.js +1 -0
- package/dist/public/sdk/{ecdsaWalletRecords-WLyq414E.js → ecdsaWalletRecords-CKaXfsVu.js} +1 -1
- package/dist/public/sdk/ed25519OperationFingerprint-Dev4P6Og.js +1 -0
- package/dist/{esm/sdk/emailOtpEcdsaDerivationIdentity-HFQXc1Yw.js → public/sdk/emailOtpEcdsaDerivationIdentity-Qd4pBwHv.js} +1 -1
- package/dist/public/sdk/{enrichDisplayModelWithAbi-O6Mw4i2E.js → enrichDisplayModelWithAbi-JeAcpa7r.js} +1 -1
- package/dist/public/sdk/{evmCryptoWasm-BUPb4hBH.js → evmCryptoWasm-CeH6Qeaa.js} +1 -1
- package/dist/public/sdk/{export-viewer-host-BtrKVXxu.js → export-viewer-host-O0OV1Oou.js} +1 -1
- package/dist/public/sdk/exportKeypairOperation-DkqY9Bpf.js +1 -0
- package/dist/public/sdk/host-BeE2dIU4.js +1 -0
- package/dist/{esm/sdk/icons-BlMXolHv.js → public/sdk/icons-pSZJ5Xrm.js} +1 -1
- package/dist/public/sdk/indexedDB-CA4tGqkr.js +1 -0
- package/dist/public/sdk/{intentDigest-HvRsBQ1z.js → intentDigest-gM3r4SVX.js} +1 -1
- package/dist/public/sdk/{lanes-BU-fGqY4.js → lanes-vBKm6yBJ.js} +1 -1
- package/dist/public/sdk/{localOnly-BATWJj78.js → localOnly-U_MucUAe.js} +1 -1
- package/dist/{esm/sdk/mountExportPrivateKeySurface-CyHU8bVc.js → public/sdk/mountExportPrivateKeySurface-C2-fnvP6.js} +1 -1
- package/dist/{esm/sdk/mountRecoveryCodeBackupSurface-C7aglQxf.js → public/sdk/mountRecoveryCodeBackupSurface-C_tJNPJX.js} +1 -1
- package/dist/public/sdk/nearEd25519YaoSigningPreparation-CnbgQfZc.js +1 -0
- package/dist/public/sdk/{nonceLaneKeys-BF_UpvIy.js → nonceLaneKeys-DtBpxubF.js} +1 -1
- package/dist/public/sdk/{normalization-Df9fZWJC.js → normalization-DmfGvZ_3.js} +1 -1
- package/dist/public/sdk/ownerNearOperation-DjNDxW3_.js +1 -0
- package/dist/{esm/sdk/pendingWalletRecoveryCodeBackup-Cjx-X-pP.js → public/sdk/pendingWalletRecoveryCodeBackup-DXFrQmO5.js} +1 -1
- package/dist/public/sdk/{presignaturePool-BbvqRWYw.js → presignaturePool-Dq4RhzXn.js} +1 -1
- package/dist/{esm/sdk/recovery-entrypoint-DJbMDC_m.js → public/sdk/recovery-entrypoint-s9OoKBcl.js} +1 -1
- package/dist/public/sdk/registration-CTtTocyo.js +1 -0
- package/dist/public/sdk/{registration-HSwOHZOo.js → registration-D3p7muCc.js} +1 -1
- package/dist/public/sdk/{registrationAccounts-4r74gX1l.js → registrationAccounts-Bso0ntMs.js} +1 -1
- package/dist/{esm/sdk/registrationIntent-Do1tD1V7.js → public/sdk/registrationIntent-C1-Kyx_-.js} +1 -1
- package/dist/public/sdk/{registrationSignerPlan-DK2b3N_p.js → registrationSignerPlan-CeMidFme.js} +1 -1
- package/dist/{esm/sdk/requireStepUpAuth-COqCGb1i.js → public/sdk/requireStepUpAuth-iVo6h_U-.js} +1 -1
- package/dist/public/sdk/resealedEnvelopeResult-DXDo-72P.js +1 -0
- package/dist/public/sdk/{routerAbNormalSigning-D-UZmCBS.js → routerAbNormalSigning-DVFFkNhJ.js} +1 -1
- package/dist/public/sdk/runtime-auth-Dsmw_dUA.js +1 -0
- package/dist/public/sdk/runtime-device-link-qmYvGep9.js +1 -0
- package/dist/public/sdk/runtime-ecdsa-tempo-Zh95TuLV.js +1 -0
- package/dist/public/sdk/runtime-email-otp-CnLuW4H1.js +1 -0
- package/dist/public/sdk/runtime-export-m8lvrXtw.js +1 -0
- package/dist/public/sdk/runtime-near-BiXzXXhH.js +1 -0
- package/dist/public/sdk/runtime-preferences-DlKHDIjb.js +1 -0
- package/dist/public/sdk/runtime-recovery-C6lS71Jp.js +1 -0
- package/dist/public/sdk/{runtime-recovery-codes-DeUjQsxZ.js → runtime-recovery-codes-B033ake_.js} +1 -1
- package/dist/public/sdk/runtimeContext-RNS2E5wy.js +7 -0
- package/dist/{esm/sdk/secp256k1-CE7-q9Sn.js → public/sdk/secp256k1-DPeaOjM0.js} +1 -1
- package/dist/public/sdk/signEvmFamily-Cksw3RpU.js +1 -0
- package/dist/public/sdk/{signEvmFamilyWithUiConfirmForTempo-CrMIAXUe.js → signEvmFamilyWithUiConfirmForTempo-B7p9UVix.js} +1 -1
- package/dist/public/sdk/{signEvmWithUiConfirm-CGrLtMV6.js → signEvmWithUiConfirm-B14zYdwE.js} +1 -1
- package/dist/public/sdk/signNear-D0rFEYP1.js +1 -0
- package/dist/public/sdk/{signatureUses-kSrUHSSH.js → signatureUses-BLOoPRsb.js} +1 -1
- package/dist/{esm/sdk/signingFlow-BcetvUeS.js → public/sdk/signingFlow-Bd1X0e-1.js} +2 -2
- package/dist/{esm/sdk/signingQueue-dMFOFOP5.js → public/sdk/signingQueue-DoUBeaCv.js} +1 -1
- package/dist/public/sdk/{thresholdEcdsa-CqR1fFA-.js → thresholdEcdsa-BxfOZmiR.js} +1 -1
- package/dist/public/sdk/{trace--mRP2OQc.js → trace-BnhLKxcu.js} +1 -1
- package/dist/public/sdk/{transaction-activity-DCzHGg3b.js → transaction-activity-BXSxMp1E.js} +1 -1
- package/dist/{esm/sdk/transactionState-29T9xfvL.js → public/sdk/transactionState-G_FPe-U8.js} +1 -1
- package/dist/public/sdk/tx-confirm-ui.js +8 -0
- package/dist/public/sdk/{types-f7dyj5N6.js → types-A-w1cYlJ.js} +1 -1
- package/dist/public/sdk/{unlockedEd25519ExportRootCapability-yzxQjIFd.js → unlockedEd25519ExportRootCapability-5F1egCSv.js} +1 -1
- package/dist/public/sdk/voiceid-host.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-recovery-BZB2Vu3X.js → wallet-recovery-DXdm68_Q.js} +1 -1
- package/dist/{esm/sdk/walletAuthMethodRecord-DLBB5fez.js → public/sdk/walletAuthMethodRecord-BW-XV4fv.js} +1 -1
- package/dist/public/sdk/{walletAuthority-BTGAuOi8.js → walletAuthority-DbGaSw7D.js} +1 -1
- package/dist/public/sdk/{walletCapabilityBindings-D5YYB7nN.js → walletCapabilityBindings-mPx-6_r-.js} +1 -1
- package/dist/{esm/sdk/walletCustodyEcdsaContinuity-C31YQ9av.js → public/sdk/walletCustodyEcdsaContinuity-BnyL1Ryu.js} +1 -1
- package/dist/public/sdk/{walletOwnershipGeneration-CgjCtPrV.js → walletOwnershipGeneration-BZc6UKqX.js} +1 -1
- package/dist/public/sdk/walletRecoveryAdminProof-DdwikrW3.js +1 -0
- package/dist/public/sdk/walletRecoveryCommit-DbAoiJp5.js +1 -0
- package/dist/{esm/sdk/walletSessionAuthorizationStore-B9Vwkshr.js → public/sdk/walletSessionAuthorizationStore-BivTUoKY.js} +1 -1
- package/dist/public/sdk/{webauthnP256-BsQQPurm.js → webauthnP256-BGHikiNl.js} +1 -1
- package/dist/public/wallet-assets.manifest.json +262 -262
- package/dist/public/wallet-service/index.html +4 -4
- package/dist/types/shared-ts/src/auth/externalAuth.d.ts +127 -0
- package/dist/types/shared-ts/src/authorization/index.d.ts +1 -1
- package/dist/types/shared-ts/src/authorization/walletOwnerOperation.d.ts +10 -0
- package/dist/types/shared-ts/src/utils/registrationEstablishedSession.d.ts +4 -0
- package/dist/types/shared-ts/src/utils/registrationIntent.d.ts +2 -0
- package/dist/types/shared-ts/src/utils/walletManagementProtocol.d.ts +1 -1
- package/dist/types/wallet/src/SeamsWeb/operations/devices/walletHostOwnerAuthority.d.ts +2 -1
- package/dist/types/wallet/src/SeamsWeb/operations/registration/pendingRegistrationRecovery.d.ts +1 -0
- package/dist/types/wallet/src/SeamsWeb/operations/registration/registration.d.ts +1 -0
- package/dist/types/wallet/src/SeamsWeb/operations/registration/registrationPasskeyMaterial.d.ts +24 -0
- package/dist/types/wallet/src/SeamsWeb/publicApi/auth.d.ts +1 -1
- package/dist/types/wallet/src/SeamsWeb/publicApi/createPublicApi.d.ts +1 -0
- package/dist/types/wallet/src/SeamsWeb/publicApi/nearCommands.d.ts +2 -0
- package/dist/types/wallet/src/SeamsWeb/publicApi/ownerNearOperation.d.ts +58 -0
- package/dist/types/wallet/src/SeamsWeb/publicApi/types.d.ts +21 -2
- package/dist/types/wallet/src/SeamsWeb/signingSurface/BrowserSigningSurface.d.ts +57 -56
- package/dist/types/wallet/src/SeamsWeb/signingSurface/nearOwnerOperation.d.ts +16 -0
- package/dist/types/wallet/src/SeamsWeb/signingSurface/nearPasskeyOperationMaterial.d.ts +72 -0
- package/dist/types/wallet/src/SeamsWeb/signingSurface/types.d.ts +3 -0
- package/dist/types/wallet/src/SeamsWeb/walletIframe/client/ownerNearOperation.d.ts +25 -0
- package/dist/types/wallet/src/SeamsWeb/walletIframe/client/router.d.ts +8 -1
- package/dist/types/wallet/src/SeamsWeb/walletIframe/host/WalletHostRuntime.d.ts +8 -2
- package/dist/types/wallet/src/SeamsWeb/walletIframe/host/createNearCommands.d.ts +2 -1
- package/dist/types/wallet/src/SeamsWeb/walletIframe/host/createSessionCommands.d.ts +9 -2
- package/dist/types/wallet/src/SeamsWeb/walletIframe/host/externalAuth.d.ts +31 -0
- package/dist/types/wallet/src/SeamsWeb/walletIframe/host/externalOwnerApproval.d.ts +24 -0
- package/dist/types/wallet/src/SeamsWeb/walletIframe/host/ownerNearOperation.d.ts +12 -0
- package/dist/types/wallet/src/SeamsWeb/walletIframe/host/requestRouter.d.ts +2 -2
- package/dist/types/wallet/src/SeamsWeb/walletIframe/host/sessionObserver.d.ts +1 -0
- package/dist/types/wallet/src/SeamsWeb/walletIframe/shared/exactSessionState.d.ts +8 -0
- package/dist/types/wallet/src/SeamsWeb/walletIframe/shared/messages.d.ts +17 -7
- package/dist/types/wallet/src/SeamsWeb/walletIframe/shared/ownerNearOperation.d.ts +51 -0
- package/dist/types/wallet/src/core/authMethods/plugins.d.ts +2 -0
- package/dist/types/wallet/src/core/indexedDB/seamsWalletDB/registrationSetup.d.ts +1 -0
- package/dist/types/wallet/src/core/indexedDB/seamsWalletDB/repositories.d.ts +4 -0
- package/dist/types/wallet/src/core/rpcClients/near/NearClient.d.ts +4 -0
- package/dist/types/wallet/src/core/rpcClients/relayer/walletRecoveryRotate.d.ts +2 -2
- package/dist/types/wallet/src/core/rpcClients/relayer/walletRegistration.d.ts +1 -0
- package/dist/types/wallet/src/core/signingEngine/session/passkey/ed25519YaoLocalMaterial.d.ts +21 -0
- package/dist/types/wallet/src/core/types/seams.d.ts +21 -6
- package/dist/types/wallet/src/core/ui/messages.d.ts +1 -1
- package/dist/types/wallet/src/index.d.ts +3 -0
- package/dist/types/wallet/src/react/boundWallet.d.ts +21 -1
- package/dist/types/wallet/src/react/components/AccountMenuButton/AccountMenuButtonView.d.ts +2 -1
- package/dist/types/wallet/src/react/components/AccountMenuButton/AccountSettingsDialog.d.ts +10 -0
- package/dist/types/wallet/src/react/components/AccountMenuButton/AuthenticationMethodsModal.d.ts +1 -2
- package/dist/types/wallet/src/react/components/AccountMenuButton/ExternalWalletSettings.d.ts +10 -0
- package/dist/types/wallet/src/react/components/AccountMenuButton/LinkedDevicesModal.d.ts +1 -2
- package/dist/types/wallet/src/react/components/AccountMenuButton/WalletSettingsLayout.d.ts +1 -0
- package/dist/types/wallet/src/react/components/AccountMenuButton/hooks/useProfileState.d.ts +2 -2
- package/dist/types/wallet/src/react/components/AccountMenuButton/types.d.ts +4 -3
- package/dist/types/wallet/src/react/context/reactLoginStateBuilders.d.ts +1 -1
- package/dist/types/wallet/src/react/hooks/useOwnerNearOperation.d.ts +4 -0
- package/dist/types/wallet/src/react/index.d.ts +3 -0
- package/dist/types/wallet/src/react/types.d.ts +13 -3
- package/dist/types/wallet/src/voiceid-host.d.ts +2 -2
- package/package.json +1 -1
- package/dist/esm/react/components/AccountMenuButton/AccountMenuModal.js +0 -66
- package/dist/esm/sdk/NonceCoordinator-3YhmDTS5.js +0 -1
- package/dist/esm/sdk/accountLifecycle-6DHYWf0v.js +0 -1
- package/dist/esm/sdk/appearance-token-vars-BJydfWT_.js +0 -1
- package/dist/esm/sdk/clientSessionPersistenceState-BCkJAYSz.js +0 -1
- package/dist/esm/sdk/configBuilder-CSwJrmcR.js +0 -1
- package/dist/esm/sdk/confirm-ui-nU6ymgiv.js +0 -2
- package/dist/esm/sdk/ecdsaDerivationExport-DJKOzDbS.js +0 -1
- package/dist/esm/sdk/exportKeypairOperation-CGE9ZU1m.js +0 -1
- package/dist/esm/sdk/host-DayrOrgm.js +0 -1
- package/dist/esm/sdk/indexedDB-C4SDsyOG.js +0 -1
- package/dist/esm/sdk/nearEd25519YaoMaterialActivation-BfXmy3Jr.js +0 -1
- package/dist/esm/sdk/nearEd25519YaoSigningPreparation-DHNk0F8e.js +0 -1
- package/dist/esm/sdk/registration-CNLUYN-p.js +0 -1
- package/dist/esm/sdk/resealedEnvelopeResult-B1p5UkYg.js +0 -1
- package/dist/esm/sdk/runtime-auth-BCoj7_-G.js +0 -1
- package/dist/esm/sdk/runtime-device-link-DAsq5tGT.js +0 -1
- package/dist/esm/sdk/runtime-ecdsa-tempo-CVh_Vwl6.js +0 -1
- package/dist/esm/sdk/runtime-email-otp-BxSKK9AG.js +0 -1
- package/dist/esm/sdk/runtime-export-BWnQXMzT.js +0 -1
- package/dist/esm/sdk/runtime-near-CuzPZrDS.js +0 -1
- package/dist/esm/sdk/runtime-preferences-B-nDWlm3.js +0 -1
- package/dist/esm/sdk/runtime-recovery-DpOdEJ8N.js +0 -1
- package/dist/esm/sdk/runtimeContext-5JcewRo3.js +0 -6
- package/dist/esm/sdk/sessionObservationRevision-JOvVF4Hf.js +0 -1
- package/dist/esm/sdk/signEvmFamily-BY5jlZEG.js +0 -1
- package/dist/esm/sdk/signNear-DMpJFkwF.js +0 -1
- package/dist/esm/sdk/signer-worker-BNodGJKY.js +0 -1
- package/dist/esm/sdk/walletRecoveryAdminProof-CvSYbyg5.js +0 -1
- package/dist/esm/sdk/walletRecoveryCommit-Cc2LAkCS.js +0 -1
- package/dist/public/sdk/NonceCoordinator-3YhmDTS5.js +0 -1
- package/dist/public/sdk/accountLifecycle-6DHYWf0v.js +0 -1
- package/dist/public/sdk/appearance-token-vars-BJydfWT_.js +0 -1
- package/dist/public/sdk/clientSessionPersistenceState-BCkJAYSz.js +0 -1
- package/dist/public/sdk/configBuilder-CSwJrmcR.js +0 -1
- package/dist/public/sdk/confirm-ui-nU6ymgiv.js +0 -2
- package/dist/public/sdk/ecdsaDerivationExport-DJKOzDbS.js +0 -1
- package/dist/public/sdk/exportKeypairOperation-CGE9ZU1m.js +0 -1
- package/dist/public/sdk/host-DayrOrgm.js +0 -1
- package/dist/public/sdk/indexedDB-C4SDsyOG.js +0 -1
- package/dist/public/sdk/nearEd25519YaoMaterialActivation-BfXmy3Jr.js +0 -1
- package/dist/public/sdk/nearEd25519YaoSigningPreparation-DHNk0F8e.js +0 -1
- package/dist/public/sdk/registration-CNLUYN-p.js +0 -1
- package/dist/public/sdk/resealedEnvelopeResult-B1p5UkYg.js +0 -1
- package/dist/public/sdk/runtime-auth-BCoj7_-G.js +0 -1
- package/dist/public/sdk/runtime-device-link-DAsq5tGT.js +0 -1
- package/dist/public/sdk/runtime-ecdsa-tempo-CVh_Vwl6.js +0 -1
- package/dist/public/sdk/runtime-email-otp-BxSKK9AG.js +0 -1
- package/dist/public/sdk/runtime-export-BWnQXMzT.js +0 -1
- package/dist/public/sdk/runtime-near-CuzPZrDS.js +0 -1
- package/dist/public/sdk/runtime-preferences-B-nDWlm3.js +0 -1
- package/dist/public/sdk/runtime-recovery-DpOdEJ8N.js +0 -1
- package/dist/public/sdk/runtimeContext-5JcewRo3.js +0 -6
- package/dist/public/sdk/sessionObservationRevision-JOvVF4Hf.js +0 -1
- package/dist/public/sdk/signEvmFamily-BY5jlZEG.js +0 -1
- package/dist/public/sdk/signNear-DMpJFkwF.js +0 -1
- package/dist/public/sdk/signer-worker-BNodGJKY.js +0 -1
- package/dist/public/sdk/walletRecoveryAdminProof-CvSYbyg5.js +0 -1
- package/dist/public/sdk/walletRecoveryCommit-Cc2LAkCS.js +0 -1
- package/dist/types/shared-ts/src/authorization/walletCustodyOperation.d.ts +0 -10
- package/dist/types/wallet/src/react/components/AccountMenuButton/AccountMenuModal.d.ts +0 -9
- /package/dist/esm/sdk/{accountIds-CW2BP-d9.js → accountIds-DGWFzEnw.js} +0 -0
- /package/dist/esm/sdk/{actions-DrtSTGus.js → actions-7SvZZut1.js} +0 -0
- /package/dist/esm/sdk/{authenticatorOptions-WCDKYRux.js → authenticatorOptions-B4q62CLs.js} +0 -0
- /package/dist/esm/sdk/{confirmTypes-BvVtQs-M.js → confirmTypes-DmEPoxys.js} +0 -0
- /package/dist/esm/sdk/{csp-stylesheet-DUSqfXvZ.js → csp-stylesheet-5LU6VGKK.js} +0 -0
- /package/dist/esm/sdk/{digestEncoding-CqNXPZY9.js → digestEncoding-34kXJoJr.js} +0 -0
- /package/dist/esm/sdk/{ecdsaChainTarget-Bm5X4k-V.js → ecdsaChainTarget-BoRVQtjQ.js} +0 -0
- /package/dist/esm/sdk/{executeWorkerOperation-C9FOCCR7.js → executeWorkerOperation-CAYSt0NA.js} +0 -0
- /package/dist/esm/sdk/{helpers-Dubwo5uK.js → helpers-B7c1zc7h.js} +0 -0
- /package/dist/esm/sdk/{jsonRpc-BVDv1wfm.js → jsonRpc-DGzeiNSa.js} +0 -0
- /package/dist/esm/sdk/{keccak-mS0Mejjx.js → keccak-DGHI1G6t.js} +0 -0
- /package/dist/esm/sdk/{keyMaterialEnvelope-Dm2ZEilb.js → keyMaterialEnvelope-Czkks9Ki.js} +0 -0
- /package/dist/esm/sdk/{presignatures-BCeq56DG.js → presignatures-CkhuZ0YQ.js} +0 -0
- /package/dist/esm/sdk/{profileAccountProjection-C5sNt-s2.js → profileAccountProjection-dvLchPBo.js} +0 -0
- /package/dist/esm/sdk/{registrationAuthMethodInput-BR1WVbK3.js → registrationAuthMethodInput-C4o7yFBJ.js} +0 -0
- /package/dist/esm/sdk/{sdkSentEvents-DjOlKtdW.js → sdkSentEvents-BFwv3mBw.js} +0 -0
- /package/dist/esm/sdk/{signerDomain-BAsLT3XN.js → signerDomain-D-EUTlLK.js} +0 -0
- /package/dist/esm/sdk/{signerSlot-D2RZnb27.js → signerSlot-BlijMq8C.js} +0 -0
- /package/dist/esm/sdk/{surface-measurement-reporter-DXsvq401.js → surface-measurement-reporter-DJ_dQhBV.js} +0 -0
- /package/dist/esm/sdk/{walletCustodyOperation-DimzAbCB.js → walletOwnerOperation-CScYv2K6.js} +0 -0
- /package/dist/esm/sdk/{walletSessionAuthorizationStatus-DG7DPcgR.js → walletSessionAuthorizationStatus-GhcGvDCX.js} +0 -0
- /package/dist/public/sdk/{accountIds-CW2BP-d9.js → accountIds-DGWFzEnw.js} +0 -0
- /package/dist/public/sdk/{actions-DrtSTGus.js → actions-7SvZZut1.js} +0 -0
- /package/dist/public/sdk/{authenticatorOptions-WCDKYRux.js → authenticatorOptions-B4q62CLs.js} +0 -0
- /package/dist/public/sdk/{confirmTypes-BvVtQs-M.js → confirmTypes-DmEPoxys.js} +0 -0
- /package/dist/public/sdk/{csp-stylesheet-DUSqfXvZ.js → csp-stylesheet-5LU6VGKK.js} +0 -0
- /package/dist/public/sdk/{digestEncoding-CqNXPZY9.js → digestEncoding-34kXJoJr.js} +0 -0
- /package/dist/public/sdk/{ecdsaChainTarget-Bm5X4k-V.js → ecdsaChainTarget-BoRVQtjQ.js} +0 -0
- /package/dist/public/sdk/{executeWorkerOperation-C9FOCCR7.js → executeWorkerOperation-CAYSt0NA.js} +0 -0
- /package/dist/public/sdk/{helpers-Dubwo5uK.js → helpers-B7c1zc7h.js} +0 -0
- /package/dist/public/sdk/{jsonRpc-BVDv1wfm.js → jsonRpc-DGzeiNSa.js} +0 -0
- /package/dist/public/sdk/{keccak-mS0Mejjx.js → keccak-DGHI1G6t.js} +0 -0
- /package/dist/public/sdk/{keyMaterialEnvelope-Dm2ZEilb.js → keyMaterialEnvelope-Czkks9Ki.js} +0 -0
- /package/dist/public/sdk/{presignatures-BCeq56DG.js → presignatures-CkhuZ0YQ.js} +0 -0
- /package/dist/public/sdk/{profileAccountProjection-C5sNt-s2.js → profileAccountProjection-dvLchPBo.js} +0 -0
- /package/dist/public/sdk/{registrationAuthMethodInput-BR1WVbK3.js → registrationAuthMethodInput-C4o7yFBJ.js} +0 -0
- /package/dist/public/sdk/{sdkSentEvents-DjOlKtdW.js → sdkSentEvents-BFwv3mBw.js} +0 -0
- /package/dist/public/sdk/{signerDomain-BAsLT3XN.js → signerDomain-D-EUTlLK.js} +0 -0
- /package/dist/public/sdk/{signerSlot-D2RZnb27.js → signerSlot-BlijMq8C.js} +0 -0
- /package/dist/public/sdk/{surface-measurement-reporter-DXsvq401.js → surface-measurement-reporter-DJ_dQhBV.js} +0 -0
- /package/dist/public/sdk/{walletCustodyOperation-DimzAbCB.js → walletOwnerOperation-CScYv2K6.js} +0 -0
- /package/dist/public/sdk/{walletSessionAuthorizationStatus-DG7DPcgR.js → walletSessionAuthorizationStatus-GhcGvDCX.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e,t}from"./digests-BIaE0DMd.js";import{i as n}from"./base64-BmKR3UqU.js";import{t as r}from"./actions-
|
|
1
|
+
import{r as e,t}from"./digests-BIaE0DMd.js";import{i as n}from"./base64-BmKR3UqU.js";import{t as r}from"./actions-7SvZZut1.js";async function i(t){return n(await e(t))}async function a(e){return i(t({kind:`nep413`,...e}))}async function o(e){return i(t(e))}async function s(e){return i(t(e))}function c(e){switch(e.action_type){case r.FunctionCall:return{action_type:e.action_type,args:e.args,deposit:e.deposit,gas:e.gas,method_name:e.method_name};case r.Transfer:return{action_type:e.action_type,deposit:e.deposit};case r.Stake:return{action_type:e.action_type,stake:e.stake,public_key:e.public_key};case r.AddKey:return{action_type:e.action_type,public_key:e.public_key,access_key:e.access_key};case r.DeleteKey:return{action_type:e.action_type,public_key:e.public_key};case r.DeleteAccount:return{action_type:e.action_type,beneficiary_id:e.beneficiary_id};case r.DeployContract:return{action_type:e.action_type,code:e.code};case r.SignedDelegate:return{action_type:e.action_type,delegate_action:e.delegate_action,signature:e.signature};case r.DeployGlobalContract:return{action_type:e.action_type,code:e.code,deploy_mode:e.deploy_mode};case r.UseGlobalContract:return{action_type:e.action_type,account_id:e.account_id,code_hash:e.code_hash};case r.CreateAccount:return{action_type:e.action_type};default:return e}}export{i as a,c as i,a as n,s as r,o as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{v as e,y as t}from"./nearEd25519YaoSigningPreparation-
|
|
1
|
+
import{v as e,y as t}from"./nearEd25519YaoSigningPreparation-CnbgQfZc.js";function n(e){return m({...t({walletId:e.walletId,nearAccountId:e.nearAccountId,nearEd25519SigningKeyId:e.nearEd25519SigningKeyId,signerSlot:e.signerSlot,auth:e.auth,walletSessionId:e.walletSessionId,quotaId:e.quotaId,thresholdSessionId:e.thresholdSessionId}),keyKind:`threshold_ed25519`,chainFamily:`near`,storageSource:e.storageSource,sessionOrigin:e.sessionOrigin||h(e.storageSource),...e.retention?{retention:e.retention}:{}})}function r(e){return m({...t({walletId:e.walletId,nearAccountId:e.nearAccountId,nearEd25519SigningKeyId:e.nearEd25519SigningKeyId,signerSlot:e.signerSlot,auth:e.auth,walletSessionId:e.walletSessionId,quotaId:e.quotaId,thresholdSessionId:e.thresholdSessionId}),keyKind:`threshold_ed25519`,chainFamily:`near`,storageSource:`email_otp`,sessionOrigin:e.sessionOrigin||`per_operation`,...e.retention?{retention:e.retention}:{}})}function i(t){return m({...e({key:t.key,materialActivation:t.materialActivation,keyHandle:t.keyHandle,walletId:t.walletId,auth:t.auth,authorization:t.authorization,chainTarget:t.chainTarget}),keyKind:`threshold_ecdsa_secp256k1`,chainFamily:t.chainTarget.kind,storageSource:t.storageSource,sessionOrigin:t.sessionOrigin||h(t.storageSource),...t.retention?{retention:t.retention}:{}})}function a(t){return m({...e({key:t.key,materialActivation:t.materialActivation,keyHandle:t.keyHandle,walletId:t.walletId,auth:t.auth,authorization:t.authorization,chainTarget:t.chainTarget}),keyKind:`threshold_ecdsa_secp256k1`,chainFamily:t.chainTarget.kind,storageSource:`email_otp`,sessionOrigin:t.sessionOrigin||`per_operation`,...t.retention?{retention:t.retention}:{}})}function o(e){if(e.auth.kind===`voiceid`)return m({...t({walletId:e.walletId,nearAccountId:e.nearAccountId,nearEd25519SigningKeyId:e.nearEd25519SigningKeyId,signerSlot:e.signerSlot,auth:e.auth,walletSessionId:e.walletSessionId,quotaId:e.quotaId,thresholdSessionId:e.thresholdSessionId}),keyKind:`threshold_ed25519`,chainFamily:`near`,storageSource:`login`,sessionOrigin:`login`,retention:`session`});if(d(e))return r(e);if(u(e))return n(e);throw Error(`[SigningSession] unsupported NEAR lane auth`)}function s(e){if(e.chainTarget.kind!==`tempo`)throw Error(`Tempo ECDSA transaction lane requires a Tempo chain target`);return l(e)}function c(e){if(e.chainTarget.kind!==`evm`)throw Error(`EVM ECDSA transaction lane requires an EIP-155 chain target`);return l(e)}function l(e){if(p(e))return a(e);if(f(e))return i(e);throw Error(`[SigningSession] unsupported ECDSA lane auth`)}function u(e){return e.auth.kind===`passkey`}function d(e){return e.auth.kind===`email_otp`}function f(e){return e.auth.kind===`passkey`||e.auth.kind===`voiceid`}function p(e){return e.auth.kind===`email_otp`}function m(e){return{...e,retention:e.retention||`session`}}function h(e){switch(e){case`login`:return`login`;case`registration`:return`registration`;case`add-signer`:return`add_signer`;case`manual-bootstrap`:return`manual_bootstrap`;case`manual-connect`:return`manual_connect`;case`bootstrap`:return`bootstrap`;case`sealed_restore`:return`sealed_restore`}}export{o as n,s as r,c as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e}from"./base64-BmKR3UqU.js";import"./capabilityKinds-DVlGMspk.js";import{t}from"./errors-BJBDbwHk.js";import"./
|
|
1
|
+
import{i as e}from"./base64-BmKR3UqU.js";import"./capabilityKinds-DVlGMspk.js";import{t}from"./errors-BJBDbwHk.js";import"./signerDomain-D-EUTlLK.js";import"./accountIds-DGWFzEnw.js";import"./csp-stylesheet-5LU6VGKK.js";import{a as n,b as r,f as i,m as a,n as o,t as s}from"./adapters-B2k8y0MB.js";import{n as c,r as l}from"./collectAuthenticationCredentialForChallengeB64u-BoFVpdRS.js";import{n as u}from"./confirmTypes-DmEPoxys.js";import{c as d}from"./confirm-ui-Dx6c4-Rk.js";import"./appearance-token-vars-DkF3EBbF.js";import{t as f}from"./appearance-DL7c6bML.js";import{n as p,r as m}from"./export-viewer-host-O0OV1Oou.js";function h(){return e(crypto.getRandomValues(new Uint8Array(32)).buffer)}function g(e){switch(e.kind){case`near_wallet`:return e.nearAccountId;case`evm_wallet`:return e.walletId;default:{let t=e;throw Error(`Unsupported local key export subject: ${String(t)}`)}}}async function _(e,t,n,r){await m({theme:t.theme||r||`dark`,variant:t.variant||(n.uiMode===`drawer`?`drawer`:`modal`),accountId:g(t.subject),sessionId:t.viewerSessionId,publicKey:t.publicKey,privateKey:t.privateKey,keys:Array.isArray(t.keys)?t.keys:void 0,guidance:t.guidance,appearance:f({getAppearance:e.getAppearance,requestedMode:t.theme}),loading:t.loading===!0,errorMessage:t.errorMessage,onLifecycle:t.onLifecycle,surfaceMeasurementBinding:e.surfaceMeasurementBinding})}function v(e){try{return{rpId:e.security.getRpId()}}catch{return{}}}async function y(e){switch(e.payload.subject.kind){case`near_wallet`:return await c({touchIdPrompt:e.ctx.touchIdPrompt,nearAccountId:e.payload.subject.nearAccountId,credentialIdB64u:e.payload.credentialIdB64u,challengeB64u:e.challengeB64u,includeSecondPrfOutput:!0});case`evm_wallet`:return await l({touchIdPrompt:e.ctx.touchIdPrompt,walletId:e.payload.subject.walletId,credentialIdB64u:e.payload.credentialIdB64u,challengeB64u:e.challengeB64u,includeSecondPrfOutput:!0});default:{let t=e.payload.subject;throw Error(`Unsupported local key export subject: ${String(t)}`)}}}async function b(e,c,l,f){let{confirmationConfig:m,transactionSummary:g,theme:b}=f,x=o(e),S=s({adapters:x,worker:l,request:c,confirmationConfig:m,transactionSummary:g,theme:b,surface:{kind:`mount_new`}});if(c.type===u.SHOW_SECURE_PRIVATE_KEY_UI)try{await _(e,c.payload,m,b),S.confirmAndCloseModal({requestId:c.requestId,intentDigest:n(c),confirmed:!0});return}catch(e){return S.confirmAndCloseModal({requestId:c.requestId,intentDigest:n(c),confirmed:!1,error:t(e)||`Failed to render export UI`})}if(c.type===u.AUTHORIZE_KEY_EXPORT){p();let o=d()?r():m,s=String(c.payload?.challengeB64u||``).trim()||h();if(o.kind!==`silent`){try{let e=g.operation,t=g.warning;g.title||=e||`Export Private Key`,g.body||=t||`Confirm to authenticate with your passkey.`}catch{}let e=v(x),{confirmed:t,error:r}=await S.promptUser({securityContext:e});if(!t)return S.confirmAndCloseModal({requestId:c.requestId,intentDigest:n(c),confirmed:!1,error:r})}try{let t=await y({ctx:e,payload:c.payload,challengeB64u:s});return S.confirmAndCloseModal({requestId:c.requestId,intentDigest:n(c),confirmed:!0,credential:t})}catch(e){let r=a(e);return S.confirmAndCloseModal({requestId:c.requestId,intentDigest:n(c),confirmed:!1,error:r?i.cancelled:t(e)||i.collectCredentialsFailed})}}}export{b as handleLocalOnlyFlow};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./events-D6l0_ugy.js";import{a as t,i as n,o as r,r as i,s as a}from"./csp-stylesheet-DUSqfXvZ.js";import{a as o,c as s,i as c,n as l,o as u,r as d,s as f,t as p}from"./appearance-token-vars-BJydfWT_.js";import{i as m,n as h,r as g,t as _}from"./ConfirmationDrawer-AZruQmhP.js";function v(e){throw Error(`Unexpected private key reveal state: ${String(e)}`)}function y(e){switch(e){case`secp256k1`:return{prefix:`0x`,alphabet:`0123456789abcdef`,slotCount:64};case`ed25519`:return{prefix:`ed25519:`,alphabet:`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`,slotCount:88};default:return v(e)}}function b(e){return e[Math.floor(Math.random()*e.length)]??e[0]??`x`}function x(e,t){return e+Math.random()*(t-e)}function S(e,t,n){let r=[];for(let i=0;i<e.slotCount;i+=1)r.push({glyph:t?`x`:b(e.alphabet),nextChangeAtMs:t?1/0:n+i*37%90});return r}function C(e,t,n,r){let i=y(t);return{kind:`spinning`,entryKey:e,prefix:i.prefix,alphabet:i.alphabet,slots:S(i,n,r)}}function w(e){if(!e)return``;let t=(e.startsWith(`ed25519:`)?8:0)+6,n=Math.max(t,e.length-6);return`${e.slice(0,t)}${`x`.repeat(n-t)}${e.slice(n)}`}function T(e,t,n){let r=t.startsWith(e.prefix)?e.prefix:``,i=Array.from(t.slice(r.length)),a=i.length===e.slots.length?e.slots:i.map((t,r)=>({glyph:b(e.alphabet),nextChangeAtMs:n+r*37%90}));return{kind:`settling`,entryKey:e.entryKey,prefix:r,alphabet:e.alphabet,slots:a,targetSlots:i,lockedSlots:0,startedAtMs:n}}function E(e,t){let n=Math.max(1,e.targetSlots.length-1),r=0;for(let i=0;i<e.targetSlots.length;i+=1){let a=i/n*700;t>=e.startedAtMs+a+300&&(r+=1)}return r}function D(e,t,n){let r=t/Math.max(1,e.targetSlots.length-1)*700,i=e.startedAtMs+r;return Math.max(0,Math.min(1,(n-i)/300))}function O(e,t,n){let r=null;for(let i=0;i<e.length;i+=1){let a=e[i];!a||n<a.nextChangeAtMs||(r===null&&(r=[...e]),r[i]={glyph:b(t),nextChangeAtMs:n+x(90,150)})}return r??e}function k(e,t,n){let r=null;for(let i=0;i<e.slots.length;i+=1){let a=e.slots[i];if(!a)continue;if(i<t){let t=e.targetSlots[i]??a.glyph;if(a.glyph===t&&a.nextChangeAtMs===1/0)continue;r===null&&(r=[...e.slots]),r[i]={glyph:t,nextChangeAtMs:1/0};continue}if(n<a.nextChangeAtMs)continue;let o=D(e,i,n)*90;r===null&&(r=[...e.slots]),r[i]={glyph:b(e.alphabet),nextChangeAtMs:n+x(90+o,150+o)}}return r??e.slots}function A(e,t){if(e.kind===`spinning`){let n=O(e.slots,e.alphabet,t);return n===e.slots?e:{...e,slots:n}}if(e.kind===`settling`){let n=E(e,t);if(n>=e.targetSlots.length)return{kind:`settled`,entryKey:e.entryKey};let r=k(e,n,t);return r===e.slots&&n===e.lockedSlots?e:{...e,slots:r,lockedSlots:n}}return v(e)}function j({model:e,onClose:t}){let n=o(),r=e.kind===`failed`?[]:e.entries,a=r.length===0||r.some(M);return i(`div`,{class:`seams-export-key-viewer`,"data-seams-drawer-no-drag":!0,onPointerDown:P,onMouseDown:P,onTouchStart:P,children:i(`div`,{class:`content`,children:[i(`div`,{class:`seams-export-header`,children:[i(`h2`,{class:`title`,children:i(c,{message:`Exported Keys`})}),t&&i(`button`,{type:`button`,class:`seams-export-modal-close`,"aria-label":s(n,`Close exported keys`),onClick:t,children:`×`})]}),e.kind===`failed`&&i(`div`,{class:`error-banner`,role:`alert`,children:i(c,{copy:e.message})}),i(`div`,{class:`fields`,children:[a&&i(`div`,{class:`field`,children:[i(`div`,{class:`field-label`,children:i(c,{message:`Near Account ID`})}),i(`div`,{class:`field-value`,children:i(`span`,{class:`value`,children:e.accountId||`—`})})]}),r.length>0?r.map(N):i(`div`,{class:`field`,children:i(`div`,{class:`field-value`,children:i(`span`,{class:`muted`,children:e.kind===`loading`?i(c,{message:`Preparing private key…`}):i(c,{message:`No keys available`})})})})]}),e.guidance&&i(F,{guidance:e.guidance}),i(`div`,{class:`warning`,children:i(c,{message:`Warning: your private keys grant full control of your account and funds. Keep it in a secret place.`})})]})})}function M(e){return e.scheme===`ed25519`}function N(e){return i(L,{entry:e},e.id)}function P(e){e.stopPropagation()}function F({guidance:e}){return i(`div`,{class:`warning`,children:[i(`strong`,{children:i(c,{copy:e.title||`Next Steps`})}),e.body&&i(`div`,{children:i(c,{copy:e.body})}),e.steps?.length?i(`ol`,{children:e.steps.map(I)}):null]})}function I(e,t){return i(`li`,{children:i(c,{copy:e})},t)}var L=class extends n{static contextType=d;state={reveal:null,publicCopied:!1,privateCopied:!1};root=t();frame=null;timers=new Map;generation=0;copyLifetime=new AbortController;active=!1;componentDidMount(){this.active=!0,this.reset(this.props.entry)}componentWillReceiveProps(e){R(this.props.entry,e.entry)||this.reset(e.entry)}componentDidUpdate(){this.schedule()}componentWillUnmount(){this.active=!1,this.clearPending(),this.state.reveal=null}clearPending(){this.generation+=1,this.copyLifetime.abort();let e=this.root.current?.ownerDocument.defaultView;this.frame!==null&&e?.cancelAnimationFrame(this.frame),this.frame=null;for(let t of this.timers.values())e?.clearTimeout(t);this.timers.clear()}reset(e){this.clearPending(),this.copyLifetime=new AbortController;let t=this.root.current.ownerDocument.defaultView,n=t.matchMedia(`(prefers-reduced-motion: reduce)`).matches,r=t.performance.now(),i=null;switch(e.material.kind){case`loading`:i=C(e.id,e.scheme,n,r);break;case`ready`:i=n?{kind:`settled`,entryKey:e.id}:T(C(e.id,e.scheme,!1,r),w(e.material.value),r);break;case`unavailable`:break;default:H(e.material)}this.setState({reveal:i,publicCopied:!1,privateCopied:!1})}schedule(){let e=this.state.reveal;if(!this.active||this.frame!==null||!e||e.kind===`settled`)return;let t=this.root.current.ownerDocument.defaultView;t.matchMedia(`(prefers-reduced-motion: reduce)`).matches||(this.frame=t.requestAnimationFrame(this.tick))}tick=e=>{this.frame=null;let t=this.state.reveal;if(!this.active||!t||t.kind===`settled`)return;let n=A(t,e);n!==t&&this.setState({reveal:n}),this.schedule()};copyPublic=()=>{this.copy(`public`)};copyPrivate=()=>{this.copy(`private`)};clearPublic=()=>{this.timers.delete(`public`),this.active&&this.setState({publicCopied:!1})};clearPrivate=()=>{this.timers.delete(`private`),this.active&&this.setState({privateCopied:!1})};async copy(e){let t=this.props.entry;if(!this.active||e===`private`&&(t.material.kind!==`ready`||this.state.reveal?.kind!==`settled`))return;let n=t.publicKey;if(e===`private`){if(t.material.kind!==`ready`)return;n=t.material.value}if(!n)return;let r=this.generation,i=this.root.current,a=i.ownerDocument.defaultView;if(a.focus(),!await m(i,n,this.copyLifetime.signal).catch(z)||!this.active||r!==this.generation)return;let o=this.timers.get(e);o!==void 0&&a.clearTimeout(o),e===`public`?this.setState({publicCopied:!0}):this.setState({privateCopied:!0}),this.timers.set(e,a.setTimeout(e===`public`?this.clearPublic:this.clearPrivate,3e3))}render(){let e=this.props.entry,t=e.material.kind===`ready`&&this.state.reveal?.kind===`settled`;return i(`div`,{class:`key-card`,ref:this.root,children:[i(`div`,{class:`key-title`,children:i(c,{copy:e.label})}),e.address&&i(`div`,{class:`field`,children:[i(`div`,{class:`field-label`,children:i(c,{message:`Address`})}),i(`div`,{class:`field-value`,children:i(`span`,{class:`value`,children:e.address})})]}),e.scheme===`ed25519`&&i(`button`,{type:`button`,class:`field copy-field${this.state.publicCopied?` copied`:``}`,"aria-label":f(this.context,this.state.publicCopied?`Public key copied`:`Copy public key`),disabled:!e.publicKey,onClick:this.copyPublic,children:[i(`div`,{class:`field-label`,children:i(c,{message:`Public Key`})}),i(`div`,{class:`field-value`,children:[i(`span`,{class:`value`,children:e.publicKey||`—`}),i(g,{})]})]}),i(`button`,{type:`button`,class:`field copy-field${this.state.privateCopied?` copied`:``}`,"aria-label":f(this.context,this.state.privateCopied?`Private key copied`:`Copy private key`),disabled:!t,onClick:this.copyPrivate,children:[i(`div`,{class:`field-label`,children:i(c,{message:`Private Key`})}),i(`div`,{class:`field-value`,children:[i(`span`,{class:`value private-key`,children:i(B,{material:e.material,reveal:this.state.reveal})}),i(g,{})]})]})]})}};function R(e,t){return e.id===t.id&&e.scheme===t.scheme&&e.publicKey===t.publicKey&&e.material.kind===t.material.kind&&e.material.value===t.material.value}function z(){return!1}function B({material:e,reveal:t}){return t&&t.kind!==`settled`?i(a,{children:[i(`span`,{class:`private-key-reel`,"aria-hidden":`true`,children:[i(`span`,{class:`reel-prefix`,children:t.prefix}),V(t)]}),i(`span`,{class:`seams-sr-only`,role:`status`,children:i(c,{message:`Decrypting private key`})})]}):e.kind===`ready`?i(a,{children:[i(`span`,{children:w(e.value)}),i(`span`,{class:`seams-sr-only`,role:`status`,children:i(c,{message:`Private key ready`})})]}):i(`span`,{class:`muted`,children:`—`})}function V(e){let t=e.kind===`settling`?e.lockedSlots:0,n=[];for(let r=0;r<e.slots.length;r+=1)n.push(i(`span`,{class:`reel-slot${r<t?` settled`:``}`,children:e.slots[r].glyph},r));return n}function H(e){throw Error(`Unexpected export key material: ${String(e)}`)}let U=0;var W=class{element;styles;context;state;constructor(t){this.styles=l(t.parent.ownerDocument),this.context=t.context,this.state={kind:`mounted`,onClosed:t.onClosed},this.element=t.parent.ownerDocument.createElement(`div`),this.element.id=`seams-export-surface-${++U}`,this.element.className=`seams-wallet-ui seams-export-surface`,this.element.dataset.seamsExportSurface=t.context,this.element.addEventListener(e.TX_CONFIRMER_CANCEL,this.handleCancel),t.parent.appendChild(this.element);try{this.update(t.model)}catch(e){throw this.remove(),e}}update(e){if(this.state.kind!==`disposed`){if(this.element.lang=e.appearance.locale??`en`,this.element.dataset.theme=e.appearance.theme.mode,this.element.dataset.seamsExportVariant=e.variant,this.styles.setDynamicRule(this.element.id,p(this.element.id,e.appearance)),e.variant===`modal`){r(u(e.appearance.locale??`en`,i(h,{context:this.context,label:`Exported Keys`,onCancel:this.dispose,children:i(j,{model:e.content,onClose:this.dispose})})),this.element);return}r(u(e.appearance.locale??`en`,i(_,{context:this.context,label:`Exported Keys`,dismissOnBackdrop:!1,styles:this.styles,state:{kind:`open`,interaction:`ready`},onCancel:this.dispose,children:i(j,{model:e.content})})),this.element)}}dispose=()=>{if(this.state.kind===`disposed`)return;let e=this.state.onClosed;this.remove(),e()};handleCancel=()=>{this.dispose()};remove(){this.state={kind:`disposed`},this.element.removeEventListener(e.TX_CONFIRMER_CANCEL,this.handleCancel),r(null,this.element),this.styles.deleteDynamicRule(this.element.id),this.element.remove()}};function G(e){return new W(e)}export{G as mountExportPrivateKeySurface};
|
|
1
|
+
import{t as e}from"./events-D6l0_ugy.js";import{a as t,i as n,o as r,r as i,s as a}from"./csp-stylesheet-5LU6VGKK.js";import{a as o,c as s,i as c,n as l,o as u,r as d,s as f,t as p}from"./appearance-token-vars-DkF3EBbF.js";import{i as m,n as h,r as g,t as _}from"./ConfirmationDrawer-BRnd5SEf.js";function v(e){throw Error(`Unexpected private key reveal state: ${String(e)}`)}function y(e){switch(e){case`secp256k1`:return{prefix:`0x`,alphabet:`0123456789abcdef`,slotCount:64};case`ed25519`:return{prefix:`ed25519:`,alphabet:`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`,slotCount:88};default:return v(e)}}function b(e){return e[Math.floor(Math.random()*e.length)]??e[0]??`x`}function x(e,t){return e+Math.random()*(t-e)}function S(e,t,n){let r=[];for(let i=0;i<e.slotCount;i+=1)r.push({glyph:t?`x`:b(e.alphabet),nextChangeAtMs:t?1/0:n+i*37%90});return r}function C(e,t,n,r){let i=y(t);return{kind:`spinning`,entryKey:e,prefix:i.prefix,alphabet:i.alphabet,slots:S(i,n,r)}}function w(e){if(!e)return``;let t=(e.startsWith(`ed25519:`)?8:0)+6,n=Math.max(t,e.length-6);return`${e.slice(0,t)}${`x`.repeat(n-t)}${e.slice(n)}`}function T(e,t,n){let r=t.startsWith(e.prefix)?e.prefix:``,i=Array.from(t.slice(r.length)),a=i.length===e.slots.length?e.slots:i.map((t,r)=>({glyph:b(e.alphabet),nextChangeAtMs:n+r*37%90}));return{kind:`settling`,entryKey:e.entryKey,prefix:r,alphabet:e.alphabet,slots:a,targetSlots:i,lockedSlots:0,startedAtMs:n}}function E(e,t){let n=Math.max(1,e.targetSlots.length-1),r=0;for(let i=0;i<e.targetSlots.length;i+=1){let a=i/n*700;t>=e.startedAtMs+a+300&&(r+=1)}return r}function D(e,t,n){let r=t/Math.max(1,e.targetSlots.length-1)*700,i=e.startedAtMs+r;return Math.max(0,Math.min(1,(n-i)/300))}function O(e,t,n){let r=null;for(let i=0;i<e.length;i+=1){let a=e[i];!a||n<a.nextChangeAtMs||(r===null&&(r=[...e]),r[i]={glyph:b(t),nextChangeAtMs:n+x(90,150)})}return r??e}function k(e,t,n){let r=null;for(let i=0;i<e.slots.length;i+=1){let a=e.slots[i];if(!a)continue;if(i<t){let t=e.targetSlots[i]??a.glyph;if(a.glyph===t&&a.nextChangeAtMs===1/0)continue;r===null&&(r=[...e.slots]),r[i]={glyph:t,nextChangeAtMs:1/0};continue}if(n<a.nextChangeAtMs)continue;let o=D(e,i,n)*90;r===null&&(r=[...e.slots]),r[i]={glyph:b(e.alphabet),nextChangeAtMs:n+x(90+o,150+o)}}return r??e.slots}function A(e,t){if(e.kind===`spinning`){let n=O(e.slots,e.alphabet,t);return n===e.slots?e:{...e,slots:n}}if(e.kind===`settling`){let n=E(e,t);if(n>=e.targetSlots.length)return{kind:`settled`,entryKey:e.entryKey};let r=k(e,n,t);return r===e.slots&&n===e.lockedSlots?e:{...e,slots:r,lockedSlots:n}}return v(e)}function j({model:e,onClose:t}){let n=o(),r=e.kind===`failed`?[]:e.entries,a=r.length===0||r.some(M);return i(`div`,{class:`seams-export-key-viewer`,"data-seams-drawer-no-drag":!0,onPointerDown:P,onMouseDown:P,onTouchStart:P,children:i(`div`,{class:`content`,children:[i(`div`,{class:`seams-export-header`,children:[i(`h2`,{class:`title`,children:i(c,{message:`Exported Keys`})}),t&&i(`button`,{type:`button`,class:`seams-export-modal-close`,"aria-label":s(n,`Close exported keys`),onClick:t,children:`×`})]}),e.kind===`failed`&&i(`div`,{class:`error-banner`,role:`alert`,children:i(c,{copy:e.message})}),i(`div`,{class:`fields`,children:[a&&i(`div`,{class:`field`,children:[i(`div`,{class:`field-label`,children:i(c,{message:`Near Account ID`})}),i(`div`,{class:`field-value`,children:i(`span`,{class:`value`,children:e.accountId||`—`})})]}),r.length>0?r.map(N):i(`div`,{class:`field`,children:i(`div`,{class:`field-value`,children:i(`span`,{class:`muted`,children:e.kind===`loading`?i(c,{message:`Preparing private key…`}):i(c,{message:`No keys available`})})})})]}),e.guidance&&i(F,{guidance:e.guidance}),i(`div`,{class:`warning`,children:i(c,{message:`Warning: your private keys grant full control of your account and funds. Keep it in a secret place.`})})]})})}function M(e){return e.scheme===`ed25519`}function N(e){return i(L,{entry:e},e.id)}function P(e){e.stopPropagation()}function F({guidance:e}){return i(`div`,{class:`warning`,children:[i(`strong`,{children:i(c,{copy:e.title||`Next Steps`})}),e.body&&i(`div`,{children:i(c,{copy:e.body})}),e.steps?.length?i(`ol`,{children:e.steps.map(I)}):null]})}function I(e,t){return i(`li`,{children:i(c,{copy:e})},t)}var L=class extends n{static contextType=d;state={reveal:null,publicCopied:!1,privateCopied:!1};root=t();frame=null;timers=new Map;generation=0;copyLifetime=new AbortController;active=!1;componentDidMount(){this.active=!0,this.reset(this.props.entry)}componentWillReceiveProps(e){R(this.props.entry,e.entry)||this.reset(e.entry)}componentDidUpdate(){this.schedule()}componentWillUnmount(){this.active=!1,this.clearPending(),this.state.reveal=null}clearPending(){this.generation+=1,this.copyLifetime.abort();let e=this.root.current?.ownerDocument.defaultView;this.frame!==null&&e?.cancelAnimationFrame(this.frame),this.frame=null;for(let t of this.timers.values())e?.clearTimeout(t);this.timers.clear()}reset(e){this.clearPending(),this.copyLifetime=new AbortController;let t=this.root.current.ownerDocument.defaultView,n=t.matchMedia(`(prefers-reduced-motion: reduce)`).matches,r=t.performance.now(),i=null;switch(e.material.kind){case`loading`:i=C(e.id,e.scheme,n,r);break;case`ready`:i=n?{kind:`settled`,entryKey:e.id}:T(C(e.id,e.scheme,!1,r),w(e.material.value),r);break;case`unavailable`:break;default:H(e.material)}this.setState({reveal:i,publicCopied:!1,privateCopied:!1})}schedule(){let e=this.state.reveal;if(!this.active||this.frame!==null||!e||e.kind===`settled`)return;let t=this.root.current.ownerDocument.defaultView;t.matchMedia(`(prefers-reduced-motion: reduce)`).matches||(this.frame=t.requestAnimationFrame(this.tick))}tick=e=>{this.frame=null;let t=this.state.reveal;if(!this.active||!t||t.kind===`settled`)return;let n=A(t,e);n!==t&&this.setState({reveal:n}),this.schedule()};copyPublic=()=>{this.copy(`public`)};copyPrivate=()=>{this.copy(`private`)};clearPublic=()=>{this.timers.delete(`public`),this.active&&this.setState({publicCopied:!1})};clearPrivate=()=>{this.timers.delete(`private`),this.active&&this.setState({privateCopied:!1})};async copy(e){let t=this.props.entry;if(!this.active||e===`private`&&(t.material.kind!==`ready`||this.state.reveal?.kind!==`settled`))return;let n=t.publicKey;if(e===`private`){if(t.material.kind!==`ready`)return;n=t.material.value}if(!n)return;let r=this.generation,i=this.root.current,a=i.ownerDocument.defaultView;if(a.focus(),!await m(i,n,this.copyLifetime.signal).catch(z)||!this.active||r!==this.generation)return;let o=this.timers.get(e);o!==void 0&&a.clearTimeout(o),e===`public`?this.setState({publicCopied:!0}):this.setState({privateCopied:!0}),this.timers.set(e,a.setTimeout(e===`public`?this.clearPublic:this.clearPrivate,3e3))}render(){let e=this.props.entry,t=e.material.kind===`ready`&&this.state.reveal?.kind===`settled`;return i(`div`,{class:`key-card`,ref:this.root,children:[i(`div`,{class:`key-title`,children:i(c,{copy:e.label})}),e.address&&i(`div`,{class:`field`,children:[i(`div`,{class:`field-label`,children:i(c,{message:`Address`})}),i(`div`,{class:`field-value`,children:i(`span`,{class:`value`,children:e.address})})]}),e.scheme===`ed25519`&&i(`button`,{type:`button`,class:`field copy-field${this.state.publicCopied?` copied`:``}`,"aria-label":f(this.context,this.state.publicCopied?`Public key copied`:`Copy public key`),disabled:!e.publicKey,onClick:this.copyPublic,children:[i(`div`,{class:`field-label`,children:i(c,{message:`Public Key`})}),i(`div`,{class:`field-value`,children:[i(`span`,{class:`value`,children:e.publicKey||`—`}),i(g,{})]})]}),i(`button`,{type:`button`,class:`field copy-field${this.state.privateCopied?` copied`:``}`,"aria-label":f(this.context,this.state.privateCopied?`Private key copied`:`Copy private key`),disabled:!t,onClick:this.copyPrivate,children:[i(`div`,{class:`field-label`,children:i(c,{message:`Private Key`})}),i(`div`,{class:`field-value`,children:[i(`span`,{class:`value private-key`,children:i(B,{material:e.material,reveal:this.state.reveal})}),i(g,{})]})]})]})}};function R(e,t){return e.id===t.id&&e.scheme===t.scheme&&e.publicKey===t.publicKey&&e.material.kind===t.material.kind&&e.material.value===t.material.value}function z(){return!1}function B({material:e,reveal:t}){return t&&t.kind!==`settled`?i(a,{children:[i(`span`,{class:`private-key-reel`,"aria-hidden":`true`,children:[i(`span`,{class:`reel-prefix`,children:t.prefix}),V(t)]}),i(`span`,{class:`seams-sr-only`,role:`status`,children:i(c,{message:`Decrypting private key`})})]}):e.kind===`ready`?i(a,{children:[i(`span`,{children:w(e.value)}),i(`span`,{class:`seams-sr-only`,role:`status`,children:i(c,{message:`Private key ready`})})]}):i(`span`,{class:`muted`,children:`—`})}function V(e){let t=e.kind===`settling`?e.lockedSlots:0,n=[];for(let r=0;r<e.slots.length;r+=1)n.push(i(`span`,{class:`reel-slot${r<t?` settled`:``}`,children:e.slots[r].glyph},r));return n}function H(e){throw Error(`Unexpected export key material: ${String(e)}`)}let U=0;var W=class{element;styles;context;state;constructor(t){this.styles=l(t.parent.ownerDocument),this.context=t.context,this.state={kind:`mounted`,onClosed:t.onClosed},this.element=t.parent.ownerDocument.createElement(`div`),this.element.id=`seams-export-surface-${++U}`,this.element.className=`seams-wallet-ui seams-export-surface`,this.element.dataset.seamsExportSurface=t.context,this.element.addEventListener(e.TX_CONFIRMER_CANCEL,this.handleCancel),t.parent.appendChild(this.element);try{this.update(t.model)}catch(e){throw this.remove(),e}}update(e){if(this.state.kind!==`disposed`){if(this.element.lang=e.appearance.locale??`en`,this.element.dataset.theme=e.appearance.theme.mode,this.element.dataset.seamsExportVariant=e.variant,this.styles.setDynamicRule(this.element.id,p(this.element.id,e.appearance)),e.variant===`modal`){r(u(e.appearance.locale??`en`,i(h,{context:this.context,label:`Exported Keys`,onCancel:this.dispose,children:i(j,{model:e.content,onClose:this.dispose})})),this.element);return}r(u(e.appearance.locale??`en`,i(_,{context:this.context,label:`Exported Keys`,dismissOnBackdrop:!1,styles:this.styles,state:{kind:`open`,interaction:`ready`},onCancel:this.dispose,children:i(j,{model:e.content})})),this.element)}}dispose=()=>{if(this.state.kind===`disposed`)return;let e=this.state.onClosed;this.remove(),e()};handleCancel=()=>{this.dispose()};remove(){this.state={kind:`disposed`},this.element.removeEventListener(e.TX_CONFIRMER_CANCEL,this.handleCancel),r(null,this.element),this.styles.deleteDynamicRule(this.element.id),this.element.remove()}};function G(e){return new W(e)}export{G as mountExportPrivateKeySurface};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e,i as t,o as n,r,s as i}from"./csp-stylesheet-
|
|
1
|
+
import{a as e,i as t,o as n,r,s as i}from"./csp-stylesheet-5LU6VGKK.js";import{c as a,i as o,n as s,o as c,r as l,t as u}from"./appearance-token-vars-DkF3EBbF.js";function d(e){throw Error(`Unhandled recovery-code state: ${String(e)}`)}function f(e,t){return e instanceof Error&&e.message.trim()?e.message:t}function p(e){switch(e.kind){case`direct_backup`:return{kind:`recovery_codes`,request:e.request};case`account_menu`:return{kind:`summary`,walletId:e.walletId,loadState:{kind:`loading`},actionError:null};default:return d(e)}}function m(e){return{viewState:p(e),acknowledged:!1,statusMessage:``,copied:!1}}function h(e){switch(e.kind){case`summary`:case`opening`:case`recovery_codes`:return e.kind;default:return d(e)}}function g(e){switch(e.kind){case`ready`:return e.pendingLocalBackup||e.backupOutstanding?`Backup needed`:`Backed up`;case`no_recovery_set`:return`No recovery set`;case`unauthorized`:return`Authorization required`;case`transport_failed`:return`Could not load`;default:return d(e)}}function _(e){return e.kind===`loaded`&&e.status.kind===`ready`&&e.status.pendingLocalBackup}function v(e){if(e.kind===`error`)return e.message;if(e.kind!==`loaded`)return null;switch(e.status.kind){case`unauthorized`:case`transport_failed`:return e.status.message;case`ready`:case`no_recovery_set`:return null;default:return d(e.status)}}function y(e){switch(e.kind){case`loading`:return`Loading`;case`error`:return`Could not load`;case`loaded`:return g(e.status);default:return d(e)}}function b(e){switch(e.kind){case`loading`:return`Checking your codes…`;case`error`:return`Status unavailable`;case`loaded`:return e.status.kind===`ready`?`${e.status.activeCodeCount} of ${e.status.totalCodeCount} codes left`:`Status unavailable`;default:return d(e)}}function x(e){return e.trim().replace(/[^A-Za-z0-9_.-]/g,`_`)||`wallet`}function S(e,t){let n=[`Seams wallet recovery codes`,``,`Wallet: ${e}`,``,`Save these codes somewhere private. Each code can be used once.`,``];for(let[e,r]of t.entries())n.push(`${String(e+1).padStart(2,`0`)} ${r}`);return`${n.join(`
|
|
2
2
|
`)}\n`}function C(e,t){return t?`Finish backup`:e.continuation===`registration_may_defer`?`Back up later`:`Close`}function w(e,t){return r(`li`,{class:`recovery-code-item`,children:[r(`span`,{class:`recovery-code-index`,children:t+1}),r(`span`,{class:`recovery-code-value`,children:e})]},`${t}-${e}`)}var T=class extends t{static contextType=l;state=m(this.props.experience);root=e();active=!1;loadGeneration=0;copiedResetTimer=null;focusFrame=null;componentDidMount(){this.active=!0,this.loadGeneration+=1,this.notifyStage(),this.beginAccountStatus(this.props.experience,this.loadGeneration)}componentWillReceiveProps(e){e.experience!==this.props.experience&&(this.loadGeneration+=1,this.clearFocusFrame(),this.clearCopiedFlash(),this.setState(m(e.experience)),this.beginAccountStatus(e.experience,this.loadGeneration))}componentDidUpdate(e,t){h(t.viewState)!==h(this.state.viewState)&&this.notifyStage(),t.viewState.kind!==`recovery_codes`&&this.state.viewState.kind===`recovery_codes`&&this.focusTitleAfterRender()}componentWillUnmount(){this.active=!1,this.loadGeneration+=1,this.clearFocusFrame(),this.clearCopiedFlash()}render(){let e=this.state.viewState,t=h(e),n=e.kind===`recovery_codes`?this.renderRecoveryCodes(e.request):this.renderSummary(e);return r(`div`,{ref:this.root,class:`seams-recovery-code-backup-viewer`,"data-seams-recovery-entry":this.props.experience.kind,"data-seams-recovery-stage":t,children:n})}notifyStage(){this.props.onStageChange(h(this.state.viewState))}beginAccountStatus(e,t){e.kind===`account_menu`&&this.loadSummaryStatus(e,t)}async loadSummaryStatus(e,t){try{let n=await e.loadStatus();this.updateSummaryLoadState(t,{kind:`loaded`,status:n})}catch(e){this.updateSummaryLoadState(t,{kind:`error`,message:f(e,`Could not load recovery-code status`)})}}updateSummaryLoadState(e,t){if(!this.active||e!==this.loadGeneration)return;let n=this.state.viewState;n.kind!==`summary`&&n.kind!==`opening`||this.setState({viewState:{...n,loadState:t}})}retryStatus=()=>{let e=this.props.experience;if(e.kind!==`account_menu`)return;let t=this.state.viewState;if(t.kind!==`summary`)return;let n=++this.loadGeneration;this.setState({viewState:{...t,loadState:{kind:`loading`},actionError:null}}),this.loadSummaryStatus(e,n)};openRecoveryCodes=async()=>{let e=this.props.experience,t=this.state.viewState;if(e.kind!==`account_menu`||t.kind!==`summary`)return;if(t.loadState.kind!==`loaded`||t.loadState.status.kind!==`ready`){this.setState({viewState:{...t,actionError:`Verify recovery-code status before opening saved codes.`}});return}let n=t.loadState.status.issuedAtMs,r=this.loadGeneration;this.setState({viewState:{...t,kind:`opening`,actionError:null}});try{let i=await e.loadPendingBackup();if(!this.active||r!==this.loadGeneration)return;if(!i){this.setState({viewState:{...t,actionError:`Recovery codes are no longer available on this device.`}});return}if(i.continuation!==`pending_backup_must_finish`||i.issuedAtMs!==n){this.setState({viewState:{...t,actionError:`These saved codes belong to a different recovery set. Check status again.`}});return}this.setState({viewState:{kind:`recovery_codes`,request:i}})}catch(e){if(!this.active||r!==this.loadGeneration)return;this.setState({viewState:{...t,actionError:f(e,`Could not open recovery codes`)}})}};closeSummary=()=>{this.props.onClose({kind:`dismissed`})};closeRecoveryCodes=()=>{let e=this.state.viewState;e.kind===`recovery_codes`&&this.props.onClose({kind:`recovery_codes`,acknowledged:this.state.acknowledged,request:e.request})};onAcknowledgementChange=e=>{e.currentTarget instanceof HTMLInputElement&&this.setState({acknowledged:e.currentTarget.checked})};download=()=>{let e=this.state.viewState;if(e.kind!==`recovery_codes`)return;let t=this.root.current?.ownerDocument.defaultView;if(!t)return;let{walletId:n,recoveryCodes:r}=e.request;try{let e=t.URL.createObjectURL(new t.Blob([S(n,r)],{type:`text/plain;charset=utf-8`})),i=t.document.createElement(`a`);i.href=e,i.download=`seams-wallet-recovery-codes-${x(n)}.txt`;try{i.click()}finally{t.setTimeout(()=>t.URL.revokeObjectURL(e),0)}this.setState({statusMessage:`Recovery codes downloaded.`})}catch{this.setState({statusMessage:`Unable to download the codes. Copy them or try again.`})}};copy=async()=>{let e=this.state.viewState;if(e.kind!==`recovery_codes`||!this.active)return;let{walletId:t,recoveryCodes:n}=e.request,r=this.loadGeneration;try{if(await navigator.clipboard.writeText(S(t,n)),!this.active||r!==this.loadGeneration)return;this.setState({statusMessage:`Recovery codes copied.`}),this.flashCopied()}catch{if(!this.active||r!==this.loadGeneration)return;this.setState({statusMessage:`Unable to copy the codes. Download them or try again.`})}};flashCopied(){let e=this.root.current?.ownerDocument.defaultView;e&&(this.copiedResetTimer!==null&&e.clearTimeout(this.copiedResetTimer),this.setState({copied:!0}),this.copiedResetTimer=e.setTimeout(()=>{this.copiedResetTimer=null,this.active&&this.setState({copied:!1})},1800))}clearCopiedFlash(){let e=this.root.current?.ownerDocument.defaultView;e&&this.copiedResetTimer!==null&&e.clearTimeout(this.copiedResetTimer),this.copiedResetTimer=null}clearFocusFrame(){let e=this.root.current?.ownerDocument.defaultView;e&&this.focusFrame!==null&&e.cancelAnimationFrame(this.focusFrame),this.focusFrame=null}focusTitleAfterRender(){let e=this.root.current?.ownerDocument.defaultView;e&&(this.clearFocusFrame(),this.focusFrame=e.requestAnimationFrame(()=>{this.focusFrame=null,this.active&&this.root.current?.querySelector(`.recovery-backup-title`)?.focus()}))}renderSummary(e){let t=v(e.loadState),n=_(e.loadState),s=e.kind===`opening`;return r(i,{children:[r(`button`,{type:`button`,class:`recovery-summary-close`,"aria-label":a(this.context,`Close recovery codes`),onClick:this.closeSummary,children:r(`svg`,{"aria-hidden":`true`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,children:r(`path`,{d:`M6 6l12 12M18 6 6 18`})})}),r(`h1`,{id:`seams-wallet-recovery-title`,class:`recovery-backup-title`,tabIndex:-1,children:r(o,{message:`Wallet recovery codes`})}),r(`p`,{id:`seams-wallet-recovery-description`,class:`recovery-backup-description`,children:r(o,{message:`View and save the recovery codes retained by this wallet after registration.`})}),r(`div`,{class:`recovery-summary-body`,children:[r(`h2`,{class:`recovery-summary-section-label`,children:r(o,{message:`Security`})}),r(`div`,{class:`recovery-summary-item`,children:[r(`span`,{class:`recovery-summary-item-icon`,"aria-hidden":`true`,children:r(E,{})}),r(`span`,{class:`recovery-summary-item-text`,children:[r(`span`,{class:`recovery-summary-item-title`,children:r(o,{message:`Recovery codes`})}),r(`span`,{class:`recovery-summary-item-detail`,children:r(o,{copy:b(e.loadState)})})]}),r(`span`,{class:`recovery-summary-badge`,children:r(o,{copy:y(e.loadState)})})]}),r(`div`,{class:`recovery-summary-item`,children:[r(`span`,{class:`recovery-summary-item-icon`,"aria-hidden":`true`,children:r(D,{})}),r(`span`,{class:`recovery-summary-item-text`,children:[r(`span`,{class:`recovery-summary-item-title`,children:r(o,{message:`Wallet`})}),r(`span`,{class:`recovery-summary-item-detail`,children:e.walletId})]})]}),n&&r(`button`,{type:`button`,class:`recovery-backup-button secondary recovery-summary-open`,disabled:s,onClick:this.openRecoveryCodes,children:s?r(i,{children:[r(o,{message:`Opening recovery codes`}),r(`span`,{class:`recovery-summary-ellipsis`,"aria-hidden":`true`,children:[r(`span`,{children:`.`}),r(`span`,{children:`.`}),r(`span`,{children:`.`})]})]}):r(o,{message:`View recovery codes`})}),r(`p`,{class:`recovery-summary-live-status`,role:`status`,"aria-live":`polite`,children:e.loadState.kind===`loading`?r(o,{message:`Loading recovery-code status…`}):``}),t&&r(`p`,{class:`recovery-summary-error`,role:`alert`,children:r(o,{copy:t})}),e.actionError&&r(`p`,{class:`recovery-summary-error`,role:`alert`,children:r(o,{copy:e.actionError})}),e.loadState.kind===`error`&&r(`button`,{type:`button`,class:`recovery-backup-button secondary`,onClick:this.retryStatus,children:r(o,{message:`Retry status`})})]})]})}renderRecoveryCodes(e){let t=e.continuation===`registration_may_defer`?`Each code can recover your wallet once. Save them now, or back them up later from Recovery Codes.`:`Each code can recover your wallet once. Keep them somewhere private.`;return r(i,{children:[r(`h1`,{id:`seams-wallet-recovery-title`,class:`recovery-backup-title`,tabIndex:-1,children:r(o,{message:`Save your recovery codes`})}),r(`p`,{id:`seams-wallet-recovery-description`,class:`recovery-backup-description`,children:r(o,{copy:t})}),r(`div`,{class:`recovery-code-sheet`,children:[r(`div`,{class:`recovery-code-sheet-heading`,children:[r(`span`,{children:r(o,{message:`Recovery codes`})}),r(`span`,{children:r(o,{message:`{value0} single-use codes`,values:{value0:e.recoveryCodes.length}})})]}),r(`ol`,{class:`recovery-code-list`,children:e.recoveryCodes.map(w)})]}),r(`div`,{class:`recovery-backup-actions`,children:[r(`button`,{type:`button`,class:`recovery-backup-button primary`,onClick:this.download,children:r(o,{message:`Download codes`})}),r(`button`,{type:`button`,class:`recovery-backup-button secondary recovery-backup-copy${this.state.copied?` copied`:``}`,onClick:this.copy,children:[r(O,{}),r(o,{message:`Copy codes`})]})]}),r(`div`,{class:`recovery-backup-footer`,children:[r(`label`,{class:`recovery-backup-acknowledgement`,children:[r(`input`,{type:`checkbox`,"data-seams-wallet-recovery-backup-acknowledgement":!0,checked:this.state.acknowledged,onChange:this.onAcknowledgementChange}),r(`span`,{children:[r(o,{message:`I saved these recovery codes somewhere safe.`}),r(`small`,{children:r(o,{message:`They won’t be shown again after you finish.`})})]})]}),r(`button`,{type:`button`,class:`recovery-backup-button ${this.state.acknowledged?`primary`:`secondary`}`,"data-seams-wallet-recovery-backup-close":!0,onClick:this.closeRecoveryCodes,children:r(o,{copy:C(e,this.state.acknowledged)})})]}),r(`p`,{class:`recovery-backup-status`,role:`status`,children:r(o,{copy:this.state.statusMessage})})]})}};function E(){return r(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,children:[r(`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`}),r(`path`,{d:`m9 12 2 2 4-4`})]})}function D(){return r(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,children:[r(`path`,{d:`M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1`}),r(`path`,{d:`M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4`})]})}function O(){return r(`span`,{class:`copy-icon`,"aria-hidden":`true`,children:[r(`span`,{class:`copy-icon-check`,children:r(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,children:r(`path`,{d:`M20 6 9 17l-5-5`})})}),r(`span`,{class:`copy-icon-copy`,children:r(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,children:[r(`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`}),r(`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`})]})})]})}let k=0;var A=class{element;dialog;document;input;state=`mounted`;constructor(e){this.input=e,this.document=e.parent.ownerDocument,this.element=this.document.createElement(`div`),this.element.id=`seams-recovery-surface-${++k}`,this.element.className=`seams-wallet-ui seams-recovery-code-backup-host`,this.element.lang=e.appearance?.locale??`en`,this.element.dataset.seamsRecoverySurface=e.surface,e.appearance&&(this.element.dataset.theme=e.appearance.theme.mode,s(this.document).setDynamicRule(this.element.id,u(this.element.id,e.appearance))),this.dialog=this.document.createElement(`dialog`),this.dialog.className=`seams-host-themed-dialog`,this.dialog.tabIndex=-1,this.dialog.setAttribute(`data-seams-wallet-recovery-backup-dialog`,``),this.dialog.dataset.seamsRecoverySurface=e.surface,this.dialog.setAttribute(`aria-labelledby`,`seams-wallet-recovery-title`),this.dialog.setAttribute(`aria-describedby`,`seams-wallet-recovery-description`),this.dialog.addEventListener(`cancel`,this.handleCancel),this.element.appendChild(this.dialog),e.parent.appendChild(this.element);try{this.render(e.experience),this.dialog.showModal(),this.focusTitle(),e.onShown(this.dialog)}catch(e){throw this.dispose(),e}}update(e){this.state!==`disposed`&&this.render(e)}dispose(){this.state!==`disposed`&&(this.state=`disposed`,this.dialog.removeEventListener(`cancel`,this.handleCancel),n(null,this.dialog),this.dialog.open&&this.dialog.close(),s(this.document).deleteDynamicRule(this.element.id),this.element.remove())}render(e){this.state!==`disposed`&&(this.element.dataset.seamsRecoveryEntry=e.kind,n(c(this.input.appearance?.locale??`en`,r(T,{experience:e,onClose:this.input.onClose,onStageChange:this.handleStageChange})),this.dialog))}handleCancel=e=>{e.preventDefault(),this.input.onCancel()};handleStageChange=e=>{this.state!==`disposed`&&(this.dialog.dataset.seamsRecoveryStage=e)};focusTitle(){this.dialog.querySelector(`.recovery-backup-title`)?.focus()}};function j(e){return new A(e)}export{j as mountRecoveryCodeBackupSurface};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{E as e,g as t,i as n}from"./domainIds-t1lp25yU.js";import{t as r}from"./digests-BIaE0DMd.js";import{t as i}from"./activeWalletSession-BJ4B-nJo.js";import{r as a}from"./canonicalPrimitives-Jd3i_Ngz.js";import{c as o,r as s}from"./types-A-w1cYlJ.js";import{l as c,o as ee}from"./accountIds-DGWFzEnw.js";import{a as te,c as l,o as u}from"./ecdsaChainTarget-BoRVQtjQ.js";import{$ as d,X as f,et as p,tt as m,ut as h}from"./digestEncoding-34kXJoJr.js";import{t as g}from"./signerSlot-BlijMq8C.js";import{c as _,i as v,l as y,n as b,r as x}from"./walletCapabilityBindings-mPx-6_r-.js";import{C as S,T as C,o as w}from"./emailOtpEcdsaDerivationIdentity-Qd4pBwHv.js";function T(e){throw Error(`[SigningSession] unsupported exact signing lane branch: ${String(e)}`)}function E(e,t){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`[SigningSession] ${t} must be an object`);return e}function D(e,t){let n=String(e??``).trim();if(!n)throw Error(`[SigningSession] ${t} is required`);return n}function O(e,t,n){for(let r of t)if(e[r]!==void 0)throw Error(`[SigningSession] ${n} exact lane cannot include ${r}`)}function k(t){let n=E(t,`exact lane auth`);switch(n.kind){case`voiceid`:{let t=e(n.walletAuthMethodId);if(!t.ok)throw Error(`VoiceID lane method ID is invalid`);return{kind:`voiceid`,walletAuthMethodId:t.value,deviceKeyId:a(n.deviceKeyId)}}case`passkey`:return{kind:`passkey`,rpId:C(n.rpId),credentialIdB64u:D(n.credentialIdB64u,`credentialIdB64u`)};case`email_otp`:return{kind:`email_otp`,providerSubjectId:D(n.providerSubjectId,`providerSubjectId`)};default:throw Error(`[SigningSession] exact lane auth kind is unsupported`)}}function A(e){let t=E(e,`ECDSA exact lane chainTarget`),n=te({kind:t.kind,namespace:t.namespace,chainId:t.chainId,networkSlug:t.networkSlug});if(t.key!=null&&String(t.key)!==u(n))throw Error(`[SigningSession] exact ECDSA lane chain target key mismatch`);return n}function j(e){let t=E(e,`ECDSA exact lane key identity`);if(t.keyScope!==`evm-family`)throw Error(`[SigningSession] exact ECDSA lane keyScope must be evm-family`);return w({walletId:t.walletId,ecdsaThresholdKeyId:t.ecdsaThresholdKeyId,signingRootId:t.signingRootId,signingRootVersion:t.signingRootVersion,participantIds:t.participantIds,thresholdOwnerAddress:t.thresholdOwnerAddress})}function M(e){let n=t(e);if(!n.ok)throw Error(n.error.message);return n.value}function N(e){let t=c(e.nearAccountId);if(!t.ok)throw Error(`[SigningSession] invalid exact Ed25519 NEAR account: ${t.message}`);let n=_({walletId:l(e.walletId)});return ee(t.value)?b({wallet:n,nearAccountId:t.value}):x({wallet:n,nearAccountId:t.value})}function P(e){let t=Number(e.signerSlot);if(!Number.isSafeInteger(t)||t<1)throw Error(`[SigningSession] exact Ed25519 signer requires signerSlot >= 1`);return v({account:N({walletId:e.walletId,nearAccountId:e.nearAccountId}),nearEd25519SigningKeyId:e.nearEd25519SigningKeyId,signerSlot:t})}function F(e){if(String(e.key.walletId)!==String(e.walletId))throw Error(`[SigningSession] exact ECDSA lane identity wallet mismatch`);let t=M(e.materialActivation);if(String(t.materialOwner)!==String(e.walletId))throw Error(`[SigningSession] exact ECDSA lane material owner mismatch`);return{kind:`evm_family_ecdsa_signer`,walletId:l(e.walletId),chainTarget:e.chainTarget,keyHandle:e.keyHandle,key:e.key,materialActivation:t}}function I(e){let t=E(e,`ECDSA exact lane signer`);if(t.kind!==`evm_family_ecdsa_signer`)throw Error(`[SigningSession] expected EVM-family ECDSA signer`);let n=A(t.chainTarget),r=j(t.key);return F({walletId:l(t.walletId),chainTarget:n,keyHandle:S(t.keyHandle),key:r,materialActivation:M(t.materialActivation)})}function L(e){return e.kind===`evm`?{key:u(e),kind:`evm`,namespace:`eip155`,chainId:e.chainId}:{key:u(e),kind:`tempo`,chainId:e.chainId}}function R(e){return{walletId:String(e.walletId),keyScope:e.keyScope,ecdsaThresholdKeyId:String(e.ecdsaThresholdKeyId),signingRootId:String(e.signingRootId),signingRootVersion:String(e.signingRootVersion),participantIds:[...e.participantIds].map(e=>Number(e)),thresholdOwnerAddress:String(e.thresholdOwnerAddress).toLowerCase()}}function z(e){switch(e.kind){case`voiceid`:return{kind:`voiceid`,walletAuthMethodId:e.walletAuthMethodId,deviceKeyId:e.deviceKeyId};case`passkey`:return{kind:`passkey`,rpId:String(e.rpId),credentialIdB64u:String(e.credentialIdB64u)};case`email_otp`:return{kind:`email_otp`,providerSubjectId:String(e.providerSubjectId)};default:return T(e)}}function B(e){return{kind:`evm_family_ecdsa_signer`,walletId:String(e.walletId),keyHandle:String(e.keyHandle),chainTarget:L(e.chainTarget),key:R(e.key),materialActivation:{kind:e.materialActivation.kind,activationId:String(e.materialActivation.activationId),capability:String(e.materialActivation.capability),materialOwner:String(e.materialActivation.materialOwner),keyBinding:String(e.materialActivation.keyBinding),lifecycleBinding:String(e.materialActivation.lifecycleBinding),signingWorker:String(e.materialActivation.signingWorker)}}}function V(e){return Q(e)?{kind:`exact_signing_lane`,signer:B(e.signer),auth:z(e.auth)}:{kind:`exact_signing_lane`,signer:{kind:`near_ed25519_signer`,account:{kind:e.signer.account.kind,walletId:String(e.signer.account.wallet.walletId),nearAccountId:String(e.signer.account.nearAccountId)},nearEd25519SigningKeyId:String(e.signer.nearEd25519SigningKeyId),signerSlot:Number(e.signer.signerSlot)},auth:z(e.auth),walletSessionId:String(e.walletSessionId),quotaId:String(e.quotaId),thresholdSessionId:String(e.thresholdSessionId)}}function H(e){return r(V(e))}function U(e){return{kind:`exact_signing_lane`,signer:e.signer,auth:e.auth,walletSessionId:s.walletSession(e.walletSessionId),quotaId:s.walletSessionQuota(e.quotaId),thresholdSessionId:s.thresholdEd25519Session(e.thresholdSessionId)}}function W(e){return{kind:`exact_ed25519_export_material`,signer:e.signer,auth:e.auth,thresholdSessionId:s.thresholdEd25519Session(e.thresholdSessionId)}}function G(e){return{kind:`exact_signing_lane`,signer:e.signer,auth:e.auth}}function K(e){return e.identity}function q(e){return e.identity}function J(e){return e.identity}function Y(e){let t=E(e,`exact Ed25519 export material identity`);if(t.kind!==`exact_ed25519_export_material`)throw Error(`[SigningSession] expected exact Ed25519 export material identity`);O(t,[`walletSessionId`,`quotaId`,`walletId`,`nearAccountId`,`nearEd25519SigningKeyId`,`chainTarget`,`keyHandle`,`key`,`curve`,`chainFamily`,`accountId`,`subjectId`,`authMethod`,`authorization`],`nested`);let n=y(E(t.signer,`exact Ed25519 export material signer`));if(!n.ok)throw Error(n.error.message);return W({signer:n.value,auth:k(t.auth),thresholdSessionId:t.thresholdSessionId})}function X(e){let t=Z(e);if(Q(t))return t;throw Error(`[SigningSession] expected exact ECDSA lane identity`)}function Z(e){let t=E(e,`exact signing lane identity`);if(t.kind!==`exact_signing_lane`)throw Error(`[SigningSession] expected exact signing lane identity`);O(t,[`walletId`,`nearAccountId`,`nearEd25519SigningKeyId`,`chainTarget`,`keyHandle`,`key`,`curve`,`chainFamily`,`accountId`,`subjectId`,`authMethod`,`authorization`],`nested`);let n=E(t.signer,`exact lane signer`),r=k(t.auth);switch(n.kind){case`near_ed25519_signer`:{let e=y(n);if(!e.ok)throw Error(e.error.message);return U({signer:e.value,auth:r,walletSessionId:t.walletSessionId,quotaId:t.quotaId,thresholdSessionId:t.thresholdSessionId})}case`evm_family_ecdsa_signer`:return G({signer:I(n),auth:r});default:throw Error(`[SigningSession] exact signing lane signer kind is unsupported`)}}function Q(e){return e.signer.kind===`evm_family_ecdsa_signer`}function ne(e){switch(e.signer.kind){case`near_ed25519_signer`:return e.signer.account.wallet.walletId;case`evm_family_ecdsa_signer`:return e.signer.walletId;default:return T(e.signer)}}function re(e,t){if(e.signer.kind!==`evm_family_ecdsa_signer`)throw Error(`[SigningSession] ${t} requires an EVM-family ECDSA signer`);return e.signer}function ie(e,t){if(e.signer.kind!==`near_ed25519_signer`)throw Error(`[SigningSession] ${t} requires a NEAR Ed25519 signer`);return e.signer}function ae(e,t=`NEAR protocol projection`){let n=ie(e,t);return{walletId:n.account.wallet.walletId,nearAccountId:n.account.nearAccountId,nearEd25519SigningKeyId:n.nearEd25519SigningKeyId,signerSlot:n.signerSlot}}function oe(e,t){return H(e)===H(t)}function se(e){return String(m(e.authority))}function ce(e){return p(e.authority)}function le(e){return d(e.authority)}function ue(e){switch(e.use.kind){case`session`:return`session`;case`single_use_pending`:case`single_use_consumed`:return`single_use`}throw e.use,Error(`[SigningSession] unsupported Email OTP auth use`)}function de(e){return e.use.kind===`single_use_consumed`?e.use.consumedAtMs:null}function fe(e){return e.use.kind===`session`}function pe(e){return e.use.kind===`single_use_pending`}function $(e){if(e.policy===`per_operation`&&e.retention!==`single_use`)throw Error(`Invalid Email OTP auth context: per-operation sessions must be single-use`);if(e.retention===`single_use`&&Object.prototype.hasOwnProperty.call(e,`reason`))throw Error(`Invalid Email OTP auth context: single-use sessions must not carry reason`);let t=Math.floor(Number(e.consumedAtMs)||0),n=e.retention===`session`?{kind:`session`,reason:e.reason}:t>0?{kind:`single_use_consumed`,consumedAtMs:t}:{kind:`single_use_pending`};return{policy:e.policy,authMethod:`email_otp`,authority:e.authority,use:n}}function me(e){let t=e.authority;if(e.retention===`session`)return $({policy:e.policy,reason:e.reason,retention:`session`,authority:t});if(Object.prototype.hasOwnProperty.call(e,`reason`))throw Error(`Invalid Email OTP auth context: single-use sessions must not carry reason`);let n=Math.floor(Number(e.consumedAtMs)||0);return $(n>0?{policy:e.policy,retention:`single_use`,authority:t,consumedAtMs:n}:{policy:e.policy,retention:`single_use`,authority:t})}function he(e){let t=f({walletId:e.walletId,provider:e.provider,providerUserId:e.providerUserId,emailHashHex:e.emailHashHex});if(e.retention===`session`)return $({policy:e.policy,reason:e.reason,retention:`session`,authority:t});if(Object.prototype.hasOwnProperty.call(e,`reason`))throw Error(`Invalid Email OTP auth context: single-use sessions must not carry reason`);let n=Math.floor(Number(e.consumedAtMs)||0);return $(n>0?{policy:e.policy,retention:`single_use`,authority:t,consumedAtMs:n}:{policy:e.policy,retention:`single_use`,authority:t})}function ge(e){let t=g(e.signerSlot);if(t==null)throw Error(`[SigningSession] selected Ed25519 lane requires signerSlot >= 1`);let n=s.walletSession(e.walletSessionId),r=s.walletSessionQuota(e.quotaId),i=s.thresholdEd25519Session(e.thresholdSessionId);return{kind:`selected_lane`,identity:U({signer:P({walletId:e.walletId,nearAccountId:e.nearAccountId,nearEd25519SigningKeyId:e.nearEd25519SigningKeyId,signerSlot:t}),auth:e.auth,walletSessionId:n,quotaId:r,thresholdSessionId:i}),auth:e.auth,curve:`ed25519`,chain:`near`,walletSessionId:n,quotaId:r,thresholdSessionId:i}}function _e(e){if(!e.key)throw Error(`[SigningSession] selected ECDSA lane requires shared key identity`);let t=S(e.keyHandle);if(String(e.key.walletId)!==String(e.walletId))throw Error(`[SigningSession] selected ECDSA lane wallet mismatch`);return{kind:`selected_lane`,identity:G({signer:F({walletId:e.walletId,chainTarget:e.chainTarget,keyHandle:t,key:e.key,materialActivation:e.materialActivation}),auth:e.auth}),auth:e.auth,curve:`ecdsa`,chain:e.chainTarget.kind,materialActivation:e.materialActivation,authorization:e.authorization}}function ve(e){let t=Math.floor(Number(e.nowMs)||Date.now());return e.expiresAtMs<=t?`expired`:e.remainingUses<=0?`exhausted`:`ready`}function ye(e){return o(e.auth)}function be(e){switch(e.kind){case`found`:return{kind:`authorized`,authorization:e.authorization};case`expired`:case`exhausted`:return{kind:`operation_step_up`,reason:e.kind};case`persistence_unavailable`:return{kind:`temporarily_unavailable`,reason:e.kind};case`missing`:case`corrupt`:case`upgrade_required`:case`superseded`:case`authority_unavailable`:case`method_unavailable`:case`capability_unavailable`:case`unavailable`:return{kind:`full_login_required`,reason:e.kind};default:throw Error(`[SigningEngine][near] unsupported Wallet Session authorization state`)}}function xe(e){switch(e.kind){case`use_live_runtime`:case`rehydrate_material_activation`:case`reauthorize_public_anchor`:return e.authority;case`blocked`:return null;default:throw Error(`[SigningEngine][near] unsupported MPC hydration plan`)}}function Se(e){let{selectedAuthority:t,selectedAuthMethod:n,selectedFactorAuthority:r}=e;return t.state!==`active`||t.walletId!==n.walletId||t.authorityId!==n.walletAuthorityId||t.signerActivations.ed25519===void 0||r.walletId!==n.walletId||r.bindingId!==n.walletAuthMethodId?!1:n.kind===`voiceid`?r.factor.kind===`voiceid`&&r.factor.deviceKeyId===n.deviceKeyId&&r.verifier.kind===`device_signature`:n.kind===`passkey`?r.factor.kind===`passkey`&&r.factor.credentialIdB64u===n.credentialIdB64u&&r.verifier.kind===`webauthn`&&r.verifier.rpId===n.rpId:r.factor.kind===`email_otp`&&r.verifier.kind===`email_otp_wallet_auth_method`&&r.verifier.emailHashHex===n.emailHashHex&&r.factor.providerUserId.trim().length>0}function Ce(e){let{authorization:t,nowMs:n}=e,{selectedAuthority:r,selectedAuthMethod:a,session:o,operationCredential:s,status:c}=t;return!(!Se({selectedAuthority:r,selectedAuthMethod:a,selectedFactorAuthority:t.selectedFactorAuthority})||o.kind!==`active_wallet_session_v1`||o.walletId!==r.walletId||o.authorityId!==r.authorityId||o.authMethodId!==a.walletAuthMethodId||o.authorityDigestB64u!==r.authorityDigestB64u||o.authorityRevocationEpoch!==r.revocationEpoch||s.kind!==`opaque_wallet_session_operation_credential_v1`||s.token.trim().length===0||s.walletSessionId.trim().length===0||o.authorizationId.trim().length===0||o.quotaId.trim().length===0||o.expiresAtMs<=n||c.status!==`active`||c.walletSessionId!==s.walletSessionId||c.quotaId!==o.quotaId||c.remainingUses<=0||c.expiresAtMs<=n||c.quotaLifecycle!==`active`||c.authorization.expiresAtMs!==o.expiresAtMs||!i(c.authorization,o))}function we(e){let t=0;for(let r of e.session.capabilitySubjects)r.kind===`sign`&&r.keyFamily===`ed25519`&&n(r.materialActivation,e.materialActivation)&&(t+=1);return t===1}async function Te(e){let t=xe(e.hydration);if(!t)return;let n=await h({authority:e.authorization.selectedFactorAuthority});if(t.walletId!==n.walletId||t.walletAuthMethodId!==n.walletAuthMethodId||t.authorityDigest!==n.authorityDigest)throw Error(`[SigningEngine][near] Wallet Session authorization does not match material authority`)}function Ee(e){let{requirement:t,authorization:n}=e;if(t.kind!==n.selectedAuthMethod.kind)throw Error(`[SigningEngine][near] Wallet Session authorization does not match material factor`);if(t.kind===`voiceid`){if(n.selectedAuthMethod.kind!==`voiceid`||t.walletAuthMethodId!==n.selectedAuthMethod.walletAuthMethodId||t.deviceKeyId!==n.selectedAuthMethod.deviceKeyId)throw Error(`[SigningEngine][near] Wallet Session authorization does not match VoiceID factor`);return}if(t.kind===`passkey`){if(n.selectedAuthMethod.kind!==`passkey`||String(t.rpId)!==String(n.selectedAuthMethod.rpId)||t.credentialIdB64u!==n.selectedAuthMethod.credentialIdB64u)throw Error(`[SigningEngine][near] Wallet Session authorization does not match Passkey factor`);return}if(n.selectedAuthMethod.kind!==`email_otp`||n.selectedFactorAuthority.factor.kind!==`email_otp`||t.providerSubjectId!==n.selectedFactorAuthority.factor.providerUserId)throw Error(`[SigningEngine][near] Wallet Session authorization does not match Email OTP factor`)}function De(e){if(!Number.isSafeInteger(e.nowMs)||e.nowMs<0)throw Error(`[SigningEngine][near] Wallet Session authorization requires a valid timestamp`);let t={kind:`exact_near_ed25519_wallet_session_authorization_v1`,selectedAuthority:e.selectedAuthority,selectedAuthMethod:e.selectedAuthMethod,selectedFactorAuthority:e.selectedFactorAuthority,session:e.session,operationCredential:e.operationCredential,status:e.status};if(!Ce({authorization:t,nowMs:e.nowMs}))throw Error(`[SigningEngine][near] Exact Wallet Session authorization identity is invalid`);return t}async function Oe(e){return Ee(e),await Te(e),{kind:`near_ed25519_yao_signing_preparation`,hydration:e.hydration,authorization:{kind:`authorized`,authorization:e.authorization}}}function ke(e){return{kind:`near_ed25519_yao_signing_preparation`,hydration:e.hydration,authorization:{kind:`authorization_required`,requirement:e.requirement}}}export{Q as A,W as C,H as D,K as E,re as F,ae as M,X as N,oe as O,Y as P,J as S,q as T,ve as _,we as a,F as b,me as c,ce as d,se as f,ye as g,fe as h,be as i,P as j,ne as k,de as l,pe as m,ke as n,$ as o,ue as p,Oe as r,he as s,De as t,le as u,_e as v,U as w,G as x,ge as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./secureRandomId-8LSc91aN.js";import{o as t}from"./ecdsaChainTarget-
|
|
1
|
+
import{r as e}from"./secureRandomId-8LSc91aN.js";import{o as t}from"./ecdsaChainTarget-BoRVQtjQ.js";const n={Reserved:`reserved`,Released:`released`,Expired:`expired`,Signed:`signed`,SignedLeaseExpired:`signed_lease_expired`,BroadcastAccepted:`broadcast_accepted`,BroadcastRejected:`broadcast_rejected`,Finalized:`finalized`,Dropped:`dropped`,Replaced:`replaced`,Reconciled:`reconciled`},r={Reserved:n.Reserved,Signed:n.Signed,BroadcastAccepted:n.BroadcastAccepted},i={LeaseReserved:`nonce_lease_reserved`,LeaseReleased:`nonce_lease_released`,LeaseExpired:`nonce_lease_expired`,LeaseSigned:`nonce_lease_signed`,LeaseBroadcastAccepted:`nonce_lease_broadcast_accepted`,LeaseBroadcastRejected:`nonce_lease_broadcast_rejected`,LeaseFinalized:`nonce_lease_finalized`,LeaseDropped:`nonce_lease_dropped`,LeaseReplaced:`nonce_lease_replaced`,Metrics:`nonce_coordinator_metrics`,LaneAlert:`nonce_lane_alert`,CoordinationDegraded:`nonce_coordination_degraded`,LanesCleared:`nonce_lanes_cleared`,LaneReconciled:`nonce_lane_reconciled`},a={Dropped:`dropped`,Replaced:`replaced`},o={WebLocksUnavailable:`web_locks_unavailable`,IndexedDBUnavailable:`indexeddb_unavailable`,DurableLockTimeout:`durable_lock_timeout`,DurableStoreError:`durable_store_error`,MalformedDurableRecord:`malformed_durable_record`},s={InRuntimeLock:`in_runtime_lock`,None:`none`},c={NonceAdvancedHashMissing:`near_nonce_advanced_hash_missing`,HashMissingNonceNotAdvanced:`near_hash_missing_nonce_not_advanced`},l=Object.values(n);function u(e){return{family:`evm`,chainTarget:e.chainTarget,subjectId:e.subjectId,sender:e.sender,...e.nonceKey==null?{}:{nonceKey:e.nonceKey}}}function d(e){return y(e),{...m(e.lane),nonce:e.nonce,leaseId:e.leaseId,operationId:String(e.operationId),operationFingerprint:String(e.operationFingerprint),reservedAtMs:e.reservedAtMs,expiresAtMs:e.expiresAtMs}}function f(e){return u(e)}function p(e){return{leaseId:e.leaseId,operationId:String(e.operationId),operationFingerprint:String(e.operationFingerprint),nonce:String(e.nonce),...e.batchId?{batchId:e.batchId}:{},...Number.isSafeInteger(e.txIndex)?{txIndex:e.txIndex}:{}}}function m(e){return{chainTarget:e.chainTarget,subjectId:e.subjectId,sender:e.sender,...e.nonceKey==null?{}:{nonceKey:e.nonceKey}}}function h(e){return e.family===`near`?e.networkKey:t(e.chainTarget)}function g(e){return e.family===`near`?e.walletId:e.subjectId}function _(e){return e.family===`near`?v(e):C([`evm`,t(e.chainTarget),e.subjectId,e.sender.toLowerCase(),e.nonceKey==null?``:String(e.nonceKey)])}function v(e){return C([`near`,e.networkKey,e.walletId,e.nearAccountId,e.publicKey])}function y(e){if(e.lane.family!==`evm`)throw Error(`[NonceCoordinator] expected an EVM-family nonce lease`)}function b(e,t,n){if(e.operationId!==t)throw Error(`[NonceCoordinator] nonce lease operation mismatch`);if(e.operationFingerprint!==n)throw Error(`[NonceCoordinator] nonce lease operation fingerprint mismatch`)}function x(t){let n=e(`nonce-lease`,32,`nonce lease IDs`);return`nonce-lease-v1:${C([t.chain,t.operationId,t.nonce,n])}`}function S(t){let n=e(`nonce-batch`,32,`nonce batch IDs`);return`nonce-batch-v1:${C([t.chain,t.operationId,t.firstNonce,t.count,n])}`}function C(e){return e.map(e=>{let t=String(e);return`${t.length}:${t}`}).join(`|`)}function w(){return e(`nonce-runtime`,32,`nonce runtime IDs`)}export{o as _,w as a,r as b,d as c,h as d,g as f,c as g,l as h,x as i,u as l,a as m,b as n,m as o,p,S as r,f as s,y as t,_ as u,s as v,n as x,i as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{R as e,z as t}from"./domainIds-t1lp25yU.js";import{o as n}from"./ecdsaChainTarget-
|
|
1
|
+
import{R as e,z as t}from"./domainIds-t1lp25yU.js";import{o as n}from"./ecdsaChainTarget-BoRVQtjQ.js";function r(e){let n=t(e);return!n||n===`null`?null:n}function i(t){return e(t)}function a(t){return e(t)}function o(t){return e(t)}function s(e){return n(e)}function c(e){return typeof e==`string`&&e.length>0&&e.trim()===e?e:null}function l(e){return[e.chainIdKey,e.accountAddress].join(`\0`)}export{c as a,r as i,o as n,l as o,i as r,s,a as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{E as e,k as t}from"./domainIds-t1lp25yU.js";import{S as n,b as r,g as i,x as a}from"./digests-BIaE0DMd.js";import{N as o,r as s}from"./activeWalletSession-BJ4B-nJo.js";import{r as c}from"./canonicalPrimitives-Jd3i_Ngz.js";import{t as l}from"./walletIframeIdentity-CpgyEnKg.js";import{o as u}from"./errors-BJBDbwHk.js";import{s as d}from"./nearRpcResults-CeHdqaS4.js";import{n as f}from"./ed25519OperationFingerprint-Dev4P6Og.js";import{r as p}from"./types-A-w1cYlJ.js";import{t as m}from"./accountIds-DGWFzEnw.js";import{t as h}from"./actions-7SvZZut1.js";const g=`__SEAMS_WALLET_SDK_BASE__`,_=`SEAMS_WALLET_SDK_BASE_CHANGED`,v=`__SEAMS_WALLET_ASSET_VERSION__`;function ee(){if(typeof window>`u`)return;let e=window[g];return typeof e==`string`&&e.length>0?e:void 0}function te(e){if(typeof window>`u`)return;let t=window;t[g]=e,window.dispatchEvent(new CustomEvent(_,{detail:e}))}function ne(){if(typeof window>`u`)return;let e=window[v];return typeof e==`string`&&e.length>0?e:void 0}function y(e){if(typeof window>`u`)return;let t=e.trim();t&&(window[v]=t)}function b(e){if(typeof window>`u`)return()=>{};let t=t=>{let n=t.detail;typeof n==`string`&&n.length>0&&e(n)};return window.addEventListener(_,t,{passive:!0}),()=>window.removeEventListener(_,t)}const x={login:{title:`Welcome back`,subtitle:``,passkeyCta:`Unlock with passkey`},register:{title:`Create a wallet`,subtitle:``,passkeyNameLabel:`Wallet name`,passkeyCta:`Create wallet with passkey`},common:{closeLabel:`Close`}};function S(e,t){return typeof e==`string`&&e.trim()||null}function C(e,t){let n=S(e,t);return n===null?null:n}function w(e){try{return l(e)}catch{return null}}function T(e,t){let n=new Set(t);return Object.keys(e).every(e=>n.has(e))}function E(e){return C(e,`authMenuSessionId`)}function D(e){return C(e,`externalAuthRequestId`)}function O(e){return i(e)?e:null}function k(e,t=new Set,n=!1){if(e===void 0)return n;if(e===null||typeof e==`string`||typeof e==`boolean`)return!0;if(typeof e==`number`)return Number.isFinite(e);if(typeof e!=`object`||t.has(e))return!1;if(t.add(e),Array.isArray(e))return e.every(e=>k(e,t,n));let r=O(e);return r!==null&&Object.values(r).every(e=>k(e,t,n))}function A(e,t){return S(e,`copy`)??t}function j(e,t){let n=O(e);return{title:A(n?.title,t.title),subtitle:A(n?.subtitle,t.subtitle),passkeyCta:A(n?.passkeyCta,t.passkeyCta)}}function re(e){let t=O(e),n=O(t?.register);return{login:j(t?.login,x.login),register:{...j(t?.register,x.register),passkeyNameLabel:A(n?.passkeyNameLabel,x.register.passkeyNameLabel)},common:{closeLabel:A(O(t?.common)?.closeLabel,x.common.closeLabel)}}}function ie(e){return e===`google`?e:null}function M(e){return e===`login`||e===`register`?e:null}function ae(e){return e===`implicit_wallet`||e===`sponsored_named_near_account`?e:null}function oe(e){return e===`close_button`||e===`component_unmounted`||e===`connection_closed`?e:null}function N(e,t){if(e===void 0)return!0;let n=O(e);return n!==null&&T(n,t)}function P(e){let t=O(e);return!t||!T(t,[`login`,`register`,`common`])?!1:N(t.login,[`title`,`subtitle`,`passkeyCta`])&&N(t.register,[`title`,`subtitle`,`passkeyCta`,`passkeyNameLabel`])&&N(t.common,[`closeLabel`])}function F(e){if(!Array.isArray(e))return null;let t=[];for(let n of e){let e=ie(n);if(!e)return null;t.push(e)}return t}function I(e){let n=O(e);if(!n||!k(n,new Set,!0)||n.kind!==`hosted_auth_menu_open_v1`||!T(n,[`kind`,`authMenuSessionId`,`initialMode`,`initialHeightCssPx`,`loginTarget`,`registrationAccountInput`,`showRegistrationInput`,`showProgress`,`copy`,`enabledExternalProviders`])||!P(n.copy))return null;let r=E(n.authMenuSessionId),i=M(n.initialMode),a=n.initialHeightCssPx;if(a!==void 0&&(typeof a!=`number`||!Number.isFinite(a)||a<=0))return null;let o=O(n.loginTarget),s=o?.kind===`wallet`||o?.kind===`wallet_sync`?t(o.walletId):null,c=o?.kind===`discoverable`&&T(o,[`kind`])?{kind:`discoverable`}:o?.kind===`wallet`&&T(o,[`kind`,`walletId`])&&s?.ok?{kind:`wallet`,walletId:s.value}:o?.kind===`wallet_sync`&&T(o,[`kind`,`walletId`])&&s?.ok?{kind:`wallet_sync`,walletId:s.value}:null,l=ae(n.registrationAccountInput),u=F(n.enabledExternalProviders);return!r||!i||!c||!l||typeof n.showRegistrationInput!=`boolean`||typeof n.showProgress!=`boolean`||!u||!k(n.copy,new Set,!0)?null:{kind:`hosted_auth_menu_open_v1`,authMenuSessionId:r,initialMode:i,initialHeightCssPx:a,loginTarget:c,registrationAccountInput:l,showRegistrationInput:n.showRegistrationInput,showProgress:n.showProgress,copy:re(n.copy),enabledExternalProviders:u}}function L(e){let t=O(e);if(!t||!k(t)||t.kind!==`hosted_auth_menu_error_v1`||!T(t,[`kind`,`authMenuSessionId`,`mode`,`message`]))return null;let n=E(t.authMenuSessionId),r=M(t.mode),i=S(t.message,`message`);return n&&r&&i?{kind:t.kind,authMenuSessionId:n,mode:r,message:i}:null}function R(e){let t=O(e);if(!t||!k(t))return null;switch(t.kind){case`google_id_token`:{if(!T(t,[`kind`,`idToken`]))return null;let e=S(t.idToken,`idToken`);return e?{kind:t.kind,idToken:e}:null}case`cancelled`:return T(t,[`kind`,`reason`])&&t.reason===`user_cancelled`?{kind:t.kind,reason:t.reason}:null;case`failed`:{if(!T(t,[`kind`,`code`,`message`]))return null;let e=t.code===`provider_unavailable`||t.code===`provider_error`||t.code===`invalid_evidence`?t.code:null,n=S(t.message,`message`);return e&&n?{kind:t.kind,code:e,message:n}:null}default:return null}}function z(e){let t=O(e);if(!t||!k(t)||t.kind!==`hosted_auth_menu_external_auth_resolution_v1`||!T(t,[`kind`,`authMenuSessionId`,`externalAuthRequestId`,`requestId`,`evidence`]))return null;let n=E(t.authMenuSessionId),r=D(t.externalAuthRequestId),i=w(t.requestId),a=R(t.evidence);return!n||!r||!i||!a?null:{kind:t.kind,authMenuSessionId:n,externalAuthRequestId:r,requestId:i,evidence:a}}function B(e){let t=O(e);if(!t||!k(t)||t.kind!==`hosted_auth_menu_cancel_v1`||!T(t,[`kind`,`authMenuSessionId`,`requestId`,`reason`]))return null;let n=E(t.authMenuSessionId),r=w(t.requestId),i=oe(t.reason);return n&&r&&i?{kind:t.kind,authMenuSessionId:n,requestId:r,reason:i}:null}const V=`19.0.0`,H=`WALLET_IFRAME_PROTOCOL_VERSION_MISMATCH`,U=[`home`,`exchangeCode`,`nonce`,`appOrigin`,`walletOrigin`,`relayUrl`];function W(e,t){if(typeof e!=`string`||e.length===0||e.length>512||e.trim()!==e||/[\s\u0000-\u001f\u007f]/.test(e))throw Error(`${t} must be a compact opaque identifier`);return e}function G(e,t){if(typeof e!=`string`||e.length===0||e.trim()!==e)throw Error(`${t} must be a canonical HTTP origin`);let n;try{n=new URL(e)}catch{throw Error(`${t} must be a canonical HTTP origin`)}if(n.protocol!==`https:`&&n.protocol!==`http:`||n.origin!==e||n.pathname!==`/`||n.search!==``||n.hash!==``)throw Error(`${t} must be a canonical HTTP origin`);return n.origin}function K(e){if(!i(e))throw Error(`hosted-wallet redemption payload must be an exact object`);if(Object.keys(e).length!==U.length)throw Error(`hosted-wallet redemption payload fields are invalid`);for(let t of U)if(!Object.hasOwn(e,t))throw Error(`hosted-wallet redemption payload fields are invalid`);return{home:s(e.home),exchangeCode:W(e.exchangeCode,`exchangeCode`),nonce:W(e.nonce,`nonce`),appOrigin:G(e.appOrigin,`appOrigin`),walletOrigin:G(e.walletOrigin,`walletOrigin`),relayUrl:W(e.relayUrl,`relayUrl`)}}function q(t){if(!i(t)||!T(t,[`scanRequestId`,`action`])||typeof t.scanRequestId!=`string`||t.scanRequestId.length===0||!i(t.action))return null;let n=t.action;if(n.kind===`cancel`)return T(n,[`kind`])?{scanRequestId:t.scanRequestId,action:{kind:n.kind}}:null;if(n.kind!==`select`||!T(n,[`kind`,`baseWalletAuthMethodId`]))return null;let r=e(n.baseWalletAuthMethodId);return r.ok?{scanRequestId:t.scanRequestId,action:{kind:n.kind,baseWalletAuthMethodId:r.value}}:null}function se(e){if(!i(e)||!T(e,[`activationId`,`action`])||typeof e.activationId!=`string`||e.activationId.length===0||!i(e.action))return null;let t=e.action;switch(t.kind){case`create_passkey`:case`send_email_otp`:case`resend_email_otp`:return T(t,[`kind`])?{activationId:e.activationId,action:{kind:t.kind}}:null;case`submit_email_otp`:return T(t,[`kind`,`otpCode`])&&typeof t.otpCode==`string`&&/^\d{6}$/.test(t.otpCode)?{activationId:e.activationId,action:{kind:t.kind,otpCode:t.otpCode}}:null;default:return null}}function ce(e){let t=n(e,`NEAR transaction result`);if(t.success===!0){let e=r(t.transactionId,`transactionId`),n=d(t.result);if(e!==n.transaction.hash)throw Error(`NEAR transaction result contains different transaction hashes`);return typeof n.status==`object`&&`Failure`in n.status?J(e,Error(`NEAR transaction execution failed`)):{success:!0,transactionId:e,result:n}}if(t.success!==!1)throw Error(`Invalid NEAR transaction result`);let i=a(t.error,`NEAR transaction error`);switch(t.kind){case`not_submitted`:return{success:!1,kind:`not_submitted`,error:i};case`submission_unknown`:return{success:!1,kind:`submission_unknown`,error:i};case`unresolved`:return{success:!1,kind:`unresolved`,transactionId:r(t.transactionId,`transactionId`),error:i};default:throw Error(`Invalid NEAR transaction failure`)}}function le(e,t){return{success:!1,kind:t,error:u(e)||`NEAR transaction failed`}}function J(e,t){return{success:!1,kind:`unresolved`,transactionId:e,error:u(t)}}function ue(){return{appIdentity:{kind:`anonymous`},authentication:{kind:`signed_out`},capabilityProjection:{kind:`not_requested`},nonceDiagnostics:null}}let Y=0;function de(){return Y+=1,Y}const fe=`/wallet/external-auth`;function pe(e){let t=n(e,`external identity`),i=t.provider,a=r(t.issuer,`issuer`),o=r(t.subject,`subject`);switch(i){case`google`:if(a!==`https://accounts.google.com`)throw Error(`Invalid Google issuer`);return{provider:i,issuer:a,subject:o};case`application`:return{provider:i,issuer:a,subject:o};default:throw Error(`Invalid external identity provider`)}}function me(e){let i=n(e,`external owner challenge`),a=t(i.walletId);if(!a.ok)throw Error(`Invalid owner challenge wallet`);let s=a.value,l=r(i.attemptId,`attemptId`),u=pe(i.identity),d=c(i.challengeB64u),f=o(i.expiresAtMs,`owner challenge expiry`);switch(i.kind){case`associate`:return{kind:`associate`,walletId:s,attemptId:l,identity:u,challengeB64u:d,expiresAtMs:f};case`unlink`:return{kind:`unlink`,walletId:s,attemptId:l,identity:u,challengeB64u:d,expiresAtMs:f,associationId:r(i.associationId,`associationId`)};default:throw Error(`Invalid owner challenge purpose`)}}function he(e){let t=n(e,`external auth command`);if(t.action===`prepare`||t.action===`prepare_association`)return{action:t.action,walletId:r(t.walletId,`walletId`)};if(t.action===`unlink`)return{action:`unlink`,walletId:r(t.walletId,`walletId`),associationId:r(t.associationId,`associationId`)};if(t.action!==`authenticate`&&t.action!==`associate`)throw Error(`Invalid external authentication command`);let i=n(t.input,`authentication input`),a=r(i.walletId,`walletId`);if(i.method===`google`)return{action:t.action,input:{method:`google`,walletId:a,idToken:r(i.idToken,`idToken`)}};if(i.method===`handoff`)return{action:t.action,input:{method:`handoff`,walletId:a,attemptId:r(i.attemptId,`attemptId`),code:r(i.code,`code`)}};throw Error(`Unsupported external authentication method`)}function X(e){let i=n(e,`external authentication`),a=t(i.walletId);if(!a.ok||i.kind!==`external_authenticated`||i.provider!==`google`&&i.provider!==`application`||i.permission!==`wallet_settings_read`||`authMethod`in i)throw Error(`External authentication is invalid`);return{kind:`external_authenticated`,walletId:a.value,sessionId:r(i.sessionId,`sessionId`),associationId:r(i.associationId,`associationId`),environmentId:r(i.environmentId,`environmentId`),provider:i.provider,permission:`wallet_settings_read`,expiresAtMs:o(i.expiresAtMs,`expiresAtMs`)}}function Z(e){return{ok:!1,code:e,message:`Wallet authentication could not be completed.`}}function ge(e){let t=n(e,`external authentication failure`);switch(t.code){case`invalid_request`:case`invalid_credential`:case`access_denied`:case`expired`:case`superseded`:case`unavailable`:case`rate_limited`:case`cancelled`:return Z(t.code);default:return Z(`unavailable`)}}function _e(e){let t=n(e,`external settings`);if(!Array.isArray(t.accounts)||!Array.isArray(t.methods)||!Array.isArray(t.devices))throw Error(`Invalid wallet settings`);return{authentication:X(t.authentication),accounts:t.accounts.map(Q),methods:t.methods.map(ve),devices:t.devices.map(ye)}}function Q(e){let t=n(e,`account`);if(t.family!==`ed25519`&&t.family!==`ecdsa`)throw Error(`Invalid account family`);return{family:t.family,address:r(t.address,`address`),publicKey:r(t.publicKey,`publicKey`)}}function ve(e){let t=n(e,`method`);if(t.kind!==`passkey`&&t.kind!==`email_otp`&&t.kind!==`voiceid`)throw Error(`Invalid method`);return{id:r(t.id,`id`),kind:t.kind}}function ye(e){return{id:r(n(e,`device`).id,`id`)}}function $(e){let i=n(e,`owner operation recovery`),a=r(i.operationId,`operationId`);if(!/^owner-near:[A-Za-z0-9_-]{32,64}$/.test(a))throw Error(`Invalid owner operation ID.`);let o=t(i.walletId);if(!o.ok)throw Error(`Invalid owner operation wallet.`);return{operationId:p.signingOperation(a),walletId:o.value,nearAccountId:m(r(i.nearAccountId,`nearAccountId`))}}function be(e){let t=n(e,`owner operation command`),r=X(t.authentication),i=$(t.recovery);if(i.walletId!==String(r.walletId))throw Error(`Owner operation wallet mismatch.`);switch(t.action){case`recover`:return{action:`recover`,authentication:r,recovery:i};case`approve`:{let e=n(t.transaction,`transaction`),a=f({nearAccountId:i.nearAccountId,receiverId:e.receiverId,actions:e.actions},`transaction`);if(a.nearAccountId!==String(i.nearAccountId))throw Error(`Owner operation account mismatch.`);let o=t.expiresAtMs;if(typeof o!=`number`||!Number.isSafeInteger(o)||o<=0)throw Error(`Invalid owner operation expiry.`);return{action:`approve`,authentication:r,recovery:i,expiresAtMs:o,transaction:{receiverId:a.receiverId,actions:a.actions.map(Se)}}}default:throw Error(`Invalid owner operation action.`)}}function xe(e){let t=n(e,`owner operation outcome`);switch(t.kind){case`completed`:{let e=ce(t.result);if(!e.success)throw Error(`A completed owner operation requires a successful transaction.`);return{kind:`completed`,result:e}}case`reverted`:return{kind:`reverted`,transactionId:r(t.transactionId,`transactionId`),error:r(t.error,`error`)};case`cancelled`:return{kind:`cancelled`};case`expired`:return{kind:`expired`};case`failed`:return{kind:`failed`,error:r(t.error,`error`)};case`unknown`:return{kind:`unknown`,recovery:$(t.recovery)};default:throw Error(`Invalid owner operation outcome.`)}}function Se(e){switch(e.action_type){case`CreateAccount`:return{action_type:h.CreateAccount};case`DeployContract`:return{action_type:h.DeployContract,code:[...e.code]};case`FunctionCall`:return{action_type:h.FunctionCall,method_name:e.method_name,args:e.args,gas:e.gas,deposit:e.deposit};case`Transfer`:return{action_type:h.Transfer,deposit:e.deposit};case`Stake`:return{action_type:h.Stake,stake:e.stake,public_key:e.public_key};case`AddKey`:return{action_type:h.AddKey,public_key:e.public_key,access_key:e.access_key};case`DeleteKey`:return{action_type:h.DeleteKey,public_key:e.public_key};case`DeleteAccount`:return{action_type:h.DeleteAccount,beneficiary_id:e.beneficiary_id};case`DeployGlobalContract`:return{action_type:h.DeployGlobalContract,code:[...e.code],deploy_mode:e.deploy_mode};case`UseGlobalContract`:return e.account_id===void 0?{action_type:h.UseGlobalContract,code_hash:e.code_hash}:{action_type:h.UseGlobalContract,account_id:e.account_id};case`SignedDelegate`:throw Error(`Use the delegate API for delegated actions.`);default:throw Error(`Unsupported owner transaction action.`)}}export{K as C,y as D,b as E,te as O,I as S,ee as T,q as _,Z as a,L as b,me as c,ue as d,le as f,D as g,V as h,fe as i,_e as l,H as m,xe as n,he as o,J as p,$ as r,ge as s,be as t,de as u,se as v,ne as w,z as x,B as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./secureRandomId-8LSc91aN.js";import{t}from"./surface-measurement-reporter-
|
|
1
|
+
import{r as e}from"./secureRandomId-8LSc91aN.js";import{t}from"./surface-measurement-reporter-DJ_dQhBV.js";import{a as n,n as r}from"./presignatures-CkhuZ0YQ.js";import{A as i}from"./indexedDB-CA4tGqkr.js";import{l as a}from"./helpers-B7c1zc7h.js";function o(e){return String(a(e)||``).trim()}function s(e,t){let n=o(e);if(!n)throw Error(`${t} requires PRF.first output from the passkey credential`);return n}function c(e){return String(e?.rawId||e?.id||``).trim()}const l=`Recovery-code backup was cancelled before acknowledgement`;async function u(e,n={kind:`disabled`},r={}){if(typeof document>`u`)throw Error(`Wallet recovery-code backup requires a browser or a backup handler`);let i=document.activeElement instanceof HTMLElement?document.activeElement:null;if(r.shouldCancel?.())throw Error(l);let a=await import(`./mountRecoveryCodeBackupSurface-C_tJNPJX.js`);if(r.shouldCancel?.())throw Error(l);let o=null,s=null,c=!1;return await new Promise((u,d)=>{let f=()=>{o?.disconnect(),o=null,s?.dispose(),s=null,i?.focus()},m=e=>{c||(c=!0,f(),e instanceof Error?d(e):u(e))},h=t=>{switch(t.kind){case`dismissed`:m(Error(l));return;case`recovery_codes`:if(t.acknowledged){if(e.kind===`account_menu`){if(t.request.continuation!==`pending_backup_must_finish`){m(Error(`Displayed recovery codes have no committed issuance`));return}m({kind:`account_menu_backed_up`,issuedAtMs:t.request.issuedAtMs});return}m({kind:`registration_backed_up`});return}if(e.kind===`direct_backup`&&e.request.continuation===`registration_may_defer`){m({kind:`deferred`});return}m(Error(l));return}};try{s=a.mountRecoveryCodeBackupSurface({parent:document.body,appearance:r.appearance,experience:e,surface:n.kind===`wallet_iframe`?`wallet-iframe`:`standalone`,onClose:h,onCancel:()=>m(Error(l)),onShown:e=>{c||n.kind!==`wallet_iframe`||(o=t({kind:`request_scroll_surface`,requestId:n.requestId,element:e,postMeasurement:p.bind(null,e,n.postMeasurement)}))}})}catch(e){m(e instanceof Error?e:Error(String(e)))}})}async function d(e,t={kind:`disabled`}){switch((await u({kind:`direct_backup`,request:e},t)).kind){case`registration_backed_up`:return{kind:`wallet_recovery_codes_backed_up_v1`};case`deferred`:return{kind:`wallet_recovery_code_backup_deferred_v1`};case`account_menu_backed_up`:throw Error(`Registration backup returned an account-menu issuance`)}}async function f(e,t={kind:`disabled`},n={}){let r=await u({kind:`account_menu`,...e},t,n);if(r.kind!==`account_menu_backed_up`)throw Error(`Account-menu backup did not acknowledge committed recovery codes`);return{kind:`wallet_recovery_codes_backed_up_v1`,issuedAtMs:r.issuedAtMs}}function p(e,t,n){if(n.kind!==`measured_v1`)throw Error(`Recovery codes require a request surface measurement`);t({kind:`measured_v1`,requestId:n.requestId,sequence:n.sequence,widthCssPx:e.dataset.seamsRecoveryStage===`recovery_codes`?688:480,heightCssPx:n.heightCssPx})}const m=`wallet_recovery_codes_v1`,h=[`record_version`,`wallet_id`,`enrollment_id`,`recovery_codes_issued_at_ms`,`status`,`key`,`iv`,`ciphertext`],g=[`record_version`,`wallet_id`,`enrollment_id`,`aad_issued_at_ms`,`pending_backup_id`,`status`,`key`,`iv`,`ciphertext`],_=[...g,`recovery_codes_issued_at_ms`];function v(e){return typeof CryptoKey<`u`&&e instanceof CryptoKey&&e.type===`secret`&&!e.extractable&&e.algorithm.name===`AES-GCM`&&e.usages.includes(`encrypt`)&&e.usages.includes(`decrypt`)}function y(e,t){if(e.size!==t.length)return!1;for(let n of t)if(!e.has(n))return!1;return!0}function b(e,t){if(typeof e!=`object`||!e||Array.isArray(e))return null;let n=new Map(Object.entries(e)),r=n.get(`record_version`)===1&&n.get(`status`)===`pending`&&y(n,h),i=n.get(`record_version`)===2&&n.get(`status`)===`awaiting_commit`&&y(n,g),a=n.get(`record_version`)===2&&n.get(`status`)===`ready`&&y(n,_);if(!r&&!i&&!a)return null;let o=n.get(r?`recovery_codes_issued_at_ms`:`aad_issued_at_ms`),s=r?Number(o):o,c=n.get(`key`),l=n.get(`iv`),u=n.get(`ciphertext`);if(n.get(`wallet_id`)!==t||n.get(`enrollment_id`)!==m||typeof s!=`number`||!Number.isSafeInteger(s)||s<=0||!v(c)||!(l instanceof Uint8Array)||l.byteLength!==12||!(u instanceof Uint8Array)||u.byteLength===0)return null;if(r)return{kind:`legacy_unbound`,aadIssuedAtMs:s,key:c,iv:l,ciphertext:u};let d=n.get(`pending_backup_id`);if(typeof d!=`string`||!d.trim())return null;if(a){let e=n.get(`recovery_codes_issued_at_ms`);return!Number.isSafeInteger(e)||typeof e!=`number`||e<=0?null:{kind:`ready`,aadIssuedAtMs:s,pendingBackupId:d,issuedAtMs:e,key:c,iv:l,ciphertext:u}}return{kind:`awaiting_commit`,aadIssuedAtMs:s,pendingBackupId:d,key:c,iv:l,ciphertext:u}}function x(e,t){return new TextEncoder().encode(JSON.stringify({kind:m,walletId:e,issuedAtMs:t}))}function S(e){return[e,m]}async function C(e,t){await t.store(n.pendingWalletRecoveryCodeBackups).put(e)}async function w(e,t,r){let i=r.store(n.pendingWalletRecoveryCodeBackups),a=b(await i.get(S(e.walletId)),e.walletId);if(a?.kind!==`awaiting_commit`||a.pendingBackupId!==e.pendingBackupId)throw Error(`Pending recovery-code backup reference does not match an unbound backup`);let o={record_version:2,wallet_id:e.walletId,enrollment_id:m,aad_issued_at_ms:a.aadIssuedAtMs,pending_backup_id:a.pendingBackupId,recovery_codes_issued_at_ms:t,status:`ready`,key:a.key,iv:a.iv,ciphertext:a.ciphertext};await i.put(o)}async function T(e,t,r){let i=r.store(n.pendingWalletRecoveryCodeBackups),a=b(await i.get(S(e)),e);a?.kind===`ready`&&a.issuedAtMs===t&&await i.delete(S(e))}const E=new class{async write(t){let a=t.walletId.trim();if(!a)throw Error(`Pending recovery-code backup requires a wallet`);let o=i(t.recoveryCodes.map(String)),s=e(`pending-recovery-backup`,32,`pending recovery-code backup references`),c=Date.now();if(!Number.isSafeInteger(c)||c<=0)throw Error(`Pending recovery-code backup encryption time is invalid`);let l=await crypto.subtle.generateKey({name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`]),u=crypto.getRandomValues(new Uint8Array(12)),d=x(a,c),f=new TextEncoder().encode(JSON.stringify(o)),p=null;try{let e=new Uint8Array(await crypto.subtle.encrypt({name:`AES-GCM`,iv:u,additionalData:d},l,f));p=e;let t={record_version:2,wallet_id:a,enrollment_id:m,aad_issued_at_ms:c,pending_backup_id:s,status:`awaiting_commit`,key:l,iv:u,ciphertext:e};return await r.runTransaction([n.pendingWalletRecoveryCodeBackups],`readwrite`,C.bind(null,t)),{walletId:a,pendingBackupId:s}}finally{d.fill(0),f.fill(0),p?.fill(0)}}async read(e){let t=e.trim();if(!t)return null;let a=b(await(await r.getDB()).get(n.pendingWalletRecoveryCodeBackups,S(t)),t);if(!a)return null;let o=x(t,a.aadIssuedAtMs),s=null;try{s=new Uint8Array(await crypto.subtle.decrypt({name:`AES-GCM`,iv:a.iv.slice(),additionalData:o},a.key,a.ciphertext.slice()));let e=JSON.parse(new TextDecoder().decode(s));if(!Array.isArray(e))throw Error(`Pending recovery-code backup is invalid`);let n=i(e.map(String));return a.kind===`ready`?{kind:`ready`,walletId:t,recoveryCodes:n,issuedAtMs:a.issuedAtMs}:{kind:`awaiting_commit`,walletId:t,recoveryCodes:n}}finally{o.fill(0),s?.fill(0)}}async has(e){let t=e.trim();return t?b(await(await r.getDB()).get(n.pendingWalletRecoveryCodeBackups,S(t)),t)!==null:!1}async bindIssuedAtMs(e,t){if(!e.walletId||e.walletId!==e.walletId.trim()||!e.pendingBackupId||e.pendingBackupId!==e.pendingBackupId.trim()||!Number.isSafeInteger(t)||t<=0)throw Error(`Pending recovery-code backup identity is invalid`);await r.runTransaction([n.pendingWalletRecoveryCodeBackups],`readwrite`,w.bind(null,e,t))}async deleteIssuedAtMs(e,t){let i=e.trim();if(!i||!Number.isSafeInteger(t)||t<=0)throw Error(`Pending recovery-code backup identity is invalid`);await r.runTransaction([n.pendingWalletRecoveryCodeBackups],`readwrite`,T.bind(null,i,t))}};export{o as a,c as i,d as n,s as o,f as r,E as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{H as e,V as t}from"./domainIds-t1lp25yU.js";import{c as n,l as r}from"./participants-BXdREC5k.js";import{i,r as a}from"./base64-BmKR3UqU.js";import{r as o}from"./secureRandomId-8LSc91aN.js";import{t as s}from"./presignatures-BCeq56DG.js";import{B as c,b as l,d as u,h as d,m as ee,p as f,u as p}from"./digestEncoding-CqNXPZY9.js";import{I as m,L as h,R as g}from"./ecdsaCapabilityManifest-DAJEVjlP.js";import{ct as _,n as v,ut as y}from"./walletOwnershipGeneration-CgjCtPrV.js";import{o as b,s as te,t as ne}from"./evmCryptoWasm-BUPb4hBH.js";import{i as x,n as S,r as re,u as C}from"./trace--mRP2OQc.js";import{A as ie,C as ae,D as w,E as T,O as E,S as D,T as oe,k as O,w as se,x as k,y as A}from"./ecdsaDerivationClientWasm-AYOJgTJm.js";import{t as ce}from"./authorizationAdmission-28jo_IVJ.js";import{t as j}from"./walletSessionFailure-CxsVtroW.js";import{c as le,f as M,o as ue,t as de}from"./routerAbNormalSigning-D-UZmCBS.js";async function fe(e){let t=e.clientShare.material;if(t.kind===`worker_loaded`)return;let n=await A({materialHandle:e.clientShare.handle.materialHandle,bindingDigest:e.clientShare.handle.bindingDigest,stateBlob:t.stateBlob,workerCtx:e.workerCtx});if(n.materialHandle!==e.clientShare.handle.materialHandle||n.bindingDigest!==e.clientShare.handle.bindingDigest)throw Error(`[multichain] ECDSA role-local worker material handle mismatch`)}async function pe(e){let t=e.signerSession,n=t.clientShare;if(n.kind===`linked_holder_worker_share`){let e=n.holderHandleId;return{signerSession:t,clientSigningMaterial:me(e),cleanupAfterSign:async()=>void 0}}let r=n;return{signerSession:t,clientSigningMaterial:{kind:`router_ab_ecdsa_derivation_client_signing_material_source_v1`,initClientPresignSession:async t=>(await fe({workerCtx:e.workerCtx,clientShare:r}),await E({materialHandle:r.handle.materialHandle,material:r.material.kind===`worker_loaded`?{kind:`persisted`,materialRef:r.material.materialRef}:{kind:`runtime_loaded`,expectedBindingDigest:r.handle.bindingDigest},...t})),stepClientPresignSession:O,abortClientPresignSession:w,admitClientPresignature:ae,destroyClientPresignature:T,reserveClientPresignature:ie,commitClientPresignature:se,listAvailableClientPresignatures:D.bind(void 0,`role_local_derivation_handle`),computeSignatureShareFromPresignatureHandle:oe},cleanupAfterSign:async()=>void 0}}async function N(e,t){return await k({holderHandleId:e,...t})}function me(e){return{kind:`router_ab_ecdsa_derivation_client_signing_material_source_v1`,initClientPresignSession:N.bind(void 0,e),stepClientPresignSession:O,abortClientPresignSession:w,admitClientPresignature:ae,destroyClientPresignature:T,reserveClientPresignature:ie,commitClientPresignature:se,listAvailableClientPresignatures:D.bind(void 0,`linked_holder_signing_material`),computeSignatureShareFromPresignatureHandle:oe}}function P(e,t,n,r){let i=Math.floor(Number(e));return Number.isFinite(i)?i<n?n:i>r?r:i:t}function he(e,t){return P(e,t,1,5)}function ge(e,t,n){return P(e,t,0,n)}function _e(e){let t=e||M,n=he(t.targetDepth,M.targetDepth),r=ge(t.lowWatermark,M.lowWatermark,n);return{enabled:typeof t.enabled==`boolean`?t.enabled:M.enabled,targetDepth:n,lowWatermark:r,maxRefillInFlight:P(t.maxRefillInFlight,M.maxRefillInFlight,1,8),refillAttemptTimeoutMs:P(t.refillAttemptTimeoutMs,M.refillAttemptTimeoutMs,5e3,12e4)}}function ve(e){let t=Math.floor(Number(e));return Number.isFinite(t)&&t>0?t:2e4}function ye(e){return String(e&&typeof e==`object`&&`message`in e?e.message:e||``)}function be(e){return Error(`[router-ab-ecdsa-derivation] ${e.operation} request timed out after ${e.timeoutMs}ms`)}async function xe(e){let t=ve(e.timeoutMs),n=typeof AbortController==`function`?new AbortController:null,i={...e.init},a=null,o=null,s=!1;try{let c;if(n){let l=e.init.signal;if(l){if(l.aborted)n.abort();else if(typeof l.addEventListener==`function`){let e=()=>n.abort();l.addEventListener(`abort`,e,{once:!0}),o=()=>l.removeEventListener(`abort`,e)}}a=setTimeout(()=>{s=!0,n.abort()},t),c=await r(new Request(e.url,{...i,signal:n.signal}))}else c=await Promise.race([r(new Request(e.url,i)),new Promise((n,r)=>{a=setTimeout(()=>{s=!0,r(be({operation:e.operation,timeoutMs:t}))},t)})]);let l=await c.json().catch(()=>({}));if(s)throw be({operation:e.operation,timeoutMs:t});return{response:c,data:l}}catch(n){if(s)throw be({operation:e.operation,timeoutMs:t});let r=ye(n);throw Error(r||`[router-ab-ecdsa-derivation] ${e.operation} request failed`)}finally{a&&clearTimeout(a),o?.()}}const Se=5e3;function Ce(e,t){let n=Math.min(e-Date.now(),t??Se,Se);return Number.isFinite(n)&&n>0?n:null}function we(n){return e(t(n))||null}function Te(e){let t={"Content-Type":`application/json`};switch(e.credential.kind){case`operation_step_up`:return{ok:!0,headers:t,credentials:`omit`};case`wallet_session_opaque`:{let r=String(e.credential.walletSessionToken||``).trim();return r?(Object.assign(t,n({token:r,home:e.credential.home})),{ok:!0,headers:t,credentials:`omit`}):{ok:!1,code:`invalid_args`,message:`Missing opaque Wallet Session token for Router A/B ECDSA derivation presign pool fill`}}}}function Ee(e){switch(e.authorization.kind){case`reusable_wallet_session`:return{authorization:e.authorization};case`operation_step_up`:{let t=e.operation;if(!t)throw Error(`Operation step-up pool fill requires exact operation preparation`);return{authorization:e.authorization,operation:t}}}}function De(e){let t=String(e.keyHandle||``).trim();return t?{ok:!0,value:{keyHandle:t}}:{ok:!1,code:`invalid_args`,message:`Missing keyHandle for Router A/B ECDSA derivation pool-fill init`}}async function Oe(e){let t=we(e.relayerUrl);if(!t)return{ok:!1,code:`invalid_args`,message:`Missing relayerUrl for Router A/B ECDSA derivation pool-fill init`};if(typeof fetch!=`function`)return{ok:!1,code:`unsupported`,message:`fetch is not available for Router A/B ECDSA derivation pool-fill init`};let n=De(e);if(!n.ok)return n;let r=String(e.requestTag||``).trim(),i=Te(e);if(!i.ok)return i;let a=Ce(e.poolFill.ceremonyExpiresAtMs,e.requestTimeoutMs);if(a===null)return{ok:!1,code:`presign_timeout`,message:`Presign ceremony deadline has elapsed`};try{let{response:o,data:s}=await xe({url:`${t}${e.path}`,operation:`presign/init`,timeoutMs:a,init:{method:`POST`,headers:i.headers,credentials:i.credentials,body:JSON.stringify({...n.value,count:Number.isFinite(e.count)?Math.max(1,Math.floor(Number(e.count))):1,...r?{requestTag:r}:{},poolFill:e.poolFill,presignSessionId:e.presignSessionId,firstMessageB64u:e.firstMessageB64u,...Ee(e)})}});return typeof s.presignSessionId==`string`&&S(s.presignSessionId,`init`,o.headers.get(`Server-Timing`)),o.ok?{ok:s.ok===!0,presignSessionId:s.presignSessionId,...Number.isSafeInteger(s.ceremonyExpiresAtMs)?{ceremonyExpiresAtMs:s.ceremonyExpiresAtMs}:{},...Number.isSafeInteger(s.materialExpiresAtMs)?{materialExpiresAtMs:s.materialExpiresAtMs}:{},stage:s.stage,outgoingMessagesB64u:Array.isArray(s.outgoingMessagesB64u)?s.outgoingMessagesB64u:[],...s.code?{code:s.code}:{},...s.message?{message:s.message}:{}}:{ok:!1,code:s.code||`http_error`,message:s.message||`HTTP ${o.status}`}}catch(e){return{ok:!1,code:`network_error`,message:String(e&&typeof e==`object`&&`message`in e?e.message:e||`Failed Router A/B ECDSA derivation pool-fill init`)}}}async function ke(e){return Oe({...e,path:p})}async function Ae(e){let t=we(e.relayerUrl);if(!t)return{ok:!1,code:`invalid_args`,message:`Missing relayerUrl for Router A/B ECDSA derivation pool-fill step`};if(typeof fetch!=`function`)return{ok:!1,code:`unsupported`,message:`fetch is not available for Router A/B ECDSA derivation pool-fill step`};let n=String(e.presignSessionId||``).trim();if(!n)return{ok:!1,code:`invalid_args`,message:`Missing presignSessionId for Router A/B ECDSA derivation pool-fill step`};let r=String(e.requestTag||``).trim(),i=Te(e);if(!i.ok)return i;let a=Ce(e.ceremonyExpiresAtMs,e.requestTimeoutMs);if(a===null)return{ok:!1,code:`presign_timeout`,message:`Presign ceremony deadline has elapsed`};try{let{response:o,data:s}=await xe({url:`${t}${e.path}`,operation:`presign/step`,timeoutMs:a,init:{method:`POST`,headers:i.headers,credentials:i.credentials,body:JSON.stringify({presignSessionId:n,ceremonyExpiresAtMs:e.ceremonyExpiresAtMs,materialExpiresAtMs:e.materialExpiresAtMs,stage:e.stage,outgoingMessagesB64u:Array.isArray(e.outgoingMessagesB64u)?e.outgoingMessagesB64u:[],...r?{requestTag:r}:{},...Ee(e)})}});return S(n,`step`,o.headers.get(`Server-Timing`)),o.ok?{ok:s.ok===!0,stage:s.stage,event:s.event,outgoingMessagesB64u:Array.isArray(s.outgoingMessagesB64u)?s.outgoingMessagesB64u:[],...s.presignatureId?{presignatureId:s.presignatureId}:{},...s.bigRB64u?{bigRB64u:s.bigRB64u}:{},...s.code?{code:s.code}:{},...s.message?{message:s.message}:{}}:{ok:!1,code:s.code||`http_error`,message:s.message||`HTTP ${o.status}`}}catch(e){return{ok:!1,code:`network_error`,message:String(e&&typeof e==`object`&&`message`in e?e.message:e||`Failed Router A/B ECDSA derivation pool-fill step`)}}}async function je(e){return Ae({...e,path:u})}var Me=class{state={kind:`refilling`,revision:0};waiters=new Map;snapshot(){return this.state}hasForegroundWaiters(){for(let e of this.waiters.values())if(e===`foreground`)return!0;return!1}publishAvailable(){this.state.kind!==`settled`&&(this.state={kind:`refilling`,revision:this.state.revision+1},this.flushWaiters())}settle(){this.state.kind!==`settled`&&(this.state={kind:`settled`,revision:this.state.revision},this.flushWaiters())}waitForChange(e,t){return this.state.kind===`settled`||this.state.revision!==e.revision?Promise.resolve(this.state):new Promise(n=>{this.waiters.set(n,t),(this.state.kind===`settled`||this.state.revision!==e.revision)&&(this.waiters.delete(n),n(this.state))})}flushWaiters(){let e=this.state,t=[...this.waiters.keys()];this.waiters.clear();for(let n of t)n(e)}};function Ne(){let e=globalThis.crypto;if(!e||typeof e.getRandomValues!=`function`)throw Error(`WebCrypto getRandomValues is required for ECDSA rerandomization`);return e.getRandomValues(new Uint8Array(32))}function F(e){switch(e.authorization.kind){case`reusable_wallet_session`:return{authorization:e.authorization};case`operation_step_up`:{let t=e.operation;if(!t)throw Error(`Operation step-up pool fill requires exact operation preparation`);return{authorization:e.authorization,operation:t}}}}function Pe(e){return String(e&&typeof e==`object`&&`message`in e?e.message:e||`signature recovery failed`)}function I(e){e instanceof Uint8Array&&e.fill(0)}function Fe(e){if(e?.kind!==`router_ab_ecdsa_derivation_client_signing_material_source_v1`)throw Error(`Router A/B ECDSA derivation client signing material source is required`)}const Ie=6e4,L=new Map,R=new Map,z=new Map,B=new Map,V=new Map,H=new Map;function Le(e){return e===`triples_done`||e===`presign`||e===`done`}function Re(e){return Le(e.clientStage)&&Le(e.serverStage)?`presign`:`triples`}function ze(e){let t=L.get(e);if(!t?.length)return null;let n=t.shift()??null;return t.length?L.set(e,t):L.delete(e),n}async function U(e){return await Ue(e),ze(e.poolKey)}function Be(e,t,n){if(!K(n))return`invalid`;let r=L.get(e)||[];for(let e of r)if(e.materialHandle===n.materialHandle)return`duplicate`;return r.filter(e=>K(e)).length>=5?`capacity_full`:(r.push(n),L.set(e,r),R.set(e,t),`stored`)}function Ve(e,t=Date.now()){let n=L.get(e);if(!n?.length)return[];let r=[],i=[];for(let e of n)K(e,t)?r.push(e):i.push(e);return r.length>0?L.set(e,r):L.delete(e),i}async function He(e){for(let t of e.refs)await e.clientSigningMaterial.destroyClientPresignature({materialHandle:t.materialHandle,poolIdentity:e.poolIdentity,workerCtx:e.workerCtx}).catch(()=>{})}async function Ue(e){await He({refs:Ve(e.poolKey),poolIdentity:e.poolIdentity,clientSigningMaterial:e.clientSigningMaterial,workerCtx:e.workerCtx})}async function W(e,t,n){try{await v(e.walletId,e.ownershipGeneration)}catch(r){throw await qe({poolIdentity:e,poolKey:_(e),clientSigningMaterial:t,workerCtx:n}),r}}async function We(e){await W(e.poolIdentity,e.clientSigningMaterial,e.workerCtx);let t=V.get(e.poolKey);if(t){await t;return}let n=Ge(e);V.set(e.poolKey,n);try{await n}finally{V.get(e.poolKey)===n&&V.delete(e.poolKey)}}async function Ge(e){await Ue(e);let t;t=await e.clientSigningMaterial.listAvailableClientPresignatures({poolIdentity:e.poolIdentity,workerCtx:e.workerCtx});try{await W(e.poolIdentity,e.clientSigningMaterial,e.workerCtx)}catch{}if(q(e.poolKey)!==e.generation){for(let n of t)I(n.bigR33),await e.clientSigningMaterial.destroyClientPresignature({materialHandle:n.materialHandle,poolIdentity:e.poolIdentity,workerCtx:e.workerCtx}).catch(()=>{});return}for(let n of t){let t=Be(e.poolKey,e.poolIdentity,{presignatureId:n.presignatureId,materialHandle:n.materialHandle,bigRB64u:i(n.bigR33),createdAtMs:n.createdAtMs,expiresAtMs:n.expiresAtMs});I(n.bigR33),(t===`invalid`||t===`capacity_full`)&&await e.clientSigningMaterial.destroyClientPresignature({materialHandle:n.materialHandle,poolIdentity:e.poolIdentity,workerCtx:e.workerCtx}).catch(()=>{})}}function G(e){let t=L.get(e);return t?t.reduce((e,t)=>e+(K(t)?1:0),0):0}function K(e,t=Date.now()){let n=Math.floor(Number(e.expiresAtMs));return!!(e.presignatureId&&e.bigRB64u&&e.materialHandle)&&Number.isSafeInteger(n)&&n>t+2e3}function q(e){let t=H.get(e);return t===void 0?(H.set(e,0),0):t}function Ke(e){Z(e);let t=q(e)+1;return H.set(e,t),t}async function qe(e){let t=L.get(e.poolKey)??[];$e(e.poolKey),await He({...e,refs:t})}function J(e){return B.get(e)||0}function Je(e){let t=J(e);B.set(e,t+1)}function Ye(e){let t=J(e);if(t<=1){B.delete(e),Q(e,0);return}B.set(e,t-1)}async function Xe(e,t){let n=z.get(e);if(!n)return;let r=n.snapshot();for(;G(e)===0&&r.kind===`refilling`;)r=await n.waitForChange(r,t)}async function Ze(e){let t=_(y({ownershipGeneration:e.ownershipGeneration,relayerUrl:e.relayerUrl,scope:e.scope,materialActivation:e.materialActivation}));return G(t)>0?!0:(await Xe(t,`background`),G(t)>0)}function Y(e,t,n){return{scheduled:!1,reason:e,depth:t,targetDepth:n}}function Qe(){let e=new Set([...X.keys(),...L.keys(),...z.keys(),...B.keys(),...H.keys()]);for(let t of e)Ke(t);L.clear(),R.clear();for(let e of z.values())e.settle();z.clear(),B.clear()}function $e(e){L.delete(e),R.delete(e),Ke(e),z.get(e)?.settle(),z.delete(e)}function et(e){let t=String(e).trim();if(!t)throw Error(`ECDSA presignature wallet id is required`);for(let[e,n]of[...R])n.walletId===t&&$e(e)}const X=new Map;function Z(e){let t=X.get(e);t&&t.timer!==null&&clearTimeout(t.timer),X.delete(e),X.size===0&&typeof window<`u`&&(window.removeEventListener(`online`,$),document.removeEventListener(`visibilitychange`,$))}function Q(e,t){let n=X.get(e);if(!n)return;n.timer!==null&&clearTimeout(n.timer);let r=n.input.routerAbEcdsaDerivationPoolFill.ceremonyExpiresAtMs-Date.now();if(r<=0||q(e)!==n.generation){Z(e);return}n.timer=setTimeout(tt,Math.min(t,r),e)}function $(){if(!(typeof document<`u`&&document.visibilityState===`hidden`))for(let e of X.keys())Q(e,0)}function tt(e){let t=X.get(e);if(!t)return;if(t.timer=null,Date.now()>=t.input.routerAbEcdsaDerivationPoolFill.ceremonyExpiresAtMs){Z(e);return}if(typeof navigator<`u`&&navigator.onLine===!1){Q(e,3e4);return}let n=at(t.input);n.scheduled||Q(e,n.depth>=n.targetDepth?3e4:5e3)}function nt(e,t){t.authorization.kind===`reusable_wallet_session`&&X.get(e)?.input!==t&&(Z(e),X.size===0&&typeof window<`u`&&(window.addEventListener(`online`,$),document.addEventListener(`visibilitychange`,$)),X.set(e,{input:t,generation:q(e),failures:0,timer:null}),Q(e,3e4))}function rt(e,t,n){let r=X.get(e);if(!(!r||r!==t)){switch(n){case`network_error`:case`internal`:case`presign_timeout`:case`temporarily_unavailable`:case`service_unavailable`:case`wallet_session_unavailable`:if(r.failures+=1,r.failures<=3)return}Z(e)}}async function it(e){let{args:t,refillInput:n,poolKey:r,poolIdentity:i,scheduledGeneration:a,targetDepth:o,refillAttemptTimeoutMs:s,progress:c}=e,l=X.get(r)??null;try{for(await We({poolKey:r,poolIdentity:i,clientSigningMaterial:t.clientSigningMaterial,workerCtx:t.workerCtx,generation:a}),G(r)>0&&c.publishAvailable();Date.now()<t.routerAbEcdsaDerivationPoolFill.ceremonyExpiresAtMs;){if(q(r)!==a||(X.get(r)??null)!==l||G(r)>=o||J(r)>0||typeof navigator<`u`&&navigator.onLine===!1)return;let e=Math.min(Date.now()+s,t.routerAbEcdsaDerivationPoolFill.ceremonyExpiresAtMs),i=await _t({...n,routerAbEcdsaDerivationPoolFill:{kind:`router_ab_ecdsa_derivation_signing_worker_pool`,scope:n.routerAbEcdsaDerivationPoolFill.scope,ceremonyExpiresAtMs:e,materialExpiresAtMs:n.routerAbEcdsaDerivationPoolFill.materialExpiresAtMs},trafficClass:`background`});if(C(`evm-family`,{event:`ecdsa_background_refill_result`,authorization:t.authorization.kind,outcome:i.ok?`available`:`failed`,code:i.ok?null:i.code,depth:G(r),targetDepth:o}),!i.ok){rt(r,l,i.code);return}let u=X.get(r);u&&u===l&&(u.failures=0),c.publishAvailable()}}catch{rt(r,l,`internal`)}finally{c.settle(),z.get(r)===c&&z.delete(r);let e=X.get(r);if(e){let t=e.failures>0?2e3*2**e.failures:1e3;G(r)>=o&&(t=3e4),e!==l&&(t=0),Q(r,t)}}}function at(e){try{let t=_e(e.poolPolicy),n=y({ownershipGeneration:e.credential.ownershipGeneration,relayerUrl:e.relayerUrl,scope:e.routerAbEcdsaDerivationPoolFill.scope,materialActivation:e.materialActivation}),r=_(n);R.set(r,n);let i=he(e.targetDepth,t.targetDepth),a=ge(e.triggerIfDepthAtOrBelow,t.lowWatermark,i),o=G(r),s=q(r);if(!t.enabled)return Y(`disabled`,o,i);if(e.routerAbEcdsaDerivationPoolFill.ceremonyExpiresAtMs<=Date.now())return Z(r),Y(`invalid_args`,o,i);if(nt(r,e),o>a)return Y(`depth_above_trigger`,o,i);if(o>=i)return Y(`depth_at_or_above_target`,o,i);if(z.has(r)||J(r)>0)return Y(`in_flight_for_pool_key`,o,i);if(z.size>=t.maxRefillInFlight)return Y(`global_in_flight_limit`,o,i);let c={relayerUrl:e.relayerUrl,keyHandle:e.keyHandle,ecdsaThresholdKeyId:e.ecdsaThresholdKeyId,clientVerifyingShareB64u:e.clientVerifyingShareB64u,clientSigningMaterial:e.clientSigningMaterial,thresholdEcdsaPublicKeyB64u:e.thresholdEcdsaPublicKeyB64u,relayerVerifyingShareB64u:e.relayerVerifyingShareB64u,credential:e.credential,materialActivation:e.materialActivation,routerAbEcdsaDerivationPoolFill:e.routerAbEcdsaDerivationPoolFill,workerCtx:e.workerCtx,...F(e)},l=new Me;return z.set(r,l),it({args:e,refillInput:c,poolKey:r,poolIdentity:n,scheduledGeneration:s,targetDepth:i,refillAttemptTimeoutMs:t.refillAttemptTimeoutMs,progress:l}),{scheduled:!0,reason:`scheduled`,depth:o,targetDepth:i}}catch{return Y(`invalid_args`,0,0)}}function ot(e){return e.map(e=>i(e))}function st(e){return Array.isArray(e)?e.map(e=>String(e||``).trim()).filter(e=>!!e).map(e=>a(e)):[]}async function ct(e){let t=String(e.thresholdEcdsaPublicKeyB64u||``).trim();if(t){let n=a(t);if(n.length!==33)throw Error(`thresholdEcdsaPublicKeyB64u must decode to 33 bytes`);return await b({publicKey33:n,workerCtx:e.workerCtx})}let n=String(e.clientVerifyingShareB64u||``).trim(),r=String(e.relayerVerifyingShareB64u||``).trim();if(!n||!r)throw Error(`Missing thresholdEcdsaPublicKeyB64u (or relayerVerifyingShareB64u fallback) for Router A/B ECDSA derivation signing`);let i=a(n),o=a(r);if(i.length!==33)throw Error(`clientVerifyingShareB64u must decode to 33 bytes`);if(o.length!==33)throw Error(`relayerVerifyingShareB64u must decode to 33 bytes`);return await ne({left33:await b({publicKey33:i,workerCtx:e.workerCtx}),right33:await b({publicKey33:o,workerCtx:e.workerCtx}),workerCtx:e.workerCtx})}function lt(e){return e.trafficClass===`foreground`||z.get(e.poolKey)?.hasForegroundWaiters()?`foreground_presign_pool_refill`:`background_presign_pool_refill`}async function ut(e){for(let t=0;t<2;t+=1){let n=await dt(e);if(n.ok||!ft(n)||t===1)return n}return{ok:!1,code:`stale_session_state`,message:`Router A/B ECDSA derivation pool-fill session stayed stale after retry`}}async function dt(e){Fe(e.clientSigningMaterial);let t=performance.now(),n=e.routerAbEcdsaDerivationPoolFill.ceremonyExpiresAtMs,r=e.routerAbEcdsaDerivationPoolFill.materialExpiresAtMs,a=`ecdsa-presign-v2:${n}:${i(crypto.getRandomValues(new Uint8Array(32)))}`,o=a,s=y({ownershipGeneration:e.credential.ownershipGeneration,relayerUrl:e.relayerUrl,scope:e.routerAbEcdsaDerivationPoolFill.scope,materialActivation:e.materialActivation}),c=null,l=null,u=null,d=null,ee=!1,f=`triples`,p=[],m=!0,h=!1;try{let t=await e.clientSigningMaterial.initClientPresignSession({sessionId:o,groupPublicKey33:e.groupPublicKey33,ceremonyExpiresAtMs:n,materialExpiresAtMs:r,poolIdentity:s,workerCtx:e.workerCtx});if(t.stage!==`triples`||t.outgoingMessages.length!==1)return{ok:!1,code:`presign_init_failed`,message:`Client presign init must emit exactly one first message`};f=t.stage;let g=await ke({relayerUrl:e.relayerUrl,...e.poolFillInitKeySelector,count:1,presignSessionId:a,firstMessageB64u:i(t.outgoingMessages[0]),credential:e.credential,requestTag:lt(e),poolFill:e.routerAbEcdsaDerivationPoolFill,...F(e)});if(!g.ok)return{ok:!1,code:g.code||`presign_init_failed`,message:g.message||`Presign initialization failed`};if(g.presignSessionId!==a||g.ceremonyExpiresAtMs!==n||g.materialExpiresAtMs!==r||n<=Date.now())return{ok:!1,code:`invalid_pool_fill_expiry`,message:`Presign initialization changed the bound identity or deadlines`};let _=g.stage||`triples`,v=st(g.outgoingMessagesB64u);for(let t=0;t<64;t++){if(v.length>0&&!c){let t=await e.clientSigningMaterial.stepClientPresignSession({sessionId:o,stage:Re({clientStage:f,serverStage:_}),incomingMessages:v,workerCtx:e.workerCtx});f=t.stage,v=[],p.push(...t.outgoingMessages),t.presignatureHandle&&t.presignatureBigR33&&(c=t.presignatureHandle,l=t.presignatureBigR33)}if(!ee){let i=performance.now(),o=lt(e),s={relayerUrl:e.relayerUrl,presignSessionId:a,ceremonyExpiresAtMs:n,materialExpiresAtMs:r,stage:Re({clientStage:f,serverStage:_}),outgoingMessagesB64u:ot(p),credential:e.credential,requestTag:o,...F(e)},c=await je(s);if(C(`evm-family`,{event:`ecdsa_presignature_round`,requestTag:o,presignSessionId:a,authorization:e.authorization.kind,round:t,stage:s.stage,durationMs:performance.now()-i,outcome:c.ok?`succeeded`:`failed`}),p=[],!c.ok)return{ok:!1,code:c.code||`presign_step_failed`,message:c.message||`Router A/B ECDSA derivation pool-fill step failed`};v=st(c.outgoingMessagesB64u),_=c.stage||_,c.event===`presign_done`&&(u=String(c.presignatureId||``).trim()||null,d=String(c.bigRB64u||``).trim()||null,ee=!0)}if(c&&l&&u&&d)break}if(!c||!l)return{ok:!1,code:`presign_timeout`,message:`Client presign session did not reach done state`};if(!u||!d)return{ok:!1,code:`presign_timeout`,message:`Server presign session did not reach done state`};if(l.length!==33)return{ok:!1,code:`internal`,message:`Invalid local presignature bigR bytes (expected 33, got ${l.length})`};try{let t=Date.now(),n=i(l);if(n!==d)return{ok:!1,code:`presign_mismatch`,message:`Client/server presignature mismatch (bigR mismatch)`};let a=await e.clientSigningMaterial.admitClientPresignature({materialHandle:c,expectedPresignatureId:u,poolIdentity:s,admissionMode:e.authorization.kind===`operation_step_up`?`resident`:`durable`,workerCtx:e.workerCtx});return a.kind===`discarded_capacity`?{ok:!1,code:`pool_full`,message:`Router A/B ECDSA derivation client presignature pool is full`}:a.kind===`discarded_ambiguous`?{ok:!1,code:`presign_failed`,message:`Router A/B ECDSA derivation client presignature admission was ambiguous`}:(h=!0,m=!1,{ok:!0,kind:`available`,presignature:{presignatureId:u,bigRB64u:n,materialHandle:c,createdAtMs:t,expiresAtMs:r}})}finally{I(l)}}catch(e){return{ok:!1,code:`presign_failed`,message:String(e&&typeof e==`object`&&`message`in e?e.message:e||`Router A/B ECDSA derivation pool-fill handshake failed`)}}finally{C(`evm-family`,{event:`ecdsa_presignature_generation`,requestTag:lt(e),presignSessionId:a,authorization:e.authorization.kind,durationMs:performance.now()-t,outcome:h?`available`:`failed`}),I(l),!h&&c&&await e.clientSigningMaterial.destroyClientPresignature({materialHandle:c,poolIdentity:s,workerCtx:e.workerCtx}).catch(()=>{}),m&&await e.clientSigningMaterial.abortClientPresignSession({sessionId:o,workerCtx:e.workerCtx}).catch(()=>{})}}function ft(e){return e.code===`stale_session_state`||e.code===`stale_pool_fill_session`}function pt(e){let t=l(e);return{ecdsaThresholdKeyId:m(t.ecdsa_threshold_key_id),clientVerifyingShareB64u:g(t.public_identity.derivation_client_share_public_key33_b64u),thresholdEcdsaPublicKeyB64u:t.public_identity.threshold_public_key33_b64u}}function mt(e){let t=Math.floor(Number(e.materialExpiresAtMs)),n=Number.isSafeInteger(e.authorizationExpiresAtMs)?Math.floor(Number(e.authorizationExpiresAtMs)):e.nowMs+Ie,r=Math.min(t,n,e.nowMs+Ie);return Number.isSafeInteger(r)&&r>e.nowMs?r:null}async function ht(e,t,n){let r=null,s=null,l=null,u=null,f=null,p={kind:`unclaimed`},m=null,h={kind:`before_prepare`};try{let g=String(e.relayerUrl||``).trim().replace(/\/+$/g,``);if(!g)return{ok:!1,code:`invalid_args`,message:`Missing relayerUrl for Router A/B ECDSA derivation signing`};let v=pt(e.scope);if(!v.ecdsaThresholdKeyId)return{ok:!1,code:`invalid_args`,message:`Missing ecdsaThresholdKeyId for Router A/B ECDSA derivation signing`};let b=v.clientVerifyingShareB64u;if(!b)return{ok:!1,code:`invalid_args`,message:`Missing clientVerifyingShareB64u for Router A/B ECDSA derivation signing`};if(!(e.signingDigest32 instanceof Uint8Array)||e.signingDigest32.length!==32)return{ok:!1,code:`invalid_args`,message:`signingDigest32 must be 32 bytes for Router A/B ECDSA derivation signing`};let ne=performance.now(),S=await ct({clientVerifyingShareB64u:b,thresholdEcdsaPublicKeyB64u:v.thresholdEcdsaPublicKeyB64u,workerCtx:e.workerCtx});x(e.operationId,`public_key_validation`,ne),s=y({ownershipGeneration:e.credential.ownershipGeneration,relayerUrl:g,scope:e.scope,materialActivation:e.materialActivation}),await W(s,e.clientSigningMaterial,e.workerCtx),r=_(s),R.set(r,s),m=q(r);let ie=performance.now();if(l=await U({poolKey:r,poolIdentity:s,clientSigningMaterial:e.clientSigningMaterial,workerCtx:e.workerCtx}),x(e.operationId,`pool_lookup`,ie),!l){let t=performance.now();await We({poolKey:r,poolIdentity:s,clientSigningMaterial:e.clientSigningMaterial,workerCtx:e.workerCtx,generation:m}),x(e.operationId,`pool_restore`,t),m=q(r),l=await U({poolKey:r,poolIdentity:s,clientSigningMaterial:e.clientSigningMaterial,workerCtx:e.workerCtx})}if(!l){let t=performance.now();await Xe(r,`foreground`),x(e.operationId,`refill_wait`,t),m=q(r),l=await U({poolKey:r,poolIdentity:s,clientSigningMaterial:e.clientSigningMaterial,workerCtx:e.workerCtx})}if(!l){let t=performance.now();Je(r);try{let t=await _t({...n,trafficClass:`foreground`});if(!t.ok&&t.code===`invalidated`&&(t=await _t({...n,trafficClass:`foreground`})),!t.ok&&t.code!==`pool_full`)return t;!t.ok&&t.code===`pool_full`&&await We({poolKey:r,poolIdentity:s,clientSigningMaterial:e.clientSigningMaterial,workerCtx:e.workerCtx,generation:q(r)})}finally{Ye(r)}m=q(r),l=await U({poolKey:r,poolIdentity:s,clientSigningMaterial:e.clientSigningMaterial,workerCtx:e.workerCtx}),x(e.operationId,`foreground_refill`,t)}if(C(`evm-family`,{event:`ecdsa_presignature_selection`,operationId:e.operationId,authorization:e.authorization.kind,outcome:l?`available`:`empty`,remainingDepth:G(r),attempt:t}),!l)return{ok:!1,code:`pool_empty`,message:`Router A/B ECDSA derivation client presignature pool is empty`};let ae=Date.now(),w=mt({authorizationExpiresAtMs:e.expiresAtMs,materialExpiresAtMs:l.expiresAtMs,nowMs:ae});if(!w)return{ok:!1,code:`pool_entry_expired`,message:`Router A/B ECDSA derivation client presignature is expired`};if(await W(s,e.clientSigningMaterial,e.workerCtx),m!==q(r))return{ok:!1,code:`pool_entry_unavailable`,message:`Router A/B ECDSA derivation client presignature pool was invalidated before prepare`};f=Ne();let T=await c(f),E=d({scope:e.scope,requestId:o(`router-ab-ecdsa-sign`,32,`Router A/B ECDSA derivation sign request`),operationId:e.operationId,operationDigests:e.operationDigests,authorization:e.authorization,materialActivation:e.materialActivation,clientPresignatureId:l.presignatureId,expiresAtMs:w,signingDigest32:e.signingDigest32,clientRerandomizationCommitment32:T});I(T);let D=o(`router-ab-ecdsa-reservation`,32,`Router A/B ECDSA Client presignature reservation`);p={kind:`destroy`};let oe=performance.now(),O=await e.clientSigningMaterial.reserveClientPresignature({materialHandle:l.materialHandle,expectedPresignatureId:l.presignatureId,poolIdentity:s,requestBinding:E.request_id,reservationId:D,leaseExpiresAtMs:E.expires_at_ms,workerCtx:e.workerCtx});if(x(e.operationId,`presignature_reserve`,oe),O.kind===`unavailable`)return O.reason===`claimed_elsewhere`&&(p={kind:`owned_elsewhere`}),t<4?await ht(e,t+1,n):{ok:!1,code:O.reason===`expired`?`pool_entry_expired`:`pool_entry_unavailable`,message:`Router A/B ECDSA derivation client presignature is unavailable: ${O.reason}`};if(await W(s,e.clientSigningMaterial,e.workerCtx),m!==q(r))return{ok:!1,code:`pool_entry_unavailable`,message:`Router A/B ECDSA derivation client presignature pool was invalidated before prepare`};Q(r,0),h={kind:`prepare_submitted`};let se=performance.now(),k=await le({relayServerUrl:g,credential:e.credential,request:E,onServerTiming:re.bind(void 0,e.operationId,`prepare`)});if(x(e.operationId,`prepare`,se),k.kind===`reusable_wallet_session`){if(!e.reconcileSession)throw Error(`Wallet Session reconciliation is required`);await e.reconcileSession(k.sessionStatus)}let A=k.signing;if(A.server_big_r33_b64u!==l.bigRB64u)return{ok:!1,code:`presign_mismatch`,message:`Router A/B ECDSA derivation SigningWorker returned a different presignature bigR`};let ce=performance.now();await e.clientSigningMaterial.commitClientPresignature({materialHandle:l.materialHandle,poolIdentity:s,requestBinding:E.request_id,reservationId:D,workerCtx:e.workerCtx}),x(e.operationId,`presignature_commit`,ce);let j=a(l.bigRB64u),M=a(A.signing_worker_rerandomization_contribution32_b64u);try{if(j.length!==33)return{ok:!1,code:`internal`,message:`Router A/B ECDSA derivation presign bigR must decode to 33 bytes`};if(M.length!==32)return{ok:!1,code:`internal`,message:`Router A/B ECDSA derivation SigningWorker rerandomization contribution must decode to 32 bytes`};let t=performance.now();u=await e.clientSigningMaterial.computeSignatureShareFromPresignatureHandle({materialHandle:l.materialHandle,poolIdentity:s,requestBinding:E.request_id,reservationId:D,groupPublicKey33:S,expectedPresignBigR33:j,digest32:e.signingDigest32,clientRerandomizationContribution32:f,signingWorkerRerandomizationContribution32:M,workerCtx:e.workerCtx}),x(e.operationId,`client_share`,t),p={kind:`consumed`}}finally{I(j),I(M)}if(u.length!==32)return{ok:!1,code:`internal`,message:`Invalid Router A/B ECDSA derivation client signature share length (expected 32, got ${u.length})`};let de=ee({scope:e.scope,requestId:E.request_id,operationId:E.operation_id,operationDigests:E.operation_digests,authorization:e.authorization,materialActivation:e.materialActivation,expiresAtMs:E.expires_at_ms,signingDigest32:e.signingDigest32,serverPresignatureId:A.server_presignature_id,clientSignatureShare32:u,clientRerandomizationContribution32:f}),fe=performance.now(),pe=await ue({relayServerUrl:g,credential:e.credential,request:de,onServerTiming:re.bind(void 0,e.operationId,`finalize`)});x(e.operationId,`finalize`,fe);let N=a(pe.signature65_b64u);if(N.length!==65)return{ok:!1,code:`internal`,message:`Router A/B ECDSA derivation returned invalid signature length (expected 65, got ${N.length})`};try{let t=performance.now();await te({digest32:e.signingDigest32,signature65:N,publicKey33:S,workerCtx:e.workerCtx}),x(e.operationId,`signature_verify`,t)}catch(e){return{ok:!1,code:`internal`,message:`Router A/B ECDSA derivation returned a signature that does not recover to the threshold group public key: ${Pe(e)}`}}return{ok:!0,signature65:N,signature65B64u:pe.signature65_b64u,rB64u:i(N.slice(0,32)),sB64u:i(N.slice(32,64)),recId:N[64]}}catch(t){if(t instanceof ce||t instanceof j)throw t;let n=String(t&&typeof t==`object`&&`message`in t?t.message:t||`Router A/B ECDSA derivation signing failed`);return t instanceof de&&t.code===`expired_local_request`?{ok:!1,code:`pool_entry_expired`,message:n}:r&&s&&m!==null&&h.kind===`before_prepare`&&q(r)!==m?(await qe({poolKey:r,poolIdentity:s,clientSigningMaterial:e.clientSigningMaterial,workerCtx:e.workerCtx}),{ok:!1,code:`pool_entry_unavailable`,message:`Router A/B ECDSA derivation client presignature pool was invalidated before prepare`}):{ok:!1,code:`router_ab_sign_failed`,message:n}}finally{if(I(u),I(f),l&&s&&p.kind!==`consumed`&&p.kind!==`owned_elsewhere`){let t=!1;if(p.kind===`unclaimed`&&r&&m!==null&&m===q(r)){let e=Be(r,s,l);t=e===`stored`||e===`duplicate`}t||await e.clientSigningMaterial.destroyClientPresignature({materialHandle:l.materialHandle,poolIdentity:s,workerCtx:e.workerCtx}).catch(()=>{})}r&&Q(r,0)}}async function gt(e){let t=pt(e.scope),n=Math.floor(Number(e.expiresAtMs));if(!Number.isSafeInteger(n)||n<=Date.now())return{ok:!1,code:`invalid_pool_fill_expiry`,message:`Router A/B ECDSA derivation pool fill expiry is unavailable or expired`};let r={relayerUrl:e.relayerUrl,keyHandle:e.keyHandle,ecdsaThresholdKeyId:t.ecdsaThresholdKeyId,clientVerifyingShareB64u:t.clientVerifyingShareB64u,clientSigningMaterial:e.clientSigningMaterial,thresholdEcdsaPublicKeyB64u:t.thresholdEcdsaPublicKeyB64u,credential:e.credential,materialActivation:e.materialActivation,routerAbEcdsaDerivationPoolFill:{kind:`router_ab_ecdsa_derivation_signing_worker_pool`,scope:e.scope,ceremonyExpiresAtMs:Math.min(n,Date.now()+f-3e4),materialExpiresAtMs:e.authorization.kind===`operation_step_up`?n:Date.now()+s},workerCtx:e.workerCtx,...F(e)},i=await ht(e,0,r);return!i.ok&&(i.code===`pool_entry_expired`||i.code===`pool_entry_unavailable`)?await ht(e,0,r):i}async function _t(e){try{let t=y({ownershipGeneration:e.credential.ownershipGeneration,relayerUrl:e.relayerUrl,scope:e.routerAbEcdsaDerivationPoolFill.scope,materialActivation:e.materialActivation});await W(t,e.clientSigningMaterial,e.workerCtx);let n=_(t);await Ue({poolKey:n,poolIdentity:t,clientSigningMaterial:e.clientSigningMaterial,workerCtx:e.workerCtx});let r=q(n),i=await ct({clientVerifyingShareB64u:e.clientVerifyingShareB64u,thresholdEcdsaPublicKeyB64u:e.thresholdEcdsaPublicKeyB64u,relayerVerifyingShareB64u:e.relayerVerifyingShareB64u,workerCtx:e.workerCtx}),a=await ut({relayerUrl:e.relayerUrl,poolFillInitKeySelector:{keyHandle:h(e.keyHandle)},clientSigningMaterial:e.clientSigningMaterial,groupPublicKey33:i,materialActivation:e.materialActivation,credential:e.credential,poolKey:n,trafficClass:e.trafficClass,routerAbEcdsaDerivationPoolFill:e.routerAbEcdsaDerivationPoolFill,workerCtx:e.workerCtx,...F(e)});if(!a.ok)return a;try{await W(t,e.clientSigningMaterial,e.workerCtx)}catch{}if(q(n)!==r)return await e.clientSigningMaterial.destroyClientPresignature({materialHandle:a.presignature.materialHandle,poolIdentity:t,workerCtx:e.workerCtx}).catch(()=>{}),{ok:!1,code:`invalidated`,message:`Router A/B ECDSA derivation presignature pool invalidated`};let o=Be(n,t,a.presignature);return(o===`capacity_full`||o===`invalid`)&&await e.clientSigningMaterial.destroyClientPresignature({materialHandle:a.presignature.materialHandle,poolIdentity:t,workerCtx:e.workerCtx}).catch(()=>{}),{ok:!0,presignatureId:a.presignature.presignatureId}}catch(e){return{ok:!1,code:`internal`,message:String(e&&typeof e==`object`&&`message`in e?e.message:e||`Router A/B ECDSA derivation presignature refill failed`)}}}export{Ze as a,pe as c,gt as i,et as n,_e as o,at as r,me as s,Qe as t};
|
|
1
|
+
import{H as e,V as t}from"./domainIds-t1lp25yU.js";import{c as n,l as r}from"./participants-BXdREC5k.js";import{i,r as a}from"./base64-BmKR3UqU.js";import{r as o}from"./secureRandomId-8LSc91aN.js";import{t as s}from"./presignatures-CkhuZ0YQ.js";import{B as c,b as l,d as u,h as d,m as ee,p as f,u as p}from"./digestEncoding-34kXJoJr.js";import{I as m,L as h,R as g}from"./ecdsaCapabilityManifest--1Ztngfx.js";import{ct as _,n as v,ut as y}from"./walletOwnershipGeneration-BZc6UKqX.js";import{o as b,s as te,t as ne}from"./evmCryptoWasm-CeH6Qeaa.js";import{i as x,n as S,r as re,u as C}from"./trace-BnhLKxcu.js";import{A as ie,C as ae,D as w,E as T,O as E,S as D,T as oe,k as O,w as se,x as k,y as A}from"./ecdsaDerivationClientWasm-DJh2uN-q.js";import{t as ce}from"./authorizationAdmission-28jo_IVJ.js";import{t as j}from"./walletSessionFailure-CxsVtroW.js";import{c as le,f as M,o as ue,t as de}from"./routerAbNormalSigning-DVFFkNhJ.js";async function fe(e){let t=e.clientShare.material;if(t.kind===`worker_loaded`)return;let n=await A({materialHandle:e.clientShare.handle.materialHandle,bindingDigest:e.clientShare.handle.bindingDigest,stateBlob:t.stateBlob,workerCtx:e.workerCtx});if(n.materialHandle!==e.clientShare.handle.materialHandle||n.bindingDigest!==e.clientShare.handle.bindingDigest)throw Error(`[multichain] ECDSA role-local worker material handle mismatch`)}async function pe(e){let t=e.signerSession,n=t.clientShare;if(n.kind===`linked_holder_worker_share`){let e=n.holderHandleId;return{signerSession:t,clientSigningMaterial:me(e),cleanupAfterSign:async()=>void 0}}let r=n;return{signerSession:t,clientSigningMaterial:{kind:`router_ab_ecdsa_derivation_client_signing_material_source_v1`,initClientPresignSession:async t=>(await fe({workerCtx:e.workerCtx,clientShare:r}),await E({materialHandle:r.handle.materialHandle,material:r.material.kind===`worker_loaded`?{kind:`persisted`,materialRef:r.material.materialRef}:{kind:`runtime_loaded`,expectedBindingDigest:r.handle.bindingDigest},...t})),stepClientPresignSession:O,abortClientPresignSession:w,admitClientPresignature:ae,destroyClientPresignature:T,reserveClientPresignature:ie,commitClientPresignature:se,listAvailableClientPresignatures:D.bind(void 0,`role_local_derivation_handle`),computeSignatureShareFromPresignatureHandle:oe},cleanupAfterSign:async()=>void 0}}async function N(e,t){return await k({holderHandleId:e,...t})}function me(e){return{kind:`router_ab_ecdsa_derivation_client_signing_material_source_v1`,initClientPresignSession:N.bind(void 0,e),stepClientPresignSession:O,abortClientPresignSession:w,admitClientPresignature:ae,destroyClientPresignature:T,reserveClientPresignature:ie,commitClientPresignature:se,listAvailableClientPresignatures:D.bind(void 0,`linked_holder_signing_material`),computeSignatureShareFromPresignatureHandle:oe}}function P(e,t,n,r){let i=Math.floor(Number(e));return Number.isFinite(i)?i<n?n:i>r?r:i:t}function he(e,t){return P(e,t,1,5)}function ge(e,t,n){return P(e,t,0,n)}function _e(e){let t=e||M,n=he(t.targetDepth,M.targetDepth),r=ge(t.lowWatermark,M.lowWatermark,n);return{enabled:typeof t.enabled==`boolean`?t.enabled:M.enabled,targetDepth:n,lowWatermark:r,maxRefillInFlight:P(t.maxRefillInFlight,M.maxRefillInFlight,1,8),refillAttemptTimeoutMs:P(t.refillAttemptTimeoutMs,M.refillAttemptTimeoutMs,5e3,12e4)}}function ve(e){let t=Math.floor(Number(e));return Number.isFinite(t)&&t>0?t:2e4}function ye(e){return String(e&&typeof e==`object`&&`message`in e?e.message:e||``)}function be(e){return Error(`[router-ab-ecdsa-derivation] ${e.operation} request timed out after ${e.timeoutMs}ms`)}async function xe(e){let t=ve(e.timeoutMs),n=typeof AbortController==`function`?new AbortController:null,i={...e.init},a=null,o=null,s=!1;try{let c;if(n){let l=e.init.signal;if(l){if(l.aborted)n.abort();else if(typeof l.addEventListener==`function`){let e=()=>n.abort();l.addEventListener(`abort`,e,{once:!0}),o=()=>l.removeEventListener(`abort`,e)}}a=setTimeout(()=>{s=!0,n.abort()},t),c=await r(new Request(e.url,{...i,signal:n.signal}))}else c=await Promise.race([r(new Request(e.url,i)),new Promise((n,r)=>{a=setTimeout(()=>{s=!0,r(be({operation:e.operation,timeoutMs:t}))},t)})]);let l=await c.json().catch(()=>({}));if(s)throw be({operation:e.operation,timeoutMs:t});return{response:c,data:l}}catch(n){if(s)throw be({operation:e.operation,timeoutMs:t});let r=ye(n);throw Error(r||`[router-ab-ecdsa-derivation] ${e.operation} request failed`)}finally{a&&clearTimeout(a),o?.()}}const Se=5e3;function Ce(e,t){let n=Math.min(e-Date.now(),t??Se,Se);return Number.isFinite(n)&&n>0?n:null}function we(n){return e(t(n))||null}function Te(e){let t={"Content-Type":`application/json`};switch(e.credential.kind){case`operation_step_up`:return{ok:!0,headers:t,credentials:`omit`};case`wallet_session_opaque`:{let r=String(e.credential.walletSessionToken||``).trim();return r?(Object.assign(t,n({token:r,home:e.credential.home})),{ok:!0,headers:t,credentials:`omit`}):{ok:!1,code:`invalid_args`,message:`Missing opaque Wallet Session token for Router A/B ECDSA derivation presign pool fill`}}}}function Ee(e){switch(e.authorization.kind){case`reusable_wallet_session`:return{authorization:e.authorization};case`operation_step_up`:{let t=e.operation;if(!t)throw Error(`Operation step-up pool fill requires exact operation preparation`);return{authorization:e.authorization,operation:t}}}}function De(e){let t=String(e.keyHandle||``).trim();return t?{ok:!0,value:{keyHandle:t}}:{ok:!1,code:`invalid_args`,message:`Missing keyHandle for Router A/B ECDSA derivation pool-fill init`}}async function Oe(e){let t=we(e.relayerUrl);if(!t)return{ok:!1,code:`invalid_args`,message:`Missing relayerUrl for Router A/B ECDSA derivation pool-fill init`};if(typeof fetch!=`function`)return{ok:!1,code:`unsupported`,message:`fetch is not available for Router A/B ECDSA derivation pool-fill init`};let n=De(e);if(!n.ok)return n;let r=String(e.requestTag||``).trim(),i=Te(e);if(!i.ok)return i;let a=Ce(e.poolFill.ceremonyExpiresAtMs,e.requestTimeoutMs);if(a===null)return{ok:!1,code:`presign_timeout`,message:`Presign ceremony deadline has elapsed`};try{let{response:o,data:s}=await xe({url:`${t}${e.path}`,operation:`presign/init`,timeoutMs:a,init:{method:`POST`,headers:i.headers,credentials:i.credentials,body:JSON.stringify({...n.value,count:Number.isFinite(e.count)?Math.max(1,Math.floor(Number(e.count))):1,...r?{requestTag:r}:{},poolFill:e.poolFill,presignSessionId:e.presignSessionId,firstMessageB64u:e.firstMessageB64u,...Ee(e)})}});return typeof s.presignSessionId==`string`&&S(s.presignSessionId,`init`,o.headers.get(`Server-Timing`)),o.ok?{ok:s.ok===!0,presignSessionId:s.presignSessionId,...Number.isSafeInteger(s.ceremonyExpiresAtMs)?{ceremonyExpiresAtMs:s.ceremonyExpiresAtMs}:{},...Number.isSafeInteger(s.materialExpiresAtMs)?{materialExpiresAtMs:s.materialExpiresAtMs}:{},stage:s.stage,outgoingMessagesB64u:Array.isArray(s.outgoingMessagesB64u)?s.outgoingMessagesB64u:[],...s.code?{code:s.code}:{},...s.message?{message:s.message}:{}}:{ok:!1,code:s.code||`http_error`,message:s.message||`HTTP ${o.status}`}}catch(e){return{ok:!1,code:`network_error`,message:String(e&&typeof e==`object`&&`message`in e?e.message:e||`Failed Router A/B ECDSA derivation pool-fill init`)}}}async function ke(e){return Oe({...e,path:p})}async function Ae(e){let t=we(e.relayerUrl);if(!t)return{ok:!1,code:`invalid_args`,message:`Missing relayerUrl for Router A/B ECDSA derivation pool-fill step`};if(typeof fetch!=`function`)return{ok:!1,code:`unsupported`,message:`fetch is not available for Router A/B ECDSA derivation pool-fill step`};let n=String(e.presignSessionId||``).trim();if(!n)return{ok:!1,code:`invalid_args`,message:`Missing presignSessionId for Router A/B ECDSA derivation pool-fill step`};let r=String(e.requestTag||``).trim(),i=Te(e);if(!i.ok)return i;let a=Ce(e.ceremonyExpiresAtMs,e.requestTimeoutMs);if(a===null)return{ok:!1,code:`presign_timeout`,message:`Presign ceremony deadline has elapsed`};try{let{response:o,data:s}=await xe({url:`${t}${e.path}`,operation:`presign/step`,timeoutMs:a,init:{method:`POST`,headers:i.headers,credentials:i.credentials,body:JSON.stringify({presignSessionId:n,ceremonyExpiresAtMs:e.ceremonyExpiresAtMs,materialExpiresAtMs:e.materialExpiresAtMs,stage:e.stage,outgoingMessagesB64u:Array.isArray(e.outgoingMessagesB64u)?e.outgoingMessagesB64u:[],...r?{requestTag:r}:{},...Ee(e)})}});return S(n,`step`,o.headers.get(`Server-Timing`)),o.ok?{ok:s.ok===!0,stage:s.stage,event:s.event,outgoingMessagesB64u:Array.isArray(s.outgoingMessagesB64u)?s.outgoingMessagesB64u:[],...s.presignatureId?{presignatureId:s.presignatureId}:{},...s.bigRB64u?{bigRB64u:s.bigRB64u}:{},...s.code?{code:s.code}:{},...s.message?{message:s.message}:{}}:{ok:!1,code:s.code||`http_error`,message:s.message||`HTTP ${o.status}`}}catch(e){return{ok:!1,code:`network_error`,message:String(e&&typeof e==`object`&&`message`in e?e.message:e||`Failed Router A/B ECDSA derivation pool-fill step`)}}}async function je(e){return Ae({...e,path:u})}var Me=class{state={kind:`refilling`,revision:0};waiters=new Map;snapshot(){return this.state}hasForegroundWaiters(){for(let e of this.waiters.values())if(e===`foreground`)return!0;return!1}publishAvailable(){this.state.kind!==`settled`&&(this.state={kind:`refilling`,revision:this.state.revision+1},this.flushWaiters())}settle(){this.state.kind!==`settled`&&(this.state={kind:`settled`,revision:this.state.revision},this.flushWaiters())}waitForChange(e,t){return this.state.kind===`settled`||this.state.revision!==e.revision?Promise.resolve(this.state):new Promise(n=>{this.waiters.set(n,t),(this.state.kind===`settled`||this.state.revision!==e.revision)&&(this.waiters.delete(n),n(this.state))})}flushWaiters(){let e=this.state,t=[...this.waiters.keys()];this.waiters.clear();for(let n of t)n(e)}};function Ne(){let e=globalThis.crypto;if(!e||typeof e.getRandomValues!=`function`)throw Error(`WebCrypto getRandomValues is required for ECDSA rerandomization`);return e.getRandomValues(new Uint8Array(32))}function F(e){switch(e.authorization.kind){case`reusable_wallet_session`:return{authorization:e.authorization};case`operation_step_up`:{let t=e.operation;if(!t)throw Error(`Operation step-up pool fill requires exact operation preparation`);return{authorization:e.authorization,operation:t}}}}function Pe(e){return String(e&&typeof e==`object`&&`message`in e?e.message:e||`signature recovery failed`)}function I(e){e instanceof Uint8Array&&e.fill(0)}function Fe(e){if(e?.kind!==`router_ab_ecdsa_derivation_client_signing_material_source_v1`)throw Error(`Router A/B ECDSA derivation client signing material source is required`)}const Ie=6e4,L=new Map,R=new Map,z=new Map,B=new Map,V=new Map,H=new Map;function Le(e){return e===`triples_done`||e===`presign`||e===`done`}function Re(e){return Le(e.clientStage)&&Le(e.serverStage)?`presign`:`triples`}function ze(e){let t=L.get(e);if(!t?.length)return null;let n=t.shift()??null;return t.length?L.set(e,t):L.delete(e),n}async function U(e){return await Ue(e),ze(e.poolKey)}function Be(e,t,n){if(!K(n))return`invalid`;let r=L.get(e)||[];for(let e of r)if(e.materialHandle===n.materialHandle)return`duplicate`;return r.filter(e=>K(e)).length>=5?`capacity_full`:(r.push(n),L.set(e,r),R.set(e,t),`stored`)}function Ve(e,t=Date.now()){let n=L.get(e);if(!n?.length)return[];let r=[],i=[];for(let e of n)K(e,t)?r.push(e):i.push(e);return r.length>0?L.set(e,r):L.delete(e),i}async function He(e){for(let t of e.refs)await e.clientSigningMaterial.destroyClientPresignature({materialHandle:t.materialHandle,poolIdentity:e.poolIdentity,workerCtx:e.workerCtx}).catch(()=>{})}async function Ue(e){await He({refs:Ve(e.poolKey),poolIdentity:e.poolIdentity,clientSigningMaterial:e.clientSigningMaterial,workerCtx:e.workerCtx})}async function W(e,t,n){try{await v(e.walletId,e.ownershipGeneration)}catch(r){throw await qe({poolIdentity:e,poolKey:_(e),clientSigningMaterial:t,workerCtx:n}),r}}async function We(e){await W(e.poolIdentity,e.clientSigningMaterial,e.workerCtx);let t=V.get(e.poolKey);if(t){await t;return}let n=Ge(e);V.set(e.poolKey,n);try{await n}finally{V.get(e.poolKey)===n&&V.delete(e.poolKey)}}async function Ge(e){await Ue(e);let t;t=await e.clientSigningMaterial.listAvailableClientPresignatures({poolIdentity:e.poolIdentity,workerCtx:e.workerCtx});try{await W(e.poolIdentity,e.clientSigningMaterial,e.workerCtx)}catch{}if(q(e.poolKey)!==e.generation){for(let n of t)I(n.bigR33),await e.clientSigningMaterial.destroyClientPresignature({materialHandle:n.materialHandle,poolIdentity:e.poolIdentity,workerCtx:e.workerCtx}).catch(()=>{});return}for(let n of t){let t=Be(e.poolKey,e.poolIdentity,{presignatureId:n.presignatureId,materialHandle:n.materialHandle,bigRB64u:i(n.bigR33),createdAtMs:n.createdAtMs,expiresAtMs:n.expiresAtMs});I(n.bigR33),(t===`invalid`||t===`capacity_full`)&&await e.clientSigningMaterial.destroyClientPresignature({materialHandle:n.materialHandle,poolIdentity:e.poolIdentity,workerCtx:e.workerCtx}).catch(()=>{})}}function G(e){let t=L.get(e);return t?t.reduce((e,t)=>e+(K(t)?1:0),0):0}function K(e,t=Date.now()){let n=Math.floor(Number(e.expiresAtMs));return!!(e.presignatureId&&e.bigRB64u&&e.materialHandle)&&Number.isSafeInteger(n)&&n>t+2e3}function q(e){let t=H.get(e);return t===void 0?(H.set(e,0),0):t}function Ke(e){Z(e);let t=q(e)+1;return H.set(e,t),t}async function qe(e){let t=L.get(e.poolKey)??[];$e(e.poolKey),await He({...e,refs:t})}function J(e){return B.get(e)||0}function Je(e){let t=J(e);B.set(e,t+1)}function Ye(e){let t=J(e);if(t<=1){B.delete(e),Q(e,0);return}B.set(e,t-1)}async function Xe(e,t){let n=z.get(e);if(!n)return;let r=n.snapshot();for(;G(e)===0&&r.kind===`refilling`;)r=await n.waitForChange(r,t)}async function Ze(e){let t=_(y({ownershipGeneration:e.ownershipGeneration,relayerUrl:e.relayerUrl,scope:e.scope,materialActivation:e.materialActivation}));return G(t)>0?!0:(await Xe(t,`background`),G(t)>0)}function Y(e,t,n){return{scheduled:!1,reason:e,depth:t,targetDepth:n}}function Qe(){let e=new Set([...X.keys(),...L.keys(),...z.keys(),...B.keys(),...H.keys()]);for(let t of e)Ke(t);L.clear(),R.clear();for(let e of z.values())e.settle();z.clear(),B.clear()}function $e(e){L.delete(e),R.delete(e),Ke(e),z.get(e)?.settle(),z.delete(e)}function et(e){let t=String(e).trim();if(!t)throw Error(`ECDSA presignature wallet id is required`);for(let[e,n]of[...R])n.walletId===t&&$e(e)}const X=new Map;function Z(e){let t=X.get(e);t&&t.timer!==null&&clearTimeout(t.timer),X.delete(e),X.size===0&&typeof window<`u`&&(window.removeEventListener(`online`,$),document.removeEventListener(`visibilitychange`,$))}function Q(e,t){let n=X.get(e);if(!n)return;n.timer!==null&&clearTimeout(n.timer);let r=n.input.routerAbEcdsaDerivationPoolFill.ceremonyExpiresAtMs-Date.now();if(r<=0||q(e)!==n.generation){Z(e);return}n.timer=setTimeout(tt,Math.min(t,r),e)}function $(){if(!(typeof document<`u`&&document.visibilityState===`hidden`))for(let e of X.keys())Q(e,0)}function tt(e){let t=X.get(e);if(!t)return;if(t.timer=null,Date.now()>=t.input.routerAbEcdsaDerivationPoolFill.ceremonyExpiresAtMs){Z(e);return}if(typeof navigator<`u`&&navigator.onLine===!1){Q(e,3e4);return}let n=at(t.input);n.scheduled||Q(e,n.depth>=n.targetDepth?3e4:5e3)}function nt(e,t){t.authorization.kind===`reusable_wallet_session`&&X.get(e)?.input!==t&&(Z(e),X.size===0&&typeof window<`u`&&(window.addEventListener(`online`,$),document.addEventListener(`visibilitychange`,$)),X.set(e,{input:t,generation:q(e),failures:0,timer:null}),Q(e,3e4))}function rt(e,t,n){let r=X.get(e);if(!(!r||r!==t)){switch(n){case`network_error`:case`internal`:case`presign_timeout`:case`temporarily_unavailable`:case`service_unavailable`:case`wallet_session_unavailable`:if(r.failures+=1,r.failures<=3)return}Z(e)}}async function it(e){let{args:t,refillInput:n,poolKey:r,poolIdentity:i,scheduledGeneration:a,targetDepth:o,refillAttemptTimeoutMs:s,progress:c}=e,l=X.get(r)??null;try{for(await We({poolKey:r,poolIdentity:i,clientSigningMaterial:t.clientSigningMaterial,workerCtx:t.workerCtx,generation:a}),G(r)>0&&c.publishAvailable();Date.now()<t.routerAbEcdsaDerivationPoolFill.ceremonyExpiresAtMs;){if(q(r)!==a||(X.get(r)??null)!==l||G(r)>=o||J(r)>0||typeof navigator<`u`&&navigator.onLine===!1)return;let e=Math.min(Date.now()+s,t.routerAbEcdsaDerivationPoolFill.ceremonyExpiresAtMs),i=await _t({...n,routerAbEcdsaDerivationPoolFill:{kind:`router_ab_ecdsa_derivation_signing_worker_pool`,scope:n.routerAbEcdsaDerivationPoolFill.scope,ceremonyExpiresAtMs:e,materialExpiresAtMs:n.routerAbEcdsaDerivationPoolFill.materialExpiresAtMs},trafficClass:`background`});if(C(`evm-family`,{event:`ecdsa_background_refill_result`,authorization:t.authorization.kind,outcome:i.ok?`available`:`failed`,code:i.ok?null:i.code,depth:G(r),targetDepth:o}),!i.ok){rt(r,l,i.code);return}let u=X.get(r);u&&u===l&&(u.failures=0),c.publishAvailable()}}catch{rt(r,l,`internal`)}finally{c.settle(),z.get(r)===c&&z.delete(r);let e=X.get(r);if(e){let t=e.failures>0?2e3*2**e.failures:1e3;G(r)>=o&&(t=3e4),e!==l&&(t=0),Q(r,t)}}}function at(e){try{let t=_e(e.poolPolicy),n=y({ownershipGeneration:e.credential.ownershipGeneration,relayerUrl:e.relayerUrl,scope:e.routerAbEcdsaDerivationPoolFill.scope,materialActivation:e.materialActivation}),r=_(n);R.set(r,n);let i=he(e.targetDepth,t.targetDepth),a=ge(e.triggerIfDepthAtOrBelow,t.lowWatermark,i),o=G(r),s=q(r);if(!t.enabled)return Y(`disabled`,o,i);if(e.routerAbEcdsaDerivationPoolFill.ceremonyExpiresAtMs<=Date.now())return Z(r),Y(`invalid_args`,o,i);if(nt(r,e),o>a)return Y(`depth_above_trigger`,o,i);if(o>=i)return Y(`depth_at_or_above_target`,o,i);if(z.has(r)||J(r)>0)return Y(`in_flight_for_pool_key`,o,i);if(z.size>=t.maxRefillInFlight)return Y(`global_in_flight_limit`,o,i);let c={relayerUrl:e.relayerUrl,keyHandle:e.keyHandle,ecdsaThresholdKeyId:e.ecdsaThresholdKeyId,clientVerifyingShareB64u:e.clientVerifyingShareB64u,clientSigningMaterial:e.clientSigningMaterial,thresholdEcdsaPublicKeyB64u:e.thresholdEcdsaPublicKeyB64u,relayerVerifyingShareB64u:e.relayerVerifyingShareB64u,credential:e.credential,materialActivation:e.materialActivation,routerAbEcdsaDerivationPoolFill:e.routerAbEcdsaDerivationPoolFill,workerCtx:e.workerCtx,...F(e)},l=new Me;return z.set(r,l),it({args:e,refillInput:c,poolKey:r,poolIdentity:n,scheduledGeneration:s,targetDepth:i,refillAttemptTimeoutMs:t.refillAttemptTimeoutMs,progress:l}),{scheduled:!0,reason:`scheduled`,depth:o,targetDepth:i}}catch{return Y(`invalid_args`,0,0)}}function ot(e){return e.map(e=>i(e))}function st(e){return Array.isArray(e)?e.map(e=>String(e||``).trim()).filter(e=>!!e).map(e=>a(e)):[]}async function ct(e){let t=String(e.thresholdEcdsaPublicKeyB64u||``).trim();if(t){let n=a(t);if(n.length!==33)throw Error(`thresholdEcdsaPublicKeyB64u must decode to 33 bytes`);return await b({publicKey33:n,workerCtx:e.workerCtx})}let n=String(e.clientVerifyingShareB64u||``).trim(),r=String(e.relayerVerifyingShareB64u||``).trim();if(!n||!r)throw Error(`Missing thresholdEcdsaPublicKeyB64u (or relayerVerifyingShareB64u fallback) for Router A/B ECDSA derivation signing`);let i=a(n),o=a(r);if(i.length!==33)throw Error(`clientVerifyingShareB64u must decode to 33 bytes`);if(o.length!==33)throw Error(`relayerVerifyingShareB64u must decode to 33 bytes`);return await ne({left33:await b({publicKey33:i,workerCtx:e.workerCtx}),right33:await b({publicKey33:o,workerCtx:e.workerCtx}),workerCtx:e.workerCtx})}function lt(e){return e.trafficClass===`foreground`||z.get(e.poolKey)?.hasForegroundWaiters()?`foreground_presign_pool_refill`:`background_presign_pool_refill`}async function ut(e){for(let t=0;t<2;t+=1){let n=await dt(e);if(n.ok||!ft(n)||t===1)return n}return{ok:!1,code:`stale_session_state`,message:`Router A/B ECDSA derivation pool-fill session stayed stale after retry`}}async function dt(e){Fe(e.clientSigningMaterial);let t=performance.now(),n=e.routerAbEcdsaDerivationPoolFill.ceremonyExpiresAtMs,r=e.routerAbEcdsaDerivationPoolFill.materialExpiresAtMs,a=`ecdsa-presign-v2:${n}:${i(crypto.getRandomValues(new Uint8Array(32)))}`,o=a,s=y({ownershipGeneration:e.credential.ownershipGeneration,relayerUrl:e.relayerUrl,scope:e.routerAbEcdsaDerivationPoolFill.scope,materialActivation:e.materialActivation}),c=null,l=null,u=null,d=null,ee=!1,f=`triples`,p=[],m=!0,h=!1;try{let t=await e.clientSigningMaterial.initClientPresignSession({sessionId:o,groupPublicKey33:e.groupPublicKey33,ceremonyExpiresAtMs:n,materialExpiresAtMs:r,poolIdentity:s,workerCtx:e.workerCtx});if(t.stage!==`triples`||t.outgoingMessages.length!==1)return{ok:!1,code:`presign_init_failed`,message:`Client presign init must emit exactly one first message`};f=t.stage;let g=await ke({relayerUrl:e.relayerUrl,...e.poolFillInitKeySelector,count:1,presignSessionId:a,firstMessageB64u:i(t.outgoingMessages[0]),credential:e.credential,requestTag:lt(e),poolFill:e.routerAbEcdsaDerivationPoolFill,...F(e)});if(!g.ok)return{ok:!1,code:g.code||`presign_init_failed`,message:g.message||`Presign initialization failed`};if(g.presignSessionId!==a||g.ceremonyExpiresAtMs!==n||g.materialExpiresAtMs!==r||n<=Date.now())return{ok:!1,code:`invalid_pool_fill_expiry`,message:`Presign initialization changed the bound identity or deadlines`};let _=g.stage||`triples`,v=st(g.outgoingMessagesB64u);for(let t=0;t<64;t++){if(v.length>0&&!c){let t=await e.clientSigningMaterial.stepClientPresignSession({sessionId:o,stage:Re({clientStage:f,serverStage:_}),incomingMessages:v,workerCtx:e.workerCtx});f=t.stage,v=[],p.push(...t.outgoingMessages),t.presignatureHandle&&t.presignatureBigR33&&(c=t.presignatureHandle,l=t.presignatureBigR33)}if(!ee){let i=performance.now(),o=lt(e),s={relayerUrl:e.relayerUrl,presignSessionId:a,ceremonyExpiresAtMs:n,materialExpiresAtMs:r,stage:Re({clientStage:f,serverStage:_}),outgoingMessagesB64u:ot(p),credential:e.credential,requestTag:o,...F(e)},c=await je(s);if(C(`evm-family`,{event:`ecdsa_presignature_round`,requestTag:o,presignSessionId:a,authorization:e.authorization.kind,round:t,stage:s.stage,durationMs:performance.now()-i,outcome:c.ok?`succeeded`:`failed`}),p=[],!c.ok)return{ok:!1,code:c.code||`presign_step_failed`,message:c.message||`Router A/B ECDSA derivation pool-fill step failed`};v=st(c.outgoingMessagesB64u),_=c.stage||_,c.event===`presign_done`&&(u=String(c.presignatureId||``).trim()||null,d=String(c.bigRB64u||``).trim()||null,ee=!0)}if(c&&l&&u&&d)break}if(!c||!l)return{ok:!1,code:`presign_timeout`,message:`Client presign session did not reach done state`};if(!u||!d)return{ok:!1,code:`presign_timeout`,message:`Server presign session did not reach done state`};if(l.length!==33)return{ok:!1,code:`internal`,message:`Invalid local presignature bigR bytes (expected 33, got ${l.length})`};try{let t=Date.now(),n=i(l);if(n!==d)return{ok:!1,code:`presign_mismatch`,message:`Client/server presignature mismatch (bigR mismatch)`};let a=await e.clientSigningMaterial.admitClientPresignature({materialHandle:c,expectedPresignatureId:u,poolIdentity:s,admissionMode:e.authorization.kind===`operation_step_up`?`resident`:`durable`,workerCtx:e.workerCtx});return a.kind===`discarded_capacity`?{ok:!1,code:`pool_full`,message:`Router A/B ECDSA derivation client presignature pool is full`}:a.kind===`discarded_ambiguous`?{ok:!1,code:`presign_failed`,message:`Router A/B ECDSA derivation client presignature admission was ambiguous`}:(h=!0,m=!1,{ok:!0,kind:`available`,presignature:{presignatureId:u,bigRB64u:n,materialHandle:c,createdAtMs:t,expiresAtMs:r}})}finally{I(l)}}catch(e){return{ok:!1,code:`presign_failed`,message:String(e&&typeof e==`object`&&`message`in e?e.message:e||`Router A/B ECDSA derivation pool-fill handshake failed`)}}finally{C(`evm-family`,{event:`ecdsa_presignature_generation`,requestTag:lt(e),presignSessionId:a,authorization:e.authorization.kind,durationMs:performance.now()-t,outcome:h?`available`:`failed`}),I(l),!h&&c&&await e.clientSigningMaterial.destroyClientPresignature({materialHandle:c,poolIdentity:s,workerCtx:e.workerCtx}).catch(()=>{}),m&&await e.clientSigningMaterial.abortClientPresignSession({sessionId:o,workerCtx:e.workerCtx}).catch(()=>{})}}function ft(e){return e.code===`stale_session_state`||e.code===`stale_pool_fill_session`}function pt(e){let t=l(e);return{ecdsaThresholdKeyId:m(t.ecdsa_threshold_key_id),clientVerifyingShareB64u:g(t.public_identity.derivation_client_share_public_key33_b64u),thresholdEcdsaPublicKeyB64u:t.public_identity.threshold_public_key33_b64u}}function mt(e){let t=Math.floor(Number(e.materialExpiresAtMs)),n=Number.isSafeInteger(e.authorizationExpiresAtMs)?Math.floor(Number(e.authorizationExpiresAtMs)):e.nowMs+Ie,r=Math.min(t,n,e.nowMs+Ie);return Number.isSafeInteger(r)&&r>e.nowMs?r:null}async function ht(e,t,n){let r=null,s=null,l=null,u=null,f=null,p={kind:`unclaimed`},m=null,h={kind:`before_prepare`};try{let g=String(e.relayerUrl||``).trim().replace(/\/+$/g,``);if(!g)return{ok:!1,code:`invalid_args`,message:`Missing relayerUrl for Router A/B ECDSA derivation signing`};let v=pt(e.scope);if(!v.ecdsaThresholdKeyId)return{ok:!1,code:`invalid_args`,message:`Missing ecdsaThresholdKeyId for Router A/B ECDSA derivation signing`};let b=v.clientVerifyingShareB64u;if(!b)return{ok:!1,code:`invalid_args`,message:`Missing clientVerifyingShareB64u for Router A/B ECDSA derivation signing`};if(!(e.signingDigest32 instanceof Uint8Array)||e.signingDigest32.length!==32)return{ok:!1,code:`invalid_args`,message:`signingDigest32 must be 32 bytes for Router A/B ECDSA derivation signing`};let ne=performance.now(),S=await ct({clientVerifyingShareB64u:b,thresholdEcdsaPublicKeyB64u:v.thresholdEcdsaPublicKeyB64u,workerCtx:e.workerCtx});x(e.operationId,`public_key_validation`,ne),s=y({ownershipGeneration:e.credential.ownershipGeneration,relayerUrl:g,scope:e.scope,materialActivation:e.materialActivation}),await W(s,e.clientSigningMaterial,e.workerCtx),r=_(s),R.set(r,s),m=q(r);let ie=performance.now();if(l=await U({poolKey:r,poolIdentity:s,clientSigningMaterial:e.clientSigningMaterial,workerCtx:e.workerCtx}),x(e.operationId,`pool_lookup`,ie),!l){let t=performance.now();await We({poolKey:r,poolIdentity:s,clientSigningMaterial:e.clientSigningMaterial,workerCtx:e.workerCtx,generation:m}),x(e.operationId,`pool_restore`,t),m=q(r),l=await U({poolKey:r,poolIdentity:s,clientSigningMaterial:e.clientSigningMaterial,workerCtx:e.workerCtx})}if(!l){let t=performance.now();await Xe(r,`foreground`),x(e.operationId,`refill_wait`,t),m=q(r),l=await U({poolKey:r,poolIdentity:s,clientSigningMaterial:e.clientSigningMaterial,workerCtx:e.workerCtx})}if(!l){let t=performance.now();Je(r);try{let t=await _t({...n,trafficClass:`foreground`});if(!t.ok&&t.code===`invalidated`&&(t=await _t({...n,trafficClass:`foreground`})),!t.ok&&t.code!==`pool_full`)return t;!t.ok&&t.code===`pool_full`&&await We({poolKey:r,poolIdentity:s,clientSigningMaterial:e.clientSigningMaterial,workerCtx:e.workerCtx,generation:q(r)})}finally{Ye(r)}m=q(r),l=await U({poolKey:r,poolIdentity:s,clientSigningMaterial:e.clientSigningMaterial,workerCtx:e.workerCtx}),x(e.operationId,`foreground_refill`,t)}if(C(`evm-family`,{event:`ecdsa_presignature_selection`,operationId:e.operationId,authorization:e.authorization.kind,outcome:l?`available`:`empty`,remainingDepth:G(r),attempt:t}),!l)return{ok:!1,code:`pool_empty`,message:`Router A/B ECDSA derivation client presignature pool is empty`};let ae=Date.now(),w=mt({authorizationExpiresAtMs:e.expiresAtMs,materialExpiresAtMs:l.expiresAtMs,nowMs:ae});if(!w)return{ok:!1,code:`pool_entry_expired`,message:`Router A/B ECDSA derivation client presignature is expired`};if(await W(s,e.clientSigningMaterial,e.workerCtx),m!==q(r))return{ok:!1,code:`pool_entry_unavailable`,message:`Router A/B ECDSA derivation client presignature pool was invalidated before prepare`};f=Ne();let T=await c(f),E=d({scope:e.scope,requestId:o(`router-ab-ecdsa-sign`,32,`Router A/B ECDSA derivation sign request`),operationId:e.operationId,operationDigests:e.operationDigests,authorization:e.authorization,materialActivation:e.materialActivation,clientPresignatureId:l.presignatureId,expiresAtMs:w,signingDigest32:e.signingDigest32,clientRerandomizationCommitment32:T});I(T);let D=o(`router-ab-ecdsa-reservation`,32,`Router A/B ECDSA Client presignature reservation`);p={kind:`destroy`};let oe=performance.now(),O=await e.clientSigningMaterial.reserveClientPresignature({materialHandle:l.materialHandle,expectedPresignatureId:l.presignatureId,poolIdentity:s,requestBinding:E.request_id,reservationId:D,leaseExpiresAtMs:E.expires_at_ms,workerCtx:e.workerCtx});if(x(e.operationId,`presignature_reserve`,oe),O.kind===`unavailable`)return O.reason===`claimed_elsewhere`&&(p={kind:`owned_elsewhere`}),t<4?await ht(e,t+1,n):{ok:!1,code:O.reason===`expired`?`pool_entry_expired`:`pool_entry_unavailable`,message:`Router A/B ECDSA derivation client presignature is unavailable: ${O.reason}`};if(await W(s,e.clientSigningMaterial,e.workerCtx),m!==q(r))return{ok:!1,code:`pool_entry_unavailable`,message:`Router A/B ECDSA derivation client presignature pool was invalidated before prepare`};Q(r,0),h={kind:`prepare_submitted`};let se=performance.now(),k=await le({relayServerUrl:g,credential:e.credential,request:E,onServerTiming:re.bind(void 0,e.operationId,`prepare`)});if(x(e.operationId,`prepare`,se),k.kind===`reusable_wallet_session`){if(!e.reconcileSession)throw Error(`Wallet Session reconciliation is required`);await e.reconcileSession(k.sessionStatus)}let A=k.signing;if(A.server_big_r33_b64u!==l.bigRB64u)return{ok:!1,code:`presign_mismatch`,message:`Router A/B ECDSA derivation SigningWorker returned a different presignature bigR`};let ce=performance.now();await e.clientSigningMaterial.commitClientPresignature({materialHandle:l.materialHandle,poolIdentity:s,requestBinding:E.request_id,reservationId:D,workerCtx:e.workerCtx}),x(e.operationId,`presignature_commit`,ce);let j=a(l.bigRB64u),M=a(A.signing_worker_rerandomization_contribution32_b64u);try{if(j.length!==33)return{ok:!1,code:`internal`,message:`Router A/B ECDSA derivation presign bigR must decode to 33 bytes`};if(M.length!==32)return{ok:!1,code:`internal`,message:`Router A/B ECDSA derivation SigningWorker rerandomization contribution must decode to 32 bytes`};let t=performance.now();u=await e.clientSigningMaterial.computeSignatureShareFromPresignatureHandle({materialHandle:l.materialHandle,poolIdentity:s,requestBinding:E.request_id,reservationId:D,groupPublicKey33:S,expectedPresignBigR33:j,digest32:e.signingDigest32,clientRerandomizationContribution32:f,signingWorkerRerandomizationContribution32:M,workerCtx:e.workerCtx}),x(e.operationId,`client_share`,t),p={kind:`consumed`}}finally{I(j),I(M)}if(u.length!==32)return{ok:!1,code:`internal`,message:`Invalid Router A/B ECDSA derivation client signature share length (expected 32, got ${u.length})`};let de=ee({scope:e.scope,requestId:E.request_id,operationId:E.operation_id,operationDigests:E.operation_digests,authorization:e.authorization,materialActivation:e.materialActivation,expiresAtMs:E.expires_at_ms,signingDigest32:e.signingDigest32,serverPresignatureId:A.server_presignature_id,clientSignatureShare32:u,clientRerandomizationContribution32:f}),fe=performance.now(),pe=await ue({relayServerUrl:g,credential:e.credential,request:de,onServerTiming:re.bind(void 0,e.operationId,`finalize`)});x(e.operationId,`finalize`,fe);let N=a(pe.signature65_b64u);if(N.length!==65)return{ok:!1,code:`internal`,message:`Router A/B ECDSA derivation returned invalid signature length (expected 65, got ${N.length})`};try{let t=performance.now();await te({digest32:e.signingDigest32,signature65:N,publicKey33:S,workerCtx:e.workerCtx}),x(e.operationId,`signature_verify`,t)}catch(e){return{ok:!1,code:`internal`,message:`Router A/B ECDSA derivation returned a signature that does not recover to the threshold group public key: ${Pe(e)}`}}return{ok:!0,signature65:N,signature65B64u:pe.signature65_b64u,rB64u:i(N.slice(0,32)),sB64u:i(N.slice(32,64)),recId:N[64]}}catch(t){if(t instanceof ce||t instanceof j)throw t;let n=String(t&&typeof t==`object`&&`message`in t?t.message:t||`Router A/B ECDSA derivation signing failed`);return t instanceof de&&t.code===`expired_local_request`?{ok:!1,code:`pool_entry_expired`,message:n}:r&&s&&m!==null&&h.kind===`before_prepare`&&q(r)!==m?(await qe({poolKey:r,poolIdentity:s,clientSigningMaterial:e.clientSigningMaterial,workerCtx:e.workerCtx}),{ok:!1,code:`pool_entry_unavailable`,message:`Router A/B ECDSA derivation client presignature pool was invalidated before prepare`}):{ok:!1,code:`router_ab_sign_failed`,message:n}}finally{if(I(u),I(f),l&&s&&p.kind!==`consumed`&&p.kind!==`owned_elsewhere`){let t=!1;if(p.kind===`unclaimed`&&r&&m!==null&&m===q(r)){let e=Be(r,s,l);t=e===`stored`||e===`duplicate`}t||await e.clientSigningMaterial.destroyClientPresignature({materialHandle:l.materialHandle,poolIdentity:s,workerCtx:e.workerCtx}).catch(()=>{})}r&&Q(r,0)}}async function gt(e){let t=pt(e.scope),n=Math.floor(Number(e.expiresAtMs));if(!Number.isSafeInteger(n)||n<=Date.now())return{ok:!1,code:`invalid_pool_fill_expiry`,message:`Router A/B ECDSA derivation pool fill expiry is unavailable or expired`};let r={relayerUrl:e.relayerUrl,keyHandle:e.keyHandle,ecdsaThresholdKeyId:t.ecdsaThresholdKeyId,clientVerifyingShareB64u:t.clientVerifyingShareB64u,clientSigningMaterial:e.clientSigningMaterial,thresholdEcdsaPublicKeyB64u:t.thresholdEcdsaPublicKeyB64u,credential:e.credential,materialActivation:e.materialActivation,routerAbEcdsaDerivationPoolFill:{kind:`router_ab_ecdsa_derivation_signing_worker_pool`,scope:e.scope,ceremonyExpiresAtMs:Math.min(n,Date.now()+f-3e4),materialExpiresAtMs:e.authorization.kind===`operation_step_up`?n:Date.now()+s},workerCtx:e.workerCtx,...F(e)},i=await ht(e,0,r);return!i.ok&&(i.code===`pool_entry_expired`||i.code===`pool_entry_unavailable`)?await ht(e,0,r):i}async function _t(e){try{let t=y({ownershipGeneration:e.credential.ownershipGeneration,relayerUrl:e.relayerUrl,scope:e.routerAbEcdsaDerivationPoolFill.scope,materialActivation:e.materialActivation});await W(t,e.clientSigningMaterial,e.workerCtx);let n=_(t);await Ue({poolKey:n,poolIdentity:t,clientSigningMaterial:e.clientSigningMaterial,workerCtx:e.workerCtx});let r=q(n),i=await ct({clientVerifyingShareB64u:e.clientVerifyingShareB64u,thresholdEcdsaPublicKeyB64u:e.thresholdEcdsaPublicKeyB64u,relayerVerifyingShareB64u:e.relayerVerifyingShareB64u,workerCtx:e.workerCtx}),a=await ut({relayerUrl:e.relayerUrl,poolFillInitKeySelector:{keyHandle:h(e.keyHandle)},clientSigningMaterial:e.clientSigningMaterial,groupPublicKey33:i,materialActivation:e.materialActivation,credential:e.credential,poolKey:n,trafficClass:e.trafficClass,routerAbEcdsaDerivationPoolFill:e.routerAbEcdsaDerivationPoolFill,workerCtx:e.workerCtx,...F(e)});if(!a.ok)return a;try{await W(t,e.clientSigningMaterial,e.workerCtx)}catch{}if(q(n)!==r)return await e.clientSigningMaterial.destroyClientPresignature({materialHandle:a.presignature.materialHandle,poolIdentity:t,workerCtx:e.workerCtx}).catch(()=>{}),{ok:!1,code:`invalidated`,message:`Router A/B ECDSA derivation presignature pool invalidated`};let o=Be(n,t,a.presignature);return(o===`capacity_full`||o===`invalid`)&&await e.clientSigningMaterial.destroyClientPresignature({materialHandle:a.presignature.materialHandle,poolIdentity:t,workerCtx:e.workerCtx}).catch(()=>{}),{ok:!0,presignatureId:a.presignature.presignatureId}}catch(e){return{ok:!1,code:`internal`,message:String(e&&typeof e==`object`&&`message`in e?e.message:e||`Router A/B ECDSA derivation presignature refill failed`)}}}export{Ze as a,pe as c,gt as i,et as n,_e as o,at as r,me as s,Qe as t};
|
package/dist/{esm/sdk/recovery-entrypoint-DJbMDC_m.js → public/sdk/recovery-entrypoint-s9OoKBcl.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{N as e,s as t}from"./domainIds-t1lp25yU.js";import{i as n,n as r}from"./digests-BIaE0DMd.js";import{i}from"./base64-BmKR3UqU.js";import{r as a}from"./secureRandomId-8LSc91aN.js";import"./walletDbName-Ca0rCq5r.js";import"./activeWalletSession-BJ4B-nJo.js";import"./signingSessionSeal-BFOBKj-J.js";import"./capabilityKinds-DVlGMspk.js";import"./errors-BJBDbwHk.js";import"./signerDomain-BAsLT3XN.js";import{g as o,p as s}from"./registrationIntent-Do1tD1V7.js";import"./presignatures-BCeq56DG.js";import"./accountIds-CW2BP-d9.js";import"./device-linking-DiCNt3iA.js";import"./walletAuthority-BTGAuOi8.js";import"./digestEncoding-CqNXPZY9.js";import"./walletAuthMethodRecord-DLBB5fez.js";import"./signerSlot-D2RZnb27.js";import{j as c,t as l,y as u}from"./indexedDB-C4SDsyOG.js";import"./keccak-mS0Mejjx.js";import"./registrationSignerPlan-DK2b3N_p.js";import"./walletCapabilityBindings-D5YYB7nN.js";import"./emailOtpEcdsaDerivationIdentity-HFQXc1Yw.js";import"./wallet-recovery-BZB2Vu3X.js";import{a as d,c as f,d as p,l as m,n as h,o as g,r as _,s as v,t as y,u as b}from"./walletRecoveryCommit-Cc2LAkCS.js";function x(e){throw Error(`Unhandled wallet recovery branch: ${String(e)}`)}function S(e){return e.target.kind===`google_email_otp`}function C(e,t){if(!e||e.stage===`prepared`||e.stage===`google_verified`||e.walletId!==t.walletId||e.target.kind!==t.target.kind)return null;switch(e.target.kind){case`passkey`:return t.kind===`credential_created`&&t.target.kind===`passkey`&&e.target.rpId===t.target.rpId?e:null;case`google_email_otp`:return t.kind===`email_otp_verified`&&t.target.kind===`google_email_otp`&&e.target.googleProvider===t.target.googleProvider?e:null}}function w(){return u(a(`wallet-recovery-reservation`,32,`wallet recovery operation reservations`))}function T(e){return e}const E=`seams:recovery:consumed-code-digests`;function D(){try{let e=JSON.parse(sessionStorage.getItem(E)??`[]`);return Array.isArray(e)?new Set(e.filter(e=>typeof e==`string`)):new Set}catch{return new Set}}function O(e,t){e.add(t);try{sessionStorage.setItem(E,JSON.stringify([...e].slice(-32)))}catch{}}function k(e){e&&e.byteLength>0&&new Uint8Array(e).fill(0)}function A(e){switch(e.recoveryCodeBytes.fill(0),e.stage){case`prepared`:case`google_verified`:return;case`credential_created`:k(e.replacement.factorSecret);return;case`email_otp_verified`:case`manifest_recovered`:k(e.replacement.kind===`passkey`?e.replacement.factorSecret:e.replacement.factor.factorSecret);return}}function j(){return{kind:`refused`}}function M(e){if(typeof e!=`object`||!e)return!1;let t=Reflect.get(e,`name`);return t===`NotAllowedError`||t===`AbortError`}function N(e,t){if(e.target.kind!==`passkey`||!e.prepared.registration)throw Error(`passkey recovery registration is unavailable`);return{stage:`credential_created`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,relayUrl:e.relayUrl,target:e.target,prepared:e.prepared,custodyJson:e.custodyJson,recoveryCodeBytes:e.recoveryCodeBytes,replacement:{kind:`passkey`,registration:t.registration,credentialIdB64u:t.credentialIdB64u,factorSecret:t.factorSecret}}}function P(e,t){return{stage:`email_otp_verified`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,relayUrl:e.relayUrl,target:e.target,prepared:e.prepared,custodyJson:e.custodyJson,recoveryCodeBytes:e.recoveryCodeBytes,replacement:t}}function F(e){let t=e.prepared.registration;if(!t)throw Error(`passkey recovery registration is unavailable`);return{replacementId:t.replacementId,walletAuthMethodId:t.walletAuthMethodId,factor:o({rpId:t.rpId,credentialIdB64u:e.replacement.credentialIdB64u}),factorSecret:e.replacement.factorSecret}}function I(e){let t=e.prepared.registration;if(!t)throw Error(`passkey recovery registration is unavailable`);return t.challengeId}function L(e,t){return{stage:`manifest_recovered`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,relayUrl:e.relayUrl,target:e.target,prepared:e.prepared,custodyJson:e.custodyJson,recoveryCodeBytes:e.recoveryCodeBytes,replacement:e.replacement,recovered:t}}function R(e,t){return{stage:`manifest_recovered`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,relayUrl:e.relayUrl,target:e.target,prepared:e.prepared,custodyJson:e.custodyJson,recoveryCodeBytes:e.recoveryCodeBytes,replacement:e.replacement,recovered:t}}function z(e,t){switch(e.stage){case`credential_created`:return L(e,t);case`email_otp_verified`:return R(e,t);default:return x(e)}}function B(e){return e.authMethod.kind===`passkey`}function V(e){return e.target.kind===`passkey`&&e.replacement.kind===`passkey`}function H(e){return e.target.kind===`google_email_otp`&&e.replacement.kind===`email_otp`}async function U(e){return await e.context.signingEngine.getSignerWorkerContext().requestWorkerOperation({kind:`emailOtp`,request:{type:`releaseWalletRecoveryEmailOtpFactor`,payload:{relayUrl:e.relayUrl,walletId:String(e.walletId),recoveryOperationId:e.recoveryOperationId,reservationId:e.reservationId}}})}async function W(e){let t=e.prepared.registration;if(!t)throw Error(`passkey recovery registration is unavailable`);return await m({relayUrl:e.relayUrl,walletId:e.walletId,reservationId:e.prepared.reservationId,recoveryOperationId:e.prepared.recoveryOperationId,targetDeviceId:e.prepared.targetDeviceId,targetAuthorityId:e.prepared.targetAuthorityId,targetWalletAuthMethodId:e.prepared.targetWalletAuthMethodId,challengeId:t.challengeId,replacementId:t.replacementId,webauthnRegistration:e.replacement.registration,replacementEnvelope:e.recovered.replacementEnvelope,ecdsaMaterialPossessionProofs:e.recovered.ecdsaKeySets.map(e=>({keySetId:e.entry.keySetId,proof:e.activation.possessionProof}))})}var G=class{constructor(e=null){this.rpc=e}#e=new Map;#t=new Map;#n=new Map;#r=new Map;#i=new Map;#a=D();async prepareWithCode(t){if(this.#c(),t.signal.aborted)return j();if(t.target.kind===`passkey`){let n=e(t.context.signingEngine.getRpId());if(!n.ok||n.value!==t.target.rpId)return j()}let n=null;try{n=c(t.recoveryCode);let e=i(await r(n));if(this.#a.has(e))return{kind:`consumed`};let o=T(e),s=this.#r.get(o),l=s?.expiresAtMs&&s.expiresAtMs>Date.now()?s.reservationId:w(),u=await p({relayUrl:t.relayUrl,target:t.target,recoveryCodeB64u:i(n),reservationId:l});if(u.kind!==`prepared`)return u.kind===`retryable_conflict`||u.kind===`transport_uncertain`?this.#r.set(o,{reservationId:l,expiresAtMs:Date.now()+3e5}):this.#r.delete(o),u;if(this.#r.delete(o),t.signal.aborted)return this.#r.set(o,{reservationId:u.reservationId,expiresAtMs:u.reservationExpiresAtMs}),j();let d=a(`wallet-recovery-operation`,24,`wallet recovery client operation handles`);return this.#e.set(d,{stage:`prepared`,recoveryOperationId:d,walletId:u.walletId,relayUrl:t.relayUrl,target:t.target,prepared:u,custodyJson:b({walletId:u.walletId,prepared:u}),recoveryCodeBytes:n}),this.#i.set(d,o),n=null,{kind:`prepared`,recoveryOperationId:d,walletId:u.walletId,target:t.target}}catch{return j()}finally{n?.fill(0)}}createPasskey(e){this.#c();let t=this.#e.get(e.operation.recoveryOperationId);if(!t||t.stage!==`prepared`||t.walletId!==e.operation.walletId||t.target.kind!==`passkey`||e.operation.target.kind!==`passkey`||t.target.rpId!==e.operation.target.rpId||this.#n.has(t.recoveryOperationId)||!t.prepared.registration)return Promise.resolve({kind:`refused`});let n=new AbortController;this.#n.set(t.recoveryOperationId,n);let r;try{r=e.context.signingEngine.createWalletRecoveryReplacementCredential({walletId:t.walletId,registration:t.prepared.registration,cancellation:{kind:`abort_signal`,signal:n.signal}})}catch{return this.cancel(t.recoveryOperationId),Promise.resolve({kind:`refused`})}return this.#s({current:t,credentialPromise:r,promptController:n})}async verifyGoogle(e){this.#c();let t=this.#e.get(e.operation.recoveryOperationId);if(!this.rpc||!t||t.stage!==`prepared`||t.target.kind!==`google_email_otp`||e.operation.target.kind!==`google_email_otp`||t.walletId!==e.operation.walletId||t.target.googleProvider!==e.operation.target.googleProvider||t.relayUrl!==e.relayUrl)return j();let n=t.prepared;if(!S(n))return j();try{let r=await this.rpc.verifyGoogle({relayUrl:t.relayUrl,recoveryOperationId:n.recoveryOperationId,reservationId:n.reservationId,idToken:e.idToken});if(r.kind!==`verified`)return r;if(r.recoveryOperationId!==n.recoveryOperationId)return{kind:`transport_uncertain`};let i={kind:`google_verified`,recoveryOperationId:t.recoveryOperationId,walletId:t.walletId,target:t.target,challengeId:r.challengeId,delivery:r.delivery,expiresAtMs:r.expiresAtMs},a={stage:`google_verified`,recoveryOperationId:t.recoveryOperationId,walletId:t.walletId,relayUrl:t.relayUrl,target:t.target,prepared:n,custodyJson:t.custodyJson,recoveryCodeBytes:t.recoveryCodeBytes,verification:i};return this.#e.set(a.recoveryOperationId,a),i}catch{return{kind:`transport_uncertain`}}}async verifyEmailOtp(e){this.#c();let n=this.#e.get(e.operation.recoveryOperationId);if(!this.rpc||!n||n.stage!==`google_verified`||n.walletId!==e.operation.walletId||n.target.kind!==`google_email_otp`||e.operation.target.kind!==`google_email_otp`||n.verification.challengeId!==e.operation.challengeId||e.challengeId!==e.operation.challengeId)return j();let r=t(e.challengeId);if(!r.ok)return j();try{let t=await this.rpc.verifyEmailOtp({relayUrl:n.relayUrl,recoveryOperationId:n.prepared.recoveryOperationId,reservationId:n.prepared.reservationId,challengeId:r.value,otpCode:e.otpCode});if(t.kind!==`verified`)return t;if(t.recoveryOperationId!==n.prepared.recoveryOperationId||t.challengeId!==e.challengeId)return{kind:`transport_uncertain`};let i=await U({context:e.context,relayUrl:n.relayUrl,walletId:n.walletId,recoveryOperationId:n.prepared.recoveryOperationId,reservationId:String(n.prepared.reservationId)});if(i.kind===`existing`){if(i.recoveryOperationId!==String(n.prepared.recoveryOperationId)||i.reservationId!==String(n.prepared.reservationId)||i.factorSecret32.byteLength!==32)return k(i.factorSecret32),{kind:`transport_uncertain`};let t=P(n,{kind:`email_otp`,factor:{replacementId:String(n.prepared.recoveryOperationId),walletAuthMethodId:n.prepared.targetWalletAuthMethodId,factor:s({enrollmentId:i.enrollmentId,enrollmentSealKeyVersion:i.enrollmentSealKeyVersion}),factorSecret:i.factorSecret32},enrollment:{kind:`existing`,enrollmentId:i.enrollmentId,enrollmentSealKeyVersion:i.enrollmentSealKeyVersion},providerSubject:i.providerSubject,verifiedEmail:i.verifiedEmail,registrationAuthorityId:e.challengeId});return this.#e.set(t.recoveryOperationId,t),{kind:`email_otp_verified`,recoveryOperationId:t.recoveryOperationId,walletId:t.walletId,target:t.target,challengeId:e.challengeId}}if(i.kind!==`create`)return i;if(i.recoveryOperationId!==String(n.prepared.recoveryOperationId)||i.reservationId!==String(n.prepared.reservationId))return{kind:`transport_uncertain`};let a=crypto.getRandomValues(new Uint8Array(32)),o=null;try{let t=await e.context.signingEngine.prepareEmailOtpRegistrationEnrollmentMaterialInternal({relayUrl:n.relayUrl,walletId:n.walletId,userId:i.providerSubject,clientSecret32:a});o=a.slice().buffer;let r=P(n,{kind:`email_otp`,factor:{replacementId:String(n.prepared.recoveryOperationId),walletAuthMethodId:n.prepared.targetWalletAuthMethodId,factor:s({enrollmentId:t.enrollmentId,enrollmentSealKeyVersion:t.enrollmentSealKeyVersion}),factorSecret:o},enrollment:{kind:`create`,enrollmentId:t.enrollmentId,providerSubject:i.providerSubject,verifiedEmail:i.verifiedEmail,material:t.emailOtpEnrollment},providerSubject:i.providerSubject,verifiedEmail:i.verifiedEmail,registrationAuthorityId:e.challengeId});return this.#e.set(r.recoveryOperationId,r),o=null,{kind:`email_otp_verified`,recoveryOperationId:r.recoveryOperationId,walletId:r.walletId,target:r.target,challengeId:e.challengeId}}finally{a.fill(0),o&&k(o)}}catch{return{kind:`refused`}}}async finalize(e){let t=String(e.operation.recoveryOperationId),n=this.#t.get(t);if(n)return n;let r=this.#o(e).finally(()=>{this.#t.delete(t)});return this.#t.set(t,r),r}async#o(e){this.#c();let t=C(this.#e.get(e.operation.recoveryOperationId),e.operation);if(!t)return j();try{if(t.stage===`credential_created`||t.stage===`email_otp_verified`){let n=t.stage===`credential_created`?F(t):t.replacement.factor,r=await e.context.signingEngine.recoverWalletCustodyManifest({walletId:t.walletId,prepared:t.prepared,custodyJson:t.custodyJson,recoveryCodeBytes:t.recoveryCodeBytes,replacementFactor:n,recoveryChallengeId:t.stage===`credential_created`?I(t):String(t.prepared.recoveryOperationId),relayUrl:t.relayUrl});if(this.#e.get(t.recoveryOperationId)!==t)return A(t),j();if(t.prepared.reservationExpiresAtMs<=Date.now())return this.cancel(t.recoveryOperationId),j();t.recoveryCodeBytes.fill(0),k(t.stage===`credential_created`?t.replacement.factorSecret:t.replacement.factor.factorSecret),t=z(t,r),this.#e.set(t.recoveryOperationId,t)}if(t.stage===`manifest_recovered`){if(!V(t)&&!H(t))return{kind:`transport_uncertain`};if(t.target.kind===`google_email_otp`&&!this.rpc)return{kind:`refused`};let e=await y({operation:t});if(this.#e.get(t.recoveryOperationId)!==t)return{kind:`transport_uncertain`};await l.putPendingWalletRecoveryCommit(e.pending);let r=V(t)?await W(t):this.rpc?await this.rpc.finalizeEmailOtp({relayUrl:t.relayUrl,walletId:t.walletId,recoveryOperationId:t.prepared.recoveryOperationId,reservationId:t.prepared.reservationId,targetDeviceId:t.prepared.targetDeviceId,targetAuthorityId:t.prepared.targetAuthorityId,targetWalletAuthMethodId:t.prepared.targetWalletAuthMethodId,expectedProviderSubject:t.replacement.providerSubject,expectedEmailHashHex:await n(t.replacement.verifiedEmail),expectedRegistrationAuthorityId:t.replacement.registrationAuthorityId,replacementEnvelope:t.recovered.replacementEnvelope,ecdsaMaterialPossessionProofs:t.recovered.ecdsaKeySets.map(e=>({keySetId:e.entry.keySetId,proof:e.activation.possessionProof})),emailOtpEnrollment:t.replacement.enrollment.kind===`create`?{kind:`create`,material:t.replacement.enrollment.material}:null}):{kind:`refused`};if(r.kind===`refused`)return await l.deletePendingWalletRecoveryCommit(t.prepared.recoveryOperationId),this.#e.get(t.recoveryOperationId)===t&&this.cancel(t.recoveryOperationId),r;if(this.#e.get(t.recoveryOperationId)!==t)return r.kind===`promoted`?{kind:`transport_uncertain`}:r;if(r.kind!==`promoted`)return r;if(t.replacement.kind===`passkey`&&r.authMethod.credentialIdB64u!==t.replacement.credentialIdB64u)return{kind:`transport_uncertain`};let i;if(f(e.payload)){if(!B(r))return{kind:`transport_uncertain`};i={kind:`passkey`,payload:e.payload,promotion:r}}else{if(B(r))return{kind:`transport_uncertain`};i={kind:`google_email_otp`,payload:e.payload,promotion:r}}await _({pending:await h({awaiting:e.pending,promotion:i}),payload:i.payload})}let r=this.#i.get(t.recoveryOperationId);return r&&O(this.#a,r),this.#e.delete(t.recoveryOperationId),this.#i.delete(t.recoveryOperationId),A(t),{kind:`ready_for_sign_in`,walletId:t.walletId}}catch{return{kind:`transport_uncertain`}}}async#s(e){try{let t=await e.credentialPromise;if(this.#e.get(e.current.recoveryOperationId)!==e.current||e.promptController.signal.aborted)return k(t.factorSecret),{kind:`dismissed`};if(e.current.prepared.reservationExpiresAtMs<=Date.now())return k(t.factorSecret),this.cancel(e.current.recoveryOperationId),{kind:`refused`};let n=N(e.current,t);return this.#e.set(n.recoveryOperationId,n),{kind:`credential_created`,recoveryOperationId:n.recoveryOperationId,walletId:n.walletId,target:n.target}}catch(t){return e.promptController.signal.aborted||M(t)?{kind:`dismissed`}:{kind:`transport_uncertain`}}finally{this.#n.get(e.current.recoveryOperationId)===e.promptController&&this.#n.delete(e.current.recoveryOperationId)}}cancel(e){this.#n.get(e)?.abort(),this.#n.delete(e);let t=this.#e.get(e);if(!t)return;let n=this.#i.get(e);this.#i.delete(e),n&&t.prepared.reservationExpiresAtMs>Date.now()&&this.#r.set(n,{reservationId:t.prepared.reservationId,expiresAtMs:t.prepared.reservationExpiresAtMs}),this.#e.delete(e),A(t)}#c(){let e=Date.now();for(let[t,n]of this.#r)n.expiresAtMs<=e&&this.#r.delete(t);for(let[t,n]of this.#e)n.prepared.reservationExpiresAtMs>e||(this.#n.get(t)?.abort(),this.#n.delete(t),this.#e.delete(t),this.#i.delete(t),A(n))}},K=class{#e=new G({verifyGoogle:v,verifyEmailOtp:g,finalizeEmailOtp:d});constructor(t,n){this.context=t,this.relayUrl=n;let r=e(t.signingEngine.getRpId());if(!r.ok)throw Error(`wallet recovery RP ID ${r.error.message}`);this.#t=r.value}#t;targetFor(e){switch(e){case`passkey`:return{kind:e,rpId:this.#t};case`google_email_otp`:return{kind:e,googleProvider:`google`}}}async prepare(e){let t=await this.#e.prepareWithCode({context:this.context,relayUrl:this.relayUrl,recoveryCode:e.recoveryCode,target:e.target,signal:e.signal});return t.kind===`prepared`?(t.target.kind,{kind:`hosted_recovery_prepared`,recoveryOperationId:t.recoveryOperationId,walletId:t.walletId,target:t.target}):t}createPasskey(e){return this.#n({kind:`prepared`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,target:e.target})}async verifyGoogle(e,t){let n=await this.#e.verifyGoogle({relayUrl:this.relayUrl,operation:{kind:`prepared`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,target:e.target},idToken:t});return n.kind===`google_verified`?{kind:`hosted_recovery_google_verified`,recoveryOperationId:n.recoveryOperationId,walletId:n.walletId,target:n.target,challengeId:n.challengeId,delivery:n.delivery,expiresAtMs:n.expiresAtMs}:n}async verifyEmailOtp(e,t){let n=await this.#e.verifyEmailOtp({context:this.context,operation:{kind:`google_verified`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,target:e.target,challengeId:e.challengeId,delivery:e.delivery,expiresAtMs:e.expiresAtMs},challengeId:t.challengeId,otpCode:t.otpCode});return n.kind===`email_otp_verified`?{kind:`hosted_recovery_email_otp_verified`,recoveryOperationId:n.recoveryOperationId,walletId:n.walletId,target:n.target,challengeId:n.challengeId}:n}async finalize(e){return e.kind===`hosted_recovery_credential_created`?await this.#e.finalize({context:this.context,operation:{kind:`credential_created`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,target:e.target}}):await this.#e.finalize({context:this.context,operation:{kind:`email_otp_verified`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,target:e.target,challengeId:e.challengeId}})}async cancel(e){this.#e.cancel(e.recoveryOperationId)}async#n(e){let t=await this.#e.createPasskey({context:this.context,operation:e});return t.kind===`credential_created`?this.#r(t):t}#r(e){return{kind:`hosted_recovery_credential_created`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,target:e.target}}};function q(e){return new K(e.context,e.relayUrl)}export{q as createHostedRecoveryPort};
|
|
1
|
+
import{N as e,s as t}from"./domainIds-t1lp25yU.js";import{i as n,n as r}from"./digests-BIaE0DMd.js";import{i}from"./base64-BmKR3UqU.js";import{r as a}from"./secureRandomId-8LSc91aN.js";import"./walletDbName-Ca0rCq5r.js";import"./activeWalletSession-BJ4B-nJo.js";import"./signingSessionSeal-BFOBKj-J.js";import"./capabilityKinds-DVlGMspk.js";import"./errors-BJBDbwHk.js";import"./signerDomain-D-EUTlLK.js";import"./accountIds-DGWFzEnw.js";import{g as o,p as s}from"./registrationIntent-C1-Kyx_-.js";import"./presignatures-CkhuZ0YQ.js";import"./device-linking-_o3_fgiG.js";import"./walletAuthority-DbGaSw7D.js";import"./digestEncoding-34kXJoJr.js";import"./walletAuthMethodRecord-BW-XV4fv.js";import"./signerSlot-BlijMq8C.js";import{j as c,t as l,y as u}from"./indexedDB-CA4tGqkr.js";import"./keccak-DGHI1G6t.js";import"./registrationSignerPlan-CeMidFme.js";import"./walletCapabilityBindings-mPx-6_r-.js";import"./emailOtpEcdsaDerivationIdentity-Qd4pBwHv.js";import"./wallet-recovery-DXdm68_Q.js";import{a as d,c as f,d as p,l as m,n as h,o as g,r as _,s as v,t as y,u as b}from"./walletRecoveryCommit-DbAoiJp5.js";function x(e){throw Error(`Unhandled wallet recovery branch: ${String(e)}`)}function S(e){return e.target.kind===`google_email_otp`}function C(e,t){if(!e||e.stage===`prepared`||e.stage===`google_verified`||e.walletId!==t.walletId||e.target.kind!==t.target.kind)return null;switch(e.target.kind){case`passkey`:return t.kind===`credential_created`&&t.target.kind===`passkey`&&e.target.rpId===t.target.rpId?e:null;case`google_email_otp`:return t.kind===`email_otp_verified`&&t.target.kind===`google_email_otp`&&e.target.googleProvider===t.target.googleProvider?e:null}}function w(){return u(a(`wallet-recovery-reservation`,32,`wallet recovery operation reservations`))}function T(e){return e}const E=`seams:recovery:consumed-code-digests`;function D(){try{let e=JSON.parse(sessionStorage.getItem(E)??`[]`);return Array.isArray(e)?new Set(e.filter(e=>typeof e==`string`)):new Set}catch{return new Set}}function O(e,t){e.add(t);try{sessionStorage.setItem(E,JSON.stringify([...e].slice(-32)))}catch{}}function k(e){e&&e.byteLength>0&&new Uint8Array(e).fill(0)}function A(e){switch(e.recoveryCodeBytes.fill(0),e.stage){case`prepared`:case`google_verified`:return;case`credential_created`:k(e.replacement.factorSecret);return;case`email_otp_verified`:case`manifest_recovered`:k(e.replacement.kind===`passkey`?e.replacement.factorSecret:e.replacement.factor.factorSecret);return}}function j(){return{kind:`refused`}}function M(e){if(typeof e!=`object`||!e)return!1;let t=Reflect.get(e,`name`);return t===`NotAllowedError`||t===`AbortError`}function N(e,t){if(e.target.kind!==`passkey`||!e.prepared.registration)throw Error(`passkey recovery registration is unavailable`);return{stage:`credential_created`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,relayUrl:e.relayUrl,target:e.target,prepared:e.prepared,custodyJson:e.custodyJson,recoveryCodeBytes:e.recoveryCodeBytes,replacement:{kind:`passkey`,registration:t.registration,credentialIdB64u:t.credentialIdB64u,factorSecret:t.factorSecret}}}function P(e,t){return{stage:`email_otp_verified`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,relayUrl:e.relayUrl,target:e.target,prepared:e.prepared,custodyJson:e.custodyJson,recoveryCodeBytes:e.recoveryCodeBytes,replacement:t}}function F(e){let t=e.prepared.registration;if(!t)throw Error(`passkey recovery registration is unavailable`);return{replacementId:t.replacementId,walletAuthMethodId:t.walletAuthMethodId,factor:o({rpId:t.rpId,credentialIdB64u:e.replacement.credentialIdB64u}),factorSecret:e.replacement.factorSecret}}function I(e){let t=e.prepared.registration;if(!t)throw Error(`passkey recovery registration is unavailable`);return t.challengeId}function L(e,t){return{stage:`manifest_recovered`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,relayUrl:e.relayUrl,target:e.target,prepared:e.prepared,custodyJson:e.custodyJson,recoveryCodeBytes:e.recoveryCodeBytes,replacement:e.replacement,recovered:t}}function R(e,t){return{stage:`manifest_recovered`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,relayUrl:e.relayUrl,target:e.target,prepared:e.prepared,custodyJson:e.custodyJson,recoveryCodeBytes:e.recoveryCodeBytes,replacement:e.replacement,recovered:t}}function z(e,t){switch(e.stage){case`credential_created`:return L(e,t);case`email_otp_verified`:return R(e,t);default:return x(e)}}function B(e){return e.authMethod.kind===`passkey`}function V(e){return e.target.kind===`passkey`&&e.replacement.kind===`passkey`}function H(e){return e.target.kind===`google_email_otp`&&e.replacement.kind===`email_otp`}async function U(e){return await e.context.signingEngine.getSignerWorkerContext().requestWorkerOperation({kind:`emailOtp`,request:{type:`releaseWalletRecoveryEmailOtpFactor`,payload:{relayUrl:e.relayUrl,walletId:String(e.walletId),recoveryOperationId:e.recoveryOperationId,reservationId:e.reservationId}}})}async function W(e){let t=e.prepared.registration;if(!t)throw Error(`passkey recovery registration is unavailable`);return await m({relayUrl:e.relayUrl,walletId:e.walletId,reservationId:e.prepared.reservationId,recoveryOperationId:e.prepared.recoveryOperationId,targetDeviceId:e.prepared.targetDeviceId,targetAuthorityId:e.prepared.targetAuthorityId,targetWalletAuthMethodId:e.prepared.targetWalletAuthMethodId,challengeId:t.challengeId,replacementId:t.replacementId,webauthnRegistration:e.replacement.registration,replacementEnvelope:e.recovered.replacementEnvelope,ecdsaMaterialPossessionProofs:e.recovered.ecdsaKeySets.map(e=>({keySetId:e.entry.keySetId,proof:e.activation.possessionProof}))})}var G=class{constructor(e=null){this.rpc=e}#e=new Map;#t=new Map;#n=new Map;#r=new Map;#i=new Map;#a=D();async prepareWithCode(t){if(this.#c(),t.signal.aborted)return j();if(t.target.kind===`passkey`){let n=e(t.context.signingEngine.getRpId());if(!n.ok||n.value!==t.target.rpId)return j()}let n=null;try{n=c(t.recoveryCode);let e=i(await r(n));if(this.#a.has(e))return{kind:`consumed`};let o=T(e),s=this.#r.get(o),l=s?.expiresAtMs&&s.expiresAtMs>Date.now()?s.reservationId:w(),u=await p({relayUrl:t.relayUrl,target:t.target,recoveryCodeB64u:i(n),reservationId:l});if(u.kind!==`prepared`)return u.kind===`retryable_conflict`||u.kind===`transport_uncertain`?this.#r.set(o,{reservationId:l,expiresAtMs:Date.now()+3e5}):this.#r.delete(o),u;if(this.#r.delete(o),t.signal.aborted)return this.#r.set(o,{reservationId:u.reservationId,expiresAtMs:u.reservationExpiresAtMs}),j();let d=a(`wallet-recovery-operation`,24,`wallet recovery client operation handles`);return this.#e.set(d,{stage:`prepared`,recoveryOperationId:d,walletId:u.walletId,relayUrl:t.relayUrl,target:t.target,prepared:u,custodyJson:b({walletId:u.walletId,prepared:u}),recoveryCodeBytes:n}),this.#i.set(d,o),n=null,{kind:`prepared`,recoveryOperationId:d,walletId:u.walletId,target:t.target}}catch{return j()}finally{n?.fill(0)}}createPasskey(e){this.#c();let t=this.#e.get(e.operation.recoveryOperationId);if(!t||t.stage!==`prepared`||t.walletId!==e.operation.walletId||t.target.kind!==`passkey`||e.operation.target.kind!==`passkey`||t.target.rpId!==e.operation.target.rpId||this.#n.has(t.recoveryOperationId)||!t.prepared.registration)return Promise.resolve({kind:`refused`});let n=new AbortController;this.#n.set(t.recoveryOperationId,n);let r;try{r=e.context.signingEngine.createWalletRecoveryReplacementCredential({walletId:t.walletId,registration:t.prepared.registration,cancellation:{kind:`abort_signal`,signal:n.signal}})}catch{return this.cancel(t.recoveryOperationId),Promise.resolve({kind:`refused`})}return this.#s({current:t,credentialPromise:r,promptController:n})}async verifyGoogle(e){this.#c();let t=this.#e.get(e.operation.recoveryOperationId);if(!this.rpc||!t||t.stage!==`prepared`||t.target.kind!==`google_email_otp`||e.operation.target.kind!==`google_email_otp`||t.walletId!==e.operation.walletId||t.target.googleProvider!==e.operation.target.googleProvider||t.relayUrl!==e.relayUrl)return j();let n=t.prepared;if(!S(n))return j();try{let r=await this.rpc.verifyGoogle({relayUrl:t.relayUrl,recoveryOperationId:n.recoveryOperationId,reservationId:n.reservationId,idToken:e.idToken});if(r.kind!==`verified`)return r;if(r.recoveryOperationId!==n.recoveryOperationId)return{kind:`transport_uncertain`};let i={kind:`google_verified`,recoveryOperationId:t.recoveryOperationId,walletId:t.walletId,target:t.target,challengeId:r.challengeId,delivery:r.delivery,expiresAtMs:r.expiresAtMs},a={stage:`google_verified`,recoveryOperationId:t.recoveryOperationId,walletId:t.walletId,relayUrl:t.relayUrl,target:t.target,prepared:n,custodyJson:t.custodyJson,recoveryCodeBytes:t.recoveryCodeBytes,verification:i};return this.#e.set(a.recoveryOperationId,a),i}catch{return{kind:`transport_uncertain`}}}async verifyEmailOtp(e){this.#c();let n=this.#e.get(e.operation.recoveryOperationId);if(!this.rpc||!n||n.stage!==`google_verified`||n.walletId!==e.operation.walletId||n.target.kind!==`google_email_otp`||e.operation.target.kind!==`google_email_otp`||n.verification.challengeId!==e.operation.challengeId||e.challengeId!==e.operation.challengeId)return j();let r=t(e.challengeId);if(!r.ok)return j();try{let t=await this.rpc.verifyEmailOtp({relayUrl:n.relayUrl,recoveryOperationId:n.prepared.recoveryOperationId,reservationId:n.prepared.reservationId,challengeId:r.value,otpCode:e.otpCode});if(t.kind!==`verified`)return t;if(t.recoveryOperationId!==n.prepared.recoveryOperationId||t.challengeId!==e.challengeId)return{kind:`transport_uncertain`};let i=await U({context:e.context,relayUrl:n.relayUrl,walletId:n.walletId,recoveryOperationId:n.prepared.recoveryOperationId,reservationId:String(n.prepared.reservationId)});if(i.kind===`existing`){if(i.recoveryOperationId!==String(n.prepared.recoveryOperationId)||i.reservationId!==String(n.prepared.reservationId)||i.factorSecret32.byteLength!==32)return k(i.factorSecret32),{kind:`transport_uncertain`};let t=P(n,{kind:`email_otp`,factor:{replacementId:String(n.prepared.recoveryOperationId),walletAuthMethodId:n.prepared.targetWalletAuthMethodId,factor:s({enrollmentId:i.enrollmentId,enrollmentSealKeyVersion:i.enrollmentSealKeyVersion}),factorSecret:i.factorSecret32},enrollment:{kind:`existing`,enrollmentId:i.enrollmentId,enrollmentSealKeyVersion:i.enrollmentSealKeyVersion},providerSubject:i.providerSubject,verifiedEmail:i.verifiedEmail,registrationAuthorityId:e.challengeId});return this.#e.set(t.recoveryOperationId,t),{kind:`email_otp_verified`,recoveryOperationId:t.recoveryOperationId,walletId:t.walletId,target:t.target,challengeId:e.challengeId}}if(i.kind!==`create`)return i;if(i.recoveryOperationId!==String(n.prepared.recoveryOperationId)||i.reservationId!==String(n.prepared.reservationId))return{kind:`transport_uncertain`};let a=crypto.getRandomValues(new Uint8Array(32)),o=null;try{let t=await e.context.signingEngine.prepareEmailOtpRegistrationEnrollmentMaterialInternal({relayUrl:n.relayUrl,walletId:n.walletId,userId:i.providerSubject,clientSecret32:a});o=a.slice().buffer;let r=P(n,{kind:`email_otp`,factor:{replacementId:String(n.prepared.recoveryOperationId),walletAuthMethodId:n.prepared.targetWalletAuthMethodId,factor:s({enrollmentId:t.enrollmentId,enrollmentSealKeyVersion:t.enrollmentSealKeyVersion}),factorSecret:o},enrollment:{kind:`create`,enrollmentId:t.enrollmentId,providerSubject:i.providerSubject,verifiedEmail:i.verifiedEmail,material:t.emailOtpEnrollment},providerSubject:i.providerSubject,verifiedEmail:i.verifiedEmail,registrationAuthorityId:e.challengeId});return this.#e.set(r.recoveryOperationId,r),o=null,{kind:`email_otp_verified`,recoveryOperationId:r.recoveryOperationId,walletId:r.walletId,target:r.target,challengeId:e.challengeId}}finally{a.fill(0),o&&k(o)}}catch{return{kind:`refused`}}}async finalize(e){let t=String(e.operation.recoveryOperationId),n=this.#t.get(t);if(n)return n;let r=this.#o(e).finally(()=>{this.#t.delete(t)});return this.#t.set(t,r),r}async#o(e){this.#c();let t=C(this.#e.get(e.operation.recoveryOperationId),e.operation);if(!t)return j();try{if(t.stage===`credential_created`||t.stage===`email_otp_verified`){let n=t.stage===`credential_created`?F(t):t.replacement.factor,r=await e.context.signingEngine.recoverWalletCustodyManifest({walletId:t.walletId,prepared:t.prepared,custodyJson:t.custodyJson,recoveryCodeBytes:t.recoveryCodeBytes,replacementFactor:n,recoveryChallengeId:t.stage===`credential_created`?I(t):String(t.prepared.recoveryOperationId),relayUrl:t.relayUrl});if(this.#e.get(t.recoveryOperationId)!==t)return A(t),j();if(t.prepared.reservationExpiresAtMs<=Date.now())return this.cancel(t.recoveryOperationId),j();t.recoveryCodeBytes.fill(0),k(t.stage===`credential_created`?t.replacement.factorSecret:t.replacement.factor.factorSecret),t=z(t,r),this.#e.set(t.recoveryOperationId,t)}if(t.stage===`manifest_recovered`){if(!V(t)&&!H(t))return{kind:`transport_uncertain`};if(t.target.kind===`google_email_otp`&&!this.rpc)return{kind:`refused`};let e=await y({operation:t});if(this.#e.get(t.recoveryOperationId)!==t)return{kind:`transport_uncertain`};await l.putPendingWalletRecoveryCommit(e.pending);let r=V(t)?await W(t):this.rpc?await this.rpc.finalizeEmailOtp({relayUrl:t.relayUrl,walletId:t.walletId,recoveryOperationId:t.prepared.recoveryOperationId,reservationId:t.prepared.reservationId,targetDeviceId:t.prepared.targetDeviceId,targetAuthorityId:t.prepared.targetAuthorityId,targetWalletAuthMethodId:t.prepared.targetWalletAuthMethodId,expectedProviderSubject:t.replacement.providerSubject,expectedEmailHashHex:await n(t.replacement.verifiedEmail),expectedRegistrationAuthorityId:t.replacement.registrationAuthorityId,replacementEnvelope:t.recovered.replacementEnvelope,ecdsaMaterialPossessionProofs:t.recovered.ecdsaKeySets.map(e=>({keySetId:e.entry.keySetId,proof:e.activation.possessionProof})),emailOtpEnrollment:t.replacement.enrollment.kind===`create`?{kind:`create`,material:t.replacement.enrollment.material}:null}):{kind:`refused`};if(r.kind===`refused`)return await l.deletePendingWalletRecoveryCommit(t.prepared.recoveryOperationId),this.#e.get(t.recoveryOperationId)===t&&this.cancel(t.recoveryOperationId),r;if(this.#e.get(t.recoveryOperationId)!==t)return r.kind===`promoted`?{kind:`transport_uncertain`}:r;if(r.kind!==`promoted`)return r;if(t.replacement.kind===`passkey`&&r.authMethod.credentialIdB64u!==t.replacement.credentialIdB64u)return{kind:`transport_uncertain`};let i;if(f(e.payload)){if(!B(r))return{kind:`transport_uncertain`};i={kind:`passkey`,payload:e.payload,promotion:r}}else{if(B(r))return{kind:`transport_uncertain`};i={kind:`google_email_otp`,payload:e.payload,promotion:r}}await _({pending:await h({awaiting:e.pending,promotion:i}),payload:i.payload})}let r=this.#i.get(t.recoveryOperationId);return r&&O(this.#a,r),this.#e.delete(t.recoveryOperationId),this.#i.delete(t.recoveryOperationId),A(t),{kind:`ready_for_sign_in`,walletId:t.walletId}}catch{return{kind:`transport_uncertain`}}}async#s(e){try{let t=await e.credentialPromise;if(this.#e.get(e.current.recoveryOperationId)!==e.current||e.promptController.signal.aborted)return k(t.factorSecret),{kind:`dismissed`};if(e.current.prepared.reservationExpiresAtMs<=Date.now())return k(t.factorSecret),this.cancel(e.current.recoveryOperationId),{kind:`refused`};let n=N(e.current,t);return this.#e.set(n.recoveryOperationId,n),{kind:`credential_created`,recoveryOperationId:n.recoveryOperationId,walletId:n.walletId,target:n.target}}catch(t){return e.promptController.signal.aborted||M(t)?{kind:`dismissed`}:{kind:`transport_uncertain`}}finally{this.#n.get(e.current.recoveryOperationId)===e.promptController&&this.#n.delete(e.current.recoveryOperationId)}}cancel(e){this.#n.get(e)?.abort(),this.#n.delete(e);let t=this.#e.get(e);if(!t)return;let n=this.#i.get(e);this.#i.delete(e),n&&t.prepared.reservationExpiresAtMs>Date.now()&&this.#r.set(n,{reservationId:t.prepared.reservationId,expiresAtMs:t.prepared.reservationExpiresAtMs}),this.#e.delete(e),A(t)}#c(){let e=Date.now();for(let[t,n]of this.#r)n.expiresAtMs<=e&&this.#r.delete(t);for(let[t,n]of this.#e)n.prepared.reservationExpiresAtMs>e||(this.#n.get(t)?.abort(),this.#n.delete(t),this.#e.delete(t),this.#i.delete(t),A(n))}},K=class{#e=new G({verifyGoogle:v,verifyEmailOtp:g,finalizeEmailOtp:d});constructor(t,n){this.context=t,this.relayUrl=n;let r=e(t.signingEngine.getRpId());if(!r.ok)throw Error(`wallet recovery RP ID ${r.error.message}`);this.#t=r.value}#t;targetFor(e){switch(e){case`passkey`:return{kind:e,rpId:this.#t};case`google_email_otp`:return{kind:e,googleProvider:`google`}}}async prepare(e){let t=await this.#e.prepareWithCode({context:this.context,relayUrl:this.relayUrl,recoveryCode:e.recoveryCode,target:e.target,signal:e.signal});return t.kind===`prepared`?(t.target.kind,{kind:`hosted_recovery_prepared`,recoveryOperationId:t.recoveryOperationId,walletId:t.walletId,target:t.target}):t}createPasskey(e){return this.#n({kind:`prepared`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,target:e.target})}async verifyGoogle(e,t){let n=await this.#e.verifyGoogle({relayUrl:this.relayUrl,operation:{kind:`prepared`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,target:e.target},idToken:t});return n.kind===`google_verified`?{kind:`hosted_recovery_google_verified`,recoveryOperationId:n.recoveryOperationId,walletId:n.walletId,target:n.target,challengeId:n.challengeId,delivery:n.delivery,expiresAtMs:n.expiresAtMs}:n}async verifyEmailOtp(e,t){let n=await this.#e.verifyEmailOtp({context:this.context,operation:{kind:`google_verified`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,target:e.target,challengeId:e.challengeId,delivery:e.delivery,expiresAtMs:e.expiresAtMs},challengeId:t.challengeId,otpCode:t.otpCode});return n.kind===`email_otp_verified`?{kind:`hosted_recovery_email_otp_verified`,recoveryOperationId:n.recoveryOperationId,walletId:n.walletId,target:n.target,challengeId:n.challengeId}:n}async finalize(e){return e.kind===`hosted_recovery_credential_created`?await this.#e.finalize({context:this.context,operation:{kind:`credential_created`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,target:e.target}}):await this.#e.finalize({context:this.context,operation:{kind:`email_otp_verified`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,target:e.target,challengeId:e.challengeId}})}async cancel(e){this.#e.cancel(e.recoveryOperationId)}async#n(e){let t=await this.#e.createPasskey({context:this.context,operation:e});return t.kind===`credential_created`?this.#r(t):t}#r(e){return{kind:`hosted_recovery_credential_created`,recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,target:e.target}}};function q(e){return new K(e.context,e.relayUrl)}export{q as createHostedRecoveryPort};
|