@odatano/core 1.7.10 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/@cds-models/CardanoODataService/index.d.ts +66 -42
  2. package/@cds-models/CardanoODataService/index.d.ts.map +1 -1
  3. package/@cds-models/CardanoODataService/index.js.map +1 -1
  4. package/@cds-models/CardanoODataService/index.ts +11 -7
  5. package/@cds-models/odatano/cardano/index.d.ts +70 -46
  6. package/@cds-models/odatano/cardano/index.d.ts.map +1 -1
  7. package/@cds-models/odatano/cardano/index.js +2 -2
  8. package/@cds-models/odatano/cardano/index.js.map +1 -1
  9. package/@cds-models/odatano/cardano/index.ts +13 -13
  10. package/LICENSE +1 -24
  11. package/README.md +102 -96
  12. package/db/schema.cds +18 -18
  13. package/db/types.cds +3 -3
  14. package/package.json +25 -11
  15. package/src/index.d.ts +29 -0
  16. package/src/index.js +1 -0
  17. package/src/plugin.d.ts +2 -0
  18. package/src/plugin.js +6 -0
  19. package/srv/blockchain/backends/blockfrost-backend.d.ts +155 -0
  20. package/srv/blockchain/backends/blockfrost-backend.js +19 -8
  21. package/srv/blockchain/backends/cardano-backend.d.ts +182 -0
  22. package/srv/blockchain/backends/koios-backend.d.ts +171 -0
  23. package/srv/blockchain/backends/koios-backend.js +69 -27
  24. package/srv/blockchain/backends/ogmios-backend.d.ts +188 -0
  25. package/srv/blockchain/backends/ogmios-backend.js +175 -108
  26. package/srv/blockchain/cardano-client.d.ts +279 -0
  27. package/srv/blockchain/cardano-client.js +134 -33
  28. package/srv/blockchain/cardano-indexer.d.ts +330 -0
  29. package/srv/blockchain/cardano-indexer.js +51 -8
  30. package/srv/blockchain/cardano-tx-builder.d.ts +113 -0
  31. package/srv/blockchain/cardano-tx-builder.js +64 -57
  32. package/srv/blockchain/circuit-breaker.d.ts +37 -0
  33. package/srv/blockchain/circuit-breaker.js +11 -2
  34. package/srv/blockchain/request-coalescer.d.ts +23 -0
  35. package/srv/blockchain/signing/external-signer.d.ts +146 -0
  36. package/srv/blockchain/signing/external-signer.js +23 -0
  37. package/srv/blockchain/signing/hsm-signer.d.ts +74 -0
  38. package/srv/blockchain/signing/hsm-signer.js +20 -5
  39. package/srv/blockchain/signing/signature-verifier.d.ts +56 -0
  40. package/srv/blockchain/signing/signature-verifier.js +79 -79
  41. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +236 -0
  42. package/srv/blockchain/transaction-building/buildooor-tx.js +632 -173
  43. package/srv/blockchain/transaction-building/cardano-tx.d.ts +47 -0
  44. package/srv/cardano-service.cds +23 -3
  45. package/srv/cardano-service.d.ts +2 -0
  46. package/srv/cardano-service.js +26 -6
  47. package/srv/cardano-sign-service.cds +5 -0
  48. package/srv/cardano-sign-service.d.ts +2 -0
  49. package/srv/cardano-sign-service.js +221 -134
  50. package/srv/cardano-tx-service.cds +8 -0
  51. package/srv/cardano-tx-service.d.ts +12 -0
  52. package/srv/cardano-tx-service.js +170 -111
  53. package/srv/cbor/index.d.ts +2 -0
  54. package/srv/cbor/parse.d.ts +64 -0
  55. package/srv/server.d.ts +90 -0
  56. package/srv/server.js +52 -41
  57. package/srv/utils/backend-request-handler.d.ts +20 -0
  58. package/srv/utils/const.d.ts +183 -0
  59. package/srv/utils/const.js +13 -6
  60. package/srv/utils/error-codes.d.ts +79 -0
  61. package/srv/utils/errors.d.ts +259 -0
  62. package/srv/utils/errors.js +22 -7
  63. package/srv/utils/mappers.d.ts +260 -0
  64. package/srv/utils/mappers.js +34 -10
  65. package/srv/utils/plutus-placeholders.d.ts +35 -0
  66. package/srv/utils/plutus-placeholders.js +6 -17
  67. package/srv/utils/signing-helper.d.ts +23 -0
  68. package/srv/utils/signing-helper.js +11 -49
  69. package/srv/utils/tx-build-helper.d.ts +76 -0
  70. package/srv/utils/tx-build-helper.js +29 -80
  71. package/srv/utils/types.d.ts +653 -0
  72. package/srv/utils/validators.d.ts +145 -0
  73. package/srv/utils/validators.js +28 -1
  74. package/@cds-models/CardanoWatcherAdminService/index.js +0 -109
  75. package/@cds-models/CardanoWatcherAdminService/index.js.map +0 -1
  76. package/@cds-models/CardanoWatcherAdminService/index.ts +0 -263
  77. package/@cds-models/cds/outbox/index.js.map +0 -1
  78. package/@cds-models/cds/xt/MTXServices/index.js +0 -8
  79. package/@cds-models/cds/xt/MTXServices/index.js.map +0 -1
  80. package/@cds-models/cds/xt/MTXServices/index.ts +0 -4
  81. package/@cds-models/odatano/reeve/index.js +0 -77
  82. package/@cds-models/odatano/reeve/index.js.map +0 -1
  83. package/@cds-models/odatano/reeve/index.ts +0 -57
  84. package/@cds-models/odatano/transactions/index.js +0 -55
  85. package/@cds-models/odatano/transactions/index.js.map +0 -1
  86. package/@cds-models/odatano/transactions/index.ts +0 -18
  87. package/@cds-models/odatano/watch/index.js +0 -114
  88. package/@cds-models/odatano/watch/index.js.map +0 -1
  89. package/@cds-models/odatano/watch/index.ts +0 -110
  90. package/config/preview/cardano-node/alonzo-genesis.json +0 -196
  91. package/config/preview/cardano-node/byron-genesis.json +0 -117
  92. package/config/preview/cardano-node/config.json +0 -118
  93. package/config/preview/cardano-node/conway-genesis.json +0 -297
  94. package/config/preview/cardano-node/shelley-genesis.json +0 -68
  95. package/config/preview/cardano-node/topology.json +0 -19
  96. package/output/sora/iter0_base.json +0 -32
  97. package/output/sora/iter0_base.mp4 +0 -0
  98. package/output/sora/logo_ref_1280x720.png +0 -0
  99. package/output/sora/odatano_full_logo_sky_ref_1280x720.png +0 -0
  100. package/output/sora/odatano_full_logo_transparent.png +0 -0
  101. package/output/sora/odatano_full_logo_transparent_dark.png +0 -0
  102. package/output/sora/odatano_full_logo_v4_8s.json +0 -32
  103. package/output/sora/odatano_full_logo_v4_8s.mp4 +0 -0
  104. package/output/sora/odatano_full_logo_v5_create.json +0 -15
  105. package/output/sora/odatano_full_logo_v5_fixes.json +0 -15
  106. package/output/sora/odatano_full_logo_v5_fixes.mp4 +0 -0
  107. package/output/sora/odatano_logo_v1.json +0 -32
  108. package/output/sora/odatano_logo_v1.mp4 +0 -0
  109. package/output/sora/odatano_o_only_clean.png +0 -0
  110. package/output/sora/odatano_o_sky_ref_1280x720.png +0 -0
  111. package/output/sora/odatano_o_sky_v2_8s.json +0 -32
  112. package/output/sora/odatano_o_sky_v2_8s.mp4 +0 -0
  113. package/output/sora/odatano_o_sky_v3_create.json +0 -15
  114. package/output/sora/odatano_o_sky_v3_splash_text.json +0 -15
  115. package/output/sora/odatano_o_sky_v3_splash_text.mp4 +0 -0
  116. package/output/sora/odatano_v6_composite_exact_logo.mp4 +0 -0
  117. package/output/sora/odatano_v6_composite_exact_logo_clean.mp4 +0 -0
  118. package/output/sora/odatano_v6_composite_exact_logo_final.mp4 +0 -0
  119. package/output/sora/odatano_v6_endframe.jpg +0 -0
  120. package/output/sora/odatano_v6_endframe_clean.jpg +0 -0
  121. package/output/sora/odatano_v6_endframe_final.jpg +0 -0
  122. package/output/sora/odatano_v7_1_earlylogo_fadeoldtext.mp4 +0 -0
  123. package/output/sora/odatano_v7_1_end.jpg +0 -0
  124. package/output/sora/odatano_v7_1_transition.jpg +0 -0
  125. package/output/sora/odatano_v7_2_original2d_keep_sky.mp4 +0 -0
  126. package/output/sora/odatano_v7_endframe_nobg.jpg +0 -0
  127. package/output/sora/odatano_v7_endframe_nobg_cleanend.jpg +0 -0
  128. package/output/sora/odatano_v7_spin_splash_logo_nobg.mp4 +0 -0
  129. package/output/sora/odatano_v7_spin_splash_logo_nobg_cleanend.mp4 +0 -0
  130. package/src/index.d.ts.map +0 -1
  131. package/src/index.js.map +0 -1
  132. package/src/plugin.d.ts.map +0 -1
  133. package/src/plugin.js.map +0 -1
  134. package/srv/blockchain/backends/blockfrost-backend.d.ts.map +0 -1
  135. package/srv/blockchain/backends/blockfrost-backend.js.map +0 -1
  136. package/srv/blockchain/backends/cardano-backend.d.ts.map +0 -1
  137. package/srv/blockchain/backends/cardano-backend.js.map +0 -1
  138. package/srv/blockchain/backends/gerolamo-backend.d.ts.map +0 -1
  139. package/srv/blockchain/backends/gerolamo-backend.js +0 -321
  140. package/srv/blockchain/backends/gerolamo-backend.js.map +0 -1
  141. package/srv/blockchain/backends/koios-backend.d.ts.map +0 -1
  142. package/srv/blockchain/backends/koios-backend.js.map +0 -1
  143. package/srv/blockchain/backends/ogmios-backend.d.ts.map +0 -1
  144. package/srv/blockchain/backends/ogmios-backend.js.map +0 -1
  145. package/srv/blockchain/cardano-client.d.ts.map +0 -1
  146. package/srv/blockchain/cardano-client.js.map +0 -1
  147. package/srv/blockchain/cardano-indexer.d.ts.map +0 -1
  148. package/srv/blockchain/cardano-indexer.js.map +0 -1
  149. package/srv/blockchain/cardano-tx-builder.d.ts.map +0 -1
  150. package/srv/blockchain/cardano-tx-builder.js.map +0 -1
  151. package/srv/blockchain/circuit-breaker.d.ts.map +0 -1
  152. package/srv/blockchain/circuit-breaker.js.map +0 -1
  153. package/srv/blockchain/request-coalescer.d.ts.map +0 -1
  154. package/srv/blockchain/request-coalescer.js.map +0 -1
  155. package/srv/blockchain/signing/external-signer.d.ts.map +0 -1
  156. package/srv/blockchain/signing/external-signer.js.map +0 -1
  157. package/srv/blockchain/signing/hsm-signer.d.ts.map +0 -1
  158. package/srv/blockchain/signing/hsm-signer.js.map +0 -1
  159. package/srv/blockchain/signing/signature-verifier.d.ts.map +0 -1
  160. package/srv/blockchain/signing/signature-verifier.js.map +0 -1
  161. package/srv/blockchain/transaction-building/buildooor-tx.d.ts.map +0 -1
  162. package/srv/blockchain/transaction-building/buildooor-tx.js.map +0 -1
  163. package/srv/blockchain/transaction-building/cardano-tx.d.ts.map +0 -1
  164. package/srv/blockchain/transaction-building/cardano-tx.js.map +0 -1
  165. package/srv/blockchain/transaction-building/csl-tx.d.ts.map +0 -1
  166. package/srv/blockchain/transaction-building/csl-tx.js +0 -922
  167. package/srv/blockchain/transaction-building/csl-tx.js.map +0 -1
  168. package/srv/blockchain/transaction-building/tx-builder-registry.d.ts.map +0 -1
  169. package/srv/blockchain/transaction-building/tx-builder-registry.js +0 -69
  170. package/srv/blockchain/transaction-building/tx-builder-registry.js.map +0 -1
  171. package/srv/cardano-service.d.ts.map +0 -1
  172. package/srv/cardano-service.js.map +0 -1
  173. package/srv/cardano-sign-service.d.ts.map +0 -1
  174. package/srv/cardano-sign-service.js.map +0 -1
  175. package/srv/cardano-tx-service.d.ts.map +0 -1
  176. package/srv/cardano-tx-service.js.map +0 -1
  177. package/srv/cbor/index.d.ts.map +0 -1
  178. package/srv/cbor/index.js.map +0 -1
  179. package/srv/cbor/parse.d.ts.map +0 -1
  180. package/srv/cbor/parse.js.map +0 -1
  181. package/srv/server.d.ts.map +0 -1
  182. package/srv/server.js.map +0 -1
  183. package/srv/utils/backend-request-handler.d.ts.map +0 -1
  184. package/srv/utils/backend-request-handler.js.map +0 -1
  185. package/srv/utils/const.d.ts.map +0 -1
  186. package/srv/utils/const.js.map +0 -1
  187. package/srv/utils/error-codes.d.ts.map +0 -1
  188. package/srv/utils/error-codes.js.map +0 -1
  189. package/srv/utils/errors.d.ts.map +0 -1
  190. package/srv/utils/errors.js.map +0 -1
  191. package/srv/utils/mappers.d.ts.map +0 -1
  192. package/srv/utils/mappers.js.map +0 -1
  193. package/srv/utils/plutus-placeholders.d.ts.map +0 -1
  194. package/srv/utils/plutus-placeholders.js.map +0 -1
  195. package/srv/utils/signing-helper.d.ts.map +0 -1
  196. package/srv/utils/signing-helper.js.map +0 -1
  197. package/srv/utils/tx-build-helper.d.ts.map +0 -1
  198. package/srv/utils/tx-build-helper.js.map +0 -1
  199. package/srv/utils/types.d.ts.map +0 -1
  200. package/srv/utils/types.js.map +0 -1
  201. package/srv/utils/validators.d.ts.map +0 -1
  202. package/srv/utils/validators.js.map +0 -1
@@ -212,7 +212,10 @@ function mapAddress(address, addressData, maxAge) {
212
212
  * @param addressTxsData address transactions data from provider
213
213
  * @returns {AddressTransactionRow[]} mapped address transaction rows
214
214
  * */
215
- function mapAddressTransactions(addr, addressTxsData, validFrom, validTo) {
215
+ // AddressTransactions is keyed by (address, tx) and the per-tx net amounts are
216
+ // immutable once confirmed — no temporal validity. The entity has no
217
+ // validFrom/validTo columns, so the previous TTL plumbing was silently dropped.
218
+ function mapAddressTransactions(addr, addressTxsData) {
216
219
  return addressTxsData.map((tx) => {
217
220
  // Calculate net amounts for this address in this transaction
218
221
  const { netLovelace, netAssets } = calculateNetAmounts(addr, tx);
@@ -223,8 +226,6 @@ function mapAddressTransactions(addr, addressTxsData, validFrom, validTo) {
223
226
  blockTime: tx.blockTime,
224
227
  netAssets: netAssets.length > 0 ? JSON.stringify(netAssets) : null,
225
228
  hasAssets: netAssets.length > 0,
226
- validFrom: validFrom,
227
- validTo: validTo,
228
229
  };
229
230
  });
230
231
  }
@@ -248,7 +249,7 @@ function calculateNetAmounts(addr, tx) {
248
249
  else {
249
250
  // Native asset
250
251
  const current = assetBalances.get(amount.unit) || 0n;
251
- assetBalances.set(amount.unit, current - BigInt(amount.quantity));
252
+ assetBalances.set(amount.unit, current - BigInt(amount.quantity || '0'));
252
253
  }
253
254
  }
254
255
  }
@@ -263,7 +264,7 @@ function calculateNetAmounts(addr, tx) {
263
264
  else {
264
265
  // Native asset
265
266
  const current = assetBalances.get(amount.unit) || 0n;
266
- assetBalances.set(amount.unit, current + BigInt(amount.quantity));
267
+ assetBalances.set(amount.unit, current + BigInt(amount.quantity || '0'));
267
268
  }
268
269
  }
269
270
  }
@@ -311,7 +312,11 @@ function mapAddressUtxos(addr, validFrom, validTo, addressUtxosData) {
311
312
  blockHash: utxo.blockHash,
312
313
  utxodata_dataHash: utxo.datumHash,
313
314
  utxodata_inlineDatum: utxo.inlineDatum || null,
314
- utxodata_referenceScriptHash: utxo.scriptRef,
315
+ // This column is a script HASH (Blake2b256). UTxO.scriptRef is overloaded:
316
+ // Blockfrost/Ogmios give a 56-hex hash (stored as-is); Koios gives the full
317
+ // script CBOR (used by the tx-builder, but it would truncate this hash
318
+ // column) — only persist hash-length values here.
319
+ utxodata_referenceScriptHash: utxo.scriptRef && utxo.scriptRef.length <= 64 ? utxo.scriptRef : null,
315
320
  lovelace: lovelace,
316
321
  validFrom: validFrom,
317
322
  validTo: validTo,
@@ -411,7 +416,8 @@ function mapBlock(providerBlockData, epochData) {
411
416
  time: new Date(providerBlockData.time * 1000).toISOString(),
412
417
  height: providerBlockData.height,
413
418
  hash: providerBlockData.hash,
414
- slotLeader: String(providerBlockData.slotLeader ?? null),
419
+ // was `String(x ?? null)` → persisted the literal string "null" when absent
420
+ slotLeader: providerBlockData.slotLeader ?? null,
415
421
  epochNumber: epochData?.epoch ?? providerBlockData.epoch,
416
422
  epoch: epochData,
417
423
  epochSlot: providerBlockData.epochSlot,
@@ -449,8 +455,14 @@ function mapEpoch(providerEpochData) {
449
455
  function mapTransactionMetadata(providerLabels) {
450
456
  const rows = [];
451
457
  for (const lbl of providerLabels) {
458
+ const numericId = Number(lbl.label);
459
+ // Metadata labels are uint64; the exact value is kept in the `label` string.
460
+ // The numeric `id` key (now Integer64) is exact up to 2^53 — warn beyond that.
461
+ if (!Number.isSafeInteger(numericId)) {
462
+ logger.warn(`Metadata label ${lbl.label} exceeds safe-integer range — numeric id key may lose precision (string label is exact)`);
463
+ }
452
464
  rows.push({
453
- id: Number(lbl.label),
465
+ id: numericId,
454
466
  tx_hash: lbl.txHash,
455
467
  label: lbl.label.toString(),
456
468
  payload: lbl.json !== undefined ? JSON.stringify(lbl.json) : null,
@@ -464,7 +476,11 @@ function mapTransactionMetadata(providerLabels) {
464
476
  * @param providerPoolData pool data from provider
465
477
  * @returns {PoolRow} mapped pool row
466
478
  */
467
- function mapPool(providerPoolData) {
479
+ function mapPool(providerPoolData, max_age) {
480
+ // temporal stamping: live fields (liveStake/liveSaturation/retired…) change every
481
+ // epoch, so a slice expires after max_age and the index-on-miss read re-fetches
482
+ const validFrom = new Date().toISOString();
483
+ const validTo = new Date(Date.now() + max_age).toISOString();
468
484
  return {
469
485
  poolId: providerPoolData.poolId,
470
486
  vrfKeyHash: providerPoolData.vrfKeyHash,
@@ -480,6 +496,8 @@ function mapPool(providerPoolData) {
480
496
  margin: Number(providerPoolData.margin),
481
497
  fixedCost: providerPoolData.fixedCost,
482
498
  rewardAccount: providerPoolData.rewardAccount,
499
+ validFrom,
500
+ validTo,
483
501
  };
484
502
  }
485
503
  /**
@@ -539,7 +557,11 @@ function mapAssetHistory(entries) {
539
557
  * @param providerDrepData drep data from provider
540
558
  * @returns {DrepRow} mapped drep row
541
559
  */
542
- function mapDrep(providerDrepData) {
560
+ function mapDrep(providerDrepData, max_age) {
561
+ // temporal stamping: amount/retired/expired drift over time → slice expires
562
+ // after max_age so the index-on-miss read re-fetches fresh state
563
+ const validFrom = new Date().toISOString();
564
+ const validTo = new Date(Date.now() + max_age).toISOString();
543
565
  return {
544
566
  drepId: providerDrepData.drepId,
545
567
  hex: providerDrepData.hex,
@@ -548,6 +570,8 @@ function mapDrep(providerDrepData) {
548
570
  lastActiveEpoch: providerDrepData.lastActiveEpoch,
549
571
  retired: Boolean(providerDrepData.retired),
550
572
  expired: Boolean(providerDrepData.expired),
573
+ validFrom,
574
+ validTo,
551
575
  };
552
576
  }
553
577
  /**
@@ -0,0 +1,35 @@
1
+ import type { JSONValue } from './types';
2
+ /**
3
+ * PlutusData-JSON input-index placeholder.
4
+ * Matches the full string form `__INPUT_IDX:<64-hex txHash>#<outputIndex>__`.
5
+ * The placeholder must be the entire `int` field value — partial matches are ignored.
6
+ */
7
+ export declare const INPUT_IDX_REGEX: RegExp;
8
+ /** Minimal UTxO reference shape used by the placeholder resolver. */
9
+ export interface InputRef {
10
+ txHash: string;
11
+ outputIndex: number;
12
+ }
13
+ export interface ResolveContext {
14
+ /** Inputs in their final, post-sort order — index of `ref` in this array == resolved placeholder value. */
15
+ sortedInputs: InputRef[];
16
+ }
17
+ /**
18
+ * Replicates Buildooor's input sort: lexicographic on the txHash bytes, tie-break by outputIndex asc.
19
+ * This mirrors the Cardano ledger CBOR-set ordering used by Buildooor.
20
+ * Verified against node_modules/@harmoniclabs/buildooor/dist/TxBuilder/TxBuilder.js:772.
21
+ */
22
+ export declare function sortInputsLikeBuildooor<T extends InputRef>(refs: T[]): T[];
23
+ /**
24
+ * Walk a PlutusData JSON tree and replace any `{int: "__INPUT_IDX:<hash>#<idx>__"}` leaves
25
+ * with `{int: <resolvedIndex>}` according to the sorted input order in `ctx`.
26
+ *
27
+ * Placeholders are only recognised inside an `int` field. Strings elsewhere (e.g. `bytes`)
28
+ * are left untouched — hex payloads may legitimately contain `__` sequences.
29
+ *
30
+ * Throws TransactionValidationError if a placeholder references a UTxO ref that is not present
31
+ * in `ctx.sortedInputs`. The exact placeholder string is included in the message so consumers
32
+ * can diagnose missing forceInputs / script UTxOs.
33
+ */
34
+ export declare function resolveIndexPlaceholders(node: JSONValue, ctx: ResolveContext): JSONValue;
35
+ //# sourceMappingURL=plutus-placeholders.d.ts.map
@@ -3,18 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.INPUT_IDX_REGEX = void 0;
4
4
  exports.sortInputsLikeBuildooor = sortInputsLikeBuildooor;
5
5
  exports.resolveIndexPlaceholders = resolveIndexPlaceholders;
6
- exports.containsIndexPlaceholder = containsIndexPlaceholder;
7
6
  const errors_1 = require("./errors");
8
7
  /**
9
8
  * PlutusData-JSON input-index placeholder.
10
9
  * Matches the full string form `__INPUT_IDX:<64-hex txHash>#<outputIndex>__`.
11
10
  * The placeholder must be the entire `int` field value — partial matches are ignored.
12
11
  */
13
- exports.INPUT_IDX_REGEX = /^__INPUT_IDX:([0-9a-f]{64})#(\d+)__$/;
12
+ // case-insensitive: tx hashes are conventionally lowercase, but accept either
13
+ // case and normalize the captured hash to lowercase at the use site
14
+ exports.INPUT_IDX_REGEX = /^__INPUT_IDX:([0-9a-fA-F]{64})#(\d+)__$/;
14
15
  const MAX_WALK_DEPTH = 64;
15
16
  /**
16
17
  * Replicates Buildooor's input sort: lexicographic on the txHash bytes, tie-break by outputIndex asc.
17
- * This mirrors the Cardano ledger CBOR-set ordering so both Buildooor and CSL converge on the same layout.
18
+ * This mirrors the Cardano ledger CBOR-set ordering used by Buildooor.
18
19
  * Verified against node_modules/@harmoniclabs/buildooor/dist/TxBuilder/TxBuilder.js:772.
19
20
  */
20
21
  function sortInputsLikeBuildooor(refs) {
@@ -57,7 +58,8 @@ function walk(node, ctx, depth) {
57
58
  if (key === 'int' && typeof value === 'string') {
58
59
  const match = exports.INPUT_IDX_REGEX.exec(value);
59
60
  if (match) {
60
- const [, txHash, idxStr] = match;
61
+ const [, rawTxHash, idxStr] = match;
62
+ const txHash = rawTxHash.toLowerCase(); // normalize to match validated lowercase input refs
61
63
  const outputIndex = Number(idxStr);
62
64
  const pos = ctx.sortedInputs.findIndex(ref => ref.txHash === txHash && ref.outputIndex === outputIndex);
63
65
  if (pos === -1) {
@@ -71,17 +73,4 @@ function walk(node, ctx, depth) {
71
73
  }
72
74
  return out;
73
75
  }
74
- /**
75
- * Returns true if any string leaf in the JSON tree looks like an __INPUT_IDX__ placeholder.
76
- * Used by service handlers for early rejection when the active builder (e.g. CSL) cannot
77
- * resolve placeholders.
78
- */
79
- function containsIndexPlaceholder(node) {
80
- if (node === null || typeof node !== 'object') {
81
- return typeof node === 'string' && exports.INPUT_IDX_REGEX.test(node);
82
- }
83
- if (Array.isArray(node))
84
- return node.some(containsIndexPlaceholder);
85
- return Object.values(node).some(containsIndexPlaceholder);
86
- }
87
76
  //# sourceMappingURL=plutus-placeholders.js.map
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Combine an unsigned transaction with a witness set from CIP-30 wallet signing
3
+ *
4
+ * CIP-30 signTx() returns only the witness set, not a complete signed transaction.
5
+ * This function combines the original unsigned transaction with the witness set
6
+ * to create a complete signed transaction that can be submitted to the network.
7
+ *
8
+ * @param unsignedTxCbor - The unsigned transaction CBOR (hex)
9
+ * @param witnessSetCbor - The witness set CBOR from CIP-30 signTx() (hex)
10
+ * @returns Complete signed transaction CBOR (hex)
11
+ */
12
+ export declare function combineTransactionWithWitnesses(unsignedTxCbor: string, witnessSetCbor: string): string;
13
+ /**
14
+ * Check if a CBOR string is a witness set (vs a full transaction)
15
+ *
16
+ * CIP-30 returns witness sets, not full transactions.
17
+ * This helps detect when we need to call combineTransactionWithWitnesses.
18
+ *
19
+ * @param cborHex - CBOR hex string
20
+ * @returns true if it's a witness set, false if it's a full transaction
21
+ */
22
+ export declare function isWitnessSetCbor(cborHex: string): boolean;
23
+ //# sourceMappingURL=signing-helper.d.ts.map
@@ -1,37 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
@@ -39,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
6
  exports.combineTransactionWithWitnesses = combineTransactionWithWitnesses;
40
7
  exports.isWitnessSetCbor = isWitnessSetCbor;
41
8
  const cds_1 = __importDefault(require("@sap/cds"));
42
- const CSL = __importStar(require("@emurgo/cardano-serialization-lib-nodejs"));
43
9
  const cbor_1 = require("@harmoniclabs/cbor");
44
10
  const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
45
11
  const errors_1 = require("./errors");
@@ -95,8 +61,11 @@ function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
95
61
  else {
96
62
  throw new errors_1.TransactionValidationError('Witness set must be CBOR map per Cardano spec');
97
63
  }
98
- // Re-encode the tx array, preserving encoding metadata on body and all witness values.
99
- // Construct a new CborArray to avoid stale subCborRef pointing to the old bytes.
64
+ // Re-encode the tx as a NEW outer CborArray so the encoder cannot short-circuit
65
+ // to the original full-tx bytes via the outer value's subCborRef (which no longer
66
+ // matches now that the witness set changed). The INNER element subCborRefs are
67
+ // deliberately kept: that byte-preserves the body (array[0]), so the tx body hash
68
+ // the witnesses signed stays identical.
100
69
  const signedTxCbor = (0, uint8array_utils_1.toHex)(cbor_1.Cbor.encode(new cbor_1.CborArray(txObj.array, { indefinite: txObj.indefinite })));
101
70
  logger.info({
102
71
  unsignedTxLength: unsignedTxCbor.length,
@@ -123,22 +92,15 @@ function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
123
92
  */
124
93
  function isWitnessSetCbor(cborHex) {
125
94
  try {
126
- const bytes = Buffer.from(cborHex, 'hex');
127
- // Try to parse as transaction first
128
- try {
129
- const tx = CSL.Transaction.from_bytes(bytes);
130
- // If successful and has a body, it's a full transaction
131
- tx.body();
95
+ const obj = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(cborHex));
96
+ // A full transaction is a CBOR array ([body, witness_set, is_valid, aux_data]);
97
+ // a CIP-30 witness set is a CBOR map. The two shapes are unambiguous.
98
+ if (obj instanceof cbor_1.CborArray)
132
99
  return false;
133
- }
134
- catch {
135
- // Not a transaction, try as witness set
136
- CSL.TransactionWitnessSet.from_bytes(bytes);
137
- return true;
138
- }
100
+ return obj instanceof cbor_1.CborMap;
139
101
  }
140
102
  catch {
141
- // Neither - could be invalid CBOR
103
+ // Invalid / unparseable CBOR
142
104
  return false;
143
105
  }
144
106
  }
@@ -0,0 +1,76 @@
1
+ import type { UTxO as OdatanoUtxo, JSONValue } from '../utils/types';
2
+ import { type Data } from '@harmoniclabs/plutus-data';
3
+ /**
4
+ * Extract lovelace amount from UTxO
5
+ * @param u UTxO to extract from
6
+ * @returns {bigint} lovelace amount
7
+ */
8
+ export declare function getLovelace(u: OdatanoUtxo): bigint;
9
+ /**
10
+ * Assert that UTxO contains only ADA (lovelace)
11
+ * @param u UTxO to check
12
+ * @throws {MixedAssetsError} if UTxO contains non-ADA assets
13
+ */
14
+ export declare function assertAdaOnly(u: OdatanoUtxo): void;
15
+ /**
16
+ * Extract transaction hash from a transaction CBOR (signed or unsigned).
17
+ * Hash is computed over the body, so witness presence does not affect it.
18
+ * @param txCbor transaction in CBOR hex format
19
+ * @returns {string} transaction hash (64 character hex string)
20
+ * @throws {Error} if CBOR is invalid or transaction hash cannot be extracted
21
+ */
22
+ export declare function getTxHashFromCbor(txCbor: string): string;
23
+ /**
24
+ * Maps builder errors to typed BackendErrors
25
+ * Used by the Buildooor transaction builder.
26
+ * When no assetUnit is provided, extracts it from the error message if possible
27
+ * (e.g. "not enough <policyId.assetName>"), falling back to 'lovelace'.
28
+ * @param err Error from builder
29
+ * @param assetUnit Optional asset unit override (auto-extracted from error message if omitted)
30
+ * @throws {InsufficientFundsError} if error is related to insufficient funds
31
+ * @throws {Error} original error if not mappable
32
+ */
33
+ export declare function mapBuilderError(err: unknown, assetUnit?: string): never;
34
+ /**
35
+ * Parse asset unit string into policyId and assetName
36
+ * Format: policyId (56 hex chars) + assetName (remaining hex)
37
+ * Used by the Buildooor transaction builder
38
+ */
39
+ export declare function parseAssetUnit(assetUnit: string): {
40
+ policyId: string;
41
+ assetName: string;
42
+ };
43
+ /**
44
+ * Convert JSON value to Buildooor PlutusData (Data type).
45
+ * Accepts both cardano-cli format ("constructor") and Buildooor format ("constr").
46
+ * - { "int": 42 } → DataI(42)
47
+ * - { "bytes": "deadbeef" } → DataB("deadbeef")
48
+ * - { "list": [...] } → DataList([...])
49
+ * - { "map": [{ "k": ..., "v": ... }] } → DataMap([...])
50
+ * - { "constructor": 0, "fields": [...] } or { "constr": 0, "fields": [...] } → DataConstr(0, [...])
51
+ * @param json JSON value representing PlutusData
52
+ * @returns Buildooor Data object
53
+ */
54
+ export declare function jsonToPlutusData(json: JSONValue): Data;
55
+ /**
56
+ * Normalize a backend-provided inline datum to canonical CBOR hex.
57
+ *
58
+ * Backends report inline datums in different shapes:
59
+ * - Blockfrost: hex CBOR string (e.g. "19a6aa")
60
+ * - Koios (_extended): wrapper { bytes: "<hex>", value: { ...PlutusData JSON... } }
61
+ * - Koios (sometimes empty): { bytes: null, value: null }
62
+ * - Some endpoints: raw PlutusData JSON ({ "int": 42 } / { "constructor": 0, "fields": [] })
63
+ *
64
+ * Returns hex CBOR (lowercase) or null. Defensive: returns null on unknown
65
+ * shapes rather than throwing — backend mappers must not crash on malformed data.
66
+ */
67
+ export declare function inlineDatumToHex(datum: unknown): string | null;
68
+ /**
69
+ * Apply parameters to a parameterized PlutusV3 script (CBOR-wrapped flat UPLC).
70
+ * Each parameter is applied as a successive UPLC Application node wrapping the program body.
71
+ * @param scriptHex CBOR hex of the unapplied Plutus script (as output by Aiken/Plutus compilers)
72
+ * @param params Array of PlutusData JSON objects (DetailedSchema format) to apply in order
73
+ * @returns CBOR hex of the applied script (ready for transaction building)
74
+ */
75
+ export declare function applyScriptParameters(scriptHex: string, params: JSONValue[]): string;
76
+ //# sourceMappingURL=tx-build-helper.d.ts.map
@@ -1,51 +1,17 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.getLovelace = getLovelace;
37
4
  exports.assertAdaOnly = assertAdaOnly;
38
5
  exports.getTxHashFromCbor = getTxHashFromCbor;
39
6
  exports.mapBuilderError = mapBuilderError;
40
7
  exports.parseAssetUnit = parseAssetUnit;
41
- exports.parseOptionalJson = parseOptionalJson;
42
- exports.parseOptionalJsonArray = parseOptionalJsonArray;
43
8
  exports.jsonToPlutusData = jsonToPlutusData;
44
9
  exports.inlineDatumToHex = inlineDatumToHex;
45
10
  exports.applyScriptParameters = applyScriptParameters;
46
- const CSL = __importStar(require("@emurgo/cardano-serialization-lib-nodejs"));
47
11
  const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
12
+ const crypto_1 = require("@harmoniclabs/crypto");
48
13
  const errors_1 = require("./errors");
14
+ const error_codes_1 = require("./error-codes");
49
15
  const plutus_data_1 = require("@harmoniclabs/plutus-data");
50
16
  const uplc_1 = require("@harmoniclabs/uplc");
51
17
  const cbor_1 = require("@harmoniclabs/cbor");
@@ -80,24 +46,34 @@ function getTxHashFromCbor(txCbor) {
80
46
  if (!txCbor || typeof txCbor !== 'string') {
81
47
  throw new Error('Invalid input: txCbor must be a non-empty string');
82
48
  }
83
- // Validate hex format
84
- if (!/^[a-fA-F0-9]+$/.test(txCbor)) {
49
+ // Validate hex format. Require even length — a hex byte string encodes whole bytes,
50
+ // so an odd-length string is malformed and would otherwise surface as a confusing
51
+ // "Failed to parse transaction CBOR" from fromHex/Cbor.parse rather than a clear
52
+ // input-validation error.
53
+ if (!/^[a-fA-F0-9]+$/.test(txCbor) || txCbor.length % 2 !== 0) {
85
54
  throw new Error('Invalid input: txCbor must be a valid hex string');
86
55
  }
87
- // Use CSL.FixedTransaction: preserves original CBOR bytes (deterministic hash)
88
- // and avoids the harmoniclabs AuxiliaryData.fromCbor bug on metadata-only aux_data.
56
+ // Compute blake2b-256 over the ORIGINAL transaction-body bytes (CBOR array index 0).
57
+ // subCborRef.toBuffer() returns the exact bytes as received — no re-serialization, so
58
+ // the hash matches what was signed. Working at the raw-CBOR level also sidesteps the
59
+ // @harmoniclabs/cardano-ledger-ts AuxiliaryData.fromCbor bug on metadata-only aux_data
60
+ // (we never instantiate the high-level Tx type).
89
61
  try {
90
- const txBytes = Buffer.from(txCbor, 'hex');
91
- const fixedTx = CSL.FixedTransaction.from_bytes(txBytes);
92
- return Buffer.from(fixedTx.transaction_hash().to_bytes()).toString('hex');
62
+ const tx = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(txCbor));
63
+ if (!(tx instanceof cbor_1.CborArray) || tx.array.length < 1 || !tx.array[0].subCborRef) {
64
+ throw new Error('not a transaction');
65
+ }
66
+ const bodyBytes = tx.array[0].subCborRef.toBuffer();
67
+ return (0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_256)(bodyBytes));
93
68
  }
94
- catch {
95
- throw new Error('Failed to parse transaction CBOR');
69
+ catch (err) {
70
+ // typed 400 — a plain Error here surfaced as a 500 to the consumer
71
+ throw new errors_1.TransactionValidationError('Failed to parse transaction CBOR', err, error_codes_1.ERROR_CODES.TX_PARSE_FAILED);
96
72
  }
97
73
  }
98
74
  /**
99
75
  * Maps builder errors to typed BackendErrors
100
- * Shared between CSL and Buildooor transaction builders.
76
+ * Used by the Buildooor transaction builder.
101
77
  * When no assetUnit is provided, extracts it from the error message if possible
102
78
  * (e.g. "not enough <policyId.assetName>"), falling back to 'lovelace'.
103
79
  * @param err Error from builder
@@ -106,6 +82,12 @@ function getTxHashFromCbor(txCbor) {
106
82
  * @throws {Error} original error if not mappable
107
83
  */
108
84
  function mapBuilderError(err, assetUnit) {
85
+ // Already-typed errors carry their own status + payload (amounts, asset units,
86
+ // validation details) — re-wrapping them into a generic InsufficientFundsError
87
+ // because their MESSAGE happens to contain "balance"/"insufficient" destroys that.
88
+ if (err instanceof errors_1.BackendError) {
89
+ throw err;
90
+ }
109
91
  const errObj = err;
110
92
  const msg = (errObj?.message || errObj?.toString?.() || String(err)).toLowerCase();
111
93
  if (msg.includes('not enough') ||
@@ -122,7 +104,7 @@ function mapBuilderError(err, assetUnit) {
122
104
  /**
123
105
  * Parse asset unit string into policyId and assetName
124
106
  * Format: policyId (56 hex chars) + assetName (remaining hex)
125
- * Shared between CSL and Buildooor transaction builders
107
+ * Used by the Buildooor transaction builder
126
108
  */
127
109
  function parseAssetUnit(assetUnit) {
128
110
  return {
@@ -130,39 +112,6 @@ function parseAssetUnit(assetUnit) {
130
112
  assetName: assetUnit.substring(56)
131
113
  };
132
114
  }
133
- /**
134
- * Parse optional JSON string, returning undefined if not provided.
135
- * Throws with a descriptive message on parse failure.
136
- */
137
- function parseOptionalJson(json, fieldName) {
138
- if (!json)
139
- return undefined;
140
- try {
141
- return JSON.parse(json);
142
- }
143
- catch {
144
- throw new Error(`${fieldName} must be valid JSON`);
145
- }
146
- }
147
- /**
148
- * Parse optional JSON string that must be an array.
149
- * Returns undefined if not provided, throws on invalid JSON or non-array.
150
- */
151
- function parseOptionalJsonArray(json, fieldName) {
152
- if (!json)
153
- return undefined;
154
- let parsed;
155
- try {
156
- parsed = JSON.parse(json);
157
- }
158
- catch {
159
- throw new Error(`${fieldName} must be valid JSON`);
160
- }
161
- if (!Array.isArray(parsed)) {
162
- throw new Error(`${fieldName} must be a JSON array`);
163
- }
164
- return parsed;
165
- }
166
115
  /** Allowed keys in PlutusData JSON — strip anything else for defense-in-depth */
167
116
  const PLUTUS_DATA_ALLOWED_KEYS = new Set([
168
117
  'constructor', 'constr', 'fields', 'int', 'bytes', 'list', 'map', 'k', 'v'