@lucid-evolution/uplc 0.3.0 → 0.4.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.
@@ -2,11 +2,9 @@
2
2
  let imports = {};
3
3
  imports['__wbindgen_placeholder__'] = module.exports;
4
4
  let wasm;
5
- const { TextDecoder } = require(`util`);
5
+ const { TextEncoder, TextDecoder } = require(`util`);
6
6
 
7
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
8
-
9
- cachedTextDecoder.decode();
7
+ let WASM_VECTOR_LEN = 0;
10
8
 
11
9
  let cachedUint8ArrayMemory0 = null;
12
10
 
@@ -17,20 +15,64 @@ function getUint8ArrayMemory0() {
17
15
  return cachedUint8ArrayMemory0;
18
16
  }
19
17
 
20
- function getStringFromWasm0(ptr, len) {
21
- ptr = ptr >>> 0;
22
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
18
+ let cachedTextEncoder = new TextEncoder('utf-8');
19
+
20
+ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
21
+ ? function (arg, view) {
22
+ return cachedTextEncoder.encodeInto(arg, view);
23
23
  }
24
+ : function (arg, view) {
25
+ const buf = cachedTextEncoder.encode(arg);
26
+ view.set(buf);
27
+ return {
28
+ read: arg.length,
29
+ written: buf.length
30
+ };
31
+ });
24
32
 
25
- let WASM_VECTOR_LEN = 0;
33
+ function passStringToWasm0(arg, malloc, realloc) {
26
34
 
27
- function passArray8ToWasm0(arg, malloc) {
28
- const ptr = malloc(arg.length * 1, 1) >>> 0;
29
- getUint8ArrayMemory0().set(arg, ptr / 1);
30
- WASM_VECTOR_LEN = arg.length;
35
+ if (realloc === undefined) {
36
+ const buf = cachedTextEncoder.encode(arg);
37
+ const ptr = malloc(buf.length, 1) >>> 0;
38
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
39
+ WASM_VECTOR_LEN = buf.length;
40
+ return ptr;
41
+ }
42
+
43
+ let len = arg.length;
44
+ let ptr = malloc(len, 1) >>> 0;
45
+
46
+ const mem = getUint8ArrayMemory0();
47
+
48
+ let offset = 0;
49
+
50
+ for (; offset < len; offset++) {
51
+ const code = arg.charCodeAt(offset);
52
+ if (code > 0x7F) break;
53
+ mem[ptr + offset] = code;
54
+ }
55
+
56
+ if (offset !== len) {
57
+ if (offset !== 0) {
58
+ arg = arg.slice(offset);
59
+ }
60
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
61
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
62
+ const ret = encodeString(arg, view);
63
+
64
+ offset += ret.written;
65
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
66
+ }
67
+
68
+ WASM_VECTOR_LEN = offset;
31
69
  return ptr;
32
70
  }
33
71
 
72
+ function isLikeNone(x) {
73
+ return x === undefined || x === null;
74
+ }
75
+
34
76
  let cachedDataViewMemory0 = null;
35
77
 
36
78
  function getDataViewMemory0() {
@@ -40,6 +82,22 @@ function getDataViewMemory0() {
40
82
  return cachedDataViewMemory0;
41
83
  }
42
84
 
85
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
86
+
87
+ cachedTextDecoder.decode();
88
+
89
+ function getStringFromWasm0(ptr, len) {
90
+ ptr = ptr >>> 0;
91
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
92
+ }
93
+
94
+ function passArray8ToWasm0(arg, malloc) {
95
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
96
+ getUint8ArrayMemory0().set(arg, ptr / 1);
97
+ WASM_VECTOR_LEN = arg.length;
98
+ return ptr;
99
+ }
100
+
43
101
  function addToExternrefTable0(obj) {
44
102
  const idx = wasm.__externref_table_alloc();
45
103
  wasm.__wbindgen_export_0.set(idx, obj);
@@ -56,10 +114,6 @@ function passArrayJsValueToWasm0(array, malloc) {
56
114
  return ptr;
57
115
  }
58
116
 
59
- function isLikeNone(x) {
60
- return x === undefined || x === null;
61
- }
62
-
63
117
  function takeFromExternrefTable0(idx) {
64
118
  const value = wasm.__wbindgen_export_0.get(idx);
65
119
  wasm.__externref_table_dealloc(idx);
@@ -130,6 +184,204 @@ module.exports.apply_params_to_script = function(params_bytes, plutus_script_byt
130
184
  return v3;
131
185
  };
132
186
 
187
+ let cachedBigUint64ArrayMemory0 = null;
188
+
189
+ function getBigUint64ArrayMemory0() {
190
+ if (cachedBigUint64ArrayMemory0 === null || cachedBigUint64ArrayMemory0.byteLength === 0) {
191
+ cachedBigUint64ArrayMemory0 = new BigUint64Array(wasm.memory.buffer);
192
+ }
193
+ return cachedBigUint64ArrayMemory0;
194
+ }
195
+
196
+ function passArray64ToWasm0(arg, malloc) {
197
+ const ptr = malloc(arg.length * 8, 8) >>> 0;
198
+ getBigUint64ArrayMemory0().set(arg, ptr / 8);
199
+ WASM_VECTOR_LEN = arg.length;
200
+ return ptr;
201
+ }
202
+ /**
203
+ * Evaluates a UPLC program applied to Data arguments, outside of any
204
+ * transaction: the caller builds whatever arguments the program expects,
205
+ * including its script context.
206
+ *
207
+ * - `program_flat`: the program, flat-encoded without a CBOR wrapper.
208
+ * - `args_cbor`: the arguments, each one CBOR-encoded Data, applied in order.
209
+ * - `language`: the Plutus version to evaluate as, 1, 2 or 3.
210
+ * - `protocol_major_version`: the protocol version whose semantics to use,
211
+ * from 5 (Alonzo) to 12 (Dijkstra).
212
+ * - `cost_model`: the cost model parameters, every one the evaluator knows
213
+ * for this Plutus version (350 for Plutus V3), in the ledger's order.
214
+ * - `budget_cpu`, `budget_mem`: the budget.
215
+ * - `strict_budget`: charge every step as the machine takes it, and stop the
216
+ * program as soon as it goes over budget, instead of charging steps and
217
+ * checking the budget every 200 steps as the ledger does. Only the cost of a
218
+ * program that fails differs: the ledger does not charge the steps it took
219
+ * since the budget was last checked.
220
+ *
221
+ * Fails only when the inputs are malformed or unsupported. A program that fails
222
+ * is an [`EvalProgramResult`] that is not `ok`.
223
+ * @param {Uint8Array} program_flat
224
+ * @param {Uint8Array[]} args_cbor
225
+ * @param {number} language
226
+ * @param {number} protocol_major_version
227
+ * @param {BigInt64Array} cost_model
228
+ * @param {bigint} budget_cpu
229
+ * @param {bigint} budget_mem
230
+ * @param {boolean} strict_budget
231
+ * @returns {EvalProgramResult}
232
+ */
233
+ module.exports.eval_program_raw = function(program_flat, args_cbor, language, protocol_major_version, cost_model, budget_cpu, budget_mem, strict_budget) {
234
+ const ptr0 = passArray8ToWasm0(program_flat, wasm.__wbindgen_malloc);
235
+ const len0 = WASM_VECTOR_LEN;
236
+ const ptr1 = passArrayJsValueToWasm0(args_cbor, wasm.__wbindgen_malloc);
237
+ const len1 = WASM_VECTOR_LEN;
238
+ const ptr2 = passArray64ToWasm0(cost_model, wasm.__wbindgen_malloc);
239
+ const len2 = WASM_VECTOR_LEN;
240
+ const ret = wasm.eval_program_raw(ptr0, len0, ptr1, len1, language, protocol_major_version, ptr2, len2, budget_cpu, budget_mem, strict_budget);
241
+ if (ret[2]) {
242
+ throw takeFromExternrefTable0(ret[1]);
243
+ }
244
+ return EvalProgramResult.__wrap(ret[0]);
245
+ };
246
+
247
+ /**
248
+ * Describes this build of the evaluator as JSON: the uplc crate it was built
249
+ * from, the length of each Plutus version's cost model, and a digest of what a
250
+ * fixed set of programs evaluate to, with their costs, under Plutus V3 and the
251
+ * latest protocol version. Two builds with the same digest agree on those
252
+ * programs; `selfTest` says whether this one gives the expected results.
253
+ * @returns {string}
254
+ */
255
+ module.exports.uplc_build_info = function() {
256
+ let deferred1_0;
257
+ let deferred1_1;
258
+ try {
259
+ const ret = wasm.uplc_build_info();
260
+ deferred1_0 = ret[0];
261
+ deferred1_1 = ret[1];
262
+ return getStringFromWasm0(ret[0], ret[1]);
263
+ } finally {
264
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
265
+ }
266
+ };
267
+
268
+ const EvalProgramResultFinalization = (typeof FinalizationRegistry === 'undefined')
269
+ ? { register: () => {}, unregister: () => {} }
270
+ : new FinalizationRegistry(ptr => wasm.__wbg_evalprogramresult_free(ptr >>> 0, 1));
271
+ /**
272
+ * The outcome of [`eval_program_raw`].
273
+ */
274
+ class EvalProgramResult {
275
+
276
+ static __wrap(ptr) {
277
+ ptr = ptr >>> 0;
278
+ const obj = Object.create(EvalProgramResult.prototype);
279
+ obj.__wbg_ptr = ptr;
280
+ EvalProgramResultFinalization.register(obj, obj.__wbg_ptr, obj);
281
+ return obj;
282
+ }
283
+
284
+ __destroy_into_raw() {
285
+ const ptr = this.__wbg_ptr;
286
+ this.__wbg_ptr = 0;
287
+ EvalProgramResultFinalization.unregister(this);
288
+ return ptr;
289
+ }
290
+
291
+ free() {
292
+ const ptr = this.__destroy_into_raw();
293
+ wasm.__wbg_evalprogramresult_free(ptr, 0);
294
+ }
295
+ /**
296
+ * Whether the program succeeded: it did not fail and, for Plutus V3, it
297
+ * returned unit.
298
+ * @returns {boolean}
299
+ */
300
+ get ok() {
301
+ const ret = wasm.__wbg_get_evalprogramresult_ok(this.__wbg_ptr);
302
+ return ret !== 0;
303
+ }
304
+ /**
305
+ * Whether the program succeeded: it did not fail and, for Plutus V3, it
306
+ * returned unit.
307
+ * @param {boolean} arg0
308
+ */
309
+ set ok(arg0) {
310
+ wasm.__wbg_set_evalprogramresult_ok(this.__wbg_ptr, arg0);
311
+ }
312
+ /**
313
+ * The CPU the program used. A program that went over budget is charged
314
+ * what it used up to the point where the machine stopped it.
315
+ * @returns {bigint}
316
+ */
317
+ get cpu() {
318
+ const ret = wasm.__wbg_get_evalprogramresult_cpu(this.__wbg_ptr);
319
+ return BigInt.asUintN(64, ret);
320
+ }
321
+ /**
322
+ * The CPU the program used. A program that went over budget is charged
323
+ * what it used up to the point where the machine stopped it.
324
+ * @param {bigint} arg0
325
+ */
326
+ set cpu(arg0) {
327
+ wasm.__wbg_set_evalprogramresult_cpu(this.__wbg_ptr, arg0);
328
+ }
329
+ /**
330
+ * The memory the program used.
331
+ * @returns {bigint}
332
+ */
333
+ get mem() {
334
+ const ret = wasm.__wbg_get_evalprogramresult_mem(this.__wbg_ptr);
335
+ return BigInt.asUintN(64, ret);
336
+ }
337
+ /**
338
+ * The memory the program used.
339
+ * @param {bigint} arg0
340
+ */
341
+ set mem(arg0) {
342
+ wasm.__wbg_set_evalprogramresult_mem(this.__wbg_ptr, arg0);
343
+ }
344
+ /**
345
+ * Why the program did not succeed: 0 when it did, 1 when it went over
346
+ * budget, 2 when it failed in any other way and 3 when a Plutus V3 program
347
+ * returned something other than unit.
348
+ * @returns {number}
349
+ */
350
+ get error_kind() {
351
+ const ret = wasm.__wbg_get_evalprogramresult_error_kind(this.__wbg_ptr);
352
+ return ret;
353
+ }
354
+ /**
355
+ * Why the program did not succeed: 0 when it did, 1 when it went over
356
+ * budget, 2 when it failed in any other way and 3 when a Plutus V3 program
357
+ * returned something other than unit.
358
+ * @param {number} arg0
359
+ */
360
+ set error_kind(arg0) {
361
+ wasm.__wbg_set_evalprogramresult_error_kind(this.__wbg_ptr, arg0);
362
+ }
363
+ /**
364
+ * The messages the program traced, in order.
365
+ * @returns {string[]}
366
+ */
367
+ get logs() {
368
+ const ret = wasm.__wbg_get_evalprogramresult_logs(this.__wbg_ptr);
369
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
370
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
371
+ return v1;
372
+ }
373
+ /**
374
+ * The messages the program traced, in order.
375
+ * @param {string[]} arg0
376
+ */
377
+ set logs(arg0) {
378
+ const ptr0 = passArrayJsValueToWasm0(arg0, wasm.__wbindgen_malloc);
379
+ const len0 = WASM_VECTOR_LEN;
380
+ wasm.__wbg_set_evalprogramresult_logs(this.__wbg_ptr, ptr0, len0);
381
+ }
382
+ }
383
+ module.exports.EvalProgramResult = EvalProgramResult;
384
+
133
385
  module.exports.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
134
386
  const ret = arg0.buffer;
135
387
  return ret;
@@ -170,6 +422,15 @@ module.exports.__wbindgen_memory = function() {
170
422
  return ret;
171
423
  };
172
424
 
425
+ module.exports.__wbindgen_string_get = function(arg0, arg1) {
426
+ const obj = arg1;
427
+ const ret = typeof(obj) === 'string' ? obj : undefined;
428
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
429
+ var len1 = WASM_VECTOR_LEN;
430
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
431
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
432
+ };
433
+
173
434
  module.exports.__wbindgen_string_new = function(arg0, arg1) {
174
435
  const ret = getStringFromWasm0(arg0, arg1);
175
436
  return ret;
Binary file
@@ -1,6 +1,24 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
+ export const __wbg_evalprogramresult_free: (a: number, b: number) => void;
5
+ export const __wbg_get_evalprogramresult_cpu: (a: number) => bigint;
6
+ export const __wbg_get_evalprogramresult_error_kind: (a: number) => number;
7
+ export const __wbg_get_evalprogramresult_logs: (a: number) => [number, number];
8
+ export const __wbg_get_evalprogramresult_mem: (a: number) => bigint;
9
+ export const __wbg_get_evalprogramresult_ok: (a: number) => number;
10
+ export const __wbg_set_evalprogramresult_cpu: (a: number, b: bigint) => void;
11
+ export const __wbg_set_evalprogramresult_error_kind: (
12
+ a: number,
13
+ b: number,
14
+ ) => void;
15
+ export const __wbg_set_evalprogramresult_logs: (
16
+ a: number,
17
+ b: number,
18
+ c: number,
19
+ ) => void;
20
+ export const __wbg_set_evalprogramresult_mem: (a: number, b: bigint) => void;
21
+ export const __wbg_set_evalprogramresult_ok: (a: number, b: number) => void;
4
22
  export const apply_params_to_script: (
5
23
  a: number,
6
24
  b: number,
@@ -24,8 +42,28 @@ export const eval_phase_two_raw: (
24
42
  n: number,
25
43
  o: number,
26
44
  ) => [number, number, number, number];
45
+ export const eval_program_raw: (
46
+ a: number,
47
+ b: number,
48
+ c: number,
49
+ d: number,
50
+ e: number,
51
+ f: number,
52
+ g: number,
53
+ h: number,
54
+ i: bigint,
55
+ j: bigint,
56
+ k: number,
57
+ ) => [number, number, number];
58
+ export const uplc_build_info: () => [number, number];
27
59
  export const __wbindgen_export_0: WebAssembly.Table;
28
60
  export const __wbindgen_malloc: (a: number, b: number) => number;
61
+ export const __wbindgen_realloc: (
62
+ a: number,
63
+ b: number,
64
+ c: number,
65
+ d: number,
66
+ ) => number;
29
67
  export const __externref_table_alloc: () => number;
30
68
  export const __externref_table_dealloc: (a: number) => void;
31
69
  export const __externref_drop_slice: (a: number, b: number) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucid-evolution/uplc",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "main": "./dist/speed/node/uplc_tx.js",
5
5
  "browser": "./dist/size/browser/uplc_tx.js",
6
6
  "types": "./dist/speed/node/uplc_tx.d.ts",
@@ -48,10 +48,14 @@
48
48
  "publishConfig": {
49
49
  "access": "public"
50
50
  },
51
+ "devDependencies": {
52
+ "vitest": "^2.1.8"
53
+ },
51
54
  "scripts": {
52
55
  "build-local": "rm -rf dist && cd rust && wasm-pack build --target bundler --out-dir ../src/speed/browser && wasm-pack build --target nodejs --out-dir ../src/speed/node && wasm-pack build --profile release-size --target bundler --out-dir ../src/size/browser && wasm-pack build --profile release-size --target nodejs --out-dir ../src/size/node && cd .. && pnpm clean-garbage",
53
56
  "build": "cp -r src dist",
54
57
  "clean-garbage": "for d in speed/browser speed/node size/browser size/node; do rm -f src/$d/.gitignore src/$d/package.json; done",
55
- "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
58
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
59
+ "test": "vitest run"
56
60
  }
57
61
  }