@odatano/core 0.3.15 → 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.15",
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":"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;;;;;;;;;;;;;;;;;;;;;;;;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,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 cbor_1 = require("@harmoniclabs/cbor");
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
  /**
@@ -52,60 +53,72 @@ const logger = cds_1.default.log('SigningHelper');
52
53
  *
53
54
  * Cardano transaction structure: [body, witness_set, is_valid, auxiliary_data]
54
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
+ *
55
68
  * @param unsignedTxCbor - The unsigned transaction CBOR (hex)
56
69
  * @param witnessSetCbor - The witness set CBOR from CIP-30 signTx() (hex)
57
70
  * @returns Complete signed transaction CBOR (hex)
58
71
  */
59
72
  function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
60
73
  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) {
74
+ // Parse at raw CBOR level no 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) {
65
77
  throw new Error('Invalid transaction CBOR structure');
66
78
  }
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);
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
+ }
84
107
  }
85
- txArray[1] = origWs;
86
108
  }
87
109
  else {
88
110
  // 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()];
111
+ txObj.array[1] = walletWsObj;
101
112
  }
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());
102
116
  logger.info({
103
117
  unsignedTxLength: unsignedTxCbor.length,
104
118
  witnessSetLength: witnessSetCbor.length,
105
119
  signedTxLength: signedTxCbor.length,
106
120
  witnessCount,
107
- witnessKeys,
108
- }, 'Combined transaction with witness set (raw CBOR)');
121
+ }, 'Combined transaction with witness set (harmoniclabs CBOR)');
109
122
  return signedTxCbor;
110
123
  }
111
124
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"signing-helper.js","sourceRoot":"","sources":["signing-helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,0EAiEC;AAWD,4CAkBC;AAlHD,mDAA2B;AAC3B,8EAAgE;AAChE,2CAA6B;AAC7B,qCAAsD;AAEtD,MAAM,MAAM,GAAG,aAAG,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAExC;;;;;;;;;;;;GAYG;AACH,SAAgB,+BAA+B,CAAC,cAAsB,EAAE,cAAsB;IAC5F,IAAI,CAAC;QACH,6DAA6D;QAC7D,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;QAC3D,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;QAEtD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAClD,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACxD,CAAC;QAED,kCAAkC;QAClC,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;QAC3D,MAAM,gBAAgB,GAAG,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;QAE/D,8CAA8C;QAC9C,gGAAgG;QAChG,gDAAgD;QAChD,gDAAgD;QAEhD,2DAA2D;QAC3D,2DAA2D;QAC3D,wFAAwF;QACxF,kEAAkE;QAClE,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QAC1B,MAAM,QAAQ,GAAG,gBAAgB,CAAC;QAElC,IAAI,QAAQ,YAAY,GAAG,IAAI,MAAM,YAAY,GAAG,EAAE,CAAC;YACrD,MAAM,K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