@seams/wallet 0.9.4 → 0.10.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/core/rpcClients/relayer/walletRegistration.js +1 -1
- package/dist/esm/sdk/{host-h55onlkx.js → host-CCwkhJHK.js} +1 -1
- package/dist/esm/sdk/nearEd25519YaoMaterialActivation-DMGPKrn8.js +1 -0
- package/dist/esm/sdk/registration-Cx_f58rb.js +1 -0
- package/dist/{public/sdk/runtime-auth-Ch4qvKL2.js → esm/sdk/runtime-auth-Cjvf3UFB.js} +1 -1
- package/dist/esm/sdk/{runtime-device-link-DtNpEjq5.js → runtime-device-link-BCKuKNp1.js} +1 -1
- package/dist/esm/sdk/{runtime-ecdsa-tempo-Bntp_Zgx.js → runtime-ecdsa-tempo-Bpmv6fe0.js} +1 -1
- package/dist/esm/sdk/{runtime-email-otp-DEFt-Y-_.js → runtime-email-otp-Bp16EG2j.js} +1 -1
- package/dist/esm/sdk/{runtime-export-DE_umiS1.js → runtime-export-fONYqIZg.js} +1 -1
- package/dist/esm/sdk/{runtime-near-uXqcLEz8.js → runtime-near-s4rtAbA2.js} +1 -1
- package/dist/esm/sdk/{runtime-preferences-C49p0VLC.js → runtime-preferences-1v5EHalc.js} +1 -1
- package/dist/esm/sdk/{runtime-recovery-D7wklehP.js → runtime-recovery-mppuqUaS.js} +1 -1
- package/dist/esm/sdk/{shared-D6RYxvYR.js → shared-Big0VQEK.js} +1 -1
- package/dist/esm/sdk/{signNear-DR50cpes.js → signNear-D0tlQXb9.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/{host-h55onlkx.js → host-CCwkhJHK.js} +1 -1
- package/dist/public/sdk/nearEd25519YaoMaterialActivation-DMGPKrn8.js +1 -0
- package/dist/public/sdk/registration-Cx_f58rb.js +1 -0
- package/dist/{esm/sdk/runtime-auth-Ch4qvKL2.js → public/sdk/runtime-auth-Cjvf3UFB.js} +1 -1
- package/dist/public/sdk/{runtime-device-link-DtNpEjq5.js → runtime-device-link-BCKuKNp1.js} +1 -1
- package/dist/public/sdk/{runtime-ecdsa-tempo-Bntp_Zgx.js → runtime-ecdsa-tempo-Bpmv6fe0.js} +1 -1
- package/dist/public/sdk/{runtime-email-otp-DEFt-Y-_.js → runtime-email-otp-Bp16EG2j.js} +1 -1
- package/dist/public/sdk/{runtime-export-DE_umiS1.js → runtime-export-fONYqIZg.js} +1 -1
- package/dist/public/sdk/{runtime-near-uXqcLEz8.js → runtime-near-s4rtAbA2.js} +1 -1
- package/dist/public/sdk/{runtime-preferences-C49p0VLC.js → runtime-preferences-1v5EHalc.js} +1 -1
- package/dist/public/sdk/{runtime-recovery-D7wklehP.js → runtime-recovery-mppuqUaS.js} +1 -1
- package/dist/public/sdk/{shared-D6RYxvYR.js → shared-Big0VQEK.js} +1 -1
- package/dist/public/sdk/{signNear-DR50cpes.js → signNear-D0tlQXb9.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 +28 -28
- package/dist/public/wallet-service/index.html +4 -4
- package/dist/types/shared-ts/src/utils/walletManagementProtocol.d.ts +1 -1
- package/dist/types/wallet/src/SeamsWeb/signingSurface/BrowserSigningSurface.d.ts +2 -16
- package/dist/types/wallet/src/SeamsWeb/signingSurface/ports.d.ts +24 -15
- package/dist/types/wallet/src/core/rpcClients/relayer/walletRegistration.d.ts +44 -6
- package/dist/types/wallet/src/core/signingEngine/walletCustody/ceremonyDriver.d.ts +14 -0
- package/dist/types/wallet/src/core/signingEngine/walletCustody/registrationCeremony.d.ts +27 -5
- package/package.json +1 -1
- package/dist/esm/sdk/nearEd25519YaoMaterialActivation-CvDs4RtV.js +0 -1
- package/dist/esm/sdk/registration-Cfg9rWhA.js +0 -1
- package/dist/public/sdk/nearEd25519YaoMaterialActivation-CvDs4RtV.js +0 -1
- package/dist/public/sdk/registration-Cfg9rWhA.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{D as e,M as t,O as n,S as r,T as i,f as a,h as o,j as s,r as c,x as l}from"./domainIds-BzkGsRqO.js";import{C as u,S as d,c as f}from"./chains-C_X_fNuS.js";import{D as p,E as m,M as ee,j as te,k as h,y as ne}from"./primitives-CqrjmIAH.js";import{t as re}from"./walletRegistrationSetupPrewarm-B9kpnrbK.js";import{r as ie}from"./base64-DW79QA0h.js";import{o as ae}from"./sessionPolicy-CBTZQe1n.js";import{d as oe,f as se,i as ce,r as le}from"./signingSessionSeal-DX41aXUL.js";import{i as ue,n as de,r as fe}from"./activeWalletSession-WdZkhtBB.js";import{d as g,g as pe,h as _,m as me}from"./capabilityKinds-N8xo_IEh.js";import{o as he,r as ge}from"./canonicalPrimitives-Dsbsxgxc.js";import{c as _e,l as ve,s as ye}from"./accountIds-BzZs7YoX.js";import{r as be}from"./registrationAuthMethodInput-BBCeWDmw.js";import{o as xe,u as Se}from"./registrationSignerPlan-dY9Rp0m_.js";import{a as v,l as Ce,o as we,s as Te}from"./ecdsaChainTarget-DJBXHzbH.js";import{n as Ee,r as De}from"./signerDomain-DqLCvI-D.js";import{P as Oe,a as ke,c as Ae,i as je,lt as Me,n as Ne,o as Pe,s as Fe,t as Ie,vt as Le,yt as Re}from"./registrationIntent-BHU5k2Q-.js";import{d as ze}from"./walletAuthority-BWvfaKIX.js";import{At as Be,C as Ve,Dt as y,E as He,K as Ue,M as We,b as Ge,en as Ke,it as qe,l as Je,nt as Ye,ot as Xe,q as Ze,rt as Qe,y as $e}from"./emailOtpEcdsaDerivationIdentity-p0C1CQva.js";import{K as b,O as et,U as tt}from"./challengeDelivery-5lIu9spR.js";import{r as nt}from"./walletAuthMethodRecord-CnBw27ED.js";import{a as rt,i as x}from"./registrationIds-ByuReLUc.js";import{d as S,t as it}from"./passkey-custody-Cd_yyoRa.js";import{n as at}from"./thresholdEcdsa-D-QMyevW.js";function ot(e){let t=T(e);if(!t||!(`kind`in t)||typeof t.kind!=`string`)return null;switch(t.kind){case`issued`:{if(!E(t,[`kind`,`session`])||!(`session`in t))return null;let e=st(t.session);return e===null?null:{kind:`issued`,session:e}}case`already_committed`:{if(!E(t,[`kind`,`session`,`next`])||!(`session`in t)||!(`next`in t)||t.next!==`unlock_exact_method`)return null;let e=ut(t.session);return e===null?null:{kind:`already_committed`,session:e,next:t.next}}default:return null}}function st(e){try{let t=T(e);if(!t||!E(t,[`kind`,`walletId`,`authorizationId`,`walletSessionId`,`quotaId`,`expiresAtMs`,`remainingUses`,`walletSession`,`operationCredential`,`tokens`])||!(`kind`in t)||!(`walletId`in t)||!(`authorizationId`in t)||!(`walletSessionId`in t)||!(`quotaId`in t)||!(`expiresAtMs`in t)||!(`remainingUses`in t)||!(`walletSession`in t)||!(`operationCredential`in t)||!(`tokens`in t)||t.kind!==`registration_established_wallet_session_v2`)return null;let r=n(t.walletId),i=_(t.walletSessionId),a=me(t.authorizationId),o=g(t.quotaId);if(!r.ok||!a.ok||!i.ok||!o.ok)return null;let s=w(t.expiresAtMs),c=w(t.remainingUses);if(s===null||s<=0||c===null||c<=0)return null;let l=de(t.walletSession),u=ue(t.operationCredential);if(l.walletId!==r.value||l.authorizationId!==a.value||l.quotaId!==o.value||l.expiresAtMs!==s||u.walletSessionId!==i.value)return null;let d=dt(t.tokens);return d===null||!ct(l,d)?null:{kind:`registration_established_wallet_session_v2`,walletId:r.value,authorizationId:a.value,walletSessionId:i.value,quotaId:o.value,expiresAtMs:s,remainingUses:c,walletSession:l,operationCredential:u,tokens:d}}catch{return null}}function ct(e,t){switch(t.kind){case`evm_family_ecdsa`:return C(e,`ecdsa_secp256k1`,t.ecdsa.materialActivation)&&!lt(e,`ecdsa_secp256k1`);case`near_ed25519`:return C(e,`ed25519`,t.ed25519.materialActivation)&&!lt(e,`ed25519`);case`near_ed25519_and_evm_family_ecdsa`:return C(e,`ecdsa_secp256k1`,t.ecdsa.materialActivation)&&C(e,`ed25519`,t.ed25519.materialActivation)&&!lt(e,`ed25519`,`ecdsa_secp256k1`);default:return!1}}function C(e,t,n){return e.capabilitySubjects.some(e=>e.kind===`sign`&&e.keyFamily===t&&c(e.materialActivation,n))}function lt(e,...t){return e.capabilitySubjects.some(e=>e.kind===`sign`&&!t.includes(e.keyFamily))}function ut(e){try{let t=T(e);if(!t||!E(t,[`kind`,`walletId`,`authorizationId`,`walletSessionId`,`quotaId`,`expiresAtMs`,`remainingUses`,`walletSession`,`tokens`])||!(`kind`in t)||!(`walletId`in t)||!(`authorizationId`in t)||!(`walletSessionId`in t)||!(`quotaId`in t)||!(`expiresAtMs`in t)||!(`remainingUses`in t)||!(`walletSession`in t)||!(`tokens`in t)||t.kind!==`registration_established_wallet_session_projection_v2`)return null;let r=n(t.walletId),i=me(t.authorizationId),a=_(t.walletSessionId),o=g(t.quotaId);if(!r.ok||!i.ok||!a.ok||!o.ok||new Set([i.value,a.value,o.value]).size!==3)return null;let s=w(t.expiresAtMs),c=w(t.remainingUses),l=de(t.walletSession),u=dt(t.tokens);return s===null||s<=0||c===null||u===null||l.walletId!==r.value||l.authorizationId!==i.value||l.quotaId!==o.value||l.expiresAtMs!==s||!ct(l,u)?null:{kind:`registration_established_wallet_session_projection_v2`,walletId:r.value,authorizationId:i.value,walletSessionId:a.value,quotaId:o.value,expiresAtMs:s,remainingUses:c,walletSession:l,tokens:u}}catch{return null}}function dt(e){let t=T(e);if(!t||!(`kind`in t)||typeof t.kind!=`string`)return null;switch(t.kind){case`evm_family_ecdsa`:{if(!E(t,[`kind`,`ecdsa`])||!(`ecdsa`in t))return null;let e=ft(t.ecdsa);return e===null?null:{kind:`evm_family_ecdsa`,ecdsa:e}}case`near_ed25519`:{if(!E(t,[`kind`,`ed25519`])||!(`ed25519`in t))return null;let e=pt(t.ed25519);return e===null?null:{kind:`near_ed25519`,ed25519:e}}case`near_ed25519_and_evm_family_ecdsa`:{if(!E(t,[`kind`,`ecdsa`,`ed25519`])||!(`ecdsa`in t)||!(`ed25519`in t))return null;let e=ft(t.ecdsa),n=pt(t.ed25519);return e===null||n===null?null:{kind:`near_ed25519_and_evm_family_ecdsa`,ecdsa:e,ed25519:n}}default:return null}}function ft(e){let t=T(e);if(!t||!E(t,[`sessionKind`,`thresholdSessionId`,`keyHandle`,`runtimePolicyScope`,`materialActivation`,`routerAbEcdsaDerivationNormalSigning`])||!(`sessionKind`in t)||!(`thresholdSessionId`in t)||!(`keyHandle`in t)||!(`runtimePolicyScope`in t)||!(`materialActivation`in t)||!(`routerAbEcdsaDerivationNormalSigning`in t)||t.sessionKind!==`credential_free_projection_v2`)return null;let n=l(t.thresholdSessionId);if(!n.ok)return null;try{let e=We(t.keyHandle),r=mt(t.runtimePolicyScope),i=o(t.materialActivation);if(!i.ok)return null;let a=Ue(t.routerAbEcdsaDerivationNormalSigning);if(!a)return null;let s=Ke(a.scope.material_activation);return c(i.value,s)?{sessionKind:`credential_free_projection_v2`,thresholdSessionId:n.value,keyHandle:e,runtimePolicyScope:r,materialActivation:i.value,routerAbEcdsaDerivationNormalSigning:a}:null}catch{return null}}function pt(e){let t=T(e);if(!t||!E(t,[`sessionKind`,`thresholdSessionId`,`nearAccountId`,`nearEd25519SigningKeyId`,`runtimePolicyScope`,`materialActivation`,`routerAbNormalSigning`])||!(`sessionKind`in t)||!(`thresholdSessionId`in t)||!(`nearAccountId`in t)||!(`nearEd25519SigningKeyId`in t)||!(`runtimePolicyScope`in t)||!(`materialActivation`in t)||!(`routerAbNormalSigning`in t)||t.sessionKind!==`credential_free_projection_v2`)return null;let n=r(t.thresholdSessionId),i=ve(t.nearAccountId);if(!n.ok||!i.ok)return null;try{let e=x(t.nearEd25519SigningKeyId),r=mt(t.runtimePolicyScope),a=o(t.materialActivation);if(!a.ok)return null;let s=oe(t.routerAbNormalSigning);return s?{sessionKind:`credential_free_projection_v2`,thresholdSessionId:n.value,nearAccountId:i.value,nearEd25519SigningKeyId:e,runtimePolicyScope:r,materialActivation:a.value,routerAbNormalSigning:s}:null}catch{return null}}function mt(e){let t=T(e);if(!t||!E(t,[`orgId`,`projectId`,`envId`,`signingRootVersion`])||!(`orgId`in t)||!(`projectId`in t)||!(`envId`in t)||!(`signingRootVersion`in t))throw Error(`runtime policy scope projection is invalid`);return ne({orgId:t.orgId,projectId:t.projectId,envId:t.envId,signingRootVersion:t.signingRootVersion})}function w(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0?e:null}function T(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:null}function E(e,t){return Object.keys(e).length===t.length&&t.every(t=>Object.prototype.hasOwnProperty.call(e,t))}function D(e){let t=String(e||``).trim().toLowerCase();return/^0x[0-9a-f]{40}$/.test(t)?t:``}const ht=/^ederivation-key-[A-Za-z0-9_-]+$/;function O(e){let t=String(e||``).trim();return t?ht.test(t)?{kind:`resolved`,keyHandle:t}:{kind:`invalid`}:{kind:`missing`}}function gt(e){let t=O(e.keyHandle),n=d(e.sharedEvmFamilyKey)?O(e.sharedEvmFamilyKey.keyHandle):{kind:`missing`};return t.kind===`missing`?{kind:`blocked`,reason:`missing_key_handle`}:t.kind===`invalid`||n.kind===`invalid`?{kind:`blocked`,reason:`invalid_key_handle`}:n.kind===`resolved`&&t.keyHandle!==n.keyHandle?{kind:`blocked`,reason:`duplicate_key_handles`}:{kind:`resolved`,keyHandle:t.keyHandle}}function _t(e){let t=(d(e.metadata.sharedEvmFamilyKey)?e.metadata.sharedEvmFamilyKey:null)||e.metadata,n=String(t.thresholdEcdsaPublicKeyB64u||e.metadata.thresholdEcdsaPublicKeyB64u||``).trim();if(!n)return null;let r=String(t.walletId||``).trim();if(!r)return null;try{He(n);let i=t.ecdsaThresholdKeyId||e.metadata.ecdsaThresholdKeyId,a=t.signingRootId||e.metadata.signingRootId,o=t.signingRootVersion||e.metadata.signingRootVersion,s=t.participantIds||e.metadata.participantIds,c=t.thresholdOwnerAddress||e.metadata.thresholdOwnerAddress||e.metadata.ownerAddress;return Je({walletId:r,keyHandle:e.keyHandle,chainTarget:e.chainTarget,ecdsaThresholdKeyId:i,signingRootId:a,signingRootVersion:o,participantIds:s,thresholdOwnerAddress:c,thresholdEcdsaPublicKeyB64u:n})}catch{return null}}function vt(e){try{let t=Ze(e.raw);return String(t.client_id)!==String(e.walletId)||t.public_identity.threshold_public_key33_b64u!==e.thresholdEcdsaPublicKeyB64u?null:t}catch{return null}}function yt(e){let t=e.signer;if(t.status!==`active`||t.signerKind!==De.thresholdEcdsa||t.signerAuthMethod!==Ee.passkey)return{kind:`skipped`};let n=d(t.metadata)?t.metadata:{};if(!d(n.chainTarget))return{kind:`blocked`,targetKey:``,reason:`missing_chain_target`};let r;try{r=v(n.chainTarget)}catch{return{kind:`blocked`,targetKey:``,reason:`invalid_chain_target`}}if(!e.configuredTargets.some(e=>Te(e,r)))return{kind:`skipped`};let i=we(r),a=gt(n);if(a.kind===`blocked`)return{kind:`blocked`,targetKey:i,reason:a.reason};let o=_t({metadata:n,keyHandle:a.keyHandle,chainTarget:r});if(!o)return{kind:`key_facts_inventory_required`,chainTarget:r,targetKey:i,keyHandle:a.keyHandle,reason:`missing_key_facts`};let s=vt({raw:n.publicCapability,walletId:e.walletId,thresholdEcdsaPublicKeyB64u:o.keyFacts.thresholdEcdsaPublicKeyB64u});return{kind:`active_wallet_key`,chainTarget:r,targetKey:i,walletKey:o,publicCapability:s?{kind:`persisted_public_capability`,value:s}:{kind:`missing_public_capability`}}}function bt(e){let{raw:t}=e;if(!d(t)||!d(t.chainTarget))return null;let n=d(t.key)?t.key:t,r;try{r=v(t.chainTarget)}catch{return null}let i=O(t.keyHandle),a=O(n.keyHandle),o=D(t.accountAddress),s=D(t.ownerAddress),c=String(n.walletId||``).trim(),l=String(n.subjectId||``).trim(),u=String(Ce({walletId:e.walletId})),f=String(n.rpId||``).trim(),p=String(n.thresholdEcdsaPublicKeyB64u||t.thresholdEcdsaPublicKeyB64u||``).trim(),m=D(n.thresholdOwnerAddress||t.ownerAddress||t.accountAddress||t.ethereumAddress);if(i.kind!==`resolved`||a.kind!==`resolved`||a.keyHandle!==i.keyHandle||!p||!s||!o||!m||c!==String(e.walletId)||l&&l!==u||f!==e.rpId||m!==s)return null;try{let a=vt({raw:t.publicCapability,walletId:e.walletId,thresholdEcdsaPublicKeyB64u:p});if(!a)return null;let c=Ve(i.keyHandle),l=Ge({record:{ecdsaThresholdKeyId:t.ecdsaThresholdKeyId}}),u=$e({signingRootId:t.signingRootId||n.signingRootId,signingRootVersion:t.signingRootVersion||n.signingRootVersion});return{accountAddress:o,ownerAddress:s,publicCapability:a,walletKey:Je({walletId:e.walletId,keyHandle:c,chainTarget:r,ecdsaThresholdKeyId:l,signingRootId:u.signingRootId,signingRootVersion:u.signingRootVersion,participantIds:n.participantIds||t.participantIds,thresholdOwnerAddress:m,thresholdEcdsaPublicKeyB64u:p})}}catch{return null}}function xt(e){let t=[];for(let n of e.records){let r=bt({walletId:e.walletId,rpId:e.rpId,raw:n});r&&t.push(r)}return t}function k(e){let t=String(e.value||``).trim();if(!t)throw Error(`${e.responseName} response missing ${e.field}`);return t}function A(e){if(!u(e.value))throw Error(`${e.responseName} response missing ${e.field}`);return e.value}function j(e,t,n){let r=new Set(t);for(let t of Object.keys(e))if(!r.has(t))throw Error(`${n} response contains unexpected ${t}`)}function M(e){let t=Number(e.value);if(!Number.isSafeInteger(t)||t<e.minimum)throw Error(`${e.responseName} response has invalid ${e.field}`);return t}function N(e,t){if(!Array.isArray(e)||e.length!==2)throw Error(`${t} response has invalid participantIds`);let n=M({responseName:t,field:`participantIds[0]`,value:e[0],minimum:1}),r=M({responseName:t,field:`participantIds[1]`,value:e[1],minimum:1});if(n===r)throw Error(`${t} response has duplicate participantIds`);if(n!==1||r!==2)throw Error(`${t} response has unsupported participantIds`);return[n,r]}function P(e,n){let r=t(e);if(!r.ok)throw Error(`${n} response has invalid rpId`);return r.value}function St(e,t){let n=A({responseName:t,field:`authorityScope`,value:e});switch(n.kind){case`passkey_rp`:return j(n,[`kind`,`rpId`],t),{kind:`passkey_rp`,rpId:P(n.rpId,t)};case`email_otp`:if(j(n,[`kind`,`provider`,`providerUserId`],t),n.provider!==`google`&&n.provider!==`email`)throw Error(`${t} response has invalid authorityScope provider`);return{kind:`email_otp`,provider:n.provider,providerUserId:k({responseName:t,field:`authorityScope.providerUserId`,value:n.providerUserId})};default:throw Error(`${t} response has invalid authorityScope`)}}function Ct(e,t){let n=A({responseName:t,field:`ed25519`,value:e});if(j(n,[`signerSlot`,`nearAccountId`,`nearEd25519SigningKeyId`,`publicKey`,`relayerKeyId`,`keyVersion`,`recoveryExportCapable`,`participantIds`],t),n.recoveryExportCapable!==!0)throw Error(`${t} response is not recovery/export capable`);return{signerSlot:M({responseName:t,field:`ed25519.signerSlot`,value:n.signerSlot,minimum:1}),nearAccountId:k({responseName:t,field:`ed25519.nearAccountId`,value:n.nearAccountId}),nearEd25519SigningKeyId:k({responseName:t,field:`ed25519.nearEd25519SigningKeyId`,value:n.nearEd25519SigningKeyId}),publicKey:k({responseName:t,field:`ed25519.publicKey`,value:n.publicKey}),relayerKeyId:k({responseName:t,field:`ed25519.relayerKeyId`,value:n.relayerKeyId}),keyVersion:k({responseName:t,field:`ed25519.keyVersion`,value:n.keyVersion}),recoveryExportCapable:!0,participantIds:N(n.participantIds,t)}}function wt(e,t){let n=A({responseName:t,field:`ed25519`,value:e});j(n,[`signerSlot`,`nearAccountId`,`nearEd25519SigningKeyId`,`publicKey`,`relayerKeyId`,`keyVersion`,`recoveryExportCapable`,`participantIds`,`thresholdSessionId`,`runtimePolicyScope`,`routerAbNormalSigning`],t);let i=Ct({signerSlot:n.signerSlot,nearAccountId:n.nearAccountId,nearEd25519SigningKeyId:n.nearEd25519SigningKeyId,publicKey:n.publicKey,relayerKeyId:n.relayerKeyId,keyVersion:n.keyVersion,recoveryExportCapable:n.recoveryExportCapable,participantIds:n.participantIds},t),a=r(n.thresholdSessionId);if(!a.ok)throw Error(`${t} response has invalid ed25519.thresholdSessionId`);let o=ae(n.runtimePolicyScope);if(!o)throw Error(`${t} response has invalid ed25519.runtimePolicyScope`);return{...i,thresholdSessionId:a.value,runtimePolicyScope:o,routerAbNormalSigning:se(n.routerAbNormalSigning)}}function Tt(e,t){let n=A({responseName:t,field:`chainTarget`,value:e});switch(n.kind){case`evm`:return j(n,[`kind`,`namespace`,`chainId`,`networkSlug`],t),v(n);case`tempo`:return j(n,[`kind`,`chainId`,`networkSlug`],t),v(n);default:throw Error(`${t} response has invalid chainTarget kind`)}}function Et(e,t){let n=A({responseName:t,field:`ecdsa.walletKeys[]`,value:e});if(j(n,[`keyScope`,`chainTarget`,`walletId`,`evmFamilySigningKeySlotId`,`keyHandle`,`ecdsaThresholdKeyId`,`signingRootId`,`signingRootVersion`,`thresholdEcdsaPublicKeyB64u`,`thresholdOwnerAddress`,`relayerKeyId`,`relayerVerifyingShareB64u`,`contextBinding32B64u`,`derivationClientSharePublicKey33B64u`,`clientShareRetryCounter`,`relayerShareRetryCounter`,`participantIds`,`publicCapability`],t),n.keyScope!==`evm-family`)throw Error(`${t} response has invalid keyScope`);return{keyScope:`evm-family`,chainTarget:Tt(n.chainTarget,t),walletId:k({responseName:t,field:`walletId`,value:n.walletId}),evmFamilySigningKeySlotId:k({responseName:t,field:`evmFamilySigningKeySlotId`,value:n.evmFamilySigningKeySlotId}),keyHandle:k({responseName:t,field:`keyHandle`,value:n.keyHandle}),ecdsaThresholdKeyId:k({responseName:t,field:`ecdsaThresholdKeyId`,value:n.ecdsaThresholdKeyId}),signingRootId:k({responseName:t,field:`signingRootId`,value:n.signingRootId}),signingRootVersion:k({responseName:t,field:`signingRootVersion`,value:n.signingRootVersion}),thresholdEcdsaPublicKeyB64u:k({responseName:t,field:`thresholdEcdsaPublicKeyB64u`,value:n.thresholdEcdsaPublicKeyB64u}),thresholdOwnerAddress:k({responseName:t,field:`thresholdOwnerAddress`,value:n.thresholdOwnerAddress}),relayerKeyId:k({responseName:t,field:`relayerKeyId`,value:n.relayerKeyId}),relayerVerifyingShareB64u:k({responseName:t,field:`relayerVerifyingShareB64u`,value:n.relayerVerifyingShareB64u}),contextBinding32B64u:k({responseName:t,field:`contextBinding32B64u`,value:n.contextBinding32B64u}),derivationClientSharePublicKey33B64u:k({responseName:t,field:`derivationClientSharePublicKey33B64u`,value:n.derivationClientSharePublicKey33B64u}),clientShareRetryCounter:M({responseName:t,field:`clientShareRetryCounter`,value:n.clientShareRetryCounter,minimum:0}),relayerShareRetryCounter:M({responseName:t,field:`relayerShareRetryCounter`,value:n.relayerShareRetryCounter,minimum:0}),participantIds:N(n.participantIds,t),publicCapability:Ze(n.publicCapability)}}function Dt(e){switch(e){case`registrationIntentLoadMs`:case`registrationIntentDigestMs`:case`registrationIntentConsumeMs`:case`registrationAttemptGateMs`:case`registrationPreparationPersistMs`:case`registrationPreparationLoadMs`:case`registrationPreparationConsumeMs`:case`registrationPreparationScopeCheckMs`:case`registrationAuthorityVerifyMs`:case`registrationEcdsaPrepareMs`:case`registrationCeremonyPersistMs`:case`registerPrepareTotalMs`:case`registerStartTotalMs`:case`registrationEcdsaRespondMs`:case`registrationFinalizeReplayLoadMs`:case`registrationCeremonyLoadMs`:case`registrationEcdsaBootstrapVerifyMs`:case`sponsoredNearAccountCreateMs`:case`registrationKeygenMs`:case`registrationEmailOtpEnrollmentPlanMs`:case`relaySessionMintMs`:case`relayGoogleEmailOtpActivationPlanMs`:case`relayPersistenceMs`:case`registrationFinalizeReplayCacheMs`:case`registerFinalizeTotalMs`:return e;default:throw Error(`Wallet registration finalize response has invalid diagnostics timing name`)}}function Ot(e){let t=`Wallet registration finalize`,n=A({responseName:t,field:`registrationDiagnostics`,value:e});if(j(n,[`kind`,`route`,`entries`],t),n.kind!==`wallet_registration_route_diagnostics_v1`||n.route!==`wallets_register_finalize`||!Array.isArray(n.entries))throw Error(`${t} response has invalid registrationDiagnostics`);return{kind:`wallet_registration_route_diagnostics_v1`,route:`wallets_register_finalize`,entries:n.entries.map(e=>{let n=A({responseName:t,field:`registrationDiagnostics.entries[]`,value:e});if(j(n,[`name`,`durationMs`],t),typeof n.durationMs!=`number`||!Number.isFinite(n.durationMs)||n.durationMs<0)throw Error(`${t} response has invalid diagnostics durationMs`);return{name:Dt(n.name),durationMs:n.durationMs}})}}function kt(e){let t=`Wallet registration finalize`,n=A({responseName:t,field:`authority`,value:e});j(n,[`walletId`,`factor`,`verifier`,`bindingId`],t);let r=A({responseName:t,field:`authority.factor`,value:n.factor}),i=A({responseName:t,field:`authority.verifier`,value:n.verifier});switch(r.kind){case`passkey`:j(r,[`kind`,`credentialIdB64u`],t),j(i,[`kind`,`rpId`],t);break;case`email_otp`:j(r,[`kind`,`provider`,`providerUserId`],t),j(i,[`kind`,`emailHashHex`],t);break;default:throw Error(`${t} response has invalid authority factor`)}let a=Be(n);if(!a)throw Error(`${t} response has invalid authority`);return a}function At(e){let t=`Wallet registration finalize`,n=A({responseName:t,field:`authMethod`,value:e.response.authMethod});if(String(e.authority.walletId)!==String(e.walletId))throw Error(`${t} response authority wallet mismatch`);switch(n.kind){case`passkey`:{if(j(n,[`kind`,`credentialIdB64u`,`credentialPublicKeyB64u`],t),!y(e.authority))throw Error(`${t} response has inconsistent passkey authority`);let r=P(e.response.rpId,t),i=k({responseName:t,field:`authMethod.credentialIdB64u`,value:n.credentialIdB64u});if(String(e.authority.factor.credentialIdB64u)!==i||String(e.authority.verifier.rpId)!==String(r))throw Error(`${t} response passkey authority binding mismatch`);return{kind:`passkey`,rpId:r,authMethod:{kind:`passkey`,credentialIdB64u:i,credentialPublicKeyB64u:k({responseName:t,field:`authMethod.credentialPublicKeyB64u`,value:n.credentialPublicKeyB64u})}}}case`email_otp`:if(j(n,[`kind`,`registrationAuthorityId`],t),y(e.authority)||e.response.rpId!==void 0)throw Error(`${t} response has inconsistent email OTP authority`);return{kind:`email_otp`,authMethod:{kind:`email_otp`,registrationAuthorityId:k({responseName:t,field:`authMethod.registrationAuthorityId`,value:n.registrationAuthorityId})}};default:throw Error(`${t} response has invalid authMethod`)}}function jt(e){let t=`Wallet registration finalize`,n=A({responseName:t,field:`accountProvisioning`,value:e});switch(n.kind){case`implicit_account`:if(j(n,[`kind`,`accountIdSource`],t),n.accountIdSource!==`ed25519_public_key`)throw Error(`${t} response has invalid implicit account provisioning`);return{kind:`implicit_account`,accountIdSource:`ed25519_public_key`};case`sponsored_named_account`:{j(n,[`kind`,`requestedAccountId`,`sponsor`],t);let e=_e(n.requestedAccountId);if(!e.ok||n.sponsor!==`relayer`)throw Error(`${t} response has invalid named account provisioning`);return{kind:`sponsored_named_account`,requestedAccountId:e.value,sponsor:`relayer`}}default:throw Error(`${t} response has invalid accountProvisioning kind`)}}function Mt(e){let t=`Wallet registration finalize`,n=A({responseName:t,field:`resolvedAccount`,value:e});switch(n.kind){case`implicit_account`:{j(n,[`kind`,`nearAccountId`,`nearEd25519SigningKeyId`],t);let e=ye(n.nearAccountId);if(!e.ok)throw Error(`${t} response has invalid implicit nearAccountId`);return{kind:`implicit_account`,nearAccountId:e.value,nearEd25519SigningKeyId:x(n.nearEd25519SigningKeyId)}}case`sponsored_named_account`:{j(n,[`kind`,`nearAccountId`,`nearEd25519SigningKeyId`,`transactionHash`],t);let e=_e(n.nearAccountId);if(!e.ok)throw Error(`${t} response has invalid named nearAccountId`);return{kind:`sponsored_named_account`,nearAccountId:e.value,nearEd25519SigningKeyId:x(n.nearEd25519SigningKeyId),transactionHash:k({responseName:t,field:`resolvedAccount.transactionHash`,value:n.transactionHash})}}default:throw Error(`${t} response has invalid resolvedAccount kind`)}}function Nt(e){let t=`Wallet registration finalize`,n=A({responseName:t,field:`ecdsa`,value:e.value});if(j(n,[`walletKeys`],t),!Array.isArray(n.walletKeys)||n.walletKeys.length===0)throw Error(`${t} response has invalid walletKeys`);let r=new Set;return{walletKeys:n.walletKeys.map(n=>{let i=Et(n,t);if(i.walletId!==String(e.walletId))throw Error(`${t} response ECDSA walletId mismatch`);if(String(i.publicCapability.client_id)!==String(e.walletId)||i.publicCapability.public_identity.context_binding_b64u!==i.contextBinding32B64u||i.publicCapability.public_identity.derivation_client_share_public_key33_b64u!==i.derivationClientSharePublicKey33B64u||i.publicCapability.public_identity.threshold_public_key33_b64u!==i.thresholdEcdsaPublicKeyB64u||i.publicCapability.public_identity.client_share_retry_counter!==i.clientShareRetryCounter||i.publicCapability.public_identity.server_share_retry_counter!==i.relayerShareRetryCounter)throw Error(`${t} response ECDSA public capability mismatch`);let a=we(i.chainTarget);if(r.has(a))throw Error(`${t} response has duplicate ECDSA target ${a}`);return r.add(a),i})}}function Pt(e){let t=`Wallet registration finalize`,n=St(e.response.authorityScope,t),r=jt(e.response.accountProvisioning),i=Mt(e.response.resolvedAccount),a=wt(e.response.ed25519,t);if(r.kind!==i.kind||i.nearAccountId!==a.nearAccountId||i.nearEd25519SigningKeyId!==a.nearEd25519SigningKeyId)throw Error(`${t} response has inconsistent Ed25519 identity`);if(n.kind===`passkey_rp`&&(!y(e.authority)||String(e.authority.verifier.rpId)!==String(n.rpId))||n.kind===`email_otp`&&(y(e.authority)||e.authority.factor.provider!==n.provider||String(e.authority.factor.providerUserId)!==n.providerUserId))throw Error(`${t} response authorityScope mismatch`);return{authorityScope:n,accountProvisioning:r,resolvedAccount:i,ed25519:a}}function Ft(e){let t=`Wallet registration finalize`,n=A({responseName:t,field:`body`,value:e.value});if(j(n,[`ok`,`walletId`,`authority`,`foundingAuthority`,`foundingAuthMethod`,`registrationDiagnostics`,`rpId`,`authMethod`,`walletCustody`,`custodyKeyManifestDigestB64u`,`kind`,`authorityScope`,`accountProvisioning`,`resolvedAccount`,`ed25519`,`ecdsa`],t),n.ok!==!0||n.kind!==e.expectedKind)throw Error(`${t} response substituted signer branch`);let r=rt(k({responseName:t,field:`walletId`,value:n.walletId})),i=kt(n.authority),a=ze(n.foundingAuthority),o=nt(n.foundingAuthMethod);if(!a.ok)throw Error(`${t} response has an invalid founding authority: ${a.error.message}`);if(a.value.state!==`active`)throw Error(`${t} response has an inactive founding authority`);if(!o)throw Error(`${t} response has an invalid founding auth method`);if(o.status!==`active`)throw Error(`${t} response has an inactive founding auth method`);if(a.value.walletId!==r||o.walletId!==r)throw Error(`${t} response changed the founding wallet identity`);if(o.walletAuthorityId!==a.value.authorityId)throw Error(`${t} response has mismatched founding authority identities`);if(o.walletAuthMethodId!==i.bindingId)throw Error(`${t} response has mismatched founding auth-method identities`);let s=At({response:n,walletId:r,authority:i}),c=n.registrationDiagnostics===void 0?void 0:Ot(n.registrationDiagnostics),l=n.walletCustody===void 0?{}:{walletCustody:it(n.walletCustody,t)},u=n.custodyKeyManifestDigestB64u===void 0?void 0:k({responseName:t,field:`custodyKeyManifestDigestB64u`,value:n.custodyKeyManifestDigestB64u});if(u!==void 0&&ie(u).byteLength!==32)throw Error(`${t} response has invalid custodyKeyManifestDigestB64u`);let d=u===void 0?{}:{custodyKeyManifestDigestB64u:u};switch(n.kind){case`near_ed25519`:{if(n.ecdsa!==void 0)throw Error(`${t} response mixed signer branches`);let e=Pt({response:n,authority:i});return s.kind===`passkey`?{ok:!0,walletId:r,authority:i,foundingAuthority:a.value,foundingAuthMethod:o,...c?{registrationDiagnostics:c}:{},...l,...d,rpId:s.rpId,authMethod:s.authMethod,kind:`near_ed25519`,authorityScope:e.authorityScope,accountProvisioning:e.accountProvisioning,resolvedAccount:e.resolvedAccount,ed25519:e.ed25519}:{ok:!0,walletId:r,authority:i,foundingAuthority:a.value,foundingAuthMethod:o,...c?{registrationDiagnostics:c}:{},...l,...d,authMethod:s.authMethod,kind:`near_ed25519`,authorityScope:e.authorityScope,accountProvisioning:e.accountProvisioning,resolvedAccount:e.resolvedAccount,ed25519:e.ed25519}}case`evm_family_ecdsa`:{if(n.authorityScope!==void 0||n.accountProvisioning!==void 0||n.resolvedAccount!==void 0||n.ed25519!==void 0)throw Error(`${t} response mixed signer branches`);let e=Nt({value:n.ecdsa,walletId:r});return s.kind===`passkey`?{ok:!0,walletId:r,authority:i,foundingAuthority:a.value,foundingAuthMethod:o,...c?{registrationDiagnostics:c}:{},...l,...d,rpId:s.rpId,authMethod:s.authMethod,kind:`evm_family_ecdsa`,ecdsa:e}:{ok:!0,walletId:r,authority:i,foundingAuthority:a.value,foundingAuthMethod:o,...c?{registrationDiagnostics:c}:{},...l,...d,authMethod:s.authMethod,kind:`evm_family_ecdsa`,ecdsa:e}}default:throw Error(`${t} response has invalid kind`)}}const It=`/wallets/register/respond`,Lt=`/wallets/register/activate`,Rt=`/wallets/register/near-provisioning`,zt=`X-Seams-Environment-Id`;function Bt(e){let t=[It];e.evmFamilyEcdsa&&t.push(Lt),e.nearEd25519&&(e.evmFamilyEcdsa&&t.push(`/wallets/register/near-admission`),t.push(et,Rt,ce,le)),ee(e.relayerUrl,t)}function Vt(e){try{return new TextEncoder().encode(String(e||``)).length}catch{return String(e||``).length}}function Ht(){try{return globalThis.__SEAMS_REGISTRATION_BENCHMARK_DIAGNOSTICS===!0}catch{return!1}}function Ut(e){if(!(!e.value||typeof e.value!=`object`||Array.isArray(e.value))&&!(Object.keys(e.out).length>=64))for(let[t,n]of Object.entries(e.value)){if(Object.keys(e.out).length>=64)return;let r=e.path?`${e.path}.${t}`:t;typeof n==`string`?e.out[`${r}Bytes`]=Vt(n):Array.isArray(n)?e.out[`${r}Count`]=n.length:e.depth>0&&n&&typeof n==`object`&&Ut({value:n,out:e.out,path:r,depth:e.depth-1})}}function Wt(e){let t={};return Ut({value:e,out:t,path:``,depth:2}),t}function Gt(e){try{return JSON.parse(e)}catch{return}}function F(e,t){if(!(typeof e!=`object`||!e||Array.isArray(e)))return Reflect.get(e,t)}async function Kt(e){try{return await e.text()}catch{return`{}`}}async function I(e){let t=Date.now(),n=JSON.stringify(e.body),r=await fetch(`${te(e.relayerUrl,{trim:!1})}${e.path}`,p({headers:{...e.headers,"X-Seams-Wallet-Protocol":`3`},body:e.body,bodyJson:n}));if(e.onServerTiming)try{e.onServerTiming(r.headers.get(`Server-Timing`))}catch{}let i=await Kt(r),a=Gt(i);if(Ht()&&console.info(`[Registration] wallet route payload summary`,{path:e.path,status:r.status,requestBytes:Vt(n),requestSizeBreakdown:Wt(e.body),responseBytes:Vt(i),responseSizeBreakdown:Wt(a),totalMs:Date.now()-t}),!r.ok||F(a,`ok`)===!1)throw Error(String(F(a,`message`)||F(a,`error`)||F(a,`code`)||`HTTP ${r.status}`));return a}const qt=[`ok`,`walletId`,`nearAccountId`,`fundedAmountYocto`],Jt=[`transactionHash`,`message`],Yt=[`ok`,`code`,`message`];function Xt(e,t){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`${t} must be an object`);return e}function Zt(e,t,n,r){let i=new Set([...t,...n]),a=Object.keys(e);if(a.some(e=>!i.has(e)))throw Error(`${r} contains unexpected fields`);for(let e of t)if(!a.includes(e))throw Error(`${r}.${e} is required`)}function L(e,t){return Reflect.get(e,t)}function R(e,t){if(typeof e!=`string`||e.trim().length===0)throw Error(`${t} must be a non-empty string`);return e.trim()}function Qt(e,t){if(e!==void 0){if(typeof e!=`string`)throw Error(`${t} must be a string`);return e}}function $t(e){let t=Xt(e,`fund implicit NEAR account response`),r=L(t,`ok`);if(r===!0){Zt(t,qt,Jt,`fund implicit NEAR account success response`);let e=n(L(t,`walletId`));if(!e.ok)throw Error(`fund implicit NEAR account walletId is invalid`);let r=ye(L(t,`nearAccountId`));if(!r.ok)throw Error(`fund implicit NEAR account nearAccountId is invalid`);let i=Qt(L(t,`transactionHash`),`fund implicit NEAR account transactionHash`),a=Qt(L(t,`message`),`fund implicit NEAR account message`);return{ok:!0,walletId:e.value,nearAccountId:r.value,fundedAmountYocto:R(L(t,`fundedAmountYocto`),`fund implicit NEAR account fundedAmountYocto`),...i===void 0?{}:{transactionHash:i},...a===void 0?{}:{message:a}}}if(r===!1)return Zt(t,Yt,[],`fund implicit NEAR account failure response`),{ok:!1,code:R(L(t,`code`),`fund implicit NEAR account code`),message:R(L(t,`message`),`fund implicit NEAR account message`)};throw Error(`fund implicit NEAR account response has an invalid ok discriminator`)}async function en(e){let t=String(e.walletId||``).trim(),n=String(e.nearAccountId||``).trim(),r=String(e.nearPublicKeyStr||``).trim(),i=String(e.walletSessionToken||``).trim();if(!t)throw Error(`walletId is required for implicit NEAR account funding`);if(!n)throw Error(`nearAccountId is required for implicit NEAR account funding`);if(!r)throw Error(`nearPublicKeyStr is required for implicit NEAR account funding`);if(!i)throw Error(`walletSessionToken is required for implicit NEAR account funding`);return $t(await I({relayerUrl:e.relayerUrl,path:`/wallets/${encodeURIComponent(t)}/near/implicit-account/fund`,headers:m({token:i,missingMessage:`walletSessionToken is required for implicit NEAR account funding`}),body:{nearAccountId:n,nearPublicKeyStr:r}}))}function tn(e){let t=String(e||``).trim();if(!t)throw Error(`Registration preparation id is required`);return t}const nn=[`formatVersion`,`walletId`,`evmFamilySigningKeySlotId`,`ecdsaThresholdKeyId`,`signingRootId`,`signingRootVersion`,`keyScope`,`relayerKeyId`,`registrationPreparationId`,`requestId`,`thresholdSessionId`,`ttlMs`,`remainingUses`,`participantIds`,`runtimePolicyScope`];function z(e){if(e.value===null||typeof e.value!=`object`||Array.isArray(e.value))throw Error(`${e.responseName} response missing ${e.field}`);return e.value}function B(e,t,n){if(!Object.keys(e).includes(t))throw Error(`${n} is missing ${t}`);return Reflect.get(e,t)}function V(e,t,n){if(Object.keys(e).includes(t))return Reflect.get(e,t)}function H(e,t,n){let r=new Set(t);for(let t of Object.keys(e))if(!r.has(t))throw Error(`${n} contains unexpected ${t}`)}function U(e,t){if(!Array.isArray(e))throw Error(`${t} must be an array`);return e}function rn(e,t){return Object.keys(e).includes(t)}function an(e,t){if(typeof e!=`string`||e.length===0||e.trim()!==e)throw Error(`${t} must be a non-empty canonical string`);return e}function on(e,t,n){if(typeof e!=`number`||!Number.isSafeInteger(e)||e<n)throw Error(`${t} must be a safe integer`);return e}function W(e,t,n){return an(B(e,t,n),`${n}.${t}`)}function G(e,t,n){if(rn(e,t))return an(B(e,t,n),`${n}.${t}`)}function K(e,t,n,r){return on(B(e,t,n),`${n}.${t}`,r)}function sn(e,t){let n=U(e,t);if(n.length===0)throw Error(`${t} must not be empty`);let r=[];for(let e=0;e<n.length;e+=1)r.push(on(n[e],`${t}[${e}]`,1));return r}function cn(e,t){let n=sn(e,t);if(n.length!==2||n[0]!==1||n[1]!==2)throw Error(`${t} must be [1, 2]`);return[1,2]}function ln(e,t,n=!1){if(e===void 0)return;let r=`${t} runtimePolicyScope`,i=z({responseName:r,field:`value`,value:e});H(i,[`orgId`,`projectId`,`envId`,`signingRootVersion`],r);let a=G(i,`signingRootVersion`,r);if(n&&a===void 0)throw Error(`${r}.signingRootVersion is required`);let o={orgId:W(i,`orgId`,r),projectId:W(i,`projectId`,r),envId:W(i,`envId`,r)};return a===void 0?o:{...o,signingRootVersion:a}}function un(e,t){let n=ln(e,t,!0);if(!n||n.signingRootVersion===void 0)throw Error(`${t} runtimePolicyScope is invalid`);return{orgId:n.orgId,projectId:n.projectId,envId:n.envId,signingRootVersion:n.signingRootVersion}}function dn(e){let n=`Wallet registration setup intent authMethod`,r=z({responseName:n,field:`value`,value:e});switch(W(r,`kind`,n)){case`passkey`:if(H(r,[`kind`,`rpId`,`authenticatorOptions`],n),!t(W(r,`rpId`,n)).ok)throw Error(`${n}.rpId is invalid`);if(!rn(r,`authenticatorOptions`))break;if(B(r,`authenticatorOptions`,n)===void 0)throw Error(`${n}.authenticatorOptions must be defined when present`);break;case`email_otp`:switch(W(r,`proofKind`,n)){case`otp_challenge`:H(r,[`kind`,`proofKind`,`email`,`providerSubject`,`otpCode`,`challengeId`],n),G(r,`challengeId`,n),W(r,`email`,n),W(r,`providerSubject`,n),W(r,`otpCode`,n);break;case`google_sso_registration`:H(r,[`kind`,`proofKind`,`email`,`providerSubject`,`googleEmailOtpRegistrationAttemptId`,`googleEmailOtpRegistrationOfferId`,`googleEmailOtpRegistrationCandidateId`],n),W(r,`email`,n),W(r,`providerSubject`,n),W(r,`googleEmailOtpRegistrationAttemptId`,n),W(r,`googleEmailOtpRegistrationOfferId`,n),W(r,`googleEmailOtpRegistrationCandidateId`,n);break;default:throw Error(`${n}.proofKind is invalid`)}break;default:throw Error(`${n}.kind is invalid`)}let i=be(e);if(!i)throw Error(`${n} is invalid`);return i}function fn(e){let t=`Wallet registration setup intent accountProvisioning`,n=z({responseName:t,field:`value`,value:e}),r=W(n,`kind`,t);switch(r){case`implicit_account`:if(H(n,[`kind`,`accountIdSource`],t),W(n,`accountIdSource`,t)!==`ed25519_public_key`)throw Error(`${t}.accountIdSource is invalid`);return{kind:r,accountIdSource:`ed25519_public_key`};case`sponsored_named_account`:{if(H(n,[`kind`,`requestedAccountId`,`sponsor`],t),W(n,`sponsor`,t)!==`relayer`)throw Error(`${t}.sponsor is invalid`);let e=_e(W(n,`requestedAccountId`,t));if(!e.ok)throw Error(`${t}.requestedAccountId is invalid`);return{kind:r,requestedAccountId:e.value,sponsor:`relayer`}}default:throw Error(`${t}.kind is invalid`)}}function q(e,t){switch(e.kind){case`evm`:return t.kind===`evm`&&e.namespace===t.namespace&&e.chainId===t.chainId&&e.networkSlug===t.networkSlug;case`tempo`:return t.kind===`tempo`&&e.chainId===t.chainId&&e.networkSlug===t.networkSlug;default:return pn(e)}}function pn(e){throw Error(`Unsupported wallet registration setup chain target: ${String(e)}`)}function J(e,t){let n=z({responseName:t,field:`chainTarget`,value:e}),r=W(n,`kind`,t);switch(r){case`evm`:{if(H(n,[`kind`,`namespace`,`chainId`,`networkSlug`],t),W(n,`namespace`,t)!==`eip155`)throw Error(`${t}.namespace is invalid`);let e=K(n,`chainId`,t,1),i=G(n,`networkSlug`,t);return i===void 0?{kind:r,namespace:`eip155`,chainId:e}:{kind:r,namespace:`eip155`,chainId:e,networkSlug:i}}case`tempo`:{H(n,[`kind`,`chainId`,`networkSlug`],t);let e=K(n,`chainId`,t,1),i=G(n,`networkSlug`,t);return i===void 0?{kind:r,chainId:e}:{kind:r,chainId:e,networkSlug:i}}default:throw Error(`${t}.kind is invalid`)}}function mn(e){try{return J(e,`Wallet registration setup intent`)}catch{return null}}function hn(e){let t=`Wallet registration setup intent signer`,n=z({responseName:t,field:`value`,value:e}),r=W(n,`kind`,t);switch(r){case`near_ed25519`:if(H(n,[`kind`,`accountProvisioning`,`signerSlot`,`participantIds`,`derivationVersion`],t),K(n,`derivationVersion`,t,1)!==1)throw Error(`${t}.derivationVersion is invalid`);return{kind:r,accountProvisioning:fn(B(n,`accountProvisioning`,t)),signerSlot:K(n,`signerSlot`,t,1),participantIds:sn(B(n,`participantIds`,t),`${t}.participantIds`),derivationVersion:1};case`evm_family_ecdsa`:{H(n,[`kind`,`participantIds`,`chainTargets`],t);let e=U(B(n,`chainTargets`,t),`${t}.chainTargets`);if(e.length===0)throw Error(`${t}.chainTargets must not be empty`);let i=[];for(let n of e){let e=J(n,`${t}.chainTargets`);if(i.some(t=>q(t,e)))throw Error(`${t}.chainTargets contains a duplicate target`);i.push(e)}return{kind:r,participantIds:sn(B(n,`participantIds`,t),`${t}.participantIds`),chainTargets:i}}default:throw Error(`${t}.kind is invalid`)}}function gn(e){let t=`Wallet registration setup intent signerSelection`,n=z({responseName:t,field:`value`,value:e});if(H(n,[`kind`,`signers`],t),W(n,`kind`,t)!==`signer_set`)throw Error(`${t}.kind is invalid`);let r=U(B(n,`signers`,t),`${t}.signers`);if(r.length===0)throw Error(`${t}.signers must not be empty`);let i=[];for(let e of r)i.push(hn(e));return{kind:`signer_set`,signers:i}}function _n(e){let t=`Wallet registration setup intent`,r=z({responseName:t,field:`intent`,value:e});if(H(r,[`version`,`walletId`,`authMethod`,`signerSelection`,`foundingWalletAuthMethodId`,`runtimePolicyScope`,`nonceB64u`],t),W(r,`version`,t)!==`registration_intent_v1`)throw Error(`${t}.version is invalid`);let a=n(W(r,`walletId`,t));if(!a.ok)throw Error(`${t}.walletId is invalid`);let o=i(W(r,`foundingWalletAuthMethodId`,t));if(!o.ok)throw Error(`${t}.foundingWalletAuthMethodId is invalid`);let s=dn(B(r,`authMethod`,t)),c=gn(B(r,`signerSelection`,t)),l=ln(V(r,`runtimePolicyScope`,t),t),u=W(r,`nonceB64u`,t);return l===void 0?{version:`registration_intent_v1`,walletId:a.value,authMethod:s,signerSelection:c,foundingWalletAuthMethodId:o.value,nonceB64u:u}:{version:`registration_intent_v1`,walletId:a.value,authMethod:s,signerSelection:c,foundingWalletAuthMethodId:o.value,runtimePolicyScope:l,nonceB64u:u}}function vn(e){let t=`Wallet add-signer ECDSA derivation`,n=z({responseName:t,field:`response`,value:e});if(H(n,[`ok`,`addSignerCeremonyId`,`ecdsa`],`${t} response`),B(n,`ok`,`${t} response`)!==!0)throw Error(`${t} response is not successful`);let r=z({responseName:t,field:`ecdsa`,value:B(n,`ecdsa`,`${t} response`)});if(H(r,[`kind`,`strictResult`],`${t} response ecdsa`),B(r,`kind`,`${t} response ecdsa`)!==`router_ab_ecdsa_registration_forwarded_v1`)throw Error(`${t} response kind is invalid`);return{ok:!0,addSignerCeremonyId:k({responseName:t,field:`addSignerCeremonyId`,value:B(n,`addSignerCeremonyId`,t)}),ecdsa:{kind:`router_ab_ecdsa_registration_forwarded_v1`,strictResult:qe(B(r,`strictResult`,`${t} response ecdsa`))}}}function yn(e){let t=`Wallet add-signer ECDSA activation`,n=z({responseName:t,field:`response`,value:e});if(H(n,[`ok`,`addSignerCeremonyId`,`ecdsa`],`${t} response`),B(n,`ok`,`${t} response`)!==!0)throw Error(`${t} response is not successful`);let r=z({responseName:t,field:`ecdsa`,value:B(n,`ecdsa`,`${t} response`)});if(H(r,[`kind`,`activation`,`bootstrap`],`${t} response ecdsa`),B(r,`kind`,`${t} response ecdsa`)!==`router_ab_ecdsa_registration_activated_v1`)throw Error(`${t} response kind is invalid`);return{ok:!0,addSignerCeremonyId:k({responseName:t,field:`addSignerCeremonyId`,value:B(n,`addSignerCeremonyId`,t)}),ecdsa:{kind:`router_ab_ecdsa_registration_activated_v1`,activation:Ye(B(r,`activation`,`${t} response ecdsa`)),bootstrap:at(B(r,`bootstrap`,`${t} response ecdsa`))}}}function bn(e){return e.authMethod.kind===`email_otp`}function xn(e){let t=`Wallet add-auth-method intent`,n=z({responseName:t,field:`body`,value:e});if(H(n,[`ok`,`intent`,`addAuthMethodIntentDigestB64u`,`addAuthMethodIntentGrant`,`expiresAtMs`],t),B(n,`ok`,t)!==!0)throw Error(`${t} response is not successful`);let r=ke(B(n,`intent`,t)),i;try{i=ge(B(n,`addAuthMethodIntentDigestB64u`,t))}catch{throw Error(`${t} response has invalid addAuthMethodIntentDigestB64u`)}let a=B(n,`addAuthMethodIntentGrant`,t);if(typeof a!=`string`||!a.trim())throw Error(`${t} response is missing addAuthMethodIntentGrant`);return{ok:!0,intent:r,addAuthMethodIntentDigestB64u:i,addAuthMethodIntentGrant:Ie(a),expiresAtMs:M({responseName:t,field:`expiresAtMs`,value:B(n,`expiresAtMs`,t),minimum:1})}}function Sn(e){let t=`Wallet add-signer intent`,n=z({responseName:t,field:`body`,value:e});if(H(n,[`ok`,`intent`,`addSignerIntentDigestB64u`,`addSignerIntentGrant`,`expiresAtMs`],t),B(n,`ok`,t)!==!0)throw Error(`${t} response is not successful`);let r=Pe(B(n,`intent`,t)),i;try{i=ge(B(n,`addSignerIntentDigestB64u`,t))}catch{throw Error(`${t} response has invalid addSignerIntentDigestB64u`)}let a=B(n,`addSignerIntentGrant`,t);if(typeof a!=`string`||!a.trim())throw Error(`${t} response is missing addSignerIntentGrant`);return{ok:!0,intent:r,addSignerIntentDigestB64u:i,addSignerIntentGrant:Ne(a),expiresAtMs:M({responseName:t,field:`expiresAtMs`,value:B(n,`expiresAtMs`,t),minimum:1})}}function Cn(e){let r=`Wallet add-auth-method finalize`,i=z({responseName:r,field:`body`,value:e});if(B(i,`ok`,r)!==!0)throw Error(`${r} response is not successful`);let a=z({responseName:r,field:`authMethod`,value:B(i,`authMethod`,r)}),o=B(a,`kind`,`${r} authMethod`);if(o!==`passkey`&&o!==`email_otp`)throw Error(`${r} response has invalid authMethod kind`);let c=n(B(i,`walletId`,r));if(!c.ok)throw Error(`${r} response has invalid walletId`);let l=Be(B(i,`authority`,r));if(!l)throw Error(`${r} response has invalid authority`);if(l.walletId!==c.value)throw Error(`${r} response authority wallet mismatch`);if(o===`passkey`){if(H(i,[`ok`,`walletId`,`authority`,`rpId`,`authMethod`],r),H(a,[`kind`,`status`,`credentialIdB64u`,`credentialPublicKeyB64u`,`counter`,`device`],`${r} authMethod`),B(a,`status`,r)!==`active`)throw Error(`${r} response has invalid authMethod status`);if(l.factor.kind!==`passkey`||l.verifier.kind!==`webauthn`)throw Error(`${r} response has inconsistent passkey authority`);let e=t(B(i,`rpId`,r));if(!e.ok)throw Error(`${r} response has invalid rpId`);let n=s(B(a,`credentialIdB64u`,r));if(!n.ok)throw Error(`${r} response has invalid credentialIdB64u`);let o=B(a,`credentialPublicKeyB64u`,r);if(typeof o!=`string`||!o.trim())throw Error(`${r} response is missing credentialPublicKeyB64u`);let u=B(a,`counter`,r);if(typeof u!=`number`||!Number.isSafeInteger(u)||u<0)throw Error(`${r} response has invalid counter`);let d=Oe(B(a,`device`,r));if(!d)throw Error(`${r} response has invalid device`);if(l.factor.credentialIdB64u!==n.value||l.verifier.rpId!==e.value)throw Error(`${r} response passkey authority binding mismatch`);return{ok:!0,walletId:c.value,authority:l,rpId:e.value,authMethod:{kind:`passkey`,status:`active`,credentialIdB64u:n.value,credentialPublicKeyB64u:o.trim(),counter:u,device:d}}}if(H(i,[`ok`,`walletId`,`authority`,`authMethod`],r),H(a,[`kind`,`status`],`${r} authMethod`),B(a,`status`,r)!==`active`)throw Error(`${r} response has invalid authMethod status`);if(l.factor.kind!==`email_otp`||l.verifier.kind!==`email_otp_wallet_auth_method`)throw Error(`${r} response has inconsistent email OTP authority`);return{ok:!0,walletId:c.value,authority:l,authMethod:{kind:`email_otp`,status:`active`}}}function wn(e){let t=`Wallet add-auth-method start`,n=z({responseName:t,field:`body`,value:e.value});if(B(n,`ok`,t)!==!0)throw Error(`${t} response is not successful`);let r=k({responseName:t,field:`addAuthMethodCeremonyId`,value:B(n,`addAuthMethodCeremonyId`,t)}),i=En(B(n,`intent`,t),e.expectedIntent);return e.expectedIntent.authMethod.kind===`email_otp`?(H(n,[`ok`,`addAuthMethodCeremonyId`,`intent`,`custodyEnvelope`,`addAuthMethodCeremonyExpiresAtMs`],t),{ok:!0,addAuthMethodCeremonyId:r,intent:i,custodyEnvelope:S(B(n,`custodyEnvelope`,t)),addAuthMethodCeremonyExpiresAtMs:M({responseName:t,field:`addAuthMethodCeremonyExpiresAtMs`,value:B(n,`addAuthMethodCeremonyExpiresAtMs`,t),minimum:1})}):(H(n,[`ok`,`addAuthMethodCeremonyId`,`intent`,`custodyEnvelope`,`registration`,`addAuthMethodCeremonyExpiresAtMs`],t),{ok:!0,addAuthMethodCeremonyId:r,intent:i,custodyEnvelope:S(B(n,`custodyEnvelope`,t)),registration:Me(B(n,`registration`,t)),addAuthMethodCeremonyExpiresAtMs:M({responseName:t,field:`addAuthMethodCeremonyExpiresAtMs`,value:B(n,`addAuthMethodCeremonyExpiresAtMs`,t),minimum:1})})}function Tn(e,t){try{if(!Ae(Pe(e),t))throw Error(`intent mismatch`)}catch{throw Error(`Wallet add-signer start response changed the admitted intent`)}return t}function En(e,t){try{if(!Fe(ke(e),t))throw Error(`intent mismatch`)}catch{throw Error(`Wallet add-auth-method start response changed the admitted intent`)}return t}function Dn(e,t){let n=z({responseName:t,field:`ecdsa.prepare`,value:e});if(H(n,nn,t),B(n,`formatVersion`,t)!==`ecdsa-derivation-role-local`||B(n,`keyScope`,t)!==`evm-family`)throw Error(`${t} response has invalid prepare discriminator`);let r=ae(B(n,`runtimePolicyScope`,t));if(!r)throw Error(`${t} response has invalid runtimePolicyScope`);return{formatVersion:`ecdsa-derivation-role-local`,walletId:k({responseName:t,field:`prepare.walletId`,value:B(n,`walletId`,t)}),evmFamilySigningKeySlotId:k({responseName:t,field:`prepare.evmFamilySigningKeySlotId`,value:B(n,`evmFamilySigningKeySlotId`,t)}),ecdsaThresholdKeyId:k({responseName:t,field:`prepare.ecdsaThresholdKeyId`,value:B(n,`ecdsaThresholdKeyId`,t)}),signingRootId:k({responseName:t,field:`prepare.signingRootId`,value:B(n,`signingRootId`,t)}),signingRootVersion:k({responseName:t,field:`prepare.signingRootVersion`,value:B(n,`signingRootVersion`,t)}),keyScope:`evm-family`,relayerKeyId:k({responseName:t,field:`prepare.relayerKeyId`,value:B(n,`relayerKeyId`,t)}),registrationPreparationId:tn(k({responseName:t,field:`prepare.registrationPreparationId`,value:B(n,`registrationPreparationId`,t)})),requestId:k({responseName:t,field:`prepare.requestId`,value:B(n,`requestId`,t)}),thresholdSessionId:k({responseName:t,field:`prepare.thresholdSessionId`,value:B(n,`thresholdSessionId`,t)}),ttlMs:M({responseName:t,field:`prepare.ttlMs`,value:B(n,`ttlMs`,t),minimum:1}),remainingUses:M({responseName:t,field:`prepare.remainingUses`,value:B(n,`remainingUses`,t),minimum:0}),participantIds:[...N(B(n,`participantIds`,t),t)],runtimePolicyScope:r}}function On(e,t){let n=z({responseName:t,field:`ecdsa.prepare`,value:e});if(H(n,nn,t),B(n,`formatVersion`,t)!==`ecdsa-derivation-role-local`||B(n,`keyScope`,t)!==`evm-family`)throw Error(`${t} response has invalid prepare discriminator`);for(let e of[`walletId`,`evmFamilySigningKeySlotId`,`ecdsaThresholdKeyId`,`signingRootId`,`signingRootVersion`,`relayerKeyId`,`registrationPreparationId`,`requestId`,`thresholdSessionId`])W(n,e,t);K(n,`ttlMs`,t,1),K(n,`remainingUses`,t,0),cn(B(n,`participantIds`,t),`${t}.participantIds`),un(B(n,`runtimePolicyScope`,t),t)}function kn(e){let t=`Wallet registration setup ECDSA`,n=z({responseName:t,field:`ecdsa`,value:e});if(H(n,[`kind`,`chainTargets`,`prepare`,`strictRegistration`],t),B(n,`kind`,t)!==`evm_family_ecdsa_keygen`)throw Error(`${t} response has an invalid kind`);let r=B(n,`chainTargets`,t);if(!Array.isArray(r)||r.length===0)throw Error(`${t} response has invalid chainTargets`);let i=[];for(let e of r){let n=J(e,`${t}.chainTargets`);if(i.some(e=>q(e,n)))throw Error(`${t} response has duplicate chainTargets`);i.push(n)}let[a,...o]=i;if(!a)throw Error(`${t} response has invalid chainTargets`);let s=B(n,`prepare`,t);On(s,t);let c=Dn(s,t),l=Qe(B(n,`strictRegistration`,t));if(l.registration_purpose!==`wallet_registration`)throw Error(`${t} response has an invalid registration purpose`);return{kind:`evm_family_ecdsa_keygen`,chainTargets:[a,...o],prepare:c,strictRegistration:l}}function An(e){let t=!1,n=!1;for(let r of e.signerSelection.signers)switch(r.kind){case`near_ed25519`:t=!0;break;case`evm_family_ecdsa`:n=!0;break;default:return jn(r)}if(t&&n)return`near_ed25519_and_evm_family_ecdsa`;if(n)return`evm_family_ecdsa`;if(t)return`near_ed25519`;throw Error(`Wallet registration setup intent has no signer branch`)}function jn(e){throw Error(`Unsupported wallet registration setup signer: ${String(e)}`)}function Mn(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0}function Nn(e,t){return e!==void 0&&e.orgId===t.orgId&&e.projectId===t.projectId&&e.envId===t.envId&&e.signingRootVersion===t.signingRootVersion}function Pn(e,t){try{return q(J(e,`Wallet registration setup intent`),t)}catch{return!1}}function Fn(e){let t=e.intent.signerSelection.signers.find(e=>e.kind===`evm_family_ecdsa`);if(!t)throw Error(`${e.responseName} response has no ECDSA intent branch`);if(t.chainTargets.length!==e.ecdsa.chainTargets.length||t.chainTargets.some((t,n)=>!Pn(t,e.ecdsa.chainTargets[n])))throw Error(`${e.responseName} response ECDSA chainTargets do not match intent`);if(!Mn(t.participantIds,e.ecdsa.prepare.participantIds))throw Error(`${e.responseName} response ECDSA participantIds do not match intent`);if(e.ecdsa.prepare.walletId!==String(e.walletId))throw Error(`${e.responseName} response ECDSA prepare walletId does not match response`);if(!Nn(e.intent.runtimePolicyScope,e.ecdsa.prepare.runtimePolicyScope))throw Error(`${e.responseName} response ECDSA runtimePolicyScope does not match intent`);let n=e.ecdsa.strictRegistration.lifecycle;if(n.lifecycle_id!==e.registrationCeremonyId||n.account_id!==String(e.walletId)||e.ecdsa.strictRegistration.client_id!==String(e.walletId))throw Error(`${e.responseName} response ECDSA identities do not match response`)}function In(e){let t=`Wallet registration setup`,r=z({responseName:t,field:`body`,value:e});if(B(r,`ok`,t)!==!0)throw Error(`${t} response is not successful`);let a=B(r,`kind`,t);if(a!==`near_ed25519`&&a!==`evm_family_ecdsa`&&a!==`near_ed25519_and_evm_family_ecdsa`)throw Error(`${t} response kind is invalid`);let o=a!==`near_ed25519`;H(r,[`ok`,`registrationCeremonyId`,`walletId`,`walletAuthMethodId`,`registrationIntentDigestB64u`,`intent`,`signedSetup`,`home`,`kind`,...o?[`ecdsa`]:[]],t);let s=W(r,`registrationCeremonyId`,t),c=n(W(r,`walletId`,t));if(!c.ok)throw Error(`${t} response has an invalid walletId`);let l=i(W(r,`walletAuthMethodId`,t));if(!l.ok)throw Error(`${t} response has an invalid walletAuthMethodId`);let u=_n(B(r,`intent`,t));if(u.walletId!==c.value)throw Error(`${t} response walletId does not match intent`);if(u.foundingWalletAuthMethodId!==l.value)throw Error(`${t} response walletAuthMethodId does not match intent`);let d;try{d=ge(B(r,`registrationIntentDigestB64u`,t))}catch{throw Error(`${t} response has an invalid registrationIntentDigestB64u`)}let f=fe(B(r,`home`,t)),p=B(r,`signedSetup`,t);if(typeof p!=`string`||!p.trim())throw Error(`${t} response missing signedSetup`);if(!o){if(An(u)!==a)throw Error(`${t} response kind does not match intent`);return{ok:!0,registrationCeremonyId:s,walletId:c.value,walletAuthMethodId:l.value,registrationIntentDigestB64u:d,intent:u,signedSetup:p,home:f,kind:`near_ed25519`}}let m=kn(B(r,`ecdsa`,t));if(An(u)!==a)throw Error(`${t} response kind does not match intent`);return Fn({responseName:t,registrationCeremonyId:s,walletId:c.value,intent:u,ecdsa:m}),{ok:!0,registrationCeremonyId:s,walletId:c.value,walletAuthMethodId:l.value,registrationIntentDigestB64u:d,intent:u,signedSetup:p,home:f,kind:a,ecdsa:m}}function Ln(e){let t=be(e.authMethod);if(!t)throw Error(`Wallet registration setup request authMethod is invalid`);let n=xe(e.signerSelection);if(!n.ok)throw Error(`Wallet registration setup request signerSelection is invalid: ${n.message}`);let r=Se(n.value,{normalizeEcdsaChainTarget:mn});if(!r.ok)throw Error(`Wallet registration setup request signerSelection is invalid: ${r.message}`);return{wallet:e.wallet??{kind:`server_allocated`},authMethod:t,signerSelection:r.value}}function Rn(e,t){let n={version:`registration_intent_v1`,walletId:e.walletId,authMethod:t.authMethod,signerSelection:t.signerSelection,foundingWalletAuthMethodId:e.foundingWalletAuthMethodId,nonceB64u:e.nonceB64u};return e.runtimePolicyScope===void 0?n:{...n,runtimePolicyScope:e.runtimePolicyScope}}async function zn(e){if(e.requestedWallet?.kind===`provided`&&String(e.requestedWallet.walletId)!==e.response.walletId)throw Error(`Wallet registration setup response walletId does not match request`);if(await je(e.response.intent)!==e.response.registrationIntentDigestB64u)throw Error(`Wallet registration setup response digest does not match intent`);if(await je(Rn(e.response.intent,e.request))!==e.response.registrationIntentDigestB64u)throw Error(`Wallet registration setup response intent does not match request`)}function Bn(e,t){let n=`Wallet add-signer ECDSA start`,r=z({responseName:n,field:`ecdsa`,value:e});H(r,[`kind`,`chainTargets`,`prepare`,`strictRegistration`,`custodyEnvelope`],n);let i=B(r,`kind`,n),a=B(r,`chainTargets`,n);if(i!==`evm_family_ecdsa_keygen`||!Array.isArray(a))throw Error(`${n} response has invalid payload`);if(t.signerSelection.mode!==`ecdsa`)throw Error(`${n} response substituted signer branch`);let o=t.signerSelection.ecdsa.chainTargets;if(a.length!==o.length)throw Error(`${n} response changed target count`);let s=[];for(let e=0;e<a.length;e+=1){let t=a[e],r=Tt(t,n),i=o[e];if(!i||!Te(r,Tt(i,n)))throw Error(`${n} response changed chainTarget`);s.push(r)}let[c,...l]=s;if(!c)throw Error(`${n} response requires an EVM-family target`);let u=Dn(B(r,`prepare`,n),n),d=Qe(B(r,`strictRegistration`,n));if(d.registration_purpose!==`wallet_add_signer`)throw Error(`${n} response has invalid registration purpose`);return{kind:`evm_family_ecdsa_keygen`,chainTargets:[c,...l],prepare:u,strictRegistration:d}}function Vn(e){let t=`Wallet add-signer start`,n=z({responseName:t,field:`body`,value:e.value});if(H(n,[`ok`,`addSignerCeremonyId`,`intent`,`authorizationKind`,`kind`,`ed25519`,`ecdsa`],t),B(n,`ok`,t)!==!0)throw Error(`${t} response is not successful`);let r=k({responseName:t,field:`addSignerCeremonyId`,value:B(n,`addSignerCeremonyId`,t)}),i=Tn(B(n,`intent`,t),e.expectedIntent),a=B(n,`authorizationKind`,t);if(a!==`webauthn_assertion`)throw Error(`${t} response has invalid authorization kind`);switch(B(n,`kind`,t)){case`near_ed25519`:{if(a!==`webauthn_assertion`||i.signerSelection.mode!==`ed25519`||V(n,`ecdsa`,t)!==void 0)throw Error(`${t} response substituted signer branch`);let e=z({responseName:t,field:`ed25519`,value:B(n,`ed25519`,t)});H(e,[`admissionRequest`,`custodyEnvelope`],t);let o=b(B(e,`admissionRequest`,t));if(!o.ok)throw Error(o.message);return{ok:!0,addSignerCeremonyId:r,intent:i,authorizationKind:`webauthn_assertion`,kind:`near_ed25519`,ed25519:{admissionRequest:o.value,custodyEnvelope:S(B(e,`custodyEnvelope`,t))}}}case`evm_family_ecdsa`:{if(i.signerSelection.mode!==`ecdsa`||V(n,`ed25519`,t)!==void 0)throw Error(`${t} response substituted signer branch`);let e=B(n,`ecdsa`,t),a=Bn(e,i),o=z({responseName:t,field:`ecdsa`,value:e});return{ok:!0,addSignerCeremonyId:r,intent:i,authorizationKind:`webauthn_assertion`,kind:`evm_family_ecdsa`,ecdsa:{...a,custodyEnvelope:S(B(o,`custodyEnvelope`,t))}}}default:throw Error(`${t} response has invalid kind`)}}function Hn(e){let t=`Wallet add-signer finalize`,n=z({responseName:t,field:`body`,value:e.value});H(n,[`ok`,`walletId`,`kind`,`rpId`,`credentialIdB64u`,`ed25519`,`ecdsa`,`authority`],t);let r=B(n,`ok`,t),i=B(n,`kind`,t);if(r!==!0||i!==e.expectedKind)throw Error(`${t} response substituted signer branch`);let a=rt(k({responseName:t,field:`walletId`,value:B(n,`walletId`,t)})),o=P(B(n,`rpId`,t),t);switch(i){case`near_ed25519`:{if(V(n,`ecdsa`,t)!==void 0||V(n,`authority`,t)!==void 0)throw Error(`${t} response mixed signer branches`);let e=Ct(B(n,`ed25519`,t),`Wallet add-signer Ed25519 finalize`);return{ok:!0,walletId:a,kind:`near_ed25519`,rpId:o,credentialIdB64u:k({responseName:t,field:`credentialIdB64u`,value:B(n,`credentialIdB64u`,t)}),ed25519:e}}case`evm_family_ecdsa`:{if(V(n,`ed25519`,t)!==void 0||V(n,`credentialIdB64u`,t)!==void 0)throw Error(`${t} response mixed signer branches`);let e=z({responseName:t,field:`ecdsa`,value:B(n,`ecdsa`,t)});H(e,[`walletKeys`],t);let r=U(B(e,`walletKeys`,t),`${t} walletKeys`);if(r.length===0)throw Error(`${t} response has invalid walletKeys`);let i=ze(B(n,`authority`,t));if(!i.ok||i.value.state!==`active`||i.value.walletId!==a)throw Error(`${t} response has invalid authority`);return{ok:!0,walletId:a,kind:`evm_family_ecdsa`,rpId:o,ecdsa:{walletKeys:r.map(Un)},authority:i.value}}default:throw Error(`${t} response has invalid kind`)}}function Un(e){return Et(e,`Wallet add-signer ECDSA finalize`)}function Y(e){let t=String(e.expected||``).trim(),n=String(e.actual||``).trim();if(!t||!n)throw Error(`ECDSA registration bootstrap returned incomplete ${e.field}`);if(t!==n)throw Error(`ECDSA registration bootstrap ${e.field} mismatch`);return n}function Wn(e){let t=e.expected.map(e=>Math.floor(Number(e))),n=e.actual.map(e=>Math.floor(Number(e)));if(t.length===0||n.length===0||t.some(e=>!Number.isSafeInteger(e)||e<=0)||n.some(e=>!Number.isSafeInteger(e)||e<=0))throw Error(`ECDSA registration bootstrap returned incomplete participantIds`);if(t.length!==n.length||t.some((e,t)=>e!==n[t]))throw Error(`ECDSA registration bootstrap participantIds mismatch`);return n}function Gn(e){let t=e.clientBootstrap,n=e.serverBootstrap;Y({field:`derivationClientSharePublicKey33B64u`,expected:t.derivationClientSharePublicKey33B64u,actual:n.publicIdentity.derivationClientSharePublicKey33B64u});let r=Y({field:`contextBinding32B64u`,expected:t.contextBinding32B64u,actual:n.contextBinding32B64u}),i=Y({field:`walletId`,expected:t.walletId,actual:n.walletId}),a=Y({field:`evmFamilySigningKeySlotId`,expected:t.evmFamilySigningKeySlotId,actual:n.evmFamilySigningKeySlotId});Y({field:`activationEpoch`,expected:e.activationEpoch,actual:n.activationEpoch});let o=Wn({expected:t.participantIds,actual:n.participantIds}),s=Xe(n.routerAbEcdsaDerivationNormalSigning),c=String(n.ecdsaThresholdKeyId||``).trim(),l=String(n.keyHandle||``).trim(),u=String(n.signingRootId||``).trim(),d=String(n.signingRootVersion||``).trim(),f=String(n.applicationBindingDigestB64u||``).trim(),p=String(n.thresholdEcdsaPublicKeyB64u||``).trim(),m=String(n.ethereumAddress||``).trim(),ee=String(n.relayerKeyId||``).trim(),te=String(n.relayerVerifyingShareB64u||``).trim(),h=Math.floor(Number(n.relayerShareRetryCounter));if(!i||!a||!l||!c||!u||!d||!f||!p||!m||!ee||!te||!Number.isSafeInteger(h)||h<0||!o.length||o.some(e=>!Number.isSafeInteger(e)||e<=0))throw Error(`ECDSA registration bootstrap returned incomplete session material`);return{walletId:i,evmFamilySigningKeySlotId:a,ecdsaThresholdKeyId:c,relayerKeyId:ee,applicationBindingDigestB64u:f,contextBinding32B64u:r,publicIdentity:n.publicIdentity,relayerShareRetryCounter:h,keyHandle:l,signingRootId:u,signingRootVersion:d,thresholdEcdsaPublicKeyB64u:p,ethereumAddress:m,relayerVerifyingShareB64u:te,participantIds:o,routerAbEcdsaDerivationNormalSigning:s}}function Kn(e){let t=`Wallet ECDSA key-facts inventory`,n=z({responseName:t,field:`body`,value:e.value});if(H(n,[`ok`,`ecdsaKeyIdentityTargets`,`diagnostics`],t),B(n,`ok`,t)!==!0)throw Error(`${t} response is not successful`);let r=U(B(n,`ecdsaKeyIdentityTargets`,t),`${t} ecdsaKeyIdentityTargets`);return{ok:!0,records:xt({walletId:e.walletId,rpId:e.rpId,records:r}),diagnostics:B(n,`diagnostics`,t)}}async function qn(e){let t=String(e.auth?.publishableKey||``).trim(),n=String(e.auth?.environmentId||``).trim();if(!t||!n)return{ok:!1,code:`invalid_body`,message:`registration setup requires a publishable key and environment id`};let r=Ln(e.request),i=await Re({relayerUrl:e.relayerUrl,publishableKey:t,environmentId:n}),a=await Le.begin(i,r),o=In(await I({relayerUrl:e.relayerUrl,path:re,headers:{...e.headers,Authorization:`Bearer ${t}`,[zt]:n},body:{registrationOperationId:a.operationId,wallet:r.wallet,signerSelection:r.signerSelection,authMethod:r.authMethod},...e.onServerTiming?{onServerTiming:e.onServerTiming}:{}}));return o.ok?(await zn({response:o,...e.request.wallet?{requestedWallet:e.request.wallet}:{},request:r}),await Le.accept(a,o),o):o}async function Jn(e){let t=String(e.walletId||``).trim();if(!t)throw Error(`walletId is required for add-signer intent`);let n=String(e.auth.publishableKey||``).trim(),r=String(e.auth.environmentId||``).trim();if(!n||!r)throw Error(`add-signer intent requires a publishable key and environment id`);return Sn(await I({relayerUrl:e.relayerUrl,path:`/wallets/${encodeURIComponent(t)}/signers/intent`,headers:{Authorization:`Bearer ${n}`,[zt]:r},body:e.request}))}function Yn(e){let t=`Wallet auth-method revoke`,r=z({responseName:t,field:`body`,value:e});if(B(r,`ok`,t)!==!0)throw Error(`${t} response is not successful`);let i=n(B(r,`walletId`,t));if(!i.ok)throw Error(`${t} response has invalid walletId`);let a=z({responseName:t,field:`authMethod`,value:B(r,`authMethod`,t)});if(H(a,[`kind`,`status`],`${t} response authMethod`),B(a,`status`,t)!==`revoked`)throw Error(`${t} response has invalid authMethod status`);switch(B(a,`kind`,t)){case`passkey`:return H(r,[`ok`,`walletId`,`authMethod`,`rpId`],t),{ok:!0,walletId:i.value,authMethod:{kind:`passkey`,status:`revoked`},rpId:P(B(r,`rpId`,t),t)};case`email_otp`:return H(r,[`ok`,`walletId`,`authMethod`],t),{ok:!0,walletId:i.value,authMethod:{kind:`email_otp`,status:`revoked`}};default:throw Error(`${t} response has invalid authMethod kind`)}}async function Xn(e){let t=String(e.walletId||``).trim(),n=String(e.walletAuthMethodId||``).trim();if(!t||!n)throw Error(`auth-method revoke requires a wallet and a target method`);let r={relayerUrl:e.relayerUrl,path:`/wallets/${encodeURIComponent(t)}/auth-methods/${encodeURIComponent(n)}/revoke`,body:{walletId:t,walletAuthMethodId:n,requestedAtMs:e.requestedAtMs,sourceProof:e.sourceProof}},i;try{i=await I(r)}catch(e){if(!(e instanceof TypeError))throw e;i=await I(r)}return Yn(i)}async function Zn(e){let t=String(e.walletId||``).trim();if(!t)throw Error(`walletId is required for add-auth-method intent`);let n=String(e.auth.publishableKey||``).trim(),r=String(e.auth.environmentId||``).trim();if(!n||!r)throw Error(`add-auth-method intent requires a publishable key and environment id`);let i=e.request.caller.caller===`same_device_addition`?{caller:`same_device_addition`,source:e.request.caller.source}:{caller:`linked_device_ceremony`};return xn(await I({relayerUrl:e.relayerUrl,path:`/wallets/${encodeURIComponent(t)}/auth-methods/intent`,headers:{Authorization:`Bearer ${n}`,[zt]:r},body:{walletId:e.request.walletId,rpId:e.request.rpId,authMethod:e.request.authMethod,...i}}))}function Qn(e){let t=`Wallet registration respond`,n=z({responseName:t,field:`body`,value:e});if(B(n,`ok`,t)!==!0)throw Error(`${t} response is not successful`);let r=k({responseName:t,field:`registrationCeremonyId`,value:B(n,`registrationCeremonyId`,t)}),i=B(n,`kind`,t);if(i!==`evm_family_ecdsa`&&i!==`near_ed25519_and_evm_family_ecdsa`&&i!==`near_ed25519`)throw Error(`${t} response kind is invalid`);let a=i!==`near_ed25519`,o=i!==`evm_family_ecdsa`;H(n,[`ok`,`registrationCeremonyId`,`kind`,...a?[`ecdsa`]:[],...o?[`ed25519`]:[]],t);let s=V(n,`ed25519`,t);if(o&&s===void 0)throw Error(`${t} signer plan is missing its ed25519 deferred work`);if(!a)return{ok:!0,registrationCeremonyId:r,kind:`near_ed25519`,ed25519:$n(s)};let c=z({responseName:t,field:`ecdsa`,value:B(n,`ecdsa`,t)});if(H(c,[`kind`,`strictResult`],`${t} ecdsa`),B(c,`kind`,`${t} ecdsa`)!==`router_ab_ecdsa_registration_forwarded_v1`)throw Error(`${t} ecdsa kind is invalid`);let l=o?er(s):null,u={kind:`router_ab_ecdsa_registration_forwarded_v1`,strictResult:qe(B(c,`strictResult`,`${t} ecdsa`))};return l?{ok:!0,registrationCeremonyId:r,kind:`near_ed25519_and_evm_family_ecdsa`,ecdsa:u,ed25519:l}:{ok:!0,registrationCeremonyId:r,kind:`evm_family_ecdsa`,ecdsa:u}}function $n(e){let t=`Wallet registration respond ed25519 admission`,n=z({responseName:t,field:`ed25519`,value:e});if(H(n,[`status`,`admissionRequest`,`admissionReceipt`],t),B(n,`status`,t)!==`admitted`)throw Error(`${t} status is invalid`);let r=b(B(n,`admissionRequest`,t)),i=tt(B(n,`admissionReceipt`,t));if(!r.ok||!i.ok)throw Error(`${t} request or receipt is invalid`);return{status:`admitted`,admissionRequest:r.value,admissionReceipt:i.value}}function er(e){let t=`Wallet registration respond ed25519`,n=z({responseName:t,field:`ed25519`,value:e});if(H(n,[`status`,`admissionRequest`],t),B(n,`status`,t)!==`deferred`)throw Error(`${t} status is invalid`);let r=b(B(n,`admissionRequest`,t));if(!r.ok)throw Error(`${t} admissionRequest is invalid`);return{status:`deferred`,admissionRequest:r.value}}function tr(e){let t={registrationCeremonyId:e.registrationCeremonyId,signedSetup:e.signedSetup,kind:e.signerPlanKind};switch(e.kind){case`passkey`:t.webauthn_registration=e.webauthnRegistration;break;case`email_otp`:t.emailOtpRegistrationProof=e.emailOtpRegistrationProof;break}return t.ecdsa=e.ecdsa,t}async function nr(e){return Qn(await I({relayerUrl:e.relayerUrl,path:It,headers:e.headers,body:tr(e),onServerTiming:e.onServerTiming}))}function rr(e,t){let n=ot(e);if(n===null||n.session.walletId!==t)throw Error(`Wallet registration established session direct session result is invalid`);return n}function ir(e,t){let n=`Wallet registration activate`,r=V(e,`registrationDiagnostics`,n),i=V(e,`rpId`,n),a=V(e,`walletCustody`,n),o=V(e,`custodyKeyManifestDigestB64u`,n);return{ok:B(e,`ok`,n),walletId:B(e,`walletId`,n),authority:B(e,`authority`,n),foundingAuthority:B(e,`foundingAuthority`,n),foundingAuthMethod:B(e,`foundingAuthMethod`,n),...r===void 0?{}:{registrationDiagnostics:r},...i===void 0?{}:{rpId:i},authMethod:B(e,`authMethod`,n),...a===void 0?{}:{walletCustody:a},...o===void 0?{}:{custodyKeyManifestDigestB64u:o},kind:`evm_family_ecdsa`,ecdsa:{walletKeys:B(t,`walletKeys`,n)}}}function ar(e){let t=`Wallet registration NEAR provisioning`,n=V(e,`registrationDiagnostics`,t),r=V(e,`rpId`,t),i=V(e,`walletCustody`,t),a=V(e,`custodyKeyManifestDigestB64u`,t);return{ok:B(e,`ok`,t),walletId:B(e,`walletId`,t),authority:B(e,`authority`,t),foundingAuthority:B(e,`foundingAuthority`,t),foundingAuthMethod:B(e,`foundingAuthMethod`,t),...n===void 0?{}:{registrationDiagnostics:n},...r===void 0?{}:{rpId:r},authMethod:B(e,`authMethod`,t),...i===void 0?{}:{walletCustody:i},...a===void 0?{}:{custodyKeyManifestDigestB64u:a},kind:`near_ed25519`,authorityScope:B(e,`authorityScope`,t),accountProvisioning:B(e,`accountProvisioning`,t),resolvedAccount:B(e,`resolvedAccount`,t),ed25519:B(e,`ed25519`,t)}}function or(e){let t=`Wallet registration activate`,n=z({responseName:t,field:`body`,value:e}),r=B(n,`kind`,t),i=V(n,`nearProvisioning`,t),a=V(n,`registrationEstablishedSession`,t);if(r!==`evm_family_ecdsa`)throw Error(`${t} response has invalid kind`);let o=z({responseName:t,field:`ecdsa`,value:B(n,`ecdsa`,t)});H(n,[`ok`,`walletId`,`authority`,`foundingAuthority`,`foundingAuthMethod`,`registrationDiagnostics`,`rpId`,`authMethod`,`walletCustody`,`custodyKeyManifestDigestB64u`,`kind`,`ecdsa`,`nearProvisioning`,`registrationEstablishedSession`],t),H(o,[`walletKeys`,`activation`,`bootstrap`],t);let s=V(o,`activation`,t),c=V(o,`bootstrap`,t);if(i!==void 0){let e=z({responseName:t,field:`nearProvisioning`,value:i});if(H(e,[`status`],`${t} nearProvisioning`),B(e,`status`,`${t} nearProvisioning`)!==`near_pending`)throw Error(`${t} nearProvisioning status is invalid`)}if(s===void 0||c===void 0)throw Error(`${t} is missing the activation payload the client needs to build its ECDSA session`);let l=Ft({value:ir(n,o),expectedKind:`evm_family_ecdsa`});if(!l.ok||l.kind!==`evm_family_ecdsa`)throw Error(`${t} did not return an activated ECDSA wallet`);let u=rr(a,l.walletId);return{...l,ecdsa:{...l.ecdsa,activation:Ye(s),bootstrap:at(c)},registrationEstablishedSession:u,...i===void 0?{}:{nearProvisioning:{status:`near_pending`}}}}function sr(e){let t={registrationCeremonyId:e.registrationCeremonyId,kind:e.signerPlanKind,signedSetup:e.signedSetup,idempotencyKey:e.idempotencyKey};return t.ecdsa=e.ecdsa,e.emailOtpEnrollment&&(t.emailOtpEnrollment=e.emailOtpEnrollment),e.walletCustodyCommit&&(t.walletCustodyCommit=e.walletCustodyCommit),t}async function cr(e){return or(await I({relayerUrl:e.relayerUrl,path:Lt,headers:e.headers,body:sr(e),onServerTiming:e.onServerTiming}))}function lr(e){let t=`Wallet registration session seal`,n=z({responseName:t,field:`body`,value:e});H(n,[`ciphertext`,`keyVersion`,`expiresAtMs`,`remainingUses`],t);let r=B(n,`ciphertext`,t),i=B(n,`keyVersion`,t),a=B(n,`expiresAtMs`,t),o=B(n,`remainingUses`,t);if(typeof r!=`string`||!r.trim()||typeof i!=`string`||!i.trim()||typeof a!=`number`||!Number.isSafeInteger(a)||a<=0||typeof o!=`number`||!Number.isSafeInteger(o)||o<0)throw Error(`${t} is invalid`);return{ciphertext:r,keyVersion:i,expiresAtMs:a,remainingUses:o}}function ur(e){let t=`Wallet registration NEAR provisioning`,n=z({responseName:t,field:`body`,value:e});if(B(n,`ok`,t)!==!0){H(n,[`ok`,`code`,`message`,`nearProvisioning`],t);let e=B(n,`code`,t),r=B(n,`message`,t);if(typeof e!=`string`||typeof r!=`string`)throw Error(`${t} failure is invalid`);let i=V(n,`nearProvisioning`,t);if(i!==void 0){let n=z({responseName:t,field:`nearProvisioning`,value:i});if(H(n,[`status`],`${t} nearProvisioning`),B(n,`status`,`${t} nearProvisioning`)!==`near_failed_retryable`)throw Error(`${t} failure status is invalid`);return{ok:!1,code:e,message:r,nearProvisioning:{status:`near_failed_retryable`}}}return{ok:!1,code:e,message:r}}H(n,[`ok`,`walletId`,`authority`,`foundingAuthority`,`foundingAuthMethod`,`registrationDiagnostics`,`rpId`,`authMethod`,`walletCustody`,`custodyKeyManifestDigestB64u`,`kind`,`accountProvisioning`,`resolvedAccount`,`ed25519`,`authorityScope`,`nearProvisioning`,`registrationEstablishedSession`,`sessionSeal`],t);let r=z({responseName:t,field:`nearProvisioning`,value:B(n,`nearProvisioning`,t)});if(H(r,[`status`],`${t} nearProvisioning`),B(r,`status`,`${t} nearProvisioning`)!==`near_ready`)throw Error(`${t} success status is invalid`);let i=Ft({value:ar(n),expectedKind:`near_ed25519`});if(!i.ok||i.kind!==`near_ed25519`)throw Error(`${t} did not return a finalized Ed25519 wallet`);let a=V(n,`sessionSeal`,t),o=rr(B(n,`registrationEstablishedSession`,t),i.walletId);if(bn(i)){if(a!==void 0)throw Error(`${t} returned a session seal for an Email OTP authority`);return{...i,nearProvisioning:{status:`near_ready`},registrationEstablishedSession:o}}let s={...i,nearProvisioning:{status:`near_ready`},registrationEstablishedSession:o};return a===void 0?s:{...s,sessionSeal:lr(a)}}async function dr(e){let t={registrationCeremonyId:e.registrationCeremonyId,signedSetup:e.signedSetup,idempotencyKey:e.idempotencyKey,ed25519:e.ed25519};return e.auth.kind===`email_otp`&&(t.emailOtpEnrollment=e.auth.enrollment),e.walletCustodyCommit&&(t.walletCustodyCommit=e.walletCustodyCommit),e.sessionSeal&&(t.sessionSeal=e.sessionSeal),ur(await I({relayerUrl:e.relayerUrl,path:Rt,headers:e.headers,body:t,...e.onServerTiming?{onServerTiming:e.onServerTiming}:{}}))}function fr(e){switch(e.kind){case`webauthn_assertion`:return{kind:`webauthn_assertion`,rpId:e.rpId,credential:e.credential,expectedChallengeDigestB64u:e.expectedChallengeDigestB64u}}}function pr(e){switch(e.kind){case`webauthn_assertion`:return{kind:`webauthn_assertion`,rpId:e.rpId,credential:e.credential,expectedChallengeDigestB64u:e.expectedChallengeDigestB64u};case`wallet_session`:return{kind:`wallet_session`};case`email_otp`:return{kind:`email_otp`,challengeId:e.challengeId,otpCode:e.otpCode,expectedChallengeDigestB64u:e.expectedChallengeDigestB64u}}}function mr(e){switch(e.kind){case`passkey`:return{};case`email_otp`:return{emailOtpRegistrationProof:e.emailOtpRegistrationProof}}}async function hr(e){let t=String(e.walletId||``).trim();if(!t)throw Error(`walletId is required for add-signer start`);return Vn({value:await I({relayerUrl:e.relayerUrl,path:`/wallets/${encodeURIComponent(t)}/signers/start`,body:{addSignerIntentGrant:e.addSignerIntentGrant,addSignerIntentDigestB64u:e.addSignerIntentDigestB64u,intent:e.intent,auth:fr(e.auth)}}),expectedIntent:e.intent})}function gr(e){let t=`Email OTP enrollment code`,n=z({responseName:t,field:`body`,value:e});if(H(n,[`ok`,`challengeId`,`expiresAtMs`,`emailHint`],t),B(n,`ok`,t)!==!0)throw Error(`${t} response is not successful`);let r=B(n,`challengeId`,t);if(typeof r!=`string`||!r.trim())throw Error(`${t} response missing challengeId`);let i=B(n,`expiresAtMs`,t);if(typeof i!=`number`||!Number.isSafeInteger(i)||i<1)throw Error(`${t} response has invalid expiresAtMs`);let a=B(n,`emailHint`,t);if(typeof a!=`string`)throw Error(`${t} response has invalid emailHint`);return{challengeId:r.trim(),expiresAtMs:i,emailHint:a}}async function _r(e){let t=String(e.walletId||``).trim();if(!t)throw Error(`walletId is required for the Email OTP enrollment code`);return gr(await I({relayerUrl:e.relayerUrl,path:`/wallets/${encodeURIComponent(t)}/auth-methods/email-otp/challenge`,body:{addAuthMethodIntentGrant:e.addAuthMethodIntentGrant,addAuthMethodIntentDigestB64u:e.addAuthMethodIntentDigestB64u}}))}async function vr(e){let t=String(e.walletId||``).trim();if(!t)throw Error(`walletId is required for add-auth-method start`);return wn({value:await I({relayerUrl:e.relayerUrl,path:`/wallets/${encodeURIComponent(t)}/auth-methods/start`,body:{addAuthMethodIntentGrant:e.addAuthMethodIntentGrant,addAuthMethodIntentDigestB64u:e.addAuthMethodIntentDigestB64u,intent:e.intent,auth:pr(e.auth),...mr(e.authority)},...e.auth.kind===`wallet_session`?{headers:{authorization:`Bearer ${e.auth.walletSessionToken}`}}:{}}),expectedIntent:e.intent})}async function yr(e){let t=String(e.walletId||``).trim();if(!t)throw Error(`walletId is required for add-signer ECDSA respond`);return vn(await I({relayerUrl:e.relayerUrl,path:`/wallets/${encodeURIComponent(t)}/signers/derivation/respond`,body:{addSignerCeremonyId:e.addSignerCeremonyId,ecdsa:e.ecdsa}}))}async function br(e){let t=String(e.walletId||``).trim();if(!t)throw Error(`walletId is required for add-signer ECDSA activation`);return yn(await I({relayerUrl:e.relayerUrl,path:`/wallets/${encodeURIComponent(t)}/signers/derivation/activate`,body:{addSignerCeremonyId:e.addSignerCeremonyId,ecdsa:{kind:`router_ab_ecdsa_registration_activation_v1`,activationCorrelationId:e.activationCorrelationId,publicFacts:e.publicFacts,expectedActivationRequestDigest:e.expectedActivationRequestDigest}}}))}function xr(e){switch(e.kind){case`near_ed25519`:return{addSignerCeremonyId:e.addSignerCeremonyId,idempotencyKey:e.idempotencyKey,kind:e.kind,ed25519:e.ed25519,custodyKeySet:e.custodyKeySet};case`evm_family_ecdsa`:return{addSignerCeremonyId:e.addSignerCeremonyId,idempotencyKey:e.idempotencyKey,kind:e.kind,ecdsa:e.ecdsa,custodyKeySet:e.custodyKeySet}}}async function Sr(e){let t=String(e.walletId||``).trim();if(!t)throw Error(`walletId is required for add-signer finalize`);return Hn({value:await I({relayerUrl:e.relayerUrl,path:`/wallets/${encodeURIComponent(t)}/signers/finalize`,body:xr(e)}),expectedKind:e.kind})}async function Cr(e){let t=String(e.walletId||``).trim();if(!t)throw Error(`walletId is required for add-auth-method finalize`);let n=e.custodyEnvelope===void 0?{addAuthMethodCeremonyId:e.addAuthMethodCeremonyId}:e.webauthnRegistration===void 0?{addAuthMethodCeremonyId:e.addAuthMethodCeremonyId,custodyEnvelope:S(e.custodyEnvelope),emailOtpTarget:e.emailOtpTarget}:{addAuthMethodCeremonyId:e.addAuthMethodCeremonyId,webauthnRegistration:e.webauthnRegistration,custodyEnvelope:S(e.custodyEnvelope)},r={relayerUrl:e.relayerUrl,path:`/wallets/${encodeURIComponent(t)}/auth-methods/finalize`,body:n},i;try{i=await I(r)}catch(e){if(!(e instanceof TypeError))throw e;i=await I(r)}return Cn(i)}async function wr(e){let t=String(e.walletId||``).trim(),n=String(e.rpId||``).trim(),r=e.operationCredential;if(!t)throw Error(`walletId is required for ECDSA key-facts inventory`);if(!n)throw Error(`rpId is required for ECDSA key-facts inventory`);return Kn({value:await I({relayerUrl:e.relayerUrl,path:`/wallets/${encodeURIComponent(t)}/signers/ecdsa/key-facts/inventory`,headers:h(r),body:{rpId:n,keyTargets:e.keyTargets,auth:{kind:r.kind,walletSessionId:r.walletSessionId}}}),walletId:e.walletId,rpId:n})}async function Tr(e){let t=String(e.walletId||``).trim(),n=String(e.rpId||``).trim(),r=String(e.serverNonceB64u||``).trim(),i=String(e.expectedChallengeDigestB64u||``).trim();if(!t)throw Error(`walletId is required for ECDSA key-facts inventory`);if(!n)throw Error(`rpId is required for ECDSA key-facts inventory`);if(!r||!i)throw Error(`WebAuthn ECDSA key-facts inventory requires challenge binding`);return Kn({value:await I({relayerUrl:e.relayerUrl,path:`/wallets/${encodeURIComponent(t)}/signers/ecdsa/key-facts/inventory`,body:{rpId:n,keyTargets:e.keyTargets,auth:{kind:`webauthn_assertion`,credential:e.credential,serverNonceB64u:r,expectedChallengeDigestB64u:i,...e.runtimePolicyScope?{runtimePolicyScope:e.runtimePolicyScope}:{}}}}),walletId:e.walletId,rpId:n})}async function Er(e){return he(`seams:wallet-custody:challenge:v1|${f({walletId:e.walletId,operation:e.operation,payload:e.payload,requestOrigin:e.requestOrigin})}`)}function X(e,t){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let n=Object.keys(e);return n.length===t.length&&n.every(e=>t.includes(e))}const Dr=[`kind`,`walletId`,`authorityId`,`walletAuthMethodId`,`mintId`,`authorizationId`,`walletSessionId`,`quotaId`],Or=[`ok`,`code`,`message`,`next`,`committed`],kr=[`ok`,`code`,`message`,`next`,`kind`,`walletId`,`authorityId`,`walletAuthMethodId`,`mintId`,`authorizationId`,`walletSessionId`,`quotaId`],Ar=[...kr,`unlocked`,`unlockBackend`];function jr(t){if(!u(t)||!X(t,Dr)||t.kind!==`already_committed_wallet_session_v1`)return null;let r=n(t.walletId),a=e(t.authorityId),o=i(t.walletAuthMethodId),s=pe(t.mintId),c=me(t.authorizationId),l=_(t.walletSessionId),d=g(t.quotaId);return!r.ok||!a.ok||!o.ok||!s.ok||!c.ok||!l.ok||!d.ok?null:{kind:`already_committed_wallet_session_v1`,walletId:r.value,authorityId:a.value,walletAuthMethodId:o.value,mintId:s.value,authorizationId:c.value,walletSessionId:l.value,quotaId:d.value}}function Mr(e){return e.ok!==!1||e.code!==`already_committed`||typeof e.message!=`string`||e.next!==`unlock_exact_method`?null:{ok:!1,code:`already_committed`,message:e.message,next:`unlock_exact_method`}}function Nr(e){return!X(e,kr)&&!X(e,Ar)||X(e,Ar)&&(e.unlocked!==!1||e.unlockBackend!==`passkey`&&e.unlockBackend!==`email_otp`)||e.kind!==`already_committed`?null:jr({kind:`already_committed_wallet_session_v1`,walletId:e.walletId,authorityId:e.authorityId,walletAuthMethodId:e.walletAuthMethodId,mintId:e.mintId,authorizationId:e.authorizationId,walletSessionId:e.walletSessionId,quotaId:e.quotaId})}function Pr(e,t){return{ok:!1,code:`already_committed`,message:e.message,next:`unlock_exact_method`,committed:t}}function Fr(e){if(!u(e))return null;let t=Mr(e);if(!t||!X(e,Or))return null;let n=jr(e.committed);return n?Pr(t,n):null}function Ir(e){if(!u(e))return null;let t=Mr(e);if(!t)return null;let n=Nr(e);return n?Pr(t,n):null}var Z=class{retainProof(){return!0}constructor(){this.retainProof()}},Lr=class extends Z{constructor(e){super(),this.kind=`use_live_runtime`,this.capability=e.materialActivation.capability,this.materialOwner=e.materialActivation.materialOwner,this.authority=e.authority,this.runtime=e.runtime,this.materialActivation=e.materialActivation}},Rr=class extends Z{constructor(e){super(),this.kind=`rehydrate_material_activation`,this.capability=e.materialActivation.capability,this.materialOwner=e.materialActivation.materialOwner,this.authority=e.authority,this.materialActivation=e.materialActivation,this.sealedMaterial=e.sealedMaterial}},zr=class extends Z{constructor(e){super(),this.kind=`reauthorize_public_anchor`,this.capability=e.publicReauthAnchor.capability,this.materialOwner=e.publicReauthAnchor.materialOwner,this.authority=e.publicReauthAnchor.authority,this.retirement=e.retirement,this.publicReauthAnchor=e.publicReauthAnchor}},Br=class extends Z{constructor(...e){super(...e),this.kind=`blocked`}},Vr=class extends Br{constructor(...e){super(...e),this.capability=null,this.reason=`missing_capability`}},Hr=class extends Br{constructor(e){super(),this.capability=e.capability,this.reason=e.reason}};function Ur(e){return new Lr(e)}function Wr(e){return new Rr(e)}function Gr(e){return new zr(e)}function Q(e){return e.reason===`missing_capability`?new Vr:new Hr(e)}function Kr(e){if(!e.ok)throw Error(e.error.message);return e.value}function qr(e){return e.materialActivation}function Jr(e){return Kr(a(`near-ed25519-yao:${e.activationId}`))}function $(e,t){let n=e.sealed.kind===`available`?e.sealed.materialActivation.capability:e.runtime.kind===`live`?e.runtime.materialActivation.capability:e.publicLocator.kind===`available`?e.publicLocator.materialActivation.capability:null;return Q(n?{capability:n,reason:t}:{capability:null,reason:`missing_capability`})}function Yr(e){switch(e.publicLocator.kind){case`missing`:return Q({capability:null,reason:`missing_capability`});case`retired`:return Gr({retirement:e.publicLocator.retirement,publicReauthAnchor:e.publicLocator.publicReauthAnchor});case`conflict`:return $(e,`exact_record_conflict`);case`corrupt`:return $(e,`corrupt`);case`unavailable`:return Q({capability:e.publicLocator.capability,reason:`persistence_unavailable`});case`available`:break;default:e.publicLocator}let t=e.publicLocator.materialActivation;if(String(t.materialOwner)!==e.publicLocator.walletId)return $(e,`binding_mismatch`);switch(e.runtime.kind){case`live`:return c(t,e.runtime.materialActivation)?Ur({authority:e.publicLocator.authority,runtime:e.runtime.runtime,materialActivation:t}):$(e,`binding_mismatch`);case`absent`:break;default:e.runtime}switch(e.sealed.kind){case`missing`:return $(e,`missing_material`);case`corrupt`:return $(e,`corrupt`);case`available`:break;default:e.sealed}let n=e.sealed;if(String(n.authority.walletId)!==e.publicLocator.walletId||String(n.authority.authorityDigest)!==String(e.publicLocator.authority.authorityDigest)||String(n.materialActivation.materialOwner)!==e.publicLocator.walletId||!c(n.materialActivation,e.publicLocator.materialActivation))return $(e,`binding_mismatch`);switch(e.unlockSource.kind){case`unavailable`:return $(e,`missing_material`);case`available`:return String(e.unlockSource.authority.walletId)!==String(n.authority.walletId)||String(e.unlockSource.authority.authorityDigest)!==String(n.authority.authorityDigest)?$(e,`binding_mismatch`):Wr({authority:n.authority,materialActivation:n.materialActivation,sealedMaterial:n.sealedMaterial});default:e.unlockSource}throw Error(`Unsupported Near Ed25519 unlock-source observation`)}export{hr as A,Bt as C,Xn as D,nr as E,qn as O,Gn as S,yr as T,Tr as _,Wr as a,en as b,Ir as c,br as d,cr as f,wr as g,Jn as h,Q as i,yt as j,vr as k,X as l,Zn as m,Jr as n,Ur as o,dr as p,Yr as r,Fr as s,qr as t,Er as u,Cr as v,_r as w,bn as x,Sr as y};
|