@odatano/core 1.8.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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/CardanoSignService/index.d.ts +49 -0
  6. package/@cds-models/CardanoSignService/index.d.ts.map +1 -1
  7. package/@cds-models/CardanoSignService/index.js.map +1 -1
  8. package/@cds-models/CardanoSignService/index.ts +41 -0
  9. package/@cds-models/odatano/cardano/index.d.ts +70 -46
  10. package/@cds-models/odatano/cardano/index.d.ts.map +1 -1
  11. package/@cds-models/odatano/cardano/index.js +2 -2
  12. package/@cds-models/odatano/cardano/index.js.map +1 -1
  13. package/@cds-models/odatano/cardano/index.ts +13 -13
  14. package/db/schema.cds +18 -18
  15. package/db/types.cds +3 -3
  16. package/package.json +16 -2
  17. package/src/index.d.ts +29 -0
  18. package/src/index.js +1 -0
  19. package/src/plugin.d.ts +2 -0
  20. package/src/plugin.js +6 -0
  21. package/srv/blockchain/backends/blockfrost-backend.d.ts +155 -0
  22. package/srv/blockchain/backends/blockfrost-backend.js +19 -8
  23. package/srv/blockchain/backends/cardano-backend.d.ts +182 -0
  24. package/srv/blockchain/backends/koios-backend.d.ts +171 -0
  25. package/srv/blockchain/backends/koios-backend.js +69 -27
  26. package/srv/blockchain/backends/ogmios-backend.d.ts +188 -0
  27. package/srv/blockchain/backends/ogmios-backend.js +175 -108
  28. package/srv/blockchain/cardano-client.d.ts +279 -0
  29. package/srv/blockchain/cardano-client.js +134 -33
  30. package/srv/blockchain/cardano-indexer.d.ts +330 -0
  31. package/srv/blockchain/cardano-indexer.js +51 -8
  32. package/srv/blockchain/cardano-tx-builder.d.ts +113 -0
  33. package/srv/blockchain/cardano-tx-builder.js +61 -54
  34. package/srv/blockchain/circuit-breaker.d.ts +37 -0
  35. package/srv/blockchain/circuit-breaker.js +11 -2
  36. package/srv/blockchain/request-coalescer.d.ts +23 -0
  37. package/srv/blockchain/signing/cose-verifier.d.ts +34 -0
  38. package/srv/blockchain/signing/cose-verifier.js +128 -0
  39. package/srv/blockchain/signing/external-signer.d.ts +146 -0
  40. package/srv/blockchain/signing/external-signer.js +23 -0
  41. package/srv/blockchain/signing/hsm-signer.d.ts +74 -0
  42. package/srv/blockchain/signing/hsm-signer.js +20 -5
  43. package/srv/blockchain/signing/signature-verifier.d.ts +56 -0
  44. package/srv/blockchain/signing/signature-verifier.js +11 -2
  45. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +236 -0
  46. package/srv/blockchain/transaction-building/buildooor-tx.js +626 -187
  47. package/srv/blockchain/transaction-building/cardano-tx.d.ts +47 -0
  48. package/srv/cardano-service.cds +23 -3
  49. package/srv/cardano-service.d.ts +2 -0
  50. package/srv/cardano-service.js +25 -5
  51. package/srv/cardano-sign-service.cds +25 -0
  52. package/srv/cardano-sign-service.d.ts +2 -0
  53. package/srv/cardano-sign-service.js +243 -131
  54. package/srv/cardano-tx-service.d.ts +12 -0
  55. package/srv/cardano-tx-service.js +152 -110
  56. package/srv/cbor/index.d.ts +2 -0
  57. package/srv/cbor/parse.d.ts +64 -0
  58. package/srv/server.d.ts +90 -0
  59. package/srv/server.js +34 -9
  60. package/srv/utils/backend-request-handler.d.ts +20 -0
  61. package/srv/utils/const.d.ts +183 -0
  62. package/srv/utils/const.js +13 -6
  63. package/srv/utils/error-codes.d.ts +79 -0
  64. package/srv/utils/errors.d.ts +259 -0
  65. package/srv/utils/errors.js +22 -7
  66. package/srv/utils/mappers.d.ts +260 -0
  67. package/srv/utils/mappers.js +52 -17
  68. package/srv/utils/network-context.d.ts +6 -0
  69. package/srv/utils/network-context.js +27 -0
  70. package/srv/utils/plutus-placeholders.d.ts +35 -0
  71. package/srv/utils/plutus-placeholders.js +5 -15
  72. package/srv/utils/signing-helper.d.ts +23 -0
  73. package/srv/utils/signing-helper.js +5 -2
  74. package/srv/utils/tx-build-helper.d.ts +76 -0
  75. package/srv/utils/tx-build-helper.js +10 -37
  76. package/srv/utils/types.d.ts +653 -0
  77. package/srv/utils/validators.d.ts +145 -0
  78. package/srv/utils/validators.js +41 -19
  79. package/@cds-models/CardanoWatcherAdminService/index.js +0 -109
  80. package/@cds-models/CardanoWatcherAdminService/index.js.map +0 -1
  81. package/@cds-models/CardanoWatcherAdminService/index.ts +0 -263
  82. package/@cds-models/cds/outbox/index.js.map +0 -1
  83. package/@cds-models/cds/xt/MTXServices/index.js +0 -8
  84. package/@cds-models/cds/xt/MTXServices/index.js.map +0 -1
  85. package/@cds-models/cds/xt/MTXServices/index.ts +0 -4
  86. package/@cds-models/odatano/reeve/index.js +0 -77
  87. package/@cds-models/odatano/reeve/index.js.map +0 -1
  88. package/@cds-models/odatano/reeve/index.ts +0 -57
  89. package/@cds-models/odatano/transactions/index.js +0 -55
  90. package/@cds-models/odatano/transactions/index.js.map +0 -1
  91. package/@cds-models/odatano/transactions/index.ts +0 -18
  92. package/@cds-models/odatano/watch/index.js +0 -114
  93. package/@cds-models/odatano/watch/index.js.map +0 -1
  94. package/@cds-models/odatano/watch/index.ts +0 -110
  95. package/config/preview/cardano-node/alonzo-genesis.json +0 -196
  96. package/config/preview/cardano-node/byron-genesis.json +0 -117
  97. package/config/preview/cardano-node/config.json +0 -117
  98. package/config/preview/cardano-node/conway-genesis.json +0 -297
  99. package/config/preview/cardano-node/peer-snapshot.json +0 -890
  100. package/config/preview/cardano-node/shelley-genesis.json +0 -68
  101. package/config/preview/cardano-node/topology.json +0 -24
  102. package/output/sora/iter0_base.json +0 -32
  103. package/output/sora/iter0_base.mp4 +0 -0
  104. package/output/sora/logo_ref_1280x720.png +0 -0
  105. package/output/sora/odatano_full_logo_sky_ref_1280x720.png +0 -0
  106. package/output/sora/odatano_full_logo_transparent.png +0 -0
  107. package/output/sora/odatano_full_logo_transparent_dark.png +0 -0
  108. package/output/sora/odatano_full_logo_v4_8s.json +0 -32
  109. package/output/sora/odatano_full_logo_v4_8s.mp4 +0 -0
  110. package/output/sora/odatano_full_logo_v5_create.json +0 -15
  111. package/output/sora/odatano_full_logo_v5_fixes.json +0 -15
  112. package/output/sora/odatano_full_logo_v5_fixes.mp4 +0 -0
  113. package/output/sora/odatano_logo_v1.json +0 -32
  114. package/output/sora/odatano_logo_v1.mp4 +0 -0
  115. package/output/sora/odatano_o_only_clean.png +0 -0
  116. package/output/sora/odatano_o_sky_ref_1280x720.png +0 -0
  117. package/output/sora/odatano_o_sky_v2_8s.json +0 -32
  118. package/output/sora/odatano_o_sky_v2_8s.mp4 +0 -0
  119. package/output/sora/odatano_o_sky_v3_create.json +0 -15
  120. package/output/sora/odatano_o_sky_v3_splash_text.json +0 -15
  121. package/output/sora/odatano_o_sky_v3_splash_text.mp4 +0 -0
  122. package/output/sora/odatano_v6_composite_exact_logo.mp4 +0 -0
  123. package/output/sora/odatano_v6_composite_exact_logo_clean.mp4 +0 -0
  124. package/output/sora/odatano_v6_composite_exact_logo_final.mp4 +0 -0
  125. package/output/sora/odatano_v6_endframe.jpg +0 -0
  126. package/output/sora/odatano_v6_endframe_clean.jpg +0 -0
  127. package/output/sora/odatano_v6_endframe_final.jpg +0 -0
  128. package/output/sora/odatano_v7_1_earlylogo_fadeoldtext.mp4 +0 -0
  129. package/output/sora/odatano_v7_1_end.jpg +0 -0
  130. package/output/sora/odatano_v7_1_transition.jpg +0 -0
  131. package/output/sora/odatano_v7_2_original2d_keep_sky.mp4 +0 -0
  132. package/output/sora/odatano_v7_endframe_nobg.jpg +0 -0
  133. package/output/sora/odatano_v7_endframe_nobg_cleanend.jpg +0 -0
  134. package/output/sora/odatano_v7_spin_splash_logo_nobg.mp4 +0 -0
  135. package/output/sora/odatano_v7_spin_splash_logo_nobg_cleanend.mp4 +0 -0
  136. package/prod.mtaext +0 -17
  137. package/prod.mtaext.example +0 -27
  138. package/review.md +0 -42
  139. package/src/index.d.ts.map +0 -1
  140. package/src/index.js.map +0 -1
  141. package/src/plugin.d.ts.map +0 -1
  142. package/src/plugin.js.map +0 -1
  143. package/srv/blockchain/backends/blockfrost-backend.d.ts.map +0 -1
  144. package/srv/blockchain/backends/blockfrost-backend.js.map +0 -1
  145. package/srv/blockchain/backends/cardano-backend.d.ts.map +0 -1
  146. package/srv/blockchain/backends/cardano-backend.js.map +0 -1
  147. package/srv/blockchain/backends/koios-backend.d.ts.map +0 -1
  148. package/srv/blockchain/backends/koios-backend.js.map +0 -1
  149. package/srv/blockchain/backends/ogmios-backend.d.ts.map +0 -1
  150. package/srv/blockchain/backends/ogmios-backend.js.map +0 -1
  151. package/srv/blockchain/cardano-client.d.ts.map +0 -1
  152. package/srv/blockchain/cardano-client.js.map +0 -1
  153. package/srv/blockchain/cardano-indexer.d.ts.map +0 -1
  154. package/srv/blockchain/cardano-indexer.js.map +0 -1
  155. package/srv/blockchain/cardano-tx-builder.d.ts.map +0 -1
  156. package/srv/blockchain/cardano-tx-builder.js.map +0 -1
  157. package/srv/blockchain/circuit-breaker.d.ts.map +0 -1
  158. package/srv/blockchain/circuit-breaker.js.map +0 -1
  159. package/srv/blockchain/request-coalescer.d.ts.map +0 -1
  160. package/srv/blockchain/request-coalescer.js.map +0 -1
  161. package/srv/blockchain/signing/external-signer.d.ts.map +0 -1
  162. package/srv/blockchain/signing/external-signer.js.map +0 -1
  163. package/srv/blockchain/signing/hsm-signer.d.ts.map +0 -1
  164. package/srv/blockchain/signing/hsm-signer.js.map +0 -1
  165. package/srv/blockchain/signing/signature-verifier.d.ts.map +0 -1
  166. package/srv/blockchain/signing/signature-verifier.js.map +0 -1
  167. package/srv/blockchain/transaction-building/buildooor-tx.d.ts.map +0 -1
  168. package/srv/blockchain/transaction-building/buildooor-tx.js.map +0 -1
  169. package/srv/blockchain/transaction-building/cardano-tx.d.ts.map +0 -1
  170. package/srv/blockchain/transaction-building/cardano-tx.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,14 @@ 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
+ // Read the clock ONCE — separate Date.now() calls for validFrom/validTo let the
483
+ // millisecond tick over between them, making the span max_age+1.
484
+ const now = Date.now();
485
+ const validFrom = new Date(now).toISOString();
486
+ const validTo = new Date(now + max_age).toISOString();
468
487
  return {
469
488
  poolId: providerPoolData.poolId,
470
489
  vrfKeyHash: providerPoolData.vrfKeyHash,
@@ -480,6 +499,8 @@ function mapPool(providerPoolData) {
480
499
  margin: Number(providerPoolData.margin),
481
500
  fixedCost: providerPoolData.fixedCost,
482
501
  rewardAccount: providerPoolData.rewardAccount,
502
+ validFrom,
503
+ validTo,
483
504
  };
484
505
  }
485
506
  /**
@@ -492,8 +513,10 @@ function mapPool(providerPoolData) {
492
513
  * @returns {AssetRow} mapped asset row
493
514
  */
494
515
  function mapAsset(providerAssetInfo, max_age) {
495
- const validFrom = new Date().toISOString();
496
- const validTo = new Date(Date.now() + max_age).toISOString();
516
+ // Read the clock once so validTo - validFrom is exactly max_age (see mapPool).
517
+ const now = Date.now();
518
+ const validFrom = new Date(now).toISOString();
519
+ const validTo = new Date(now + max_age).toISOString();
497
520
  return {
498
521
  unit: providerAssetInfo.unit,
499
522
  policyId: providerAssetInfo.policyId,
@@ -539,7 +562,13 @@ function mapAssetHistory(entries) {
539
562
  * @param providerDrepData drep data from provider
540
563
  * @returns {DrepRow} mapped drep row
541
564
  */
542
- function mapDrep(providerDrepData) {
565
+ function mapDrep(providerDrepData, max_age) {
566
+ // temporal stamping: amount/retired/expired drift over time → slice expires
567
+ // after max_age so the index-on-miss read re-fetches fresh state.
568
+ // Read the clock once so the span is exactly max_age (see mapPool).
569
+ const now = Date.now();
570
+ const validFrom = new Date(now).toISOString();
571
+ const validTo = new Date(now + max_age).toISOString();
543
572
  return {
544
573
  drepId: providerDrepData.drepId,
545
574
  hex: providerDrepData.hex,
@@ -548,6 +577,8 @@ function mapDrep(providerDrepData) {
548
577
  lastActiveEpoch: providerDrepData.lastActiveEpoch,
549
578
  retired: Boolean(providerDrepData.retired),
550
579
  expired: Boolean(providerDrepData.expired),
580
+ validFrom,
581
+ validTo,
551
582
  };
552
583
  }
553
584
  /**
@@ -557,8 +588,10 @@ function mapDrep(providerDrepData) {
557
588
  * @returns {AccountRow} mapped account row
558
589
  */
559
590
  function mapAccount(providerAccountData, max_age) {
560
- const validFrom = new Date().toISOString();
561
- const validTo = new Date(Date.now() + max_age).toISOString();
591
+ // Read the clock once so validTo - validFrom is exactly max_age (see mapPool).
592
+ const now = Date.now();
593
+ const validFrom = new Date(now).toISOString();
594
+ const validTo = new Date(now + max_age).toISOString();
562
595
  return {
563
596
  validFrom: validFrom,
564
597
  validTo: validTo,
@@ -599,9 +632,11 @@ function mapError(req, err, ctx) {
599
632
  */
600
633
  function mapBuildResult(txbuildResult, max_age) {
601
634
  const buildId = cds_1.default.utils.uuid();
602
- const now = Math.floor(Date.now() / 1000);
603
- const validFrom = new Date().toISOString();
604
- const validTo = new Date(Date.now() + max_age).toISOString();
635
+ // Read the clock once so validTo - validFrom is exactly max_age (see mapPool).
636
+ const nowMs = Date.now();
637
+ const now = Math.floor(nowMs / 1000);
638
+ const validFrom = new Date(nowMs).toISOString();
639
+ const validTo = new Date(nowMs + max_age).toISOString();
605
640
  const hasInputs = Array.isArray(txbuildResult.inputs) && txbuildResult.inputs.length > 0;
606
641
  const hasOutputs = Array.isArray(txbuildResult.outputs) && txbuildResult.outputs.length > 0;
607
642
  return {
@@ -0,0 +1,6 @@
1
+ import type { Network } from '../blockchain/cardano-client';
2
+ /** Record the active network. Pass `null` to clear (shutdown/reset). */
3
+ export declare function setActiveNetwork(n: Network | null): void;
4
+ /** The active network, or `null` if the app context has not been initialized. */
5
+ export declare function getActiveNetwork(): Network | null;
6
+ //# sourceMappingURL=network-context.d.ts.map
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setActiveNetwork = setActiveNetwork;
4
+ exports.getActiveNetwork = getActiveNetwork;
5
+ /**
6
+ * Module-scoped holder for the active Cardano network.
7
+ *
8
+ * This is a deliberately tiny *leaf* module: it has no runtime dependencies (the
9
+ * `Network` import is type-only and erased at compile), so leaf utilities such as
10
+ * `validators.ts` can read the configured network WITHOUT importing `server.ts`
11
+ * — which would otherwise drag the whole server → indexer graph (and its
12
+ * module-load `cds.ql` access) into every consumer.
13
+ *
14
+ * Set during bootstrap by `initializeAppContext` and cleared on shutdown. Reads
15
+ * before bootstrap return `null`; callers treat that as "not ready" rather than
16
+ * throwing (e.g. network-aware validators return `false`).
17
+ */
18
+ let active = null;
19
+ /** Record the active network. Pass `null` to clear (shutdown/reset). */
20
+ function setActiveNetwork(n) {
21
+ active = n;
22
+ }
23
+ /** The active network, or `null` if the app context has not been initialized. */
24
+ function getActiveNetwork() {
25
+ return active;
26
+ }
27
+ //# sourceMappingURL=network-context.js.map
@@ -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,14 +3,15 @@ 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.
@@ -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,16 +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
- * Utility detector for __INPUT_IDX__ placeholders in a PlutusData JSON tree.
77
- */
78
- function containsIndexPlaceholder(node) {
79
- if (node === null || typeof node !== 'object') {
80
- return typeof node === 'string' && exports.INPUT_IDX_REGEX.test(node);
81
- }
82
- if (Array.isArray(node))
83
- return node.some(containsIndexPlaceholder);
84
- return Object.values(node).some(containsIndexPlaceholder);
85
- }
86
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
@@ -61,8 +61,11 @@ function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
61
61
  else {
62
62
  throw new errors_1.TransactionValidationError('Witness set must be CBOR map per Cardano spec');
63
63
  }
64
- // Re-encode the tx array, preserving encoding metadata on body and all witness values.
65
- // 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.
66
69
  const signedTxCbor = (0, uint8array_utils_1.toHex)(cbor_1.Cbor.encode(new cbor_1.CborArray(txObj.array, { indefinite: txObj.indefinite })));
67
70
  logger.info({
68
71
  unsignedTxLength: unsignedTxCbor.length,
@@ -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
@@ -5,14 +5,13 @@ exports.assertAdaOnly = assertAdaOnly;
5
5
  exports.getTxHashFromCbor = getTxHashFromCbor;
6
6
  exports.mapBuilderError = mapBuilderError;
7
7
  exports.parseAssetUnit = parseAssetUnit;
8
- exports.parseOptionalJson = parseOptionalJson;
9
- exports.parseOptionalJsonArray = parseOptionalJsonArray;
10
8
  exports.jsonToPlutusData = jsonToPlutusData;
11
9
  exports.inlineDatumToHex = inlineDatumToHex;
12
10
  exports.applyScriptParameters = applyScriptParameters;
13
11
  const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
14
12
  const crypto_1 = require("@harmoniclabs/crypto");
15
13
  const errors_1 = require("./errors");
14
+ const error_codes_1 = require("./error-codes");
16
15
  const plutus_data_1 = require("@harmoniclabs/plutus-data");
17
16
  const uplc_1 = require("@harmoniclabs/uplc");
18
17
  const cbor_1 = require("@harmoniclabs/cbor");
@@ -67,8 +66,9 @@ function getTxHashFromCbor(txCbor) {
67
66
  const bodyBytes = tx.array[0].subCborRef.toBuffer();
68
67
  return (0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_256)(bodyBytes));
69
68
  }
70
- catch {
71
- 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);
72
72
  }
73
73
  }
74
74
  /**
@@ -82,6 +82,12 @@ function getTxHashFromCbor(txCbor) {
82
82
  * @throws {Error} original error if not mappable
83
83
  */
84
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
+ }
85
91
  const errObj = err;
86
92
  const msg = (errObj?.message || errObj?.toString?.() || String(err)).toLowerCase();
87
93
  if (msg.includes('not enough') ||
@@ -106,39 +112,6 @@ function parseAssetUnit(assetUnit) {
106
112
  assetName: assetUnit.substring(56)
107
113
  };
108
114
  }
109
- /**
110
- * Parse optional JSON string, returning undefined if not provided.
111
- * Throws with a descriptive message on parse failure.
112
- */
113
- function parseOptionalJson(json, fieldName) {
114
- if (!json)
115
- return undefined;
116
- try {
117
- return JSON.parse(json);
118
- }
119
- catch {
120
- throw new Error(`${fieldName} must be valid JSON`);
121
- }
122
- }
123
- /**
124
- * Parse optional JSON string that must be an array.
125
- * Returns undefined if not provided, throws on invalid JSON or non-array.
126
- */
127
- function parseOptionalJsonArray(json, fieldName) {
128
- if (!json)
129
- return undefined;
130
- let parsed;
131
- try {
132
- parsed = JSON.parse(json);
133
- }
134
- catch {
135
- throw new Error(`${fieldName} must be valid JSON`);
136
- }
137
- if (!Array.isArray(parsed)) {
138
- throw new Error(`${fieldName} must be a JSON array`);
139
- }
140
- return parsed;
141
- }
142
115
  /** Allowed keys in PlutusData JSON — strip anything else for defense-in-depth */
143
116
  const PLUTUS_DATA_ALLOWED_KEYS = new Set([
144
117
  'constructor', 'constr', 'fields', 'int', 'bytes', 'list', 'map', 'k', 'v'