@seams/wallet-server 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +8 -0
- package/artifact-manifest.json +464 -0
- package/cloudflare-router-ab/build/deriver-a/index.js +2 -0
- package/cloudflare-router-ab/build/deriver-a/index_bg.wasm +0 -0
- package/cloudflare-router-ab/build/deriver-a/package.json +16 -0
- package/cloudflare-router-ab/build/deriver-a/worker/shim.mjs +4 -0
- package/cloudflare-router-ab/build/deriver-b/index.js +2 -0
- package/cloudflare-router-ab/build/deriver-b/index_bg.wasm +0 -0
- package/cloudflare-router-ab/build/deriver-b/package.json +16 -0
- package/cloudflare-router-ab/build/deriver-b/worker/shim.mjs +4 -0
- package/cloudflare-router-ab/build/local-tools/darwin-arm64/router_ab_local_init +0 -0
- package/cloudflare-router-ab/build/router/index.js +2 -0
- package/cloudflare-router-ab/build/router/index_bg.wasm +0 -0
- package/cloudflare-router-ab/build/router/package.json +16 -0
- package/cloudflare-router-ab/build/router/worker/shim.mjs +4 -0
- package/cloudflare-router-ab/build/signing-worker/index.js +2 -0
- package/cloudflare-router-ab/build/signing-worker/index_bg.wasm +0 -0
- package/cloudflare-router-ab/build/signing-worker/package.json +16 -0
- package/cloudflare-router-ab/build/signing-worker/worker/shim.mjs +4 -0
- package/cloudflare-router-ab/build/tenant-root-control-plane/index.js +2 -0
- package/cloudflare-router-ab/build/tenant-root-control-plane/index_bg.wasm +0 -0
- package/cloudflare-router-ab/build/tenant-root-control-plane/package.json +16 -0
- package/cloudflare-router-ab/build/tenant-root-control-plane/worker/shim.mjs +4 -0
- package/cloudflare-router-ab/env/tenant-root-control-plane.local.example +6 -0
- package/cloudflare-router-ab/migrations/deriver-a/0001_role_private_storage.sql +14 -0
- package/cloudflare-router-ab/migrations/deriver-a/0002_tenant_root_role_shares.sql +32 -0
- package/cloudflare-router-ab/migrations/deriver-a/0003_tenant_root_command_replays.sql +76 -0
- package/cloudflare-router-ab/migrations/deriver-a/0004_tenant_root_creation_admission.sql +7 -0
- package/cloudflare-router-ab/migrations/deriver-a/0005_tenant_root_refresh_state.sql +15 -0
- package/cloudflare-router-ab/migrations/deriver-a/0006_tenant_root_restore_import_keys.sql +119 -0
- package/cloudflare-router-ab/migrations/deriver-a/0007_tenant_root_restore_refresh_attempts.sql +103 -0
- package/cloudflare-router-ab/migrations/deriver-a/0008_tenant_root_restore_promotion.sql +40 -0
- package/cloudflare-router-ab/migrations/deriver-a/0009_tenant_root_restore_preactivation_cleanup.sql +8 -0
- package/cloudflare-router-ab/migrations/deriver-a/0010_tenant_root_recovery_attempts.sql +26 -0
- package/cloudflare-router-ab/migrations/deriver-a/0011_tenant_root_source_retirement.sql +100 -0
- package/cloudflare-router-ab/migrations/deriver-b/0001_role_private_storage.sql +14 -0
- package/cloudflare-router-ab/migrations/deriver-b/0002_tenant_root_role_shares.sql +32 -0
- package/cloudflare-router-ab/migrations/deriver-b/0003_tenant_root_command_replays.sql +76 -0
- package/cloudflare-router-ab/migrations/deriver-b/0004_tenant_root_creation_admission.sql +7 -0
- package/cloudflare-router-ab/migrations/deriver-b/0005_tenant_root_refresh_state.sql +15 -0
- package/cloudflare-router-ab/migrations/deriver-b/0006_tenant_root_restore_import_keys.sql +119 -0
- package/cloudflare-router-ab/migrations/deriver-b/0007_tenant_root_restore_refresh_attempts.sql +103 -0
- package/cloudflare-router-ab/migrations/deriver-b/0008_tenant_root_restore_promotion.sql +40 -0
- package/cloudflare-router-ab/migrations/deriver-b/0009_tenant_root_restore_preactivation_cleanup.sql +8 -0
- package/cloudflare-router-ab/migrations/deriver-b/0010_tenant_root_recovery_attempts.sql +26 -0
- package/cloudflare-router-ab/migrations/deriver-b/0011_tenant_root_source_retirement.sql +100 -0
- package/cloudflare-router-ab/migrations/signing-worker/0001_private_storage.sql +67 -0
- package/cloudflare-router-ab/migrations/signing-worker/0002_activation_revocation_fences.sql +3 -0
- package/cloudflare-router-ab/scripts/bootstrap-local-tenant-root.mjs +182 -0
- package/cloudflare-router-ab/scripts/initialize-local-wallet.mjs +17 -0
- package/cloudflare-router-ab/scripts/local-key-material.mjs +29 -0
- package/cloudflare-router-ab/scripts/prepare-local-runtime-config.mjs +1110 -0
- package/cloudflare-router-ab/scripts/start-local-role-workers.mjs +333 -0
- package/cloudflare-router-ab/scripts/start-local-wallet-system.mjs +427 -0
- package/cloudflare-router-ab/wrangler.deriver-a.toml +123 -0
- package/cloudflare-router-ab/wrangler.deriver-b.toml +123 -0
- package/cloudflare-router-ab/wrangler.router.toml +126 -0
- package/cloudflare-router-ab/wrangler.signing-worker.toml +86 -0
- package/cloudflare-router-ab/wrangler.tenant-root-control-plane.toml +56 -0
- package/dist/esm/authorization/capabilityPolicy.js +96 -0
- package/dist/esm/authorization/domain.js +434 -0
- package/dist/esm/authorization/factorEvidence.js +405 -0
- package/dist/esm/authorization/service.js +319 -0
- package/dist/esm/authorization/vaultProxyUse.js +295 -0
- package/dist/esm/cloud-host.js +126 -0
- package/dist/esm/core/AuthService.js +2 -0
- package/dist/esm/core/EmailOtpRecords.js +361 -0
- package/dist/esm/core/EmailOtpStores.js +1460 -0
- package/dist/esm/core/IdentityStore.js +617 -0
- package/dist/esm/core/NearPublicKeyStore.js +242 -0
- package/dist/esm/core/RegistrationCeremonyStore.js +2101 -0
- package/dist/esm/core/SessionService.js +255 -0
- package/dist/esm/core/ThresholdService/config.js +111 -0
- package/dist/esm/core/ThresholdService/ecdsaClientRootProof.js +27 -0
- package/dist/esm/core/ThresholdService/evmCryptoWasm.js +167 -0
- package/dist/esm/core/ThresholdService/index.js +4 -0
- package/dist/esm/core/ThresholdService/kv.js +368 -0
- package/dist/esm/core/ThresholdService/routerAb/ecdsaDerivationPoolFillHandlers.js +360 -0
- package/dist/esm/core/ThresholdService/routerAb/ecdsaDerivationPoolFillLiveSession.js +282 -0
- package/dist/esm/core/ThresholdService/routerAb/ecdsaDerivationPresignBridge.js +272 -0
- package/dist/esm/core/ThresholdService/routerAb/internalServiceHttp.js +57 -0
- package/dist/esm/core/ThresholdService/routerAbEcdsaSigningWorkerWasm.js +115 -0
- package/dist/esm/core/ThresholdService/routerAbNormalSigningPolicy.js +31 -0
- package/dist/esm/core/ThresholdService/secureRandomId.js +9 -0
- package/dist/esm/core/ThresholdService/stores/CloudflareDurableObjectStore.js +603 -0
- package/dist/esm/core/ThresholdService/stores/EcdsaSigningStore.js +422 -0
- package/dist/esm/core/ThresholdService/stores/KeyStore.js +140 -0
- package/dist/esm/core/ThresholdService/stores/SessionStore.js +437 -0
- package/dist/esm/core/ThresholdService/stores/StoreConfig.js +13 -0
- package/dist/esm/core/ThresholdService/stores/WalletSessionStore.js +722 -0
- package/dist/esm/core/ThresholdService/validation.js +718 -0
- package/dist/esm/core/WalletAuthMethodStore.js +180 -0
- package/dist/esm/core/WalletStore.js +495 -0
- package/dist/esm/core/WebAuthnAuthenticatorStore.js +485 -0
- package/dist/esm/core/WebAuthnCredentialBindingStore.js +594 -0
- package/dist/esm/core/WebAuthnLoginChallengeStore.js +432 -0
- package/dist/esm/core/WebAuthnSyncChallengeStore.js +434 -0
- package/dist/esm/core/authService/AuthService.js +611 -0
- package/dist/esm/core/authService/bytes.js +22 -0
- package/dist/esm/core/authService/configValues.js +15 -0
- package/dist/esm/core/authService/emailOtpChallengeOperations.js +126 -0
- package/dist/esm/core/authService/emailOtpChallengeProof.js +214 -0
- package/dist/esm/core/authService/emailOtpChallengeVerification.js +335 -0
- package/dist/esm/core/authService/emailOtpChallenges.js +260 -0
- package/dist/esm/core/authService/emailOtpConfig.js +231 -0
- package/dist/esm/core/authService/emailOtpDelivery.js +169 -0
- package/dist/esm/core/authService/emailOtpEnrollment.js +141 -0
- package/dist/esm/core/authService/emailOtpGrant.js +74 -0
- package/dist/esm/core/authService/emailOtpRegistrationEnrollment.js +322 -0
- package/dist/esm/core/authService/emailOtpSeal.js +78 -0
- package/dist/esm/core/authService/emailOtpUnlock.js +264 -0
- package/dist/esm/core/authService/githubOAuth.js +140 -0
- package/dist/esm/core/authService/googleEmailOtpErrors.js +6 -0
- package/dist/esm/core/authService/googleEmailOtpOperations.js +141 -0
- package/dist/esm/core/authService/googleEmailOtpRegistration.js +674 -0
- package/dist/esm/core/authService/identity.js +57 -0
- package/dist/esm/core/authService/identityOperations.js +32 -0
- package/dist/esm/core/authService/nearAccountOperations.js +229 -0
- package/dist/esm/core/authService/nearPrivateKeySigning.js +110 -0
- package/dist/esm/core/authService/nearPublicKeyMetadata.js +127 -0
- package/dist/esm/core/authService/nearTransactions.js +139 -0
- package/dist/esm/core/authService/oidcVerification.js +262 -0
- package/dist/esm/core/authService/portableCrypto.js +19 -0
- package/dist/esm/core/authService/rateLimits.js +117 -0
- package/dist/esm/core/authService/record.js +8 -0
- package/dist/esm/core/authService/registrationThresholdHelpers.js +131 -0
- package/dist/esm/core/authService/runtime.js +45 -0
- package/dist/esm/core/authService/signerWasmUrls.js +20 -0
- package/dist/esm/core/authService/storeRegistry.js +113 -0
- package/dist/esm/core/authService/thresholdEcdsaKeyInventory.js +146 -0
- package/dist/esm/core/authService/thresholdRuntimePolicy.js +19 -0
- package/dist/esm/core/authService/thresholdStoreSummary.js +32 -0
- package/dist/esm/core/authService/walletRegistrationPlanning.js +49 -0
- package/dist/esm/core/authService/wasm.js +78 -0
- package/dist/esm/core/authService/webauthn.js +746 -0
- package/dist/esm/core/authService/webauthnAuthority.js +17 -0
- package/dist/esm/core/authService/webauthnOidcHelpers.js +91 -0
- package/dist/esm/core/authService/webauthnWalletBinding.js +157 -0
- package/dist/esm/core/config.js +110 -0
- package/dist/esm/core/d1IdentityStore.js +340 -0
- package/dist/esm/core/d1WalletAuthMethodStore.js +768 -0
- package/dist/esm/core/d1WalletStore.js +724 -0
- package/dist/esm/core/defaultConfigsServer.js +9 -0
- package/dist/esm/core/deviceLinking/index.js +5 -0
- package/dist/esm/core/deviceLinking/linkedDeviceEd25519ExportRoot.js +0 -0
- package/dist/esm/core/deviceLinking/linkedDeviceEmailOtpGrant.js +211 -0
- package/dist/esm/core/deviceLinking/linkedDeviceManagement.js +279 -0
- package/dist/esm/core/deviceLinking/linkedDeviceSession.js +1419 -0
- package/dist/esm/core/deviceLinking/requestProof.js +172 -0
- package/dist/esm/core/errors.js +54 -0
- package/dist/esm/core/hostedAccountIds.js +225 -0
- package/dist/esm/core/keyMaterialBrands.js +58 -0
- package/dist/esm/core/logger.js +39 -0
- package/dist/esm/core/nearKeys.js +20 -0
- package/dist/esm/core/nearRelayerAccountProvisioning.js +713 -0
- package/dist/esm/core/nearSignerWasmRuntime.js +87 -0
- package/dist/esm/core/registrationContracts.js +2 -0
- package/dist/esm/core/routerAbSigning/RouterAbEcdsaPresignRuntime.js +88 -0
- package/dist/esm/core/routerAbSigning/RouterAbNormalSigningRuntime.js +101 -0
- package/dist/esm/core/routerAbSigning/createCloudflareDurableObjectRouterAbSigningRuntimes.js +39 -0
- package/dist/esm/core/routerAbSigning/createRouterAbSigningRuntimes.js +91 -0
- package/dist/esm/core/rpcClients/near/NearClient.js +389 -0
- package/dist/esm/core/sessionValidation.js +0 -0
- package/dist/esm/core/signingLanes/LaneAggregateRevocationApplicationService.js +86 -0
- package/dist/esm/core/signingLanes/LaneEffectJournalStore.js +0 -0
- package/dist/esm/core/signingLanes/LaneEnrollmentActivation.js +324 -0
- package/dist/esm/core/signingLanes/LaneEnrollmentRevocation.js +173 -0
- package/dist/esm/core/signingLanes/LaneLifecycleApplicationService.js +200 -0
- package/dist/esm/core/signingLanes/LaneLifecycleStore.js +24 -0
- package/dist/esm/core/signingLanes/SigningLaneStore.js +0 -0
- package/dist/esm/core/signingLanes/WalletExecutionLaneProjection.js +296 -0
- package/dist/esm/core/signingLanes/WalletKeyStore.js +0 -0
- package/dist/esm/core/signingLanes/ecdsaServerRetirement.js +78 -0
- package/dist/esm/core/signingLanes/ed25519ServerRetirement.js +71 -0
- package/dist/esm/core/signingLanes/index.js +8 -0
- package/dist/esm/core/signingLanes/signingWorkerLaneMaterialIdentity.js +0 -0
- package/dist/esm/core/signingMaterial/ordinaryInactiveSignerMaterialReservation.js +305 -0
- package/dist/esm/core/threeRouteRegistrationContracts.js +5 -0
- package/dist/esm/core/thresholdEcdsaChainTarget.js +49 -0
- package/dist/esm/core/types.js +8 -0
- package/dist/esm/core/utils.js +14 -0
- package/dist/esm/delegateAction/index.js +136 -0
- package/dist/esm/hosted-wallet-gateway-worker.js +18 -0
- package/dist/esm/hosted-wallet-gateway.js +701 -0
- package/dist/esm/index.js +53 -0
- package/dist/esm/local-hosted-wallet-gateway-worker.js +23 -0
- package/dist/esm/node_modules/@near-js/types/lib/esm/provider/response.js +17 -0
- package/dist/esm/router/auth/authRequestValidation.js +264 -0
- package/dist/esm/router/auth/commonRouterUtils.js +305 -0
- package/dist/esm/router/auth/routerApiCredentialAuth.js +91 -0
- package/dist/esm/router/auth/routerApiKeyAuth.js +63 -0
- package/dist/esm/router/auth/walletSessionFailure.js +49 -0
- package/dist/esm/router/auth/webAuthnCredentialCodecs.js +107 -0
- package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthBoundary.js +84 -0
- package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthConfig.js +321 -0
- package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthService.js +1581 -0
- package/dist/esm/router/cloudflare/d1/authorization/d1AuthorizationStore.js +1820 -0
- package/dist/esm/router/cloudflare/d1/authorization/d1VaultProxyStore.js +122 -0
- package/dist/esm/router/cloudflare/d1/authorization/walletSessionAuthorityProjection.js +119 -0
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceAuthorityInstallService.js +1831 -0
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEd25519ExportRootStore.js +118 -0
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEmailOtpGrantStore.js +81 -0
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEmailOtpTargetFactor.js +539 -0
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceManagementService.js +92 -0
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceOwnerAuthorizationProvider.js +560 -0
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceRequestProofNonceStore.js +136 -0
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceRouteService.js +95 -0
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionRecords.js +91 -0
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionService.js +15 -0
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionStore.js +732 -0
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSourceContributionPreparationPlanner.js +195 -0
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetAuthenticatorStore.js +100 -0
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetCredentialProvider.js +867 -0
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetPlanner.js +169 -0
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceVerifiedLinkBuilder.js +255 -0
- package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceVerifiedLinkSourceReader.js +128 -0
- package/dist/esm/router/cloudflare/d1/deviceLinking/index.js +15 -0
- package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoCapabilityPersistence.js +311 -0
- package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoProductRegistrationPartitionedStateStore.js +21 -0
- package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoWalletSigner.js +65 -0
- package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeIssuer.js +216 -0
- package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeService.js +326 -0
- package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeStore.js +346 -0
- package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeVerifier.js +495 -0
- package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpDeliveryRuntime.js +157 -0
- package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpEnrollmentStore.js +248 -0
- package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpGrantStore.js +66 -0
- package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRateLimitStore.js +76 -0
- package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRecords.js +539 -0
- package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRecoveryService.js +404 -0
- package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRegistrationEnrollmentFinalizer.js +200 -0
- package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpServerSealRuntime.js +84 -0
- package/dist/esm/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpRegistrationAttemptStore.js +217 -0
- package/dist/esm/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpRegistrationRecords.js +485 -0
- package/dist/esm/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpSessionResolver.js +509 -0
- package/dist/esm/router/cloudflare/d1/identity/d1IdentityRecords.js +51 -0
- package/dist/esm/router/cloudflare/d1/identity/d1IdentityService.js +135 -0
- package/dist/esm/router/cloudflare/d1/near/d1NearPublicKeyStore.js +62 -0
- package/dist/esm/router/cloudflare/d1/oidc/d1OidcBoundary.js +272 -0
- package/dist/esm/router/cloudflare/d1/oidc/d1OidcVerificationService.js +132 -0
- package/dist/esm/router/cloudflare/d1/passkeyCustody/d1PasskeyCustodyEnvelopeStore.js +628 -0
- package/dist/esm/router/cloudflare/d1/passkeyCustody/d1PasskeyCustodyRouteService.js +871 -0
- package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletCustodyCommitStore.js +823 -0
- package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpAttemptStore.js +38 -0
- package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpRecords.js +304 -0
- package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpService.js +793 -0
- package/dist/esm/router/cloudflare/d1/registration/d1EvmFamilyEcdsaRegistrationBranch.js +120 -0
- package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyRecordStore.js +317 -0
- package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyRecords.js +2084 -0
- package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyStore.js +309 -0
- package/dist/esm/router/cloudflare/d1/registration/d1RegistrationIntentService.js +120 -0
- package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationCommitStore.js +263 -0
- package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationService.js +3887 -0
- package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationSetup.js +182 -0
- package/dist/esm/router/cloudflare/d1/registration/walletRegistrationEstablishedSessionIssuer.js +399 -0
- package/dist/esm/router/cloudflare/d1/registration/walletRegistrationSessionCommitReceipt.js +486 -0
- package/dist/esm/router/cloudflare/d1/signingAdmission/d1RouterAbNormalSigningAdmissionStore.js +146 -0
- package/dist/esm/router/cloudflare/d1/signingLanes/d1EcdsaLanePrivateBindingResolver.js +10 -0
- package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneAggregateRevocationApplicationService.js +22 -0
- package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneEffectJournalStore.js +167 -0
- package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneEnrollmentGateway.js +38 -0
- package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneLifecycleApplicationService.js +20 -0
- package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneLifecycleStore.js +1459 -0
- package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneLockStore.js +114 -0
- package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneProtocolCommitter.js +16 -0
- package/dist/esm/router/cloudflare/d1/signingLanes/d1LaneRecords.js +170 -0
- package/dist/esm/router/cloudflare/d1/signingLanes/index.js +10 -0
- package/dist/esm/router/cloudflare/d1/versionedJson/d1VersionedJsonRecordStore.js +412 -0
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletAddSignerService.js +1396 -0
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthMethodBoundary.js +285 -0
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthMethodService.js +2018 -0
- package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorityStore.js +792 -0
- package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnAuthService.js +635 -0
- package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnRecords.js +538 -0
- package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnStore.js +264 -0
- package/dist/esm/router/cloudflare/durableObjects/thresholdStore.js +514 -0
- package/dist/esm/router/cloudflare/durableObjects/versionedJsonRecordStore.js +192 -0
- package/dist/esm/router/cloudflare/runtime/cloudflare.types.js +0 -0
- package/dist/esm/router/cloudflare/runtime/cloudflareSignerWasm.js +8 -0
- package/dist/esm/router/cloudflare/runtime/createCloudflareRouter.js +19 -0
- package/dist/esm/router/cloudflare/runtime/createSelfHostedCloudflareSigningWorker.js +94 -0
- package/dist/esm/router/cloudflare/runtime/ed25519SessionAdapter.js +106 -0
- package/dist/esm/router/cloudflare/runtime/environment.js +25 -0
- package/dist/esm/router/cloudflare/runtime/routerAbPrewarm.js +34 -0
- package/dist/esm/router/cloudflare/runtime/routerAbServiceBindings.js +33 -0
- package/dist/esm/router/cloudflare/runtime/sessionAdapterRuntime.js +104 -0
- package/dist/esm/router/cloudflare/runtime/staticWalletConsoleBinding.js +168 -0
- package/dist/esm/router/cloudflare/runtime/tenantRootCreationGrant.js +147 -0
- package/dist/esm/router/cloudflare/runtime/walletConsoleOps.js +143 -0
- package/dist/esm/router/cloudflare/runtime/walletConsoleOpsClient.js +227 -0
- package/dist/esm/router/cloudflare/runtime/walletConsoleTenantRootLineage.js +30 -0
- package/dist/esm/router/cloudflare/runtime/walletControlOps.js +107 -0
- package/dist/esm/router/cloudflare/runtime/walletGateway.js +149 -0
- package/dist/esm/router/cloudflare/runtime/walletRuntimeOps.js +322 -0
- package/dist/esm/router/cloudflare/runtime/walletRuntimeOpsHandler.js +48 -0
- package/dist/esm/router/cloudflare/signingLanes/cloudflareLaneCurveExecution.js +597 -0
- package/dist/esm/router/cloudflare/signingLanes/cloudflareLaneProtocolCommitter.js +272 -0
- package/dist/esm/router/cloudflare/signingLanes/cloudflareOrdinaryInactiveSignerMaterialReservation.js +477 -0
- package/dist/esm/router/cloudflare/signingLanes/index.js +4 -0
- package/dist/esm/router/cloudflare/signingLanes/linkedDeviceEd25519CeremonyBinding.js +32 -0
- package/dist/esm/router/cloudflare-adaptor.js +45 -0
- package/dist/esm/router/cloudflare.js +42794 -0
- package/dist/esm/router/domains/ecdsa/routerAbEcdsaStrictRegistration.js +738 -0
- package/dist/esm/router/domains/ecdsa/thresholdEcdsaRequestValidation.js +134 -0
- package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.js +368 -0
- package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitionedStateStore.js +624 -0
- package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitioning.js +143 -0
- package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPersistence.js +270 -0
- package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRunner.js +31 -0
- package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRuntime.js +162 -0
- package/dist/esm/router/domains/ed25519Yao/export/routerAbEd25519YaoExport.js +1366 -0
- package/dist/esm/router/domains/ed25519Yao/export/routerAbEd25519YaoExportRequestScopedCloudflare.js +465 -0
- package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecovery.js +1609 -0
- package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryRequestScopedCloudflare.js +540 -0
- package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryWalletSessionAuthorization.js +394 -0
- package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoHttpRegistrationBackend.js +572 -0
- package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistration.js +555 -0
- package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationExecutionRecord.js +268 -0
- package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationIntentAuthorization.js +329 -0
- package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationRequestScopedCloudflare.js +423 -0
- package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.js +432 -0
- package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationTwoPhaseRunner.js +58 -0
- package/dist/esm/router/domains/ed25519Yao/routerAbEd25519YaoGatewayEnvelope.js +0 -0
- package/dist/esm/router/domains/ed25519Yao/session/routerAbEd25519YaoWalletSession.js +0 -0
- package/dist/esm/router/domains/ed25519Yao/session/thresholdEd25519RequestValidation.js +275 -0
- package/dist/esm/router/domains/emailOtp/emailOtpExportPolicy.js +70 -0
- package/dist/esm/router/domains/emailOtp/emailOtpRequestValidation.js +34 -0
- package/dist/esm/router/domains/emailOtp/emailOtpRouteHandlers.js +218 -0
- package/dist/esm/router/domains/emailOtp/emailOtpSessionRouteHelpers.js +210 -0
- package/dist/esm/router/domains/passkeyCustody/envelopeRevocationAdmission.js +26 -0
- package/dist/esm/router/domains/passkeyCustody/passkeyCustodyEnvelopeRetrieval.js +107 -0
- package/dist/esm/router/domains/passkeyCustody/passkeyCustodyEnvelopeRetrievalRoute.js +45 -0
- package/dist/esm/router/domains/passkeyCustody/registrationCustodyOutcome.js +47 -0
- package/dist/esm/router/domains/passkeyCustody/verifiedCustodyFactor.js +46 -0
- package/dist/esm/router/domains/passkeyCustody/walletCustodyRegistrationAdmission.js +32 -0
- package/dist/esm/router/domains/passkeyCustody/walletCustodyRegistrationCommit.js +170 -0
- package/dist/esm/router/domains/passkeyCustody/walletRecoveryAttempt.js +64 -0
- package/dist/esm/router/domains/passkeyCustody/walletRecoveryFinalization.js +652 -0
- package/dist/esm/router/domains/passkeyCustody/walletRecoveryKeyManifest.js +396 -0
- package/dist/esm/router/domains/passkeyCustody/walletRecoveryRotation.js +87 -0
- package/dist/esm/router/domains/signingOperations/ed25519AuthorizedOperationReceipt.js +89 -0
- package/dist/esm/router/domains/signingOperations/routerAbNormalSigningAdmissionCore.js +106 -0
- package/dist/esm/router/domains/signingOperations/routerAbPrivateSigningWorker.js +2669 -0
- package/dist/esm/router/domains/signingOperations/walletExecutionAdmission.js +228 -0
- package/dist/esm/router/domains/syncAccount/syncAccountRequestValidation.js +78 -0
- package/dist/esm/router/domains/tenantRoot/tenantRootCustodyLineage.js +0 -0
- package/dist/esm/router/domains/tenantRoot/tenantRootEcdsaWalletSessionComposition.js +55 -0
- package/dist/esm/router/domains/tenantRoot/tenantRootEd25519WalletSessionComposition.js +56 -0
- package/dist/esm/router/domains/tenantRoot/tenantRootIdentityResolution.js +111 -0
- package/dist/esm/router/domains/walletRegistration/walletRegistrationInputs.js +0 -0
- package/dist/esm/router/domains/walletRegistration/walletRegistrationRoutes.js +2199 -0
- package/dist/esm/router/domains/walletRegistration/walletRegistrationSetupPayload.js +155 -0
- package/dist/esm/router/domains/walletUnlock/walletUnlockRequestedCapabilitiesValidation.js +84 -0
- package/dist/esm/router/domains/walletUnlock/walletUnlockRouteHandlers.js +1142 -0
- package/dist/esm/router/express-adaptor.js +84 -0
- package/dist/esm/router/express.js +26616 -0
- package/dist/esm/router/framework/apiCredentialPorts.js +11 -0
- package/dist/esm/router/framework/applyRouteMetering.js +26 -0
- package/dist/esm/router/framework/authServicePort.js +30 -0
- package/dist/esm/router/framework/enforceRoutePolicy.js +92 -0
- package/dist/esm/router/framework/http.js +87 -0
- package/dist/esm/router/framework/logger.js +7 -0
- package/dist/esm/router/framework/modules.js +34 -0
- package/dist/esm/router/framework/ror/index.js +5 -0
- package/dist/esm/router/framework/ror/normalize.js +57 -0
- package/dist/esm/router/framework/ror/options.js +33 -0
- package/dist/esm/router/framework/ror/provider.js +33 -0
- package/dist/esm/router/framework/ror/staticProvider.js +24 -0
- package/dist/esm/router/framework/routeAuthPolicy.js +16 -0
- package/dist/esm/router/framework/routeDefinitions.js +446 -0
- package/dist/esm/router/framework/routeExecutionContext.js +24 -0
- package/dist/esm/router/framework/routeExtensions.js +50 -0
- package/dist/esm/router/framework/routeMeteringPolicy.js +0 -0
- package/dist/esm/router/framework/routeRequestValidation.js +32 -0
- package/dist/esm/router/framework/routeResponses.js +33 -0
- package/dist/esm/router/framework/routerApi.js +42 -0
- package/dist/esm/router/framework/routerApiRouteSurface.js +54 -0
- package/dist/esm/router/framework/routerApiWebhooks.js +60 -0
- package/dist/esm/router/framework/runtimeSnapshotConsumer.js +145 -0
- package/dist/esm/router/framework/versionedJsonRecordStore.js +0 -0
- package/dist/esm/router/ror-adaptor.js +5 -0
- package/dist/esm/router/ror.js +178 -0
- package/dist/esm/router/transport/fetch/createFetchRouter.js +309 -0
- package/dist/esm/router/transport/fetch/fetchRouter.types.js +0 -0
- package/dist/esm/router/transport/fetch/routes/auth.js +219 -0
- package/dist/esm/router/transport/fetch/routes/deviceLinking.js +1196 -0
- package/dist/esm/router/transport/fetch/routes/deviceLinkingOwnerAuthorization.js +264 -0
- package/dist/esm/router/transport/fetch/routes/deviceManagement.js +289 -0
- package/dist/esm/router/transport/fetch/routes/health.js +42 -0
- package/dist/esm/router/transport/fetch/routes/nearPublicKeys.js +39 -0
- package/dist/esm/router/transport/fetch/routes/normalSigningRouterProxy.js +118 -0
- package/dist/esm/router/transport/fetch/routes/passkeyCustody.js +1618 -0
- package/dist/esm/router/transport/fetch/routes/sessions.js +1033 -0
- package/dist/esm/router/transport/fetch/routes/syncAccount.js +187 -0
- package/dist/esm/router/transport/fetch/routes/syncAccountBootstrap.js +214 -0
- package/dist/esm/router/transport/fetch/routes/thresholdEcdsa.js +1729 -0
- package/dist/esm/router/transport/fetch/routes/thresholdEd25519.js +1321 -0
- package/dist/esm/router/transport/fetch/routes/walletExecutionLanePreflight.js +228 -0
- package/dist/esm/router/transport/fetch/routes/walletRegistration.js +73 -0
- package/dist/esm/router/transport/fetch/routes/webauthnAuthenticators.js +43 -0
- package/dist/esm/router/transport/fetch/routes/wellKnown.js +48 -0
- package/dist/esm/shared-ts/src/authorization/capabilityKinds.js +224 -0
- package/dist/esm/shared-ts/src/authorization/delegatedAuthority.js +134 -0
- package/dist/esm/shared-ts/src/authorization/index.js +6 -0
- package/dist/esm/shared-ts/src/authorization/operationFingerprint.js +58 -0
- package/dist/esm/shared-ts/src/authorization/walletAuthority.js +802 -0
- package/dist/esm/shared-ts/src/authorization/walletCustodyOperation.js +18 -0
- package/dist/esm/shared-ts/src/authorization/walletSessionIssuance.js +5 -0
- package/dist/esm/shared-ts/src/device-linking/committedSignerPackages.js +332 -0
- package/dist/esm/shared-ts/src/device-linking/contracts.js +8 -0
- package/dist/esm/shared-ts/src/device-linking/delegatedActivationPlan.js +132 -0
- package/dist/esm/shared-ts/src/device-linking/digests.js +273 -0
- package/dist/esm/shared-ts/src/device-linking/ed25519ExportRoot.js +158 -0
- package/dist/esm/shared-ts/src/device-linking/index.js +9 -0
- package/dist/esm/shared-ts/src/device-linking/parsers.js +1412 -0
- package/dist/esm/shared-ts/src/device-linking/requestProof.js +114 -0
- package/dist/esm/shared-ts/src/device-linking/sourceContribution.js +563 -0
- package/dist/esm/shared-ts/src/device-linking/walletSessionCredentialDelivery.js +207 -0
- package/dist/esm/shared-ts/src/near/actions.js +75 -0
- package/dist/esm/shared-ts/src/passkey-custody/ceremonyCommitPayload.js +69 -0
- package/dist/esm/shared-ts/src/passkey-custody/credentialActivity.js +81 -0
- package/dist/esm/shared-ts/src/passkey-custody/custodyEnvelope.js +272 -0
- package/dist/esm/shared-ts/src/passkey-custody/custodySecretBinding.js +175 -0
- package/dist/esm/shared-ts/src/passkey-custody/index.js +5 -0
- package/dist/esm/shared-ts/src/passkey-custody/primitives.js +92 -0
- package/dist/esm/shared-ts/src/signing-lanes/evmFamilySigningKeySlotId.js +53 -0
- package/dist/esm/shared-ts/src/signing-lanes/execution.js +14 -0
- package/dist/esm/shared-ts/src/signing-lanes/index.js +11 -0
- package/dist/esm/shared-ts/src/signing-lanes/linkedEcdsaScope.js +1 -0
- package/dist/esm/shared-ts/src/signing-lanes/ownerContinuity.js +91 -0
- package/dist/esm/shared-ts/src/signing-lanes/participantDigest.js +124 -0
- package/dist/esm/shared-ts/src/signing-lanes/participants.js +262 -0
- package/dist/esm/shared-ts/src/signing-lanes/recordParsers.js +143 -0
- package/dist/esm/shared-ts/src/signing-lanes/rotation.js +8 -0
- package/dist/esm/shared-ts/src/signing-lanes/rotationDigests.js +397 -0
- package/dist/esm/shared-ts/src/signing-lanes/rotationLifecycle.js +313 -0
- package/dist/esm/shared-ts/src/signing-lanes/rotationParsers.js +1620 -0
- package/dist/esm/shared-ts/src/tenant-root/index.js +2 -0
- package/dist/esm/shared-ts/src/tenant-root/tenantRootIdentity.js +198 -0
- package/dist/esm/shared-ts/src/tenant-root/tenantRootOperationRecord.js +440 -0
- package/dist/esm/shared-ts/src/threshold/ecdsaDerivationRoleLocalBootstrap.js +85 -0
- package/dist/esm/shared-ts/src/threshold/participants.js +26 -0
- package/dist/esm/shared-ts/src/threshold/sessionPolicy.js +9 -0
- package/dist/esm/shared-ts/src/threshold/signingRootScope.js +40 -0
- package/dist/esm/shared-ts/src/utils/addAuthMethodRegistration.js +104 -0
- package/dist/esm/shared-ts/src/utils/addWalletAuthMethod.js +36 -0
- package/dist/esm/shared-ts/src/utils/base58.js +28 -0
- package/dist/esm/shared-ts/src/utils/base64.js +70 -0
- package/dist/esm/shared-ts/src/utils/canonicalPrimitives.js +27 -0
- package/dist/esm/shared-ts/src/utils/digests.js +33 -0
- package/dist/esm/shared-ts/src/utils/domainIds.js +309 -0
- package/dist/esm/shared-ts/src/utils/ecdsaCapabilityActivation.js +34 -0
- package/dist/esm/shared-ts/src/utils/ecdsaKeyFactsInventory.js +46 -0
- package/dist/esm/shared-ts/src/utils/emailOtpDomain.js +38 -0
- package/dist/esm/shared-ts/src/utils/emailOtpRecoveryKey.js +10 -0
- package/dist/esm/shared-ts/src/utils/encoders.js +2 -0
- package/dist/esm/shared-ts/src/utils/errors.js +88 -0
- package/dist/esm/shared-ts/src/utils/evmRpcResults.js +97 -0
- package/dist/esm/shared-ts/src/utils/jsonRpc.js +64 -0
- package/dist/esm/shared-ts/src/utils/keccak.js +150 -0
- package/dist/esm/shared-ts/src/utils/near.js +99 -0
- package/dist/esm/shared-ts/src/utils/nearRpcResults.js +205 -0
- package/dist/esm/shared-ts/src/utils/normalize.js +87 -0
- package/dist/esm/shared-ts/src/utils/registrationEstablishedSession.js +201 -0
- package/dist/esm/shared-ts/src/utils/registrationIntent.js +1268 -0
- package/dist/esm/shared-ts/src/utils/routerAbEcdsaDerivation.js +1655 -0
- package/dist/esm/shared-ts/src/utils/routerAbEd25519Yao.js +984 -0
- package/dist/esm/shared-ts/src/utils/routerAbNormalSigningIdentity.js +118 -0
- package/dist/esm/shared-ts/src/utils/routerAbPublicKeyset.js +138 -0
- package/dist/esm/shared-ts/src/utils/routerAbTraceContext.js +36 -0
- package/dist/esm/shared-ts/src/utils/secureRandomId.js +35 -0
- package/dist/esm/shared-ts/src/utils/signingSessionSeal.js +118 -0
- package/dist/esm/shared-ts/src/utils/thresholdEcdsaKeyHandle.js +28 -0
- package/dist/esm/shared-ts/src/utils/validation.js +23 -0
- package/dist/esm/shared-ts/src/utils/walletAddSignerActivation.js +32 -0
- package/dist/esm/shared-ts/src/utils/walletAuthAuthority.js +207 -0
- package/dist/esm/shared-ts/src/utils/walletSessionFailure.js +15 -0
- package/dist/esm/shared-ts/src/utils/webauthnDeviceInfo.js +207 -0
- package/dist/esm/shared-ts/src/wallet-recovery/backupAcknowledgement.js +66 -0
- package/dist/esm/shared-ts/src/wallet-recovery/index.js +10 -0
- package/dist/esm/shared-ts/src/wallet-recovery/recoveryCodeIssuance.js +1 -0
- package/dist/esm/shared-ts/src/wallet-recovery/recoveryCodeLocator.js +34 -0
- package/dist/esm/shared-ts/src/wallet-recovery/recoveryCodeReservation.js +80 -0
- package/dist/esm/shared-ts/src/wallet-recovery/recoveryCodes.js +4 -0
- package/dist/esm/shared-ts/src/wallet-recovery/recoveryKeyId.js +53 -0
- package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryCommittedProjection.js +108 -0
- package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryEcdsaPossession.js +157 -0
- package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryEnvelopeSet.js +233 -0
- package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryRotation.js +3 -0
- package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryTarget.js +29 -0
- package/dist/esm/storage/d1Sql.js +85 -0
- package/dist/esm/storage/tenantRoute.js +89 -0
- package/dist/esm/tenant-root.js +5 -0
- package/dist/esm/threshold/session/signingSessionSeal/crypto/cipher.js +204 -0
- package/dist/esm/threshold/session/signingSessionSeal/crypto/shamir3PassWasm.js +87 -0
- package/dist/esm/threshold/session/signingSessionSeal/guards/backends.js +192 -0
- package/dist/esm/threshold/session/signingSessionSeal/guards/index.js +121 -0
- package/dist/esm/threshold/session/signingSessionSeal/idempotency.js +38 -0
- package/dist/esm/threshold/session/signingSessionSeal/idempotencyBackends.js +131 -0
- package/dist/esm/threshold/session/signingSessionSeal/idempotencyRecords.js +55 -0
- package/dist/esm/threshold/session/signingSessionSeal/index.js +13 -0
- package/dist/esm/threshold/session/signingSessionSeal/observability/audit.js +38 -0
- package/dist/esm/threshold/session/signingSessionSeal/options.js +54 -0
- package/dist/esm/threshold/session/signingSessionSeal/routesOptions.js +45 -0
- package/dist/esm/threshold/session/signingSessionSeal/service.js +316 -0
- package/dist/esm/threshold/session/signingSessionSeal/signingSessionSeal.types.js +0 -0
- package/dist/esm/threshold/session/signingSessionSeal/transport/express.js +151 -0
- package/dist/esm/threshold/session/signingSessionSeal/transport/fetch.js +106 -0
- package/dist/esm/threshold/session/signingSessionSeal/transport/shared.js +159 -0
- package/dist/esm/threshold/statusCodes.js +39 -0
- package/dist/esm/wasm/evm_crypto/pkg/evm_crypto.js +601 -0
- package/dist/esm/wasm/evm_crypto/pkg/evm_crypto_bg.wasm +0 -0
- package/dist/esm/wasm/near_signer/pkg/wasm_signer_worker.js +1078 -0
- package/dist/esm/wasm/near_signer/pkg/wasm_signer_worker_bg.wasm +0 -0
- package/dist/esm/wasm/router_ab_ecdsa_signing_worker/pkg/router_ab_ecdsa_signing_worker.js +503 -0
- package/dist/esm/wasm/router_ab_ecdsa_signing_worker/pkg/router_ab_ecdsa_signing_worker_bg.wasm +0 -0
- package/dist/esm/wasm/shamir3pass_runtime/pkg/shamir3pass_runtime.js +393 -0
- package/dist/esm/wasm/shamir3pass_runtime/pkg/shamir3pass_runtime_bg.wasm +0 -0
- package/dist/esm/wasm/signer.js +2 -0
- package/dist/types/shared-ts/src/authorization/capabilityKinds.d.ts +147 -0
- package/dist/types/shared-ts/src/authorization/capabilityKinds.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/authorization/delegatedAuthority.d.ts +44 -0
- package/dist/types/shared-ts/src/authorization/index.d.ts +7 -0
- package/dist/types/shared-ts/src/authorization/operationFingerprint.d.ts +39 -0
- package/dist/types/shared-ts/src/authorization/operationFingerprint.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/authorization/walletAuthority.d.ts +168 -0
- package/dist/types/shared-ts/src/authorization/walletAuthority.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/authorization/walletCustodyOperation.d.ts +10 -0
- package/dist/types/shared-ts/src/authorization/walletSessionIssuance.d.ts +28 -0
- package/dist/types/shared-ts/src/device-linking/activeWalletSession.d.ts +3 -0
- package/dist/types/shared-ts/src/device-linking/activeWalletSession.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/device-linking/committedSignerPackages.d.ts +71 -0
- package/dist/types/shared-ts/src/device-linking/contracts.d.ts +843 -0
- package/dist/types/shared-ts/src/device-linking/contracts.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/device-linking/delegatedActivationPlan.d.ts +37 -0
- package/dist/types/shared-ts/src/device-linking/digests.d.ts +23 -0
- package/dist/types/shared-ts/src/device-linking/ed25519ExportRoot.d.ts +93 -0
- package/dist/types/shared-ts/src/device-linking/index.d.ts +11 -0
- package/dist/types/shared-ts/src/device-linking/parsers.d.ts +124 -0
- package/dist/types/shared-ts/src/device-linking/requestProof.d.ts +26 -0
- package/dist/types/shared-ts/src/device-linking/sourceContribution.d.ts +182 -0
- package/dist/types/shared-ts/src/device-linking/walletSessionCredentialDelivery.d.ts +84 -0
- package/dist/types/shared-ts/src/index.d.ts +10 -0
- package/dist/types/shared-ts/src/near/actions.d.ts +141 -0
- package/dist/types/shared-ts/src/near/delegate.d.ts +55 -0
- package/dist/types/shared-ts/src/near/index.d.ts +3 -0
- package/dist/types/shared-ts/src/passkey-custody/ceremonyCommitPayload.d.ts +211 -0
- package/dist/types/shared-ts/src/passkey-custody/credentialActivity.d.ts +49 -0
- package/dist/types/shared-ts/src/passkey-custody/credentialObservations.d.ts +74 -0
- package/dist/types/shared-ts/src/passkey-custody/custodyEnvelope.d.ts +191 -0
- package/dist/types/shared-ts/src/passkey-custody/custodySecretBinding.d.ts +140 -0
- package/dist/types/shared-ts/src/passkey-custody/envelopeIndex.d.ts +29 -0
- package/dist/types/shared-ts/src/passkey-custody/index.d.ts +9 -0
- package/dist/types/shared-ts/src/passkey-custody/kekContext.d.ts +34 -0
- package/dist/types/shared-ts/src/passkey-custody/passkeyCustody.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/passkey-custody/primitives.d.ts +34 -0
- package/dist/types/shared-ts/src/signing-lanes/evmFamilySigningKeySlotId.d.ts +27 -0
- package/dist/types/shared-ts/src/signing-lanes/execution.d.ts +91 -0
- package/dist/types/shared-ts/src/signing-lanes/execution.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/signing-lanes/ids.d.ts +18 -0
- package/dist/types/shared-ts/src/signing-lanes/index.d.ts +14 -0
- package/dist/types/shared-ts/src/signing-lanes/linkedEcdsaScope.d.ts +62 -0
- package/dist/types/shared-ts/src/signing-lanes/linkedEcdsaScope.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/signing-lanes/ownerContinuity.d.ts +30 -0
- package/dist/types/shared-ts/src/signing-lanes/ownerContinuity.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/signing-lanes/participantDigest.d.ts +48 -0
- package/dist/types/shared-ts/src/signing-lanes/participantDigest.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/signing-lanes/participants.d.ts +89 -0
- package/dist/types/shared-ts/src/signing-lanes/recordParsers.d.ts +128 -0
- package/dist/types/shared-ts/src/signing-lanes/records.d.ts +160 -0
- package/dist/types/shared-ts/src/signing-lanes/records.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/signing-lanes/rotation.d.ts +894 -0
- package/dist/types/shared-ts/src/signing-lanes/rotation.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/signing-lanes/rotationDigests.d.ts +32 -0
- package/dist/types/shared-ts/src/signing-lanes/rotationLifecycle.d.ts +99 -0
- package/dist/types/shared-ts/src/signing-lanes/rotationParsers.d.ts +67 -0
- package/dist/types/shared-ts/src/signing-lanes/validation.d.ts +11 -0
- package/dist/types/shared-ts/src/tenant-root/index.d.ts +3 -0
- package/dist/types/shared-ts/src/tenant-root/tenantRootIdentity.d.ts +72 -0
- package/dist/types/shared-ts/src/tenant-root/tenantRootOperationRecord.d.ts +192 -0
- package/dist/types/shared-ts/src/threshold/ecdsaDerivationRoleLocalBootstrap.d.ts +77 -0
- package/dist/types/shared-ts/src/threshold/ed25519OperationFingerprint.d.ts +130 -0
- package/dist/types/shared-ts/src/threshold/index.d.ts +7 -0
- package/dist/types/shared-ts/src/threshold/participants.d.ts +38 -0
- package/dist/types/shared-ts/src/threshold/secp256k1.d.ts +39 -0
- package/dist/types/shared-ts/src/threshold/sessionPolicy.d.ts +5 -0
- package/dist/types/shared-ts/src/threshold/signingRootScope.d.ts +24 -0
- package/dist/types/shared-ts/src/utils/addAuthMethodRegistration.d.ts +63 -0
- package/dist/types/shared-ts/src/utils/addWalletAuthMethod.d.ts +295 -0
- package/dist/types/shared-ts/src/utils/addWalletAuthMethod.typecheck.d.ts +11 -0
- package/dist/types/shared-ts/src/utils/authenticatorOptions.d.ts +25 -0
- package/dist/types/shared-ts/src/utils/base58.d.ts +17 -0
- package/dist/types/shared-ts/src/utils/base64.d.ts +53 -0
- package/dist/types/shared-ts/src/utils/bigint.d.ts +3 -0
- package/dist/types/shared-ts/src/utils/canonicalPrimitives.d.ts +12 -0
- package/dist/types/shared-ts/src/utils/digests.d.ts +6 -0
- package/dist/types/shared-ts/src/utils/domainIds.d.ts +140 -0
- package/dist/types/shared-ts/src/utils/domainIds.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/utils/ecdsaCapabilityActivation.d.ts +29 -0
- package/dist/types/shared-ts/src/utils/ecdsaKeyFactsInventory.d.ts +24 -0
- package/dist/types/shared-ts/src/utils/emailOtpDomain.d.ts +30 -0
- package/dist/types/shared-ts/src/utils/emailOtpRecoveryKey.d.ts +31 -0
- package/dist/types/shared-ts/src/utils/encoders.d.ts +3 -0
- package/dist/types/shared-ts/src/utils/errors.d.ts +44 -0
- package/dist/types/shared-ts/src/utils/evmRpcResults.d.ts +31 -0
- package/dist/types/shared-ts/src/utils/generated/routerAbEd25519YaoCore.d.ts +128 -0
- package/dist/types/shared-ts/src/utils/index.d.ts +34 -0
- package/dist/types/shared-ts/src/utils/jsonRpc.d.ts +30 -0
- package/dist/types/shared-ts/src/utils/keccak.d.ts +2 -0
- package/dist/types/shared-ts/src/utils/near.d.ts +81 -0
- package/dist/types/shared-ts/src/utils/nearRpcResults.d.ts +101 -0
- package/dist/types/shared-ts/src/utils/normalize.d.ts +57 -0
- package/dist/types/shared-ts/src/utils/paillier.d.ts +37 -0
- package/dist/types/shared-ts/src/utils/recoveryDomain.d.ts +12 -0
- package/dist/types/shared-ts/src/utils/registrationEstablishedSession.d.ts +85 -0
- package/dist/types/shared-ts/src/utils/registrationIntent.d.ts +621 -0
- package/dist/types/shared-ts/src/utils/registrationIntent.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/utils/routerAbEcdsaDerivation.d.ts +715 -0
- package/dist/types/shared-ts/src/utils/routerAbEcdsaDerivation.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/utils/routerAbEcdsaDerivationRefresh.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/utils/routerAbEd25519Yao.d.ts +339 -0
- package/dist/types/shared-ts/src/utils/routerAbEd25519Yao.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/utils/routerAbNormalSigningIdentity.d.ts +71 -0
- package/dist/types/shared-ts/src/utils/routerAbPublicKeyset.d.ts +51 -0
- package/dist/types/shared-ts/src/utils/routerAbTraceContext.d.ts +16 -0
- package/dist/types/shared-ts/src/utils/secureRandomId.d.ts +6 -0
- package/dist/types/shared-ts/src/utils/signerDomain.d.ts +75 -0
- package/dist/types/shared-ts/src/utils/signerDomain.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/utils/signerSlot.d.ts +11 -0
- package/dist/types/shared-ts/src/utils/signingSessionSeal.d.ts +153 -0
- package/dist/types/shared-ts/src/utils/signingSessionSeal.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/utils/theme.d.ts +2 -0
- package/dist/types/shared-ts/src/utils/thresholdEcdsaKeyHandle.d.ts +11 -0
- package/dist/types/shared-ts/src/utils/validation.d.ts +35 -0
- package/dist/types/shared-ts/src/utils/walletAddSignerActivation.d.ts +23 -0
- package/dist/types/shared-ts/src/utils/walletAuthAuthority.d.ts +150 -0
- package/dist/types/shared-ts/src/utils/walletAuthAuthority.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/utils/walletCapabilityBindings.d.ts +106 -0
- package/dist/types/shared-ts/src/utils/walletCapabilityBindings.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/utils/walletSessionFailure.d.ts +13 -0
- package/dist/types/shared-ts/src/utils/webauthnDeviceInfo.d.ts +48 -0
- package/dist/types/shared-ts/src/wallet-recovery/backupAcknowledgement.d.ts +56 -0
- package/dist/types/shared-ts/src/wallet-recovery/index.d.ts +10 -0
- package/dist/types/shared-ts/src/wallet-recovery/recoveryCodeAttempt.d.ts +59 -0
- package/dist/types/shared-ts/src/wallet-recovery/recoveryCodeIssuance.d.ts +37 -0
- package/dist/types/shared-ts/src/wallet-recovery/recoveryCodeLocator.d.ts +22 -0
- package/dist/types/shared-ts/src/wallet-recovery/recoveryCodeReservation.d.ts +79 -0
- package/dist/types/shared-ts/src/wallet-recovery/recoveryCodes.d.ts +11 -0
- package/dist/types/shared-ts/src/wallet-recovery/recoveryEnvelopes.d.ts +42 -0
- package/dist/types/shared-ts/src/wallet-recovery/recoveryKekContext.d.ts +37 -0
- package/dist/types/shared-ts/src/wallet-recovery/recoveryKeyId.d.ts +58 -0
- package/dist/types/shared-ts/src/wallet-recovery/walletRecovery.typecheck.d.ts +2 -0
- package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryCommittedProjection.d.ts +110 -0
- package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryEcdsaPossession.d.ts +29 -0
- package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryEnvelopeSet.d.ts +115 -0
- package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryRotation.d.ts +18 -0
- package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryTarget.d.ts +12 -0
- package/dist/types/shared-ts/src/wallet-recovery/walletRecoveryTarget.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/authorization/capabilityPolicy.d.ts +45 -0
- package/dist/types/wallet-server/src/authorization/capabilityPolicy.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/authorization/domain.d.ts +454 -0
- package/dist/types/wallet-server/src/authorization/domain.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/authorization/factorEvidence.d.ts +165 -0
- package/dist/types/wallet-server/src/authorization/factorEvidence.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/authorization/service.d.ts +227 -0
- package/dist/types/wallet-server/src/authorization/vaultProxyUse.d.ts +75 -0
- package/dist/types/wallet-server/src/cloud-host.d.ts +94 -0
- package/dist/types/wallet-server/src/core/AuthService.d.ts +3 -0
- package/dist/types/wallet-server/src/core/EmailOtpRecords.d.ts +33 -0
- package/dist/types/wallet-server/src/core/EmailOtpStores.d.ts +336 -0
- package/dist/types/wallet-server/src/core/IdentityStore.d.ts +57 -0
- package/dist/types/wallet-server/src/core/NearPublicKeyStore.d.ts +58 -0
- package/dist/types/wallet-server/src/core/RegistrationCeremonyStore.d.ts +551 -0
- package/dist/types/wallet-server/src/core/SessionService.d.ts +70 -0
- package/dist/types/wallet-server/src/core/ThresholdService/config.d.ts +23 -0
- package/dist/types/wallet-server/src/core/ThresholdService/ecdsaClientRootProof.d.ts +12 -0
- package/dist/types/wallet-server/src/core/ThresholdService/evmCryptoWasm.d.ts +32 -0
- package/dist/types/wallet-server/src/core/ThresholdService/index.d.ts +4 -0
- package/dist/types/wallet-server/src/core/ThresholdService/kv.d.ts +52 -0
- package/dist/types/wallet-server/src/core/ThresholdService/routerAb/ecdsaDerivationPoolFillHandlers.d.ts +45 -0
- package/dist/types/wallet-server/src/core/ThresholdService/routerAb/ecdsaDerivationPoolFillLiveSession.d.ts +93 -0
- package/dist/types/wallet-server/src/core/ThresholdService/routerAb/ecdsaDerivationPresignBridge.d.ts +138 -0
- package/dist/types/wallet-server/src/core/ThresholdService/routerAb/internalServiceHttp.d.ts +30 -0
- package/dist/types/wallet-server/src/core/ThresholdService/routerAbEcdsaSigningWorkerWasm.d.ts +17 -0
- package/dist/types/wallet-server/src/core/ThresholdService/routerAbNormalSigningPolicy.d.ts +21 -0
- package/dist/types/wallet-server/src/core/ThresholdService/secureRandomId.d.ts +2 -0
- package/dist/types/wallet-server/src/core/ThresholdService/stores/CloudflareDurableObjectStore.d.ts +128 -0
- package/dist/types/wallet-server/src/core/ThresholdService/stores/EcdsaSigningStore.d.ts +76 -0
- package/dist/types/wallet-server/src/core/ThresholdService/stores/KeyStore.d.ts +39 -0
- package/dist/types/wallet-server/src/core/ThresholdService/stores/SessionStore.d.ts +102 -0
- package/dist/types/wallet-server/src/core/ThresholdService/stores/StoreConfig.d.ts +3 -0
- package/dist/types/wallet-server/src/core/ThresholdService/stores/ThresholdStoreConfig.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/core/ThresholdService/stores/WalletSessionStore.d.ts +98 -0
- package/dist/types/wallet-server/src/core/ThresholdService/thresholdEd25519AuthorityScope.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/core/ThresholdService/validation.d.ts +193 -0
- package/dist/types/wallet-server/src/core/WalletAuthMethodStore.d.ts +12 -0
- package/dist/types/wallet-server/src/core/WalletStore.d.ts +143 -0
- package/dist/types/wallet-server/src/core/WalletStore.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/core/WebAuthnAuthenticatorStore.d.ts +62 -0
- package/dist/types/wallet-server/src/core/WebAuthnCredentialBindingStore.d.ts +116 -0
- package/dist/types/wallet-server/src/core/WebAuthnCredentialBindingStore.typecheck.d.ts +13 -0
- package/dist/types/wallet-server/src/core/WebAuthnLoginChallengeStore.d.ts +50 -0
- package/dist/types/wallet-server/src/core/WebAuthnSyncChallengeStore.d.ts +50 -0
- package/dist/types/wallet-server/src/core/authService/AuthService.d.ts +493 -0
- package/dist/types/wallet-server/src/core/authService/bytes.d.ts +4 -0
- package/dist/types/wallet-server/src/core/authService/configValues.d.ts +7 -0
- package/dist/types/wallet-server/src/core/authService/emailOtpChallengeOperations.d.ts +108 -0
- package/dist/types/wallet-server/src/core/authService/emailOtpChallengeProof.d.ts +177 -0
- package/dist/types/wallet-server/src/core/authService/emailOtpChallengeVerification.d.ts +46 -0
- package/dist/types/wallet-server/src/core/authService/emailOtpChallenges.d.ts +110 -0
- package/dist/types/wallet-server/src/core/authService/emailOtpConfig.d.ts +34 -0
- package/dist/types/wallet-server/src/core/authService/emailOtpDelivery.d.ts +65 -0
- package/dist/types/wallet-server/src/core/authService/emailOtpEnrollment.d.ts +79 -0
- package/dist/types/wallet-server/src/core/authService/emailOtpGrant.d.ts +42 -0
- package/dist/types/wallet-server/src/core/authService/emailOtpRegistrationEnrollment.d.ts +116 -0
- package/dist/types/wallet-server/src/core/authService/emailOtpSeal.d.ts +35 -0
- package/dist/types/wallet-server/src/core/authService/emailOtpUnlock.d.ts +70 -0
- package/dist/types/wallet-server/src/core/authService/githubOAuth.d.ts +35 -0
- package/dist/types/wallet-server/src/core/authService/googleEmailOtpErrors.d.ts +2 -0
- package/dist/types/wallet-server/src/core/authService/googleEmailOtpOperations.d.ts +126 -0
- package/dist/types/wallet-server/src/core/authService/googleEmailOtpRegistration.d.ts +172 -0
- package/dist/types/wallet-server/src/core/authService/identity.d.ts +25 -0
- package/dist/types/wallet-server/src/core/authService/identityOperations.d.ts +19 -0
- package/dist/types/wallet-server/src/core/authService/nearAccountOperations.d.ts +55 -0
- package/dist/types/wallet-server/src/core/authService/nearPrivateKeySigning.d.ts +16 -0
- package/dist/types/wallet-server/src/core/authService/nearPublicKeyMetadata.d.ts +43 -0
- package/dist/types/wallet-server/src/core/authService/nearTransactions.d.ts +49 -0
- package/dist/types/wallet-server/src/core/authService/oidcVerification.d.ts +65 -0
- package/dist/types/wallet-server/src/core/authService/portableCrypto.d.ts +3 -0
- package/dist/types/wallet-server/src/core/authService/rateLimits.d.ts +30 -0
- package/dist/types/wallet-server/src/core/authService/record.d.ts +2 -0
- package/dist/types/wallet-server/src/core/authService/registrationThresholdHelpers.d.ts +37 -0
- package/dist/types/wallet-server/src/core/authService/runtime.d.ts +20 -0
- package/dist/types/wallet-server/src/core/authService/signerWasmUrls.d.ts +3 -0
- package/dist/types/wallet-server/src/core/authService/storeRegistry.d.ts +58 -0
- package/dist/types/wallet-server/src/core/authService/thresholdEcdsaKeyInventory.d.ts +72 -0
- package/dist/types/wallet-server/src/core/authService/thresholdRuntimePolicy.d.ts +4 -0
- package/dist/types/wallet-server/src/core/authService/thresholdStoreSummary.d.ts +3 -0
- package/dist/types/wallet-server/src/core/authService/walletRegistrationPlanning.d.ts +19 -0
- package/dist/types/wallet-server/src/core/authService/wasm.d.ts +12 -0
- package/dist/types/wallet-server/src/core/authService/webauthn.d.ts +207 -0
- package/dist/types/wallet-server/src/core/authService/webauthnAuthority.d.ts +5 -0
- package/dist/types/wallet-server/src/core/authService/webauthnOidcHelpers.d.ts +52 -0
- package/dist/types/wallet-server/src/core/authService/webauthnWalletBinding.d.ts +48 -0
- package/dist/types/wallet-server/src/core/config.d.ts +13 -0
- package/dist/types/wallet-server/src/core/d1IdentityStore.d.ts +44 -0
- package/dist/types/wallet-server/src/core/d1WalletAuthMethodStore.d.ts +214 -0
- package/dist/types/wallet-server/src/core/d1WalletStore.d.ts +108 -0
- package/dist/types/wallet-server/src/core/defaultConfigsServer.d.ts +5 -0
- package/dist/types/wallet-server/src/core/deviceLinking/index.d.ts +5 -0
- package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceEd25519ExportRoot.d.ts +36 -0
- package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceEmailOtpGrant.d.ts +87 -0
- package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceManagement.d.ts +137 -0
- package/dist/types/wallet-server/src/core/deviceLinking/linkedDeviceSession.d.ts +462 -0
- package/dist/types/wallet-server/src/core/deviceLinking/requestProof.d.ts +55 -0
- package/dist/types/wallet-server/src/core/errors.d.ts +10 -0
- package/dist/types/wallet-server/src/core/hostedAccountIds.d.ts +31 -0
- package/dist/types/wallet-server/src/core/keyMaterialBrands.d.ts +28 -0
- package/dist/types/wallet-server/src/core/keyMaterialBrands.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/core/logger.d.ts +21 -0
- package/dist/types/wallet-server/src/core/nearKeys.d.ts +3 -0
- package/dist/types/wallet-server/src/core/nearRelayerAccountProvisioning.d.ts +78 -0
- package/dist/types/wallet-server/src/core/nearSignerWasmRuntime.d.ts +3 -0
- package/dist/types/wallet-server/src/core/registrationContracts.d.ts +747 -0
- package/dist/types/wallet-server/src/core/registrationRequests.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/core/routerAbSigning/RouterAbEcdsaPresignRuntime.d.ts +53 -0
- package/dist/types/wallet-server/src/core/routerAbSigning/RouterAbNormalSigningRuntime.d.ts +71 -0
- package/dist/types/wallet-server/src/core/routerAbSigning/createCloudflareDurableObjectRouterAbSigningRuntimes.d.ts +28 -0
- package/dist/types/wallet-server/src/core/routerAbSigning/createRouterAbSigningRuntimes.d.ts +16 -0
- package/dist/types/wallet-server/src/core/rpcClients/near/NearClient.d.ts +134 -0
- package/dist/types/wallet-server/src/core/sessionValidation.d.ts +9 -0
- package/dist/types/wallet-server/src/core/signingLanes/LaneAggregateRevocationApplicationService.d.ts +35 -0
- package/dist/types/wallet-server/src/core/signingLanes/LaneEffectJournalStore.d.ts +63 -0
- package/dist/types/wallet-server/src/core/signingLanes/LaneEnrollmentActivation.d.ts +13 -0
- package/dist/types/wallet-server/src/core/signingLanes/LaneEnrollmentRevocation.d.ts +24 -0
- package/dist/types/wallet-server/src/core/signingLanes/LaneLifecycleApplicationService.d.ts +141 -0
- package/dist/types/wallet-server/src/core/signingLanes/LaneLifecycleStore.d.ts +229 -0
- package/dist/types/wallet-server/src/core/signingLanes/SigningLaneStore.d.ts +15 -0
- package/dist/types/wallet-server/src/core/signingLanes/WalletExecutionLaneProjection.d.ts +59 -0
- package/dist/types/wallet-server/src/core/signingLanes/WalletKeyStore.d.ts +13 -0
- package/dist/types/wallet-server/src/core/signingLanes/ecdsaServerRetirement.d.ts +58 -0
- package/dist/types/wallet-server/src/core/signingLanes/ed25519ServerRetirement.d.ts +30 -0
- package/dist/types/wallet-server/src/core/signingLanes/index.d.ts +11 -0
- package/dist/types/wallet-server/src/core/signingLanes/signingWorkerLaneMaterialIdentity.d.ts +21 -0
- package/dist/types/wallet-server/src/core/signingMaterial/ordinaryInactiveSignerMaterialReservation.d.ts +155 -0
- package/dist/types/wallet-server/src/core/threeRouteRegistrationContracts.d.ts +442 -0
- package/dist/types/wallet-server/src/core/threeRouteRegistrationContracts.typecheck.d.ts +58 -0
- package/dist/types/wallet-server/src/core/thresholdEcdsaChainTarget.d.ts +15 -0
- package/dist/types/wallet-server/src/core/types.d.ts +757 -0
- package/dist/types/wallet-server/src/core/utils.d.ts +3 -0
- package/dist/types/wallet-server/src/delegateAction/index.d.ts +88 -0
- package/dist/types/wallet-server/src/hosted-wallet-gateway-worker.d.ts +10 -0
- package/dist/types/wallet-server/src/hosted-wallet-gateway.d.ts +126 -0
- package/dist/types/wallet-server/src/index.d.ts +34 -0
- package/dist/types/wallet-server/src/local-hosted-wallet-gateway-worker.d.ts +13 -0
- package/dist/types/wallet-server/src/router/auth/authRequestValidation.d.ts +97 -0
- package/dist/types/wallet-server/src/router/auth/commonRouterUtils.d.ts +142 -0
- package/dist/types/wallet-server/src/router/auth/routerApiCredentialAuth.d.ts +26 -0
- package/dist/types/wallet-server/src/router/auth/routerApiKeyAuth.d.ts +16 -0
- package/dist/types/wallet-server/src/router/auth/walletSessionFailure.d.ts +14 -0
- package/dist/types/wallet-server/src/router/auth/webAuthnCredentialCodecs.d.ts +20 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthBoundary.d.ts +28 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthConfig.d.ts +192 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthService.d.ts +13 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/authorization/d1AuthorizationStore.d.ts +174 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/authorization/d1VaultProxyStore.d.ts +13 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/authorization/walletSessionAuthorityProjection.d.ts +24 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceAuthorityInstallService.d.ts +241 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEd25519ExportRootStore.d.ts +23 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEmailOtpGrantStore.d.ts +32 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceEmailOtpTargetFactor.d.ts +118 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceManagementService.d.ts +22 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceOwnerAuthorizationProvider.d.ts +80 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceRequestProofNonceStore.d.ts +29 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceRouteService.d.ts +17 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionRecords.d.ts +37 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionService.d.ts +12 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionStore.d.ts +149 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSourceContributionPreparationPlanner.d.ts +38 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetAuthenticatorStore.d.ts +19 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetCredentialProvider.d.ts +220 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetPlanner.d.ts +88 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceVerifiedLinkBuilder.d.ts +54 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceVerifiedLinkSourceReader.d.ts +23 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/index.d.ts +15 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoCapabilityPersistence.d.ts +33 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoProductRegistrationPartitionedStateStore.d.ts +6 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoWalletSigner.d.ts +27 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeIssuer.d.ts +80 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeService.d.ts +48 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeStore.d.ts +64 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeVerifier.d.ts +126 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpDeliveryRuntime.d.ts +22 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpEnrollmentStore.d.ts +68 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpGrantStore.d.ts +15 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRateLimitStore.d.ts +37 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRecords.d.ts +186 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRecoveryService.d.ts +45 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRegistrationEnrollmentFinalizer.d.ts +124 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpServerSealRuntime.d.ts +24 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpRegistrationAttemptStore.d.ts +51 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpRegistrationRecords.d.ts +69 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpSessionResolver.d.ts +57 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/identity/d1IdentityRecords.d.ts +38 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/identity/d1IdentityService.d.ts +31 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/near/d1NearPublicKeyStore.d.ts +30 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/oidc/d1OidcBoundary.d.ts +60 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/oidc/d1OidcVerificationService.d.ts +39 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1PasskeyCustodyEnvelopeStore.d.ts +335 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1PasskeyCustodyRouteService.d.ts +448 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1WalletCustodyCommitStore.d.ts +256 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpAttemptStore.d.ts +32 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpRecords.d.ts +116 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1WalletRecoveryGoogleEmailOtpService.d.ts +180 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1EvmFamilyEcdsaRegistrationBranch.d.ts +24 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyRecordStore.d.ts +86 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyRecords.d.ts +121 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyStore.d.ts +84 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationIntentService.d.ts +31 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationCommitStore.d.ts +49 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationService.d.ts +369 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationSetup.d.ts +106 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/walletRegistrationEstablishedSessionIssuer.d.ts +104 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/registration/walletRegistrationSessionCommitReceipt.d.ts +70 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/signingAdmission/d1RouterAbNormalSigningAdmissionStore.d.ts +26 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1EcdsaLanePrivateBindingResolver.d.ts +4 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneAggregateRevocationApplicationService.d.ts +4 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneEffectJournalStore.d.ts +25 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneEnrollmentGateway.d.ts +20 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneLifecycleApplicationService.d.ts +13 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneLifecycleStore.d.ts +51 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneLockStore.d.ts +28 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneProtocolCommitter.d.ts +5 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/d1LaneRecords.d.ts +107 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/signingLanes/index.d.ts +10 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/versionedJson/d1VersionedJsonRecordStore.d.ts +118 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAddSignerService.d.ts +114 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAddSignerService.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthMethodBoundary.d.ts +90 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthMethodService.d.ts +359 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorityStore.d.ts +143 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/webauthn/d1WebAuthnAuthService.d.ts +42 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/webauthn/d1WebAuthnRecords.d.ts +135 -0
- package/dist/types/wallet-server/src/router/cloudflare/d1/webauthn/d1WebAuthnStore.d.ts +89 -0
- package/dist/types/wallet-server/src/router/cloudflare/durableObjects/thresholdStore.d.ts +19 -0
- package/dist/types/wallet-server/src/router/cloudflare/durableObjects/versionedJsonRecordStore.d.ts +32 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/cloudflare.types.d.ts +30 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/cloudflareSignerWasm.d.ts +2 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/createCloudflareRouter.d.ts +5 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/createSelfHostedCloudflareSigningWorker.d.ts +23 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/ed25519SessionAdapter.d.ts +16 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/environment.d.ts +5 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/routerAbPrewarm.d.ts +9 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/routerAbServiceBindings.d.ts +11 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/sessionAdapterRuntime.d.ts +28 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/staticWalletConsoleBinding.d.ts +27 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/tenantRootCreationGrant.d.ts +24 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletConsoleOps.d.ts +143 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletConsoleOpsClient.d.ts +20 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletConsoleTenantRootLineage.d.ts +7 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletControlOps.d.ts +21 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletGateway.d.ts +30 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRuntimeOps.d.ts +64 -0
- package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRuntimeOpsHandler.d.ts +3 -0
- package/dist/types/wallet-server/src/router/cloudflare/signingLanes/cloudflareLaneCurveExecution.d.ts +217 -0
- package/dist/types/wallet-server/src/router/cloudflare/signingLanes/cloudflareLaneProtocolCommitter.d.ts +73 -0
- package/dist/types/wallet-server/src/router/cloudflare/signingLanes/cloudflareOrdinaryInactiveSignerMaterialReservation.d.ts +100 -0
- package/dist/types/wallet-server/src/router/cloudflare/signingLanes/index.d.ts +4 -0
- package/dist/types/wallet-server/src/router/cloudflare/signingLanes/linkedDeviceEd25519CeremonyBinding.d.ts +6 -0
- package/dist/types/wallet-server/src/router/cloudflare-adaptor.d.ts +75 -0
- package/dist/types/wallet-server/src/router/domains/ecdsa/routerAbEcdsaStrictRegistration.d.ts +199 -0
- package/dist/types/wallet-server/src/router/domains/ecdsa/thresholdEcdsaRequestValidation.d.ts +32 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.d.ts +172 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitionedStateStore.d.ts +156 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitioning.d.ts +59 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPersistence.d.ts +47 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRunner.d.ts +29 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRuntime.d.ts +20 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/export/routerAbEd25519YaoExport.d.ts +271 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/export/routerAbEd25519YaoExportRequestScopedCloudflare.d.ts +12 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecovery.d.ts +509 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryActivation.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryRequestScopedCloudflare.d.ts +14 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryWalletSessionAuthorization.d.ts +20 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoHttpRegistrationBackend.d.ts +56 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistration.d.ts +200 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationExecutionRecord.d.ts +70 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationIntentAuthorization.d.ts +73 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationRequestScopedCloudflare.d.ts +9 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.d.ts +131 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationTwoPhaseRunner.d.ts +62 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/routerAbEd25519YaoGatewayEnvelope.d.ts +17 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/session/routerAbEd25519YaoWalletSession.d.ts +178 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/session/routerAbEd25519YaoWalletSession.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/router/domains/ed25519Yao/session/thresholdEd25519RequestValidation.d.ts +19 -0
- package/dist/types/wallet-server/src/router/domains/emailOtp/emailOtpExportPolicy.d.ts +32 -0
- package/dist/types/wallet-server/src/router/domains/emailOtp/emailOtpRequestValidation.d.ts +13 -0
- package/dist/types/wallet-server/src/router/domains/emailOtp/emailOtpRouteHandlers.d.ts +35 -0
- package/dist/types/wallet-server/src/router/domains/emailOtp/emailOtpSessionRouteHelpers.d.ts +134 -0
- package/dist/types/wallet-server/src/router/domains/passkeyCustody/envelopeRevocationAdmission.d.ts +31 -0
- package/dist/types/wallet-server/src/router/domains/passkeyCustody/passkeyCustodyEnvelopeRetrieval.d.ts +85 -0
- package/dist/types/wallet-server/src/router/domains/passkeyCustody/passkeyCustodyEnvelopeRetrievalRoute.d.ts +42 -0
- package/dist/types/wallet-server/src/router/domains/passkeyCustody/registrationCustodyOutcome.d.ts +38 -0
- package/dist/types/wallet-server/src/router/domains/passkeyCustody/verifiedCustodyFactor.d.ts +35 -0
- package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletCustodyRegistrationAdmission.d.ts +56 -0
- package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletCustodyRegistrationCommit.d.ts +65 -0
- package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletRecoveryAttempt.d.ts +59 -0
- package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletRecoveryFinalization.d.ts +81 -0
- package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletRecoveryKeyManifest.d.ts +184 -0
- package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletRecoveryRotation.d.ts +31 -0
- package/dist/types/wallet-server/src/router/domains/signingOperations/ed25519AuthorizedOperationReceipt.d.ts +32 -0
- package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbNormalSigningAdmissionCore.d.ts +48 -0
- package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbPrivateSigningWorker.d.ts +909 -0
- package/dist/types/wallet-server/src/router/domains/signingOperations/walletExecutionAdmission.d.ts +104 -0
- package/dist/types/wallet-server/src/router/domains/syncAccount/syncAccountRequestValidation.d.ts +30 -0
- package/dist/types/wallet-server/src/router/domains/tenantRoot/tenantRootCustodyLineage.d.ts +14 -0
- package/dist/types/wallet-server/src/router/domains/tenantRoot/tenantRootEcdsaWalletSessionComposition.d.ts +35 -0
- package/dist/types/wallet-server/src/router/domains/tenantRoot/tenantRootEd25519WalletSessionComposition.d.ts +35 -0
- package/dist/types/wallet-server/src/router/domains/tenantRoot/tenantRootIdentityResolution.d.ts +56 -0
- package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationInputs.d.ts +78 -0
- package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationRoutes.d.ts +91 -0
- package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationSetupPayload.d.ts +105 -0
- package/dist/types/wallet-server/src/router/domains/walletUnlock/walletUnlockRequestedCapabilitiesValidation.d.ts +39 -0
- package/dist/types/wallet-server/src/router/domains/walletUnlock/walletUnlockRouteHandlers.d.ts +172 -0
- package/dist/types/wallet-server/src/router/express-adaptor.d.ts +22 -0
- package/dist/types/wallet-server/src/router/framework/apiCredentialPorts.d.ts +82 -0
- package/dist/types/wallet-server/src/router/framework/applyRouteMetering.d.ts +23 -0
- package/dist/types/wallet-server/src/router/framework/authServicePort.d.ts +1392 -0
- package/dist/types/wallet-server/src/router/framework/enforceRoutePolicy.d.ts +48 -0
- package/dist/types/wallet-server/src/router/framework/http.d.ts +12 -0
- package/dist/types/wallet-server/src/router/framework/logger.d.ts +5 -0
- package/dist/types/wallet-server/src/router/framework/modules.d.ts +17 -0
- package/dist/types/wallet-server/src/router/framework/ror/index.d.ts +7 -0
- package/dist/types/wallet-server/src/router/framework/ror/normalize.d.ts +14 -0
- package/dist/types/wallet-server/src/router/framework/ror/options.d.ts +9 -0
- package/dist/types/wallet-server/src/router/framework/ror/provider.d.ts +17 -0
- package/dist/types/wallet-server/src/router/framework/ror/staticProvider.d.ts +11 -0
- package/dist/types/wallet-server/src/router/framework/routeAuthPolicy.d.ts +34 -0
- package/dist/types/wallet-server/src/router/framework/routeDefinitions.d.ts +27 -0
- package/dist/types/wallet-server/src/router/framework/routeDefinitions.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/router/framework/routeExecutionContext.d.ts +29 -0
- package/dist/types/wallet-server/src/router/framework/routeExtensions.d.ts +27 -0
- package/dist/types/wallet-server/src/router/framework/routeMeteringPolicy.d.ts +17 -0
- package/dist/types/wallet-server/src/router/framework/routeRequestValidation.d.ts +5 -0
- package/dist/types/wallet-server/src/router/framework/routeResponses.d.ts +17 -0
- package/dist/types/wallet-server/src/router/framework/routerApi.d.ts +221 -0
- package/dist/types/wallet-server/src/router/framework/routerApiRouteSurface.d.ts +14 -0
- package/dist/types/wallet-server/src/router/framework/routerApiWebhooks.d.ts +12 -0
- package/dist/types/wallet-server/src/router/framework/runtimeSnapshotConsumer.d.ts +28 -0
- package/dist/types/wallet-server/src/router/framework/versionedJsonRecordStore.d.ts +20 -0
- package/dist/types/wallet-server/src/router/ror-adaptor.d.ts +3 -0
- package/dist/types/wallet-server/src/router/transport/fetch/createFetchRouter.d.ts +8 -0
- package/dist/types/wallet-server/src/router/transport/fetch/fetchRouter.types.d.ts +23 -0
- package/dist/types/wallet-server/src/router/transport/fetch/routes/auth.d.ts +3 -0
- package/dist/types/wallet-server/src/router/transport/fetch/routes/deviceLinking.d.ts +202 -0
- package/dist/types/wallet-server/src/router/transport/fetch/routes/deviceLinkingOwnerAuthorization.d.ts +92 -0
- package/dist/types/wallet-server/src/router/transport/fetch/routes/deviceManagement.d.ts +29 -0
- package/dist/types/wallet-server/src/router/transport/fetch/routes/health.d.ts +4 -0
- package/dist/types/wallet-server/src/router/transport/fetch/routes/nearPublicKeys.d.ts +3 -0
- package/dist/types/wallet-server/src/router/transport/fetch/routes/normalSigningRouterProxy.d.ts +33 -0
- package/dist/types/wallet-server/src/router/transport/fetch/routes/passkeyCustody.d.ts +66 -0
- package/dist/types/wallet-server/src/router/transport/fetch/routes/sessions.d.ts +31 -0
- package/dist/types/wallet-server/src/router/transport/fetch/routes/syncAccount.d.ts +3 -0
- package/dist/types/wallet-server/src/router/transport/fetch/routes/syncAccountBootstrap.d.ts +128 -0
- package/dist/types/wallet-server/src/router/transport/fetch/routes/thresholdEcdsa.d.ts +87 -0
- package/dist/types/wallet-server/src/router/transport/fetch/routes/thresholdEd25519.d.ts +47 -0
- package/dist/types/wallet-server/src/router/transport/fetch/routes/walletExecutionLanePreflight.d.ts +4 -0
- package/dist/types/wallet-server/src/router/transport/fetch/routes/walletRegistration.d.ts +3 -0
- package/dist/types/wallet-server/src/router/transport/fetch/routes/webauthnAuthenticators.d.ts +3 -0
- package/dist/types/wallet-server/src/router/transport/fetch/routes/wellKnown.d.ts +3 -0
- package/dist/types/wallet-server/src/storage/d1Sql.d.ts +14 -0
- package/dist/types/wallet-server/src/storage/tenantRoute.d.ts +136 -0
- package/dist/types/wallet-server/src/storage/tenantRoute.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/tenant-root.d.ts +5 -0
- package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/crypto/cipher.d.ts +45 -0
- package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/crypto/shamir3PassWasm.d.ts +16 -0
- package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/guards/backends.d.ts +23 -0
- package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/guards/index.d.ts +46 -0
- package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/idempotency.d.ts +3 -0
- package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/idempotencyBackends.d.ts +24 -0
- package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/idempotencyRecords.d.ts +22 -0
- package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/index.d.ts +23 -0
- package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/observability/audit.d.ts +9 -0
- package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/options.d.ts +9 -0
- package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/routesOptions.d.ts +20 -0
- package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/service.d.ts +3 -0
- package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/signingSessionSeal.typecheck.d.ts +2 -0
- package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/signingSessionSeal.types.d.ts +148 -0
- package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/transport/express.d.ts +12 -0
- package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/transport/fetch.d.ts +13 -0
- package/dist/types/wallet-server/src/threshold/session/signingSessionSeal/transport/shared.d.ts +24 -0
- package/dist/types/wallet-server/src/threshold/statusCodes.d.ts +10 -0
- package/dist/types/wallet-server/src/wasm/signer.d.ts +8 -0
- package/migrations/d1-signer/0001_signer_d1_initial.sql +2486 -0
- package/migrations/d1-signer/0002_signer_post_103_canonical_upgrade.sql +1576 -0
- package/migrations/d1-signer/0003_r107_wallet_authorization.sql +299 -0
- package/migrations/d1-signer/0004_remove_legacy_email_recovery.sql +14 -0
- package/migrations/d1-signer/0005_r103p8_linked_owner_auth_bindings.sql +92 -0
- package/migrations/d1-signer/0006_r103p8_linked_device_custody_transfers.sql +77 -0
- package/migrations/d1-signer/0007_r103p8_wallet_session_auth_method_provenance.sql +18 -0
- package/migrations/d1-signer/0008_r103p8_linked_device_session_cas_guard.sql +35 -0
- package/migrations/d1-signer/0009_linked_device_email_otp.sql +405 -0
- package/migrations/d1-signer/0010_linked_device_session_target_factor.sql +78 -0
- package/migrations/d1-signer/0011_linked_device_ed25519_export_root.sql +9 -0
- package/migrations/d1-signer/0012_versioned_json_cas_guard.sql +3 -0
- package/migrations/d1-signer/0013_linked_device_export_authorization.sql +133 -0
- package/migrations/d1-signer/0014_wallet_recovery_code_locators.sql +19 -0
- package/migrations/d1-signer/0015_r103e_authority_baseline.sql +259 -0
- package/migrations/d1-signer/0016_r103e_wallet_session_authorizations_v2.sql +133 -0
- package/migrations/d1-signer/0017_r103e_link_session_state.sql +83 -0
- package/migrations/d1-signer/0018_r103e_linked_device_authority_installations.sql +34 -0
- package/migrations/d1-signer/0019_r103e_email_otp_device_methods.sql +3 -0
- package/migrations/d1-signer/0020_r103e_wallet_session_operation_credentials.sql +12 -0
- package/migrations/d1-signer/0021_linked_device_source_contribution_transcripts.sql +64 -0
- package/migrations/d1-signer/0022_r109c_multi_auth_email_cardinality.sql +118 -0
- package/migrations/d1-signer/0023_r109d_first_email_linked_device.sql +111 -0
- package/migrations/d1-signer/0024_r103f_v2_authorized_operation_claim.sql +99 -0
- package/migrations/d1-signer/0025_r109d_email_enrollment_wallet_cardinality.sql +57 -0
- package/migrations/d1-signer/0026_r115_wallet_recovery_authority_provenance.sql +253 -0
- package/migrations/d1-signer/0027_r115_email_otp_recovery_bootstrap.sql +90 -0
- package/migrations/d1-signer/0028_r103f_phase1_additive_schema_bridge.sql +1119 -0
- package/migrations/d1-signer/0029_r103f_phase0_registration_replay_tokens.sql +135 -0
- package/migrations/d1-signer/0030_r103f_wallet_session_client_capability.sql +17 -0
- package/migrations/d1-signer/0031_r103f_delete_registration_replay_tokens.sql +4 -0
- package/migrations/d1-signer/0032_r103f_exact_authorized_operation_enforcement.sql +149 -0
- package/migrations/d1-signer/0033_r103f_linked_delivery_recipient.sql +6 -0
- package/migrations/d1-signer/0034_r103f_exact_wallet_session_cutover.sql +743 -0
- package/migrations/d1-signer/0035_r103f_linked_delivery_acknowledgement_cleanup_window.sql +413 -0
- package/package.json +132 -0
- package/scripts/d1-local-migrate-signer.mjs +148 -0
- package/src/README.md +75 -0
- package/wrangler.local-hosted-wallet-gateway.toml +37 -0
|
@@ -0,0 +1,3887 @@
|
|
|
1
|
+
import { parseThresholdEd25519SessionId, parseWalletAuthMethodId, parseWalletAuthorityId, parseWalletKeyId, parseWebAuthnCredentialIdB64u } from "../../../../shared-ts/src/utils/domainIds.js";
|
|
2
|
+
import { parseDeviceId, parseWalletSessionMintId } from "../../../../shared-ts/src/authorization/capabilityKinds.js";
|
|
3
|
+
import { base64UrlDecode, base64UrlEncode } from "../../../../shared-ts/src/utils/base64.js";
|
|
4
|
+
import { parseDigestB64u } from "../../../../shared-ts/src/utils/canonicalPrimitives.js";
|
|
5
|
+
import { alphabetizeStringify, bytesToUnprefixedHex, sha256BytesUtf8 } from "../../../../shared-ts/src/utils/digests.js";
|
|
6
|
+
import "../../../../shared-ts/src/utils/encoders.js";
|
|
7
|
+
import { parseEd25519PublicKeyB64u, parseSecp256k1CompressedPublicKeyB64u } from "../../../../shared-ts/src/passkey-custody/primitives.js";
|
|
8
|
+
import { buildExactAdministeredSignerManifestV1 } from "../../../../shared-ts/src/device-linking/delegatedActivationPlan.js";
|
|
9
|
+
import { buildFullOwnerPermissionsV1 } from "../../../../shared-ts/src/authorization/delegatedAuthority.js";
|
|
10
|
+
import { buildActiveCombinedWalletAuthorityV1, buildActiveWalletAuthorityV1, buildWalletSignerActivationSetV1, computeWalletAuthorityDigestB64u, computeWalletSignerActivationSetDigestB64u, isActiveEcdsaWalletAuthorityV1, isCombinedWalletSignerActivationSetV1 } from "../../../../shared-ts/src/authorization/walletAuthority.js";
|
|
11
|
+
import { parseImplicitNearAccountId, parseNamedNearAccountId } from "../../../../shared-ts/src/utils/near.js";
|
|
12
|
+
import { buildWalletAuthMethodRecordV2, findRegistrationSignerPlanEvmFamilyEcdsaBranch, findRegistrationSignerPlanNearEd25519Branch, nearEd25519SigningKeyIdFromString, registrationEd25519AuthorityScopeFromAuthority, registrationIntentGrantFromString, registrationNearEd25519BranchKey, registrationSignerPlanFromSelection, walletIdFromString } from "../../../../shared-ts/src/utils/registrationIntent.js";
|
|
13
|
+
import { routerAbMpcMaterialActivationRefFromWire, routerAbMpcMaterialActivationRefToWire, sameRouterAbMpcMaterialActivationRef } from "../../../../shared-ts/src/utils/routerAbNormalSigningIdentity.js";
|
|
14
|
+
import { deriveRouterAbEd25519YaoRuntimePolicyBindingV1, sameRouterAbEd25519YaoRegistrationAdmissionRequestV1 } from "../../../../shared-ts/src/utils/routerAbEd25519Yao.js";
|
|
15
|
+
import { ecdsaClientRootPublicKey33B64uFromString } from "../../../../shared-ts/src/threshold/ecdsaDerivationRoleLocalBootstrap.js";
|
|
16
|
+
import { normalizeOptionalTrimmedString } from "../../../../shared-ts/src/utils/normalize.js";
|
|
17
|
+
import "../../../../shared-ts/src/utils/validation.js";
|
|
18
|
+
import { deriveSigningRootId, signingRootScopeFromRuntimePolicyScope } from "../../../../shared-ts/src/threshold/signingRootScope.js";
|
|
19
|
+
import { isEmailOtpWalletAuthAuthority, isPasskeyWalletAuthAuthority, walletAuthAuthoritiesMatch } from "../../../../shared-ts/src/utils/walletAuthAuthority.js";
|
|
20
|
+
import { ROUTER_AB_ECDSA_DERIVATION_NORMAL_SIGNING_STATE_KIND_V1, buildRouterAbEcdsaDerivationActiveStateIdV1, buildRouterAbEcdsaDerivationPublicCapabilityV1, parseRouterAbEcdsaDerivationNormalSigningStateV1, sameRouterAbEcdsaDerivationNormalSigningStateV1, sameRouterAbEcdsaDerivationPublicCapabilityV1, sameRouterAbEcdsaRegistrationActivationReceiptV1, sameRouterAbEcdsaVerifiedClientActivationFactsV1, sameRouterAbPublicDigest32V1Wire } from "../../../../shared-ts/src/utils/routerAbEcdsaDerivation.js";
|
|
21
|
+
import { secureRandomBase64Url } from "../../../../shared-ts/src/utils/secureRandomId.js";
|
|
22
|
+
import { ROUTER_AB_ED25519_NORMAL_SIGNING_STATE_KIND } from "../../../../shared-ts/src/utils/signingSessionSeal.js";
|
|
23
|
+
import { normalizeThresholdEd25519ParticipantIds } from "../../../../shared-ts/src/threshold/participants.js";
|
|
24
|
+
import { registrationPreparationIdFromString } from "../../../../core/types.js";
|
|
25
|
+
import { buildTenantRootIdentityFromAuthenticatedDeploymentV1 } from "../../../../shared-ts/src/tenant-root/tenantRootIdentity.js";
|
|
26
|
+
import { walletCustodyCeremonyCommitPayloadFromWire } from "../../../../shared-ts/src/passkey-custody/ceremonyCommitPayload.js";
|
|
27
|
+
import "../../../../shared-ts/src/passkey-custody/index.js";
|
|
28
|
+
import { computeWalletRegistrationSetupDigestB64u, verifySignedWalletRegistrationSetup, verifyWalletRegistrationSetupClaims } from "../../../domains/walletRegistration/walletRegistrationSetupPayload.js";
|
|
29
|
+
import { DEFAULT_WALLET_SESSION_TTL_MS } from "../../../../shared-ts/src/threshold/sessionPolicy.js";
|
|
30
|
+
import { parseEcdsaDerivationPublicIdentity, thresholdEd25519AuthorityScopeFromWalletAuthAuthority } from "../../../../core/ThresholdService/validation.js";
|
|
31
|
+
import { walletAuthAuthorityFromRegistrationAuthority, walletRegistrationFinalizeAuthMethodFromAuthority } from "../wallet/d1WalletAuthMethodBoundary.js";
|
|
32
|
+
import { buildRouterAbEd25519YaoRegistrationCapabilityRecordV1 } from "../../../domains/ed25519Yao/recovery/routerAbEd25519YaoRecovery.js";
|
|
33
|
+
import { buildRouterAbEd25519YaoProductAdmissionRequestV1, createRouterAbEd25519YaoMaterialActivationRefV1, projectRouterAbEd25519YaoExactWalletSession } from "../../../domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.js";
|
|
34
|
+
import { runRouterAbEd25519YaoRegistrationSideEffectV2, throwIfRouterAbEd25519YaoRetryableSideEffectFailureV1 } from "../../../domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.js";
|
|
35
|
+
import { buildYaoEd25519WalletSignerRecord, ed25519NearPublicKeyFromBytes, implicitNearAccountIdFromEd25519PublicKeyBytes } from "../ed25519Yao/d1Ed25519YaoWalletSigner.js";
|
|
36
|
+
import { deriveThresholdEcdsaKeyHandle } from "../../../../shared-ts/src/utils/thresholdEcdsaKeyHandle.js";
|
|
37
|
+
import { routerAbEcdsaStrictRegistrationFactsBindingJson, routerAbEcdsaStrictRegistrationRequestBindingJson } from "../../../domains/ecdsa/routerAbEcdsaStrictRegistration.js";
|
|
38
|
+
import { buildStoredWalletRegistrationEvmFamilyEcdsaFinalizedBranch, buildStoredWalletRegistrationEvmFamilyEcdsaPreparedBranch, buildStoredWalletRegistrationNearEd25519YaoAuthorizedBranch, buildStoredWalletRegistrationPreparedContext, findStoredWalletRegistrationEvmFamilyEcdsaBranch, findStoredWalletRegistrationNearEd25519YaoBranch, replaceStoredWalletRegistrationSignerBranch, storedRegistrationAuthoritiesMatch, verifiedRegistrationCeremonyAuthority } from "../../../../core/RegistrationCeremonyStore.js";
|
|
39
|
+
import { buildD1EcdsaWalletKeysFromBootstrap, buildD1WalletEcdsaSignerRecords, buildD1WalletRecord, buildRegistrationIntent, createD1ServerAllocatedWalletId, inferRuntimePolicyScopeFromSigningRoot, normalizeThresholdEcdsaChainTargets, parseWalletIdForIntent, thresholdEcdsaChainTargetsEqual } from "./d1RegistrationCeremonyRecords.js";
|
|
40
|
+
import { resolveTenantRootIdentityV1 } from "../../../domains/tenantRoot/tenantRootIdentityResolution.js";
|
|
41
|
+
import { listThresholdEcdsaKeyIdentityTargetsForUser } from "../../../../core/authService/thresholdEcdsaKeyInventory.js";
|
|
42
|
+
import { buildWalletRegistrationSetupSignature, normalizeWalletRegistrationSetupRequest, resolveWalletRegistrationSetupWalletId, storedRespondEd25519DeferredWork, walletRegistrationRespondResult, walletRegistrationSetupError, walletRegistrationSetupExpiresAtMs, walletRegistrationSetupIds, walletRegistrationSetupIntentDigest } from "./d1WalletRegistrationSetup.js";
|
|
43
|
+
import { commitRegistrationCustody } from "../../../domains/passkeyCustody/registrationCustodyOutcome.js";
|
|
44
|
+
import { buildD1EvmFamilyEcdsaRegistrationPrepare } from "./d1EvmFamilyEcdsaRegistrationBranch.js";
|
|
45
|
+
import { projectWalletRegistrationSessionCommitReceiptV2, registrationReplayAuthMethodFields, replayedRegistrationCommit, unissuedRegistrationCommit } from "./walletRegistrationSessionCommitReceipt.js";
|
|
46
|
+
import { assertDirectWalletSessionOwnerProof, buildRegistrationOwnerProof, issueDirectRegistrationEstablishedEcdsaSession, issueDirectRegistrationEstablishedEd25519Session, replayDirectRegistrationEstablishedEcdsaSession, replayDirectRegistrationEstablishedEd25519Session, walletSessionPrincipalId } from "./walletRegistrationEstablishedSessionIssuer.js";
|
|
47
|
+
//#region src/router/cloudflare/d1/registration/d1WalletRegistrationService.ts
|
|
48
|
+
function buildWalletRegistrationActivatePendingPasskeyResponse(input) {
|
|
49
|
+
return {
|
|
50
|
+
ok: true,
|
|
51
|
+
kind: "near_ed25519",
|
|
52
|
+
walletId: input.walletId,
|
|
53
|
+
authority: input.authority,
|
|
54
|
+
authMethod: input.authMethod,
|
|
55
|
+
rpId: input.rpId,
|
|
56
|
+
nearProvisioning: { status: "near_pending" }
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function buildWalletRegistrationActivatePendingEmailOtpResponse(input) {
|
|
60
|
+
return {
|
|
61
|
+
ok: true,
|
|
62
|
+
kind: "near_ed25519",
|
|
63
|
+
walletId: input.walletId,
|
|
64
|
+
authority: input.authority,
|
|
65
|
+
authMethod: input.authMethod,
|
|
66
|
+
nearProvisioning: { status: "near_pending" }
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function sameEd25519ParticipantIds(left, right) {
|
|
70
|
+
return left[0] === right[0] && left[1] === right[1];
|
|
71
|
+
}
|
|
72
|
+
function sameEcdsaParticipantIds(left, right) {
|
|
73
|
+
if (left.length !== right.length) return false;
|
|
74
|
+
for (let index = 0; index < left.length; index += 1) if (left[index] !== right[index]) return false;
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
function sameEcdsaDerivationPublicIdentity(left, right) {
|
|
78
|
+
return left.derivationClientSharePublicKey33B64u === right.derivationClientSharePublicKey33B64u && left.relayerPublicKey33B64u === right.relayerPublicKey33B64u && left.groupPublicKey33B64u === right.groupPublicKey33B64u && left.ethereumAddress === right.ethereumAddress;
|
|
79
|
+
}
|
|
80
|
+
function sameWalletRuntimePolicyScope(left, right) {
|
|
81
|
+
return left.orgId === right.orgId && left.projectId === right.projectId && left.envId === right.envId && left.signingRootVersion === right.signingRootVersion;
|
|
82
|
+
}
|
|
83
|
+
function sameRouterAbEcdsaRegistrationEnvelope(left, right) {
|
|
84
|
+
return left.recipient_role === right.recipient_role && sameRouterAbPublicDigest32V1Wire(left.header_digest, right.header_digest) && sameRouterAbPublicDigest32V1Wire(left.aad_digest, right.aad_digest) && left.ciphertext.bytes.length === right.ciphertext.bytes.length && left.ciphertext.bytes.every((value, index) => value === right.ciphertext.bytes[index]);
|
|
85
|
+
}
|
|
86
|
+
function sameRouterAbEcdsaRegistrationRequest(left, right) {
|
|
87
|
+
return routerAbEcdsaStrictRegistrationRequestBindingJson(left) === routerAbEcdsaStrictRegistrationRequestBindingJson(right) && left.client_ephemeral_public_key === right.client_ephemeral_public_key && sameRouterAbEcdsaRegistrationEnvelope(left.deriver_a_envelope, right.deriver_a_envelope) && sameRouterAbEcdsaRegistrationEnvelope(left.deriver_b_envelope, right.deriver_b_envelope);
|
|
88
|
+
}
|
|
89
|
+
function sameEcdsaDerivationServerBootstrap(left, right) {
|
|
90
|
+
return left.formatVersion === right.formatVersion && left.walletId === right.walletId && left.evmFamilySigningKeySlotId === right.evmFamilySigningKeySlotId && left.ecdsaThresholdKeyId === right.ecdsaThresholdKeyId && left.relayerKeyId === right.relayerKeyId && left.applicationBindingDigestB64u === right.applicationBindingDigestB64u && left.contextBinding32B64u === right.contextBinding32B64u && sameEcdsaDerivationPublicIdentity(left.publicIdentity, right.publicIdentity) && left.clientShareRetryCounter === right.clientShareRetryCounter && left.relayerShareRetryCounter === right.relayerShareRetryCounter && left.publicTranscriptDigest32B64u === right.publicTranscriptDigest32B64u && left.keyHandle === right.keyHandle && left.signingRootId === right.signingRootId && left.signingRootVersion === right.signingRootVersion && left.thresholdEcdsaPublicKeyB64u === right.thresholdEcdsaPublicKeyB64u && left.ethereumAddress === right.ethereumAddress && left.relayerVerifyingShareB64u === right.relayerVerifyingShareB64u && sameEcdsaParticipantIds(left.participantIds, right.participantIds) && left.thresholdSessionId === right.thresholdSessionId && left.activationEpoch === right.activationEpoch && left.expiresAtMs === right.expiresAtMs && left.expiresAt === right.expiresAt && left.remainingUses === right.remainingUses && sameRouterAbEcdsaDerivationNormalSigningStateV1(left.routerAbEcdsaDerivationNormalSigning, right.routerAbEcdsaDerivationNormalSigning);
|
|
91
|
+
}
|
|
92
|
+
function linkedEd25519ProjectionMaterialActivationWire(projection) {
|
|
93
|
+
return routerAbMpcMaterialActivationRefToWire(projection.materialActivation);
|
|
94
|
+
}
|
|
95
|
+
function linkedEd25519ProjectionMatchesSigner(input) {
|
|
96
|
+
const { projection, signer } = input;
|
|
97
|
+
const authorityActivation = input.authority.signerActivations.ed25519;
|
|
98
|
+
if (!authorityActivation) return false;
|
|
99
|
+
const registeredPublicKeyBytes = projection.activationReceipt.registered_public_key;
|
|
100
|
+
const registeredPublicKeyB64u = base64UrlEncode(Uint8Array.from(registeredPublicKeyBytes));
|
|
101
|
+
const expectedWalletKeyId = `wallet-key:ed25519:${input.walletId}:${signer.nearEd25519SigningKeyId}`;
|
|
102
|
+
const targetBinding = projection.targetBinding;
|
|
103
|
+
const targetLifecycle = targetBinding.lifecycle;
|
|
104
|
+
return projection.walletId === input.walletId && projection.authorityId === input.authority.authorityId && projection.walletAuthMethodId === input.authMethodId && input.authority.provenance.kind === "device_link" && projection.linkSessionId === input.authority.provenance.linkSessionId && projection.applicationBinding.wallet_id === input.walletId && projection.applicationBinding.near_ed25519_signing_key_id === signer.nearEd25519SigningKeyId && projection.applicationBinding.key_creation_signer_slot === signer.signerSlot && projection.applicationBinding.signing_root_id === signer.signingRootId && sameEd25519ParticipantIds(projection.participantIds, signer.participantIds) && targetBinding.operation === "registration" && targetLifecycle.work_kind === "registration_prepare" && targetLifecycle.primitive_request_kind === "registration" && targetLifecycle.account_id === input.walletId && targetLifecycle.root_share_epoch === signer.signingRootVersion && targetLifecycle.signer_set_id === String(registrationNearEd25519BranchKey(signer.signerSlot)) && targetLifecycle.selected_server_id === signer.signingWorkerId && sameRouterAbMpcMaterialActivationRef(linkedEd25519ProjectionMaterialActivationWire(projection), routerAbMpcMaterialActivationRefToWire(authorityActivation.materialActivation)) && authorityActivation.signer.walletId === input.walletId && authorityActivation.signer.walletKeyId === expectedWalletKeyId && authorityActivation.signer.registeredPublicKeyB64u === registeredPublicKeyB64u && signer.publicKey === ed25519NearPublicKeyFromBytes(registeredPublicKeyBytes);
|
|
105
|
+
}
|
|
106
|
+
function linkedEd25519ProjectionMatchesDescriptor(input) {
|
|
107
|
+
const { projection, descriptor } = input;
|
|
108
|
+
const targetBinding = projection.targetBinding;
|
|
109
|
+
const targetLifecycle = targetBinding.lifecycle;
|
|
110
|
+
const registeredPublicKeyBytes = projection.activationReceipt.registered_public_key;
|
|
111
|
+
const descriptorPublicKeyBytes = descriptor.registeredPublicKey;
|
|
112
|
+
return projection.applicationBinding.wallet_id === descriptor.applicationBinding.wallet_id && projection.applicationBinding.near_ed25519_signing_key_id === descriptor.applicationBinding.near_ed25519_signing_key_id && projection.applicationBinding.signing_root_id === descriptor.applicationBinding.signing_root_id && projection.applicationBinding.key_creation_signer_slot === descriptor.applicationBinding.key_creation_signer_slot && sameEd25519ParticipantIds(projection.participantIds, descriptor.participantIds) && targetBinding.operation === "registration" && targetLifecycle.work_kind === "registration_prepare" && targetLifecycle.primitive_request_kind === "registration" && targetLifecycle.account_id === descriptor.lifecycle.accountId && targetLifecycle.root_share_epoch === descriptor.lifecycle.rootShareEpoch && targetLifecycle.signer_set_id === descriptor.lifecycle.signerSetId && targetLifecycle.selected_server_id === descriptor.lifecycle.signingWorkerId && sameRouterAbMpcMaterialActivationRef(targetBinding.material_activation, linkedEd25519ProjectionMaterialActivationWire(projection)) && sameRouterAbMpcMaterialActivationRef(projection.activationReceipt.material_activation, linkedEd25519ProjectionMaterialActivationWire(projection)) && ed25519NearPublicKeyFromBytes(registeredPublicKeyBytes) === ed25519NearPublicKeyFromBytes(descriptorPublicKeyBytes) && descriptor.nearAccountId === implicitNearAccountIdFromEd25519PublicKeyBytes(registeredPublicKeyBytes);
|
|
113
|
+
}
|
|
114
|
+
function linkedEcdsaProjectionMatchesSigner(input) {
|
|
115
|
+
const receipt = input.projection.activationReceipt;
|
|
116
|
+
const source = receipt.binding.source;
|
|
117
|
+
const sourceScope = receipt.sourceDerivation.sourceNormalSigning.scope;
|
|
118
|
+
const capability = input.signer.walletKey.publicCapability;
|
|
119
|
+
const activation = input.signer.activationReceipt.ecdsa_activation;
|
|
120
|
+
return input.signer.walletId === input.projection.walletId && input.projection.signer.walletId === input.signer.walletId && input.projection.signer.thresholdPublicKey33B64u === source.thresholdPublicKey33B64u && input.signer.walletKey.ecdsaThresholdKeyId === sourceScope.ecdsa_threshold_key_id && input.signer.walletKey.signingRootId === sourceScope.signing_root_id && input.signer.walletKey.signingRootVersion === sourceScope.signing_root_version && input.signer.walletKey.thresholdEcdsaPublicKeyB64u === source.thresholdPublicKey33B64u && String(input.signer.walletKey.derivationClientSharePublicKey33B64u) === source.clientPublicKey33B64u && String(input.signer.walletKey.relayerVerifyingShareB64u) === source.relayerPublicKey33B64u && sameRouterAbMpcMaterialActivationRef(capability.material_activation, routerAbMpcMaterialActivationRefToWire(source.activation)) && capability.client_id === String(input.projection.walletId) && capability.context.application_binding_digest_b64u === sourceScope.context.application_binding_digest_b64u && capability.public_identity.context_binding_b64u === sourceScope.public_identity.context_binding_b64u && capability.public_identity.derivation_client_share_public_key33_b64u === source.clientPublicKey33B64u && capability.public_identity.server_public_key33_b64u === source.relayerPublicKey33B64u && capability.public_identity.threshold_public_key33_b64u === source.thresholdPublicKey33B64u && capability.public_identity.ethereum_address20_b64u === source.thresholdEthereumAddress20B64u && capability.public_identity.client_share_retry_counter === sourceScope.public_identity.client_share_retry_counter && capability.public_identity.server_share_retry_counter === sourceScope.public_identity.server_share_retry_counter && capability.signer_set.selected_server.server_id === sourceScope.signing_worker.server_id && capability.activation_epoch === sourceScope.activation_epoch && sameRouterAbMpcMaterialActivationRef(activation.material_activation, routerAbMpcMaterialActivationRefToWire(source.activation)) && activation.context.application_binding_digest_b64u === sourceScope.context.application_binding_digest_b64u && activation.public_identity.context_binding_b64u === sourceScope.public_identity.context_binding_b64u && activation.public_identity.derivation_client_share_public_key33_b64u === source.clientPublicKey33B64u && activation.public_identity.server_public_key33_b64u === source.relayerPublicKey33B64u && activation.public_identity.threshold_public_key33_b64u === source.thresholdPublicKey33B64u && activation.public_identity.ethereum_address20_b64u === source.thresholdEthereumAddress20B64u && activation.signing_worker.server_id === sourceScope.signing_worker.server_id && activation.activation_epoch === sourceScope.activation_epoch;
|
|
121
|
+
}
|
|
122
|
+
function sameLinkedEcdsaResolvedSignerIdentity(left, right) {
|
|
123
|
+
return left.walletId === right.walletId && left.walletKey.keyHandle === right.walletKey.keyHandle && left.walletKey.relayerKeyId === right.walletKey.relayerKeyId && left.walletKey.participantIds[0] === right.walletKey.participantIds[0] && left.walletKey.participantIds[1] === right.walletKey.participantIds[1] && sameRouterAbEcdsaDerivationPublicCapabilityV1(left.walletKey.publicCapability, right.walletKey.publicCapability) && sameWalletRuntimePolicyScope(left.runtimePolicyScope, right.runtimePolicyScope);
|
|
124
|
+
}
|
|
125
|
+
async function ed25519ExportIdentityFromActiveCapability(descriptor) {
|
|
126
|
+
return {
|
|
127
|
+
scope: {
|
|
128
|
+
lifecycle_id: descriptor.lifecycle.lifecycleId,
|
|
129
|
+
root_share_epoch: descriptor.lifecycle.rootShareEpoch,
|
|
130
|
+
account_id: descriptor.lifecycle.accountId,
|
|
131
|
+
threshold_session_id: descriptor.lifecycle.thresholdSessionId,
|
|
132
|
+
signer_set_id: descriptor.lifecycle.signerSetId,
|
|
133
|
+
signing_worker_id: descriptor.lifecycle.signingWorkerId,
|
|
134
|
+
material_activation: descriptor.materialActivation
|
|
135
|
+
},
|
|
136
|
+
application_binding: descriptor.applicationBinding,
|
|
137
|
+
participant_ids: descriptor.participantIds,
|
|
138
|
+
registered_public_key: descriptor.registeredPublicKey,
|
|
139
|
+
state_epoch: descriptor.stateEpoch,
|
|
140
|
+
runtime_policy_binding: await deriveRouterAbEd25519YaoRuntimePolicyBindingV1(descriptor.runtimePolicyScope)
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
async function ed25519ExportIdentityFromPersistedCapability(capability) {
|
|
144
|
+
const binding = capability.activationResult.binding;
|
|
145
|
+
return {
|
|
146
|
+
scope: {
|
|
147
|
+
lifecycle_id: binding.lifecycle.lifecycle_id,
|
|
148
|
+
root_share_epoch: binding.lifecycle.root_share_epoch,
|
|
149
|
+
account_id: binding.lifecycle.account_id,
|
|
150
|
+
threshold_session_id: binding.lifecycle.session_id,
|
|
151
|
+
signer_set_id: binding.lifecycle.signer_set_id,
|
|
152
|
+
signing_worker_id: binding.lifecycle.selected_server_id,
|
|
153
|
+
material_activation: binding.material_activation
|
|
154
|
+
},
|
|
155
|
+
application_binding: capability.admissionRequest.application_binding,
|
|
156
|
+
participant_ids: capability.admissionRequest.participant_ids,
|
|
157
|
+
registered_public_key: capability.activationResult.public_receipt.registered_public_key,
|
|
158
|
+
state_epoch: capability.activationResult.public_receipt.state_epoch,
|
|
159
|
+
runtime_policy_binding: await deriveRouterAbEd25519YaoRuntimePolicyBindingV1(capability.runtimePolicyScope)
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
async function activeEd25519MaterialFromPersistedSigner(signer) {
|
|
163
|
+
const capability = signer.activeYaoCapability;
|
|
164
|
+
return {
|
|
165
|
+
ok: true,
|
|
166
|
+
materialActivation: capability.activationResult.binding.material_activation,
|
|
167
|
+
nearAccountId: capability.nearAccountId,
|
|
168
|
+
signerSlot: signer.signerSlot,
|
|
169
|
+
signingWorkerId: signer.signingWorkerId,
|
|
170
|
+
participantIds: signer.participantIds,
|
|
171
|
+
runtimePolicyScope: capability.runtimePolicyScope,
|
|
172
|
+
exportIdentity: await ed25519ExportIdentityFromPersistedCapability(capability)
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
async function ed25519ExportIdentityFromLinkedProjection(projection, descriptor) {
|
|
176
|
+
const lifecycle = projection.targetBinding.lifecycle;
|
|
177
|
+
return {
|
|
178
|
+
scope: {
|
|
179
|
+
lifecycle_id: lifecycle.lifecycle_id,
|
|
180
|
+
root_share_epoch: lifecycle.root_share_epoch,
|
|
181
|
+
account_id: lifecycle.account_id,
|
|
182
|
+
threshold_session_id: lifecycle.session_id,
|
|
183
|
+
signer_set_id: lifecycle.signer_set_id,
|
|
184
|
+
signing_worker_id: lifecycle.selected_server_id,
|
|
185
|
+
material_activation: projection.targetBinding.material_activation
|
|
186
|
+
},
|
|
187
|
+
application_binding: projection.applicationBinding,
|
|
188
|
+
participant_ids: projection.participantIds,
|
|
189
|
+
registered_public_key: projection.activationReceipt.registered_public_key,
|
|
190
|
+
state_epoch: projection.activationReceipt.state_epoch,
|
|
191
|
+
runtime_policy_binding: await deriveRouterAbEd25519YaoRuntimePolicyBindingV1(descriptor.runtimePolicyScope)
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
async function walletRegistrationFinalizeRequestFingerprint(request) {
|
|
195
|
+
return base64UrlEncode(await sha256BytesUtf8(alphabetizeStringify(request)));
|
|
196
|
+
}
|
|
197
|
+
function requirePreparedRegistrationId(result, label) {
|
|
198
|
+
if (!result.ok) throw new Error(`${label} is invalid: ${result.error.message}`);
|
|
199
|
+
return result.value;
|
|
200
|
+
}
|
|
201
|
+
function allocateWalletRegistrationOperationPrepared() {
|
|
202
|
+
return {
|
|
203
|
+
kind: "d1_wallet_registration_operation_prepared_v1",
|
|
204
|
+
walletAuthorityId: requirePreparedRegistrationId(parseWalletAuthorityId(`wallet-authority:${secureRandomBase64Url(32)}`), "walletAuthorityId"),
|
|
205
|
+
deviceId: requirePreparedRegistrationId(parseDeviceId(`device:${secureRandomBase64Url(32)}`), "deviceId"),
|
|
206
|
+
walletAuthMethodId: requirePreparedRegistrationId(parseWalletAuthMethodId(`wallet-auth-method:${secureRandomBase64Url(32)}`), "walletAuthMethodId")
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function walletRegistrationOperationPreparedFromCeremony(ceremony) {
|
|
210
|
+
if (String(ceremony.foundingWalletAuthMethodId) !== String(ceremony.intent.foundingWalletAuthMethodId)) throw new Error("registration ceremony and intent name different founding auth methods");
|
|
211
|
+
return {
|
|
212
|
+
kind: "d1_wallet_registration_operation_prepared_v1",
|
|
213
|
+
walletAuthorityId: ceremony.foundingWalletAuthorityId,
|
|
214
|
+
deviceId: ceremony.foundingDeviceId,
|
|
215
|
+
walletAuthMethodId: ceremony.foundingWalletAuthMethodId
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function committedInstallationProjectionFromCeremony(ceremony) {
|
|
219
|
+
const registrationAuthority = verifiedRegistrationCeremonyAuthority(ceremony);
|
|
220
|
+
if (ceremony.signerState.kind !== "signer_set_registration" || registrationAuthority === null) return null;
|
|
221
|
+
const branches = registrationSignerBranchesFromPlan(ceremony.signerPlan);
|
|
222
|
+
const nearPlan = branches.nearEd25519;
|
|
223
|
+
const ecdsaBranch = findStoredWalletRegistrationEvmFamilyEcdsaBranch(ceremony.signerState);
|
|
224
|
+
const nearBranch = findStoredWalletRegistrationNearEd25519YaoBranch(ceremony.signerState);
|
|
225
|
+
if (nearPlan === null || branches.evmFamilyEcdsa === null || ecdsaBranch?.kind !== "evm_family_ecdsa_finalized" || ecdsaBranch.branchKey !== branches.evmFamilyEcdsa.branchKey || nearBranch === null || nearBranch.branchKey !== nearPlan.branchKey || nearBranch.admissionRequest.scope.lifecycle_id !== ceremony.registrationCeremonyId || nearBranch.admissionRequest.scope.account_id !== String(ceremony.intent.walletId) || nearBranch.admissionRequest.application_binding.wallet_id !== String(ceremony.intent.walletId) || nearBranch.admissionRequest.application_binding.signing_root_id !== ceremony.preparedContext.signingRootId || nearBranch.admissionRequest.application_binding.key_creation_signer_slot !== nearPlan.signerSlot || nearBranch.admissionRequest.participant_ids.length !== nearPlan.participantIds.length || nearBranch.admissionRequest.participant_ids.some((participantId, index) => participantId !== nearPlan.participantIds[index])) return null;
|
|
226
|
+
return {
|
|
227
|
+
kind: "wallet_registration_committed_installation_projection_v1",
|
|
228
|
+
registrationCeremonyId: ceremony.registrationCeremonyId,
|
|
229
|
+
walletId: ceremony.intent.walletId,
|
|
230
|
+
orgId: ceremony.orgId,
|
|
231
|
+
registrationAuthority,
|
|
232
|
+
signerPlan: ceremony.signerPlan,
|
|
233
|
+
preparedContext: ceremony.preparedContext,
|
|
234
|
+
nearEd25519: nearBranch
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function requireFoundingWalletKeyId(raw, label) {
|
|
238
|
+
const parsed = parseWalletKeyId(raw);
|
|
239
|
+
if (!parsed.ok) throw new Error(`${label} is invalid: ${parsed.error.message}`);
|
|
240
|
+
return parsed.value;
|
|
241
|
+
}
|
|
242
|
+
function requireFoundingEvmAddress(raw) {
|
|
243
|
+
if (!/^0x[0-9a-fA-F]{40}$/.test(raw)) throw new Error("ECDSA registration returned an invalid owner address");
|
|
244
|
+
return raw;
|
|
245
|
+
}
|
|
246
|
+
function requireSingleFoundingEcdsaWalletKey(walletKeys) {
|
|
247
|
+
const first = walletKeys[0];
|
|
248
|
+
if (!first) throw new Error("ECDSA founding authority is missing wallet-key facts");
|
|
249
|
+
for (const candidate of walletKeys.slice(1)) if (candidate.walletId !== first.walletId || candidate.evmFamilySigningKeySlotId !== first.evmFamilySigningKeySlotId || candidate.thresholdEcdsaPublicKeyB64u !== first.thresholdEcdsaPublicKeyB64u || candidate.thresholdOwnerAddress !== first.thresholdOwnerAddress) throw new Error("ECDSA founding authority received conflicting wallet-key facts");
|
|
250
|
+
return first;
|
|
251
|
+
}
|
|
252
|
+
function foundingEd25519SignerIdentity(walletId, facts) {
|
|
253
|
+
return {
|
|
254
|
+
kind: "exact_administered_ed25519_signer_v1",
|
|
255
|
+
keyFamily: "ed25519",
|
|
256
|
+
walletId,
|
|
257
|
+
walletKeyId: requireFoundingWalletKeyId(`wallet-key:ed25519:${walletId}:${facts.signer.nearEd25519SigningKeyId}`, "Ed25519 walletKeyId"),
|
|
258
|
+
registeredPublicKeyB64u: parseEd25519PublicKeyB64u(facts.registeredPublicKeyB64u)
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function foundingEcdsaSignerIdentity(walletId, facts) {
|
|
262
|
+
return {
|
|
263
|
+
kind: "exact_administered_ecdsa_signer_v1",
|
|
264
|
+
keyFamily: "ecdsa_secp256k1",
|
|
265
|
+
walletId,
|
|
266
|
+
walletKeyId: requireFoundingWalletKeyId(`wallet-key:ecdsa:${walletId}:${facts.walletKey.evmFamilySigningKeySlotId}`, "ECDSA walletKeyId"),
|
|
267
|
+
thresholdPublicKey33B64u: parseSecp256k1CompressedPublicKeyB64u(facts.walletKey.thresholdEcdsaPublicKeyB64u),
|
|
268
|
+
evmAddress: requireFoundingEvmAddress(facts.walletKey.thresholdOwnerAddress)
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function foundingSignerManifest(walletId, facts) {
|
|
272
|
+
switch (facts.kind) {
|
|
273
|
+
case "ed25519": return buildExactAdministeredSignerManifestV1([foundingEd25519SignerIdentity(walletId, facts.ed25519)]);
|
|
274
|
+
case "ecdsa_secp256k1": return buildExactAdministeredSignerManifestV1([foundingEcdsaSignerIdentity(walletId, facts.ecdsa)]);
|
|
275
|
+
case "both": return buildExactAdministeredSignerManifestV1([foundingEd25519SignerIdentity(walletId, facts.ed25519), foundingEcdsaSignerIdentity(walletId, facts.ecdsa)]);
|
|
276
|
+
default: return assertNeverFoundingSignerFacts(facts);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function foundingSignerActivations(walletId, facts) {
|
|
280
|
+
const manifest = foundingSignerManifest(walletId, facts);
|
|
281
|
+
switch (facts.kind) {
|
|
282
|
+
case "ed25519": return buildWalletSignerActivationSetV1({
|
|
283
|
+
manifest,
|
|
284
|
+
materialActivations: {
|
|
285
|
+
keyFamilies: ["ed25519"],
|
|
286
|
+
ed25519: facts.ed25519.materialActivation
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
case "ecdsa_secp256k1": return buildWalletSignerActivationSetV1({
|
|
290
|
+
manifest,
|
|
291
|
+
materialActivations: {
|
|
292
|
+
keyFamilies: ["ecdsa_secp256k1"],
|
|
293
|
+
ecdsa: facts.ecdsa.materialActivation
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
case "both": return buildWalletSignerActivationSetV1({
|
|
297
|
+
manifest,
|
|
298
|
+
materialActivations: {
|
|
299
|
+
keyFamilies: ["ed25519", "ecdsa_secp256k1"],
|
|
300
|
+
ed25519: facts.ed25519.materialActivation,
|
|
301
|
+
ecdsa: facts.ecdsa.materialActivation
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
default: return assertNeverFoundingSignerFacts(facts);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
async function buildActiveFoundingAuthority(input) {
|
|
308
|
+
const signerActivations = foundingSignerActivations(input.walletId, input.signerFacts);
|
|
309
|
+
const signerActivationSetDigestB64u = await computeWalletSignerActivationSetDigestB64u(signerActivations);
|
|
310
|
+
const permissions = buildFullOwnerPermissionsV1();
|
|
311
|
+
const draft = {
|
|
312
|
+
kind: "wallet_authority_v1",
|
|
313
|
+
authorityId: input.prepared.walletAuthorityId,
|
|
314
|
+
walletId: input.walletId,
|
|
315
|
+
principal: {
|
|
316
|
+
kind: "owner_device",
|
|
317
|
+
deviceId: input.prepared.deviceId
|
|
318
|
+
},
|
|
319
|
+
provenance: { kind: "wallet_registration" },
|
|
320
|
+
permissions,
|
|
321
|
+
signerActivations,
|
|
322
|
+
signerActivationSetDigestB64u,
|
|
323
|
+
authorityDigestB64u: signerActivationSetDigestB64u,
|
|
324
|
+
revocationEpoch: 0,
|
|
325
|
+
createdAtMs: input.now,
|
|
326
|
+
updatedAtMs: input.now,
|
|
327
|
+
state: "active",
|
|
328
|
+
activatedAtMs: input.now
|
|
329
|
+
};
|
|
330
|
+
const authorityDigestB64u = await computeWalletAuthorityDigestB64u(draft);
|
|
331
|
+
return buildActiveWalletAuthorityV1({
|
|
332
|
+
kind: "wallet_authority_v1",
|
|
333
|
+
authorityId: draft.authorityId,
|
|
334
|
+
walletId: draft.walletId,
|
|
335
|
+
principal: draft.principal,
|
|
336
|
+
provenance: draft.provenance,
|
|
337
|
+
permissions: draft.permissions,
|
|
338
|
+
signerActivations: draft.signerActivations,
|
|
339
|
+
signerActivationSetDigestB64u: draft.signerActivationSetDigestB64u,
|
|
340
|
+
authorityDigestB64u,
|
|
341
|
+
revocationEpoch: draft.revocationEpoch,
|
|
342
|
+
createdAtMs: draft.createdAtMs,
|
|
343
|
+
updatedAtMs: draft.updatedAtMs,
|
|
344
|
+
state: draft.state,
|
|
345
|
+
activatedAtMs: draft.activatedAtMs
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
async function extendFoundingAuthorityWithEd25519(input) {
|
|
349
|
+
const existingEcdsa = input.authority.signerActivations.ecdsa;
|
|
350
|
+
const signerActivationsCandidate = buildWalletSignerActivationSetV1({
|
|
351
|
+
manifest: buildExactAdministeredSignerManifestV1([foundingEd25519SignerIdentity(input.authority.walletId, input.ed25519), existingEcdsa.signer]),
|
|
352
|
+
materialActivations: {
|
|
353
|
+
keyFamilies: ["ed25519", "ecdsa_secp256k1"],
|
|
354
|
+
ed25519: input.ed25519.materialActivation,
|
|
355
|
+
ecdsa: existingEcdsa.materialActivation
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
if (!isCombinedWalletSignerActivationSetV1(signerActivationsCandidate)) throw new Error("Deferred Ed25519 activation did not produce a combined signer activation set");
|
|
359
|
+
const signerActivations = signerActivationsCandidate;
|
|
360
|
+
const signerActivationSetDigestB64u = await computeWalletSignerActivationSetDigestB64u(signerActivations);
|
|
361
|
+
const draft = {
|
|
362
|
+
kind: "wallet_authority_v1",
|
|
363
|
+
authorityId: input.authority.authorityId,
|
|
364
|
+
walletId: input.authority.walletId,
|
|
365
|
+
principal: input.authority.principal,
|
|
366
|
+
provenance: input.authority.provenance,
|
|
367
|
+
permissions: input.authority.permissions,
|
|
368
|
+
signerActivations,
|
|
369
|
+
signerActivationSetDigestB64u,
|
|
370
|
+
authorityDigestB64u: input.authority.authorityDigestB64u,
|
|
371
|
+
revocationEpoch: input.authority.revocationEpoch,
|
|
372
|
+
createdAtMs: input.authority.createdAtMs,
|
|
373
|
+
updatedAtMs: Math.max(input.authority.updatedAtMs, input.now),
|
|
374
|
+
state: "active",
|
|
375
|
+
activatedAtMs: input.authority.activatedAtMs
|
|
376
|
+
};
|
|
377
|
+
return buildActiveCombinedWalletAuthorityV1({
|
|
378
|
+
kind: draft.kind,
|
|
379
|
+
authorityId: draft.authorityId,
|
|
380
|
+
walletId: draft.walletId,
|
|
381
|
+
principal: draft.principal,
|
|
382
|
+
provenance: draft.provenance,
|
|
383
|
+
permissions: draft.permissions,
|
|
384
|
+
signerActivations: draft.signerActivations,
|
|
385
|
+
signerActivationSetDigestB64u: draft.signerActivationSetDigestB64u,
|
|
386
|
+
authorityDigestB64u: await computeWalletAuthorityDigestB64u(draft),
|
|
387
|
+
revocationEpoch: draft.revocationEpoch,
|
|
388
|
+
createdAtMs: draft.createdAtMs,
|
|
389
|
+
updatedAtMs: draft.updatedAtMs,
|
|
390
|
+
state: draft.state,
|
|
391
|
+
activatedAtMs: draft.activatedAtMs
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
function buildActiveFoundingAuthMethod(input) {
|
|
395
|
+
switch (input.authority.kind) {
|
|
396
|
+
case "passkey": return requireActiveFoundingAuthMethod(buildWalletAuthMethodRecordV2({
|
|
397
|
+
version: "wallet_auth_method_v2",
|
|
398
|
+
walletAuthMethodId: input.prepared.walletAuthMethodId,
|
|
399
|
+
walletId: input.authority.walletId,
|
|
400
|
+
walletAuthorityId: input.prepared.walletAuthorityId,
|
|
401
|
+
kind: "passkey",
|
|
402
|
+
status: "active",
|
|
403
|
+
rpId: input.authority.rpId,
|
|
404
|
+
credentialIdB64u: requirePreparedRegistrationId(parseWebAuthnCredentialIdB64u(input.authority.credentialIdB64u), "registration credentialIdB64u"),
|
|
405
|
+
credentialPublicKeyB64u: input.authority.credentialPublicKeyB64u,
|
|
406
|
+
counter: input.authority.counter,
|
|
407
|
+
createdAtMs: input.now,
|
|
408
|
+
updatedAtMs: input.now,
|
|
409
|
+
activatedAtMs: input.now
|
|
410
|
+
}));
|
|
411
|
+
case "email_otp": return requireActiveFoundingAuthMethod(buildWalletAuthMethodRecordV2({
|
|
412
|
+
version: "wallet_auth_method_v2",
|
|
413
|
+
walletAuthMethodId: input.prepared.walletAuthMethodId,
|
|
414
|
+
walletId: input.authority.walletId,
|
|
415
|
+
walletAuthorityId: input.prepared.walletAuthorityId,
|
|
416
|
+
kind: "email_otp",
|
|
417
|
+
status: "active",
|
|
418
|
+
emailHashHex: input.authority.emailHashHex,
|
|
419
|
+
registrationAuthorityId: input.authority.registrationAuthorityId,
|
|
420
|
+
createdAtMs: input.now,
|
|
421
|
+
updatedAtMs: input.now,
|
|
422
|
+
activatedAtMs: input.now
|
|
423
|
+
}));
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
function requireActiveFoundingAuthMethod(record) {
|
|
427
|
+
if (record.status !== "active") throw new Error("Founding wallet auth method must be active");
|
|
428
|
+
return record;
|
|
429
|
+
}
|
|
430
|
+
async function buildFoundingAuthorityRecords(input) {
|
|
431
|
+
return {
|
|
432
|
+
authority: await buildActiveFoundingAuthority({
|
|
433
|
+
walletId: input.walletId,
|
|
434
|
+
prepared: input.prepared,
|
|
435
|
+
signerFacts: input.signerFacts,
|
|
436
|
+
now: input.now
|
|
437
|
+
}),
|
|
438
|
+
authMethod: buildActiveFoundingAuthMethod({
|
|
439
|
+
authority: input.authority,
|
|
440
|
+
prepared: input.prepared,
|
|
441
|
+
now: input.now
|
|
442
|
+
})
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
function assertNeverFoundingSignerFacts(value) {
|
|
446
|
+
throw new Error(`Unsupported founding signer facts: ${String(value)}`);
|
|
447
|
+
}
|
|
448
|
+
function registrationFinalizeCeremonyFromStored(ceremony) {
|
|
449
|
+
if (ceremony.signerState.kind !== "signer_set_registration") throw new Error("signer-set registration state is required");
|
|
450
|
+
return {
|
|
451
|
+
registrationCeremonyId: ceremony.registrationCeremonyId,
|
|
452
|
+
intent: { walletId: ceremony.intent.walletId },
|
|
453
|
+
signerPlan: ceremony.signerPlan,
|
|
454
|
+
preparedContext: ceremony.preparedContext,
|
|
455
|
+
orgId: ceremony.orgId,
|
|
456
|
+
expiresAtMs: ceremony.expiresAtMs,
|
|
457
|
+
authorityState: ceremony.authorityState,
|
|
458
|
+
signerState: ceremony.signerState
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
function setupPolicyMatchesPreparedContext(policy, preparedContext) {
|
|
462
|
+
switch (policy.kind) {
|
|
463
|
+
case "runtime_policy_scope": return preparedContext.runtimePolicy.kind === "runtime_policy_scope" && preparedContext.runtimePolicy.scope.orgId === policy.scope.orgId && preparedContext.runtimePolicy.scope.projectId === policy.scope.projectId && preparedContext.runtimePolicy.scope.envId === policy.scope.envId && preparedContext.runtimePolicy.scope.signingRootVersion === policy.scope.signingRootVersion;
|
|
464
|
+
case "signing_root_only": return preparedContext.runtimePolicy.kind === "signing_root_only";
|
|
465
|
+
default: return assertNeverRegistrationSetupPolicy(policy);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
function assertNeverRegistrationSetupPolicy(value) {
|
|
469
|
+
throw new Error(`Unsupported registration setup policy: ${String(value)}`);
|
|
470
|
+
}
|
|
471
|
+
function registrationFinalizeRecoveryFromCommittedInstallation(input) {
|
|
472
|
+
const walletId = parseWalletIdForIntent(input.setupClaims.walletId);
|
|
473
|
+
if (!walletId) throw new Error("signed registration setup claims contain an invalid wallet identity");
|
|
474
|
+
const branches = registrationSignerBranchesFromPlan(input.projection.signerPlan);
|
|
475
|
+
if (!branches.nearEd25519 || !branches.evmFamilyEcdsa) throw new Error("committed registration installation is not a mixed signer plan");
|
|
476
|
+
if (input.setupClaims.registrationCeremonyId !== input.projection.registrationCeremonyId || input.setupClaims.walletId !== String(input.projection.walletId) || walletId !== input.projection.walletId || input.setupClaims.orgId !== input.projection.orgId || input.setupClaims.signingRootId !== input.projection.preparedContext.signingRootId || input.setupClaims.signingRootVersion !== input.projection.preparedContext.signingRootVersion || !setupPolicyMatchesPreparedContext(input.setupClaims.policy, input.projection.preparedContext) || input.projection.registrationAuthority.walletId !== input.projection.walletId) throw new Error("committed registration installation does not match signed setup claims");
|
|
477
|
+
return {
|
|
478
|
+
kind: "committed_mixed_installation",
|
|
479
|
+
ceremony: {
|
|
480
|
+
registrationCeremonyId: input.setupClaims.registrationCeremonyId,
|
|
481
|
+
intent: { walletId },
|
|
482
|
+
signerPlan: input.projection.signerPlan,
|
|
483
|
+
preparedContext: input.projection.preparedContext,
|
|
484
|
+
orgId: input.projection.orgId,
|
|
485
|
+
expiresAtMs: input.setupClaims.expiresAtMs,
|
|
486
|
+
authorityState: {
|
|
487
|
+
kind: "verified",
|
|
488
|
+
authority: input.projection.registrationAuthority
|
|
489
|
+
},
|
|
490
|
+
signerState: {
|
|
491
|
+
kind: "signer_set_registration",
|
|
492
|
+
branches: [input.projection.nearEd25519]
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
function isWalletRegistrationNearProvisioningSuccess(value) {
|
|
498
|
+
return value.ok && value.kind === "near_ed25519" && "registrationEstablishedSession" in value;
|
|
499
|
+
}
|
|
500
|
+
function assertNeverD1RegistrationSessionIssuance(value) {
|
|
501
|
+
throw new Error(`Unsupported registration Wallet Session issuance: ${String(value)}`);
|
|
502
|
+
}
|
|
503
|
+
function assertNeverD1RegistrationSideEffectRecord(value) {
|
|
504
|
+
throw new Error(`Unsupported registration side-effect record: ${String(value)}`);
|
|
505
|
+
}
|
|
506
|
+
function registrationEstablishedSessionResultFromIssuance(result) {
|
|
507
|
+
switch (result.kind) {
|
|
508
|
+
case "issued": return {
|
|
509
|
+
kind: "issued",
|
|
510
|
+
session: result.session
|
|
511
|
+
};
|
|
512
|
+
case "already_committed": return {
|
|
513
|
+
kind: "already_committed",
|
|
514
|
+
session: result.session,
|
|
515
|
+
next: result.next
|
|
516
|
+
};
|
|
517
|
+
default: return assertNeverD1RegistrationSessionIssuance(result);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
const D1_WALLET_REGISTRATION_OPERATION_RESUME_AFTER_MS = 3e4;
|
|
521
|
+
const WALLET_REGISTRATION_ROUTER_POLICY_VERSION = "wallet-registration-v1";
|
|
522
|
+
function requireWalletSessionMintId(value) {
|
|
523
|
+
const parsed = parseWalletSessionMintId(value);
|
|
524
|
+
if (!parsed.ok) throw new Error(`Wallet Session mint identity is invalid: ${parsed.error.message}`);
|
|
525
|
+
return parsed.value;
|
|
526
|
+
}
|
|
527
|
+
function assertNeverEd25519WalletSessionIssue(value) {
|
|
528
|
+
throw new Error(`Unsupported Ed25519 Yao Wallet Session issuance: ${String(value)}`);
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* A committed mint has no reachable credential, so the caller is told to
|
|
532
|
+
* unlock the exact auth method rather than being handed a second bearer for
|
|
533
|
+
* the same session.
|
|
534
|
+
*/
|
|
535
|
+
function ed25519AlreadyCommittedWalletSessionResponse(committed) {
|
|
536
|
+
return {
|
|
537
|
+
ok: false,
|
|
538
|
+
code: "already_committed",
|
|
539
|
+
message: "Ed25519 Wallet Session is already committed; unlock the exact auth method",
|
|
540
|
+
next: committed.next,
|
|
541
|
+
committed: {
|
|
542
|
+
kind: "already_committed_wallet_session_v1",
|
|
543
|
+
walletId: committed.walletId,
|
|
544
|
+
authorityId: committed.authorityId,
|
|
545
|
+
walletAuthMethodId: committed.walletAuthMethodId,
|
|
546
|
+
mintId: committed.mintId,
|
|
547
|
+
authorizationId: committed.authorizationId,
|
|
548
|
+
walletSessionId: committed.walletSessionId,
|
|
549
|
+
quotaId: committed.quotaId
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* The bearer issuer used to re-check the owner proof against the session
|
|
555
|
+
* binding it signed. Direct issuance writes no such binding, so the same claim
|
|
556
|
+
* is asserted here before the exact session is committed.
|
|
557
|
+
*/
|
|
558
|
+
function registrationWalletAuthAuthority(input) {
|
|
559
|
+
return walletAuthAuthorityFromRegistrationAuthority(input);
|
|
560
|
+
}
|
|
561
|
+
function errorMessage(error) {
|
|
562
|
+
return error instanceof Error ? error.message : String(error || "");
|
|
563
|
+
}
|
|
564
|
+
function assertNeverSponsoredNamedNearAccountCreationResult(value) {
|
|
565
|
+
throw new Error(`Unexpected sponsored NEAR account creation result: ${String(value)}`);
|
|
566
|
+
}
|
|
567
|
+
function isRegistrationEcdsaReadyReceipt(receipt) {
|
|
568
|
+
return receipt.committed.kind === "ecdsa_ready";
|
|
569
|
+
}
|
|
570
|
+
function isRegistrationNearPendingReceipt(receipt) {
|
|
571
|
+
return receipt.committed.kind === "near_pending";
|
|
572
|
+
}
|
|
573
|
+
function isRegistrationNearReadyReceipt(receipt) {
|
|
574
|
+
return receipt.committed.kind === "near_ready";
|
|
575
|
+
}
|
|
576
|
+
function assertNeverRegistrationReceiptCommit(value) {
|
|
577
|
+
throw new Error(`Unsupported registration receipt commit: ${String(value)}`);
|
|
578
|
+
}
|
|
579
|
+
async function cleanupFinalizedRegistrationCeremony(input) {
|
|
580
|
+
try {
|
|
581
|
+
await input.store.deleteCeremony(input.registrationCeremonyId);
|
|
582
|
+
} catch {}
|
|
583
|
+
}
|
|
584
|
+
function createD1RegistrationRouteTimingRecorder(route) {
|
|
585
|
+
return {
|
|
586
|
+
route,
|
|
587
|
+
entries: []
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
function startD1RegistrationRouteTiming(name) {
|
|
591
|
+
return {
|
|
592
|
+
name,
|
|
593
|
+
startedAtMs: Date.now()
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
function finishD1RegistrationRouteTiming(recorder, mark) {
|
|
597
|
+
recorder.entries.push({
|
|
598
|
+
name: mark.name,
|
|
599
|
+
durationMs: Math.max(0, Date.now() - mark.startedAtMs)
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
function d1RegistrationRouteDiagnostics(recorder) {
|
|
603
|
+
return {
|
|
604
|
+
kind: "wallet_registration_route_diagnostics_v1",
|
|
605
|
+
route: recorder.route,
|
|
606
|
+
entries: recorder.entries.map((entry) => ({
|
|
607
|
+
name: entry.name,
|
|
608
|
+
durationMs: entry.durationMs
|
|
609
|
+
}))
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
function withD1RegistrationRouteDiagnostics(response, recorder) {
|
|
613
|
+
if (!response.ok) return response;
|
|
614
|
+
return {
|
|
615
|
+
...response,
|
|
616
|
+
registrationDiagnostics: d1RegistrationRouteDiagnostics(recorder)
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
function normalizedKeyHandleSet(keyHandles) {
|
|
620
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
621
|
+
for (const keyHandle of keyHandles) {
|
|
622
|
+
const value = String(keyHandle || "").trim();
|
|
623
|
+
if (value) normalized.add(value);
|
|
624
|
+
}
|
|
625
|
+
return normalized;
|
|
626
|
+
}
|
|
627
|
+
function hasEcdsaKeyHandleSetMismatch(expectedKeyHandles, actualKeyHandles) {
|
|
628
|
+
if (expectedKeyHandles.length === 0) return false;
|
|
629
|
+
const expected = normalizedKeyHandleSet(expectedKeyHandles);
|
|
630
|
+
const actual = normalizedKeyHandleSet(actualKeyHandles);
|
|
631
|
+
if (expected.size !== actual.size) return true;
|
|
632
|
+
for (const keyHandle of expected) if (!actual.has(keyHandle)) return true;
|
|
633
|
+
return false;
|
|
634
|
+
}
|
|
635
|
+
function registrationIntentSignerBranches(intent) {
|
|
636
|
+
const plan = registrationSignerPlanFromSelection(intent.signerSelection);
|
|
637
|
+
if (!plan.ok) return plan;
|
|
638
|
+
return {
|
|
639
|
+
ok: true,
|
|
640
|
+
value: registrationSignerBranchesFromPlan(plan.value)
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
function registrationSignerBranchesFromPlan(plan) {
|
|
644
|
+
return {
|
|
645
|
+
plan,
|
|
646
|
+
nearEd25519: findRegistrationSignerPlanNearEd25519Branch(plan),
|
|
647
|
+
evmFamilyEcdsa: findRegistrationSignerPlanEvmFamilyEcdsaBranch(plan)
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
function resolveRegistrationPreparedContextFromPlan(input) {
|
|
651
|
+
const branches = registrationSignerBranchesFromPlan(input.signerPlan);
|
|
652
|
+
const ecdsaChainTargets = branches.evmFamilyEcdsa ? normalizeThresholdEcdsaChainTargets(branches.evmFamilyEcdsa.chainTargets) : null;
|
|
653
|
+
if (branches.evmFamilyEcdsa && !ecdsaChainTargets) return {
|
|
654
|
+
ok: false,
|
|
655
|
+
code: "invalid_body",
|
|
656
|
+
message: "ECDSA registration contains an invalid chain target"
|
|
657
|
+
};
|
|
658
|
+
try {
|
|
659
|
+
return {
|
|
660
|
+
ok: true,
|
|
661
|
+
preparedContext: buildStoredWalletRegistrationPreparedContext({
|
|
662
|
+
signingRootId: input.signingRootId,
|
|
663
|
+
signingRootVersion: input.signingRootVersion,
|
|
664
|
+
runtimePolicyScope: input.runtimePolicyScope || null,
|
|
665
|
+
ecdsaChainTargets
|
|
666
|
+
}),
|
|
667
|
+
ecdsaChainTargets
|
|
668
|
+
};
|
|
669
|
+
} catch (error) {
|
|
670
|
+
return {
|
|
671
|
+
ok: false,
|
|
672
|
+
code: "invalid_body",
|
|
673
|
+
message: errorMessage(error) || "registration prepared context is invalid"
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
function registrationPreparedContextRuntimePolicyScope(preparedContext) {
|
|
678
|
+
return preparedContext.runtimePolicy.kind === "runtime_policy_scope" ? preparedContext.runtimePolicy.scope : void 0;
|
|
679
|
+
}
|
|
680
|
+
function registrationTenantRootIdentity(preparedContext) {
|
|
681
|
+
const scope = registrationPreparedContextRuntimePolicyScope(preparedContext);
|
|
682
|
+
if (!scope) return null;
|
|
683
|
+
const identity = buildTenantRootIdentityFromAuthenticatedDeploymentV1({
|
|
684
|
+
orgId: scope.orgId,
|
|
685
|
+
projectId: scope.projectId,
|
|
686
|
+
envId: scope.envId,
|
|
687
|
+
signingRootId: preparedContext.signingRootId,
|
|
688
|
+
signingRootVersion: preparedContext.signingRootVersion
|
|
689
|
+
});
|
|
690
|
+
return identity.ok ? identity.value : null;
|
|
691
|
+
}
|
|
692
|
+
function registrationPreparedContextEcdsaChainTargets(preparedContext) {
|
|
693
|
+
return preparedContext.ecdsa.kind === "evm_family_ecdsa_requested" ? preparedContext.ecdsa.chainTargets : null;
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* A verified authority must name the same wallet the intent does. A ceremony
|
|
697
|
+
* still awaiting its proof has no authority to disagree with, so it matches
|
|
698
|
+
* vacuously — respond performs this check again once the proof binds.
|
|
699
|
+
*/
|
|
700
|
+
function registrationCeremonyWalletsMatch(input) {
|
|
701
|
+
const authority = verifiedRegistrationCeremonyAuthority(input.ceremony);
|
|
702
|
+
if (!authority) return true;
|
|
703
|
+
return authority.walletId === input.ceremony.intent.walletId;
|
|
704
|
+
}
|
|
705
|
+
function resolvedRegistrationNearAccount(input) {
|
|
706
|
+
const nearEd25519SigningKeyId = nearEd25519SigningKeyIdFromString(input.nearEd25519SigningKeyId);
|
|
707
|
+
switch (input.accountProvisioning.kind) {
|
|
708
|
+
case "implicit_account": {
|
|
709
|
+
const parsed = parseImplicitNearAccountId(input.nearAccountId);
|
|
710
|
+
if (!parsed.ok) return {
|
|
711
|
+
ok: false,
|
|
712
|
+
code: "internal",
|
|
713
|
+
message: parsed.message
|
|
714
|
+
};
|
|
715
|
+
return {
|
|
716
|
+
ok: true,
|
|
717
|
+
value: {
|
|
718
|
+
kind: "implicit_account",
|
|
719
|
+
nearAccountId: parsed.value,
|
|
720
|
+
nearEd25519SigningKeyId
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
case "sponsored_named_account": {
|
|
725
|
+
const parsed = parseNamedNearAccountId(input.nearAccountId);
|
|
726
|
+
if (!parsed.ok) return {
|
|
727
|
+
ok: false,
|
|
728
|
+
code: "internal",
|
|
729
|
+
message: parsed.message
|
|
730
|
+
};
|
|
731
|
+
const transactionHash = normalizeOptionalTrimmedString(input.sponsoredTransactionHash);
|
|
732
|
+
if (!transactionHash) return {
|
|
733
|
+
ok: false,
|
|
734
|
+
code: "internal",
|
|
735
|
+
message: "Sponsored named registration missing account creation transaction hash"
|
|
736
|
+
};
|
|
737
|
+
return {
|
|
738
|
+
ok: true,
|
|
739
|
+
value: {
|
|
740
|
+
kind: "sponsored_named_account",
|
|
741
|
+
nearAccountId: parsed.value,
|
|
742
|
+
nearEd25519SigningKeyId,
|
|
743
|
+
transactionHash
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
function sponsoredNamedRegistrationAccountId(provisioning) {
|
|
750
|
+
switch (provisioning.kind) {
|
|
751
|
+
case "implicit_account": return null;
|
|
752
|
+
case "sponsored_named_account": return String(provisioning.requestedAccountId);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* A mixed plan finalizes in two calls: `evm_family_ecdsa` first, which returns
|
|
757
|
+
* the wallet ECDSA-ready and leaves the ceremony open, then `near_ed25519`
|
|
758
|
+
* once the Yao ceremony settles (Refactor 94 Phase 4+5). Single-signer plans
|
|
759
|
+
* still finalize in one call.
|
|
760
|
+
*
|
|
761
|
+
* The requested kind must name only branches the plan admitted, and must be
|
|
762
|
+
* legal for the progress those branches have made — a `near_ed25519` call on a
|
|
763
|
+
* mixed plan before the ECDSA commit is durable would return a NEAR-ready
|
|
764
|
+
* wallet whose ECDSA signer does not exist.
|
|
765
|
+
*/
|
|
766
|
+
function finalizeSignerWorkSequenceFailure(input) {
|
|
767
|
+
switch (input.request.kind) {
|
|
768
|
+
case "near_ed25519":
|
|
769
|
+
if (!input.hasNearEd25519) return {
|
|
770
|
+
code: "invalid_body",
|
|
771
|
+
message: "registration plan has no Ed25519 signer to finalize"
|
|
772
|
+
};
|
|
773
|
+
if (input.hasEvmFamilyEcdsa && !input.ecdsaFinalized) return {
|
|
774
|
+
code: "invalid_state",
|
|
775
|
+
message: "ECDSA finalize must complete before the Ed25519 finalize"
|
|
776
|
+
};
|
|
777
|
+
return null;
|
|
778
|
+
case "evm_family_ecdsa":
|
|
779
|
+
if (!input.hasEvmFamilyEcdsa) return {
|
|
780
|
+
code: "invalid_body",
|
|
781
|
+
message: "registration plan has no ECDSA signer to finalize"
|
|
782
|
+
};
|
|
783
|
+
if (input.ecdsaFinalized) return {
|
|
784
|
+
code: "invalid_state",
|
|
785
|
+
message: "ECDSA finalize has already completed for this ceremony"
|
|
786
|
+
};
|
|
787
|
+
return null;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
function finalizePasskeyRpId(authority) {
|
|
791
|
+
if (authority.kind !== "passkey") throw new Error("passkey finalize auth method requires a passkey registration authority");
|
|
792
|
+
return authority.rpId;
|
|
793
|
+
}
|
|
794
|
+
function ecdsaStrictRegistrationAuthority(facts) {
|
|
795
|
+
return {
|
|
796
|
+
subjectId: facts.client_id,
|
|
797
|
+
sessionId: facts.lifecycle.session_id,
|
|
798
|
+
accountId: facts.lifecycle.account_id,
|
|
799
|
+
expiresAtMs: facts.expires_at_ms
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
function exactEcdsaParticipantPair(participantIds) {
|
|
803
|
+
if (participantIds.length !== 2 || participantIds[0] !== 1 || participantIds[1] !== 2) throw new Error("ECDSA registration requires participant pair [1, 2]");
|
|
804
|
+
return [1, 2];
|
|
805
|
+
}
|
|
806
|
+
function ethereumAddressHexFromBase64Url(value) {
|
|
807
|
+
const bytes = base64UrlDecode(value);
|
|
808
|
+
if (bytes.length !== 20) throw new Error("ECDSA activation Ethereum address must contain 20 bytes");
|
|
809
|
+
let hex = "0x";
|
|
810
|
+
for (const byte of bytes) hex += byte.toString(16).padStart(2, "0");
|
|
811
|
+
return hex;
|
|
812
|
+
}
|
|
813
|
+
function requireActivatedEcdsaIdentity(input) {
|
|
814
|
+
const registration = input.branch.strictRegistration;
|
|
815
|
+
const receipt = input.activation.ecdsa_activation;
|
|
816
|
+
const identity = receipt.public_identity;
|
|
817
|
+
if (receipt.context.application_binding_digest_b64u !== registration.context.application_binding_digest_b64u || identity.context_binding_b64u !== input.publicFacts.contextBinding32B64u || identity.derivation_client_share_public_key33_b64u !== input.publicFacts.derivationClientSharePublicKey33B64u || identity.client_share_retry_counter !== input.publicFacts.clientShareRetryCounter || input.activation.lifecycle_id !== registration.lifecycle.lifecycle_id || base64UrlEncode(Uint8Array.from(input.activation.transcript_digest.bytes)) !== input.publicFacts.proofTranscriptDigestB64u || receipt.signing_worker.server_id !== registration.lifecycle.selected_server_id) throw new Error("ECDSA activation receipt does not match the admitted registration identity");
|
|
818
|
+
}
|
|
819
|
+
async function buildActivatedEcdsaFamilyBootstrap(input) {
|
|
820
|
+
requireActivatedEcdsaIdentity(input);
|
|
821
|
+
const prepare = input.branch.prepare;
|
|
822
|
+
const identity = input.activation.ecdsa_activation.public_identity;
|
|
823
|
+
const expiresAtMs = input.branch.strictRegistration.expires_at_ms;
|
|
824
|
+
const ethereumAddress = ethereumAddressHexFromBase64Url(identity.ethereum_address20_b64u);
|
|
825
|
+
const publicIdentity = parseEcdsaDerivationPublicIdentity({
|
|
826
|
+
derivationClientSharePublicKey33B64u: input.publicFacts.derivationClientSharePublicKey33B64u,
|
|
827
|
+
relayerPublicKey33B64u: identity.server_public_key33_b64u,
|
|
828
|
+
groupPublicKey33B64u: identity.threshold_public_key33_b64u,
|
|
829
|
+
ethereumAddress
|
|
830
|
+
});
|
|
831
|
+
if (!publicIdentity) throw new Error("ECDSA activation receipt contains an invalid public identity");
|
|
832
|
+
const keyHandle = await deriveThresholdEcdsaKeyHandle({
|
|
833
|
+
ecdsaThresholdKeyId: prepare.ecdsaThresholdKeyId,
|
|
834
|
+
signingRootId: prepare.signingRootId,
|
|
835
|
+
signingRootVersion: prepare.signingRootVersion
|
|
836
|
+
});
|
|
837
|
+
const routerAbEcdsaDerivationNormalSigning = parseRouterAbEcdsaDerivationNormalSigningStateV1({
|
|
838
|
+
kind: ROUTER_AB_ECDSA_DERIVATION_NORMAL_SIGNING_STATE_KIND_V1,
|
|
839
|
+
scope: {
|
|
840
|
+
wallet_id: String(prepare.walletId),
|
|
841
|
+
ecdsa_threshold_key_id: prepare.ecdsaThresholdKeyId,
|
|
842
|
+
signing_root_id: prepare.signingRootId,
|
|
843
|
+
signing_root_version: prepare.signingRootVersion,
|
|
844
|
+
context: { application_binding_digest_b64u: input.branch.strictRegistration.context.application_binding_digest_b64u },
|
|
845
|
+
public_identity: {
|
|
846
|
+
context_binding_b64u: input.publicFacts.contextBinding32B64u,
|
|
847
|
+
derivation_client_share_public_key33_b64u: input.publicFacts.derivationClientSharePublicKey33B64u,
|
|
848
|
+
server_public_key33_b64u: identity.server_public_key33_b64u,
|
|
849
|
+
threshold_public_key33_b64u: identity.threshold_public_key33_b64u,
|
|
850
|
+
ethereum_address20_b64u: base64UrlEncode(Uint8Array.from(ethereumAddress.slice(2).match(/.{2}/g)?.map((byte) => Number.parseInt(byte, 16)) ?? [])),
|
|
851
|
+
client_share_retry_counter: input.publicFacts.clientShareRetryCounter,
|
|
852
|
+
server_share_retry_counter: identity.server_share_retry_counter
|
|
853
|
+
},
|
|
854
|
+
signing_worker: input.activation.ecdsa_activation.signing_worker,
|
|
855
|
+
material_activation: input.activation.ecdsa_activation.material_activation,
|
|
856
|
+
activation_epoch: input.activation.ecdsa_activation.activation_epoch
|
|
857
|
+
}
|
|
858
|
+
});
|
|
859
|
+
if (!routerAbEcdsaDerivationNormalSigning) throw new Error("ECDSA activation produced invalid normal-signing state");
|
|
860
|
+
return {
|
|
861
|
+
formatVersion: "ecdsa-derivation-role-local",
|
|
862
|
+
walletId: String(prepare.walletId),
|
|
863
|
+
evmFamilySigningKeySlotId: prepare.evmFamilySigningKeySlotId,
|
|
864
|
+
ecdsaThresholdKeyId: prepare.ecdsaThresholdKeyId,
|
|
865
|
+
relayerKeyId: prepare.relayerKeyId,
|
|
866
|
+
applicationBindingDigestB64u: input.branch.strictRegistration.context.application_binding_digest_b64u,
|
|
867
|
+
contextBinding32B64u: input.publicFacts.contextBinding32B64u,
|
|
868
|
+
publicIdentity,
|
|
869
|
+
clientShareRetryCounter: input.publicFacts.clientShareRetryCounter,
|
|
870
|
+
relayerShareRetryCounter: identity.server_share_retry_counter,
|
|
871
|
+
publicTranscriptDigest32B64u: input.publicFacts.proofTranscriptDigestB64u,
|
|
872
|
+
keyHandle,
|
|
873
|
+
signingRootId: prepare.signingRootId,
|
|
874
|
+
signingRootVersion: prepare.signingRootVersion,
|
|
875
|
+
thresholdEcdsaPublicKeyB64u: identity.threshold_public_key33_b64u,
|
|
876
|
+
ethereumAddress,
|
|
877
|
+
relayerVerifyingShareB64u: identity.server_public_key33_b64u,
|
|
878
|
+
participantIds: [...exactEcdsaParticipantPair(prepare.participantIds)],
|
|
879
|
+
thresholdSessionId: buildRouterAbEcdsaDerivationActiveStateIdV1({
|
|
880
|
+
ecdsaThresholdKeyId: prepare.ecdsaThresholdKeyId,
|
|
881
|
+
signingRootId: prepare.signingRootId,
|
|
882
|
+
signingRootVersion: prepare.signingRootVersion,
|
|
883
|
+
activationEpoch: input.activation.ecdsa_activation.activation_epoch
|
|
884
|
+
}),
|
|
885
|
+
activationEpoch: input.activation.ecdsa_activation.activation_epoch,
|
|
886
|
+
expiresAtMs,
|
|
887
|
+
expiresAt: new Date(expiresAtMs).toISOString(),
|
|
888
|
+
remainingUses: prepare.remainingUses,
|
|
889
|
+
routerAbEcdsaDerivationNormalSigning
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
function postRegistrationProofResponse(input) {
|
|
893
|
+
return input.response.response;
|
|
894
|
+
}
|
|
895
|
+
function postRegistrationProofMatchesRequest(input) {
|
|
896
|
+
const response = postRegistrationProofResponse(input);
|
|
897
|
+
return response.bundles.signerA.transcriptDigestB64u === response.bundles.signerB.transcriptDigestB64u;
|
|
898
|
+
}
|
|
899
|
+
function postRegistrationRequestId(input) {
|
|
900
|
+
return input.request.refresh_nonce;
|
|
901
|
+
}
|
|
902
|
+
function pendingEcdsaSessionActivationRecord(input) {
|
|
903
|
+
postRegistrationProofResponse(input.proof);
|
|
904
|
+
return {
|
|
905
|
+
version: "wallet_ecdsa_pending_session_activation_v1",
|
|
906
|
+
walletId: input.walletId,
|
|
907
|
+
lifecycleId: input.proof.request.lifecycle.lifecycle_id,
|
|
908
|
+
requestId: postRegistrationRequestId(input.proof),
|
|
909
|
+
publicCapability: input.publicCapability,
|
|
910
|
+
createdAtMs: input.nowMs,
|
|
911
|
+
expiresAtMs: input.proof.request.expires_at_ms,
|
|
912
|
+
operation: "refresh",
|
|
913
|
+
request: input.proof.request,
|
|
914
|
+
response: input.proof.response
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
function buildPostRegistrationEcdsaNormalSigningState(input) {
|
|
918
|
+
const capability = input.publicCapability;
|
|
919
|
+
const state = parseRouterAbEcdsaDerivationNormalSigningStateV1({
|
|
920
|
+
kind: ROUTER_AB_ECDSA_DERIVATION_NORMAL_SIGNING_STATE_KIND_V1,
|
|
921
|
+
scope: {
|
|
922
|
+
wallet_id: input.walletKey.walletId,
|
|
923
|
+
ecdsa_threshold_key_id: input.walletKey.ecdsaThresholdKeyId,
|
|
924
|
+
signing_root_id: input.walletKey.signingRootId,
|
|
925
|
+
signing_root_version: input.walletKey.signingRootVersion,
|
|
926
|
+
context: capability.context,
|
|
927
|
+
public_identity: capability.public_identity,
|
|
928
|
+
material_activation: capability.material_activation,
|
|
929
|
+
signing_worker: capability.signer_set.selected_server,
|
|
930
|
+
activation_epoch: capability.activation_epoch
|
|
931
|
+
}
|
|
932
|
+
});
|
|
933
|
+
if (!state) throw new Error("registered ECDSA normal-signing state is invalid");
|
|
934
|
+
return state;
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Upper bound on Router metrics folded into one Gateway header. The Router is
|
|
938
|
+
* ours, but a merged header grows at every hop, so the fold is bounded rather
|
|
939
|
+
* than trusting the peer to stay terse.
|
|
940
|
+
*/
|
|
941
|
+
const ROUTER_SERVER_TIMING_MERGE_LIMIT = 32;
|
|
942
|
+
/** Metric names the Gateway is willing to re-emit in its own header. */
|
|
943
|
+
const ROUTER_SERVER_TIMING_NAME_PATTERN = /^[A-Za-z0-9_-]+$/;
|
|
944
|
+
/**
|
|
945
|
+
* Folds the Router's own `Server-Timing` header into the Gateway's span list
|
|
946
|
+
* (Refactor 94B Phase 0), so the Router and role-worker breakdown reaches the
|
|
947
|
+
* browser on the same header as the Gateway's own boundaries.
|
|
948
|
+
*
|
|
949
|
+
* Entries without a finite non-negative `dur` are dropped, which also discards
|
|
950
|
+
* Cloudflare's descriptive metrics, and names are restricted to a token
|
|
951
|
+
* charset so a metric name can never forge extra entries downstream.
|
|
952
|
+
*/
|
|
953
|
+
function mergeRouterServerTiming(target, header) {
|
|
954
|
+
let merged = 0;
|
|
955
|
+
for (const entry of header.split(",")) {
|
|
956
|
+
if (merged >= ROUTER_SERVER_TIMING_MERGE_LIMIT) return;
|
|
957
|
+
const parts = entry.split(";");
|
|
958
|
+
const name = String(parts[0] || "").trim();
|
|
959
|
+
if (!ROUTER_SERVER_TIMING_NAME_PATTERN.test(name)) continue;
|
|
960
|
+
for (const part of parts.slice(1)) {
|
|
961
|
+
const [key, rawValue] = part.split("=");
|
|
962
|
+
if (String(key || "").trim() !== "dur") continue;
|
|
963
|
+
const duration = Number(String(rawValue || "").trim());
|
|
964
|
+
if (!Number.isFinite(duration) || duration < 0) break;
|
|
965
|
+
target.push([name, duration]);
|
|
966
|
+
merged += 1;
|
|
967
|
+
break;
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
var CloudflareD1WalletRegistrationService = class {
|
|
972
|
+
constructor(input) {
|
|
973
|
+
this.authorizationService = input.authorizationService;
|
|
974
|
+
this.authorizationTenantId = input.authorizationTenantId;
|
|
975
|
+
this.createSponsoredNamedNearAccount = input.createSponsoredNamedNearAccount;
|
|
976
|
+
this.emailOtpRegistrationEnrollmentFinalizer = input.emailOtpRegistrationEnrollmentFinalizer;
|
|
977
|
+
this.getRegistrationCeremonyIntentStore = input.getRegistrationCeremonyIntentStore;
|
|
978
|
+
this.getEd25519YaoProductRegistration = input.getEd25519YaoProductRegistration;
|
|
979
|
+
this.ecdsaStrictRegistration = input.ecdsaStrictRegistration;
|
|
980
|
+
this.tenantRootCustodyLineage = input.tenantRootCustodyLineage;
|
|
981
|
+
this.getWalletStore = input.getWalletStore;
|
|
982
|
+
this.activateSideEffects = input.activateSideEffects;
|
|
983
|
+
this.nearProvisioningSideEffects = input.nearProvisioningSideEffects;
|
|
984
|
+
this.walletRegistrationCommitStore = input.walletRegistrationCommitStore;
|
|
985
|
+
this.walletCustodyCommitStore = input.walletCustodyCommitStore;
|
|
986
|
+
this.walletAuthMethods = input.walletAuthMethods;
|
|
987
|
+
this.getLinkedDeviceEd25519AuthorityReader = input.getLinkedDeviceEd25519AuthorityReader;
|
|
988
|
+
}
|
|
989
|
+
async getWalletRegistrationRuntimePolicyScope(registrationCeremonyId) {
|
|
990
|
+
const ceremony = await this.getRegistrationCeremonyIntentStore().getCeremony(registrationCeremonyId);
|
|
991
|
+
if (!ceremony) return void 0;
|
|
992
|
+
return registrationPreparedContextRuntimePolicyScope(ceremony.preparedContext);
|
|
993
|
+
}
|
|
994
|
+
async resolveEd25519MaterialActivation(input) {
|
|
995
|
+
try {
|
|
996
|
+
const walletId = walletIdFromString(input.walletId);
|
|
997
|
+
const signer = await this.getWalletStore().getEd25519SignerByMaterialActivation({
|
|
998
|
+
walletId,
|
|
999
|
+
materialActivation: input.materialActivation
|
|
1000
|
+
});
|
|
1001
|
+
const yaoRuntime = this.getEd25519YaoProductRegistration();
|
|
1002
|
+
if (!yaoRuntime) return {
|
|
1003
|
+
ok: false,
|
|
1004
|
+
code: "internal",
|
|
1005
|
+
message: "Ed25519 Yao capability resolver is not configured"
|
|
1006
|
+
};
|
|
1007
|
+
if (!signer) {
|
|
1008
|
+
const linkedDeviceReader = this.getLinkedDeviceEd25519AuthorityReader();
|
|
1009
|
+
const projection = linkedDeviceReader ? await linkedDeviceReader.readInstalledEd25519AuthorityByMaterialActivationV1({
|
|
1010
|
+
walletId,
|
|
1011
|
+
materialActivation: routerAbMpcMaterialActivationRefFromWire(input.materialActivation)
|
|
1012
|
+
}) : null;
|
|
1013
|
+
if (!projection) return {
|
|
1014
|
+
ok: false,
|
|
1015
|
+
code: "not_found",
|
|
1016
|
+
message: "Ed25519 material activation is not active for this wallet"
|
|
1017
|
+
};
|
|
1018
|
+
const projectionMaterialActivation = linkedEd25519ProjectionMaterialActivationWire(projection);
|
|
1019
|
+
if (projection.walletId !== walletId || !sameRouterAbMpcMaterialActivationRef(projectionMaterialActivation, input.materialActivation)) return {
|
|
1020
|
+
ok: false,
|
|
1021
|
+
code: "not_found",
|
|
1022
|
+
message: "Linked Ed25519 material activation does not match its installation"
|
|
1023
|
+
};
|
|
1024
|
+
const linkedSignerSlot = projection.applicationBinding.key_creation_signer_slot;
|
|
1025
|
+
const linkedSigningWorkerId = projection.targetBinding.lifecycle.selected_server_id;
|
|
1026
|
+
const active = await yaoRuntime.resolveActiveCapability({
|
|
1027
|
+
kind: "router_ab_ed25519_yao_active_capability_lookup_v1",
|
|
1028
|
+
walletId: input.walletId,
|
|
1029
|
+
nearEd25519SigningKeyId: projection.applicationBinding.near_ed25519_signing_key_id,
|
|
1030
|
+
signerSlot: linkedSignerSlot,
|
|
1031
|
+
signingWorkerId: linkedSigningWorkerId,
|
|
1032
|
+
participantIds: projection.participantIds
|
|
1033
|
+
});
|
|
1034
|
+
if (!active.ok) return {
|
|
1035
|
+
ok: false,
|
|
1036
|
+
code: active.code === "unknown_capability" ? "not_found" : "internal",
|
|
1037
|
+
message: active.message
|
|
1038
|
+
};
|
|
1039
|
+
if (!linkedEd25519ProjectionMatchesDescriptor({
|
|
1040
|
+
projection,
|
|
1041
|
+
descriptor: active.capability
|
|
1042
|
+
})) return {
|
|
1043
|
+
ok: false,
|
|
1044
|
+
code: "not_found",
|
|
1045
|
+
message: "Linked Ed25519 installation does not match the active signer identity"
|
|
1046
|
+
};
|
|
1047
|
+
return {
|
|
1048
|
+
ok: true,
|
|
1049
|
+
materialActivation: projectionMaterialActivation,
|
|
1050
|
+
nearAccountId: active.capability.nearAccountId,
|
|
1051
|
+
signerSlot: linkedSignerSlot,
|
|
1052
|
+
signingWorkerId: linkedSigningWorkerId,
|
|
1053
|
+
participantIds: projection.participantIds,
|
|
1054
|
+
runtimePolicyScope: active.capability.runtimePolicyScope,
|
|
1055
|
+
exportIdentity: await ed25519ExportIdentityFromLinkedProjection(projection, active.capability)
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
const active = await yaoRuntime.resolveActiveCapability({
|
|
1059
|
+
kind: "router_ab_ed25519_yao_active_capability_lookup_v1",
|
|
1060
|
+
walletId: input.walletId,
|
|
1061
|
+
nearEd25519SigningKeyId: signer.nearEd25519SigningKeyId,
|
|
1062
|
+
signerSlot: signer.signerSlot,
|
|
1063
|
+
signingWorkerId: signer.signingWorkerId,
|
|
1064
|
+
participantIds: signer.participantIds
|
|
1065
|
+
});
|
|
1066
|
+
if (!active.ok) {
|
|
1067
|
+
if (active.code === "unknown_capability") {
|
|
1068
|
+
if (!sameRouterAbMpcMaterialActivationRef(signer.activeYaoCapability.activationResult.binding.material_activation, input.materialActivation)) return {
|
|
1069
|
+
ok: false,
|
|
1070
|
+
code: "not_found",
|
|
1071
|
+
message: "Ed25519 material activation does not match the persisted capability"
|
|
1072
|
+
};
|
|
1073
|
+
return await activeEd25519MaterialFromPersistedSigner(signer);
|
|
1074
|
+
}
|
|
1075
|
+
return {
|
|
1076
|
+
ok: false,
|
|
1077
|
+
code: "internal",
|
|
1078
|
+
message: active.message
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
if (!sameRouterAbMpcMaterialActivationRef(active.capability.materialActivation, input.materialActivation)) return {
|
|
1082
|
+
ok: false,
|
|
1083
|
+
code: "not_found",
|
|
1084
|
+
message: "Ed25519 material activation does not match the active capability"
|
|
1085
|
+
};
|
|
1086
|
+
return {
|
|
1087
|
+
ok: true,
|
|
1088
|
+
materialActivation: active.capability.materialActivation,
|
|
1089
|
+
nearAccountId: active.capability.nearAccountId,
|
|
1090
|
+
signerSlot: signer.signerSlot,
|
|
1091
|
+
signingWorkerId: signer.signingWorkerId,
|
|
1092
|
+
participantIds: signer.participantIds,
|
|
1093
|
+
runtimePolicyScope: active.capability.runtimePolicyScope,
|
|
1094
|
+
exportIdentity: await ed25519ExportIdentityFromActiveCapability(active.capability)
|
|
1095
|
+
};
|
|
1096
|
+
} catch (error) {
|
|
1097
|
+
return {
|
|
1098
|
+
ok: false,
|
|
1099
|
+
code: "internal",
|
|
1100
|
+
message: error instanceof Error ? error.message : "Ed25519 material lookup failed"
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
async resolveEcdsaMaterialActivation(input) {
|
|
1105
|
+
try {
|
|
1106
|
+
const walletId = walletIdFromString(input.walletId);
|
|
1107
|
+
const store = this.getWalletStore();
|
|
1108
|
+
const signer = await store.getEcdsaSignerByMaterialActivation({
|
|
1109
|
+
walletId,
|
|
1110
|
+
materialActivation: input.materialActivation
|
|
1111
|
+
});
|
|
1112
|
+
if (signer) return {
|
|
1113
|
+
ok: true,
|
|
1114
|
+
materialActivation: signer.walletKey.publicCapability.material_activation,
|
|
1115
|
+
keyHandle: signer.walletKey.keyHandle,
|
|
1116
|
+
relayerKeyId: signer.walletKey.relayerKeyId,
|
|
1117
|
+
participantIds: signer.walletKey.participantIds,
|
|
1118
|
+
runtimePolicyScope: signer.runtimePolicyScope,
|
|
1119
|
+
routerAbEcdsaDerivationNormalSigning: buildPostRegistrationEcdsaNormalSigningState({
|
|
1120
|
+
walletKey: signer.walletKey,
|
|
1121
|
+
publicCapability: signer.walletKey.publicCapability
|
|
1122
|
+
})
|
|
1123
|
+
};
|
|
1124
|
+
const linkedDeviceReader = this.getLinkedDeviceEd25519AuthorityReader();
|
|
1125
|
+
const projection = linkedDeviceReader?.readInstalledEcdsaAuthorityByMaterialActivationV1 ? await linkedDeviceReader.readInstalledEcdsaAuthorityByMaterialActivationV1({
|
|
1126
|
+
walletId,
|
|
1127
|
+
materialActivation: routerAbMpcMaterialActivationRefFromWire(input.materialActivation)
|
|
1128
|
+
}) : null;
|
|
1129
|
+
if (!projection) return {
|
|
1130
|
+
ok: false,
|
|
1131
|
+
code: "not_found",
|
|
1132
|
+
message: "ECDSA material activation is not active for this wallet"
|
|
1133
|
+
};
|
|
1134
|
+
const matchingSourceSigners = (await store.listEcdsaSignersForWallet({ walletId })).filter((candidate) => linkedEcdsaProjectionMatchesSigner({
|
|
1135
|
+
projection,
|
|
1136
|
+
signer: candidate
|
|
1137
|
+
}));
|
|
1138
|
+
const canonicalSigner = matchingSourceSigners[0];
|
|
1139
|
+
if (!canonicalSigner) return {
|
|
1140
|
+
ok: false,
|
|
1141
|
+
code: "not_found",
|
|
1142
|
+
message: "Linked ECDSA material has no canonical custody source"
|
|
1143
|
+
};
|
|
1144
|
+
if (matchingSourceSigners.some((candidate) => !sameLinkedEcdsaResolvedSignerIdentity(canonicalSigner, candidate))) return {
|
|
1145
|
+
ok: false,
|
|
1146
|
+
code: "internal",
|
|
1147
|
+
message: "Linked ECDSA material has conflicting custody source identities"
|
|
1148
|
+
};
|
|
1149
|
+
return {
|
|
1150
|
+
ok: true,
|
|
1151
|
+
materialActivation: routerAbMpcMaterialActivationRefToWire(projection.materialActivation),
|
|
1152
|
+
keyHandle: canonicalSigner.walletKey.keyHandle,
|
|
1153
|
+
relayerKeyId: canonicalSigner.walletKey.relayerKeyId,
|
|
1154
|
+
participantIds: canonicalSigner.walletKey.participantIds,
|
|
1155
|
+
runtimePolicyScope: canonicalSigner.runtimePolicyScope,
|
|
1156
|
+
routerAbEcdsaDerivationNormalSigning: projection.activationReceipt.normalSigning
|
|
1157
|
+
};
|
|
1158
|
+
} catch (error) {
|
|
1159
|
+
return {
|
|
1160
|
+
ok: false,
|
|
1161
|
+
code: "internal",
|
|
1162
|
+
message: error instanceof Error ? error.message : "ECDSA material lookup failed"
|
|
1163
|
+
};
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
async resolveActiveEd25519TenantRoot(input) {
|
|
1167
|
+
const activeMaterial = await this.resolveEd25519MaterialActivation(input);
|
|
1168
|
+
if (!activeMaterial.ok) return activeMaterial;
|
|
1169
|
+
const identity = resolveTenantRootIdentityV1({
|
|
1170
|
+
kind: "ed25519_b5_active_material",
|
|
1171
|
+
activeMaterial
|
|
1172
|
+
});
|
|
1173
|
+
if (!identity.ok) return {
|
|
1174
|
+
ok: false,
|
|
1175
|
+
code: "invalid_state",
|
|
1176
|
+
message: identity.message
|
|
1177
|
+
};
|
|
1178
|
+
try {
|
|
1179
|
+
const tenantRoot = await this.tenantRootCustodyLineage.resolveActiveLineageForRuntimeScope(identity.identity);
|
|
1180
|
+
if (!tenantRoot) return {
|
|
1181
|
+
ok: false,
|
|
1182
|
+
code: "not_found",
|
|
1183
|
+
message: "Ed25519 tenant root is not active"
|
|
1184
|
+
};
|
|
1185
|
+
return {
|
|
1186
|
+
ok: true,
|
|
1187
|
+
...tenantRoot
|
|
1188
|
+
};
|
|
1189
|
+
} catch (error) {
|
|
1190
|
+
return {
|
|
1191
|
+
ok: false,
|
|
1192
|
+
code: "internal",
|
|
1193
|
+
message: error instanceof Error ? error.message : "Ed25519 tenant-root lookup failed"
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
async resolveActiveEcdsaTenantRoot(input) {
|
|
1198
|
+
const activeMaterial = await this.resolveEcdsaMaterialActivation(input);
|
|
1199
|
+
if (!activeMaterial.ok) return activeMaterial;
|
|
1200
|
+
const identity = resolveTenantRootIdentityV1({
|
|
1201
|
+
kind: "ecdsa_b5_active_material",
|
|
1202
|
+
activeMaterial
|
|
1203
|
+
});
|
|
1204
|
+
if (!identity.ok) return {
|
|
1205
|
+
ok: false,
|
|
1206
|
+
code: "invalid_state",
|
|
1207
|
+
message: identity.message
|
|
1208
|
+
};
|
|
1209
|
+
try {
|
|
1210
|
+
const tenantRoot = await this.tenantRootCustodyLineage.resolveActiveLineageForRuntimeScope(identity.identity);
|
|
1211
|
+
if (!tenantRoot) return {
|
|
1212
|
+
ok: false,
|
|
1213
|
+
code: "not_found",
|
|
1214
|
+
message: "ECDSA tenant root is not active"
|
|
1215
|
+
};
|
|
1216
|
+
return {
|
|
1217
|
+
ok: true,
|
|
1218
|
+
...tenantRoot
|
|
1219
|
+
};
|
|
1220
|
+
} catch (error) {
|
|
1221
|
+
return {
|
|
1222
|
+
ok: false,
|
|
1223
|
+
code: "internal",
|
|
1224
|
+
message: error instanceof Error ? error.message : "ECDSA tenant-root lookup failed"
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
async listWalletEcdsaKeyFactsInventory(input) {
|
|
1229
|
+
const store = this.getWalletStore();
|
|
1230
|
+
return await listThresholdEcdsaKeyIdentityTargetsForUser({
|
|
1231
|
+
userId: input.walletId,
|
|
1232
|
+
rpId: input.rpId,
|
|
1233
|
+
keyTargets: input.keyTargets,
|
|
1234
|
+
getEcdsaSignerByKeyHandle: store.getEcdsaSignerByKeyHandle.bind(store)
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
async listWalletEcdsaCustodyContinuity(input) {
|
|
1238
|
+
return await this.getWalletStore().listEcdsaSignersForWallet({ walletId: walletIdFromString(input.walletId) });
|
|
1239
|
+
}
|
|
1240
|
+
async recordEcdsaPostRegistrationProof(input) {
|
|
1241
|
+
try {
|
|
1242
|
+
const nowMs = Date.now();
|
|
1243
|
+
if (input.request.expires_at_ms <= nowMs || !postRegistrationProofMatchesRequest(input)) return {
|
|
1244
|
+
ok: false,
|
|
1245
|
+
code: "scope_mismatch",
|
|
1246
|
+
message: "ECDSA post-registration proof does not match its admitted request"
|
|
1247
|
+
};
|
|
1248
|
+
const walletId = walletIdFromString(input.request.lifecycle.account_id);
|
|
1249
|
+
if (input.request.client_id !== walletId || input.request.lifecycle.root_share_epoch === "") return {
|
|
1250
|
+
ok: false,
|
|
1251
|
+
code: "identity_mismatch",
|
|
1252
|
+
message: "ECDSA post-registration proof has an invalid wallet identity"
|
|
1253
|
+
};
|
|
1254
|
+
const store = this.getWalletStore();
|
|
1255
|
+
const signer = await store.getEcdsaSignerByPostRegistrationRequest({
|
|
1256
|
+
walletId,
|
|
1257
|
+
request: input.request
|
|
1258
|
+
});
|
|
1259
|
+
if (!signer) return {
|
|
1260
|
+
ok: false,
|
|
1261
|
+
code: "not_found",
|
|
1262
|
+
message: "ECDSA post-registration public capability is not registered"
|
|
1263
|
+
};
|
|
1264
|
+
if (input.request.previous_activation_epoch !== signer.walletKey.publicCapability.activation_epoch) return {
|
|
1265
|
+
ok: false,
|
|
1266
|
+
code: "scope_mismatch",
|
|
1267
|
+
message: "ECDSA post-registration request uses a stale activation epoch"
|
|
1268
|
+
};
|
|
1269
|
+
await store.putEcdsaPendingSessionActivation(pendingEcdsaSessionActivationRecord({
|
|
1270
|
+
proof: input,
|
|
1271
|
+
walletId,
|
|
1272
|
+
publicCapability: signer.walletKey.publicCapability,
|
|
1273
|
+
nowMs
|
|
1274
|
+
}));
|
|
1275
|
+
return { ok: true };
|
|
1276
|
+
} catch (error) {
|
|
1277
|
+
return {
|
|
1278
|
+
ok: false,
|
|
1279
|
+
code: "internal",
|
|
1280
|
+
message: errorMessage(error) || "Failed to persist ECDSA post-registration proof"
|
|
1281
|
+
};
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
async activateEcdsaPostRegistrationSession(input) {
|
|
1285
|
+
try {
|
|
1286
|
+
const nowMs = Date.now();
|
|
1287
|
+
const walletId = walletIdFromString(input.public_capability.client_id);
|
|
1288
|
+
const signer = await this.getWalletStore().getEcdsaSignerByPublicCapability({
|
|
1289
|
+
walletId,
|
|
1290
|
+
publicCapability: input.public_capability
|
|
1291
|
+
});
|
|
1292
|
+
if (!signer) return {
|
|
1293
|
+
ok: false,
|
|
1294
|
+
code: "not_found",
|
|
1295
|
+
message: "ECDSA public capability is not registered for this wallet"
|
|
1296
|
+
};
|
|
1297
|
+
const walletKey = signer.walletKey;
|
|
1298
|
+
const signingRootScope = signingRootScopeFromRuntimePolicyScope(input.session_policy.runtime_policy_scope);
|
|
1299
|
+
if (signingRootScope.signingRootId !== walletKey.signingRootId || signingRootScope.signingRootVersion !== walletKey.signingRootVersion) return {
|
|
1300
|
+
ok: false,
|
|
1301
|
+
code: "scope_mismatch",
|
|
1302
|
+
message: "ECDSA session policy is outside the registered signing-root scope"
|
|
1303
|
+
};
|
|
1304
|
+
const normalSigning = buildPostRegistrationEcdsaNormalSigningState({
|
|
1305
|
+
walletKey,
|
|
1306
|
+
publicCapability: input.public_capability
|
|
1307
|
+
});
|
|
1308
|
+
return {
|
|
1309
|
+
ok: true,
|
|
1310
|
+
walletKey,
|
|
1311
|
+
session: {
|
|
1312
|
+
thresholdSessionId: input.session_policy.threshold_session_id,
|
|
1313
|
+
expiresAtMs: nowMs + input.session_policy.ttl_ms,
|
|
1314
|
+
remainingUses: input.session_policy.remaining_uses
|
|
1315
|
+
},
|
|
1316
|
+
normalSigning,
|
|
1317
|
+
keyManifestDigestB64u: parseDigestB64u(signer.custodyKeyManifestDigestB64u)
|
|
1318
|
+
};
|
|
1319
|
+
} catch (error) {
|
|
1320
|
+
return {
|
|
1321
|
+
ok: false,
|
|
1322
|
+
code: "internal",
|
|
1323
|
+
message: errorMessage(error) || "Failed to activate ECDSA post-registration session"
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
async refreshEd25519YaoWalletSession(request) {
|
|
1328
|
+
try {
|
|
1329
|
+
const policy = request.sessionPolicy;
|
|
1330
|
+
const authorization = request.authorization;
|
|
1331
|
+
const authority = policy.authority;
|
|
1332
|
+
const runtimePolicyScope = policy.runtimePolicyScope;
|
|
1333
|
+
const routerAbNormalSigning = policy.routerAbNormalSigning;
|
|
1334
|
+
const participantIds = normalizeThresholdEd25519ParticipantIds(policy.participantIds);
|
|
1335
|
+
if (!runtimePolicyScope || !routerAbNormalSigning || !participantIds || participantIds.length !== 2 || !walletAuthAuthoritiesMatch(authority, authorization.authority)) return {
|
|
1336
|
+
ok: false,
|
|
1337
|
+
code: "invalid_body",
|
|
1338
|
+
message: "Ed25519 Yao budget refresh policy is invalid"
|
|
1339
|
+
};
|
|
1340
|
+
if (!isPasskeyWalletAuthAuthority(authority)) return {
|
|
1341
|
+
ok: false,
|
|
1342
|
+
code: "invalid_body",
|
|
1343
|
+
message: "Ed25519 Yao passkey budget refresh requires passkey authority"
|
|
1344
|
+
};
|
|
1345
|
+
const firstParticipantId = participantIds[0];
|
|
1346
|
+
const secondParticipantId = participantIds[1];
|
|
1347
|
+
if (firstParticipantId === void 0 || secondParticipantId === void 0) return {
|
|
1348
|
+
ok: false,
|
|
1349
|
+
code: "invalid_body",
|
|
1350
|
+
message: "Ed25519 Yao budget refresh requires exactly two participants"
|
|
1351
|
+
};
|
|
1352
|
+
const exactParticipantIds = [firstParticipantId, secondParticipantId];
|
|
1353
|
+
const yaoRuntime = this.getEd25519YaoProductRegistration();
|
|
1354
|
+
if (!yaoRuntime) return {
|
|
1355
|
+
ok: false,
|
|
1356
|
+
code: "not_configured",
|
|
1357
|
+
message: "Ed25519 Yao Wallet Session refresh is not configured"
|
|
1358
|
+
};
|
|
1359
|
+
if (policy.relayerKeyId !== yaoRuntime.signingWorkerId || routerAbNormalSigning.signingWorkerId !== yaoRuntime.signingWorkerId) return {
|
|
1360
|
+
ok: false,
|
|
1361
|
+
code: "scope_mismatch",
|
|
1362
|
+
message: "Ed25519 Yao budget refresh does not match the active Wallet Session"
|
|
1363
|
+
};
|
|
1364
|
+
const activeAuthority = await this.walletAuthMethods.verifyActivePasskeyAuthority(authorization.authority);
|
|
1365
|
+
if (!activeAuthority.ok) return activeAuthority;
|
|
1366
|
+
const signingRoot = signingRootScopeFromRuntimePolicyScope(runtimePolicyScope);
|
|
1367
|
+
const signingRootVersion = normalizeOptionalTrimmedString(signingRoot.signingRootVersion);
|
|
1368
|
+
if (!signingRootVersion) return {
|
|
1369
|
+
ok: false,
|
|
1370
|
+
code: "invalid_body",
|
|
1371
|
+
message: "Ed25519 Yao budget refresh requires a signing-root version"
|
|
1372
|
+
};
|
|
1373
|
+
const signer = await this.getWalletStore().getEd25519Signer({
|
|
1374
|
+
walletId: authority.walletId,
|
|
1375
|
+
nearAccountId: policy.nearAccountId,
|
|
1376
|
+
nearEd25519SigningKeyId: policy.nearEd25519SigningKeyId
|
|
1377
|
+
});
|
|
1378
|
+
if (!signer || signer.signingWorkerId !== yaoRuntime.signingWorkerId || !sameEd25519ParticipantIds(signer.participantIds, exactParticipantIds) || signer.signingRootId !== signingRoot.signingRootId || signer.signingRootVersion !== signingRootVersion || !sameWalletRuntimePolicyScope(signer.runtimePolicyScope, runtimePolicyScope)) return {
|
|
1379
|
+
ok: false,
|
|
1380
|
+
code: "not_found",
|
|
1381
|
+
message: "Registered Ed25519 Yao signer does not match the refresh policy"
|
|
1382
|
+
};
|
|
1383
|
+
const issuedAtMs = Date.now();
|
|
1384
|
+
const expiresAtMs = issuedAtMs + DEFAULT_WALLET_SESSION_TTL_MS;
|
|
1385
|
+
const remainingUses = Math.min(3, policy.remainingUses);
|
|
1386
|
+
await assertDirectWalletSessionOwnerProof({
|
|
1387
|
+
proof: authorization.proof,
|
|
1388
|
+
tenantId: this.authorizationTenantId,
|
|
1389
|
+
authority,
|
|
1390
|
+
activeAuthority: activeAuthority.authority,
|
|
1391
|
+
walletAuthMethodId: activeAuthority.authMethod.walletAuthMethodId,
|
|
1392
|
+
nowMs: issuedAtMs
|
|
1393
|
+
});
|
|
1394
|
+
const directIssue = await this.authorizationService.issueDirectWalletSessionAuthorizationV2({
|
|
1395
|
+
tenantId: this.authorizationTenantId,
|
|
1396
|
+
principalId: walletSessionPrincipalId(authority),
|
|
1397
|
+
walletId: activeAuthority.authority.walletId,
|
|
1398
|
+
authority: activeAuthority.authority,
|
|
1399
|
+
walletAuthMethodId: activeAuthority.authMethod.walletAuthMethodId,
|
|
1400
|
+
mintId: requireWalletSessionMintId(authorization.verifiedChallengeId),
|
|
1401
|
+
remainingUses,
|
|
1402
|
+
issuedAtMs,
|
|
1403
|
+
expiresAtMs
|
|
1404
|
+
});
|
|
1405
|
+
if (directIssue.kind === "already_committed") return ed25519AlreadyCommittedWalletSessionResponse(directIssue);
|
|
1406
|
+
const sessionInput = {
|
|
1407
|
+
kind: "same_identity_budget_refresh_v1",
|
|
1408
|
+
walletId: authority.walletId,
|
|
1409
|
+
nearAccountId: policy.nearAccountId,
|
|
1410
|
+
nearEd25519SigningKeyId: policy.nearEd25519SigningKeyId,
|
|
1411
|
+
authority,
|
|
1412
|
+
thresholdSessionId: policy.thresholdSessionId,
|
|
1413
|
+
authorizationId: directIssue.session.authorizationId,
|
|
1414
|
+
walletSessionId: directIssue.quota.walletSessionId,
|
|
1415
|
+
quotaId: directIssue.quota.quotaId,
|
|
1416
|
+
expiresAtMs: directIssue.session.expiresAtMs,
|
|
1417
|
+
remainingUses: directIssue.quota.remainingUses,
|
|
1418
|
+
participantIds: exactParticipantIds,
|
|
1419
|
+
runtimePolicyScope,
|
|
1420
|
+
keyManifestDigestB64u: parseDigestB64u(signer.custodyKeyManifestDigestB64u),
|
|
1421
|
+
walletSessionCredential: {
|
|
1422
|
+
kind: "issued_exact_wallet_session",
|
|
1423
|
+
operationCredential: directIssue.operationCredential
|
|
1424
|
+
}
|
|
1425
|
+
};
|
|
1426
|
+
const session = await projectRouterAbEd25519YaoExactWalletSession({
|
|
1427
|
+
signingWorkerId: yaoRuntime.signingWorkerId,
|
|
1428
|
+
sessionInput
|
|
1429
|
+
});
|
|
1430
|
+
if (session.sessionKind !== "issued_exact_wallet_session") throw new Error("Direct Ed25519 budget refresh did not project an issued session");
|
|
1431
|
+
return {
|
|
1432
|
+
ok: true,
|
|
1433
|
+
walletId: session.walletId,
|
|
1434
|
+
nearAccountId: session.nearAccountId,
|
|
1435
|
+
nearEd25519SigningKeyId: session.nearEd25519SigningKeyId,
|
|
1436
|
+
authorityScope: session.authorityScope,
|
|
1437
|
+
thresholdSessionId: session.thresholdSessionId,
|
|
1438
|
+
authorizationId: directIssue.session.authorizationId,
|
|
1439
|
+
walletSessionId: session.walletSessionId,
|
|
1440
|
+
quotaId: session.quotaId,
|
|
1441
|
+
expiresAtMs: session.expiresAtMs,
|
|
1442
|
+
expiresAt: new Date(session.expiresAtMs).toISOString(),
|
|
1443
|
+
participantIds: exactParticipantIds,
|
|
1444
|
+
remainingUses: session.remainingUses,
|
|
1445
|
+
runtimePolicyScope,
|
|
1446
|
+
routerAbNormalSigning,
|
|
1447
|
+
sessionKind: "issued_exact_wallet_session",
|
|
1448
|
+
operationCredential: session.operationCredential
|
|
1449
|
+
};
|
|
1450
|
+
} catch (error) {
|
|
1451
|
+
return {
|
|
1452
|
+
ok: false,
|
|
1453
|
+
code: "internal",
|
|
1454
|
+
message: errorMessage(error) || "Ed25519 Yao Wallet Session refresh failed"
|
|
1455
|
+
};
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
async provisionEd25519YaoWalletSession(request) {
|
|
1459
|
+
try {
|
|
1460
|
+
const walletId = normalizeOptionalTrimmedString(request.walletId);
|
|
1461
|
+
const verifiedChallengeId = normalizeOptionalTrimmedString(request.verifiedChallengeId);
|
|
1462
|
+
const signerSlot = Math.floor(Number(request.signerSlot));
|
|
1463
|
+
const remainingUses = Math.floor(Number(request.remainingUses));
|
|
1464
|
+
if (!walletId || !verifiedChallengeId || !Number.isSafeInteger(signerSlot) || signerSlot < 1 || !Number.isSafeInteger(remainingUses) || remainingUses < 1) return {
|
|
1465
|
+
ok: false,
|
|
1466
|
+
code: "invalid_body",
|
|
1467
|
+
message: "Verified Ed25519 Wallet Session request is invalid"
|
|
1468
|
+
};
|
|
1469
|
+
const yaoRuntime = this.getEd25519YaoProductRegistration();
|
|
1470
|
+
if (!yaoRuntime) return {
|
|
1471
|
+
ok: false,
|
|
1472
|
+
code: "not_configured",
|
|
1473
|
+
message: "Verified Ed25519 Wallet Session provisioning is not configured"
|
|
1474
|
+
};
|
|
1475
|
+
const authority = request.authority;
|
|
1476
|
+
if (String(authority.walletId) !== walletId) return {
|
|
1477
|
+
ok: false,
|
|
1478
|
+
code: "scope_mismatch",
|
|
1479
|
+
message: "Verified owner proof does not match the wallet authority"
|
|
1480
|
+
};
|
|
1481
|
+
let activeAuthority;
|
|
1482
|
+
if (isPasskeyWalletAuthAuthority(authority)) {
|
|
1483
|
+
const verified = await this.walletAuthMethods.verifyActivePasskeyAuthority(authority);
|
|
1484
|
+
if (!verified.ok) return verified;
|
|
1485
|
+
activeAuthority = verified;
|
|
1486
|
+
} else if (isEmailOtpWalletAuthAuthority(authority)) {
|
|
1487
|
+
const resolved = await this.walletAuthMethods.resolveActiveEmailOtpAuthorityForUnlock({
|
|
1488
|
+
walletId: walletIdFromString(walletId),
|
|
1489
|
+
walletAuthMethodId: authority.bindingId,
|
|
1490
|
+
providerUserId: authority.factor.providerUserId,
|
|
1491
|
+
emailHashHex: authority.verifier.emailHashHex
|
|
1492
|
+
});
|
|
1493
|
+
if (resolved.kind === "rejected") return {
|
|
1494
|
+
ok: false,
|
|
1495
|
+
code: resolved.code,
|
|
1496
|
+
message: resolved.message
|
|
1497
|
+
};
|
|
1498
|
+
if (!walletAuthAuthoritiesMatch(resolved.walletAuthAuthority, authority)) return {
|
|
1499
|
+
ok: false,
|
|
1500
|
+
code: "unauthorized",
|
|
1501
|
+
message: "Verified Email OTP authority does not match the active auth method"
|
|
1502
|
+
};
|
|
1503
|
+
activeAuthority = resolved;
|
|
1504
|
+
} else return {
|
|
1505
|
+
ok: false,
|
|
1506
|
+
code: "invalid_body",
|
|
1507
|
+
message: "Verified Ed25519 Wallet Session authority is invalid"
|
|
1508
|
+
};
|
|
1509
|
+
const signer = await this.getWalletStore().getEd25519SignerBySlot({
|
|
1510
|
+
walletId: walletIdFromString(walletId),
|
|
1511
|
+
signerSlot
|
|
1512
|
+
});
|
|
1513
|
+
const firstParticipantId = signer?.participantIds[0];
|
|
1514
|
+
const secondParticipantId = signer?.participantIds[1];
|
|
1515
|
+
if (!signer || signer.walletId !== walletId || signer.signerSlot !== signerSlot || signer.signingWorkerId !== yaoRuntime.signingWorkerId || firstParticipantId === void 0 || secondParticipantId === void 0) return {
|
|
1516
|
+
ok: false,
|
|
1517
|
+
code: "not_found",
|
|
1518
|
+
message: "Registered Ed25519 Yao signer is unavailable for wallet unlock"
|
|
1519
|
+
};
|
|
1520
|
+
const participantIds = [firstParticipantId, secondParticipantId];
|
|
1521
|
+
const signingRoot = signingRootScopeFromRuntimePolicyScope(signer.runtimePolicyScope);
|
|
1522
|
+
if (signingRoot.signingRootId !== signer.signingRootId || signingRoot.signingRootVersion !== signer.signingRootVersion) return {
|
|
1523
|
+
ok: false,
|
|
1524
|
+
code: "invalid_state",
|
|
1525
|
+
message: "Registered Ed25519 Yao signer has inconsistent signing-root scope"
|
|
1526
|
+
};
|
|
1527
|
+
const capability = await yaoRuntime.resolveActiveCapability({
|
|
1528
|
+
kind: "router_ab_ed25519_yao_active_capability_lookup_v1",
|
|
1529
|
+
walletId,
|
|
1530
|
+
nearEd25519SigningKeyId: signer.nearEd25519SigningKeyId,
|
|
1531
|
+
signerSlot,
|
|
1532
|
+
signingWorkerId: signer.signingWorkerId,
|
|
1533
|
+
participantIds
|
|
1534
|
+
});
|
|
1535
|
+
if (!capability.ok) return capability;
|
|
1536
|
+
const descriptor = capability.capability;
|
|
1537
|
+
if (descriptor.applicationBinding.wallet_id !== walletId || descriptor.applicationBinding.near_ed25519_signing_key_id !== signer.nearEd25519SigningKeyId || descriptor.applicationBinding.key_creation_signer_slot !== signerSlot || descriptor.applicationBinding.signing_root_id !== signer.signingRootId || descriptor.nearAccountId !== signer.nearAccountId || descriptor.lifecycle.accountId !== walletId || descriptor.lifecycle.signerSetId !== String(registrationNearEd25519BranchKey(signerSlot)) || descriptor.lifecycle.signingWorkerId !== signer.signingWorkerId || descriptor.lifecycle.rootShareEpoch !== signer.signingRootVersion || ed25519NearPublicKeyFromBytes(descriptor.registeredPublicKey) !== signer.publicKey || !sameEd25519ParticipantIds(descriptor.participantIds, participantIds) || !sameWalletRuntimePolicyScope(descriptor.runtimePolicyScope, signer.runtimePolicyScope)) return {
|
|
1538
|
+
ok: false,
|
|
1539
|
+
code: "capability_conflict",
|
|
1540
|
+
message: "Active Ed25519 Yao capability does not match the registered signer"
|
|
1541
|
+
};
|
|
1542
|
+
let thresholdSessionId = descriptor.lifecycle.thresholdSessionId;
|
|
1543
|
+
let issuedCapability = descriptor;
|
|
1544
|
+
if (activeAuthority.authority.provenance.kind === "device_link") {
|
|
1545
|
+
const linkedDeviceReader = this.getLinkedDeviceEd25519AuthorityReader();
|
|
1546
|
+
const projection = linkedDeviceReader ? await linkedDeviceReader.readInstalledEd25519AuthorityByIdentityV1({
|
|
1547
|
+
walletId: walletIdFromString(walletId),
|
|
1548
|
+
authorityId: activeAuthority.authority.authorityId,
|
|
1549
|
+
walletAuthMethodId: activeAuthority.authMethod.walletAuthMethodId
|
|
1550
|
+
}) : null;
|
|
1551
|
+
if (!projection || !linkedEd25519ProjectionMatchesSigner({
|
|
1552
|
+
projection,
|
|
1553
|
+
walletId,
|
|
1554
|
+
authority: activeAuthority.authority,
|
|
1555
|
+
authMethodId: activeAuthority.authMethod.walletAuthMethodId,
|
|
1556
|
+
signer
|
|
1557
|
+
}) || !linkedEd25519ProjectionMatchesDescriptor({
|
|
1558
|
+
projection,
|
|
1559
|
+
descriptor
|
|
1560
|
+
})) return {
|
|
1561
|
+
ok: false,
|
|
1562
|
+
code: "invalid_state",
|
|
1563
|
+
message: "Linked Ed25519 authority installation does not match the active signer"
|
|
1564
|
+
};
|
|
1565
|
+
const targetSessionId = parseThresholdEd25519SessionId(projection.targetBinding.lifecycle.session_id);
|
|
1566
|
+
if (!targetSessionId.ok) return {
|
|
1567
|
+
ok: false,
|
|
1568
|
+
code: "invalid_state",
|
|
1569
|
+
message: "Linked Ed25519 authority installation has an invalid target session"
|
|
1570
|
+
};
|
|
1571
|
+
thresholdSessionId = targetSessionId.value;
|
|
1572
|
+
issuedCapability = {
|
|
1573
|
+
...descriptor,
|
|
1574
|
+
materialActivation: linkedEd25519ProjectionMaterialActivationWire(projection),
|
|
1575
|
+
lifecycle: {
|
|
1576
|
+
...descriptor.lifecycle,
|
|
1577
|
+
thresholdSessionId: targetSessionId.value
|
|
1578
|
+
}
|
|
1579
|
+
};
|
|
1580
|
+
}
|
|
1581
|
+
const issuedAtMs = Date.now();
|
|
1582
|
+
let walletSessionIdentity;
|
|
1583
|
+
switch (request.walletSessionIdentity.kind) {
|
|
1584
|
+
case "new_wallet_session": {
|
|
1585
|
+
const expiresAtMs = issuedAtMs + DEFAULT_WALLET_SESSION_TTL_MS;
|
|
1586
|
+
const issuedRemainingUses = Math.min(3, remainingUses);
|
|
1587
|
+
await assertDirectWalletSessionOwnerProof({
|
|
1588
|
+
proof: request.proof,
|
|
1589
|
+
tenantId: this.authorizationTenantId,
|
|
1590
|
+
authority,
|
|
1591
|
+
activeAuthority: activeAuthority.authority,
|
|
1592
|
+
walletAuthMethodId: activeAuthority.authMethod.walletAuthMethodId,
|
|
1593
|
+
nowMs: issuedAtMs
|
|
1594
|
+
});
|
|
1595
|
+
const directIssue = await this.authorizationService.issueDirectWalletSessionAuthorizationV2({
|
|
1596
|
+
tenantId: this.authorizationTenantId,
|
|
1597
|
+
principalId: walletSessionPrincipalId(authority),
|
|
1598
|
+
walletId: activeAuthority.authority.walletId,
|
|
1599
|
+
authority: activeAuthority.authority,
|
|
1600
|
+
walletAuthMethodId: activeAuthority.authMethod.walletAuthMethodId,
|
|
1601
|
+
mintId: requireWalletSessionMintId(verifiedChallengeId),
|
|
1602
|
+
remainingUses: issuedRemainingUses,
|
|
1603
|
+
issuedAtMs,
|
|
1604
|
+
expiresAtMs
|
|
1605
|
+
});
|
|
1606
|
+
switch (directIssue.kind) {
|
|
1607
|
+
case "issued":
|
|
1608
|
+
walletSessionIdentity = {
|
|
1609
|
+
authorizationId: directIssue.session.authorizationId,
|
|
1610
|
+
walletSessionId: directIssue.quota.walletSessionId,
|
|
1611
|
+
quotaId: directIssue.quota.quotaId,
|
|
1612
|
+
expiresAtMs,
|
|
1613
|
+
remainingUses: issuedRemainingUses,
|
|
1614
|
+
walletSessionCredential: {
|
|
1615
|
+
kind: "issued_exact_wallet_session",
|
|
1616
|
+
operationCredential: directIssue.operationCredential
|
|
1617
|
+
}
|
|
1618
|
+
};
|
|
1619
|
+
break;
|
|
1620
|
+
case "already_committed": return ed25519AlreadyCommittedWalletSessionResponse(directIssue);
|
|
1621
|
+
default: return assertNeverEd25519WalletSessionIssue(directIssue);
|
|
1622
|
+
}
|
|
1623
|
+
break;
|
|
1624
|
+
}
|
|
1625
|
+
case "reuse_wallet_session_v2": {
|
|
1626
|
+
const requestedIdentity = request.walletSessionIdentity;
|
|
1627
|
+
const existing = await this.authorizationService.readWalletSessionAuthorizationV2ByIdentity({
|
|
1628
|
+
tenantId: this.authorizationTenantId,
|
|
1629
|
+
walletId: walletIdFromString(walletId),
|
|
1630
|
+
walletSessionId: requestedIdentity.walletSessionId,
|
|
1631
|
+
authorizationId: requestedIdentity.authorizationId,
|
|
1632
|
+
nowMs: issuedAtMs
|
|
1633
|
+
});
|
|
1634
|
+
if (!existing || existing.session.authorityId !== activeAuthority.authority.authorityId || existing.session.walletAuthMethodId !== activeAuthority.authMethod.walletAuthMethodId || existing.session.authorityDigestB64u !== activeAuthority.authority.authorityDigestB64u || existing.session.authorityRevocationEpoch !== activeAuthority.authority.revocationEpoch || existing.session.quotaId !== requestedIdentity.quotaId || existing.session.expiresAtMs !== requestedIdentity.expiresAtMs || existing.quota.remainingUses !== requestedIdentity.remainingUses || requestedIdentity.expiresAtMs <= issuedAtMs || requestedIdentity.remainingUses < 1) return {
|
|
1635
|
+
ok: false,
|
|
1636
|
+
code: "invalid_state",
|
|
1637
|
+
message: "Linked Ed25519 Wallet Session identity is unavailable"
|
|
1638
|
+
};
|
|
1639
|
+
walletSessionIdentity = {
|
|
1640
|
+
...requestedIdentity,
|
|
1641
|
+
walletSessionCredential: { kind: "already_committed_exact_wallet_session" }
|
|
1642
|
+
};
|
|
1643
|
+
break;
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
return {
|
|
1647
|
+
ok: true,
|
|
1648
|
+
session: await projectRouterAbEd25519YaoExactWalletSession({
|
|
1649
|
+
signingWorkerId: yaoRuntime.signingWorkerId,
|
|
1650
|
+
sessionInput: {
|
|
1651
|
+
kind: "verified_wallet_unlock_v1",
|
|
1652
|
+
walletId: walletIdFromString(walletId),
|
|
1653
|
+
nearAccountId: signer.nearAccountId,
|
|
1654
|
+
nearEd25519SigningKeyId: signer.nearEd25519SigningKeyId,
|
|
1655
|
+
authority,
|
|
1656
|
+
thresholdSessionId,
|
|
1657
|
+
authorizationId: walletSessionIdentity.authorizationId,
|
|
1658
|
+
walletSessionId: walletSessionIdentity.walletSessionId,
|
|
1659
|
+
quotaId: walletSessionIdentity.quotaId,
|
|
1660
|
+
participantIds,
|
|
1661
|
+
runtimePolicyScope: signer.runtimePolicyScope,
|
|
1662
|
+
keyManifestDigestB64u: parseDigestB64u(signer.custodyKeyManifestDigestB64u),
|
|
1663
|
+
expiresAtMs: walletSessionIdentity.expiresAtMs,
|
|
1664
|
+
remainingUses: walletSessionIdentity.remainingUses,
|
|
1665
|
+
walletSessionCredential: walletSessionIdentity.walletSessionCredential
|
|
1666
|
+
}
|
|
1667
|
+
}),
|
|
1668
|
+
capability: issuedCapability
|
|
1669
|
+
};
|
|
1670
|
+
} catch (error) {
|
|
1671
|
+
return {
|
|
1672
|
+
ok: false,
|
|
1673
|
+
code: "internal",
|
|
1674
|
+
message: errorMessage(error) || "Verified Ed25519 Wallet Session provisioning failed"
|
|
1675
|
+
};
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
/**
|
|
1679
|
+
* Refactor 94C. `/wallets/register/setup` — grant, intent, and start in one
|
|
1680
|
+
* request, with one D1 write.
|
|
1681
|
+
*
|
|
1682
|
+
* Setup runs before the client's WebAuthn create, because it issues the
|
|
1683
|
+
* challenge that create signs. So the ECDSA prepare and the Ed25519
|
|
1684
|
+
* admission — the two Router calls that dominated the measured cold path —
|
|
1685
|
+
* overlap the authenticator prompt instead of being serialized after it.
|
|
1686
|
+
* They are started before either is awaited: they share no state and neither
|
|
1687
|
+
* can invalidate the other.
|
|
1688
|
+
*/
|
|
1689
|
+
async setupWalletRegistration(input) {
|
|
1690
|
+
const timing = createD1RegistrationRouteTimingRecorder("wallets_register_setup");
|
|
1691
|
+
const total = startD1RegistrationRouteTiming("registerSetupTotalMs");
|
|
1692
|
+
try {
|
|
1693
|
+
const normalized = normalizeWalletRegistrationSetupRequest(input.request);
|
|
1694
|
+
if (!normalized.ok) return walletRegistrationSetupError(normalized.code, normalized.message);
|
|
1695
|
+
const wallet = resolveWalletRegistrationSetupWalletId({
|
|
1696
|
+
wallet: input.request?.wallet,
|
|
1697
|
+
parseProvided: parseWalletIdForIntent,
|
|
1698
|
+
createServerAllocated: createD1ServerAllocatedWalletId
|
|
1699
|
+
});
|
|
1700
|
+
if (!wallet.ok) return walletRegistrationSetupError(wallet.code, wallet.message);
|
|
1701
|
+
const runtimePolicyScope = input.runtimePolicyScope || inferRuntimePolicyScopeFromSigningRoot({
|
|
1702
|
+
orgId: input.orgId,
|
|
1703
|
+
signingRootId: input.signingRootId,
|
|
1704
|
+
signingRootVersion: input.signingRootVersion
|
|
1705
|
+
});
|
|
1706
|
+
const signingRootId = normalizeOptionalTrimmedString(input.signingRootId) || (runtimePolicyScope ? deriveSigningRootId(runtimePolicyScope) : "");
|
|
1707
|
+
const signingRootVersion = normalizeOptionalTrimmedString(input.signingRootVersion) || runtimePolicyScope?.signingRootVersion || "default";
|
|
1708
|
+
if (!signingRootId) return walletRegistrationSetupError("invalid_body", "registration requires a signing root");
|
|
1709
|
+
const registrationOperation = allocateWalletRegistrationOperationPrepared();
|
|
1710
|
+
const intent = buildRegistrationIntent({
|
|
1711
|
+
walletId: wallet.walletId,
|
|
1712
|
+
authMethod: normalized.authMethod,
|
|
1713
|
+
signerSelection: normalized.signerSelection,
|
|
1714
|
+
foundingWalletAuthMethodId: registrationOperation.walletAuthMethodId,
|
|
1715
|
+
...runtimePolicyScope ? { runtimePolicyScope } : {}
|
|
1716
|
+
});
|
|
1717
|
+
const digestB64u = await walletRegistrationSetupIntentDigest(intent);
|
|
1718
|
+
const branches = registrationIntentSignerBranches(intent);
|
|
1719
|
+
if (!branches.ok) return walletRegistrationSetupError(branches.code, branches.message);
|
|
1720
|
+
const ecdsaBranch = branches.value.evmFamilyEcdsa;
|
|
1721
|
+
const nearEd25519Branch = branches.value.nearEd25519;
|
|
1722
|
+
if (!ecdsaBranch && !nearEd25519Branch) return walletRegistrationSetupError("invalid_body", "registration signer branch is required");
|
|
1723
|
+
const preparedContext = resolveRegistrationPreparedContextFromPlan({
|
|
1724
|
+
signerPlan: branches.value.plan,
|
|
1725
|
+
runtimePolicyScope,
|
|
1726
|
+
signingRootId,
|
|
1727
|
+
signingRootVersion
|
|
1728
|
+
});
|
|
1729
|
+
if (!preparedContext.ok) return walletRegistrationSetupError(preparedContext.code, preparedContext.message);
|
|
1730
|
+
if (ecdsaBranch && !runtimePolicyScope) return walletRegistrationSetupError("invalid_body", "ECDSA registration requires an exact runtime policy scope");
|
|
1731
|
+
const chainTargets = ecdsaBranch ? registrationPreparedContextEcdsaChainTargets(preparedContext.preparedContext) : null;
|
|
1732
|
+
if (ecdsaBranch && !chainTargets) return walletRegistrationSetupError("invalid_body", "ECDSA chain targets are required");
|
|
1733
|
+
const expiresAtMs = walletRegistrationSetupExpiresAtMs(Date.now());
|
|
1734
|
+
const { registrationCeremonyId, registrationPreparationId } = walletRegistrationSetupIds();
|
|
1735
|
+
const ecdsaPrepared = ecdsaBranch && chainTargets && runtimePolicyScope ? await buildD1EvmFamilyEcdsaRegistrationPrepare({
|
|
1736
|
+
registrationPurpose: "wallet_registration",
|
|
1737
|
+
registrationCeremonyId,
|
|
1738
|
+
registrationPreparationId: registrationPreparationIdFromString(registrationPreparationId),
|
|
1739
|
+
walletId: wallet.walletId,
|
|
1740
|
+
signingRootId,
|
|
1741
|
+
signingRootVersion,
|
|
1742
|
+
chainTargets,
|
|
1743
|
+
participantIds: [...ecdsaBranch.participantIds],
|
|
1744
|
+
strictRegistration: this.ecdsaStrictRegistration,
|
|
1745
|
+
runtimePolicyScope
|
|
1746
|
+
}) : null;
|
|
1747
|
+
if (ecdsaPrepared && !ecdsaPrepared.ok) return walletRegistrationSetupError(ecdsaPrepared.code, ecdsaPrepared.message);
|
|
1748
|
+
const storedBranches = [];
|
|
1749
|
+
if (ecdsaPrepared?.ok && ecdsaBranch) storedBranches.push(buildStoredWalletRegistrationEvmFamilyEcdsaPreparedBranch({
|
|
1750
|
+
branchKey: ecdsaBranch.branchKey,
|
|
1751
|
+
ecdsa: {
|
|
1752
|
+
kind: ecdsaPrepared.ecdsa.kind,
|
|
1753
|
+
chainTargets: ecdsaPrepared.ecdsa.chainTargets,
|
|
1754
|
+
prepare: ecdsaPrepared.ecdsa.prepare,
|
|
1755
|
+
strictRegistration: ecdsaPrepared.ecdsa.strictRegistration,
|
|
1756
|
+
strictRegistrationBindingJson: routerAbEcdsaStrictRegistrationFactsBindingJson(ecdsaPrepared.ecdsa.strictRegistration)
|
|
1757
|
+
}
|
|
1758
|
+
}));
|
|
1759
|
+
const ceremony = {
|
|
1760
|
+
registrationCeremonyId,
|
|
1761
|
+
foundingWalletAuthorityId: registrationOperation.walletAuthorityId,
|
|
1762
|
+
foundingDeviceId: registrationOperation.deviceId,
|
|
1763
|
+
foundingWalletAuthMethodId: registrationOperation.walletAuthMethodId,
|
|
1764
|
+
intent,
|
|
1765
|
+
digestB64u,
|
|
1766
|
+
signerPlan: branches.value.plan,
|
|
1767
|
+
preparedContext: preparedContext.preparedContext,
|
|
1768
|
+
orgId: normalizeOptionalTrimmedString(input.orgId) || "",
|
|
1769
|
+
signingRootId,
|
|
1770
|
+
signingRootVersion,
|
|
1771
|
+
...input.expectedOrigin ? { expectedOrigin: input.expectedOrigin } : {},
|
|
1772
|
+
expiresAtMs,
|
|
1773
|
+
authorityState: {
|
|
1774
|
+
kind: "awaiting_proof",
|
|
1775
|
+
authMethod: normalized.authMethod
|
|
1776
|
+
},
|
|
1777
|
+
signerState: {
|
|
1778
|
+
kind: "signer_set_registration",
|
|
1779
|
+
branches: storedBranches
|
|
1780
|
+
}
|
|
1781
|
+
};
|
|
1782
|
+
const ceremonyWriteTiming = startD1RegistrationRouteTiming("registrationCeremonyInsertMs");
|
|
1783
|
+
try {
|
|
1784
|
+
await this.getRegistrationCeremonyIntentStore().putCeremony(ceremony);
|
|
1785
|
+
} finally {
|
|
1786
|
+
finishD1RegistrationRouteTiming(timing, ceremonyWriteTiming);
|
|
1787
|
+
}
|
|
1788
|
+
const { signedSetup } = await buildWalletRegistrationSetupSignature({
|
|
1789
|
+
signer: input.signer,
|
|
1790
|
+
ceremony,
|
|
1791
|
+
expectedOrigin: input.expectedOrigin
|
|
1792
|
+
});
|
|
1793
|
+
finishD1RegistrationRouteTiming(timing, total);
|
|
1794
|
+
const success = {
|
|
1795
|
+
ok: true,
|
|
1796
|
+
registrationCeremonyId,
|
|
1797
|
+
walletId: String(wallet.walletId),
|
|
1798
|
+
walletAuthMethodId: registrationOperation.walletAuthMethodId,
|
|
1799
|
+
registrationIntentDigestB64u: digestB64u,
|
|
1800
|
+
intent,
|
|
1801
|
+
signedSetup
|
|
1802
|
+
};
|
|
1803
|
+
if (!ecdsaPrepared?.ok || !ecdsaBranch) return {
|
|
1804
|
+
...success,
|
|
1805
|
+
kind: "near_ed25519"
|
|
1806
|
+
};
|
|
1807
|
+
return {
|
|
1808
|
+
...success,
|
|
1809
|
+
kind: nearEd25519Branch ? "near_ed25519_and_evm_family_ecdsa" : "evm_family_ecdsa",
|
|
1810
|
+
ecdsa: {
|
|
1811
|
+
kind: ecdsaPrepared.ecdsa.kind,
|
|
1812
|
+
chainTargets: ecdsaPrepared.ecdsa.chainTargets,
|
|
1813
|
+
prepare: ecdsaPrepared.ecdsa.prepare,
|
|
1814
|
+
strictRegistration: ecdsaPrepared.ecdsa.strictRegistration
|
|
1815
|
+
}
|
|
1816
|
+
};
|
|
1817
|
+
} catch (error) {
|
|
1818
|
+
return walletRegistrationSetupError("internal", errorMessage(error) || "Failed to set up wallet registration");
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
async respondWalletRegistration(input, traceContext) {
|
|
1822
|
+
const serverTiming = [];
|
|
1823
|
+
const totalStartedAtMs = Date.now();
|
|
1824
|
+
const mark = (name, startedAtMs) => {
|
|
1825
|
+
serverTiming.push([name, Math.max(0, Date.now() - startedAtMs)]);
|
|
1826
|
+
};
|
|
1827
|
+
try {
|
|
1828
|
+
const store = this.getRegistrationCeremonyIntentStore();
|
|
1829
|
+
const loadStartedAtMs = Date.now();
|
|
1830
|
+
const snapshot = await store.getCeremonySnapshot(input.registrationCeremonyId);
|
|
1831
|
+
mark("respond_d1_load", loadStartedAtMs);
|
|
1832
|
+
if (!snapshot) return {
|
|
1833
|
+
ok: false,
|
|
1834
|
+
code: "not_found",
|
|
1835
|
+
message: "registration ceremony not found"
|
|
1836
|
+
};
|
|
1837
|
+
const ceremony = snapshot.ceremony;
|
|
1838
|
+
if (ceremony.signerState.kind !== "signer_set_registration") return {
|
|
1839
|
+
ok: false,
|
|
1840
|
+
code: "invalid_state",
|
|
1841
|
+
message: "signer-set registration state is required"
|
|
1842
|
+
};
|
|
1843
|
+
const expectedOrigin = normalizeOptionalTrimmedString(ceremony.expectedOrigin) || "";
|
|
1844
|
+
const setupDigestB64u = await computeWalletRegistrationSetupDigestB64u({
|
|
1845
|
+
registrationCeremonyId: ceremony.registrationCeremonyId,
|
|
1846
|
+
intent: ceremony.intent,
|
|
1847
|
+
intentDigestB64u: ceremony.digestB64u,
|
|
1848
|
+
orgId: ceremony.orgId,
|
|
1849
|
+
signingRootId: normalizeOptionalTrimmedString(ceremony.signingRootId) || "",
|
|
1850
|
+
signingRootVersion: normalizeOptionalTrimmedString(ceremony.signingRootVersion) || "",
|
|
1851
|
+
expectedOrigin
|
|
1852
|
+
});
|
|
1853
|
+
const verifiedSetup = await verifySignedWalletRegistrationSetup(input.verifier, input.signedSetup, {
|
|
1854
|
+
registrationCeremonyId: ceremony.registrationCeremonyId,
|
|
1855
|
+
setupDigestB64u,
|
|
1856
|
+
nowMs: Date.now()
|
|
1857
|
+
});
|
|
1858
|
+
if (!verifiedSetup.ok) return {
|
|
1859
|
+
ok: false,
|
|
1860
|
+
code: verifiedSetup.code,
|
|
1861
|
+
message: verifiedSetup.message
|
|
1862
|
+
};
|
|
1863
|
+
const registrationBearerToken = normalizeOptionalTrimmedString(input.signedSetup);
|
|
1864
|
+
if (!registrationBearerToken) return {
|
|
1865
|
+
ok: false,
|
|
1866
|
+
code: "invalid_body",
|
|
1867
|
+
message: "signedSetup is required"
|
|
1868
|
+
};
|
|
1869
|
+
const ecdsaBranch = findStoredWalletRegistrationEvmFamilyEcdsaBranch(ceremony.signerState);
|
|
1870
|
+
const planNearEd25519 = registrationSignerBranchesFromPlan(ceremony.signerPlan).nearEd25519;
|
|
1871
|
+
if (!ecdsaBranch && !planNearEd25519) return {
|
|
1872
|
+
ok: false,
|
|
1873
|
+
code: "invalid_state",
|
|
1874
|
+
message: "a signer branch is required"
|
|
1875
|
+
};
|
|
1876
|
+
const ceremonyIsEd25519Only = !ecdsaBranch && Boolean(planNearEd25519);
|
|
1877
|
+
if (input.planKind === "near_ed25519" !== ceremonyIsEd25519Only) return {
|
|
1878
|
+
ok: false,
|
|
1879
|
+
code: "scope_mismatch",
|
|
1880
|
+
message: "respond signer plan does not match the registration ceremony"
|
|
1881
|
+
};
|
|
1882
|
+
if (!ecdsaBranch && planNearEd25519) return await this.respondEd25519OnlyRegistration({
|
|
1883
|
+
snapshot,
|
|
1884
|
+
ceremony,
|
|
1885
|
+
branch: planNearEd25519,
|
|
1886
|
+
authorityInput: input.authority,
|
|
1887
|
+
registrationBearerToken,
|
|
1888
|
+
expectedOrigin,
|
|
1889
|
+
...input.userAgent ? { userAgent: input.userAgent } : {}
|
|
1890
|
+
});
|
|
1891
|
+
if (!ecdsaBranch) return {
|
|
1892
|
+
ok: false,
|
|
1893
|
+
code: "invalid_state",
|
|
1894
|
+
message: "ECDSA branch is required"
|
|
1895
|
+
};
|
|
1896
|
+
if (!input.ecdsa) return {
|
|
1897
|
+
ok: false,
|
|
1898
|
+
code: "invalid_body",
|
|
1899
|
+
message: "strict Router A/B ECDSA registration request is required"
|
|
1900
|
+
};
|
|
1901
|
+
const strictRegistration = input.ecdsa.strictRegistration;
|
|
1902
|
+
const strictRegistrationBindingJson = routerAbEcdsaStrictRegistrationRequestBindingJson(strictRegistration);
|
|
1903
|
+
if (ecdsaBranch.kind === "evm_family_ecdsa_pending_activation") {
|
|
1904
|
+
if (!sameRouterAbEcdsaRegistrationRequest(ecdsaBranch.registrationRequest, strictRegistration)) return {
|
|
1905
|
+
ok: false,
|
|
1906
|
+
code: "scope_mismatch",
|
|
1907
|
+
message: "ECDSA registration replay changed the exact request"
|
|
1908
|
+
};
|
|
1909
|
+
const replayAuthority = await this.verifyRespondReplayAuthority({
|
|
1910
|
+
ceremony,
|
|
1911
|
+
authorityInput: input.authority,
|
|
1912
|
+
expectedOrigin,
|
|
1913
|
+
...input.userAgent ? { userAgent: input.userAgent } : {}
|
|
1914
|
+
});
|
|
1915
|
+
if (!replayAuthority.ok) return {
|
|
1916
|
+
ok: false,
|
|
1917
|
+
code: replayAuthority.code,
|
|
1918
|
+
message: replayAuthority.message
|
|
1919
|
+
};
|
|
1920
|
+
return walletRegistrationRespondResult({
|
|
1921
|
+
ceremony,
|
|
1922
|
+
strictResult: ecdsaBranch.publicResponse,
|
|
1923
|
+
ed25519: storedRespondEd25519DeferredWork(ceremony.signerState)
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
if (ecdsaBranch.kind !== "evm_family_ecdsa_prepared") return {
|
|
1927
|
+
ok: false,
|
|
1928
|
+
code: "invalid_state",
|
|
1929
|
+
message: "ECDSA registration branch is not respondable"
|
|
1930
|
+
};
|
|
1931
|
+
if (ecdsaBranch.strictRegistrationBindingJson !== strictRegistrationBindingJson) return {
|
|
1932
|
+
ok: false,
|
|
1933
|
+
code: "scope_mismatch",
|
|
1934
|
+
message: "ECDSA registration request does not match the admitted ceremony facts"
|
|
1935
|
+
};
|
|
1936
|
+
const authorityStartedAtMs = Date.now();
|
|
1937
|
+
const verifiedAuthority = await this.walletAuthMethods.verifyRegistrationAuthorityForIntent({
|
|
1938
|
+
orgId: ceremony.orgId,
|
|
1939
|
+
authority: input.authority,
|
|
1940
|
+
expectedDigestB64u: ceremony.digestB64u,
|
|
1941
|
+
expectedOrigin,
|
|
1942
|
+
intent: ceremony.intent,
|
|
1943
|
+
verificationOperationId: ceremony.registrationCeremonyId,
|
|
1944
|
+
verificationReceiptExpiresAtMs: ceremony.expiresAtMs,
|
|
1945
|
+
...input.userAgent ? { userAgent: input.userAgent } : {}
|
|
1946
|
+
});
|
|
1947
|
+
mark("respond_authority_verify", authorityStartedAtMs);
|
|
1948
|
+
if (!verifiedAuthority.ok) return {
|
|
1949
|
+
ok: false,
|
|
1950
|
+
code: verifiedAuthority.code,
|
|
1951
|
+
message: verifiedAuthority.message
|
|
1952
|
+
};
|
|
1953
|
+
const authority = verifiedAuthority.authority;
|
|
1954
|
+
if (authority.walletId !== ceremony.intent.walletId) return {
|
|
1955
|
+
ok: false,
|
|
1956
|
+
code: "scope_mismatch",
|
|
1957
|
+
message: "registration authority walletId does not match the ceremony"
|
|
1958
|
+
};
|
|
1959
|
+
const tenantRootIdentity = registrationTenantRootIdentity(ceremony.preparedContext);
|
|
1960
|
+
if (!tenantRootIdentity) return {
|
|
1961
|
+
ok: false,
|
|
1962
|
+
code: "invalid_state",
|
|
1963
|
+
message: "ECDSA registration has no authoritative tenant-root identity"
|
|
1964
|
+
};
|
|
1965
|
+
const tenantRoot = await this.tenantRootCustodyLineage.resolveActiveLineageForRuntimeScope(tenantRootIdentity);
|
|
1966
|
+
if (!tenantRoot) return {
|
|
1967
|
+
ok: false,
|
|
1968
|
+
code: "invalid_state",
|
|
1969
|
+
message: "ECDSA registration tenant root is not active"
|
|
1970
|
+
};
|
|
1971
|
+
const routerStartedAtMs = Date.now();
|
|
1972
|
+
const nearEd25519Branch = registrationSignerBranchesFromPlan(ceremony.signerPlan).nearEd25519;
|
|
1973
|
+
const [strictResult, ed25519Admission] = await Promise.all([this.ecdsaStrictRegistration.registerWithTenantRoot({
|
|
1974
|
+
request: strictRegistration,
|
|
1975
|
+
tenantRoot,
|
|
1976
|
+
requestPolicy: {
|
|
1977
|
+
policyVersion: WALLET_REGISTRATION_ROUTER_POLICY_VERSION,
|
|
1978
|
+
requestDigestB64u: input.ecdsa.requestDigestB64u
|
|
1979
|
+
},
|
|
1980
|
+
authority: ecdsaStrictRegistrationAuthority(ecdsaBranch.strictRegistration),
|
|
1981
|
+
traceContext,
|
|
1982
|
+
onServerTiming: (header) => mergeRouterServerTiming(serverTiming, header),
|
|
1983
|
+
onHeaderPresence: (presence) => serverTiming.push([`ecdsa_role_timing_${presence.serverTiming}`, 1])
|
|
1984
|
+
}), this.admitRespondEd25519Branch({
|
|
1985
|
+
ceremony,
|
|
1986
|
+
branch: nearEd25519Branch,
|
|
1987
|
+
authority,
|
|
1988
|
+
registrationBearerToken
|
|
1989
|
+
})]);
|
|
1990
|
+
mark("respond_router", routerStartedAtMs);
|
|
1991
|
+
if (!strictResult.ok) {
|
|
1992
|
+
if (!strictResult.retryable) await store.cancelTerminalCeremony({
|
|
1993
|
+
registrationCeremonyId: ceremony.registrationCeremonyId,
|
|
1994
|
+
walletId: ceremony.intent.walletId
|
|
1995
|
+
});
|
|
1996
|
+
return {
|
|
1997
|
+
ok: false,
|
|
1998
|
+
code: strictResult.code,
|
|
1999
|
+
message: strictResult.message
|
|
2000
|
+
};
|
|
2001
|
+
}
|
|
2002
|
+
if (!ed25519Admission.ok) return {
|
|
2003
|
+
ok: false,
|
|
2004
|
+
code: ed25519Admission.code,
|
|
2005
|
+
message: ed25519Admission.message
|
|
2006
|
+
};
|
|
2007
|
+
let nextSignerState = replaceStoredWalletRegistrationSignerBranch({
|
|
2008
|
+
state: ceremony.signerState,
|
|
2009
|
+
replacement: {
|
|
2010
|
+
kind: "evm_family_ecdsa_pending_activation",
|
|
2011
|
+
branchKey: ecdsaBranch.branchKey,
|
|
2012
|
+
derivationKind: ecdsaBranch.derivationKind,
|
|
2013
|
+
chainTargets: ecdsaBranch.chainTargets,
|
|
2014
|
+
prepare: ecdsaBranch.prepare,
|
|
2015
|
+
strictRegistration: ecdsaBranch.strictRegistration,
|
|
2016
|
+
strictRegistrationBindingJson: ecdsaBranch.strictRegistrationBindingJson,
|
|
2017
|
+
registrationRequest: strictRegistration,
|
|
2018
|
+
pendingActivation: strictResult.value.pendingActivation,
|
|
2019
|
+
publicResponse: strictResult.value.publicResponse
|
|
2020
|
+
}
|
|
2021
|
+
});
|
|
2022
|
+
if (ed25519Admission.branch) nextSignerState = {
|
|
2023
|
+
kind: "signer_set_registration",
|
|
2024
|
+
branches: [ed25519Admission.branch, ...nextSignerState.branches]
|
|
2025
|
+
};
|
|
2026
|
+
const next = {
|
|
2027
|
+
...ceremony,
|
|
2028
|
+
authorityState: {
|
|
2029
|
+
kind: "verified",
|
|
2030
|
+
authority
|
|
2031
|
+
},
|
|
2032
|
+
signerState: nextSignerState
|
|
2033
|
+
};
|
|
2034
|
+
const commitStartedAtMs = Date.now();
|
|
2035
|
+
try {
|
|
2036
|
+
await store.commitEcdsaClaim({
|
|
2037
|
+
expected: snapshot,
|
|
2038
|
+
next
|
|
2039
|
+
});
|
|
2040
|
+
} catch (error) {
|
|
2041
|
+
const reconciled = await store.getCeremony(input.registrationCeremonyId);
|
|
2042
|
+
const reconciledBranch = reconciled?.signerState.kind === "signer_set_registration" ? findStoredWalletRegistrationEvmFamilyEcdsaBranch(reconciled.signerState) : null;
|
|
2043
|
+
if (!reconciled || reconciledBranch?.kind !== "evm_family_ecdsa_pending_activation" || !sameRouterAbEcdsaRegistrationRequest(reconciledBranch.registrationRequest, strictRegistration)) throw error;
|
|
2044
|
+
mark("respond_d1_commit", commitStartedAtMs);
|
|
2045
|
+
mark("respond_total", totalStartedAtMs);
|
|
2046
|
+
return walletRegistrationRespondResult({
|
|
2047
|
+
ceremony: reconciled,
|
|
2048
|
+
strictResult: reconciledBranch.publicResponse,
|
|
2049
|
+
ed25519: storedRespondEd25519DeferredWork(reconciled.signerState)
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
mark("respond_d1_commit", commitStartedAtMs);
|
|
2053
|
+
mark("respond_total", totalStartedAtMs);
|
|
2054
|
+
return walletRegistrationRespondResult({
|
|
2055
|
+
ceremony: next,
|
|
2056
|
+
strictResult: strictResult.value.publicResponse,
|
|
2057
|
+
ed25519: ed25519Admission.deferred
|
|
2058
|
+
});
|
|
2059
|
+
} catch (error) {
|
|
2060
|
+
return {
|
|
2061
|
+
ok: false,
|
|
2062
|
+
code: "internal",
|
|
2063
|
+
message: errorMessage(error) || "Failed to respond to wallet registration ceremony"
|
|
2064
|
+
};
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
/**
|
|
2068
|
+
* The Ed25519 commit core, extracted so deferred provisioning reaches it
|
|
2069
|
+
* without going through the standalone finalize wrapper. The operation row
|
|
2070
|
+
* owns idempotency here, so the commit keeps no replay cache of its own.
|
|
2071
|
+
*/
|
|
2072
|
+
async readRegistrationOwnerProofContext(registrationCeremonyId) {
|
|
2073
|
+
const ceremony = await this.getRegistrationCeremonyIntentStore().getCeremony(registrationCeremonyId);
|
|
2074
|
+
if (!ceremony) {
|
|
2075
|
+
const committed = await this.readCommittedRegistrationInstallation(registrationCeremonyId);
|
|
2076
|
+
if (!committed) return null;
|
|
2077
|
+
if (!isRegistrationEcdsaReadyReceipt(committed.receipt)) throw new Error("Committed registration installation has no ECDSA session receipt");
|
|
2078
|
+
const runtimePolicyScope = registrationPreparedContextRuntimePolicyScope(committed.projection.preparedContext);
|
|
2079
|
+
if (!runtimePolicyScope) throw new Error("Committed registration is missing its runtime policy scope");
|
|
2080
|
+
return {
|
|
2081
|
+
expectedOrigin: committed.receipt.expectedOrigin,
|
|
2082
|
+
runtimePolicyScope,
|
|
2083
|
+
expiresAtMs: committed.receipt.expiresAtMs
|
|
2084
|
+
};
|
|
2085
|
+
}
|
|
2086
|
+
const expectedOrigin = normalizeOptionalTrimmedString(ceremony.expectedOrigin);
|
|
2087
|
+
const runtimePolicyScope = registrationPreparedContextRuntimePolicyScope(ceremony.preparedContext);
|
|
2088
|
+
if (!expectedOrigin || !runtimePolicyScope) throw new Error("Registration is missing its session origin or runtime policy scope");
|
|
2089
|
+
return {
|
|
2090
|
+
expectedOrigin,
|
|
2091
|
+
runtimePolicyScope,
|
|
2092
|
+
expiresAtMs: ceremony.expiresAtMs
|
|
2093
|
+
};
|
|
2094
|
+
}
|
|
2095
|
+
async registrationOwnerProof(input) {
|
|
2096
|
+
const context = await this.readRegistrationOwnerProofContext(input.registrationCeremonyId);
|
|
2097
|
+
if (!context) throw new Error("Registration owner proof context is unavailable");
|
|
2098
|
+
return await this.registrationOwnerProofWithContext(context, input);
|
|
2099
|
+
}
|
|
2100
|
+
/** For callers that must read the context before finalize tombstones it. */
|
|
2101
|
+
async registrationOwnerProofWithContext(context, input) {
|
|
2102
|
+
return await buildRegistrationOwnerProof({
|
|
2103
|
+
...input,
|
|
2104
|
+
tenantId: this.authorizationTenantId,
|
|
2105
|
+
expectedOrigin: context.expectedOrigin,
|
|
2106
|
+
expiresAtMs: Math.min(context.expiresAtMs, Date.now() + DEFAULT_WALLET_SESSION_TTL_MS)
|
|
2107
|
+
});
|
|
2108
|
+
}
|
|
2109
|
+
async readCommittedRegistrationInstallation(registrationCeremonyId) {
|
|
2110
|
+
const entries = await this.activateSideEffects.listByKeyPrefix(`registration-activate:${registrationCeremonyId}:`, { limit: 2 });
|
|
2111
|
+
const completed = [];
|
|
2112
|
+
for (const entry of entries) {
|
|
2113
|
+
if (entry.result.kind !== "present") continue;
|
|
2114
|
+
switch (entry.result.value.kind) {
|
|
2115
|
+
case "router_ab_ed25519_yao_registration_side_effect_completion_v2":
|
|
2116
|
+
completed.push({ record: entry.result.value });
|
|
2117
|
+
break;
|
|
2118
|
+
case "router_ab_ed25519_yao_registration_side_effect_claim_v1": throw new Error("registration activation has an unfinished side-effect claim");
|
|
2119
|
+
default: return assertNeverD1RegistrationSideEffectRecord(entry.result.value);
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
if (completed.length === 0) return null;
|
|
2123
|
+
if (completed.length !== 1) throw new Error("registration activation has conflicting committed installation receipts");
|
|
2124
|
+
const record = completed[0].record;
|
|
2125
|
+
if (base64UrlEncode(await sha256BytesUtf8(alphabetizeStringify(record.prepared))) !== record.preparedArtifactFingerprint) throw new Error("registration activation prepared artifact fingerprint is invalid");
|
|
2126
|
+
const receipt = record.receipt;
|
|
2127
|
+
if (receipt.operation !== "registration_activate" || receipt.registrationCeremonyId !== registrationCeremonyId || receipt.operationFingerprint !== record.requestFingerprint || !isRegistrationEcdsaReadyReceipt(receipt) || receipt.committed.nearProvisioning?.status !== "near_pending" || receipt.committed.installation === void 0) throw new Error("registration activation receipt has no valid mixed installation projection");
|
|
2128
|
+
const projection = receipt.committed.installation;
|
|
2129
|
+
const foundingDeviceId = receipt.foundingAuthority.principal.deviceId;
|
|
2130
|
+
const derivedAuthority = registrationWalletAuthAuthority({
|
|
2131
|
+
authority: projection.registrationAuthority,
|
|
2132
|
+
walletAuthMethodId: receipt.walletAuthMethodId
|
|
2133
|
+
});
|
|
2134
|
+
const nearPlan = projection.signerPlan.branches.find((branch) => branch.kind === "near_ed25519");
|
|
2135
|
+
const ecdsaPlan = projection.signerPlan.branches.find((branch) => branch.kind === "evm_family_ecdsa");
|
|
2136
|
+
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");
|
|
2137
|
+
return {
|
|
2138
|
+
receipt,
|
|
2139
|
+
projection,
|
|
2140
|
+
prepared: record.prepared
|
|
2141
|
+
};
|
|
2142
|
+
}
|
|
2143
|
+
async prepareNearProvisioningOperation(registrationCeremonyId, allocated) {
|
|
2144
|
+
const ceremony = await this.getRegistrationCeremonyIntentStore().getCeremony(registrationCeremonyId);
|
|
2145
|
+
if (!ceremony) {
|
|
2146
|
+
const committed = await this.readCommittedRegistrationInstallation(registrationCeremonyId);
|
|
2147
|
+
if (!committed) throw new Error("Registration ceremony is unavailable for identity preparation");
|
|
2148
|
+
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");
|
|
2149
|
+
return committed.prepared;
|
|
2150
|
+
}
|
|
2151
|
+
const prepared = allocated ?? walletRegistrationOperationPreparedFromCeremony(ceremony);
|
|
2152
|
+
const authority = verifiedRegistrationCeremonyAuthority(ceremony);
|
|
2153
|
+
if (!authority) return prepared;
|
|
2154
|
+
const persisted = await this.walletAuthMethods.readActiveRegistrationIdentity(authority);
|
|
2155
|
+
if (!persisted) return prepared;
|
|
2156
|
+
return {
|
|
2157
|
+
kind: prepared.kind,
|
|
2158
|
+
walletAuthorityId: persisted.walletAuthorityId,
|
|
2159
|
+
deviceId: prepared.deviceId,
|
|
2160
|
+
walletAuthMethodId: persisted.walletAuthMethodId
|
|
2161
|
+
};
|
|
2162
|
+
}
|
|
2163
|
+
async commitDeferredEd25519Signer(args, prepared) {
|
|
2164
|
+
const ownerProofContext = await this.readRegistrationOwnerProofContext(args.input.registrationCeremonyId);
|
|
2165
|
+
if (!ownerProofContext) throw new Error("Registration owner proof context is unavailable");
|
|
2166
|
+
const ceremony = await this.getRegistrationCeremonyIntentStore().getCeremony(args.input.registrationCeremonyId);
|
|
2167
|
+
let recovery = null;
|
|
2168
|
+
let registrationAuthority;
|
|
2169
|
+
let sessionPredecessor;
|
|
2170
|
+
if (ceremony) {
|
|
2171
|
+
const authority = verifiedRegistrationCeremonyAuthority(ceremony);
|
|
2172
|
+
if (!authority) throw new Error("Registration authority is unavailable before finalize");
|
|
2173
|
+
registrationAuthority = authority;
|
|
2174
|
+
sessionPredecessor = { kind: "ed25519_only" };
|
|
2175
|
+
} else {
|
|
2176
|
+
const committed = await this.readCommittedRegistrationInstallation(args.input.registrationCeremonyId);
|
|
2177
|
+
if (!committed) throw new Error("Committed registration installation is unavailable");
|
|
2178
|
+
recovery = registrationFinalizeRecoveryFromCommittedInstallation({
|
|
2179
|
+
setupClaims: args.setupClaims,
|
|
2180
|
+
projection: committed.projection
|
|
2181
|
+
});
|
|
2182
|
+
const authority = verifiedRegistrationCeremonyAuthority(recovery.ceremony);
|
|
2183
|
+
if (!authority) throw new Error("Committed registration installation has no verified authority");
|
|
2184
|
+
registrationAuthority = authority;
|
|
2185
|
+
const activationReceipt = committed.receipt;
|
|
2186
|
+
if (!isRegistrationEcdsaReadyReceipt(activationReceipt)) throw new Error("Committed mixed registration receipt is not ECDSA-ready");
|
|
2187
|
+
if (activationReceipt.committed.session.tokens.kind !== "evm_family_ecdsa") throw new Error("Committed mixed registration is missing its ECDSA session projection");
|
|
2188
|
+
sessionPredecessor = {
|
|
2189
|
+
kind: "mixed",
|
|
2190
|
+
ecdsa: activationReceipt.committed.session.tokens.ecdsa
|
|
2191
|
+
};
|
|
2192
|
+
}
|
|
2193
|
+
const effectivePrepared = await this.prepareNearProvisioningOperation(args.input.registrationCeremonyId, prepared);
|
|
2194
|
+
const committed = await this.executeWalletRegistrationFinalize({
|
|
2195
|
+
kind: "near_ed25519",
|
|
2196
|
+
registrationCeremonyId: args.input.registrationCeremonyId,
|
|
2197
|
+
idempotencyKey: args.input.idempotencyKey,
|
|
2198
|
+
ed25519: args.input.ed25519,
|
|
2199
|
+
emailOtpEnrollment: args.input.emailOtpEnrollment,
|
|
2200
|
+
walletCustodyCommit: args.input.walletCustodyCommit
|
|
2201
|
+
}, effectivePrepared, recovery);
|
|
2202
|
+
const finalized = committed.ok ? committed : throwIfRouterAbEd25519YaoRetryableSideEffectFailureV1(committed);
|
|
2203
|
+
if (!finalized.ok || finalized.kind !== "near_ed25519") return unissuedRegistrationCommit(finalized);
|
|
2204
|
+
const proof = await buildRegistrationOwnerProof({
|
|
2205
|
+
registrationCeremonyId: args.input.registrationCeremonyId,
|
|
2206
|
+
authMethod: finalized.authMethod,
|
|
2207
|
+
authority: finalized.authority,
|
|
2208
|
+
tenantId: this.authorizationTenantId,
|
|
2209
|
+
expectedOrigin: ownerProofContext.expectedOrigin,
|
|
2210
|
+
expiresAtMs: ownerProofContext.expiresAtMs
|
|
2211
|
+
});
|
|
2212
|
+
const issuedRegistrationSession = await issueDirectRegistrationEstablishedEd25519Session({
|
|
2213
|
+
authorizationService: this.authorizationService,
|
|
2214
|
+
authorizationTenantId: this.authorizationTenantId,
|
|
2215
|
+
walletAuthMethods: this.walletAuthMethods,
|
|
2216
|
+
registrationCeremonyId: args.input.registrationCeremonyId,
|
|
2217
|
+
authority: finalized.authority,
|
|
2218
|
+
registrationAuthority,
|
|
2219
|
+
walletAuthMethodId: effectivePrepared.walletAuthMethodId,
|
|
2220
|
+
expiresAtMs: Date.now() + DEFAULT_WALLET_SESSION_TTL_MS,
|
|
2221
|
+
remainingUses: 3,
|
|
2222
|
+
publicResult: finalized.ed25519,
|
|
2223
|
+
predecessor: sessionPredecessor,
|
|
2224
|
+
keyManifestDigestB64u: finalized.custodyKeyManifestDigestB64u,
|
|
2225
|
+
proof
|
|
2226
|
+
});
|
|
2227
|
+
switch (issuedRegistrationSession.kind) {
|
|
2228
|
+
case "issued": return {
|
|
2229
|
+
kind: "session_issued",
|
|
2230
|
+
response: {
|
|
2231
|
+
...finalized,
|
|
2232
|
+
registrationEstablishedSession: {
|
|
2233
|
+
kind: "issued",
|
|
2234
|
+
session: issuedRegistrationSession.session
|
|
2235
|
+
}
|
|
2236
|
+
},
|
|
2237
|
+
issuedAtMs: issuedRegistrationSession.issuedAtMs,
|
|
2238
|
+
expectedOrigin: ownerProofContext.expectedOrigin
|
|
2239
|
+
};
|
|
2240
|
+
case "already_committed": return {
|
|
2241
|
+
kind: "session_issued",
|
|
2242
|
+
response: {
|
|
2243
|
+
...finalized,
|
|
2244
|
+
registrationEstablishedSession: {
|
|
2245
|
+
kind: "already_committed",
|
|
2246
|
+
session: issuedRegistrationSession.session,
|
|
2247
|
+
next: issuedRegistrationSession.next
|
|
2248
|
+
}
|
|
2249
|
+
},
|
|
2250
|
+
issuedAtMs: issuedRegistrationSession.issuedAtMs,
|
|
2251
|
+
expectedOrigin: ownerProofContext.expectedOrigin
|
|
2252
|
+
};
|
|
2253
|
+
default: return assertNeverD1RegistrationSessionIssuance(issuedRegistrationSession);
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
async replayWalletRegistrationActivateCommit(receipt) {
|
|
2257
|
+
if (receipt.operation !== "registration_activate") throw new Error("Registration activation receipt operation is invalid");
|
|
2258
|
+
switch (receipt.committed.kind) {
|
|
2259
|
+
case "error": return replayedRegistrationCommit(receipt.committed.error);
|
|
2260
|
+
case "near_pending": {
|
|
2261
|
+
if (!isRegistrationNearPendingReceipt(receipt)) throw new Error("Registration pending receipt branch is invalid");
|
|
2262
|
+
const authMethod = registrationReplayAuthMethodFields(receipt);
|
|
2263
|
+
if (authMethod.kind === "passkey") return replayedRegistrationCommit({
|
|
2264
|
+
ok: true,
|
|
2265
|
+
kind: "near_ed25519",
|
|
2266
|
+
walletId: receipt.walletId,
|
|
2267
|
+
authority: receipt.authority,
|
|
2268
|
+
authMethod: authMethod.authMethod,
|
|
2269
|
+
rpId: authMethod.rpId,
|
|
2270
|
+
...receipt.registrationDiagnostics ? { registrationDiagnostics: receipt.registrationDiagnostics } : {},
|
|
2271
|
+
nearProvisioning: { status: "near_pending" }
|
|
2272
|
+
});
|
|
2273
|
+
return replayedRegistrationCommit({
|
|
2274
|
+
ok: true,
|
|
2275
|
+
kind: "near_ed25519",
|
|
2276
|
+
walletId: receipt.walletId,
|
|
2277
|
+
authority: receipt.authority,
|
|
2278
|
+
authMethod: authMethod.authMethod,
|
|
2279
|
+
...receipt.registrationDiagnostics ? { registrationDiagnostics: receipt.registrationDiagnostics } : {},
|
|
2280
|
+
nearProvisioning: { status: "near_pending" }
|
|
2281
|
+
});
|
|
2282
|
+
}
|
|
2283
|
+
case "ecdsa_ready": {
|
|
2284
|
+
if (!isRegistrationEcdsaReadyReceipt(receipt)) throw new Error("Registration activation receipt branch is invalid");
|
|
2285
|
+
const registrationEstablishedSession = replayDirectRegistrationEstablishedEcdsaSession(receipt);
|
|
2286
|
+
const authMethod = registrationReplayAuthMethodFields(receipt);
|
|
2287
|
+
const committedFields = {
|
|
2288
|
+
ok: true,
|
|
2289
|
+
kind: "evm_family_ecdsa",
|
|
2290
|
+
walletId: receipt.walletId,
|
|
2291
|
+
authority: receipt.authority,
|
|
2292
|
+
foundingAuthority: receipt.foundingAuthority,
|
|
2293
|
+
foundingAuthMethod: receipt.foundingAuthMethod,
|
|
2294
|
+
...receipt.registrationDiagnostics ? { registrationDiagnostics: receipt.registrationDiagnostics } : {},
|
|
2295
|
+
...receipt.walletCustody ? { walletCustody: receipt.walletCustody } : {},
|
|
2296
|
+
custodyKeyManifestDigestB64u: receipt.custodyKeyManifestDigestB64u,
|
|
2297
|
+
ecdsa: {
|
|
2298
|
+
...receipt.committed.ecdsa,
|
|
2299
|
+
walletKeys: [...receipt.committed.ecdsa.walletKeys]
|
|
2300
|
+
},
|
|
2301
|
+
registrationEstablishedSession,
|
|
2302
|
+
...receipt.committed.nearProvisioning ? { nearProvisioning: receipt.committed.nearProvisioning } : {}
|
|
2303
|
+
};
|
|
2304
|
+
if (authMethod.kind === "passkey") return replayedRegistrationCommit({
|
|
2305
|
+
...committedFields,
|
|
2306
|
+
authMethod: authMethod.authMethod,
|
|
2307
|
+
rpId: authMethod.rpId
|
|
2308
|
+
});
|
|
2309
|
+
return replayedRegistrationCommit({
|
|
2310
|
+
...committedFields,
|
|
2311
|
+
authMethod: authMethod.authMethod
|
|
2312
|
+
});
|
|
2313
|
+
}
|
|
2314
|
+
case "near_ready": throw new Error("Registration activation receipt contains a deferred NEAR result");
|
|
2315
|
+
default: return assertNeverRegistrationReceiptCommit(receipt.committed);
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
async replayWalletRegistrationNearProvisioningCommit(receipt) {
|
|
2319
|
+
if (receipt.operation !== "near_provisioning") throw new Error("Registration NEAR provisioning receipt operation is invalid");
|
|
2320
|
+
if (receipt.committed.kind === "error") return replayedRegistrationCommit(receipt.committed.error);
|
|
2321
|
+
if (receipt.committed.kind !== "near_ready") throw new Error("Registration NEAR provisioning receipt branch is invalid");
|
|
2322
|
+
if (!isRegistrationNearReadyReceipt(receipt)) throw new Error("Registration NEAR provisioning receipt branch is invalid");
|
|
2323
|
+
const authMethod = registrationReplayAuthMethodFields(receipt);
|
|
2324
|
+
const registrationEstablishedSession = replayDirectRegistrationEstablishedEd25519Session(receipt);
|
|
2325
|
+
const committedFields = {
|
|
2326
|
+
ok: true,
|
|
2327
|
+
kind: "near_ed25519",
|
|
2328
|
+
walletId: receipt.walletId,
|
|
2329
|
+
authority: receipt.authority,
|
|
2330
|
+
foundingAuthority: receipt.foundingAuthority,
|
|
2331
|
+
foundingAuthMethod: receipt.foundingAuthMethod,
|
|
2332
|
+
...receipt.registrationDiagnostics ? { registrationDiagnostics: receipt.registrationDiagnostics } : {},
|
|
2333
|
+
...receipt.walletCustody ? { walletCustody: receipt.walletCustody } : {},
|
|
2334
|
+
custodyKeyManifestDigestB64u: receipt.custodyKeyManifestDigestB64u,
|
|
2335
|
+
authorityScope: receipt.committed.authorityScope,
|
|
2336
|
+
accountProvisioning: receipt.committed.accountProvisioning,
|
|
2337
|
+
resolvedAccount: receipt.committed.resolvedAccount,
|
|
2338
|
+
ed25519: receipt.committed.ed25519,
|
|
2339
|
+
registrationEstablishedSession
|
|
2340
|
+
};
|
|
2341
|
+
if (authMethod.kind === "passkey") return replayedRegistrationCommit({
|
|
2342
|
+
...committedFields,
|
|
2343
|
+
authMethod: authMethod.authMethod,
|
|
2344
|
+
rpId: authMethod.rpId
|
|
2345
|
+
});
|
|
2346
|
+
return replayedRegistrationCommit({
|
|
2347
|
+
...committedFields,
|
|
2348
|
+
authMethod: authMethod.authMethod
|
|
2349
|
+
});
|
|
2350
|
+
}
|
|
2351
|
+
/**
|
|
2352
|
+
* Deferred NEAR provisioning. Verifies the signed setup, then reuses the
|
|
2353
|
+
* existing deferred Ed25519 commit — the same path lazy-Yao 4+5 built — so
|
|
2354
|
+
* signer installation and the implicit-account projection keep one
|
|
2355
|
+
* implementation across both plans.
|
|
2356
|
+
*
|
|
2357
|
+
* A retryable failure leaves the pending wallet intact: the wallet must not
|
|
2358
|
+
* be destroyed because its signer ceremony needs another attempt.
|
|
2359
|
+
*/
|
|
2360
|
+
async completeWalletRegistrationNearProvisioning(input) {
|
|
2361
|
+
try {
|
|
2362
|
+
const verified = await verifyWalletRegistrationSetupClaims(input.verifier, input.signedSetup, {
|
|
2363
|
+
registrationCeremonyId: input.registrationCeremonyId,
|
|
2364
|
+
nowMs: Date.now()
|
|
2365
|
+
});
|
|
2366
|
+
if (!verified.ok) return {
|
|
2367
|
+
ok: false,
|
|
2368
|
+
code: verified.code,
|
|
2369
|
+
message: verified.message
|
|
2370
|
+
};
|
|
2371
|
+
const requestFingerprint = base64UrlEncode(await sha256BytesUtf8(alphabetizeStringify({
|
|
2372
|
+
version: "wallet_registration_near_provisioning_digest_v1",
|
|
2373
|
+
registrationCeremonyId: input.registrationCeremonyId,
|
|
2374
|
+
setupDigestB64u: verified.claims.setupDigestB64u,
|
|
2375
|
+
idempotencyKey: input.idempotencyKey,
|
|
2376
|
+
ed25519: input.ed25519,
|
|
2377
|
+
emailOtpEnrollment: input.emailOtpEnrollment
|
|
2378
|
+
})));
|
|
2379
|
+
const run = await runRouterAbEd25519YaoRegistrationSideEffectV2(this.nearProvisioningSideEffects, {
|
|
2380
|
+
kind: "prepared_resumable",
|
|
2381
|
+
operation: "near_provisioning",
|
|
2382
|
+
key: `near-provisioning:${input.registrationCeremonyId}:${input.idempotencyKey}`,
|
|
2383
|
+
requestFingerprint,
|
|
2384
|
+
resumeAfterMs: D1_WALLET_REGISTRATION_OPERATION_RESUME_AFTER_MS,
|
|
2385
|
+
nowMs: Date.now,
|
|
2386
|
+
prepare: async () => await this.prepareNearProvisioningOperation(input.registrationCeremonyId),
|
|
2387
|
+
derivePreparedArtifactFingerprint: async (prepared) => base64UrlEncode(await sha256BytesUtf8(alphabetizeStringify(prepared))),
|
|
2388
|
+
execute: this.commitDeferredEd25519Signer.bind(this, {
|
|
2389
|
+
input,
|
|
2390
|
+
setupClaims: verified.claims
|
|
2391
|
+
}),
|
|
2392
|
+
projectReceipt: (execution) => projectWalletRegistrationSessionCommitReceiptV2({
|
|
2393
|
+
operation: "near_provisioning",
|
|
2394
|
+
operationFingerprint: requestFingerprint,
|
|
2395
|
+
registrationCeremonyId: input.registrationCeremonyId,
|
|
2396
|
+
execution
|
|
2397
|
+
}),
|
|
2398
|
+
replay: this.replayWalletRegistrationNearProvisioningCommit.bind(this)
|
|
2399
|
+
});
|
|
2400
|
+
switch (run.kind) {
|
|
2401
|
+
case "executed":
|
|
2402
|
+
case "exact_replay": break;
|
|
2403
|
+
case "request_conflict": return {
|
|
2404
|
+
ok: false,
|
|
2405
|
+
code: "idempotency_conflict",
|
|
2406
|
+
message: "NEAR provisioning idempotency key was reused for a different request"
|
|
2407
|
+
};
|
|
2408
|
+
case "in_progress": return {
|
|
2409
|
+
ok: false,
|
|
2410
|
+
code: "conflict",
|
|
2411
|
+
message: "NEAR provisioning is already in progress; retry later"
|
|
2412
|
+
};
|
|
2413
|
+
case "uncertain": return {
|
|
2414
|
+
ok: false,
|
|
2415
|
+
code: "internal",
|
|
2416
|
+
message: run.message || "Failed to reconcile NEAR provisioning",
|
|
2417
|
+
nearProvisioning: { status: "near_failed_retryable" }
|
|
2418
|
+
};
|
|
2419
|
+
default: return {
|
|
2420
|
+
ok: false,
|
|
2421
|
+
code: "internal",
|
|
2422
|
+
message: "unsupported provisioning outcome"
|
|
2423
|
+
};
|
|
2424
|
+
}
|
|
2425
|
+
const committed = run.value.response;
|
|
2426
|
+
if (!committed.ok) return {
|
|
2427
|
+
ok: false,
|
|
2428
|
+
code: committed.code,
|
|
2429
|
+
message: committed.message,
|
|
2430
|
+
nearProvisioning: { status: "near_failed_retryable" }
|
|
2431
|
+
};
|
|
2432
|
+
if (committed.kind !== "near_ed25519") return {
|
|
2433
|
+
ok: false,
|
|
2434
|
+
code: "internal",
|
|
2435
|
+
message: "NEAR provisioning committed a different signer branch"
|
|
2436
|
+
};
|
|
2437
|
+
if (!isWalletRegistrationNearProvisioningSuccess(committed)) return {
|
|
2438
|
+
ok: false,
|
|
2439
|
+
code: "internal",
|
|
2440
|
+
message: "NEAR provisioning did not establish a Wallet Session",
|
|
2441
|
+
nearProvisioning: { status: "near_failed_retryable" }
|
|
2442
|
+
};
|
|
2443
|
+
await cleanupFinalizedRegistrationCeremony({
|
|
2444
|
+
store: this.getRegistrationCeremonyIntentStore(),
|
|
2445
|
+
registrationCeremonyId: input.registrationCeremonyId
|
|
2446
|
+
});
|
|
2447
|
+
return {
|
|
2448
|
+
...committed,
|
|
2449
|
+
nearProvisioning: { status: "near_ready" }
|
|
2450
|
+
};
|
|
2451
|
+
} catch (error) {
|
|
2452
|
+
return {
|
|
2453
|
+
ok: false,
|
|
2454
|
+
code: "internal",
|
|
2455
|
+
message: errorMessage(error) || "Failed to complete NEAR provisioning",
|
|
2456
|
+
nearProvisioning: { status: "near_failed_retryable" }
|
|
2457
|
+
};
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
/**
|
|
2461
|
+
* Persists the Ed25519-only wallet in `near_pending`: wallet, profile, and
|
|
2462
|
+
* authentication state, and no signer record — the signer does not exist
|
|
2463
|
+
* until deferred Yao produces it.
|
|
2464
|
+
*
|
|
2465
|
+
* The terminal response carries no signer, resolved account, or key
|
|
2466
|
+
* identity, because none of those are known yet. Reporting them would be
|
|
2467
|
+
* fabricating readiness.
|
|
2468
|
+
*/
|
|
2469
|
+
async commitEd25519PendingWallet(input) {
|
|
2470
|
+
const now = Date.now();
|
|
2471
|
+
const ceremony = input.ceremony;
|
|
2472
|
+
const authority = input.authority;
|
|
2473
|
+
const wallet = buildD1WalletRecord({
|
|
2474
|
+
walletId: ceremony.intent.walletId,
|
|
2475
|
+
now
|
|
2476
|
+
});
|
|
2477
|
+
const walletAuthAuthority = registrationWalletAuthAuthority({
|
|
2478
|
+
authority,
|
|
2479
|
+
walletAuthMethodId: input.walletAuthMethodId
|
|
2480
|
+
});
|
|
2481
|
+
switch (authority.kind) {
|
|
2482
|
+
case "passkey":
|
|
2483
|
+
await this.walletRegistrationCommitStore.commit({
|
|
2484
|
+
kind: "passkey_wallet_registration_commit_v1",
|
|
2485
|
+
wallet,
|
|
2486
|
+
walletSigners: [],
|
|
2487
|
+
authority,
|
|
2488
|
+
now
|
|
2489
|
+
});
|
|
2490
|
+
break;
|
|
2491
|
+
case "email_otp": {
|
|
2492
|
+
const enrollment = await this.emailOtpRegistrationEnrollmentFinalizer.prepareRegistrationFinalize({
|
|
2493
|
+
authority,
|
|
2494
|
+
request: input.enrollment,
|
|
2495
|
+
walletId: ceremony.intent.walletId,
|
|
2496
|
+
orgId: ceremony.orgId,
|
|
2497
|
+
nowMs: now
|
|
2498
|
+
});
|
|
2499
|
+
if (!enrollment.ok) return enrollment;
|
|
2500
|
+
if (!enrollment.persistence) return {
|
|
2501
|
+
ok: false,
|
|
2502
|
+
code: "invalid_state",
|
|
2503
|
+
message: "Email OTP registration is missing enrollment persistence state"
|
|
2504
|
+
};
|
|
2505
|
+
await this.walletRegistrationCommitStore.commit({
|
|
2506
|
+
kind: "email_otp_wallet_registration_commit_v1",
|
|
2507
|
+
wallet,
|
|
2508
|
+
walletSigners: [],
|
|
2509
|
+
authority,
|
|
2510
|
+
emailOtp: this.emailOtpRegistrationEnrollmentFinalizer.prepareRegistrationCommitPlan(enrollment.persistence),
|
|
2511
|
+
now
|
|
2512
|
+
});
|
|
2513
|
+
const completedIdentity = await this.emailOtpRegistrationEnrollmentFinalizer.completeRegistrationIdentity({
|
|
2514
|
+
authority,
|
|
2515
|
+
walletId: ceremony.intent.walletId
|
|
2516
|
+
});
|
|
2517
|
+
if (!completedIdentity.ok) return completedIdentity;
|
|
2518
|
+
break;
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
const authMethod = walletRegistrationFinalizeAuthMethodFromAuthority(authority);
|
|
2522
|
+
if (authMethod.kind === "passkey") {
|
|
2523
|
+
if (!isPasskeyWalletAuthAuthority(walletAuthAuthority)) return {
|
|
2524
|
+
ok: false,
|
|
2525
|
+
code: "internal",
|
|
2526
|
+
message: "Passkey registration returned a different authority"
|
|
2527
|
+
};
|
|
2528
|
+
return buildWalletRegistrationActivatePendingPasskeyResponse({
|
|
2529
|
+
walletId: ceremony.intent.walletId,
|
|
2530
|
+
authority: walletAuthAuthority,
|
|
2531
|
+
authMethod,
|
|
2532
|
+
rpId: finalizePasskeyRpId(authority)
|
|
2533
|
+
});
|
|
2534
|
+
}
|
|
2535
|
+
if (!isEmailOtpWalletAuthAuthority(walletAuthAuthority)) return {
|
|
2536
|
+
ok: false,
|
|
2537
|
+
code: "internal",
|
|
2538
|
+
message: "Email OTP registration returned a different authority"
|
|
2539
|
+
};
|
|
2540
|
+
return buildWalletRegistrationActivatePendingEmailOtpResponse({
|
|
2541
|
+
walletId: ceremony.intent.walletId,
|
|
2542
|
+
authority: walletAuthAuthority,
|
|
2543
|
+
authMethod
|
|
2544
|
+
});
|
|
2545
|
+
}
|
|
2546
|
+
/**
|
|
2547
|
+
* Ed25519-only respond. The wallet's sole signer is Yao, and that is
|
|
2548
|
+
* deliberately not a reason to block: the admission is returned as deferred
|
|
2549
|
+
* work exactly as on a mixed plan, and the wallet lives in `near_pending`
|
|
2550
|
+
* until the computation completes.
|
|
2551
|
+
*/
|
|
2552
|
+
/**
|
|
2553
|
+
* Respond replay stays authority-bound.
|
|
2554
|
+
*
|
|
2555
|
+
* `signedSetup` is client-carried, so possession of it must never recover a
|
|
2556
|
+
* stored respond result. Re-verifying the proof is necessary but not
|
|
2557
|
+
* sufficient: registration *mints* the credential, so a fresh passkey over
|
|
2558
|
+
* the same challenge would verify. The replayed proof must therefore resolve
|
|
2559
|
+
* to the same authority that admitted the stored result.
|
|
2560
|
+
*/
|
|
2561
|
+
async verifyRespondReplayAuthority(input) {
|
|
2562
|
+
const ceremony = input.ceremony;
|
|
2563
|
+
const storedAuthority = verifiedRegistrationCeremonyAuthority(ceremony);
|
|
2564
|
+
if (!storedAuthority) return {
|
|
2565
|
+
ok: false,
|
|
2566
|
+
code: "invalid_state",
|
|
2567
|
+
message: "registration ceremony has no verified authority to replay"
|
|
2568
|
+
};
|
|
2569
|
+
const verified = await this.walletAuthMethods.verifyRegistrationAuthorityForIntent({
|
|
2570
|
+
orgId: ceremony.orgId,
|
|
2571
|
+
authority: input.authorityInput,
|
|
2572
|
+
expectedDigestB64u: ceremony.digestB64u,
|
|
2573
|
+
expectedOrigin: input.expectedOrigin,
|
|
2574
|
+
intent: ceremony.intent,
|
|
2575
|
+
verificationOperationId: ceremony.registrationCeremonyId,
|
|
2576
|
+
verificationReceiptExpiresAtMs: ceremony.expiresAtMs,
|
|
2577
|
+
...input.userAgent ? { userAgent: input.userAgent } : {}
|
|
2578
|
+
});
|
|
2579
|
+
if (!verified.ok) return {
|
|
2580
|
+
ok: false,
|
|
2581
|
+
code: verified.code,
|
|
2582
|
+
message: verified.message
|
|
2583
|
+
};
|
|
2584
|
+
if (!storedRegistrationAuthoritiesMatch(storedAuthority, verified.authority)) return {
|
|
2585
|
+
ok: false,
|
|
2586
|
+
code: "unauthorized",
|
|
2587
|
+
message: "registration respond replay presented a different authority"
|
|
2588
|
+
};
|
|
2589
|
+
return { ok: true };
|
|
2590
|
+
}
|
|
2591
|
+
async respondEd25519OnlyRegistration(input) {
|
|
2592
|
+
const ceremony = input.ceremony;
|
|
2593
|
+
const stored = storedRespondEd25519DeferredWork(ceremony.signerState);
|
|
2594
|
+
if (stored) {
|
|
2595
|
+
const replayAuthority = await this.verifyRespondReplayAuthority({
|
|
2596
|
+
ceremony,
|
|
2597
|
+
authorityInput: input.authorityInput,
|
|
2598
|
+
expectedOrigin: input.expectedOrigin,
|
|
2599
|
+
...input.userAgent ? { userAgent: input.userAgent } : {}
|
|
2600
|
+
});
|
|
2601
|
+
if (!replayAuthority.ok) return {
|
|
2602
|
+
ok: false,
|
|
2603
|
+
code: replayAuthority.code,
|
|
2604
|
+
message: replayAuthority.message
|
|
2605
|
+
};
|
|
2606
|
+
return {
|
|
2607
|
+
ok: true,
|
|
2608
|
+
registrationCeremonyId: ceremony.registrationCeremonyId,
|
|
2609
|
+
kind: "near_ed25519",
|
|
2610
|
+
ed25519: stored
|
|
2611
|
+
};
|
|
2612
|
+
}
|
|
2613
|
+
const verifiedAuthority = await this.walletAuthMethods.verifyRegistrationAuthorityForIntent({
|
|
2614
|
+
orgId: ceremony.orgId,
|
|
2615
|
+
authority: input.authorityInput,
|
|
2616
|
+
expectedDigestB64u: ceremony.digestB64u,
|
|
2617
|
+
expectedOrigin: input.expectedOrigin,
|
|
2618
|
+
intent: ceremony.intent,
|
|
2619
|
+
verificationOperationId: ceremony.registrationCeremonyId,
|
|
2620
|
+
verificationReceiptExpiresAtMs: ceremony.expiresAtMs,
|
|
2621
|
+
...input.userAgent ? { userAgent: input.userAgent } : {}
|
|
2622
|
+
});
|
|
2623
|
+
if (!verifiedAuthority.ok) return {
|
|
2624
|
+
ok: false,
|
|
2625
|
+
code: verifiedAuthority.code,
|
|
2626
|
+
message: verifiedAuthority.message
|
|
2627
|
+
};
|
|
2628
|
+
const authority = verifiedAuthority.authority;
|
|
2629
|
+
if (authority.walletId !== ceremony.intent.walletId) return {
|
|
2630
|
+
ok: false,
|
|
2631
|
+
code: "scope_mismatch",
|
|
2632
|
+
message: "registration authority walletId does not match the ceremony"
|
|
2633
|
+
};
|
|
2634
|
+
const admitted = await this.admitRespondEd25519Branch({
|
|
2635
|
+
ceremony,
|
|
2636
|
+
branch: input.branch,
|
|
2637
|
+
authority,
|
|
2638
|
+
registrationBearerToken: input.registrationBearerToken
|
|
2639
|
+
});
|
|
2640
|
+
if (!admitted.ok) return {
|
|
2641
|
+
ok: false,
|
|
2642
|
+
code: admitted.code,
|
|
2643
|
+
message: admitted.message
|
|
2644
|
+
};
|
|
2645
|
+
if (!admitted.branch || !admitted.deferred) return {
|
|
2646
|
+
ok: false,
|
|
2647
|
+
code: "internal",
|
|
2648
|
+
message: "Ed25519 admission produced no branch"
|
|
2649
|
+
};
|
|
2650
|
+
await this.getRegistrationCeremonyIntentStore().commitEcdsaClaim({
|
|
2651
|
+
expected: input.snapshot,
|
|
2652
|
+
next: {
|
|
2653
|
+
...ceremony,
|
|
2654
|
+
authorityState: {
|
|
2655
|
+
kind: "verified",
|
|
2656
|
+
authority
|
|
2657
|
+
},
|
|
2658
|
+
signerState: {
|
|
2659
|
+
kind: "signer_set_registration",
|
|
2660
|
+
branches: [admitted.branch]
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
});
|
|
2664
|
+
return {
|
|
2665
|
+
ok: true,
|
|
2666
|
+
registrationCeremonyId: ceremony.registrationCeremonyId,
|
|
2667
|
+
kind: "near_ed25519",
|
|
2668
|
+
ed25519: admitted.deferred
|
|
2669
|
+
};
|
|
2670
|
+
}
|
|
2671
|
+
/**
|
|
2672
|
+
* Derives the authority-bound Yao admission now that the proof is verified.
|
|
2673
|
+
* Both auth methods take this path — the scope comes from the verified
|
|
2674
|
+
* authority, so Email OTP's `providerUserId` is established rather than
|
|
2675
|
+
* assumed.
|
|
2676
|
+
*/
|
|
2677
|
+
async admitRespondEd25519Branch(input) {
|
|
2678
|
+
if (!input.branch) return {
|
|
2679
|
+
ok: true,
|
|
2680
|
+
branch: null,
|
|
2681
|
+
deferred: null
|
|
2682
|
+
};
|
|
2683
|
+
const yaoRuntime = this.getEd25519YaoProductRegistration();
|
|
2684
|
+
if (!yaoRuntime) return {
|
|
2685
|
+
ok: false,
|
|
2686
|
+
code: "not_configured",
|
|
2687
|
+
message: "Ed25519 Yao product registration is not configured"
|
|
2688
|
+
};
|
|
2689
|
+
const admissionRequest = await buildRouterAbEd25519YaoProductAdmissionRequestV1({
|
|
2690
|
+
registrationCeremonyId: input.ceremony.registrationCeremonyId,
|
|
2691
|
+
walletId: input.ceremony.intent.walletId,
|
|
2692
|
+
signingRootId: normalizeOptionalTrimmedString(input.ceremony.signingRootId) || "",
|
|
2693
|
+
signingRootVersion: normalizeOptionalTrimmedString(input.ceremony.signingRootVersion) || "",
|
|
2694
|
+
authorityScope: registrationEd25519AuthorityScopeFromAuthority(input.authority),
|
|
2695
|
+
branch: input.branch,
|
|
2696
|
+
signingWorkerId: yaoRuntime.signingWorkerId,
|
|
2697
|
+
materialActivation: createRouterAbEd25519YaoMaterialActivationRefV1({
|
|
2698
|
+
walletId: input.ceremony.intent.walletId,
|
|
2699
|
+
signingWorkerId: yaoRuntime.signingWorkerId
|
|
2700
|
+
})
|
|
2701
|
+
});
|
|
2702
|
+
const admitted = await yaoRuntime.bindAndAdmitVerifiedRegistration({
|
|
2703
|
+
kind: "verified_registration_intent",
|
|
2704
|
+
registrationIntentGrant: registrationIntentGrantFromString(input.registrationBearerToken),
|
|
2705
|
+
intent: input.ceremony.intent,
|
|
2706
|
+
admissionRequest,
|
|
2707
|
+
expiresAtMs: input.ceremony.expiresAtMs
|
|
2708
|
+
});
|
|
2709
|
+
if (!admitted.ok) return {
|
|
2710
|
+
ok: false,
|
|
2711
|
+
code: admitted.code,
|
|
2712
|
+
message: admitted.message
|
|
2713
|
+
};
|
|
2714
|
+
return {
|
|
2715
|
+
ok: true,
|
|
2716
|
+
branch: buildStoredWalletRegistrationNearEd25519YaoAuthorizedBranch({
|
|
2717
|
+
branchKey: input.branch.branchKey,
|
|
2718
|
+
admissionRequest,
|
|
2719
|
+
admissionReceipt: admitted.value
|
|
2720
|
+
}),
|
|
2721
|
+
deferred: {
|
|
2722
|
+
status: "deferred",
|
|
2723
|
+
admissionRequest,
|
|
2724
|
+
admissionReceipt: admitted.value
|
|
2725
|
+
}
|
|
2726
|
+
};
|
|
2727
|
+
}
|
|
2728
|
+
/**
|
|
2729
|
+
* Refactor 94C. `/wallets/register/activate` — activation and finalization
|
|
2730
|
+
* as one irreversible step behind one Gateway operation row.
|
|
2731
|
+
*
|
|
2732
|
+
* Previously activation and finalization were separate requests with
|
|
2733
|
+
* separate idempotency: activation claimed and CAS'd the ceremony branch,
|
|
2734
|
+
* then finalize opened its own side-effect journal *and* maintained a second
|
|
2735
|
+
* replay cache. Three records guarding one irreversible commit, each with
|
|
2736
|
+
* its own failure window.
|
|
2737
|
+
*
|
|
2738
|
+
* Here the operation row is the only one. Its claim is the activation claim,
|
|
2739
|
+
* and its completion record holds one credential-free session receipt plus
|
|
2740
|
+
* the request fingerprint. The direct-capability first response carries one
|
|
2741
|
+
* ephemeral primary credential after the receipt CAS; exact retry returns
|
|
2742
|
+
* the committed projection without fabricating a credential or repeating a
|
|
2743
|
+
* custody effect. A conflicting fingerprint is refused
|
|
2744
|
+
* before execution; an ambiguous outcome after the custody call stays
|
|
2745
|
+
* `uncertain` rather than being guessed either way.
|
|
2746
|
+
*/
|
|
2747
|
+
async activateWalletRegistration(input, traceContext) {
|
|
2748
|
+
try {
|
|
2749
|
+
const verifiedSetup = await verifyWalletRegistrationSetupClaims(input.verifier, input.signedSetup, {
|
|
2750
|
+
registrationCeremonyId: input.registrationCeremonyId,
|
|
2751
|
+
nowMs: Date.now()
|
|
2752
|
+
});
|
|
2753
|
+
if (!verifiedSetup.ok) return {
|
|
2754
|
+
ok: false,
|
|
2755
|
+
code: verifiedSetup.code,
|
|
2756
|
+
message: verifiedSetup.message
|
|
2757
|
+
};
|
|
2758
|
+
const claims = verifiedSetup.claims;
|
|
2759
|
+
const idempotencyKey = normalizeOptionalTrimmedString(input.idempotencyKey);
|
|
2760
|
+
if (!idempotencyKey) return {
|
|
2761
|
+
ok: false,
|
|
2762
|
+
code: "invalid_body",
|
|
2763
|
+
message: "registration activate idempotencyKey is required"
|
|
2764
|
+
};
|
|
2765
|
+
const activateDigestB64u = base64UrlEncode(await sha256BytesUtf8(alphabetizeStringify({
|
|
2766
|
+
version: "wallet_registration_activate_digest_v1",
|
|
2767
|
+
registrationCeremonyId: claims.registrationCeremonyId,
|
|
2768
|
+
setupDigestB64u: claims.setupDigestB64u,
|
|
2769
|
+
idempotencyKey,
|
|
2770
|
+
ecdsa: input.ecdsa,
|
|
2771
|
+
...input.emailOtpEnrollment ? { emailOtpEnrollment: input.emailOtpEnrollment } : {}
|
|
2772
|
+
})));
|
|
2773
|
+
const run = await runRouterAbEd25519YaoRegistrationSideEffectV2(this.activateSideEffects, {
|
|
2774
|
+
kind: "prepared_resumable",
|
|
2775
|
+
operation: "registration_activate",
|
|
2776
|
+
key: `registration-activate:${claims.registrationCeremonyId}:${idempotencyKey}`,
|
|
2777
|
+
requestFingerprint: activateDigestB64u,
|
|
2778
|
+
resumeAfterMs: D1_WALLET_REGISTRATION_OPERATION_RESUME_AFTER_MS,
|
|
2779
|
+
nowMs: Date.now,
|
|
2780
|
+
prepare: async () => await this.prepareNearProvisioningOperation(claims.registrationCeremonyId),
|
|
2781
|
+
derivePreparedArtifactFingerprint: async (prepared) => base64UrlEncode(await sha256BytesUtf8(alphabetizeStringify(prepared))),
|
|
2782
|
+
execute: this.executeWalletRegistrationActivation.bind(this, {
|
|
2783
|
+
registrationCeremonyId: claims.registrationCeremonyId,
|
|
2784
|
+
idempotencyKey,
|
|
2785
|
+
input,
|
|
2786
|
+
traceContext
|
|
2787
|
+
}),
|
|
2788
|
+
projectReceipt: (execution) => projectWalletRegistrationSessionCommitReceiptV2({
|
|
2789
|
+
operation: "registration_activate",
|
|
2790
|
+
operationFingerprint: activateDigestB64u,
|
|
2791
|
+
registrationCeremonyId: claims.registrationCeremonyId,
|
|
2792
|
+
execution
|
|
2793
|
+
}),
|
|
2794
|
+
replay: this.replayWalletRegistrationActivateCommit.bind(this)
|
|
2795
|
+
});
|
|
2796
|
+
switch (run.kind) {
|
|
2797
|
+
case "executed":
|
|
2798
|
+
case "exact_replay":
|
|
2799
|
+
if (run.value.response.ok && run.value.response.kind === "evm_family_ecdsa") await cleanupFinalizedRegistrationCeremony({
|
|
2800
|
+
store: this.getRegistrationCeremonyIntentStore(),
|
|
2801
|
+
registrationCeremonyId: claims.registrationCeremonyId
|
|
2802
|
+
});
|
|
2803
|
+
return run.value.response;
|
|
2804
|
+
case "request_conflict": return {
|
|
2805
|
+
ok: false,
|
|
2806
|
+
code: "idempotency_conflict",
|
|
2807
|
+
message: "registration activate idempotency key was reused for a different request"
|
|
2808
|
+
};
|
|
2809
|
+
case "in_progress": return {
|
|
2810
|
+
ok: false,
|
|
2811
|
+
code: "conflict",
|
|
2812
|
+
message: "registration activation is already in progress; retry later"
|
|
2813
|
+
};
|
|
2814
|
+
case "uncertain": return {
|
|
2815
|
+
ok: false,
|
|
2816
|
+
code: "internal",
|
|
2817
|
+
message: run.message || "Failed to reconcile wallet registration activation"
|
|
2818
|
+
};
|
|
2819
|
+
default: return {
|
|
2820
|
+
ok: false,
|
|
2821
|
+
code: "internal",
|
|
2822
|
+
message: "registration activation returned an unsupported outcome"
|
|
2823
|
+
};
|
|
2824
|
+
}
|
|
2825
|
+
} catch (error) {
|
|
2826
|
+
return {
|
|
2827
|
+
ok: false,
|
|
2828
|
+
code: "internal",
|
|
2829
|
+
message: errorMessage(error) || "Failed to activate wallet registration"
|
|
2830
|
+
};
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
/**
|
|
2834
|
+
* Router/SigningWorker activation followed by the blocking finalize
|
|
2835
|
+
* persistence, as one unit inside the operation row. The commit is told the
|
|
2836
|
+
* operation row owns idempotency, so it maintains no replay cache of its own.
|
|
2837
|
+
*/
|
|
2838
|
+
async executeWalletRegistrationActivation(context, prepared) {
|
|
2839
|
+
const ceremony = await this.getRegistrationCeremonyIntentStore().getCeremony(context.registrationCeremonyId);
|
|
2840
|
+
if (!ceremony) return unissuedRegistrationCommit({
|
|
2841
|
+
ok: false,
|
|
2842
|
+
code: "not_found",
|
|
2843
|
+
message: "registration ceremony not found"
|
|
2844
|
+
});
|
|
2845
|
+
const ceremonyAuthority = verifiedRegistrationCeremonyAuthority(ceremony);
|
|
2846
|
+
if (!ceremonyAuthority) return unissuedRegistrationCommit({
|
|
2847
|
+
ok: false,
|
|
2848
|
+
code: "invalid_state",
|
|
2849
|
+
message: "registration ceremony has not verified its authority proof"
|
|
2850
|
+
});
|
|
2851
|
+
if (!registrationSignerBranchesFromPlan(ceremony.signerPlan).evmFamilyEcdsa) {
|
|
2852
|
+
const expectedOrigin = normalizeOptionalTrimmedString(ceremony.expectedOrigin);
|
|
2853
|
+
if (!expectedOrigin) return unissuedRegistrationCommit({
|
|
2854
|
+
ok: false,
|
|
2855
|
+
code: "invalid_state",
|
|
2856
|
+
message: "registration ceremony has no expected origin"
|
|
2857
|
+
});
|
|
2858
|
+
const pending = await this.commitEd25519PendingWallet({
|
|
2859
|
+
ceremony,
|
|
2860
|
+
authority: ceremonyAuthority,
|
|
2861
|
+
walletAuthMethodId: prepared.walletAuthMethodId,
|
|
2862
|
+
enrollment: { ...context.input.emailOtpEnrollment ? { emailOtpEnrollment: context.input.emailOtpEnrollment } : {} }
|
|
2863
|
+
});
|
|
2864
|
+
if (!pending.ok) return unissuedRegistrationCommit(pending);
|
|
2865
|
+
return {
|
|
2866
|
+
kind: "near_pending",
|
|
2867
|
+
response: pending,
|
|
2868
|
+
expectedOrigin
|
|
2869
|
+
};
|
|
2870
|
+
}
|
|
2871
|
+
if (!context.input.ecdsa) return unissuedRegistrationCommit({
|
|
2872
|
+
ok: false,
|
|
2873
|
+
code: "invalid_body",
|
|
2874
|
+
message: "browser-verified clientActivation is required for this signer plan"
|
|
2875
|
+
});
|
|
2876
|
+
const ecdsa = context.input.ecdsa;
|
|
2877
|
+
const activated = await this.activateWalletRegistrationEcdsa({
|
|
2878
|
+
registrationCeremonyId: context.registrationCeremonyId,
|
|
2879
|
+
ecdsa: {
|
|
2880
|
+
kind: "router_ab_ecdsa_registration_activation_v1",
|
|
2881
|
+
activationCorrelationId: ecdsa.activationCorrelationId,
|
|
2882
|
+
activationRequestDigestB64u: ecdsa.activationRequestDigestB64u,
|
|
2883
|
+
publicFacts: ecdsa.clientActivation
|
|
2884
|
+
}
|
|
2885
|
+
}, context.traceContext, context.idempotencyKey);
|
|
2886
|
+
if (!activated.ok) return unissuedRegistrationCommit(throwIfRouterAbEd25519YaoRetryableSideEffectFailureV1(activated));
|
|
2887
|
+
const keyHandle = activated.ecdsa.bootstrap?.keyHandle;
|
|
2888
|
+
if (!keyHandle) return unissuedRegistrationCommit({
|
|
2889
|
+
ok: false,
|
|
2890
|
+
code: "internal",
|
|
2891
|
+
message: "ECDSA activation completed without a key handle to commit"
|
|
2892
|
+
});
|
|
2893
|
+
const ownerProofContext = await this.readRegistrationOwnerProofContext(context.registrationCeremonyId);
|
|
2894
|
+
if (!ownerProofContext) throw new Error("Registration owner proof context is unavailable");
|
|
2895
|
+
const commit = await this.executeWalletRegistrationFinalize({
|
|
2896
|
+
kind: "evm_family_ecdsa",
|
|
2897
|
+
registrationCeremonyId: context.registrationCeremonyId,
|
|
2898
|
+
idempotencyKey: context.idempotencyKey,
|
|
2899
|
+
ecdsa: { expectedKeyHandles: [keyHandle] },
|
|
2900
|
+
...context.input.emailOtpEnrollment ? { emailOtpEnrollment: context.input.emailOtpEnrollment } : {},
|
|
2901
|
+
...context.input.walletCustodyCommit !== void 0 ? { walletCustodyCommit: context.input.walletCustodyCommit } : {}
|
|
2902
|
+
}, prepared, null);
|
|
2903
|
+
if (!commit.ok) return unissuedRegistrationCommit(throwIfRouterAbEd25519YaoRetryableSideEffectFailureV1(commit));
|
|
2904
|
+
if (commit.kind !== "evm_family_ecdsa") return unissuedRegistrationCommit({
|
|
2905
|
+
ok: false,
|
|
2906
|
+
code: "internal",
|
|
2907
|
+
message: "registration activation committed a non-ECDSA branch"
|
|
2908
|
+
});
|
|
2909
|
+
let installationProjection = null;
|
|
2910
|
+
if (registrationSignerBranchesFromPlan(ceremony.signerPlan).nearEd25519) {
|
|
2911
|
+
const committedCeremony = await this.getRegistrationCeremonyIntentStore().getCeremony(context.registrationCeremonyId);
|
|
2912
|
+
installationProjection = committedCeremony ? committedInstallationProjectionFromCeremony(committedCeremony) : null;
|
|
2913
|
+
if (!installationProjection) throw new Error("mixed registration did not persist its installation projection");
|
|
2914
|
+
}
|
|
2915
|
+
const runtimePolicyScope = registrationPreparedContextRuntimePolicyScope(ceremony.preparedContext);
|
|
2916
|
+
if (!runtimePolicyScope) throw new Error("ECDSA registration is missing runtime policy scope");
|
|
2917
|
+
const registrationEstablishedSession = await issueDirectRegistrationEstablishedEcdsaSession({
|
|
2918
|
+
authorizationService: this.authorizationService,
|
|
2919
|
+
authorizationTenantId: this.authorizationTenantId,
|
|
2920
|
+
walletAuthMethods: this.walletAuthMethods,
|
|
2921
|
+
registrationCeremonyId: context.registrationCeremonyId,
|
|
2922
|
+
authority: commit.authority,
|
|
2923
|
+
registrationAuthority: ceremonyAuthority,
|
|
2924
|
+
walletAuthMethodId: prepared.walletAuthMethodId,
|
|
2925
|
+
expiresAtMs: activated.ecdsa.bootstrap.expiresAtMs,
|
|
2926
|
+
remainingUses: activated.ecdsa.bootstrap.remainingUses,
|
|
2927
|
+
bootstrap: activated.ecdsa.bootstrap,
|
|
2928
|
+
runtimePolicyScope,
|
|
2929
|
+
keyManifestDigestB64u: commit.custodyKeyManifestDigestB64u,
|
|
2930
|
+
proof: await this.registrationOwnerProofWithContext(ownerProofContext, {
|
|
2931
|
+
registrationCeremonyId: context.registrationCeremonyId,
|
|
2932
|
+
authMethod: commit.authMethod,
|
|
2933
|
+
authority: commit.authority
|
|
2934
|
+
})
|
|
2935
|
+
});
|
|
2936
|
+
const registrationEstablishedSessionResult = registrationEstablishedSessionResultFromIssuance(registrationEstablishedSession);
|
|
2937
|
+
const responseBase = {
|
|
2938
|
+
ok: true,
|
|
2939
|
+
kind: "evm_family_ecdsa",
|
|
2940
|
+
walletId: commit.walletId,
|
|
2941
|
+
authority: commit.authority,
|
|
2942
|
+
foundingAuthority: commit.foundingAuthority,
|
|
2943
|
+
foundingAuthMethod: commit.foundingAuthMethod,
|
|
2944
|
+
...commit.registrationDiagnostics ? { registrationDiagnostics: commit.registrationDiagnostics } : {},
|
|
2945
|
+
...commit.walletCustody ? { walletCustody: commit.walletCustody } : {},
|
|
2946
|
+
custodyKeyManifestDigestB64u: commit.custodyKeyManifestDigestB64u,
|
|
2947
|
+
ecdsa: {
|
|
2948
|
+
...commit.ecdsa,
|
|
2949
|
+
activation: activated.ecdsa.activation,
|
|
2950
|
+
bootstrap: activated.ecdsa.bootstrap
|
|
2951
|
+
},
|
|
2952
|
+
...registrationSignerBranchesFromPlan(ceremony.signerPlan).nearEd25519 ? { nearProvisioning: { status: "near_pending" } } : {},
|
|
2953
|
+
registrationEstablishedSession: registrationEstablishedSessionResult
|
|
2954
|
+
};
|
|
2955
|
+
const issuedContext = {
|
|
2956
|
+
issuedAtMs: registrationEstablishedSession.issuedAtMs,
|
|
2957
|
+
expectedOrigin: ownerProofContext.expectedOrigin
|
|
2958
|
+
};
|
|
2959
|
+
if (commit.authMethod.kind === "passkey") {
|
|
2960
|
+
if (!commit.rpId) throw new Error("Passkey registration activation is missing its RP ID");
|
|
2961
|
+
const response = {
|
|
2962
|
+
...responseBase,
|
|
2963
|
+
authMethod: commit.authMethod,
|
|
2964
|
+
rpId: commit.rpId
|
|
2965
|
+
};
|
|
2966
|
+
if (installationProjection) return {
|
|
2967
|
+
kind: "session_issued_with_installation_projection",
|
|
2968
|
+
response,
|
|
2969
|
+
...issuedContext,
|
|
2970
|
+
installationProjection
|
|
2971
|
+
};
|
|
2972
|
+
return {
|
|
2973
|
+
kind: "session_issued",
|
|
2974
|
+
response,
|
|
2975
|
+
...issuedContext
|
|
2976
|
+
};
|
|
2977
|
+
}
|
|
2978
|
+
const response = {
|
|
2979
|
+
...responseBase,
|
|
2980
|
+
authMethod: commit.authMethod
|
|
2981
|
+
};
|
|
2982
|
+
if (installationProjection) return {
|
|
2983
|
+
kind: "session_issued_with_installation_projection",
|
|
2984
|
+
response,
|
|
2985
|
+
...issuedContext,
|
|
2986
|
+
installationProjection
|
|
2987
|
+
};
|
|
2988
|
+
return {
|
|
2989
|
+
kind: "session_issued",
|
|
2990
|
+
response,
|
|
2991
|
+
...issuedContext
|
|
2992
|
+
};
|
|
2993
|
+
}
|
|
2994
|
+
async activateWalletRegistrationEcdsa(request, traceContext, activationOwner) {
|
|
2995
|
+
const serverTiming = [];
|
|
2996
|
+
const totalStartedAtMs = Date.now();
|
|
2997
|
+
const markServerTiming = (name, startedAtMs) => {
|
|
2998
|
+
serverTiming.push([name, Math.max(0, Date.now() - startedAtMs)]);
|
|
2999
|
+
};
|
|
3000
|
+
const withServerTiming = (response) => {
|
|
3001
|
+
markServerTiming("ecdsa_activate_total", totalStartedAtMs);
|
|
3002
|
+
return {
|
|
3003
|
+
...response,
|
|
3004
|
+
gatewayServerTiming: serverTiming
|
|
3005
|
+
};
|
|
3006
|
+
};
|
|
3007
|
+
try {
|
|
3008
|
+
const store = this.getRegistrationCeremonyIntentStore();
|
|
3009
|
+
const claimStartedAtMs = Date.now();
|
|
3010
|
+
const owner = normalizeOptionalTrimmedString(activationOwner);
|
|
3011
|
+
if (!owner) return {
|
|
3012
|
+
ok: false,
|
|
3013
|
+
code: "internal",
|
|
3014
|
+
message: "ECDSA activation requires an owning operation identity"
|
|
3015
|
+
};
|
|
3016
|
+
let claimed = await store.claimEcdsaActivation({
|
|
3017
|
+
registrationCeremonyId: request.registrationCeremonyId,
|
|
3018
|
+
publicFacts: request.ecdsa.publicFacts,
|
|
3019
|
+
activationRequestDigestB64u: request.ecdsa.activationRequestDigestB64u,
|
|
3020
|
+
activationOwner: owner
|
|
3021
|
+
});
|
|
3022
|
+
markServerTiming("ecdsa_activate_d1_claim", claimStartedAtMs);
|
|
3023
|
+
if (!claimed) {
|
|
3024
|
+
const reconcileStartedAtMs = Date.now();
|
|
3025
|
+
const existing = await store.getCeremonySnapshot(request.registrationCeremonyId);
|
|
3026
|
+
markServerTiming("ecdsa_activate_reconcile", reconcileStartedAtMs);
|
|
3027
|
+
if (!existing) return {
|
|
3028
|
+
ok: false,
|
|
3029
|
+
code: "not_found",
|
|
3030
|
+
message: "registration ceremony not found"
|
|
3031
|
+
};
|
|
3032
|
+
const ceremony = existing.ceremony;
|
|
3033
|
+
if (!registrationCeremonyWalletsMatch({ ceremony }) || ceremony.signerState.kind !== "signer_set_registration") return {
|
|
3034
|
+
ok: false,
|
|
3035
|
+
code: "invalid_state",
|
|
3036
|
+
message: "signer-set registration state is required"
|
|
3037
|
+
};
|
|
3038
|
+
const ecdsaBranch = findStoredWalletRegistrationEvmFamilyEcdsaBranch(ceremony.signerState);
|
|
3039
|
+
if (ecdsaBranch?.kind === "evm_family_ecdsa_activated") {
|
|
3040
|
+
if (!sameRouterAbEcdsaVerifiedClientActivationFactsV1(ecdsaBranch.publicFacts, request.ecdsa.publicFacts)) return {
|
|
3041
|
+
ok: false,
|
|
3042
|
+
code: "scope_mismatch",
|
|
3043
|
+
message: "ECDSA activation replay changed the verified client facts"
|
|
3044
|
+
};
|
|
3045
|
+
if (ecdsaBranch.activationOwner !== owner) return {
|
|
3046
|
+
ok: false,
|
|
3047
|
+
code: "conflict",
|
|
3048
|
+
message: "ECDSA activation belongs to another activate operation"
|
|
3049
|
+
};
|
|
3050
|
+
return withServerTiming({
|
|
3051
|
+
ok: true,
|
|
3052
|
+
registrationCeremonyId: ceremony.registrationCeremonyId,
|
|
3053
|
+
ecdsa: {
|
|
3054
|
+
kind: "router_ab_ecdsa_registration_activated_v1",
|
|
3055
|
+
activation: ecdsaBranch.activation,
|
|
3056
|
+
bootstrap: ecdsaBranch.bootstrap
|
|
3057
|
+
}
|
|
3058
|
+
});
|
|
3059
|
+
}
|
|
3060
|
+
if (ecdsaBranch?.kind !== "evm_family_ecdsa_activation_claimed") return {
|
|
3061
|
+
ok: false,
|
|
3062
|
+
code: "invalid_state",
|
|
3063
|
+
message: "ECDSA registration activation is not claimable"
|
|
3064
|
+
};
|
|
3065
|
+
if (!sameRouterAbEcdsaVerifiedClientActivationFactsV1(ecdsaBranch.publicFacts, request.ecdsa.publicFacts) || ecdsaBranch.activationRequestDigestB64u !== request.ecdsa.activationRequestDigestB64u) return {
|
|
3066
|
+
ok: false,
|
|
3067
|
+
code: "scope_mismatch",
|
|
3068
|
+
message: "ECDSA activation claim belongs to different verified client facts"
|
|
3069
|
+
};
|
|
3070
|
+
if (ecdsaBranch.activationOwner !== owner) return {
|
|
3071
|
+
ok: false,
|
|
3072
|
+
code: "conflict",
|
|
3073
|
+
message: "ECDSA activation claim belongs to another activate operation"
|
|
3074
|
+
};
|
|
3075
|
+
claimed = existing;
|
|
3076
|
+
}
|
|
3077
|
+
const ceremony = claimed.ceremony;
|
|
3078
|
+
if (ceremony.signerState.kind !== "signer_set_registration") throw new Error("Claimed ECDSA activation ceremony has an invalid signer state");
|
|
3079
|
+
const ecdsaBranch = findStoredWalletRegistrationEvmFamilyEcdsaBranch(ceremony.signerState);
|
|
3080
|
+
if (!ecdsaBranch || ecdsaBranch.kind !== "evm_family_ecdsa_activation_claimed") throw new Error("Claimed ECDSA activation branch is invalid");
|
|
3081
|
+
const routerStartedAtMs = Date.now();
|
|
3082
|
+
const activated = await this.ecdsaStrictRegistration.activate({
|
|
3083
|
+
activationCorrelationId: request.ecdsa.activationCorrelationId,
|
|
3084
|
+
activationRequestDigestB64u: ecdsaBranch.activationRequestDigestB64u,
|
|
3085
|
+
pendingActivation: ecdsaBranch.pendingActivation,
|
|
3086
|
+
clientActivation: ecdsaBranch.publicFacts,
|
|
3087
|
+
requestPolicy: {
|
|
3088
|
+
policyVersion: WALLET_REGISTRATION_ROUTER_POLICY_VERSION,
|
|
3089
|
+
requestDigestB64u: ecdsaBranch.publicFacts.registrationRequestDigestB64u
|
|
3090
|
+
},
|
|
3091
|
+
authority: ecdsaStrictRegistrationAuthority(ecdsaBranch.strictRegistration),
|
|
3092
|
+
traceContext,
|
|
3093
|
+
onServerTiming: (header) => mergeRouterServerTiming(serverTiming, header),
|
|
3094
|
+
onHeaderPresence: (presence) => serverTiming.push([`ecdsa_role_timing_${presence.serverTiming}`, 1])
|
|
3095
|
+
});
|
|
3096
|
+
markServerTiming("ecdsa_activate_router", routerStartedAtMs);
|
|
3097
|
+
if (!activated.ok) {
|
|
3098
|
+
if (!activated.retryable) await store.commitEcdsaClaim({
|
|
3099
|
+
expected: claimed,
|
|
3100
|
+
next: {
|
|
3101
|
+
...ceremony,
|
|
3102
|
+
signerState: {
|
|
3103
|
+
kind: "registration_failed",
|
|
3104
|
+
failedAtMs: Date.now(),
|
|
3105
|
+
failure: {
|
|
3106
|
+
code: activated.code,
|
|
3107
|
+
message: activated.message
|
|
3108
|
+
}
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3111
|
+
});
|
|
3112
|
+
return {
|
|
3113
|
+
ok: false,
|
|
3114
|
+
code: activated.code,
|
|
3115
|
+
message: activated.message
|
|
3116
|
+
};
|
|
3117
|
+
}
|
|
3118
|
+
try {
|
|
3119
|
+
const bootstrapStartedAtMs = Date.now();
|
|
3120
|
+
const bootstrap = await buildActivatedEcdsaFamilyBootstrap({
|
|
3121
|
+
branch: ecdsaBranch,
|
|
3122
|
+
publicFacts: ecdsaBranch.publicFacts,
|
|
3123
|
+
activation: activated.value
|
|
3124
|
+
});
|
|
3125
|
+
markServerTiming("ecdsa_activate_bootstrap", bootstrapStartedAtMs);
|
|
3126
|
+
const activatedBranch = {
|
|
3127
|
+
kind: "evm_family_ecdsa_activated",
|
|
3128
|
+
activationOwner: ecdsaBranch.activationOwner,
|
|
3129
|
+
branchKey: ecdsaBranch.branchKey,
|
|
3130
|
+
derivationKind: ecdsaBranch.derivationKind,
|
|
3131
|
+
chainTargets: ecdsaBranch.chainTargets,
|
|
3132
|
+
prepare: ecdsaBranch.prepare,
|
|
3133
|
+
strictRegistration: ecdsaBranch.strictRegistration,
|
|
3134
|
+
strictRegistrationBindingJson: ecdsaBranch.strictRegistrationBindingJson,
|
|
3135
|
+
registrationRequest: ecdsaBranch.registrationRequest,
|
|
3136
|
+
publicFacts: ecdsaBranch.publicFacts,
|
|
3137
|
+
activation: activated.value,
|
|
3138
|
+
publicCapability: buildRouterAbEcdsaDerivationPublicCapabilityV1({
|
|
3139
|
+
registrationFacts: ecdsaBranch.strictRegistration,
|
|
3140
|
+
registrationRequest: ecdsaBranch.registrationRequest,
|
|
3141
|
+
clientActivation: ecdsaBranch.publicFacts,
|
|
3142
|
+
activationReceipt: activated.value
|
|
3143
|
+
}),
|
|
3144
|
+
bootstrap: {
|
|
3145
|
+
formatVersion: bootstrap.formatVersion,
|
|
3146
|
+
walletId: bootstrap.walletId,
|
|
3147
|
+
evmFamilySigningKeySlotId: bootstrap.evmFamilySigningKeySlotId,
|
|
3148
|
+
ecdsaThresholdKeyId: bootstrap.ecdsaThresholdKeyId,
|
|
3149
|
+
relayerKeyId: bootstrap.relayerKeyId,
|
|
3150
|
+
applicationBindingDigestB64u: bootstrap.applicationBindingDigestB64u,
|
|
3151
|
+
contextBinding32B64u: bootstrap.contextBinding32B64u,
|
|
3152
|
+
publicIdentity: bootstrap.publicIdentity,
|
|
3153
|
+
clientShareRetryCounter: bootstrap.clientShareRetryCounter,
|
|
3154
|
+
relayerShareRetryCounter: bootstrap.relayerShareRetryCounter,
|
|
3155
|
+
publicTranscriptDigest32B64u: bootstrap.publicTranscriptDigest32B64u,
|
|
3156
|
+
keyHandle: bootstrap.keyHandle,
|
|
3157
|
+
signingRootId: bootstrap.signingRootId,
|
|
3158
|
+
signingRootVersion: bootstrap.signingRootVersion,
|
|
3159
|
+
thresholdEcdsaPublicKeyB64u: bootstrap.thresholdEcdsaPublicKeyB64u,
|
|
3160
|
+
ethereumAddress: bootstrap.ethereumAddress,
|
|
3161
|
+
relayerVerifyingShareB64u: bootstrap.relayerVerifyingShareB64u,
|
|
3162
|
+
thresholdSessionId: bootstrap.thresholdSessionId,
|
|
3163
|
+
activationEpoch: bootstrap.activationEpoch,
|
|
3164
|
+
expiresAtMs: bootstrap.expiresAtMs,
|
|
3165
|
+
expiresAt: bootstrap.expiresAt,
|
|
3166
|
+
remainingUses: bootstrap.remainingUses,
|
|
3167
|
+
participantIds: [...exactEcdsaParticipantPair(bootstrap.participantIds)],
|
|
3168
|
+
routerAbEcdsaDerivationNormalSigning: bootstrap.routerAbEcdsaDerivationNormalSigning
|
|
3169
|
+
}
|
|
3170
|
+
};
|
|
3171
|
+
const commitStartedAtMs = Date.now();
|
|
3172
|
+
try {
|
|
3173
|
+
await store.commitEcdsaClaim({
|
|
3174
|
+
expected: claimed,
|
|
3175
|
+
next: {
|
|
3176
|
+
...ceremony,
|
|
3177
|
+
signerState: replaceStoredWalletRegistrationSignerBranch({
|
|
3178
|
+
state: ceremony.signerState,
|
|
3179
|
+
replacement: activatedBranch
|
|
3180
|
+
})
|
|
3181
|
+
}
|
|
3182
|
+
});
|
|
3183
|
+
} catch (error) {
|
|
3184
|
+
const reconciled = await store.getCeremony(request.registrationCeremonyId);
|
|
3185
|
+
const reconciledBranch = reconciled?.signerState.kind === "signer_set_registration" ? findStoredWalletRegistrationEvmFamilyEcdsaBranch(reconciled.signerState) : null;
|
|
3186
|
+
if (reconciledBranch?.kind !== "evm_family_ecdsa_activated" || reconciledBranch.activationOwner !== activatedBranch.activationOwner || !sameRouterAbEcdsaVerifiedClientActivationFactsV1(reconciledBranch.publicFacts, activatedBranch.publicFacts) || !sameRouterAbEcdsaRegistrationActivationReceiptV1(reconciledBranch.activation, activatedBranch.activation) || !sameEcdsaDerivationServerBootstrap(reconciledBranch.bootstrap, activatedBranch.bootstrap)) throw error;
|
|
3187
|
+
} finally {
|
|
3188
|
+
markServerTiming("ecdsa_activate_d1_commit", commitStartedAtMs);
|
|
3189
|
+
}
|
|
3190
|
+
return withServerTiming({
|
|
3191
|
+
ok: true,
|
|
3192
|
+
registrationCeremonyId: ceremony.registrationCeremonyId,
|
|
3193
|
+
ecdsa: {
|
|
3194
|
+
kind: "router_ab_ecdsa_registration_activated_v1",
|
|
3195
|
+
activation: activated.value,
|
|
3196
|
+
bootstrap: activatedBranch.bootstrap
|
|
3197
|
+
}
|
|
3198
|
+
});
|
|
3199
|
+
} catch (error) {
|
|
3200
|
+
const message = errorMessage(error) || "ECDSA activation could not establish normal signing";
|
|
3201
|
+
await store.commitEcdsaClaim({
|
|
3202
|
+
expected: claimed,
|
|
3203
|
+
next: {
|
|
3204
|
+
...ceremony,
|
|
3205
|
+
signerState: {
|
|
3206
|
+
kind: "registration_failed",
|
|
3207
|
+
failedAtMs: Date.now(),
|
|
3208
|
+
failure: {
|
|
3209
|
+
code: "ecdsa_activation_terminal_failure",
|
|
3210
|
+
message
|
|
3211
|
+
}
|
|
3212
|
+
}
|
|
3213
|
+
}
|
|
3214
|
+
});
|
|
3215
|
+
return {
|
|
3216
|
+
ok: false,
|
|
3217
|
+
code: "ecdsa_activation_terminal_failure",
|
|
3218
|
+
message
|
|
3219
|
+
};
|
|
3220
|
+
}
|
|
3221
|
+
} catch (error) {
|
|
3222
|
+
return {
|
|
3223
|
+
ok: false,
|
|
3224
|
+
code: "internal",
|
|
3225
|
+
message: errorMessage(error) || "Failed to activate ECDSA wallet registration"
|
|
3226
|
+
};
|
|
3227
|
+
}
|
|
3228
|
+
}
|
|
3229
|
+
async executeWalletRegistrationFinalize(request, prepared, recovery) {
|
|
3230
|
+
const finalizeTiming = createD1RegistrationRouteTimingRecorder("wallets_register_finalize");
|
|
3231
|
+
const totalTiming = startD1RegistrationRouteTiming("registerFinalizeTotalMs");
|
|
3232
|
+
try {
|
|
3233
|
+
const store = this.getRegistrationCeremonyIntentStore();
|
|
3234
|
+
if (!normalizeOptionalTrimmedString(request.idempotencyKey)) return {
|
|
3235
|
+
ok: false,
|
|
3236
|
+
code: "invalid_body",
|
|
3237
|
+
message: "registration finalize idempotencyKey is required"
|
|
3238
|
+
};
|
|
3239
|
+
const requestFingerprint = await walletRegistrationFinalizeRequestFingerprint(request);
|
|
3240
|
+
const ceremonyLoadTiming = startD1RegistrationRouteTiming("registrationCeremonyLoadMs");
|
|
3241
|
+
let storedCeremony;
|
|
3242
|
+
try {
|
|
3243
|
+
storedCeremony = await store.getCeremony(request.registrationCeremonyId);
|
|
3244
|
+
} finally {
|
|
3245
|
+
finishD1RegistrationRouteTiming(finalizeTiming, ceremonyLoadTiming);
|
|
3246
|
+
}
|
|
3247
|
+
let ceremony;
|
|
3248
|
+
if (storedCeremony) {
|
|
3249
|
+
if (storedCeremony.signerState.kind !== "signer_set_registration") return {
|
|
3250
|
+
ok: false,
|
|
3251
|
+
code: "invalid_state",
|
|
3252
|
+
message: "signer-set registration state is required"
|
|
3253
|
+
};
|
|
3254
|
+
ceremony = registrationFinalizeCeremonyFromStored(storedCeremony);
|
|
3255
|
+
} else if (recovery) {
|
|
3256
|
+
if (request.kind !== "near_ed25519") return {
|
|
3257
|
+
ok: false,
|
|
3258
|
+
code: "invalid_state",
|
|
3259
|
+
message: "committed mixed registration can only finalize NEAR Ed25519"
|
|
3260
|
+
};
|
|
3261
|
+
ceremony = recovery.ceremony;
|
|
3262
|
+
} else return {
|
|
3263
|
+
ok: false,
|
|
3264
|
+
code: "not_found",
|
|
3265
|
+
message: "registration ceremony not found"
|
|
3266
|
+
};
|
|
3267
|
+
if (!registrationCeremonyWalletsMatch({ ceremony })) return {
|
|
3268
|
+
ok: false,
|
|
3269
|
+
code: "scope_mismatch",
|
|
3270
|
+
message: "registration ceremony walletId mismatch"
|
|
3271
|
+
};
|
|
3272
|
+
const ceremonyAuthority = verifiedRegistrationCeremonyAuthority(ceremony);
|
|
3273
|
+
if (!ceremonyAuthority) return {
|
|
3274
|
+
ok: false,
|
|
3275
|
+
code: "invalid_state",
|
|
3276
|
+
message: "registration ceremony has not verified its authority proof"
|
|
3277
|
+
};
|
|
3278
|
+
const signerBranches = registrationSignerBranchesFromPlan(ceremony.signerPlan);
|
|
3279
|
+
const requestedNearEd25519 = signerBranches.nearEd25519;
|
|
3280
|
+
const requestedEvmFamilyEcdsa = signerBranches.evmFamilyEcdsa;
|
|
3281
|
+
if (!requestedNearEd25519 && !requestedEvmFamilyEcdsa) return {
|
|
3282
|
+
ok: false,
|
|
3283
|
+
code: "invalid_state",
|
|
3284
|
+
message: "registration signer set requires a signer branch"
|
|
3285
|
+
};
|
|
3286
|
+
const storedEcdsaBranch = findStoredWalletRegistrationEvmFamilyEcdsaBranch(ceremony.signerState);
|
|
3287
|
+
const ecdsaAlreadyFinalized = storedCeremony === null && recovery !== null || storedEcdsaBranch?.kind === "evm_family_ecdsa_finalized";
|
|
3288
|
+
const sequenceFailure = finalizeSignerWorkSequenceFailure({
|
|
3289
|
+
request,
|
|
3290
|
+
hasNearEd25519: requestedNearEd25519 !== null,
|
|
3291
|
+
hasEvmFamilyEcdsa: requestedEvmFamilyEcdsa !== null,
|
|
3292
|
+
ecdsaFinalized: ecdsaAlreadyFinalized
|
|
3293
|
+
});
|
|
3294
|
+
if (sequenceFailure) return {
|
|
3295
|
+
ok: false,
|
|
3296
|
+
...sequenceFailure
|
|
3297
|
+
};
|
|
3298
|
+
const finalizeEvmFamilyEcdsa = request.kind === "evm_family_ecdsa" ? requestedEvmFamilyEcdsa : null;
|
|
3299
|
+
const finalizeNearEd25519 = request.kind === "near_ed25519" ? requestedNearEd25519 : null;
|
|
3300
|
+
const ed25519FinalizePending = finalizeEvmFamilyEcdsa !== null && requestedNearEd25519 !== null;
|
|
3301
|
+
const walletCustodyCommitPayload = walletCustodyCeremonyCommitPayloadFromWire(request.walletCustodyCommit);
|
|
3302
|
+
if (!walletCustodyCommitPayload) return {
|
|
3303
|
+
ok: false,
|
|
3304
|
+
code: "invalid_body",
|
|
3305
|
+
message: "registration finalize requires its wallet custody commit"
|
|
3306
|
+
};
|
|
3307
|
+
if (walletCustodyCommitPayload.walletId !== ceremony.intent.walletId) return {
|
|
3308
|
+
ok: false,
|
|
3309
|
+
code: "scope_mismatch",
|
|
3310
|
+
message: "wallet custody commit does not name the registered wallet"
|
|
3311
|
+
};
|
|
3312
|
+
const expectedCustodyKeySet = finalizeEvmFamilyEcdsa ? "evm_family_ecdsa_v1" : "near_ed25519_v1";
|
|
3313
|
+
if (walletCustodyCommitPayload.keySet !== expectedCustodyKeySet) return {
|
|
3314
|
+
ok: false,
|
|
3315
|
+
code: "scope_mismatch",
|
|
3316
|
+
message: "wallet custody commit does not name the finalized key set"
|
|
3317
|
+
};
|
|
3318
|
+
let custodyKeyManifestDigestB64u;
|
|
3319
|
+
try {
|
|
3320
|
+
custodyKeyManifestDigestB64u = parseDigestB64u(walletCustodyCommitPayload.keyManifestDigestB64u);
|
|
3321
|
+
} catch {
|
|
3322
|
+
return {
|
|
3323
|
+
ok: false,
|
|
3324
|
+
code: "invalid_body",
|
|
3325
|
+
message: "wallet custody commit carries an invalid key manifest digest"
|
|
3326
|
+
};
|
|
3327
|
+
}
|
|
3328
|
+
let custodyClientRootPublicKey33B64u = null;
|
|
3329
|
+
if (finalizeEvmFamilyEcdsa) try {
|
|
3330
|
+
custodyClientRootPublicKey33B64u = ecdsaClientRootPublicKey33B64uFromString(walletCustodyCommitPayload.clientRootPublicKey33B64u ?? "");
|
|
3331
|
+
} catch {
|
|
3332
|
+
return {
|
|
3333
|
+
ok: false,
|
|
3334
|
+
code: "invalid_body",
|
|
3335
|
+
message: "ECDSA custody commit carries an invalid client root public key"
|
|
3336
|
+
};
|
|
3337
|
+
}
|
|
3338
|
+
const ecdsaWalletKeys = [];
|
|
3339
|
+
let ecdsaMaterialActivation = null;
|
|
3340
|
+
let activatedEcdsaBranch = null;
|
|
3341
|
+
if (finalizeEvmFamilyEcdsa) {
|
|
3342
|
+
const ecdsaState = storedEcdsaBranch;
|
|
3343
|
+
if (!ecdsaState || ecdsaState.kind !== "evm_family_ecdsa_activated") return {
|
|
3344
|
+
ok: false,
|
|
3345
|
+
code: "invalid_state",
|
|
3346
|
+
message: "ECDSA family activation is required before finalize"
|
|
3347
|
+
};
|
|
3348
|
+
activatedEcdsaBranch = ecdsaState;
|
|
3349
|
+
if (!request.ecdsa) return {
|
|
3350
|
+
ok: false,
|
|
3351
|
+
code: "invalid_body",
|
|
3352
|
+
message: "ECDSA finalize requires the activated family key handle"
|
|
3353
|
+
};
|
|
3354
|
+
const expectedKeyHandles = request.ecdsa.expectedKeyHandles;
|
|
3355
|
+
if (hasEcdsaKeyHandleSetMismatch(expectedKeyHandles, [ecdsaState.bootstrap.keyHandle])) return {
|
|
3356
|
+
ok: false,
|
|
3357
|
+
code: "key_handle_mismatch",
|
|
3358
|
+
message: "ECDSA finalize expected key handle mismatch"
|
|
3359
|
+
};
|
|
3360
|
+
const ecdsaVerifyTiming = startD1RegistrationRouteTiming("registrationEcdsaBootstrapVerifyMs");
|
|
3361
|
+
let walletKeyResult;
|
|
3362
|
+
try {
|
|
3363
|
+
walletKeyResult = buildD1EcdsaWalletKeysFromBootstrap({
|
|
3364
|
+
bootstraps: ecdsaState.chainTargets.map((chainTarget) => ({
|
|
3365
|
+
chainTarget,
|
|
3366
|
+
bootstrap: ecdsaState.bootstrap
|
|
3367
|
+
})),
|
|
3368
|
+
publicCapability: ecdsaState.publicCapability,
|
|
3369
|
+
errorContext: "ECDSA registration finalize"
|
|
3370
|
+
});
|
|
3371
|
+
} finally {
|
|
3372
|
+
finishD1RegistrationRouteTiming(finalizeTiming, ecdsaVerifyTiming);
|
|
3373
|
+
}
|
|
3374
|
+
if (!walletKeyResult.ok) return walletKeyResult;
|
|
3375
|
+
ecdsaWalletKeys.push(...walletKeyResult.walletKeys);
|
|
3376
|
+
ecdsaMaterialActivation = routerAbMpcMaterialActivationRefFromWire(ecdsaState.activation.ecdsa_activation.material_activation);
|
|
3377
|
+
} else if (storedEcdsaBranch?.kind === "evm_family_ecdsa_finalized") {
|
|
3378
|
+
const walletKeyResult = buildD1EcdsaWalletKeysFromBootstrap({
|
|
3379
|
+
bootstraps: storedEcdsaBranch.chainTargets.map((chainTarget) => ({
|
|
3380
|
+
chainTarget,
|
|
3381
|
+
bootstrap: storedEcdsaBranch.bootstrap
|
|
3382
|
+
})),
|
|
3383
|
+
publicCapability: storedEcdsaBranch.publicCapability,
|
|
3384
|
+
errorContext: "ECDSA registration final Ed25519 finalize"
|
|
3385
|
+
});
|
|
3386
|
+
if (!walletKeyResult.ok) return walletKeyResult;
|
|
3387
|
+
ecdsaWalletKeys.push(...walletKeyResult.walletKeys);
|
|
3388
|
+
ecdsaMaterialActivation = routerAbMpcMaterialActivationRefFromWire(storedEcdsaBranch.activation.ecdsa_activation.material_activation);
|
|
3389
|
+
}
|
|
3390
|
+
const now = Date.now();
|
|
3391
|
+
const emailOtpEnrollmentTiming = startD1RegistrationRouteTiming("registrationEmailOtpEnrollmentPlanMs");
|
|
3392
|
+
let emailOtpEnrollment;
|
|
3393
|
+
try {
|
|
3394
|
+
emailOtpEnrollment = await this.emailOtpRegistrationEnrollmentFinalizer.prepareRegistrationFinalize({
|
|
3395
|
+
authority: ceremonyAuthority,
|
|
3396
|
+
request,
|
|
3397
|
+
walletId: ceremony.intent.walletId,
|
|
3398
|
+
orgId: ceremony.orgId,
|
|
3399
|
+
nowMs: now
|
|
3400
|
+
});
|
|
3401
|
+
} finally {
|
|
3402
|
+
finishD1RegistrationRouteTiming(finalizeTiming, emailOtpEnrollmentTiming);
|
|
3403
|
+
}
|
|
3404
|
+
if (!emailOtpEnrollment.ok) return emailOtpEnrollment;
|
|
3405
|
+
const walletAuthAuthority = registrationWalletAuthAuthority({
|
|
3406
|
+
authority: ceremonyAuthority,
|
|
3407
|
+
walletAuthMethodId: prepared.walletAuthMethodId
|
|
3408
|
+
});
|
|
3409
|
+
let ed25519PublicResult = null;
|
|
3410
|
+
let resolvedNearAccount = null;
|
|
3411
|
+
let ed25519SignerRecord = null;
|
|
3412
|
+
let ed25519MaterialActivation = null;
|
|
3413
|
+
let ed25519RegisteredPublicKeyB64u = null;
|
|
3414
|
+
let ed25519CapabilityInstallation = null;
|
|
3415
|
+
if (finalizeNearEd25519) {
|
|
3416
|
+
const yaoRuntime = this.getEd25519YaoProductRegistration();
|
|
3417
|
+
if (!yaoRuntime) return {
|
|
3418
|
+
ok: false,
|
|
3419
|
+
code: "not_configured",
|
|
3420
|
+
message: "Ed25519 Yao product registration is not configured"
|
|
3421
|
+
};
|
|
3422
|
+
const storedYao = findStoredWalletRegistrationNearEd25519YaoBranch(ceremony.signerState);
|
|
3423
|
+
if (!storedYao || !request.ed25519) return {
|
|
3424
|
+
ok: false,
|
|
3425
|
+
code: "invalid_state",
|
|
3426
|
+
message: "authorized Ed25519 Yao registration is required before finalize"
|
|
3427
|
+
};
|
|
3428
|
+
if (ceremony.preparedContext.runtimePolicy.kind !== "runtime_policy_scope") return {
|
|
3429
|
+
ok: false,
|
|
3430
|
+
code: "invalid_state",
|
|
3431
|
+
message: "Ed25519 Yao wallet session requires a runtime policy scope"
|
|
3432
|
+
};
|
|
3433
|
+
const runtimePolicyScope = ceremony.preparedContext.runtimePolicy.scope;
|
|
3434
|
+
const activationReference = request.ed25519.activationReference;
|
|
3435
|
+
if (activationReference.lifecycle_id !== ceremony.registrationCeremonyId) return {
|
|
3436
|
+
ok: false,
|
|
3437
|
+
code: "scope_mismatch",
|
|
3438
|
+
message: "Ed25519 activation reference does not belong to this registration ceremony"
|
|
3439
|
+
};
|
|
3440
|
+
const consumed = await yaoRuntime.consumeActivated({
|
|
3441
|
+
reference: {
|
|
3442
|
+
lifecycleId: activationReference.lifecycle_id,
|
|
3443
|
+
sessionId: activationReference.session_id
|
|
3444
|
+
},
|
|
3445
|
+
consumerBinding: requestFingerprint
|
|
3446
|
+
});
|
|
3447
|
+
if (!consumed.ok) return {
|
|
3448
|
+
ok: false,
|
|
3449
|
+
code: consumed.code,
|
|
3450
|
+
message: consumed.message
|
|
3451
|
+
};
|
|
3452
|
+
if (!sameRouterAbEd25519YaoRegistrationAdmissionRequestV1(consumed.activation.admissionRequest, storedYao.admissionRequest)) return {
|
|
3453
|
+
ok: false,
|
|
3454
|
+
code: "scope_mismatch",
|
|
3455
|
+
message: "activated Ed25519 Yao registration does not match the stored signer branch"
|
|
3456
|
+
};
|
|
3457
|
+
const firstParticipantId = finalizeNearEd25519.participantIds[0];
|
|
3458
|
+
const secondParticipantId = finalizeNearEd25519.participantIds[1];
|
|
3459
|
+
if (finalizeNearEd25519.participantIds.length !== 2 || firstParticipantId === void 0 || secondParticipantId === void 0) return {
|
|
3460
|
+
ok: false,
|
|
3461
|
+
code: "invalid_state",
|
|
3462
|
+
message: "Ed25519 Yao registration requires exactly two participants"
|
|
3463
|
+
};
|
|
3464
|
+
const participantIds = [firstParticipantId, secondParticipantId];
|
|
3465
|
+
const publicKeyBytes = consumed.activation.result.public_receipt.registered_public_key;
|
|
3466
|
+
ed25519RegisteredPublicKeyB64u = base64UrlEncode(Uint8Array.from(publicKeyBytes));
|
|
3467
|
+
if (walletCustodyCommitPayload.registeredPublicKeyB64u !== ed25519RegisteredPublicKeyB64u) return {
|
|
3468
|
+
ok: false,
|
|
3469
|
+
code: "scope_mismatch",
|
|
3470
|
+
message: "NEAR custody commit changed the activated public key"
|
|
3471
|
+
};
|
|
3472
|
+
const publicKey = ed25519NearPublicKeyFromBytes(publicKeyBytes);
|
|
3473
|
+
let nearAccountId = implicitNearAccountIdFromEd25519PublicKeyBytes(publicKeyBytes);
|
|
3474
|
+
let sponsoredTransactionHash;
|
|
3475
|
+
const sponsoredAccountId = sponsoredNamedRegistrationAccountId(finalizeNearEd25519.accountProvisioning);
|
|
3476
|
+
if (sponsoredAccountId) {
|
|
3477
|
+
const created = await this.createSponsoredNamedNearAccount({
|
|
3478
|
+
accountId: sponsoredAccountId,
|
|
3479
|
+
publicKey,
|
|
3480
|
+
idempotencyKey: bytesToUnprefixedHex(Uint8Array.from(consumed.activation.result.binding.session_id))
|
|
3481
|
+
});
|
|
3482
|
+
switch (created.kind) {
|
|
3483
|
+
case "rejected": return {
|
|
3484
|
+
ok: false,
|
|
3485
|
+
code: "account_creation_failed",
|
|
3486
|
+
message: created.message
|
|
3487
|
+
};
|
|
3488
|
+
case "retryable": return {
|
|
3489
|
+
ok: false,
|
|
3490
|
+
code: "account_creation_retryable",
|
|
3491
|
+
message: created.message,
|
|
3492
|
+
retryAfterMs: created.retryAfterMs
|
|
3493
|
+
};
|
|
3494
|
+
case "created":
|
|
3495
|
+
nearAccountId = created.accountId;
|
|
3496
|
+
sponsoredTransactionHash = created.transactionHash;
|
|
3497
|
+
break;
|
|
3498
|
+
default: return assertNeverSponsoredNamedNearAccountCreationResult(created);
|
|
3499
|
+
}
|
|
3500
|
+
}
|
|
3501
|
+
const resolved = resolvedRegistrationNearAccount({
|
|
3502
|
+
accountProvisioning: finalizeNearEd25519.accountProvisioning,
|
|
3503
|
+
nearAccountId,
|
|
3504
|
+
nearEd25519SigningKeyId: consumed.activation.admissionRequest.application_binding.near_ed25519_signing_key_id,
|
|
3505
|
+
...sponsoredTransactionHash ? { sponsoredTransactionHash } : {}
|
|
3506
|
+
});
|
|
3507
|
+
if (!resolved.ok) return resolved;
|
|
3508
|
+
resolvedNearAccount = resolved.value;
|
|
3509
|
+
ed25519CapabilityInstallation = {
|
|
3510
|
+
kind: "router_ab_ed25519_yao_registration_finalize_capability_v1",
|
|
3511
|
+
activeCapabilityBinding: consumed.activation.result.binding.session_id,
|
|
3512
|
+
nearAccountId,
|
|
3513
|
+
registrationAdmissionRequest: consumed.activation.admissionRequest,
|
|
3514
|
+
registrationAdmissionReceipt: consumed.activation.admissionReceipt,
|
|
3515
|
+
registrationResult: consumed.activation.result,
|
|
3516
|
+
runtimePolicyScope
|
|
3517
|
+
};
|
|
3518
|
+
const activeYaoCapability = buildRouterAbEd25519YaoRegistrationCapabilityRecordV1(ed25519CapabilityInstallation);
|
|
3519
|
+
if (!activeYaoCapability.ok) return {
|
|
3520
|
+
ok: false,
|
|
3521
|
+
code: activeYaoCapability.code,
|
|
3522
|
+
message: activeYaoCapability.message
|
|
3523
|
+
};
|
|
3524
|
+
const activatedEd25519PublicResult = {
|
|
3525
|
+
signerSlot: finalizeNearEd25519.signerSlot,
|
|
3526
|
+
nearAccountId,
|
|
3527
|
+
nearEd25519SigningKeyId: consumed.activation.admissionRequest.application_binding.near_ed25519_signing_key_id,
|
|
3528
|
+
publicKey,
|
|
3529
|
+
relayerKeyId: yaoRuntime.signingWorkerId,
|
|
3530
|
+
keyVersion: finalizeNearEd25519.keyVersion,
|
|
3531
|
+
recoveryExportCapable: true,
|
|
3532
|
+
participantIds,
|
|
3533
|
+
thresholdSessionId: consumed.activation.admissionRequest.scope.threshold_session_id,
|
|
3534
|
+
runtimePolicyScope,
|
|
3535
|
+
routerAbNormalSigning: {
|
|
3536
|
+
kind: ROUTER_AB_ED25519_NORMAL_SIGNING_STATE_KIND,
|
|
3537
|
+
signingWorkerId: yaoRuntime.signingWorkerId
|
|
3538
|
+
}
|
|
3539
|
+
};
|
|
3540
|
+
ed25519PublicResult = activatedEd25519PublicResult;
|
|
3541
|
+
ed25519MaterialActivation = routerAbMpcMaterialActivationRefFromWire(consumed.activation.admissionRequest.scope.material_activation);
|
|
3542
|
+
ed25519SignerRecord = buildYaoEd25519WalletSignerRecord({
|
|
3543
|
+
walletId: ceremony.intent.walletId,
|
|
3544
|
+
nearAccountId,
|
|
3545
|
+
nearEd25519SigningKeyId: activatedEd25519PublicResult.nearEd25519SigningKeyId,
|
|
3546
|
+
thresholdSessionId: consumed.activation.admissionRequest.scope.threshold_session_id,
|
|
3547
|
+
signerSlot: finalizeNearEd25519.signerSlot,
|
|
3548
|
+
publicKey,
|
|
3549
|
+
signingWorkerId: yaoRuntime.signingWorkerId,
|
|
3550
|
+
keyVersion: finalizeNearEd25519.keyVersion,
|
|
3551
|
+
participantIds,
|
|
3552
|
+
signingRootId: ceremony.preparedContext.signingRootId,
|
|
3553
|
+
signingRootVersion: ceremony.preparedContext.signingRootVersion,
|
|
3554
|
+
runtimePolicyScope,
|
|
3555
|
+
activeYaoCapability: activeYaoCapability.record,
|
|
3556
|
+
custodyKeyManifestDigestB64u,
|
|
3557
|
+
now
|
|
3558
|
+
});
|
|
3559
|
+
}
|
|
3560
|
+
const wallet = buildD1WalletRecord({
|
|
3561
|
+
walletId: ceremony.intent.walletId,
|
|
3562
|
+
now
|
|
3563
|
+
});
|
|
3564
|
+
if (activatedEcdsaBranch && !custodyClientRootPublicKey33B64u) return {
|
|
3565
|
+
ok: false,
|
|
3566
|
+
code: "invalid_state",
|
|
3567
|
+
message: "ECDSA registration is missing its custody client root public key"
|
|
3568
|
+
};
|
|
3569
|
+
const walletSigners = [];
|
|
3570
|
+
if (activatedEcdsaBranch) {
|
|
3571
|
+
const custodyClientRootPublicKey = custodyClientRootPublicKey33B64u;
|
|
3572
|
+
if (!custodyClientRootPublicKey) return {
|
|
3573
|
+
ok: false,
|
|
3574
|
+
code: "invalid_state",
|
|
3575
|
+
message: "ECDSA registration is missing its custody client root public key"
|
|
3576
|
+
};
|
|
3577
|
+
walletSigners.push(...buildD1WalletEcdsaSignerRecords({
|
|
3578
|
+
walletId: ceremony.intent.walletId,
|
|
3579
|
+
walletKeys: ecdsaWalletKeys,
|
|
3580
|
+
activationReceipt: activatedEcdsaBranch.activation,
|
|
3581
|
+
runtimePolicyScope: activatedEcdsaBranch.prepare.runtimePolicyScope,
|
|
3582
|
+
custodyKeyManifestDigestB64u,
|
|
3583
|
+
custodyClientRootPublicKey33B64u: custodyClientRootPublicKey,
|
|
3584
|
+
now
|
|
3585
|
+
}));
|
|
3586
|
+
}
|
|
3587
|
+
if (ed25519SignerRecord) walletSigners.push(ed25519SignerRecord);
|
|
3588
|
+
const foundingAuthorityAlreadyCommitted = finalizeNearEd25519 !== null && ecdsaAlreadyFinalized;
|
|
3589
|
+
const foundingAuthorityNeedsEd25519Extension = foundingAuthorityAlreadyCommitted && requestedEvmFamilyEcdsa !== null;
|
|
3590
|
+
const foundingCommitComplete = finalizeEvmFamilyEcdsa !== null || finalizeNearEd25519 !== null && requestedEvmFamilyEcdsa === null || foundingAuthorityNeedsEd25519Extension;
|
|
3591
|
+
let foundingAuthorityRecords = null;
|
|
3592
|
+
if (foundingAuthorityNeedsEd25519Extension) {
|
|
3593
|
+
if (!ed25519SignerRecord || !ed25519MaterialActivation || !ed25519RegisteredPublicKeyB64u) return {
|
|
3594
|
+
ok: false,
|
|
3595
|
+
code: "invalid_state",
|
|
3596
|
+
message: "Deferred Ed25519 finalize is missing its founding signer facts"
|
|
3597
|
+
};
|
|
3598
|
+
const persistedFoundingRecords = await this.walletAuthMethods.readActiveRegistrationIdentity(ceremonyAuthority);
|
|
3599
|
+
if (!persistedFoundingRecords) return {
|
|
3600
|
+
ok: false,
|
|
3601
|
+
code: "invalid_state",
|
|
3602
|
+
message: "Deferred Ed25519 finalize is missing its founding authority"
|
|
3603
|
+
};
|
|
3604
|
+
if (!isActiveEcdsaWalletAuthorityV1(persistedFoundingRecords.authority)) return {
|
|
3605
|
+
ok: false,
|
|
3606
|
+
code: "invalid_state",
|
|
3607
|
+
message: "Deferred Ed25519 finalize requires an ECDSA-only founding authority"
|
|
3608
|
+
};
|
|
3609
|
+
foundingAuthorityRecords = {
|
|
3610
|
+
authority: await extendFoundingAuthorityWithEd25519({
|
|
3611
|
+
authority: persistedFoundingRecords.authority,
|
|
3612
|
+
ed25519: {
|
|
3613
|
+
signer: ed25519SignerRecord,
|
|
3614
|
+
registeredPublicKeyB64u: ed25519RegisteredPublicKeyB64u,
|
|
3615
|
+
materialActivation: ed25519MaterialActivation
|
|
3616
|
+
},
|
|
3617
|
+
now
|
|
3618
|
+
}),
|
|
3619
|
+
authMethod: persistedFoundingRecords.authMethod
|
|
3620
|
+
};
|
|
3621
|
+
} else if (foundingCommitComplete && !foundingAuthorityAlreadyCommitted) {
|
|
3622
|
+
const ecdsaWalletKey = ecdsaWalletKeys[0];
|
|
3623
|
+
if (ed25519SignerRecord && ed25519MaterialActivation && ed25519RegisteredPublicKeyB64u) if (!ecdsaWalletKey || !ecdsaMaterialActivation) {
|
|
3624
|
+
if (requestedEvmFamilyEcdsa !== null) return {
|
|
3625
|
+
ok: false,
|
|
3626
|
+
code: "invalid_state",
|
|
3627
|
+
message: "Complete registration is missing ECDSA founding facts"
|
|
3628
|
+
};
|
|
3629
|
+
foundingAuthorityRecords = await buildFoundingAuthorityRecords({
|
|
3630
|
+
authority: ceremonyAuthority,
|
|
3631
|
+
walletId: ceremony.intent.walletId,
|
|
3632
|
+
prepared,
|
|
3633
|
+
signerFacts: {
|
|
3634
|
+
kind: "ed25519",
|
|
3635
|
+
keyFamilies: ["ed25519"],
|
|
3636
|
+
ed25519: {
|
|
3637
|
+
signer: ed25519SignerRecord,
|
|
3638
|
+
registeredPublicKeyB64u: ed25519RegisteredPublicKeyB64u,
|
|
3639
|
+
materialActivation: ed25519MaterialActivation
|
|
3640
|
+
}
|
|
3641
|
+
},
|
|
3642
|
+
now
|
|
3643
|
+
});
|
|
3644
|
+
} else foundingAuthorityRecords = await buildFoundingAuthorityRecords({
|
|
3645
|
+
authority: ceremonyAuthority,
|
|
3646
|
+
walletId: ceremony.intent.walletId,
|
|
3647
|
+
prepared,
|
|
3648
|
+
signerFacts: {
|
|
3649
|
+
kind: "both",
|
|
3650
|
+
keyFamilies: ["ed25519", "ecdsa_secp256k1"],
|
|
3651
|
+
ed25519: {
|
|
3652
|
+
signer: ed25519SignerRecord,
|
|
3653
|
+
registeredPublicKeyB64u: ed25519RegisteredPublicKeyB64u,
|
|
3654
|
+
materialActivation: ed25519MaterialActivation
|
|
3655
|
+
},
|
|
3656
|
+
ecdsa: {
|
|
3657
|
+
walletKey: requireSingleFoundingEcdsaWalletKey(ecdsaWalletKeys),
|
|
3658
|
+
materialActivation: ecdsaMaterialActivation
|
|
3659
|
+
}
|
|
3660
|
+
},
|
|
3661
|
+
now
|
|
3662
|
+
});
|
|
3663
|
+
else if (ecdsaWalletKey && ecdsaMaterialActivation) foundingAuthorityRecords = await buildFoundingAuthorityRecords({
|
|
3664
|
+
authority: ceremonyAuthority,
|
|
3665
|
+
walletId: ceremony.intent.walletId,
|
|
3666
|
+
prepared,
|
|
3667
|
+
signerFacts: {
|
|
3668
|
+
kind: "ecdsa_secp256k1",
|
|
3669
|
+
keyFamilies: ["ecdsa_secp256k1"],
|
|
3670
|
+
ecdsa: {
|
|
3671
|
+
walletKey: requireSingleFoundingEcdsaWalletKey(ecdsaWalletKeys),
|
|
3672
|
+
materialActivation: ecdsaMaterialActivation
|
|
3673
|
+
}
|
|
3674
|
+
},
|
|
3675
|
+
now
|
|
3676
|
+
});
|
|
3677
|
+
else return {
|
|
3678
|
+
ok: false,
|
|
3679
|
+
code: "invalid_state",
|
|
3680
|
+
message: "Complete registration is missing founding signer facts"
|
|
3681
|
+
};
|
|
3682
|
+
}
|
|
3683
|
+
const persistenceTiming = startD1RegistrationRouteTiming("relayPersistenceMs");
|
|
3684
|
+
try {
|
|
3685
|
+
switch (ceremonyAuthority.kind) {
|
|
3686
|
+
case "passkey":
|
|
3687
|
+
if (emailOtpEnrollment.persistence) return {
|
|
3688
|
+
ok: false,
|
|
3689
|
+
code: "invalid_state",
|
|
3690
|
+
message: "Passkey registration cannot persist Email OTP enrollment state"
|
|
3691
|
+
};
|
|
3692
|
+
if (foundingAuthorityRecords) await this.walletRegistrationCommitStore.commit({
|
|
3693
|
+
kind: "passkey_wallet_registration_commit_v1",
|
|
3694
|
+
wallet,
|
|
3695
|
+
walletSigners,
|
|
3696
|
+
authority: ceremonyAuthority,
|
|
3697
|
+
foundingAuthority: foundingAuthorityRecords.authority,
|
|
3698
|
+
foundingAuthMethod: foundingAuthorityRecords.authMethod,
|
|
3699
|
+
now
|
|
3700
|
+
});
|
|
3701
|
+
else await this.walletRegistrationCommitStore.commit({
|
|
3702
|
+
kind: "passkey_wallet_registration_commit_v1",
|
|
3703
|
+
wallet,
|
|
3704
|
+
walletSigners,
|
|
3705
|
+
authority: ceremonyAuthority,
|
|
3706
|
+
now
|
|
3707
|
+
});
|
|
3708
|
+
break;
|
|
3709
|
+
case "email_otp": {
|
|
3710
|
+
if (!emailOtpEnrollment.persistence) return {
|
|
3711
|
+
ok: false,
|
|
3712
|
+
code: "invalid_state",
|
|
3713
|
+
message: "Email OTP registration is missing enrollment persistence state"
|
|
3714
|
+
};
|
|
3715
|
+
const emailOtp = this.emailOtpRegistrationEnrollmentFinalizer.prepareRegistrationCommitPlan(emailOtpEnrollment.persistence);
|
|
3716
|
+
if (foundingAuthorityRecords) await this.walletRegistrationCommitStore.commit({
|
|
3717
|
+
kind: "email_otp_wallet_registration_commit_v1",
|
|
3718
|
+
wallet,
|
|
3719
|
+
walletSigners,
|
|
3720
|
+
authority: ceremonyAuthority,
|
|
3721
|
+
emailOtp,
|
|
3722
|
+
foundingAuthority: foundingAuthorityRecords.authority,
|
|
3723
|
+
foundingAuthMethod: foundingAuthorityRecords.authMethod,
|
|
3724
|
+
now
|
|
3725
|
+
});
|
|
3726
|
+
else await this.walletRegistrationCommitStore.commit({
|
|
3727
|
+
kind: "email_otp_wallet_registration_commit_v1",
|
|
3728
|
+
wallet,
|
|
3729
|
+
walletSigners,
|
|
3730
|
+
authority: ceremonyAuthority,
|
|
3731
|
+
emailOtp,
|
|
3732
|
+
now
|
|
3733
|
+
});
|
|
3734
|
+
break;
|
|
3735
|
+
}
|
|
3736
|
+
}
|
|
3737
|
+
} finally {
|
|
3738
|
+
finishD1RegistrationRouteTiming(finalizeTiming, persistenceTiming);
|
|
3739
|
+
}
|
|
3740
|
+
const completedRegistrationIdentity = await this.emailOtpRegistrationEnrollmentFinalizer.completeRegistrationIdentity({
|
|
3741
|
+
authority: ceremonyAuthority,
|
|
3742
|
+
walletId: ceremony.intent.walletId
|
|
3743
|
+
});
|
|
3744
|
+
if (!completedRegistrationIdentity.ok) return completedRegistrationIdentity;
|
|
3745
|
+
const persistedFoundingRecords = foundingAuthorityRecords ?? await this.walletAuthMethods.readActiveRegistrationIdentity(ceremonyAuthority);
|
|
3746
|
+
if (!persistedFoundingRecords) return {
|
|
3747
|
+
ok: false,
|
|
3748
|
+
code: "invalid_state",
|
|
3749
|
+
message: "Registration founding authority is unavailable after commit"
|
|
3750
|
+
};
|
|
3751
|
+
const foundingAuthority = persistedFoundingRecords.authority;
|
|
3752
|
+
const foundingAuthMethod = persistedFoundingRecords.authMethod;
|
|
3753
|
+
if (ed25519CapabilityInstallation) {
|
|
3754
|
+
const yaoRuntime = this.getEd25519YaoProductRegistration();
|
|
3755
|
+
if (!yaoRuntime) return {
|
|
3756
|
+
ok: false,
|
|
3757
|
+
code: "not_configured",
|
|
3758
|
+
message: "Ed25519 Yao product registration is not configured"
|
|
3759
|
+
};
|
|
3760
|
+
const installed = await yaoRuntime.installRegistrationFinalizeCapability(ed25519CapabilityInstallation);
|
|
3761
|
+
if (!installed.ok) return {
|
|
3762
|
+
ok: false,
|
|
3763
|
+
code: installed.code,
|
|
3764
|
+
message: installed.message
|
|
3765
|
+
};
|
|
3766
|
+
}
|
|
3767
|
+
const walletCustody = await commitRegistrationCustody({
|
|
3768
|
+
payload: walletCustodyCommitPayload,
|
|
3769
|
+
verifiedWalletId: ceremony.intent.walletId,
|
|
3770
|
+
verifiedAuthority: walletAuthAuthority,
|
|
3771
|
+
...emailOtpEnrollment.persistence ? { verifiedEmailOtpEnrollment: {
|
|
3772
|
+
enrollmentId: emailOtpEnrollment.persistence.enrollment.enrollmentId,
|
|
3773
|
+
enrollmentSealKeyVersion: emailOtpEnrollment.persistence.enrollment.enrollmentSealKeyVersion
|
|
3774
|
+
} } : {},
|
|
3775
|
+
nowMs: now,
|
|
3776
|
+
store: this.walletCustodyCommitStore
|
|
3777
|
+
});
|
|
3778
|
+
if (walletCustody.status === "rejected") console.warn("[wallet-registration] custody commit rejected", {
|
|
3779
|
+
registrationCeremonyId: ceremony.registrationCeremonyId,
|
|
3780
|
+
reason: walletCustody.reason
|
|
3781
|
+
});
|
|
3782
|
+
const custodyField = walletCustody.status === "not_requested" ? {} : { walletCustody };
|
|
3783
|
+
const authMethod = walletRegistrationFinalizeAuthMethodFromAuthority(ceremonyAuthority);
|
|
3784
|
+
let response;
|
|
3785
|
+
if (ed25519PublicResult && finalizeNearEd25519 && resolvedNearAccount) {
|
|
3786
|
+
const authorityScope = thresholdEd25519AuthorityScopeFromWalletAuthAuthority(walletAuthAuthority);
|
|
3787
|
+
response = authMethod.kind === "passkey" ? {
|
|
3788
|
+
ok: true,
|
|
3789
|
+
kind: "near_ed25519",
|
|
3790
|
+
walletId: ceremony.intent.walletId,
|
|
3791
|
+
authority: walletAuthAuthority,
|
|
3792
|
+
foundingAuthority,
|
|
3793
|
+
foundingAuthMethod,
|
|
3794
|
+
rpId: finalizePasskeyRpId(ceremonyAuthority),
|
|
3795
|
+
authMethod,
|
|
3796
|
+
...custodyField,
|
|
3797
|
+
custodyKeyManifestDigestB64u,
|
|
3798
|
+
authorityScope,
|
|
3799
|
+
accountProvisioning: finalizeNearEd25519.accountProvisioning,
|
|
3800
|
+
resolvedAccount: resolvedNearAccount,
|
|
3801
|
+
ed25519: ed25519PublicResult
|
|
3802
|
+
} : {
|
|
3803
|
+
ok: true,
|
|
3804
|
+
kind: "near_ed25519",
|
|
3805
|
+
walletId: ceremony.intent.walletId,
|
|
3806
|
+
authority: walletAuthAuthority,
|
|
3807
|
+
foundingAuthority,
|
|
3808
|
+
foundingAuthMethod,
|
|
3809
|
+
authMethod,
|
|
3810
|
+
...custodyField,
|
|
3811
|
+
custodyKeyManifestDigestB64u,
|
|
3812
|
+
authorityScope,
|
|
3813
|
+
accountProvisioning: finalizeNearEd25519.accountProvisioning,
|
|
3814
|
+
resolvedAccount: resolvedNearAccount,
|
|
3815
|
+
ed25519: ed25519PublicResult
|
|
3816
|
+
};
|
|
3817
|
+
} else response = authMethod.kind === "passkey" ? {
|
|
3818
|
+
ok: true,
|
|
3819
|
+
kind: "evm_family_ecdsa",
|
|
3820
|
+
walletId: ceremony.intent.walletId,
|
|
3821
|
+
authority: walletAuthAuthority,
|
|
3822
|
+
foundingAuthority,
|
|
3823
|
+
foundingAuthMethod,
|
|
3824
|
+
rpId: finalizePasskeyRpId(ceremonyAuthority),
|
|
3825
|
+
authMethod,
|
|
3826
|
+
...custodyField,
|
|
3827
|
+
custodyKeyManifestDigestB64u,
|
|
3828
|
+
ecdsa: { walletKeys: ecdsaWalletKeys }
|
|
3829
|
+
} : {
|
|
3830
|
+
ok: true,
|
|
3831
|
+
kind: "evm_family_ecdsa",
|
|
3832
|
+
walletId: ceremony.intent.walletId,
|
|
3833
|
+
authority: walletAuthAuthority,
|
|
3834
|
+
foundingAuthority,
|
|
3835
|
+
foundingAuthMethod,
|
|
3836
|
+
authMethod,
|
|
3837
|
+
...custodyField,
|
|
3838
|
+
custodyKeyManifestDigestB64u,
|
|
3839
|
+
ecdsa: { walletKeys: ecdsaWalletKeys }
|
|
3840
|
+
};
|
|
3841
|
+
if (ed25519FinalizePending) {
|
|
3842
|
+
if (!activatedEcdsaBranch) return {
|
|
3843
|
+
ok: false,
|
|
3844
|
+
code: "internal",
|
|
3845
|
+
message: "ECDSA finalize completed without an activated branch to advance"
|
|
3846
|
+
};
|
|
3847
|
+
if (!storedCeremony) return {
|
|
3848
|
+
ok: false,
|
|
3849
|
+
code: "invalid_state",
|
|
3850
|
+
message: "committed mixed registration cannot finalize ECDSA"
|
|
3851
|
+
};
|
|
3852
|
+
if (storedCeremony.signerState.kind !== "signer_set_registration") return {
|
|
3853
|
+
ok: false,
|
|
3854
|
+
code: "invalid_state",
|
|
3855
|
+
message: "signer-set registration state is required"
|
|
3856
|
+
};
|
|
3857
|
+
await store.updateCeremony({
|
|
3858
|
+
expected: storedCeremony,
|
|
3859
|
+
next: {
|
|
3860
|
+
...storedCeremony,
|
|
3861
|
+
signerState: replaceStoredWalletRegistrationSignerBranch({
|
|
3862
|
+
state: storedCeremony.signerState,
|
|
3863
|
+
replacement: buildStoredWalletRegistrationEvmFamilyEcdsaFinalizedBranch({
|
|
3864
|
+
activated: activatedEcdsaBranch,
|
|
3865
|
+
finalizedAtMs: now
|
|
3866
|
+
})
|
|
3867
|
+
})
|
|
3868
|
+
}
|
|
3869
|
+
});
|
|
3870
|
+
finishD1RegistrationRouteTiming(finalizeTiming, totalTiming);
|
|
3871
|
+
return withD1RegistrationRouteDiagnostics(response, finalizeTiming);
|
|
3872
|
+
}
|
|
3873
|
+
finishD1RegistrationRouteTiming(finalizeTiming, totalTiming);
|
|
3874
|
+
return withD1RegistrationRouteDiagnostics(response, finalizeTiming);
|
|
3875
|
+
} catch (error) {
|
|
3876
|
+
return {
|
|
3877
|
+
ok: false,
|
|
3878
|
+
code: "internal",
|
|
3879
|
+
message: errorMessage(error) || "Failed to finalize wallet registration ceremony"
|
|
3880
|
+
};
|
|
3881
|
+
}
|
|
3882
|
+
}
|
|
3883
|
+
};
|
|
3884
|
+
//#endregion
|
|
3885
|
+
export { CloudflareD1WalletRegistrationService, buildActivatedEcdsaFamilyBootstrap, ecdsaStrictRegistrationAuthority, exactEcdsaParticipantPair, hasEcdsaKeyHandleSetMismatch, mergeRouterServerTiming };
|
|
3886
|
+
|
|
3887
|
+
//# sourceMappingURL=d1WalletRegistrationService.js.map
|