@odatano/core 0.3.16 → 0.3.17

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": "0.3.16",
3
+ "version": "0.3.17",
4
4
  "description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
5
5
  "imports": {
6
6
  "#cds-models/*": "./@cds-models/*/index.js"
@@ -14,9 +14,10 @@
14
14
  "@blockfrost/blockfrost-js": "^6.0.0",
15
15
  "@cardano-ogmios/client": "^6.14.0",
16
16
  "@emurgo/cardano-serialization-lib-nodejs": "^15.0.3",
17
- "@harmoniclabs/buildooor": "^0.1.21",
17
+ "@harmoniclabs/buildooor": "^0.1.28",
18
18
  "@harmoniclabs/cardano-costmodels-ts": "^1.3.0",
19
- "@sap/cds": "^9",
19
+ "@harmoniclabs/cardano-ledger-ts": "^0.4.6",
20
+ "@sap/cds": ">=9",
20
21
  "axios": "^1.13.2",
21
22
  "bech32": "^2.0.0"
22
23
  },
@@ -1 +1 @@
1
- {"version":3,"file":"signing-helper.d.ts","sourceRoot":"","sources":["signing-helper.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;GAYG;AACH,wBAAgB,+BAA+B,CAAC,cAAc,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAyCtG;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAkBzD"}
1
+ {"version":3,"file":"signing-helper.d.ts","sourceRoot":"","sources":["signing-helper.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,+BAA+B,CAAC,cAAc,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAoEtG;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAkBzD"}
@@ -40,7 +40,7 @@ exports.combineTransactionWithWitnesses = combineTransactionWithWitnesses;
40
40
  exports.isWitnessSetCbor = isWitnessSetCbor;
41
41
  const cds_1 = __importDefault(require("@sap/cds"));
42
42
  const CSL = __importStar(require("@emurgo/cardano-serialization-lib-nodejs"));
43
- const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
43
+ const cbor_1 = require("@harmoniclabs/cbor");
44
44
  const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
45
45
  const errors_1 = require("./errors");
46
46
  const logger = cds_1.default.log('SigningHelper');
@@ -53,39 +53,72 @@ const logger = cds_1.default.log('SigningHelper');
53
53
  *
54
54
  * Cardano transaction structure: [body, witness_set, is_valid, auxiliary_data]
55
55
  *
56
+ * IMPORTANT: This operates at the raw CBOR level using @harmoniclabs/cbor, NOT at the
57
+ * Cardano type level. This is critical for two reasons:
58
+ * 1. The npm 'cbor' library (v9.0.2) normalizes encoding during round-trip
59
+ * (indefinite→definite length, non-minimal integers), changing redeemer bytes and
60
+ * causing PPViewHashesDontMatch on Plutus transactions (BUG 10).
61
+ * 2. @harmoniclabs/cardano-ledger-ts has a key 7 loop bug in TxWitnessSet.fromCborObj
62
+ * (processes keys 0-6 only), which would silently drop PlutusV3 scripts.
63
+ *
64
+ * The @harmoniclabs/cbor parser preserves encoding metadata (indefinite flag, addInfos)
65
+ * on each CborObj, so re-encoding produces identical bytes for unchanged elements.
66
+ * Both Buildooor and this code use the same CBOR library, ensuring consistent encoding.
67
+ *
56
68
  * @param unsignedTxCbor - The unsigned transaction CBOR (hex)
57
69
  * @param witnessSetCbor - The witness set CBOR from CIP-30 signTx() (hex)
58
70
  * @returns Complete signed transaction CBOR (hex)
59
71
  */
60
72
  function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
61
73
  try {
62
- // Parse unsigned transaction using harmoniclabs — preserves original CBOR encoding
63
- // via SubCborRef. This is critical: the npm 'cbor' library normalizes encoding
64
- // (indefinite→definite length, non-minimal integers) during round-trip, which
65
- // changes redeemer bytes and causes PPViewHashesDontMatch on Plutus transactions.
66
- // Harmoniclabs preserves body bytes via body.cborRef and individual witness element
67
- // bytes via their own SubCborRef. See signature-verifier.ts for the same pattern.
68
- const tx = cardano_ledger_ts_1.Tx.fromCbor((0, uint8array_utils_1.fromHex)(unsignedTxCbor));
69
- // Parse wallet's witness set (CIP-30 signTx() returns only the witness set)
70
- const walletWs = cardano_ledger_ts_1.TxWitnessSet.fromCbor((0, uint8array_utils_1.fromHex)(witnessSetCbor));
71
- // Add each VKey witness from the wallet to the transaction.
72
- // This follows the same pattern as harmoniclabs' own signWithCip30Wallet() (Tx.js:168).
73
- // addVKeyWitness clears Tx.cborRef and TxWitnessSet.cborRef, but body.cborRef and
74
- // individual redeemer/datum/script SubCborRefs are preserved. Re-serialization uses
75
- // the same @harmoniclabs/cbor library as the builder, ensuring consistent encoding.
76
- const vkeys = walletWs.vkeyWitnesses ?? [];
77
- for (const vkeyWit of vkeys) {
78
- tx.addVKeyWitness(vkeyWit);
74
+ // Parse at raw CBOR levelno Cardano type validation, preserves all encoding metadata
75
+ const txObj = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(unsignedTxCbor));
76
+ if (!(txObj instanceof cbor_1.CborArray) || txObj.array.length < 2) {
77
+ throw new Error('Invalid transaction CBOR structure');
78
+ }
79
+ const walletWsObj = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(witnessSetCbor));
80
+ // txObj.array[0] = body, [1] = witness_set, [2] = is_valid, [3] = auxiliary_data
81
+ const origWs = txObj.array[1];
82
+ let witnessCount = 0;
83
+ if (origWs instanceof cbor_1.CborMap && walletWsObj instanceof cbor_1.CborMap) {
84
+ // Find wallet's VKey witnesses (map key 0)
85
+ const walletVkeyEntry = walletWsObj.map.find(e => e.k instanceof cbor_1.CborUInt && Number(e.k.num) === 0);
86
+ if (walletVkeyEntry) {
87
+ // Merge: keep all original entries (redeemers, datums, scripts at keys 3-7),
88
+ // remove any existing key 0, then add wallet's key 0 (VKey witnesses)
89
+ const mergedEntries = origWs.map
90
+ .filter(e => !(e.k instanceof cbor_1.CborUInt && Number(e.k.num) === 0))
91
+ .concat([walletVkeyEntry]);
92
+ // Construct new witness set CborMap preserving the original's encoding style
93
+ txObj.array[1] = new cbor_1.CborMap(mergedEntries, {
94
+ indefinite: origWs.indefinite,
95
+ });
96
+ // Count VKey witnesses — value may be CborArray or CborTag(258, CborArray) in Conway era
97
+ const vkeyValue = walletVkeyEntry.v;
98
+ if (vkeyValue instanceof cbor_1.CborArray) {
99
+ witnessCount = vkeyValue.array.length;
100
+ }
101
+ else if (vkeyValue instanceof cbor_1.CborTag && vkeyValue.data instanceof cbor_1.CborArray) {
102
+ witnessCount = vkeyValue.data.array.length;
103
+ }
104
+ else {
105
+ witnessCount = 1;
106
+ }
107
+ }
108
+ }
109
+ else {
110
+ // Fallback for non-Map witness sets (simple transactions)
111
+ txObj.array[1] = walletWsObj;
79
112
  }
80
- // Export the signed transaction body bytes preserved, witness set re-serialized
81
- // with wallet VKeys merged into the builder's script witnesses
82
- const signedTxCbor = (0, uint8array_utils_1.toHex)(tx.toCborBytes());
113
+ // Re-encode the tx array, preserving encoding metadata on body and all witness values.
114
+ // Construct a new CborArray to avoid stale subCborRef pointing to the old bytes.
115
+ const signedTxCbor = (0, uint8array_utils_1.toHex)(cbor_1.Cbor.encode(new cbor_1.CborArray(txObj.array, { indefinite: txObj.indefinite })).toBuffer());
83
116
  logger.info({
84
117
  unsignedTxLength: unsignedTxCbor.length,
85
118
  witnessSetLength: witnessSetCbor.length,
86
119
  signedTxLength: signedTxCbor.length,
87
- witnessCount: vkeys.length,
88
- }, 'Combined transaction with witness set (harmoniclabs byte-preserving)');
120
+ witnessCount,
121
+ }, 'Combined transaction with witness set (harmoniclabs CBOR)');
89
122
  return signedTxCbor;
90
123
  }
91
124
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"signing-helper.js","sourceRoot":"","sources":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