@odatano/core 1.9.1 → 1.9.2
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.9.
|
|
3
|
+
"version": "1.9.2",
|
|
4
4
|
"description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
|
|
5
5
|
"imports": {
|
|
6
6
|
"#cds-models/*": "./@cds-models/*/index.js"
|
|
@@ -27,7 +27,7 @@
|
|
|
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": "
|
|
30
|
+
"@harmoniclabs/buildooor": "0.2.6",
|
|
31
31
|
"@harmoniclabs/cardano-costmodels-ts": "~1.4.0",
|
|
32
32
|
"@harmoniclabs/cardano-ledger-ts": "^0.5.1",
|
|
33
33
|
"@harmoniclabs/cbor": "^2.0.1",
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
"eslint": "^9.39.2",
|
|
62
62
|
"jest": "^29.6.1",
|
|
63
63
|
"nock": "^13.5.6",
|
|
64
|
+
"patch-package": "8.0.1",
|
|
64
65
|
"ts-jest": "^29.4.5",
|
|
65
66
|
"ts-node": "^10.9.2",
|
|
66
67
|
"tsx": "^4.21.0",
|
|
@@ -105,6 +106,7 @@
|
|
|
105
106
|
}
|
|
106
107
|
},
|
|
107
108
|
"scripts": {
|
|
109
|
+
"postinstall": "patch-package",
|
|
108
110
|
"clean": "node -e \"require('glob').sync('{srv,db,src}/**/*.{js,js.map,d.ts,d.ts.map}',{ignore:'**/node_modules/**'}).forEach(f=>require('fs').unlinkSync(f));console.log('Clean complete')\"",
|
|
109
111
|
"clean:models": "node -e \"require('fs').rmSync('@cds-models',{recursive:true,force:true});console.log('Removed @cds-models')\"",
|
|
110
112
|
"build": "npm run cds:types && tsc",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { UTxO as OdatanoUtxo, JSONValue } from '../utils/types';
|
|
2
2
|
import { type Data } from '@harmoniclabs/plutus-data';
|
|
3
|
+
import { UPLCConst } from '@harmoniclabs/uplc';
|
|
3
4
|
/**
|
|
4
5
|
* Extract lovelace amount from UTxO
|
|
5
6
|
* @param u UTxO to extract from
|
|
@@ -65,11 +66,41 @@ export declare function jsonToPlutusData(json: JSONValue): Data;
|
|
|
65
66
|
* shapes rather than throwing — backend mappers must not crash on malformed data.
|
|
66
67
|
*/
|
|
67
68
|
export declare function inlineDatumToHex(datum: unknown): string | null;
|
|
69
|
+
/** UPLC type tag for a typed script parameter (see {@link encodeScriptParam}). */
|
|
70
|
+
export type ScriptParamUplcType = 'data' | 'bytes' | 'int' | 'bool' | 'unit';
|
|
71
|
+
/**
|
|
72
|
+
* Encode a single script parameter into the UPLC constant the parameterized
|
|
73
|
+
* script expects.
|
|
74
|
+
*
|
|
75
|
+
* A script parameter is applied as a UPLC constant whose TYPE must match what
|
|
76
|
+
* the compiled validator expects for that parameter. Two input shapes are
|
|
77
|
+
* accepted:
|
|
78
|
+
*
|
|
79
|
+
* 1. Typed — `{ "uplc": "<type>", "value": <...> }`:
|
|
80
|
+
* - `"data"` → `UPLCConst.data(...)` value: PlutusData JSON ("constr"/cardano-cli form)
|
|
81
|
+
* - `"bytes"` → `UPLCConst.byteString(...)` value: even-length hex string
|
|
82
|
+
* - `"int"` → `UPLCConst.int(...)` value: number | numeric string
|
|
83
|
+
* - `"bool"` → `UPLCConst.bool(...)` value: boolean
|
|
84
|
+
* - `"unit"` → `UPLCConst.unit` value: omitted
|
|
85
|
+
* Required for compilers whose scalar params are NATIVE-typed rather than
|
|
86
|
+
* Data-wrapped (e.g. Pebble: `param x: PubKeyHash` expects a native
|
|
87
|
+
* `bytestring`, not a `Data` bytestring).
|
|
88
|
+
*
|
|
89
|
+
* 2. Bare PlutusData object (e.g. `{ "bytes": "ab.." }`, `{ "constructor": 0, ... }`)
|
|
90
|
+
* — shorthand for `{ "uplc": "data", "value": <object> }`. This is the
|
|
91
|
+
* Aiken / CIP-57 blueprint convention, where every parameter is Data.
|
|
92
|
+
*/
|
|
93
|
+
export declare function encodeScriptParam(param: JSONValue): UPLCConst;
|
|
68
94
|
/**
|
|
69
95
|
* Apply parameters to a parameterized PlutusV3 script (CBOR-wrapped flat UPLC).
|
|
70
|
-
* Each parameter
|
|
71
|
-
*
|
|
72
|
-
*
|
|
96
|
+
* Each parameter becomes a successive UPLC Application wrapping the program body.
|
|
97
|
+
*
|
|
98
|
+
* Parameters are applied in their declared UPLC type via {@link encodeScriptParam}:
|
|
99
|
+
* pass `{ uplc, value }` entries for native-typed params (e.g. Pebble scalars),
|
|
100
|
+
* or bare PlutusData objects for the Data convention (Aiken / CIP-57 blueprints).
|
|
101
|
+
*
|
|
102
|
+
* @param scriptHex CBOR hex of the unapplied Plutus script (as output by Aiken/Pebble/Plutus compilers)
|
|
103
|
+
* @param params Array of script parameters (typed `{uplc,value}` and/or bare PlutusData JSON) to apply in order
|
|
73
104
|
* @returns CBOR hex of the applied script (ready for transaction building)
|
|
74
105
|
*/
|
|
75
106
|
export declare function applyScriptParameters(scriptHex: string, params: JSONValue[]): string;
|
|
@@ -7,6 +7,7 @@ exports.mapBuilderError = mapBuilderError;
|
|
|
7
7
|
exports.parseAssetUnit = parseAssetUnit;
|
|
8
8
|
exports.jsonToPlutusData = jsonToPlutusData;
|
|
9
9
|
exports.inlineDatumToHex = inlineDatumToHex;
|
|
10
|
+
exports.encodeScriptParam = encodeScriptParam;
|
|
10
11
|
exports.applyScriptParameters = applyScriptParameters;
|
|
11
12
|
const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
|
|
12
13
|
const crypto_1 = require("@harmoniclabs/crypto");
|
|
@@ -222,11 +223,81 @@ function inlineDatumToHex(datum) {
|
|
|
222
223
|
return null;
|
|
223
224
|
}
|
|
224
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Encode a single script parameter into the UPLC constant the parameterized
|
|
228
|
+
* script expects.
|
|
229
|
+
*
|
|
230
|
+
* A script parameter is applied as a UPLC constant whose TYPE must match what
|
|
231
|
+
* the compiled validator expects for that parameter. Two input shapes are
|
|
232
|
+
* accepted:
|
|
233
|
+
*
|
|
234
|
+
* 1. Typed — `{ "uplc": "<type>", "value": <...> }`:
|
|
235
|
+
* - `"data"` → `UPLCConst.data(...)` value: PlutusData JSON ("constr"/cardano-cli form)
|
|
236
|
+
* - `"bytes"` → `UPLCConst.byteString(...)` value: even-length hex string
|
|
237
|
+
* - `"int"` → `UPLCConst.int(...)` value: number | numeric string
|
|
238
|
+
* - `"bool"` → `UPLCConst.bool(...)` value: boolean
|
|
239
|
+
* - `"unit"` → `UPLCConst.unit` value: omitted
|
|
240
|
+
* Required for compilers whose scalar params are NATIVE-typed rather than
|
|
241
|
+
* Data-wrapped (e.g. Pebble: `param x: PubKeyHash` expects a native
|
|
242
|
+
* `bytestring`, not a `Data` bytestring).
|
|
243
|
+
*
|
|
244
|
+
* 2. Bare PlutusData object (e.g. `{ "bytes": "ab.." }`, `{ "constructor": 0, ... }`)
|
|
245
|
+
* — shorthand for `{ "uplc": "data", "value": <object> }`. This is the
|
|
246
|
+
* Aiken / CIP-57 blueprint convention, where every parameter is Data.
|
|
247
|
+
*/
|
|
248
|
+
function encodeScriptParam(param) {
|
|
249
|
+
if (param !== null &&
|
|
250
|
+
typeof param === 'object' &&
|
|
251
|
+
!Array.isArray(param) &&
|
|
252
|
+
'uplc' in param) {
|
|
253
|
+
const { uplc, value } = param;
|
|
254
|
+
switch (uplc) {
|
|
255
|
+
case 'data':
|
|
256
|
+
return uplc_1.UPLCConst.data(jsonToPlutusData(value));
|
|
257
|
+
case 'bytes': {
|
|
258
|
+
if (typeof value !== 'string' || !/^([0-9a-fA-F]{2})*$/.test(value)) {
|
|
259
|
+
throw new Error('Script param of uplc type "bytes" requires an even-length hex string "value"');
|
|
260
|
+
}
|
|
261
|
+
return uplc_1.UPLCConst.byteString((0, uint8array_utils_1.fromHex)(value));
|
|
262
|
+
}
|
|
263
|
+
case 'int': {
|
|
264
|
+
if (typeof value !== 'number' && typeof value !== 'string') {
|
|
265
|
+
throw new Error('Script param of uplc type "int" requires a number or numeric-string "value"');
|
|
266
|
+
}
|
|
267
|
+
let n;
|
|
268
|
+
try {
|
|
269
|
+
n = BigInt(value);
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
throw new Error(`Script param of uplc type "int" has a non-integer "value": ${String(value)}`);
|
|
273
|
+
}
|
|
274
|
+
return uplc_1.UPLCConst.int(n);
|
|
275
|
+
}
|
|
276
|
+
case 'bool': {
|
|
277
|
+
if (typeof value !== 'boolean') {
|
|
278
|
+
throw new Error('Script param of uplc type "bool" requires a boolean "value"');
|
|
279
|
+
}
|
|
280
|
+
return uplc_1.UPLCConst.bool(value);
|
|
281
|
+
}
|
|
282
|
+
case 'unit':
|
|
283
|
+
return uplc_1.UPLCConst.unit;
|
|
284
|
+
default:
|
|
285
|
+
throw new Error(`Unknown script param uplc type "${String(uplc)}"; expected one of: data, bytes, int, bool, unit`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// Bare PlutusData → apply as Data (Aiken / blueprint convention)
|
|
289
|
+
return uplc_1.UPLCConst.data(jsonToPlutusData(param));
|
|
290
|
+
}
|
|
225
291
|
/**
|
|
226
292
|
* Apply parameters to a parameterized PlutusV3 script (CBOR-wrapped flat UPLC).
|
|
227
|
-
* Each parameter
|
|
228
|
-
*
|
|
229
|
-
*
|
|
293
|
+
* Each parameter becomes a successive UPLC Application wrapping the program body.
|
|
294
|
+
*
|
|
295
|
+
* Parameters are applied in their declared UPLC type via {@link encodeScriptParam}:
|
|
296
|
+
* pass `{ uplc, value }` entries for native-typed params (e.g. Pebble scalars),
|
|
297
|
+
* or bare PlutusData objects for the Data convention (Aiken / CIP-57 blueprints).
|
|
298
|
+
*
|
|
299
|
+
* @param scriptHex CBOR hex of the unapplied Plutus script (as output by Aiken/Pebble/Plutus compilers)
|
|
300
|
+
* @param params Array of script parameters (typed `{uplc,value}` and/or bare PlutusData JSON) to apply in order
|
|
230
301
|
* @returns CBOR hex of the applied script (ready for transaction building)
|
|
231
302
|
*/
|
|
232
303
|
function applyScriptParameters(scriptHex, params) {
|
|
@@ -238,11 +309,10 @@ function applyScriptParameters(scriptHex, params) {
|
|
|
238
309
|
const flatBytes = cborObj.bytes;
|
|
239
310
|
// 2. Flat-decode → UPLCProgram
|
|
240
311
|
const program = uplc_1.UPLCDecoder.parse(flatBytes, 'flat');
|
|
241
|
-
// 3. Apply each parameter as Application(body,
|
|
312
|
+
// 3. Apply each parameter as Application(body, <typed UPLC constant>)
|
|
242
313
|
let body = program.body;
|
|
243
314
|
for (const param of params) {
|
|
244
|
-
|
|
245
|
-
body = new uplc_1.Application(body, uplc_1.UPLCConst.data(paramData));
|
|
315
|
+
body = new uplc_1.Application(body, encodeScriptParam(param));
|
|
246
316
|
}
|
|
247
317
|
// 4. Create new program with applied body, flat-encode, CBOR-wrap
|
|
248
318
|
const applied = new uplc_1.UPLCProgram(program.version, body);
|