@fuel-ts/account 0.0.0-rc-2238-20240514192918 → 0.0.0-rc-2143-20240514211533

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.

Potentially problematic release.


This version of @fuel-ts/account might be problematic. Click here for more details.

@@ -73,7 +73,7 @@
73
73
  "../../node_modules/.pnpm/bn.js@5.2.1/node_modules/bn.js/lib/bn.js"(exports, module) {
74
74
  (function(module2, exports2) {
75
75
  "use strict";
76
- function assert3(val, msg) {
76
+ function assert2(val, msg) {
77
77
  if (!val)
78
78
  throw new Error(msg || "Assertion failed");
79
79
  }
@@ -143,7 +143,7 @@
143
143
  if (base === "hex") {
144
144
  base = 16;
145
145
  }
146
- assert3(base === (base | 0) && base >= 2 && base <= 36);
146
+ assert2(base === (base | 0) && base >= 2 && base <= 36);
147
147
  number2 = number2.toString().replace(/\s+/g, "");
148
148
  var start = 0;
149
149
  if (number2[0] === "-") {
@@ -176,7 +176,7 @@
176
176
  ];
177
177
  this.length = 2;
178
178
  } else {
179
- assert3(number2 < 9007199254740992);
179
+ assert2(number2 < 9007199254740992);
180
180
  this.words = [
181
181
  number2 & 67108863,
182
182
  number2 / 67108864 & 67108863,
@@ -189,7 +189,7 @@
189
189
  this._initArray(this.toArray(), base, endian);
190
190
  };
191
191
  BN2.prototype._initArray = function _initArray(number2, base, endian) {
192
- assert3(typeof number2.length === "number");
192
+ assert2(typeof number2.length === "number");
193
193
  if (number2.length <= 0) {
194
194
  this.words = [0];
195
195
  this.length = 1;
@@ -236,7 +236,7 @@
236
236
  } else if (c >= 97 && c <= 102) {
237
237
  return c - 87;
238
238
  } else {
239
- assert3(false, "Invalid character in " + string);
239
+ assert2(false, "Invalid character in " + string);
240
240
  }
241
241
  }
242
242
  function parseHexByte(string, lowerBound, index) {
@@ -297,7 +297,7 @@
297
297
  } else {
298
298
  b = c;
299
299
  }
300
- assert3(c >= 0 && b < mul, "Invalid character");
300
+ assert2(c >= 0 && b < mul, "Invalid character");
301
301
  r += b;
302
302
  }
303
303
  return r;
@@ -557,16 +557,16 @@
557
557
  }
558
558
  return out;
559
559
  }
560
- assert3(false, "Base should be between 2 and 36");
560
+ assert2(false, "Base should be between 2 and 36");
561
561
  };
562
- BN2.prototype.toNumber = function toNumber3() {
562
+ BN2.prototype.toNumber = function toNumber2() {
563
563
  var ret2 = this.words[0];
564
564
  if (this.length === 2) {
565
565
  ret2 += this.words[1] * 67108864;
566
566
  } else if (this.length === 3 && this.words[2] === 1) {
567
567
  ret2 += 4503599627370496 + this.words[1] * 67108864;
568
568
  } else if (this.length > 2) {
569
- assert3(false, "Number can only safely store up to 53 bits");
569
+ assert2(false, "Number can only safely store up to 53 bits");
570
570
  }
571
571
  return this.negative !== 0 ? -ret2 : ret2;
572
572
  };
@@ -591,8 +591,8 @@
591
591
  this._strip();
592
592
  var byteLength = this.byteLength();
593
593
  var reqLength = length || Math.max(1, byteLength);
594
- assert3(byteLength <= reqLength, "byte array longer than desired length");
595
- assert3(reqLength > 0, "Requested array length <= 0");
594
+ assert2(byteLength <= reqLength, "byte array longer than desired length");
595
+ assert2(reqLength > 0, "Requested array length <= 0");
596
596
  var res = allocate(ArrayType, reqLength);
597
597
  var postfix = endian === "le" ? "LE" : "BE";
598
598
  this["_toArrayLike" + postfix](res, byteLength);
@@ -740,13 +740,13 @@
740
740
  BN2.prototype.byteLength = function byteLength() {
741
741
  return Math.ceil(this.bitLength() / 8);
742
742
  };
743
- BN2.prototype.toTwos = function toTwos2(width) {
743
+ BN2.prototype.toTwos = function toTwos(width) {
744
744
  if (this.negative !== 0) {
745
745
  return this.abs().inotn(width).iaddn(1);
746
746
  }
747
747
  return this.clone();
748
748
  };
749
- BN2.prototype.fromTwos = function fromTwos2(width) {
749
+ BN2.prototype.fromTwos = function fromTwos(width) {
750
750
  if (this.testn(width - 1)) {
751
751
  return this.notn(width).iaddn(1).ineg();
752
752
  }
@@ -774,7 +774,7 @@
774
774
  return this._strip();
775
775
  };
776
776
  BN2.prototype.ior = function ior(num) {
777
- assert3((this.negative | num.negative) === 0);
777
+ assert2((this.negative | num.negative) === 0);
778
778
  return this.iuor(num);
779
779
  };
780
780
  BN2.prototype.or = function or(num) {
@@ -801,7 +801,7 @@
801
801
  return this._strip();
802
802
  };
803
803
  BN2.prototype.iand = function iand(num) {
804
- assert3((this.negative | num.negative) === 0);
804
+ assert2((this.negative | num.negative) === 0);
805
805
  return this.iuand(num);
806
806
  };
807
807
  BN2.prototype.and = function and(num) {
@@ -836,7 +836,7 @@
836
836
  return this._strip();
837
837
  };
838
838
  BN2.prototype.ixor = function ixor(num) {
839
- assert3((this.negative | num.negative) === 0);
839
+ assert2((this.negative | num.negative) === 0);
840
840
  return this.iuxor(num);
841
841
  };
842
842
  BN2.prototype.xor = function xor(num) {
@@ -850,7 +850,7 @@
850
850
  return num.clone().iuxor(this);
851
851
  };
852
852
  BN2.prototype.inotn = function inotn(width) {
853
- assert3(typeof width === "number" && width >= 0);
853
+ assert2(typeof width === "number" && width >= 0);
854
854
  var bytesNeeded = Math.ceil(width / 26) | 0;
855
855
  var bitsLeft = width % 26;
856
856
  this._expand(bytesNeeded);
@@ -869,7 +869,7 @@
869
869
  return this.clone().inotn(width);
870
870
  };
871
871
  BN2.prototype.setn = function setn(bit, val) {
872
- assert3(typeof bit === "number" && bit >= 0);
872
+ assert2(typeof bit === "number" && bit >= 0);
873
873
  var off = bit / 26 | 0;
874
874
  var wbit = bit % 26;
875
875
  this._expand(off + 1);
@@ -1735,8 +1735,8 @@
1735
1735
  for (i = 2 * len; i < N; ++i) {
1736
1736
  rws[i] = 0;
1737
1737
  }
1738
- assert3(carry === 0);
1739
- assert3((carry & ~8191) === 0);
1738
+ assert2(carry === 0);
1739
+ assert2((carry & ~8191) === 0);
1740
1740
  };
1741
1741
  FFTM.prototype.stub = function stub(N) {
1742
1742
  var ph = new Array(N);
@@ -1791,8 +1791,8 @@
1791
1791
  var isNegNum = num < 0;
1792
1792
  if (isNegNum)
1793
1793
  num = -num;
1794
- assert3(typeof num === "number");
1795
- assert3(num < 67108864);
1794
+ assert2(typeof num === "number");
1795
+ assert2(num < 67108864);
1796
1796
  var carry = 0;
1797
1797
  for (var i = 0; i < this.length; i++) {
1798
1798
  var w = (this.words[i] | 0) * num;
@@ -1836,7 +1836,7 @@
1836
1836
  return res;
1837
1837
  };
1838
1838
  BN2.prototype.iushln = function iushln(bits) {
1839
- assert3(typeof bits === "number" && bits >= 0);
1839
+ assert2(typeof bits === "number" && bits >= 0);
1840
1840
  var r = bits % 26;
1841
1841
  var s = (bits - r) / 26;
1842
1842
  var carryMask = 67108863 >>> 26 - r << 26 - r;
@@ -1866,11 +1866,11 @@
1866
1866
  return this._strip();
1867
1867
  };
1868
1868
  BN2.prototype.ishln = function ishln(bits) {
1869
- assert3(this.negative === 0);
1869
+ assert2(this.negative === 0);
1870
1870
  return this.iushln(bits);
1871
1871
  };
1872
1872
  BN2.prototype.iushrn = function iushrn(bits, hint, extended) {
1873
- assert3(typeof bits === "number" && bits >= 0);
1873
+ assert2(typeof bits === "number" && bits >= 0);
1874
1874
  var h;
1875
1875
  if (hint) {
1876
1876
  h = (hint - hint % 26) / 26;
@@ -1879,7 +1879,7 @@
1879
1879
  }
1880
1880
  var r = bits % 26;
1881
1881
  var s = Math.min((bits - r) / 26, this.length);
1882
- var mask2 = 67108863 ^ 67108863 >>> r << r;
1882
+ var mask = 67108863 ^ 67108863 >>> r << r;
1883
1883
  var maskedWords = extended;
1884
1884
  h -= s;
1885
1885
  h = Math.max(0, h);
@@ -1903,7 +1903,7 @@
1903
1903
  for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
1904
1904
  var word = this.words[i] | 0;
1905
1905
  this.words[i] = carry << 26 - r | word >>> r;
1906
- carry = word & mask2;
1906
+ carry = word & mask;
1907
1907
  }
1908
1908
  if (maskedWords && carry !== 0) {
1909
1909
  maskedWords.words[maskedWords.length++] = carry;
@@ -1915,7 +1915,7 @@
1915
1915
  return this._strip();
1916
1916
  };
1917
1917
  BN2.prototype.ishrn = function ishrn(bits, hint, extended) {
1918
- assert3(this.negative === 0);
1918
+ assert2(this.negative === 0);
1919
1919
  return this.iushrn(bits, hint, extended);
1920
1920
  };
1921
1921
  BN2.prototype.shln = function shln(bits) {
@@ -1931,7 +1931,7 @@
1931
1931
  return this.clone().iushrn(bits);
1932
1932
  };
1933
1933
  BN2.prototype.testn = function testn(bit) {
1934
- assert3(typeof bit === "number" && bit >= 0);
1934
+ assert2(typeof bit === "number" && bit >= 0);
1935
1935
  var r = bit % 26;
1936
1936
  var s = (bit - r) / 26;
1937
1937
  var q = 1 << r;
@@ -1941,10 +1941,10 @@
1941
1941
  return !!(w & q);
1942
1942
  };
1943
1943
  BN2.prototype.imaskn = function imaskn(bits) {
1944
- assert3(typeof bits === "number" && bits >= 0);
1944
+ assert2(typeof bits === "number" && bits >= 0);
1945
1945
  var r = bits % 26;
1946
1946
  var s = (bits - r) / 26;
1947
- assert3(this.negative === 0, "imaskn works only with positive numbers");
1947
+ assert2(this.negative === 0, "imaskn works only with positive numbers");
1948
1948
  if (this.length <= s) {
1949
1949
  return this;
1950
1950
  }
@@ -1953,8 +1953,8 @@
1953
1953
  }
1954
1954
  this.length = Math.min(s, this.length);
1955
1955
  if (r !== 0) {
1956
- var mask2 = 67108863 ^ 67108863 >>> r << r;
1957
- this.words[this.length - 1] &= mask2;
1956
+ var mask = 67108863 ^ 67108863 >>> r << r;
1957
+ this.words[this.length - 1] &= mask;
1958
1958
  }
1959
1959
  return this._strip();
1960
1960
  };
@@ -1962,8 +1962,8 @@
1962
1962
  return this.clone().imaskn(bits);
1963
1963
  };
1964
1964
  BN2.prototype.iaddn = function iaddn(num) {
1965
- assert3(typeof num === "number");
1966
- assert3(num < 67108864);
1965
+ assert2(typeof num === "number");
1966
+ assert2(num < 67108864);
1967
1967
  if (num < 0)
1968
1968
  return this.isubn(-num);
1969
1969
  if (this.negative !== 0) {
@@ -1993,8 +1993,8 @@
1993
1993
  return this;
1994
1994
  };
1995
1995
  BN2.prototype.isubn = function isubn(num) {
1996
- assert3(typeof num === "number");
1997
- assert3(num < 67108864);
1996
+ assert2(typeof num === "number");
1997
+ assert2(num < 67108864);
1998
1998
  if (num < 0)
1999
1999
  return this.iaddn(-num);
2000
2000
  if (this.negative !== 0) {
@@ -2048,7 +2048,7 @@
2048
2048
  }
2049
2049
  if (carry === 0)
2050
2050
  return this._strip();
2051
- assert3(carry === -1);
2051
+ assert2(carry === -1);
2052
2052
  carry = 0;
2053
2053
  for (i = 0; i < this.length; i++) {
2054
2054
  w = -(this.words[i] | 0) + carry;
@@ -2116,7 +2116,7 @@
2116
2116
  };
2117
2117
  };
2118
2118
  BN2.prototype.divmod = function divmod(num, mode, positive) {
2119
- assert3(!num.isZero());
2119
+ assert2(!num.isZero());
2120
2120
  if (this.isZero()) {
2121
2121
  return {
2122
2122
  div: new BN2(0),
@@ -2214,7 +2214,7 @@
2214
2214
  var isNegNum = num < 0;
2215
2215
  if (isNegNum)
2216
2216
  num = -num;
2217
- assert3(num <= 67108863);
2217
+ assert2(num <= 67108863);
2218
2218
  var p = (1 << 26) % num;
2219
2219
  var acc = 0;
2220
2220
  for (var i = this.length - 1; i >= 0; i--) {
@@ -2229,7 +2229,7 @@
2229
2229
  var isNegNum = num < 0;
2230
2230
  if (isNegNum)
2231
2231
  num = -num;
2232
- assert3(num <= 67108863);
2232
+ assert2(num <= 67108863);
2233
2233
  var carry = 0;
2234
2234
  for (var i = this.length - 1; i >= 0; i--) {
2235
2235
  var w = (this.words[i] | 0) + carry * 67108864;
@@ -2243,8 +2243,8 @@
2243
2243
  return this.clone().idivn(num);
2244
2244
  };
2245
2245
  BN2.prototype.egcd = function egcd(p) {
2246
- assert3(p.negative === 0);
2247
- assert3(!p.isZero());
2246
+ assert2(p.negative === 0);
2247
+ assert2(!p.isZero());
2248
2248
  var x = this;
2249
2249
  var y = p.clone();
2250
2250
  if (x.negative !== 0) {
@@ -2308,8 +2308,8 @@
2308
2308
  };
2309
2309
  };
2310
2310
  BN2.prototype._invmp = function _invmp(p) {
2311
- assert3(p.negative === 0);
2312
- assert3(!p.isZero());
2311
+ assert2(p.negative === 0);
2312
+ assert2(!p.isZero());
2313
2313
  var a = this;
2314
2314
  var b = p.clone();
2315
2315
  if (a.negative !== 0) {
@@ -2407,7 +2407,7 @@
2407
2407
  return this.words[0] & num;
2408
2408
  };
2409
2409
  BN2.prototype.bincn = function bincn(bit) {
2410
- assert3(typeof bit === "number");
2410
+ assert2(typeof bit === "number");
2411
2411
  var r = bit % 26;
2412
2412
  var s = (bit - r) / 26;
2413
2413
  var q = 1 << r;
@@ -2447,7 +2447,7 @@
2447
2447
  if (negative) {
2448
2448
  num = -num;
2449
2449
  }
2450
- assert3(num <= 67108863, "Number is too big");
2450
+ assert2(num <= 67108863, "Number is too big");
2451
2451
  var w = this.words[0] | 0;
2452
2452
  res = w === num ? 0 : w < num ? -1 : 1;
2453
2453
  }
@@ -2519,12 +2519,12 @@
2519
2519
  return new Red(num);
2520
2520
  };
2521
2521
  BN2.prototype.toRed = function toRed(ctx) {
2522
- assert3(!this.red, "Already a number in reduction context");
2523
- assert3(this.negative === 0, "red works only with positives");
2522
+ assert2(!this.red, "Already a number in reduction context");
2523
+ assert2(this.negative === 0, "red works only with positives");
2524
2524
  return ctx.convertTo(this)._forceRed(ctx);
2525
2525
  };
2526
2526
  BN2.prototype.fromRed = function fromRed() {
2527
- assert3(this.red, "fromRed works only with numbers in reduction context");
2527
+ assert2(this.red, "fromRed works only with numbers in reduction context");
2528
2528
  return this.red.convertFrom(this);
2529
2529
  };
2530
2530
  BN2.prototype._forceRed = function _forceRed(ctx) {
@@ -2532,66 +2532,66 @@
2532
2532
  return this;
2533
2533
  };
2534
2534
  BN2.prototype.forceRed = function forceRed(ctx) {
2535
- assert3(!this.red, "Already a number in reduction context");
2535
+ assert2(!this.red, "Already a number in reduction context");
2536
2536
  return this._forceRed(ctx);
2537
2537
  };
2538
2538
  BN2.prototype.redAdd = function redAdd(num) {
2539
- assert3(this.red, "redAdd works only with red numbers");
2539
+ assert2(this.red, "redAdd works only with red numbers");
2540
2540
  return this.red.add(this, num);
2541
2541
  };
2542
2542
  BN2.prototype.redIAdd = function redIAdd(num) {
2543
- assert3(this.red, "redIAdd works only with red numbers");
2543
+ assert2(this.red, "redIAdd works only with red numbers");
2544
2544
  return this.red.iadd(this, num);
2545
2545
  };
2546
2546
  BN2.prototype.redSub = function redSub(num) {
2547
- assert3(this.red, "redSub works only with red numbers");
2547
+ assert2(this.red, "redSub works only with red numbers");
2548
2548
  return this.red.sub(this, num);
2549
2549
  };
2550
2550
  BN2.prototype.redISub = function redISub(num) {
2551
- assert3(this.red, "redISub works only with red numbers");
2551
+ assert2(this.red, "redISub works only with red numbers");
2552
2552
  return this.red.isub(this, num);
2553
2553
  };
2554
2554
  BN2.prototype.redShl = function redShl(num) {
2555
- assert3(this.red, "redShl works only with red numbers");
2555
+ assert2(this.red, "redShl works only with red numbers");
2556
2556
  return this.red.shl(this, num);
2557
2557
  };
2558
2558
  BN2.prototype.redMul = function redMul(num) {
2559
- assert3(this.red, "redMul works only with red numbers");
2559
+ assert2(this.red, "redMul works only with red numbers");
2560
2560
  this.red._verify2(this, num);
2561
2561
  return this.red.mul(this, num);
2562
2562
  };
2563
2563
  BN2.prototype.redIMul = function redIMul(num) {
2564
- assert3(this.red, "redMul works only with red numbers");
2564
+ assert2(this.red, "redMul works only with red numbers");
2565
2565
  this.red._verify2(this, num);
2566
2566
  return this.red.imul(this, num);
2567
2567
  };
2568
2568
  BN2.prototype.redSqr = function redSqr() {
2569
- assert3(this.red, "redSqr works only with red numbers");
2569
+ assert2(this.red, "redSqr works only with red numbers");
2570
2570
  this.red._verify1(this);
2571
2571
  return this.red.sqr(this);
2572
2572
  };
2573
2573
  BN2.prototype.redISqr = function redISqr() {
2574
- assert3(this.red, "redISqr works only with red numbers");
2574
+ assert2(this.red, "redISqr works only with red numbers");
2575
2575
  this.red._verify1(this);
2576
2576
  return this.red.isqr(this);
2577
2577
  };
2578
2578
  BN2.prototype.redSqrt = function redSqrt() {
2579
- assert3(this.red, "redSqrt works only with red numbers");
2579
+ assert2(this.red, "redSqrt works only with red numbers");
2580
2580
  this.red._verify1(this);
2581
2581
  return this.red.sqrt(this);
2582
2582
  };
2583
2583
  BN2.prototype.redInvm = function redInvm() {
2584
- assert3(this.red, "redInvm works only with red numbers");
2584
+ assert2(this.red, "redInvm works only with red numbers");
2585
2585
  this.red._verify1(this);
2586
2586
  return this.red.invm(this);
2587
2587
  };
2588
2588
  BN2.prototype.redNeg = function redNeg() {
2589
- assert3(this.red, "redNeg works only with red numbers");
2589
+ assert2(this.red, "redNeg works only with red numbers");
2590
2590
  this.red._verify1(this);
2591
2591
  return this.red.neg(this);
2592
2592
  };
2593
2593
  BN2.prototype.redPow = function redPow(num) {
2594
- assert3(this.red && !num.red, "redPow(normalNum)");
2594
+ assert2(this.red && !num.red, "redPow(normalNum)");
2595
2595
  this.red._verify1(this);
2596
2596
  return this.red.pow(this, num);
2597
2597
  };
@@ -2652,7 +2652,7 @@
2652
2652
  }
2653
2653
  inherits(K256, MPrime);
2654
2654
  K256.prototype.split = function split2(input, output2) {
2655
- var mask2 = 4194303;
2655
+ var mask = 4194303;
2656
2656
  var outLen = Math.min(input.length, 9);
2657
2657
  for (var i = 0; i < outLen; i++) {
2658
2658
  output2.words[i] = input.words[i];
@@ -2664,10 +2664,10 @@
2664
2664
  return;
2665
2665
  }
2666
2666
  var prev = input.words[9];
2667
- output2.words[output2.length++] = prev & mask2;
2667
+ output2.words[output2.length++] = prev & mask;
2668
2668
  for (i = 10; i < input.length; i++) {
2669
2669
  var next = input.words[i] | 0;
2670
- input.words[i - 10] = (next & mask2) << 4 | prev >>> 22;
2670
+ input.words[i - 10] = (next & mask) << 4 | prev >>> 22;
2671
2671
  prev = next;
2672
2672
  }
2673
2673
  prev >>>= 22;
@@ -2759,18 +2759,18 @@
2759
2759
  this.m = prime.p;
2760
2760
  this.prime = prime;
2761
2761
  } else {
2762
- assert3(m.gtn(1), "modulus must be greater than 1");
2762
+ assert2(m.gtn(1), "modulus must be greater than 1");
2763
2763
  this.m = m;
2764
2764
  this.prime = null;
2765
2765
  }
2766
2766
  }
2767
2767
  Red.prototype._verify1 = function _verify1(a) {
2768
- assert3(a.negative === 0, "red works only with positives");
2769
- assert3(a.red, "red works only with red numbers");
2768
+ assert2(a.negative === 0, "red works only with positives");
2769
+ assert2(a.red, "red works only with red numbers");
2770
2770
  };
2771
2771
  Red.prototype._verify2 = function _verify2(a, b) {
2772
- assert3((a.negative | b.negative) === 0, "red works only with positives");
2773
- assert3(
2772
+ assert2((a.negative | b.negative) === 0, "red works only with positives");
2773
+ assert2(
2774
2774
  a.red && a.red === b.red,
2775
2775
  "red works only with red numbers"
2776
2776
  );
@@ -2841,7 +2841,7 @@
2841
2841
  if (a.isZero())
2842
2842
  return a.clone();
2843
2843
  var mod3 = this.m.andln(3);
2844
- assert3(mod3 % 2 === 1);
2844
+ assert2(mod3 % 2 === 1);
2845
2845
  if (mod3 === 3) {
2846
2846
  var pow3 = this.m.add(new BN2(1)).iushrn(2);
2847
2847
  return this.pow(a, pow3);
@@ -2852,7 +2852,7 @@
2852
2852
  s++;
2853
2853
  q.iushrn(1);
2854
2854
  }
2855
- assert3(!q.isZero());
2855
+ assert2(!q.isZero());
2856
2856
  var one = new BN2(1).toRed(this);
2857
2857
  var nOne = one.redNeg();
2858
2858
  var lpow = this.m.subn(1).iushrn(1);
@@ -2870,7 +2870,7 @@
2870
2870
  for (var i = 0; tmp.cmp(one) !== 0; i++) {
2871
2871
  tmp = tmp.redSqr();
2872
2872
  }
2873
- assert3(i < m);
2873
+ assert2(i < m);
2874
2874
  var b = this.pow(c, new BN2(1).iushln(m - i - 1));
2875
2875
  r = r.redMul(b);
2876
2876
  c = b.redSqr();
@@ -29470,13 +29470,13 @@ spurious results.`);
29470
29470
  // ../versions/dist/index.mjs
29471
29471
  function getBuiltinVersions() {
29472
29472
  return {
29473
- FORC: "0.58.0",
29473
+ FORC: "0.56.1",
29474
29474
  FUEL_CORE: "0.26.0",
29475
29475
  FUELS: "0.85.0"
29476
29476
  };
29477
29477
  }
29478
- function parseVersion(version2) {
29479
- const [major, minor, patch] = version2.split(".").map((v) => parseInt(v, 10));
29478
+ function parseVersion(version) {
29479
+ const [major, minor, patch] = version.split(".").map((v) => parseInt(v, 10));
29480
29480
  return { major, minor, patch };
29481
29481
  }
29482
29482
  function versionDiffs(version1, version2) {
@@ -30036,6 +30036,123 @@ This unreleased fuel-core build may include features and updates not yet support
30036
30036
  }
30037
30037
  return hexlify(bytes2.slice(start == null ? 0 : start, end == null ? bytes2.length : end));
30038
30038
  }
30039
+ function toUtf8Bytes(stri, form = true) {
30040
+ let str = stri;
30041
+ if (form) {
30042
+ str = stri.normalize("NFC");
30043
+ }
30044
+ const result = [];
30045
+ for (let i = 0; i < str.length; i += 1) {
30046
+ const c = str.charCodeAt(i);
30047
+ if (c < 128) {
30048
+ result.push(c);
30049
+ } else if (c < 2048) {
30050
+ result.push(c >> 6 | 192);
30051
+ result.push(c & 63 | 128);
30052
+ } else if ((c & 64512) === 55296) {
30053
+ i += 1;
30054
+ const c2 = str.charCodeAt(i);
30055
+ if (i >= str.length || (c2 & 64512) !== 56320) {
30056
+ throw new FuelError(
30057
+ ErrorCode.INVALID_INPUT_PARAMETERS,
30058
+ "Invalid UTF-8 in the input string."
30059
+ );
30060
+ }
30061
+ const pair = 65536 + ((c & 1023) << 10) + (c2 & 1023);
30062
+ result.push(pair >> 18 | 240);
30063
+ result.push(pair >> 12 & 63 | 128);
30064
+ result.push(pair >> 6 & 63 | 128);
30065
+ result.push(pair & 63 | 128);
30066
+ } else {
30067
+ result.push(c >> 12 | 224);
30068
+ result.push(c >> 6 & 63 | 128);
30069
+ result.push(c & 63 | 128);
30070
+ }
30071
+ }
30072
+ return new Uint8Array(result);
30073
+ }
30074
+ function onError(reason, offset, bytes2, output2, badCodepoint) {
30075
+ console.log(`invalid codepoint at offset ${offset}; ${reason}, bytes: ${bytes2}`);
30076
+ return offset;
30077
+ }
30078
+ function helper(codePoints) {
30079
+ return codePoints.map((codePoint) => {
30080
+ if (codePoint <= 65535) {
30081
+ return String.fromCharCode(codePoint);
30082
+ }
30083
+ codePoint -= 65536;
30084
+ return String.fromCharCode(
30085
+ (codePoint >> 10 & 1023) + 55296,
30086
+ (codePoint & 1023) + 56320
30087
+ );
30088
+ }).join("");
30089
+ }
30090
+ function getUtf8CodePoints(_bytes) {
30091
+ const bytes2 = arrayify(_bytes, "bytes");
30092
+ const result = [];
30093
+ let i = 0;
30094
+ while (i < bytes2.length) {
30095
+ const c = bytes2[i++];
30096
+ if (c >> 7 === 0) {
30097
+ result.push(c);
30098
+ continue;
30099
+ }
30100
+ let extraLength = null;
30101
+ let overlongMask = null;
30102
+ if ((c & 224) === 192) {
30103
+ extraLength = 1;
30104
+ overlongMask = 127;
30105
+ } else if ((c & 240) === 224) {
30106
+ extraLength = 2;
30107
+ overlongMask = 2047;
30108
+ } else if ((c & 248) === 240) {
30109
+ extraLength = 3;
30110
+ overlongMask = 65535;
30111
+ } else {
30112
+ if ((c & 192) === 128) {
30113
+ i += onError("UNEXPECTED_CONTINUE", i - 1, bytes2, result);
30114
+ } else {
30115
+ i += onError("BAD_PREFIX", i - 1, bytes2, result);
30116
+ }
30117
+ continue;
30118
+ }
30119
+ if (i - 1 + extraLength >= bytes2.length) {
30120
+ i += onError("OVERRUN", i - 1, bytes2, result);
30121
+ continue;
30122
+ }
30123
+ let res = c & (1 << 8 - extraLength - 1) - 1;
30124
+ for (let j = 0; j < extraLength; j++) {
30125
+ const nextChar = bytes2[i];
30126
+ if ((nextChar & 192) !== 128) {
30127
+ i += onError("MISSING_CONTINUE", i, bytes2, result);
30128
+ res = null;
30129
+ break;
30130
+ }
30131
+ res = res << 6 | nextChar & 63;
30132
+ i++;
30133
+ }
30134
+ if (res === null) {
30135
+ continue;
30136
+ }
30137
+ if (res > 1114111) {
30138
+ i += onError("OUT_OF_RANGE", i - 1 - extraLength, bytes2, result, res);
30139
+ continue;
30140
+ }
30141
+ if (res >= 55296 && res <= 57343) {
30142
+ i += onError("UTF16_SURROGATE", i - 1 - extraLength, bytes2, result, res);
30143
+ continue;
30144
+ }
30145
+ if (res <= overlongMask) {
30146
+ i += onError("OVERLONG", i - 1 - extraLength, bytes2, result, res);
30147
+ continue;
30148
+ }
30149
+ result.push(res);
30150
+ }
30151
+ return result;
30152
+ }
30153
+ function toUtf8String(bytes2) {
30154
+ return helper(getUtf8CodePoints(bytes2));
30155
+ }
30039
30156
 
30040
30157
  // ../../node_modules/.pnpm/@noble+hashes@1.3.3/node_modules/@noble/hashes/esm/ripemd160.js
30041
30158
  var Rho = /* @__PURE__ */ new Uint8Array([7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8]);
@@ -30147,13 +30264,13 @@ This unreleased fuel-core build may include features and updates not yet support
30147
30264
  };
30148
30265
  var keccak256 = (data) => keccak_256(data);
30149
30266
  var locked = false;
30150
- var helper = (data) => ripemd160(data);
30151
- var ripemd = helper;
30267
+ var helper2 = (data) => ripemd160(data);
30268
+ var ripemd = helper2;
30152
30269
  function ripemd1602(_data) {
30153
30270
  const data = arrayify(_data, "data");
30154
30271
  return ripemd(data);
30155
30272
  }
30156
- ripemd1602._ = helper;
30273
+ ripemd1602._ = helper2;
30157
30274
  ripemd1602.lock = () => {
30158
30275
  locked = true;
30159
30276
  };
@@ -30757,316 +30874,6 @@ This unreleased fuel-core build may include features and updates not yet support
30757
30874
  return coinQuantities;
30758
30875
  };
30759
30876
 
30760
- // ../../node_modules/.pnpm/ethers@6.7.1/node_modules/ethers/lib.esm/_version.js
30761
- var version = "6.7.1";
30762
-
30763
- // ../../node_modules/.pnpm/ethers@6.7.1/node_modules/ethers/lib.esm/utils/properties.js
30764
- function checkType(value, type3, name) {
30765
- const types = type3.split("|").map((t) => t.trim());
30766
- for (let i = 0; i < types.length; i++) {
30767
- switch (type3) {
30768
- case "any":
30769
- return;
30770
- case "bigint":
30771
- case "boolean":
30772
- case "number":
30773
- case "string":
30774
- if (typeof value === type3) {
30775
- return;
30776
- }
30777
- }
30778
- }
30779
- const error = new Error(`invalid value for type ${type3}`);
30780
- error.code = "INVALID_ARGUMENT";
30781
- error.argument = `value.${name}`;
30782
- error.value = value;
30783
- throw error;
30784
- }
30785
- function defineProperties(target, values, types) {
30786
- for (let key in values) {
30787
- let value = values[key];
30788
- const type3 = types ? types[key] : null;
30789
- if (type3) {
30790
- checkType(value, type3, key);
30791
- }
30792
- Object.defineProperty(target, key, { enumerable: true, value, writable: false });
30793
- }
30794
- }
30795
-
30796
- // ../../node_modules/.pnpm/ethers@6.7.1/node_modules/ethers/lib.esm/utils/errors.js
30797
- function stringify(value) {
30798
- if (value == null) {
30799
- return "null";
30800
- }
30801
- if (Array.isArray(value)) {
30802
- return "[ " + value.map(stringify).join(", ") + " ]";
30803
- }
30804
- if (value instanceof Uint8Array) {
30805
- const HEX = "0123456789abcdef";
30806
- let result = "0x";
30807
- for (let i = 0; i < value.length; i++) {
30808
- result += HEX[value[i] >> 4];
30809
- result += HEX[value[i] & 15];
30810
- }
30811
- return result;
30812
- }
30813
- if (typeof value === "object" && typeof value.toJSON === "function") {
30814
- return stringify(value.toJSON());
30815
- }
30816
- switch (typeof value) {
30817
- case "boolean":
30818
- case "symbol":
30819
- return value.toString();
30820
- case "bigint":
30821
- return BigInt(value).toString();
30822
- case "number":
30823
- return value.toString();
30824
- case "string":
30825
- return JSON.stringify(value);
30826
- case "object": {
30827
- const keys = Object.keys(value);
30828
- keys.sort();
30829
- return "{ " + keys.map((k) => `${stringify(k)}: ${stringify(value[k])}`).join(", ") + " }";
30830
- }
30831
- }
30832
- return `[ COULD NOT SERIALIZE ]`;
30833
- }
30834
- function makeError(message, code, info) {
30835
- {
30836
- const details = [];
30837
- if (info) {
30838
- if ("message" in info || "code" in info || "name" in info) {
30839
- throw new Error(`value will overwrite populated values: ${stringify(info)}`);
30840
- }
30841
- for (const key in info) {
30842
- const value = info[key];
30843
- details.push(key + "=" + stringify(value));
30844
- }
30845
- }
30846
- details.push(`code=${code}`);
30847
- details.push(`version=${version}`);
30848
- if (details.length) {
30849
- message += " (" + details.join(", ") + ")";
30850
- }
30851
- }
30852
- let error;
30853
- switch (code) {
30854
- case "INVALID_ARGUMENT":
30855
- error = new TypeError(message);
30856
- break;
30857
- case "NUMERIC_FAULT":
30858
- case "BUFFER_OVERRUN":
30859
- error = new RangeError(message);
30860
- break;
30861
- default:
30862
- error = new Error(message);
30863
- }
30864
- defineProperties(error, { code });
30865
- if (info) {
30866
- Object.assign(error, info);
30867
- }
30868
- return error;
30869
- }
30870
- function assert(check, message, code, info) {
30871
- if (!check) {
30872
- throw makeError(message, code, info);
30873
- }
30874
- }
30875
- function assertArgument(check, message, name, value) {
30876
- assert(check, message, "INVALID_ARGUMENT", { argument: name, value });
30877
- }
30878
- var _normalizeForms = ["NFD", "NFC", "NFKD", "NFKC"].reduce((accum, form) => {
30879
- try {
30880
- if ("test".normalize(form) !== "test") {
30881
- throw new Error("bad");
30882
- }
30883
- ;
30884
- if (form === "NFD") {
30885
- const check = String.fromCharCode(233).normalize("NFD");
30886
- const expected = String.fromCharCode(101, 769);
30887
- if (check !== expected) {
30888
- throw new Error("broken");
30889
- }
30890
- }
30891
- accum.push(form);
30892
- } catch (error) {
30893
- }
30894
- return accum;
30895
- }, []);
30896
- function assertNormalize(form) {
30897
- assert(_normalizeForms.indexOf(form) >= 0, "platform missing String.prototype.normalize", "UNSUPPORTED_OPERATION", {
30898
- operation: "String.prototype.normalize",
30899
- info: { form }
30900
- });
30901
- }
30902
-
30903
- // ../../node_modules/.pnpm/ethers@6.7.1/node_modules/ethers/lib.esm/utils/data.js
30904
- function _getBytes(value, name, copy) {
30905
- if (value instanceof Uint8Array) {
30906
- if (copy) {
30907
- return new Uint8Array(value);
30908
- }
30909
- return value;
30910
- }
30911
- if (typeof value === "string" && value.match(/^0x([0-9a-f][0-9a-f])*$/i)) {
30912
- const result = new Uint8Array((value.length - 2) / 2);
30913
- let offset = 2;
30914
- for (let i = 0; i < result.length; i++) {
30915
- result[i] = parseInt(value.substring(offset, offset + 2), 16);
30916
- offset += 2;
30917
- }
30918
- return result;
30919
- }
30920
- assertArgument(false, "invalid BytesLike value", name || "value", value);
30921
- }
30922
- function getBytes(value, name) {
30923
- return _getBytes(value, name, false);
30924
- }
30925
-
30926
- // ../../node_modules/.pnpm/ethers@6.7.1/node_modules/ethers/lib.esm/utils/utf8.js
30927
- function errorFunc(reason, offset, bytes2, output2, badCodepoint) {
30928
- assertArgument(false, `invalid codepoint at offset ${offset}; ${reason}`, "bytes", bytes2);
30929
- }
30930
- function ignoreFunc(reason, offset, bytes2, output2, badCodepoint) {
30931
- if (reason === "BAD_PREFIX" || reason === "UNEXPECTED_CONTINUE") {
30932
- let i = 0;
30933
- for (let o = offset + 1; o < bytes2.length; o++) {
30934
- if (bytes2[o] >> 6 !== 2) {
30935
- break;
30936
- }
30937
- i++;
30938
- }
30939
- return i;
30940
- }
30941
- if (reason === "OVERRUN") {
30942
- return bytes2.length - offset - 1;
30943
- }
30944
- return 0;
30945
- }
30946
- function replaceFunc(reason, offset, bytes2, output2, badCodepoint) {
30947
- if (reason === "OVERLONG") {
30948
- assertArgument(typeof badCodepoint === "number", "invalid bad code point for replacement", "badCodepoint", badCodepoint);
30949
- output2.push(badCodepoint);
30950
- return 0;
30951
- }
30952
- output2.push(65533);
30953
- return ignoreFunc(reason, offset, bytes2, output2, badCodepoint);
30954
- }
30955
- var Utf8ErrorFuncs = Object.freeze({
30956
- error: errorFunc,
30957
- ignore: ignoreFunc,
30958
- replace: replaceFunc
30959
- });
30960
- function getUtf8CodePoints(_bytes, onError) {
30961
- if (onError == null) {
30962
- onError = Utf8ErrorFuncs.error;
30963
- }
30964
- const bytes2 = getBytes(_bytes, "bytes");
30965
- const result = [];
30966
- let i = 0;
30967
- while (i < bytes2.length) {
30968
- const c = bytes2[i++];
30969
- if (c >> 7 === 0) {
30970
- result.push(c);
30971
- continue;
30972
- }
30973
- let extraLength = null;
30974
- let overlongMask = null;
30975
- if ((c & 224) === 192) {
30976
- extraLength = 1;
30977
- overlongMask = 127;
30978
- } else if ((c & 240) === 224) {
30979
- extraLength = 2;
30980
- overlongMask = 2047;
30981
- } else if ((c & 248) === 240) {
30982
- extraLength = 3;
30983
- overlongMask = 65535;
30984
- } else {
30985
- if ((c & 192) === 128) {
30986
- i += onError("UNEXPECTED_CONTINUE", i - 1, bytes2, result);
30987
- } else {
30988
- i += onError("BAD_PREFIX", i - 1, bytes2, result);
30989
- }
30990
- continue;
30991
- }
30992
- if (i - 1 + extraLength >= bytes2.length) {
30993
- i += onError("OVERRUN", i - 1, bytes2, result);
30994
- continue;
30995
- }
30996
- let res = c & (1 << 8 - extraLength - 1) - 1;
30997
- for (let j = 0; j < extraLength; j++) {
30998
- let nextChar = bytes2[i];
30999
- if ((nextChar & 192) != 128) {
31000
- i += onError("MISSING_CONTINUE", i, bytes2, result);
31001
- res = null;
31002
- break;
31003
- }
31004
- ;
31005
- res = res << 6 | nextChar & 63;
31006
- i++;
31007
- }
31008
- if (res === null) {
31009
- continue;
31010
- }
31011
- if (res > 1114111) {
31012
- i += onError("OUT_OF_RANGE", i - 1 - extraLength, bytes2, result, res);
31013
- continue;
31014
- }
31015
- if (res >= 55296 && res <= 57343) {
31016
- i += onError("UTF16_SURROGATE", i - 1 - extraLength, bytes2, result, res);
31017
- continue;
31018
- }
31019
- if (res <= overlongMask) {
31020
- i += onError("OVERLONG", i - 1 - extraLength, bytes2, result, res);
31021
- continue;
31022
- }
31023
- result.push(res);
31024
- }
31025
- return result;
31026
- }
31027
- function toUtf8Bytes(str, form) {
31028
- if (form != null) {
31029
- assertNormalize(form);
31030
- str = str.normalize(form);
31031
- }
31032
- let result = [];
31033
- for (let i = 0; i < str.length; i++) {
31034
- const c = str.charCodeAt(i);
31035
- if (c < 128) {
31036
- result.push(c);
31037
- } else if (c < 2048) {
31038
- result.push(c >> 6 | 192);
31039
- result.push(c & 63 | 128);
31040
- } else if ((c & 64512) == 55296) {
31041
- i++;
31042
- const c2 = str.charCodeAt(i);
31043
- assertArgument(i < str.length && (c2 & 64512) === 56320, "invalid surrogate pair", "str", str);
31044
- const pair = 65536 + ((c & 1023) << 10) + (c2 & 1023);
31045
- result.push(pair >> 18 | 240);
31046
- result.push(pair >> 12 & 63 | 128);
31047
- result.push(pair >> 6 & 63 | 128);
31048
- result.push(pair & 63 | 128);
31049
- } else {
31050
- result.push(c >> 12 | 224);
31051
- result.push(c >> 6 & 63 | 128);
31052
- result.push(c & 63 | 128);
31053
- }
31054
- }
31055
- return new Uint8Array(result);
31056
- }
31057
- function _toUtf8String(codePoints) {
31058
- return codePoints.map((codePoint) => {
31059
- if (codePoint <= 65535) {
31060
- return String.fromCharCode(codePoint);
31061
- }
31062
- codePoint -= 65536;
31063
- return String.fromCharCode((codePoint >> 10 & 1023) + 55296, (codePoint & 1023) + 56320);
31064
- }).join("");
31065
- }
31066
- function toUtf8String(bytes2, onError) {
31067
- return _toUtf8String(getUtf8CodePoints(bytes2, onError));
31068
- }
31069
-
31070
30877
  // ../hasher/dist/index.mjs
31071
30878
  function sha2562(data) {
31072
30879
  return hexlify(sha256(arrayify(data)));
@@ -31092,6 +30899,19 @@ This unreleased fuel-core build may include features and updates not yet support
31092
30899
  __defNormalProp4(obj, typeof key !== "symbol" ? key + "" : key, value);
31093
30900
  return value;
31094
30901
  };
30902
+ var __accessCheck2 = (obj, member, msg) => {
30903
+ if (!member.has(obj))
30904
+ throw TypeError("Cannot " + msg);
30905
+ };
30906
+ var __privateAdd2 = (obj, member, value) => {
30907
+ if (member.has(obj))
30908
+ throw TypeError("Cannot add the same private member more than once");
30909
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
30910
+ };
30911
+ var __privateMethod2 = (obj, member, method) => {
30912
+ __accessCheck2(obj, member, "access private method");
30913
+ return method;
30914
+ };
31095
30915
  var Coder = class {
31096
30916
  name;
31097
30917
  type;
@@ -31123,6 +30943,7 @@ This unreleased fuel-core build may include features and updates not yet support
31123
30943
  var enumRegEx = /^enum (?<name>\w+)$/;
31124
30944
  var tupleRegEx = /^\((?<items>.*)\)$/;
31125
30945
  var genericRegEx = /^generic (?<name>\w+)$/;
30946
+ var ENCODING_V0 = "0";
31126
30947
  var ENCODING_V1 = "1";
31127
30948
  var WORD_SIZE = 8;
31128
30949
  var BYTES_32 = 32;
@@ -31133,6 +30954,10 @@ This unreleased fuel-core build may include features and updates not yet support
31133
30954
  var TX_LEN = WORD_SIZE * 4;
31134
30955
  var TX_POINTER_LEN = WORD_SIZE * 2;
31135
30956
  var MAX_BYTES = 2 ** 32 - 1;
30957
+ var calculateVmTxMemory = ({ maxInputs }) => BYTES_32 + // Tx ID
30958
+ ASSET_ID_LEN + // Base asset ID
30959
+ // Asset ID/Balance coin input pairs
30960
+ maxInputs * (ASSET_ID_LEN + WORD_SIZE) + WORD_SIZE;
31136
30961
  var SCRIPT_FIXED_SIZE = WORD_SIZE + // Identifier
31137
30962
  WORD_SIZE + // Gas limit
31138
30963
  WORD_SIZE + // Script size
@@ -31163,6 +30988,125 @@ This unreleased fuel-core build may include features and updates not yet support
31163
30988
  WORD_SIZE + // Predicate size
31164
30989
  WORD_SIZE + // Predicate data size
31165
30990
  WORD_SIZE;
30991
+ var encodedLengths = {
30992
+ u64: WORD_SIZE,
30993
+ u256: WORD_SIZE * 4
30994
+ };
30995
+ var BigNumberCoder = class extends Coder {
30996
+ constructor(baseType) {
30997
+ super("bigNumber", baseType, encodedLengths[baseType]);
30998
+ }
30999
+ encode(value) {
31000
+ let bytes2;
31001
+ try {
31002
+ bytes2 = toBytes2(value, this.encodedLength);
31003
+ } catch (error) {
31004
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
31005
+ }
31006
+ return bytes2;
31007
+ }
31008
+ decode(data, offset) {
31009
+ if (data.length < this.encodedLength) {
31010
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} data size.`);
31011
+ }
31012
+ let bytes2 = data.slice(offset, offset + this.encodedLength);
31013
+ bytes2 = bytes2.slice(0, this.encodedLength);
31014
+ if (bytes2.length !== this.encodedLength) {
31015
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} byte data size.`);
31016
+ }
31017
+ return [bn(bytes2), offset + this.encodedLength];
31018
+ }
31019
+ };
31020
+ var VEC_PROPERTY_SPACE = 3;
31021
+ var BASE_VECTOR_OFFSET = VEC_PROPERTY_SPACE * WORD_SIZE;
31022
+ var RAW_SLICE_PROPERTY_SPACE = 2;
31023
+ var BASE_RAW_SLICE_OFFSET = RAW_SLICE_PROPERTY_SPACE * WORD_SIZE;
31024
+ function concatWithDynamicData(items) {
31025
+ const topLevelData = {};
31026
+ let totalIndex = 0;
31027
+ const objects = items.map((item) => {
31028
+ const dynamicData = item.dynamicData;
31029
+ if (dynamicData) {
31030
+ Object.entries(dynamicData).forEach(([pointerIndex, vData]) => {
31031
+ topLevelData[parseInt(pointerIndex, 10) + totalIndex] = vData;
31032
+ });
31033
+ }
31034
+ const byteArray = arrayify(item);
31035
+ totalIndex += byteArray.byteLength / WORD_SIZE;
31036
+ return byteArray;
31037
+ });
31038
+ const length = objects.reduce((accum, item) => accum + item.length, 0);
31039
+ const result = new Uint8Array(length);
31040
+ objects.reduce((offset, object) => {
31041
+ result.set(object, offset);
31042
+ return offset + object.length;
31043
+ }, 0);
31044
+ if (Object.keys(topLevelData).length) {
31045
+ result.dynamicData = topLevelData;
31046
+ }
31047
+ return result;
31048
+ }
31049
+ function unpackDynamicData(results, baseOffset, dataOffset) {
31050
+ if (!results.dynamicData) {
31051
+ return concat([results]);
31052
+ }
31053
+ let cumulativeDynamicByteLength = 0;
31054
+ let updatedResults = results;
31055
+ Object.entries(results.dynamicData).forEach(([pointerIndex, vData]) => {
31056
+ const pointerOffset = parseInt(pointerIndex, 10) * WORD_SIZE;
31057
+ const adjustedValue = new BigNumberCoder("u64").encode(
31058
+ dataOffset + baseOffset + cumulativeDynamicByteLength
31059
+ );
31060
+ updatedResults.set(adjustedValue, pointerOffset);
31061
+ const dataToAppend = vData.dynamicData ? (
31062
+ // unpack child dynamic data
31063
+ unpackDynamicData(
31064
+ vData,
31065
+ baseOffset,
31066
+ dataOffset + vData.byteLength + cumulativeDynamicByteLength
31067
+ )
31068
+ ) : vData;
31069
+ updatedResults = concat([updatedResults, dataToAppend]);
31070
+ cumulativeDynamicByteLength += dataToAppend.byteLength;
31071
+ });
31072
+ return updatedResults;
31073
+ }
31074
+ var chunkByLength = (data, length = WORD_SIZE) => {
31075
+ const chunks = [];
31076
+ let offset = 0;
31077
+ let chunk = data.slice(offset, offset + length);
31078
+ while (chunk.length) {
31079
+ chunks.push(chunk);
31080
+ offset += length;
31081
+ chunk = data.slice(offset, offset + length);
31082
+ }
31083
+ return chunks;
31084
+ };
31085
+ var isPointerType = (type3) => {
31086
+ switch (type3) {
31087
+ case "u8":
31088
+ case "u16":
31089
+ case "u32":
31090
+ case "u64":
31091
+ case "bool": {
31092
+ return false;
31093
+ }
31094
+ default: {
31095
+ return true;
31096
+ }
31097
+ }
31098
+ };
31099
+ var isHeapType = (type3) => type3 === VEC_CODER_TYPE || type3 === BYTES_CODER_TYPE || type3 === STD_STRING_CODER_TYPE;
31100
+ var isMultipleOfWordSize = (length) => length % WORD_SIZE === 0;
31101
+ var getWordSizePadding = (length) => WORD_SIZE - length % WORD_SIZE;
31102
+ var rightPadToWordSize = (encoded) => {
31103
+ if (isMultipleOfWordSize(encoded.length)) {
31104
+ return encoded;
31105
+ }
31106
+ const padding = new Uint8Array(WORD_SIZE - encoded.length % WORD_SIZE);
31107
+ return concatBytes2([encoded, padding]);
31108
+ };
31109
+ var isUint8Array = (value) => value instanceof Uint8Array;
31166
31110
  var ArrayCoder = class extends Coder {
31167
31111
  coder;
31168
31112
  length;
@@ -31178,7 +31122,7 @@ This unreleased fuel-core build may include features and updates not yet support
31178
31122
  if (this.length !== value.length) {
31179
31123
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
31180
31124
  }
31181
- return concat(Array.from(value).map((v) => this.coder.encode(v)));
31125
+ return concatWithDynamicData(Array.from(value).map((v) => this.coder.encode(v)));
31182
31126
  }
31183
31127
  decode(data, offset) {
31184
31128
  if (data.length < this.encodedLength || data.length > MAX_BYTES) {
@@ -31255,44 +31199,764 @@ This unreleased fuel-core build may include features and updates not yet support
31255
31199
  return [toHex(bytes2, this.encodedLength), offset + this.encodedLength];
31256
31200
  }
31257
31201
  };
31258
- var encodedLengths = {
31259
- u64: WORD_SIZE,
31260
- u256: WORD_SIZE * 4
31261
- };
31262
- var BigNumberCoder = class extends Coder {
31263
- constructor(baseType) {
31264
- super("bigNumber", baseType, encodedLengths[baseType]);
31202
+ var BooleanCoder = class extends Coder {
31203
+ paddingLength;
31204
+ options;
31205
+ constructor(options = {
31206
+ isSmallBytes: false,
31207
+ isRightPadded: false
31208
+ }) {
31209
+ const paddingLength = options.isSmallBytes ? 1 : 8;
31210
+ super("boolean", "boolean", paddingLength);
31211
+ this.paddingLength = paddingLength;
31212
+ this.options = options;
31265
31213
  }
31266
31214
  encode(value) {
31215
+ const isTrueBool = value === true || value === false;
31216
+ if (!isTrueBool) {
31217
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid boolean value.`);
31218
+ }
31219
+ const output2 = toBytes2(value ? 1 : 0, this.paddingLength);
31220
+ if (this.options.isRightPadded) {
31221
+ return output2.reverse();
31222
+ }
31223
+ return output2;
31224
+ }
31225
+ decode(data, offset) {
31226
+ if (data.length < this.paddingLength) {
31227
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean data size.`);
31228
+ }
31267
31229
  let bytes2;
31268
- try {
31269
- bytes2 = toBytes2(value, this.encodedLength);
31270
- } catch (error) {
31271
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
31230
+ if (this.options.isRightPadded) {
31231
+ bytes2 = data.slice(offset, offset + 1);
31232
+ } else {
31233
+ bytes2 = data.slice(offset, offset + this.paddingLength);
31272
31234
  }
31273
- return bytes2;
31235
+ const decodedValue = bn(bytes2);
31236
+ if (decodedValue.isZero()) {
31237
+ return [false, offset + this.paddingLength];
31238
+ }
31239
+ if (!decodedValue.eq(bn(1))) {
31240
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean value.`);
31241
+ }
31242
+ return [true, offset + this.paddingLength];
31243
+ }
31244
+ };
31245
+ var _getPaddedData;
31246
+ var getPaddedData_fn;
31247
+ var ByteCoder = class extends Coder {
31248
+ constructor() {
31249
+ super("struct", "struct Bytes", BASE_VECTOR_OFFSET);
31250
+ __privateAdd2(this, _getPaddedData);
31251
+ }
31252
+ encode(value) {
31253
+ const parts = [];
31254
+ const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
31255
+ const data = __privateMethod2(this, _getPaddedData, getPaddedData_fn).call(this, value);
31256
+ pointer.dynamicData = {
31257
+ 0: concatWithDynamicData([data])
31258
+ };
31259
+ parts.push(pointer);
31260
+ parts.push(new BigNumberCoder("u64").encode(data.byteLength));
31261
+ parts.push(new BigNumberCoder("u64").encode(value.length));
31262
+ return concatWithDynamicData(parts);
31263
+ }
31264
+ decode(data, offset) {
31265
+ if (data.length < BASE_VECTOR_OFFSET) {
31266
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid byte data size.`);
31267
+ }
31268
+ const len = data.slice(16, 24);
31269
+ const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
31270
+ const byteData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + encodedLength);
31271
+ if (byteData.length !== encodedLength) {
31272
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
31273
+ }
31274
+ return [byteData, offset + BASE_VECTOR_OFFSET];
31275
+ }
31276
+ };
31277
+ _getPaddedData = /* @__PURE__ */ new WeakSet();
31278
+ getPaddedData_fn = function(value) {
31279
+ const data = value instanceof Uint8Array ? [value] : [new Uint8Array(value)];
31280
+ const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
31281
+ if (paddingLength) {
31282
+ data.push(new Uint8Array(paddingLength));
31283
+ }
31284
+ return concat(data);
31285
+ };
31286
+ __publicField4(ByteCoder, "memorySize", 1);
31287
+ var isFullyNativeEnum = (enumCoders) => Object.values(enumCoders).every(
31288
+ // @ts-expect-error complicated types
31289
+ ({ type: type3, coders }) => type3 === "()" && JSON.stringify(coders) === JSON.stringify([])
31290
+ );
31291
+ var EnumCoder = class extends Coder {
31292
+ name;
31293
+ coders;
31294
+ #caseIndexCoder;
31295
+ #encodedValueSize;
31296
+ constructor(name, coders) {
31297
+ const caseIndexCoder = new BigNumberCoder("u64");
31298
+ const encodedValueSize = Object.values(coders).reduce(
31299
+ (max, coder) => Math.max(max, coder.encodedLength),
31300
+ 0
31301
+ );
31302
+ super(`enum ${name}`, `enum ${name}`, caseIndexCoder.encodedLength + encodedValueSize);
31303
+ this.name = name;
31304
+ this.coders = coders;
31305
+ this.#caseIndexCoder = caseIndexCoder;
31306
+ this.#encodedValueSize = encodedValueSize;
31307
+ }
31308
+ #encodeNativeEnum(value) {
31309
+ const valueCoder = this.coders[value];
31310
+ const encodedValue = valueCoder.encode([]);
31311
+ const caseIndex = Object.keys(this.coders).indexOf(value);
31312
+ const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
31313
+ return concat([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
31314
+ }
31315
+ encode(value) {
31316
+ if (typeof value === "string" && this.coders[value]) {
31317
+ return this.#encodeNativeEnum(value);
31318
+ }
31319
+ const [caseKey, ...empty] = Object.keys(value);
31320
+ if (!caseKey) {
31321
+ throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "A field for the case must be provided.");
31322
+ }
31323
+ if (empty.length !== 0) {
31324
+ throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "Only one field must be provided.");
31325
+ }
31326
+ const valueCoder = this.coders[caseKey];
31327
+ const caseIndex = Object.keys(this.coders).indexOf(caseKey);
31328
+ const encodedValue = valueCoder.encode(value[caseKey]);
31329
+ const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
31330
+ return concatWithDynamicData([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
31331
+ }
31332
+ #decodeNativeEnum(caseKey, newOffset) {
31333
+ return [caseKey, newOffset];
31334
+ }
31335
+ decode(data, offset) {
31336
+ if (data.length < this.#encodedValueSize) {
31337
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid enum data size.`);
31338
+ }
31339
+ let newOffset = offset;
31340
+ let decoded;
31341
+ [decoded, newOffset] = new BigNumberCoder("u64").decode(data, newOffset);
31342
+ const caseIndex = toNumber(decoded);
31343
+ const caseKey = Object.keys(this.coders)[caseIndex];
31344
+ if (!caseKey) {
31345
+ throw new FuelError(
31346
+ ErrorCode.INVALID_DECODE_VALUE,
31347
+ `Invalid caseIndex "${caseIndex}". Valid cases: ${Object.keys(this.coders)}.`
31348
+ );
31349
+ }
31350
+ const valueCoder = this.coders[caseKey];
31351
+ const padding = this.#encodedValueSize - valueCoder.encodedLength;
31352
+ newOffset += padding;
31353
+ [decoded, newOffset] = valueCoder.decode(data, newOffset);
31354
+ if (isFullyNativeEnum(this.coders)) {
31355
+ return this.#decodeNativeEnum(caseKey, newOffset);
31356
+ }
31357
+ return [{ [caseKey]: decoded }, newOffset];
31358
+ }
31359
+ };
31360
+ var OptionCoder = class extends EnumCoder {
31361
+ encode(value) {
31362
+ const result = super.encode(this.toSwayOption(value));
31363
+ return result;
31364
+ }
31365
+ toSwayOption(input) {
31366
+ if (input !== void 0) {
31367
+ return { Some: input };
31368
+ }
31369
+ return { None: [] };
31274
31370
  }
31275
31371
  decode(data, offset) {
31276
31372
  if (data.length < this.encodedLength) {
31277
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} data size.`);
31373
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid option data size.`);
31278
31374
  }
31279
- let bytes2 = data.slice(offset, offset + this.encodedLength);
31280
- bytes2 = bytes2.slice(0, this.encodedLength);
31281
- if (bytes2.length !== this.encodedLength) {
31282
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} byte data size.`);
31375
+ const [decoded, newOffset] = super.decode(data, offset);
31376
+ return [this.toOption(decoded), newOffset];
31377
+ }
31378
+ toOption(output2) {
31379
+ if (output2 && "Some" in output2) {
31380
+ return output2.Some;
31283
31381
  }
31284
- return [bn(bytes2), offset + this.encodedLength];
31382
+ return void 0;
31285
31383
  }
31286
31384
  };
31287
- var BooleanCoder = class extends Coder {
31385
+ var NumberCoder = class extends Coder {
31386
+ // This is to align the bits to the total bytes
31387
+ // See https://github.com/FuelLabs/fuel-specs/blob/master/specs/protocol/abi.md#unsigned-integers
31388
+ length;
31389
+ paddingLength;
31390
+ baseType;
31288
31391
  options;
31289
- constructor(options = {
31290
- padToWordSize: false
31392
+ constructor(baseType, options = {
31393
+ isSmallBytes: false,
31394
+ isRightPadded: false
31291
31395
  }) {
31292
- const encodedLength = options.padToWordSize ? WORD_SIZE : 1;
31293
- super("boolean", "boolean", encodedLength);
31396
+ const paddingLength = options.isSmallBytes && baseType === "u8" ? 1 : 8;
31397
+ super("number", baseType, paddingLength);
31398
+ this.baseType = baseType;
31399
+ switch (baseType) {
31400
+ case "u8":
31401
+ this.length = 1;
31402
+ break;
31403
+ case "u16":
31404
+ this.length = 2;
31405
+ break;
31406
+ case "u32":
31407
+ default:
31408
+ this.length = 4;
31409
+ break;
31410
+ }
31411
+ this.paddingLength = paddingLength;
31294
31412
  this.options = options;
31295
31413
  }
31414
+ encode(value) {
31415
+ let bytes2;
31416
+ try {
31417
+ bytes2 = toBytes2(value);
31418
+ } catch (error) {
31419
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}.`);
31420
+ }
31421
+ if (bytes2.length > this.length) {
31422
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}, too many bytes.`);
31423
+ }
31424
+ const output2 = toBytes2(bytes2, this.paddingLength);
31425
+ if (this.baseType !== "u8") {
31426
+ return output2;
31427
+ }
31428
+ return this.options.isRightPadded ? output2.reverse() : output2;
31429
+ }
31430
+ decodeU8(data, offset) {
31431
+ let bytes2;
31432
+ if (this.options.isRightPadded) {
31433
+ bytes2 = data.slice(offset, offset + 1);
31434
+ } else {
31435
+ bytes2 = data.slice(offset, offset + this.paddingLength);
31436
+ bytes2 = bytes2.slice(this.paddingLength - this.length, this.paddingLength);
31437
+ }
31438
+ return [toNumber(bytes2), offset + this.paddingLength];
31439
+ }
31440
+ decode(data, offset) {
31441
+ if (data.length < this.paddingLength) {
31442
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);
31443
+ }
31444
+ if (this.baseType === "u8") {
31445
+ return this.decodeU8(data, offset);
31446
+ }
31447
+ let bytes2 = data.slice(offset, offset + this.paddingLength);
31448
+ bytes2 = bytes2.slice(8 - this.length, 8);
31449
+ if (bytes2.length !== this.paddingLength - (this.paddingLength - this.length)) {
31450
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);
31451
+ }
31452
+ return [toNumber(bytes2), offset + 8];
31453
+ }
31454
+ };
31455
+ var RawSliceCoder = class extends Coder {
31456
+ constructor() {
31457
+ super("raw untyped slice", "raw untyped slice", BASE_RAW_SLICE_OFFSET);
31458
+ }
31459
+ encode(value) {
31460
+ if (!Array.isArray(value)) {
31461
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
31462
+ }
31463
+ const parts = [];
31464
+ const coder = new NumberCoder("u8", { isSmallBytes: true });
31465
+ const pointer = new BigNumberCoder("u64").encode(
31466
+ BASE_RAW_SLICE_OFFSET
31467
+ );
31468
+ pointer.dynamicData = {
31469
+ 0: concatWithDynamicData(value.map((v) => coder.encode(v)))
31470
+ };
31471
+ parts.push(pointer);
31472
+ parts.push(new BigNumberCoder("u64").encode(value.length));
31473
+ return concatWithDynamicData(parts);
31474
+ }
31475
+ decode(data, offset) {
31476
+ const dataBytes = data.slice(offset);
31477
+ const internalCoder = new ArrayCoder(
31478
+ new NumberCoder("u8", { isSmallBytes: true }),
31479
+ dataBytes.length
31480
+ );
31481
+ const [decodedValue] = internalCoder.decode(dataBytes, 0);
31482
+ return [decodedValue, offset + dataBytes.length];
31483
+ }
31484
+ };
31485
+ var _getPaddedData2;
31486
+ var getPaddedData_fn2;
31487
+ var StdStringCoder = class extends Coder {
31488
+ constructor() {
31489
+ super("struct", "struct String", 1);
31490
+ __privateAdd2(this, _getPaddedData2);
31491
+ }
31492
+ encode(value) {
31493
+ const parts = [];
31494
+ const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
31495
+ const data = __privateMethod2(this, _getPaddedData2, getPaddedData_fn2).call(this, value);
31496
+ pointer.dynamicData = {
31497
+ 0: concatWithDynamicData([data])
31498
+ };
31499
+ parts.push(pointer);
31500
+ parts.push(new BigNumberCoder("u64").encode(data.byteLength));
31501
+ parts.push(new BigNumberCoder("u64").encode(value.length));
31502
+ return concatWithDynamicData(parts);
31503
+ }
31504
+ decode(data, offset) {
31505
+ if (data.length < this.encodedLength) {
31506
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string data size.`);
31507
+ }
31508
+ const len = data.slice(16, 24);
31509
+ const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
31510
+ const byteData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + encodedLength);
31511
+ if (byteData.length !== encodedLength) {
31512
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string byte data size.`);
31513
+ }
31514
+ const value = toUtf8String(byteData);
31515
+ return [value, offset + BASE_VECTOR_OFFSET];
31516
+ }
31517
+ };
31518
+ _getPaddedData2 = /* @__PURE__ */ new WeakSet();
31519
+ getPaddedData_fn2 = function(value) {
31520
+ const data = [toUtf8Bytes(value)];
31521
+ const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
31522
+ if (paddingLength) {
31523
+ data.push(new Uint8Array(paddingLength));
31524
+ }
31525
+ return concat(data);
31526
+ };
31527
+ __publicField4(StdStringCoder, "memorySize", 1);
31528
+ var StringCoder = class extends Coder {
31529
+ length;
31530
+ #paddingLength;
31531
+ constructor(length) {
31532
+ let paddingLength = (8 - length) % 8;
31533
+ paddingLength = paddingLength < 0 ? paddingLength + 8 : paddingLength;
31534
+ super("string", `str[${length}]`, length + paddingLength);
31535
+ this.length = length;
31536
+ this.#paddingLength = paddingLength;
31537
+ }
31538
+ encode(value) {
31539
+ if (this.length !== value.length) {
31540
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Value length mismatch during encode.`);
31541
+ }
31542
+ const encoded = toUtf8Bytes(value);
31543
+ const padding = new Uint8Array(this.#paddingLength);
31544
+ return concat([encoded, padding]);
31545
+ }
31546
+ decode(data, offset) {
31547
+ if (data.length < this.encodedLength) {
31548
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string data size.`);
31549
+ }
31550
+ const bytes2 = data.slice(offset, offset + this.length);
31551
+ if (bytes2.length !== this.length) {
31552
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string byte data size.`);
31553
+ }
31554
+ const value = toUtf8String(bytes2);
31555
+ const padding = this.#paddingLength;
31556
+ return [value, offset + this.length + padding];
31557
+ }
31558
+ };
31559
+ var StructCoder = class extends Coder {
31560
+ name;
31561
+ coders;
31562
+ constructor(name, coders) {
31563
+ const encodedLength = Object.values(coders).reduce(
31564
+ (acc, coder) => acc + coder.encodedLength,
31565
+ 0
31566
+ );
31567
+ super("struct", `struct ${name}`, encodedLength);
31568
+ this.name = name;
31569
+ this.coders = coders;
31570
+ }
31571
+ encode(value) {
31572
+ const encodedFields = Object.keys(this.coders).map((fieldName) => {
31573
+ const fieldCoder = this.coders[fieldName];
31574
+ const fieldValue = value[fieldName];
31575
+ if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
31576
+ throw new FuelError(
31577
+ ErrorCode.ENCODE_ERROR,
31578
+ `Invalid ${this.type}. Field "${fieldName}" not present.`
31579
+ );
31580
+ }
31581
+ const encoded = fieldCoder.encode(fieldValue);
31582
+ if (!isMultipleOfWordSize(encoded.length)) {
31583
+ return rightPadToWordSize(encoded);
31584
+ }
31585
+ return encoded;
31586
+ });
31587
+ return concatWithDynamicData([concatWithDynamicData(encodedFields)]);
31588
+ }
31589
+ decode(data, offset) {
31590
+ if (data.length < this.encodedLength) {
31591
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid struct data size.`);
31592
+ }
31593
+ let newOffset = offset;
31594
+ const decodedValue = Object.keys(this.coders).reduce((obj, fieldName) => {
31595
+ const fieldCoder = this.coders[fieldName];
31596
+ let decoded;
31597
+ [decoded, newOffset] = fieldCoder.decode(data, newOffset);
31598
+ if (!isMultipleOfWordSize(newOffset)) {
31599
+ newOffset += getWordSizePadding(newOffset);
31600
+ }
31601
+ obj[fieldName] = decoded;
31602
+ return obj;
31603
+ }, {});
31604
+ return [decodedValue, newOffset];
31605
+ }
31606
+ };
31607
+ var TupleCoder = class extends Coder {
31608
+ coders;
31609
+ constructor(coders) {
31610
+ const encodedLength = coders.reduce((acc, coder) => acc + coder.encodedLength, 0);
31611
+ super("tuple", `(${coders.map((coder) => coder.type).join(", ")})`, encodedLength);
31612
+ this.coders = coders;
31613
+ }
31614
+ encode(value) {
31615
+ if (this.coders.length !== value.length) {
31616
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
31617
+ }
31618
+ return concatWithDynamicData(
31619
+ this.coders.map((coder, i) => {
31620
+ const encoded = coder.encode(value[i]);
31621
+ if (!isMultipleOfWordSize(encoded.length)) {
31622
+ return rightPadToWordSize(encoded);
31623
+ }
31624
+ return encoded;
31625
+ })
31626
+ );
31627
+ }
31628
+ decode(data, offset) {
31629
+ if (data.length < this.encodedLength) {
31630
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid tuple data size.`);
31631
+ }
31632
+ let newOffset = offset;
31633
+ const decodedValue = this.coders.map((coder) => {
31634
+ let decoded;
31635
+ [decoded, newOffset] = coder.decode(data, newOffset);
31636
+ if (!isMultipleOfWordSize(newOffset)) {
31637
+ newOffset += getWordSizePadding(newOffset);
31638
+ }
31639
+ return decoded;
31640
+ });
31641
+ return [decodedValue, newOffset];
31642
+ }
31643
+ };
31644
+ var VecCoder = class extends Coder {
31645
+ coder;
31646
+ constructor(coder) {
31647
+ super("struct", `struct Vec`, coder.encodedLength + BASE_VECTOR_OFFSET);
31648
+ this.coder = coder;
31649
+ }
31650
+ encode(value) {
31651
+ if (!Array.isArray(value) && !isUint8Array(value)) {
31652
+ throw new FuelError(
31653
+ ErrorCode.ENCODE_ERROR,
31654
+ `Expected array value, or a Uint8Array. You can use arrayify to convert a value to a Uint8Array.`
31655
+ );
31656
+ }
31657
+ const parts = [];
31658
+ const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
31659
+ pointer.dynamicData = {
31660
+ 0: concatWithDynamicData(Array.from(value).map((v) => this.coder.encode(v)))
31661
+ };
31662
+ parts.push(pointer);
31663
+ parts.push(new BigNumberCoder("u64").encode(value.length));
31664
+ parts.push(new BigNumberCoder("u64").encode(value.length));
31665
+ return concatWithDynamicData(parts);
31666
+ }
31667
+ decode(data, offset) {
31668
+ if (data.length < BASE_VECTOR_OFFSET || data.length > MAX_BYTES) {
31669
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec data size.`);
31670
+ }
31671
+ const len = data.slice(16, 24);
31672
+ const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
31673
+ const vectorRawDataLength = encodedLength * this.coder.encodedLength;
31674
+ const vectorRawData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + vectorRawDataLength);
31675
+ if (vectorRawData.length !== vectorRawDataLength) {
31676
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec byte data size.`);
31677
+ }
31678
+ return [
31679
+ chunkByLength(vectorRawData, this.coder.encodedLength).map(
31680
+ (chunk) => this.coder.decode(chunk, 0)[0]
31681
+ ),
31682
+ offset + BASE_VECTOR_OFFSET
31683
+ ];
31684
+ }
31685
+ };
31686
+ var getEncodingVersion = (encoding) => {
31687
+ switch (encoding) {
31688
+ case void 0:
31689
+ case ENCODING_V0:
31690
+ return ENCODING_V0;
31691
+ case ENCODING_V1:
31692
+ return ENCODING_V1;
31693
+ default:
31694
+ throw new FuelError(
31695
+ ErrorCode.UNSUPPORTED_ENCODING_VERSION,
31696
+ `Encoding version '${encoding}' is unsupported.`
31697
+ );
31698
+ }
31699
+ };
31700
+ var findFunctionByName = (abi, name) => {
31701
+ const fn = abi.functions.find((f2) => f2.name === name);
31702
+ if (!fn) {
31703
+ throw new FuelError(
31704
+ ErrorCode.FUNCTION_NOT_FOUND,
31705
+ `Function with name '${name}' doesn't exist in the ABI`
31706
+ );
31707
+ }
31708
+ return fn;
31709
+ };
31710
+ var findTypeById = (abi, typeId) => {
31711
+ const type3 = abi.types.find((t) => t.typeId === typeId);
31712
+ if (!type3) {
31713
+ throw new FuelError(
31714
+ ErrorCode.TYPE_NOT_FOUND,
31715
+ `Type with typeId '${typeId}' doesn't exist in the ABI.`
31716
+ );
31717
+ }
31718
+ return type3;
31719
+ };
31720
+ var findNonEmptyInputs = (abi, inputs) => inputs.filter((input) => findTypeById(abi, input.type).type !== "()");
31721
+ var findVectorBufferArgument = (components) => {
31722
+ const bufferComponent = components.find((c) => c.name === "buf");
31723
+ const bufferTypeArgument = bufferComponent?.originalTypeArguments?.[0];
31724
+ if (!bufferComponent || !bufferTypeArgument) {
31725
+ throw new FuelError(
31726
+ ErrorCode.INVALID_COMPONENT,
31727
+ `The Vec type provided is missing or has a malformed 'buf' component.`
31728
+ );
31729
+ }
31730
+ return bufferTypeArgument;
31731
+ };
31732
+ var ResolvedAbiType = class {
31733
+ abi;
31734
+ name;
31735
+ type;
31736
+ originalTypeArguments;
31737
+ components;
31738
+ constructor(abi, argument) {
31739
+ this.abi = abi;
31740
+ this.name = argument.name;
31741
+ const type3 = findTypeById(abi, argument.type);
31742
+ this.type = type3.type;
31743
+ this.originalTypeArguments = argument.typeArguments;
31744
+ this.components = ResolvedAbiType.getResolvedGenericComponents(
31745
+ abi,
31746
+ argument,
31747
+ type3.components,
31748
+ type3.typeParameters ?? ResolvedAbiType.getImplicitGenericTypeParameters(abi, type3.components)
31749
+ );
31750
+ }
31751
+ static getResolvedGenericComponents(abi, arg, components, typeParameters) {
31752
+ if (components === null) {
31753
+ return null;
31754
+ }
31755
+ if (typeParameters === null || typeParameters.length === 0) {
31756
+ return components.map((c) => new ResolvedAbiType(abi, c));
31757
+ }
31758
+ const typeParametersAndArgsMap = typeParameters.reduce(
31759
+ (obj, typeParameter, typeParameterIndex) => {
31760
+ const o = { ...obj };
31761
+ o[typeParameter] = structuredClone(
31762
+ arg.typeArguments?.[typeParameterIndex]
31763
+ );
31764
+ return o;
31765
+ },
31766
+ {}
31767
+ );
31768
+ const resolvedComponents = this.resolveGenericArgTypes(
31769
+ abi,
31770
+ components,
31771
+ typeParametersAndArgsMap
31772
+ );
31773
+ return resolvedComponents.map((c) => new ResolvedAbiType(abi, c));
31774
+ }
31775
+ static resolveGenericArgTypes(abi, args, typeParametersAndArgsMap) {
31776
+ return args.map((arg) => {
31777
+ if (typeParametersAndArgsMap[arg.type] !== void 0) {
31778
+ return {
31779
+ ...typeParametersAndArgsMap[arg.type],
31780
+ name: arg.name
31781
+ };
31782
+ }
31783
+ if (arg.typeArguments) {
31784
+ return {
31785
+ ...structuredClone(arg),
31786
+ typeArguments: this.resolveGenericArgTypes(
31787
+ abi,
31788
+ arg.typeArguments,
31789
+ typeParametersAndArgsMap
31790
+ )
31791
+ };
31792
+ }
31793
+ const argType = findTypeById(abi, arg.type);
31794
+ const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
31795
+ if (implicitTypeParameters && implicitTypeParameters.length > 0) {
31796
+ return {
31797
+ ...structuredClone(arg),
31798
+ typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
31799
+ };
31800
+ }
31801
+ return arg;
31802
+ });
31803
+ }
31804
+ static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
31805
+ if (!Array.isArray(args)) {
31806
+ return null;
31807
+ }
31808
+ const implicitGenericParameters = implicitGenericParametersParam ?? [];
31809
+ args.forEach((a) => {
31810
+ const argType = findTypeById(abi, a.type);
31811
+ if (genericRegEx.test(argType.type)) {
31812
+ implicitGenericParameters.push(argType.typeId);
31813
+ return;
31814
+ }
31815
+ if (!Array.isArray(a.typeArguments)) {
31816
+ return;
31817
+ }
31818
+ this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters);
31819
+ });
31820
+ return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
31821
+ }
31822
+ getSignature() {
31823
+ const prefix = this.getArgSignaturePrefix();
31824
+ const content = this.getArgSignatureContent();
31825
+ return `${prefix}${content}`;
31826
+ }
31827
+ getArgSignaturePrefix() {
31828
+ const structMatch = structRegEx.test(this.type);
31829
+ if (structMatch) {
31830
+ return "s";
31831
+ }
31832
+ const arrayMatch = arrayRegEx.test(this.type);
31833
+ if (arrayMatch) {
31834
+ return "a";
31835
+ }
31836
+ const enumMatch = enumRegEx.test(this.type);
31837
+ if (enumMatch) {
31838
+ return "e";
31839
+ }
31840
+ return "";
31841
+ }
31842
+ getArgSignatureContent() {
31843
+ if (this.type === "raw untyped ptr") {
31844
+ return "rawptr";
31845
+ }
31846
+ if (this.type === "raw untyped slice") {
31847
+ return "rawslice";
31848
+ }
31849
+ const strMatch = stringRegEx.exec(this.type)?.groups;
31850
+ if (strMatch) {
31851
+ return `str[${strMatch.length}]`;
31852
+ }
31853
+ if (this.components === null) {
31854
+ return this.type;
31855
+ }
31856
+ const arrayMatch = arrayRegEx.exec(this.type)?.groups;
31857
+ if (arrayMatch) {
31858
+ return `[${this.components[0].getSignature()};${arrayMatch.length}]`;
31859
+ }
31860
+ const typeArgumentsSignature = this.originalTypeArguments !== null ? `<${this.originalTypeArguments.map((a) => new ResolvedAbiType(this.abi, a).getSignature()).join(",")}>` : "";
31861
+ const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
31862
+ return `${typeArgumentsSignature}${componentsSignature}`;
31863
+ }
31864
+ };
31865
+ function getCoders(components, options) {
31866
+ const { getCoder: getCoder3 } = options;
31867
+ return components.reduce((obj, component) => {
31868
+ const o = obj;
31869
+ o[component.name] = getCoder3(component, options);
31870
+ return o;
31871
+ }, {});
31872
+ }
31873
+ var getCoder = (resolvedAbiType, options) => {
31874
+ switch (resolvedAbiType.type) {
31875
+ case U8_CODER_TYPE:
31876
+ case U16_CODER_TYPE:
31877
+ case U32_CODER_TYPE:
31878
+ return new NumberCoder(resolvedAbiType.type, options);
31879
+ case U64_CODER_TYPE:
31880
+ case RAW_PTR_CODER_TYPE:
31881
+ return new BigNumberCoder("u64");
31882
+ case U256_CODER_TYPE:
31883
+ return new BigNumberCoder("u256");
31884
+ case RAW_SLICE_CODER_TYPE:
31885
+ return new RawSliceCoder();
31886
+ case BOOL_CODER_TYPE:
31887
+ return new BooleanCoder(options);
31888
+ case B256_CODER_TYPE:
31889
+ return new B256Coder();
31890
+ case B512_CODER_TYPE:
31891
+ return new B512Coder();
31892
+ case BYTES_CODER_TYPE:
31893
+ return new ByteCoder();
31894
+ case STD_STRING_CODER_TYPE:
31895
+ return new StdStringCoder();
31896
+ default:
31897
+ break;
31898
+ }
31899
+ const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
31900
+ if (stringMatch) {
31901
+ const length = parseInt(stringMatch.length, 10);
31902
+ return new StringCoder(length);
31903
+ }
31904
+ const components = resolvedAbiType.components;
31905
+ const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
31906
+ if (arrayMatch) {
31907
+ const length = parseInt(arrayMatch.length, 10);
31908
+ const arg = components[0];
31909
+ if (!arg) {
31910
+ throw new FuelError(
31911
+ ErrorCode.INVALID_COMPONENT,
31912
+ `The provided Array type is missing an item of 'component'.`
31913
+ );
31914
+ }
31915
+ const arrayElementCoder = getCoder(arg, { isSmallBytes: true });
31916
+ return new ArrayCoder(arrayElementCoder, length);
31917
+ }
31918
+ if (resolvedAbiType.type === VEC_CODER_TYPE) {
31919
+ const arg = findVectorBufferArgument(components);
31920
+ const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
31921
+ const itemCoder = getCoder(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
31922
+ return new VecCoder(itemCoder);
31923
+ }
31924
+ const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
31925
+ if (structMatch) {
31926
+ const coders = getCoders(components, { isRightPadded: true, getCoder });
31927
+ return new StructCoder(structMatch.name, coders);
31928
+ }
31929
+ const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
31930
+ if (enumMatch) {
31931
+ const coders = getCoders(components, { getCoder });
31932
+ const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
31933
+ if (isOptionEnum) {
31934
+ return new OptionCoder(enumMatch.name, coders);
31935
+ }
31936
+ return new EnumCoder(enumMatch.name, coders);
31937
+ }
31938
+ const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
31939
+ if (tupleMatch) {
31940
+ const coders = components.map(
31941
+ (component) => getCoder(component, { isRightPadded: true, encoding: ENCODING_V0 })
31942
+ );
31943
+ return new TupleCoder(coders);
31944
+ }
31945
+ if (resolvedAbiType.type === STR_SLICE_CODER_TYPE) {
31946
+ throw new FuelError(
31947
+ ErrorCode.INVALID_DATA,
31948
+ "String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
31949
+ );
31950
+ }
31951
+ throw new FuelError(
31952
+ ErrorCode.CODER_NOT_FOUND,
31953
+ `Coder not found: ${JSON.stringify(resolvedAbiType)}.`
31954
+ );
31955
+ };
31956
+ var BooleanCoder2 = class extends Coder {
31957
+ constructor() {
31958
+ super("boolean", "boolean", 1);
31959
+ }
31296
31960
  encode(value) {
31297
31961
  const isTrueBool = value === true || value === false;
31298
31962
  if (!isTrueBool) {
@@ -31314,7 +31978,7 @@ This unreleased fuel-core build may include features and updates not yet support
31314
31978
  return [true, offset + this.encodedLength];
31315
31979
  }
31316
31980
  };
31317
- var ByteCoder = class extends Coder {
31981
+ var ByteCoder2 = class extends Coder {
31318
31982
  constructor() {
31319
31983
  super("struct", "struct Bytes", WORD_SIZE);
31320
31984
  }
@@ -31337,12 +32001,12 @@ This unreleased fuel-core build may include features and updates not yet support
31337
32001
  return [dataBytes, offsetAndLength + length];
31338
32002
  }
31339
32003
  };
31340
- __publicField4(ByteCoder, "memorySize", 1);
31341
- var isFullyNativeEnum = (enumCoders) => Object.values(enumCoders).every(
32004
+ __publicField4(ByteCoder2, "memorySize", 1);
32005
+ var isFullyNativeEnum2 = (enumCoders) => Object.values(enumCoders).every(
31342
32006
  // @ts-expect-error complicated types
31343
32007
  ({ type: type3, coders }) => type3 === "()" && JSON.stringify(coders) === JSON.stringify([])
31344
32008
  );
31345
- var EnumCoder = class extends Coder {
32009
+ var EnumCoder2 = class extends Coder {
31346
32010
  name;
31347
32011
  coders;
31348
32012
  #caseIndexCoder;
@@ -31401,7 +32065,7 @@ This unreleased fuel-core build may include features and updates not yet support
31401
32065
  const valueCoder = this.coders[caseKey];
31402
32066
  const offsetAndCase = offset + WORD_SIZE;
31403
32067
  const [decoded, newOffset] = valueCoder.decode(data, offsetAndCase);
31404
- if (isFullyNativeEnum(this.coders)) {
32068
+ if (isFullyNativeEnum2(this.coders)) {
31405
32069
  return this.#decodeNativeEnum(caseKey, newOffset);
31406
32070
  }
31407
32071
  return [{ [caseKey]: decoded }, newOffset];
@@ -31419,16 +32083,14 @@ This unreleased fuel-core build may include features and updates not yet support
31419
32083
  throw new FuelError(ErrorCode.TYPE_NOT_SUPPORTED, `Invalid number type: ${baseType}`);
31420
32084
  }
31421
32085
  };
31422
- var NumberCoder = class extends Coder {
32086
+ var NumberCoder2 = class extends Coder {
32087
+ length;
31423
32088
  baseType;
31424
- options;
31425
- constructor(baseType, options = {
31426
- padToWordSize: false
31427
- }) {
31428
- const length = options.padToWordSize ? WORD_SIZE : getLength(baseType);
32089
+ constructor(baseType) {
32090
+ const length = getLength(baseType);
31429
32091
  super("number", baseType, length);
31430
32092
  this.baseType = baseType;
31431
- this.options = options;
32093
+ this.length = length;
31432
32094
  }
31433
32095
  encode(value) {
31434
32096
  let bytes2;
@@ -31437,23 +32099,23 @@ This unreleased fuel-core build may include features and updates not yet support
31437
32099
  } catch (error) {
31438
32100
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}.`);
31439
32101
  }
31440
- if (bytes2.length > this.encodedLength) {
32102
+ if (bytes2.length > this.length) {
31441
32103
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}, too many bytes.`);
31442
32104
  }
31443
- return toBytes2(bytes2, this.encodedLength);
32105
+ return toBytes2(bytes2, this.length);
31444
32106
  }
31445
32107
  decode(data, offset) {
31446
32108
  if (data.length < this.encodedLength) {
31447
32109
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);
31448
32110
  }
31449
- const bytes2 = data.slice(offset, offset + this.encodedLength);
32111
+ const bytes2 = data.slice(offset, offset + this.length);
31450
32112
  if (bytes2.length !== this.encodedLength) {
31451
32113
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);
31452
32114
  }
31453
- return [toNumber(bytes2), offset + this.encodedLength];
32115
+ return [toNumber(bytes2), offset + this.length];
31454
32116
  }
31455
32117
  };
31456
- var OptionCoder = class extends EnumCoder {
32118
+ var OptionCoder2 = class extends EnumCoder2 {
31457
32119
  encode(value) {
31458
32120
  const result = super.encode(this.toSwayOption(value));
31459
32121
  return result;
@@ -31475,7 +32137,7 @@ This unreleased fuel-core build may include features and updates not yet support
31475
32137
  return void 0;
31476
32138
  }
31477
32139
  };
31478
- var RawSliceCoder = class extends Coder {
32140
+ var RawSliceCoder2 = class extends Coder {
31479
32141
  constructor() {
31480
32142
  super("raw untyped slice", "raw untyped slice", WORD_SIZE);
31481
32143
  }
@@ -31483,7 +32145,7 @@ This unreleased fuel-core build may include features and updates not yet support
31483
32145
  if (!Array.isArray(value)) {
31484
32146
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
31485
32147
  }
31486
- const internalCoder = new ArrayCoder(new NumberCoder("u8"), value.length);
32148
+ const internalCoder = new ArrayCoder(new NumberCoder2("u8"), value.length);
31487
32149
  const bytes2 = internalCoder.encode(value);
31488
32150
  const lengthBytes = new BigNumberCoder("u64").encode(bytes2.length);
31489
32151
  return new Uint8Array([...lengthBytes, ...bytes2]);
@@ -31499,12 +32161,12 @@ This unreleased fuel-core build may include features and updates not yet support
31499
32161
  if (dataBytes.length !== length) {
31500
32162
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice byte data size.`);
31501
32163
  }
31502
- const internalCoder = new ArrayCoder(new NumberCoder("u8"), length);
32164
+ const internalCoder = new ArrayCoder(new NumberCoder2("u8"), length);
31503
32165
  const [decodedValue] = internalCoder.decode(dataBytes, 0);
31504
32166
  return [decodedValue, offsetAndLength + length];
31505
32167
  }
31506
32168
  };
31507
- var StdStringCoder = class extends Coder {
32169
+ var StdStringCoder2 = class extends Coder {
31508
32170
  constructor() {
31509
32171
  super("struct", "struct String", WORD_SIZE);
31510
32172
  }
@@ -31527,7 +32189,7 @@ This unreleased fuel-core build may include features and updates not yet support
31527
32189
  return [toUtf8String(dataBytes), offsetAndLength + length];
31528
32190
  }
31529
32191
  };
31530
- __publicField4(StdStringCoder, "memorySize", 1);
32192
+ __publicField4(StdStringCoder2, "memorySize", 1);
31531
32193
  var StrSliceCoder = class extends Coder {
31532
32194
  constructor() {
31533
32195
  super("strSlice", "str", WORD_SIZE);
@@ -31552,7 +32214,7 @@ This unreleased fuel-core build may include features and updates not yet support
31552
32214
  }
31553
32215
  };
31554
32216
  __publicField4(StrSliceCoder, "memorySize", 1);
31555
- var StringCoder = class extends Coder {
32217
+ var StringCoder2 = class extends Coder {
31556
32218
  constructor(length) {
31557
32219
  super("string", `str[${length}]`, length);
31558
32220
  }
@@ -31573,7 +32235,7 @@ This unreleased fuel-core build may include features and updates not yet support
31573
32235
  return [toUtf8String(bytes2), offset + this.encodedLength];
31574
32236
  }
31575
32237
  };
31576
- var StructCoder = class extends Coder {
32238
+ var StructCoder2 = class extends Coder {
31577
32239
  name;
31578
32240
  coders;
31579
32241
  constructor(name, coders) {
@@ -31590,7 +32252,7 @@ This unreleased fuel-core build may include features and updates not yet support
31590
32252
  Object.keys(this.coders).map((fieldName) => {
31591
32253
  const fieldCoder = this.coders[fieldName];
31592
32254
  const fieldValue = value[fieldName];
31593
- if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
32255
+ if (!(fieldCoder instanceof OptionCoder2) && fieldValue == null) {
31594
32256
  throw new FuelError(
31595
32257
  ErrorCode.ENCODE_ERROR,
31596
32258
  `Invalid ${this.type}. Field "${fieldName}" not present.`
@@ -31615,7 +32277,7 @@ This unreleased fuel-core build may include features and updates not yet support
31615
32277
  return [decodedValue, newOffset];
31616
32278
  }
31617
32279
  };
31618
- var TupleCoder = class extends Coder {
32280
+ var TupleCoder2 = class extends Coder {
31619
32281
  coders;
31620
32282
  constructor(coders) {
31621
32283
  const encodedLength = coders.reduce((acc, coder) => acc + coder.encodedLength, 0);
@@ -31641,14 +32303,13 @@ This unreleased fuel-core build may include features and updates not yet support
31641
32303
  return [decodedValue, newOffset];
31642
32304
  }
31643
32305
  };
31644
- var isUint8Array = (value) => value instanceof Uint8Array;
31645
- var VecCoder = class extends Coder {
32306
+ var VecCoder2 = class extends Coder {
31646
32307
  coder;
31647
32308
  #isOptionVec;
31648
32309
  constructor(coder) {
31649
32310
  super("struct", `struct Vec`, coder.encodedLength + WORD_SIZE);
31650
32311
  this.coder = coder;
31651
- this.#isOptionVec = this.coder instanceof OptionCoder;
32312
+ this.#isOptionVec = this.coder instanceof OptionCoder2;
31652
32313
  }
31653
32314
  encode(value) {
31654
32315
  if (!Array.isArray(value) && !isUint8Array(value)) {
@@ -31672,9 +32333,9 @@ This unreleased fuel-core build may include features and updates not yet support
31672
32333
  const offsetAndLength = offset + WORD_SIZE;
31673
32334
  const lengthBytes = data.slice(offset, offsetAndLength);
31674
32335
  const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
31675
- const dataLength2 = length * this.coder.encodedLength;
31676
- const dataBytes = data.slice(offsetAndLength, offsetAndLength + dataLength2);
31677
- if (!this.#isOptionVec && dataBytes.length !== dataLength2) {
32336
+ const dataLength = length * this.coder.encodedLength;
32337
+ const dataBytes = data.slice(offsetAndLength, offsetAndLength + dataLength);
32338
+ if (!this.#isOptionVec && dataBytes.length !== dataLength) {
31678
32339
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec byte data size.`);
31679
32340
  }
31680
32341
  let newOffset = offsetAndLength;
@@ -31687,214 +32348,29 @@ This unreleased fuel-core build may include features and updates not yet support
31687
32348
  return [chunks, newOffset];
31688
32349
  }
31689
32350
  };
31690
- var getEncodingVersion = (encoding) => {
31691
- switch (encoding) {
31692
- case void 0:
31693
- case ENCODING_V1:
31694
- return ENCODING_V1;
31695
- default:
31696
- throw new FuelError(
31697
- ErrorCode.UNSUPPORTED_ENCODING_VERSION,
31698
- `Encoding version '${encoding}' is unsupported.`
31699
- );
31700
- }
31701
- };
31702
- var findFunctionByName = (abi, name) => {
31703
- const fn = abi.functions.find((f2) => f2.name === name);
31704
- if (!fn) {
31705
- throw new FuelError(
31706
- ErrorCode.FUNCTION_NOT_FOUND,
31707
- `Function with name '${name}' doesn't exist in the ABI`
31708
- );
31709
- }
31710
- return fn;
31711
- };
31712
- var findTypeById = (abi, typeId) => {
31713
- const type3 = abi.types.find((t) => t.typeId === typeId);
31714
- if (!type3) {
31715
- throw new FuelError(
31716
- ErrorCode.TYPE_NOT_FOUND,
31717
- `Type with typeId '${typeId}' doesn't exist in the ABI.`
31718
- );
31719
- }
31720
- return type3;
31721
- };
31722
- var findNonEmptyInputs = (abi, inputs) => inputs.filter((input) => findTypeById(abi, input.type).type !== "()");
31723
- var findVectorBufferArgument = (components) => {
31724
- const bufferComponent = components.find((c) => c.name === "buf");
31725
- const bufferTypeArgument = bufferComponent?.originalTypeArguments?.[0];
31726
- if (!bufferComponent || !bufferTypeArgument) {
31727
- throw new FuelError(
31728
- ErrorCode.INVALID_COMPONENT,
31729
- `The Vec type provided is missing or has a malformed 'buf' component.`
31730
- );
31731
- }
31732
- return bufferTypeArgument;
31733
- };
31734
- var ResolvedAbiType = class {
31735
- abi;
31736
- name;
31737
- type;
31738
- originalTypeArguments;
31739
- components;
31740
- constructor(abi, argument) {
31741
- this.abi = abi;
31742
- this.name = argument.name;
31743
- const type3 = findTypeById(abi, argument.type);
31744
- this.type = type3.type;
31745
- this.originalTypeArguments = argument.typeArguments;
31746
- this.components = ResolvedAbiType.getResolvedGenericComponents(
31747
- abi,
31748
- argument,
31749
- type3.components,
31750
- type3.typeParameters ?? ResolvedAbiType.getImplicitGenericTypeParameters(abi, type3.components)
31751
- );
31752
- }
31753
- static getResolvedGenericComponents(abi, arg, components, typeParameters) {
31754
- if (components === null) {
31755
- return null;
31756
- }
31757
- if (typeParameters === null || typeParameters.length === 0) {
31758
- return components.map((c) => new ResolvedAbiType(abi, c));
31759
- }
31760
- const typeParametersAndArgsMap = typeParameters.reduce(
31761
- (obj, typeParameter, typeParameterIndex) => {
31762
- const o = { ...obj };
31763
- o[typeParameter] = structuredClone(
31764
- arg.typeArguments?.[typeParameterIndex]
31765
- );
31766
- return o;
31767
- },
31768
- {}
31769
- );
31770
- const resolvedComponents = this.resolveGenericArgTypes(
31771
- abi,
31772
- components,
31773
- typeParametersAndArgsMap
31774
- );
31775
- return resolvedComponents.map((c) => new ResolvedAbiType(abi, c));
31776
- }
31777
- static resolveGenericArgTypes(abi, args, typeParametersAndArgsMap) {
31778
- return args.map((arg) => {
31779
- if (typeParametersAndArgsMap[arg.type] !== void 0) {
31780
- return {
31781
- ...typeParametersAndArgsMap[arg.type],
31782
- name: arg.name
31783
- };
31784
- }
31785
- if (arg.typeArguments) {
31786
- return {
31787
- ...structuredClone(arg),
31788
- typeArguments: this.resolveGenericArgTypes(
31789
- abi,
31790
- arg.typeArguments,
31791
- typeParametersAndArgsMap
31792
- )
31793
- };
31794
- }
31795
- const argType = findTypeById(abi, arg.type);
31796
- const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
31797
- if (implicitTypeParameters && implicitTypeParameters.length > 0) {
31798
- return {
31799
- ...structuredClone(arg),
31800
- typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
31801
- };
31802
- }
31803
- return arg;
31804
- });
31805
- }
31806
- static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
31807
- if (!Array.isArray(args)) {
31808
- return null;
31809
- }
31810
- const implicitGenericParameters = implicitGenericParametersParam ?? [];
31811
- args.forEach((a) => {
31812
- const argType = findTypeById(abi, a.type);
31813
- if (genericRegEx.test(argType.type)) {
31814
- implicitGenericParameters.push(argType.typeId);
31815
- return;
31816
- }
31817
- if (!Array.isArray(a.typeArguments)) {
31818
- return;
31819
- }
31820
- this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters);
31821
- });
31822
- return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
31823
- }
31824
- getSignature() {
31825
- const prefix = this.getArgSignaturePrefix();
31826
- const content = this.getArgSignatureContent();
31827
- return `${prefix}${content}`;
31828
- }
31829
- getArgSignaturePrefix() {
31830
- const structMatch = structRegEx.test(this.type);
31831
- if (structMatch) {
31832
- return "s";
31833
- }
31834
- const arrayMatch = arrayRegEx.test(this.type);
31835
- if (arrayMatch) {
31836
- return "a";
31837
- }
31838
- const enumMatch = enumRegEx.test(this.type);
31839
- if (enumMatch) {
31840
- return "e";
31841
- }
31842
- return "";
31843
- }
31844
- getArgSignatureContent() {
31845
- if (this.type === "raw untyped ptr") {
31846
- return "rawptr";
31847
- }
31848
- if (this.type === "raw untyped slice") {
31849
- return "rawslice";
31850
- }
31851
- const strMatch = stringRegEx.exec(this.type)?.groups;
31852
- if (strMatch) {
31853
- return `str[${strMatch.length}]`;
31854
- }
31855
- if (this.components === null) {
31856
- return this.type;
31857
- }
31858
- const arrayMatch = arrayRegEx.exec(this.type)?.groups;
31859
- if (arrayMatch) {
31860
- return `[${this.components[0].getSignature()};${arrayMatch.length}]`;
31861
- }
31862
- const typeArgumentsSignature = this.originalTypeArguments !== null ? `<${this.originalTypeArguments.map((a) => new ResolvedAbiType(this.abi, a).getSignature()).join(",")}>` : "";
31863
- const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
31864
- return `${typeArgumentsSignature}${componentsSignature}`;
31865
- }
31866
- };
31867
- function getCoders(components, options) {
31868
- const { getCoder: getCoder2 } = options;
31869
- return components.reduce((obj, component) => {
31870
- const o = obj;
31871
- o[component.name] = getCoder2(component, options);
31872
- return o;
31873
- }, {});
31874
- }
31875
- var getCoder = (resolvedAbiType, _options) => {
32351
+ var getCoder2 = (resolvedAbiType, _options) => {
31876
32352
  switch (resolvedAbiType.type) {
31877
32353
  case U8_CODER_TYPE:
31878
32354
  case U16_CODER_TYPE:
31879
32355
  case U32_CODER_TYPE:
31880
- return new NumberCoder(resolvedAbiType.type);
32356
+ return new NumberCoder2(resolvedAbiType.type);
31881
32357
  case U64_CODER_TYPE:
31882
32358
  case RAW_PTR_CODER_TYPE:
31883
32359
  return new BigNumberCoder("u64");
31884
32360
  case U256_CODER_TYPE:
31885
32361
  return new BigNumberCoder("u256");
31886
32362
  case RAW_SLICE_CODER_TYPE:
31887
- return new RawSliceCoder();
32363
+ return new RawSliceCoder2();
31888
32364
  case BOOL_CODER_TYPE:
31889
- return new BooleanCoder();
32365
+ return new BooleanCoder2();
31890
32366
  case B256_CODER_TYPE:
31891
32367
  return new B256Coder();
31892
32368
  case B512_CODER_TYPE:
31893
32369
  return new B512Coder();
31894
32370
  case BYTES_CODER_TYPE:
31895
- return new ByteCoder();
32371
+ return new ByteCoder2();
31896
32372
  case STD_STRING_CODER_TYPE:
31897
- return new StdStringCoder();
32373
+ return new StdStringCoder2();
31898
32374
  case STR_SLICE_CODER_TYPE:
31899
32375
  return new StrSliceCoder();
31900
32376
  default:
@@ -31903,7 +32379,7 @@ This unreleased fuel-core build may include features and updates not yet support
31903
32379
  const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
31904
32380
  if (stringMatch) {
31905
32381
  const length = parseInt(stringMatch.length, 10);
31906
- return new StringCoder(length);
32382
+ return new StringCoder2(length);
31907
32383
  }
31908
32384
  const components = resolvedAbiType.components;
31909
32385
  const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
@@ -31916,42 +32392,46 @@ This unreleased fuel-core build may include features and updates not yet support
31916
32392
  `The provided Array type is missing an item of 'component'.`
31917
32393
  );
31918
32394
  }
31919
- const arrayElementCoder = getCoder(arg);
32395
+ const arrayElementCoder = getCoder2(arg, { isSmallBytes: true });
31920
32396
  return new ArrayCoder(arrayElementCoder, length);
31921
32397
  }
31922
32398
  if (resolvedAbiType.type === VEC_CODER_TYPE) {
31923
32399
  const arg = findVectorBufferArgument(components);
31924
32400
  const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
31925
- const itemCoder = getCoder(argType, { encoding: ENCODING_V1 });
31926
- return new VecCoder(itemCoder);
32401
+ const itemCoder = getCoder2(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
32402
+ return new VecCoder2(itemCoder);
31927
32403
  }
31928
32404
  const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
31929
32405
  if (structMatch) {
31930
- const coders = getCoders(components, { getCoder });
31931
- return new StructCoder(structMatch.name, coders);
32406
+ const coders = getCoders(components, { isRightPadded: true, getCoder: getCoder2 });
32407
+ return new StructCoder2(structMatch.name, coders);
31932
32408
  }
31933
32409
  const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
31934
32410
  if (enumMatch) {
31935
- const coders = getCoders(components, { getCoder });
32411
+ const coders = getCoders(components, { getCoder: getCoder2 });
31936
32412
  const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
31937
32413
  if (isOptionEnum) {
31938
- return new OptionCoder(enumMatch.name, coders);
32414
+ return new OptionCoder2(enumMatch.name, coders);
31939
32415
  }
31940
- return new EnumCoder(enumMatch.name, coders);
32416
+ return new EnumCoder2(enumMatch.name, coders);
31941
32417
  }
31942
32418
  const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
31943
32419
  if (tupleMatch) {
31944
- const coders = components.map((component) => getCoder(component, { encoding: ENCODING_V1 }));
31945
- return new TupleCoder(coders);
32420
+ const coders = components.map(
32421
+ (component) => getCoder2(component, { isRightPadded: true, encoding: ENCODING_V0 })
32422
+ );
32423
+ return new TupleCoder2(coders);
31946
32424
  }
31947
32425
  throw new FuelError(
31948
32426
  ErrorCode.CODER_NOT_FOUND,
31949
32427
  `Coder not found: ${JSON.stringify(resolvedAbiType)}.`
31950
32428
  );
31951
32429
  };
31952
- function getCoderForEncoding(encoding = ENCODING_V1) {
32430
+ function getCoderForEncoding(encoding = ENCODING_V0) {
31953
32431
  switch (encoding) {
31954
32432
  case ENCODING_V1:
32433
+ return getCoder2;
32434
+ case ENCODING_V0:
31955
32435
  return getCoder;
31956
32436
  default:
31957
32437
  throw new FuelError(
@@ -31962,7 +32442,7 @@ This unreleased fuel-core build may include features and updates not yet support
31962
32442
  }
31963
32443
  var AbiCoder = class {
31964
32444
  static getCoder(abi, argument, options = {
31965
- padToWordSize: false
32445
+ isSmallBytes: false
31966
32446
  }) {
31967
32447
  const resolvedAbiType = new ResolvedAbiType(abi, argument);
31968
32448
  return getCoderForEncoding(options.encoding)(resolvedAbiType, options);
@@ -31982,6 +32462,8 @@ This unreleased fuel-core build may include features and updates not yet support
31982
32462
  name;
31983
32463
  jsonFn;
31984
32464
  attributes;
32465
+ isInputDataPointer;
32466
+ outputMetadata;
31985
32467
  jsonAbi;
31986
32468
  constructor(jsonAbi, name) {
31987
32469
  this.jsonAbi = jsonAbi;
@@ -31989,8 +32471,13 @@ This unreleased fuel-core build may include features and updates not yet support
31989
32471
  this.name = name;
31990
32472
  this.signature = FunctionFragment.getSignature(this.jsonAbi, this.jsonFn);
31991
32473
  this.selector = FunctionFragment.getFunctionSelector(this.signature);
31992
- this.selectorBytes = new StdStringCoder().encode(name);
32474
+ this.selectorBytes = new StdStringCoder2().encode(name);
31993
32475
  this.encoding = getEncodingVersion(jsonAbi.encoding);
32476
+ this.isInputDataPointer = this.#isInputDataPointer();
32477
+ this.outputMetadata = {
32478
+ isHeapType: this.#isOutputDataHeap(),
32479
+ encodedLength: this.#getOutputEncodedLength()
32480
+ };
31994
32481
  this.attributes = this.jsonFn.attributes ?? [];
31995
32482
  }
31996
32483
  static getSignature(abi, fn) {
@@ -32003,7 +32490,29 @@ This unreleased fuel-core build may include features and updates not yet support
32003
32490
  const hashedFunctionSignature = sha2562(bufferFromString2(functionSignature, "utf-8"));
32004
32491
  return bn(hashedFunctionSignature.slice(0, 10)).toHex(8);
32005
32492
  }
32006
- encodeArguments(values) {
32493
+ #isInputDataPointer() {
32494
+ const inputTypes = this.jsonFn.inputs.map((i) => findTypeById(this.jsonAbi, i.type));
32495
+ return this.jsonFn.inputs.length > 1 || isPointerType(inputTypes[0]?.type || "");
32496
+ }
32497
+ #isOutputDataHeap() {
32498
+ const outputType = findTypeById(this.jsonAbi, this.jsonFn.output.type);
32499
+ return isHeapType(outputType?.type || "");
32500
+ }
32501
+ #getOutputEncodedLength() {
32502
+ try {
32503
+ const heapCoder = AbiCoder.getCoder(this.jsonAbi, this.jsonFn.output);
32504
+ if (heapCoder instanceof VecCoder) {
32505
+ return heapCoder.coder.encodedLength;
32506
+ }
32507
+ if (heapCoder instanceof ByteCoder) {
32508
+ return ByteCoder.memorySize;
32509
+ }
32510
+ return heapCoder.encodedLength;
32511
+ } catch (e) {
32512
+ return 0;
32513
+ }
32514
+ }
32515
+ encodeArguments(values, offset = 0) {
32007
32516
  FunctionFragment.verifyArgsAndInputsAlign(values, this.jsonFn.inputs, this.jsonAbi);
32008
32517
  const shallowCopyValues = values.slice();
32009
32518
  const nonEmptyInputs = findNonEmptyInputs(this.jsonAbi, this.jsonFn.inputs);
@@ -32013,10 +32522,15 @@ This unreleased fuel-core build may include features and updates not yet support
32013
32522
  }
32014
32523
  const coders = nonEmptyInputs.map(
32015
32524
  (t) => AbiCoder.getCoder(this.jsonAbi, t, {
32525
+ isRightPadded: nonEmptyInputs.length > 1,
32016
32526
  encoding: this.encoding
32017
32527
  })
32018
32528
  );
32019
- return new TupleCoder(coders).encode(shallowCopyValues);
32529
+ if (this.encoding === ENCODING_V1) {
32530
+ return new TupleCoder2(coders).encode(shallowCopyValues);
32531
+ }
32532
+ const results = new TupleCoder(coders).encode(shallowCopyValues);
32533
+ return unpackDynamicData(results, offset, results.byteLength);
32020
32534
  }
32021
32535
  static verifyArgsAndInputsAlign(args, inputs, abi) {
32022
32536
  if (args.length === inputs.length) {
@@ -32125,9 +32639,9 @@ This unreleased fuel-core build may include features and updates not yet support
32125
32639
  const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
32126
32640
  return fragment.decodeArguments(data);
32127
32641
  }
32128
- encodeFunctionData(functionFragment, values) {
32642
+ encodeFunctionData(functionFragment, values, offset = 0) {
32129
32643
  const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
32130
- return fragment.encodeArguments(values);
32644
+ return fragment.encodeArguments(values, offset);
32131
32645
  }
32132
32646
  // Decode the result of a function call
32133
32647
  decodeFunctionResult(functionFragment, data) {
@@ -32155,7 +32669,9 @@ This unreleased fuel-core build may include features and updates not yet support
32155
32669
  );
32156
32670
  }
32157
32671
  return AbiCoder.encode(this.jsonAbi, configurable.configurableType, value, {
32158
- encoding: this.encoding
32672
+ isRightPadded: true,
32673
+ // TODO: Review support for configurables in v1 encoding when it becomes available
32674
+ encoding: ENCODING_V0
32159
32675
  });
32160
32676
  }
32161
32677
  getTypeById(typeId) {
@@ -32205,8 +32721,8 @@ This unreleased fuel-core build may include features and updates not yet support
32205
32721
  var TxPointerCoder = class extends StructCoder {
32206
32722
  constructor() {
32207
32723
  super("TxPointer", {
32208
- blockHeight: new NumberCoder("u32", { padToWordSize: true }),
32209
- txIndex: new NumberCoder("u16", { padToWordSize: true })
32724
+ blockHeight: new NumberCoder("u32"),
32725
+ txIndex: new NumberCoder("u16")
32210
32726
  });
32211
32727
  }
32212
32728
  };
@@ -32223,12 +32739,12 @@ This unreleased fuel-core build may include features and updates not yet support
32223
32739
  encode(value) {
32224
32740
  const parts = [];
32225
32741
  parts.push(new B256Coder().encode(value.txID));
32226
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputIndex));
32742
+ parts.push(new NumberCoder("u16").encode(value.outputIndex));
32227
32743
  parts.push(new B256Coder().encode(value.owner));
32228
32744
  parts.push(new BigNumberCoder("u64").encode(value.amount));
32229
32745
  parts.push(new B256Coder().encode(value.assetId));
32230
32746
  parts.push(new TxPointerCoder().encode(value.txPointer));
32231
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessIndex));
32747
+ parts.push(new NumberCoder("u16").encode(value.witnessIndex));
32232
32748
  parts.push(new BigNumberCoder("u64").encode(value.predicateGasUsed));
32233
32749
  parts.push(new BigNumberCoder("u64").encode(value.predicateLength));
32234
32750
  parts.push(new BigNumberCoder("u64").encode(value.predicateDataLength));
@@ -32243,7 +32759,7 @@ This unreleased fuel-core build may include features and updates not yet support
32243
32759
  let o = offset;
32244
32760
  [decoded, o] = new B256Coder().decode(data, o);
32245
32761
  const txID = decoded;
32246
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
32762
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
32247
32763
  const outputIndex = decoded;
32248
32764
  [decoded, o] = new B256Coder().decode(data, o);
32249
32765
  const owner = decoded;
@@ -32253,7 +32769,7 @@ This unreleased fuel-core build may include features and updates not yet support
32253
32769
  const assetId = decoded;
32254
32770
  [decoded, o] = new TxPointerCoder().decode(data, o);
32255
32771
  const txPointer = decoded;
32256
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
32772
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
32257
32773
  const witnessIndex = Number(decoded);
32258
32774
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
32259
32775
  const predicateGasUsed = decoded;
@@ -32292,7 +32808,7 @@ This unreleased fuel-core build may include features and updates not yet support
32292
32808
  encode(value) {
32293
32809
  const parts = [];
32294
32810
  parts.push(new B256Coder().encode(value.txID));
32295
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputIndex));
32811
+ parts.push(new NumberCoder("u16").encode(value.outputIndex));
32296
32812
  parts.push(new B256Coder().encode(value.balanceRoot));
32297
32813
  parts.push(new B256Coder().encode(value.stateRoot));
32298
32814
  parts.push(new TxPointerCoder().encode(value.txPointer));
@@ -32304,7 +32820,7 @@ This unreleased fuel-core build may include features and updates not yet support
32304
32820
  let o = offset;
32305
32821
  [decoded, o] = new B256Coder().decode(data, o);
32306
32822
  const txID = decoded;
32307
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
32823
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
32308
32824
  const outputIndex = decoded;
32309
32825
  [decoded, o] = new B256Coder().decode(data, o);
32310
32826
  const balanceRoot = decoded;
@@ -32343,8 +32859,8 @@ This unreleased fuel-core build may include features and updates not yet support
32343
32859
  }
32344
32860
  static encodeData(messageData) {
32345
32861
  const bytes2 = arrayify(messageData || "0x");
32346
- const dataLength2 = bytes2.length;
32347
- return new ByteArrayCoder(dataLength2).encode(bytes2);
32862
+ const dataLength = bytes2.length;
32863
+ return new ByteArrayCoder(dataLength).encode(bytes2);
32348
32864
  }
32349
32865
  encode(value) {
32350
32866
  const parts = [];
@@ -32353,7 +32869,7 @@ This unreleased fuel-core build may include features and updates not yet support
32353
32869
  parts.push(new ByteArrayCoder(32).encode(value.recipient));
32354
32870
  parts.push(new BigNumberCoder("u64").encode(value.amount));
32355
32871
  parts.push(new ByteArrayCoder(32).encode(value.nonce));
32356
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessIndex));
32872
+ parts.push(new NumberCoder("u16").encode(value.witnessIndex));
32357
32873
  parts.push(new BigNumberCoder("u64").encode(value.predicateGasUsed));
32358
32874
  parts.push(new BigNumberCoder("u64").encode(data.length));
32359
32875
  parts.push(new BigNumberCoder("u64").encode(value.predicateLength));
@@ -32367,8 +32883,8 @@ This unreleased fuel-core build may include features and updates not yet support
32367
32883
  }
32368
32884
  static decodeData(messageData) {
32369
32885
  const bytes2 = arrayify(messageData);
32370
- const dataLength2 = bytes2.length;
32371
- const [data] = new ByteArrayCoder(dataLength2).decode(bytes2, 0);
32886
+ const dataLength = bytes2.length;
32887
+ const [data] = new ByteArrayCoder(dataLength).decode(bytes2, 0);
32372
32888
  return arrayify(data);
32373
32889
  }
32374
32890
  decode(data, offset) {
@@ -32382,17 +32898,17 @@ This unreleased fuel-core build may include features and updates not yet support
32382
32898
  const amount = decoded;
32383
32899
  [decoded, o] = new B256Coder().decode(data, o);
32384
32900
  const nonce = decoded;
32385
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
32901
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
32386
32902
  const witnessIndex = Number(decoded);
32387
32903
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
32388
32904
  const predicateGasUsed = decoded;
32389
- [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
32390
- const dataLength2 = decoded;
32905
+ [decoded, o] = new NumberCoder("u32").decode(data, o);
32906
+ const dataLength = decoded;
32391
32907
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
32392
32908
  const predicateLength = decoded;
32393
32909
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
32394
32910
  const predicateDataLength = decoded;
32395
- [decoded, o] = new ByteArrayCoder(dataLength2).decode(data, o);
32911
+ [decoded, o] = new ByteArrayCoder(dataLength).decode(data, o);
32396
32912
  const messageData = decoded;
32397
32913
  [decoded, o] = new ByteArrayCoder(predicateLength.toNumber()).decode(data, o);
32398
32914
  const predicate = decoded;
@@ -32407,7 +32923,7 @@ This unreleased fuel-core build may include features and updates not yet support
32407
32923
  witnessIndex,
32408
32924
  nonce,
32409
32925
  predicateGasUsed,
32410
- dataLength: dataLength2,
32926
+ dataLength,
32411
32927
  predicateLength,
32412
32928
  predicateDataLength,
32413
32929
  data: messageData,
@@ -32424,7 +32940,7 @@ This unreleased fuel-core build may include features and updates not yet support
32424
32940
  }
32425
32941
  encode(value) {
32426
32942
  const parts = [];
32427
- parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.type));
32943
+ parts.push(new NumberCoder("u8").encode(value.type));
32428
32944
  const { type: type3 } = value;
32429
32945
  switch (type3) {
32430
32946
  case 0: {
@@ -32451,7 +32967,7 @@ This unreleased fuel-core build may include features and updates not yet support
32451
32967
  decode(data, offset) {
32452
32968
  let decoded;
32453
32969
  let o = offset;
32454
- [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
32970
+ [decoded, o] = new NumberCoder("u8").decode(data, o);
32455
32971
  const type3 = decoded;
32456
32972
  switch (type3) {
32457
32973
  case 0: {
@@ -32520,7 +33036,7 @@ This unreleased fuel-core build may include features and updates not yet support
32520
33036
  }
32521
33037
  encode(value) {
32522
33038
  const parts = [];
32523
- parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.inputIndex));
33039
+ parts.push(new NumberCoder("u8").encode(value.inputIndex));
32524
33040
  parts.push(new B256Coder().encode(value.balanceRoot));
32525
33041
  parts.push(new B256Coder().encode(value.stateRoot));
32526
33042
  return concat(parts);
@@ -32528,7 +33044,7 @@ This unreleased fuel-core build may include features and updates not yet support
32528
33044
  decode(data, offset) {
32529
33045
  let decoded;
32530
33046
  let o = offset;
32531
- [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33047
+ [decoded, o] = new NumberCoder("u8").decode(data, o);
32532
33048
  const inputIndex = decoded;
32533
33049
  [decoded, o] = new B256Coder().decode(data, o);
32534
33050
  const balanceRoot = decoded;
@@ -32640,7 +33156,7 @@ This unreleased fuel-core build may include features and updates not yet support
32640
33156
  }
32641
33157
  encode(value) {
32642
33158
  const parts = [];
32643
- parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.type));
33159
+ parts.push(new NumberCoder("u8").encode(value.type));
32644
33160
  const { type: type3 } = value;
32645
33161
  switch (type3) {
32646
33162
  case 0: {
@@ -32675,7 +33191,7 @@ This unreleased fuel-core build may include features and updates not yet support
32675
33191
  decode(data, offset) {
32676
33192
  let decoded;
32677
33193
  let o = offset;
32678
- [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33194
+ [decoded, o] = new NumberCoder("u8").decode(data, o);
32679
33195
  const type3 = decoded;
32680
33196
  switch (type3) {
32681
33197
  case 0: {
@@ -32743,7 +33259,7 @@ This unreleased fuel-core build may include features and updates not yet support
32743
33259
  parts.push(new BigNumberCoder("u64").encode(data));
32744
33260
  break;
32745
33261
  case 4:
32746
- parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(data));
33262
+ parts.push(new NumberCoder("u32").encode(data));
32747
33263
  break;
32748
33264
  default: {
32749
33265
  throw new FuelError(ErrorCode.INVALID_POLICY_TYPE, `Invalid policy type: ${type3}`);
@@ -32766,10 +33282,7 @@ This unreleased fuel-core build may include features and updates not yet support
32766
33282
  policies.push({ type: 2, data: witnessLimit });
32767
33283
  }
32768
33284
  if (policyTypes & 4) {
32769
- const [maturity, nextOffset] = new NumberCoder("u32", { padToWordSize: true }).decode(
32770
- data,
32771
- o
32772
- );
33285
+ const [maturity, nextOffset] = new NumberCoder("u32").decode(data, o);
32773
33286
  o = nextOffset;
32774
33287
  policies.push({ type: 4, data: maturity });
32775
33288
  }
@@ -32816,7 +33329,7 @@ This unreleased fuel-core build may include features and updates not yet support
32816
33329
  parts.push(new B256Coder().encode(value.recipient));
32817
33330
  parts.push(new BigNumberCoder("u64").encode(value.amount));
32818
33331
  parts.push(new B256Coder().encode(value.nonce));
32819
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.data.length));
33332
+ parts.push(new NumberCoder("u16").encode(value.data.length));
32820
33333
  parts.push(new B256Coder().encode(value.digest));
32821
33334
  parts.push(new ByteArrayCoder(value.data.length).encode(value.data));
32822
33335
  return concat(parts);
@@ -32832,7 +33345,7 @@ This unreleased fuel-core build may include features and updates not yet support
32832
33345
  const amount = decoded;
32833
33346
  [decoded, o] = new B256Coder().decode(data, o);
32834
33347
  const nonce = decoded;
32835
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33348
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
32836
33349
  const len = decoded;
32837
33350
  [decoded, o] = new B256Coder().decode(data, o);
32838
33351
  const digest = decoded;
@@ -32956,11 +33469,11 @@ This unreleased fuel-core build may include features and updates not yet support
32956
33469
  encode(upgradePurposeType) {
32957
33470
  const parts = [];
32958
33471
  const { type: type3 } = upgradePurposeType;
32959
- parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(type3));
33472
+ parts.push(new NumberCoder("u8").encode(type3));
32960
33473
  switch (type3) {
32961
33474
  case 0: {
32962
33475
  const data = upgradePurposeType.data;
32963
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(data.witnessIndex));
33476
+ parts.push(new NumberCoder("u16").encode(data.witnessIndex));
32964
33477
  parts.push(new B256Coder().encode(data.checksum));
32965
33478
  break;
32966
33479
  }
@@ -32981,11 +33494,11 @@ This unreleased fuel-core build may include features and updates not yet support
32981
33494
  decode(data, offset) {
32982
33495
  let o = offset;
32983
33496
  let decoded;
32984
- [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33497
+ [decoded, o] = new NumberCoder("u8").decode(data, o);
32985
33498
  const type3 = decoded;
32986
33499
  switch (type3) {
32987
33500
  case 0: {
32988
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33501
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
32989
33502
  const witnessIndex = decoded;
32990
33503
  [decoded, o] = new B256Coder().decode(data, o);
32991
33504
  const checksum = decoded;
@@ -33016,20 +33529,20 @@ This unreleased fuel-core build may include features and updates not yet support
33016
33529
  }
33017
33530
  encode(value) {
33018
33531
  const parts = [];
33019
- parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(value.dataLength));
33532
+ parts.push(new NumberCoder("u32").encode(value.dataLength));
33020
33533
  parts.push(new ByteArrayCoder(value.dataLength).encode(value.data));
33021
33534
  return concat(parts);
33022
33535
  }
33023
33536
  decode(data, offset) {
33024
33537
  let decoded;
33025
33538
  let o = offset;
33026
- [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
33027
- const dataLength2 = decoded;
33028
- [decoded, o] = new ByteArrayCoder(dataLength2).decode(data, o);
33539
+ [decoded, o] = new NumberCoder("u32").decode(data, o);
33540
+ const dataLength = decoded;
33541
+ [decoded, o] = new ByteArrayCoder(dataLength).decode(data, o);
33029
33542
  const witnessData = decoded;
33030
33543
  return [
33031
33544
  {
33032
- dataLength: dataLength2,
33545
+ dataLength,
33033
33546
  data: witnessData
33034
33547
  },
33035
33548
  o
@@ -33054,10 +33567,10 @@ This unreleased fuel-core build may include features and updates not yet support
33054
33567
  parts.push(new B256Coder().encode(value.receiptsRoot));
33055
33568
  parts.push(new BigNumberCoder("u64").encode(value.scriptLength));
33056
33569
  parts.push(new BigNumberCoder("u64").encode(value.scriptDataLength));
33057
- parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(value.policyTypes));
33058
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.inputsCount));
33059
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputsCount));
33060
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessesCount));
33570
+ parts.push(new NumberCoder("u32").encode(value.policyTypes));
33571
+ parts.push(new NumberCoder("u16").encode(value.inputsCount));
33572
+ parts.push(new NumberCoder("u16").encode(value.outputsCount));
33573
+ parts.push(new NumberCoder("u16").encode(value.witnessesCount));
33061
33574
  parts.push(new ByteArrayCoder(value.scriptLength.toNumber()).encode(value.script));
33062
33575
  parts.push(new ByteArrayCoder(value.scriptDataLength.toNumber()).encode(value.scriptData));
33063
33576
  parts.push(new PoliciesCoder().encode(value.policies));
@@ -33077,13 +33590,13 @@ This unreleased fuel-core build may include features and updates not yet support
33077
33590
  const scriptLength = decoded;
33078
33591
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
33079
33592
  const scriptDataLength = decoded;
33080
- [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
33593
+ [decoded, o] = new NumberCoder("u32").decode(data, o);
33081
33594
  const policyTypes = decoded;
33082
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33595
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
33083
33596
  const inputsCount = decoded;
33084
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33597
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
33085
33598
  const outputsCount = decoded;
33086
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33599
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
33087
33600
  const witnessesCount = decoded;
33088
33601
  [decoded, o] = new ByteArrayCoder(scriptLength.toNumber()).decode(data, o);
33089
33602
  const script = decoded;
@@ -33125,13 +33638,13 @@ This unreleased fuel-core build may include features and updates not yet support
33125
33638
  }
33126
33639
  encode(value) {
33127
33640
  const parts = [];
33128
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.bytecodeWitnessIndex));
33641
+ parts.push(new NumberCoder("u16").encode(value.bytecodeWitnessIndex));
33129
33642
  parts.push(new B256Coder().encode(value.salt));
33130
33643
  parts.push(new BigNumberCoder("u64").encode(value.storageSlotsCount));
33131
- parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(value.policyTypes));
33132
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.inputsCount));
33133
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputsCount));
33134
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessesCount));
33644
+ parts.push(new NumberCoder("u32").encode(value.policyTypes));
33645
+ parts.push(new NumberCoder("u16").encode(value.inputsCount));
33646
+ parts.push(new NumberCoder("u16").encode(value.outputsCount));
33647
+ parts.push(new NumberCoder("u16").encode(value.witnessesCount));
33135
33648
  parts.push(
33136
33649
  new ArrayCoder(new StorageSlotCoder(), value.storageSlotsCount.toNumber()).encode(
33137
33650
  value.storageSlots
@@ -33146,19 +33659,19 @@ This unreleased fuel-core build may include features and updates not yet support
33146
33659
  decode(data, offset) {
33147
33660
  let decoded;
33148
33661
  let o = offset;
33149
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33662
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
33150
33663
  const bytecodeWitnessIndex = decoded;
33151
33664
  [decoded, o] = new B256Coder().decode(data, o);
33152
33665
  const salt = decoded;
33153
33666
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
33154
33667
  const storageSlotsCount = decoded;
33155
- [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
33668
+ [decoded, o] = new NumberCoder("u32").decode(data, o);
33156
33669
  const policyTypes = decoded;
33157
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33670
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
33158
33671
  const inputsCount = decoded;
33159
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33672
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
33160
33673
  const outputsCount = decoded;
33161
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33674
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
33162
33675
  const witnessesCount = decoded;
33163
33676
  [decoded, o] = new ArrayCoder(new StorageSlotCoder(), storageSlotsCount.toNumber()).decode(
33164
33677
  data,
@@ -33372,7 +33885,7 @@ This unreleased fuel-core build may include features and updates not yet support
33372
33885
  }
33373
33886
  encode(value) {
33374
33887
  const parts = [];
33375
- parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.type));
33888
+ parts.push(new NumberCoder("u8").encode(value.type));
33376
33889
  const { type: type3 } = value;
33377
33890
  switch (value.type) {
33378
33891
  case 0: {
@@ -33415,7 +33928,7 @@ This unreleased fuel-core build may include features and updates not yet support
33415
33928
  decode(data, offset) {
33416
33929
  let decoded;
33417
33930
  let o = offset;
33418
- [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33931
+ [decoded, o] = new NumberCoder("u8").decode(data, o);
33419
33932
  const type3 = decoded;
33420
33933
  switch (type3) {
33421
33934
  case 0: {
@@ -38514,7 +39027,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
38514
39027
  }
38515
39028
  return { errorMessage, reason };
38516
39029
  };
38517
- var stringify2 = (obj) => JSON.stringify(obj, null, 2);
39030
+ var stringify = (obj) => JSON.stringify(obj, null, 2);
38518
39031
  var assembleRevertError = (receipts, logs) => {
38519
39032
  let errorMessage = "The transaction reverted with an unknown reason.";
38520
39033
  const revertReceipt = receipts.find(({ type: type3 }) => type3 === ReceiptType.Revert);
@@ -38524,17 +39037,17 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
38524
39037
  switch (reasonHex) {
38525
39038
  case FAILED_REQUIRE_SIGNAL: {
38526
39039
  reason = "require";
38527
- errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify2(logs[0]) : "an error."}.`;
39040
+ errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
38528
39041
  break;
38529
39042
  }
38530
39043
  case FAILED_ASSERT_EQ_SIGNAL: {
38531
- const sufix = logs.length >= 2 ? ` comparing ${stringify2(logs[1])} and ${stringify2(logs[0])}.` : ".";
39044
+ const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
38532
39045
  reason = "assert_eq";
38533
39046
  errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
38534
39047
  break;
38535
39048
  }
38536
39049
  case FAILED_ASSERT_NE_SIGNAL: {
38537
- const sufix = logs.length >= 2 ? ` comparing ${stringify2(logs[1])} and ${stringify2(logs[0])}.` : ".";
39050
+ const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
38538
39051
  reason = "assert_ne";
38539
39052
  errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
38540
39053
  break;
@@ -39142,6 +39655,15 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39142
39655
  }
39143
39656
  });
39144
39657
  }
39658
+ shiftPredicateData() {
39659
+ this.inputs.forEach((input) => {
39660
+ if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
39661
+ input.predicateData = input.padPredicateData(
39662
+ BaseTransactionRequest.getPolicyMeta(this).policies.length
39663
+ );
39664
+ }
39665
+ });
39666
+ }
39145
39667
  };
39146
39668
 
39147
39669
  // src/providers/transaction-request/hash-transaction.ts
@@ -39606,27 +40128,37 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39606
40128
  };
39607
40129
 
39608
40130
  // src/providers/transaction-summary/call.ts
39609
- var getFunctionCall = ({ abi, receipt }) => {
40131
+ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
39610
40132
  const abiInterface = new Interface(abi);
39611
40133
  const callFunctionSelector = receipt.param1.toHex(8);
39612
40134
  const functionFragment = abiInterface.getFunction(callFunctionSelector);
39613
40135
  const inputs = functionFragment.jsonFn.inputs;
39614
- const encodedArgs = receipt.param2.toHex();
40136
+ let encodedArgs;
40137
+ if (functionFragment.isInputDataPointer) {
40138
+ if (rawPayload) {
40139
+ const argsOffset = bn(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
40140
+ encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
40141
+ }
40142
+ } else {
40143
+ encodedArgs = receipt.param2.toHex();
40144
+ }
39615
40145
  let argumentsProvided;
39616
- const data = functionFragment.decodeArguments(encodedArgs);
39617
- if (data) {
39618
- argumentsProvided = inputs.reduce((prev, input, index) => {
39619
- const value = data[index];
39620
- const name = input.name;
39621
- if (name) {
39622
- return {
39623
- ...prev,
39624
- // reparse to remove bn
39625
- [name]: JSON.parse(JSON.stringify(value))
39626
- };
39627
- }
39628
- return prev;
39629
- }, {});
40146
+ if (encodedArgs) {
40147
+ const data = functionFragment.decodeArguments(encodedArgs);
40148
+ if (data) {
40149
+ argumentsProvided = inputs.reduce((prev, input, index) => {
40150
+ const value = data[index];
40151
+ const name = input.name;
40152
+ if (name) {
40153
+ return {
40154
+ ...prev,
40155
+ // reparse to remove bn
40156
+ [name]: JSON.parse(JSON.stringify(value))
40157
+ };
40158
+ }
40159
+ return prev;
40160
+ }, {});
40161
+ }
39630
40162
  }
39631
40163
  const call = {
39632
40164
  functionSignature: functionFragment.signature,
@@ -40523,13 +41055,13 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
40523
41055
  gasCosts,
40524
41056
  baseAssetId,
40525
41057
  chainId,
40526
- version: version2
41058
+ version
40527
41059
  } = consensusParameters;
40528
41060
  return {
40529
41061
  name,
40530
41062
  baseChainHeight: bn(daHeight),
40531
41063
  consensusParameters: {
40532
- version: version2,
41064
+ version,
40533
41065
  chainId: bn(chainId),
40534
41066
  baseAssetId,
40535
41067
  feeParameters: {
@@ -42123,6 +42655,7 @@ Supported fuel-core version: ${supportedVersion}.`
42123
42655
  cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
42124
42656
  );
42125
42657
  request.addResources(resources);
42658
+ request.shiftPredicateData();
42126
42659
  request.updatePredicateGasUsed(estimatedPredicates);
42127
42660
  const requestToReestimate2 = clone_default(request);
42128
42661
  if (addedSignatures) {
@@ -42154,6 +42687,7 @@ Supported fuel-core version: ${supportedVersion}.`
42154
42687
  }
42155
42688
  fundingAttempts += 1;
42156
42689
  }
42690
+ request.shiftPredicateData();
42157
42691
  request.updatePredicateGasUsed(estimatedPredicates);
42158
42692
  const requestToReestimate = clone_default(request);
42159
42693
  if (addedSignatures) {
@@ -42703,12 +43237,12 @@ Supported fuel-core version: ${supportedVersion}.`
42703
43237
  const { windows, windowSize } = opts(W);
42704
43238
  let p = c.ZERO;
42705
43239
  let f2 = c.BASE;
42706
- const mask2 = BigInt(2 ** W - 1);
43240
+ const mask = BigInt(2 ** W - 1);
42707
43241
  const maxNumber = 2 ** W;
42708
43242
  const shiftBy = BigInt(W);
42709
43243
  for (let window2 = 0; window2 < windows; window2++) {
42710
43244
  const offset = window2 * windowSize;
42711
- let wbits = Number(n & mask2);
43245
+ let wbits = Number(n & mask);
42712
43246
  n >>= shiftBy;
42713
43247
  if (wbits > windowSize) {
42714
43248
  wbits -= maxNumber;
@@ -46049,38 +46583,6 @@ Supported fuel-core version: ${supportedVersion}.`
46049
46583
  })(Language || {});
46050
46584
 
46051
46585
  // src/mnemonic/utils.ts
46052
- function toUtf8Bytes2(stri) {
46053
- const str = stri.normalize("NFKD");
46054
- const result = [];
46055
- for (let i = 0; i < str.length; i += 1) {
46056
- const c = str.charCodeAt(i);
46057
- if (c < 128) {
46058
- result.push(c);
46059
- } else if (c < 2048) {
46060
- result.push(c >> 6 | 192);
46061
- result.push(c & 63 | 128);
46062
- } else if ((c & 64512) === 55296) {
46063
- i += 1;
46064
- const c2 = str.charCodeAt(i);
46065
- if (i >= str.length || (c2 & 64512) !== 56320) {
46066
- throw new FuelError(
46067
- ErrorCode.INVALID_INPUT_PARAMETERS,
46068
- "Invalid UTF-8 in the input string."
46069
- );
46070
- }
46071
- const pair = 65536 + ((c & 1023) << 10) + (c2 & 1023);
46072
- result.push(pair >> 18 | 240);
46073
- result.push(pair >> 12 & 63 | 128);
46074
- result.push(pair >> 6 & 63 | 128);
46075
- result.push(pair & 63 | 128);
46076
- } else {
46077
- result.push(c >> 12 | 224);
46078
- result.push(c >> 6 & 63 | 128);
46079
- result.push(c & 63 | 128);
46080
- }
46081
- }
46082
- return Uint8Array.from(result);
46083
- }
46084
46586
  function getLowerMask(bits) {
46085
46587
  return (1 << bits) - 1;
46086
46588
  }
@@ -46153,7 +46655,7 @@ Supported fuel-core version: ${supportedVersion}.`
46153
46655
  }
46154
46656
 
46155
46657
  // src/mnemonic/mnemonic.ts
46156
- var MasterSecret = toUtf8Bytes2("Bitcoin seed");
46658
+ var MasterSecret = toUtf8Bytes("Bitcoin seed");
46157
46659
  var MainnetPRV = "0x0488ade4";
46158
46660
  var TestnetPRV = "0x04358394";
46159
46661
  var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
@@ -46237,8 +46739,8 @@ Supported fuel-core version: ${supportedVersion}.`
46237
46739
  */
46238
46740
  static mnemonicToSeed(phrase, passphrase = "") {
46239
46741
  assertMnemonic(getWords(phrase));
46240
- const phraseBytes = toUtf8Bytes2(getPhrase(phrase));
46241
- const salt = toUtf8Bytes2(`mnemonic${passphrase}`);
46742
+ const phraseBytes = toUtf8Bytes(getPhrase(phrase));
46743
+ const salt = toUtf8Bytes(`mnemonic${passphrase}`);
46242
46744
  return pbkdf222(phraseBytes, salt, 2048, 64, "sha512");
46243
46745
  }
46244
46746
  /**
@@ -46866,7 +47368,7 @@ Supported fuel-core version: ${supportedVersion}.`
46866
47368
  wallet_not_unlocked: "The wallet is currently locked.",
46867
47369
  passphrase_not_match: "The provided passphrase did not match the expected value."
46868
47370
  };
46869
- function assert2(condition, message) {
47371
+ function assert(condition, message) {
46870
47372
  if (!condition) {
46871
47373
  throw new FuelError(ErrorCode.WALLET_MANAGER_ERROR, message);
46872
47374
  }
@@ -46909,9 +47411,9 @@ Supported fuel-core version: ${supportedVersion}.`
46909
47411
  * the format of the return depends on the Vault type.
46910
47412
  */
46911
47413
  exportVault(vaultId) {
46912
- assert2(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
47414
+ assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
46913
47415
  const vaultState = __privateGet(this, _vaults).find((_, idx) => idx === vaultId);
46914
- assert2(vaultState, ERROR_MESSAGES.vault_not_found);
47416
+ assert(vaultState, ERROR_MESSAGES.vault_not_found);
46915
47417
  return vaultState.vault.serialize();
46916
47418
  }
46917
47419
  /**
@@ -46940,7 +47442,7 @@ Supported fuel-core version: ${supportedVersion}.`
46940
47442
  const vaultState = __privateGet(this, _vaults).find(
46941
47443
  (vs) => vs.vault.getAccounts().find((a) => a.address.equals(ownerAddress))
46942
47444
  );
46943
- assert2(vaultState, ERROR_MESSAGES.address_not_found);
47445
+ assert(vaultState, ERROR_MESSAGES.address_not_found);
46944
47446
  return vaultState.vault.getWallet(ownerAddress);
46945
47447
  }
46946
47448
  /**
@@ -46948,11 +47450,11 @@ Supported fuel-core version: ${supportedVersion}.`
46948
47450
  */
46949
47451
  exportPrivateKey(address) {
46950
47452
  const ownerAddress = Address.fromAddressOrString(address);
46951
- assert2(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
47453
+ assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
46952
47454
  const vaultState = __privateGet(this, _vaults).find(
46953
47455
  (vs) => vs.vault.getAccounts().find((a) => a.address.equals(ownerAddress))
46954
47456
  );
46955
- assert2(vaultState, ERROR_MESSAGES.address_not_found);
47457
+ assert(vaultState, ERROR_MESSAGES.address_not_found);
46956
47458
  return vaultState.vault.exportAccount(ownerAddress);
46957
47459
  }
46958
47460
  /**
@@ -46962,7 +47464,7 @@ Supported fuel-core version: ${supportedVersion}.`
46962
47464
  async addAccount(options) {
46963
47465
  await this.loadState();
46964
47466
  const vaultState = __privateGet(this, _vaults)[options?.vaultId || 0];
46965
- await assert2(vaultState, ERROR_MESSAGES.vault_not_found);
47467
+ await assert(vaultState, ERROR_MESSAGES.vault_not_found);
46966
47468
  const account = vaultState.vault.addAccount();
46967
47469
  await this.saveState();
46968
47470
  return account;
@@ -47032,7 +47534,7 @@ Supported fuel-core version: ${supportedVersion}.`
47032
47534
  * Retrieve and decrypt WalletManager state from storage
47033
47535
  */
47034
47536
  async loadState() {
47035
- await assert2(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
47537
+ await assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
47036
47538
  const data = await this.storage.getItem(this.STORAGE_KEY);
47037
47539
  if (data) {
47038
47540
  const state = await decrypt2(__privateGet(this, _passphrase), JSON.parse(data));
@@ -47043,7 +47545,7 @@ Supported fuel-core version: ${supportedVersion}.`
47043
47545
  * Store encrypted WalletManager state on storage
47044
47546
  */
47045
47547
  async saveState() {
47046
- await assert2(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
47548
+ await assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
47047
47549
  const encryptedData = await encrypt2(__privateGet(this, _passphrase), {
47048
47550
  vaults: __privateMethod(this, _serializeVaults, serializeVaults_fn).call(this, __privateGet(this, _vaults))
47049
47551
  });
@@ -47055,7 +47557,7 @@ Supported fuel-core version: ${supportedVersion}.`
47055
47557
  */
47056
47558
  getVaultClass(type3) {
47057
47559
  const VaultClass = _WalletManager.Vaults.find((v) => v.type === type3);
47058
- assert2(VaultClass, ERROR_MESSAGES.invalid_vault_type);
47560
+ assert(VaultClass, ERROR_MESSAGES.invalid_vault_type);
47059
47561
  return VaultClass;
47060
47562
  }
47061
47563
  };
@@ -47227,6 +47729,7 @@ Supported fuel-core version: ${supportedVersion}.`
47227
47729
  */
47228
47730
  populateTransactionPredicateData(transactionRequestLike) {
47229
47731
  const request = transactionRequestify(transactionRequestLike);
47732
+ const { policies } = BaseTransactionRequest.getPolicyMeta(request);
47230
47733
  const placeholderIndex = this.getIndexFromPlaceholderWitness(request);
47231
47734
  if (placeholderIndex !== -1) {
47232
47735
  request.removeWitness(placeholderIndex);
@@ -47234,7 +47737,7 @@ Supported fuel-core version: ${supportedVersion}.`
47234
47737
  request.inputs.filter(isRequestInputResource).forEach((input) => {
47235
47738
  if (isRequestInputResourceFromOwner(input, this.address)) {
47236
47739
  input.predicate = hexlify(this.bytes);
47237
- input.predicateData = hexlify(this.getPredicateData());
47740
+ input.predicateData = hexlify(this.getPredicateData(policies.length));
47238
47741
  input.witnessIndex = 0;
47239
47742
  }
47240
47743
  });
@@ -47260,12 +47763,17 @@ Supported fuel-core version: ${supportedVersion}.`
47260
47763
  const transactionRequest = transactionRequestify(transactionRequestLike);
47261
47764
  return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
47262
47765
  }
47263
- getPredicateData() {
47766
+ getPredicateData(policiesLength) {
47264
47767
  if (!this.predicateData.length) {
47265
47768
  return new Uint8Array();
47266
47769
  }
47267
47770
  const mainFn = this.interface?.functions.main;
47268
- return mainFn?.encodeArguments(this.predicateData) || new Uint8Array();
47771
+ const paddedCode = new ByteArrayCoder(this.bytes.length).encode(this.bytes);
47772
+ const VM_TX_MEMORY = calculateVmTxMemory({
47773
+ maxInputs: this.provider.getChain().consensusParameters.txParameters.maxInputs.toNumber()
47774
+ });
47775
+ const OFFSET = VM_TX_MEMORY + SCRIPT_FIXED_SIZE + INPUT_COIN_FIXED_SIZE + WORD_SIZE + paddedCode.byteLength + policiesLength * WORD_SIZE;
47776
+ return mainFn?.encodeArguments(this.predicateData, OFFSET) || new Uint8Array();
47269
47777
  }
47270
47778
  /**
47271
47779
  * Processes the predicate data and returns the altered bytecode and interface.
@@ -47314,7 +47822,8 @@ Supported fuel-core version: ${supportedVersion}.`
47314
47822
  );
47315
47823
  return resources.map((resource) => ({
47316
47824
  ...resource,
47317
- predicate: hexlify(this.bytes)
47825
+ predicate: hexlify(this.bytes),
47826
+ padPredicateData: (policiesLength) => hexlify(this.getPredicateData(policiesLength))
47318
47827
  }));
47319
47828
  }
47320
47829
  /**