@meshsdk/core-cst 1.9.0-beta.4 → 1.9.0-beta.5

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 CHANGED
@@ -30,868 +30,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
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 blake2b7(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 blake2bHex(input, key, outlen, salt, personal) {
568
- const output = blake2b7(input, key, outlen, salt, personal);
569
- return util.toHex(output);
570
- }
571
- module2.exports = {
572
- blake2b: blake2b7,
573
- blake2bHex,
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
33
  // ../../node_modules/bignumber.js/bignumber.js
896
34
  var require_bignumber = __commonJS({
897
35
  "../../node_modules/bignumber.js/bignumber.js"(exports2, module2) {
@@ -4640,7 +3778,7 @@ var import_crypto = require("@cardano-sdk/crypto");
4640
3778
  // src/message-signing/cose-sign1.ts
4641
3779
  var import_buffer = require("buffer");
4642
3780
  var import_cbor = require("@harmoniclabs/cbor");
4643
- var import_blakejs = __toESM(require_blakejs(), 1);
3781
+ var import_blakejs = require("blakejs");
4644
3782
  var import_json_bigint = __toESM(require_json_bigint(), 1);
4645
3783
  var CoseSign1 = class _CoseSign1 {
4646
3784
  protectedMap;
@@ -6873,7 +6011,7 @@ var CardanoSDKSerializer = class {
6873
6011
  }
6874
6012
  }
6875
6013
  };
6876
- serializeTxBody = (txBuilderBody, protocolParams) => {
6014
+ serializeTxBody = (txBuilderBody, protocolParams, balanced = true) => {
6877
6015
  if (this.verbose) {
6878
6016
  console.log(
6879
6017
  "txBodyJson",
@@ -6887,7 +6025,7 @@ var CardanoSDKSerializer = class {
6887
6025
  const serializerCore = new CardanoSDKSerializerCore(
6888
6026
  protocolParams ?? this.protocolParams
6889
6027
  );
6890
- return serializerCore.coreSerializeTxBody(txBuilderBody);
6028
+ return serializerCore.coreSerializeTxBody(txBuilderBody, balanced);
6891
6029
  };
6892
6030
  addSigningKeys = (txHex, signingKeys) => {
6893
6031
  let cardanoTx = Transaction.fromCbor(import_core7.Serialization.TxCBOR(txHex));
@@ -6947,7 +6085,7 @@ var CardanoSDKSerializerCore = class {
6947
6085
  this.txWitnessSet = new TransactionWitnessSet();
6948
6086
  this.txAuxilliaryData = new AuxilliaryData();
6949
6087
  }
6950
- coreSerializeTxBody = (txBuilderBody) => {
6088
+ coreSerializeTxBody = (txBuilderBody, balanced) => {
6951
6089
  const {
6952
6090
  inputs,
6953
6091
  outputs,
@@ -6962,7 +6100,8 @@ var CardanoSDKSerializerCore = class {
6962
6100
  withdrawals
6963
6101
  } = txBuilderBody;
6964
6102
  this.addAllInputs(inputs);
6965
- this.addAllOutputs(this.sanitizeOutputs(outputs));
6103
+ this.sanitizeOutputs(outputs);
6104
+ this.addAllOutputs(outputs);
6966
6105
  this.addAllMints(mints);
6967
6106
  this.addAllCerts(certificates);
6968
6107
  this.addAllWithdrawals(withdrawals);
@@ -6975,7 +6114,9 @@ var CardanoSDKSerializerCore = class {
6975
6114
  this.addMetadata(metadata);
6976
6115
  }
6977
6116
  this.buildWitnessSet();
6978
- this.balanceTx(changeAddress);
6117
+ if (balanced) {
6118
+ this.balanceTx(changeAddress);
6119
+ }
6979
6120
  return new Transaction(
6980
6121
  this.txBody,
6981
6122
  this.txWitnessSet,
@@ -7000,21 +6141,20 @@ var CardanoSDKSerializerCore = class {
7000
6141
  outputAmount.quantity = minUtxoValue.toString();
7001
6142
  }
7002
6143
  }
7003
- if (!lovelaceFound) {
7004
- let currentAmount = {
7005
- unit: "lovelace",
7006
- quantity: "10000000"
7007
- };
7008
- currentOutput.amount.push(currentAmount);
7009
- let dummyCardanoOutput = this.toCardanoOutput(
7010
- currentOutput
7011
- );
7012
- let minUtxoValue = (160 + dummyCardanoOutput.toCbor().length / 2 + 1) * this.protocolParams.coinsPerUtxoSize;
7013
- currentAmount.quantity = minUtxoValue.toString();
7014
- }
6144
+ }
6145
+ if (!lovelaceFound) {
6146
+ let currentAmount = {
6147
+ unit: "lovelace",
6148
+ quantity: "10000000"
6149
+ };
6150
+ currentOutput.amount.push(currentAmount);
6151
+ let dummyCardanoOutput = this.toCardanoOutput(
6152
+ currentOutput
6153
+ );
6154
+ let minUtxoValue = (160 + dummyCardanoOutput.toCbor().length / 2 + 1) * this.protocolParams.coinsPerUtxoSize;
6155
+ currentAmount.quantity = minUtxoValue.toString();
7015
6156
  }
7016
6157
  }
7017
- return outputs;
7018
6158
  };
7019
6159
  addAllInputs = (inputs) => {
7020
6160
  for (let i = 0; i < inputs.length; i += 1) {
@@ -7715,14 +6855,15 @@ var CardanoSDKSerializerCore = class {
7715
6855
  if (remainingValue.coin() < 0 || !empty(negatives(remainingValue))) {
7716
6856
  throw new Error(`Not enough funds to satisfy outputs`);
7717
6857
  }
7718
- currentOutputs.push(
7719
- new TransactionOutput(toCardanoAddress(changeAddress), remainingValue)
6858
+ const dummyChangeOutput = new TransactionOutput(
6859
+ toCardanoAddress(changeAddress),
6860
+ remainingValue
7720
6861
  );
7721
- this.txBody.setOutputs(currentOutputs);
6862
+ let minUtxoValue = (160 + dummyChangeOutput.toCbor().length / 2 + 1) * this.protocolParams.coinsPerUtxoSize;
7722
6863
  this.txBody.setFee(BigInt("10000000"));
7723
6864
  const numberOfRequiredWitnesses = this.countNumberOfRequiredWitnesses();
7724
6865
  const dummyTx = this.createDummyTx(numberOfRequiredWitnesses);
7725
- const fee = calculateFees(
6866
+ let fee = calculateFees(
7726
6867
  this.protocolParams.minFeeA,
7727
6868
  this.protocolParams.minFeeB,
7728
6869
  this.protocolParams.minFeeRefScriptCostPerByte,
@@ -7731,22 +6872,21 @@ var CardanoSDKSerializerCore = class {
7731
6872
  dummyTx,
7732
6873
  this.refScriptSize
7733
6874
  );
7734
- this.txBody.setFee(fee);
7735
- const changeOutput = currentOutputs.pop();
7736
- if (!changeOutput) {
7737
- throw new Error(
7738
- "Somehow the output length was 0 after attempting to calculate fees"
7739
- );
7740
- }
7741
- if (changeOutput.amount().coin() - fee > 0) {
7742
- changeOutput.amount().setCoin(changeOutput.amount().coin() - fee);
7743
- currentOutputs.push(changeOutput);
7744
- } else if (changeOutput.amount().coin() - fee < 0) {
7745
- throw new Error(
7746
- `There was enough inputs to cover outputs, but not enough to cover fees - fee: ${fee}`
7747
- );
6875
+ if (remainingValue.coin() >= fee + BigInt(minUtxoValue)) {
6876
+ dummyChangeOutput.amount().setCoin(dummyChangeOutput.amount().coin() - fee);
6877
+ currentOutputs.push(dummyChangeOutput);
6878
+ this.txBody.setOutputs(currentOutputs);
6879
+ remainingValue = new Value(BigInt(0));
6880
+ } else if (remainingValue.coin() >= fee) {
6881
+ if (remainingValue.multiasset() && remainingValue.multiasset().size > 0) {
6882
+ throw new Error(
6883
+ "Insufficient funds to create change output with tokens"
6884
+ );
6885
+ } else {
6886
+ fee = remainingValue.coin();
6887
+ }
7748
6888
  }
7749
- this.txBody.setOutputs(currentOutputs);
6889
+ this.txBody.setFee(fee);
7750
6890
  };
7751
6891
  createDummyTx = (numberOfRequiredWitnesses) => {
7752
6892
  let dummyWitnessSet = TransactionWitnessSet.fromCbor(