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