@lucid-evolution/uplc 0.5.0 → 0.5.1

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.
@@ -1,324 +1,11 @@
1
-
2
- let imports = {};
3
- imports['__wbindgen_placeholder__'] = module.exports;
4
- let wasm;
5
- const { TextEncoder, TextDecoder } = require(`util`);
6
-
7
- let WASM_VECTOR_LEN = 0;
8
-
9
- let cachedUint8ArrayMemory0 = null;
10
-
11
- function getUint8ArrayMemory0() {
12
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
13
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
14
- }
15
- return cachedUint8ArrayMemory0;
16
- }
17
-
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
- }
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
- });
32
-
33
- function passStringToWasm0(arg, malloc, realloc) {
34
-
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;
69
- return ptr;
70
- }
71
-
72
- function isLikeNone(x) {
73
- return x === undefined || x === null;
74
- }
75
-
76
- let cachedDataViewMemory0 = null;
77
-
78
- function getDataViewMemory0() {
79
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
80
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
81
- }
82
- return cachedDataViewMemory0;
83
- }
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
-
101
- function addToExternrefTable0(obj) {
102
- const idx = wasm.__externref_table_alloc();
103
- wasm.__wbindgen_export_0.set(idx, obj);
104
- return idx;
105
- }
106
-
107
- function passArrayJsValueToWasm0(array, malloc) {
108
- const ptr = malloc(array.length * 4, 4) >>> 0;
109
- for (let i = 0; i < array.length; i++) {
110
- const add = addToExternrefTable0(array[i]);
111
- getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
112
- }
113
- WASM_VECTOR_LEN = array.length;
114
- return ptr;
115
- }
116
-
117
- function takeFromExternrefTable0(idx) {
118
- const value = wasm.__wbindgen_export_0.get(idx);
119
- wasm.__externref_table_dealloc(idx);
120
- return value;
121
- }
122
-
123
- function getArrayJsValueFromWasm0(ptr, len) {
124
- ptr = ptr >>> 0;
125
- const mem = getDataViewMemory0();
126
- const result = [];
127
- for (let i = ptr; i < ptr + 4 * len; i += 4) {
128
- result.push(wasm.__wbindgen_export_0.get(mem.getUint32(i, true)));
129
- }
130
- wasm.__externref_drop_slice(ptr, len);
131
- return result;
132
- }
133
- /**
134
- * @param {Uint8Array} tx_bytes
135
- * @param {Uint8Array[]} utxos_bytes_x
136
- * @param {Uint8Array[]} utxos_bytes_y
137
- * @param {Uint8Array} cost_mdls_bytes
138
- * @param {bigint} initial_budget_n
139
- * @param {bigint} initial_budget_d
140
- * @param {bigint} slot_config_x
141
- * @param {bigint} slot_config_y
142
- * @param {number} slot_config_z
143
- * @param {number | null} [protocol_major_version]
144
- * @returns {Uint8Array[]}
145
- */
146
- module.exports.eval_phase_two_raw = function(tx_bytes, utxos_bytes_x, utxos_bytes_y, cost_mdls_bytes, initial_budget_n, initial_budget_d, slot_config_x, slot_config_y, slot_config_z, protocol_major_version) {
147
- const ptr0 = passArray8ToWasm0(tx_bytes, wasm.__wbindgen_malloc);
148
- const len0 = WASM_VECTOR_LEN;
149
- const ptr1 = passArrayJsValueToWasm0(utxos_bytes_x, wasm.__wbindgen_malloc);
150
- const len1 = WASM_VECTOR_LEN;
151
- const ptr2 = passArrayJsValueToWasm0(utxos_bytes_y, wasm.__wbindgen_malloc);
152
- const len2 = WASM_VECTOR_LEN;
153
- const ptr3 = passArray8ToWasm0(cost_mdls_bytes, wasm.__wbindgen_malloc);
154
- const len3 = WASM_VECTOR_LEN;
155
- const ret = wasm.eval_phase_two_raw(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, initial_budget_n, initial_budget_d, slot_config_x, slot_config_y, slot_config_z, !isLikeNone(protocol_major_version), isLikeNone(protocol_major_version) ? 0 : protocol_major_version);
156
- if (ret[3]) {
157
- throw takeFromExternrefTable0(ret[2]);
158
- }
159
- var v5 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
160
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
161
- return v5;
162
- };
163
-
164
- function getArrayU8FromWasm0(ptr, len) {
165
- ptr = ptr >>> 0;
166
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
167
- }
168
- /**
169
- * @param {Uint8Array} params_bytes
170
- * @param {Uint8Array} plutus_script_bytes
171
- * @returns {Uint8Array}
172
- */
173
- module.exports.apply_params_to_script = function(params_bytes, plutus_script_bytes) {
174
- const ptr0 = passArray8ToWasm0(params_bytes, wasm.__wbindgen_malloc);
175
- const len0 = WASM_VECTOR_LEN;
176
- const ptr1 = passArray8ToWasm0(plutus_script_bytes, wasm.__wbindgen_malloc);
177
- const len1 = WASM_VECTOR_LEN;
178
- const ret = wasm.apply_params_to_script(ptr0, len0, ptr1, len1);
179
- if (ret[3]) {
180
- throw takeFromExternrefTable0(ret[2]);
181
- }
182
- var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
183
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
184
- return v3;
185
- };
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
- /**
269
- * Evaluates the builtin `tag` applied to `args` as a Plutus V3 script
270
- * evaluates it at a protocol version, without any program around it: the
271
- * result, or how it fails, is what the machine gives for the saturated
272
- * application.
273
- *
274
- * - `tag`: the builtin's flat tag (0 for addInteger to 100 for scaleValue).
275
- * The Miller-loop builtins (68 to 70) are not supported, since their
276
- * results cannot be returned.
277
- * - `args`: exactly the builtin's arguments, in order, each encoded as the
278
- * matching entry of `arg_kinds` says, a [`BuiltinValueKind`]: 0 for a
279
- * flat-encoded `(program 1.1.0 (con …))`, 1 for a compressed G1 point, 2
280
- * for a compressed G2 point, 3 for a list of G1 points, 4 for a list of G2
281
- * points, 5 for an array of G1 points and 6 for an array of G2 points, each
282
- * list or array as the compressed points one after the other. Flat cannot
283
- * encode BLS12-381 points, so they cross as their compressed bytes.
284
- * - `protocol_major_version`: from 9 (Chang, which introduced Plutus V3) to
285
- * 12 (Dijkstra). It decides which builtins are available and the semantics
286
- * they have.
287
- *
288
- * The result's `cpu` and `mem` are the builtin's charge for the application
289
- * under Plutus' default Plutus V3 cost model (not the ledger's protocol
290
- * parameters), excluding the machine's per-step costs.
291
- *
292
- * Fails only when the inputs are malformed or unsupported: an unknown or
293
- * Miller-loop tag, a number of arguments other than the builtin's arity, an
294
- * argument that does not decode as its kind says or is not a constant, an
295
- * invalid compressed point, a protocol version out of range, or a result that
296
- * none of the kinds can encode. A builtin that fails is an
297
- * [`EvalBuiltinResult`] that is not `ok`.
298
- * @param {number} tag
299
- * @param {Uint8Array[]} args
300
- * @param {Uint8Array} arg_kinds
301
- * @param {number} protocol_major_version
302
- * @returns {EvalBuiltinResult}
303
- */
304
- module.exports.eval_builtin_raw = function(tag, args, arg_kinds, protocol_major_version) {
305
- const ptr0 = passArrayJsValueToWasm0(args, wasm.__wbindgen_malloc);
306
- const len0 = WASM_VECTOR_LEN;
307
- const ptr1 = passArray8ToWasm0(arg_kinds, wasm.__wbindgen_malloc);
308
- const len1 = WASM_VECTOR_LEN;
309
- const ret = wasm.eval_builtin_raw(tag, ptr0, len0, ptr1, len1, protocol_major_version);
310
- if (ret[2]) {
311
- throw takeFromExternrefTable0(ret[1]);
312
- }
313
- return EvalBuiltinResult.__wrap(ret[0]);
314
- };
1
+ /* @ts-self-types="./uplc_tx.d.ts" */
315
2
 
316
3
  /**
317
4
  * Why the builtin given to [`eval_builtin_raw`] did not return a value: the
318
5
  * codes of the result's `error_kind`.
319
6
  * @enum {0 | 1 | 2 | 3}
320
7
  */
321
- module.exports.BuiltinErrorKind = Object.freeze({
8
+ const BuiltinErrorKind = Object.freeze({
322
9
  /**
323
10
  * The builtin returned a value.
324
11
  */
@@ -337,12 +24,14 @@ module.exports.BuiltinErrorKind = Object.freeze({
337
24
  */
338
25
  Failed: 3, "3": "Failed",
339
26
  });
27
+ exports.BuiltinErrorKind = BuiltinErrorKind;
28
+
340
29
  /**
341
30
  * How a value of [`eval_builtin_raw`] is encoded: the codes of its
342
31
  * `arg_kinds` and of the result's `result_kind`.
343
32
  * @enum {0 | 1 | 2 | 3 | 4 | 5 | 6}
344
33
  */
345
- module.exports.BuiltinValueKind = Object.freeze({
34
+ const BuiltinValueKind = Object.freeze({
346
35
  /**
347
36
  * A flat-encoded program whose body is a constant,
348
37
  * `(program 1.1.0 (con …))`. A result in this form is always version
@@ -378,48 +67,48 @@ module.exports.BuiltinValueKind = Object.freeze({
378
67
  */
379
68
  G2Array: 6, "6": "G2Array",
380
69
  });
70
+ exports.BuiltinValueKind = BuiltinValueKind;
381
71
 
382
- const EvalBuiltinResultFinalization = (typeof FinalizationRegistry === 'undefined')
383
- ? { register: () => {}, unregister: () => {} }
384
- : new FinalizationRegistry(ptr => wasm.__wbg_evalbuiltinresult_free(ptr >>> 0, 1));
385
72
  /**
386
73
  * The outcome of [`eval_builtin_raw`].
387
74
  */
388
75
  class EvalBuiltinResult {
389
-
390
76
  static __wrap(ptr) {
391
- ptr = ptr >>> 0;
392
77
  const obj = Object.create(EvalBuiltinResult.prototype);
393
78
  obj.__wbg_ptr = ptr;
394
- EvalBuiltinResultFinalization.register(obj, obj.__wbg_ptr, obj);
79
+ Object.defineProperty(obj, '__wbg_inst', { value: __wbg_instance_id, writable: true });
80
+
81
+ EvalBuiltinResultFinalization.register(obj, { ptr, instance: __wbg_instance_id }, obj);
395
82
  return obj;
396
83
  }
397
-
398
84
  __destroy_into_raw() {
399
85
  const ptr = this.__wbg_ptr;
400
86
  this.__wbg_ptr = 0;
401
87
  EvalBuiltinResultFinalization.unregister(this);
402
88
  return ptr;
403
89
  }
404
-
405
90
  free() {
406
91
  const ptr = this.__destroy_into_raw();
92
+ __wbg_call_guard();
407
93
  wasm.__wbg_evalbuiltinresult_free(ptr, 0);
94
+
408
95
  }
409
96
  /**
410
- * Whether the builtin returned a value.
411
- * @returns {boolean}
412
- */
413
- get ok() {
414
- const ret = wasm.__wbg_get_evalbuiltinresult_ok(this.__wbg_ptr);
415
- return ret !== 0;
416
- }
417
- /**
418
- * Whether the builtin returned a value.
419
- * @param {boolean} arg0
97
+ * The CPU the builtin's cost model charges for this application, under
98
+ * Plutus' default cost model for Plutus V3 at the protocol version; 0
99
+ * when the builtin was not costed (error kinds 1 and 2). It leaves out the
100
+ * machine's own step costs for evaluating the application (the builtin,
101
+ * each force and each apply).
102
+ * @returns {bigint}
420
103
  */
421
- set ok(arg0) {
422
- wasm.__wbg_set_evalbuiltinresult_ok(this.__wbg_ptr, arg0);
104
+ get cpu() {
105
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
106
+ throw new Error('Invalid stale object from previous Wasm instance');
107
+ }
108
+ let ret;
109
+ __wbg_call_guard();
110
+ ret = wasm.__wbg_get_evalbuiltinresult_cpu(this.__wbg_ptr);
111
+ return BigInt.asUintN(64, ret);
423
112
  }
424
113
  /**
425
114
  * Why the builtin did not return a value, a [`BuiltinErrorKind`]: 0 when
@@ -429,9 +118,108 @@ class EvalBuiltinResult {
429
118
  * @returns {number}
430
119
  */
431
120
  get error_kind() {
432
- const ret = wasm.__wbg_get_evalbuiltinresult_error_kind(this.__wbg_ptr);
121
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
122
+ throw new Error('Invalid stale object from previous Wasm instance');
123
+ }
124
+ let ret;
125
+ __wbg_call_guard();
126
+ ret = wasm.__wbg_get_evalbuiltinresult_error_kind(this.__wbg_ptr);
433
127
  return ret;
434
128
  }
129
+ /**
130
+ * The evaluator's description of why the builtin did not return a value;
131
+ * empty when it did.
132
+ * @returns {string}
133
+ */
134
+ get error() {
135
+ let deferred1_0;
136
+ let deferred1_1;
137
+ try {
138
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
139
+ throw new Error('Invalid stale object from previous Wasm instance');
140
+ }
141
+ let ret;
142
+ __wbg_call_guard();
143
+ ret = wasm.__wbg_get_evalbuiltinresult_error(this.__wbg_ptr);
144
+ deferred1_0 = ret[0];
145
+ deferred1_1 = ret[1];
146
+ return getStringFromWasm0(ret[0], ret[1]);
147
+ } finally {
148
+ __wbg_call_guard();
149
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
150
+ }
151
+ }
152
+ /**
153
+ * The memory the builtin's cost model charges for this application; see
154
+ * `cpu`.
155
+ * @returns {bigint}
156
+ */
157
+ get mem() {
158
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
159
+ throw new Error('Invalid stale object from previous Wasm instance');
160
+ }
161
+ let ret;
162
+ __wbg_call_guard();
163
+ ret = wasm.__wbg_get_evalbuiltinresult_mem(this.__wbg_ptr);
164
+ return BigInt.asUintN(64, ret);
165
+ }
166
+ /**
167
+ * Whether the builtin returned a value.
168
+ * @returns {boolean}
169
+ */
170
+ get ok() {
171
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
172
+ throw new Error('Invalid stale object from previous Wasm instance');
173
+ }
174
+ let ret;
175
+ __wbg_call_guard();
176
+ ret = wasm.__wbg_get_evalbuiltinresult_ok(this.__wbg_ptr);
177
+ return ret !== 0;
178
+ }
179
+ /**
180
+ * How `result` encodes the value, a [`BuiltinValueKind`] as for the
181
+ * arguments of [`eval_builtin_raw`]; 0 when there is no value.
182
+ * @returns {number}
183
+ */
184
+ get result_kind() {
185
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
186
+ throw new Error('Invalid stale object from previous Wasm instance');
187
+ }
188
+ let ret;
189
+ __wbg_call_guard();
190
+ ret = wasm.__wbg_get_evalbuiltinresult_result_kind(this.__wbg_ptr);
191
+ return ret;
192
+ }
193
+ /**
194
+ * The value the builtin returned; empty when there is none.
195
+ * @returns {Uint8Array}
196
+ */
197
+ get result() {
198
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
199
+ throw new Error('Invalid stale object from previous Wasm instance');
200
+ }
201
+ let ret;
202
+ __wbg_call_guard();
203
+ ret = wasm.__wbg_get_evalbuiltinresult_result(this.__wbg_ptr);
204
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
205
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
206
+ return v1;
207
+ }
208
+ /**
209
+ * The CPU the builtin's cost model charges for this application, under
210
+ * Plutus' default cost model for Plutus V3 at the protocol version; 0
211
+ * when the builtin was not costed (error kinds 1 and 2). It leaves out the
212
+ * machine's own step costs for evaluating the application (the builtin,
213
+ * each force and each apply).
214
+ * @param {bigint} arg0
215
+ */
216
+ set cpu(arg0) {
217
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
218
+ throw new Error('Invalid stale object from previous Wasm instance');
219
+ }
220
+ __wbg_call_guard();
221
+ wasm.__wbg_set_evalbuiltinresult_cpu(this.__wbg_ptr, arg0);
222
+ }
435
223
  /**
436
224
  * Why the builtin did not return a value, a [`BuiltinErrorKind`]: 0 when
437
225
  * it did, 1 when it is not available to Plutus V3 at the protocol version,
@@ -440,16 +228,48 @@ class EvalBuiltinResult {
440
228
  * @param {number} arg0
441
229
  */
442
230
  set error_kind(arg0) {
231
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
232
+ throw new Error('Invalid stale object from previous Wasm instance');
233
+ }
234
+ __wbg_call_guard();
443
235
  wasm.__wbg_set_evalbuiltinresult_error_kind(this.__wbg_ptr, arg0);
444
236
  }
445
237
  /**
446
- * How `result` encodes the value, a [`BuiltinValueKind`] as for the
447
- * arguments of [`eval_builtin_raw`]; 0 when there is no value.
448
- * @returns {number}
238
+ * The evaluator's description of why the builtin did not return a value;
239
+ * empty when it did.
240
+ * @param {string} arg0
449
241
  */
450
- get result_kind() {
451
- const ret = wasm.__wbg_get_evalbuiltinresult_result_kind(this.__wbg_ptr);
452
- return ret;
242
+ set error(arg0) {
243
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
244
+ throw new Error('Invalid stale object from previous Wasm instance');
245
+ }
246
+ const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
247
+ const len0 = WASM_VECTOR_LEN;
248
+ __wbg_call_guard();
249
+ wasm.__wbg_set_evalbuiltinresult_error(this.__wbg_ptr, ptr0, len0);
250
+ }
251
+ /**
252
+ * The memory the builtin's cost model charges for this application; see
253
+ * `cpu`.
254
+ * @param {bigint} arg0
255
+ */
256
+ set mem(arg0) {
257
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
258
+ throw new Error('Invalid stale object from previous Wasm instance');
259
+ }
260
+ __wbg_call_guard();
261
+ wasm.__wbg_set_evalbuiltinresult_mem(this.__wbg_ptr, arg0);
262
+ }
263
+ /**
264
+ * Whether the builtin returned a value.
265
+ * @param {boolean} arg0
266
+ */
267
+ set ok(arg0) {
268
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
269
+ throw new Error('Invalid stale object from previous Wasm instance');
270
+ }
271
+ __wbg_call_guard();
272
+ wasm.__wbg_set_evalbuiltinresult_ok(this.__wbg_ptr, arg0);
453
273
  }
454
274
  /**
455
275
  * How `result` encodes the value, a [`BuiltinValueKind`] as for the
@@ -457,279 +277,595 @@ class EvalBuiltinResult {
457
277
  * @param {number} arg0
458
278
  */
459
279
  set result_kind(arg0) {
280
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
281
+ throw new Error('Invalid stale object from previous Wasm instance');
282
+ }
283
+ __wbg_call_guard();
460
284
  wasm.__wbg_set_evalbuiltinresult_result_kind(this.__wbg_ptr, arg0);
461
285
  }
462
- /**
463
- * The value the builtin returned; empty when there is none.
464
- * @returns {Uint8Array}
465
- */
466
- get result() {
467
- const ret = wasm.__wbg_get_evalbuiltinresult_result(this.__wbg_ptr);
468
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
469
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
470
- return v1;
471
- }
472
286
  /**
473
287
  * The value the builtin returned; empty when there is none.
474
288
  * @param {Uint8Array} arg0
475
289
  */
476
290
  set result(arg0) {
291
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
292
+ throw new Error('Invalid stale object from previous Wasm instance');
293
+ }
477
294
  const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
478
295
  const len0 = WASM_VECTOR_LEN;
296
+ __wbg_call_guard();
479
297
  wasm.__wbg_set_evalbuiltinresult_result(this.__wbg_ptr, ptr0, len0);
480
298
  }
299
+ }
300
+ if (Symbol.dispose) EvalBuiltinResult.prototype[Symbol.dispose] = EvalBuiltinResult.prototype.free;
301
+ exports.EvalBuiltinResult = EvalBuiltinResult;
302
+
303
+ /**
304
+ * The outcome of [`eval_program_raw`].
305
+ */
306
+ class EvalProgramResult {
307
+ static __wrap(ptr) {
308
+ const obj = Object.create(EvalProgramResult.prototype);
309
+ obj.__wbg_ptr = ptr;
310
+ Object.defineProperty(obj, '__wbg_inst', { value: __wbg_instance_id, writable: true });
311
+
312
+ EvalProgramResultFinalization.register(obj, { ptr, instance: __wbg_instance_id }, obj);
313
+ return obj;
314
+ }
315
+ __destroy_into_raw() {
316
+ const ptr = this.__wbg_ptr;
317
+ this.__wbg_ptr = 0;
318
+ EvalProgramResultFinalization.unregister(this);
319
+ return ptr;
320
+ }
321
+ free() {
322
+ const ptr = this.__destroy_into_raw();
323
+ __wbg_call_guard();
324
+ wasm.__wbg_evalprogramresult_free(ptr, 0);
325
+
326
+ }
481
327
  /**
482
- * The CPU the builtin's cost model charges for this application, under
483
- * Plutus' default cost model for Plutus V3 at the protocol version; 0
484
- * when the builtin was not costed (error kinds 1 and 2). It leaves out the
485
- * machine's own step costs for evaluating the application (the builtin,
486
- * each force and each apply).
328
+ * The CPU the program used. A program that went over budget is charged
329
+ * what it used up to the point where the machine stopped it.
487
330
  * @returns {bigint}
488
331
  */
489
332
  get cpu() {
490
- const ret = wasm.__wbg_get_evalbuiltinresult_cpu(this.__wbg_ptr);
333
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
334
+ throw new Error('Invalid stale object from previous Wasm instance');
335
+ }
336
+ let ret;
337
+ __wbg_call_guard();
338
+ ret = wasm.__wbg_get_evalprogramresult_cpu(this.__wbg_ptr);
491
339
  return BigInt.asUintN(64, ret);
492
340
  }
493
341
  /**
494
- * The CPU the builtin's cost model charges for this application, under
495
- * Plutus' default cost model for Plutus V3 at the protocol version; 0
496
- * when the builtin was not costed (error kinds 1 and 2). It leaves out the
497
- * machine's own step costs for evaluating the application (the builtin,
498
- * each force and each apply).
499
- * @param {bigint} arg0
342
+ * Why the program did not succeed: 0 when it did, 1 when it went over
343
+ * budget, 2 when it failed in any other way and 3 when a Plutus V3 program
344
+ * returned something other than unit.
345
+ * @returns {number}
500
346
  */
501
- set cpu(arg0) {
502
- wasm.__wbg_set_evalbuiltinresult_cpu(this.__wbg_ptr, arg0);
347
+ get error_kind() {
348
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
349
+ throw new Error('Invalid stale object from previous Wasm instance');
350
+ }
351
+ let ret;
352
+ __wbg_call_guard();
353
+ ret = wasm.__wbg_get_evalprogramresult_error_kind(this.__wbg_ptr);
354
+ return ret;
503
355
  }
504
356
  /**
505
- * The memory the builtin's cost model charges for this application; see
506
- * `cpu`.
357
+ * The messages the program traced, in order.
358
+ * @returns {string[]}
359
+ */
360
+ get logs() {
361
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
362
+ throw new Error('Invalid stale object from previous Wasm instance');
363
+ }
364
+ let ret;
365
+ __wbg_call_guard();
366
+ ret = wasm.__wbg_get_evalprogramresult_logs(this.__wbg_ptr);
367
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
368
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
369
+ return v1;
370
+ }
371
+ /**
372
+ * The memory the program used.
507
373
  * @returns {bigint}
508
374
  */
509
375
  get mem() {
510
- const ret = wasm.__wbg_get_evalbuiltinresult_mem(this.__wbg_ptr);
376
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
377
+ throw new Error('Invalid stale object from previous Wasm instance');
378
+ }
379
+ let ret;
380
+ __wbg_call_guard();
381
+ ret = wasm.__wbg_get_evalprogramresult_mem(this.__wbg_ptr);
511
382
  return BigInt.asUintN(64, ret);
512
383
  }
513
384
  /**
514
- * The memory the builtin's cost model charges for this application; see
515
- * `cpu`.
385
+ * Whether the program succeeded: it did not fail and, for Plutus V3, it
386
+ * returned unit.
387
+ * @returns {boolean}
388
+ */
389
+ get ok() {
390
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
391
+ throw new Error('Invalid stale object from previous Wasm instance');
392
+ }
393
+ let ret;
394
+ __wbg_call_guard();
395
+ ret = wasm.__wbg_get_evalprogramresult_ok(this.__wbg_ptr);
396
+ return ret !== 0;
397
+ }
398
+ /**
399
+ * The CPU the program used. A program that went over budget is charged
400
+ * what it used up to the point where the machine stopped it.
516
401
  * @param {bigint} arg0
517
402
  */
518
- set mem(arg0) {
519
- wasm.__wbg_set_evalbuiltinresult_mem(this.__wbg_ptr, arg0);
403
+ set cpu(arg0) {
404
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
405
+ throw new Error('Invalid stale object from previous Wasm instance');
406
+ }
407
+ __wbg_call_guard();
408
+ wasm.__wbg_set_evalprogramresult_cpu(this.__wbg_ptr, arg0);
520
409
  }
521
410
  /**
522
- * The evaluator's description of why the builtin did not return a value;
523
- * empty when it did.
524
- * @returns {string}
411
+ * Why the program did not succeed: 0 when it did, 1 when it went over
412
+ * budget, 2 when it failed in any other way and 3 when a Plutus V3 program
413
+ * returned something other than unit.
414
+ * @param {number} arg0
525
415
  */
526
- get error() {
527
- let deferred1_0;
528
- let deferred1_1;
529
- try {
530
- const ret = wasm.__wbg_get_evalbuiltinresult_error(this.__wbg_ptr);
531
- deferred1_0 = ret[0];
532
- deferred1_1 = ret[1];
533
- return getStringFromWasm0(ret[0], ret[1]);
534
- } finally {
535
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
416
+ set error_kind(arg0) {
417
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
418
+ throw new Error('Invalid stale object from previous Wasm instance');
536
419
  }
420
+ __wbg_call_guard();
421
+ wasm.__wbg_set_evalprogramresult_error_kind(this.__wbg_ptr, arg0);
537
422
  }
538
423
  /**
539
- * The evaluator's description of why the builtin did not return a value;
540
- * empty when it did.
541
- * @param {string} arg0
424
+ * The messages the program traced, in order.
425
+ * @param {string[]} arg0
542
426
  */
543
- set error(arg0) {
544
- const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
427
+ set logs(arg0) {
428
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
429
+ throw new Error('Invalid stale object from previous Wasm instance');
430
+ }
431
+ const ptr0 = passArrayJsValueToWasm0(arg0, wasm.__wbindgen_malloc);
545
432
  const len0 = WASM_VECTOR_LEN;
546
- wasm.__wbg_set_evalbuiltinresult_error(this.__wbg_ptr, ptr0, len0);
433
+ __wbg_call_guard();
434
+ wasm.__wbg_set_evalprogramresult_logs(this.__wbg_ptr, ptr0, len0);
435
+ }
436
+ /**
437
+ * The memory the program used.
438
+ * @param {bigint} arg0
439
+ */
440
+ set mem(arg0) {
441
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
442
+ throw new Error('Invalid stale object from previous Wasm instance');
443
+ }
444
+ __wbg_call_guard();
445
+ wasm.__wbg_set_evalprogramresult_mem(this.__wbg_ptr, arg0);
446
+ }
447
+ /**
448
+ * Whether the program succeeded: it did not fail and, for Plutus V3, it
449
+ * returned unit.
450
+ * @param {boolean} arg0
451
+ */
452
+ set ok(arg0) {
453
+ if (this.__wbg_inst !== undefined && this.__wbg_inst !== __wbg_instance_id) {
454
+ throw new Error('Invalid stale object from previous Wasm instance');
455
+ }
456
+ __wbg_call_guard();
457
+ wasm.__wbg_set_evalprogramresult_ok(this.__wbg_ptr, arg0);
458
+ }
459
+ }
460
+ if (Symbol.dispose) EvalProgramResult.prototype[Symbol.dispose] = EvalProgramResult.prototype.free;
461
+ exports.EvalProgramResult = EvalProgramResult;
462
+
463
+ function __wbg_reset_state () {
464
+ __wbg_instance_id++;
465
+ cachedBigUint64ArrayMemory0 = null;
466
+ cachedDataViewMemory0 = null;
467
+ cachedUint8ArrayMemory0 = null;
468
+ if (typeof numBytesDecoded !== 'undefined') numBytesDecoded = 0;
469
+ if (typeof WASM_VECTOR_LEN !== 'undefined') WASM_VECTOR_LEN = 0;
470
+ __wbg_reinit_scheduled = false;
471
+ wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
472
+ wasm = wasmInstance.exports;
473
+ wasm.__wbindgen_start();
474
+ }
475
+ exports.__wbg_reset_state = __wbg_reset_state;
476
+
477
+ /**
478
+ * @param {Uint8Array} params_bytes
479
+ * @param {Uint8Array} plutus_script_bytes
480
+ * @returns {Uint8Array}
481
+ */
482
+ function apply_params_to_script(params_bytes, plutus_script_bytes) {
483
+ const ptr0 = passArray8ToWasm0(params_bytes, wasm.__wbindgen_malloc);
484
+ const len0 = WASM_VECTOR_LEN;
485
+ const ptr1 = passArray8ToWasm0(plutus_script_bytes, wasm.__wbindgen_malloc);
486
+ const len1 = WASM_VECTOR_LEN;
487
+ let ret;
488
+ __wbg_call_guard();
489
+ ret = wasm.apply_params_to_script(ptr0, len0, ptr1, len1);
490
+ if (ret[3]) {
491
+ throw takeFromExternrefTable0(ret[2]);
492
+ }
493
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
494
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
495
+ return v3;
496
+ }
497
+ exports.apply_params_to_script = apply_params_to_script;
498
+
499
+ /**
500
+ * Evaluates the builtin `tag` applied to `args` as a Plutus V3 script
501
+ * evaluates it at a protocol version, without any program around it: the
502
+ * result, or how it fails, is what the machine gives for the saturated
503
+ * application.
504
+ *
505
+ * - `tag`: the builtin's flat tag (0 for addInteger to 100 for scaleValue).
506
+ * The Miller-loop builtins (68 to 70) are not supported, since their
507
+ * results cannot be returned.
508
+ * - `args`: exactly the builtin's arguments, in order, each encoded as the
509
+ * matching entry of `arg_kinds` says, a [`BuiltinValueKind`]: 0 for a
510
+ * flat-encoded `(program 1.1.0 (con …))`, 1 for a compressed G1 point, 2
511
+ * for a compressed G2 point, 3 for a list of G1 points, 4 for a list of G2
512
+ * points, 5 for an array of G1 points and 6 for an array of G2 points, each
513
+ * list or array as the compressed points one after the other. Flat cannot
514
+ * encode BLS12-381 points, so they cross as their compressed bytes.
515
+ * - `protocol_major_version`: from 9 (Chang, which introduced Plutus V3) to
516
+ * 12 (Dijkstra). It decides which builtins are available and the semantics
517
+ * they have.
518
+ *
519
+ * The result's `cpu` and `mem` are the builtin's charge for the application
520
+ * under Plutus' default Plutus V3 cost model (not the ledger's protocol
521
+ * parameters), excluding the machine's per-step costs.
522
+ *
523
+ * Fails only when the inputs are malformed or unsupported: an unknown or
524
+ * Miller-loop tag, a number of arguments other than the builtin's arity, an
525
+ * argument that does not decode as its kind says or is not a constant, an
526
+ * invalid compressed point, a protocol version out of range, or a result that
527
+ * none of the kinds can encode. A builtin that fails is an
528
+ * [`EvalBuiltinResult`] that is not `ok`.
529
+ * @param {number} tag
530
+ * @param {Uint8Array[]} args
531
+ * @param {Uint8Array} arg_kinds
532
+ * @param {number} protocol_major_version
533
+ * @returns {EvalBuiltinResult}
534
+ */
535
+ function eval_builtin_raw(tag, args, arg_kinds, protocol_major_version) {
536
+ const ptr0 = passArrayJsValueToWasm0(args, wasm.__wbindgen_malloc);
537
+ const len0 = WASM_VECTOR_LEN;
538
+ const ptr1 = passArray8ToWasm0(arg_kinds, wasm.__wbindgen_malloc);
539
+ const len1 = WASM_VECTOR_LEN;
540
+ let ret;
541
+ __wbg_call_guard();
542
+ ret = wasm.eval_builtin_raw(tag, ptr0, len0, ptr1, len1, protocol_major_version);
543
+ if (ret[2]) {
544
+ throw takeFromExternrefTable0(ret[1]);
545
+ }
546
+ return EvalBuiltinResult.__wrap(ret[0]);
547
+ }
548
+ exports.eval_builtin_raw = eval_builtin_raw;
549
+
550
+ /**
551
+ * @param {Uint8Array} tx_bytes
552
+ * @param {Uint8Array[]} utxos_bytes_x
553
+ * @param {Uint8Array[]} utxos_bytes_y
554
+ * @param {Uint8Array} cost_mdls_bytes
555
+ * @param {bigint} initial_budget_n
556
+ * @param {bigint} initial_budget_d
557
+ * @param {bigint} slot_config_x
558
+ * @param {bigint} slot_config_y
559
+ * @param {number} slot_config_z
560
+ * @param {number | null} [protocol_major_version]
561
+ * @returns {Uint8Array[]}
562
+ */
563
+ function eval_phase_two_raw(tx_bytes, utxos_bytes_x, utxos_bytes_y, cost_mdls_bytes, initial_budget_n, initial_budget_d, slot_config_x, slot_config_y, slot_config_z, protocol_major_version) {
564
+ const ptr0 = passArray8ToWasm0(tx_bytes, wasm.__wbindgen_malloc);
565
+ const len0 = WASM_VECTOR_LEN;
566
+ const ptr1 = passArrayJsValueToWasm0(utxos_bytes_x, wasm.__wbindgen_malloc);
567
+ const len1 = WASM_VECTOR_LEN;
568
+ const ptr2 = passArrayJsValueToWasm0(utxos_bytes_y, wasm.__wbindgen_malloc);
569
+ const len2 = WASM_VECTOR_LEN;
570
+ const ptr3 = passArray8ToWasm0(cost_mdls_bytes, wasm.__wbindgen_malloc);
571
+ const len3 = WASM_VECTOR_LEN;
572
+ let ret;
573
+ __wbg_call_guard();
574
+ ret = wasm.eval_phase_two_raw(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, initial_budget_n, initial_budget_d, slot_config_x, slot_config_y, slot_config_z, !isLikeNone(protocol_major_version), isLikeNone(protocol_major_version) ? 0 : protocol_major_version);
575
+ if (ret[3]) {
576
+ throw takeFromExternrefTable0(ret[2]);
577
+ }
578
+ var v5 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
579
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
580
+ return v5;
581
+ }
582
+ exports.eval_phase_two_raw = eval_phase_two_raw;
583
+
584
+ /**
585
+ * Evaluates a UPLC program applied to Data arguments, outside of any
586
+ * transaction: the caller builds whatever arguments the program expects,
587
+ * including its script context.
588
+ *
589
+ * - `program_flat`: the program, flat-encoded without a CBOR wrapper.
590
+ * - `args_cbor`: the arguments, each one CBOR-encoded Data, applied in order.
591
+ * - `language`: the Plutus version to evaluate as, 1, 2 or 3.
592
+ * - `protocol_major_version`: the protocol version whose semantics to use,
593
+ * from 5 (Alonzo) to 12 (Dijkstra).
594
+ * - `cost_model`: the cost model parameters, every one the evaluator knows
595
+ * for this Plutus version (350 for Plutus V3), in the ledger's order.
596
+ * - `budget_cpu`, `budget_mem`: the budget.
597
+ * - `strict_budget`: charge every step as the machine takes it, and stop the
598
+ * program as soon as it goes over budget, instead of charging steps and
599
+ * checking the budget every 200 steps as the ledger does. Only the cost of a
600
+ * program that fails differs: the ledger does not charge the steps it took
601
+ * since the budget was last checked.
602
+ *
603
+ * Fails only when the inputs are malformed or unsupported. A program that fails
604
+ * is an [`EvalProgramResult`] that is not `ok`.
605
+ * @param {Uint8Array} program_flat
606
+ * @param {Uint8Array[]} args_cbor
607
+ * @param {number} language
608
+ * @param {number} protocol_major_version
609
+ * @param {BigInt64Array} cost_model
610
+ * @param {bigint} budget_cpu
611
+ * @param {bigint} budget_mem
612
+ * @param {boolean} strict_budget
613
+ * @returns {EvalProgramResult}
614
+ */
615
+ function eval_program_raw(program_flat, args_cbor, language, protocol_major_version, cost_model, budget_cpu, budget_mem, strict_budget) {
616
+ const ptr0 = passArray8ToWasm0(program_flat, wasm.__wbindgen_malloc);
617
+ const len0 = WASM_VECTOR_LEN;
618
+ const ptr1 = passArrayJsValueToWasm0(args_cbor, wasm.__wbindgen_malloc);
619
+ const len1 = WASM_VECTOR_LEN;
620
+ const ptr2 = passArray64ToWasm0(cost_model, wasm.__wbindgen_malloc);
621
+ const len2 = WASM_VECTOR_LEN;
622
+ let ret;
623
+ __wbg_call_guard();
624
+ ret = wasm.eval_program_raw(ptr0, len0, ptr1, len1, language, protocol_major_version, ptr2, len2, budget_cpu, budget_mem, strict_budget);
625
+ if (ret[2]) {
626
+ throw takeFromExternrefTable0(ret[1]);
547
627
  }
628
+ return EvalProgramResult.__wrap(ret[0]);
548
629
  }
549
- module.exports.EvalBuiltinResult = EvalBuiltinResult;
630
+ exports.eval_program_raw = eval_program_raw;
550
631
 
551
- const EvalProgramResultFinalization = (typeof FinalizationRegistry === 'undefined')
552
- ? { register: () => {}, unregister: () => {} }
553
- : new FinalizationRegistry(ptr => wasm.__wbg_evalprogramresult_free(ptr >>> 0, 1));
554
632
  /**
555
- * The outcome of [`eval_program_raw`].
633
+ * Describes this build of the evaluator as JSON: the uplc crate it was built
634
+ * from, the length of each Plutus version's cost model, and a digest of what a
635
+ * fixed set of programs evaluate to, with their costs, under Plutus V3 and the
636
+ * latest protocol version. Two builds with the same digest agree on those
637
+ * programs; `selfTest` says whether this one gives the expected results.
638
+ * @returns {string}
556
639
  */
557
- class EvalProgramResult {
558
-
559
- static __wrap(ptr) {
560
- ptr = ptr >>> 0;
561
- const obj = Object.create(EvalProgramResult.prototype);
562
- obj.__wbg_ptr = ptr;
563
- EvalProgramResultFinalization.register(obj, obj.__wbg_ptr, obj);
564
- return obj;
640
+ function uplc_build_info() {
641
+ let deferred1_0;
642
+ let deferred1_1;
643
+ try {
644
+ let ret;
645
+ __wbg_call_guard();
646
+ ret = wasm.uplc_build_info();
647
+ deferred1_0 = ret[0];
648
+ deferred1_1 = ret[1];
649
+ return getStringFromWasm0(ret[0], ret[1]);
650
+ } finally {
651
+ __wbg_call_guard();
652
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
565
653
  }
654
+ }
655
+ exports.uplc_build_info = uplc_build_info;
656
+ function __wbg_get_imports() {
657
+ const import0 = {
658
+ __proto__: null,
659
+ __wbg___wbindgen_string_get_b0ca35b86a603356: function(arg0, arg1) {
660
+ const obj = arg1;
661
+ const ret = typeof(obj) === 'string' ? obj : undefined;
662
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
663
+ var len1 = WASM_VECTOR_LEN;
664
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
665
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
666
+ },
667
+ __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
668
+ throw new Error(getStringFromWasm0(arg0, arg1));
669
+ },
670
+ __wbg_length_1f0964f4a5e2c6d8: function(arg0) {
671
+ const ret = arg0.length;
672
+ return ret;
673
+ },
674
+ __wbg_new_from_slice_77cdfb7977362f3c: function(arg0, arg1) {
675
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
676
+ return ret;
677
+ },
678
+ __wbg_prototypesetcall_4770620bbe4688a0: function(arg0, arg1, arg2) {
679
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
680
+ },
681
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
682
+ // Cast intrinsic for `Ref(String) -> Externref`.
683
+ const ret = getStringFromWasm0(arg0, arg1);
684
+ return ret;
685
+ },
686
+ __wbindgen_init_externref_table: function() {
687
+ const table = wasm.__wbindgen_externrefs;
688
+ const offset = table.grow(4);
689
+ table.set(0, undefined);
690
+ table.set(offset + 0, undefined);
691
+ table.set(offset + 1, null);
692
+ table.set(offset + 2, true);
693
+ table.set(offset + 3, false);
694
+ },
695
+ };
696
+ return {
697
+ __proto__: null,
698
+ "./uplc_tx_bg.js": import0,
699
+ };
700
+ }
566
701
 
567
- __destroy_into_raw() {
568
- const ptr = this.__wbg_ptr;
569
- this.__wbg_ptr = 0;
570
- EvalProgramResultFinalization.unregister(this);
571
- return ptr;
702
+ function __wbg_call_guard() {
703
+ if (__wbg_reinit_scheduled) {
704
+ __wbg_reset_state();
705
+ return;
572
706
  }
707
+ }
573
708
 
574
- free() {
575
- const ptr = this.__destroy_into_raw();
576
- wasm.__wbg_evalprogramresult_free(ptr, 0);
577
- }
578
- /**
579
- * Whether the program succeeded: it did not fail and, for Plutus V3, it
580
- * returned unit.
581
- * @returns {boolean}
582
- */
583
- get ok() {
584
- const ret = wasm.__wbg_get_evalprogramresult_ok(this.__wbg_ptr);
585
- return ret !== 0;
586
- }
587
- /**
588
- * Whether the program succeeded: it did not fail and, for Plutus V3, it
589
- * returned unit.
590
- * @param {boolean} arg0
591
- */
592
- set ok(arg0) {
593
- wasm.__wbg_set_evalprogramresult_ok(this.__wbg_ptr, arg0);
594
- }
595
- /**
596
- * The CPU the program used. A program that went over budget is charged
597
- * what it used up to the point where the machine stopped it.
598
- * @returns {bigint}
599
- */
600
- get cpu() {
601
- const ret = wasm.__wbg_get_evalbuiltinresult_cpu(this.__wbg_ptr);
602
- return BigInt.asUintN(64, ret);
709
+
710
+ let __wbg_instance_id = 0;
711
+ const EvalBuiltinResultFinalization = (typeof FinalizationRegistry === 'undefined')
712
+ ? { register: () => {}, unregister: () => {} }
713
+ : new FinalizationRegistry(({ ptr, instance }) => {
714
+ if (instance === __wbg_instance_id) wasm.__wbg_evalbuiltinresult_free(ptr, 1);
715
+ });
716
+ const EvalProgramResultFinalization = (typeof FinalizationRegistry === 'undefined')
717
+ ? { register: () => {}, unregister: () => {} }
718
+ : new FinalizationRegistry(({ ptr, instance }) => {
719
+ if (instance === __wbg_instance_id) wasm.__wbg_evalprogramresult_free(ptr, 1);
720
+ });
721
+
722
+ function addToExternrefTable0(obj) {
723
+ const idx = wasm.__externref_table_alloc();
724
+ wasm.__wbindgen_externrefs.set(idx, obj);
725
+ return idx;
726
+ }
727
+
728
+ function getArrayJsValueFromWasm0(ptr, len) {
729
+ ptr = ptr >>> 0;
730
+ const mem = getDataViewMemory0();
731
+ const result = [];
732
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
733
+ result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
603
734
  }
604
- /**
605
- * The CPU the program used. A program that went over budget is charged
606
- * what it used up to the point where the machine stopped it.
607
- * @param {bigint} arg0
608
- */
609
- set cpu(arg0) {
610
- wasm.__wbg_set_evalbuiltinresult_cpu(this.__wbg_ptr, arg0);
735
+ wasm.__externref_drop_slice(ptr, len);
736
+ return result;
737
+ }
738
+
739
+ function getArrayU8FromWasm0(ptr, len) {
740
+ ptr = ptr >>> 0;
741
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
742
+ }
743
+
744
+ let cachedBigUint64ArrayMemory0 = null;
745
+ function getBigUint64ArrayMemory0() {
746
+ if (cachedBigUint64ArrayMemory0 === null || cachedBigUint64ArrayMemory0.byteLength === 0) {
747
+ cachedBigUint64ArrayMemory0 = new BigUint64Array(wasm.memory.buffer);
611
748
  }
612
- /**
613
- * The memory the program used.
614
- * @returns {bigint}
615
- */
616
- get mem() {
617
- const ret = wasm.__wbg_get_evalbuiltinresult_mem(this.__wbg_ptr);
618
- return BigInt.asUintN(64, ret);
749
+ return cachedBigUint64ArrayMemory0;
750
+ }
751
+
752
+ let cachedDataViewMemory0 = null;
753
+ function getDataViewMemory0() {
754
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
755
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
619
756
  }
620
- /**
621
- * The memory the program used.
622
- * @param {bigint} arg0
623
- */
624
- set mem(arg0) {
625
- wasm.__wbg_set_evalbuiltinresult_mem(this.__wbg_ptr, arg0);
757
+ return cachedDataViewMemory0;
758
+ }
759
+
760
+ function getStringFromWasm0(ptr, len) {
761
+ return decodeText(ptr >>> 0, len);
762
+ }
763
+
764
+ let cachedUint8ArrayMemory0 = null;
765
+ function getUint8ArrayMemory0() {
766
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
767
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
626
768
  }
627
- /**
628
- * Why the program did not succeed: 0 when it did, 1 when it went over
629
- * budget, 2 when it failed in any other way and 3 when a Plutus V3 program
630
- * returned something other than unit.
631
- * @returns {number}
632
- */
633
- get error_kind() {
634
- const ret = wasm.__wbg_get_evalprogramresult_error_kind(this.__wbg_ptr);
635
- return ret;
769
+ return cachedUint8ArrayMemory0;
770
+ }
771
+
772
+ function isLikeNone(x) {
773
+ return x === undefined || x === null;
774
+ }
775
+
776
+ function passArray64ToWasm0(arg, malloc) {
777
+ const ptr = malloc(arg.length * 8, 8) >>> 0;
778
+ getBigUint64ArrayMemory0().set(arg, ptr / 8);
779
+ WASM_VECTOR_LEN = arg.length;
780
+ return ptr;
781
+ }
782
+
783
+ function passArray8ToWasm0(arg, malloc) {
784
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
785
+ getUint8ArrayMemory0().set(arg, ptr / 1);
786
+ WASM_VECTOR_LEN = arg.length;
787
+ return ptr;
788
+ }
789
+
790
+ function passArrayJsValueToWasm0(array, malloc) {
791
+ const ptr = malloc(array.length * 4, 4) >>> 0;
792
+ for (let i = 0; i < array.length; i++) {
793
+ const add = addToExternrefTable0(array[i]);
794
+ getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
636
795
  }
637
- /**
638
- * Why the program did not succeed: 0 when it did, 1 when it went over
639
- * budget, 2 when it failed in any other way and 3 when a Plutus V3 program
640
- * returned something other than unit.
641
- * @param {number} arg0
642
- */
643
- set error_kind(arg0) {
644
- wasm.__wbg_set_evalprogramresult_error_kind(this.__wbg_ptr, arg0);
796
+ WASM_VECTOR_LEN = array.length;
797
+ return ptr;
798
+ }
799
+
800
+ function passStringToWasm0(arg, malloc, realloc) {
801
+ if (realloc === undefined) {
802
+ const buf = cachedTextEncoder.encode(arg);
803
+ const ptr = malloc(buf.length, 1) >>> 0;
804
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
805
+ WASM_VECTOR_LEN = buf.length;
806
+ return ptr;
645
807
  }
646
- /**
647
- * The messages the program traced, in order.
648
- * @returns {string[]}
649
- */
650
- get logs() {
651
- const ret = wasm.__wbg_get_evalprogramresult_logs(this.__wbg_ptr);
652
- var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
653
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
654
- return v1;
808
+
809
+ let len = arg.length;
810
+ let ptr = malloc(len, 1) >>> 0;
811
+
812
+ const mem = getUint8ArrayMemory0();
813
+
814
+ let offset = 0;
815
+
816
+ for (; offset < len; offset++) {
817
+ const code = arg.charCodeAt(offset);
818
+ if (code > 0x7F) break;
819
+ mem[ptr + offset] = code;
655
820
  }
656
- /**
657
- * The messages the program traced, in order.
658
- * @param {string[]} arg0
659
- */
660
- set logs(arg0) {
661
- const ptr0 = passArrayJsValueToWasm0(arg0, wasm.__wbindgen_malloc);
662
- const len0 = WASM_VECTOR_LEN;
663
- wasm.__wbg_set_evalprogramresult_logs(this.__wbg_ptr, ptr0, len0);
821
+ if (offset !== len) {
822
+ if (offset !== 0) {
823
+ arg = arg.slice(offset);
824
+ }
825
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
826
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
827
+ const ret = cachedTextEncoder.encodeInto(arg, view);
828
+
829
+ offset += ret.written;
830
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
664
831
  }
832
+
833
+ WASM_VECTOR_LEN = offset;
834
+ return ptr;
665
835
  }
666
- module.exports.EvalProgramResult = EvalProgramResult;
667
-
668
- module.exports.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
669
- const ret = arg0.buffer;
670
- return ret;
671
- };
672
-
673
- module.exports.__wbg_length_a446193dc22c12f8 = function(arg0) {
674
- const ret = arg0.length;
675
- return ret;
676
- };
677
-
678
- module.exports.__wbg_new_a12002a7f91c75be = function(arg0) {
679
- const ret = new Uint8Array(arg0);
680
- return ret;
681
- };
682
-
683
- module.exports.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function(arg0, arg1, arg2) {
684
- const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
685
- return ret;
686
- };
687
-
688
- module.exports.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) {
689
- arg0.set(arg1, arg2 >>> 0);
690
- };
691
-
692
- module.exports.__wbindgen_init_externref_table = function() {
693
- const table = wasm.__wbindgen_export_0;
694
- const offset = table.grow(4);
695
- table.set(0, undefined);
696
- table.set(offset + 0, undefined);
697
- table.set(offset + 1, null);
698
- table.set(offset + 2, true);
699
- table.set(offset + 3, false);
700
- ;
701
- };
702
-
703
- module.exports.__wbindgen_memory = function() {
704
- const ret = wasm.memory;
705
- return ret;
706
- };
707
-
708
- module.exports.__wbindgen_string_get = function(arg0, arg1) {
709
- const obj = arg1;
710
- const ret = typeof(obj) === 'string' ? obj : undefined;
711
- var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
712
- var len1 = WASM_VECTOR_LEN;
713
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
714
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
715
- };
716
-
717
- module.exports.__wbindgen_string_new = function(arg0, arg1) {
718
- const ret = getStringFromWasm0(arg0, arg1);
719
- return ret;
720
- };
721
-
722
- module.exports.__wbindgen_throw = function(arg0, arg1) {
723
- throw new Error(getStringFromWasm0(arg0, arg1));
724
- };
725
-
726
- const path = require('path').join(__dirname, 'uplc_tx_bg.wasm');
727
- const bytes = require('fs').readFileSync(path);
728
-
729
- const wasmModule = new WebAssembly.Module(bytes);
730
- const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
731
- wasm = wasmInstance.exports;
732
- module.exports.__wasm = wasm;
733
836
 
734
- wasm.__wbindgen_start();
837
+ let __wbg_reinit_scheduled = false;
838
+
839
+ function takeFromExternrefTable0(idx) {
840
+ const value = wasm.__wbindgen_externrefs.get(idx);
841
+ wasm.__externref_table_dealloc(idx);
842
+ return value;
843
+ }
844
+
845
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
846
+ cachedTextDecoder.decode();
847
+ function decodeText(ptr, len) {
848
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
849
+ }
735
850
 
851
+ const cachedTextEncoder = new TextEncoder();
852
+
853
+ if (!('encodeInto' in cachedTextEncoder)) {
854
+ cachedTextEncoder.encodeInto = function (arg, view) {
855
+ const buf = cachedTextEncoder.encode(arg);
856
+ view.set(buf);
857
+ return {
858
+ read: arg.length,
859
+ written: buf.length
860
+ };
861
+ };
862
+ }
863
+
864
+ let WASM_VECTOR_LEN = 0;
865
+
866
+ const wasmPath = `${__dirname}/uplc_tx_bg.wasm`;
867
+ const wasmBytes = require('fs').readFileSync(wasmPath);
868
+ const wasmModule = new WebAssembly.Module(wasmBytes);
869
+ let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
870
+ let wasm = wasmInstance.exports;
871
+ wasm.__wbindgen_start();