@seams/wallet-server 0.8.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD_PARTY_NOTICES.md +7 -1
- package/artifact-manifest.json +196 -41
- package/cloudflare-router-ab/build/deriver-a/build-stamp.json +1 -1
- package/cloudflare-router-ab/build/deriver-a/index.js +2 -2
- package/cloudflare-router-ab/build/deriver-a/index_bg.wasm +0 -0
- package/cloudflare-router-ab/build/deriver-b/build-stamp.json +1 -1
- package/cloudflare-router-ab/build/deriver-b/index.js +2 -2
- package/cloudflare-router-ab/build/deriver-b/index_bg.wasm +0 -0
- package/cloudflare-router-ab/build/local-tools/darwin-arm64/router_ab_local_init +0 -0
- package/cloudflare-router-ab/build/local-tools/darwin-x64/router_ab_local_init +0 -0
- package/cloudflare-router-ab/build/local-tools/linux-x64/router_ab_local_init +0 -0
- package/cloudflare-router-ab/build/router/build-stamp.json +1 -1
- package/cloudflare-router-ab/build/router/index.js +2 -2
- package/cloudflare-router-ab/build/router/index_bg.wasm +0 -0
- package/cloudflare-router-ab/build/signing-worker/build-stamp.json +1 -1
- package/cloudflare-router-ab/build/signing-worker/index.js +2 -2
- package/cloudflare-router-ab/build/signing-worker/index_bg.wasm +0 -0
- package/cloudflare-router-ab/build/tenant-root-control-plane/build-stamp.json +1 -1
- package/cloudflare-router-ab/build/tenant-root-control-plane/index.js +2 -2
- package/cloudflare-router-ab/build/tenant-root-control-plane/index_bg.wasm +0 -0
- package/cloudflare-router-ab/migrations/deriver-a/0019_wallet_object_addresses.sql +10 -0
- package/cloudflare-router-ab/migrations/deriver-b/0019_wallet_object_addresses.sql +10 -0
- package/cloudflare-router-ab/scripts/prepare-local-runtime-config.mjs +3 -117
- package/cloudflare-router-ab/wrangler.deriver-a.toml +0 -8
- package/cloudflare-router-ab/wrangler.deriver-b.toml +24 -8
- package/cloudflare-router-ab/wrangler.router.toml +0 -2
- package/cloudflare-router-ab/wrangler.signing-worker.toml +29 -0
- package/dist/esm/authorization/domain.js +3 -2
- package/dist/esm/authorization/ed25519WalletSessionAdmission.js +0 -0
- package/dist/esm/authorization/service.js +64 -36
- package/dist/esm/cloud-host.js +24 -19
- package/dist/esm/core/EmailOtpRecords.js +29 -6
- package/dist/esm/core/ThresholdService/routerAb/ecdsaDerivationPoolFillHandlers.js +2 -0
- package/dist/esm/core/ThresholdService/routerAb/ecdsaDerivationPresignBridge.js +10 -0
- package/dist/esm/core/ThresholdService/routerAb/internalServiceHttp.js +1 -0
- package/dist/esm/core/ThresholdService/validation.js +2 -2
- package/dist/esm/core/authService/nearPrivateKeySigning.js +1 -1
- package/dist/esm/core/authService/webauthn.js +1 -1
- package/dist/esm/core/d1Ed25519SignerRead.js +55 -0
- package/dist/esm/core/d1WalletStore.js +14 -11
- package/dist/esm/core/deviceLinking/linkedDeviceEmailOtpGrant.js +2 -2
- package/dist/esm/core/deviceLinking/linkedDeviceManagement.js +1 -1
- package/dist/esm/core/deviceLinking/linkedDeviceSessionRecord.js +2 -2
- package/dist/esm/core/emailOtpD1Statements.js +1 -0
- package/dist/esm/core/nearRelayerAccountProvisioning.js +1 -1
- package/dist/esm/core/routerAbSigning/RouterAbEcdsaPresignRuntime.js +4 -0
- package/dist/esm/core/signingLanes/WalletExecutionLaneProjection.js +1 -1
- package/dist/esm/core/signingMaterial/ordinaryInactiveSignerMaterialReservation.js +1 -0
- package/dist/esm/hosted-wallet-gateway.js +93 -10
- package/dist/esm/localHostedWalletGatewayHandler.js +12 -9
- package/dist/esm/localIntendedYaoSigningFault.js +2 -30
- package/dist/esm/localRegistrationSetupAuthority.js +8 -1
- package/dist/esm/router/auth/commonRouterUtils.js +17 -10
- package/dist/esm/router/auth/routerApiCredentialAuth.js +26 -7
- package/dist/esm/router/auth/walletRegistrationContext.js +49 -0
- package/dist/esm/router/auth/webAuthnCredentialCodecs.js +1 -1
- package/dist/esm/router/cloudflare/d1/auth/d1AuthorizationAssembly.js +4 -3
- package/dist/esm/router/cloudflare/d1/auth/d1AuthorizedOperationRouteService.js +2 -0
- package/dist/esm/router/cloudflare/d1/auth/d1EmailOtpRouteService.js +25 -0
- package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthConfig.js +14 -6
- package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthService.js +44 -40
- package/dist/esm/router/cloudflare/d1/auth/walletSessionCredentialReaders.js +17 -1
- package/dist/esm/router/cloudflare/d1/authorization/authorizedOperationStatements.js +35 -5
- package/dist/esm/router/cloudflare/d1/authorization/d1AuthorizationStore.js +258 -99
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceAuthorityInstallService.js +31 -4
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceOwnerAuthorizationProvider.js +1 -1
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceRequestProofNonceStore.js +1 -1
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionRecords.js +1 -1
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetCredentialProvider.js +1 -1
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetPlanner.js +1 -1
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceVerifiedLinkBuilder.js +1 -1
- package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoLifecycleDecisionStore.js +11 -2
- package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoProductRegistrationPartitionedStateStore.js +100 -10
- package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoStateWriteFence.js +92 -0
- package/dist/esm/router/cloudflare/d1/ed25519Yao/d1WalletCeremonyActivity.js +77 -0
- package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeIssuer.js +14 -8
- package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeStore.js +14 -8
- package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeVerifier.js +3 -1
- package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRateLimitStore.js +58 -38
- package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRecords.js +27 -20
- package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRecoveryService.js +1 -0
- package/dist/esm/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpSessionResolver.js +1 -0
- package/dist/esm/router/cloudflare/d1/oidc/d1OidcBoundary.js +1 -1
- package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletCustodyCommitStore.js +18 -7
- package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyRecordStore.js +75 -14
- package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyRecords.js +1 -1
- package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyStore.js +49 -29
- package/dist/esm/router/cloudflare/d1/registration/d1RegistrationSessionTransaction.js +28 -0
- package/dist/esm/router/cloudflare/d1/registration/d1RegistrationSetupSupport.js +11 -1
- package/dist/esm/router/cloudflare/d1/registration/d1WalletExecutionAuthority.js +168 -0
- package/dist/esm/router/cloudflare/d1/registration/d1WalletOperationStore.js +53 -0
- package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationCommitStore.js +83 -42
- package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationInitialSession.js +33 -0
- package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationPreparation.js +16 -0
- package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationRead.js +58 -0
- package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationService.js +439 -500
- package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationSetup.js +1 -1
- package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationSetupExecution.js +104 -90
- package/dist/esm/router/cloudflare/d1/registration/walletRegistrationEstablishedSessionIssuer.js +78 -44
- package/dist/esm/router/cloudflare/d1/registration/walletRegistrationSessionCommitReceipt.js +11 -35
- package/dist/esm/router/cloudflare/d1/signingAdmission/d1RouterAbNormalSigningAdmissionStore.js +98 -39
- package/dist/esm/router/cloudflare/d1/versionedJson/d1VersionedJsonRecordStore.js +12 -9
- package/dist/esm/router/cloudflare/d1/wallet/authorizationSnapshotLayout.js +168 -0
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletAddSignerFinalizeRecord.js +1 -1
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletAddSignerService.js +15 -6
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthMethodService.js +3 -40
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorityStore.js +54 -1
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorizationCleanup.js +157 -0
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorizationFreeze.js +56 -0
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorizationHistory.js +238 -0
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorizationIntake.js +287 -0
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorizationSnapshot.js +295 -0
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationApprovals.js +140 -0
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationChallenges.js +170 -0
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationEmailOtp.js +60 -0
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationOwner.js +33 -0
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationOwnerRequest.js +74 -0
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationPasskey.js +77 -0
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationReadAccess.js +37 -0
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationSessions.js +97 -0
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationWriteBlock.js +133 -0
- package/dist/esm/router/cloudflare/d1/walletObjectAddresses.js +47 -0
- package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnAuthService.js +1 -1
- package/dist/esm/router/cloudflare/runtime/routerAbServiceBindings.js +32 -1
- package/dist/esm/router/cloudflare/runtime/staticWalletConsoleBinding.js +20 -8
- package/dist/esm/router/cloudflare/runtime/walletAuthorizationRelocationRoutes.js +488 -0
- package/dist/esm/router/cloudflare/runtime/walletConsoleOps.js +1 -1
- package/dist/esm/router/cloudflare/runtime/walletConsoleOpsClient.js +26 -6
- package/dist/esm/router/cloudflare/runtime/walletControlOps.js +3 -0
- package/dist/esm/router/cloudflare/runtime/walletGateway.js +1 -1
- package/dist/esm/router/cloudflare/runtime/walletObjectAddresses.js +105 -0
- package/dist/esm/router/cloudflare/runtime/walletPlacementRoutes.js +339 -0
- package/dist/esm/router/cloudflare/runtime/walletRelocationDeriver.js +244 -0
- package/dist/esm/router/cloudflare/runtime/walletRelocationEcdsa.js +212 -0
- package/dist/esm/router/cloudflare/runtime/walletRelocationEd25519.js +172 -0
- package/dist/esm/router/cloudflare/runtime/walletRelocationOps.js +183 -0
- package/dist/esm/router/cloudflare/runtime/walletRelocationPresign.js +185 -0
- package/dist/esm/router/cloudflare/runtime/walletRelocationSource.js +221 -0
- package/dist/esm/router/cloudflare/signingLanes/cloudflareOrdinaryInactiveSignerMaterialReservation.js +30 -8
- package/dist/esm/router/cloudflare-adaptor.js +8 -8
- package/dist/esm/router/cloudflare.js +34115 -32240
- package/dist/esm/router/domains/ecdsa/routerAbEcdsaStrictRegistration.js +35 -9
- package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoCapabilityCommit.js +42 -0
- package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.js +32 -6
- package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitionedStateStore.js +61 -1
- package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPersistence.js +70 -3
- package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRuntime.js +59 -87
- package/dist/esm/router/domains/ed25519Yao/export/routerAbEd25519YaoExport.js +52 -22
- package/dist/esm/router/domains/ed25519Yao/export/routerAbEd25519YaoExportRequestScopedCloudflare.js +10 -7
- package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecovery.js +108 -78
- package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryRequestScopedCloudflare.js +19 -5
- package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryWalletSessionAuthorization.js +71 -22
- package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoHttpRegistrationBackend.js +37 -25
- package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistration.js +3 -3
- package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationExecutionRecord.js +2 -1
- package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationIntentAuthorization.js +24 -3
- package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationRequestScopedCloudflare.js +4 -3
- package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.js +20 -7
- package/dist/esm/router/domains/ed25519Yao/routerAbEd25519YaoGatewayEnvelope.js +7 -1
- package/dist/esm/router/domains/emailOtp/emailOtpRouteHandlers.js +2 -2
- package/dist/esm/router/domains/passkeyCustody/passkeyCustodyEnvelopeRetrieval.js +1 -1
- package/dist/esm/router/domains/passkeyCustody/registrationCustodyOutcome.js +34 -18
- package/dist/esm/router/domains/passkeyCustody/walletCustodyRegistrationAdmission.js +2 -2
- package/dist/esm/router/domains/passkeyCustody/walletCustodyRegistrationCommit.js +16 -6
- package/dist/esm/router/domains/signingOperations/authorizedOperationWire.js +73 -0
- package/dist/esm/router/domains/signingOperations/ecdsaSigningResponse.js +31 -0
- package/dist/esm/router/domains/signingOperations/ed25519AuthorizedOperationReceipt.js +1 -1
- package/dist/esm/router/domains/signingOperations/routerAbEcdsaDerivationNormalSigningRoute.js +2 -1
- package/dist/esm/router/domains/signingOperations/routerAbEd25519NormalSigningRoute.js +31 -121
- package/dist/esm/router/domains/signingOperations/routerAbNormalSigningAdmission.js +2 -93
- package/dist/esm/router/domains/signingOperations/routerAbPrivateSigningWorker.js +1 -1
- package/dist/esm/router/domains/signingOperations/signingPrepareSession.js +33 -0
- package/dist/esm/router/domains/walletRegistration/registrationSessionSeal.js +121 -0
- package/dist/esm/router/domains/walletRegistration/walletRegistrationReservation.js +4 -4
- package/dist/esm/router/domains/walletRegistration/walletRegistrationRoutes.js +46 -157
- package/dist/esm/router/domains/walletRegistration/walletRegistrationSetupPayload.js +1 -1
- package/dist/esm/router/express.js +764 -894
- package/dist/esm/router/framework/http.js +2 -1
- package/dist/esm/router/transport/fetch/createFetchRouter.js +2 -2
- package/dist/esm/router/transport/fetch/routes/auth.js +1 -1
- package/dist/esm/router/transport/fetch/routes/deviceLinking.js +3 -3
- package/dist/esm/router/transport/fetch/routes/deviceLinkingOwnerAuthorization.js +2 -2
- package/dist/esm/router/transport/fetch/routes/ed25519AuthorizedOperationRevalidation.js +65 -0
- package/dist/esm/router/transport/fetch/routes/normalSigningRouterProxy.js +13 -3
- package/dist/esm/router/transport/fetch/routes/passkeyCustody.js +3 -3
- package/dist/esm/router/transport/fetch/routes/sessions.js +3 -2
- package/dist/esm/router/transport/fetch/routes/thresholdEcdsa.js +67 -130
- package/dist/esm/router/transport/fetch/routes/thresholdEd25519.js +76 -212
- package/dist/esm/router/transport/fetch/routes/walletExecutionLanePreflight.js +18 -41
- package/dist/esm/router/transport/fetch/routes/walletRegistration.js +6 -5
- package/dist/esm/router/transport/fetch/routes/webauthnAuthenticators.js +1 -1
- package/dist/esm/shared-ts/src/authorization/index.js +1 -1
- package/dist/esm/shared-ts/src/authorization/walletAuthority.js +2 -2
- package/dist/esm/shared-ts/src/device-linking/activeWalletSession.js +12 -2
- package/dist/esm/shared-ts/src/device-linking/digests.js +1 -1
- package/dist/esm/shared-ts/src/device-linking/ed25519ExportRoot.js +1 -1
- package/dist/esm/shared-ts/src/device-linking/index.js +1 -1
- package/dist/esm/shared-ts/src/device-linking/parsers.js +1 -1
- package/dist/esm/shared-ts/src/device-linking/sourceContribution.js +1 -1
- package/dist/esm/shared-ts/src/device-linking/wireFields.js +1 -1
- package/dist/esm/shared-ts/src/near/nearClient.js +1 -1
- package/dist/esm/shared-ts/src/signing-lanes/ownerContinuity.js +2 -2
- package/dist/esm/shared-ts/src/utils/ecdsaServerTiming.js +6 -1
- package/dist/esm/shared-ts/src/utils/emailOtpDomain.js +4 -2
- package/dist/esm/shared-ts/src/utils/routerAbEcdsaDerivation.js +1 -1
- package/dist/esm/shared-ts/src/utils/routerAbPublicKeyset.js +0 -27
- package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryEcdsaPossession.js +1 -1
- package/dist/esm/threshold/session/signingSessionSeal/options.js +1 -1
- package/dist/esm/wasm/near_signer/pkg/wasm_signer_worker_bg.wasm +0 -0
- package/dist/types/shared-ts/src/device-linking/activeWalletSession.d.ts +2 -1
- package/dist/types/shared-ts/src/device-linking/contracts.d.ts +10 -0
- package/dist/types/shared-ts/src/threshold/ed25519OperationFingerprint.d.ts +2 -1
- package/dist/types/shared-ts/src/utils/emailOtpDomain.d.ts +3 -1
- package/dist/types/shared-ts/src/utils/routerAbPublicKeyset.d.ts +0 -9
- package/dist/types/shared-ts/src/utils/walletManagementProtocol.d.ts +1 -1
- package/dist/types/wallet-server/src/authorization/domain.d.ts +17 -1
- package/dist/types/wallet-server/src/authorization/ecdsaWalletSessionAdmission.d.ts +1 -0
- package/dist/types/wallet-server/src/authorization/ed25519WalletSessionAdmission.d.ts +35 -0
- package/dist/types/wallet-server/src/authorization/ed25519WalletSessionAdmission.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/authorization/service.d.ts +43 -5
- package/dist/types/wallet-server/src/authorization/sessionRouting.d.ts +2 -0
- package/dist/types/wallet-server/src/cloud-host.d.ts +7 -3
- package/dist/types/wallet-server/src/core/EmailOtpRecords.d.ts +2 -1
- package/dist/types/wallet-server/src/core/EmailOtpStores.d.ts +19 -5
- package/dist/types/wallet-server/src/core/ThresholdService/routerAb/ecdsaDerivationPoolFillHandlers.d.ts +1 -0
- package/dist/types/wallet-server/src/core/ThresholdService/routerAb/ecdsaDerivationPresignBridge.d.ts +6 -0
- package/dist/types/wallet-server/src/core/ThresholdService/routerAb/internalServiceHttp.d.ts +1 -0
- package/dist/types/wallet-server/src/core/d1Ed25519SignerRead.d.ts +17 -0
- package/dist/types/wallet-server/src/core/d1WalletStore.d.ts +6 -0
- package/dist/types/wallet-server/src/core/emailOtpD1Statements.d.ts +1 -0
- package/dist/types/wallet-server/src/core/routerAbSigning/RouterAbEcdsaPresignRuntime.d.ts +5 -1
- package/dist/types/wallet-server/src/core/signingMaterial/ordinaryInactiveSignerMaterialReservation.d.ts +1 -0
- package/dist/types/wallet-server/src/core/threeRouteRegistrationContracts.d.ts +14 -48
- package/dist/types/wallet-server/src/hosted-wallet-gateway.d.ts +4 -3
- package/dist/types/wallet-server/src/localIntendedYaoSigningFault.d.ts +1 -16
- package/dist/types/wallet-server/src/localRegistrationSetupAuthority.d.ts +1 -1
- package/dist/types/wallet-server/src/router/auth/commonRouterUtils.d.ts +7 -1
- package/dist/types/wallet-server/src/router/auth/routerApiCredentialAuth.d.ts +11 -3
- package/dist/types/wallet-server/src/router/auth/walletRegistrationContext.d.ts +8 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1AuthorizationAssembly.d.ts +1 -1
- package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1EmailOtpRouteService.d.ts +16 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthConfig.d.ts +7 -4
- package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthService.d.ts +4 -1
- package/dist/types/wallet-server/src/router/cloudflare/d1/auth/walletSessionCredentialReaders.d.ts +7 -1
- package/dist/types/wallet-server/src/router/cloudflare/d1/authorization/d1AuthorizationStore.d.ts +32 -1
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceAuthorityInstallService.d.ts +2 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoLifecycleDecisionStore.d.ts +3 -1
- package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoProductRegistrationPartitionedStateStore.d.ts +1 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoStateWriteFence.d.ts +8 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1WalletCeremonyActivity.d.ts +15 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeIssuer.d.ts +6 -1
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeStore.d.ts +1 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeVerifier.d.ts +4 -1
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpCounters.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRateLimitStore.d.ts +6 -29
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRecords.d.ts +21 -7
- package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1WalletCustodyCommitStore.d.ts +17 -1
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyRecordStore.d.ts +32 -7
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyStore.d.ts +16 -7
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationSessionTransaction.d.ts +13 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationSetupSupport.d.ts +7 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletExecutionAuthority.d.ts +41 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletOperationStore.d.ts +28 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationCommitStore.d.ts +6 -9
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationInitialSession.d.ts +17 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationPreparation.d.ts +12 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationRead.d.ts +43 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationService.d.ts +24 -45
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationSetupExecution.d.ts +9 -4
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/walletRegistrationEstablishedSessionIssuer.d.ts +42 -14
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/walletRegistrationSessionCommitReceipt.d.ts +5 -4
- package/dist/types/wallet-server/src/router/cloudflare/d1/signingAdmission/d1RouterAbNormalSigningAdmissionStore.d.ts +24 -1
- package/dist/types/wallet-server/src/router/cloudflare/d1/versionedJson/d1VersionedJsonRecordStore.d.ts +10 -4
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/authorizationSnapshotLayout.d.ts +21 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAddSignerService.d.ts +3 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthMethodService.d.ts +3 -7
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorityStore.d.ts +8 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorizationCleanup.d.ts +20 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorizationFreeze.d.ts +12 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorizationHistory.d.ts +20 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorizationIntake.d.ts +29 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorizationSnapshot.d.ts +31 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationApprovals.d.ts +49 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationChallenges.d.ts +47 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationEmailOtp.d.ts +25 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationOwner.d.ts +88 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationOwnerRequest.d.ts +37 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationPasskey.d.ts +12 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationReadAccess.d.ts +18 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationSessions.d.ts +23 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationWriteBlock.d.ts +16 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/walletObjectAddresses.d.ts +14 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/routerAbServiceBindings.d.ts +13 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletAuthorizationRelocationRoutes.d.ts +21 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletConsoleOps.d.ts +1 -1
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletConsoleOpsClient.d.ts +3 -3
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletControlOps.d.ts +2 -1
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletGateway.d.ts +3 -1
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletObjectAddresses.d.ts +45 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletPlacementRoutes.d.ts +30 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRelocationDeriver.d.ts +11 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRelocationEcdsa.d.ts +7 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRelocationEd25519.d.ts +7 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRelocationOps.d.ts +11 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRelocationPresign.d.ts +7 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRelocationSource.d.ts +26 -0
- package/dist/types/wallet-server/src/router/cloudflare/signingLanes/cloudflareOrdinaryInactiveSignerMaterialReservation.d.ts +5 -0
- package/dist/types/wallet-server/src/router/domains/ecdsa/routerAbEcdsaStrictRegistration.d.ts +3 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoCapabilityCommit.d.ts +7 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.d.ts +41 -7
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitionedStateStore.d.ts +33 -2
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/export/routerAbEd25519YaoExport.d.ts +12 -6
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecovery.d.ts +17 -9
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryWalletSessionAuthorization.d.ts +2 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoHttpRegistrationBackend.d.ts +13 -14
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistration.d.ts +7 -3
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationExecutionRecord.d.ts +1 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationIntentAuthorization.d.ts +6 -1
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.d.ts +11 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/routerAbEd25519YaoGatewayEnvelope.d.ts +12 -3
- package/dist/types/wallet-server/src/router/domains/passkeyCustody/registrationCustodyOutcome.d.ts +10 -6
- package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletCustodyRegistrationAdmission.d.ts +10 -3
- package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletCustodyRegistrationCommit.d.ts +12 -5
- package/dist/types/wallet-server/src/router/domains/signingOperations/authorizedOperationWire.d.ts +97 -0
- package/dist/types/wallet-server/src/router/domains/signingOperations/ecdsaSigningResponse.d.ts +13 -0
- package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbNormalSigningAdmission.d.ts +9 -206
- package/dist/types/wallet-server/src/router/domains/signingOperations/signingPrepareSession.d.ts +23 -0
- package/dist/types/wallet-server/src/router/domains/walletRegistration/registrationSessionSeal.d.ts +36 -0
- package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationInputs.d.ts +7 -7
- package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationReservation.d.ts +80 -6
- package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationRoutes.d.ts +15 -5
- package/dist/types/wallet-server/src/router/framework/apiCredentialPorts.d.ts +24 -0
- package/dist/types/wallet-server/src/router/framework/authServicePort.d.ts +21 -7
- package/dist/types/wallet-server/src/router/framework/routerApi.d.ts +3 -12
- package/dist/types/wallet-server/src/router/transport/fetch/routes/ed25519AuthorizedOperationRevalidation.d.ts +37 -0
- package/dist/types/wallet-server/src/router/transport/fetch/routes/thresholdEcdsa.d.ts +1 -17
- package/dist/types/wallet-server/src/storage/tenantRoute.d.ts +1 -1
- package/migrations/d1-signer/0049_wallet_relocation_challenges.sql +16 -0
- package/migrations/d1-signer/0050_wallet_relocation_approvals.sql +14 -0
- package/migrations/d1-signer/0051_wallet_relocation_email_otp.sql +92 -0
- package/migrations/d1-signer/0052_wallet_relocation_session_fences.sql +91 -0
- package/migrations/d1-signer/0053_wallet_hosted_history_import.sql +164 -0
- package/migrations/d1-signer/0054_wallet_authorization_freeze.sql +318 -0
- package/migrations/d1-signer/0055_wallet_authorization_snapshot.sql +120 -0
- package/migrations/d1-signer/0056_wallet_authorization_history_import.sql +424 -0
- package/migrations/d1-signer/0057_wallet_authorization_intake.sql +44 -0
- package/migrations/d1-signer/0058_wallet_ceremony_activity.sql +59 -0
- package/migrations/d1-signer/0059_wallet_authorization_activation.sql +45 -0
- package/migrations/d1-signer/0060_wallet_authorization_cleanup.sql +153 -0
- package/migrations/d1-signer/0061_wallet_session_operation_settlement.sql +28 -0
- package/migrations/d1-signer/0062_wallet_step_up_operation_settlement.sql +204 -0
- package/migrations/d1-signer/0063_wallet_operation_history_transfer.sql +466 -0
- package/migrations/d1-signer/0064_wallet_execution_generations.sql +93 -0
- package/migrations/d1-signer/0065_wallet_operation_execution_generation.sql +37 -0
- package/migrations/d1-signer/0066_regional_deployment_admission.sql +59 -0
- package/migrations/d1-signer/0067_registration_completion_decision.sql +12 -0
- package/migrations/d1-signer/0068_registration_cancellation_write_fence.sql +24 -0
- package/migrations/d1-signer/0069_cancelled_registration_session_fence.sql +11 -0
- package/migrations/d1-signer/0070_wallet_passkey_relocation.sql +369 -0
- package/migrations/d1-signer/0071_regional_wallet_otp_counters.sql +98 -0
- package/migrations/d1-signer/0072_linked_device_relocation_history.sql +899 -0
- package/migrations/d1-signer/0073_wallet_recovery_relocation.sql +86 -0
- package/migrations/d1-signer/0074_email_otp_relocation.sql +158 -0
- package/migrations/d1-signer/0075_wallet_authorization_return.sql +107 -0
- package/migrations/d1-signer/0076_wallet_relocation_write_block.sql +406 -0
- package/migrations/d1-signer/0077_wallet_object_addresses.sql +24 -0
- package/package.json +1 -1
- package/src/README.md +23 -1
- package/cloudflare-router-ab/scripts/local-key-material.mjs +0 -29
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { mpcMaterialActivationRefsEqual, parseThresholdEd25519SessionId, parseWalletKeyId, parseWebAuthnCredentialIdB64u } from "../../../../shared-ts/src/utils/domainIds.js";
|
|
2
2
|
import { parseWalletSessionMintId } from "../../../../shared-ts/src/authorization/capabilityKinds.js";
|
|
3
|
+
import { normalizeOptionalTrimmedString } from "../../../../shared-ts/src/utils/normalize.js";
|
|
4
|
+
import { buildFullOwnerPermissionsV1 } from "../../../../shared-ts/src/authorization/delegatedAuthority.js";
|
|
3
5
|
import { base64UrlDecode, base64UrlEncode } from "../../../../shared-ts/src/utils/base64.js";
|
|
4
6
|
import { alphabetizeStringify, bytesToUnprefixedHex, sha256BytesUtf8 } from "../../../../shared-ts/src/utils/digests.js";
|
|
5
7
|
import { parseDigestB64u } from "../../../../shared-ts/src/utils/canonicalPrimitives.js";
|
|
6
|
-
import "../../../../shared-ts/src/utils/encoders.js";
|
|
7
|
-
import { normalizeOptionalTrimmedString } from "../../../../shared-ts/src/utils/normalize.js";
|
|
8
|
-
import { buildFullOwnerPermissionsV1 } from "../../../../shared-ts/src/authorization/delegatedAuthority.js";
|
|
9
8
|
import { parseEd25519PublicKeyB64u, parseSecp256k1CompressedPublicKeyB64u } from "../../../../shared-ts/src/passkey-custody/primitives.js";
|
|
9
|
+
import "../../../../shared-ts/src/utils/encoders.js";
|
|
10
10
|
import { buildExactAdministeredSignerManifestV1 } from "../../../../shared-ts/src/device-linking/delegatedActivationPlan.js";
|
|
11
11
|
import { routerAbMpcMaterialActivationRefFromWire, routerAbMpcMaterialActivationRefToWire, sameRouterAbMpcMaterialActivationRef } from "../../../../shared-ts/src/utils/routerAbNormalSigningIdentity.js";
|
|
12
12
|
import { deriveRouterAbEd25519YaoRuntimePolicyBindingV1 } from "../../../../shared-ts/src/utils/routerAbEd25519YaoDigests.js";
|
|
@@ -20,13 +20,12 @@ import { buildActiveWalletAuthorityV1, buildWalletSignerActivationSetV1, compute
|
|
|
20
20
|
import { ROUTER_AB_ED25519_NORMAL_SIGNING_STATE_KIND } from "../../../../shared-ts/src/utils/signingSessionSeal.js";
|
|
21
21
|
import { normalizeThresholdEd25519ParticipantIds } from "../../../../shared-ts/src/threshold/participants.js";
|
|
22
22
|
import { nearEd25519SigningKeyIdFromString, registrationEd25519AuthorityScopeFromAuthority, walletIdFromString } from "../../../../shared-ts/src/utils/registrationIds.js";
|
|
23
|
-
import { buildTenantRootIdentityFromAuthenticatedDeploymentV1 } from "../../../../shared-ts/src/tenant-root/tenantRootIdentity.js";
|
|
24
23
|
import { walletCustodyCeremonyCommitPayloadFromWire } from "../../../../shared-ts/src/passkey-custody/ceremonyCommitPayload.js";
|
|
25
24
|
import "../../../../shared-ts/src/passkey-custody/index.js";
|
|
26
|
-
import { computeWalletRegistrationSetupDigestB64u, parseWalletRegistrationSetupClaims, verifySignedWalletRegistrationSetup, verifyWalletRegistrationSetupClaims } from "../../../domains/walletRegistration/walletRegistrationSetupPayload.js";
|
|
27
25
|
import { parseImplicitNearAccountId, parseNamedNearAccountId } from "../../../../shared-ts/src/utils/near.js";
|
|
28
26
|
import { registrationNearEd25519BranchKey } from "../../../../shared-ts/src/utils/registrationSignerPlan.js";
|
|
29
27
|
import { registrationIntentGrantFromString } from "../../../../shared-ts/src/utils/registrationIntent.js";
|
|
28
|
+
import { buildTenantRootIdentityFromAuthenticatedDeploymentV1 } from "../../../../shared-ts/src/tenant-root/tenantRootIdentity.js";
|
|
30
29
|
import { DEFAULT_WALLET_SESSION_TTL_MS } from "../../../../shared-ts/src/threshold/sessionPolicy.js";
|
|
31
30
|
import { parseEcdsaDerivationPublicIdentity, thresholdEd25519AuthorityScopeFromWalletAuthAuthority } from "../../../../core/ThresholdService/validation.js";
|
|
32
31
|
import { walletAuthAuthorityFromRegistrationAuthority, walletRegistrationFinalizeAuthMethodFromAuthority } from "../wallet/d1WalletAuthMethodBoundary.js";
|
|
@@ -38,37 +37,34 @@ import { buildStoredWalletRegistrationEvmFamilyEcdsaFinalizedBranch, buildStored
|
|
|
38
37
|
import { routerAbEcdsaStrictRegistrationRequestBindingJson } from "../../../domains/ecdsa/routerAbEcdsaStrictRegistration.js";
|
|
39
38
|
import { buildD1EcdsaWalletKeysFromBootstrap, buildD1WalletEcdsaSignerRecords, buildD1WalletRecord, parseWalletIdForIntent, thresholdEcdsaChainTargetsEqual } from "./d1RegistrationCeremonyRecords.js";
|
|
40
39
|
import { deriveThresholdEcdsaKeyHandle } from "../../../../shared-ts/src/utils/thresholdEcdsaKeyHandle.js";
|
|
41
|
-
import { admitRegistrationReservationHome,
|
|
40
|
+
import { admitRegistrationReservationHome, cancelRegistrationHome } from "../../../domains/walletRegistration/walletRegistrationReservation.js";
|
|
42
41
|
import { listThresholdEcdsaKeyIdentityTargetsForUser } from "../../../../core/authService/thresholdEcdsaKeyInventory.js";
|
|
43
42
|
import { routerAbEd25519YaoLifecycleDecisionLookupV1, routerAbEd25519YaoLifecycleDecisionV1 } from "../../../domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoLifecycleDecision.js";
|
|
44
|
-
import {
|
|
43
|
+
import { reserveRegistrationCustody } from "../../../domains/passkeyCustody/registrationCustodyOutcome.js";
|
|
45
44
|
import { resolveTenantRootIdentityV1 } from "../../../domains/tenantRoot/tenantRootIdentityResolution.js";
|
|
46
|
-
import {
|
|
45
|
+
import { walletRegistrationOperationPreparedFromCeremony } from "./d1WalletRegistrationPreparation.js";
|
|
46
|
+
import { computeWalletRegistrationSetupDigestB64u, parseWalletRegistrationSetupClaims, verifySignedWalletRegistrationSetup, verifyWalletRegistrationSetupClaims } from "../../../domains/walletRegistration/walletRegistrationSetupPayload.js";
|
|
47
|
+
import { createD1RegistrationRouteTimingRecorder, errorMessage, finishD1RegistrationRouteTiming, recordRegistrationPromiseTiming, recordRegistrationServerTiming, registrationSignerBranchesFromPlan, startD1RegistrationRouteTiming } from "./d1RegistrationSetupSupport.js";
|
|
48
|
+
import { projectWalletRegistrationSessionCommitReceiptV2, registrationCommitActivation, registrationReplayAuthMethodFields, replayedRegistrationCommit, unissuedRegistrationCommit } from "./walletRegistrationSessionCommitReceipt.js";
|
|
49
|
+
import { assertDirectWalletSessionOwnerProof, buildRegistrationOwnerProof, issueDirectRegistrationEstablishedEcdsaSession, issueDirectRegistrationEstablishedEd25519Session, projectCurrentNearRegistrationSession, replayDirectRegistrationEstablishedEcdsaSession, replayDirectRegistrationEstablishedEd25519Session, walletSessionPrincipalId } from "./walletRegistrationEstablishedSessionIssuer.js";
|
|
50
|
+
import { commitWalletRegistration } from "./d1WalletRegistrationInitialSession.js";
|
|
47
51
|
import { storedRespondEd25519DeferredWork, walletRegistrationRespondResult } from "./d1WalletRegistrationSetup.js";
|
|
48
52
|
import { executeD1WalletRegistrationSetup } from "./d1WalletRegistrationSetupExecution.js";
|
|
49
|
-
import { projectWalletRegistrationSessionCommitReceiptV2, registrationReplayAuthMethodFields, replayedRegistrationCommit, unissuedRegistrationCommit } from "./walletRegistrationSessionCommitReceipt.js";
|
|
50
|
-
import { assertDirectWalletSessionOwnerProof, buildRegistrationOwnerProof, issueDirectRegistrationEstablishedEcdsaSession, issueDirectRegistrationEstablishedEd25519Session, projectCurrentNearRegistrationSession, replayDirectRegistrationEstablishedEcdsaSession, replayDirectRegistrationEstablishedEd25519Session, walletSessionPrincipalId } from "./walletRegistrationEstablishedSessionIssuer.js";
|
|
51
53
|
//#region src/router/cloudflare/d1/registration/d1WalletRegistrationService.ts
|
|
52
|
-
function
|
|
53
|
-
return {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
kind: "near_ed25519",
|
|
67
|
-
walletId: input.walletId,
|
|
68
|
-
authority: input.authority,
|
|
69
|
-
authMethod: input.authMethod,
|
|
70
|
-
nearProvisioning: { status: "near_pending" }
|
|
71
|
-
};
|
|
54
|
+
async function buildRespondEd25519AdmissionRequest(input) {
|
|
55
|
+
return buildRouterAbEd25519YaoProductAdmissionRequestV1({
|
|
56
|
+
registrationCeremonyId: input.ceremony.registrationCeremonyId,
|
|
57
|
+
walletId: input.ceremony.intent.walletId,
|
|
58
|
+
signingRootId: normalizeOptionalTrimmedString(input.ceremony.signingRootId) || "",
|
|
59
|
+
signingRootVersion: normalizeOptionalTrimmedString(input.ceremony.signingRootVersion) || "",
|
|
60
|
+
authorityScope: registrationEd25519AuthorityScopeFromAuthority(input.authority),
|
|
61
|
+
branch: input.branch,
|
|
62
|
+
signingWorkerId: input.signingWorkerId,
|
|
63
|
+
materialActivation: createRouterAbEd25519YaoMaterialActivationRefV1({
|
|
64
|
+
walletId: input.ceremony.intent.walletId,
|
|
65
|
+
signingWorkerId: input.signingWorkerId
|
|
66
|
+
})
|
|
67
|
+
});
|
|
72
68
|
}
|
|
73
69
|
function sameEd25519ParticipantIds(left, right) {
|
|
74
70
|
return left[0] === right[0] && left[1] === right[1];
|
|
@@ -202,15 +198,6 @@ function requirePreparedRegistrationId(result, label) {
|
|
|
202
198
|
if (!result.ok) throw new Error(`${label} is invalid: ${result.error.message}`);
|
|
203
199
|
return result.value;
|
|
204
200
|
}
|
|
205
|
-
function walletRegistrationOperationPreparedFromCeremony(ceremony) {
|
|
206
|
-
if (String(ceremony.foundingWalletAuthMethodId) !== String(ceremony.intent.foundingWalletAuthMethodId)) throw new Error("registration ceremony and intent name different founding auth methods");
|
|
207
|
-
return {
|
|
208
|
-
kind: "d1_wallet_registration_operation_prepared_v1",
|
|
209
|
-
walletAuthorityId: ceremony.foundingWalletAuthorityId,
|
|
210
|
-
deviceId: ceremony.foundingDeviceId,
|
|
211
|
-
walletAuthMethodId: ceremony.foundingWalletAuthMethodId
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
201
|
function committedInstallationProjectionFromCeremony(ceremony) {
|
|
215
202
|
const registrationAuthority = verifiedRegistrationCeremonyAuthority(ceremony);
|
|
216
203
|
if (ceremony.signerState.kind !== "signer_set_registration" || registrationAuthority === null) return null;
|
|
@@ -406,6 +393,16 @@ async function buildFoundingAuthorityRecords(input) {
|
|
|
406
393
|
function assertNeverFoundingSignerFacts(value) {
|
|
407
394
|
throw new Error(`Unsupported founding signer facts: ${String(value)}`);
|
|
408
395
|
}
|
|
396
|
+
function registrationOwnerProofContextFromCeremony(ceremony) {
|
|
397
|
+
const expectedOrigin = normalizeOptionalTrimmedString(ceremony.expectedOrigin);
|
|
398
|
+
const runtimePolicyScope = registrationPreparedContextRuntimePolicyScope(ceremony.preparedContext);
|
|
399
|
+
if (!expectedOrigin || !runtimePolicyScope) throw new Error("Registration is missing its session origin or runtime policy scope");
|
|
400
|
+
return {
|
|
401
|
+
expectedOrigin,
|
|
402
|
+
runtimePolicyScope,
|
|
403
|
+
expiresAtMs: ceremony.expiresAtMs
|
|
404
|
+
};
|
|
405
|
+
}
|
|
409
406
|
function registrationFinalizeCeremonyFromStored(ceremony) {
|
|
410
407
|
if (ceremony.signerState.kind !== "signer_set_registration") throw new Error("signer-set registration state is required");
|
|
411
408
|
return {
|
|
@@ -525,9 +522,6 @@ function assertNeverSponsoredNamedNearAccountCreationResult(value) {
|
|
|
525
522
|
function isRegistrationEcdsaReadyReceipt(receipt) {
|
|
526
523
|
return receipt.committed.kind === "ecdsa_ready";
|
|
527
524
|
}
|
|
528
|
-
function isRegistrationNearPendingReceipt(receipt) {
|
|
529
|
-
return receipt.committed.kind === "near_pending";
|
|
530
|
-
}
|
|
531
525
|
function isRegistrationNearReadyReceipt(receipt) {
|
|
532
526
|
return receipt.committed.kind === "near_ready";
|
|
533
527
|
}
|
|
@@ -550,7 +544,6 @@ function d1RegistrationRouteDiagnostics(recorder) {
|
|
|
550
544
|
};
|
|
551
545
|
}
|
|
552
546
|
function withD1RegistrationRouteDiagnostics(response, recorder) {
|
|
553
|
-
if (!response.ok) return response;
|
|
554
547
|
return {
|
|
555
548
|
...response,
|
|
556
549
|
registrationDiagnostics: d1RegistrationRouteDiagnostics(recorder)
|
|
@@ -860,20 +853,14 @@ function mergeRouterServerTiming(target, header) {
|
|
|
860
853
|
}
|
|
861
854
|
}
|
|
862
855
|
}
|
|
863
|
-
function recordRegistrationServerTiming(sink, name, startedAtMs) {
|
|
864
|
-
sink.push([name, Math.max(0, Date.now() - startedAtMs)]);
|
|
865
|
-
}
|
|
866
|
-
async function recordRegistrationPromiseTiming(args) {
|
|
867
|
-
try {
|
|
868
|
-
return await args.promise;
|
|
869
|
-
} finally {
|
|
870
|
-
recordRegistrationServerTiming(args.sink, args.name, args.startedAtMs);
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
856
|
var CloudflareD1WalletRegistrationService = class {
|
|
874
857
|
constructor(input) {
|
|
858
|
+
this.home = input.home;
|
|
859
|
+
this.executionAuthority = input.executionAuthority;
|
|
875
860
|
this.registrationAuthority = input.registrationAuthority;
|
|
861
|
+
this.startRegistrationWallets = input.startRegistrationWallets;
|
|
876
862
|
this.authorizationService = input.authorizationService;
|
|
863
|
+
this.registrationSessionStore = input.registrationSessionStore;
|
|
877
864
|
this.authorizationTenantId = input.authorizationTenantId;
|
|
878
865
|
this.createSponsoredNamedNearAccount = input.createSponsoredNamedNearAccount;
|
|
879
866
|
this.emailOtpRegistrationEnrollmentFinalizer = input.emailOtpRegistrationEnrollmentFinalizer;
|
|
@@ -883,7 +870,7 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
883
870
|
this.tenantRootCustodyLineage = input.tenantRootCustodyLineage;
|
|
884
871
|
this.getWalletStore = input.getWalletStore;
|
|
885
872
|
this.activateSideEffects = input.activateSideEffects;
|
|
886
|
-
this.
|
|
873
|
+
this.registrationRead = input.registrationRead;
|
|
887
874
|
this.walletRegistrationCommitStore = input.walletRegistrationCommitStore;
|
|
888
875
|
this.walletCustodyCommitStore = input.walletCustodyCommitStore;
|
|
889
876
|
this.walletAuthMethods = input.walletAuthMethods;
|
|
@@ -893,7 +880,7 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
893
880
|
async resolveEd25519MaterialActivation(input) {
|
|
894
881
|
try {
|
|
895
882
|
const walletId = walletIdFromString(input.walletId);
|
|
896
|
-
const signer = await this.getWalletStore().getEd25519SignerByMaterialActivation({
|
|
883
|
+
const signer = input.signerRead ? input.signerRead.resolve(walletId, input.materialActivation) : await this.getWalletStore().getEd25519SignerByMaterialActivation({
|
|
897
884
|
walletId,
|
|
898
885
|
materialActivation: input.materialActivation
|
|
899
886
|
});
|
|
@@ -954,14 +941,15 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
954
941
|
exportIdentity: await ed25519ExportIdentityFromLinkedProjection(projection, active.capability)
|
|
955
942
|
};
|
|
956
943
|
}
|
|
957
|
-
const
|
|
944
|
+
const lookup = {
|
|
958
945
|
kind: "router_ab_ed25519_yao_active_capability_lookup_v1",
|
|
959
946
|
walletId: input.walletId,
|
|
960
947
|
nearEd25519SigningKeyId: signer.nearEd25519SigningKeyId,
|
|
961
948
|
signerSlot: signer.signerSlot,
|
|
962
949
|
signingWorkerId: signer.signingWorkerId,
|
|
963
950
|
participantIds: signer.participantIds
|
|
964
|
-
}
|
|
951
|
+
};
|
|
952
|
+
const active = input.signerRead?.resolveActiveCapability(lookup) ?? await yaoRuntime.resolveActiveCapability(lookup);
|
|
965
953
|
if (!active.ok) {
|
|
966
954
|
if (active.code === "unknown_capability") {
|
|
967
955
|
if (!sameRouterAbMpcMaterialActivationRef(signer.activeYaoCapability.activationResult.binding.material_activation, input.materialActivation)) return {
|
|
@@ -1127,8 +1115,15 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
1127
1115
|
code: "not_found",
|
|
1128
1116
|
message: "ECDSA tenant root is not active"
|
|
1129
1117
|
};
|
|
1118
|
+
const home = await this.executionAuthority.admitEstablishedHome({ walletId: walletIdFromString(input.walletId) });
|
|
1119
|
+
if (!home.ok) return {
|
|
1120
|
+
ok: false,
|
|
1121
|
+
code: "invalid_state",
|
|
1122
|
+
message: home.message
|
|
1123
|
+
};
|
|
1130
1124
|
return {
|
|
1131
1125
|
ok: true,
|
|
1126
|
+
ownershipGeneration: home.ownershipGeneration,
|
|
1132
1127
|
...tenantRoot
|
|
1133
1128
|
};
|
|
1134
1129
|
} catch (error) {
|
|
@@ -1591,9 +1586,11 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
1591
1586
|
}
|
|
1592
1587
|
async setupWalletRegistration(input) {
|
|
1593
1588
|
return executeD1WalletRegistrationSetup(input, {
|
|
1589
|
+
home: this.home,
|
|
1594
1590
|
reservation: this.registrationAuthority,
|
|
1595
1591
|
store: this.getRegistrationCeremonyIntentStore(),
|
|
1596
|
-
ecdsaStrictRegistration: this.ecdsaStrictRegistration
|
|
1592
|
+
ecdsaStrictRegistration: this.ecdsaStrictRegistration,
|
|
1593
|
+
startRegistrationWallets: this.startRegistrationWallets
|
|
1597
1594
|
});
|
|
1598
1595
|
}
|
|
1599
1596
|
async authorizeWalletRegistrationNearAdmission(input) {
|
|
@@ -1671,7 +1668,8 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
1671
1668
|
ceremony,
|
|
1672
1669
|
branch: branches.nearEd25519,
|
|
1673
1670
|
authority: verifiedAuthority.authority,
|
|
1674
|
-
registrationBearerToken
|
|
1671
|
+
registrationBearerToken,
|
|
1672
|
+
ownershipGeneration: homeAdmission.ownershipGeneration
|
|
1675
1673
|
});
|
|
1676
1674
|
if (!admitted.ok) return admitted;
|
|
1677
1675
|
if (!admitted.deferred) return {
|
|
@@ -1700,9 +1698,19 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
1700
1698
|
};
|
|
1701
1699
|
try {
|
|
1702
1700
|
const store = this.getRegistrationCeremonyIntentStore();
|
|
1701
|
+
const verifiedSetup = await verifyWalletRegistrationSetupClaims(input.verifier, input.signedSetup, {
|
|
1702
|
+
registrationCeremonyId: input.registrationCeremonyId,
|
|
1703
|
+
nowMs: Date.now()
|
|
1704
|
+
});
|
|
1705
|
+
if (!verifiedSetup.ok) return verifiedSetup;
|
|
1703
1706
|
const loadStartedAtMs = Date.now();
|
|
1704
|
-
const
|
|
1707
|
+
const homeAdmission = await this.registrationRead.readRespond({
|
|
1708
|
+
ceremonyId: verifiedSetup.claims.registrationCeremonyId,
|
|
1709
|
+
walletId: walletIdFromString(verifiedSetup.claims.walletId)
|
|
1710
|
+
});
|
|
1705
1711
|
mark("ecdsa_respond_d1_load", loadStartedAtMs);
|
|
1712
|
+
if (!homeAdmission.ok) return homeAdmission;
|
|
1713
|
+
const snapshot = homeAdmission.snapshot;
|
|
1706
1714
|
if (!snapshot) return {
|
|
1707
1715
|
ok: false,
|
|
1708
1716
|
code: "not_found",
|
|
@@ -1724,29 +1732,23 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
1724
1732
|
signingRootVersion: normalizeOptionalTrimmedString(ceremony.signingRootVersion) || "",
|
|
1725
1733
|
expectedOrigin
|
|
1726
1734
|
});
|
|
1727
|
-
|
|
1728
|
-
registrationCeremonyId: ceremony.registrationCeremonyId,
|
|
1729
|
-
setupDigestB64u,
|
|
1730
|
-
nowMs: Date.now()
|
|
1731
|
-
});
|
|
1732
|
-
if (!verifiedSetup.ok) return {
|
|
1735
|
+
if (verifiedSetup.claims.setupDigestB64u !== setupDigestB64u || verifiedSetup.claims.walletId !== ceremony.intent.walletId) return {
|
|
1733
1736
|
ok: false,
|
|
1734
|
-
code:
|
|
1735
|
-
message:
|
|
1737
|
+
code: "invalid_grant",
|
|
1738
|
+
message: "signedSetup does not match this registration setup"
|
|
1736
1739
|
};
|
|
1737
|
-
const
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1740
|
+
const ecdsaBranch = findStoredWalletRegistrationEvmFamilyEcdsaBranch(ceremony.signerState);
|
|
1741
|
+
const planNearEd25519 = registrationSignerBranchesFromPlan(ceremony.signerPlan).nearEd25519;
|
|
1742
|
+
const startedDispatchRoot = !ecdsaBranch && planNearEd25519 && !storedRespondEd25519DeferredWork(ceremony.signerState) ? this.getEd25519YaoProductRegistration()?.startRegistrationDispatchRoot({
|
|
1743
|
+
signing_root_id: normalizeOptionalTrimmedString(ceremony.signingRootId) || "",
|
|
1744
|
+
root_share_epoch: normalizeOptionalTrimmedString(ceremony.signingRootVersion) || ""
|
|
1745
|
+
}) ?? null : null;
|
|
1742
1746
|
const registrationBearerToken = normalizeOptionalTrimmedString(input.signedSetup);
|
|
1743
1747
|
if (!registrationBearerToken) return {
|
|
1744
1748
|
ok: false,
|
|
1745
1749
|
code: "invalid_body",
|
|
1746
1750
|
message: "signedSetup is required"
|
|
1747
1751
|
};
|
|
1748
|
-
const ecdsaBranch = findStoredWalletRegistrationEvmFamilyEcdsaBranch(ceremony.signerState);
|
|
1749
|
-
const planNearEd25519 = registrationSignerBranchesFromPlan(ceremony.signerPlan).nearEd25519;
|
|
1750
1752
|
if (!ecdsaBranch && !planNearEd25519) return {
|
|
1751
1753
|
ok: false,
|
|
1752
1754
|
code: "invalid_state",
|
|
@@ -1764,6 +1766,8 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
1764
1766
|
branch: planNearEd25519,
|
|
1765
1767
|
authorityInput: input.authority,
|
|
1766
1768
|
registrationBearerToken,
|
|
1769
|
+
ownershipGeneration: homeAdmission.ownershipGeneration,
|
|
1770
|
+
startedDispatchRoot,
|
|
1767
1771
|
expectedOrigin,
|
|
1768
1772
|
...input.userAgent ? { userAgent: input.userAgent } : {}
|
|
1769
1773
|
});
|
|
@@ -1877,6 +1881,7 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
1877
1881
|
message: "ECDSA response claim is invalid"
|
|
1878
1882
|
};
|
|
1879
1883
|
const tenantRoot = {
|
|
1884
|
+
ownershipGeneration: homeAdmission.ownershipGeneration,
|
|
1880
1885
|
projectEnvironmentId: claimedBranch.projectEnvironmentId,
|
|
1881
1886
|
identityDigestB64u: claimedBranch.tenantRootIdentityDigestB64u,
|
|
1882
1887
|
custodyLineageB64u: claimedBranch.tenantRootCustodyLineageB64u
|
|
@@ -1898,15 +1903,15 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
1898
1903
|
ceremony,
|
|
1899
1904
|
branch: nearEd25519Branch,
|
|
1900
1905
|
authority,
|
|
1901
|
-
registrationBearerToken
|
|
1906
|
+
registrationBearerToken,
|
|
1907
|
+
ownershipGeneration: homeAdmission.ownershipGeneration
|
|
1902
1908
|
})]);
|
|
1903
1909
|
mark("ecdsa_respond_router", routerStartedAtMs);
|
|
1904
1910
|
if (!strictResult.ok) {
|
|
1905
1911
|
if (!strictResult.retryable) {
|
|
1906
|
-
const completedHome = await
|
|
1912
|
+
const completedHome = await cancelRegistrationHome(this.registrationAuthority, {
|
|
1907
1913
|
ceremonyId: ceremony.registrationCeremonyId,
|
|
1908
|
-
walletId: ceremony.intent.walletId
|
|
1909
|
-
outcome: "cancelled"
|
|
1914
|
+
walletId: ceremony.intent.walletId
|
|
1910
1915
|
});
|
|
1911
1916
|
if (!completedHome.ok) return completedHome;
|
|
1912
1917
|
await store.cancelTerminalCeremony({
|
|
@@ -1985,34 +1990,6 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
1985
1990
|
};
|
|
1986
1991
|
}
|
|
1987
1992
|
}
|
|
1988
|
-
/**
|
|
1989
|
-
* The Ed25519 commit core, extracted so deferred provisioning reaches it
|
|
1990
|
-
* without going through the standalone finalize wrapper. The operation row
|
|
1991
|
-
* owns idempotency here, so the commit keeps no replay cache of its own.
|
|
1992
|
-
*/
|
|
1993
|
-
async readRegistrationOwnerProofContext(registrationCeremonyId) {
|
|
1994
|
-
const ceremony = await this.getRegistrationCeremonyIntentStore().getCeremony(registrationCeremonyId);
|
|
1995
|
-
if (!ceremony) {
|
|
1996
|
-
const committed = await this.readCommittedRegistrationInstallation(registrationCeremonyId);
|
|
1997
|
-
if (!committed) return null;
|
|
1998
|
-
if (!isRegistrationEcdsaReadyReceipt(committed.receipt)) throw new Error("Committed registration installation has no ECDSA session receipt");
|
|
1999
|
-
const runtimePolicyScope = registrationPreparedContextRuntimePolicyScope(committed.projection.preparedContext);
|
|
2000
|
-
if (!runtimePolicyScope) throw new Error("Committed registration is missing its runtime policy scope");
|
|
2001
|
-
return {
|
|
2002
|
-
expectedOrigin: committed.receipt.expectedOrigin,
|
|
2003
|
-
runtimePolicyScope,
|
|
2004
|
-
expiresAtMs: committed.receipt.expiresAtMs
|
|
2005
|
-
};
|
|
2006
|
-
}
|
|
2007
|
-
const expectedOrigin = normalizeOptionalTrimmedString(ceremony.expectedOrigin);
|
|
2008
|
-
const runtimePolicyScope = registrationPreparedContextRuntimePolicyScope(ceremony.preparedContext);
|
|
2009
|
-
if (!expectedOrigin || !runtimePolicyScope) throw new Error("Registration is missing its session origin or runtime policy scope");
|
|
2010
|
-
return {
|
|
2011
|
-
expectedOrigin,
|
|
2012
|
-
runtimePolicyScope,
|
|
2013
|
-
expiresAtMs: ceremony.expiresAtMs
|
|
2014
|
-
};
|
|
2015
|
-
}
|
|
2016
1993
|
/** For callers that must read the context before finalize tombstones it. */
|
|
2017
1994
|
async registrationOwnerProofWithContext(context, input) {
|
|
2018
1995
|
return await buildRegistrationOwnerProof({
|
|
@@ -2035,7 +2012,7 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2035
2012
|
nowMs
|
|
2036
2013
|
});
|
|
2037
2014
|
if (!issued) return null;
|
|
2038
|
-
const active = await this.walletAuthMethods.
|
|
2015
|
+
const active = await this.walletAuthMethods.readActiveRegistrationIdentity(installation.projection.registrationAuthority);
|
|
2039
2016
|
if (!active || issued.session.walletId !== installation.projection.walletId || issued.session.authorityId !== installation.receipt.foundingAuthority.authorityId || issued.session.walletAuthMethodId !== installation.receipt.walletAuthMethodId || active.walletAuthMethodId !== issued.session.walletAuthMethodId || active.authority.authorityId !== issued.session.authorityId || active.authority.authorityDigestB64u !== issued.session.authorityDigestB64u || active.authority.revocationEpoch !== issued.session.authorityRevocationEpoch || active.authority.revocationEpoch !== installation.receipt.foundingAuthority.revocationEpoch || issued.session.expiresAtMs <= nowMs) return null;
|
|
2040
2017
|
const originalSubjects = installation.receipt.committed.session.walletSession.capabilitySubjects;
|
|
2041
2018
|
for (const subject of originalSubjects) if (!issued.session.capabilitySubjects.some(sameRegistrationContinuationSubject.bind(void 0, subject))) return null;
|
|
@@ -2076,64 +2053,70 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2076
2053
|
});
|
|
2077
2054
|
const nearPlan = projection.signerPlan.branches.find((branch) => branch.kind === "near_ed25519");
|
|
2078
2055
|
const ecdsaPlan = projection.signerPlan.branches.find((branch) => branch.kind === "evm_family_ecdsa");
|
|
2079
|
-
if (projection.registrationCeremonyId !== registrationCeremonyId || projection.walletId !== receipt.walletId || projection.registrationAuthority.walletId !== receipt.walletId || projection.orgId !== (projection.preparedContext.runtimePolicy.kind === "runtime_policy_scope" ? projection.preparedContext.runtimePolicy.scope.orgId : "") || !nearPlan || !ecdsaPlan || !thresholdEcdsaChainTargetsEqual(ecdsaPlan.chainTargets, projection.preparedContext.ecdsa.kind === "evm_family_ecdsa_requested" ? projection.preparedContext.ecdsa.chainTargets : []) || !thresholdEcdsaChainTargetsEqual(ecdsaPlan.chainTargets, receipt.committed.ecdsa.walletKeys.map((walletKey) => walletKey.chainTarget)) || receipt.committed.ecdsa.walletKeys.some((walletKey) => walletKey.walletId !== String(receipt.walletId) || walletKey.signingRootId !== projection.preparedContext.signingRootId || walletKey.signingRootVersion !== projection.preparedContext.signingRootVersion || walletKey.participantIds.length !== ecdsaPlan.participantIds.length || walletKey.participantIds.some((participantId, index) => participantId !== ecdsaPlan.participantIds[index])) || projection.nearEd25519.branchKey !== nearPlan.branchKey || projection.nearEd25519.admissionRequest.scope.lifecycle_id !== registrationCeremonyId || projection.nearEd25519.admissionRequest.scope.account_id !== String(receipt.walletId) || projection.nearEd25519.admissionRequest.scope.root_share_epoch !== projection.preparedContext.signingRootVersion || projection.nearEd25519.admissionRequest.scope.signer_set_id !== String(nearPlan.branchKey) || projection.nearEd25519.admissionRequest.application_binding.wallet_id !== String(receipt.walletId) || projection.nearEd25519.admissionRequest.application_binding.signing_root_id !== projection.preparedContext.signingRootId || projection.nearEd25519.admissionRequest.application_binding.key_creation_signer_slot !== nearPlan.signerSlot || projection.nearEd25519.admissionRequest.participant_ids.length !== nearPlan.participantIds.length || projection.nearEd25519.admissionRequest.participant_ids.some((participantId, index) => participantId !== nearPlan.participantIds[index]) || !walletAuthAuthoritiesMatch(derivedAuthority, receipt.authority) || record.prepared.walletAuthorityId !== receipt.foundingAuthority.authorityId || record.prepared.deviceId !== foundingDeviceId || record.prepared.walletAuthMethodId !== receipt.walletAuthMethodId) throw new Error("registration activation receipt installation identity is invalid");
|
|
2056
|
+
if (projection.registrationCeremonyId !== registrationCeremonyId || projection.walletId !== receipt.walletId || projection.registrationAuthority.walletId !== receipt.walletId || projection.orgId !== (projection.preparedContext.runtimePolicy.kind === "runtime_policy_scope" ? projection.preparedContext.runtimePolicy.scope.orgId : "") || !nearPlan || !ecdsaPlan || !thresholdEcdsaChainTargetsEqual(ecdsaPlan.chainTargets, projection.preparedContext.ecdsa.kind === "evm_family_ecdsa_requested" ? projection.preparedContext.ecdsa.chainTargets : []) || !thresholdEcdsaChainTargetsEqual(ecdsaPlan.chainTargets, receipt.committed.ecdsa.walletKeys.map((walletKey) => walletKey.chainTarget)) || receipt.committed.ecdsa.walletKeys.some((walletKey) => walletKey.walletId !== String(receipt.walletId) || walletKey.signingRootId !== projection.preparedContext.signingRootId || walletKey.signingRootVersion !== projection.preparedContext.signingRootVersion || walletKey.participantIds.length !== ecdsaPlan.participantIds.length || walletKey.participantIds.some((participantId, index) => participantId !== ecdsaPlan.participantIds[index])) || projection.nearEd25519.branchKey !== nearPlan.branchKey || projection.nearEd25519.admissionRequest.scope.lifecycle_id !== registrationCeremonyId || projection.nearEd25519.admissionRequest.scope.account_id !== String(receipt.walletId) || projection.nearEd25519.admissionRequest.scope.root_share_epoch !== projection.preparedContext.signingRootVersion || projection.nearEd25519.admissionRequest.scope.signer_set_id !== String(nearPlan.branchKey) || projection.nearEd25519.admissionRequest.application_binding.wallet_id !== String(receipt.walletId) || projection.nearEd25519.admissionRequest.application_binding.signing_root_id !== projection.preparedContext.signingRootId || projection.nearEd25519.admissionRequest.application_binding.key_creation_signer_slot !== nearPlan.signerSlot || projection.nearEd25519.admissionRequest.participant_ids.length !== nearPlan.participantIds.length || projection.nearEd25519.admissionRequest.participant_ids.some((participantId, index) => participantId !== nearPlan.participantIds[index]) || !walletAuthAuthoritiesMatch(derivedAuthority, receipt.authority) || record.prepared.walletId !== receipt.walletId || record.prepared.walletAuthorityId !== receipt.foundingAuthority.authorityId || record.prepared.deviceId !== foundingDeviceId || record.prepared.walletAuthMethodId !== receipt.walletAuthMethodId) throw new Error("registration activation receipt installation identity is invalid");
|
|
2080
2057
|
return {
|
|
2081
2058
|
receipt,
|
|
2082
2059
|
projection,
|
|
2083
2060
|
prepared: record.prepared
|
|
2084
2061
|
};
|
|
2085
2062
|
}
|
|
2086
|
-
|
|
2087
|
-
|
|
2063
|
+
/** Carries the preparation's ceremony into this request's execution. */
|
|
2064
|
+
async prepareNearProvisioningOperation(registrationCeremonyId, allocated, source) {
|
|
2065
|
+
const ceremony = source.kind === "ceremony" ? source.ceremony : null;
|
|
2088
2066
|
if (!ceremony) {
|
|
2089
|
-
const committed =
|
|
2067
|
+
const committed = source.kind === "installation" ? source.installation : await this.readCommittedRegistrationInstallation(registrationCeremonyId);
|
|
2090
2068
|
if (!committed) throw new Error("Registration ceremony is unavailable for identity preparation");
|
|
2091
|
-
if (allocated && (allocated.walletAuthorityId !== committed.prepared.walletAuthorityId || allocated.deviceId !== committed.prepared.deviceId || allocated.walletAuthMethodId !== committed.prepared.walletAuthMethodId)) throw new Error("registration operation identity does not match its committed installation");
|
|
2092
|
-
return
|
|
2069
|
+
if (allocated && (allocated.walletId !== committed.prepared.walletId || allocated.walletAuthorityId !== committed.prepared.walletAuthorityId || allocated.deviceId !== committed.prepared.deviceId || allocated.walletAuthMethodId !== committed.prepared.walletAuthMethodId)) throw new Error("registration operation identity does not match its committed installation");
|
|
2070
|
+
return {
|
|
2071
|
+
prepared: committed.prepared,
|
|
2072
|
+
ceremony: null
|
|
2073
|
+
};
|
|
2093
2074
|
}
|
|
2094
|
-
const prepared = allocated ?? walletRegistrationOperationPreparedFromCeremony(ceremony);
|
|
2095
|
-
const authority = verifiedRegistrationCeremonyAuthority(ceremony);
|
|
2096
|
-
if (!authority) return prepared;
|
|
2097
|
-
const persisted = await this.walletAuthMethods.readActiveRegistrationIdentity(authority);
|
|
2098
|
-
if (!persisted) return prepared;
|
|
2099
2075
|
return {
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
deviceId: prepared.deviceId,
|
|
2103
|
-
walletAuthMethodId: persisted.walletAuthMethodId
|
|
2076
|
+
prepared: walletRegistrationOperationPreparedFromCeremony(ceremony, allocated),
|
|
2077
|
+
ceremony
|
|
2104
2078
|
};
|
|
2105
2079
|
}
|
|
2106
2080
|
async commitDeferredEd25519Signer(args, prepared) {
|
|
2081
|
+
const sourceStartedAtMs = Date.now();
|
|
2107
2082
|
const committedInstallation = args.authoritySource.kind === "committed_mixed" ? args.authoritySource.installation : null;
|
|
2108
2083
|
if (committedInstallation && !isRegistrationEcdsaReadyReceipt(committedInstallation.receipt)) throw new Error("Committed mixed registration receipt is not ECDSA-ready");
|
|
2109
|
-
const
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
if (!ownerProofContext) throw new Error("Registration owner proof context is unavailable");
|
|
2115
|
-
if (!ownerProofContext.runtimePolicyScope) throw new Error("Committed registration is missing its runtime policy scope");
|
|
2116
|
-
const ceremony = committedInstallation ? null : await this.getRegistrationCeremonyIntentStore().getCeremony(args.input.registrationCeremonyId);
|
|
2117
|
-
let recovery = null;
|
|
2118
|
-
let registrationAuthority;
|
|
2084
|
+
const preparedCeremony = committedInstallation ? null : args.preparedCeremony();
|
|
2085
|
+
const ceremony = committedInstallation || preparedCeremony ? preparedCeremony : await this.getRegistrationCeremonyIntentStore().getCeremony(args.input.registrationCeremonyId);
|
|
2086
|
+
let source;
|
|
2087
|
+
let ownerProofContext;
|
|
2088
|
+
let effectivePrepared;
|
|
2119
2089
|
let sessionPredecessor;
|
|
2120
2090
|
if (ceremony) {
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2091
|
+
source = {
|
|
2092
|
+
kind: "stored_ceremony",
|
|
2093
|
+
ceremony
|
|
2094
|
+
};
|
|
2095
|
+
ownerProofContext = registrationOwnerProofContextFromCeremony(ceremony);
|
|
2096
|
+
if (!verifiedRegistrationCeremonyAuthority(ceremony)) throw new Error("Registration authority is unavailable before finalize");
|
|
2124
2097
|
sessionPredecessor = { kind: "ed25519_only" };
|
|
2098
|
+
effectivePrepared = walletRegistrationOperationPreparedFromCeremony(ceremony, prepared);
|
|
2125
2099
|
} else {
|
|
2126
2100
|
const committed = committedInstallation ?? await this.readCommittedRegistrationInstallation(args.input.registrationCeremonyId);
|
|
2127
2101
|
if (!committed) throw new Error("Committed registration installation is unavailable");
|
|
2128
|
-
|
|
2102
|
+
source = registrationFinalizeRecoveryFromCommittedInstallation({
|
|
2129
2103
|
setupClaims: args.setupClaims,
|
|
2130
2104
|
projection: committed.projection
|
|
2131
2105
|
});
|
|
2132
|
-
|
|
2133
|
-
if (!authority) throw new Error("Committed registration installation has no verified authority");
|
|
2134
|
-
registrationAuthority = authority;
|
|
2106
|
+
if (!verifiedRegistrationCeremonyAuthority(source.ceremony)) throw new Error("Committed registration installation has no verified authority");
|
|
2135
2107
|
const activationReceipt = committed.receipt;
|
|
2136
2108
|
if (!isRegistrationEcdsaReadyReceipt(activationReceipt)) throw new Error("Committed mixed registration receipt is not ECDSA-ready");
|
|
2109
|
+
const runtimePolicyScope = registrationPreparedContextRuntimePolicyScope(committed.projection.preparedContext);
|
|
2110
|
+
if (!runtimePolicyScope) throw new Error("Committed registration is missing its runtime policy scope");
|
|
2111
|
+
ownerProofContext = {
|
|
2112
|
+
expectedOrigin: activationReceipt.expectedOrigin,
|
|
2113
|
+
runtimePolicyScope,
|
|
2114
|
+
expiresAtMs: activationReceipt.expiresAtMs
|
|
2115
|
+
};
|
|
2116
|
+
effectivePrepared = (await this.prepareNearProvisioningOperation(args.input.registrationCeremonyId, prepared, {
|
|
2117
|
+
kind: "installation",
|
|
2118
|
+
installation: committed
|
|
2119
|
+
})).prepared;
|
|
2137
2120
|
if (activationReceipt.committed.session.tokens.kind !== "evm_family_ecdsa") throw new Error("Committed mixed registration is missing its ECDSA session projection");
|
|
2138
2121
|
if (args.input.authorization.kind === "wallet_session") {
|
|
2139
2122
|
const authorization = args.authoritySource.kind === "committed_mixed" ? args.authoritySource.authorization : null;
|
|
@@ -2148,57 +2131,100 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2148
2131
|
ecdsa: activationReceipt.committed.session.tokens.ecdsa
|
|
2149
2132
|
};
|
|
2150
2133
|
}
|
|
2151
|
-
|
|
2152
|
-
const
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
walletCustodyCommit: args.input.walletCustodyCommit
|
|
2159
|
-
}, effectivePrepared, recovery);
|
|
2160
|
-
const finalized = committed.ok ? committed : throwIfRouterAbEd25519YaoRetryableSideEffectFailureV1(committed);
|
|
2161
|
-
if (!finalized.ok || finalized.kind !== "near_ed25519") return unissuedRegistrationCommit(finalized);
|
|
2134
|
+
recordRegistrationServerTiming(args.serverTiming, "near_finalize_source", sourceStartedAtMs);
|
|
2135
|
+
const ceremonyAuthority = verifiedRegistrationCeremonyAuthority(source.ceremony);
|
|
2136
|
+
if (!ceremonyAuthority) throw new Error("Registration authority is unavailable before finalize");
|
|
2137
|
+
const sessionAuthority = registrationWalletAuthAuthority({
|
|
2138
|
+
authority: ceremonyAuthority,
|
|
2139
|
+
walletAuthMethodId: effectivePrepared.walletAuthMethodId
|
|
2140
|
+
});
|
|
2162
2141
|
const proof = await buildRegistrationOwnerProof({
|
|
2163
2142
|
registrationCeremonyId: args.input.registrationCeremonyId,
|
|
2164
|
-
authMethod:
|
|
2165
|
-
authority:
|
|
2143
|
+
authMethod: walletRegistrationFinalizeAuthMethodFromAuthority(ceremonyAuthority),
|
|
2144
|
+
authority: sessionAuthority,
|
|
2166
2145
|
tenantId: this.authorizationTenantId,
|
|
2167
2146
|
expectedOrigin: ownerProofContext.expectedOrigin,
|
|
2168
2147
|
expiresAtMs: args.input.authorization.kind === "wallet_session" ? args.setupClaims.expiresAtMs : ownerProofContext.expiresAtMs
|
|
2169
2148
|
});
|
|
2170
|
-
const
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2149
|
+
const initialSessionPlan = sessionPredecessor.kind === "ed25519_only" && !registrationSignerBranchesFromPlan(source.ceremony.signerPlan).evmFamilyEcdsa ? {
|
|
2150
|
+
kind: "initial_near",
|
|
2151
|
+
store: this.registrationSessionStore,
|
|
2152
|
+
request: {
|
|
2153
|
+
authorizationService: this.authorizationService,
|
|
2154
|
+
authorizationTenantId: this.authorizationTenantId,
|
|
2155
|
+
registrationCeremonyId: args.input.registrationCeremonyId,
|
|
2156
|
+
authority: sessionAuthority,
|
|
2157
|
+
walletAuthMethodId: effectivePrepared.walletAuthMethodId,
|
|
2158
|
+
expiresAtMs: Date.now() + DEFAULT_WALLET_SESSION_TTL_MS,
|
|
2159
|
+
remainingUses: 3,
|
|
2160
|
+
proof
|
|
2161
|
+
}
|
|
2162
|
+
} : { kind: "separate" };
|
|
2163
|
+
const execution = await this.executeWalletRegistrationFinalize({
|
|
2164
|
+
kind: "near_ed25519",
|
|
2174
2165
|
registrationCeremonyId: args.input.registrationCeremonyId,
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2166
|
+
idempotencyKey: args.input.idempotencyKey,
|
|
2167
|
+
ed25519: args.input.ed25519,
|
|
2168
|
+
emailOtpEnrollment: args.input.emailOtpEnrollment,
|
|
2169
|
+
walletCustodyCommit: args.input.walletCustodyCommit
|
|
2170
|
+
}, effectivePrepared, source, args.serverTiming, initialSessionPlan, args.lifecycleDecision);
|
|
2171
|
+
if (!execution.ok) return unissuedRegistrationCommit(throwIfRouterAbEd25519YaoRetryableSideEffectFailureV1(execution));
|
|
2172
|
+
const finalized = execution.finalized;
|
|
2173
|
+
if (finalized.kind !== "near_ed25519") {
|
|
2174
|
+
await execution.custody;
|
|
2175
|
+
return unissuedRegistrationCommit({
|
|
2176
|
+
ok: false,
|
|
2177
|
+
code: "internal",
|
|
2178
|
+
message: "NEAR provisioning committed a non-NEAR branch"
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
2181
|
+
if (!this.registrationAuthority) throw new Error("Registration home completion is unavailable");
|
|
2182
|
+
const [issuance, custody] = await Promise.allSettled([recordRegistrationPromiseTiming({
|
|
2183
|
+
sink: args.serverTiming,
|
|
2184
|
+
name: "near_finalize_session_issue",
|
|
2185
|
+
startedAtMs: Date.now(),
|
|
2186
|
+
promise: issueDirectRegistrationEstablishedEd25519Session({
|
|
2187
|
+
homeCompletion: this.registrationAuthority,
|
|
2188
|
+
authorizationService: this.authorizationService,
|
|
2189
|
+
authorizationTenantId: this.authorizationTenantId,
|
|
2190
|
+
foundingAuthority: finalized.foundingAuthority,
|
|
2191
|
+
registrationCeremonyId: args.input.registrationCeremonyId,
|
|
2192
|
+
authority: finalized.authority,
|
|
2193
|
+
walletAuthMethodId: effectivePrepared.walletAuthMethodId,
|
|
2194
|
+
expiresAtMs: Date.now() + DEFAULT_WALLET_SESSION_TTL_MS,
|
|
2195
|
+
remainingUses: 3,
|
|
2196
|
+
publicResult: finalized.ed25519,
|
|
2197
|
+
predecessor: sessionPredecessor,
|
|
2198
|
+
initialSession: execution.initialSession,
|
|
2199
|
+
keyManifestDigestB64u: finalized.custodyKeyManifestDigestB64u,
|
|
2200
|
+
proof,
|
|
2201
|
+
onSessionCommitted: finalized.authMethod.kind === "passkey" ? args.input.onSessionCommitted : void 0
|
|
2202
|
+
})
|
|
2203
|
+
}), execution.custody]);
|
|
2204
|
+
if (issuance.status === "rejected") throw issuance.reason;
|
|
2205
|
+
if (custody.status === "rejected") throw custody.reason;
|
|
2206
|
+
const issuedRegistrationSession = issuance.value;
|
|
2207
|
+
const custodyField = custody.value.status === "not_requested" ? {} : { walletCustody: custody.value };
|
|
2185
2208
|
switch (issuedRegistrationSession.kind) {
|
|
2186
2209
|
case "issued": return {
|
|
2187
2210
|
kind: "session_issued",
|
|
2188
2211
|
response: {
|
|
2189
2212
|
...finalized,
|
|
2213
|
+
...custodyField,
|
|
2190
2214
|
registrationEstablishedSession: {
|
|
2191
2215
|
kind: "issued",
|
|
2192
2216
|
session: issuedRegistrationSession.session
|
|
2193
2217
|
}
|
|
2194
2218
|
},
|
|
2195
2219
|
issuedAtMs: issuedRegistrationSession.issuedAtMs,
|
|
2196
|
-
expectedOrigin: ownerProofContext.expectedOrigin
|
|
2220
|
+
expectedOrigin: ownerProofContext.expectedOrigin,
|
|
2221
|
+
activation: issuedRegistrationSession.activation
|
|
2197
2222
|
};
|
|
2198
2223
|
case "already_committed": return {
|
|
2199
2224
|
kind: "session_issued",
|
|
2200
2225
|
response: {
|
|
2201
2226
|
...finalized,
|
|
2227
|
+
...custodyField,
|
|
2202
2228
|
registrationEstablishedSession: {
|
|
2203
2229
|
kind: "already_committed",
|
|
2204
2230
|
session: issuedRegistrationSession.session,
|
|
@@ -2206,7 +2232,8 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2206
2232
|
}
|
|
2207
2233
|
},
|
|
2208
2234
|
issuedAtMs: issuedRegistrationSession.issuedAtMs,
|
|
2209
|
-
expectedOrigin: ownerProofContext.expectedOrigin
|
|
2235
|
+
expectedOrigin: ownerProofContext.expectedOrigin,
|
|
2236
|
+
activation: issuedRegistrationSession.activation
|
|
2210
2237
|
};
|
|
2211
2238
|
default: return assertNeverD1RegistrationSessionIssuance(issuedRegistrationSession);
|
|
2212
2239
|
}
|
|
@@ -2215,29 +2242,6 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2215
2242
|
if (receipt.operation !== "registration_activate") throw new Error("Registration activation receipt operation is invalid");
|
|
2216
2243
|
switch (receipt.committed.kind) {
|
|
2217
2244
|
case "error": return replayedRegistrationCommit(receipt.committed.error);
|
|
2218
|
-
case "near_pending": {
|
|
2219
|
-
if (!isRegistrationNearPendingReceipt(receipt)) throw new Error("Registration pending receipt branch is invalid");
|
|
2220
|
-
const authMethod = registrationReplayAuthMethodFields(receipt);
|
|
2221
|
-
if (authMethod.kind === "passkey") return replayedRegistrationCommit({
|
|
2222
|
-
ok: true,
|
|
2223
|
-
kind: "near_ed25519",
|
|
2224
|
-
walletId: receipt.walletId,
|
|
2225
|
-
authority: receipt.authority,
|
|
2226
|
-
authMethod: authMethod.authMethod,
|
|
2227
|
-
rpId: authMethod.rpId,
|
|
2228
|
-
...receipt.registrationDiagnostics ? { registrationDiagnostics: receipt.registrationDiagnostics } : {},
|
|
2229
|
-
nearProvisioning: { status: "near_pending" }
|
|
2230
|
-
});
|
|
2231
|
-
return replayedRegistrationCommit({
|
|
2232
|
-
ok: true,
|
|
2233
|
-
kind: "near_ed25519",
|
|
2234
|
-
walletId: receipt.walletId,
|
|
2235
|
-
authority: receipt.authority,
|
|
2236
|
-
authMethod: authMethod.authMethod,
|
|
2237
|
-
...receipt.registrationDiagnostics ? { registrationDiagnostics: receipt.registrationDiagnostics } : {},
|
|
2238
|
-
nearProvisioning: { status: "near_pending" }
|
|
2239
|
-
});
|
|
2240
|
-
}
|
|
2241
2245
|
case "ecdsa_ready": {
|
|
2242
2246
|
if (!isRegistrationEcdsaReadyReceipt(receipt)) throw new Error("Registration activation receipt branch is invalid");
|
|
2243
2247
|
const registrationEstablishedSession = replayDirectRegistrationEstablishedEcdsaSession(receipt);
|
|
@@ -2306,15 +2310,7 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2306
2310
|
authMethod: authMethod.authMethod
|
|
2307
2311
|
});
|
|
2308
2312
|
}
|
|
2309
|
-
/**
|
|
2310
|
-
* Deferred NEAR provisioning. Verifies the signed setup, then reuses the
|
|
2311
|
-
* existing deferred Ed25519 commit — the same path lazy-Yao 4+5 built — so
|
|
2312
|
-
* signer installation and the implicit-account projection keep one
|
|
2313
|
-
* implementation across both plans.
|
|
2314
|
-
*
|
|
2315
|
-
* A retryable failure leaves the pending wallet intact: the wallet must not
|
|
2316
|
-
* be destroyed because its signer ceremony needs another attempt.
|
|
2317
|
-
*/
|
|
2313
|
+
/** Verifies registration or continuation authority without destroying retryable state. */
|
|
2318
2314
|
async verifyNearProvisioningAuthority(input) {
|
|
2319
2315
|
if (input.authorization.kind === "registration_grant") {
|
|
2320
2316
|
const verified = await verifyWalletRegistrationSetupClaims(input.verifier, input.signedSetup, {
|
|
@@ -2360,7 +2356,7 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2360
2356
|
}
|
|
2361
2357
|
};
|
|
2362
2358
|
}
|
|
2363
|
-
async completeWalletRegistrationNearProvisioning(input, timingSink) {
|
|
2359
|
+
async completeWalletRegistrationNearProvisioning(input, timingSink, waitUntil) {
|
|
2364
2360
|
const serverTiming = timingSink ?? [];
|
|
2365
2361
|
const totalStartedAtMs = Date.now();
|
|
2366
2362
|
try {
|
|
@@ -2372,11 +2368,14 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2372
2368
|
code: verified.code,
|
|
2373
2369
|
message: verified.message
|
|
2374
2370
|
};
|
|
2375
|
-
const
|
|
2371
|
+
const admissionStartedAtMs = Date.now();
|
|
2372
|
+
const operationKey = `near-provisioning:${input.registrationCeremonyId}:${input.idempotencyKey}`;
|
|
2373
|
+
const initial = await this.registrationRead.readFinalization({
|
|
2376
2374
|
ceremonyId: verified.claims.registrationCeremonyId,
|
|
2377
2375
|
walletId: walletIdFromString(verified.claims.walletId)
|
|
2378
|
-
});
|
|
2379
|
-
|
|
2376
|
+
}, operationKey);
|
|
2377
|
+
recordRegistrationServerTiming(serverTiming, "near_finalize_initial_read", admissionStartedAtMs);
|
|
2378
|
+
if (!initial.ok) return initial;
|
|
2380
2379
|
const fingerprintStartedAtMs = Date.now();
|
|
2381
2380
|
const requestFingerprint = base64UrlEncode(await sha256BytesUtf8(alphabetizeStringify({
|
|
2382
2381
|
version: "wallet_registration_near_provisioning_digest_v1",
|
|
@@ -2388,19 +2387,34 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2388
2387
|
})));
|
|
2389
2388
|
recordRegistrationServerTiming(serverTiming, "near_finalize_fingerprint", fingerprintStartedAtMs);
|
|
2390
2389
|
const sideEffectStartedAtMs = Date.now();
|
|
2391
|
-
|
|
2390
|
+
let preparedCeremony = null;
|
|
2391
|
+
const run = await runRouterAbEd25519YaoRegistrationSideEffectV2(this.registrationRead.operations, {
|
|
2392
2392
|
kind: "prepared_resumable",
|
|
2393
2393
|
operation: "near_provisioning",
|
|
2394
|
-
key:
|
|
2394
|
+
key: operationKey,
|
|
2395
|
+
initialRecord: initial.operation,
|
|
2395
2396
|
requestFingerprint,
|
|
2396
2397
|
resumeAfterMs: D1_WALLET_REGISTRATION_OPERATION_RESUME_AFTER_MS,
|
|
2397
2398
|
nowMs: Date.now,
|
|
2398
|
-
prepare: async () =>
|
|
2399
|
+
prepare: async () => {
|
|
2400
|
+
const preparation = await this.prepareNearProvisioningOperation(input.registrationCeremonyId, null, verified.source.kind === "committed_mixed" ? {
|
|
2401
|
+
kind: "installation",
|
|
2402
|
+
installation: verified.source.installation
|
|
2403
|
+
} : {
|
|
2404
|
+
kind: "ceremony",
|
|
2405
|
+
ceremony: await initial.readCeremony()
|
|
2406
|
+
});
|
|
2407
|
+
preparedCeremony = preparation.ceremony;
|
|
2408
|
+
return preparation.prepared;
|
|
2409
|
+
},
|
|
2399
2410
|
derivePreparedArtifactFingerprint: async (prepared) => base64UrlEncode(await sha256BytesUtf8(alphabetizeStringify(prepared))),
|
|
2400
2411
|
execute: this.commitDeferredEd25519Signer.bind(this, {
|
|
2401
2412
|
input,
|
|
2413
|
+
serverTiming,
|
|
2402
2414
|
setupClaims: verified.claims,
|
|
2403
|
-
authoritySource: verified.source
|
|
2415
|
+
authoritySource: verified.source,
|
|
2416
|
+
preparedCeremony: () => preparedCeremony,
|
|
2417
|
+
lifecycleDecision: initial.decision
|
|
2404
2418
|
}),
|
|
2405
2419
|
projectReceipt: (execution) => projectWalletRegistrationSessionCommitReceiptV2({
|
|
2406
2420
|
operation: "near_provisioning",
|
|
@@ -2408,6 +2422,7 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2408
2422
|
registrationCeremonyId: input.registrationCeremonyId,
|
|
2409
2423
|
execution
|
|
2410
2424
|
}),
|
|
2425
|
+
completionWrite: registrationCommitActivation,
|
|
2411
2426
|
replay: this.replayWalletRegistrationNearProvisioningCommit.bind(this)
|
|
2412
2427
|
});
|
|
2413
2428
|
recordRegistrationServerTiming(serverTiming, "near_finalize_side_effect", sideEffectStartedAtMs);
|
|
@@ -2454,12 +2469,6 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2454
2469
|
message: "NEAR provisioning did not establish a Wallet Session",
|
|
2455
2470
|
nearProvisioning: { status: "near_failed_retryable" }
|
|
2456
2471
|
};
|
|
2457
|
-
const completedHome = await completeRegistrationReservation(this.registrationAuthority, {
|
|
2458
|
-
ceremonyId: input.registrationCeremonyId,
|
|
2459
|
-
walletId: walletIdFromString(committed.walletId),
|
|
2460
|
-
outcome: "established"
|
|
2461
|
-
});
|
|
2462
|
-
if (!completedHome.ok) return completedHome;
|
|
2463
2472
|
const cleanup = recordRegistrationPromiseTiming({
|
|
2464
2473
|
sink: serverTiming,
|
|
2465
2474
|
name: "near_finalize_cleanup",
|
|
@@ -2469,6 +2478,7 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2469
2478
|
registrationCeremonyId: input.registrationCeremonyId
|
|
2470
2479
|
})
|
|
2471
2480
|
});
|
|
2481
|
+
if (waitUntil) waitUntil(cleanup);
|
|
2472
2482
|
if (input.authorization.kind === "wallet_session") {
|
|
2473
2483
|
const projectionStartedAtMs = Date.now();
|
|
2474
2484
|
const [current] = await Promise.all([recordRegistrationPromiseTiming({
|
|
@@ -2480,7 +2490,7 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2480
2490
|
token: input.authorization.credential,
|
|
2481
2491
|
nowMs: Date.now()
|
|
2482
2492
|
})
|
|
2483
|
-
}), cleanup]);
|
|
2493
|
+
}), waitUntil ? void 0 : cleanup]);
|
|
2484
2494
|
const tokens = committed.registrationEstablishedSession.session.tokens;
|
|
2485
2495
|
if (!current || tokens.kind !== "near_ed25519_and_evm_family_ecdsa") throw new Error("NEAR continuation Wallet Session is no longer active");
|
|
2486
2496
|
recordRegistrationServerTiming(serverTiming, "near_finalize_total", totalStartedAtMs);
|
|
@@ -2494,7 +2504,7 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2494
2504
|
nearProvisioning: { status: "near_ready" }
|
|
2495
2505
|
};
|
|
2496
2506
|
}
|
|
2497
|
-
await cleanup;
|
|
2507
|
+
if (!waitUntil) await cleanup;
|
|
2498
2508
|
recordRegistrationServerTiming(serverTiming, "near_finalize_total", totalStartedAtMs);
|
|
2499
2509
|
return {
|
|
2500
2510
|
...committed,
|
|
@@ -2511,100 +2521,6 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2511
2521
|
}
|
|
2512
2522
|
}
|
|
2513
2523
|
/**
|
|
2514
|
-
* Persists the Ed25519-only wallet in `near_pending`: wallet, profile, and
|
|
2515
|
-
* authentication state, and no signer record — the signer does not exist
|
|
2516
|
-
* until deferred Yao produces it.
|
|
2517
|
-
*
|
|
2518
|
-
* The terminal response carries no signer, resolved account, or key
|
|
2519
|
-
* identity, because none of those are known yet. Reporting them would be
|
|
2520
|
-
* fabricating readiness.
|
|
2521
|
-
*/
|
|
2522
|
-
async commitEd25519PendingWallet(input) {
|
|
2523
|
-
const now = Date.now();
|
|
2524
|
-
const ceremony = input.ceremony;
|
|
2525
|
-
const authority = input.authority;
|
|
2526
|
-
const wallet = buildD1WalletRecord({
|
|
2527
|
-
walletId: ceremony.intent.walletId,
|
|
2528
|
-
now
|
|
2529
|
-
});
|
|
2530
|
-
const walletAuthAuthority = registrationWalletAuthAuthority({
|
|
2531
|
-
authority,
|
|
2532
|
-
walletAuthMethodId: input.walletAuthMethodId
|
|
2533
|
-
});
|
|
2534
|
-
switch (authority.kind) {
|
|
2535
|
-
case "passkey":
|
|
2536
|
-
await this.walletRegistrationCommitStore.commit({
|
|
2537
|
-
kind: "passkey_wallet_registration_commit_v1",
|
|
2538
|
-
wallet,
|
|
2539
|
-
walletSigners: [],
|
|
2540
|
-
authority,
|
|
2541
|
-
now,
|
|
2542
|
-
decisionStatements: []
|
|
2543
|
-
});
|
|
2544
|
-
break;
|
|
2545
|
-
case "email_otp": {
|
|
2546
|
-
const enrollment = await this.emailOtpRegistrationEnrollmentFinalizer.prepareRegistrationFinalize({
|
|
2547
|
-
authority,
|
|
2548
|
-
request: input.enrollment,
|
|
2549
|
-
walletId: ceremony.intent.walletId,
|
|
2550
|
-
orgId: ceremony.orgId,
|
|
2551
|
-
nowMs: now
|
|
2552
|
-
});
|
|
2553
|
-
if (!enrollment.ok) return enrollment;
|
|
2554
|
-
if (!enrollment.persistence) return {
|
|
2555
|
-
ok: false,
|
|
2556
|
-
code: "invalid_state",
|
|
2557
|
-
message: "Email OTP registration is missing enrollment persistence state"
|
|
2558
|
-
};
|
|
2559
|
-
await this.walletRegistrationCommitStore.commit({
|
|
2560
|
-
kind: "email_otp_wallet_registration_commit_v1",
|
|
2561
|
-
wallet,
|
|
2562
|
-
walletSigners: [],
|
|
2563
|
-
authority,
|
|
2564
|
-
emailOtp: this.emailOtpRegistrationEnrollmentFinalizer.prepareRegistrationCommitPlan(enrollment.persistence),
|
|
2565
|
-
now,
|
|
2566
|
-
decisionStatements: []
|
|
2567
|
-
});
|
|
2568
|
-
const completedIdentity = await this.emailOtpRegistrationEnrollmentFinalizer.completeRegistrationIdentity({
|
|
2569
|
-
authority,
|
|
2570
|
-
walletId: ceremony.intent.walletId
|
|
2571
|
-
});
|
|
2572
|
-
if (!completedIdentity.ok) return completedIdentity;
|
|
2573
|
-
break;
|
|
2574
|
-
}
|
|
2575
|
-
}
|
|
2576
|
-
const authMethod = walletRegistrationFinalizeAuthMethodFromAuthority(authority);
|
|
2577
|
-
if (authMethod.kind === "passkey") {
|
|
2578
|
-
if (!isPasskeyWalletAuthAuthority(walletAuthAuthority)) return {
|
|
2579
|
-
ok: false,
|
|
2580
|
-
code: "internal",
|
|
2581
|
-
message: "Passkey registration returned a different authority"
|
|
2582
|
-
};
|
|
2583
|
-
return buildWalletRegistrationActivatePendingPasskeyResponse({
|
|
2584
|
-
walletId: ceremony.intent.walletId,
|
|
2585
|
-
authority: walletAuthAuthority,
|
|
2586
|
-
authMethod,
|
|
2587
|
-
rpId: finalizePasskeyRpId(authority)
|
|
2588
|
-
});
|
|
2589
|
-
}
|
|
2590
|
-
if (!isEmailOtpWalletAuthAuthority(walletAuthAuthority)) return {
|
|
2591
|
-
ok: false,
|
|
2592
|
-
code: "internal",
|
|
2593
|
-
message: "Email OTP registration returned a different authority"
|
|
2594
|
-
};
|
|
2595
|
-
return buildWalletRegistrationActivatePendingEmailOtpResponse({
|
|
2596
|
-
walletId: ceremony.intent.walletId,
|
|
2597
|
-
authority: walletAuthAuthority,
|
|
2598
|
-
authMethod
|
|
2599
|
-
});
|
|
2600
|
-
}
|
|
2601
|
-
/**
|
|
2602
|
-
* Ed25519-only respond. The wallet's sole signer is Yao, and that is
|
|
2603
|
-
* deliberately not a reason to block: the admission is returned as deferred
|
|
2604
|
-
* work exactly as on a mixed plan, and the wallet lives in `near_pending`
|
|
2605
|
-
* until the computation completes.
|
|
2606
|
-
*/
|
|
2607
|
-
/**
|
|
2608
2524
|
* Respond replay stays authority-bound.
|
|
2609
2525
|
*
|
|
2610
2526
|
* `signedSetup` is client-carried, so possession of it must never recover a
|
|
@@ -2646,6 +2562,7 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2646
2562
|
async respondEd25519OnlyRegistration(input) {
|
|
2647
2563
|
const ceremony = input.ceremony;
|
|
2648
2564
|
const stored = storedRespondEd25519DeferredWork(ceremony.signerState);
|
|
2565
|
+
let authority;
|
|
2649
2566
|
if (stored) {
|
|
2650
2567
|
const replayAuthority = await this.verifyRespondReplayAuthority({
|
|
2651
2568
|
ceremony,
|
|
@@ -2653,74 +2570,95 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2653
2570
|
expectedOrigin: input.expectedOrigin,
|
|
2654
2571
|
...input.userAgent ? { userAgent: input.userAgent } : {}
|
|
2655
2572
|
});
|
|
2656
|
-
if (!replayAuthority.ok) return
|
|
2573
|
+
if (!replayAuthority.ok) return replayAuthority;
|
|
2574
|
+
const retainedAuthority = verifiedRegistrationCeremonyAuthority(ceremony);
|
|
2575
|
+
if (!retainedAuthority) return {
|
|
2657
2576
|
ok: false,
|
|
2658
|
-
code:
|
|
2659
|
-
message:
|
|
2577
|
+
code: "invalid_state",
|
|
2578
|
+
message: "Registration authority is unavailable"
|
|
2660
2579
|
};
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2580
|
+
authority = retainedAuthority;
|
|
2581
|
+
} else {
|
|
2582
|
+
const verified = await this.walletAuthMethods.verifyRegistrationAuthorityForIntent({
|
|
2583
|
+
orgId: ceremony.orgId,
|
|
2584
|
+
authority: input.authorityInput,
|
|
2585
|
+
expectedDigestB64u: ceremony.digestB64u,
|
|
2586
|
+
expectedOrigin: input.expectedOrigin,
|
|
2587
|
+
intent: ceremony.intent,
|
|
2588
|
+
verificationOperationId: ceremony.registrationCeremonyId,
|
|
2589
|
+
verificationReceiptExpiresAtMs: ceremony.expiresAtMs,
|
|
2590
|
+
...input.userAgent ? { userAgent: input.userAgent } : {}
|
|
2591
|
+
});
|
|
2592
|
+
if (!verified.ok) return {
|
|
2593
|
+
ok: false,
|
|
2594
|
+
code: verified.code,
|
|
2595
|
+
message: verified.message
|
|
2666
2596
|
};
|
|
2597
|
+
authority = verified.authority;
|
|
2667
2598
|
}
|
|
2668
|
-
const verifiedAuthority = await this.walletAuthMethods.verifyRegistrationAuthorityForIntent({
|
|
2669
|
-
orgId: ceremony.orgId,
|
|
2670
|
-
authority: input.authorityInput,
|
|
2671
|
-
expectedDigestB64u: ceremony.digestB64u,
|
|
2672
|
-
expectedOrigin: input.expectedOrigin,
|
|
2673
|
-
intent: ceremony.intent,
|
|
2674
|
-
verificationOperationId: ceremony.registrationCeremonyId,
|
|
2675
|
-
verificationReceiptExpiresAtMs: ceremony.expiresAtMs,
|
|
2676
|
-
...input.userAgent ? { userAgent: input.userAgent } : {}
|
|
2677
|
-
});
|
|
2678
|
-
if (!verifiedAuthority.ok) return {
|
|
2679
|
-
ok: false,
|
|
2680
|
-
code: verifiedAuthority.code,
|
|
2681
|
-
message: verifiedAuthority.message
|
|
2682
|
-
};
|
|
2683
|
-
const authority = verifiedAuthority.authority;
|
|
2684
2599
|
if (authority.walletId !== ceremony.intent.walletId) return {
|
|
2685
2600
|
ok: false,
|
|
2686
2601
|
code: "scope_mismatch",
|
|
2687
2602
|
message: "registration authority walletId does not match the ceremony"
|
|
2688
2603
|
};
|
|
2689
|
-
const
|
|
2604
|
+
const runtime = this.getEd25519YaoProductRegistration();
|
|
2605
|
+
if (!runtime) return {
|
|
2606
|
+
ok: false,
|
|
2607
|
+
code: "not_configured",
|
|
2608
|
+
message: "Ed25519 Yao registration is unavailable"
|
|
2609
|
+
};
|
|
2610
|
+
const admissionRequest = stored ? stored.admissionRequest : await buildRespondEd25519AdmissionRequest({
|
|
2690
2611
|
ceremony,
|
|
2691
2612
|
branch: input.branch,
|
|
2692
2613
|
authority,
|
|
2693
|
-
|
|
2614
|
+
signingWorkerId: runtime.signingWorkerId
|
|
2615
|
+
});
|
|
2616
|
+
const verifiedAuthority = authority;
|
|
2617
|
+
const branchKey = input.branch.branchKey;
|
|
2618
|
+
const ceremonyStore = this.getRegistrationCeremonyIntentStore();
|
|
2619
|
+
const authorizedCeremony = (bound) => ({
|
|
2620
|
+
...ceremony,
|
|
2621
|
+
authorityState: {
|
|
2622
|
+
kind: "verified",
|
|
2623
|
+
authority: verifiedAuthority
|
|
2624
|
+
},
|
|
2625
|
+
signerState: {
|
|
2626
|
+
kind: "signer_set_registration",
|
|
2627
|
+
branches: [buildStoredWalletRegistrationNearEd25519YaoAuthorizedBranch({
|
|
2628
|
+
branchKey,
|
|
2629
|
+
admissionRequest: bound
|
|
2630
|
+
})]
|
|
2631
|
+
}
|
|
2694
2632
|
});
|
|
2633
|
+
const admitted = await runtime.bindAndAdmitVerifiedRegistration({
|
|
2634
|
+
kind: "verified_registration_intent",
|
|
2635
|
+
ownershipGeneration: input.ownershipGeneration,
|
|
2636
|
+
registrationIntentGrant: registrationIntentGrantFromString(input.registrationBearerToken),
|
|
2637
|
+
intent: ceremony.intent,
|
|
2638
|
+
admissionRequest,
|
|
2639
|
+
expiresAtMs: ceremony.expiresAtMs
|
|
2640
|
+
}, stored ? null : (bound) => ceremonyStore.prepareEcdsaClaimCommit({
|
|
2641
|
+
expected: input.snapshot,
|
|
2642
|
+
next: authorizedCeremony(bound)
|
|
2643
|
+
}), input.startedDispatchRoot);
|
|
2695
2644
|
if (!admitted.ok) return {
|
|
2696
2645
|
ok: false,
|
|
2697
2646
|
code: admitted.code,
|
|
2698
2647
|
message: admitted.message
|
|
2699
2648
|
};
|
|
2700
|
-
if (!admitted.
|
|
2701
|
-
ok: false,
|
|
2702
|
-
code: "internal",
|
|
2703
|
-
message: "Ed25519 admission produced no branch"
|
|
2704
|
-
};
|
|
2705
|
-
await this.getRegistrationCeremonyIntentStore().commitEcdsaClaim({
|
|
2649
|
+
if (!stored && admitted.companionWrite === "not_committed") await ceremonyStore.commitEcdsaClaim({
|
|
2706
2650
|
expected: input.snapshot,
|
|
2707
|
-
next:
|
|
2708
|
-
...ceremony,
|
|
2709
|
-
authorityState: {
|
|
2710
|
-
kind: "verified",
|
|
2711
|
-
authority
|
|
2712
|
-
},
|
|
2713
|
-
signerState: {
|
|
2714
|
-
kind: "signer_set_registration",
|
|
2715
|
-
branches: [admitted.branch]
|
|
2716
|
-
}
|
|
2717
|
-
}
|
|
2651
|
+
next: authorizedCeremony(admitted.admissionRequest)
|
|
2718
2652
|
});
|
|
2719
2653
|
return {
|
|
2720
2654
|
ok: true,
|
|
2721
2655
|
registrationCeremonyId: ceremony.registrationCeremonyId,
|
|
2722
2656
|
kind: "near_ed25519",
|
|
2723
|
-
ed25519:
|
|
2657
|
+
ed25519: {
|
|
2658
|
+
status: "admitted",
|
|
2659
|
+
admissionRequest: admitted.admissionRequest,
|
|
2660
|
+
admissionReceipt: admitted.value
|
|
2661
|
+
}
|
|
2724
2662
|
};
|
|
2725
2663
|
}
|
|
2726
2664
|
/**
|
|
@@ -2741,21 +2679,15 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2741
2679
|
code: "not_configured",
|
|
2742
2680
|
message: "Ed25519 Yao product registration is not configured"
|
|
2743
2681
|
};
|
|
2744
|
-
const admissionRequest = await
|
|
2745
|
-
|
|
2746
|
-
walletId: input.ceremony.intent.walletId,
|
|
2747
|
-
signingRootId: normalizeOptionalTrimmedString(input.ceremony.signingRootId) || "",
|
|
2748
|
-
signingRootVersion: normalizeOptionalTrimmedString(input.ceremony.signingRootVersion) || "",
|
|
2749
|
-
authorityScope: registrationEd25519AuthorityScopeFromAuthority(input.authority),
|
|
2682
|
+
const admissionRequest = await buildRespondEd25519AdmissionRequest({
|
|
2683
|
+
ceremony: input.ceremony,
|
|
2750
2684
|
branch: input.branch,
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
walletId: input.ceremony.intent.walletId,
|
|
2754
|
-
signingWorkerId: yaoRuntime.signingWorkerId
|
|
2755
|
-
})
|
|
2685
|
+
authority: input.authority,
|
|
2686
|
+
signingWorkerId: yaoRuntime.signingWorkerId
|
|
2756
2687
|
});
|
|
2757
2688
|
const admitted = await yaoRuntime.bindVerifiedIntent({
|
|
2758
2689
|
kind: "verified_registration_intent",
|
|
2690
|
+
ownershipGeneration: input.ownershipGeneration,
|
|
2759
2691
|
registrationIntentGrant: registrationIntentGrantFromString(input.registrationBearerToken),
|
|
2760
2692
|
intent: input.ceremony.intent,
|
|
2761
2693
|
admissionRequest,
|
|
@@ -2832,10 +2764,14 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2832
2764
|
kind: "prepared_resumable",
|
|
2833
2765
|
operation: "registration_activate",
|
|
2834
2766
|
key: `registration-activate:${claims.registrationCeremonyId}:${idempotencyKey}`,
|
|
2767
|
+
initialRecord: await this.activateSideEffects.read(`registration-activate:${claims.registrationCeremonyId}:${idempotencyKey}`),
|
|
2835
2768
|
requestFingerprint: activateDigestB64u,
|
|
2836
2769
|
resumeAfterMs: D1_WALLET_REGISTRATION_OPERATION_RESUME_AFTER_MS,
|
|
2837
2770
|
nowMs: Date.now,
|
|
2838
|
-
prepare: async () => await this.prepareNearProvisioningOperation(claims.registrationCeremonyId
|
|
2771
|
+
prepare: async () => (await this.prepareNearProvisioningOperation(claims.registrationCeremonyId, null, {
|
|
2772
|
+
kind: "ceremony",
|
|
2773
|
+
ceremony: await this.getRegistrationCeremonyIntentStore().getCeremony(claims.registrationCeremonyId)
|
|
2774
|
+
})).prepared,
|
|
2839
2775
|
derivePreparedArtifactFingerprint: async (prepared) => base64UrlEncode(await sha256BytesUtf8(alphabetizeStringify(prepared))),
|
|
2840
2776
|
execute: this.executeWalletRegistrationActivation.bind(this, {
|
|
2841
2777
|
registrationCeremonyId: claims.registrationCeremonyId,
|
|
@@ -2850,19 +2786,12 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2850
2786
|
registrationCeremonyId: claims.registrationCeremonyId,
|
|
2851
2787
|
execution
|
|
2852
2788
|
}),
|
|
2789
|
+
completionWrite: registrationCommitActivation,
|
|
2853
2790
|
replay: this.replayWalletRegistrationActivateCommit.bind(this)
|
|
2854
2791
|
});
|
|
2855
2792
|
switch (run.kind) {
|
|
2856
2793
|
case "executed":
|
|
2857
2794
|
case "exact_replay":
|
|
2858
|
-
if (run.value.response.ok && run.value.response.kind !== "near_ed25519") {
|
|
2859
|
-
const completedHome = await completeRegistrationReservation(this.registrationAuthority, {
|
|
2860
|
-
ceremonyId: claims.registrationCeremonyId,
|
|
2861
|
-
walletId: walletIdFromString(run.value.response.walletId),
|
|
2862
|
-
outcome: "established"
|
|
2863
|
-
});
|
|
2864
|
-
if (!completedHome.ok) return completedHome;
|
|
2865
|
-
}
|
|
2866
2795
|
if (run.value.response.ok && run.value.response.kind === "evm_family_ecdsa") await cleanupFinalizedRegistrationCeremony({
|
|
2867
2796
|
store: this.getRegistrationCeremonyIntentStore(),
|
|
2868
2797
|
registrationCeremonyId: claims.registrationCeremonyId
|
|
@@ -2909,36 +2838,15 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2909
2838
|
code: "not_found",
|
|
2910
2839
|
message: "registration ceremony not found"
|
|
2911
2840
|
});
|
|
2912
|
-
|
|
2913
|
-
if (!ceremonyAuthority) return unissuedRegistrationCommit({
|
|
2841
|
+
if (!verifiedRegistrationCeremonyAuthority(ceremony)) return unissuedRegistrationCommit({
|
|
2914
2842
|
ok: false,
|
|
2915
2843
|
code: "invalid_state",
|
|
2916
2844
|
message: "registration ceremony has not verified its authority proof"
|
|
2917
2845
|
});
|
|
2918
|
-
if (!registrationSignerBranchesFromPlan(ceremony.signerPlan).evmFamilyEcdsa) {
|
|
2919
|
-
const expectedOrigin = normalizeOptionalTrimmedString(ceremony.expectedOrigin);
|
|
2920
|
-
if (!expectedOrigin) return unissuedRegistrationCommit({
|
|
2921
|
-
ok: false,
|
|
2922
|
-
code: "invalid_state",
|
|
2923
|
-
message: "registration ceremony has no expected origin"
|
|
2924
|
-
});
|
|
2925
|
-
const pending = await this.commitEd25519PendingWallet({
|
|
2926
|
-
ceremony,
|
|
2927
|
-
authority: ceremonyAuthority,
|
|
2928
|
-
walletAuthMethodId: prepared.walletAuthMethodId,
|
|
2929
|
-
enrollment: { ...context.input.emailOtpEnrollment ? { emailOtpEnrollment: context.input.emailOtpEnrollment } : {} }
|
|
2930
|
-
});
|
|
2931
|
-
if (!pending.ok) return unissuedRegistrationCommit(pending);
|
|
2932
|
-
return {
|
|
2933
|
-
kind: "near_pending",
|
|
2934
|
-
response: pending,
|
|
2935
|
-
expectedOrigin
|
|
2936
|
-
};
|
|
2937
|
-
}
|
|
2938
|
-
if (!context.input.ecdsa) return unissuedRegistrationCommit({
|
|
2846
|
+
if (!registrationSignerBranchesFromPlan(ceremony.signerPlan).evmFamilyEcdsa) return unissuedRegistrationCommit({
|
|
2939
2847
|
ok: false,
|
|
2940
|
-
code: "
|
|
2941
|
-
message: "
|
|
2848
|
+
code: "scope_mismatch",
|
|
2849
|
+
message: "NEAR-only registration commits through NEAR finalization"
|
|
2942
2850
|
});
|
|
2943
2851
|
const ecdsa = context.input.ecdsa;
|
|
2944
2852
|
const activated = await this.activateWalletRegistrationEcdsa({
|
|
@@ -2958,22 +2866,30 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2958
2866
|
code: "internal",
|
|
2959
2867
|
message: "ECDSA activation completed without a key handle to commit"
|
|
2960
2868
|
});
|
|
2961
|
-
const
|
|
2962
|
-
if (!
|
|
2963
|
-
const
|
|
2869
|
+
const activatedCeremony = await this.getRegistrationCeremonyIntentStore().getCeremony(context.registrationCeremonyId);
|
|
2870
|
+
if (!activatedCeremony) throw new Error("Registration owner proof context is unavailable");
|
|
2871
|
+
const ownerProofContext = registrationOwnerProofContextFromCeremony(activatedCeremony);
|
|
2872
|
+
const execution = await this.executeWalletRegistrationFinalize({
|
|
2964
2873
|
kind: "evm_family_ecdsa",
|
|
2965
2874
|
registrationCeremonyId: context.registrationCeremonyId,
|
|
2966
2875
|
idempotencyKey: context.idempotencyKey,
|
|
2967
2876
|
ecdsa: { expectedKeyHandles: [keyHandle] },
|
|
2968
2877
|
...context.input.emailOtpEnrollment ? { emailOtpEnrollment: context.input.emailOtpEnrollment } : {},
|
|
2969
2878
|
...context.input.walletCustodyCommit !== void 0 ? { walletCustodyCommit: context.input.walletCustodyCommit } : {}
|
|
2970
|
-
}, prepared,
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2879
|
+
}, prepared, {
|
|
2880
|
+
kind: "stored_ceremony",
|
|
2881
|
+
ceremony: activatedCeremony
|
|
2882
|
+
}, [], { kind: "separate" }, null);
|
|
2883
|
+
if (!execution.ok) return unissuedRegistrationCommit(throwIfRouterAbEd25519YaoRetryableSideEffectFailureV1(execution));
|
|
2884
|
+
const commit = execution.finalized;
|
|
2885
|
+
if (commit.kind !== "evm_family_ecdsa") {
|
|
2886
|
+
await execution.custody;
|
|
2887
|
+
return unissuedRegistrationCommit({
|
|
2888
|
+
ok: false,
|
|
2889
|
+
code: "internal",
|
|
2890
|
+
message: "registration activation committed a non-ECDSA branch"
|
|
2891
|
+
});
|
|
2892
|
+
}
|
|
2977
2893
|
let installationProjection = null;
|
|
2978
2894
|
if (registrationSignerBranchesFromPlan(ceremony.signerPlan).nearEd25519) {
|
|
2979
2895
|
const committedCeremony = await this.getRegistrationCeremonyIntentStore().getCeremony(context.registrationCeremonyId);
|
|
@@ -2982,25 +2898,30 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
2982
2898
|
}
|
|
2983
2899
|
const runtimePolicyScope = registrationPreparedContextRuntimePolicyScope(ceremony.preparedContext);
|
|
2984
2900
|
if (!runtimePolicyScope) throw new Error("ECDSA registration is missing runtime policy scope");
|
|
2985
|
-
|
|
2901
|
+
if (!this.registrationAuthority) throw new Error("Registration home completion is unavailable");
|
|
2902
|
+
const proof = await this.registrationOwnerProofWithContext(ownerProofContext, {
|
|
2903
|
+
registrationCeremonyId: context.registrationCeremonyId,
|
|
2904
|
+
authMethod: commit.authMethod,
|
|
2905
|
+
authority: commit.authority
|
|
2906
|
+
});
|
|
2907
|
+
const [issuance, custody] = await Promise.allSettled([issueDirectRegistrationEstablishedEcdsaSession({
|
|
2908
|
+
homeCompletion: this.registrationAuthority,
|
|
2986
2909
|
authorizationService: this.authorizationService,
|
|
2987
2910
|
authorizationTenantId: this.authorizationTenantId,
|
|
2988
|
-
|
|
2911
|
+
foundingAuthority: commit.foundingAuthority,
|
|
2989
2912
|
registrationCeremonyId: context.registrationCeremonyId,
|
|
2990
2913
|
authority: commit.authority,
|
|
2991
|
-
registrationAuthority: ceremonyAuthority,
|
|
2992
2914
|
walletAuthMethodId: prepared.walletAuthMethodId,
|
|
2993
2915
|
expiresAtMs: activated.ecdsa.bootstrap.expiresAtMs,
|
|
2994
2916
|
remainingUses: activated.ecdsa.bootstrap.remainingUses,
|
|
2995
2917
|
bootstrap: activated.ecdsa.bootstrap,
|
|
2996
2918
|
runtimePolicyScope,
|
|
2997
2919
|
keyManifestDigestB64u: commit.custodyKeyManifestDigestB64u,
|
|
2998
|
-
proof
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
});
|
|
2920
|
+
proof
|
|
2921
|
+
}), execution.custody]);
|
|
2922
|
+
if (issuance.status === "rejected") throw issuance.reason;
|
|
2923
|
+
if (custody.status === "rejected") throw custody.reason;
|
|
2924
|
+
const registrationEstablishedSession = issuance.value;
|
|
3004
2925
|
const registrationEstablishedSessionResult = registrationEstablishedSessionResultFromIssuance(registrationEstablishedSession);
|
|
3005
2926
|
const responseBase = {
|
|
3006
2927
|
ok: true,
|
|
@@ -3010,7 +2931,7 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3010
2931
|
foundingAuthority: commit.foundingAuthority,
|
|
3011
2932
|
foundingAuthMethod: commit.foundingAuthMethod,
|
|
3012
2933
|
...commit.registrationDiagnostics ? { registrationDiagnostics: commit.registrationDiagnostics } : {},
|
|
3013
|
-
...
|
|
2934
|
+
...custody.value.status === "not_requested" ? {} : { walletCustody: custody.value },
|
|
3014
2935
|
custodyKeyManifestDigestB64u: commit.custodyKeyManifestDigestB64u,
|
|
3015
2936
|
ecdsa: {
|
|
3016
2937
|
...commit.ecdsa,
|
|
@@ -3022,7 +2943,8 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3022
2943
|
};
|
|
3023
2944
|
const issuedContext = {
|
|
3024
2945
|
issuedAtMs: registrationEstablishedSession.issuedAtMs,
|
|
3025
|
-
expectedOrigin: ownerProofContext.expectedOrigin
|
|
2946
|
+
expectedOrigin: ownerProofContext.expectedOrigin,
|
|
2947
|
+
activation: registrationEstablishedSession.activation
|
|
3026
2948
|
};
|
|
3027
2949
|
if (commit.authMethod.kind === "passkey") {
|
|
3028
2950
|
if (!commit.rpId) throw new Error("Passkey registration activation is missing its RP ID");
|
|
@@ -3293,9 +3215,10 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3293
3215
|
};
|
|
3294
3216
|
}
|
|
3295
3217
|
}
|
|
3296
|
-
async executeWalletRegistrationFinalize(request, prepared,
|
|
3218
|
+
async executeWalletRegistrationFinalize(request, prepared, source, serverTiming, initialSessionPlan, lifecycleDecision) {
|
|
3297
3219
|
const finalizeTiming = createD1RegistrationRouteTimingRecorder("wallets_register_finalize");
|
|
3298
3220
|
const totalTiming = startD1RegistrationRouteTiming("registerFinalizeTotalMs");
|
|
3221
|
+
let startedCustody = null;
|
|
3299
3222
|
try {
|
|
3300
3223
|
const store = this.getRegistrationCeremonyIntentStore();
|
|
3301
3224
|
if (!normalizeOptionalTrimmedString(request.idempotencyKey)) return {
|
|
@@ -3304,29 +3227,20 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3304
3227
|
message: "registration finalize idempotencyKey is required"
|
|
3305
3228
|
};
|
|
3306
3229
|
const requestFingerprint = await walletRegistrationFinalizeRequestFingerprint(request);
|
|
3307
|
-
const
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
}
|
|
3314
|
-
|
|
3315
|
-
if (storedCeremony) {
|
|
3316
|
-
if (storedCeremony.signerState.kind !== "signer_set_registration") return {
|
|
3317
|
-
ok: false,
|
|
3318
|
-
code: "invalid_state",
|
|
3319
|
-
message: "signer-set registration state is required"
|
|
3320
|
-
};
|
|
3321
|
-
ceremony = registrationFinalizeCeremonyFromStored(storedCeremony);
|
|
3322
|
-
} else if (recovery) {
|
|
3230
|
+
const storedCeremony = source.kind === "stored_ceremony" ? source.ceremony : null;
|
|
3231
|
+
const ceremony = source.kind === "stored_ceremony" ? registrationFinalizeCeremonyFromStored(source.ceremony) : source.ceremony;
|
|
3232
|
+
if (ceremony.registrationCeremonyId !== request.registrationCeremonyId) return {
|
|
3233
|
+
ok: false,
|
|
3234
|
+
code: "scope_mismatch",
|
|
3235
|
+
message: "registration ceremony mismatch"
|
|
3236
|
+
};
|
|
3237
|
+
if (source.kind === "committed_mixed_installation") {
|
|
3323
3238
|
if (request.kind !== "near_ed25519") return {
|
|
3324
3239
|
ok: false,
|
|
3325
3240
|
code: "invalid_state",
|
|
3326
3241
|
message: "committed mixed registration can only finalize NEAR Ed25519"
|
|
3327
3242
|
};
|
|
3328
|
-
|
|
3329
|
-
} else return {
|
|
3243
|
+
} else if (ceremony.expiresAtMs <= Date.now()) return {
|
|
3330
3244
|
ok: false,
|
|
3331
3245
|
code: "not_found",
|
|
3332
3246
|
message: "registration ceremony not found"
|
|
@@ -3351,7 +3265,7 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3351
3265
|
message: "registration signer set requires a signer branch"
|
|
3352
3266
|
};
|
|
3353
3267
|
const storedEcdsaBranch = findStoredWalletRegistrationEvmFamilyEcdsaBranch(ceremony.signerState);
|
|
3354
|
-
const ecdsaAlreadyFinalized =
|
|
3268
|
+
const ecdsaAlreadyFinalized = source.kind === "committed_mixed_installation" || storedEcdsaBranch?.kind === "evm_family_ecdsa_finalized";
|
|
3355
3269
|
const sequenceFailure = finalizeSignerWorkSequenceFailure({
|
|
3356
3270
|
request,
|
|
3357
3271
|
hasNearEd25519: requestedNearEd25519 !== null,
|
|
@@ -3478,8 +3392,26 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3478
3392
|
let ed25519SignerRecord = null;
|
|
3479
3393
|
let ed25519MaterialActivation = null;
|
|
3480
3394
|
let ed25519RegisteredPublicKeyB64u = null;
|
|
3481
|
-
let ed25519CapabilityInstallation = null;
|
|
3482
3395
|
let yaoDecision = null;
|
|
3396
|
+
let yaoDecisionFound = null;
|
|
3397
|
+
let commitWallet;
|
|
3398
|
+
const reserveCustody = () => recordRegistrationPromiseTiming({
|
|
3399
|
+
sink: serverTiming,
|
|
3400
|
+
name: "near_finalize_custody_reserve",
|
|
3401
|
+
startedAtMs: Date.now(),
|
|
3402
|
+
promise: reserveRegistrationCustody({
|
|
3403
|
+
payload: walletCustodyCommitPayload,
|
|
3404
|
+
verifiedWalletId: ceremony.intent.walletId,
|
|
3405
|
+
verifiedAuthority: walletAuthAuthority,
|
|
3406
|
+
...emailOtpEnrollment.persistence ? { verifiedEmailOtpEnrollment: {
|
|
3407
|
+
enrollmentId: emailOtpEnrollment.persistence.enrollment.enrollmentId,
|
|
3408
|
+
enrollmentSealKeyVersion: emailOtpEnrollment.persistence.enrollment.enrollmentSealKeyVersion
|
|
3409
|
+
} } : {},
|
|
3410
|
+
nowMs: now,
|
|
3411
|
+
store: this.walletCustodyCommitStore
|
|
3412
|
+
})
|
|
3413
|
+
});
|
|
3414
|
+
let custodyReservation;
|
|
3483
3415
|
if (finalizeNearEd25519) {
|
|
3484
3416
|
const yaoRuntime = this.getEd25519YaoProductRegistration();
|
|
3485
3417
|
if (!yaoRuntime) return {
|
|
@@ -3505,13 +3437,24 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3505
3437
|
code: "scope_mismatch",
|
|
3506
3438
|
message: "Ed25519 activation reference does not belong to this registration ceremony"
|
|
3507
3439
|
};
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3440
|
+
custodyReservation = reserveCustody();
|
|
3441
|
+
startedCustody = custodyReservation;
|
|
3442
|
+
const [activationConsumption, authorityReservation] = await Promise.allSettled([recordRegistrationPromiseTiming({
|
|
3443
|
+
sink: serverTiming,
|
|
3444
|
+
name: "near_finalize_router_consume",
|
|
3445
|
+
startedAtMs: Date.now(),
|
|
3446
|
+
promise: yaoRuntime.consumeActivated({
|
|
3447
|
+
reference: {
|
|
3448
|
+
lifecycleId: activationReference.lifecycle_id,
|
|
3449
|
+
sessionId: activationReference.session_id
|
|
3450
|
+
},
|
|
3451
|
+
consumerBinding: requestFingerprint
|
|
3452
|
+
})
|
|
3453
|
+
}), this.walletRegistrationCommitStore.reserveAuthority(ceremonyAuthority)]);
|
|
3454
|
+
if (activationConsumption.status === "rejected") throw activationConsumption.reason;
|
|
3455
|
+
if (authorityReservation.status === "rejected") throw authorityReservation.reason;
|
|
3456
|
+
const consumed = activationConsumption.value;
|
|
3457
|
+
commitWallet = authorityReservation.value;
|
|
3515
3458
|
if (!consumed.ok) return {
|
|
3516
3459
|
ok: false,
|
|
3517
3460
|
code: consumed.code,
|
|
@@ -3575,7 +3518,7 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3575
3518
|
});
|
|
3576
3519
|
if (!resolved.ok) return resolved;
|
|
3577
3520
|
resolvedNearAccount = resolved.value;
|
|
3578
|
-
|
|
3521
|
+
const activeYaoCapability = buildRouterAbEd25519YaoRegistrationCapabilityRecordV1({
|
|
3579
3522
|
kind: "router_ab_ed25519_yao_registration_finalize_capability_v1",
|
|
3580
3523
|
activeCapabilityBinding: consumed.activation.result.binding.session_id,
|
|
3581
3524
|
nearAccountId,
|
|
@@ -3583,8 +3526,7 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3583
3526
|
registrationAdmissionReceipt: consumed.activation.admissionReceipt,
|
|
3584
3527
|
registrationResult: consumed.activation.result,
|
|
3585
3528
|
runtimePolicyScope
|
|
3586
|
-
};
|
|
3587
|
-
const activeYaoCapability = buildRouterAbEd25519YaoRegistrationCapabilityRecordV1(ed25519CapabilityInstallation);
|
|
3529
|
+
});
|
|
3588
3530
|
if (!activeYaoCapability.ok) return {
|
|
3589
3531
|
ok: false,
|
|
3590
3532
|
code: activeYaoCapability.code,
|
|
@@ -3597,6 +3539,7 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3597
3539
|
consumerBinding: requestFingerprint,
|
|
3598
3540
|
capability: activeYaoCapability.record
|
|
3599
3541
|
});
|
|
3542
|
+
yaoDecisionFound = routerAbEd25519YaoLifecycleDecisionLookupV1(yaoDecision, lifecycleDecision);
|
|
3600
3543
|
const activatedEd25519PublicResult = {
|
|
3601
3544
|
signerSlot: finalizeNearEd25519.signerSlot,
|
|
3602
3545
|
nearAccountId,
|
|
@@ -3632,14 +3575,18 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3632
3575
|
custodyKeyManifestDigestB64u,
|
|
3633
3576
|
now
|
|
3634
3577
|
});
|
|
3578
|
+
} else {
|
|
3579
|
+
custodyReservation = reserveCustody();
|
|
3580
|
+
startedCustody = custodyReservation;
|
|
3581
|
+
commitWallet = await this.walletRegistrationCommitStore.reserveAuthority(ceremonyAuthority);
|
|
3635
3582
|
}
|
|
3636
|
-
const yaoDecisionFound = yaoDecision ? routerAbEd25519YaoLifecycleDecisionLookupV1(yaoDecision, await this.yaoLifecycleDecisions.read(yaoDecision.lifecycleId)) : null;
|
|
3637
3583
|
if (yaoDecisionFound?.kind === "decided_otherwise") return {
|
|
3638
3584
|
ok: false,
|
|
3639
3585
|
code: "invalid_state",
|
|
3640
3586
|
message: "Ed25519 Yao registration lifecycle was finalized by another request"
|
|
3641
3587
|
};
|
|
3642
3588
|
let foundingAuthorityRecords = null;
|
|
3589
|
+
let initialSession = { kind: "uncommitted" };
|
|
3643
3590
|
if (yaoDecisionFound?.kind !== "decided") {
|
|
3644
3591
|
const wallet = buildD1WalletRecord({
|
|
3645
3592
|
walletId: ceremony.intent.walletId,
|
|
@@ -3765,6 +3712,7 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3765
3712
|
}
|
|
3766
3713
|
const decisionStatements = yaoDecision ? this.yaoLifecycleDecisions.prepareDecideStatements(yaoDecision, now) : [];
|
|
3767
3714
|
const persistenceTiming = startD1RegistrationRouteTiming("relayPersistenceMs");
|
|
3715
|
+
const walletCommitStartedAtMs = Date.now();
|
|
3768
3716
|
try {
|
|
3769
3717
|
switch (ceremonyAuthority.kind) {
|
|
3770
3718
|
case "passkey":
|
|
@@ -3773,24 +3721,22 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3773
3721
|
code: "invalid_state",
|
|
3774
3722
|
message: "Passkey registration cannot persist Email OTP enrollment state"
|
|
3775
3723
|
};
|
|
3776
|
-
if (foundingAuthorityRecords) await
|
|
3724
|
+
if (foundingAuthorityRecords) initialSession = await commitWalletRegistration(commitWallet, {
|
|
3777
3725
|
kind: "passkey_wallet_registration_commit_v1",
|
|
3778
3726
|
wallet,
|
|
3779
3727
|
walletSigners,
|
|
3780
|
-
authority: ceremonyAuthority,
|
|
3781
3728
|
foundingAuthority: foundingAuthorityRecords.authority,
|
|
3782
3729
|
foundingAuthMethod: foundingAuthorityRecords.authMethod,
|
|
3783
3730
|
now,
|
|
3784
3731
|
decisionStatements
|
|
3785
|
-
});
|
|
3786
|
-
else await
|
|
3732
|
+
}, initialSessionPlan);
|
|
3733
|
+
else initialSession = await commitWalletRegistration(commitWallet, {
|
|
3787
3734
|
kind: "passkey_wallet_registration_commit_v1",
|
|
3788
3735
|
wallet,
|
|
3789
3736
|
walletSigners,
|
|
3790
|
-
authority: ceremonyAuthority,
|
|
3791
3737
|
now,
|
|
3792
3738
|
decisionStatements
|
|
3793
|
-
});
|
|
3739
|
+
}, initialSessionPlan);
|
|
3794
3740
|
break;
|
|
3795
3741
|
case "email_otp": {
|
|
3796
3742
|
if (!emailOtpEnrollment.persistence) return {
|
|
@@ -3799,31 +3745,30 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3799
3745
|
message: "Email OTP registration is missing enrollment persistence state"
|
|
3800
3746
|
};
|
|
3801
3747
|
const emailOtp = this.emailOtpRegistrationEnrollmentFinalizer.prepareRegistrationCommitPlan(emailOtpEnrollment.persistence);
|
|
3802
|
-
if (foundingAuthorityRecords) await
|
|
3748
|
+
if (foundingAuthorityRecords) initialSession = await commitWalletRegistration(commitWallet, {
|
|
3803
3749
|
kind: "email_otp_wallet_registration_commit_v1",
|
|
3804
3750
|
wallet,
|
|
3805
3751
|
walletSigners,
|
|
3806
|
-
authority: ceremonyAuthority,
|
|
3807
3752
|
emailOtp,
|
|
3808
3753
|
foundingAuthority: foundingAuthorityRecords.authority,
|
|
3809
3754
|
foundingAuthMethod: foundingAuthorityRecords.authMethod,
|
|
3810
3755
|
now,
|
|
3811
3756
|
decisionStatements
|
|
3812
|
-
});
|
|
3813
|
-
else await
|
|
3757
|
+
}, initialSessionPlan);
|
|
3758
|
+
else initialSession = await commitWalletRegistration(commitWallet, {
|
|
3814
3759
|
kind: "email_otp_wallet_registration_commit_v1",
|
|
3815
3760
|
wallet,
|
|
3816
3761
|
walletSigners,
|
|
3817
|
-
authority: ceremonyAuthority,
|
|
3818
3762
|
emailOtp,
|
|
3819
3763
|
now,
|
|
3820
3764
|
decisionStatements
|
|
3821
|
-
});
|
|
3765
|
+
}, initialSessionPlan);
|
|
3822
3766
|
break;
|
|
3823
3767
|
}
|
|
3824
3768
|
}
|
|
3825
3769
|
} finally {
|
|
3826
3770
|
finishD1RegistrationRouteTiming(finalizeTiming, persistenceTiming);
|
|
3771
|
+
recordRegistrationServerTiming(serverTiming, "near_finalize_wallet_commit", walletCommitStartedAtMs);
|
|
3827
3772
|
}
|
|
3828
3773
|
}
|
|
3829
3774
|
const completedRegistrationIdentity = await this.emailOtpRegistrationEnrollmentFinalizer.completeRegistrationIdentity({
|
|
@@ -3839,36 +3784,20 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3839
3784
|
};
|
|
3840
3785
|
const foundingAuthority = persistedFoundingRecords.authority;
|
|
3841
3786
|
const foundingAuthMethod = persistedFoundingRecords.authMethod;
|
|
3842
|
-
|
|
3843
|
-
const
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
};
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
};
|
|
3855
|
-
}
|
|
3856
|
-
const walletCustody = await commitRegistrationCustody({
|
|
3857
|
-
payload: walletCustodyCommitPayload,
|
|
3858
|
-
verifiedWalletId: ceremony.intent.walletId,
|
|
3859
|
-
verifiedAuthority: walletAuthAuthority,
|
|
3860
|
-
...emailOtpEnrollment.persistence ? { verifiedEmailOtpEnrollment: {
|
|
3861
|
-
enrollmentId: emailOtpEnrollment.persistence.enrollment.enrollmentId,
|
|
3862
|
-
enrollmentSealKeyVersion: emailOtpEnrollment.persistence.enrollment.enrollmentSealKeyVersion
|
|
3863
|
-
} } : {},
|
|
3864
|
-
nowMs: now,
|
|
3865
|
-
store: this.walletCustodyCommitStore
|
|
3866
|
-
});
|
|
3867
|
-
if (walletCustody.status === "rejected") console.warn("[wallet-registration] custody commit rejected", {
|
|
3868
|
-
registrationCeremonyId: ceremony.registrationCeremonyId,
|
|
3869
|
-
reason: walletCustody.reason
|
|
3787
|
+
const custody = custodyReservation.then(async (commitCustody) => {
|
|
3788
|
+
const walletCustody = await recordRegistrationPromiseTiming({
|
|
3789
|
+
sink: serverTiming,
|
|
3790
|
+
name: "near_finalize_custody_commit",
|
|
3791
|
+
startedAtMs: Date.now(),
|
|
3792
|
+
promise: commitCustody()
|
|
3793
|
+
});
|
|
3794
|
+
if (walletCustody.status === "rejected") console.warn("[wallet-registration] custody commit rejected", {
|
|
3795
|
+
registrationCeremonyId: ceremony.registrationCeremonyId,
|
|
3796
|
+
reason: walletCustody.reason
|
|
3797
|
+
});
|
|
3798
|
+
return walletCustody;
|
|
3870
3799
|
});
|
|
3871
|
-
|
|
3800
|
+
startedCustody = custody;
|
|
3872
3801
|
const authMethod = walletRegistrationFinalizeAuthMethodFromAuthority(ceremonyAuthority);
|
|
3873
3802
|
let response;
|
|
3874
3803
|
if (ed25519PublicResult && finalizeNearEd25519 && resolvedNearAccount) {
|
|
@@ -3882,7 +3811,6 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3882
3811
|
foundingAuthMethod,
|
|
3883
3812
|
rpId: finalizePasskeyRpId(ceremonyAuthority),
|
|
3884
3813
|
authMethod,
|
|
3885
|
-
...custodyField,
|
|
3886
3814
|
custodyKeyManifestDigestB64u,
|
|
3887
3815
|
authorityScope,
|
|
3888
3816
|
accountProvisioning: finalizeNearEd25519.accountProvisioning,
|
|
@@ -3896,7 +3824,6 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3896
3824
|
foundingAuthority,
|
|
3897
3825
|
foundingAuthMethod,
|
|
3898
3826
|
authMethod,
|
|
3899
|
-
...custodyField,
|
|
3900
3827
|
custodyKeyManifestDigestB64u,
|
|
3901
3828
|
authorityScope,
|
|
3902
3829
|
accountProvisioning: finalizeNearEd25519.accountProvisioning,
|
|
@@ -3912,7 +3839,6 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3912
3839
|
foundingAuthMethod,
|
|
3913
3840
|
rpId: finalizePasskeyRpId(ceremonyAuthority),
|
|
3914
3841
|
authMethod,
|
|
3915
|
-
...custodyField,
|
|
3916
3842
|
custodyKeyManifestDigestB64u,
|
|
3917
3843
|
ecdsa: { walletKeys: ecdsaWalletKeys }
|
|
3918
3844
|
} : {
|
|
@@ -3923,7 +3849,6 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3923
3849
|
foundingAuthority,
|
|
3924
3850
|
foundingAuthMethod,
|
|
3925
3851
|
authMethod,
|
|
3926
|
-
...custodyField,
|
|
3927
3852
|
custodyKeyManifestDigestB64u,
|
|
3928
3853
|
ecdsa: { walletKeys: ecdsaWalletKeys }
|
|
3929
3854
|
};
|
|
@@ -3957,16 +3882,30 @@ var CloudflareD1WalletRegistrationService = class {
|
|
|
3957
3882
|
}
|
|
3958
3883
|
});
|
|
3959
3884
|
finishD1RegistrationRouteTiming(finalizeTiming, totalTiming);
|
|
3960
|
-
|
|
3885
|
+
startedCustody = null;
|
|
3886
|
+
return {
|
|
3887
|
+
ok: true,
|
|
3888
|
+
finalized: withD1RegistrationRouteDiagnostics(response, finalizeTiming),
|
|
3889
|
+
custody,
|
|
3890
|
+
initialSession
|
|
3891
|
+
};
|
|
3961
3892
|
}
|
|
3962
3893
|
finishD1RegistrationRouteTiming(finalizeTiming, totalTiming);
|
|
3963
|
-
|
|
3894
|
+
startedCustody = null;
|
|
3895
|
+
return {
|
|
3896
|
+
ok: true,
|
|
3897
|
+
finalized: withD1RegistrationRouteDiagnostics(response, finalizeTiming),
|
|
3898
|
+
custody,
|
|
3899
|
+
initialSession
|
|
3900
|
+
};
|
|
3964
3901
|
} catch (error) {
|
|
3965
3902
|
return {
|
|
3966
3903
|
ok: false,
|
|
3967
3904
|
code: "internal",
|
|
3968
3905
|
message: errorMessage(error) || "Failed to finalize wallet registration ceremony"
|
|
3969
3906
|
};
|
|
3907
|
+
} finally {
|
|
3908
|
+
await startedCustody;
|
|
3970
3909
|
}
|
|
3971
3910
|
}
|
|
3972
3911
|
};
|