@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
@@ -0,0 +1,74 @@
1
+ import { HsmConfig, HsmSignResult } from '../../utils/types';
2
+ export declare class HsmSigner {
3
+ private pkcs11;
4
+ private session;
5
+ private privateKeyHandle;
6
+ private publicKeyBytes;
7
+ private publicKeyHashHex;
8
+ private cardanoAddress;
9
+ private config;
10
+ private connected;
11
+ constructor(config: HsmConfig);
12
+ /**
13
+ * Initialize PKCS#11 session and locate the signing key.
14
+ * Called once during plugin startup.
15
+ *
16
+ * @param network - Cardano network (mainnet, preview, preprod) for address derivation
17
+ */
18
+ init(network: 'mainnet' | 'preview' | 'preprod' | string): Promise<void>;
19
+ /**
20
+ * Sign a 32-byte transaction body hash using the HSM.
21
+ * Returns the Ed25519 signature + public key for witness construction.
22
+ *
23
+ * @param txBodyHash - 32-byte hash of the transaction body
24
+ * @returns HsmSignResult with signature, public key, and key hash
25
+ */
26
+ sign(txBodyHash: Buffer): HsmSignResult;
27
+ /**
28
+ * Sign a transaction and produce a complete signed transaction CBOR.
29
+ *
30
+ * Takes the unsigned transaction CBOR, signs the body hash via HSM,
31
+ * builds a VKey witness [publicKey, signature], and merges it into
32
+ * the transaction's witness set using raw CBOR manipulation.
33
+ *
34
+ * @param unsignedTxCbor - Unsigned transaction CBOR (hex)
35
+ * @param txBodyHash - Transaction body hash (hex, 64 chars)
36
+ * @returns Signed transaction CBOR (hex)
37
+ */
38
+ signTransaction(unsignedTxCbor: string, txBodyHash: string): string;
39
+ /** Get the HSM-derived Cardano enterprise address */
40
+ getAddress(): string;
41
+ /** Get the public key hash (for requiredSigners) */
42
+ getPublicKeyHash(): string;
43
+ /** Check connection status */
44
+ isConnected(): boolean;
45
+ /** Get status for monitoring */
46
+ getStatus(): {
47
+ connected: boolean;
48
+ keyId?: string;
49
+ keyLabel?: string;
50
+ publicKeyHash?: string;
51
+ address?: string;
52
+ };
53
+ /** Graceful shutdown — close PKCS#11 session */
54
+ shutdown(): void;
55
+ /**
56
+ * Find a key object (private or public) in the HSM by label and/or ID
57
+ */
58
+ private _findKey;
59
+ /**
60
+ * Export the Ed25519 public key from the HSM.
61
+ * Handles both DER-wrapped (04 20 <32 bytes>) and raw 32-byte formats.
62
+ */
63
+ private _exportPublicKey;
64
+ }
65
+ /**
66
+ * Get the initialized HsmSigner instance.
67
+ * Returns null if HSM is not configured.
68
+ */
69
+ export declare function getHsmSigner(): HsmSigner | null;
70
+ /**
71
+ * Set the HsmSigner instance (called during initialization and shutdown).
72
+ */
73
+ export declare function setHsmSigner(signer: HsmSigner | null): void;
74
+ //# sourceMappingURL=hsm-signer.d.ts.map
@@ -50,10 +50,13 @@ class HsmSigner {
50
50
  this.pkcs11.load(this.config.pkcs11Module);
51
51
  this.pkcs11.C_Initialize();
52
52
  logger.info({ module: this.config.pkcs11Module }, 'PKCS#11 module loaded');
53
- // 2. Open session on configured slot
53
+ // 2. Open session on configured slot.
54
+ // NOTE: `config.slot` is the 0-based INDEX into the list of slots-with-token
55
+ // returned by C_GetSlotList(true), NOT the PKCS#11 slot ID (which need not be
56
+ // contiguous or zero-based). Configure it as a position, not a hardware slot id.
54
57
  const slots = this.pkcs11.C_GetSlotList(true);
55
58
  if (this.config.slot >= slots.length) {
56
- throw new errors_1.HsmError(`HSM slot ${this.config.slot} not found. Available slots: ${slots.length}`, 503, error_codes_1.ERROR_CODES.HSM_UNAVAILABLE);
59
+ throw new errors_1.HsmError(`HSM slot index ${this.config.slot} not found. ${slots.length} slot(s) with a token present (valid indices 0..${slots.length - 1}).`, 503, error_codes_1.ERROR_CODES.HSM_UNAVAILABLE);
57
60
  }
58
61
  this.session = this.pkcs11.C_OpenSession(slots[this.config.slot], pkcs11js.CKF_SERIAL_SESSION | pkcs11js.CKF_RW_SESSION);
59
62
  logger.debug({ slot: this.config.slot }, 'PKCS#11 session opened');
@@ -62,9 +65,21 @@ class HsmSigner {
62
65
  this.pkcs11.C_Login(this.session, pkcs11js.CKU_USER, this.config.pin);
63
66
  }
64
67
  finally {
65
- // Clear PIN from memory regardless of login outcome — PIN is no longer needed
66
- // even on failure (preventing in-memory PIN residue for crash-dump / heap-inspection scenarios)
67
- this.config = { ...this.config, pin: '' };
68
+ // Zero the PIN everywhere it could residue after login (crash-dump /
69
+ // heap-inspection hardening), regardless of login outcome:
70
+ // - this.config (shared reference with the server-side hsmConfigInstance
71
+ // singleton) — mutate IN PLACE, not reassign, so the singleton clears too
72
+ // - the HSM_PIN environment variable
73
+ // - the CAP config (cds.env.requires['odatano-core'].hsm.pin)
74
+ this.config.pin = '';
75
+ if (process.env.HSM_PIN)
76
+ delete process.env.HSM_PIN;
77
+ try {
78
+ const hsmCds = cds_1.default.env?.requires?.['odatano-core']?.hsm;
79
+ if (hsmCds && 'pin' in hsmCds)
80
+ hsmCds.pin = '';
81
+ }
82
+ catch { /* best effort */ }
68
83
  }
69
84
  logger.debug('PKCS#11 login successful');
70
85
  // 4. Find private key by label or ID
@@ -0,0 +1,56 @@
1
+ import { SignatureVerificationResult, VerificationOptions } from '../../utils/types';
2
+ /**
3
+ * SignatureVerifier - Verifies transaction signatures without accessing private keys
4
+ *
5
+ * This module provides signature verification for externally signed transactions.
6
+ * It ensures:
7
+ * 1. The signed CBOR is valid and parseable
8
+ * 2. The transaction body hash matches the expected hash (integrity check)
9
+ * 3. Required signatures are present (when specified)
10
+ * 4. No tampering occurred between build and sign steps
11
+ */
12
+ export declare class SignatureVerifier {
13
+ /**
14
+ * Verify a signed transaction
15
+ *
16
+ * @param signedTxCbor - The signed transaction in CBOR hex format
17
+ * @param options - Verification options
18
+ * @returns Verification result with details
19
+ */
20
+ verify(signedTxCbor: string, options?: VerificationOptions): SignatureVerificationResult;
21
+ /**
22
+ * Verify signature and throw on failure
23
+ *
24
+ * @param signedTxCbor - The signed transaction in CBOR hex format
25
+ * @param options - Verification options
26
+ * @throws {TransactionValidationError} if verification fails
27
+ */
28
+ verifyOrThrow(signedTxCbor: string, options?: VerificationOptions): SignatureVerificationResult;
29
+ /**
30
+ * Extract transaction body hash from unsigned or signed CBOR
31
+ *
32
+ * @param txCbor - Transaction CBOR (signed or unsigned)
33
+ * @returns Transaction body hash as hex string
34
+ * @throws {Error} if CBOR is invalid
35
+ */
36
+ extractTxBodyHash(txCbor: string): string;
37
+ /**
38
+ * Check if a transaction is signed (has witnesses)
39
+ *
40
+ * @param txCbor - Transaction CBOR
41
+ * @returns true if transaction has at least one witness
42
+ */
43
+ isSigned(txCbor: string): boolean;
44
+ /**
45
+ * Get witness count from transaction
46
+ *
47
+ * @param txCbor - Transaction CBOR
48
+ * @returns Number of witnesses
49
+ */
50
+ getWitnessCount(txCbor: string): number;
51
+ }
52
+ /**
53
+ * Get the singleton SignatureVerifier instance
54
+ */
55
+ export declare function getSignatureVerifier(): SignatureVerifier;
56
+ //# sourceMappingURL=signature-verifier.d.ts.map
@@ -46,14 +46,23 @@ function extractVkeyWitnesses(txBytes) {
46
46
  // would otherwise throw a TypeError and surface as an opaque internal error. Skip
47
47
  // any entry that isn't a [vkey, signature] pair of byte strings.
48
48
  const witnesses = [];
49
+ let skipped = 0;
49
50
  for (const pair of arr.array) {
50
- if (!(pair instanceof cbor_1.CborArray) || pair.array.length !== 2)
51
+ if (!(pair instanceof cbor_1.CborArray) || pair.array.length !== 2) {
52
+ skipped++;
51
53
  continue;
54
+ }
52
55
  const [vk, sg] = pair.array;
53
- if (!(vk instanceof cbor_1.CborBytes) || !(sg instanceof cbor_1.CborBytes))
56
+ if (!(vk instanceof cbor_1.CborBytes) || !(sg instanceof cbor_1.CborBytes)) {
57
+ skipped++;
54
58
  continue;
59
+ }
55
60
  witnesses.push({ pubKey: vk.bytes, signature: sg.bytes });
56
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
+ }
57
66
  return witnesses;
58
67
  }
59
68
  /**
@@ -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