@seams/wallet-server 0.5.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.
Files changed (1075) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +8 -0
  3. package/artifact-manifest.json +464 -0
  4. package/cloudflare-router-ab/build/deriver-a/index.js +2 -0
  5. package/cloudflare-router-ab/build/deriver-a/index_bg.wasm +0 -0
  6. package/cloudflare-router-ab/build/deriver-a/package.json +16 -0
  7. package/cloudflare-router-ab/build/deriver-a/worker/shim.mjs +4 -0
  8. package/cloudflare-router-ab/build/deriver-b/index.js +2 -0
  9. package/cloudflare-router-ab/build/deriver-b/index_bg.wasm +0 -0
  10. package/cloudflare-router-ab/build/deriver-b/package.json +16 -0
  11. package/cloudflare-router-ab/build/deriver-b/worker/shim.mjs +4 -0
  12. package/cloudflare-router-ab/build/local-tools/darwin-arm64/router_ab_local_init +0 -0
  13. package/cloudflare-router-ab/build/router/index.js +2 -0
  14. package/cloudflare-router-ab/build/router/index_bg.wasm +0 -0
  15. package/cloudflare-router-ab/build/router/package.json +16 -0
  16. package/cloudflare-router-ab/build/router/worker/shim.mjs +4 -0
  17. package/cloudflare-router-ab/build/signing-worker/index.js +2 -0
  18. package/cloudflare-router-ab/build/signing-worker/index_bg.wasm +0 -0
  19. package/cloudflare-router-ab/build/signing-worker/package.json +16 -0
  20. package/cloudflare-router-ab/build/signing-worker/worker/shim.mjs +4 -0
  21. package/cloudflare-router-ab/build/tenant-root-control-plane/index.js +2 -0
  22. package/cloudflare-router-ab/build/tenant-root-control-plane/index_bg.wasm +0 -0
  23. package/cloudflare-router-ab/build/tenant-root-control-plane/package.json +16 -0
  24. package/cloudflare-router-ab/build/tenant-root-control-plane/worker/shim.mjs +4 -0
  25. package/cloudflare-router-ab/env/tenant-root-control-plane.local.example +6 -0
  26. package/cloudflare-router-ab/migrations/deriver-a/0001_role_private_storage.sql +14 -0
  27. package/cloudflare-router-ab/migrations/deriver-a/0002_tenant_root_role_shares.sql +32 -0
  28. package/cloudflare-router-ab/migrations/deriver-a/0003_tenant_root_command_replays.sql +76 -0
  29. package/cloudflare-router-ab/migrations/deriver-a/0004_tenant_root_creation_admission.sql +7 -0
  30. package/cloudflare-router-ab/migrations/deriver-a/0005_tenant_root_refresh_state.sql +15 -0
  31. package/cloudflare-router-ab/migrations/deriver-a/0006_tenant_root_restore_import_keys.sql +119 -0
  32. package/cloudflare-router-ab/migrations/deriver-a/0007_tenant_root_restore_refresh_attempts.sql +103 -0
  33. package/cloudflare-router-ab/migrations/deriver-a/0008_tenant_root_restore_promotion.sql +40 -0
  34. package/cloudflare-router-ab/migrations/deriver-a/0009_tenant_root_restore_preactivation_cleanup.sql +8 -0
  35. package/cloudflare-router-ab/migrations/deriver-a/0010_tenant_root_recovery_attempts.sql +26 -0
  36. package/cloudflare-router-ab/migrations/deriver-a/0011_tenant_root_source_retirement.sql +100 -0
  37. package/cloudflare-router-ab/migrations/deriver-b/0001_role_private_storage.sql +14 -0
  38. package/cloudflare-router-ab/migrations/deriver-b/0002_tenant_root_role_shares.sql +32 -0
  39. package/cloudflare-router-ab/migrations/deriver-b/0003_tenant_root_command_replays.sql +76 -0
  40. package/cloudflare-router-ab/migrations/deriver-b/0004_tenant_root_creation_admission.sql +7 -0
  41. package/cloudflare-router-ab/migrations/deriver-b/0005_tenant_root_refresh_state.sql +15 -0
  42. package/cloudflare-router-ab/migrations/deriver-b/0006_tenant_root_restore_import_keys.sql +119 -0
  43. package/cloudflare-router-ab/migrations/deriver-b/0007_tenant_root_restore_refresh_attempts.sql +103 -0
  44. package/cloudflare-router-ab/migrations/deriver-b/0008_tenant_root_restore_promotion.sql +40 -0
  45. package/cloudflare-router-ab/migrations/deriver-b/0009_tenant_root_restore_preactivation_cleanup.sql +8 -0
  46. package/cloudflare-router-ab/migrations/deriver-b/0010_tenant_root_recovery_attempts.sql +26 -0
  47. package/cloudflare-router-ab/migrations/deriver-b/0011_tenant_root_source_retirement.sql +100 -0
  48. package/cloudflare-router-ab/migrations/signing-worker/0001_private_storage.sql +67 -0
  49. package/cloudflare-router-ab/migrations/signing-worker/0002_activation_revocation_fences.sql +3 -0
  50. package/cloudflare-router-ab/scripts/bootstrap-local-tenant-root.mjs +182 -0
  51. package/cloudflare-router-ab/scripts/initialize-local-wallet.mjs +17 -0
  52. package/cloudflare-router-ab/scripts/local-key-material.mjs +29 -0
  53. package/cloudflare-router-ab/scripts/prepare-local-runtime-config.mjs +1110 -0
  54. package/cloudflare-router-ab/scripts/start-local-role-workers.mjs +333 -0
  55. package/cloudflare-router-ab/scripts/start-local-wallet-system.mjs +427 -0
  56. package/cloudflare-router-ab/wrangler.deriver-a.toml +123 -0
  57. package/cloudflare-router-ab/wrangler.deriver-b.toml +123 -0
  58. package/cloudflare-router-ab/wrangler.router.toml +126 -0
  59. package/cloudflare-router-ab/wrangler.signing-worker.toml +86 -0
  60. package/cloudflare-router-ab/wrangler.tenant-root-control-plane.toml +56 -0
  61. package/dist/esm/authorization/capabilityPolicy.js +96 -0
  62. package/dist/esm/authorization/domain.js +434 -0
  63. package/dist/esm/authorization/factorEvidence.js +405 -0
  64. package/dist/esm/authorization/service.js +319 -0
  65. package/dist/esm/authorization/vaultProxyUse.js +295 -0
  66. package/dist/esm/cloud-host.js +126 -0
  67. package/dist/esm/core/AuthService.js +2 -0
  68. package/dist/esm/core/EmailOtpRecords.js +361 -0
  69. package/dist/esm/core/EmailOtpStores.js +1460 -0
  70. package/dist/esm/core/IdentityStore.js +617 -0
  71. package/dist/esm/core/NearPublicKeyStore.js +242 -0
  72. package/dist/esm/core/RegistrationCeremonyStore.js +2101 -0
  73. package/dist/esm/core/SessionService.js +255 -0
  74. package/dist/esm/core/ThresholdService/config.js +111 -0
  75. package/dist/esm/core/ThresholdService/ecdsaClientRootProof.js +27 -0
  76. package/dist/esm/core/ThresholdService/evmCryptoWasm.js +167 -0
  77. package/dist/esm/core/ThresholdService/index.js +4 -0
  78. package/dist/esm/core/ThresholdService/kv.js +368 -0
  79. package/dist/esm/core/ThresholdService/routerAb/ecdsaDerivationPoolFillHandlers.js +360 -0
  80. package/dist/esm/core/ThresholdService/routerAb/ecdsaDerivationPoolFillLiveSession.js +282 -0
  81. package/dist/esm/core/ThresholdService/routerAb/ecdsaDerivationPresignBridge.js +272 -0
  82. package/dist/esm/core/ThresholdService/routerAb/internalServiceHttp.js +57 -0
  83. package/dist/esm/core/ThresholdService/routerAbEcdsaSigningWorkerWasm.js +115 -0
  84. package/dist/esm/core/ThresholdService/routerAbNormalSigningPolicy.js +31 -0
  85. package/dist/esm/core/ThresholdService/secureRandomId.js +9 -0
  86. package/dist/esm/core/ThresholdService/stores/CloudflareDurableObjectStore.js +603 -0
  87. package/dist/esm/core/ThresholdService/stores/EcdsaSigningStore.js +422 -0
  88. package/dist/esm/core/ThresholdService/stores/KeyStore.js +140 -0
  89. package/dist/esm/core/ThresholdService/stores/SessionStore.js +437 -0
  90. package/dist/esm/core/ThresholdService/stores/StoreConfig.js +13 -0
  91. package/dist/esm/core/ThresholdService/stores/WalletSessionStore.js +722 -0
  92. package/dist/esm/core/ThresholdService/validation.js +718 -0
  93. package/dist/esm/core/WalletAuthMethodStore.js +180 -0
  94. package/dist/esm/core/WalletStore.js +495 -0
  95. package/dist/esm/core/WebAuthnAuthenticatorStore.js +485 -0
  96. package/dist/esm/core/WebAuthnCredentialBindingStore.js +594 -0
  97. package/dist/esm/core/WebAuthnLoginChallengeStore.js +432 -0
  98. package/dist/esm/core/WebAuthnSyncChallengeStore.js +434 -0
  99. package/dist/esm/core/authService/AuthService.js +611 -0
  100. package/dist/esm/core/authService/bytes.js +22 -0
  101. package/dist/esm/core/authService/configValues.js +15 -0
  102. package/dist/esm/core/authService/emailOtpChallengeOperations.js +126 -0
  103. package/dist/esm/core/authService/emailOtpChallengeProof.js +214 -0
  104. package/dist/esm/core/authService/emailOtpChallengeVerification.js +335 -0
  105. package/dist/esm/core/authService/emailOtpChallenges.js +260 -0
  106. package/dist/esm/core/authService/emailOtpConfig.js +231 -0
  107. package/dist/esm/core/authService/emailOtpDelivery.js +169 -0
  108. package/dist/esm/core/authService/emailOtpEnrollment.js +141 -0
  109. package/dist/esm/core/authService/emailOtpGrant.js +74 -0
  110. package/dist/esm/core/authService/emailOtpRegistrationEnrollment.js +322 -0
  111. package/dist/esm/core/authService/emailOtpSeal.js +78 -0
  112. package/dist/esm/core/authService/emailOtpUnlock.js +264 -0
  113. package/dist/esm/core/authService/githubOAuth.js +140 -0
  114. package/dist/esm/core/authService/googleEmailOtpErrors.js +6 -0
  115. package/dist/esm/core/authService/googleEmailOtpOperations.js +141 -0
  116. package/dist/esm/core/authService/googleEmailOtpRegistration.js +674 -0
  117. package/dist/esm/core/authService/identity.js +57 -0
  118. package/dist/esm/core/authService/identityOperations.js +32 -0
  119. package/dist/esm/core/authService/nearAccountOperations.js +229 -0
  120. package/dist/esm/core/authService/nearPrivateKeySigning.js +110 -0
  121. package/dist/esm/core/authService/nearPublicKeyMetadata.js +127 -0
  122. package/dist/esm/core/authService/nearTransactions.js +139 -0
  123. package/dist/esm/core/authService/oidcVerification.js +262 -0
  124. package/dist/esm/core/authService/portableCrypto.js +19 -0
  125. package/dist/esm/core/authService/rateLimits.js +117 -0
  126. package/dist/esm/core/authService/record.js +8 -0
  127. package/dist/esm/core/authService/registrationThresholdHelpers.js +131 -0
  128. package/dist/esm/core/authService/runtime.js +45 -0
  129. package/dist/esm/core/authService/signerWasmUrls.js +20 -0
  130. package/dist/esm/core/authService/storeRegistry.js +113 -0
  131. package/dist/esm/core/authService/thresholdEcdsaKeyInventory.js +146 -0
  132. package/dist/esm/core/authService/thresholdRuntimePolicy.js +19 -0
  133. package/dist/esm/core/authService/thresholdStoreSummary.js +32 -0
  134. package/dist/esm/core/authService/walletRegistrationPlanning.js +49 -0
  135. package/dist/esm/core/authService/wasm.js +78 -0
  136. package/dist/esm/core/authService/webauthn.js +746 -0
  137. package/dist/esm/core/authService/webauthnAuthority.js +17 -0
  138. package/dist/esm/core/authService/webauthnOidcHelpers.js +91 -0
  139. package/dist/esm/core/authService/webauthnWalletBinding.js +157 -0
  140. package/dist/esm/core/config.js +110 -0
  141. package/dist/esm/core/d1IdentityStore.js +340 -0
  142. package/dist/esm/core/d1WalletAuthMethodStore.js +768 -0
  143. package/dist/esm/core/d1WalletStore.js +724 -0
  144. package/dist/esm/core/defaultConfigsServer.js +9 -0
  145. package/dist/esm/core/deviceLinking/index.js +5 -0
  146. package/dist/esm/core/deviceLinking/linkedDeviceEd25519ExportRoot.js +0 -0
  147. package/dist/esm/core/deviceLinking/linkedDeviceEmailOtpGrant.js +211 -0
  148. package/dist/esm/core/deviceLinking/linkedDeviceManagement.js +279 -0
  149. package/dist/esm/core/deviceLinking/linkedDeviceSession.js +1419 -0
  150. package/dist/esm/core/deviceLinking/requestProof.js +172 -0
  151. package/dist/esm/core/errors.js +54 -0
  152. package/dist/esm/core/hostedAccountIds.js +225 -0
  153. package/dist/esm/core/keyMaterialBrands.js +58 -0
  154. package/dist/esm/core/logger.js +39 -0
  155. package/dist/esm/core/nearKeys.js +20 -0
  156. package/dist/esm/core/nearRelayerAccountProvisioning.js +713 -0
  157. package/dist/esm/core/nearSignerWasmRuntime.js +87 -0
  158. package/dist/esm/core/registrationContracts.js +2 -0
  159. package/dist/esm/core/routerAbSigning/RouterAbEcdsaPresignRuntime.js +88 -0
  160. package/dist/esm/core/routerAbSigning/RouterAbNormalSigningRuntime.js +101 -0
  161. package/dist/esm/core/routerAbSigning/createCloudflareDurableObjectRouterAbSigningRuntimes.js +39 -0
  162. package/dist/esm/core/routerAbSigning/createRouterAbSigningRuntimes.js +91 -0
  163. package/dist/esm/core/rpcClients/near/NearClient.js +389 -0
  164. package/dist/esm/core/sessionValidation.js +0 -0
  165. package/dist/esm/core/signingLanes/LaneAggregateRevocationApplicationService.js +86 -0
  166. package/dist/esm/core/signingLanes/LaneEffectJournalStore.js +0 -0
  167. package/dist/esm/core/signingLanes/LaneEnrollmentActivation.js +324 -0
  168. package/dist/esm/core/signingLanes/LaneEnrollmentRevocation.js +173 -0
  169. package/dist/esm/core/signingLanes/LaneLifecycleApplicationService.js +200 -0
  170. package/dist/esm/core/signingLanes/LaneLifecycleStore.js +24 -0
  171. package/dist/esm/core/signingLanes/SigningLaneStore.js +0 -0
  172. package/dist/esm/core/signingLanes/WalletExecutionLaneProjection.js +296 -0
  173. package/dist/esm/core/signingLanes/WalletKeyStore.js +0 -0
  174. package/dist/esm/core/signingLanes/ecdsaServerRetirement.js +78 -0
  175. package/dist/esm/core/signingLanes/ed25519ServerRetirement.js +71 -0
  176. package/dist/esm/core/signingLanes/index.js +8 -0
  177. package/dist/esm/core/signingLanes/signingWorkerLaneMaterialIdentity.js +0 -0
  178. package/dist/esm/core/signingMaterial/ordinaryInactiveSignerMaterialReservation.js +305 -0
  179. package/dist/esm/core/threeRouteRegistrationContracts.js +5 -0
  180. package/dist/esm/core/thresholdEcdsaChainTarget.js +49 -0
  181. package/dist/esm/core/types.js +8 -0
  182. package/dist/esm/core/utils.js +14 -0
  183. package/dist/esm/delegateAction/index.js +136 -0
  184. package/dist/esm/hosted-wallet-gateway-worker.js +18 -0
  185. package/dist/esm/hosted-wallet-gateway.js +701 -0
  186. package/dist/esm/index.js +53 -0
  187. package/dist/esm/local-hosted-wallet-gateway-worker.js +23 -0
  188. package/dist/esm/node_modules/@near-js/types/lib/esm/provider/response.js +17 -0
  189. package/dist/esm/router/auth/authRequestValidation.js +264 -0
  190. package/dist/esm/router/auth/commonRouterUtils.js +305 -0
  191. package/dist/esm/router/auth/routerApiCredentialAuth.js +91 -0
  192. package/dist/esm/router/auth/routerApiKeyAuth.js +63 -0
  193. package/dist/esm/router/auth/walletSessionFailure.js +49 -0
  194. package/dist/esm/router/auth/webAuthnCredentialCodecs.js +107 -0
  195. package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthBoundary.js +84 -0
  196. package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthConfig.js +321 -0
  197. package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthService.js +1581 -0
  198. package/dist/esm/router/cloudflare/d1/authorization/d1AuthorizationStore.js +1820 -0
  199. package/dist/esm/router/cloudflare/d1/authorization/d1VaultProxyStore.js +122 -0
  200. package/dist/esm/router/cloudflare/d1/authorization/walletSessionAuthorityProjection.js +119 -0
  201. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceAuthorityInstallService.js +1831 -0
  202. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEd25519ExportRootStore.js +118 -0
  203. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEmailOtpGrantStore.js +81 -0
  204. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEmailOtpTargetFactor.js +539 -0
  205. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceManagementService.js +92 -0
  206. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceOwnerAuthorizationProvider.js +560 -0
  207. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceRequestProofNonceStore.js +136 -0
  208. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceRouteService.js +95 -0
  209. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionRecords.js +91 -0
  210. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionService.js +15 -0
  211. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionStore.js +732 -0
  212. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSourceContributionPreparationPlanner.js +195 -0
  213. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetAuthenticatorStore.js +100 -0
  214. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetCredentialProvider.js +867 -0
  215. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetPlanner.js +169 -0
  216. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceVerifiedLinkBuilder.js +255 -0
  217. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceVerifiedLinkSourceReader.js +128 -0
  218. package/dist/esm/router/cloudflare/d1/deviceLinking/index.js +15 -0
  219. package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoCapabilityPersistence.js +311 -0
  220. package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoProductRegistrationPartitionedStateStore.js +21 -0
  221. package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoWalletSigner.js +65 -0
  222. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeIssuer.js +216 -0
  223. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeService.js +326 -0
  224. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeStore.js +346 -0
  225. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeVerifier.js +495 -0
  226. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpDeliveryRuntime.js +157 -0
  227. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpEnrollmentStore.js +248 -0
  228. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpGrantStore.js +66 -0
  229. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRateLimitStore.js +76 -0
  230. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRecords.js +539 -0
  231. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRecoveryService.js +404 -0
  232. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRegistrationEnrollmentFinalizer.js +200 -0
  233. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpServerSealRuntime.js +84 -0
  234. package/dist/esm/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpRegistrationAttemptStore.js +217 -0
  235. package/dist/esm/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpRegistrationRecords.js +485 -0
  236. package/dist/esm/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpSessionResolver.js +509 -0
  237. package/dist/esm/router/cloudflare/d1/identity/d1IdentityRecords.js +51 -0
  238. package/dist/esm/router/cloudflare/d1/identity/d1IdentityService.js +135 -0
  239. package/dist/esm/router/cloudflare/d1/near/d1NearPublicKeyStore.js +62 -0
  240. package/dist/esm/router/cloudflare/d1/oidc/d1OidcBoundary.js +272 -0
  241. package/dist/esm/router/cloudflare/d1/oidc/d1OidcVerificationService.js +132 -0
  242. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1PasskeyCustodyEnvelopeStore.js +628 -0
  243. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1PasskeyCustodyRouteService.js +871 -0
  244. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletCustodyCommitStore.js +823 -0
  245. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpAttemptStore.js +38 -0
  246. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpRecords.js +304 -0
  247. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpService.js +793 -0
  248. package/dist/esm/router/cloudflare/d1/registration/d1EvmFamilyEcdsaRegistrationBranch.js +120 -0
  249. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyRecordStore.js +317 -0
  250. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyRecords.js +2084 -0
  251. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyStore.js +309 -0
  252. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationIntentService.js +120 -0
  253. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationCommitStore.js +263 -0
  254. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationService.js +3887 -0
  255. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationSetup.js +182 -0
  256. package/dist/esm/router/cloudflare/d1/registration/walletRegistrationEstablishedSessionIssuer.js +399 -0
  257. package/dist/esm/router/cloudflare/d1/registration/walletRegistrationSessionCommitReceipt.js +486 -0
  258. package/dist/esm/router/cloudflare/d1/signingAdmission/d1RouterAbNormalSigningAdmissionStore.js +146 -0
  259. package/dist/esm/router/cloudflare/d1/signingLanes/d1EcdsaLanePrivateBindingResolver.js +10 -0
  260. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneAggregateRevocationApplicationService.js +22 -0
  261. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneEffectJournalStore.js +167 -0
  262. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneEnrollmentGateway.js +38 -0
  263. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneLifecycleApplicationService.js +20 -0
  264. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneLifecycleStore.js +1459 -0
  265. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneLockStore.js +114 -0
  266. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneProtocolCommitter.js +16 -0
  267. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneRecords.js +170 -0
  268. package/dist/esm/router/cloudflare/d1/signingLanes/index.js +10 -0
  269. package/dist/esm/router/cloudflare/d1/versionedJson/d1VersionedJsonRecordStore.js +412 -0
  270. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAddSignerService.js +1396 -0
  271. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthMethodBoundary.js +285 -0
  272. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthMethodService.js +2018 -0
  273. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorityStore.js +792 -0
  274. package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnAuthService.js +635 -0
  275. package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnRecords.js +538 -0
  276. package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnStore.js +264 -0
  277. package/dist/esm/router/cloudflare/durableObjects/thresholdStore.js +514 -0
  278. package/dist/esm/router/cloudflare/durableObjects/versionedJsonRecordStore.js +192 -0
  279. package/dist/esm/router/cloudflare/runtime/cloudflare.types.js +0 -0
  280. package/dist/esm/router/cloudflare/runtime/cloudflareSignerWasm.js +8 -0
  281. package/dist/esm/router/cloudflare/runtime/createCloudflareRouter.js +19 -0
  282. package/dist/esm/router/cloudflare/runtime/createSelfHostedCloudflareSigningWorker.js +94 -0
  283. package/dist/esm/router/cloudflare/runtime/ed25519SessionAdapter.js +106 -0
  284. package/dist/esm/router/cloudflare/runtime/environment.js +25 -0
  285. package/dist/esm/router/cloudflare/runtime/routerAbPrewarm.js +34 -0
  286. package/dist/esm/router/cloudflare/runtime/routerAbServiceBindings.js +33 -0
  287. package/dist/esm/router/cloudflare/runtime/sessionAdapterRuntime.js +104 -0
  288. package/dist/esm/router/cloudflare/runtime/staticWalletConsoleBinding.js +168 -0
  289. package/dist/esm/router/cloudflare/runtime/tenantRootCreationGrant.js +147 -0
  290. package/dist/esm/router/cloudflare/runtime/walletConsoleOps.js +143 -0
  291. package/dist/esm/router/cloudflare/runtime/walletConsoleOpsClient.js +227 -0
  292. package/dist/esm/router/cloudflare/runtime/walletConsoleTenantRootLineage.js +30 -0
  293. package/dist/esm/router/cloudflare/runtime/walletControlOps.js +107 -0
  294. package/dist/esm/router/cloudflare/runtime/walletGateway.js +149 -0
  295. package/dist/esm/router/cloudflare/runtime/walletRuntimeOps.js +322 -0
  296. package/dist/esm/router/cloudflare/runtime/walletRuntimeOpsHandler.js +48 -0
  297. package/dist/esm/router/cloudflare/signingLanes/cloudflareLaneCurveExecution.js +597 -0
  298. package/dist/esm/router/cloudflare/signingLanes/cloudflareLaneProtocolCommitter.js +272 -0
  299. package/dist/esm/router/cloudflare/signingLanes/cloudflareOrdinaryInactiveSignerMaterialReservation.js +477 -0
  300. package/dist/esm/router/cloudflare/signingLanes/index.js +4 -0
  301. package/dist/esm/router/cloudflare/signingLanes/linkedDeviceEd25519CeremonyBinding.js +32 -0
  302. package/dist/esm/router/cloudflare-adaptor.js +45 -0
  303. package/dist/esm/router/cloudflare.js +42794 -0
  304. package/dist/esm/router/domains/ecdsa/routerAbEcdsaStrictRegistration.js +738 -0
  305. package/dist/esm/router/domains/ecdsa/thresholdEcdsaRequestValidation.js +134 -0
  306. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.js +368 -0
  307. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitionedStateStore.js +624 -0
  308. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitioning.js +143 -0
  309. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPersistence.js +270 -0
  310. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRunner.js +31 -0
  311. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRuntime.js +162 -0
  312. package/dist/esm/router/domains/ed25519Yao/export/routerAbEd25519YaoExport.js +1366 -0
  313. package/dist/esm/router/domains/ed25519Yao/export/routerAbEd25519YaoExportRequestScopedCloudflare.js +465 -0
  314. package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecovery.js +1609 -0
  315. package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryRequestScopedCloudflare.js +540 -0
  316. package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryWalletSessionAuthorization.js +394 -0
  317. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoHttpRegistrationBackend.js +572 -0
  318. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistration.js +555 -0
  319. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationExecutionRecord.js +268 -0
  320. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationIntentAuthorization.js +329 -0
  321. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationRequestScopedCloudflare.js +423 -0
  322. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.js +432 -0
  323. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationTwoPhaseRunner.js +58 -0
  324. package/dist/esm/router/domains/ed25519Yao/routerAbEd25519YaoGatewayEnvelope.js +0 -0
  325. package/dist/esm/router/domains/ed25519Yao/session/routerAbEd25519YaoWalletSession.js +0 -0
  326. package/dist/esm/router/domains/ed25519Yao/session/thresholdEd25519RequestValidation.js +275 -0
  327. package/dist/esm/router/domains/emailOtp/emailOtpExportPolicy.js +70 -0
  328. package/dist/esm/router/domains/emailOtp/emailOtpRequestValidation.js +34 -0
  329. package/dist/esm/router/domains/emailOtp/emailOtpRouteHandlers.js +218 -0
  330. package/dist/esm/router/domains/emailOtp/emailOtpSessionRouteHelpers.js +210 -0
  331. package/dist/esm/router/domains/passkeyCustody/envelopeRevocationAdmission.js +26 -0
  332. package/dist/esm/router/domains/passkeyCustody/passkeyCustodyEnvelopeRetrieval.js +107 -0
  333. package/dist/esm/router/domains/passkeyCustody/passkeyCustodyEnvelopeRetrievalRoute.js +45 -0
  334. package/dist/esm/router/domains/passkeyCustody/registrationCustodyOutcome.js +47 -0
  335. package/dist/esm/router/domains/passkeyCustody/verifiedCustodyFactor.js +46 -0
  336. package/dist/esm/router/domains/passkeyCustody/walletCustodyRegistrationAdmission.js +32 -0
  337. package/dist/esm/router/domains/passkeyCustody/walletCustodyRegistrationCommit.js +170 -0
  338. package/dist/esm/router/domains/passkeyCustody/walletRecoveryAttempt.js +64 -0
  339. package/dist/esm/router/domains/passkeyCustody/walletRecoveryFinalization.js +652 -0
  340. package/dist/esm/router/domains/passkeyCustody/walletRecoveryKeyManifest.js +396 -0
  341. package/dist/esm/router/domains/passkeyCustody/walletRecoveryRotation.js +87 -0
  342. package/dist/esm/router/domains/signingOperations/ed25519AuthorizedOperationReceipt.js +89 -0
  343. package/dist/esm/router/domains/signingOperations/routerAbNormalSigningAdmissionCore.js +106 -0
  344. package/dist/esm/router/domains/signingOperations/routerAbPrivateSigningWorker.js +2669 -0
  345. package/dist/esm/router/domains/signingOperations/walletExecutionAdmission.js +228 -0
  346. package/dist/esm/router/domains/syncAccount/syncAccountRequestValidation.js +78 -0
  347. package/dist/esm/router/domains/tenantRoot/tenantRootCustodyLineage.js +0 -0
  348. package/dist/esm/router/domains/tenantRoot/tenantRootEcdsaWalletSessionComposition.js +55 -0
  349. package/dist/esm/router/domains/tenantRoot/tenantRootEd25519WalletSessionComposition.js +56 -0
  350. package/dist/esm/router/domains/tenantRoot/tenantRootIdentityResolution.js +111 -0
  351. package/dist/esm/router/domains/walletRegistration/walletRegistrationInputs.js +0 -0
  352. package/dist/esm/router/domains/walletRegistration/walletRegistrationRoutes.js +2199 -0
  353. package/dist/esm/router/domains/walletRegistration/walletRegistrationSetupPayload.js +155 -0
  354. package/dist/esm/router/domains/walletUnlock/walletUnlockRequestedCapabilitiesValidation.js +84 -0
  355. package/dist/esm/router/domains/walletUnlock/walletUnlockRouteHandlers.js +1142 -0
  356. package/dist/esm/router/express-adaptor.js +84 -0
  357. package/dist/esm/router/express.js +26616 -0
  358. package/dist/esm/router/framework/apiCredentialPorts.js +11 -0
  359. package/dist/esm/router/framework/applyRouteMetering.js +26 -0
  360. package/dist/esm/router/framework/authServicePort.js +30 -0
  361. package/dist/esm/router/framework/enforceRoutePolicy.js +92 -0
  362. package/dist/esm/router/framework/http.js +87 -0
  363. package/dist/esm/router/framework/logger.js +7 -0
  364. package/dist/esm/router/framework/modules.js +34 -0
  365. package/dist/esm/router/framework/ror/index.js +5 -0
  366. package/dist/esm/router/framework/ror/normalize.js +57 -0
  367. package/dist/esm/router/framework/ror/options.js +33 -0
  368. package/dist/esm/router/framework/ror/provider.js +33 -0
  369. package/dist/esm/router/framework/ror/staticProvider.js +24 -0
  370. package/dist/esm/router/framework/routeAuthPolicy.js +16 -0
  371. package/dist/esm/router/framework/routeDefinitions.js +446 -0
  372. package/dist/esm/router/framework/routeExecutionContext.js +24 -0
  373. package/dist/esm/router/framework/routeExtensions.js +50 -0
  374. package/dist/esm/router/framework/routeMeteringPolicy.js +0 -0
  375. package/dist/esm/router/framework/routeRequestValidation.js +32 -0
  376. package/dist/esm/router/framework/routeResponses.js +33 -0
  377. package/dist/esm/router/framework/routerApi.js +42 -0
  378. package/dist/esm/router/framework/routerApiRouteSurface.js +54 -0
  379. package/dist/esm/router/framework/routerApiWebhooks.js +60 -0
  380. package/dist/esm/router/framework/runtimeSnapshotConsumer.js +145 -0
  381. package/dist/esm/router/framework/versionedJsonRecordStore.js +0 -0
  382. package/dist/esm/router/ror-adaptor.js +5 -0
  383. package/dist/esm/router/ror.js +178 -0
  384. package/dist/esm/router/transport/fetch/createFetchRouter.js +309 -0
  385. package/dist/esm/router/transport/fetch/fetchRouter.types.js +0 -0
  386. package/dist/esm/router/transport/fetch/routes/auth.js +219 -0
  387. package/dist/esm/router/transport/fetch/routes/deviceLinking.js +1196 -0
  388. package/dist/esm/router/transport/fetch/routes/deviceLinkingOwnerAuthorization.js +264 -0
  389. package/dist/esm/router/transport/fetch/routes/deviceManagement.js +289 -0
  390. package/dist/esm/router/transport/fetch/routes/health.js +42 -0
  391. package/dist/esm/router/transport/fetch/routes/nearPublicKeys.js +39 -0
  392. package/dist/esm/router/transport/fetch/routes/normalSigningRouterProxy.js +118 -0
  393. package/dist/esm/router/transport/fetch/routes/passkeyCustody.js +1618 -0
  394. package/dist/esm/router/transport/fetch/routes/sessions.js +1033 -0
  395. package/dist/esm/router/transport/fetch/routes/syncAccount.js +187 -0
  396. package/dist/esm/router/transport/fetch/routes/syncAccountBootstrap.js +214 -0
  397. package/dist/esm/router/transport/fetch/routes/thresholdEcdsa.js +1729 -0
  398. package/dist/esm/router/transport/fetch/routes/thresholdEd25519.js +1321 -0
  399. package/dist/esm/router/transport/fetch/routes/walletExecutionLanePreflight.js +228 -0
  400. package/dist/esm/router/transport/fetch/routes/walletRegistration.js +73 -0
  401. package/dist/esm/router/transport/fetch/routes/webauthnAuthenticators.js +43 -0
  402. package/dist/esm/router/transport/fetch/routes/wellKnown.js +48 -0
  403. package/dist/esm/shared-ts/src/authorization/capabilityKinds.js +224 -0
  404. package/dist/esm/shared-ts/src/authorization/delegatedAuthority.js +134 -0
  405. package/dist/esm/shared-ts/src/authorization/index.js +6 -0
  406. package/dist/esm/shared-ts/src/authorization/operationFingerprint.js +58 -0
  407. package/dist/esm/shared-ts/src/authorization/walletAuthority.js +802 -0
  408. package/dist/esm/shared-ts/src/authorization/walletCustodyOperation.js +18 -0
  409. package/dist/esm/shared-ts/src/authorization/walletSessionIssuance.js +5 -0
  410. package/dist/esm/shared-ts/src/device-linking/committedSignerPackages.js +332 -0
  411. package/dist/esm/shared-ts/src/device-linking/contracts.js +8 -0
  412. package/dist/esm/shared-ts/src/device-linking/delegatedActivationPlan.js +132 -0
  413. package/dist/esm/shared-ts/src/device-linking/digests.js +273 -0
  414. package/dist/esm/shared-ts/src/device-linking/ed25519ExportRoot.js +158 -0
  415. package/dist/esm/shared-ts/src/device-linking/index.js +9 -0
  416. package/dist/esm/shared-ts/src/device-linking/parsers.js +1412 -0
  417. package/dist/esm/shared-ts/src/device-linking/requestProof.js +114 -0
  418. package/dist/esm/shared-ts/src/device-linking/sourceContribution.js +563 -0
  419. package/dist/esm/shared-ts/src/device-linking/walletSessionCredentialDelivery.js +207 -0
  420. package/dist/esm/shared-ts/src/near/actions.js +75 -0
  421. package/dist/esm/shared-ts/src/passkey-custody/ceremonyCommitPayload.js +69 -0
  422. package/dist/esm/shared-ts/src/passkey-custody/credentialActivity.js +81 -0
  423. package/dist/esm/shared-ts/src/passkey-custody/custodyEnvelope.js +272 -0
  424. package/dist/esm/shared-ts/src/passkey-custody/custodySecretBinding.js +175 -0
  425. package/dist/esm/shared-ts/src/passkey-custody/index.js +5 -0
  426. package/dist/esm/shared-ts/src/passkey-custody/primitives.js +92 -0
  427. package/dist/esm/shared-ts/src/signing-lanes/evmFamilySigningKeySlotId.js +53 -0
  428. package/dist/esm/shared-ts/src/signing-lanes/execution.js +14 -0
  429. package/dist/esm/shared-ts/src/signing-lanes/index.js +11 -0
  430. package/dist/esm/shared-ts/src/signing-lanes/linkedEcdsaScope.js +1 -0
  431. package/dist/esm/shared-ts/src/signing-lanes/ownerContinuity.js +91 -0
  432. package/dist/esm/shared-ts/src/signing-lanes/participantDigest.js +124 -0
  433. package/dist/esm/shared-ts/src/signing-lanes/participants.js +262 -0
  434. package/dist/esm/shared-ts/src/signing-lanes/recordParsers.js +143 -0
  435. package/dist/esm/shared-ts/src/signing-lanes/rotation.js +8 -0
  436. package/dist/esm/shared-ts/src/signing-lanes/rotationDigests.js +397 -0
  437. package/dist/esm/shared-ts/src/signing-lanes/rotationLifecycle.js +313 -0
  438. package/dist/esm/shared-ts/src/signing-lanes/rotationParsers.js +1620 -0
  439. package/dist/esm/shared-ts/src/tenant-root/index.js +2 -0
  440. package/dist/esm/shared-ts/src/tenant-root/tenantRootIdentity.js +198 -0
  441. package/dist/esm/shared-ts/src/tenant-root/tenantRootOperationRecord.js +440 -0
  442. package/dist/esm/shared-ts/src/threshold/ecdsaDerivationRoleLocalBootstrap.js +85 -0
  443. package/dist/esm/shared-ts/src/threshold/participants.js +26 -0
  444. package/dist/esm/shared-ts/src/threshold/sessionPolicy.js +9 -0
  445. package/dist/esm/shared-ts/src/threshold/signingRootScope.js +40 -0
  446. package/dist/esm/shared-ts/src/utils/addAuthMethodRegistration.js +104 -0
  447. package/dist/esm/shared-ts/src/utils/addWalletAuthMethod.js +36 -0
  448. package/dist/esm/shared-ts/src/utils/base58.js +28 -0
  449. package/dist/esm/shared-ts/src/utils/base64.js +70 -0
  450. package/dist/esm/shared-ts/src/utils/canonicalPrimitives.js +27 -0
  451. package/dist/esm/shared-ts/src/utils/digests.js +33 -0
  452. package/dist/esm/shared-ts/src/utils/domainIds.js +309 -0
  453. package/dist/esm/shared-ts/src/utils/ecdsaCapabilityActivation.js +34 -0
  454. package/dist/esm/shared-ts/src/utils/ecdsaKeyFactsInventory.js +46 -0
  455. package/dist/esm/shared-ts/src/utils/emailOtpDomain.js +38 -0
  456. package/dist/esm/shared-ts/src/utils/emailOtpRecoveryKey.js +10 -0
  457. package/dist/esm/shared-ts/src/utils/encoders.js +2 -0
  458. package/dist/esm/shared-ts/src/utils/errors.js +88 -0
  459. package/dist/esm/shared-ts/src/utils/evmRpcResults.js +97 -0
  460. package/dist/esm/shared-ts/src/utils/jsonRpc.js +64 -0
  461. package/dist/esm/shared-ts/src/utils/keccak.js +150 -0
  462. package/dist/esm/shared-ts/src/utils/near.js +99 -0
  463. package/dist/esm/shared-ts/src/utils/nearRpcResults.js +205 -0
  464. package/dist/esm/shared-ts/src/utils/normalize.js +87 -0
  465. package/dist/esm/shared-ts/src/utils/registrationEstablishedSession.js +201 -0
  466. package/dist/esm/shared-ts/src/utils/registrationIntent.js +1268 -0
  467. package/dist/esm/shared-ts/src/utils/routerAbEcdsaDerivation.js +1655 -0
  468. package/dist/esm/shared-ts/src/utils/routerAbEd25519Yao.js +984 -0
  469. package/dist/esm/shared-ts/src/utils/routerAbNormalSigningIdentity.js +118 -0
  470. package/dist/esm/shared-ts/src/utils/routerAbPublicKeyset.js +138 -0
  471. package/dist/esm/shared-ts/src/utils/routerAbTraceContext.js +36 -0
  472. package/dist/esm/shared-ts/src/utils/secureRandomId.js +35 -0
  473. package/dist/esm/shared-ts/src/utils/signingSessionSeal.js +118 -0
  474. package/dist/esm/shared-ts/src/utils/thresholdEcdsaKeyHandle.js +28 -0
  475. package/dist/esm/shared-ts/src/utils/validation.js +23 -0
  476. package/dist/esm/shared-ts/src/utils/walletAddSignerActivation.js +32 -0
  477. package/dist/esm/shared-ts/src/utils/walletAuthAuthority.js +207 -0
  478. package/dist/esm/shared-ts/src/utils/walletSessionFailure.js +15 -0
  479. package/dist/esm/shared-ts/src/utils/webauthnDeviceInfo.js +207 -0
  480. package/dist/esm/shared-ts/src/wallet-recovery/backupAcknowledgement.js +66 -0
  481. package/dist/esm/shared-ts/src/wallet-recovery/index.js +10 -0
  482. package/dist/esm/shared-ts/src/wallet-recovery/recoveryCodeIssuance.js +1 -0
  483. package/dist/esm/shared-ts/src/wallet-recovery/recoveryCodeLocator.js +34 -0
  484. package/dist/esm/shared-ts/src/wallet-recovery/recoveryCodeReservation.js +80 -0
  485. package/dist/esm/shared-ts/src/wallet-recovery/recoveryCodes.js +4 -0
  486. package/dist/esm/shared-ts/src/wallet-recovery/recoveryKeyId.js +53 -0
  487. package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryCommittedProjection.js +108 -0
  488. package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryEcdsaPossession.js +157 -0
  489. package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryEnvelopeSet.js +233 -0
  490. package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryRotation.js +3 -0
  491. package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryTarget.js +29 -0
  492. package/dist/esm/storage/d1Sql.js +85 -0
  493. package/dist/esm/storage/tenantRoute.js +89 -0
  494. package/dist/esm/tenant-root.js +5 -0
  495. package/dist/esm/threshold/session/signingSessionSeal/crypto/cipher.js +204 -0
  496. package/dist/esm/threshold/session/signingSessionSeal/crypto/shamir3PassWasm.js +87 -0
  497. package/dist/esm/threshold/session/signingSessionSeal/guards/backends.js +192 -0
  498. package/dist/esm/threshold/session/signingSessionSeal/guards/index.js +121 -0
  499. package/dist/esm/threshold/session/signingSessionSeal/idempotency.js +38 -0
  500. package/dist/esm/threshold/session/signingSessionSeal/idempotencyBackends.js +131 -0
  501. package/dist/esm/threshold/session/signingSessionSeal/idempotencyRecords.js +55 -0
  502. package/dist/esm/threshold/session/signingSessionSeal/index.js +13 -0
  503. package/dist/esm/threshold/session/signingSessionSeal/observability/audit.js +38 -0
  504. package/dist/esm/threshold/session/signingSessionSeal/options.js +54 -0
  505. package/dist/esm/threshold/session/signingSessionSeal/routesOptions.js +45 -0
  506. package/dist/esm/threshold/session/signingSessionSeal/service.js +316 -0
  507. package/dist/esm/threshold/session/signingSessionSeal/signingSessionSeal.types.js +0 -0
  508. package/dist/esm/threshold/session/signingSessionSeal/transport/express.js +151 -0
  509. package/dist/esm/threshold/session/signingSessionSeal/transport/fetch.js +106 -0
  510. package/dist/esm/threshold/session/signingSessionSeal/transport/shared.js +159 -0
  511. package/dist/esm/threshold/statusCodes.js +39 -0
  512. package/dist/esm/wasm/evm_crypto/pkg/evm_crypto.js +601 -0
  513. package/dist/esm/wasm/evm_crypto/pkg/evm_crypto_bg.wasm +0 -0
  514. package/dist/esm/wasm/near_signer/pkg/wasm_signer_worker.js +1078 -0
  515. package/dist/esm/wasm/near_signer/pkg/wasm_signer_worker_bg.wasm +0 -0
  516. package/dist/esm/wasm/router_ab_ecdsa_signing_worker/pkg/router_ab_ecdsa_signing_worker.js +503 -0
  517. package/dist/esm/wasm/router_ab_ecdsa_signing_worker/pkg/router_ab_ecdsa_signing_worker_bg.wasm +0 -0
  518. package/dist/esm/wasm/shamir3pass_runtime/pkg/shamir3pass_runtime.js +393 -0
  519. package/dist/esm/wasm/shamir3pass_runtime/pkg/shamir3pass_runtime_bg.wasm +0 -0
  520. package/dist/esm/wasm/signer.js +2 -0
  521. package/dist/types/shared-ts/src/authorization/capabilityKinds.d.ts +147 -0
  522. package/dist/types/shared-ts/src/authorization/capabilityKinds.typecheck.d.ts +2 -0
  523. package/dist/types/shared-ts/src/authorization/delegatedAuthority.d.ts +44 -0
  524. package/dist/types/shared-ts/src/authorization/index.d.ts +7 -0
  525. package/dist/types/shared-ts/src/authorization/operationFingerprint.d.ts +39 -0
  526. package/dist/types/shared-ts/src/authorization/operationFingerprint.typecheck.d.ts +2 -0
  527. package/dist/types/shared-ts/src/authorization/walletAuthority.d.ts +168 -0
  528. package/dist/types/shared-ts/src/authorization/walletAuthority.typecheck.d.ts +2 -0
  529. package/dist/types/shared-ts/src/authorization/walletCustodyOperation.d.ts +10 -0
  530. package/dist/types/shared-ts/src/authorization/walletSessionIssuance.d.ts +28 -0
  531. package/dist/types/shared-ts/src/device-linking/activeWalletSession.d.ts +3 -0
  532. package/dist/types/shared-ts/src/device-linking/activeWalletSession.typecheck.d.ts +2 -0
  533. package/dist/types/shared-ts/src/device-linking/committedSignerPackages.d.ts +71 -0
  534. package/dist/types/shared-ts/src/device-linking/contracts.d.ts +843 -0
  535. package/dist/types/shared-ts/src/device-linking/contracts.typecheck.d.ts +2 -0
  536. package/dist/types/shared-ts/src/device-linking/delegatedActivationPlan.d.ts +37 -0
  537. package/dist/types/shared-ts/src/device-linking/digests.d.ts +23 -0
  538. package/dist/types/shared-ts/src/device-linking/ed25519ExportRoot.d.ts +93 -0
  539. package/dist/types/shared-ts/src/device-linking/index.d.ts +11 -0
  540. package/dist/types/shared-ts/src/device-linking/parsers.d.ts +124 -0
  541. package/dist/types/shared-ts/src/device-linking/requestProof.d.ts +26 -0
  542. package/dist/types/shared-ts/src/device-linking/sourceContribution.d.ts +182 -0
  543. package/dist/types/shared-ts/src/device-linking/walletSessionCredentialDelivery.d.ts +84 -0
  544. package/dist/types/shared-ts/src/index.d.ts +10 -0
  545. package/dist/types/shared-ts/src/near/actions.d.ts +141 -0
  546. package/dist/types/shared-ts/src/near/delegate.d.ts +55 -0
  547. package/dist/types/shared-ts/src/near/index.d.ts +3 -0
  548. package/dist/types/shared-ts/src/passkey-custody/ceremonyCommitPayload.d.ts +211 -0
  549. package/dist/types/shared-ts/src/passkey-custody/credentialActivity.d.ts +49 -0
  550. package/dist/types/shared-ts/src/passkey-custody/credentialObservations.d.ts +74 -0
  551. package/dist/types/shared-ts/src/passkey-custody/custodyEnvelope.d.ts +191 -0
  552. package/dist/types/shared-ts/src/passkey-custody/custodySecretBinding.d.ts +140 -0
  553. package/dist/types/shared-ts/src/passkey-custody/envelopeIndex.d.ts +29 -0
  554. package/dist/types/shared-ts/src/passkey-custody/index.d.ts +9 -0
  555. package/dist/types/shared-ts/src/passkey-custody/kekContext.d.ts +34 -0
  556. package/dist/types/shared-ts/src/passkey-custody/passkeyCustody.typecheck.d.ts +2 -0
  557. package/dist/types/shared-ts/src/passkey-custody/primitives.d.ts +34 -0
  558. package/dist/types/shared-ts/src/signing-lanes/evmFamilySigningKeySlotId.d.ts +27 -0
  559. package/dist/types/shared-ts/src/signing-lanes/execution.d.ts +91 -0
  560. package/dist/types/shared-ts/src/signing-lanes/execution.typecheck.d.ts +2 -0
  561. package/dist/types/shared-ts/src/signing-lanes/ids.d.ts +18 -0
  562. package/dist/types/shared-ts/src/signing-lanes/index.d.ts +14 -0
  563. package/dist/types/shared-ts/src/signing-lanes/linkedEcdsaScope.d.ts +62 -0
  564. package/dist/types/shared-ts/src/signing-lanes/linkedEcdsaScope.typecheck.d.ts +2 -0
  565. package/dist/types/shared-ts/src/signing-lanes/ownerContinuity.d.ts +30 -0
  566. package/dist/types/shared-ts/src/signing-lanes/ownerContinuity.typecheck.d.ts +2 -0
  567. package/dist/types/shared-ts/src/signing-lanes/participantDigest.d.ts +48 -0
  568. package/dist/types/shared-ts/src/signing-lanes/participantDigest.typecheck.d.ts +2 -0
  569. package/dist/types/shared-ts/src/signing-lanes/participants.d.ts +89 -0
  570. package/dist/types/shared-ts/src/signing-lanes/recordParsers.d.ts +128 -0
  571. package/dist/types/shared-ts/src/signing-lanes/records.d.ts +160 -0
  572. package/dist/types/shared-ts/src/signing-lanes/records.typecheck.d.ts +2 -0
  573. package/dist/types/shared-ts/src/signing-lanes/rotation.d.ts +894 -0
  574. package/dist/types/shared-ts/src/signing-lanes/rotation.typecheck.d.ts +2 -0
  575. package/dist/types/shared-ts/src/signing-lanes/rotationDigests.d.ts +32 -0
  576. package/dist/types/shared-ts/src/signing-lanes/rotationLifecycle.d.ts +99 -0
  577. package/dist/types/shared-ts/src/signing-lanes/rotationParsers.d.ts +67 -0
  578. package/dist/types/shared-ts/src/signing-lanes/validation.d.ts +11 -0
  579. package/dist/types/shared-ts/src/tenant-root/index.d.ts +3 -0
  580. package/dist/types/shared-ts/src/tenant-root/tenantRootIdentity.d.ts +72 -0
  581. package/dist/types/shared-ts/src/tenant-root/tenantRootOperationRecord.d.ts +192 -0
  582. package/dist/types/shared-ts/src/threshold/ecdsaDerivationRoleLocalBootstrap.d.ts +77 -0
  583. package/dist/types/shared-ts/src/threshold/ed25519OperationFingerprint.d.ts +130 -0
  584. package/dist/types/shared-ts/src/threshold/index.d.ts +7 -0
  585. package/dist/types/shared-ts/src/threshold/participants.d.ts +38 -0
  586. package/dist/types/shared-ts/src/threshold/secp256k1.d.ts +39 -0
  587. package/dist/types/shared-ts/src/threshold/sessionPolicy.d.ts +5 -0
  588. package/dist/types/shared-ts/src/threshold/signingRootScope.d.ts +24 -0
  589. package/dist/types/shared-ts/src/utils/addAuthMethodRegistration.d.ts +63 -0
  590. package/dist/types/shared-ts/src/utils/addWalletAuthMethod.d.ts +295 -0
  591. package/dist/types/shared-ts/src/utils/addWalletAuthMethod.typecheck.d.ts +11 -0
  592. package/dist/types/shared-ts/src/utils/authenticatorOptions.d.ts +25 -0
  593. package/dist/types/shared-ts/src/utils/base58.d.ts +17 -0
  594. package/dist/types/shared-ts/src/utils/base64.d.ts +53 -0
  595. package/dist/types/shared-ts/src/utils/bigint.d.ts +3 -0
  596. package/dist/types/shared-ts/src/utils/canonicalPrimitives.d.ts +12 -0
  597. package/dist/types/shared-ts/src/utils/digests.d.ts +6 -0
  598. package/dist/types/shared-ts/src/utils/domainIds.d.ts +140 -0
  599. package/dist/types/shared-ts/src/utils/domainIds.typecheck.d.ts +2 -0
  600. package/dist/types/shared-ts/src/utils/ecdsaCapabilityActivation.d.ts +29 -0
  601. package/dist/types/shared-ts/src/utils/ecdsaKeyFactsInventory.d.ts +24 -0
  602. package/dist/types/shared-ts/src/utils/emailOtpDomain.d.ts +30 -0
  603. package/dist/types/shared-ts/src/utils/emailOtpRecoveryKey.d.ts +31 -0
  604. package/dist/types/shared-ts/src/utils/encoders.d.ts +3 -0
  605. package/dist/types/shared-ts/src/utils/errors.d.ts +44 -0
  606. package/dist/types/shared-ts/src/utils/evmRpcResults.d.ts +31 -0
  607. package/dist/types/shared-ts/src/utils/generated/routerAbEd25519YaoCore.d.ts +128 -0
  608. package/dist/types/shared-ts/src/utils/index.d.ts +34 -0
  609. package/dist/types/shared-ts/src/utils/jsonRpc.d.ts +30 -0
  610. package/dist/types/shared-ts/src/utils/keccak.d.ts +2 -0
  611. package/dist/types/shared-ts/src/utils/near.d.ts +81 -0
  612. package/dist/types/shared-ts/src/utils/nearRpcResults.d.ts +101 -0
  613. package/dist/types/shared-ts/src/utils/normalize.d.ts +57 -0
  614. package/dist/types/shared-ts/src/utils/paillier.d.ts +37 -0
  615. package/dist/types/shared-ts/src/utils/recoveryDomain.d.ts +12 -0
  616. package/dist/types/shared-ts/src/utils/registrationEstablishedSession.d.ts +85 -0
  617. package/dist/types/shared-ts/src/utils/registrationIntent.d.ts +621 -0
  618. package/dist/types/shared-ts/src/utils/registrationIntent.typecheck.d.ts +2 -0
  619. package/dist/types/shared-ts/src/utils/routerAbEcdsaDerivation.d.ts +715 -0
  620. package/dist/types/shared-ts/src/utils/routerAbEcdsaDerivation.typecheck.d.ts +2 -0
  621. package/dist/types/shared-ts/src/utils/routerAbEcdsaDerivationRefresh.typecheck.d.ts +2 -0
  622. package/dist/types/shared-ts/src/utils/routerAbEd25519Yao.d.ts +339 -0
  623. package/dist/types/shared-ts/src/utils/routerAbEd25519Yao.typecheck.d.ts +2 -0
  624. package/dist/types/shared-ts/src/utils/routerAbNormalSigningIdentity.d.ts +71 -0
  625. package/dist/types/shared-ts/src/utils/routerAbPublicKeyset.d.ts +51 -0
  626. package/dist/types/shared-ts/src/utils/routerAbTraceContext.d.ts +16 -0
  627. package/dist/types/shared-ts/src/utils/secureRandomId.d.ts +6 -0
  628. package/dist/types/shared-ts/src/utils/signerDomain.d.ts +75 -0
  629. package/dist/types/shared-ts/src/utils/signerDomain.typecheck.d.ts +2 -0
  630. package/dist/types/shared-ts/src/utils/signerSlot.d.ts +11 -0
  631. package/dist/types/shared-ts/src/utils/signingSessionSeal.d.ts +153 -0
  632. package/dist/types/shared-ts/src/utils/signingSessionSeal.typecheck.d.ts +2 -0
  633. package/dist/types/shared-ts/src/utils/theme.d.ts +2 -0
  634. package/dist/types/shared-ts/src/utils/thresholdEcdsaKeyHandle.d.ts +11 -0
  635. package/dist/types/shared-ts/src/utils/validation.d.ts +35 -0
  636. package/dist/types/shared-ts/src/utils/walletAddSignerActivation.d.ts +23 -0
  637. package/dist/types/shared-ts/src/utils/walletAuthAuthority.d.ts +150 -0
  638. package/dist/types/shared-ts/src/utils/walletAuthAuthority.typecheck.d.ts +2 -0
  639. package/dist/types/shared-ts/src/utils/walletCapabilityBindings.d.ts +106 -0
  640. package/dist/types/shared-ts/src/utils/walletCapabilityBindings.typecheck.d.ts +2 -0
  641. package/dist/types/shared-ts/src/utils/walletSessionFailure.d.ts +13 -0
  642. package/dist/types/shared-ts/src/utils/webauthnDeviceInfo.d.ts +48 -0
  643. package/dist/types/shared-ts/src/wallet-recovery/backupAcknowledgement.d.ts +56 -0
  644. package/dist/types/shared-ts/src/wallet-recovery/index.d.ts +10 -0
  645. package/dist/types/shared-ts/src/wallet-recovery/recoveryCodeAttempt.d.ts +59 -0
  646. package/dist/types/shared-ts/src/wallet-recovery/recoveryCodeIssuance.d.ts +37 -0
  647. package/dist/types/shared-ts/src/wallet-recovery/recoveryCodeLocator.d.ts +22 -0
  648. package/dist/types/shared-ts/src/wallet-recovery/recoveryCodeReservation.d.ts +79 -0
  649. package/dist/types/shared-ts/src/wallet-recovery/recoveryCodes.d.ts +11 -0
  650. package/dist/types/shared-ts/src/wallet-recovery/recoveryEnvelopes.d.ts +42 -0
  651. package/dist/types/shared-ts/src/wallet-recovery/recoveryKekContext.d.ts +37 -0
  652. package/dist/types/shared-ts/src/wallet-recovery/recoveryKeyId.d.ts +58 -0
  653. package/dist/types/shared-ts/src/wallet-recovery/walletRecovery.typecheck.d.ts +2 -0
  654. package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryCommittedProjection.d.ts +110 -0
  655. package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryEcdsaPossession.d.ts +29 -0
  656. package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryEnvelopeSet.d.ts +115 -0
  657. package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryRotation.d.ts +18 -0
  658. package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryTarget.d.ts +12 -0
  659. package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryTarget.typecheck.d.ts +2 -0
  660. package/dist/types/wallet-server/src/authorization/capabilityPolicy.d.ts +45 -0
  661. package/dist/types/wallet-server/src/authorization/capabilityPolicy.typecheck.d.ts +2 -0
  662. package/dist/types/wallet-server/src/authorization/domain.d.ts +454 -0
  663. package/dist/types/wallet-server/src/authorization/domain.typecheck.d.ts +2 -0
  664. package/dist/types/wallet-server/src/authorization/factorEvidence.d.ts +165 -0
  665. package/dist/types/wallet-server/src/authorization/factorEvidence.typecheck.d.ts +2 -0
  666. package/dist/types/wallet-server/src/authorization/service.d.ts +227 -0
  667. package/dist/types/wallet-server/src/authorization/vaultProxyUse.d.ts +75 -0
  668. package/dist/types/wallet-server/src/cloud-host.d.ts +94 -0
  669. package/dist/types/wallet-server/src/core/AuthService.d.ts +3 -0
  670. package/dist/types/wallet-server/src/core/EmailOtpRecords.d.ts +33 -0
  671. package/dist/types/wallet-server/src/core/EmailOtpStores.d.ts +336 -0
  672. package/dist/types/wallet-server/src/core/IdentityStore.d.ts +57 -0
  673. package/dist/types/wallet-server/src/core/NearPublicKeyStore.d.ts +58 -0
  674. package/dist/types/wallet-server/src/core/RegistrationCeremonyStore.d.ts +551 -0
  675. package/dist/types/wallet-server/src/core/SessionService.d.ts +70 -0
  676. package/dist/types/wallet-server/src/core/ThresholdService/config.d.ts +23 -0
  677. package/dist/types/wallet-server/src/core/ThresholdService/ecdsaClientRootProof.d.ts +12 -0
  678. package/dist/types/wallet-server/src/core/ThresholdService/evmCryptoWasm.d.ts +32 -0
  679. package/dist/types/wallet-server/src/core/ThresholdService/index.d.ts +4 -0
  680. package/dist/types/wallet-server/src/core/ThresholdService/kv.d.ts +52 -0
  681. package/dist/types/wallet-server/src/core/ThresholdService/routerAb/ecdsaDerivationPoolFillHandlers.d.ts +45 -0
  682. package/dist/types/wallet-server/src/core/ThresholdService/routerAb/ecdsaDerivationPoolFillLiveSession.d.ts +93 -0
  683. package/dist/types/wallet-server/src/core/ThresholdService/routerAb/ecdsaDerivationPresignBridge.d.ts +138 -0
  684. package/dist/types/wallet-server/src/core/ThresholdService/routerAb/internalServiceHttp.d.ts +30 -0
  685. package/dist/types/wallet-server/src/core/ThresholdService/routerAbEcdsaSigningWorkerWasm.d.ts +17 -0
  686. package/dist/types/wallet-server/src/core/ThresholdService/routerAbNormalSigningPolicy.d.ts +21 -0
  687. package/dist/types/wallet-server/src/core/ThresholdService/secureRandomId.d.ts +2 -0
  688. package/dist/types/wallet-server/src/core/ThresholdService/stores/CloudflareDurableObjectStore.d.ts +128 -0
  689. package/dist/types/wallet-server/src/core/ThresholdService/stores/EcdsaSigningStore.d.ts +76 -0
  690. package/dist/types/wallet-server/src/core/ThresholdService/stores/KeyStore.d.ts +39 -0
  691. package/dist/types/wallet-server/src/core/ThresholdService/stores/SessionStore.d.ts +102 -0
  692. package/dist/types/wallet-server/src/core/ThresholdService/stores/StoreConfig.d.ts +3 -0
  693. package/dist/types/wallet-server/src/core/ThresholdService/stores/ThresholdStoreConfig.typecheck.d.ts +2 -0
  694. package/dist/types/wallet-server/src/core/ThresholdService/stores/WalletSessionStore.d.ts +98 -0
  695. package/dist/types/wallet-server/src/core/ThresholdService/thresholdEd25519AuthorityScope.typecheck.d.ts +2 -0
  696. package/dist/types/wallet-server/src/core/ThresholdService/validation.d.ts +193 -0
  697. package/dist/types/wallet-server/src/core/WalletAuthMethodStore.d.ts +12 -0
  698. package/dist/types/wallet-server/src/core/WalletStore.d.ts +143 -0
  699. package/dist/types/wallet-server/src/core/WalletStore.typecheck.d.ts +2 -0
  700. package/dist/types/wallet-server/src/core/WebAuthnAuthenticatorStore.d.ts +62 -0
  701. package/dist/types/wallet-server/src/core/WebAuthnCredentialBindingStore.d.ts +116 -0
  702. package/dist/types/wallet-server/src/core/WebAuthnCredentialBindingStore.typecheck.d.ts +13 -0
  703. package/dist/types/wallet-server/src/core/WebAuthnLoginChallengeStore.d.ts +50 -0
  704. package/dist/types/wallet-server/src/core/WebAuthnSyncChallengeStore.d.ts +50 -0
  705. package/dist/types/wallet-server/src/core/authService/AuthService.d.ts +493 -0
  706. package/dist/types/wallet-server/src/core/authService/bytes.d.ts +4 -0
  707. package/dist/types/wallet-server/src/core/authService/configValues.d.ts +7 -0
  708. package/dist/types/wallet-server/src/core/authService/emailOtpChallengeOperations.d.ts +108 -0
  709. package/dist/types/wallet-server/src/core/authService/emailOtpChallengeProof.d.ts +177 -0
  710. package/dist/types/wallet-server/src/core/authService/emailOtpChallengeVerification.d.ts +46 -0
  711. package/dist/types/wallet-server/src/core/authService/emailOtpChallenges.d.ts +110 -0
  712. package/dist/types/wallet-server/src/core/authService/emailOtpConfig.d.ts +34 -0
  713. package/dist/types/wallet-server/src/core/authService/emailOtpDelivery.d.ts +65 -0
  714. package/dist/types/wallet-server/src/core/authService/emailOtpEnrollment.d.ts +79 -0
  715. package/dist/types/wallet-server/src/core/authService/emailOtpGrant.d.ts +42 -0
  716. package/dist/types/wallet-server/src/core/authService/emailOtpRegistrationEnrollment.d.ts +116 -0
  717. package/dist/types/wallet-server/src/core/authService/emailOtpSeal.d.ts +35 -0
  718. package/dist/types/wallet-server/src/core/authService/emailOtpUnlock.d.ts +70 -0
  719. package/dist/types/wallet-server/src/core/authService/githubOAuth.d.ts +35 -0
  720. package/dist/types/wallet-server/src/core/authService/googleEmailOtpErrors.d.ts +2 -0
  721. package/dist/types/wallet-server/src/core/authService/googleEmailOtpOperations.d.ts +126 -0
  722. package/dist/types/wallet-server/src/core/authService/googleEmailOtpRegistration.d.ts +172 -0
  723. package/dist/types/wallet-server/src/core/authService/identity.d.ts +25 -0
  724. package/dist/types/wallet-server/src/core/authService/identityOperations.d.ts +19 -0
  725. package/dist/types/wallet-server/src/core/authService/nearAccountOperations.d.ts +55 -0
  726. package/dist/types/wallet-server/src/core/authService/nearPrivateKeySigning.d.ts +16 -0
  727. package/dist/types/wallet-server/src/core/authService/nearPublicKeyMetadata.d.ts +43 -0
  728. package/dist/types/wallet-server/src/core/authService/nearTransactions.d.ts +49 -0
  729. package/dist/types/wallet-server/src/core/authService/oidcVerification.d.ts +65 -0
  730. package/dist/types/wallet-server/src/core/authService/portableCrypto.d.ts +3 -0
  731. package/dist/types/wallet-server/src/core/authService/rateLimits.d.ts +30 -0
  732. package/dist/types/wallet-server/src/core/authService/record.d.ts +2 -0
  733. package/dist/types/wallet-server/src/core/authService/registrationThresholdHelpers.d.ts +37 -0
  734. package/dist/types/wallet-server/src/core/authService/runtime.d.ts +20 -0
  735. package/dist/types/wallet-server/src/core/authService/signerWasmUrls.d.ts +3 -0
  736. package/dist/types/wallet-server/src/core/authService/storeRegistry.d.ts +58 -0
  737. package/dist/types/wallet-server/src/core/authService/thresholdEcdsaKeyInventory.d.ts +72 -0
  738. package/dist/types/wallet-server/src/core/authService/thresholdRuntimePolicy.d.ts +4 -0
  739. package/dist/types/wallet-server/src/core/authService/thresholdStoreSummary.d.ts +3 -0
  740. package/dist/types/wallet-server/src/core/authService/walletRegistrationPlanning.d.ts +19 -0
  741. package/dist/types/wallet-server/src/core/authService/wasm.d.ts +12 -0
  742. package/dist/types/wallet-server/src/core/authService/webauthn.d.ts +207 -0
  743. package/dist/types/wallet-server/src/core/authService/webauthnAuthority.d.ts +5 -0
  744. package/dist/types/wallet-server/src/core/authService/webauthnOidcHelpers.d.ts +52 -0
  745. package/dist/types/wallet-server/src/core/authService/webauthnWalletBinding.d.ts +48 -0
  746. package/dist/types/wallet-server/src/core/config.d.ts +13 -0
  747. package/dist/types/wallet-server/src/core/d1IdentityStore.d.ts +44 -0
  748. package/dist/types/wallet-server/src/core/d1WalletAuthMethodStore.d.ts +214 -0
  749. package/dist/types/wallet-server/src/core/d1WalletStore.d.ts +108 -0
  750. package/dist/types/wallet-server/src/core/defaultConfigsServer.d.ts +5 -0
  751. package/dist/types/wallet-server/src/core/deviceLinking/index.d.ts +5 -0
  752. package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceEd25519ExportRoot.d.ts +36 -0
  753. package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceEmailOtpGrant.d.ts +87 -0
  754. package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceManagement.d.ts +137 -0
  755. package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceSession.d.ts +462 -0
  756. package/dist/types/wallet-server/src/core/deviceLinking/requestProof.d.ts +55 -0
  757. package/dist/types/wallet-server/src/core/errors.d.ts +10 -0
  758. package/dist/types/wallet-server/src/core/hostedAccountIds.d.ts +31 -0
  759. package/dist/types/wallet-server/src/core/keyMaterialBrands.d.ts +28 -0
  760. package/dist/types/wallet-server/src/core/keyMaterialBrands.typecheck.d.ts +2 -0
  761. package/dist/types/wallet-server/src/core/logger.d.ts +21 -0
  762. package/dist/types/wallet-server/src/core/nearKeys.d.ts +3 -0
  763. package/dist/types/wallet-server/src/core/nearRelayerAccountProvisioning.d.ts +78 -0
  764. package/dist/types/wallet-server/src/core/nearSignerWasmRuntime.d.ts +3 -0
  765. package/dist/types/wallet-server/src/core/registrationContracts.d.ts +747 -0
  766. package/dist/types/wallet-server/src/core/registrationRequests.typecheck.d.ts +2 -0
  767. package/dist/types/wallet-server/src/core/routerAbSigning/RouterAbEcdsaPresignRuntime.d.ts +53 -0
  768. package/dist/types/wallet-server/src/core/routerAbSigning/RouterAbNormalSigningRuntime.d.ts +71 -0
  769. package/dist/types/wallet-server/src/core/routerAbSigning/createCloudflareDurableObjectRouterAbSigningRuntimes.d.ts +28 -0
  770. package/dist/types/wallet-server/src/core/routerAbSigning/createRouterAbSigningRuntimes.d.ts +16 -0
  771. package/dist/types/wallet-server/src/core/rpcClients/near/NearClient.d.ts +134 -0
  772. package/dist/types/wallet-server/src/core/sessionValidation.d.ts +9 -0
  773. package/dist/types/wallet-server/src/core/signingLanes/LaneAggregateRevocationApplicationService.d.ts +35 -0
  774. package/dist/types/wallet-server/src/core/signingLanes/LaneEffectJournalStore.d.ts +63 -0
  775. package/dist/types/wallet-server/src/core/signingLanes/LaneEnrollmentActivation.d.ts +13 -0
  776. package/dist/types/wallet-server/src/core/signingLanes/LaneEnrollmentRevocation.d.ts +24 -0
  777. package/dist/types/wallet-server/src/core/signingLanes/LaneLifecycleApplicationService.d.ts +141 -0
  778. package/dist/types/wallet-server/src/core/signingLanes/LaneLifecycleStore.d.ts +229 -0
  779. package/dist/types/wallet-server/src/core/signingLanes/SigningLaneStore.d.ts +15 -0
  780. package/dist/types/wallet-server/src/core/signingLanes/WalletExecutionLaneProjection.d.ts +59 -0
  781. package/dist/types/wallet-server/src/core/signingLanes/WalletKeyStore.d.ts +13 -0
  782. package/dist/types/wallet-server/src/core/signingLanes/ecdsaServerRetirement.d.ts +58 -0
  783. package/dist/types/wallet-server/src/core/signingLanes/ed25519ServerRetirement.d.ts +30 -0
  784. package/dist/types/wallet-server/src/core/signingLanes/index.d.ts +11 -0
  785. package/dist/types/wallet-server/src/core/signingLanes/signingWorkerLaneMaterialIdentity.d.ts +21 -0
  786. package/dist/types/wallet-server/src/core/signingMaterial/ordinaryInactiveSignerMaterialReservation.d.ts +155 -0
  787. package/dist/types/wallet-server/src/core/threeRouteRegistrationContracts.d.ts +442 -0
  788. package/dist/types/wallet-server/src/core/threeRouteRegistrationContracts.typecheck.d.ts +58 -0
  789. package/dist/types/wallet-server/src/core/thresholdEcdsaChainTarget.d.ts +15 -0
  790. package/dist/types/wallet-server/src/core/types.d.ts +757 -0
  791. package/dist/types/wallet-server/src/core/utils.d.ts +3 -0
  792. package/dist/types/wallet-server/src/delegateAction/index.d.ts +88 -0
  793. package/dist/types/wallet-server/src/hosted-wallet-gateway-worker.d.ts +10 -0
  794. package/dist/types/wallet-server/src/hosted-wallet-gateway.d.ts +126 -0
  795. package/dist/types/wallet-server/src/index.d.ts +34 -0
  796. package/dist/types/wallet-server/src/local-hosted-wallet-gateway-worker.d.ts +13 -0
  797. package/dist/types/wallet-server/src/router/auth/authRequestValidation.d.ts +97 -0
  798. package/dist/types/wallet-server/src/router/auth/commonRouterUtils.d.ts +142 -0
  799. package/dist/types/wallet-server/src/router/auth/routerApiCredentialAuth.d.ts +26 -0
  800. package/dist/types/wallet-server/src/router/auth/routerApiKeyAuth.d.ts +16 -0
  801. package/dist/types/wallet-server/src/router/auth/walletSessionFailure.d.ts +14 -0
  802. package/dist/types/wallet-server/src/router/auth/webAuthnCredentialCodecs.d.ts +20 -0
  803. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthBoundary.d.ts +28 -0
  804. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthConfig.d.ts +192 -0
  805. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthService.d.ts +13 -0
  806. package/dist/types/wallet-server/src/router/cloudflare/d1/authorization/d1AuthorizationStore.d.ts +174 -0
  807. package/dist/types/wallet-server/src/router/cloudflare/d1/authorization/d1VaultProxyStore.d.ts +13 -0
  808. package/dist/types/wallet-server/src/router/cloudflare/d1/authorization/walletSessionAuthorityProjection.d.ts +24 -0
  809. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceAuthorityInstallService.d.ts +241 -0
  810. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEd25519ExportRootStore.d.ts +23 -0
  811. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEmailOtpGrantStore.d.ts +32 -0
  812. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEmailOtpTargetFactor.d.ts +118 -0
  813. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceManagementService.d.ts +22 -0
  814. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceOwnerAuthorizationProvider.d.ts +80 -0
  815. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceRequestProofNonceStore.d.ts +29 -0
  816. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceRouteService.d.ts +17 -0
  817. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionRecords.d.ts +37 -0
  818. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionService.d.ts +12 -0
  819. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionStore.d.ts +149 -0
  820. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSourceContributionPreparationPlanner.d.ts +38 -0
  821. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetAuthenticatorStore.d.ts +19 -0
  822. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetCredentialProvider.d.ts +220 -0
  823. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetPlanner.d.ts +88 -0
  824. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceVerifiedLinkBuilder.d.ts +54 -0
  825. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceVerifiedLinkSourceReader.d.ts +23 -0
  826. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/index.d.ts +15 -0
  827. package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoCapabilityPersistence.d.ts +33 -0
  828. package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoProductRegistrationPartitionedStateStore.d.ts +6 -0
  829. package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoWalletSigner.d.ts +27 -0
  830. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeIssuer.d.ts +80 -0
  831. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeService.d.ts +48 -0
  832. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeStore.d.ts +64 -0
  833. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeVerifier.d.ts +126 -0
  834. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpDeliveryRuntime.d.ts +22 -0
  835. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpEnrollmentStore.d.ts +68 -0
  836. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpGrantStore.d.ts +15 -0
  837. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRateLimitStore.d.ts +37 -0
  838. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRecords.d.ts +186 -0
  839. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRecoveryService.d.ts +45 -0
  840. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRegistrationEnrollmentFinalizer.d.ts +124 -0
  841. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpServerSealRuntime.d.ts +24 -0
  842. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpRegistrationAttemptStore.d.ts +51 -0
  843. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpRegistrationRecords.d.ts +69 -0
  844. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpSessionResolver.d.ts +57 -0
  845. package/dist/types/wallet-server/src/router/cloudflare/d1/identity/d1IdentityRecords.d.ts +38 -0
  846. package/dist/types/wallet-server/src/router/cloudflare/d1/identity/d1IdentityService.d.ts +31 -0
  847. package/dist/types/wallet-server/src/router/cloudflare/d1/near/d1NearPublicKeyStore.d.ts +30 -0
  848. package/dist/types/wallet-server/src/router/cloudflare/d1/oidc/d1OidcBoundary.d.ts +60 -0
  849. package/dist/types/wallet-server/src/router/cloudflare/d1/oidc/d1OidcVerificationService.d.ts +39 -0
  850. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1PasskeyCustodyEnvelopeStore.d.ts +335 -0
  851. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1PasskeyCustodyRouteService.d.ts +448 -0
  852. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1WalletCustodyCommitStore.d.ts +256 -0
  853. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpAttemptStore.d.ts +32 -0
  854. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpRecords.d.ts +116 -0
  855. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpService.d.ts +180 -0
  856. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1EvmFamilyEcdsaRegistrationBranch.d.ts +24 -0
  857. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyRecordStore.d.ts +86 -0
  858. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyRecords.d.ts +121 -0
  859. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyStore.d.ts +84 -0
  860. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationIntentService.d.ts +31 -0
  861. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationCommitStore.d.ts +49 -0
  862. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationService.d.ts +369 -0
  863. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationSetup.d.ts +106 -0
  864. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/walletRegistrationEstablishedSessionIssuer.d.ts +104 -0
  865. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/walletRegistrationSessionCommitReceipt.d.ts +70 -0
  866. package/dist/types/wallet-server/src/router/cloudflare/d1/signingAdmission/d1RouterAbNormalSigningAdmissionStore.d.ts +26 -0
  867. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1EcdsaLanePrivateBindingResolver.d.ts +4 -0
  868. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneAggregateRevocationApplicationService.d.ts +4 -0
  869. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneEffectJournalStore.d.ts +25 -0
  870. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneEnrollmentGateway.d.ts +20 -0
  871. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneLifecycleApplicationService.d.ts +13 -0
  872. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneLifecycleStore.d.ts +51 -0
  873. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneLockStore.d.ts +28 -0
  874. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneProtocolCommitter.d.ts +5 -0
  875. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneRecords.d.ts +107 -0
  876. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/index.d.ts +10 -0
  877. package/dist/types/wallet-server/src/router/cloudflare/d1/versionedJson/d1VersionedJsonRecordStore.d.ts +118 -0
  878. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAddSignerService.d.ts +114 -0
  879. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAddSignerService.typecheck.d.ts +2 -0
  880. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthMethodBoundary.d.ts +90 -0
  881. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthMethodService.d.ts +359 -0
  882. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorityStore.d.ts +143 -0
  883. package/dist/types/wallet-server/src/router/cloudflare/d1/webauthn/d1WebAuthnAuthService.d.ts +42 -0
  884. package/dist/types/wallet-server/src/router/cloudflare/d1/webauthn/d1WebAuthnRecords.d.ts +135 -0
  885. package/dist/types/wallet-server/src/router/cloudflare/d1/webauthn/d1WebAuthnStore.d.ts +89 -0
  886. package/dist/types/wallet-server/src/router/cloudflare/durableObjects/thresholdStore.d.ts +19 -0
  887. package/dist/types/wallet-server/src/router/cloudflare/durableObjects/versionedJsonRecordStore.d.ts +32 -0
  888. package/dist/types/wallet-server/src/router/cloudflare/runtime/cloudflare.types.d.ts +30 -0
  889. package/dist/types/wallet-server/src/router/cloudflare/runtime/cloudflareSignerWasm.d.ts +2 -0
  890. package/dist/types/wallet-server/src/router/cloudflare/runtime/createCloudflareRouter.d.ts +5 -0
  891. package/dist/types/wallet-server/src/router/cloudflare/runtime/createSelfHostedCloudflareSigningWorker.d.ts +23 -0
  892. package/dist/types/wallet-server/src/router/cloudflare/runtime/ed25519SessionAdapter.d.ts +16 -0
  893. package/dist/types/wallet-server/src/router/cloudflare/runtime/environment.d.ts +5 -0
  894. package/dist/types/wallet-server/src/router/cloudflare/runtime/routerAbPrewarm.d.ts +9 -0
  895. package/dist/types/wallet-server/src/router/cloudflare/runtime/routerAbServiceBindings.d.ts +11 -0
  896. package/dist/types/wallet-server/src/router/cloudflare/runtime/sessionAdapterRuntime.d.ts +28 -0
  897. package/dist/types/wallet-server/src/router/cloudflare/runtime/staticWalletConsoleBinding.d.ts +27 -0
  898. package/dist/types/wallet-server/src/router/cloudflare/runtime/tenantRootCreationGrant.d.ts +24 -0
  899. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletConsoleOps.d.ts +143 -0
  900. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletConsoleOpsClient.d.ts +20 -0
  901. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletConsoleTenantRootLineage.d.ts +7 -0
  902. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletControlOps.d.ts +21 -0
  903. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletGateway.d.ts +30 -0
  904. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRuntimeOps.d.ts +64 -0
  905. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRuntimeOpsHandler.d.ts +3 -0
  906. package/dist/types/wallet-server/src/router/cloudflare/signingLanes/cloudflareLaneCurveExecution.d.ts +217 -0
  907. package/dist/types/wallet-server/src/router/cloudflare/signingLanes/cloudflareLaneProtocolCommitter.d.ts +73 -0
  908. package/dist/types/wallet-server/src/router/cloudflare/signingLanes/cloudflareOrdinaryInactiveSignerMaterialReservation.d.ts +100 -0
  909. package/dist/types/wallet-server/src/router/cloudflare/signingLanes/index.d.ts +4 -0
  910. package/dist/types/wallet-server/src/router/cloudflare/signingLanes/linkedDeviceEd25519CeremonyBinding.d.ts +6 -0
  911. package/dist/types/wallet-server/src/router/cloudflare-adaptor.d.ts +75 -0
  912. package/dist/types/wallet-server/src/router/domains/ecdsa/routerAbEcdsaStrictRegistration.d.ts +199 -0
  913. package/dist/types/wallet-server/src/router/domains/ecdsa/thresholdEcdsaRequestValidation.d.ts +32 -0
  914. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.d.ts +172 -0
  915. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.typecheck.d.ts +2 -0
  916. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitionedStateStore.d.ts +156 -0
  917. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitioning.d.ts +59 -0
  918. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPersistence.d.ts +47 -0
  919. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRunner.d.ts +29 -0
  920. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRuntime.d.ts +20 -0
  921. package/dist/types/wallet-server/src/router/domains/ed25519Yao/export/routerAbEd25519YaoExport.d.ts +271 -0
  922. package/dist/types/wallet-server/src/router/domains/ed25519Yao/export/routerAbEd25519YaoExportRequestScopedCloudflare.d.ts +12 -0
  923. package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecovery.d.ts +509 -0
  924. package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryActivation.typecheck.d.ts +2 -0
  925. package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryRequestScopedCloudflare.d.ts +14 -0
  926. package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryWalletSessionAuthorization.d.ts +20 -0
  927. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoHttpRegistrationBackend.d.ts +56 -0
  928. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistration.d.ts +200 -0
  929. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationExecutionRecord.d.ts +70 -0
  930. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationIntentAuthorization.d.ts +73 -0
  931. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationRequestScopedCloudflare.d.ts +9 -0
  932. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.d.ts +131 -0
  933. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.typecheck.d.ts +2 -0
  934. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationTwoPhaseRunner.d.ts +62 -0
  935. package/dist/types/wallet-server/src/router/domains/ed25519Yao/routerAbEd25519YaoGatewayEnvelope.d.ts +17 -0
  936. package/dist/types/wallet-server/src/router/domains/ed25519Yao/session/routerAbEd25519YaoWalletSession.d.ts +178 -0
  937. package/dist/types/wallet-server/src/router/domains/ed25519Yao/session/routerAbEd25519YaoWalletSession.typecheck.d.ts +2 -0
  938. package/dist/types/wallet-server/src/router/domains/ed25519Yao/session/thresholdEd25519RequestValidation.d.ts +19 -0
  939. package/dist/types/wallet-server/src/router/domains/emailOtp/emailOtpExportPolicy.d.ts +32 -0
  940. package/dist/types/wallet-server/src/router/domains/emailOtp/emailOtpRequestValidation.d.ts +13 -0
  941. package/dist/types/wallet-server/src/router/domains/emailOtp/emailOtpRouteHandlers.d.ts +35 -0
  942. package/dist/types/wallet-server/src/router/domains/emailOtp/emailOtpSessionRouteHelpers.d.ts +134 -0
  943. package/dist/types/wallet-server/src/router/domains/passkeyCustody/envelopeRevocationAdmission.d.ts +31 -0
  944. package/dist/types/wallet-server/src/router/domains/passkeyCustody/passkeyCustodyEnvelopeRetrieval.d.ts +85 -0
  945. package/dist/types/wallet-server/src/router/domains/passkeyCustody/passkeyCustodyEnvelopeRetrievalRoute.d.ts +42 -0
  946. package/dist/types/wallet-server/src/router/domains/passkeyCustody/registrationCustodyOutcome.d.ts +38 -0
  947. package/dist/types/wallet-server/src/router/domains/passkeyCustody/verifiedCustodyFactor.d.ts +35 -0
  948. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletCustodyRegistrationAdmission.d.ts +56 -0
  949. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletCustodyRegistrationCommit.d.ts +65 -0
  950. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletRecoveryAttempt.d.ts +59 -0
  951. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletRecoveryFinalization.d.ts +81 -0
  952. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletRecoveryKeyManifest.d.ts +184 -0
  953. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletRecoveryRotation.d.ts +31 -0
  954. package/dist/types/wallet-server/src/router/domains/signingOperations/ed25519AuthorizedOperationReceipt.d.ts +32 -0
  955. package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbNormalSigningAdmissionCore.d.ts +48 -0
  956. package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbPrivateSigningWorker.d.ts +909 -0
  957. package/dist/types/wallet-server/src/router/domains/signingOperations/walletExecutionAdmission.d.ts +104 -0
  958. package/dist/types/wallet-server/src/router/domains/syncAccount/syncAccountRequestValidation.d.ts +30 -0
  959. package/dist/types/wallet-server/src/router/domains/tenantRoot/tenantRootCustodyLineage.d.ts +14 -0
  960. package/dist/types/wallet-server/src/router/domains/tenantRoot/tenantRootEcdsaWalletSessionComposition.d.ts +35 -0
  961. package/dist/types/wallet-server/src/router/domains/tenantRoot/tenantRootEd25519WalletSessionComposition.d.ts +35 -0
  962. package/dist/types/wallet-server/src/router/domains/tenantRoot/tenantRootIdentityResolution.d.ts +56 -0
  963. package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationInputs.d.ts +78 -0
  964. package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationRoutes.d.ts +91 -0
  965. package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationSetupPayload.d.ts +105 -0
  966. package/dist/types/wallet-server/src/router/domains/walletUnlock/walletUnlockRequestedCapabilitiesValidation.d.ts +39 -0
  967. package/dist/types/wallet-server/src/router/domains/walletUnlock/walletUnlockRouteHandlers.d.ts +172 -0
  968. package/dist/types/wallet-server/src/router/express-adaptor.d.ts +22 -0
  969. package/dist/types/wallet-server/src/router/framework/apiCredentialPorts.d.ts +82 -0
  970. package/dist/types/wallet-server/src/router/framework/applyRouteMetering.d.ts +23 -0
  971. package/dist/types/wallet-server/src/router/framework/authServicePort.d.ts +1392 -0
  972. package/dist/types/wallet-server/src/router/framework/enforceRoutePolicy.d.ts +48 -0
  973. package/dist/types/wallet-server/src/router/framework/http.d.ts +12 -0
  974. package/dist/types/wallet-server/src/router/framework/logger.d.ts +5 -0
  975. package/dist/types/wallet-server/src/router/framework/modules.d.ts +17 -0
  976. package/dist/types/wallet-server/src/router/framework/ror/index.d.ts +7 -0
  977. package/dist/types/wallet-server/src/router/framework/ror/normalize.d.ts +14 -0
  978. package/dist/types/wallet-server/src/router/framework/ror/options.d.ts +9 -0
  979. package/dist/types/wallet-server/src/router/framework/ror/provider.d.ts +17 -0
  980. package/dist/types/wallet-server/src/router/framework/ror/staticProvider.d.ts +11 -0
  981. package/dist/types/wallet-server/src/router/framework/routeAuthPolicy.d.ts +34 -0
  982. package/dist/types/wallet-server/src/router/framework/routeDefinitions.d.ts +27 -0
  983. package/dist/types/wallet-server/src/router/framework/routeDefinitions.typecheck.d.ts +2 -0
  984. package/dist/types/wallet-server/src/router/framework/routeExecutionContext.d.ts +29 -0
  985. package/dist/types/wallet-server/src/router/framework/routeExtensions.d.ts +27 -0
  986. package/dist/types/wallet-server/src/router/framework/routeMeteringPolicy.d.ts +17 -0
  987. package/dist/types/wallet-server/src/router/framework/routeRequestValidation.d.ts +5 -0
  988. package/dist/types/wallet-server/src/router/framework/routeResponses.d.ts +17 -0
  989. package/dist/types/wallet-server/src/router/framework/routerApi.d.ts +221 -0
  990. package/dist/types/wallet-server/src/router/framework/routerApiRouteSurface.d.ts +14 -0
  991. package/dist/types/wallet-server/src/router/framework/routerApiWebhooks.d.ts +12 -0
  992. package/dist/types/wallet-server/src/router/framework/runtimeSnapshotConsumer.d.ts +28 -0
  993. package/dist/types/wallet-server/src/router/framework/versionedJsonRecordStore.d.ts +20 -0
  994. package/dist/types/wallet-server/src/router/ror-adaptor.d.ts +3 -0
  995. package/dist/types/wallet-server/src/router/transport/fetch/createFetchRouter.d.ts +8 -0
  996. package/dist/types/wallet-server/src/router/transport/fetch/fetchRouter.types.d.ts +23 -0
  997. package/dist/types/wallet-server/src/router/transport/fetch/routes/auth.d.ts +3 -0
  998. package/dist/types/wallet-server/src/router/transport/fetch/routes/deviceLinking.d.ts +202 -0
  999. package/dist/types/wallet-server/src/router/transport/fetch/routes/deviceLinkingOwnerAuthorization.d.ts +92 -0
  1000. package/dist/types/wallet-server/src/router/transport/fetch/routes/deviceManagement.d.ts +29 -0
  1001. package/dist/types/wallet-server/src/router/transport/fetch/routes/health.d.ts +4 -0
  1002. package/dist/types/wallet-server/src/router/transport/fetch/routes/nearPublicKeys.d.ts +3 -0
  1003. package/dist/types/wallet-server/src/router/transport/fetch/routes/normalSigningRouterProxy.d.ts +33 -0
  1004. package/dist/types/wallet-server/src/router/transport/fetch/routes/passkeyCustody.d.ts +66 -0
  1005. package/dist/types/wallet-server/src/router/transport/fetch/routes/sessions.d.ts +31 -0
  1006. package/dist/types/wallet-server/src/router/transport/fetch/routes/syncAccount.d.ts +3 -0
  1007. package/dist/types/wallet-server/src/router/transport/fetch/routes/syncAccountBootstrap.d.ts +128 -0
  1008. package/dist/types/wallet-server/src/router/transport/fetch/routes/thresholdEcdsa.d.ts +87 -0
  1009. package/dist/types/wallet-server/src/router/transport/fetch/routes/thresholdEd25519.d.ts +47 -0
  1010. package/dist/types/wallet-server/src/router/transport/fetch/routes/walletExecutionLanePreflight.d.ts +4 -0
  1011. package/dist/types/wallet-server/src/router/transport/fetch/routes/walletRegistration.d.ts +3 -0
  1012. package/dist/types/wallet-server/src/router/transport/fetch/routes/webauthnAuthenticators.d.ts +3 -0
  1013. package/dist/types/wallet-server/src/router/transport/fetch/routes/wellKnown.d.ts +3 -0
  1014. package/dist/types/wallet-server/src/storage/d1Sql.d.ts +14 -0
  1015. package/dist/types/wallet-server/src/storage/tenantRoute.d.ts +136 -0
  1016. package/dist/types/wallet-server/src/storage/tenantRoute.typecheck.d.ts +2 -0
  1017. package/dist/types/wallet-server/src/tenant-root.d.ts +5 -0
  1018. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/crypto/cipher.d.ts +45 -0
  1019. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/crypto/shamir3PassWasm.d.ts +16 -0
  1020. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/guards/backends.d.ts +23 -0
  1021. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/guards/index.d.ts +46 -0
  1022. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/idempotency.d.ts +3 -0
  1023. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/idempotencyBackends.d.ts +24 -0
  1024. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/idempotencyRecords.d.ts +22 -0
  1025. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/index.d.ts +23 -0
  1026. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/observability/audit.d.ts +9 -0
  1027. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/options.d.ts +9 -0
  1028. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/routesOptions.d.ts +20 -0
  1029. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/service.d.ts +3 -0
  1030. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/signingSessionSeal.typecheck.d.ts +2 -0
  1031. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/signingSessionSeal.types.d.ts +148 -0
  1032. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/transport/express.d.ts +12 -0
  1033. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/transport/fetch.d.ts +13 -0
  1034. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/transport/shared.d.ts +24 -0
  1035. package/dist/types/wallet-server/src/threshold/statusCodes.d.ts +10 -0
  1036. package/dist/types/wallet-server/src/wasm/signer.d.ts +8 -0
  1037. package/migrations/d1-signer/0001_signer_d1_initial.sql +2486 -0
  1038. package/migrations/d1-signer/0002_signer_post_103_canonical_upgrade.sql +1576 -0
  1039. package/migrations/d1-signer/0003_r107_wallet_authorization.sql +299 -0
  1040. package/migrations/d1-signer/0004_remove_legacy_email_recovery.sql +14 -0
  1041. package/migrations/d1-signer/0005_r103p8_linked_owner_auth_bindings.sql +92 -0
  1042. package/migrations/d1-signer/0006_r103p8_linked_device_custody_transfers.sql +77 -0
  1043. package/migrations/d1-signer/0007_r103p8_wallet_session_auth_method_provenance.sql +18 -0
  1044. package/migrations/d1-signer/0008_r103p8_linked_device_session_cas_guard.sql +35 -0
  1045. package/migrations/d1-signer/0009_linked_device_email_otp.sql +405 -0
  1046. package/migrations/d1-signer/0010_linked_device_session_target_factor.sql +78 -0
  1047. package/migrations/d1-signer/0011_linked_device_ed25519_export_root.sql +9 -0
  1048. package/migrations/d1-signer/0012_versioned_json_cas_guard.sql +3 -0
  1049. package/migrations/d1-signer/0013_linked_device_export_authorization.sql +133 -0
  1050. package/migrations/d1-signer/0014_wallet_recovery_code_locators.sql +19 -0
  1051. package/migrations/d1-signer/0015_r103e_authority_baseline.sql +259 -0
  1052. package/migrations/d1-signer/0016_r103e_wallet_session_authorizations_v2.sql +133 -0
  1053. package/migrations/d1-signer/0017_r103e_link_session_state.sql +83 -0
  1054. package/migrations/d1-signer/0018_r103e_linked_device_authority_installations.sql +34 -0
  1055. package/migrations/d1-signer/0019_r103e_email_otp_device_methods.sql +3 -0
  1056. package/migrations/d1-signer/0020_r103e_wallet_session_operation_credentials.sql +12 -0
  1057. package/migrations/d1-signer/0021_linked_device_source_contribution_transcripts.sql +64 -0
  1058. package/migrations/d1-signer/0022_r109c_multi_auth_email_cardinality.sql +118 -0
  1059. package/migrations/d1-signer/0023_r109d_first_email_linked_device.sql +111 -0
  1060. package/migrations/d1-signer/0024_r103f_v2_authorized_operation_claim.sql +99 -0
  1061. package/migrations/d1-signer/0025_r109d_email_enrollment_wallet_cardinality.sql +57 -0
  1062. package/migrations/d1-signer/0026_r115_wallet_recovery_authority_provenance.sql +253 -0
  1063. package/migrations/d1-signer/0027_r115_email_otp_recovery_bootstrap.sql +90 -0
  1064. package/migrations/d1-signer/0028_r103f_phase1_additive_schema_bridge.sql +1119 -0
  1065. package/migrations/d1-signer/0029_r103f_phase0_registration_replay_tokens.sql +135 -0
  1066. package/migrations/d1-signer/0030_r103f_wallet_session_client_capability.sql +17 -0
  1067. package/migrations/d1-signer/0031_r103f_delete_registration_replay_tokens.sql +4 -0
  1068. package/migrations/d1-signer/0032_r103f_exact_authorized_operation_enforcement.sql +149 -0
  1069. package/migrations/d1-signer/0033_r103f_linked_delivery_recipient.sql +6 -0
  1070. package/migrations/d1-signer/0034_r103f_exact_wallet_session_cutover.sql +743 -0
  1071. package/migrations/d1-signer/0035_r103f_linked_delivery_acknowledgement_cleanup_window.sql +413 -0
  1072. package/package.json +132 -0
  1073. package/scripts/d1-local-migrate-signer.mjs +148 -0
  1074. package/src/README.md +75 -0
  1075. package/wrangler.local-hosted-wallet-gateway.toml +37 -0
@@ -0,0 +1,2669 @@
1
+ import { mpcMaterialActivationRefsEqual, parseMpcMaterialActivationId, parseProviderSubject, parseWalletId } from "../../../shared-ts/src/utils/domainIds.js";
2
+ import { buildAuthorizationGrantRef, buildEvmEcdsaMpcOperationRef, buildNearEd25519MpcOperationRef, parseAuthorizationAuditEventId, parseAuthorizedOperationId, parseCapabilityId, parseCapabilityOperationId, parsePrincipalId } from "../../../shared-ts/src/authorization/capabilityKinds.js";
3
+ import { base64UrlDecode, base64UrlEncode } from "../../../shared-ts/src/utils/base64.js";
4
+ import { parseDigestB64u } from "../../../shared-ts/src/utils/canonicalPrimitives.js";
5
+ import { buildCapabilityOperationEnvelope, computeCapabilityOperationFingerprintDigest, parseSigningOperationFingerprintDigest } from "../../../shared-ts/src/authorization/operationFingerprint.js";
6
+ import "../../../shared-ts/src/utils/encoders.js";
7
+ import { routerAbMpcMaterialActivationRefFromWire, routerAbMpcMaterialActivationRefToWire, sameRouterAbMpcMaterialActivationRef } from "../../../shared-ts/src/utils/routerAbNormalSigningIdentity.js";
8
+ import { walletAuthAuthorityRef } from "../../../shared-ts/src/utils/walletAuthAuthority.js";
9
+ import { ROUTER_AB_ECDSA_DERIVATION_NORMAL_SIGNING_STATE_KIND_V1, parseRouterAbEcdsaDerivationEvmDigestSigningFinalizeRequestV1, parseRouterAbEcdsaDerivationEvmDigestSigningRequestV1, routerAbEcdsaDerivationActiveStateId, routerAbEcdsaDerivationEvmDigestSigningFinalizeCoreRequestDigestV1, routerAbEcdsaDerivationEvmDigestSigningRequestDigestV1, sameRouterAbEcdsaDerivationNormalSigningScopeV1 } from "../../../shared-ts/src/utils/routerAbEcdsaDerivation.js";
10
+ import { authorizedOperationReplayBodyInit, parseSessionOrigin } from "../../../authorization/domain.js";
11
+ import { WALLET_SESSION_FAILURE_CODES } from "../../../shared-ts/src/utils/walletSessionFailure.js";
12
+ import { postRouterAbInternalServiceJson } from "../../../core/ThresholdService/routerAb/internalServiceHttp.js";
13
+ import { extractBearerCredential } from "../../auth/routerApiKeyAuth.js";
14
+ import { walletSessionFailure, walletSessionFailureStatus } from "../../auth/walletSessionFailure.js";
15
+ import { resolveWalletSessionAuthorizationV2Admission } from "./walletExecutionAdmission.js";
16
+ import { resolveWalletSessionOperationCredentialAdmission, validateRouterAbEcdsaDerivationWalletSessionInputs, validateRouterAbEd25519WalletSessionInputs } from "../../auth/commonRouterUtils.js";
17
+ import { parseEd25519ReusableAuthorizedOperationReceipt, parseEd25519VerifiedStepUpAuthorizedOperationReceipt } from "./ed25519AuthorizedOperationReceipt.js";
18
+ //#region src/router/domains/signingOperations/routerAbPrivateSigningWorker.ts
19
+ const ED25519_SIGNING_INTENT_VERSION_V2 = "router-ab-protocol/ed25519-normal-signing/intent/v2";
20
+ const ED25519_SIGNING_PAYLOAD_VERSION_V2 = "router-ab-protocol/ed25519-normal-signing/payload/v2";
21
+ const ED25519_ROUND1_BINDING_VERSION_V2 = "router-ab-protocol/ed25519-normal-signing/round1-binding/v2";
22
+ const ED25519_TRUSTED_SOURCE_VERSION_V2 = "router-ab-cloudflare-trusted-source/v2";
23
+ function routerAbEcdsaAtomicAuthorizationConfigured(authorizedOperations) {
24
+ return typeof authorizedOperations.admitAuthorizedOperation === "function";
25
+ }
26
+ function buildRouterAbEd25519AcceptedAuthorizedOperationV1(input) {
27
+ const operation = input.operation;
28
+ const operationRef = operation.operation.operation;
29
+ if (operationRef.capabilityKind !== "near_ed25519_mpc_signing") throw new Error("Ed25519 authorized operation capability is invalid");
30
+ if (operationRef.operationKind === "near.export_key") throw new Error("Ed25519 export cannot use normal-signing admission");
31
+ return buildRouterAbAcceptedAuthorizedOperationV1({
32
+ operation,
33
+ operationKind: operationRef.operationKind,
34
+ capabilityKind: "near_ed25519_mpc_signing",
35
+ binding: input.binding
36
+ });
37
+ }
38
+ function buildRouterAbEcdsaAcceptedAuthorizedOperationV1(input) {
39
+ const operation = input.operation;
40
+ const operationRef = operation.operation.operation;
41
+ if (operationRef.capabilityKind !== "evm_ecdsa_mpc_signing" || operationRef.operationKind !== "evm.sign_transaction") throw new Error("ECDSA authorized operation capability or operation kind is invalid");
42
+ return buildRouterAbAcceptedAuthorizedOperationV1({
43
+ operation,
44
+ operationKind: "evm.sign_transaction",
45
+ capabilityKind: "evm_ecdsa_mpc_signing",
46
+ binding: input.binding
47
+ });
48
+ }
49
+ function buildRouterAbAcceptedAuthorizedOperationV1(input) {
50
+ const operation = input.operation;
51
+ const commonAuthorizedOperation = {
52
+ authorized_operation_id: operation.authorizedOperationId,
53
+ operation_id: operation.operation.operationId,
54
+ capability_kind: input.capabilityKind,
55
+ operation_kind: input.operationKind,
56
+ lane_digest_b64u: operation.operation.digests.laneDigest,
57
+ intent_digest_b64u: operation.operation.digests.intentDigest,
58
+ display_digest_b64u: operation.operation.digests.displayDigest,
59
+ operation_fingerprint_digest: operation.operationFingerprintDigest
60
+ };
61
+ switch (input.binding.kind) {
62
+ case "reusable_wallet_session":
63
+ if (operation.authorization.kind !== "authorization_grant" || operation.quota.kind !== "consume_reusable_wallet_session") throw new Error("Reusable Wallet Session authorized operation is invalid");
64
+ return {
65
+ binding: {
66
+ kind: "reusable_wallet_session",
67
+ authorization_id: operation.authorization.authorizationGrantRef.authorizationId,
68
+ wallet_session_id: input.binding.walletSessionId,
69
+ quota_id: input.binding.quotaId
70
+ },
71
+ authorized_operation: {
72
+ kind: "reusable_wallet_session_authorized_operation_v1",
73
+ ...commonAuthorizedOperation
74
+ }
75
+ };
76
+ case "gateway_owner_wallet_session":
77
+ if (operation.authorization.kind !== "authorization_grant" || operation.quota.kind !== "consume_reusable_wallet_session") throw new Error("Gateway owner Wallet Session authorized operation is invalid");
78
+ return {
79
+ binding: {
80
+ kind: "gateway_owner_wallet_session",
81
+ subject_id: input.binding.subjectId,
82
+ account_id: input.binding.accountId,
83
+ authorization_id: input.binding.authorizationId,
84
+ wallet_session_id: input.binding.walletSessionId,
85
+ quota_id: input.binding.quotaId,
86
+ threshold_session_id: input.binding.thresholdSessionId,
87
+ org_id: input.binding.orgId,
88
+ project_id: input.binding.projectId,
89
+ environment: input.binding.environment,
90
+ signing_worker_id: input.binding.signingWorkerId,
91
+ expires_at_ms: input.binding.expiresAtMs
92
+ },
93
+ authorized_operation: {
94
+ kind: "reusable_wallet_session_authorized_operation_v1",
95
+ ...commonAuthorizedOperation
96
+ }
97
+ };
98
+ case "operation_step_up":
99
+ if (operation.authorization.kind !== "verified_step_up" || operation.quota.kind !== "quota_neutral") throw new Error("Verified step-up authorized operation is invalid");
100
+ return {
101
+ binding: {
102
+ kind: "operation_step_up",
103
+ authorization_session_id: input.binding.authorizationSessionId,
104
+ org_id: input.binding.orgId,
105
+ project_id: input.binding.projectId,
106
+ environment: input.binding.environment,
107
+ subject_id: input.binding.subjectId
108
+ },
109
+ authorized_operation: {
110
+ kind: "verified_step_up_authorized_operation_v1",
111
+ authorization_session_id: input.binding.authorizationSessionId,
112
+ evidence_set_digest: operation.authorization.evidenceSetDigest,
113
+ ...commonAuthorizedOperation
114
+ }
115
+ };
116
+ }
117
+ }
118
+ const PRIVATE_ED25519_SIGNING_PREPARE_PATH = "/router-ab/signing-worker/sign/prepare";
119
+ const PRIVATE_ED25519_SIGNING_FINALIZE_PATH = "/router-ab/signing-worker/sign";
120
+ const PRIVATE_ECDSA_DERIVATION_SIGNING_PREPARE_PATH = "/router-ab/signing-worker/ecdsa-derivation/sign/prepare";
121
+ const PRIVATE_ECDSA_DERIVATION_SIGNING_FINALIZE_PATH = "/router-ab/signing-worker/ecdsa-derivation/sign";
122
+ const ROUTER_AB_ED25519_PRIVATE_SIGNING_PATHS = {
123
+ prepare: PRIVATE_ED25519_SIGNING_PREPARE_PATH,
124
+ finalize: PRIVATE_ED25519_SIGNING_FINALIZE_PATH
125
+ };
126
+ const ROUTER_AB_ECDSA_DERIVATION_PRIVATE_SIGNING_PATHS = {
127
+ prepare: PRIVATE_ECDSA_DERIVATION_SIGNING_PREPARE_PATH,
128
+ finalize: PRIVATE_ECDSA_DERIVATION_SIGNING_FINALIZE_PATH
129
+ };
130
+ function resolveRouterAbSigningWorkerFetch(input) {
131
+ if (input) return input;
132
+ return typeof globalThis.fetch === "function" ? globalThis.fetch.bind(globalThis) : null;
133
+ }
134
+ function routerAbEcdsaOperationInProgressResult() {
135
+ return routerAbStepUpError(409, "operation_in_progress", "ECDSA signing operation is already in progress");
136
+ }
137
+ function buildRouterAbEcdsaOwnerOperationStepUpPreparation(input) {
138
+ const [firstParticipantId, secondParticipantId] = input.participantIds;
139
+ if (!input.keyHandle || !input.relayerKeyId || firstParticipantId === void 0 || secondParticipantId === void 0 || input.participantIds.length !== 2) return null;
140
+ return {
141
+ wallet_id: input.request.scope.wallet_id,
142
+ operation_kind: "evm.sign_transaction",
143
+ operation_id: input.request.operation_id,
144
+ operation_digests: input.request.operation_digests,
145
+ material_activation: input.request.material_activation,
146
+ normal_signing_scope: input.request.scope,
147
+ signing_worker_id: input.request.scope.signing_worker.server_id,
148
+ key_handle: input.keyHandle,
149
+ relayer_key_id: input.relayerKeyId,
150
+ participant_ids: [firstParticipantId, secondParticipantId],
151
+ expires_at_ms: input.request.expires_at_ms
152
+ };
153
+ }
154
+ async function resolveRouterAbEcdsaOwnerOperationStepUpPreparation(input) {
155
+ if (input.phase !== "prepare") return void 0;
156
+ try {
157
+ const request = parseRouterAbEcdsaDerivationEvmDigestSigningRequestV1(input.body);
158
+ const walletId = parseWalletId(request.scope.wallet_id);
159
+ if (!walletId.ok) return void 0;
160
+ const activeMaterial = await input.resolveEcdsaMaterialActivation({
161
+ walletId: walletId.value,
162
+ materialActivation: request.material_activation
163
+ });
164
+ if (!activeMaterial.ok) return void 0;
165
+ return buildRouterAbEcdsaOwnerOperationStepUpPreparation({
166
+ request,
167
+ keyHandle: activeMaterial.keyHandle,
168
+ relayerKeyId: activeMaterial.relayerKeyId,
169
+ participantIds: activeMaterial.participantIds
170
+ }) ?? void 0;
171
+ } catch {
172
+ return;
173
+ }
174
+ }
175
+ function decideRouterAbEcdsaOwnerOperationAuthorization(input) {
176
+ if (input.operation.lifecycle !== "claimed" || input.operation.authorization.kind !== "authorization_grant" || input.operation.quota.kind !== "consume_reusable_wallet_session" || input.operation.authorization.authorizationGrantRef.kind !== "wallet_session_authorization") return {
177
+ kind: "denied",
178
+ denial: {
179
+ code: "invalid_authority",
180
+ message: "ECDSA reusable Wallet Session authorization is invalid"
181
+ }
182
+ };
183
+ return {
184
+ kind: "authorized",
185
+ operation: input.operation,
186
+ source: {
187
+ kind: "authorization_grant",
188
+ authorizationGrantRef: input.operation.authorization.authorizationGrantRef
189
+ }
190
+ };
191
+ }
192
+ function buildRouterAbEd25519OwnerOperationStepUpPreparation(input) {
193
+ const operation = parseRouterAbOperationStepUpOperation(input.body.intent);
194
+ const expiresAtMs = Number(input.body.expires_at_ms);
195
+ if (!operation.ok || !Number.isSafeInteger(expiresAtMs) || expiresAtMs <= 0 || input.scope.account_id !== input.scope.material_activation.material_owner || input.material.signingWorkerId !== input.scope.signing_worker_id || input.material.participantIds.length !== 2) return null;
196
+ return {
197
+ wallet_id: input.scope.account_id,
198
+ operation_kind: operation.operation.operationKind,
199
+ operation_id: operation.operationId,
200
+ request_id: input.scope.request_id,
201
+ account_id: input.scope.account_id,
202
+ material_activation: input.scope.material_activation,
203
+ signing_worker_id: input.scope.signing_worker_id,
204
+ near_account_id: input.material.nearAccountId,
205
+ signer_slot: input.material.signerSlot,
206
+ participant_ids: input.material.participantIds,
207
+ expires_at_ms: expiresAtMs
208
+ };
209
+ }
210
+ async function resolveRouterAbEd25519OwnerOperationStepUpPreparation(input) {
211
+ if (input.phase !== "prepare") return void 0;
212
+ try {
213
+ const activeMaterial = await input.resolveEd25519MaterialActivation({
214
+ walletId: input.scope.account_id,
215
+ materialActivation: input.scope.material_activation
216
+ });
217
+ if (!activeMaterial.ok) return void 0;
218
+ return buildRouterAbEd25519OwnerOperationStepUpPreparation({
219
+ scope: input.scope,
220
+ body: input.body,
221
+ material: activeMaterial
222
+ }) ?? void 0;
223
+ } catch {
224
+ return;
225
+ }
226
+ }
227
+ function decideRouterAbEd25519OwnerOperationAuthorization(input) {
228
+ if (input.operation.lifecycle !== "claimed" || input.operation.authorization.kind !== "authorization_grant" || input.operation.authorization.authorizationGrantRef.kind !== "wallet_session_authorization" || input.operation.quota.kind !== "consume_reusable_wallet_session") return {
229
+ kind: "denied",
230
+ denial: {
231
+ code: "invalid_authority",
232
+ message: "Ed25519 reusable Wallet Session authorization is invalid"
233
+ }
234
+ };
235
+ return {
236
+ kind: "authorized",
237
+ operation: input.operation,
238
+ source: {
239
+ kind: "authorization_grant",
240
+ authorizationGrantRef: input.operation.authorization.authorizationGrantRef
241
+ }
242
+ };
243
+ }
244
+ function routerAbEd25519OwnerOperationDecisionForFailure(input) {
245
+ const reason = (() => {
246
+ switch (input.code) {
247
+ case "wallet_session_missing": return "wallet_session_missing";
248
+ case "wallet_session_expired": return "wallet_session_expired";
249
+ case "wallet_budget_exhausted":
250
+ case "wallet_session_quota_exhausted": return "wallet_session_exhausted";
251
+ case "wallet_session_invalid": return "wallet_session_ended";
252
+ default: return null;
253
+ }
254
+ })();
255
+ if (reason && input.phase === "prepare" && input.stepUp) return {
256
+ kind: "step_up_required",
257
+ reason,
258
+ step_up: input.stepUp
259
+ };
260
+ if (reason && input.phase === "prepare") return {
261
+ kind: "denied",
262
+ denial: {
263
+ code: "authorization_unavailable",
264
+ message: "Owner operation step-up preparation is unavailable"
265
+ }
266
+ };
267
+ switch (input.code) {
268
+ case "invalid_body": return {
269
+ kind: "denied",
270
+ denial: {
271
+ code: "invalid_operation",
272
+ message: "Ed25519 operation request is invalid"
273
+ }
274
+ };
275
+ case "wallet_session_mismatch":
276
+ case "wallet_session_scope_mismatch":
277
+ case "scope_mismatch":
278
+ case "authorization_grant_rejected":
279
+ case "verified_step_up_rejected": return {
280
+ kind: "denied",
281
+ denial: {
282
+ code: "invalid_authority",
283
+ message: "Ed25519 operation authority is invalid"
284
+ }
285
+ };
286
+ case "material_mismatch": return {
287
+ kind: "denied",
288
+ denial: {
289
+ code: "inactive_material",
290
+ message: "Ed25519 signing material is inactive"
291
+ }
292
+ };
293
+ case "internal":
294
+ case "not_configured": return {
295
+ kind: "denied",
296
+ denial: {
297
+ code: "authorization_unavailable",
298
+ message: "Ed25519 operation authorization is unavailable"
299
+ }
300
+ };
301
+ default: return null;
302
+ }
303
+ }
304
+ function routerAbEd25519OwnerOperationFailureResult(input) {
305
+ const decision = routerAbEd25519OwnerOperationDecisionForFailure(input);
306
+ return {
307
+ status: input.status,
308
+ body: {
309
+ ok: false,
310
+ code: input.code,
311
+ message: input.message,
312
+ ...decision ? { authorization_decision: decision } : {}
313
+ }
314
+ };
315
+ }
316
+ function routerAbEcdsaOwnerOperationDecisionForFailure(input) {
317
+ const reason = (() => {
318
+ switch (input.code) {
319
+ case "wallet_session_missing": return "wallet_session_missing";
320
+ case "wallet_session_expired": return "wallet_session_expired";
321
+ case "wallet_budget_exhausted":
322
+ case "wallet_session_quota_exhausted": return "wallet_session_exhausted";
323
+ case "wallet_session_invalid": return "wallet_session_ended";
324
+ default: return null;
325
+ }
326
+ })();
327
+ if (reason && input.phase === "prepare" && input.stepUp) {
328
+ const decision = {
329
+ kind: "step_up_required",
330
+ reason,
331
+ stepUp: input.stepUp
332
+ };
333
+ return {
334
+ kind: decision.kind,
335
+ reason: decision.reason,
336
+ step_up: decision.stepUp
337
+ };
338
+ }
339
+ if (reason && input.phase === "prepare") return {
340
+ kind: "denied",
341
+ denial: {
342
+ code: "authorization_unavailable",
343
+ message: "Owner operation step-up preparation is unavailable"
344
+ }
345
+ };
346
+ switch (input.code) {
347
+ case "invalid_body": return {
348
+ kind: "denied",
349
+ denial: {
350
+ code: "invalid_operation",
351
+ message: "ECDSA operation request is invalid"
352
+ }
353
+ };
354
+ case "wallet_session_mismatch":
355
+ case "wallet_session_scope_mismatch":
356
+ case "scope_mismatch":
357
+ case "authorization_grant_rejected":
358
+ case "verified_step_up_rejected": return {
359
+ kind: "denied",
360
+ denial: {
361
+ code: "invalid_authority",
362
+ message: "ECDSA operation authority is invalid"
363
+ }
364
+ };
365
+ case "material_mismatch": return {
366
+ kind: "denied",
367
+ denial: {
368
+ code: "inactive_material",
369
+ message: "ECDSA signing material is inactive"
370
+ }
371
+ };
372
+ case "internal":
373
+ case "not_configured": return {
374
+ kind: "denied",
375
+ denial: {
376
+ code: "authorization_unavailable",
377
+ message: "ECDSA operation authorization is unavailable"
378
+ }
379
+ };
380
+ default: return null;
381
+ }
382
+ }
383
+ function routerAbEcdsaOwnerOperationFailureResult(input) {
384
+ const decision = routerAbEcdsaOwnerOperationDecisionForFailure(input);
385
+ return {
386
+ status: input.status,
387
+ body: {
388
+ ok: false,
389
+ code: input.code,
390
+ message: input.message,
391
+ ...decision ? { authorization_decision: decision } : {}
392
+ }
393
+ };
394
+ }
395
+ function routerAbEcdsaReplayUnavailableResult() {
396
+ return routerAbStepUpError(409, "authorized_operation_replay_unavailable", "Completed ECDSA signing operation has no replayable response");
397
+ }
398
+ function routerAbEcdsaRecordedResponse(operation) {
399
+ return operation.lifecycle === "completed" ? operation.response : null;
400
+ }
401
+ function routerAbEcdsaReplayResult(operation) {
402
+ const response = routerAbEcdsaRecordedResponse(operation);
403
+ if (!response) return routerAbEcdsaReplayUnavailableResult();
404
+ let body = response.bodyText;
405
+ try {
406
+ body = JSON.parse(response.bodyText);
407
+ } catch {}
408
+ return {
409
+ status: response.status,
410
+ body
411
+ };
412
+ }
413
+ function routerAbEcdsaReplayHttpResponse(operation) {
414
+ const response = routerAbEcdsaRecordedResponse(operation);
415
+ if (!response) return null;
416
+ return new Response(authorizedOperationReplayBodyInit(response), {
417
+ status: response.status,
418
+ headers: { "content-type": response.contentType }
419
+ });
420
+ }
421
+ function routerAbEcdsaPrivateSigningWorkerUnavailableResult() {
422
+ return {
423
+ status: 501,
424
+ body: {
425
+ ok: false,
426
+ code: "not_configured",
427
+ message: "Router A/B SigningWorker private HTTP target is not configured"
428
+ }
429
+ };
430
+ }
431
+ async function evaluateRouterAbNormalSigningAdmission(input) {
432
+ if (!input.adapter) return {
433
+ ok: false,
434
+ status: 501,
435
+ code: "not_configured",
436
+ message: "Router A/B normal-signing admission adapter is not configured"
437
+ };
438
+ if (input.curve === "ed25519") return await input.adapter.evaluatePolicy({
439
+ curve: "ed25519",
440
+ authorityKind: "wallet_authority_v1",
441
+ authorityId: input.authorityId,
442
+ phase: input.phase,
443
+ walletId: input.walletId,
444
+ thresholdSessionId: input.thresholdSessionId,
445
+ walletSessionId: input.walletSessionId,
446
+ quotaId: input.quotaId,
447
+ requestId: input.requestId,
448
+ expiresAtMs: input.expiresAtMs,
449
+ signingWorkerId: input.signingWorkerId,
450
+ runtimePolicyScope: input.runtimePolicyScope
451
+ });
452
+ return await input.adapter.evaluatePolicy({
453
+ curve: "ecdsa",
454
+ phase: input.phase,
455
+ walletId: input.walletId,
456
+ materialActivationId: requireMpcMaterialActivationId(input.admission.materialActivation.activation_id),
457
+ authorizationIdentity: {
458
+ kind: "reusable_wallet_session",
459
+ walletSessionId: input.walletSessionId
460
+ },
461
+ requestId: input.admission.requestId,
462
+ expiresAtMs: input.admission.expiresAtMs,
463
+ signingWorkerId: input.signingWorkerId,
464
+ keyHandle: input.keyHandle,
465
+ runtimePolicyScope: input.runtimePolicyScope
466
+ });
467
+ }
468
+ function validateRouterAbNormalSigningEffectClaim(claim, scope, authorization) {
469
+ requirePrivateSigningString(claim.authorized_operation_id, "effect_claim.authorized_operation_id");
470
+ requirePrivateSigningString(claim.operation_id, "effect_claim.operation_id");
471
+ requirePrivateSigningString(claim.operation_fingerprint_digest, "effect_claim.operation_fingerprint_digest");
472
+ if (claim.kind === "reusable_wallet_session") {
473
+ requirePrivateSigningString(claim.wallet_session_id, "effect_claim.wallet_session_id");
474
+ if (scope.authorization.kind !== "reusable_wallet_session" || claim.wallet_session_id !== scope.authorization.wallet_session_id) throw new Error("Reusable Wallet Session effect claim does not match request scope");
475
+ return;
476
+ }
477
+ requirePrivateSigningString(claim.authorization_session_id, "effect_claim.authorization_session_id");
478
+ if (scope.authorization.kind !== "operation_step_up" || authorization.kind !== "operation_step_up" || claim.authorization_session_id !== authorization.authorizationSessionId) throw new Error("Operation step-up effect claim does not match request scope");
479
+ }
480
+ function registrationMaterialSourceV1(input) {
481
+ return {
482
+ kind: "registration_activation",
483
+ lookup: {
484
+ account_id: input.accountId,
485
+ material_activation_id: input.materialActivationId,
486
+ signing_worker_id: input.signingWorkerId
487
+ }
488
+ };
489
+ }
490
+ function routerAbNormalSigningMaterialSourceFromActiveLaneV1(input) {
491
+ const groupPublicKey = input.groupPublicKey.trim();
492
+ if (groupPublicKey.length === 0) throw new Error("active lane group public key is required");
493
+ return {
494
+ kind: "rotatable_lane",
495
+ lookup: {
496
+ identity: input.identity,
497
+ admittedLaneIdentityDigestB64u: input.admittedLaneIdentityDigestB64u
498
+ },
499
+ group_public_key: groupPublicKey
500
+ };
501
+ }
502
+ function isPlainObject(value) {
503
+ return !!value && typeof value === "object" && !Array.isArray(value);
504
+ }
505
+ function nonEmptyString(value) {
506
+ return String(value || "").trim();
507
+ }
508
+ function pushU32Be(out, value) {
509
+ out.push(value >>> 24 & 255, value >>> 16 & 255, value >>> 8 & 255, value & 255);
510
+ }
511
+ function pushU64Be(out, value) {
512
+ const encoded = BigInt(value);
513
+ for (let shift = 56n; shift >= 0n; shift -= 8n) out.push(Number(encoded >> shift & 255n));
514
+ }
515
+ function textBytes(value) {
516
+ return new TextEncoder().encode(value);
517
+ }
518
+ function pushLen32(out, bytes) {
519
+ pushU32Be(out, bytes.length);
520
+ for (const byte of bytes) out.push(byte);
521
+ }
522
+ async function sha256B64u(bytes) {
523
+ const buffer = new ArrayBuffer(bytes.byteLength);
524
+ new Uint8Array(buffer).set(bytes);
525
+ const digest = await globalThis.crypto.subtle.digest("SHA-256", buffer);
526
+ return base64UrlEncode(new Uint8Array(digest));
527
+ }
528
+ async function sha256Digest32(bytes) {
529
+ return digest32FromB64u(await sha256B64u(bytes));
530
+ }
531
+ function routerAbSigningError(status, code, message) {
532
+ return {
533
+ ok: false,
534
+ status,
535
+ body: {
536
+ ok: false,
537
+ code,
538
+ message
539
+ }
540
+ };
541
+ }
542
+ function routerAbWalletSessionError(code) {
543
+ const failure = walletSessionFailure(code);
544
+ return routerAbSigningError(walletSessionFailureStatus(code), failure.code, failure.message);
545
+ }
546
+ function routerAbWalletSessionValidationStatus(code) {
547
+ if (code === "sessions_disabled") return 501;
548
+ return walletSessionFailureStatus(code);
549
+ }
550
+ function replayResponseFromSigningWorkerResult(result) {
551
+ if (result.ok) return result.replay;
552
+ return {
553
+ status: result.status,
554
+ contentType: "application/json",
555
+ bodyText: JSON.stringify(result.body)
556
+ };
557
+ }
558
+ function isRouterAbEcdsaSigningWorkerOperationInProgress(result) {
559
+ return !result.ok && result.status === 409 && result.body.message.includes("ReplayedLocalRequest:") && result.body.message.includes("SigningWorker ECDSA effect is already in progress");
560
+ }
561
+ function privateSigningWorkerUrl(config, path) {
562
+ const base = config.signingWorkerBaseUrl.trim().replace(/\/+$/, "");
563
+ if (!base) throw new Error("Router A/B SigningWorker base URL is required");
564
+ return `${base}${path}`;
565
+ }
566
+ function digest32FromB64u(value) {
567
+ const bytes = base64UrlDecode(value);
568
+ if (bytes.length !== 32) throw new Error("Router A/B digest must be 32 bytes");
569
+ return { bytes: Array.from(bytes) };
570
+ }
571
+ function requirePrivateSigningRecord(value, label) {
572
+ if (!isPlainObject(value)) throw new Error(`${label} must be an object`);
573
+ return value;
574
+ }
575
+ function requirePrivateSigningString(value, label) {
576
+ const normalized = nonEmptyString(value);
577
+ if (!normalized) throw new Error(`${label} must be a non-empty string`);
578
+ return normalized;
579
+ }
580
+ function requirePrivateSigningPositiveSafeInteger(value, label) {
581
+ const parsed = Number(value);
582
+ if (!Number.isSafeInteger(parsed) || parsed <= 0) throw new Error(`${label} must be a positive safe integer`);
583
+ return parsed;
584
+ }
585
+ function requirePrivateSigningExactFields(record, expectedFields, label) {
586
+ const actualFields = Object.keys(record).sort();
587
+ const expected = [...expectedFields].sort();
588
+ if (actualFields.length !== expected.length || actualFields.some((field, index) => field !== expected[index])) throw new Error(`${label} has invalid fields`);
589
+ }
590
+ function requirePrivateSigningAuthorization(value) {
591
+ const authorization = requirePrivateSigningRecord(value, "scope.authorization");
592
+ switch (authorization.kind) {
593
+ case "reusable_wallet_session":
594
+ requirePrivateSigningExactFields(authorization, ["kind", "wallet_session_id"], "scope.authorization");
595
+ return {
596
+ kind: "reusable_wallet_session",
597
+ wallet_session_id: requirePrivateSigningString(authorization.wallet_session_id, "scope.authorization.wallet_session_id")
598
+ };
599
+ case "operation_step_up":
600
+ requirePrivateSigningExactFields(authorization, ["kind"], "scope.authorization");
601
+ return { kind: "operation_step_up" };
602
+ default: throw new Error("scope.authorization.kind is invalid");
603
+ }
604
+ }
605
+ function requirePrivateSigningMaterialActivation(value) {
606
+ const activation = requirePrivateSigningRecord(value, "scope.material_activation");
607
+ requirePrivateSigningExactFields(activation, [
608
+ "kind",
609
+ "activation_id",
610
+ "capability",
611
+ "material_owner",
612
+ "key_binding",
613
+ "lifecycle_binding",
614
+ "signing_worker"
615
+ ], "scope.material_activation");
616
+ if (activation.kind !== "mpc_material_activation_ref") throw new Error("scope.material_activation.kind is invalid");
617
+ return {
618
+ kind: "mpc_material_activation_ref",
619
+ activation_id: requireMpcMaterialActivationId(activation.activation_id),
620
+ capability: requirePrivateSigningString(activation.capability, "scope.material_activation.capability"),
621
+ material_owner: requirePrivateSigningString(activation.material_owner, "scope.material_activation.material_owner"),
622
+ key_binding: requirePrivateSigningString(activation.key_binding, "scope.material_activation.key_binding"),
623
+ lifecycle_binding: requirePrivateSigningString(activation.lifecycle_binding, "scope.material_activation.lifecycle_binding"),
624
+ signing_worker: requirePrivateSigningString(activation.signing_worker, "scope.material_activation.signing_worker")
625
+ };
626
+ }
627
+ function requireMpcMaterialActivationId(value) {
628
+ const parsed = parseMpcMaterialActivationId(value);
629
+ if (!parsed.ok) throw new Error(parsed.error.message);
630
+ return parsed.value;
631
+ }
632
+ function parseRouterAbEd25519NormalSigningScopeV2(value) {
633
+ const scope = requirePrivateSigningRecord(value, "scope");
634
+ requirePrivateSigningExactFields(scope, [
635
+ "request_id",
636
+ "account_id",
637
+ "authorization",
638
+ "material_activation",
639
+ "signing_worker_id"
640
+ ], "scope");
641
+ const parsed = {
642
+ request_id: requirePrivateSigningString(scope.request_id, "scope.request_id"),
643
+ account_id: requirePrivateSigningString(scope.account_id, "scope.account_id"),
644
+ authorization: requirePrivateSigningAuthorization(scope.authorization),
645
+ material_activation: requirePrivateSigningMaterialActivation(scope.material_activation),
646
+ signing_worker_id: requirePrivateSigningString(scope.signing_worker_id, "scope.signing_worker_id")
647
+ };
648
+ if (parsed.material_activation.signing_worker !== parsed.signing_worker_id) throw new Error("scope material activation SigningWorker mismatch");
649
+ return parsed;
650
+ }
651
+ function requirePrivateSigningDigest(value, label) {
652
+ const record = requirePrivateSigningRecord(value, label);
653
+ const bytes = Array.isArray(record.bytes) ? record.bytes.map((entry) => Number(entry)) : [];
654
+ if (bytes.length !== 32 || !bytes.every((entry) => Number.isInteger(entry) && entry >= 0 && entry <= 255)) throw new Error(`${label}.bytes must contain exactly 32 bytes`);
655
+ return { bytes };
656
+ }
657
+ function requirePrivateSigningStringArray(value, label) {
658
+ if (!Array.isArray(value)) throw new Error(`${label} must be an array`);
659
+ return value;
660
+ }
661
+ function pushPrivateSigningIntentCommon(out, intent) {
662
+ pushLen32(out, textBytes(requirePrivateSigningString(intent.operation_id, "intent.operation_id")));
663
+ pushLen32(out, textBytes(requirePrivateSigningString(intent.operation_fingerprint, "intent.operation_fingerprint")));
664
+ pushLen32(out, textBytes(requirePrivateSigningString(intent.near_account_id, "intent.near_account_id")));
665
+ pushLen32(out, textBytes(requirePrivateSigningString(intent.near_network_id, "intent.near_network_id")));
666
+ }
667
+ function pushPrivateSigningOptionalString(out, value, label) {
668
+ if (value === void 0 || value === null || value === "") {
669
+ out.push(0);
670
+ return;
671
+ }
672
+ out.push(1);
673
+ pushLen32(out, textBytes(requirePrivateSigningString(value, label)));
674
+ }
675
+ function canonicalPrivateSigningIntentBytes(value) {
676
+ const intent = requirePrivateSigningRecord(value, "intent");
677
+ const kind = requirePrivateSigningString(intent.kind, "intent.kind");
678
+ const out = [];
679
+ pushLen32(out, textBytes(ED25519_SIGNING_INTENT_VERSION_V2));
680
+ pushLen32(out, textBytes(kind));
681
+ pushPrivateSigningIntentCommon(out, intent);
682
+ switch (kind) {
683
+ case "near_transaction_v1": {
684
+ const transactions = requirePrivateSigningStringArray(intent.transactions, "intent.transactions");
685
+ pushU32Be(out, transactions.length);
686
+ for (const [index, transactionValue] of transactions.entries()) {
687
+ const transaction = requirePrivateSigningRecord(transactionValue, `intent.transactions[${index}]`);
688
+ pushLen32(out, textBytes(requirePrivateSigningString(transaction.receiver_id, `intent.transactions[${index}].receiver_id`)));
689
+ pushLen32(out, textBytes(requirePrivateSigningString(transaction.action_fingerprint, `intent.transactions[${index}].action_fingerprint`)));
690
+ }
691
+ pushLen32(out, textBytes(requirePrivateSigningString(intent.unsigned_transaction_borsh_b64u, "intent.unsigned_transaction_borsh_b64u")));
692
+ return Uint8Array.from(out);
693
+ }
694
+ case "nep413_v1":
695
+ pushLen32(out, textBytes(requirePrivateSigningString(intent.recipient, "intent.recipient")));
696
+ pushLen32(out, textBytes(requirePrivateSigningString(intent.message, "intent.message")));
697
+ pushLen32(out, textBytes(requirePrivateSigningString(intent.nonce_b64u, "intent.nonce_b64u")));
698
+ pushPrivateSigningOptionalString(out, intent.callback_url, "intent.callback_url");
699
+ return Uint8Array.from(out);
700
+ case "near_delegate_action_v1": {
701
+ const delegate = requirePrivateSigningRecord(intent.delegate, "intent.delegate");
702
+ for (const field of [
703
+ "sender_id",
704
+ "receiver_id",
705
+ "public_key",
706
+ "nonce",
707
+ "max_block_height",
708
+ "action_fingerprint",
709
+ "canonical_delegate_borsh_b64u"
710
+ ]) pushLen32(out, textBytes(requirePrivateSigningString(delegate[field], `intent.delegate.${field}`)));
711
+ return Uint8Array.from(out);
712
+ }
713
+ default: throw new Error(`intent.kind is unsupported: ${kind}`);
714
+ }
715
+ }
716
+ function privateSigningPayloadPreimage(value) {
717
+ const payload = requirePrivateSigningRecord(value, "signing_payload");
718
+ const kind = requirePrivateSigningString(payload.kind, "signing_payload.kind");
719
+ const expectedDigestB64u = requirePrivateSigningString(payload.expected_signing_digest_b64u, "signing_payload.expected_signing_digest_b64u");
720
+ const out = [];
721
+ pushLen32(out, textBytes(ED25519_SIGNING_PAYLOAD_VERSION_V2));
722
+ pushLen32(out, textBytes(kind));
723
+ let preimageB64u;
724
+ switch (kind) {
725
+ case "near_unsigned_transaction_borsh_v1":
726
+ preimageB64u = requirePrivateSigningString(payload.unsigned_transaction_borsh_b64u, "signing_payload.unsigned_transaction_borsh_b64u");
727
+ break;
728
+ case "nep413_message_v1":
729
+ preimageB64u = requirePrivateSigningString(payload.canonical_message_b64u, "signing_payload.canonical_message_b64u");
730
+ break;
731
+ case "near_delegate_action_v1":
732
+ preimageB64u = requirePrivateSigningString(payload.canonical_delegate_borsh_b64u, "signing_payload.canonical_delegate_borsh_b64u");
733
+ break;
734
+ default: throw new Error(`signing_payload.kind is unsupported: ${kind}`);
735
+ }
736
+ pushLen32(out, textBytes(preimageB64u));
737
+ pushLen32(out, textBytes(expectedDigestB64u));
738
+ return {
739
+ canonical: Uint8Array.from(out),
740
+ preimage: base64UrlDecode(preimageB64u),
741
+ expectedDigest: digest32FromB64u(expectedDigestB64u)
742
+ };
743
+ }
744
+ function privateSigningDigestsEqual(left, right) {
745
+ return left.bytes.every((byte, index) => byte === right.bytes[index]);
746
+ }
747
+ async function privateSigningAdmissionMaterial(input) {
748
+ const payload = privateSigningPayloadPreimage(input.signingPayload);
749
+ const [intentDigest, signingPayloadDigest, admittedSigningDigest] = await Promise.all([
750
+ sha256Digest32(canonicalPrivateSigningIntentBytes(input.intent)),
751
+ sha256Digest32(payload.canonical),
752
+ sha256Digest32(payload.preimage)
753
+ ]);
754
+ if (!privateSigningDigestsEqual(admittedSigningDigest, payload.expectedDigest)) throw new Error("signing_payload expected signing digest does not match its preimage");
755
+ return {
756
+ intentDigest,
757
+ signingPayloadDigest,
758
+ admittedSigningDigest
759
+ };
760
+ }
761
+ async function computeRouterAbEd25519NormalSigningAdmissionMaterial(input) {
762
+ return await privateSigningAdmissionMaterial(input);
763
+ }
764
+ async function privateSigningRound1BindingDigest(input) {
765
+ const out = [];
766
+ pushLen32(out, textBytes(ED25519_ROUND1_BINDING_VERSION_V2));
767
+ pushLen32(out, textBytes(input.scope.request_id));
768
+ pushLen32(out, textBytes(input.scope.account_id));
769
+ switch (input.scope.authorization.kind) {
770
+ case "reusable_wallet_session":
771
+ pushLen32(out, textBytes("reusable_wallet_session"));
772
+ pushLen32(out, textBytes(input.scope.authorization.wallet_session_id));
773
+ break;
774
+ case "operation_step_up":
775
+ pushLen32(out, textBytes("operation_step_up"));
776
+ break;
777
+ }
778
+ pushLen32(out, textBytes("mpc_material_activation_ref"));
779
+ pushLen32(out, textBytes(input.scope.material_activation.activation_id));
780
+ pushLen32(out, textBytes(input.scope.material_activation.capability));
781
+ pushLen32(out, textBytes(input.scope.material_activation.material_owner));
782
+ pushLen32(out, textBytes(input.scope.material_activation.key_binding));
783
+ pushLen32(out, textBytes(input.scope.material_activation.lifecycle_binding));
784
+ pushLen32(out, textBytes(input.scope.material_activation.signing_worker));
785
+ pushLen32(out, textBytes(input.scope.signing_worker_id));
786
+ pushU64Be(out, input.expiresAtMs);
787
+ out.push(...input.displayDigest.bytes, ...input.intentDigest.bytes, ...input.signingPayloadDigest.bytes, ...input.admittedSigningDigest.bytes);
788
+ return sha256Digest32(Uint8Array.from(out));
789
+ }
790
+ function normalizedPrivateSigningHeader(headers, name) {
791
+ const entry = Object.entries(headers).find(([key]) => key.toLowerCase() === name);
792
+ if (!entry) return "";
793
+ return Array.isArray(entry[1]) ? entry[1].join(",") : String(entry[1] || "").trim();
794
+ }
795
+ async function privateSigningTrustedSourceDigest(headers) {
796
+ const out = Array.from(textBytes(ED25519_TRUSTED_SOURCE_VERSION_V2));
797
+ for (const name of ["cf-connecting-ip"]) {
798
+ const nameBytes = textBytes(name);
799
+ const valueBytes = textBytes(normalizedPrivateSigningHeader(headers, name));
800
+ pushU64Be(out, nameBytes.length);
801
+ out.push(...nameBytes);
802
+ pushU64Be(out, valueBytes.length);
803
+ out.push(...valueBytes);
804
+ }
805
+ return sha256Digest32(Uint8Array.from(out));
806
+ }
807
+ function privateSigningTrustedAdmission(input) {
808
+ return {
809
+ metadata: {
810
+ org_id: input.runtimePolicyScope.orgId,
811
+ project_id: input.runtimePolicyScope.projectId,
812
+ environment: input.runtimePolicyScope.envId,
813
+ account_id: input.accountId,
814
+ auth: input.authorization.kind === "reusable_wallet_session" ? {
815
+ auth: "owner_wallet_session",
816
+ subject_id: input.subjectId,
817
+ wallet_session_id: input.authorization.walletSessionId
818
+ } : {
819
+ auth: "owner_operation_step_up",
820
+ subject_id: input.subjectId,
821
+ authorization_session_id: input.authorization.authorizationSessionId
822
+ },
823
+ trusted_source_digest: input.trustedSourceDigest,
824
+ intent_digest: input.intentDigest
825
+ },
826
+ decision: {
827
+ kind: "accepted",
828
+ request_id: input.requestId
829
+ }
830
+ };
831
+ }
832
+ function privateSigningAuthorizationContextFromAuthorization(authorization) {
833
+ switch (authorization.kind) {
834
+ case "wallet_session_operation_credential_v1": return {
835
+ kind: "reusable_wallet_session",
836
+ runtimePolicyScope: authorization.runtimePolicyScope,
837
+ subjectId: authorization.principalId,
838
+ walletSessionId: authorization.walletSessionId
839
+ };
840
+ case "operation_step_up": return {
841
+ kind: "operation_step_up",
842
+ runtimePolicyScope: authorization.session.runtimePolicyScope,
843
+ subjectId: authorization.session.principalId,
844
+ authorizationSessionId: authorization.session.sessionId
845
+ };
846
+ }
847
+ }
848
+ function validatePrivateSigningAuthorizationContext(authorization, context) {
849
+ if (authorization.kind !== context.kind) throw new Error("Router A/B private authorization branch does not match request");
850
+ if (authorization.kind === "reusable_wallet_session" && context.kind === "reusable_wallet_session" && authorization.wallet_session_id !== context.walletSessionId) throw new Error("Router A/B private Wallet Session does not match request");
851
+ }
852
+ function privateSigningAuthorizationContext(scope, authorization) {
853
+ const context = privateSigningAuthorizationContextFromAuthorization(authorization);
854
+ if (context.kind === "reusable_wallet_session" && scope.authorization.kind === "reusable_wallet_session") {
855
+ if (scope.authorization.wallet_session_id !== context.walletSessionId) throw new Error("Router A/B Ed25519 scope authorization does not match exact session");
856
+ return context;
857
+ }
858
+ if (context.kind === "operation_step_up" && authorization.kind === "operation_step_up" && scope.authorization.kind === "operation_step_up") {
859
+ if (scope.account_id !== authorization.session.walletId || scope.material_activation.material_owner !== authorization.session.walletId) throw new Error("Router A/B Ed25519 step-up scope does not match the wallet authorization");
860
+ return context;
861
+ }
862
+ throw new Error("Router A/B Ed25519 authorization branch does not match verified binding");
863
+ }
864
+ async function buildRouterAbEd25519PrivateSigningWorkerBody(input) {
865
+ const scope = parseRouterAbEd25519NormalSigningScopeV2(input.body.scope);
866
+ const signingContext = privateSigningAuthorizationContext(scope, input.authorization);
867
+ const trustedSourceDigest = await privateSigningTrustedSourceDigest(input.headers);
868
+ if (input.phase === "finalize") {
869
+ validateRouterAbNormalSigningEffectClaim(input.effectClaim, scope, signingContext);
870
+ const prepareBinding = requirePrivateSigningRecord(input.body.prepare_binding, "prepare_binding");
871
+ const intentDigest = requirePrivateSigningDigest(prepareBinding.intent_digest, "prepare_binding.intent_digest");
872
+ const signingPayloadDigest = requirePrivateSigningDigest(prepareBinding.signing_payload_digest, "prepare_binding.signing_payload_digest");
873
+ const round1BindingDigest = requirePrivateSigningDigest(prepareBinding.round1_binding_digest, "prepare_binding.round1_binding_digest");
874
+ const expiresAtMs = requirePrivateSigningPositiveSafeInteger(input.body.expires_at_ms, "expires_at_ms");
875
+ return {
876
+ request: input.body,
877
+ admission_candidate: {
878
+ org_id: signingContext.runtimePolicyScope.orgId,
879
+ project_id: signingContext.runtimePolicyScope.projectId,
880
+ environment: signingContext.runtimePolicyScope.envId,
881
+ account_id: scope.account_id,
882
+ subject_id: signingContext.subjectId,
883
+ authorization: signingContext.kind === "reusable_wallet_session" ? {
884
+ kind: "reusable_wallet_session",
885
+ wallet_session_id: signingContext.walletSessionId
886
+ } : {
887
+ kind: "operation_step_up",
888
+ authorization_session_id: signingContext.authorizationSessionId
889
+ },
890
+ signing_worker_id: scope.signing_worker_id,
891
+ request_id: scope.request_id,
892
+ intent_digest: intentDigest,
893
+ signing_payload_digest: signingPayloadDigest,
894
+ round1_binding_digest: round1BindingDigest,
895
+ trusted_source_digest: trustedSourceDigest,
896
+ expires_at_ms: expiresAtMs
897
+ },
898
+ trusted_admission: privateSigningTrustedAdmission({
899
+ runtimePolicyScope: signingContext.runtimePolicyScope,
900
+ subjectId: signingContext.subjectId,
901
+ accountId: scope.account_id,
902
+ authorization: signingContext,
903
+ requestId: scope.request_id,
904
+ intentDigest,
905
+ trustedSourceDigest
906
+ }),
907
+ effect_claim: input.effectClaim,
908
+ material_source: input.materialSource ?? registrationMaterialSourceV1({
909
+ accountId: scope.account_id,
910
+ materialActivationId: scope.material_activation.activation_id,
911
+ signingWorkerId: scope.signing_worker_id
912
+ })
913
+ };
914
+ }
915
+ const expiresAtMs = requirePrivateSigningPositiveSafeInteger(input.body.expires_at_ms, "expires_at_ms");
916
+ const material = await privateSigningAdmissionMaterial({
917
+ intent: input.body.intent,
918
+ signingPayload: input.body.signing_payload
919
+ });
920
+ const round1BindingDigest = await privateSigningRound1BindingDigest({
921
+ scope,
922
+ expiresAtMs,
923
+ displayDigest: requirePrivateSigningDigest(input.body.display_digest, "display_digest"),
924
+ ...material
925
+ });
926
+ const trustedAdmission = privateSigningTrustedAdmission({
927
+ runtimePolicyScope: signingContext.runtimePolicyScope,
928
+ subjectId: signingContext.subjectId,
929
+ accountId: scope.account_id,
930
+ authorization: signingContext,
931
+ requestId: scope.request_id,
932
+ intentDigest: material.intentDigest,
933
+ trustedSourceDigest
934
+ });
935
+ return {
936
+ scope,
937
+ expires_at_ms: expiresAtMs,
938
+ admission_candidate: {
939
+ org_id: signingContext.runtimePolicyScope.orgId,
940
+ project_id: signingContext.runtimePolicyScope.projectId,
941
+ environment: signingContext.runtimePolicyScope.envId,
942
+ account_id: scope.account_id,
943
+ subject_id: signingContext.subjectId,
944
+ authorization: signingContext.kind === "reusable_wallet_session" ? {
945
+ kind: "reusable_wallet_session",
946
+ wallet_session_id: signingContext.walletSessionId
947
+ } : {
948
+ kind: "operation_step_up",
949
+ authorization_session_id: signingContext.authorizationSessionId
950
+ },
951
+ signing_worker_id: scope.signing_worker_id,
952
+ request_id: scope.request_id,
953
+ intent_digest: material.intentDigest,
954
+ signing_payload_digest: material.signingPayloadDigest,
955
+ admitted_signing_digest: material.admittedSigningDigest,
956
+ round1_binding_digest: round1BindingDigest,
957
+ trusted_source_digest: trustedSourceDigest,
958
+ expires_at_ms: expiresAtMs
959
+ },
960
+ trusted_admission: trustedAdmission,
961
+ material_source: input.materialSource ?? registrationMaterialSourceV1({
962
+ accountId: scope.account_id,
963
+ materialActivationId: scope.material_activation.activation_id,
964
+ signingWorkerId: scope.signing_worker_id
965
+ })
966
+ };
967
+ }
968
+ async function buildRouterAbEcdsaDerivationPrivateSigningWorkerBody(input) {
969
+ const signingContext = privateSigningAuthorizationContextFromAuthorization(input.authorization);
970
+ const trustedSourceDigest = await privateSigningTrustedSourceDigest(input.headers);
971
+ if (input.phase === "prepare") {
972
+ const request = parseRouterAbEcdsaDerivationEvmDigestSigningRequestV1(input.body);
973
+ validatePrivateSigningAuthorizationContext(request.authorization, signingContext);
974
+ const requestDigest = await routerAbEcdsaDerivationEvmDigestSigningRequestDigestV1(request);
975
+ return {
976
+ request,
977
+ trusted_admission: privateSigningTrustedAdmission({
978
+ runtimePolicyScope: signingContext.runtimePolicyScope,
979
+ subjectId: signingContext.subjectId,
980
+ accountId: request.scope.wallet_id,
981
+ authorization: signingContext,
982
+ requestId: request.request_id,
983
+ intentDigest: requestDigest,
984
+ trustedSourceDigest
985
+ }),
986
+ material_source: input.materialSource ?? registrationMaterialSourceV1({
987
+ accountId: request.scope.wallet_id,
988
+ materialActivationId: request.scope.material_activation.activation_id,
989
+ signingWorkerId: request.scope.signing_worker.server_id
990
+ })
991
+ };
992
+ }
993
+ const request = parseRouterAbEcdsaDerivationEvmDigestSigningFinalizeRequestV1(input.body);
994
+ validatePrivateSigningAuthorizationContext(request.authorization, signingContext);
995
+ const requestDigest = await routerAbEcdsaDerivationEvmDigestSigningFinalizeCoreRequestDigestV1(request);
996
+ return {
997
+ request,
998
+ trusted_admission: privateSigningTrustedAdmission({
999
+ runtimePolicyScope: signingContext.runtimePolicyScope,
1000
+ subjectId: signingContext.subjectId,
1001
+ accountId: request.scope.wallet_id,
1002
+ authorization: signingContext,
1003
+ requestId: request.request_id,
1004
+ intentDigest: requestDigest,
1005
+ trustedSourceDigest
1006
+ }),
1007
+ material_source: input.materialSource ?? registrationMaterialSourceV1({
1008
+ accountId: request.scope.wallet_id,
1009
+ materialActivationId: request.scope.material_activation.activation_id,
1010
+ signingWorkerId: request.scope.signing_worker.server_id
1011
+ })
1012
+ };
1013
+ }
1014
+ async function handleRouterAbEd25519OperationStepUpRoute(input) {
1015
+ if (input.scope.authorization.kind !== "operation_step_up") return routerAbStepUpError(400, "invalid_body", "Operation step-up authority is required");
1016
+ const expiresAtMs = Number(input.body.expires_at_ms);
1017
+ if (!Number.isSafeInteger(expiresAtMs) || expiresAtMs <= Date.now()) return routerAbStepUpError(408, "expired_request", "Router A/B Ed25519 step-up request is expired");
1018
+ let authenticated = await authenticateRouterAbWalletOperationStepUp({
1019
+ headers: input.headers,
1020
+ scope: input.scope,
1021
+ operationKind: input.operationKind,
1022
+ requestExpiresAtMs: expiresAtMs,
1023
+ authorizedOperations: input.authorizedOperations,
1024
+ authorizationSessions: input.authorizationSessions,
1025
+ resolveEd25519MaterialActivation: input.resolveEd25519MaterialActivation
1026
+ });
1027
+ if (!authenticated.ok && input.authorizedOperations && input.authorizationSessions && isWalletSessionUnavailableStepUpError(authenticated.error)) {
1028
+ const exhaustedCandidate = await resolveRouterAbEd25519ExhaustedCandidateOperationStepUpAuthentication({
1029
+ headers: input.headers,
1030
+ scope: input.scope,
1031
+ operationKind: input.operationKind,
1032
+ requestExpiresAtMs: expiresAtMs,
1033
+ authorizedOperations: input.authorizedOperations,
1034
+ authorizationSessions: input.authorizationSessions,
1035
+ resolveEd25519MaterialActivation: input.resolveEd25519MaterialActivation
1036
+ });
1037
+ if (exhaustedCandidate) {
1038
+ if (!exhaustedCandidate.ok) return exhaustedCandidate.error;
1039
+ authenticated = exhaustedCandidate;
1040
+ }
1041
+ }
1042
+ if (!authenticated.ok) return authenticated.error;
1043
+ const activeMaterial = "activeMaterial" in authenticated ? authenticated.activeMaterial : await input.resolveEd25519MaterialActivation({
1044
+ walletId: authenticated.session.walletId,
1045
+ materialActivation: input.scope.material_activation
1046
+ });
1047
+ if (!activeMaterial.ok) return routerAbStepUpError(activeMaterial.code === "internal" ? 500 : 403, activeMaterial.code === "internal" ? "internal" : "scope_mismatch", activeMaterial.code === "internal" ? activeMaterial.message : "Operation step-up material is no longer active");
1048
+ if (!sameRouterAbMpcMaterialActivationRef(activeMaterial.materialActivation, input.scope.material_activation)) return routerAbStepUpError(403, "scope_mismatch", "Operation step-up scope does not name the active material");
1049
+ if (input.phase === "prepare") {
1050
+ let privateBody;
1051
+ try {
1052
+ privateBody = await buildRouterAbEd25519PrivateSigningWorkerBody({
1053
+ phase: "prepare",
1054
+ body: input.body,
1055
+ authorization: {
1056
+ kind: "operation_step_up",
1057
+ session: authenticated.session
1058
+ },
1059
+ headers: input.headers
1060
+ });
1061
+ } catch (error) {
1062
+ return routerAbStepUpError(400, "invalid_body", errorMessage(error));
1063
+ }
1064
+ const operation = parseRouterAbOperationStepUpOperation(input.body.intent);
1065
+ if (!operation.ok) return routerAbStepUpError(400, "invalid_body", operation.message);
1066
+ let authorizedOperationId;
1067
+ let capabilityId;
1068
+ let laneDigest;
1069
+ let intentDigest;
1070
+ let displayDigest;
1071
+ try {
1072
+ authorizedOperationId = requireAuthorizationValue(parseAuthorizedOperationId(`normal-signing-operation:${input.scope.request_id}`));
1073
+ capabilityId = requireAuthorizationValue(parseCapabilityId(input.scope.material_activation.capability));
1074
+ if (!("admission_candidate" in privateBody)) throw new Error("Router A/B step-up prepare admission is missing");
1075
+ laneDigest = parseSigningOperationFingerprintDigest(input.body.intent.operation_fingerprint);
1076
+ intentDigest = parseDigestB64u(base64UrlEncode(Uint8Array.from(privateBody.admission_candidate.intent_digest.bytes)));
1077
+ displayDigest = parseDigestB64u(base64UrlEncode(Uint8Array.from(requirePrivateSigningDigest(input.body.display_digest, "display_digest").bytes)));
1078
+ } catch (error) {
1079
+ return routerAbStepUpError(400, "invalid_body", errorMessage(error));
1080
+ }
1081
+ const operationFingerprintDigest = await computeCapabilityOperationFingerprintDigest(buildCapabilityOperationEnvelope({
1082
+ tenantId: authenticated.session.tenantId,
1083
+ principalId: authenticated.session.principalId,
1084
+ capabilityId,
1085
+ operationId: operation.operationId,
1086
+ operation: operation.operation,
1087
+ digests: {
1088
+ laneDigest,
1089
+ intentDigest,
1090
+ displayDigest
1091
+ }
1092
+ }));
1093
+ const existing = await authenticated.authorizedOperations.readAuthorizedOperation({
1094
+ tenantId: authenticated.session.tenantId,
1095
+ operationFingerprintDigest
1096
+ });
1097
+ if (!existing || existing.authorizedOperationId !== authorizedOperationId) return routerAbStepUpError(409, "authorized_operation_missing", "Authorized operation is unavailable");
1098
+ if (existing.authorization.kind !== "verified_step_up" || existing.quota.kind !== "quota_neutral") return routerAbStepUpError(409, "authorized_operation_missing", "Operation authorization has an invalid source or quota");
1099
+ let claimResult;
1100
+ try {
1101
+ claimResult = await authenticated.authorizedOperations.admitAuthorizedOperation({ operation: {
1102
+ tenantId: existing.tenantId,
1103
+ authorizedOperationId: existing.authorizedOperationId,
1104
+ auditEventId: existing.auditEventId,
1105
+ operation: existing.operation,
1106
+ authorization: existing.authorization,
1107
+ quota: existing.quota,
1108
+ claimedAtMs: Date.now()
1109
+ } });
1110
+ } catch (error) {
1111
+ return routerAbStepUpError(400, "invalid_body", errorMessage(error));
1112
+ }
1113
+ const claimFailure = routerAbOperationStepUpClaimFailure(claimResult);
1114
+ if (claimFailure) return claimFailure;
1115
+ if (claimResult.kind !== "claimed" && claimResult.kind !== "operation_in_progress" && claimResult.kind !== "replayed") return routerAbStepUpError(409, "authorized_operation_missing", "Authorized operation is unavailable");
1116
+ return {
1117
+ phase: "prepare",
1118
+ session: authenticated.session,
1119
+ operation: claimResult.operation,
1120
+ operationDigests: {
1121
+ laneDigest,
1122
+ intentDigest,
1123
+ displayDigest
1124
+ },
1125
+ admissionKind: claimResult.kind
1126
+ };
1127
+ }
1128
+ return {
1129
+ phase: "finalize",
1130
+ session: authenticated.session
1131
+ };
1132
+ }
1133
+ async function resolveRouterAbEd25519OperationStepUpSession(input) {
1134
+ const admittedMaterialActivation = routerAbMpcMaterialActivationRefToWire(input.admission.materialActivation);
1135
+ if (input.admission.operationKind !== input.operationKind || String(input.session.walletId) !== input.walletId || input.materialOwner !== input.walletId || !Number.isSafeInteger(input.requestExpiresAtMs) || input.requestExpiresAtMs > input.session.expiresAtMs || !sameRouterAbMpcMaterialActivationRef(admittedMaterialActivation, input.materialActivation)) return {
1136
+ ok: false,
1137
+ error: routerAbStepUpError(403, "scope_mismatch", "Wallet Session scope is invalid")
1138
+ };
1139
+ let activeMaterial;
1140
+ try {
1141
+ activeMaterial = await input.resolveEd25519MaterialActivation({
1142
+ walletId: input.walletId,
1143
+ materialActivation: admittedMaterialActivation
1144
+ });
1145
+ } catch {
1146
+ return {
1147
+ ok: false,
1148
+ error: routerAbStepUpError(503, "wallet_session_unavailable", "Wallet Session is unavailable")
1149
+ };
1150
+ }
1151
+ if (!activeMaterial.ok || !sameRouterAbMpcMaterialActivationRef(activeMaterial.materialActivation, admittedMaterialActivation) || !sameRouterAbMpcMaterialActivationRef(activeMaterial.exportIdentity.scope.material_activation, admittedMaterialActivation) || activeMaterial.exportIdentity.scope.account_id !== input.walletId || activeMaterial.exportIdentity.application_binding.wallet_id !== input.walletId || base64UrlEncode(Uint8Array.from(activeMaterial.exportIdentity.registered_public_key)) !== input.admission.signer.registeredPublicKeyB64u) return {
1152
+ ok: false,
1153
+ error: routerAbStepUpError(activeMaterial.ok || activeMaterial.code !== "internal" ? 403 : 503, activeMaterial.ok || activeMaterial.code !== "internal" ? "scope_mismatch" : "wallet_session_unavailable", activeMaterial.ok ? "Wallet Session material does not match the active Ed25519 material" : activeMaterial.message)
1154
+ };
1155
+ if (input.session.tenantId !== input.authorizedOperations.tenantId || activeMaterial.runtimePolicyScope.orgId !== input.session.tenantId || input.session.expiresAtMs <= Date.now()) return {
1156
+ ok: false,
1157
+ error: routerAbStepUpError(403, "scope_mismatch", "Wallet Session scope is invalid")
1158
+ };
1159
+ return {
1160
+ ok: true,
1161
+ activeMaterial,
1162
+ session: {
1163
+ tenantId: input.session.tenantId,
1164
+ principalId: input.session.principalId,
1165
+ sessionId: String(input.session.authorizationId),
1166
+ walletId: String(input.session.walletId),
1167
+ runtimePolicyScope: activeMaterial.runtimePolicyScope,
1168
+ laneAuthorization: {
1169
+ kind: "wallet_auth_method",
1170
+ walletAuthMethodId: input.session.walletAuthMethodId
1171
+ }
1172
+ }
1173
+ };
1174
+ }
1175
+ async function resolveRouterAbEd25519ExhaustedCandidateOperationStepUpAuthentication(input) {
1176
+ const token = extractBearerCredential(input.headers);
1177
+ if (!token) return null;
1178
+ const requestOriginRaw = (Array.isArray(input.headers.origin) ? input.headers.origin[0] : input.headers.origin) || "";
1179
+ let requestOrigin;
1180
+ try {
1181
+ requestOrigin = parseSessionOrigin(String(requestOriginRaw).trim());
1182
+ } catch {
1183
+ return {
1184
+ ok: false,
1185
+ error: routerAbStepUpError(401, "unauthorized", "Wallet owner proof origin is invalid")
1186
+ };
1187
+ }
1188
+ let candidate;
1189
+ try {
1190
+ candidate = await input.authorizationSessions.readExhaustedWalletSessionAuthorizationV2CandidateByOperationCredential({
1191
+ tenantId: input.authorizationSessions.tenantId,
1192
+ token,
1193
+ nowMs: Date.now()
1194
+ });
1195
+ } catch {
1196
+ return {
1197
+ ok: false,
1198
+ error: routerAbStepUpError(503, "wallet_session_unavailable", "Wallet Session is unavailable")
1199
+ };
1200
+ }
1201
+ if (!candidate) return null;
1202
+ const session = candidate.status.session;
1203
+ const admission = resolveWalletSessionAuthorizationV2Admission({
1204
+ authorization: session,
1205
+ authority: candidate.authority,
1206
+ authMethod: candidate.authMethod,
1207
+ operation: {
1208
+ tenantId: session.tenantId,
1209
+ principalId: session.principalId,
1210
+ walletId: session.walletId,
1211
+ keyFamily: "ed25519",
1212
+ operationKind: input.operationKind
1213
+ },
1214
+ retiredAtMs: candidate.retiredAtMs,
1215
+ nowMs: Date.now()
1216
+ });
1217
+ if (!admission.ok || admission.keyFamily !== "ed25519") return {
1218
+ ok: false,
1219
+ error: routerAbStepUpError(403, "scope_mismatch", "Wallet Session scope is invalid")
1220
+ };
1221
+ const resolved = await resolveRouterAbEd25519OperationStepUpSession({
1222
+ walletId: input.scope.account_id,
1223
+ materialOwner: input.scope.material_activation.material_owner,
1224
+ materialActivation: input.scope.material_activation,
1225
+ requestExpiresAtMs: input.requestExpiresAtMs,
1226
+ operationKind: input.operationKind,
1227
+ authorizedOperations: input.authorizedOperations,
1228
+ session,
1229
+ admission,
1230
+ resolveEd25519MaterialActivation: input.resolveEd25519MaterialActivation
1231
+ });
1232
+ if (!resolved.ok) return resolved;
1233
+ return {
1234
+ ok: true,
1235
+ kind: "wallet_session_operation_credential_exhausted_candidate_v1",
1236
+ authorizedOperations: input.authorizedOperations,
1237
+ candidate,
1238
+ activeMaterial: resolved.activeMaterial,
1239
+ session: resolved.session,
1240
+ requestOrigin,
1241
+ expiresAtMs: session.expiresAtMs
1242
+ };
1243
+ }
1244
+ function isWalletSessionUnavailableStepUpError(result) {
1245
+ return isPlainObject(result.body) && result.body.code === "wallet_session_unavailable";
1246
+ }
1247
+ async function authenticateRouterAbWalletOperationStepUpIdentity(input) {
1248
+ if (!input.authorizedOperations) return {
1249
+ ok: false,
1250
+ error: routerAbStepUpError(501, "not_configured", "Router A/B operation step-up authorization is not configured")
1251
+ };
1252
+ const requestOriginRaw = (Array.isArray(input.headers.origin) ? input.headers.origin[0] : input.headers.origin) || "";
1253
+ let requestOrigin;
1254
+ try {
1255
+ requestOrigin = parseSessionOrigin(String(requestOriginRaw).trim());
1256
+ } catch {
1257
+ return {
1258
+ ok: false,
1259
+ error: routerAbStepUpError(401, "unauthorized", "Wallet owner proof origin is invalid")
1260
+ };
1261
+ }
1262
+ if (input.kind === "verified_owner_proof") {
1263
+ const tenantId = input.authorizedOperations.tenantId;
1264
+ const authorityRef = await walletAuthAuthorityRef({ authority: input.authority });
1265
+ const principal = parsePrincipalId(input.authority.factor.kind === "email_otp" ? input.authority.factor.providerUserId : input.walletId);
1266
+ const authSource = walletExecutionLaneAuthSourceFromAuthority(input.authority);
1267
+ if (!principal.ok || !authSource || input.walletId !== input.materialOwner || input.authority.walletId !== input.walletId || input.runtimePolicyScope.orgId !== tenantId || input.expiresAtMs <= Date.now()) return {
1268
+ ok: false,
1269
+ error: routerAbStepUpError(403, "scope_mismatch", "Wallet owner proof scope is invalid")
1270
+ };
1271
+ return {
1272
+ ok: true,
1273
+ authorizedOperations: input.authorizedOperations,
1274
+ session: {
1275
+ tenantId,
1276
+ principalId: principal.value,
1277
+ sessionId: input.operationId,
1278
+ walletId: input.walletId,
1279
+ runtimePolicyScope: input.runtimePolicyScope,
1280
+ laneAuthorization: {
1281
+ kind: "authority_ref",
1282
+ authorityRef,
1283
+ authSource
1284
+ }
1285
+ },
1286
+ authorityRef,
1287
+ requestOrigin,
1288
+ expiresAtMs: input.expiresAtMs
1289
+ };
1290
+ }
1291
+ if (!input.authorizationSessions) return {
1292
+ ok: false,
1293
+ error: routerAbStepUpError(501, "not_configured", "Router A/B Wallet Sessions are not configured")
1294
+ };
1295
+ const token = extractBearerCredential(input.headers);
1296
+ if (!token) return {
1297
+ ok: false,
1298
+ error: routerAbStepUpError(401, "unauthorized", "Wallet Session is required")
1299
+ };
1300
+ let resolution;
1301
+ try {
1302
+ const operation = input.keyFamily === "ed25519" ? {
1303
+ keyFamily: "ed25519",
1304
+ operationKind: input.operationKind
1305
+ } : {
1306
+ keyFamily: "ecdsa_secp256k1",
1307
+ operationKind: input.operationKind
1308
+ };
1309
+ resolution = await resolveWalletSessionOperationCredentialAdmission({
1310
+ authorizationSessions: input.authorizationSessions,
1311
+ token,
1312
+ nowMs: Date.now(),
1313
+ operation
1314
+ });
1315
+ } catch {
1316
+ return {
1317
+ ok: false,
1318
+ error: routerAbStepUpError(503, "wallet_session_unavailable", "Wallet Session is unavailable")
1319
+ };
1320
+ }
1321
+ if (resolution.kind === "not_found") return {
1322
+ ok: false,
1323
+ error: routerAbStepUpError(401, "unauthorized", "Wallet Session is invalid")
1324
+ };
1325
+ if (resolution.kind === "rejected") return {
1326
+ ok: false,
1327
+ error: routerAbStepUpError(403, "scope_mismatch", "Wallet Session scope is invalid")
1328
+ };
1329
+ const admission = resolution.admission;
1330
+ const session = admission.context.authorization.session;
1331
+ const admittedMaterialActivation = routerAbMpcMaterialActivationRefToWire(admission.admission.materialActivation);
1332
+ if (admission.curve === "ed25519" && input.keyFamily === "ed25519") {
1333
+ const resolved = await resolveRouterAbEd25519OperationStepUpSession({
1334
+ walletId: input.walletId,
1335
+ materialOwner: input.materialOwner,
1336
+ materialActivation: input.materialActivation,
1337
+ requestExpiresAtMs: input.requestExpiresAtMs,
1338
+ operationKind: input.operationKind,
1339
+ authorizedOperations: input.authorizedOperations,
1340
+ session,
1341
+ admission: admission.admission,
1342
+ resolveEd25519MaterialActivation: input.resolveEd25519MaterialActivation
1343
+ });
1344
+ if (!resolved.ok) return {
1345
+ ok: false,
1346
+ error: resolved.error
1347
+ };
1348
+ return {
1349
+ ok: true,
1350
+ authorizedOperations: input.authorizedOperations,
1351
+ session: resolved.session,
1352
+ requestOrigin,
1353
+ expiresAtMs: session.expiresAtMs
1354
+ };
1355
+ }
1356
+ if (admission.admission.keyFamily !== input.keyFamily || admission.admission.operationKind !== input.operationKind || String(session.walletId) !== input.walletId || input.materialOwner !== input.walletId || !Number.isSafeInteger(input.requestExpiresAtMs) || input.requestExpiresAtMs > session.expiresAtMs || !sameRouterAbMpcMaterialActivationRef(admittedMaterialActivation, input.materialActivation)) return {
1357
+ ok: false,
1358
+ error: routerAbStepUpError(403, "scope_mismatch", "Wallet Session scope is invalid")
1359
+ };
1360
+ let runtimePolicyScope;
1361
+ try {
1362
+ if (admission.curve === "ecdsa" && input.keyFamily === "ecdsa_secp256k1") {
1363
+ const activeMaterial = await input.resolveEcdsaMaterialActivation({
1364
+ walletId: input.walletId,
1365
+ materialActivation: admittedMaterialActivation
1366
+ });
1367
+ const normalSigning = activeMaterial.ok ? activeMaterial.routerAbEcdsaDerivationNormalSigning : null;
1368
+ if (!activeMaterial.ok || !normalSigning || !sameRouterAbMpcMaterialActivationRef(activeMaterial.materialActivation, admittedMaterialActivation) || !sameRouterAbMpcMaterialActivationRef(normalSigning.scope.material_activation, admittedMaterialActivation) || normalSigning.scope.wallet_id !== input.walletId || normalSigning.scope.public_identity.threshold_public_key33_b64u !== admission.admission.signer.thresholdPublicKey33B64u || normalSigning.scope.public_identity.ethereum_address20_b64u !== evmAddress20B64u(admission.admission.signer.evmAddress)) return {
1369
+ ok: false,
1370
+ error: routerAbStepUpError(activeMaterial.ok || activeMaterial.code !== "internal" ? 403 : 503, activeMaterial.ok || activeMaterial.code !== "internal" ? "scope_mismatch" : "wallet_session_unavailable", activeMaterial.ok ? "Wallet Session material does not match the active ECDSA material" : activeMaterial.message)
1371
+ };
1372
+ runtimePolicyScope = activeMaterial.runtimePolicyScope;
1373
+ } else return {
1374
+ ok: false,
1375
+ error: routerAbStepUpError(403, "scope_mismatch", "Wallet Session family is invalid")
1376
+ };
1377
+ } catch {
1378
+ return {
1379
+ ok: false,
1380
+ error: routerAbStepUpError(503, "wallet_session_unavailable", "Wallet Session is unavailable")
1381
+ };
1382
+ }
1383
+ if (session.tenantId !== input.authorizedOperations.tenantId || runtimePolicyScope.orgId !== session.tenantId || session.expiresAtMs <= Date.now()) return {
1384
+ ok: false,
1385
+ error: routerAbStepUpError(403, "scope_mismatch", "Wallet Session scope is invalid")
1386
+ };
1387
+ return {
1388
+ ok: true,
1389
+ authorizedOperations: input.authorizedOperations,
1390
+ session: {
1391
+ tenantId: session.tenantId,
1392
+ principalId: session.principalId,
1393
+ sessionId: String(session.authorizationId),
1394
+ walletId: String(session.walletId),
1395
+ runtimePolicyScope,
1396
+ laneAuthorization: {
1397
+ kind: "wallet_auth_method",
1398
+ walletAuthMethodId: session.walletAuthMethodId
1399
+ }
1400
+ },
1401
+ requestOrigin,
1402
+ expiresAtMs: session.expiresAtMs
1403
+ };
1404
+ }
1405
+ function walletExecutionLaneAuthSourceFromAuthority(authority) {
1406
+ if (authority.factor.kind === "passkey") return {
1407
+ kind: "passkey",
1408
+ credentialIdB64u: authority.factor.credentialIdB64u
1409
+ };
1410
+ const providerSubject = parseProviderSubject(authority.factor.providerUserId);
1411
+ return providerSubject.ok ? {
1412
+ kind: "oidc_provider",
1413
+ providerId: authority.factor.provider === "google" ? "google_oidc" : "oidc",
1414
+ providerSubject: providerSubject.value
1415
+ } : null;
1416
+ }
1417
+ function evmAddress20B64u(value) {
1418
+ if (!/^0x[0-9a-fA-F]{40}$/.test(value)) return null;
1419
+ const bytes = new Uint8Array(20);
1420
+ for (let index = 0; index < bytes.length; index += 1) bytes[index] = Number.parseInt(value.slice(2 + index * 2, 4 + index * 2), 16);
1421
+ return base64UrlEncode(bytes);
1422
+ }
1423
+ async function authenticateRouterAbWalletOperationStepUp(input) {
1424
+ return authenticateRouterAbWalletOperationStepUpIdentity({
1425
+ kind: "wallet_session_operation_credential_v1",
1426
+ headers: input.headers,
1427
+ keyFamily: "ed25519",
1428
+ operationKind: input.operationKind,
1429
+ walletId: input.scope.account_id,
1430
+ materialOwner: input.scope.material_activation.material_owner,
1431
+ materialActivation: input.scope.material_activation,
1432
+ requestExpiresAtMs: input.requestExpiresAtMs,
1433
+ authorizedOperations: input.authorizedOperations,
1434
+ authorizationSessions: input.authorizationSessions,
1435
+ resolveEd25519MaterialActivation: input.resolveEd25519MaterialActivation
1436
+ });
1437
+ }
1438
+ async function authenticateRouterAbEcdsaOperationStepUp(input) {
1439
+ const scope = routerAbEcdsaOperationStepUpScope(input.request);
1440
+ return await authenticateRouterAbWalletOperationStepUpIdentity({
1441
+ kind: "wallet_session_operation_credential_v1",
1442
+ headers: input.headers,
1443
+ keyFamily: "ecdsa_secp256k1",
1444
+ operationKind: "evm.sign_transaction",
1445
+ walletId: scope.wallet_id,
1446
+ materialOwner: input.request.material_activation.material_owner,
1447
+ materialActivation: input.request.material_activation,
1448
+ requestExpiresAtMs: input.request.expires_at_ms,
1449
+ authorizedOperations: input.authorizedOperations,
1450
+ authorizationSessions: input.authorizationSessions,
1451
+ resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation
1452
+ });
1453
+ }
1454
+ function parseRouterAbEd25519OperationStepUpScope(value) {
1455
+ return parseRouterAbEd25519NormalSigningScopeV2(value);
1456
+ }
1457
+ function parseRouterAbOperationStepUpOperation(value) {
1458
+ const intent = isPlainObject(value) ? value : null;
1459
+ if (!intent) return {
1460
+ ok: false,
1461
+ message: "Router A/B step-up intent is required"
1462
+ };
1463
+ let operationKind;
1464
+ switch (intent.kind) {
1465
+ case "near_transaction_v1":
1466
+ operationKind = "near.sign_transaction";
1467
+ break;
1468
+ case "near_delegate_action_v1":
1469
+ operationKind = "near.sign_delegate_action";
1470
+ break;
1471
+ case "nep413_v1":
1472
+ operationKind = "near.sign_nep413_message";
1473
+ break;
1474
+ default: return {
1475
+ ok: false,
1476
+ message: "Router A/B step-up intent kind is invalid"
1477
+ };
1478
+ }
1479
+ const operationId = parseCapabilityOperationId(intent.operation_id);
1480
+ if (!operationId.ok) return {
1481
+ ok: false,
1482
+ message: operationId.error.message
1483
+ };
1484
+ return {
1485
+ ok: true,
1486
+ operationId: operationId.value,
1487
+ operation: buildNearEd25519MpcOperationRef(operationKind)
1488
+ };
1489
+ }
1490
+ function parseRouterAbEd25519NormalSigningOperationForAdmission(input) {
1491
+ if (input.phase === "prepare") {
1492
+ const requestedOperation = parseRouterAbOperationStepUpOperation(input.body.intent);
1493
+ if (!requestedOperation.ok) return requestedOperation;
1494
+ return {
1495
+ ok: true,
1496
+ operation: {
1497
+ phase: "prepare",
1498
+ operationKind: requestedOperation.operation.operationKind
1499
+ }
1500
+ };
1501
+ }
1502
+ try {
1503
+ switch (input.authorizationKind) {
1504
+ case "reusable_wallet_session": {
1505
+ const receipt = parseEd25519ReusableAuthorizedOperationReceipt(input.body.authorized_operation);
1506
+ return {
1507
+ ok: true,
1508
+ operation: {
1509
+ phase: "finalize",
1510
+ operationKind: receipt.operation_kind,
1511
+ authorizationKind: "reusable_wallet_session",
1512
+ receipt
1513
+ }
1514
+ };
1515
+ }
1516
+ case "operation_step_up": {
1517
+ const receipt = parseEd25519VerifiedStepUpAuthorizedOperationReceipt(input.body.authorized_operation);
1518
+ return {
1519
+ ok: true,
1520
+ operation: {
1521
+ phase: "finalize",
1522
+ operationKind: receipt.operation_kind,
1523
+ authorizationKind: "operation_step_up",
1524
+ receipt
1525
+ }
1526
+ };
1527
+ }
1528
+ }
1529
+ } catch (error) {
1530
+ return {
1531
+ ok: false,
1532
+ message: errorMessage(error)
1533
+ };
1534
+ }
1535
+ }
1536
+ async function validateRouterAbEd25519V2FinalizeAuthorizedOperation(input) {
1537
+ if (!input.authorizedOperations) return {
1538
+ ok: false,
1539
+ result: routerAbEd25519OwnerOperationFailureResult({
1540
+ status: 501,
1541
+ code: "not_configured",
1542
+ message: "Reusable Wallet Session authorization is not configured",
1543
+ phase: input.phase
1544
+ })
1545
+ };
1546
+ let authorizedOperationId;
1547
+ try {
1548
+ authorizedOperationId = requireAuthorizationValue(parseAuthorizedOperationId(input.receipt.authorized_operation_id));
1549
+ requireAuthorizationValue(parseCapabilityOperationId(input.receipt.operation_id));
1550
+ } catch (error) {
1551
+ return {
1552
+ ok: false,
1553
+ result: routerAbEd25519OwnerOperationFailureResult({
1554
+ status: 400,
1555
+ code: "invalid_authorized_operation",
1556
+ message: errorMessage(error),
1557
+ phase: input.phase
1558
+ })
1559
+ };
1560
+ }
1561
+ let operation;
1562
+ try {
1563
+ operation = await input.authorizedOperations.readAuthorizedOperationById({
1564
+ tenantId: input.authorizedOperations.tenantId,
1565
+ authorizedOperationId
1566
+ });
1567
+ } catch (error) {
1568
+ return {
1569
+ ok: false,
1570
+ result: routerAbEd25519OwnerOperationFailureResult({
1571
+ status: 500,
1572
+ code: "internal",
1573
+ message: errorMessage(error),
1574
+ phase: input.phase
1575
+ })
1576
+ };
1577
+ }
1578
+ if (!operation) return {
1579
+ ok: false,
1580
+ result: routerAbEd25519OwnerOperationFailureResult({
1581
+ status: 409,
1582
+ code: "authorized_operation_missing",
1583
+ message: "Authorized operation is unavailable",
1584
+ phase: input.phase
1585
+ })
1586
+ };
1587
+ const operationRef = operation.operation.operation;
1588
+ if (operation.tenantId !== input.authorizedOperations.tenantId || operation.authorizedOperationId !== authorizedOperationId || operation.operation.operationId !== input.receipt.operation_id || operation.operationFingerprintDigest !== input.receipt.operation_fingerprint_digest || operation.operation.digests.laneDigest !== input.receipt.lane_digest_b64u || operation.operation.digests.intentDigest !== input.receipt.intent_digest_b64u || operation.operation.digests.displayDigest !== input.receipt.display_digest_b64u || operationRef.capabilityKind !== "near_ed25519_mpc_signing" || operationRef.operationKind !== input.receipt.operation_kind) return {
1589
+ ok: false,
1590
+ result: routerAbEd25519OwnerOperationFailureResult({
1591
+ status: 400,
1592
+ code: "invalid_authorized_operation",
1593
+ message: "Ed25519 authorized operation does not match its receipt",
1594
+ phase: input.phase
1595
+ })
1596
+ };
1597
+ switch (operationRef.operationKind) {
1598
+ case "near.sign_transaction":
1599
+ case "near.sign_delegate_action":
1600
+ case "near.sign_nep413_message": return {
1601
+ ok: true,
1602
+ operationKind: operationRef.operationKind
1603
+ };
1604
+ }
1605
+ }
1606
+ function requireAuthorizationValue(result) {
1607
+ if (!result.ok) throw new Error(result.error.message);
1608
+ return result.value;
1609
+ }
1610
+ async function authorizeRouterAbEd25519WalletSessionRequest(input) {
1611
+ if (input.operation.phase === "finalize") {
1612
+ const exactOperation = await validateRouterAbEd25519V2FinalizeAuthorizedOperation({
1613
+ receipt: input.operation.receipt,
1614
+ authorizedOperations: input.authorizedOperations,
1615
+ phase: input.phase
1616
+ });
1617
+ if (!exactOperation.ok) return exactOperation;
1618
+ if (exactOperation.operationKind !== input.admission.operationKind) return {
1619
+ ok: false,
1620
+ result: routerAbEd25519OwnerOperationFailureResult({
1621
+ status: 403,
1622
+ code: "wallet_session_scope_mismatch",
1623
+ message: "Exact Wallet Session operation does not match the authorized operation",
1624
+ phase: input.phase
1625
+ })
1626
+ };
1627
+ }
1628
+ const expectedMaterialActivation = routerAbMpcMaterialActivationRefFromWire(input.scope.material_activation);
1629
+ const admittedMaterialActivation = routerAbMpcMaterialActivationRefToWire(input.admission.materialActivation);
1630
+ const expiresAtMs = Number(input.body.expires_at_ms);
1631
+ if (input.scope.authorization.wallet_session_id !== input.session.walletSessionId || input.scope.account_id !== String(input.session.walletId) || input.scope.material_activation.material_owner !== String(input.session.walletId) || input.scope.signing_worker_id !== input.scope.material_activation.signing_worker || !mpcMaterialActivationRefsEqual(expectedMaterialActivation, input.admission.materialActivation) || !Number.isFinite(expiresAtMs) || expiresAtMs <= 0) return {
1632
+ ok: false,
1633
+ result: routerAbEd25519OwnerOperationFailureResult({
1634
+ status: 403,
1635
+ code: "wallet_session_scope_mismatch",
1636
+ message: "Exact Wallet Session does not authorize this Ed25519 request",
1637
+ phase: input.phase
1638
+ })
1639
+ };
1640
+ if (expiresAtMs <= Date.now()) return {
1641
+ ok: false,
1642
+ result: routerAbEd25519OwnerOperationFailureResult({
1643
+ status: 408,
1644
+ code: "expired_request",
1645
+ message: "Router A/B Ed25519 normal-signing request is expired",
1646
+ phase: input.phase
1647
+ })
1648
+ };
1649
+ if (expiresAtMs > input.session.expiresAtMs) return {
1650
+ ok: false,
1651
+ result: routerAbEd25519OwnerOperationFailureResult({
1652
+ status: 403,
1653
+ code: "wallet_session_scope_mismatch",
1654
+ message: "Ed25519 request exceeds the exact Wallet Session lifetime",
1655
+ phase: input.phase
1656
+ })
1657
+ };
1658
+ const activeMaterial = await input.resolveEd25519MaterialActivation({
1659
+ walletId: String(input.session.walletId),
1660
+ materialActivation: admittedMaterialActivation
1661
+ });
1662
+ if (!activeMaterial.ok || !sameRouterAbMpcMaterialActivationRef(activeMaterial.materialActivation, admittedMaterialActivation) || activeMaterial.signingWorkerId !== input.scope.signing_worker_id || base64UrlEncode(Uint8Array.from(activeMaterial.exportIdentity.registered_public_key)) !== input.admission.signer.registeredPublicKeyB64u) return {
1663
+ ok: false,
1664
+ result: routerAbEd25519OwnerOperationFailureResult({
1665
+ status: activeMaterial.ok || activeMaterial.code !== "internal" ? 403 : 500,
1666
+ code: activeMaterial.ok || activeMaterial.code !== "internal" ? "material_mismatch" : "internal",
1667
+ message: activeMaterial.ok ? "Exact Wallet Session material does not match the active Ed25519 material" : activeMaterial.message,
1668
+ phase: input.phase
1669
+ })
1670
+ };
1671
+ const admission = {
1672
+ ok: true,
1673
+ thresholdSessionId: activeMaterial.exportIdentity.scope.threshold_session_id,
1674
+ requestId: input.scope.request_id,
1675
+ expiresAtMs,
1676
+ materialActivation: admittedMaterialActivation
1677
+ };
1678
+ const admissionDecision = await evaluateRouterAbNormalSigningAdmission({
1679
+ adapter: input.admissionAdapter,
1680
+ curve: "ed25519",
1681
+ authorizationKind: "wallet_session_operation_credential_v1",
1682
+ phase: input.phase,
1683
+ walletId: String(input.session.walletId),
1684
+ authorityId: input.authorityId,
1685
+ thresholdSessionId: activeMaterial.exportIdentity.scope.threshold_session_id,
1686
+ walletSessionId: String(input.session.walletSessionId),
1687
+ quotaId: String(input.session.quotaId),
1688
+ requestId: input.scope.request_id,
1689
+ expiresAtMs,
1690
+ signingWorkerId: activeMaterial.signingWorkerId,
1691
+ runtimePolicyScope: activeMaterial.runtimePolicyScope
1692
+ });
1693
+ if (!admissionDecision.ok) return {
1694
+ ok: false,
1695
+ result: routerAbEd25519OwnerOperationFailureResult({
1696
+ status: admissionDecision.status,
1697
+ code: admissionDecision.code,
1698
+ message: admissionDecision.message,
1699
+ phase: input.phase
1700
+ })
1701
+ };
1702
+ return {
1703
+ ok: true,
1704
+ admission,
1705
+ activeMaterial
1706
+ };
1707
+ }
1708
+ async function resolveRouterAbEd25519ExhaustedCandidateAuthorization(input) {
1709
+ const token = extractBearerCredential(input.headers);
1710
+ if (!token) return null;
1711
+ let candidate;
1712
+ try {
1713
+ candidate = await input.authorizationSessions.readExhaustedWalletSessionAuthorizationV2CandidateByOperationCredential({
1714
+ tenantId: input.authorizationSessions.tenantId,
1715
+ token,
1716
+ nowMs: Date.now()
1717
+ });
1718
+ } catch {
1719
+ return {
1720
+ ok: false,
1721
+ result: routerAbStepUpError(503, "wallet_session_unavailable", "Wallet Session is unavailable")
1722
+ };
1723
+ }
1724
+ if (!candidate) return null;
1725
+ const session = candidate.status.session;
1726
+ const admission = resolveWalletSessionAuthorizationV2Admission({
1727
+ authorization: session,
1728
+ authority: candidate.authority,
1729
+ authMethod: candidate.authMethod,
1730
+ operation: {
1731
+ tenantId: session.tenantId,
1732
+ principalId: session.principalId,
1733
+ walletId: session.walletId,
1734
+ keyFamily: "ed25519",
1735
+ operationKind: input.operation.operationKind
1736
+ },
1737
+ retiredAtMs: candidate.retiredAtMs,
1738
+ nowMs: Date.now()
1739
+ });
1740
+ if (!admission.ok || admission.keyFamily !== "ed25519") return {
1741
+ ok: false,
1742
+ result: routerAbEd25519OwnerOperationFailureResult({
1743
+ status: 403,
1744
+ code: "wallet_session_scope_mismatch",
1745
+ message: "Exact Wallet Session does not authorize this Ed25519 request",
1746
+ phase: input.phase
1747
+ })
1748
+ };
1749
+ const authorized = await authorizeRouterAbEd25519WalletSessionRequest({
1750
+ phase: input.phase,
1751
+ body: input.body,
1752
+ scope: input.scope,
1753
+ operation: input.operation,
1754
+ session,
1755
+ authorityId: String(candidate.authority.authorityId),
1756
+ admission,
1757
+ authorizedOperations: input.authorizedOperations,
1758
+ admissionAdapter: input.admissionAdapter,
1759
+ resolveEd25519MaterialActivation: input.resolveEd25519MaterialActivation
1760
+ });
1761
+ if (!authorized.ok) return authorized;
1762
+ return {
1763
+ ok: true,
1764
+ kind: "wallet_session_operation_credential_exhausted_candidate_v1",
1765
+ candidate,
1766
+ admission: authorized.admission,
1767
+ activeMaterial: authorized.activeMaterial
1768
+ };
1769
+ }
1770
+ function routerAbOperationStepUpClaimFailure(result) {
1771
+ switch (result.kind) {
1772
+ case "claimed":
1773
+ case "operation_in_progress":
1774
+ case "replayed": return null;
1775
+ case "authorization_grant_rejected":
1776
+ case "verified_step_up_rejected": return routerAbStepUpError(403, result.kind, "Operation step-up authorization is invalid");
1777
+ case "wallet_session_quota_exhausted": return routerAbStepUpError(409, result.kind, "Operation step-up authorization is invalid");
1778
+ case "material_mismatch": return routerAbStepUpError(403, result.kind, "Operation step-up material is invalid");
1779
+ }
1780
+ }
1781
+ function routerAbStepUpError(status, code, message) {
1782
+ return {
1783
+ status,
1784
+ body: {
1785
+ ok: false,
1786
+ code,
1787
+ message
1788
+ }
1789
+ };
1790
+ }
1791
+ async function authorizeRouterAbEd25519NormalSigningRoute(input) {
1792
+ let scope;
1793
+ try {
1794
+ scope = parseRouterAbEd25519NormalSigningScopeV2(input.body.scope);
1795
+ } catch (error) {
1796
+ return {
1797
+ ok: false,
1798
+ result: routerAbEd25519OwnerOperationFailureResult({
1799
+ status: 400,
1800
+ code: "invalid_body",
1801
+ message: errorMessage(error),
1802
+ phase: input.phase
1803
+ })
1804
+ };
1805
+ }
1806
+ const operationForAdmission = parseRouterAbEd25519NormalSigningOperationForAdmission({
1807
+ phase: input.phase,
1808
+ body: input.body,
1809
+ authorizationKind: scope.authorization.kind
1810
+ });
1811
+ if (!operationForAdmission.ok) return {
1812
+ ok: false,
1813
+ result: routerAbEd25519OwnerOperationFailureResult({
1814
+ status: 400,
1815
+ code: "invalid_body",
1816
+ message: operationForAdmission.message,
1817
+ phase: input.phase
1818
+ })
1819
+ };
1820
+ if (scope.authorization.kind === "operation_step_up") {
1821
+ const result = await handleRouterAbEd25519OperationStepUpRoute({
1822
+ body: input.body,
1823
+ headers: input.headers,
1824
+ authorizedOperations: input.authorizedOperations,
1825
+ authorizationSessions: input.authorizationSessions,
1826
+ resolveEd25519MaterialActivation: input.resolveEd25519MaterialActivation,
1827
+ phase: input.phase,
1828
+ scope,
1829
+ operationKind: operationForAdmission.operation.operationKind
1830
+ });
1831
+ return "status" in result ? {
1832
+ ok: false,
1833
+ result
1834
+ } : {
1835
+ ok: true,
1836
+ kind: "operation_step_up",
1837
+ ...result
1838
+ };
1839
+ }
1840
+ const validated = await validateRouterAbEd25519WalletSessionInputs({
1841
+ headers: input.headers,
1842
+ authorizationSessions: input.authorizationSessions,
1843
+ operationKind: operationForAdmission.operation.operationKind
1844
+ });
1845
+ if (!validated.ok) {
1846
+ const operation = operationForAdmission.operation;
1847
+ if (validated.code === "wallet_session_unavailable" && input.authorizationSessions && (operation.phase === "prepare" || operation.authorizationKind === "reusable_wallet_session")) {
1848
+ const exhaustedCandidate = await resolveRouterAbEd25519ExhaustedCandidateAuthorization({
1849
+ body: input.body,
1850
+ headers: input.headers,
1851
+ scope,
1852
+ phase: input.phase,
1853
+ operation,
1854
+ authorizedOperations: input.authorizedOperations,
1855
+ authorizationSessions: input.authorizationSessions,
1856
+ admissionAdapter: input.admissionAdapter,
1857
+ resolveEd25519MaterialActivation: input.resolveEd25519MaterialActivation
1858
+ });
1859
+ if (exhaustedCandidate) return exhaustedCandidate;
1860
+ }
1861
+ const stepUp = await resolveRouterAbEd25519OwnerOperationStepUpPreparation({
1862
+ scope,
1863
+ body: input.body,
1864
+ phase: input.phase,
1865
+ resolveEd25519MaterialActivation: input.resolveEd25519MaterialActivation
1866
+ });
1867
+ return {
1868
+ ok: false,
1869
+ result: routerAbEd25519OwnerOperationFailureResult({
1870
+ status: routerAbWalletSessionValidationStatus(validated.code),
1871
+ code: validated.code,
1872
+ message: validated.message,
1873
+ phase: input.phase,
1874
+ stepUp
1875
+ })
1876
+ };
1877
+ }
1878
+ const operation = operationForAdmission.operation;
1879
+ if (operation.phase === "finalize" && operation.authorizationKind !== "reusable_wallet_session") return {
1880
+ ok: false,
1881
+ result: routerAbEd25519OwnerOperationFailureResult({
1882
+ status: 400,
1883
+ code: "invalid_authorized_operation",
1884
+ message: "Reusable Wallet Session authorized operation is required",
1885
+ phase: input.phase
1886
+ })
1887
+ };
1888
+ const authorized = await authorizeRouterAbEd25519WalletSessionRequest({
1889
+ phase: input.phase,
1890
+ body: input.body,
1891
+ scope,
1892
+ operation,
1893
+ session: validated.admission.context.authorization.session,
1894
+ authorityId: String(validated.admission.context.authority.authorityId),
1895
+ admission: validated.admission.admission,
1896
+ authorizedOperations: input.authorizedOperations,
1897
+ admissionAdapter: input.admissionAdapter,
1898
+ resolveEd25519MaterialActivation: input.resolveEd25519MaterialActivation
1899
+ });
1900
+ if (!authorized.ok) return authorized;
1901
+ return {
1902
+ ok: true,
1903
+ kind: "wallet_session_operation_credential_v1",
1904
+ validated,
1905
+ admission: authorized.admission,
1906
+ activeMaterial: authorized.activeMaterial
1907
+ };
1908
+ }
1909
+ function errorMessage(error) {
1910
+ return String(error && typeof error === "object" && "message" in error ? error.message : error || "unknown error");
1911
+ }
1912
+ /**
1913
+ * Re-resolve the complete activation reference immediately before a claim or
1914
+ * evidence write. The resolver is authoritative for capability identity and
1915
+ * all owner/key/lifecycle/worker bindings; a stale or superseded reference
1916
+ * must fail before any authorization side effect is attempted.
1917
+ */
1918
+ async function resolveFreshRouterAbEcdsaMaterialActivation(input) {
1919
+ const resolved = await input.resolveEcdsaMaterialActivation({
1920
+ walletId: input.walletId,
1921
+ materialActivation: input.expected
1922
+ });
1923
+ if (!resolved.ok) return resolved;
1924
+ if (!sameRouterAbMpcMaterialActivationRef(resolved.materialActivation, input.expected)) return {
1925
+ ok: false,
1926
+ code: "scope_mismatch",
1927
+ message: "ECDSA material activation changed before authorization claim"
1928
+ };
1929
+ return {
1930
+ ok: true,
1931
+ materialActivation: resolved.materialActivation,
1932
+ keyHandle: resolved.keyHandle,
1933
+ relayerKeyId: resolved.relayerKeyId,
1934
+ participantIds: resolved.participantIds,
1935
+ runtimePolicyScope: resolved.runtimePolicyScope
1936
+ };
1937
+ }
1938
+ function validateRouterAbEcdsaV2NormalSigningRequestForSession(input) {
1939
+ let request;
1940
+ try {
1941
+ request = input.phase === "prepare" ? parseRouterAbEcdsaDerivationEvmDigestSigningRequestV1(input.body) : parseRouterAbEcdsaDerivationEvmDigestSigningFinalizeRequestV1(input.body);
1942
+ } catch (error) {
1943
+ return {
1944
+ ok: false,
1945
+ error: routerAbStepUpError(400, "invalid_body", errorMessage(error))
1946
+ };
1947
+ }
1948
+ if (request.authorization.kind !== "reusable_wallet_session" || request.authorization.wallet_session_id !== input.session.walletSessionId || request.scope.wallet_id !== String(input.session.walletId) || request.material_activation.material_owner !== String(input.session.walletId) || request.material_activation.signing_worker !== request.scope.signing_worker.server_id || !sameRouterAbMpcMaterialActivationRef(request.material_activation, request.scope.material_activation) || !sameRouterAbMpcMaterialActivationRef(request.material_activation, input.admittedMaterialActivation)) return {
1949
+ ok: false,
1950
+ error: routerAbWalletSessionError(WALLET_SESSION_FAILURE_CODES.scopeMismatch)
1951
+ };
1952
+ if (request.expires_at_ms <= Date.now()) return {
1953
+ ok: false,
1954
+ error: routerAbSigningError(408, "expired_request", "Router A/B ECDSA derivation normal-signing request is expired")
1955
+ };
1956
+ if (request.expires_at_ms > input.session.expiresAtMs) return {
1957
+ ok: false,
1958
+ error: routerAbWalletSessionError(WALLET_SESSION_FAILURE_CODES.scopeMismatch)
1959
+ };
1960
+ return {
1961
+ ok: true,
1962
+ request,
1963
+ admission: {
1964
+ ok: true,
1965
+ thresholdSessionId: routerAbEcdsaDerivationActiveStateId({
1966
+ kind: ROUTER_AB_ECDSA_DERIVATION_NORMAL_SIGNING_STATE_KIND_V1,
1967
+ scope: request.scope
1968
+ }),
1969
+ requestId: request.request_id,
1970
+ expiresAtMs: request.expires_at_ms,
1971
+ materialActivation: input.admittedMaterialActivation
1972
+ }
1973
+ };
1974
+ }
1975
+ async function admitRouterAbEcdsaReusableWalletSessionOperation(input) {
1976
+ if (!routerAbEcdsaAtomicAuthorizationConfigured(input.authorizedOperations)) return {
1977
+ ok: false,
1978
+ error: routerAbStepUpError(501, "not_configured", "ECDSA atomic authorization is not configured")
1979
+ };
1980
+ if (input.request.authorization.kind !== "reusable_wallet_session") return {
1981
+ ok: false,
1982
+ error: routerAbStepUpError(400, "invalid_body", "Reusable Wallet Session authority is required")
1983
+ };
1984
+ const nowMs = Date.now();
1985
+ try {
1986
+ const session = input.binding.kind === "wallet_session_operation_credential_v1" ? input.binding.context.authorization.session : input.binding.candidate.status.session;
1987
+ const tenantId = session.tenantId;
1988
+ const principalId = session.principalId;
1989
+ const walletId = session.walletId;
1990
+ const walletSessionId = session.walletSessionId;
1991
+ const authorizationId = session.authorizationId;
1992
+ const quotaId = session.quotaId;
1993
+ if (tenantId !== input.authorizedOperations.tenantId || input.request.authorization.wallet_session_id !== walletSessionId) return {
1994
+ ok: false,
1995
+ error: routerAbStepUpError(403, "wallet_session_mismatch", "Reusable Wallet Session identity does not match")
1996
+ };
1997
+ const freshMaterial = await resolveFreshRouterAbEcdsaMaterialActivation({
1998
+ resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation,
1999
+ walletId: String(walletId),
2000
+ expected: input.materialActivation
2001
+ });
2002
+ if (!freshMaterial.ok) return {
2003
+ ok: false,
2004
+ error: routerAbStepUpError(freshMaterial.code === "internal" ? 500 : 403, freshMaterial.code === "internal" ? "internal" : "wallet_session_mismatch", freshMaterial.message)
2005
+ };
2006
+ const capabilityId = requireAuthorizationValue(parseCapabilityId(freshMaterial.materialActivation.capability));
2007
+ const operationId = requireAuthorizationValue(parseCapabilityOperationId(input.request.operation_id));
2008
+ const envelope = buildCapabilityOperationEnvelope({
2009
+ tenantId,
2010
+ principalId,
2011
+ capabilityId,
2012
+ operationId,
2013
+ operation: buildEvmEcdsaMpcOperationRef("evm.sign_transaction"),
2014
+ digests: {
2015
+ laneDigest: parseDigestB64u(input.request.operation_digests.lane_digest_b64u),
2016
+ intentDigest: parseDigestB64u(input.request.operation_digests.intent_digest_b64u),
2017
+ displayDigest: parseDigestB64u(input.request.operation_digests.display_digest_b64u)
2018
+ }
2019
+ });
2020
+ const authorizedOperationId = requireAuthorizationValue(parseAuthorizedOperationId(`ecdsa-authorized-operation:${operationId}:${input.request.request_id}`));
2021
+ const auditEventId = requireAuthorizationValue(parseAuthorizationAuditEventId(`ecdsa-operation-audit:${operationId}`));
2022
+ const outcome = await input.authorizedOperations.admitAuthorizedOperation({
2023
+ operation: {
2024
+ tenantId,
2025
+ authorizedOperationId,
2026
+ auditEventId,
2027
+ operation: envelope,
2028
+ authorization: {
2029
+ kind: "authorization_grant",
2030
+ authorizationGrantRef: buildAuthorizationGrantRef(authorizationId)
2031
+ },
2032
+ quota: {
2033
+ kind: "consume_reusable_wallet_session",
2034
+ quotaId
2035
+ },
2036
+ claimedAtMs: nowMs
2037
+ },
2038
+ material: {
2039
+ walletId,
2040
+ keyHandle: freshMaterial.keyHandle,
2041
+ runtimePolicyScope: freshMaterial.runtimePolicyScope,
2042
+ materialActivation: freshMaterial.materialActivation
2043
+ }
2044
+ });
2045
+ const claimFailure = routerAbReusableWalletSessionClaimFailure(outcome);
2046
+ if (claimFailure) return {
2047
+ ok: false,
2048
+ error: claimFailure
2049
+ };
2050
+ if (outcome.kind === "claimed" || outcome.kind === "operation_in_progress" || outcome.kind === "replayed") return {
2051
+ ok: true,
2052
+ admission: {
2053
+ kind: outcome.kind,
2054
+ operation: outcome.operation
2055
+ }
2056
+ };
2057
+ return {
2058
+ ok: false,
2059
+ error: routerAbStepUpError(409, outcome.kind, "Authorized operation is unavailable")
2060
+ };
2061
+ } catch (error) {
2062
+ return {
2063
+ ok: false,
2064
+ error: routerAbStepUpError(400, "invalid_body", errorMessage(error))
2065
+ };
2066
+ }
2067
+ }
2068
+ function routerAbReusableWalletSessionClaimFailure(result) {
2069
+ switch (result.kind) {
2070
+ case "claimed":
2071
+ case "operation_in_progress":
2072
+ case "replayed": return null;
2073
+ case "wallet_session_quota_exhausted": return routerAbStepUpError(409, result.kind, "Reusable Wallet Session quota is exhausted");
2074
+ case "authorization_grant_rejected": return routerAbStepUpError(403, result.kind, "Reusable Wallet Session authorization is invalid");
2075
+ case "verified_step_up_rejected": return routerAbStepUpError(403, result.kind, "Reusable Wallet Session authorization is invalid");
2076
+ case "material_mismatch": return routerAbStepUpError(403, result.kind, "ECDSA material activation is no longer active");
2077
+ }
2078
+ }
2079
+ async function completeRouterAbEcdsaOperation(input) {
2080
+ await input.authorizedOperations.completeAuthorizedOperation({
2081
+ operation: input.operation,
2082
+ result: input.result,
2083
+ response: input.response,
2084
+ completedAtMs: Date.now()
2085
+ });
2086
+ }
2087
+ function routerAbEcdsaOperationStepUpScope(request) {
2088
+ return "scope" in request ? request.scope : request.normal_signing_scope;
2089
+ }
2090
+ function parseRouterAbEcdsaOperationStepUpRequest(input) {
2091
+ return input.phase === "prepare" ? parseRouterAbEcdsaDerivationEvmDigestSigningRequestV1(input.body) : parseRouterAbEcdsaDerivationEvmDigestSigningFinalizeRequestV1(input.body);
2092
+ }
2093
+ async function authorizeRouterAbEcdsaWalletSessionRequest(input) {
2094
+ const validated = validateRouterAbEcdsaV2NormalSigningRequestForSession(input);
2095
+ if (!validated.ok) return {
2096
+ ok: false,
2097
+ result: validated.error
2098
+ };
2099
+ const activeMaterial = await input.resolveEcdsaMaterialActivation({
2100
+ walletId: String(input.session.walletId),
2101
+ materialActivation: validated.admission.materialActivation
2102
+ });
2103
+ if (!activeMaterial.ok) return {
2104
+ ok: false,
2105
+ result: routerAbEcdsaOwnerOperationFailureResult({
2106
+ status: activeMaterial.code === "internal" ? 500 : 403,
2107
+ code: activeMaterial.code === "internal" ? "internal" : "material_mismatch",
2108
+ message: activeMaterial.code === "internal" ? activeMaterial.message : "Wallet Session V2 material is no longer active",
2109
+ phase: input.phase
2110
+ })
2111
+ };
2112
+ if (!sameRouterAbMpcMaterialActivationRef(activeMaterial.materialActivation, validated.admission.materialActivation) || !sameRouterAbEcdsaDerivationNormalSigningScopeV1(validated.request.scope, activeMaterial.routerAbEcdsaDerivationNormalSigning.scope)) return {
2113
+ ok: false,
2114
+ result: routerAbStepUpError(403, "wallet_session_scope_mismatch", "Wallet Session V2 scope does not match the active material")
2115
+ };
2116
+ const admissionDecision = await evaluateRouterAbNormalSigningAdmission({
2117
+ adapter: input.admissionAdapter,
2118
+ curve: "ecdsa",
2119
+ authorizationKind: "wallet_session_operation_credential_v1",
2120
+ phase: input.phase,
2121
+ walletId: String(input.session.walletId),
2122
+ walletSessionId: String(input.session.walletSessionId),
2123
+ materialActivation: activeMaterial.materialActivation,
2124
+ requestId: validated.admission.requestId,
2125
+ expiresAtMs: validated.admission.expiresAtMs,
2126
+ signingWorkerId: activeMaterial.materialActivation.signing_worker,
2127
+ keyHandle: activeMaterial.keyHandle,
2128
+ runtimePolicyScope: activeMaterial.runtimePolicyScope,
2129
+ admission: validated.admission
2130
+ });
2131
+ if (!admissionDecision.ok) return {
2132
+ ok: false,
2133
+ result: routerAbEcdsaOwnerOperationFailureResult({
2134
+ status: admissionDecision.status,
2135
+ code: admissionDecision.code,
2136
+ message: admissionDecision.message,
2137
+ phase: input.phase
2138
+ })
2139
+ };
2140
+ return {
2141
+ ok: true,
2142
+ request: validated.request,
2143
+ admission: {
2144
+ ...validated.admission,
2145
+ materialActivation: activeMaterial.materialActivation
2146
+ },
2147
+ activeMaterial
2148
+ };
2149
+ }
2150
+ async function resolveRouterAbEcdsaExhaustedCandidateAuthorization(input) {
2151
+ const token = extractBearerCredential(input.headers);
2152
+ if (!token) return null;
2153
+ let candidate;
2154
+ try {
2155
+ candidate = await input.authorizationSessions.readExhaustedWalletSessionAuthorizationV2CandidateByOperationCredential({
2156
+ tenantId: input.authorizationSessions.tenantId,
2157
+ token,
2158
+ nowMs: Date.now()
2159
+ });
2160
+ } catch {
2161
+ return {
2162
+ ok: false,
2163
+ result: routerAbStepUpError(503, "wallet_session_unavailable", "Wallet Session is unavailable")
2164
+ };
2165
+ }
2166
+ if (!candidate) return null;
2167
+ const session = candidate.status.session;
2168
+ const admission = resolveWalletSessionAuthorizationV2Admission({
2169
+ authorization: session,
2170
+ authority: candidate.authority,
2171
+ authMethod: candidate.authMethod,
2172
+ operation: {
2173
+ tenantId: session.tenantId,
2174
+ principalId: session.principalId,
2175
+ walletId: session.walletId,
2176
+ keyFamily: "ecdsa_secp256k1",
2177
+ operationKind: "evm.sign_transaction"
2178
+ },
2179
+ retiredAtMs: candidate.retiredAtMs,
2180
+ nowMs: Date.now()
2181
+ });
2182
+ if (!admission.ok || admission.keyFamily !== "ecdsa_secp256k1") return {
2183
+ ok: false,
2184
+ result: routerAbWalletSessionError(WALLET_SESSION_FAILURE_CODES.scopeMismatch)
2185
+ };
2186
+ const authorized = await authorizeRouterAbEcdsaWalletSessionRequest({
2187
+ phase: input.phase,
2188
+ body: input.body,
2189
+ session,
2190
+ admittedMaterialActivation: routerAbMpcMaterialActivationRefToWire(admission.materialActivation),
2191
+ admissionAdapter: input.admissionAdapter,
2192
+ resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation
2193
+ });
2194
+ if (!authorized.ok) return authorized;
2195
+ return {
2196
+ ok: true,
2197
+ kind: "wallet_session_operation_credential_exhausted_candidate_v1",
2198
+ candidate,
2199
+ admission: authorized.admission,
2200
+ activeMaterial: authorized.activeMaterial
2201
+ };
2202
+ }
2203
+ async function resolveRouterAbEcdsaExhaustedCandidateOperationStepUpAuthentication(input) {
2204
+ const token = extractBearerCredential(input.headers);
2205
+ if (!token) return null;
2206
+ const requestOriginRaw = (Array.isArray(input.headers.origin) ? input.headers.origin[0] : input.headers.origin) || "";
2207
+ let requestOrigin;
2208
+ try {
2209
+ requestOrigin = parseSessionOrigin(String(requestOriginRaw).trim());
2210
+ } catch {
2211
+ return {
2212
+ ok: false,
2213
+ error: routerAbStepUpError(401, "unauthorized", "Wallet owner proof origin is invalid")
2214
+ };
2215
+ }
2216
+ let candidate;
2217
+ try {
2218
+ candidate = await input.authorizationSessions.readExhaustedWalletSessionAuthorizationV2CandidateByOperationCredential({
2219
+ tenantId: input.authorizationSessions.tenantId,
2220
+ token,
2221
+ nowMs: Date.now()
2222
+ });
2223
+ } catch {
2224
+ return {
2225
+ ok: false,
2226
+ error: routerAbStepUpError(503, "wallet_session_unavailable", "Wallet Session is unavailable")
2227
+ };
2228
+ }
2229
+ if (!candidate) return null;
2230
+ const session = candidate.status.session;
2231
+ const scope = routerAbEcdsaOperationStepUpScope(input.request);
2232
+ const admission = resolveWalletSessionAuthorizationV2Admission({
2233
+ authorization: session,
2234
+ authority: candidate.authority,
2235
+ authMethod: candidate.authMethod,
2236
+ operation: {
2237
+ tenantId: session.tenantId,
2238
+ principalId: session.principalId,
2239
+ walletId: session.walletId,
2240
+ keyFamily: "ecdsa_secp256k1",
2241
+ operationKind: "evm.sign_transaction"
2242
+ },
2243
+ retiredAtMs: candidate.retiredAtMs,
2244
+ nowMs: Date.now()
2245
+ });
2246
+ if (!admission.ok || admission.keyFamily !== "ecdsa_secp256k1") return {
2247
+ ok: false,
2248
+ error: routerAbStepUpError(403, "scope_mismatch", "Wallet Session scope is invalid")
2249
+ };
2250
+ const admittedMaterialActivation = routerAbMpcMaterialActivationRefToWire(admission.materialActivation);
2251
+ if (admission.operationKind !== "evm.sign_transaction" || session.walletId.toString() !== scope.wallet_id || input.request.material_activation.material_owner !== scope.wallet_id || !Number.isSafeInteger(input.request.expires_at_ms) || input.request.expires_at_ms > session.expiresAtMs || !sameRouterAbMpcMaterialActivationRef(admittedMaterialActivation, input.request.material_activation)) return {
2252
+ ok: false,
2253
+ error: routerAbStepUpError(403, "scope_mismatch", "Wallet Session scope is invalid")
2254
+ };
2255
+ let activeMaterial;
2256
+ try {
2257
+ activeMaterial = await input.resolveEcdsaMaterialActivation({
2258
+ walletId: scope.wallet_id,
2259
+ materialActivation: admittedMaterialActivation
2260
+ });
2261
+ } catch {
2262
+ return {
2263
+ ok: false,
2264
+ error: routerAbStepUpError(503, "wallet_session_unavailable", "Wallet Session is unavailable")
2265
+ };
2266
+ }
2267
+ const normalSigning = activeMaterial.ok ? activeMaterial.routerAbEcdsaDerivationNormalSigning : null;
2268
+ if (!activeMaterial.ok || !normalSigning || !sameRouterAbMpcMaterialActivationRef(activeMaterial.materialActivation, admittedMaterialActivation) || !sameRouterAbMpcMaterialActivationRef(normalSigning.scope.material_activation, admittedMaterialActivation) || normalSigning.scope.wallet_id !== scope.wallet_id || normalSigning.scope.public_identity.threshold_public_key33_b64u !== admission.signer.thresholdPublicKey33B64u || normalSigning.scope.public_identity.ethereum_address20_b64u !== evmAddress20B64u(admission.signer.evmAddress)) return {
2269
+ ok: false,
2270
+ error: routerAbStepUpError(activeMaterial.ok || activeMaterial.code !== "internal" ? 403 : 503, activeMaterial.ok || activeMaterial.code !== "internal" ? "scope_mismatch" : "wallet_session_unavailable", activeMaterial.ok ? "Wallet Session material does not match the active ECDSA material" : activeMaterial.message)
2271
+ };
2272
+ if (session.tenantId !== input.authorizedOperations.tenantId || activeMaterial.runtimePolicyScope.orgId !== session.tenantId || session.expiresAtMs <= Date.now()) return {
2273
+ ok: false,
2274
+ error: routerAbStepUpError(403, "scope_mismatch", "Wallet Session scope is invalid")
2275
+ };
2276
+ return {
2277
+ ok: true,
2278
+ kind: "wallet_session_operation_credential_exhausted_candidate_v1",
2279
+ authorizedOperations: input.authorizedOperations,
2280
+ candidate,
2281
+ activeMaterial,
2282
+ session: {
2283
+ tenantId: session.tenantId,
2284
+ principalId: session.principalId,
2285
+ sessionId: String(session.authorizationId),
2286
+ walletId: String(session.walletId),
2287
+ runtimePolicyScope: activeMaterial.runtimePolicyScope,
2288
+ laneAuthorization: {
2289
+ kind: "wallet_auth_method",
2290
+ walletAuthMethodId: session.walletAuthMethodId
2291
+ }
2292
+ },
2293
+ requestOrigin,
2294
+ expiresAtMs: session.expiresAtMs
2295
+ };
2296
+ }
2297
+ async function authenticateRouterAbEcdsaOperationStepUpWithExhaustedCandidate(input) {
2298
+ const authenticated = await authenticateRouterAbEcdsaOperationStepUp(input);
2299
+ if (authenticated.ok || !input.authorizedOperations || !input.authorizationSessions || !isWalletSessionUnavailableStepUpError(authenticated.error)) return authenticated;
2300
+ return await resolveRouterAbEcdsaExhaustedCandidateOperationStepUpAuthentication({
2301
+ headers: input.headers,
2302
+ request: input.request,
2303
+ authorizedOperations: input.authorizedOperations,
2304
+ authorizationSessions: input.authorizationSessions,
2305
+ resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation
2306
+ }) ?? authenticated;
2307
+ }
2308
+ function validateRouterAbEcdsaOperationStepUpIdentity(input) {
2309
+ const request = input.request;
2310
+ if (request.authorization.kind !== "operation_step_up" || request.scope.wallet_id !== input.session.walletId || request.material_activation.material_owner !== input.session.walletId || request.material_activation.signing_worker !== request.scope.signing_worker.server_id || !sameRouterAbMpcMaterialActivationRef(request.material_activation, request.scope.material_activation)) return routerAbStepUpError(403, "scope_mismatch", "ECDSA operation step-up identity does not match");
2311
+ if (request.expires_at_ms <= Date.now()) return routerAbStepUpError(408, "expired_request", "Router A/B ECDSA operation step-up request is expired");
2312
+ return null;
2313
+ }
2314
+ async function claimRouterAbEcdsaOperationStepUp(input) {
2315
+ if (!routerAbEcdsaAtomicAuthorizationConfigured(input.authenticated.authorizedOperations)) return routerAbStepUpError(501, "not_configured", "ECDSA atomic authorization is not configured");
2316
+ let authorizedOperationId;
2317
+ let operationEnvelope;
2318
+ try {
2319
+ const operationId = requireAuthorizationValue(parseCapabilityOperationId(input.operation.operation_id));
2320
+ authorizedOperationId = requireAuthorizationValue(parseAuthorizedOperationId(`ecdsa-step-up-authorized-operation:${input.operation.operation_id}`));
2321
+ operationEnvelope = buildCapabilityOperationEnvelope({
2322
+ tenantId: input.authenticated.session.tenantId,
2323
+ principalId: input.authenticated.session.principalId,
2324
+ capabilityId: requireAuthorizationValue(parseCapabilityId(input.materialActivation.capability)),
2325
+ operationId,
2326
+ operation: buildEvmEcdsaMpcOperationRef(input.operationKind),
2327
+ digests: {
2328
+ laneDigest: parseDigestB64u(input.operation.operation_digests.lane_digest_b64u),
2329
+ intentDigest: parseDigestB64u(input.operation.operation_digests.intent_digest_b64u),
2330
+ displayDigest: parseDigestB64u(input.operation.operation_digests.display_digest_b64u)
2331
+ }
2332
+ });
2333
+ } catch (error) {
2334
+ return routerAbStepUpError(400, "invalid_body", errorMessage(error));
2335
+ }
2336
+ const existing = await input.authenticated.authorizedOperations.readAuthorizedOperation({
2337
+ tenantId: input.authenticated.session.tenantId,
2338
+ operationFingerprintDigest: await computeCapabilityOperationFingerprintDigest(operationEnvelope)
2339
+ });
2340
+ if (!existing || existing.authorizedOperationId !== authorizedOperationId) return routerAbStepUpError(409, "authorized_operation_missing", "Operation authorization is unavailable");
2341
+ if (existing.authorization.kind !== "verified_step_up" || existing.quota.kind !== "quota_neutral") return routerAbStepUpError(409, "authorized_operation_missing", "Operation authorization has an invalid source or quota");
2342
+ const result = await input.authenticated.authorizedOperations.admitAuthorizedOperation({
2343
+ operation: {
2344
+ tenantId: existing.tenantId,
2345
+ authorizedOperationId: existing.authorizedOperationId,
2346
+ auditEventId: existing.auditEventId,
2347
+ operation: existing.operation,
2348
+ authorization: existing.authorization,
2349
+ quota: existing.quota,
2350
+ claimedAtMs: Date.now()
2351
+ },
2352
+ material: {
2353
+ walletId: requireAuthorizationValue(parseWalletId(input.authenticated.session.walletId)),
2354
+ keyHandle: input.keyHandle,
2355
+ runtimePolicyScope: input.authenticated.session.runtimePolicyScope,
2356
+ materialActivation: input.materialActivation
2357
+ }
2358
+ });
2359
+ if (result.kind === "material_mismatch") return routerAbStepUpError(403, "scope_mismatch", "ECDSA material activation changed before authorized-operation admission");
2360
+ const claimFailure = routerAbOperationStepUpClaimFailure(result);
2361
+ if (claimFailure) return claimFailure;
2362
+ if (result.kind === "claimed" || result.kind === "operation_in_progress" || result.kind === "replayed") return {
2363
+ kind: result.kind,
2364
+ operation: result.operation
2365
+ };
2366
+ return routerAbStepUpError(409, "authorized_operation_missing", "Authorized operation is unavailable");
2367
+ }
2368
+ async function handleRouterAbEcdsaOperationStepUpRoute(input) {
2369
+ let request;
2370
+ try {
2371
+ request = parseRouterAbEcdsaOperationStepUpRequest(input);
2372
+ } catch (error) {
2373
+ return routerAbStepUpError(400, "invalid_body", errorMessage(error));
2374
+ }
2375
+ if (request.authorization.kind !== "operation_step_up") return routerAbStepUpError(400, "invalid_body", "Operation step-up authority is required");
2376
+ const authenticated = await authenticateRouterAbEcdsaOperationStepUpWithExhaustedCandidate({
2377
+ headers: input.headers,
2378
+ request,
2379
+ authorizedOperations: input.authorizedOperations,
2380
+ authorizationSessions: input.authorizationSessions,
2381
+ resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation
2382
+ });
2383
+ if (!authenticated.ok) return authenticated.error;
2384
+ const identityFailure = validateRouterAbEcdsaOperationStepUpIdentity({
2385
+ request,
2386
+ session: authenticated.session
2387
+ });
2388
+ if (identityFailure) return identityFailure;
2389
+ const activeMaterial = "activeMaterial" in authenticated ? authenticated.activeMaterial : await input.resolveEcdsaMaterialActivation({
2390
+ walletId: authenticated.session.walletId,
2391
+ materialActivation: request.material_activation
2392
+ });
2393
+ if (!activeMaterial.ok) return routerAbStepUpError(activeMaterial.code === "internal" ? 500 : 403, activeMaterial.code === "internal" ? "internal" : "scope_mismatch", activeMaterial.code === "internal" ? activeMaterial.message : "ECDSA operation step-up material is no longer active");
2394
+ if (!sameRouterAbMpcMaterialActivationRef(activeMaterial.materialActivation, request.scope.material_activation)) return routerAbStepUpError(403, "scope_mismatch", "ECDSA operation step-up scope does not name the active material");
2395
+ const materialActivationId = requireMpcMaterialActivationId(activeMaterial.materialActivation.activation_id);
2396
+ if (!input.admissionAdapter) return routerAbStepUpError(501, "not_configured", "Router A/B ECDSA operation step-up admission is not configured");
2397
+ const admission = await input.admissionAdapter.evaluatePolicy({
2398
+ curve: "ecdsa",
2399
+ phase: input.phase,
2400
+ walletId: authenticated.session.walletId,
2401
+ materialActivationId,
2402
+ authorizationIdentity: {
2403
+ kind: "operation_step_up",
2404
+ materialActivationId
2405
+ },
2406
+ requestId: request.request_id,
2407
+ expiresAtMs: request.expires_at_ms,
2408
+ signingWorkerId: activeMaterial.materialActivation.signing_worker,
2409
+ keyHandle: activeMaterial.keyHandle,
2410
+ runtimePolicyScope: authenticated.session.runtimePolicyScope
2411
+ });
2412
+ if (!admission.ok) return {
2413
+ status: admission.status,
2414
+ body: {
2415
+ ok: false,
2416
+ code: admission.code,
2417
+ message: admission.message
2418
+ }
2419
+ };
2420
+ const freshMaterial = await resolveFreshRouterAbEcdsaMaterialActivation({
2421
+ resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation,
2422
+ walletId: authenticated.session.walletId,
2423
+ expected: request.material_activation
2424
+ });
2425
+ if (!freshMaterial.ok) return routerAbStepUpError(freshMaterial.code === "internal" ? 500 : 403, freshMaterial.code === "internal" ? "internal" : "scope_mismatch", freshMaterial.message);
2426
+ if (freshMaterial.keyHandle !== activeMaterial.keyHandle || freshMaterial.relayerKeyId !== activeMaterial.relayerKeyId || freshMaterial.participantIds[0] !== activeMaterial.participantIds[0] || freshMaterial.participantIds[1] !== activeMaterial.participantIds[1]) return routerAbStepUpError(403, "scope_mismatch", "ECDSA operation step-up signer facts changed before authorized-operation admission");
2427
+ const claimResult = await claimRouterAbEcdsaOperationStepUp({
2428
+ operationKind: "evm.sign_transaction",
2429
+ operation: {
2430
+ operation_id: request.operation_id,
2431
+ operation_digests: request.operation_digests,
2432
+ material_activation: request.material_activation
2433
+ },
2434
+ materialActivation: freshMaterial.materialActivation,
2435
+ keyHandle: freshMaterial.keyHandle,
2436
+ authenticated
2437
+ });
2438
+ if (!claimResult) return routerAbStepUpError(409, "authorized_operation_missing", "Authorized operation is unavailable");
2439
+ if ("status" in claimResult) return claimResult;
2440
+ return {
2441
+ operation: claimResult.operation,
2442
+ session: authenticated.session,
2443
+ admissionKind: claimResult.kind
2444
+ };
2445
+ }
2446
+ async function authorizeRouterAbEcdsaDerivationNormalSigningRoute(input) {
2447
+ let requestedAuthorizationKind;
2448
+ try {
2449
+ requestedAuthorizationKind = parseRouterAbEcdsaOperationStepUpRequest({
2450
+ phase: input.phase,
2451
+ body: input.body
2452
+ }).authorization.kind;
2453
+ } catch (error) {
2454
+ return {
2455
+ ok: false,
2456
+ result: routerAbStepUpError(400, "invalid_body", errorMessage(error))
2457
+ };
2458
+ }
2459
+ if (requestedAuthorizationKind === "operation_step_up") {
2460
+ const stepUp = await handleRouterAbEcdsaOperationStepUpRoute({
2461
+ body: input.body,
2462
+ headers: input.headers,
2463
+ authorizedOperations: input.authorizedOperations,
2464
+ authorizationSessions: input.authorizationSessions,
2465
+ admissionAdapter: input.admissionAdapter,
2466
+ resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation,
2467
+ phase: input.phase
2468
+ });
2469
+ if ("status" in stepUp) return {
2470
+ ok: false,
2471
+ result: stepUp
2472
+ };
2473
+ return {
2474
+ ok: true,
2475
+ kind: "operation_step_up",
2476
+ phase: input.phase,
2477
+ operation: stepUp.operation,
2478
+ session: stepUp.session,
2479
+ admissionKind: stepUp.admissionKind
2480
+ };
2481
+ }
2482
+ const validated = await validateRouterAbEcdsaDerivationWalletSessionInputs({
2483
+ headers: input.headers,
2484
+ authorizationSessions: input.authorizationSessions,
2485
+ operationKind: "evm.sign_transaction"
2486
+ });
2487
+ if (!validated.ok) {
2488
+ if (validated.code === "wallet_session_unavailable" && input.authorizationSessions) {
2489
+ const exhaustedCandidate = await resolveRouterAbEcdsaExhaustedCandidateAuthorization({
2490
+ phase: input.phase,
2491
+ body: input.body,
2492
+ headers: input.headers,
2493
+ authorizationSessions: input.authorizationSessions,
2494
+ admissionAdapter: input.admissionAdapter,
2495
+ resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation
2496
+ });
2497
+ if (exhaustedCandidate) return exhaustedCandidate;
2498
+ }
2499
+ const stepUp = await resolveRouterAbEcdsaOwnerOperationStepUpPreparation({
2500
+ body: input.body,
2501
+ phase: input.phase,
2502
+ resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation
2503
+ });
2504
+ return {
2505
+ ok: false,
2506
+ result: routerAbEcdsaOwnerOperationFailureResult({
2507
+ status: routerAbWalletSessionValidationStatus(validated.code),
2508
+ code: validated.code,
2509
+ message: validated.message,
2510
+ phase: input.phase,
2511
+ stepUp
2512
+ })
2513
+ };
2514
+ }
2515
+ const session = validated.admission.context.authorization.session;
2516
+ const authorized = await authorizeRouterAbEcdsaWalletSessionRequest({
2517
+ phase: input.phase,
2518
+ body: input.body,
2519
+ session,
2520
+ admittedMaterialActivation: routerAbMpcMaterialActivationRefToWire(validated.admission.admission.materialActivation),
2521
+ admissionAdapter: input.admissionAdapter,
2522
+ resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation
2523
+ });
2524
+ if (!authorized.ok) return authorized;
2525
+ return {
2526
+ ok: true,
2527
+ kind: "wallet_session_operation_credential_v1",
2528
+ validated,
2529
+ admission: authorized.admission,
2530
+ activeMaterial: authorized.activeMaterial
2531
+ };
2532
+ }
2533
+ async function handleRouterAbEcdsaDerivationNormalSigningRouteCore(input) {
2534
+ const authorization = await authorizeRouterAbEcdsaDerivationNormalSigningRoute(input);
2535
+ if (!authorization.ok) return authorization.result;
2536
+ if (authorization.kind === "operation_step_up") return routerAbStepUpError(500, "internal", "Operation step-up must execute through the MPC router");
2537
+ const walletSession = authorization.kind === "wallet_session_operation_credential_v1" ? authorization.validated.admission.context.authorization.session : authorization.candidate.status.session;
2538
+ const privateBody = await buildRouterAbEcdsaDerivationPrivateSigningWorkerBody({
2539
+ phase: input.phase,
2540
+ body: input.body,
2541
+ authorization: {
2542
+ kind: "wallet_session_operation_credential_v1",
2543
+ walletSessionId: String(walletSession.walletSessionId),
2544
+ principalId: String(walletSession.principalId),
2545
+ runtimePolicyScope: authorization.activeMaterial.runtimePolicyScope
2546
+ },
2547
+ headers: input.headers
2548
+ });
2549
+ if (!input.authorizedOperations) return routerAbStepUpError(501, "not_configured", "Reusable Wallet Session authorization is not configured");
2550
+ const claimed = await admitRouterAbEcdsaReusableWalletSessionOperation({
2551
+ request: input.phase === "prepare" ? parseRouterAbEcdsaDerivationEvmDigestSigningRequestV1(input.body) : parseRouterAbEcdsaDerivationEvmDigestSigningFinalizeRequestV1(input.body),
2552
+ materialActivation: authorization.admission.materialActivation,
2553
+ binding: authorization.kind === "wallet_session_operation_credential_v1" ? {
2554
+ kind: "wallet_session_operation_credential_v1",
2555
+ context: authorization.validated.admission.context
2556
+ } : {
2557
+ kind: "wallet_session_operation_credential_exhausted_candidate_v1",
2558
+ candidate: authorization.candidate
2559
+ },
2560
+ authorizedOperations: input.authorizedOperations,
2561
+ resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation
2562
+ });
2563
+ if (!claimed.ok) return claimed.error;
2564
+ if (claimed.admission.kind === "replayed") return routerAbEcdsaReplayResult(claimed.admission.operation);
2565
+ const runtime = input.runtime;
2566
+ if (!runtime) return routerAbEcdsaPrivateSigningWorkerUnavailableResult();
2567
+ const signingWorker = runtime.getSigningWorkerPrivateTransport();
2568
+ if (signingWorker.kind === "unconfigured") return routerAbEcdsaPrivateSigningWorkerUnavailableResult();
2569
+ if (input.phase === "prepare") {
2570
+ if (claimed.admission.kind === "operation_in_progress") return routerAbEcdsaOperationInProgressResult();
2571
+ const operation = claimed.admission.operation;
2572
+ const replay = await runtime.reservePrepareReplay({
2573
+ curve: "ecdsa",
2574
+ authorizationIdentity: {
2575
+ kind: "reusable_wallet_session",
2576
+ walletSessionId: String(walletSession.walletSessionId)
2577
+ },
2578
+ requestId: authorization.admission.requestId,
2579
+ expiresAtMs: authorization.admission.expiresAtMs
2580
+ });
2581
+ if (!replay.ok) {
2582
+ await completeRouterAbEcdsaOperation({
2583
+ authorizedOperations: input.authorizedOperations,
2584
+ operation,
2585
+ result: "failed_before_side_effect",
2586
+ response: {
2587
+ status: replay.status,
2588
+ contentType: "application/json",
2589
+ bodyText: JSON.stringify({
2590
+ ok: false,
2591
+ code: replay.code,
2592
+ message: replay.message
2593
+ })
2594
+ }
2595
+ });
2596
+ return {
2597
+ status: replay.status,
2598
+ body: {
2599
+ ok: false,
2600
+ code: replay.code,
2601
+ message: replay.message
2602
+ }
2603
+ };
2604
+ }
2605
+ const forwarded = await postRouterAbSigningWorkerJson({
2606
+ config: signingWorker,
2607
+ path: input.privatePath,
2608
+ body: privateBody
2609
+ });
2610
+ if (!forwarded.ok && !isRouterAbEcdsaSigningWorkerOperationInProgress(forwarded)) await completeRouterAbEcdsaOperation({
2611
+ authorizedOperations: input.authorizedOperations,
2612
+ operation,
2613
+ result: forwarded.status < 500 ? "failed_before_side_effect" : "failed_after_side_effect",
2614
+ response: replayResponseFromSigningWorkerResult(forwarded)
2615
+ });
2616
+ return forwarded.ok ? {
2617
+ status: 200,
2618
+ body: forwarded.body
2619
+ } : {
2620
+ status: forwarded.status,
2621
+ body: forwarded.body
2622
+ };
2623
+ }
2624
+ if (claimed.admission.kind === "claimed") return routerAbStepUpError(409, "authorized_operation_missing", "ECDSA finalize requires a claimed prepare operation");
2625
+ const forwarded = await postRouterAbSigningWorkerJson({
2626
+ config: signingWorker,
2627
+ path: input.privatePath,
2628
+ body: privateBody
2629
+ });
2630
+ await completeRouterAbEcdsaOperation({
2631
+ authorizedOperations: input.authorizedOperations,
2632
+ operation: claimed.admission.operation,
2633
+ result: forwarded.ok ? "succeeded" : forwarded.status < 500 ? "failed_before_side_effect" : "failed_after_side_effect",
2634
+ response: replayResponseFromSigningWorkerResult(forwarded)
2635
+ });
2636
+ return forwarded.ok ? {
2637
+ status: 200,
2638
+ body: forwarded.body
2639
+ } : {
2640
+ status: forwarded.status,
2641
+ body: forwarded.body
2642
+ };
2643
+ }
2644
+ async function postRouterAbSigningWorkerJson(input) {
2645
+ const fetchImpl = resolveRouterAbSigningWorkerFetch(input.config.fetchImpl);
2646
+ if (!fetchImpl) return routerAbSigningError(500, "internal", "fetch is not available in this runtime");
2647
+ const response = await postRouterAbInternalServiceJson({
2648
+ url: privateSigningWorkerUrl(input.config, input.path),
2649
+ body: input.body,
2650
+ authSecret: input.config.auth.secret,
2651
+ fetchImpl
2652
+ });
2653
+ if (!response.ok && response.code === "network_error") return routerAbSigningError(502, "signing_worker_unreachable", `Router A/B SigningWorker request failed: ${response.message}`);
2654
+ if (!response.ok && response.code === "http_error") return routerAbSigningError(response.status || 502, "signing_worker_error", response.bodyText || `Router A/B SigningWorker returned HTTP ${response.status}`);
2655
+ if (!response.ok) return routerAbSigningError(502, "invalid_signing_worker_response", `Router A/B SigningWorker returned invalid JSON: ${response.message}`);
2656
+ return {
2657
+ ok: true,
2658
+ body: response.json,
2659
+ replay: {
2660
+ status: response.status,
2661
+ contentType: "application/json",
2662
+ bodyText: response.bodyText
2663
+ }
2664
+ };
2665
+ }
2666
+ //#endregion
2667
+ export { ROUTER_AB_ECDSA_DERIVATION_PRIVATE_SIGNING_PATHS, ROUTER_AB_ED25519_PRIVATE_SIGNING_PATHS, admitRouterAbEcdsaReusableWalletSessionOperation, authenticateRouterAbEcdsaOperationStepUp, authenticateRouterAbEcdsaOperationStepUpWithExhaustedCandidate, authenticateRouterAbWalletOperationStepUp, authenticateRouterAbWalletOperationStepUpIdentity, authorizeRouterAbEcdsaDerivationNormalSigningRoute, authorizeRouterAbEd25519NormalSigningRoute, buildRouterAbEcdsaAcceptedAuthorizedOperationV1, buildRouterAbEcdsaDerivationPrivateSigningWorkerBody, buildRouterAbEcdsaOwnerOperationStepUpPreparation, buildRouterAbEd25519AcceptedAuthorizedOperationV1, buildRouterAbEd25519OwnerOperationStepUpPreparation, buildRouterAbEd25519PrivateSigningWorkerBody, claimRouterAbEcdsaOperationStepUp, completeRouterAbEcdsaOperation, computeRouterAbEd25519NormalSigningAdmissionMaterial, decideRouterAbEcdsaOwnerOperationAuthorization, decideRouterAbEd25519OwnerOperationAuthorization, evaluateRouterAbNormalSigningAdmission, handleRouterAbEcdsaDerivationNormalSigningRouteCore, parseRouterAbEd25519NormalSigningScopeV2, parseRouterAbEd25519OperationStepUpScope, parseRouterAbOperationStepUpOperation, postRouterAbSigningWorkerJson, resolveFreshRouterAbEcdsaMaterialActivation, routerAbEcdsaAtomicAuthorizationConfigured, routerAbEcdsaOperationInProgressResult, routerAbEcdsaOwnerOperationFailureResult, routerAbEcdsaRecordedResponse, routerAbEcdsaReplayHttpResponse, routerAbEcdsaReplayResult, routerAbEcdsaReplayUnavailableResult, routerAbEd25519OwnerOperationFailureResult, routerAbNormalSigningMaterialSourceFromActiveLaneV1 };
2668
+
2669
+ //# sourceMappingURL=routerAbPrivateSigningWorker.js.map