@seams/wallet-server 0.7.1 → 0.7.3

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 (259) hide show
  1. package/THIRD_PARTY_NOTICES.md +1 -105
  2. package/artifact-manifest.json +21 -21
  3. package/cloudflare-router-ab/build/deriver-a/build-stamp.json +1 -1
  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 -1
  6. package/cloudflare-router-ab/build/deriver-b/index_bg.wasm +0 -0
  7. package/cloudflare-router-ab/build/local-tools/darwin-arm64/router_ab_local_init +0 -0
  8. package/cloudflare-router-ab/build/local-tools/darwin-x64/router_ab_local_init +0 -0
  9. package/cloudflare-router-ab/build/local-tools/linux-x64/router_ab_local_init +0 -0
  10. package/cloudflare-router-ab/build/router/build-stamp.json +1 -1
  11. package/cloudflare-router-ab/build/router/index_bg.wasm +0 -0
  12. package/cloudflare-router-ab/build/signing-worker/build-stamp.json +1 -1
  13. package/cloudflare-router-ab/build/signing-worker/index_bg.wasm +0 -0
  14. package/cloudflare-router-ab/build/tenant-root-control-plane/build-stamp.json +1 -1
  15. package/cloudflare-router-ab/build/tenant-root-control-plane/index_bg.wasm +0 -0
  16. package/dist/esm/authorization/service.js +8 -0
  17. package/dist/esm/authorization/vaultProxyUse.js +2 -6
  18. package/dist/esm/cloud-host.js +4 -4
  19. package/dist/esm/core/IdentityStore.js +23 -110
  20. package/dist/esm/core/SessionService.js +7 -30
  21. package/dist/esm/core/ThresholdService/routerAbNormalSigningPolicy.js +3 -10
  22. package/dist/esm/core/ThresholdService/stores/WalletSessionStore.js +21 -97
  23. package/dist/esm/core/ThresholdService/stores/exportReplayGuard.js +7 -0
  24. package/dist/esm/core/WalletStore.js +4 -6
  25. package/dist/esm/core/authService/bytes.js +1 -4
  26. package/dist/esm/core/authService/emailOtpChallengeOperations.js +2 -5
  27. package/dist/esm/core/authService/emailOtpChallengeProof.js +9 -40
  28. package/dist/esm/core/authService/emailOtpChallengeVerification.js +19 -90
  29. package/dist/esm/core/authService/emailOtpChallenges.js +10 -45
  30. package/dist/esm/core/authService/emailOtpDelivery.js +10 -45
  31. package/dist/esm/core/authService/emailOtpEnrollment.js +9 -40
  32. package/dist/esm/core/authService/emailOtpGrant.js +9 -40
  33. package/dist/esm/core/authService/emailOtpRegistrationEnrollment.js +9 -40
  34. package/dist/esm/core/authService/emailOtpSeal.js +5 -20
  35. package/dist/esm/core/authService/emailOtpUnlock.js +20 -110
  36. package/dist/esm/core/authService/googleEmailOtpRegistration.js +28 -115
  37. package/dist/esm/core/authService/identity.js +5 -20
  38. package/dist/esm/core/authService/nearPublicKeyMetadata.js +6 -25
  39. package/dist/esm/core/authService/oidcVerification.js +22 -34
  40. package/dist/esm/core/authService/rateLimits.js +2 -5
  41. package/dist/esm/core/authService/thresholdEcdsaKeyInventory.js +2 -1
  42. package/dist/esm/core/authService/webauthn.js +37 -191
  43. package/dist/esm/core/authService/webauthnVerificationOutcomes.js +5 -24
  44. package/dist/esm/core/d1EcdsaSignerRead.js +76 -0
  45. package/dist/esm/core/d1IdentityStore.js +16 -75
  46. package/dist/esm/core/d1TenantStore.js +1 -1
  47. package/dist/esm/core/d1WalletStore.js +15 -25
  48. package/dist/esm/core/deviceLinking/linkedDeviceEmailOtpGrant.js +1 -5
  49. package/dist/esm/core/deviceLinking/linkedDeviceSessionApproval.js +1 -3
  50. package/dist/esm/core/deviceLinking/linkedDeviceSessionRecord.js +2 -8
  51. package/dist/esm/core/deviceLinking/requestProof.js +13 -4
  52. package/dist/esm/core/ecdsaMaterialReadSnapshot.js +85 -0
  53. package/dist/esm/core/nearRelayerAccountProvisioning.js +2 -5
  54. package/dist/esm/core/signingLanes/WalletExecutionLaneProjection.js +3 -6
  55. package/dist/esm/core/signingMaterial/ordinaryInactiveSignerMaterialReservation.js +2 -5
  56. package/dist/esm/core/storeBackends.js +1 -1
  57. package/dist/esm/core/thresholdEcdsaChainTarget.js +1 -3
  58. package/dist/esm/hosted-wallet-gateway.js +2 -2
  59. package/dist/esm/localHostedWalletGatewayHandler.js +13 -0
  60. package/dist/esm/localIntendedMaterialAdmissionFault.js +176 -0
  61. package/dist/esm/localIntendedPresignCancellation.js +44 -0
  62. package/dist/esm/router/auth/commonRouterUtils.js +24 -10
  63. package/dist/esm/router/auth/walletSessionFailure.js +2 -5
  64. package/dist/esm/router/auth/webAuthnCredentialCodecs.js +4 -15
  65. package/dist/esm/router/cloudflare/d1/auth/d1AuthorizedOperationRouteService.js +1 -0
  66. package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthBoundary.js +2 -6
  67. package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthService.js +5 -27
  68. package/dist/esm/router/cloudflare/d1/auth/walletSessionCredentialReaders.js +76 -0
  69. package/dist/esm/router/cloudflare/d1/authorization/authorizedOperationStatements.js +28 -21
  70. package/dist/esm/router/cloudflare/d1/authorization/d1AuthorizationStore.js +209 -44
  71. package/dist/esm/router/cloudflare/d1/authorization/d1VaultProxyStore.js +8 -12
  72. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceAuthorityInstallService.js +50 -8
  73. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetCredentialProvider.js +1 -1
  74. package/dist/esm/router/cloudflare/d1/deviceLinking/index.js +3 -3
  75. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeIssuer.js +12 -55
  76. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeService.js +17 -80
  77. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpDeliveryRuntime.js +6 -25
  78. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRecords.js +12 -47
  79. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRecoveryService.js +24 -85
  80. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRegistrationEnrollmentFinalizer.js +7 -30
  81. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpServerSealRuntime.js +5 -20
  82. package/dist/esm/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpSessionResolver.js +23 -110
  83. package/dist/esm/router/cloudflare/d1/identity/d1IdentityService.js +9 -40
  84. package/dist/esm/router/cloudflare/d1/near/d1NearPublicKeyStore.js +3 -10
  85. package/dist/esm/router/cloudflare/d1/oidc/d1OidcBoundary.js +18 -91
  86. package/dist/esm/router/cloudflare/d1/oidc/d1OidcVerificationService.js +6 -30
  87. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1PasskeyCustodyRouteService.js +4 -15
  88. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletCustodyCommitStore.js +2 -7
  89. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpRecords.js +9 -13
  90. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpService.js +11 -50
  91. package/dist/esm/router/cloudflare/d1/registration/d1EvmFamilyEcdsaRegistrationBranch.js +5 -20
  92. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyRecordStore.js +4 -7
  93. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyRecords.js +2 -1
  94. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationIntentService.js +7 -30
  95. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationService.js +32 -22
  96. package/dist/esm/router/cloudflare/d1/registration/walletRegistrationSessionCommitReceipt.js +1 -4
  97. package/dist/esm/router/cloudflare/d1/signingAdmission/d1RouterAbNormalSigningAdmissionStore.js +119 -25
  98. package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnAuthService.js +31 -168
  99. package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnRecords.js +6 -9
  100. package/dist/esm/router/cloudflare/durableObjects/thresholdStore.js +59 -66
  101. package/dist/esm/router/cloudflare/runtime/routerAbPrewarm.js +2 -2
  102. package/dist/esm/router/cloudflare/runtime/staticWalletConsoleBinding.js +5 -20
  103. package/dist/esm/router/cloudflare/runtime/tenantRootCreationGrant.js +2 -9
  104. package/dist/esm/router/cloudflare/runtime/walletControlOps.js +2 -1
  105. package/dist/esm/router/cloudflare/signingLanes/cloudflareLaneCurveExecution.js +2 -1
  106. package/dist/esm/router/cloudflare/signingLanes/cloudflareLaneProtocolCommitter.js +2 -2
  107. package/dist/esm/router/cloudflare.js +2146 -1802
  108. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPersistence.js +5 -8
  109. package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryWalletSessionAuthorization.js +3 -6
  110. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationIntentAuthorization.js +6 -25
  111. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.js +39 -55
  112. package/dist/esm/router/domains/emailOtp/emailOtpRouteHandlers.js +15 -62
  113. package/dist/esm/router/domains/signingOperations/routerAbEcdsaDerivationNormalSigningRoute.js +83 -74
  114. package/dist/esm/router/domains/signingOperations/routerAbNormalSigningAdmission.js +1 -0
  115. package/dist/esm/router/domains/signingOperations/routerAbOperationStepUp.js +1 -0
  116. package/dist/esm/router/domains/signingOperations/walletExecutionAdmission.js +1 -4
  117. package/dist/esm/router/domains/tenantRoot/tenantRootIdentityResolution.js +7 -13
  118. package/dist/esm/router/domains/walletUnlock/walletUnlockRouteHandlers.js +41 -200
  119. package/dist/esm/router/express.js +317 -699
  120. package/dist/esm/router/framework/http.js +5 -1
  121. package/dist/esm/router/framework/runtimeSnapshotConsumer.js +8 -35
  122. package/dist/esm/router/transport/fetch/createFetchRouter.js +3 -6
  123. package/dist/esm/router/transport/fetch/routes/auth.js +9 -41
  124. package/dist/esm/router/transport/fetch/routes/deviceLinkingOwnerAuthorization.js +5 -22
  125. package/dist/esm/router/transport/fetch/routes/nearPublicKeys.js +4 -16
  126. package/dist/esm/router/transport/fetch/routes/sessions.js +1 -0
  127. package/dist/esm/router/transport/fetch/routes/syncAccount.js +8 -36
  128. package/dist/esm/router/transport/fetch/routes/thresholdEcdsa.js +27 -79
  129. package/dist/esm/router/transport/fetch/routes/walletExecutionLanePreflight.js +4 -1
  130. package/dist/esm/router/transport/fetch/routes/webauthnAuthenticators.js +4 -16
  131. package/dist/esm/shared-ts/src/authorization/walletSignerActivationEquality.js +12 -0
  132. package/dist/esm/shared-ts/src/device-linking/committedSignerPackages.js +2 -5
  133. package/dist/esm/shared-ts/src/device-linking/delegatedActivationPlan.js +1 -5
  134. package/dist/esm/shared-ts/src/device-linking/ed25519ExportRoot.js +12 -16
  135. package/dist/esm/shared-ts/src/device-linking/sourceContribution.js +5 -8
  136. package/dist/esm/shared-ts/src/passkey-custody/primitives.js +5 -1
  137. package/dist/esm/shared-ts/src/signing-lanes/ownerContinuity.js +4 -8
  138. package/dist/esm/shared-ts/src/tenant-root/tenantRootIdentifier.js +12 -0
  139. package/dist/esm/shared-ts/src/tenant-root/tenantRootIdentity.js +2 -9
  140. package/dist/esm/shared-ts/src/tenant-root/tenantRootOperationRecord.js +1 -4
  141. package/dist/esm/shared-ts/src/utils/ecdsaKeyFactsInventory.js +2 -4
  142. package/dist/esm/shared-ts/src/utils/ecdsaServerTiming.js +0 -1
  143. package/dist/esm/shared-ts/src/utils/emailOtpDomain.js +3 -1
  144. package/dist/esm/shared-ts/src/utils/exactKeys.js +17 -0
  145. package/dist/esm/shared-ts/src/utils/failure.js +20 -0
  146. package/dist/esm/shared-ts/src/utils/registrationIntent.js +3 -12
  147. package/dist/esm/shared-ts/src/utils/registrationSignerPlan.js +2 -5
  148. package/dist/esm/shared-ts/src/utils/routerAbEcdsaDerivation.js +1 -1
  149. package/dist/esm/shared-ts/src/utils/routerAbEd25519Yao.js +1 -1
  150. package/dist/esm/shared-ts/src/utils/thresholdEcdsaChainTarget.js +9 -0
  151. package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryCommittedProjection.js +1 -4
  152. package/dist/esm/threshold/session/signingSessionSeal/crypto/cipher.js +10 -32
  153. package/dist/esm/threshold/session/signingSessionSeal/idempotencyBackends.js +3 -3
  154. package/dist/esm/threshold/session/signingSessionSeal/idempotencyRecords.js +3 -9
  155. package/dist/esm/threshold/session/signingSessionSeal/service.js +8 -35
  156. package/dist/esm/threshold/session/signingSessionSeal/transport/express.js +18 -94
  157. package/dist/esm/threshold/session/signingSessionSeal/transport/fetch.js +6 -30
  158. package/dist/esm/threshold/session/signingSessionSeal/transport/shared.js +5 -20
  159. package/dist/esm/wasm/evm_crypto/pkg/evm_crypto_bg.wasm +0 -0
  160. package/dist/esm/wasm/near_signer/pkg/wasm_signer_worker_bg.wasm +0 -0
  161. package/dist/types/shared-ts/src/authorization/delegatedAuthority.d.ts +2 -1
  162. package/dist/types/shared-ts/src/authorization/walletSessionIssuance.d.ts +9 -2
  163. package/dist/types/shared-ts/src/authorization/walletSignerActivationEquality.d.ts +4 -0
  164. package/dist/types/shared-ts/src/device-linking/committedSignerPackages.d.ts +3 -4
  165. package/dist/types/shared-ts/src/device-linking/contracts.d.ts +5 -63
  166. package/dist/types/shared-ts/src/device-linking/sourceContribution.d.ts +2 -0
  167. package/dist/types/shared-ts/src/passkey-custody/custodyEnvelope.d.ts +5 -12
  168. package/dist/types/shared-ts/src/passkey-custody/primitives.d.ts +9 -0
  169. package/dist/types/shared-ts/src/signing-lanes/execution.d.ts +11 -1
  170. package/dist/types/shared-ts/src/signing-lanes/ids.d.ts +1 -10
  171. package/dist/types/shared-ts/src/signing-lanes/rotation.d.ts +3 -5
  172. package/dist/types/shared-ts/src/tenant-root/tenantRootIdentifier.d.ts +3 -0
  173. package/dist/types/shared-ts/src/tenant-root/tenantRootOperationRecord.d.ts +2 -1
  174. package/dist/types/shared-ts/src/threshold/ecdsaDerivationRoleLocalBootstrap.d.ts +6 -0
  175. package/dist/types/shared-ts/src/threshold/signingRootScope.d.ts +1 -0
  176. package/dist/types/shared-ts/src/utils/ecdsaKeyFactsInventory.d.ts +2 -11
  177. package/dist/types/shared-ts/src/utils/eip1559TxWasmJson.d.ts +16 -0
  178. package/dist/types/shared-ts/src/utils/emailOtpDomain.d.ts +2 -0
  179. package/dist/types/shared-ts/src/utils/exactKeys.d.ts +11 -0
  180. package/dist/types/shared-ts/src/utils/failure.d.ts +12 -0
  181. package/dist/types/shared-ts/src/utils/jsonRpc.d.ts +3 -4
  182. package/dist/types/shared-ts/src/utils/nearRpcResults.d.ts +1 -0
  183. package/dist/types/shared-ts/src/utils/registrationAuthMethodInput.d.ts +3 -8
  184. package/dist/types/shared-ts/src/utils/registrationSignerPlan.d.ts +7 -19
  185. package/dist/types/shared-ts/src/utils/routerAbEcdsaDerivation.d.ts +3 -1
  186. package/dist/types/shared-ts/src/utils/routerAbEd25519Yao.d.ts +1 -0
  187. package/dist/types/shared-ts/src/utils/routerAbEd25519YaoDigests.d.ts +3 -4
  188. package/dist/types/shared-ts/src/utils/routerAbNormalSigningIdentity.d.ts +30 -8
  189. package/dist/types/shared-ts/src/utils/routerApiKeyAuth.d.ts +2 -0
  190. package/dist/types/shared-ts/src/utils/signingSessionSeal.d.ts +10 -11
  191. package/dist/types/shared-ts/src/utils/thresholdEcdsaChainTarget.d.ts +25 -0
  192. package/dist/types/shared-ts/src/utils/variant.d.ts +18 -0
  193. package/dist/types/shared-ts/src/utils/walletAuthMethodRecord.d.ts +3 -6
  194. package/dist/types/shared-ts/src/utils/webauthnDeviceInfo.d.ts +4 -2
  195. package/dist/types/shared-ts/src/wallet-recovery/recoveryEnvelopes.d.ts +3 -16
  196. package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryPreparation.d.ts +15 -0
  197. package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryTarget.d.ts +3 -4
  198. package/dist/types/wallet-server/src/authorization/domain.d.ts +13 -2
  199. package/dist/types/wallet-server/src/authorization/ecdsaWalletSessionAdmission.d.ts +27 -3
  200. package/dist/types/wallet-server/src/authorization/service.d.ts +19 -0
  201. package/dist/types/wallet-server/src/core/ThresholdService/stores/SessionStore.d.ts +2 -2
  202. package/dist/types/wallet-server/src/core/ThresholdService/stores/WalletSessionStore.d.ts +1 -1
  203. package/dist/types/wallet-server/src/core/ThresholdService/stores/exportReplayGuard.d.ts +3 -0
  204. package/dist/types/wallet-server/src/core/ThresholdService/validation.d.ts +8 -101
  205. package/dist/types/wallet-server/src/core/WebAuthnAuthenticatorStore.d.ts +8 -0
  206. package/dist/types/wallet-server/src/core/authService/bytes.d.ts +0 -1
  207. package/dist/types/wallet-server/src/core/authService/emailOtpChallenges.d.ts +2 -10
  208. package/dist/types/wallet-server/src/core/authService/emailOtpSeal.d.ts +1 -1
  209. package/dist/types/wallet-server/src/core/authService/emailOtpUnlock.d.ts +3 -10
  210. package/dist/types/wallet-server/src/core/d1EcdsaSignerRead.d.ts +39 -0
  211. package/dist/types/wallet-server/src/core/d1WalletStore.d.ts +10 -0
  212. package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceSessionRecord.d.ts +3 -4
  213. package/dist/types/wallet-server/src/core/ecdsaMaterialReadSnapshot.d.ts +19 -0
  214. package/dist/types/wallet-server/src/core/routerAbSigning/RouterAbNormalSigningRuntime.d.ts +3 -5
  215. package/dist/types/wallet-server/src/core/rpcClients/near/NearClient.d.ts +1 -2
  216. package/dist/types/wallet-server/src/core/signingLanes/WalletExecutionLaneProjection.d.ts +2 -11
  217. package/dist/types/wallet-server/src/core/signingLanes/signingWorkerLaneMaterialIdentity.d.ts +2 -19
  218. package/dist/types/wallet-server/src/core/thresholdEcdsaChainTarget.d.ts +3 -11
  219. package/dist/types/wallet-server/src/core/types.d.ts +2 -6
  220. package/dist/types/wallet-server/src/localIntendedMaterialAdmissionFault.d.ts +38 -0
  221. package/dist/types/wallet-server/src/localIntendedPresignCancellation.d.ts +4 -0
  222. package/dist/types/wallet-server/src/router/auth/authRequestValidation.d.ts +4 -9
  223. package/dist/types/wallet-server/src/router/auth/commonRouterUtils.d.ts +15 -1
  224. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthBoundary.d.ts +0 -1
  225. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthService.d.ts +1 -1
  226. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/walletSessionCredentialReaders.d.ts +9 -0
  227. package/dist/types/wallet-server/src/router/cloudflare/d1/authorization/authorizedOperationStatements.d.ts +4 -0
  228. package/dist/types/wallet-server/src/router/cloudflare/d1/authorization/d1AuthorizationStore.d.ts +10 -1
  229. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceAuthorityInstallService.d.ts +19 -2
  230. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionStore.d.ts +2 -6
  231. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetCredentialProvider.d.ts +5 -8
  232. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpEnrollmentStore.d.ts +2 -8
  233. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRateLimitStore.d.ts +2 -9
  234. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRecords.d.ts +5 -5
  235. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpServerSealRuntime.d.ts +4 -14
  236. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyRecordStore.d.ts +2 -6
  237. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationService.d.ts +8 -6
  238. package/dist/types/wallet-server/src/router/cloudflare/d1/signingAdmission/d1RouterAbNormalSigningAdmissionStore.d.ts +14 -1
  239. package/dist/types/wallet-server/src/router/cloudflare/d1/webauthn/d1WebAuthnRecords.d.ts +10 -39
  240. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletConsoleOps.d.ts +8 -34
  241. package/dist/types/wallet-server/src/router/domains/ecdsa/thresholdEcdsaRequestValidation.d.ts +3 -15
  242. package/dist/types/wallet-server/src/router/domains/ed25519Yao/session/routerAbEd25519YaoWalletSession.d.ts +9 -50
  243. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletRecoveryKeyManifest.d.ts +1 -13
  244. package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbEcdsaDerivationNormalSigningRoute.d.ts +8 -9
  245. package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbNormalSigningAdmission.d.ts +13 -0
  246. package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbOperationStepUp.d.ts +3 -4
  247. package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbPrivateSigningWorker.d.ts +7 -16
  248. package/dist/types/wallet-server/src/router/domains/syncAccount/syncAccountRequestValidation.d.ts +2 -7
  249. package/dist/types/wallet-server/src/router/framework/apiCredentialPorts.d.ts +3 -1
  250. package/dist/types/wallet-server/src/router/framework/authServicePort.d.ts +25 -4
  251. package/dist/types/wallet-server/src/router/framework/http.d.ts +1 -0
  252. package/dist/types/wallet-server/src/router/framework/ror/normalize.d.ts +1 -9
  253. package/dist/types/wallet-server/src/router/transport/fetch/routes/deviceLinkingOwnerAuthorization.d.ts +3 -6
  254. package/dist/types/wallet-server/src/router/transport/fetch/routes/syncAccountBootstrap.d.ts +3 -5
  255. package/dist/types/wallet-server/src/router/transport/fetch/routes/thresholdEcdsa.d.ts +0 -1
  256. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/idempotencyRecords.d.ts +1 -2
  257. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/signingSessionSeal.types.d.ts +6 -8
  258. package/package.json +1 -1
  259. package/dist/esm/wasm/router_ab_ecdsa_signing_worker/pkg/router_ab_ecdsa_signing_worker_bg.wasm +0 -0
@@ -1,6 +1,7 @@
1
1
  import { ROUTER_AB_ED25519_YAO_RECOVERY_CHALLENGE_ID_HEADER_V1 } from "../../shared-ts/src/utils/routerAbEd25519Yao.js";
2
2
  import { LINKED_DEVICE_REQUEST_PROOF_HEADER_V1 } from "../../shared-ts/src/device-linking/requestProof.js";
3
3
  import "../../shared-ts/src/device-linking/index.js";
4
+ import { failure } from "../../shared-ts/src/utils/failure.js";
4
5
  import { buildCorsOrigins, normalizeCorsOrigin } from "../../core/SessionService.js";
5
6
  import { ROUTER_AB_TRACE_ID_HEADER_V1 } from "../../shared-ts/src/utils/routerAbTraceContext.js";
6
7
  //#region src/router/framework/http.ts
@@ -30,6 +31,9 @@ function json(body, init, extraHeaders) {
30
31
  headers
31
32
  });
32
33
  }
34
+ function jsonFailure(status, code, message) {
35
+ return json(failure(code, message), { status });
36
+ }
33
37
  function withCors(headers, opts, request) {
34
38
  const pathname = request ? new URL(request.url).pathname : "";
35
39
  if (pathname === "/healthz" || pathname === "/readyz") {
@@ -82,6 +86,6 @@ function headersToRecord(headers) {
82
86
  return out;
83
87
  }
84
88
  //#endregion
85
- export { headersToRecord, json, readJson, toResponse, withCors };
89
+ export { headersToRecord, json, jsonFailure, readJson, toResponse, withCors };
86
90
 
87
91
  //# sourceMappingURL=http.js.map
@@ -1,3 +1,4 @@
1
+ import { failure } from "../../shared-ts/src/utils/failure.js";
1
2
  //#region src/router/framework/runtimeSnapshotConsumer.ts
2
3
  function parseExpectation(raw) {
3
4
  if (raw === void 0 || raw === null) return { parsed: null };
@@ -38,45 +39,17 @@ function parseExpectation(raw) {
38
39
  }
39
40
  async function validateRuntimeSnapshotExpectation(input) {
40
41
  const expectationResult = parseExpectation(input.expectationRaw);
41
- if (expectationResult.error) return {
42
- ok: false,
43
- code: "runtime_snapshot_invalid_expectation",
44
- message: expectationResult.error
45
- };
42
+ if (expectationResult.error) return failure("runtime_snapshot_invalid_expectation", expectationResult.error);
46
43
  const expectation = expectationResult.parsed;
47
44
  if (!expectation) return { ok: true };
48
45
  const scope = input.scope;
49
- if (!scope) return {
50
- ok: false,
51
- code: "runtime_snapshot_scope_missing",
52
- message: "threshold session is missing runtimePolicyScope"
53
- };
54
- if (!input.runtimeSnapshots) return {
55
- ok: false,
56
- code: "runtime_snapshots_not_configured",
57
- message: "Runtime snapshot consumer is not configured on this server"
58
- };
46
+ if (!scope) return failure("runtime_snapshot_scope_missing", "threshold session is missing runtimePolicyScope");
47
+ if (!input.runtimeSnapshots) return failure("runtime_snapshots_not_configured", "Runtime snapshot consumer is not configured on this server");
59
48
  const latest = await input.runtimeSnapshots.getLatestSnapshot(scope);
60
- if (!latest) return {
61
- ok: false,
62
- code: "runtime_snapshot_not_found",
63
- message: `No runtime snapshot found for org=${scope.orgId} project=${scope.projectId} env=${scope.envId}`
64
- };
65
- if (expectation.snapshotId && latest.snapshotId !== expectation.snapshotId) return {
66
- ok: false,
67
- code: "runtime_snapshot_id_mismatch",
68
- message: `Runtime snapshot id mismatch: expected ${expectation.snapshotId}, got ${latest.snapshotId}`
69
- };
70
- if (expectation.version !== void 0 && latest.version !== expectation.version) return {
71
- ok: false,
72
- code: "runtime_snapshot_version_mismatch",
73
- message: `Runtime snapshot version mismatch: expected ${expectation.version}, got ${latest.version}`
74
- };
75
- if (expectation.checksum && latest.checksum !== expectation.checksum) return {
76
- ok: false,
77
- code: "runtime_snapshot_checksum_mismatch",
78
- message: `Runtime snapshot checksum mismatch: expected ${expectation.checksum}, got ${latest.checksum}`
79
- };
49
+ if (!latest) return failure("runtime_snapshot_not_found", `No runtime snapshot found for org=${scope.orgId} project=${scope.projectId} env=${scope.envId}`);
50
+ if (expectation.snapshotId && latest.snapshotId !== expectation.snapshotId) return failure("runtime_snapshot_id_mismatch", `Runtime snapshot id mismatch: expected ${expectation.snapshotId}, got ${latest.snapshotId}`);
51
+ if (expectation.version !== void 0 && latest.version !== expectation.version) return failure("runtime_snapshot_version_mismatch", `Runtime snapshot version mismatch: expected ${expectation.version}, got ${latest.version}`);
52
+ if (expectation.checksum && latest.checksum !== expectation.checksum) return failure("runtime_snapshot_checksum_mismatch", `Runtime snapshot checksum mismatch: expected ${expectation.checksum}, got ${latest.checksum}`);
80
53
  return { ok: true };
81
54
  }
82
55
  function makeScopeKey(scope) {
@@ -5,7 +5,7 @@ import { routerAbEcdsaDerivationActiveStateId } from "../../../shared-ts/src/uti
5
5
  import { findRouteDefinitionForRequest } from "../../framework/routeDefinitions.js";
6
6
  import { getRouterApiRouteExtensionRoutes, getRouterApiRouteExtensionsForTransport } from "../../framework/routeExtensions.js";
7
7
  import { coerceRouterLogger } from "../../framework/logger.js";
8
- import { json, withCors } from "../../framework/http.js";
8
+ import { json, jsonFailure, withCors } from "../../framework/http.js";
9
9
  import { handleHealth, handleReady } from "./routes/health.js";
10
10
  import { extractBearerCredential } from "../../auth/routerApiKeyAuth.js";
11
11
  import { resolveWalletSessionOperationCredentialAdmissionFromContext } from "../../auth/commonRouterUtils.js";
@@ -44,6 +44,7 @@ async function signingSessionSealRecordFromExactAdmission(input) {
44
44
  switch (admission.curve) {
45
45
  case "ecdsa": {
46
46
  const active = await input.walletRegistration.resolveEcdsaMaterialActivation({
47
+ source: { kind: "database" },
47
48
  walletId,
48
49
  materialActivation
49
50
  });
@@ -204,11 +205,7 @@ function createFetchRouter(service, opts, runtime) {
204
205
  async (context) => {
205
206
  if (!context.pathname.startsWith("/wallet/device-linking/v1/devices")) return null;
206
207
  const service = context.service.deviceManagement;
207
- if (!service) return json({
208
- ok: false,
209
- code: "not_supported",
210
- message: "Linked-device management is not configured"
211
- }, { status: 501 });
208
+ if (!service) return jsonFailure(501, "not_supported", "Linked-device management is not configured");
212
209
  return await handleDeviceManagement(context, service);
213
210
  },
214
211
  handlePasskeyCustody,
@@ -1,4 +1,4 @@
1
- import { json, readJson } from "../../../framework/http.js";
1
+ import { json, jsonFailure, readJson } from "../../../framework/http.js";
2
2
  import { extractBearerCredential } from "../../../auth/routerApiKeyAuth.js";
3
3
  import { resolveThresholdRuntimePolicyScope } from "../../../auth/commonRouterUtils.js";
4
4
  import { parseAuthIdentityMutationRequest, parseAuthProviderActionPath, parseGoogleLoginVerifyRequest, parsePasskeyLoginOptionsRequest, parsePasskeyLoginVerifyRequest } from "../../../auth/authRequestValidation.js";
@@ -13,11 +13,7 @@ async function requireExactWalletSession(ctx) {
13
13
  const token = extractBearerCredential(ctx.request.headers);
14
14
  if (!token) return {
15
15
  ok: false,
16
- response: json({
17
- ok: false,
18
- code: "unauthorized",
19
- message: "No valid Wallet Session"
20
- }, { status: 401 })
16
+ response: jsonFailure(401, "unauthorized", "No valid Wallet Session")
21
17
  };
22
18
  try {
23
19
  const context = await ctx.service.authorizationSessions.readWalletSessionAuthorizationV2ByOperationCredential({
@@ -27,11 +23,7 @@ async function requireExactWalletSession(ctx) {
27
23
  });
28
24
  if (!context) return {
29
25
  ok: false,
30
- response: json({
31
- ok: false,
32
- code: "unauthorized",
33
- message: "No valid Wallet Session"
34
- }, { status: 401 })
26
+ response: jsonFailure(401, "unauthorized", "No valid Wallet Session")
35
27
  };
36
28
  return {
37
29
  ok: true,
@@ -40,11 +32,7 @@ async function requireExactWalletSession(ctx) {
40
32
  } catch {
41
33
  return {
42
34
  ok: false,
43
- response: json({
44
- ok: false,
45
- code: "wallet_session_unavailable",
46
- message: "Wallet Session is unavailable"
47
- }, { status: 503 })
35
+ response: jsonFailure(503, "wallet_session_unavailable", "Wallet Session is unavailable")
48
36
  };
49
37
  }
50
38
  }
@@ -57,19 +45,11 @@ async function requireExactPasskeyStepUp(input) {
57
45
  const walletId = String(input.context.authorization.session.walletId);
58
46
  if (String(result.userId).trim() !== walletId) return {
59
47
  ok: false,
60
- response: json({
61
- ok: false,
62
- code: "forbidden",
63
- message: "Step-up user mismatch"
64
- }, { status: 403 })
48
+ response: jsonFailure(403, "forbidden", "Step-up user mismatch")
65
49
  };
66
50
  if (result.walletAuthMethodId !== input.context.authMethod.walletAuthMethodId || result.walletAuthorityId !== input.context.authority.authorityId) return {
67
51
  ok: false,
68
- response: json({
69
- ok: false,
70
- code: "forbidden",
71
- message: "Step-up authority mismatch"
72
- }, { status: 403 })
52
+ response: jsonFailure(403, "forbidden", "Step-up authority mismatch")
73
53
  };
74
54
  return { ok: true };
75
55
  }
@@ -127,11 +107,7 @@ async function handleAuth(ctx) {
127
107
  default: assertNeverAuthIdentityMutation(command);
128
108
  }
129
109
  const subject = command.request.subject;
130
- if (subject.startsWith("near:")) return json({
131
- ok: false,
132
- code: "not_supported",
133
- message: "near: subjects cannot be unlinked"
134
- }, { status: 400 });
110
+ if (subject.startsWith("near:")) return jsonFailure(400, "not_supported", "near: subjects cannot be unlinked");
135
111
  const out = await ctx.service.identity.unlinkIdentity({
136
112
  userId: walletId,
137
113
  subject
@@ -188,16 +164,8 @@ async function handleAuth(ctx) {
188
164
  publishableKeyAuth: ctx.opts.publishableKeyAuth,
189
165
  orgProjectEnv: ctx.opts.orgProjectEnv
190
166
  });
191
- if (!runtimePolicyScope.ok) return json({
192
- ok: false,
193
- code: runtimePolicyScope.code,
194
- message: runtimePolicyScope.message
195
- }, { status: runtimePolicyScope.status });
196
- if (!runtimePolicyScope.scope) return json({
197
- ok: false,
198
- code: "runtime_policy_scope_unavailable",
199
- message: "Google Email OTP requires an active managed runtime policy scope"
200
- }, { status: 500 });
167
+ if (!runtimePolicyScope.ok) return jsonFailure(runtimePolicyScope.status, runtimePolicyScope.code, runtimePolicyScope.message);
168
+ if (!runtimePolicyScope.scope) return jsonFailure(500, "runtime_policy_scope_unavailable", "Google Email OTP requires an active managed runtime policy scope");
201
169
  const result = await ctx.service.identity.verifyGoogleLogin(parsed.request);
202
170
  if (!result.ok || !result.verified || !result.providerSubject) return json(result, { status: result.code === "internal" ? 500 : 400 });
203
171
  const resolution = await ctx.service.identity.resolveGoogleEmailOtpSession({
@@ -5,7 +5,7 @@ import { buildEmailOtpWalletAuthAuthority, buildPasskeyWalletAuthAuthority, wall
5
5
  import { parseLinkedDeviceOwnerAuthorizationRequestV1 } from "../../../../shared-ts/src/device-linking/parsers.js";
6
6
  import { buildWalletSessionCapabilitySubjectsV1, walletSessionCapabilitySubjectsV1Equal } from "../../../../authorization/domain.js";
7
7
  import { thresholdEd25519AuthorityScopeFromWalletAuthAuthority } from "../../../../core/ThresholdService/validation.js";
8
- import { json, readJson } from "../../../framework/http.js";
8
+ import { json, jsonFailure, readJson } from "../../../framework/http.js";
9
9
  import { extractBearerCredential } from "../../../auth/routerApiKeyAuth.js";
10
10
  //#region src/router/transport/fetch/routes/deviceLinkingOwnerAuthorization.ts
11
11
  const LINKED_DEVICE_OWNER_AUTHORIZATION_PATH_V1 = "/wallet/device-linking/v1/owner-authorization";
@@ -61,11 +61,7 @@ async function authenticateDeviceLinkingOwnerWalletSessionRequestV1(input) {
61
61
  async function handleDeviceLinkingOwnerAuthorization(ctx, service) {
62
62
  if (ctx.pathname !== "/wallet/device-linking/v1/owner-authorization") return null;
63
63
  if (ctx.method !== "POST") return methodNotAllowedResponse();
64
- if (!service) return json({
65
- ok: false,
66
- code: "not_supported",
67
- message: "Linked-device owner authorization is not configured"
68
- }, { status: 501 });
64
+ if (!service) return jsonFailure(501, "not_supported", "Linked-device owner authorization is not configured");
69
65
  const nowV1 = Date.now;
70
66
  let body;
71
67
  let rawBody;
@@ -75,11 +71,7 @@ async function handleDeviceLinkingOwnerAuthorization(ctx, service) {
75
71
  rawBody = await readJson(ctx.request.clone());
76
72
  body = parseLinkedDeviceOwnerAuthorizationRequestV1(rawBody);
77
73
  } catch (error) {
78
- return json({
79
- ok: false,
80
- code: "invalid_body",
81
- message: error instanceof Error ? error.message : "Owner authorization body is invalid"
82
- }, { status: 400 });
74
+ return jsonFailure(400, "invalid_body", error instanceof Error ? error.message : "Owner authorization body is invalid");
83
75
  }
84
76
  const validated = await authenticateDeviceLinkingOwnerWalletSessionRequestV1({
85
77
  request: ctx.request,
@@ -99,11 +91,7 @@ async function handleDeviceLinkingOwnerAuthorization(ctx, service) {
99
91
  owner: validated.owner
100
92
  }), { status: 200 });
101
93
  } catch (error) {
102
- return json({
103
- ok: false,
104
- code: "internal",
105
- message: error instanceof Error ? error.message : String(error)
106
- }, { status: 500 });
94
+ return jsonFailure(500, "internal", error instanceof Error ? error.message : String(error));
107
95
  }
108
96
  }
109
97
  async function validateOwnerWalletSessionV1(input) {
@@ -267,12 +255,7 @@ function methodNotAllowedResponse() {
267
255
  }, { status: 405 });
268
256
  }
269
257
  function authDeniedResponse(value) {
270
- const status = value.code === "expired" ? 401 : value.code === "invalid" ? 403 : 401;
271
- return json({
272
- ok: false,
273
- code: value.code,
274
- message: value.message
275
- }, { status });
258
+ return jsonFailure(value.code === "expired" ? 401 : value.code === "invalid" ? 403 : 401, value.code, value.message);
276
259
  }
277
260
  //#endregion
278
261
  export { LINKED_DEVICE_OWNER_AUTHORIZATION_PATH_V1, authenticateDeviceLinkingOwnerWalletSessionRequestV1, createDeviceLinkingOwnerRequestAuthenticatorV1, handleDeviceLinkingOwnerAuthorization };
@@ -1,4 +1,4 @@
1
- import { json } from "../../../framework/http.js";
1
+ import { json, jsonFailure } from "../../../framework/http.js";
2
2
  import { extractBearerCredential } from "../../../auth/routerApiKeyAuth.js";
3
3
  //#region src/router/transport/fetch/routes/nearPublicKeys.ts
4
4
  async function handleNearPublicKeys(ctx) {
@@ -6,31 +6,19 @@ async function handleNearPublicKeys(ctx) {
6
6
  if (ctx.pathname !== "/near/public-keys") return null;
7
7
  try {
8
8
  const token = extractBearerCredential(ctx.request.headers);
9
- if (!token) return json({
10
- ok: false,
11
- code: "unauthorized",
12
- message: "No valid Wallet Session"
13
- }, { status: 401 });
9
+ if (!token) return jsonFailure(401, "unauthorized", "No valid Wallet Session");
14
10
  const nowMs = Date.now();
15
11
  const exact = await ctx.service.authorizationSessions.readWalletSessionAuthorizationV2ByOperationCredential({
16
12
  tenantId: ctx.service.authorizationSessions.tenantId,
17
13
  token,
18
14
  nowMs
19
15
  });
20
- if (!exact) return json({
21
- ok: false,
22
- code: "unauthorized",
23
- message: "No valid Wallet Session"
24
- }, { status: 401 });
16
+ if (!exact) return jsonFailure(401, "unauthorized", "No valid Wallet Session");
25
17
  const result = await ctx.service.nearFunding.listNearPublicKeysForUser({ userId: String(exact.authorization.session.walletId) });
26
18
  if (!result.ok) return json(result, { status: result.code === "not_supported" ? 501 : result.code === "invalid_args" ? 400 : 500 });
27
19
  return json(result, { status: 200 });
28
20
  } catch (e) {
29
- return json({
30
- ok: false,
31
- code: "internal",
32
- message: e?.message || "Internal error"
33
- }, { status: 500 });
21
+ return jsonFailure(500, "internal", e?.message || "Internal error");
34
22
  }
35
23
  }
36
24
  //#endregion
@@ -123,6 +123,7 @@ async function resolveWalletEmailOtpChallengeSignerSelection(args) {
123
123
  };
124
124
  }
125
125
  const resolved = await args.ctx.service.walletRegistration.resolveEcdsaMaterialActivation({
126
+ source: { kind: "database" },
126
127
  walletId: String(args.authority.walletId),
127
128
  materialActivation: routerAbMpcMaterialActivationRefToWire(ecdsaActivation.materialActivation)
128
129
  });
@@ -6,7 +6,7 @@ import { walletAuthAuthorityRef } from "../../../../shared-ts/src/utils/walletAu
6
6
  import { parseSessionOrigin, parseVerifiedOwnerProofId } from "../../../../authorization/domain.js";
7
7
  import { buildVerifiedWalletSessionPasskeyFactorResult } from "../../../../authorization/factorEvidence.js";
8
8
  import { walletIdFromString } from "../../../../shared-ts/src/utils/registrationIds.js";
9
- import { json, readJson } from "../../../framework/http.js";
9
+ import { json, jsonFailure, readJson } from "../../../framework/http.js";
10
10
  import { parseSyncAccountOptionsRequest, parseSyncAccountVerifyRequest } from "../../../domains/syncAccount/syncAccountRequestValidation.js";
11
11
  import { DEFAULT_WALLET_SESSION_TTL_MS } from "../../../../shared-ts/src/threshold/sessionPolicy.js";
12
12
  import { issueSyncAccountBootstrapV1 } from "./syncAccountBootstrap.js";
@@ -55,11 +55,7 @@ async function handleSyncAccount(ctx) {
55
55
  let responseBody = result;
56
56
  if (result.ok && result.verified && result.thresholdEd25519) {
57
57
  const custodyKeyManifestDigestB64u = result.custodyKeyManifestDigestB64u;
58
- if (!custodyKeyManifestDigestB64u) return json({
59
- ok: false,
60
- code: "internal",
61
- message: "Sync verification did not resolve the wallet key manifest"
62
- }, { status: 500 });
58
+ if (!custodyKeyManifestDigestB64u) return jsonFailure(500, "internal", "Sync verification did not resolve the wallet key manifest");
63
59
  const thresholdEd25519 = result.thresholdEd25519;
64
60
  const walletId = String(result.walletId || "").trim();
65
61
  const nearAccountId = String(result.nearAccountId || "").trim();
@@ -67,11 +63,7 @@ async function handleSyncAccount(ctx) {
67
63
  const signerSlot = Number(result.signerSlot);
68
64
  const walletBinding = result.walletBinding;
69
65
  const credentialIdB64u = String(result.credentialIdB64u || "").trim();
70
- if (!thresholdEd25519 || !walletId || !nearAccountId || !nearEd25519SigningKeyId || !Number.isSafeInteger(signerSlot) || signerSlot < 1 || !walletBinding || !credentialIdB64u || !String(result.publicKey || "").trim() || !String(result.credentialPublicKeyB64u || "").trim() || String(walletBinding.walletId) !== walletId || String(walletBinding.nearAccountId) !== nearAccountId || String(walletBinding.nearEd25519SigningKeyId) !== nearEd25519SigningKeyId || walletBinding.signerSlot !== signerSlot) return json({
71
- ok: false,
72
- code: "internal",
73
- message: "verified passkey wallet is missing its Ed25519 Yao identity"
74
- }, { status: 500 });
66
+ if (!thresholdEd25519 || !walletId || !nearAccountId || !nearEd25519SigningKeyId || !Number.isSafeInteger(signerSlot) || signerSlot < 1 || !walletBinding || !credentialIdB64u || !String(result.publicKey || "").trim() || !String(result.credentialPublicKeyB64u || "").trim() || String(walletBinding.walletId) !== walletId || String(walletBinding.nearAccountId) !== nearAccountId || String(walletBinding.nearEd25519SigningKeyId) !== nearEd25519SigningKeyId || walletBinding.signerSlot !== signerSlot) return jsonFailure(500, "internal", "verified passkey wallet is missing its Ed25519 Yao identity");
75
67
  const authority = passkeyWalletAuthAuthorityForMethod({
76
68
  walletId: walletBinding.walletId,
77
69
  rpId: walletBinding.rpId,
@@ -83,29 +75,17 @@ async function handleSyncAccount(ctx) {
83
75
  rpId: authority.verifier.rpId,
84
76
  credentialIdB64u: authority.factor.credentialIdB64u
85
77
  });
86
- if (!activeAuthority.ok || activeAuthority.walletAuthority.authorityId !== result.walletAuthorityId || activeAuthority.authMethod.walletAuthMethodId !== result.walletAuthMethodId) return json({
87
- ok: false,
88
- code: "internal",
89
- message: "Verified passkey wallet authority is unavailable"
90
- }, { status: 500 });
78
+ if (!activeAuthority.ok || activeAuthority.walletAuthority.authorityId !== result.walletAuthorityId || activeAuthority.authMethod.walletAuthMethodId !== result.walletAuthMethodId) return jsonFailure(500, "internal", "Verified passkey wallet authority is unavailable");
91
79
  const authorityRef = await walletAuthAuthorityRef({ authority });
92
80
  const principalId = parsePrincipalId(walletId);
93
81
  const mintId = parseWalletSessionMintId(parsed.request.challengeId);
94
- if (!principalId.ok || !mintId.ok) return json({
95
- ok: false,
96
- code: "internal",
97
- message: "Verified passkey Wallet Session identity is invalid"
98
- }, { status: 500 });
82
+ if (!principalId.ok || !mintId.ok) return jsonFailure(500, "internal", "Verified passkey Wallet Session identity is invalid");
99
83
  const issuedAtMs = Date.now();
100
84
  const expiresAtMs = issuedAtMs + DEFAULT_WALLET_SESSION_TTL_MS;
101
85
  const origin = parseSessionOrigin(parsed.request.expected_origin);
102
86
  const factorId = parseAuthFactorId(`passkey:${credentialIdB64u}`);
103
87
  const credentialId = parseWebAuthnCredentialIdB64u(credentialIdB64u);
104
- if (!factorId.ok || !credentialId.ok) return json({
105
- ok: false,
106
- code: "internal",
107
- message: "Verified passkey factor identity is invalid"
108
- }, { status: 500 });
88
+ if (!factorId.ok || !credentialId.ok) return jsonFailure(500, "internal", "Verified passkey factor identity is invalid");
109
89
  const proof = await ctx.service.authorizedOperations.buildVerifiedOwnerProof({
110
90
  purpose: "wallet_session",
111
91
  proofId: parseVerifiedOwnerProofId(`sync-account:${parsed.request.challengeId}`),
@@ -123,11 +103,7 @@ async function handleSyncAccount(ctx) {
123
103
  expiresAtMs
124
104
  })
125
105
  });
126
- if (proof.purpose !== "wallet_session") return json({
127
- ok: false,
128
- code: "internal",
129
- message: "Owner proof purpose is invalid"
130
- }, { status: 500 });
106
+ if (proof.purpose !== "wallet_session") return jsonFailure(500, "internal", "Owner proof purpose is invalid");
131
107
  const bootstrap = await issueSyncAccountBootstrapV1({
132
108
  ctx,
133
109
  result: {
@@ -168,11 +144,7 @@ async function handleSyncAccount(ctx) {
168
144
  message: "Wallet Session sync is already committed; retry the exact method",
169
145
  ...bootstrap.committed
170
146
  }, { status: 409 });
171
- if (bootstrap.kind === "error") return json({
172
- ok: false,
173
- code: bootstrap.code,
174
- message: bootstrap.message
175
- }, { status: bootstrap.status });
147
+ if (bootstrap.kind === "error") return jsonFailure(bootstrap.status, bootstrap.code, bootstrap.message);
176
148
  responseBody = bootstrap.body;
177
149
  }
178
150
  return json(responseBody, { status: syncAccountResponseStatus(result) });
@@ -236,18 +236,13 @@ async function executeRouterAbEcdsaDerivationNormalSigningRoute(input, timing) {
236
236
  binding: await ecdsaOperationStepUpBinding(input.ctx, authorization.session, authorizedOperation)
237
237
  });
238
238
  } else {
239
+ const request = input.phase === "prepare" ? parseRouterAbEcdsaDerivationEvmDigestSigningRequestV1(input.body) : parseRouterAbEcdsaDerivationEvmDigestSigningFinalizeRequestV1(input.body);
239
240
  const operation = await admitRouterAbEcdsaReusableWalletSessionOperation({
240
- request: input.phase === "prepare" ? parseRouterAbEcdsaDerivationEvmDigestSigningRequestV1(input.body) : parseRouterAbEcdsaDerivationEvmDigestSigningFinalizeRequestV1(input.body),
241
- materialActivation: authorization.admission.materialActivation,
242
- binding: authorization.kind === "wallet_session_operation_credential_v1" ? {
243
- kind: "wallet_session_operation_credential_v1",
244
- context: authorization.validated.admission.context
245
- } : {
246
- kind: "wallet_session_operation_credential_exhausted_candidate_v1",
247
- candidate: authorization.candidate
248
- },
249
- authorizedOperations: input.ctx.service.authorizedOperations,
250
- resolveEcdsaMaterialActivation: input.ctx.service.walletRegistration.resolveEcdsaMaterialActivation.bind(input.ctx.service.walletRegistration)
241
+ phase: input.phase,
242
+ request,
243
+ material: authorization.activeMaterial,
244
+ binding: authorization,
245
+ authorizedOperations: input.ctx.service.authorizedOperations
251
246
  });
252
247
  if (!operation.ok) {
253
248
  const failureBody = operation.error.body;
@@ -273,11 +268,6 @@ async function executeRouterAbEcdsaDerivationNormalSigningRoute(input, timing) {
273
268
  return json(failure.body, { status: failure.status });
274
269
  }
275
270
  if (operation.admission.kind === "replayed") return routerAbEcdsaReplayResponse(operation.admission.operation);
276
- if (operation.admission.kind === "claimed" && input.phase === "finalize") return json({
277
- ok: false,
278
- code: "authorized_operation_missing",
279
- message: "ECDSA finalize requires a claimed prepare operation"
280
- }, { status: 409 });
281
271
  const ownerDecision = decideRouterAbEcdsaOwnerOperationAuthorization({ operation: operation.admission.operation });
282
272
  switch (ownerDecision.kind) {
283
273
  case "authorized": break;
@@ -502,6 +492,7 @@ async function issueEcdsaOperationStepUpAuthorization(input) {
502
492
  message: v2Resolution.message
503
493
  }, { status: 403 });
504
494
  const activeMaterial = v2Resolution.kind === "admitted" ? v2Resolution.activeMaterial : await input.ctx.service.walletRegistration.resolveEcdsaMaterialActivation({
495
+ source: { kind: "database" },
505
496
  walletId: operation.wallet_id,
506
497
  materialActivation: operation.material_activation
507
498
  });
@@ -820,7 +811,6 @@ async function issueEcdsaOperationStepUpAuthorization(input) {
820
811
  async function handleEcdsaPoolFillRoute(input) {
821
812
  const startedAt = performance.now();
822
813
  const timing = {
823
- queue: null,
824
814
  authenticate: null,
825
815
  material: null,
826
816
  admit: null,
@@ -855,31 +845,24 @@ async function executeEcdsaPoolFillRoute(input, timing, workerTimings) {
855
845
  const parsed = input.phase === "init" ? parseRouterAbEcdsaDerivationPoolFillInitRouteRequest(input.body) : parseRouterAbEcdsaDerivationPoolFillStepRouteRequest(input.body);
856
846
  if (!parsed.ok) return json(parsed.body, { status: thresholdEcdsaStatusCode(parsed.body) });
857
847
  const request = parsed.request;
858
- const queuedAt = performance.now();
859
- const gateTicket = await presignPriorityGate.acquire(resolvePresignTrafficClass(request.requestTag));
860
- timing.queue = performance.now() - queuedAt;
861
- try {
862
- const authorized = await authorizeEcdsaPoolFill({
863
- ctx: input.ctx,
864
- request,
865
- timing
866
- });
867
- if (!authorized.ok) return json(authorized.error.body, { status: authorized.error.status });
868
- const proxyStartedAt = performance.now();
869
- const result = "poolFill" in request ? await runtime.initializePoolFill({
870
- binding: authorized.binding,
871
- request: ecdsaPoolFillInitRuntimeRequest(request),
872
- onServerTiming: collectEcdsaPresignWorkerTiming.bind(void 0, workerTimings)
873
- }) : await runtime.advancePoolFill({
874
- binding: authorized.binding,
875
- request: ecdsaPoolFillStepRuntimeRequest(request),
876
- onServerTiming: collectEcdsaPresignWorkerTiming.bind(void 0, workerTimings)
877
- });
878
- timing.proxy = performance.now() - proxyStartedAt;
879
- return json(result, { status: thresholdEcdsaStatusCode(result) });
880
- } finally {
881
- gateTicket.release();
882
- }
848
+ const authorized = await authorizeEcdsaPoolFill({
849
+ ctx: input.ctx,
850
+ request,
851
+ timing
852
+ });
853
+ if (!authorized.ok) return json(authorized.error.body, { status: authorized.error.status });
854
+ const proxyStartedAt = performance.now();
855
+ const result = "poolFill" in request ? await runtime.initializePoolFill({
856
+ binding: authorized.binding,
857
+ request: ecdsaPoolFillInitRuntimeRequest(request),
858
+ onServerTiming: collectEcdsaPresignWorkerTiming.bind(void 0, workerTimings)
859
+ }) : await runtime.advancePoolFill({
860
+ binding: authorized.binding,
861
+ request: ecdsaPoolFillStepRuntimeRequest(request),
862
+ onServerTiming: collectEcdsaPresignWorkerTiming.bind(void 0, workerTimings)
863
+ });
864
+ timing.proxy = performance.now() - proxyStartedAt;
865
+ return json(result, { status: thresholdEcdsaStatusCode(result) });
883
866
  }
884
867
  function poolFillMaterialActivation(request) {
885
868
  return "poolFill" in request ? request.poolFill.scope.material_activation : null;
@@ -1018,6 +1001,7 @@ async function authorizeEcdsaPoolFill(input) {
1018
1001
  const admitted = validated;
1019
1002
  const materialStartedAt = performance.now();
1020
1003
  const activeMaterial = await input.ctx.service.walletRegistration.resolveEcdsaMaterialActivation({
1004
+ source: { kind: "database" },
1021
1005
  walletId: String(session.walletId),
1022
1006
  materialActivation: routerAbMpcMaterialActivationRefToWire(admitted.materialActivation)
1023
1007
  });
@@ -1106,43 +1090,6 @@ function ecdsaPoolFillStepRuntimeRequest(request) {
1106
1090
  ...request.requestTag === void 0 ? {} : { requestTag: request.requestTag }
1107
1091
  };
1108
1092
  }
1109
- function resolvePresignPriorityTurn(resolve) {
1110
- setTimeout(resolve, 5);
1111
- }
1112
- function waitForPresignPriorityTurn() {
1113
- return new Promise(resolvePresignPriorityTurn);
1114
- }
1115
- var PresignPriorityGate = class {
1116
- constructor() {
1117
- this.foregroundInFlight = 0;
1118
- this.backgroundInFlight = 0;
1119
- }
1120
- async acquire(trafficClass) {
1121
- if (trafficClass === "foreground") {
1122
- this.foregroundInFlight += 1;
1123
- return this.createTicket("foreground");
1124
- }
1125
- while (!this.canRunBackgroundNow()) await waitForPresignPriorityTurn();
1126
- this.backgroundInFlight += 1;
1127
- return this.createTicket("background");
1128
- }
1129
- createTicket(trafficClass) {
1130
- let released = false;
1131
- return { release: () => {
1132
- if (released) return;
1133
- released = true;
1134
- if (trafficClass === "foreground") this.foregroundInFlight = Math.max(0, this.foregroundInFlight - 1);
1135
- else this.backgroundInFlight = Math.max(0, this.backgroundInFlight - 1);
1136
- } };
1137
- }
1138
- canRunBackgroundNow() {
1139
- return this.foregroundInFlight === 0 && this.backgroundInFlight === 0;
1140
- }
1141
- };
1142
- function resolvePresignTrafficClass(requestTag) {
1143
- return requestTag === "background_presign_pool_refill" ? "background" : "foreground";
1144
- }
1145
- const presignPriorityGate = new PresignPriorityGate();
1146
1093
  function strictEcdsaAuthorizationFailureStatus(failure) {
1147
1094
  switch (failure.code) {
1148
1095
  case "unauthorized": return 401;
@@ -1525,6 +1472,7 @@ async function authorizeStrictEcdsaExport(input) {
1525
1472
  scope: operation.normal_signing_scope
1526
1473
  })) return strictEcdsaExportFailure(403, "scope_mismatch", "ECDSA export operation scope does not match the request");
1527
1474
  const activeMaterial = await input.ctx.service.walletRegistration.resolveEcdsaMaterialActivation({
1475
+ source: { kind: "database" },
1528
1476
  walletId: operation.wallet_id,
1529
1477
  materialActivation: input.request.material_activation
1530
1478
  });
@@ -1,9 +1,10 @@
1
1
  import { parseMpcMaterialActivationRef, parseWalletId } from "../../../../shared-ts/src/utils/domainIds.js";
2
2
  import { EVM_ECDSA_MPC_OPERATION_KINDS, NEAR_ED25519_MPC_OPERATION_KINDS } from "../../../../shared-ts/src/authorization/capabilityKinds.js";
3
3
  import { isPlainObject } from "../../../../shared-ts/src/utils/validation.js";
4
+ import { routerAbMpcMaterialActivationRefToWire } from "../../../../shared-ts/src/utils/routerAbNormalSigningIdentity.js";
4
5
  import { WALLET_SESSION_FAILURE_CODES } from "../../../../shared-ts/src/utils/walletSessionFailure.js";
5
6
  import { json, readJson } from "../../../framework/http.js";
6
- import { walletSessionFailureStatus } from "../../../auth/walletSessionFailure.js";
7
+ import { walletSessionFailure, walletSessionFailureStatus } from "../../../auth/walletSessionFailure.js";
7
8
  import { validateRouterAbEcdsaDerivationWalletSessionInputs, validateRouterAbEd25519WalletSessionInputs } from "../../../auth/commonRouterUtils.js";
8
9
  //#region src/router/transport/fetch/routes/walletExecutionLanePreflight.ts
9
10
  const OWNER_WALLET_EXECUTION_LANE_PREFLIGHT_PATH = "/wallet/execution-lane/owner";
@@ -177,11 +178,13 @@ async function handleOwnerWalletExecutionLanePreflight(ctx) {
177
178
  };
178
179
  } else {
179
180
  const validated = await validateRouterAbEcdsaDerivationWalletSessionInputs({
181
+ materialActivation: routerAbMpcMaterialActivationRefToWire(request.expectedMaterialActivation),
180
182
  headers,
181
183
  authorizationSessions: ctx.service.authorizationSessions,
182
184
  operationKind: EVM_ECDSA_MPC_OPERATION_KINDS.signTransaction
183
185
  });
184
186
  if (!validated.ok) return validationFailure(validated);
187
+ if (validated.kind === "wallet_session_operation_credential_exhausted_candidate_v1") return validationFailure(walletSessionFailure("wallet_session_unavailable"));
185
188
  walletIdRaw = String(validated.admission.context.authorization.session.walletId);
186
189
  authorization = {
187
190
  kind: "wallet_auth_method",
@@ -1,4 +1,4 @@
1
- import { json } from "../../../framework/http.js";
1
+ import { json, jsonFailure } from "../../../framework/http.js";
2
2
  import { extractBearerCredential } from "../../../auth/routerApiKeyAuth.js";
3
3
  //#region src/router/transport/fetch/routes/webauthnAuthenticators.ts
4
4
  async function handleWebAuthnAuthenticators(ctx) {
@@ -6,22 +6,14 @@ async function handleWebAuthnAuthenticators(ctx) {
6
6
  if (ctx.pathname !== "/webauthn/authenticators") return null;
7
7
  try {
8
8
  const token = extractBearerCredential(ctx.request.headers);
9
- if (!token) return json({
10
- ok: false,
11
- code: "unauthorized",
12
- message: "No valid Wallet Session"
13
- }, { status: 401 });
9
+ if (!token) return jsonFailure(401, "unauthorized", "No valid Wallet Session");
14
10
  const nowMs = Date.now();
15
11
  const exact = await ctx.service.authorizationSessions.readWalletSessionAuthorizationV2ByOperationCredential({
16
12
  tenantId: ctx.service.authorizationSessions.tenantId,
17
13
  token,
18
14
  nowMs
19
15
  });
20
- if (!exact) return json({
21
- ok: false,
22
- code: "unauthorized",
23
- message: "No valid Wallet Session"
24
- }, { status: 401 });
16
+ if (!exact) return jsonFailure(401, "unauthorized", "No valid Wallet Session");
25
17
  const rpIdFromQuery = String(ctx.url.searchParams.get("rpId") || ctx.url.searchParams.get("rp_id") || "").trim();
26
18
  const result = await ctx.service.webAuthn.listWebAuthnAuthenticatorsForUser({
27
19
  userId: String(exact.authorization.session.walletId),
@@ -30,11 +22,7 @@ async function handleWebAuthnAuthenticators(ctx) {
30
22
  if (!result.ok) return json(result, { status: result.code === "not_supported" ? 501 : result.code === "invalid_args" ? 400 : 500 });
31
23
  return json(result, { status: 200 });
32
24
  } catch (e) {
33
- return json({
34
- ok: false,
35
- code: "internal",
36
- message: e?.message || "Internal error"
37
- }, { status: 500 });
25
+ return jsonFailure(500, "internal", e?.message || "Internal error");
38
26
  }
39
27
  }
40
28
  //#endregion