@meshsdk/common 1.9.0-beta.1 → 1.9.0-beta.100
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/dist/index.cjs +718 -902
- package/dist/index.d.cts +798 -244
- package/dist/index.d.ts +798 -244
- package/dist/index.js +699 -924
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -5,9 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
-
};
|
|
11
8
|
var __export = (target, all) => {
|
|
12
9
|
for (var name in all)
|
|
13
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -30,868 +27,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
27
|
));
|
|
31
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
29
|
|
|
33
|
-
// ../../node_modules/blakejs/util.js
|
|
34
|
-
var require_util = __commonJS({
|
|
35
|
-
"../../node_modules/blakejs/util.js"(exports2, module2) {
|
|
36
|
-
"use strict";
|
|
37
|
-
var ERROR_MSG_INPUT = "Input must be an string, Buffer or Uint8Array";
|
|
38
|
-
function normalizeInput(input) {
|
|
39
|
-
let ret;
|
|
40
|
-
if (input instanceof Uint8Array) {
|
|
41
|
-
ret = input;
|
|
42
|
-
} else if (typeof input === "string") {
|
|
43
|
-
const encoder = new TextEncoder();
|
|
44
|
-
ret = encoder.encode(input);
|
|
45
|
-
} else {
|
|
46
|
-
throw new Error(ERROR_MSG_INPUT);
|
|
47
|
-
}
|
|
48
|
-
return ret;
|
|
49
|
-
}
|
|
50
|
-
function toHex(bytes) {
|
|
51
|
-
return Array.prototype.map.call(bytes, function(n) {
|
|
52
|
-
return (n < 16 ? "0" : "") + n.toString(16);
|
|
53
|
-
}).join("");
|
|
54
|
-
}
|
|
55
|
-
function uint32ToHex(val) {
|
|
56
|
-
return (4294967296 + val).toString(16).substring(1);
|
|
57
|
-
}
|
|
58
|
-
function debugPrint(label, arr, size) {
|
|
59
|
-
let msg = "\n" + label + " = ";
|
|
60
|
-
for (let i = 0; i < arr.length; i += 2) {
|
|
61
|
-
if (size === 32) {
|
|
62
|
-
msg += uint32ToHex(arr[i]).toUpperCase();
|
|
63
|
-
msg += " ";
|
|
64
|
-
msg += uint32ToHex(arr[i + 1]).toUpperCase();
|
|
65
|
-
} else if (size === 64) {
|
|
66
|
-
msg += uint32ToHex(arr[i + 1]).toUpperCase();
|
|
67
|
-
msg += uint32ToHex(arr[i]).toUpperCase();
|
|
68
|
-
} else throw new Error("Invalid size " + size);
|
|
69
|
-
if (i % 6 === 4) {
|
|
70
|
-
msg += "\n" + new Array(label.length + 4).join(" ");
|
|
71
|
-
} else if (i < arr.length - 2) {
|
|
72
|
-
msg += " ";
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
console.log(msg);
|
|
76
|
-
}
|
|
77
|
-
function testSpeed(hashFn, N, M) {
|
|
78
|
-
let startMs = (/* @__PURE__ */ new Date()).getTime();
|
|
79
|
-
const input = new Uint8Array(N);
|
|
80
|
-
for (let i = 0; i < N; i++) {
|
|
81
|
-
input[i] = i % 256;
|
|
82
|
-
}
|
|
83
|
-
const genMs = (/* @__PURE__ */ new Date()).getTime();
|
|
84
|
-
console.log("Generated random input in " + (genMs - startMs) + "ms");
|
|
85
|
-
startMs = genMs;
|
|
86
|
-
for (let i = 0; i < M; i++) {
|
|
87
|
-
const hashHex = hashFn(input);
|
|
88
|
-
const hashMs = (/* @__PURE__ */ new Date()).getTime();
|
|
89
|
-
const ms = hashMs - startMs;
|
|
90
|
-
startMs = hashMs;
|
|
91
|
-
console.log("Hashed in " + ms + "ms: " + hashHex.substring(0, 20) + "...");
|
|
92
|
-
console.log(
|
|
93
|
-
Math.round(N / (1 << 20) / (ms / 1e3) * 100) / 100 + " MB PER SECOND"
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
module2.exports = {
|
|
98
|
-
normalizeInput,
|
|
99
|
-
toHex,
|
|
100
|
-
debugPrint,
|
|
101
|
-
testSpeed
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
// ../../node_modules/blakejs/blake2b.js
|
|
107
|
-
var require_blake2b = __commonJS({
|
|
108
|
-
"../../node_modules/blakejs/blake2b.js"(exports2, module2) {
|
|
109
|
-
"use strict";
|
|
110
|
-
var util = require_util();
|
|
111
|
-
function ADD64AA(v2, a, b) {
|
|
112
|
-
const o0 = v2[a] + v2[b];
|
|
113
|
-
let o1 = v2[a + 1] + v2[b + 1];
|
|
114
|
-
if (o0 >= 4294967296) {
|
|
115
|
-
o1++;
|
|
116
|
-
}
|
|
117
|
-
v2[a] = o0;
|
|
118
|
-
v2[a + 1] = o1;
|
|
119
|
-
}
|
|
120
|
-
function ADD64AC(v2, a, b0, b1) {
|
|
121
|
-
let o0 = v2[a] + b0;
|
|
122
|
-
if (b0 < 0) {
|
|
123
|
-
o0 += 4294967296;
|
|
124
|
-
}
|
|
125
|
-
let o1 = v2[a + 1] + b1;
|
|
126
|
-
if (o0 >= 4294967296) {
|
|
127
|
-
o1++;
|
|
128
|
-
}
|
|
129
|
-
v2[a] = o0;
|
|
130
|
-
v2[a + 1] = o1;
|
|
131
|
-
}
|
|
132
|
-
function B2B_GET32(arr, i) {
|
|
133
|
-
return arr[i] ^ arr[i + 1] << 8 ^ arr[i + 2] << 16 ^ arr[i + 3] << 24;
|
|
134
|
-
}
|
|
135
|
-
function B2B_G(a, b, c, d, ix, iy) {
|
|
136
|
-
const x0 = m[ix];
|
|
137
|
-
const x1 = m[ix + 1];
|
|
138
|
-
const y0 = m[iy];
|
|
139
|
-
const y1 = m[iy + 1];
|
|
140
|
-
ADD64AA(v, a, b);
|
|
141
|
-
ADD64AC(v, a, x0, x1);
|
|
142
|
-
let xor0 = v[d] ^ v[a];
|
|
143
|
-
let xor1 = v[d + 1] ^ v[a + 1];
|
|
144
|
-
v[d] = xor1;
|
|
145
|
-
v[d + 1] = xor0;
|
|
146
|
-
ADD64AA(v, c, d);
|
|
147
|
-
xor0 = v[b] ^ v[c];
|
|
148
|
-
xor1 = v[b + 1] ^ v[c + 1];
|
|
149
|
-
v[b] = xor0 >>> 24 ^ xor1 << 8;
|
|
150
|
-
v[b + 1] = xor1 >>> 24 ^ xor0 << 8;
|
|
151
|
-
ADD64AA(v, a, b);
|
|
152
|
-
ADD64AC(v, a, y0, y1);
|
|
153
|
-
xor0 = v[d] ^ v[a];
|
|
154
|
-
xor1 = v[d + 1] ^ v[a + 1];
|
|
155
|
-
v[d] = xor0 >>> 16 ^ xor1 << 16;
|
|
156
|
-
v[d + 1] = xor1 >>> 16 ^ xor0 << 16;
|
|
157
|
-
ADD64AA(v, c, d);
|
|
158
|
-
xor0 = v[b] ^ v[c];
|
|
159
|
-
xor1 = v[b + 1] ^ v[c + 1];
|
|
160
|
-
v[b] = xor1 >>> 31 ^ xor0 << 1;
|
|
161
|
-
v[b + 1] = xor0 >>> 31 ^ xor1 << 1;
|
|
162
|
-
}
|
|
163
|
-
var BLAKE2B_IV32 = new Uint32Array([
|
|
164
|
-
4089235720,
|
|
165
|
-
1779033703,
|
|
166
|
-
2227873595,
|
|
167
|
-
3144134277,
|
|
168
|
-
4271175723,
|
|
169
|
-
1013904242,
|
|
170
|
-
1595750129,
|
|
171
|
-
2773480762,
|
|
172
|
-
2917565137,
|
|
173
|
-
1359893119,
|
|
174
|
-
725511199,
|
|
175
|
-
2600822924,
|
|
176
|
-
4215389547,
|
|
177
|
-
528734635,
|
|
178
|
-
327033209,
|
|
179
|
-
1541459225
|
|
180
|
-
]);
|
|
181
|
-
var SIGMA8 = [
|
|
182
|
-
0,
|
|
183
|
-
1,
|
|
184
|
-
2,
|
|
185
|
-
3,
|
|
186
|
-
4,
|
|
187
|
-
5,
|
|
188
|
-
6,
|
|
189
|
-
7,
|
|
190
|
-
8,
|
|
191
|
-
9,
|
|
192
|
-
10,
|
|
193
|
-
11,
|
|
194
|
-
12,
|
|
195
|
-
13,
|
|
196
|
-
14,
|
|
197
|
-
15,
|
|
198
|
-
14,
|
|
199
|
-
10,
|
|
200
|
-
4,
|
|
201
|
-
8,
|
|
202
|
-
9,
|
|
203
|
-
15,
|
|
204
|
-
13,
|
|
205
|
-
6,
|
|
206
|
-
1,
|
|
207
|
-
12,
|
|
208
|
-
0,
|
|
209
|
-
2,
|
|
210
|
-
11,
|
|
211
|
-
7,
|
|
212
|
-
5,
|
|
213
|
-
3,
|
|
214
|
-
11,
|
|
215
|
-
8,
|
|
216
|
-
12,
|
|
217
|
-
0,
|
|
218
|
-
5,
|
|
219
|
-
2,
|
|
220
|
-
15,
|
|
221
|
-
13,
|
|
222
|
-
10,
|
|
223
|
-
14,
|
|
224
|
-
3,
|
|
225
|
-
6,
|
|
226
|
-
7,
|
|
227
|
-
1,
|
|
228
|
-
9,
|
|
229
|
-
4,
|
|
230
|
-
7,
|
|
231
|
-
9,
|
|
232
|
-
3,
|
|
233
|
-
1,
|
|
234
|
-
13,
|
|
235
|
-
12,
|
|
236
|
-
11,
|
|
237
|
-
14,
|
|
238
|
-
2,
|
|
239
|
-
6,
|
|
240
|
-
5,
|
|
241
|
-
10,
|
|
242
|
-
4,
|
|
243
|
-
0,
|
|
244
|
-
15,
|
|
245
|
-
8,
|
|
246
|
-
9,
|
|
247
|
-
0,
|
|
248
|
-
5,
|
|
249
|
-
7,
|
|
250
|
-
2,
|
|
251
|
-
4,
|
|
252
|
-
10,
|
|
253
|
-
15,
|
|
254
|
-
14,
|
|
255
|
-
1,
|
|
256
|
-
11,
|
|
257
|
-
12,
|
|
258
|
-
6,
|
|
259
|
-
8,
|
|
260
|
-
3,
|
|
261
|
-
13,
|
|
262
|
-
2,
|
|
263
|
-
12,
|
|
264
|
-
6,
|
|
265
|
-
10,
|
|
266
|
-
0,
|
|
267
|
-
11,
|
|
268
|
-
8,
|
|
269
|
-
3,
|
|
270
|
-
4,
|
|
271
|
-
13,
|
|
272
|
-
7,
|
|
273
|
-
5,
|
|
274
|
-
15,
|
|
275
|
-
14,
|
|
276
|
-
1,
|
|
277
|
-
9,
|
|
278
|
-
12,
|
|
279
|
-
5,
|
|
280
|
-
1,
|
|
281
|
-
15,
|
|
282
|
-
14,
|
|
283
|
-
13,
|
|
284
|
-
4,
|
|
285
|
-
10,
|
|
286
|
-
0,
|
|
287
|
-
7,
|
|
288
|
-
6,
|
|
289
|
-
3,
|
|
290
|
-
9,
|
|
291
|
-
2,
|
|
292
|
-
8,
|
|
293
|
-
11,
|
|
294
|
-
13,
|
|
295
|
-
11,
|
|
296
|
-
7,
|
|
297
|
-
14,
|
|
298
|
-
12,
|
|
299
|
-
1,
|
|
300
|
-
3,
|
|
301
|
-
9,
|
|
302
|
-
5,
|
|
303
|
-
0,
|
|
304
|
-
15,
|
|
305
|
-
4,
|
|
306
|
-
8,
|
|
307
|
-
6,
|
|
308
|
-
2,
|
|
309
|
-
10,
|
|
310
|
-
6,
|
|
311
|
-
15,
|
|
312
|
-
14,
|
|
313
|
-
9,
|
|
314
|
-
11,
|
|
315
|
-
3,
|
|
316
|
-
0,
|
|
317
|
-
8,
|
|
318
|
-
12,
|
|
319
|
-
2,
|
|
320
|
-
13,
|
|
321
|
-
7,
|
|
322
|
-
1,
|
|
323
|
-
4,
|
|
324
|
-
10,
|
|
325
|
-
5,
|
|
326
|
-
10,
|
|
327
|
-
2,
|
|
328
|
-
8,
|
|
329
|
-
4,
|
|
330
|
-
7,
|
|
331
|
-
6,
|
|
332
|
-
1,
|
|
333
|
-
5,
|
|
334
|
-
15,
|
|
335
|
-
11,
|
|
336
|
-
9,
|
|
337
|
-
14,
|
|
338
|
-
3,
|
|
339
|
-
12,
|
|
340
|
-
13,
|
|
341
|
-
0,
|
|
342
|
-
0,
|
|
343
|
-
1,
|
|
344
|
-
2,
|
|
345
|
-
3,
|
|
346
|
-
4,
|
|
347
|
-
5,
|
|
348
|
-
6,
|
|
349
|
-
7,
|
|
350
|
-
8,
|
|
351
|
-
9,
|
|
352
|
-
10,
|
|
353
|
-
11,
|
|
354
|
-
12,
|
|
355
|
-
13,
|
|
356
|
-
14,
|
|
357
|
-
15,
|
|
358
|
-
14,
|
|
359
|
-
10,
|
|
360
|
-
4,
|
|
361
|
-
8,
|
|
362
|
-
9,
|
|
363
|
-
15,
|
|
364
|
-
13,
|
|
365
|
-
6,
|
|
366
|
-
1,
|
|
367
|
-
12,
|
|
368
|
-
0,
|
|
369
|
-
2,
|
|
370
|
-
11,
|
|
371
|
-
7,
|
|
372
|
-
5,
|
|
373
|
-
3
|
|
374
|
-
];
|
|
375
|
-
var SIGMA82 = new Uint8Array(
|
|
376
|
-
SIGMA8.map(function(x) {
|
|
377
|
-
return x * 2;
|
|
378
|
-
})
|
|
379
|
-
);
|
|
380
|
-
var v = new Uint32Array(32);
|
|
381
|
-
var m = new Uint32Array(32);
|
|
382
|
-
function blake2bCompress(ctx, last) {
|
|
383
|
-
let i = 0;
|
|
384
|
-
for (i = 0; i < 16; i++) {
|
|
385
|
-
v[i] = ctx.h[i];
|
|
386
|
-
v[i + 16] = BLAKE2B_IV32[i];
|
|
387
|
-
}
|
|
388
|
-
v[24] = v[24] ^ ctx.t;
|
|
389
|
-
v[25] = v[25] ^ ctx.t / 4294967296;
|
|
390
|
-
if (last) {
|
|
391
|
-
v[28] = ~v[28];
|
|
392
|
-
v[29] = ~v[29];
|
|
393
|
-
}
|
|
394
|
-
for (i = 0; i < 32; i++) {
|
|
395
|
-
m[i] = B2B_GET32(ctx.b, 4 * i);
|
|
396
|
-
}
|
|
397
|
-
for (i = 0; i < 12; i++) {
|
|
398
|
-
B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);
|
|
399
|
-
B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);
|
|
400
|
-
B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);
|
|
401
|
-
B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);
|
|
402
|
-
B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);
|
|
403
|
-
B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);
|
|
404
|
-
B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);
|
|
405
|
-
B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);
|
|
406
|
-
}
|
|
407
|
-
for (i = 0; i < 16; i++) {
|
|
408
|
-
ctx.h[i] = ctx.h[i] ^ v[i] ^ v[i + 16];
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
var parameterBlock = new Uint8Array([
|
|
412
|
-
0,
|
|
413
|
-
0,
|
|
414
|
-
0,
|
|
415
|
-
0,
|
|
416
|
-
// 0: outlen, keylen, fanout, depth
|
|
417
|
-
0,
|
|
418
|
-
0,
|
|
419
|
-
0,
|
|
420
|
-
0,
|
|
421
|
-
// 4: leaf length, sequential mode
|
|
422
|
-
0,
|
|
423
|
-
0,
|
|
424
|
-
0,
|
|
425
|
-
0,
|
|
426
|
-
// 8: node offset
|
|
427
|
-
0,
|
|
428
|
-
0,
|
|
429
|
-
0,
|
|
430
|
-
0,
|
|
431
|
-
// 12: node offset
|
|
432
|
-
0,
|
|
433
|
-
0,
|
|
434
|
-
0,
|
|
435
|
-
0,
|
|
436
|
-
// 16: node depth, inner length, rfu
|
|
437
|
-
0,
|
|
438
|
-
0,
|
|
439
|
-
0,
|
|
440
|
-
0,
|
|
441
|
-
// 20: rfu
|
|
442
|
-
0,
|
|
443
|
-
0,
|
|
444
|
-
0,
|
|
445
|
-
0,
|
|
446
|
-
// 24: rfu
|
|
447
|
-
0,
|
|
448
|
-
0,
|
|
449
|
-
0,
|
|
450
|
-
0,
|
|
451
|
-
// 28: rfu
|
|
452
|
-
0,
|
|
453
|
-
0,
|
|
454
|
-
0,
|
|
455
|
-
0,
|
|
456
|
-
// 32: salt
|
|
457
|
-
0,
|
|
458
|
-
0,
|
|
459
|
-
0,
|
|
460
|
-
0,
|
|
461
|
-
// 36: salt
|
|
462
|
-
0,
|
|
463
|
-
0,
|
|
464
|
-
0,
|
|
465
|
-
0,
|
|
466
|
-
// 40: salt
|
|
467
|
-
0,
|
|
468
|
-
0,
|
|
469
|
-
0,
|
|
470
|
-
0,
|
|
471
|
-
// 44: salt
|
|
472
|
-
0,
|
|
473
|
-
0,
|
|
474
|
-
0,
|
|
475
|
-
0,
|
|
476
|
-
// 48: personal
|
|
477
|
-
0,
|
|
478
|
-
0,
|
|
479
|
-
0,
|
|
480
|
-
0,
|
|
481
|
-
// 52: personal
|
|
482
|
-
0,
|
|
483
|
-
0,
|
|
484
|
-
0,
|
|
485
|
-
0,
|
|
486
|
-
// 56: personal
|
|
487
|
-
0,
|
|
488
|
-
0,
|
|
489
|
-
0,
|
|
490
|
-
0
|
|
491
|
-
// 60: personal
|
|
492
|
-
]);
|
|
493
|
-
function blake2bInit(outlen, key, salt, personal) {
|
|
494
|
-
if (outlen === 0 || outlen > 64) {
|
|
495
|
-
throw new Error("Illegal output length, expected 0 < length <= 64");
|
|
496
|
-
}
|
|
497
|
-
if (key && key.length > 64) {
|
|
498
|
-
throw new Error("Illegal key, expected Uint8Array with 0 < length <= 64");
|
|
499
|
-
}
|
|
500
|
-
if (salt && salt.length !== 16) {
|
|
501
|
-
throw new Error("Illegal salt, expected Uint8Array with length is 16");
|
|
502
|
-
}
|
|
503
|
-
if (personal && personal.length !== 16) {
|
|
504
|
-
throw new Error("Illegal personal, expected Uint8Array with length is 16");
|
|
505
|
-
}
|
|
506
|
-
const ctx = {
|
|
507
|
-
b: new Uint8Array(128),
|
|
508
|
-
h: new Uint32Array(16),
|
|
509
|
-
t: 0,
|
|
510
|
-
// input count
|
|
511
|
-
c: 0,
|
|
512
|
-
// pointer within buffer
|
|
513
|
-
outlen
|
|
514
|
-
// output length in bytes
|
|
515
|
-
};
|
|
516
|
-
parameterBlock.fill(0);
|
|
517
|
-
parameterBlock[0] = outlen;
|
|
518
|
-
if (key) parameterBlock[1] = key.length;
|
|
519
|
-
parameterBlock[2] = 1;
|
|
520
|
-
parameterBlock[3] = 1;
|
|
521
|
-
if (salt) parameterBlock.set(salt, 32);
|
|
522
|
-
if (personal) parameterBlock.set(personal, 48);
|
|
523
|
-
for (let i = 0; i < 16; i++) {
|
|
524
|
-
ctx.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameterBlock, i * 4);
|
|
525
|
-
}
|
|
526
|
-
if (key) {
|
|
527
|
-
blake2bUpdate(ctx, key);
|
|
528
|
-
ctx.c = 128;
|
|
529
|
-
}
|
|
530
|
-
return ctx;
|
|
531
|
-
}
|
|
532
|
-
function blake2bUpdate(ctx, input) {
|
|
533
|
-
for (let i = 0; i < input.length; i++) {
|
|
534
|
-
if (ctx.c === 128) {
|
|
535
|
-
ctx.t += ctx.c;
|
|
536
|
-
blake2bCompress(ctx, false);
|
|
537
|
-
ctx.c = 0;
|
|
538
|
-
}
|
|
539
|
-
ctx.b[ctx.c++] = input[i];
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
function blake2bFinal(ctx) {
|
|
543
|
-
ctx.t += ctx.c;
|
|
544
|
-
while (ctx.c < 128) {
|
|
545
|
-
ctx.b[ctx.c++] = 0;
|
|
546
|
-
}
|
|
547
|
-
blake2bCompress(ctx, true);
|
|
548
|
-
const out = new Uint8Array(ctx.outlen);
|
|
549
|
-
for (let i = 0; i < ctx.outlen; i++) {
|
|
550
|
-
out[i] = ctx.h[i >> 2] >> 8 * (i & 3);
|
|
551
|
-
}
|
|
552
|
-
return out;
|
|
553
|
-
}
|
|
554
|
-
function blake2b2(input, key, outlen, salt, personal) {
|
|
555
|
-
outlen = outlen || 64;
|
|
556
|
-
input = util.normalizeInput(input);
|
|
557
|
-
if (salt) {
|
|
558
|
-
salt = util.normalizeInput(salt);
|
|
559
|
-
}
|
|
560
|
-
if (personal) {
|
|
561
|
-
personal = util.normalizeInput(personal);
|
|
562
|
-
}
|
|
563
|
-
const ctx = blake2bInit(outlen, key, salt, personal);
|
|
564
|
-
blake2bUpdate(ctx, input);
|
|
565
|
-
return blake2bFinal(ctx);
|
|
566
|
-
}
|
|
567
|
-
function blake2bHex2(input, key, outlen, salt, personal) {
|
|
568
|
-
const output = blake2b2(input, key, outlen, salt, personal);
|
|
569
|
-
return util.toHex(output);
|
|
570
|
-
}
|
|
571
|
-
module2.exports = {
|
|
572
|
-
blake2b: blake2b2,
|
|
573
|
-
blake2bHex: blake2bHex2,
|
|
574
|
-
blake2bInit,
|
|
575
|
-
blake2bUpdate,
|
|
576
|
-
blake2bFinal
|
|
577
|
-
};
|
|
578
|
-
}
|
|
579
|
-
});
|
|
580
|
-
|
|
581
|
-
// ../../node_modules/blakejs/blake2s.js
|
|
582
|
-
var require_blake2s = __commonJS({
|
|
583
|
-
"../../node_modules/blakejs/blake2s.js"(exports2, module2) {
|
|
584
|
-
"use strict";
|
|
585
|
-
var util = require_util();
|
|
586
|
-
function B2S_GET32(v2, i) {
|
|
587
|
-
return v2[i] ^ v2[i + 1] << 8 ^ v2[i + 2] << 16 ^ v2[i + 3] << 24;
|
|
588
|
-
}
|
|
589
|
-
function B2S_G(a, b, c, d, x, y) {
|
|
590
|
-
v[a] = v[a] + v[b] + x;
|
|
591
|
-
v[d] = ROTR32(v[d] ^ v[a], 16);
|
|
592
|
-
v[c] = v[c] + v[d];
|
|
593
|
-
v[b] = ROTR32(v[b] ^ v[c], 12);
|
|
594
|
-
v[a] = v[a] + v[b] + y;
|
|
595
|
-
v[d] = ROTR32(v[d] ^ v[a], 8);
|
|
596
|
-
v[c] = v[c] + v[d];
|
|
597
|
-
v[b] = ROTR32(v[b] ^ v[c], 7);
|
|
598
|
-
}
|
|
599
|
-
function ROTR32(x, y) {
|
|
600
|
-
return x >>> y ^ x << 32 - y;
|
|
601
|
-
}
|
|
602
|
-
var BLAKE2S_IV = new Uint32Array([
|
|
603
|
-
1779033703,
|
|
604
|
-
3144134277,
|
|
605
|
-
1013904242,
|
|
606
|
-
2773480762,
|
|
607
|
-
1359893119,
|
|
608
|
-
2600822924,
|
|
609
|
-
528734635,
|
|
610
|
-
1541459225
|
|
611
|
-
]);
|
|
612
|
-
var SIGMA = new Uint8Array([
|
|
613
|
-
0,
|
|
614
|
-
1,
|
|
615
|
-
2,
|
|
616
|
-
3,
|
|
617
|
-
4,
|
|
618
|
-
5,
|
|
619
|
-
6,
|
|
620
|
-
7,
|
|
621
|
-
8,
|
|
622
|
-
9,
|
|
623
|
-
10,
|
|
624
|
-
11,
|
|
625
|
-
12,
|
|
626
|
-
13,
|
|
627
|
-
14,
|
|
628
|
-
15,
|
|
629
|
-
14,
|
|
630
|
-
10,
|
|
631
|
-
4,
|
|
632
|
-
8,
|
|
633
|
-
9,
|
|
634
|
-
15,
|
|
635
|
-
13,
|
|
636
|
-
6,
|
|
637
|
-
1,
|
|
638
|
-
12,
|
|
639
|
-
0,
|
|
640
|
-
2,
|
|
641
|
-
11,
|
|
642
|
-
7,
|
|
643
|
-
5,
|
|
644
|
-
3,
|
|
645
|
-
11,
|
|
646
|
-
8,
|
|
647
|
-
12,
|
|
648
|
-
0,
|
|
649
|
-
5,
|
|
650
|
-
2,
|
|
651
|
-
15,
|
|
652
|
-
13,
|
|
653
|
-
10,
|
|
654
|
-
14,
|
|
655
|
-
3,
|
|
656
|
-
6,
|
|
657
|
-
7,
|
|
658
|
-
1,
|
|
659
|
-
9,
|
|
660
|
-
4,
|
|
661
|
-
7,
|
|
662
|
-
9,
|
|
663
|
-
3,
|
|
664
|
-
1,
|
|
665
|
-
13,
|
|
666
|
-
12,
|
|
667
|
-
11,
|
|
668
|
-
14,
|
|
669
|
-
2,
|
|
670
|
-
6,
|
|
671
|
-
5,
|
|
672
|
-
10,
|
|
673
|
-
4,
|
|
674
|
-
0,
|
|
675
|
-
15,
|
|
676
|
-
8,
|
|
677
|
-
9,
|
|
678
|
-
0,
|
|
679
|
-
5,
|
|
680
|
-
7,
|
|
681
|
-
2,
|
|
682
|
-
4,
|
|
683
|
-
10,
|
|
684
|
-
15,
|
|
685
|
-
14,
|
|
686
|
-
1,
|
|
687
|
-
11,
|
|
688
|
-
12,
|
|
689
|
-
6,
|
|
690
|
-
8,
|
|
691
|
-
3,
|
|
692
|
-
13,
|
|
693
|
-
2,
|
|
694
|
-
12,
|
|
695
|
-
6,
|
|
696
|
-
10,
|
|
697
|
-
0,
|
|
698
|
-
11,
|
|
699
|
-
8,
|
|
700
|
-
3,
|
|
701
|
-
4,
|
|
702
|
-
13,
|
|
703
|
-
7,
|
|
704
|
-
5,
|
|
705
|
-
15,
|
|
706
|
-
14,
|
|
707
|
-
1,
|
|
708
|
-
9,
|
|
709
|
-
12,
|
|
710
|
-
5,
|
|
711
|
-
1,
|
|
712
|
-
15,
|
|
713
|
-
14,
|
|
714
|
-
13,
|
|
715
|
-
4,
|
|
716
|
-
10,
|
|
717
|
-
0,
|
|
718
|
-
7,
|
|
719
|
-
6,
|
|
720
|
-
3,
|
|
721
|
-
9,
|
|
722
|
-
2,
|
|
723
|
-
8,
|
|
724
|
-
11,
|
|
725
|
-
13,
|
|
726
|
-
11,
|
|
727
|
-
7,
|
|
728
|
-
14,
|
|
729
|
-
12,
|
|
730
|
-
1,
|
|
731
|
-
3,
|
|
732
|
-
9,
|
|
733
|
-
5,
|
|
734
|
-
0,
|
|
735
|
-
15,
|
|
736
|
-
4,
|
|
737
|
-
8,
|
|
738
|
-
6,
|
|
739
|
-
2,
|
|
740
|
-
10,
|
|
741
|
-
6,
|
|
742
|
-
15,
|
|
743
|
-
14,
|
|
744
|
-
9,
|
|
745
|
-
11,
|
|
746
|
-
3,
|
|
747
|
-
0,
|
|
748
|
-
8,
|
|
749
|
-
12,
|
|
750
|
-
2,
|
|
751
|
-
13,
|
|
752
|
-
7,
|
|
753
|
-
1,
|
|
754
|
-
4,
|
|
755
|
-
10,
|
|
756
|
-
5,
|
|
757
|
-
10,
|
|
758
|
-
2,
|
|
759
|
-
8,
|
|
760
|
-
4,
|
|
761
|
-
7,
|
|
762
|
-
6,
|
|
763
|
-
1,
|
|
764
|
-
5,
|
|
765
|
-
15,
|
|
766
|
-
11,
|
|
767
|
-
9,
|
|
768
|
-
14,
|
|
769
|
-
3,
|
|
770
|
-
12,
|
|
771
|
-
13,
|
|
772
|
-
0
|
|
773
|
-
]);
|
|
774
|
-
var v = new Uint32Array(16);
|
|
775
|
-
var m = new Uint32Array(16);
|
|
776
|
-
function blake2sCompress(ctx, last) {
|
|
777
|
-
let i = 0;
|
|
778
|
-
for (i = 0; i < 8; i++) {
|
|
779
|
-
v[i] = ctx.h[i];
|
|
780
|
-
v[i + 8] = BLAKE2S_IV[i];
|
|
781
|
-
}
|
|
782
|
-
v[12] ^= ctx.t;
|
|
783
|
-
v[13] ^= ctx.t / 4294967296;
|
|
784
|
-
if (last) {
|
|
785
|
-
v[14] = ~v[14];
|
|
786
|
-
}
|
|
787
|
-
for (i = 0; i < 16; i++) {
|
|
788
|
-
m[i] = B2S_GET32(ctx.b, 4 * i);
|
|
789
|
-
}
|
|
790
|
-
for (i = 0; i < 10; i++) {
|
|
791
|
-
B2S_G(0, 4, 8, 12, m[SIGMA[i * 16 + 0]], m[SIGMA[i * 16 + 1]]);
|
|
792
|
-
B2S_G(1, 5, 9, 13, m[SIGMA[i * 16 + 2]], m[SIGMA[i * 16 + 3]]);
|
|
793
|
-
B2S_G(2, 6, 10, 14, m[SIGMA[i * 16 + 4]], m[SIGMA[i * 16 + 5]]);
|
|
794
|
-
B2S_G(3, 7, 11, 15, m[SIGMA[i * 16 + 6]], m[SIGMA[i * 16 + 7]]);
|
|
795
|
-
B2S_G(0, 5, 10, 15, m[SIGMA[i * 16 + 8]], m[SIGMA[i * 16 + 9]]);
|
|
796
|
-
B2S_G(1, 6, 11, 12, m[SIGMA[i * 16 + 10]], m[SIGMA[i * 16 + 11]]);
|
|
797
|
-
B2S_G(2, 7, 8, 13, m[SIGMA[i * 16 + 12]], m[SIGMA[i * 16 + 13]]);
|
|
798
|
-
B2S_G(3, 4, 9, 14, m[SIGMA[i * 16 + 14]], m[SIGMA[i * 16 + 15]]);
|
|
799
|
-
}
|
|
800
|
-
for (i = 0; i < 8; i++) {
|
|
801
|
-
ctx.h[i] ^= v[i] ^ v[i + 8];
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
function blake2sInit(outlen, key) {
|
|
805
|
-
if (!(outlen > 0 && outlen <= 32)) {
|
|
806
|
-
throw new Error("Incorrect output length, should be in [1, 32]");
|
|
807
|
-
}
|
|
808
|
-
const keylen = key ? key.length : 0;
|
|
809
|
-
if (key && !(keylen > 0 && keylen <= 32)) {
|
|
810
|
-
throw new Error("Incorrect key length, should be in [1, 32]");
|
|
811
|
-
}
|
|
812
|
-
const ctx = {
|
|
813
|
-
h: new Uint32Array(BLAKE2S_IV),
|
|
814
|
-
// hash state
|
|
815
|
-
b: new Uint8Array(64),
|
|
816
|
-
// input block
|
|
817
|
-
c: 0,
|
|
818
|
-
// pointer within block
|
|
819
|
-
t: 0,
|
|
820
|
-
// input count
|
|
821
|
-
outlen
|
|
822
|
-
// output length in bytes
|
|
823
|
-
};
|
|
824
|
-
ctx.h[0] ^= 16842752 ^ keylen << 8 ^ outlen;
|
|
825
|
-
if (keylen > 0) {
|
|
826
|
-
blake2sUpdate(ctx, key);
|
|
827
|
-
ctx.c = 64;
|
|
828
|
-
}
|
|
829
|
-
return ctx;
|
|
830
|
-
}
|
|
831
|
-
function blake2sUpdate(ctx, input) {
|
|
832
|
-
for (let i = 0; i < input.length; i++) {
|
|
833
|
-
if (ctx.c === 64) {
|
|
834
|
-
ctx.t += ctx.c;
|
|
835
|
-
blake2sCompress(ctx, false);
|
|
836
|
-
ctx.c = 0;
|
|
837
|
-
}
|
|
838
|
-
ctx.b[ctx.c++] = input[i];
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
function blake2sFinal(ctx) {
|
|
842
|
-
ctx.t += ctx.c;
|
|
843
|
-
while (ctx.c < 64) {
|
|
844
|
-
ctx.b[ctx.c++] = 0;
|
|
845
|
-
}
|
|
846
|
-
blake2sCompress(ctx, true);
|
|
847
|
-
const out = new Uint8Array(ctx.outlen);
|
|
848
|
-
for (let i = 0; i < ctx.outlen; i++) {
|
|
849
|
-
out[i] = ctx.h[i >> 2] >> 8 * (i & 3) & 255;
|
|
850
|
-
}
|
|
851
|
-
return out;
|
|
852
|
-
}
|
|
853
|
-
function blake2s(input, key, outlen) {
|
|
854
|
-
outlen = outlen || 32;
|
|
855
|
-
input = util.normalizeInput(input);
|
|
856
|
-
const ctx = blake2sInit(outlen, key);
|
|
857
|
-
blake2sUpdate(ctx, input);
|
|
858
|
-
return blake2sFinal(ctx);
|
|
859
|
-
}
|
|
860
|
-
function blake2sHex(input, key, outlen) {
|
|
861
|
-
const output = blake2s(input, key, outlen);
|
|
862
|
-
return util.toHex(output);
|
|
863
|
-
}
|
|
864
|
-
module2.exports = {
|
|
865
|
-
blake2s,
|
|
866
|
-
blake2sHex,
|
|
867
|
-
blake2sInit,
|
|
868
|
-
blake2sUpdate,
|
|
869
|
-
blake2sFinal
|
|
870
|
-
};
|
|
871
|
-
}
|
|
872
|
-
});
|
|
873
|
-
|
|
874
|
-
// ../../node_modules/blakejs/index.js
|
|
875
|
-
var require_blakejs = __commonJS({
|
|
876
|
-
"../../node_modules/blakejs/index.js"(exports2, module2) {
|
|
877
|
-
"use strict";
|
|
878
|
-
var b2b = require_blake2b();
|
|
879
|
-
var b2s = require_blake2s();
|
|
880
|
-
module2.exports = {
|
|
881
|
-
blake2b: b2b.blake2b,
|
|
882
|
-
blake2bHex: b2b.blake2bHex,
|
|
883
|
-
blake2bInit: b2b.blake2bInit,
|
|
884
|
-
blake2bUpdate: b2b.blake2bUpdate,
|
|
885
|
-
blake2bFinal: b2b.blake2bFinal,
|
|
886
|
-
blake2s: b2s.blake2s,
|
|
887
|
-
blake2sHex: b2s.blake2sHex,
|
|
888
|
-
blake2sInit: b2s.blake2sInit,
|
|
889
|
-
blake2sUpdate: b2s.blake2sUpdate,
|
|
890
|
-
blake2sFinal: b2s.blake2sFinal
|
|
891
|
-
};
|
|
892
|
-
}
|
|
893
|
-
});
|
|
894
|
-
|
|
895
30
|
// src/index.ts
|
|
896
31
|
var index_exports = {};
|
|
897
32
|
__export(index_exports, {
|
|
@@ -899,12 +34,14 @@ __export(index_exports, {
|
|
|
899
34
|
BigNum: () => BigNum,
|
|
900
35
|
CIP68_100: () => CIP68_100,
|
|
901
36
|
CIP68_222: () => CIP68_222,
|
|
37
|
+
DEFAULT_FETCHER_OPTIONS: () => DEFAULT_FETCHER_OPTIONS,
|
|
902
38
|
DEFAULT_PROTOCOL_PARAMETERS: () => DEFAULT_PROTOCOL_PARAMETERS,
|
|
903
39
|
DEFAULT_REDEEMER_BUDGET: () => DEFAULT_REDEEMER_BUDGET,
|
|
904
40
|
DEFAULT_V1_COST_MODEL_LIST: () => DEFAULT_V1_COST_MODEL_LIST,
|
|
905
41
|
DEFAULT_V2_COST_MODEL_LIST: () => DEFAULT_V2_COST_MODEL_LIST,
|
|
906
42
|
DEFAULT_V3_COST_MODEL_LIST: () => DEFAULT_V3_COST_MODEL_LIST,
|
|
907
43
|
DREP_DEPOSIT: () => DREP_DEPOSIT,
|
|
44
|
+
GovernanceActionKind: () => GovernanceActionKind,
|
|
908
45
|
HARDENED_KEY_START: () => HARDENED_KEY_START,
|
|
909
46
|
LANGUAGE_VERSIONS: () => LANGUAGE_VERSIONS,
|
|
910
47
|
MeshValue: () => MeshValue,
|
|
@@ -916,7 +53,9 @@ __export(index_exports, {
|
|
|
916
53
|
SUPPORTED_OGMIOS_LINKS: () => SUPPORTED_OGMIOS_LINKS,
|
|
917
54
|
SUPPORTED_TOKENS: () => SUPPORTED_TOKENS,
|
|
918
55
|
SUPPORTED_WALLETS: () => SUPPORTED_WALLETS,
|
|
56
|
+
TxTester: () => TxTester,
|
|
919
57
|
UtxoSelection: () => UtxoSelection,
|
|
58
|
+
VOTING_PROPOSAL_DEPOSIT: () => VOTING_PROPOSAL_DEPOSIT,
|
|
920
59
|
assetClass: () => assetClass,
|
|
921
60
|
assetName: () => assetName,
|
|
922
61
|
assocMap: () => assocMap,
|
|
@@ -925,11 +64,13 @@ __export(index_exports, {
|
|
|
925
64
|
byteString: () => byteString,
|
|
926
65
|
bytesToHex: () => bytesToHex,
|
|
927
66
|
castProtocol: () => castProtocol,
|
|
67
|
+
cloneTxBuilderBody: () => cloneTxBuilderBody,
|
|
928
68
|
conStr: () => conStr,
|
|
929
69
|
conStr0: () => conStr0,
|
|
930
70
|
conStr1: () => conStr1,
|
|
931
71
|
conStr2: () => conStr2,
|
|
932
72
|
conStr3: () => conStr3,
|
|
73
|
+
credential: () => credential,
|
|
933
74
|
currencySymbol: () => currencySymbol,
|
|
934
75
|
dict: () => dict,
|
|
935
76
|
emptyTxBuilderBody: () => emptyTxBuilderBody,
|
|
@@ -943,8 +84,11 @@ __export(index_exports, {
|
|
|
943
84
|
hexToBytes: () => hexToBytes,
|
|
944
85
|
hexToString: () => hexToString,
|
|
945
86
|
integer: () => integer,
|
|
87
|
+
isHexString: () => isHexString,
|
|
946
88
|
isNetwork: () => isNetwork,
|
|
89
|
+
jsonProofToPlutusData: () => jsonProofToPlutusData,
|
|
947
90
|
keepRelevant: () => keepRelevant,
|
|
91
|
+
keySignedLogic: () => keySignedLogic,
|
|
948
92
|
largestFirst: () => largestFirst,
|
|
949
93
|
largestFirstMultiAsset: () => largestFirstMultiAsset,
|
|
950
94
|
list: () => list,
|
|
@@ -955,18 +99,21 @@ __export(index_exports, {
|
|
|
955
99
|
mConStr1: () => mConStr1,
|
|
956
100
|
mConStr2: () => mConStr2,
|
|
957
101
|
mConStr3: () => mConStr3,
|
|
102
|
+
mCredential: () => mCredential,
|
|
958
103
|
mMaybeStakingHash: () => mMaybeStakingHash,
|
|
959
104
|
mNone: () => mNone,
|
|
960
105
|
mOption: () => mOption,
|
|
961
106
|
mOutputReference: () => mOutputReference,
|
|
962
107
|
mPlutusBSArrayToString: () => mPlutusBSArrayToString,
|
|
963
108
|
mPubKeyAddress: () => mPubKeyAddress,
|
|
109
|
+
mScript: () => mScript,
|
|
964
110
|
mScriptAddress: () => mScriptAddress,
|
|
965
111
|
mSome: () => mSome,
|
|
966
112
|
mStringToPlutusBSArray: () => mStringToPlutusBSArray,
|
|
967
113
|
mTuple: () => mTuple,
|
|
968
114
|
mTxOutRef: () => mTxOutRef,
|
|
969
115
|
mValue: () => mValue,
|
|
116
|
+
mVerificationKey: () => mVerificationKey,
|
|
970
117
|
maybeStakingHash: () => maybeStakingHash,
|
|
971
118
|
mergeAssets: () => mergeAssets,
|
|
972
119
|
metadataStandardKeys: () => metadataStandardKeys,
|
|
@@ -975,6 +122,7 @@ __export(index_exports, {
|
|
|
975
122
|
none: () => none,
|
|
976
123
|
option: () => option,
|
|
977
124
|
outputReference: () => outputReference,
|
|
125
|
+
pairs: () => pairs,
|
|
978
126
|
parseAssetUnit: () => parseAssetUnit,
|
|
979
127
|
plutusBSArrayToString: () => plutusBSArrayToString,
|
|
980
128
|
policyId: () => policyId,
|
|
@@ -987,6 +135,7 @@ __export(index_exports, {
|
|
|
987
135
|
resolveSlotNo: () => resolveSlotNo,
|
|
988
136
|
resolveTxFees: () => resolveTxFees,
|
|
989
137
|
royaltiesStandardKeys: () => royaltiesStandardKeys,
|
|
138
|
+
script: () => script,
|
|
990
139
|
scriptAddress: () => scriptAddress,
|
|
991
140
|
scriptHash: () => scriptHash,
|
|
992
141
|
slotToBeginUnixTime: () => slotToBeginUnixTime,
|
|
@@ -995,12 +144,16 @@ __export(index_exports, {
|
|
|
995
144
|
stringToHex: () => stringToHex,
|
|
996
145
|
toBytes: () => toBytes,
|
|
997
146
|
toUTF8: () => toUTF8,
|
|
147
|
+
tokenMintedLogic: () => tokenMintedLogic,
|
|
998
148
|
tokenName: () => tokenName,
|
|
999
149
|
tuple: () => tuple,
|
|
150
|
+
txInToUtxo: () => txInToUtxo,
|
|
1000
151
|
txOutRef: () => txOutRef,
|
|
1001
152
|
unixTimeToEnclosingSlot: () => unixTimeToEnclosingSlot,
|
|
153
|
+
validityRangeFromObj: () => validityRangeFromObj,
|
|
1002
154
|
validityRangeToObj: () => validityRangeToObj,
|
|
1003
|
-
value: () => value
|
|
155
|
+
value: () => value,
|
|
156
|
+
verificationKey: () => verificationKey
|
|
1004
157
|
});
|
|
1005
158
|
module.exports = __toCommonJS(index_exports);
|
|
1006
159
|
|
|
@@ -1029,6 +182,7 @@ var DEFAULT_PROTOCOL_PARAMETERS = {
|
|
|
1029
182
|
minFeeRefScriptCostPerByte: 15
|
|
1030
183
|
};
|
|
1031
184
|
var DREP_DEPOSIT = "500000000";
|
|
185
|
+
var VOTING_PROPOSAL_DEPOSIT = "100000000000";
|
|
1032
186
|
var resolveTxFees = (txSize, minFeeA = DEFAULT_PROTOCOL_PARAMETERS.minFeeA, minFeeB = DEFAULT_PROTOCOL_PARAMETERS.minFeeB) => {
|
|
1033
187
|
const fees = BigInt(minFeeA) * BigInt(txSize) + BigInt(minFeeB);
|
|
1034
188
|
return fees.toString();
|
|
@@ -1773,6 +927,12 @@ var CIP68_222 = (tokenNameHex) => {
|
|
|
1773
927
|
return `000de140${tokenNameHex}`;
|
|
1774
928
|
};
|
|
1775
929
|
|
|
930
|
+
// src/interfaces/fetcher.ts
|
|
931
|
+
var DEFAULT_FETCHER_OPTIONS = {
|
|
932
|
+
maxPage: 20,
|
|
933
|
+
order: "desc"
|
|
934
|
+
};
|
|
935
|
+
|
|
1776
936
|
// src/types/asset.ts
|
|
1777
937
|
var mergeAssets = (assets) => {
|
|
1778
938
|
const merged = [];
|
|
@@ -1842,10 +1002,25 @@ var castProtocol = (data) => {
|
|
|
1842
1002
|
return result;
|
|
1843
1003
|
};
|
|
1844
1004
|
|
|
1005
|
+
// src/types/transaction-builder/txin.ts
|
|
1006
|
+
var txInToUtxo = (txIn) => {
|
|
1007
|
+
return {
|
|
1008
|
+
input: {
|
|
1009
|
+
txHash: txIn.txHash,
|
|
1010
|
+
outputIndex: txIn.txIndex
|
|
1011
|
+
},
|
|
1012
|
+
output: {
|
|
1013
|
+
address: txIn.address || "",
|
|
1014
|
+
amount: txIn.amount || []
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
};
|
|
1018
|
+
|
|
1845
1019
|
// src/types/transaction-builder/index.ts
|
|
1846
1020
|
var emptyTxBuilderBody = () => ({
|
|
1847
1021
|
inputs: [],
|
|
1848
1022
|
outputs: [],
|
|
1023
|
+
fee: "0",
|
|
1849
1024
|
extraInputs: [],
|
|
1850
1025
|
collaterals: [],
|
|
1851
1026
|
requiredSignatures: [],
|
|
@@ -1853,24 +1028,53 @@ var emptyTxBuilderBody = () => ({
|
|
|
1853
1028
|
mints: [],
|
|
1854
1029
|
changeAddress: "",
|
|
1855
1030
|
metadata: /* @__PURE__ */ new Map(),
|
|
1031
|
+
scriptMetadata: [],
|
|
1856
1032
|
validityRange: {},
|
|
1857
1033
|
certificates: [],
|
|
1858
1034
|
withdrawals: [],
|
|
1859
1035
|
votes: [],
|
|
1036
|
+
proposals: [],
|
|
1860
1037
|
signingKey: [],
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
network: "mainnet"
|
|
1038
|
+
chainedTxs: [],
|
|
1039
|
+
inputsForEvaluation: {},
|
|
1040
|
+
network: "mainnet",
|
|
1041
|
+
expectedNumberKeyWitnesses: 0,
|
|
1042
|
+
expectedByronAddressWitnesses: []
|
|
1867
1043
|
});
|
|
1044
|
+
function cloneTxBuilderBody(body) {
|
|
1045
|
+
const { extraInputs, ...otherProps } = body;
|
|
1046
|
+
const cloned = structuredClone(otherProps);
|
|
1047
|
+
cloned.extraInputs = extraInputs;
|
|
1048
|
+
return cloned;
|
|
1049
|
+
}
|
|
1868
1050
|
var validityRangeToObj = (validityRange) => {
|
|
1869
1051
|
return {
|
|
1870
1052
|
invalidBefore: validityRange.invalidBefore ?? null,
|
|
1871
1053
|
invalidHereafter: validityRange.invalidHereafter ?? null
|
|
1872
1054
|
};
|
|
1873
1055
|
};
|
|
1056
|
+
var validityRangeFromObj = (obj) => {
|
|
1057
|
+
const validityRange = {};
|
|
1058
|
+
if (obj.invalidBefore !== null && obj.invalidBefore !== void 0) {
|
|
1059
|
+
validityRange.invalidBefore = Number(obj.invalidBefore);
|
|
1060
|
+
}
|
|
1061
|
+
if (obj.invalidHereafter !== null && obj.invalidHereafter !== void 0) {
|
|
1062
|
+
validityRange.invalidHereafter = Number(obj.invalidHereafter);
|
|
1063
|
+
}
|
|
1064
|
+
return validityRange;
|
|
1065
|
+
};
|
|
1066
|
+
|
|
1067
|
+
// src/types/governance.ts
|
|
1068
|
+
var GovernanceActionKind = /* @__PURE__ */ ((GovernanceActionKind2) => {
|
|
1069
|
+
GovernanceActionKind2["ParameterChangeAction"] = "ParameterChangeAction";
|
|
1070
|
+
GovernanceActionKind2["HardForkInitiationAction"] = "HardForkInitiationAction";
|
|
1071
|
+
GovernanceActionKind2["TreasuryWithdrawalsAction"] = "TreasuryWithdrawalsAction";
|
|
1072
|
+
GovernanceActionKind2["NoConfidenceAction"] = "NoConfidenceAction";
|
|
1073
|
+
GovernanceActionKind2["UpdateCommitteeAction"] = "UpdateCommitteeAction";
|
|
1074
|
+
GovernanceActionKind2["NewConstitutionAction"] = "NewConstitutionAction";
|
|
1075
|
+
GovernanceActionKind2["InfoAction"] = "InfoAction";
|
|
1076
|
+
return GovernanceActionKind2;
|
|
1077
|
+
})(GovernanceActionKind || {});
|
|
1874
1078
|
|
|
1875
1079
|
// src/data/mesh/constructors.ts
|
|
1876
1080
|
var mConStr = (alternative, fields) => ({
|
|
@@ -1920,7 +1124,7 @@ var mTxOutRef = (txHash, index) => {
|
|
|
1920
1124
|
}
|
|
1921
1125
|
return mConStr0([mConStr0([txHash]), index]);
|
|
1922
1126
|
};
|
|
1923
|
-
var mTuple = (
|
|
1127
|
+
var mTuple = (...args) => args;
|
|
1924
1128
|
var mOption = (value2) => {
|
|
1925
1129
|
if (value2) {
|
|
1926
1130
|
return mSome(value2);
|
|
@@ -1931,14 +1135,16 @@ var mSome = (value2) => mConStr0([value2]);
|
|
|
1931
1135
|
var mNone = () => mConStr1([]);
|
|
1932
1136
|
|
|
1933
1137
|
// src/data/mesh/credentials.ts
|
|
1138
|
+
var mVerificationKey = (bytes) => mConStr0([bytes]);
|
|
1139
|
+
var mScript = (bytes) => mConStr1([bytes]);
|
|
1934
1140
|
var mMaybeStakingHash = (stakeCredential, isStakeScriptCredential = false) => {
|
|
1935
1141
|
if (stakeCredential === "") {
|
|
1936
1142
|
return mConStr1([]);
|
|
1937
1143
|
}
|
|
1938
1144
|
if (isStakeScriptCredential) {
|
|
1939
|
-
return mConStr0([mConStr0([
|
|
1145
|
+
return mConStr0([mConStr0([mScript(stakeCredential)])]);
|
|
1940
1146
|
}
|
|
1941
|
-
return mConStr0([mConStr0([
|
|
1147
|
+
return mConStr0([mConStr0([mVerificationKey(stakeCredential)])]);
|
|
1942
1148
|
};
|
|
1943
1149
|
var mPubKeyAddress = (bytes, stakeCredential, isStakeScriptCredential = false) => mConStr0([
|
|
1944
1150
|
{ alternative: 0, fields: [bytes] },
|
|
@@ -1948,6 +1154,7 @@ var mScriptAddress = (bytes, stakeCredential, isStakeScriptCredential = false) =
|
|
|
1948
1154
|
{ alternative: 1, fields: [bytes] },
|
|
1949
1155
|
mMaybeStakingHash(stakeCredential || "", isStakeScriptCredential)
|
|
1950
1156
|
]);
|
|
1157
|
+
var mCredential = (hash, isScriptCredential = false) => isScriptCredential ? mScript(hash) : mVerificationKey(hash);
|
|
1951
1158
|
|
|
1952
1159
|
// src/data/mesh/primitives.ts
|
|
1953
1160
|
var mBool = (b) => b ? mConStr1([]) : mConStr0([]);
|
|
@@ -2035,11 +1242,25 @@ var assocMap = (mapItems, validation = true) => ({
|
|
|
2035
1242
|
return { k, v };
|
|
2036
1243
|
})
|
|
2037
1244
|
});
|
|
1245
|
+
var pairs = (mapItems, validation = true) => ({
|
|
1246
|
+
map: mapItems.map(([k, v]) => {
|
|
1247
|
+
if (validation) {
|
|
1248
|
+
if (typeof k !== "object" || typeof v !== "object") {
|
|
1249
|
+
throw new Error(
|
|
1250
|
+
`Map item of JSON Cardano data type must be an object - ${k}, ${v}`
|
|
1251
|
+
);
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
return { k, v };
|
|
1255
|
+
})
|
|
1256
|
+
});
|
|
2038
1257
|
|
|
2039
1258
|
// src/data/json/aliases.ts
|
|
2040
1259
|
var hashByteString = (bytes) => {
|
|
2041
1260
|
if (bytes.length !== 56) {
|
|
2042
|
-
throw new Error(
|
|
1261
|
+
throw new Error(
|
|
1262
|
+
`Invalid hash for [${bytes}] - should be 28 bytes (56 hex length) long`
|
|
1263
|
+
);
|
|
2043
1264
|
}
|
|
2044
1265
|
return byteString(bytes);
|
|
2045
1266
|
};
|
|
@@ -2048,7 +1269,7 @@ var pubKeyHash = (bytes) => hashByteString(bytes);
|
|
|
2048
1269
|
var policyId = (bytes) => {
|
|
2049
1270
|
if (bytes.length !== POLICY_ID_LENGTH && bytes !== "") {
|
|
2050
1271
|
throw new Error(
|
|
2051
|
-
`Invalid policy id for [${bytes}] - should be ${POLICY_ID_LENGTH} bytes long or empty string for lovelace`
|
|
1272
|
+
`Invalid policy id for [${bytes}] - should be ${POLICY_ID_LENGTH / 2} bytes (${POLICY_ID_LENGTH} hex length) long or empty string for lovelace`
|
|
2052
1273
|
);
|
|
2053
1274
|
}
|
|
2054
1275
|
return byteString(bytes);
|
|
@@ -2080,7 +1301,9 @@ var posixTime = (int) => ({ int });
|
|
|
2080
1301
|
var dict = (itemsMap) => ({
|
|
2081
1302
|
map: itemsMap.map(([k, v]) => ({ k, v }))
|
|
2082
1303
|
});
|
|
2083
|
-
var tuple = (
|
|
1304
|
+
var tuple = (...args) => ({
|
|
1305
|
+
list: args
|
|
1306
|
+
});
|
|
2084
1307
|
var option = (value2) => {
|
|
2085
1308
|
if (!value2) {
|
|
2086
1309
|
return none();
|
|
@@ -2091,32 +1314,62 @@ var some = (value2) => conStr0([value2]);
|
|
|
2091
1314
|
var none = () => conStr1([]);
|
|
2092
1315
|
|
|
2093
1316
|
// src/data/json/credentials.ts
|
|
1317
|
+
var verificationKey = (bytes) => conStr0([pubKeyHash(bytes)]);
|
|
1318
|
+
var script = (bytes) => conStr1([scriptHash(bytes)]);
|
|
2094
1319
|
var maybeStakingHash = (stakeCredential, isStakeScriptCredential = false) => {
|
|
2095
1320
|
if (stakeCredential === "") {
|
|
2096
1321
|
return conStr1([]);
|
|
2097
1322
|
}
|
|
2098
1323
|
if (isStakeScriptCredential) {
|
|
2099
|
-
return conStr0([
|
|
2100
|
-
conStr0([conStr1([scriptHash(stakeCredential)])])
|
|
2101
|
-
]);
|
|
1324
|
+
return conStr0([conStr0([script(stakeCredential)])]);
|
|
2102
1325
|
}
|
|
2103
|
-
return conStr0([
|
|
2104
|
-
conStr0([conStr0([pubKeyHash(stakeCredential)])])
|
|
2105
|
-
]);
|
|
1326
|
+
return conStr0([conStr0([verificationKey(stakeCredential)])]);
|
|
2106
1327
|
};
|
|
2107
1328
|
var pubKeyAddress = (bytes, stakeCredential, isStakeScriptCredential = false) => conStr0([
|
|
2108
1329
|
conStr0([pubKeyHash(bytes)]),
|
|
2109
1330
|
maybeStakingHash(stakeCredential || "", isStakeScriptCredential)
|
|
2110
1331
|
]);
|
|
2111
1332
|
var scriptAddress = (bytes, stakeCredential, isStakeScriptCredential = false) => conStr0([
|
|
2112
|
-
|
|
1333
|
+
script(bytes),
|
|
2113
1334
|
maybeStakingHash(stakeCredential || "", isStakeScriptCredential)
|
|
2114
1335
|
]);
|
|
1336
|
+
var credential = (hash, isScriptCredential = false) => isScriptCredential ? script(hash) : verificationKey(hash);
|
|
1337
|
+
|
|
1338
|
+
// src/data/json/mpf.ts
|
|
1339
|
+
var jsonProofToPlutusData = (proof) => {
|
|
1340
|
+
const proofSteps = [];
|
|
1341
|
+
const proofJson = proof;
|
|
1342
|
+
proofJson.forEach((proof2) => {
|
|
1343
|
+
const skip = integer(proof2.skip);
|
|
1344
|
+
switch (proof2.type) {
|
|
1345
|
+
case "branch":
|
|
1346
|
+
proofSteps.push(
|
|
1347
|
+
conStr0([skip, byteString(proof2.neighbors.toString("hex"))])
|
|
1348
|
+
);
|
|
1349
|
+
break;
|
|
1350
|
+
case "fork":
|
|
1351
|
+
const { prefix, nibble, root } = proof2.neighbor;
|
|
1352
|
+
const neighbor = conStr0([
|
|
1353
|
+
integer(nibble),
|
|
1354
|
+
byteString(prefix.toString("hex")),
|
|
1355
|
+
byteString(root.toString("hex"))
|
|
1356
|
+
]);
|
|
1357
|
+
proofSteps.push(conStr1([skip, neighbor]));
|
|
1358
|
+
break;
|
|
1359
|
+
case "leaf":
|
|
1360
|
+
const { key, value: value2 } = proof2.neighbor;
|
|
1361
|
+
proofSteps.push(conStr2([skip, byteString(key), byteString(value2)]));
|
|
1362
|
+
break;
|
|
1363
|
+
}
|
|
1364
|
+
});
|
|
1365
|
+
return proofSteps;
|
|
1366
|
+
};
|
|
2115
1367
|
|
|
2116
1368
|
// src/data/parser.ts
|
|
2117
1369
|
var bytesToHex = (bytes) => Buffer.from(bytes).toString("hex");
|
|
2118
1370
|
var hexToBytes = (hex) => Buffer.from(hex, "hex");
|
|
2119
1371
|
var stringToHex = (str) => Buffer.from(str, "utf8").toString("hex");
|
|
1372
|
+
var isHexString = (hex) => /^[0-9A-F]*$/i.test(hex);
|
|
2120
1373
|
var hexToString = (hex) => Buffer.from(hex, "hex").toString("utf8");
|
|
2121
1374
|
var toBytes = (hex) => {
|
|
2122
1375
|
if (hex.length % 2 === 0 && /^[0-9A-F]*$/i.test(hex))
|
|
@@ -2295,10 +1548,10 @@ var BigNum = class _BigNum {
|
|
|
2295
1548
|
};
|
|
2296
1549
|
|
|
2297
1550
|
// src/utils/data-hash.ts
|
|
2298
|
-
var import_blakejs =
|
|
1551
|
+
var import_blakejs = require("blakejs");
|
|
2299
1552
|
var hashDrepAnchor = (jsonLD) => {
|
|
2300
|
-
const jsonHash = (0, import_blakejs.
|
|
2301
|
-
return jsonHash;
|
|
1553
|
+
const jsonHash = (0, import_blakejs.blake2b)(JSON.stringify(jsonLD, null, 2), void 0, 32);
|
|
1554
|
+
return Buffer.from(jsonHash).toString("hex");
|
|
2302
1555
|
};
|
|
2303
1556
|
|
|
2304
1557
|
// src/utils/file.ts
|
|
@@ -2310,6 +1563,7 @@ function getFile(url) {
|
|
|
2310
1563
|
}
|
|
2311
1564
|
|
|
2312
1565
|
// src/data/value.ts
|
|
1566
|
+
var compareByteOrder = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
2313
1567
|
var value = (assets) => {
|
|
2314
1568
|
return MeshValue.fromAssets(assets).toJSON();
|
|
2315
1569
|
};
|
|
@@ -2321,6 +1575,26 @@ var MeshValue = class _MeshValue {
|
|
|
2321
1575
|
constructor(value2 = {}) {
|
|
2322
1576
|
this.value = value2;
|
|
2323
1577
|
}
|
|
1578
|
+
/**
|
|
1579
|
+
* Sort a Value (JSON representation) by policy ID then token name
|
|
1580
|
+
* @param plutusValue The Value to sort
|
|
1581
|
+
* @returns Sorted Value
|
|
1582
|
+
*/
|
|
1583
|
+
static sortValue = (plutusValue) => {
|
|
1584
|
+
const sortedPolicies = [...plutusValue.map].sort(
|
|
1585
|
+
(a, b) => compareByteOrder(a.k.bytes, b.k.bytes)
|
|
1586
|
+
);
|
|
1587
|
+
const sortedMap = sortedPolicies.map((policyEntry) => {
|
|
1588
|
+
const sortedTokens = [...policyEntry.v.map].sort(
|
|
1589
|
+
(a, b) => compareByteOrder(a.k.bytes, b.k.bytes)
|
|
1590
|
+
);
|
|
1591
|
+
return {
|
|
1592
|
+
k: policyEntry.k,
|
|
1593
|
+
v: { map: sortedTokens }
|
|
1594
|
+
};
|
|
1595
|
+
});
|
|
1596
|
+
return { map: sortedMap };
|
|
1597
|
+
};
|
|
2324
1598
|
/**
|
|
2325
1599
|
* Converting assets into MeshValue
|
|
2326
1600
|
* @param assets The assets to convert
|
|
@@ -2411,6 +1685,23 @@ var MeshValue = class _MeshValue {
|
|
|
2411
1685
|
get = (unit) => {
|
|
2412
1686
|
return this.value[unit] ? BigInt(this.value[unit]) : BigInt(0);
|
|
2413
1687
|
};
|
|
1688
|
+
/**
|
|
1689
|
+
* Get all assets that belong to a specific policy ID
|
|
1690
|
+
* @param policyId The policy ID to filter by
|
|
1691
|
+
* @returns Array of assets that match the policy ID
|
|
1692
|
+
*/
|
|
1693
|
+
getPolicyAssets = (policyId2) => {
|
|
1694
|
+
const assets = [];
|
|
1695
|
+
Object.entries(this.value).forEach(([unit, quantity]) => {
|
|
1696
|
+
if (unit.startsWith(policyId2)) {
|
|
1697
|
+
assets.push({
|
|
1698
|
+
unit,
|
|
1699
|
+
quantity: quantity.toString()
|
|
1700
|
+
});
|
|
1701
|
+
}
|
|
1702
|
+
});
|
|
1703
|
+
return assets;
|
|
1704
|
+
};
|
|
2414
1705
|
/**
|
|
2415
1706
|
* Get all asset units
|
|
2416
1707
|
* @returns The asset units
|
|
@@ -2458,6 +1749,26 @@ var MeshValue = class _MeshValue {
|
|
|
2458
1749
|
}
|
|
2459
1750
|
return BigInt(this.value[unit]) <= BigInt(other.value[unit]);
|
|
2460
1751
|
};
|
|
1752
|
+
/**
|
|
1753
|
+
* Check if the value is equal to another value
|
|
1754
|
+
* @param other - The value to compare against
|
|
1755
|
+
* @returns boolean
|
|
1756
|
+
*/
|
|
1757
|
+
eq = (other) => {
|
|
1758
|
+
return Object.keys(this.value).every((key) => this.eqUnit(key, other));
|
|
1759
|
+
};
|
|
1760
|
+
/**
|
|
1761
|
+
* Check if the specific unit of value is equal to that unit of another value
|
|
1762
|
+
* @param unit - The unit to compare
|
|
1763
|
+
* @param other - The value to compare against
|
|
1764
|
+
* @returns boolean
|
|
1765
|
+
*/
|
|
1766
|
+
eqUnit = (unit, other) => {
|
|
1767
|
+
if (this.value[unit] === void 0 || other.value[unit] === void 0) {
|
|
1768
|
+
return false;
|
|
1769
|
+
}
|
|
1770
|
+
return BigInt(this.value[unit]) === BigInt(other.value[unit]);
|
|
1771
|
+
};
|
|
2461
1772
|
/**
|
|
2462
1773
|
* Check if the value is empty
|
|
2463
1774
|
* @returns boolean
|
|
@@ -2492,17 +1803,18 @@ var MeshValue = class _MeshValue {
|
|
|
2492
1803
|
};
|
|
2493
1804
|
/**
|
|
2494
1805
|
* Convert the MeshValue object into Cardano data Value in Mesh Data type
|
|
1806
|
+
* Entries are sorted by byte ordering of policy ID, then token name
|
|
2495
1807
|
*/
|
|
2496
1808
|
toData = () => {
|
|
2497
|
-
const
|
|
1809
|
+
const unsortedMap = /* @__PURE__ */ new Map();
|
|
2498
1810
|
this.toAssets().forEach((asset) => {
|
|
2499
1811
|
const sanitizedName = asset.unit.replace("lovelace", "");
|
|
2500
1812
|
const policy = sanitizedName.slice(0, 56) || "";
|
|
2501
1813
|
const token = sanitizedName.slice(56) || "";
|
|
2502
|
-
if (!
|
|
2503
|
-
|
|
1814
|
+
if (!unsortedMap.has(policy)) {
|
|
1815
|
+
unsortedMap.set(policy, /* @__PURE__ */ new Map());
|
|
2504
1816
|
}
|
|
2505
|
-
const tokenMap =
|
|
1817
|
+
const tokenMap = unsortedMap.get(policy);
|
|
2506
1818
|
const quantity = tokenMap?.get(token);
|
|
2507
1819
|
if (!quantity) {
|
|
2508
1820
|
tokenMap.set(token, BigInt(asset.quantity));
|
|
@@ -2510,10 +1822,24 @@ var MeshValue = class _MeshValue {
|
|
|
2510
1822
|
tokenMap.set(token, quantity + BigInt(asset.quantity));
|
|
2511
1823
|
}
|
|
2512
1824
|
});
|
|
1825
|
+
const sortedPolicies = Array.from(unsortedMap.keys()).sort(compareByteOrder);
|
|
1826
|
+
const valueMap = /* @__PURE__ */ new Map();
|
|
1827
|
+
sortedPolicies.forEach((policy) => {
|
|
1828
|
+
const unsortedTokenMap = unsortedMap.get(policy);
|
|
1829
|
+
const sortedTokens = Array.from(unsortedTokenMap.keys()).sort(
|
|
1830
|
+
compareByteOrder
|
|
1831
|
+
);
|
|
1832
|
+
const sortedTokenMap = /* @__PURE__ */ new Map();
|
|
1833
|
+
sortedTokens.forEach((token) => {
|
|
1834
|
+
sortedTokenMap.set(token, unsortedTokenMap.get(token));
|
|
1835
|
+
});
|
|
1836
|
+
valueMap.set(policy, sortedTokenMap);
|
|
1837
|
+
});
|
|
2513
1838
|
return valueMap;
|
|
2514
1839
|
};
|
|
2515
1840
|
/**
|
|
2516
1841
|
* Convert the MeshValue object into a JSON representation of Cardano data Value
|
|
1842
|
+
* Entries are sorted by byte ordering of policy ID, then token name
|
|
2517
1843
|
* @returns Cardano data Value in JSON
|
|
2518
1844
|
*/
|
|
2519
1845
|
toJSON = () => {
|
|
@@ -2532,11 +1858,16 @@ var MeshValue = class _MeshValue {
|
|
|
2532
1858
|
valueMap[policy][token] += Number(asset.quantity);
|
|
2533
1859
|
}
|
|
2534
1860
|
});
|
|
2535
|
-
Object.keys(valueMap).
|
|
1861
|
+
const sortedPolicies = Object.keys(valueMap).sort(compareByteOrder);
|
|
1862
|
+
sortedPolicies.forEach((policy) => {
|
|
2536
1863
|
const policyByte = currencySymbol(policy);
|
|
2537
|
-
const
|
|
2538
|
-
|
|
1864
|
+
const sortedTokenNames = Object.keys(valueMap[policy]).sort(
|
|
1865
|
+
compareByteOrder
|
|
2539
1866
|
);
|
|
1867
|
+
const tokens = sortedTokenNames.map((name) => [
|
|
1868
|
+
tokenName(name),
|
|
1869
|
+
integer(valueMap[policy][name])
|
|
1870
|
+
]);
|
|
2540
1871
|
const policyMap = assocMap(tokens);
|
|
2541
1872
|
valueMapToParse.push([policyByte, policyMap]);
|
|
2542
1873
|
});
|
|
@@ -2560,7 +1891,7 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
2560
1891
|
const selectedInputs = /* @__PURE__ */ new Set();
|
|
2561
1892
|
const onlyLovelace = /* @__PURE__ */ new Set();
|
|
2562
1893
|
const singletons = /* @__PURE__ */ new Set();
|
|
2563
|
-
const
|
|
1894
|
+
const pairs2 = /* @__PURE__ */ new Set();
|
|
2564
1895
|
const rest = /* @__PURE__ */ new Set();
|
|
2565
1896
|
const collaterals = /* @__PURE__ */ new Set();
|
|
2566
1897
|
for (let i = 0; i < inputs.length; i++) {
|
|
@@ -2579,7 +1910,7 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
2579
1910
|
break;
|
|
2580
1911
|
}
|
|
2581
1912
|
case 3: {
|
|
2582
|
-
|
|
1913
|
+
pairs2.add(i);
|
|
2583
1914
|
break;
|
|
2584
1915
|
}
|
|
2585
1916
|
default: {
|
|
@@ -2612,10 +1943,10 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
2612
1943
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
2613
1944
|
addUtxoWithAssetAmount(inputIndex, assetUnit, singletons);
|
|
2614
1945
|
}
|
|
2615
|
-
for (const inputIndex of
|
|
1946
|
+
for (const inputIndex of pairs2) {
|
|
2616
1947
|
const assetRequired = totalRequiredAssets.get(assetUnit);
|
|
2617
1948
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
2618
|
-
addUtxoWithAssetAmount(inputIndex, assetUnit,
|
|
1949
|
+
addUtxoWithAssetAmount(inputIndex, assetUnit, pairs2);
|
|
2619
1950
|
}
|
|
2620
1951
|
for (const inputIndex of rest) {
|
|
2621
1952
|
const assetRequired = totalRequiredAssets.get(assetUnit);
|
|
@@ -2633,10 +1964,10 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
2633
1964
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
2634
1965
|
addUtxoWithAssetAmount(inputIndex, "lovelace", singletons);
|
|
2635
1966
|
}
|
|
2636
|
-
for (const inputIndex of
|
|
1967
|
+
for (const inputIndex of pairs2) {
|
|
2637
1968
|
const assetRequired = totalRequiredAssets.get("lovelace");
|
|
2638
1969
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
2639
|
-
addUtxoWithAssetAmount(inputIndex, "lovelace",
|
|
1970
|
+
addUtxoWithAssetAmount(inputIndex, "lovelace", pairs2);
|
|
2640
1971
|
}
|
|
2641
1972
|
for (const inputIndex of rest) {
|
|
2642
1973
|
const assetRequired = totalRequiredAssets.get("lovelace");
|
|
@@ -2811,6 +2142,473 @@ var UtxoSelection = class {
|
|
|
2811
2142
|
}
|
|
2812
2143
|
};
|
|
2813
2144
|
|
|
2145
|
+
// src/tx-tester/index.ts
|
|
2146
|
+
var TxTester = class {
|
|
2147
|
+
txBody;
|
|
2148
|
+
inputsEvaluating;
|
|
2149
|
+
outputsEvaluating;
|
|
2150
|
+
traces;
|
|
2151
|
+
/**
|
|
2152
|
+
* Create a new TxTester instance
|
|
2153
|
+
* @param txBody The transaction builder body
|
|
2154
|
+
*/
|
|
2155
|
+
constructor(txBody) {
|
|
2156
|
+
this.txBody = { ...txBody };
|
|
2157
|
+
this.inputsEvaluating = [];
|
|
2158
|
+
this.outputsEvaluating = [];
|
|
2159
|
+
this.traces = [];
|
|
2160
|
+
}
|
|
2161
|
+
/**
|
|
2162
|
+
* Add a trace to the TxTester
|
|
2163
|
+
* @param funcName The function name where the error occurred
|
|
2164
|
+
* @param message The error message
|
|
2165
|
+
*/
|
|
2166
|
+
addTrace(funcName, message) {
|
|
2167
|
+
const msg = `[Error - ${funcName}]: ${message}`;
|
|
2168
|
+
this.traces.push(msg);
|
|
2169
|
+
}
|
|
2170
|
+
/**
|
|
2171
|
+
* Check if the transaction evaluation was successful
|
|
2172
|
+
* @returns true if there are no errors, false otherwise
|
|
2173
|
+
*/
|
|
2174
|
+
success() {
|
|
2175
|
+
return this.traces.length === 0;
|
|
2176
|
+
}
|
|
2177
|
+
/**
|
|
2178
|
+
* Get the error messages if any
|
|
2179
|
+
* @returns A string representation of the errors or "No errors" if there are none
|
|
2180
|
+
*/
|
|
2181
|
+
errors() {
|
|
2182
|
+
if (this.traces.length > 0) {
|
|
2183
|
+
return `${this.traces}`;
|
|
2184
|
+
} else {
|
|
2185
|
+
return "No errors";
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
/**
|
|
2189
|
+
* Checks if the transaction is valid after a specified timestamp.
|
|
2190
|
+
* @param requiredTimestamp The timestamp after which the transaction should be valid
|
|
2191
|
+
* @returns The TxTester instance for chaining
|
|
2192
|
+
*/
|
|
2193
|
+
validAfter = (requiredTimestamp) => {
|
|
2194
|
+
const invalidBefore = this.txBody.validityRange?.invalidHereafter ? this.txBody.validityRange.invalidHereafter : 9999999999999;
|
|
2195
|
+
const isValidAfter = this.txBody.validityRange?.invalidBefore ? this.txBody.validityRange.invalidBefore < requiredTimestamp : true;
|
|
2196
|
+
if (!isValidAfter) {
|
|
2197
|
+
this.addTrace(
|
|
2198
|
+
"validAfter",
|
|
2199
|
+
`tx invalid before ${invalidBefore}, with requiredTimestamp ${requiredTimestamp}`
|
|
2200
|
+
);
|
|
2201
|
+
}
|
|
2202
|
+
return this;
|
|
2203
|
+
};
|
|
2204
|
+
/**
|
|
2205
|
+
* Checks if the transaction is valid before a specified timestamp.
|
|
2206
|
+
* @param requiredTimestamp The timestamp before which the transaction should be valid
|
|
2207
|
+
* @returns The TxTester instance for chaining
|
|
2208
|
+
*/
|
|
2209
|
+
validBefore = (requiredTimestamp) => {
|
|
2210
|
+
const invalidHereafter = this.txBody.validityRange?.invalidBefore ? this.txBody.validityRange.invalidBefore : 0;
|
|
2211
|
+
const isValidBefore = this.txBody.validityRange?.invalidHereafter ? this.txBody.validityRange.invalidHereafter > requiredTimestamp : true;
|
|
2212
|
+
if (!isValidBefore) {
|
|
2213
|
+
this.addTrace(
|
|
2214
|
+
"validBefore",
|
|
2215
|
+
`tx invalid after ${invalidHereafter}, with requiredTimestamp ${requiredTimestamp}`
|
|
2216
|
+
);
|
|
2217
|
+
}
|
|
2218
|
+
return this;
|
|
2219
|
+
};
|
|
2220
|
+
// Extra Signatories Methods
|
|
2221
|
+
/**
|
|
2222
|
+
* Checks if a specific key is signed in the transaction.
|
|
2223
|
+
* @param keyHash The key hash to check
|
|
2224
|
+
* @returns The TxTester instance for chaining
|
|
2225
|
+
*/
|
|
2226
|
+
keySigned = (keyHash) => {
|
|
2227
|
+
const isKeySigned = keySignedLogic(this.txBody.requiredSignatures, keyHash);
|
|
2228
|
+
if (!isKeySigned) {
|
|
2229
|
+
this.addTrace("keySigned", `tx does not have key ${keyHash} signed`);
|
|
2230
|
+
}
|
|
2231
|
+
return this;
|
|
2232
|
+
};
|
|
2233
|
+
/**
|
|
2234
|
+
* Checks if any one of the specified keys is signed in the transaction.
|
|
2235
|
+
* @param keyHashes The array of key hashes to check
|
|
2236
|
+
* @returns The TxTester instance for chaining
|
|
2237
|
+
*/
|
|
2238
|
+
oneOfKeysSigned = (keyHashes) => {
|
|
2239
|
+
const isOneOfKeysSigned = keyHashes.some(
|
|
2240
|
+
(keyHash) => keySignedLogic(this.txBody.requiredSignatures, keyHash)
|
|
2241
|
+
);
|
|
2242
|
+
if (!isOneOfKeysSigned) {
|
|
2243
|
+
this.addTrace(
|
|
2244
|
+
"oneOfKeysSigned",
|
|
2245
|
+
`tx does not have any of the keys signed: ${keyHashes.join(", ")}`
|
|
2246
|
+
);
|
|
2247
|
+
}
|
|
2248
|
+
return this;
|
|
2249
|
+
};
|
|
2250
|
+
/**
|
|
2251
|
+
* Checks if all specified keys are signed in the transaction.
|
|
2252
|
+
* @param keyHashes The array of key hashes to check
|
|
2253
|
+
* @returns The TxTester instance for chaining
|
|
2254
|
+
*/
|
|
2255
|
+
allKeysSigned = (keyHashes) => {
|
|
2256
|
+
const missingKeys = [];
|
|
2257
|
+
const isAllKeysSigned = keyHashes.every((keyHash) => {
|
|
2258
|
+
const isKeySigned = keySignedLogic(
|
|
2259
|
+
this.txBody.requiredSignatures,
|
|
2260
|
+
keyHash
|
|
2261
|
+
);
|
|
2262
|
+
if (!isKeySigned) {
|
|
2263
|
+
missingKeys.push(keyHash);
|
|
2264
|
+
}
|
|
2265
|
+
return isKeySigned;
|
|
2266
|
+
});
|
|
2267
|
+
if (!isAllKeysSigned) {
|
|
2268
|
+
this.addTrace(
|
|
2269
|
+
"allKeysSigned",
|
|
2270
|
+
`tx does not have all keys signed: ${missingKeys.join(", ")}`
|
|
2271
|
+
);
|
|
2272
|
+
}
|
|
2273
|
+
return this;
|
|
2274
|
+
};
|
|
2275
|
+
/**
|
|
2276
|
+
* Checks if a specific token is minted in the transaction.
|
|
2277
|
+
* @param policyId The policy ID of the token
|
|
2278
|
+
* @param assetName The asset name of the token
|
|
2279
|
+
* @param quantity The quantity of the token
|
|
2280
|
+
* @returns The TxTester instance for chaining
|
|
2281
|
+
*/
|
|
2282
|
+
tokenMinted = (policyId2, assetName2, quantity) => {
|
|
2283
|
+
const isTokenMinted = tokenMintedLogic(
|
|
2284
|
+
this.txBody.mints,
|
|
2285
|
+
policyId2,
|
|
2286
|
+
assetName2,
|
|
2287
|
+
quantity
|
|
2288
|
+
);
|
|
2289
|
+
if (!isTokenMinted) {
|
|
2290
|
+
this.addTrace(
|
|
2291
|
+
"tokenMinted",
|
|
2292
|
+
`Token with policy_id: ${policyId2}, asset_name: ${assetName2}, quantity: ${quantity} not found in mints.`
|
|
2293
|
+
);
|
|
2294
|
+
}
|
|
2295
|
+
return this;
|
|
2296
|
+
};
|
|
2297
|
+
/**
|
|
2298
|
+
* Checks if a specific token is minted in the transaction and that it is the only mint.
|
|
2299
|
+
* @param policyId The policy ID of the token
|
|
2300
|
+
* @param assetName The asset name of the token
|
|
2301
|
+
* @param quantity The quantity of the token
|
|
2302
|
+
* @returns The TxTester instance for chaining
|
|
2303
|
+
*/
|
|
2304
|
+
onlyTokenMinted = (policyId2, assetName2, quantity) => {
|
|
2305
|
+
const isTokenMinted = tokenMintedLogic(
|
|
2306
|
+
this.txBody.mints,
|
|
2307
|
+
policyId2,
|
|
2308
|
+
assetName2,
|
|
2309
|
+
quantity
|
|
2310
|
+
);
|
|
2311
|
+
const isOnlyOneMint = this.txBody.mints?.length === 1;
|
|
2312
|
+
if (!isTokenMinted) {
|
|
2313
|
+
this.addTrace(
|
|
2314
|
+
"onlyTokenMinted",
|
|
2315
|
+
`Token with policy_id: ${policyId2}, asset_name: ${assetName2}, quantity: ${quantity} not found in mints`
|
|
2316
|
+
);
|
|
2317
|
+
}
|
|
2318
|
+
if (!isOnlyOneMint) {
|
|
2319
|
+
this.addTrace(
|
|
2320
|
+
"onlyTokenMinted",
|
|
2321
|
+
`Expected only one mint, but found ${this.txBody.mints?.length || 0} mints.`
|
|
2322
|
+
);
|
|
2323
|
+
}
|
|
2324
|
+
return this;
|
|
2325
|
+
};
|
|
2326
|
+
/**
|
|
2327
|
+
* Checks if a specific token is minted in the transaction, ensuring that it is the only mint for the given policy ID.
|
|
2328
|
+
* @param policyId The policy ID of the token
|
|
2329
|
+
* @param assetName The asset name of the token
|
|
2330
|
+
* @param quantity The quantity of the token
|
|
2331
|
+
* @returns The TxTester instance for chaining
|
|
2332
|
+
*/
|
|
2333
|
+
policyOnlyMintedToken = (policyId2, assetName2, quantity) => {
|
|
2334
|
+
const filteredMints = this.txBody.mints?.filter((token) => {
|
|
2335
|
+
return token.policyId === policyId2;
|
|
2336
|
+
}) || [];
|
|
2337
|
+
const isTokenMinted = tokenMintedLogic(
|
|
2338
|
+
this.txBody.mints,
|
|
2339
|
+
policyId2,
|
|
2340
|
+
assetName2,
|
|
2341
|
+
quantity
|
|
2342
|
+
);
|
|
2343
|
+
const isOnlyOneMint = filteredMints.length === 1;
|
|
2344
|
+
if (!isOnlyOneMint) {
|
|
2345
|
+
this.addTrace(
|
|
2346
|
+
"policyOnlyMintedToken",
|
|
2347
|
+
`Expected only one mint for policy_id: ${policyId2}, but found ${filteredMints.length} mints.`
|
|
2348
|
+
);
|
|
2349
|
+
}
|
|
2350
|
+
if (!isTokenMinted) {
|
|
2351
|
+
this.addTrace(
|
|
2352
|
+
"policyOnlyMintedToken",
|
|
2353
|
+
`Token with policy_id: ${policyId2}, asset_name: ${assetName2}, quantity: ${quantity} not found in mints.`
|
|
2354
|
+
);
|
|
2355
|
+
}
|
|
2356
|
+
return this;
|
|
2357
|
+
};
|
|
2358
|
+
/**
|
|
2359
|
+
* Checks if a specific policy ID is burned in the transaction, ensuring that it is the only minting (i.e. burning item).
|
|
2360
|
+
* @param policyId The policy ID to check
|
|
2361
|
+
* @returns true if the policy is the only burn, false otherwise
|
|
2362
|
+
*/
|
|
2363
|
+
checkPolicyOnlyBurn = (policyId2) => {
|
|
2364
|
+
const filteredMints = this.txBody.mints?.filter((token) => {
|
|
2365
|
+
return token.policyId === policyId2 && token.mintValue.findIndex((m) => BigInt(m.amount) > 0) >= 0;
|
|
2366
|
+
}) || [];
|
|
2367
|
+
return filteredMints.length === 0;
|
|
2368
|
+
};
|
|
2369
|
+
/**
|
|
2370
|
+
* Not apply filter to inputs
|
|
2371
|
+
* @returns The TxTester instance for chaining
|
|
2372
|
+
*/
|
|
2373
|
+
allInputs = () => {
|
|
2374
|
+
this.inputsEvaluating = this.txBody.inputs?.slice() || [];
|
|
2375
|
+
return this;
|
|
2376
|
+
};
|
|
2377
|
+
/**
|
|
2378
|
+
* Filter inputs by address
|
|
2379
|
+
* @param address The address to filter by
|
|
2380
|
+
* @returns The TxTester instance for chaining
|
|
2381
|
+
*/
|
|
2382
|
+
inputsAt = (address) => {
|
|
2383
|
+
this.inputsEvaluating = this.txBody.inputs?.filter(
|
|
2384
|
+
(input) => txInToUtxo(input.txIn).output.address === address
|
|
2385
|
+
) || [];
|
|
2386
|
+
return this;
|
|
2387
|
+
};
|
|
2388
|
+
/**
|
|
2389
|
+
* Filter inputs by unit
|
|
2390
|
+
* @param unit The unit to filter by
|
|
2391
|
+
* @returns The TxTester instance for chaining
|
|
2392
|
+
*/
|
|
2393
|
+
inputsWith = (unit) => {
|
|
2394
|
+
this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
|
|
2395
|
+
const inputValue = MeshValue.fromAssets(
|
|
2396
|
+
txInToUtxo(input.txIn).output.amount
|
|
2397
|
+
);
|
|
2398
|
+
const quantity = inputValue.get(unit);
|
|
2399
|
+
return quantity > 0;
|
|
2400
|
+
}) || [];
|
|
2401
|
+
return this;
|
|
2402
|
+
};
|
|
2403
|
+
/**
|
|
2404
|
+
* Filter inputs by policy ID
|
|
2405
|
+
* @param policyId The policy ID to filter by
|
|
2406
|
+
* @returns The TxTester instance for chaining
|
|
2407
|
+
*/
|
|
2408
|
+
inputsWithPolicy = (policyId2) => {
|
|
2409
|
+
this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
|
|
2410
|
+
const inputValue = MeshValue.fromAssets(
|
|
2411
|
+
txInToUtxo(input.txIn).output.amount
|
|
2412
|
+
);
|
|
2413
|
+
const assets = inputValue.getPolicyAssets(policyId2);
|
|
2414
|
+
return assets.length > 0;
|
|
2415
|
+
}) || [];
|
|
2416
|
+
return this;
|
|
2417
|
+
};
|
|
2418
|
+
/**
|
|
2419
|
+
* Filter inputs by address and policy ID
|
|
2420
|
+
* @param address The address to filter by
|
|
2421
|
+
* @param policyId The policy ID to filter by
|
|
2422
|
+
* @returns The TxTester instance for chaining
|
|
2423
|
+
*/
|
|
2424
|
+
inputsAtWithPolicy = (address, policyId2) => {
|
|
2425
|
+
this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
|
|
2426
|
+
const utxo = txInToUtxo(input.txIn);
|
|
2427
|
+
const inputValue = MeshValue.fromAssets(utxo.output.amount);
|
|
2428
|
+
const assets = inputValue.getPolicyAssets(policyId2);
|
|
2429
|
+
return utxo.output.address === address && assets.length > 0;
|
|
2430
|
+
}) || [];
|
|
2431
|
+
return this;
|
|
2432
|
+
};
|
|
2433
|
+
/**
|
|
2434
|
+
* Filter inputs by address and unit
|
|
2435
|
+
* @param address The address to filter by
|
|
2436
|
+
* @param unit The unit to filter by
|
|
2437
|
+
* @returns The TxTester instance for chaining
|
|
2438
|
+
*/
|
|
2439
|
+
inputsAtWith = (address, unit) => {
|
|
2440
|
+
this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
|
|
2441
|
+
const utxo = txInToUtxo(input.txIn);
|
|
2442
|
+
const inputValue = MeshValue.fromAssets(utxo.output.amount);
|
|
2443
|
+
const quantity = inputValue.get(unit);
|
|
2444
|
+
return utxo.output.address === address && quantity > 0;
|
|
2445
|
+
}) || [];
|
|
2446
|
+
return this;
|
|
2447
|
+
};
|
|
2448
|
+
/**
|
|
2449
|
+
* Check if inputs contain the expected value.
|
|
2450
|
+
* *Reminder - It must be called after filtering methods for inputs*
|
|
2451
|
+
* @param expectedValue The expected value
|
|
2452
|
+
* @returns The TxTester instance for chaining
|
|
2453
|
+
*/
|
|
2454
|
+
inputsValue = (expectedValue) => {
|
|
2455
|
+
let value2 = new MeshValue();
|
|
2456
|
+
this.inputsEvaluating.forEach((input) => {
|
|
2457
|
+
const utxo = txInToUtxo(input.txIn);
|
|
2458
|
+
value2.addAssets(utxo.output.amount);
|
|
2459
|
+
});
|
|
2460
|
+
const isValueCorrect = value2.eq(expectedValue);
|
|
2461
|
+
if (!isValueCorrect) {
|
|
2462
|
+
this.addTrace(
|
|
2463
|
+
"inputsValue",
|
|
2464
|
+
`inputs ${JSON.stringify(this.inputsEvaluating)} have value ${JSON.stringify(value2)}, expect ${JSON.stringify(expectedValue)}`
|
|
2465
|
+
);
|
|
2466
|
+
}
|
|
2467
|
+
return this;
|
|
2468
|
+
};
|
|
2469
|
+
// /**
|
|
2470
|
+
// * Check if inputs contain a specific inline datum.
|
|
2471
|
+
// * *Reminder - It must be called after filtering methods for inputs*
|
|
2472
|
+
// * @param datumCbor The datum CBOR to check
|
|
2473
|
+
// * @returns The TxTester instance for chaining
|
|
2474
|
+
// */
|
|
2475
|
+
// inputsInlineDatumExist = (datumCbor: string): this => {
|
|
2476
|
+
// const inputsWithInlineDatum = this.inputsEvaluating.filter((input) => {
|
|
2477
|
+
// const utxo = txInToUtxo(input.txIn);
|
|
2478
|
+
// return utxo.output.plutusData === datumCbor;
|
|
2479
|
+
// });
|
|
2480
|
+
// if (inputsWithInlineDatum.length === 0) {
|
|
2481
|
+
// this.addTrace(
|
|
2482
|
+
// "inputsInlineDatumExist",
|
|
2483
|
+
// `No inputs with inline datum matching: ${datumCbor}`,
|
|
2484
|
+
// );
|
|
2485
|
+
// }
|
|
2486
|
+
// return this;
|
|
2487
|
+
// };
|
|
2488
|
+
/**
|
|
2489
|
+
* Not apply filter to outputs
|
|
2490
|
+
* @returns The TxTester instance for chaining
|
|
2491
|
+
*/
|
|
2492
|
+
allOutputs = () => {
|
|
2493
|
+
this.outputsEvaluating = this.txBody.outputs?.slice() || [];
|
|
2494
|
+
return this;
|
|
2495
|
+
};
|
|
2496
|
+
/**
|
|
2497
|
+
* Filter outputs by address
|
|
2498
|
+
* @param address The address to filter by
|
|
2499
|
+
* @returns The TxTester instance for chaining
|
|
2500
|
+
*/
|
|
2501
|
+
outputsAt = (address) => {
|
|
2502
|
+
this.outputsEvaluating = this.txBody.outputs?.filter((output) => output.address === address) || [];
|
|
2503
|
+
return this;
|
|
2504
|
+
};
|
|
2505
|
+
/**
|
|
2506
|
+
* Filter outputs by unit
|
|
2507
|
+
* @param unit The unit to filter by
|
|
2508
|
+
* @returns The TxTester instance for chaining
|
|
2509
|
+
*/
|
|
2510
|
+
outputsWith = (unit) => {
|
|
2511
|
+
this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
|
|
2512
|
+
const outputValue = MeshValue.fromAssets(output.amount);
|
|
2513
|
+
const quantity = outputValue.get(unit);
|
|
2514
|
+
return quantity > 0;
|
|
2515
|
+
}) || [];
|
|
2516
|
+
return this;
|
|
2517
|
+
};
|
|
2518
|
+
/**
|
|
2519
|
+
* Filter outputs by policy ID
|
|
2520
|
+
* @param policyId The policy ID to filter by
|
|
2521
|
+
* @returns The TxTester instance for chaining
|
|
2522
|
+
*/
|
|
2523
|
+
outputsWithPolicy = (policyId2) => {
|
|
2524
|
+
this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
|
|
2525
|
+
const outputValue = MeshValue.fromAssets(output.amount);
|
|
2526
|
+
const assets = outputValue.getPolicyAssets(policyId2);
|
|
2527
|
+
return assets.length > 0;
|
|
2528
|
+
}) || [];
|
|
2529
|
+
return this;
|
|
2530
|
+
};
|
|
2531
|
+
/**
|
|
2532
|
+
* Filter outputs by address and policy ID
|
|
2533
|
+
* @param address The address to filter by
|
|
2534
|
+
* @param policyId The policy ID to filter by
|
|
2535
|
+
* @returns The TxTester instance for chaining
|
|
2536
|
+
*/
|
|
2537
|
+
outputsAtWithPolicy = (address, policyId2) => {
|
|
2538
|
+
this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
|
|
2539
|
+
const outputValue = MeshValue.fromAssets(output.amount);
|
|
2540
|
+
const assets = outputValue.getPolicyAssets(policyId2);
|
|
2541
|
+
return output.address === address && assets.length > 0;
|
|
2542
|
+
}) || [];
|
|
2543
|
+
return this;
|
|
2544
|
+
};
|
|
2545
|
+
/**
|
|
2546
|
+
* Filter outputs by address and unit
|
|
2547
|
+
* @param address The address to filter by
|
|
2548
|
+
* @param unit The unit to filter by
|
|
2549
|
+
* @returns The TxTester instance for chaining
|
|
2550
|
+
*/
|
|
2551
|
+
outputsAtWith = (address, unit) => {
|
|
2552
|
+
this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
|
|
2553
|
+
const outputValue = MeshValue.fromAssets(output.amount);
|
|
2554
|
+
const quantity = outputValue.get(unit);
|
|
2555
|
+
return output.address === address && quantity > 0;
|
|
2556
|
+
}) || [];
|
|
2557
|
+
return this;
|
|
2558
|
+
};
|
|
2559
|
+
/**
|
|
2560
|
+
* Check if outputs contain the expected value.
|
|
2561
|
+
* *Reminder - It must be called after filtering methods for outputs*
|
|
2562
|
+
* @param expectedValue The expected value
|
|
2563
|
+
* @returns The TxTester instance for chaining
|
|
2564
|
+
*/
|
|
2565
|
+
outputsValue = (expectedValue) => {
|
|
2566
|
+
let value2 = new MeshValue();
|
|
2567
|
+
this.outputsEvaluating.forEach((output) => {
|
|
2568
|
+
value2.addAssets(output.amount);
|
|
2569
|
+
});
|
|
2570
|
+
const isValueCorrect = value2.eq(expectedValue);
|
|
2571
|
+
if (!isValueCorrect) {
|
|
2572
|
+
this.addTrace(
|
|
2573
|
+
"outputsValue",
|
|
2574
|
+
`tx outputs ${JSON.stringify(this.outputsEvaluating)} have value ${JSON.stringify(value2)}, expected ${JSON.stringify(expectedValue)}`
|
|
2575
|
+
);
|
|
2576
|
+
}
|
|
2577
|
+
return this;
|
|
2578
|
+
};
|
|
2579
|
+
/**
|
|
2580
|
+
* Check if outputs contain a specific inline datum.
|
|
2581
|
+
* *Reminder - It must be called after filtering methods for outputs*
|
|
2582
|
+
* @param datumCbor The datum CBOR to check
|
|
2583
|
+
* @returns The TxTester instance for chaining
|
|
2584
|
+
*/
|
|
2585
|
+
outputsInlineDatumExist = (datumCbor) => {
|
|
2586
|
+
const outputsWithInlineDatum = this.outputsEvaluating.filter((output) => {
|
|
2587
|
+
if (output.datum && output.datum.type === "Inline") {
|
|
2588
|
+
return output.datum.data.content === datumCbor;
|
|
2589
|
+
}
|
|
2590
|
+
return false;
|
|
2591
|
+
});
|
|
2592
|
+
if (outputsWithInlineDatum.length === 0) {
|
|
2593
|
+
this.addTrace(
|
|
2594
|
+
"outputs_inline_datum_exist",
|
|
2595
|
+
`No outputs with inline datum matching: ${datumCbor}`
|
|
2596
|
+
);
|
|
2597
|
+
}
|
|
2598
|
+
return this;
|
|
2599
|
+
};
|
|
2600
|
+
};
|
|
2601
|
+
function keySignedLogic(requiredSignatures, keyHash) {
|
|
2602
|
+
return requiredSignatures?.some((signatory) => signatory === keyHash) || false;
|
|
2603
|
+
}
|
|
2604
|
+
function tokenMintedLogic(mints, policyId2, assetName2, quantity) {
|
|
2605
|
+
return mints?.some((token) => {
|
|
2606
|
+
return token.policyId === policyId2 && token.mintValue.findIndex(
|
|
2607
|
+
(m) => m.assetName === assetName2 && BigInt(m.amount) === BigInt(quantity)
|
|
2608
|
+
) >= 0;
|
|
2609
|
+
}) || false;
|
|
2610
|
+
}
|
|
2611
|
+
|
|
2814
2612
|
// src/index.ts
|
|
2815
2613
|
var import_bip39 = require("bip39");
|
|
2816
2614
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -2819,12 +2617,14 @@ var import_bip39 = require("bip39");
|
|
|
2819
2617
|
BigNum,
|
|
2820
2618
|
CIP68_100,
|
|
2821
2619
|
CIP68_222,
|
|
2620
|
+
DEFAULT_FETCHER_OPTIONS,
|
|
2822
2621
|
DEFAULT_PROTOCOL_PARAMETERS,
|
|
2823
2622
|
DEFAULT_REDEEMER_BUDGET,
|
|
2824
2623
|
DEFAULT_V1_COST_MODEL_LIST,
|
|
2825
2624
|
DEFAULT_V2_COST_MODEL_LIST,
|
|
2826
2625
|
DEFAULT_V3_COST_MODEL_LIST,
|
|
2827
2626
|
DREP_DEPOSIT,
|
|
2627
|
+
GovernanceActionKind,
|
|
2828
2628
|
HARDENED_KEY_START,
|
|
2829
2629
|
LANGUAGE_VERSIONS,
|
|
2830
2630
|
MeshValue,
|
|
@@ -2836,7 +2636,9 @@ var import_bip39 = require("bip39");
|
|
|
2836
2636
|
SUPPORTED_OGMIOS_LINKS,
|
|
2837
2637
|
SUPPORTED_TOKENS,
|
|
2838
2638
|
SUPPORTED_WALLETS,
|
|
2639
|
+
TxTester,
|
|
2839
2640
|
UtxoSelection,
|
|
2641
|
+
VOTING_PROPOSAL_DEPOSIT,
|
|
2840
2642
|
assetClass,
|
|
2841
2643
|
assetName,
|
|
2842
2644
|
assocMap,
|
|
@@ -2845,11 +2647,13 @@ var import_bip39 = require("bip39");
|
|
|
2845
2647
|
byteString,
|
|
2846
2648
|
bytesToHex,
|
|
2847
2649
|
castProtocol,
|
|
2650
|
+
cloneTxBuilderBody,
|
|
2848
2651
|
conStr,
|
|
2849
2652
|
conStr0,
|
|
2850
2653
|
conStr1,
|
|
2851
2654
|
conStr2,
|
|
2852
2655
|
conStr3,
|
|
2656
|
+
credential,
|
|
2853
2657
|
currencySymbol,
|
|
2854
2658
|
dict,
|
|
2855
2659
|
emptyTxBuilderBody,
|
|
@@ -2863,8 +2667,11 @@ var import_bip39 = require("bip39");
|
|
|
2863
2667
|
hexToBytes,
|
|
2864
2668
|
hexToString,
|
|
2865
2669
|
integer,
|
|
2670
|
+
isHexString,
|
|
2866
2671
|
isNetwork,
|
|
2672
|
+
jsonProofToPlutusData,
|
|
2867
2673
|
keepRelevant,
|
|
2674
|
+
keySignedLogic,
|
|
2868
2675
|
largestFirst,
|
|
2869
2676
|
largestFirstMultiAsset,
|
|
2870
2677
|
list,
|
|
@@ -2875,18 +2682,21 @@ var import_bip39 = require("bip39");
|
|
|
2875
2682
|
mConStr1,
|
|
2876
2683
|
mConStr2,
|
|
2877
2684
|
mConStr3,
|
|
2685
|
+
mCredential,
|
|
2878
2686
|
mMaybeStakingHash,
|
|
2879
2687
|
mNone,
|
|
2880
2688
|
mOption,
|
|
2881
2689
|
mOutputReference,
|
|
2882
2690
|
mPlutusBSArrayToString,
|
|
2883
2691
|
mPubKeyAddress,
|
|
2692
|
+
mScript,
|
|
2884
2693
|
mScriptAddress,
|
|
2885
2694
|
mSome,
|
|
2886
2695
|
mStringToPlutusBSArray,
|
|
2887
2696
|
mTuple,
|
|
2888
2697
|
mTxOutRef,
|
|
2889
2698
|
mValue,
|
|
2699
|
+
mVerificationKey,
|
|
2890
2700
|
maybeStakingHash,
|
|
2891
2701
|
mergeAssets,
|
|
2892
2702
|
metadataStandardKeys,
|
|
@@ -2895,6 +2705,7 @@ var import_bip39 = require("bip39");
|
|
|
2895
2705
|
none,
|
|
2896
2706
|
option,
|
|
2897
2707
|
outputReference,
|
|
2708
|
+
pairs,
|
|
2898
2709
|
parseAssetUnit,
|
|
2899
2710
|
plutusBSArrayToString,
|
|
2900
2711
|
policyId,
|
|
@@ -2907,6 +2718,7 @@ var import_bip39 = require("bip39");
|
|
|
2907
2718
|
resolveSlotNo,
|
|
2908
2719
|
resolveTxFees,
|
|
2909
2720
|
royaltiesStandardKeys,
|
|
2721
|
+
script,
|
|
2910
2722
|
scriptAddress,
|
|
2911
2723
|
scriptHash,
|
|
2912
2724
|
slotToBeginUnixTime,
|
|
@@ -2915,10 +2727,14 @@ var import_bip39 = require("bip39");
|
|
|
2915
2727
|
stringToHex,
|
|
2916
2728
|
toBytes,
|
|
2917
2729
|
toUTF8,
|
|
2730
|
+
tokenMintedLogic,
|
|
2918
2731
|
tokenName,
|
|
2919
2732
|
tuple,
|
|
2733
|
+
txInToUtxo,
|
|
2920
2734
|
txOutRef,
|
|
2921
2735
|
unixTimeToEnclosingSlot,
|
|
2736
|
+
validityRangeFromObj,
|
|
2922
2737
|
validityRangeToObj,
|
|
2923
|
-
value
|
|
2738
|
+
value,
|
|
2739
|
+
verificationKey
|
|
2924
2740
|
});
|