@seams/wallet 0.14.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.build-inputs.sha256 +1 -1
- package/dist/esm/SeamsWeb/publicApi/keyExport.js +0 -2
- package/dist/esm/SeamsWeb/walletIframe/client/router.js +0 -4
- package/dist/esm/SeamsWeb/walletIframe/shared/facadeBoundary.js +0 -4
- package/dist/esm/core/signingEngine/routerAb/ecdsaDerivation/presignaturePool.js +24 -27
- package/dist/esm/plugins/plugin-utils.js +2 -142
- package/dist/esm/react/components/AccountMenuButton/AccountMenuDialog.js +13 -89
- package/dist/esm/react/components/AccountMenuButton/AccountsSection.css +7 -1
- package/dist/esm/react/components/AccountMenuButton/AuthenticationMethodRow.js +2 -8
- package/dist/esm/react/components/AccountMenuButton/AuthenticationMethodsModal.js +4 -17
- package/dist/esm/react/components/AccountMenuButton/ExportKeysSection.css +7 -1
- package/dist/esm/react/components/AccountMenuButton/LinkedDevicesModal.css +0 -68
- package/dist/esm/react/components/AccountMenuButton/LinkedDevicesModal.js +2 -11
- package/dist/esm/react/components/AccountMenuButton/Web3AuthProfileButton.css +95 -3
- package/dist/esm/react/components/AccountMenuButton/icons/HoverArrowIcon.js +26 -0
- package/dist/esm/react/components/AccountMenuButton/index.js +4 -4
- package/dist/esm/react/styles/styles.css +102 -4
- package/dist/esm/sdk/ecdsaDerivationExport-DOGzq0qC.js +1 -0
- package/dist/esm/sdk/exportKeypairOperation-DzbjKbnk.js +1 -0
- package/dist/esm/sdk/{host-D3Q_NsmE.js → host-DYuu07E5.js} +1 -1
- package/dist/{public/sdk/presignaturePool-DX_hqZ6Z.js → esm/sdk/presignaturePool-V10fZpG3.js} +1 -1
- package/dist/esm/sdk/{runtime-auth-DDOPe7LO.js → runtime-auth-BNR1wI8E.js} +1 -1
- package/dist/esm/sdk/{runtime-device-link-Bkt5AJAI.js → runtime-device-link-Dq8g_UNb.js} +1 -1
- package/dist/{public/sdk/runtime-ecdsa-tempo-DUOkCNFT.js → esm/sdk/runtime-ecdsa-tempo-AGjT7Xpa.js} +1 -1
- package/dist/esm/sdk/{runtime-email-otp-Bsv55Gin.js → runtime-email-otp-BpBOuSsT.js} +1 -1
- package/dist/esm/sdk/{runtime-export-D7QKXvdg.js → runtime-export-CBsacCPY.js} +1 -1
- package/dist/esm/sdk/{runtime-near-Bl7bBU2g.js → runtime-near-J3hKjC7G.js} +1 -1
- package/dist/esm/sdk/{runtime-preferences-C2Rqmp7q.js → runtime-preferences-CVt5sLvm.js} +1 -1
- package/dist/esm/sdk/{runtime-recovery-BMY7AkJq.js → runtime-recovery-BzewdcoT.js} +1 -1
- package/dist/{public/sdk/secp256k1-CL273JMp.js → esm/sdk/secp256k1-CKq7_HD-.js} +1 -1
- package/dist/esm/sdk/shared-BywEqTsd.js +6 -0
- package/dist/esm/sdk/{signEvmFamily-BE0a14MT.js → signEvmFamily-Cpm3e6Zs.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/public/headers.manifest.json +1 -1
- package/dist/public/sdk/ecdsaDerivationExport-DOGzq0qC.js +1 -0
- package/dist/public/sdk/exportKeypairOperation-DzbjKbnk.js +1 -0
- package/dist/public/sdk/{host-D3Q_NsmE.js → host-DYuu07E5.js} +1 -1
- package/dist/{esm/sdk/presignaturePool-DX_hqZ6Z.js → public/sdk/presignaturePool-V10fZpG3.js} +1 -1
- package/dist/public/sdk/{runtime-auth-DDOPe7LO.js → runtime-auth-BNR1wI8E.js} +1 -1
- package/dist/public/sdk/{runtime-device-link-Bkt5AJAI.js → runtime-device-link-Dq8g_UNb.js} +1 -1
- package/dist/{esm/sdk/runtime-ecdsa-tempo-DUOkCNFT.js → public/sdk/runtime-ecdsa-tempo-AGjT7Xpa.js} +1 -1
- package/dist/public/sdk/{runtime-email-otp-Bsv55Gin.js → runtime-email-otp-BpBOuSsT.js} +1 -1
- package/dist/public/sdk/{runtime-export-D7QKXvdg.js → runtime-export-CBsacCPY.js} +1 -1
- package/dist/public/sdk/{runtime-near-Bl7bBU2g.js → runtime-near-J3hKjC7G.js} +1 -1
- package/dist/public/sdk/{runtime-preferences-C2Rqmp7q.js → runtime-preferences-CVt5sLvm.js} +1 -1
- package/dist/public/sdk/{runtime-recovery-BMY7AkJq.js → runtime-recovery-BzewdcoT.js} +1 -1
- package/dist/{esm/sdk/secp256k1-CL273JMp.js → public/sdk/secp256k1-CKq7_HD-.js} +1 -1
- package/dist/public/sdk/shared-BywEqTsd.js +6 -0
- package/dist/public/sdk/{signEvmFamily-BE0a14MT.js → signEvmFamily-Cpm3e6Zs.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/wallet-assets.manifest.json +32 -32
- package/dist/public/wallet-service/index.html +4 -4
- package/dist/types/shared-ts/src/device-linking/contracts.d.ts +0 -9
- package/dist/types/shared-ts/src/utils/routerAbEcdsaDerivation.d.ts +0 -1
- package/dist/types/wallet/src/SeamsWeb/operations/auth/login.d.ts +1 -2
- package/dist/types/wallet/src/SeamsWeb/publicApi/types.d.ts +2 -11
- package/dist/types/wallet/src/core/signingEngine/flows/recovery/keyExportFlow.d.ts +0 -3
- package/dist/types/wallet/src/core/signingEngine/routerAb/ecdsaDerivation/presignaturePool.d.ts +0 -19
- package/dist/types/wallet/src/core/signingEngine/session/identity/ownerLaneScope.d.ts +0 -27
- package/dist/types/wallet/src/plugins/plugin-utils.d.ts +0 -30
- package/dist/types/wallet/src/react/components/AccountMenuButton/AccountMenuDialog.d.ts +1 -9
- package/dist/types/wallet/src/react/components/AccountMenuButton/AuthenticationMethodsModal.d.ts +1 -1
- package/dist/types/wallet/src/react/components/AccountMenuButton/LinkedDevicesModal.d.ts +1 -1
- package/dist/types/wallet/src/react/components/AccountMenuButton/icons/HoverArrowIcon.d.ts +7 -0
- package/package.json +1 -1
- package/dist/esm/plugins/headers.js +0 -55
- package/dist/esm/plugins/next.js +0 -196
- package/dist/esm/plugins/shared-ts/src/utils/normalize.js +0 -31
- package/dist/esm/plugins/vite.js +0 -293
- package/dist/esm/react/components/AccountMenuButton/icons/LayersIcon.js +0 -8
- package/dist/esm/sdk/ecdsaDerivationExport-CuNIssOt.js +0 -1
- package/dist/esm/sdk/exportKeypairOperation-Bql0I-8U.js +0 -1
- package/dist/esm/sdk/shared-CNT5EU_h.js +0 -6
- package/dist/public/sdk/ecdsaDerivationExport-CuNIssOt.js +0 -1
- package/dist/public/sdk/exportKeypairOperation-Bql0I-8U.js +0 -1
- package/dist/public/sdk/shared-CNT5EU_h.js +0 -6
- package/dist/types/wallet/src/plugins/headers.d.ts +0 -25
- package/dist/types/wallet/src/plugins/next.d.ts +0 -66
- package/dist/types/wallet/src/plugins/vite.d.ts +0 -74
- package/dist/types/wallet/src/react/components/AccountMenuButton/icons/LayersIcon.d.ts +0 -2
- /package/dist/esm/plugins/{wallet/src/core → core}/browser/walletIframe/hostVariant.js +0 -0
|
@@ -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"./walletDbName-DtRewci9.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-Cpvlkvbe.js";import{c as l,o as u,s as ee,u as d}from"./ecdsaChainTarget-Bfatk3oP.js";import"./signerDomain-Dp7BhfmZ.js";import"./singletons-BXhnsqeY.js";import"./walletAuthority-CAiGuWW2.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-Bik0N8v9.js";import{t as ie}from"./challengeDelivery-CATQ4u6P.js";import"./digestEncoding-BX3VW9eF.js";import{i as ae}from"./walletAuthMethodRecord-LniOQQmj.js";import"./registrationIds-BaK3jUS6.js";import{a as oe,n as _,u as se}from"./sdkSentEvents-D4KtK7_I.js";import{s as ce}from"./types-hKLqDUhR.js";import{i as le}from"./helpers-B9fpZNAP.js";import{C as ue,D as v,b as de,j as fe,x as pe}from"./nearEd25519YaoSigningPreparation-RIfkYN0d.js";import{l as y,u as me}from"./trace-BBux0jtr.js";import{n as he,r as ge,t as _e,w as ve,x as ye}from"./ecdsaDerivationExport-CuNIssOt.js";import{i as be}from"./walletSessionFailure-YuhraC3P.js";import{i as xe,n as Se,r as Ce,s as we}from"./signingQueue-D_Ebmzcn.js";import{h as b,i as x,l as Te,n as Ee,s as S}from"./clientSessionPersistenceState-CBylL1Ul.js";import{t as C}from"./types-Buoe6179.js";import{i as w}from"./appearance-4DmzKUWf.js";import{n as T,t as E}from"./export-viewer-host-CV-lSsQF.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};
|