@seams/wallet-server 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (369) hide show
  1. package/THIRD_PARTY_NOTICES.md +7 -1
  2. package/artifact-manifest.json +196 -41
  3. package/cloudflare-router-ab/build/deriver-a/build-stamp.json +1 -1
  4. package/cloudflare-router-ab/build/deriver-a/index.js +2 -2
  5. package/cloudflare-router-ab/build/deriver-a/index_bg.wasm +0 -0
  6. package/cloudflare-router-ab/build/deriver-b/build-stamp.json +1 -1
  7. package/cloudflare-router-ab/build/deriver-b/index.js +2 -2
  8. package/cloudflare-router-ab/build/deriver-b/index_bg.wasm +0 -0
  9. package/cloudflare-router-ab/build/local-tools/darwin-arm64/router_ab_local_init +0 -0
  10. package/cloudflare-router-ab/build/local-tools/darwin-x64/router_ab_local_init +0 -0
  11. package/cloudflare-router-ab/build/local-tools/linux-x64/router_ab_local_init +0 -0
  12. package/cloudflare-router-ab/build/router/build-stamp.json +1 -1
  13. package/cloudflare-router-ab/build/router/index.js +2 -2
  14. package/cloudflare-router-ab/build/router/index_bg.wasm +0 -0
  15. package/cloudflare-router-ab/build/signing-worker/build-stamp.json +1 -1
  16. package/cloudflare-router-ab/build/signing-worker/index.js +2 -2
  17. package/cloudflare-router-ab/build/signing-worker/index_bg.wasm +0 -0
  18. package/cloudflare-router-ab/build/tenant-root-control-plane/build-stamp.json +1 -1
  19. package/cloudflare-router-ab/build/tenant-root-control-plane/index.js +2 -2
  20. package/cloudflare-router-ab/build/tenant-root-control-plane/index_bg.wasm +0 -0
  21. package/cloudflare-router-ab/migrations/deriver-a/0019_wallet_object_addresses.sql +10 -0
  22. package/cloudflare-router-ab/migrations/deriver-b/0019_wallet_object_addresses.sql +10 -0
  23. package/cloudflare-router-ab/scripts/prepare-local-runtime-config.mjs +3 -117
  24. package/cloudflare-router-ab/wrangler.deriver-a.toml +0 -8
  25. package/cloudflare-router-ab/wrangler.deriver-b.toml +24 -8
  26. package/cloudflare-router-ab/wrangler.router.toml +0 -2
  27. package/cloudflare-router-ab/wrangler.signing-worker.toml +29 -0
  28. package/dist/esm/authorization/domain.js +3 -2
  29. package/dist/esm/authorization/ed25519WalletSessionAdmission.js +0 -0
  30. package/dist/esm/authorization/service.js +64 -36
  31. package/dist/esm/cloud-host.js +24 -19
  32. package/dist/esm/core/EmailOtpRecords.js +29 -6
  33. package/dist/esm/core/ThresholdService/routerAb/ecdsaDerivationPoolFillHandlers.js +2 -0
  34. package/dist/esm/core/ThresholdService/routerAb/ecdsaDerivationPresignBridge.js +10 -0
  35. package/dist/esm/core/ThresholdService/routerAb/internalServiceHttp.js +1 -0
  36. package/dist/esm/core/ThresholdService/validation.js +2 -2
  37. package/dist/esm/core/authService/nearPrivateKeySigning.js +1 -1
  38. package/dist/esm/core/authService/webauthn.js +1 -1
  39. package/dist/esm/core/d1Ed25519SignerRead.js +55 -0
  40. package/dist/esm/core/d1WalletStore.js +14 -11
  41. package/dist/esm/core/deviceLinking/linkedDeviceEmailOtpGrant.js +2 -2
  42. package/dist/esm/core/deviceLinking/linkedDeviceManagement.js +1 -1
  43. package/dist/esm/core/deviceLinking/linkedDeviceSessionRecord.js +2 -2
  44. package/dist/esm/core/emailOtpD1Statements.js +1 -0
  45. package/dist/esm/core/nearRelayerAccountProvisioning.js +1 -1
  46. package/dist/esm/core/routerAbSigning/RouterAbEcdsaPresignRuntime.js +4 -0
  47. package/dist/esm/core/signingLanes/WalletExecutionLaneProjection.js +1 -1
  48. package/dist/esm/core/signingMaterial/ordinaryInactiveSignerMaterialReservation.js +1 -0
  49. package/dist/esm/hosted-wallet-gateway.js +93 -10
  50. package/dist/esm/localHostedWalletGatewayHandler.js +12 -9
  51. package/dist/esm/localIntendedYaoSigningFault.js +2 -30
  52. package/dist/esm/localRegistrationSetupAuthority.js +8 -1
  53. package/dist/esm/router/auth/commonRouterUtils.js +17 -10
  54. package/dist/esm/router/auth/routerApiCredentialAuth.js +26 -7
  55. package/dist/esm/router/auth/walletRegistrationContext.js +49 -0
  56. package/dist/esm/router/auth/webAuthnCredentialCodecs.js +1 -1
  57. package/dist/esm/router/cloudflare/d1/auth/d1AuthorizationAssembly.js +4 -3
  58. package/dist/esm/router/cloudflare/d1/auth/d1AuthorizedOperationRouteService.js +2 -0
  59. package/dist/esm/router/cloudflare/d1/auth/d1EmailOtpRouteService.js +25 -0
  60. package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthConfig.js +14 -6
  61. package/dist/esm/router/cloudflare/d1/auth/d1RouterApiAuthService.js +44 -40
  62. package/dist/esm/router/cloudflare/d1/auth/walletSessionCredentialReaders.js +17 -1
  63. package/dist/esm/router/cloudflare/d1/authorization/authorizedOperationStatements.js +35 -5
  64. package/dist/esm/router/cloudflare/d1/authorization/d1AuthorizationStore.js +258 -99
  65. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceAuthorityInstallService.js +31 -4
  66. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceOwnerAuthorizationProvider.js +1 -1
  67. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceRequestProofNonceStore.js +1 -1
  68. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceSessionRecords.js +1 -1
  69. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetCredentialProvider.js +1 -1
  70. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceTargetPlanner.js +1 -1
  71. package/dist/esm/router/cloudflare/d1/deviceLinking/d1LinkedDeviceVerifiedLinkBuilder.js +1 -1
  72. package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoLifecycleDecisionStore.js +11 -2
  73. package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoProductRegistrationPartitionedStateStore.js +100 -10
  74. package/dist/esm/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoStateWriteFence.js +92 -0
  75. package/dist/esm/router/cloudflare/d1/ed25519Yao/d1WalletCeremonyActivity.js +77 -0
  76. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeIssuer.js +14 -8
  77. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeStore.js +14 -8
  78. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeVerifier.js +3 -1
  79. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRateLimitStore.js +58 -38
  80. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRecords.js +27 -20
  81. package/dist/esm/router/cloudflare/d1/emailOtp/d1EmailOtpRecoveryService.js +1 -0
  82. package/dist/esm/router/cloudflare/d1/emailOtp/d1GoogleEmailOtpSessionResolver.js +1 -0
  83. package/dist/esm/router/cloudflare/d1/oidc/d1OidcBoundary.js +1 -1
  84. package/dist/esm/router/cloudflare/d1/passkeyCustody/d1WalletCustodyCommitStore.js +18 -7
  85. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyRecordStore.js +75 -14
  86. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyRecords.js +1 -1
  87. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationCeremonyStore.js +49 -29
  88. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationSessionTransaction.js +28 -0
  89. package/dist/esm/router/cloudflare/d1/registration/d1RegistrationSetupSupport.js +11 -1
  90. package/dist/esm/router/cloudflare/d1/registration/d1WalletExecutionAuthority.js +168 -0
  91. package/dist/esm/router/cloudflare/d1/registration/d1WalletOperationStore.js +53 -0
  92. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationCommitStore.js +83 -42
  93. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationInitialSession.js +33 -0
  94. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationPreparation.js +16 -0
  95. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationRead.js +58 -0
  96. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationService.js +439 -500
  97. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationSetup.js +1 -1
  98. package/dist/esm/router/cloudflare/d1/registration/d1WalletRegistrationSetupExecution.js +104 -90
  99. package/dist/esm/router/cloudflare/d1/registration/walletRegistrationEstablishedSessionIssuer.js +78 -44
  100. package/dist/esm/router/cloudflare/d1/registration/walletRegistrationSessionCommitReceipt.js +11 -35
  101. package/dist/esm/router/cloudflare/d1/signingAdmission/d1RouterAbNormalSigningAdmissionStore.js +98 -39
  102. package/dist/esm/router/cloudflare/d1/versionedJson/d1VersionedJsonRecordStore.js +12 -9
  103. package/dist/esm/router/cloudflare/d1/wallet/authorizationSnapshotLayout.js +168 -0
  104. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAddSignerFinalizeRecord.js +1 -1
  105. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAddSignerService.js +15 -6
  106. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthMethodService.js +3 -40
  107. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorityStore.js +54 -1
  108. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorizationCleanup.js +157 -0
  109. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorizationFreeze.js +56 -0
  110. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorizationHistory.js +238 -0
  111. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorizationIntake.js +287 -0
  112. package/dist/esm/router/cloudflare/d1/wallet/d1WalletAuthorizationSnapshot.js +295 -0
  113. package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationApprovals.js +140 -0
  114. package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationChallenges.js +170 -0
  115. package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationEmailOtp.js +60 -0
  116. package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationOwner.js +33 -0
  117. package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationOwnerRequest.js +74 -0
  118. package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationPasskey.js +77 -0
  119. package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationReadAccess.js +37 -0
  120. package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationSessions.js +97 -0
  121. package/dist/esm/router/cloudflare/d1/wallet/d1WalletRelocationWriteBlock.js +133 -0
  122. package/dist/esm/router/cloudflare/d1/walletObjectAddresses.js +47 -0
  123. package/dist/esm/router/cloudflare/d1/webauthn/d1WebAuthnAuthService.js +1 -1
  124. package/dist/esm/router/cloudflare/runtime/routerAbServiceBindings.js +32 -1
  125. package/dist/esm/router/cloudflare/runtime/staticWalletConsoleBinding.js +20 -8
  126. package/dist/esm/router/cloudflare/runtime/walletAuthorizationRelocationRoutes.js +488 -0
  127. package/dist/esm/router/cloudflare/runtime/walletConsoleOps.js +1 -1
  128. package/dist/esm/router/cloudflare/runtime/walletConsoleOpsClient.js +26 -6
  129. package/dist/esm/router/cloudflare/runtime/walletControlOps.js +3 -0
  130. package/dist/esm/router/cloudflare/runtime/walletGateway.js +1 -1
  131. package/dist/esm/router/cloudflare/runtime/walletObjectAddresses.js +105 -0
  132. package/dist/esm/router/cloudflare/runtime/walletPlacementRoutes.js +339 -0
  133. package/dist/esm/router/cloudflare/runtime/walletRelocationDeriver.js +244 -0
  134. package/dist/esm/router/cloudflare/runtime/walletRelocationEcdsa.js +212 -0
  135. package/dist/esm/router/cloudflare/runtime/walletRelocationEd25519.js +172 -0
  136. package/dist/esm/router/cloudflare/runtime/walletRelocationOps.js +183 -0
  137. package/dist/esm/router/cloudflare/runtime/walletRelocationPresign.js +185 -0
  138. package/dist/esm/router/cloudflare/runtime/walletRelocationSource.js +221 -0
  139. package/dist/esm/router/cloudflare/signingLanes/cloudflareOrdinaryInactiveSignerMaterialReservation.js +30 -8
  140. package/dist/esm/router/cloudflare-adaptor.js +8 -8
  141. package/dist/esm/router/cloudflare.js +34115 -32240
  142. package/dist/esm/router/domains/ecdsa/routerAbEcdsaStrictRegistration.js +35 -9
  143. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoCapabilityCommit.js +42 -0
  144. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.js +32 -6
  145. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitionedStateStore.js +61 -1
  146. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPersistence.js +70 -3
  147. package/dist/esm/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationRequestScopedRuntime.js +59 -87
  148. package/dist/esm/router/domains/ed25519Yao/export/routerAbEd25519YaoExport.js +52 -22
  149. package/dist/esm/router/domains/ed25519Yao/export/routerAbEd25519YaoExportRequestScopedCloudflare.js +10 -7
  150. package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecovery.js +108 -78
  151. package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryRequestScopedCloudflare.js +19 -5
  152. package/dist/esm/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryWalletSessionAuthorization.js +71 -22
  153. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoHttpRegistrationBackend.js +37 -25
  154. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistration.js +3 -3
  155. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationExecutionRecord.js +2 -1
  156. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationIntentAuthorization.js +24 -3
  157. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationRequestScopedCloudflare.js +4 -3
  158. package/dist/esm/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.js +20 -7
  159. package/dist/esm/router/domains/ed25519Yao/routerAbEd25519YaoGatewayEnvelope.js +7 -1
  160. package/dist/esm/router/domains/emailOtp/emailOtpRouteHandlers.js +2 -2
  161. package/dist/esm/router/domains/passkeyCustody/passkeyCustodyEnvelopeRetrieval.js +1 -1
  162. package/dist/esm/router/domains/passkeyCustody/registrationCustodyOutcome.js +34 -18
  163. package/dist/esm/router/domains/passkeyCustody/walletCustodyRegistrationAdmission.js +2 -2
  164. package/dist/esm/router/domains/passkeyCustody/walletCustodyRegistrationCommit.js +16 -6
  165. package/dist/esm/router/domains/signingOperations/authorizedOperationWire.js +73 -0
  166. package/dist/esm/router/domains/signingOperations/ecdsaSigningResponse.js +31 -0
  167. package/dist/esm/router/domains/signingOperations/ed25519AuthorizedOperationReceipt.js +1 -1
  168. package/dist/esm/router/domains/signingOperations/routerAbEcdsaDerivationNormalSigningRoute.js +2 -1
  169. package/dist/esm/router/domains/signingOperations/routerAbEd25519NormalSigningRoute.js +31 -121
  170. package/dist/esm/router/domains/signingOperations/routerAbNormalSigningAdmission.js +2 -93
  171. package/dist/esm/router/domains/signingOperations/routerAbPrivateSigningWorker.js +1 -1
  172. package/dist/esm/router/domains/signingOperations/signingPrepareSession.js +33 -0
  173. package/dist/esm/router/domains/walletRegistration/registrationSessionSeal.js +121 -0
  174. package/dist/esm/router/domains/walletRegistration/walletRegistrationReservation.js +4 -4
  175. package/dist/esm/router/domains/walletRegistration/walletRegistrationRoutes.js +46 -157
  176. package/dist/esm/router/domains/walletRegistration/walletRegistrationSetupPayload.js +1 -1
  177. package/dist/esm/router/express.js +764 -894
  178. package/dist/esm/router/framework/http.js +2 -1
  179. package/dist/esm/router/transport/fetch/createFetchRouter.js +2 -2
  180. package/dist/esm/router/transport/fetch/routes/auth.js +1 -1
  181. package/dist/esm/router/transport/fetch/routes/deviceLinking.js +3 -3
  182. package/dist/esm/router/transport/fetch/routes/deviceLinkingOwnerAuthorization.js +2 -2
  183. package/dist/esm/router/transport/fetch/routes/ed25519AuthorizedOperationRevalidation.js +65 -0
  184. package/dist/esm/router/transport/fetch/routes/normalSigningRouterProxy.js +13 -3
  185. package/dist/esm/router/transport/fetch/routes/passkeyCustody.js +3 -3
  186. package/dist/esm/router/transport/fetch/routes/sessions.js +3 -2
  187. package/dist/esm/router/transport/fetch/routes/thresholdEcdsa.js +67 -130
  188. package/dist/esm/router/transport/fetch/routes/thresholdEd25519.js +76 -212
  189. package/dist/esm/router/transport/fetch/routes/walletExecutionLanePreflight.js +18 -41
  190. package/dist/esm/router/transport/fetch/routes/walletRegistration.js +6 -5
  191. package/dist/esm/router/transport/fetch/routes/webauthnAuthenticators.js +1 -1
  192. package/dist/esm/shared-ts/src/authorization/index.js +1 -1
  193. package/dist/esm/shared-ts/src/authorization/walletAuthority.js +2 -2
  194. package/dist/esm/shared-ts/src/device-linking/activeWalletSession.js +12 -2
  195. package/dist/esm/shared-ts/src/device-linking/digests.js +1 -1
  196. package/dist/esm/shared-ts/src/device-linking/ed25519ExportRoot.js +1 -1
  197. package/dist/esm/shared-ts/src/device-linking/index.js +1 -1
  198. package/dist/esm/shared-ts/src/device-linking/parsers.js +1 -1
  199. package/dist/esm/shared-ts/src/device-linking/sourceContribution.js +1 -1
  200. package/dist/esm/shared-ts/src/device-linking/wireFields.js +1 -1
  201. package/dist/esm/shared-ts/src/near/nearClient.js +1 -1
  202. package/dist/esm/shared-ts/src/signing-lanes/ownerContinuity.js +2 -2
  203. package/dist/esm/shared-ts/src/utils/ecdsaServerTiming.js +6 -1
  204. package/dist/esm/shared-ts/src/utils/emailOtpDomain.js +4 -2
  205. package/dist/esm/shared-ts/src/utils/routerAbEcdsaDerivation.js +1 -1
  206. package/dist/esm/shared-ts/src/utils/routerAbPublicKeyset.js +0 -27
  207. package/dist/esm/shared-ts/src/wallet-recovery/walletRecoveryEcdsaPossession.js +1 -1
  208. package/dist/esm/threshold/session/signingSessionSeal/options.js +1 -1
  209. package/dist/esm/wasm/near_signer/pkg/wasm_signer_worker_bg.wasm +0 -0
  210. package/dist/types/shared-ts/src/device-linking/activeWalletSession.d.ts +2 -1
  211. package/dist/types/shared-ts/src/device-linking/contracts.d.ts +10 -0
  212. package/dist/types/shared-ts/src/threshold/ed25519OperationFingerprint.d.ts +2 -1
  213. package/dist/types/shared-ts/src/utils/emailOtpDomain.d.ts +3 -1
  214. package/dist/types/shared-ts/src/utils/routerAbPublicKeyset.d.ts +0 -9
  215. package/dist/types/shared-ts/src/utils/walletManagementProtocol.d.ts +1 -1
  216. package/dist/types/wallet-server/src/authorization/domain.d.ts +17 -1
  217. package/dist/types/wallet-server/src/authorization/ecdsaWalletSessionAdmission.d.ts +1 -0
  218. package/dist/types/wallet-server/src/authorization/ed25519WalletSessionAdmission.d.ts +35 -0
  219. package/dist/types/wallet-server/src/authorization/ed25519WalletSessionAdmission.typecheck.d.ts +2 -0
  220. package/dist/types/wallet-server/src/authorization/service.d.ts +43 -5
  221. package/dist/types/wallet-server/src/authorization/sessionRouting.d.ts +2 -0
  222. package/dist/types/wallet-server/src/cloud-host.d.ts +7 -3
  223. package/dist/types/wallet-server/src/core/EmailOtpRecords.d.ts +2 -1
  224. package/dist/types/wallet-server/src/core/EmailOtpStores.d.ts +19 -5
  225. package/dist/types/wallet-server/src/core/ThresholdService/routerAb/ecdsaDerivationPoolFillHandlers.d.ts +1 -0
  226. package/dist/types/wallet-server/src/core/ThresholdService/routerAb/ecdsaDerivationPresignBridge.d.ts +6 -0
  227. package/dist/types/wallet-server/src/core/ThresholdService/routerAb/internalServiceHttp.d.ts +1 -0
  228. package/dist/types/wallet-server/src/core/d1Ed25519SignerRead.d.ts +17 -0
  229. package/dist/types/wallet-server/src/core/d1WalletStore.d.ts +6 -0
  230. package/dist/types/wallet-server/src/core/emailOtpD1Statements.d.ts +1 -0
  231. package/dist/types/wallet-server/src/core/routerAbSigning/RouterAbEcdsaPresignRuntime.d.ts +5 -1
  232. package/dist/types/wallet-server/src/core/signingMaterial/ordinaryInactiveSignerMaterialReservation.d.ts +1 -0
  233. package/dist/types/wallet-server/src/core/threeRouteRegistrationContracts.d.ts +14 -48
  234. package/dist/types/wallet-server/src/hosted-wallet-gateway.d.ts +4 -3
  235. package/dist/types/wallet-server/src/localIntendedYaoSigningFault.d.ts +1 -16
  236. package/dist/types/wallet-server/src/localRegistrationSetupAuthority.d.ts +1 -1
  237. package/dist/types/wallet-server/src/router/auth/commonRouterUtils.d.ts +7 -1
  238. package/dist/types/wallet-server/src/router/auth/routerApiCredentialAuth.d.ts +11 -3
  239. package/dist/types/wallet-server/src/router/auth/walletRegistrationContext.d.ts +8 -0
  240. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1AuthorizationAssembly.d.ts +1 -1
  241. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1EmailOtpRouteService.d.ts +16 -0
  242. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthConfig.d.ts +7 -4
  243. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/d1RouterApiAuthService.d.ts +4 -1
  244. package/dist/types/wallet-server/src/router/cloudflare/d1/auth/walletSessionCredentialReaders.d.ts +7 -1
  245. package/dist/types/wallet-server/src/router/cloudflare/d1/authorization/d1AuthorizationStore.d.ts +32 -1
  246. package/dist/types/wallet-server/src/router/cloudflare/d1/deviceLinking/d1LinkedDeviceAuthorityInstallService.d.ts +2 -0
  247. package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoLifecycleDecisionStore.d.ts +3 -1
  248. package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoProductRegistrationPartitionedStateStore.d.ts +1 -0
  249. package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1Ed25519YaoStateWriteFence.d.ts +8 -0
  250. package/dist/types/wallet-server/src/router/cloudflare/d1/ed25519Yao/d1WalletCeremonyActivity.d.ts +15 -0
  251. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeIssuer.d.ts +6 -1
  252. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeStore.d.ts +1 -0
  253. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpChallengeVerifier.d.ts +4 -1
  254. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpCounters.typecheck.d.ts +2 -0
  255. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRateLimitStore.d.ts +6 -29
  256. package/dist/types/wallet-server/src/router/cloudflare/d1/emailOtp/d1EmailOtpRecords.d.ts +21 -7
  257. package/dist/types/wallet-server/src/router/cloudflare/d1/passkeyCustody/d1WalletCustodyCommitStore.d.ts +17 -1
  258. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyRecordStore.d.ts +32 -7
  259. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationCeremonyStore.d.ts +16 -7
  260. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationSessionTransaction.d.ts +13 -0
  261. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1RegistrationSetupSupport.d.ts +7 -0
  262. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletExecutionAuthority.d.ts +41 -0
  263. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletOperationStore.d.ts +28 -0
  264. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationCommitStore.d.ts +6 -9
  265. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationInitialSession.d.ts +17 -0
  266. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationPreparation.d.ts +12 -0
  267. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationRead.d.ts +43 -0
  268. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationService.d.ts +24 -45
  269. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/d1WalletRegistrationSetupExecution.d.ts +9 -4
  270. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/walletRegistrationEstablishedSessionIssuer.d.ts +42 -14
  271. package/dist/types/wallet-server/src/router/cloudflare/d1/registration/walletRegistrationSessionCommitReceipt.d.ts +5 -4
  272. package/dist/types/wallet-server/src/router/cloudflare/d1/signingAdmission/d1RouterAbNormalSigningAdmissionStore.d.ts +24 -1
  273. package/dist/types/wallet-server/src/router/cloudflare/d1/versionedJson/d1VersionedJsonRecordStore.d.ts +10 -4
  274. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/authorizationSnapshotLayout.d.ts +21 -0
  275. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAddSignerService.d.ts +3 -0
  276. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthMethodService.d.ts +3 -7
  277. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorityStore.d.ts +8 -0
  278. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorizationCleanup.d.ts +20 -0
  279. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorizationFreeze.d.ts +12 -0
  280. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorizationHistory.d.ts +20 -0
  281. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorizationIntake.d.ts +29 -0
  282. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletAuthorizationSnapshot.d.ts +31 -0
  283. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationApprovals.d.ts +49 -0
  284. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationChallenges.d.ts +47 -0
  285. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationEmailOtp.d.ts +25 -0
  286. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationOwner.d.ts +88 -0
  287. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationOwnerRequest.d.ts +37 -0
  288. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationPasskey.d.ts +12 -0
  289. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationReadAccess.d.ts +18 -0
  290. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationSessions.d.ts +23 -0
  291. package/dist/types/wallet-server/src/router/cloudflare/d1/wallet/d1WalletRelocationWriteBlock.d.ts +16 -0
  292. package/dist/types/wallet-server/src/router/cloudflare/d1/walletObjectAddresses.d.ts +14 -0
  293. package/dist/types/wallet-server/src/router/cloudflare/runtime/routerAbServiceBindings.d.ts +13 -0
  294. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletAuthorizationRelocationRoutes.d.ts +21 -0
  295. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletConsoleOps.d.ts +1 -1
  296. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletConsoleOpsClient.d.ts +3 -3
  297. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletControlOps.d.ts +2 -1
  298. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletGateway.d.ts +3 -1
  299. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletObjectAddresses.d.ts +45 -0
  300. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletPlacementRoutes.d.ts +30 -0
  301. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRelocationDeriver.d.ts +11 -0
  302. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRelocationEcdsa.d.ts +7 -0
  303. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRelocationEd25519.d.ts +7 -0
  304. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRelocationOps.d.ts +11 -0
  305. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRelocationPresign.d.ts +7 -0
  306. package/dist/types/wallet-server/src/router/cloudflare/runtime/walletRelocationSource.d.ts +26 -0
  307. package/dist/types/wallet-server/src/router/cloudflare/signingLanes/cloudflareOrdinaryInactiveSignerMaterialReservation.d.ts +5 -0
  308. package/dist/types/wallet-server/src/router/domains/ecdsa/routerAbEcdsaStrictRegistration.d.ts +3 -0
  309. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoCapabilityCommit.d.ts +7 -0
  310. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistration.d.ts +41 -7
  311. package/dist/types/wallet-server/src/router/domains/ed25519Yao/capabilityLifecycle/routerAbEd25519YaoProductRegistrationPartitionedStateStore.d.ts +33 -2
  312. package/dist/types/wallet-server/src/router/domains/ed25519Yao/export/routerAbEd25519YaoExport.d.ts +12 -6
  313. package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecovery.d.ts +17 -9
  314. package/dist/types/wallet-server/src/router/domains/ed25519Yao/recovery/routerAbEd25519YaoRecoveryWalletSessionAuthorization.d.ts +2 -0
  315. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoHttpRegistrationBackend.d.ts +13 -14
  316. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistration.d.ts +7 -3
  317. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationExecutionRecord.d.ts +1 -0
  318. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationIntentAuthorization.d.ts +6 -1
  319. package/dist/types/wallet-server/src/router/domains/ed25519Yao/registration/routerAbEd25519YaoRegistrationSideEffectBoundary.d.ts +11 -0
  320. package/dist/types/wallet-server/src/router/domains/ed25519Yao/routerAbEd25519YaoGatewayEnvelope.d.ts +12 -3
  321. package/dist/types/wallet-server/src/router/domains/passkeyCustody/registrationCustodyOutcome.d.ts +10 -6
  322. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletCustodyRegistrationAdmission.d.ts +10 -3
  323. package/dist/types/wallet-server/src/router/domains/passkeyCustody/walletCustodyRegistrationCommit.d.ts +12 -5
  324. package/dist/types/wallet-server/src/router/domains/signingOperations/authorizedOperationWire.d.ts +97 -0
  325. package/dist/types/wallet-server/src/router/domains/signingOperations/ecdsaSigningResponse.d.ts +13 -0
  326. package/dist/types/wallet-server/src/router/domains/signingOperations/routerAbNormalSigningAdmission.d.ts +9 -206
  327. package/dist/types/wallet-server/src/router/domains/signingOperations/signingPrepareSession.d.ts +23 -0
  328. package/dist/types/wallet-server/src/router/domains/walletRegistration/registrationSessionSeal.d.ts +36 -0
  329. package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationInputs.d.ts +7 -7
  330. package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationReservation.d.ts +80 -6
  331. package/dist/types/wallet-server/src/router/domains/walletRegistration/walletRegistrationRoutes.d.ts +15 -5
  332. package/dist/types/wallet-server/src/router/framework/apiCredentialPorts.d.ts +24 -0
  333. package/dist/types/wallet-server/src/router/framework/authServicePort.d.ts +21 -7
  334. package/dist/types/wallet-server/src/router/framework/routerApi.d.ts +3 -12
  335. package/dist/types/wallet-server/src/router/transport/fetch/routes/ed25519AuthorizedOperationRevalidation.d.ts +37 -0
  336. package/dist/types/wallet-server/src/router/transport/fetch/routes/thresholdEcdsa.d.ts +1 -17
  337. package/dist/types/wallet-server/src/storage/tenantRoute.d.ts +1 -1
  338. package/migrations/d1-signer/0049_wallet_relocation_challenges.sql +16 -0
  339. package/migrations/d1-signer/0050_wallet_relocation_approvals.sql +14 -0
  340. package/migrations/d1-signer/0051_wallet_relocation_email_otp.sql +92 -0
  341. package/migrations/d1-signer/0052_wallet_relocation_session_fences.sql +91 -0
  342. package/migrations/d1-signer/0053_wallet_hosted_history_import.sql +164 -0
  343. package/migrations/d1-signer/0054_wallet_authorization_freeze.sql +318 -0
  344. package/migrations/d1-signer/0055_wallet_authorization_snapshot.sql +120 -0
  345. package/migrations/d1-signer/0056_wallet_authorization_history_import.sql +424 -0
  346. package/migrations/d1-signer/0057_wallet_authorization_intake.sql +44 -0
  347. package/migrations/d1-signer/0058_wallet_ceremony_activity.sql +59 -0
  348. package/migrations/d1-signer/0059_wallet_authorization_activation.sql +45 -0
  349. package/migrations/d1-signer/0060_wallet_authorization_cleanup.sql +153 -0
  350. package/migrations/d1-signer/0061_wallet_session_operation_settlement.sql +28 -0
  351. package/migrations/d1-signer/0062_wallet_step_up_operation_settlement.sql +204 -0
  352. package/migrations/d1-signer/0063_wallet_operation_history_transfer.sql +466 -0
  353. package/migrations/d1-signer/0064_wallet_execution_generations.sql +93 -0
  354. package/migrations/d1-signer/0065_wallet_operation_execution_generation.sql +37 -0
  355. package/migrations/d1-signer/0066_regional_deployment_admission.sql +59 -0
  356. package/migrations/d1-signer/0067_registration_completion_decision.sql +12 -0
  357. package/migrations/d1-signer/0068_registration_cancellation_write_fence.sql +24 -0
  358. package/migrations/d1-signer/0069_cancelled_registration_session_fence.sql +11 -0
  359. package/migrations/d1-signer/0070_wallet_passkey_relocation.sql +369 -0
  360. package/migrations/d1-signer/0071_regional_wallet_otp_counters.sql +98 -0
  361. package/migrations/d1-signer/0072_linked_device_relocation_history.sql +899 -0
  362. package/migrations/d1-signer/0073_wallet_recovery_relocation.sql +86 -0
  363. package/migrations/d1-signer/0074_email_otp_relocation.sql +158 -0
  364. package/migrations/d1-signer/0075_wallet_authorization_return.sql +107 -0
  365. package/migrations/d1-signer/0076_wallet_relocation_write_block.sql +406 -0
  366. package/migrations/d1-signer/0077_wallet_object_addresses.sql +24 -0
  367. package/package.json +1 -1
  368. package/src/README.md +23 -1
  369. package/cloudflare-router-ab/scripts/local-key-material.mjs +0 -29
@@ -0,0 +1,899 @@
1
+ -- Snapshot inventories must not change during an in-progress transfer.
2
+ CREATE TABLE wallet_linked_relocation_upgrade_guard (count INTEGER NOT NULL CHECK (count = 0));
3
+ INSERT INTO wallet_linked_relocation_upgrade_guard
4
+ SELECT (SELECT COUNT(*) FROM wallet_relocation_authorization_snapshots AS snapshot
5
+ WHERE NOT EXISTS (
6
+ SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
7
+ WHERE cleanup.namespace = snapshot.namespace AND cleanup.org_id = snapshot.org_id
8
+ AND cleanup.project_id = snapshot.project_id AND cleanup.env_id = snapshot.env_id
9
+ AND cleanup.wallet_id = snapshot.wallet_id AND cleanup.move_id = snapshot.move_id
10
+ AND cleanup.request_digest_hex = snapshot.request_digest_hex
11
+ AND cleanup.source_generation = snapshot.source_generation
12
+ AND cleanup.state = 'cleaned'))
13
+ + (SELECT COUNT(*) FROM wallet_relocation_authorization_imports WHERE state != 'activated');
14
+ DROP TABLE wallet_linked_relocation_upgrade_guard;
15
+
16
+ -- Transfer linked-device enrollment and delivery history with its retired sessions.
17
+ -- The existing import context authorizes one exact record. Imported history cannot resume.
18
+
19
+ CREATE TRIGGER linked_device_sessions_relocation_insert
20
+ BEFORE INSERT ON linked_device_sessions
21
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
22
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
23
+ AND fence.wallet_id = json_extract(NEW.record_json, '$.claimTranscript.value.walletId')))
24
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
25
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
26
+ AND destination.wallet_id = json_extract(NEW.record_json, '$.claimTranscript.value.walletId') AND destination.state != 'activated') AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_context AS context
27
+ JOIN wallet_relocation_authorization_imports AS destination
28
+ ON destination.namespace = context.namespace AND destination.org_id = context.org_id
29
+ AND destination.project_id = context.project_id AND destination.env_id = context.env_id
30
+ AND destination.wallet_id = context.wallet_id AND destination.move_id = context.move_id
31
+ AND destination.request_digest_hex = context.request_digest_hex
32
+ AND destination.source_generation = context.source_generation AND destination.state = 'importing'
33
+ WHERE context.namespace = NEW.namespace AND context.org_id = NEW.org_id
34
+ AND context.project_id = NEW.project_id AND context.env_id = NEW.env_id
35
+ AND context.wallet_id = json_extract(NEW.record_json, '$.claimTranscript.value.walletId')
36
+ AND context.table_name = 'linked_device_sessions' AND context.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id)))
37
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
38
+
39
+ CREATE TRIGGER linked_device_sessions_relocation_update
40
+ BEFORE UPDATE ON linked_device_sessions
41
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
42
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
43
+ AND fence.wallet_id = json_extract(OLD.record_json, '$.claimTranscript.value.walletId')))
44
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
45
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
46
+ AND destination.wallet_id = json_extract(OLD.record_json, '$.claimTranscript.value.walletId') AND destination.state != 'activated'))
47
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
48
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
49
+ AND receipt.wallet_id = json_extract(OLD.record_json, '$.claimTranscript.value.walletId') AND receipt.table_name = 'linked_device_sessions' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id)))
50
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
51
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
52
+ AND fence.wallet_id = json_extract(NEW.record_json, '$.claimTranscript.value.walletId')))
53
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
54
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
55
+ AND destination.wallet_id = json_extract(NEW.record_json, '$.claimTranscript.value.walletId') AND destination.state != 'activated'))
56
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = NEW.namespace AND receipt.org_id = NEW.org_id
57
+ AND receipt.project_id = NEW.project_id AND receipt.env_id = NEW.env_id
58
+ AND receipt.wallet_id = json_extract(NEW.record_json, '$.claimTranscript.value.walletId') AND receipt.table_name = 'linked_device_sessions' AND receipt.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id)))
59
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
60
+
61
+ CREATE TRIGGER linked_device_sessions_relocation_delete
62
+ BEFORE DELETE ON linked_device_sessions
63
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
64
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
65
+ AND fence.wallet_id = json_extract(OLD.record_json, '$.claimTranscript.value.walletId')) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
66
+ JOIN wallet_relocation_authorization_fences AS fence
67
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
68
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
69
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
70
+ AND cleanup.request_digest_hex = fence.request_digest_hex
71
+ AND cleanup.source_generation = fence.source_generation
72
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
73
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
74
+ AND cleanup.wallet_id = json_extract(OLD.record_json, '$.claimTranscript.value.walletId') AND cleanup.state = 'cleaning'))
75
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
76
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
77
+ AND destination.wallet_id = json_extract(OLD.record_json, '$.claimTranscript.value.walletId') AND destination.state != 'activated'))
78
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
79
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
80
+ AND receipt.wallet_id = json_extract(OLD.record_json, '$.claimTranscript.value.walletId') AND receipt.table_name = 'linked_device_sessions' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id)) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
81
+ JOIN wallet_relocation_authorization_fences AS fence
82
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
83
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
84
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
85
+ AND cleanup.request_digest_hex = fence.request_digest_hex
86
+ AND cleanup.source_generation = fence.source_generation
87
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
88
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
89
+ AND cleanup.wallet_id = json_extract(OLD.record_json, '$.claimTranscript.value.walletId') AND cleanup.state = 'cleaning'))
90
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
91
+
92
+ CREATE TRIGGER linked_device_authority_allocations_relocation_insert
93
+ BEFORE INSERT ON linked_device_authority_allocations
94
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
95
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
96
+ AND fence.wallet_id = NEW.wallet_id))
97
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
98
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
99
+ AND destination.wallet_id = NEW.wallet_id AND destination.state != 'activated') AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_context AS context
100
+ JOIN wallet_relocation_authorization_imports AS destination
101
+ ON destination.namespace = context.namespace AND destination.org_id = context.org_id
102
+ AND destination.project_id = context.project_id AND destination.env_id = context.env_id
103
+ AND destination.wallet_id = context.wallet_id AND destination.move_id = context.move_id
104
+ AND destination.request_digest_hex = context.request_digest_hex
105
+ AND destination.source_generation = context.source_generation AND destination.state = 'importing'
106
+ WHERE context.namespace = NEW.namespace AND context.org_id = NEW.org_id
107
+ AND context.project_id = NEW.project_id AND context.env_id = NEW.env_id
108
+ AND context.wallet_id = NEW.wallet_id
109
+ AND context.table_name = 'linked_device_authority_allocations' AND context.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id)))
110
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
111
+
112
+ CREATE TRIGGER linked_device_authority_allocations_relocation_update
113
+ BEFORE UPDATE ON linked_device_authority_allocations
114
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
115
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
116
+ AND fence.wallet_id = OLD.wallet_id))
117
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
118
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
119
+ AND destination.wallet_id = OLD.wallet_id AND destination.state != 'activated'))
120
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
121
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
122
+ AND receipt.wallet_id = OLD.wallet_id AND receipt.table_name = 'linked_device_authority_allocations' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id)))
123
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
124
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
125
+ AND fence.wallet_id = NEW.wallet_id))
126
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
127
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
128
+ AND destination.wallet_id = NEW.wallet_id AND destination.state != 'activated'))
129
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = NEW.namespace AND receipt.org_id = NEW.org_id
130
+ AND receipt.project_id = NEW.project_id AND receipt.env_id = NEW.env_id
131
+ AND receipt.wallet_id = NEW.wallet_id AND receipt.table_name = 'linked_device_authority_allocations' AND receipt.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id)))
132
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
133
+
134
+ CREATE TRIGGER linked_device_authority_allocations_relocation_delete
135
+ BEFORE DELETE ON linked_device_authority_allocations
136
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
137
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
138
+ AND fence.wallet_id = OLD.wallet_id) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
139
+ JOIN wallet_relocation_authorization_fences AS fence
140
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
141
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
142
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
143
+ AND cleanup.request_digest_hex = fence.request_digest_hex
144
+ AND cleanup.source_generation = fence.source_generation
145
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
146
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
147
+ AND cleanup.wallet_id = OLD.wallet_id AND cleanup.state = 'cleaning'))
148
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
149
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
150
+ AND destination.wallet_id = OLD.wallet_id AND destination.state != 'activated'))
151
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
152
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
153
+ AND receipt.wallet_id = OLD.wallet_id AND receipt.table_name = 'linked_device_authority_allocations' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id)) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
154
+ JOIN wallet_relocation_authorization_fences AS fence
155
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
156
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
157
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
158
+ AND cleanup.request_digest_hex = fence.request_digest_hex
159
+ AND cleanup.source_generation = fence.source_generation
160
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
161
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
162
+ AND cleanup.wallet_id = OLD.wallet_id AND cleanup.state = 'cleaning'))
163
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
164
+
165
+ CREATE TRIGGER linked_device_authority_installations_relocation_insert
166
+ BEFORE INSERT ON linked_device_authority_installations
167
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
168
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
169
+ AND fence.wallet_id = NEW.wallet_id))
170
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
171
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
172
+ AND destination.wallet_id = NEW.wallet_id AND destination.state != 'activated') AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_context AS context
173
+ JOIN wallet_relocation_authorization_imports AS destination
174
+ ON destination.namespace = context.namespace AND destination.org_id = context.org_id
175
+ AND destination.project_id = context.project_id AND destination.env_id = context.env_id
176
+ AND destination.wallet_id = context.wallet_id AND destination.move_id = context.move_id
177
+ AND destination.request_digest_hex = context.request_digest_hex
178
+ AND destination.source_generation = context.source_generation AND destination.state = 'importing'
179
+ WHERE context.namespace = NEW.namespace AND context.org_id = NEW.org_id
180
+ AND context.project_id = NEW.project_id AND context.env_id = NEW.env_id
181
+ AND context.wallet_id = NEW.wallet_id
182
+ AND context.table_name = 'linked_device_authority_installations' AND context.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id)))
183
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
184
+
185
+ CREATE TRIGGER linked_device_authority_installations_relocation_update
186
+ BEFORE UPDATE ON linked_device_authority_installations
187
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
188
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
189
+ AND fence.wallet_id = OLD.wallet_id))
190
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
191
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
192
+ AND destination.wallet_id = OLD.wallet_id AND destination.state != 'activated'))
193
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
194
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
195
+ AND receipt.wallet_id = OLD.wallet_id AND receipt.table_name = 'linked_device_authority_installations' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id)))
196
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
197
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
198
+ AND fence.wallet_id = NEW.wallet_id))
199
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
200
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
201
+ AND destination.wallet_id = NEW.wallet_id AND destination.state != 'activated'))
202
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = NEW.namespace AND receipt.org_id = NEW.org_id
203
+ AND receipt.project_id = NEW.project_id AND receipt.env_id = NEW.env_id
204
+ AND receipt.wallet_id = NEW.wallet_id AND receipt.table_name = 'linked_device_authority_installations' AND receipt.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id)))
205
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
206
+
207
+ CREATE TRIGGER linked_device_authority_installations_relocation_delete
208
+ BEFORE DELETE ON linked_device_authority_installations
209
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
210
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
211
+ AND fence.wallet_id = OLD.wallet_id) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
212
+ JOIN wallet_relocation_authorization_fences AS fence
213
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
214
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
215
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
216
+ AND cleanup.request_digest_hex = fence.request_digest_hex
217
+ AND cleanup.source_generation = fence.source_generation
218
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
219
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
220
+ AND cleanup.wallet_id = OLD.wallet_id AND cleanup.state = 'cleaning'))
221
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
222
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
223
+ AND destination.wallet_id = OLD.wallet_id AND destination.state != 'activated'))
224
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
225
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
226
+ AND receipt.wallet_id = OLD.wallet_id AND receipt.table_name = 'linked_device_authority_installations' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id)) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
227
+ JOIN wallet_relocation_authorization_fences AS fence
228
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
229
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
230
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
231
+ AND cleanup.request_digest_hex = fence.request_digest_hex
232
+ AND cleanup.source_generation = fence.source_generation
233
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
234
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
235
+ AND cleanup.wallet_id = OLD.wallet_id AND cleanup.state = 'cleaning'))
236
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
237
+
238
+ CREATE TRIGGER linked_device_target_credentials_relocation_insert
239
+ BEFORE INSERT ON linked_device_target_credentials
240
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
241
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
242
+ AND fence.wallet_id = NEW.wallet_id))
243
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
244
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
245
+ AND destination.wallet_id = NEW.wallet_id AND destination.state != 'activated') AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_context AS context
246
+ JOIN wallet_relocation_authorization_imports AS destination
247
+ ON destination.namespace = context.namespace AND destination.org_id = context.org_id
248
+ AND destination.project_id = context.project_id AND destination.env_id = context.env_id
249
+ AND destination.wallet_id = context.wallet_id AND destination.move_id = context.move_id
250
+ AND destination.request_digest_hex = context.request_digest_hex
251
+ AND destination.source_generation = context.source_generation AND destination.state = 'importing'
252
+ WHERE context.namespace = NEW.namespace AND context.org_id = NEW.org_id
253
+ AND context.project_id = NEW.project_id AND context.env_id = NEW.env_id
254
+ AND context.wallet_id = NEW.wallet_id
255
+ AND context.table_name = 'linked_device_target_credentials' AND context.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id)))
256
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
257
+
258
+ CREATE TRIGGER linked_device_target_credentials_relocation_update
259
+ BEFORE UPDATE ON linked_device_target_credentials
260
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
261
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
262
+ AND fence.wallet_id = OLD.wallet_id))
263
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
264
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
265
+ AND destination.wallet_id = OLD.wallet_id AND destination.state != 'activated'))
266
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
267
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
268
+ AND receipt.wallet_id = OLD.wallet_id AND receipt.table_name = 'linked_device_target_credentials' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id)))
269
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
270
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
271
+ AND fence.wallet_id = NEW.wallet_id))
272
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
273
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
274
+ AND destination.wallet_id = NEW.wallet_id AND destination.state != 'activated'))
275
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = NEW.namespace AND receipt.org_id = NEW.org_id
276
+ AND receipt.project_id = NEW.project_id AND receipt.env_id = NEW.env_id
277
+ AND receipt.wallet_id = NEW.wallet_id AND receipt.table_name = 'linked_device_target_credentials' AND receipt.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id)))
278
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
279
+
280
+ CREATE TRIGGER linked_device_target_credentials_relocation_delete
281
+ BEFORE DELETE ON linked_device_target_credentials
282
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
283
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
284
+ AND fence.wallet_id = OLD.wallet_id) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
285
+ JOIN wallet_relocation_authorization_fences AS fence
286
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
287
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
288
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
289
+ AND cleanup.request_digest_hex = fence.request_digest_hex
290
+ AND cleanup.source_generation = fence.source_generation
291
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
292
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
293
+ AND cleanup.wallet_id = OLD.wallet_id AND cleanup.state = 'cleaning'))
294
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
295
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
296
+ AND destination.wallet_id = OLD.wallet_id AND destination.state != 'activated'))
297
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
298
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
299
+ AND receipt.wallet_id = OLD.wallet_id AND receipt.table_name = 'linked_device_target_credentials' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id)) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
300
+ JOIN wallet_relocation_authorization_fences AS fence
301
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
302
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
303
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
304
+ AND cleanup.request_digest_hex = fence.request_digest_hex
305
+ AND cleanup.source_generation = fence.source_generation
306
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
307
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
308
+ AND cleanup.wallet_id = OLD.wallet_id AND cleanup.state = 'cleaning'))
309
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
310
+
311
+ CREATE TRIGGER linked_device_target_commit_reservations_relocation_insert
312
+ BEFORE INSERT ON linked_device_target_commit_reservations
313
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
314
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
315
+ AND fence.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id)))
316
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
317
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
318
+ AND destination.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id) AND destination.state != 'activated') AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_context AS context
319
+ JOIN wallet_relocation_authorization_imports AS destination
320
+ ON destination.namespace = context.namespace AND destination.org_id = context.org_id
321
+ AND destination.project_id = context.project_id AND destination.env_id = context.env_id
322
+ AND destination.wallet_id = context.wallet_id AND destination.move_id = context.move_id
323
+ AND destination.request_digest_hex = context.request_digest_hex
324
+ AND destination.source_generation = context.source_generation AND destination.state = 'importing'
325
+ WHERE context.namespace = NEW.namespace AND context.org_id = NEW.org_id
326
+ AND context.project_id = NEW.project_id AND context.env_id = NEW.env_id
327
+ AND context.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id)
328
+ AND context.table_name = 'linked_device_target_commit_reservations' AND context.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id)))
329
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
330
+
331
+ CREATE TRIGGER linked_device_target_commit_reservations_relocation_update
332
+ BEFORE UPDATE ON linked_device_target_commit_reservations
333
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
334
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
335
+ AND fence.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id)))
336
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
337
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
338
+ AND destination.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND destination.state != 'activated'))
339
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
340
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
341
+ AND receipt.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND receipt.table_name = 'linked_device_target_commit_reservations' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id)))
342
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
343
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
344
+ AND fence.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id)))
345
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
346
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
347
+ AND destination.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id) AND destination.state != 'activated'))
348
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = NEW.namespace AND receipt.org_id = NEW.org_id
349
+ AND receipt.project_id = NEW.project_id AND receipt.env_id = NEW.env_id
350
+ AND receipt.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id) AND receipt.table_name = 'linked_device_target_commit_reservations' AND receipt.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id)))
351
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
352
+
353
+ CREATE TRIGGER linked_device_target_commit_reservations_relocation_delete
354
+ BEFORE DELETE ON linked_device_target_commit_reservations
355
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
356
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
357
+ AND fence.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id)) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
358
+ JOIN wallet_relocation_authorization_fences AS fence
359
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
360
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
361
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
362
+ AND cleanup.request_digest_hex = fence.request_digest_hex
363
+ AND cleanup.source_generation = fence.source_generation
364
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
365
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
366
+ AND cleanup.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND cleanup.state = 'cleaning'))
367
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
368
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
369
+ AND destination.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND destination.state != 'activated'))
370
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
371
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
372
+ AND receipt.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND receipt.table_name = 'linked_device_target_commit_reservations' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id)) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
373
+ JOIN wallet_relocation_authorization_fences AS fence
374
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
375
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
376
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
377
+ AND cleanup.request_digest_hex = fence.request_digest_hex
378
+ AND cleanup.source_generation = fence.source_generation
379
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
380
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
381
+ AND cleanup.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND cleanup.state = 'cleaning'))
382
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
383
+
384
+ CREATE TRIGGER linked_device_session_transcripts_relocation_insert
385
+ BEFORE INSERT ON linked_device_session_transcripts
386
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
387
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
388
+ AND fence.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id)))
389
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
390
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
391
+ AND destination.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id) AND destination.state != 'activated') AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_context AS context
392
+ JOIN wallet_relocation_authorization_imports AS destination
393
+ ON destination.namespace = context.namespace AND destination.org_id = context.org_id
394
+ AND destination.project_id = context.project_id AND destination.env_id = context.env_id
395
+ AND destination.wallet_id = context.wallet_id AND destination.move_id = context.move_id
396
+ AND destination.request_digest_hex = context.request_digest_hex
397
+ AND destination.source_generation = context.source_generation AND destination.state = 'importing'
398
+ WHERE context.namespace = NEW.namespace AND context.org_id = NEW.org_id
399
+ AND context.project_id = NEW.project_id AND context.env_id = NEW.env_id
400
+ AND context.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id)
401
+ AND context.table_name = 'linked_device_session_transcripts' AND context.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id, NEW.transcript_kind)))
402
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
403
+
404
+ CREATE TRIGGER linked_device_session_transcripts_relocation_update
405
+ BEFORE UPDATE ON linked_device_session_transcripts
406
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
407
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
408
+ AND fence.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id)))
409
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
410
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
411
+ AND destination.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND destination.state != 'activated'))
412
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
413
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
414
+ AND receipt.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND receipt.table_name = 'linked_device_session_transcripts' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id, OLD.transcript_kind)))
415
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
416
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
417
+ AND fence.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id)))
418
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
419
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
420
+ AND destination.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id) AND destination.state != 'activated'))
421
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = NEW.namespace AND receipt.org_id = NEW.org_id
422
+ AND receipt.project_id = NEW.project_id AND receipt.env_id = NEW.env_id
423
+ AND receipt.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id) AND receipt.table_name = 'linked_device_session_transcripts' AND receipt.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id, NEW.transcript_kind)))
424
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
425
+
426
+ CREATE TRIGGER linked_device_session_transcripts_relocation_delete
427
+ BEFORE DELETE ON linked_device_session_transcripts
428
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
429
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
430
+ AND fence.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id)) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
431
+ JOIN wallet_relocation_authorization_fences AS fence
432
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
433
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
434
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
435
+ AND cleanup.request_digest_hex = fence.request_digest_hex
436
+ AND cleanup.source_generation = fence.source_generation
437
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
438
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
439
+ AND cleanup.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND cleanup.state = 'cleaning'))
440
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
441
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
442
+ AND destination.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND destination.state != 'activated'))
443
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
444
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
445
+ AND receipt.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND receipt.table_name = 'linked_device_session_transcripts' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id, OLD.transcript_kind)) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
446
+ JOIN wallet_relocation_authorization_fences AS fence
447
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
448
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
449
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
450
+ AND cleanup.request_digest_hex = fence.request_digest_hex
451
+ AND cleanup.source_generation = fence.source_generation
452
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
453
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
454
+ AND cleanup.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND cleanup.state = 'cleaning'))
455
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
456
+
457
+ CREATE TRIGGER linked_device_ed25519_export_root_transfers_relocation_insert
458
+ BEFORE INSERT ON linked_device_ed25519_export_root_transfers
459
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
460
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
461
+ AND fence.wallet_id = NEW.wallet_id))
462
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
463
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
464
+ AND destination.wallet_id = NEW.wallet_id AND destination.state != 'activated') AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_context AS context
465
+ JOIN wallet_relocation_authorization_imports AS destination
466
+ ON destination.namespace = context.namespace AND destination.org_id = context.org_id
467
+ AND destination.project_id = context.project_id AND destination.env_id = context.env_id
468
+ AND destination.wallet_id = context.wallet_id AND destination.move_id = context.move_id
469
+ AND destination.request_digest_hex = context.request_digest_hex
470
+ AND destination.source_generation = context.source_generation AND destination.state = 'importing'
471
+ WHERE context.namespace = NEW.namespace AND context.org_id = NEW.org_id
472
+ AND context.project_id = NEW.project_id AND context.env_id = NEW.env_id
473
+ AND context.wallet_id = NEW.wallet_id
474
+ AND context.table_name = 'linked_device_ed25519_export_root_transfers' AND context.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id)))
475
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
476
+
477
+ CREATE TRIGGER linked_device_ed25519_export_root_transfers_relocation_update
478
+ BEFORE UPDATE ON linked_device_ed25519_export_root_transfers
479
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
480
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
481
+ AND fence.wallet_id = OLD.wallet_id))
482
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
483
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
484
+ AND destination.wallet_id = OLD.wallet_id AND destination.state != 'activated'))
485
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
486
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
487
+ AND receipt.wallet_id = OLD.wallet_id AND receipt.table_name = 'linked_device_ed25519_export_root_transfers' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id)))
488
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
489
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
490
+ AND fence.wallet_id = NEW.wallet_id))
491
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
492
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
493
+ AND destination.wallet_id = NEW.wallet_id AND destination.state != 'activated'))
494
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = NEW.namespace AND receipt.org_id = NEW.org_id
495
+ AND receipt.project_id = NEW.project_id AND receipt.env_id = NEW.env_id
496
+ AND receipt.wallet_id = NEW.wallet_id AND receipt.table_name = 'linked_device_ed25519_export_root_transfers' AND receipt.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id)))
497
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
498
+
499
+ CREATE TRIGGER linked_device_ed25519_export_root_transfers_relocation_delete
500
+ BEFORE DELETE ON linked_device_ed25519_export_root_transfers
501
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
502
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
503
+ AND fence.wallet_id = OLD.wallet_id) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
504
+ JOIN wallet_relocation_authorization_fences AS fence
505
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
506
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
507
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
508
+ AND cleanup.request_digest_hex = fence.request_digest_hex
509
+ AND cleanup.source_generation = fence.source_generation
510
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
511
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
512
+ AND cleanup.wallet_id = OLD.wallet_id AND cleanup.state = 'cleaning'))
513
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
514
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
515
+ AND destination.wallet_id = OLD.wallet_id AND destination.state != 'activated'))
516
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
517
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
518
+ AND receipt.wallet_id = OLD.wallet_id AND receipt.table_name = 'linked_device_ed25519_export_root_transfers' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id)) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
519
+ JOIN wallet_relocation_authorization_fences AS fence
520
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
521
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
522
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
523
+ AND cleanup.request_digest_hex = fence.request_digest_hex
524
+ AND cleanup.source_generation = fence.source_generation
525
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
526
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
527
+ AND cleanup.wallet_id = OLD.wallet_id AND cleanup.state = 'cleaning'))
528
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
529
+
530
+ CREATE TRIGGER linked_device_email_otp_grants_relocation_insert
531
+ BEFORE INSERT ON linked_device_email_otp_grants
532
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
533
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
534
+ AND fence.wallet_id = NEW.wallet_id))
535
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
536
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
537
+ AND destination.wallet_id = NEW.wallet_id AND destination.state != 'activated') AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_context AS context
538
+ JOIN wallet_relocation_authorization_imports AS destination
539
+ ON destination.namespace = context.namespace AND destination.org_id = context.org_id
540
+ AND destination.project_id = context.project_id AND destination.env_id = context.env_id
541
+ AND destination.wallet_id = context.wallet_id AND destination.move_id = context.move_id
542
+ AND destination.request_digest_hex = context.request_digest_hex
543
+ AND destination.source_generation = context.source_generation AND destination.state = 'importing'
544
+ WHERE context.namespace = NEW.namespace AND context.org_id = NEW.org_id
545
+ AND context.project_id = NEW.project_id AND context.env_id = NEW.env_id
546
+ AND context.wallet_id = NEW.wallet_id
547
+ AND context.table_name = 'linked_device_email_otp_grants' AND context.record_key = json_array(NEW.env_id, NEW.grant_id, NEW.namespace, NEW.org_id, NEW.project_id)))
548
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
549
+
550
+ CREATE TRIGGER linked_device_email_otp_grants_relocation_update
551
+ BEFORE UPDATE ON linked_device_email_otp_grants
552
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
553
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
554
+ AND fence.wallet_id = OLD.wallet_id))
555
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
556
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
557
+ AND destination.wallet_id = OLD.wallet_id AND destination.state != 'activated'))
558
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
559
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
560
+ AND receipt.wallet_id = OLD.wallet_id AND receipt.table_name = 'linked_device_email_otp_grants' AND receipt.record_key = json_array(OLD.env_id, OLD.grant_id, OLD.namespace, OLD.org_id, OLD.project_id)))
561
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
562
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
563
+ AND fence.wallet_id = NEW.wallet_id))
564
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
565
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
566
+ AND destination.wallet_id = NEW.wallet_id AND destination.state != 'activated'))
567
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = NEW.namespace AND receipt.org_id = NEW.org_id
568
+ AND receipt.project_id = NEW.project_id AND receipt.env_id = NEW.env_id
569
+ AND receipt.wallet_id = NEW.wallet_id AND receipt.table_name = 'linked_device_email_otp_grants' AND receipt.record_key = json_array(NEW.env_id, NEW.grant_id, NEW.namespace, NEW.org_id, NEW.project_id)))
570
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
571
+
572
+ CREATE TRIGGER linked_device_email_otp_grants_relocation_delete
573
+ BEFORE DELETE ON linked_device_email_otp_grants
574
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
575
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
576
+ AND fence.wallet_id = OLD.wallet_id) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
577
+ JOIN wallet_relocation_authorization_fences AS fence
578
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
579
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
580
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
581
+ AND cleanup.request_digest_hex = fence.request_digest_hex
582
+ AND cleanup.source_generation = fence.source_generation
583
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
584
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
585
+ AND cleanup.wallet_id = OLD.wallet_id AND cleanup.state = 'cleaning'))
586
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
587
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
588
+ AND destination.wallet_id = OLD.wallet_id AND destination.state != 'activated'))
589
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
590
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
591
+ AND receipt.wallet_id = OLD.wallet_id AND receipt.table_name = 'linked_device_email_otp_grants' AND receipt.record_key = json_array(OLD.env_id, OLD.grant_id, OLD.namespace, OLD.org_id, OLD.project_id)) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
592
+ JOIN wallet_relocation_authorization_fences AS fence
593
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
594
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
595
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
596
+ AND cleanup.request_digest_hex = fence.request_digest_hex
597
+ AND cleanup.source_generation = fence.source_generation
598
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
599
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
600
+ AND cleanup.wallet_id = OLD.wallet_id AND cleanup.state = 'cleaning'))
601
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
602
+
603
+ CREATE TRIGGER linked_device_request_proof_nonces_relocation_insert
604
+ BEFORE INSERT ON linked_device_request_proof_nonces
605
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
606
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
607
+ AND fence.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id)))
608
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
609
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
610
+ AND destination.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id) AND destination.state != 'activated') AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_context AS context
611
+ JOIN wallet_relocation_authorization_imports AS destination
612
+ ON destination.namespace = context.namespace AND destination.org_id = context.org_id
613
+ AND destination.project_id = context.project_id AND destination.env_id = context.env_id
614
+ AND destination.wallet_id = context.wallet_id AND destination.move_id = context.move_id
615
+ AND destination.request_digest_hex = context.request_digest_hex
616
+ AND destination.source_generation = context.source_generation AND destination.state = 'importing'
617
+ WHERE context.namespace = NEW.namespace AND context.org_id = NEW.org_id
618
+ AND context.project_id = NEW.project_id AND context.env_id = NEW.env_id
619
+ AND context.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id)
620
+ AND context.table_name = 'linked_device_request_proof_nonces' AND context.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id, NEW.request_nonce_b64u)))
621
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
622
+
623
+ CREATE TRIGGER linked_device_request_proof_nonces_relocation_update
624
+ BEFORE UPDATE ON linked_device_request_proof_nonces
625
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
626
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
627
+ AND fence.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id)))
628
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
629
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
630
+ AND destination.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND destination.state != 'activated'))
631
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
632
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
633
+ AND receipt.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND receipt.table_name = 'linked_device_request_proof_nonces' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id, OLD.request_nonce_b64u)))
634
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
635
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
636
+ AND fence.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id)))
637
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
638
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
639
+ AND destination.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id) AND destination.state != 'activated'))
640
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = NEW.namespace AND receipt.org_id = NEW.org_id
641
+ AND receipt.project_id = NEW.project_id AND receipt.env_id = NEW.env_id
642
+ AND receipt.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id) AND receipt.table_name = 'linked_device_request_proof_nonces' AND receipt.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id, NEW.request_nonce_b64u)))
643
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
644
+
645
+ CREATE TRIGGER linked_device_request_proof_nonces_relocation_delete
646
+ BEFORE DELETE ON linked_device_request_proof_nonces
647
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
648
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
649
+ AND fence.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id)) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
650
+ JOIN wallet_relocation_authorization_fences AS fence
651
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
652
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
653
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
654
+ AND cleanup.request_digest_hex = fence.request_digest_hex
655
+ AND cleanup.source_generation = fence.source_generation
656
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
657
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
658
+ AND cleanup.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND cleanup.state = 'cleaning'))
659
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
660
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
661
+ AND destination.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND destination.state != 'activated'))
662
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
663
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
664
+ AND receipt.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND receipt.table_name = 'linked_device_request_proof_nonces' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id, OLD.request_nonce_b64u)) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
665
+ JOIN wallet_relocation_authorization_fences AS fence
666
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
667
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
668
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
669
+ AND cleanup.request_digest_hex = fence.request_digest_hex
670
+ AND cleanup.source_generation = fence.source_generation
671
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
672
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
673
+ AND cleanup.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND cleanup.state = 'cleaning'))
674
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
675
+
676
+ CREATE TRIGGER linked_device_bootstrap_imports_relocation_insert
677
+ BEFORE INSERT ON linked_device_bootstrap_imports
678
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
679
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
680
+ AND fence.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id)))
681
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
682
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
683
+ AND destination.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id) AND destination.state != 'activated') AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_context AS context
684
+ JOIN wallet_relocation_authorization_imports AS destination
685
+ ON destination.namespace = context.namespace AND destination.org_id = context.org_id
686
+ AND destination.project_id = context.project_id AND destination.env_id = context.env_id
687
+ AND destination.wallet_id = context.wallet_id AND destination.move_id = context.move_id
688
+ AND destination.request_digest_hex = context.request_digest_hex
689
+ AND destination.source_generation = context.source_generation AND destination.state = 'importing'
690
+ WHERE context.namespace = NEW.namespace AND context.org_id = NEW.org_id
691
+ AND context.project_id = NEW.project_id AND context.env_id = NEW.env_id
692
+ AND context.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id)
693
+ AND context.table_name = 'linked_device_bootstrap_imports' AND context.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id)))
694
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
695
+
696
+ CREATE TRIGGER linked_device_bootstrap_imports_relocation_update
697
+ BEFORE UPDATE ON linked_device_bootstrap_imports
698
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
699
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
700
+ AND fence.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id)))
701
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
702
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
703
+ AND destination.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND destination.state != 'activated'))
704
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
705
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
706
+ AND receipt.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND receipt.table_name = 'linked_device_bootstrap_imports' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id)))
707
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
708
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
709
+ AND fence.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id)))
710
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
711
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
712
+ AND destination.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id) AND destination.state != 'activated'))
713
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = NEW.namespace AND receipt.org_id = NEW.org_id
714
+ AND receipt.project_id = NEW.project_id AND receipt.env_id = NEW.env_id
715
+ AND receipt.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = NEW.namespace AND parent.org_id = NEW.org_id AND parent.project_id = NEW.project_id AND parent.env_id = NEW.env_id AND parent.link_session_id = NEW.link_session_id) AND receipt.table_name = 'linked_device_bootstrap_imports' AND receipt.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id)))
716
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
717
+
718
+ CREATE TRIGGER linked_device_bootstrap_imports_relocation_delete
719
+ BEFORE DELETE ON linked_device_bootstrap_imports
720
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
721
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
722
+ AND fence.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id)) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
723
+ JOIN wallet_relocation_authorization_fences AS fence
724
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
725
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
726
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
727
+ AND cleanup.request_digest_hex = fence.request_digest_hex
728
+ AND cleanup.source_generation = fence.source_generation
729
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
730
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
731
+ AND cleanup.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND cleanup.state = 'cleaning'))
732
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
733
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
734
+ AND destination.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND destination.state != 'activated'))
735
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
736
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
737
+ AND receipt.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND receipt.table_name = 'linked_device_bootstrap_imports' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id)) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
738
+ JOIN wallet_relocation_authorization_fences AS fence
739
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
740
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
741
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
742
+ AND cleanup.request_digest_hex = fence.request_digest_hex
743
+ AND cleanup.source_generation = fence.source_generation
744
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
745
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
746
+ AND cleanup.wallet_id = (SELECT json_extract(parent.record_json, '$.claimTranscript.value.walletId') FROM linked_device_sessions AS parent WHERE parent.namespace = OLD.namespace AND parent.org_id = OLD.org_id AND parent.project_id = OLD.project_id AND parent.env_id = OLD.env_id AND parent.link_session_id = OLD.link_session_id) AND cleanup.state = 'cleaning'))
747
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
748
+
749
+ CREATE TRIGGER linked_device_wallet_session_credential_deliveries_v1_relocation_insert
750
+ BEFORE INSERT ON linked_device_wallet_session_credential_deliveries_v1
751
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
752
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
753
+ AND fence.wallet_id = NEW.wallet_id))
754
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
755
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
756
+ AND destination.wallet_id = NEW.wallet_id AND destination.state != 'activated') AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_context AS context
757
+ JOIN wallet_relocation_authorization_imports AS destination
758
+ ON destination.namespace = context.namespace AND destination.org_id = context.org_id
759
+ AND destination.project_id = context.project_id AND destination.env_id = context.env_id
760
+ AND destination.wallet_id = context.wallet_id AND destination.move_id = context.move_id
761
+ AND destination.request_digest_hex = context.request_digest_hex
762
+ AND destination.source_generation = context.source_generation AND destination.state = 'importing'
763
+ WHERE context.namespace = NEW.namespace AND context.org_id = NEW.org_id
764
+ AND context.project_id = NEW.project_id AND context.env_id = NEW.env_id
765
+ AND context.wallet_id = NEW.wallet_id
766
+ AND context.table_name = 'linked_device_wallet_session_credential_deliveries_v1' AND context.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id)))
767
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
768
+
769
+ CREATE TRIGGER linked_device_wallet_session_credential_deliveries_v1_relocation_update
770
+ BEFORE UPDATE ON linked_device_wallet_session_credential_deliveries_v1
771
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
772
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
773
+ AND fence.wallet_id = OLD.wallet_id))
774
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
775
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
776
+ AND destination.wallet_id = OLD.wallet_id AND destination.state != 'activated'))
777
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
778
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
779
+ AND receipt.wallet_id = OLD.wallet_id AND receipt.table_name = 'linked_device_wallet_session_credential_deliveries_v1' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id)))
780
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = NEW.namespace AND fence.org_id = NEW.org_id
781
+ AND fence.project_id = NEW.project_id AND fence.env_id = NEW.env_id
782
+ AND fence.wallet_id = NEW.wallet_id))
783
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = NEW.namespace AND destination.org_id = NEW.org_id
784
+ AND destination.project_id = NEW.project_id AND destination.env_id = NEW.env_id
785
+ AND destination.wallet_id = NEW.wallet_id AND destination.state != 'activated'))
786
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = NEW.namespace AND receipt.org_id = NEW.org_id
787
+ AND receipt.project_id = NEW.project_id AND receipt.env_id = NEW.env_id
788
+ AND receipt.wallet_id = NEW.wallet_id AND receipt.table_name = 'linked_device_wallet_session_credential_deliveries_v1' AND receipt.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id)))
789
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
790
+
791
+ CREATE TRIGGER linked_device_wallet_session_credential_deliveries_v1_relocation_delete
792
+ BEFORE DELETE ON linked_device_wallet_session_credential_deliveries_v1
793
+ WHEN (EXISTS (SELECT 1 FROM wallet_relocation_session_fences AS fence WHERE fence.namespace = OLD.namespace AND fence.org_id = OLD.org_id
794
+ AND fence.project_id = OLD.project_id AND fence.env_id = OLD.env_id
795
+ AND fence.wallet_id = OLD.wallet_id) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
796
+ JOIN wallet_relocation_authorization_fences AS fence
797
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
798
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
799
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
800
+ AND cleanup.request_digest_hex = fence.request_digest_hex
801
+ AND cleanup.source_generation = fence.source_generation
802
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
803
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
804
+ AND cleanup.wallet_id = OLD.wallet_id AND cleanup.state = 'cleaning'))
805
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_imports AS destination WHERE destination.namespace = OLD.namespace AND destination.org_id = OLD.org_id
806
+ AND destination.project_id = OLD.project_id AND destination.env_id = OLD.env_id
807
+ AND destination.wallet_id = OLD.wallet_id AND destination.state != 'activated'))
808
+ OR (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_receipts AS receipt WHERE receipt.namespace = OLD.namespace AND receipt.org_id = OLD.org_id
809
+ AND receipt.project_id = OLD.project_id AND receipt.env_id = OLD.env_id
810
+ AND receipt.wallet_id = OLD.wallet_id AND receipt.table_name = 'linked_device_wallet_session_credential_deliveries_v1' AND receipt.record_key = json_array(OLD.env_id, OLD.link_session_id, OLD.namespace, OLD.org_id, OLD.project_id)) AND NOT EXISTS (SELECT 1 FROM wallet_relocation_authorization_cleanups AS cleanup
811
+ JOIN wallet_relocation_authorization_fences AS fence
812
+ ON cleanup.namespace = fence.namespace AND cleanup.org_id = fence.org_id
813
+ AND cleanup.project_id = fence.project_id AND cleanup.env_id = fence.env_id
814
+ AND cleanup.wallet_id = fence.wallet_id AND cleanup.move_id = fence.move_id
815
+ AND cleanup.request_digest_hex = fence.request_digest_hex
816
+ AND cleanup.source_generation = fence.source_generation
817
+ WHERE cleanup.namespace = OLD.namespace AND cleanup.org_id = OLD.org_id
818
+ AND cleanup.project_id = OLD.project_id AND cleanup.env_id = OLD.env_id
819
+ AND cleanup.wallet_id = OLD.wallet_id AND cleanup.state = 'cleaning'))
820
+ BEGIN SELECT RAISE(ABORT, 'linked_device_relocation_fenced'); END;
821
+
822
+ DROP TRIGGER linked_device_wallet_session_credential_delivery_insert_lifecycle_guard;
823
+ CREATE TRIGGER linked_device_wallet_session_credential_delivery_insert_lifecycle_guard
824
+ BEFORE INSERT ON linked_device_wallet_session_credential_deliveries_v1
825
+ WHEN (NEW.lifecycle_kind != 'issued'
826
+ OR NEW.acknowledged_at_ms IS NOT NULL
827
+ OR NEW.acknowledgement_receipt_json IS NOT NULL
828
+ OR NEW.cleanup_state != 'pending'
829
+ OR NEW.cleanup_receipt_json IS NOT NULL
830
+ OR NEW.cleanup_completed_at_ms IS NOT NULL
831
+ OR NEW.acknowledgement_auth_binding_digest_b64u IS NOT NULL
832
+ OR NEW.acknowledgement_auth_package_set_digest_b64u IS NOT NULL
833
+ OR NEW.acknowledgement_auth_expires_at_ms IS NOT NULL) AND NOT (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_context AS context
834
+ JOIN wallet_relocation_authorization_imports AS destination
835
+ ON destination.namespace = context.namespace AND destination.org_id = context.org_id
836
+ AND destination.project_id = context.project_id AND destination.env_id = context.env_id
837
+ AND destination.wallet_id = context.wallet_id AND destination.move_id = context.move_id
838
+ AND destination.request_digest_hex = context.request_digest_hex
839
+ AND destination.source_generation = context.source_generation AND destination.state = 'importing'
840
+ WHERE context.namespace = NEW.namespace AND context.org_id = NEW.org_id
841
+ AND context.project_id = NEW.project_id AND context.env_id = NEW.env_id
842
+ AND context.wallet_id = NEW.wallet_id
843
+ AND context.table_name = 'linked_device_wallet_session_credential_deliveries_v1' AND context.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id)) AND EXISTS (SELECT 1 FROM wallet_session_authorizations_v2 AS session
844
+ WHERE session.namespace = NEW.namespace AND session.org_id = NEW.org_id
845
+ AND session.project_id = NEW.project_id AND session.env_id = NEW.env_id
846
+ AND session.wallet_id = NEW.wallet_id AND session.tenant_id = NEW.tenant_id
847
+ AND session.authorization_id = NEW.authorization_id AND session.retired_at_ms IS NOT NULL))
848
+ BEGIN
849
+ SELECT RAISE(ABORT, 'linked_device_wallet_session_credential_delivery_initial_state_rejected');
850
+ END;
851
+
852
+ DROP TRIGGER linked_device_wallet_session_credential_delivery_parent_guard;
853
+ CREATE TRIGGER linked_device_wallet_session_credential_delivery_parent_guard
854
+ BEFORE INSERT ON linked_device_wallet_session_credential_deliveries_v1
855
+ WHEN NOT EXISTS (
856
+ SELECT 1
857
+ FROM wallet_session_authorizations_v2 AS session
858
+ JOIN linked_device_authority_installations AS installation
859
+ ON installation.namespace = NEW.namespace
860
+ AND installation.org_id = NEW.org_id
861
+ AND installation.project_id = NEW.project_id
862
+ AND installation.env_id = NEW.env_id
863
+ AND installation.link_session_id = NEW.link_session_id
864
+ WHERE session.namespace = NEW.namespace
865
+ AND session.org_id = NEW.org_id
866
+ AND session.project_id = NEW.project_id
867
+ AND session.env_id = NEW.env_id
868
+ AND session.tenant_id = NEW.tenant_id
869
+ AND session.authorization_id = NEW.authorization_id
870
+ AND session.wallet_session_id = NEW.wallet_session_id
871
+ AND session.quota_id = NEW.quota_id
872
+ AND session.principal_id = NEW.principal_id
873
+ AND session.wallet_id = NEW.wallet_id
874
+ AND session.authority_id = NEW.authority_id
875
+ AND session.wallet_auth_method_id = NEW.wallet_auth_method_id
876
+ AND session.operation_credential_hash IS NOT NULL
877
+ AND session.retired_at_ms IS NULL
878
+ AND session.expires_at_ms >= NEW.expires_at_ms
879
+ AND installation.authority_id = NEW.authority_id
880
+ AND installation.wallet_id = NEW.wallet_id
881
+ AND installation.auth_method_id = NEW.wallet_auth_method_id
882
+ ) AND NOT (EXISTS (SELECT 1 FROM wallet_relocation_authorization_import_context AS context
883
+ JOIN wallet_relocation_authorization_imports AS destination
884
+ ON destination.namespace = context.namespace AND destination.org_id = context.org_id
885
+ AND destination.project_id = context.project_id AND destination.env_id = context.env_id
886
+ AND destination.wallet_id = context.wallet_id AND destination.move_id = context.move_id
887
+ AND destination.request_digest_hex = context.request_digest_hex
888
+ AND destination.source_generation = context.source_generation AND destination.state = 'importing'
889
+ WHERE context.namespace = NEW.namespace AND context.org_id = NEW.org_id
890
+ AND context.project_id = NEW.project_id AND context.env_id = NEW.env_id
891
+ AND context.wallet_id = NEW.wallet_id
892
+ AND context.table_name = 'linked_device_wallet_session_credential_deliveries_v1' AND context.record_key = json_array(NEW.env_id, NEW.link_session_id, NEW.namespace, NEW.org_id, NEW.project_id)) AND EXISTS (SELECT 1 FROM wallet_session_authorizations_v2 AS session
893
+ WHERE session.namespace = NEW.namespace AND session.org_id = NEW.org_id
894
+ AND session.project_id = NEW.project_id AND session.env_id = NEW.env_id
895
+ AND session.wallet_id = NEW.wallet_id AND session.tenant_id = NEW.tenant_id
896
+ AND session.authorization_id = NEW.authorization_id AND session.retired_at_ms IS NOT NULL))
897
+ BEGIN
898
+ SELECT RAISE(ABORT, 'linked_device_wallet_session_credential_delivery_parent_rejected');
899
+ END;