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

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 (208) 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 +347 -0
  4. package/@cds-models/CardanoBackendService/index.js +40 -0
  5. package/@cds-models/CardanoIndexerService/index.d.ts +496 -11
  6. package/@cds-models/CardanoIndexerService/index.js +64 -0
  7. package/@cds-models/CardanoODataService/index.d.ts +414 -57
  8. package/@cds-models/CardanoODataService/index.js +42 -0
  9. package/@cds-models/CardanoSignService/index.d.ts +32 -19
  10. package/@cds-models/CardanoSignService/index.js +3 -0
  11. package/@cds-models/CardanoTransactionService/index.d.ts +58 -44
  12. package/@cds-models/CardanoTransactionService/index.js +4 -0
  13. package/@cds-models/CardanoWorkerService/index.d.ts +7 -22
  14. package/@cds-models/index.d.ts +101 -1
  15. package/@cds-models/index.js +16 -1
  16. package/@cds-models/odatano/cardano/index.d.ts +437 -32
  17. package/@cds-models/odatano/cardano/index.js +48 -0
  18. package/README.md +207 -167
  19. package/db/schema.cds +2402 -1705
  20. package/db/types.cds +446 -295
  21. package/package.json +41 -16
  22. package/scripts/migrate-schema.mjs +334 -0
  23. package/scripts/migrate-slot-leader.mjs +96 -0
  24. package/src/index.d.ts +20 -21
  25. package/src/index.js +45 -31
  26. package/src/plugin.js +17 -35
  27. package/srv/blockchain/asset-decimals.d.ts +7 -0
  28. package/srv/blockchain/asset-decimals.js +91 -0
  29. package/srv/blockchain/backends/blockfrost-backend.d.ts +25 -135
  30. package/srv/blockchain/backends/blockfrost-backend.js +66 -172
  31. package/srv/blockchain/backends/cardano-backend.d.ts +94 -186
  32. package/srv/blockchain/backends/cardano-backend.js +29 -5
  33. package/srv/blockchain/backends/koios-backend.d.ts +103 -168
  34. package/srv/blockchain/backends/koios-backend.js +428 -360
  35. package/srv/blockchain/backends/odatano-backend.d.ts +54 -0
  36. package/srv/blockchain/backends/odatano-backend.js +169 -0
  37. package/srv/blockchain/backends/ogmios-backend.d.ts +123 -190
  38. package/srv/blockchain/backends/ogmios-backend.js +637 -315
  39. package/srv/blockchain/backends/ogmios-frame-guard.d.ts +14 -0
  40. package/srv/blockchain/backends/ogmios-frame-guard.js +89 -0
  41. package/srv/blockchain/cardano-client.d.ts +61 -241
  42. package/srv/blockchain/cardano-client.js +253 -293
  43. package/srv/blockchain/cardano-indexer.d.ts +282 -281
  44. package/srv/blockchain/cardano-indexer.js +1551 -484
  45. package/srv/blockchain/cardano-tx-builder.d.ts +25 -89
  46. package/srv/blockchain/cardano-tx-builder.js +164 -140
  47. package/srv/blockchain/circuit-breaker.d.ts +1 -13
  48. package/srv/blockchain/circuit-breaker.js +5 -15
  49. package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
  50. package/srv/blockchain/crawler/account-snapshots.js +153 -0
  51. package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +15 -0
  52. package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
  53. package/srv/blockchain/crawler/asset-registry-backfill.d.ts +43 -0
  54. package/srv/blockchain/crawler/asset-registry-backfill.js +153 -0
  55. package/srv/blockchain/crawler/certificate-backfill.d.ts +52 -0
  56. package/srv/blockchain/crawler/certificate-backfill.js +162 -0
  57. package/srv/blockchain/crawler/crawler.d.ts +104 -81
  58. package/srv/blockchain/crawler/crawler.js +532 -160
  59. package/srv/blockchain/crawler/credential-backfill.d.ts +28 -0
  60. package/srv/blockchain/crawler/credential-backfill.js +124 -0
  61. package/srv/blockchain/crawler/hooks.d.ts +2 -17
  62. package/srv/blockchain/crawler/index.d.ts +1 -8
  63. package/srv/blockchain/crawler/index.js +31 -17
  64. package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
  65. package/srv/blockchain/crawler/input-asset-copies.js +171 -0
  66. package/srv/blockchain/crawler/metadata-position-backfill.d.ts +16 -0
  67. package/srv/blockchain/crawler/metadata-position-backfill.js +55 -0
  68. package/srv/blockchain/crawler/output-datum-backfill.d.ts +39 -0
  69. package/srv/blockchain/crawler/output-datum-backfill.js +110 -0
  70. package/srv/blockchain/crawler/sync-state.d.ts +27 -47
  71. package/srv/blockchain/crawler/sync-state.js +113 -63
  72. package/srv/blockchain/crawler/transaction-backfill.d.ts +44 -0
  73. package/srv/blockchain/crawler/transaction-backfill.js +278 -0
  74. package/srv/blockchain/crawler/utxo-set-import.d.ts +66 -0
  75. package/srv/blockchain/crawler/utxo-set-import.js +399 -0
  76. package/srv/blockchain/ledger-state.d.ts +62 -0
  77. package/srv/blockchain/ledger-state.js +419 -0
  78. package/srv/blockchain/pending-spends.d.ts +16 -0
  79. package/srv/blockchain/pending-spends.js +81 -0
  80. package/srv/blockchain/pool-metadata.d.ts +15 -0
  81. package/srv/blockchain/pool-metadata.js +132 -0
  82. package/srv/blockchain/request-coalescer.d.ts +2 -16
  83. package/srv/blockchain/request-coalescer.js +2 -16
  84. package/srv/blockchain/signing/cose-verifier.d.ts +3 -17
  85. package/srv/blockchain/signing/cose-verifier.js +146 -70
  86. package/srv/blockchain/signing/external-signer.d.ts +15 -115
  87. package/srv/blockchain/signing/external-signer.js +17 -126
  88. package/srv/blockchain/signing/hsm-signer.d.ts +10 -54
  89. package/srv/blockchain/signing/hsm-signer.js +28 -79
  90. package/srv/blockchain/signing/signature-verifier.d.ts +9 -47
  91. package/srv/blockchain/signing/signature-verifier.js +70 -83
  92. package/srv/blockchain/signing/submission-finalizer.d.ts +23 -45
  93. package/srv/blockchain/signing/submission-finalizer.js +219 -86
  94. package/srv/blockchain/stored-chain.d.ts +20 -0
  95. package/srv/blockchain/stored-chain.js +237 -0
  96. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +31 -229
  97. package/srv/blockchain/transaction-building/buildooor-tx.js +652 -416
  98. package/srv/blockchain/transaction-building/cardano-tx.d.ts +9 -37
  99. package/srv/blockchain/transaction-presence.d.ts +5 -0
  100. package/srv/blockchain/transaction-presence.js +29 -0
  101. package/srv/blockchain/transaction-rows.d.ts +12 -0
  102. package/srv/blockchain/transaction-rows.js +44 -0
  103. package/srv/blockchain/wallet-worker/build-request.d.ts +5 -20
  104. package/srv/blockchain/wallet-worker/build-request.js +47 -30
  105. package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +5 -46
  106. package/srv/blockchain/wallet-worker/confirmation-tracker.js +25 -45
  107. package/srv/blockchain/wallet-worker/index.d.ts +1 -1
  108. package/srv/blockchain/wallet-worker/index.js +3 -11
  109. package/srv/blockchain/wallet-worker/job-store.d.ts +30 -148
  110. package/srv/blockchain/wallet-worker/job-store.js +101 -201
  111. package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -26
  112. package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -28
  113. package/srv/blockchain/wallet-worker/signers.d.ts +5 -24
  114. package/srv/blockchain/wallet-worker/signers.js +4 -12
  115. package/srv/blockchain/wallet-worker/wallet-worker.d.ts +8 -80
  116. package/srv/blockchain/wallet-worker/wallet-worker.js +107 -155
  117. package/srv/cardano-agent-service.cds +122 -84
  118. package/srv/cardano-agent-service.js +4 -9
  119. package/srv/cardano-backend-service.cds +78 -0
  120. package/srv/cardano-backend-service.d.ts +2 -0
  121. package/srv/cardano-backend-service.js +242 -0
  122. package/srv/cardano-indexer-service.cds +387 -73
  123. package/srv/cardano-indexer-service.d.ts +5 -1
  124. package/srv/cardano-indexer-service.js +532 -16
  125. package/srv/cardano-service.cds +424 -269
  126. package/srv/cardano-service.js +289 -201
  127. package/srv/cardano-sign-service.cds +201 -180
  128. package/srv/cardano-sign-service.js +71 -201
  129. package/srv/cardano-tx-service.cds +451 -370
  130. package/srv/cardano-tx-service.js +271 -289
  131. package/srv/cardano-ui.cds +16 -16
  132. package/srv/cardano-worker-service.cds +118 -125
  133. package/srv/cardano-worker-service.js +52 -61
  134. package/srv/cbor/cip68.d.ts +13 -0
  135. package/srv/cbor/cip68.js +56 -0
  136. package/srv/cbor/index.d.ts +3 -1
  137. package/srv/cbor/index.js +9 -1
  138. package/srv/cbor/parse.d.ts +30 -18
  139. package/srv/cbor/parse.js +44 -9
  140. package/srv/cbor/plutus-data-json.d.ts +20 -0
  141. package/srv/cbor/plutus-data-json.js +32 -0
  142. package/srv/config.d.ts +113 -0
  143. package/srv/config.js +409 -0
  144. package/srv/server.d.ts +15 -110
  145. package/srv/server.js +84 -404
  146. package/srv/utils/agent-access.d.ts +9 -0
  147. package/srv/utils/agent-access.js +67 -0
  148. package/srv/utils/agent-grants-config.d.ts +0 -46
  149. package/srv/utils/agent-grants-config.js +17 -85
  150. package/srv/utils/agent-grants.d.ts +106 -122
  151. package/srv/utils/agent-grants.js +538 -236
  152. package/srv/utils/agent-token-auth.d.ts +4 -99
  153. package/srv/utils/agent-token-auth.js +18 -182
  154. package/srv/utils/backend-request-handler.d.ts +3 -17
  155. package/srv/utils/backend-request-handler.js +3 -18
  156. package/srv/utils/collections.d.ts +3 -10
  157. package/srv/utils/collections.js +3 -10
  158. package/srv/utils/const.d.ts +23 -74
  159. package/srv/utils/const.js +32 -79
  160. package/srv/utils/crypto.d.ts +3 -12
  161. package/srv/utils/crypto.js +6 -21
  162. package/srv/utils/db-indexes.d.ts +27 -0
  163. package/srv/utils/db-indexes.js +120 -0
  164. package/srv/utils/db-sanitize.d.ts +20 -0
  165. package/srv/utils/db-sanitize.js +80 -0
  166. package/srv/utils/deep-json.d.ts +6 -0
  167. package/srv/utils/deep-json.js +240 -0
  168. package/srv/utils/epoch-slots.d.ts +13 -0
  169. package/srv/utils/epoch-slots.js +38 -0
  170. package/srv/utils/error-codes.d.ts +22 -75
  171. package/srv/utils/error-codes.js +23 -72
  172. package/srv/utils/errors.d.ts +46 -187
  173. package/srv/utils/errors.js +114 -230
  174. package/srv/utils/liveness.d.ts +12 -0
  175. package/srv/utils/liveness.js +35 -0
  176. package/srv/utils/mappers.d.ts +102 -223
  177. package/srv/utils/mappers.js +387 -316
  178. package/srv/utils/network-context.js +2 -13
  179. package/srv/utils/paging.d.ts +31 -0
  180. package/srv/utils/paging.js +43 -0
  181. package/srv/utils/pg-inline-json.d.ts +8 -0
  182. package/srv/utils/pg-inline-json.js +58 -0
  183. package/srv/utils/pg-order-nulls.d.ts +14 -0
  184. package/srv/utils/pg-order-nulls.js +54 -0
  185. package/srv/utils/plutus-placeholders.d.ts +16 -22
  186. package/srv/utils/plutus-placeholders.js +62 -33
  187. package/srv/utils/rate-limiter.d.ts +2 -21
  188. package/srv/utils/rate-limiter.js +5 -17
  189. package/srv/utils/readiness.d.ts +12 -0
  190. package/srv/utils/readiness.js +29 -0
  191. package/srv/utils/reference-script.d.ts +19 -0
  192. package/srv/utils/reference-script.js +84 -0
  193. package/srv/utils/result-numbers.d.ts +15 -0
  194. package/srv/utils/result-numbers.js +61 -0
  195. package/srv/utils/service-events.d.ts +0 -24
  196. package/srv/utils/service-events.js +3 -25
  197. package/srv/utils/signing-helper.d.ts +3 -20
  198. package/srv/utils/signing-helper.js +35 -64
  199. package/srv/utils/tx-build-helper.d.ts +10 -105
  200. package/srv/utils/tx-build-helper.js +81 -144
  201. package/srv/utils/tx-request-parsers.d.ts +82 -33
  202. package/srv/utils/tx-request-parsers.js +401 -49
  203. package/srv/utils/tx-utils.d.ts +3 -27
  204. package/srv/utils/tx-utils.js +32 -50
  205. package/srv/utils/types.d.ts +261 -191
  206. package/srv/utils/types.js +2 -6
  207. package/srv/utils/validators.d.ts +22 -92
  208. package/srv/utils/validators.js +50 -149
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SignatureVerifier = void 0;
7
+ exports.verifyTxWitnesses = verifyTxWitnesses;
7
8
  exports.getSignatureVerifier = getSignatureVerifier;
8
9
  const cds_1 = __importDefault(require("@sap/cds"));
9
10
  const cbor_1 = require("@harmoniclabs/cbor");
@@ -12,13 +13,8 @@ const crypto_1 = require("@harmoniclabs/crypto");
12
13
  const errors_1 = require("../../utils/errors");
13
14
  const error_codes_1 = require("../../utils/error-codes");
14
15
  const logger = cds_1.default.log('SignatureVerifier');
15
- /**
16
- * blake2b-256 over the ORIGINAL transaction-body bytes (CBOR array index 0).
17
- * subCborRef preserves the exact received bytes, so the hash matches what was signed
18
- * and re-serialization can never drift it. (Historically this also sidestepped the
19
- * ledger-ts AuxiliaryData.fromCbor bug on metadata-only aux_data — fixed in 0.5.6 —
20
- * but byte-exactness remains the reason to stay at the raw-CBOR level.)
21
- */
16
+ // blake2b-256 over the original body bytes. subCborRef keeps the received bytes,
17
+ // so the hash matches what was signed.
22
18
  function computeBodyHash(txBytes) {
23
19
  const tx = cbor_1.Cbor.parse(txBytes);
24
20
  if (!(tx instanceof cbor_1.CborArray) || tx.array.length < 1 || !tx.array[0].subCborRef) {
@@ -26,64 +22,82 @@ function computeBodyHash(txBytes) {
26
22
  }
27
23
  return (0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_256)(tx.array[0].subCborRef.toBuffer()));
28
24
  }
29
- /**
30
- * Extract vkey witnesses (raw public key + signature bytes) from a transaction's
31
- * witness set (CBOR array index 1, map key 0). Conway wraps the witness array in CBOR
32
- * tag 258 (set) — unwrapped here. Returns [] when the tx has no vkey witnesses.
33
- */
34
- function extractVkeyWitnesses(txBytes) {
25
+ // Conway wraps the vkey witness array in CBOR tag 258, which is unwrapped here.
26
+ // `malformed` counts entries that are not a [vkey, signature] byte pair.
27
+ function readVkeyWitnesses(txBytes) {
35
28
  const tx = cbor_1.Cbor.parse(txBytes);
36
29
  if (!(tx instanceof cbor_1.CborArray) || !(tx.array[1] instanceof cbor_1.CborMap))
37
- return [];
30
+ return { witnesses: [], malformed: 0 };
38
31
  const entry = tx.array[1].map.find(e => e.k instanceof cbor_1.CborUInt && Number(e.k.num) === 0);
39
32
  if (!entry)
40
- return [];
33
+ return { witnesses: [], malformed: 0 };
41
34
  let arr = entry.v;
42
35
  if (arr instanceof cbor_1.CborTag)
43
36
  arr = arr.data;
44
37
  if (!(arr instanceof cbor_1.CborArray))
45
- return [];
46
- // Parse defensively: a malformed witness entry (wrong shape or non-bytes members)
47
- // would otherwise throw a TypeError and surface as an opaque internal error. Skip
48
- // any entry that isn't a [vkey, signature] pair of byte strings.
38
+ return { witnesses: [], malformed: 0 };
49
39
  const witnesses = [];
50
- let skipped = 0;
51
- for (const pair of arr.array) {
40
+ let malformed = 0;
41
+ arr.array.forEach((pair, index) => {
52
42
  if (!(pair instanceof cbor_1.CborArray) || pair.array.length !== 2) {
53
- skipped++;
54
- continue;
43
+ malformed++;
44
+ return;
55
45
  }
56
46
  const [vk, sg] = pair.array;
57
47
  if (!(vk instanceof cbor_1.CborBytes) || !(sg instanceof cbor_1.CborBytes)) {
58
- skipped++;
59
- continue;
48
+ malformed++;
49
+ return;
60
50
  }
61
- witnesses.push({ pubKey: vk.bytes, signature: sg.bytes });
62
- }
63
- if (skipped > 0) {
64
- // not fatal, but a malformed witness in a signed tx is suspicious — surface it
65
- logger.warn(`Skipped ${skipped} malformed vkey witness entr${skipped === 1 ? 'y' : 'ies'} while verifying (expected [vkey, signature] byte pairs)`);
51
+ witnesses.push({ index, pubKey: vk.bytes, signature: sg.bytes });
52
+ });
53
+ return { witnesses, malformed };
54
+ }
55
+ /** Well-formed vkey witnesses; [] when the tx has none. Malformed entries are skipped with a warning. */
56
+ function extractVkeyWitnesses(txBytes) {
57
+ const { witnesses, malformed } = readVkeyWitnesses(txBytes);
58
+ if (malformed > 0) {
59
+ // Not fatal, but a malformed witness in a signed tx is suspicious.
60
+ logger.warn(`Skipped ${malformed} malformed vkey witness entr${malformed === 1 ? 'y' : 'ies'} while verifying (expected [vkey, signature] byte pairs)`);
66
61
  }
67
62
  return witnesses;
68
63
  }
69
- /**
70
- * SignatureVerifier - Verifies transaction signatures without accessing private keys
71
- *
72
- * This module provides signature verification for externally signed transactions.
73
- * It ensures:
74
- * 1. The signed CBOR is valid and parseable
75
- * 2. The transaction body hash matches the expected hash (integrity check)
76
- * 3. Required signatures are present (when specified)
77
- * 4. No tampering occurred between build and sign steps
78
- */
64
+ /** Ed25519 check of one witness over the body hash; false for a key or signature of the wrong length. */
65
+ function signatureValid(w, bodyHashBytes) {
66
+ try {
67
+ return (0, crypto_1.verifyEd25519Signature_sync)(w.signature, bodyHashBytes, w.pubKey);
68
+ }
69
+ catch {
70
+ return false;
71
+ }
72
+ }
73
+ // Checks every vkey witness against the body hash. Needs no initialize().
74
+ // A tx without vkey witnesses is valid here; required signers are the caller's check.
75
+ function verifyTxWitnesses(signedTxCbor) {
76
+ const errors = [];
77
+ const signerKeyHashes = [];
78
+ let txBodyHash = null;
79
+ try {
80
+ const txBytes = (0, uint8array_utils_1.fromHex)(signedTxCbor);
81
+ txBodyHash = computeBodyHash(txBytes);
82
+ const bodyHashBytes = (0, uint8array_utils_1.fromHex)(txBodyHash);
83
+ const { witnesses, malformed } = readVkeyWitnesses(txBytes);
84
+ if (malformed > 0)
85
+ errors.push(`${malformed} vkey witness entr${malformed === 1 ? 'y is' : 'ies are'} not a [vkey, signature] byte pair`);
86
+ for (const w of witnesses) {
87
+ if (signatureValid(w, bodyHashBytes))
88
+ signerKeyHashes.push((0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_224)(w.pubKey)));
89
+ else
90
+ errors.push(`Invalid signature at witness index ${w.index}`);
91
+ }
92
+ }
93
+ catch (error) {
94
+ errors.push(`Failed to read transaction: ${error instanceof Error ? error.message : String(error)}`);
95
+ }
96
+ return { valid: errors.length === 0, txBodyHash, signerKeyHashes, errors };
97
+ }
98
+ /** Verifies externally signed transactions without private keys. */
79
99
  class SignatureVerifier {
80
- /**
81
- * Verify a signed transaction
82
- *
83
- * @param signedTxCbor - The signed transaction in CBOR hex format
84
- * @param options - Verification options
85
- * @returns Verification result with details
86
- */
100
+ /** Verify a signed tx (hex CBOR); all failures are reported in the result, never thrown. */
87
101
  verify(signedTxCbor, options = {}) {
88
102
  const result = {
89
103
  isValid: false,
@@ -93,8 +107,7 @@ class SignatureVerifier {
93
107
  warnings: [],
94
108
  };
95
109
  try {
96
- // Compute the body hash over the original CBOR body bytes (no re-serialization),
97
- // matching exactly what was signed.
110
+ // Body hash over the original body bytes, exactly what was signed.
98
111
  const txBytes = (0, uint8array_utils_1.fromHex)(signedTxCbor);
99
112
  const computedHash = computeBodyHash(txBytes);
100
113
  result.txBodyHash = computedHash;
@@ -137,11 +150,9 @@ class SignatureVerifier {
137
150
  // verify each signature cryptographically against the transaction body hash
138
151
  if (vkeyWitnesses.length > 0) {
139
152
  const bodyHashBytes = (0, uint8array_utils_1.fromHex)(computedHash);
140
- for (let i = 0; i < vkeyWitnesses.length; i++) {
141
- const { pubKey, signature } = vkeyWitnesses[i];
142
- const isValidSig = (0, crypto_1.verifyEd25519Signature_sync)(signature, bodyHashBytes, pubKey);
143
- if (!isValidSig) {
144
- result.errorMessage = `Invalid signature at witness index ${i}. The signature does not match the transaction body.`;
153
+ for (const w of vkeyWitnesses) {
154
+ if (!signatureValid(w, bodyHashBytes)) {
155
+ result.errorMessage = `Invalid signature at witness index ${w.index}. The signature does not match the transaction body.`;
145
156
  logger.warn(result.errorMessage);
146
157
  return result;
147
158
  }
@@ -159,13 +170,7 @@ class SignatureVerifier {
159
170
  }
160
171
  return result;
161
172
  }
162
- /**
163
- * Verify signature and throw on failure
164
- *
165
- * @param signedTxCbor - The signed transaction in CBOR hex format
166
- * @param options - Verification options
167
- * @throws {TransactionValidationError} if verification fails
168
- */
173
+ /** Like verify(), but throws TransactionValidationError on failure. */
169
174
  verifyOrThrow(signedTxCbor, options = {}) {
170
175
  const result = this.verify(signedTxCbor, options);
171
176
  if (!result.isValid) {
@@ -173,13 +178,7 @@ class SignatureVerifier {
173
178
  }
174
179
  return result;
175
180
  }
176
- /**
177
- * Extract transaction body hash from unsigned or signed CBOR
178
- *
179
- * @param txCbor - Transaction CBOR (signed or unsigned)
180
- * @returns Transaction body hash as hex string
181
- * @throws {Error} if CBOR is invalid
182
- */
181
+ /** Body hash (hex) of an unsigned or signed tx CBOR; throws BackendError 400 on invalid CBOR. */
183
182
  extractTxBodyHash(txCbor) {
184
183
  try {
185
184
  return computeBodyHash((0, uint8array_utils_1.fromHex)(txCbor));
@@ -189,12 +188,7 @@ class SignatureVerifier {
189
188
  throw new errors_1.BackendError(`Failed to extract transaction body hash: ${msg}`, 400, error_codes_1.ERROR_CODES.INVALID_INPUT);
190
189
  }
191
190
  }
192
- /**
193
- * Check if a transaction is signed (has witnesses)
194
- *
195
- * @param txCbor - Transaction CBOR
196
- * @returns true if transaction has at least one witness
197
- */
191
+ /** True when the tx carries at least one vkey witness. */
198
192
  isSigned(txCbor) {
199
193
  try {
200
194
  return extractVkeyWitnesses((0, uint8array_utils_1.fromHex)(txCbor)).length > 0;
@@ -203,12 +197,7 @@ class SignatureVerifier {
203
197
  return false;
204
198
  }
205
199
  }
206
- /**
207
- * Get witness count from transaction
208
- *
209
- * @param txCbor - Transaction CBOR
210
- * @returns Number of witnesses
211
- */
200
+ /** Number of vkey witnesses in the tx (0 on invalid CBOR). */
212
201
  getWitnessCount(txCbor) {
213
202
  try {
214
203
  return extractVkeyWitnesses((0, uint8array_utils_1.fromHex)(txCbor)).length;
@@ -221,9 +210,7 @@ class SignatureVerifier {
221
210
  exports.SignatureVerifier = SignatureVerifier;
222
211
  // Singleton instance
223
212
  let verifierInstance = null;
224
- /**
225
- * Get the singleton SignatureVerifier instance
226
- */
213
+ /** Singleton SignatureVerifier. */
227
214
  function getSignatureVerifier() {
228
215
  if (!verifierInstance) {
229
216
  verifierInstance = new SignatureVerifier();
@@ -1,4 +1,10 @@
1
1
  import cds, { Request } from '@sap/cds';
2
+ import { type TransactionLookup } from '../transaction-presence';
3
+ import type { CardanoIndexer } from '../cardano-indexer';
4
+ import type { CardanoClient } from '../cardano-client';
5
+ import { type TransactionSubmission } from '#cds-models/CardanoTransactionService';
6
+ /** An open submit is sent again for this long. After it only the chain is read. */
7
+ export declare const RESUBMIT_WINDOW_MS: number;
2
8
  /** Shape persisted by indexVerifiedTransactionSubmission. */
3
9
  export interface FinalizeParams {
4
10
  signingRequestId: string;
@@ -14,50 +20,22 @@ export interface FinalizeParams {
14
20
  signerType?: string;
15
21
  signerInfo?: string;
16
22
  }
17
- /**
18
- * Submit a verified+claimed signing request to the blockchain and persist the
19
- * outcome — DELIBERATELY outside the caller's request transaction.
20
- *
21
- * The caller must already have durably committed `status:'submitting'` (the
22
- * claim). This function then:
23
- * 1. submits with NO DB write-lock held (the lock was the reason concurrent
24
- * submits serialized and the SQLite busy-timeout could fire mid-network),
25
- * 2. on submit failure: marks the request 'failed' in its own committed tx
26
- * and rethrows (NOT rolled back to a pre-submit status — losing the
27
- * attempt would hide a tx the node may have accepted),
28
- * 3. on success: persists the submission + 'submitted' status in a committed
29
- * transaction.
30
- *
31
- * Crash window: a process death between (1) and (3) leaves the request durably
32
- * at 'submitting'. Deferred-path requests carry their signed CBOR on the row
33
- * and are re-driven at the next boot (redriveInterruptedSubmissions); sync-path
34
- * requests are left for the operator/poller exactly as before.
35
- */
36
- export declare function submitAndFinalize(SigningRequests: unknown, params: FinalizeParams, afterFinalize?: (db: cds.Transaction) => Promise<void>): Promise<unknown>;
37
- /**
38
- * Deferred-submit scheduler (KNOWN_ISSUES #11, Layer 2).
39
- *
40
- * Called by an action handler AFTER verify + claim ran on the CALLER's
41
- * transaction. Hooks the request's post-commit event: only once the caller's
42
- * root transaction has committed (claim durable, pooled connection released)
43
- * does the network submit + finalize run — detached via setImmediate +
44
- * runWithoutAmbientTx, so no ambient transaction is held across it.
45
- *
46
- * If the caller's transaction rolls back instead, 'succeeded' never fires and
47
- * nothing was claimed — strictly consistent.
48
- */
23
+ type SubmissionIndexer = Pick<CardanoIndexer, 'persistTransactionSubmission' | 'updateSubmissionStatus' | 'dropDuplicateSubmission' | 'invalidateUtxoCacheForTx' | 'findIndexedTransaction'>;
24
+ type SubmissionClient = Pick<CardanoClient, 'submitTransaction'> & TransactionLookup;
25
+ interface SubmissionDeps {
26
+ indexer: SubmissionIndexer & Pick<CardanoIndexer, 'indexVerifiedTransactionSubmission'>;
27
+ client: SubmissionClient;
28
+ }
29
+ export declare function submitAndFinalize(SigningRequests: unknown, params: FinalizeParams, afterFinalize?: (db: cds.Transaction) => Promise<void>, send?: boolean, { indexer, client }?: SubmissionDeps): Promise<unknown>;
30
+ export declare function submitRecorded(params: {
31
+ signedTxCbor: string;
32
+ txHash: string;
33
+ buildId: string | null;
34
+ }, indexer?: SubmissionIndexer, client?: SubmissionClient): Promise<TransactionSubmission>;
49
35
  export declare function scheduleDeferredSubmit(req: Request, SigningRequests: unknown, params: FinalizeParams): void;
50
- /**
51
- * Boot-time recovery: re-drive submissions that were claimed on the deferred
52
- * path (status 'submitting' WITH persisted signedTxCbor) but never finalized —
53
- * i.e. the process died between the caller's commit and the detached submit.
54
- *
55
- * Safe to repeat: a tx the node already holds finalizes as 'submitted' via the
56
- * TransactionAlreadySubmittedError path in submitAndFinalize. Rows at
57
- * 'submitting' WITHOUT signed CBOR (sync-path crash window) are deliberately
58
- * left untouched for the operator/poller, exactly as before Layer 2.
59
- *
60
- * @returns number of rows re-driven (attempted, not necessarily succeeded)
61
- */
62
- export declare function redriveInterruptedSubmissions(): Promise<number>;
36
+ export declare function redriveInterruptedSubmissions(deps?: SubmissionDeps): Promise<number>;
37
+ /** Starts the periodic pass over open signing requests and submissions. Idempotent. */
38
+ export declare function startSubmissionReconciler(): void;
39
+ export declare function stopSubmissionReconciler(): void;
40
+ export {};
63
41
  //# sourceMappingURL=submission-finalizer.d.ts.map