@seams/wallet-server 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1075) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +8 -0
  3. package/artifact-manifest.json +464 -0
  4. package/cloudflare-router-ab/build/deriver-a/index.js +2 -0
  5. package/cloudflare-router-ab/build/deriver-a/index_bg.wasm +0 -0
  6. package/cloudflare-router-ab/build/deriver-a/package.json +16 -0
  7. package/cloudflare-router-ab/build/deriver-a/worker/shim.mjs +4 -0
  8. package/cloudflare-router-ab/build/deriver-b/index.js +2 -0
  9. package/cloudflare-router-ab/build/deriver-b/index_bg.wasm +0 -0
  10. package/cloudflare-router-ab/build/deriver-b/package.json +16 -0
  11. package/cloudflare-router-ab/build/deriver-b/worker/shim.mjs +4 -0
  12. package/cloudflare-router-ab/build/local-tools/darwin-arm64/router_ab_local_init +0 -0
  13. package/cloudflare-router-ab/build/router/index.js +2 -0
  14. package/cloudflare-router-ab/build/router/index_bg.wasm +0 -0
  15. package/cloudflare-router-ab/build/router/package.json +16 -0
  16. package/cloudflare-router-ab/build/router/worker/shim.mjs +4 -0
  17. package/cloudflare-router-ab/build/signing-worker/index.js +2 -0
  18. package/cloudflare-router-ab/build/signing-worker/index_bg.wasm +0 -0
  19. package/cloudflare-router-ab/build/signing-worker/package.json +16 -0
  20. package/cloudflare-router-ab/build/signing-worker/worker/shim.mjs +4 -0
  21. package/cloudflare-router-ab/build/tenant-root-control-plane/index.js +2 -0
  22. package/cloudflare-router-ab/build/tenant-root-control-plane/index_bg.wasm +0 -0
  23. package/cloudflare-router-ab/build/tenant-root-control-plane/package.json +16 -0
  24. package/cloudflare-router-ab/build/tenant-root-control-plane/worker/shim.mjs +4 -0
  25. package/cloudflare-router-ab/env/tenant-root-control-plane.local.example +6 -0
  26. package/cloudflare-router-ab/migrations/deriver-a/0001_role_private_storage.sql +14 -0
  27. package/cloudflare-router-ab/migrations/deriver-a/0002_tenant_root_role_shares.sql +32 -0
  28. package/cloudflare-router-ab/migrations/deriver-a/0003_tenant_root_command_replays.sql +76 -0
  29. package/cloudflare-router-ab/migrations/deriver-a/0004_tenant_root_creation_admission.sql +7 -0
  30. package/cloudflare-router-ab/migrations/deriver-a/0005_tenant_root_refresh_state.sql +15 -0
  31. package/cloudflare-router-ab/migrations/deriver-a/0006_tenant_root_restore_import_keys.sql +119 -0
  32. package/cloudflare-router-ab/migrations/deriver-a/0007_tenant_root_restore_refresh_attempts.sql +103 -0
  33. package/cloudflare-router-ab/migrations/deriver-a/0008_tenant_root_restore_promotion.sql +40 -0
  34. package/cloudflare-router-ab/migrations/deriver-a/0009_tenant_root_restore_preactivation_cleanup.sql +8 -0
  35. package/cloudflare-router-ab/migrations/deriver-a/0010_tenant_root_recovery_attempts.sql +26 -0
  36. package/cloudflare-router-ab/migrations/deriver-a/0011_tenant_root_source_retirement.sql +100 -0
  37. package/cloudflare-router-ab/migrations/deriver-b/0001_role_private_storage.sql +14 -0
  38. package/cloudflare-router-ab/migrations/deriver-b/0002_tenant_root_role_shares.sql +32 -0
  39. package/cloudflare-router-ab/migrations/deriver-b/0003_tenant_root_command_replays.sql +76 -0
  40. package/cloudflare-router-ab/migrations/deriver-b/0004_tenant_root_creation_admission.sql +7 -0
  41. package/cloudflare-router-ab/migrations/deriver-b/0005_tenant_root_refresh_state.sql +15 -0
  42. package/cloudflare-router-ab/migrations/deriver-b/0006_tenant_root_restore_import_keys.sql +119 -0
  43. package/cloudflare-router-ab/migrations/deriver-b/0007_tenant_root_restore_refresh_attempts.sql +103 -0
  44. package/cloudflare-router-ab/migrations/deriver-b/0008_tenant_root_restore_promotion.sql +40 -0
  45. package/cloudflare-router-ab/migrations/deriver-b/0009_tenant_root_restore_preactivation_cleanup.sql +8 -0
  46. package/cloudflare-router-ab/migrations/deriver-b/0010_tenant_root_recovery_attempts.sql +26 -0
  47. package/cloudflare-router-ab/migrations/deriver-b/0011_tenant_root_source_retirement.sql +100 -0
  48. package/cloudflare-router-ab/migrations/signing-worker/0001_private_storage.sql +67 -0
  49. package/cloudflare-router-ab/migrations/signing-worker/0002_activation_revocation_fences.sql +3 -0
  50. package/cloudflare-router-ab/scripts/bootstrap-local-tenant-root.mjs +182 -0
  51. package/cloudflare-router-ab/scripts/initialize-local-wallet.mjs +17 -0
  52. package/cloudflare-router-ab/scripts/local-key-material.mjs +29 -0
  53. package/cloudflare-router-ab/scripts/prepare-local-runtime-config.mjs +1110 -0
  54. package/cloudflare-router-ab/scripts/start-local-role-workers.mjs +333 -0
  55. package/cloudflare-router-ab/scripts/start-local-wallet-system.mjs +427 -0
  56. package/cloudflare-router-ab/wrangler.deriver-a.toml +123 -0
  57. package/cloudflare-router-ab/wrangler.deriver-b.toml +123 -0
  58. package/cloudflare-router-ab/wrangler.router.toml +126 -0
  59. package/cloudflare-router-ab/wrangler.signing-worker.toml +86 -0
  60. package/cloudflare-router-ab/wrangler.tenant-root-control-plane.toml +56 -0
  61. package/dist/esm/authorization/capabilityPolicy.js +96 -0
  62. package/dist/esm/authorization/domain.js +434 -0
  63. package/dist/esm/authorization/factorEvidence.js +405 -0
  64. package/dist/esm/authorization/service.js +319 -0
  65. package/dist/esm/authorization/vaultProxyUse.js +295 -0
  66. package/dist/esm/cloud-host.js +126 -0
  67. package/dist/esm/core/AuthService.js +2 -0
  68. package/dist/esm/core/EmailOtpRecords.js +361 -0
  69. package/dist/esm/core/EmailOtpStores.js +1460 -0
  70. package/dist/esm/core/IdentityStore.js +617 -0
  71. package/dist/esm/core/NearPublicKeyStore.js +242 -0
  72. package/dist/esm/core/RegistrationCeremonyStore.js +2101 -0
  73. package/dist/esm/core/SessionService.js +255 -0
  74. package/dist/esm/core/ThresholdService/config.js +111 -0
  75. package/dist/esm/core/ThresholdService/ecdsaClientRootProof.js +27 -0
  76. package/dist/esm/core/ThresholdService/evmCryptoWasm.js +167 -0
  77. package/dist/esm/core/ThresholdService/index.js +4 -0
  78. package/dist/esm/core/ThresholdService/kv.js +368 -0
  79. package/dist/esm/core/ThresholdService/routerAb/ecdsaDerivationPoolFillHandlers.js +360 -0
  80. package/dist/esm/core/ThresholdService/routerAb/ecdsaDerivationPoolFillLiveSession.js +282 -0
  81. package/dist/esm/core/ThresholdService/routerAb/ecdsaDerivationPresignBridge.js +272 -0
  82. package/dist/esm/core/ThresholdService/routerAb/internalServiceHttp.js +57 -0
  83. package/dist/esm/core/ThresholdService/routerAbEcdsaSigningWorkerWasm.js +115 -0
  84. package/dist/esm/core/ThresholdService/routerAbNormalSigningPolicy.js +31 -0
  85. package/dist/esm/core/ThresholdService/secureRandomId.js +9 -0
  86. package/dist/esm/core/ThresholdService/stores/CloudflareDurableObjectStore.js +603 -0
  87. package/dist/esm/core/ThresholdService/stores/EcdsaSigningStore.js +422 -0
  88. package/dist/esm/core/ThresholdService/stores/KeyStore.js +140 -0
  89. package/dist/esm/core/ThresholdService/stores/SessionStore.js +437 -0
  90. package/dist/esm/core/ThresholdService/stores/StoreConfig.js +13 -0
  91. package/dist/esm/core/ThresholdService/stores/WalletSessionStore.js +722 -0
  92. package/dist/esm/core/ThresholdService/validation.js +718 -0
  93. package/dist/esm/core/WalletAuthMethodStore.js +180 -0
  94. package/dist/esm/core/WalletStore.js +495 -0
  95. package/dist/esm/core/WebAuthnAuthenticatorStore.js +485 -0
  96. package/dist/esm/core/WebAuthnCredentialBindingStore.js +594 -0
  97. package/dist/esm/core/WebAuthnLoginChallengeStore.js +432 -0
  98. package/dist/esm/core/WebAuthnSyncChallengeStore.js +434 -0
  99. package/dist/esm/core/authService/AuthService.js +611 -0
  100. package/dist/esm/core/authService/bytes.js +22 -0
  101. package/dist/esm/core/authService/configValues.js +15 -0
  102. package/dist/esm/core/authService/emailOtpChallengeOperations.js +126 -0
  103. package/dist/esm/core/authService/emailOtpChallengeProof.js +214 -0
  104. package/dist/esm/core/authService/emailOtpChallengeVerification.js +335 -0
  105. package/dist/esm/core/authService/emailOtpChallenges.js +260 -0
  106. package/dist/esm/core/authService/emailOtpConfig.js +231 -0
  107. package/dist/esm/core/authService/emailOtpDelivery.js +169 -0
  108. package/dist/esm/core/authService/emailOtpEnrollment.js +141 -0
  109. package/dist/esm/core/authService/emailOtpGrant.js +74 -0
  110. package/dist/esm/core/authService/emailOtpRegistrationEnrollment.js +322 -0
  111. package/dist/esm/core/authService/emailOtpSeal.js +78 -0
  112. package/dist/esm/core/authService/emailOtpUnlock.js +264 -0
  113. package/dist/esm/core/authService/githubOAuth.js +140 -0
  114. package/dist/esm/core/authService/googleEmailOtpErrors.js +6 -0
  115. package/dist/esm/core/authService/googleEmailOtpOperations.js +141 -0
  116. package/dist/esm/core/authService/googleEmailOtpRegistration.js +674 -0
  117. package/dist/esm/core/authService/identity.js +57 -0
  118. package/dist/esm/core/authService/identityOperations.js +32 -0
  119. package/dist/esm/core/authService/nearAccountOperations.js +229 -0
  120. package/dist/esm/core/authService/nearPrivateKeySigning.js +110 -0
  121. package/dist/esm/core/authService/nearPublicKeyMetadata.js +127 -0
  122. package/dist/esm/core/authService/nearTransactions.js +139 -0
  123. package/dist/esm/core/authService/oidcVerification.js +262 -0
  124. package/dist/esm/core/authService/portableCrypto.js +19 -0
  125. package/dist/esm/core/authService/rateLimits.js +117 -0
  126. package/dist/esm/core/authService/record.js +8 -0
  127. package/dist/esm/core/authService/registrationThresholdHelpers.js +131 -0
  128. package/dist/esm/core/authService/runtime.js +45 -0
  129. package/dist/esm/core/authService/signerWasmUrls.js +20 -0
  130. package/dist/esm/core/authService/storeRegistry.js +113 -0
  131. package/dist/esm/core/authService/thresholdEcdsaKeyInventory.js +146 -0
  132. package/dist/esm/core/authService/thresholdRuntimePolicy.js +19 -0
  133. package/dist/esm/core/authService/thresholdStoreSummary.js +32 -0
  134. package/dist/esm/core/authService/walletRegistrationPlanning.js +49 -0
  135. package/dist/esm/core/authService/wasm.js +78 -0
  136. package/dist/esm/core/authService/webauthn.js +746 -0
  137. package/dist/esm/core/authService/webauthnAuthority.js +17 -0
  138. package/dist/esm/core/authService/webauthnOidcHelpers.js +91 -0
  139. package/dist/esm/core/authService/webauthnWalletBinding.js +157 -0
  140. package/dist/esm/core/config.js +110 -0
  141. package/dist/esm/core/d1IdentityStore.js +340 -0
  142. package/dist/esm/core/d1WalletAuthMethodStore.js +768 -0
  143. package/dist/esm/core/d1WalletStore.js +724 -0
  144. package/dist/esm/core/defaultConfigsServer.js +9 -0
  145. package/dist/esm/core/deviceLinking/index.js +5 -0
  146. package/dist/esm/core/deviceLinking/linkedDeviceEd25519ExportRoot.js +0 -0
  147. package/dist/esm/core/deviceLinking/linkedDeviceEmailOtpGrant.js +211 -0
  148. package/dist/esm/core/deviceLinking/linkedDeviceManagement.js +279 -0
  149. package/dist/esm/core/deviceLinking/linkedDeviceSession.js +1419 -0
  150. package/dist/esm/core/deviceLinking/requestProof.js +172 -0
  151. package/dist/esm/core/errors.js +54 -0
  152. package/dist/esm/core/hostedAccountIds.js +225 -0
  153. package/dist/esm/core/keyMaterialBrands.js +58 -0
  154. package/dist/esm/core/logger.js +39 -0
  155. package/dist/esm/core/nearKeys.js +20 -0
  156. package/dist/esm/core/nearRelayerAccountProvisioning.js +713 -0
  157. package/dist/esm/core/nearSignerWasmRuntime.js +87 -0
  158. package/dist/esm/core/registrationContracts.js +2 -0
  159. package/dist/esm/core/routerAbSigning/RouterAbEcdsaPresignRuntime.js +88 -0
  160. package/dist/esm/core/routerAbSigning/RouterAbNormalSigningRuntime.js +101 -0
  161. package/dist/esm/core/routerAbSigning/createCloudflareDurableObjectRouterAbSigningRuntimes.js +39 -0
  162. package/dist/esm/core/routerAbSigning/createRouterAbSigningRuntimes.js +91 -0
  163. package/dist/esm/core/rpcClients/near/NearClient.js +389 -0
  164. package/dist/esm/core/sessionValidation.js +0 -0
  165. package/dist/esm/core/signingLanes/LaneAggregateRevocationApplicationService.js +86 -0
  166. package/dist/esm/core/signingLanes/LaneEffectJournalStore.js +0 -0
  167. package/dist/esm/core/signingLanes/LaneEnrollmentActivation.js +324 -0
  168. package/dist/esm/core/signingLanes/LaneEnrollmentRevocation.js +173 -0
  169. package/dist/esm/core/signingLanes/LaneLifecycleApplicationService.js +200 -0
  170. package/dist/esm/core/signingLanes/LaneLifecycleStore.js +24 -0
  171. package/dist/esm/core/signingLanes/SigningLaneStore.js +0 -0
  172. package/dist/esm/core/signingLanes/WalletExecutionLaneProjection.js +296 -0
  173. package/dist/esm/core/signingLanes/WalletKeyStore.js +0 -0
  174. package/dist/esm/core/signingLanes/ecdsaServerRetirement.js +78 -0
  175. package/dist/esm/core/signingLanes/ed25519ServerRetirement.js +71 -0
  176. package/dist/esm/core/signingLanes/index.js +8 -0
  177. package/dist/esm/core/signingLanes/signingWorkerLaneMaterialIdentity.js +0 -0
  178. package/dist/esm/core/signingMaterial/ordinaryInactiveSignerMaterialReservation.js +305 -0
  179. package/dist/esm/core/threeRouteRegistrationContracts.js +5 -0
  180. package/dist/esm/core/thresholdEcdsaChainTarget.js +49 -0
  181. package/dist/esm/core/types.js +8 -0
  182. package/dist/esm/core/utils.js +14 -0
  183. package/dist/esm/delegateAction/index.js +136 -0
  184. package/dist/esm/hosted-wallet-gateway-worker.js +18 -0
  185. package/dist/esm/hosted-wallet-gateway.js +701 -0
  186. package/dist/esm/index.js +53 -0
  187. package/dist/esm/local-hosted-wallet-gateway-worker.js +23 -0
  188. package/dist/esm/node_modules/@near-js/types/lib/esm/provider/response.js +17 -0
  189. package/dist/esm/router/auth/authRequestValidation.js +264 -0
  190. package/dist/esm/router/auth/commonRouterUtils.js +305 -0
  191. package/dist/esm/router/auth/routerApiCredentialAuth.js +91 -0
  192. package/dist/esm/router/auth/routerApiKeyAuth.js +63 -0
  193. package/dist/esm/router/auth/walletSessionFailure.js +49 -0
  194. package/dist/esm/router/auth/webAuthnCredentialCodecs.js +107 -0
  195. package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthBoundary.js +84 -0
  196. package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthConfig.js +321 -0
  197. package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthService.js +1581 -0
  198. package/dist/esm/router/cloudflare/d1/authorization/d1AuthorizationStore.js +1820 -0
  199. package/dist/esm/router/cloudflare/d1/authorization/d1VaultProxyStore.js +122 -0
  200. package/dist/esm/router/cloudflare/d1/authorization/walletSessionAuthorityProjection.js +119 -0
  201. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceAuthorityInstallService.js +1831 -0
  202. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEd25519ExportRootStore.js +118 -0
  203. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEmailOtpGrantStore.js +81 -0
  204. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEmailOtpTargetFactor.js +539 -0
  205. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceManagementService.js +92 -0
  206. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceOwnerAuthorizationProvider.js +560 -0
  207. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceRequestProofNonceStore.js +136 -0
  208. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceRouteService.js +95 -0
  209. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionRecords.js +91 -0
  210. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionService.js +15 -0
  211. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionStore.js +732 -0
  212. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSourceContributionPreparationPlanner.js +195 -0
  213. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetAuthenticatorStore.js +100 -0
  214. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetCredentialProvider.js +867 -0
  215. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetPlanner.js +169 -0
  216. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceVerifiedLinkBuilder.js +255 -0
  217. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceVerifiedLinkSourceReader.js +128 -0
  218. package/dist/esm/router/cloudflare/d1/deviceLinking/index.js +15 -0
  219. package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoCapabilityPersistence.js +311 -0
  220. package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoProductRegistrationPartitionedStateStore.js +21 -0
  221. package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoWalletSigner.js +65 -0
  222. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeIssuer.js +216 -0
  223. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeService.js +326 -0
  224. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeStore.js +346 -0
  225. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeVerifier.js +495 -0
  226. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpDeliveryRuntime.js +157 -0
  227. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpEnrollmentStore.js +248 -0
  228. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpGrantStore.js +66 -0
  229. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRateLimitStore.js +76 -0
  230. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRecords.js +539 -0
  231. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRecoveryService.js +404 -0
  232. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRegistrationEnrollmentFinalizer.js +200 -0
  233. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpServerSealRuntime.js +84 -0
  234. package/dist/esm/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpRegistrationAttemptStore.js +217 -0
  235. package/dist/esm/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpRegistrationRecords.js +485 -0
  236. package/dist/esm/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpSessionResolver.js +509 -0
  237. package/dist/esm/router/cloudflare/d1/identity/d1IdentityRecords.js +51 -0
  238. package/dist/esm/router/cloudflare/d1/identity/d1IdentityService.js +135 -0
  239. package/dist/esm/router/cloudflare/d1/near/d1NearPublicKeyStore.js +62 -0
  240. package/dist/esm/router/cloudflare/d1/oidc/d1OidcBoundary.js +272 -0
  241. package/dist/esm/router/cloudflare/d1/oidc/d1OidcVerificationService.js +132 -0
  242. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1PasskeyCustodyEnvelopeStore.js +628 -0
  243. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1PasskeyCustodyRouteService.js +871 -0
  244. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletCustodyCommitStore.js +823 -0
  245. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpAttemptStore.js +38 -0
  246. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpRecords.js +304 -0
  247. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpService.js +793 -0
  248. package/dist/esm/router/cloudflare/d1/registration/d1EvmFamilyEcdsaRegistrationBranch.js +120 -0
  249. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyRecordStore.js +317 -0
  250. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyRecords.js +2084 -0
  251. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyStore.js +309 -0
  252. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationIntentService.js +120 -0
  253. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationCommitStore.js +263 -0
  254. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationService.js +3887 -0
  255. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationSetup.js +182 -0
  256. package/dist/esm/router/cloudflare/d1/registration/walletRegistrationEstablishedSessionIssuer.js +399 -0
  257. package/dist/esm/router/cloudflare/d1/registration/walletRegistrationSessionCommitReceipt.js +486 -0
  258. package/dist/esm/router/cloudflare/d1/signingAdmission/d1RouterAbNormalSigningAdmissionStore.js +146 -0
  259. package/dist/esm/router/cloudflare/d1/signingLanes/d1EcdsaLanePrivateBindingResolver.js +10 -0
  260. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneAggregateRevocationApplicationService.js +22 -0
  261. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneEffectJournalStore.js +167 -0
  262. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneEnrollmentGateway.js +38 -0
  263. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneLifecycleApplicationService.js +20 -0
  264. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneLifecycleStore.js +1459 -0
  265. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneLockStore.js +114 -0
  266. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneProtocolCommitter.js +16 -0
  267. package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneRecords.js +170 -0
  268. package/dist/esm/router/cloudflare/d1/signingLanes/index.js +10 -0
  269. package/dist/esm/router/cloudflare/d1/versionedJson/d1VersionedJsonRecordStore.js +412 -0
  270. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAddSignerService.js +1396 -0
  271. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthMethodBoundary.js +285 -0
  272. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthMethodService.js +2018 -0
  273. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorityStore.js +792 -0
  274. package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnAuthService.js +635 -0
  275. package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnRecords.js +538 -0
  276. package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnStore.js +264 -0
  277. package/dist/esm/router/cloudflare/durableObjects/thresholdStore.js +514 -0
  278. package/dist/esm/router/cloudflare/durableObjects/versionedJsonRecordStore.js +192 -0
  279. package/dist/esm/router/cloudflare/runtime/cloudflare.types.js +0 -0
  280. package/dist/esm/router/cloudflare/runtime/cloudflareSignerWasm.js +8 -0
  281. package/dist/esm/router/cloudflare/runtime/createCloudflareRouter.js +19 -0
  282. package/dist/esm/router/cloudflare/runtime/createSelfHostedCloudflareSigningWorker.js +94 -0
  283. package/dist/esm/router/cloudflare/runtime/ed25519SessionAdapter.js +106 -0
  284. package/dist/esm/router/cloudflare/runtime/environment.js +25 -0
  285. package/dist/esm/router/cloudflare/runtime/routerAbPrewarm.js +34 -0
  286. package/dist/esm/router/cloudflare/runtime/routerAbServiceBindings.js +33 -0
  287. package/dist/esm/router/cloudflare/runtime/sessionAdapterRuntime.js +104 -0
  288. package/dist/esm/router/cloudflare/runtime/staticWalletConsoleBinding.js +168 -0
  289. package/dist/esm/router/cloudflare/runtime/tenantRootCreationGrant.js +147 -0
  290. package/dist/esm/router/cloudflare/runtime/walletConsoleOps.js +143 -0
  291. package/dist/esm/router/cloudflare/runtime/walletConsoleOpsClient.js +227 -0
  292. package/dist/esm/router/cloudflare/runtime/walletConsoleTenantRootLineage.js +30 -0
  293. package/dist/esm/router/cloudflare/runtime/walletControlOps.js +107 -0
  294. package/dist/esm/router/cloudflare/runtime/walletGateway.js +149 -0
  295. package/dist/esm/router/cloudflare/runtime/walletRuntimeOps.js +322 -0
  296. package/dist/esm/router/cloudflare/runtime/walletRuntimeOpsHandler.js +48 -0
  297. package/dist/esm/router/cloudflare/signingLanes/cloudflareLaneCurveExecution.js +597 -0
  298. package/dist/esm/router/cloudflare/signingLanes/cloudflareLaneProtocolCommitter.js +272 -0
  299. package/dist/esm/router/cloudflare/signingLanes/cloudflareOrdinaryInactiveSignerMaterialReservation.js +477 -0
  300. package/dist/esm/router/cloudflare/signingLanes/index.js +4 -0
  301. package/dist/esm/router/cloudflare/signingLanes/linkedDeviceEd25519CeremonyBinding.js +32 -0
  302. package/dist/esm/router/cloudflare-adaptor.js +45 -0
  303. package/dist/esm/router/cloudflare.js +42794 -0
  304. package/dist/esm/router/domains/ecdsa/routerAbEcdsaStrictRegistration.js +738 -0
  305. package/dist/esm/router/domains/ecdsa/thresholdEcdsaRequestValidation.js +134 -0
  306. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.js +368 -0
  307. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitionedStateStore.js +624 -0
  308. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitioning.js +143 -0
  309. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPersistence.js +270 -0
  310. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRunner.js +31 -0
  311. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRuntime.js +162 -0
  312. package/dist/esm/router/domains/ed25519Yao/export/routerAbEd25519YaoExport.js +1366 -0
  313. package/dist/esm/router/domains/ed25519Yao/export/routerAbEd25519YaoExportRequestScopedCloudflare.js +465 -0
  314. package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecovery.js +1609 -0
  315. package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryRequestScopedCloudflare.js +540 -0
  316. package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryWalletSessionAuthorization.js +394 -0
  317. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoHttpRegistrationBackend.js +572 -0
  318. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistration.js +555 -0
  319. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationExecutionRecord.js +268 -0
  320. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationIntentAuthorization.js +329 -0
  321. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationRequestScopedCloudflare.js +423 -0
  322. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.js +432 -0
  323. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationTwoPhaseRunner.js +58 -0
  324. package/dist/esm/router/domains/ed25519Yao/routerAbEd25519YaoGatewayEnvelope.js +0 -0
  325. package/dist/esm/router/domains/ed25519Yao/session/routerAbEd25519YaoWalletSession.js +0 -0
  326. package/dist/esm/router/domains/ed25519Yao/session/thresholdEd25519RequestValidation.js +275 -0
  327. package/dist/esm/router/domains/emailOtp/emailOtpExportPolicy.js +70 -0
  328. package/dist/esm/router/domains/emailOtp/emailOtpRequestValidation.js +34 -0
  329. package/dist/esm/router/domains/emailOtp/emailOtpRouteHandlers.js +218 -0
  330. package/dist/esm/router/domains/emailOtp/emailOtpSessionRouteHelpers.js +210 -0
  331. package/dist/esm/router/domains/passkeyCustody/envelopeRevocationAdmission.js +26 -0
  332. package/dist/esm/router/domains/passkeyCustody/passkeyCustodyEnvelopeRetrieval.js +107 -0
  333. package/dist/esm/router/domains/passkeyCustody/passkeyCustodyEnvelopeRetrievalRoute.js +45 -0
  334. package/dist/esm/router/domains/passkeyCustody/registrationCustodyOutcome.js +47 -0
  335. package/dist/esm/router/domains/passkeyCustody/verifiedCustodyFactor.js +46 -0
  336. package/dist/esm/router/domains/passkeyCustody/walletCustodyRegistrationAdmission.js +32 -0
  337. package/dist/esm/router/domains/passkeyCustody/walletCustodyRegistrationCommit.js +170 -0
  338. package/dist/esm/router/domains/passkeyCustody/walletRecoveryAttempt.js +64 -0
  339. package/dist/esm/router/domains/passkeyCustody/walletRecoveryFinalization.js +652 -0
  340. package/dist/esm/router/domains/passkeyCustody/walletRecoveryKeyManifest.js +396 -0
  341. package/dist/esm/router/domains/passkeyCustody/walletRecoveryRotation.js +87 -0
  342. package/dist/esm/router/domains/signingOperations/ed25519AuthorizedOperationReceipt.js +89 -0
  343. package/dist/esm/router/domains/signingOperations/routerAbNormalSigningAdmissionCore.js +106 -0
  344. package/dist/esm/router/domains/signingOperations/routerAbPrivateSigningWorker.js +2669 -0
  345. package/dist/esm/router/domains/signingOperations/walletExecutionAdmission.js +228 -0
  346. package/dist/esm/router/domains/syncAccount/syncAccountRequestValidation.js +78 -0
  347. package/dist/esm/router/domains/tenantRoot/tenantRootCustodyLineage.js +0 -0
  348. package/dist/esm/router/domains/tenantRoot/tenantRootEcdsaWalletSessionComposition.js +55 -0
  349. package/dist/esm/router/domains/tenantRoot/tenantRootEd25519WalletSessionComposition.js +56 -0
  350. package/dist/esm/router/domains/tenantRoot/tenantRootIdentityResolution.js +111 -0
  351. package/dist/esm/router/domains/walletRegistration/walletRegistrationInputs.js +0 -0
  352. package/dist/esm/router/domains/walletRegistration/walletRegistrationRoutes.js +2199 -0
  353. package/dist/esm/router/domains/walletRegistration/walletRegistrationSetupPayload.js +155 -0
  354. package/dist/esm/router/domains/walletUnlock/walletUnlockRequestedCapabilitiesValidation.js +84 -0
  355. package/dist/esm/router/domains/walletUnlock/walletUnlockRouteHandlers.js +1142 -0
  356. package/dist/esm/router/express-adaptor.js +84 -0
  357. package/dist/esm/router/express.js +26616 -0
  358. package/dist/esm/router/framework/apiCredentialPorts.js +11 -0
  359. package/dist/esm/router/framework/applyRouteMetering.js +26 -0
  360. package/dist/esm/router/framework/authServicePort.js +30 -0
  361. package/dist/esm/router/framework/enforceRoutePolicy.js +92 -0
  362. package/dist/esm/router/framework/http.js +87 -0
  363. package/dist/esm/router/framework/logger.js +7 -0
  364. package/dist/esm/router/framework/modules.js +34 -0
  365. package/dist/esm/router/framework/ror/index.js +5 -0
  366. package/dist/esm/router/framework/ror/normalize.js +57 -0
  367. package/dist/esm/router/framework/ror/options.js +33 -0
  368. package/dist/esm/router/framework/ror/provider.js +33 -0
  369. package/dist/esm/router/framework/ror/staticProvider.js +24 -0
  370. package/dist/esm/router/framework/routeAuthPolicy.js +16 -0
  371. package/dist/esm/router/framework/routeDefinitions.js +446 -0
  372. package/dist/esm/router/framework/routeExecutionContext.js +24 -0
  373. package/dist/esm/router/framework/routeExtensions.js +50 -0
  374. package/dist/esm/router/framework/routeMeteringPolicy.js +0 -0
  375. package/dist/esm/router/framework/routeRequestValidation.js +32 -0
  376. package/dist/esm/router/framework/routeResponses.js +33 -0
  377. package/dist/esm/router/framework/routerApi.js +42 -0
  378. package/dist/esm/router/framework/routerApiRouteSurface.js +54 -0
  379. package/dist/esm/router/framework/routerApiWebhooks.js +60 -0
  380. package/dist/esm/router/framework/runtimeSnapshotConsumer.js +145 -0
  381. package/dist/esm/router/framework/versionedJsonRecordStore.js +0 -0
  382. package/dist/esm/router/ror-adaptor.js +5 -0
  383. package/dist/esm/router/ror.js +178 -0
  384. package/dist/esm/router/transport/fetch/createFetchRouter.js +309 -0
  385. package/dist/esm/router/transport/fetch/fetchRouter.types.js +0 -0
  386. package/dist/esm/router/transport/fetch/routes/auth.js +219 -0
  387. package/dist/esm/router/transport/fetch/routes/deviceLinking.js +1196 -0
  388. package/dist/esm/router/transport/fetch/routes/deviceLinkingOwnerAuthorization.js +264 -0
  389. package/dist/esm/router/transport/fetch/routes/deviceManagement.js +289 -0
  390. package/dist/esm/router/transport/fetch/routes/health.js +42 -0
  391. package/dist/esm/router/transport/fetch/routes/nearPublicKeys.js +39 -0
  392. package/dist/esm/router/transport/fetch/routes/normalSigningRouterProxy.js +118 -0
  393. package/dist/esm/router/transport/fetch/routes/passkeyCustody.js +1618 -0
  394. package/dist/esm/router/transport/fetch/routes/sessions.js +1033 -0
  395. package/dist/esm/router/transport/fetch/routes/syncAccount.js +187 -0
  396. package/dist/esm/router/transport/fetch/routes/syncAccountBootstrap.js +214 -0
  397. package/dist/esm/router/transport/fetch/routes/thresholdEcdsa.js +1729 -0
  398. package/dist/esm/router/transport/fetch/routes/thresholdEd25519.js +1321 -0
  399. package/dist/esm/router/transport/fetch/routes/walletExecutionLanePreflight.js +228 -0
  400. package/dist/esm/router/transport/fetch/routes/walletRegistration.js +73 -0
  401. package/dist/esm/router/transport/fetch/routes/webauthnAuthenticators.js +43 -0
  402. package/dist/esm/router/transport/fetch/routes/wellKnown.js +48 -0
  403. package/dist/esm/shared-ts/src/authorization/capabilityKinds.js +224 -0
  404. package/dist/esm/shared-ts/src/authorization/delegatedAuthority.js +134 -0
  405. package/dist/esm/shared-ts/src/authorization/index.js +6 -0
  406. package/dist/esm/shared-ts/src/authorization/operationFingerprint.js +58 -0
  407. package/dist/esm/shared-ts/src/authorization/walletAuthority.js +802 -0
  408. package/dist/esm/shared-ts/src/authorization/walletCustodyOperation.js +18 -0
  409. package/dist/esm/shared-ts/src/authorization/walletSessionIssuance.js +5 -0
  410. package/dist/esm/shared-ts/src/device-linking/committedSignerPackages.js +332 -0
  411. package/dist/esm/shared-ts/src/device-linking/contracts.js +8 -0
  412. package/dist/esm/shared-ts/src/device-linking/delegatedActivationPlan.js +132 -0
  413. package/dist/esm/shared-ts/src/device-linking/digests.js +273 -0
  414. package/dist/esm/shared-ts/src/device-linking/ed25519ExportRoot.js +158 -0
  415. package/dist/esm/shared-ts/src/device-linking/index.js +9 -0
  416. package/dist/esm/shared-ts/src/device-linking/parsers.js +1412 -0
  417. package/dist/esm/shared-ts/src/device-linking/requestProof.js +114 -0
  418. package/dist/esm/shared-ts/src/device-linking/sourceContribution.js +563 -0
  419. package/dist/esm/shared-ts/src/device-linking/walletSessionCredentialDelivery.js +207 -0
  420. package/dist/esm/shared-ts/src/near/actions.js +75 -0
  421. package/dist/esm/shared-ts/src/passkey-custody/ceremonyCommitPayload.js +69 -0
  422. package/dist/esm/shared-ts/src/passkey-custody/credentialActivity.js +81 -0
  423. package/dist/esm/shared-ts/src/passkey-custody/custodyEnvelope.js +272 -0
  424. package/dist/esm/shared-ts/src/passkey-custody/custodySecretBinding.js +175 -0
  425. package/dist/esm/shared-ts/src/passkey-custody/index.js +5 -0
  426. package/dist/esm/shared-ts/src/passkey-custody/primitives.js +92 -0
  427. package/dist/esm/shared-ts/src/signing-lanes/evmFamilySigningKeySlotId.js +53 -0
  428. package/dist/esm/shared-ts/src/signing-lanes/execution.js +14 -0
  429. package/dist/esm/shared-ts/src/signing-lanes/index.js +11 -0
  430. package/dist/esm/shared-ts/src/signing-lanes/linkedEcdsaScope.js +1 -0
  431. package/dist/esm/shared-ts/src/signing-lanes/ownerContinuity.js +91 -0
  432. package/dist/esm/shared-ts/src/signing-lanes/participantDigest.js +124 -0
  433. package/dist/esm/shared-ts/src/signing-lanes/participants.js +262 -0
  434. package/dist/esm/shared-ts/src/signing-lanes/recordParsers.js +143 -0
  435. package/dist/esm/shared-ts/src/signing-lanes/rotation.js +8 -0
  436. package/dist/esm/shared-ts/src/signing-lanes/rotationDigests.js +397 -0
  437. package/dist/esm/shared-ts/src/signing-lanes/rotationLifecycle.js +313 -0
  438. package/dist/esm/shared-ts/src/signing-lanes/rotationParsers.js +1620 -0
  439. package/dist/esm/shared-ts/src/tenant-root/index.js +2 -0
  440. package/dist/esm/shared-ts/src/tenant-root/tenantRootIdentity.js +198 -0
  441. package/dist/esm/shared-ts/src/tenant-root/tenantRootOperationRecord.js +440 -0
  442. package/dist/esm/shared-ts/src/threshold/ecdsaDerivationRoleLocalBootstrap.js +85 -0
  443. package/dist/esm/shared-ts/src/threshold/participants.js +26 -0
  444. package/dist/esm/shared-ts/src/threshold/sessionPolicy.js +9 -0
  445. package/dist/esm/shared-ts/src/threshold/signingRootScope.js +40 -0
  446. package/dist/esm/shared-ts/src/utils/addAuthMethodRegistration.js +104 -0
  447. package/dist/esm/shared-ts/src/utils/addWalletAuthMethod.js +36 -0
  448. package/dist/esm/shared-ts/src/utils/base58.js +28 -0
  449. package/dist/esm/shared-ts/src/utils/base64.js +70 -0
  450. package/dist/esm/shared-ts/src/utils/canonicalPrimitives.js +27 -0
  451. package/dist/esm/shared-ts/src/utils/digests.js +33 -0
  452. package/dist/esm/shared-ts/src/utils/domainIds.js +309 -0
  453. package/dist/esm/shared-ts/src/utils/ecdsaCapabilityActivation.js +34 -0
  454. package/dist/esm/shared-ts/src/utils/ecdsaKeyFactsInventory.js +46 -0
  455. package/dist/esm/shared-ts/src/utils/emailOtpDomain.js +38 -0
  456. package/dist/esm/shared-ts/src/utils/emailOtpRecoveryKey.js +10 -0
  457. package/dist/esm/shared-ts/src/utils/encoders.js +2 -0
  458. package/dist/esm/shared-ts/src/utils/errors.js +88 -0
  459. package/dist/esm/shared-ts/src/utils/evmRpcResults.js +97 -0
  460. package/dist/esm/shared-ts/src/utils/jsonRpc.js +64 -0
  461. package/dist/esm/shared-ts/src/utils/keccak.js +150 -0
  462. package/dist/esm/shared-ts/src/utils/near.js +99 -0
  463. package/dist/esm/shared-ts/src/utils/nearRpcResults.js +205 -0
  464. package/dist/esm/shared-ts/src/utils/normalize.js +87 -0
  465. package/dist/esm/shared-ts/src/utils/registrationEstablishedSession.js +201 -0
  466. package/dist/esm/shared-ts/src/utils/registrationIntent.js +1268 -0
  467. package/dist/esm/shared-ts/src/utils/routerAbEcdsaDerivation.js +1655 -0
  468. package/dist/esm/shared-ts/src/utils/routerAbEd25519Yao.js +984 -0
  469. package/dist/esm/shared-ts/src/utils/routerAbNormalSigningIdentity.js +118 -0
  470. package/dist/esm/shared-ts/src/utils/routerAbPublicKeyset.js +138 -0
  471. package/dist/esm/shared-ts/src/utils/routerAbTraceContext.js +36 -0
  472. package/dist/esm/shared-ts/src/utils/secureRandomId.js +35 -0
  473. package/dist/esm/shared-ts/src/utils/signingSessionSeal.js +118 -0
  474. package/dist/esm/shared-ts/src/utils/thresholdEcdsaKeyHandle.js +28 -0
  475. package/dist/esm/shared-ts/src/utils/validation.js +23 -0
  476. package/dist/esm/shared-ts/src/utils/walletAddSignerActivation.js +32 -0
  477. package/dist/esm/shared-ts/src/utils/walletAuthAuthority.js +207 -0
  478. package/dist/esm/shared-ts/src/utils/walletSessionFailure.js +15 -0
  479. package/dist/esm/shared-ts/src/utils/webauthnDeviceInfo.js +207 -0
  480. package/dist/esm/shared-ts/src/wallet-recovery/backupAcknowledgement.js +66 -0
  481. package/dist/esm/shared-ts/src/wallet-recovery/index.js +10 -0
  482. package/dist/esm/shared-ts/src/wallet-recovery/recoveryCodeIssuance.js +1 -0
  483. package/dist/esm/shared-ts/src/wallet-recovery/recoveryCodeLocator.js +34 -0
  484. package/dist/esm/shared-ts/src/wallet-recovery/recoveryCodeReservation.js +80 -0
  485. package/dist/esm/shared-ts/src/wallet-recovery/recoveryCodes.js +4 -0
  486. package/dist/esm/shared-ts/src/wallet-recovery/recoveryKeyId.js +53 -0
  487. package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryCommittedProjection.js +108 -0
  488. package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryEcdsaPossession.js +157 -0
  489. package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryEnvelopeSet.js +233 -0
  490. package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryRotation.js +3 -0
  491. package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryTarget.js +29 -0
  492. package/dist/esm/storage/d1Sql.js +85 -0
  493. package/dist/esm/storage/tenantRoute.js +89 -0
  494. package/dist/esm/tenant-root.js +5 -0
  495. package/dist/esm/threshold/session/signingSessionSeal/crypto/cipher.js +204 -0
  496. package/dist/esm/threshold/session/signingSessionSeal/crypto/shamir3PassWasm.js +87 -0
  497. package/dist/esm/threshold/session/signingSessionSeal/guards/backends.js +192 -0
  498. package/dist/esm/threshold/session/signingSessionSeal/guards/index.js +121 -0
  499. package/dist/esm/threshold/session/signingSessionSeal/idempotency.js +38 -0
  500. package/dist/esm/threshold/session/signingSessionSeal/idempotencyBackends.js +131 -0
  501. package/dist/esm/threshold/session/signingSessionSeal/idempotencyRecords.js +55 -0
  502. package/dist/esm/threshold/session/signingSessionSeal/index.js +13 -0
  503. package/dist/esm/threshold/session/signingSessionSeal/observability/audit.js +38 -0
  504. package/dist/esm/threshold/session/signingSessionSeal/options.js +54 -0
  505. package/dist/esm/threshold/session/signingSessionSeal/routesOptions.js +45 -0
  506. package/dist/esm/threshold/session/signingSessionSeal/service.js +316 -0
  507. package/dist/esm/threshold/session/signingSessionSeal/signingSessionSeal.types.js +0 -0
  508. package/dist/esm/threshold/session/signingSessionSeal/transport/express.js +151 -0
  509. package/dist/esm/threshold/session/signingSessionSeal/transport/fetch.js +106 -0
  510. package/dist/esm/threshold/session/signingSessionSeal/transport/shared.js +159 -0
  511. package/dist/esm/threshold/statusCodes.js +39 -0
  512. package/dist/esm/wasm/evm_crypto/pkg/evm_crypto.js +601 -0
  513. package/dist/esm/wasm/evm_crypto/pkg/evm_crypto_bg.wasm +0 -0
  514. package/dist/esm/wasm/near_signer/pkg/wasm_signer_worker.js +1078 -0
  515. package/dist/esm/wasm/near_signer/pkg/wasm_signer_worker_bg.wasm +0 -0
  516. package/dist/esm/wasm/router_ab_ecdsa_signing_worker/pkg/router_ab_ecdsa_signing_worker.js +503 -0
  517. package/dist/esm/wasm/router_ab_ecdsa_signing_worker/pkg/router_ab_ecdsa_signing_worker_bg.wasm +0 -0
  518. package/dist/esm/wasm/shamir3pass_runtime/pkg/shamir3pass_runtime.js +393 -0
  519. package/dist/esm/wasm/shamir3pass_runtime/pkg/shamir3pass_runtime_bg.wasm +0 -0
  520. package/dist/esm/wasm/signer.js +2 -0
  521. package/dist/types/shared-ts/src/authorization/capabilityKinds.d.ts +147 -0
  522. package/dist/types/shared-ts/src/authorization/capabilityKinds.typecheck.d.ts +2 -0
  523. package/dist/types/shared-ts/src/authorization/delegatedAuthority.d.ts +44 -0
  524. package/dist/types/shared-ts/src/authorization/index.d.ts +7 -0
  525. package/dist/types/shared-ts/src/authorization/operationFingerprint.d.ts +39 -0
  526. package/dist/types/shared-ts/src/authorization/operationFingerprint.typecheck.d.ts +2 -0
  527. package/dist/types/shared-ts/src/authorization/walletAuthority.d.ts +168 -0
  528. package/dist/types/shared-ts/src/authorization/walletAuthority.typecheck.d.ts +2 -0
  529. package/dist/types/shared-ts/src/authorization/walletCustodyOperation.d.ts +10 -0
  530. package/dist/types/shared-ts/src/authorization/walletSessionIssuance.d.ts +28 -0
  531. package/dist/types/shared-ts/src/device-linking/activeWalletSession.d.ts +3 -0
  532. package/dist/types/shared-ts/src/device-linking/activeWalletSession.typecheck.d.ts +2 -0
  533. package/dist/types/shared-ts/src/device-linking/committedSignerPackages.d.ts +71 -0
  534. package/dist/types/shared-ts/src/device-linking/contracts.d.ts +843 -0
  535. package/dist/types/shared-ts/src/device-linking/contracts.typecheck.d.ts +2 -0
  536. package/dist/types/shared-ts/src/device-linking/delegatedActivationPlan.d.ts +37 -0
  537. package/dist/types/shared-ts/src/device-linking/digests.d.ts +23 -0
  538. package/dist/types/shared-ts/src/device-linking/ed25519ExportRoot.d.ts +93 -0
  539. package/dist/types/shared-ts/src/device-linking/index.d.ts +11 -0
  540. package/dist/types/shared-ts/src/device-linking/parsers.d.ts +124 -0
  541. package/dist/types/shared-ts/src/device-linking/requestProof.d.ts +26 -0
  542. package/dist/types/shared-ts/src/device-linking/sourceContribution.d.ts +182 -0
  543. package/dist/types/shared-ts/src/device-linking/walletSessionCredentialDelivery.d.ts +84 -0
  544. package/dist/types/shared-ts/src/index.d.ts +10 -0
  545. package/dist/types/shared-ts/src/near/actions.d.ts +141 -0
  546. package/dist/types/shared-ts/src/near/delegate.d.ts +55 -0
  547. package/dist/types/shared-ts/src/near/index.d.ts +3 -0
  548. package/dist/types/shared-ts/src/passkey-custody/ceremonyCommitPayload.d.ts +211 -0
  549. package/dist/types/shared-ts/src/passkey-custody/credentialActivity.d.ts +49 -0
  550. package/dist/types/shared-ts/src/passkey-custody/credentialObservations.d.ts +74 -0
  551. package/dist/types/shared-ts/src/passkey-custody/custodyEnvelope.d.ts +191 -0
  552. package/dist/types/shared-ts/src/passkey-custody/custodySecretBinding.d.ts +140 -0
  553. package/dist/types/shared-ts/src/passkey-custody/envelopeIndex.d.ts +29 -0
  554. package/dist/types/shared-ts/src/passkey-custody/index.d.ts +9 -0
  555. package/dist/types/shared-ts/src/passkey-custody/kekContext.d.ts +34 -0
  556. package/dist/types/shared-ts/src/passkey-custody/passkeyCustody.typecheck.d.ts +2 -0
  557. package/dist/types/shared-ts/src/passkey-custody/primitives.d.ts +34 -0
  558. package/dist/types/shared-ts/src/signing-lanes/evmFamilySigningKeySlotId.d.ts +27 -0
  559. package/dist/types/shared-ts/src/signing-lanes/execution.d.ts +91 -0
  560. package/dist/types/shared-ts/src/signing-lanes/execution.typecheck.d.ts +2 -0
  561. package/dist/types/shared-ts/src/signing-lanes/ids.d.ts +18 -0
  562. package/dist/types/shared-ts/src/signing-lanes/index.d.ts +14 -0
  563. package/dist/types/shared-ts/src/signing-lanes/linkedEcdsaScope.d.ts +62 -0
  564. package/dist/types/shared-ts/src/signing-lanes/linkedEcdsaScope.typecheck.d.ts +2 -0
  565. package/dist/types/shared-ts/src/signing-lanes/ownerContinuity.d.ts +30 -0
  566. package/dist/types/shared-ts/src/signing-lanes/ownerContinuity.typecheck.d.ts +2 -0
  567. package/dist/types/shared-ts/src/signing-lanes/participantDigest.d.ts +48 -0
  568. package/dist/types/shared-ts/src/signing-lanes/participantDigest.typecheck.d.ts +2 -0
  569. package/dist/types/shared-ts/src/signing-lanes/participants.d.ts +89 -0
  570. package/dist/types/shared-ts/src/signing-lanes/recordParsers.d.ts +128 -0
  571. package/dist/types/shared-ts/src/signing-lanes/records.d.ts +160 -0
  572. package/dist/types/shared-ts/src/signing-lanes/records.typecheck.d.ts +2 -0
  573. package/dist/types/shared-ts/src/signing-lanes/rotation.d.ts +894 -0
  574. package/dist/types/shared-ts/src/signing-lanes/rotation.typecheck.d.ts +2 -0
  575. package/dist/types/shared-ts/src/signing-lanes/rotationDigests.d.ts +32 -0
  576. package/dist/types/shared-ts/src/signing-lanes/rotationLifecycle.d.ts +99 -0
  577. package/dist/types/shared-ts/src/signing-lanes/rotationParsers.d.ts +67 -0
  578. package/dist/types/shared-ts/src/signing-lanes/validation.d.ts +11 -0
  579. package/dist/types/shared-ts/src/tenant-root/index.d.ts +3 -0
  580. package/dist/types/shared-ts/src/tenant-root/tenantRootIdentity.d.ts +72 -0
  581. package/dist/types/shared-ts/src/tenant-root/tenantRootOperationRecord.d.ts +192 -0
  582. package/dist/types/shared-ts/src/threshold/ecdsaDerivationRoleLocalBootstrap.d.ts +77 -0
  583. package/dist/types/shared-ts/src/threshold/ed25519OperationFingerprint.d.ts +130 -0
  584. package/dist/types/shared-ts/src/threshold/index.d.ts +7 -0
  585. package/dist/types/shared-ts/src/threshold/participants.d.ts +38 -0
  586. package/dist/types/shared-ts/src/threshold/secp256k1.d.ts +39 -0
  587. package/dist/types/shared-ts/src/threshold/sessionPolicy.d.ts +5 -0
  588. package/dist/types/shared-ts/src/threshold/signingRootScope.d.ts +24 -0
  589. package/dist/types/shared-ts/src/utils/addAuthMethodRegistration.d.ts +63 -0
  590. package/dist/types/shared-ts/src/utils/addWalletAuthMethod.d.ts +295 -0
  591. package/dist/types/shared-ts/src/utils/addWalletAuthMethod.typecheck.d.ts +11 -0
  592. package/dist/types/shared-ts/src/utils/authenticatorOptions.d.ts +25 -0
  593. package/dist/types/shared-ts/src/utils/base58.d.ts +17 -0
  594. package/dist/types/shared-ts/src/utils/base64.d.ts +53 -0
  595. package/dist/types/shared-ts/src/utils/bigint.d.ts +3 -0
  596. package/dist/types/shared-ts/src/utils/canonicalPrimitives.d.ts +12 -0
  597. package/dist/types/shared-ts/src/utils/digests.d.ts +6 -0
  598. package/dist/types/shared-ts/src/utils/domainIds.d.ts +140 -0
  599. package/dist/types/shared-ts/src/utils/domainIds.typecheck.d.ts +2 -0
  600. package/dist/types/shared-ts/src/utils/ecdsaCapabilityActivation.d.ts +29 -0
  601. package/dist/types/shared-ts/src/utils/ecdsaKeyFactsInventory.d.ts +24 -0
  602. package/dist/types/shared-ts/src/utils/emailOtpDomain.d.ts +30 -0
  603. package/dist/types/shared-ts/src/utils/emailOtpRecoveryKey.d.ts +31 -0
  604. package/dist/types/shared-ts/src/utils/encoders.d.ts +3 -0
  605. package/dist/types/shared-ts/src/utils/errors.d.ts +44 -0
  606. package/dist/types/shared-ts/src/utils/evmRpcResults.d.ts +31 -0
  607. package/dist/types/shared-ts/src/utils/generated/routerAbEd25519YaoCore.d.ts +128 -0
  608. package/dist/types/shared-ts/src/utils/index.d.ts +34 -0
  609. package/dist/types/shared-ts/src/utils/jsonRpc.d.ts +30 -0
  610. package/dist/types/shared-ts/src/utils/keccak.d.ts +2 -0
  611. package/dist/types/shared-ts/src/utils/near.d.ts +81 -0
  612. package/dist/types/shared-ts/src/utils/nearRpcResults.d.ts +101 -0
  613. package/dist/types/shared-ts/src/utils/normalize.d.ts +57 -0
  614. package/dist/types/shared-ts/src/utils/paillier.d.ts +37 -0
  615. package/dist/types/shared-ts/src/utils/recoveryDomain.d.ts +12 -0
  616. package/dist/types/shared-ts/src/utils/registrationEstablishedSession.d.ts +85 -0
  617. package/dist/types/shared-ts/src/utils/registrationIntent.d.ts +621 -0
  618. package/dist/types/shared-ts/src/utils/registrationIntent.typecheck.d.ts +2 -0
  619. package/dist/types/shared-ts/src/utils/routerAbEcdsaDerivation.d.ts +715 -0
  620. package/dist/types/shared-ts/src/utils/routerAbEcdsaDerivation.typecheck.d.ts +2 -0
  621. package/dist/types/shared-ts/src/utils/routerAbEcdsaDerivationRefresh.typecheck.d.ts +2 -0
  622. package/dist/types/shared-ts/src/utils/routerAbEd25519Yao.d.ts +339 -0
  623. package/dist/types/shared-ts/src/utils/routerAbEd25519Yao.typecheck.d.ts +2 -0
  624. package/dist/types/shared-ts/src/utils/routerAbNormalSigningIdentity.d.ts +71 -0
  625. package/dist/types/shared-ts/src/utils/routerAbPublicKeyset.d.ts +51 -0
  626. package/dist/types/shared-ts/src/utils/routerAbTraceContext.d.ts +16 -0
  627. package/dist/types/shared-ts/src/utils/secureRandomId.d.ts +6 -0
  628. package/dist/types/shared-ts/src/utils/signerDomain.d.ts +75 -0
  629. package/dist/types/shared-ts/src/utils/signerDomain.typecheck.d.ts +2 -0
  630. package/dist/types/shared-ts/src/utils/signerSlot.d.ts +11 -0
  631. package/dist/types/shared-ts/src/utils/signingSessionSeal.d.ts +153 -0
  632. package/dist/types/shared-ts/src/utils/signingSessionSeal.typecheck.d.ts +2 -0
  633. package/dist/types/shared-ts/src/utils/theme.d.ts +2 -0
  634. package/dist/types/shared-ts/src/utils/thresholdEcdsaKeyHandle.d.ts +11 -0
  635. package/dist/types/shared-ts/src/utils/validation.d.ts +35 -0
  636. package/dist/types/shared-ts/src/utils/walletAddSignerActivation.d.ts +23 -0
  637. package/dist/types/shared-ts/src/utils/walletAuthAuthority.d.ts +150 -0
  638. package/dist/types/shared-ts/src/utils/walletAuthAuthority.typecheck.d.ts +2 -0
  639. package/dist/types/shared-ts/src/utils/walletCapabilityBindings.d.ts +106 -0
  640. package/dist/types/shared-ts/src/utils/walletCapabilityBindings.typecheck.d.ts +2 -0
  641. package/dist/types/shared-ts/src/utils/walletSessionFailure.d.ts +13 -0
  642. package/dist/types/shared-ts/src/utils/webauthnDeviceInfo.d.ts +48 -0
  643. package/dist/types/shared-ts/src/wallet-recovery/backupAcknowledgement.d.ts +56 -0
  644. package/dist/types/shared-ts/src/wallet-recovery/index.d.ts +10 -0
  645. package/dist/types/shared-ts/src/wallet-recovery/recoveryCodeAttempt.d.ts +59 -0
  646. package/dist/types/shared-ts/src/wallet-recovery/recoveryCodeIssuance.d.ts +37 -0
  647. package/dist/types/shared-ts/src/wallet-recovery/recoveryCodeLocator.d.ts +22 -0
  648. package/dist/types/shared-ts/src/wallet-recovery/recoveryCodeReservation.d.ts +79 -0
  649. package/dist/types/shared-ts/src/wallet-recovery/recoveryCodes.d.ts +11 -0
  650. package/dist/types/shared-ts/src/wallet-recovery/recoveryEnvelopes.d.ts +42 -0
  651. package/dist/types/shared-ts/src/wallet-recovery/recoveryKekContext.d.ts +37 -0
  652. package/dist/types/shared-ts/src/wallet-recovery/recoveryKeyId.d.ts +58 -0
  653. package/dist/types/shared-ts/src/wallet-recovery/walletRecovery.typecheck.d.ts +2 -0
  654. package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryCommittedProjection.d.ts +110 -0
  655. package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryEcdsaPossession.d.ts +29 -0
  656. package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryEnvelopeSet.d.ts +115 -0
  657. package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryRotation.d.ts +18 -0
  658. package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryTarget.d.ts +12 -0
  659. package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryTarget.typecheck.d.ts +2 -0
  660. package/dist/types/wallet-server/src/authorization/capabilityPolicy.d.ts +45 -0
  661. package/dist/types/wallet-server/src/authorization/capabilityPolicy.typecheck.d.ts +2 -0
  662. package/dist/types/wallet-server/src/authorization/domain.d.ts +454 -0
  663. package/dist/types/wallet-server/src/authorization/domain.typecheck.d.ts +2 -0
  664. package/dist/types/wallet-server/src/authorization/factorEvidence.d.ts +165 -0
  665. package/dist/types/wallet-server/src/authorization/factorEvidence.typecheck.d.ts +2 -0
  666. package/dist/types/wallet-server/src/authorization/service.d.ts +227 -0
  667. package/dist/types/wallet-server/src/authorization/vaultProxyUse.d.ts +75 -0
  668. package/dist/types/wallet-server/src/cloud-host.d.ts +94 -0
  669. package/dist/types/wallet-server/src/core/AuthService.d.ts +3 -0
  670. package/dist/types/wallet-server/src/core/EmailOtpRecords.d.ts +33 -0
  671. package/dist/types/wallet-server/src/core/EmailOtpStores.d.ts +336 -0
  672. package/dist/types/wallet-server/src/core/IdentityStore.d.ts +57 -0
  673. package/dist/types/wallet-server/src/core/NearPublicKeyStore.d.ts +58 -0
  674. package/dist/types/wallet-server/src/core/RegistrationCeremonyStore.d.ts +551 -0
  675. package/dist/types/wallet-server/src/core/SessionService.d.ts +70 -0
  676. package/dist/types/wallet-server/src/core/ThresholdService/config.d.ts +23 -0
  677. package/dist/types/wallet-server/src/core/ThresholdService/ecdsaClientRootProof.d.ts +12 -0
  678. package/dist/types/wallet-server/src/core/ThresholdService/evmCryptoWasm.d.ts +32 -0
  679. package/dist/types/wallet-server/src/core/ThresholdService/index.d.ts +4 -0
  680. package/dist/types/wallet-server/src/core/ThresholdService/kv.d.ts +52 -0
  681. package/dist/types/wallet-server/src/core/ThresholdService/routerAb/ecdsaDerivationPoolFillHandlers.d.ts +45 -0
  682. package/dist/types/wallet-server/src/core/ThresholdService/routerAb/ecdsaDerivationPoolFillLiveSession.d.ts +93 -0
  683. package/dist/types/wallet-server/src/core/ThresholdService/routerAb/ecdsaDerivationPresignBridge.d.ts +138 -0
  684. package/dist/types/wallet-server/src/core/ThresholdService/routerAb/internalServiceHttp.d.ts +30 -0
  685. package/dist/types/wallet-server/src/core/ThresholdService/routerAbEcdsaSigningWorkerWasm.d.ts +17 -0
  686. package/dist/types/wallet-server/src/core/ThresholdService/routerAbNormalSigningPolicy.d.ts +21 -0
  687. package/dist/types/wallet-server/src/core/ThresholdService/secureRandomId.d.ts +2 -0
  688. package/dist/types/wallet-server/src/core/ThresholdService/stores/CloudflareDurableObjectStore.d.ts +128 -0
  689. package/dist/types/wallet-server/src/core/ThresholdService/stores/EcdsaSigningStore.d.ts +76 -0
  690. package/dist/types/wallet-server/src/core/ThresholdService/stores/KeyStore.d.ts +39 -0
  691. package/dist/types/wallet-server/src/core/ThresholdService/stores/SessionStore.d.ts +102 -0
  692. package/dist/types/wallet-server/src/core/ThresholdService/stores/StoreConfig.d.ts +3 -0
  693. package/dist/types/wallet-server/src/core/ThresholdService/stores/ThresholdStoreConfig.typecheck.d.ts +2 -0
  694. package/dist/types/wallet-server/src/core/ThresholdService/stores/WalletSessionStore.d.ts +98 -0
  695. package/dist/types/wallet-server/src/core/ThresholdService/thresholdEd25519AuthorityScope.typecheck.d.ts +2 -0
  696. package/dist/types/wallet-server/src/core/ThresholdService/validation.d.ts +193 -0
  697. package/dist/types/wallet-server/src/core/WalletAuthMethodStore.d.ts +12 -0
  698. package/dist/types/wallet-server/src/core/WalletStore.d.ts +143 -0
  699. package/dist/types/wallet-server/src/core/WalletStore.typecheck.d.ts +2 -0
  700. package/dist/types/wallet-server/src/core/WebAuthnAuthenticatorStore.d.ts +62 -0
  701. package/dist/types/wallet-server/src/core/WebAuthnCredentialBindingStore.d.ts +116 -0
  702. package/dist/types/wallet-server/src/core/WebAuthnCredentialBindingStore.typecheck.d.ts +13 -0
  703. package/dist/types/wallet-server/src/core/WebAuthnLoginChallengeStore.d.ts +50 -0
  704. package/dist/types/wallet-server/src/core/WebAuthnSyncChallengeStore.d.ts +50 -0
  705. package/dist/types/wallet-server/src/core/authService/AuthService.d.ts +493 -0
  706. package/dist/types/wallet-server/src/core/authService/bytes.d.ts +4 -0
  707. package/dist/types/wallet-server/src/core/authService/configValues.d.ts +7 -0
  708. package/dist/types/wallet-server/src/core/authService/emailOtpChallengeOperations.d.ts +108 -0
  709. package/dist/types/wallet-server/src/core/authService/emailOtpChallengeProof.d.ts +177 -0
  710. package/dist/types/wallet-server/src/core/authService/emailOtpChallengeVerification.d.ts +46 -0
  711. package/dist/types/wallet-server/src/core/authService/emailOtpChallenges.d.ts +110 -0
  712. package/dist/types/wallet-server/src/core/authService/emailOtpConfig.d.ts +34 -0
  713. package/dist/types/wallet-server/src/core/authService/emailOtpDelivery.d.ts +65 -0
  714. package/dist/types/wallet-server/src/core/authService/emailOtpEnrollment.d.ts +79 -0
  715. package/dist/types/wallet-server/src/core/authService/emailOtpGrant.d.ts +42 -0
  716. package/dist/types/wallet-server/src/core/authService/emailOtpRegistrationEnrollment.d.ts +116 -0
  717. package/dist/types/wallet-server/src/core/authService/emailOtpSeal.d.ts +35 -0
  718. package/dist/types/wallet-server/src/core/authService/emailOtpUnlock.d.ts +70 -0
  719. package/dist/types/wallet-server/src/core/authService/githubOAuth.d.ts +35 -0
  720. package/dist/types/wallet-server/src/core/authService/googleEmailOtpErrors.d.ts +2 -0
  721. package/dist/types/wallet-server/src/core/authService/googleEmailOtpOperations.d.ts +126 -0
  722. package/dist/types/wallet-server/src/core/authService/googleEmailOtpRegistration.d.ts +172 -0
  723. package/dist/types/wallet-server/src/core/authService/identity.d.ts +25 -0
  724. package/dist/types/wallet-server/src/core/authService/identityOperations.d.ts +19 -0
  725. package/dist/types/wallet-server/src/core/authService/nearAccountOperations.d.ts +55 -0
  726. package/dist/types/wallet-server/src/core/authService/nearPrivateKeySigning.d.ts +16 -0
  727. package/dist/types/wallet-server/src/core/authService/nearPublicKeyMetadata.d.ts +43 -0
  728. package/dist/types/wallet-server/src/core/authService/nearTransactions.d.ts +49 -0
  729. package/dist/types/wallet-server/src/core/authService/oidcVerification.d.ts +65 -0
  730. package/dist/types/wallet-server/src/core/authService/portableCrypto.d.ts +3 -0
  731. package/dist/types/wallet-server/src/core/authService/rateLimits.d.ts +30 -0
  732. package/dist/types/wallet-server/src/core/authService/record.d.ts +2 -0
  733. package/dist/types/wallet-server/src/core/authService/registrationThresholdHelpers.d.ts +37 -0
  734. package/dist/types/wallet-server/src/core/authService/runtime.d.ts +20 -0
  735. package/dist/types/wallet-server/src/core/authService/signerWasmUrls.d.ts +3 -0
  736. package/dist/types/wallet-server/src/core/authService/storeRegistry.d.ts +58 -0
  737. package/dist/types/wallet-server/src/core/authService/thresholdEcdsaKeyInventory.d.ts +72 -0
  738. package/dist/types/wallet-server/src/core/authService/thresholdRuntimePolicy.d.ts +4 -0
  739. package/dist/types/wallet-server/src/core/authService/thresholdStoreSummary.d.ts +3 -0
  740. package/dist/types/wallet-server/src/core/authService/walletRegistrationPlanning.d.ts +19 -0
  741. package/dist/types/wallet-server/src/core/authService/wasm.d.ts +12 -0
  742. package/dist/types/wallet-server/src/core/authService/webauthn.d.ts +207 -0
  743. package/dist/types/wallet-server/src/core/authService/webauthnAuthority.d.ts +5 -0
  744. package/dist/types/wallet-server/src/core/authService/webauthnOidcHelpers.d.ts +52 -0
  745. package/dist/types/wallet-server/src/core/authService/webauthnWalletBinding.d.ts +48 -0
  746. package/dist/types/wallet-server/src/core/config.d.ts +13 -0
  747. package/dist/types/wallet-server/src/core/d1IdentityStore.d.ts +44 -0
  748. package/dist/types/wallet-server/src/core/d1WalletAuthMethodStore.d.ts +214 -0
  749. package/dist/types/wallet-server/src/core/d1WalletStore.d.ts +108 -0
  750. package/dist/types/wallet-server/src/core/defaultConfigsServer.d.ts +5 -0
  751. package/dist/types/wallet-server/src/core/deviceLinking/index.d.ts +5 -0
  752. package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceEd25519ExportRoot.d.ts +36 -0
  753. package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceEmailOtpGrant.d.ts +87 -0
  754. package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceManagement.d.ts +137 -0
  755. package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceSession.d.ts +462 -0
  756. package/dist/types/wallet-server/src/core/deviceLinking/requestProof.d.ts +55 -0
  757. package/dist/types/wallet-server/src/core/errors.d.ts +10 -0
  758. package/dist/types/wallet-server/src/core/hostedAccountIds.d.ts +31 -0
  759. package/dist/types/wallet-server/src/core/keyMaterialBrands.d.ts +28 -0
  760. package/dist/types/wallet-server/src/core/keyMaterialBrands.typecheck.d.ts +2 -0
  761. package/dist/types/wallet-server/src/core/logger.d.ts +21 -0
  762. package/dist/types/wallet-server/src/core/nearKeys.d.ts +3 -0
  763. package/dist/types/wallet-server/src/core/nearRelayerAccountProvisioning.d.ts +78 -0
  764. package/dist/types/wallet-server/src/core/nearSignerWasmRuntime.d.ts +3 -0
  765. package/dist/types/wallet-server/src/core/registrationContracts.d.ts +747 -0
  766. package/dist/types/wallet-server/src/core/registrationRequests.typecheck.d.ts +2 -0
  767. package/dist/types/wallet-server/src/core/routerAbSigning/RouterAbEcdsaPresignRuntime.d.ts +53 -0
  768. package/dist/types/wallet-server/src/core/routerAbSigning/RouterAbNormalSigningRuntime.d.ts +71 -0
  769. package/dist/types/wallet-server/src/core/routerAbSigning/createCloudflareDurableObjectRouterAbSigningRuntimes.d.ts +28 -0
  770. package/dist/types/wallet-server/src/core/routerAbSigning/createRouterAbSigningRuntimes.d.ts +16 -0
  771. package/dist/types/wallet-server/src/core/rpcClients/near/NearClient.d.ts +134 -0
  772. package/dist/types/wallet-server/src/core/sessionValidation.d.ts +9 -0
  773. package/dist/types/wallet-server/src/core/signingLanes/LaneAggregateRevocationApplicationService.d.ts +35 -0
  774. package/dist/types/wallet-server/src/core/signingLanes/LaneEffectJournalStore.d.ts +63 -0
  775. package/dist/types/wallet-server/src/core/signingLanes/LaneEnrollmentActivation.d.ts +13 -0
  776. package/dist/types/wallet-server/src/core/signingLanes/LaneEnrollmentRevocation.d.ts +24 -0
  777. package/dist/types/wallet-server/src/core/signingLanes/LaneLifecycleApplicationService.d.ts +141 -0
  778. package/dist/types/wallet-server/src/core/signingLanes/LaneLifecycleStore.d.ts +229 -0
  779. package/dist/types/wallet-server/src/core/signingLanes/SigningLaneStore.d.ts +15 -0
  780. package/dist/types/wallet-server/src/core/signingLanes/WalletExecutionLaneProjection.d.ts +59 -0
  781. package/dist/types/wallet-server/src/core/signingLanes/WalletKeyStore.d.ts +13 -0
  782. package/dist/types/wallet-server/src/core/signingLanes/ecdsaServerRetirement.d.ts +58 -0
  783. package/dist/types/wallet-server/src/core/signingLanes/ed25519ServerRetirement.d.ts +30 -0
  784. package/dist/types/wallet-server/src/core/signingLanes/index.d.ts +11 -0
  785. package/dist/types/wallet-server/src/core/signingLanes/signingWorkerLaneMaterialIdentity.d.ts +21 -0
  786. package/dist/types/wallet-server/src/core/signingMaterial/ordinaryInactiveSignerMaterialReservation.d.ts +155 -0
  787. package/dist/types/wallet-server/src/core/threeRouteRegistrationContracts.d.ts +442 -0
  788. package/dist/types/wallet-server/src/core/threeRouteRegistrationContracts.typecheck.d.ts +58 -0
  789. package/dist/types/wallet-server/src/core/thresholdEcdsaChainTarget.d.ts +15 -0
  790. package/dist/types/wallet-server/src/core/types.d.ts +757 -0
  791. package/dist/types/wallet-server/src/core/utils.d.ts +3 -0
  792. package/dist/types/wallet-server/src/delegateAction/index.d.ts +88 -0
  793. package/dist/types/wallet-server/src/hosted-wallet-gateway-worker.d.ts +10 -0
  794. package/dist/types/wallet-server/src/hosted-wallet-gateway.d.ts +126 -0
  795. package/dist/types/wallet-server/src/index.d.ts +34 -0
  796. package/dist/types/wallet-server/src/local-hosted-wallet-gateway-worker.d.ts +13 -0
  797. package/dist/types/wallet-server/src/router/auth/authRequestValidation.d.ts +97 -0
  798. package/dist/types/wallet-server/src/router/auth/commonRouterUtils.d.ts +142 -0
  799. package/dist/types/wallet-server/src/router/auth/routerApiCredentialAuth.d.ts +26 -0
  800. package/dist/types/wallet-server/src/router/auth/routerApiKeyAuth.d.ts +16 -0
  801. package/dist/types/wallet-server/src/router/auth/walletSessionFailure.d.ts +14 -0
  802. package/dist/types/wallet-server/src/router/auth/webAuthnCredentialCodecs.d.ts +20 -0
  803. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthBoundary.d.ts +28 -0
  804. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthConfig.d.ts +192 -0
  805. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthService.d.ts +13 -0
  806. package/dist/types/wallet-server/src/router/cloudflare/d1/authorization/d1AuthorizationStore.d.ts +174 -0
  807. package/dist/types/wallet-server/src/router/cloudflare/d1/authorization/d1VaultProxyStore.d.ts +13 -0
  808. package/dist/types/wallet-server/src/router/cloudflare/d1/authorization/walletSessionAuthorityProjection.d.ts +24 -0
  809. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceAuthorityInstallService.d.ts +241 -0
  810. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEd25519ExportRootStore.d.ts +23 -0
  811. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEmailOtpGrantStore.d.ts +32 -0
  812. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEmailOtpTargetFactor.d.ts +118 -0
  813. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceManagementService.d.ts +22 -0
  814. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceOwnerAuthorizationProvider.d.ts +80 -0
  815. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceRequestProofNonceStore.d.ts +29 -0
  816. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceRouteService.d.ts +17 -0
  817. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionRecords.d.ts +37 -0
  818. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionService.d.ts +12 -0
  819. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionStore.d.ts +149 -0
  820. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSourceContributionPreparationPlanner.d.ts +38 -0
  821. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetAuthenticatorStore.d.ts +19 -0
  822. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetCredentialProvider.d.ts +220 -0
  823. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetPlanner.d.ts +88 -0
  824. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceVerifiedLinkBuilder.d.ts +54 -0
  825. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceVerifiedLinkSourceReader.d.ts +23 -0
  826. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/index.d.ts +15 -0
  827. package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoCapabilityPersistence.d.ts +33 -0
  828. package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoProductRegistrationPartitionedStateStore.d.ts +6 -0
  829. package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoWalletSigner.d.ts +27 -0
  830. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeIssuer.d.ts +80 -0
  831. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeService.d.ts +48 -0
  832. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeStore.d.ts +64 -0
  833. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeVerifier.d.ts +126 -0
  834. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpDeliveryRuntime.d.ts +22 -0
  835. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpEnrollmentStore.d.ts +68 -0
  836. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpGrantStore.d.ts +15 -0
  837. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRateLimitStore.d.ts +37 -0
  838. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRecords.d.ts +186 -0
  839. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRecoveryService.d.ts +45 -0
  840. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRegistrationEnrollmentFinalizer.d.ts +124 -0
  841. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpServerSealRuntime.d.ts +24 -0
  842. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpRegistrationAttemptStore.d.ts +51 -0
  843. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpRegistrationRecords.d.ts +69 -0
  844. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpSessionResolver.d.ts +57 -0
  845. package/dist/types/wallet-server/src/router/cloudflare/d1/identity/d1IdentityRecords.d.ts +38 -0
  846. package/dist/types/wallet-server/src/router/cloudflare/d1/identity/d1IdentityService.d.ts +31 -0
  847. package/dist/types/wallet-server/src/router/cloudflare/d1/near/d1NearPublicKeyStore.d.ts +30 -0
  848. package/dist/types/wallet-server/src/router/cloudflare/d1/oidc/d1OidcBoundary.d.ts +60 -0
  849. package/dist/types/wallet-server/src/router/cloudflare/d1/oidc/d1OidcVerificationService.d.ts +39 -0
  850. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1PasskeyCustodyEnvelopeStore.d.ts +335 -0
  851. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1PasskeyCustodyRouteService.d.ts +448 -0
  852. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1WalletCustodyCommitStore.d.ts +256 -0
  853. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpAttemptStore.d.ts +32 -0
  854. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpRecords.d.ts +116 -0
  855. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpService.d.ts +180 -0
  856. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1EvmFamilyEcdsaRegistrationBranch.d.ts +24 -0
  857. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyRecordStore.d.ts +86 -0
  858. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyRecords.d.ts +121 -0
  859. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyStore.d.ts +84 -0
  860. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationIntentService.d.ts +31 -0
  861. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationCommitStore.d.ts +49 -0
  862. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationService.d.ts +369 -0
  863. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationSetup.d.ts +106 -0
  864. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/walletRegistrationEstablishedSessionIssuer.d.ts +104 -0
  865. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/walletRegistrationSessionCommitReceipt.d.ts +70 -0
  866. package/dist/types/wallet-server/src/router/cloudflare/d1/signingAdmission/d1RouterAbNormalSigningAdmissionStore.d.ts +26 -0
  867. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1EcdsaLanePrivateBindingResolver.d.ts +4 -0
  868. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneAggregateRevocationApplicationService.d.ts +4 -0
  869. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneEffectJournalStore.d.ts +25 -0
  870. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneEnrollmentGateway.d.ts +20 -0
  871. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneLifecycleApplicationService.d.ts +13 -0
  872. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneLifecycleStore.d.ts +51 -0
  873. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneLockStore.d.ts +28 -0
  874. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneProtocolCommitter.d.ts +5 -0
  875. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneRecords.d.ts +107 -0
  876. package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/index.d.ts +10 -0
  877. package/dist/types/wallet-server/src/router/cloudflare/d1/versionedJson/d1VersionedJsonRecordStore.d.ts +118 -0
  878. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAddSignerService.d.ts +114 -0
  879. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAddSignerService.typecheck.d.ts +2 -0
  880. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthMethodBoundary.d.ts +90 -0
  881. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthMethodService.d.ts +359 -0
  882. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorityStore.d.ts +143 -0
  883. package/dist/types/wallet-server/src/router/cloudflare/d1/webauthn/d1WebAuthnAuthService.d.ts +42 -0
  884. package/dist/types/wallet-server/src/router/cloudflare/d1/webauthn/d1WebAuthnRecords.d.ts +135 -0
  885. package/dist/types/wallet-server/src/router/cloudflare/d1/webauthn/d1WebAuthnStore.d.ts +89 -0
  886. package/dist/types/wallet-server/src/router/cloudflare/durableObjects/thresholdStore.d.ts +19 -0
  887. package/dist/types/wallet-server/src/router/cloudflare/durableObjects/versionedJsonRecordStore.d.ts +32 -0
  888. package/dist/types/wallet-server/src/router/cloudflare/runtime/cloudflare.types.d.ts +30 -0
  889. package/dist/types/wallet-server/src/router/cloudflare/runtime/cloudflareSignerWasm.d.ts +2 -0
  890. package/dist/types/wallet-server/src/router/cloudflare/runtime/createCloudflareRouter.d.ts +5 -0
  891. package/dist/types/wallet-server/src/router/cloudflare/runtime/createSelfHostedCloudflareSigningWorker.d.ts +23 -0
  892. package/dist/types/wallet-server/src/router/cloudflare/runtime/ed25519SessionAdapter.d.ts +16 -0
  893. package/dist/types/wallet-server/src/router/cloudflare/runtime/environment.d.ts +5 -0
  894. package/dist/types/wallet-server/src/router/cloudflare/runtime/routerAbPrewarm.d.ts +9 -0
  895. package/dist/types/wallet-server/src/router/cloudflare/runtime/routerAbServiceBindings.d.ts +11 -0
  896. package/dist/types/wallet-server/src/router/cloudflare/runtime/sessionAdapterRuntime.d.ts +28 -0
  897. package/dist/types/wallet-server/src/router/cloudflare/runtime/staticWalletConsoleBinding.d.ts +27 -0
  898. package/dist/types/wallet-server/src/router/cloudflare/runtime/tenantRootCreationGrant.d.ts +24 -0
  899. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletConsoleOps.d.ts +143 -0
  900. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletConsoleOpsClient.d.ts +20 -0
  901. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletConsoleTenantRootLineage.d.ts +7 -0
  902. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletControlOps.d.ts +21 -0
  903. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletGateway.d.ts +30 -0
  904. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRuntimeOps.d.ts +64 -0
  905. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRuntimeOpsHandler.d.ts +3 -0
  906. package/dist/types/wallet-server/src/router/cloudflare/signingLanes/cloudflareLaneCurveExecution.d.ts +217 -0
  907. package/dist/types/wallet-server/src/router/cloudflare/signingLanes/cloudflareLaneProtocolCommitter.d.ts +73 -0
  908. package/dist/types/wallet-server/src/router/cloudflare/signingLanes/cloudflareOrdinaryInactiveSignerMaterialReservation.d.ts +100 -0
  909. package/dist/types/wallet-server/src/router/cloudflare/signingLanes/index.d.ts +4 -0
  910. package/dist/types/wallet-server/src/router/cloudflare/signingLanes/linkedDeviceEd25519CeremonyBinding.d.ts +6 -0
  911. package/dist/types/wallet-server/src/router/cloudflare-adaptor.d.ts +75 -0
  912. package/dist/types/wallet-server/src/router/domains/ecdsa/routerAbEcdsaStrictRegistration.d.ts +199 -0
  913. package/dist/types/wallet-server/src/router/domains/ecdsa/thresholdEcdsaRequestValidation.d.ts +32 -0
  914. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.d.ts +172 -0
  915. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.typecheck.d.ts +2 -0
  916. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitionedStateStore.d.ts +156 -0
  917. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitioning.d.ts +59 -0
  918. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPersistence.d.ts +47 -0
  919. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRunner.d.ts +29 -0
  920. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRuntime.d.ts +20 -0
  921. package/dist/types/wallet-server/src/router/domains/ed25519Yao/export/routerAbEd25519YaoExport.d.ts +271 -0
  922. package/dist/types/wallet-server/src/router/domains/ed25519Yao/export/routerAbEd25519YaoExportRequestScopedCloudflare.d.ts +12 -0
  923. package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecovery.d.ts +509 -0
  924. package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryActivation.typecheck.d.ts +2 -0
  925. package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryRequestScopedCloudflare.d.ts +14 -0
  926. package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryWalletSessionAuthorization.d.ts +20 -0
  927. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoHttpRegistrationBackend.d.ts +56 -0
  928. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistration.d.ts +200 -0
  929. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationExecutionRecord.d.ts +70 -0
  930. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationIntentAuthorization.d.ts +73 -0
  931. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationRequestScopedCloudflare.d.ts +9 -0
  932. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.d.ts +131 -0
  933. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.typecheck.d.ts +2 -0
  934. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationTwoPhaseRunner.d.ts +62 -0
  935. package/dist/types/wallet-server/src/router/domains/ed25519Yao/routerAbEd25519YaoGatewayEnvelope.d.ts +17 -0
  936. package/dist/types/wallet-server/src/router/domains/ed25519Yao/session/routerAbEd25519YaoWalletSession.d.ts +178 -0
  937. package/dist/types/wallet-server/src/router/domains/ed25519Yao/session/routerAbEd25519YaoWalletSession.typecheck.d.ts +2 -0
  938. package/dist/types/wallet-server/src/router/domains/ed25519Yao/session/thresholdEd25519RequestValidation.d.ts +19 -0
  939. package/dist/types/wallet-server/src/router/domains/emailOtp/emailOtpExportPolicy.d.ts +32 -0
  940. package/dist/types/wallet-server/src/router/domains/emailOtp/emailOtpRequestValidation.d.ts +13 -0
  941. package/dist/types/wallet-server/src/router/domains/emailOtp/emailOtpRouteHandlers.d.ts +35 -0
  942. package/dist/types/wallet-server/src/router/domains/emailOtp/emailOtpSessionRouteHelpers.d.ts +134 -0
  943. package/dist/types/wallet-server/src/router/domains/passkeyCustody/envelopeRevocationAdmission.d.ts +31 -0
  944. package/dist/types/wallet-server/src/router/domains/passkeyCustody/passkeyCustodyEnvelopeRetrieval.d.ts +85 -0
  945. package/dist/types/wallet-server/src/router/domains/passkeyCustody/passkeyCustodyEnvelopeRetrievalRoute.d.ts +42 -0
  946. package/dist/types/wallet-server/src/router/domains/passkeyCustody/registrationCustodyOutcome.d.ts +38 -0
  947. package/dist/types/wallet-server/src/router/domains/passkeyCustody/verifiedCustodyFactor.d.ts +35 -0
  948. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletCustodyRegistrationAdmission.d.ts +56 -0
  949. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletCustodyRegistrationCommit.d.ts +65 -0
  950. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletRecoveryAttempt.d.ts +59 -0
  951. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletRecoveryFinalization.d.ts +81 -0
  952. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletRecoveryKeyManifest.d.ts +184 -0
  953. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletRecoveryRotation.d.ts +31 -0
  954. package/dist/types/wallet-server/src/router/domains/signingOperations/ed25519AuthorizedOperationReceipt.d.ts +32 -0
  955. package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbNormalSigningAdmissionCore.d.ts +48 -0
  956. package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbPrivateSigningWorker.d.ts +909 -0
  957. package/dist/types/wallet-server/src/router/domains/signingOperations/walletExecutionAdmission.d.ts +104 -0
  958. package/dist/types/wallet-server/src/router/domains/syncAccount/syncAccountRequestValidation.d.ts +30 -0
  959. package/dist/types/wallet-server/src/router/domains/tenantRoot/tenantRootCustodyLineage.d.ts +14 -0
  960. package/dist/types/wallet-server/src/router/domains/tenantRoot/tenantRootEcdsaWalletSessionComposition.d.ts +35 -0
  961. package/dist/types/wallet-server/src/router/domains/tenantRoot/tenantRootEd25519WalletSessionComposition.d.ts +35 -0
  962. package/dist/types/wallet-server/src/router/domains/tenantRoot/tenantRootIdentityResolution.d.ts +56 -0
  963. package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationInputs.d.ts +78 -0
  964. package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationRoutes.d.ts +91 -0
  965. package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationSetupPayload.d.ts +105 -0
  966. package/dist/types/wallet-server/src/router/domains/walletUnlock/walletUnlockRequestedCapabilitiesValidation.d.ts +39 -0
  967. package/dist/types/wallet-server/src/router/domains/walletUnlock/walletUnlockRouteHandlers.d.ts +172 -0
  968. package/dist/types/wallet-server/src/router/express-adaptor.d.ts +22 -0
  969. package/dist/types/wallet-server/src/router/framework/apiCredentialPorts.d.ts +82 -0
  970. package/dist/types/wallet-server/src/router/framework/applyRouteMetering.d.ts +23 -0
  971. package/dist/types/wallet-server/src/router/framework/authServicePort.d.ts +1392 -0
  972. package/dist/types/wallet-server/src/router/framework/enforceRoutePolicy.d.ts +48 -0
  973. package/dist/types/wallet-server/src/router/framework/http.d.ts +12 -0
  974. package/dist/types/wallet-server/src/router/framework/logger.d.ts +5 -0
  975. package/dist/types/wallet-server/src/router/framework/modules.d.ts +17 -0
  976. package/dist/types/wallet-server/src/router/framework/ror/index.d.ts +7 -0
  977. package/dist/types/wallet-server/src/router/framework/ror/normalize.d.ts +14 -0
  978. package/dist/types/wallet-server/src/router/framework/ror/options.d.ts +9 -0
  979. package/dist/types/wallet-server/src/router/framework/ror/provider.d.ts +17 -0
  980. package/dist/types/wallet-server/src/router/framework/ror/staticProvider.d.ts +11 -0
  981. package/dist/types/wallet-server/src/router/framework/routeAuthPolicy.d.ts +34 -0
  982. package/dist/types/wallet-server/src/router/framework/routeDefinitions.d.ts +27 -0
  983. package/dist/types/wallet-server/src/router/framework/routeDefinitions.typecheck.d.ts +2 -0
  984. package/dist/types/wallet-server/src/router/framework/routeExecutionContext.d.ts +29 -0
  985. package/dist/types/wallet-server/src/router/framework/routeExtensions.d.ts +27 -0
  986. package/dist/types/wallet-server/src/router/framework/routeMeteringPolicy.d.ts +17 -0
  987. package/dist/types/wallet-server/src/router/framework/routeRequestValidation.d.ts +5 -0
  988. package/dist/types/wallet-server/src/router/framework/routeResponses.d.ts +17 -0
  989. package/dist/types/wallet-server/src/router/framework/routerApi.d.ts +221 -0
  990. package/dist/types/wallet-server/src/router/framework/routerApiRouteSurface.d.ts +14 -0
  991. package/dist/types/wallet-server/src/router/framework/routerApiWebhooks.d.ts +12 -0
  992. package/dist/types/wallet-server/src/router/framework/runtimeSnapshotConsumer.d.ts +28 -0
  993. package/dist/types/wallet-server/src/router/framework/versionedJsonRecordStore.d.ts +20 -0
  994. package/dist/types/wallet-server/src/router/ror-adaptor.d.ts +3 -0
  995. package/dist/types/wallet-server/src/router/transport/fetch/createFetchRouter.d.ts +8 -0
  996. package/dist/types/wallet-server/src/router/transport/fetch/fetchRouter.types.d.ts +23 -0
  997. package/dist/types/wallet-server/src/router/transport/fetch/routes/auth.d.ts +3 -0
  998. package/dist/types/wallet-server/src/router/transport/fetch/routes/deviceLinking.d.ts +202 -0
  999. package/dist/types/wallet-server/src/router/transport/fetch/routes/deviceLinkingOwnerAuthorization.d.ts +92 -0
  1000. package/dist/types/wallet-server/src/router/transport/fetch/routes/deviceManagement.d.ts +29 -0
  1001. package/dist/types/wallet-server/src/router/transport/fetch/routes/health.d.ts +4 -0
  1002. package/dist/types/wallet-server/src/router/transport/fetch/routes/nearPublicKeys.d.ts +3 -0
  1003. package/dist/types/wallet-server/src/router/transport/fetch/routes/normalSigningRouterProxy.d.ts +33 -0
  1004. package/dist/types/wallet-server/src/router/transport/fetch/routes/passkeyCustody.d.ts +66 -0
  1005. package/dist/types/wallet-server/src/router/transport/fetch/routes/sessions.d.ts +31 -0
  1006. package/dist/types/wallet-server/src/router/transport/fetch/routes/syncAccount.d.ts +3 -0
  1007. package/dist/types/wallet-server/src/router/transport/fetch/routes/syncAccountBootstrap.d.ts +128 -0
  1008. package/dist/types/wallet-server/src/router/transport/fetch/routes/thresholdEcdsa.d.ts +87 -0
  1009. package/dist/types/wallet-server/src/router/transport/fetch/routes/thresholdEd25519.d.ts +47 -0
  1010. package/dist/types/wallet-server/src/router/transport/fetch/routes/walletExecutionLanePreflight.d.ts +4 -0
  1011. package/dist/types/wallet-server/src/router/transport/fetch/routes/walletRegistration.d.ts +3 -0
  1012. package/dist/types/wallet-server/src/router/transport/fetch/routes/webauthnAuthenticators.d.ts +3 -0
  1013. package/dist/types/wallet-server/src/router/transport/fetch/routes/wellKnown.d.ts +3 -0
  1014. package/dist/types/wallet-server/src/storage/d1Sql.d.ts +14 -0
  1015. package/dist/types/wallet-server/src/storage/tenantRoute.d.ts +136 -0
  1016. package/dist/types/wallet-server/src/storage/tenantRoute.typecheck.d.ts +2 -0
  1017. package/dist/types/wallet-server/src/tenant-root.d.ts +5 -0
  1018. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/crypto/cipher.d.ts +45 -0
  1019. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/crypto/shamir3PassWasm.d.ts +16 -0
  1020. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/guards/backends.d.ts +23 -0
  1021. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/guards/index.d.ts +46 -0
  1022. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/idempotency.d.ts +3 -0
  1023. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/idempotencyBackends.d.ts +24 -0
  1024. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/idempotencyRecords.d.ts +22 -0
  1025. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/index.d.ts +23 -0
  1026. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/observability/audit.d.ts +9 -0
  1027. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/options.d.ts +9 -0
  1028. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/routesOptions.d.ts +20 -0
  1029. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/service.d.ts +3 -0
  1030. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/signingSessionSeal.typecheck.d.ts +2 -0
  1031. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/signingSessionSeal.types.d.ts +148 -0
  1032. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/transport/express.d.ts +12 -0
  1033. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/transport/fetch.d.ts +13 -0
  1034. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/transport/shared.d.ts +24 -0
  1035. package/dist/types/wallet-server/src/threshold/statusCodes.d.ts +10 -0
  1036. package/dist/types/wallet-server/src/wasm/signer.d.ts +8 -0
  1037. package/migrations/d1-signer/0001_signer_d1_initial.sql +2486 -0
  1038. package/migrations/d1-signer/0002_signer_post_103_canonical_upgrade.sql +1576 -0
  1039. package/migrations/d1-signer/0003_r107_wallet_authorization.sql +299 -0
  1040. package/migrations/d1-signer/0004_remove_legacy_email_recovery.sql +14 -0
  1041. package/migrations/d1-signer/0005_r103p8_linked_owner_auth_bindings.sql +92 -0
  1042. package/migrations/d1-signer/0006_r103p8_linked_device_custody_transfers.sql +77 -0
  1043. package/migrations/d1-signer/0007_r103p8_wallet_session_auth_method_provenance.sql +18 -0
  1044. package/migrations/d1-signer/0008_r103p8_linked_device_session_cas_guard.sql +35 -0
  1045. package/migrations/d1-signer/0009_linked_device_email_otp.sql +405 -0
  1046. package/migrations/d1-signer/0010_linked_device_session_target_factor.sql +78 -0
  1047. package/migrations/d1-signer/0011_linked_device_ed25519_export_root.sql +9 -0
  1048. package/migrations/d1-signer/0012_versioned_json_cas_guard.sql +3 -0
  1049. package/migrations/d1-signer/0013_linked_device_export_authorization.sql +133 -0
  1050. package/migrations/d1-signer/0014_wallet_recovery_code_locators.sql +19 -0
  1051. package/migrations/d1-signer/0015_r103e_authority_baseline.sql +259 -0
  1052. package/migrations/d1-signer/0016_r103e_wallet_session_authorizations_v2.sql +133 -0
  1053. package/migrations/d1-signer/0017_r103e_link_session_state.sql +83 -0
  1054. package/migrations/d1-signer/0018_r103e_linked_device_authority_installations.sql +34 -0
  1055. package/migrations/d1-signer/0019_r103e_email_otp_device_methods.sql +3 -0
  1056. package/migrations/d1-signer/0020_r103e_wallet_session_operation_credentials.sql +12 -0
  1057. package/migrations/d1-signer/0021_linked_device_source_contribution_transcripts.sql +64 -0
  1058. package/migrations/d1-signer/0022_r109c_multi_auth_email_cardinality.sql +118 -0
  1059. package/migrations/d1-signer/0023_r109d_first_email_linked_device.sql +111 -0
  1060. package/migrations/d1-signer/0024_r103f_v2_authorized_operation_claim.sql +99 -0
  1061. package/migrations/d1-signer/0025_r109d_email_enrollment_wallet_cardinality.sql +57 -0
  1062. package/migrations/d1-signer/0026_r115_wallet_recovery_authority_provenance.sql +253 -0
  1063. package/migrations/d1-signer/0027_r115_email_otp_recovery_bootstrap.sql +90 -0
  1064. package/migrations/d1-signer/0028_r103f_phase1_additive_schema_bridge.sql +1119 -0
  1065. package/migrations/d1-signer/0029_r103f_phase0_registration_replay_tokens.sql +135 -0
  1066. package/migrations/d1-signer/0030_r103f_wallet_session_client_capability.sql +17 -0
  1067. package/migrations/d1-signer/0031_r103f_delete_registration_replay_tokens.sql +4 -0
  1068. package/migrations/d1-signer/0032_r103f_exact_authorized_operation_enforcement.sql +149 -0
  1069. package/migrations/d1-signer/0033_r103f_linked_delivery_recipient.sql +6 -0
  1070. package/migrations/d1-signer/0034_r103f_exact_wallet_session_cutover.sql +743 -0
  1071. package/migrations/d1-signer/0035_r103f_linked_delivery_acknowledgement_cleanup_window.sql +413 -0
  1072. package/package.json +132 -0
  1073. package/scripts/d1-local-migrate-signer.mjs +148 -0
  1074. package/src/README.md +75 -0
  1075. package/wrangler.local-hosted-wallet-gateway.toml +37 -0
@@ -0,0 +1,1820 @@
1
+ import { parseWalletAuthorityId } from "../../../../shared-ts/src/utils/domainIds.js";
2
+ import { CAPABILITY_KINDS, parseAuthorizationAuditEventId, parseAuthorizationGrantRef, parseAuthorizedOperationId, parseCapabilityId, parseCapabilityOperationId, parseCapabilityOperationRef, parseMpcWalletSigningQuotaId, parsePrincipalId, parseTenantId, parseWalletSessionAuthorizationId, parseWalletSessionId } from "../../../../shared-ts/src/authorization/capabilityKinds.js";
3
+ import { parseDigestB64u } from "../../../../shared-ts/src/utils/canonicalPrimitives.js";
4
+ import { buildCapabilityOperationEnvelope, computeCapabilityOperationFingerprintDigest, parseCapabilityOperationFingerprintDigest } from "../../../../shared-ts/src/authorization/operationFingerprint.js";
5
+ import { routerAbMpcMaterialActivationRefToWire, sameRouterAbMpcMaterialActivationRef } from "../../../../shared-ts/src/utils/routerAbNormalSigningIdentity.js";
6
+ import { buildActiveWalletSessionQuota, buildAuthorizedOperation, buildExactWalletSessionQuotaProjectionV1, computeAuthorizedOperationResultDigest, exactWalletSessionCapabilitySubjectsResolveAuthority, parseAuthorizedOperationReplayResponse, parseHostedWalletSessionCredentialId, parseSessionOrigin, parseWalletSessionAuthorizationV2, walletSessionAuthorizationV2RecordsEqual } from "../../../../authorization/domain.js";
7
+ import { d1ChangedRows, parseD1JsonColumn } from "../../../../storage/d1Sql.js";
8
+ import { D1WalletStore } from "../../../../core/d1WalletStore.js";
9
+ import { D1WalletAuthorityStore } from "../wallet/d1WalletAuthorityStore.js";
10
+ import { prepareD1WalletSessionAuthorityProjectionStatements } from "./walletSessionAuthorityProjection.js";
11
+ //#region src/router/cloudflare/d1/authorization/d1AuthorizationStore.ts
12
+ const ECDSA_SIGNER_MATCH = `
13
+ EXISTS (
14
+ SELECT 1
15
+ FROM wallet_signers AS signer
16
+ WHERE signer.namespace = ?
17
+ AND signer.org_id = ?
18
+ AND signer.project_id = ?
19
+ AND signer.env_id = ?
20
+ AND signer.wallet_id = ?
21
+ AND signer.signer_family = 'ecdsa'
22
+ AND json_extract(signer.record_json, '$.walletKey.publicCapability.material_activation.material_owner') = signer.wallet_id
23
+ AND json_extract(signer.record_json, '$.walletKey.keyHandle') = ?
24
+ AND json_extract(signer.record_json, '$.walletKey.publicCapability.material_activation.kind') = ?
25
+ AND json_extract(signer.record_json, '$.walletKey.publicCapability.material_activation.activation_id') = ?
26
+ AND json_extract(signer.record_json, '$.walletKey.publicCapability.material_activation.capability') = ?
27
+ AND json_extract(signer.record_json, '$.walletKey.publicCapability.material_activation.material_owner') = ?
28
+ AND json_extract(signer.record_json, '$.walletKey.publicCapability.material_activation.key_binding') = ?
29
+ AND json_extract(signer.record_json, '$.walletKey.publicCapability.material_activation.lifecycle_binding') = ?
30
+ AND json_extract(signer.record_json, '$.walletKey.publicCapability.material_activation.signing_worker') = ?
31
+ )`;
32
+ function ecdsaSignerMatchBindings(walletSignerScope, material) {
33
+ const activation = material.materialActivation;
34
+ return [
35
+ walletSignerScope.namespace,
36
+ walletSignerScope.orgId,
37
+ walletSignerScope.projectId,
38
+ walletSignerScope.envId,
39
+ material.walletId,
40
+ material.keyHandle,
41
+ activation.kind,
42
+ activation.activation_id,
43
+ activation.capability,
44
+ activation.material_owner,
45
+ activation.key_binding,
46
+ activation.lifecycle_binding,
47
+ activation.signing_worker
48
+ ];
49
+ }
50
+ const ACTIVE_V2_AUTHORITY_METHOD_EXISTS_SQL = `
51
+ EXISTS (
52
+ SELECT 1
53
+ FROM wallet_authorities AS authority
54
+ JOIN wallet_auth_methods AS auth_method
55
+ ON auth_method.namespace = authority.namespace
56
+ AND auth_method.org_id = authority.org_id
57
+ AND auth_method.project_id = authority.project_id
58
+ AND auth_method.env_id = authority.env_id
59
+ AND auth_method.wallet_authority_id = authority.authority_id
60
+ AND auth_method.wallet_id = authority.wallet_id
61
+ AND auth_method.wallet_auth_method_id = ?
62
+ AND auth_method.status = 'active'
63
+ WHERE authority.namespace = ?
64
+ AND authority.org_id = ?
65
+ AND authority.project_id = ?
66
+ AND authority.env_id = ?
67
+ AND authority.authority_id = ?
68
+ AND authority.wallet_id = ?
69
+ AND authority.lifecycle_state = 'active'
70
+ AND authority.authority_digest_b64u = ?
71
+ AND authority.revocation_epoch = ?
72
+ )`;
73
+ const ACTIVE_V2_HOSTED_PARENT_PROVENANCE_SQL = `
74
+ EXISTS (
75
+ SELECT 1
76
+ FROM wallet_authorities AS authority
77
+ JOIN wallet_auth_methods AS auth_method
78
+ ON auth_method.namespace = authority.namespace
79
+ AND auth_method.org_id = authority.org_id
80
+ AND auth_method.project_id = authority.project_id
81
+ AND auth_method.env_id = authority.env_id
82
+ AND auth_method.wallet_authority_id = authority.authority_id
83
+ AND auth_method.wallet_id = authority.wallet_id
84
+ AND auth_method.wallet_auth_method_id = session.wallet_auth_method_id
85
+ AND auth_method.status = 'active'
86
+ WHERE authority.namespace = session.namespace
87
+ AND authority.org_id = session.org_id
88
+ AND authority.project_id = session.project_id
89
+ AND authority.env_id = session.env_id
90
+ AND authority.authority_id = session.authority_id
91
+ AND authority.wallet_id = session.wallet_id
92
+ AND authority.lifecycle_state = 'active'
93
+ AND authority.authority_digest_b64u = session.authority_digest_b64u
94
+ AND authority.revocation_epoch = session.authority_revocation_epoch
95
+ )`;
96
+ function activeV2AuthorityMethodBindings(scope, session) {
97
+ return [
98
+ String(session.walletAuthMethodId),
99
+ scope.namespace,
100
+ scope.orgId,
101
+ scope.projectId,
102
+ scope.envId,
103
+ String(session.authorityId),
104
+ String(session.walletId),
105
+ String(session.authorityDigestB64u),
106
+ session.authorityRevocationEpoch
107
+ ];
108
+ }
109
+ var CloudflareD1AuthorizationStore = class {
110
+ constructor(options) {
111
+ this.getLinkedDeviceAuthorityReader = options.getLinkedDeviceAuthorityReader ?? (() => null);
112
+ this.database = options.database;
113
+ this.namespace = requireOpaqueString(options.namespace, "namespace");
114
+ this.walletSignerScope = {
115
+ namespace: requireOpaqueString(options.walletSignerScope.namespace, "walletSignerScope.namespace"),
116
+ orgId: requireOpaqueString(options.walletSignerScope.orgId, "walletSignerScope.orgId"),
117
+ projectId: requireOpaqueString(options.walletSignerScope.projectId, "walletSignerScope.projectId"),
118
+ envId: requireOpaqueString(options.walletSignerScope.envId, "walletSignerScope.envId")
119
+ };
120
+ this.walletAuthorityStore = new D1WalletAuthorityStore({
121
+ database: this.database,
122
+ scope: this.walletSignerScope,
123
+ ensureSchema: false
124
+ });
125
+ this.walletStore = new D1WalletStore({
126
+ database: this.database,
127
+ namespace: this.walletSignerScope.namespace,
128
+ orgId: this.walletSignerScope.orgId,
129
+ projectId: this.walletSignerScope.projectId,
130
+ envId: this.walletSignerScope.envId,
131
+ ensureSchema: false
132
+ });
133
+ }
134
+ async retireWalletSessionAuthorizationsForAuthMethod(input) {
135
+ await this.database.batch(this.prepareRetireWalletSessionAuthorizationsForAuthMethod(input));
136
+ }
137
+ prepareRetireWalletSessionAuthorizationsForAuthMethod(input) {
138
+ requirePositiveInteger(input.nowMs, "auth-method session retirement time");
139
+ const exhaustExactQuotas = this.database.prepare(`UPDATE authorization_wallet_session_quotas
140
+ SET remaining_uses = 0,
141
+ lifecycle_kind = 'exhausted'
142
+ WHERE namespace = ?
143
+ AND tenant_id = ?
144
+ AND lifecycle_kind = 'active'
145
+ AND quota_id IN (
146
+ SELECT quota_id
147
+ FROM wallet_session_authorizations_v2
148
+ WHERE namespace = ?
149
+ AND org_id = ?
150
+ AND project_id = ?
151
+ AND env_id = ?
152
+ AND tenant_id = ?
153
+ AND wallet_id = ?
154
+ AND wallet_auth_method_id = ?
155
+ AND retired_at_ms IS NULL
156
+ )`).bind(this.namespace, input.tenantId, this.namespace, this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, input.tenantId, input.walletId, input.walletAuthMethodId);
157
+ const retireExactSessions = this.database.prepare(`UPDATE wallet_session_authorizations_v2
158
+ SET retired_at_ms = MAX(issued_at_ms, ?)
159
+ WHERE namespace = ?
160
+ AND org_id = ?
161
+ AND project_id = ?
162
+ AND env_id = ?
163
+ AND tenant_id = ?
164
+ AND wallet_id = ?
165
+ AND wallet_auth_method_id = ?
166
+ AND retired_at_ms IS NULL`).bind(input.nowMs, this.namespace, this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, input.tenantId, input.walletId, input.walletAuthMethodId);
167
+ const [deleteHostedExchanges, retireHostedCredentials] = this.prepareRetireHostedChildrenForParentSelection({
168
+ tenantId: input.tenantId,
169
+ nowMs: input.nowMs,
170
+ parentSelectionSql: `
171
+ predecessor.wallet_id = ?
172
+ AND predecessor.wallet_auth_method_id = ?
173
+ AND predecessor.retired_at_ms IS NULL`,
174
+ parentSelectionBindings: [input.walletId, input.walletAuthMethodId]
175
+ });
176
+ return [
177
+ exhaustExactQuotas,
178
+ deleteHostedExchanges,
179
+ retireHostedCredentials,
180
+ retireExactSessions
181
+ ];
182
+ }
183
+ prepareRetireWalletSessionAuthorizationsV2ForAuthority(input) {
184
+ requirePositiveInteger(input.nowMs, "authority session revocation time");
185
+ const remainingMethodFilter = `
186
+ SELECT 1
187
+ FROM wallet_auth_methods AS remaining_method
188
+ WHERE remaining_method.namespace = ?
189
+ AND remaining_method.org_id = ?
190
+ AND remaining_method.project_id = ?
191
+ AND remaining_method.env_id = ?
192
+ AND remaining_method.wallet_id = ?
193
+ AND remaining_method.wallet_authority_id = ?
194
+ AND remaining_method.status = 'active'`;
195
+ const remainingMethodBindings = [
196
+ this.namespace,
197
+ this.walletSignerScope.orgId,
198
+ this.walletSignerScope.projectId,
199
+ this.walletSignerScope.envId,
200
+ input.walletId,
201
+ input.authorityId
202
+ ];
203
+ const exhaustExactQuotas = this.database.prepare(`UPDATE authorization_wallet_session_quotas
204
+ SET remaining_uses = 0,
205
+ lifecycle_kind = 'exhausted'
206
+ WHERE namespace = ?
207
+ AND tenant_id = ?
208
+ AND lifecycle_kind = 'active'
209
+ AND quota_id IN (
210
+ SELECT session.quota_id
211
+ FROM wallet_session_authorizations_v2 AS session
212
+ WHERE session.namespace = ?
213
+ AND session.org_id = ?
214
+ AND session.project_id = ?
215
+ AND session.env_id = ?
216
+ AND session.tenant_id = ?
217
+ AND session.wallet_id = ?
218
+ AND session.authority_id = ?
219
+ AND session.retired_at_ms IS NULL
220
+ AND NOT EXISTS (${remainingMethodFilter})
221
+ )`).bind(this.namespace, input.tenantId, this.namespace, this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, input.tenantId, input.walletId, input.authorityId, ...remainingMethodBindings);
222
+ const retireExactSessions = this.database.prepare(`UPDATE wallet_session_authorizations_v2
223
+ SET retired_at_ms = MAX(issued_at_ms, ?)
224
+ WHERE namespace = ?
225
+ AND org_id = ?
226
+ AND project_id = ?
227
+ AND env_id = ?
228
+ AND tenant_id = ?
229
+ AND wallet_id = ?
230
+ AND authority_id = ?
231
+ AND retired_at_ms IS NULL
232
+ AND NOT EXISTS (${remainingMethodFilter})`).bind(input.nowMs, this.namespace, this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, input.tenantId, input.walletId, input.authorityId, ...remainingMethodBindings);
233
+ const [deleteHostedExchanges, retireHostedCredentials] = this.prepareRetireHostedChildrenForParentSelection({
234
+ tenantId: input.tenantId,
235
+ nowMs: input.nowMs,
236
+ parentSelectionSql: `
237
+ predecessor.wallet_id = ?
238
+ AND predecessor.authority_id = ?
239
+ AND predecessor.retired_at_ms IS NULL
240
+ AND NOT EXISTS (${remainingMethodFilter})`,
241
+ parentSelectionBindings: [
242
+ input.walletId,
243
+ input.authorityId,
244
+ ...remainingMethodBindings
245
+ ]
246
+ });
247
+ return [
248
+ exhaustExactQuotas,
249
+ deleteHostedExchanges,
250
+ retireHostedCredentials,
251
+ retireExactSessions
252
+ ];
253
+ }
254
+ prepareRetireHostedChildrenForParentSelection(input) {
255
+ const parentIdentityJoin = `
256
+ predecessor.namespace = hosted.namespace
257
+ AND predecessor.org_id = hosted.org_id
258
+ AND predecessor.project_id = hosted.project_id
259
+ AND predecessor.env_id = hosted.env_id
260
+ AND predecessor.tenant_id = hosted.tenant_id
261
+ AND predecessor.authorization_id = hosted.authorization_id
262
+ AND predecessor.wallet_session_id = hosted.wallet_session_id
263
+ AND predecessor.quota_id = hosted.quota_id
264
+ AND predecessor.principal_id = hosted.principal_id
265
+ AND predecessor.wallet_id = hosted.wallet_id
266
+ AND predecessor.authority_id = hosted.authority_id
267
+ AND predecessor.wallet_auth_method_id = hosted.wallet_auth_method_id`;
268
+ const scopeBindings = [
269
+ this.namespace,
270
+ this.walletSignerScope.orgId,
271
+ this.walletSignerScope.projectId,
272
+ this.walletSignerScope.envId,
273
+ input.tenantId
274
+ ];
275
+ return [this.database.prepare(`DELETE FROM wallet_session_hosted_exchange_codes_v2 AS hosted
276
+ WHERE hosted.namespace = ?
277
+ AND hosted.org_id = ?
278
+ AND hosted.project_id = ?
279
+ AND hosted.env_id = ?
280
+ AND hosted.tenant_id = ?
281
+ AND hosted.lifecycle_kind = 'issued'
282
+ AND EXISTS (
283
+ SELECT 1
284
+ FROM wallet_session_authorizations_v2 AS predecessor
285
+ WHERE ${parentIdentityJoin}
286
+ AND ${input.parentSelectionSql}
287
+ )`).bind(...scopeBindings, ...input.parentSelectionBindings), this.database.prepare(`UPDATE wallet_session_hosted_credentials_v2 AS hosted
288
+ SET lifecycle_kind = 'retired',
289
+ retired_at_ms = MAX(hosted.issued_at_ms, ?)
290
+ WHERE hosted.namespace = ?
291
+ AND hosted.org_id = ?
292
+ AND hosted.project_id = ?
293
+ AND hosted.env_id = ?
294
+ AND hosted.tenant_id = ?
295
+ AND hosted.lifecycle_kind = 'active'
296
+ AND hosted.retired_at_ms IS NULL
297
+ AND EXISTS (
298
+ SELECT 1
299
+ FROM wallet_session_authorizations_v2 AS predecessor
300
+ WHERE ${parentIdentityJoin}
301
+ AND ${input.parentSelectionSql}
302
+ )`).bind(input.nowMs, ...scopeBindings, ...input.parentSelectionBindings)];
303
+ }
304
+ async putIssuedHostedWalletSeamsSessionExchange(exchange) {
305
+ if (exchange.kind !== "issued_hosted_wallet_session_exchange_v2") throw new Error("hosted-wallet exchange kind is invalid");
306
+ requireOneChangedRow(await this.database.prepare(`INSERT INTO wallet_session_hosted_exchange_codes_v2 (
307
+ namespace,
308
+ org_id,
309
+ project_id,
310
+ env_id,
311
+ tenant_id,
312
+ exchange_code_id,
313
+ authorization_id,
314
+ wallet_session_id,
315
+ quota_id,
316
+ principal_id,
317
+ wallet_id,
318
+ authority_id,
319
+ wallet_auth_method_id,
320
+ code_hash,
321
+ nonce_digest,
322
+ app_origin,
323
+ wallet_origin,
324
+ issued_at_ms,
325
+ expires_at_ms,
326
+ lifecycle_kind,
327
+ hosted_credential_id,
328
+ consumed_at_ms
329
+ )
330
+ SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'issued', NULL, NULL
331
+ FROM wallet_session_authorizations_v2 AS session
332
+ JOIN authorization_wallet_session_quotas AS quota
333
+ ON quota.namespace = session.namespace
334
+ AND quota.tenant_id = session.tenant_id
335
+ AND quota.quota_id = session.quota_id
336
+ AND quota.wallet_session_id = session.wallet_session_id
337
+ AND quota.principal_id = session.principal_id
338
+ WHERE session.namespace = ?
339
+ AND session.org_id = ?
340
+ AND session.project_id = ?
341
+ AND session.env_id = ?
342
+ AND session.tenant_id = ?
343
+ AND session.authorization_id = ?
344
+ AND session.wallet_session_id = ?
345
+ AND session.quota_id = ?
346
+ AND session.principal_id = ?
347
+ AND session.wallet_id = ?
348
+ AND session.authority_id = ?
349
+ AND session.wallet_auth_method_id = ?
350
+ AND session.operation_credential_hash IS NOT NULL
351
+ AND session.retired_at_ms IS NULL
352
+ AND session.expires_at_ms >= ?
353
+ AND quota.lifecycle_kind = 'active'
354
+ AND quota.remaining_uses > 0
355
+ AND quota.expires_at_ms >= ?
356
+ AND ${ACTIVE_V2_HOSTED_PARENT_PROVENANCE_SQL}`).bind(this.namespace, this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, exchange.tenantId, exchange.exchangeCodeId, exchange.authorizationId, exchange.walletSessionId, exchange.quotaId, exchange.principalId, exchange.walletId, exchange.authorityId, exchange.walletAuthMethodId, exchange.codeHash, exchange.nonceDigest, exchange.appOrigin, exchange.walletOrigin, requirePositiveInteger(exchange.issuedAtMs, "exchange.issuedAtMs"), requirePositiveInteger(exchange.expiresAtMs, "exchange.expiresAtMs"), this.namespace, this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, exchange.tenantId, exchange.authorizationId, exchange.walletSessionId, exchange.quotaId, exchange.principalId, exchange.walletId, exchange.authorityId, exchange.walletAuthMethodId, exchange.expiresAtMs, exchange.expiresAtMs).run(), "hosted-wallet Seams session exchange code");
357
+ }
358
+ async redeemHostedWalletSeamsSessionExchange(input) {
359
+ const current = await this.readHostedWalletExchangeV2(input.codeHash);
360
+ const rejected = classifyHostedWalletExchangeV2(current, input);
361
+ if (rejected) return rejected;
362
+ if (!current) throw new Error("hosted-wallet exchange disappeared");
363
+ try {
364
+ const insertCredential = this.database.prepare(`INSERT INTO wallet_session_hosted_credentials_v2 (
365
+ namespace,
366
+ org_id,
367
+ project_id,
368
+ env_id,
369
+ tenant_id,
370
+ hosted_credential_id,
371
+ authorization_id,
372
+ wallet_session_id,
373
+ quota_id,
374
+ principal_id,
375
+ wallet_id,
376
+ authority_id,
377
+ wallet_auth_method_id,
378
+ credential_digest_b64u,
379
+ app_origin,
380
+ wallet_origin,
381
+ issued_at_ms,
382
+ expires_at_ms,
383
+ lifecycle_kind,
384
+ retired_at_ms
385
+ )
386
+ SELECT exchange.namespace,
387
+ exchange.org_id,
388
+ exchange.project_id,
389
+ exchange.env_id,
390
+ exchange.tenant_id,
391
+ ?,
392
+ exchange.authorization_id,
393
+ exchange.wallet_session_id,
394
+ exchange.quota_id,
395
+ exchange.principal_id,
396
+ exchange.wallet_id,
397
+ exchange.authority_id,
398
+ exchange.wallet_auth_method_id,
399
+ ?,
400
+ exchange.app_origin,
401
+ exchange.wallet_origin,
402
+ exchange.issued_at_ms,
403
+ exchange.expires_at_ms,
404
+ 'active',
405
+ NULL
406
+ FROM wallet_session_hosted_exchange_codes_v2 AS exchange
407
+ JOIN wallet_session_authorizations_v2 AS session
408
+ ON session.namespace = exchange.namespace
409
+ AND session.org_id = exchange.org_id
410
+ AND session.project_id = exchange.project_id
411
+ AND session.env_id = exchange.env_id
412
+ AND session.tenant_id = exchange.tenant_id
413
+ AND session.authorization_id = exchange.authorization_id
414
+ AND session.wallet_session_id = exchange.wallet_session_id
415
+ AND session.quota_id = exchange.quota_id
416
+ AND session.principal_id = exchange.principal_id
417
+ AND session.wallet_id = exchange.wallet_id
418
+ AND session.authority_id = exchange.authority_id
419
+ AND session.wallet_auth_method_id = exchange.wallet_auth_method_id
420
+ JOIN authorization_wallet_session_quotas AS quota
421
+ ON quota.namespace = exchange.namespace
422
+ AND quota.tenant_id = exchange.tenant_id
423
+ AND quota.quota_id = exchange.quota_id
424
+ AND quota.wallet_session_id = exchange.wallet_session_id
425
+ AND quota.principal_id = exchange.principal_id
426
+ WHERE exchange.namespace = ?
427
+ AND exchange.org_id = ?
428
+ AND exchange.project_id = ?
429
+ AND exchange.env_id = ?
430
+ AND exchange.tenant_id = ?
431
+ AND exchange.code_hash = ?
432
+ AND exchange.nonce_digest = ?
433
+ AND exchange.app_origin = ?
434
+ AND exchange.wallet_origin = ?
435
+ AND exchange.lifecycle_kind = 'issued'
436
+ AND exchange.hosted_credential_id IS NULL
437
+ AND exchange.consumed_at_ms IS NULL
438
+ AND exchange.expires_at_ms > ?
439
+ AND session.operation_credential_hash IS NOT NULL
440
+ AND session.retired_at_ms IS NULL
441
+ AND session.expires_at_ms >= exchange.expires_at_ms
442
+ AND quota.lifecycle_kind = 'active'
443
+ AND quota.remaining_uses > 0
444
+ AND quota.expires_at_ms >= exchange.expires_at_ms
445
+ AND ${ACTIVE_V2_HOSTED_PARENT_PROVENANCE_SQL}`).bind(input.hostedCredentialId, input.tokenHash, this.namespace, this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, current.tenant_id, input.codeHash, input.nonceDigest, input.appOrigin, input.walletOrigin, requirePositiveInteger(input.redeemedAtMs, "exchange.redeemedAtMs"));
446
+ const updateStatement = this.database.prepare(`UPDATE wallet_session_hosted_exchange_codes_v2 AS exchange
447
+ SET lifecycle_kind = 'consumed',
448
+ hosted_credential_id = ?,
449
+ consumed_at_ms = ?
450
+ WHERE exchange.namespace = ?
451
+ AND exchange.org_id = ?
452
+ AND exchange.project_id = ?
453
+ AND exchange.env_id = ?
454
+ AND exchange.tenant_id = ?
455
+ AND exchange.code_hash = ?
456
+ AND exchange.nonce_digest = ?
457
+ AND exchange.app_origin = ?
458
+ AND exchange.wallet_origin = ?
459
+ AND exchange.lifecycle_kind = 'issued'
460
+ AND exchange.hosted_credential_id IS NULL
461
+ AND exchange.consumed_at_ms IS NULL
462
+ AND exchange.expires_at_ms > ?
463
+ AND EXISTS (
464
+ SELECT 1
465
+ FROM wallet_session_authorizations_v2 AS session
466
+ WHERE session.namespace = exchange.namespace
467
+ AND session.org_id = exchange.org_id
468
+ AND session.project_id = exchange.project_id
469
+ AND session.env_id = exchange.env_id
470
+ AND session.tenant_id = exchange.tenant_id
471
+ AND session.authorization_id = exchange.authorization_id
472
+ AND session.wallet_session_id = exchange.wallet_session_id
473
+ AND session.quota_id = exchange.quota_id
474
+ AND session.principal_id = exchange.principal_id
475
+ AND session.wallet_id = exchange.wallet_id
476
+ AND session.authority_id = exchange.authority_id
477
+ AND session.wallet_auth_method_id = exchange.wallet_auth_method_id
478
+ AND session.operation_credential_hash IS NOT NULL
479
+ AND session.retired_at_ms IS NULL
480
+ AND session.expires_at_ms >= exchange.expires_at_ms
481
+ AND session.expires_at_ms > ?
482
+ AND ${ACTIVE_V2_HOSTED_PARENT_PROVENANCE_SQL}
483
+ )
484
+ AND EXISTS (
485
+ SELECT 1
486
+ FROM authorization_wallet_session_quotas AS quota
487
+ WHERE quota.namespace = exchange.namespace
488
+ AND quota.tenant_id = exchange.tenant_id
489
+ AND quota.quota_id = exchange.quota_id
490
+ AND quota.wallet_session_id = exchange.wallet_session_id
491
+ AND quota.principal_id = exchange.principal_id
492
+ AND quota.lifecycle_kind = 'active'
493
+ AND quota.remaining_uses > 0
494
+ AND quota.expires_at_ms >= exchange.expires_at_ms
495
+ )
496
+ AND EXISTS (
497
+ SELECT 1
498
+ FROM wallet_session_hosted_credentials_v2 AS credential
499
+ WHERE credential.namespace = exchange.namespace
500
+ AND credential.org_id = exchange.org_id
501
+ AND credential.project_id = exchange.project_id
502
+ AND credential.env_id = exchange.env_id
503
+ AND credential.tenant_id = exchange.tenant_id
504
+ AND credential.hosted_credential_id = ?
505
+ AND credential.authorization_id = exchange.authorization_id
506
+ AND credential.wallet_session_id = exchange.wallet_session_id
507
+ AND credential.quota_id = exchange.quota_id
508
+ AND credential.principal_id = exchange.principal_id
509
+ AND credential.wallet_id = exchange.wallet_id
510
+ AND credential.authority_id = exchange.authority_id
511
+ AND credential.wallet_auth_method_id = exchange.wallet_auth_method_id
512
+ AND credential.credential_digest_b64u = ?
513
+ AND credential.lifecycle_kind = 'active'
514
+ AND credential.retired_at_ms IS NULL
515
+ AND credential.expires_at_ms >= exchange.expires_at_ms
516
+ )`).bind(input.hostedCredentialId, requirePositiveInteger(input.redeemedAtMs, "exchange.redeemedAtMs"), this.namespace, this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, current.tenant_id, input.codeHash, input.nonceDigest, input.appOrigin, input.walletOrigin, input.redeemedAtMs, input.redeemedAtMs, input.hostedCredentialId, input.tokenHash);
517
+ const deleteOrphanedCredential = this.database.prepare(`DELETE FROM wallet_session_hosted_credentials_v2 AS credential
518
+ WHERE credential.namespace = ?
519
+ AND credential.org_id = ?
520
+ AND credential.project_id = ?
521
+ AND credential.env_id = ?
522
+ AND credential.tenant_id = ?
523
+ AND credential.hosted_credential_id = ?
524
+ AND credential.authorization_id = ?
525
+ AND credential.wallet_session_id = ?
526
+ AND credential.quota_id = ?
527
+ AND credential.principal_id = ?
528
+ AND credential.wallet_id = ?
529
+ AND credential.authority_id = ?
530
+ AND credential.wallet_auth_method_id = ?
531
+ AND credential.credential_digest_b64u = ?
532
+ AND EXISTS (
533
+ SELECT 1
534
+ FROM wallet_session_hosted_exchange_codes_v2 AS exchange
535
+ WHERE exchange.namespace = credential.namespace
536
+ AND exchange.org_id = credential.org_id
537
+ AND exchange.project_id = credential.project_id
538
+ AND exchange.env_id = credential.env_id
539
+ AND exchange.tenant_id = credential.tenant_id
540
+ AND exchange.code_hash = ?
541
+ AND exchange.lifecycle_kind = 'issued'
542
+ AND exchange.hosted_credential_id IS NULL
543
+ AND exchange.consumed_at_ms IS NULL
544
+ )`).bind(this.namespace, this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, current.tenant_id, input.hostedCredentialId, current.authorization_id, current.wallet_session_id, current.quota_id, current.principal_id, current.wallet_id, current.authority_id, current.wallet_auth_method_id, input.tokenHash, input.codeHash);
545
+ const results = await this.database.batch([
546
+ insertCredential,
547
+ updateStatement,
548
+ deleteOrphanedCredential
549
+ ]);
550
+ const inserted = results[0];
551
+ const updated = results[1];
552
+ if (d1ChangedRows(inserted) !== 1 || d1ChangedRows(updated) !== 1) return classifyHostedWalletExchangeV2(await this.readHostedWalletExchangeV2(input.codeHash), input) ?? { kind: "wallet_session_unavailable" };
553
+ } catch {
554
+ return { kind: "wallet_session_unavailable" };
555
+ }
556
+ if (!current) throw new Error("hosted-wallet Seams session exchange disappeared");
557
+ return {
558
+ kind: "redeemed",
559
+ tenantId: requireParsed(current.tenant_id, parseTenantId, "exchange.tenantId"),
560
+ authorizationId: requireParsed(current.authorization_id, parseWalletSessionAuthorizationId, "exchange.authorizationId"),
561
+ walletSessionId: requireParsed(current.wallet_session_id, parseWalletSessionId, "exchange.walletSessionId"),
562
+ hostedCredentialId: parseHostedWalletSessionCredentialId(input.hostedCredentialId),
563
+ expiresAtMs: integerColumn(current.expires_at_ms, "exchange.expiresAtMs")
564
+ };
565
+ }
566
+ async readHostedWalletSessionOperationCredentialV2(input) {
567
+ const row = await this.database.prepare(`SELECT credential.hosted_credential_id,
568
+ credential.authorization_id,
569
+ credential.wallet_session_id,
570
+ credential.quota_id,
571
+ credential.principal_id,
572
+ credential.wallet_id,
573
+ credential.authority_id,
574
+ credential.wallet_auth_method_id,
575
+ credential.app_origin,
576
+ credential.wallet_origin,
577
+ credential.expires_at_ms,
578
+ credential.retired_at_ms,
579
+ session.record_json AS session_record_json,
580
+ session.retired_at_ms AS session_retired_at_ms,
581
+ session.expires_at_ms AS session_expires_at_ms,
582
+ session.operation_credential_hash AS session_operation_credential_hash,
583
+ quota.lifecycle_kind AS quota_lifecycle_kind,
584
+ quota.remaining_uses AS quota_remaining_uses,
585
+ quota.expires_at_ms AS quota_expires_at_ms
586
+ FROM wallet_session_hosted_credentials_v2 AS credential
587
+ LEFT JOIN wallet_session_authorizations_v2 AS session
588
+ ON session.namespace = credential.namespace
589
+ AND session.org_id = credential.org_id
590
+ AND session.project_id = credential.project_id
591
+ AND session.env_id = credential.env_id
592
+ AND session.tenant_id = credential.tenant_id
593
+ AND session.authorization_id = credential.authorization_id
594
+ AND session.wallet_session_id = credential.wallet_session_id
595
+ AND session.quota_id = credential.quota_id
596
+ AND session.principal_id = credential.principal_id
597
+ AND session.wallet_id = credential.wallet_id
598
+ AND session.authority_id = credential.authority_id
599
+ AND session.wallet_auth_method_id = credential.wallet_auth_method_id
600
+ LEFT JOIN authorization_wallet_session_quotas AS quota
601
+ ON quota.namespace = credential.namespace
602
+ AND quota.tenant_id = credential.tenant_id
603
+ AND quota.quota_id = credential.quota_id
604
+ AND quota.wallet_session_id = credential.wallet_session_id
605
+ AND quota.principal_id = credential.principal_id
606
+ WHERE credential.namespace = ?
607
+ AND credential.org_id = ?
608
+ AND credential.project_id = ?
609
+ AND credential.env_id = ?
610
+ AND credential.tenant_id = ?
611
+ AND credential.credential_digest_b64u = ?
612
+ AND credential.lifecycle_kind = 'active'
613
+ AND credential.retired_at_ms IS NULL
614
+ LIMIT 1`).bind(this.namespace, this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, input.tenantId, input.tokenHash).first();
615
+ if (!row) return null;
616
+ const appOrigin = parseSessionOrigin(row.app_origin);
617
+ const walletOrigin = parseSessionOrigin(row.wallet_origin);
618
+ if (walletOrigin !== input.requestOrigin) return null;
619
+ if (row.session_record_json === null || row.session_record_json === void 0 || row.session_operation_credential_hash === null || row.session_operation_credential_hash === void 0 || row.session_retired_at_ms !== null && row.session_retired_at_ms !== void 0 || row.credential_retired_at_ms !== null && row.credential_retired_at_ms !== void 0 || row.quota_lifecycle_kind !== "active" || integerColumn(row.quota_remaining_uses, "hosted credential quota remaining uses") <= 0 || integerColumn(row.expires_at_ms, "hosted credential expiry") <= input.nowMs || integerColumn(row.session_expires_at_ms, "hosted parent expiry") <= input.nowMs || integerColumn(row.session_expires_at_ms, "hosted parent expiry") < integerColumn(row.expires_at_ms, "hosted credential expiry") || integerColumn(row.quota_expires_at_ms, "hosted quota expiry") <= input.nowMs || integerColumn(row.quota_expires_at_ms, "hosted quota expiry") < integerColumn(row.expires_at_ms, "hosted credential expiry")) return null;
620
+ const expected = parseWalletSessionAuthorizationV2(parseD1JsonColumn(row.session_record_json));
621
+ let authorization;
622
+ try {
623
+ authorization = await this.readWalletSessionAuthorizationV2ByAuthorizationId({
624
+ expected,
625
+ nowMs: input.nowMs
626
+ });
627
+ } catch {
628
+ return null;
629
+ }
630
+ if (!authorization) return null;
631
+ return {
632
+ kind: "resolved_hosted_wallet_session_operation_credential_v2",
633
+ authorization,
634
+ hostedCredentialId: parseHostedWalletSessionCredentialId(row.hosted_credential_id),
635
+ appOrigin,
636
+ walletOrigin,
637
+ expiresAtMs: integerColumn(row.expires_at_ms, "hosted credential expiry")
638
+ };
639
+ }
640
+ async putVerifiedEvidenceSet(evidenceSet) {
641
+ if (d1ChangedRows(await this.database.prepare(`INSERT OR IGNORE INTO verified_wallet_operation_evidence_sets (
642
+ namespace,
643
+ tenant_id,
644
+ evidence_set_id,
645
+ principal_id,
646
+ wallet_id,
647
+ authority_digest,
648
+ request_origin,
649
+ audience,
650
+ evidence_set_digest,
651
+ evidence_json,
652
+ capability_kind,
653
+ operation_kind,
654
+ lane_digest,
655
+ intent_digest,
656
+ display_digest,
657
+ assurance,
658
+ verified_at_ms,
659
+ expires_at_ms
660
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).bind(this.namespace, evidenceSet.tenantId, evidenceSet.evidenceSetId, evidenceSet.principalId, evidenceSet.walletId, evidenceSet.authorityRef.authorityDigest, evidenceSet.requestOrigin, evidenceSet.audience, evidenceSet.evidenceSetDigest, JSON.stringify(evidenceSet.evidence), evidenceSet.operation.capabilityKind, evidenceSet.operation.operationKind, evidenceSet.laneDigest, evidenceSet.intentDigest, evidenceSet.displayDigest, evidenceSet.assurance, requirePositiveInteger(evidenceSet.verifiedAtMs, "evidenceSet.verifiedAtMs"), requirePositiveInteger(evidenceSet.expiresAtMs, "evidenceSet.expiresAtMs")).run()) > 1) throw new Error("verified wallet operation evidence set changed more than one row");
661
+ }
662
+ async consumeVerifiedOwnerProof(proof, consumedAtMs, consumptionScopeId) {
663
+ const consumedAt = requirePositiveInteger(consumedAtMs, "owner proof consumedAtMs");
664
+ const scopeId = consumptionScopeId.trim();
665
+ if (!scopeId) throw new Error("owner proof consumption scope is required");
666
+ if (proof.verifiedAtMs > consumedAt || proof.expiresAtMs <= consumedAt) throw new Error("owner proof is outside its verification window");
667
+ if (d1ChangedRows(await this.database.prepare(`INSERT OR IGNORE INTO verified_owner_proof_consumptions (
668
+ namespace,
669
+ tenant_id,
670
+ proof_id,
671
+ purpose,
672
+ method,
673
+ principal_id,
674
+ wallet_id,
675
+ authority_digest,
676
+ replay_identity,
677
+ consumption_scope_id,
678
+ consumed_at_ms
679
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).bind(this.namespace, proof.tenantId, proof.proofId, proof.purpose, proof.method, proof.principalId, proof.walletId, proof.authority.authorityDigest, proof.replayIdentity, scopeId, consumedAt).run()) === 1) return true;
680
+ const existing = await this.database.prepare(`SELECT
681
+ purpose,
682
+ method,
683
+ principal_id,
684
+ wallet_id,
685
+ authority_digest,
686
+ replay_identity,
687
+ consumption_scope_id
688
+ FROM verified_owner_proof_consumptions
689
+ WHERE namespace = ?
690
+ AND tenant_id = ?
691
+ AND proof_id = ?
692
+ AND replay_identity = ?`).bind(this.namespace, proof.tenantId, proof.proofId, proof.replayIdentity).first();
693
+ return existing?.purpose === proof.purpose && existing.method === proof.method && existing.principal_id === proof.principalId && existing.wallet_id === proof.walletId && existing.authority_digest === proof.authority.authorityDigest && existing.replay_identity === proof.replayIdentity && existing.consumption_scope_id === scopeId;
694
+ }
695
+ async commitDirectWalletSessionAuthorizationV2(input) {
696
+ return await this.commitDirectWalletSessionAuthorizationV2WithMode({
697
+ persisted: input.persisted,
698
+ mode: { kind: "strict" }
699
+ });
700
+ }
701
+ /** The service validates the committed winner against its caller-specific replay contract. */
702
+ async commitDirectReplayableWalletSessionAuthorizationV2(input) {
703
+ return await this.commitDirectWalletSessionAuthorizationV2WithMode({
704
+ persisted: input.persisted,
705
+ mode: { kind: "replayable" }
706
+ });
707
+ }
708
+ async commitDirectWalletSessionAuthorizationV2WithMode(input) {
709
+ const { persisted, mode } = input;
710
+ requireExactPersistedActiveWalletSessionAuthorizationV2(persisted);
711
+ const statements = this.prepareDirectWalletSessionAuthorizationV2Statements(persisted);
712
+ const results = await this.database.batch(statements);
713
+ if (results.length !== 6) throw new Error("Direct V2 Wallet Session transaction returned incomplete results");
714
+ const quotaResult = results[4];
715
+ const sessionResult = results[5];
716
+ if (!quotaResult || !sessionResult) throw new Error("Direct V2 Wallet Session transaction returned incomplete results");
717
+ const quotaChanges = d1ChangedRows(quotaResult);
718
+ const sessionChanges = d1ChangedRows(sessionResult);
719
+ if (quotaChanges !== sessionChanges) throw new Error("Direct V2 Wallet Session transaction persisted an incomplete identity");
720
+ const lookup = {
721
+ tenantId: persisted.session.tenantId,
722
+ principalId: persisted.session.principalId,
723
+ walletId: persisted.session.walletId,
724
+ authorityId: persisted.session.authorityId,
725
+ walletAuthMethodId: persisted.session.walletAuthMethodId,
726
+ mintId: persisted.session.mintId
727
+ };
728
+ const committed = await this.readWalletSessionAuthorizationV2ByMint(lookup);
729
+ if (!committed) throw new Error("Direct V2 Wallet Session authorization commit was not readable");
730
+ if (sessionChanges === 0) switch (mode.kind) {
731
+ case "strict": break;
732
+ case "replayable": return {
733
+ kind: "already_committed",
734
+ committed
735
+ };
736
+ default: return assertNeverDirectV2CommitMode(mode);
737
+ }
738
+ if (committed.session.walletSessionId !== persisted.session.walletSessionId) throw new Error("Direct V2 Wallet Session commit returned a different session identity");
739
+ if (committed.primaryOperationCredentialDigestB64u !== persisted.primaryOperationCredentialDigestB64u) throw new Error("Direct V2 Wallet Session commit returned a different credential digest");
740
+ if (sessionChanges === 0) return {
741
+ kind: "already_committed",
742
+ committed
743
+ };
744
+ if (sessionChanges !== 1) throw new Error("Direct V2 Wallet Session transaction changed more than one session");
745
+ return { kind: "inserted" };
746
+ }
747
+ /**
748
+ * Builds the one batch used by direct issuance. Every predecessor mutation
749
+ * is gated by the candidate identity check, so a same-mint replay leaves
750
+ * the committed session and its predecessor state untouched.
751
+ */
752
+ prepareDirectWalletSessionAuthorizationV2Statements(persisted) {
753
+ requireExactPersistedActiveWalletSessionAuthorizationV2(persisted);
754
+ const { session, quota, primaryOperationCredentialDigestB64u } = persisted;
755
+ const capabilitySubjectsJson = JSON.stringify(session.capabilitySubjects);
756
+ const recordJson = JSON.stringify(session);
757
+ if (!capabilitySubjectsJson || !recordJson) throw new Error("Direct V2 Wallet Session authorization serialization is required");
758
+ const availabilitySql = directV2IdentityAvailabilitySql();
759
+ const availabilityBindings = directV2IdentityAvailabilityBindings(this.namespace, this.walletSignerScope, session);
760
+ const sessionIdentityAvailabilitySql = directV2SessionIdentityAvailabilitySql();
761
+ const sessionIdentityAvailabilityBindings = directV2SessionIdentityAvailabilityBindings(this.namespace, this.walletSignerScope, session);
762
+ const retirePredecessorSessions = this.database.prepare(`UPDATE wallet_session_authorizations_v2
763
+ SET retired_at_ms = MAX(issued_at_ms, ?)
764
+ WHERE namespace = ?
765
+ AND org_id = ?
766
+ AND project_id = ?
767
+ AND env_id = ?
768
+ AND tenant_id = ?
769
+ AND wallet_id = ?
770
+ AND authority_id = ?
771
+ AND wallet_auth_method_id = ?
772
+ AND retired_at_ms IS NULL
773
+ AND mint_id != ?
774
+ AND ${availabilitySql}`).bind(requirePositiveInteger(session.createdAtMs, "Direct V2 issuance time"), this.namespace, this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, session.tenantId, String(session.walletId), String(session.authorityId), String(session.walletAuthMethodId), String(session.mintId), ...availabilityBindings);
775
+ const exhaustPredecessorQuotas = this.database.prepare(`UPDATE authorization_wallet_session_quotas
776
+ SET remaining_uses = 0,
777
+ lifecycle_kind = 'exhausted'
778
+ WHERE namespace = ?
779
+ AND tenant_id = ?
780
+ AND quota_id IN (
781
+ SELECT predecessor.quota_id
782
+ FROM wallet_session_authorizations_v2 AS predecessor
783
+ WHERE predecessor.namespace = ?
784
+ AND predecessor.org_id = ?
785
+ AND predecessor.project_id = ?
786
+ AND predecessor.env_id = ?
787
+ AND predecessor.tenant_id = ?
788
+ AND predecessor.wallet_id = ?
789
+ AND predecessor.authority_id = ?
790
+ AND predecessor.wallet_auth_method_id = ?
791
+ AND predecessor.mint_id != ?
792
+ AND predecessor.retired_at_ms IS NULL
793
+ )
794
+ AND ${availabilitySql}`).bind(this.namespace, session.tenantId, this.namespace, this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, session.tenantId, String(session.walletId), String(session.authorityId), String(session.walletAuthMethodId), String(session.mintId), ...availabilityBindings);
795
+ const quotaStatement = this.database.prepare(`INSERT OR IGNORE INTO authorization_wallet_session_quotas (
796
+ namespace,
797
+ tenant_id,
798
+ quota_id,
799
+ wallet_session_id,
800
+ principal_id,
801
+ remaining_uses,
802
+ lifecycle_kind,
803
+ expires_at_ms
804
+ )
805
+ SELECT ?, ?, ?, ?, ?, ?, 'active', ?
806
+ WHERE ${availabilitySql}
807
+ AND ${ACTIVE_V2_AUTHORITY_METHOD_EXISTS_SQL}`).bind(this.namespace, quota.tenantId, String(quota.quotaId), String(quota.walletSessionId), String(quota.principalId), requirePositiveInteger(quota.remainingUses, "Direct V2 quota.remainingUses"), requirePositiveInteger(quota.expiresAtMs, "Direct V2 quota.expiresAtMs"), ...availabilityBindings, ...activeV2AuthorityMethodBindings(this.walletSignerScope, session));
808
+ const sessionStatement = this.database.prepare(`INSERT OR IGNORE INTO wallet_session_authorizations_v2 (
809
+ namespace,
810
+ org_id,
811
+ project_id,
812
+ env_id,
813
+ tenant_id,
814
+ authorization_id,
815
+ mint_id,
816
+ wallet_session_id,
817
+ quota_id,
818
+ principal_id,
819
+ wallet_id,
820
+ authority_id,
821
+ wallet_auth_method_id,
822
+ authority_digest_b64u,
823
+ authority_revocation_epoch,
824
+ capability_subjects_json,
825
+ issued_at_ms,
826
+ expires_at_ms,
827
+ retired_at_ms,
828
+ record_json,
829
+ operation_credential_hash
830
+ )
831
+ SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NULL, ?, ?
832
+ WHERE ${sessionIdentityAvailabilitySql}
833
+ AND ${ACTIVE_V2_AUTHORITY_METHOD_EXISTS_SQL}
834
+ AND EXISTS (
835
+ SELECT 1
836
+ FROM authorization_wallet_session_quotas AS quota
837
+ WHERE quota.namespace = ?
838
+ AND quota.tenant_id = ?
839
+ AND quota.quota_id = ?
840
+ AND quota.wallet_session_id = ?
841
+ AND quota.principal_id = ?
842
+ AND quota.remaining_uses = ?
843
+ AND quota.lifecycle_kind = 'active'
844
+ AND quota.expires_at_ms = ?
845
+ )`).bind(this.namespace, this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, session.tenantId, String(session.authorizationId), String(session.mintId), String(session.walletSessionId), String(session.quotaId), String(session.principalId), String(session.walletId), String(session.authorityId), String(session.walletAuthMethodId), String(session.authorityDigestB64u), session.authorityRevocationEpoch, capabilitySubjectsJson, requirePositiveInteger(session.createdAtMs, "Direct V2 session.createdAtMs"), requirePositiveInteger(session.expiresAtMs, "Direct V2 session.expiresAtMs"), recordJson, String(primaryOperationCredentialDigestB64u), ...sessionIdentityAvailabilityBindings, ...activeV2AuthorityMethodBindings(this.walletSignerScope, session), this.namespace, quota.tenantId, String(quota.quotaId), String(quota.walletSessionId), String(quota.principalId), requirePositiveInteger(quota.remainingUses, "Direct V2 quota.remainingUses"), requirePositiveInteger(quota.expiresAtMs, "Direct V2 quota.expiresAtMs"));
846
+ const [deleteHostedExchanges, retireHostedCredentials] = this.prepareRetireHostedChildrenForParentSelection({
847
+ tenantId: session.tenantId,
848
+ nowMs: session.createdAtMs,
849
+ parentSelectionSql: `
850
+ predecessor.wallet_id = ?
851
+ AND predecessor.authority_id = ?
852
+ AND predecessor.wallet_auth_method_id = ?
853
+ AND predecessor.mint_id != ?
854
+ AND predecessor.retired_at_ms IS NULL`,
855
+ parentSelectionBindings: [
856
+ session.walletId,
857
+ session.authorityId,
858
+ session.walletAuthMethodId,
859
+ session.mintId
860
+ ]
861
+ });
862
+ return [
863
+ exhaustPredecessorQuotas,
864
+ deleteHostedExchanges,
865
+ retireHostedCredentials,
866
+ retirePredecessorSessions,
867
+ quotaStatement,
868
+ sessionStatement
869
+ ];
870
+ }
871
+ async replaceWalletSessionAuthorizationV2AuthorityProjection(input) {
872
+ requireExactWalletSessionAuthorizationV2Quota(input);
873
+ const statements = this.prepareWalletSessionAuthorizationV2AuthorityProjectionStatements({
874
+ session: input.session,
875
+ promotionAtMs: input.session.createdAtMs
876
+ });
877
+ const results = await this.database.batch(statements);
878
+ if (results.length !== statements.length) throw new Error("V2 Wallet Session authority projection transaction returned incomplete results");
879
+ const result = results.at(-1);
880
+ if (!result || d1ChangedRows(result) === 0) throw new Error("V2 Wallet Session authority projection was not replaced");
881
+ const persisted = await this.readWalletSessionAuthorizationV2ByAuthorizationId({
882
+ expected: input.session,
883
+ nowMs: input.session.createdAtMs
884
+ });
885
+ if (!persisted || persisted.quota.remainingUses !== input.quota.remainingUses) throw new Error("V2 Wallet Session authority projection was not replaced");
886
+ }
887
+ prepareWalletSessionAuthorizationV2AuthorityProjectionStatements(input) {
888
+ return prepareD1WalletSessionAuthorityProjectionStatements({
889
+ database: this.database,
890
+ scope: this.walletSignerScope,
891
+ projection: {
892
+ walletId: input.session.walletId,
893
+ authorityId: input.session.authorityId,
894
+ authorityDigestB64u: input.session.authorityDigestB64u,
895
+ authorityRevocationEpoch: input.session.authorityRevocationEpoch,
896
+ capabilitySubjects: input.session.capabilitySubjects,
897
+ promotionAtMs: input.promotionAtMs
898
+ }
899
+ });
900
+ }
901
+ async existingWalletSessionAuthorizationV2QuotaMatches(quota) {
902
+ const row = await this.database.prepare(`SELECT
903
+ tenant_id,
904
+ principal_id,
905
+ wallet_session_id,
906
+ quota_id,
907
+ remaining_uses,
908
+ lifecycle_kind,
909
+ expires_at_ms
910
+ FROM authorization_wallet_session_quotas
911
+ WHERE namespace = ?
912
+ AND tenant_id = ?
913
+ AND quota_id = ?
914
+ LIMIT 1`).bind(this.namespace, quota.tenantId, String(quota.quotaId)).first();
915
+ return row !== null && row.tenant_id === String(quota.tenantId) && row.principal_id === String(quota.principalId) && row.wallet_session_id === String(quota.walletSessionId) && row.quota_id === String(quota.quotaId) && row.lifecycle_kind === "active" && integerColumn(row.remaining_uses, "V2 quota.remainingUses") === quota.remainingUses && integerColumn(row.expires_at_ms, "V2 quota.expiresAtMs") === quota.expiresAtMs;
916
+ }
917
+ async readWalletSessionAuthorizationV2ByMint(input) {
918
+ const row = await this.database.prepare(`SELECT
919
+ record_json,
920
+ capability_subjects_json,
921
+ tenant_id,
922
+ authorization_id,
923
+ mint_id,
924
+ wallet_session_id,
925
+ quota_id,
926
+ principal_id,
927
+ wallet_id,
928
+ authority_id,
929
+ wallet_auth_method_id,
930
+ authority_digest_b64u,
931
+ authority_revocation_epoch,
932
+ issued_at_ms,
933
+ expires_at_ms,
934
+ retired_at_ms,
935
+ operation_credential_hash
936
+ FROM wallet_session_authorizations_v2
937
+ WHERE namespace = ?
938
+ AND org_id = ?
939
+ AND project_id = ?
940
+ AND env_id = ?
941
+ AND tenant_id = ?
942
+ AND principal_id = ?
943
+ AND wallet_id = ?
944
+ AND authority_id = ?
945
+ AND wallet_auth_method_id = ?
946
+ AND mint_id = ?
947
+ LIMIT 1`).bind(this.namespace, this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, input.tenantId, String(input.principalId), String(input.walletId), String(input.authorityId), String(input.walletAuthMethodId), String(input.mintId)).first();
948
+ if (!row) return null;
949
+ const session = parseWalletSessionAuthorizationV2(parseD1JsonColumn(row.record_json));
950
+ if (!walletSessionAuthorizationV2RowMatches({
951
+ session_tenant_id: row.tenant_id,
952
+ session_authorization_id: row.authorization_id,
953
+ session_mint_id: row.mint_id,
954
+ session_wallet_session_id: row.wallet_session_id,
955
+ session_quota_id: row.quota_id,
956
+ session_principal_id: row.principal_id,
957
+ session_wallet_id: row.wallet_id,
958
+ session_authority_id: row.authority_id,
959
+ session_wallet_auth_method_id: row.wallet_auth_method_id,
960
+ session_authority_digest_b64u: row.authority_digest_b64u,
961
+ session_authority_revocation_epoch: row.authority_revocation_epoch,
962
+ session_issued_at_ms: row.issued_at_ms,
963
+ session_expires_at_ms: row.expires_at_ms
964
+ }, session)) throw new Error("Stored V2 Wallet Session mint columns disagree with record");
965
+ if (!walletSessionAuthorizationV2RecordsEqual(parseWalletSessionAuthorizationV2WithSubjects({
966
+ session_tenant_id: row.tenant_id,
967
+ session_authorization_id: row.authorization_id,
968
+ session_mint_id: row.mint_id,
969
+ session_wallet_session_id: row.wallet_session_id,
970
+ session_quota_id: row.quota_id,
971
+ session_principal_id: row.principal_id,
972
+ session_wallet_id: row.wallet_id,
973
+ session_authority_id: row.authority_id,
974
+ session_wallet_auth_method_id: row.wallet_auth_method_id,
975
+ session_authority_digest_b64u: row.authority_digest_b64u,
976
+ session_authority_revocation_epoch: row.authority_revocation_epoch,
977
+ session_issued_at_ms: row.issued_at_ms,
978
+ session_expires_at_ms: row.expires_at_ms
979
+ }, parseD1JsonColumn(row.capability_subjects_json)), session)) throw new Error("Stored V2 Wallet Session mint subjects disagree with record");
980
+ if (session.tenantId !== input.tenantId || session.principalId !== input.principalId || session.walletId !== input.walletId || session.authorityId !== input.authorityId || session.walletAuthMethodId !== input.walletAuthMethodId || session.mintId !== input.mintId) throw new Error("Stored V2 Wallet Session mint identity does not match the request");
981
+ return {
982
+ kind: "committed",
983
+ session,
984
+ primaryOperationCredentialDigestB64u: parseDigestB64u(row.operation_credential_hash),
985
+ retiredAtMs: row.retired_at_ms === null || row.retired_at_ms === void 0 ? null : requirePositiveInteger(row.retired_at_ms, "V2 session.retiredAtMs")
986
+ };
987
+ }
988
+ async readWalletSessionAuthorizationV2ByAuthorizationId(input) {
989
+ return await this.readWalletSessionAuthorizationV2(input, "authorization_id");
990
+ }
991
+ async readWalletSessionAuthorizationV2ByIdentity(input) {
992
+ return await this.readWalletSessionAuthorizationV2({
993
+ identity: {
994
+ tenantId: input.tenantId,
995
+ walletId: input.walletId,
996
+ walletSessionId: input.walletSessionId,
997
+ authorizationId: input.authorizationId
998
+ },
999
+ nowMs: input.nowMs
1000
+ }, "authorization_id");
1001
+ }
1002
+ async readActiveWalletSessionAuthorizationV2ByIdentity(input) {
1003
+ const row = await this.database.prepare(`SELECT record_json, retired_at_ms
1004
+ FROM wallet_session_authorizations_v2
1005
+ WHERE namespace = ?
1006
+ AND org_id = ?
1007
+ AND project_id = ?
1008
+ AND env_id = ?
1009
+ AND tenant_id = ?
1010
+ AND wallet_id = ?
1011
+ AND wallet_session_id = ?
1012
+ AND authorization_id = ?
1013
+ LIMIT 1`).bind(this.namespace, this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, input.tenantId, input.walletId, input.walletSessionId, input.authorizationId).first();
1014
+ if (!row) return null;
1015
+ if (row.retired_at_ms !== null && row.retired_at_ms !== void 0) return null;
1016
+ const session = parseWalletSessionAuthorizationV2(parseD1JsonColumn(row.record_json));
1017
+ if (session.tenantId !== input.tenantId || session.walletId !== input.walletId || session.walletSessionId !== input.walletSessionId || session.authorizationId !== input.authorizationId) throw new Error("Stored V2 Wallet Session identity does not match the request");
1018
+ const nowMs = requirePositiveInteger(input.nowMs, "V2 authorization read time");
1019
+ return session.expiresAtMs > nowMs ? session : null;
1020
+ }
1021
+ async readWalletSessionAuthorizationV2ByOperationCredential(input) {
1022
+ return await this.readWalletSessionAuthorizationV2({
1023
+ operationCredentialHash: input.tokenHash,
1024
+ tenantId: input.tenantId,
1025
+ nowMs: input.nowMs
1026
+ }, "operation_credential_hash");
1027
+ }
1028
+ /**
1029
+ * Resolves one exact operation credential to the whole digest-free
1030
+ * authorization lifecycle. Every observed row returns typed data: expiry,
1031
+ * exhaustion, retirement, and an unavailable authority, method, or capability
1032
+ * are lifecycle states, not failures. Corrupt rows, columns disagreeing with
1033
+ * their record, and broken foreign-key identity still throw.
1034
+ */
1035
+ async readExactWalletSessionStatusByOperationCredential(input) {
1036
+ const nowMs = requirePositiveInteger(input.nowMs, "exact Wallet Session status time");
1037
+ const row = await this.readJoinedWalletSessionAuthorizationV2Row({
1038
+ lookupColumn: "operation_credential_hash",
1039
+ tenantId: input.tenantId,
1040
+ lookupValue: input.tokenHash
1041
+ });
1042
+ if (!row) return { kind: "missing" };
1043
+ const session = parseWalletSessionAuthorizationV2(parseD1JsonColumn(row.session_record_json));
1044
+ if (!walletSessionAuthorizationV2RowMatches(row, session)) throw new Error("Stored V2 Wallet Session authorization columns disagree with record");
1045
+ if (!walletSessionAuthorizationV2RecordsEqual(parseWalletSessionAuthorizationV2WithSubjects(row, parseD1JsonColumn(row.session_capability_subjects_json)), session)) throw new Error("Stored V2 Wallet Session capability subjects disagree with record");
1046
+ if (session.tenantId !== input.tenantId) throw new Error("Stored V2 Wallet Session tenant does not match the request");
1047
+ const quota = parseExactWalletSessionQuotaProjectionRow(row, session);
1048
+ if (session.expiresAtMs <= nowMs) return {
1049
+ kind: "expired",
1050
+ session,
1051
+ quota
1052
+ };
1053
+ if (row.session_retired_at_ms !== null && row.session_retired_at_ms !== void 0) return {
1054
+ kind: "retired",
1055
+ session,
1056
+ quota,
1057
+ retiredAtMs: requirePositiveInteger(row.session_retired_at_ms, "V2 session.retiredAtMs")
1058
+ };
1059
+ if (quota.lifecycle === "exhausted") return {
1060
+ kind: "exhausted",
1061
+ session,
1062
+ quota
1063
+ };
1064
+ if (row.authority_id === null || row.authority_id === void 0) return {
1065
+ kind: "authority_unavailable",
1066
+ session,
1067
+ quota
1068
+ };
1069
+ const authority = await this.readExactStatusAuthority(row);
1070
+ if (!authority) return {
1071
+ kind: "authority_unavailable",
1072
+ session,
1073
+ quota
1074
+ };
1075
+ if (authority.authorityId !== session.authorityId || authority.walletId !== session.walletId || authority.state !== row.authority_lifecycle_state || authority.authorityDigestB64u !== row.authority_digest_b64u || authority.revocationEpoch !== integerColumn(row.authority_revocation_epoch, "authority.revocationEpoch")) throw new Error("Stored V2 Wallet Session authority identity does not match the record");
1076
+ if (authority.authorityId !== session.authorityId || authority.walletId !== session.walletId || authority.authorityDigestB64u !== session.authorityDigestB64u || authority.revocationEpoch !== session.authorityRevocationEpoch || authority.state !== "active") return {
1077
+ kind: "authority_unavailable",
1078
+ session,
1079
+ quota
1080
+ };
1081
+ if (row.auth_method_id === null || row.auth_method_id === void 0) return {
1082
+ kind: "method_unavailable",
1083
+ session,
1084
+ quota
1085
+ };
1086
+ if (row.auth_method_id !== String(session.walletAuthMethodId) || row.auth_method_wallet_id !== String(session.walletId) || row.auth_method_authority_id !== String(session.authorityId)) throw new Error("Stored V2 Wallet Session auth method identity does not match the record");
1087
+ if (row.auth_method_status !== "active") return {
1088
+ kind: "method_unavailable",
1089
+ session,
1090
+ quota
1091
+ };
1092
+ if (!exactWalletSessionCapabilitySubjectsResolveAuthority({
1093
+ session,
1094
+ signerActivations: authority.signerActivations
1095
+ })) return {
1096
+ kind: "capability_unavailable",
1097
+ session,
1098
+ quota
1099
+ };
1100
+ if (!await this.exactWalletSessionCapabilitySubjectsResolveMaterial(session)) return {
1101
+ kind: "capability_unavailable",
1102
+ session,
1103
+ quota
1104
+ };
1105
+ return {
1106
+ kind: "active",
1107
+ session,
1108
+ quota
1109
+ };
1110
+ }
1111
+ async readExactStatusAuthority(row) {
1112
+ const authorityId = parseWalletAuthorityId(row.authority_id);
1113
+ if (!authorityId.ok) throw new Error("Stored V2 Wallet Session authority identity is invalid");
1114
+ return await this.walletAuthorityStore.readById(authorityId.value);
1115
+ }
1116
+ async exactWalletSessionCapabilitySubjectsResolveMaterial(session) {
1117
+ for (const subject of session.capabilitySubjects) switch (subject.kind) {
1118
+ case "sign":
1119
+ case "export_keys": {
1120
+ const materialActivation = routerAbMpcMaterialActivationRefToWire(subject.materialActivation);
1121
+ const signer = subject.keyFamily === "ed25519" ? await this.walletStore.getEd25519SignerByMaterialActivation({
1122
+ walletId: session.walletId,
1123
+ materialActivation
1124
+ }) : await this.walletStore.getEcdsaSignerByMaterialActivation({
1125
+ walletId: session.walletId,
1126
+ materialActivation
1127
+ });
1128
+ if (!signer) {
1129
+ if (!await this.readLinkedAuthorityMaterial(session.walletId, subject)) return false;
1130
+ break;
1131
+ }
1132
+ if (signer.walletId !== session.walletId) throw new Error("Stored wallet signer material identity does not match the session");
1133
+ break;
1134
+ }
1135
+ case "link_devices":
1136
+ case "revoke_devices": break;
1137
+ default: return false;
1138
+ }
1139
+ return true;
1140
+ }
1141
+ async readLinkedAuthorityMaterial(walletId, subject) {
1142
+ const reader = this.getLinkedDeviceAuthorityReader();
1143
+ if (!reader) return null;
1144
+ const projection = subject.keyFamily === "ed25519" ? await reader.readInstalledEd25519AuthorityByMaterialActivationV1({
1145
+ walletId,
1146
+ materialActivation: subject.materialActivation
1147
+ }) : await reader.readInstalledEcdsaAuthorityByMaterialActivationV1({
1148
+ walletId,
1149
+ materialActivation: subject.materialActivation
1150
+ });
1151
+ if (!projection) return null;
1152
+ if (projection.walletId !== String(walletId)) throw new Error("Installed linked authority material identity does not match the session");
1153
+ if (!sameRouterAbMpcMaterialActivationRef(routerAbMpcMaterialActivationRefToWire(projection.materialActivation), routerAbMpcMaterialActivationRefToWire(subject.materialActivation))) throw new Error("Installed linked authority material does not match the session subject");
1154
+ return projection;
1155
+ }
1156
+ async readJoinedWalletSessionAuthorizationV2Row(input) {
1157
+ return await this.database.prepare(`SELECT
1158
+ session.record_json AS session_record_json,
1159
+ session.capability_subjects_json AS session_capability_subjects_json,
1160
+ session.tenant_id AS session_tenant_id,
1161
+ session.authorization_id AS session_authorization_id,
1162
+ session.mint_id AS session_mint_id,
1163
+ session.wallet_session_id AS session_wallet_session_id,
1164
+ session.quota_id AS session_quota_id,
1165
+ session.principal_id AS session_principal_id,
1166
+ session.wallet_id AS session_wallet_id,
1167
+ session.authority_id AS session_authority_id,
1168
+ session.wallet_auth_method_id AS session_wallet_auth_method_id,
1169
+ session.authority_digest_b64u AS session_authority_digest_b64u,
1170
+ session.authority_revocation_epoch AS session_authority_revocation_epoch,
1171
+ session.issued_at_ms AS session_issued_at_ms,
1172
+ session.expires_at_ms AS session_expires_at_ms,
1173
+ session.retired_at_ms AS session_retired_at_ms,
1174
+ authority.authority_id AS authority_id,
1175
+ authority.wallet_id AS authority_wallet_id,
1176
+ authority.lifecycle_state AS authority_lifecycle_state,
1177
+ authority.authority_digest_b64u AS authority_digest_b64u,
1178
+ authority.revocation_epoch AS authority_revocation_epoch,
1179
+ authority.signer_activations_json AS authority_signer_activations_json,
1180
+ auth_method.wallet_auth_method_id AS auth_method_id,
1181
+ auth_method.wallet_id AS auth_method_wallet_id,
1182
+ auth_method.wallet_authority_id AS auth_method_authority_id,
1183
+ auth_method.status AS auth_method_status,
1184
+ quota.tenant_id AS quota_tenant_id,
1185
+ quota.principal_id AS quota_principal_id,
1186
+ quota.wallet_session_id AS quota_wallet_session_id,
1187
+ quota.quota_id AS quota_id,
1188
+ quota.remaining_uses AS quota_remaining_uses,
1189
+ quota.lifecycle_kind AS quota_lifecycle_kind,
1190
+ quota.expires_at_ms AS quota_expires_at_ms
1191
+ FROM wallet_session_authorizations_v2 AS session
1192
+ LEFT JOIN wallet_authorities AS authority
1193
+ ON authority.namespace = session.namespace
1194
+ AND authority.org_id = ?
1195
+ AND authority.project_id = ?
1196
+ AND authority.env_id = ?
1197
+ AND authority.authority_id = session.authority_id
1198
+ AND authority.wallet_id = session.wallet_id
1199
+ LEFT JOIN wallet_auth_methods AS auth_method
1200
+ ON auth_method.namespace = session.namespace
1201
+ AND auth_method.org_id = ?
1202
+ AND auth_method.project_id = ?
1203
+ AND auth_method.env_id = ?
1204
+ AND auth_method.wallet_auth_method_id = session.wallet_auth_method_id
1205
+ AND auth_method.wallet_id = session.wallet_id
1206
+ AND auth_method.wallet_authority_id = session.authority_id
1207
+ LEFT JOIN authorization_wallet_session_quotas AS quota
1208
+ ON quota.namespace = session.namespace
1209
+ AND quota.tenant_id = session.tenant_id
1210
+ AND quota.quota_id = session.quota_id
1211
+ WHERE session.namespace = ?
1212
+ AND session.org_id = ?
1213
+ AND session.project_id = ?
1214
+ AND session.env_id = ?
1215
+ AND session.tenant_id = ?
1216
+ AND session.${input.lookupColumn} = ?
1217
+ LIMIT 1`).bind(this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, this.namespace, this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, input.tenantId, input.lookupValue).first();
1218
+ }
1219
+ async readWalletSessionAuthorizationV2(input, lookupColumn) {
1220
+ const lookup = "expected" in input ? input.expected : "identity" in input ? input.identity : null;
1221
+ const operationCredentialHash = "operationCredentialHash" in input ? input.operationCredentialHash : null;
1222
+ const row = await this.readJoinedWalletSessionAuthorizationV2Row({
1223
+ lookupColumn,
1224
+ tenantId: "operationCredentialHash" in input ? input.tenantId : lookup?.tenantId,
1225
+ lookupValue: lookupColumn === "mint_id" ? String("expected" in input ? input.expected.mintId : lookup?.authorizationId) : lookupColumn === "authorization_id" ? String(lookup?.authorizationId) : operationCredentialHash
1226
+ });
1227
+ if (!row) return null;
1228
+ if (row.session_retired_at_ms !== null && row.session_retired_at_ms !== void 0) throw new Error("Stored V2 Wallet Session authorization is retired");
1229
+ const session = parseWalletSessionAuthorizationV2(parseD1JsonColumn(row.session_record_json));
1230
+ if (!walletSessionAuthorizationV2RowMatches(row, session)) throw new Error("Stored V2 Wallet Session authorization columns disagree with record");
1231
+ if (!walletSessionAuthorizationV2RecordsEqual(parseWalletSessionAuthorizationV2WithSubjects(row, parseD1JsonColumn(row.session_capability_subjects_json)), session)) throw new Error("Stored V2 Wallet Session capability subjects disagree with record");
1232
+ if (row.authority_id !== String(session.authorityId) || row.authority_wallet_id !== String(session.walletId) || row.authority_lifecycle_state !== "active" || row.authority_digest_b64u !== String(session.authorityDigestB64u) || integerColumn(row.authority_revocation_epoch, "authority.revocationEpoch") !== session.authorityRevocationEpoch || row.auth_method_id !== String(session.walletAuthMethodId) || row.auth_method_wallet_id !== String(session.walletId) || row.auth_method_authority_id !== String(session.authorityId) || row.auth_method_status !== "active") throw new Error("Stored V2 Wallet Session authority provenance is no longer active");
1233
+ if ("identity" in input && (session.walletId !== input.identity.walletId || session.walletSessionId !== input.identity.walletSessionId || session.authorizationId !== input.identity.authorizationId)) throw new Error("Stored V2 Wallet Session identity does not match the request");
1234
+ if ("expected" in input && !walletSessionAuthorizationV2RecordsEqual(session, input.expected)) throw new Error("Stored V2 Wallet Session authorization replay does not match");
1235
+ const nowMs = requirePositiveInteger(input.nowMs, "V2 authorization read time");
1236
+ if (session.expiresAtMs <= nowMs) throw new Error("Stored V2 Wallet Session authorization has expired");
1237
+ return {
1238
+ session,
1239
+ quota: parseWalletSessionAuthorizationV2QuotaRow(row, session)
1240
+ };
1241
+ }
1242
+ async readAuthorizedOperation(input) {
1243
+ return (await this.readAuthorizedOperationRecord(input))?.operation ?? null;
1244
+ }
1245
+ async readAuthorizedOperationById(input) {
1246
+ const row = await this.database.prepare(`SELECT * FROM authorized_operations
1247
+ WHERE namespace = ? AND tenant_id = ? AND authorized_operation_id = ?
1248
+ LIMIT 1`).bind(this.namespace, input.tenantId, input.authorizedOperationId).first();
1249
+ return row ? await parseAuthorizedOperationRow(row) : null;
1250
+ }
1251
+ async readAuthorizedOperationRecord(input) {
1252
+ const row = await this.database.prepare(`SELECT * FROM authorized_operations
1253
+ WHERE namespace = ? AND tenant_id = ? AND operation_fingerprint_digest = ?
1254
+ LIMIT 1`).bind(this.namespace, input.tenantId, input.operationFingerprintDigest).first();
1255
+ return row ? {
1256
+ row,
1257
+ operation: await parseAuthorizedOperationRow(row)
1258
+ } : null;
1259
+ }
1260
+ async admitAuthorizedOperation(input) {
1261
+ const operation = await buildAuthorizedOperation(input.operation);
1262
+ if (operation.operation.operation.capabilityKind === CAPABILITY_KINDS.evmEcdsaMpcSigning && !input.material) return { kind: "material_mismatch" };
1263
+ if (input.material && input.material.kind === "ecdsa_material_activation" && (operation.operation.operation.capabilityKind !== CAPABILITY_KINDS.evmEcdsaMpcSigning || input.material.runtimePolicyScope.orgId !== operation.tenantId || input.material.materialActivation.capability !== operation.operation.capabilityId || input.material.materialActivation.material_owner !== input.material.walletId)) return { kind: "material_mismatch" };
1264
+ const existing = await this.readAuthorizedOperationRecord({
1265
+ tenantId: operation.tenantId,
1266
+ operationFingerprintDigest: operation.operationFingerprintDigest
1267
+ });
1268
+ if (existing) {
1269
+ const replayMismatch = authorizedOperationReplayMismatch({
1270
+ existing: existing.row,
1271
+ incoming: operation,
1272
+ material: input.material,
1273
+ scope: this.walletSignerScope
1274
+ });
1275
+ if (replayMismatch) return replayMismatch;
1276
+ if (existing.operation.lifecycle === "completed") {
1277
+ if (existing.operation.authorization.kind === "authorization_grant" && !await this.isAuthorizedOperationSourceActive(existing.row, operation.claimedAtMs)) return { kind: "authorization_grant_rejected" };
1278
+ return {
1279
+ kind: "replayed",
1280
+ operation: existing.operation
1281
+ };
1282
+ }
1283
+ if (!await this.isAuthorizedOperationSourceActive(existing.row, operation.claimedAtMs)) return authorizationSourceRejected(operation.authorization);
1284
+ return {
1285
+ kind: "operation_in_progress",
1286
+ operation: existing.operation
1287
+ };
1288
+ }
1289
+ const source = operation.authorization;
1290
+ const quota = operation.quota;
1291
+ const materialActivationId = input.material?.materialActivation.activation_id ?? null;
1292
+ try {
1293
+ const values = [
1294
+ this.namespace,
1295
+ operation.tenantId,
1296
+ operation.authorizedOperationId,
1297
+ operation.auditEventId,
1298
+ operation.operation.principalId,
1299
+ operation.operation.capabilityId,
1300
+ operation.operation.operation.capabilityKind,
1301
+ operation.operation.operation.operationKind,
1302
+ operation.operation.operationId,
1303
+ operation.operationFingerprintDigest,
1304
+ operation.operation.digests.laneDigest,
1305
+ operation.operation.digests.intentDigest,
1306
+ operation.operation.digests.displayDigest,
1307
+ source.kind,
1308
+ source.kind === "authorization_grant" ? source.authorizationGrantRef.authorizationId : null,
1309
+ source.kind === "verified_step_up" ? source.evidenceSetDigest : null,
1310
+ quota.kind === "consume_reusable_wallet_session" ? quota.quotaId : null,
1311
+ quota.kind,
1312
+ source.kind === "authorization_grant" ? source.authorizationGrantRef.kind : null,
1313
+ requirePositiveInteger(input.operation.claimedAtMs, "operation.claimedAtMs"),
1314
+ materialActivationId,
1315
+ input.material?.materialActivation.capability ?? null,
1316
+ input.material?.materialActivation.material_owner ?? null,
1317
+ input.material?.materialActivation.key_binding ?? null,
1318
+ input.material?.materialActivation.lifecycle_binding ?? null,
1319
+ input.material?.materialActivation.signing_worker ?? null,
1320
+ null,
1321
+ null,
1322
+ null,
1323
+ null,
1324
+ null,
1325
+ null,
1326
+ null,
1327
+ source.kind === "authorization_grant" ? this.walletSignerScope.orgId : null,
1328
+ source.kind === "authorization_grant" ? this.walletSignerScope.projectId : null,
1329
+ source.kind === "authorization_grant" ? this.walletSignerScope.envId : null
1330
+ ];
1331
+ const result = await (input.material?.kind === "ecdsa_material_activation" ? this.database.prepare(`INSERT INTO authorized_operations (
1332
+ namespace, tenant_id, authorized_operation_id, audit_event_id,
1333
+ principal_id, capability_id, capability_kind, operation_kind, operation_id,
1334
+ operation_fingerprint_digest, lane_digest, intent_digest, display_digest,
1335
+ authorization_source_kind, authorization_id, evidence_set_digest,
1336
+ quota_id, quota_kind, authorization_grant_kind, lifecycle_kind, result_kind,
1337
+ result_digest, result_status, result_content_type, result_body_text,
1338
+ claimed_at_ms, completed_at_ms,
1339
+ material_activation_id, material_activation_capability,
1340
+ material_activation_owner, material_activation_key_binding,
1341
+ material_activation_lifecycle_binding, material_activation_signing_worker,
1342
+ linked_wallet_id, linked_enrollment_id, linked_device_id,
1343
+ linked_wallet_key_id, linked_lane_id, linked_lane_share_epoch,
1344
+ linked_revocation_epoch, linked_scope_org_id, linked_scope_project_id,
1345
+ linked_scope_env_id
1346
+ ) SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
1347
+ 'claimed', 'pending', NULL, NULL, NULL, NULL, ?, NULL, ?,
1348
+ ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
1349
+ WHERE ${ECDSA_SIGNER_MATCH}`).bind(...values, ...ecdsaSignerMatchBindings(this.walletSignerScope, input.material)) : this.database.prepare(`INSERT INTO authorized_operations (
1350
+ namespace, tenant_id, authorized_operation_id, audit_event_id,
1351
+ principal_id, capability_id, capability_kind, operation_kind, operation_id,
1352
+ operation_fingerprint_digest, lane_digest, intent_digest, display_digest,
1353
+ authorization_source_kind, authorization_id, evidence_set_digest,
1354
+ quota_id, quota_kind, authorization_grant_kind, lifecycle_kind, result_kind,
1355
+ result_digest, result_status, result_content_type, result_body_text,
1356
+ claimed_at_ms, completed_at_ms,
1357
+ material_activation_id, material_activation_capability,
1358
+ material_activation_owner, material_activation_key_binding,
1359
+ material_activation_lifecycle_binding, material_activation_signing_worker,
1360
+ linked_wallet_id, linked_enrollment_id, linked_device_id,
1361
+ linked_wallet_key_id, linked_lane_id, linked_lane_share_epoch,
1362
+ linked_revocation_epoch, linked_scope_org_id, linked_scope_project_id,
1363
+ linked_scope_env_id
1364
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
1365
+ 'claimed', 'pending', NULL, NULL, NULL, NULL, ?, NULL, ?,
1366
+ ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).bind(...values)).run();
1367
+ if (input.material && d1ChangedRows(result) === 0) return { kind: "material_mismatch" };
1368
+ } catch (error) {
1369
+ const raced = await this.readAuthorizedOperationRecord({
1370
+ tenantId: operation.tenantId,
1371
+ operationFingerprintDigest: operation.operationFingerprintDigest
1372
+ });
1373
+ if (raced) {
1374
+ const replayMismatch = authorizedOperationReplayMismatch({
1375
+ existing: raced.row,
1376
+ incoming: operation,
1377
+ material: input.material,
1378
+ scope: this.walletSignerScope
1379
+ });
1380
+ if (replayMismatch) return replayMismatch;
1381
+ if (raced.operation.lifecycle === "completed") {
1382
+ if (raced.operation.authorization.kind === "authorization_grant" && !await this.isAuthorizedOperationSourceActive(raced.row, operation.claimedAtMs)) return { kind: "authorization_grant_rejected" };
1383
+ return {
1384
+ kind: "replayed",
1385
+ operation: raced.operation
1386
+ };
1387
+ }
1388
+ if (!await this.isAuthorizedOperationSourceActive(raced.row, operation.claimedAtMs)) return authorizationSourceRejected(operation.authorization);
1389
+ return {
1390
+ kind: "operation_in_progress",
1391
+ operation: raced.operation
1392
+ };
1393
+ }
1394
+ const triggerFailure = classifyAuthorizedOperationAdmissionError(error);
1395
+ if (triggerFailure) return triggerFailure;
1396
+ throw error;
1397
+ }
1398
+ const committed = await this.readAuthorizedOperationRecord({
1399
+ tenantId: operation.tenantId,
1400
+ operationFingerprintDigest: operation.operationFingerprintDigest
1401
+ });
1402
+ if (!committed) throw new Error("authorized operation admission could not be read back");
1403
+ return {
1404
+ kind: "claimed",
1405
+ operation: committed.operation
1406
+ };
1407
+ }
1408
+ async isAuthorizedOperationSourceActive(row, nowMs) {
1409
+ const sourceKind = requireString(row.authorization_source_kind, "operation.authorization.kind");
1410
+ if (sourceKind === "authorization_grant") {
1411
+ const scope = [
1412
+ row.linked_scope_org_id,
1413
+ row.linked_scope_project_id,
1414
+ row.linked_scope_env_id
1415
+ ];
1416
+ if (scope.some((value) => typeof value !== "string" || value.length === 0)) return false;
1417
+ if (scope[0] !== this.walletSignerScope.orgId || scope[1] !== this.walletSignerScope.projectId || scope[2] !== this.walletSignerScope.envId) return false;
1418
+ return await this.database.prepare(`SELECT 1 AS active
1419
+ FROM wallet_session_authorizations_v2 AS session
1420
+ JOIN wallet_authorities AS authority
1421
+ ON authority.namespace = session.namespace
1422
+ AND authority.org_id = session.org_id
1423
+ AND authority.project_id = session.project_id
1424
+ AND authority.env_id = session.env_id
1425
+ AND authority.authority_id = session.authority_id
1426
+ AND authority.wallet_id = session.wallet_id
1427
+ JOIN wallet_auth_methods AS auth_method
1428
+ ON auth_method.namespace = session.namespace
1429
+ AND auth_method.org_id = session.org_id
1430
+ AND auth_method.project_id = session.project_id
1431
+ AND auth_method.env_id = session.env_id
1432
+ AND auth_method.wallet_auth_method_id = session.wallet_auth_method_id
1433
+ AND auth_method.wallet_id = session.wallet_id
1434
+ AND auth_method.wallet_authority_id = session.authority_id
1435
+ WHERE session.namespace = ?
1436
+ AND session.org_id = ?
1437
+ AND session.project_id = ?
1438
+ AND session.env_id = ?
1439
+ AND session.tenant_id = ?
1440
+ AND session.authorization_id = ?
1441
+ AND session.principal_id = ?
1442
+ AND (? = 'quota_neutral' OR session.quota_id = ?)
1443
+ AND session.retired_at_ms IS NULL
1444
+ AND session.expires_at_ms > ?
1445
+ AND authority.lifecycle_state = 'active'
1446
+ AND authority.authority_digest_b64u = session.authority_digest_b64u
1447
+ AND authority.revocation_epoch = session.authority_revocation_epoch
1448
+ AND auth_method.status = 'active'
1449
+ LIMIT 1`).bind(this.namespace, ...scope, requireString(row.tenant_id, "operation.tenantId"), requireString(row.authorization_id, "operation.authorizationId"), requireString(row.principal_id, "operation.principalId"), requireString(row.quota_kind, "operation.quota.kind"), row.quota_id, requirePositiveInteger(nowMs, "operation replay time")).first() !== null;
1450
+ }
1451
+ if (sourceKind !== "verified_step_up") return false;
1452
+ const capabilityKind = requireString(row.capability_kind, "operation.capabilityKind");
1453
+ return await this.database.prepare(`SELECT 1 AS active
1454
+ FROM verified_wallet_operation_evidence_sets AS evidence
1455
+ WHERE evidence.namespace = ?
1456
+ AND evidence.tenant_id = ?
1457
+ AND evidence.evidence_set_digest = ?
1458
+ AND evidence.principal_id = ?
1459
+ AND evidence.capability_kind = ?
1460
+ AND evidence.operation_kind = ?
1461
+ AND evidence.lane_digest = ?
1462
+ AND evidence.intent_digest = ?
1463
+ AND evidence.display_digest = ?
1464
+ AND evidence.assurance = 'step_up'
1465
+ AND evidence.expires_at_ms > ?
1466
+ LIMIT 1`).bind(this.namespace, requireString(row.tenant_id, "operation.tenantId"), requireString(row.evidence_set_digest, "operation.evidenceSetDigest"), requireString(row.principal_id, "operation.principalId"), capabilityKind, requireString(row.operation_kind, "operation.operationKind"), requireString(row.lane_digest, "operation.laneDigest"), requireString(row.intent_digest, "operation.intentDigest"), requireString(row.display_digest, "operation.displayDigest"), requirePositiveInteger(nowMs, "operation replay time")).first() !== null;
1467
+ }
1468
+ async completeAuthorizedOperation(input) {
1469
+ const operation = input.operation;
1470
+ const response = parseAuthorizedOperationReplayResponse(input.response);
1471
+ const resultDigest = await computeAuthorizedOperationResultDigest(response);
1472
+ if (d1ChangedRows(await this.database.prepare(`UPDATE authorized_operations
1473
+ SET lifecycle_kind = 'completed', result_kind = ?, result_digest = ?,
1474
+ result_status = ?, result_content_type = ?, result_body_text = ?,
1475
+ completed_at_ms = ?
1476
+ WHERE namespace = ? AND tenant_id = ?
1477
+ AND authorized_operation_id = ? AND operation_fingerprint_digest = ?
1478
+ AND lifecycle_kind = 'claimed'`).bind(input.result, resultDigest, response.status, response.contentType, response.bodyText, requirePositiveInteger(input.completedAtMs, "operation.completedAtMs"), this.namespace, operation.tenantId, operation.authorizedOperationId, operation.operationFingerprintDigest).run()) === 0) {
1479
+ const existing = await this.readAuthorizedOperation({
1480
+ tenantId: operation.tenantId,
1481
+ operationFingerprintDigest: operation.operationFingerprintDigest
1482
+ });
1483
+ if (!existing) throw new Error("authorized operation completion claim is missing");
1484
+ return existing;
1485
+ }
1486
+ const completed = await this.readAuthorizedOperation({
1487
+ tenantId: operation.tenantId,
1488
+ operationFingerprintDigest: operation.operationFingerprintDigest
1489
+ });
1490
+ if (!completed) throw new Error("authorized operation completion could not be read back");
1491
+ return completed;
1492
+ }
1493
+ async readHostedWalletExchangeV2(codeHash) {
1494
+ return await this.database.prepare(`SELECT exchange.*,
1495
+ session.operation_credential_hash AS session_operation_credential_hash,
1496
+ session.retired_at_ms AS session_retired_at_ms,
1497
+ session.expires_at_ms AS session_expires_at_ms,
1498
+ quota.remaining_uses AS quota_remaining_uses,
1499
+ quota.lifecycle_kind AS quota_lifecycle_kind,
1500
+ quota.expires_at_ms AS quota_expires_at_ms
1501
+ FROM wallet_session_hosted_exchange_codes_v2 AS exchange
1502
+ LEFT JOIN wallet_session_authorizations_v2 AS session
1503
+ ON session.namespace = exchange.namespace
1504
+ AND session.org_id = exchange.org_id
1505
+ AND session.project_id = exchange.project_id
1506
+ AND session.env_id = exchange.env_id
1507
+ AND session.tenant_id = exchange.tenant_id
1508
+ AND session.authorization_id = exchange.authorization_id
1509
+ AND session.wallet_session_id = exchange.wallet_session_id
1510
+ AND session.quota_id = exchange.quota_id
1511
+ AND session.principal_id = exchange.principal_id
1512
+ AND session.wallet_id = exchange.wallet_id
1513
+ AND session.authority_id = exchange.authority_id
1514
+ AND session.wallet_auth_method_id = exchange.wallet_auth_method_id
1515
+ LEFT JOIN authorization_wallet_session_quotas AS quota
1516
+ ON quota.namespace = exchange.namespace
1517
+ AND quota.tenant_id = exchange.tenant_id
1518
+ AND quota.quota_id = exchange.quota_id
1519
+ AND quota.wallet_session_id = exchange.wallet_session_id
1520
+ AND quota.principal_id = exchange.principal_id
1521
+ WHERE exchange.namespace = ?
1522
+ AND exchange.org_id = ?
1523
+ AND exchange.project_id = ?
1524
+ AND exchange.env_id = ?
1525
+ AND exchange.code_hash = ?
1526
+ LIMIT 1`).bind(this.namespace, this.walletSignerScope.orgId, this.walletSignerScope.projectId, this.walletSignerScope.envId, codeHash).first();
1527
+ }
1528
+ };
1529
+ function classifyAuthorizedOperationAdmissionError(error) {
1530
+ const message = error instanceof Error ? error.message : String(error);
1531
+ if (message.includes("authorization_wallet_session_quota_rejected")) return { kind: "wallet_session_quota_exhausted" };
1532
+ if (message.includes("authorization_wallet_session_rejected")) return { kind: "authorization_grant_rejected" };
1533
+ if (message.includes("authorization_evidence_claim_rejected")) return { kind: "verified_step_up_rejected" };
1534
+ return null;
1535
+ }
1536
+ function authorizedOperationReplayMismatch(input) {
1537
+ if (requireString(input.existing.authorization_source_kind, "operation.authorization.kind") !== input.incoming.authorization.kind) return authorizationSourceRejected(input.incoming.authorization);
1538
+ if (input.incoming.authorization.kind === "authorization_grant") {
1539
+ if (input.existing.linked_scope_org_id !== input.scope.orgId || input.existing.linked_scope_project_id !== input.scope.projectId || input.existing.linked_scope_env_id !== input.scope.envId) return { kind: "authorization_grant_rejected" };
1540
+ const expectedGrantKind = input.incoming.authorization.authorizationGrantRef.kind;
1541
+ if (input.existing.authorization_grant_kind !== expectedGrantKind) return { kind: "authorization_grant_rejected" };
1542
+ if (input.existing.authorization_id !== input.incoming.authorization.authorizationGrantRef.authorizationId) return { kind: "authorization_grant_rejected" };
1543
+ } else if (input.existing.evidence_set_digest !== input.incoming.authorization.evidenceSetDigest) return { kind: "verified_step_up_rejected" };
1544
+ const existingQuotaKind = requireString(input.existing.quota_kind, "operation.quota.kind");
1545
+ if (existingQuotaKind !== input.incoming.quota.kind) return authorizationSourceRejected(input.incoming.authorization);
1546
+ if (existingQuotaKind === "consume_reusable_wallet_session" && input.existing.quota_id !== input.incoming.quota.quotaId) return { kind: "authorization_grant_rejected" };
1547
+ if (existingQuotaKind === "quota_neutral" && input.existing.quota_id !== null) return { kind: "authorization_grant_rejected" };
1548
+ if (!authorizedOperationMaterialMatches(input.existing, input.material)) return { kind: "material_mismatch" };
1549
+ return null;
1550
+ }
1551
+ function authorizedOperationMaterialMatches(existing, incoming) {
1552
+ const material = incoming?.materialActivation;
1553
+ return existing.material_activation_id === (material?.activation_id ?? null) && existing.material_activation_capability === (material?.capability ?? null) && existing.material_activation_owner === (material?.material_owner ?? null) && existing.material_activation_key_binding === (material?.key_binding ?? null) && existing.material_activation_lifecycle_binding === (material?.lifecycle_binding ?? null) && existing.material_activation_signing_worker === (material?.signing_worker ?? null);
1554
+ }
1555
+ function authorizationSourceRejected(source) {
1556
+ return source.kind === "verified_step_up" ? { kind: "verified_step_up_rejected" } : { kind: "authorization_grant_rejected" };
1557
+ }
1558
+ function classifyHostedWalletExchangeV2(row, input) {
1559
+ if (!row) return { kind: "invalid_code" };
1560
+ if (row.lifecycle_kind === "consumed") return { kind: "already_consumed" };
1561
+ if (row.lifecycle_kind !== "issued") return { kind: "invalid_code" };
1562
+ if (integerColumn(row.expires_at_ms, "exchange.expiresAtMs") <= input.redeemedAtMs) return { kind: "expired" };
1563
+ if (row.nonce_digest !== input.nonceDigest) return { kind: "nonce_mismatch" };
1564
+ if (row.app_origin !== input.appOrigin) return { kind: "app_origin_mismatch" };
1565
+ if (row.wallet_origin !== input.walletOrigin) return { kind: "wallet_origin_mismatch" };
1566
+ if (row.session_operation_credential_hash === null || row.session_operation_credential_hash === void 0 || row.session_retired_at_ms !== null && row.session_retired_at_ms !== void 0 || row.quota_lifecycle_kind !== "active" || integerColumn(row.quota_remaining_uses, "exchange.quotaRemainingUses") <= 0 || integerColumn(row.session_expires_at_ms, "exchange.sessionExpiresAtMs") <= input.redeemedAtMs || integerColumn(row.session_expires_at_ms, "exchange.sessionExpiresAtMs") < integerColumn(row.expires_at_ms, "exchange.expiresAtMs") || integerColumn(row.quota_expires_at_ms, "exchange.quotaExpiresAtMs") <= input.redeemedAtMs || integerColumn(row.quota_expires_at_ms, "exchange.quotaExpiresAtMs") < integerColumn(row.expires_at_ms, "exchange.expiresAtMs")) return { kind: "wallet_session_unavailable" };
1567
+ return null;
1568
+ }
1569
+ async function parseAuthorizedOperationRow(row) {
1570
+ const tenantId = requireParsed(row.tenant_id, parseTenantId, "operation.tenantId");
1571
+ const operation = buildCapabilityOperationEnvelope({
1572
+ tenantId,
1573
+ principalId: requireParsed(row.principal_id, parsePrincipalId, "operation.principalId"),
1574
+ capabilityId: requireParsed(row.capability_id, parseCapabilityId, "operation.capabilityId"),
1575
+ operationId: requireParsed(row.operation_id, parseCapabilityOperationId, "operation.operationId"),
1576
+ operation: requireParsed({
1577
+ capabilityKind: row.capability_kind,
1578
+ operationKind: row.operation_kind
1579
+ }, parseCapabilityOperationRef, "operation.operation"),
1580
+ digests: {
1581
+ laneDigest: parseDigestB64u(requireString(row.lane_digest, "operation.laneDigest")),
1582
+ intentDigest: parseDigestB64u(requireString(row.intent_digest, "operation.intentDigest")),
1583
+ displayDigest: parseDigestB64u(requireString(row.display_digest, "operation.displayDigest"))
1584
+ }
1585
+ });
1586
+ const sourceKind = requireString(row.authorization_source_kind, "operation.authorization.kind");
1587
+ let authorization;
1588
+ if (sourceKind === "authorization_grant") {
1589
+ if (row.evidence_set_digest != null) throw new Error("operation.authorization grant row cannot contain evidenceSetDigest");
1590
+ if (row.authorization_grant_kind !== "wallet_session_authorization") throw new Error("operation.authorization grant kind is invalid");
1591
+ authorization = {
1592
+ kind: "authorization_grant",
1593
+ authorizationGrantRef: requireParsed({
1594
+ kind: "wallet_session_authorization",
1595
+ authorizationId: row.authorization_id
1596
+ }, parseAuthorizationGrantRef, "operation.authorization.authorizationGrantRef")
1597
+ };
1598
+ } else if (sourceKind === "verified_step_up") {
1599
+ if (row.authorization_id != null) throw new Error("operation.authorization step-up row cannot contain authorizationId");
1600
+ authorization = {
1601
+ kind: "verified_step_up",
1602
+ evidenceSetDigest: parseDigestB64u(requireString(row.evidence_set_digest, "operation.authorization.evidenceSetDigest"))
1603
+ };
1604
+ } else throw new Error("operation.authorization.kind is invalid");
1605
+ const lifecycle = requireString(row.lifecycle_kind, "operation.lifecycle");
1606
+ const base = {
1607
+ kind: "authorized_operation",
1608
+ tenantId,
1609
+ authorizedOperationId: requireParsed(row.authorized_operation_id, parseAuthorizedOperationId, "operation.authorizedOperationId"),
1610
+ auditEventId: requireParsed(row.audit_event_id, parseAuthorizationAuditEventId, "operation.auditEventId"),
1611
+ operation,
1612
+ operationFingerprintDigest: parseOperationFingerprint(row.operation_fingerprint_digest),
1613
+ authorization,
1614
+ claimedAtMs: requirePositiveInteger(row.claimed_at_ms, "operation.claimedAtMs"),
1615
+ quota: (() => {
1616
+ const quotaKind = requireString(row.quota_kind, "operation.quota.kind");
1617
+ if (quotaKind === "consume_reusable_wallet_session") return {
1618
+ kind: "consume_reusable_wallet_session",
1619
+ quotaId: requireParsed(row.quota_id, parseMpcWalletSigningQuotaId, "operation.quotaId")
1620
+ };
1621
+ if (quotaKind === "quota_neutral") {
1622
+ if (row.quota_id != null) throw new Error("operation.quota-neutral row cannot contain quotaId");
1623
+ return { kind: "quota_neutral" };
1624
+ }
1625
+ throw new Error("operation.quota.kind is invalid");
1626
+ })()
1627
+ };
1628
+ if (await computeCapabilityOperationFingerprintDigest(operation) !== base.operationFingerprintDigest) throw new Error("operation.operationFingerprintDigest does not match operation envelope");
1629
+ if (lifecycle === "claimed") return {
1630
+ ...base,
1631
+ lifecycle: "claimed"
1632
+ };
1633
+ if (lifecycle !== "completed") throw new Error("operation.lifecycle is invalid");
1634
+ const result = requireString(row.result_kind, "operation.result");
1635
+ if (result !== "succeeded" && result !== "failed_before_side_effect" && result !== "failed_after_side_effect") throw new Error("operation.result is invalid");
1636
+ const response = parseAuthorizedOperationReplayResponse({
1637
+ status: integerColumn(row.result_status, "operation.response.status"),
1638
+ contentType: requiredText(row.result_content_type, "operation.response.contentType"),
1639
+ bodyText: requiredText(row.result_body_text, "operation.response.bodyText")
1640
+ });
1641
+ const resultDigest = parseDigestB64u(requireString(row.result_digest, "operation.resultDigest"));
1642
+ if (await computeAuthorizedOperationResultDigest(response) !== resultDigest) throw new Error("operation.resultDigest does not match replay response");
1643
+ return {
1644
+ ...base,
1645
+ lifecycle: "completed",
1646
+ result,
1647
+ response,
1648
+ resultDigest,
1649
+ completedAtMs: requirePositiveInteger(row.completed_at_ms, "operation.completedAtMs")
1650
+ };
1651
+ }
1652
+ function requiredText(value, label) {
1653
+ if (typeof value !== "string") throw new Error(`${label} must be text`);
1654
+ return value;
1655
+ }
1656
+ function requireParsed(value, parser, label) {
1657
+ const parsed = parser(value);
1658
+ if (!parsed.ok) throw new Error(`${label}: ${parsed.error.message}`);
1659
+ return parsed.value;
1660
+ }
1661
+ function parseOperationFingerprint(value) {
1662
+ try {
1663
+ return parseCapabilityOperationFingerprintDigest(value);
1664
+ } catch (error) {
1665
+ throw new Error(`operation.operationFingerprintDigest: ${error instanceof Error ? error.message : String(error)}`);
1666
+ }
1667
+ }
1668
+ function integerColumn(value, label) {
1669
+ const parsed = typeof value === "number" ? value : Number(value);
1670
+ if (!Number.isSafeInteger(parsed)) throw new Error(`${label} must be a safe integer`);
1671
+ return parsed;
1672
+ }
1673
+ function requirePositiveInteger(value, label) {
1674
+ const parsed = integerColumn(value, label);
1675
+ if (parsed <= 0) throw new Error(`${label} must be positive`);
1676
+ return parsed;
1677
+ }
1678
+ function requireOpaqueString(value, label) {
1679
+ if (typeof value !== "string" || value.trim() !== value || value.length === 0 || value.length > 512 || /[\s\u0000-\u001f\u007f]/.test(value)) throw new Error(`${label} must be a compact opaque identifier`);
1680
+ return value;
1681
+ }
1682
+ function requireString(value, label) {
1683
+ return requireOpaqueString(value, label);
1684
+ }
1685
+ function requireOneChangedRow(result, label) {
1686
+ if (d1ChangedRows({
1687
+ success: true,
1688
+ meta: result.meta
1689
+ }) !== 1) throw new Error(`${label} was not persisted`);
1690
+ }
1691
+ function requireExactWalletSessionAuthorizationV2Quota(input) {
1692
+ if (input.session.tenantId !== input.quota.tenantId || input.session.principalId !== input.quota.principalId || input.session.walletSessionId !== input.quota.walletSessionId || input.session.quotaId !== input.quota.quotaId || input.session.expiresAtMs !== input.quota.expiresAtMs) throw new Error("V2 Wallet Session authorization and quota must have one exact identity");
1693
+ }
1694
+ function requireExactPersistedActiveWalletSessionAuthorizationV2(input) {
1695
+ if (input.kind !== "persisted_active_wallet_session_authorization_v2") throw new Error("Direct V2 Wallet Session aggregate kind is invalid");
1696
+ requireExactWalletSessionAuthorizationV2Quota(input);
1697
+ parseDigestB64u(input.primaryOperationCredentialDigestB64u);
1698
+ if (input.retiredAtMs !== void 0) throw new Error("Direct V2 Wallet Session aggregate cannot be retired");
1699
+ }
1700
+ function directV2IdentityAvailabilitySql() {
1701
+ return `${directV2SessionIdentityAvailabilitySql()}
1702
+ AND NOT EXISTS (
1703
+ SELECT 1
1704
+ FROM authorization_wallet_session_quotas AS existing_quota
1705
+ WHERE existing_quota.namespace = ?
1706
+ AND existing_quota.tenant_id = ?
1707
+ AND existing_quota.quota_id = ?
1708
+ )`;
1709
+ }
1710
+ function directV2IdentityAvailabilityBindings(namespace, scope, session) {
1711
+ return [
1712
+ ...directV2SessionIdentityAvailabilityBindings(namespace, scope, session),
1713
+ namespace,
1714
+ String(session.tenantId),
1715
+ String(session.quotaId)
1716
+ ];
1717
+ }
1718
+ function directV2SessionIdentityAvailabilitySql() {
1719
+ return `
1720
+ NOT EXISTS (
1721
+ SELECT 1
1722
+ FROM wallet_session_authorizations_v2 AS existing
1723
+ WHERE existing.namespace = ?
1724
+ AND existing.org_id = ?
1725
+ AND existing.project_id = ?
1726
+ AND existing.env_id = ?
1727
+ AND existing.tenant_id = ?
1728
+ AND (
1729
+ existing.authorization_id = ?
1730
+ OR existing.mint_id = ?
1731
+ OR existing.wallet_session_id = ?
1732
+ OR existing.quota_id = ?
1733
+ )
1734
+ )`;
1735
+ }
1736
+ function directV2SessionIdentityAvailabilityBindings(namespace, scope, session) {
1737
+ return [
1738
+ namespace,
1739
+ scope.orgId,
1740
+ scope.projectId,
1741
+ scope.envId,
1742
+ String(session.tenantId),
1743
+ String(session.authorizationId),
1744
+ String(session.mintId),
1745
+ String(session.walletSessionId),
1746
+ String(session.quotaId)
1747
+ ];
1748
+ }
1749
+ function walletSessionAuthorizationV2RowMatches(row, session) {
1750
+ return row.session_tenant_id === String(session.tenantId) && row.session_authorization_id === String(session.authorizationId) && row.session_mint_id === String(session.mintId) && row.session_wallet_session_id === String(session.walletSessionId) && row.session_quota_id === String(session.quotaId) && row.session_principal_id === String(session.principalId) && row.session_wallet_id === String(session.walletId) && row.session_authority_id === String(session.authorityId) && row.session_wallet_auth_method_id === String(session.walletAuthMethodId) && row.session_authority_digest_b64u === String(session.authorityDigestB64u) && integerColumn(row.session_authority_revocation_epoch, "session.authorityRevocationEpoch") === session.authorityRevocationEpoch && integerColumn(row.session_issued_at_ms, "session.createdAtMs") === session.createdAtMs && integerColumn(row.session_expires_at_ms, "session.expiresAtMs") === session.expiresAtMs;
1751
+ }
1752
+ function parseWalletSessionAuthorizationV2WithSubjects(row, capabilitySubjects) {
1753
+ return parseWalletSessionAuthorizationV2({
1754
+ kind: "wallet_session_authorization_v2",
1755
+ tenantId: row.session_tenant_id,
1756
+ principalId: row.session_principal_id,
1757
+ walletId: row.session_wallet_id,
1758
+ authorityId: row.session_authority_id,
1759
+ walletAuthMethodId: row.session_wallet_auth_method_id,
1760
+ authorityDigestB64u: row.session_authority_digest_b64u,
1761
+ authorityRevocationEpoch: row.session_authority_revocation_epoch,
1762
+ mintId: row.session_mint_id,
1763
+ authorizationId: row.session_authorization_id,
1764
+ walletSessionId: row.session_wallet_session_id,
1765
+ quotaId: row.session_quota_id,
1766
+ capabilitySubjects,
1767
+ createdAtMs: row.session_issued_at_ms,
1768
+ expiresAtMs: row.session_expires_at_ms
1769
+ });
1770
+ }
1771
+ function parseWalletSessionAuthorizationV2QuotaRow(row, session) {
1772
+ if (row.quota_lifecycle_kind !== "active") throw new Error("Stored V2 Wallet Session quota is no longer active");
1773
+ const quotaTenantId = requireParsed(row.quota_tenant_id, parseTenantId, "V2 quota.tenantId");
1774
+ const quotaPrincipalId = requireParsed(row.quota_principal_id, parsePrincipalId, "V2 quota.principalId");
1775
+ const quotaWalletSessionId = requireParsed(row.quota_wallet_session_id, parseWalletSessionId, "V2 quota.walletSessionId");
1776
+ const quotaId = requireParsed(row.quota_id, parseMpcWalletSigningQuotaId, "V2 quota.quotaId");
1777
+ const remainingUses = requirePositiveInteger(row.quota_remaining_uses, "V2 quota.remainingUses");
1778
+ const expiresAtMs = requirePositiveInteger(row.quota_expires_at_ms, "V2 quota.expiresAtMs");
1779
+ if (quotaTenantId !== session.tenantId || quotaPrincipalId !== session.principalId || quotaWalletSessionId !== session.walletSessionId || quotaId !== session.quotaId || expiresAtMs !== session.expiresAtMs) throw new Error("Stored V2 Wallet Session quota identity does not match");
1780
+ return buildActiveWalletSessionQuota({
1781
+ tenantId: quotaTenantId,
1782
+ principalId: quotaPrincipalId,
1783
+ walletSessionId: quotaWalletSessionId,
1784
+ quotaId,
1785
+ remainingUses,
1786
+ expiresAtMs
1787
+ });
1788
+ }
1789
+ /**
1790
+ * Reads the quota joined to an exact authorization without collapsing an
1791
+ * exhausted quota into an error. Identity disagreement remains a corrupt-row
1792
+ * exception because the quota is the authorization's own committed row.
1793
+ */
1794
+ function parseExactWalletSessionQuotaProjectionRow(row, session) {
1795
+ if (row.quota_id === null || row.quota_id === void 0) throw new Error("Stored V2 Wallet Session quota row is missing");
1796
+ if (row.quota_lifecycle_kind !== "active" && row.quota_lifecycle_kind !== "exhausted") throw new Error("Stored V2 Wallet Session quota lifecycle is unsupported");
1797
+ const quotaTenantId = requireParsed(row.quota_tenant_id, parseTenantId, "V2 quota.tenantId");
1798
+ const quotaPrincipalId = requireParsed(row.quota_principal_id, parsePrincipalId, "V2 quota.principalId");
1799
+ const quotaWalletSessionId = requireParsed(row.quota_wallet_session_id, parseWalletSessionId, "V2 quota.walletSessionId");
1800
+ const quotaId = requireParsed(row.quota_id, parseMpcWalletSigningQuotaId, "V2 quota.quotaId");
1801
+ const remainingUses = integerColumn(row.quota_remaining_uses, "V2 quota.remainingUses");
1802
+ const expiresAtMs = requirePositiveInteger(row.quota_expires_at_ms, "V2 quota.expiresAtMs");
1803
+ if (quotaTenantId !== session.tenantId || quotaPrincipalId !== session.principalId || quotaWalletSessionId !== session.walletSessionId || quotaId !== session.quotaId || expiresAtMs !== session.expiresAtMs) throw new Error("Stored V2 Wallet Session quota identity does not match");
1804
+ return buildExactWalletSessionQuotaProjectionV1({
1805
+ lifecycle: row.quota_lifecycle_kind,
1806
+ tenantId: quotaTenantId,
1807
+ principalId: quotaPrincipalId,
1808
+ walletSessionId: quotaWalletSessionId,
1809
+ quotaId,
1810
+ remainingUses,
1811
+ expiresAtMs
1812
+ });
1813
+ }
1814
+ function assertNeverDirectV2CommitMode(value) {
1815
+ throw new Error(`Unsupported direct V2 Wallet Session commit mode: ${String(value)}`);
1816
+ }
1817
+ //#endregion
1818
+ export { CloudflareD1AuthorizationStore };
1819
+
1820
+ //# sourceMappingURL=d1AuthorizationStore.js.map