@seams/wallet-server 0.8.0 → 0.9.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 (369) hide show
  1. package/THIRD_PARTY_NOTICES.md +7 -1
  2. package/artifact-manifest.json +196 -41
  3. package/cloudflare-router-ab/build/deriver-a/build-stamp.json +1 -1
  4. package/cloudflare-router-ab/build/deriver-a/index.js +2 -2
  5. package/cloudflare-router-ab/build/deriver-a/index_bg.wasm +0 -0
  6. package/cloudflare-router-ab/build/deriver-b/build-stamp.json +1 -1
  7. package/cloudflare-router-ab/build/deriver-b/index.js +2 -2
  8. package/cloudflare-router-ab/build/deriver-b/index_bg.wasm +0 -0
  9. package/cloudflare-router-ab/build/local-tools/darwin-arm64/router_ab_local_init +0 -0
  10. package/cloudflare-router-ab/build/local-tools/darwin-x64/router_ab_local_init +0 -0
  11. package/cloudflare-router-ab/build/local-tools/linux-x64/router_ab_local_init +0 -0
  12. package/cloudflare-router-ab/build/router/build-stamp.json +1 -1
  13. package/cloudflare-router-ab/build/router/index.js +2 -2
  14. package/cloudflare-router-ab/build/router/index_bg.wasm +0 -0
  15. package/cloudflare-router-ab/build/signing-worker/build-stamp.json +1 -1
  16. package/cloudflare-router-ab/build/signing-worker/index.js +2 -2
  17. package/cloudflare-router-ab/build/signing-worker/index_bg.wasm +0 -0
  18. package/cloudflare-router-ab/build/tenant-root-control-plane/build-stamp.json +1 -1
  19. package/cloudflare-router-ab/build/tenant-root-control-plane/index.js +2 -2
  20. package/cloudflare-router-ab/build/tenant-root-control-plane/index_bg.wasm +0 -0
  21. package/cloudflare-router-ab/migrations/deriver-a/0019_wallet_object_addresses.sql +10 -0
  22. package/cloudflare-router-ab/migrations/deriver-b/0019_wallet_object_addresses.sql +10 -0
  23. package/cloudflare-router-ab/scripts/prepare-local-runtime-config.mjs +3 -117
  24. package/cloudflare-router-ab/wrangler.deriver-a.toml +0 -8
  25. package/cloudflare-router-ab/wrangler.deriver-b.toml +24 -8
  26. package/cloudflare-router-ab/wrangler.router.toml +0 -2
  27. package/cloudflare-router-ab/wrangler.signing-worker.toml +29 -0
  28. package/dist/esm/authorization/domain.js +3 -2
  29. package/dist/esm/authorization/ed25519WalletSessionAdmission.js +0 -0
  30. package/dist/esm/authorization/service.js +64 -36
  31. package/dist/esm/cloud-host.js +24 -19
  32. package/dist/esm/core/EmailOtpRecords.js +29 -6
  33. package/dist/esm/core/ThresholdService/routerAb/ecdsaDerivationPoolFillHandlers.js +2 -0
  34. package/dist/esm/core/ThresholdService/routerAb/ecdsaDerivationPresignBridge.js +10 -0
  35. package/dist/esm/core/ThresholdService/routerAb/internalServiceHttp.js +1 -0
  36. package/dist/esm/core/ThresholdService/validation.js +2 -2
  37. package/dist/esm/core/authService/nearPrivateKeySigning.js +1 -1
  38. package/dist/esm/core/authService/webauthn.js +1 -1
  39. package/dist/esm/core/d1Ed25519SignerRead.js +55 -0
  40. package/dist/esm/core/d1WalletStore.js +14 -11
  41. package/dist/esm/core/deviceLinking/linkedDeviceEmailOtpGrant.js +2 -2
  42. package/dist/esm/core/deviceLinking/linkedDeviceManagement.js +1 -1
  43. package/dist/esm/core/deviceLinking/linkedDeviceSessionRecord.js +2 -2
  44. package/dist/esm/core/emailOtpD1Statements.js +1 -0
  45. package/dist/esm/core/nearRelayerAccountProvisioning.js +1 -1
  46. package/dist/esm/core/routerAbSigning/RouterAbEcdsaPresignRuntime.js +4 -0
  47. package/dist/esm/core/signingLanes/WalletExecutionLaneProjection.js +1 -1
  48. package/dist/esm/core/signingMaterial/ordinaryInactiveSignerMaterialReservation.js +1 -0
  49. package/dist/esm/hosted-wallet-gateway.js +93 -10
  50. package/dist/esm/localHostedWalletGatewayHandler.js +12 -9
  51. package/dist/esm/localIntendedYaoSigningFault.js +2 -30
  52. package/dist/esm/localRegistrationSetupAuthority.js +8 -1
  53. package/dist/esm/router/auth/commonRouterUtils.js +17 -10
  54. package/dist/esm/router/auth/routerApiCredentialAuth.js +26 -7
  55. package/dist/esm/router/auth/walletRegistrationContext.js +49 -0
  56. package/dist/esm/router/auth/webAuthnCredentialCodecs.js +1 -1
  57. package/dist/esm/router/cloudflare/d1/auth/d1AuthorizationAssembly.js +4 -3
  58. package/dist/esm/router/cloudflare/d1/auth/d1AuthorizedOperationRouteService.js +2 -0
  59. package/dist/esm/router/cloudflare/d1/auth/d1EmailOtpRouteService.js +25 -0
  60. package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthConfig.js +14 -6
  61. package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthService.js +44 -40
  62. package/dist/esm/router/cloudflare/d1/auth/walletSessionCredentialReaders.js +17 -1
  63. package/dist/esm/router/cloudflare/d1/authorization/authorizedOperationStatements.js +35 -5
  64. package/dist/esm/router/cloudflare/d1/authorization/d1AuthorizationStore.js +258 -99
  65. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceAuthorityInstallService.js +31 -4
  66. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceOwnerAuthorizationProvider.js +1 -1
  67. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceRequestProofNonceStore.js +1 -1
  68. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionRecords.js +1 -1
  69. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetCredentialProvider.js +1 -1
  70. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetPlanner.js +1 -1
  71. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceVerifiedLinkBuilder.js +1 -1
  72. package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoLifecycleDecisionStore.js +11 -2
  73. package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoProductRegistrationPartitionedStateStore.js +100 -10
  74. package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoStateWriteFence.js +92 -0
  75. package/dist/esm/router/cloudflare/d1/ed25519Yao/d1WalletCeremonyActivity.js +77 -0
  76. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeIssuer.js +14 -8
  77. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeStore.js +14 -8
  78. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeVerifier.js +3 -1
  79. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRateLimitStore.js +58 -38
  80. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRecords.js +27 -20
  81. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRecoveryService.js +1 -0
  82. package/dist/esm/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpSessionResolver.js +1 -0
  83. package/dist/esm/router/cloudflare/d1/oidc/d1OidcBoundary.js +1 -1
  84. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletCustodyCommitStore.js +18 -7
  85. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyRecordStore.js +75 -14
  86. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyRecords.js +1 -1
  87. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyStore.js +49 -29
  88. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationSessionTransaction.js +28 -0
  89. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationSetupSupport.js +11 -1
  90. package/dist/esm/router/cloudflare/d1/registration/d1WalletExecutionAuthority.js +168 -0
  91. package/dist/esm/router/cloudflare/d1/registration/d1WalletOperationStore.js +53 -0
  92. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationCommitStore.js +83 -42
  93. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationInitialSession.js +33 -0
  94. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationPreparation.js +16 -0
  95. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationRead.js +58 -0
  96. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationService.js +439 -500
  97. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationSetup.js +1 -1
  98. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationSetupExecution.js +104 -90
  99. package/dist/esm/router/cloudflare/d1/registration/walletRegistrationEstablishedSessionIssuer.js +78 -44
  100. package/dist/esm/router/cloudflare/d1/registration/walletRegistrationSessionCommitReceipt.js +11 -35
  101. package/dist/esm/router/cloudflare/d1/signingAdmission/d1RouterAbNormalSigningAdmissionStore.js +98 -39
  102. package/dist/esm/router/cloudflare/d1/versionedJson/d1VersionedJsonRecordStore.js +12 -9
  103. package/dist/esm/router/cloudflare/d1/wallet/authorizationSnapshotLayout.js +168 -0
  104. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAddSignerFinalizeRecord.js +1 -1
  105. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAddSignerService.js +15 -6
  106. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthMethodService.js +3 -40
  107. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorityStore.js +54 -1
  108. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorizationCleanup.js +157 -0
  109. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorizationFreeze.js +56 -0
  110. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorizationHistory.js +238 -0
  111. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorizationIntake.js +287 -0
  112. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorizationSnapshot.js +295 -0
  113. package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationApprovals.js +140 -0
  114. package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationChallenges.js +170 -0
  115. package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationEmailOtp.js +60 -0
  116. package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationOwner.js +33 -0
  117. package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationOwnerRequest.js +74 -0
  118. package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationPasskey.js +77 -0
  119. package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationReadAccess.js +37 -0
  120. package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationSessions.js +97 -0
  121. package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationWriteBlock.js +133 -0
  122. package/dist/esm/router/cloudflare/d1/walletObjectAddresses.js +47 -0
  123. package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnAuthService.js +1 -1
  124. package/dist/esm/router/cloudflare/runtime/routerAbServiceBindings.js +32 -1
  125. package/dist/esm/router/cloudflare/runtime/staticWalletConsoleBinding.js +20 -8
  126. package/dist/esm/router/cloudflare/runtime/walletAuthorizationRelocationRoutes.js +488 -0
  127. package/dist/esm/router/cloudflare/runtime/walletConsoleOps.js +1 -1
  128. package/dist/esm/router/cloudflare/runtime/walletConsoleOpsClient.js +26 -6
  129. package/dist/esm/router/cloudflare/runtime/walletControlOps.js +3 -0
  130. package/dist/esm/router/cloudflare/runtime/walletGateway.js +1 -1
  131. package/dist/esm/router/cloudflare/runtime/walletObjectAddresses.js +105 -0
  132. package/dist/esm/router/cloudflare/runtime/walletPlacementRoutes.js +339 -0
  133. package/dist/esm/router/cloudflare/runtime/walletRelocationDeriver.js +244 -0
  134. package/dist/esm/router/cloudflare/runtime/walletRelocationEcdsa.js +212 -0
  135. package/dist/esm/router/cloudflare/runtime/walletRelocationEd25519.js +172 -0
  136. package/dist/esm/router/cloudflare/runtime/walletRelocationOps.js +183 -0
  137. package/dist/esm/router/cloudflare/runtime/walletRelocationPresign.js +185 -0
  138. package/dist/esm/router/cloudflare/runtime/walletRelocationSource.js +221 -0
  139. package/dist/esm/router/cloudflare/signingLanes/cloudflareOrdinaryInactiveSignerMaterialReservation.js +30 -8
  140. package/dist/esm/router/cloudflare-adaptor.js +8 -8
  141. package/dist/esm/router/cloudflare.js +34115 -32240
  142. package/dist/esm/router/domains/ecdsa/routerAbEcdsaStrictRegistration.js +35 -9
  143. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoCapabilityCommit.js +42 -0
  144. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.js +32 -6
  145. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitionedStateStore.js +61 -1
  146. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPersistence.js +70 -3
  147. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRuntime.js +59 -87
  148. package/dist/esm/router/domains/ed25519Yao/export/routerAbEd25519YaoExport.js +52 -22
  149. package/dist/esm/router/domains/ed25519Yao/export/routerAbEd25519YaoExportRequestScopedCloudflare.js +10 -7
  150. package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecovery.js +108 -78
  151. package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryRequestScopedCloudflare.js +19 -5
  152. package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryWalletSessionAuthorization.js +71 -22
  153. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoHttpRegistrationBackend.js +37 -25
  154. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistration.js +3 -3
  155. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationExecutionRecord.js +2 -1
  156. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationIntentAuthorization.js +24 -3
  157. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationRequestScopedCloudflare.js +4 -3
  158. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.js +20 -7
  159. package/dist/esm/router/domains/ed25519Yao/routerAbEd25519YaoGatewayEnvelope.js +7 -1
  160. package/dist/esm/router/domains/emailOtp/emailOtpRouteHandlers.js +2 -2
  161. package/dist/esm/router/domains/passkeyCustody/passkeyCustodyEnvelopeRetrieval.js +1 -1
  162. package/dist/esm/router/domains/passkeyCustody/registrationCustodyOutcome.js +34 -18
  163. package/dist/esm/router/domains/passkeyCustody/walletCustodyRegistrationAdmission.js +2 -2
  164. package/dist/esm/router/domains/passkeyCustody/walletCustodyRegistrationCommit.js +16 -6
  165. package/dist/esm/router/domains/signingOperations/authorizedOperationWire.js +73 -0
  166. package/dist/esm/router/domains/signingOperations/ecdsaSigningResponse.js +31 -0
  167. package/dist/esm/router/domains/signingOperations/ed25519AuthorizedOperationReceipt.js +1 -1
  168. package/dist/esm/router/domains/signingOperations/routerAbEcdsaDerivationNormalSigningRoute.js +2 -1
  169. package/dist/esm/router/domains/signingOperations/routerAbEd25519NormalSigningRoute.js +31 -121
  170. package/dist/esm/router/domains/signingOperations/routerAbNormalSigningAdmission.js +2 -93
  171. package/dist/esm/router/domains/signingOperations/routerAbPrivateSigningWorker.js +1 -1
  172. package/dist/esm/router/domains/signingOperations/signingPrepareSession.js +33 -0
  173. package/dist/esm/router/domains/walletRegistration/registrationSessionSeal.js +121 -0
  174. package/dist/esm/router/domains/walletRegistration/walletRegistrationReservation.js +4 -4
  175. package/dist/esm/router/domains/walletRegistration/walletRegistrationRoutes.js +46 -157
  176. package/dist/esm/router/domains/walletRegistration/walletRegistrationSetupPayload.js +1 -1
  177. package/dist/esm/router/express.js +764 -894
  178. package/dist/esm/router/framework/http.js +2 -1
  179. package/dist/esm/router/transport/fetch/createFetchRouter.js +2 -2
  180. package/dist/esm/router/transport/fetch/routes/auth.js +1 -1
  181. package/dist/esm/router/transport/fetch/routes/deviceLinking.js +3 -3
  182. package/dist/esm/router/transport/fetch/routes/deviceLinkingOwnerAuthorization.js +2 -2
  183. package/dist/esm/router/transport/fetch/routes/ed25519AuthorizedOperationRevalidation.js +65 -0
  184. package/dist/esm/router/transport/fetch/routes/normalSigningRouterProxy.js +13 -3
  185. package/dist/esm/router/transport/fetch/routes/passkeyCustody.js +3 -3
  186. package/dist/esm/router/transport/fetch/routes/sessions.js +3 -2
  187. package/dist/esm/router/transport/fetch/routes/thresholdEcdsa.js +67 -130
  188. package/dist/esm/router/transport/fetch/routes/thresholdEd25519.js +76 -212
  189. package/dist/esm/router/transport/fetch/routes/walletExecutionLanePreflight.js +18 -41
  190. package/dist/esm/router/transport/fetch/routes/walletRegistration.js +6 -5
  191. package/dist/esm/router/transport/fetch/routes/webauthnAuthenticators.js +1 -1
  192. package/dist/esm/shared-ts/src/authorization/index.js +1 -1
  193. package/dist/esm/shared-ts/src/authorization/walletAuthority.js +2 -2
  194. package/dist/esm/shared-ts/src/device-linking/activeWalletSession.js +12 -2
  195. package/dist/esm/shared-ts/src/device-linking/digests.js +1 -1
  196. package/dist/esm/shared-ts/src/device-linking/ed25519ExportRoot.js +1 -1
  197. package/dist/esm/shared-ts/src/device-linking/index.js +1 -1
  198. package/dist/esm/shared-ts/src/device-linking/parsers.js +1 -1
  199. package/dist/esm/shared-ts/src/device-linking/sourceContribution.js +1 -1
  200. package/dist/esm/shared-ts/src/device-linking/wireFields.js +1 -1
  201. package/dist/esm/shared-ts/src/near/nearClient.js +1 -1
  202. package/dist/esm/shared-ts/src/signing-lanes/ownerContinuity.js +2 -2
  203. package/dist/esm/shared-ts/src/utils/ecdsaServerTiming.js +6 -1
  204. package/dist/esm/shared-ts/src/utils/emailOtpDomain.js +4 -2
  205. package/dist/esm/shared-ts/src/utils/routerAbEcdsaDerivation.js +1 -1
  206. package/dist/esm/shared-ts/src/utils/routerAbPublicKeyset.js +0 -27
  207. package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryEcdsaPossession.js +1 -1
  208. package/dist/esm/threshold/session/signingSessionSeal/options.js +1 -1
  209. package/dist/esm/wasm/near_signer/pkg/wasm_signer_worker_bg.wasm +0 -0
  210. package/dist/types/shared-ts/src/device-linking/activeWalletSession.d.ts +2 -1
  211. package/dist/types/shared-ts/src/device-linking/contracts.d.ts +10 -0
  212. package/dist/types/shared-ts/src/threshold/ed25519OperationFingerprint.d.ts +2 -1
  213. package/dist/types/shared-ts/src/utils/emailOtpDomain.d.ts +3 -1
  214. package/dist/types/shared-ts/src/utils/routerAbPublicKeyset.d.ts +0 -9
  215. package/dist/types/shared-ts/src/utils/walletManagementProtocol.d.ts +1 -1
  216. package/dist/types/wallet-server/src/authorization/domain.d.ts +17 -1
  217. package/dist/types/wallet-server/src/authorization/ecdsaWalletSessionAdmission.d.ts +1 -0
  218. package/dist/types/wallet-server/src/authorization/ed25519WalletSessionAdmission.d.ts +35 -0
  219. package/dist/types/wallet-server/src/authorization/ed25519WalletSessionAdmission.typecheck.d.ts +2 -0
  220. package/dist/types/wallet-server/src/authorization/service.d.ts +43 -5
  221. package/dist/types/wallet-server/src/authorization/sessionRouting.d.ts +2 -0
  222. package/dist/types/wallet-server/src/cloud-host.d.ts +7 -3
  223. package/dist/types/wallet-server/src/core/EmailOtpRecords.d.ts +2 -1
  224. package/dist/types/wallet-server/src/core/EmailOtpStores.d.ts +19 -5
  225. package/dist/types/wallet-server/src/core/ThresholdService/routerAb/ecdsaDerivationPoolFillHandlers.d.ts +1 -0
  226. package/dist/types/wallet-server/src/core/ThresholdService/routerAb/ecdsaDerivationPresignBridge.d.ts +6 -0
  227. package/dist/types/wallet-server/src/core/ThresholdService/routerAb/internalServiceHttp.d.ts +1 -0
  228. package/dist/types/wallet-server/src/core/d1Ed25519SignerRead.d.ts +17 -0
  229. package/dist/types/wallet-server/src/core/d1WalletStore.d.ts +6 -0
  230. package/dist/types/wallet-server/src/core/emailOtpD1Statements.d.ts +1 -0
  231. package/dist/types/wallet-server/src/core/routerAbSigning/RouterAbEcdsaPresignRuntime.d.ts +5 -1
  232. package/dist/types/wallet-server/src/core/signingMaterial/ordinaryInactiveSignerMaterialReservation.d.ts +1 -0
  233. package/dist/types/wallet-server/src/core/threeRouteRegistrationContracts.d.ts +14 -48
  234. package/dist/types/wallet-server/src/hosted-wallet-gateway.d.ts +4 -3
  235. package/dist/types/wallet-server/src/localIntendedYaoSigningFault.d.ts +1 -16
  236. package/dist/types/wallet-server/src/localRegistrationSetupAuthority.d.ts +1 -1
  237. package/dist/types/wallet-server/src/router/auth/commonRouterUtils.d.ts +7 -1
  238. package/dist/types/wallet-server/src/router/auth/routerApiCredentialAuth.d.ts +11 -3
  239. package/dist/types/wallet-server/src/router/auth/walletRegistrationContext.d.ts +8 -0
  240. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1AuthorizationAssembly.d.ts +1 -1
  241. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1EmailOtpRouteService.d.ts +16 -0
  242. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthConfig.d.ts +7 -4
  243. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthService.d.ts +4 -1
  244. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/walletSessionCredentialReaders.d.ts +7 -1
  245. package/dist/types/wallet-server/src/router/cloudflare/d1/authorization/d1AuthorizationStore.d.ts +32 -1
  246. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceAuthorityInstallService.d.ts +2 -0
  247. package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoLifecycleDecisionStore.d.ts +3 -1
  248. package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoProductRegistrationPartitionedStateStore.d.ts +1 -0
  249. package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoStateWriteFence.d.ts +8 -0
  250. package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1WalletCeremonyActivity.d.ts +15 -0
  251. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeIssuer.d.ts +6 -1
  252. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeStore.d.ts +1 -0
  253. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeVerifier.d.ts +4 -1
  254. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpCounters.typecheck.d.ts +2 -0
  255. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRateLimitStore.d.ts +6 -29
  256. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRecords.d.ts +21 -7
  257. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1WalletCustodyCommitStore.d.ts +17 -1
  258. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyRecordStore.d.ts +32 -7
  259. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyStore.d.ts +16 -7
  260. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationSessionTransaction.d.ts +13 -0
  261. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationSetupSupport.d.ts +7 -0
  262. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletExecutionAuthority.d.ts +41 -0
  263. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletOperationStore.d.ts +28 -0
  264. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationCommitStore.d.ts +6 -9
  265. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationInitialSession.d.ts +17 -0
  266. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationPreparation.d.ts +12 -0
  267. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationRead.d.ts +43 -0
  268. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationService.d.ts +24 -45
  269. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationSetupExecution.d.ts +9 -4
  270. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/walletRegistrationEstablishedSessionIssuer.d.ts +42 -14
  271. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/walletRegistrationSessionCommitReceipt.d.ts +5 -4
  272. package/dist/types/wallet-server/src/router/cloudflare/d1/signingAdmission/d1RouterAbNormalSigningAdmissionStore.d.ts +24 -1
  273. package/dist/types/wallet-server/src/router/cloudflare/d1/versionedJson/d1VersionedJsonRecordStore.d.ts +10 -4
  274. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/authorizationSnapshotLayout.d.ts +21 -0
  275. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAddSignerService.d.ts +3 -0
  276. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthMethodService.d.ts +3 -7
  277. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorityStore.d.ts +8 -0
  278. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorizationCleanup.d.ts +20 -0
  279. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorizationFreeze.d.ts +12 -0
  280. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorizationHistory.d.ts +20 -0
  281. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorizationIntake.d.ts +29 -0
  282. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorizationSnapshot.d.ts +31 -0
  283. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationApprovals.d.ts +49 -0
  284. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationChallenges.d.ts +47 -0
  285. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationEmailOtp.d.ts +25 -0
  286. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationOwner.d.ts +88 -0
  287. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationOwnerRequest.d.ts +37 -0
  288. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationPasskey.d.ts +12 -0
  289. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationReadAccess.d.ts +18 -0
  290. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationSessions.d.ts +23 -0
  291. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationWriteBlock.d.ts +16 -0
  292. package/dist/types/wallet-server/src/router/cloudflare/d1/walletObjectAddresses.d.ts +14 -0
  293. package/dist/types/wallet-server/src/router/cloudflare/runtime/routerAbServiceBindings.d.ts +13 -0
  294. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletAuthorizationRelocationRoutes.d.ts +21 -0
  295. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletConsoleOps.d.ts +1 -1
  296. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletConsoleOpsClient.d.ts +3 -3
  297. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletControlOps.d.ts +2 -1
  298. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletGateway.d.ts +3 -1
  299. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletObjectAddresses.d.ts +45 -0
  300. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletPlacementRoutes.d.ts +30 -0
  301. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRelocationDeriver.d.ts +11 -0
  302. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRelocationEcdsa.d.ts +7 -0
  303. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRelocationEd25519.d.ts +7 -0
  304. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRelocationOps.d.ts +11 -0
  305. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRelocationPresign.d.ts +7 -0
  306. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRelocationSource.d.ts +26 -0
  307. package/dist/types/wallet-server/src/router/cloudflare/signingLanes/cloudflareOrdinaryInactiveSignerMaterialReservation.d.ts +5 -0
  308. package/dist/types/wallet-server/src/router/domains/ecdsa/routerAbEcdsaStrictRegistration.d.ts +3 -0
  309. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoCapabilityCommit.d.ts +7 -0
  310. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.d.ts +41 -7
  311. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitionedStateStore.d.ts +33 -2
  312. package/dist/types/wallet-server/src/router/domains/ed25519Yao/export/routerAbEd25519YaoExport.d.ts +12 -6
  313. package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecovery.d.ts +17 -9
  314. package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryWalletSessionAuthorization.d.ts +2 -0
  315. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoHttpRegistrationBackend.d.ts +13 -14
  316. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistration.d.ts +7 -3
  317. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationExecutionRecord.d.ts +1 -0
  318. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationIntentAuthorization.d.ts +6 -1
  319. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.d.ts +11 -0
  320. package/dist/types/wallet-server/src/router/domains/ed25519Yao/routerAbEd25519YaoGatewayEnvelope.d.ts +12 -3
  321. package/dist/types/wallet-server/src/router/domains/passkeyCustody/registrationCustodyOutcome.d.ts +10 -6
  322. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletCustodyRegistrationAdmission.d.ts +10 -3
  323. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletCustodyRegistrationCommit.d.ts +12 -5
  324. package/dist/types/wallet-server/src/router/domains/signingOperations/authorizedOperationWire.d.ts +97 -0
  325. package/dist/types/wallet-server/src/router/domains/signingOperations/ecdsaSigningResponse.d.ts +13 -0
  326. package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbNormalSigningAdmission.d.ts +9 -206
  327. package/dist/types/wallet-server/src/router/domains/signingOperations/signingPrepareSession.d.ts +23 -0
  328. package/dist/types/wallet-server/src/router/domains/walletRegistration/registrationSessionSeal.d.ts +36 -0
  329. package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationInputs.d.ts +7 -7
  330. package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationReservation.d.ts +80 -6
  331. package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationRoutes.d.ts +15 -5
  332. package/dist/types/wallet-server/src/router/framework/apiCredentialPorts.d.ts +24 -0
  333. package/dist/types/wallet-server/src/router/framework/authServicePort.d.ts +21 -7
  334. package/dist/types/wallet-server/src/router/framework/routerApi.d.ts +3 -12
  335. package/dist/types/wallet-server/src/router/transport/fetch/routes/ed25519AuthorizedOperationRevalidation.d.ts +37 -0
  336. package/dist/types/wallet-server/src/router/transport/fetch/routes/thresholdEcdsa.d.ts +1 -17
  337. package/dist/types/wallet-server/src/storage/tenantRoute.d.ts +1 -1
  338. package/migrations/d1-signer/0049_wallet_relocation_challenges.sql +16 -0
  339. package/migrations/d1-signer/0050_wallet_relocation_approvals.sql +14 -0
  340. package/migrations/d1-signer/0051_wallet_relocation_email_otp.sql +92 -0
  341. package/migrations/d1-signer/0052_wallet_relocation_session_fences.sql +91 -0
  342. package/migrations/d1-signer/0053_wallet_hosted_history_import.sql +164 -0
  343. package/migrations/d1-signer/0054_wallet_authorization_freeze.sql +318 -0
  344. package/migrations/d1-signer/0055_wallet_authorization_snapshot.sql +120 -0
  345. package/migrations/d1-signer/0056_wallet_authorization_history_import.sql +424 -0
  346. package/migrations/d1-signer/0057_wallet_authorization_intake.sql +44 -0
  347. package/migrations/d1-signer/0058_wallet_ceremony_activity.sql +59 -0
  348. package/migrations/d1-signer/0059_wallet_authorization_activation.sql +45 -0
  349. package/migrations/d1-signer/0060_wallet_authorization_cleanup.sql +153 -0
  350. package/migrations/d1-signer/0061_wallet_session_operation_settlement.sql +28 -0
  351. package/migrations/d1-signer/0062_wallet_step_up_operation_settlement.sql +204 -0
  352. package/migrations/d1-signer/0063_wallet_operation_history_transfer.sql +466 -0
  353. package/migrations/d1-signer/0064_wallet_execution_generations.sql +93 -0
  354. package/migrations/d1-signer/0065_wallet_operation_execution_generation.sql +37 -0
  355. package/migrations/d1-signer/0066_regional_deployment_admission.sql +59 -0
  356. package/migrations/d1-signer/0067_registration_completion_decision.sql +12 -0
  357. package/migrations/d1-signer/0068_registration_cancellation_write_fence.sql +24 -0
  358. package/migrations/d1-signer/0069_cancelled_registration_session_fence.sql +11 -0
  359. package/migrations/d1-signer/0070_wallet_passkey_relocation.sql +369 -0
  360. package/migrations/d1-signer/0071_regional_wallet_otp_counters.sql +98 -0
  361. package/migrations/d1-signer/0072_linked_device_relocation_history.sql +899 -0
  362. package/migrations/d1-signer/0073_wallet_recovery_relocation.sql +86 -0
  363. package/migrations/d1-signer/0074_email_otp_relocation.sql +158 -0
  364. package/migrations/d1-signer/0075_wallet_authorization_return.sql +107 -0
  365. package/migrations/d1-signer/0076_wallet_relocation_write_block.sql +406 -0
  366. package/migrations/d1-signer/0077_wallet_object_addresses.sql +24 -0
  367. package/package.json +1 -1
  368. package/src/README.md +23 -1
  369. package/cloudflare-router-ab/scripts/local-key-material.mjs +0 -29
@@ -0,0 +1,121 @@
1
+ import { isPlainObject } from "../../../shared-ts/src/utils/validation.js";
2
+ //#region src/router/domains/walletRegistration/registrationSessionSeal.ts
3
+ /** Holds one request's computation until registration can publish its response. */
4
+ var RegistrationPreparedSessionSeal = class {
5
+ constructor(request, service) {
6
+ this.request = request;
7
+ this.service = service;
8
+ this.prepared = null;
9
+ }
10
+ async prepare(session) {
11
+ await this.finish(session);
12
+ }
13
+ async finish(session) {
14
+ const tokens = session.tokens;
15
+ const ed25519 = tokens.kind === "near_ed25519" || tokens.kind === "near_ed25519_and_evm_family_ecdsa" ? tokens.ed25519 : null;
16
+ if (!ed25519 || String(ed25519.thresholdSessionId) !== this.request.thresholdSessionId) return {
17
+ ok: false,
18
+ code: "invalid_session_seal",
19
+ message: "Prepared seal does not match the established Ed25519 session"
20
+ };
21
+ if (this.prepared === null) this.prepared = {
22
+ walletId: String(session.walletId),
23
+ walletSessionId: String(session.walletSessionId),
24
+ expiresAtMs: session.expiresAtMs,
25
+ result: applyRegistrationSessionSeal(this.service, this.request, session)
26
+ };
27
+ if (this.prepared.walletId !== String(session.walletId) || this.prepared.walletSessionId !== String(session.walletSessionId) || this.prepared.expiresAtMs !== session.expiresAtMs) return {
28
+ ok: false,
29
+ code: "invalid_session_seal",
30
+ message: "Prepared seal does not match the committed Wallet Session"
31
+ };
32
+ const sealed = await this.prepared.result;
33
+ if (!sealed.ok) return sealed;
34
+ const keyVersion = String(sealed.keyVersion || "").trim();
35
+ if (!keyVersion) return {
36
+ ok: false,
37
+ code: "invalid_session_seal",
38
+ message: "Signing-session seal response is missing its key version"
39
+ };
40
+ const expiresAtMs = Math.min(sealed.expiresAtMs ?? session.expiresAtMs, session.expiresAtMs);
41
+ if (expiresAtMs <= Date.now()) return {
42
+ ok: false,
43
+ code: "expired",
44
+ message: "threshold session expired"
45
+ };
46
+ return {
47
+ ok: true,
48
+ value: {
49
+ ciphertext: sealed.ciphertext,
50
+ keyVersion,
51
+ expiresAtMs,
52
+ remainingUses: session.remainingUses
53
+ }
54
+ };
55
+ }
56
+ };
57
+ async function applyRegistrationSessionSeal(service, request, session) {
58
+ if (!service) return {
59
+ ok: false,
60
+ code: "signing_session_seal_unavailable",
61
+ message: "Signing-session sealing is unavailable"
62
+ };
63
+ try {
64
+ return await service.applyServerSeal(request, {
65
+ userId: String(session.walletId),
66
+ session: {
67
+ kind: "exact_wallet_session_operation_credential",
68
+ curve: "ed25519",
69
+ thresholdSessionId: request.thresholdSessionId,
70
+ userId: String(session.walletId),
71
+ expiresAtMs: session.expiresAtMs
72
+ }
73
+ });
74
+ } catch {
75
+ return {
76
+ ok: false,
77
+ code: "signing_session_seal_unavailable",
78
+ message: "Signing-session sealing failed"
79
+ };
80
+ }
81
+ }
82
+ function parseRegistrationPreparedSessionSeal(raw, service) {
83
+ if (raw === void 0) return {
84
+ ok: true,
85
+ value: null
86
+ };
87
+ if (!isPlainObject(raw)) return {
88
+ ok: false,
89
+ code: "invalid_body",
90
+ message: "sessionSeal must be an object"
91
+ };
92
+ for (const field of Object.keys(raw)) if (![
93
+ "thresholdSessionId",
94
+ "ciphertext",
95
+ "keyVersion"
96
+ ].includes(field)) return {
97
+ ok: false,
98
+ code: "invalid_body",
99
+ message: "sessionSeal has unknown fields"
100
+ };
101
+ const thresholdSessionId = String(raw.thresholdSessionId || "").trim();
102
+ const ciphertext = String(raw.ciphertext || "").trim();
103
+ const keyVersion = String(raw.keyVersion || "").trim();
104
+ if (!thresholdSessionId || !ciphertext) return {
105
+ ok: false,
106
+ code: "invalid_body",
107
+ message: "sessionSeal thresholdSessionId and ciphertext are required"
108
+ };
109
+ return {
110
+ ok: true,
111
+ value: new RegistrationPreparedSessionSeal({
112
+ thresholdSessionId,
113
+ ciphertext,
114
+ ...keyVersion ? { keyVersion } : {}
115
+ }, service)
116
+ };
117
+ }
118
+ //#endregion
119
+ export { parseRegistrationPreparedSessionSeal };
120
+
121
+ //# sourceMappingURL=registrationSessionSeal.js.map
@@ -1,7 +1,7 @@
1
1
  import { parseWalletAuthMethodId, parseWalletAuthorityId, parseWalletId } from "../../../shared-ts/src/utils/domainIds.js";
2
2
  import { parseDeviceId } from "../../../shared-ts/src/authorization/capabilityKinds.js";
3
- import { alphabetizeStringify, sha256HexUtf8 } from "../../../shared-ts/src/utils/digests.js";
4
3
  import { isPlainObject, requireCanonicalString } from "../../../shared-ts/src/utils/validation.js";
4
+ import { alphabetizeStringify, sha256HexUtf8 } from "../../../shared-ts/src/utils/digests.js";
5
5
  import { secureRandomBase64Url } from "../../../shared-ts/src/utils/secureRandomId.js";
6
6
  import { createServerAllocatedWalletId } from "../../../shared-ts/src/utils/registrationIds.js";
7
7
  //#region src/router/domains/walletRegistration/walletRegistrationReservation.ts
@@ -48,13 +48,13 @@ async function walletRegistrationSetupRequestDigest(namespace, input) {
48
48
  signerSelection: input.request.signerSelection
49
49
  }));
50
50
  }
51
- async function completeRegistrationReservation(authority, input) {
51
+ async function cancelRegistrationHome(authority, input) {
52
52
  if (!authority) return {
53
53
  ok: false,
54
54
  code: "registration_authority_unavailable",
55
55
  message: "Registration reservation authority is required"
56
56
  };
57
- return authority.complete(input);
57
+ return authority.cancel(input);
58
58
  }
59
59
  async function admitRegistrationReservationHome(authority, input) {
60
60
  if (!authority) return {
@@ -65,6 +65,6 @@ async function admitRegistrationReservationHome(authority, input) {
65
65
  return authority.admitHome(input);
66
66
  }
67
67
  //#endregion
68
- export { admitRegistrationReservationHome, completeRegistrationReservation, parseWalletRegistrationSetupReservation, proposeWalletRegistrationSetup, walletRegistrationSetupRequestDigest };
68
+ export { admitRegistrationReservationHome, cancelRegistrationHome, parseWalletRegistrationSetupReservation, proposeWalletRegistrationSetup, walletRegistrationSetupRequestDigest };
69
69
 
70
70
  //# sourceMappingURL=walletRegistrationReservation.js.map
@@ -1,10 +1,10 @@
1
1
  import { parseWalletAuthMethodId, parseWalletId, parseWebAuthnRpId } from "../../../shared-ts/src/utils/domainIds.js";
2
2
  import { EVM_ECDSA_MPC_OPERATION_KINDS, NEAR_ED25519_MPC_OPERATION_KINDS, parseWalletSessionId } from "../../../shared-ts/src/authorization/capabilityKinds.js";
3
+ import { isPlainObject } from "../../../shared-ts/src/utils/validation.js";
3
4
  import { base64UrlDecode } from "../../../shared-ts/src/utils/base64.js";
4
5
  import { parseDigestB64u } from "../../../shared-ts/src/utils/canonicalPrimitives.js";
5
6
  import { base58Encode } from "../../../shared-ts/src/utils/base58.js";
6
7
  import "../../../shared-ts/src/utils/encoders.js";
7
- import { isPlainObject } from "../../../shared-ts/src/utils/validation.js";
8
8
  import { ecdsaClientRootPublicKey33B64uFromString } from "../../../shared-ts/src/threshold/ecdsaDerivationRoleLocalBootstrap.js";
9
9
  import { normalizeRuntimePolicyScope } from "../../../shared-ts/src/threshold/signingRootScope.js";
10
10
  import { parseRouterAbEcdsaRegistrationActivationRequestV1, parseRouterAbEcdsaRegistrationRequestV1 } from "../../../shared-ts/src/utils/routerAbEcdsaDerivation.js";
@@ -13,20 +13,20 @@ import { parseHostedWalletSessionOperationCredentialToken, parsePrimaryWalletSes
13
13
  import { normalizeCorsOrigin } from "../../../core/SessionService.js";
14
14
  import { thresholdEcdsaChainTargetFromValue } from "../../../core/thresholdEcdsaChainTarget.js";
15
15
  import { walletIdFromString } from "../../../shared-ts/src/utils/registrationIds.js";
16
- import { parseRouterAbTraceContextV1 } from "../../../shared-ts/src/utils/routerAbTraceContext.js";
17
16
  import { parseRegistrationSetupOperationId } from "../../../shared-ts/src/utils/registrationSetupOperation.js";
18
17
  import { extractBearerCredential, extractRouterApiEnvironmentId } from "../../auth/routerApiKeyAuth.js";
19
- import { resolvePublishableKeyApiCredentialAuth } from "../../auth/routerApiCredentialAuth.js";
18
+ import { publishableKeyRoutePrincipal, resolvePublishableKeyApiCredentialAuth, resolveWalletRegistrationContext } from "../../auth/routerApiCredentialAuth.js";
20
19
  import { resolveActiveRuntimePolicyScopeForEnvironment, resolveWalletSessionAdministrationAdmission, resolveWalletSessionOperationCredentialAdmission, resolveWalletSessionOperationCredentialAdmissionFromContext } from "../../auth/commonRouterUtils.js";
21
20
  import { enforceRoutePolicy } from "../../framework/enforceRoutePolicy.js";
21
+ import { parseRegistrationPreparedSessionSeal } from "./registrationSessionSeal.js";
22
22
  import { routeError, routeJson } from "../../framework/routeResponses.js";
23
23
  import { parsePasskeyCustodyEnvelopeRecord } from "../../../shared-ts/src/passkey-custody/custodyEnvelope.js";
24
24
  import "../../../shared-ts/src/passkey-custody/index.js";
25
- import { verifyWalletRegistrationSetupClaims } from "./walletRegistrationSetupPayload.js";
26
25
  import { computeWalletEcdsaKeyFactsInventoryChallengeDigestB64u } from "../../../shared-ts/src/utils/ecdsaKeyFactsInventory.js";
27
26
  import { deriveImplicitNearAccountIdFromEd25519PublicKey, parseImplicitNearAccountId } from "../../../shared-ts/src/utils/near.js";
28
27
  import { normalizeRegistrationSignerPlan, registrationSignerSetSelectionFromPlan } from "../../../shared-ts/src/utils/registrationSignerPlan.js";
29
28
  import { addAuthMethodIntentGrantFromString, addSignerIntentGrantFromString, computeAddAuthMethodIntentDigestB64u, computeAddSignerIntentDigestB64u, normalizeAddAuthMethodIntentCaller } from "../../../shared-ts/src/utils/registrationIntent.js";
29
+ import { parseRouterAbTraceContextV1 } from "../../../shared-ts/src/utils/routerAbTraceContext.js";
30
30
  //#region src/router/domains/walletRegistration/walletRegistrationRoutes.ts
31
31
  function parseRegistrationTraceContext(headers) {
32
32
  const parsed = parseRouterAbTraceContextV1(headers["x-seams-trace-id"] ?? headers["X-Seams-Trace-Id"]);
@@ -1568,8 +1568,27 @@ async function handleRouterApiWalletRegistrationSetup(input) {
1568
1568
  if (!isPlainObject(input.body)) return routeError(400, "invalid_body", "JSON body required");
1569
1569
  const origin = normalizeCorsOrigin(input.origin);
1570
1570
  if (!origin) return routeError(403, "forbidden", "Origin header is required and must be a valid exact origin");
1571
- const publishableKeyAuth = input.services.publishableKeyAuth;
1572
- if (!publishableKeyAuth) return routeError(500, "route_auth_not_configured", "wallet registration setup requires publishable key auth on this server");
1571
+ const registrationContext = input.services.registrationContext;
1572
+ if (!registrationContext) return routeError(500, "route_auth_not_configured", "Wallet registration context is not configured");
1573
+ const request = parseWalletRegistrationSetupRequest(input.body);
1574
+ if (!request.ok) return routeError(400, request.code, request.message);
1575
+ const context = await resolveWalletRegistrationContext({
1576
+ registration: request.value,
1577
+ environmentId: extractRouterApiEnvironmentId(input.headers) || void 0,
1578
+ headers: input.headers,
1579
+ missingEnvironmentMessage: "Environment header is required for wallet registration setup",
1580
+ missingOriginMessage: "Origin header is required and must be a valid exact origin",
1581
+ missingPublishableKeyMessage: "Missing publishable key",
1582
+ origin,
1583
+ registrationContext,
1584
+ route: input.route,
1585
+ routeAuthNotConfiguredMessage: "Wallet registration setup requires API credential auth policy"
1586
+ });
1587
+ if (!context.ok) {
1588
+ if (context.status === 401) return routeError(401, "unauthorized", `${context.code}: ${context.message}`);
1589
+ if (context.status === 403) return routeError(403, "forbidden", `${context.code}: ${context.message}`);
1590
+ return routeError(context.status, "internal", `${context.code}: ${context.message}`);
1591
+ }
1573
1592
  const resolved = await enforceRoutePolicy({
1574
1593
  headers: input.headers,
1575
1594
  logger: input.logger,
@@ -1580,42 +1599,26 @@ async function handleRouterApiWalletRegistrationSetup(input) {
1580
1599
  route: input.route,
1581
1600
  services: walletRegistrationRoutePolicyServices(input),
1582
1601
  sourceIp: input.sourceIp,
1583
- resolvers: { apiCredentials: async () => await resolvePublishableKeyApiCredentialAuth({
1584
- environmentId: extractRouterApiEnvironmentId(input.headers) || void 0,
1585
- headers: input.headers,
1586
- missingEnvironmentMessage: "Environment header is required for wallet registration setup",
1587
- missingOriginMessage: "Origin header is required and must be a valid exact origin",
1588
- missingPublishableKeyMessage: "Missing publishable key",
1589
- origin,
1590
- publishableKeyAuth,
1591
- route: input.route,
1592
- routeAuthNotConfiguredMessage: "Wallet registration setup requires API credential auth policy"
1593
- }) }
1602
+ resolvers: { apiCredentials: publishableKeyRoutePrincipal.bind(void 0, context.principal) }
1594
1603
  });
1595
1604
  if (!resolved.ok) return routeJson(resolved.status, resolved.body);
1596
- if (resolved.context.principal.kind !== "api_credentials") return routeError(500, "internal", "wallet registration setup requires API credentials");
1597
- const principal = resolved.context.principal.principal;
1598
- const runtimePolicyScope = await resolveActiveRuntimePolicyScopeForEnvironment({
1599
- orgProjectEnv: input.services.orgProjectEnv || null,
1605
+ const principal = context.principal;
1606
+ const runtimePolicyScope = {
1600
1607
  orgId: principal.orgId,
1601
- environmentId: principal.environmentId,
1602
- projectId: principal.projectId,
1603
- envId: principal.envId
1604
- });
1608
+ projectId: context.environment.projectId,
1609
+ envId: context.environment.key,
1610
+ signingRootVersion: context.environment.signingRootVersion
1611
+ };
1605
1612
  const session = input.services.session;
1606
1613
  if (!session) return routeError(500, "internal", "wallet registration setup requires session signing");
1607
- const request = parseWalletRegistrationSetupRequest(input.body);
1608
- if (!request.ok) return routeError(400, request.code, request.message);
1609
1614
  return input.services.walletRegistration.setupWalletRegistration({
1610
1615
  request: request.value,
1611
1616
  orgId: principal.orgId,
1612
1617
  expectedOrigin: origin,
1613
1618
  signer: session,
1614
- ...runtimePolicyScope ? { runtimePolicyScope } : {},
1615
- ...runtimePolicyScope ? {
1616
- signingRootId: `${runtimePolicyScope.projectId}:${runtimePolicyScope.envId}`,
1617
- signingRootVersion: runtimePolicyScope.signingRootVersion
1618
- } : {}
1619
+ runtimePolicyScope,
1620
+ signingRootId: `${runtimePolicyScope.projectId}:${runtimePolicyScope.envId}`,
1621
+ signingRootVersion: runtimePolicyScope.signingRootVersion
1619
1622
  });
1620
1623
  }
1621
1624
  /**
@@ -1781,30 +1784,6 @@ function parseRegistrationRequestDigestB64u(raw) {
1781
1784
  return null;
1782
1785
  }
1783
1786
  }
1784
- async function projectActivatedWallet(input) {
1785
- const walletProjection = input.services.walletProjection || null;
1786
- if (!walletProjection) return null;
1787
- const verifier = input.services.session;
1788
- if (!verifier) return "wallet projection requires setup verification";
1789
- const verified = await verifyWalletRegistrationSetupClaims(verifier, input.signedSetup, {
1790
- registrationCeremonyId: input.registrationCeremonyId,
1791
- nowMs: Date.now()
1792
- });
1793
- if (!verified.ok) return verified.message;
1794
- if (verified.claims.policy.kind !== "runtime_policy_scope") return "wallet projection requires an exact runtime policy scope";
1795
- if (verified.claims.policy.scope.orgId !== verified.claims.orgId) return "wallet projection scope does not match its organization";
1796
- try {
1797
- await walletProjection.recordCreatedWallet({
1798
- orgId: verified.claims.orgId,
1799
- runtimePolicyScope: verified.claims.policy.scope,
1800
- walletId: verified.claims.walletId,
1801
- occurredAt: (/* @__PURE__ */ new Date()).toISOString()
1802
- });
1803
- return null;
1804
- } catch (error) {
1805
- return error instanceof Error ? error.message : String(error);
1806
- }
1807
- }
1808
1787
  /**
1809
1788
  * `POST /wallets/register/activate` — activation and finalization behind
1810
1789
  * one Gateway operation row.
@@ -1823,9 +1802,7 @@ async function handleRouterApiWalletRegistrationActivate(input) {
1823
1802
  const idempotencyKey = String(body.idempotencyKey || "").trim();
1824
1803
  if (!idempotencyKey) return routeError(400, "invalid_body", "idempotencyKey is required");
1825
1804
  const planKind = String(body.kind || "").trim();
1826
- if (planKind !== "evm_family_ecdsa" && planKind !== "near_ed25519_and_evm_family_ecdsa" && planKind !== "near_ed25519") return routeError(400, "invalid_body", "kind must name the signer plan");
1827
- const ed25519Only = planKind === "near_ed25519";
1828
- if (ed25519Only && body.ecdsa !== void 0) return routeError(400, "invalid_body", "an Ed25519-only activate carries no ECDSA activation");
1805
+ if (planKind !== "evm_family_ecdsa" && planKind !== "near_ed25519_and_evm_family_ecdsa") return routeError(400, "invalid_body", "activation requires an ECDSA signer plan");
1829
1806
  const ecdsa = isPlainObject(body.ecdsa) ? body.ecdsa : null;
1830
1807
  const unknownEcdsaField = ecdsa ? findUnknownField(ecdsa, [
1831
1808
  "activationCorrelationId",
@@ -1833,9 +1810,9 @@ async function handleRouterApiWalletRegistrationActivate(input) {
1833
1810
  "clientActivation"
1834
1811
  ]) : null;
1835
1812
  if (unknownEcdsaField) return routeError(400, "invalid_body", `wallet registration ECDSA activation field ${unknownEcdsaField} is unsupported`);
1836
- if (!ed25519Only && (!ecdsa || typeof ecdsa.activationCorrelationId !== "string" || typeof ecdsa.activationRequestDigestB64u !== "string" || !isPlainObject(ecdsa.clientActivation))) return routeError(400, "invalid_body", "browser-verified clientActivation is required");
1813
+ if (!ecdsa || typeof ecdsa.activationCorrelationId !== "string" || typeof ecdsa.activationRequestDigestB64u !== "string" || !isPlainObject(ecdsa.clientActivation)) return routeError(400, "invalid_body", "browser-verified clientActivation is required");
1837
1814
  let parsedActivation;
1838
- if (ecdsa) try {
1815
+ try {
1839
1816
  const parsed = parseRouterAbEcdsaRegistrationActivationRequestV1({
1840
1817
  registrationCeremonyId,
1841
1818
  ecdsa: {
@@ -1858,25 +1835,17 @@ async function handleRouterApiWalletRegistrationActivate(input) {
1858
1835
  signedSetup,
1859
1836
  idempotencyKey,
1860
1837
  planKind,
1861
- ...parsedActivation ? { ecdsa: parsedActivation } : {},
1838
+ ecdsa: parsedActivation,
1862
1839
  ...body.emailOtpEnrollment ? { emailOtpEnrollment: body.emailOtpEnrollment } : {},
1863
1840
  ...body.walletCustodyCommit !== void 0 ? { walletCustodyCommit: body.walletCustodyCommit } : {},
1864
1841
  verifier: session
1865
1842
  }, traceContext.value ?? void 0, serverTiming);
1866
1843
  if (!result.ok) return routeJson(400, result);
1867
1844
  if (!isEmailOtpWalletRegistrationActivateSuccessV2(result) && !isPasskeyWalletRegistrationActivateSuccessV2(result)) return routeError(500, "internal", "Wallet registration activation returned an invalid authority");
1868
- const projectionError = await projectActivatedWallet({
1869
- registrationCeremonyId,
1870
- services: input.services,
1871
- signedSetup
1872
- });
1873
- if (projectionError) return routeError(500, "internal", `Wallet was created but its Console projection failed: ${projectionError}`);
1874
1845
  return routeJson(200, result, { headers: ecdsaGatewayServerTimingHeaders(serverTiming) });
1875
1846
  }
1876
1847
  /**
1877
- * `POST /wallets/register/near-provisioning` — the non-blocking completion
1878
- * the client calls after activate, once its already-running Yao computation
1879
- * produces an activation.
1848
+ * Commits a NEAR-only wallet or completes a mixed wallet's deferred signer.
1880
1849
  */
1881
1850
  async function handleRouterApiWalletRegistrationNearProvisioning(input) {
1882
1851
  if (!isPlainObject(input.body)) return routeError(400, "invalid_body", "JSON body required");
@@ -1889,7 +1858,7 @@ async function handleRouterApiWalletRegistrationNearProvisioning(input) {
1889
1858
  if (!registrationCeremonyId || !signedSetup || !idempotencyKey) return routeError(400, "invalid_body", "registrationCeremonyId, signedSetup and idempotencyKey are required");
1890
1859
  const ed25519 = parseWalletRegistrationEd25519Finalize(body.ed25519);
1891
1860
  if (!ed25519.ok) return routeError(400, ed25519.code, ed25519.message);
1892
- const sessionSeal = parseRegistrationPreparedSessionSeal(body.sessionSeal);
1861
+ const sessionSeal = parseRegistrationPreparedSessionSeal(body.sessionSeal, input.signingSessionSeal?.service ?? null);
1893
1862
  if (!sessionSeal.ok) return routeError(400, sessionSeal.code, sessionSeal.message);
1894
1863
  const serverTiming = [];
1895
1864
  const result = await input.services.walletRegistration.completeWalletRegistrationNearProvisioning({
@@ -1900,17 +1869,14 @@ async function handleRouterApiWalletRegistrationNearProvisioning(input) {
1900
1869
  ed25519: ed25519.value,
1901
1870
  emailOtpEnrollment: body.emailOtpEnrollment,
1902
1871
  ...body.walletCustodyCommit !== void 0 ? { walletCustodyCommit: body.walletCustodyCommit } : {},
1903
- verifier: session
1904
- }, serverTiming);
1872
+ verifier: session,
1873
+ onSessionCommitted: sessionSeal.value?.prepare.bind(sessionSeal.value)
1874
+ }, serverTiming, input.waitUntil);
1905
1875
  if (!result.ok) return routeJson(400, result);
1906
1876
  if (sessionSeal.value) {
1907
1877
  if (!isPasskeyWalletRegistrationNearProvisioningSuccessV2(result)) return routeError(400, "invalid_body", "Registration session sealing requires a passkey authority");
1908
1878
  const sealStartedAt = Date.now();
1909
- const sealed = await applyRegistrationPreparedSessionSeal({
1910
- options: input.signingSessionSeal,
1911
- request: sessionSeal.value,
1912
- response: result
1913
- });
1879
+ const sealed = await sessionSeal.value.finish(result.registrationEstablishedSession.session);
1914
1880
  serverTiming.push(["near_finalize_session_seal", Math.max(0, Date.now() - sealStartedAt)]);
1915
1881
  if (!sealed.ok) return routeJson(503, {
1916
1882
  ok: false,
@@ -1924,83 +1890,6 @@ async function handleRouterApiWalletRegistrationNearProvisioning(input) {
1924
1890
  }
1925
1891
  return routeJson(200, result, { headers: ecdsaGatewayServerTimingHeaders(serverTiming) });
1926
1892
  }
1927
- function parseRegistrationPreparedSessionSeal(raw) {
1928
- if (raw === void 0) return {
1929
- ok: true,
1930
- value: void 0
1931
- };
1932
- if (!isPlainObject(raw)) return {
1933
- ok: false,
1934
- code: "invalid_body",
1935
- message: "sessionSeal must be an object"
1936
- };
1937
- if (Object.keys(raw).some((field) => ![
1938
- "thresholdSessionId",
1939
- "ciphertext",
1940
- "keyVersion"
1941
- ].includes(field))) return {
1942
- ok: false,
1943
- code: "invalid_body",
1944
- message: "sessionSeal has unknown fields"
1945
- };
1946
- const thresholdSessionId = String(raw.thresholdSessionId || "").trim();
1947
- const ciphertext = String(raw.ciphertext || "").trim();
1948
- const keyVersion = String(raw.keyVersion || "").trim();
1949
- if (!thresholdSessionId || !ciphertext) return {
1950
- ok: false,
1951
- code: "invalid_body",
1952
- message: "sessionSeal thresholdSessionId and ciphertext are required"
1953
- };
1954
- return {
1955
- ok: true,
1956
- value: {
1957
- thresholdSessionId,
1958
- ciphertext,
1959
- ...keyVersion ? { keyVersion } : {}
1960
- }
1961
- };
1962
- }
1963
- async function applyRegistrationPreparedSessionSeal(args) {
1964
- if (!args.options) return {
1965
- ok: false,
1966
- code: "signing_session_seal_unavailable",
1967
- message: "Signing-session sealing is unavailable"
1968
- };
1969
- const session = args.response.registrationEstablishedSession.session;
1970
- const tokens = session.tokens;
1971
- const ed25519 = tokens.kind === "near_ed25519" || tokens.kind === "near_ed25519_and_evm_family_ecdsa" ? tokens.ed25519 : null;
1972
- if (!ed25519 || String(ed25519.thresholdSessionId) !== args.request.thresholdSessionId) return {
1973
- ok: false,
1974
- code: "invalid_session_seal",
1975
- message: "Prepared seal does not match the established Ed25519 session"
1976
- };
1977
- const sealed = await args.options.service.applyServerSeal(args.request, {
1978
- userId: String(session.walletId),
1979
- session: {
1980
- kind: "exact_wallet_session_operation_credential",
1981
- curve: "ed25519",
1982
- thresholdSessionId: args.request.thresholdSessionId,
1983
- userId: String(session.walletId),
1984
- expiresAtMs: session.expiresAtMs
1985
- }
1986
- });
1987
- if (!sealed.ok) return sealed;
1988
- const keyVersion = String(sealed.keyVersion || "").trim();
1989
- if (!keyVersion) return {
1990
- ok: false,
1991
- code: "invalid_session_seal",
1992
- message: "Signing-session seal response is missing its key version"
1993
- };
1994
- return {
1995
- ok: true,
1996
- value: {
1997
- ciphertext: sealed.ciphertext,
1998
- keyVersion,
1999
- expiresAtMs: Math.min(sealed.expiresAtMs ?? session.expiresAtMs, session.expiresAtMs),
2000
- remainingUses: session.remainingUses
2001
- }
2002
- };
2003
- }
2004
1893
  function ecdsaGatewayServerTimingHeaders(serverTiming) {
2005
1894
  if (serverTiming.length === 0) return void 0;
2006
1895
  const header = serverTiming.map(([name, durationMs]) => `${name};dur=${Math.max(0, durationMs).toFixed(1)}`).join(", ");
@@ -2337,6 +2226,6 @@ function registrationContinuationAuthorization(headers) {
2337
2226
  } : { kind: "registration_grant" };
2338
2227
  }
2339
2228
  //#endregion
2340
- export { handleRouterApiWalletAddAuthMethodEmailOtpChallenge, handleRouterApiWalletAddAuthMethodFinalize, handleRouterApiWalletAddAuthMethodIntent, handleRouterApiWalletAddAuthMethodStart, handleRouterApiWalletAddSignerEcdsaActivation, handleRouterApiWalletAddSignerEcdsaDerivationRespond, handleRouterApiWalletAddSignerFinalize, handleRouterApiWalletAddSignerIntent, handleRouterApiWalletAddSignerStart, handleRouterApiWalletEcdsaKeyFactsInventory, handleRouterApiWalletNearImplicitAccountFund, handleRouterApiWalletRegistrationActivate, handleRouterApiWalletRegistrationNearAdmission, handleRouterApiWalletRegistrationNearProvisioning, handleRouterApiWalletRegistrationRespond, handleRouterApiWalletRegistrationSetup, handleRouterApiWalletRevokeAuthMethod };
2229
+ export { handleRouterApiWalletAddAuthMethodEmailOtpChallenge, handleRouterApiWalletAddAuthMethodFinalize, handleRouterApiWalletAddAuthMethodIntent, handleRouterApiWalletAddAuthMethodStart, handleRouterApiWalletAddSignerEcdsaActivation, handleRouterApiWalletAddSignerEcdsaDerivationRespond, handleRouterApiWalletAddSignerFinalize, handleRouterApiWalletAddSignerIntent, handleRouterApiWalletAddSignerStart, handleRouterApiWalletEcdsaKeyFactsInventory, handleRouterApiWalletNearImplicitAccountFund, handleRouterApiWalletRegistrationActivate, handleRouterApiWalletRegistrationNearAdmission, handleRouterApiWalletRegistrationNearProvisioning, handleRouterApiWalletRegistrationRespond, handleRouterApiWalletRegistrationSetup, handleRouterApiWalletRevokeAuthMethod, parseWalletRegistrationSetupRequest };
2341
2230
 
2342
2231
  //# sourceMappingURL=walletRegistrationRoutes.js.map
@@ -1,7 +1,7 @@
1
+ import { normalizeOptionalTrimmedString } from "../../../shared-ts/src/utils/normalize.js";
1
2
  import { base64UrlEncode } from "../../../shared-ts/src/utils/base64.js";
2
3
  import { alphabetizeStringify, sha256BytesUtf8 } from "../../../shared-ts/src/utils/digests.js";
3
4
  import "../../../shared-ts/src/utils/encoders.js";
4
- import { normalizeOptionalTrimmedString } from "../../../shared-ts/src/utils/normalize.js";
5
5
  import { normalizeRuntimePolicyScope } from "../../../shared-ts/src/threshold/signingRootScope.js";
6
6
  //#region src/router/domains/walletRegistration/walletRegistrationSetupPayload.ts
7
7
  /**