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