@odatano/core 0.3.15 → 0.3.16

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.15",
3
+ "version": "0.3.16",
4
4
  "description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
5
5
  "imports": {
6
6
  "#cds-models/*": "./@cds-models/*/index.js"
@@ -1 +1 @@
1
- {"version":3,"file":"signing-helper.d.ts","sourceRoot":"","sources":["signing-helper.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;GAYG;AACH,wBAAgB,+BAA+B,CAAC,cAAc,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAiEtG;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;;;;;;;;;;;;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"}
@@ -40,7 +40,8 @@ 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 cbor = __importStar(require("cbor"));
43
+ const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
44
+ const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
44
45
  const errors_1 = require("./errors");
45
46
  const logger = cds_1.default.log('SigningHelper');
46
47
  /**
@@ -58,54 +59,33 @@ const logger = cds_1.default.log('SigningHelper');
58
59
  */
59
60
  function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
60
61
  try {
61
- // Decode the unsigned transaction CBOR (array of 4 elements)
62
- const unsignedTxBytes = Buffer.from(unsignedTxCbor, 'hex');
63
- const txArray = cbor.decodeFirstSync(unsignedTxBytes);
64
- if (!Array.isArray(txArray) || txArray.length < 2) {
65
- throw new Error('Invalid transaction CBOR structure');
66
- }
67
- // Decode the wallet's witness set
68
- const witnessSetBytes = Buffer.from(witnessSetCbor, 'hex');
69
- const walletWitnessSet = cbor.decodeFirstSync(witnessSetBytes);
70
- // txArray[0] = body (preserved exactly as-is)
71
- // txArray[1] = witness_set (CBOR Map: 0=vkeys, 3=plutus_v1, 5=redeemers, 6=datums, 7=plutus_v3)
72
- // txArray[2] = is_valid (boolean, usually true)
73
- // txArray[3] = auxiliary_data (preserved as-is)
74
- // MERGE wallet's VKey witnesses into existing witness set.
75
- // CIP-30 signTx() only returns VKey witnesses (map key 0).
76
- // The builder puts script witnesses (keys 3, 5, 6, 7) in the unsigned tx's witness set.
77
- // We must preserve those and only add/replace the VKey witnesses.
78
- const origWs = txArray[1];
79
- const walletWs = walletWitnessSet;
80
- if (walletWs instanceof Map && origWs instanceof Map) {
81
- const vkeys = walletWs.get(0);
82
- if (vkeys) {
83
- origWs.set(0, vkeys);
84
- }
85
- txArray[1] = origWs;
86
- }
87
- else {
88
- // Fallback for non-Map witness sets (simple transactions)
89
- txArray[1] = walletWitnessSet;
90
- }
91
- // Re-encode to CBOR
92
- const signedTxBytes = cbor.encodeOne(txArray);
93
- const signedTxCbor = signedTxBytes.toString('hex');
94
- // Count witnesses for logging
95
- let witnessCount = 0;
96
- let witnessKeys = [];
97
- if (txArray[1] instanceof Map) {
98
- const vkeys = txArray[1].get(0);
99
- witnessCount = Array.isArray(vkeys) ? vkeys.length : 0;
100
- witnessKeys = [...txArray[1].keys()];
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);
101
79
  }
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());
102
83
  logger.info({
103
84
  unsignedTxLength: unsignedTxCbor.length,
104
85
  witnessSetLength: witnessSetCbor.length,
105
86
  signedTxLength: signedTxCbor.length,
106
- witnessCount,
107
- witnessKeys,
108
- }, 'Combined transaction with witness set (raw CBOR)');
87
+ witnessCount: vkeys.length,
88
+ }, 'Combined transaction with witness set (harmoniclabs byte-preserving)');
109
89
  return signedTxCbor;
110
90
  }
111
91
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"signing-helper.js","sourceRoot":"","sources":["signing-helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;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