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

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
@@ -5,9 +5,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
9
  var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
10
+ for (var name2 in all)
11
+ __defProp(target, name2, { get: all[name2], enumerable: true });
11
12
  };
12
13
  var __copyProps = (to, from, except, desc) => {
13
14
  if (from && typeof from === "object" || typeof from === "function") {
@@ -26,6 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
27
  mod
27
28
  ));
28
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
29
31
 
30
32
  // src/index.ts
31
33
  var index_exports = {};
@@ -49,6 +51,9 @@ var decoder = new TextDecoder();
49
51
  function uint8ArrayToHex(uint8Array) {
50
52
  return Buffer.from(uint8Array).toString("hex");
51
53
  }
54
+ function hexToUint8Array(hex) {
55
+ return new Uint8Array(Buffer.from(hex, "hex"));
56
+ }
52
57
  function stringToUint8Array(str) {
53
58
  return new Uint8Array(Buffer.from(str, "utf8"));
54
59
  }
@@ -57,44 +62,10 @@ function stringToUint8Array(str) {
57
62
  var import_warps = require("@vleap/warps");
58
63
 
59
64
  // src/sdk/FastsetClient.ts
60
- var import_bcs = require("@mysten/bcs");
61
65
  var bech32 = __toESM(require("bech32"), 1);
62
66
  BigInt.prototype.toJSON = function() {
63
67
  return Number(this);
64
68
  };
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
69
  var id = 0;
99
70
  var FastsetClient = class {
100
71
  constructor(proxyUrl) {
@@ -152,17 +123,17 @@ var FastsetClient = class {
152
123
  };
153
124
 
154
125
  // src/helpers/general.ts
155
- var getConfiguredFastsetClient = (config, chain) => {
156
- const proxyUrl = (0, import_warps.getProviderUrl)(config, chain.name, config.env, chain.defaultApiUrl);
126
+ var getConfiguredFastsetClient = (config, chain2) => {
127
+ const proxyUrl = (0, import_warps.getProviderUrl)(config, chain2.name, config.env, chain2.defaultApiUrl);
157
128
  return new FastsetClient(proxyUrl);
158
129
  };
159
130
 
160
131
  // src/WarpFastsetDataLoader.ts
161
132
  var WarpFastsetDataLoader = class {
162
- constructor(config, chain) {
133
+ constructor(config, chain2) {
163
134
  this.config = config;
164
- this.chain = chain;
165
- this.client = getConfiguredFastsetClient(config, chain);
135
+ this.chain = chain2;
136
+ this.client = getConfiguredFastsetClient(config, chain2);
166
137
  }
167
138
  async getAccount(address) {
168
139
  const addressBytes = this.addressToBytes(address);
@@ -238,9 +209,9 @@ var WarpFastsetDataLoader = class {
238
209
  // src/WarpFastsetExecutor.ts
239
210
  var import_warps2 = require("@vleap/warps");
240
211
  var WarpFastsetExecutor = class {
241
- constructor(config, chain) {
212
+ constructor(config, chain2) {
242
213
  this.config = config;
243
- this.chain = chain;
214
+ this.chain = chain2;
244
215
  this.client = getConfiguredFastsetClient(this.config, this.chain);
245
216
  }
246
217
  async createTransaction(executable) {
@@ -287,8 +258,8 @@ var WarpFastsetExplorer = class {
287
258
  getAccountUrl(address) {
288
259
  return `${this.explorerUrl}/account/${address}`;
289
260
  }
290
- getTransactionUrl(hash) {
291
- return `${this.explorerUrl}/transaction/${hash}`;
261
+ getTransactionUrl(hash2) {
262
+ return `${this.explorerUrl}/transaction/${hash2}`;
292
263
  }
293
264
  getAssetUrl(identifier) {
294
265
  return `${this.explorerUrl}/asset/${identifier}`;
@@ -413,9 +384,9 @@ var WarpFastsetSerializer = class {
413
384
 
414
385
  // src/WarpFastsetResults.ts
415
386
  var WarpFastsetResults = class {
416
- constructor(config, chain) {
387
+ constructor(config, chain2) {
417
388
  this.config = config;
418
- this.chain = chain;
389
+ this.chain = chain2;
419
390
  this.serializer = new WarpFastsetSerializer();
420
391
  }
421
392
  async getTransactionExecutionResults(warp, tx) {
@@ -500,83 +471,2269 @@ var WarpFastsetResults = class {
500
471
  var bip39 = __toESM(require("@scure/bip39"), 1);
501
472
  var import_warps5 = require("@vleap/warps");
502
473
 
474
+ // ../../node_modules/@noble/ed25519/index.js
475
+ var ed25519_exports = {};
476
+ __export(ed25519_exports, {
477
+ Point: () => Point,
478
+ etc: () => etc,
479
+ getPublicKey: () => getPublicKey,
480
+ getPublicKeyAsync: () => getPublicKeyAsync,
481
+ hash: () => hash,
482
+ hashes: () => hashes,
483
+ keygen: () => keygen,
484
+ keygenAsync: () => keygenAsync,
485
+ sign: () => sign,
486
+ signAsync: () => signAsync,
487
+ utils: () => utils,
488
+ verify: () => verify,
489
+ verifyAsync: () => verifyAsync
490
+ });
491
+ var ed25519_CURVE = {
492
+ p: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedn,
493
+ n: 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn,
494
+ h: 8n,
495
+ a: 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecn,
496
+ d: 0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3n,
497
+ Gx: 0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,
498
+ Gy: 0x6666666666666666666666666666666666666666666666666666666666666658n
499
+ };
500
+ var { p: P, n: N, Gx, Gy, a: _a, d: _d, h } = ed25519_CURVE;
501
+ var L = 32;
502
+ var L2 = 64;
503
+ var captureTrace = (...args) => {
504
+ if ("captureStackTrace" in Error && typeof Error.captureStackTrace === "function") {
505
+ Error.captureStackTrace(...args);
506
+ }
507
+ };
508
+ var err = (message = "") => {
509
+ const e = new Error(message);
510
+ captureTrace(e, err);
511
+ throw e;
512
+ };
513
+ var isBig = (n) => typeof n === "bigint";
514
+ var isStr = (s) => typeof s === "string";
515
+ var isBytes = (a) => a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
516
+ var abytes = (value, length, title = "") => {
517
+ const bytes = isBytes(value);
518
+ const len = value?.length;
519
+ const needsLen = length !== void 0;
520
+ if (!bytes || needsLen && len !== length) {
521
+ const prefix = title && `"${title}" `;
522
+ const ofLen = needsLen ? ` of length ${length}` : "";
523
+ const got = bytes ? `length=${len}` : `type=${typeof value}`;
524
+ err(prefix + "expected Uint8Array" + ofLen + ", got " + got);
525
+ }
526
+ return value;
527
+ };
528
+ var u8n = (len) => new Uint8Array(len);
529
+ var u8fr = (buf) => Uint8Array.from(buf);
530
+ var padh = (n, pad) => n.toString(16).padStart(pad, "0");
531
+ var bytesToHex = (b) => Array.from(abytes(b)).map((e) => padh(e, 2)).join("");
532
+ var C = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
533
+ var _ch = (ch) => {
534
+ if (ch >= C._0 && ch <= C._9)
535
+ return ch - C._0;
536
+ if (ch >= C.A && ch <= C.F)
537
+ return ch - (C.A - 10);
538
+ if (ch >= C.a && ch <= C.f)
539
+ return ch - (C.a - 10);
540
+ return;
541
+ };
542
+ var hexToBytes = (hex) => {
543
+ const e = "hex invalid";
544
+ if (!isStr(hex))
545
+ return err(e);
546
+ const hl = hex.length;
547
+ const al = hl / 2;
548
+ if (hl % 2)
549
+ return err(e);
550
+ const array = u8n(al);
551
+ for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
552
+ const n1 = _ch(hex.charCodeAt(hi));
553
+ const n2 = _ch(hex.charCodeAt(hi + 1));
554
+ if (n1 === void 0 || n2 === void 0)
555
+ return err(e);
556
+ array[ai] = n1 * 16 + n2;
557
+ }
558
+ return array;
559
+ };
560
+ var cr = () => globalThis?.crypto;
561
+ var subtle = () => cr()?.subtle ?? err("crypto.subtle must be defined, consider polyfill");
562
+ var concatBytes = (...arrs) => {
563
+ const r = u8n(arrs.reduce((sum, a) => sum + abytes(a).length, 0));
564
+ let pad = 0;
565
+ arrs.forEach((a) => {
566
+ r.set(a, pad);
567
+ pad += a.length;
568
+ });
569
+ return r;
570
+ };
571
+ var randomBytes = (len = L) => {
572
+ const c = cr();
573
+ return c.getRandomValues(u8n(len));
574
+ };
575
+ var big = BigInt;
576
+ var assertRange = (n, min, max, msg = "bad number: out of range") => isBig(n) && min <= n && n < max ? n : err(msg);
577
+ var M = (a, b = P) => {
578
+ const r = a % b;
579
+ return r >= 0n ? r : b + r;
580
+ };
581
+ var modN = (a) => M(a, N);
582
+ var invert = (num, md) => {
583
+ if (num === 0n || md <= 0n)
584
+ err("no inverse n=" + num + " mod=" + md);
585
+ let a = M(num, md), b = md, x = 0n, y = 1n, u = 1n, v = 0n;
586
+ while (a !== 0n) {
587
+ const q = b / a, r = b % a;
588
+ const m = x - u * q, n = y - v * q;
589
+ b = a, a = r, x = u, y = v, u = m, v = n;
590
+ }
591
+ return b === 1n ? M(x, md) : err("no inverse");
592
+ };
593
+ var callHash = (name2) => {
594
+ const fn = hashes[name2];
595
+ if (typeof fn !== "function")
596
+ err("hashes." + name2 + " not set");
597
+ return fn;
598
+ };
599
+ var hash = (msg) => callHash("sha512")(msg);
600
+ var apoint = (p) => p instanceof Point ? p : err("Point expected");
601
+ var B256 = 2n ** 256n;
602
+ var _Point = class _Point {
603
+ constructor(X, Y, Z, T) {
604
+ __publicField(this, "X");
605
+ __publicField(this, "Y");
606
+ __publicField(this, "Z");
607
+ __publicField(this, "T");
608
+ const max = B256;
609
+ this.X = assertRange(X, 0n, max);
610
+ this.Y = assertRange(Y, 0n, max);
611
+ this.Z = assertRange(Z, 1n, max);
612
+ this.T = assertRange(T, 0n, max);
613
+ Object.freeze(this);
614
+ }
615
+ static CURVE() {
616
+ return ed25519_CURVE;
617
+ }
618
+ static fromAffine(p) {
619
+ return new _Point(p.x, p.y, 1n, M(p.x * p.y));
620
+ }
621
+ /** RFC8032 5.1.3: Uint8Array to Point. */
622
+ static fromBytes(hex, zip215 = false) {
623
+ const d = _d;
624
+ const normed = u8fr(abytes(hex, L));
625
+ const lastByte = hex[31];
626
+ normed[31] = lastByte & ~128;
627
+ const y = bytesToNumLE(normed);
628
+ const max = zip215 ? B256 : P;
629
+ assertRange(y, 0n, max);
630
+ const y2 = M(y * y);
631
+ const u = M(y2 - 1n);
632
+ const v = M(d * y2 + 1n);
633
+ let { isValid, value: x } = uvRatio(u, v);
634
+ if (!isValid)
635
+ err("bad point: y not sqrt");
636
+ const isXOdd = (x & 1n) === 1n;
637
+ const isLastByteOdd = (lastByte & 128) !== 0;
638
+ if (!zip215 && x === 0n && isLastByteOdd)
639
+ err("bad point: x==0, isLastByteOdd");
640
+ if (isLastByteOdd !== isXOdd)
641
+ x = M(-x);
642
+ return new _Point(x, y, 1n, M(x * y));
643
+ }
644
+ static fromHex(hex, zip215) {
645
+ return _Point.fromBytes(hexToBytes(hex), zip215);
646
+ }
647
+ get x() {
648
+ return this.toAffine().x;
649
+ }
650
+ get y() {
651
+ return this.toAffine().y;
652
+ }
653
+ /** Checks if the point is valid and on-curve. */
654
+ assertValidity() {
655
+ const a = _a;
656
+ const d = _d;
657
+ const p = this;
658
+ if (p.is0())
659
+ return err("bad point: ZERO");
660
+ const { X, Y, Z, T } = p;
661
+ const X2 = M(X * X);
662
+ const Y2 = M(Y * Y);
663
+ const Z2 = M(Z * Z);
664
+ const Z4 = M(Z2 * Z2);
665
+ const aX2 = M(X2 * a);
666
+ const left = M(Z2 * M(aX2 + Y2));
667
+ const right = M(Z4 + M(d * M(X2 * Y2)));
668
+ if (left !== right)
669
+ return err("bad point: equation left != right (1)");
670
+ const XY = M(X * Y);
671
+ const ZT = M(Z * T);
672
+ if (XY !== ZT)
673
+ return err("bad point: equation left != right (2)");
674
+ return this;
675
+ }
676
+ /** Equality check: compare points P&Q. */
677
+ equals(other) {
678
+ const { X: X1, Y: Y1, Z: Z1 } = this;
679
+ const { X: X2, Y: Y2, Z: Z2 } = apoint(other);
680
+ const X1Z2 = M(X1 * Z2);
681
+ const X2Z1 = M(X2 * Z1);
682
+ const Y1Z2 = M(Y1 * Z2);
683
+ const Y2Z1 = M(Y2 * Z1);
684
+ return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
685
+ }
686
+ is0() {
687
+ return this.equals(I);
688
+ }
689
+ /** Flip point over y coordinate. */
690
+ negate() {
691
+ return new _Point(M(-this.X), this.Y, this.Z, M(-this.T));
692
+ }
693
+ /** Point doubling. Complete formula. Cost: `4M + 4S + 1*a + 6add + 1*2`. */
694
+ double() {
695
+ const { X: X1, Y: Y1, Z: Z1 } = this;
696
+ const a = _a;
697
+ const A = M(X1 * X1);
698
+ const B = M(Y1 * Y1);
699
+ const C2 = M(2n * M(Z1 * Z1));
700
+ const D = M(a * A);
701
+ const x1y1 = X1 + Y1;
702
+ const E = M(M(x1y1 * x1y1) - A - B);
703
+ const G2 = D + B;
704
+ const F = G2 - C2;
705
+ const H = D - B;
706
+ const X3 = M(E * F);
707
+ const Y3 = M(G2 * H);
708
+ const T3 = M(E * H);
709
+ const Z3 = M(F * G2);
710
+ return new _Point(X3, Y3, Z3, T3);
711
+ }
712
+ /** Point addition. Complete formula. Cost: `8M + 1*k + 8add + 1*2`. */
713
+ add(other) {
714
+ const { X: X1, Y: Y1, Z: Z1, T: T1 } = this;
715
+ const { X: X2, Y: Y2, Z: Z2, T: T2 } = apoint(other);
716
+ const a = _a;
717
+ const d = _d;
718
+ const A = M(X1 * X2);
719
+ const B = M(Y1 * Y2);
720
+ const C2 = M(T1 * d * T2);
721
+ const D = M(Z1 * Z2);
722
+ const E = M((X1 + Y1) * (X2 + Y2) - A - B);
723
+ const F = M(D - C2);
724
+ const G2 = M(D + C2);
725
+ const H = M(B - a * A);
726
+ const X3 = M(E * F);
727
+ const Y3 = M(G2 * H);
728
+ const T3 = M(E * H);
729
+ const Z3 = M(F * G2);
730
+ return new _Point(X3, Y3, Z3, T3);
731
+ }
732
+ subtract(other) {
733
+ return this.add(apoint(other).negate());
734
+ }
735
+ /**
736
+ * Point-by-scalar multiplication. Scalar must be in range 1 <= n < CURVE.n.
737
+ * Uses {@link wNAF} for base point.
738
+ * Uses fake point to mitigate side-channel leakage.
739
+ * @param n scalar by which point is multiplied
740
+ * @param safe safe mode guards against timing attacks; unsafe mode is faster
741
+ */
742
+ multiply(n, safe = true) {
743
+ if (!safe && (n === 0n || this.is0()))
744
+ return I;
745
+ assertRange(n, 1n, N);
746
+ if (n === 1n)
747
+ return this;
748
+ if (this.equals(G))
749
+ return wNAF(n).p;
750
+ let p = I;
751
+ let f = G;
752
+ for (let d = this; n > 0n; d = d.double(), n >>= 1n) {
753
+ if (n & 1n)
754
+ p = p.add(d);
755
+ else if (safe)
756
+ f = f.add(d);
757
+ }
758
+ return p;
759
+ }
760
+ multiplyUnsafe(scalar) {
761
+ return this.multiply(scalar, false);
762
+ }
763
+ /** Convert point to 2d xy affine point. (X, Y, Z) ∋ (x=X/Z, y=Y/Z) */
764
+ toAffine() {
765
+ const { X, Y, Z } = this;
766
+ if (this.equals(I))
767
+ return { x: 0n, y: 1n };
768
+ const iz = invert(Z, P);
769
+ if (M(Z * iz) !== 1n)
770
+ err("invalid inverse");
771
+ const x = M(X * iz);
772
+ const y = M(Y * iz);
773
+ return { x, y };
774
+ }
775
+ toBytes() {
776
+ const { x, y } = this.assertValidity().toAffine();
777
+ const b = numTo32bLE(y);
778
+ b[31] |= x & 1n ? 128 : 0;
779
+ return b;
780
+ }
781
+ toHex() {
782
+ return bytesToHex(this.toBytes());
783
+ }
784
+ clearCofactor() {
785
+ return this.multiply(big(h), false);
786
+ }
787
+ isSmallOrder() {
788
+ return this.clearCofactor().is0();
789
+ }
790
+ isTorsionFree() {
791
+ let p = this.multiply(N / 2n, false).double();
792
+ if (N % 2n)
793
+ p = p.add(this);
794
+ return p.is0();
795
+ }
796
+ };
797
+ __publicField(_Point, "BASE");
798
+ __publicField(_Point, "ZERO");
799
+ var Point = _Point;
800
+ var G = new Point(Gx, Gy, 1n, M(Gx * Gy));
801
+ var I = new Point(0n, 1n, 1n, 0n);
802
+ Point.BASE = G;
803
+ Point.ZERO = I;
804
+ var numTo32bLE = (num) => hexToBytes(padh(assertRange(num, 0n, B256), L2)).reverse();
805
+ var bytesToNumLE = (b) => big("0x" + bytesToHex(u8fr(abytes(b)).reverse()));
806
+ var pow2 = (x, power) => {
807
+ let r = x;
808
+ while (power-- > 0n) {
809
+ r *= r;
810
+ r %= P;
811
+ }
812
+ return r;
813
+ };
814
+ var pow_2_252_3 = (x) => {
815
+ const x2 = x * x % P;
816
+ const b2 = x2 * x % P;
817
+ const b4 = pow2(b2, 2n) * b2 % P;
818
+ const b5 = pow2(b4, 1n) * x % P;
819
+ const b10 = pow2(b5, 5n) * b5 % P;
820
+ const b20 = pow2(b10, 10n) * b10 % P;
821
+ const b40 = pow2(b20, 20n) * b20 % P;
822
+ const b80 = pow2(b40, 40n) * b40 % P;
823
+ const b160 = pow2(b80, 80n) * b80 % P;
824
+ const b240 = pow2(b160, 80n) * b80 % P;
825
+ const b250 = pow2(b240, 10n) * b10 % P;
826
+ const pow_p_5_8 = pow2(b250, 2n) * x % P;
827
+ return { pow_p_5_8, b2 };
828
+ };
829
+ var RM1 = 0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0n;
830
+ var uvRatio = (u, v) => {
831
+ const v3 = M(v * v * v);
832
+ const v7 = M(v3 * v3 * v);
833
+ const pow = pow_2_252_3(u * v7).pow_p_5_8;
834
+ let x = M(u * v3 * pow);
835
+ const vx2 = M(v * x * x);
836
+ const root1 = x;
837
+ const root2 = M(x * RM1);
838
+ const useRoot1 = vx2 === u;
839
+ const useRoot2 = vx2 === M(-u);
840
+ const noRoot = vx2 === M(-u * RM1);
841
+ if (useRoot1)
842
+ x = root1;
843
+ if (useRoot2 || noRoot)
844
+ x = root2;
845
+ if ((M(x) & 1n) === 1n)
846
+ x = M(-x);
847
+ return { isValid: useRoot1 || useRoot2, value: x };
848
+ };
849
+ var modL_LE = (hash2) => modN(bytesToNumLE(hash2));
850
+ var sha512a = (...m) => hashes.sha512Async(concatBytes(...m));
851
+ var sha512s = (...m) => callHash("sha512")(concatBytes(...m));
852
+ var hash2extK = (hashed) => {
853
+ const head = hashed.slice(0, L);
854
+ head[0] &= 248;
855
+ head[31] &= 127;
856
+ head[31] |= 64;
857
+ const prefix = hashed.slice(L, L2);
858
+ const scalar = modL_LE(head);
859
+ const point = G.multiply(scalar);
860
+ const pointBytes = point.toBytes();
861
+ return { head, prefix, scalar, point, pointBytes };
862
+ };
863
+ var getExtendedPublicKeyAsync = (secretKey) => sha512a(abytes(secretKey, L)).then(hash2extK);
864
+ var getExtendedPublicKey = (secretKey) => hash2extK(sha512s(abytes(secretKey, L)));
865
+ var getPublicKeyAsync = (secretKey) => getExtendedPublicKeyAsync(secretKey).then((p) => p.pointBytes);
866
+ var getPublicKey = (priv) => getExtendedPublicKey(priv).pointBytes;
867
+ var hashFinishA = (res) => sha512a(res.hashable).then(res.finish);
868
+ var hashFinishS = (res) => res.finish(sha512s(res.hashable));
869
+ var _sign = (e, rBytes, msg) => {
870
+ const { pointBytes: P2, scalar: s } = e;
871
+ const r = modL_LE(rBytes);
872
+ const R = G.multiply(r).toBytes();
873
+ const hashable = concatBytes(R, P2, msg);
874
+ const finish = (hashed) => {
875
+ const S = modN(r + modL_LE(hashed) * s);
876
+ return abytes(concatBytes(R, numTo32bLE(S)), L2);
877
+ };
878
+ return { hashable, finish };
879
+ };
880
+ var signAsync = async (message, secretKey) => {
881
+ const m = abytes(message);
882
+ const e = await getExtendedPublicKeyAsync(secretKey);
883
+ const rBytes = await sha512a(e.prefix, m);
884
+ return hashFinishA(_sign(e, rBytes, m));
885
+ };
886
+ var sign = (message, secretKey) => {
887
+ const m = abytes(message);
888
+ const e = getExtendedPublicKey(secretKey);
889
+ const rBytes = sha512s(e.prefix, m);
890
+ return hashFinishS(_sign(e, rBytes, m));
891
+ };
892
+ var defaultVerifyOpts = { zip215: true };
893
+ var _verify = (sig, msg, pub, opts = defaultVerifyOpts) => {
894
+ sig = abytes(sig, L2);
895
+ msg = abytes(msg);
896
+ pub = abytes(pub, L);
897
+ const { zip215 } = opts;
898
+ let A;
899
+ let R;
900
+ let s;
901
+ let SB;
902
+ let hashable = Uint8Array.of();
903
+ try {
904
+ A = Point.fromBytes(pub, zip215);
905
+ R = Point.fromBytes(sig.slice(0, L), zip215);
906
+ s = bytesToNumLE(sig.slice(L, L2));
907
+ SB = G.multiply(s, false);
908
+ hashable = concatBytes(R.toBytes(), A.toBytes(), msg);
909
+ } catch (error) {
910
+ }
911
+ const finish = (hashed) => {
912
+ if (SB == null)
913
+ return false;
914
+ if (!zip215 && A.isSmallOrder())
915
+ return false;
916
+ const k = modL_LE(hashed);
917
+ const RkA = R.add(A.multiply(k, false));
918
+ return RkA.add(SB.negate()).clearCofactor().is0();
919
+ };
920
+ return { hashable, finish };
921
+ };
922
+ var verifyAsync = async (signature, message, publicKey, opts = defaultVerifyOpts) => hashFinishA(_verify(signature, message, publicKey, opts));
923
+ var verify = (signature, message, publicKey, opts = defaultVerifyOpts) => hashFinishS(_verify(signature, message, publicKey, opts));
924
+ var etc = {
925
+ bytesToHex,
926
+ hexToBytes,
927
+ concatBytes,
928
+ mod: M,
929
+ invert,
930
+ randomBytes
931
+ };
932
+ var hashes = {
933
+ sha512Async: async (message) => {
934
+ const s = subtle();
935
+ const m = concatBytes(message);
936
+ return u8n(await s.digest("SHA-512", m.buffer));
937
+ },
938
+ sha512: void 0
939
+ };
940
+ var randomSecretKey = (seed = randomBytes(L)) => seed;
941
+ var keygen = (seed) => {
942
+ const secretKey = randomSecretKey(seed);
943
+ const publicKey = getPublicKey(secretKey);
944
+ return { secretKey, publicKey };
945
+ };
946
+ var keygenAsync = async (seed) => {
947
+ const secretKey = randomSecretKey(seed);
948
+ const publicKey = await getPublicKeyAsync(secretKey);
949
+ return { secretKey, publicKey };
950
+ };
951
+ var utils = {
952
+ getExtendedPublicKeyAsync,
953
+ getExtendedPublicKey,
954
+ randomSecretKey
955
+ };
956
+ var W = 8;
957
+ var scalarBits = 256;
958
+ var pwindows = Math.ceil(scalarBits / W) + 1;
959
+ var pwindowSize = 2 ** (W - 1);
960
+ var precompute = () => {
961
+ const points = [];
962
+ let p = G;
963
+ let b = p;
964
+ for (let w = 0; w < pwindows; w++) {
965
+ b = p;
966
+ points.push(b);
967
+ for (let i = 1; i < pwindowSize; i++) {
968
+ b = b.add(p);
969
+ points.push(b);
970
+ }
971
+ p = b.double();
972
+ }
973
+ return points;
974
+ };
975
+ var Gpows = void 0;
976
+ var ctneg = (cnd, p) => {
977
+ const n = p.negate();
978
+ return cnd ? n : p;
979
+ };
980
+ var wNAF = (n) => {
981
+ const comp = Gpows || (Gpows = precompute());
982
+ let p = I;
983
+ let f = G;
984
+ const pow_2_w = 2 ** W;
985
+ const maxNum = pow_2_w;
986
+ const mask = big(pow_2_w - 1);
987
+ const shiftBy = big(W);
988
+ for (let w = 0; w < pwindows; w++) {
989
+ let wbits = Number(n & mask);
990
+ n >>= shiftBy;
991
+ if (wbits > pwindowSize) {
992
+ wbits -= maxNum;
993
+ n += 1n;
994
+ }
995
+ const off = w * pwindowSize;
996
+ const offF = off;
997
+ const offP = off + Math.abs(wbits) - 1;
998
+ const isEven = w % 2 !== 0;
999
+ const isNeg = wbits < 0;
1000
+ if (wbits === 0) {
1001
+ f = f.add(ctneg(isEven, comp[offF]));
1002
+ } else {
1003
+ p = p.add(ctneg(isNeg, comp[offP]));
1004
+ }
1005
+ }
1006
+ if (n !== 0n)
1007
+ err("invalid wnaf");
1008
+ return { p, f };
1009
+ };
1010
+
1011
+ // ../../node_modules/@noble/hashes/esm/utils.js
1012
+ function isBytes2(a) {
1013
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
1014
+ }
1015
+ function abytes2(b, ...lengths) {
1016
+ if (!isBytes2(b))
1017
+ throw new Error("Uint8Array expected");
1018
+ if (lengths.length > 0 && !lengths.includes(b.length))
1019
+ throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
1020
+ }
1021
+ function aexists(instance, checkFinished = true) {
1022
+ if (instance.destroyed)
1023
+ throw new Error("Hash instance has been destroyed");
1024
+ if (checkFinished && instance.finished)
1025
+ throw new Error("Hash#digest() has already been called");
1026
+ }
1027
+ function aoutput(out, instance) {
1028
+ abytes2(out);
1029
+ const min = instance.outputLen;
1030
+ if (out.length < min) {
1031
+ throw new Error("digestInto() expects output buffer of length at least " + min);
1032
+ }
1033
+ }
1034
+ function clean(...arrays) {
1035
+ for (let i = 0; i < arrays.length; i++) {
1036
+ arrays[i].fill(0);
1037
+ }
1038
+ }
1039
+ function createView(arr) {
1040
+ return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
1041
+ }
1042
+ function utf8ToBytes(str) {
1043
+ if (typeof str !== "string")
1044
+ throw new Error("string expected");
1045
+ return new Uint8Array(new TextEncoder().encode(str));
1046
+ }
1047
+ function toBytes(data) {
1048
+ if (typeof data === "string")
1049
+ data = utf8ToBytes(data);
1050
+ abytes2(data);
1051
+ return data;
1052
+ }
1053
+ var Hash = class {
1054
+ };
1055
+ function createHasher(hashCons) {
1056
+ const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
1057
+ const tmp = hashCons();
1058
+ hashC.outputLen = tmp.outputLen;
1059
+ hashC.blockLen = tmp.blockLen;
1060
+ hashC.create = () => hashCons();
1061
+ return hashC;
1062
+ }
1063
+
1064
+ // ../../node_modules/@noble/hashes/esm/_md.js
1065
+ function setBigUint64(view, byteOffset, value, isLE) {
1066
+ if (typeof view.setBigUint64 === "function")
1067
+ return view.setBigUint64(byteOffset, value, isLE);
1068
+ const _32n2 = BigInt(32);
1069
+ const _u32_max = BigInt(4294967295);
1070
+ const wh = Number(value >> _32n2 & _u32_max);
1071
+ const wl = Number(value & _u32_max);
1072
+ const h2 = isLE ? 4 : 0;
1073
+ const l = isLE ? 0 : 4;
1074
+ view.setUint32(byteOffset + h2, wh, isLE);
1075
+ view.setUint32(byteOffset + l, wl, isLE);
1076
+ }
1077
+ var HashMD = class extends Hash {
1078
+ constructor(blockLen, outputLen, padOffset, isLE) {
1079
+ super();
1080
+ this.finished = false;
1081
+ this.length = 0;
1082
+ this.pos = 0;
1083
+ this.destroyed = false;
1084
+ this.blockLen = blockLen;
1085
+ this.outputLen = outputLen;
1086
+ this.padOffset = padOffset;
1087
+ this.isLE = isLE;
1088
+ this.buffer = new Uint8Array(blockLen);
1089
+ this.view = createView(this.buffer);
1090
+ }
1091
+ update(data) {
1092
+ aexists(this);
1093
+ data = toBytes(data);
1094
+ abytes2(data);
1095
+ const { view, buffer, blockLen } = this;
1096
+ const len = data.length;
1097
+ for (let pos = 0; pos < len; ) {
1098
+ const take = Math.min(blockLen - this.pos, len - pos);
1099
+ if (take === blockLen) {
1100
+ const dataView = createView(data);
1101
+ for (; blockLen <= len - pos; pos += blockLen)
1102
+ this.process(dataView, pos);
1103
+ continue;
1104
+ }
1105
+ buffer.set(data.subarray(pos, pos + take), this.pos);
1106
+ this.pos += take;
1107
+ pos += take;
1108
+ if (this.pos === blockLen) {
1109
+ this.process(view, 0);
1110
+ this.pos = 0;
1111
+ }
1112
+ }
1113
+ this.length += data.length;
1114
+ this.roundClean();
1115
+ return this;
1116
+ }
1117
+ digestInto(out) {
1118
+ aexists(this);
1119
+ aoutput(out, this);
1120
+ this.finished = true;
1121
+ const { buffer, view, blockLen, isLE } = this;
1122
+ let { pos } = this;
1123
+ buffer[pos++] = 128;
1124
+ clean(this.buffer.subarray(pos));
1125
+ if (this.padOffset > blockLen - pos) {
1126
+ this.process(view, 0);
1127
+ pos = 0;
1128
+ }
1129
+ for (let i = pos; i < blockLen; i++)
1130
+ buffer[i] = 0;
1131
+ setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
1132
+ this.process(view, 0);
1133
+ const oview = createView(out);
1134
+ const len = this.outputLen;
1135
+ if (len % 4)
1136
+ throw new Error("_sha2: outputLen should be aligned to 32bit");
1137
+ const outLen = len / 4;
1138
+ const state = this.get();
1139
+ if (outLen > state.length)
1140
+ throw new Error("_sha2: outputLen bigger than state");
1141
+ for (let i = 0; i < outLen; i++)
1142
+ oview.setUint32(4 * i, state[i], isLE);
1143
+ }
1144
+ digest() {
1145
+ const { buffer, outputLen } = this;
1146
+ this.digestInto(buffer);
1147
+ const res = buffer.slice(0, outputLen);
1148
+ this.destroy();
1149
+ return res;
1150
+ }
1151
+ _cloneInto(to) {
1152
+ to || (to = new this.constructor());
1153
+ to.set(...this.get());
1154
+ const { blockLen, buffer, length, finished, destroyed, pos } = this;
1155
+ to.destroyed = destroyed;
1156
+ to.finished = finished;
1157
+ to.length = length;
1158
+ to.pos = pos;
1159
+ if (length % blockLen)
1160
+ to.buffer.set(buffer);
1161
+ return to;
1162
+ }
1163
+ clone() {
1164
+ return this._cloneInto();
1165
+ }
1166
+ };
1167
+ var SHA512_IV = /* @__PURE__ */ Uint32Array.from([
1168
+ 1779033703,
1169
+ 4089235720,
1170
+ 3144134277,
1171
+ 2227873595,
1172
+ 1013904242,
1173
+ 4271175723,
1174
+ 2773480762,
1175
+ 1595750129,
1176
+ 1359893119,
1177
+ 2917565137,
1178
+ 2600822924,
1179
+ 725511199,
1180
+ 528734635,
1181
+ 4215389547,
1182
+ 1541459225,
1183
+ 327033209
1184
+ ]);
1185
+
1186
+ // ../../node_modules/@noble/hashes/esm/_u64.js
1187
+ var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
1188
+ var _32n = /* @__PURE__ */ BigInt(32);
1189
+ function fromBig(n, le = false) {
1190
+ if (le)
1191
+ return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
1192
+ return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
1193
+ }
1194
+ function split(lst, le = false) {
1195
+ const len = lst.length;
1196
+ let Ah = new Uint32Array(len);
1197
+ let Al = new Uint32Array(len);
1198
+ for (let i = 0; i < len; i++) {
1199
+ const { h: h2, l } = fromBig(lst[i], le);
1200
+ [Ah[i], Al[i]] = [h2, l];
1201
+ }
1202
+ return [Ah, Al];
1203
+ }
1204
+ var shrSH = (h2, _l, s) => h2 >>> s;
1205
+ var shrSL = (h2, l, s) => h2 << 32 - s | l >>> s;
1206
+ var rotrSH = (h2, l, s) => h2 >>> s | l << 32 - s;
1207
+ var rotrSL = (h2, l, s) => h2 << 32 - s | l >>> s;
1208
+ var rotrBH = (h2, l, s) => h2 << 64 - s | l >>> s - 32;
1209
+ var rotrBL = (h2, l, s) => h2 >>> s - 32 | l << 64 - s;
1210
+ function add(Ah, Al, Bh, Bl) {
1211
+ const l = (Al >>> 0) + (Bl >>> 0);
1212
+ return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
1213
+ }
1214
+ var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
1215
+ var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
1216
+ var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
1217
+ var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
1218
+ var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
1219
+ var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
1220
+
1221
+ // ../../node_modules/@noble/hashes/esm/sha2.js
1222
+ var K512 = /* @__PURE__ */ (() => split([
1223
+ "0x428a2f98d728ae22",
1224
+ "0x7137449123ef65cd",
1225
+ "0xb5c0fbcfec4d3b2f",
1226
+ "0xe9b5dba58189dbbc",
1227
+ "0x3956c25bf348b538",
1228
+ "0x59f111f1b605d019",
1229
+ "0x923f82a4af194f9b",
1230
+ "0xab1c5ed5da6d8118",
1231
+ "0xd807aa98a3030242",
1232
+ "0x12835b0145706fbe",
1233
+ "0x243185be4ee4b28c",
1234
+ "0x550c7dc3d5ffb4e2",
1235
+ "0x72be5d74f27b896f",
1236
+ "0x80deb1fe3b1696b1",
1237
+ "0x9bdc06a725c71235",
1238
+ "0xc19bf174cf692694",
1239
+ "0xe49b69c19ef14ad2",
1240
+ "0xefbe4786384f25e3",
1241
+ "0x0fc19dc68b8cd5b5",
1242
+ "0x240ca1cc77ac9c65",
1243
+ "0x2de92c6f592b0275",
1244
+ "0x4a7484aa6ea6e483",
1245
+ "0x5cb0a9dcbd41fbd4",
1246
+ "0x76f988da831153b5",
1247
+ "0x983e5152ee66dfab",
1248
+ "0xa831c66d2db43210",
1249
+ "0xb00327c898fb213f",
1250
+ "0xbf597fc7beef0ee4",
1251
+ "0xc6e00bf33da88fc2",
1252
+ "0xd5a79147930aa725",
1253
+ "0x06ca6351e003826f",
1254
+ "0x142929670a0e6e70",
1255
+ "0x27b70a8546d22ffc",
1256
+ "0x2e1b21385c26c926",
1257
+ "0x4d2c6dfc5ac42aed",
1258
+ "0x53380d139d95b3df",
1259
+ "0x650a73548baf63de",
1260
+ "0x766a0abb3c77b2a8",
1261
+ "0x81c2c92e47edaee6",
1262
+ "0x92722c851482353b",
1263
+ "0xa2bfe8a14cf10364",
1264
+ "0xa81a664bbc423001",
1265
+ "0xc24b8b70d0f89791",
1266
+ "0xc76c51a30654be30",
1267
+ "0xd192e819d6ef5218",
1268
+ "0xd69906245565a910",
1269
+ "0xf40e35855771202a",
1270
+ "0x106aa07032bbd1b8",
1271
+ "0x19a4c116b8d2d0c8",
1272
+ "0x1e376c085141ab53",
1273
+ "0x2748774cdf8eeb99",
1274
+ "0x34b0bcb5e19b48a8",
1275
+ "0x391c0cb3c5c95a63",
1276
+ "0x4ed8aa4ae3418acb",
1277
+ "0x5b9cca4f7763e373",
1278
+ "0x682e6ff3d6b2b8a3",
1279
+ "0x748f82ee5defb2fc",
1280
+ "0x78a5636f43172f60",
1281
+ "0x84c87814a1f0ab72",
1282
+ "0x8cc702081a6439ec",
1283
+ "0x90befffa23631e28",
1284
+ "0xa4506cebde82bde9",
1285
+ "0xbef9a3f7b2c67915",
1286
+ "0xc67178f2e372532b",
1287
+ "0xca273eceea26619c",
1288
+ "0xd186b8c721c0c207",
1289
+ "0xeada7dd6cde0eb1e",
1290
+ "0xf57d4f7fee6ed178",
1291
+ "0x06f067aa72176fba",
1292
+ "0x0a637dc5a2c898a6",
1293
+ "0x113f9804bef90dae",
1294
+ "0x1b710b35131c471b",
1295
+ "0x28db77f523047d84",
1296
+ "0x32caab7b40c72493",
1297
+ "0x3c9ebe0a15c9bebc",
1298
+ "0x431d67c49c100d4c",
1299
+ "0x4cc5d4becb3e42b6",
1300
+ "0x597f299cfc657e2a",
1301
+ "0x5fcb6fab3ad6faec",
1302
+ "0x6c44198c4a475817"
1303
+ ].map((n) => BigInt(n))))();
1304
+ var SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
1305
+ var SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
1306
+ var SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
1307
+ var SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
1308
+ var SHA512 = class extends HashMD {
1309
+ constructor(outputLen = 64) {
1310
+ super(128, outputLen, 16, false);
1311
+ this.Ah = SHA512_IV[0] | 0;
1312
+ this.Al = SHA512_IV[1] | 0;
1313
+ this.Bh = SHA512_IV[2] | 0;
1314
+ this.Bl = SHA512_IV[3] | 0;
1315
+ this.Ch = SHA512_IV[4] | 0;
1316
+ this.Cl = SHA512_IV[5] | 0;
1317
+ this.Dh = SHA512_IV[6] | 0;
1318
+ this.Dl = SHA512_IV[7] | 0;
1319
+ this.Eh = SHA512_IV[8] | 0;
1320
+ this.El = SHA512_IV[9] | 0;
1321
+ this.Fh = SHA512_IV[10] | 0;
1322
+ this.Fl = SHA512_IV[11] | 0;
1323
+ this.Gh = SHA512_IV[12] | 0;
1324
+ this.Gl = SHA512_IV[13] | 0;
1325
+ this.Hh = SHA512_IV[14] | 0;
1326
+ this.Hl = SHA512_IV[15] | 0;
1327
+ }
1328
+ // prettier-ignore
1329
+ get() {
1330
+ const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
1331
+ return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
1332
+ }
1333
+ // prettier-ignore
1334
+ set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
1335
+ this.Ah = Ah | 0;
1336
+ this.Al = Al | 0;
1337
+ this.Bh = Bh | 0;
1338
+ this.Bl = Bl | 0;
1339
+ this.Ch = Ch | 0;
1340
+ this.Cl = Cl | 0;
1341
+ this.Dh = Dh | 0;
1342
+ this.Dl = Dl | 0;
1343
+ this.Eh = Eh | 0;
1344
+ this.El = El | 0;
1345
+ this.Fh = Fh | 0;
1346
+ this.Fl = Fl | 0;
1347
+ this.Gh = Gh | 0;
1348
+ this.Gl = Gl | 0;
1349
+ this.Hh = Hh | 0;
1350
+ this.Hl = Hl | 0;
1351
+ }
1352
+ process(view, offset) {
1353
+ for (let i = 0; i < 16; i++, offset += 4) {
1354
+ SHA512_W_H[i] = view.getUint32(offset);
1355
+ SHA512_W_L[i] = view.getUint32(offset += 4);
1356
+ }
1357
+ for (let i = 16; i < 80; i++) {
1358
+ const W15h = SHA512_W_H[i - 15] | 0;
1359
+ const W15l = SHA512_W_L[i - 15] | 0;
1360
+ const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
1361
+ const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
1362
+ const W2h = SHA512_W_H[i - 2] | 0;
1363
+ const W2l = SHA512_W_L[i - 2] | 0;
1364
+ const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
1365
+ const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
1366
+ const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
1367
+ const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
1368
+ SHA512_W_H[i] = SUMh | 0;
1369
+ SHA512_W_L[i] = SUMl | 0;
1370
+ }
1371
+ let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
1372
+ for (let i = 0; i < 80; i++) {
1373
+ const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
1374
+ const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
1375
+ const CHIh = Eh & Fh ^ ~Eh & Gh;
1376
+ const CHIl = El & Fl ^ ~El & Gl;
1377
+ const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
1378
+ const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
1379
+ const T1l = T1ll | 0;
1380
+ const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
1381
+ const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
1382
+ const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
1383
+ const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
1384
+ Hh = Gh | 0;
1385
+ Hl = Gl | 0;
1386
+ Gh = Fh | 0;
1387
+ Gl = Fl | 0;
1388
+ Fh = Eh | 0;
1389
+ Fl = El | 0;
1390
+ ({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
1391
+ Dh = Ch | 0;
1392
+ Dl = Cl | 0;
1393
+ Ch = Bh | 0;
1394
+ Cl = Bl | 0;
1395
+ Bh = Ah | 0;
1396
+ Bl = Al | 0;
1397
+ const All = add3L(T1l, sigma0l, MAJl);
1398
+ Ah = add3H(All, T1h, sigma0h, MAJh);
1399
+ Al = All | 0;
1400
+ }
1401
+ ({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
1402
+ ({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
1403
+ ({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
1404
+ ({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
1405
+ ({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
1406
+ ({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
1407
+ ({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
1408
+ ({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
1409
+ this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
1410
+ }
1411
+ roundClean() {
1412
+ clean(SHA512_W_H, SHA512_W_L);
1413
+ }
1414
+ destroy() {
1415
+ clean(this.buffer);
1416
+ this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
1417
+ }
1418
+ };
1419
+ var sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
1420
+
1421
+ // ../../node_modules/@noble/hashes/esm/sha512.js
1422
+ var sha5122 = sha512;
1423
+
503
1424
  // src/sdk/ed25519-setup.ts
504
- 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));
1425
+ hashes.sha512 = sha5122;
1426
+
1427
+ // ../../node_modules/@scure/base/lib/esm/index.js
1428
+ function isBytes3(a) {
1429
+ return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
1430
+ }
1431
+ function isArrayOf(isString, arr) {
1432
+ if (!Array.isArray(arr))
1433
+ return false;
1434
+ if (arr.length === 0)
1435
+ return true;
1436
+ if (isString) {
1437
+ return arr.every((item) => typeof item === "string");
1438
+ } else {
1439
+ return arr.every((item) => Number.isSafeInteger(item));
1440
+ }
1441
+ }
1442
+ function astr(label, input) {
1443
+ if (typeof input !== "string")
1444
+ throw new Error(`${label}: string expected`);
1445
+ return true;
1446
+ }
1447
+ function anumber(n) {
1448
+ if (!Number.isSafeInteger(n))
1449
+ throw new Error(`invalid integer: ${n}`);
1450
+ }
1451
+ function aArr(input) {
1452
+ if (!Array.isArray(input))
1453
+ throw new Error("array expected");
1454
+ }
1455
+ function astrArr(label, input) {
1456
+ if (!isArrayOf(true, input))
1457
+ throw new Error(`${label}: array of strings expected`);
1458
+ }
1459
+ function anumArr(label, input) {
1460
+ if (!isArrayOf(false, input))
1461
+ throw new Error(`${label}: array of numbers expected`);
1462
+ }
1463
+ // @__NO_SIDE_EFFECTS__
1464
+ function chain(...args) {
1465
+ const id2 = (a) => a;
1466
+ const wrap = (a, b) => (c) => a(b(c));
1467
+ const encode = args.map((x) => x.encode).reduceRight(wrap, id2);
1468
+ const decode = args.map((x) => x.decode).reduce(wrap, id2);
1469
+ return { encode, decode };
1470
+ }
1471
+ // @__NO_SIDE_EFFECTS__
1472
+ function alphabet(letters) {
1473
+ const lettersA = typeof letters === "string" ? letters.split("") : letters;
1474
+ const len = lettersA.length;
1475
+ astrArr("alphabet", lettersA);
1476
+ const indexes = new Map(lettersA.map((l, i) => [l, i]));
1477
+ return {
1478
+ encode: (digits) => {
1479
+ aArr(digits);
1480
+ return digits.map((i) => {
1481
+ if (!Number.isSafeInteger(i) || i < 0 || i >= len)
1482
+ throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`);
1483
+ return lettersA[i];
1484
+ });
1485
+ },
1486
+ decode: (input) => {
1487
+ aArr(input);
1488
+ return input.map((letter) => {
1489
+ astr("alphabet.decode", letter);
1490
+ const i = indexes.get(letter);
1491
+ if (i === void 0)
1492
+ throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
1493
+ return i;
1494
+ });
1495
+ }
1496
+ };
1497
+ }
1498
+ // @__NO_SIDE_EFFECTS__
1499
+ function join(separator = "") {
1500
+ astr("join", separator);
1501
+ return {
1502
+ encode: (from) => {
1503
+ astrArr("join.decode", from);
1504
+ return from.join(separator);
1505
+ },
1506
+ decode: (to) => {
1507
+ astr("join.decode", to);
1508
+ return to.split(separator);
1509
+ }
1510
+ };
1511
+ }
1512
+ function convertRadix(data, from, to) {
1513
+ if (from < 2)
1514
+ throw new Error(`convertRadix: invalid from=${from}, base cannot be less than 2`);
1515
+ if (to < 2)
1516
+ throw new Error(`convertRadix: invalid to=${to}, base cannot be less than 2`);
1517
+ aArr(data);
1518
+ if (!data.length)
1519
+ return [];
1520
+ let pos = 0;
1521
+ const res = [];
1522
+ const digits = Array.from(data, (d) => {
1523
+ anumber(d);
1524
+ if (d < 0 || d >= from)
1525
+ throw new Error(`invalid integer: ${d}`);
1526
+ return d;
1527
+ });
1528
+ const dlen = digits.length;
1529
+ while (true) {
1530
+ let carry = 0;
1531
+ let done = true;
1532
+ for (let i = pos; i < dlen; i++) {
1533
+ const digit = digits[i];
1534
+ const fromCarry = from * carry;
1535
+ const digitBase = fromCarry + digit;
1536
+ if (!Number.isSafeInteger(digitBase) || fromCarry / from !== carry || digitBase - digit !== fromCarry) {
1537
+ throw new Error("convertRadix: carry overflow");
1538
+ }
1539
+ const div = digitBase / to;
1540
+ carry = digitBase % to;
1541
+ const rounded = Math.floor(div);
1542
+ digits[i] = rounded;
1543
+ if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase)
1544
+ throw new Error("convertRadix: carry overflow");
1545
+ if (!done)
1546
+ continue;
1547
+ else if (!rounded)
1548
+ pos = i;
1549
+ else
1550
+ done = false;
1551
+ }
1552
+ res.push(carry);
1553
+ if (done)
1554
+ break;
1555
+ }
1556
+ for (let i = 0; i < data.length - 1 && data[i] === 0; i++)
1557
+ res.push(0);
1558
+ return res.reverse();
1559
+ }
1560
+ // @__NO_SIDE_EFFECTS__
1561
+ function radix(num) {
1562
+ anumber(num);
1563
+ const _256 = 2 ** 8;
1564
+ return {
1565
+ encode: (bytes) => {
1566
+ if (!isBytes3(bytes))
1567
+ throw new Error("radix.encode input should be Uint8Array");
1568
+ return convertRadix(Array.from(bytes), _256, num);
1569
+ },
1570
+ decode: (digits) => {
1571
+ anumArr("radix.decode", digits);
1572
+ return Uint8Array.from(convertRadix(digits, num, _256));
1573
+ }
1574
+ };
1575
+ }
1576
+ var genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join(""));
1577
+ var base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
1578
+
1579
+ // ../../node_modules/@mysten/utils/dist/esm/b58.js
1580
+ var toBase58 = (buffer) => base58.encode(buffer);
1581
+ var fromBase58 = (str) => base58.decode(str);
1582
+
1583
+ // ../../node_modules/@mysten/utils/dist/esm/b64.js
1584
+ function fromBase64(base64String) {
1585
+ return Uint8Array.from(atob(base64String), (char) => char.charCodeAt(0));
1586
+ }
1587
+ var CHUNK_SIZE = 8192;
1588
+ function toBase64(bytes) {
1589
+ if (bytes.length < CHUNK_SIZE) {
1590
+ return btoa(String.fromCharCode(...bytes));
1591
+ }
1592
+ let output = "";
1593
+ for (var i = 0; i < bytes.length; i += CHUNK_SIZE) {
1594
+ const chunk = bytes.slice(i, i + CHUNK_SIZE);
1595
+ output += String.fromCharCode(...chunk);
1596
+ }
1597
+ return btoa(output);
1598
+ }
1599
+
1600
+ // ../../node_modules/@mysten/utils/dist/esm/hex.js
1601
+ function fromHex(hexStr) {
1602
+ const normalized = hexStr.startsWith("0x") ? hexStr.slice(2) : hexStr;
1603
+ const padded = normalized.length % 2 === 0 ? normalized : `0${normalized}`;
1604
+ const intArr = padded.match(/[0-9a-fA-F]{2}/g)?.map((byte) => parseInt(byte, 16)) ?? [];
1605
+ if (intArr.length !== padded.length / 2) {
1606
+ throw new Error(`Invalid hex string ${hexStr}`);
1607
+ }
1608
+ return Uint8Array.from(intArr);
1609
+ }
1610
+ function toHex(bytes) {
1611
+ return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
1612
+ }
1613
+
1614
+ // ../../node_modules/@mysten/bcs/dist/esm/uleb.js
1615
+ function ulebEncode(num) {
1616
+ const arr = [];
1617
+ let len = 0;
1618
+ if (num === 0) {
1619
+ return [0];
1620
+ }
1621
+ while (num > 0) {
1622
+ arr[len] = num & 127;
1623
+ if (num >>= 7) {
1624
+ arr[len] |= 128;
1625
+ }
1626
+ len += 1;
1627
+ }
1628
+ return arr;
1629
+ }
1630
+ function ulebDecode(arr) {
1631
+ let total = 0;
1632
+ let shift = 0;
1633
+ let len = 0;
1634
+ while (true) {
1635
+ const byte = arr[len];
1636
+ len += 1;
1637
+ total |= (byte & 127) << shift;
1638
+ if ((byte & 128) === 0) {
1639
+ break;
1640
+ }
1641
+ shift += 7;
1642
+ }
1643
+ return {
1644
+ value: total,
1645
+ length: len
1646
+ };
1647
+ }
1648
+
1649
+ // ../../node_modules/@mysten/bcs/dist/esm/reader.js
1650
+ var BcsReader = class {
1651
+ /**
1652
+ * @param {Uint8Array} data Data to use as a buffer.
1653
+ */
1654
+ constructor(data) {
1655
+ this.bytePosition = 0;
1656
+ this.dataView = new DataView(data.buffer, data.byteOffset, data.byteLength);
1657
+ }
1658
+ /**
1659
+ * Shift current cursor position by `bytes`.
1660
+ *
1661
+ * @param {Number} bytes Number of bytes to
1662
+ * @returns {this} Self for possible chaining.
1663
+ */
1664
+ shift(bytes) {
1665
+ this.bytePosition += bytes;
1666
+ return this;
1667
+ }
1668
+ /**
1669
+ * Read U8 value from the buffer and shift cursor by 1.
1670
+ * @returns
1671
+ */
1672
+ read8() {
1673
+ const value = this.dataView.getUint8(this.bytePosition);
1674
+ this.shift(1);
1675
+ return value;
1676
+ }
1677
+ /**
1678
+ * Read U16 value from the buffer and shift cursor by 2.
1679
+ * @returns
1680
+ */
1681
+ read16() {
1682
+ const value = this.dataView.getUint16(this.bytePosition, true);
1683
+ this.shift(2);
1684
+ return value;
1685
+ }
1686
+ /**
1687
+ * Read U32 value from the buffer and shift cursor by 4.
1688
+ * @returns
1689
+ */
1690
+ read32() {
1691
+ const value = this.dataView.getUint32(this.bytePosition, true);
1692
+ this.shift(4);
1693
+ return value;
1694
+ }
1695
+ /**
1696
+ * Read U64 value from the buffer and shift cursor by 8.
1697
+ * @returns
1698
+ */
1699
+ read64() {
1700
+ const value1 = this.read32();
1701
+ const value2 = this.read32();
1702
+ const result = value2.toString(16) + value1.toString(16).padStart(8, "0");
1703
+ return BigInt("0x" + result).toString(10);
1704
+ }
1705
+ /**
1706
+ * Read U128 value from the buffer and shift cursor by 16.
1707
+ */
1708
+ read128() {
1709
+ const value1 = BigInt(this.read64());
1710
+ const value2 = BigInt(this.read64());
1711
+ const result = value2.toString(16) + value1.toString(16).padStart(16, "0");
1712
+ return BigInt("0x" + result).toString(10);
1713
+ }
1714
+ /**
1715
+ * Read U128 value from the buffer and shift cursor by 32.
1716
+ * @returns
1717
+ */
1718
+ read256() {
1719
+ const value1 = BigInt(this.read128());
1720
+ const value2 = BigInt(this.read128());
1721
+ const result = value2.toString(16) + value1.toString(16).padStart(32, "0");
1722
+ return BigInt("0x" + result).toString(10);
1723
+ }
1724
+ /**
1725
+ * Read `num` number of bytes from the buffer and shift cursor by `num`.
1726
+ * @param num Number of bytes to read.
1727
+ */
1728
+ readBytes(num) {
1729
+ const start = this.bytePosition + this.dataView.byteOffset;
1730
+ const value = new Uint8Array(this.dataView.buffer, start, num);
1731
+ this.shift(num);
1732
+ return value;
1733
+ }
1734
+ /**
1735
+ * Read ULEB value - an integer of varying size. Used for enum indexes and
1736
+ * vector lengths.
1737
+ * @returns {Number} The ULEB value.
1738
+ */
1739
+ readULEB() {
1740
+ const start = this.bytePosition + this.dataView.byteOffset;
1741
+ const buffer = new Uint8Array(this.dataView.buffer, start);
1742
+ const { value, length } = ulebDecode(buffer);
1743
+ this.shift(length);
1744
+ return value;
1745
+ }
1746
+ /**
1747
+ * Read a BCS vector: read a length and then apply function `cb` X times
1748
+ * where X is the length of the vector, defined as ULEB in BCS bytes.
1749
+ * @param cb Callback to process elements of vector.
1750
+ * @returns {Array<Any>} Array of the resulting values, returned by callback.
1751
+ */
1752
+ readVec(cb) {
1753
+ const length = this.readULEB();
1754
+ const result = [];
1755
+ for (let i = 0; i < length; i++) {
1756
+ result.push(cb(this, i, length));
1757
+ }
1758
+ return result;
1759
+ }
1760
+ };
1761
+
1762
+ // ../../node_modules/@mysten/bcs/dist/esm/utils.js
1763
+ function encodeStr(data, encoding) {
1764
+ switch (encoding) {
1765
+ case "base58":
1766
+ return toBase58(data);
1767
+ case "base64":
1768
+ return toBase64(data);
1769
+ case "hex":
1770
+ return toHex(data);
1771
+ default:
1772
+ throw new Error("Unsupported encoding, supported values are: base64, hex");
1773
+ }
508
1774
  }
509
1775
 
1776
+ // ../../node_modules/@mysten/bcs/dist/esm/writer.js
1777
+ var BcsWriter = class {
1778
+ constructor({
1779
+ initialSize = 1024,
1780
+ maxSize = Infinity,
1781
+ allocateSize = 1024
1782
+ } = {}) {
1783
+ this.bytePosition = 0;
1784
+ this.size = initialSize;
1785
+ this.maxSize = maxSize;
1786
+ this.allocateSize = allocateSize;
1787
+ this.dataView = new DataView(new ArrayBuffer(initialSize));
1788
+ }
1789
+ ensureSizeOrGrow(bytes) {
1790
+ const requiredSize = this.bytePosition + bytes;
1791
+ if (requiredSize > this.size) {
1792
+ const nextSize = Math.min(this.maxSize, this.size + this.allocateSize);
1793
+ if (requiredSize > nextSize) {
1794
+ throw new Error(
1795
+ `Attempting to serialize to BCS, but buffer does not have enough size. Allocated size: ${this.size}, Max size: ${this.maxSize}, Required size: ${requiredSize}`
1796
+ );
1797
+ }
1798
+ this.size = nextSize;
1799
+ const nextBuffer = new ArrayBuffer(this.size);
1800
+ new Uint8Array(nextBuffer).set(new Uint8Array(this.dataView.buffer));
1801
+ this.dataView = new DataView(nextBuffer);
1802
+ }
1803
+ }
1804
+ /**
1805
+ * Shift current cursor position by `bytes`.
1806
+ *
1807
+ * @param {Number} bytes Number of bytes to
1808
+ * @returns {this} Self for possible chaining.
1809
+ */
1810
+ shift(bytes) {
1811
+ this.bytePosition += bytes;
1812
+ return this;
1813
+ }
1814
+ /**
1815
+ * Write a U8 value into a buffer and shift cursor position by 1.
1816
+ * @param {Number} value Value to write.
1817
+ * @returns {this}
1818
+ */
1819
+ write8(value) {
1820
+ this.ensureSizeOrGrow(1);
1821
+ this.dataView.setUint8(this.bytePosition, Number(value));
1822
+ return this.shift(1);
1823
+ }
1824
+ /**
1825
+ * Write a U16 value into a buffer and shift cursor position by 2.
1826
+ * @param {Number} value Value to write.
1827
+ * @returns {this}
1828
+ */
1829
+ write16(value) {
1830
+ this.ensureSizeOrGrow(2);
1831
+ this.dataView.setUint16(this.bytePosition, Number(value), true);
1832
+ return this.shift(2);
1833
+ }
1834
+ /**
1835
+ * Write a U32 value into a buffer and shift cursor position by 4.
1836
+ * @param {Number} value Value to write.
1837
+ * @returns {this}
1838
+ */
1839
+ write32(value) {
1840
+ this.ensureSizeOrGrow(4);
1841
+ this.dataView.setUint32(this.bytePosition, Number(value), true);
1842
+ return this.shift(4);
1843
+ }
1844
+ /**
1845
+ * Write a U64 value into a buffer and shift cursor position by 8.
1846
+ * @param {bigint} value Value to write.
1847
+ * @returns {this}
1848
+ */
1849
+ write64(value) {
1850
+ toLittleEndian(BigInt(value), 8).forEach((el) => this.write8(el));
1851
+ return this;
1852
+ }
1853
+ /**
1854
+ * Write a U128 value into a buffer and shift cursor position by 16.
1855
+ *
1856
+ * @param {bigint} value Value to write.
1857
+ * @returns {this}
1858
+ */
1859
+ write128(value) {
1860
+ toLittleEndian(BigInt(value), 16).forEach((el) => this.write8(el));
1861
+ return this;
1862
+ }
1863
+ /**
1864
+ * Write a U256 value into a buffer and shift cursor position by 16.
1865
+ *
1866
+ * @param {bigint} value Value to write.
1867
+ * @returns {this}
1868
+ */
1869
+ write256(value) {
1870
+ toLittleEndian(BigInt(value), 32).forEach((el) => this.write8(el));
1871
+ return this;
1872
+ }
1873
+ /**
1874
+ * Write a ULEB value into a buffer and shift cursor position by number of bytes
1875
+ * written.
1876
+ * @param {Number} value Value to write.
1877
+ * @returns {this}
1878
+ */
1879
+ writeULEB(value) {
1880
+ ulebEncode(value).forEach((el) => this.write8(el));
1881
+ return this;
1882
+ }
1883
+ /**
1884
+ * Write a vector into a buffer by first writing the vector length and then calling
1885
+ * a callback on each passed value.
1886
+ *
1887
+ * @param {Array<Any>} vector Array of elements to write.
1888
+ * @param {WriteVecCb} cb Callback to call on each element of the vector.
1889
+ * @returns {this}
1890
+ */
1891
+ writeVec(vector2, cb) {
1892
+ this.writeULEB(vector2.length);
1893
+ Array.from(vector2).forEach((el, i) => cb(this, el, i, vector2.length));
1894
+ return this;
1895
+ }
1896
+ /**
1897
+ * Adds support for iterations over the object.
1898
+ * @returns {Uint8Array}
1899
+ */
1900
+ *[Symbol.iterator]() {
1901
+ for (let i = 0; i < this.bytePosition; i++) {
1902
+ yield this.dataView.getUint8(i);
1903
+ }
1904
+ return this.toBytes();
1905
+ }
1906
+ /**
1907
+ * Get underlying buffer taking only value bytes (in case initial buffer size was bigger).
1908
+ * @returns {Uint8Array} Resulting bcs.
1909
+ */
1910
+ toBytes() {
1911
+ return new Uint8Array(this.dataView.buffer.slice(0, this.bytePosition));
1912
+ }
1913
+ /**
1914
+ * Represent data as 'hex' or 'base64'
1915
+ * @param encoding Encoding to use: 'base64' or 'hex'
1916
+ */
1917
+ toString(encoding) {
1918
+ return encodeStr(this.toBytes(), encoding);
1919
+ }
1920
+ };
1921
+ function toLittleEndian(bigint, size) {
1922
+ const result = new Uint8Array(size);
1923
+ let i = 0;
1924
+ while (bigint > 0) {
1925
+ result[i] = Number(bigint % BigInt(256));
1926
+ bigint = bigint / BigInt(256);
1927
+ i += 1;
1928
+ }
1929
+ return result;
1930
+ }
1931
+
1932
+ // ../../node_modules/@mysten/bcs/dist/esm/bcs-type.js
1933
+ var __typeError = (msg) => {
1934
+ throw TypeError(msg);
1935
+ };
1936
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
1937
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1938
+ 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);
1939
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
1940
+ var _write;
1941
+ var _serialize;
1942
+ var _schema;
1943
+ var _bytes;
1944
+ var _BcsType = class _BcsType2 {
1945
+ constructor(options) {
1946
+ __privateAdd(this, _write);
1947
+ __privateAdd(this, _serialize);
1948
+ this.name = options.name;
1949
+ this.read = options.read;
1950
+ this.serializedSize = options.serializedSize ?? (() => null);
1951
+ __privateSet(this, _write, options.write);
1952
+ __privateSet(this, _serialize, options.serialize ?? ((value, options2) => {
1953
+ const writer = new BcsWriter({
1954
+ initialSize: this.serializedSize(value) ?? void 0,
1955
+ ...options2
1956
+ });
1957
+ __privateGet(this, _write).call(this, value, writer);
1958
+ return writer.toBytes();
1959
+ }));
1960
+ this.validate = options.validate ?? (() => {
1961
+ });
1962
+ }
1963
+ write(value, writer) {
1964
+ this.validate(value);
1965
+ __privateGet(this, _write).call(this, value, writer);
1966
+ }
1967
+ serialize(value, options) {
1968
+ this.validate(value);
1969
+ return new SerializedBcs(this, __privateGet(this, _serialize).call(this, value, options));
1970
+ }
1971
+ parse(bytes) {
1972
+ const reader = new BcsReader(bytes);
1973
+ return this.read(reader);
1974
+ }
1975
+ fromHex(hex) {
1976
+ return this.parse(fromHex(hex));
1977
+ }
1978
+ fromBase58(b64) {
1979
+ return this.parse(fromBase58(b64));
1980
+ }
1981
+ fromBase64(b64) {
1982
+ return this.parse(fromBase64(b64));
1983
+ }
1984
+ transform({
1985
+ name: name2,
1986
+ input,
1987
+ output,
1988
+ validate
1989
+ }) {
1990
+ return new _BcsType2({
1991
+ name: name2 ?? this.name,
1992
+ read: (reader) => output ? output(this.read(reader)) : this.read(reader),
1993
+ write: (value, writer) => __privateGet(this, _write).call(this, input ? input(value) : value, writer),
1994
+ serializedSize: (value) => this.serializedSize(input ? input(value) : value),
1995
+ serialize: (value, options) => __privateGet(this, _serialize).call(this, input ? input(value) : value, options),
1996
+ validate: (value) => {
1997
+ validate?.(value);
1998
+ this.validate(input ? input(value) : value);
1999
+ }
2000
+ });
2001
+ }
2002
+ };
2003
+ _write = /* @__PURE__ */ new WeakMap();
2004
+ _serialize = /* @__PURE__ */ new WeakMap();
2005
+ var BcsType = _BcsType;
2006
+ var SERIALIZED_BCS_BRAND = Symbol.for("@mysten/serialized-bcs");
2007
+ var SerializedBcs = class {
2008
+ constructor(schema, bytes) {
2009
+ __privateAdd(this, _schema);
2010
+ __privateAdd(this, _bytes);
2011
+ __privateSet(this, _schema, schema);
2012
+ __privateSet(this, _bytes, bytes);
2013
+ }
2014
+ // Used to brand SerializedBcs so that they can be identified, even between multiple copies
2015
+ // of the @mysten/bcs package are installed
2016
+ get [SERIALIZED_BCS_BRAND]() {
2017
+ return true;
2018
+ }
2019
+ toBytes() {
2020
+ return __privateGet(this, _bytes);
2021
+ }
2022
+ toHex() {
2023
+ return toHex(__privateGet(this, _bytes));
2024
+ }
2025
+ toBase64() {
2026
+ return toBase64(__privateGet(this, _bytes));
2027
+ }
2028
+ toBase58() {
2029
+ return toBase58(__privateGet(this, _bytes));
2030
+ }
2031
+ parse() {
2032
+ return __privateGet(this, _schema).parse(__privateGet(this, _bytes));
2033
+ }
2034
+ };
2035
+ _schema = /* @__PURE__ */ new WeakMap();
2036
+ _bytes = /* @__PURE__ */ new WeakMap();
2037
+ function fixedSizeBcsType({
2038
+ size,
2039
+ ...options
2040
+ }) {
2041
+ return new BcsType({
2042
+ ...options,
2043
+ serializedSize: () => size
2044
+ });
2045
+ }
2046
+ function uIntBcsType({
2047
+ readMethod,
2048
+ writeMethod,
2049
+ ...options
2050
+ }) {
2051
+ return fixedSizeBcsType({
2052
+ ...options,
2053
+ read: (reader) => reader[readMethod](),
2054
+ write: (value, writer) => writer[writeMethod](value),
2055
+ validate: (value) => {
2056
+ if (value < 0 || value > options.maxValue) {
2057
+ throw new TypeError(
2058
+ `Invalid ${options.name} value: ${value}. Expected value in range 0-${options.maxValue}`
2059
+ );
2060
+ }
2061
+ options.validate?.(value);
2062
+ }
2063
+ });
2064
+ }
2065
+ function bigUIntBcsType({
2066
+ readMethod,
2067
+ writeMethod,
2068
+ ...options
2069
+ }) {
2070
+ return fixedSizeBcsType({
2071
+ ...options,
2072
+ read: (reader) => reader[readMethod](),
2073
+ write: (value, writer) => writer[writeMethod](BigInt(value)),
2074
+ validate: (val) => {
2075
+ const value = BigInt(val);
2076
+ if (value < 0 || value > options.maxValue) {
2077
+ throw new TypeError(
2078
+ `Invalid ${options.name} value: ${value}. Expected value in range 0-${options.maxValue}`
2079
+ );
2080
+ }
2081
+ options.validate?.(value);
2082
+ }
2083
+ });
2084
+ }
2085
+ function dynamicSizeBcsType({
2086
+ serialize,
2087
+ ...options
2088
+ }) {
2089
+ const type = new BcsType({
2090
+ ...options,
2091
+ serialize,
2092
+ write: (value, writer) => {
2093
+ for (const byte of type.serialize(value).toBytes()) {
2094
+ writer.write8(byte);
2095
+ }
2096
+ }
2097
+ });
2098
+ return type;
2099
+ }
2100
+ function stringLikeBcsType({
2101
+ toBytes: toBytes2,
2102
+ fromBytes,
2103
+ ...options
2104
+ }) {
2105
+ return new BcsType({
2106
+ ...options,
2107
+ read: (reader) => {
2108
+ const length = reader.readULEB();
2109
+ const bytes = reader.readBytes(length);
2110
+ return fromBytes(bytes);
2111
+ },
2112
+ write: (hex, writer) => {
2113
+ const bytes = toBytes2(hex);
2114
+ writer.writeULEB(bytes.length);
2115
+ for (let i = 0; i < bytes.length; i++) {
2116
+ writer.write8(bytes[i]);
2117
+ }
2118
+ },
2119
+ serialize: (value) => {
2120
+ const bytes = toBytes2(value);
2121
+ const size = ulebEncode(bytes.length);
2122
+ const result = new Uint8Array(size.length + bytes.length);
2123
+ result.set(size, 0);
2124
+ result.set(bytes, size.length);
2125
+ return result;
2126
+ },
2127
+ validate: (value) => {
2128
+ if (typeof value !== "string") {
2129
+ throw new TypeError(`Invalid ${options.name} value: ${value}. Expected string`);
2130
+ }
2131
+ options.validate?.(value);
2132
+ }
2133
+ });
2134
+ }
2135
+ function lazyBcsType(cb) {
2136
+ let lazyType = null;
2137
+ function getType() {
2138
+ if (!lazyType) {
2139
+ lazyType = cb();
2140
+ }
2141
+ return lazyType;
2142
+ }
2143
+ return new BcsType({
2144
+ name: "lazy",
2145
+ read: (data) => getType().read(data),
2146
+ serializedSize: (value) => getType().serializedSize(value),
2147
+ write: (value, writer) => getType().write(value, writer),
2148
+ serialize: (value, options) => getType().serialize(value, options).toBytes()
2149
+ });
2150
+ }
2151
+ var BcsStruct = class extends BcsType {
2152
+ constructor({ name: name2, fields, ...options }) {
2153
+ const canonicalOrder = Object.entries(fields);
2154
+ super({
2155
+ name: name2,
2156
+ serializedSize: (values) => {
2157
+ let total = 0;
2158
+ for (const [field, type] of canonicalOrder) {
2159
+ const size = type.serializedSize(values[field]);
2160
+ if (size == null) {
2161
+ return null;
2162
+ }
2163
+ total += size;
2164
+ }
2165
+ return total;
2166
+ },
2167
+ read: (reader) => {
2168
+ const result = {};
2169
+ for (const [field, type] of canonicalOrder) {
2170
+ result[field] = type.read(reader);
2171
+ }
2172
+ return result;
2173
+ },
2174
+ write: (value, writer) => {
2175
+ for (const [field, type] of canonicalOrder) {
2176
+ type.write(value[field], writer);
2177
+ }
2178
+ },
2179
+ ...options,
2180
+ validate: (value) => {
2181
+ options?.validate?.(value);
2182
+ if (typeof value !== "object" || value == null) {
2183
+ throw new TypeError(`Expected object, found ${typeof value}`);
2184
+ }
2185
+ }
2186
+ });
2187
+ }
2188
+ };
2189
+ var BcsEnum = class extends BcsType {
2190
+ constructor({ fields, ...options }) {
2191
+ const canonicalOrder = Object.entries(fields);
2192
+ super({
2193
+ read: (reader) => {
2194
+ const index = reader.readULEB();
2195
+ const enumEntry = canonicalOrder[index];
2196
+ if (!enumEntry) {
2197
+ throw new TypeError(`Unknown value ${index} for enum ${name}`);
2198
+ }
2199
+ const [kind, type] = enumEntry;
2200
+ return {
2201
+ [kind]: type?.read(reader) ?? true,
2202
+ $kind: kind
2203
+ };
2204
+ },
2205
+ write: (value, writer) => {
2206
+ const [name2, val] = Object.entries(value).filter(
2207
+ ([name3]) => Object.hasOwn(fields, name3)
2208
+ )[0];
2209
+ for (let i = 0; i < canonicalOrder.length; i++) {
2210
+ const [optionName, optionType] = canonicalOrder[i];
2211
+ if (optionName === name2) {
2212
+ writer.writeULEB(i);
2213
+ optionType?.write(val, writer);
2214
+ return;
2215
+ }
2216
+ }
2217
+ },
2218
+ ...options,
2219
+ validate: (value) => {
2220
+ options?.validate?.(value);
2221
+ if (typeof value !== "object" || value == null) {
2222
+ throw new TypeError(`Expected object, found ${typeof value}`);
2223
+ }
2224
+ const keys = Object.keys(value).filter(
2225
+ (k) => value[k] !== void 0 && Object.hasOwn(fields, k)
2226
+ );
2227
+ if (keys.length !== 1) {
2228
+ throw new TypeError(
2229
+ `Expected object with one key, but found ${keys.length} for type ${name}}`
2230
+ );
2231
+ }
2232
+ const [variant] = keys;
2233
+ if (!Object.hasOwn(fields, variant)) {
2234
+ throw new TypeError(`Invalid enum variant ${variant}`);
2235
+ }
2236
+ }
2237
+ });
2238
+ }
2239
+ };
2240
+ var BcsTuple = class extends BcsType {
2241
+ constructor({ fields, name: name2, ...options }) {
2242
+ super({
2243
+ name: name2 ?? `(${fields.map((t) => t.name).join(", ")})`,
2244
+ serializedSize: (values) => {
2245
+ let total = 0;
2246
+ for (let i = 0; i < fields.length; i++) {
2247
+ const size = fields[i].serializedSize(values[i]);
2248
+ if (size == null) {
2249
+ return null;
2250
+ }
2251
+ total += size;
2252
+ }
2253
+ return total;
2254
+ },
2255
+ read: (reader) => {
2256
+ const result = [];
2257
+ for (const field of fields) {
2258
+ result.push(field.read(reader));
2259
+ }
2260
+ return result;
2261
+ },
2262
+ write: (value, writer) => {
2263
+ for (let i = 0; i < fields.length; i++) {
2264
+ fields[i].write(value[i], writer);
2265
+ }
2266
+ },
2267
+ ...options,
2268
+ validate: (value) => {
2269
+ options?.validate?.(value);
2270
+ if (!Array.isArray(value)) {
2271
+ throw new TypeError(`Expected array, found ${typeof value}`);
2272
+ }
2273
+ if (value.length !== fields.length) {
2274
+ throw new TypeError(`Expected array of length ${fields.length}, found ${value.length}`);
2275
+ }
2276
+ }
2277
+ });
2278
+ }
2279
+ };
2280
+
2281
+ // ../../node_modules/@mysten/bcs/dist/esm/bcs.js
2282
+ function fixedArray(size, type, options) {
2283
+ return new BcsType({
2284
+ read: (reader) => {
2285
+ const result = new Array(size);
2286
+ for (let i = 0; i < size; i++) {
2287
+ result[i] = type.read(reader);
2288
+ }
2289
+ return result;
2290
+ },
2291
+ write: (value, writer) => {
2292
+ for (const item of value) {
2293
+ type.write(item, writer);
2294
+ }
2295
+ },
2296
+ ...options,
2297
+ name: options?.name ?? `${type.name}[${size}]`,
2298
+ validate: (value) => {
2299
+ options?.validate?.(value);
2300
+ if (!value || typeof value !== "object" || !("length" in value)) {
2301
+ throw new TypeError(`Expected array, found ${typeof value}`);
2302
+ }
2303
+ if (value.length !== size) {
2304
+ throw new TypeError(`Expected array of length ${size}, found ${value.length}`);
2305
+ }
2306
+ }
2307
+ });
2308
+ }
2309
+ function option(type) {
2310
+ return bcs.enum(`Option<${type.name}>`, {
2311
+ None: null,
2312
+ Some: type
2313
+ }).transform({
2314
+ input: (value) => {
2315
+ if (value == null) {
2316
+ return { None: true };
2317
+ }
2318
+ return { Some: value };
2319
+ },
2320
+ output: (value) => {
2321
+ if (value.$kind === "Some") {
2322
+ return value.Some;
2323
+ }
2324
+ return null;
2325
+ }
2326
+ });
2327
+ }
2328
+ function vector(type, options) {
2329
+ return new BcsType({
2330
+ read: (reader) => {
2331
+ const length = reader.readULEB();
2332
+ const result = new Array(length);
2333
+ for (let i = 0; i < length; i++) {
2334
+ result[i] = type.read(reader);
2335
+ }
2336
+ return result;
2337
+ },
2338
+ write: (value, writer) => {
2339
+ writer.writeULEB(value.length);
2340
+ for (const item of value) {
2341
+ type.write(item, writer);
2342
+ }
2343
+ },
2344
+ ...options,
2345
+ name: options?.name ?? `vector<${type.name}>`,
2346
+ validate: (value) => {
2347
+ options?.validate?.(value);
2348
+ if (!value || typeof value !== "object" || !("length" in value)) {
2349
+ throw new TypeError(`Expected array, found ${typeof value}`);
2350
+ }
2351
+ }
2352
+ });
2353
+ }
2354
+ function map(keyType, valueType) {
2355
+ return bcs.vector(bcs.tuple([keyType, valueType])).transform({
2356
+ name: `Map<${keyType.name}, ${valueType.name}>`,
2357
+ input: (value) => {
2358
+ return [...value.entries()];
2359
+ },
2360
+ output: (value) => {
2361
+ const result = /* @__PURE__ */ new Map();
2362
+ for (const [key, val] of value) {
2363
+ result.set(key, val);
2364
+ }
2365
+ return result;
2366
+ }
2367
+ });
2368
+ }
2369
+ var bcs = {
2370
+ /**
2371
+ * Creates a BcsType that can be used to read and write an 8-bit unsigned integer.
2372
+ * @example
2373
+ * bcs.u8().serialize(255).toBytes() // Uint8Array [ 255 ]
2374
+ */
2375
+ u8(options) {
2376
+ return uIntBcsType({
2377
+ readMethod: "read8",
2378
+ writeMethod: "write8",
2379
+ size: 1,
2380
+ maxValue: 2 ** 8 - 1,
2381
+ ...options,
2382
+ name: options?.name ?? "u8"
2383
+ });
2384
+ },
2385
+ /**
2386
+ * Creates a BcsType that can be used to read and write a 16-bit unsigned integer.
2387
+ * @example
2388
+ * bcs.u16().serialize(65535).toBytes() // Uint8Array [ 255, 255 ]
2389
+ */
2390
+ u16(options) {
2391
+ return uIntBcsType({
2392
+ readMethod: "read16",
2393
+ writeMethod: "write16",
2394
+ size: 2,
2395
+ maxValue: 2 ** 16 - 1,
2396
+ ...options,
2397
+ name: options?.name ?? "u16"
2398
+ });
2399
+ },
2400
+ /**
2401
+ * Creates a BcsType that can be used to read and write a 32-bit unsigned integer.
2402
+ * @example
2403
+ * bcs.u32().serialize(4294967295).toBytes() // Uint8Array [ 255, 255, 255, 255 ]
2404
+ */
2405
+ u32(options) {
2406
+ return uIntBcsType({
2407
+ readMethod: "read32",
2408
+ writeMethod: "write32",
2409
+ size: 4,
2410
+ maxValue: 2 ** 32 - 1,
2411
+ ...options,
2412
+ name: options?.name ?? "u32"
2413
+ });
2414
+ },
2415
+ /**
2416
+ * Creates a BcsType that can be used to read and write a 64-bit unsigned integer.
2417
+ * @example
2418
+ * bcs.u64().serialize(1).toBytes() // Uint8Array [ 1, 0, 0, 0, 0, 0, 0, 0 ]
2419
+ */
2420
+ u64(options) {
2421
+ return bigUIntBcsType({
2422
+ readMethod: "read64",
2423
+ writeMethod: "write64",
2424
+ size: 8,
2425
+ maxValue: 2n ** 64n - 1n,
2426
+ ...options,
2427
+ name: options?.name ?? "u64"
2428
+ });
2429
+ },
2430
+ /**
2431
+ * Creates a BcsType that can be used to read and write a 128-bit unsigned integer.
2432
+ * @example
2433
+ * bcs.u128().serialize(1).toBytes() // Uint8Array [ 1, ..., 0 ]
2434
+ */
2435
+ u128(options) {
2436
+ return bigUIntBcsType({
2437
+ readMethod: "read128",
2438
+ writeMethod: "write128",
2439
+ size: 16,
2440
+ maxValue: 2n ** 128n - 1n,
2441
+ ...options,
2442
+ name: options?.name ?? "u128"
2443
+ });
2444
+ },
2445
+ /**
2446
+ * Creates a BcsType that can be used to read and write a 256-bit unsigned integer.
2447
+ * @example
2448
+ * bcs.u256().serialize(1).toBytes() // Uint8Array [ 1, ..., 0 ]
2449
+ */
2450
+ u256(options) {
2451
+ return bigUIntBcsType({
2452
+ readMethod: "read256",
2453
+ writeMethod: "write256",
2454
+ size: 32,
2455
+ maxValue: 2n ** 256n - 1n,
2456
+ ...options,
2457
+ name: options?.name ?? "u256"
2458
+ });
2459
+ },
2460
+ /**
2461
+ * Creates a BcsType that can be used to read and write boolean values.
2462
+ * @example
2463
+ * bcs.bool().serialize(true).toBytes() // Uint8Array [ 1 ]
2464
+ */
2465
+ bool(options) {
2466
+ return fixedSizeBcsType({
2467
+ size: 1,
2468
+ read: (reader) => reader.read8() === 1,
2469
+ write: (value, writer) => writer.write8(value ? 1 : 0),
2470
+ ...options,
2471
+ name: options?.name ?? "bool",
2472
+ validate: (value) => {
2473
+ options?.validate?.(value);
2474
+ if (typeof value !== "boolean") {
2475
+ throw new TypeError(`Expected boolean, found ${typeof value}`);
2476
+ }
2477
+ }
2478
+ });
2479
+ },
2480
+ /**
2481
+ * Creates a BcsType that can be used to read and write unsigned LEB encoded integers
2482
+ * @example
2483
+ *
2484
+ */
2485
+ uleb128(options) {
2486
+ return dynamicSizeBcsType({
2487
+ read: (reader) => reader.readULEB(),
2488
+ serialize: (value) => {
2489
+ return Uint8Array.from(ulebEncode(value));
2490
+ },
2491
+ ...options,
2492
+ name: options?.name ?? "uleb128"
2493
+ });
2494
+ },
2495
+ /**
2496
+ * Creates a BcsType representing a fixed length byte array
2497
+ * @param size The number of bytes this types represents
2498
+ * @example
2499
+ * bcs.bytes(3).serialize(new Uint8Array([1, 2, 3])).toBytes() // Uint8Array [1, 2, 3]
2500
+ */
2501
+ bytes(size, options) {
2502
+ return fixedSizeBcsType({
2503
+ size,
2504
+ read: (reader) => reader.readBytes(size),
2505
+ write: (value, writer) => {
2506
+ const array = new Uint8Array(value);
2507
+ for (let i = 0; i < size; i++) {
2508
+ writer.write8(array[i] ?? 0);
2509
+ }
2510
+ },
2511
+ ...options,
2512
+ name: options?.name ?? `bytes[${size}]`,
2513
+ validate: (value) => {
2514
+ options?.validate?.(value);
2515
+ if (!value || typeof value !== "object" || !("length" in value)) {
2516
+ throw new TypeError(`Expected array, found ${typeof value}`);
2517
+ }
2518
+ if (value.length !== size) {
2519
+ throw new TypeError(`Expected array of length ${size}, found ${value.length}`);
2520
+ }
2521
+ }
2522
+ });
2523
+ },
2524
+ /**
2525
+ * Creates a BcsType representing a variable length byte array
2526
+ *
2527
+ * @example
2528
+ * bcs.byteVector().serialize([1, 2, 3]).toBytes() // Uint8Array [3, 1, 2, 3]
2529
+ */
2530
+ byteVector(options) {
2531
+ return new BcsType({
2532
+ read: (reader) => {
2533
+ const length = reader.readULEB();
2534
+ return reader.readBytes(length);
2535
+ },
2536
+ write: (value, writer) => {
2537
+ const array = new Uint8Array(value);
2538
+ writer.writeULEB(array.length);
2539
+ for (let i = 0; i < array.length; i++) {
2540
+ writer.write8(array[i] ?? 0);
2541
+ }
2542
+ },
2543
+ ...options,
2544
+ name: options?.name ?? "vector<u8>",
2545
+ serializedSize: (value) => {
2546
+ const length = "length" in value ? value.length : null;
2547
+ return length == null ? null : ulebEncode(length).length + length;
2548
+ },
2549
+ validate: (value) => {
2550
+ options?.validate?.(value);
2551
+ if (!value || typeof value !== "object" || !("length" in value)) {
2552
+ throw new TypeError(`Expected array, found ${typeof value}`);
2553
+ }
2554
+ }
2555
+ });
2556
+ },
2557
+ /**
2558
+ * Creates a BcsType that can ser/de string values. Strings will be UTF-8 encoded
2559
+ * @example
2560
+ * bcs.string().serialize('a').toBytes() // Uint8Array [ 1, 97 ]
2561
+ */
2562
+ string(options) {
2563
+ return stringLikeBcsType({
2564
+ toBytes: (value) => new TextEncoder().encode(value),
2565
+ fromBytes: (bytes) => new TextDecoder().decode(bytes),
2566
+ ...options,
2567
+ name: options?.name ?? "string"
2568
+ });
2569
+ },
2570
+ /**
2571
+ * Creates a BcsType that represents a fixed length array of a given type
2572
+ * @param size The number of elements in the array
2573
+ * @param type The BcsType of each element in the array
2574
+ * @example
2575
+ * bcs.fixedArray(3, bcs.u8()).serialize([1, 2, 3]).toBytes() // Uint8Array [ 1, 2, 3 ]
2576
+ */
2577
+ fixedArray,
2578
+ /**
2579
+ * Creates a BcsType representing an optional value
2580
+ * @param type The BcsType of the optional value
2581
+ * @example
2582
+ * bcs.option(bcs.u8()).serialize(null).toBytes() // Uint8Array [ 0 ]
2583
+ * bcs.option(bcs.u8()).serialize(1).toBytes() // Uint8Array [ 1, 1 ]
2584
+ */
2585
+ option,
2586
+ /**
2587
+ * Creates a BcsType representing a variable length vector of a given type
2588
+ * @param type The BcsType of each element in the vector
2589
+ *
2590
+ * @example
2591
+ * bcs.vector(bcs.u8()).toBytes([1, 2, 3]) // Uint8Array [ 3, 1, 2, 3 ]
2592
+ */
2593
+ vector,
2594
+ /**
2595
+ * Creates a BcsType representing a tuple of a given set of types
2596
+ * @param types The BcsTypes for each element in the tuple
2597
+ *
2598
+ * @example
2599
+ * const tuple = bcs.tuple([bcs.u8(), bcs.string(), bcs.bool()])
2600
+ * tuple.serialize([1, 'a', true]).toBytes() // Uint8Array [ 1, 1, 97, 1 ]
2601
+ */
2602
+ tuple(fields, options) {
2603
+ return new BcsTuple({
2604
+ fields,
2605
+ ...options
2606
+ });
2607
+ },
2608
+ /**
2609
+ * Creates a BcsType representing a struct of a given set of fields
2610
+ * @param name The name of the struct
2611
+ * @param fields The fields of the struct. The order of the fields affects how data is serialized and deserialized
2612
+ *
2613
+ * @example
2614
+ * const struct = bcs.struct('MyStruct', {
2615
+ * a: bcs.u8(),
2616
+ * b: bcs.string(),
2617
+ * })
2618
+ * struct.serialize({ a: 1, b: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
2619
+ */
2620
+ struct(name2, fields, options) {
2621
+ return new BcsStruct({
2622
+ name: name2,
2623
+ fields,
2624
+ ...options
2625
+ });
2626
+ },
2627
+ /**
2628
+ * Creates a BcsType representing an enum of a given set of options
2629
+ * @param name The name of the enum
2630
+ * @param values The values of the enum. The order of the values affects how data is serialized and deserialized.
2631
+ * null can be used to represent a variant with no data.
2632
+ *
2633
+ * @example
2634
+ * const enum = bcs.enum('MyEnum', {
2635
+ * A: bcs.u8(),
2636
+ * B: bcs.string(),
2637
+ * C: null,
2638
+ * })
2639
+ * enum.serialize({ A: 1 }).toBytes() // Uint8Array [ 0, 1 ]
2640
+ * enum.serialize({ B: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
2641
+ * enum.serialize({ C: true }).toBytes() // Uint8Array [ 2 ]
2642
+ */
2643
+ enum(name2, fields, options) {
2644
+ return new BcsEnum({
2645
+ name: name2,
2646
+ fields,
2647
+ ...options
2648
+ });
2649
+ },
2650
+ /**
2651
+ * Creates a BcsType representing a map of a given key and value type
2652
+ * @param keyType The BcsType of the key
2653
+ * @param valueType The BcsType of the value
2654
+ * @example
2655
+ * const map = bcs.map(bcs.u8(), bcs.string())
2656
+ * map.serialize(new Map([[2, 'a']])).toBytes() // Uint8Array [ 1, 2, 1, 97 ]
2657
+ */
2658
+ map,
2659
+ /**
2660
+ * Creates a BcsType that wraps another BcsType which is lazily evaluated. This is useful for creating recursive types.
2661
+ * @param cb A callback that returns the BcsType
2662
+ */
2663
+ lazy(cb) {
2664
+ return lazyBcsType(cb);
2665
+ }
2666
+ };
2667
+
510
2668
  // src/sdk/types.ts
511
- var import_bcs2 = require("@mysten/bcs");
512
2669
  BigInt.prototype.toJSON = function() {
513
2670
  return Number(this);
514
2671
  };
515
- var Bytes32 = import_bcs2.bcs.fixedArray(32, import_bcs2.bcs.u8());
516
- var Bytes64 = import_bcs2.bcs.fixedArray(64, import_bcs2.bcs.u8());
2672
+ var Bytes32 = bcs.fixedArray(32, bcs.u8());
2673
+ var Bytes64 = bcs.fixedArray(64, bcs.u8());
517
2674
  var PublicKey = Bytes32;
518
2675
  var Signature = Bytes64;
519
- var Address = import_bcs2.bcs.enum("Address", {
2676
+ var Address = bcs.enum("Address", {
520
2677
  External: PublicKey,
521
2678
  FastSet: PublicKey
522
2679
  });
523
- var Amount = import_bcs2.bcs.u256().transform({
2680
+ var Amount = bcs.u256().transform({
524
2681
  // CAUTION: When we build a transaction object, we must use a hex encoded string because the
525
2682
  // validator expects amounts to be in hex. However, bcs.u256() by default expects a decimal
526
2683
  // string. Therefore, we must transform the input amount from hex to decimal here.
527
2684
  input: (val) => hexToDecimal(val.toString()),
528
2685
  output: (value) => value
529
2686
  });
530
- var Balance = import_bcs2.bcs.string().transform({
2687
+ var Balance = bcs.string().transform({
531
2688
  input: (val) => val,
532
2689
  output: (value) => value
533
2690
  });
534
- var UserData = import_bcs2.bcs.option(Bytes32);
535
- var Nonce = import_bcs2.bcs.u64();
536
- var Quorum = import_bcs2.bcs.u64();
2691
+ var UserData = bcs.option(Bytes32);
2692
+ var Nonce = bcs.u64();
2693
+ var Quorum = bcs.u64();
537
2694
  var TokenId = Bytes32;
538
- var Transfer = import_bcs2.bcs.struct("Transfer", {
2695
+ var Transfer = bcs.struct("Transfer", {
539
2696
  amount: Amount,
540
2697
  user_data: UserData
541
2698
  });
542
- var TokenTransfer = import_bcs2.bcs.struct("TokenTransfer", {
2699
+ var TokenTransfer = bcs.struct("TokenTransfer", {
543
2700
  token_id: TokenId,
544
2701
  amount: Amount,
545
2702
  user_data: UserData
546
2703
  });
547
- var TokenCreation = import_bcs2.bcs.struct("TokenCreation", {
548
- token_name: import_bcs2.bcs.string(),
549
- decimals: import_bcs2.bcs.u8(),
2704
+ var TokenCreation = bcs.struct("TokenCreation", {
2705
+ token_name: bcs.string(),
2706
+ decimals: bcs.u8(),
550
2707
  initial_amount: Amount,
551
- mints: import_bcs2.bcs.vector(PublicKey),
2708
+ mints: bcs.vector(PublicKey),
552
2709
  user_data: UserData
553
2710
  });
554
- var AddressChange = import_bcs2.bcs.enum("AddressChange", {
2711
+ var AddressChange = bcs.enum("AddressChange", {
555
2712
  Add: PublicKey,
556
2713
  Remove: PublicKey
557
2714
  });
558
- var TokenManagement = import_bcs2.bcs.struct("TokenManagement", {
2715
+ var TokenManagement = bcs.struct("TokenManagement", {
559
2716
  token_id: TokenId,
560
2717
  update_id: Nonce,
561
- new_admin: import_bcs2.bcs.option(PublicKey),
562
- mints: import_bcs2.bcs.vector(import_bcs2.bcs.tuple([AddressChange, PublicKey])),
2718
+ new_admin: bcs.option(PublicKey),
2719
+ mints: bcs.vector(bcs.tuple([AddressChange, PublicKey])),
563
2720
  user_data: UserData
564
2721
  });
565
- var Mint = import_bcs2.bcs.struct("Mint", {
2722
+ var Mint = bcs.struct("Mint", {
566
2723
  token_id: TokenId,
567
2724
  amount: Amount
568
2725
  });
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),
2726
+ var ClaimData = bcs.vector(bcs.u8());
2727
+ var ExternalClaimBody = bcs.struct("ExternalClaimBody", {
2728
+ verifier_committee: bcs.vector(PublicKey),
572
2729
  verifier_quorum: Quorum,
573
2730
  claim_data: ClaimData
574
2731
  });
575
- var ExternalClaim = import_bcs2.bcs.struct("ExternalClaim", {
2732
+ var ExternalClaim = bcs.struct("ExternalClaim", {
576
2733
  claim: ExternalClaimBody,
577
- signatures: import_bcs2.bcs.vector(import_bcs2.bcs.tuple([PublicKey, Signature]))
2734
+ signatures: bcs.vector(bcs.tuple([PublicKey, Signature]))
578
2735
  });
579
- var ClaimType = import_bcs2.bcs.enum("ClaimType", {
2736
+ var ClaimType = bcs.enum("ClaimType", {
580
2737
  Transfer,
581
2738
  TokenTransfer,
582
2739
  TokenCreation,
@@ -584,26 +2741,26 @@ var ClaimType = import_bcs2.bcs.enum("ClaimType", {
584
2741
  Mint,
585
2742
  ExternalClaim
586
2743
  });
587
- var Transaction = import_bcs2.bcs.struct("Transaction", {
2744
+ var Transaction = bcs.struct("Transaction", {
588
2745
  sender: PublicKey,
589
2746
  recipient: Address,
590
2747
  nonce: Nonce,
591
- timestamp_nanos: import_bcs2.bcs.u128(),
2748
+ timestamp_nanos: bcs.u128(),
592
2749
  claim: ClaimType
593
2750
  });
594
- var SubmitTransactionResponse = import_bcs2.bcs.struct("SubmitTransactionResponse", {
2751
+ var SubmitTransactionResponse = bcs.struct("SubmitTransactionResponse", {
595
2752
  validator: PublicKey,
596
2753
  signature: Signature,
597
2754
  next_nonce: Nonce,
598
- transaction_hash: import_bcs2.bcs.vector(import_bcs2.bcs.u8())
2755
+ transaction_hash: bcs.vector(bcs.u8())
599
2756
  });
600
- var TransactionEnvelope = import_bcs2.bcs.struct("TransactionEnvelope", {
2757
+ var TransactionEnvelope = bcs.struct("TransactionEnvelope", {
601
2758
  transaction: Transaction,
602
2759
  signature: Signature
603
2760
  });
604
- var TransactionCertificate = import_bcs2.bcs.struct("TransactionCertificate", {
2761
+ var TransactionCertificate = bcs.struct("TransactionCertificate", {
605
2762
  envelope: TransactionEnvelope,
606
- signatures: import_bcs2.bcs.vector(import_bcs2.bcs.tuple([PublicKey, Signature]))
2763
+ signatures: bcs.vector(bcs.tuple([PublicKey, Signature]))
607
2764
  });
608
2765
  function hexToDecimal(hex) {
609
2766
  return BigInt(`0x${hex}`).toString();
@@ -611,13 +2768,10 @@ function hexToDecimal(hex) {
611
2768
 
612
2769
  // src/WarpFastsetWallet.ts
613
2770
  var WarpFastsetWallet = class {
614
- constructor(config, chain) {
2771
+ constructor(config, chain2) {
615
2772
  this.config = config;
616
- this.chain = chain;
2773
+ this.chain = chain2;
617
2774
  this.client = getConfiguredFastsetClient(this.config, this.chain);
618
- const privateKey = (0, import_warps5.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
619
- if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
620
- this.privateKey = privateKey;
621
2775
  }
622
2776
  async signTransaction(tx) {
623
2777
  const msg = Transaction.serialize(tx);
@@ -626,20 +2780,23 @@ var WarpFastsetWallet = class {
626
2780
  const dataToSign = new Uint8Array(prefix.length + msgBytes.length);
627
2781
  dataToSign.set(prefix, 0);
628
2782
  dataToSign.set(msgBytes, prefix.length);
629
- const signature = ed.sign(dataToSign, this.privateKey);
2783
+ const privateKey = (0, import_warps5.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
2784
+ if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
2785
+ const privateKeyBytes = hexToUint8Array(privateKey);
2786
+ const signature = ed25519_exports.sign(dataToSign, privateKeyBytes);
630
2787
  return { ...tx, signature };
631
2788
  }
632
2789
  async signMessage(message) {
633
2790
  const messageBytes = stringToUint8Array(message);
634
- const signature = ed.sign(messageBytes, this.privateKey);
2791
+ const privateKey = (0, import_warps5.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
2792
+ if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
2793
+ const privateKeyBytes = hexToUint8Array(privateKey);
2794
+ const signature = ed25519_exports.sign(messageBytes, privateKeyBytes);
635
2795
  return uint8ArrayToHex(signature);
636
2796
  }
637
2797
  async sendTransaction(tx) {
638
2798
  const { signature, ...transactionWithoutSignature } = tx;
639
- const submitTxReq = {
640
- transaction: transactionWithoutSignature,
641
- signature
642
- };
2799
+ const submitTxReq = { transaction: transactionWithoutSignature, signature };
643
2800
  const proxyUrl = (0, import_warps5.getProviderUrl)(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
644
2801
  const response = await this.client.request(proxyUrl, "set_proxy_submitTransaction", submitTxReq);
645
2802
  if (response.error) throw new Error(`JSON-RPC error ${response.error.code}: ${response.error.message}`);
@@ -649,13 +2806,13 @@ var WarpFastsetWallet = class {
649
2806
  create(mnemonic) {
650
2807
  const seed = bip39.mnemonicToSeedSync(mnemonic);
651
2808
  const privateKey = seed.slice(0, 32);
652
- const publicKey = ed.getPublicKey(privateKey);
2809
+ const publicKey = ed25519_exports.getPublicKey(privateKey);
653
2810
  const address = FastsetClient.encodeBech32Address(publicKey);
654
2811
  return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic };
655
2812
  }
656
2813
  generate() {
657
- const privateKey = ed.utils.randomPrivateKey();
658
- const publicKey = ed.getPublicKey(privateKey);
2814
+ const privateKey = ed25519_exports.utils.randomPrivateKey();
2815
+ const publicKey = ed25519_exports.getPublicKey(privateKey);
659
2816
  const address = FastsetClient.encodeBech32Address(publicKey);
660
2817
  return { address, privateKey: uint8ArrayToHex(privateKey), mnemonic: null };
661
2818
  }
@@ -734,4 +2891,15 @@ var getFastsetAdapter = createFastsetAdapter(import_warps6.WarpChainName.Fastset
734
2891
  WarpFastsetWallet,
735
2892
  getFastsetAdapter
736
2893
  });
2894
+ /*! Bundled license information:
2895
+
2896
+ @noble/ed25519/index.js:
2897
+ (*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) *)
2898
+
2899
+ @noble/hashes/esm/utils.js:
2900
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2901
+
2902
+ @scure/base/lib/esm/index.js:
2903
+ (*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
2904
+ */
737
2905
  //# sourceMappingURL=index.js.map