@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
@@ -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,10 +6,65 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
6
  exports.SignatureVerifier = void 0;
40
7
  exports.getSignatureVerifier = getSignatureVerifier;
41
8
  const cds_1 = __importDefault(require("@sap/cds"));
42
- const CSL = __importStar(require("@emurgo/cardano-serialization-lib-nodejs"));
9
+ const cbor_1 = require("@harmoniclabs/cbor");
10
+ const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
11
+ const crypto_1 = require("@harmoniclabs/crypto");
43
12
  const errors_1 = require("../../utils/errors");
44
13
  const error_codes_1 = require("../../utils/error-codes");
45
14
  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. Operating at the raw-CBOR level also avoids
19
+ * the @harmoniclabs/cardano-ledger-ts AuxiliaryData.fromCbor bug on metadata-only aux_data.
20
+ */
21
+ function computeBodyHash(txBytes) {
22
+ const tx = cbor_1.Cbor.parse(txBytes);
23
+ if (!(tx instanceof cbor_1.CborArray) || tx.array.length < 1 || !tx.array[0].subCborRef) {
24
+ throw new Error('Invalid transaction CBOR: missing body');
25
+ }
26
+ return (0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_256)(tx.array[0].subCborRef.toBuffer()));
27
+ }
28
+ /**
29
+ * Extract vkey witnesses (raw public key + signature bytes) from a transaction's
30
+ * witness set (CBOR array index 1, map key 0). Conway wraps the witness array in CBOR
31
+ * tag 258 (set) — unwrapped here. Returns [] when the tx has no vkey witnesses.
32
+ */
33
+ function extractVkeyWitnesses(txBytes) {
34
+ const tx = cbor_1.Cbor.parse(txBytes);
35
+ if (!(tx instanceof cbor_1.CborArray) || !(tx.array[1] instanceof cbor_1.CborMap))
36
+ return [];
37
+ const entry = tx.array[1].map.find(e => e.k instanceof cbor_1.CborUInt && Number(e.k.num) === 0);
38
+ if (!entry)
39
+ return [];
40
+ let arr = entry.v;
41
+ if (arr instanceof cbor_1.CborTag)
42
+ arr = arr.data;
43
+ if (!(arr instanceof cbor_1.CborArray))
44
+ return [];
45
+ // Parse defensively: a malformed witness entry (wrong shape or non-bytes members)
46
+ // would otherwise throw a TypeError and surface as an opaque internal error. Skip
47
+ // any entry that isn't a [vkey, signature] pair of byte strings.
48
+ const witnesses = [];
49
+ let skipped = 0;
50
+ for (const pair of arr.array) {
51
+ if (!(pair instanceof cbor_1.CborArray) || pair.array.length !== 2) {
52
+ skipped++;
53
+ continue;
54
+ }
55
+ const [vk, sg] = pair.array;
56
+ if (!(vk instanceof cbor_1.CborBytes) || !(sg instanceof cbor_1.CborBytes)) {
57
+ skipped++;
58
+ continue;
59
+ }
60
+ witnesses.push({ pubKey: vk.bytes, signature: sg.bytes });
61
+ }
62
+ if (skipped > 0) {
63
+ // not fatal, but a malformed witness in a signed tx is suspicious — surface it
64
+ logger.warn(`Skipped ${skipped} malformed vkey witness entr${skipped === 1 ? 'y' : 'ies'} while verifying (expected [vkey, signature] byte pairs)`);
65
+ }
66
+ return witnesses;
67
+ }
46
68
  /**
47
69
  * SignatureVerifier - Verifies transaction signatures without accessing private keys
48
70
  *
@@ -70,18 +92,14 @@ class SignatureVerifier {
70
92
  warnings: [],
71
93
  };
72
94
  try {
73
- // Compute the body hash via CSL.FixedTransaction, which preserves the
74
- // original CBOR bytes and avoids re-serialization. This path is immune
75
- // to the @harmoniclabs/cardano-ledger-ts@0.5.x AuxiliaryData.fromCbor bug
76
- // that rejects metadata-only Conway aux_data (all four script-array fields
77
- // are required non-optional even though the constructor handles undefined).
78
- const txBytes = Buffer.from(signedTxCbor, 'hex');
79
- const fixedTx = CSL.FixedTransaction.from_bytes(txBytes);
80
- const computedHash = Buffer.from(fixedTx.transaction_hash().to_bytes()).toString('hex');
95
+ // Compute the body hash over the original CBOR body bytes (no re-serialization),
96
+ // matching exactly what was signed. Raw-CBOR parsing is immune to the
97
+ // @harmoniclabs/cardano-ledger-ts AuxiliaryData.fromCbor bug that rejects
98
+ // metadata-only Conway aux_data.
99
+ const txBytes = (0, uint8array_utils_1.fromHex)(signedTxCbor);
100
+ const computedHash = computeBodyHash(txBytes);
81
101
  result.txBodyHash = computedHash;
82
- logger.debug(`Computed transaction body hash (CSL FixedTransaction): ${computedHash}`);
83
- // Parse with CSL.Transaction for witness extraction and Ed25519 verification.
84
- const tx = CSL.Transaction.from_bytes(txBytes);
102
+ logger.debug(`Computed transaction body hash: ${computedHash}`);
85
103
  // verify transaction body hash matches expected
86
104
  if (options.expectedTxBodyHash) {
87
105
  if (computedHash.toLowerCase() !== options.expectedTxBodyHash.toLowerCase()) {
@@ -91,17 +109,13 @@ class SignatureVerifier {
91
109
  }
92
110
  logger.debug('Transaction body hash verified successfully');
93
111
  }
94
- // Extract witness set
95
- const witnessSet = tx.witness_set();
96
- const vkeyWitnesses = witnessSet.vkeys();
97
- if (vkeyWitnesses) {
98
- result.witnessCount = vkeyWitnesses.len();
99
- // extract signer public key hashes
100
- for (let i = 0; i < vkeyWitnesses.len(); i++) {
101
- const witness = vkeyWitnesses.get(i);
102
- const vkey = witness.vkey();
103
- const pubKeyHash = vkey.public_key().hash();
104
- result.signerKeyHashes.push(Buffer.from(pubKeyHash.to_bytes()).toString('hex'));
112
+ // Extract vkey witnesses (raw pubkey + signature bytes)
113
+ const vkeyWitnesses = extractVkeyWitnesses(txBytes);
114
+ result.witnessCount = vkeyWitnesses.length;
115
+ if (vkeyWitnesses.length > 0) {
116
+ // signer key hash = blake2b-224 of the Ed25519 public key
117
+ for (const w of vkeyWitnesses) {
118
+ result.signerKeyHashes.push((0, uint8array_utils_1.toHex)((0, crypto_1.blake2b_224)(w.pubKey)));
105
119
  }
106
120
  logger.debug(`Found ${result.witnessCount} witness(es): ${result.signerKeyHashes.join(', ')}`);
107
121
  }
@@ -121,16 +135,12 @@ class SignatureVerifier {
121
135
  return result;
122
136
  }
123
137
  }
124
- // verify each signature cryptographically
125
- if (vkeyWitnesses && vkeyWitnesses.len() > 0) {
126
- const bodyHash = CSL.TransactionHash.from_bytes(Buffer.from(computedHash, 'hex'));
127
- for (let i = 0; i < vkeyWitnesses.len(); i++) {
128
- const witness = vkeyWitnesses.get(i);
129
- const vkey = witness.vkey();
130
- const signature = witness.signature();
131
- const publicKey = vkey.public_key();
132
- // verify the signature against the transaction body hash
133
- const isValidSig = publicKey.verify(bodyHash.to_bytes(), signature);
138
+ // verify each signature cryptographically against the transaction body hash
139
+ if (vkeyWitnesses.length > 0) {
140
+ const bodyHashBytes = (0, uint8array_utils_1.fromHex)(computedHash);
141
+ for (let i = 0; i < vkeyWitnesses.length; i++) {
142
+ const { pubKey, signature } = vkeyWitnesses[i];
143
+ const isValidSig = (0, crypto_1.verifyEd25519Signature_sync)(signature, bodyHashBytes, pubKey);
134
144
  if (!isValidSig) {
135
145
  result.errorMessage = `Invalid signature at witness index ${i}. The signature does not match the transaction body.`;
136
146
  logger.warn(result.errorMessage);
@@ -173,9 +183,7 @@ class SignatureVerifier {
173
183
  */
174
184
  extractTxBodyHash(txCbor) {
175
185
  try {
176
- const txBytes = Buffer.from(txCbor, 'hex');
177
- const fixedTx = CSL.FixedTransaction.from_bytes(txBytes);
178
- return Buffer.from(fixedTx.transaction_hash().to_bytes()).toString('hex');
186
+ return computeBodyHash((0, uint8array_utils_1.fromHex)(txCbor));
179
187
  }
180
188
  catch (error) {
181
189
  const msg = error instanceof Error ? error.message : String(error);
@@ -190,11 +198,7 @@ class SignatureVerifier {
190
198
  */
191
199
  isSigned(txCbor) {
192
200
  try {
193
- const txBytes = Buffer.from(txCbor, 'hex');
194
- const tx = CSL.Transaction.from_bytes(txBytes);
195
- const witnessSet = tx.witness_set();
196
- const vkeyWitnesses = witnessSet.vkeys();
197
- return vkeyWitnesses !== undefined && vkeyWitnesses.len() > 0;
201
+ return extractVkeyWitnesses((0, uint8array_utils_1.fromHex)(txCbor)).length > 0;
198
202
  }
199
203
  catch {
200
204
  return false;
@@ -208,11 +212,7 @@ class SignatureVerifier {
208
212
  */
209
213
  getWitnessCount(txCbor) {
210
214
  try {
211
- const txBytes = Buffer.from(txCbor, 'hex');
212
- const tx = CSL.Transaction.from_bytes(txBytes);
213
- const witnessSet = tx.witness_set();
214
- const vkeyWitnesses = witnessSet.vkeys();
215
- return vkeyWitnesses ? vkeyWitnesses.len() : 0;
215
+ return extractVkeyWitnesses((0, uint8array_utils_1.fromHex)(txCbor)).length;
216
216
  }
217
217
  catch {
218
218
  return 0;
@@ -0,0 +1,236 @@
1
+ import type { CardanoTxBuilder } from "./cardano-tx";
2
+ import type { TxBuildRequest, TxBuildMintRequest, TxBuildPlutusSpendRequest, TxBuildContext, TxBuildResult, LedgerProtocolParameters } from "../../utils/types";
3
+ import { CardanoClient } from "../cardano-client";
4
+ /**
5
+ * BuildooorTxBuilder - Implementation of CardanoTxBuilder using Buildooor library
6
+ */
7
+ export declare class BuildooorTxBuilder implements CardanoTxBuilder {
8
+ readonly name = "BuildooorTxBuilder";
9
+ private txBuilder;
10
+ private cardanoClient;
11
+ private genesisInfos;
12
+ private paramsFingerprint;
13
+ /**
14
+ * Initialize the builder
15
+ * @param client - The CardanoClient instance
16
+ * @param protocolParams - Optional protocol parameters (if not provided, fetched from backend)
17
+ */
18
+ init(client: CardanoClient, protocolParams?: LedgerProtocolParameters): Promise<void>;
19
+ /**
20
+ * Rebuild the TxBuilder when the per-request protocol parameters differ from
21
+ * the ones the current TxBuilder was constructed with. Buildooor's TxBuilder
22
+ * has no setter for protocol params, but its constructor is cheap, so we
23
+ * rebuild on change (effectively once per epoch) instead of staying frozen
24
+ * at init-time parameters for the process lifetime.
25
+ */
26
+ private _ensureCurrentProtocolParameters;
27
+ private _applyProtocolParameters;
28
+ /**
29
+ * Build unsigned transfer transaction (ADA-only or with native assets).
30
+ */
31
+ buildUnsignedTransfer(req: TxBuildRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
32
+ /**
33
+ * Build unsigned transfer transaction with attached metadata.
34
+ */
35
+ buildUnsignedTransactionWithMetadata(req: TxBuildRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
36
+ /**
37
+ * Shared non-script transfer build. The two public entry points only differ in
38
+ * the optional pieces of the request they carry (assets/outputDatum on the
39
+ * plain-transfer path, metadataJson on the metadata path) — all handled here
40
+ * conditionally on the field being present, so behaviour matches both.
41
+ */
42
+ private _buildSimpleTransfer;
43
+ buildUnsignedMintTransaction(req: TxBuildMintRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
44
+ buildUnsignedPlutusSpendTransaction(req: TxBuildPlutusSpendRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
45
+ /** Extract CBOR, hash, fee, size, inputs and outputs from a built Buildooor Tx */
46
+ private _extractTxDetails;
47
+ /** Build the standard TxBuildResult object */
48
+ private _buildResult;
49
+ /**
50
+ * Build a script-bearing transaction whose redeemers carry *real* execution units and
51
+ * whose fee covers them.
52
+ *
53
+ * Background (verified against the vendored Buildooor source): `initTxBuild` constructs
54
+ * every redeemer with a dummy budget — caller-supplied execution units in the build args
55
+ * are never read — and `onEvaluationResult` unconditionally stamps each redeemer with
56
+ * the budget the local CEK run consumed, even when the script failed (partial budget).
57
+ * So the declared units are whatever the *local* evaluation produced, and any cushion
58
+ * passed into the args silently evaporates. This method makes the declared units real:
59
+ *
60
+ * 1. First pass: build once; redeemers now carry the local CEK budgets.
61
+ * 2. Evaluate that CBOR via Ogmios (when configured) for authoritative per-redeemer
62
+ * budgets, cushioned by EXECUTION_UNIT_BUFFER / ABS_*_BUFFER.
63
+ * 3. Resolve target units per redeemer (Ogmios beats buffered-local; a local failure
64
+ * without an Ogmios result aborts — see makeScriptBuildOpts).
65
+ * 4. Second pass with a fee floor covering the target units (Buildooor prices the fee
66
+ * from its own local budgets, so the floor adds the price + encoding-size delta).
67
+ * 5. Stamp the target units into the redeemers and recompute scriptDataHash.
68
+ */
69
+ private _buildScriptTx;
70
+ /**
71
+ * Evaluate a transaction via Ogmios and return cushioned budgets keyed per redeemer
72
+ * (`tag:index`). Returns undefined when the evaluation is unusable (transient backend
73
+ * failure, empty result) so callers fall back to buffered local units. A
74
+ * TransactionValidationError or ScriptValidationError from the evaluator is
75
+ * authoritative (the script really failed on the ledger) and is rethrown.
76
+ */
77
+ private _evaluateExUnitsByRedeemer;
78
+ /**
79
+ * Combined cushion: relative multiplier catches proportional drift on large
80
+ * validators, absolute floor catches sub-percent drift on small ones (observed
81
+ * when metadata affects the real tx body vs the evaluator's ScriptContext).
82
+ */
83
+ private _applyExUnitBuffer;
84
+ /**
85
+ * Decide the execution units each redeemer must declare.
86
+ * - Local run succeeded + Ogmios result → max of both (local is a real lower bound).
87
+ * - Local run succeeded, no Ogmios → buffered local (cushions local↔ledger drift).
88
+ * - Local run failed + Ogmios result → Ogmios (the local partial budget is meaningless).
89
+ * - Local run failed, no Ogmios → abort: declaring unreliable units would forfeit the
90
+ * collateral of whoever signs and submits the returned CBOR.
91
+ */
92
+ private _resolveTargetExUnits;
93
+ /** Fee delta of the target vs local units, priced like Buildooor's own fee loop. */
94
+ private _exUnitsPriceDelta;
95
+ /** CBOR size growth (bytes) from stamping larger budgets into the redeemers. */
96
+ private _exUnitsSizeDelta;
97
+ private _txFeePerByte;
98
+ /**
99
+ * Replace the redeemers' execution units and recompute scriptDataHash.
100
+ *
101
+ * Not implemented via TxBuilder.overrideTxRedeemers: that method computes the script
102
+ * data hash from the OLD witness set (library bug), which would yield a phase-1
103
+ * rejection (PPViewHashesDontMatch). We rebuild the witness set first and hash it with
104
+ * the same exported getScriptDataHash + language views the build itself uses.
105
+ */
106
+ private _stampExecUnits;
107
+ /**
108
+ * Language-view selection for scriptDataHash, mirroring Buildooor's initTxBuild
109
+ * (which flags the languages of *executed* scripts). This builder only attaches
110
+ * scripts inline, so the witness set carries every executed script.
111
+ */
112
+ private _usedLanguageViewOpts;
113
+ /**
114
+ * Split UTxOs into forced inputs (must be consumed) and remaining candidates (free for
115
+ * coin selection / collateral). Refs in forceInputs that are not present in utxos are
116
+ * silently ignored — the resolver upstream has already validated existence.
117
+ */
118
+ private _partitionForcedInputs;
119
+ /**
120
+ * Map resolved CIP-31 reference input UTxOs to Buildooor LedgerUTxO format.
121
+ * Returns empty array when no reference inputs are provided.
122
+ */
123
+ private _mapReferenceInputs;
124
+ /**
125
+ * Build the Buildooor mint-entry array shared by the mint-only flow and the
126
+ * combined spend+mint flow (Buildooor ignores caller-supplied execution units;
127
+ * they are stamped into the redeemers post-build by _buildScriptTx).
128
+ */
129
+ private _buildMintEntries;
130
+ /**
131
+ * Pick a collateral UTxO and return remaining funding UTxOs.
132
+ * Throws if no ADA-only UTxO is available.
133
+ *
134
+ * Selection: the SMALLEST ADA-only UTxO that still covers the static
135
+ * COLLATERAL_LOVELACE floor (5 ADA ≳ collateralPercentage × any realistic fee).
136
+ * The previous "first ADA-only" pick failed both ways: a dust UTxO below
137
+ * collateralPercentage × fee is rejected at submit, and a large UTxO is
138
+ * fully forfeited on phase-2 failure (Buildooor sets no collateralReturn
139
+ * for ADA-only collateral). Everything above the floor is therefore handed
140
+ * back via an explicit collateralReturn when the excess satisfies min-ADA.
141
+ */
142
+ private _setupCollateral;
143
+ /** Build a Ledger Value from lovelace + optional multi-asset array */
144
+ private _buildLedgerValue;
145
+ /** Build a TxOut with optional inline datum and optional reference script (CIP-33) */
146
+ private _buildTxOut;
147
+ /**
148
+ * Parse a consumer-provided, CBOR-wrapped Plutus script and reject UPLC 1.0.0
149
+ * code (PlutusV1/V2). `Script.fromCbor` defaults to PlutusV3, so V1/V2 bytes
150
+ * would be hashed with the 0x03 prefix — a silently wrong script hash, i.e.
151
+ * wrong policy IDs and unspendable script addresses with no error anywhere
152
+ * down the line. The UPLC version is the first three flat-encoded naturals
153
+ * of the unwrapped script: [1,0,0] (V1/V2) vs [1,1,0] (V3).
154
+ */
155
+ private _parsePlutusV3Script;
156
+ /** Parse a Plutus V3 CBOR hex into a Buildooor Script for refScript attachment. */
157
+ private _parseReferenceScript;
158
+ /**
159
+ * Map an input UTxO's scriptRef field to a Buildooor Script when possible.
160
+ * UTxO.scriptRef is overloaded across backends: Blockfrost/Ogmios set it to a 28-byte
161
+ * hash (56 hex chars), Koios sets it to the full CBOR script bytes. Only full bytes
162
+ * are usable here — hash-only entries are preserved only on-chain, not in local eval.
163
+ */
164
+ private _buildInputRefScript;
165
+ /**
166
+ * Compute the post-sort input order so __INPUT_IDX__ placeholders (FR-3) resolve to the
167
+ * same indices Buildooor will assign during build(). Order: script-input first by convention,
168
+ * then forced + funding sorted lexicographically on (txHash, outputIndex).
169
+ * Buildooor sorts ALL inputs together; we mirror that exact behaviour via sortInputsLikeBuildooor.
170
+ */
171
+ private _computeSortedInputs;
172
+ /** Extract InputRef list from the Buildooor-shaped funding inputs returned by keepRelevant. */
173
+ private _extractFundingRefs;
174
+ /**
175
+ * Resolve __INPUT_IDX__ placeholders (FR-3) inside each extraOutput.inlineDatum.
176
+ * Returns a new array with resolved datums; non-datum fields pass through unchanged.
177
+ */
178
+ private _resolveExtraOutputPlaceholders;
179
+ /**
180
+ * Append parsed extraOutputs (FR-2) to the outputs array, enforcing min-ADA per entry.
181
+ * Throws TransactionValidationError with the required min-ADA in the message so consumers
182
+ * can adjust without having to inspect Buildooor internals.
183
+ */
184
+ private _appendExtraOutputs;
185
+ /**
186
+ * Resolve the transaction's validity window (slots) from the request.
187
+ * Falls back to `now - 2 min` / `now + 1 h` when the request omits bounds.
188
+ * Script-validated builds must call this; plain transfers pass their own
189
+ * explicit bounds through (no defaulting) so replay behavior is opt-in.
190
+ */
191
+ private _resolveValiditySlots;
192
+ /**
193
+ * Map ODATANO LedgerProtocolParameter to Buildooor's ProtocolParameters shape.
194
+ *
195
+ * Every field is null-guarded: a missing/null source value keeps the library
196
+ * default instead of degrading to 0 (`Number(null) === 0` previously set
197
+ * utxoCostPerByte = 0, disabling min-ADA checks entirely). Cost models and
198
+ * execution-unit prices are mapped because they feed the scriptDataHash
199
+ * (language views) and the fee/ExUnits math — stale defaults there cause
200
+ * PPViewHashesDontMatch or fee underestimation on-chain.
201
+ */
202
+ private _mapLedgerParametersToBuildooorParams;
203
+ /**
204
+ * Parse the cost-models JSON blob (backend-normalized number arrays, keys
205
+ * 'PlutusV1'/'PlutusV2'/'PlutusV3' or Ogmios 'plutus:vN') into Buildooor's
206
+ * CostModels shape ('PlutusScriptVN' keys). Returns undefined when nothing
207
+ * usable is found, so the caller can keep defaults and warn.
208
+ */
209
+ private _mapCostModels;
210
+ /**
211
+ * Map ODATANO UTxO to Ledger UTxO (ADA-only)
212
+ */
213
+ private _mapOdatanoUtxoToLedgerUtxo;
214
+ /**
215
+ * Map ODATANO UTxO to Ledger UTxO (with multi-asset support)
216
+ */
217
+ private _mapMultiAssetUtxoToLedgerUtxo;
218
+ /**
219
+ * Map ODATANO metadata JSON to Ledger TxMetadata
220
+ */
221
+ private _mapOdatanoMetadataToLedgerMetadata;
222
+ /**
223
+ * Recursively convert JSON value to TxMetadatum.
224
+ *
225
+ * Ledger rules enforced here (instead of a node-side rejection or a raw 500):
226
+ * - numbers must be integers (BigInt(1.5) would throw a bare RangeError)
227
+ * - text and byte values are limited to 64 BYTES per metadatum — longer values
228
+ * are chunked into a list of ≤64-byte pieces (the established convention,
229
+ * e.g. CIP-25 long strings)
230
+ * - strings prefixed with "0x" (even hex length) become byte metadata
231
+ * - map keys are not auto-chunked (readers match on the literal key) — over-long
232
+ * keys are rejected with a clear 400
233
+ */
234
+ private _jsonToTxMetadatum;
235
+ }
236
+ //# sourceMappingURL=buildooor-tx.d.ts.map