@odatano/core 1.10.0 → 1.11.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odatano/core",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
5
5
  "imports": {
6
6
  "#cds-models/*": "./@cds-models/*/index.js"
@@ -27,9 +27,9 @@
27
27
  "@blockfrost/blockfrost-js": "~6.0.0",
28
28
  "@cap-js/hana": "^2",
29
29
  "@cardano-ogmios/client": "^6.14.0",
30
- "@harmoniclabs/buildooor": "0.2.6",
31
- "@harmoniclabs/cardano-costmodels-ts": "~1.4.0",
32
- "@harmoniclabs/cardano-ledger-ts": "^0.5.1",
30
+ "@harmoniclabs/buildooor": "0.2.9",
31
+ "@harmoniclabs/cardano-costmodels-ts": "~1.6.1",
32
+ "@harmoniclabs/cardano-ledger-ts": "^0.5.6",
33
33
  "@harmoniclabs/cbor": "^2.0.1",
34
34
  "@harmoniclabs/crypto": "^0.3.0",
35
35
  "@harmoniclabs/uint8array-utils": "^1.0.4",
@@ -161,4 +161,4 @@
161
161
  "url": "https://github.com/ODATANO/ODATANO/issues"
162
162
  },
163
163
  "homepage": "https://github.com/ODATANO/ODATANO#readme"
164
- }
164
+ }
@@ -15,8 +15,9 @@ const logger = cds_1.default.log('SignatureVerifier');
15
15
  /**
16
16
  * blake2b-256 over the ORIGINAL transaction-body bytes (CBOR array index 0).
17
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.
18
+ * and re-serialization can never drift it. (Historically this also sidestepped the
19
+ * ledger-ts AuxiliaryData.fromCbor bug on metadata-only aux_data — fixed in 0.5.6 —
20
+ * but byte-exactness remains the reason to stay at the raw-CBOR level.)
20
21
  */
21
22
  function computeBodyHash(txBytes) {
22
23
  const tx = cbor_1.Cbor.parse(txBytes);
@@ -93,9 +94,7 @@ class SignatureVerifier {
93
94
  };
94
95
  try {
95
96
  // 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.
97
+ // matching exactly what was signed.
99
98
  const txBytes = (0, uint8array_utils_1.fromHex)(signedTxCbor);
100
99
  const computedHash = computeBodyHash(txBytes);
101
100
  result.txBodyHash = computedHash;
@@ -105,16 +105,13 @@ export declare class BuildooorTxBuilder implements CardanoTxBuilder {
105
105
  /**
106
106
  * Replace the redeemers' execution units and recompute scriptDataHash.
107
107
  *
108
- * Not implemented via TxBuilder.overrideTxRedeemers: that method computes the script
109
- * data hash from the OLD witness set (library bug), which would yield a phase-1
110
- * rejection (PPViewHashesDontMatch). We rebuild the witness set first and hash it with
111
- * the same exported getScriptDataHash the build itself uses.
112
- *
113
- * The hash is recomputed even when the target units already match: Buildooor's
114
- * internal hash comes from the named-key cost models, which clamp the chain array
115
- * to the parameter count the library release knows — wrong on networks whose cost
116
- * model has grown past that (ScriptIntegrityHashMismatch at submit). This recompute
117
- * with _languageViewCostModels (raw chain arrays) is where the hash becomes correct.
108
+ * Still not implemented via TxBuilder.overrideTxRedeemers, although buildooor
109
+ * 0.2.9 fixed its old-witness-set hashing (our PR): that method hashes with the
110
+ * builder's named-key cost models, which clamp the chain array to the parameter
111
+ * count the library release knows — wrong whenever the on-chain cost model has
112
+ * grown past that (ScriptIntegrityHashMismatch at submit). This recompute with
113
+ * _languageViewCostModels (raw chain arrays) stays governance-proof, so the hash
114
+ * is recomputed here even when the target units already match.
118
115
  */
119
116
  private _stampExecUnits;
120
117
  /**
@@ -4,13 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.BuildooorTxBuilder = void 0;
7
+ // Coin selection uses this.txBuilder.keepRelevant again since buildooor 0.2.9
8
+ // ships the fixed implementation (our PR); the vendored keep-relevant.ts is gone.
7
9
  const buildooor_1 = require("@harmoniclabs/buildooor");
8
10
  const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
9
11
  const tx_build_helper_1 = require("../../utils/tx-build-helper");
10
12
  const errors_1 = require("../../utils/errors");
11
13
  const plutus_placeholders_1 = require("../../utils/plutus-placeholders");
12
- // Vendored coin selection (buildooor PR #12 fix) — NOT this.txBuilder.keepRelevant; see keep-relevant.ts
13
- const keep_relevant_1 = require("./keep-relevant");
14
14
  const cds_1 = __importDefault(require("@sap/cds"));
15
15
  const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
16
16
  // Metadata classes are imported from the DIST paths ON PURPOSE: buildooor's
@@ -221,7 +221,7 @@ class BuildooorTxBuilder {
221
221
  const forcedInputs = forced.map(u => ({ utxo: this._mapMultiAssetUtxoToLedgerUtxo(u) }));
222
222
  const candidateInputs = rest.map(u => ({ utxo: this._mapMultiAssetUtxoToLedgerUtxo(u) }));
223
223
  // Coin selection on candidates only; forced inputs are prepended unconditionally
224
- const selected = (0, keep_relevant_1.keepRelevant)(outputValue, candidateInputs);
224
+ const selected = this.txBuilder.keepRelevant(outputValue, candidateInputs);
225
225
  const inputs = [...forcedInputs, ...selected];
226
226
  logger.debug(`Coin selection: ${selected.length}/${candidateInputs.length} UTxOs selected (${forcedInputs.length} forced) for ${label}`);
227
227
  const metadata = req.metadataJson !== undefined && req.metadataJson !== null
@@ -266,7 +266,7 @@ class BuildooorTxBuilder {
266
266
  const allFundingInputs = fundingLedgerUtxos.map(utxo => ({ utxo }));
267
267
  // Coin selection: only need enough ADA from funding UTxOs (minted tokens come from thin air)
268
268
  const requiredFundingValue = cardano_ledger_ts_1.Value.lovelaces(BigInt(req.lovelaceAmount));
269
- const selectedFunding = (0, keep_relevant_1.keepRelevant)(requiredFundingValue, allFundingInputs);
269
+ const selectedFunding = this.txBuilder.keepRelevant(requiredFundingValue, allFundingInputs);
270
270
  const inputs = [...forcedInputs, ...selectedFunding];
271
271
  logger.debug(`Coin selection: ${selectedFunding.length}/${allFundingInputs.length} UTxOs selected (${forcedInputs.length} forced) for mint`);
272
272
  // FR-3: resolve __INPUT_IDX__ placeholders in mintRedeemer + inlineDatum after final input order is known.
@@ -360,7 +360,7 @@ class BuildooorTxBuilder {
360
360
  requiredFundingValue = cardano_ledger_ts_1.Value.add(requiredFundingValue, this._buildLedgerValue(BigInt(extra.lovelaceAmount), extra.assets));
361
361
  }
362
362
  }
363
- const selectedFundingInputs = (0, keep_relevant_1.keepRelevant)(requiredFundingValue, allFundingInputs);
363
+ const selectedFundingInputs = this.txBuilder.keepRelevant(requiredFundingValue, allFundingInputs);
364
364
  logger.debug(`Coin selection: ${selectedFundingInputs.length}/${allFundingInputs.length} UTxOs selected (${forcedInputs.length} forced) for Plutus spend`);
365
365
  // FR-3: compute the final input order (replicates Buildooor's lex sort) and resolve any
366
366
  // __INPUT_IDX__ placeholders in redeemer / datum / output datums BEFORE PlutusData encoding.
@@ -675,16 +675,13 @@ class BuildooorTxBuilder {
675
675
  /**
676
676
  * Replace the redeemers' execution units and recompute scriptDataHash.
677
677
  *
678
- * Not implemented via TxBuilder.overrideTxRedeemers: that method computes the script
679
- * data hash from the OLD witness set (library bug), which would yield a phase-1
680
- * rejection (PPViewHashesDontMatch). We rebuild the witness set first and hash it with
681
- * the same exported getScriptDataHash the build itself uses.
682
- *
683
- * The hash is recomputed even when the target units already match: Buildooor's
684
- * internal hash comes from the named-key cost models, which clamp the chain array
685
- * to the parameter count the library release knows — wrong on networks whose cost
686
- * model has grown past that (ScriptIntegrityHashMismatch at submit). This recompute
687
- * with _languageViewCostModels (raw chain arrays) is where the hash becomes correct.
678
+ * Still not implemented via TxBuilder.overrideTxRedeemers, although buildooor
679
+ * 0.2.9 fixed its old-witness-set hashing (our PR): that method hashes with the
680
+ * builder's named-key cost models, which clamp the chain array to the parameter
681
+ * count the library release knows — wrong whenever the on-chain cost model has
682
+ * grown past that (ScriptIntegrityHashMismatch at submit). This recompute with
683
+ * _languageViewCostModels (raw chain arrays) stays governance-proof, so the hash
684
+ * is recomputed here even when the target units already match.
688
685
  */
689
686
  _stampExecUnits(tx, targets) {
690
687
  const rdmrs = tx.witnesses.redeemers ?? [];
@@ -35,8 +35,7 @@ export interface TxCacheTargets {
35
35
  * Extract the consumed input refs and the output addresses from a transaction
36
36
  * CBOR (signed or unsigned) — the rows a successful submit makes stale in the
37
37
  * UTxO cache. Works at the raw-CBOR level for the same reason as
38
- * getTxHashFromCbor (the high-level Tx.fromCbor rejects its own tag-259
39
- * AuxiliaryData builds).
38
+ * getTxHashFromCbor (byte-exact, no high-level Tx round-trip).
40
39
  *
41
40
  * Outputs whose address bytes cannot be decoded (e.g. Byron bootstrap
42
41
  * addresses) are skipped — invalidation is best-effort per address.
@@ -58,9 +58,8 @@ function getTxHashFromCbor(txCbor) {
58
58
  }
59
59
  // Compute blake2b-256 over the ORIGINAL transaction-body bytes (CBOR array index 0).
60
60
  // subCborRef.toBuffer() returns the exact bytes as received — no re-serialization, so
61
- // the hash matches what was signed. Working at the raw-CBOR level also sidesteps the
62
- // @harmoniclabs/cardano-ledger-ts AuxiliaryData.fromCbor bug on metadata-only aux_data
63
- // (we never instantiate the high-level Tx type).
61
+ // the hash matches what was signed. We stay at the raw-CBOR level (never instantiate
62
+ // the high-level Tx type) for that byte-exactness.
64
63
  try {
65
64
  const tx = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(txCbor));
66
65
  if (!(tx instanceof cbor_1.CborArray) || tx.array.length < 1 || !tx.array[0].subCborRef) {
@@ -78,8 +77,7 @@ function getTxHashFromCbor(txCbor) {
78
77
  * Extract the consumed input refs and the output addresses from a transaction
79
78
  * CBOR (signed or unsigned) — the rows a successful submit makes stale in the
80
79
  * UTxO cache. Works at the raw-CBOR level for the same reason as
81
- * getTxHashFromCbor (the high-level Tx.fromCbor rejects its own tag-259
82
- * AuxiliaryData builds).
80
+ * getTxHashFromCbor (byte-exact, no high-level Tx round-trip).
83
81
  *
84
82
  * Outputs whose address bytes cannot be decoded (e.g. Byron bootstrap
85
83
  * addresses) are skipped — invalidation is best-effort per address.
@@ -1,29 +0,0 @@
1
- import { type CanBeUInteger, type ITxBuildInput } from "@harmoniclabs/buildooor";
2
- import { Value, type ValueUnits } from "@harmoniclabs/cardano-ledger-ts";
3
- /**
4
- * Coin selection ("keep relevant" strategy) — vendored fix for
5
- * @harmoniclabs/buildooor 0.2.6 (HarmonicLabs/buildooor PR #12).
6
- *
7
- * The shipped `TxBuilder.keepRelevant` has several defects: the asset-relevance
8
- * filter matches lovelace too (whenever lovelace is requested, EVERY input counts
9
- * as a multi-asset match and the whole UTxO set is selected), the dedup between
10
- * the asset and lovelace selection phases compares only the tx id — not id#index,
11
- * so sibling outputs of one transaction collapse and inputs get selected twice —
12
- * the lovelace sort goes through parseInt/number (breaks above 2^53), and
13
- * `enoughValueHasBeenSelected` has an operator-precedence bug that makes asset
14
- * sums meaningless.
15
- *
16
- * Vendored here (instead of patch-package) so the fix actually reaches consumers
17
- * of the published package: `patches/` never ships in the tarball, and running
18
- * patch-package from a dependency's postinstall is unreliable under npm hoisting.
19
- * Drop this module and call `txBuilder.keepRelevant` again once a buildooor
20
- * release contains the upstream PR.
21
- *
22
- * Semantics: select the inputs holding any requested non-lovelace asset, then add
23
- * smallest-first lovelace-relevant inputs until the requested lovelace (plus a
24
- * safety minimum for fee/change) is covered. Selection may still undershoot when
25
- * the pool itself is insufficient — Buildooor's build() surfaces that as its own
26
- * insufficient-funds error, exactly like the upstream implementation.
27
- */
28
- export declare function keepRelevant(requestedOutputSet: Value | ValueUnits | Record<string, CanBeUInteger>, initialUTxOSet: ITxBuildInput[], minimumLovelaceRequired?: CanBeUInteger): ITxBuildInput[];
29
- //# sourceMappingURL=keep-relevant.d.ts.map
@@ -1,116 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.keepRelevant = keepRelevant;
4
- const buildooor_1 = require("@harmoniclabs/buildooor");
5
- const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
6
- /**
7
- * Coin selection ("keep relevant" strategy) — vendored fix for
8
- * @harmoniclabs/buildooor 0.2.6 (HarmonicLabs/buildooor PR #12).
9
- *
10
- * The shipped `TxBuilder.keepRelevant` has several defects: the asset-relevance
11
- * filter matches lovelace too (whenever lovelace is requested, EVERY input counts
12
- * as a multi-asset match and the whole UTxO set is selected), the dedup between
13
- * the asset and lovelace selection phases compares only the tx id — not id#index,
14
- * so sibling outputs of one transaction collapse and inputs get selected twice —
15
- * the lovelace sort goes through parseInt/number (breaks above 2^53), and
16
- * `enoughValueHasBeenSelected` has an operator-precedence bug that makes asset
17
- * sums meaningless.
18
- *
19
- * Vendored here (instead of patch-package) so the fix actually reaches consumers
20
- * of the published package: `patches/` never ships in the tarball, and running
21
- * patch-package from a dependency's postinstall is unreliable under npm hoisting.
22
- * Drop this module and call `txBuilder.keepRelevant` again once a buildooor
23
- * release contains the upstream PR.
24
- *
25
- * Semantics: select the inputs holding any requested non-lovelace asset, then add
26
- * smallest-first lovelace-relevant inputs until the requested lovelace (plus a
27
- * safety minimum for fee/change) is covered. Selection may still undershoot when
28
- * the pool itself is insufficient — Buildooor's build() surfaces that as its own
29
- * insufficient-funds error, exactly like the upstream implementation.
30
- */
31
- function keepRelevant(requestedOutputSet, initialUTxOSet, minimumLovelaceRequired = 5_000_000) {
32
- const requested = normalizeRequestedOutputSet(requestedOutputSet);
33
- const requestedLovelace = (requested["lovelace"] ?? 0n) + (0, buildooor_1.forceBigUInt)(minimumLovelaceRequired);
34
- const requestedAssetUnits = Object.keys(requested).filter(unit => unit !== "lovelace");
35
- const multiAssetIns = initialUTxOSet.filter(input => new cardano_ledger_ts_1.UTxO(input.utxo).resolved.value.toUnits()
36
- .filter(asset => asset.unit !== "lovelace")
37
- .some(asset => requestedAssetUnits.includes(asset.unit)));
38
- const totLovelaces = getTotLovelaces(multiAssetIns);
39
- const lovelaceIns = totLovelaces < requestedLovelace
40
- ? remainingLovelace(requestedLovelace - totLovelaces,
41
- // filter out inputs already picked by the multi-asset selection
42
- initialUTxOSet.filter(initialUtxo => {
43
- const refStr = utxoRefStr(initialUtxo);
44
- return !multiAssetIns.some(selected => utxoRefStr(selected) === refStr);
45
- }))
46
- : [];
47
- return lovelaceIns.concat(multiAssetIns).map(buildooor_1.normalizeITxBuildInput);
48
- }
49
- /**
50
- * Tolerates `Value` instances from a duplicated `cardano-ledger-ts` in
51
- * node_modules, where `instanceof` fails across the two copies.
52
- */
53
- function isValueLike(x) {
54
- return x instanceof cardano_ledger_ts_1.Value ||
55
- (!Array.isArray(x) && typeof x?.toUnits === "function");
56
- }
57
- /**
58
- * `keepRelevant` historically accepted two shapes besides `Value`: the
59
- * `ValueUnits` array returned by `Value.toUnits()` and a Mesh-style
60
- * `{ [unit]: quantity }` record. Normalize all of them to a record with
61
- * `bigint` quantities so the algorithm only deals with one shape.
62
- */
63
- function normalizeRequestedOutputSet(requested) {
64
- const units = isValueLike(requested)
65
- ? requested.toUnits()
66
- : requested;
67
- const result = {};
68
- if (Array.isArray(units)) {
69
- for (const { unit, quantity } of units) {
70
- result[unit] = (result[unit] ?? 0n) + BigInt(quantity);
71
- }
72
- return result;
73
- }
74
- for (const unit of Object.keys(units)) {
75
- result[unit] = BigInt(units[unit]);
76
- }
77
- return result;
78
- }
79
- /** Full utxo ref (id#index) — the id alone collapses sibling outputs of one tx. */
80
- function utxoRefStr(input) {
81
- const ref = input.utxo.utxoRef;
82
- return `${ref.id.toString()}#${ref.index.toString()}`;
83
- }
84
- function getTotLovelaces(inputs) {
85
- return inputs.reduce((sum, input) => sum + new cardano_ledger_ts_1.UTxO(input.utxo).resolved.value.lovelaces, 0n);
86
- }
87
- function remainingLovelace(quantity, initialUTxOSet) {
88
- // smallest-first, compared as bigint (a number sort breaks above 2^53 lovelace)
89
- const sortedUTxOs = initialUTxOSet.slice().sort((a, b) => {
90
- const aLovelaces = new cardano_ledger_ts_1.UTxO(a.utxo).resolved.value.lovelaces;
91
- const bLovelaces = new cardano_ledger_ts_1.UTxO(b.utxo).resolved.value.lovelaces;
92
- return aLovelaces < bLovelaces ? -1 : aLovelaces > bLovelaces ? 1 : 0;
93
- });
94
- return selectValue(sortedUTxOs, { lovelace: quantity });
95
- }
96
- function enoughValueHasBeenSelected(selection, assets) {
97
- return Object.keys(assets).every(unit => selection.reduce((selectedQuantity, input) => {
98
- const utxoQuantity = new cardano_ledger_ts_1.UTxO(input.utxo).resolved.value.toUnits()
99
- .reduce((quantity, a) => quantity + (unit === a.unit ? BigInt(a.quantity) : 0n), 0n);
100
- return selectedQuantity + utxoQuantity;
101
- }, 0n) >= assets[unit]);
102
- }
103
- function selectValue(inputUTxO, outputSet, selection = []) {
104
- if (inputUTxO.length === 0 || enoughValueHasBeenSelected(selection, outputSet)) {
105
- return selection;
106
- }
107
- if (canValueBeSelected(inputUTxO[0], outputSet)) {
108
- return selectValue(inputUTxO.slice(1), outputSet, selection.concat(inputUTxO[0]));
109
- }
110
- return selectValue(inputUTxO.slice(1), outputSet, selection);
111
- }
112
- function canValueBeSelected(input, assets) {
113
- return Object.keys(assets).some(unit => new cardano_ledger_ts_1.UTxO(input.utxo).resolved.value.toUnits()
114
- .some(asset => asset.unit === unit));
115
- }
116
- //# sourceMappingURL=keep-relevant.js.map