@seams/wallet-server 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { isPlainObject } from "../../../shared-ts/src/utils/validation.js";
|
|
2
|
+
import { walletObjectIdentity, walletObjectIdentityFromWireScope, walletObjectIdentityHeaders, walletRelocationObjectIdentity } from "./walletObjectAddresses.js";
|
|
3
|
+
import { ROUTER_AB_INTERNAL_SERVICE_AUTH_HEADER_V1 } from "../../../core/ThresholdService/routerAb/internalServiceHttp.js";
|
|
4
|
+
import { forwardPresignSource, presignSourceOperation } from "./walletRelocationPresign.js";
|
|
5
|
+
import { authorizeRuntimeSource, recordRuntimeRouterReceipt } from "./walletRelocationSource.js";
|
|
6
|
+
import { ecdsaRuntimeOperation, forwardEcdsaRelocation } from "./walletRelocationEcdsa.js";
|
|
7
|
+
import { ed25519RuntimeOperation, forwardEd25519Snapshot } from "./walletRelocationEd25519.js";
|
|
8
|
+
import { deriverRuntimeOperation, forwardDeriverRelocation } from "./walletRelocationDeriver.js";
|
|
9
|
+
//#region src/router/cloudflare/runtime/walletRelocationOps.ts
|
|
10
|
+
const ORIGIN = "https://wallet-runtime.internal";
|
|
11
|
+
const BASE_PATH = "/internal/wallet-runtime/v1/relocation";
|
|
12
|
+
const OPERATIONS = {
|
|
13
|
+
"custody-target": "/router-ab/internal/custody-target",
|
|
14
|
+
"deriver-a-activate": "/router-ab/internal/deriver-a/wallet/snapshot",
|
|
15
|
+
"deriver-a-cleanup": "/router-ab/internal/deriver-a/wallet/snapshot",
|
|
16
|
+
"deriver-b-activate": "/router-ab/internal/deriver-b/wallet/snapshot",
|
|
17
|
+
"deriver-b-cleanup": "/router-ab/internal/deriver-b/wallet/snapshot",
|
|
18
|
+
"deriver-a-capture": "/router-ab/internal/deriver-a/wallet/snapshot",
|
|
19
|
+
"deriver-a-export": "/router-ab/internal/deriver-a/wallet/snapshot",
|
|
20
|
+
"deriver-a-import": "/router-ab/internal/deriver-a/wallet/snapshot",
|
|
21
|
+
"deriver-a-status": "/router-ab/internal/deriver-a/wallet/snapshot",
|
|
22
|
+
"deriver-a-verify": "/router-ab/internal/deriver-a/wallet/snapshot",
|
|
23
|
+
"deriver-b-capture": "/router-ab/internal/deriver-b/wallet/snapshot",
|
|
24
|
+
"deriver-b-export": "/router-ab/internal/deriver-b/wallet/snapshot",
|
|
25
|
+
"deriver-b-import": "/router-ab/internal/deriver-b/wallet/snapshot",
|
|
26
|
+
"deriver-b-status": "/router-ab/internal/deriver-b/wallet/snapshot",
|
|
27
|
+
"deriver-b-verify": "/router-ab/internal/deriver-b/wallet/snapshot",
|
|
28
|
+
"deriver-a-fence": "/router-ab/internal/deriver-a/wallet/fence-relocation",
|
|
29
|
+
"deriver-b-fence": "/router-ab/internal/deriver-b/wallet/fence-relocation",
|
|
30
|
+
"signing-worker-context": "/router-ab/signing-worker/wallet/relocation-context",
|
|
31
|
+
"deriver-a-context": "/router-ab/internal/deriver-a/wallet/relocation-context",
|
|
32
|
+
"deriver-b-context": "/router-ab/internal/deriver-b/wallet/relocation-context",
|
|
33
|
+
"deriver-b-prepare": "/router-ab/internal/deriver-b/wallet/prepare-relocation",
|
|
34
|
+
"deriver-a-prepare": "/router-ab/internal/deriver-a/wallet/prepare-relocation",
|
|
35
|
+
"router-freeze": "/router-ab/router/wallet/freeze",
|
|
36
|
+
"router-cleanup": "/router-ab/router/wallet/transfer",
|
|
37
|
+
"router-activate": "/router-ab/router/wallet/transfer",
|
|
38
|
+
"router-import": "/router-ab/router/wallet/transfer",
|
|
39
|
+
"router-status": "/router-ab/router/wallet/transfer",
|
|
40
|
+
"router-verify": "/router-ab/router/wallet/transfer",
|
|
41
|
+
"router-export": "/router-ab/router/wallet/transfer",
|
|
42
|
+
"router-transfer": "/router-ab/router/wallet/transfer",
|
|
43
|
+
"ed25519-activate": "/router-ab/signing-worker/wallet/ed25519/snapshot",
|
|
44
|
+
"ed25519-cleanup": "/router-ab/signing-worker/wallet/ed25519/snapshot",
|
|
45
|
+
"ed25519-export": "/router-ab/signing-worker/wallet/ed25519/snapshot",
|
|
46
|
+
"ed25519-import": "/router-ab/signing-worker/wallet/ed25519/snapshot",
|
|
47
|
+
"ed25519-status": "/router-ab/signing-worker/wallet/ed25519/snapshot",
|
|
48
|
+
"ed25519-verify": "/router-ab/signing-worker/wallet/ed25519/snapshot",
|
|
49
|
+
"ed25519-capture": "/router-ab/signing-worker/wallet/ed25519/snapshot",
|
|
50
|
+
"ed25519-settle": "/router-ab/signing-worker/wallet/ed25519/settle",
|
|
51
|
+
"ed25519-snapshot": "/router-ab/signing-worker/wallet/ed25519/snapshot",
|
|
52
|
+
"ecdsa-import": "/router-ab/signing-worker/wallet/ecdsa/transfer",
|
|
53
|
+
"ecdsa-status": "/router-ab/signing-worker/wallet/ecdsa/transfer",
|
|
54
|
+
"ecdsa-verify": "/router-ab/signing-worker/wallet/ecdsa/transfer",
|
|
55
|
+
"ecdsa-activate": "/router-ab/signing-worker/wallet/ecdsa/transfer",
|
|
56
|
+
"ecdsa-cleanup": "/router-ab/signing-worker/wallet/ecdsa/transfer",
|
|
57
|
+
"ecdsa-freeze": "/router-ab/signing-worker/wallet/pool/freeze",
|
|
58
|
+
"ecdsa-export": "/router-ab/signing-worker/wallet/ecdsa/export",
|
|
59
|
+
"ecdsa-transfer": "/router-ab/signing-worker/wallet/ecdsa/transfer",
|
|
60
|
+
"presign-preparation-inventory": "/router-ab/signing-worker/wallet/linked-presign-preparation-inventory",
|
|
61
|
+
"presign-inventory": "/router-ab/signing-worker/wallet/linked-presign-inventory",
|
|
62
|
+
"presign-fence": "/router-ab/signing-worker/linked-presign-session/fence",
|
|
63
|
+
"presign-freeze": "/router-ab/signing-worker/linked-presign-session/freeze",
|
|
64
|
+
"presign-cleanup": "/router-ab/signing-worker/linked-presign-session/transfer",
|
|
65
|
+
"presign-status": "/router-ab/signing-worker/linked-presign-session/transfer",
|
|
66
|
+
"presign-import": "/router-ab/signing-worker/linked-presign-session/transfer",
|
|
67
|
+
"presign-verify": "/router-ab/signing-worker/linked-presign-session/transfer",
|
|
68
|
+
"presign-export": "/router-ab/signing-worker/linked-presign-session/export",
|
|
69
|
+
"presign-transfer": "/router-ab/signing-worker/linked-presign-session/transfer"
|
|
70
|
+
};
|
|
71
|
+
async function handleWalletRelocationRequest(request, env) {
|
|
72
|
+
const url = new URL(request.url);
|
|
73
|
+
if (url.origin !== ORIGIN || !url.pathname.startsWith(`${BASE_PATH}/`)) return null;
|
|
74
|
+
if (request.method !== "POST") return failure("method_not_allowed", 405);
|
|
75
|
+
const operation = url.pathname.slice(39);
|
|
76
|
+
if (!Object.hasOwn(OPERATIONS, operation) || url.search !== "") return failure("operation_not_found", 404);
|
|
77
|
+
const path = Reflect.get(OPERATIONS, operation);
|
|
78
|
+
if (typeof path !== "string") return failure("operation_not_found", 404);
|
|
79
|
+
if (!(request.headers.get("content-type") || "").toLowerCase().startsWith("application/json")) return failure("unsupported_media_type", 415);
|
|
80
|
+
const deriverAction = deriverRuntimeOperation(operation);
|
|
81
|
+
const credential = deriverAction !== null || operation === "deriver-a-prepare" || operation === "deriver-b-prepare" || operation === "deriver-a-context" || operation === "deriver-b-context" ? env.ROUTER_AB_INTERNAL_SERVICE_AUTH_SECRET?.trim() : env.ROUTER_AB_GATEWAY_TO_ROUTER_AUTH_SECRET?.trim();
|
|
82
|
+
if (!credential) return failure("relocation_transport_unavailable", 503);
|
|
83
|
+
const bytes = await request.arrayBuffer();
|
|
84
|
+
if (bytes.byteLength > 131072) return failure("request_too_large", 413);
|
|
85
|
+
let input;
|
|
86
|
+
try {
|
|
87
|
+
input = JSON.parse(new TextDecoder().decode(bytes));
|
|
88
|
+
} catch {
|
|
89
|
+
return failure("invalid_input", 400);
|
|
90
|
+
}
|
|
91
|
+
if (deriverAction) {
|
|
92
|
+
const binding = deriverAction.role === "deriver-a" ? env.DERIVER_A : env.DERIVER_B;
|
|
93
|
+
return forwardDeriverRelocation(input, deriverAction.role, deriverAction.operation, binding, credential, env);
|
|
94
|
+
}
|
|
95
|
+
const ed25519Action = ed25519RuntimeOperation(operation);
|
|
96
|
+
if (ed25519Action) return forwardEd25519Snapshot(input, ed25519Action, env.MPC_ROUTER, credential, env);
|
|
97
|
+
const ecdsaAction = ecdsaRuntimeOperation(operation);
|
|
98
|
+
if (ecdsaAction) return forwardEcdsaRelocation(input, ecdsaAction, env.MPC_ROUTER, credential, env);
|
|
99
|
+
const presignAction = presignSourceOperation(operation);
|
|
100
|
+
if (presignAction) return forwardPresignSource(input, presignAction, env.MPC_ROUTER, credential, env);
|
|
101
|
+
let body = bytes;
|
|
102
|
+
let identity = null;
|
|
103
|
+
if (operation === "router-cleanup" || operation === "router-activate" || operation === "router-import" || operation === "router-status" || operation === "router-verify" || operation === "router-export" || operation === "router-freeze" || operation === "ed25519-settle") {
|
|
104
|
+
const authorized = await authorizeRuntimeSource(input, operation, env);
|
|
105
|
+
if (!authorized.ok) {
|
|
106
|
+
let status = 503;
|
|
107
|
+
if (authorized.code === "invalid_input") status = 400;
|
|
108
|
+
else if (authorized.code === "source_command_denied") status = 409;
|
|
109
|
+
return failure(authorized.code, status);
|
|
110
|
+
}
|
|
111
|
+
body = authorized.body;
|
|
112
|
+
identity = authorized.identity;
|
|
113
|
+
} else if (operation === "router-transfer" && isPlainObject(input) && (input.kind === "export" || input.kind === "status" || input.kind === "verify" || input.kind === "import" || input.kind === "activate" || input.kind === "cleanup")) return failure("source_command_required", 400);
|
|
114
|
+
else if ((operation === "ecdsa-transfer" || operation === "presign-transfer") && (!isPlainObject(input) || input.kind !== "prepare")) return failure("source_command_required", 400);
|
|
115
|
+
else if (operation === "ed25519-snapshot" && isPlainObject(input) && (input.command === "capture" || input.command === "export" || input.command === "import" || input.command === "status" || input.command === "verify" || input.command === "activate" || input.command === "cleanup")) return failure("source_command_required", 400);
|
|
116
|
+
if ((operation === "deriver-a-prepare" || operation === "deriver-b-prepare" || operation === "deriver-a-context" || operation === "deriver-b-context") && isPlainObject(input) && isPlainObject(input.owner)) identity = walletObjectIdentity(input.owner.wallet_id, operation.endsWith("-prepare") ? input.destination_generation : input.ownership_generation, {
|
|
117
|
+
orgId: input.owner.org_id,
|
|
118
|
+
projectId: input.owner.project_id,
|
|
119
|
+
envId: input.owner.env_id
|
|
120
|
+
});
|
|
121
|
+
if (isPlainObject(input)) {
|
|
122
|
+
if (operation === "router-transfer" && input.kind === "prepare" && isPlainObject(input.request) && isPlainObject(input.request.owner)) {
|
|
123
|
+
const owner = input.request.owner;
|
|
124
|
+
identity = walletObjectIdentity(owner.wallet_id, input.request.destination_generation, {
|
|
125
|
+
orgId: owner.org_id,
|
|
126
|
+
projectId: owner.project_id,
|
|
127
|
+
envId: owner.env_id
|
|
128
|
+
});
|
|
129
|
+
} else if (operation === "ecdsa-transfer" && input.kind === "prepare" && isPlainObject(input.request)) {
|
|
130
|
+
const source = walletObjectIdentityFromWireScope(input.scope, input.request.source_generation);
|
|
131
|
+
identity = walletObjectIdentity(source.walletId, source.ownershipGeneration + 1, source);
|
|
132
|
+
} else if (operation === "ed25519-snapshot" && input.command === "prepare" && isPlainObject(input.source) && isPlainObject(input.source.request)) {
|
|
133
|
+
const source = walletObjectIdentityFromWireScope(input.source.scope, input.source.request.source_generation);
|
|
134
|
+
identity = walletObjectIdentity(source.walletId, source.ownershipGeneration + 1, source);
|
|
135
|
+
} else if (operation === "presign-transfer" && input.kind === "prepare" && isPlainObject(input.command) && isPlainObject(input.command.request)) {
|
|
136
|
+
const source = walletObjectIdentityFromWireScope(input.command.wallet_scope, input.command.request.source_generation);
|
|
137
|
+
identity = walletObjectIdentity(source.walletId, source.ownershipGeneration + 1, source);
|
|
138
|
+
} else if (operation === "presign-preparation-inventory") identity = walletObjectIdentityFromWireScope(input.scope, input.source_generation);
|
|
139
|
+
}
|
|
140
|
+
if (operation === "custody-target" && isPlainObject(input) && input.role !== "presignSessions") {
|
|
141
|
+
if (!isPlainObject(input.wallet)) return failure("invalid_input", 400);
|
|
142
|
+
identity = walletRelocationObjectIdentity(input.wallet, input.ownership_generation);
|
|
143
|
+
body = JSON.stringify({
|
|
144
|
+
role: input.role,
|
|
145
|
+
object_name: input.object_name,
|
|
146
|
+
placement: input.placement
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
let transport = env.MPC_ROUTER;
|
|
150
|
+
let origin = "https://mpc-router.router-ab.internal";
|
|
151
|
+
if (operation === "deriver-a-prepare" || operation === "deriver-a-context") {
|
|
152
|
+
transport = env.DERIVER_A;
|
|
153
|
+
origin = "https://deriver-a.router-ab.internal";
|
|
154
|
+
} else if (operation === "deriver-b-prepare" || operation === "deriver-b-context") {
|
|
155
|
+
transport = env.DERIVER_B;
|
|
156
|
+
origin = "https://deriver-b.router-ab.internal";
|
|
157
|
+
}
|
|
158
|
+
const response = await transport.fetch(new Request(`${origin}${path}`, {
|
|
159
|
+
method: "POST",
|
|
160
|
+
redirect: "manual",
|
|
161
|
+
headers: {
|
|
162
|
+
"content-type": "application/json",
|
|
163
|
+
...identity === null ? {} : walletObjectIdentityHeaders(identity),
|
|
164
|
+
[ROUTER_AB_INTERNAL_SERVICE_AUTH_HEADER_V1]: credential
|
|
165
|
+
},
|
|
166
|
+
body
|
|
167
|
+
}));
|
|
168
|
+
if (operation === "router-freeze" || operation === "router-activate") return recordRuntimeRouterReceipt(operation, input, response, env);
|
|
169
|
+
return response;
|
|
170
|
+
}
|
|
171
|
+
function failure(code, status) {
|
|
172
|
+
return Response.json({
|
|
173
|
+
ok: false,
|
|
174
|
+
code
|
|
175
|
+
}, {
|
|
176
|
+
status,
|
|
177
|
+
headers: { "Cache-Control": "no-store" }
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
//#endregion
|
|
181
|
+
export { handleWalletRelocationRequest };
|
|
182
|
+
|
|
183
|
+
//# sourceMappingURL=walletRelocationOps.js.map
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { isPlainObject } from "../../../shared-ts/src/utils/validation.js";
|
|
2
|
+
import { walletObjectIdentityHeaders, walletRelocationObjectIdentity } from "./walletObjectAddresses.js";
|
|
3
|
+
import { ROUTER_AB_INTERNAL_SERVICE_AUTH_HEADER_V1 } from "../../../core/ThresholdService/routerAb/internalServiceHttp.js";
|
|
4
|
+
//#region src/router/cloudflare/runtime/walletRelocationPresign.ts
|
|
5
|
+
function presignSourceOperation(operation) {
|
|
6
|
+
switch (operation) {
|
|
7
|
+
case "presign-inventory": return "inventory";
|
|
8
|
+
case "presign-fence": return "fence";
|
|
9
|
+
case "presign-freeze": return "freeze";
|
|
10
|
+
case "presign-export": return "export";
|
|
11
|
+
case "presign-import": return "import";
|
|
12
|
+
case "presign-verify": return "verify";
|
|
13
|
+
case "presign-status": return "status";
|
|
14
|
+
case "presign-cleanup": return "cleanup";
|
|
15
|
+
default: return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async function forwardPresignSource(input, operation, router, credential, directory) {
|
|
19
|
+
if (operation === "export" || operation === "import" || operation === "verify" || operation === "status" || operation === "cleanup") return forwardPresignTransfer(input, operation, router, credential, directory);
|
|
20
|
+
if (!isPlainObject(input) || Object.keys(input).length !== (operation === "inventory" ? 4 : 3) || !isPlainObject(input.wallet) || !isPlainObject(input.attempt)) return failure("invalid_input", 400);
|
|
21
|
+
const request = operation === "inventory" ? {
|
|
22
|
+
operation,
|
|
23
|
+
cursor: input.cursor,
|
|
24
|
+
limit: input.limit
|
|
25
|
+
} : {
|
|
26
|
+
operation,
|
|
27
|
+
session: input.session
|
|
28
|
+
};
|
|
29
|
+
try {
|
|
30
|
+
const authorized = await postDirectory(directory, "relocation-presign-source", {
|
|
31
|
+
wallet: input.wallet,
|
|
32
|
+
attempt: input.attempt,
|
|
33
|
+
request
|
|
34
|
+
});
|
|
35
|
+
if (!authorized.ok) return failure("source_command_denied", 409);
|
|
36
|
+
const result = await authorized.json();
|
|
37
|
+
if (!isPlainObject(result) || Object.keys(result).length !== 2 || result.ok !== true || !isPlainObject(result.command) || Object.keys(result.command).length !== 2 || result.command.operation !== operation || !isPlainObject(result.command.payload)) return failure("source_command_unavailable", 503);
|
|
38
|
+
const payload = result.command.payload;
|
|
39
|
+
const scope = operation === "inventory" ? payload.scope : payload.wallet_scope;
|
|
40
|
+
if (Object.keys(payload).length !== 4 || !isPlainObject(scope) || Object.keys(scope).length !== 4 || typeof scope.org_id !== "string" || scope.org_id !== input.wallet.organizationId || typeof scope.project_id !== "string" || scope.project_id !== input.wallet.projectId || typeof scope.project_environment_id !== "string" || scope.project_environment_id !== input.wallet.environmentId || typeof scope.wallet_id !== "string" || scope.wallet_id !== input.wallet.walletId || !isPlainObject(payload.request) || Object.keys(payload.request).length !== 3 || typeof payload.request.move_id !== "string" || payload.request.move_id !== input.attempt.moveId || !positiveInteger(payload.request.source_generation) || !positiveInteger(payload.request.invalidated_at_ms)) return failure("source_command_unavailable", 503);
|
|
41
|
+
let path;
|
|
42
|
+
if (operation === "inventory") {
|
|
43
|
+
if (!sameFields(payload.cursor, input.cursor) || payload.limit !== input.limit || !positiveInteger(payload.limit) || payload.limit > 128) return failure("source_command_unavailable", 503);
|
|
44
|
+
path = "/router-ab/signing-worker/wallet/linked-presign-inventory";
|
|
45
|
+
} else {
|
|
46
|
+
if (!isPlainObject(input.session) || Object.keys(input.session).length !== 2 || typeof input.session.presignSessionId !== "string" || !input.session.presignSessionId.trim() || typeof input.session.serverPresignatureId !== "string" || !input.session.serverPresignatureId.trim() || payload.presign_session_id !== input.session.presignSessionId || payload.server_presignature_id !== input.session.serverPresignatureId) return failure("source_command_unavailable", 503);
|
|
47
|
+
path = `/router-ab/signing-worker/linked-presign-session/${operation}`;
|
|
48
|
+
}
|
|
49
|
+
const response = await router.fetch(new Request(`https://mpc-router.router-ab.internal${path}`, {
|
|
50
|
+
method: "POST",
|
|
51
|
+
redirect: "manual",
|
|
52
|
+
headers: {
|
|
53
|
+
"content-type": "application/json",
|
|
54
|
+
[ROUTER_AB_INTERNAL_SERVICE_AUTH_HEADER_V1]: credential,
|
|
55
|
+
...walletObjectIdentityHeaders(walletRelocationObjectIdentity(input.wallet, payload.request.source_generation))
|
|
56
|
+
},
|
|
57
|
+
body: JSON.stringify(payload)
|
|
58
|
+
}));
|
|
59
|
+
if (operation !== "freeze" || !response.ok) return response;
|
|
60
|
+
const raw = await response.clone().json();
|
|
61
|
+
if (!isPlainObject(raw) || Object.keys(raw).length !== 3 || !sameFields(raw.command, payload) || !positiveInteger(raw.record_count) || typeof raw.records_digest_hex !== "string" || !/^[a-f0-9]{64}$/u.test(raw.records_digest_hex)) return failure("source_receipt_unavailable", 503);
|
|
62
|
+
const receipt = {
|
|
63
|
+
command: payload,
|
|
64
|
+
record_count: raw.record_count,
|
|
65
|
+
records_digest_hex: raw.records_digest_hex
|
|
66
|
+
};
|
|
67
|
+
const recorded = await postDirectory(directory, "relocation-presign-receipt", {
|
|
68
|
+
wallet: input.wallet,
|
|
69
|
+
attempt: input.attempt,
|
|
70
|
+
receipt
|
|
71
|
+
});
|
|
72
|
+
if (!recorded.ok) return failure("source_receipt_unavailable", 503);
|
|
73
|
+
const confirmed = await recorded.json();
|
|
74
|
+
if (!isPlainObject(confirmed) || Object.keys(confirmed).length !== 2 || confirmed.ok !== true || !sameFields(confirmed.receipt, receipt)) return failure("source_receipt_unavailable", 503);
|
|
75
|
+
return response;
|
|
76
|
+
} catch {
|
|
77
|
+
return failure("source_command_unavailable", 503);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function positiveInteger(raw) {
|
|
81
|
+
return typeof raw === "number" && Number.isSafeInteger(raw) && raw > 0;
|
|
82
|
+
}
|
|
83
|
+
function sameFields(left, right) {
|
|
84
|
+
if (!isPlainObject(left) || !isPlainObject(right)) return left === right;
|
|
85
|
+
if (Object.keys(left).length !== Object.keys(right).length) return false;
|
|
86
|
+
for (const key of Object.keys(left)) if (!sameFields(left[key], right[key])) return false;
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
function postDirectory(directory, endpoint, body) {
|
|
90
|
+
const version = directory.CF_VERSION_METADATA.id;
|
|
91
|
+
if (typeof version !== "string" || !version) throw new Error("Runtime version is unavailable");
|
|
92
|
+
return directory.WALLET_CONSOLE.fetch(new Request(`https://wallet-placement.internal/internal/wallet-placement/v1/${endpoint}`, {
|
|
93
|
+
method: "POST",
|
|
94
|
+
headers: {
|
|
95
|
+
"content-type": "application/json",
|
|
96
|
+
"x-seams-writer-role": "walletRuntime",
|
|
97
|
+
"x-seams-writer-version": version,
|
|
98
|
+
"x-seams-writer-account": directory.SEAMS_D1_HOME_ACCOUNT_ID,
|
|
99
|
+
"x-seams-writer-database": directory.SEAMS_D1_HOME_DATABASE_ID
|
|
100
|
+
},
|
|
101
|
+
body: JSON.stringify(body)
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
function failure(code, status) {
|
|
105
|
+
return Response.json({
|
|
106
|
+
ok: false,
|
|
107
|
+
code
|
|
108
|
+
}, {
|
|
109
|
+
status,
|
|
110
|
+
headers: { "Cache-Control": "no-store" }
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
async function forwardPresignTransfer(input, operation, router, credential, directory) {
|
|
114
|
+
if (!isPlainObject(input) || Object.keys(input).length !== (operation === "verify" || operation === "status" || operation === "cleanup" ? 3 : 4) || !isPlainObject(input.wallet) || !isPlainObject(input.attempt) || !isPlainObject(input.session) || Object.keys(input.session).length !== 2 || typeof input.session.presignSessionId !== "string" || !input.session.presignSessionId.trim() || typeof input.session.serverPresignatureId !== "string" || !input.session.serverPresignatureId.trim()) return failure("invalid_input", 400);
|
|
115
|
+
if (operation === "export" && !segmentIndex(input.segmentIndex)) return failure("invalid_input", 400);
|
|
116
|
+
const request = operation === "export" ? {
|
|
117
|
+
operation,
|
|
118
|
+
session: input.session,
|
|
119
|
+
segmentIndex: input.segmentIndex
|
|
120
|
+
} : {
|
|
121
|
+
operation,
|
|
122
|
+
session: input.session
|
|
123
|
+
};
|
|
124
|
+
try {
|
|
125
|
+
const authorized = await postDirectory(directory, "relocation-presign-transfer", {
|
|
126
|
+
wallet: input.wallet,
|
|
127
|
+
attempt: input.attempt,
|
|
128
|
+
request
|
|
129
|
+
});
|
|
130
|
+
if (!authorized.ok) return failure("source_command_denied", 409);
|
|
131
|
+
const result = await authorized.json();
|
|
132
|
+
if (!isPlainObject(result) || Object.keys(result).length !== 2 || result.ok !== true || !isPlainObject(result.command) || result.command.kind !== operation || Object.keys(result.command).length !== (operation === "export" ? 4 : operation === "import" || operation === "status" ? 3 : 2)) return failure("source_command_unavailable", 503);
|
|
133
|
+
const command = result.command;
|
|
134
|
+
const receipt = command.receipt;
|
|
135
|
+
if (!isPlainObject(receipt) || Object.keys(receipt).length !== 3 || !positiveInteger(receipt.record_count) || typeof receipt.records_digest_hex !== "string" || !/^[a-f0-9]{64}$/u.test(receipt.records_digest_hex) || !isPlainObject(receipt.command) || Object.keys(receipt.command).length !== 4) return failure("source_command_unavailable", 503);
|
|
136
|
+
const source = receipt.command;
|
|
137
|
+
const scope = source.wallet_scope;
|
|
138
|
+
const move = source.request;
|
|
139
|
+
if (!isPlainObject(scope) || Object.keys(scope).length !== 4 || scope.org_id !== input.wallet.organizationId || scope.project_id !== input.wallet.projectId || scope.project_environment_id !== input.wallet.environmentId || scope.wallet_id !== input.wallet.walletId || !isPlainObject(move) || Object.keys(move).length !== 3 || move.move_id !== input.attempt.moveId || !positiveInteger(move.source_generation) || !positiveInteger(move.invalidated_at_ms) || source.presign_session_id !== input.session.presignSessionId || source.server_presignature_id !== input.session.serverPresignatureId || operation !== "verify" && operation !== "cleanup" && command.chunk_bytes !== 4096) return failure("source_command_unavailable", 503);
|
|
140
|
+
let payload;
|
|
141
|
+
if (operation === "export") {
|
|
142
|
+
if (command.segment_index !== input.segmentIndex) return failure("source_command_unavailable", 503);
|
|
143
|
+
payload = {
|
|
144
|
+
receipt,
|
|
145
|
+
segment_index: command.segment_index,
|
|
146
|
+
chunk_bytes: 4096
|
|
147
|
+
};
|
|
148
|
+
} else if (operation === "import") {
|
|
149
|
+
const chunk = input.chunk;
|
|
150
|
+
if (!isPlainObject(chunk) || Object.keys(chunk).length !== 5 || !sameFields(chunk.receipt, receipt) || !segmentIndex(chunk.segment_index) || !positiveInteger(chunk.segment_count) || chunk.segment_count > 4294967295 || chunk.segment_index >= chunk.segment_count || chunk.chunk_bytes !== 4096 || typeof chunk.data_b64u !== "string" || chunk.data_b64u.length > 5462 || !/^[A-Za-z0-9_-]+$/u.test(chunk.data_b64u)) return failure("invalid_input", 400);
|
|
151
|
+
payload = {
|
|
152
|
+
kind: "import",
|
|
153
|
+
chunk
|
|
154
|
+
};
|
|
155
|
+
} else if (operation === "status") payload = {
|
|
156
|
+
kind: "status",
|
|
157
|
+
receipt,
|
|
158
|
+
chunk_bytes: 4096
|
|
159
|
+
};
|
|
160
|
+
else payload = {
|
|
161
|
+
kind: operation,
|
|
162
|
+
receipt
|
|
163
|
+
};
|
|
164
|
+
const path = operation === "export" ? "export" : "transfer";
|
|
165
|
+
return await router.fetch(new Request(`https://mpc-router.router-ab.internal/router-ab/signing-worker/linked-presign-session/${path}`, {
|
|
166
|
+
method: "POST",
|
|
167
|
+
redirect: "manual",
|
|
168
|
+
headers: {
|
|
169
|
+
"content-type": "application/json",
|
|
170
|
+
[ROUTER_AB_INTERNAL_SERVICE_AUTH_HEADER_V1]: credential,
|
|
171
|
+
...walletObjectIdentityHeaders(walletRelocationObjectIdentity(input.wallet, move.source_generation + (operation === "export" || operation === "cleanup" ? 0 : 1)))
|
|
172
|
+
},
|
|
173
|
+
body: JSON.stringify(payload)
|
|
174
|
+
}));
|
|
175
|
+
} catch {
|
|
176
|
+
return failure("source_command_unavailable", 503);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function segmentIndex(raw) {
|
|
180
|
+
return typeof raw === "number" && Number.isInteger(raw) && raw >= 0 && raw <= 4294967295;
|
|
181
|
+
}
|
|
182
|
+
//#endregion
|
|
183
|
+
export { forwardPresignSource, presignSourceOperation };
|
|
184
|
+
|
|
185
|
+
//# sourceMappingURL=walletRelocationPresign.js.map
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { isPlainObject } from "../../../shared-ts/src/utils/validation.js";
|
|
2
|
+
import { walletRelocationObjectIdentity } from "./walletObjectAddresses.js";
|
|
3
|
+
//#region src/router/cloudflare/runtime/walletRelocationSource.ts
|
|
4
|
+
async function authorizeRuntimeSource(input, operation, env) {
|
|
5
|
+
let fieldCount = 2;
|
|
6
|
+
if (operation === "router-export") fieldCount = 4;
|
|
7
|
+
else if (operation === "router-import") fieldCount = 3;
|
|
8
|
+
if (!isPlainObject(input) || Object.keys(input).length !== fieldCount || !isPlainObject(input.wallet) || !isPlainObject(input.attempt)) return {
|
|
9
|
+
ok: false,
|
|
10
|
+
code: "invalid_input"
|
|
11
|
+
};
|
|
12
|
+
const version = env.CF_VERSION_METADATA.id;
|
|
13
|
+
if (typeof version !== "string" || !version) return {
|
|
14
|
+
ok: false,
|
|
15
|
+
code: "source_command_unavailable"
|
|
16
|
+
};
|
|
17
|
+
const destination = operation === "router-status" || operation === "router-verify" || operation === "router-import" || operation === "router-activate";
|
|
18
|
+
const transfer = destination || operation === "router-export" || operation === "router-cleanup";
|
|
19
|
+
let endpoint = "relocation-runtime-source";
|
|
20
|
+
let commandBody = JSON.stringify({
|
|
21
|
+
wallet: input.wallet,
|
|
22
|
+
attempt: input.attempt,
|
|
23
|
+
operation
|
|
24
|
+
});
|
|
25
|
+
if (operation === "router-export") {
|
|
26
|
+
endpoint = "relocation-router-export";
|
|
27
|
+
commandBody = JSON.stringify({
|
|
28
|
+
wallet: input.wallet,
|
|
29
|
+
attempt: input.attempt,
|
|
30
|
+
recordIndex: input.recordIndex,
|
|
31
|
+
segmentIndex: input.segmentIndex
|
|
32
|
+
});
|
|
33
|
+
} else if (operation === "router-cleanup") {
|
|
34
|
+
endpoint = "relocation-router-cleanup";
|
|
35
|
+
commandBody = JSON.stringify({
|
|
36
|
+
wallet: input.wallet,
|
|
37
|
+
attempt: input.attempt
|
|
38
|
+
});
|
|
39
|
+
} else if (destination) {
|
|
40
|
+
endpoint = "relocation-router-destination";
|
|
41
|
+
let destinationOperation = "verify";
|
|
42
|
+
if (operation === "router-status") destinationOperation = "status";
|
|
43
|
+
else if (operation === "router-import") destinationOperation = "import";
|
|
44
|
+
else if (operation === "router-activate") destinationOperation = "activate";
|
|
45
|
+
commandBody = JSON.stringify({
|
|
46
|
+
wallet: input.wallet,
|
|
47
|
+
attempt: input.attempt,
|
|
48
|
+
operation: destinationOperation
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
let response;
|
|
52
|
+
let result;
|
|
53
|
+
try {
|
|
54
|
+
response = await env.WALLET_CONSOLE.fetch(new Request(`https://wallet-placement.internal/internal/wallet-placement/v1/${endpoint}`, {
|
|
55
|
+
method: "POST",
|
|
56
|
+
headers: {
|
|
57
|
+
"content-type": "application/json",
|
|
58
|
+
"x-seams-writer-role": "walletRuntime",
|
|
59
|
+
"x-seams-writer-version": version,
|
|
60
|
+
"x-seams-writer-account": env.SEAMS_D1_HOME_ACCOUNT_ID,
|
|
61
|
+
"x-seams-writer-database": env.SEAMS_D1_HOME_DATABASE_ID
|
|
62
|
+
},
|
|
63
|
+
body: commandBody
|
|
64
|
+
}));
|
|
65
|
+
if (!response.ok) return {
|
|
66
|
+
ok: false,
|
|
67
|
+
code: "source_command_denied"
|
|
68
|
+
};
|
|
69
|
+
result = await response.json();
|
|
70
|
+
} catch {
|
|
71
|
+
return {
|
|
72
|
+
ok: false,
|
|
73
|
+
code: "source_command_unavailable"
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (!isPlainObject(result) || result.ok !== true || !isPlainObject(result.command) || !transfer && (result.command.operation !== operation || !isPlainObject(result.command.payload))) return {
|
|
77
|
+
ok: false,
|
|
78
|
+
code: "source_command_unavailable"
|
|
79
|
+
};
|
|
80
|
+
const payload = transfer ? result.command : result.command.payload;
|
|
81
|
+
if (!isPlainObject(payload)) return {
|
|
82
|
+
ok: false,
|
|
83
|
+
code: "source_command_unavailable"
|
|
84
|
+
};
|
|
85
|
+
if (operation === "router-freeze" || transfer) {
|
|
86
|
+
let request = payload;
|
|
87
|
+
if (transfer) {
|
|
88
|
+
let receipt = payload.receipt;
|
|
89
|
+
if (operation === "router-cleanup") {
|
|
90
|
+
if (Object.keys(payload).length !== 2 || payload.kind !== "cleanup" || !isPlainObject(payload.activation) || Object.keys(payload.activation).length !== 2 || typeof payload.activation.destination_object !== "string" || payload.activation.destination_object.length === 0 || payload.activation.destination_object.length > 512) return {
|
|
91
|
+
ok: false,
|
|
92
|
+
code: "source_command_unavailable"
|
|
93
|
+
};
|
|
94
|
+
receipt = payload.activation.source;
|
|
95
|
+
}
|
|
96
|
+
if (!isPlainObject(receipt) || Object.keys(receipt).length !== 3 || !isPlainObject(receipt.request) || typeof receipt.records_digest_hex !== "string" || !/^[a-f0-9]{64}$/u.test(receipt.records_digest_hex) || typeof receipt.record_count !== "number" || !Number.isSafeInteger(receipt.record_count) || receipt.record_count < 0) return {
|
|
97
|
+
ok: false,
|
|
98
|
+
code: "source_command_unavailable"
|
|
99
|
+
};
|
|
100
|
+
if (operation === "router-export") {
|
|
101
|
+
if (Object.keys(payload).length !== 5 || payload.kind !== "export" || payload.record_index !== input.recordIndex || payload.segment_index !== input.segmentIndex || payload.chunk_bytes !== 4096 || typeof input.recordIndex !== "number" || !Number.isSafeInteger(input.recordIndex) || input.recordIndex < 0 || input.recordIndex >= receipt.record_count || typeof input.segmentIndex !== "number" || !Number.isSafeInteger(input.segmentIndex) || input.segmentIndex < 0 || input.segmentIndex > 4294967295) return {
|
|
102
|
+
ok: false,
|
|
103
|
+
code: "source_command_unavailable"
|
|
104
|
+
};
|
|
105
|
+
} else if (operation === "router-status" || operation === "router-import") {
|
|
106
|
+
if (Object.keys(payload).length !== 3 || payload.kind !== (operation === "router-status" ? "status" : "import") || payload.chunk_bytes !== 4096) return {
|
|
107
|
+
ok: false,
|
|
108
|
+
code: "source_command_unavailable"
|
|
109
|
+
};
|
|
110
|
+
} else if (operation !== "router-cleanup" && (Object.keys(payload).length !== 2 || payload.kind !== (operation === "router-activate" ? "activate" : "verify"))) return {
|
|
111
|
+
ok: false,
|
|
112
|
+
code: "source_command_unavailable"
|
|
113
|
+
};
|
|
114
|
+
request = receipt.request;
|
|
115
|
+
}
|
|
116
|
+
if (Object.keys(request).length !== 5 || !isPlainObject(request.owner) || Object.keys(request.owner).length !== 4 || request.owner.org_id !== input.wallet.organizationId || request.owner.project_id !== input.wallet.projectId || request.owner.env_id !== input.wallet.environmentId || request.owner.wallet_id !== input.wallet.walletId || request.move_id !== input.attempt.moveId || typeof request.request_digest_hex !== "string" || !/^[0-9a-f]{64}$/.test(request.request_digest_hex) || typeof request.source_generation !== "number" || !Number.isSafeInteger(request.source_generation) || request.source_generation < 1 || typeof request.destination_generation !== "number" || !Number.isSafeInteger(request.destination_generation) || request.destination_generation !== request.source_generation + 1) return {
|
|
117
|
+
ok: false,
|
|
118
|
+
code: "source_command_unavailable"
|
|
119
|
+
};
|
|
120
|
+
const generation = operation === "router-freeze" || operation === "router-export" || operation === "router-cleanup" ? request.source_generation : request.destination_generation;
|
|
121
|
+
const identity = walletRelocationObjectIdentity(input.wallet, generation);
|
|
122
|
+
if (operation === "router-import") return authorizeImportChunk(input.chunk, payload.receipt, identity);
|
|
123
|
+
return {
|
|
124
|
+
ok: true,
|
|
125
|
+
body: JSON.stringify(payload),
|
|
126
|
+
identity
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
const source = operation === "ed25519-capture" ? payload.source : payload;
|
|
130
|
+
if (operation === "ed25519-capture" && (payload.command !== "capture" || Object.keys(payload).length !== 2) || !isPlainObject(source) || Object.keys(source).length !== 2 || !isPlainObject(source.scope) || !isPlainObject(source.request) || Object.keys(source.scope).length !== 4 || Object.keys(source.request).length !== 3 || source.scope.org_id !== input.wallet.organizationId || source.scope.project_id !== input.wallet.projectId || source.scope.project_environment_id !== input.wallet.environmentId || source.scope.wallet_id !== input.wallet.walletId || source.request.move_id !== input.attempt.moveId || typeof source.request.source_generation !== "number" || !Number.isSafeInteger(source.request.source_generation) || source.request.source_generation < 1 || typeof source.request.invalidated_at_ms !== "number" || !Number.isSafeInteger(source.request.invalidated_at_ms) || source.request.invalidated_at_ms < 1) return {
|
|
131
|
+
ok: false,
|
|
132
|
+
code: "source_command_unavailable"
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
ok: true,
|
|
136
|
+
body: JSON.stringify(payload),
|
|
137
|
+
identity: walletRelocationObjectIdentity(input.wallet, source.request.source_generation)
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
async function recordRuntimeRouterReceipt(operation, input, response, env) {
|
|
141
|
+
if (!response.ok) return response;
|
|
142
|
+
try {
|
|
143
|
+
const result = await response.clone().json();
|
|
144
|
+
if (!isPlainObject(input) || !isPlainObject(result)) return receiptUnavailable();
|
|
145
|
+
let receipt;
|
|
146
|
+
let endpoint;
|
|
147
|
+
if (operation === "router-freeze") {
|
|
148
|
+
if (result.state === "draining") return response;
|
|
149
|
+
if (result.state !== "frozen") return receiptUnavailable();
|
|
150
|
+
receipt = result.receipt;
|
|
151
|
+
endpoint = "relocation-router-receipt";
|
|
152
|
+
} else {
|
|
153
|
+
if (result.kind !== "activated") return receiptUnavailable();
|
|
154
|
+
receipt = result.activation;
|
|
155
|
+
endpoint = "relocation-router-activation";
|
|
156
|
+
}
|
|
157
|
+
if (!isPlainObject(receipt)) return receiptUnavailable();
|
|
158
|
+
const version = env.CF_VERSION_METADATA.id;
|
|
159
|
+
if (typeof version !== "string" || !version) return receiptUnavailable();
|
|
160
|
+
const recorded = await env.WALLET_CONSOLE.fetch(new Request(`https://wallet-placement.internal/internal/wallet-placement/v1/${endpoint}`, {
|
|
161
|
+
method: "POST",
|
|
162
|
+
headers: {
|
|
163
|
+
"content-type": "application/json",
|
|
164
|
+
"x-seams-writer-role": "walletRuntime",
|
|
165
|
+
"x-seams-writer-version": version,
|
|
166
|
+
"x-seams-writer-account": env.SEAMS_D1_HOME_ACCOUNT_ID,
|
|
167
|
+
"x-seams-writer-database": env.SEAMS_D1_HOME_DATABASE_ID
|
|
168
|
+
},
|
|
169
|
+
body: JSON.stringify({
|
|
170
|
+
wallet: input.wallet,
|
|
171
|
+
attempt: input.attempt,
|
|
172
|
+
receipt
|
|
173
|
+
})
|
|
174
|
+
}));
|
|
175
|
+
if (!recorded.ok) return receiptUnavailable();
|
|
176
|
+
const acknowledgement = await recorded.json();
|
|
177
|
+
if (!isPlainObject(acknowledgement) || acknowledgement.ok !== true || !isPlainObject(acknowledgement.receipt)) return receiptUnavailable();
|
|
178
|
+
if (!sameReceipt(receipt, acknowledgement.receipt)) return receiptUnavailable();
|
|
179
|
+
return response;
|
|
180
|
+
} catch {
|
|
181
|
+
return receiptUnavailable();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function sameReceipt(expected, actual) {
|
|
185
|
+
if (Object.keys(expected).length !== Object.keys(actual).length) return false;
|
|
186
|
+
for (const key of Object.keys(expected)) {
|
|
187
|
+
const left = expected[key];
|
|
188
|
+
const right = actual[key];
|
|
189
|
+
if (isPlainObject(left) && isPlainObject(right)) {
|
|
190
|
+
if (!sameReceipt(left, right)) return false;
|
|
191
|
+
} else if (left !== right) return false;
|
|
192
|
+
}
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
function receiptUnavailable() {
|
|
196
|
+
return Response.json({
|
|
197
|
+
ok: false,
|
|
198
|
+
code: "router_receipt_unavailable"
|
|
199
|
+
}, {
|
|
200
|
+
status: 503,
|
|
201
|
+
headers: { "Cache-Control": "no-store" }
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
function authorizeImportChunk(chunk, receipt, identity) {
|
|
205
|
+
if (!isPlainObject(receipt) || !isPlainObject(chunk) || Object.keys(chunk).length !== 6 || !isPlainObject(chunk.receipt) || !sameReceipt(receipt, chunk.receipt) || typeof chunk.record_index !== "number" || !Number.isSafeInteger(chunk.record_index) || chunk.record_index < 0 || typeof receipt.record_count !== "number" || chunk.record_index >= receipt.record_count || typeof chunk.segment_index !== "number" || !Number.isSafeInteger(chunk.segment_index) || chunk.segment_index < 0 || typeof chunk.segment_count !== "number" || !Number.isSafeInteger(chunk.segment_count) || chunk.segment_count < 1 || chunk.segment_count > 4294967295 || chunk.segment_index >= chunk.segment_count || chunk.chunk_bytes !== 4096 || typeof chunk.data_b64u !== "string" || chunk.data_b64u.length > 5462 || !/^[A-Za-z0-9_-]+$/u.test(chunk.data_b64u)) return {
|
|
206
|
+
ok: false,
|
|
207
|
+
code: "invalid_input"
|
|
208
|
+
};
|
|
209
|
+
return {
|
|
210
|
+
ok: true,
|
|
211
|
+
body: JSON.stringify({
|
|
212
|
+
kind: "import",
|
|
213
|
+
chunk
|
|
214
|
+
}),
|
|
215
|
+
identity
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
//#endregion
|
|
219
|
+
export { authorizeRuntimeSource, recordRuntimeRouterReceipt };
|
|
220
|
+
|
|
221
|
+
//# sourceMappingURL=walletRelocationSource.js.map
|