@vleap/warps-adapter-fastset 0.1.0-alpha.25 → 0.1.0-alpha.26

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.mjs CHANGED
@@ -10,6 +10,9 @@ var decoder = new TextDecoder();
10
10
  function uint8ArrayToHex(uint8Array) {
11
11
  return Buffer.from(uint8Array).toString("hex");
12
12
  }
13
+ function hexToUint8Array(hex) {
14
+ return new Uint8Array(Buffer.from(hex, "hex"));
15
+ }
13
16
  function stringToUint8Array(str) {
14
17
  return new Uint8Array(Buffer.from(str, "utf8"));
15
18
  }
@@ -18,44 +21,10 @@ function stringToUint8Array(str) {
18
21
  import { getProviderUrl } from "@vleap/warps";
19
22
 
20
23
  // src/sdk/FastsetClient.ts
21
- import { BCS, getSuiMoveConfig } from "@mysten/bcs";
22
24
  import * as bech32 from "bech32";
23
25
  BigInt.prototype.toJSON = function() {
24
26
  return Number(this);
25
27
  };
26
- var bcs = new BCS(getSuiMoveConfig());
27
- bcs.registerStructType("FastSetAddress", {
28
- bytes: "vector<u8>"
29
- });
30
- bcs.registerStructType("ExternalAddress", {
31
- bytes: "vector<u8>"
32
- });
33
- bcs.registerEnumType("Address", {
34
- FastSet: "FastSetAddress",
35
- External: "ExternalAddress"
36
- });
37
- bcs.registerEnumType("UserDataOption", {
38
- Some: "vector<u8>",
39
- None: "bool"
40
- // Use bool for None variant (false = None)
41
- });
42
- bcs.registerStructType("TransferClaim", {
43
- amount: "u256",
44
- // 256-bit unsigned integer
45
- user_data: "UserDataOption"
46
- // Use our custom option type
47
- });
48
- bcs.registerStructType("ClaimType", {
49
- Transfer: "TransferClaim"
50
- });
51
- bcs.registerStructType("Transaction", {
52
- sender: "vector<u8>",
53
- // 32 bytes
54
- recipient: "Address",
55
- nonce: "u64",
56
- timestamp_nanos: "u128",
57
- claim: "ClaimType"
58
- });
59
28
  var id = 0;
60
29
  var FastsetClient = class {
61
30
  constructor(proxyUrl) {
@@ -113,17 +82,17 @@ var FastsetClient = class {
113
82
  };
114
83
 
115
84
  // src/helpers/general.ts
116
- var getConfiguredFastsetClient = (config, chain) => {
117
- const proxyUrl = getProviderUrl(config, chain.name, config.env, chain.defaultApiUrl);
85
+ var getConfiguredFastsetClient = (config, chain2) => {
86
+ const proxyUrl = getProviderUrl(config, chain2.name, config.env, chain2.defaultApiUrl);
118
87
  return new FastsetClient(proxyUrl);
119
88
  };
120
89
 
121
90
  // src/WarpFastsetDataLoader.ts
122
91
  var WarpFastsetDataLoader = class {
123
- constructor(config, chain) {
92
+ constructor(config, chain2) {
124
93
  this.config = config;
125
- this.chain = chain;
126
- this.client = getConfiguredFastsetClient(config, chain);
94
+ this.chain = chain2;
95
+ this.client = getConfiguredFastsetClient(config, chain2);
127
96
  }
128
97
  async getAccount(address) {
129
98
  const addressBytes = this.addressToBytes(address);
@@ -202,9 +171,9 @@ import {
202
171
  getWarpWalletAddressFromConfig
203
172
  } from "@vleap/warps";
204
173
  var WarpFastsetExecutor = class {
205
- constructor(config, chain) {
174
+ constructor(config, chain2) {
206
175
  this.config = config;
207
- this.chain = chain;
176
+ this.chain = chain2;
208
177
  this.client = getConfiguredFastsetClient(this.config, this.chain);
209
178
  }
210
179
  async createTransaction(executable) {
@@ -384,9 +353,9 @@ var WarpFastsetSerializer = class {
384
353
 
385
354
  // src/WarpFastsetResults.ts
386
355
  var WarpFastsetResults = class {
387
- constructor(config, chain) {
356
+ constructor(config, chain2) {
388
357
  this.config = config;
389
- this.chain = chain;
358
+ this.chain = chain2;
390
359
  this.serializer = new WarpFastsetSerializer();
391
360
  }
392
361
  async getTransactionExecutionResults(warp, tx) {
@@ -477,81 +446,1733 @@ import {
477
446
 
478
447
  // src/sdk/ed25519-setup.ts
479
448
  import * as ed from "@noble/ed25519";
480
- import { sha512 } from "@noble/hashes/sha512";
481
- if (ed.etc) {
482
- ed.etc.sha512Sync = (...m) => sha512(ed.etc.concatBytes(...m));
449
+
450
+ // ../../node_modules/@noble/hashes/esm/utils.js
451
+ function isBytes(a) {
452
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
453
+ }
454
+ function abytes(b, ...lengths) {
455
+ if (!isBytes(b))
456
+ throw new Error("Uint8Array expected");
457
+ if (lengths.length > 0 && !lengths.includes(b.length))
458
+ throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
459
+ }
460
+ function aexists(instance, checkFinished = true) {
461
+ if (instance.destroyed)
462
+ throw new Error("Hash instance has been destroyed");
463
+ if (checkFinished && instance.finished)
464
+ throw new Error("Hash#digest() has already been called");
465
+ }
466
+ function aoutput(out, instance) {
467
+ abytes(out);
468
+ const min = instance.outputLen;
469
+ if (out.length < min) {
470
+ throw new Error("digestInto() expects output buffer of length at least " + min);
471
+ }
472
+ }
473
+ function clean(...arrays) {
474
+ for (let i = 0; i < arrays.length; i++) {
475
+ arrays[i].fill(0);
476
+ }
477
+ }
478
+ function createView(arr) {
479
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
480
+ }
481
+ function utf8ToBytes(str) {
482
+ if (typeof str !== "string")
483
+ throw new Error("string expected");
484
+ return new Uint8Array(new TextEncoder().encode(str));
485
+ }
486
+ function toBytes(data) {
487
+ if (typeof data === "string")
488
+ data = utf8ToBytes(data);
489
+ abytes(data);
490
+ return data;
491
+ }
492
+ var Hash = class {
493
+ };
494
+ function createHasher(hashCons) {
495
+ const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
496
+ const tmp = hashCons();
497
+ hashC.outputLen = tmp.outputLen;
498
+ hashC.blockLen = tmp.blockLen;
499
+ hashC.create = () => hashCons();
500
+ return hashC;
501
+ }
502
+
503
+ // ../../node_modules/@noble/hashes/esm/_md.js
504
+ function setBigUint64(view, byteOffset, value, isLE) {
505
+ if (typeof view.setBigUint64 === "function")
506
+ return view.setBigUint64(byteOffset, value, isLE);
507
+ const _32n2 = BigInt(32);
508
+ const _u32_max = BigInt(4294967295);
509
+ const wh = Number(value >> _32n2 & _u32_max);
510
+ const wl = Number(value & _u32_max);
511
+ const h = isLE ? 4 : 0;
512
+ const l = isLE ? 0 : 4;
513
+ view.setUint32(byteOffset + h, wh, isLE);
514
+ view.setUint32(byteOffset + l, wl, isLE);
515
+ }
516
+ var HashMD = class extends Hash {
517
+ constructor(blockLen, outputLen, padOffset, isLE) {
518
+ super();
519
+ this.finished = false;
520
+ this.length = 0;
521
+ this.pos = 0;
522
+ this.destroyed = false;
523
+ this.blockLen = blockLen;
524
+ this.outputLen = outputLen;
525
+ this.padOffset = padOffset;
526
+ this.isLE = isLE;
527
+ this.buffer = new Uint8Array(blockLen);
528
+ this.view = createView(this.buffer);
529
+ }
530
+ update(data) {
531
+ aexists(this);
532
+ data = toBytes(data);
533
+ abytes(data);
534
+ const { view, buffer, blockLen } = this;
535
+ const len = data.length;
536
+ for (let pos = 0; pos < len; ) {
537
+ const take = Math.min(blockLen - this.pos, len - pos);
538
+ if (take === blockLen) {
539
+ const dataView = createView(data);
540
+ for (; blockLen <= len - pos; pos += blockLen)
541
+ this.process(dataView, pos);
542
+ continue;
543
+ }
544
+ buffer.set(data.subarray(pos, pos + take), this.pos);
545
+ this.pos += take;
546
+ pos += take;
547
+ if (this.pos === blockLen) {
548
+ this.process(view, 0);
549
+ this.pos = 0;
550
+ }
551
+ }
552
+ this.length += data.length;
553
+ this.roundClean();
554
+ return this;
555
+ }
556
+ digestInto(out) {
557
+ aexists(this);
558
+ aoutput(out, this);
559
+ this.finished = true;
560
+ const { buffer, view, blockLen, isLE } = this;
561
+ let { pos } = this;
562
+ buffer[pos++] = 128;
563
+ clean(this.buffer.subarray(pos));
564
+ if (this.padOffset > blockLen - pos) {
565
+ this.process(view, 0);
566
+ pos = 0;
567
+ }
568
+ for (let i = pos; i < blockLen; i++)
569
+ buffer[i] = 0;
570
+ setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
571
+ this.process(view, 0);
572
+ const oview = createView(out);
573
+ const len = this.outputLen;
574
+ if (len % 4)
575
+ throw new Error("_sha2: outputLen should be aligned to 32bit");
576
+ const outLen = len / 4;
577
+ const state = this.get();
578
+ if (outLen > state.length)
579
+ throw new Error("_sha2: outputLen bigger than state");
580
+ for (let i = 0; i < outLen; i++)
581
+ oview.setUint32(4 * i, state[i], isLE);
582
+ }
583
+ digest() {
584
+ const { buffer, outputLen } = this;
585
+ this.digestInto(buffer);
586
+ const res = buffer.slice(0, outputLen);
587
+ this.destroy();
588
+ return res;
589
+ }
590
+ _cloneInto(to) {
591
+ to || (to = new this.constructor());
592
+ to.set(...this.get());
593
+ const { blockLen, buffer, length, finished, destroyed, pos } = this;
594
+ to.destroyed = destroyed;
595
+ to.finished = finished;
596
+ to.length = length;
597
+ to.pos = pos;
598
+ if (length % blockLen)
599
+ to.buffer.set(buffer);
600
+ return to;
601
+ }
602
+ clone() {
603
+ return this._cloneInto();
604
+ }
605
+ };
606
+ var SHA512_IV = /* @__PURE__ */ Uint32Array.from([
607
+ 1779033703,
608
+ 4089235720,
609
+ 3144134277,
610
+ 2227873595,
611
+ 1013904242,
612
+ 4271175723,
613
+ 2773480762,
614
+ 1595750129,
615
+ 1359893119,
616
+ 2917565137,
617
+ 2600822924,
618
+ 725511199,
619
+ 528734635,
620
+ 4215389547,
621
+ 1541459225,
622
+ 327033209
623
+ ]);
624
+
625
+ // ../../node_modules/@noble/hashes/esm/_u64.js
626
+ var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
627
+ var _32n = /* @__PURE__ */ BigInt(32);
628
+ function fromBig(n, le = false) {
629
+ if (le)
630
+ return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
631
+ return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
632
+ }
633
+ function split(lst, le = false) {
634
+ const len = lst.length;
635
+ let Ah = new Uint32Array(len);
636
+ let Al = new Uint32Array(len);
637
+ for (let i = 0; i < len; i++) {
638
+ const { h, l } = fromBig(lst[i], le);
639
+ [Ah[i], Al[i]] = [h, l];
640
+ }
641
+ return [Ah, Al];
642
+ }
643
+ var shrSH = (h, _l, s) => h >>> s;
644
+ var shrSL = (h, l, s) => h << 32 - s | l >>> s;
645
+ var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
646
+ var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
647
+ var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
648
+ var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
649
+ function add(Ah, Al, Bh, Bl) {
650
+ const l = (Al >>> 0) + (Bl >>> 0);
651
+ return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
652
+ }
653
+ var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
654
+ var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
655
+ var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
656
+ var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
657
+ var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
658
+ var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
659
+
660
+ // ../../node_modules/@noble/hashes/esm/sha2.js
661
+ var K512 = /* @__PURE__ */ (() => split([
662
+ "0x428a2f98d728ae22",
663
+ "0x7137449123ef65cd",
664
+ "0xb5c0fbcfec4d3b2f",
665
+ "0xe9b5dba58189dbbc",
666
+ "0x3956c25bf348b538",
667
+ "0x59f111f1b605d019",
668
+ "0x923f82a4af194f9b",
669
+ "0xab1c5ed5da6d8118",
670
+ "0xd807aa98a3030242",
671
+ "0x12835b0145706fbe",
672
+ "0x243185be4ee4b28c",
673
+ "0x550c7dc3d5ffb4e2",
674
+ "0x72be5d74f27b896f",
675
+ "0x80deb1fe3b1696b1",
676
+ "0x9bdc06a725c71235",
677
+ "0xc19bf174cf692694",
678
+ "0xe49b69c19ef14ad2",
679
+ "0xefbe4786384f25e3",
680
+ "0x0fc19dc68b8cd5b5",
681
+ "0x240ca1cc77ac9c65",
682
+ "0x2de92c6f592b0275",
683
+ "0x4a7484aa6ea6e483",
684
+ "0x5cb0a9dcbd41fbd4",
685
+ "0x76f988da831153b5",
686
+ "0x983e5152ee66dfab",
687
+ "0xa831c66d2db43210",
688
+ "0xb00327c898fb213f",
689
+ "0xbf597fc7beef0ee4",
690
+ "0xc6e00bf33da88fc2",
691
+ "0xd5a79147930aa725",
692
+ "0x06ca6351e003826f",
693
+ "0x142929670a0e6e70",
694
+ "0x27b70a8546d22ffc",
695
+ "0x2e1b21385c26c926",
696
+ "0x4d2c6dfc5ac42aed",
697
+ "0x53380d139d95b3df",
698
+ "0x650a73548baf63de",
699
+ "0x766a0abb3c77b2a8",
700
+ "0x81c2c92e47edaee6",
701
+ "0x92722c851482353b",
702
+ "0xa2bfe8a14cf10364",
703
+ "0xa81a664bbc423001",
704
+ "0xc24b8b70d0f89791",
705
+ "0xc76c51a30654be30",
706
+ "0xd192e819d6ef5218",
707
+ "0xd69906245565a910",
708
+ "0xf40e35855771202a",
709
+ "0x106aa07032bbd1b8",
710
+ "0x19a4c116b8d2d0c8",
711
+ "0x1e376c085141ab53",
712
+ "0x2748774cdf8eeb99",
713
+ "0x34b0bcb5e19b48a8",
714
+ "0x391c0cb3c5c95a63",
715
+ "0x4ed8aa4ae3418acb",
716
+ "0x5b9cca4f7763e373",
717
+ "0x682e6ff3d6b2b8a3",
718
+ "0x748f82ee5defb2fc",
719
+ "0x78a5636f43172f60",
720
+ "0x84c87814a1f0ab72",
721
+ "0x8cc702081a6439ec",
722
+ "0x90befffa23631e28",
723
+ "0xa4506cebde82bde9",
724
+ "0xbef9a3f7b2c67915",
725
+ "0xc67178f2e372532b",
726
+ "0xca273eceea26619c",
727
+ "0xd186b8c721c0c207",
728
+ "0xeada7dd6cde0eb1e",
729
+ "0xf57d4f7fee6ed178",
730
+ "0x06f067aa72176fba",
731
+ "0x0a637dc5a2c898a6",
732
+ "0x113f9804bef90dae",
733
+ "0x1b710b35131c471b",
734
+ "0x28db77f523047d84",
735
+ "0x32caab7b40c72493",
736
+ "0x3c9ebe0a15c9bebc",
737
+ "0x431d67c49c100d4c",
738
+ "0x4cc5d4becb3e42b6",
739
+ "0x597f299cfc657e2a",
740
+ "0x5fcb6fab3ad6faec",
741
+ "0x6c44198c4a475817"
742
+ ].map((n) => BigInt(n))))();
743
+ var SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
744
+ var SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
745
+ var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
746
+ var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
747
+ var SHA512 = class extends HashMD {
748
+ constructor(outputLen = 64) {
749
+ super(128, outputLen, 16, false);
750
+ this.Ah = SHA512_IV[0] | 0;
751
+ this.Al = SHA512_IV[1] | 0;
752
+ this.Bh = SHA512_IV[2] | 0;
753
+ this.Bl = SHA512_IV[3] | 0;
754
+ this.Ch = SHA512_IV[4] | 0;
755
+ this.Cl = SHA512_IV[5] | 0;
756
+ this.Dh = SHA512_IV[6] | 0;
757
+ this.Dl = SHA512_IV[7] | 0;
758
+ this.Eh = SHA512_IV[8] | 0;
759
+ this.El = SHA512_IV[9] | 0;
760
+ this.Fh = SHA512_IV[10] | 0;
761
+ this.Fl = SHA512_IV[11] | 0;
762
+ this.Gh = SHA512_IV[12] | 0;
763
+ this.Gl = SHA512_IV[13] | 0;
764
+ this.Hh = SHA512_IV[14] | 0;
765
+ this.Hl = SHA512_IV[15] | 0;
766
+ }
767
+ // prettier-ignore
768
+ get() {
769
+ const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
770
+ return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
771
+ }
772
+ // prettier-ignore
773
+ set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
774
+ this.Ah = Ah | 0;
775
+ this.Al = Al | 0;
776
+ this.Bh = Bh | 0;
777
+ this.Bl = Bl | 0;
778
+ this.Ch = Ch | 0;
779
+ this.Cl = Cl | 0;
780
+ this.Dh = Dh | 0;
781
+ this.Dl = Dl | 0;
782
+ this.Eh = Eh | 0;
783
+ this.El = El | 0;
784
+ this.Fh = Fh | 0;
785
+ this.Fl = Fl | 0;
786
+ this.Gh = Gh | 0;
787
+ this.Gl = Gl | 0;
788
+ this.Hh = Hh | 0;
789
+ this.Hl = Hl | 0;
790
+ }
791
+ process(view, offset) {
792
+ for (let i = 0; i < 16; i++, offset += 4) {
793
+ SHA512_W_H[i] = view.getUint32(offset);
794
+ SHA512_W_L[i] = view.getUint32(offset += 4);
795
+ }
796
+ for (let i = 16; i < 80; i++) {
797
+ const W15h = SHA512_W_H[i - 15] | 0;
798
+ const W15l = SHA512_W_L[i - 15] | 0;
799
+ const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
800
+ const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
801
+ const W2h = SHA512_W_H[i - 2] | 0;
802
+ const W2l = SHA512_W_L[i - 2] | 0;
803
+ const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
804
+ const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
805
+ const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
806
+ const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
807
+ SHA512_W_H[i] = SUMh | 0;
808
+ SHA512_W_L[i] = SUMl | 0;
809
+ }
810
+ let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
811
+ for (let i = 0; i < 80; i++) {
812
+ const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
813
+ const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
814
+ const CHIh = Eh & Fh ^ ~Eh & Gh;
815
+ const CHIl = El & Fl ^ ~El & Gl;
816
+ const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
817
+ const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
818
+ const T1l = T1ll | 0;
819
+ const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
820
+ const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
821
+ const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
822
+ const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
823
+ Hh = Gh | 0;
824
+ Hl = Gl | 0;
825
+ Gh = Fh | 0;
826
+ Gl = Fl | 0;
827
+ Fh = Eh | 0;
828
+ Fl = El | 0;
829
+ ({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
830
+ Dh = Ch | 0;
831
+ Dl = Cl | 0;
832
+ Ch = Bh | 0;
833
+ Cl = Bl | 0;
834
+ Bh = Ah | 0;
835
+ Bl = Al | 0;
836
+ const All = add3L(T1l, sigma0l, MAJl);
837
+ Ah = add3H(All, T1h, sigma0h, MAJh);
838
+ Al = All | 0;
839
+ }
840
+ ({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
841
+ ({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
842
+ ({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
843
+ ({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
844
+ ({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
845
+ ({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
846
+ ({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
847
+ ({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
848
+ this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
849
+ }
850
+ roundClean() {
851
+ clean(SHA512_W_H, SHA512_W_L);
852
+ }
853
+ destroy() {
854
+ clean(this.buffer);
855
+ this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
856
+ }
857
+ };
858
+ var sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
859
+
860
+ // ../../node_modules/@noble/hashes/esm/sha512.js
861
+ var sha5122 = sha512;
862
+
863
+ // src/sdk/ed25519-setup.ts
864
+ ed.hashes.sha512 = sha5122;
865
+
866
+ // ../../node_modules/@scure/base/lib/esm/index.js
867
+ function isBytes2(a) {
868
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
869
+ }
870
+ function isArrayOf(isString, arr) {
871
+ if (!Array.isArray(arr))
872
+ return false;
873
+ if (arr.length === 0)
874
+ return true;
875
+ if (isString) {
876
+ return arr.every((item) => typeof item === "string");
877
+ } else {
878
+ return arr.every((item) => Number.isSafeInteger(item));
879
+ }
880
+ }
881
+ function astr(label, input) {
882
+ if (typeof input !== "string")
883
+ throw new Error(`${label}: string expected`);
884
+ return true;
885
+ }
886
+ function anumber(n) {
887
+ if (!Number.isSafeInteger(n))
888
+ throw new Error(`invalid integer: ${n}`);
889
+ }
890
+ function aArr(input) {
891
+ if (!Array.isArray(input))
892
+ throw new Error("array expected");
893
+ }
894
+ function astrArr(label, input) {
895
+ if (!isArrayOf(true, input))
896
+ throw new Error(`${label}: array of strings expected`);
897
+ }
898
+ function anumArr(label, input) {
899
+ if (!isArrayOf(false, input))
900
+ throw new Error(`${label}: array of numbers expected`);
901
+ }
902
+ // @__NO_SIDE_EFFECTS__
903
+ function chain(...args) {
904
+ const id2 = (a) => a;
905
+ const wrap = (a, b) => (c) => a(b(c));
906
+ const encode = args.map((x) => x.encode).reduceRight(wrap, id2);
907
+ const decode = args.map((x) => x.decode).reduce(wrap, id2);
908
+ return { encode, decode };
909
+ }
910
+ // @__NO_SIDE_EFFECTS__
911
+ function alphabet(letters) {
912
+ const lettersA = typeof letters === "string" ? letters.split("") : letters;
913
+ const len = lettersA.length;
914
+ astrArr("alphabet", lettersA);
915
+ const indexes = new Map(lettersA.map((l, i) => [l, i]));
916
+ return {
917
+ encode: (digits) => {
918
+ aArr(digits);
919
+ return digits.map((i) => {
920
+ if (!Number.isSafeInteger(i) || i < 0 || i >= len)
921
+ throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`);
922
+ return lettersA[i];
923
+ });
924
+ },
925
+ decode: (input) => {
926
+ aArr(input);
927
+ return input.map((letter) => {
928
+ astr("alphabet.decode", letter);
929
+ const i = indexes.get(letter);
930
+ if (i === void 0)
931
+ throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
932
+ return i;
933
+ });
934
+ }
935
+ };
936
+ }
937
+ // @__NO_SIDE_EFFECTS__
938
+ function join(separator = "") {
939
+ astr("join", separator);
940
+ return {
941
+ encode: (from) => {
942
+ astrArr("join.decode", from);
943
+ return from.join(separator);
944
+ },
945
+ decode: (to) => {
946
+ astr("join.decode", to);
947
+ return to.split(separator);
948
+ }
949
+ };
950
+ }
951
+ function convertRadix(data, from, to) {
952
+ if (from < 2)
953
+ throw new Error(`convertRadix: invalid from=${from}, base cannot be less than 2`);
954
+ if (to < 2)
955
+ throw new Error(`convertRadix: invalid to=${to}, base cannot be less than 2`);
956
+ aArr(data);
957
+ if (!data.length)
958
+ return [];
959
+ let pos = 0;
960
+ const res = [];
961
+ const digits = Array.from(data, (d) => {
962
+ anumber(d);
963
+ if (d < 0 || d >= from)
964
+ throw new Error(`invalid integer: ${d}`);
965
+ return d;
966
+ });
967
+ const dlen = digits.length;
968
+ while (true) {
969
+ let carry = 0;
970
+ let done = true;
971
+ for (let i = pos; i < dlen; i++) {
972
+ const digit = digits[i];
973
+ const fromCarry = from * carry;
974
+ const digitBase = fromCarry + digit;
975
+ if (!Number.isSafeInteger(digitBase) || fromCarry / from !== carry || digitBase - digit !== fromCarry) {
976
+ throw new Error("convertRadix: carry overflow");
977
+ }
978
+ const div = digitBase / to;
979
+ carry = digitBase % to;
980
+ const rounded = Math.floor(div);
981
+ digits[i] = rounded;
982
+ if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase)
983
+ throw new Error("convertRadix: carry overflow");
984
+ if (!done)
985
+ continue;
986
+ else if (!rounded)
987
+ pos = i;
988
+ else
989
+ done = false;
990
+ }
991
+ res.push(carry);
992
+ if (done)
993
+ break;
994
+ }
995
+ for (let i = 0; i < data.length - 1 && data[i] === 0; i++)
996
+ res.push(0);
997
+ return res.reverse();
998
+ }
999
+ // @__NO_SIDE_EFFECTS__
1000
+ function radix(num) {
1001
+ anumber(num);
1002
+ const _256 = 2 ** 8;
1003
+ return {
1004
+ encode: (bytes) => {
1005
+ if (!isBytes2(bytes))
1006
+ throw new Error("radix.encode input should be Uint8Array");
1007
+ return convertRadix(Array.from(bytes), _256, num);
1008
+ },
1009
+ decode: (digits) => {
1010
+ anumArr("radix.decode", digits);
1011
+ return Uint8Array.from(convertRadix(digits, num, _256));
1012
+ }
1013
+ };
1014
+ }
1015
+ var genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join(""));
1016
+ var base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
1017
+
1018
+ // ../../node_modules/@mysten/utils/dist/esm/b58.js
1019
+ var toBase58 = (buffer) => base58.encode(buffer);
1020
+ var fromBase58 = (str) => base58.decode(str);
1021
+
1022
+ // ../../node_modules/@mysten/utils/dist/esm/b64.js
1023
+ function fromBase64(base64String) {
1024
+ return Uint8Array.from(atob(base64String), (char) => char.charCodeAt(0));
1025
+ }
1026
+ var CHUNK_SIZE = 8192;
1027
+ function toBase64(bytes) {
1028
+ if (bytes.length < CHUNK_SIZE) {
1029
+ return btoa(String.fromCharCode(...bytes));
1030
+ }
1031
+ let output = "";
1032
+ for (var i = 0; i < bytes.length; i += CHUNK_SIZE) {
1033
+ const chunk = bytes.slice(i, i + CHUNK_SIZE);
1034
+ output += String.fromCharCode(...chunk);
1035
+ }
1036
+ return btoa(output);
1037
+ }
1038
+
1039
+ // ../../node_modules/@mysten/utils/dist/esm/hex.js
1040
+ function fromHex(hexStr) {
1041
+ const normalized = hexStr.startsWith("0x") ? hexStr.slice(2) : hexStr;
1042
+ const padded = normalized.length % 2 === 0 ? normalized : `0${normalized}`;
1043
+ const intArr = padded.match(/[0-9a-fA-F]{2}/g)?.map((byte) => parseInt(byte, 16)) ?? [];
1044
+ if (intArr.length !== padded.length / 2) {
1045
+ throw new Error(`Invalid hex string ${hexStr}`);
1046
+ }
1047
+ return Uint8Array.from(intArr);
1048
+ }
1049
+ function toHex(bytes) {
1050
+ return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
1051
+ }
1052
+
1053
+ // ../../node_modules/@mysten/bcs/dist/esm/uleb.js
1054
+ function ulebEncode(num) {
1055
+ const arr = [];
1056
+ let len = 0;
1057
+ if (num === 0) {
1058
+ return [0];
1059
+ }
1060
+ while (num > 0) {
1061
+ arr[len] = num & 127;
1062
+ if (num >>= 7) {
1063
+ arr[len] |= 128;
1064
+ }
1065
+ len += 1;
1066
+ }
1067
+ return arr;
1068
+ }
1069
+ function ulebDecode(arr) {
1070
+ let total = 0;
1071
+ let shift = 0;
1072
+ let len = 0;
1073
+ while (true) {
1074
+ const byte = arr[len];
1075
+ len += 1;
1076
+ total |= (byte & 127) << shift;
1077
+ if ((byte & 128) === 0) {
1078
+ break;
1079
+ }
1080
+ shift += 7;
1081
+ }
1082
+ return {
1083
+ value: total,
1084
+ length: len
1085
+ };
1086
+ }
1087
+
1088
+ // ../../node_modules/@mysten/bcs/dist/esm/reader.js
1089
+ var BcsReader = class {
1090
+ /**
1091
+ * @param {Uint8Array} data Data to use as a buffer.
1092
+ */
1093
+ constructor(data) {
1094
+ this.bytePosition = 0;
1095
+ this.dataView = new DataView(data.buffer, data.byteOffset, data.byteLength);
1096
+ }
1097
+ /**
1098
+ * Shift current cursor position by `bytes`.
1099
+ *
1100
+ * @param {Number} bytes Number of bytes to
1101
+ * @returns {this} Self for possible chaining.
1102
+ */
1103
+ shift(bytes) {
1104
+ this.bytePosition += bytes;
1105
+ return this;
1106
+ }
1107
+ /**
1108
+ * Read U8 value from the buffer and shift cursor by 1.
1109
+ * @returns
1110
+ */
1111
+ read8() {
1112
+ const value = this.dataView.getUint8(this.bytePosition);
1113
+ this.shift(1);
1114
+ return value;
1115
+ }
1116
+ /**
1117
+ * Read U16 value from the buffer and shift cursor by 2.
1118
+ * @returns
1119
+ */
1120
+ read16() {
1121
+ const value = this.dataView.getUint16(this.bytePosition, true);
1122
+ this.shift(2);
1123
+ return value;
1124
+ }
1125
+ /**
1126
+ * Read U32 value from the buffer and shift cursor by 4.
1127
+ * @returns
1128
+ */
1129
+ read32() {
1130
+ const value = this.dataView.getUint32(this.bytePosition, true);
1131
+ this.shift(4);
1132
+ return value;
1133
+ }
1134
+ /**
1135
+ * Read U64 value from the buffer and shift cursor by 8.
1136
+ * @returns
1137
+ */
1138
+ read64() {
1139
+ const value1 = this.read32();
1140
+ const value2 = this.read32();
1141
+ const result = value2.toString(16) + value1.toString(16).padStart(8, "0");
1142
+ return BigInt("0x" + result).toString(10);
1143
+ }
1144
+ /**
1145
+ * Read U128 value from the buffer and shift cursor by 16.
1146
+ */
1147
+ read128() {
1148
+ const value1 = BigInt(this.read64());
1149
+ const value2 = BigInt(this.read64());
1150
+ const result = value2.toString(16) + value1.toString(16).padStart(16, "0");
1151
+ return BigInt("0x" + result).toString(10);
1152
+ }
1153
+ /**
1154
+ * Read U128 value from the buffer and shift cursor by 32.
1155
+ * @returns
1156
+ */
1157
+ read256() {
1158
+ const value1 = BigInt(this.read128());
1159
+ const value2 = BigInt(this.read128());
1160
+ const result = value2.toString(16) + value1.toString(16).padStart(32, "0");
1161
+ return BigInt("0x" + result).toString(10);
1162
+ }
1163
+ /**
1164
+ * Read `num` number of bytes from the buffer and shift cursor by `num`.
1165
+ * @param num Number of bytes to read.
1166
+ */
1167
+ readBytes(num) {
1168
+ const start = this.bytePosition + this.dataView.byteOffset;
1169
+ const value = new Uint8Array(this.dataView.buffer, start, num);
1170
+ this.shift(num);
1171
+ return value;
1172
+ }
1173
+ /**
1174
+ * Read ULEB value - an integer of varying size. Used for enum indexes and
1175
+ * vector lengths.
1176
+ * @returns {Number} The ULEB value.
1177
+ */
1178
+ readULEB() {
1179
+ const start = this.bytePosition + this.dataView.byteOffset;
1180
+ const buffer = new Uint8Array(this.dataView.buffer, start);
1181
+ const { value, length } = ulebDecode(buffer);
1182
+ this.shift(length);
1183
+ return value;
1184
+ }
1185
+ /**
1186
+ * Read a BCS vector: read a length and then apply function `cb` X times
1187
+ * where X is the length of the vector, defined as ULEB in BCS bytes.
1188
+ * @param cb Callback to process elements of vector.
1189
+ * @returns {Array<Any>} Array of the resulting values, returned by callback.
1190
+ */
1191
+ readVec(cb) {
1192
+ const length = this.readULEB();
1193
+ const result = [];
1194
+ for (let i = 0; i < length; i++) {
1195
+ result.push(cb(this, i, length));
1196
+ }
1197
+ return result;
1198
+ }
1199
+ };
1200
+
1201
+ // ../../node_modules/@mysten/bcs/dist/esm/utils.js
1202
+ function encodeStr(data, encoding) {
1203
+ switch (encoding) {
1204
+ case "base58":
1205
+ return toBase58(data);
1206
+ case "base64":
1207
+ return toBase64(data);
1208
+ case "hex":
1209
+ return toHex(data);
1210
+ default:
1211
+ throw new Error("Unsupported encoding, supported values are: base64, hex");
1212
+ }
1213
+ }
1214
+
1215
+ // ../../node_modules/@mysten/bcs/dist/esm/writer.js
1216
+ var BcsWriter = class {
1217
+ constructor({
1218
+ initialSize = 1024,
1219
+ maxSize = Infinity,
1220
+ allocateSize = 1024
1221
+ } = {}) {
1222
+ this.bytePosition = 0;
1223
+ this.size = initialSize;
1224
+ this.maxSize = maxSize;
1225
+ this.allocateSize = allocateSize;
1226
+ this.dataView = new DataView(new ArrayBuffer(initialSize));
1227
+ }
1228
+ ensureSizeOrGrow(bytes) {
1229
+ const requiredSize = this.bytePosition + bytes;
1230
+ if (requiredSize > this.size) {
1231
+ const nextSize = Math.min(this.maxSize, this.size + this.allocateSize);
1232
+ if (requiredSize > nextSize) {
1233
+ throw new Error(
1234
+ `Attempting to serialize to BCS, but buffer does not have enough size. Allocated size: ${this.size}, Max size: ${this.maxSize}, Required size: ${requiredSize}`
1235
+ );
1236
+ }
1237
+ this.size = nextSize;
1238
+ const nextBuffer = new ArrayBuffer(this.size);
1239
+ new Uint8Array(nextBuffer).set(new Uint8Array(this.dataView.buffer));
1240
+ this.dataView = new DataView(nextBuffer);
1241
+ }
1242
+ }
1243
+ /**
1244
+ * Shift current cursor position by `bytes`.
1245
+ *
1246
+ * @param {Number} bytes Number of bytes to
1247
+ * @returns {this} Self for possible chaining.
1248
+ */
1249
+ shift(bytes) {
1250
+ this.bytePosition += bytes;
1251
+ return this;
1252
+ }
1253
+ /**
1254
+ * Write a U8 value into a buffer and shift cursor position by 1.
1255
+ * @param {Number} value Value to write.
1256
+ * @returns {this}
1257
+ */
1258
+ write8(value) {
1259
+ this.ensureSizeOrGrow(1);
1260
+ this.dataView.setUint8(this.bytePosition, Number(value));
1261
+ return this.shift(1);
1262
+ }
1263
+ /**
1264
+ * Write a U16 value into a buffer and shift cursor position by 2.
1265
+ * @param {Number} value Value to write.
1266
+ * @returns {this}
1267
+ */
1268
+ write16(value) {
1269
+ this.ensureSizeOrGrow(2);
1270
+ this.dataView.setUint16(this.bytePosition, Number(value), true);
1271
+ return this.shift(2);
1272
+ }
1273
+ /**
1274
+ * Write a U32 value into a buffer and shift cursor position by 4.
1275
+ * @param {Number} value Value to write.
1276
+ * @returns {this}
1277
+ */
1278
+ write32(value) {
1279
+ this.ensureSizeOrGrow(4);
1280
+ this.dataView.setUint32(this.bytePosition, Number(value), true);
1281
+ return this.shift(4);
1282
+ }
1283
+ /**
1284
+ * Write a U64 value into a buffer and shift cursor position by 8.
1285
+ * @param {bigint} value Value to write.
1286
+ * @returns {this}
1287
+ */
1288
+ write64(value) {
1289
+ toLittleEndian(BigInt(value), 8).forEach((el) => this.write8(el));
1290
+ return this;
1291
+ }
1292
+ /**
1293
+ * Write a U128 value into a buffer and shift cursor position by 16.
1294
+ *
1295
+ * @param {bigint} value Value to write.
1296
+ * @returns {this}
1297
+ */
1298
+ write128(value) {
1299
+ toLittleEndian(BigInt(value), 16).forEach((el) => this.write8(el));
1300
+ return this;
1301
+ }
1302
+ /**
1303
+ * Write a U256 value into a buffer and shift cursor position by 16.
1304
+ *
1305
+ * @param {bigint} value Value to write.
1306
+ * @returns {this}
1307
+ */
1308
+ write256(value) {
1309
+ toLittleEndian(BigInt(value), 32).forEach((el) => this.write8(el));
1310
+ return this;
1311
+ }
1312
+ /**
1313
+ * Write a ULEB value into a buffer and shift cursor position by number of bytes
1314
+ * written.
1315
+ * @param {Number} value Value to write.
1316
+ * @returns {this}
1317
+ */
1318
+ writeULEB(value) {
1319
+ ulebEncode(value).forEach((el) => this.write8(el));
1320
+ return this;
1321
+ }
1322
+ /**
1323
+ * Write a vector into a buffer by first writing the vector length and then calling
1324
+ * a callback on each passed value.
1325
+ *
1326
+ * @param {Array<Any>} vector Array of elements to write.
1327
+ * @param {WriteVecCb} cb Callback to call on each element of the vector.
1328
+ * @returns {this}
1329
+ */
1330
+ writeVec(vector2, cb) {
1331
+ this.writeULEB(vector2.length);
1332
+ Array.from(vector2).forEach((el, i) => cb(this, el, i, vector2.length));
1333
+ return this;
1334
+ }
1335
+ /**
1336
+ * Adds support for iterations over the object.
1337
+ * @returns {Uint8Array}
1338
+ */
1339
+ *[Symbol.iterator]() {
1340
+ for (let i = 0; i < this.bytePosition; i++) {
1341
+ yield this.dataView.getUint8(i);
1342
+ }
1343
+ return this.toBytes();
1344
+ }
1345
+ /**
1346
+ * Get underlying buffer taking only value bytes (in case initial buffer size was bigger).
1347
+ * @returns {Uint8Array} Resulting bcs.
1348
+ */
1349
+ toBytes() {
1350
+ return new Uint8Array(this.dataView.buffer.slice(0, this.bytePosition));
1351
+ }
1352
+ /**
1353
+ * Represent data as 'hex' or 'base64'
1354
+ * @param encoding Encoding to use: 'base64' or 'hex'
1355
+ */
1356
+ toString(encoding) {
1357
+ return encodeStr(this.toBytes(), encoding);
1358
+ }
1359
+ };
1360
+ function toLittleEndian(bigint, size) {
1361
+ const result = new Uint8Array(size);
1362
+ let i = 0;
1363
+ while (bigint > 0) {
1364
+ result[i] = Number(bigint % BigInt(256));
1365
+ bigint = bigint / BigInt(256);
1366
+ i += 1;
1367
+ }
1368
+ return result;
483
1369
  }
484
1370
 
1371
+ // ../../node_modules/@mysten/bcs/dist/esm/bcs-type.js
1372
+ var __typeError = (msg) => {
1373
+ throw TypeError(msg);
1374
+ };
1375
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
1376
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1377
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1378
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
1379
+ var _write;
1380
+ var _serialize;
1381
+ var _schema;
1382
+ var _bytes;
1383
+ var _BcsType = class _BcsType2 {
1384
+ constructor(options) {
1385
+ __privateAdd(this, _write);
1386
+ __privateAdd(this, _serialize);
1387
+ this.name = options.name;
1388
+ this.read = options.read;
1389
+ this.serializedSize = options.serializedSize ?? (() => null);
1390
+ __privateSet(this, _write, options.write);
1391
+ __privateSet(this, _serialize, options.serialize ?? ((value, options2) => {
1392
+ const writer = new BcsWriter({
1393
+ initialSize: this.serializedSize(value) ?? void 0,
1394
+ ...options2
1395
+ });
1396
+ __privateGet(this, _write).call(this, value, writer);
1397
+ return writer.toBytes();
1398
+ }));
1399
+ this.validate = options.validate ?? (() => {
1400
+ });
1401
+ }
1402
+ write(value, writer) {
1403
+ this.validate(value);
1404
+ __privateGet(this, _write).call(this, value, writer);
1405
+ }
1406
+ serialize(value, options) {
1407
+ this.validate(value);
1408
+ return new SerializedBcs(this, __privateGet(this, _serialize).call(this, value, options));
1409
+ }
1410
+ parse(bytes) {
1411
+ const reader = new BcsReader(bytes);
1412
+ return this.read(reader);
1413
+ }
1414
+ fromHex(hex) {
1415
+ return this.parse(fromHex(hex));
1416
+ }
1417
+ fromBase58(b64) {
1418
+ return this.parse(fromBase58(b64));
1419
+ }
1420
+ fromBase64(b64) {
1421
+ return this.parse(fromBase64(b64));
1422
+ }
1423
+ transform({
1424
+ name: name2,
1425
+ input,
1426
+ output,
1427
+ validate
1428
+ }) {
1429
+ return new _BcsType2({
1430
+ name: name2 ?? this.name,
1431
+ read: (reader) => output ? output(this.read(reader)) : this.read(reader),
1432
+ write: (value, writer) => __privateGet(this, _write).call(this, input ? input(value) : value, writer),
1433
+ serializedSize: (value) => this.serializedSize(input ? input(value) : value),
1434
+ serialize: (value, options) => __privateGet(this, _serialize).call(this, input ? input(value) : value, options),
1435
+ validate: (value) => {
1436
+ validate?.(value);
1437
+ this.validate(input ? input(value) : value);
1438
+ }
1439
+ });
1440
+ }
1441
+ };
1442
+ _write = /* @__PURE__ */ new WeakMap();
1443
+ _serialize = /* @__PURE__ */ new WeakMap();
1444
+ var BcsType = _BcsType;
1445
+ var SERIALIZED_BCS_BRAND = Symbol.for("@mysten/serialized-bcs");
1446
+ var SerializedBcs = class {
1447
+ constructor(schema, bytes) {
1448
+ __privateAdd(this, _schema);
1449
+ __privateAdd(this, _bytes);
1450
+ __privateSet(this, _schema, schema);
1451
+ __privateSet(this, _bytes, bytes);
1452
+ }
1453
+ // Used to brand SerializedBcs so that they can be identified, even between multiple copies
1454
+ // of the @mysten/bcs package are installed
1455
+ get [SERIALIZED_BCS_BRAND]() {
1456
+ return true;
1457
+ }
1458
+ toBytes() {
1459
+ return __privateGet(this, _bytes);
1460
+ }
1461
+ toHex() {
1462
+ return toHex(__privateGet(this, _bytes));
1463
+ }
1464
+ toBase64() {
1465
+ return toBase64(__privateGet(this, _bytes));
1466
+ }
1467
+ toBase58() {
1468
+ return toBase58(__privateGet(this, _bytes));
1469
+ }
1470
+ parse() {
1471
+ return __privateGet(this, _schema).parse(__privateGet(this, _bytes));
1472
+ }
1473
+ };
1474
+ _schema = /* @__PURE__ */ new WeakMap();
1475
+ _bytes = /* @__PURE__ */ new WeakMap();
1476
+ function fixedSizeBcsType({
1477
+ size,
1478
+ ...options
1479
+ }) {
1480
+ return new BcsType({
1481
+ ...options,
1482
+ serializedSize: () => size
1483
+ });
1484
+ }
1485
+ function uIntBcsType({
1486
+ readMethod,
1487
+ writeMethod,
1488
+ ...options
1489
+ }) {
1490
+ return fixedSizeBcsType({
1491
+ ...options,
1492
+ read: (reader) => reader[readMethod](),
1493
+ write: (value, writer) => writer[writeMethod](value),
1494
+ validate: (value) => {
1495
+ if (value < 0 || value > options.maxValue) {
1496
+ throw new TypeError(
1497
+ `Invalid ${options.name} value: ${value}. Expected value in range 0-${options.maxValue}`
1498
+ );
1499
+ }
1500
+ options.validate?.(value);
1501
+ }
1502
+ });
1503
+ }
1504
+ function bigUIntBcsType({
1505
+ readMethod,
1506
+ writeMethod,
1507
+ ...options
1508
+ }) {
1509
+ return fixedSizeBcsType({
1510
+ ...options,
1511
+ read: (reader) => reader[readMethod](),
1512
+ write: (value, writer) => writer[writeMethod](BigInt(value)),
1513
+ validate: (val) => {
1514
+ const value = BigInt(val);
1515
+ if (value < 0 || value > options.maxValue) {
1516
+ throw new TypeError(
1517
+ `Invalid ${options.name} value: ${value}. Expected value in range 0-${options.maxValue}`
1518
+ );
1519
+ }
1520
+ options.validate?.(value);
1521
+ }
1522
+ });
1523
+ }
1524
+ function dynamicSizeBcsType({
1525
+ serialize,
1526
+ ...options
1527
+ }) {
1528
+ const type = new BcsType({
1529
+ ...options,
1530
+ serialize,
1531
+ write: (value, writer) => {
1532
+ for (const byte of type.serialize(value).toBytes()) {
1533
+ writer.write8(byte);
1534
+ }
1535
+ }
1536
+ });
1537
+ return type;
1538
+ }
1539
+ function stringLikeBcsType({
1540
+ toBytes: toBytes2,
1541
+ fromBytes,
1542
+ ...options
1543
+ }) {
1544
+ return new BcsType({
1545
+ ...options,
1546
+ read: (reader) => {
1547
+ const length = reader.readULEB();
1548
+ const bytes = reader.readBytes(length);
1549
+ return fromBytes(bytes);
1550
+ },
1551
+ write: (hex, writer) => {
1552
+ const bytes = toBytes2(hex);
1553
+ writer.writeULEB(bytes.length);
1554
+ for (let i = 0; i < bytes.length; i++) {
1555
+ writer.write8(bytes[i]);
1556
+ }
1557
+ },
1558
+ serialize: (value) => {
1559
+ const bytes = toBytes2(value);
1560
+ const size = ulebEncode(bytes.length);
1561
+ const result = new Uint8Array(size.length + bytes.length);
1562
+ result.set(size, 0);
1563
+ result.set(bytes, size.length);
1564
+ return result;
1565
+ },
1566
+ validate: (value) => {
1567
+ if (typeof value !== "string") {
1568
+ throw new TypeError(`Invalid ${options.name} value: ${value}. Expected string`);
1569
+ }
1570
+ options.validate?.(value);
1571
+ }
1572
+ });
1573
+ }
1574
+ function lazyBcsType(cb) {
1575
+ let lazyType = null;
1576
+ function getType() {
1577
+ if (!lazyType) {
1578
+ lazyType = cb();
1579
+ }
1580
+ return lazyType;
1581
+ }
1582
+ return new BcsType({
1583
+ name: "lazy",
1584
+ read: (data) => getType().read(data),
1585
+ serializedSize: (value) => getType().serializedSize(value),
1586
+ write: (value, writer) => getType().write(value, writer),
1587
+ serialize: (value, options) => getType().serialize(value, options).toBytes()
1588
+ });
1589
+ }
1590
+ var BcsStruct = class extends BcsType {
1591
+ constructor({ name: name2, fields, ...options }) {
1592
+ const canonicalOrder = Object.entries(fields);
1593
+ super({
1594
+ name: name2,
1595
+ serializedSize: (values) => {
1596
+ let total = 0;
1597
+ for (const [field, type] of canonicalOrder) {
1598
+ const size = type.serializedSize(values[field]);
1599
+ if (size == null) {
1600
+ return null;
1601
+ }
1602
+ total += size;
1603
+ }
1604
+ return total;
1605
+ },
1606
+ read: (reader) => {
1607
+ const result = {};
1608
+ for (const [field, type] of canonicalOrder) {
1609
+ result[field] = type.read(reader);
1610
+ }
1611
+ return result;
1612
+ },
1613
+ write: (value, writer) => {
1614
+ for (const [field, type] of canonicalOrder) {
1615
+ type.write(value[field], writer);
1616
+ }
1617
+ },
1618
+ ...options,
1619
+ validate: (value) => {
1620
+ options?.validate?.(value);
1621
+ if (typeof value !== "object" || value == null) {
1622
+ throw new TypeError(`Expected object, found ${typeof value}`);
1623
+ }
1624
+ }
1625
+ });
1626
+ }
1627
+ };
1628
+ var BcsEnum = class extends BcsType {
1629
+ constructor({ fields, ...options }) {
1630
+ const canonicalOrder = Object.entries(fields);
1631
+ super({
1632
+ read: (reader) => {
1633
+ const index = reader.readULEB();
1634
+ const enumEntry = canonicalOrder[index];
1635
+ if (!enumEntry) {
1636
+ throw new TypeError(`Unknown value ${index} for enum ${name}`);
1637
+ }
1638
+ const [kind, type] = enumEntry;
1639
+ return {
1640
+ [kind]: type?.read(reader) ?? true,
1641
+ $kind: kind
1642
+ };
1643
+ },
1644
+ write: (value, writer) => {
1645
+ const [name2, val] = Object.entries(value).filter(
1646
+ ([name3]) => Object.hasOwn(fields, name3)
1647
+ )[0];
1648
+ for (let i = 0; i < canonicalOrder.length; i++) {
1649
+ const [optionName, optionType] = canonicalOrder[i];
1650
+ if (optionName === name2) {
1651
+ writer.writeULEB(i);
1652
+ optionType?.write(val, writer);
1653
+ return;
1654
+ }
1655
+ }
1656
+ },
1657
+ ...options,
1658
+ validate: (value) => {
1659
+ options?.validate?.(value);
1660
+ if (typeof value !== "object" || value == null) {
1661
+ throw new TypeError(`Expected object, found ${typeof value}`);
1662
+ }
1663
+ const keys = Object.keys(value).filter(
1664
+ (k) => value[k] !== void 0 && Object.hasOwn(fields, k)
1665
+ );
1666
+ if (keys.length !== 1) {
1667
+ throw new TypeError(
1668
+ `Expected object with one key, but found ${keys.length} for type ${name}}`
1669
+ );
1670
+ }
1671
+ const [variant] = keys;
1672
+ if (!Object.hasOwn(fields, variant)) {
1673
+ throw new TypeError(`Invalid enum variant ${variant}`);
1674
+ }
1675
+ }
1676
+ });
1677
+ }
1678
+ };
1679
+ var BcsTuple = class extends BcsType {
1680
+ constructor({ fields, name: name2, ...options }) {
1681
+ super({
1682
+ name: name2 ?? `(${fields.map((t) => t.name).join(", ")})`,
1683
+ serializedSize: (values) => {
1684
+ let total = 0;
1685
+ for (let i = 0; i < fields.length; i++) {
1686
+ const size = fields[i].serializedSize(values[i]);
1687
+ if (size == null) {
1688
+ return null;
1689
+ }
1690
+ total += size;
1691
+ }
1692
+ return total;
1693
+ },
1694
+ read: (reader) => {
1695
+ const result = [];
1696
+ for (const field of fields) {
1697
+ result.push(field.read(reader));
1698
+ }
1699
+ return result;
1700
+ },
1701
+ write: (value, writer) => {
1702
+ for (let i = 0; i < fields.length; i++) {
1703
+ fields[i].write(value[i], writer);
1704
+ }
1705
+ },
1706
+ ...options,
1707
+ validate: (value) => {
1708
+ options?.validate?.(value);
1709
+ if (!Array.isArray(value)) {
1710
+ throw new TypeError(`Expected array, found ${typeof value}`);
1711
+ }
1712
+ if (value.length !== fields.length) {
1713
+ throw new TypeError(`Expected array of length ${fields.length}, found ${value.length}`);
1714
+ }
1715
+ }
1716
+ });
1717
+ }
1718
+ };
1719
+
1720
+ // ../../node_modules/@mysten/bcs/dist/esm/bcs.js
1721
+ function fixedArray(size, type, options) {
1722
+ return new BcsType({
1723
+ read: (reader) => {
1724
+ const result = new Array(size);
1725
+ for (let i = 0; i < size; i++) {
1726
+ result[i] = type.read(reader);
1727
+ }
1728
+ return result;
1729
+ },
1730
+ write: (value, writer) => {
1731
+ for (const item of value) {
1732
+ type.write(item, writer);
1733
+ }
1734
+ },
1735
+ ...options,
1736
+ name: options?.name ?? `${type.name}[${size}]`,
1737
+ validate: (value) => {
1738
+ options?.validate?.(value);
1739
+ if (!value || typeof value !== "object" || !("length" in value)) {
1740
+ throw new TypeError(`Expected array, found ${typeof value}`);
1741
+ }
1742
+ if (value.length !== size) {
1743
+ throw new TypeError(`Expected array of length ${size}, found ${value.length}`);
1744
+ }
1745
+ }
1746
+ });
1747
+ }
1748
+ function option(type) {
1749
+ return bcs.enum(`Option<${type.name}>`, {
1750
+ None: null,
1751
+ Some: type
1752
+ }).transform({
1753
+ input: (value) => {
1754
+ if (value == null) {
1755
+ return { None: true };
1756
+ }
1757
+ return { Some: value };
1758
+ },
1759
+ output: (value) => {
1760
+ if (value.$kind === "Some") {
1761
+ return value.Some;
1762
+ }
1763
+ return null;
1764
+ }
1765
+ });
1766
+ }
1767
+ function vector(type, options) {
1768
+ return new BcsType({
1769
+ read: (reader) => {
1770
+ const length = reader.readULEB();
1771
+ const result = new Array(length);
1772
+ for (let i = 0; i < length; i++) {
1773
+ result[i] = type.read(reader);
1774
+ }
1775
+ return result;
1776
+ },
1777
+ write: (value, writer) => {
1778
+ writer.writeULEB(value.length);
1779
+ for (const item of value) {
1780
+ type.write(item, writer);
1781
+ }
1782
+ },
1783
+ ...options,
1784
+ name: options?.name ?? `vector<${type.name}>`,
1785
+ validate: (value) => {
1786
+ options?.validate?.(value);
1787
+ if (!value || typeof value !== "object" || !("length" in value)) {
1788
+ throw new TypeError(`Expected array, found ${typeof value}`);
1789
+ }
1790
+ }
1791
+ });
1792
+ }
1793
+ function map(keyType, valueType) {
1794
+ return bcs.vector(bcs.tuple([keyType, valueType])).transform({
1795
+ name: `Map<${keyType.name}, ${valueType.name}>`,
1796
+ input: (value) => {
1797
+ return [...value.entries()];
1798
+ },
1799
+ output: (value) => {
1800
+ const result = /* @__PURE__ */ new Map();
1801
+ for (const [key, val] of value) {
1802
+ result.set(key, val);
1803
+ }
1804
+ return result;
1805
+ }
1806
+ });
1807
+ }
1808
+ var bcs = {
1809
+ /**
1810
+ * Creates a BcsType that can be used to read and write an 8-bit unsigned integer.
1811
+ * @example
1812
+ * bcs.u8().serialize(255).toBytes() // Uint8Array [ 255 ]
1813
+ */
1814
+ u8(options) {
1815
+ return uIntBcsType({
1816
+ readMethod: "read8",
1817
+ writeMethod: "write8",
1818
+ size: 1,
1819
+ maxValue: 2 ** 8 - 1,
1820
+ ...options,
1821
+ name: options?.name ?? "u8"
1822
+ });
1823
+ },
1824
+ /**
1825
+ * Creates a BcsType that can be used to read and write a 16-bit unsigned integer.
1826
+ * @example
1827
+ * bcs.u16().serialize(65535).toBytes() // Uint8Array [ 255, 255 ]
1828
+ */
1829
+ u16(options) {
1830
+ return uIntBcsType({
1831
+ readMethod: "read16",
1832
+ writeMethod: "write16",
1833
+ size: 2,
1834
+ maxValue: 2 ** 16 - 1,
1835
+ ...options,
1836
+ name: options?.name ?? "u16"
1837
+ });
1838
+ },
1839
+ /**
1840
+ * Creates a BcsType that can be used to read and write a 32-bit unsigned integer.
1841
+ * @example
1842
+ * bcs.u32().serialize(4294967295).toBytes() // Uint8Array [ 255, 255, 255, 255 ]
1843
+ */
1844
+ u32(options) {
1845
+ return uIntBcsType({
1846
+ readMethod: "read32",
1847
+ writeMethod: "write32",
1848
+ size: 4,
1849
+ maxValue: 2 ** 32 - 1,
1850
+ ...options,
1851
+ name: options?.name ?? "u32"
1852
+ });
1853
+ },
1854
+ /**
1855
+ * Creates a BcsType that can be used to read and write a 64-bit unsigned integer.
1856
+ * @example
1857
+ * bcs.u64().serialize(1).toBytes() // Uint8Array [ 1, 0, 0, 0, 0, 0, 0, 0 ]
1858
+ */
1859
+ u64(options) {
1860
+ return bigUIntBcsType({
1861
+ readMethod: "read64",
1862
+ writeMethod: "write64",
1863
+ size: 8,
1864
+ maxValue: 2n ** 64n - 1n,
1865
+ ...options,
1866
+ name: options?.name ?? "u64"
1867
+ });
1868
+ },
1869
+ /**
1870
+ * Creates a BcsType that can be used to read and write a 128-bit unsigned integer.
1871
+ * @example
1872
+ * bcs.u128().serialize(1).toBytes() // Uint8Array [ 1, ..., 0 ]
1873
+ */
1874
+ u128(options) {
1875
+ return bigUIntBcsType({
1876
+ readMethod: "read128",
1877
+ writeMethod: "write128",
1878
+ size: 16,
1879
+ maxValue: 2n ** 128n - 1n,
1880
+ ...options,
1881
+ name: options?.name ?? "u128"
1882
+ });
1883
+ },
1884
+ /**
1885
+ * Creates a BcsType that can be used to read and write a 256-bit unsigned integer.
1886
+ * @example
1887
+ * bcs.u256().serialize(1).toBytes() // Uint8Array [ 1, ..., 0 ]
1888
+ */
1889
+ u256(options) {
1890
+ return bigUIntBcsType({
1891
+ readMethod: "read256",
1892
+ writeMethod: "write256",
1893
+ size: 32,
1894
+ maxValue: 2n ** 256n - 1n,
1895
+ ...options,
1896
+ name: options?.name ?? "u256"
1897
+ });
1898
+ },
1899
+ /**
1900
+ * Creates a BcsType that can be used to read and write boolean values.
1901
+ * @example
1902
+ * bcs.bool().serialize(true).toBytes() // Uint8Array [ 1 ]
1903
+ */
1904
+ bool(options) {
1905
+ return fixedSizeBcsType({
1906
+ size: 1,
1907
+ read: (reader) => reader.read8() === 1,
1908
+ write: (value, writer) => writer.write8(value ? 1 : 0),
1909
+ ...options,
1910
+ name: options?.name ?? "bool",
1911
+ validate: (value) => {
1912
+ options?.validate?.(value);
1913
+ if (typeof value !== "boolean") {
1914
+ throw new TypeError(`Expected boolean, found ${typeof value}`);
1915
+ }
1916
+ }
1917
+ });
1918
+ },
1919
+ /**
1920
+ * Creates a BcsType that can be used to read and write unsigned LEB encoded integers
1921
+ * @example
1922
+ *
1923
+ */
1924
+ uleb128(options) {
1925
+ return dynamicSizeBcsType({
1926
+ read: (reader) => reader.readULEB(),
1927
+ serialize: (value) => {
1928
+ return Uint8Array.from(ulebEncode(value));
1929
+ },
1930
+ ...options,
1931
+ name: options?.name ?? "uleb128"
1932
+ });
1933
+ },
1934
+ /**
1935
+ * Creates a BcsType representing a fixed length byte array
1936
+ * @param size The number of bytes this types represents
1937
+ * @example
1938
+ * bcs.bytes(3).serialize(new Uint8Array([1, 2, 3])).toBytes() // Uint8Array [1, 2, 3]
1939
+ */
1940
+ bytes(size, options) {
1941
+ return fixedSizeBcsType({
1942
+ size,
1943
+ read: (reader) => reader.readBytes(size),
1944
+ write: (value, writer) => {
1945
+ const array = new Uint8Array(value);
1946
+ for (let i = 0; i < size; i++) {
1947
+ writer.write8(array[i] ?? 0);
1948
+ }
1949
+ },
1950
+ ...options,
1951
+ name: options?.name ?? `bytes[${size}]`,
1952
+ validate: (value) => {
1953
+ options?.validate?.(value);
1954
+ if (!value || typeof value !== "object" || !("length" in value)) {
1955
+ throw new TypeError(`Expected array, found ${typeof value}`);
1956
+ }
1957
+ if (value.length !== size) {
1958
+ throw new TypeError(`Expected array of length ${size}, found ${value.length}`);
1959
+ }
1960
+ }
1961
+ });
1962
+ },
1963
+ /**
1964
+ * Creates a BcsType representing a variable length byte array
1965
+ *
1966
+ * @example
1967
+ * bcs.byteVector().serialize([1, 2, 3]).toBytes() // Uint8Array [3, 1, 2, 3]
1968
+ */
1969
+ byteVector(options) {
1970
+ return new BcsType({
1971
+ read: (reader) => {
1972
+ const length = reader.readULEB();
1973
+ return reader.readBytes(length);
1974
+ },
1975
+ write: (value, writer) => {
1976
+ const array = new Uint8Array(value);
1977
+ writer.writeULEB(array.length);
1978
+ for (let i = 0; i < array.length; i++) {
1979
+ writer.write8(array[i] ?? 0);
1980
+ }
1981
+ },
1982
+ ...options,
1983
+ name: options?.name ?? "vector<u8>",
1984
+ serializedSize: (value) => {
1985
+ const length = "length" in value ? value.length : null;
1986
+ return length == null ? null : ulebEncode(length).length + length;
1987
+ },
1988
+ validate: (value) => {
1989
+ options?.validate?.(value);
1990
+ if (!value || typeof value !== "object" || !("length" in value)) {
1991
+ throw new TypeError(`Expected array, found ${typeof value}`);
1992
+ }
1993
+ }
1994
+ });
1995
+ },
1996
+ /**
1997
+ * Creates a BcsType that can ser/de string values. Strings will be UTF-8 encoded
1998
+ * @example
1999
+ * bcs.string().serialize('a').toBytes() // Uint8Array [ 1, 97 ]
2000
+ */
2001
+ string(options) {
2002
+ return stringLikeBcsType({
2003
+ toBytes: (value) => new TextEncoder().encode(value),
2004
+ fromBytes: (bytes) => new TextDecoder().decode(bytes),
2005
+ ...options,
2006
+ name: options?.name ?? "string"
2007
+ });
2008
+ },
2009
+ /**
2010
+ * Creates a BcsType that represents a fixed length array of a given type
2011
+ * @param size The number of elements in the array
2012
+ * @param type The BcsType of each element in the array
2013
+ * @example
2014
+ * bcs.fixedArray(3, bcs.u8()).serialize([1, 2, 3]).toBytes() // Uint8Array [ 1, 2, 3 ]
2015
+ */
2016
+ fixedArray,
2017
+ /**
2018
+ * Creates a BcsType representing an optional value
2019
+ * @param type The BcsType of the optional value
2020
+ * @example
2021
+ * bcs.option(bcs.u8()).serialize(null).toBytes() // Uint8Array [ 0 ]
2022
+ * bcs.option(bcs.u8()).serialize(1).toBytes() // Uint8Array [ 1, 1 ]
2023
+ */
2024
+ option,
2025
+ /**
2026
+ * Creates a BcsType representing a variable length vector of a given type
2027
+ * @param type The BcsType of each element in the vector
2028
+ *
2029
+ * @example
2030
+ * bcs.vector(bcs.u8()).toBytes([1, 2, 3]) // Uint8Array [ 3, 1, 2, 3 ]
2031
+ */
2032
+ vector,
2033
+ /**
2034
+ * Creates a BcsType representing a tuple of a given set of types
2035
+ * @param types The BcsTypes for each element in the tuple
2036
+ *
2037
+ * @example
2038
+ * const tuple = bcs.tuple([bcs.u8(), bcs.string(), bcs.bool()])
2039
+ * tuple.serialize([1, 'a', true]).toBytes() // Uint8Array [ 1, 1, 97, 1 ]
2040
+ */
2041
+ tuple(fields, options) {
2042
+ return new BcsTuple({
2043
+ fields,
2044
+ ...options
2045
+ });
2046
+ },
2047
+ /**
2048
+ * Creates a BcsType representing a struct of a given set of fields
2049
+ * @param name The name of the struct
2050
+ * @param fields The fields of the struct. The order of the fields affects how data is serialized and deserialized
2051
+ *
2052
+ * @example
2053
+ * const struct = bcs.struct('MyStruct', {
2054
+ * a: bcs.u8(),
2055
+ * b: bcs.string(),
2056
+ * })
2057
+ * struct.serialize({ a: 1, b: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
2058
+ */
2059
+ struct(name2, fields, options) {
2060
+ return new BcsStruct({
2061
+ name: name2,
2062
+ fields,
2063
+ ...options
2064
+ });
2065
+ },
2066
+ /**
2067
+ * Creates a BcsType representing an enum of a given set of options
2068
+ * @param name The name of the enum
2069
+ * @param values The values of the enum. The order of the values affects how data is serialized and deserialized.
2070
+ * null can be used to represent a variant with no data.
2071
+ *
2072
+ * @example
2073
+ * const enum = bcs.enum('MyEnum', {
2074
+ * A: bcs.u8(),
2075
+ * B: bcs.string(),
2076
+ * C: null,
2077
+ * })
2078
+ * enum.serialize({ A: 1 }).toBytes() // Uint8Array [ 0, 1 ]
2079
+ * enum.serialize({ B: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
2080
+ * enum.serialize({ C: true }).toBytes() // Uint8Array [ 2 ]
2081
+ */
2082
+ enum(name2, fields, options) {
2083
+ return new BcsEnum({
2084
+ name: name2,
2085
+ fields,
2086
+ ...options
2087
+ });
2088
+ },
2089
+ /**
2090
+ * Creates a BcsType representing a map of a given key and value type
2091
+ * @param keyType The BcsType of the key
2092
+ * @param valueType The BcsType of the value
2093
+ * @example
2094
+ * const map = bcs.map(bcs.u8(), bcs.string())
2095
+ * map.serialize(new Map([[2, 'a']])).toBytes() // Uint8Array [ 1, 2, 1, 97 ]
2096
+ */
2097
+ map,
2098
+ /**
2099
+ * Creates a BcsType that wraps another BcsType which is lazily evaluated. This is useful for creating recursive types.
2100
+ * @param cb A callback that returns the BcsType
2101
+ */
2102
+ lazy(cb) {
2103
+ return lazyBcsType(cb);
2104
+ }
2105
+ };
2106
+
485
2107
  // src/sdk/types.ts
486
- import { bcs as bcs2 } from "@mysten/bcs";
487
2108
  BigInt.prototype.toJSON = function() {
488
2109
  return Number(this);
489
2110
  };
490
- var Bytes32 = bcs2.fixedArray(32, bcs2.u8());
491
- var Bytes64 = bcs2.fixedArray(64, bcs2.u8());
2111
+ var Bytes32 = bcs.fixedArray(32, bcs.u8());
2112
+ var Bytes64 = bcs.fixedArray(64, bcs.u8());
492
2113
  var PublicKey = Bytes32;
493
2114
  var Signature = Bytes64;
494
- var Address = bcs2.enum("Address", {
2115
+ var Address = bcs.enum("Address", {
495
2116
  External: PublicKey,
496
2117
  FastSet: PublicKey
497
2118
  });
498
- var Amount = bcs2.u256().transform({
2119
+ var Amount = bcs.u256().transform({
499
2120
  // CAUTION: When we build a transaction object, we must use a hex encoded string because the
500
2121
  // validator expects amounts to be in hex. However, bcs.u256() by default expects a decimal
501
2122
  // string. Therefore, we must transform the input amount from hex to decimal here.
502
2123
  input: (val) => hexToDecimal(val.toString()),
503
2124
  output: (value) => value
504
2125
  });
505
- var Balance = bcs2.string().transform({
2126
+ var Balance = bcs.string().transform({
506
2127
  input: (val) => val,
507
2128
  output: (value) => value
508
2129
  });
509
- var UserData = bcs2.option(Bytes32);
510
- var Nonce = bcs2.u64();
511
- var Quorum = bcs2.u64();
2130
+ var UserData = bcs.option(Bytes32);
2131
+ var Nonce = bcs.u64();
2132
+ var Quorum = bcs.u64();
512
2133
  var TokenId = Bytes32;
513
- var Transfer = bcs2.struct("Transfer", {
2134
+ var Transfer = bcs.struct("Transfer", {
514
2135
  amount: Amount,
515
2136
  user_data: UserData
516
2137
  });
517
- var TokenTransfer = bcs2.struct("TokenTransfer", {
2138
+ var TokenTransfer = bcs.struct("TokenTransfer", {
518
2139
  token_id: TokenId,
519
2140
  amount: Amount,
520
2141
  user_data: UserData
521
2142
  });
522
- var TokenCreation = bcs2.struct("TokenCreation", {
523
- token_name: bcs2.string(),
524
- decimals: bcs2.u8(),
2143
+ var TokenCreation = bcs.struct("TokenCreation", {
2144
+ token_name: bcs.string(),
2145
+ decimals: bcs.u8(),
525
2146
  initial_amount: Amount,
526
- mints: bcs2.vector(PublicKey),
2147
+ mints: bcs.vector(PublicKey),
527
2148
  user_data: UserData
528
2149
  });
529
- var AddressChange = bcs2.enum("AddressChange", {
2150
+ var AddressChange = bcs.enum("AddressChange", {
530
2151
  Add: PublicKey,
531
2152
  Remove: PublicKey
532
2153
  });
533
- var TokenManagement = bcs2.struct("TokenManagement", {
2154
+ var TokenManagement = bcs.struct("TokenManagement", {
534
2155
  token_id: TokenId,
535
2156
  update_id: Nonce,
536
- new_admin: bcs2.option(PublicKey),
537
- mints: bcs2.vector(bcs2.tuple([AddressChange, PublicKey])),
2157
+ new_admin: bcs.option(PublicKey),
2158
+ mints: bcs.vector(bcs.tuple([AddressChange, PublicKey])),
538
2159
  user_data: UserData
539
2160
  });
540
- var Mint = bcs2.struct("Mint", {
2161
+ var Mint = bcs.struct("Mint", {
541
2162
  token_id: TokenId,
542
2163
  amount: Amount
543
2164
  });
544
- var ClaimData = bcs2.vector(bcs2.u8());
545
- var ExternalClaimBody = bcs2.struct("ExternalClaimBody", {
546
- verifier_committee: bcs2.vector(PublicKey),
2165
+ var ClaimData = bcs.vector(bcs.u8());
2166
+ var ExternalClaimBody = bcs.struct("ExternalClaimBody", {
2167
+ verifier_committee: bcs.vector(PublicKey),
547
2168
  verifier_quorum: Quorum,
548
2169
  claim_data: ClaimData
549
2170
  });
550
- var ExternalClaim = bcs2.struct("ExternalClaim", {
2171
+ var ExternalClaim = bcs.struct("ExternalClaim", {
551
2172
  claim: ExternalClaimBody,
552
- signatures: bcs2.vector(bcs2.tuple([PublicKey, Signature]))
2173
+ signatures: bcs.vector(bcs.tuple([PublicKey, Signature]))
553
2174
  });
554
- var ClaimType = bcs2.enum("ClaimType", {
2175
+ var ClaimType = bcs.enum("ClaimType", {
555
2176
  Transfer,
556
2177
  TokenTransfer,
557
2178
  TokenCreation,
@@ -559,26 +2180,26 @@ var ClaimType = bcs2.enum("ClaimType", {
559
2180
  Mint,
560
2181
  ExternalClaim
561
2182
  });
562
- var Transaction = bcs2.struct("Transaction", {
2183
+ var Transaction = bcs.struct("Transaction", {
563
2184
  sender: PublicKey,
564
2185
  recipient: Address,
565
2186
  nonce: Nonce,
566
- timestamp_nanos: bcs2.u128(),
2187
+ timestamp_nanos: bcs.u128(),
567
2188
  claim: ClaimType
568
2189
  });
569
- var SubmitTransactionResponse = bcs2.struct("SubmitTransactionResponse", {
2190
+ var SubmitTransactionResponse = bcs.struct("SubmitTransactionResponse", {
570
2191
  validator: PublicKey,
571
2192
  signature: Signature,
572
2193
  next_nonce: Nonce,
573
- transaction_hash: bcs2.vector(bcs2.u8())
2194
+ transaction_hash: bcs.vector(bcs.u8())
574
2195
  });
575
- var TransactionEnvelope = bcs2.struct("TransactionEnvelope", {
2196
+ var TransactionEnvelope = bcs.struct("TransactionEnvelope", {
576
2197
  transaction: Transaction,
577
2198
  signature: Signature
578
2199
  });
579
- var TransactionCertificate = bcs2.struct("TransactionCertificate", {
2200
+ var TransactionCertificate = bcs.struct("TransactionCertificate", {
580
2201
  envelope: TransactionEnvelope,
581
- signatures: bcs2.vector(bcs2.tuple([PublicKey, Signature]))
2202
+ signatures: bcs.vector(bcs.tuple([PublicKey, Signature]))
582
2203
  });
583
2204
  function hexToDecimal(hex) {
584
2205
  return BigInt(`0x${hex}`).toString();
@@ -586,9 +2207,9 @@ function hexToDecimal(hex) {
586
2207
 
587
2208
  // src/WarpFastsetWallet.ts
588
2209
  var WarpFastsetWallet = class {
589
- constructor(config, chain) {
2210
+ constructor(config, chain2) {
590
2211
  this.config = config;
591
- this.chain = chain;
2212
+ this.chain = chain2;
592
2213
  this.client = getConfiguredFastsetClient(this.config, this.chain);
593
2214
  const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
594
2215
  if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
@@ -601,20 +2222,19 @@ var WarpFastsetWallet = class {
601
2222
  const dataToSign = new Uint8Array(prefix.length + msgBytes.length);
602
2223
  dataToSign.set(prefix, 0);
603
2224
  dataToSign.set(msgBytes, prefix.length);
604
- const signature = ed.sign(dataToSign, this.privateKey);
2225
+ const privateKeyBytes = hexToUint8Array(this.privateKey);
2226
+ const signature = ed.sign(dataToSign, privateKeyBytes);
605
2227
  return { ...tx, signature };
606
2228
  }
607
2229
  async signMessage(message) {
608
2230
  const messageBytes = stringToUint8Array(message);
609
- const signature = ed.sign(messageBytes, this.privateKey);
2231
+ const privateKeyBytes = hexToUint8Array(this.privateKey);
2232
+ const signature = ed.sign(messageBytes, privateKeyBytes);
610
2233
  return uint8ArrayToHex(signature);
611
2234
  }
612
2235
  async sendTransaction(tx) {
613
2236
  const { signature, ...transactionWithoutSignature } = tx;
614
- const submitTxReq = {
615
- transaction: transactionWithoutSignature,
616
- signature
617
- };
2237
+ const submitTxReq = { transaction: transactionWithoutSignature, signature };
618
2238
  const proxyUrl = getProviderUrl2(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
619
2239
  const response = await this.client.request(proxyUrl, "set_proxy_submitTransaction", submitTxReq);
620
2240
  if (response.error) throw new Error(`JSON-RPC error ${response.error.code}: ${response.error.message}`);
@@ -708,4 +2328,12 @@ export {
708
2328
  WarpFastsetWallet,
709
2329
  getFastsetAdapter
710
2330
  };
2331
+ /*! Bundled license information:
2332
+
2333
+ @noble/hashes/esm/utils.js:
2334
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2335
+
2336
+ @scure/base/lib/esm/index.js:
2337
+ (*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2338
+ */
711
2339
  //# sourceMappingURL=index.mjs.map