@odatano/core 2.0.0-rc.5 → 2.0.0-rc.51

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 (239) hide show
  1. package/@cds-models/CardanoAgentService/index.d.ts +99 -51
  2. package/@cds-models/CardanoAgentService/index.js +15 -0
  3. package/@cds-models/CardanoBackendService/index.d.ts +358 -0
  4. package/@cds-models/CardanoBackendService/index.js +41 -0
  5. package/@cds-models/CardanoIndexerService/index.d.ts +594 -11
  6. package/@cds-models/CardanoIndexerService/index.js +74 -0
  7. package/@cds-models/CardanoODataService/index.d.ts +417 -57
  8. package/@cds-models/CardanoODataService/index.js +42 -0
  9. package/@cds-models/CardanoSignService/index.d.ts +45 -19
  10. package/@cds-models/CardanoSignService/index.js +4 -0
  11. package/@cds-models/CardanoTransactionService/index.d.ts +70 -44
  12. package/@cds-models/CardanoTransactionService/index.js +5 -0
  13. package/@cds-models/CardanoWorkerService/index.d.ts +35 -22
  14. package/@cds-models/CardanoWorkerService/index.js +2 -0
  15. package/@cds-models/index.d.ts +114 -4
  16. package/@cds-models/index.js +20 -4
  17. package/@cds-models/odatano/cardano/index.d.ts +451 -32
  18. package/@cds-models/odatano/cardano/index.js +48 -0
  19. package/README.md +103 -167
  20. package/db/schema.cds +2455 -1705
  21. package/db/types.cds +456 -295
  22. package/package.json +41 -53
  23. package/scripts/deploy-schema.mjs +113 -0
  24. package/scripts/migrate-schema.mjs +528 -0
  25. package/scripts/migrate-slot-leader.mjs +96 -0
  26. package/src/index.d.ts +20 -21
  27. package/src/index.js +45 -31
  28. package/src/plugin.js +17 -35
  29. package/srv/blockchain/asset-decimals.d.ts +7 -0
  30. package/srv/blockchain/asset-decimals.js +91 -0
  31. package/srv/blockchain/backends/blockfrost-backend.d.ts +25 -137
  32. package/srv/blockchain/backends/blockfrost-backend.js +125 -215
  33. package/srv/blockchain/backends/call-signal.d.ts +7 -0
  34. package/srv/blockchain/backends/call-signal.js +22 -0
  35. package/srv/blockchain/backends/cardano-backend.d.ts +100 -189
  36. package/srv/blockchain/backends/cardano-backend.js +29 -5
  37. package/srv/blockchain/backends/koios-backend.d.ts +108 -170
  38. package/srv/blockchain/backends/koios-backend.js +488 -482
  39. package/srv/blockchain/backends/odatano-backend.d.ts +55 -0
  40. package/srv/blockchain/backends/odatano-backend.js +211 -0
  41. package/srv/blockchain/backends/ogmios-backend.d.ts +122 -190
  42. package/srv/blockchain/backends/ogmios-backend.js +683 -327
  43. package/srv/blockchain/backends/ogmios-frame-guard.d.ts +14 -0
  44. package/srv/blockchain/backends/ogmios-frame-guard.js +89 -0
  45. package/srv/blockchain/cardano-client.d.ts +71 -241
  46. package/srv/blockchain/cardano-client.js +354 -322
  47. package/srv/blockchain/cardano-indexer.d.ts +295 -283
  48. package/srv/blockchain/cardano-indexer.js +1690 -502
  49. package/srv/blockchain/cardano-tx-builder.d.ts +25 -89
  50. package/srv/blockchain/cardano-tx-builder.js +164 -140
  51. package/srv/blockchain/circuit-breaker.d.ts +2 -13
  52. package/srv/blockchain/circuit-breaker.js +11 -15
  53. package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
  54. package/srv/blockchain/crawler/account-snapshots.js +173 -0
  55. package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +17 -0
  56. package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
  57. package/srv/blockchain/crawler/asset-registry-backfill.d.ts +46 -0
  58. package/srv/blockchain/crawler/asset-registry-backfill.js +157 -0
  59. package/srv/blockchain/crawler/asset-slice-backfill.d.ts +35 -0
  60. package/srv/blockchain/crawler/asset-slice-backfill.js +149 -0
  61. package/srv/blockchain/crawler/certificate-backfill.d.ts +56 -0
  62. package/srv/blockchain/crawler/certificate-backfill.js +174 -0
  63. package/srv/blockchain/crawler/crawler.d.ts +125 -81
  64. package/srv/blockchain/crawler/crawler.js +738 -167
  65. package/srv/blockchain/crawler/credential-backfill.d.ts +30 -0
  66. package/srv/blockchain/crawler/credential-backfill.js +101 -0
  67. package/srv/blockchain/crawler/hooks.d.ts +2 -17
  68. package/srv/blockchain/crawler/index.d.ts +1 -8
  69. package/srv/blockchain/crawler/index.js +31 -17
  70. package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
  71. package/srv/blockchain/crawler/input-asset-copies.js +161 -0
  72. package/srv/blockchain/crawler/key-pages.d.ts +12 -0
  73. package/srv/blockchain/crawler/key-pages.js +48 -0
  74. package/srv/blockchain/crawler/metadata-position-backfill.d.ts +22 -0
  75. package/srv/blockchain/crawler/metadata-position-backfill.js +59 -0
  76. package/srv/blockchain/crawler/output-datum-backfill.d.ts +41 -0
  77. package/srv/blockchain/crawler/output-datum-backfill.js +100 -0
  78. package/srv/blockchain/crawler/sync-state.d.ts +31 -47
  79. package/srv/blockchain/crawler/sync-state.js +135 -128
  80. package/srv/blockchain/crawler/transaction-backfill.d.ts +46 -0
  81. package/srv/blockchain/crawler/transaction-backfill.js +271 -0
  82. package/srv/blockchain/crawler/utxo-set-import.d.ts +66 -0
  83. package/srv/blockchain/crawler/utxo-set-import.js +399 -0
  84. package/srv/blockchain/crawler/window-plan.d.ts +31 -0
  85. package/srv/blockchain/crawler/window-plan.js +59 -0
  86. package/srv/blockchain/ledger-state.d.ts +62 -0
  87. package/srv/blockchain/ledger-state.js +521 -0
  88. package/srv/blockchain/pending-spends.d.ts +16 -0
  89. package/srv/blockchain/pending-spends.js +81 -0
  90. package/srv/blockchain/pool-metadata.d.ts +15 -0
  91. package/srv/blockchain/pool-metadata.js +132 -0
  92. package/srv/blockchain/request-coalescer.d.ts +2 -16
  93. package/srv/blockchain/request-coalescer.js +2 -16
  94. package/srv/blockchain/signing/cose-verifier.d.ts +3 -17
  95. package/srv/blockchain/signing/cose-verifier.js +146 -70
  96. package/srv/blockchain/signing/external-signer.d.ts +15 -115
  97. package/srv/blockchain/signing/external-signer.js +22 -131
  98. package/srv/blockchain/signing/failed-recheck.d.ts +17 -0
  99. package/srv/blockchain/signing/failed-recheck.js +135 -0
  100. package/srv/blockchain/signing/hsm-signer.d.ts +10 -54
  101. package/srv/blockchain/signing/hsm-signer.js +28 -79
  102. package/srv/blockchain/signing/landing-proof.d.ts +60 -0
  103. package/srv/blockchain/signing/landing-proof.js +224 -0
  104. package/srv/blockchain/signing/signature-verifier.d.ts +9 -47
  105. package/srv/blockchain/signing/signature-verifier.js +71 -87
  106. package/srv/blockchain/signing/submission-finalizer.d.ts +37 -45
  107. package/srv/blockchain/signing/submission-finalizer.js +280 -86
  108. package/srv/blockchain/stored-chain.d.ts +19 -0
  109. package/srv/blockchain/stored-chain.js +258 -0
  110. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +31 -229
  111. package/srv/blockchain/transaction-building/buildooor-tx.js +663 -421
  112. package/srv/blockchain/transaction-building/cardano-tx.d.ts +9 -37
  113. package/srv/blockchain/transaction-presence.d.ts +12 -0
  114. package/srv/blockchain/transaction-presence.js +29 -0
  115. package/srv/blockchain/transaction-rows.d.ts +12 -0
  116. package/srv/blockchain/transaction-rows.js +44 -0
  117. package/srv/blockchain/wallet-worker/build-request.d.ts +8 -23
  118. package/srv/blockchain/wallet-worker/build-request.js +40 -353
  119. package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +27 -47
  120. package/srv/blockchain/wallet-worker/confirmation-tracker.js +158 -61
  121. package/srv/blockchain/wallet-worker/index.d.ts +1 -1
  122. package/srv/blockchain/wallet-worker/index.js +3 -11
  123. package/srv/blockchain/wallet-worker/invalidation.d.ts +35 -0
  124. package/srv/blockchain/wallet-worker/invalidation.js +128 -0
  125. package/srv/blockchain/wallet-worker/job-store.d.ts +58 -150
  126. package/srv/blockchain/wallet-worker/job-store.js +200 -273
  127. package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -26
  128. package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -28
  129. package/srv/blockchain/wallet-worker/signers.d.ts +5 -24
  130. package/srv/blockchain/wallet-worker/signers.js +4 -12
  131. package/srv/blockchain/wallet-worker/wallet-worker.d.ts +29 -82
  132. package/srv/blockchain/wallet-worker/wallet-worker.js +334 -198
  133. package/srv/cardano-agent-service.cds +122 -84
  134. package/srv/cardano-agent-service.js +12 -9
  135. package/srv/cardano-backend-service.cds +81 -0
  136. package/srv/cardano-backend-service.d.ts +2 -0
  137. package/srv/cardano-backend-service.js +259 -0
  138. package/srv/cardano-indexer-service.cds +393 -18
  139. package/srv/cardano-indexer-service.d.ts +5 -1
  140. package/srv/cardano-indexer-service.js +477 -16
  141. package/srv/cardano-service.cds +426 -269
  142. package/srv/cardano-service.js +640 -217
  143. package/srv/cardano-sign-service.cds +211 -180
  144. package/srv/cardano-sign-service.js +210 -287
  145. package/srv/cardano-tx-service.cds +462 -370
  146. package/srv/cardano-tx-service.js +283 -800
  147. package/srv/cardano-ui.cds +16 -16
  148. package/srv/cardano-worker-service.cds +141 -125
  149. package/srv/cardano-worker-service.js +104 -61
  150. package/srv/cbor/cip68.d.ts +13 -0
  151. package/srv/cbor/cip68.js +56 -0
  152. package/srv/cbor/index.d.ts +3 -1
  153. package/srv/cbor/index.js +9 -1
  154. package/srv/cbor/parse.d.ts +30 -18
  155. package/srv/cbor/parse.js +44 -9
  156. package/srv/cbor/plutus-data-json.d.ts +20 -0
  157. package/srv/cbor/plutus-data-json.js +32 -0
  158. package/srv/config.d.ts +117 -0
  159. package/srv/config.js +419 -0
  160. package/srv/server.d.ts +15 -110
  161. package/srv/server.js +83 -405
  162. package/srv/utils/agent-access.d.ts +11 -0
  163. package/srv/utils/agent-access.js +86 -0
  164. package/srv/utils/agent-grants-config.d.ts +0 -46
  165. package/srv/utils/agent-grants-config.js +17 -85
  166. package/srv/utils/agent-grants.d.ts +106 -122
  167. package/srv/utils/agent-grants.js +538 -237
  168. package/srv/utils/agent-token-auth.d.ts +4 -99
  169. package/srv/utils/agent-token-auth.js +62 -186
  170. package/srv/utils/backend-request-handler.d.ts +3 -17
  171. package/srv/utils/backend-request-handler.js +3 -18
  172. package/srv/utils/build-request.d.ts +52 -0
  173. package/srv/utils/build-request.js +487 -0
  174. package/srv/utils/collections.d.ts +4 -10
  175. package/srv/utils/collections.js +14 -10
  176. package/srv/utils/const.d.ts +32 -75
  177. package/srv/utils/const.js +40 -80
  178. package/srv/utils/crypto.d.ts +3 -12
  179. package/srv/utils/crypto.js +11 -25
  180. package/srv/utils/db-indexes.d.ts +31 -0
  181. package/srv/utils/db-indexes.js +185 -0
  182. package/srv/utils/db-kind.d.ts +23 -0
  183. package/srv/utils/db-kind.js +42 -0
  184. package/srv/utils/db-sanitize.d.ts +20 -0
  185. package/srv/utils/db-sanitize.js +80 -0
  186. package/srv/utils/deep-json.d.ts +6 -0
  187. package/srv/utils/deep-json.js +240 -0
  188. package/srv/utils/detached-run.d.ts +41 -0
  189. package/srv/utils/detached-run.js +101 -0
  190. package/srv/utils/epoch-slots.d.ts +14 -0
  191. package/srv/utils/epoch-slots.js +45 -0
  192. package/srv/utils/error-codes.d.ts +26 -75
  193. package/srv/utils/error-codes.js +27 -72
  194. package/srv/utils/errors.d.ts +55 -187
  195. package/srv/utils/errors.js +161 -235
  196. package/srv/utils/lease.d.ts +20 -0
  197. package/srv/utils/lease.js +62 -0
  198. package/srv/utils/liveness.d.ts +12 -0
  199. package/srv/utils/liveness.js +35 -0
  200. package/srv/utils/mappers.d.ts +111 -223
  201. package/srv/utils/mappers.js +432 -371
  202. package/srv/utils/navigation.d.ts +17 -0
  203. package/srv/utils/navigation.js +52 -0
  204. package/srv/utils/network-context.d.ts +0 -1
  205. package/srv/utils/network-context.js +9 -15
  206. package/srv/utils/paging.d.ts +31 -0
  207. package/srv/utils/paging.js +43 -0
  208. package/srv/utils/pg-inline-json.d.ts +8 -0
  209. package/srv/utils/pg-inline-json.js +58 -0
  210. package/srv/utils/pg-order-nulls.d.ts +14 -0
  211. package/srv/utils/pg-order-nulls.js +54 -0
  212. package/srv/utils/plutus-placeholders.d.ts +16 -22
  213. package/srv/utils/plutus-placeholders.js +62 -33
  214. package/srv/utils/rate-limiter.d.ts +2 -21
  215. package/srv/utils/rate-limiter.js +5 -17
  216. package/srv/utils/readiness.d.ts +12 -0
  217. package/srv/utils/readiness.js +29 -0
  218. package/srv/utils/reference-script.d.ts +19 -0
  219. package/srv/utils/reference-script.js +84 -0
  220. package/srv/utils/resolution.d.ts +13 -0
  221. package/srv/utils/resolution.js +47 -0
  222. package/srv/utils/result-numbers.d.ts +15 -0
  223. package/srv/utils/result-numbers.js +61 -0
  224. package/srv/utils/row-values.d.ts +7 -0
  225. package/srv/utils/row-values.js +27 -0
  226. package/srv/utils/service-events.d.ts +0 -24
  227. package/srv/utils/service-events.js +3 -25
  228. package/srv/utils/signing-helper.d.ts +3 -20
  229. package/srv/utils/signing-helper.js +35 -64
  230. package/srv/utils/tx-build-helper.d.ts +25 -105
  231. package/srv/utils/tx-build-helper.js +108 -156
  232. package/srv/utils/tx-request-parsers.d.ts +82 -33
  233. package/srv/utils/tx-request-parsers.js +401 -49
  234. package/srv/utils/tx-utils.d.ts +3 -27
  235. package/srv/utils/tx-utils.js +32 -50
  236. package/srv/utils/types.d.ts +294 -232
  237. package/srv/utils/types.js +2 -22
  238. package/srv/utils/validators.d.ts +22 -92
  239. package/srv/utils/validators.js +60 -170
@@ -1,24 +1,3 @@
1
- /**
2
- * Keeps a per-wallet lease alive for as long as a job execution runs.
3
- *
4
- * Building and signing a transaction can easily outlast WORKER_LEASE_TTL_MS (a
5
- * multi-backend build plus an HSM round-trip); a single renewal before the build
6
- * is therefore not enough. Without a heartbeat the lease silently expires
7
- * mid-execution, another instance adopts the wallet, fails this executor's row as
8
- * orphaned and starts the next job — two executors on one wallet, which is exactly
9
- * what the per-wallet lease exists to prevent.
10
- *
11
- * Renewals run at a third of the TTL, so two consecutive misses (slow DB, event
12
- * loop hiccup) are tolerated before the lease can lapse. A process that is truly
13
- * wedged stops beating and correctly loses the wallet.
14
- *
15
- * Two failure semantics, on purpose:
16
- * - the periodic `beat` is lenient: a DB error is logged and retried next tick,
17
- * only a definitive "not yours" marks the lease lost.
18
- * - `fence()` is strict: it is called right before an irreversible step, where
19
- * "cannot prove ownership" must be treated as "not ours". Aborting there is
20
- * free (nothing has been sent yet); guessing wrong is a double spend.
21
- */
22
1
  export declare const LEASE_HEARTBEAT_INTERVAL_MS: number;
23
2
  export declare class LeaseHeartbeat {
24
3
  private readonly renew;
@@ -26,14 +5,11 @@ export declare class LeaseHeartbeat {
26
5
  private readonly intervalMs;
27
6
  private timer;
28
7
  private lost;
29
- /**
30
- * @param renew renews the lease and reports whether it is (still) ours
31
- * @param label what the lease covers, for log messages
32
- */
8
+ /** renew reports whether the lease is still ours. label names the lease in logs. */
33
9
  constructor(renew: () => Promise<boolean>, label: string, intervalMs?: number);
34
10
  start(): void;
35
11
  stop(): void;
36
- /** True once a renewal proved the lease is no longer ours — abort the execution. */
12
+ /** True once a renewal proved the lease is not ours. The execution must abort. */
37
13
  isLost(): boolean;
38
14
  /** Renew now; false means "do not touch this wallet any further". */
39
15
  fence(): Promise<boolean>;
@@ -7,27 +7,8 @@ exports.LeaseHeartbeat = exports.LEASE_HEARTBEAT_INTERVAL_MS = void 0;
7
7
  const cds_1 = __importDefault(require("@sap/cds"));
8
8
  const job_store_1 = require("./job-store");
9
9
  const logger = cds_1.default.log('CardanoWalletWorker');
10
- /**
11
- * Keeps a per-wallet lease alive for as long as a job execution runs.
12
- *
13
- * Building and signing a transaction can easily outlast WORKER_LEASE_TTL_MS (a
14
- * multi-backend build plus an HSM round-trip); a single renewal before the build
15
- * is therefore not enough. Without a heartbeat the lease silently expires
16
- * mid-execution, another instance adopts the wallet, fails this executor's row as
17
- * orphaned and starts the next job — two executors on one wallet, which is exactly
18
- * what the per-wallet lease exists to prevent.
19
- *
20
- * Renewals run at a third of the TTL, so two consecutive misses (slow DB, event
21
- * loop hiccup) are tolerated before the lease can lapse. A process that is truly
22
- * wedged stops beating and correctly loses the wallet.
23
- *
24
- * Two failure semantics, on purpose:
25
- * - the periodic `beat` is lenient: a DB error is logged and retried next tick,
26
- * only a definitive "not yours" marks the lease lost.
27
- * - `fence()` is strict: it is called right before an irreversible step, where
28
- * "cannot prove ownership" must be treated as "not ours". Aborting there is
29
- * free (nothing has been sent yet); guessing wrong is a double spend.
30
- */
10
+ // Keeps a wallet lease alive while a job runs. Renewing at a third of the TTL tolerates two misses.
11
+ // beat retries on DB errors. fence treats an unprovable lease as lost, before irreversible steps.
31
12
  exports.LEASE_HEARTBEAT_INTERVAL_MS = Math.floor(job_store_1.WORKER_LEASE_TTL_MS / 3);
32
13
  class LeaseHeartbeat {
33
14
  renew;
@@ -35,10 +16,7 @@ class LeaseHeartbeat {
35
16
  intervalMs;
36
17
  timer = null;
37
18
  lost = false;
38
- /**
39
- * @param renew renews the lease and reports whether it is (still) ours
40
- * @param label what the lease covers, for log messages
41
- */
19
+ /** renew reports whether the lease is still ours. label names the lease in logs. */
42
20
  constructor(renew, label, intervalMs = exports.LEASE_HEARTBEAT_INTERVAL_MS) {
43
21
  this.renew = renew;
44
22
  this.label = label;
@@ -56,7 +34,7 @@ class LeaseHeartbeat {
56
34
  this.timer = null;
57
35
  }
58
36
  }
59
- /** True once a renewal proved the lease is no longer ours — abort the execution. */
37
+ /** True once a renewal proved the lease is not ours. The execution must abort. */
60
38
  isLost() {
61
39
  return this.lost;
62
40
  }
@@ -71,7 +49,7 @@ class LeaseHeartbeat {
71
49
  return held;
72
50
  }
73
51
  catch (err) {
74
- logger.warn(`Lease fence for ${this.label} could not be verified — treating the lease as lost:`, err);
52
+ logger.warn(`Lease fence for ${this.label} could not be verified, treating the lease as lost:`, err);
75
53
  this.lost = true;
76
54
  return false;
77
55
  }
@@ -92,7 +70,7 @@ class LeaseHeartbeat {
92
70
  return;
93
71
  this.lost = true;
94
72
  this.stop();
95
- logger.warn(`Lease for ${this.label} was taken over by another instance — this executor must stand down`);
73
+ logger.warn(`Lease for ${this.label} was taken over by another instance, this executor must stand down`);
96
74
  }
97
75
  }
98
76
  exports.LeaseHeartbeat = LeaseHeartbeat;
@@ -1,17 +1,4 @@
1
1
  import type { WorkerSignerTypeValue } from './job-store';
2
- /**
3
- * Wallet-worker signers (v2.0).
4
- *
5
- * `WorkerSigner` is the signer-agnostic surface the worker engine executes against:
6
- * - `hsm` (production): thin wrapper around the already-initialized `HsmSigner`
7
- * (PKCS#11 — keys never leave the module).
8
- * - `software` (dev/test): operator-configured Ed25519 key from an environment
9
- * variable, either plain 64-char hex or AES-256-GCM encrypted
10
- * (`iv:authTag:ciphertext`, keyed by ENCRYPTION_KEY — see srv/utils/crypto.ts).
11
- *
12
- * Keys are NEVER accepted through the OData surface and never persisted; the
13
- * software key lives only in this process's memory.
14
- */
15
2
  export interface WorkerSigner {
16
3
  readonly type: WorkerSignerTypeValue;
17
4
  /** Bech32 enterprise address the wallet spends from. */
@@ -25,22 +12,16 @@ export interface WorkerSigner {
25
12
  export interface WorkerWalletConfig {
26
13
  walletId: string;
27
14
  signerType: WorkerSignerTypeValue;
28
- /**
29
- * software only: name of the environment variable holding the Ed25519 signing
30
- * key — plain 64-char hex, or AES-256-GCM `iv:authTag:ciphertext` (base64 parts).
31
- */
15
+ /** software only. Env var with the Ed25519 key as 64 hex chars or AES-256-GCM `iv:authTag:ciphertext` in base64. */
32
16
  keyEnv?: string;
17
+ /** Role a caller needs to queue jobs for this wallet. Absent = any authenticated user. */
18
+ requiresRole?: string;
33
19
  }
34
- /**
35
- * Merge a single VKey witness [publicKey, signature] into an unsigned transaction's
36
- * witness set at the raw CBOR level, preserving all non-vkey entries (scripts,
37
- * datums, redeemers) and encoding metadata. Same single-signer semantics as
38
- * HsmSigner.signTransaction — the worker wallet is the sole signer of its builds.
39
- */
20
+ /** Replaces the vkey witnesses in the raw CBOR witness set with this one. Other entries and encoding stay. */
40
21
  export declare function mergeVkeyWitness(unsignedTxCbor: string, publicKeyHex: string, signatureHex: string): string;
41
22
  /** Derive the bech32 enterprise key-hash address for a 28-byte key hash. */
42
23
  export declare function deriveEnterpriseAddress(publicKeyHash: Uint8Array, network: string): string;
43
- /** software — in-memory Ed25519 key (dev/test). */
24
+ /** In-memory Ed25519 key for development and tests. */
44
25
  export declare class SoftwareWorkerSigner implements WorkerSigner {
45
26
  readonly type: "software";
46
27
  private readonly privateKey;
@@ -16,12 +16,7 @@ const hsm_signer_1 = require("../signing/hsm-signer");
16
16
  const errors_1 = require("../../utils/errors");
17
17
  const crypto_2 = require("../../utils/crypto");
18
18
  const logger = cds_1.default.log('CardanoWalletWorker');
19
- /**
20
- * Merge a single VKey witness [publicKey, signature] into an unsigned transaction's
21
- * witness set at the raw CBOR level, preserving all non-vkey entries (scripts,
22
- * datums, redeemers) and encoding metadata. Same single-signer semantics as
23
- * HsmSigner.signTransaction — the worker wallet is the sole signer of its builds.
24
- */
19
+ /** Replaces the vkey witnesses in the raw CBOR witness set with this one. Other entries and encoding stay. */
25
20
  function mergeVkeyWitness(unsignedTxCbor, publicKeyHex, signatureHex) {
26
21
  const txObj = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(unsignedTxCbor));
27
22
  if (!(txObj instanceof cbor_1.CborArray) || txObj.array.length < 2) {
@@ -49,7 +44,7 @@ function deriveEnterpriseAddress(publicKeyHash, network) {
49
44
  const hrp = network === 'mainnet' ? 'addr' : 'addr_test';
50
45
  return bech32_1.bech32.encode(hrp, bech32_1.bech32.toWords(payload), 120);
51
46
  }
52
- /** hsm — delegates to the process-wide HsmSigner initialized at bootstrap. */
47
+ /** Delegates to the process-wide HsmSigner set up at bootstrap. */
53
48
  class HsmWorkerSigner {
54
49
  type = 'hsm';
55
50
  get signer() {
@@ -69,7 +64,7 @@ class HsmWorkerSigner {
69
64
  return this.signer.signTransaction(unsignedTxCbor, txBodyHash);
70
65
  }
71
66
  }
72
- /** software — in-memory Ed25519 key (dev/test). */
67
+ /** In-memory Ed25519 key for development and tests. */
73
68
  class SoftwareWorkerSigner {
74
69
  type = 'software';
75
70
  privateKey;
@@ -99,10 +94,7 @@ class SoftwareWorkerSigner {
99
94
  }
100
95
  }
101
96
  exports.SoftwareWorkerSigner = SoftwareWorkerSigner;
102
- /**
103
- * Resolve the software key material for a wallet: plain hex passes through,
104
- * the AES-256-GCM combined format (contains ':') is decrypted with ENCRYPTION_KEY.
105
- */
97
+ /** Plain hex passes through; the AES-256-GCM combined format (contains ':') is decrypted with ENCRYPTION_KEY. */
106
98
  function resolveSoftwareKey(wallet) {
107
99
  if (!wallet.keyEnv) {
108
100
  throw new errors_1.ConfigError(`Wallet worker: wallet "${wallet.walletId}" is signerType=software but has no keyEnv configured`);
@@ -1,34 +1,6 @@
1
- import type { CardanoClient } from '../cardano-client';
1
+ import type { CardanoClient, Network } from '../cardano-client';
2
2
  import type { CardanoIndexer } from '../cardano-indexer';
3
3
  import { type WorkerSigner, type WorkerWalletConfig } from './signers';
4
- /**
5
- * Wallet worker engine (v2.0, design §6).
6
- *
7
- * Dispatch loop over `CardanoWalletJobs`: per tick, for every configured wallet
8
- * with pending work and NO active job (building or submitted — the queue stays
9
- * blocked until the previous job CONFIRMS, which makes per-wallet UTxO contention
10
- * impossible by construction), acquire the per-wallet DB lease and execute:
11
- *
12
- * building → CardanoIndexer.index<Kind>BuildResult (build + TransactionBuilds row)
13
- * → signer.signTransaction
14
- * submitting → signed CBOR + hash committed, THEN client.submitTransaction
15
- * submitted → hand to the ConfirmationTracker (crawler hook or polling)
16
- *
17
- * The `submitting` commit is what makes the submit boundary crash-safe: the exact
18
- * bytes that may be on-chain are durable before the network call, and the row stays
19
- * non-terminal, so it keeps holding its idempotency key. Anything that goes wrong
20
- * from there on is reconciled against the chain (`reconcileSubmitting`) — the same
21
- * transaction is re-submitted, never a rebuild.
22
- *
23
- * Transient failures BEFORE the signed tx exists (provider outages, rate limits,
24
- * HSM hiccups during build/sign) re-queue the job with exponential backoff up to
25
- * `maxAttempts`; deterministic rejections (validation, insufficient funds) fail
26
- * immediately.
27
- *
28
- * All DB access runs in short fresh transactions (ambient context cleared —
29
- * NIGHTGATE lesson 2) so the single pooled SQLite connection is never held
30
- * across build/submit round-trips.
31
- */
32
4
  export interface WalletWorkerConfig {
33
5
  enabled: boolean;
34
6
  wallets: WorkerWalletConfig[];
@@ -42,16 +14,13 @@ export interface WalletWorkerConfig {
42
14
  export interface WalletWorkerDeps {
43
15
  client: CardanoClient;
44
16
  indexer: CardanoIndexer;
45
- network: string;
17
+ network: Network;
46
18
  config: WalletWorkerConfig;
47
19
  instanceId: string;
48
20
  }
49
21
  /** Retry backoff: 5s · 2^(attempt-1), capped at 60s. */
50
22
  export declare function retryBackoffMs(attempt: number): number;
51
- /**
52
- * Transient errors are worth a bounded retry; everything else is deterministic
53
- * (a retry cannot change the outcome) and fails the job immediately.
54
- */
23
+ /** Transient errors get a bounded retry; everything else fails the job immediately. */
55
24
  export declare function isTransientJobError(err: unknown): boolean;
56
25
  export declare class CardanoWalletWorker {
57
26
  private readonly deps;
@@ -60,9 +29,20 @@ export declare class CardanoWalletWorker {
60
29
  private readonly executionPromises;
61
30
  private readonly tracker;
62
31
  private dispatchTimer;
32
+ /** Earliest next reconcile per job with an open submit, and how often it was tried. */
33
+ private readonly reconcileBackoff;
34
+ /** Jobs whose transaction has no expiry, has not landed and still can: the unspent inputs, by job. */
35
+ private readonly staleJobs;
36
+ /** Earliest next look at a job's invalidation, and the tip height an own output was first seen at. */
37
+ private readonly invalidationNotBefore;
38
+ private readonly invalidationSeen;
39
+ /** Sends of a stored self-transfer not seen on chain yet, and the earliest next one. */
40
+ private readonly invalidationResend;
63
41
  private running;
64
- private ticking;
42
+ private tickInFlight;
65
43
  constructor(deps: WalletWorkerDeps);
44
+ /** A terminal outcome after its commit, so subscribers reading the row see the announced state. */
45
+ private announce;
66
46
  isRunning(): boolean;
67
47
  /** Wallets this instance can sign for (signer init succeeded). */
68
48
  getWalletIds(): string[];
@@ -79,66 +59,33 @@ export declare class CardanoWalletWorker {
79
59
  /** One dispatch round; serialized (overlapping timers collapse into one run). */
80
60
  private tickSafe;
81
61
  private tick;
82
- /**
83
- * Adopt `submitting` rows left behind by a dead executor (this process before a
84
- * restart, or another instance whose lease expired) and resolve them against the
85
- * chain. Runs per wallet under the same lease the executor would hold.
86
- */
62
+ /** Watch every submitted job of the wallets this instance signs for until it confirms or fails. */
63
+ private adoptSubmittedJobs;
64
+ private trackSubmitted;
65
+ /** Adopt `submitting` rows left by a dead executor and resolve them against the chain, under the wallet lease. */
87
66
  private reconcileOrphanedSubmissions;
88
67
  /** Run one wallet's work in the background, tracked for concurrency + shutdown. */
89
68
  private spawn;
90
69
  /** A heartbeat that keeps this instance's lease on `walletId` alive while it works. */
91
70
  private leaseHeartbeat;
92
- /**
93
- * Execute one job: building → (build → sign) → submitting → submit → submitted,
94
- * then hand to the tracker. The wallet lease is held for the duration — renewed by
95
- * a heartbeat, because build+sign can outlast its TTL — and released afterwards
96
- * (queue serialization continues via the job row, not the lease).
97
- *
98
- * Everything up to and including the `submitting` commit may fail freely — nothing
99
- * has been sent, so the job re-queues or fails normally. Past that commit the job
100
- * belongs to `reconcileSubmitting`.
101
- */
71
+ /** Builds, signs and submits one job under a renewed wallet lease. After the submitting commit, reconcileSubmitting owns it. */
102
72
  private executeJob;
103
- /**
104
- * Send a transaction that is already durable in its `submitting` row and advance
105
- * the job to `submitted`.
106
- *
107
- * A submit failure is NEVER propagated as a job failure here: a rejection from one
108
- * backend does not prove the tx is absent from every mempool (failover, timeouts,
109
- * a node that accepted before the connection dropped). The row simply stays
110
- * `submitting` and the next tick reconciles it against the chain.
111
- */
73
+ /** Sends the stored tx. A failed submit leaves the row submitting, since one rejection proves nothing. */
112
74
  private submitStoredTransaction;
113
75
  /** submitting → submitted + hand to the confirmation tracker. */
114
76
  private adoptSubmitted;
115
- /**
116
- * Resolve a `submitting` job whose submit outcome is unknown (process died around
117
- * the network call, or the call failed ambiguously). The stored transaction is the
118
- * only one this job may ever have — it is re-submitted verbatim, never rebuilt.
119
- *
120
- * 1. Re-submit the same CBOR: mempool/ledger dedup makes this a no-op if it was
121
- * accepted before, so success (or "already known") simply promotes the job.
122
- * 2. If that fails, ask the chain: found → the tx did make it, promote it.
123
- * 3. Only when the chain proves absence AND the node rejects the tx for good (or
124
- * it has been absent past the confirmation timeout) is the job failed —
125
- * failing releases the idempotency key, so it needs that proof.
126
- * Anything else leaves the row as-is; the next tick tries again.
127
- *
128
- * Runs under the same heartbeat-kept wallet lease as an execution: the chain
129
- * lookups here are slow enough to outlive the raw TTL. Losing the lease mid-way
130
- * is not dangerous (the re-submit is the same transaction, and every terminal
131
- * transition is row-guarded), so it only stops further work.
132
- */
133
77
  private reconcileSubmitting;
134
78
  private failReconciled;
79
+ /** One invalidation per wallet at a time: the job already being invalidated first, else a stale one. */
80
+ private invalidateStaleJobs;
81
+ private handleInvalidation;
82
+ private resendWaitingInvalidation;
83
+ private finishInvalidated;
84
+ /** The job's build, ready to run in a transaction. A malformed request throws 400 INVALID_INPUT here. */
85
+ private buildOf;
135
86
  /** Dispatch the job kind to the matching indexer build method. */
136
87
  private buildForKind;
137
- /**
138
- * Submit tolerant of "already known": after a crash between submit and the
139
- * `submitted` transition, the retry re-submits the same CBOR — mempool dedup
140
- * answers with an already-submitted error that IS our success case.
141
- */
88
+ /** Submit treating "already known" as success: a re-submit of the same CBOR after a crash hits mempool dedup. */
142
89
  private submitWithAlreadyKnownTolerance;
143
90
  private handleExecutionFailure;
144
91
  }