@seams/wallet-server 0.10.1 → 0.11.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 (105) hide show
  1. package/THIRD_PARTY_NOTICES.md +33 -1812
  2. package/artifact-manifest.json +30 -30
  3. package/cloudflare-router-ab/build/deriver-a/build-stamp.json +1 -1
  4. package/cloudflare-router-ab/build/deriver-a/index.js +2 -2
  5. package/cloudflare-router-ab/build/deriver-a/index_bg.wasm +0 -0
  6. package/cloudflare-router-ab/build/deriver-b/build-stamp.json +1 -1
  7. package/cloudflare-router-ab/build/deriver-b/index.js +2 -2
  8. package/cloudflare-router-ab/build/deriver-b/index_bg.wasm +0 -0
  9. package/cloudflare-router-ab/build/local-tools/darwin-arm64/router_ab_local_init +0 -0
  10. package/cloudflare-router-ab/build/local-tools/darwin-x64/router_ab_local_init +0 -0
  11. package/cloudflare-router-ab/build/local-tools/linux-x64/router_ab_local_init +0 -0
  12. package/cloudflare-router-ab/build/router/build-stamp.json +1 -1
  13. package/cloudflare-router-ab/build/router/index.js +2 -2
  14. package/cloudflare-router-ab/build/router/index_bg.wasm +0 -0
  15. package/cloudflare-router-ab/build/signing-worker/build-stamp.json +1 -1
  16. package/cloudflare-router-ab/build/signing-worker/index.js +2 -2
  17. package/cloudflare-router-ab/build/signing-worker/index_bg.wasm +0 -0
  18. package/cloudflare-router-ab/build/tenant-root-control-plane/build-stamp.json +1 -1
  19. package/cloudflare-router-ab/build/tenant-root-control-plane/index.js +2 -2
  20. package/cloudflare-router-ab/build/tenant-root-control-plane/index_bg.wasm +0 -0
  21. package/dist/esm/cloud-host.js +8 -7
  22. package/dist/esm/hosted-wallet-gateway.js +19 -2
  23. package/dist/esm/index.js +1 -2
  24. package/dist/esm/localHostedWalletGatewayHandler.js +17 -11
  25. package/dist/esm/localIntendedYaoFault.js +34 -3
  26. package/dist/esm/localIntendedYaoRecoveryFault.js +19 -16
  27. package/dist/esm/localIntendedYaoSigningFault.js +31 -16
  28. package/dist/esm/router/auth/routerApiKeyAuth.js +1 -13
  29. package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthService.js +13 -4
  30. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceOwnerAuthorizationProvider.js +1 -1
  31. package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoProductRegistrationPartitionedStateStore.js +4 -4
  32. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRecords.js +1 -1
  33. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRecoveryService.js +1 -1
  34. package/dist/esm/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpSessionResolver.js +1 -1
  35. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyRecordStore.js +19 -0
  36. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyRecords.js +5 -5
  37. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyStore.js +5 -2
  38. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationSetupSupport.js +7 -1
  39. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationCommitStore.js +56 -21
  40. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationRead.js +15 -5
  41. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationService.js +87 -34
  42. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationSetupExecution.js +23 -7
  43. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAddSignerFinalizeRecord.js +1 -1
  44. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAddSignerService.js +3 -3
  45. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthMethodService.js +3 -3
  46. package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnAuthService.js +1 -1
  47. package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnRecords.js +1 -1
  48. package/dist/esm/router/cloudflare-adaptor.js +2 -2
  49. package/dist/esm/router/cloudflare.js +2495 -2444
  50. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.js +1 -1
  51. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitionedStateStore.js +5 -1
  52. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRuntime.js +15 -3
  53. package/dist/esm/router/domains/walletRegistration/walletRegistrationRoutes.js +39 -32
  54. package/dist/esm/router/framework/registrationSetupDispatch.js +11 -3
  55. package/dist/esm/router/framework/routeResponses.js +1 -5
  56. package/dist/esm/router/transport/fetch/routes/deviceLinkingOwnerAuthorization.js +1 -1
  57. package/dist/esm/router/transport/fetch/routes/passkeyCustody.js +2 -2
  58. package/dist/esm/router/transport/fetch/routes/thresholdEd25519.js +51 -24
  59. package/dist/esm/shared-ts/src/utils/validation.js +5 -1
  60. package/dist/esm/threshold/session/signingSessionSeal/crypto/shamir3PassWasm.js +19 -1
  61. package/dist/esm/threshold/session/signingSessionSeal/index.js +1 -2
  62. package/dist/esm/wasm/evm_crypto/pkg/evm_crypto_bg.wasm +0 -0
  63. package/dist/esm/wasm/near_signer/pkg/wasm_signer_worker_bg.wasm +0 -0
  64. package/dist/esm/wasm/shamir3pass_runtime/pkg/shamir3pass_runtime_bg.wasm +0 -0
  65. package/dist/types/wallet-server/src/cloud-host.d.ts +1 -0
  66. package/dist/types/wallet-server/src/localHostedWalletGatewayHandler.d.ts +1 -1
  67. package/dist/types/wallet-server/src/localIntendedYaoFault.d.ts +13 -3
  68. package/dist/types/wallet-server/src/localIntendedYaoRecoveryFault.d.ts +4 -2
  69. package/dist/types/wallet-server/src/localIntendedYaoSigningFault.d.ts +4 -2
  70. package/dist/types/wallet-server/src/router/auth/routerApiKeyAuth.d.ts +0 -8
  71. package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoProductRegistrationPartitionedStateStore.d.ts +2 -1
  72. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyRecordStore.d.ts +2 -0
  73. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyStore.d.ts +1 -0
  74. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationSetupSupport.d.ts +2 -0
  75. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationCommitStore.d.ts +27 -3
  76. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationRead.d.ts +20 -1
  77. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationService.d.ts +6 -0
  78. package/dist/types/wallet-server/src/router/cloudflare-adaptor.d.ts +1 -1
  79. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.d.ts +10 -1
  80. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitionedStateStore.d.ts +3 -1
  81. package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationInputs.d.ts +2 -0
  82. package/dist/types/wallet-server/src/router/framework/routeResponses.d.ts +0 -2
  83. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/crypto/shamir3PassWasm.d.ts +6 -0
  84. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/index.d.ts +1 -2
  85. package/package.json +2 -9
  86. package/src/README.md +5 -3
  87. package/dist/esm/router/express-adaptor.js +0 -84
  88. package/dist/esm/router/express.js +0 -26400
  89. package/dist/esm/router/node/nodeHostedWalletGateway.js +0 -64
  90. package/dist/esm/router/node/nodeHostedWalletGatewayCheck.js +0 -163
  91. package/dist/esm/router/node/nodeHostedWalletGatewayMain.js +0 -120
  92. package/dist/esm/router/node/nodeHttp.js +0 -79
  93. package/dist/esm/router/node/nodeSqlite.js +0 -43
  94. package/dist/esm/router/node/signerSqlMigrations.js +0 -48
  95. package/dist/esm/storage/syncSqlite.js +0 -79
  96. package/dist/esm/threshold/session/signingSessionSeal/transport/express.js +0 -75
  97. package/dist/types/wallet-server/src/router/express-adaptor.d.ts +0 -22
  98. package/dist/types/wallet-server/src/router/node/nodeHostedWalletGateway.d.ts +0 -34
  99. package/dist/types/wallet-server/src/router/node/nodeHostedWalletGatewayCheck.d.ts +0 -21
  100. package/dist/types/wallet-server/src/router/node/nodeHostedWalletGatewayMain.d.ts +0 -2
  101. package/dist/types/wallet-server/src/router/node/nodeHttp.d.ts +0 -13
  102. package/dist/types/wallet-server/src/router/node/nodeSqlite.d.ts +0 -22
  103. package/dist/types/wallet-server/src/router/node/signerSqlMigrations.d.ts +0 -20
  104. package/dist/types/wallet-server/src/storage/syncSqlite.d.ts +0 -28
  105. package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/transport/express.d.ts +0 -12
@@ -6,15 +6,17 @@ import { D1WalletStore } from "../../../../core/d1WalletStore.js";
6
6
  import { D1WalletAuthMethodStore } from "../../../../core/d1WalletAuthMethodStore.js";
7
7
  import { normalizeLogger } from "../../../../core/logger.js";
8
8
  import { executeSignedDelegateWithRelayer } from "../../../../delegateAction/index.js";
9
+ import { sha256BytesPortable, toRecordValue } from "./d1RouterApiAuthBoundary.js";
10
+ import { parseD1EcdsaDerivationServerBootstrapResponse, parseD1WalletRegistrationCommittedInstallationProjection, parseD1WalletRegistrationFinalizeReplayResponse } from "../registration/d1RegistrationCeremonyRecords.js";
9
11
  import { parseWalletUnlockIssuanceRejectionCode } from "../../../framework/authServicePort.js";
10
12
  import { parseWebAuthnAuthenticationCredential } from "../../../auth/webAuthnCredentialCodecs.js";
11
13
  import { resolveActiveOwnerWalletExecutionLane, resolveWalletAuthMethodIdForAuthority } from "../../../../core/signingLanes/WalletExecutionLaneProjection.js";
12
14
  import { DEFAULT_WALLET_SESSION_TTL_MS } from "../../../../shared-ts/src/threshold/sessionPolicy.js";
13
15
  import { createDeviceLinkingOwnerRequestAuthenticatorV1 } from "../../../transport/fetch/routes/deviceLinkingOwnerAuthorization.js";
14
- import { sha256BytesPortable, toRecordValue } from "./d1RouterApiAuthBoundary.js";
15
16
  import { verifyD1LinkedDeviceFreshRevokeProofV1 } from "../wallet/d1WalletAuthMethodBoundary.js";
16
17
  import { D1LinkedDeviceAuthorityInstallServiceV1 } from "../deviceLinking/d1LinkedDeviceAuthorityInstallService.js";
17
18
  import { D1WalletAuthorityStore } from "../wallet/d1WalletAuthorityStore.js";
19
+ import { createD1Ed25519YaoLifecycleRecords } from "../ed25519Yao/d1Ed25519YaoProductRegistrationPartitionedStateStore.js";
18
20
  import { parseRouterAbEd25519YaoRegistrationSideEffectRecordV2 } from "../../../domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.js";
19
21
  import { createCloudflareOrdinaryInactiveSignerMaterialActivationPortV1, createCloudflareOrdinaryInactiveSignerMaterialDeactivationPortV1, createCloudflareOrdinaryInactiveSignerMaterialReservationServiceV1 } from "../../signingLanes/cloudflareOrdinaryInactiveSignerMaterialReservation.js";
20
22
  import { normalizeD1RouterApiAuthOptions } from "./d1RouterApiAuthConfig.js";
@@ -24,7 +26,6 @@ import { toPublicKeyStringFromSecretKey } from "../../../../core/nearKeys.js";
24
26
  import { MinimalNearClient } from "../../../../core/rpcClients/near/NearClient.js";
25
27
  import { fundImplicitNearAccountWithRelayer } from "../../../../core/nearRelayerAccountProvisioning.js";
26
28
  import { createSponsoredNamedNearAccountForOptions } from "../near/d1SponsoredNearAccount.js";
27
- import { parseD1EcdsaDerivationServerBootstrapResponse, parseD1WalletRegistrationCommittedInstallationProjection, parseD1WalletRegistrationFinalizeReplayResponse } from "../registration/d1RegistrationCeremonyRecords.js";
28
29
  import { parseD1WalletAddSignerFinalizeSideEffectRecord } from "../wallet/d1WalletAddSignerFinalizeRecord.js";
29
30
  import { dispatchWalletRegistrationSetup } from "../../../framework/registrationSetupDispatch.js";
30
31
  import { readActiveWalletSessionCredential, readEd25519WalletSessionSigningRead, readExhaustedWalletSessionCredential, readWalletSessionSigningCandidate } from "./walletSessionCredentialReaders.js";
@@ -52,8 +53,8 @@ import { D1WalletAuthMethodRevocationReplayStoreV1 } from "../wallet/d1WalletAut
52
53
  import { CloudflareD1WalletAuthMethodService } from "../wallet/d1WalletAuthMethodService.js";
53
54
  import { parseWalletRegistrationSessionCommitReceiptV2 } from "../registration/walletRegistrationSessionCommitReceipt.js";
54
55
  import { CloudflareD1WalletRegistrationService } from "../registration/d1WalletRegistrationService.js";
55
- import { D1WalletRegistrationRead } from "../registration/d1WalletRegistrationRead.js";
56
56
  import { CloudflareD1WalletRegistrationCommitStore } from "../registration/d1WalletRegistrationCommitStore.js";
57
+ import { D1WalletRegistrationRead } from "../registration/d1WalletRegistrationRead.js";
57
58
  import { CloudflareD1Ed25519YaoLifecycleDecisionStoreV1 } from "../ed25519Yao/d1Ed25519YaoLifecycleDecisionStore.js";
58
59
  import { createD1PasskeyCustodyRouteService } from "../passkeyCustody/d1PasskeyCustodyRouteService.js";
59
60
  import { CloudflareD1WalletRecoveryGoogleEmailOtpAttemptStore } from "../passkeyCustody/d1WalletRecoveryGoogleEmailOtpAttemptStore.js";
@@ -846,7 +847,15 @@ function createCloudflareD1RouterApiAuthAssembly(input) {
846
847
  tenantRootCustodyLineage: options.tenantRootCustodyLineage,
847
848
  getWalletStore,
848
849
  activateSideEffects: walletRegistrationActivateSideEffectStore(options),
849
- registrationRead: new D1WalletRegistrationRead(options.database, options.registrationAuthority ?? null, walletRegistrationNearProvisioningSideEffectStore(options), getRegistrationCeremonyIntentStore, yaoLifecycleDecisions, walletRegistrationCommitStore),
850
+ registrationRead: new D1WalletRegistrationRead(options.database, options.registrationAuthority ?? null, walletRegistrationNearProvisioningSideEffectStore(options), getRegistrationCeremonyIntentStore, yaoLifecycleDecisions, createD1Ed25519YaoLifecycleRecords({
851
+ database: options.database,
852
+ scope: {
853
+ namespace: options.namespace,
854
+ orgId: options.orgId,
855
+ projectId: options.projectId,
856
+ envId: options.envId
857
+ }
858
+ }), walletRegistrationCommitStore),
850
859
  walletRegistrationCommitStore,
851
860
  walletCustodyCommitStore,
852
861
  walletAuthMethods,
@@ -11,9 +11,9 @@ import { buildEmailOtpWalletAuthAuthority, buildPasskeyWalletAuthAuthority, wall
11
11
  import { walletAuthorityDigestsMatchV1 } from "../../../../shared-ts/src/authorization/walletAuthority.js";
12
12
  import { buildWalletSessionLinkedDeviceOwnerAuthorizationV1, parseQrLinkedDeviceSessionPayloadV5 } from "../../../../shared-ts/src/device-linking/parsers.js";
13
13
  import { computeLinkedDevicePublicKeyDigestV1 } from "../../../../shared-ts/src/device-linking/requestProof.js";
14
+ import { thresholdEd25519AuthorityScopeFromWalletAuthAuthority } from "../../../../core/ThresholdService/validation.js";
14
15
  import { resolveActiveOwnerWalletExecutionLane, resolveWalletAuthMethodIdForAuthority } from "../../../../core/signingLanes/WalletExecutionLaneProjection.js";
15
16
  import "../../../../core/deviceLinking/requestProof.js";
16
- import { thresholdEd25519AuthorityScopeFromWalletAuthAuthority } from "../../../../core/ThresholdService/validation.js";
17
17
  import { sourceKeyManifestDigestForFamilyV1 } from "../../../../core/deviceLinking/linkedDeviceSessionRecord.js";
18
18
  import { LinkedDeviceSourceFamilyUnavailableErrorV1 } from "./d1LinkedDeviceVerifiedLinkSourceReader.js";
19
19
  import { linkedDeviceSignerManifestsEqualV1 } from "./d1LinkedDeviceVerifiedLinkBuilder.js";
@@ -4,7 +4,7 @@ import { D1WalletCeremonyActivity, ceremonySettled } from "./d1WalletCeremonyAct
4
4
  import { collectChangedStateWallets, lifecycleWriteFenceStatements } from "./d1Ed25519YaoStateWriteFence.js";
5
5
  //#region src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoProductRegistrationPartitionedStateStore.ts
6
6
  function createRouterAbEd25519YaoProductRegistrationPartitionedStateStoreFromD1V1(options) {
7
- return createRouterAbEd25519YaoProductRegistrationPartitionedStateStoreV1(new D1LifecycleRecords(options, createLifecycleRecords(options)));
7
+ return createRouterAbEd25519YaoProductRegistrationPartitionedStateStoreV1(new D1LifecycleRecords(options, createD1Ed25519YaoLifecycleRecords(options)));
8
8
  }
9
9
  var D1LifecycleRecords = class {
10
10
  constructor(options, records) {
@@ -64,7 +64,7 @@ function readPartition(value) {
64
64
  return record;
65
65
  }
66
66
  async function evictWalletEd25519CapabilityCache(options, walletId) {
67
- const records = createLifecycleRecords(options);
67
+ const records = createD1Ed25519YaoLifecycleRecords(options);
68
68
  const key = ROUTER_AB_ED25519_YAO_SHARED_STATE_RECORD_KEY_V1;
69
69
  const current = await records.read(key);
70
70
  if (current.kind !== "present") return;
@@ -98,7 +98,7 @@ async function evictWalletEd25519CapabilityCache(options, walletId) {
98
98
  expectedVersion: current.version
99
99
  }])).kind !== "stored") throw new Error("Capability cache changed during cleanup");
100
100
  }
101
- function createLifecycleRecords(options) {
101
+ function createD1Ed25519YaoLifecycleRecords(options) {
102
102
  return createCloudflareD1VersionedJsonRecordStore({
103
103
  ...options,
104
104
  encode: identityVersionedJsonObject,
@@ -106,6 +106,6 @@ function createLifecycleRecords(options) {
106
106
  });
107
107
  }
108
108
  //#endregion
109
- export { createRouterAbEd25519YaoProductRegistrationPartitionedStateStoreFromD1V1, evictWalletEd25519CapabilityCache };
109
+ export { createD1Ed25519YaoLifecycleRecords, createRouterAbEd25519YaoProductRegistrationPartitionedStateStoreFromD1V1, evictWalletEd25519CapabilityCache };
110
110
 
111
111
  //# sourceMappingURL=d1Ed25519YaoProductRegistrationPartitionedStateStore.js.map
@@ -3,8 +3,8 @@ import { base64UrlDecode } from "../../../../shared-ts/src/utils/base64.js";
3
3
  import "../../../../shared-ts/src/utils/encoders.js";
4
4
  import { hasExactKeys } from "../../../../shared-ts/src/utils/exactKeys.js";
5
5
  import { failure } from "../../../../shared-ts/src/utils/failure.js";
6
- import { EMAIL_OTP_CHANNEL, WALLET_EMAIL_OTP_ACTIONS, WALLET_EMAIL_OTP_UNLOCK_OPERATION, isWalletEmailOtpLoginOperation } from "../../../../shared-ts/src/utils/emailOtpDomain.js";
7
6
  import { isB64uString, nonNegativeSafeInteger, parseJsonObject, positiveSafeInteger } from "../auth/d1RouterApiAuthBoundary.js";
7
+ import { EMAIL_OTP_CHANNEL, WALLET_EMAIL_OTP_ACTIONS, WALLET_EMAIL_OTP_UNLOCK_OPERATION, isWalletEmailOtpLoginOperation } from "../../../../shared-ts/src/utils/emailOtpDomain.js";
8
8
  import { parseCurrentEmailOtpChallengeRow, parseCurrentEmailOtpGrantRow, parseCurrentEmailOtpUnlockChallengeRow, parseEmailOtpChallengePurpose } from "../../../../core/EmailOtpRecords.js";
9
9
  //#region src/router/cloudflare/d1/emailOtp/d1EmailOtpRecords.ts
10
10
  function maskEmail(email) {
@@ -2,8 +2,8 @@ import { normalizeOptionalTrimmedString } from "../../../../shared-ts/src/utils/
2
2
  import { secureRandomBase64Url } from "../../../../shared-ts/src/utils/secureRandomId.js";
3
3
  import { failedVerification, failure } from "../../../../shared-ts/src/utils/failure.js";
4
4
  import { validateSecp256k1PublicKey33, verifySecp256k1RecoverableSignatureAgainstPublicKey33 } from "../../../../core/ThresholdService/evmCryptoWasm.js";
5
- import { EMAIL_OTP_CHANNEL, WALLET_EMAIL_OTP_ACTIONS } from "../../../../shared-ts/src/utils/emailOtpDomain.js";
6
5
  import { parseD1BoundaryWalletIdResult } from "../auth/d1RouterApiAuthBoundary.js";
6
+ import { EMAIL_OTP_CHANNEL, WALLET_EMAIL_OTP_ACTIONS } from "../../../../shared-ts/src/utils/emailOtpDomain.js";
7
7
  import { bytesEqual, clampedEmailOtpUnlockTtlMs, decodeFixedBase64Url, emailOtpUnlockChallengeRecord } from "./d1EmailOtpRecords.js";
8
8
  //#region src/router/cloudflare/d1/emailOtp/d1EmailOtpRecoveryService.ts
9
9
  function errorMessage(error) {
@@ -3,8 +3,8 @@ import { normalizeOptionalTrimmedString } from "../../../../shared-ts/src/utils/
3
3
  import { secureRandomBase64Url } from "../../../../shared-ts/src/utils/secureRandomId.js";
4
4
  import { failure } from "../../../../shared-ts/src/utils/failure.js";
5
5
  import { createServerAllocatedWalletId } from "../../../../shared-ts/src/utils/registrationIds.js";
6
- import { hashEmailOtpOperationBinding } from "../../../domains/emailOtp/emailOtpSessionRouteHelpers.js";
7
6
  import { parseD1BoundaryWalletId, parseD1BoundaryWalletIdResult } from "../auth/d1RouterApiAuthBoundary.js";
7
+ import { hashEmailOtpOperationBinding } from "../../../domains/emailOtp/emailOtpSessionRouteHelpers.js";
8
8
  import { abandonedGoogleEmailOtpRegistrationAttemptRecord, expiredGoogleEmailOtpRegistrationAttemptRecord, googleEmailOtpRegistrationOfferForResponse, requireRuntimePolicyScope } from "./d1GoogleEmailOtpRegistrationRecords.js";
9
9
  import { googleEmailOtpStaleIdentityMapping, hasDifferentWalletIdentitySubject } from "../identity/d1IdentityRecords.js";
10
10
  //#region src/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpSessionResolver.ts
@@ -40,6 +40,25 @@ var D1RegistrationCeremonyRecordStore = class {
40
40
  prepareGet(scope, id) {
41
41
  return this.prepareRead(this.normalizeKey(scope, id));
42
42
  }
43
+ /** Load the ceremony's immutable founding identities and their current records together. */
44
+ prepareFoundingRecordsRead(id) {
45
+ const key = this.normalizeKey("ceremony", id);
46
+ return this.database.prepare(`
47
+ SELECT json_extract(ceremony.record_json, '$.foundingWalletAuthorityId') AS authority_id,
48
+ json_extract(ceremony.record_json, '$.foundingWalletAuthMethodId') AS auth_method_id,
49
+ (SELECT record_json FROM wallet_authorities
50
+ WHERE namespace = ?1 AND org_id = ?2 AND project_id = ?3 AND env_id = ?4
51
+ AND authority_id = json_extract(ceremony.record_json, '$.foundingWalletAuthorityId'))
52
+ AS authority_json,
53
+ (SELECT record_json FROM wallet_auth_methods
54
+ WHERE namespace = ?1 AND org_id = ?2 AND project_id = ?3 AND env_id = ?4
55
+ AND wallet_auth_method_id = json_extract(ceremony.record_json, '$.foundingWalletAuthMethodId'))
56
+ AS auth_method_json
57
+ FROM registration_ceremony_records AS ceremony
58
+ WHERE namespace = ?1 AND org_id = ?2 AND project_id = ?3 AND env_id = ?4
59
+ AND record_scope = ?5 AND record_id = ?6
60
+ `).bind(...this.bindKey(key));
61
+ }
43
62
  async parseGet(scope, id, row) {
44
63
  if (!row) return null;
45
64
  const parsed = parseStoredRow(row);
@@ -20,16 +20,16 @@ import { thresholdEcdsaChainTargetFromValue } from "../../../../core/thresholdEc
20
20
  import { buildWalletEcdsaSignerRecord, parseWalletEd25519SignerRecord } from "../../../../core/d1WalletStore.js";
21
21
  import { nearEd25519SigningKeyIdFromString, walletIdFromString } from "../../../../shared-ts/src/utils/registrationIds.js";
22
22
  import { registrationPreparationIdFromString } from "../../../../core/types.js";
23
- import "../../../../shared-ts/src/signing-lanes/index.js";
24
- import { parsePasskeyCustodyEnvelopeRecord } from "../../../../shared-ts/src/passkey-custody/custodyEnvelope.js";
25
- import "../../../../shared-ts/src/passkey-custody/index.js";
26
23
  import { parseImplicitNearAccountId, parseNamedNearAccountId } from "../../../../shared-ts/src/utils/near.js";
27
24
  import { findRegistrationSignerPlanNearEd25519Branch, normalizeAddSignerSelection, normalizeRegistrationSignerPlan, registrationSignerBranchKeyFromString, registrationSignerSetSelectionFromPlan } from "../../../../shared-ts/src/utils/registrationSignerPlan.js";
25
+ import { parseStoredRegistrationSignerPlan, parseStoredWalletRegistrationPreparedContext, storedRegistrationSignerPlansMatch } from "../../../../core/RegistrationCeremonyStore.js";
26
+ import "../../../../shared-ts/src/signing-lanes/index.js";
28
27
  import { addAuthMethodIntentGrantFromString, addSignerIntentGrantFromString, normalizeAddAuthMethodIntentCaller } from "../../../../shared-ts/src/utils/registrationIntent.js";
28
+ import { parsePasskeyCustodyEnvelopeRecord } from "../../../../shared-ts/src/passkey-custody/custodyEnvelope.js";
29
+ import "../../../../shared-ts/src/passkey-custody/index.js";
29
30
  import { parseEcdsaDerivationPublicIdentity, parseThresholdEd25519AuthorityScope, thresholdEd25519AuthorityScopeFromWalletAuthAuthority, thresholdEd25519AuthorityScopesMatch } from "../../../../core/ThresholdService/validation.js";
30
- import { toRecordValue } from "../auth/d1RouterApiAuthBoundary.js";
31
- import { parseStoredRegistrationSignerPlan, parseStoredWalletRegistrationPreparedContext, storedRegistrationSignerPlansMatch } from "../../../../core/RegistrationCeremonyStore.js";
32
31
  import { parseStoredRouterAbEcdsaPendingActivationV1 } from "../../../domains/ecdsa/routerAbEcdsaStrictRegistration.js";
32
+ import { toRecordValue } from "../auth/d1RouterApiAuthBoundary.js";
33
33
  //#region src/router/cloudflare/d1/registration/d1RegistrationCeremonyRecords.ts
34
34
  function inferRuntimePolicyScopeFromSigningRoot(input) {
35
35
  const signingRootId = normalizeOptionalTrimmedString(input.signingRootId);
@@ -1,9 +1,9 @@
1
1
  import { normalizeOptionalTrimmedString } from "../../../../shared-ts/src/utils/normalize.js";
2
2
  import { isPlainObject } from "../../../../shared-ts/src/utils/validation.js";
3
- import { prepareD1RegistrationHomeReservation } from "./d1WalletExecutionAuthority.js";
3
+ import { D1RegistrationCeremonyRecordStore } from "./d1RegistrationCeremonyRecordStore.js";
4
4
  import { parseD1StoredAddAuthMethodIntent, parseD1StoredAddSignerIntent, parseD1StoredWalletAddAuthMethodCeremony, parseD1StoredWalletAddAuthMethodFinalizeReplay, parseD1StoredWalletAddSignerCeremony, parseD1StoredWalletAddSignerFinalizeReplay, parseD1StoredWalletRegistrationCeremony } from "./d1RegistrationCeremonyRecords.js";
5
+ import { prepareD1RegistrationHomeReservation } from "./d1WalletExecutionAuthority.js";
5
6
  import { retryTransientD1 } from "../../../../storage/d1Retry.js";
6
- import { D1RegistrationCeremonyRecordStore } from "./d1RegistrationCeremonyRecordStore.js";
7
7
  //#region src/router/cloudflare/d1/registration/d1RegistrationCeremonyStore.ts
8
8
  var CloudflareD1RegistrationCeremonyIntentStore = class {
9
9
  constructor(input) {
@@ -47,6 +47,9 @@ var CloudflareD1RegistrationCeremonyIntentStore = class {
47
47
  prepareCeremonyRead(registrationCeremonyId) {
48
48
  return this.storage.prepareGet("ceremony", registrationCeremonyId);
49
49
  }
50
+ prepareFoundingRecordsRead(registrationCeremonyId) {
51
+ return this.storage.prepareFoundingRecordsRead(registrationCeremonyId);
52
+ }
50
53
  async parseCeremonyRead(registrationCeremonyId, result) {
51
54
  return (await this.parseCeremonySnapshotRead(registrationCeremonyId, result))?.ceremony ?? null;
52
55
  }
@@ -71,6 +71,12 @@ function registrationSignerBranchesFromPlan(plan) {
71
71
  function recordRegistrationServerTiming(sink, name, startedAtMs) {
72
72
  sink.push([name, Math.max(0, Date.now() - startedAtMs)]);
73
73
  }
74
+ /** The `Server-Timing` header of a registration route's recorded waits. */
75
+ function registrationServerTimingHeaders(serverTiming) {
76
+ if (serverTiming.length === 0) return void 0;
77
+ const header = serverTiming.map(([name, durationMs]) => `${name};dur=${Math.max(0, durationMs).toFixed(1)}`).join(", ");
78
+ return { "Server-Timing": header };
79
+ }
74
80
  async function recordRegistrationPromiseTiming(args) {
75
81
  try {
76
82
  return await args.promise;
@@ -79,6 +85,6 @@ async function recordRegistrationPromiseTiming(args) {
79
85
  }
80
86
  }
81
87
  //#endregion
82
- export { createD1RegistrationRouteTimingRecorder, errorMessage, finishD1RegistrationRouteTiming, recordRegistrationPromiseTiming, recordRegistrationServerTiming, registrationIntentSignerBranches, registrationPreparedContextEcdsaChainTargets, registrationSignerBranchesFromPlan, resolveRegistrationPreparedContextFromPlan, startD1RegistrationRouteTiming };
88
+ export { createD1RegistrationRouteTimingRecorder, errorMessage, finishD1RegistrationRouteTiming, recordRegistrationPromiseTiming, recordRegistrationServerTiming, registrationIntentSignerBranches, registrationPreparedContextEcdsaChainTargets, registrationServerTimingHeaders, registrationSignerBranchesFromPlan, resolveRegistrationPreparedContextFromPlan, startD1RegistrationRouteTiming };
83
89
 
84
90
  //# sourceMappingURL=d1RegistrationSetupSupport.js.map
@@ -1,4 +1,4 @@
1
- import { mpcMaterialActivationRefsEqual, parseWalletId } from "../../../../shared-ts/src/utils/domainIds.js";
1
+ import { mpcMaterialActivationRefsEqual, parseWalletAuthMethodId, parseWalletAuthorityId, parseWalletId } from "../../../../shared-ts/src/utils/domainIds.js";
2
2
  import { normalizeOptionalTrimmedString } from "../../../../shared-ts/src/utils/normalize.js";
3
3
  import { parseWalletAuthMethodRecordV2, sameWalletAuthMethodRecordV2 } from "../../../../shared-ts/src/utils/walletAuthMethodRecord.js";
4
4
  import { parseWalletAuthorityV1 } from "../../../../shared-ts/src/authorization/walletAuthority.js";
@@ -123,32 +123,65 @@ function canExtendFoundingAuthorityWithEd25519(existing, next) {
123
123
  const nextEcdsa = next.signerActivations.ecdsa;
124
124
  return existing.signerActivations.keyFamilies.length === 1 && existing.signerActivations.keyFamilies[0] === "ecdsa_secp256k1" && next.signerActivations.keyFamilies.length === 2 && next.signerActivations.keyFamilies[0] === "ed25519" && next.signerActivations.keyFamilies[1] === "ecdsa_secp256k1" && existingEcdsa !== void 0 && nextEcdsa !== void 0 && sameWalletEcdsaSignerActivationV1(existingEcdsa, nextEcdsa) && foundingAuthorityIdentityMatches(existing, next) && next.updatedAtMs >= existing.updatedAtMs;
125
125
  }
126
- async function prepareFoundingStatements(input) {
127
- if (!input.foundingAuthority) return [];
128
- const foundingAuthMethod = requireFoundingAuthMethod(input.foundingAuthMethod);
129
- const authorityRead = input.database.prepare(`SELECT record_json
126
+ function parseRegistrationFoundingRead(result) {
127
+ if (!result.success) throw new Error("Registration founding records read failed");
128
+ const row = result.results?.[0];
129
+ if (!row) return null;
130
+ const authorityId = parseWalletAuthorityId(row.authority_id);
131
+ const authMethodId = parseWalletAuthMethodId(row.auth_method_id);
132
+ if (!authorityId.ok || !authMethodId.ok) throw new Error("Registration founding identity is invalid");
133
+ return {
134
+ kind: "snapshot",
135
+ records: {
136
+ walletAuthorityId: authorityId.value,
137
+ walletAuthMethodId: authMethodId.value,
138
+ authorityRow: row.authority_json === null ? null : { record_json: row.authority_json },
139
+ authMethodRow: row.auth_method_json === null ? null : { record_json: row.auth_method_json }
140
+ }
141
+ };
142
+ }
143
+ function readFoundingRecords(database, scope, founding) {
144
+ if (founding === null) return Promise.resolve(null);
145
+ switch (founding.kind) {
146
+ case "read": return readStoredFoundingRecords(database, scope, founding.ids);
147
+ case "snapshot": return Promise.resolve(founding.records);
148
+ }
149
+ }
150
+ async function readStoredFoundingRecords(database, scope, ids) {
151
+ const authorityRead = database.prepare(`SELECT record_json
130
152
  FROM wallet_authorities
131
153
  WHERE namespace = ?
132
154
  AND org_id = ?
133
155
  AND project_id = ?
134
156
  AND env_id = ?
135
157
  AND authority_id = ?
136
- LIMIT 1`).bind(input.scope.namespace, input.scope.orgId, input.scope.projectId, input.scope.envId, String(input.foundingAuthority.authorityId));
137
- const authMethodRead = input.database.prepare(`SELECT record_json
158
+ LIMIT 1`).bind(scope.namespace, scope.orgId, scope.projectId, scope.envId, String(ids.walletAuthorityId));
159
+ const authMethodRead = database.prepare(`SELECT record_json
138
160
  FROM wallet_auth_methods
139
161
  WHERE namespace = ?
140
162
  AND org_id = ?
141
163
  AND project_id = ?
142
164
  AND env_id = ?
143
165
  AND wallet_auth_method_id = ?
144
- LIMIT 1`).bind(input.scope.namespace, input.scope.orgId, input.scope.projectId, input.scope.envId, String(foundingAuthMethod.walletAuthMethodId));
145
- const results = await input.database.batch([authorityRead, authMethodRead]);
166
+ LIMIT 1`).bind(scope.namespace, scope.orgId, scope.projectId, scope.envId, String(ids.walletAuthMethodId));
167
+ const results = await database.batch([authorityRead, authMethodRead]);
146
168
  assertBatchSucceeded({
147
169
  expectedStatementCount: 2,
148
170
  results
149
171
  });
150
- const authorityRow = results[0]?.results?.[0] ?? null;
151
- const authMethodRow = results[1]?.results?.[0] ?? null;
172
+ return {
173
+ walletAuthorityId: ids.walletAuthorityId,
174
+ walletAuthMethodId: ids.walletAuthMethodId,
175
+ authorityRow: results[0]?.results?.[0] ?? null,
176
+ authMethodRow: results[1]?.results?.[0] ?? null
177
+ };
178
+ }
179
+ function prepareFoundingStatements(input) {
180
+ if (!input.foundingAuthority) return [];
181
+ const foundingAuthMethod = requireFoundingAuthMethod(input.foundingAuthMethod);
182
+ const { stored } = input;
183
+ if (!stored || String(stored.walletAuthorityId) !== String(input.foundingAuthority.authorityId) || String(stored.walletAuthMethodId) !== String(foundingAuthMethod.walletAuthMethodId)) throw new Error("A founding commit requires the records that its reservation read");
184
+ const { authorityRow, authMethodRow } = stored;
152
185
  let persistedAuthority = null;
153
186
  if (authorityRow) {
154
187
  const parsedAuthority = parseWalletAuthorityV1(parseD1JsonColumn(authorityRow.record_json));
@@ -187,7 +220,8 @@ async function prepareFoundingStatements(input) {
187
220
  if (!authMethodRow) statements.push(prepareD1WalletAuthMethodV2PutStatement({
188
221
  database: input.database,
189
222
  scope: input.scope,
190
- record: foundingAuthMethod
223
+ record: foundingAuthMethod,
224
+ insertOnly: true
191
225
  }));
192
226
  return statements;
193
227
  }
@@ -210,13 +244,13 @@ var CloudflareD1WalletRegistrationCommitStore = class {
210
244
  this.database = input.database;
211
245
  this.scope = normalizeScope(input);
212
246
  }
213
- async reserveAuthority(authority, held = null) {
214
- if (authority.kind === "passkey" && !heldClaimCovers(held, authority)) await reservePasskeyCredential(this.credentialClaims, {
247
+ async reserveAuthority(authority, held, founding) {
248
+ const [, stored] = await Promise.all([authority.kind === "passkey" && !heldClaimCovers(held, authority) ? reservePasskeyCredential(this.credentialClaims, {
215
249
  walletId: authority.walletId,
216
250
  rpId: authority.rpId,
217
251
  credentialIdB64u: authority.credentialIdB64u
218
- });
219
- return this.commit.bind(this, authority);
252
+ }) : void 0, readFoundingRecords(this.database, this.scope, founding)]);
253
+ return this.commit.bind(this, authority, stored);
220
254
  }
221
255
  async claimPasskeyAhead(input) {
222
256
  const { authority } = input;
@@ -259,7 +293,7 @@ var CloudflareD1WalletRegistrationCommitStore = class {
259
293
  AND env_id = ?4
260
294
  AND registration_ceremony_id = ?5`).bind(this.scope.namespace, this.scope.orgId, this.scope.projectId, this.scope.envId, registrationCeremonyId).run();
261
295
  }
262
- async commit(authority, input, executeBatch) {
296
+ async commit(authority, stored, input, executeBatch) {
263
297
  assertCommitWalletIdentity(input, authority);
264
298
  const fenced = [];
265
299
  const ed25519Signer = input.walletSigners.find(isEd25519Signer);
@@ -283,7 +317,7 @@ var CloudflareD1WalletRegistrationCommitStore = class {
283
317
  scope: this.scope
284
318
  }, new Set([capabilityWallet.value, input.wallet.walletId])));
285
319
  }
286
- const prepared = await prepareWalletWrite(this.database, this.scope, authority, input);
320
+ const prepared = prepareWalletWrite(this.database, this.scope, authority, input, stored);
287
321
  const statements = [...fenced, ...prepared.statements];
288
322
  const results = executeBatch ? await executeBatch(statements) : await this.database.batch(statements);
289
323
  assertBatchSucceeded({
@@ -292,12 +326,13 @@ var CloudflareD1WalletRegistrationCommitStore = class {
292
326
  });
293
327
  }
294
328
  };
295
- async function prepareWalletWrite(database, scope, authority, input) {
296
- const foundingStatements = await prepareFoundingStatements({
329
+ function prepareWalletWrite(database, scope, authority, input, stored) {
330
+ const foundingStatements = prepareFoundingStatements({
297
331
  database,
298
332
  scope,
299
333
  foundingAuthority: input.foundingAuthority,
300
334
  foundingAuthMethod: input.foundingAuthMethod,
335
+ stored,
301
336
  now: input.now
302
337
  });
303
338
  const statements = [prepareD1WalletPutSubjectStatement({
@@ -326,6 +361,6 @@ function isEd25519Signer(signer) {
326
361
  return signer.version === "wallet_signer_ed25519_v1";
327
362
  }
328
363
  //#endregion
329
- export { CloudflareD1WalletRegistrationCommitStore };
364
+ export { CloudflareD1WalletRegistrationCommitStore, parseRegistrationFoundingRead };
330
365
 
331
366
  //# sourceMappingURL=d1WalletRegistrationCommitStore.js.map
@@ -1,12 +1,15 @@
1
+ import { parseRouterAbEd25519YaoRegistrationAdmissionReadV1 } from "../../../domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitionedStateStore.js";
2
+ import { parseRegistrationFoundingRead } from "./d1WalletRegistrationCommitStore.js";
1
3
  //#region src/router/cloudflare/d1/registration/d1WalletRegistrationRead.ts
2
4
  /** Read admission and immutable finalization state from one D1 snapshot. */
3
5
  var D1WalletRegistrationRead = class {
4
- constructor(database, authority, operations, getCeremonies, decisions, passkeyClaims) {
6
+ constructor(database, authority, operations, getCeremonies, decisions, yaoRecords, passkeyClaims) {
5
7
  this.database = database;
6
8
  this.authority = authority;
7
9
  this.operations = operations;
8
10
  this.getCeremonies = getCeremonies;
9
11
  this.decisions = decisions;
12
+ this.yaoRecords = yaoRecords;
10
13
  this.passkeyClaims = passkeyClaims;
11
14
  }
12
15
  async readRespond(home) {
@@ -39,21 +42,28 @@ var D1WalletRegistrationRead = class {
39
42
  this.operations.prepareRead(operationKey),
40
43
  ceremonies.prepareCeremonyRead(home.ceremonyId),
41
44
  this.decisions.prepareRead(home.ceremonyId),
42
- this.passkeyClaims.prepareHeldPasskeyClaimRead(home.ceremonyId)
45
+ this.passkeyClaims.prepareHeldPasskeyClaimRead(home.ceremonyId),
46
+ this.yaoRecords.prepareRead(home.ceremonyId),
47
+ ceremonies.prepareFoundingRecordsRead(home.ceremonyId)
43
48
  ]);
44
- const [homeRead, operationRead, ceremonyRead, decisionRead, passkeyClaimRead] = results;
45
- if (results.length !== 5 || !homeRead || !operationRead || !ceremonyRead || !decisionRead || !passkeyClaimRead) throw new Error("Registration finalization D1 batch returned incomplete results");
49
+ const [homeRead, operationRead, ceremonyRead, decisionRead, passkeyClaimRead, yaoRead, foundingRead] = results;
50
+ if (results.length !== 7 || !homeRead || !operationRead || !ceremonyRead || !decisionRead || !passkeyClaimRead || !yaoRead || !foundingRead) throw new Error("Registration finalization D1 batch returned incomplete results");
46
51
  const admission = await this.authority.admitHomeRead(home, homeRead);
47
52
  if (!admission.ok) return admission;
48
53
  if (!ceremonyRead.success) throw new Error("Registration ceremony D1 read failed");
49
54
  return {
50
55
  ok: true,
51
56
  operation: this.operations.parseReadResult(operationRead),
57
+ readFounding: parseRegistrationFoundingRead.bind(void 0, foundingRead),
52
58
  decision: this.decisions.parseRead(home.ceremonyId, decisionRead),
53
59
  heldPasskeyClaim: this.passkeyClaims.parseHeldPasskeyClaimRead(passkeyClaimRead),
54
- readCeremony: ceremonies.parseCeremonyRead.bind(ceremonies, home.ceremonyId, ceremonyRead)
60
+ readCeremony: ceremonies.parseCeremonyRead.bind(ceremonies, home.ceremonyId, ceremonyRead),
61
+ readYaoAdmission: this.parseYaoAdmission.bind(this, home.ceremonyId, yaoRead)
55
62
  };
56
63
  }
64
+ parseYaoAdmission(ceremonyId, result) {
65
+ return parseRouterAbEd25519YaoRegistrationAdmissionReadV1(ceremonyId, this.yaoRecords.parseReadResult(result));
66
+ }
57
67
  };
58
68
  //#endregion
59
69
  export { D1WalletRegistrationRead };