@seams/wallet-server 0.6.1 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (705) hide show
  1. package/artifact-manifest.json +147 -32
  2. package/cloudflare-router-ab/build/deriver-a/build-stamp.json +1 -0
  3. package/cloudflare-router-ab/build/deriver-a/index.js +2 -2
  4. package/cloudflare-router-ab/build/deriver-a/index_bg.wasm +0 -0
  5. package/cloudflare-router-ab/build/deriver-b/build-stamp.json +1 -0
  6. package/cloudflare-router-ab/build/deriver-b/index.js +2 -2
  7. package/cloudflare-router-ab/build/deriver-b/index_bg.wasm +0 -0
  8. package/cloudflare-router-ab/build/local-tools/darwin-arm64/router_ab_local_init +0 -0
  9. package/cloudflare-router-ab/build/local-tools/darwin-x64/router_ab_local_init +0 -0
  10. package/cloudflare-router-ab/build/local-tools/linux-x64/router_ab_local_init +0 -0
  11. package/cloudflare-router-ab/build/router/build-stamp.json +1 -0
  12. package/cloudflare-router-ab/build/router/index.js +2 -2
  13. package/cloudflare-router-ab/build/router/index_bg.wasm +0 -0
  14. package/cloudflare-router-ab/build/signing-worker/build-stamp.json +1 -0
  15. package/cloudflare-router-ab/build/signing-worker/index.js +2 -2
  16. package/cloudflare-router-ab/build/signing-worker/index_bg.wasm +0 -0
  17. package/cloudflare-router-ab/build/tenant-root-control-plane/build-stamp.json +1 -0
  18. package/cloudflare-router-ab/build/tenant-root-control-plane/index.js +2 -2
  19. package/cloudflare-router-ab/build/tenant-root-control-plane/index_bg.wasm +0 -0
  20. package/cloudflare-router-ab/migrations/deriver-a/0012_tenant_root_creation_tombstones.sql +20 -0
  21. package/cloudflare-router-ab/migrations/deriver-a/0013_tenant_root_root_use_admissions.sql +32 -0
  22. package/cloudflare-router-ab/migrations/deriver-a/0014_tenant_root_refresh_supersessions.sql +24 -0
  23. package/cloudflare-router-ab/migrations/deriver-a/0015_tenant_root_root_use_attempts.sql +56 -0
  24. package/cloudflare-router-ab/migrations/deriver-a/0016_tenant_root_root_use_admission_settlement.sql +5 -0
  25. package/cloudflare-router-ab/migrations/deriver-a/0017_tenant_root_root_use_admission_claims.sql +64 -0
  26. package/cloudflare-router-ab/migrations/deriver-a/0018_tenant_root_recovery_retention_keys.sql +12 -0
  27. package/cloudflare-router-ab/migrations/deriver-b/0012_tenant_root_creation_tombstones.sql +20 -0
  28. package/cloudflare-router-ab/migrations/deriver-b/0013_tenant_root_root_use_admissions.sql +32 -0
  29. package/cloudflare-router-ab/migrations/deriver-b/0014_tenant_root_refresh_supersessions.sql +24 -0
  30. package/cloudflare-router-ab/migrations/deriver-b/0015_tenant_root_root_use_attempts.sql +56 -0
  31. package/cloudflare-router-ab/migrations/deriver-b/0016_tenant_root_root_use_admission_settlement.sql +5 -0
  32. package/cloudflare-router-ab/migrations/deriver-b/0017_tenant_root_root_use_admission_claims.sql +64 -0
  33. package/cloudflare-router-ab/migrations/deriver-b/0018_tenant_root_recovery_retention_keys.sql +12 -0
  34. package/cloudflare-router-ab/scripts/bootstrap-local-tenant-root.mjs +81 -16
  35. package/cloudflare-router-ab/scripts/prepare-local-runtime-config.mjs +102 -9
  36. package/cloudflare-router-ab/scripts/start-local-role-workers.mjs +4 -1
  37. package/cloudflare-router-ab/wrangler.deriver-a.toml +24 -0
  38. package/cloudflare-router-ab/wrangler.router.toml +13 -0
  39. package/dist/esm/authorization/capabilityPolicy.js +1 -1
  40. package/dist/esm/authorization/domain.js +2 -2
  41. package/dist/esm/authorization/factorEvidence.js +6 -100
  42. package/dist/esm/authorization/service.js +34 -2
  43. package/dist/esm/authorization/vaultProxyUse.js +3 -4
  44. package/dist/esm/cloud-host.js +16 -11
  45. package/dist/esm/core/EmailOtpRecords.js +19 -1
  46. package/dist/esm/core/EmailOtpStores.js +323 -924
  47. package/dist/esm/core/IdentityStore.js +44 -235
  48. package/dist/esm/core/NearPublicKeyStore.js +21 -63
  49. package/dist/esm/core/RegistrationCeremonyStore.js +3 -1793
  50. package/dist/esm/core/ThresholdService/config.js +1 -82
  51. package/dist/esm/core/ThresholdService/kv.js +3 -3
  52. package/dist/esm/core/ThresholdService/routerAb/ecdsaDerivationPoolFillHandlers.js +37 -5
  53. package/dist/esm/core/ThresholdService/routerAb/ecdsaDerivationPresignBridge.js +4 -74
  54. package/dist/esm/core/ThresholdService/stores/CloudflareDurableObjectStore.js +15 -51
  55. package/dist/esm/core/ThresholdService/stores/KeyStore.js +3 -3
  56. package/dist/esm/core/ThresholdService/stores/SessionStore.js +5 -81
  57. package/dist/esm/core/ThresholdService/stores/WalletSessionStore.js +185 -290
  58. package/dist/esm/core/ThresholdService/validation.js +18 -230
  59. package/dist/esm/core/WalletAuthMethodStore.js +22 -79
  60. package/dist/esm/core/WalletStore.js +58 -185
  61. package/dist/esm/core/WebAuthnAuthenticatorStore.js +57 -340
  62. package/dist/esm/core/WebAuthnCredentialBindingStore.js +90 -369
  63. package/dist/esm/core/WebAuthnLoginChallengeStore.js +17 -397
  64. package/dist/esm/core/WebAuthnSyncChallengeStore.js +17 -397
  65. package/dist/esm/core/authService/AuthService.js +2 -19
  66. package/dist/esm/core/authService/emailOtpChallengeProof.js +1 -1
  67. package/dist/esm/core/authService/emailOtpChallenges.js +1 -1
  68. package/dist/esm/core/authService/emailOtpConfig.js +1 -32
  69. package/dist/esm/core/authService/emailOtpRegistrationEnrollment.js +6 -153
  70. package/dist/esm/core/authService/googleEmailOtpRegistration.js +1 -1
  71. package/dist/esm/core/authService/nearPrivateKeySigning.js +7 -15
  72. package/dist/esm/core/authService/nearTransactions.js +2 -1
  73. package/dist/esm/core/authService/oidcVerification.js +3 -4
  74. package/dist/esm/core/authService/rateLimits.js +1 -31
  75. package/dist/esm/core/authService/registrationThresholdHelpers.js +2 -103
  76. package/dist/esm/core/authService/storeRegistry.js +2 -13
  77. package/dist/esm/core/authService/thresholdEcdsaKeyInventory.js +4 -5
  78. package/dist/esm/core/authService/webauthn.js +15 -50
  79. package/dist/esm/core/authService/webauthnOidcHelpers.js +1 -6
  80. package/dist/esm/core/authService/webauthnVerificationOutcomes.js +60 -0
  81. package/dist/esm/core/authService/webauthnWalletBinding.js +2 -122
  82. package/dist/esm/core/d1IdentityStore.js +32 -66
  83. package/dist/esm/core/d1TenantStore.js +82 -0
  84. package/dist/esm/core/d1WalletAuthMethodStore.js +92 -143
  85. package/dist/esm/core/d1WalletStore.js +14 -12
  86. package/dist/esm/core/deviceLinking/linkedDeviceEmailOtpGrant.js +10 -8
  87. package/dist/esm/core/deviceLinking/linkedDeviceManagement.js +25 -3
  88. package/dist/esm/core/deviceLinking/linkedDeviceSession.js +6 -895
  89. package/dist/esm/core/deviceLinking/linkedDeviceSessionApproval.js +102 -0
  90. package/dist/esm/core/deviceLinking/linkedDeviceSessionRecord.js +668 -0
  91. package/dist/esm/core/emailOtpD1Statements.js +383 -0
  92. package/dist/esm/core/hostedAccountIds.js +2 -2
  93. package/dist/esm/core/keyMaterialBrands.js +2 -48
  94. package/dist/esm/core/nearRelayerAccountProvisioning.js +25 -150
  95. package/dist/esm/core/nearSignerWasmRuntime.js +1 -4
  96. package/dist/esm/core/rpcClients/near/NearClient.js +15 -218
  97. package/dist/esm/core/signingLanes/LaneEnrollmentActivation.js +1 -1
  98. package/dist/esm/core/signingLanes/LaneLifecycleApplicationService.js +2 -4
  99. package/dist/esm/core/signingLanes/LaneLifecycleStore.js +0 -24
  100. package/dist/esm/core/signingLanes/WalletExecutionLaneProjection.js +5 -5
  101. package/dist/esm/core/signingLanes/ecdsaServerRetirement.js +3 -8
  102. package/dist/esm/core/signingLanes/ed25519ServerRetirement.js +1 -4
  103. package/dist/esm/core/storeBackends.js +208 -0
  104. package/dist/esm/core/thresholdEcdsaChainTarget.js +1 -7
  105. package/dist/esm/core/webAuthnD1Statements.js +92 -0
  106. package/dist/esm/core/webAuthnStoreBackends.js +198 -0
  107. package/dist/esm/hosted-wallet-gateway.js +33 -16
  108. package/dist/esm/index.js +2 -2
  109. package/dist/esm/local-hosted-wallet-gateway-worker.js +2 -23
  110. package/dist/esm/localHostedWalletGatewayHandler.js +299 -0
  111. package/dist/esm/localIntendedEcdsaFinalizeFault.js +85 -0
  112. package/dist/esm/localIntendedLinkExecuteFault.js +140 -0
  113. package/dist/esm/localIntendedRevokeFault.js +106 -0
  114. package/dist/esm/localIntendedSessionAdmissionFault.js +139 -0
  115. package/dist/esm/localIntendedYaoExportFault.js +117 -0
  116. package/dist/esm/localIntendedYaoFault.js +13 -16
  117. package/dist/esm/localIntendedYaoFinalizeFault.js +99 -0
  118. package/dist/esm/localIntendedYaoRecoveryFault.js +102 -0
  119. package/dist/esm/localIntendedYaoSigningFault.js +127 -0
  120. package/dist/esm/router/auth/authRequestValidation.js +1 -1
  121. package/dist/esm/router/auth/commonRouterUtils.js +10 -2
  122. package/dist/esm/router/auth/walletSessionFailure.js +1 -14
  123. package/dist/esm/router/cloudflare/d1/auth/d1AuthorizedOperationRouteService.js +23 -0
  124. package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthService.js +86 -66
  125. package/dist/esm/router/cloudflare/d1/authorization/authorizedOperationStatements.js +208 -0
  126. package/dist/esm/router/cloudflare/d1/authorization/d1AuthorizationStore.js +246 -296
  127. package/dist/esm/router/cloudflare/d1/authorization/persistedWalletSessionAuthorization.js +14 -0
  128. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceAuthorityInstallService.js +62 -63
  129. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEmailOtpGrantStore.js +3 -6
  130. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEmailOtpTargetFactor.js +1 -19
  131. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceManagementService.js +4 -3
  132. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceOwnerAuthorizationProvider.js +52 -9
  133. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceRequestProofNonceStore.js +3 -6
  134. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceRevocation.js +100 -0
  135. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionRecords.js +7 -10
  136. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionStore.js +33 -124
  137. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSourceContributionPreparationPlanner.js +2 -2
  138. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetCredentialProvider.js +9 -17
  139. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceVerifiedLinkBuilder.js +6 -6
  140. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceVerifiedLinkSourceReader.js +3 -1
  141. package/dist/esm/router/cloudflare/d1/deviceLinking/index.js +3 -3
  142. package/dist/esm/router/cloudflare/d1/deviceLinking/installedEcdsaAuthority.js +69 -0
  143. package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoCapabilityPersistence.js +39 -68
  144. package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoLifecycleDecisionStore.js +69 -0
  145. package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoProductRegistrationPartitionedStateStore.js +2 -2
  146. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeStore.js +26 -71
  147. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeVerifier.js +20 -3
  148. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpEnrollmentStore.js +7 -94
  149. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpGrantStore.js +5 -47
  150. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRecords.js +26 -123
  151. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRecoveryService.js +0 -2
  152. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRegistrationEnrollmentFinalizer.js +2 -2
  153. package/dist/esm/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpRegistrationAttemptStore.js +15 -134
  154. package/dist/esm/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpRegistrationRecords.js +54 -260
  155. package/dist/esm/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpSessionResolver.js +1 -1
  156. package/dist/esm/router/cloudflare/d1/identity/d1IdentityRecords.js +1 -28
  157. package/dist/esm/router/cloudflare/d1/near/d1NearPublicKeyStore.js +2 -8
  158. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1PasskeyCustodyEnvelopeStore.js +1 -1
  159. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1PasskeyCustodyRouteService.js +3 -3
  160. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletCustodyCommitStore.js +23 -73
  161. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpRecords.js +15 -2
  162. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpService.js +12 -203
  163. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyRecordStore.js +16 -32
  164. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyRecords.js +29 -72
  165. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyStore.js +4 -1
  166. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationIntentService.js +3 -1
  167. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationCommitStore.js +6 -30
  168. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationService.js +261 -205
  169. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationSetup.js +5 -3
  170. package/dist/esm/router/cloudflare/d1/registration/walletRegistrationEstablishedSessionIssuer.js +2 -2
  171. package/dist/esm/router/cloudflare/d1/registration/walletRegistrationSessionCommitReceipt.js +3 -3
  172. package/dist/esm/router/cloudflare/d1/signingAdmission/d1RouterAbNormalSigningAdmissionStore.js +43 -25
  173. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneEffectJournalStore.js +0 -1
  174. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneLifecycleStore.js +1 -1
  175. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneRecords.js +2 -1
  176. package/dist/esm/router/cloudflare/d1/versionedJson/d1VersionedJsonRecordStore.js +2 -60
  177. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAddSignerService.js +158 -19
  178. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthMethodBoundary.js +19 -49
  179. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthMethodRevocationReplayStore.js +100 -0
  180. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthMethodService.js +132 -33
  181. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorityStore.js +83 -4
  182. package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnAuthService.js +14 -49
  183. package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnRecords.js +4 -4
  184. package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnStore.js +22 -116
  185. package/dist/esm/router/cloudflare/runtime/createSelfHostedCloudflareSigningWorker.js +1 -2
  186. package/dist/esm/router/cloudflare/runtime/walletConsoleTenantRootLineage.js +11 -2
  187. package/dist/esm/router/cloudflare/runtime/walletGateway.js +1 -1
  188. package/dist/esm/router/cloudflare/signingLanes/cloudflareLaneCurveExecution.js +5 -6
  189. package/dist/esm/router/cloudflare/signingLanes/cloudflareLaneProtocolCommitter.js +2 -1
  190. package/dist/esm/router/cloudflare/signingLanes/cloudflareOrdinaryInactiveSignerMaterialReservation.js +48 -21
  191. package/dist/esm/router/cloudflare.js +11480 -12853
  192. package/dist/esm/router/domains/ecdsa/routerAbEcdsaStrictRegistration.js +16 -5
  193. package/dist/esm/router/domains/ecdsa/thresholdEcdsaRequestValidation.js +2 -8
  194. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoLifecycleDecision.js +33 -0
  195. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.js +17 -9
  196. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitionedStateStore.js +29 -431
  197. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitioning.js +7 -2
  198. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRunner.js +2 -1
  199. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRuntime.js +70 -2
  200. package/dist/esm/router/domains/ed25519Yao/export/routerAbEd25519YaoExport.js +134 -169
  201. package/dist/esm/router/domains/ed25519Yao/export/routerAbEd25519YaoExportRequestScopedCloudflare.js +77 -162
  202. package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecovery.js +205 -51
  203. package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryRequestScopedCloudflare.js +29 -11
  204. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoHttpRegistrationBackend.js +182 -55
  205. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistration.js +2 -1
  206. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationExecutionRecord.js +63 -247
  207. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationIntentAuthorization.js +3 -2
  208. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationRequestScopedCloudflare.js +87 -132
  209. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationTwoPhaseRunner.js +5 -4
  210. package/dist/esm/router/domains/ed25519Yao/routerAbEd25519YaoGatewayEnvelope.js +45 -0
  211. package/dist/esm/router/domains/ed25519Yao/session/thresholdEd25519RequestValidation.js +1 -1
  212. package/dist/esm/router/domains/emailOtp/emailOtpExportPolicy.js +1 -42
  213. package/dist/esm/router/domains/emailOtp/emailOtpRequestValidation.js +1 -6
  214. package/dist/esm/router/domains/emailOtp/emailOtpSessionRouteHelpers.js +1 -142
  215. package/dist/esm/router/domains/passkeyCustody/passkeyCustodyEnvelopeRetrievalRoute.js +1 -1
  216. package/dist/esm/router/domains/passkeyCustody/walletCustodyRegistrationCommit.js +2 -2
  217. package/dist/esm/router/domains/passkeyCustody/walletRecoveryFinalization.js +23 -45
  218. package/dist/esm/router/domains/passkeyCustody/walletRecoveryKeyManifest.js +5 -5
  219. package/dist/esm/router/domains/signingOperations/ed25519AuthorizedOperationReceipt.js +1 -1
  220. package/dist/esm/router/domains/signingOperations/routerAbEcdsaDerivationNormalSigningRoute.js +827 -0
  221. package/dist/esm/router/domains/signingOperations/routerAbEd25519NormalSigningRoute.js +698 -0
  222. package/dist/esm/router/domains/signingOperations/routerAbNormalSigningAdmission.js +209 -0
  223. package/dist/esm/router/domains/signingOperations/routerAbNormalSigningAdmissionCore.js +16 -15
  224. package/dist/esm/router/domains/signingOperations/routerAbOperationStepUp.js +313 -0
  225. package/dist/esm/router/domains/signingOperations/routerAbPrivateSigningWorker.js +62 -2159
  226. package/dist/esm/router/domains/tenantRoot/tenantRootIdentityResolution.js +1 -1
  227. package/dist/esm/router/domains/walletRegistration/walletRegistrationRoutes.js +18 -22
  228. package/dist/esm/router/domains/walletRegistration/walletRegistrationSetupPayload.js +3 -4
  229. package/dist/esm/router/domains/walletUnlock/walletUnlockRequestedCapabilitiesValidation.js +2 -2
  230. package/dist/esm/router/domains/walletUnlock/walletUnlockRouteHandlers.js +97 -150
  231. package/dist/esm/router/express.js +5967 -6410
  232. package/dist/esm/router/framework/http.js +1 -4
  233. package/dist/esm/router/framework/ror/normalize.js +1 -1
  234. package/dist/esm/router/framework/routerApiRouteSurface.js +1 -1
  235. package/dist/esm/router/node/nodeHostedWalletGateway.js +64 -0
  236. package/dist/esm/router/node/nodeHostedWalletGatewayCheck.js +163 -0
  237. package/dist/esm/router/node/nodeHostedWalletGatewayMain.js +120 -0
  238. package/dist/esm/router/node/nodeHttp.js +79 -0
  239. package/dist/esm/router/node/nodeSqlite.js +43 -0
  240. package/dist/esm/router/node/signerSqlMigrations.js +48 -0
  241. package/dist/esm/router/transport/fetch/createFetchRouter.js +1 -1
  242. package/dist/esm/router/transport/fetch/routes/deviceLinking.js +16 -18
  243. package/dist/esm/router/transport/fetch/routes/deviceLinkingOwnerAuthorization.js +3 -5
  244. package/dist/esm/router/transport/fetch/routes/deviceManagement.js +15 -24
  245. package/dist/esm/router/transport/fetch/routes/normalSigningRouterProxy.js +3 -16
  246. package/dist/esm/router/transport/fetch/routes/passkeyCustody.js +144 -461
  247. package/dist/esm/router/transport/fetch/routes/sessions.js +4 -4
  248. package/dist/esm/router/transport/fetch/routes/syncAccount.js +4 -6
  249. package/dist/esm/router/transport/fetch/routes/syncAccountBootstrap.js +2 -2
  250. package/dist/esm/router/transport/fetch/routes/thresholdEcdsa.js +69 -23
  251. package/dist/esm/router/transport/fetch/routes/thresholdEd25519.js +52 -27
  252. package/dist/esm/shared-ts/src/authorization/capabilityKinds.js +1 -1
  253. package/dist/esm/shared-ts/src/authorization/delegatedAuthority.js +1 -1
  254. package/dist/esm/shared-ts/src/authorization/operationFingerprint.js +1 -2
  255. package/dist/esm/shared-ts/src/authorization/walletAuthority.js +99 -227
  256. package/dist/esm/shared-ts/src/authorization/walletCustodyOperation.js +4 -6
  257. package/dist/esm/shared-ts/src/device-linking/activeWalletSession.js +74 -0
  258. package/dist/esm/shared-ts/src/device-linking/authorityActivation.js +50 -0
  259. package/dist/esm/shared-ts/src/device-linking/committedSignerPackages.js +8 -9
  260. package/dist/esm/shared-ts/src/device-linking/delegatedActivationPlan.js +3 -1
  261. package/dist/esm/shared-ts/src/device-linking/deviceManagement.js +55 -0
  262. package/dist/esm/shared-ts/src/device-linking/digests.js +10 -65
  263. package/dist/esm/shared-ts/src/device-linking/ed25519ExportRoot.js +3 -1
  264. package/dist/esm/shared-ts/src/device-linking/index.js +4 -1
  265. package/dist/esm/shared-ts/src/device-linking/parsers.js +510 -1063
  266. package/dist/esm/shared-ts/src/device-linking/requestProof.js +5 -14
  267. package/dist/esm/shared-ts/src/device-linking/sourceContribution.js +6 -9
  268. package/dist/esm/shared-ts/src/device-linking/walletSessionCredentialDelivery.js +9 -9
  269. package/dist/esm/shared-ts/src/device-linking/wireFields.js +59 -0
  270. package/dist/esm/shared-ts/src/near/nearClient.js +252 -0
  271. package/dist/esm/shared-ts/src/passkey-custody/credentialActivity.js +3 -1
  272. package/dist/esm/shared-ts/src/passkey-custody/custodyEnvelope.js +7 -5
  273. package/dist/esm/shared-ts/src/passkey-custody/custodySecretBinding.js +6 -4
  274. package/dist/esm/shared-ts/src/passkey-custody/primitives.js +5 -39
  275. package/dist/esm/shared-ts/src/signing-lanes/evmFamilySigningKeySlotId.js +1 -5
  276. package/dist/esm/shared-ts/src/signing-lanes/index.js +3 -3
  277. package/dist/esm/shared-ts/src/signing-lanes/ownerContinuity.js +5 -12
  278. package/dist/esm/shared-ts/src/signing-lanes/participantDigest.js +5 -14
  279. package/dist/esm/shared-ts/src/signing-lanes/participants.js +2 -5
  280. package/dist/esm/shared-ts/src/signing-lanes/recordParsers.js +7 -5
  281. package/dist/esm/shared-ts/src/signing-lanes/rotationDigests.js +6 -45
  282. package/dist/esm/shared-ts/src/signing-lanes/rotationParsers.js +423 -1511
  283. package/dist/esm/shared-ts/src/signing-lanes/rotationProtocolParsers.js +323 -0
  284. package/dist/esm/shared-ts/src/signing-lanes/rotationWireFields.js +59 -0
  285. package/dist/esm/shared-ts/src/tenant-root/tenantRootOperationRecord.js +1 -1
  286. package/dist/esm/shared-ts/src/threshold/ecdsaDerivationRoleLocalBootstrap.js +1 -2
  287. package/dist/esm/shared-ts/src/threshold/keyMaterialBrands.js +49 -0
  288. package/dist/esm/shared-ts/src/utils/addAuthMethodRegistration.js +3 -4
  289. package/dist/esm/shared-ts/src/utils/canonicalPrimitives.js +8 -1
  290. package/dist/esm/shared-ts/src/utils/digestEncoding.js +63 -0
  291. package/dist/esm/shared-ts/src/utils/emailOtpDomain.js +2 -2
  292. package/dist/esm/shared-ts/src/utils/exactRecord.js +44 -0
  293. package/dist/esm/shared-ts/src/utils/registrationAuthMethodInput.js +127 -0
  294. package/dist/esm/shared-ts/src/utils/registrationEstablishedSession.js +2 -2
  295. package/dist/esm/shared-ts/src/utils/registrationIds.js +280 -0
  296. package/dist/esm/shared-ts/src/utils/registrationIntent.js +4 -1170
  297. package/dist/esm/shared-ts/src/utils/registrationSignerPlan.js +429 -0
  298. package/dist/esm/shared-ts/src/utils/routerAbEcdsaDerivation.js +11 -136
  299. package/dist/esm/shared-ts/src/utils/routerAbEd25519Yao.js +3 -163
  300. package/dist/esm/shared-ts/src/utils/routerAbEd25519YaoDigests.js +160 -0
  301. package/dist/esm/shared-ts/src/utils/routerAbNormalSigningIdentity.js +1 -4
  302. package/dist/esm/shared-ts/src/utils/routerAbPublicKeyset.js +7 -15
  303. package/dist/esm/shared-ts/src/utils/validation.js +37 -6
  304. package/dist/esm/shared-ts/src/utils/walletAuthMethodRecord.js +362 -0
  305. package/dist/esm/shared-ts/src/utils/wireSchema.js +77 -0
  306. package/dist/esm/shared-ts/src/wallet-recovery/recoveryCodeLocator.js +1 -1
  307. package/dist/esm/shared-ts/src/wallet-recovery/recoveryCodeReservation.js +1 -1
  308. package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryCommittedProjection.js +7 -11
  309. package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryEcdsaPossession.js +4 -8
  310. package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryEnvelopeSet.js +3 -1
  311. package/dist/esm/storage/d1Sql.js +10 -1
  312. package/dist/esm/storage/syncSqlite.js +79 -0
  313. package/dist/esm/threshold/session/signingSessionSeal/crypto/cipher.js +1 -1
  314. package/dist/esm/threshold/session/signingSessionSeal/crypto/shamir3PassWasm.js +1 -1
  315. package/dist/esm/threshold/session/signingSessionSeal/idempotencyRecords.js +1 -2
  316. package/dist/esm/threshold/session/signingSessionSeal/options.js +1 -1
  317. package/dist/esm/threshold/session/signingSessionSeal/transport/shared.js +18 -55
  318. package/dist/esm/threshold/statusCodes.js +1 -1
  319. package/dist/esm/wasm/near_signer/pkg/wasm_signer_worker.js +3 -3
  320. package/dist/esm/wasm/near_signer/pkg/wasm_signer_worker_bg.wasm +0 -0
  321. package/dist/esm/wasm/router_ab_ecdsa_signing_worker/pkg/router_ab_ecdsa_signing_worker_bg.wasm +0 -0
  322. package/dist/types/shared-ts/src/authorization/capabilityKinds.d.ts +8 -26
  323. package/dist/types/shared-ts/src/authorization/delegatedAuthority.d.ts +0 -8
  324. package/dist/types/shared-ts/src/authorization/operationFingerprint.d.ts +1 -3
  325. package/dist/types/shared-ts/src/authorization/walletAuthority.d.ts +25 -12
  326. package/dist/types/shared-ts/src/authorization/walletSessionIssuance.d.ts +2 -1
  327. package/dist/types/shared-ts/src/device-linking/activeWalletSession.d.ts +3 -2
  328. package/dist/types/shared-ts/src/device-linking/authorityActivation.d.ts +5 -0
  329. package/dist/types/shared-ts/src/device-linking/committedSignerPackages.d.ts +2 -5
  330. package/dist/types/shared-ts/src/device-linking/contracts.d.ts +8 -11
  331. package/dist/types/shared-ts/src/device-linking/contracts.typecheck.d.ts +2 -1
  332. package/dist/types/shared-ts/src/device-linking/deviceManagement.d.ts +7 -0
  333. package/dist/types/shared-ts/src/device-linking/digests.d.ts +0 -5
  334. package/dist/types/shared-ts/src/device-linking/ed25519ExportRoot.d.ts +3 -2
  335. package/dist/types/shared-ts/src/device-linking/index.d.ts +2 -0
  336. package/dist/types/shared-ts/src/device-linking/parsers.d.ts +4 -41
  337. package/dist/types/shared-ts/src/device-linking/requestProof.d.ts +0 -1
  338. package/dist/types/shared-ts/src/device-linking/sourceContribution.d.ts +3 -2
  339. package/dist/types/shared-ts/src/device-linking/walletSessionCredentialDelivery.d.ts +2 -1
  340. package/dist/types/shared-ts/src/device-linking/wireFields.d.ts +26 -0
  341. package/dist/types/shared-ts/src/near/actions.d.ts +4 -4
  342. package/dist/types/shared-ts/src/near/delegate.d.ts +3 -2
  343. package/dist/types/shared-ts/src/near/nearClient.d.ts +145 -0
  344. package/dist/types/shared-ts/src/passkey-custody/ceremonyCommitPayload.d.ts +0 -22
  345. package/dist/types/shared-ts/src/passkey-custody/credentialActivity.d.ts +2 -4
  346. package/dist/types/shared-ts/src/passkey-custody/custodyEnvelope.d.ts +9 -18
  347. package/dist/types/shared-ts/src/passkey-custody/custodySecretBinding.d.ts +8 -24
  348. package/dist/types/shared-ts/src/passkey-custody/index.d.ts +0 -2
  349. package/dist/types/shared-ts/src/passkey-custody/primitives.d.ts +0 -14
  350. package/dist/types/shared-ts/src/signing-lanes/evmFamilySigningKeySlotId.d.ts +0 -15
  351. package/dist/types/shared-ts/src/signing-lanes/execution.d.ts +2 -51
  352. package/dist/types/shared-ts/src/signing-lanes/index.d.ts +1 -2
  353. package/dist/types/shared-ts/src/signing-lanes/ownerContinuity.d.ts +1 -2
  354. package/dist/types/shared-ts/src/signing-lanes/participantDigest.d.ts +5 -27
  355. package/dist/types/shared-ts/src/signing-lanes/participants.d.ts +0 -11
  356. package/dist/types/shared-ts/src/signing-lanes/recordParsers.d.ts +6 -53
  357. package/dist/types/shared-ts/src/signing-lanes/records.d.ts +1 -2
  358. package/dist/types/shared-ts/src/signing-lanes/rotation.d.ts +15 -37
  359. package/dist/types/shared-ts/src/signing-lanes/rotationDigests.d.ts +1 -20
  360. package/dist/types/shared-ts/src/signing-lanes/rotationLifecycle.d.ts +4 -25
  361. package/dist/types/shared-ts/src/signing-lanes/rotationParsers.d.ts +1 -41
  362. package/dist/types/shared-ts/src/signing-lanes/rotationProtocolParsers.d.ts +6 -0
  363. package/dist/types/shared-ts/src/signing-lanes/rotationWireFields.d.ts +20 -0
  364. package/dist/types/shared-ts/src/threshold/ecdsaDerivationRoleLocalBootstrap.d.ts +2 -35
  365. package/dist/types/shared-ts/src/threshold/ed25519OperationFingerprint.d.ts +8 -35
  366. package/dist/types/shared-ts/src/threshold/keyMaterialBrands.d.ts +25 -0
  367. package/dist/types/shared-ts/src/threshold/participants.d.ts +3 -9
  368. package/dist/types/shared-ts/src/threshold/secp256k1.d.ts +0 -37
  369. package/dist/types/shared-ts/src/threshold/sessionPolicy.d.ts +24 -0
  370. package/dist/types/shared-ts/src/threshold/signingRootScope.d.ts +2 -5
  371. package/dist/types/shared-ts/src/utils/addAuthMethodRegistration.d.ts +3 -4
  372. package/dist/types/shared-ts/src/utils/addWalletAuthMethod.d.ts +7 -108
  373. package/dist/types/shared-ts/src/utils/addWalletAuthMethod.typecheck.d.ts +16 -3
  374. package/dist/types/shared-ts/src/utils/canonicalPrimitives.d.ts +2 -0
  375. package/dist/types/shared-ts/src/utils/digestEncoding.d.ts +9 -0
  376. package/dist/types/shared-ts/src/utils/domainIds.d.ts +1 -2
  377. package/dist/types/shared-ts/src/utils/ecdsaKeyFactsInventory.d.ts +1 -2
  378. package/dist/types/shared-ts/src/utils/emailOtpDomain.d.ts +5 -5
  379. package/dist/types/shared-ts/src/utils/emailOtpRecoveryKey.d.ts +0 -2
  380. package/dist/types/shared-ts/src/utils/errors.d.ts +0 -7
  381. package/dist/types/shared-ts/src/utils/exactRecord.d.ts +12 -0
  382. package/dist/types/shared-ts/src/utils/index.d.ts +5 -2
  383. package/dist/types/shared-ts/src/utils/jsonRpc.d.ts +3 -2
  384. package/dist/types/shared-ts/src/utils/near.d.ts +2 -1
  385. package/dist/types/shared-ts/src/utils/nearRpcResults.d.ts +7 -7
  386. package/dist/types/shared-ts/src/utils/normalize.d.ts +0 -4
  387. package/dist/types/shared-ts/src/utils/registrationAuthMethodInput.d.ts +184 -0
  388. package/dist/types/shared-ts/src/utils/registrationContracts.d.ts +76 -0
  389. package/dist/types/shared-ts/src/utils/registrationEstablishedSession.d.ts +1 -2
  390. package/dist/types/shared-ts/src/utils/registrationIds.d.ts +56 -0
  391. package/dist/types/shared-ts/src/utils/registrationIntent.d.ts +9 -514
  392. package/dist/types/shared-ts/src/utils/registrationSignerPlan.d.ts +142 -0
  393. package/dist/types/shared-ts/src/utils/routerAbEcdsaDerivation.d.ts +21 -92
  394. package/dist/types/shared-ts/src/utils/routerAbEd25519Yao.d.ts +14 -99
  395. package/dist/types/shared-ts/src/utils/routerAbEd25519YaoDigests.d.ts +39 -0
  396. package/dist/types/shared-ts/src/utils/routerAbPublicKeyset.d.ts +10 -15
  397. package/dist/types/shared-ts/src/utils/routerAbTraceContext.d.ts +2 -1
  398. package/dist/types/shared-ts/src/utils/secureRandomId.d.ts +0 -2
  399. package/dist/types/shared-ts/src/utils/signerDomain.d.ts +3 -35
  400. package/dist/types/shared-ts/src/utils/signerSlot.d.ts +0 -4
  401. package/dist/types/shared-ts/src/utils/signingSessionSeal.d.ts +1 -7
  402. package/dist/types/shared-ts/src/utils/validation.d.ts +10 -10
  403. package/dist/types/shared-ts/src/utils/variant.d.ts +11 -0
  404. package/dist/types/shared-ts/src/utils/variant.typecheck.d.ts +22 -0
  405. package/dist/types/shared-ts/src/utils/walletAddSignerActivation.d.ts +2 -2
  406. package/dist/types/shared-ts/src/utils/walletAuthAuthority.d.ts +1 -58
  407. package/dist/types/shared-ts/src/utils/walletAuthMethodRecord.d.ts +104 -0
  408. package/dist/types/shared-ts/src/utils/walletCapabilityBindings.d.ts +3 -7
  409. package/dist/types/shared-ts/src/utils/webauthnDeviceInfo.d.ts +3 -4
  410. package/dist/types/shared-ts/src/utils/wireSchema.d.ts +60 -0
  411. package/dist/types/shared-ts/src/wallet-recovery/backupAcknowledgement.d.ts +2 -1
  412. package/dist/types/shared-ts/src/wallet-recovery/index.d.ts +0 -1
  413. package/dist/types/shared-ts/src/wallet-recovery/recoveryCodeLocator.d.ts +0 -16
  414. package/dist/types/shared-ts/src/wallet-recovery/recoveryCodeReservation.d.ts +2 -11
  415. package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryCommittedProjection.d.ts +6 -18
  416. package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryEcdsaPossession.d.ts +0 -2
  417. package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryEnvelopeSet.d.ts +1 -3
  418. package/dist/types/wallet-server/src/authorization/capabilityPolicy.d.ts +0 -1
  419. package/dist/types/wallet-server/src/authorization/domain.d.ts +25 -5
  420. package/dist/types/wallet-server/src/authorization/ecdsaWalletSessionAdmission.d.ts +37 -0
  421. package/dist/types/wallet-server/src/authorization/ecdsaWalletSessionAdmission.typecheck.d.ts +2 -0
  422. package/dist/types/wallet-server/src/authorization/factorEvidence.d.ts +6 -7
  423. package/dist/types/wallet-server/src/authorization/service.d.ts +52 -3
  424. package/dist/types/wallet-server/src/cloud-host.d.ts +6 -2
  425. package/dist/types/wallet-server/src/core/EmailOtpRecords.d.ts +10 -1
  426. package/dist/types/wallet-server/src/core/EmailOtpStores.d.ts +16 -116
  427. package/dist/types/wallet-server/src/core/IdentityStore.d.ts +2 -7
  428. package/dist/types/wallet-server/src/core/NearPublicKeyStore.d.ts +6 -16
  429. package/dist/types/wallet-server/src/core/RegistrationCeremonyStore.d.ts +29 -90
  430. package/dist/types/wallet-server/src/core/ThresholdService/config.d.ts +0 -12
  431. package/dist/types/wallet-server/src/core/ThresholdService/routerAb/ecdsaDerivationPoolFillHandlers.d.ts +10 -3
  432. package/dist/types/wallet-server/src/core/ThresholdService/routerAb/ecdsaDerivationPresignBridge.d.ts +17 -48
  433. package/dist/types/wallet-server/src/core/ThresholdService/routerAb/internalServiceHttp.d.ts +2 -1
  434. package/dist/types/wallet-server/src/core/ThresholdService/stores/CloudflareDurableObjectStore.d.ts +4 -71
  435. package/dist/types/wallet-server/src/core/ThresholdService/stores/KeyStore.d.ts +2 -1
  436. package/dist/types/wallet-server/src/core/ThresholdService/stores/SessionStore.d.ts +4 -8
  437. package/dist/types/wallet-server/src/core/ThresholdService/stores/StoreConfig.d.ts +2 -1
  438. package/dist/types/wallet-server/src/core/ThresholdService/stores/WalletSessionStore.d.ts +1 -3
  439. package/dist/types/wallet-server/src/core/ThresholdService/validation.d.ts +14 -47
  440. package/dist/types/wallet-server/src/core/WalletAuthMethodStore.d.ts +2 -7
  441. package/dist/types/wallet-server/src/core/WalletStore.d.ts +3 -8
  442. package/dist/types/wallet-server/src/core/WebAuthnAuthenticatorStore.d.ts +7 -22
  443. package/dist/types/wallet-server/src/core/WebAuthnCredentialBindingStore.d.ts +14 -36
  444. package/dist/types/wallet-server/src/core/WebAuthnLoginChallengeStore.d.ts +9 -34
  445. package/dist/types/wallet-server/src/core/WebAuthnSyncChallengeStore.d.ts +9 -34
  446. package/dist/types/wallet-server/src/core/authService/AuthService.d.ts +0 -3
  447. package/dist/types/wallet-server/src/core/authService/emailOtpChallengeOperations.d.ts +6 -5
  448. package/dist/types/wallet-server/src/core/authService/emailOtpChallengeProof.d.ts +9 -17
  449. package/dist/types/wallet-server/src/core/authService/emailOtpChallengeVerification.d.ts +3 -2
  450. package/dist/types/wallet-server/src/core/authService/emailOtpChallenges.d.ts +7 -23
  451. package/dist/types/wallet-server/src/core/authService/emailOtpConfig.d.ts +3 -10
  452. package/dist/types/wallet-server/src/core/authService/emailOtpDelivery.d.ts +4 -3
  453. package/dist/types/wallet-server/src/core/authService/emailOtpGrant.d.ts +4 -3
  454. package/dist/types/wallet-server/src/core/authService/emailOtpRegistrationEnrollment.d.ts +3 -70
  455. package/dist/types/wallet-server/src/core/authService/emailOtpSeal.d.ts +3 -2
  456. package/dist/types/wallet-server/src/core/authService/emailOtpUnlock.d.ts +4 -3
  457. package/dist/types/wallet-server/src/core/authService/googleEmailOtpRegistration.d.ts +5 -8
  458. package/dist/types/wallet-server/src/core/authService/nearPrivateKeySigning.d.ts +3 -2
  459. package/dist/types/wallet-server/src/core/authService/nearPublicKeyMetadata.d.ts +2 -1
  460. package/dist/types/wallet-server/src/core/authService/nearTransactions.d.ts +2 -1
  461. package/dist/types/wallet-server/src/core/authService/oidcVerification.d.ts +4 -3
  462. package/dist/types/wallet-server/src/core/authService/rateLimits.d.ts +0 -3
  463. package/dist/types/wallet-server/src/core/authService/registrationThresholdHelpers.d.ts +0 -26
  464. package/dist/types/wallet-server/src/core/authService/storeRegistry.d.ts +0 -5
  465. package/dist/types/wallet-server/src/core/authService/thresholdEcdsaKeyInventory.d.ts +0 -23
  466. package/dist/types/wallet-server/src/core/authService/webauthn.d.ts +8 -16
  467. package/dist/types/wallet-server/src/core/authService/webauthnOidcHelpers.d.ts +7 -7
  468. package/dist/types/wallet-server/src/core/authService/webauthnVerificationOutcomes.d.ts +43 -0
  469. package/dist/types/wallet-server/src/core/authService/webauthnWalletBinding.d.ts +1 -28
  470. package/dist/types/wallet-server/src/core/d1IdentityStore.d.ts +6 -16
  471. package/dist/types/wallet-server/src/core/d1TenantStore.d.ts +51 -0
  472. package/dist/types/wallet-server/src/core/d1WalletAuthMethodStore.d.ts +11 -29
  473. package/dist/types/wallet-server/src/core/d1WalletStore.d.ts +6 -1
  474. package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceEd25519ExportRoot.d.ts +2 -1
  475. package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceEmailOtpGrant.d.ts +2 -1
  476. package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceManagement.d.ts +44 -26
  477. package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceSession.d.ts +19 -217
  478. package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceSessionApproval.d.ts +8 -0
  479. package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceSessionRecord.d.ts +259 -0
  480. package/dist/types/wallet-server/src/core/deviceLinking/requestProof.d.ts +2 -2
  481. package/dist/types/wallet-server/src/core/emailOtpD1Statements.d.ts +54 -0
  482. package/dist/types/wallet-server/src/core/hostedAccountIds.d.ts +0 -15
  483. package/dist/types/wallet-server/src/core/keyMaterialBrands.d.ts +4 -24
  484. package/dist/types/wallet-server/src/core/nearRelayerAccountProvisioning.d.ts +2 -3
  485. package/dist/types/wallet-server/src/core/nearSignerWasmRuntime.d.ts +0 -1
  486. package/dist/types/wallet-server/src/core/registrationContracts.d.ts +37 -108
  487. package/dist/types/wallet-server/src/core/routerAbSigning/RouterAbNormalSigningRuntime.d.ts +5 -4
  488. package/dist/types/wallet-server/src/core/rpcClients/near/NearClient.d.ts +10 -106
  489. package/dist/types/wallet-server/src/core/signingLanes/LaneAggregateRevocationApplicationService.d.ts +4 -3
  490. package/dist/types/wallet-server/src/core/signingLanes/LaneEffectJournalStore.d.ts +2 -3
  491. package/dist/types/wallet-server/src/core/signingLanes/LaneLifecycleStore.d.ts +2 -3
  492. package/dist/types/wallet-server/src/core/signingLanes/WalletExecutionLaneProjection.d.ts +3 -9
  493. package/dist/types/wallet-server/src/core/signingLanes/ecdsaServerRetirement.d.ts +4 -4
  494. package/dist/types/wallet-server/src/core/signingLanes/ed25519ServerRetirement.d.ts +3 -3
  495. package/dist/types/wallet-server/src/core/storeBackends.d.ts +83 -0
  496. package/dist/types/wallet-server/src/core/threeRouteRegistrationContracts.d.ts +13 -59
  497. package/dist/types/wallet-server/src/core/threeRouteRegistrationContracts.typecheck.d.ts +51 -3
  498. package/dist/types/wallet-server/src/core/thresholdEcdsaChainTarget.d.ts +0 -1
  499. package/dist/types/wallet-server/src/core/types.d.ts +3 -24
  500. package/dist/types/wallet-server/src/core/webAuthnD1Statements.d.ts +29 -0
  501. package/dist/types/wallet-server/src/core/webAuthnStoreBackends.d.ts +96 -0
  502. package/dist/types/wallet-server/src/hosted-wallet-gateway.d.ts +11 -7
  503. package/dist/types/wallet-server/src/index.d.ts +1 -1
  504. package/dist/types/wallet-server/src/local-hosted-wallet-gateway-worker.d.ts +1 -4
  505. package/dist/types/wallet-server/src/localHostedWalletGatewayHandler.d.ts +12 -0
  506. package/dist/types/wallet-server/src/localIntendedEcdsaFinalizeFault.d.ts +33 -0
  507. package/dist/types/wallet-server/src/localIntendedLinkExecuteFault.d.ts +47 -0
  508. package/dist/types/wallet-server/src/localIntendedRevokeFault.d.ts +40 -0
  509. package/dist/types/wallet-server/src/localIntendedSessionAdmissionFault.d.ts +41 -0
  510. package/dist/types/wallet-server/src/localIntendedYaoExportFault.d.ts +41 -0
  511. package/dist/types/wallet-server/src/localIntendedYaoFault.d.ts +7 -1
  512. package/dist/types/wallet-server/src/localIntendedYaoFinalizeFault.d.ts +37 -0
  513. package/dist/types/wallet-server/src/localIntendedYaoRecoveryFault.d.ts +45 -0
  514. package/dist/types/wallet-server/src/localIntendedYaoSigningFault.d.ts +51 -0
  515. package/dist/types/wallet-server/src/router/auth/authRequestValidation.d.ts +10 -21
  516. package/dist/types/wallet-server/src/router/auth/commonRouterUtils.d.ts +5 -10
  517. package/dist/types/wallet-server/src/router/auth/walletSessionFailure.d.ts +1 -4
  518. package/dist/types/wallet-server/src/router/auth/webAuthnCredentialCodecs.d.ts +3 -2
  519. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1AuthorizedOperationRouteService.d.ts +12 -0
  520. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthBoundary.d.ts +3 -2
  521. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthConfig.d.ts +2 -2
  522. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthService.d.ts +1 -1
  523. package/dist/types/wallet-server/src/router/cloudflare/d1/authorization/authorizedOperationStatements.d.ts +30 -0
  524. package/dist/types/wallet-server/src/router/cloudflare/d1/authorization/d1AuthorizationStore.d.ts +45 -21
  525. package/dist/types/wallet-server/src/router/cloudflare/d1/authorization/persistedWalletSessionAuthorization.d.ts +3 -0
  526. package/dist/types/wallet-server/src/router/cloudflare/d1/authorization/walletSessionAuthorityProjection.d.ts +2 -1
  527. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceAuthorityInstallService.d.ts +57 -6
  528. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEmailOtpGrantStore.d.ts +2 -3
  529. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEmailOtpTargetFactor.d.ts +8 -21
  530. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceOwnerAuthorizationProvider.d.ts +14 -1
  531. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceRevocation.d.ts +49 -0
  532. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionRecords.d.ts +1 -1
  533. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionStore.d.ts +4 -2
  534. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSourceContributionPreparationPlanner.d.ts +1 -1
  535. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetCredentialProvider.d.ts +2 -2
  536. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetPlanner.d.ts +8 -4
  537. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceVerifiedLinkBuilder.d.ts +3 -5
  538. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/installedEcdsaAuthority.d.ts +7 -0
  539. package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoCapabilityPersistence.d.ts +1 -2
  540. package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoLifecycleDecisionStore.d.ts +33 -0
  541. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeIssuer.d.ts +1 -1
  542. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeStore.d.ts +13 -3
  543. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeVerifier.d.ts +24 -5
  544. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpEnrollmentStore.d.ts +2 -3
  545. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpGrantStore.d.ts +1 -3
  546. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRateLimitStore.d.ts +3 -4
  547. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRecords.d.ts +9 -8
  548. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRecoveryService.d.ts +0 -2
  549. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRegistrationEnrollmentFinalizer.d.ts +5 -4
  550. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpRegistrationAttemptStore.d.ts +1 -3
  551. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpRegistrationRecords.d.ts +3 -21
  552. package/dist/types/wallet-server/src/router/cloudflare/d1/identity/d1IdentityRecords.d.ts +0 -23
  553. package/dist/types/wallet-server/src/router/cloudflare/d1/near/d1NearPublicKeyStore.d.ts +1 -2
  554. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1PasskeyCustodyEnvelopeStore.d.ts +11 -19
  555. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1PasskeyCustodyRouteService.d.ts +5 -54
  556. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1WalletCustodyCommitStore.d.ts +7 -19
  557. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpRecords.d.ts +4 -3
  558. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpService.d.ts +8 -12
  559. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyRecordStore.d.ts +5 -8
  560. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyRecords.d.ts +10 -22
  561. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyStore.d.ts +6 -2
  562. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationCommitStore.d.ts +10 -6
  563. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationService.d.ts +15 -22
  564. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationSetup.d.ts +5 -3
  565. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/walletRegistrationEstablishedSessionIssuer.d.ts +4 -3
  566. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/walletRegistrationSessionCommitReceipt.d.ts +5 -5
  567. package/dist/types/wallet-server/src/router/cloudflare/d1/signingAdmission/d1RouterAbNormalSigningAdmissionStore.d.ts +3 -5
  568. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneEffectJournalStore.d.ts +0 -1
  569. package/dist/types/wallet-server/src/router/cloudflare/d1/versionedJson/d1VersionedJsonRecordStore.d.ts +0 -16
  570. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAddSignerService.d.ts +29 -14
  571. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthMethodBoundary.d.ts +15 -12
  572. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthMethodRevocationReplayStore.d.ts +71 -0
  573. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthMethodService.d.ts +34 -24
  574. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorityStore.d.ts +44 -26
  575. package/dist/types/wallet-server/src/router/cloudflare/d1/webauthn/d1WebAuthnRecords.d.ts +3 -7
  576. package/dist/types/wallet-server/src/router/cloudflare/d1/webauthn/d1WebAuthnStore.d.ts +8 -19
  577. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletConsoleTenantRootLineage.d.ts +2 -1
  578. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletGateway.d.ts +1 -0
  579. package/dist/types/wallet-server/src/router/cloudflare/signingLanes/cloudflareOrdinaryInactiveSignerMaterialReservation.d.ts +15 -2
  580. package/dist/types/wallet-server/src/router/cloudflare-adaptor.d.ts +2 -2
  581. package/dist/types/wallet-server/src/router/domains/ecdsa/routerAbEcdsaStrictRegistration.d.ts +9 -7
  582. package/dist/types/wallet-server/src/router/domains/ecdsa/thresholdEcdsaRequestValidation.d.ts +4 -4
  583. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoLifecycleDecision.d.ts +46 -0
  584. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.d.ts +5 -3
  585. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitionedStateStore.d.ts +20 -79
  586. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitioning.d.ts +2 -0
  587. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRunner.d.ts +1 -1
  588. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRuntime.d.ts +4 -3
  589. package/dist/types/wallet-server/src/router/domains/ed25519Yao/export/routerAbEd25519YaoExport.d.ts +62 -42
  590. package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecovery.d.ts +108 -32
  591. package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryActivation.typecheck.d.ts +5 -0
  592. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoHttpRegistrationBackend.d.ts +36 -5
  593. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistration.d.ts +5 -4
  594. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationExecutionRecord.d.ts +41 -50
  595. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationIntentAuthorization.d.ts +2 -2
  596. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationRequestScopedCloudflare.d.ts +3 -3
  597. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.d.ts +6 -5
  598. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationTwoPhaseRunner.d.ts +14 -4
  599. package/dist/types/wallet-server/src/router/domains/ed25519Yao/routerAbEd25519YaoGatewayEnvelope.d.ts +12 -1
  600. package/dist/types/wallet-server/src/router/domains/ed25519Yao/session/routerAbEd25519YaoWalletSession.d.ts +5 -5
  601. package/dist/types/wallet-server/src/router/domains/ed25519Yao/session/thresholdEd25519RequestValidation.d.ts +3 -4
  602. package/dist/types/wallet-server/src/router/domains/emailOtp/emailOtpExportPolicy.d.ts +2 -27
  603. package/dist/types/wallet-server/src/router/domains/emailOtp/emailOtpRequestValidation.d.ts +1 -2
  604. package/dist/types/wallet-server/src/router/domains/emailOtp/emailOtpRouteHandlers.d.ts +2 -1
  605. package/dist/types/wallet-server/src/router/domains/emailOtp/emailOtpSessionRouteHelpers.d.ts +2 -102
  606. package/dist/types/wallet-server/src/router/domains/passkeyCustody/envelopeRevocationAdmission.d.ts +2 -1
  607. package/dist/types/wallet-server/src/router/domains/passkeyCustody/passkeyCustodyEnvelopeRetrieval.d.ts +3 -2
  608. package/dist/types/wallet-server/src/router/domains/passkeyCustody/passkeyCustodyEnvelopeRetrievalRoute.d.ts +1 -9
  609. package/dist/types/wallet-server/src/router/domains/passkeyCustody/registrationCustodyOutcome.d.ts +2 -1
  610. package/dist/types/wallet-server/src/router/domains/passkeyCustody/verifiedCustodyFactor.d.ts +2 -1
  611. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletCustodyRegistrationAdmission.d.ts +2 -1
  612. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletCustodyRegistrationCommit.d.ts +2 -28
  613. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletRecoveryFinalization.d.ts +43 -1
  614. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletRecoveryKeyManifest.d.ts +7 -7
  615. package/dist/types/wallet-server/src/router/domains/signingOperations/ed25519AuthorizedOperationReceipt.d.ts +0 -3
  616. package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbEcdsaDerivationNormalSigningRoute.d.ts +165 -0
  617. package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbEd25519NormalSigningRoute.d.ts +110 -0
  618. package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbNormalSigningAdmission.d.ts +360 -0
  619. package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbNormalSigningAdmissionCore.d.ts +11 -10
  620. package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbNormalSigningAdmissionCore.typecheck.d.ts +2 -0
  621. package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbOperationStepUp.d.ts +165 -0
  622. package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbPrivateSigningWorker.d.ts +16 -702
  623. package/dist/types/wallet-server/src/router/domains/signingOperations/walletExecutionAdmission.d.ts +5 -12
  624. package/dist/types/wallet-server/src/router/domains/syncAccount/syncAccountRequestValidation.d.ts +5 -4
  625. package/dist/types/wallet-server/src/router/domains/tenantRoot/tenantRootCustodyLineage.d.ts +6 -1
  626. package/dist/types/wallet-server/src/router/domains/tenantRoot/tenantRootIdentityResolution.d.ts +4 -7
  627. package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationInputs.d.ts +2 -1
  628. package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationRoutes.d.ts +8 -8
  629. package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationSetupPayload.d.ts +4 -4
  630. package/dist/types/wallet-server/src/router/domains/walletUnlock/walletUnlockRequestedCapabilitiesValidation.d.ts +4 -4
  631. package/dist/types/wallet-server/src/router/domains/walletUnlock/walletUnlockRouteHandlers.d.ts +4 -62
  632. package/dist/types/wallet-server/src/router/express-adaptor.d.ts +2 -2
  633. package/dist/types/wallet-server/src/router/framework/authServicePort.d.ts +64 -61
  634. package/dist/types/wallet-server/src/router/framework/http.d.ts +0 -1
  635. package/dist/types/wallet-server/src/router/framework/ror/normalize.d.ts +2 -2
  636. package/dist/types/wallet-server/src/router/framework/routeMeteringPolicy.d.ts +3 -2
  637. package/dist/types/wallet-server/src/router/framework/routerApi.d.ts +1 -1
  638. package/dist/types/wallet-server/src/router/framework/routerApiRouteSurface.d.ts +3 -3
  639. package/dist/types/wallet-server/src/router/node/nodeHostedWalletGateway.d.ts +34 -0
  640. package/dist/types/wallet-server/src/router/node/nodeHostedWalletGatewayCheck.d.ts +21 -0
  641. package/dist/types/wallet-server/src/router/node/nodeHostedWalletGatewayMain.d.ts +2 -0
  642. package/dist/types/wallet-server/src/router/node/nodeHttp.d.ts +13 -0
  643. package/dist/types/wallet-server/src/router/node/nodeSqlite.d.ts +22 -0
  644. package/dist/types/wallet-server/src/router/node/signerSqlMigrations.d.ts +20 -0
  645. package/dist/types/wallet-server/src/router/transport/fetch/createFetchRouter.d.ts +1 -3
  646. package/dist/types/wallet-server/src/router/transport/fetch/routes/deviceLinking.d.ts +5 -6
  647. package/dist/types/wallet-server/src/router/transport/fetch/routes/deviceLinkingOwnerAuthorization.d.ts +2 -2
  648. package/dist/types/wallet-server/src/router/transport/fetch/routes/deviceManagement.d.ts +14 -16
  649. package/dist/types/wallet-server/src/router/transport/fetch/routes/normalSigningRouterProxy.d.ts +0 -12
  650. package/dist/types/wallet-server/src/router/transport/fetch/routes/passkeyCustody.d.ts +1 -1
  651. package/dist/types/wallet-server/src/router/transport/fetch/routes/sessions.d.ts +2 -1
  652. package/dist/types/wallet-server/src/router/transport/fetch/routes/syncAccountBootstrap.d.ts +7 -13
  653. package/dist/types/wallet-server/src/router/transport/fetch/routes/thresholdEcdsa.d.ts +3 -57
  654. package/dist/types/wallet-server/src/router/transport/fetch/routes/thresholdEd25519.d.ts +0 -44
  655. package/dist/types/wallet-server/src/storage/d1Sql.d.ts +7 -0
  656. package/dist/types/wallet-server/src/storage/syncSqlite.d.ts +28 -0
  657. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/crypto/shamir3PassWasm.d.ts +0 -1
  658. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/idempotencyRecords.d.ts +5 -6
  659. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/transport/shared.d.ts +1 -0
  660. package/dist/types/wallet-server/src/threshold/statusCodes.d.ts +4 -4
  661. package/migrations/d1-signer/0036_r150_yao_lifecycle_decisions.sql +22 -0
  662. package/migrations/d1-signer/0037_r150_wallet_auth_method_revocation_replays.sql +26 -0
  663. package/migrations/d1-signer/0038_r150_registration_ceremony_cas_guard_seed.sql +8 -0
  664. package/migrations/d1-signer/0039_r150_revocation_replay_answer_kind.sql +9 -0
  665. package/package.json +1 -1
  666. package/dist/esm/core/ThresholdService/ecdsaClientRootProof.js +0 -27
  667. package/dist/esm/core/ThresholdService/routerAbEcdsaSigningWorkerWasm.js +0 -115
  668. package/dist/esm/core/ThresholdService/secureRandomId.js +0 -9
  669. package/dist/esm/core/authService/record.js +0 -8
  670. package/dist/esm/core/authService/thresholdRuntimePolicy.js +0 -19
  671. package/dist/esm/core/authService/walletRegistrationPlanning.js +0 -49
  672. package/dist/esm/core/deviceLinking/index.js +0 -5
  673. package/dist/esm/core/errors.js +0 -54
  674. package/dist/esm/core/routerAbSigning/createCloudflareDurableObjectRouterAbSigningRuntimes.js +0 -39
  675. package/dist/esm/core/signingLanes/WalletKeyStore.js +0 -0
  676. package/dist/esm/core/signingLanes/index.js +0 -8
  677. package/dist/esm/router/domains/tenantRoot/tenantRootEcdsaWalletSessionComposition.js +0 -55
  678. package/dist/esm/router/domains/tenantRoot/tenantRootEd25519WalletSessionComposition.js +0 -56
  679. package/dist/esm/shared-ts/src/signing-lanes/linkedEcdsaScope.js +0 -1
  680. package/dist/esm/wasm/router_ab_ecdsa_signing_worker/pkg/router_ab_ecdsa_signing_worker.js +0 -414
  681. package/dist/types/shared-ts/src/passkey-custody/credentialObservations.d.ts +0 -74
  682. package/dist/types/shared-ts/src/passkey-custody/kekContext.d.ts +0 -34
  683. package/dist/types/shared-ts/src/signing-lanes/linkedEcdsaScope.d.ts +0 -62
  684. package/dist/types/shared-ts/src/signing-lanes/linkedEcdsaScope.typecheck.d.ts +0 -2
  685. package/dist/types/shared-ts/src/signing-lanes/validation.d.ts +0 -11
  686. package/dist/types/shared-ts/src/utils/bigint.d.ts +0 -3
  687. package/dist/types/shared-ts/src/utils/paillier.d.ts +0 -37
  688. package/dist/types/shared-ts/src/utils/recoveryDomain.d.ts +0 -12
  689. package/dist/types/shared-ts/src/utils/signerDomain.typecheck.d.ts +0 -2
  690. package/dist/types/shared-ts/src/wallet-recovery/recoveryKekContext.d.ts +0 -37
  691. package/dist/types/wallet-server/src/core/ThresholdService/ecdsaClientRootProof.d.ts +0 -12
  692. package/dist/types/wallet-server/src/core/ThresholdService/routerAbEcdsaSigningWorkerWasm.d.ts +0 -17
  693. package/dist/types/wallet-server/src/core/ThresholdService/secureRandomId.d.ts +0 -2
  694. package/dist/types/wallet-server/src/core/authService/record.d.ts +0 -2
  695. package/dist/types/wallet-server/src/core/authService/thresholdRuntimePolicy.d.ts +0 -4
  696. package/dist/types/wallet-server/src/core/authService/walletRegistrationPlanning.d.ts +0 -19
  697. package/dist/types/wallet-server/src/core/deviceLinking/index.d.ts +0 -5
  698. package/dist/types/wallet-server/src/core/errors.d.ts +0 -10
  699. package/dist/types/wallet-server/src/core/routerAbSigning/createCloudflareDurableObjectRouterAbSigningRuntimes.d.ts +0 -28
  700. package/dist/types/wallet-server/src/core/signingLanes/SigningLaneStore.d.ts +0 -15
  701. package/dist/types/wallet-server/src/core/signingLanes/WalletKeyStore.d.ts +0 -13
  702. package/dist/types/wallet-server/src/core/signingLanes/index.d.ts +0 -11
  703. package/dist/types/wallet-server/src/router/domains/tenantRoot/tenantRootEcdsaWalletSessionComposition.d.ts +0 -35
  704. package/dist/types/wallet-server/src/router/domains/tenantRoot/tenantRootEd25519WalletSessionComposition.d.ts +0 -35
  705. /package/dist/esm/{core/signingLanes/SigningLaneStore.js → authorization/ecdsaWalletSessionAdmission.js} +0 -0
@@ -1,120 +1,14 @@
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
1
  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
2
  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";
3
+ import { isPlainObject } from "../../../shared-ts/src/utils/validation.js";
4
+ import { parseRouterAbEcdsaDerivationEvmDigestSigningFinalizeRequestV1, parseRouterAbEcdsaDerivationEvmDigestSigningRequestV1, routerAbEcdsaDerivationEvmDigestSigningFinalizeCoreRequestDigestV1, routerAbEcdsaDerivationEvmDigestSigningRequestDigestV1 } from "../../../shared-ts/src/utils/routerAbEcdsaDerivation.js";
12
5
  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";
6
+ import { requireMpcMaterialActivationId, routerAbSigningError } from "./routerAbNormalSigningAdmission.js";
18
7
  //#region src/router/domains/signingOperations/routerAbPrivateSigningWorker.ts
19
8
  const ED25519_SIGNING_INTENT_VERSION_V2 = "router-ab-protocol/ed25519-normal-signing/intent/v2";
20
9
  const ED25519_SIGNING_PAYLOAD_VERSION_V2 = "router-ab-protocol/ed25519-normal-signing/payload/v2";
21
10
  const ED25519_ROUND1_BINDING_VERSION_V2 = "router-ab-protocol/ed25519-normal-signing/round1-binding/v2";
22
11
  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
12
  const PRIVATE_ED25519_SIGNING_PREPARE_PATH = "/router-ab/signing-worker/sign/prepare";
119
13
  const PRIVATE_ED25519_SIGNING_FINALIZE_PATH = "/router-ab/signing-worker/sign";
120
14
  const PRIVATE_ECDSA_DERIVATION_SIGNING_PREPARE_PATH = "/router-ab/signing-worker/ecdsa-derivation/sign/prepare";
@@ -131,340 +25,6 @@ function resolveRouterAbSigningWorkerFetch(input) {
131
25
  if (input) return input;
132
26
  return typeof globalThis.fetch === "function" ? globalThis.fetch.bind(globalThis) : null;
133
27
  }
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
28
  function validateRouterAbNormalSigningEffectClaim(claim, scope, authorization) {
469
29
  requirePrivateSigningString(claim.authorized_operation_id, "effect_claim.authorized_operation_id");
470
30
  requirePrivateSigningString(claim.operation_id, "effect_claim.operation_id");
@@ -499,9 +59,6 @@ function routerAbNormalSigningMaterialSourceFromActiveLaneV1(input) {
499
59
  group_public_key: groupPublicKey
500
60
  };
501
61
  }
502
- function isPlainObject(value) {
503
- return !!value && typeof value === "object" && !Array.isArray(value);
504
- }
505
62
  function nonEmptyString(value) {
506
63
  return String(value || "").trim();
507
64
  }
@@ -528,25 +85,6 @@ async function sha256B64u(bytes) {
528
85
  async function sha256Digest32(bytes) {
529
86
  return digest32FromB64u(await sha256B64u(bytes));
530
87
  }
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
88
  function replayResponseFromSigningWorkerResult(result) {
551
89
  if (result.ok) return result.replay;
552
90
  return {
@@ -624,11 +162,6 @@ function requirePrivateSigningMaterialActivation(value) {
624
162
  signing_worker: requirePrivateSigningString(activation.signing_worker, "scope.material_activation.signing_worker")
625
163
  };
626
164
  }
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
165
  function parseRouterAbEd25519NormalSigningScopeV2(value) {
633
166
  const scope = requirePrivateSigningRecord(value, "scope");
634
167
  requirePrivateSigningExactFields(scope, [
@@ -744,7 +277,7 @@ function privateSigningPayloadPreimage(value) {
744
277
  function privateSigningDigestsEqual(left, right) {
745
278
  return left.bytes.every((byte, index) => byte === right.bytes[index]);
746
279
  }
747
- async function privateSigningAdmissionMaterial(input) {
280
+ async function computeRouterAbEd25519NormalSigningAdmissionMaterial(input) {
748
281
  const payload = privateSigningPayloadPreimage(input.signingPayload);
749
282
  const [intentDigest, signingPayloadDigest, admittedSigningDigest] = await Promise.all([
750
283
  sha256Digest32(canonicalPrivateSigningIntentBytes(input.intent)),
@@ -758,9 +291,6 @@ async function privateSigningAdmissionMaterial(input) {
758
291
  admittedSigningDigest
759
292
  };
760
293
  }
761
- async function computeRouterAbEd25519NormalSigningAdmissionMaterial(input) {
762
- return await privateSigningAdmissionMaterial(input);
763
- }
764
294
  async function privateSigningRound1BindingDigest(input) {
765
295
  const out = [];
766
296
  pushLen32(out, textBytes(ED25519_ROUND1_BINDING_VERSION_V2));
@@ -807,17 +337,17 @@ async function privateSigningTrustedSourceDigest(headers) {
807
337
  function privateSigningTrustedAdmission(input) {
808
338
  return {
809
339
  metadata: {
810
- org_id: input.runtimePolicyScope.orgId,
811
- project_id: input.runtimePolicyScope.projectId,
812
- environment: input.runtimePolicyScope.envId,
340
+ org_id: input.authorization.runtimePolicyScope.orgId,
341
+ project_id: input.authorization.runtimePolicyScope.projectId,
342
+ environment: input.authorization.runtimePolicyScope.envId,
813
343
  account_id: input.accountId,
814
344
  auth: input.authorization.kind === "reusable_wallet_session" ? {
815
345
  auth: "owner_wallet_session",
816
- subject_id: input.subjectId,
346
+ subject_id: input.authorization.subjectId,
817
347
  wallet_session_id: input.authorization.walletSessionId
818
348
  } : {
819
349
  auth: "owner_operation_step_up",
820
- subject_id: input.subjectId,
350
+ subject_id: input.authorization.subjectId,
821
351
  authorization_session_id: input.authorization.authorizationSessionId
822
352
  },
823
353
  trusted_source_digest: input.trustedSourceDigest,
@@ -865,6 +395,11 @@ async function buildRouterAbEd25519PrivateSigningWorkerBody(input) {
865
395
  const scope = parseRouterAbEd25519NormalSigningScopeV2(input.body.scope);
866
396
  const signingContext = privateSigningAuthorizationContext(scope, input.authorization);
867
397
  const trustedSourceDigest = await privateSigningTrustedSourceDigest(input.headers);
398
+ const materialSource = input.materialSource ?? registrationMaterialSourceV1({
399
+ accountId: scope.account_id,
400
+ materialActivationId: scope.material_activation.activation_id,
401
+ signingWorkerId: scope.signing_worker_id
402
+ });
868
403
  if (input.phase === "finalize") {
869
404
  validateRouterAbNormalSigningEffectClaim(input.effectClaim, scope, signingContext);
870
405
  const prepareBinding = requirePrivateSigningRecord(input.body.prepare_binding, "prepare_binding");
@@ -875,20 +410,7 @@ async function buildRouterAbEd25519PrivateSigningWorkerBody(input) {
875
410
  return {
876
411
  request: input.body,
877
412
  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,
413
+ ...privateSigningAdmissionCandidateScope(scope, signingContext),
892
414
  intent_digest: intentDigest,
893
415
  signing_payload_digest: signingPayloadDigest,
894
416
  round1_binding_digest: round1BindingDigest,
@@ -896,8 +418,6 @@ async function buildRouterAbEd25519PrivateSigningWorkerBody(input) {
896
418
  expires_at_ms: expiresAtMs
897
419
  },
898
420
  trusted_admission: privateSigningTrustedAdmission({
899
- runtimePolicyScope: signingContext.runtimePolicyScope,
900
- subjectId: signingContext.subjectId,
901
421
  accountId: scope.account_id,
902
422
  authorization: signingContext,
903
423
  requestId: scope.request_id,
@@ -905,15 +425,11 @@ async function buildRouterAbEd25519PrivateSigningWorkerBody(input) {
905
425
  trustedSourceDigest
906
426
  }),
907
427
  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
- })
428
+ material_source: materialSource
913
429
  };
914
430
  }
915
431
  const expiresAtMs = requirePrivateSigningPositiveSafeInteger(input.body.expires_at_ms, "expires_at_ms");
916
- const material = await privateSigningAdmissionMaterial({
432
+ const material = await computeRouterAbEd25519NormalSigningAdmissionMaterial({
917
433
  intent: input.body.intent,
918
434
  signingPayload: input.body.signing_payload
919
435
  });
@@ -924,8 +440,6 @@ async function buildRouterAbEd25519PrivateSigningWorkerBody(input) {
924
440
  ...material
925
441
  });
926
442
  const trustedAdmission = privateSigningTrustedAdmission({
927
- runtimePolicyScope: signingContext.runtimePolicyScope,
928
- subjectId: signingContext.subjectId,
929
443
  accountId: scope.account_id,
930
444
  authorization: signingContext,
931
445
  requestId: scope.request_id,
@@ -936,20 +450,7 @@ async function buildRouterAbEd25519PrivateSigningWorkerBody(input) {
936
450
  scope,
937
451
  expires_at_ms: expiresAtMs,
938
452
  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,
453
+ ...privateSigningAdmissionCandidateScope(scope, signingContext),
953
454
  intent_digest: material.intentDigest,
954
455
  signing_payload_digest: material.signingPayloadDigest,
955
456
  admitted_signing_digest: material.admittedSigningDigest,
@@ -958,11 +459,25 @@ async function buildRouterAbEd25519PrivateSigningWorkerBody(input) {
958
459
  expires_at_ms: expiresAtMs
959
460
  },
960
461
  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
- })
462
+ material_source: materialSource
463
+ };
464
+ }
465
+ function privateSigningAdmissionCandidateScope(scope, signingContext) {
466
+ return {
467
+ org_id: signingContext.runtimePolicyScope.orgId,
468
+ project_id: signingContext.runtimePolicyScope.projectId,
469
+ environment: signingContext.runtimePolicyScope.envId,
470
+ account_id: scope.account_id,
471
+ subject_id: signingContext.subjectId,
472
+ authorization: signingContext.kind === "reusable_wallet_session" ? {
473
+ kind: "reusable_wallet_session",
474
+ wallet_session_id: signingContext.walletSessionId
475
+ } : {
476
+ kind: "operation_step_up",
477
+ authorization_session_id: signingContext.authorizationSessionId
478
+ },
479
+ signing_worker_id: scope.signing_worker_id,
480
+ request_id: scope.request_id
966
481
  };
967
482
  }
968
483
  async function buildRouterAbEcdsaDerivationPrivateSigningWorkerBody(input) {
@@ -971,1652 +486,40 @@ async function buildRouterAbEcdsaDerivationPrivateSigningWorkerBody(input) {
971
486
  if (input.phase === "prepare") {
972
487
  const request = parseRouterAbEcdsaDerivationEvmDigestSigningRequestV1(input.body);
973
488
  validatePrivateSigningAuthorizationContext(request.authorization, signingContext);
974
- const requestDigest = await routerAbEcdsaDerivationEvmDigestSigningRequestDigestV1(request);
975
- return {
489
+ return privateEcdsaDerivationSigningWorkerBody({
976
490
  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
- };
491
+ requestDigest: await routerAbEcdsaDerivationEvmDigestSigningRequestDigestV1(request),
492
+ signingContext,
493
+ trustedSourceDigest,
494
+ materialSource: input.materialSource
495
+ });
992
496
  }
993
497
  const request = parseRouterAbEcdsaDerivationEvmDigestSigningFinalizeRequestV1(input.body);
994
498
  validatePrivateSigningAuthorizationContext(request.authorization, signingContext);
995
- const requestDigest = await routerAbEcdsaDerivationEvmDigestSigningFinalizeCoreRequestDigestV1(request);
996
- return {
499
+ return privateEcdsaDerivationSigningWorkerBody({
997
500
  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
- function parseRouterAbEd25519OperationStepUpScope(value) {
1439
- return parseRouterAbEd25519NormalSigningScopeV2(value);
1440
- }
1441
- function parseRouterAbOperationStepUpOperation(value) {
1442
- const intent = isPlainObject(value) ? value : null;
1443
- if (!intent) return {
1444
- ok: false,
1445
- message: "Router A/B step-up intent is required"
1446
- };
1447
- let operationKind;
1448
- switch (intent.kind) {
1449
- case "near_transaction_v1":
1450
- operationKind = "near.sign_transaction";
1451
- break;
1452
- case "near_delegate_action_v1":
1453
- operationKind = "near.sign_delegate_action";
1454
- break;
1455
- case "nep413_v1":
1456
- operationKind = "near.sign_nep413_message";
1457
- break;
1458
- default: return {
1459
- ok: false,
1460
- message: "Router A/B step-up intent kind is invalid"
1461
- };
1462
- }
1463
- const operationId = parseCapabilityOperationId(intent.operation_id);
1464
- if (!operationId.ok) return {
1465
- ok: false,
1466
- message: operationId.error.message
1467
- };
1468
- return {
1469
- ok: true,
1470
- operationId: operationId.value,
1471
- operation: buildNearEd25519MpcOperationRef(operationKind)
1472
- };
1473
- }
1474
- function parseRouterAbEd25519NormalSigningOperationForAdmission(input) {
1475
- if (input.phase === "prepare") {
1476
- const requestedOperation = parseRouterAbOperationStepUpOperation(input.body.intent);
1477
- if (!requestedOperation.ok) return requestedOperation;
1478
- return {
1479
- ok: true,
1480
- operation: {
1481
- phase: "prepare",
1482
- operationKind: requestedOperation.operation.operationKind
1483
- }
1484
- };
1485
- }
1486
- try {
1487
- switch (input.authorizationKind) {
1488
- case "reusable_wallet_session": {
1489
- const receipt = parseEd25519ReusableAuthorizedOperationReceipt(input.body.authorized_operation);
1490
- return {
1491
- ok: true,
1492
- operation: {
1493
- phase: "finalize",
1494
- operationKind: receipt.operation_kind,
1495
- authorizationKind: "reusable_wallet_session",
1496
- receipt
1497
- }
1498
- };
1499
- }
1500
- case "operation_step_up": {
1501
- const receipt = parseEd25519VerifiedStepUpAuthorizedOperationReceipt(input.body.authorized_operation);
1502
- return {
1503
- ok: true,
1504
- operation: {
1505
- phase: "finalize",
1506
- operationKind: receipt.operation_kind,
1507
- authorizationKind: "operation_step_up",
1508
- receipt
1509
- }
1510
- };
1511
- }
1512
- }
1513
- } catch (error) {
1514
- return {
1515
- ok: false,
1516
- message: errorMessage(error)
1517
- };
1518
- }
1519
- }
1520
- async function validateRouterAbEd25519V2FinalizeAuthorizedOperation(input) {
1521
- if (!input.authorizedOperations) return {
1522
- ok: false,
1523
- result: routerAbEd25519OwnerOperationFailureResult({
1524
- status: 501,
1525
- code: "not_configured",
1526
- message: "Reusable Wallet Session authorization is not configured",
1527
- phase: input.phase
1528
- })
1529
- };
1530
- let authorizedOperationId;
1531
- try {
1532
- authorizedOperationId = requireAuthorizationValue(parseAuthorizedOperationId(input.receipt.authorized_operation_id));
1533
- requireAuthorizationValue(parseCapabilityOperationId(input.receipt.operation_id));
1534
- } catch (error) {
1535
- return {
1536
- ok: false,
1537
- result: routerAbEd25519OwnerOperationFailureResult({
1538
- status: 400,
1539
- code: "invalid_authorized_operation",
1540
- message: errorMessage(error),
1541
- phase: input.phase
1542
- })
1543
- };
1544
- }
1545
- let operation;
1546
- try {
1547
- operation = await input.authorizedOperations.readAuthorizedOperationById({
1548
- tenantId: input.authorizedOperations.tenantId,
1549
- authorizedOperationId
1550
- });
1551
- } catch (error) {
1552
- return {
1553
- ok: false,
1554
- result: routerAbEd25519OwnerOperationFailureResult({
1555
- status: 500,
1556
- code: "internal",
1557
- message: errorMessage(error),
1558
- phase: input.phase
1559
- })
1560
- };
1561
- }
1562
- if (!operation) return {
1563
- ok: false,
1564
- result: routerAbEd25519OwnerOperationFailureResult({
1565
- status: 409,
1566
- code: "authorized_operation_missing",
1567
- message: "Authorized operation is unavailable",
1568
- phase: input.phase
1569
- })
1570
- };
1571
- const operationRef = operation.operation.operation;
1572
- 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 {
1573
- ok: false,
1574
- result: routerAbEd25519OwnerOperationFailureResult({
1575
- status: 400,
1576
- code: "invalid_authorized_operation",
1577
- message: "Ed25519 authorized operation does not match its receipt",
1578
- phase: input.phase
1579
- })
1580
- };
1581
- switch (operationRef.operationKind) {
1582
- case "near.sign_transaction":
1583
- case "near.sign_delegate_action":
1584
- case "near.sign_nep413_message": return {
1585
- ok: true,
1586
- operationKind: operationRef.operationKind
1587
- };
1588
- }
1589
- }
1590
- function requireAuthorizationValue(result) {
1591
- if (!result.ok) throw new Error(result.error.message);
1592
- return result.value;
1593
- }
1594
- async function authorizeRouterAbEd25519WalletSessionRequest(input) {
1595
- if (input.operation.phase === "finalize") {
1596
- const exactOperation = await validateRouterAbEd25519V2FinalizeAuthorizedOperation({
1597
- receipt: input.operation.receipt,
1598
- authorizedOperations: input.authorizedOperations,
1599
- phase: input.phase
1600
- });
1601
- if (!exactOperation.ok) return exactOperation;
1602
- if (exactOperation.operationKind !== input.admission.operationKind) return {
1603
- ok: false,
1604
- result: routerAbEd25519OwnerOperationFailureResult({
1605
- status: 403,
1606
- code: "wallet_session_scope_mismatch",
1607
- message: "Exact Wallet Session operation does not match the authorized operation",
1608
- phase: input.phase
1609
- })
1610
- };
1611
- }
1612
- const expectedMaterialActivation = routerAbMpcMaterialActivationRefFromWire(input.scope.material_activation);
1613
- const admittedMaterialActivation = routerAbMpcMaterialActivationRefToWire(input.admission.materialActivation);
1614
- const expiresAtMs = Number(input.body.expires_at_ms);
1615
- 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 {
1616
- ok: false,
1617
- result: routerAbEd25519OwnerOperationFailureResult({
1618
- status: 403,
1619
- code: "wallet_session_scope_mismatch",
1620
- message: "Exact Wallet Session does not authorize this Ed25519 request",
1621
- phase: input.phase
1622
- })
1623
- };
1624
- if (expiresAtMs <= Date.now()) return {
1625
- ok: false,
1626
- result: routerAbEd25519OwnerOperationFailureResult({
1627
- status: 408,
1628
- code: "expired_request",
1629
- message: "Router A/B Ed25519 normal-signing request is expired",
1630
- phase: input.phase
1631
- })
1632
- };
1633
- if (expiresAtMs > input.session.expiresAtMs) return {
1634
- ok: false,
1635
- result: routerAbEd25519OwnerOperationFailureResult({
1636
- status: 403,
1637
- code: "wallet_session_scope_mismatch",
1638
- message: "Ed25519 request exceeds the exact Wallet Session lifetime",
1639
- phase: input.phase
1640
- })
1641
- };
1642
- const activeMaterial = await input.resolveEd25519MaterialActivation({
1643
- walletId: String(input.session.walletId),
1644
- materialActivation: admittedMaterialActivation
1645
- });
1646
- 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 {
1647
- ok: false,
1648
- result: routerAbEd25519OwnerOperationFailureResult({
1649
- status: activeMaterial.ok || activeMaterial.code !== "internal" ? 403 : 500,
1650
- code: activeMaterial.ok || activeMaterial.code !== "internal" ? "material_mismatch" : "internal",
1651
- message: activeMaterial.ok ? "Exact Wallet Session material does not match the active Ed25519 material" : activeMaterial.message,
1652
- phase: input.phase
1653
- })
1654
- };
1655
- const admission = {
1656
- ok: true,
1657
- thresholdSessionId: activeMaterial.exportIdentity.scope.threshold_session_id,
1658
- requestId: input.scope.request_id,
1659
- expiresAtMs,
1660
- materialActivation: admittedMaterialActivation
1661
- };
1662
- const admissionDecision = await evaluateRouterAbNormalSigningAdmission({
1663
- adapter: input.admissionAdapter,
1664
- curve: "ed25519",
1665
- authorizationKind: "wallet_session_operation_credential_v1",
1666
- phase: input.phase,
1667
- walletId: String(input.session.walletId),
1668
- authorityId: input.authorityId,
1669
- thresholdSessionId: activeMaterial.exportIdentity.scope.threshold_session_id,
1670
- walletSessionId: String(input.session.walletSessionId),
1671
- quotaId: String(input.session.quotaId),
1672
- requestId: input.scope.request_id,
1673
- expiresAtMs,
1674
- signingWorkerId: activeMaterial.signingWorkerId,
1675
- runtimePolicyScope: activeMaterial.runtimePolicyScope
1676
- });
1677
- if (!admissionDecision.ok) return {
1678
- ok: false,
1679
- result: routerAbEd25519OwnerOperationFailureResult({
1680
- status: admissionDecision.status,
1681
- code: admissionDecision.code,
1682
- message: admissionDecision.message,
1683
- phase: input.phase
1684
- })
1685
- };
1686
- return {
1687
- ok: true,
1688
- admission,
1689
- activeMaterial
1690
- };
1691
- }
1692
- async function resolveRouterAbEd25519ExhaustedCandidateAuthorization(input) {
1693
- const token = extractBearerCredential(input.headers);
1694
- if (!token) return null;
1695
- let candidate;
1696
- try {
1697
- candidate = await input.authorizationSessions.readExhaustedWalletSessionAuthorizationV2CandidateByOperationCredential({
1698
- tenantId: input.authorizationSessions.tenantId,
1699
- token,
1700
- nowMs: Date.now()
1701
- });
1702
- } catch {
1703
- return {
1704
- ok: false,
1705
- result: routerAbStepUpError(503, "wallet_session_unavailable", "Wallet Session is unavailable")
1706
- };
1707
- }
1708
- if (!candidate) return null;
1709
- const session = candidate.status.session;
1710
- const admission = resolveWalletSessionAuthorizationV2Admission({
1711
- authorization: session,
1712
- authority: candidate.authority,
1713
- authMethod: candidate.authMethod,
1714
- operation: {
1715
- tenantId: session.tenantId,
1716
- principalId: session.principalId,
1717
- walletId: session.walletId,
1718
- keyFamily: "ed25519",
1719
- operationKind: input.operation.operationKind
1720
- },
1721
- retiredAtMs: candidate.retiredAtMs,
1722
- nowMs: Date.now()
1723
- });
1724
- if (!admission.ok || admission.keyFamily !== "ed25519") return {
1725
- ok: false,
1726
- result: routerAbEd25519OwnerOperationFailureResult({
1727
- status: 403,
1728
- code: "wallet_session_scope_mismatch",
1729
- message: "Exact Wallet Session does not authorize this Ed25519 request",
1730
- phase: input.phase
1731
- })
1732
- };
1733
- const authorized = await authorizeRouterAbEd25519WalletSessionRequest({
1734
- phase: input.phase,
1735
- body: input.body,
1736
- scope: input.scope,
1737
- operation: input.operation,
1738
- session,
1739
- authorityId: String(candidate.authority.authorityId),
1740
- admission,
1741
- authorizedOperations: input.authorizedOperations,
1742
- admissionAdapter: input.admissionAdapter,
1743
- resolveEd25519MaterialActivation: input.resolveEd25519MaterialActivation
501
+ requestDigest: await routerAbEcdsaDerivationEvmDigestSigningFinalizeCoreRequestDigestV1(request),
502
+ signingContext,
503
+ trustedSourceDigest,
504
+ materialSource: input.materialSource
1744
505
  });
1745
- if (!authorized.ok) return authorized;
1746
- return {
1747
- ok: true,
1748
- kind: "wallet_session_operation_credential_exhausted_candidate_v1",
1749
- candidate,
1750
- admission: authorized.admission,
1751
- activeMaterial: authorized.activeMaterial
1752
- };
1753
506
  }
1754
- function routerAbOperationStepUpClaimFailure(result) {
1755
- switch (result.kind) {
1756
- case "claimed":
1757
- case "operation_in_progress":
1758
- case "replayed": return null;
1759
- case "authorization_grant_rejected":
1760
- case "verified_step_up_rejected": return routerAbStepUpError(403, result.kind, "Operation step-up authorization is invalid");
1761
- case "wallet_session_quota_exhausted": return routerAbStepUpError(409, result.kind, "Operation step-up authorization is invalid");
1762
- case "material_mismatch": return routerAbStepUpError(403, result.kind, "Operation step-up material is invalid");
1763
- }
1764
- }
1765
- function routerAbStepUpError(status, code, message) {
507
+ function privateEcdsaDerivationSigningWorkerBody(input) {
1766
508
  return {
1767
- status,
1768
- body: {
1769
- ok: false,
1770
- code,
1771
- message
1772
- }
1773
- };
1774
- }
1775
- async function authorizeRouterAbEd25519NormalSigningRoute(input) {
1776
- let scope;
1777
- try {
1778
- scope = parseRouterAbEd25519NormalSigningScopeV2(input.body.scope);
1779
- } catch (error) {
1780
- return {
1781
- ok: false,
1782
- result: routerAbEd25519OwnerOperationFailureResult({
1783
- status: 400,
1784
- code: "invalid_body",
1785
- message: errorMessage(error),
1786
- phase: input.phase
1787
- })
1788
- };
1789
- }
1790
- const operationForAdmission = parseRouterAbEd25519NormalSigningOperationForAdmission({
1791
- phase: input.phase,
1792
- body: input.body,
1793
- authorizationKind: scope.authorization.kind
1794
- });
1795
- if (!operationForAdmission.ok) return {
1796
- ok: false,
1797
- result: routerAbEd25519OwnerOperationFailureResult({
1798
- status: 400,
1799
- code: "invalid_body",
1800
- message: operationForAdmission.message,
1801
- phase: input.phase
1802
- })
1803
- };
1804
- if (scope.authorization.kind === "operation_step_up") {
1805
- const result = await handleRouterAbEd25519OperationStepUpRoute({
1806
- body: input.body,
1807
- headers: input.headers,
1808
- authorizedOperations: input.authorizedOperations,
1809
- authorizationSessions: input.authorizationSessions,
1810
- resolveEd25519MaterialActivation: input.resolveEd25519MaterialActivation,
1811
- phase: input.phase,
1812
- scope,
1813
- operationKind: operationForAdmission.operation.operationKind
1814
- });
1815
- return "status" in result ? {
1816
- ok: false,
1817
- result
1818
- } : {
1819
- ok: true,
1820
- kind: "operation_step_up",
1821
- ...result
1822
- };
1823
- }
1824
- const validated = await validateRouterAbEd25519WalletSessionInputs({
1825
- headers: input.headers,
1826
- authorizationSessions: input.authorizationSessions,
1827
- operationKind: operationForAdmission.operation.operationKind
1828
- });
1829
- if (!validated.ok) {
1830
- const operation = operationForAdmission.operation;
1831
- if (validated.code === "wallet_session_unavailable" && input.authorizationSessions && (operation.phase === "prepare" || operation.authorizationKind === "reusable_wallet_session")) {
1832
- const exhaustedCandidate = await resolveRouterAbEd25519ExhaustedCandidateAuthorization({
1833
- body: input.body,
1834
- headers: input.headers,
1835
- scope,
1836
- phase: input.phase,
1837
- operation,
1838
- authorizedOperations: input.authorizedOperations,
1839
- authorizationSessions: input.authorizationSessions,
1840
- admissionAdapter: input.admissionAdapter,
1841
- resolveEd25519MaterialActivation: input.resolveEd25519MaterialActivation
1842
- });
1843
- if (exhaustedCandidate) return exhaustedCandidate;
1844
- }
1845
- const stepUp = await resolveRouterAbEd25519OwnerOperationStepUpPreparation({
1846
- scope,
1847
- body: input.body,
1848
- phase: input.phase,
1849
- resolveEd25519MaterialActivation: input.resolveEd25519MaterialActivation
1850
- });
1851
- return {
1852
- ok: false,
1853
- result: routerAbEd25519OwnerOperationFailureResult({
1854
- status: routerAbWalletSessionValidationStatus(validated.code),
1855
- code: validated.code,
1856
- message: validated.message,
1857
- phase: input.phase,
1858
- stepUp
1859
- })
1860
- };
1861
- }
1862
- const operation = operationForAdmission.operation;
1863
- if (operation.phase === "finalize" && operation.authorizationKind !== "reusable_wallet_session") return {
1864
- ok: false,
1865
- result: routerAbEd25519OwnerOperationFailureResult({
1866
- status: 400,
1867
- code: "invalid_authorized_operation",
1868
- message: "Reusable Wallet Session authorized operation is required",
1869
- phase: input.phase
1870
- })
1871
- };
1872
- const authorized = await authorizeRouterAbEd25519WalletSessionRequest({
1873
- phase: input.phase,
1874
- body: input.body,
1875
- scope,
1876
- operation,
1877
- session: validated.admission.context.authorization.session,
1878
- authorityId: String(validated.admission.context.authority.authorityId),
1879
- admission: validated.admission.admission,
1880
- authorizedOperations: input.authorizedOperations,
1881
- admissionAdapter: input.admissionAdapter,
1882
- resolveEd25519MaterialActivation: input.resolveEd25519MaterialActivation
1883
- });
1884
- if (!authorized.ok) return authorized;
1885
- return {
1886
- ok: true,
1887
- kind: "wallet_session_operation_credential_v1",
1888
- validated,
1889
- admission: authorized.admission,
1890
- activeMaterial: authorized.activeMaterial
1891
- };
1892
- }
1893
- function errorMessage(error) {
1894
- return String(error && typeof error === "object" && "message" in error ? error.message : error || "unknown error");
1895
- }
1896
- /**
1897
- * Re-resolve the complete activation reference immediately before a claim or
1898
- * evidence write. The resolver is authoritative for capability identity and
1899
- * all owner/key/lifecycle/worker bindings; a stale or superseded reference
1900
- * must fail before any authorization side effect is attempted.
1901
- */
1902
- async function resolveFreshRouterAbEcdsaMaterialActivation(input) {
1903
- const resolved = await input.resolveEcdsaMaterialActivation({
1904
- walletId: input.walletId,
1905
- materialActivation: input.expected
1906
- });
1907
- if (!resolved.ok) return resolved;
1908
- if (!sameRouterAbMpcMaterialActivationRef(resolved.materialActivation, input.expected)) return {
1909
- ok: false,
1910
- code: "scope_mismatch",
1911
- message: "ECDSA material activation changed before authorization claim"
1912
- };
1913
- return {
1914
- ok: true,
1915
- materialActivation: resolved.materialActivation,
1916
- keyHandle: resolved.keyHandle,
1917
- relayerKeyId: resolved.relayerKeyId,
1918
- participantIds: resolved.participantIds,
1919
- runtimePolicyScope: resolved.runtimePolicyScope
1920
- };
1921
- }
1922
- function validateRouterAbEcdsaV2NormalSigningRequestForSession(input) {
1923
- let request;
1924
- try {
1925
- request = input.phase === "prepare" ? parseRouterAbEcdsaDerivationEvmDigestSigningRequestV1(input.body) : parseRouterAbEcdsaDerivationEvmDigestSigningFinalizeRequestV1(input.body);
1926
- } catch (error) {
1927
- return {
1928
- ok: false,
1929
- error: routerAbStepUpError(400, "invalid_body", errorMessage(error))
1930
- };
1931
- }
1932
- 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 {
1933
- ok: false,
1934
- error: routerAbWalletSessionError(WALLET_SESSION_FAILURE_CODES.scopeMismatch)
1935
- };
1936
- if (request.expires_at_ms <= Date.now()) return {
1937
- ok: false,
1938
- error: routerAbSigningError(408, "expired_request", "Router A/B ECDSA derivation normal-signing request is expired")
1939
- };
1940
- if (request.expires_at_ms > input.session.expiresAtMs) return {
1941
- ok: false,
1942
- error: routerAbWalletSessionError(WALLET_SESSION_FAILURE_CODES.scopeMismatch)
1943
- };
1944
- return {
1945
- ok: true,
1946
- request,
1947
- admission: {
1948
- ok: true,
1949
- thresholdSessionId: routerAbEcdsaDerivationActiveStateId({
1950
- kind: ROUTER_AB_ECDSA_DERIVATION_NORMAL_SIGNING_STATE_KIND_V1,
1951
- scope: request.scope
1952
- }),
1953
- requestId: request.request_id,
1954
- expiresAtMs: request.expires_at_ms,
1955
- materialActivation: input.admittedMaterialActivation
1956
- }
1957
- };
1958
- }
1959
- async function admitRouterAbEcdsaReusableWalletSessionOperation(input) {
1960
- if (!routerAbEcdsaAtomicAuthorizationConfigured(input.authorizedOperations)) return {
1961
- ok: false,
1962
- error: routerAbStepUpError(501, "not_configured", "ECDSA atomic authorization is not configured")
1963
- };
1964
- if (input.request.authorization.kind !== "reusable_wallet_session") return {
1965
- ok: false,
1966
- error: routerAbStepUpError(400, "invalid_body", "Reusable Wallet Session authority is required")
1967
- };
1968
- const nowMs = Date.now();
1969
- try {
1970
- const session = input.binding.kind === "wallet_session_operation_credential_v1" ? input.binding.context.authorization.session : input.binding.candidate.status.session;
1971
- const tenantId = session.tenantId;
1972
- const principalId = session.principalId;
1973
- const walletId = session.walletId;
1974
- const walletSessionId = session.walletSessionId;
1975
- const authorizationId = session.authorizationId;
1976
- const quotaId = session.quotaId;
1977
- if (tenantId !== input.authorizedOperations.tenantId || input.request.authorization.wallet_session_id !== walletSessionId) return {
1978
- ok: false,
1979
- error: routerAbStepUpError(403, "wallet_session_mismatch", "Reusable Wallet Session identity does not match")
1980
- };
1981
- const freshMaterial = await resolveFreshRouterAbEcdsaMaterialActivation({
1982
- resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation,
1983
- walletId: String(walletId),
1984
- expected: input.materialActivation
1985
- });
1986
- if (!freshMaterial.ok) return {
1987
- ok: false,
1988
- error: routerAbStepUpError(freshMaterial.code === "internal" ? 500 : 403, freshMaterial.code === "internal" ? "internal" : "wallet_session_mismatch", freshMaterial.message)
1989
- };
1990
- const capabilityId = requireAuthorizationValue(parseCapabilityId(freshMaterial.materialActivation.capability));
1991
- const operationId = requireAuthorizationValue(parseCapabilityOperationId(input.request.operation_id));
1992
- const envelope = buildCapabilityOperationEnvelope({
1993
- tenantId,
1994
- principalId,
1995
- capabilityId,
1996
- operationId,
1997
- operation: buildEvmEcdsaMpcOperationRef("evm.sign_transaction"),
1998
- digests: {
1999
- laneDigest: parseDigestB64u(input.request.operation_digests.lane_digest_b64u),
2000
- intentDigest: parseDigestB64u(input.request.operation_digests.intent_digest_b64u),
2001
- displayDigest: parseDigestB64u(input.request.operation_digests.display_digest_b64u)
2002
- }
2003
- });
2004
- const authorizedOperationId = requireAuthorizationValue(parseAuthorizedOperationId(`ecdsa-authorized-operation:${operationId}:${input.request.request_id}`));
2005
- const auditEventId = requireAuthorizationValue(parseAuthorizationAuditEventId(`ecdsa-operation-audit:${operationId}`));
2006
- const outcome = await input.authorizedOperations.admitAuthorizedOperation({
2007
- operation: {
2008
- tenantId,
2009
- authorizedOperationId,
2010
- auditEventId,
2011
- operation: envelope,
2012
- authorization: {
2013
- kind: "authorization_grant",
2014
- authorizationGrantRef: buildAuthorizationGrantRef(authorizationId)
2015
- },
2016
- quota: {
2017
- kind: "consume_reusable_wallet_session",
2018
- quotaId
2019
- },
2020
- claimedAtMs: nowMs
2021
- },
2022
- material: {
2023
- walletId,
2024
- keyHandle: freshMaterial.keyHandle,
2025
- runtimePolicyScope: freshMaterial.runtimePolicyScope,
2026
- materialActivation: freshMaterial.materialActivation
2027
- }
2028
- });
2029
- const claimFailure = routerAbReusableWalletSessionClaimFailure(outcome);
2030
- if (claimFailure) return {
2031
- ok: false,
2032
- error: claimFailure
2033
- };
2034
- if (outcome.kind === "claimed" || outcome.kind === "operation_in_progress" || outcome.kind === "replayed") return {
2035
- ok: true,
2036
- admission: {
2037
- kind: outcome.kind,
2038
- operation: outcome.operation
2039
- }
2040
- };
2041
- return {
2042
- ok: false,
2043
- error: routerAbStepUpError(409, outcome.kind, "Authorized operation is unavailable")
2044
- };
2045
- } catch (error) {
2046
- return {
2047
- ok: false,
2048
- error: routerAbStepUpError(400, "invalid_body", errorMessage(error))
2049
- };
2050
- }
2051
- }
2052
- function routerAbReusableWalletSessionClaimFailure(result) {
2053
- switch (result.kind) {
2054
- case "claimed":
2055
- case "operation_in_progress":
2056
- case "replayed": return null;
2057
- case "wallet_session_quota_exhausted": return routerAbStepUpError(409, result.kind, "Reusable Wallet Session quota is exhausted");
2058
- case "authorization_grant_rejected": return routerAbStepUpError(403, result.kind, "Reusable Wallet Session authorization is invalid");
2059
- case "verified_step_up_rejected": return routerAbStepUpError(403, result.kind, "Reusable Wallet Session authorization is invalid");
2060
- case "material_mismatch": return routerAbStepUpError(403, result.kind, "ECDSA material activation is no longer active");
2061
- }
2062
- }
2063
- async function completeRouterAbEcdsaOperation(input) {
2064
- await input.authorizedOperations.completeAuthorizedOperation({
2065
- operation: input.operation,
2066
- result: input.result,
2067
- response: input.response,
2068
- completedAtMs: Date.now()
2069
- });
2070
- }
2071
- function routerAbEcdsaOperationStepUpScope(request) {
2072
- return "scope" in request ? request.scope : request.normal_signing_scope;
2073
- }
2074
- function parseRouterAbEcdsaOperationStepUpRequest(input) {
2075
- return input.phase === "prepare" ? parseRouterAbEcdsaDerivationEvmDigestSigningRequestV1(input.body) : parseRouterAbEcdsaDerivationEvmDigestSigningFinalizeRequestV1(input.body);
2076
- }
2077
- async function authorizeRouterAbEcdsaWalletSessionRequest(input) {
2078
- const validated = validateRouterAbEcdsaV2NormalSigningRequestForSession(input);
2079
- if (!validated.ok) return {
2080
- ok: false,
2081
- result: validated.error
2082
- };
2083
- const activeMaterial = await input.resolveEcdsaMaterialActivation({
2084
- walletId: String(input.session.walletId),
2085
- materialActivation: validated.admission.materialActivation
2086
- });
2087
- if (!activeMaterial.ok) return {
2088
- ok: false,
2089
- result: routerAbEcdsaOwnerOperationFailureResult({
2090
- status: activeMaterial.code === "internal" ? 500 : 403,
2091
- code: activeMaterial.code === "internal" ? "internal" : "material_mismatch",
2092
- message: activeMaterial.code === "internal" ? activeMaterial.message : "Wallet Session V2 material is no longer active",
2093
- phase: input.phase
2094
- })
2095
- };
2096
- if (!sameRouterAbMpcMaterialActivationRef(activeMaterial.materialActivation, validated.admission.materialActivation) || !sameRouterAbEcdsaDerivationNormalSigningScopeV1(validated.request.scope, activeMaterial.routerAbEcdsaDerivationNormalSigning.scope)) return {
2097
- ok: false,
2098
- result: routerAbStepUpError(403, "wallet_session_scope_mismatch", "Wallet Session V2 scope does not match the active material")
2099
- };
2100
- const admissionDecision = await evaluateRouterAbNormalSigningAdmission({
2101
- adapter: input.admissionAdapter,
2102
- curve: "ecdsa",
2103
- authorizationKind: "wallet_session_operation_credential_v1",
2104
- phase: input.phase,
2105
- walletId: String(input.session.walletId),
2106
- walletSessionId: String(input.session.walletSessionId),
2107
- materialActivation: activeMaterial.materialActivation,
2108
- requestId: validated.admission.requestId,
2109
- expiresAtMs: validated.admission.expiresAtMs,
2110
- signingWorkerId: activeMaterial.materialActivation.signing_worker,
2111
- keyHandle: activeMaterial.keyHandle,
2112
- runtimePolicyScope: activeMaterial.runtimePolicyScope,
2113
- admission: validated.admission
2114
- });
2115
- if (!admissionDecision.ok) return {
2116
- ok: false,
2117
- result: routerAbEcdsaOwnerOperationFailureResult({
2118
- status: admissionDecision.status,
2119
- code: admissionDecision.code,
2120
- message: admissionDecision.message,
2121
- phase: input.phase
509
+ request: input.request,
510
+ trusted_admission: privateSigningTrustedAdmission({
511
+ accountId: input.request.scope.wallet_id,
512
+ authorization: input.signingContext,
513
+ requestId: input.request.request_id,
514
+ intentDigest: input.requestDigest,
515
+ trustedSourceDigest: input.trustedSourceDigest
516
+ }),
517
+ material_source: input.materialSource ?? registrationMaterialSourceV1({
518
+ accountId: input.request.scope.wallet_id,
519
+ materialActivationId: input.request.scope.material_activation.activation_id,
520
+ signingWorkerId: input.request.scope.signing_worker.server_id
2122
521
  })
2123
522
  };
2124
- return {
2125
- ok: true,
2126
- request: validated.request,
2127
- admission: {
2128
- ...validated.admission,
2129
- materialActivation: activeMaterial.materialActivation
2130
- },
2131
- activeMaterial
2132
- };
2133
- }
2134
- async function resolveRouterAbEcdsaExhaustedCandidateAuthorization(input) {
2135
- const token = extractBearerCredential(input.headers);
2136
- if (!token) return null;
2137
- let candidate;
2138
- try {
2139
- candidate = await input.authorizationSessions.readExhaustedWalletSessionAuthorizationV2CandidateByOperationCredential({
2140
- tenantId: input.authorizationSessions.tenantId,
2141
- token,
2142
- nowMs: Date.now()
2143
- });
2144
- } catch {
2145
- return {
2146
- ok: false,
2147
- result: routerAbStepUpError(503, "wallet_session_unavailable", "Wallet Session is unavailable")
2148
- };
2149
- }
2150
- if (!candidate) return null;
2151
- const session = candidate.status.session;
2152
- const admission = resolveWalletSessionAuthorizationV2Admission({
2153
- authorization: session,
2154
- authority: candidate.authority,
2155
- authMethod: candidate.authMethod,
2156
- operation: {
2157
- tenantId: session.tenantId,
2158
- principalId: session.principalId,
2159
- walletId: session.walletId,
2160
- keyFamily: "ecdsa_secp256k1",
2161
- operationKind: "evm.sign_transaction"
2162
- },
2163
- retiredAtMs: candidate.retiredAtMs,
2164
- nowMs: Date.now()
2165
- });
2166
- if (!admission.ok || admission.keyFamily !== "ecdsa_secp256k1") return {
2167
- ok: false,
2168
- result: routerAbWalletSessionError(WALLET_SESSION_FAILURE_CODES.scopeMismatch)
2169
- };
2170
- const authorized = await authorizeRouterAbEcdsaWalletSessionRequest({
2171
- phase: input.phase,
2172
- body: input.body,
2173
- session,
2174
- admittedMaterialActivation: routerAbMpcMaterialActivationRefToWire(admission.materialActivation),
2175
- admissionAdapter: input.admissionAdapter,
2176
- resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation
2177
- });
2178
- if (!authorized.ok) return authorized;
2179
- return {
2180
- ok: true,
2181
- kind: "wallet_session_operation_credential_exhausted_candidate_v1",
2182
- candidate,
2183
- admission: authorized.admission,
2184
- activeMaterial: authorized.activeMaterial
2185
- };
2186
- }
2187
- async function authenticateRouterAbEcdsaOperationStepUp(input) {
2188
- if (!input.authorizedOperations || !input.authorizationSessions) return {
2189
- ok: false,
2190
- error: routerAbStepUpError(501, "not_configured", "ECDSA operation step-up authorization is not configured")
2191
- };
2192
- const token = extractBearerCredential(input.headers);
2193
- if (!token) return {
2194
- ok: false,
2195
- error: routerAbStepUpError(401, "unauthorized", "Wallet Session is required")
2196
- };
2197
- const requestOriginRaw = (Array.isArray(input.headers.origin) ? input.headers.origin[0] : input.headers.origin) || "";
2198
- let requestOrigin;
2199
- try {
2200
- requestOrigin = parseSessionOrigin(String(requestOriginRaw).trim());
2201
- } catch {
2202
- return {
2203
- ok: false,
2204
- error: routerAbStepUpError(401, "unauthorized", "Wallet owner proof origin is invalid")
2205
- };
2206
- }
2207
- let candidate;
2208
- try {
2209
- candidate = await input.authorizationSessions.readWalletSessionExactOperationContextByCredential({
2210
- tenantId: input.authorizationSessions.tenantId,
2211
- token,
2212
- nowMs: Date.now()
2213
- });
2214
- } catch {
2215
- return {
2216
- ok: false,
2217
- error: routerAbStepUpError(503, "wallet_session_unavailable", "Wallet Session is unavailable")
2218
- };
2219
- }
2220
- if (!candidate) return {
2221
- ok: false,
2222
- error: routerAbStepUpError(401, "unauthorized", "Wallet Session is invalid")
2223
- };
2224
- const session = candidate.session;
2225
- const scope = routerAbEcdsaOperationStepUpScope(input.request);
2226
- const admission = resolveWalletSessionAuthorizationV2Admission({
2227
- authorization: session,
2228
- authority: candidate.authority,
2229
- authMethod: candidate.authMethod,
2230
- operation: {
2231
- tenantId: session.tenantId,
2232
- principalId: session.principalId,
2233
- walletId: session.walletId,
2234
- keyFamily: "ecdsa_secp256k1",
2235
- operationKind: "evm.sign_transaction"
2236
- },
2237
- retiredAtMs: candidate.retiredAtMs,
2238
- nowMs: Date.now()
2239
- });
2240
- if (!admission.ok || admission.keyFamily !== "ecdsa_secp256k1") return {
2241
- ok: false,
2242
- error: routerAbStepUpError(403, "scope_mismatch", "Wallet Session scope is invalid")
2243
- };
2244
- const admittedMaterialActivation = routerAbMpcMaterialActivationRefToWire(admission.materialActivation);
2245
- 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 {
2246
- ok: false,
2247
- error: routerAbStepUpError(403, "scope_mismatch", "Wallet Session scope is invalid")
2248
- };
2249
- let activeMaterial;
2250
- try {
2251
- activeMaterial = await input.resolveEcdsaMaterialActivation({
2252
- walletId: scope.wallet_id,
2253
- materialActivation: admittedMaterialActivation
2254
- });
2255
- } catch {
2256
- return {
2257
- ok: false,
2258
- error: routerAbStepUpError(503, "wallet_session_unavailable", "Wallet Session is unavailable")
2259
- };
2260
- }
2261
- const normalSigning = activeMaterial.ok ? activeMaterial.routerAbEcdsaDerivationNormalSigning : null;
2262
- 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 {
2263
- ok: false,
2264
- 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)
2265
- };
2266
- if (session.tenantId !== input.authorizedOperations.tenantId || activeMaterial.runtimePolicyScope.orgId !== session.tenantId || session.expiresAtMs <= Date.now()) return {
2267
- ok: false,
2268
- error: routerAbStepUpError(403, "scope_mismatch", "Wallet Session scope is invalid")
2269
- };
2270
- return {
2271
- ok: true,
2272
- authorizedOperations: input.authorizedOperations,
2273
- activeMaterial,
2274
- session: {
2275
- tenantId: session.tenantId,
2276
- principalId: session.principalId,
2277
- sessionId: String(session.authorizationId),
2278
- walletId: String(session.walletId),
2279
- runtimePolicyScope: activeMaterial.runtimePolicyScope,
2280
- laneAuthorization: {
2281
- kind: "wallet_auth_method",
2282
- walletAuthMethodId: session.walletAuthMethodId
2283
- }
2284
- },
2285
- requestOrigin,
2286
- expiresAtMs: session.expiresAtMs
2287
- };
2288
- }
2289
- function validateRouterAbEcdsaOperationStepUpIdentity(input) {
2290
- const request = input.request;
2291
- 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");
2292
- if (request.expires_at_ms <= Date.now()) return routerAbStepUpError(408, "expired_request", "Router A/B ECDSA operation step-up request is expired");
2293
- return null;
2294
- }
2295
- async function claimRouterAbEcdsaOperationStepUp(input) {
2296
- if (!routerAbEcdsaAtomicAuthorizationConfigured(input.authenticated.authorizedOperations)) return routerAbStepUpError(501, "not_configured", "ECDSA atomic authorization is not configured");
2297
- let authorizedOperationId;
2298
- let operationEnvelope;
2299
- try {
2300
- const operationId = requireAuthorizationValue(parseCapabilityOperationId(input.operation.operation_id));
2301
- authorizedOperationId = requireAuthorizationValue(parseAuthorizedOperationId(`ecdsa-step-up-authorized-operation:${input.operation.operation_id}`));
2302
- operationEnvelope = buildCapabilityOperationEnvelope({
2303
- tenantId: input.authenticated.session.tenantId,
2304
- principalId: input.authenticated.session.principalId,
2305
- capabilityId: requireAuthorizationValue(parseCapabilityId(input.materialActivation.capability)),
2306
- operationId,
2307
- operation: buildEvmEcdsaMpcOperationRef(input.operationKind),
2308
- digests: {
2309
- laneDigest: parseDigestB64u(input.operation.operation_digests.lane_digest_b64u),
2310
- intentDigest: parseDigestB64u(input.operation.operation_digests.intent_digest_b64u),
2311
- displayDigest: parseDigestB64u(input.operation.operation_digests.display_digest_b64u)
2312
- }
2313
- });
2314
- } catch (error) {
2315
- return routerAbStepUpError(400, "invalid_body", errorMessage(error));
2316
- }
2317
- const existing = await input.authenticated.authorizedOperations.readAuthorizedOperation({
2318
- tenantId: input.authenticated.session.tenantId,
2319
- operationFingerprintDigest: await computeCapabilityOperationFingerprintDigest(operationEnvelope)
2320
- });
2321
- if (!existing || existing.authorizedOperationId !== authorizedOperationId) return routerAbStepUpError(409, "authorized_operation_missing", "Operation authorization is unavailable");
2322
- 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");
2323
- const result = await input.authenticated.authorizedOperations.admitAuthorizedOperation({
2324
- operation: {
2325
- tenantId: existing.tenantId,
2326
- authorizedOperationId: existing.authorizedOperationId,
2327
- auditEventId: existing.auditEventId,
2328
- operation: existing.operation,
2329
- authorization: existing.authorization,
2330
- quota: existing.quota,
2331
- claimedAtMs: Date.now()
2332
- },
2333
- material: {
2334
- walletId: requireAuthorizationValue(parseWalletId(input.authenticated.session.walletId)),
2335
- keyHandle: input.keyHandle,
2336
- runtimePolicyScope: input.authenticated.session.runtimePolicyScope,
2337
- materialActivation: input.materialActivation
2338
- }
2339
- });
2340
- if (result.kind === "material_mismatch") return routerAbStepUpError(403, "scope_mismatch", "ECDSA material activation changed before authorized-operation admission");
2341
- const claimFailure = routerAbOperationStepUpClaimFailure(result);
2342
- if (claimFailure) return claimFailure;
2343
- if (result.kind === "claimed" || result.kind === "operation_in_progress" || result.kind === "replayed") return {
2344
- kind: result.kind,
2345
- operation: result.operation
2346
- };
2347
- return routerAbStepUpError(409, "authorized_operation_missing", "Authorized operation is unavailable");
2348
- }
2349
- async function handleRouterAbEcdsaOperationStepUpRoute(input) {
2350
- let request;
2351
- try {
2352
- request = parseRouterAbEcdsaOperationStepUpRequest(input);
2353
- } catch (error) {
2354
- return routerAbStepUpError(400, "invalid_body", errorMessage(error));
2355
- }
2356
- if (request.authorization.kind !== "operation_step_up") return routerAbStepUpError(400, "invalid_body", "Operation step-up authority is required");
2357
- const authenticated = await authenticateRouterAbEcdsaOperationStepUp({
2358
- headers: input.headers,
2359
- request,
2360
- authorizedOperations: input.authorizedOperations,
2361
- authorizationSessions: input.authorizationSessions,
2362
- resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation
2363
- });
2364
- if (!authenticated.ok) return authenticated.error;
2365
- const identityFailure = validateRouterAbEcdsaOperationStepUpIdentity({
2366
- request,
2367
- session: authenticated.session
2368
- });
2369
- if (identityFailure) return identityFailure;
2370
- const activeMaterial = authenticated.activeMaterial;
2371
- if (!sameRouterAbMpcMaterialActivationRef(activeMaterial.materialActivation, request.scope.material_activation)) return routerAbStepUpError(403, "scope_mismatch", "ECDSA operation step-up scope does not name the active material");
2372
- const materialActivationId = requireMpcMaterialActivationId(activeMaterial.materialActivation.activation_id);
2373
- if (!input.admissionAdapter) return routerAbStepUpError(501, "not_configured", "Router A/B ECDSA operation step-up admission is not configured");
2374
- const admission = await input.admissionAdapter.evaluatePolicy({
2375
- curve: "ecdsa",
2376
- phase: input.phase,
2377
- walletId: authenticated.session.walletId,
2378
- materialActivationId,
2379
- authorizationIdentity: {
2380
- kind: "operation_step_up",
2381
- materialActivationId
2382
- },
2383
- requestId: request.request_id,
2384
- expiresAtMs: request.expires_at_ms,
2385
- signingWorkerId: activeMaterial.materialActivation.signing_worker,
2386
- keyHandle: activeMaterial.keyHandle,
2387
- runtimePolicyScope: authenticated.session.runtimePolicyScope
2388
- });
2389
- if (!admission.ok) return {
2390
- status: admission.status,
2391
- body: {
2392
- ok: false,
2393
- code: admission.code,
2394
- message: admission.message
2395
- }
2396
- };
2397
- const freshMaterial = await resolveFreshRouterAbEcdsaMaterialActivation({
2398
- resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation,
2399
- walletId: authenticated.session.walletId,
2400
- expected: request.material_activation
2401
- });
2402
- if (!freshMaterial.ok) return routerAbStepUpError(freshMaterial.code === "internal" ? 500 : 403, freshMaterial.code === "internal" ? "internal" : "scope_mismatch", freshMaterial.message);
2403
- 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");
2404
- const claimResult = await claimRouterAbEcdsaOperationStepUp({
2405
- operationKind: "evm.sign_transaction",
2406
- operation: {
2407
- operation_id: request.operation_id,
2408
- operation_digests: request.operation_digests,
2409
- material_activation: request.material_activation
2410
- },
2411
- materialActivation: freshMaterial.materialActivation,
2412
- keyHandle: freshMaterial.keyHandle,
2413
- authenticated
2414
- });
2415
- if (!claimResult) return routerAbStepUpError(409, "authorized_operation_missing", "Authorized operation is unavailable");
2416
- if ("status" in claimResult) return claimResult;
2417
- return {
2418
- operation: claimResult.operation,
2419
- session: authenticated.session,
2420
- admissionKind: claimResult.kind
2421
- };
2422
- }
2423
- async function authorizeRouterAbEcdsaDerivationNormalSigningRoute(input) {
2424
- let requestedAuthorizationKind;
2425
- try {
2426
- requestedAuthorizationKind = parseRouterAbEcdsaOperationStepUpRequest({
2427
- phase: input.phase,
2428
- body: input.body
2429
- }).authorization.kind;
2430
- } catch (error) {
2431
- return {
2432
- ok: false,
2433
- result: routerAbStepUpError(400, "invalid_body", errorMessage(error))
2434
- };
2435
- }
2436
- if (requestedAuthorizationKind === "operation_step_up") {
2437
- const stepUp = await handleRouterAbEcdsaOperationStepUpRoute({
2438
- body: input.body,
2439
- headers: input.headers,
2440
- authorizedOperations: input.authorizedOperations,
2441
- authorizationSessions: input.authorizationSessions,
2442
- admissionAdapter: input.admissionAdapter,
2443
- resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation,
2444
- phase: input.phase
2445
- });
2446
- if ("status" in stepUp) return {
2447
- ok: false,
2448
- result: stepUp
2449
- };
2450
- return {
2451
- ok: true,
2452
- kind: "operation_step_up",
2453
- phase: input.phase,
2454
- operation: stepUp.operation,
2455
- session: stepUp.session,
2456
- admissionKind: stepUp.admissionKind
2457
- };
2458
- }
2459
- const validated = await validateRouterAbEcdsaDerivationWalletSessionInputs({
2460
- headers: input.headers,
2461
- authorizationSessions: input.authorizationSessions,
2462
- operationKind: "evm.sign_transaction"
2463
- });
2464
- if (!validated.ok) {
2465
- if (validated.code === "wallet_session_unavailable" && input.authorizationSessions) {
2466
- const exhaustedCandidate = await resolveRouterAbEcdsaExhaustedCandidateAuthorization({
2467
- phase: input.phase,
2468
- body: input.body,
2469
- headers: input.headers,
2470
- authorizationSessions: input.authorizationSessions,
2471
- admissionAdapter: input.admissionAdapter,
2472
- resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation
2473
- });
2474
- if (exhaustedCandidate) return exhaustedCandidate;
2475
- }
2476
- const stepUp = await resolveRouterAbEcdsaOwnerOperationStepUpPreparation({
2477
- body: input.body,
2478
- phase: input.phase,
2479
- resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation
2480
- });
2481
- return {
2482
- ok: false,
2483
- result: routerAbEcdsaOwnerOperationFailureResult({
2484
- status: routerAbWalletSessionValidationStatus(validated.code),
2485
- code: validated.code,
2486
- message: validated.message,
2487
- phase: input.phase,
2488
- stepUp
2489
- })
2490
- };
2491
- }
2492
- const session = validated.admission.context.authorization.session;
2493
- const authorized = await authorizeRouterAbEcdsaWalletSessionRequest({
2494
- phase: input.phase,
2495
- body: input.body,
2496
- session,
2497
- admittedMaterialActivation: routerAbMpcMaterialActivationRefToWire(validated.admission.admission.materialActivation),
2498
- admissionAdapter: input.admissionAdapter,
2499
- resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation
2500
- });
2501
- if (!authorized.ok) return authorized;
2502
- return {
2503
- ok: true,
2504
- kind: "wallet_session_operation_credential_v1",
2505
- validated,
2506
- admission: authorized.admission,
2507
- activeMaterial: authorized.activeMaterial
2508
- };
2509
- }
2510
- async function handleRouterAbEcdsaDerivationNormalSigningRouteCore(input) {
2511
- const authorization = await authorizeRouterAbEcdsaDerivationNormalSigningRoute(input);
2512
- if (!authorization.ok) return authorization.result;
2513
- if (authorization.kind === "operation_step_up") return routerAbStepUpError(500, "internal", "Operation step-up must execute through the MPC router");
2514
- const walletSession = authorization.kind === "wallet_session_operation_credential_v1" ? authorization.validated.admission.context.authorization.session : authorization.candidate.status.session;
2515
- const privateBody = await buildRouterAbEcdsaDerivationPrivateSigningWorkerBody({
2516
- phase: input.phase,
2517
- body: input.body,
2518
- authorization: {
2519
- kind: "wallet_session_operation_credential_v1",
2520
- walletSessionId: String(walletSession.walletSessionId),
2521
- principalId: String(walletSession.principalId),
2522
- runtimePolicyScope: authorization.activeMaterial.runtimePolicyScope
2523
- },
2524
- headers: input.headers
2525
- });
2526
- if (!input.authorizedOperations) return routerAbStepUpError(501, "not_configured", "Reusable Wallet Session authorization is not configured");
2527
- const claimed = await admitRouterAbEcdsaReusableWalletSessionOperation({
2528
- request: input.phase === "prepare" ? parseRouterAbEcdsaDerivationEvmDigestSigningRequestV1(input.body) : parseRouterAbEcdsaDerivationEvmDigestSigningFinalizeRequestV1(input.body),
2529
- materialActivation: authorization.admission.materialActivation,
2530
- binding: authorization.kind === "wallet_session_operation_credential_v1" ? {
2531
- kind: "wallet_session_operation_credential_v1",
2532
- context: authorization.validated.admission.context
2533
- } : {
2534
- kind: "wallet_session_operation_credential_exhausted_candidate_v1",
2535
- candidate: authorization.candidate
2536
- },
2537
- authorizedOperations: input.authorizedOperations,
2538
- resolveEcdsaMaterialActivation: input.resolveEcdsaMaterialActivation
2539
- });
2540
- if (!claimed.ok) return claimed.error;
2541
- if (claimed.admission.kind === "replayed") return routerAbEcdsaReplayResult(claimed.admission.operation);
2542
- const runtime = input.runtime;
2543
- if (!runtime) return routerAbEcdsaPrivateSigningWorkerUnavailableResult();
2544
- const signingWorker = runtime.getSigningWorkerPrivateTransport();
2545
- if (signingWorker.kind === "unconfigured") return routerAbEcdsaPrivateSigningWorkerUnavailableResult();
2546
- if (input.phase === "prepare") {
2547
- if (claimed.admission.kind === "operation_in_progress") return routerAbEcdsaOperationInProgressResult();
2548
- const operation = claimed.admission.operation;
2549
- const replay = await runtime.reservePrepareReplay({
2550
- curve: "ecdsa",
2551
- authorizationIdentity: {
2552
- kind: "reusable_wallet_session",
2553
- walletSessionId: String(walletSession.walletSessionId)
2554
- },
2555
- requestId: authorization.admission.requestId,
2556
- expiresAtMs: authorization.admission.expiresAtMs
2557
- });
2558
- if (!replay.ok) {
2559
- await completeRouterAbEcdsaOperation({
2560
- authorizedOperations: input.authorizedOperations,
2561
- operation,
2562
- result: "failed_before_side_effect",
2563
- response: {
2564
- status: replay.status,
2565
- contentType: "application/json",
2566
- bodyText: JSON.stringify({
2567
- ok: false,
2568
- code: replay.code,
2569
- message: replay.message
2570
- })
2571
- }
2572
- });
2573
- return {
2574
- status: replay.status,
2575
- body: {
2576
- ok: false,
2577
- code: replay.code,
2578
- message: replay.message
2579
- }
2580
- };
2581
- }
2582
- const forwarded = await postRouterAbSigningWorkerJson({
2583
- config: signingWorker,
2584
- path: input.privatePath,
2585
- body: privateBody
2586
- });
2587
- if (!forwarded.ok && !isRouterAbEcdsaSigningWorkerOperationInProgress(forwarded)) await completeRouterAbEcdsaOperation({
2588
- authorizedOperations: input.authorizedOperations,
2589
- operation,
2590
- result: forwarded.status < 500 ? "failed_before_side_effect" : "failed_after_side_effect",
2591
- response: replayResponseFromSigningWorkerResult(forwarded)
2592
- });
2593
- return forwarded.ok ? {
2594
- status: 200,
2595
- body: forwarded.body
2596
- } : {
2597
- status: forwarded.status,
2598
- body: forwarded.body
2599
- };
2600
- }
2601
- if (claimed.admission.kind === "claimed") return routerAbStepUpError(409, "authorized_operation_missing", "ECDSA finalize requires a claimed prepare operation");
2602
- const forwarded = await postRouterAbSigningWorkerJson({
2603
- config: signingWorker,
2604
- path: input.privatePath,
2605
- body: privateBody
2606
- });
2607
- await completeRouterAbEcdsaOperation({
2608
- authorizedOperations: input.authorizedOperations,
2609
- operation: claimed.admission.operation,
2610
- result: forwarded.ok ? "succeeded" : forwarded.status < 500 ? "failed_before_side_effect" : "failed_after_side_effect",
2611
- response: replayResponseFromSigningWorkerResult(forwarded)
2612
- });
2613
- return forwarded.ok ? {
2614
- status: 200,
2615
- body: forwarded.body
2616
- } : {
2617
- status: forwarded.status,
2618
- body: forwarded.body
2619
- };
2620
523
  }
2621
524
  async function postRouterAbSigningWorkerJson(input) {
2622
525
  const fetchImpl = resolveRouterAbSigningWorkerFetch(input.config.fetchImpl);
@@ -2641,6 +544,6 @@ async function postRouterAbSigningWorkerJson(input) {
2641
544
  };
2642
545
  }
2643
546
  //#endregion
2644
- export { ROUTER_AB_ECDSA_DERIVATION_PRIVATE_SIGNING_PATHS, ROUTER_AB_ED25519_PRIVATE_SIGNING_PATHS, admitRouterAbEcdsaReusableWalletSessionOperation, authenticateRouterAbEcdsaOperationStepUp, 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 };
547
+ export { ROUTER_AB_ECDSA_DERIVATION_PRIVATE_SIGNING_PATHS, ROUTER_AB_ED25519_PRIVATE_SIGNING_PATHS, buildRouterAbEcdsaDerivationPrivateSigningWorkerBody, buildRouterAbEd25519PrivateSigningWorkerBody, computeRouterAbEd25519NormalSigningAdmissionMaterial, isRouterAbEcdsaSigningWorkerOperationInProgress, parseRouterAbEd25519NormalSigningScopeV2, postRouterAbSigningWorkerJson, replayResponseFromSigningWorkerResult, requirePrivateSigningDigest, routerAbNormalSigningMaterialSourceFromActiveLaneV1 };
2645
548
 
2646
549
  //# sourceMappingURL=routerAbPrivateSigningWorker.js.map