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

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) {
@@ -4360,7 +3498,8 @@ __export(index_exports, {
4360
3498
  Bip32PrivateKeyHex: () => Bip32PrivateKeyHex2,
4361
3499
  Bip32PublicKey: () => Bip32PublicKey2,
4362
3500
  Bip32PublicKeyHex: () => Bip32PublicKeyHex2,
4363
- Cardano: () => import_core8.Cardano,
3501
+ BootstrapWitness: () => BootstrapWitness,
3502
+ Cardano: () => import_core9.Cardano,
4364
3503
  CardanoSDK: () => CardanoSDK,
4365
3504
  CardanoSDKSerializer: () => CardanoSDKSerializer,
4366
3505
  CardanoSDKUtil: () => CardanoSDKUtil,
@@ -4427,7 +3566,7 @@ __export(index_exports, {
4427
3566
  Script: () => Script,
4428
3567
  ScriptHash: () => ScriptHash,
4429
3568
  ScriptPubkey: () => ScriptPubkey,
4430
- Serialization: () => import_core8.Serialization,
3569
+ Serialization: () => import_core9.Serialization,
4431
3570
  Slot: () => Slot,
4432
3571
  StakeCredentialStatus: () => StakeCredentialStatus,
4433
3572
  StakeDelegation: () => StakeDelegation,
@@ -4462,6 +3601,7 @@ __export(index_exports, {
4462
3601
  buildRewardAddress: () => buildRewardAddress,
4463
3602
  buildScriptPubkey: () => buildScriptPubkey,
4464
3603
  bytesToHex: () => bytesToHex,
3604
+ calculateFees: () => calculateFees,
4465
3605
  checkSignature: () => checkSignature,
4466
3606
  clampScalar: () => clampScalar,
4467
3607
  computeAuxiliaryDataHash: () => computeAuxiliaryDataHash,
@@ -4536,7 +3676,7 @@ __export(index_exports, {
4536
3676
  v2ScriptToBech32: () => v2ScriptToBech32
4537
3677
  });
4538
3678
  module.exports = __toCommonJS(index_exports);
4539
- var import_core8 = require("@cardano-sdk/core");
3679
+ var import_core9 = require("@cardano-sdk/core");
4540
3680
 
4541
3681
  // src/types/cardano-sdk.ts
4542
3682
  var import_core = require("@cardano-sdk/core");
@@ -4545,7 +3685,9 @@ var import_util = require("@cardano-sdk/util");
4545
3685
  var Slot = import_core.Cardano.Slot;
4546
3686
  var Value = import_core.Serialization.Value;
4547
3687
  var Transaction = import_core.Serialization.Transaction;
4548
- var TransactionId = import_core.Cardano.TransactionId;
3688
+ var TransactionId = (value) => {
3689
+ return import_core.Cardano.TransactionId(value);
3690
+ };
4549
3691
  var TransactionBody = import_core.Serialization.TransactionBody;
4550
3692
  var TransactionWitnessSet = import_core.Serialization.TransactionWitnessSet;
4551
3693
  var AuxilliaryData = import_core.Serialization.AuxiliaryData;
@@ -4581,7 +3723,9 @@ var Ed25519PrivateExtendedKeyHex = (value) => (0, import_util.typedHex)(value, 1
4581
3723
  var Ed25519KeyHash2 = Crypto.Ed25519KeyHash;
4582
3724
  var Ed25519KeyHashHex2 = Crypto.Ed25519KeyHashHex;
4583
3725
  var Hash28ByteBase162 = Crypto.Hash28ByteBase16;
4584
- var Hash32ByteBase162 = Crypto.Hash32ByteBase16;
3726
+ var Hash32ByteBase162 = (value) => {
3727
+ return Crypto.Hash32ByteBase16(value);
3728
+ };
4585
3729
  var CredentialType = import_core.Cardano.CredentialType;
4586
3730
  var Certificate = import_core.Serialization.Certificate;
4587
3731
  var PoolId = import_core.Cardano.PoolId;
@@ -4611,7 +3755,9 @@ var CborWriter = import_core.Serialization.CborWriter;
4611
3755
  var ConstrPlutusData = import_core.Serialization.ConstrPlutusData;
4612
3756
  var RewardAccount = import_core.Cardano.RewardAccount;
4613
3757
  var Hash = import_core.Serialization.Hash;
4614
- var DatumHash = Crypto.Hash32ByteBase16;
3758
+ var DatumHash = (value) => {
3759
+ return Crypto.Hash32ByteBase16(value);
3760
+ };
4615
3761
  var Datum = import_core.Serialization.Datum;
4616
3762
  var ExUnits = import_core.Serialization.ExUnits;
4617
3763
  var NetworkId = import_core.Cardano.NetworkId;
@@ -4633,6 +3779,7 @@ var TxCBOR = import_core.Serialization.TxCBOR;
4633
3779
  var Ed25519PrivateKey2 = Crypto.Ed25519PrivateKey;
4634
3780
  var computeAuxiliaryDataHash = import_core.Cardano.computeAuxiliaryDataHash;
4635
3781
  var blake2b2 = Crypto.blake2b;
3782
+ var BootstrapWitness = import_core.Serialization.BootstrapWitness;
4636
3783
 
4637
3784
  // src/message-signing/check-signature.ts
4638
3785
  var import_crypto = require("@cardano-sdk/crypto");
@@ -4640,7 +3787,7 @@ var import_crypto = require("@cardano-sdk/crypto");
4640
3787
  // src/message-signing/cose-sign1.ts
4641
3788
  var import_buffer = require("buffer");
4642
3789
  var import_cbor = require("@harmoniclabs/cbor");
4643
- var import_blakejs = __toESM(require_blakejs(), 1);
3790
+ var import_blakejs = require("blakejs");
4644
3791
  var import_json_bigint = __toESM(require_json_bigint(), 1);
4645
3792
  var CoseSign1 = class _CoseSign1 {
4646
3793
  protectedMap;
@@ -4953,10 +4100,10 @@ var import_bech323 = require("bech32");
4953
4100
  var import_common7 = require("@meshsdk/common");
4954
4101
 
4955
4102
  // src/utils/builder.ts
4956
- var import_crypto3 = require("@cardano-sdk/crypto");
4103
+ var import_crypto3 = require("crypto");
4104
+ var import_crypto4 = require("@cardano-sdk/crypto");
4957
4105
  var import_util2 = require("@cardano-sdk/util");
4958
4106
  var import_hash = __toESM(require_hash(), 1);
4959
- var import_crypto4 = require("crypto");
4960
4107
  var import_common2 = require("@meshsdk/common");
4961
4108
  var buildBaseAddress = (networkId, paymentKeyHash, stakeKeyHash) => {
4962
4109
  return BaseAddress.fromCredentials(
@@ -4992,7 +4139,7 @@ var buildBip32PrivateKey = (entropy, password = "") => {
4992
4139
  const PBKDF2_KEY_SIZE = 96;
4993
4140
  const PBKDF2_DIGEST_ALGORITHM = "sha512";
4994
4141
  const _entropy = Buffer.from(entropy, "hex");
4995
- const xprv = (0, import_crypto4.pbkdf2Sync)(
4142
+ const xprv = (0, import_crypto3.pbkdf2Sync)(
4996
4143
  password,
4997
4144
  _entropy,
4998
4145
  PBKDF2_ITERATIONS,
@@ -5026,8 +4173,12 @@ var buildKeys = (privateKeyHex, accountIndex, keyIndex = 0) => {
5026
4173
  const dRepKey = accountKey.derive([3, keyIndex]).toRawKey();
5027
4174
  return { paymentKey, stakeKey, dRepKey };
5028
4175
  } else {
5029
- const paymentKey = buildEd25519PrivateKeyFromSecretKey(privateKeyHex[0]);
5030
- const stakeKey = buildEd25519PrivateKeyFromSecretKey(privateKeyHex[1]);
4176
+ const paymentKey = Ed25519PrivateKey2.fromNormalHex(
4177
+ Ed25519PrivateNormalKeyHex(privateKeyHex[0])
4178
+ );
4179
+ const stakeKey = Ed25519PrivateKey2.fromNormalHex(
4180
+ Ed25519PrivateNormalKeyHex(privateKeyHex[1])
4181
+ );
5031
4182
  return { paymentKey, stakeKey };
5032
4183
  }
5033
4184
  };
@@ -5048,7 +4199,7 @@ var buildScriptPubkey = (keyHash) => {
5048
4199
  };
5049
4200
  var buildDRepID = (dRepKey, networkId = NetworkId.Testnet, addressType = AddressType.EnterpriseKey) => {
5050
4201
  const dRepKeyBytes = Buffer.from(dRepKey, "hex");
5051
- const dRepIdHex = (0, import_crypto3.blake2b)(28).update(dRepKeyBytes).digest("hex");
4202
+ const dRepIdHex = (0, import_crypto4.blake2b)(28).update(dRepKeyBytes).digest("hex");
5052
4203
  const paymentAddress = EnterpriseAddress.packParts({
5053
4204
  networkId,
5054
4205
  paymentPart: {
@@ -5197,7 +4348,7 @@ var fromBuilderToPlutusData = (data) => {
5197
4348
  var fromPlutusDataToJson = (data) => {
5198
4349
  if (data.getKind() === PlutusDataKind.ConstrPlutusData) {
5199
4350
  const plutusData = data.asConstrPlutusData();
5200
- if (plutusData) {
4351
+ if (plutusData !== void 0) {
5201
4352
  const fields = plutusData.getData();
5202
4353
  const list = [];
5203
4354
  for (let i = 0; i < fields.getLength(); i++) {
@@ -5214,7 +4365,7 @@ var fromPlutusDataToJson = (data) => {
5214
4365
  } else if (data.getKind() === PlutusDataKind.Map) {
5215
4366
  const plutusMap = data.asMap();
5216
4367
  const mapList = [];
5217
- if (plutusMap) {
4368
+ if (plutusMap !== void 0) {
5218
4369
  const keys = plutusMap.getKeys();
5219
4370
  for (let i = 0; i < keys.getLength(); i++) {
5220
4371
  const key = keys.get(i);
@@ -5234,7 +4385,7 @@ var fromPlutusDataToJson = (data) => {
5234
4385
  }
5235
4386
  } else if (data.getKind() === PlutusDataKind.List) {
5236
4387
  const plutusList = data.asList();
5237
- if (plutusList) {
4388
+ if (plutusList !== void 0) {
5238
4389
  const list = [];
5239
4390
  for (let i = 0; i < plutusList.getLength(); i++) {
5240
4391
  const element = plutusList.get(i);
@@ -5246,16 +4397,16 @@ var fromPlutusDataToJson = (data) => {
5246
4397
  }
5247
4398
  } else if (data.getKind() === PlutusDataKind.Integer) {
5248
4399
  const plutusInt = data.asInteger();
5249
- if (plutusInt) {
4400
+ if (plutusInt !== void 0) {
5250
4401
  return {
5251
- int: BigInt(plutusInt.toString())
4402
+ int: plutusInt
5252
4403
  };
5253
4404
  } else {
5254
4405
  throw new Error("Invalid integer data found");
5255
4406
  }
5256
4407
  } else if (data.getKind() === PlutusDataKind.Bytes) {
5257
4408
  const plutusBytes = data.asBoundedBytes();
5258
- if (plutusBytes) {
4409
+ if (plutusBytes !== void 0) {
5259
4410
  return {
5260
4411
  bytes: Buffer.from(plutusBytes).toString("hex")
5261
4412
  };
@@ -5277,7 +4428,7 @@ var parseInlineDatum = (utxo) => {
5277
4428
  const datumCbor = utxo.inline_datum || "";
5278
4429
  return datumCborToJson(datumCbor);
5279
4430
  };
5280
- var deserializeDataHash = (dataHash) => DatumHash.fromHexBlob((0, import_util3.HexBlob)(dataHash));
4431
+ var deserializeDataHash = (dataHash) => DatumHash(dataHash);
5281
4432
  var deserializePlutusData = (plutusData) => PlutusData.fromCbor((0, import_util3.HexBlob)(plutusData));
5282
4433
 
5283
4434
  // src/utils/deserializer.ts
@@ -5304,7 +4455,7 @@ var deserializeScriptRef = (scriptRef) => Script.fromCbor((0, import_util4.HexBl
5304
4455
  var deserializeTxUnspentOutput = (txUnspentOutput) => TransactionUnspentOutput.fromCbor((0, import_util4.HexBlob)(txUnspentOutput));
5305
4456
  var deserializeValue = (value) => Value.fromCbor((0, import_util4.HexBlob)(value));
5306
4457
  var deserializeTx = (tx) => Transaction.fromCbor(import_core2.Serialization.TxCBOR(tx));
5307
- var deserializeTxHash = (txHash) => TransactionId.fromHexBlob((0, import_util4.HexBlob)(txHash));
4458
+ var deserializeTxHash = (txHash) => TransactionId(txHash);
5308
4459
 
5309
4460
  // src/utils/converter.ts
5310
4461
  var toAddress = (bech325) => Address.fromBech32(bech325);
@@ -5538,10 +4689,10 @@ var toNativeScript = (script) => {
5538
4689
  };
5539
4690
  var toValue = (assets) => {
5540
4691
  const multiAsset = /* @__PURE__ */ new Map();
5541
- assets.filter((asset) => asset.unit !== "lovelace").forEach((asset) => {
4692
+ assets.filter((asset) => asset.unit !== "lovelace" && asset.unit !== "").forEach((asset) => {
5542
4693
  multiAsset.set(AssetId(asset.unit), BigInt(asset.quantity));
5543
4694
  });
5544
- const lovelace = assets.find((asset) => asset.unit === "lovelace");
4695
+ const lovelace = assets.find((asset) => asset.unit === "lovelace" || asset.unit === "");
5545
4696
  const value = new Value(BigInt(lovelace ? lovelace.quantity : 0));
5546
4697
  if (assets.length > 1 || !lovelace) {
5547
4698
  value.setMultiasset(multiAsset);
@@ -5832,7 +4983,7 @@ var plutusDataToAddrBech32 = (plutusData, networkId = 0) => {
5832
4983
  }
5833
4984
  const cardanoPaymentCredential = {
5834
4985
  hash: Hash28ByteBase162(Buffer.from(paymentBytes).toString("hex")),
5835
- type: paymentConstrData.getAlternative() === BigInt(0) ? 0 : 1
4986
+ type: Number(paymentConstrData.getAlternative())
5836
4987
  };
5837
4988
  const delegationData = plutusDataList.get(1);
5838
4989
  const delegationConstrData = delegationData.asConstrPlutusData();
@@ -5867,15 +5018,27 @@ var plutusDataToAddrBech32 = (plutusData, networkId = 0) => {
5867
5018
  "Error: serializeAddressObj: Delegation inner part must contain 1 element"
5868
5019
  );
5869
5020
  }
5870
- const delegationBytes = delegationDataInnerList.get(0).asBoundedBytes();
5021
+ const delegationCredential = delegationDataInnerList.get(0).asConstrPlutusData();
5022
+ if (!delegationCredential) {
5023
+ throw new Error(
5024
+ "Error: serializeAddressObj: Delegation inner part must be a constructor"
5025
+ );
5026
+ }
5027
+ const delegationBytesList = delegationCredential.getData();
5028
+ if (delegationBytesList.getLength() !== 1) {
5029
+ throw new Error(
5030
+ "Error: serializeAddressObj: Delegation bytes part must contain 1 element"
5031
+ );
5032
+ }
5033
+ const delegationBytes = delegationBytesList.get(0).asBoundedBytes();
5871
5034
  if (!delegationBytes) {
5872
5035
  throw new Error(
5873
- "Error: serializeAddressObj: Delegation inner part must be bytes"
5036
+ "Error: serializeAddressObj: Delegation bytes part must be of type bytes"
5874
5037
  );
5875
5038
  }
5876
5039
  const cardanoStakeCredential = {
5877
5040
  hash: Hash28ByteBase162(Buffer.from(delegationBytes).toString("hex")),
5878
- type: delegationDataInnerConstrData.getAlternative() === BigInt(0) ? 0 : 1
5041
+ type: Number(delegationCredential.getAlternative())
5879
5042
  };
5880
5043
  return BaseAddress.fromCredentials(
5881
5044
  networkId,
@@ -6022,9 +5185,60 @@ var addVKeyWitnessSetToTransaction = (txHex, vkeyWitnessSet) => {
6022
5185
  return tx.toCbor();
6023
5186
  };
6024
5187
 
5188
+ // src/utils/fee.ts
5189
+ var calculateFees = (minFeeA, minFeeB, minFeeRefScriptCostPerByte, priceMem, priceStep, tx, refScriptSize) => {
5190
+ let fee = minFeeB + tx.toCbor().length / 2 * minFeeA;
5191
+ fee += calculateRefScriptFees(refScriptSize, minFeeRefScriptCostPerByte);
5192
+ let scriptFee = BigInt(0);
5193
+ let priceMemNumerator = priceMem;
5194
+ let priceMemDenominator = 1;
5195
+ while (priceMemNumerator % 1) {
5196
+ priceMemNumerator *= 10;
5197
+ priceMemDenominator *= 10;
5198
+ }
5199
+ let priceStepNumerator = priceStep;
5200
+ let priceStepDenominator = 1;
5201
+ while (priceStepNumerator % 1) {
5202
+ priceStepNumerator *= 10;
5203
+ priceStepDenominator *= 10;
5204
+ }
5205
+ if (tx.witnessSet().redeemers()) {
5206
+ for (const redeemer of tx.witnessSet().redeemers().values()) {
5207
+ scriptFee += redeemer.exUnits().mem() * BigInt(priceMemNumerator.toString()) / BigInt(priceMemDenominator.toString());
5208
+ scriptFee += redeemer.exUnits().steps() * BigInt(priceStepNumerator.toString()) / BigInt(priceStepDenominator.toString());
5209
+ if (priceMemNumerator % priceMemDenominator !== 0) {
5210
+ scriptFee += BigInt(1);
5211
+ }
5212
+ if (priceStepNumerator % priceStepDenominator !== 0) {
5213
+ scriptFee += BigInt(1);
5214
+ }
5215
+ }
5216
+ }
5217
+ return BigInt(fee) + scriptFee;
5218
+ };
5219
+ var calculateRefScriptFees = (refScriptSize, minFeeRefScriptCostPerByte, tierMultiplier = 1.2) => {
5220
+ let fee = 0;
5221
+ const tierSize = 25600;
5222
+ let currentRefScriptSize = refScriptSize;
5223
+ let multiplier = 1;
5224
+ while (currentRefScriptSize >= tierSize) {
5225
+ fee += tierSize * multiplier * minFeeRefScriptCostPerByte;
5226
+ currentRefScriptSize -= tierSize;
5227
+ multiplier *= tierMultiplier;
5228
+ }
5229
+ if (currentRefScriptSize > 0) {
5230
+ fee += currentRefScriptSize * multiplier * minFeeRefScriptCostPerByte;
5231
+ }
5232
+ fee = Math.ceil(fee);
5233
+ return fee;
5234
+ };
5235
+
6025
5236
  // src/resolvers/index.ts
6026
- var resolveDataHash = (data) => {
6027
- const plutusData = toPlutusData(data);
5237
+ var resolveDataHash = (rawData, type = "Mesh") => {
5238
+ const plutusData = fromBuilderToPlutusData({
5239
+ content: rawData,
5240
+ type
5241
+ });
6028
5242
  return plutusData.hash().toString();
6029
5243
  };
6030
5244
  var resolveNativeScriptAddress = (script, networkId = 0) => {
@@ -6142,7 +5356,8 @@ var resolveEd25519KeyHash = (bech325) => {
6142
5356
  };
6143
5357
 
6144
5358
  // src/serializer/index.ts
6145
- var import_core7 = require("@cardano-sdk/core");
5359
+ var import_buffer2 = require("buffer");
5360
+ var import_core8 = require("@cardano-sdk/core");
6146
5361
  var import_util9 = require("@cardano-sdk/util");
6147
5362
  var import_cbor3 = require("@harmoniclabs/cbor");
6148
5363
  var import_base32_encoding4 = __toESM(require("base32-encoding"), 1);
@@ -6253,7 +5468,7 @@ var toCardanoCert = (cert) => {
6253
5468
  return Certificate.newStakeDelegation(
6254
5469
  new import_core5.Serialization.StakeDelegation(
6255
5470
  rewardAddress.getPaymentCredential(),
6256
- Ed25519KeyHashHex2(cert.poolId)
5471
+ cert.poolId.startsWith("pool1") ? import_core5.Cardano.PoolId.toKeyHash(import_core5.Cardano.PoolId(cert.poolId)) : Ed25519KeyHashHex2(cert.poolId)
6257
5472
  )
6258
5473
  );
6259
5474
  }
@@ -6275,7 +5490,7 @@ var toCardanoCert = (cert) => {
6275
5490
  case "RetirePool": {
6276
5491
  return Certificate.newPoolRetirement(
6277
5492
  new import_core5.Serialization.PoolRetirement(
6278
- Ed25519KeyHashHex2(cert.poolId),
5493
+ cert.poolId.startsWith("pool1") ? import_core5.Cardano.PoolId.toKeyHash(import_core5.Cardano.PoolId(cert.poolId)) : Ed25519KeyHashHex2(cert.poolId),
6279
5494
  import_core5.Cardano.EpochNo(cert.epoch)
6280
5495
  )
6281
5496
  );
@@ -6528,48 +5743,6 @@ var toCardanoCert = (cert) => {
6528
5743
  }
6529
5744
  };
6530
5745
 
6531
- // src/utils/fee.ts
6532
- var calculateFees = (minFeeA, minFeeB, minFeeRefScriptCostPerByte, priceMem, priceStep, tx, refScriptSize) => {
6533
- let fee = minFeeB + tx.toCbor().length / 2 * minFeeA;
6534
- const tierSize = 25600;
6535
- let currentRefScriptSize = refScriptSize;
6536
- let multiplier = 1.2;
6537
- while (currentRefScriptSize >= tierSize) {
6538
- fee += tierSize * multiplier * minFeeRefScriptCostPerByte;
6539
- currentRefScriptSize -= tierSize;
6540
- multiplier *= multiplier;
6541
- }
6542
- if (currentRefScriptSize > 0) {
6543
- fee += currentRefScriptSize * multiplier * minFeeRefScriptCostPerByte;
6544
- }
6545
- let scriptFee = BigInt(0);
6546
- let priceMemNumerator = priceMem;
6547
- let priceMemDenominator = 1;
6548
- while (priceMemNumerator % 1) {
6549
- priceMemNumerator *= 10;
6550
- priceMemDenominator *= 10;
6551
- }
6552
- let priceStepNumerator = priceStep;
6553
- let priceStepDenominator = 1;
6554
- while (priceStepNumerator % 1) {
6555
- priceStepNumerator *= 10;
6556
- priceStepDenominator *= 10;
6557
- }
6558
- if (tx.witnessSet().redeemers()) {
6559
- for (const redeemer of tx.witnessSet().redeemers().values()) {
6560
- scriptFee += redeemer.exUnits().mem() * BigInt(priceMemNumerator.toString()) / BigInt(priceMemDenominator.toString());
6561
- scriptFee += redeemer.exUnits().steps() * BigInt(priceStepNumerator.toString()) / BigInt(priceStepDenominator.toString());
6562
- if (priceMemNumerator % priceMemDenominator !== 0) {
6563
- scriptFee += BigInt(1);
6564
- }
6565
- if (priceStepNumerator % priceStepDenominator !== 0) {
6566
- scriptFee += BigInt(1);
6567
- }
6568
- }
6569
- }
6570
- return BigInt(fee) + scriptFee;
6571
- };
6572
-
6573
5746
  // src/utils/metadata.ts
6574
5747
  var toCardanoMetadataMap = (metadata) => {
6575
5748
  let cardanoMetadataMap = /* @__PURE__ */ new Map();
@@ -6609,27 +5782,19 @@ var import_core6 = require("@cardano-sdk/core");
6609
5782
  var Crypto3 = __toESM(require("@cardano-sdk/crypto"), 1);
6610
5783
  var import_crypto8 = require("@cardano-sdk/crypto");
6611
5784
  var import_util8 = require("@cardano-sdk/util");
6612
- var CBOR_EMPTY_LIST = new Uint8Array([128]);
6613
5785
  var CBOR_EMPTY_MAP = new Uint8Array([160]);
6614
- var getCborEncodedArray = (items) => {
6615
- const writer = new import_core6.Serialization.CborWriter();
6616
- writer.writeStartArray(items.length);
6617
- for (const item of items) {
6618
- writer.writeEncodedValue(Buffer.from(item.toCbor(), "hex"));
6619
- }
6620
- return writer.encode();
6621
- };
6622
5786
  var hashScriptData = (costModels, redemeers, datums) => {
6623
5787
  const writer = new import_core6.Serialization.CborWriter();
6624
- if (datums && datums.length > 0 && (!redemeers || redemeers.length === 0)) {
6625
- writer.writeEncodedValue(CBOR_EMPTY_LIST);
6626
- writer.writeEncodedValue(getCborEncodedArray(datums));
5788
+ if (datums && datums.size() > 0 && (!redemeers || redemeers.size() === 0)) {
5789
+ writer.writeEncodedValue(CBOR_EMPTY_MAP);
5790
+ writer.writeEncodedValue(Buffer.from(datums.toCbor(), "hex"));
6627
5791
  writer.writeEncodedValue(CBOR_EMPTY_MAP);
6628
5792
  } else {
6629
- if (!redemeers || redemeers.length === 0) return void 0;
6630
- writer.writeEncodedValue(getCborEncodedArray(redemeers));
6631
- if (datums && datums.length > 0)
6632
- writer.writeEncodedValue(getCborEncodedArray(datums));
5793
+ if (!redemeers || redemeers.size() === 0) return void 0;
5794
+ writer.writeEncodedValue(Buffer.from(redemeers.toCbor(), "hex"));
5795
+ if (datums && datums.size() > 0) {
5796
+ writer.writeEncodedValue(Buffer.from(datums.toCbor(), "hex"));
5797
+ }
6633
5798
  writer.writeEncodedValue(
6634
5799
  Buffer.from(costModels.languageViewsEncoding(), "hex")
6635
5800
  );
@@ -6641,13 +5806,90 @@ var hashScriptData = (costModels, redemeers, datums) => {
6641
5806
  );
6642
5807
  };
6643
5808
 
5809
+ // src/utils/vote.ts
5810
+ var import_core7 = require("@cardano-sdk/core");
5811
+ var toCardanoVoter = (voter) => {
5812
+ switch (voter.type) {
5813
+ case "ConstitutionalCommittee": {
5814
+ switch (voter.hotCred.type) {
5815
+ case "KeyHash": {
5816
+ return import_core7.Serialization.Voter.newConstitutionalCommitteeHotKey({
5817
+ type: 0,
5818
+ hash: Hash28ByteBase162(voter.hotCred.keyHash)
5819
+ });
5820
+ }
5821
+ case "ScriptHash": {
5822
+ return import_core7.Serialization.Voter.newConstitutionalCommitteeHotKey({
5823
+ type: 1,
5824
+ hash: Hash28ByteBase162(voter.hotCred.scriptHash)
5825
+ });
5826
+ }
5827
+ }
5828
+ }
5829
+ case "DRep": {
5830
+ const cardanoDrep = toDRep(voter.drepId);
5831
+ if (cardanoDrep.toKeyHash() !== void 0) {
5832
+ return import_core7.Serialization.Voter.newDrep({
5833
+ type: 0,
5834
+ hash: Hash28ByteBase162(cardanoDrep.toKeyHash())
5835
+ });
5836
+ } else if (cardanoDrep.toScriptHash() !== void 0) {
5837
+ return import_core7.Serialization.Voter.newDrep({
5838
+ type: 1,
5839
+ hash: Hash28ByteBase162(cardanoDrep.toScriptHash())
5840
+ });
5841
+ } else {
5842
+ throw new Error("Invalid DRep provided");
5843
+ }
5844
+ }
5845
+ case "StakingPool": {
5846
+ return import_core7.Serialization.Voter.newStakingPool(
5847
+ Ed25519KeyHashHex2(voter.keyHash)
5848
+ );
5849
+ }
5850
+ }
5851
+ };
5852
+ var toCardanoVotingProcedure = (votingProcedure) => {
5853
+ return new import_core7.Serialization.VotingProcedure(
5854
+ toCardanoVoteKind(votingProcedure.voteKind),
5855
+ votingProcedure.anchor ? toCardanoAnchor(votingProcedure.anchor) : void 0
5856
+ );
5857
+ };
5858
+ var toCardanoAnchor = (anchor) => {
5859
+ return new import_core7.Serialization.Anchor(
5860
+ anchor.anchorUrl,
5861
+ Hash32ByteBase162(anchor.anchorDataHash)
5862
+ );
5863
+ };
5864
+ var toCardanoVoteKind = (voteType) => {
5865
+ switch (voteType) {
5866
+ case "Yes": {
5867
+ return 1;
5868
+ }
5869
+ case "No": {
5870
+ return 0;
5871
+ }
5872
+ case "Abstain": {
5873
+ return 2;
5874
+ }
5875
+ }
5876
+ };
5877
+ var toCardanoGovernanceActionId = (govActionId) => {
5878
+ return new import_core7.Serialization.GovernanceActionId(
5879
+ import_core7.Cardano.TransactionId(govActionId.txHash),
5880
+ BigInt(govActionId.txIndex)
5881
+ );
5882
+ };
5883
+
6644
5884
  // src/serializer/index.ts
5885
+ var VKEY_PUBKEY_SIZE_BYTES = 32;
5886
+ var VKEY_SIGNATURE_SIZE_BYTES = 64;
5887
+ var CHAIN_CODE_SIZE_BYTES = 32;
6645
5888
  var CardanoSDKSerializer = class {
6646
- verbose;
6647
5889
  protocolParams;
6648
- constructor(protocolParams, verbose = false) {
5890
+ constructor(protocolParams) {
5891
+ (0, import_core8.setInConwayEra)(true);
6649
5892
  this.protocolParams = protocolParams || import_common8.DEFAULT_PROTOCOL_PARAMETERS;
6650
- this.verbose = verbose;
6651
5893
  }
6652
5894
  serializeRewardAddress(stakeKeyHash, isScriptHash, network_id) {
6653
5895
  return RewardAddress.fromCredentials(network_id ?? 0, {
@@ -6777,7 +6019,7 @@ var CardanoSDKSerializer = class {
6777
6019
  resolvePrivateKey: function(words) {
6778
6020
  const buildBip32PrivateKey2 = (entropy2, password = "") => {
6779
6021
  return Bip32PrivateKey2.fromBip39Entropy(
6780
- Buffer.from((0, import_common8.toBytes)(entropy2)),
6022
+ import_buffer2.Buffer.from((0, import_common8.toBytes)(entropy2)),
6781
6023
  (0, import_common8.fromUTF8)(password)
6782
6024
  );
6783
6025
  };
@@ -6809,12 +6051,12 @@ var CardanoSDKSerializer = class {
6809
6051
  },
6810
6052
  tx: {
6811
6053
  resolveTxHash: function(txHex) {
6812
- return Transaction.fromCbor(import_core7.Serialization.TxCBOR(txHex)).getId();
6054
+ return Transaction.fromCbor(import_core8.Serialization.TxCBOR(txHex)).getId();
6813
6055
  }
6814
6056
  },
6815
6057
  data: {
6816
- resolveDataHash: function(data) {
6817
- return fromBuilderToPlutusData({ type: "Mesh", content: data }).hash();
6058
+ resolveDataHash: function(rawData, type = "Mesh") {
6059
+ return resolveDataHash(rawData, type);
6818
6060
  }
6819
6061
  },
6820
6062
  script: {
@@ -6874,23 +6116,17 @@ var CardanoSDKSerializer = class {
6874
6116
  }
6875
6117
  };
6876
6118
  serializeTxBody = (txBuilderBody, protocolParams) => {
6877
- if (this.verbose) {
6878
- console.log(
6879
- "txBodyJson",
6880
- JSON.stringify(txBuilderBody, (key, val) => {
6881
- if (key === "extraInputs") return void 0;
6882
- if (key === "selectionConfig") return void 0;
6883
- return val;
6884
- })
6885
- );
6886
- }
6887
6119
  const serializerCore = new CardanoSDKSerializerCore(
6888
6120
  protocolParams ?? this.protocolParams
6889
6121
  );
6890
- return serializerCore.coreSerializeTxBody(txBuilderBody);
6122
+ return serializerCore.coreSerializeTx(txBuilderBody);
6891
6123
  };
6124
+ serializeTxBodyWithMockSignatures(txBuilderBody, protocolParams) {
6125
+ const serializerCore = new CardanoSDKSerializerCore(protocolParams);
6126
+ return serializerCore.coreSerializeTxWithMockSignatures(txBuilderBody);
6127
+ }
6892
6128
  addSigningKeys = (txHex, signingKeys) => {
6893
- let cardanoTx = Transaction.fromCbor(import_core7.Serialization.TxCBOR(txHex));
6129
+ let cardanoTx = Transaction.fromCbor(import_core8.Serialization.TxCBOR(txHex));
6894
6130
  let currentWitnessSet = cardanoTx.witnessSet();
6895
6131
  let currentWitnessSetVkeys = currentWitnessSet.vkeys();
6896
6132
  let currentWitnessSetVkeysValues = currentWitnessSetVkeys ? [...currentWitnessSetVkeys.values()] : [];
@@ -6911,7 +6147,7 @@ var CardanoSDKSerializer = class {
6911
6147
  }
6912
6148
  }
6913
6149
  currentWitnessSet.setVkeys(
6914
- import_core7.Serialization.CborSet.fromCore(
6150
+ import_core8.Serialization.CborSet.fromCore(
6915
6151
  currentWitnessSetVkeysValues.map((vkw) => vkw.toCore()),
6916
6152
  VkeyWitness.fromCore
6917
6153
  )
@@ -6919,6 +6155,63 @@ var CardanoSDKSerializer = class {
6919
6155
  cardanoTx.setWitnessSet(currentWitnessSet);
6920
6156
  return cardanoTx.toCbor();
6921
6157
  };
6158
+ serializeValue(value) {
6159
+ return toValue(value).toCbor();
6160
+ }
6161
+ serializeOutput(output) {
6162
+ let cardanoOutput = new TransactionOutput(
6163
+ toCardanoAddress(output.address),
6164
+ toValue(output.amount)
6165
+ );
6166
+ if (output.datum?.type === "Hash") {
6167
+ cardanoOutput.setDatum(
6168
+ Datum.newDataHash(fromBuilderToPlutusData(output.datum.data).hash())
6169
+ );
6170
+ } else if (output.datum?.type === "Inline") {
6171
+ cardanoOutput.setDatum(
6172
+ Datum.newInlineData(fromBuilderToPlutusData(output.datum.data))
6173
+ );
6174
+ } else if (output.datum?.type === "Embedded") {
6175
+ throw new Error("Embedded datum not supported");
6176
+ }
6177
+ if (output.referenceScript) {
6178
+ switch (output.referenceScript.version) {
6179
+ case "V1": {
6180
+ cardanoOutput.setScriptRef(
6181
+ Script.newPlutusV1Script(
6182
+ PlutusV1Script.fromCbor((0, import_util9.HexBlob)(output.referenceScript.code))
6183
+ )
6184
+ );
6185
+ break;
6186
+ }
6187
+ case "V2": {
6188
+ cardanoOutput.setScriptRef(
6189
+ Script.newPlutusV2Script(
6190
+ PlutusV2Script.fromCbor((0, import_util9.HexBlob)(output.referenceScript.code))
6191
+ )
6192
+ );
6193
+ break;
6194
+ }
6195
+ case "V3": {
6196
+ cardanoOutput.setScriptRef(
6197
+ Script.newPlutusV3Script(
6198
+ PlutusV3Script.fromCbor((0, import_util9.HexBlob)(output.referenceScript.code))
6199
+ )
6200
+ );
6201
+ break;
6202
+ }
6203
+ default: {
6204
+ cardanoOutput.setScriptRef(
6205
+ Script.newNativeScript(
6206
+ NativeScript.fromCbor((0, import_util9.HexBlob)(output.referenceScript.code))
6207
+ )
6208
+ );
6209
+ break;
6210
+ }
6211
+ }
6212
+ }
6213
+ return cardanoOutput.toCbor();
6214
+ }
6922
6215
  };
6923
6216
  var CardanoSDKSerializerCore = class {
6924
6217
  txBody;
@@ -6938,7 +6231,7 @@ var CardanoSDKSerializerCore = class {
6938
6231
  constructor(protocolParams) {
6939
6232
  this.protocolParams = protocolParams || import_common8.DEFAULT_PROTOCOL_PARAMETERS;
6940
6233
  this.txBody = new TransactionBody(
6941
- import_core7.Serialization.CborSet.fromCore([], TransactionInput.fromCore),
6234
+ import_core8.Serialization.CborSet.fromCore([], TransactionInput.fromCore),
6942
6235
  [],
6943
6236
  BigInt(0),
6944
6237
  void 0
@@ -6955,33 +6248,69 @@ var CardanoSDKSerializerCore = class {
6955
6248
  requiredSignatures,
6956
6249
  referenceInputs,
6957
6250
  mints,
6958
- changeAddress,
6959
6251
  metadata,
6960
6252
  validityRange,
6961
6253
  certificates,
6962
- withdrawals
6254
+ withdrawals,
6255
+ votes,
6256
+ totalCollateral,
6257
+ collateralReturnAddress,
6258
+ changeAddress
6963
6259
  } = txBuilderBody;
6260
+ const uniqueRefInputs = this.removeBodyInputRefInputOverlap(
6261
+ inputs,
6262
+ referenceInputs
6263
+ );
6964
6264
  this.addAllInputs(inputs);
6965
- this.addAllOutputs(this.sanitizeOutputs(outputs));
6265
+ this.setFee(txBuilderBody.fee ?? "0");
6266
+ this.sanitizeOutputs(outputs);
6267
+ this.addAllOutputs(outputs);
6966
6268
  this.addAllMints(mints);
6967
6269
  this.addAllCerts(certificates);
6968
6270
  this.addAllWithdrawals(withdrawals);
6271
+ this.addAllVotes(votes);
6969
6272
  this.addAllCollateralInputs(collaterals);
6970
- this.addAllReferenceInputs(referenceInputs);
6273
+ if (totalCollateral) {
6274
+ this.txBody.setTotalCollateral(BigInt(totalCollateral));
6275
+ this.addCollateralReturn(
6276
+ totalCollateral,
6277
+ collaterals,
6278
+ collateralReturnAddress ?? changeAddress
6279
+ );
6280
+ }
6281
+ this.addAllReferenceInputs(uniqueRefInputs);
6971
6282
  this.removeInputRefInputOverlap();
6972
6283
  this.setValidityInterval(validityRange);
6973
6284
  this.addAllRequiredSignatures(requiredSignatures);
6974
6285
  if (metadata.size > 0) {
6975
6286
  this.addMetadata(metadata);
6976
6287
  }
6288
+ return this.txBody;
6289
+ };
6290
+ coreSerializeTx(txBuilderBody) {
6291
+ const bodyCore = this.coreSerializeTxBody(txBuilderBody);
6292
+ if (txBuilderBody.fee !== void 0) {
6293
+ this.txBody.setFee(BigInt(txBuilderBody.fee));
6294
+ }
6977
6295
  this.buildWitnessSet();
6978
- this.balanceTx(changeAddress);
6979
6296
  return new Transaction(
6980
- this.txBody,
6297
+ bodyCore,
6981
6298
  this.txWitnessSet,
6982
6299
  this.txAuxilliaryData
6983
6300
  ).toCbor();
6984
- };
6301
+ }
6302
+ coreSerializeTxWithMockSignatures(txBuilderBody) {
6303
+ const bodyCore = this.coreSerializeTxBody(txBuilderBody);
6304
+ const mockWitSet = this.createMockedWitnessSet(
6305
+ txBuilderBody.expectedNumberKeyWitnesses,
6306
+ txBuilderBody.expectedByronAddressWitnesses
6307
+ );
6308
+ return new Transaction(
6309
+ bodyCore,
6310
+ mockWitSet,
6311
+ this.txAuxilliaryData
6312
+ ).toCbor();
6313
+ }
6985
6314
  sanitizeOutputs = (outputs) => {
6986
6315
  for (let i = 0; i < outputs.length; i++) {
6987
6316
  let currentOutput = outputs[i];
@@ -7000,21 +6329,32 @@ var CardanoSDKSerializerCore = class {
7000
6329
  outputAmount.quantity = minUtxoValue.toString();
7001
6330
  }
7002
6331
  }
6332
+ }
6333
+ if (!lovelaceFound) {
6334
+ let currentAmount = {
6335
+ unit: "lovelace",
6336
+ quantity: "10000000"
6337
+ };
6338
+ currentOutput.amount.push(currentAmount);
6339
+ let dummyCardanoOutput = this.toCardanoOutput(
6340
+ currentOutput
6341
+ );
6342
+ let minUtxoValue = (160 + dummyCardanoOutput.toCbor().length / 2 + 1) * this.protocolParams.coinsPerUtxoSize;
6343
+ currentAmount.quantity = minUtxoValue.toString();
7003
6344
  if (!lovelaceFound) {
7004
- let currentAmount = {
6345
+ let currentAmount2 = {
7005
6346
  unit: "lovelace",
7006
6347
  quantity: "10000000"
7007
6348
  };
7008
- currentOutput.amount.push(currentAmount);
7009
- let dummyCardanoOutput = this.toCardanoOutput(
6349
+ currentOutput.amount.push(currentAmount2);
6350
+ let dummyCardanoOutput2 = this.toCardanoOutput(
7010
6351
  currentOutput
7011
6352
  );
7012
- let minUtxoValue = (160 + dummyCardanoOutput.toCbor().length / 2 + 1) * this.protocolParams.coinsPerUtxoSize;
7013
- currentAmount.quantity = minUtxoValue.toString();
6353
+ let minUtxoValue2 = (160 + dummyCardanoOutput2.toCbor().length / 2 + 1) * this.protocolParams.coinsPerUtxoSize;
6354
+ currentAmount2.quantity = minUtxoValue2.toString();
7014
6355
  }
7015
6356
  }
7016
6357
  }
7017
- return outputs;
7018
6358
  };
7019
6359
  addAllInputs = (inputs) => {
7020
6360
  for (let i = 0; i < inputs.length; i += 1) {
@@ -7057,6 +6397,9 @@ var CardanoSDKSerializerCore = class {
7057
6397
  );
7058
6398
  this.utxoContext.set(cardanoTxIn, cardanoTxOut);
7059
6399
  this.txBody.setInputs(inputs);
6400
+ if (currentTxIn.txIn.scriptSize) {
6401
+ this.refScriptSize += currentTxIn.txIn.scriptSize;
6402
+ }
7060
6403
  };
7061
6404
  addScriptTxIn = (currentTxIn, index) => {
7062
6405
  this.addTxIn({
@@ -7082,16 +6425,10 @@ var CardanoSDKSerializerCore = class {
7082
6425
  fromBuilderToPlutusData(currentTxIn.scriptTxIn.datumSource.data)
7083
6426
  );
7084
6427
  } else if (currentTxIn.scriptTxIn.datumSource.type === "Inline") {
7085
- let referenceInputs = this.txBody.referenceInputs() ?? import_core7.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
7086
- let referenceInputsList = [...referenceInputs.values()];
7087
- referenceInputsList.push(
7088
- new TransactionInput(
7089
- TransactionId(currentTxIn.txIn.txHash),
7090
- BigInt(currentTxIn.txIn.txIndex)
7091
- )
7092
- );
7093
- referenceInputs.setValues(referenceInputsList);
7094
- this.txBody.setReferenceInputs(referenceInputs);
6428
+ this.addReferenceInput({
6429
+ txHash: currentTxIn.txIn.txHash,
6430
+ txIndex: currentTxIn.txIn.txIndex
6431
+ });
7095
6432
  }
7096
6433
  let exUnits = currentTxIn.scriptTxIn.redeemer.exUnits;
7097
6434
  let redeemers = this.txWitnessSet.redeemers() ?? Redeemers.fromCore([]);
@@ -7145,9 +6482,7 @@ var CardanoSDKSerializerCore = class {
7145
6482
  if (output.datum?.type === "Hash") {
7146
6483
  cardanoOutput.setDatum(
7147
6484
  Datum.newDataHash(
7148
- DatumHash.fromHexBlob(
7149
- (0, import_util9.HexBlob)(fromBuilderToPlutusData(output.datum.data).hash())
7150
- )
6485
+ DatumHash(fromBuilderToPlutusData(output.datum.data).hash())
7151
6486
  )
7152
6487
  );
7153
6488
  } else if (output.datum?.type === "Inline") {
@@ -7155,7 +6490,7 @@ var CardanoSDKSerializerCore = class {
7155
6490
  Datum.newInlineData(fromBuilderToPlutusData(output.datum.data))
7156
6491
  );
7157
6492
  } else if (output.datum?.type === "Embedded") {
7158
- const currentWitnessDatum = this.txWitnessSet.plutusData() ?? import_core7.Serialization.CborSet.fromCore([], import_core7.Serialization.PlutusData.fromCore);
6493
+ const currentWitnessDatum = this.txWitnessSet.plutusData() ?? import_core8.Serialization.CborSet.fromCore([], import_core8.Serialization.PlutusData.fromCore);
7159
6494
  const currentWitnessDatumValues = [...currentWitnessDatum.values()];
7160
6495
  currentWitnessDatumValues.push(
7161
6496
  fromBuilderToPlutusData(output.datum.data)
@@ -7199,15 +6534,22 @@ var CardanoSDKSerializerCore = class {
7199
6534
  }
7200
6535
  };
7201
6536
  addReferenceInput = (refInput) => {
7202
- let referenceInputs = this.txBody.referenceInputs() ?? import_core7.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
6537
+ let referenceInputs = this.txBody.referenceInputs() ?? import_core8.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
7203
6538
  let referenceInputsList = [...referenceInputs.values()];
6539
+ if (referenceInputsList.some(
6540
+ (input) => input.transactionId().toString() === refInput.txHash && input.index().toString() === refInput.txIndex.toString()
6541
+ ))
6542
+ return;
7204
6543
  referenceInputsList.push(
7205
6544
  new TransactionInput(
7206
- TransactionId.fromHexBlob((0, import_util9.HexBlob)(refInput.txHash)),
6545
+ TransactionId(refInput.txHash),
7207
6546
  BigInt(refInput.txIndex)
7208
6547
  )
7209
6548
  );
7210
6549
  referenceInputs.setValues(referenceInputsList);
6550
+ if (refInput.scriptSize) {
6551
+ this.refScriptSize += refInput.scriptSize;
6552
+ }
7211
6553
  this.txBody.setReferenceInputs(referenceInputs);
7212
6554
  };
7213
6555
  addAllMints = (mints) => {
@@ -7232,16 +6574,21 @@ var CardanoSDKSerializerCore = class {
7232
6574
  };
7233
6575
  addMint = (mint) => {
7234
6576
  const currentMint = this.txBody.mint() ?? /* @__PURE__ */ new Map();
7235
- const mintAssetId = mint.policyId + mint.assetName;
7236
- for (const asset of currentMint.keys()) {
7237
- if (asset.toString() == mintAssetId) {
7238
- throw new Error("The same asset is already in the mint field");
6577
+ for (const assetValue of mint.mintValue) {
6578
+ const mintAssetId = `${mint.policyId}${assetValue.assetName}`;
6579
+ for (const asset of currentMint.keys()) {
6580
+ if (asset.toString() == mintAssetId) {
6581
+ throw new Error("The same asset is already in the mint field");
6582
+ }
7239
6583
  }
6584
+ currentMint.set(
6585
+ AssetId.fromParts(
6586
+ PolicyId(mint.policyId),
6587
+ AssetName(assetValue.assetName)
6588
+ ),
6589
+ BigInt(assetValue.amount)
6590
+ );
7240
6591
  }
7241
- currentMint.set(
7242
- AssetId.fromParts(PolicyId(mint.policyId), AssetName(mint.assetName)),
7243
- BigInt(mint.amount)
7244
- );
7245
6592
  this.txBody.setMint(currentMint);
7246
6593
  if (mint.type === "Native") {
7247
6594
  if (!mint.scriptSource)
@@ -7303,7 +6650,7 @@ var CardanoSDKSerializerCore = class {
7303
6650
  }
7304
6651
  };
7305
6652
  addCert = (cert, index) => {
7306
- const currentCerts = this.txBody.certs() ?? import_core7.Serialization.CborSet.fromCore([], import_core7.Serialization.Certificate.fromCore);
6653
+ const currentCerts = this.txBody.certs() ?? import_core8.Serialization.CborSet.fromCore([], import_core8.Serialization.Certificate.fromCore);
7307
6654
  let currentCertsValues = [...currentCerts.values()];
7308
6655
  currentCertsValues.push(toCardanoCert(cert.certType));
7309
6656
  currentCerts.setValues(currentCertsValues);
@@ -7446,7 +6793,7 @@ var CardanoSDKSerializerCore = class {
7446
6793
  TransactionId(collateral.txIn.txHash),
7447
6794
  BigInt(collateral.txIn.txIndex)
7448
6795
  );
7449
- const collateralInputs = this.txBody.collateral() ?? import_core7.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
6796
+ const collateralInputs = this.txBody.collateral() ?? import_core8.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
7450
6797
  const collateralInputsList = [
7451
6798
  ...collateralInputs.values()
7452
6799
  ];
@@ -7464,6 +6811,22 @@ var CardanoSDKSerializerCore = class {
7464
6811
  this.utxoContext.set(cardanoTxIn, cardanoTxOut);
7465
6812
  this.txBody.setCollateral(collateralInputs);
7466
6813
  };
6814
+ addCollateralReturn = (totalCollateral, collaterals, collateralReturnAddress) => {
6815
+ let collateralReturnValue = Value.fromCore({
6816
+ coins: -BigInt(totalCollateral)
6817
+ });
6818
+ for (const collateral of collaterals) {
6819
+ collateralReturnValue = mergeValue(
6820
+ collateralReturnValue,
6821
+ toValue(collateral.txIn.amount)
6822
+ );
6823
+ }
6824
+ const collateralReturn = new TransactionOutput(
6825
+ toCardanoAddress(collateralReturnAddress),
6826
+ collateralReturnValue
6827
+ );
6828
+ this.txBody.setCollateralReturn(collateralReturn);
6829
+ };
7467
6830
  setValidityInterval = (validity) => {
7468
6831
  if (validity.invalidBefore) {
7469
6832
  this.txBody.setValidityStartInterval(Slot(validity.invalidBefore));
@@ -7472,12 +6835,15 @@ var CardanoSDKSerializerCore = class {
7472
6835
  this.txBody.setTtl(Slot(validity.invalidHereafter));
7473
6836
  }
7474
6837
  };
6838
+ setFee = (fee) => {
6839
+ this.txBody.setFee(BigInt(fee));
6840
+ };
7475
6841
  addAllRequiredSignatures = (requiredSignatures) => {
7476
- const requiredSigners = this.txBody.requiredSigners() ?? import_core7.Serialization.CborSet.fromCore([], import_core7.Serialization.Hash.fromCore);
6842
+ const requiredSigners = this.txBody.requiredSigners() ?? import_core8.Serialization.CborSet.fromCore([], import_core8.Serialization.Hash.fromCore);
7477
6843
  let requiredSignerValues = [...requiredSigners.values()];
7478
6844
  for (const requiredSigner of requiredSignatures) {
7479
6845
  requiredSignerValues.push(
7480
- import_core7.Serialization.Hash.fromCore(Ed25519KeyHashHex2(requiredSigner))
6846
+ import_core8.Serialization.Hash.fromCore(Ed25519KeyHashHex2(requiredSigner))
7481
6847
  );
7482
6848
  }
7483
6849
  requiredSigners.setValues(requiredSignerValues);
@@ -7485,16 +6851,33 @@ var CardanoSDKSerializerCore = class {
7485
6851
  };
7486
6852
  addMetadata = (metadata) => {
7487
6853
  this.txAuxilliaryData.setMetadata(
7488
- new import_core7.Serialization.GeneralTransactionMetadata(
6854
+ new import_core8.Serialization.GeneralTransactionMetadata(
7489
6855
  toCardanoMetadataMap(metadata)
7490
6856
  )
7491
6857
  );
7492
6858
  };
6859
+ createMockedWitnessSet = (requiredSignaturesCount, requiredByronSignatures) => {
6860
+ this.buildWitnessSet();
6861
+ const clonedWitnessSet = TransactionWitnessSet.fromCbor(
6862
+ this.txWitnessSet.toCbor()
6863
+ );
6864
+ const bootstrapWitnesses = this.mockBootstrapWitnesses(
6865
+ requiredByronSignatures
6866
+ );
6867
+ const vkeyWitnesses = this.mockVkeyWitnesses(requiredSignaturesCount);
6868
+ const bootstrapsSet = CborSet.fromCore([], BootstrapWitness.fromCore);
6869
+ bootstrapsSet.setValues(bootstrapWitnesses);
6870
+ clonedWitnessSet.setBootstraps(bootstrapsSet);
6871
+ const vkeysSet = CborSet.fromCore([], VkeyWitness.fromCore);
6872
+ vkeysSet.setValues(vkeyWitnesses);
6873
+ clonedWitnessSet.setVkeys(vkeysSet);
6874
+ return clonedWitnessSet;
6875
+ };
7493
6876
  buildWitnessSet = () => {
7494
- let nativeScripts = this.txWitnessSet.nativeScripts() ?? import_core7.Serialization.CborSet.fromCore([], NativeScript.fromCore);
7495
- let v1Scripts = this.txWitnessSet.plutusV1Scripts() ?? import_core7.Serialization.CborSet.fromCore([], PlutusV1Script.fromCore);
7496
- let v2Scripts = this.txWitnessSet.plutusV2Scripts() ?? import_core7.Serialization.CborSet.fromCore([], PlutusV2Script.fromCore);
7497
- let v3Scripts = this.txWitnessSet.plutusV3Scripts() ?? import_core7.Serialization.CborSet.fromCore([], PlutusV3Script.fromCore);
6877
+ let nativeScripts = this.txWitnessSet.nativeScripts() ?? import_core8.Serialization.CborSet.fromCore([], NativeScript.fromCore);
6878
+ let v1Scripts = this.txWitnessSet.plutusV1Scripts() ?? import_core8.Serialization.CborSet.fromCore([], PlutusV1Script.fromCore);
6879
+ let v2Scripts = this.txWitnessSet.plutusV2Scripts() ?? import_core8.Serialization.CborSet.fromCore([], PlutusV2Script.fromCore);
6880
+ let v3Scripts = this.txWitnessSet.plutusV3Scripts() ?? import_core8.Serialization.CborSet.fromCore([], PlutusV3Script.fromCore);
7498
6881
  this.scriptsProvided.forEach((scriptHex) => {
7499
6882
  const script = Script.fromCbor((0, import_util9.HexBlob)(scriptHex));
7500
6883
  if (script.asNative() !== void 0) {
@@ -7519,23 +6902,23 @@ var CardanoSDKSerializerCore = class {
7519
6902
  this.txWitnessSet.setPlutusV2Scripts(v2Scripts);
7520
6903
  this.txWitnessSet.setPlutusV3Scripts(v3Scripts);
7521
6904
  });
7522
- let datums = this.txWitnessSet.plutusData() ?? import_core7.Serialization.CborSet.fromCore([], PlutusData.fromCore);
6905
+ let datums = this.txWitnessSet.plutusData() ?? import_core8.Serialization.CborSet.fromCore([], PlutusData.fromCore);
7523
6906
  let datumsList = [...datums.values()];
7524
6907
  this.datumsProvided.forEach((datum) => {
7525
6908
  datumsList.push(datum);
7526
6909
  });
7527
6910
  datums.setValues(datumsList);
7528
6911
  this.txWitnessSet.setPlutusData(datums);
7529
- let costModelV1 = import_core7.Serialization.CostModel.newPlutusV1(
6912
+ let costModelV1 = import_core8.Serialization.CostModel.newPlutusV1(
7530
6913
  import_common8.DEFAULT_V1_COST_MODEL_LIST
7531
6914
  );
7532
- let costModelV2 = import_core7.Serialization.CostModel.newPlutusV2(
6915
+ let costModelV2 = import_core8.Serialization.CostModel.newPlutusV2(
7533
6916
  import_common8.DEFAULT_V2_COST_MODEL_LIST
7534
6917
  );
7535
- let costModelV3 = import_core7.Serialization.CostModel.newPlutusV3(
6918
+ let costModelV3 = import_core8.Serialization.CostModel.newPlutusV3(
7536
6919
  import_common8.DEFAULT_V3_COST_MODEL_LIST
7537
6920
  );
7538
- let costModels = new import_core7.Serialization.Costmdls();
6921
+ let costModels = new import_core8.Serialization.Costmdls();
7539
6922
  if (this.usedLanguages[PlutusLanguageVersion.V1]) {
7540
6923
  costModels.insert(costModelV1);
7541
6924
  }
@@ -7548,8 +6931,8 @@ var CardanoSDKSerializerCore = class {
7548
6931
  const redeemers = this.txWitnessSet.redeemers() ?? Redeemers.fromCore([]);
7549
6932
  let scriptDataHash = hashScriptData(
7550
6933
  costModels,
7551
- redeemers.size() > 0 ? [...redeemers.values()] : void 0,
7552
- datums.size() > 0 ? [...datums.values()] : void 0
6934
+ redeemers,
6935
+ datums.size() > 0 ? datums : void 0
7553
6936
  );
7554
6937
  if (scriptDataHash) {
7555
6938
  this.txBody.setScriptDataHash(scriptDataHash);
@@ -7578,206 +6961,39 @@ var CardanoSDKSerializerCore = class {
7578
6961
  }
7579
6962
  });
7580
6963
  this.txBody.setReferenceInputs(
7581
- import_core7.Serialization.CborSet.fromCore(
6964
+ import_core8.Serialization.CborSet.fromCore(
7582
6965
  refInputsValues.map((input) => input.toCore()),
7583
6966
  TransactionInput.fromCore
7584
6967
  )
7585
6968
  );
7586
6969
  }
7587
6970
  };
7588
- balanceTx = (changeAddress) => {
7589
- if (changeAddress === "") {
7590
- throw new Error("Can't balance tx without a change address");
7591
- }
7592
- const inputs = this.txBody.inputs().values();
7593
- let remainingValue = new Value(BigInt(0));
7594
- for (let i = 0; i < inputs.length; i++) {
7595
- let input = inputs[i];
7596
- if (!input) {
7597
- throw new Error("Invalid input found");
7598
- }
7599
- const output = this.utxoContext.get(input);
7600
- if (!output) {
7601
- throw new Error(`Unable to resolve input: ${input.toCbor()}`);
7602
- }
7603
- remainingValue = mergeValue(remainingValue, output.amount());
7604
- }
7605
- const withdrawals = this.txBody.withdrawals();
7606
- if (withdrawals) {
7607
- withdrawals.forEach((coin) => {
7608
- remainingValue = mergeValue(remainingValue, new Value(coin));
7609
- });
7610
- }
7611
- remainingValue = mergeValue(
7612
- remainingValue,
7613
- new Value(BigInt(0), this.txBody.mint())
7614
- );
7615
- const currentOutputs = this.txBody.outputs();
7616
- for (let i = 0; i < currentOutputs.length; i++) {
7617
- let output = currentOutputs.at(i);
7618
- if (output) {
7619
- remainingValue = subValue(remainingValue, output.amount());
6971
+ removeBodyInputRefInputOverlap = (inputs, refInputs) => {
6972
+ let finalRefInputs = [];
6973
+ for (let i = 0; i < refInputs.length; i++) {
6974
+ let refInput = refInputs[i];
6975
+ if (!inputs.some(
6976
+ (input) => input.txIn.txHash === refInput.txHash && input.txIn.txIndex === refInput.txIndex
6977
+ )) {
6978
+ finalRefInputs.push(refInput);
7620
6979
  }
7621
6980
  }
7622
- const certs = this.txBody.certs();
7623
- if (certs) {
7624
- certs.values().forEach((cert) => {
7625
- switch (cert.toCore().__typename) {
7626
- case CertificateType.StakeRegistration: {
7627
- remainingValue = subValue(
7628
- remainingValue,
7629
- new Value(BigInt(this.protocolParams.keyDeposit))
7630
- );
7631
- break;
7632
- }
7633
- case CertificateType.StakeDeregistration: {
7634
- remainingValue = mergeValue(
7635
- remainingValue,
7636
- new Value(BigInt(this.protocolParams.keyDeposit))
7637
- );
7638
- break;
7639
- }
7640
- case CertificateType.Registration: {
7641
- remainingValue = subValue(
7642
- remainingValue,
7643
- new Value(BigInt(cert.asRegistrationCert()?.deposit() ?? 0))
7644
- );
7645
- break;
7646
- }
7647
- case CertificateType.Unregistration: {
7648
- remainingValue = mergeValue(
7649
- remainingValue,
7650
- new Value(BigInt(cert.asUnregistrationCert()?.deposit() ?? 0))
7651
- );
7652
- break;
7653
- }
7654
- case CertificateType.PoolRegistration: {
7655
- remainingValue = subValue(
7656
- remainingValue,
7657
- new Value(BigInt(this.protocolParams.poolDeposit))
7658
- );
7659
- break;
7660
- }
7661
- case CertificateType.PoolRetirement: {
7662
- remainingValue = mergeValue(
7663
- remainingValue,
7664
- new Value(BigInt(this.protocolParams.poolDeposit))
7665
- );
7666
- break;
7667
- }
7668
- case CertificateType.RegisterDelegateRepresentative: {
7669
- remainingValue = subValue(
7670
- remainingValue,
7671
- new Value(
7672
- BigInt(
7673
- cert.asRegisterDelegateRepresentativeCert()?.deposit() ?? 0
7674
- )
7675
- )
7676
- );
7677
- break;
7678
- }
7679
- case CertificateType.UnregisterDelegateRepresentative: {
7680
- remainingValue = mergeValue(
7681
- remainingValue,
7682
- new Value(
7683
- BigInt(
7684
- cert.asUnregisterDelegateRepresentativeCert()?.deposit() ?? 0
7685
- )
7686
- )
7687
- );
7688
- break;
7689
- }
7690
- case CertificateType.StakeRegistrationDelegation: {
7691
- remainingValue = subValue(
7692
- remainingValue,
7693
- new Value(
7694
- BigInt(
7695
- cert.asStakeRegistrationDelegationCert()?.deposit() ?? 0
7696
- )
7697
- )
7698
- );
7699
- break;
7700
- }
7701
- case CertificateType.StakeVoteRegistrationDelegation: {
7702
- remainingValue = subValue(
7703
- remainingValue,
7704
- new Value(
7705
- BigInt(
7706
- cert.asStakeVoteRegistrationDelegationCert()?.deposit() ?? 0
7707
- )
7708
- )
7709
- );
7710
- break;
7711
- }
7712
- }
7713
- });
7714
- }
7715
- if (remainingValue.coin() < 0 || !empty(negatives(remainingValue))) {
7716
- throw new Error(`Not enough funds to satisfy outputs`);
7717
- }
7718
- currentOutputs.push(
7719
- new TransactionOutput(toCardanoAddress(changeAddress), remainingValue)
7720
- );
7721
- this.txBody.setOutputs(currentOutputs);
7722
- this.txBody.setFee(BigInt("10000000"));
7723
- const numberOfRequiredWitnesses = this.countNumberOfRequiredWitnesses();
7724
- const dummyTx = this.createDummyTx(numberOfRequiredWitnesses);
7725
- const fee = calculateFees(
7726
- this.protocolParams.minFeeA,
7727
- this.protocolParams.minFeeB,
7728
- this.protocolParams.minFeeRefScriptCostPerByte,
7729
- this.protocolParams.priceMem,
7730
- this.protocolParams.priceStep,
7731
- dummyTx,
7732
- this.refScriptSize
7733
- );
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
- );
7748
- }
7749
- this.txBody.setOutputs(currentOutputs);
7750
- };
7751
- createDummyTx = (numberOfRequiredWitnesses) => {
7752
- let dummyWitnessSet = TransactionWitnessSet.fromCbor(
7753
- (0, import_util9.HexBlob)(this.txWitnessSet.toCbor())
7754
- );
7755
- const dummyVkeyWitnesses = [];
7756
- for (let i = 0; i < numberOfRequiredWitnesses; i++) {
7757
- dummyVkeyWitnesses.push([
7758
- Ed25519PublicKeyHex2(String(i).repeat(64)),
7759
- Ed25519SignatureHex2(String(i).repeat(128))
7760
- ]);
7761
- }
7762
- dummyWitnessSet.setVkeys(
7763
- import_core7.Serialization.CborSet.fromCore(dummyVkeyWitnesses, VkeyWitness.fromCore)
7764
- );
7765
- return new Transaction(this.txBody, dummyWitnessSet, this.txAuxilliaryData);
6981
+ return finalRefInputs;
7766
6982
  };
7767
6983
  addScriptRef = (scriptSource) => {
7768
6984
  if (scriptSource.type !== "Inline") {
7769
6985
  return;
7770
6986
  }
7771
- let referenceInputs = this.txBody.referenceInputs() ?? import_core7.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
7772
- let referenceInputsList = [...referenceInputs.values()];
7773
- referenceInputsList.push(
7774
- new TransactionInput(
7775
- TransactionId(scriptSource.txHash),
7776
- BigInt(scriptSource.txIndex)
7777
- )
7778
- );
7779
- referenceInputs.setValues(referenceInputsList);
7780
- this.txBody.setReferenceInputs(referenceInputs);
6987
+ if (!scriptSource.scriptSize) {
6988
+ throw new Error(
6989
+ "A reference script was used without providing its size, this must be provided as fee calculations are based on it"
6990
+ );
6991
+ }
6992
+ this.addReferenceInput({
6993
+ txHash: scriptSource.txHash,
6994
+ txIndex: scriptSource.txIndex,
6995
+ scriptSize: Number(scriptSource.scriptSize)
6996
+ });
7781
6997
  switch (scriptSource.version) {
7782
6998
  case "V1": {
7783
6999
  this.usedLanguages[PlutusLanguageVersion.V1] = true;
@@ -7792,205 +7008,22 @@ var CardanoSDKSerializerCore = class {
7792
7008
  break;
7793
7009
  }
7794
7010
  }
7795
- if (scriptSource.scriptSize) {
7796
- this.refScriptSize += Number(scriptSource.scriptSize);
7797
- } else {
7798
- throw new Error(
7799
- "A reference script was used without providing its size, this must be provided as fee calculations are based on it"
7800
- );
7801
- }
7802
7011
  };
7803
7012
  addSimpleScriptRef = (simpleScriptSource) => {
7804
7013
  if (simpleScriptSource.type !== "Inline") {
7805
7014
  return;
7806
7015
  }
7807
- let referenceInputs = this.txBody.referenceInputs() ?? import_core7.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
7808
- let referenceInputsList = [...referenceInputs.values()];
7809
- referenceInputsList.push(
7810
- new TransactionInput(
7811
- TransactionId(simpleScriptSource.txHash),
7812
- BigInt(simpleScriptSource.txIndex)
7813
- )
7814
- );
7815
- if (simpleScriptSource.scriptSize) {
7816
- this.refScriptSize += Number(simpleScriptSource.scriptSize);
7817
- } else {
7016
+ if (!simpleScriptSource.scriptSize) {
7818
7017
  throw new Error(
7819
7018
  "A reference script was used without providing its size, this must be provided as fee calculations are based on it"
7820
7019
  );
7821
7020
  }
7822
- referenceInputs.setValues(referenceInputsList);
7823
- this.txBody.setReferenceInputs(referenceInputs);
7021
+ this.addReferenceInput({
7022
+ txHash: simpleScriptSource.txHash,
7023
+ txIndex: simpleScriptSource.txIndex,
7024
+ scriptSize: Number(simpleScriptSource.scriptSize)
7025
+ });
7824
7026
  };
7825
- countNumberOfRequiredWitnesses() {
7826
- let requiredWitnesses = /* @__PURE__ */ new Set();
7827
- const inputs = this.txBody.inputs().values();
7828
- for (let i = 0; i < inputs.length; i++) {
7829
- const input = inputs[i];
7830
- const addressPaymentPart = this.utxoContext.get(input)?.address().getProps().paymentPart;
7831
- if (addressPaymentPart?.type === 0) {
7832
- requiredWitnesses.add(addressPaymentPart.hash);
7833
- }
7834
- }
7835
- const collateralInputs = this.txBody.collateral()?.values();
7836
- if (collateralInputs) {
7837
- for (let i = 0; i < collateralInputs?.length; i++) {
7838
- const collateralInput = collateralInputs[i];
7839
- const addressPaymentPart = this.utxoContext.get(collateralInput)?.address().getProps().paymentPart;
7840
- if (addressPaymentPart?.type === 0) {
7841
- requiredWitnesses.add(addressPaymentPart.hash);
7842
- }
7843
- }
7844
- }
7845
- const withdrawalKeys = this.txBody.withdrawals()?.keys();
7846
- if (withdrawalKeys) {
7847
- for (let withdrawalKey of withdrawalKeys) {
7848
- requiredWitnesses.add(RewardAccount.toHash(withdrawalKey));
7849
- }
7850
- }
7851
- const certs = this.txBody.certs()?.values();
7852
- if (certs) {
7853
- for (let cert of certs) {
7854
- const coreCert = cert.toCore();
7855
- switch (coreCert.__typename) {
7856
- case CertificateType.StakeRegistration: {
7857
- requiredWitnesses.add(coreCert.stakeCredential.hash);
7858
- break;
7859
- }
7860
- case CertificateType.StakeDeregistration: {
7861
- requiredWitnesses.add(coreCert.stakeCredential.hash);
7862
- break;
7863
- }
7864
- case CertificateType.PoolRegistration: {
7865
- for (let owner of coreCert.poolParameters.owners) {
7866
- requiredWitnesses.add(RewardAccount.toHash(owner));
7867
- }
7868
- requiredWitnesses.add(PoolId.toKeyHash(coreCert.poolParameters.id));
7869
- break;
7870
- }
7871
- case CertificateType.PoolRetirement: {
7872
- requiredWitnesses.add(PoolId.toKeyHash(coreCert.poolId));
7873
- break;
7874
- }
7875
- case CertificateType.StakeDelegation: {
7876
- requiredWitnesses.add(coreCert.stakeCredential.hash);
7877
- break;
7878
- }
7879
- case CertificateType.MIR:
7880
- break;
7881
- case CertificateType.GenesisKeyDelegation: {
7882
- requiredWitnesses.add(coreCert.genesisDelegateHash);
7883
- break;
7884
- }
7885
- case CertificateType.Registration: {
7886
- requiredWitnesses.add(coreCert.stakeCredential.hash);
7887
- break;
7888
- }
7889
- case CertificateType.Unregistration: {
7890
- requiredWitnesses.add(coreCert.stakeCredential.hash);
7891
- break;
7892
- }
7893
- case CertificateType.VoteDelegation: {
7894
- requiredWitnesses.add(coreCert.stakeCredential.hash);
7895
- break;
7896
- }
7897
- case CertificateType.StakeVoteDelegation: {
7898
- requiredWitnesses.add(coreCert.stakeCredential.hash);
7899
- break;
7900
- }
7901
- case CertificateType.StakeRegistrationDelegation: {
7902
- requiredWitnesses.add(coreCert.stakeCredential.hash);
7903
- break;
7904
- }
7905
- case CertificateType.VoteRegistrationDelegation: {
7906
- requiredWitnesses.add(coreCert.stakeCredential.hash);
7907
- break;
7908
- }
7909
- case CertificateType.StakeVoteRegistrationDelegation: {
7910
- requiredWitnesses.add(coreCert.stakeCredential.hash);
7911
- break;
7912
- }
7913
- case CertificateType.AuthorizeCommitteeHot: {
7914
- requiredWitnesses.add(coreCert.hotCredential.hash);
7915
- break;
7916
- }
7917
- case CertificateType.ResignCommitteeCold: {
7918
- requiredWitnesses.add(coreCert.coldCredential.hash);
7919
- break;
7920
- }
7921
- case CertificateType.RegisterDelegateRepresentative: {
7922
- requiredWitnesses.add(coreCert.dRepCredential.hash);
7923
- break;
7924
- }
7925
- case CertificateType.UnregisterDelegateRepresentative: {
7926
- requiredWitnesses.add(coreCert.dRepCredential.hash);
7927
- break;
7928
- }
7929
- case CertificateType.UpdateDelegateRepresentative: {
7930
- requiredWitnesses.add(coreCert.dRepCredential.hash);
7931
- break;
7932
- }
7933
- }
7934
- }
7935
- }
7936
- for (const scriptHex of this.scriptsProvided) {
7937
- const script = Script.fromCbor((0, import_util9.HexBlob)(scriptHex));
7938
- let nativeScript = script.asNative();
7939
- if (nativeScript) {
7940
- this.addKeyHashesFromNativeScript(nativeScript, requiredWitnesses);
7941
- }
7942
- }
7943
- const requiredSigners = this.txBody.requiredSigners()?.values();
7944
- if (requiredSigners) {
7945
- for (let i = 0; i < requiredSigners.length; i++) {
7946
- requiredWitnesses.add(requiredSigners[i].toCbor());
7947
- }
7948
- }
7949
- return requiredWitnesses.size;
7950
- }
7951
- addKeyHashesFromNativeScript(script, keyHashes) {
7952
- const scriptCore = script.toCore();
7953
- switch (scriptCore.kind) {
7954
- case RequireSignature: {
7955
- keyHashes.add(scriptCore.keyHash);
7956
- break;
7957
- }
7958
- case RequireTimeAfter: {
7959
- break;
7960
- }
7961
- case RequireTimeBefore: {
7962
- break;
7963
- }
7964
- case RequireAllOf: {
7965
- for (const innerScript of scriptCore.scripts) {
7966
- this.addKeyHashesFromNativeScript(
7967
- NativeScript.fromCore(innerScript),
7968
- keyHashes
7969
- );
7970
- }
7971
- break;
7972
- }
7973
- case RequireAnyOf: {
7974
- for (const innerScript of scriptCore.scripts) {
7975
- this.addKeyHashesFromNativeScript(
7976
- NativeScript.fromCore(innerScript),
7977
- keyHashes
7978
- );
7979
- }
7980
- break;
7981
- }
7982
- case RequireNOf: {
7983
- for (const innerScript of scriptCore.scripts) {
7984
- this.addKeyHashesFromNativeScript(
7985
- NativeScript.fromCore(innerScript),
7986
- keyHashes
7987
- );
7988
- }
7989
- break;
7990
- }
7991
- }
7992
- return keyHashes;
7993
- }
7994
7027
  addProvidedPlutusScript = (script) => {
7995
7028
  switch (script.version) {
7996
7029
  case "V1": {
@@ -8022,6 +7055,159 @@ var CardanoSDKSerializerCore = class {
8022
7055
  }
8023
7056
  }
8024
7057
  };
7058
+ addAllVotes = (votes) => {
7059
+ for (let i = 0; i < votes.length; i++) {
7060
+ const vote = votes[i];
7061
+ switch (vote.type) {
7062
+ case "BasicVote": {
7063
+ this.addBasicVote(vote);
7064
+ break;
7065
+ }
7066
+ case "ScriptVote": {
7067
+ this.addScriptVote(vote, i);
7068
+ break;
7069
+ }
7070
+ case "SimpleScriptVote": {
7071
+ this.addSimpleScriptVote(vote);
7072
+ break;
7073
+ }
7074
+ }
7075
+ }
7076
+ };
7077
+ addBasicVote = (basicVote) => {
7078
+ const votes = this.txBody.votingProcedures() ?? import_core8.Serialization.VotingProcedures.fromCore([]);
7079
+ votes.insert(
7080
+ toCardanoVoter(basicVote.vote.voter),
7081
+ toCardanoGovernanceActionId(basicVote.vote.govActionId),
7082
+ toCardanoVotingProcedure(basicVote.vote.votingProcedure)
7083
+ );
7084
+ this.txBody.setVotingProcedures(votes);
7085
+ };
7086
+ addScriptVote = (vote, index) => {
7087
+ if (!vote.scriptSource)
7088
+ throw new Error("Script source not provided for plutus script vote");
7089
+ const plutusScriptSource = vote.scriptSource;
7090
+ if (!plutusScriptSource) {
7091
+ throw new Error(
7092
+ "A script source for a plutus certificate was not plutus script somehow"
7093
+ );
7094
+ }
7095
+ if (!vote.redeemer) {
7096
+ throw new Error("A redeemer was not provided for a plutus vote");
7097
+ }
7098
+ let redeemers = this.txWitnessSet.redeemers() ?? Redeemers.fromCore([]);
7099
+ let redeemersList = [...redeemers.values()];
7100
+ redeemersList.push(
7101
+ new Redeemer(
7102
+ RedeemerTag.Voting,
7103
+ BigInt(index),
7104
+ fromBuilderToPlutusData(vote.redeemer.data),
7105
+ new ExUnits(
7106
+ BigInt(vote.redeemer.exUnits.mem),
7107
+ BigInt(vote.redeemer.exUnits.steps)
7108
+ )
7109
+ )
7110
+ );
7111
+ redeemers.setValues(redeemersList);
7112
+ this.txWitnessSet.setRedeemers(redeemers);
7113
+ if (plutusScriptSource.type === "Provided") {
7114
+ this.addProvidedPlutusScript(plutusScriptSource.script);
7115
+ } else if (plutusScriptSource.type === "Inline") {
7116
+ this.addScriptRef(plutusScriptSource);
7117
+ }
7118
+ this.addBasicVote({ type: "BasicVote", vote: vote.vote });
7119
+ };
7120
+ addSimpleScriptVote = (vote) => {
7121
+ if (!vote.simpleScriptSource)
7122
+ throw new Error("Script source not provided for native script vote");
7123
+ const nativeScriptSource = vote.simpleScriptSource;
7124
+ if (!nativeScriptSource)
7125
+ throw new Error(
7126
+ "A script source for a native script was not a native script somehow"
7127
+ );
7128
+ if (nativeScriptSource.type === "Provided") {
7129
+ this.scriptsProvided.add(
7130
+ Script.newNativeScript(
7131
+ NativeScript.fromCbor((0, import_util9.HexBlob)(nativeScriptSource.scriptCode))
7132
+ ).toCbor()
7133
+ );
7134
+ } else if (nativeScriptSource.type === "Inline") {
7135
+ this.addSimpleScriptRef(nativeScriptSource);
7136
+ }
7137
+ this.addBasicVote({ type: "BasicVote", vote: vote.vote });
7138
+ };
7139
+ mockVkeyWitnesses = (numberOfRequiredWitnesses) => {
7140
+ let vkeyWitnesses = [];
7141
+ for (let i = 0; i < numberOfRequiredWitnesses; i++) {
7142
+ const numberInHex = this.numberToIntegerHex(i);
7143
+ const pubKeyHex = this.mockPubkey(numberInHex);
7144
+ const signature = this.mockSignature(numberInHex);
7145
+ vkeyWitnesses.push(
7146
+ new VkeyWitness(
7147
+ Ed25519PublicKeyHex2(pubKeyHex),
7148
+ Ed25519SignatureHex2(signature)
7149
+ )
7150
+ );
7151
+ }
7152
+ return vkeyWitnesses;
7153
+ };
7154
+ mockPubkey(numberInHex) {
7155
+ return "0".repeat(VKEY_PUBKEY_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
7156
+ }
7157
+ mockSignature(numberInHex) {
7158
+ return "0".repeat(VKEY_SIGNATURE_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
7159
+ }
7160
+ mockChainCode = (numberInHex) => {
7161
+ return "0".repeat(CHAIN_CODE_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
7162
+ };
7163
+ numberToIntegerHex = (number) => {
7164
+ return BigInt(number).toString(16);
7165
+ };
7166
+ mockBootstrapWitnesses = (byronAddresses) => {
7167
+ let bootstrapWitnesses = [];
7168
+ for (let i = 0; i < byronAddresses.length; i++) {
7169
+ const address = Address.fromBytes(byronAddresses[i]).asByron();
7170
+ if (!address) {
7171
+ throw new Error(`Failed to parse byron address: ${byronAddresses[i]}`);
7172
+ }
7173
+ const numberInHex = this.numberToIntegerHex(i);
7174
+ const pubKeyHex = this.mockPubkey(numberInHex);
7175
+ const signature = this.mockSignature(numberInHex);
7176
+ const chainCode = this.mockChainCode(numberInHex);
7177
+ const attributes = address.getAttributes();
7178
+ bootstrapWitnesses.push(
7179
+ new BootstrapWitness(
7180
+ Ed25519PublicKeyHex2(pubKeyHex),
7181
+ Ed25519SignatureHex2(signature),
7182
+ (0, import_util9.HexBlob)(chainCode),
7183
+ this.serializeByronAttributes(attributes)
7184
+ )
7185
+ );
7186
+ }
7187
+ return bootstrapWitnesses;
7188
+ };
7189
+ serializeByronAttributes = (attributes) => {
7190
+ const writer = new CborWriter();
7191
+ let mapSize = 0;
7192
+ if (attributes.magic) {
7193
+ mapSize++;
7194
+ }
7195
+ if (attributes.derivationPath) {
7196
+ mapSize++;
7197
+ }
7198
+ writer.writeStartMap(mapSize);
7199
+ if (attributes.derivationPath) {
7200
+ writer.writeInt(1);
7201
+ const encodedPathCbor = new CborWriter().writeByteString(import_buffer2.Buffer.from(attributes.derivationPath, "hex")).encode();
7202
+ writer.writeByteString(encodedPathCbor);
7203
+ }
7204
+ if (attributes.magic) {
7205
+ writer.writeInt(2);
7206
+ const encodedMagicCbor = new CborWriter().writeInt(attributes.magic).encode();
7207
+ writer.writeByteString(encodedMagicCbor);
7208
+ }
7209
+ return writer.encodeAsHex();
7210
+ };
8025
7211
  };
8026
7212
 
8027
7213
  // src/plutus-tools/index.ts
@@ -8169,6 +7355,7 @@ var CardanoSDK = __toESM(require("@cardano-sdk/core"), 1);
8169
7355
  Bip32PrivateKeyHex,
8170
7356
  Bip32PublicKey,
8171
7357
  Bip32PublicKeyHex,
7358
+ BootstrapWitness,
8172
7359
  Cardano,
8173
7360
  CardanoSDK,
8174
7361
  CardanoSDKSerializer,
@@ -8271,6 +7458,7 @@ var CardanoSDK = __toESM(require("@cardano-sdk/core"), 1);
8271
7458
  buildRewardAddress,
8272
7459
  buildScriptPubkey,
8273
7460
  bytesToHex,
7461
+ calculateFees,
8274
7462
  checkSignature,
8275
7463
  clampScalar,
8276
7464
  computeAuxiliaryDataHash,