@seams/wallet 0.13.1 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/.build-inputs.sha256 +1 -1
- package/dist/esm/SeamsWeb/SeamsWeb.js +1 -0
- package/dist/esm/SeamsWeb/walletIframe/client/router.js +9 -0
- package/dist/esm/SeamsWeb/walletIframe/coordinator.js +8 -0
- package/dist/esm/SeamsWeb/walletIframe/shared/messages.js +1 -1
- package/dist/esm/core/indexedDB/index.js +2 -1
- package/dist/esm/core/indexedDB/schemaNames.js +1 -2
- package/dist/esm/core/indexedDB/seamsWalletDB/schema.js +2 -1
- package/dist/esm/core/indexedDB/walletDbName.js +6 -0
- package/dist/esm/sdk/{ConfirmationDrawer-Frj3uEee.js → ConfirmationDrawer-BFzQjd1P.js} +1 -1
- package/dist/esm/sdk/{NonceCoordinator-S5ZbrkDp.js → NonceCoordinator-CDGnEgfI.js} +1 -1
- package/dist/{public/sdk/accountLifecycle-HEUmDLus.js → esm/sdk/accountLifecycle-CBOkr0vU.js} +1 -1
- package/dist/esm/sdk/{adapters-CGvNLOfZ.js → adapters-DsAaBNNY.js} +2 -2
- package/dist/esm/sdk/{challengeDelivery-5lIu9spR.js → challengeDelivery-CATQ4u6P.js} +1 -1
- package/dist/{public/sdk/clientSessionPersistenceState-DRdve9rC.js → esm/sdk/clientSessionPersistenceState-CBylL1Ul.js} +1 -1
- package/dist/esm/sdk/{commitQueue-qjvY_zWn.js → commitQueue-DYEgzoLA.js} +1 -1
- package/dist/esm/sdk/{display-DTbGoX4e.js → display-DsfJkAra.js} +1 -1
- package/dist/esm/sdk/{ecdsaCapabilityManifest-ChszYCC0.js → ecdsaCapabilityManifest-DX6TflEz.js} +1 -1
- package/dist/{public/sdk/ecdsaDerivationClientWasm-CpH-b3jx.js → esm/sdk/ecdsaDerivationClientWasm-CpjnN4aK.js} +1 -1
- package/dist/esm/sdk/ecdsaDerivationExport-CuNIssOt.js +1 -0
- package/dist/esm/sdk/{ecdsaWalletRecords-Di_NUxD_.js → ecdsaWalletRecords-CHfrYvKr.js} +1 -1
- package/dist/{public/sdk/emailOtpEcdsaDerivationIdentity-p0C1CQva.js → esm/sdk/emailOtpEcdsaDerivationIdentity-Bik0N8v9.js} +1 -1
- package/dist/esm/sdk/{enrichDisplayModelWithAbi-DZIhvE-x.js → enrichDisplayModelWithAbi-DSj4NAlY.js} +1 -1
- package/dist/esm/sdk/{export-viewer-host-DUMwD6zP.js → export-viewer-host-CV-lSsQF.js} +1 -1
- package/dist/esm/sdk/exportKeypairOperation-Bql0I-8U.js +1 -0
- package/dist/esm/sdk/host-D3Q_NsmE.js +1 -0
- package/dist/esm/sdk/{lanes-Ck81oEGv.js → lanes-5kcTFbPx.js} +1 -1
- package/dist/esm/sdk/{localOnly-CUVRoMy2.js → localOnly-C5mSXb_D.js} +1 -1
- package/dist/{public/sdk/mountExportPrivateKeySurface-B4gH1Sel.js → esm/sdk/mountExportPrivateKeySurface-CatAhYoG.js} +1 -1
- package/dist/{public/sdk/mountRecoveryCodeBackupSurface-D1G-iCPI.js → esm/sdk/mountRecoveryCodeBackupSurface-DlEb3uD7.js} +1 -1
- package/dist/esm/sdk/nearEd25519YaoMaterialActivation-Bo3IOTS-.js +1 -0
- package/dist/esm/sdk/{nearEd25519YaoSigningPreparation-Eiq_ikXk.js → nearEd25519YaoSigningPreparation-RIfkYN0d.js} +1 -1
- package/dist/esm/sdk/{nonceLaneKeys-Do5Vs-De.js → nonceLaneKeys-BCYfl1wv.js} +1 -1
- package/dist/esm/sdk/{normalization-DJPmcXTg.js → normalization-n503J-BI.js} +1 -1
- package/dist/{public/sdk/passkey-custody-Cd_yyoRa.js → esm/sdk/passkey-custody-DpTM-eNJ.js} +1 -1
- package/dist/esm/sdk/{pendingWalletRecoveryCodeBackup-DMg5U0Fk.js → pendingWalletRecoveryCodeBackup-C60sZMj5.js} +1 -1
- package/dist/{public/sdk/presignaturePool-Bkk6bLFB.js → esm/sdk/presignaturePool-DX_hqZ6Z.js} +1 -1
- package/dist/esm/sdk/recovery-entrypoint-BULjaFBM.js +1 -0
- package/dist/esm/sdk/{registration-Drtkzrlc.js → registration-CyF7nOXs.js} +1 -1
- package/dist/esm/sdk/registration-DEGZR8kA.js +1 -0
- package/dist/esm/sdk/{registrationAccounts-DP-32yCK.js → registrationAccounts-BQMUusdD.js} +1 -1
- package/dist/{public/sdk/registrationIntent-BHU5k2Q-.js → esm/sdk/registrationIntent-090Zj7Iu.js} +1 -1
- package/dist/{public/sdk/registrationSignerPlan-dY9Rp0m_.js → esm/sdk/registrationSignerPlan-CPzHavPM.js} +1 -1
- package/dist/esm/sdk/{requireStepUpAuth-FqZSU021.js → requireStepUpAuth-BCY5ZStI.js} +1 -1
- package/dist/esm/sdk/routerAbNormalSigning-C4P2tDU-.js +1 -0
- package/dist/esm/sdk/runtime-auth-DDOPe7LO.js +1 -0
- package/dist/esm/sdk/runtime-device-link-Bkt5AJAI.js +1 -0
- package/dist/esm/sdk/runtime-ecdsa-tempo-DUOkCNFT.js +1 -0
- package/dist/esm/sdk/runtime-email-otp-Bsv55Gin.js +1 -0
- package/dist/esm/sdk/runtime-export-D7QKXvdg.js +1 -0
- package/dist/esm/sdk/runtime-near-Bl7bBU2g.js +1 -0
- package/dist/esm/sdk/runtime-preferences-C2Rqmp7q.js +1 -0
- package/dist/esm/sdk/runtime-recovery-BMY7AkJq.js +1 -0
- package/dist/esm/sdk/runtime-recovery-codes-GOytzExh.js +1 -0
- package/dist/esm/sdk/secp256k1-CL273JMp.js +1 -0
- package/dist/esm/sdk/sessionObservationRevision-CnEOLDbl.js +1 -0
- package/dist/esm/sdk/shared-CNT5EU_h.js +6 -0
- package/dist/{public/sdk/signEvmFamily-ttVfV0qm.js → esm/sdk/signEvmFamily-BE0a14MT.js} +1 -1
- package/dist/esm/sdk/{signEvmFamilyWithUiConfirmForTempo-Bo25SwuV.js → signEvmFamilyWithUiConfirmForTempo-DGWmm9n7.js} +1 -1
- package/dist/esm/sdk/{signEvmWithUiConfirm-CFcqJRj3.js → signEvmWithUiConfirm-BRmdLgmm.js} +1 -1
- package/dist/esm/sdk/signNear-XGZBxc_g.js +1 -0
- package/dist/esm/sdk/signer-worker-DlK58rEA.js +1 -0
- package/dist/{public/sdk/signingFlow-DZvV4AgG.js → esm/sdk/signingFlow-VAnM8L5C.js} +1 -1
- package/dist/esm/sdk/{signingQueue-2pr7lAUS.js → signingQueue-D_Ebmzcn.js} +1 -1
- package/dist/esm/sdk/singletons-BXhnsqeY.js +1 -0
- package/dist/esm/sdk/{thresholdEcdsa-D-QMyevW.js → thresholdEcdsa-CneSKcRt.js} +1 -1
- package/dist/esm/sdk/{trace-QLsbYdld.js → trace-BBux0jtr.js} +1 -1
- package/dist/esm/sdk/{transaction-activity-xfeHKJoq.js → transaction-activity-Cccvec2J.js} +1 -1
- package/dist/esm/sdk/{transactionState-CGULLokO.js → transactionState-Day-1x7Y.js} +1 -1
- package/dist/esm/sdk/{types-WGrFMQSw.js → types-hKLqDUhR.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-LMtGiEL3.js → wallet-recovery-Bfhfk52N.js} +1 -1
- package/dist/esm/sdk/{walletAuthMethodRecord-CnBw27ED.js → walletAuthMethodRecord-LniOQQmj.js} +1 -1
- package/dist/{public/sdk/walletAuthority-BWvfaKIX.js → esm/sdk/walletAuthority-CAiGuWW2.js} +1 -1
- package/dist/esm/sdk/walletCustodyEcdsaContinuity-B4fTDL10.js +1 -0
- package/dist/esm/sdk/{sessionPolicy-CBTZQe1n.js → walletDbName-DtRewci9.js} +1 -1
- package/dist/{public/sdk/walletOwnershipGeneration-CAycHv-H.js → esm/sdk/walletOwnershipGeneration-B6HyR2rE.js} +1 -1
- package/dist/esm/sdk/walletRecoveryCommit-C6HF84_U.js +1 -0
- package/dist/{public/sdk/walletSessionAuthorizationStore-BiKGIBWQ.js → esm/sdk/walletSessionAuthorizationStore-DmYe-cDR.js} +1 -1
- package/dist/esm/sdk/warmSessionHydration-CsQpQVuy.js +1 -0
- package/dist/public/headers.manifest.json +1 -1
- package/dist/public/sdk/{ConfirmationDrawer-Frj3uEee.js → ConfirmationDrawer-BFzQjd1P.js} +1 -1
- package/dist/public/sdk/{NonceCoordinator-S5ZbrkDp.js → NonceCoordinator-CDGnEgfI.js} +1 -1
- package/dist/{esm/sdk/accountLifecycle-HEUmDLus.js → public/sdk/accountLifecycle-CBOkr0vU.js} +1 -1
- package/dist/public/sdk/{adapters-CGvNLOfZ.js → adapters-DsAaBNNY.js} +2 -2
- package/dist/public/sdk/{challengeDelivery-5lIu9spR.js → challengeDelivery-CATQ4u6P.js} +1 -1
- package/dist/{esm/sdk/clientSessionPersistenceState-DRdve9rC.js → public/sdk/clientSessionPersistenceState-CBylL1Ul.js} +1 -1
- package/dist/public/sdk/{commitQueue-qjvY_zWn.js → commitQueue-DYEgzoLA.js} +1 -1
- package/dist/public/sdk/{display-DTbGoX4e.js → display-DsfJkAra.js} +1 -1
- package/dist/public/sdk/{ecdsaCapabilityManifest-ChszYCC0.js → ecdsaCapabilityManifest-DX6TflEz.js} +1 -1
- package/dist/{esm/sdk/ecdsaDerivationClientWasm-CpH-b3jx.js → public/sdk/ecdsaDerivationClientWasm-CpjnN4aK.js} +1 -1
- package/dist/public/sdk/ecdsaDerivationExport-CuNIssOt.js +1 -0
- package/dist/public/sdk/{ecdsaWalletRecords-Di_NUxD_.js → ecdsaWalletRecords-CHfrYvKr.js} +1 -1
- package/dist/{esm/sdk/emailOtpEcdsaDerivationIdentity-p0C1CQva.js → public/sdk/emailOtpEcdsaDerivationIdentity-Bik0N8v9.js} +1 -1
- package/dist/public/sdk/{enrichDisplayModelWithAbi-DZIhvE-x.js → enrichDisplayModelWithAbi-DSj4NAlY.js} +1 -1
- package/dist/public/sdk/{export-viewer-host-DUMwD6zP.js → export-viewer-host-CV-lSsQF.js} +1 -1
- package/dist/public/sdk/exportKeypairOperation-Bql0I-8U.js +1 -0
- package/dist/public/sdk/host-D3Q_NsmE.js +1 -0
- package/dist/public/sdk/{lanes-Ck81oEGv.js → lanes-5kcTFbPx.js} +1 -1
- package/dist/public/sdk/{localOnly-CUVRoMy2.js → localOnly-C5mSXb_D.js} +1 -1
- package/dist/{esm/sdk/mountExportPrivateKeySurface-B4gH1Sel.js → public/sdk/mountExportPrivateKeySurface-CatAhYoG.js} +1 -1
- package/dist/{esm/sdk/mountRecoveryCodeBackupSurface-D1G-iCPI.js → public/sdk/mountRecoveryCodeBackupSurface-DlEb3uD7.js} +1 -1
- package/dist/public/sdk/nearEd25519YaoMaterialActivation-Bo3IOTS-.js +1 -0
- package/dist/public/sdk/{nearEd25519YaoSigningPreparation-Eiq_ikXk.js → nearEd25519YaoSigningPreparation-RIfkYN0d.js} +1 -1
- package/dist/public/sdk/{nonceLaneKeys-Do5Vs-De.js → nonceLaneKeys-BCYfl1wv.js} +1 -1
- package/dist/public/sdk/{normalization-DJPmcXTg.js → normalization-n503J-BI.js} +1 -1
- package/dist/{esm/sdk/passkey-custody-Cd_yyoRa.js → public/sdk/passkey-custody-DpTM-eNJ.js} +1 -1
- package/dist/public/sdk/{pendingWalletRecoveryCodeBackup-DMg5U0Fk.js → pendingWalletRecoveryCodeBackup-C60sZMj5.js} +1 -1
- package/dist/{esm/sdk/presignaturePool-Bkk6bLFB.js → public/sdk/presignaturePool-DX_hqZ6Z.js} +1 -1
- package/dist/public/sdk/recovery-entrypoint-BULjaFBM.js +1 -0
- package/dist/public/sdk/{registration-Drtkzrlc.js → registration-CyF7nOXs.js} +1 -1
- package/dist/public/sdk/registration-DEGZR8kA.js +1 -0
- package/dist/public/sdk/{registrationAccounts-DP-32yCK.js → registrationAccounts-BQMUusdD.js} +1 -1
- package/dist/{esm/sdk/registrationIntent-BHU5k2Q-.js → public/sdk/registrationIntent-090Zj7Iu.js} +1 -1
- package/dist/{esm/sdk/registrationSignerPlan-dY9Rp0m_.js → public/sdk/registrationSignerPlan-CPzHavPM.js} +1 -1
- package/dist/public/sdk/{requireStepUpAuth-FqZSU021.js → requireStepUpAuth-BCY5ZStI.js} +1 -1
- package/dist/public/sdk/routerAbNormalSigning-C4P2tDU-.js +1 -0
- package/dist/public/sdk/runtime-auth-DDOPe7LO.js +1 -0
- package/dist/public/sdk/runtime-device-link-Bkt5AJAI.js +1 -0
- package/dist/public/sdk/runtime-ecdsa-tempo-DUOkCNFT.js +1 -0
- package/dist/public/sdk/runtime-email-otp-Bsv55Gin.js +1 -0
- package/dist/public/sdk/runtime-export-D7QKXvdg.js +1 -0
- package/dist/public/sdk/runtime-near-Bl7bBU2g.js +1 -0
- package/dist/public/sdk/runtime-preferences-C2Rqmp7q.js +1 -0
- package/dist/public/sdk/runtime-recovery-BMY7AkJq.js +1 -0
- package/dist/public/sdk/runtime-recovery-codes-GOytzExh.js +1 -0
- package/dist/public/sdk/secp256k1-CL273JMp.js +1 -0
- package/dist/public/sdk/sessionObservationRevision-CnEOLDbl.js +1 -0
- package/dist/public/sdk/shared-CNT5EU_h.js +6 -0
- package/dist/{esm/sdk/signEvmFamily-ttVfV0qm.js → public/sdk/signEvmFamily-BE0a14MT.js} +1 -1
- package/dist/public/sdk/{signEvmFamilyWithUiConfirmForTempo-Bo25SwuV.js → signEvmFamilyWithUiConfirmForTempo-DGWmm9n7.js} +1 -1
- package/dist/public/sdk/{signEvmWithUiConfirm-CFcqJRj3.js → signEvmWithUiConfirm-BRmdLgmm.js} +1 -1
- package/dist/public/sdk/signNear-XGZBxc_g.js +1 -0
- package/dist/public/sdk/signer-worker-DlK58rEA.js +1 -0
- package/dist/{esm/sdk/signingFlow-DZvV4AgG.js → public/sdk/signingFlow-VAnM8L5C.js} +1 -1
- package/dist/public/sdk/{signingQueue-2pr7lAUS.js → signingQueue-D_Ebmzcn.js} +1 -1
- package/dist/public/sdk/singletons-BXhnsqeY.js +1 -0
- package/dist/public/sdk/{thresholdEcdsa-D-QMyevW.js → thresholdEcdsa-CneSKcRt.js} +1 -1
- package/dist/public/sdk/{trace-QLsbYdld.js → trace-BBux0jtr.js} +1 -1
- package/dist/public/sdk/{transaction-activity-xfeHKJoq.js → transaction-activity-Cccvec2J.js} +1 -1
- package/dist/public/sdk/{transactionState-CGULLokO.js → transactionState-Day-1x7Y.js} +1 -1
- package/dist/public/sdk/{types-WGrFMQSw.js → types-hKLqDUhR.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-LMtGiEL3.js → wallet-recovery-Bfhfk52N.js} +1 -1
- package/dist/public/sdk/{walletAuthMethodRecord-CnBw27ED.js → walletAuthMethodRecord-LniOQQmj.js} +1 -1
- package/dist/{esm/sdk/walletAuthority-BWvfaKIX.js → public/sdk/walletAuthority-CAiGuWW2.js} +1 -1
- package/dist/public/sdk/walletCustodyEcdsaContinuity-B4fTDL10.js +1 -0
- package/dist/public/sdk/{sessionPolicy-CBTZQe1n.js → walletDbName-DtRewci9.js} +1 -1
- package/dist/{esm/sdk/walletOwnershipGeneration-CAycHv-H.js → public/sdk/walletOwnershipGeneration-B6HyR2rE.js} +1 -1
- package/dist/public/sdk/walletRecoveryCommit-C6HF84_U.js +1 -0
- package/dist/{esm/sdk/walletSessionAuthorizationStore-BiKGIBWQ.js → public/sdk/walletSessionAuthorizationStore-DmYe-cDR.js} +1 -1
- package/dist/public/sdk/warmSessionHydration-CsQpQVuy.js +1 -0
- package/dist/public/sdk/workers/ecdsa-derivation-client.worker.js +3 -1
- package/dist/public/wallet-assets.manifest.json +233 -209
- package/dist/public/wallet-service/index.html +4 -4
- package/dist/types/wallet/src/SeamsWeb/publicApi/types.d.ts +7 -0
- package/dist/types/wallet/src/SeamsWeb/walletIframe/client/router.d.ts +3 -0
- package/dist/types/wallet/src/SeamsWeb/walletIframe/coordinator.d.ts +1 -0
- package/dist/types/wallet/src/SeamsWeb/walletIframe/host/emptyWalletStoreReads.d.ts +19 -0
- package/dist/types/wallet/src/SeamsWeb/walletIframe/host/requestRouter.d.ts +1 -1
- package/dist/types/wallet/src/SeamsWeb/walletIframe/host/runtimeLoader.d.ts +5 -0
- package/dist/types/wallet/src/SeamsWeb/walletIframe/host/sessionObservationRevision.d.ts +7 -0
- package/dist/types/wallet/src/SeamsWeb/walletIframe/shared/messages.d.ts +3 -3
- package/dist/types/wallet/src/core/indexedDB/index.d.ts +2 -1
- package/dist/types/wallet/src/core/indexedDB/schemaNames.d.ts +0 -1
- package/dist/types/wallet/src/core/indexedDB/seamsWalletDB/manager.d.ts +2 -1
- package/dist/types/wallet/src/core/indexedDB/walletDbName.d.ts +2 -0
- package/dist/workers/ecdsa-derivation-client.worker.js +3 -1
- package/package.json +1 -1
- package/dist/esm/sdk/ecdsaDerivationExport-C1cE5m0t.js +0 -1
- package/dist/esm/sdk/exportKeypairOperation-BHXMSA3v.js +0 -1
- package/dist/esm/sdk/host-BAeJh9rB.js +0 -1
- package/dist/esm/sdk/messages-DgJlG9NU.js +0 -1
- package/dist/esm/sdk/nearEd25519YaoMaterialActivation-DMGPKrn8.js +0 -1
- package/dist/esm/sdk/recovery-entrypoint-EHY_b7Z-.js +0 -1
- package/dist/esm/sdk/registration-CQxxUt5s.js +0 -1
- package/dist/esm/sdk/routerAbNormalSigning-B35zb-P-.js +0 -1
- package/dist/esm/sdk/runtime-auth-D7VqiZeg.js +0 -1
- package/dist/esm/sdk/runtime-device-link-BKc_MD5V.js +0 -1
- package/dist/esm/sdk/runtime-ecdsa-tempo-DC51NDrh.js +0 -1
- package/dist/esm/sdk/runtime-email-otp-C-wopKFf.js +0 -1
- package/dist/esm/sdk/runtime-export-BtGy8BKi.js +0 -1
- package/dist/esm/sdk/runtime-near-nq8pgRAl.js +0 -1
- package/dist/esm/sdk/runtime-preferences-778ZfMmT.js +0 -1
- package/dist/esm/sdk/runtime-recovery-B-JsRiN0.js +0 -1
- package/dist/esm/sdk/runtime-recovery-codes-rLR4Guy4.js +0 -1
- package/dist/esm/sdk/secp256k1-CYQS0rj-.js +0 -1
- package/dist/esm/sdk/shared-B6BCLs8L.js +0 -6
- package/dist/esm/sdk/signNear-bcWIHxEY.js +0 -1
- package/dist/esm/sdk/singletons-8UH3gOnZ.js +0 -1
- package/dist/esm/sdk/walletCustodyEcdsaContinuity-D-gYxv6e.js +0 -1
- package/dist/esm/sdk/walletRecoveryCommit-BYRC_2li.js +0 -1
- package/dist/esm/sdk/warmSessionHydration-B7-kCnJh.js +0 -1
- package/dist/public/sdk/ecdsaDerivationExport-C1cE5m0t.js +0 -1
- package/dist/public/sdk/exportKeypairOperation-BHXMSA3v.js +0 -1
- package/dist/public/sdk/host-BAeJh9rB.js +0 -1
- package/dist/public/sdk/messages-DgJlG9NU.js +0 -1
- package/dist/public/sdk/nearEd25519YaoMaterialActivation-DMGPKrn8.js +0 -1
- package/dist/public/sdk/recovery-entrypoint-EHY_b7Z-.js +0 -1
- package/dist/public/sdk/registration-CQxxUt5s.js +0 -1
- package/dist/public/sdk/routerAbNormalSigning-B35zb-P-.js +0 -1
- package/dist/public/sdk/runtime-auth-D7VqiZeg.js +0 -1
- package/dist/public/sdk/runtime-device-link-BKc_MD5V.js +0 -1
- package/dist/public/sdk/runtime-ecdsa-tempo-DC51NDrh.js +0 -1
- package/dist/public/sdk/runtime-email-otp-C-wopKFf.js +0 -1
- package/dist/public/sdk/runtime-export-BtGy8BKi.js +0 -1
- package/dist/public/sdk/runtime-near-nq8pgRAl.js +0 -1
- package/dist/public/sdk/runtime-preferences-778ZfMmT.js +0 -1
- package/dist/public/sdk/runtime-recovery-B-JsRiN0.js +0 -1
- package/dist/public/sdk/runtime-recovery-codes-rLR4Guy4.js +0 -1
- package/dist/public/sdk/secp256k1-CYQS0rj-.js +0 -1
- package/dist/public/sdk/shared-B6BCLs8L.js +0 -6
- package/dist/public/sdk/signNear-bcWIHxEY.js +0 -1
- package/dist/public/sdk/singletons-8UH3gOnZ.js +0 -1
- package/dist/public/sdk/walletCustodyEcdsaContinuity-D-gYxv6e.js +0 -1
- package/dist/public/sdk/walletRecoveryCommit-BYRC_2li.js +0 -1
- package/dist/public/sdk/warmSessionHydration-B7-kCnJh.js +0 -1
- /package/dist/esm/sdk/{accountIds-BzZs7YoX.js → accountIds-Cpvlkvbe.js} +0 -0
- /package/dist/esm/sdk/{appearance-DITtYj-z.js → appearance-4DmzKUWf.js} +0 -0
- /package/dist/esm/sdk/{authenticatorOptions-C9aCKgeF.js → authenticatorOptions-2_XK8aXv.js} +0 -0
- /package/dist/esm/sdk/{browser-DkCRXFkk.js → browser-n3IVr7qu.js} +0 -0
- /package/dist/esm/sdk/{digestEncoding-CkUc5vtR.js → digestEncoding-BX3VW9eF.js} +0 -0
- /package/dist/esm/sdk/{ecdsaChainTarget-DJBXHzbH.js → ecdsaChainTarget-Bfatk3oP.js} +0 -0
- /package/dist/esm/sdk/{helpers-BnkILY2_.js → helpers-B9fpZNAP.js} +0 -0
- /package/dist/esm/sdk/{intentDigest-DJBrMyLJ.js → intentDigest-P_-CM7lS.js} +0 -0
- /package/dist/esm/sdk/{jsonRpc-YKL5n8VL.js → jsonRpc-BVDv1wfm.js} +0 -0
- /package/dist/esm/sdk/{jsxRuntime.module-C8JOKu_4.js → jsxRuntime.module-DKsgiFjd.js} +0 -0
- /package/dist/esm/sdk/{keccak-BArcwgbj.js → keccak-mS0Mejjx.js} +0 -0
- /package/dist/esm/sdk/{normalization-CeZT7ob0.js → normalization-C6fQN6mW.js} +0 -0
- /package/dist/esm/sdk/{operationFingerprint-CUrnoh-M.js → operationFingerprint-BHNYryLY.js} +0 -0
- /package/dist/esm/sdk/{presignatures-DZm0d6Wy.js → presignatures-K-yuzOE0.js} +0 -0
- /package/dist/esm/sdk/{prfCache-DCkuB8Lu.js → prfCache-DJ93rtDv.js} +0 -0
- /package/dist/esm/sdk/{profileAccountProjection-B3LXAUmo.js → profileAccountProjection-BNVJLOt2.js} +0 -0
- /package/dist/esm/sdk/{promptText-B8RprJhO.js → promptText-CnyrLxgj.js} +0 -0
- /package/dist/esm/sdk/{registrationAuthMethodInput-BBCeWDmw.js → registrationAuthMethodInput-RbSR7R1G.js} +0 -0
- /package/dist/esm/sdk/{registrationIds-ByuReLUc.js → registrationIds-BaK3jUS6.js} +0 -0
- /package/dist/esm/sdk/{sdkSentEvents-Dl8fOL50.js → sdkSentEvents-D4KtK7_I.js} +0 -0
- /package/dist/esm/sdk/{signatureUses-8c8Ku_Fw.js → signatureUses-BKAoDbQd.js} +0 -0
- /package/dist/esm/sdk/{signerDomain-DqLCvI-D.js → signerDomain-Dp7BhfmZ.js} +0 -0
- /package/dist/esm/sdk/{signerSlot-B4Eq8Oe2.js → signerSlot-FJAGOhmg.js} +0 -0
- /package/dist/esm/sdk/{types-DhtByIcQ.js → types-Buoe6179.js} +0 -0
- /package/dist/esm/sdk/{walletRecoveryRotate-D_1a8Agl.js → walletRecoveryRotate-BN3H8byw.js} +0 -0
- /package/dist/esm/sdk/{walletSessionAuthorizationStatus-BLyzJbU8.js → walletSessionAuthorizationStatus-BL7j2TeM.js} +0 -0
- /package/dist/esm/sdk/{webauthnP256-DZCusNY9.js → webauthnP256-BwgxtG5N.js} +0 -0
- /package/dist/esm/sdk/{webauthnPromptCoordinator-CS4Xc_jZ.js → webauthnPromptCoordinator-CwJeKiYq.js} +0 -0
- /package/dist/public/sdk/{accountIds-BzZs7YoX.js → accountIds-Cpvlkvbe.js} +0 -0
- /package/dist/public/sdk/{appearance-DITtYj-z.js → appearance-4DmzKUWf.js} +0 -0
- /package/dist/public/sdk/{authenticatorOptions-C9aCKgeF.js → authenticatorOptions-2_XK8aXv.js} +0 -0
- /package/dist/public/sdk/{browser-DkCRXFkk.js → browser-n3IVr7qu.js} +0 -0
- /package/dist/public/sdk/{digestEncoding-CkUc5vtR.js → digestEncoding-BX3VW9eF.js} +0 -0
- /package/dist/public/sdk/{ecdsaChainTarget-DJBXHzbH.js → ecdsaChainTarget-Bfatk3oP.js} +0 -0
- /package/dist/public/sdk/{helpers-BnkILY2_.js → helpers-B9fpZNAP.js} +0 -0
- /package/dist/public/sdk/{intentDigest-DJBrMyLJ.js → intentDigest-P_-CM7lS.js} +0 -0
- /package/dist/public/sdk/{jsonRpc-YKL5n8VL.js → jsonRpc-BVDv1wfm.js} +0 -0
- /package/dist/public/sdk/{jsxRuntime.module-C8JOKu_4.js → jsxRuntime.module-DKsgiFjd.js} +0 -0
- /package/dist/public/sdk/{keccak-BArcwgbj.js → keccak-mS0Mejjx.js} +0 -0
- /package/dist/public/sdk/{normalization-CeZT7ob0.js → normalization-C6fQN6mW.js} +0 -0
- /package/dist/public/sdk/{operationFingerprint-CUrnoh-M.js → operationFingerprint-BHNYryLY.js} +0 -0
- /package/dist/public/sdk/{presignatures-DZm0d6Wy.js → presignatures-K-yuzOE0.js} +0 -0
- /package/dist/public/sdk/{prfCache-DCkuB8Lu.js → prfCache-DJ93rtDv.js} +0 -0
- /package/dist/public/sdk/{profileAccountProjection-B3LXAUmo.js → profileAccountProjection-BNVJLOt2.js} +0 -0
- /package/dist/public/sdk/{promptText-B8RprJhO.js → promptText-CnyrLxgj.js} +0 -0
- /package/dist/public/sdk/{registrationAuthMethodInput-BBCeWDmw.js → registrationAuthMethodInput-RbSR7R1G.js} +0 -0
- /package/dist/public/sdk/{registrationIds-ByuReLUc.js → registrationIds-BaK3jUS6.js} +0 -0
- /package/dist/public/sdk/{sdkSentEvents-Dl8fOL50.js → sdkSentEvents-D4KtK7_I.js} +0 -0
- /package/dist/public/sdk/{signatureUses-8c8Ku_Fw.js → signatureUses-BKAoDbQd.js} +0 -0
- /package/dist/public/sdk/{signerDomain-DqLCvI-D.js → signerDomain-Dp7BhfmZ.js} +0 -0
- /package/dist/public/sdk/{signerSlot-B4Eq8Oe2.js → signerSlot-FJAGOhmg.js} +0 -0
- /package/dist/public/sdk/{types-DhtByIcQ.js → types-Buoe6179.js} +0 -0
- /package/dist/public/sdk/{walletRecoveryRotate-D_1a8Agl.js → walletRecoveryRotate-BN3H8byw.js} +0 -0
- /package/dist/public/sdk/{walletSessionAuthorizationStatus-BLyzJbU8.js → walletSessionAuthorizationStatus-BL7j2TeM.js} +0 -0
- /package/dist/public/sdk/{webauthnP256-DZCusNY9.js → webauthnP256-BwgxtG5N.js} +0 -0
- /package/dist/public/sdk/{webauthnPromptCoordinator-CS4Xc_jZ.js → webauthnPromptCoordinator-CwJeKiYq.js} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{A as e,D as t,M as n,O as r,S as i,T as a,j as o,o as s,s as c}from"./domainIds-BzkGsRqO.js";import{E as l,c as u,d,k as f}from"./chains-C_X_fNuS.js";import{D as p,_ as m,c as h,i as g,j as _,n as v,o as y,r as b,s as x,t as S,y as C}from"./primitives-CqrjmIAH.js";import{i as w,r as T}from"./base64-DW79QA0h.js";import{o as ee}from"./sessionPolicy-CBTZQe1n.js";import{n as te,t as ne}from"./signingSessionSeal-DX41aXUL.js";import{E,O as D,k as O}from"./activeWalletSession-WdZkhtBB.js";import{l as k}from"./capabilityKinds-N8xo_IEh.js";import{d as re,t as A}from"./accountIds-BzZs7YoX.js";import{M as ie,h as ae,m as oe}from"./accountLifecycle-HEUmDLus.js";import{m as se}from"./walletAuthority-BWvfaKIX.js";import{Jt as ce,Kt as le,Nt as ue,Qt as de,Wt as fe,Xt as pe,Yt as me,en as he,q as ge,qt as _e,tn as ve,tt as ye,xt as be}from"./emailOtpEcdsaDerivationIdentity-p0C1CQva.js";import{n as xe}from"./challengeDelivery-5lIu9spR.js";import{l as Se}from"./digestEncoding-CkUc5vtR.js";import{i as Ce}from"./walletAuthMethodRecord-CnBw27ED.js";import{d as j}from"./passkey-custody-Cd_yyoRa.js";import{C as we}from"./ecdsaCapabilityManifest-ChszYCC0.js";import{E as Te,_ as M,r as Ee,u as N}from"./walletCustodyEcdsaContinuity-D-gYxv6e.js";import{a as De,f as P,l as Oe,n as F,t as ke,u as I}from"./wallet-recovery-LMtGiEL3.js";import{o as Ae}from"./helpers-BnkILY2_.js";function je(e){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`wallet recovery target must be an object`);let t=e,r=Object.keys(t);switch(t.kind){case`passkey`:{if(r.length!==2||!r.includes(`rpId`))throw Error(`Passkey recovery target fields are invalid`);let e=n(t.rpId);if(!e.ok)throw Error(`Passkey recovery target RP ID is invalid`);return{kind:`passkey`,rpId:e.value}}case`google_email_otp`:if(r.length!==2||!r.includes(`googleProvider`)||t.googleProvider!==`google`)throw Error(`Google Email OTP recovery target fields are invalid`);return{kind:`google_email_otp`,googleProvider:`google`};default:throw Error(`wallet recovery target kind is unsupported`)}}const Me=[`ok`,`walletId`,`target`,`recoveryOperationId`,`targetDeviceId`,`targetAuthorityId`,`targetWalletAuthMethodId`,`wrap`,`entries`,`keyManifest`,`reservationId`,`reservationExpiresAtMs`,`storeVersion`],Ne=[...Me,`registration`];function L(e,t){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`${t} must be an object`);return e}function Pe(e,t,n){let r=new Set(t),i=Object.keys(e);if(i.length!==r.size||i.some(e=>!r.has(e)))throw Error(`${n} contains unexpected fields`)}function R(e,t,n){let r=L(e,n);return Pe(r,t,n),r}function z(e,t){return Object.prototype.hasOwnProperty.call(e,t)?Reflect.get(e,t):void 0}function Fe(e){try{return L(e,`walletRecoveryPrepare response`)}catch{return null}}function Ie(e){let t=r(e.walletId);if(!t.ok)throw Error(`wallet recovery ${t.error.message}`);return JSON.stringify({walletId:String(t.value),wrap:e.prepared.wrap,entry:e.prepared.entries[0]})}async function Le(e){let t=await Re(e);return t.ok?await ze({response:t.response,target:e.target,reservationId:e.reservationId}):{kind:t.kind}}async function Re(e){let t=`${_(e.relayUrl)}/wallets/recovery/prepare`,n=e.fetchImpl||fetch;try{return{ok:!0,response:await n(t,p({body:{recoveryCodeB64u:e.recoveryCodeB64u,reservationId:e.reservationId,target:e.target}}))}}catch{return{ok:!1,kind:`transport_uncertain`}}}async function ze(n){let i=n.response,o=Fe(await i.json().catch(()=>({})));if(i.status===200&&o&&z(o,`ok`)===!0)try{let i=R(o,n.target.kind===`passkey`?Ne:Me,`walletRecoveryPrepare`),s=Ge()(z(i,`wrap`),`walletRecoveryPrepare.wrap`),c=Ke(z(i,`entries`)),l=r(z(i,`walletId`));if(!l.ok)throw Error(`walletRecoveryPrepare.walletId is invalid`);let u=l.value,d=je(z(i,`target`));if(!Ue(d,n.target))throw Error(`wallet recovery preparation changed the recovery target`);let f=e(z(i,`recoveryOperationId`)),p=k(z(i,`targetDeviceId`)),m=t(z(i,`targetAuthorityId`)),g=a(z(i,`targetWalletAuthMethodId`));if(!f.ok||!p.ok||!m.ok||!g.ok)throw Error(`wallet recovery preparation target identity is invalid`);let _=qe(z(i,`keyManifest`),u),v=P(z(i,`reservationId`)),y=h(z(i,`reservationExpiresAtMs`),`walletRecoveryPrepare.reservationExpiresAtMs`),b=B(z(i,`storeVersion`),`storeVersion`);if(v!==n.reservationId)throw Error(`wallet recovery preparation changed the reservation identity`);let x={kind:`prepared`,walletId:u,recoveryOperationId:f.value,targetDeviceId:p.value,targetAuthorityId:m.value,targetWalletAuthMethodId:g.value,wrap:s,entries:c,keyManifest:_,reservationId:v,reservationExpiresAtMs:y,storeVersion:b};switch(d.kind){case`passkey`:{let e=Be(String(u),d.rpId)(z(i,`registration`),`registration`);if(e.walletAuthMethodId!==g.value)throw Error(`wallet recovery registration changed the target auth method`);return{...x,target:d,registration:e}}case`google_email_otp`:if(Object.prototype.hasOwnProperty.call(i,`registration`))throw Error(`Google Email OTP recovery cannot carry passkey registration`);return{...x,target:d};default:return We(d)}}catch{return{kind:`transport_uncertain`}}return i.status===409?{kind:`retryable_conflict`}:i.status===401&&o&&z(o,`code`)===`recovery_code_used`?{kind:`consumed`}:i.status===401||i.status===400?{kind:`refused`}:{kind:`transport_uncertain`}}function Be(e,t){let r=w(new TextEncoder().encode(e)),i=D({type:E(`public-key`),id:(e,t)=>{let n=O(o)(e,t);return at(n,t),n}});return D({kind:E(`webauthn_recovery_registration_v1`),challengeId:B,challengeB64u:(e,t)=>it(e,32,t),replacementId:B,walletAuthMethodId:O(a),rpId:O(n),user:D({idB64u:at,name:B,displayName:B},(t,n)=>{if(t.idB64u!==r||t.name!==e||t.displayName!==e)throw Error(`${n} is bound to another wallet`)}),pubKeyCredParams:(e,t)=>{if(!Array.isArray(e)||e.length!==2)throw Error(`${t} is invalid`);return[Ve(-7)(e[0],`${t}[0]`),Ve(-257)(e[1],`${t}[1]`)]},authenticatorSelection:D({residentKey:E(`required`),userVerification:E(`preferred`)}),timeoutMs:(e,t)=>{let n=Number(e);if(!Number.isSafeInteger(n)||n<=0)throw Error(`${t} is invalid`);return n},attestation:E(`none`),extensions:D({prf:D({eval:D({firstB64u:He(ne),secondB64u:He(te)})})}),excludeCredentials:(e,t)=>l(e,t).map((e,n)=>i(e,`${t}[${n}]`))},(e,n)=>{if(e.rpId!==t)throw Error(`${n} changed the relying party`)})}function Ve(e){return D({type:E(`public-key`),alg:(t,n)=>{if(t!==e)throw Error(`${n} is invalid`);return e}})}function He(e){return(t,n)=>{let r=it(t,e.length,n);if(r!==w(e))throw Error(`${n} is unsupported`);return r}}function Ue(e,t){if(e.kind!==t.kind)return!1;switch(e.kind){case`passkey`:return t.kind===`passkey`&&e.rpId===t.rpId;case`google_email_otp`:return t.kind===`google_email_otp`&&e.googleProvider===t.googleProvider;default:return We(e)}}function We(e){throw Error(`unsupported wallet recovery target: ${String(e)}`)}function Ge(){return D({nonceB64u:g,wrappedManifestKekB64u:b,aadHashB64u:S})}function Ke(e){if(!Array.isArray(e)||e.length!==1)throw Error(`walletRecoveryPrepare.entries must contain exactly one custody seed`);return[De(e[0],`walletRecoveryPrepare.entries[0]`)]}function B(e,t){if(typeof e!=`string`||!e.trim())throw Error(`walletRecoveryPrepare.${t} must be a non-empty string`);return e.trim()}function qe(e,t){let n=R(e,[`version`,`walletId`,`entries`],`walletRecoveryPrepare.keyManifest`);if(z(n,`version`)!==`wallet_recovery_preparation_key_manifest_v1`)throw Error(`walletRecoveryPrepare.keyManifest version is invalid`);let r=B(z(n,`walletId`),`keyManifest.walletId`);if(r!==t)throw Error(`walletRecoveryPrepare.keyManifest changed the wallet identity`);let i=z(n,`entries`);if(!Array.isArray(i)||i.length===0)throw Error(`walletRecoveryPrepare.keyManifest must contain a key set`);let a=i.map(e=>Je(e,r));if(new Set(a.map(e=>e.keySetId)).size!==a.length)throw Error(`walletRecoveryPrepare.keyManifest contains duplicate key sets`);return{version:`wallet_recovery_preparation_key_manifest_v1`,walletId:r,entries:a}}function Je(e,t){switch(z(L(e,`walletRecoveryPrepare.keyManifest.entries[]`),`kind`)){case`near_ed25519`:{let n=R(e,[`kind`,`keySetId`,`signerId`,`nearAccountId`,`recordedKeyManifestDigestB64u`,`recoveryBasis`],`walletRecoveryPrepare.keyManifest.entries[].near_ed25519`),r=B(z(n,`signerId`),`keyManifest.entries[].signerId`),i=B(z(n,`keySetId`),`keyManifest.entries[].keySetId`),a=`near_ed25519:${r}`;if(i!==a)throw Error(`walletRecoveryPrepare NEAR key-set identity is inconsistent`);let o=B(z(n,`nearAccountId`),`keyManifest.entries[].nearAccountId`),s=Ye(z(n,`recoveryBasis`),t);return{kind:`near_ed25519`,keySetId:a,signerId:r,nearAccountId:o,recordedKeyManifestDigestB64u:S(z(n,`recordedKeyManifestDigestB64u`),`walletRecoveryPrepare.keyManifest.entries[].recordedKeyManifestDigestB64u`),recoveryBasis:s}}case`evm_family_ecdsa`:{let n=R(e,[`kind`,`keySetId`,`keyHandle`,`evmFamilySigningKeySlotId`,`recordedKeyManifestDigestB64u`,`recoveryBasis`],`walletRecoveryPrepare.keyManifest.entries[].evm_family_ecdsa`),r=B(z(n,`keyHandle`),`keyManifest.entries[].keyHandle`),i=B(z(n,`keySetId`),`keyManifest.entries[].keySetId`),a=`evm_family_ecdsa:${r}`;if(i!==a)throw Error(`walletRecoveryPrepare ECDSA key-set identity is inconsistent`);let o=Xe(z(n,`recoveryBasis`),t);return{kind:`evm_family_ecdsa`,keySetId:a,keyHandle:r,evmFamilySigningKeySlotId:Se(z(n,`evmFamilySigningKeySlotId`)),recordedKeyManifestDigestB64u:S(z(n,`recordedKeyManifestDigestB64u`),`walletRecoveryPrepare.keyManifest.entries[].recordedKeyManifestDigestB64u`),recoveryBasis:o}}default:throw Error(`walletRecoveryPrepare key-manifest entry kind is invalid`)}}function Ye(e,t){let n=R(e,[`capabilityKind`,`activeCapabilityBinding`,`scope`,`applicationBinding`,`participantIds`,`registeredPublicKey`,`runtimePolicyScope`,`activationTranscript`,`activationStateEpoch`,`signingWorkerVerifyingShare`],`walletRecoveryPrepare.keyManifest.entries[].recoveryBasis`),r=z(n,`capabilityKind`);if(r!==`registration`&&r!==`recovery`)throw Error(`walletRecoveryPrepare NEAR recovery capability kind is invalid`);let i=V(z(n,`activeCapabilityBinding`),32,`NEAR recovery active capability binding`),a=et(z(n,`scope`)),o=tt(z(n,`applicationBinding`)),s=rt(z(n,`participantIds`),`NEAR recovery participant IDs`),c=V(z(n,`registeredPublicKey`),32,`NEAR recovery registered public key`),l=nt(z(n,`runtimePolicyScope`)),u=V(z(n,`activationTranscript`),32,`NEAR recovery activation transcript`),d=Number(z(n,`activationStateEpoch`));if(!Number.isSafeInteger(d)||d<=0)throw Error(`walletRecoveryPrepare NEAR recovery activation state epoch is invalid`);let f=V(z(n,`signingWorkerVerifyingShare`),32,`NEAR recovery signing-worker verifying share`);if(o.wallet_id!==t||a.account_id!==t||a.root_share_epoch!==l.signingRootVersion)throw Error(`walletRecoveryPrepare NEAR recovery basis changed its wallet scope`);return{capabilityKind:r,activeCapabilityBinding:i,scope:a,applicationBinding:o,participantIds:s,registeredPublicKey:c,runtimePolicyScope:l,activationTranscript:u,activationStateEpoch:d,signingWorkerVerifyingShare:f}}function Xe(e,t){let n=R(e,[`publicCapability`,`activationReceipt`,`serverGeneration`,`clientRootPublicKey33B64u`,`chainTargets`,`ecdsaThresholdKeyId`,`signingRootId`,`signingRootVersion`,`runtimePolicyScope`,`participantIds`,`possessionChallenge`],`walletRecoveryPrepare.keyManifest.entries[].recoveryBasis`),r=ge(z(n,`publicCapability`)),i=ye(z(n,`activationReceipt`));if(r.client_id!==t)throw Error(`walletRecoveryPrepare ECDSA recovery capability changed the wallet scope`);let a=ce(z(n,`signingRootId`)),o=me(z(n,`signingRootVersion`)),s=nt(z(n,`runtimePolicyScope`));if(s.signingRootVersion!==o)throw Error(`walletRecoveryPrepare ECDSA recovery scope changed the signing root`);let c=fe(z(n,`serverGeneration`));if(String(i.server_generation)!==String(c))throw Error(`walletRecoveryPrepare ECDSA activation receipt changed server generation`);let l=ke(z(n,`possessionChallenge`));if(l.walletId!==t||l.expectedServerGeneration!==String(c)||l.derivationClientSharePublicKey33B64u!==r.public_identity.derivation_client_share_public_key33_b64u)throw Error(`walletRecoveryPrepare ECDSA possession challenge changed its capability`);return{publicCapability:r,activationReceipt:i,serverGeneration:c,clientRootPublicKey33B64u:_e(B(z(n,`clientRootPublicKey33B64u`),`keyManifest.entries[].recoveryBasis.clientRootPublicKey33B64u`)),chainTargets:Ze(z(n,`chainTargets`)),ecdsaThresholdKeyId:pe(z(n,`ecdsaThresholdKeyId`)),signingRootId:a,signingRootVersion:o,runtimePolicyScope:s,participantIds:$e(z(n,`participantIds`)),possessionChallenge:l}}function Ze(e){if(!Array.isArray(e)||e.length===0)throw Error(`walletRecoveryPrepare ECDSA recovery chain targets are invalid`);let t=e.map((e,t)=>Qe(e,t));if(new Set(t.map(Te)).size!==t.length)throw Error(`walletRecoveryPrepare ECDSA recovery chain targets are duplicated`);let n=t[0];if(!n)throw Error(`walletRecoveryPrepare ECDSA recovery chain targets are invalid`);return[n,...t.slice(1)]}function Qe(e,t){let n=`walletRecoveryPrepare.keyManifest.entries[].recoveryBasis.chainTargets[${t}]`,r=L(e,n),i=z(r,`kind`);Pe(r,i===`evm`?[`kind`,`namespace`,`chainId`,`networkSlug`]:[`kind`,`chainId`,`networkSlug`],n);let a=z(r,`namespace`),o=Number(z(r,`chainId`));if(!Number.isSafeInteger(o)||o<=0)throw Error(`walletRecoveryPrepare ECDSA recovery chain id is invalid`);let s=z(r,`networkSlug`),c=typeof s==`string`&&s.trim()?s.trim():null;if(i===`evm`){if(a!==`eip155`)throw Error(`walletRecoveryPrepare ECDSA recovery EVM namespace is invalid`);return{kind:`evm`,namespace:`eip155`,chainId:o,networkSlug:c??`evm-${o}`}}if(i===`tempo`)return{kind:`tempo`,chainId:o,networkSlug:c??`tempo-${o}`};throw Error(`walletRecoveryPrepare ECDSA recovery chain family is invalid`)}function $e(e){if(!Array.isArray(e)||e.length!==2||e[0]!==1||e[1]!==2)throw Error(`walletRecoveryPrepare ECDSA recovery participant IDs are invalid`);return[1,2]}function et(e){let t=R(e,[`lifecycle_id`,`root_share_epoch`,`account_id`,`threshold_session_id`,`signer_set_id`,`signing_worker_id`,`material_activation`],`walletRecoveryPrepare.keyManifest.entries[].recoveryBasis.scope`);return{lifecycle_id:B(z(t,`lifecycle_id`),`keyManifest.entries[].recoveryBasis.scope.lifecycle_id`),root_share_epoch:B(z(t,`root_share_epoch`),`keyManifest.entries[].recoveryBasis.scope.root_share_epoch`),account_id:B(z(t,`account_id`),`keyManifest.entries[].recoveryBasis.scope.account_id`),threshold_session_id:B(z(t,`threshold_session_id`),`keyManifest.entries[].recoveryBasis.scope.threshold_session_id`),signer_set_id:B(z(t,`signer_set_id`),`keyManifest.entries[].recoveryBasis.scope.signer_set_id`),signing_worker_id:B(z(t,`signing_worker_id`),`keyManifest.entries[].recoveryBasis.scope.signing_worker_id`),material_activation:de(z(t,`material_activation`))}}function tt(e){let t=R(e,[`wallet_id`,`near_ed25519_signing_key_id`,`signing_root_id`,`key_creation_signer_slot`],`walletRecoveryPrepare.keyManifest.entries[].recoveryBasis.applicationBinding`),n=Number(z(t,`key_creation_signer_slot`));if(!Number.isSafeInteger(n)||n<=0)throw Error(`walletRecoveryPrepare NEAR recovery key-creation signer slot is invalid`);return{wallet_id:B(z(t,`wallet_id`),`keyManifest.entries[].recoveryBasis.applicationBinding.wallet_id`),near_ed25519_signing_key_id:B(z(t,`near_ed25519_signing_key_id`),`keyManifest.entries[].recoveryBasis.applicationBinding.near_ed25519_signing_key_id`),signing_root_id:B(z(t,`signing_root_id`),`keyManifest.entries[].recoveryBasis.applicationBinding.signing_root_id`),key_creation_signer_slot:n}}function nt(e){let t=R(e,[`orgId`,`projectId`,`envId`,`signingRootVersion`],`walletRecoveryPrepare.keyManifest.entries[].recoveryBasis.runtimePolicyScope`);try{return C(t)}catch{throw Error(`walletRecoveryPrepare NEAR recovery runtime policy scope is invalid`)}}function rt(e,t){if(!Array.isArray(e)||e.length!==2||!Number.isSafeInteger(e[0])||!Number.isSafeInteger(e[1])||Number(e[0])<=0||Number(e[1])<=0||Number(e[0])===Number(e[1]))throw Error(`walletRecoveryPrepare ${t} is invalid`);return[Number(e[0]),Number(e[1])]}function it(e,t,n){let r=B(e,n),i=T(r);if(i.length!==t||w(i)!==r)throw Error(`walletRecoveryPrepare ${n} is invalid`);return r}function at(e,t){let n=B(e,t),r=T(n);if(r.length===0||w(r)!==n)throw Error(`walletRecoveryPrepare ${t} is invalid`);return n}function V(e,t,n){if(!Array.isArray(e)||e.length!==t||e.some(e=>!Number.isInteger(e)||e<0||e>255))throw Error(`walletRecoveryPrepare ${n} is invalid`);return e.map(Number)}const ot=`/wallets/recovery/finalize`;async function st(e){let t=`${_(e.relayUrl)}${ot}`,n=e.fetchImpl||fetch,r;try{r=Ae(e.webauthnRegistration)}catch{return{kind:`refused`}}let i;try{let t=new Set;i=e.ecdsaMaterialPossessionProofs.map(e=>{if(typeof e.keySetId!=`string`||!e.keySetId.startsWith(`evm_family_ecdsa:`)||e.keySetId.length<=17)throw Error(`ECDSA possession proof key-set id is invalid`);if(t.has(e.keySetId))throw Error(`ECDSA possession proof key-set ids are duplicated`);return t.add(e.keySetId),{keySetId:e.keySetId,proof:F(e.proof)}})}catch{return{kind:`refused`}}let a;try{if(a=j(e.replacementEnvelope,`walletRecoveryFinalize.replacementEnvelope`),String(a.walletId)!==String(e.walletId))throw Error(`replacement envelope changed the wallet identity`);if(String(a.envelopeId)!==String(e.replacementId))throw Error(`replacement envelope changed the replacement identity`);if(a.factor.kind!==`passkey`)throw Error(`replacement envelope is not bound to a passkey`)}catch{return{kind:`refused`}}let o;try{o=await n(t,p({body:{kind:`finalize`,walletId:e.walletId,reservationId:e.reservationId,recoveryOperationId:e.recoveryOperationId,targetDeviceId:e.targetDeviceId,targetAuthorityId:e.targetAuthorityId,targetWalletAuthMethodId:e.targetWalletAuthMethodId,challengeId:e.challengeId,replacementId:e.replacementId,webauthnRegistration:r,replacementEnvelope:a,ecdsaMaterialPossessionProofs:i}}))}catch{return{kind:`transport_uncertain`}}let s=lt(await o.json().catch(()=>({})));if(o.status===200&&s.kind===`success`)try{let t=await I(s.projection,ut(e,a));if(t.kind!==`passkey`)throw Error(`recovery projection branch changed`);return{kind:`promoted`,storeVersion:t.storeVersion,authority:t.authority,authMethod:t.authMethod}}catch{return{kind:`transport_uncertain`}}return o.status===409?{kind:`retryable_conflict`}:o.status===400||o.status===401?{kind:`refused`}:{kind:`transport_uncertain`}}async function ct(e){let t;try{if(t=j(e.replacementEnvelope,`walletRecoveryReplay.replacementEnvelope`),String(t.walletId)!==String(e.walletId)||String(t.envelopeId)!==String(e.replacementId)||t.factor.kind!==`passkey`)throw Error(`recovery replay envelope identity is invalid`)}catch{return{kind:`refused`}}let n;try{n=await(e.fetchImpl??fetch)(`${_(e.relayUrl)}${ot}`,p({body:{kind:`replay`,walletId:e.walletId,reservationId:e.reservationId,recoveryOperationId:e.recoveryOperationId,targetDeviceId:e.targetDeviceId,targetAuthorityId:e.targetAuthorityId,targetWalletAuthMethodId:e.targetWalletAuthMethodId,replacementId:e.replacementId,replacementEnvelope:t}}))}catch{return{kind:`transport_uncertain`}}let r=lt(await n.json().catch(()=>({})));if(n.status===200&&r.kind===`success`)try{let n=await I(r.projection,ut(e,t));if(n.kind!==`passkey`)throw Error(`recovery projection branch changed`);return{kind:`promoted`,storeVersion:n.storeVersion,authority:n.authority,authMethod:n.authMethod}}catch{return{kind:`transport_uncertain`}}return n.status===409?{kind:`retryable_conflict`}:n.status===400||n.status===401?{kind:`refused`}:{kind:`transport_uncertain`}}function lt(e){if(typeof e!=`object`||!e||Array.isArray(e)||Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)return{kind:`invalid`};let t=new Map(Object.entries(e)),n=[...t.keys()];if(t.size===2&&n.includes(`ok`)&&n.includes(`projection`)&&t.get(`ok`)===!0)return{kind:`success`,projection:t.get(`projection`)};let r=t.get(`code`),i=t.get(`message`);return t.size===3&&n.includes(`ok`)&&n.includes(`code`)&&n.includes(`message`)&&t.get(`ok`)===!1&&typeof r==`string`&&typeof i==`string`?{kind:`failure`,code:r,message:i}:{kind:`invalid`}}function ut(n,i){if(i.factor.kind!==`passkey`)throw Error(`replacement envelope is not a passkey envelope`);return{kind:`passkey`,walletId:H(r(n.walletId)),recoveryOperationId:H(e(n.recoveryOperationId)),targetDeviceId:H(k(n.targetDeviceId)),targetAuthorityId:H(t(n.targetAuthorityId)),targetWalletAuthMethodId:H(a(n.targetWalletAuthMethodId)),rpId:i.factor.rpId,credentialIdB64u:i.factor.credentialIdB64u}}function H(e){if(!e.ok)throw Error(`invalid recovery identity`);return e.value}function U(e){return e.target.kind===`passkey`}function dt(e){return{kind:`email_otp_enrollment_reference_v1`,enrollmentId:e.enrollment.enrollmentId,enrollmentSealKeyVersion:e.enrollment.kind===`existing`?e.enrollment.enrollmentSealKeyVersion:e.enrollment.material.enrollmentSealKeyVersion}}const ft=[`kind`,`keySetId`,`applicationBindingDigestB64u`,`registeredPublicKeyB64u`,`participantIds`,`stateEpoch`,`signingWorkerVerifyingShareB64u`,`materialActivation`,`sealed`],pt=[`kind`,`keySetId`,`possessionProof`,`readyStateBlobB64u`,`publicFacts`],mt=[`contextBinding32B64u`,`derivationClientSharePublicKey33B64u`,`clientVerifyingShare33B64u`,`relayerPublicKey33B64u`,`groupPublicKey33B64u`,`ethereumAddress`,`clientShareRetryCounter`,`relayerShareRetryCounter`],ht=[`kind`,`version`,`recoveryOperationId`,`walletId`,`reservationId`,`targetDeviceId`,`targetAuthorityId`,`targetWalletAuthMethodId`,`replacementEnvelope`,`keyManifest`,`nearKeySets`,`ecdsaKeySets`,`target`];function W(e,t,n){if(m(e,t,n),Object.keys(e).length!==t.length)throw Error(n+` fields are invalid`)}function G(e,t){if(typeof e!=`string`||!e||e.trim()!==e)throw Error(t+` must be a non-empty canonical string`);return e}function K(e,t,n){let r=G(e,t),i=T(r);if(n!==void 0&&i.byteLength!==n)throw Error(t+` must decode to `+n+` bytes`);return r}function gt(e,t){if(typeof e!=`number`||!Number.isSafeInteger(e)||e<0)throw Error(t+` must be a non-negative safe integer`);return e}function _t(e,t){if(!Array.isArray(e)||e.length!==2||e.some(vt))throw Error(t+` must contain two positive participant IDs`);return[e[0],e[1]]}function vt(e){return typeof e!=`number`||!Number.isSafeInteger(e)||e<1}function yt(e,t){let n=G(f(t,`recovery durable NEAR key set`).keySetId,`recovery durable NEAR keySetId`),r=e.entries.find(e=>e.keySetId===n);if(!r||r.kind!==`near_ed25519`)throw Error(`recovery durable NEAR key-set manifest entry is invalid`);return r}function bt(e,t){let n=G(f(t,`recovery durable ECDSA key set`).keySetId,`recovery durable ECDSA keySetId`),r=e.entries.find(e=>e.keySetId===n);if(!r||r.kind!==`evm_family_ecdsa`)throw Error(`recovery durable ECDSA key-set manifest entry is invalid`);return r}function xt(e){let t=ee(e);if(!t)throw Error(`recovery runtime policy scope is invalid`);return t}function St(e,t){let n=f(e,`recovery durable NEAR key set`);if(W(n,ft,`recovery durable NEAR key set`),n.kind!==`near_ed25519`||n.keySetId!==t.keySetId)throw Error(`recovery durable NEAR key-set identity is invalid`);let r=t.recoveryBasis,a=r.scope.threshold_session_id;if(!i(a).ok)throw Error(`recovery durable NEAR thresholdSessionId is invalid`);let o={kind:ie,applicationBindingDigestB64u:S(n.applicationBindingDigestB64u,`recovery durable NEAR application binding digest`),registeredPublicKeyB64u:v(n.registeredPublicKeyB64u,`recovery durable NEAR registered public key`),participantIds:_t(n.participantIds,`recovery durable NEAR participantIds`),stateEpoch:G(n.stateEpoch,`recovery durable NEAR stateEpoch`),walletId:r.applicationBinding.wallet_id,nearAccountId:t.nearAccountId,nearEd25519SigningKeyId:r.applicationBinding.near_ed25519_signing_key_id,signerSlot:y(r.applicationBinding.key_creation_signer_slot,`recovery durable NEAR signerSlot`),signingWorkerId:r.scope.signing_worker_id,signingWorkerVerifyingShareB64u:v(n.signingWorkerVerifyingShareB64u,`recovery durable NEAR signing-worker verifying share`)},s=f(n.sealed,`recovery durable NEAR sealed material`);return W(s,[`ciphertextB64u`,`nonceB64u`],`recovery durable NEAR sealed material`),{kind:`near_ed25519`,keySetId:t.keySetId,binding:o,thresholdSessionId:a,runtimePolicyScope:xt(r.runtimePolicyScope),materialActivation:de(n.materialActivation),sealed:{ciphertextB64u:b(s.ciphertextB64u,`recovery durable NEAR ciphertext`),nonceB64u:g(s.nonceB64u,`recovery durable NEAR nonce`)}}}function Ct(e){let t=f(e,`recovery durable ECDSA public facts`);W(t,mt,`recovery durable ECDSA public facts`);let n=G(t.ethereumAddress,`recovery durable ECDSA ethereumAddress`).toLowerCase();if(!/^0x[0-9a-f]{40}$/.test(n))throw Error(`recovery durable ECDSA ethereumAddress is invalid`);return{contextBinding32B64u:S(t.contextBinding32B64u,`recovery durable ECDSA context binding`),derivationClientSharePublicKey33B64u:x(t.derivationClientSharePublicKey33B64u,`recovery durable ECDSA client share`),clientVerifyingShare33B64u:x(t.clientVerifyingShare33B64u,`recovery durable ECDSA client verifying share`),relayerPublicKey33B64u:x(t.relayerPublicKey33B64u,`recovery durable ECDSA relayer public key`),groupPublicKey33B64u:x(t.groupPublicKey33B64u,`recovery durable ECDSA group public key`),ethereumAddress:n,clientShareRetryCounter:gt(t.clientShareRetryCounter,`recovery durable ECDSA client-share retry counter`),relayerShareRetryCounter:gt(t.relayerShareRetryCounter,`recovery durable ECDSA relayer-share retry counter`)}}function wt(e,t){let n=f(e,`recovery durable ECDSA key set`);if(W(n,pt,`recovery durable ECDSA key set`),n.kind!==`evm_family_ecdsa`||n.keySetId!==t.keySetId)throw Error(`recovery durable ECDSA key-set identity is invalid`);return{kind:`evm_family_ecdsa`,entry:t,possessionProof:F(n.possessionProof),readyStateBlobB64u:K(n.readyStateBlobB64u,`recovery durable ECDSA ready-state blob`),publicFacts:Ct(n.publicFacts)}}function Tt(e){let t=f(e,`recovery durable registration`);if(W(t,[`kind`,`id`,`rawId`,`type`,`authenticatorAttachment`,`response`],`recovery durable registration`),t.kind!==`wallet_recovery_redacted_registration_v1`)throw Error(`recovery durable registration kind is invalid`);if(t.authenticatorAttachment!==null&&typeof t.authenticatorAttachment!=`string`)throw Error(`recovery durable registration authenticatorAttachment is invalid`);let n=f(t.response,`recovery durable registration response`);if(W(n,[`clientDataJSON`,`attestationObject`,`transports`],`recovery durable registration response`),!Array.isArray(n.transports))throw Error(`recovery durable registration transports are invalid`);return{kind:`wallet_recovery_redacted_registration_v1`,id:G(t.id,`recovery durable registration id`),rawId:K(t.rawId,`recovery durable registration rawId`),type:G(t.type,`recovery durable registration type`),authenticatorAttachment:t.authenticatorAttachment,response:{clientDataJSON:K(n.clientDataJSON,`recovery durable registration clientDataJSON`),attestationObject:K(n.attestationObject,`recovery durable registration attestationObject`),transports:n.transports.map((e,t)=>G(e,`recovery durable registration transports[`+t+`]`))}}}function Et(e){let t=f(e,`recovery durable Email OTP enrollment`);if(t.kind===`existing`)return W(t,[`kind`,`enrollmentId`,`enrollmentSealKeyVersion`],`recovery durable existing Email OTP enrollment`),{kind:`existing`,enrollmentId:G(t.enrollmentId,`recovery enrollmentId`),enrollmentSealKeyVersion:G(t.enrollmentSealKeyVersion,`recovery enrollment seal-key version`)};if(t.kind!==`create`)throw Error(`recovery durable Email OTP enrollment kind is invalid`);W(t,[`kind`,`enrollmentId`,`providerSubject`,`verifiedEmail`,`material`],`recovery durable create Email OTP enrollment`);let n=f(t.material,`recovery durable enrollment material`);return W(n,[`enrollmentSealKeyVersion`,`clientUnlockPublicKeyB64u`,`unlockKeyVersion`,`serverSealedFactorCiphertextB64u`],`recovery durable enrollment material`),{kind:`create`,enrollmentId:G(t.enrollmentId,`recovery enrollmentId`),providerSubject:G(t.providerSubject,`recovery enrollment providerSubject`),verifiedEmail:G(t.verifiedEmail,`recovery enrollment verifiedEmail`),material:{enrollmentSealKeyVersion:G(n.enrollmentSealKeyVersion,`recovery enrollment material seal-key version`),clientUnlockPublicKeyB64u:K(n.clientUnlockPublicKeyB64u,`recovery enrollment client unlock public key`),unlockKeyVersion:G(n.unlockKeyVersion,`recovery enrollment unlock-key version`),serverSealedFactorCiphertextB64u:K(n.serverSealedFactorCiphertextB64u,`recovery enrollment sealed factor ciphertext`)}}}function q(i){let o=f(i,`wallet recovery durable payload`);if(o.kind!==`wallet_recovery_durable_payload_v1`||o.version!==1)throw Error(`wallet recovery durable payload version is invalid`);W(o,[...ht,...f(o.target,`wallet recovery durable target`).kind===`passkey`?[`replacementId`,`challengeId`,`registration`]:[`providerSubject`,`verifiedEmail`,`emailHashHex`,`registrationAuthorityId`,`replacementId`,`enrollment`]],`wallet recovery durable payload`);let s=e(o.recoveryOperationId),l=r(o.walletId),u;try{u=P(o.reservationId)}catch(e){throw Error(`wallet recovery durable reservationId is invalid`,{cause:e})}let d=k(o.targetDeviceId),p=t(o.targetAuthorityId),m=a(o.targetWalletAuthMethodId);if(!s.ok||!l.ok||!d.ok||!p.ok||!m.ok)throw Error(`wallet recovery durable payload identity is invalid`);if(!Array.isArray(o.nearKeySets)||!Array.isArray(o.ecdsaKeySets))throw Error(`wallet recovery durable key-set arrays are invalid`);let h=qe(o.keyManifest,String(l.value)),g=o.nearKeySets.map(e=>St(e,yt(h,e))),_=o.ecdsaKeySets.map(e=>wt(e,bt(h,e))),v=[...g.map(e=>e.keySetId),..._.map(e=>e.entry.keySetId)];if(new Set(v).size!==v.length)throw Error(`wallet recovery durable key-set ids are duplicated`);if(h.entries.length!==v.length||h.entries.some(e=>!v.includes(e.keySetId)))throw Error(`wallet recovery durable key-set manifest coverage is invalid`);let y={kind:`wallet_recovery_durable_payload_v1`,version:1,recoveryOperationId:s.value,walletId:l.value,reservationId:u,targetDeviceId:d.value,targetAuthorityId:p.value,targetWalletAuthMethodId:m.value,replacementEnvelope:j(o.replacementEnvelope,`wallet recovery durable replacementEnvelope`),keyManifest:h,nearKeySets:g,ecdsaKeySets:_};if(String(y.replacementEnvelope.walletId)!==String(l.value))throw Error(`wallet recovery durable replacement envelope wallet changed`);if(y.replacementEnvelope.ownership.kind!==`method_bound`||y.replacementEnvelope.ownership.walletAuthMethodId!==m.value)throw Error(`wallet recovery durable replacement envelope method changed`);for(let e of g)if(e.binding.walletId!==String(l.value))throw Error(`wallet recovery durable NEAR binding wallet changed`);let b=f(o.target,`wallet recovery durable target`);if(b.kind===`passkey`){W(b,[`kind`,`rpId`],`wallet recovery durable passkey target`);let e=n(b.rpId);if(!e.ok)throw Error(`wallet recovery durable passkey RP ID is invalid`);let t=Tt(o.registration);if(t.rawId!==y.replacementEnvelope.factor.credentialIdB64u)throw Error(`wallet recovery durable passkey registration identity changed`);if(y.replacementEnvelope.factor.kind!==`passkey`)throw Error(`wallet recovery durable passkey envelope factor is invalid`);if(y.replacementEnvelope.factor.rpId!==e.value||y.replacementEnvelope.factor.credentialIdB64u!==t.rawId)throw Error(`wallet recovery durable passkey envelope identity changed`);let r=G(o.replacementId,`wallet recovery durable replacementId`);if(String(y.replacementEnvelope.envelopeId)!==r)throw Error(`wallet recovery durable passkey envelope id changed`);return{...y,target:{kind:`passkey`,rpId:e.value},replacementId:r,challengeId:G(o.challengeId,`wallet recovery durable challengeId`),registration:t}}if(b.kind!==`google_email_otp`)throw Error(`wallet recovery durable target kind is invalid`);W(b,[`kind`],`wallet recovery durable Email OTP target`);let x=G(o.providerSubject,`wallet recovery providerSubject`);if(!c(x).ok)throw Error(`wallet recovery durable providerSubject is invalid`);let S=G(o.verifiedEmail,`wallet recovery durable verifiedEmail`),C=G(o.emailHashHex,`wallet recovery durable emailHashHex`);if(!/^[0-9a-f]{64}$/.test(C))throw Error(`wallet recovery durable emailHashHex is invalid`);let w=G(o.registrationAuthorityId,`wallet recovery durable registrationAuthorityId`),T=Et(o.enrollment);if(y.replacementEnvelope.factor.kind!==`email_otp`)throw Error(`wallet recovery durable Email OTP envelope factor is invalid`);let ee=T.kind===`existing`?{enrollmentId:T.enrollmentId,enrollmentSealKeyVersion:T.enrollmentSealKeyVersion}:{enrollmentId:T.enrollmentId,enrollmentSealKeyVersion:T.material.enrollmentSealKeyVersion};if(y.replacementEnvelope.factor.enrollmentId!==ee.enrollmentId||y.replacementEnvelope.factor.enrollmentSealKeyVersion!==ee.enrollmentSealKeyVersion)throw Error(`wallet recovery durable Email OTP envelope identity changed`);if(T.kind===`create`&&(T.providerSubject!==x||T.verifiedEmail!==S))throw Error(`wallet recovery durable Email OTP enrollment identity changed`);let te=G(o.replacementId,`wallet recovery durable replacementId`);if(String(y.replacementEnvelope.envelopeId)!==te)throw Error(`wallet recovery durable Email OTP envelope id changed`);return{...y,target:{kind:`google_email_otp`},providerSubject:x,verifiedEmail:S,emailHashHex:C,registrationAuthorityId:w,replacementId:te,enrollment:T}}function Dt(e){let t=e.nearKeySets.map(e=>({kind:e.kind,keySetId:e.keySetId,applicationBindingDigestB64u:e.binding.applicationBindingDigestB64u,registeredPublicKeyB64u:e.binding.registeredPublicKeyB64u,participantIds:e.binding.participantIds,stateEpoch:e.binding.stateEpoch,signingWorkerVerifyingShareB64u:e.binding.signingWorkerVerifyingShareB64u,materialActivation:e.materialActivation,sealed:e.sealed})),n=e.ecdsaKeySets.map(e=>({kind:e.kind,keySetId:e.entry.keySetId,possessionProof:e.possessionProof,readyStateBlobB64u:e.readyStateBlobB64u,publicFacts:e.publicFacts})),r={kind:e.kind,version:e.version,recoveryOperationId:String(e.recoveryOperationId),walletId:String(e.walletId),reservationId:String(e.reservationId),targetDeviceId:String(e.targetDeviceId),targetAuthorityId:String(e.targetAuthorityId),targetWalletAuthMethodId:String(e.targetWalletAuthMethodId),replacementEnvelope:e.replacementEnvelope,keyManifest:e.keyManifest,nearKeySets:t,ecdsaKeySets:n},i=U(e)?{...r,target:e.target,replacementId:e.replacementId,challengeId:e.challengeId,registration:e.registration}:{...r,target:e.target,providerSubject:e.providerSubject,verifiedEmail:e.verifiedEmail,emailHashHex:e.emailHashHex,registrationAuthorityId:e.registrationAuthorityId,replacementId:e.replacementId,enrollment:e.enrollment};return q(i),i}async function Ot(e){if(U(e))return;let t=await d(e.verifiedEmail);if(e.emailHashHex!==t)throw Error(`wallet recovery durable email hash does not match verified email`);if(e.enrollment.kind===`create`&&(e.enrollment.providerSubject!==e.providerSubject||e.enrollment.verifiedEmail!==e.verifiedEmail))throw Error(`wallet recovery durable enrollment does not match Email OTP identity`)}function J(e){if(U(e)){let t=o(e.registration.rawId);if(!t.ok)throw Error(`wallet recovery durable passkey credential id is invalid`);return{kind:`passkey`,rpId:e.target.rpId,credentialIdB64u:t.value}}let t=c(e.providerSubject);if(!t.ok)throw Error(`wallet recovery durable providerSubject is invalid`);return{kind:`google_email_otp`,providerSubject:t.value,emailHashHex:e.emailHashHex,registrationAuthorityId:e.registrationAuthorityId,enrollment:dt(e)}}function kt(e){return{kind:`near_ed25519`,keySetId:e.entry.keySetId,applicationBindingDigestB64u:e.localMaterial.applicationBindingDigestB64u,registeredPublicKeyB64u:w(e.metadata.registeredPublicKey),participantIds:e.metadata.participantIds,stateEpoch:String(e.metadata.stateEpoch),signingWorkerVerifyingShareB64u:w(e.metadata.signingWorkerVerifyingShare),materialActivation:ve(e.metadata.materialActivation),sealed:{ciphertextB64u:e.localMaterial.b64u,nonceB64u:e.localMaterial.nonceB64u}}}function At(e){return{kind:`evm_family_ecdsa`,keySetId:e.entry.keySetId,possessionProof:F(e.activation.possessionProof),readyStateBlobB64u:e.readyStateBlobB64u,publicFacts:e.publicFacts}}function jt(e){return{kind:`wallet_recovery_redacted_registration_v1`,id:e.id,rawId:e.rawId,type:e.type,authenticatorAttachment:e.authenticatorAttachment??null,response:{clientDataJSON:e.response.clientDataJSON,attestationObject:e.response.attestationObject,transports:[...e.response.transports]}}}async function Mt(e){let t={kind:`wallet_recovery_durable_payload_v1`,version:1,recoveryOperationId:String(e.prepared.recoveryOperationId),walletId:e.walletId,reservationId:e.prepared.reservationId,targetDeviceId:e.prepared.targetDeviceId,targetAuthorityId:e.prepared.targetAuthorityId,targetWalletAuthMethodId:e.prepared.targetWalletAuthMethodId,replacementEnvelope:j(e.recovered.replacementEnvelope,`wallet recovery durable replacement envelope`),keyManifest:{version:`wallet_recovery_preparation_key_manifest_v1`,walletId:String(e.walletId),entries:[...e.recovered.nearKeySets.map(e=>e.entry),...e.recovered.ecdsaKeySets.map(e=>e.entry)]},nearKeySets:e.recovered.nearKeySets.map(kt),ecdsaKeySets:e.recovered.ecdsaKeySets.map(At)};if(e.replacement.kind===`passkey`){if(e.target.kind!==`passkey`)throw Error(`wallet recovery durable payload branch is invalid`);let n=e.prepared.registration;if(!n)throw Error(`wallet recovery registration options are unavailable`);let r=jt(e.replacement.registration);if(r.rawId!==e.replacement.credentialIdB64u)throw Error(`wallet recovery passkey registration rawId changed its credential identity`);let i=q({...t,target:{kind:`passkey`,rpId:e.target.rpId},replacementId:n.replacementId,challengeId:n.challengeId,registration:r});return await Ot(i),i}if(e.target.kind!==`google_email_otp`)throw Error(`wallet recovery durable payload branch is invalid`);let n=e.replacement.enrollment;if(e.replacement.factor.walletAuthMethodId!==t.targetWalletAuthMethodId)throw Error(`wallet recovery Email OTP factor method changed its target identity`);let r=await d(e.replacement.verifiedEmail),i=q({...t,target:{kind:`google_email_otp`},enrollment:n,providerSubject:e.replacement.providerSubject,verifiedEmail:e.replacement.verifiedEmail,emailHashHex:r,registrationAuthorityId:e.replacement.registrationAuthorityId,replacementId:e.replacement.factor.replacementId});return await Ot(i),i}function Nt(e){return new TextEncoder().encode(u({kind:`pending_wallet_recovery_commit_v1`,version:1,...e}))}function Pt(e){return Nt({recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,reservationId:e.reservationId,targetDeviceId:e.targetDeviceId,targetAuthorityId:e.targetAuthorityId,targetWalletAuthMethodId:e.targetWalletAuthMethodId,target:J(e)})}async function Ft(e){let t=await crypto.subtle.generateKey({name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`]);if(!(t instanceof CryptoKey))throw Error(`wallet recovery durable key generation failed`);let n=crypto.getRandomValues(new Uint8Array(12)),r=new TextEncoder().encode(JSON.stringify(Dt(e)));return{kind:`wallet_recovery_encrypted_material_v1`,key:t,iv:n,ciphertext:new Uint8Array(await crypto.subtle.encrypt({name:`AES-GCM`,iv:n,additionalData:Pt(e)},t,r))}}async function It(e){let t=await crypto.subtle.decrypt({name:`AES-GCM`,iv:e.localMaterial.iv,additionalData:Lt(e)},e.localMaterial.key,e.localMaterial.ciphertext),n=q(JSON.parse(new TextDecoder().decode(t)));if(await Ot(n),!Rt(e,n))throw Error(`wallet recovery durable payload identity does not match its journal`);return n}function Lt(e){return Nt({recoveryOperationId:e.recoveryOperationId,walletId:e.walletId,reservationId:e.reservationId,targetDeviceId:e.targetDeviceId,targetAuthorityId:e.targetAuthorityId,targetWalletAuthMethodId:e.targetWalletAuthMethodId,target:e.target})}function Y(t){let n=e(t);if(!n.ok)throw Error(`wallet recovery operation id is invalid`);return n.value}function Rt(e,t){let n={kind:`pending_wallet_recovery_commit_v1`,version:1,recoveryOperationId:Y(t.recoveryOperationId),walletId:t.walletId,reservationId:t.reservationId,targetDeviceId:t.targetDeviceId,targetAuthorityId:t.targetAuthorityId,targetWalletAuthMethodId:t.targetWalletAuthMethodId,localMaterial:e.localMaterial,createdAtMs:e.createdAtMs,updatedAtMs:e.updatedAtMs},r=J(t);if(e.stage===`awaiting_server_promotion`)return M(e,{...n,stage:`awaiting_server_promotion`,target:r});switch(r.kind){case`passkey`:return e.projection.kind===`passkey`?M(e,{...n,stage:`server_promoted`,target:r,projection:e.projection}):!1;case`google_email_otp`:return e.projection.kind===`google_email_otp`?M(e,{...n,stage:`server_promoted`,target:r,projection:e.projection}):!1}}function zt(e,t,n,r){return{kind:`pending_wallet_recovery_commit_v1`,version:1,recoveryOperationId:Y(e.recoveryOperationId),walletId:e.walletId,reservationId:e.reservationId,targetDeviceId:e.targetDeviceId,targetAuthorityId:e.targetAuthorityId,targetWalletAuthMethodId:e.targetWalletAuthMethodId,target:J(e),localMaterial:t,createdAtMs:n,updatedAtMs:r}}function Bt(e,t,n=Date.now()){return{...zt(e,t,n,n),stage:`awaiting_server_promotion`}}function Vt(e,t,n,r=Date.now()){let i=zt(t,e.localMaterial,e.createdAtMs,Math.max(r,e.createdAtMs+1));if(U(t)){if(n.kind!==`passkey`)throw Error(`wallet recovery promotion projection branch changed`);return{...i,stage:`server_promoted`,target:J(t),projection:n}}if(n.kind!==`google_email_otp`)throw Error(`wallet recovery promotion projection branch changed`);return{...i,stage:`server_promoted`,target:J(t),projection:n}}const Ht=`/wallets/recovery/google-email-otp/finalize`;async function Ut(e){let t=await X(e,`/wallets/recovery/google/verify`,{recoveryOperationId:e.recoveryOperationId,reservationId:e.reservationId,idToken:e.idToken});if(!t.ok)return t.failure;try{let n=Jt(t.body),r=qt(n,e),i=Q(s(n.challengeId)),a=Number(n.expiresAtMs);if(!Number.isSafeInteger(a)||a<=0)throw Error(`invalid expiry`);return{kind:`verified`,...r,challengeId:i,delivery:xe(n.delivery,`walletRecoveryGoogleVerify.delivery`),expiresAtMs:a}}catch{return{kind:`transport_uncertain`}}}async function Wt(e){let t=await X(e,`/wallets/recovery/email-otp/verify`,{recoveryOperationId:e.recoveryOperationId,reservationId:e.reservationId,challengeId:e.challengeId,otpCode:e.otpCode});if(!t.ok)return t.failure;try{let n=Yt(t.body),r=qt(n,e),i=Q(s(n.challengeId));if(i!==e.challengeId)throw Error(`challenge changed`);return{kind:`verified`,...r,challengeId:i}}catch{return{kind:`transport_uncertain`}}}async function Gt(e){let t,n;try{if(t=j(e.replacementEnvelope,`walletRecoveryGoogleEmailOtpFinalize.replacementEnvelope`),t.factor.kind!==`email_otp`)throw Error(`wrong factor`);n=e.ecdsaMaterialPossessionProofs.map(e=>({keySetId:e.keySetId,proof:F(e.proof)}))}catch{return{kind:`refused`}}let r=await X(e,Ht,{kind:`finalize`,recoveryOperationId:e.recoveryOperationId,reservationId:e.reservationId,replacementEnvelope:t,ecdsaMaterialPossessionProofs:n,...e.emailOtpEnrollment?{emailOtpEnrollment:e.emailOtpEnrollment}:{}});if(!r.ok)return r.failure;try{let n=await I(Xt(r.body,`walletRecoveryGoogleEmailOtpFinalize`).projection,en(e,t));if(n.kind!==`google_email_otp`)throw Error(`recovery projection branch changed`);return{kind:`promoted`,storeVersion:n.storeVersion,authority:n.authority,authMethod:n.authMethod}}catch{return{kind:`transport_uncertain`}}}async function Kt(e){let t;try{if(t=j(e.replacementEnvelope,`walletRecoveryGoogleEmailOtpReplay.replacementEnvelope`),t.factor.kind!==`email_otp`||String(t.walletId)!==String(e.walletId))throw Error(`recovery replay envelope identity is invalid`)}catch{return{kind:`refused`}}let n=await X(e,Ht,{kind:`replay`,recoveryOperationId:e.recoveryOperationId,reservationId:e.reservationId,replacementEnvelope:t});if(!n.ok)return n.failure;try{let r=await I(Xt(n.body,`walletRecoveryGoogleEmailOtpReplay`).projection,en(e,t));if(r.kind!==`google_email_otp`)throw Error(`recovery projection branch changed`);return{kind:`promoted`,storeVersion:r.storeVersion,authority:r.authority,authMethod:r.authMethod}}catch{return{kind:`transport_uncertain`}}}async function X(e,t,n){let r;try{r=await(e.fetchImpl??fetch)(`${_(e.relayUrl)}${t}`,p({body:n}))}catch{return{ok:!1,failure:{kind:`transport_uncertain`}}}let i=await r.json().catch(()=>void 0);return r.status===200?{ok:!0,body:i}:r.status===409||r.status===429?{ok:!1,failure:{kind:`retryable_conflict`}}:r.status===400||r.status===401?{ok:!1,failure:{kind:`refused`}}:{ok:!1,failure:{kind:`transport_uncertain`}}}function qt(t,n){let r=Q(e(t.recoveryOperationId)),i=P(t.reservationId);if(r!==n.recoveryOperationId||i!==n.reservationId)throw Error(`recovery operation identity changed`);return{recoveryOperationId:r,reservationId:i}}function Jt(e){let t=Zt(e,[`ok`,`recoveryOperationId`,`reservationId`,`challengeId`,`delivery`,`expiresAtMs`],`walletRecoveryGoogleVerify`);return $t(t,`walletRecoveryGoogleVerify`),{recoveryOperationId:Z(t,`recoveryOperationId`),reservationId:Z(t,`reservationId`),challengeId:Z(t,`challengeId`),delivery:Z(t,`delivery`),expiresAtMs:Z(t,`expiresAtMs`)}}function Yt(e){let t=Zt(e,[`ok`,`recoveryOperationId`,`reservationId`,`challengeId`],`walletRecoveryEmailOtpVerify`);return $t(t,`walletRecoveryEmailOtpVerify`),{recoveryOperationId:Z(t,`recoveryOperationId`),reservationId:Z(t,`reservationId`),challengeId:Z(t,`challengeId`)}}function Xt(e,t){let n=Zt(e,[`ok`,`projection`],t);return $t(n,t),{projection:Z(n,`projection`)}}function Zt(e,t,n){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`${n} must be a JSON object`);let r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)throw Error(`${n} must be a plain JSON object`);let i=Object.keys(e);if(i.length!==t.length||!Qt(i,t))throw Error(`${n} has an unexpected response shape`);return e}function Qt(e,t){for(let n of t)if(!e.includes(n))return!1;return!0}function $t(e,t){if(Z(e,`ok`)!==!0)throw Error(`${t} did not succeed`)}function Z(e,t){let n=Object.getOwnPropertyDescriptor(e,t);if(!n||!(`value`in n))throw Error(`response field ${t} is missing`);return n.value}function Q(e){if(!e.ok)throw Error(`invalid domain identity`);return e.value}function $(e){if(typeof e!=`string`||!e.trim())throw Error(`value must be a string`);return e.trim()}function en(e,t){if(t.factor.kind!==`email_otp`)throw Error(`replacement envelope is not an Email OTP envelope`);return{kind:`google_email_otp`,walletId:e.walletId,recoveryOperationId:e.recoveryOperationId,targetDeviceId:e.targetDeviceId,targetAuthorityId:e.targetAuthorityId,targetWalletAuthMethodId:e.targetWalletAuthMethodId,providerSubject:Q(c(e.expectedProviderSubject)),emailHashHex:tn(e.expectedEmailHashHex),registrationAuthorityId:$(e.expectedRegistrationAuthorityId),enrollment:{kind:`email_otp_enrollment_reference_v1`,enrollmentId:$(t.factor.enrollmentId),enrollmentSealKeyVersion:$(t.factor.enrollmentSealKeyVersion)}}}function tn(e){let t=$(e);if(!/^[0-9a-f]{64}$/.test(t))throw Error(`email hash is invalid`);return t}async function nn(e,t){if(e.version!==t.version||e.storeVersion!==t.storeVersion||e.walletId!==t.walletId||e.recoveryOperationId!==t.recoveryOperationId||e.targetDeviceId!==t.targetDeviceId||e.targetAuthorityId!==t.targetAuthorityId||e.targetWalletAuthMethodId!==t.targetWalletAuthMethodId||!await se(e.authority,t.authority)||!Ce(e.authMethod,t.authMethod)||e.kind!==t.kind)return!1;switch(e.kind){case`passkey`:return t.kind===`passkey`?e.target.kind===t.target.kind&&e.target.rpId===t.target.rpId&&e.target.credentialIdB64u===t.target.credentialIdB64u:!1;case`google_email_otp`:return t.kind===`google_email_otp`?e.target.kind===t.target.kind&&e.target.provider===t.target.provider&&e.target.providerSubject===t.target.providerSubject&&e.target.emailHashHex===t.target.emailHashHex&&e.target.registrationAuthorityId===t.target.registrationAuthorityId&&e.target.enrollment.kind===t.target.enrollment.kind&&e.target.enrollment.enrollmentId===t.target.enrollment.enrollmentId&&e.target.enrollment.enrollmentSealKeyVersion===t.target.enrollment.enrollmentSealKeyVersion:!1;default:return rn(e)}}function rn(e){throw Error(`unsupported wallet recovery projection: ${String(e)}`)}function an(e){let t=Y(e.payload.recoveryOperationId);switch(e.kind){case`passkey`:return Oe({kind:`passkey`,storeVersion:e.promotion.storeVersion,walletId:e.payload.walletId,recoveryOperationId:t,targetDeviceId:e.payload.targetDeviceId,targetAuthorityId:e.payload.targetAuthorityId,targetWalletAuthMethodId:e.payload.targetWalletAuthMethodId,authority:e.promotion.authority,authMethod:e.promotion.authMethod});case`google_email_otp`:{let n=c(e.payload.providerSubject);if(!n.ok)throw Error(`wallet recovery provider subject is invalid`);return Oe({kind:`google_email_otp`,storeVersion:e.promotion.storeVersion,walletId:e.payload.walletId,recoveryOperationId:t,targetDeviceId:e.payload.targetDeviceId,targetAuthorityId:e.payload.targetAuthorityId,targetWalletAuthMethodId:e.payload.targetWalletAuthMethodId,authority:e.promotion.authority,authMethod:e.promotion.authMethod,providerSubject:n.value,emailHashHex:e.payload.emailHashHex,registrationAuthorityId:e.payload.registrationAuthorityId,enrollment:dt(e.payload)})}}}function on(e){return e.ecdsaKeySets.map(e=>({keySetId:e.entry.keySetId,proof:e.possessionProof}))}function sn(e){return{id:e.registration.id,rawId:e.registration.rawId,type:e.registration.type,authenticatorAttachment:e.registration.authenticatorAttachment??void 0,response:{clientDataJSON:e.registration.response.clientDataJSON,attestationObject:e.registration.response.attestationObject,transports:[...e.registration.response.transports]},clientExtensionResults:{prf:{results:{first:void 0,second:void 0}}}}}async function cn(e){let{payload:t}=e;if(U(t)){let n=await st({relayUrl:e.relayUrl,walletId:String(t.walletId),reservationId:String(t.reservationId),recoveryOperationId:Y(t.recoveryOperationId),targetDeviceId:String(t.targetDeviceId),targetAuthorityId:String(t.targetAuthorityId),targetWalletAuthMethodId:String(t.targetWalletAuthMethodId),challengeId:t.challengeId,replacementId:t.replacementId,webauthnRegistration:sn(t),replacementEnvelope:t.replacementEnvelope,ecdsaMaterialPossessionProofs:on(t),fetchImpl:e.fetchImpl});return n.kind===`promoted`?{kind:`passkey`,payload:t,promotion:n}:n}let n=await Gt({relayUrl:e.relayUrl,recoveryOperationId:Y(t.recoveryOperationId),reservationId:t.reservationId,walletId:t.walletId,targetDeviceId:t.targetDeviceId,targetAuthorityId:t.targetAuthorityId,targetWalletAuthMethodId:t.targetWalletAuthMethodId,expectedProviderSubject:t.providerSubject,expectedEmailHashHex:t.emailHashHex,expectedRegistrationAuthorityId:t.registrationAuthorityId,replacementEnvelope:t.replacementEnvelope,ecdsaMaterialPossessionProofs:on(t),emailOtpEnrollment:ln(t.enrollment),fetchImpl:e.fetchImpl});return n.kind===`promoted`?{kind:`google_email_otp`,payload:t,promotion:n}:n}function ln(e){return e.kind===`create`?{kind:`create`,material:e.material}:null}async function un(e){let{payload:t}=e;if(U(t)){let n=await ct({relayUrl:e.relayUrl,walletId:String(t.walletId),reservationId:String(t.reservationId),recoveryOperationId:Y(t.recoveryOperationId),targetDeviceId:String(t.targetDeviceId),targetAuthorityId:String(t.targetAuthorityId),targetWalletAuthMethodId:String(t.targetWalletAuthMethodId),replacementId:t.replacementId,replacementEnvelope:t.replacementEnvelope,fetchImpl:e.fetchImpl});return n.kind===`promoted`?{kind:`passkey`,payload:t,promotion:n}:n}let n=await Kt({relayUrl:e.relayUrl,recoveryOperationId:Y(t.recoveryOperationId),reservationId:t.reservationId,walletId:t.walletId,targetDeviceId:t.targetDeviceId,targetAuthorityId:t.targetAuthorityId,targetWalletAuthMethodId:t.targetWalletAuthMethodId,expectedProviderSubject:t.providerSubject,expectedEmailHashHex:t.emailHashHex,expectedRegistrationAuthorityId:t.registrationAuthorityId,replacementEnvelope:t.replacementEnvelope,fetchImpl:e.fetchImpl});return n.kind===`promoted`?{kind:`google_email_otp`,payload:t,promotion:n}:n}function dn(e){return e.kind===`passkey`||e.kind===`google_email_otp`}async function fn(e){let t=await un(e);return dn(t)||t.kind!==`refused`?t:await cn(e)}function pn(e,t){return{walletId:e.walletId,factor:{kind:`passkey`,credentialIdB64u:t.target.credentialIdB64u},verifier:{kind:`webauthn`,rpId:t.target.rpId},bindingId:t.authMethod.walletAuthMethodId}}function mn(e,t){let n=be({walletId:e.walletId,provider:`google`,providerUserId:e.providerSubject,emailHashHex:e.emailHashHex});return{walletId:n.walletId,factor:n.factor,verifier:n.verifier,bindingId:t.authMethod.walletAuthMethodId}}async function hn(e,t){if(U(e)){if(t.kind!==`passkey`)throw Error(`wallet recovery projection branch changed`);return ue({authority:pn(e,t)})}if(t.kind!==`google_email_otp`)throw Error(`wallet recovery projection branch changed`);return ue({authority:mn(e,t)})}async function gn(e){let t=[],n=[];for(let r of e.payload.ecdsaKeySets){let i=r.entry,a=i.recoveryBasis,o=await le({walletId:e.payload.walletId,signingRootId:a.signingRootId,signingRootVersion:a.signingRootVersion}),s=await Ee({authority:e.authority,chainTargets:a.chainTargets,walletId:String(e.payload.walletId),keyHandle:i.keyHandle,ecdsaThresholdKeyId:a.ecdsaThresholdKeyId,signingRootId:a.signingRootId,signingRootVersion:a.signingRootVersion,relayerKeyId:o,participantIds:a.participantIds,publicCapability:a.publicCapability,activationReceipt:a.activationReceipt,runtimePolicyScope:a.runtimePolicyScope,readyStateBlobB64u:r.readyStateBlobB64u,publicFacts:r.publicFacts});n.push(s);for(let n of a.chainTargets)t.push(_n({payload:e.payload,keySet:r,chainTarget:n,materialRef:s.roleLocalMaterialRef,relayerKeyId:o}))}return{walletKeys:t,ecdsaContinuity:n}}function _n(e){let t=e.keySet.entry,n=t.recoveryBasis,r=e.keySet.publicFacts,i=we({walletId:e.payload.walletId,chainTarget:e.chainTarget,keyHandle:t.keyHandle,ecdsaThresholdKeyId:n.ecdsaThresholdKeyId,signingRootId:n.signingRootId,signingRootVersion:n.signingRootVersion,applicationBindingDigestB64u:n.publicCapability.context.application_binding_digest_b64u,clientParticipantId:1,relayerParticipantId:2,participantIds:n.participantIds,contextBinding32B64u:r.contextBinding32B64u,derivationClientSharePublicKey33B64u:r.derivationClientSharePublicKey33B64u,relayerPublicKey33B64u:r.relayerPublicKey33B64u,groupPublicKey33B64u:r.groupPublicKey33B64u,ethereumAddress:r.ethereumAddress,publicCapability:n.publicCapability});return{keyScope:`evm-family`,chainTarget:e.chainTarget,walletId:String(e.payload.walletId),evmFamilySigningKeySlotId:t.evmFamilySigningKeySlotId,keyHandle:t.keyHandle,ecdsaThresholdKeyId:n.ecdsaThresholdKeyId,signingRootId:n.signingRootId,signingRootVersion:n.signingRootVersion,thresholdEcdsaPublicKeyB64u:r.groupPublicKey33B64u,thresholdOwnerAddress:r.ethereumAddress,relayerKeyId:e.relayerKeyId,relayerVerifyingShareB64u:r.relayerPublicKey33B64u,participantIds:n.participantIds,publicCapability:n.publicCapability,roleLocalMaterialRef:e.materialRef,ecdsaRoleLocalPublicFacts:i}}function vn(e){if(e.nearKeySets.length!==1)throw Error(`wallet recovery requires exactly one NEAR key set`);return e.nearKeySets[0]}function yn(e){return[...e.registration.response.transports]}function bn(e){return`ed25519:${re(T(vn(e).binding.registeredPublicKeyB64u))}`}function xn(e,t){let n=i(t.thresholdSessionId);if(!n.ok)throw Error(`recovery NEAR threshold session id is invalid`);return{walletId:e.walletId,nearAccountId:A(t.binding.nearAccountId),thresholdSessionId:n.value,runtimePolicyScope:t.runtimePolicyScope,materialActivation:he(t.materialActivation)}}async function Sn(e){if(U(e.payload)){if(e.projection.kind!==`passkey`)throw Error(`wallet recovery projection branch changed`);let t={walletId:e.payload.walletId,rpId:e.projection.target.rpId,credentialIdB64u:e.projection.target.credentialIdB64u,credentialPublicKeyB64u:e.projection.authMethod.credentialPublicKeyB64u,transports:yn(e.payload),walletKeys:e.walletKeys};if(e.payload.nearKeySets.length===0)return ae({kind:`evm_family_ecdsa`,...t});let n=vn(e.payload);return ae({kind:`near_ed25519`,...t,nearAccountId:A(n.binding.nearAccountId),nearEd25519SigningKeyId:n.binding.nearEd25519SigningKeyId,signerSlot:n.binding.signerSlot,operationalPublicKey:bn(e.payload),relayerKeyId:n.binding.signingWorkerId,participantIds:n.binding.participantIds,custodyMaterials:e.payload.nearKeySets.map(e=>({binding:e.binding,sealed:e.sealed}))})}if(e.projection.kind!==`google_email_otp`)throw Error(`wallet recovery projection branch changed`);let t=mn(e.payload,e.projection),n={walletId:e.payload.walletId,email:e.payload.verifiedEmail,registrationAuthorityId:e.payload.registrationAuthorityId,authority:t,walletKeys:e.walletKeys};if(e.payload.nearKeySets.length===0)return oe({kind:`evm_family_ecdsa`,...n});let r=vn(e.payload);return oe({kind:`near_ed25519`,...n,nearAccountId:A(r.binding.nearAccountId),nearEd25519SigningKeyId:r.binding.nearEd25519SigningKeyId,signerSlot:r.binding.signerSlot,operationalPublicKey:bn(e.payload),relayerKeyId:r.binding.signingWorkerId,participantIds:r.binding.participantIds,custodyMaterials:e.payload.nearKeySets.map(e=>({binding:e.binding,sealed:e.sealed}))})}async function Cn(e){let t=e.pending.projection,n=await hn(e.payload,t),r=await gn({payload:e.payload,authority:n}),i=await Sn({payload:e.payload,projection:t,walletKeys:r.walletKeys});await N.publishPendingWalletRecoveryCommit({pending:e.pending,authority:t.authority,authMethod:t.authMethod,registration:i,ecdsaContinuity:r.ecdsaContinuity,ed25519PublicCapabilityReferences:e.payload.nearKeySets.map(t=>xn(e.payload,t))})}async function wn(e){let t=await N.listPendingWalletRecoveryCommits(),n=[];for(let r of t)try{let t=await It(r),i=r.stage===`awaiting_server_promotion`?await fn({relayUrl:e.relayUrl,payload:t,fetchImpl:e.fetchImpl}):await un({relayUrl:e.relayUrl,payload:t,fetchImpl:e.fetchImpl});if(!dn(i)){if(i.kind===`refused`){await N.deletePendingWalletRecoveryCommit(r.recoveryOperationId),n.push({kind:`discarded`,recoveryOperationId:String(r.recoveryOperationId)});continue}n.push({kind:`pending`,recoveryOperationId:String(r.recoveryOperationId),failure:i});continue}let a=i,o=an(a),s=r.stage===`awaiting_server_promotion`?await N.advancePendingWalletRecoveryCommit({awaiting:r,promoted:Vt(r,a.payload,o,r.updatedAtMs+1)}):r;if(r.stage===`server_promoted`&&!await nn(r.projection,o))throw Error(`wallet recovery replay projection changed`);await Cn({pending:s,payload:a.payload}),n.push({kind:`completed`,recoveryOperationId:String(r.recoveryOperationId)})}catch(e){console.warn(`[SeamsWeb] pending wallet recovery replay failed before classification:`,String(r.recoveryOperationId),e instanceof Error?e.message:String(e||`unknown error`)),n.push({kind:`corrupt`,recoveryOperationId:String(r.recoveryOperationId)})}return n}async function Tn(e){let t=await Mt(e.operation);return{payload:t,pending:Bt(t,await Ft(t),e.nowMs)}}async function En(e){let t=an(e.promotion);return N.advancePendingWalletRecoveryCommit({awaiting:e.awaiting,promoted:Vt(e.awaiting,e.promotion.payload,t,e.awaiting.updatedAtMs+1)})}export{Gt as a,U as c,Le as d,wn as i,st as l,En as n,Wt as o,Cn as r,Ut as s,Tn as t,Ie as u};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./prfCache-DCkuB8Lu.js";function t(t){return{hydrateSigningSession:n=>e(t.getWarmSessionMaterialWriter(),n)}}export{t as createWarmSessionHydrationService};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./domainIds-BzkGsRqO.js";import{c as t,u as n}from"./chains-C_X_fNuS.js";import{i as r,r as i}from"./base64-DW79QA0h.js";import{r as a}from"./secureRandomId-LwBFx84B.js";import{o}from"./sessionPolicy-CBTZQe1n.js";import{g as s}from"./capabilityKinds-N8xo_IEh.js";import{r as c}from"./canonicalPrimitives-Dsbsxgxc.js";import{c as l,o as u}from"./ecdsaChainTarget-DJBXHzbH.js";import{i as d,n as f}from"./signerDomain-DqLCvI-D.js";import{$ as p,C as m,J as h,Kt as g,N as _,Nt as v,Ot as y,T as b,Z as ee,en as x,h as te,tn as S,v as C}from"./emailOtpEcdsaDerivationIdentity-p0C1CQva.js";import{B as ne,C as re,E as w,I as ie,R as ae,S as oe,x as se,y as ce,z as le}from"./ecdsaCapabilityManifest-ChszYCC0.js";import{t as ue}from"./signerSlot-B4Eq8Oe2.js";import{r as T}from"./types-WGrFMQSw.js";import{o as de}from"./walletSessionAuthorizationStore-BiKGIBWQ.js";import{t as fe}from"./thresholdEcdsa-D-QMyevW.js";import{p as pe}from"./nearEd25519YaoSigningPreparation-Eiq_ikXk.js";import{a as me,i as he,r as ge}from"./walletSessionAuthorizationProjection-DuU6w0FP.js";import{a as _e,d as ve,i as ye,n as be,u as xe}from"./ecdsaDerivationClientWasm-CpH-b3jx.js";import{a as Se,r as Ce,t as we}from"./walletSessionFailure-YuhraC3P.js";import{a as E,o as D}from"./signingQueue-2pr7lAUS.js";import{t as O}from"./bytes-DZRW2UDg.js";const Te=`router-ab-ed25519-yao-seed-export-v1`;function Ee(e){if(typeof e!=`object`||!e||Array.isArray(e))return null;let t=e,n=typeof t.id==`string`&&t.id.trim()?t.id.trim():void 0;return t.success===!0&&`data`in t&&t.error===void 0?{id:n,success:!0,data:t.data}:t.success===!1&&typeof t.error==`string`&&t.data===void 0?{id:n,success:!1,error:t.error}:null}var k=class extends Error{constructor(e){super(`[OwnerLaneScope] ${e}`),this.name=`OwnerLaneScopeIntegrityError`}},De=class extends Error{constructor(e){super(`[OwnerLaneScope] relink_required: no active canonical wallet auth method (${e})`),this.code=`relink_required`,this.reason=`missing_canonical_owner_binding`,this.name=`OwnerRelinkRequiredError`}};function Oe(e){return e instanceof De&&e.name===`OwnerRelinkRequiredError`&&e.code===`relink_required`}function ke(e){return{walletId:e.walletId,factor:{kind:`passkey`,credentialIdB64u:e.credentialIdB64u},verifier:{kind:`webauthn`,rpId:e.rpId},bindingId:e.walletAuthMethodId}}function Ae(e){let t=String(e.providerSubjectId||``).trim();if(!t)throw new k(`active Email OTP method has no exact local factor`);let n=y({walletId:e.authMethod.walletId,factor:{kind:`email_otp`,provider:t.startsWith(`google:`)?`google`:`email`,providerUserId:t},verifier:{kind:`email_otp_wallet_auth_method`,emailHashHex:e.authMethod.emailHashHex},bindingId:e.authMethod.walletAuthMethodId});if(!n)throw new k(`active Email OTP method has no exact local factor`);return n}function je(e){let t=e.localMethods.filter(t=>t.kind===`email_otp`&&t.status===`active`&&t.walletId===e.authMethod.walletId&&t.emailHashHex===e.authMethod.emailHashHex),n=t[0],r=n?y(n.authority):null;if(t.length!==1||!r||r.walletId!==e.authMethod.walletId||r.bindingId!==e.authMethod.walletAuthMethodId||r.verifier.emailHashHex!==e.authMethod.emailHashHex)throw new k(`active Email OTP method has no exact local factor`);return r}async function A(e){let t=String(e.authMethod.walletId);try{return je({authMethod:e.authMethod,localMethods:await e.stores.listWalletAuthMethodsForWallet(t)})}catch(n){if(!e.stores.readEmailOtpProviderSubjectForWallet)throw n;let r=await e.stores.readEmailOtpProviderSubjectForWallet(t);if(!r)throw n;return Ae({authMethod:e.authMethod,providerSubjectId:r})}}function Me(e){if(e.authority.walletId!==e.authMethod.walletId||e.authority.bindingId!==e.authMethod.walletAuthMethodId)throw new k(`active wallet auth method does not have an exact factor authority binding`);return e.authority}async function Ne(e){return e.authMethod.kind===`passkey`?Me({authMethod:e.authMethod,authority:ke(e.authMethod)}):Me({authMethod:e.authMethod,authority:await A({authMethod:e.authMethod,stores:e.stores})})}function Pe(e){return{auth:{kind:`passkey`,rpId:b(e.authMethod.rpId),credentialIdB64u:e.authMethod.credentialIdB64u},signerSlot:e.signerSlot}}function Fe(e){return{auth:{kind:`passkey`,rpId:b(e.authMethod.rpId),credentialIdB64u:e.authMethod.credentialIdB64u},keyFamily:`ecdsa`}}function Ie(e){if(e.factorAuthority.walletId!==e.authMethod.walletId||e.factorAuthority.bindingId!==e.authMethod.walletAuthMethodId||e.factorAuthority.verifier.emailHashHex!==e.authMethod.emailHashHex||e.authorityRef.walletId!==e.authMethod.walletId||e.authorityRef.walletAuthMethodId!==e.authMethod.walletAuthMethodId)throw new k(`linked Email OTP authority does not match the selected V2 method`);return{auth:{kind:`email_otp`,providerSubjectId:String(e.factorAuthority.factor.providerUserId)},ownerAuthority:{walletAuthMethodId:e.authorityRef.walletAuthMethodId,authorityDigest:e.authorityRef.authorityDigest}}}async function Le(e){let t=await e.stores.getWalletPasskeyAuthenticator({walletId:String(e.authMethod.walletId),credentialId:e.authMethod.credentialIdB64u});if(!t||t.credentialId!==e.authMethod.credentialIdB64u)throw new k(`active Passkey auth method has no exact local authenticator`);let n=ue(t.signerSlot,{min:1});if(n===null)throw new k(`local authenticator signer slot is invalid`);return Pe({authMethod:e.authMethod,signerSlot:n})}async function Re(e){if(e.authMethod.kind===`passkey`)return await Le({authMethod:e.authMethod,stores:e.stores});let t=await A({authMethod:e.authMethod,stores:e.stores}),n=await v({authority:t});return{auth:{kind:`email_otp`,providerSubjectId:String(t.factor.providerUserId)},ownerAuthority:{walletAuthMethodId:n.walletAuthMethodId,authorityDigest:n.authorityDigest}}}function j(e){return e.kind===`credential_free_ecdsa_session_activation_authorization_v1`}function ze(e,t){return e.error||e.message||e.code||t}function M(e){return p({kind:`router_ab_ecdsa_post_registration_session_activation_v1`,public_capability:e.publicCapability,session_policy:{threshold_session_id:e.thresholdSessionId,wallet_session_mint_id:e.walletSessionMintId,ttl_ms:e.ttlMs,remaining_uses:e.remainingUses,runtime_policy_scope:e.runtimePolicyScope}})}function Be(e,t){let n=t.public_identity;return e.applicationBindingDigestB64u===t.context.application_binding_digest_b64u&&e.contextBinding32B64u===n.context_binding_b64u&&e.derivationClientSharePublicKey33B64u===n.derivation_client_share_public_key33_b64u&&e.relayerPublicKey33B64u===n.server_public_key33_b64u&&e.groupPublicKey33B64u===n.threshold_public_key33_b64u&&e.ethereumAddress.toLowerCase()===O(i(n.ethereum_address20_b64u))&&ce(e.publicCapability,t)}function Ve(e,t){let n=e.normal_signing.scope;return n.wallet_id===String(t.walletId)&&n.ecdsa_threshold_key_id===String(t.ecdsaThresholdKeyId)&&n.signing_root_id===String(t.signingRootId)&&n.signing_root_version===String(t.signingRootVersion)}function N(e){let t=e.persistedRoleLocalMaterial.publicFacts;if(!ce(e.sessionActivation.public_capability,e.publicCapability)||e.sessionActivation.session.threshold_session_id!==e.thresholdSessionId||!Ve(e.sessionActivation,t))throw Error(`Strict ECDSA session activation returned a different registered key identity`)}function He(t){let n=t.sessionActivation.activation,r=t.sessionActivation.authorization,i=r.record,a=x(n.public_capability.material_activation),o=0;for(let t of i.capabilitySubjects)t.kind===`sign`&&t.keyFamily===`ecdsa_secp256k1`&&e(t.materialActivation,a)&&(o+=1);if(N({publicCapability:t.publicCapability,persistedRoleLocalMaterial:t.persistedRoleLocalMaterial,thresholdSessionId:t.thresholdSessionId,sessionActivation:n}),String(i.walletId)!==t.walletId||String(i.walletId)!==String(n.public_capability.client_id)||i.authMethodId!==t.persistedRoleLocalMaterial.authority.walletAuthMethodId||i.authorizationId!==n.session.authorization_id||i.quotaId!==n.session.quota_id||i.expiresAtMs!==n.session.expires_at_ms||n.session.remaining_uses!==t.remainingUses||r.operationCredential.walletSessionId!==n.session.wallet_session_id||!e(a,t.persistedRoleLocalMaterial.materialActivation)||o!==1)throw Error(`Strict ECDSA credential-free activation authority does not match its session`)}function P(e){let t=e.persistedRoleLocalMaterial.publicFacts;if(!e.walletId||!e.thresholdSessionId)throw Error(`Strict ECDSA session activation requires exact wallet and session identity`);if(!Number.isSafeInteger(e.ttlMs)||e.ttlMs<1)throw Error(`Strict ECDSA session activation requires a positive ttlMs`);if(!Number.isSafeInteger(e.remainingUses)||e.remainingUses<1)throw Error(`Strict ECDSA session activation requires positive remainingUses`);if(String(t.walletId)!==e.walletId||!Be(t,e.publicCapability))throw Error(`Strict ECDSA session activation requires exact registered role-local material`)}function Ue(e){switch(e.kind){case`rehydrated`:return e;case`device_link_required`:throw Error(`device_link_required: registered ECDSA role-local material is unavailable on this device`);case`corrupt`:throw Error(`Registered ECDSA role-local material is corrupt (${e.reason}): ${e.message}`);default:{let t=e;throw Error(`Unsupported ECDSA role-local material resolution: ${String(t)}`)}}}async function F(e){let t=Ue(await D({purpose:`registration_activation`,source:E(e.persistedRoleLocalMaterial),workerCtx:e.workerCtx}));return{kind:`existing_ecdsa_role_local_material_activated_v1`,roleLocalMaterial:t.liveHandle,roleLocalMaterialRef:t.materialRef,publicFacts:e.persistedRoleLocalMaterial.publicFacts,publicCapability:e.publicCapability}}async function We(e){P(e);let t=await fe(e.relayerUrl,{auth:e.routeAuth,request:M(e)});if(!t.ok)throw Error(ze(t,`Strict ECDSA session activation failed`));return await I({workerCtx:e.workerCtx,publicCapability:e.publicCapability,persistedRoleLocalMaterial:e.persistedRoleLocalMaterial,walletId:e.walletId,thresholdSessionId:e.thresholdSessionId,ttlMs:e.ttlMs,remainingUses:e.remainingUses,runtimePolicyScope:e.runtimePolicyScope,sessionActivation:t.value})}async function I(e){return P(e),N({publicCapability:e.publicCapability,persistedRoleLocalMaterial:e.persistedRoleLocalMaterial,thresholdSessionId:e.thresholdSessionId,sessionActivation:e.sessionActivation}),{sessionActivation:e.sessionActivation,roleLocalActivation:await F(e)}}async function Ge(e){return P(e),He(e),{sessionActivation:e.sessionActivation.activation,authorization:e.sessionActivation.authorization,roleLocalActivation:await F(e)}}async function Ke(e,t){let n=o(e.lanePolicy.runtimePolicyScope);if(!n)throw Error(`Strict ECDSA session activation requires runtimePolicyScope`);let r={workerCtx:e.workerCtx,publicCapability:e.publicCapability,persistedRoleLocalMaterial:e.existingRoleLocalMaterial,walletId:String(e.key.walletId),thresholdSessionId:e.lanePolicy.thresholdSessionId,ttlMs:e.lanePolicy.ttlMs,remainingUses:e.lanePolicy.remainingUses,runtimePolicyScope:n},s=e.sessionActivation?j(e.sessionActivation)?await Ge({...r,sessionActivation:e.sessionActivation}):await I({...r,sessionActivation:e.sessionActivation}):await We({...r,walletSessionMintId:qe(),relayerUrl:e.relayerUrl,routeAuth:e.bootstrapAuth}),c=s.sessionActivation.public_capability.public_identity,l=`authorization`in s?{thresholdSessionId:s.sessionActivation.session.threshold_session_id,authorizationSessionId:s.sessionActivation.session.authorization_session_id,authorizationId:s.sessionActivation.session.authorization_id,walletSessionId:s.sessionActivation.session.wallet_session_id,quotaId:s.sessionActivation.session.quota_id,expiresAtMs:s.sessionActivation.session.expires_at_ms,remainingUses:s.sessionActivation.session.remaining_uses,walletSession:s.authorization.record,operationCredential:s.authorization.operationCredential}:{thresholdSessionId:s.sessionActivation.session.threshold_session_id,authorizationSessionId:s.sessionActivation.session.authorization_session_id,authorizationId:s.sessionActivation.session.authorization_id,walletSessionId:s.sessionActivation.session.wallet_session_id,quotaId:s.sessionActivation.session.quota_id,expiresAtMs:s.sessionActivation.session.expires_at_ms,remainingUses:s.sessionActivation.session.remaining_uses,walletSession:s.sessionActivation.session.wallet_session,operationCredential:s.sessionActivation.session.operation_credential},u=await g({walletId:String(e.key.walletId),signingRootId:e.key.signingRootId,signingRootVersion:e.key.signingRootVersion});return{ok:!0,bootstrapKind:`strict_post_registration`,keygenSessionId:String(e.requestId||``).trim()||a(`tecdsa-keygen`,32,`threshold ECDSA session IDs`),rpId:t,keyHandle:String(e.keyHandle),clientVerifyingShareB64u:c.derivation_client_share_public_key33_b64u,thresholdEcdsaPublicKeyB64u:c.threshold_public_key33_b64u,ethereumAddress:O(i(c.ethereum_address20_b64u)),relayerKeyId:u,relayerVerifyingShareB64u:c.server_public_key33_b64u,participantIds:e.key.participantIds.map(Number),thresholdSessionId:l.thresholdSessionId,authorizationSessionId:l.authorizationSessionId,authorizationId:l.authorizationId,walletSessionId:l.walletSessionId,quotaId:l.quotaId,expiresAtMs:l.expiresAtMs,remainingUses:l.remainingUses,runtimePolicyScope:n,signingRootId:String(e.key.signingRootId),signingRootVersion:String(e.key.signingRootVersion),walletSession:l.walletSession,operationCredential:l.operationCredential,roleLocalActivation:s.roleLocalActivation,routerAbEcdsaDerivationNormalSigning:s.sessionActivation.normal_signing,secretSourceKind:`persisted_role_local`}}function qe(){let e=s(a(`wallet-session-mint`,32,`Wallet Session mint IDs`));if(!e.ok)throw Error(`Failed to create Wallet Session mint identity`);return e.value}async function Je(e){let t=e.touchIdPrompt.getRpId();if(!t)return{ok:!1,code:`invalid_args`,message:`Missing rpId for WebAuthn`};try{return await Ke(e,t)}catch(e){return{ok:!1,code:`strict_post_registration_failed`,message:e instanceof Error?e.message:String(e)}}}const L=`stale_ecdsa_key_identity`;function Ye(e){if(!e)throw Error(`Strict ECDSA session bootstrap requires Wallet Session authority`);switch(e.kind){case`opaque_wallet_session_operation_credential_v1`:return e;case`publishable_key`:throw Error(`Strict ECDSA session bootstrap requires Wallet Session authority`)}throw Error(`Strict ECDSA session bootstrap authority is invalid`)}function Xe(e){let t=String(e.code||``).trim(),n=String(e.message||``).trim().toLowerCase();return t===`stale_session_state`&&n.includes(`threshold-ecdsa bootstrap`)&&n.includes(`client verifying share`)&&n.includes(`integrated key record`)}function Ze(e){let t=String(e.message||e.code||`threshold-ecdsa bootstrap failed`).trim(),n=Xe(e)?L:String(e.code||`threshold_ecdsa_bootstrap_failed`).trim()||`threshold_ecdsa_bootstrap_failed`,r=Error(t||`threshold-ecdsa bootstrap failed`);return r.code=n,r}function Qe(e){let t=Error(e);return t.code=L,t}function $e(e){switch(e.authKind){case`email_otp`:return`email_otp`;case`passkey`:return`passkey`}return`unknown`}function et(e){switch(e.bootstrap.secretSourceKind){case`persisted_role_local`:return e.request.authKind===`email_otp`?se({authSubjectId:e.request.emailOtpWorkerSessionHandle.authSubjectId}):oe({credentialIdB64u:e.request.passkeyCredentialIdB64u,rpId:e.bootstrap.rpId})}}function R(e,t){let n=String(e||``).trim().toLowerCase();if(!/^0x[0-9a-f]{40}$/.test(n))throw Error(`threshold-ecdsa exact activation returned invalid ${t}`);return n}function tt(e){let t=R(e.bootstrapOwnerAddress,`server owner address`);if(t!==R(e.key.thresholdOwnerAddress,`key owner address`))throw Qe(`threshold-ecdsa exact activation owner address mismatches server bootstrap result`);return t}async function nt(e,t){let n=l(String(t.key.walletId)),r=t.lanePolicy.chainTarget,i=String(t.lanePolicy.thresholdSessionId).trim();if(e.routerAbNormalSigning.mode!==`enabled`)throw Error(`Router A/B ECDSA derivation normal signing must be enabled for activation`);let a={walletId:n,chainTarget:r,targetKey:u(r),operationId:i||null,authMethod:$e(t),evmFamilyKeyFingerprint:te(t.key),keyHandle:t.keyHandle,chainTargetKey:u(r),ecdsaThresholdKeyId:String(t.key.ecdsaThresholdKeyId),thresholdSessionId:i||null,freshAuthRetrySideEffectState:`not_applicable`,hasRequestedEcdsaThresholdKeyId:!0,requestedSessionId:i||null,authKind:t.walletSessionRouteAuth?.kind||`none`,passkeyCredentialBound:t.authKind===`passkey`},o;try{o=await Je({touchIdPrompt:e.touchIdPrompt,relayerUrl:t.relayerUrl,requestId:t.requestId,workerCtx:e.workerCtx,...`preauthorizedSessionActivation`in t&&t.preauthorizedSessionActivation?{sessionActivation:t.preauthorizedSessionActivation}:{bootstrapAuth:Ye(t.walletSessionRouteAuth)},keyHandle:t.keyHandle,key:t.key,lanePolicy:t.lanePolicy,publicCapability:t.publicCapability,existingRoleLocalMaterial:t.existingRoleLocalMaterial})}catch(e){try{console.warn(`[threshold-ecdsa][bootstrap][exception]`,{...a,message:e instanceof Error?e.message:String(e)})}catch{}throw e}if(!o.ok){try{console.warn(`[threshold-ecdsa][bootstrap][failure]`,{...a,code:o.code||``,message:o.message||``})}catch{}throw Ze({code:o.code,message:o.message})}let s=String(t.key.ecdsaThresholdKeyId).trim();if(!s)throw Error(`threshold-ecdsa bootstrap returned empty ecdsaThresholdKeyId`);let c=ie(s),d=le(String(o.keyHandle||``).trim()),f=String(o.relayerKeyId||``).trim();if(!f)throw Error(`threshold-ecdsa bootstrap returned empty relayerKeyId`);let p=ne(f),m=String(o.clientVerifyingShareB64u||``).trim();if(!m)throw Error(`threshold-ecdsa bootstrap returned empty clientVerifyingShareB64u`);let h=ae(m),g=String(o.thresholdSessionId||``).trim();if(!g)throw Error(`threshold-ecdsa bootstrap returned empty thresholdSessionId`);let _=Number(o.expiresAtMs);if(!Number.isFinite(_))throw Error(`threshold-ecdsa bootstrap returned invalid expiresAtMs`);let v=Number(o.remainingUses);if(!Number.isFinite(v))throw Error(`threshold-ecdsa bootstrap returned invalid remainingUses`);let y=t.key.participantIds.map(e=>Number(e));if(!y)throw Error(`threshold-ecdsa bootstrap returned empty participantIds`);let b=tt({key:t.key,bootstrapOwnerAddress:o.ethereumAddress}),ee=re({walletId:n,chainTarget:r,keyHandle:d,ecdsaThresholdKeyId:c,signingRootId:o.signingRootId,signingRootVersion:o.signingRootVersion,applicationBindingDigestB64u:o.roleLocalActivation.publicCapability.context.application_binding_digest_b64u,clientParticipantId:1,relayerParticipantId:2,participantIds:y,contextBinding32B64u:o.roleLocalActivation.publicFacts.contextBinding32B64u,derivationClientSharePublicKey33B64u:o.roleLocalActivation.publicFacts.derivationClientSharePublicKey33B64u,relayerPublicKey33B64u:o.roleLocalActivation.publicFacts.relayerPublicKey33B64u,groupPublicKey33B64u:o.roleLocalActivation.publicFacts.groupPublicKey33B64u,ethereumAddress:o.roleLocalActivation.publicFacts.ethereumAddress,publicCapability:o.roleLocalActivation.publicCapability}),x=o.routerAbEcdsaDerivationNormalSigning,S=o.roleLocalActivation.roleLocalMaterial,C=et({request:t,bootstrap:o}),w={ok:!0,thresholdSessionId:g,authorizationSessionId:o.authorizationSessionId,authorizationId:o.authorizationId,walletSessionId:o.walletSessionId,quotaId:o.quotaId,expiresAtMs:_,remainingUses:v,runtimePolicyScope:o.runtimePolicyScope,walletSession:o.walletSession,operationCredential:o.operationCredential,clientVerifyingShareB64u:h};return{thresholdEcdsaKeyRef:{type:`threshold-ecdsa-secp256k1`,userId:n,chainTarget:r,relayerUrl:t.relayerUrl,keyHandle:d,ecdsaThresholdKeyId:c,backendBinding:{materialKind:`role_local_worker_handle`,relayerKeyId:p,clientVerifyingShareB64u:h,roleLocalMaterialHandle:S,roleLocalMaterialRef:o.roleLocalActivation.roleLocalMaterialRef,publicFacts:ee,authMethod:C},participantIds:y,thresholdEcdsaPublicKeyB64u:o.thresholdEcdsaPublicKeyB64u,ethereumAddress:b,relayerVerifyingShareB64u:o.relayerVerifyingShareB64u,routerAbEcdsaDerivationNormalSigning:x},session:w}}async function rt(e,t){return await nt(e,t)}function it(e){let t;try{t=c(e.evidenceSetDigest)}catch(e){throw Error(e instanceof Error?e.message:`ECDSA explicit export evidence digest is invalid`)}let n=Math.floor(Number(e.expiresAtMs)),r=ee(e.operation);if(r.operation_kind!==`evm.export_key`)throw Error(`ECDSA explicit export operation kind is invalid`);if(!Number.isSafeInteger(n)||n<=Date.now())throw Error(`ECDSA explicit export operation authorization expiry is invalid`);let i=at(e.unseal);return{kind:`verified_step_up`,evidenceSetDigest:t,operation:r,expiresAtMs:n,quotaUse:`none`,unseal:i}}function at(e){switch(e.kind){case`not_requested`:return{kind:`not_requested`};case`email_otp_grant`:{let t=String(e.grant||``).trim(),n=String(e.challenge_id||``).trim();if(!t||!n)throw Error(`ECDSA explicit export Email OTP unseal grant is invalid`);return{kind:`email_otp_grant`,grant:t,challenge_id:n}}default:{let t=e;throw Error(`Unsupported ECDSA explicit export unseal state: ${String(t)}`)}}}async function z(e){let t=String(e.relayerUrl||``).trim();if(!t)throw Error(`ECDSA explicit export relayer URL is required`);return{kind:`explicit_key_export_ecdsa_activation_result`,purpose:`explicit_key_export`,material:{kind:`auth_neutral_ecdsa_export_material_v1`,relayerUrl:t,persistedMaterial:e.existingRoleLocalMaterial},authorization:it(e.authorization)}}function B(e,t){let n=String(e||t||``).trim();if(!n)throw Error(`Missing relayer url (configs.network.relayer.url)`);return n}function V(e){return`key`in e&&!!e.key&&`keyHandle`in e&&!!String(e.keyHandle||``).trim()}function H(e){return V(e)?e.key.walletId:e.walletId}function U(e){return V(e)?e.lanePolicy.chainTarget:e.chainTarget}function ot(e){return e.kind===`email_otp_ecdsa_bootstrap`?{authMethod:f.emailOtp,signerSource:d.emailOtpRegistration}:{authMethod:f.passkey,signerSource:d.passkeyRegistration}}function st(e){switch(e.kind){case`passkey_preauthorized_ecdsa_bootstrap`:case`wallet_session_reconnect_ecdsa_bootstrap`:return e.authorizationAuthority;case`passkey_fresh_ecdsa_bootstrap`:case`email_otp_ecdsa_bootstrap`:return e.existingRoleLocalMaterial.authority}}function ct(e){if(!(`sessionActivation`in e.request)||!e.request.sessionActivation)return;let t=e.request.sessionActivation,n=j(t)?t.activation:t,r=j(t)?t.authorization:{record:t.session.wallet_session,operationCredential:t.session.operation_credential};me({walletId:e.walletId,authority:e.authority,walletSession:r.record,operationCredential:r.operationCredential,expectedAuthorizationId:n.session.authorization_id,expectedWalletSessionId:n.session.wallet_session_id,expectedQuotaId:n.session.quota_id,expectedExpiresAtMs:n.session.expires_at_ms}),e.request.kind===`passkey_preauthorized_ecdsa_bootstrap`&&he({expected:e.request.authorizationIdentity,walletSession:r.record})}function lt(e,t){let n=(e,n,r)=>({kind:`session_bootstrap`,purpose:`transaction_signing`,relayerUrl:t,keyHandle:m(e.keyHandle),key:e.key,lanePolicy:e.lanePolicy,publicCapability:e.publicCapability,existingRoleLocalMaterial:e.existingRoleLocalMaterial,...e.requestId?{requestId:e.requestId}:{},...r,...n?{walletSessionRouteAuth:n}:{}}),r=e=>({kind:`session_bootstrap`,purpose:`transaction_signing`,relayerUrl:t,keyHandle:m(e.keyHandle),key:e.key,lanePolicy:e.lanePolicy,publicCapability:e.publicCapability,existingRoleLocalMaterial:e.existingRoleLocalMaterial,...e.requestId?{requestId:e.requestId}:{},authKind:`passkey`,passkeyCredentialIdB64u:e.passkeyCredentialIdB64u,preauthorizedSessionActivation:e.sessionActivation});switch(e.kind){case`passkey_fresh_ecdsa_bootstrap`:return n(e,e.routeAuth,{authKind:`passkey`,passkeyCredentialIdB64u:e.passkeyCredentialIdB64u});case`passkey_preauthorized_ecdsa_bootstrap`:return r(e);case`wallet_session_reconnect_ecdsa_bootstrap`:return n(e,e.routeAuth,{authKind:`passkey`,passkeyCredentialIdB64u:e.passkeyCredentialIdB64u});case`email_otp_ecdsa_bootstrap`:{let r={authKind:`email_otp`,emailOtpWorkerSessionHandle:e.emailOtpWorkerSessionHandle};return e.sessionActivation?{kind:`session_bootstrap`,purpose:`transaction_signing`,relayerUrl:t,keyHandle:m(e.keyHandle),key:e.key,lanePolicy:e.lanePolicy,publicCapability:e.publicCapability,existingRoleLocalMaterial:e.existingRoleLocalMaterial,...e.requestId?{requestId:e.requestId}:{},...r,preauthorizedSessionActivation:e.sessionActivation}:n(e,e.routeAuth,r)}}throw Error(`[SigningEngine][ecdsa] unsupported ECDSA bootstrap request`)}function ut(e,t){return{purpose:`explicit_key_export`,relayerUrl:t,existingRoleLocalMaterial:e.existingRoleLocalMaterial,authorization:e.authorization}}function dt(e,t){return{purpose:`explicit_key_export`,relayerUrl:t,existingRoleLocalMaterial:e.existingRoleLocalMaterial,authorization:e.authorization}}async function ft(e,t){if(t.kind===`reuse_warm_ecdsa_bootstrap`)throw Error(`[SigningEngine][ecdsa] reuse_warm bootstrap must resolve an existing exact material request before activation`);let n=st(t),r=l(H(t)),i=U(t),a=B(t.relayerUrl,e.defaultRelayerUrl),o=e.getSignerWorkerContext(),s={touchIdPrompt:e.touchIdPrompt,workerCtx:o,routerAbNormalSigning:e.routerAbNormalSigning};ct({request:t,walletId:r,authority:n});let c=await rt(s,lt(t,a)),u=ot(t);return await e.persistThresholdEcdsaBootstrapForWalletTarget({walletId:r,chainTarget:i,bootstrap:c,signerAuth:u}),await t.beforeAuthorizationPersistence?.(),await ge(de,{walletId:r,authority:n,bootstrap:c}),c}async function pt(e,t){return await z(ut(t,B(t.relayerUrl,e.defaultRelayerUrl)))}async function mt(e,t){return await z(dt(t,B(t.relayerUrl,e.defaultRelayerUrl)))}async function W(e,t,n){let r=String(t),i=(e.get(r)||Promise.resolve()).catch(()=>void 0),a,o=new Promise(e=>{a=e}),s=i.then(()=>o);e.set(r,s),await i;try{return await n()}finally{a(),e.get(r)===s&&e.delete(r)}}function ht(e,t){return t.runtimeScopeBootstrap&&(e.runtimeScopeBootstrap=t.runtimeScopeBootstrap),t.operationIntent&&(e.operationIntent=t.operationIntent),typeof t.ttlMs==`number`&&(e.ttlMs=t.ttlMs),e}function G(e){return ht({kind:`email_otp_ecdsa_activation`,purpose:`transaction_signing`,walletKey:e.walletKey,lanePolicy:e.lanePolicy,publicCapability:e.publicCapability,existingRoleLocalMaterial:e.existingRoleLocalMaterial,source:e.source,relayerUrl:e.relayerUrl,sessionIdentity:e.sessionIdentity,sessionKind:e.sessionKind,sessionBudgetUses:e.sessionBudgetUses,runtimePolicy:e.runtimePolicy,emailOtpWorkerSessionHandle:e.emailOtpWorkerSessionHandle,emailOtpAuthContext:e.emailOtpAuthContext,...`preauthorizedSessionActivation`in e?{preauthorizedSessionActivation:e.preauthorizedSessionActivation}:{walletSessionRouteAuth:e.walletSessionRouteAuth}},e)}function K(e){if(pe(e.context)!==e.expected)throw Error(`Email OTP ${e.label} activation requires ${e.expected} retention`)}function gt(e){return K({context:e.emailOtpAuthContext,expected:`session`,label:`session bootstrap`}),G(e)}function _t(e){return K({context:e.emailOtpAuthContext,expected:`session`,label:`recovered session`}),G(e)}function vt(e){return K({context:e.emailOtpAuthContext,expected:`session`,label:`preauthorized session bootstrap`}),G(e)}function yt(e){return K({context:e.emailOtpAuthContext,expected:`single_use`,label:`per-operation reauth`}),G(e)}function bt(e){return{kind:`email_otp_ecdsa_export_activation`,purpose:`explicit_key_export`,existingRoleLocalMaterial:e.existingRoleLocalMaterial,relayerUrl:e.relayerUrl,authorization:e.authorization}}function xt(e){return{kind:`passkey_ecdsa_export_activation`,purpose:`explicit_key_export`,existingRoleLocalMaterial:e.existingRoleLocalMaterial,relayerUrl:e.relayerUrl,authorization:e.authorization}}function St(e){switch(e.kind){case`default_policy`:return;case`scoped_policy`:return e.scope}throw Error(`[SigningEngine][ecdsa] unsupported ECDSA activation policy`)}function q(e,t){t.runtimeScopeBootstrap&&(e.runtimeScopeBootstrap=t.runtimeScopeBootstrap),t.operationIntent&&(e.operationIntent=t.operationIntent);let n=St(t.runtimePolicy);return`walletId`in e&&(typeof t.ttlMs==`number`&&(e.ttlMs=t.ttlMs),n&&(e.runtimePolicyScope=n)),e}function Ct(e){switch(e.kind){case`passkey_ecdsa_activation`:return{kind:`passkey_existing_session_activation`,request:e};case`email_otp_ecdsa_activation`:return{kind:`email_otp_existing_session_activation`,request:e}}throw Error(`[SigningEngine][ecdsa] unsupported activation request`)}function wt(e){let t=String(e.webauthnAuthentication.rawId||e.webauthnAuthentication.id||``).trim();if(!t)throw Error(`[SigningEngine][ecdsa] passkey activation requires credential identity`);return t}function Tt(e){let t=Ct(e);switch(t.kind){case`passkey_existing_session_activation`:return q({kind:`passkey_fresh_ecdsa_bootstrap`,keyHandle:t.request.walletKey.keyHandle,key:C(t.request.walletKey),lanePolicy:t.request.lanePolicy,publicCapability:t.request.publicCapability,existingRoleLocalMaterial:t.request.existingRoleLocalMaterial,source:t.request.source,relayerUrl:t.request.relayerUrl,requestId:t.request.requestId,passkeyCredentialIdB64u:wt(t.request),routeAuth:t.request.walletSessionRouteAuth},t.request);case`email_otp_existing_session_activation`:{let e={kind:`email_otp_ecdsa_bootstrap`,keyHandle:t.request.walletKey.keyHandle,key:C(t.request.walletKey),lanePolicy:t.request.lanePolicy,publicCapability:t.request.publicCapability,existingRoleLocalMaterial:t.request.existingRoleLocalMaterial,source:`email_otp`,relayerUrl:t.request.relayerUrl,emailOtpWorkerSessionHandle:t.request.emailOtpWorkerSessionHandle,emailOtpAuthContext:t.request.emailOtpAuthContext};return t.request.preauthorizedSessionActivation?q({...e,sessionActivation:t.request.preauthorizedSessionActivation},t.request):q({...e,routeAuth:t.request.walletSessionRouteAuth},t.request)}}throw Error(`[SigningEngine][ecdsa] unsupported activation request`)}function Et(e){return{kind:`passkey_ecdsa_export_bootstrap`,purpose:`explicit_key_export`,existingRoleLocalMaterial:e.existingRoleLocalMaterial,relayerUrl:e.relayerUrl,authorization:e.authorization}}async function Dt(e){let t=e.bootstrap.thresholdEcdsaKeyRef.backendBinding;if(!t)throw Error(`[WarmSessionStore] threshold ECDSA bootstrap is missing its backend binding`);let n=Ot(t);if(!n)return;let r=await e.deps.persistEcdsaRoleLocalReadyRecord({record:n,storageKeyFacts:w(n)});if(!r.ok)throw Error(`[WarmSessionStore] threshold ECDSA role-local ready record persistence failed (${r.code}): ${r.message}`)}function Ot(e){switch(e.materialKind){case`role_local_ready_state_blob`:return e.ecdsaRoleLocalReadyRecord;case`role_local_worker_handle`:case`role_local_durable_public_anchor`:case`role_local_durable_sealed_ref`:case`metadata_only`:return null;default:{let t=e;throw Error(`[WarmSessionStore] unsupported threshold ECDSA backend binding: ${JSON.stringify(t)}`)}}}async function J(e,t){let n=l(H(t));return await W(e.queueByWallet,n,async()=>{let n=await ft(e.activationDeps,t);return await Dt({deps:e,bootstrap:n}),n})}async function kt(e,t){return await J(e,Tt(t))}async function At(e,t){return await pt(e.activationDeps,Et(t))}async function jt(e,t){let n={kind:`email_otp_ecdsa_export_bootstrap`,purpose:`explicit_key_export`,existingRoleLocalMaterial:t.existingRoleLocalMaterial,relayerUrl:t.relayerUrl,authorization:t.authorization};return await mt(e.activationDeps,n)}const Y=`ecdsa-derivation:role-local:product-export-confirmation:v5`,X=`ecdsa-derivation:role-local:product-export-authorization:v5`;function Mt(e){return{kind:`operation_step_up`}}function Z(e){return{authorizationKind:e.kind,authorizationId:e.evidenceSetDigest}}function Q(){let e=globalThis.crypto;if(!e||typeof e.getRandomValues!=`function`)throw Error(`crypto.getRandomValues is required for threshold ECDSA export`);return r(e.getRandomValues(new Uint8Array(32)))}async function Nt(e){let t=String(e.relayerUrl||``).trim().replace(/\/+$/g,``);if(!t)throw Error(`[SigningEngine][ecdsa-export] relayer URL is required`);if(e.authorization.kind===`wallet_session_bearer`&&!e.authorization.token.trim())throw Error(`[SigningEngine][ecdsa-export] Wallet Session operation credential is required`);let n={"Content-Type":`application/json`};e.authorization.kind===`wallet_session_bearer`&&(n.Authorization=`Bearer ${e.authorization.token}`);try{let r=await fetch(`${t}${_}`,{method:`POST`,credentials:e.authorization.kind===`legacy_cookie`?`include`:`omit`,headers:n,body:JSON.stringify({request:e.request,requestDigestB64u:e.requestDigestB64u})}),i=await r.json().catch(()=>null);if(!r.ok){let e=i&&typeof i==`object`&&!Array.isArray(i)?i:null;return{ok:!1,code:String(e?.code||`http_error`),message:String(e?.message||`HTTP ${r.status}`)}}return{ok:!0,value:h(i)}}catch(e){return{ok:!1,error:e instanceof Error?e.message:String(e)}}}async function Pt(e){return await Nt({...e,authorization:{kind:`legacy_cookie`}})}async function Ft(e){return await Nt({relayerUrl:e.relayerUrl,request:e.request,requestDigestB64u:e.requestDigestB64u,authorization:{kind:`wallet_session_bearer`,token:e.operationCredential.token}})}function It(e){let t=Math.min(e.issuedAtUnixMs+6e4,e.authorizationExpiresAtMsCeiling??1/0);if(Number.isFinite(t)&&t>e.issuedAtUnixMs)return t;throw new we({failure:Ce(Se.expired),message:`Wallet Session expired before ECDSA export authorization`})}function Lt(e){if(String(e.material.persistedMaterial.publicFacts.walletId)!==String(e.walletSessionUserId))throw Error(`[SigningEngine][ecdsa-export] explicit export wallet mismatch`)}async function $(e){return r(await n(t(e)))}function Rt(e){switch(e.kind){case`rehydrated`:return e;case`device_link_required`:throw Error(`[SigningEngine][ecdsa-export] device_link_required: local threshold ECDSA material is unavailable`);case`corrupt`:throw Error(`[SigningEngine][ecdsa-export] local threshold ECDSA material is corrupt (${e.reason}): ${e.message}`);default:{let t=e;throw Error(`Unsupported ECDSA export material resolution: ${String(t)}`)}}}async function zt(e){return Rt(await D({purpose:`explicit_key_export`,source:E(e.persistedMaterial),workerCtx:e.workerCtx}))}function Bt(e){let t=Z(e.material.operationAuthorization),n=e.material.persistedMaterial.publicFacts;return{version:X,operation:`explicit_key_export`,keyHandle:n.keyHandle,walletId:String(n.walletId),ecdsaThresholdKeyId:e.ecdsaThresholdKeyId,relayerKeyId:n.publicCapability.signer_set.selected_server.server_id,signingRootId:e.signingRootId,signingRootVersion:e.signingRootVersion,contextBinding32B64u:e.contextBinding32B64u,publicIdentity:e.publicIdentity,exportRequestNonce32B64u:e.exportRequestNonce32B64u,confirmationDigest32B64u:e.confirmationDigest32B64u,issuedAtUnixMs:e.issuedAtUnixMs,expiresAtUnixMs:e.expiresAtUnixMs,authorizationKind:t.authorizationKind,authorizationId:t.authorizationId,materialActivation:S(e.material.persistedMaterial.materialActivation),participantIds:n.participantIds}}async function Vt(e,t){let n=t.persistedMaterial.publicFacts,r=S(t.persistedMaterial.materialActivation);switch(t.factorAuthorization.kind){case`passkey`:{let e=String(t.factorAuthorization.credential.rawId||t.factorAuthorization.credential.id||``).trim();if(!e)throw Error(`[SigningEngine][ecdsa-export] passkey authorization credential is missing`);if(e!==t.factorAuthorization.passkeyCredentialIdB64u)throw Error(`[SigningEngine][ecdsa-export] passkey export authorization credential mismatch`);break}case`email_otp_verified`:break;default:{let e=t.factorAuthorization;throw Error(`Unsupported ECDSA export authorization: ${String(e)}`)}}let i=Date.now(),a=It({issuedAtUnixMs:i,authorizationExpiresAtMsCeiling:t.operationAuthorization.expiresAtMs}),o={derivationClientSharePublicKey33B64u:n.derivationClientSharePublicKey33B64u,relayerPublicKey33B64u:n.relayerPublicKey33B64u,groupPublicKey33B64u:n.groupPublicKey33B64u,ethereumAddress:n.ethereumAddress},s=Q(),c=Z(t.operationAuthorization),l=await $({version:Y,walletId:String(n.walletId),ecdsaThresholdKeyId:n.ecdsaThresholdKeyId,relayerKeyId:n.publicCapability.signer_set.selected_server.server_id,contextBinding32B64u:n.contextBinding32B64u,publicIdentity:o,authorizationKind:c.authorizationKind,authorizationId:c.authorizationId,materialActivation:r,exportRequestNonce32B64u:s,issuedAtUnixMs:i,expiresAtUnixMs:a}),u=await $(Bt({ecdsaThresholdKeyId:n.ecdsaThresholdKeyId,signingRootId:n.signingRootId,signingRootVersion:n.signingRootVersion,contextBinding32B64u:n.contextBinding32B64u,publicIdentity:o,exportRequestNonce32B64u:s,confirmationDigest32B64u:l,issuedAtUnixMs:i,expiresAtUnixMs:a,material:t})),d=n.publicCapability,f=`ecdsa-export:${s}`,p=await _e({workerCtx:e.getSignerWorkerContext(),command:{kind:`create_router_ab_ecdsa_explicit_export_ceremony_v1`,ceremonyId:f,request:{context:d.context,lifecycle:{lifecycle_id:f,work_kind:`key_export`,primitive_request_kind:`export`,root_share_epoch:d.activation_epoch,account_id:String(n.walletId),session_id:T.thresholdEcdsaSession(f),signer_set_id:d.signer_set.signer_set_id,selected_server_id:d.signer_set.selected_server.server_id},public_identity:d.public_identity,signer_set:d.signer_set,router_id:d.router_id,client_id:d.client_id,authorization:Mt(t.operationAuthorization),authorization_id:t.operationAuthorization.evidenceSetDigest,operation:t.operationAuthorization.operation,material_activation:r,export_authorization_digest_b64u:u,export_nonce:s,expires_at_ms:a,deriver_recipient_keys:d.deriver_recipient_keys}}});if(p.kind!==`router_ab_ecdsa_explicit_export_ceremony_created_v1`)throw Error(`[SigningEngine][ecdsa-export] strict export ceremony kind mismatch`);try{let i=await Pt({relayerUrl:t.relayerUrl,request:p.request,requestDigestB64u:p.requestDigestB64u});if(!i.ok)throw Error(i.error||i.message||i.code||`Strict ECDSA explicit export request failed`);let a=await ve({workerCtx:e.getSignerWorkerContext(),command:{kind:`finalize_router_ab_ecdsa_explicit_export_v1`,ceremonyId:f,clientProofFinalization:{kind:`finalize_encrypted_client_proof_bundles_v2`,bundles:i.value.response.bundles},signingWorkerExport:i.value.signing_worker_export,authorizationKind:c.authorizationKind,authorizationId:c.authorizationId,materialActivation:r,roleLocalMaterial:t.liveMaterial.liveHandle,roleLocalMaterialRef:t.liveMaterial.materialRef,publicFacts:n}});return{publicKeyHex:a.publicKeyHex,privateKeyHex:a.privateKeyHex,ethereumAddress:a.ethereumAddress}}catch(t){throw await be({workerCtx:e.getSignerWorkerContext(),command:{kind:`close_router_ab_ecdsa_post_registration_ceremony_v1`,ceremonyId:f}}).catch(()=>void 0),t}}async function Ht(e,t){let n=t.exportProvision.material;Lt({material:n,walletSessionUserId:t.walletSessionUserId});let r=String(n.relayerUrl||``).trim();if(!r)throw Error(`[SigningEngine][ecdsa-export] relayer URL is required`);let i=n.persistedMaterial;return await Vt(e,{persistedMaterial:i,liveMaterial:await zt({persistedMaterial:i,workerCtx:e.getSignerWorkerContext()}),relayerUrl:r,operationAuthorization:t.exportProvision.authorization,factorAuthorization:t.factorAuthorization})}function Ut(t){let n=t.runtime.normalSigning.scope,r=t.operationAuthorization.operation,i=x(r.material_activation);if(r.operation_kind!==`evm.export_key`||r.wallet_id!==String(t.runtime.walletId)||r.key_handle!==t.runtime.publicFacts.keyHandle||r.relayer_key_id!==t.runtime.relayerKeyId||r.participant_ids[0]!==t.runtime.publicFacts.participantIds[0]||r.participant_ids[1]!==t.runtime.publicFacts.participantIds[1]||r.signing_worker_id!==n.signing_worker.server_id||r.normal_signing_scope.wallet_id!==n.wallet_id||r.normal_signing_scope.context.application_binding_digest_b64u!==n.context.application_binding_digest_b64u||r.normal_signing_scope.public_identity.context_binding_b64u!==n.public_identity.context_binding_b64u||r.normal_signing_scope.public_identity.threshold_public_key33_b64u!==n.public_identity.threshold_public_key33_b64u||r.normal_signing_scope.signing_worker.server_id!==n.signing_worker.server_id||!e(i,t.runtime.materialActivation)||!e(x(r.normal_signing_scope.material_activation),t.runtime.materialActivation))throw Error(`[SigningEngine][ecdsa-export] active Wallet Authority operation identity changed`)}async function Wt(e,t){Ut(t);let n=t.runtime,r=n.normalSigning.scope;if(t.operationAuthorization.exportTopology.signer_set.selected_server.server_id!==r.signing_worker.server_id)throw Error(`[SigningEngine][ecdsa-export] active export topology changed`);let i=r.material_activation,a=Date.now(),o=It({issuedAtUnixMs:a,authorizationExpiresAtMsCeiling:t.operationAuthorization.expiresAtMs}),s={derivationClientSharePublicKey33B64u:r.public_identity.derivation_client_share_public_key33_b64u,relayerPublicKey33B64u:r.public_identity.server_public_key33_b64u,groupPublicKey33B64u:r.public_identity.threshold_public_key33_b64u,ethereumAddress:n.publicFacts.thresholdOwnerAddress},l=Q(),u=Z(t.operationAuthorization),d=await $({version:Y,walletId:String(n.walletId),ecdsaThresholdKeyId:r.ecdsa_threshold_key_id,relayerKeyId:n.relayerKeyId,contextBinding32B64u:r.public_identity.context_binding_b64u,publicIdentity:s,authorizationKind:u.authorizationKind,authorizationId:u.authorizationId,materialActivation:i,exportRequestNonce32B64u:l,issuedAtUnixMs:a,expiresAtUnixMs:o}),f=await $({version:X,operation:`explicit_key_export`,keyHandle:n.publicFacts.keyHandle,walletId:String(n.walletId),ecdsaThresholdKeyId:r.ecdsa_threshold_key_id,relayerKeyId:n.relayerKeyId,signingRootId:r.signing_root_id,signingRootVersion:r.signing_root_version,contextBinding32B64u:r.public_identity.context_binding_b64u,publicIdentity:s,exportRequestNonce32B64u:l,confirmationDigest32B64u:d,issuedAtUnixMs:a,expiresAtUnixMs:o,authorizationKind:u.authorizationKind,authorizationId:u.authorizationId,materialActivation:i,participantIds:n.publicFacts.participantIds}),p=`ecdsa-export:${l}`,m={context:r.context,lifecycle:{lifecycle_id:p,work_kind:`key_export`,primitive_request_kind:`export`,root_share_epoch:r.activation_epoch,account_id:r.wallet_id,session_id:T.thresholdEcdsaSession(p),signer_set_id:t.operationAuthorization.exportTopology.signer_set.signer_set_id,selected_server_id:t.operationAuthorization.exportTopology.signer_set.selected_server.server_id},public_identity:r.public_identity,signer_set:t.operationAuthorization.exportTopology.signer_set,router_id:t.operationAuthorization.exportTopology.router_id,client_id:String(n.walletId),authorization:Mt(t.operationAuthorization),operation:t.operationAuthorization.operation,authorization_id:c(t.operationAuthorization.evidenceSetDigest),material_activation:i,export_authorization_digest_b64u:f,export_nonce:l,expires_at_ms:o,deriver_recipient_keys:t.operationAuthorization.exportTopology.deriver_recipient_keys},h=await ye({holderHandleId:n.holderRuntime.holderHandleId,request:m,workerCtx:e.getSignerWorkerContext()});if(h.kind!==`ecdsa_holder_ordinary_export_request_created_v1`)throw Error(`[SigningEngine][ecdsa-export] active holder export request kind mismatch`);let g=await Ft({relayerUrl:t.relayerUrl,request:h.request,requestDigestB64u:h.requestDigestB64u,operationCredential:n.operationCredential});if(!g.ok)throw Error(g.error||g.message||g.code||`Active Wallet Authority ECDSA export request failed`);let _={wallet_id:r.wallet_id,key_handle:n.publicFacts.keyHandle,ecdsa_threshold_key_id:r.ecdsa_threshold_key_id,signing_root_id:r.signing_root_id,signing_root_version:r.signing_root_version,activation_epoch:r.activation_epoch,signing_worker_id:r.signing_worker.server_id,context_binding_b64u:r.public_identity.context_binding_b64u,threshold_public_key33_b64u:r.public_identity.threshold_public_key33_b64u,export_request_digest_b64u:h.requestDigestB64u,export_authorization_digest_b64u:f,export_nonce:l,authorization_kind:`verified_step_up`,authorization_id:t.operationAuthorization.evidenceSetDigest,material_activation:i,lifecycle_id:p,recipient_identity:h.request.client_id,recipient_public_key:h.request.client_ephemeral_public_key,expires_at_ms:h.request.expires_at_ms},v=await xe({holderHandleId:n.holderRuntime.holderHandleId,requestDigestB64u:h.requestDigestB64u,expectedBinding:_,forwardedResponse:g.value,workerCtx:e.getSignerWorkerContext()});return{publicKeyHex:v.publicKeyHex,privateKeyHex:v.privateKeyHex,ethereumAddress:v.ethereumAddress}}export{Ne as C,Re as S,Ee as T,j as _,yt as a,Pe as b,gt as c,kt as d,J as f,M as g,H as h,bt as i,jt as l,U as m,Ht as n,vt as o,W as p,xt as r,_t as s,Wt as t,At as u,Fe as v,Te as w,Oe as x,Ie as y};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./domainIds-BzkGsRqO.js";import{c as t}from"./chains-C_X_fNuS.js";import"./primitives-CqrjmIAH.js";import{r as n}from"./secureRandomId-LwBFx84B.js";import"./sessionPolicy-CBTZQe1n.js";import"./signingSessionSeal-DX41aXUL.js";import{t as r}from"./activeWalletSession-WdZkhtBB.js";import"./capabilityKinds-N8xo_IEh.js";import{o as i}from"./canonicalPrimitives-Dsbsxgxc.js";import{i as a,t as o}from"./errors-DIWY1KR9.js";import{d as s,t as c}from"./accountIds-BzZs7YoX.js";import{c as l,o as u,s as ee,u as d}from"./ecdsaChainTarget-DJBXHzbH.js";import"./signerDomain-DqLCvI-D.js";import"./singletons-8UH3gOnZ.js";import"./walletAuthority-BWvfaKIX.js";import{Dt as f,Et as p,Mt as m,a as h,en as te,g,ht as ne,tn as re}from"./emailOtpEcdsaDerivationIdentity-p0C1CQva.js";import{t as ie}from"./challengeDelivery-5lIu9spR.js";import"./digestEncoding-CkUc5vtR.js";import{i as ae}from"./walletAuthMethodRecord-CnBw27ED.js";import"./registrationIds-ByuReLUc.js";import{a as oe,n as _,u as se}from"./sdkSentEvents-Dl8fOL50.js";import{s as ce}from"./types-WGrFMQSw.js";import{i as le}from"./helpers-BnkILY2_.js";import{C as ue,D as v,b as de,j as fe,x as pe}from"./nearEd25519YaoSigningPreparation-Eiq_ikXk.js";import{l as y,u as me}from"./trace-QLsbYdld.js";import{n as he,r as ge,t as _e,w as ve,x as ye}from"./ecdsaDerivationExport-C1cE5m0t.js";import{i as be}from"./walletSessionFailure-YuhraC3P.js";import{i as xe,n as Se,r as Ce,s as we}from"./signingQueue-2pr7lAUS.js";import{h as b,i as x,l as Te,n as Ee,s as S}from"./clientSessionPersistenceState-DRdve9rC.js";import{t as C}from"./types-DhtByIcQ.js";import{i as w}from"./appearance-DITtYj-z.js";import{n as T,t as E}from"./export-viewer-host-DUMwD6zP.js";function D(e){return e.chainTarget.kind}function De(e){return e}function Oe(e){return!e||e.curve!==`ecdsa`||!e.chainTarget||!b(e)||!String(e.publicFacts.keyHandle||``).trim()?!1:e.source===`active_wallet_authority`?e.runtime.requiredCapability===`export_keys`&&e.state===`deferred`&&e.authorizationState===`authorization_required`:e.authorization?!0:e.state===`deferred`}function O(e){if(e.length!==2)throw Error(`[SigningEngine][ecdsa-export] ECDSA participant set must contain two parties`);let t=e[0],n=e[1];if(!Number.isSafeInteger(t)||!Number.isSafeInteger(n)||t<=0||n<=0||t===n)throw Error(`[SigningEngine][ecdsa-export] ECDSA participant set is invalid`);return[t,n]}function k(t){let{exportLane:n,label:r}=t,i=n.capability,a=i.manifest.signer;if(a.walletId!==n.key.walletId||!a.scope.targetMemberships.some(e=>ee(e,n.chainTarget)))throw Error(`[SigningEngine][ecdsa-export] ${r} capability target mismatch`);if(!t.authMatches())throw Error(`[SigningEngine][ecdsa-export] ${r} capability auth mismatch`);if(!e(i.manifest.activation.materialActivation,n.laneIdentity.signer.materialActivation))throw Error(`[SigningEngine][ecdsa-export] ${r} material activation mismatch`);h({expected:n.publicFacts,actual:a.registeredPublicFacts,context:`canonical ${r} export lane`});let o=i.material.publicFacts;if(o.walletId!==a.walletId||String(o.keyHandle)!==String(n.publicFacts.keyHandle)||String(o.groupPublicKey33B64u)!==String(n.publicFacts.publicKeyB64u)||String(o.ethereumAddress)!==String(n.publicFacts.thresholdOwnerAddress)||o.participantIds.length!==n.publicFacts.participantIds.length||o.participantIds.some((e,t)=>e!==n.publicFacts.participantIds[t]))throw Error(`[SigningEngine][ecdsa-export] canonical ${r} export material mismatch`);let s=i.manifest.durableMaterial,c=s.runtimePolicyScope,l=String(t.deps.relayerUrl).trim().replace(/\/+$/g,``);if(!c)throw Error(`[SigningEngine][ecdsa-export] ${r} runtime policy scope is missing`);if(!l)throw Error(`[SigningEngine][ecdsa-export] ${r} export relayer URL is missing`);return{durable:s,runtimePolicyScope:c,relayerUrl:l}}function ke(e){let{exportLane:t}=e,n=t.capability,r=n.authority;if(!p(r))throw Error(`[SigningEngine][ecdsa-export] Email OTP capability authority mismatch`);let{durable:i,runtimePolicyScope:a,relayerUrl:o}=k({deps:e.deps,exportLane:t,label:`Email OTP`,authMatches:()=>t.laneIdentity.auth.kind===`email_otp`&&t.laneIdentity.auth.providerSubjectId===r.factor.providerUserId});return{source:`canonical_capability`,kind:`fresh_email_otp_route_auth_ready`,chainTarget:t.chainTarget,publicFacts:t.publicFacts,runtimePolicyScope:a,persistedMaterial:n.material,normalSigning:i.routerAbEcdsaDerivationNormalSigning,relayerKeyId:String(i.roleLocalBinding.relayerKeyId),participantIds:O(i.roleLocalBinding.participantIds),relayerUrl:o,authorization:{kind:`fresh_operation_authorization_required`,authority:r}}}function Ae(e){let{exportLane:t}=e,n=t.capability,r=n.authority;if(!f(r))throw Error(`[SigningEngine][ecdsa-export] passkey capability authority mismatch`);let{durable:i,runtimePolicyScope:a,relayerUrl:o}=k({deps:e.deps,exportLane:t,label:`passkey`,authMatches:()=>t.laneIdentity.auth.kind===`passkey`&&t.laneIdentity.auth.credentialIdB64u===r.factor.credentialIdB64u});return{source:`canonical_capability`,kind:`fresh_passkey_needs_authorization`,chainTarget:t.chainTarget,publicFacts:t.publicFacts,runtimePolicyScope:a,publicCapability:i.roleLocalPublicFacts.publicCapability,existingRoleLocalMaterial:n.material,normalSigning:i.routerAbEcdsaDerivationNormalSigning,relayerKeyId:String(i.roleLocalBinding.relayerKeyId),participantIds:O(i.roleLocalBinding.participantIds),relayerUrl:o}}function je(t){let{exportLane:n,resolution:r}=t;if(n.laneIdentity.auth.kind!==`email_otp`)throw Error(`[SigningEngine][ecdsa-export] Email OTP runtime auth mismatch`);if(r.runtime.authBinding.kind!==`email_otp`)throw Error(`[SigningEngine][ecdsa-export] Email OTP runtime authority mismatch`);if(n.laneIdentity.auth.providerSubjectId!==r.runtime.authBinding.providerSubjectId)throw Error(`[SigningEngine][ecdsa-export] Email OTP runtime auth mismatch`);if(!e(r.runtime.materialActivation,n.laneIdentity.signer.materialActivation))throw Error(`[SigningEngine][ecdsa-export] Email OTP material activation mismatch`);let i=r.runtime.runtimePolicyScope;if(!i)throw Error(`[SigningEngine][ecdsa-export] Email OTP runtime policy scope is missing`);let a=xe({authority:r.manifest.signer.authority,materialActivation:r.manifest.activation.materialActivation,publicFacts:r.manifest.durableMaterial.roleLocalPublicFacts});return{source:`canonical_capability`,kind:`fresh_email_otp_route_auth_ready`,chainTarget:n.chainTarget,publicFacts:n.publicFacts,runtimePolicyScope:i,persistedMaterial:a,normalSigning:r.runtime.normalSigning,relayerKeyId:r.runtime.relayerKeyId,participantIds:r.runtime.participantIds,relayerUrl:r.runtime.relayerUrl,authorization:{kind:`fresh_operation_authorization_required`,authority:r.runtime.authBinding.emailOtpAuthority}}}function Me(t){let{exportLane:n}=t,r=n.runtime;if(r.requiredCapability!==`export_keys`)throw Error(`[SigningEngine][ecdsa-export] active Wallet Authority lane lacks export_keys capability`);if(r.walletId!==n.key.walletId)throw Error(`[SigningEngine][ecdsa-export] active Wallet Authority wallet mismatch`);if(!e(r.materialActivation,n.laneIdentity.signer.materialActivation))throw Error(`[SigningEngine][ecdsa-export] active Wallet Authority material activation mismatch`);h({expected:n.publicFacts,actual:r.publicFacts,context:`active Wallet Authority ECDSA export lane`});let i=r.normalSigning,a=i.scope;if(a.wallet_id!==String(r.walletId)||a.ecdsa_threshold_key_id!==r.ecdsaThresholdKeyId||a.public_identity.threshold_public_key33_b64u!==r.publicFacts.publicKeyB64u||!e(te(a.material_activation),r.materialActivation))throw Error(`[SigningEngine][ecdsa-export] active Wallet Authority normal-signing identity mismatch`);let o=String(t.deps.relayerUrl).trim().replace(/\/+$/g,``);if(!o)throw Error(`[SigningEngine][ecdsa-export] active Wallet Authority export relayer URL is missing`);let s=O(r.publicFacts.participantIds);if(r.auth.kind===`passkey`){if(!f(r.factorAuthority))throw Error(`[SigningEngine][ecdsa-export] active passkey factor authority mismatch`);if(r.factorAuthority.factor.credentialIdB64u!==r.auth.credentialIdB64u||r.factorAuthority.bindingId!==r.walletAuthMethodId)throw Error(`[SigningEngine][ecdsa-export] active passkey factor identity mismatch`);return{source:`active_wallet_authority`,kind:`active_wallet_authority_passkey_needs_authorization`,chainTarget:n.chainTarget,publicFacts:r.publicFacts,normalSigning:i,relayerKeyId:r.relayerKeyId,participantIds:s,relayerUrl:o,runtime:r,factorAuthority:r.factorAuthority,authMethod:`passkey`}}if(!p(r.factorAuthority))throw Error(`[SigningEngine][ecdsa-export] active Email OTP factor authority mismatch`);if(r.factorAuthority.factor.providerUserId!==r.auth.providerSubjectId||r.factorAuthority.bindingId!==r.walletAuthMethodId)throw Error(`[SigningEngine][ecdsa-export] active Email OTP factor identity mismatch`);return{source:`active_wallet_authority`,kind:`active_wallet_authority_email_otp_needs_authorization`,chainTarget:n.chainTarget,publicFacts:r.publicFacts,normalSigning:i,relayerKeyId:r.relayerKeyId,participantIds:s,relayerUrl:o,runtime:r,factorAuthority:r.factorAuthority,authMethod:`email_otp`}}async function A(e,t){if(t.source!==`canonical_capability`)throw Error(`[SigningEngine][ecdsa-export] active Wallet Authority Email OTP material uses its holder runtime`);if(t.authMethod!==`email_otp`)throw Error(`[SigningEngine][ecdsa-export] fresh Email OTP export requires Email OTP lane`);let n=await e.resolveActiveEcdsaCapabilityRuntime({walletId:t.key.walletId,chainTarget:t.chainTarget});if(n.kind===`blocked`&&n.reason===`missing_material`)return ke({deps:e,exportLane:t});if(n.kind!==`resolved`)throw Error(`[SigningEngine][ecdsa-export] Email OTP capability runtime unavailable: ${n.reason}`);return je({exportLane:t,resolution:n})}async function j(t,n){if(n.source===`active_wallet_authority`)return Me({deps:t,exportLane:n});if(n.authMethod===`email_otp`)return await A(t,n);let r=await t.resolveActiveEcdsaCapabilityRuntime({walletId:n.key.walletId,chainTarget:n.chainTarget});if(r.kind===`blocked`&&r.reason===`missing_material`)return Ae({deps:t,exportLane:n});if(r.kind!==`resolved`)throw Error(`[SigningEngine][ecdsa-export] passkey capability runtime unavailable: ${r.reason}`);if(!e(r.runtime.materialActivation,n.laneIdentity.signer.materialActivation))throw Error(`[SigningEngine][ecdsa-export] passkey material activation mismatch`);if(r.runtime.authBinding.kind!==`passkey`)throw Error(`[SigningEngine][ecdsa-export] passkey authority binding mismatch`);let i=r.manifest.signer.registeredPublicFacts;h({expected:n.publicFacts,actual:i,context:`canonical passkey export lane`});let a=r.runtime.runtimePolicyScope;if(!a)throw Error(`[SigningEngine][ecdsa-export] durable passkey export requires runtimePolicyScope`);return{source:`canonical_capability`,kind:`fresh_passkey_needs_authorization`,chainTarget:n.chainTarget,publicFacts:i,runtimePolicyScope:a,publicCapability:r.manifest.durableMaterial.roleLocalPublicFacts.publicCapability,existingRoleLocalMaterial:xe({authority:r.manifest.signer.authority,materialActivation:r.manifest.durableMaterial.materialActivation,publicFacts:r.manifest.durableMaterial.roleLocalPublicFacts}),normalSigning:r.runtime.normalSigning,relayerKeyId:r.runtime.relayerKeyId,participantIds:r.runtime.participantIds,relayerUrl:r.runtime.relayerUrl}}function Ne(e){return n(e,32,`Email OTP export UI request IDs`)}function Pe(e){switch(e.kind){case`near_account`:return String(c(e.nearAccountId));case`wallet_session`:{let t=String(e.walletId||``).trim();if(!t)throw Error(`Email OTP export requires wallet identity`);return t}default:return e}}function Fe(e){switch(e.kind){case`near_account`:if(!String(e.walletId||``).trim())throw Error(`Email OTP NEAR export requires wallet identity`);return{kind:`near_wallet`,walletId:String(e.walletId).trim(),nearAccountId:String(c(e.nearAccountId))};case`wallet_session`:{let t=String(e.walletId||``).trim();if(!t)throw Error(`Email OTP export requires wallet identity`);return{kind:`evm_wallet`,walletId:t}}default:return e}}function Ie(e){return{challengeId:e.challenge.challengeId,...e.challenge.emailHint?{emailHint:e.challenge.emailHint}:{},title:`Enter email code to export`,body:`This one-time code authorizes private key export only.`,helperText:`Enter the 6-digit code sent to your email`,onResend:e.onResend}}async function M(e){let t=Pe(e.identity),n=async()=>{let t=await e.challengeSource.requestChallenge(),n=String(t.challengeId||``).trim();if(!n)throw Error(`Email OTP export challenge response did not include challengeId`);let r=String(t.emailHint||``).trim();if(!r)throw Error(`Email OTP export challenge response did not include emailHint`);let i={challengeId:n,emailHint:r,delivery:t.delivery};return e.onChallenge?.(i),i},r=await n(),i=Ie({challenge:r,onResend:async()=>(r=await n(),r)}),a=Fe(e.identity),o=await e.confirmer.requestUserConfirmation({requestId:Ne(`export-${e.curve}-email-otp-auth`),type:w.SIGN_INTENT_DIGEST,summary:{operation:`Export Private Key`,accountId:t,publicKey:e.publicKey,warning:`Enter the email code to export this key. Anyone with the private key can fully control the account.`},payload:{signingSubject:a,challengeB64u:r.challengeId,signingAuthPlan:{kind:C.EmailOtpReauth,method:`email_otp`,emailOtpPrompt:i},emailOtpPrompt:i},intentDigest:`export-keys:${t}:${e.chain}:${e.curve}:email-otp`});if(!o.confirmed)throw Error(o.error||`User cancelled Email OTP export request`);let s=String(o.otpCode||``).replace(/\D/g,``).slice(0,6);if(s.length!==6)throw Error(`Email OTP export requires a 6-digit code`);return{challengeId:String(o.emailOtpChallengeId||r.challengeId).trim(),otpCode:s}}function N(e){throw Error(`[SigningEngine][export] unsupported authorization identity: ${String(e)}`)}function Le(e){throw Error(`[SigningEngine][export] unsupported step-up method: ${String(e)}`)}function Re(e){let t=String(e.walletSessionUserId||``).trim();if(!t)throw Error(`[SigningEngine][export] missing export step-up authorization identity`);let n=String(e.publicKey||``).trim();if(!n)throw Error(`[SigningEngine][export] missing export step-up authorization public key`);switch(e.curve){case`ecdsa`:return{walletSessionUserId:t,publicKey:n,curve:`ecdsa`,intent:`ecdsa_export`,chain:e.chain};case`ed25519`:{let r={walletSessionUserId:t,publicKey:n,curve:`ed25519`,intent:`ed25519_export`,chain:`near`,nearAccountId:String(e.nearAccountId||``).trim(),nearEd25519SigningKeyId:String(e.nearEd25519SigningKeyId||``).trim(),signerSlot:Number(e.signerSlot)};if(!r.nearAccountId||!r.nearEd25519SigningKeyId||!Number.isSafeInteger(r.signerSlot)||r.signerSlot<1)throw Error(`[SigningEngine][export] Ed25519 export authorization identity is invalid`);return r}default:return N(e)}}function ze(e){let t={kind:C.EmailOtpReauth,method:`email_otp`,emailOtpPrompt:e.emailOtpPrompt},n=e.emailOtpPrompt.emailHint;switch(e.identity.curve){case`ecdsa`:return{kind:`email_otp`,signingAuthPlan:t,challengeId:e.challengeId,otpCode:e.otpCode,walletSessionUserId:e.identity.walletSessionUserId,publicKey:e.identity.publicKey,curve:`ecdsa`,intent:`ecdsa_export`,chain:e.identity.chain,...n?{emailHint:n}:{}};case`ed25519`:return{kind:`email_otp`,signingAuthPlan:t,challengeId:e.challengeId,otpCode:e.otpCode,walletSessionUserId:e.identity.walletSessionUserId,publicKey:e.identity.publicKey,curve:`ed25519`,intent:`ed25519_export`,chain:`near`,nearAccountId:e.identity.nearAccountId,nearEd25519SigningKeyId:e.identity.nearEd25519SigningKeyId,signerSlot:e.identity.signerSlot,...n?{emailHint:n}:{}};default:return N(e.identity)}}function Be(e){let t={kind:C.PasskeyReauth,method:`passkey`};switch(e.identity.curve){case`ecdsa`:return{kind:`passkey`,signingAuthPlan:t,credential:e.credential,walletSessionUserId:e.identity.walletSessionUserId,publicKey:e.identity.publicKey,curve:`ecdsa`,intent:`ecdsa_export`,chain:e.identity.chain};case`ed25519`:return{kind:`passkey`,signingAuthPlan:t,credential:e.credential,walletSessionUserId:e.identity.walletSessionUserId,publicKey:e.identity.publicKey,curve:`ed25519`,intent:`ed25519_export`,chain:`near`,nearAccountId:e.identity.nearAccountId,nearEd25519SigningKeyId:e.identity.nearEd25519SigningKeyId,signerSlot:e.identity.signerSlot};default:return N(e.identity)}}function P(e){let t=Re(e);switch(e.method){case`email_otp`:{if(!e.decision.confirmed)throw Error(e.decision.error||`User cancelled Email OTP export request`);let n=String(e.decision.otpCode||``).replace(/\D/g,``).slice(0,6);if(n.length!==6)throw Error(`Email OTP export requires a 6-digit code`);let r=String(e.decision.emailOtpChallengeId||e.emailOtpPrompt.challengeId||``).trim();if(!r)throw Error(`Email OTP export challenge response did not include challengeId`);return ze({identity:t,emailOtpPrompt:e.emailOtpPrompt,challengeId:r,otpCode:n})}case`passkey`:if(!e.decision.confirmed)throw Error(e.decision.error||`User cancelled export request`);if(!e.decision.credential)throw Error(`[SigningEngine][export] missing WebAuthn credential for export authorization`);return Be({identity:t,credential:le(e.decision.credential)});default:return Le(e)}}function Ve(e){switch(e.kind){case`ecdsa`:return{subject:`${String(e.walletSession.walletId)}:${u(e.chainTarget)}`,chain:e.chainTarget.kind,data:{curve:`ecdsa`,chain:e.chainTarget.kind,chainTarget:e.chainTarget}};case`ed25519`:return{subject:`${String(e.walletSession.walletId)}:near:${String(e.nearAccount.accountId)}`,chain:`near`,data:{curve:`ed25519`,chain:`near`,nearAccount:e.nearAccount}}}}function F(e,t){if(e)try{e(se(t))}catch{}}function I(e){return n(e,32,`key export UI request IDs`)}function He(e,t){return`key-export:${e}:${t}:${I(`flow`)}`}async function Ue(e,t){let n=Ve(e),r=He(n.subject,n.chain),i=e.walletSession.walletId,s=n.data;F(e.options.onEvent,{phase:_.STEP_01_STARTED,status:`running`,flowId:r,accountId:String(i),interaction:{kind:`none`,overlay:`none`},data:s});try{return await t({...e,flowId:r})}catch(t){let n=a(t);throw F(e.options.onEvent,{phase:n?_.CANCELLED:_.FAILED,status:n?`cancelled`:`failed`,flowId:r,accountId:String(i),interaction:{kind:`none`,overlay:`hide`},error:{message:o(t)||(n?`Key export cancelled`:`Key export failed`)},data:s}),t}}async function We(e,t){return await e.requestExportChallenge({kind:`wallet_login_challenge`,walletSession:t.walletSession,chain:t.chain})}function L(e,t){let n=e.kind===`email_otp_ed25519_export_auth`?e.walletId:e.walletSession.walletSessionUserId;F(e.onEvent,{phase:_.STEP_02_AUTH_EMAIL_OTP_INPUT_REQUIRED,status:`waiting_for_user`,flowId:e.flowId,accountId:String(n),authMethod:`email_otp`,interaction:{kind:`otp_input`,overlay:`show`},data:{emailHint:t.emailHint,demoOtpCode:ie(t.delivery)}})}async function R(e,t){let n=t.walletSession.walletSessionUserId,r=await M({identity:{kind:`wallet_session`,walletId:n},chain:t.chain,publicKey:t.publicKey,curve:t.curve,challengeSource:{requestChallenge:async()=>await We(e,t)},confirmer:{requestUserConfirmation:async t=>await e.touchConfirm.requestUserConfirmation(t)},onChallenge:L.bind(void 0,t)}),i={challengeId:r.challengeId},a={confirmed:!0,otpCode:r.otpCode,emailOtpChallengeId:r.challengeId},o=P({method:`email_otp`,walletSessionUserId:n,chain:t.chain,publicKey:t.publicKey,curve:`ecdsa`,intent:`ecdsa_export`,emailOtpPrompt:i,decision:a});if(o.kind!==`email_otp`)throw Error(`[SigningEngine][export] Email OTP export returned the wrong step-up method`);return o}async function Ge(e,t){let n=await M({identity:{kind:`near_account`,walletId:t.walletId,nearAccountId:t.nearAccountId},chain:`near`,publicKey:t.publicKey,curve:`ed25519`,challengeSource:{requestChallenge:async()=>await e.requestExportChallenge({kind:`wallet_export_challenge`,walletId:t.walletId,chain:`near`})},confirmer:{requestUserConfirmation:async t=>await e.touchConfirm.requestUserConfirmation(t)},onChallenge:L.bind(void 0,t)}),r=P({method:`email_otp`,walletSessionUserId:t.walletId,publicKey:t.publicKey,curve:`ed25519`,intent:`ed25519_export`,chain:`near`,nearAccountId:t.nearAccountId,nearEd25519SigningKeyId:t.nearEd25519SigningKeyId,signerSlot:t.signerSlot,emailOtpPrompt:{challengeId:n.challengeId},decision:{confirmed:!0,otpCode:n.otpCode,emailOtpChallengeId:n.challengeId}});if(r.kind!==`email_otp`||r.curve!==`ed25519`)throw Error(`[SigningEngine][export] Ed25519 Email OTP export authorization changed kind`);return r}async function z(e,t){let n=t.state===`loading`,r=[{scheme:`ed25519`,label:`NEAR Ed25519 private key`,publicKey:t.publicKey,privateKey:n?``:t.privateKey}];await e.touchConfirm.requestUserConfirmation({requestId:I(`export-ed25519-yao-view`),type:w.SHOW_SECURE_PRIVATE_KEY_UI,summary:{operation:`Export Private Key`,accountId:t.nearAccountId,publicKey:t.publicKey,warning:`Anyone with your private key can fully control your account. Never share it.`},payload:{subject:{kind:`near_wallet`,nearAccountId:t.nearAccountId},viewerSessionId:t.viewerSessionId,publicKey:t.publicKey,keys:r,variant:t.variant,theme:t.theme??e.theme??`dark`,loading:n,onLifecycle:e=>{F(t.onEvent,{phase:e===`opened`?_.STEP_04_VIEWER_OPENED:_.STEP_05_VIEWER_CLOSED,status:e===`opened`?`waiting_for_user`:`succeeded`,flowId:t.flowId,accountId:t.nearAccountId,interaction:{kind:`key_export_viewer`,overlay:e===`opened`?`show`:`hide`},data:{chain:`near`,curve:`ed25519`,loading:n}}),e===`closed`&&F(t.onEvent,{phase:_.STEP_06_COMPLETED,status:`succeeded`,flowId:t.flowId,accountId:t.nearAccountId,interaction:{kind:`none`,overlay:`hide`},data:{chain:`near`,curve:`ed25519`}})}},intentDigest:`export-keys:${t.walletId}:near:${t.nearAccountId}:ed25519`})}async function B(e,t){let n=t.chainTarget.kind,r=String(t.walletSessionUserId||``).trim();if(!r)throw Error(`[SigningEngine][export] missing ECDSA export wallet session user id`);return await Ke(e,{walletSessionUserId:t.walletSessionUserId,intent:`ecdsa_export`,curve:`ecdsa`,chain:n,publicKey:t.publicKey,flowId:t.flowId,onEvent:t.onEvent,request:{requestId:I(`export-threshold-ecdsa-auth`),type:w.AUTHORIZE_KEY_EXPORT,summary:{operation:`Export Private Key`,accountId:r,publicKey:t.publicKey,warning:n===`tempo`?`Confirm to reveal your Tempo private key export.`:`Confirm to reveal your EVM private key export.`},payload:{subject:{kind:`evm_wallet`,walletId:r},credentialIdB64u:t.credentialIdB64u,publicKey:t.publicKey,...t.challengeB64u?{challengeB64u:t.challengeB64u}:{}},intentDigest:`export-keys:${r}:${u(t.chainTarget)}:secp256k1`}})}async function V(e,t){let n=t.chainTarget.kind,r=n===`tempo`?`Tempo`:`EVM`,i=t.state===`loading`,a=i?[{scheme:`secp256k1`,label:r,publicKey:t.publicKeyHex,privateKey:``,address:t.ethereumAddress}]:[{scheme:`secp256k1`,label:r,publicKey:t.publicKeyHex,privateKey:t.privateKeyHex,address:t.ethereumAddress}];await e.touchConfirm.requestUserConfirmation({requestId:I(`export-threshold-ecdsa-view`),type:w.SHOW_SECURE_PRIVATE_KEY_UI,summary:{operation:`Export Private Key`,accountId:t.walletId,publicKey:t.publicKeyHex,warning:`Anyone with your private key can fully control your account. Never share it.`},payload:{subject:{kind:`evm_wallet`,walletId:t.walletId},viewerSessionId:t.viewerSessionId,publicKey:t.publicKeyHex,keys:a,variant:t.variant,theme:t.theme??e.theme??`dark`,loading:i,onLifecycle:e=>{F(t.onEvent,{phase:e===`opened`?_.STEP_04_VIEWER_OPENED:_.STEP_05_VIEWER_CLOSED,status:e===`opened`?`waiting_for_user`:`succeeded`,flowId:t.flowId,accountId:String(t.walletId),interaction:{kind:`key_export_viewer`,overlay:e===`opened`?`show`:`hide`},data:{chain:n,curve:`ecdsa`,loading:i}}),e===`closed`&&F(t.onEvent,{phase:_.STEP_06_COMPLETED,status:`succeeded`,flowId:t.flowId,accountId:String(t.walletId),interaction:{kind:`none`,overlay:`hide`},data:{chain:n,curve:`ecdsa`}})}},intentDigest:`export-keys:${t.walletId}:${u(t.chainTarget)}:secp256k1`})}async function Ke(e,t){let n=String(t.walletSessionUserId||``).trim();if(!n)throw Error(`[SigningEngine][export] missing export account identity`);F(t.onEvent,{phase:_.STEP_02_AUTH_PASSKEY_PROMPT_STARTED,status:`waiting_for_user`,flowId:t.flowId,accountId:String(n),authMethod:`passkey`,interaction:{kind:`passkey_assert`,overlay:`show`},data:{intent:t.intent,curve:t.curve}}),T();let r=await e.touchConfirm.requestUserConfirmation(t.request),i=P({method:`passkey`,walletSessionUserId:t.walletSessionUserId,publicKey:t.publicKey,curve:`ecdsa`,intent:`ecdsa_export`,chain:t.chain,decision:r});if(i.kind!==`passkey`)throw Error(`[SigningEngine][export] passkey export returned the wrong step-up method`);return F(t.onEvent,{phase:_.STEP_02_AUTH_PASSKEY_PROMPT_SUCCEEDED,status:`succeeded`,flowId:t.flowId,accountId:String(n),authMethod:`passkey`,interaction:{kind:`passkey_assert`,overlay:`hide`},data:{intent:t.intent,curve:t.curve}}),i}function qe(e){F(e.onEvent,{phase:_.STEP_03_MATERIAL_PREPARE_STARTED,status:`running`,flowId:e.flowId,accountId:String(e.walletId),interaction:{kind:`none`,overlay:`none`},data:{chain:e.chain,curve:`ecdsa`}})}function Je(e){F(e.onEvent,{phase:_.STEP_03_MATERIAL_PREPARE_SUCCEEDED,status:`succeeded`,flowId:e.flowId,accountId:String(e.walletId),interaction:{kind:`none`,overlay:`none`},data:{chain:e.chain,curve:`ecdsa`,...e.source?{source:e.source}:{}}})}async function Ye(e,t){await V({touchConfirm:e.touchConfirm,theme:e.theme},{state:`ready`,walletId:t.walletId,chainTarget:t.exportLane.chainTarget,publicKeyHex:String(t.artifact.publicKeyHex||``).trim(),privateKeyHex:String(t.artifact.privateKeyHex||``).trim(),ethereumAddress:String(t.artifact.ethereumAddress||``).trim(),variant:t.options.variant,theme:t.options.theme,viewerSessionId:t.viewerSessionId,flowId:t.flowId,onEvent:t.onEvent})}async function Xe(e,t){await V({touchConfirm:e.touchConfirm,theme:e.theme},{state:`loading`,walletId:t.walletId,chainTarget:t.exportLane.chainTarget,publicKeyHex:String(t.publicKey||``).trim(),ethereumAddress:String(t.ethereumAddress||``).trim(),variant:t.options.variant,theme:t.options.theme,viewerSessionId:t.viewerSessionId,flowId:t.flowId,onEvent:t.onEvent})}async function H(t,n){let r=D(n.exportLane),i=I(`export-threshold-ecdsa-viewer-session`);qe({flowId:n.flowId,walletId:n.walletId,chain:r,onEvent:n.onEvent});try{await Xe(t,{walletId:n.walletId,exportLane:n.exportLane,publicKey:n.exportPublicKey,ethereumAddress:n.exportLane.publicFacts.thresholdOwnerAddress,options:n.options,viewerSessionId:i,flowId:n.flowId,onEvent:n.onEvent});let a=n.exportLane.laneIdentity.signer.materialActivation,o=await t.withThresholdEcdsaSigningQueue({queueKey:x({materialActivation:a}),walletId:n.exportLane.key.walletId,enabled:!0,task:async()=>{if(n.exportLane.source===`active_wallet_authority`){let e=n.activeRuntime;if(!e)throw Error(`[SigningEngine][ecdsa-export] active runtime is missing`);await tt({ports:t.activeWalletAuthorityEcdsaRuntimeReadPorts,expectedRuntime:e})}else if(n.exportLane.authMethod===`email_otp`){if(!e((await A(t.sessionStore,n.exportLane)).persistedMaterial.materialActivation,a))throw Error(`[SigningEngine][ecdsa-export] prepared material activation was superseded`)}else{let r=await j(t.sessionStore,n.exportLane);if(r.kind!==`fresh_passkey_needs_authorization`)throw Error(`[SigningEngine][ecdsa-export] prepared export authority changed`);if(!e(r.existingRoleLocalMaterial.materialActivation,a))throw Error(`[SigningEngine][ecdsa-export] prepared material activation was superseded`)}return await n.prepareArtifact()}});return Je({flowId:n.flowId,walletId:n.walletId,chain:r,onEvent:n.onEvent}),E(i)&&await Ye(t,{walletId:n.walletId,exportLane:n.exportLane,artifact:o,options:n.options,viewerSessionId:i,flowId:n.flowId,onEvent:n.onEvent}),{accountId:String(n.walletId),exportedSchemes:[`secp256k1`]}}catch(e){throw T(),e}}function U(e){let t=e.laneIdentity.auth;if(t.kind!==`passkey`)throw Error(`[SigningEngine][ecdsa-export] fresh passkey export requires passkey lane`);return t}async function W(e){return i(t(e))}async function G(e){let t=u(e.chainTarget);return await Ce({walletId:e.walletId,operationKind:`evm.export_key`,operationId:e.requestId,operationDigests:{laneDigest:await W({walletId:e.walletId,chainTarget:t,materialActivation:e.materialActivation,keyHandle:e.keyHandle}),intentDigest:await W({operation:`explicit_key_export`,requestId:e.requestId,walletId:e.walletId,chainTarget:t}),displayDigest:await W({operation:`Export Private Key`,publicKey:e.displayPublicKey,address:e.displayAddress})},materialActivation:e.materialActivation,normalSigningScope:e.operationRuntime.normalSigning.scope,keyHandle:e.keyHandle,relayerKeyId:e.operationRuntime.relayerKeyId,participantIds:[Number(e.operationRuntime.participantIds[0]),Number(e.operationRuntime.participantIds[1])],expiresAtMs:e.operationExpiresAtMs})}async function K(e){return await G({walletId:e.walletId,chainTarget:e.chainTarget,requestId:e.requestId,keyHandle:e.keyHandle,displayPublicKey:e.displayPublicKey,displayAddress:e.displayAddress,materialActivation:e.materialActivation,operationRuntime:e.operationRuntime,operationExpiresAtMs:e.operationExpiresAtMs})}async function Ze(t){let n=await j(t.deps.sessionStore,t.exportLane);if(n.kind!==`fresh_passkey_needs_authorization`)throw Error(`[SigningEngine][ecdsa-export] passkey export authority changed`);if(!e(n.existingRoleLocalMaterial.materialActivation,t.expectedMaterialActivation))throw Error(`[SigningEngine][ecdsa-export] active material changed after authorization confirmation`)}async function Qe(t){if(!e((await A(t.deps.sessionStore,t.exportLane)).persistedMaterial.materialActivation,t.expectedMaterialActivation))throw Error(`[SigningEngine][ecdsa-export] active material changed after authorization confirmation`)}function $e(e){if(!et(e.expected,e.actual))throw Error(`[SigningEngine][ecdsa-export] active Wallet Authority runtime was replaced after authorization`)}function et(t,n){let i;switch(t.auth.kind){case`passkey`:i=n.auth.kind===`passkey`&&t.auth.rpId===n.auth.rpId&&t.auth.credentialIdB64u===n.auth.credentialIdB64u;break;case`email_otp`:i=n.auth.kind===`email_otp`&&t.auth.providerSubjectId===n.auth.providerSubjectId;break;default:return t.auth}return t.kind===n.kind&&t.walletId===n.walletId&&t.authorityId===n.authorityId&&t.walletAuthMethodId===n.walletAuthMethodId&&t.authorityDigestB64u===n.authorityDigestB64u&&t.factorAuthorityRef.kind===n.factorAuthorityRef.kind&&t.factorAuthorityRef.walletId===n.factorAuthorityRef.walletId&&t.factorAuthorityRef.authorityDigest===n.factorAuthorityRef.authorityDigest&&t.factorAuthorityRef.walletAuthMethodId===n.factorAuthorityRef.walletAuthMethodId&&t.authorityRevocationEpoch===n.authorityRevocationEpoch&&t.walletSessionId===n.walletSessionId&&t.requiredCapability===n.requiredCapability&&e(t.materialActivation,n.materialActivation)&&t.ecdsaThresholdKeyId===n.ecdsaThresholdKeyId&&t.relayerKeyId===n.relayerKeyId&&t.operationCredential.kind===n.operationCredential.kind&&t.operationCredential.token===n.operationCredential.token&&t.operationCredential.walletSessionId===n.operationCredential.walletSessionId&&r(t.session,n.session)&&ae(t.authMethod,n.authMethod)&&i&&m(t.factorAuthority,n.factorAuthority)&&t.holderRuntime.kind===n.holderRuntime.kind&&t.holderRuntime.walletId===n.holderRuntime.walletId&&t.holderRuntime.authorityId===n.holderRuntime.authorityId&&t.holderRuntime.walletAuthMethodId===n.holderRuntime.walletAuthMethodId&&m(t.holderRuntime.factorAuthority,n.holderRuntime.factorAuthority)&&e(t.holderRuntime.materialActivation,n.holderRuntime.materialActivation)&&t.holderRuntime.holderHandleId===n.holderRuntime.holderHandleId&&t.holderRuntime.ecdsaThresholdKeyId===n.holderRuntime.ecdsaThresholdKeyId&&ne(t.normalSigning,n.normalSigning)}async function q(e){let t=await we({ports:e.ports,input:{walletId:e.expectedRuntime.walletId,requiredCapability:`export_keys`,materialActivation:e.expectedRuntime.materialActivation}});if(t.kind!==`resolved`)throw Error(`[SigningEngine][ecdsa-export] active Wallet Authority runtime is ${t.reason}`);return $e({expected:e.expectedRuntime,actual:t.runtime}),t.runtime}async function tt(e){await q(e)}function J(e){let t=e.credential,n=String(t.rawId||t.id||``).trim();if(!n||n!==e.authority.factor.credentialIdB64u)throw Error(`[SigningEngine][ecdsa-export] passkey credential does not match authority`);return{kind:`passkey`,authority:e.authority,webauthn_authentication:{id:t.id,rawId:t.rawId,type:t.type,authenticatorAttachment:t.authenticatorAttachment??null,response:{clientDataJSON:t.response.clientDataJSON,authenticatorData:t.response.authenticatorData,signature:t.response.signature,userHandle:t.response.userHandle??null},clientExtensionResults:t.clientExtensionResults??null}}}function Y(e){if(!p(e.authority))throw Error(`[SigningEngine][ecdsa-export] Email OTP material authority mismatch`);return{kind:`email_otp`,authority:e.authority,challenge_id:e.challengeId,otp_code:e.otpCode}}async function X(e){let t=await Se({relayerUrl:e.relayerUrl,transport:e.transport,request:{kind:`router_ab_ecdsa_operation_step_up_v1`,operation:e.prepared.operation,proof:e.proof}});if(t.operation_kind!==`evm.export_key`)throw Error(`[SigningEngine][ecdsa-export] operation step-up kind mismatch`);let n=t.authorization.evidence_set_digest,r=nt({proofKind:e.proof.kind,unseal:t.authorization.unseal});return{kind:`verified_step_up`,evidenceSetDigest:n,operation:e.prepared.operation,expiresAtMs:t.expires_at_ms,quotaUse:`none`,unseal:r,exportTopology:t.export_topology}}function nt(e){switch(e.proofKind){case`passkey`:if(e.unseal.kind!==`not_requested`)throw Error(`[SigningEngine][ecdsa-export] passkey step-up returned Email OTP unseal material`);return{kind:`not_requested`};case`email_otp`:if(e.unseal.kind!==`email_otp_grant`)throw Error(`[SigningEngine][ecdsa-export] Email OTP step-up did not return an unseal grant`);return{kind:`email_otp_grant`,grant:e.unseal.grant,challenge_id:e.unseal.challenge_id};default:{let t=e.proofKind;throw Error(`Unsupported ECDSA export step-up proof: ${String(t)}`)}}}async function rt(e,t){U(t.exportLane);let n=I(`tecdsa-export`),r=await K({walletId:t.walletId,chainTarget:t.exportLane.chainTarget,requestId:n,keyHandle:t.material.existingRoleLocalMaterial.publicFacts.keyHandle,displayPublicKey:t.material.existingRoleLocalMaterial.publicFacts.groupPublicKey33B64u,displayAddress:t.material.existingRoleLocalMaterial.publicFacts.ethereumAddress,materialActivation:t.material.existingRoleLocalMaterial.materialActivation,operationRuntime:t.material,operationExpiresAtMs:Date.now()+5*6e4}),i=await B({touchConfirm:e.touchConfirm,theme:e.theme},{walletSessionUserId:t.walletId,credentialIdB64u:U(t.exportLane).credentialIdB64u,publicKey:t.exportPublicKey,chainTarget:t.exportLane.chainTarget,challengeB64u:r.challengeB64u,flowId:t.flowId,onEvent:t.onEvent});await Ze({deps:e,exportLane:t.exportLane,expectedMaterialActivation:t.material.existingRoleLocalMaterial.materialActivation});let a=t.exportLane.capability.authority;if(!f(a))throw Error(`[SigningEngine][ecdsa-export] exact Passkey capability authority changed`);let o=await X({relayerUrl:t.material.relayerUrl,prepared:r,transport:{kind:`factor_proof`},proof:J({authority:a,credential:i.credential})});return{exportActivation:ge({relayerUrl:t.material.relayerUrl,existingRoleLocalMaterial:t.material.existingRoleLocalMaterial,authorization:o}),credential:i.credential}}async function it(e){let t=d({walletId:e.walletId,walletSessionUserId:e.walletId});return await e.deps.emailOtp.exportEcdsaKeyWithDurableAuthorization({walletSession:t,chainTarget:e.material.chainTarget,challengeId:e.authorization.challengeId,otpCode:e.authorization.otpCode,publicFacts:e.material.publicFacts,runtimePolicyScope:e.material.runtimePolicyScope,authority:e.material.authorization.authority,persistedMaterial:e.persistedMaterial,explicitExportAuthorization:e.explicitExportAuthorization})}function Z(e){return{normalSigning:e.runtime.normalSigning,relayerKeyId:e.relayerKeyId,participantIds:e.participantIds}}function Q(e){return Math.min(Date.now()+5*6e4,e.session.expiresAtMs)}async function at(e){if(e.material.runtime.auth.kind!==`passkey`)throw Error(`[SigningEngine][ecdsa-export] active passkey runtime auth mismatch`);if(!f(e.material.factorAuthority))throw Error(`[SigningEngine][ecdsa-export] active passkey factor authority mismatch`);let t=await K({walletId:e.walletId,chainTarget:e.exportLane.chainTarget,requestId:I(`tecdsa-active-passkey-export`),keyHandle:e.material.runtime.publicFacts.keyHandle,displayPublicKey:e.material.runtime.publicFacts.publicKeyB64u,displayAddress:e.material.runtime.publicFacts.thresholdOwnerAddress,materialActivation:e.material.runtime.materialActivation,operationRuntime:Z(e.material),operationExpiresAtMs:Q(e.material.runtime)}),n=await B({touchConfirm:e.deps.touchConfirm,theme:e.deps.theme},{walletSessionUserId:e.walletId,credentialIdB64u:e.material.factorAuthority.factor.credentialIdB64u,publicKey:e.exportPublicKey,chainTarget:e.exportLane.chainTarget,challengeB64u:t.challengeB64u,flowId:e.flowId,onEvent:e.onEvent}),r=await q({ports:e.deps.activeWalletAuthorityEcdsaRuntimeReadPorts,expectedRuntime:e.material.runtime});if(!f(r.factorAuthority))throw Error(`[SigningEngine][ecdsa-export] active passkey factor authority changed`);return{runtime:r,authorization:await X({relayerUrl:e.material.relayerUrl,prepared:t,transport:{kind:`wallet_session`,credential:r.operationCredential},proof:J({authority:r.factorAuthority,credential:n.credential})})}}async function ot(e){if(e.material.runtime.auth.kind!==`email_otp`)throw Error(`[SigningEngine][ecdsa-export] active Email OTP runtime auth mismatch`);if(!p(e.material.factorAuthority))throw Error(`[SigningEngine][ecdsa-export] active Email OTP factor authority mismatch`);let t=await K({walletId:e.walletId,chainTarget:e.exportLane.chainTarget,requestId:I(`tecdsa-active-email-otp-export`),keyHandle:e.material.runtime.publicFacts.keyHandle,displayPublicKey:e.material.runtime.publicFacts.publicKeyB64u,displayAddress:e.material.runtime.publicFacts.thresholdOwnerAddress,materialActivation:e.material.runtime.materialActivation,operationRuntime:Z(e.material),operationExpiresAtMs:Q(e.material.runtime)}),n=await R({touchConfirm:e.deps.touchConfirm,requestExportChallenge:e.deps.emailOtp.requestExportChallenge},{kind:`wallet_session_export_auth`,walletSession:d({walletId:e.walletId,walletSessionUserId:e.walletId}),chain:D(e.exportLane),publicKey:e.exportPublicKey,curve:`ecdsa`,flowId:e.flowId,onEvent:e.onEvent}),r=await q({ports:e.deps.activeWalletAuthorityEcdsaRuntimeReadPorts,expectedRuntime:e.material.runtime});if(!p(r.factorAuthority))throw Error(`[SigningEngine][ecdsa-export] active Email OTP factor authority changed`);return{runtime:r,authorization:await X({relayerUrl:e.material.relayerUrl,prepared:t,transport:{kind:`wallet_session`,credential:r.operationCredential},proof:Y({authority:r.factorAuthority,challengeId:n.challengeId,otpCode:n.otpCode})})}}async function st(e){switch(e.material.kind){case`active_wallet_authority_passkey_needs_authorization`:return await at({deps:e.deps,walletId:e.walletId,exportLane:e.exportLane,material:e.material,exportPublicKey:e.exportPublicKey,flowId:e.flowId,onEvent:e.onEvent});case`active_wallet_authority_email_otp_needs_authorization`:return await ot({deps:e.deps,walletId:e.walletId,exportLane:e.exportLane,material:e.material,exportPublicKey:e.exportPublicKey,flowId:e.flowId,onEvent:e.onEvent});default:return ct(e.material)}}function ct(e){throw Error(`[SigningEngine][ecdsa-export] unsupported active wallet authority material: ${String(e)}`)}async function lt(e,t){let n=String(t.material.publicFacts.publicKeyB64u),r=await st({deps:e,walletId:t.walletId,exportLane:t.exportLane,material:t.material,exportPublicKey:n,flowId:t.flowId,onEvent:t.onEvent});return await H(e,{walletId:t.walletId,exportLane:t.exportLane,activeRuntime:r.runtime,exportPublicKey:n,options:t.options,flowId:t.flowId,onEvent:t.onEvent,prepareArtifact:async()=>{let n=await q({ports:e.activeWalletAuthorityEcdsaRuntimeReadPorts,expectedRuntime:r.runtime});return await _e({getSignerWorkerContext:e.getSignerWorkerContext},{runtime:n,operationAuthorization:r.authorization,relayerUrl:t.material.relayerUrl})}})}async function ut(e,t){let n=D(t.exportLane),r=await G({walletId:t.walletId,chainTarget:t.exportLane.chainTarget,requestId:I(`tecdsa-email-otp-export`),keyHandle:t.material.persistedMaterial.publicFacts.keyHandle,displayPublicKey:t.material.persistedMaterial.publicFacts.groupPublicKey33B64u,displayAddress:t.material.persistedMaterial.publicFacts.ethereumAddress,materialActivation:t.material.persistedMaterial.materialActivation,operationRuntime:t.material,operationExpiresAtMs:Date.now()+5*6e4}),i=await R({touchConfirm:e.touchConfirm,requestExportChallenge:e.emailOtp.requestExportChallenge},{kind:`wallet_session_export_auth`,walletSession:d({walletId:t.walletId,walletSessionUserId:t.walletId}),chain:n,publicKey:String(t.material.publicFacts.publicKeyB64u),curve:`ecdsa`,flowId:t.flowId,onEvent:t.onEvent});await Qe({deps:e,exportLane:t.exportLane,expectedMaterialActivation:t.material.persistedMaterial.materialActivation});let a=await X({relayerUrl:t.material.relayerUrl,prepared:r,transport:{kind:`factor_proof`},proof:Y({authority:t.material.authorization.authority,challengeId:i.challengeId,otpCode:i.otpCode})});return await H(e,{walletId:t.walletId,exportLane:t.exportLane,exportPublicKey:String(t.material.publicFacts.publicKeyB64u),options:t.options,flowId:t.flowId,onEvent:t.onEvent,prepareArtifact:it.bind(void 0,{deps:e,walletId:t.walletId,material:t.material,authorization:i,persistedMaterial:t.material.persistedMaterial,explicitExportAuthorization:a})})}async function dt(e,t){if(t.exportLane.authMethod!==`passkey`)throw Error(`[SigningEngine][ecdsa-export] fresh passkey export requires passkey lane`);let n=String(t.material.publicFacts.publicKeyB64u),r=await rt(e,{walletId:t.walletId,exportLane:t.exportLane,material:t.material,exportPublicKey:n,flowId:t.flowId,onEvent:t.onEvent});return await H(e,{walletId:t.walletId,exportLane:t.exportLane,exportPublicKey:n,options:t.options,flowId:t.flowId,onEvent:t.onEvent,prepareArtifact:async()=>{let n=await e.provisionPasskeyEcdsaExplicitExportSession(r.exportActivation);return await he({getSignerWorkerContext:e.getSignerWorkerContext},{walletSessionUserId:t.walletId,exportProvision:n,factorAuthorization:{kind:`passkey`,passkeyCredentialIdB64u:String(r.credential.rawId||r.credential.id),credential:r.credential}})}})}function $(e){let t=e.source===`canonical_capability`?e.authorization:null;return{authMethod:S(e),curve:e.curve,chain:e.chainTarget.kind,chainTarget:e.chainTarget,state:e.state,source:e.source,...t?{remainingUses:e.remainingUses,expiresAtMs:e.expiresAtMs}:{},updatedAtMs:e.updatedAtMs,evmFamilyKeyFingerprint:g({walletId:e.key.walletId,publicFacts:e.publicFacts})}}function ft(e,t){return String(e.key.walletId)===t.walletId?String(g({walletId:e.key.walletId,publicFacts:e.publicFacts})):``}function pt(e){if(!e.candidates.length)throw y(`evm-family`,{stage:`key_export.exact_lane_no_candidate`,context:e.context,candidateCount:e.candidates.length,candidates:e.candidates.map($)}),Error(`[SigningEngine][${e.context}] exact lane selection failed: no_candidate`);for(let t of e.candidates)if(!ft(t,e.ecdsaContext))return mt(e);if(e.candidates.length!==1)return mt(e);let[t]=e.candidates;return me(`evm-family`,{stage:`key_export.exact_lane_selected`,context:e.context,reason:`single_exact_candidate`,selectedLane:$(t),candidateCount:e.candidates.length}),t}function mt(e){throw y(`evm-family`,{stage:`key_export.exact_lane_ambiguous_material`,context:e.context,candidateCount:e.candidates.length,candidates:e.candidates.map($)}),Error(`[SigningEngine][${e.context}] exact lane selection failed: ambiguous_material`)}function ht(e){return pe({signer:de({walletId:e.lane.key.walletId,chainTarget:e.chainTarget||e.lane.chainTarget,keyHandle:e.lane.publicFacts.keyHandle,key:e.lane.key,materialActivation:e.lane.materialActivation}),auth:e.lane.auth})}function gt(e){return e.source===`active_wallet_authority`||e.state===`ready`?{kind:`loaded_worker_material`}:S(e)===`email_otp`?{kind:`material_pending`,reason:`email_otp_route_auth`}:{kind:`sealed_worker_material`}}function _t(e){if(e.lane.source===`active_wallet_authority`)return{chainTarget:e.chainTarget,authMethod:S(e.lane),material:{kind:`loaded_worker_material`},state:`deferred`};let t=S(e.lane),n=gt(e.lane);switch(e.lane.state){case`expired`:case`exhausted`:throw Error(`[SigningEngine][ecdsa-export] expired export lane requires durable public reauth authority`);case`ready`:case`deferred`:return{chainTarget:e.chainTarget,authMethod:t,material:n,state:e.lane.state}}}async function vt(e){let t=e.lane,n=ht({lane:t}),r=_t({lane:t,chainTarget:e.chainTarget});return t.source===`active_wallet_authority`?{curve:`ecdsa`,laneIdentity:n,source:`active_wallet_authority`,authorizationState:`authorization_required`,key:t.key,publicFacts:t.publicFacts,runtime:t.runtime,chainTarget:e.chainTarget,authMethod:S(t),material:{kind:`loaded_worker_material`},state:`deferred`}:t.authorization?{curve:`ecdsa`,laneIdentity:n,source:`canonical_capability`,authorizationState:`authorized`,authorization:t.authorization,capability:t.capability,key:t.key,publicFacts:t.publicFacts,...r}:{curve:`ecdsa`,laneIdentity:n,source:`canonical_capability`,authorizationState:`authorization_required`,capability:t.capability,key:t.key,publicFacts:t.publicFacts,...r}}function yt(e){return v(e.laneIdentity)===v(e.identity)}async function bt(e){return ht({lane:e})}function xt(e){return Te(e.availableLanes,e.chainTarget).filter(e=>Oe(e))}async function St(e,t){let n=xt({availableLanes:await e.readOwnerScopedAvailableSigningLanesForTargets({walletId:t.walletId,ecdsaChainTargets:[t.signingTarget]}),chainTarget:t.signingTarget}),r=[];for(let e of n)yt({laneIdentity:await bt(e),identity:t.laneIdentity})&&r.push(e);let i=pt({context:`ecdsa-export`,candidates:r,ecdsaContext:{walletId:t.walletId}});return await vt({lane:i,chainTarget:i.chainTarget})}async function Ct(e,t){try{switch(t.kind){case`ecdsa`:return await wt(e,t);case`ed25519`:return await Ot(e,t)}}catch(e){if(ye(e))return{kind:`relink_required`,reason:e.reason};throw e}}async function wt(e,t){let n=String(l(t.walletSession.walletId));return{kind:`ecdsa`,laneIdentity:await bt(pt({context:`ecdsa-export-resolve`,candidates:xt({availableLanes:await e.readOwnerScopedAvailableSigningLanesForTargets({walletId:n,ecdsaChainTargets:[t.chainTarget]}),chainTarget:t.chainTarget}),ecdsaContext:{walletId:n}}))}}function Tt(e){let t=e.lane.source===`durable_sealed_record`||e.lane.source===`public_capability_reference`;return String(e.lane.walletId)===e.walletId&&String(e.lane.nearAccountId)===e.nearAccountId&&t}function Et(e){return ue({signer:fe({walletId:e.walletId,nearAccountId:e.nearAccountId,nearEd25519SigningKeyId:e.nearEd25519SigningKeyId,signerSlot:e.signerSlot}),auth:e.auth,thresholdSessionId:e.thresholdSessionId})}function Dt(e){return[e.walletId,e.nearAccountId,e.nearEd25519SigningKeyId,e.signerSlot,ce(e.auth)].map(e=>String(e)).join(`|`)}async function Ot(e,t){let n=String(l(t.walletSession.walletId)),r=String(t.nearAccount.accountId),i=await e.readOwnerScopedAvailableSigningLanesForTargets({walletId:n,ecdsaChainTargets:[]}),a=i.lanes.ed25519.near;if(!b(a)||a.curve!==`ed25519`||!Tt({lane:a,walletId:n,nearAccountId:r}))throw Error(`[SigningEngine][ed25519-export-resolve] exact Yao lane selection failed: no_candidate`);let o=i.candidates.ed25519.near.filter(e=>b(e)&&e.curve===`ed25519`&&Tt({lane:e,walletId:n,nearAccountId:r})),s=Dt(a);if(o.some(e=>Dt(e)!==s))throw Error(`[SigningEngine][ed25519-export-resolve] exact Yao lane selection failed: ambiguous_material`);return{kind:`ed25519`,laneIdentity:Et(a),materialActivation:a.materialActivation}}async function kt(e,t){let n=await St(e,{walletId:t.walletId,signingTarget:t.signingTarget,laneIdentity:t.laneIdentity});switch(n.material.kind){case`loaded_worker_material`:case`material_pending`:case`sealed_worker_material`:return n}throw n.material,Error(`[SigningEngine][ecdsa-export] unsupported material availability`)}function At(e){return e.capability.materialActivation}function jt(e){return e.material.materialActivation}function Mt(e){return e.auth.kind===`passkey`}function Nt(e){if(!Mt(e.laneIdentity))throw Error(`[SigningEngine][ed25519-export] export requires a passkey Yao lane`);if(e.laneIdentity.signer.account.wallet.walletId!==e.walletId||String(e.laneIdentity.signer.account.nearAccountId)!==String(e.nearAccountId))throw Error(`[SigningEngine][ed25519-export] exact lane subject mismatch`);return e.laneIdentity}function Pt(e){return e.auth.kind===`email_otp`}function Ft(e){if(!Pt(e.laneIdentity))throw Error(`[SigningEngine][ed25519-export] export requires an Email OTP Yao lane`);if(e.laneIdentity.signer.account.wallet.walletId!==e.walletId||String(e.laneIdentity.signer.account.nearAccountId)!==String(e.nearAccountId))throw Error(`[SigningEngine][ed25519-export] exact lane subject mismatch`);return e.laneIdentity}function It(e){let t=e.selected.signer,n=e.context.material;return String(t.account.wallet.walletId)===String(n.walletId)&&String(t.account.nearAccountId)===String(n.nearAccountId)&&String(t.nearEd25519SigningKeyId)===String(n.nearEd25519SigningKeyId)&&t.signerSlot===n.signerSlot&&String(e.selected.auth.rpId)===e.context.rpId&&e.selected.auth.credentialIdB64u===n.credentialIdB64u}function Lt(t){if(!It({selected:t.selectedLaneIdentity,context:t.context}))throw Error(`[SigningEngine][ed25519-export] durable Yao context identity mismatch`);let n=t.context.material;if(!e(t.selectedMaterialActivation,t.context.selectedLaneMaterialActivation))throw Error(`[SigningEngine][ed25519-export] durable Yao context activation mismatch`);let r=t.context.authorization.operationCredential.token;if(!r)throw Error(`[SigningEngine][ed25519-export] active Wallet Session authorization is unavailable`);let i=n.capability.lifecycle;return{laneIdentity:t.selectedLaneIdentity,relayerUrl:t.context.relayerUrl,walletSessionToken:r,walletCustodyEnvelope:t.context.walletCustodyEnvelope,capability:{materialActivation:n.capability.materialActivation,scope:{lifecycle_id:i.lifecycleId,root_share_epoch:i.rootShareEpoch,account_id:i.accountId,threshold_session_id:i.thresholdSessionId,signer_set_id:i.signerSetId,signing_worker_id:i.signingWorkerId,material_activation:re(n.capability.materialActivation)},applicationBinding:n.capability.applicationBinding,participantIds:n.capability.participantIds,registeredPublicKey:n.capability.registeredPublicKey,stateEpoch:n.capability.stateEpoch,activeCapabilityBinding:n.capability.activeCapabilityBinding,runtimePolicyScope:n.capability.runtimePolicyScope}}}async function Rt(e,t){let n=Nt(t),r=await e.resolvePasskeyExportContext({laneIdentity:n,materialActivation:t.materialActivation});switch(r.kind){case`ready`:return Lt({context:r.context,selectedLaneIdentity:n,selectedMaterialActivation:t.materialActivation});case`capability_recovery_required`:throw Error(`[SigningEngine][ed25519-export] passkey material recovery did not publish durable context`)}throw Error(`[SigningEngine][ed25519-export] unsupported passkey export context state`)}async function zt(t,n){let r=Ft(n),i=await t.emailOtp.resolveExportContext({laneIdentity:r,materialActivation:n.materialActivation});if(!e(n.materialActivation,i.material.materialActivation)&&i.material.kind!==`sealed_export_root`)throw Error(`[SigningEngine][ed25519-export] Email OTP Yao context activation mismatch`);return{context:i,laneIdentity:r}}function Bt(e){let t=e.resolved.laneIdentity.signer;return{artifactKind:ve,walletId:String(e.input.walletId),nearAccountId:String(e.input.nearAccountId),relayerUrl:e.resolved.relayerUrl,authorization:{kind:`opaque_wallet_session`,walletSessionToken:e.resolved.walletSessionToken},flowId:e.input.flowId,viewerSessionId:e.viewerSessionId,exactLane:{nearEd25519SigningKeyId:String(t.nearEd25519SigningKeyId),signerSlot:t.signerSlot,credentialIdB64u:e.resolved.laneIdentity.auth.credentialIdB64u,materialActivation:At(e.resolved)},walletCustodyEnvelope:e.resolved.walletCustodyEnvelope,capability:e.resolved.capability,variant:e.input.options.variant,theme:e.input.options.theme??e.theme}}function Vt(e,t){let n=String(e.walletId);F(e.onEvent,{phase:t===`opened`?_.STEP_04_VIEWER_OPENED:_.STEP_05_VIEWER_CLOSED,status:t===`opened`?`waiting_for_user`:`succeeded`,flowId:e.flowId,accountId:n,interaction:{kind:`key_export_viewer`,overlay:t===`opened`?`show`:`hide`},data:{chain:`near`,curve:`ed25519`}}),t===`closed`&&F(e.onEvent,{phase:_.STEP_06_COMPLETED,status:`succeeded`,flowId:e.flowId,accountId:n,interaction:{kind:`none`,overlay:`hide`},data:{chain:`near`,curve:`ed25519`}})}async function Ht(e,t){switch(t.laneIdentity.auth.kind){case`passkey`:break;case`email_otp`:return await Ut(e,t);default:throw t.laneIdentity.auth,Error(`[SigningEngine][ed25519-export] unsupported lane authorization method`)}let n=Rt(e,t),r=e.touchConfirm.initialize(),[i]=await Promise.all([n,r]),a=String(t.walletId),o=I(`export-ed25519-yao-viewer-session`),s=Vt.bind(void 0,{flowId:t.flowId,walletId:t.walletId,onEvent:t.onEvent});F(t.onEvent,{phase:_.STEP_02_AUTH_PASSKEY_PROMPT_STARTED,status:`waiting_for_user`,flowId:t.flowId,accountId:a,authMethod:`passkey`,interaction:{kind:`passkey_assert`,overlay:`show`},data:{intent:`ed25519_export`,chain:`near`,curve:`ed25519`}}),F(t.onEvent,{phase:_.STEP_03_MATERIAL_PREPARE_STARTED,status:`running`,flowId:t.flowId,accountId:a,interaction:{kind:`none`,overlay:`none`},data:{chain:`near`,curve:`ed25519`}});let c=await e.withThresholdEd25519CommitQueue({queueKey:x({materialActivation:At(i)}),nearAccountId:t.nearAccountId,enabled:!0,task:()=>e.passkeyMpcExport.exportPrivateKeysWithUi(Bt({resolved:i,viewerSessionId:o,input:t,theme:e.theme}),{onViewerLifecycle:s})});if(c.kind!==`completed`)throw Error(c.error);if(c.exportedSchemes.length!==1||c.exportedSchemes[0]!==`ed25519`)throw Error(`[SigningEngine][ed25519-export] secure export failed`);return F(t.onEvent,{phase:_.STEP_02_AUTH_PASSKEY_PROMPT_SUCCEEDED,status:`succeeded`,flowId:t.flowId,accountId:a,authMethod:`passkey`,interaction:{kind:`passkey_assert`,overlay:`none`},data:{intent:`ed25519_export`,chain:`near`,curve:`ed25519`}}),F(t.onEvent,{phase:_.STEP_03_MATERIAL_PREPARE_SUCCEEDED,status:`succeeded`,flowId:t.flowId,accountId:a,interaction:{kind:`none`,overlay:`none`},data:{chain:`near`,curve:`ed25519`}}),{accountId:String(t.nearAccountId),exportedSchemes:[`ed25519`]}}async function Ut(e,t){let n=await zt(e,t),r=`ed25519:${s(Uint8Array.from(n.context.material.capability.registeredPublicKey))}`,i=await Ge({touchConfirm:e.touchConfirm,requestExportChallenge:e.emailOtp.requestExportChallenge},{kind:`email_otp_ed25519_export_auth`,walletId:t.walletId,nearAccountId:String(t.nearAccountId),nearEd25519SigningKeyId:String(n.laneIdentity.signer.nearEd25519SigningKeyId),signerSlot:n.laneIdentity.signer.signerSlot,publicKey:r,curve:`ed25519`,chain:`near`,flowId:t.flowId,onEvent:t.onEvent});F(t.onEvent,{phase:_.STEP_03_MATERIAL_PREPARE_STARTED,status:`running`,flowId:t.flowId,accountId:String(t.nearAccountId),interaction:{kind:`none`,overlay:`none`},data:{chain:`near`,curve:`ed25519`}});let a=I(`export-ed25519-yao-viewer-session`);try{await z({touchConfirm:e.touchConfirm,theme:e.theme},{state:`loading`,walletId:String(t.walletId),nearAccountId:String(t.nearAccountId),publicKey:r,variant:t.options.variant,theme:t.options.theme,viewerSessionId:a,flowId:t.flowId,onEvent:t.onEvent});let o=await e.withThresholdEd25519CommitQueue({queueKey:x({materialActivation:jt(n.context)}),nearAccountId:t.nearAccountId,enabled:n.context.material.kind===`active_capability`,task:()=>e.emailOtp.exportSeedWithFreshAuthorization({challengeId:i.challengeId,otpCode:i.otpCode,exportContext:n.context})});return F(t.onEvent,{phase:_.STEP_03_MATERIAL_PREPARE_SUCCEEDED,status:`succeeded`,flowId:t.flowId,accountId:String(t.nearAccountId),interaction:{kind:`none`,overlay:`none`},data:{chain:`near`,curve:`ed25519`}}),E(a)&&await z({touchConfirm:e.touchConfirm,theme:e.theme},{state:`ready`,walletId:String(t.walletId),nearAccountId:String(t.nearAccountId),publicKey:o.publicKey,privateKey:o.privateKey,variant:t.options.variant,theme:t.options.theme,viewerSessionId:a,flowId:t.flowId,onEvent:t.onEvent}),{accountId:String(t.nearAccountId),exportedSchemes:[`ed25519`]}}catch(e){throw T(),e}}function Wt(e){switch(e.kind){case`active`:case`expired`:return e;case`missing`:case`unavailable`:case`invalid`:return null;default:return e}}async function Gt(e){await e.deps.sessionLifecycle.invalidateExpiredAuthorization({state:e.state,source:e.source})}async function Kt(e){let t=await e.deps.sessionLifecycle.readAuthorization(e.request);return t.kind===`expired`&&await Gt({deps:e.deps,state:t,source:oe.operationPreflight}),t}function qt(e){let t=Wt(e.preflightState);return t?Ee({source:e.source,expiresAtMs:t.expiresAtMs,detectedAtMs:e.detectedAtMs}):null}async function Jt(e,t){let n=l(t.walletSession.walletId),r=await kt(e.laneSelection,{walletId:n,signingTarget:De(t.chainTarget),laneIdentity:t.laneIdentity}),i=await j(e.ecdsa.sessionStore,r);if(r.source===`active_wallet_authority`){if(i.source!==`active_wallet_authority`)throw Error(`[SigningEngine][ecdsa-export] active lane material source changed`);return{kind:`active_wallet_authority`,exportLane:r,exportMaterial:i}}if(i.source!==`canonical_capability`)throw Error(`[SigningEngine][ecdsa-export] canonical lane material source changed`);return{kind:`canonical_capability`,exportLane:r,exportMaterial:i}}function Yt(e){if(!(!e||e.source!==`canonical_capability`||!e.authorization))return e.authorization.operationCredential.walletSessionId}function Xt(e){let t=e.exportLane?.publicFacts,n=e.exportLane?g({walletId:e.exportLane.key.walletId,publicFacts:e.exportLane.publicFacts}):void 0;try{console.warn(`[SigningEngine][ecdsa-export][failure]`,{operationId:e.flowId,authMethod:e.exportLane?.authMethod,...n?{evmFamilyKeyFingerprint:n}:{},...t?{keyHandle:String(t.keyHandle)}:{},chainTargetKey:u(e.input.chainTarget),...Yt(e.exportLane)?{walletSessionId:Yt(e.exportLane)}:{},materialActivationId:e.exportLane?.laneIdentity.signer.materialActivation.activationId,freshAuthRetrySideEffectState:`not_applicable`,error:e.error instanceof Error?e.error.message:String(e.error||`unknown error`)})}catch{}}async function Zt(e,t,n){let r=l(t.walletSession.walletId);if(n.kind===`active_wallet_authority`)return await lt(e.ecdsa,{walletId:r,exportLane:n.exportLane,material:n.exportMaterial,options:{variant:t.options.variant,theme:t.options.theme},flowId:t.flowId,onEvent:t.options.onEvent});if(n.exportMaterial.kind===`fresh_email_otp_route_auth_ready`)return await ut(e.ecdsa,{walletId:r,exportLane:n.exportLane,material:n.exportMaterial,options:{variant:t.options.variant,theme:t.options.theme},flowId:t.flowId,onEvent:t.options.onEvent});if(n.exportMaterial.kind===`fresh_passkey_needs_authorization`)return await dt(e.ecdsa,{walletId:r,exportLane:n.exportLane,material:n.exportMaterial,options:{variant:t.options.variant,theme:t.options.theme},flowId:t.flowId,onEvent:t.options.onEvent});throw n.exportMaterial,Error(`[SigningEngine][ecdsa-export] unsupported export material`)}async function Qt(e,t,n){let[r]=await Promise.all([Jt(e,t),e.ecdsa.touchConfirm.initialize()]);if(r.exportLane.authorizationState===`authorization_required`)try{return await Zt(e,t,r)}catch(e){throw Xt({input:t,flowId:t.flowId,exportLane:r.exportLane,exportMaterial:r.exportMaterial,error:e}),e}let i={kind:`ecdsa`,laneIdentity:r.exportLane.laneIdentity,authorization:r.exportLane.authorization},a=await Kt({deps:e,request:{kind:`ecdsa`,laneIdentity:r.exportLane.laneIdentity,authorization:r.exportLane.authorization,nowMs:Date.now()}});try{return await Zt(e,t,r)}catch(o){Xt({input:t,flowId:t.flowId,exportLane:r.exportLane,exportMaterial:r.exportMaterial,error:o});let s=be(o);if(n.kind===`fresh_auth_retry`||s?.kind!==`expired`)throw o;let c=qt({source:i,preflightState:a,detectedAtMs:Date.now()});if(!c)throw o;return await Gt({deps:e,state:c,source:oe.serverRejection}),await Qt(e,t,{kind:`fresh_auth_retry`})}}async function $t(e,t){return await Ht(e.ed25519Yao,{walletId:t.walletSession.walletId,nearAccountId:t.nearAccount.accountId,laneIdentity:t.laneIdentity,materialActivation:t.materialActivation,options:{variant:t.options.variant,theme:t.options.theme},flowId:t.flowId,onEvent:t.options.onEvent})}async function en(e,t){return await Ue(t,async t=>{switch(t.kind){case`ecdsa`:return await Qt(e,t,{kind:`initial`});case`ed25519`:return await $t(e,t)}})}async function tn(e,t){return await Ct(e.laneSelection,t)}export{en as exportKeypairWithUI,tn as resolveExactKeyExportLane};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,S as t}from"./chains-C_X_fNuS.js";import{n}from"./walletRegistrationSetupPrewarm-B9kpnrbK.js";import{_ as r,c as i,f as a,g as o,h as s,l as c,m as l,n as u,o as d,t as f,v as p}from"./messages-DgJlG9NU.js";import{a as m,c as h,i as g,l as _,n as v,o as y,s as b,t as x,u as S}from"./transactionReviewAdmission-CIvR4W5_.js";import{t as C}from"./events-1dzC4Ocx.js";import{t as w}from"./walletIframeIdentity-Cz82I_Uh.js";import{t as T}from"./errors-DIWY1KR9.js";function E(){let e=globalThis;e.global===void 0&&(e.global=globalThis),!e.process||typeof e.process!=`object`?e.process={env:{}}:(!e.process.env||typeof e.process.env!=`object`)&&(e.process.env={})}function D(){E(),window.location.origin===`null`&&(window.parent?.postMessage({type:`SERVICE_HOST_DEBUG_ORIGIN`,origin:window.location.origin,href:window.location.href},`*`),console.warn(`[WalletHost] iframe is running with opaque (null) origin. Check COEP/CORP headers and ensure navigation succeeded.`)),O(),window.parent?.postMessage({type:`SERVICE_HOST_BOOTED`},`*`),window.parent?.postMessage({type:`SERVICE_HOST_DEBUG_ORIGIN`,origin:window.location.origin,href:window.location.href},`*`);let e=new URL(import.meta.url),t=e.searchParams.get(`v`);t&&l(t);let n=new URL(`.`,e).toString(),r=n.endsWith(`/`)?n:n+`/`;a()||s(r)}function O(){let e=()=>{let e=document;e.documentElement.classList.add(`seams-transparent`),e.body?.classList.add(`seams-transparent`),e.documentElement.classList.remove(`dark`),e.body?.classList.remove(`dark`)};document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>e(),{once:!0}):e(),window.addEventListener(`load`,()=>e(),{once:!0})}const k={};let A=null,j=null;function M(e){return e.type===`PM_ACKNOWLEDGE_WALLET_RECOVERY_CODE_BACKUP`?(A??=import(`./runtime-recovery-codes-rLR4Guy4.js`),A):(k[e.kind]??=P(e.kind),k[e.kind])}async function N(){A??=import(`./runtime-recovery-codes-rLR4Guy4.js`),j??=Promise.all([A,import(`./mountRecoveryCodeBackupSurface-D1G-iCPI.js`)]).then(()=>void 0),await j}function P(e){switch(e){case`auth`:return import(`./runtime-auth-D7VqiZeg.js`);case`near`:return import(`./runtime-near-nq8pgRAl.js`);case`ecdsa`:return import(`./runtime-ecdsa-tempo-DC51NDrh.js`);case`email_otp`:return import(`./runtime-email-otp-C-wopKFf.js`);case`recovery`:return import(`./runtime-recovery-B-JsRiN0.js`);case`export`:return import(`./runtime-export-BtGy8BKi.js`);case`device_link`:return import(`./runtime-device-link-BKc_MD5V.js`);case`preferences`:return import(`./runtime-preferences-778ZfMmT.js`)}return F(e)}function F(e){throw Error(`Unhandled wallet host runtime route: ${String(e)}`)}function I(e){throw Error(`Unhandled wallet host route: ${String(e)}`)}function L(e,t){if(e===null)throw Error(`Invalid ${t} payload`);return e}function R(e){try{return w(e)}catch{throw Error(`Hosted auth-menu request requires a non-empty requestId`)}}function z(e){switch(e.type){case`PM_ACTIVATE_TRANSACTION_REVIEW`:case`PING`:case`PM_SET_CONFIG`:case`PM_CANCEL`:case`PM_SET_TRANSACTION_VIEW`:case`PM_TRANSACTION_BROADCAST_STARTED`:return{kind:`boot`,type:e.type,request:e};case`PM_REGISTER_WALLET`:case`PM_ADD_WALLET_SIGNER`:case`PM_ADD_PASSKEY`:case`PM_ADD_EMAIL_OTP`:case`PM_REVOKE_AUTH_METHOD`:case`PM_GET_NEAR_PROVISIONING_STATE`:case`PM_SIGN_TX_WITH_ACTIONS`:case`PM_SIGN_AND_SEND_TX`:case`PM_SEND_TRANSACTION`:case`PM_SIGN_DELEGATE_ACTION`:case`PM_SIGN_NEP413`:return{kind:`near`,type:e.type,request:e};case`PM_OPEN_AUTH_MENU`:{let t=R(e.requestId);return{kind:`auth`,type:e.type,request:{...e,requestId:t,payload:L(c(e.payload),`hosted auth-menu open`)}}}case`PM_CANCEL_AUTH_MENU`:{let t=R(e.requestId);return{kind:`auth`,type:e.type,request:{...e,requestId:t,payload:L(d(e.payload),`hosted auth-menu cancellation`)}}}case`PM_RESOLVE_AUTH_MENU_EXTERNAL_AUTH`:{let t=R(e.requestId);return{kind:`auth`,type:e.type,request:{...e,requestId:t,payload:L(i(e.payload),`hosted auth-menu external-auth resolution`)}}}case`PM_UNLOCK`:case`PM_LOCK`:case`PM_LOCK_EXACT_WALLET_SESSION`:case`PM_GET_LAST_WALLET_MOVE_REQUEST`:case`PM_MOVE_WALLET`:case`PM_GET_WALLET_MOVE`:case`PM_GET_WALLET_PLACEMENT`:case`PM_GET_WALLET_SESSION`:case`PM_GET_EXACT_WALLET_SESSION_STATE`:case`PM_GET_RECENT_UNLOCKS`:return{kind:`auth`,type:e.type,request:e};case`PM_SIGN_TEMPO`:case`PM_REPORT_TEMPO_BROADCAST_ACCEPTED`:case`PM_REPORT_TEMPO_BROADCAST_REJECTED`:case`PM_REPORT_TEMPO_FINALIZED`:case`PM_REPORT_TEMPO_DROPPED_OR_REPLACED`:case`PM_RECONCILE_TEMPO_NONCE_LANE`:return{kind:`ecdsa`,type:e.type,request:e};case`PM_REDEEM_HOSTED_WALLET_SEAMS_SESSION`:case`PM_REQUEST_EMAIL_OTP_CHALLENGE`:case`PM_BEGIN_GOOGLE_EMAIL_OTP_WALLET_AUTH`:case`PM_GOOGLE_EMAIL_OTP_WALLET_AUTH_RESEND`:case`PM_GOOGLE_EMAIL_OTP_WALLET_AUTH_REROLL_WALLET_ID`:case`PM_GOOGLE_EMAIL_OTP_WALLET_AUTH_SUBMIT`:case`PM_GOOGLE_EMAIL_OTP_WALLET_AUTH_COMPLETE_REGISTRATION`:case`PM_GOOGLE_EMAIL_OTP_WALLET_AUTH_CANCEL`:case`PM_GET_WALLET_RECOVERY_CODE_STATUS`:case`PM_ACKNOWLEDGE_WALLET_RECOVERY_CODE_BACKUP`:case`PM_ROTATE_WALLET_RECOVERY_CODES`:case`PM_REQUEST_WALLET_CUSTODY_EMAIL_OTP_CHALLENGE`:return{kind:`email_otp`,type:e.type,request:e};case`PM_SYNC_ACCOUNT_FLOW`:return{kind:`recovery`,type:e.type,request:e};case`PM_RESOLVE_EXACT_KEY_EXPORT_LANE`:case`PM_EXPORT_KEYPAIR_UI`:return{kind:`export`,type:e.type,request:e};case`PM_HAS_PASSKEY`:case`PM_LIST_LINKED_DEVICES`:case`PM_REVOKE_LINKED_DEVICE`:case`PM_SCAN_AND_LINK_DEVICE`:case`PM_START_DEVICE2_LINKING_FLOW`:case`PM_DEVICE_LINK_TARGET_FACTOR_ACTION`:case`PM_DEVICE_LINK_EMAIL_OTP_BASE_FACTOR_ACTION`:case`PM_CANCEL_DEVICE_LINKING`:return{kind:`device_link`,type:e.type,request:e};case`PM_SET_CONFIRM_BEHAVIOR`:case`PM_SET_CONFIRMATION_CONFIG`:case`PM_GET_CONFIRMATION_CONFIG`:return{kind:`preferences`,type:e.type,request:e}}return I(e)}function B(e){return e.kind!==`boot`}let V=!1;const H=[{selector:`.seams-auth-menu-surface`,cancellationKind:`native_cancel`},{selector:`.seams-confirmation-surface`,cancellationKind:`native_cancel`},{selector:`.seams-export-surface`,cancellationKind:`wallet_iframe_cancel`},{selector:`[data-seams-wallet-recovery-backup-dialog]`,cancellationKind:`native_cancel`}];function U(e,t){let n=new Set(t),r=Object.keys(e);return r.length===t.length&&r.every(e=>n.has(e))}function W(t){return!e(t)||!U(t,[`type`,`payload`])||t.type!==`CONNECT`||!e(t.payload)||!U(t.payload,[`protocolVersion`])?null:typeof t.payload.protocolVersion==`string`?{type:`CONNECT`,payload:{protocolVersion:t.payload.protocolVersion}}:null}function G(e){if(e===`null`)return!0;try{let t=new URL(e);return(t.protocol===`https:`||t.protocol===`http:`)&&t.origin===e}catch{return!1}}function K(e){try{e.close()}catch{}}function q(e,t){if(t===`15.0.0`)return!1;let n={expectedProtocolVersion:u,receivedProtocolVersion:t};try{e.postMessage({type:`ERROR`,payload:{code:f,message:`Wallet iframe protocol version mismatch: expected ${u}, received ${t??`missing`}`,details:n}})}catch{}return K(e),!0}function J(e,t){return!t||t.has(e.kind)}function Y(e,t,n,r){e.executionGeneration===t&&n(r)}function X(e,t,n,r){return e.executionGeneration!==t||n(r)}function Z(e={}){if(V)return;V=!0,D(),(!e.supportedRuntimeRouteKinds||e.supportedRuntimeRouteKinds.has(`email_otp`))&&N().catch(()=>void 0);let i=new Set,a=new Set,s={parentOrigin:null,port:null,configuration:{kind:`unconfigured`},executionGeneration:0,onConfigurationChanged:null},c=e=>{try{s.port?.postMessage(e)}catch{}},l=e=>{e&&i.add(e)},d=e=>!!e&&(i.has(e)||g(e)?.cancelled===!0),f=e=>{e&&i.delete(e)},w=e=>{e&&c({type:`ERROR`,requestId:e,payload:{code:`cancelled`,message:`Request cancelled`}})},E=e=>!e||!d(e)?!1:g(e)?.cancelled?!0:(w(e),f(e),!0),O=()=>{for(let e of H){let t=document.querySelectorAll(e.selector);for(let n of t)try{e.cancellationKind===`native_cancel`?n.dispatchEvent(new Event(`cancel`,{cancelable:!0})):n.dispatchEvent(new CustomEvent(C.TX_CONFIRMER_CANCEL,{bubbles:!0,composed:!0}))}catch{}}},k=async i=>{let u=i.data;if(!u||!t(u))return;let C=u.requestId,D=s.executionGeneration,k=Y.bind(null,s,D,c),A=null;try{if(`transactionReview`in u){if(u.type!==`PM_SIGN_AND_SEND_TX`&&u.type!==`PM_SIGN_TEMPO`)throw new m(`review_invalid_input`,`Review is unsupported for this request`);let e=h(u.transactionReview);if(e.requestId!==C)throw new m(`review_invalid_input`,`Review request identity mismatch`);let t=u.payload?.options?.confirmationConfig;if(t?.uiMode!==`modal`||t.behavior!==`requireClick`)throw new m(`review_unsupported_mode`,`Review requires modal presentation and explicit approval`);A=new x(e,u.type===`PM_SIGN_TEMPO`&&u.payload?.request.senderSignatureAlgorithm!==`secp256k1`?`credential`:`mpc`,e=>k({type:`TRANSACTION_REVIEW_STATE`,requestId:C,payload:e}),e=>k({type:`ERROR`,requestId:C,payload:{code:e instanceof m?e.code:`cancelled`,message:e.message}}))}(u.type===`PM_LOCK`||u.type===`PM_LOCK_EXACT_WALLET_SESSION`)&&v(new m(`review_identity_changed`,`The wallet session changed`));let t=z(u);if(!B(t))switch(t.type){case`PING`:c({type:`PONG`,requestId:C});return;case`PM_SET_CONFIG`:{let e=o(s.configuration,r(t.request.payload)),i=p(s.configuration.kind===`configured`?s.configuration.config:null)!==p(e.config);if(s.configuration=e,i){s.executionGeneration+=1;let t=e.config;t.registration.publishableKey&&t.registration.projectEnvironmentId&&n(t.network.relayer.url);for(let e of a)c({type:`ERROR`,requestId:e,payload:{code:`wallet_configuration_changed`,message:`Wallet configuration changed during request`}});a.clear()}s.onConfigurationChanged?.(),i&&(v(new m(`review_identity_changed`,`Wallet execution configuration changed`)),O()),c({type:`PONG`,requestId:C});return}case`PM_ACTIVATE_TRANSACTION_REVIEW`:{let e=b(t.request.payload);e&&g(e.requestId)?.activate(e);return}case`PM_CANCEL`:{let e=t.request.payload?.requestId,n=t.request.payload,r=n&&typeof n==`object`?Reflect.get(n,`transactionReview`):void 0;if(r!==void 0){let t=h(r),i=g(t.requestId);if(t.requestId===e&&i&&_(t,i.metadata)){let e=new m(S(n&&typeof n==`object`?Reflect.get(n,`reviewErrorCode`):void 0),`Reviewed request cancelled`);try{y(i.metadata.validity)}catch(t){t instanceof Error&&(e=t)}i.cancel(e)}c({type:`PONG`,requestId:C});return}let i=e?g(e):void 0;if(i){i.cancel(new m(`cancelled`,`Request cancelled`)),c({type:`PONG`,requestId:C});return}l(e),O(),e&&w(e),c({type:`PONG`,requestId:C});return}case`PM_SET_TRANSACTION_VIEW`:{let e=t.request.payload,n=e&&typeof e==`object`?Reflect.get(e,`requestId`):null,r=e&&typeof e==`object`?Reflect.get(e,`view`):null;typeof n==`string`&&(r===`toast`||r===`closed`)&&(await import(`./transaction-activity-xfeHKJoq.js`).then(e=>e.o)).setTransactionActivityView(n,r);return}case`PM_TRANSACTION_BROADCAST_STARTED`:{let e=t.request.payload,n=e&&typeof e==`object`?Reflect.get(e,`signedTransaction`):null;typeof n==`string`&&(await import(`./transaction-activity-xfeHKJoq.js`).then(e=>e.o)).transactionBroadcastStarted(n);return}}if(!J(t,e.supportedRuntimeRouteKinds)){c({type:`ERROR`,requestId:C,payload:{code:`unsupported_request`,message:`Unsupported wallet iframe request type: ${t.type}`}});return}C&&a.add(C);let i=await M(t);if(D!==s.executionGeneration)return;await i.handleWalletHostRuntimeRequest({transactionReview:A,state:s,executionGeneration:D,req:t.request,post:Y.bind(null,s,D,c),isCancelled:X.bind(null,s,D,d),respondIfCancelled:X.bind(null,s,D,E)})}catch(e){if(D!==s.executionGeneration&&u.type!==`PM_SET_CONFIG`||A?.cancelled)return;let t=await import(`./canonicalSignerErrorCode-Cz48v4oy.js`);if(D!==s.executionGeneration&&u.type!==`PM_SET_CONFIG`)return;let n=e&&typeof e==`object`&&`code`in e?e.code:void 0,r=T(e),i=t.resolveWalletBoundaryErrorCode({requestType:u.type,rawCode:n,message:r,defaultCode:`HOST_ERROR`}),a=t.resolveWalletBoundaryErrorMessage({requestType:u.type,rawCode:n,code:i,message:r}),o=t.resolveWalletBoundarySignerKind(u.type);c({type:`ERROR`,requestId:C,payload:{code:i,message:a,...t.isWalletSignerBoundaryRequestType(u.type)&&t.isCanonicalSignerSessionBoundaryCode(i)&&o?{signerKind:o}:{}}})}finally{C&&(a.delete(C),f(C)),A?.finish()}};window.addEventListener(`message`,e=>{let t=W(e.data),n=e.ports[0];if(!(!t||!n||s.port)){if(e.source!==window.parent||!G(e.origin)){K(n);return}if(!q(n,t.payload.protocolVersion)){typeof e.origin==`string`&&e.origin.length&&e.origin!==`null`&&(s.parentOrigin=e.origin),s.port=n;try{s.port.onmessage=k,s.port.start?.()}catch{}c({type:`READY`,payload:{protocolVersion:u}})}}})}try{Z()}catch(e){console.error(`[WalletHost] init failed`,e)}export{Z as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{M as e,O as t,T as n}from"./domainIds-BzkGsRqO.js";import{C as r,T as i,b as a,k as o,n as s,r as c}from"./chains-C_X_fNuS.js";import"./signingSessionSeal-DX41aXUL.js";import{t as l}from"./configBuilder-BMawmNpz.js";import{r as u}from"./activeWalletSession-WdZkhtBB.js";import{t as d}from"./walletIframeIdentity-Cz82I_Uh.js";function f(e){return r(e)&&Object.values(e).every(i)}function p(e){if(!r(e)||e.palette!==`default`||!r(e.theme))return!1;let t=e.theme;return i(t.id)&&t.id.trim().length>0&&(t.mode===`dark`||t.mode===`light`)&&f(t.colors)&&(t.shape===void 0||f(t.shape))}function m(e){return!r(e)||!c(e.network)?!1:i(e.rpcUrl)&&e.rpcUrl.trim().length>0&&i(e.explorerUrl)&&(s(e.network)||a(e.chainId)&&Number.isSafeInteger(e.chainId)&&e.chainId>0)}function h(e){if(!r(e)||!Array.isArray(e.chains)||!e.chains.every(m))return!1;let t=e.relayer;return r(t)&&i(t.accountId)&&i(t.url)&&t.url.trim().length>0&&r(t.routes)&&i(t.routes.delegateAction)}function g(e){if(!r(e)||e.mode!==`managed`)return!1;let t=e.nearAccountProvisioning;return i(e.publishableKey)&&i(e.projectEnvironmentId)&&(e.paymentMode===`disabled`||e.paymentMode===`quota_then_x402`||e.paymentMode===`always_x402`)&&r(t)&&(t.kind===`implicit_account`||t.kind===`relayer_named_subaccount`)}function _(e){return r(e)&&a(e.ttlMs)&&a(e.remainingUses)}function v(e){if(!r(e)||typeof e.enabled!=`boolean`||!_(e.signingSession))return!1;let t=o(e.signingSession,`signingSession`);return t.kind===`jwt`||t.kind===`cookie`}function y(e){return r(e)?e.mode===`disabled`?e.signingWorkerId===void 0:e.mode===`enabled`&&i(e.signingWorkerId)&&e.signingWorkerId.trim().length>0:!1}function ee(e){return r(e)?typeof e.enabled==`boolean`&&a(e.targetDepth)&&Number.isInteger(e.targetDepth)&&e.targetDepth>=l.targetDepth.min&&e.targetDepth<=l.targetDepth.max&&a(e.lowWatermark)&&Number.isInteger(e.lowWatermark)&&e.lowWatermark>=0&&e.lowWatermark<=e.targetDepth&&a(e.maxRefillInFlight)&&Number.isInteger(e.maxRefillInFlight)&&e.maxRefillInFlight>=l.maxRefillInFlight.min&&e.maxRefillInFlight<=l.maxRefillInFlight.max&&a(e.refillAttemptTimeoutMs)&&Number.isInteger(e.refillAttemptTimeoutMs)&&e.refillAttemptTimeoutMs>=l.refillAttemptTimeoutMs.min&&e.refillAttemptTimeoutMs<=l.refillAttemptTimeoutMs.max:!1}function te(e){if(!r(e)||!_(e.sessionDefaults)||!r(e.emailOtp)||e.emailOtp.authPolicy!==`session`&&e.emailOtp.authPolicy!==`per_operation`||!r(e.routerAb)||!y(e.routerAb.normalSigning)||!r(e.routerAbEcdsaDerivation)||!ee(e.routerAbEcdsaDerivation.presignaturePool)||!r(e.thresholdEcdsa)||!r(e.thresholdEcdsa.provisioningDefaults))return!1;let t=e.thresholdEcdsa.provisioningDefaults;if(!v(t.tempo)||!v(t.evm))return!1;let n=e.sessionSeal;return r(n)?e.sessionPersistenceMode===`none`?n.mode===`none`&&n.protocol===void 0:e.sessionPersistenceMode===`sealed_refresh_v1`&&n.mode===`sealed_refresh_v1`&&r(n.protocol)&&n.protocol.algorithm===`shamir3pass-v2`&&n.protocol.groupId===`rfc2409-group2`:!1}function ne(e){if(!r(e)||!r(e.authenticatorOptions))return!1;let t=e.authenticatorOptions;if(t.userVerification!==`required`&&t.userVerification!==`preferred`&&t.userVerification!==`discouraged`)return!1;let n=t.originPolicy;return r(n)&&(n.single===void 0||typeof n.single==`boolean`)&&(n.all_subdomains===void 0||typeof n.all_subdomains==`boolean`)&&(n.multiple===void 0||Array.isArray(n.multiple)&&n.multiple.every(i))}function b(t){if(!r(t)||t.mode!==`direct`||t.iframe!==void 0)return!1;let n=e(t.rpId);return n.ok&&n.value===t.rpId}function x(e){return r(e)&&h(e.network)&&g(e.registration)&&te(e.signing)&&ne(e.webauthn)&&b(e.wallet)&&r(e.ui)&&p(e.ui.appearance)}function S(e){if(!x(e))throw Error(`Invalid resolved wallet host configuration`);return e}function C(e,t){return{network:e.network,registration:e.registration,signing:e.signing,webauthn:e.webauthn,wallet:e.wallet,ui:{appearance:t}}}function w(e){let t=o(e,`wallet configuration update`);if(t.kind===`configure`&&i(t.assetsBaseUrl)&&t.assetsBaseUrl.length>0&&t.appearance===void 0)return{kind:`configure`,config:S(t.config),assetsBaseUrl:t.assetsBaseUrl};if(t.kind===`appearance`&&p(t.appearance)&&t.config===void 0&&t.assetsBaseUrl===void 0)return{kind:`appearance`,appearance:t.appearance};throw Error(`Invalid wallet configuration update`)}function T(e,t){switch(t.kind){case`configure`:return{kind:`configured`,config:t.config,assetsBaseUrl:t.assetsBaseUrl};case`appearance`:if(e.kind!==`configured`)throw Error(`Wallet configuration is required before appearance updates`);return{kind:`configured`,config:C(e.config,t.appearance),assetsBaseUrl:e.assetsBaseUrl}}}function E(e){if(Array.isArray(e))return e.map(E);if(e&&typeof e==`object`){let t=e,n={};for(let e of Object.keys(t).sort())n[e]=E(t[e]);return n}return e}function D(e){return JSON.stringify(E({network:e?.network,registration:e?.registration,signing:e?.signing,webauthn:e?.webauthn,rpId:e?.wallet.rpId}))}const O=`__SEAMS_WALLET_SDK_BASE__`,k=`SEAMS_WALLET_SDK_BASE_CHANGED`,A=`__SEAMS_WALLET_ASSET_VERSION__`;function re(){if(typeof window>`u`)return;let e=window[O];return typeof e==`string`&&e.length>0?e:void 0}function j(e){if(typeof window>`u`)return;let t=window;t[O]=e,window.dispatchEvent(new CustomEvent(k,{detail:e}))}function M(){if(typeof window>`u`)return;let e=window[A];return typeof e==`string`&&e.length>0?e:void 0}function N(e){if(typeof window>`u`)return;let t=e.trim();t&&(window[A]=t)}function P(e){if(typeof window>`u`)return()=>{};let t=t=>{let n=t.detail;typeof n==`string`&&n.length>0&&e(n)};return window.addEventListener(k,t,{passive:!0}),()=>window.removeEventListener(k,t)}const F={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 I(e,t){return typeof e==`string`&&e.trim()||null}function L(e,t){let n=I(e,t);return n===null?null:n}function R(e){try{return d(e)}catch{return null}}function z(e,t){let n=new Set(t);return Object.keys(e).every(e=>n.has(e))}function B(e){return L(e,`authMenuSessionId`)}function V(e){return L(e,`externalAuthRequestId`)}function H(e){return r(e)?e:null}function U(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=>U(e,t,n));let r=H(e);return r!==null&&Object.values(r).every(e=>U(e,t,n))}function W(e,t){return I(e,`copy`)??t}function G(e,t){let n=H(e);return{title:W(n?.title,t.title),subtitle:W(n?.subtitle,t.subtitle),passkeyCta:W(n?.passkeyCta,t.passkeyCta)}}function K(e){let t=H(e),n=H(t?.register);return{login:G(t?.login,F.login),register:{...G(t?.register,F.register),passkeyNameLabel:W(n?.passkeyNameLabel,F.register.passkeyNameLabel)},common:{closeLabel:W(H(t?.common)?.closeLabel,F.common.closeLabel)}}}function ie(e){return e===`google`?e:null}function q(e){return e===`login`||e===`register`?e:null}function J(e){return e===`implicit_wallet`||e===`sponsored_named_near_account`?e:null}function Y(e){return e===`close_button`||e===`component_unmounted`||e===`connection_closed`?e:null}function X(e,t){if(e===void 0)return!0;let n=H(e);return n!==null&&z(n,t)}function ae(e){let t=H(e);return!t||!z(t,[`login`,`register`,`common`])?!1:X(t.login,[`title`,`subtitle`,`passkeyCta`])&&X(t.register,[`title`,`subtitle`,`passkeyCta`,`passkeyNameLabel`])&&X(t.common,[`closeLabel`])}function oe(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 se(e){let n=H(e);if(!n||!U(n,new Set,!0)||n.kind!==`hosted_auth_menu_open_v1`||!z(n,[`kind`,`authMenuSessionId`,`initialMode`,`loginTarget`,`registrationAccountInput`,`showRegistrationInput`,`showProgress`,`copy`,`enabledExternalProviders`])||!ae(n.copy))return null;let r=B(n.authMenuSessionId),i=q(n.initialMode),a=H(n.loginTarget),o=a?.kind===`wallet`||a?.kind===`wallet_sync`?t(a.walletId):null,s=a?.kind===`discoverable`&&z(a,[`kind`])?{kind:`discoverable`}:a?.kind===`wallet`&&z(a,[`kind`,`walletId`])&&o?.ok?{kind:`wallet`,walletId:o.value}:a?.kind===`wallet_sync`&&z(a,[`kind`,`walletId`])&&o?.ok?{kind:`wallet_sync`,walletId:o.value}:null,c=J(n.registrationAccountInput),l=oe(n.enabledExternalProviders);return!r||!i||!s||!c||typeof n.showRegistrationInput!=`boolean`||typeof n.showProgress!=`boolean`||!l||!U(n.copy,new Set,!0)?null:{kind:`hosted_auth_menu_open_v1`,authMenuSessionId:r,initialMode:i,loginTarget:s,registrationAccountInput:c,showRegistrationInput:n.showRegistrationInput,showProgress:n.showProgress,copy:K(n.copy),enabledExternalProviders:l}}function ce(e){let t=H(e);if(!t||!U(t)||t.kind!==`hosted_auth_menu_error_v1`||!z(t,[`kind`,`authMenuSessionId`,`mode`,`message`]))return null;let n=B(t.authMenuSessionId),r=q(t.mode),i=I(t.message,`message`);return n&&r&&i?{kind:t.kind,authMenuSessionId:n,mode:r,message:i}:null}function le(e){let t=H(e);if(!t||!U(t))return null;switch(t.kind){case`google_id_token`:{if(!z(t,[`kind`,`idToken`]))return null;let e=I(t.idToken,`idToken`);return e?{kind:t.kind,idToken:e}:null}case`cancelled`:return z(t,[`kind`,`reason`])&&t.reason===`user_cancelled`?{kind:t.kind,reason:t.reason}:null;case`failed`:{if(!z(t,[`kind`,`code`,`message`]))return null;let e=t.code===`provider_unavailable`||t.code===`provider_error`||t.code===`invalid_evidence`?t.code:null,n=I(t.message,`message`);return e&&n?{kind:t.kind,code:e,message:n}:null}default:return null}}function ue(e){let t=H(e);if(!t||!U(t)||t.kind!==`hosted_auth_menu_external_auth_resolution_v1`||!z(t,[`kind`,`authMenuSessionId`,`externalAuthRequestId`,`requestId`,`evidence`]))return null;let n=B(t.authMenuSessionId),r=V(t.externalAuthRequestId),i=R(t.requestId),a=le(t.evidence);return!n||!r||!i||!a?null:{kind:t.kind,authMenuSessionId:n,externalAuthRequestId:r,requestId:i,evidence:a}}function de(e){let t=H(e);if(!t||!U(t)||t.kind!==`hosted_auth_menu_cancel_v1`||!z(t,[`kind`,`authMenuSessionId`,`requestId`,`reason`]))return null;let n=B(t.authMenuSessionId),r=R(t.requestId),i=Y(t.reason);return n&&r&&i?{kind:t.kind,authMenuSessionId:n,requestId:r,reason:i}:null}const fe=`15.0.0`,pe=`WALLET_IFRAME_PROTOCOL_VERSION_MISMATCH`,Z=[`home`,`exchangeCode`,`nonce`,`appOrigin`,`walletOrigin`,`relayUrl`];function Q(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 $(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 me(e){if(!r(e))throw Error(`hosted-wallet redemption payload must be an exact object`);if(Object.keys(e).length!==Z.length)throw Error(`hosted-wallet redemption payload fields are invalid`);for(let t of Z)if(!Object.hasOwn(e,t))throw Error(`hosted-wallet redemption payload fields are invalid`);return{home:u(e.home),exchangeCode:Q(e.exchangeCode,`exchangeCode`),nonce:Q(e.nonce,`nonce`),appOrigin:$(e.appOrigin,`appOrigin`),walletOrigin:$(e.walletOrigin,`walletOrigin`),relayUrl:Q(e.relayUrl,`relayUrl`)}}function he(e){if(!r(e)||!z(e,[`scanRequestId`,`action`])||typeof e.scanRequestId!=`string`||e.scanRequestId.length===0||!r(e.action))return null;let t=e.action;if(t.kind===`cancel`)return z(t,[`kind`])?{scanRequestId:e.scanRequestId,action:{kind:t.kind}}:null;if(t.kind!==`select`||!z(t,[`kind`,`baseWalletAuthMethodId`]))return null;let i=n(t.baseWalletAuthMethodId);return i.ok?{scanRequestId:e.scanRequestId,action:{kind:t.kind,baseWalletAuthMethodId:i.value}}:null}function ge(e){if(!r(e)||!z(e,[`activationId`,`action`])||typeof e.activationId!=`string`||e.activationId.length===0||!r(e.action))return null;let t=e.action;switch(t.kind){case`create_passkey`:case`send_email_otp`:case`resend_email_otp`:return z(t,[`kind`])?{activationId:e.activationId,action:{kind:t.kind}}:null;case`submit_email_otp`:return z(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}}export{w as _,ge as a,ue as c,M as d,re as f,T as g,j as h,he as i,se as l,N as m,fe as n,de as o,P as p,V as r,ce as s,pe as t,me as u,D as v};
|