@fuel-ts/account 0.74.0 → 0.75.0

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.

Files changed (100) hide show
  1. package/dist/account.d.ts +4 -5
  2. package/dist/account.d.ts.map +1 -1
  3. package/dist/connectors/fuel-connector.d.ts +2 -1
  4. package/dist/connectors/fuel-connector.d.ts.map +1 -1
  5. package/dist/connectors/fuel.d.ts +1 -2
  6. package/dist/connectors/fuel.d.ts.map +1 -1
  7. package/dist/connectors/types/data-type.d.ts +0 -8
  8. package/dist/connectors/types/data-type.d.ts.map +1 -1
  9. package/dist/connectors/types/events.d.ts +2 -36
  10. package/dist/connectors/types/events.d.ts.map +1 -1
  11. package/dist/connectors/types/index.d.ts +0 -2
  12. package/dist/connectors/types/index.d.ts.map +1 -1
  13. package/dist/hdwallet/hdwallet.d.ts +1 -1
  14. package/dist/hdwallet/hdwallet.d.ts.map +1 -1
  15. package/dist/index.global.js +1358 -1074
  16. package/dist/index.global.js.map +1 -1
  17. package/dist/index.js +569 -426
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +486 -362
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/mnemonic/mnemonic.d.ts +1 -1
  22. package/dist/mnemonic/mnemonic.d.ts.map +1 -1
  23. package/dist/mnemonic/utils.d.ts +1 -1
  24. package/dist/mnemonic/utils.d.ts.map +1 -1
  25. package/dist/predicate/utils/getPredicateRoot.d.ts +1 -1
  26. package/dist/predicate/utils/getPredicateRoot.d.ts.map +1 -1
  27. package/dist/providers/assets/index.d.ts +4 -0
  28. package/dist/providers/assets/index.d.ts.map +1 -0
  29. package/dist/providers/assets/types.d.ts +36 -0
  30. package/dist/providers/assets/types.d.ts.map +1 -0
  31. package/dist/providers/assets/utils/index.d.ts +4 -0
  32. package/dist/providers/assets/utils/index.d.ts.map +1 -0
  33. package/dist/providers/assets/utils/network.d.ts +33 -0
  34. package/dist/providers/assets/utils/network.d.ts.map +1 -0
  35. package/dist/providers/assets/utils/resolveIconPaths.d.ts +14 -0
  36. package/dist/providers/assets/utils/resolveIconPaths.d.ts.map +1 -0
  37. package/dist/providers/assets/utils/url.d.ts +2 -0
  38. package/dist/providers/assets/utils/url.d.ts.map +1 -0
  39. package/dist/providers/chains.d.ts +11 -0
  40. package/dist/providers/chains.d.ts.map +1 -0
  41. package/dist/providers/coin-quantity.d.ts +1 -1
  42. package/dist/providers/coin-quantity.d.ts.map +1 -1
  43. package/dist/providers/fuel-graphql-subscriber.d.ts +13 -3
  44. package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
  45. package/dist/providers/index.d.ts +2 -0
  46. package/dist/providers/index.d.ts.map +1 -1
  47. package/dist/providers/memory-cache.d.ts +1 -1
  48. package/dist/providers/memory-cache.d.ts.map +1 -1
  49. package/dist/providers/message.d.ts +1 -2
  50. package/dist/providers/message.d.ts.map +1 -1
  51. package/dist/providers/provider.d.ts +17 -7
  52. package/dist/providers/provider.d.ts.map +1 -1
  53. package/dist/providers/resource.d.ts +1 -1
  54. package/dist/providers/resource.d.ts.map +1 -1
  55. package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
  56. package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
  57. package/dist/providers/transaction-request/hash-transaction.d.ts.map +1 -1
  58. package/dist/providers/transaction-request/input.d.ts +1 -1
  59. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  60. package/dist/providers/transaction-request/output.d.ts +1 -1
  61. package/dist/providers/transaction-request/output.d.ts.map +1 -1
  62. package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -2
  63. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  64. package/dist/providers/transaction-request/storage-slot.d.ts +1 -1
  65. package/dist/providers/transaction-request/storage-slot.d.ts.map +1 -1
  66. package/dist/providers/transaction-request/transaction-request.d.ts +2 -10
  67. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  68. package/dist/providers/transaction-request/witness.d.ts +1 -1
  69. package/dist/providers/transaction-request/witness.d.ts.map +1 -1
  70. package/dist/providers/transaction-summary/operations.d.ts +0 -2
  71. package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
  72. package/dist/providers/transaction-summary/output.d.ts +2 -2
  73. package/dist/providers/transaction-summary/output.d.ts.map +1 -1
  74. package/dist/providers/transaction-summary/types.d.ts +0 -1
  75. package/dist/providers/transaction-summary/types.d.ts.map +1 -1
  76. package/dist/providers/utils/gas.d.ts.map +1 -1
  77. package/dist/signer/signer.d.ts +1 -1
  78. package/dist/signer/signer.d.ts.map +1 -1
  79. package/dist/test-utils/launchNode.d.ts.map +1 -1
  80. package/dist/test-utils.global.js +4010 -3792
  81. package/dist/test-utils.global.js.map +1 -1
  82. package/dist/test-utils.js +462 -402
  83. package/dist/test-utils.js.map +1 -1
  84. package/dist/test-utils.mjs +384 -336
  85. package/dist/test-utils.mjs.map +1 -1
  86. package/dist/utils/formatTransferToContractScriptData.d.ts +1 -2
  87. package/dist/utils/formatTransferToContractScriptData.d.ts.map +1 -1
  88. package/dist/wallet/base-wallet-unlocked.d.ts +4 -4
  89. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  90. package/dist/wallet/wallet.d.ts +1 -2
  91. package/dist/wallet/wallet.d.ts.map +1 -1
  92. package/dist/wallet/wallets.d.ts +1 -1
  93. package/dist/wallet/wallets.d.ts.map +1 -1
  94. package/package.json +16 -16
  95. package/dist/connectors/types/asset.d.ts +0 -2
  96. package/dist/connectors/types/asset.d.ts.map +0 -1
  97. package/dist/connectors/types/constants.d.ts +0 -7
  98. package/dist/connectors/types/constants.d.ts.map +0 -1
  99. package/dist/connectors/types/message.d.ts +0 -15
  100. package/dist/connectors/types/message.d.ts.map +0 -1
@@ -30104,7 +30104,7 @@ spurious results.`);
30104
30104
  return {
30105
30105
  FORC: "0.50.0",
30106
30106
  FUEL_CORE: "0.22.1",
30107
- FUELS: "0.74.0"
30107
+ FUELS: "0.75.0"
30108
30108
  };
30109
30109
  }
30110
30110
  function parseVersion(version2) {
@@ -30170,6 +30170,7 @@ spurious results.`);
30170
30170
  ErrorCode2["CODER_NOT_FOUND"] = "coder-not-found";
30171
30171
  ErrorCode2["INVALID_DATA"] = "invalid-data";
30172
30172
  ErrorCode2["FUNCTION_NOT_FOUND"] = "function-not-found";
30173
+ ErrorCode2["UNSUPPORTED_ENCODING_VERSION"] = "unsupported-encoding-version";
30173
30174
  ErrorCode2["INVALID_BECH32_ADDRESS"] = "invalid-bech32-address";
30174
30175
  ErrorCode2["INVALID_EVM_ADDRESS"] = "invalid-evm-address";
30175
30176
  ErrorCode2["INVALID_B256_ADDRESS"] = "invalid-b256-address";
@@ -30177,6 +30178,7 @@ spurious results.`);
30177
30178
  ErrorCode2["CHAIN_INFO_CACHE_EMPTY"] = "chain-info-cache-empty";
30178
30179
  ErrorCode2["NODE_INFO_CACHE_EMPTY"] = "node-info-cache-empty";
30179
30180
  ErrorCode2["MISSING_PROVIDER"] = "missing-provider";
30181
+ ErrorCode2["INVALID_PROVIDER"] = "invalid-provider";
30180
30182
  ErrorCode2["INVALID_PUBLIC_KEY"] = "invalid-public-key";
30181
30183
  ErrorCode2["INSUFFICIENT_BALANCE"] = "insufficient-balance";
30182
30184
  ErrorCode2["WALLET_MANAGER_ERROR"] = "wallet-manager-error";
@@ -30259,6 +30261,66 @@ spurious results.`);
30259
30261
  var FuelError = _FuelError;
30260
30262
  __publicField2(FuelError, "CODES", ErrorCode);
30261
30263
 
30264
+ // ../utils/dist/index.mjs
30265
+ var chunkAndPadBytes = (bytes4, chunkSize) => {
30266
+ const chunks = [];
30267
+ for (let offset = 0; offset < bytes4.length; offset += chunkSize) {
30268
+ const chunk = new Uint8Array(chunkSize);
30269
+ chunk.set(bytes4.slice(offset, offset + chunkSize));
30270
+ chunks.push(chunk);
30271
+ }
30272
+ const lastChunk = chunks[chunks.length - 1];
30273
+ const remainingBytes = bytes4.length % chunkSize;
30274
+ const paddedChunkLength = remainingBytes + (8 - remainingBytes % 8) % 8;
30275
+ const newChunk = lastChunk.slice(0, paddedChunkLength);
30276
+ chunks[chunks.length - 1] = newChunk;
30277
+ return chunks;
30278
+ };
30279
+ var arrayify = (value) => {
30280
+ if (value instanceof Uint8Array) {
30281
+ return new Uint8Array(value);
30282
+ }
30283
+ if (typeof value === "string" && value.match(/^0x([0-9a-f][0-9a-f])*$/i)) {
30284
+ const result = new Uint8Array((value.length - 2) / 2);
30285
+ let offset = 2;
30286
+ for (let i = 0; i < result.length; i++) {
30287
+ result[i] = parseInt(value.substring(offset, offset + 2), 16);
30288
+ offset += 2;
30289
+ }
30290
+ return result;
30291
+ }
30292
+ throw new FuelError(ErrorCode.PARSE_FAILED, "invalid BytesLike value");
30293
+ };
30294
+ var concatBytes2 = (arrays) => {
30295
+ const byteArrays = arrays.map((array) => {
30296
+ if (array instanceof Uint8Array) {
30297
+ return array;
30298
+ }
30299
+ return Uint8Array.from(array);
30300
+ });
30301
+ const totalSize = byteArrays.reduce((accum, item) => accum + item.length, 0);
30302
+ const concatenated = new Uint8Array(totalSize);
30303
+ byteArrays.reduce((offset, object) => {
30304
+ concatenated.set(object, offset);
30305
+ return offset + object.length;
30306
+ }, 0);
30307
+ return concatenated;
30308
+ };
30309
+ var concat = (arrays) => {
30310
+ const bytes4 = arrays.map((v) => arrayify(v));
30311
+ return concatBytes2(bytes4);
30312
+ };
30313
+ var HexCharacters = "0123456789abcdef";
30314
+ function hexlify(data) {
30315
+ const bytes4 = arrayify(data);
30316
+ let result = "0x";
30317
+ for (let i = 0; i < bytes4.length; i++) {
30318
+ const v = bytes4[i];
30319
+ result += HexCharacters[(v & 240) >> 4] + HexCharacters[v & 15];
30320
+ }
30321
+ return result;
30322
+ }
30323
+
30262
30324
  // ../crypto/dist/index.mjs
30263
30325
  var import_crypto9 = __toESM(__require("crypto"), 1);
30264
30326
 
@@ -30427,9 +30489,6 @@ spurious results.`);
30427
30489
  function getBytes(value, name) {
30428
30490
  return _getBytes(value, name, false);
30429
30491
  }
30430
- function getBytesCopy(value, name) {
30431
- return _getBytes(value, name, true);
30432
- }
30433
30492
  function isHexString(value, length) {
30434
30493
  if (typeof value !== "string" || !value.match(/^0x[0-9A-Fa-f]*$/)) {
30435
30494
  return false;
@@ -30442,19 +30501,16 @@ spurious results.`);
30442
30501
  }
30443
30502
  return true;
30444
30503
  }
30445
- var HexCharacters = "0123456789abcdef";
30446
- function hexlify(data) {
30504
+ var HexCharacters2 = "0123456789abcdef";
30505
+ function hexlify2(data) {
30447
30506
  const bytes4 = getBytes(data);
30448
30507
  let result = "0x";
30449
30508
  for (let i = 0; i < bytes4.length; i++) {
30450
30509
  const v = bytes4[i];
30451
- result += HexCharacters[(v & 240) >> 4] + HexCharacters[v & 15];
30510
+ result += HexCharacters2[(v & 240) >> 4] + HexCharacters2[v & 15];
30452
30511
  }
30453
30512
  return result;
30454
30513
  }
30455
- function concat(datas) {
30456
- return "0x" + datas.map((d) => hexlify(d).substring(2)).join("");
30457
- }
30458
30514
  function dataSlice(data, start, end) {
30459
30515
  const bytes4 = getBytes(data);
30460
30516
  if (end != null && end > bytes4.length) {
@@ -30464,7 +30520,7 @@ spurious results.`);
30464
30520
  offset: end
30465
30521
  });
30466
30522
  }
30467
- return hexlify(bytes4.slice(start == null ? 0 : start, end == null ? bytes4.length : end));
30523
+ return hexlify2(bytes4.slice(start == null ? 0 : start, end == null ? bytes4.length : end));
30468
30524
  }
30469
30525
 
30470
30526
  // ../../node_modules/.pnpm/ethers@6.7.1/node_modules/ethers/lib.esm/utils/maths.js
@@ -30747,7 +30803,7 @@ spurious results.`);
30747
30803
  function computeHmac(algorithm, _key, _data) {
30748
30804
  const key = getBytes(_key, "key");
30749
30805
  const data = getBytes(_data, "data");
30750
- return hexlify(__computeHmac(algorithm, key, data));
30806
+ return hexlify2(__computeHmac(algorithm, key, data));
30751
30807
  }
30752
30808
  computeHmac._ = _computeHmac;
30753
30809
  computeHmac.lock = function() {
@@ -31102,7 +31158,7 @@ spurious results.`);
31102
31158
  var __keccak256 = _keccak256;
31103
31159
  function keccak2562(_data) {
31104
31160
  const data = getBytes(_data, "data");
31105
- return hexlify(__keccak256(data));
31161
+ return hexlify2(__keccak256(data));
31106
31162
  }
31107
31163
  keccak2562._ = _keccak256;
31108
31164
  keccak2562.lock = function() {
@@ -31301,7 +31357,7 @@ spurious results.`);
31301
31357
  var __ripemd160 = _ripemd160;
31302
31358
  function ripemd1602(_data) {
31303
31359
  const data = getBytes(_data, "data");
31304
- return hexlify(__ripemd160(data));
31360
+ return hexlify2(__ripemd160(data));
31305
31361
  }
31306
31362
  ripemd1602._ = _ripemd160;
31307
31363
  ripemd1602.lock = function() {
@@ -31324,7 +31380,7 @@ spurious results.`);
31324
31380
  function pbkdf22(_password, _salt, iterations, keylen, algo) {
31325
31381
  const password = getBytes(_password, "password");
31326
31382
  const salt = getBytes(_salt, "salt");
31327
- return hexlify(__pbkdf2(password, salt, iterations, keylen, algo));
31383
+ return hexlify2(__pbkdf2(password, salt, iterations, keylen, algo));
31328
31384
  }
31329
31385
  pbkdf22._ = _pbkdf2;
31330
31386
  pbkdf22.lock = function() {
@@ -31351,7 +31407,7 @@ spurious results.`);
31351
31407
  var locked512 = false;
31352
31408
  function sha2562(_data) {
31353
31409
  const data = getBytes(_data, "data");
31354
- return hexlify(__sha256(data));
31410
+ return hexlify2(__sha256(data));
31355
31411
  }
31356
31412
  sha2562._ = _sha256;
31357
31413
  sha2562.lock = function() {
@@ -31366,7 +31422,7 @@ spurious results.`);
31366
31422
  Object.freeze(sha2562);
31367
31423
  function sha512(_data) {
31368
31424
  const data = getBytes(_data, "data");
31369
- return hexlify(__sha512(data));
31425
+ return hexlify2(__sha512(data));
31370
31426
  }
31371
31427
  sha512._ = _sha512;
31372
31428
  sha512.lock = function() {
@@ -31982,7 +32038,7 @@ spurious results.`);
31982
32038
  var keyFromPassword = (password, saltBuffer) => {
31983
32039
  const passBuffer = bufferFromString(String(password).normalize("NFKC"), "utf-8");
31984
32040
  const key = pbkdf22(passBuffer, saltBuffer, 1e5, 32, "sha256");
31985
- return getBytesCopy(key);
32041
+ return arrayify(key);
31986
32042
  };
31987
32043
  var encrypt = async (password, data) => {
31988
32044
  const iv = randomBytes3(16);
@@ -32068,7 +32124,7 @@ spurious results.`);
32068
32124
  function toBech32(address) {
32069
32125
  return import_bech32.bech32m.encode(
32070
32126
  FUEL_BECH32_HRP_PREFIX,
32071
- import_bech32.bech32m.toWords(getBytesCopy(hexlify(address)))
32127
+ import_bech32.bech32m.toWords(arrayify(hexlify(address)))
32072
32128
  );
32073
32129
  }
32074
32130
  function isBech32(address) {
@@ -32247,7 +32303,7 @@ spurious results.`);
32247
32303
  if (!isPublicKey(publicKey)) {
32248
32304
  throw new FuelError(FuelError.CODES.INVALID_PUBLIC_KEY, `Invalid Public Key: ${publicKey}.`);
32249
32305
  }
32250
- const b256Address = sha2562(hexlify(getBytesCopy(publicKey)));
32306
+ const b256Address = sha2562(hexlify(arrayify(publicKey)));
32251
32307
  return new Address(toBech32(b256Address));
32252
32308
  }
32253
32309
  /**
@@ -32595,56 +32651,6 @@ spurious results.`);
32595
32651
  return coinQuantities;
32596
32652
  };
32597
32653
 
32598
- // ../utils/dist/index.mjs
32599
- var chunkAndPadBytes = (bytes4, chunkSize) => {
32600
- const chunks = [];
32601
- for (let offset = 0; offset < bytes4.length; offset += chunkSize) {
32602
- const chunk = new Uint8Array(chunkSize);
32603
- chunk.set(bytes4.slice(offset, offset + chunkSize));
32604
- chunks.push(chunk);
32605
- }
32606
- const lastChunk = chunks[chunks.length - 1];
32607
- const remainingBytes = bytes4.length % chunkSize;
32608
- const paddedChunkLength = remainingBytes + (8 - remainingBytes % 8) % 8;
32609
- const newChunk = lastChunk.slice(0, paddedChunkLength);
32610
- chunks[chunks.length - 1] = newChunk;
32611
- return chunks;
32612
- };
32613
- var arrayify = (value) => {
32614
- if (value instanceof Uint8Array) {
32615
- return new Uint8Array(value);
32616
- }
32617
- if (typeof value === "string" && value.match(/^0x([0-9a-f][0-9a-f])*$/i)) {
32618
- const result = new Uint8Array((value.length - 2) / 2);
32619
- let offset = 2;
32620
- for (let i = 0; i < result.length; i++) {
32621
- result[i] = parseInt(value.substring(offset, offset + 2), 16);
32622
- offset += 2;
32623
- }
32624
- return result;
32625
- }
32626
- throw new FuelError(ErrorCode.PARSE_FAILED, "invalid BytesLike value");
32627
- };
32628
- var concatBytes2 = (arrays) => {
32629
- const byteArrays = arrays.map((array) => {
32630
- if (array instanceof Uint8Array) {
32631
- return array;
32632
- }
32633
- return Uint8Array.from(array);
32634
- });
32635
- const totalSize = byteArrays.reduce((accum, item) => accum + item.length, 0);
32636
- const concatenated = new Uint8Array(totalSize);
32637
- byteArrays.reduce((offset, object) => {
32638
- concatenated.set(object, offset);
32639
- return offset + object.length;
32640
- }, 0);
32641
- return concatenated;
32642
- };
32643
- var concat2 = (arrays) => {
32644
- const bytes4 = arrays.map((v) => arrayify(v));
32645
- return concatBytes2(bytes4);
32646
- };
32647
-
32648
32654
  // ../abi-coder/dist/index.mjs
32649
32655
  var __defProp3 = Object.defineProperty;
32650
32656
  var __defNormalProp3 = (obj, key, value) => key in obj ? __defProp3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -32675,16 +32681,28 @@ spurious results.`);
32675
32681
  this.encodedLength = encodedLength;
32676
32682
  }
32677
32683
  };
32684
+ var U8_CODER_TYPE = "u8";
32685
+ var U16_CODER_TYPE = "u16";
32686
+ var U32_CODER_TYPE = "u32";
32687
+ var U64_CODER_TYPE = "u64";
32688
+ var RAW_PTR_CODER_TYPE = "raw untyped ptr";
32689
+ var RAW_SLICE_CODER_TYPE = "raw untyped slice";
32690
+ var BOOL_CODER_TYPE = "bool";
32691
+ var B256_CODER_TYPE = "b256";
32692
+ var B512_CODER_TYPE = "struct B512";
32678
32693
  var OPTION_CODER_TYPE = "enum Option";
32679
32694
  var VEC_CODER_TYPE = "struct Vec";
32680
32695
  var BYTES_CODER_TYPE = "struct Bytes";
32681
32696
  var STD_STRING_CODER_TYPE = "struct String";
32697
+ var STR_SLICE_CODER_TYPE = "str";
32682
32698
  var stringRegEx = /str\[(?<length>[0-9]+)\]/;
32683
32699
  var arrayRegEx = /\[(?<item>[\w\s\\[\]]+);\s*(?<length>[0-9]+)\]/;
32684
32700
  var structRegEx = /^struct (?<name>\w+)$/;
32685
32701
  var enumRegEx = /^enum (?<name>\w+)$/;
32686
32702
  var tupleRegEx = /^\((?<items>.*)\)$/;
32687
32703
  var genericRegEx = /^generic (?<name>\w+)$/;
32704
+ var ENCODING_V0 = "0";
32705
+ var ENCODING_V1 = "1";
32688
32706
  var WORD_SIZE = 8;
32689
32707
  var BYTES_32 = 32;
32690
32708
  var ASSET_ID_LEN = BYTES_32;
@@ -32767,7 +32785,7 @@ spurious results.`);
32767
32785
  topLevelData[parseInt(pointerIndex, 10) + totalIndex] = vData;
32768
32786
  });
32769
32787
  }
32770
- const byteArray = getBytesCopy(item);
32788
+ const byteArray = arrayify(item);
32771
32789
  totalIndex += byteArray.byteLength / WORD_SIZE;
32772
32790
  return byteArray;
32773
32791
  });
@@ -32784,7 +32802,7 @@ spurious results.`);
32784
32802
  }
32785
32803
  function unpackDynamicData(results, baseOffset, dataOffset) {
32786
32804
  if (!results.dynamicData) {
32787
- return concat2([results]);
32805
+ return concat([results]);
32788
32806
  }
32789
32807
  let cumulativeDynamicByteLength = 0;
32790
32808
  let updatedResults = results;
@@ -32802,7 +32820,7 @@ spurious results.`);
32802
32820
  dataOffset + vData.byteLength + cumulativeDynamicByteLength
32803
32821
  )
32804
32822
  ) : vData;
32805
- updatedResults = concat2([updatedResults, dataToAppend]);
32823
+ updatedResults = concat([updatedResults, dataToAppend]);
32806
32824
  cumulativeDynamicByteLength += dataToAppend.byteLength;
32807
32825
  });
32808
32826
  return updatedResults;
@@ -32888,7 +32906,7 @@ spurious results.`);
32888
32906
  encode(value) {
32889
32907
  let encodedValue;
32890
32908
  try {
32891
- encodedValue = getBytesCopy(value);
32909
+ encodedValue = arrayify(value);
32892
32910
  } catch (error) {
32893
32911
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
32894
32912
  }
@@ -32919,7 +32937,7 @@ spurious results.`);
32919
32937
  encode(value) {
32920
32938
  let encodedValue;
32921
32939
  try {
32922
- encodedValue = getBytesCopy(value);
32940
+ encodedValue = arrayify(value);
32923
32941
  } catch (error) {
32924
32942
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
32925
32943
  }
@@ -32986,6 +33004,51 @@ spurious results.`);
32986
33004
  return [true, offset + this.paddingLength];
32987
33005
  }
32988
33006
  };
33007
+ var _getPaddedData;
33008
+ var getPaddedData_fn;
33009
+ var ByteCoder = class extends Coder {
33010
+ constructor() {
33011
+ super("struct", "struct Bytes", BASE_VECTOR_OFFSET);
33012
+ __privateAdd2(this, _getPaddedData);
33013
+ }
33014
+ encode(value) {
33015
+ if (!Array.isArray(value)) {
33016
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
33017
+ }
33018
+ const parts = [];
33019
+ const pointer = new U64Coder().encode(BASE_VECTOR_OFFSET);
33020
+ const data = __privateMethod2(this, _getPaddedData, getPaddedData_fn).call(this, value);
33021
+ pointer.dynamicData = {
33022
+ 0: concatWithDynamicData([data])
33023
+ };
33024
+ parts.push(pointer);
33025
+ parts.push(new U64Coder().encode(data.byteLength));
33026
+ parts.push(new U64Coder().encode(value.length));
33027
+ return concatWithDynamicData(parts);
33028
+ }
33029
+ decode(data, offset) {
33030
+ if (data.length < BASE_VECTOR_OFFSET) {
33031
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid byte data size.`);
33032
+ }
33033
+ const len = data.slice(16, 24);
33034
+ const encodedLength = bn(new U64Coder().decode(len, 0)[0]).toNumber();
33035
+ const byteData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + encodedLength);
33036
+ if (byteData.length !== encodedLength) {
33037
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
33038
+ }
33039
+ return [byteData, offset + BASE_VECTOR_OFFSET];
33040
+ }
33041
+ };
33042
+ _getPaddedData = /* @__PURE__ */ new WeakSet();
33043
+ getPaddedData_fn = function(value) {
33044
+ const data = [Uint8Array.from(value)];
33045
+ const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
33046
+ if (paddingLength) {
33047
+ data.push(new Uint8Array(paddingLength));
33048
+ }
33049
+ return concat(data);
33050
+ };
33051
+ __publicField3(ByteCoder, "memorySize", 1);
32989
33052
  var isFullyNativeEnum = (enumCoders) => Object.values(enumCoders).every(
32990
33053
  // @ts-expect-error complicated types
32991
33054
  ({ type: type3, coders }) => type3 === "()" && JSON.stringify(coders) === JSON.stringify([])
@@ -33012,7 +33075,7 @@ spurious results.`);
33012
33075
  const encodedValue = valueCoder.encode([]);
33013
33076
  const caseIndex = Object.keys(this.coders).indexOf(value);
33014
33077
  const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
33015
- return concat2([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
33078
+ return concat([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
33016
33079
  }
33017
33080
  encode(value) {
33018
33081
  if (typeof value === "string" && this.coders[value]) {
@@ -33059,6 +33122,31 @@ spurious results.`);
33059
33122
  return [{ [caseKey]: decoded }, newOffset];
33060
33123
  }
33061
33124
  };
33125
+ var OptionCoder = class extends EnumCoder {
33126
+ encode(value) {
33127
+ const result = super.encode(this.toSwayOption(value));
33128
+ return result;
33129
+ }
33130
+ toSwayOption(input) {
33131
+ if (input !== void 0) {
33132
+ return { Some: input };
33133
+ }
33134
+ return { None: [] };
33135
+ }
33136
+ decode(data, offset) {
33137
+ if (data.length < this.encodedLength - 1) {
33138
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid option data size.`);
33139
+ }
33140
+ const [decoded, newOffset] = super.decode(data, offset);
33141
+ return [this.toOption(decoded), newOffset];
33142
+ }
33143
+ toOption(output4) {
33144
+ if (output4 && "Some" in output4) {
33145
+ return output4.Some;
33146
+ }
33147
+ return void 0;
33148
+ }
33149
+ };
33062
33150
  var NumberCoder = class extends Coder {
33063
33151
  // This is to align the bits to the total bytes
33064
33152
  // See https://github.com/FuelLabs/fuel-specs/blob/master/specs/protocol/abi.md#unsigned-integers
@@ -33129,6 +33217,77 @@ spurious results.`);
33129
33217
  return [toNumber2(bytes4), offset + 8];
33130
33218
  }
33131
33219
  };
33220
+ var RawSliceCoder = class extends Coder {
33221
+ constructor() {
33222
+ super("raw untyped slice", "raw untyped slice", BASE_RAW_SLICE_OFFSET);
33223
+ }
33224
+ encode(value) {
33225
+ if (!Array.isArray(value)) {
33226
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
33227
+ }
33228
+ const parts = [];
33229
+ const coder = new NumberCoder("u8", { isSmallBytes: true });
33230
+ const pointer = new U64Coder().encode(BASE_RAW_SLICE_OFFSET);
33231
+ pointer.dynamicData = {
33232
+ 0: concatWithDynamicData(value.map((v) => coder.encode(v)))
33233
+ };
33234
+ parts.push(pointer);
33235
+ parts.push(new U64Coder().encode(value.length));
33236
+ return concatWithDynamicData(parts);
33237
+ }
33238
+ decode(data, offset) {
33239
+ const dataBytes = data.slice(offset);
33240
+ const internalCoder = new ArrayCoder(
33241
+ new NumberCoder("u8", { isSmallBytes: true }),
33242
+ dataBytes.length
33243
+ );
33244
+ const [decodedValue] = internalCoder.decode(dataBytes, 0);
33245
+ return [decodedValue, offset + dataBytes.length];
33246
+ }
33247
+ };
33248
+ var _getPaddedData2;
33249
+ var getPaddedData_fn2;
33250
+ var StdStringCoder = class extends Coder {
33251
+ constructor() {
33252
+ super("struct", "struct String", 1);
33253
+ __privateAdd2(this, _getPaddedData2);
33254
+ }
33255
+ encode(value) {
33256
+ const parts = [];
33257
+ const pointer = new U64Coder().encode(BASE_VECTOR_OFFSET);
33258
+ const data = __privateMethod2(this, _getPaddedData2, getPaddedData_fn2).call(this, value);
33259
+ pointer.dynamicData = {
33260
+ 0: concatWithDynamicData([data])
33261
+ };
33262
+ parts.push(pointer);
33263
+ parts.push(new U64Coder().encode(data.byteLength));
33264
+ parts.push(new U64Coder().encode(value.length));
33265
+ return concatWithDynamicData(parts);
33266
+ }
33267
+ decode(data, offset) {
33268
+ if (data.length < this.encodedLength) {
33269
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string data size.`);
33270
+ }
33271
+ const len = data.slice(16, 24);
33272
+ const encodedLength = bn(new U64Coder().decode(len, 0)[0]).toNumber();
33273
+ const byteData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + encodedLength);
33274
+ if (byteData.length !== encodedLength) {
33275
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string byte data size.`);
33276
+ }
33277
+ const value = toUtf8String(byteData);
33278
+ return [value, offset + BASE_VECTOR_OFFSET];
33279
+ }
33280
+ };
33281
+ _getPaddedData2 = /* @__PURE__ */ new WeakSet();
33282
+ getPaddedData_fn2 = function(value) {
33283
+ const data = [toUtf8Bytes(value)];
33284
+ const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
33285
+ if (paddingLength) {
33286
+ data.push(new Uint8Array(paddingLength));
33287
+ }
33288
+ return concat(data);
33289
+ };
33290
+ __publicField3(StdStringCoder, "memorySize", 1);
33132
33291
  var StringCoder = class extends Coder {
33133
33292
  length;
33134
33293
  #paddingLength;
@@ -33145,7 +33304,7 @@ spurious results.`);
33145
33304
  }
33146
33305
  const encoded = toUtf8Bytes(value);
33147
33306
  const padding = new Uint8Array(this.#paddingLength);
33148
- return concat2([encoded, padding]);
33307
+ return concat([encoded, padding]);
33149
33308
  }
33150
33309
  decode(data, offset) {
33151
33310
  if (data.length < this.encodedLength) {
@@ -33160,31 +33319,6 @@ spurious results.`);
33160
33319
  return [value, offset + this.length + padding];
33161
33320
  }
33162
33321
  };
33163
- var OptionCoder = class extends EnumCoder {
33164
- encode(value) {
33165
- const result = super.encode(this.toSwayOption(value));
33166
- return result;
33167
- }
33168
- toSwayOption(input) {
33169
- if (input !== void 0) {
33170
- return { Some: input };
33171
- }
33172
- return { None: [] };
33173
- }
33174
- decode(data, offset) {
33175
- if (data.length < this.encodedLength - 1) {
33176
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid option data size.`);
33177
- }
33178
- const [decoded, newOffset] = super.decode(data, offset);
33179
- return [this.toOption(decoded), newOffset];
33180
- }
33181
- toOption(output4) {
33182
- if (output4 && "Some" in output4) {
33183
- return output4.Some;
33184
- }
33185
- return void 0;
33186
- }
33187
- };
33188
33322
  var StructCoder = class extends Coder {
33189
33323
  name;
33190
33324
  coders;
@@ -33309,122 +33443,246 @@ spurious results.`);
33309
33443
  ];
33310
33444
  }
33311
33445
  };
33312
- var _getPaddedData;
33313
- var getPaddedData_fn;
33314
- var ByteCoder = class extends Coder {
33315
- constructor() {
33316
- super("struct", "struct Bytes", BASE_VECTOR_OFFSET);
33317
- __privateAdd2(this, _getPaddedData);
33318
- }
33319
- encode(value) {
33320
- if (!Array.isArray(value)) {
33321
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
33322
- }
33323
- const parts = [];
33324
- const pointer = new U64Coder().encode(BASE_VECTOR_OFFSET);
33325
- const data = __privateMethod2(this, _getPaddedData, getPaddedData_fn).call(this, value);
33326
- pointer.dynamicData = {
33327
- 0: concatWithDynamicData([data])
33328
- };
33329
- parts.push(pointer);
33330
- parts.push(new U64Coder().encode(data.byteLength));
33331
- parts.push(new U64Coder().encode(value.length));
33332
- return concatWithDynamicData(parts);
33446
+ var ResolvedAbiType = class {
33447
+ abi;
33448
+ name;
33449
+ type;
33450
+ originalTypeArguments;
33451
+ components;
33452
+ constructor(abi, argument) {
33453
+ this.abi = abi;
33454
+ const type3 = findOrThrow(
33455
+ abi.types,
33456
+ (t) => t.typeId === argument.type,
33457
+ () => {
33458
+ throw new FuelError(
33459
+ ErrorCode.TYPE_NOT_FOUND,
33460
+ `Type does not exist in the provided abi: ${JSON.stringify({
33461
+ argument,
33462
+ abi: this.abi
33463
+ })}`
33464
+ );
33465
+ }
33466
+ );
33467
+ this.name = argument.name;
33468
+ this.type = type3.type;
33469
+ this.originalTypeArguments = argument.typeArguments;
33470
+ this.components = ResolvedAbiType.getResolvedGenericComponents(
33471
+ abi,
33472
+ argument,
33473
+ type3.components,
33474
+ type3.typeParameters ?? ResolvedAbiType.getImplicitGenericTypeParameters(abi, type3.components)
33475
+ );
33333
33476
  }
33334
- decode(data, offset) {
33335
- if (data.length < BASE_VECTOR_OFFSET) {
33336
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid byte data size.`);
33477
+ static getResolvedGenericComponents(abi, arg, components, typeParameters) {
33478
+ if (components === null) {
33479
+ return null;
33337
33480
  }
33338
- const len = data.slice(16, 24);
33339
- const encodedLength = bn(new U64Coder().decode(len, 0)[0]).toNumber();
33340
- const byteData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + encodedLength);
33341
- if (byteData.length !== encodedLength) {
33342
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
33481
+ if (typeParameters === null || typeParameters.length === 0) {
33482
+ return components.map((c) => new ResolvedAbiType(abi, c));
33343
33483
  }
33344
- return [byteData, offset + BASE_VECTOR_OFFSET];
33484
+ const typeParametersAndArgsMap = typeParameters.reduce(
33485
+ (obj, typeParameter, typeParameterIndex) => {
33486
+ const o = { ...obj };
33487
+ o[typeParameter] = structuredClone(
33488
+ arg.typeArguments?.[typeParameterIndex]
33489
+ );
33490
+ return o;
33491
+ },
33492
+ {}
33493
+ );
33494
+ const resolvedComponents = this.resolveGenericArgTypes(
33495
+ abi,
33496
+ components,
33497
+ typeParametersAndArgsMap
33498
+ );
33499
+ return resolvedComponents.map((c) => new ResolvedAbiType(abi, c));
33345
33500
  }
33346
- };
33347
- _getPaddedData = /* @__PURE__ */ new WeakSet();
33348
- getPaddedData_fn = function(value) {
33349
- const data = [Uint8Array.from(value)];
33350
- const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
33351
- if (paddingLength) {
33352
- data.push(new Uint8Array(paddingLength));
33501
+ static resolveGenericArgTypes(abi, args, typeParametersAndArgsMap) {
33502
+ return args.map((arg) => {
33503
+ if (typeParametersAndArgsMap[arg.type] !== void 0) {
33504
+ return {
33505
+ ...typeParametersAndArgsMap[arg.type],
33506
+ name: arg.name
33507
+ };
33508
+ }
33509
+ if (arg.typeArguments) {
33510
+ return {
33511
+ ...structuredClone(arg),
33512
+ typeArguments: this.resolveGenericArgTypes(
33513
+ abi,
33514
+ arg.typeArguments,
33515
+ typeParametersAndArgsMap
33516
+ )
33517
+ };
33518
+ }
33519
+ const argType = findOrThrow(abi.types, (t) => t.typeId === arg.type);
33520
+ const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
33521
+ if (implicitTypeParameters && implicitTypeParameters.length > 0) {
33522
+ return {
33523
+ ...structuredClone(arg),
33524
+ typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
33525
+ };
33526
+ }
33527
+ return arg;
33528
+ });
33353
33529
  }
33354
- return concat2(data);
33355
- };
33356
- __publicField3(ByteCoder, "memorySize", 1);
33357
- var RawSliceCoder = class extends Coder {
33358
- constructor() {
33359
- super("raw untyped slice", "raw untyped slice", BASE_RAW_SLICE_OFFSET);
33530
+ static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
33531
+ if (!Array.isArray(args)) {
33532
+ return null;
33533
+ }
33534
+ const implicitGenericParameters = implicitGenericParametersParam ?? [];
33535
+ args.forEach((a) => {
33536
+ const argType = findOrThrow(abi.types, (t) => t.typeId === a.type);
33537
+ if (genericRegEx.test(argType.type)) {
33538
+ implicitGenericParameters.push(argType.typeId);
33539
+ return;
33540
+ }
33541
+ if (!Array.isArray(a.typeArguments)) {
33542
+ return;
33543
+ }
33544
+ this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters);
33545
+ });
33546
+ return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
33360
33547
  }
33361
- encode(value) {
33362
- if (!Array.isArray(value)) {
33363
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
33548
+ getSignature() {
33549
+ const prefix = this.getArgSignaturePrefix();
33550
+ const content = this.getArgSignatureContent();
33551
+ return `${prefix}${content}`;
33552
+ }
33553
+ getArgSignaturePrefix() {
33554
+ const structMatch = structRegEx.test(this.type);
33555
+ if (structMatch) {
33556
+ return "s";
33364
33557
  }
33365
- const parts = [];
33366
- const coder = new NumberCoder("u8", { isSmallBytes: true });
33367
- const pointer = new U64Coder().encode(BASE_RAW_SLICE_OFFSET);
33368
- pointer.dynamicData = {
33369
- 0: concatWithDynamicData(value.map((v) => coder.encode(v)))
33370
- };
33371
- parts.push(pointer);
33372
- parts.push(new U64Coder().encode(value.length));
33373
- return concatWithDynamicData(parts);
33558
+ const arrayMatch = arrayRegEx.test(this.type);
33559
+ if (arrayMatch) {
33560
+ return "a";
33561
+ }
33562
+ const enumMatch = enumRegEx.test(this.type);
33563
+ if (enumMatch) {
33564
+ return "e";
33565
+ }
33566
+ return "";
33374
33567
  }
33375
- decode(data, offset) {
33376
- const dataBytes = data.slice(offset);
33377
- const internalCoder = new ArrayCoder(
33378
- new NumberCoder("u8", { isSmallBytes: true }),
33379
- dataBytes.length
33380
- );
33381
- const [decodedValue] = internalCoder.decode(dataBytes, 0);
33382
- return [decodedValue, offset + dataBytes.length];
33568
+ getArgSignatureContent() {
33569
+ if (this.type === "raw untyped ptr") {
33570
+ return "rawptr";
33571
+ }
33572
+ if (this.type === "raw untyped slice") {
33573
+ return "rawslice";
33574
+ }
33575
+ const strMatch = stringRegEx.exec(this.type)?.groups;
33576
+ if (strMatch) {
33577
+ return `str[${strMatch.length}]`;
33578
+ }
33579
+ if (this.components === null) {
33580
+ return this.type;
33581
+ }
33582
+ const arrayMatch = arrayRegEx.exec(this.type)?.groups;
33583
+ if (arrayMatch) {
33584
+ return `[${this.components[0].getSignature()};${arrayMatch.length}]`;
33585
+ }
33586
+ const typeArgumentsSignature = this.originalTypeArguments !== null ? `<${this.originalTypeArguments.map((a) => new ResolvedAbiType(this.abi, a).getSignature()).join(",")}>` : "";
33587
+ const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
33588
+ return `${typeArgumentsSignature}${componentsSignature}`;
33383
33589
  }
33384
33590
  };
33385
- var _getPaddedData2;
33386
- var getPaddedData_fn2;
33387
- var StdStringCoder = class extends Coder {
33388
- constructor() {
33389
- super("struct", "struct String", 1);
33390
- __privateAdd2(this, _getPaddedData2);
33591
+ function getCoders(components, options) {
33592
+ const { getCoder: getCoder3 } = options;
33593
+ return components.reduce((obj, component) => {
33594
+ const o = obj;
33595
+ o[component.name] = getCoder3(component, options);
33596
+ return o;
33597
+ }, {});
33598
+ }
33599
+ var getCoder = (resolvedAbiType, options) => {
33600
+ switch (resolvedAbiType.type) {
33601
+ case U8_CODER_TYPE:
33602
+ case U16_CODER_TYPE:
33603
+ case U32_CODER_TYPE:
33604
+ return new NumberCoder(resolvedAbiType.type, options);
33605
+ case U64_CODER_TYPE:
33606
+ case RAW_PTR_CODER_TYPE:
33607
+ return new U64Coder();
33608
+ case RAW_SLICE_CODER_TYPE:
33609
+ return new RawSliceCoder();
33610
+ case BOOL_CODER_TYPE:
33611
+ return new BooleanCoder(options);
33612
+ case B256_CODER_TYPE:
33613
+ return new B256Coder();
33614
+ case B512_CODER_TYPE:
33615
+ return new B512Coder();
33616
+ case BYTES_CODER_TYPE:
33617
+ return new ByteCoder();
33618
+ case STD_STRING_CODER_TYPE:
33619
+ return new StdStringCoder();
33620
+ default:
33621
+ break;
33391
33622
  }
33392
- encode(value) {
33393
- const parts = [];
33394
- const pointer = new U64Coder().encode(BASE_VECTOR_OFFSET);
33395
- const data = __privateMethod2(this, _getPaddedData2, getPaddedData_fn2).call(this, value);
33396
- pointer.dynamicData = {
33397
- 0: concatWithDynamicData([data])
33398
- };
33399
- parts.push(pointer);
33400
- parts.push(new U64Coder().encode(data.byteLength));
33401
- parts.push(new U64Coder().encode(value.length));
33402
- return concatWithDynamicData(parts);
33623
+ const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
33624
+ if (stringMatch) {
33625
+ const length = parseInt(stringMatch.length, 10);
33626
+ return new StringCoder(length);
33627
+ }
33628
+ const components = resolvedAbiType.components;
33629
+ const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
33630
+ if (arrayMatch) {
33631
+ const length = parseInt(arrayMatch.length, 10);
33632
+ const arg = components[0];
33633
+ if (!arg) {
33634
+ throw new FuelError(
33635
+ ErrorCode.INVALID_COMPONENT,
33636
+ `The provided Array type is missing an item of 'component'.`
33637
+ );
33638
+ }
33639
+ const arrayElementCoder = getCoder(arg, { isSmallBytes: true });
33640
+ return new ArrayCoder(arrayElementCoder, length);
33403
33641
  }
33404
- decode(data, offset) {
33405
- if (data.length < this.encodedLength) {
33406
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string data size.`);
33642
+ if (resolvedAbiType.type === VEC_CODER_TYPE) {
33643
+ const arg = findOrThrow(components, (c) => c.name === "buf").originalTypeArguments?.[0];
33644
+ if (!arg) {
33645
+ throw new FuelError(
33646
+ ErrorCode.INVALID_COMPONENT,
33647
+ `The provided Vec type is missing the 'type argument'.`
33648
+ );
33407
33649
  }
33408
- const len = data.slice(16, 24);
33409
- const encodedLength = bn(new U64Coder().decode(len, 0)[0]).toNumber();
33410
- const byteData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + encodedLength);
33411
- if (byteData.length !== encodedLength) {
33412
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string byte data size.`);
33650
+ const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
33651
+ const itemCoder = getCoder(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
33652
+ return new VecCoder(itemCoder);
33653
+ }
33654
+ const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
33655
+ if (structMatch) {
33656
+ const coders = getCoders(components, { isRightPadded: true, getCoder });
33657
+ return new StructCoder(structMatch.name, coders);
33658
+ }
33659
+ const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
33660
+ if (enumMatch) {
33661
+ const coders = getCoders(components, { getCoder });
33662
+ const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
33663
+ if (isOptionEnum) {
33664
+ return new OptionCoder(enumMatch.name, coders);
33413
33665
  }
33414
- const value = toUtf8String(byteData);
33415
- return [value, offset + BASE_VECTOR_OFFSET];
33666
+ return new EnumCoder(enumMatch.name, coders);
33416
33667
  }
33417
- };
33418
- _getPaddedData2 = /* @__PURE__ */ new WeakSet();
33419
- getPaddedData_fn2 = function(value) {
33420
- const data = [toUtf8Bytes(value)];
33421
- const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
33422
- if (paddingLength) {
33423
- data.push(new Uint8Array(paddingLength));
33668
+ const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
33669
+ if (tupleMatch) {
33670
+ const coders = components.map(
33671
+ (component) => getCoder(component, { isRightPadded: true, encoding: ENCODING_V0 })
33672
+ );
33673
+ return new TupleCoder(coders);
33674
+ }
33675
+ if (resolvedAbiType.type === STR_SLICE_CODER_TYPE) {
33676
+ throw new FuelError(
33677
+ ErrorCode.INVALID_DATA,
33678
+ "String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
33679
+ );
33424
33680
  }
33425
- return concat2(data);
33681
+ throw new FuelError(
33682
+ ErrorCode.CODER_NOT_FOUND,
33683
+ `Coder not found: ${JSON.stringify(resolvedAbiType)}.`
33684
+ );
33426
33685
  };
33427
- __publicField3(StdStringCoder, "memorySize", 1);
33428
33686
  var BooleanCoder2 = class extends Coder {
33429
33687
  constructor() {
33430
33688
  super("boolean", "boolean", 1);
@@ -33452,10 +33710,15 @@ spurious results.`);
33452
33710
  };
33453
33711
  var ByteCoder2 = class extends Coder {
33454
33712
  constructor() {
33455
- super("struct", "struct Bytes", 1);
33713
+ super("struct", "struct Bytes", WORD_SIZE);
33456
33714
  }
33457
- encode(_value) {
33458
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Bytes encode unsupported in v1`);
33715
+ encode(value) {
33716
+ if (!Array.isArray(value)) {
33717
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
33718
+ }
33719
+ const bytes4 = new Uint8Array(value);
33720
+ const lengthBytes = new U64Coder().encode(value.length);
33721
+ return new Uint8Array([...lengthBytes, ...bytes4]);
33459
33722
  }
33460
33723
  decode(data, offset) {
33461
33724
  if (data.length < WORD_SIZE) {
@@ -33464,12 +33727,11 @@ spurious results.`);
33464
33727
  const offsetAndLength = offset + WORD_SIZE;
33465
33728
  const lengthBytes = data.slice(offset, offsetAndLength);
33466
33729
  const length = bn(new U64Coder().decode(lengthBytes, 0)[0]).toNumber();
33467
- const dataLength2 = length * this.encodedLength;
33468
- const dataBytes = data.slice(offsetAndLength, offsetAndLength + dataLength2);
33730
+ const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
33469
33731
  if (dataBytes.length !== length) {
33470
33732
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
33471
33733
  }
33472
- return [dataBytes, offset + dataLength2];
33734
+ return [dataBytes, offsetAndLength + length];
33473
33735
  }
33474
33736
  };
33475
33737
  __publicField3(ByteCoder2, "memorySize", 1);
@@ -33494,8 +33756,28 @@ spurious results.`);
33494
33756
  this.#caseIndexCoder = caseIndexCoder;
33495
33757
  this.#encodedValueSize = encodedValueSize;
33496
33758
  }
33497
- encode(_value) {
33498
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Enum encode unsupported in v1`);
33759
+ #encodeNativeEnum(value) {
33760
+ const valueCoder = this.coders[value];
33761
+ const encodedValue = valueCoder.encode([]);
33762
+ const caseIndex = Object.keys(this.coders).indexOf(value);
33763
+ const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
33764
+ return concat([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
33765
+ }
33766
+ encode(value) {
33767
+ if (typeof value === "string" && this.coders[value]) {
33768
+ return this.#encodeNativeEnum(value);
33769
+ }
33770
+ const [caseKey, ...empty] = Object.keys(value);
33771
+ if (!caseKey) {
33772
+ throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "A field for the case must be provided.");
33773
+ }
33774
+ if (empty.length !== 0) {
33775
+ throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "Only one field must be provided.");
33776
+ }
33777
+ const valueCoder = this.coders[caseKey];
33778
+ const caseIndex = Object.keys(this.coders).indexOf(caseKey);
33779
+ const encodedValue = valueCoder.encode(value[caseKey]);
33780
+ return new Uint8Array([...this.#caseIndexCoder.encode(caseIndex), ...encodedValue]);
33499
33781
  }
33500
33782
  #decodeNativeEnum(caseKey, newOffset) {
33501
33783
  return [caseKey, newOffset];
@@ -33570,8 +33852,14 @@ spurious results.`);
33570
33852
  constructor() {
33571
33853
  super("raw untyped slice", "raw untyped slice", WORD_SIZE);
33572
33854
  }
33573
- encode(_value) {
33574
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Raw slice encode unsupported in v1`);
33855
+ encode(value) {
33856
+ if (!Array.isArray(value)) {
33857
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
33858
+ }
33859
+ const internalCoder = new ArrayCoder(new NumberCoder2("u8"), value.length);
33860
+ const bytes4 = internalCoder.encode(value);
33861
+ const lengthBytes = new U64Coder().encode(bytes4.length);
33862
+ return new Uint8Array([...lengthBytes, ...bytes4]);
33575
33863
  }
33576
33864
  decode(data, offset) {
33577
33865
  if (data.length < this.encodedLength) {
@@ -33593,8 +33881,10 @@ spurious results.`);
33593
33881
  constructor() {
33594
33882
  super("struct", "struct String", WORD_SIZE);
33595
33883
  }
33596
- encode(_value) {
33597
- throw new FuelError(ErrorCode.ENCODE_ERROR, `StdString encode unsupported in v1`);
33884
+ encode(value) {
33885
+ const bytes4 = toUtf8Bytes(value);
33886
+ const lengthBytes = new U64Coder().encode(value.length);
33887
+ return new Uint8Array([...lengthBytes, ...bytes4]);
33598
33888
  }
33599
33889
  decode(data, offset) {
33600
33890
  if (data.length < this.encodedLength) {
@@ -33644,8 +33934,20 @@ spurious results.`);
33644
33934
  this.name = name;
33645
33935
  this.coders = coders;
33646
33936
  }
33647
- encode(_value) {
33648
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Struct encode unsupported in v1`);
33937
+ encode(value) {
33938
+ return concatBytes2(
33939
+ Object.keys(this.coders).map((fieldName) => {
33940
+ const fieldCoder = this.coders[fieldName];
33941
+ const fieldValue = value[fieldName];
33942
+ if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
33943
+ throw new FuelError(
33944
+ ErrorCode.ENCODE_ERROR,
33945
+ `Invalid ${this.type}. Field "${fieldName}" not present.`
33946
+ );
33947
+ }
33948
+ return fieldCoder.encode(fieldValue);
33949
+ })
33950
+ );
33649
33951
  }
33650
33952
  decode(data, offset) {
33651
33953
  if (data.length < this.encodedLength) {
@@ -33673,7 +33975,7 @@ spurious results.`);
33673
33975
  if (this.coders.length !== value.length) {
33674
33976
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
33675
33977
  }
33676
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Tuple encode unsupported in v1`);
33978
+ return concatBytes2(this.coders.map((coder, i) => coder.encode(value[i])));
33677
33979
  }
33678
33980
  decode(data, offset) {
33679
33981
  if (data.length < this.encodedLength) {
@@ -33694,180 +33996,140 @@ spurious results.`);
33694
33996
  super("struct", `struct Vec`, coder.encodedLength + WORD_SIZE);
33695
33997
  this.coder = coder;
33696
33998
  }
33697
- encode(_value) {
33698
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Vec encode unsupported in v1`);
33999
+ encode(value) {
34000
+ if (!Array.isArray(value)) {
34001
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
34002
+ }
34003
+ const bytes4 = value.map((v) => this.coder.encode(v));
34004
+ const lengthBytes = new U64Coder().encode(value.length);
34005
+ return new Uint8Array([...lengthBytes, ...concatBytes2(bytes4)]);
33699
34006
  }
33700
34007
  decode(data, offset) {
33701
34008
  if (data.length < this.encodedLength || data.length > MAX_BYTES) {
33702
34009
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec data size.`);
33703
34010
  }
33704
34011
  const offsetAndLength = offset + WORD_SIZE;
33705
- const lengthBytes = data.slice(offset, offsetAndLength);
33706
- const length = bn(new U64Coder().decode(lengthBytes, 0)[0]).toNumber();
33707
- const dataLength2 = length * this.coder.encodedLength;
33708
- const dataBytes = data.slice(offsetAndLength, offsetAndLength + dataLength2);
33709
- if (dataBytes.length !== dataLength2) {
33710
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec byte data size.`);
33711
- }
33712
- return [
33713
- chunkByLength(dataBytes, this.coder.encodedLength).map(
33714
- (chunk) => this.coder.decode(chunk, 0)[0]
33715
- ),
33716
- offsetAndLength + dataLength2
33717
- ];
33718
- }
33719
- };
33720
- var ResolvedAbiType = class {
33721
- abi;
33722
- name;
33723
- type;
33724
- originalTypeArguments;
33725
- components;
33726
- constructor(abi, argument) {
33727
- this.abi = abi;
33728
- const type3 = findOrThrow(
33729
- abi.types,
33730
- (t) => t.typeId === argument.type,
33731
- () => {
33732
- throw new FuelError(
33733
- ErrorCode.TYPE_NOT_FOUND,
33734
- `Type does not exist in the provided abi: ${JSON.stringify({
33735
- argument,
33736
- abi: this.abi
33737
- })}`
33738
- );
33739
- }
33740
- );
33741
- this.name = argument.name;
33742
- this.type = type3.type;
33743
- this.originalTypeArguments = argument.typeArguments;
33744
- this.components = ResolvedAbiType.getResolvedGenericComponents(
33745
- abi,
33746
- argument,
33747
- type3.components,
33748
- type3.typeParameters ?? ResolvedAbiType.getImplicitGenericTypeParameters(abi, type3.components)
33749
- );
33750
- }
33751
- static getResolvedGenericComponents(abi, arg, components, typeParameters) {
33752
- if (components === null) {
33753
- return null;
33754
- }
33755
- if (typeParameters === null || typeParameters.length === 0) {
33756
- return components.map((c) => new ResolvedAbiType(abi, c));
33757
- }
33758
- const typeParametersAndArgsMap = typeParameters.reduce(
33759
- (obj, typeParameter, typeParameterIndex) => {
33760
- const o = { ...obj };
33761
- o[typeParameter] = structuredClone(
33762
- arg.typeArguments?.[typeParameterIndex]
33763
- );
33764
- return o;
33765
- },
33766
- {}
33767
- );
33768
- const resolvedComponents = this.resolveGenericArgTypes(
33769
- abi,
33770
- components,
33771
- typeParametersAndArgsMap
33772
- );
33773
- return resolvedComponents.map((c) => new ResolvedAbiType(abi, c));
33774
- }
33775
- static resolveGenericArgTypes(abi, args, typeParametersAndArgsMap) {
33776
- return args.map((arg) => {
33777
- if (typeParametersAndArgsMap[arg.type] !== void 0) {
33778
- return {
33779
- ...typeParametersAndArgsMap[arg.type],
33780
- name: arg.name
33781
- };
33782
- }
33783
- if (arg.typeArguments) {
33784
- return {
33785
- ...structuredClone(arg),
33786
- typeArguments: this.resolveGenericArgTypes(
33787
- abi,
33788
- arg.typeArguments,
33789
- typeParametersAndArgsMap
33790
- )
33791
- };
33792
- }
33793
- const argType = findOrThrow(abi.types, (t) => t.typeId === arg.type);
33794
- const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
33795
- if (implicitTypeParameters && implicitTypeParameters.length > 0) {
33796
- return {
33797
- ...structuredClone(arg),
33798
- typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
33799
- };
33800
- }
33801
- return arg;
33802
- });
33803
- }
33804
- static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
33805
- if (!Array.isArray(args)) {
33806
- return null;
33807
- }
33808
- const implicitGenericParameters = implicitGenericParametersParam ?? [];
33809
- args.forEach((a) => {
33810
- const argType = findOrThrow(abi.types, (t) => t.typeId === a.type);
33811
- if (genericRegEx.test(argType.type)) {
33812
- implicitGenericParameters.push(argType.typeId);
33813
- return;
33814
- }
33815
- if (!Array.isArray(a.typeArguments)) {
33816
- return;
33817
- }
33818
- this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters);
33819
- });
33820
- return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
33821
- }
33822
- getSignature() {
33823
- const prefix = this.getArgSignaturePrefix();
33824
- const content = this.getArgSignatureContent();
33825
- return `${prefix}${content}`;
33826
- }
33827
- getArgSignaturePrefix() {
33828
- const structMatch = structRegEx.test(this.type);
33829
- if (structMatch) {
33830
- return "s";
33831
- }
33832
- const arrayMatch = arrayRegEx.test(this.type);
33833
- if (arrayMatch) {
33834
- return "a";
33835
- }
33836
- const enumMatch = enumRegEx.test(this.type);
33837
- if (enumMatch) {
33838
- return "e";
33839
- }
33840
- return "";
33841
- }
33842
- getArgSignatureContent() {
33843
- if (this.type === "raw untyped ptr") {
33844
- return "rawptr";
33845
- }
33846
- if (this.type === "raw untyped slice") {
33847
- return "rawslice";
34012
+ const lengthBytes = data.slice(offset, offsetAndLength);
34013
+ const length = bn(new U64Coder().decode(lengthBytes, 0)[0]).toNumber();
34014
+ const dataLength2 = length * this.coder.encodedLength;
34015
+ const dataBytes = data.slice(offsetAndLength, offsetAndLength + dataLength2);
34016
+ if (dataBytes.length !== dataLength2) {
34017
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec byte data size.`);
33848
34018
  }
33849
- const strMatch = stringRegEx.exec(this.type)?.groups;
33850
- if (strMatch) {
33851
- return `str[${strMatch.length}]`;
34019
+ return [
34020
+ chunkByLength(dataBytes, this.coder.encodedLength).map(
34021
+ (chunk) => this.coder.decode(chunk, 0)[0]
34022
+ ),
34023
+ offsetAndLength + dataLength2
34024
+ ];
34025
+ }
34026
+ };
34027
+ var getCoder2 = (resolvedAbiType, _options) => {
34028
+ switch (resolvedAbiType.type) {
34029
+ case U8_CODER_TYPE:
34030
+ case U16_CODER_TYPE:
34031
+ case U32_CODER_TYPE:
34032
+ return new NumberCoder2(resolvedAbiType.type);
34033
+ case U64_CODER_TYPE:
34034
+ case RAW_PTR_CODER_TYPE:
34035
+ return new U64Coder();
34036
+ case RAW_SLICE_CODER_TYPE:
34037
+ return new RawSliceCoder2();
34038
+ case BOOL_CODER_TYPE:
34039
+ return new BooleanCoder2();
34040
+ case B256_CODER_TYPE:
34041
+ return new B256Coder();
34042
+ case B512_CODER_TYPE:
34043
+ return new B512Coder();
34044
+ case BYTES_CODER_TYPE:
34045
+ return new ByteCoder2();
34046
+ case STD_STRING_CODER_TYPE:
34047
+ return new StdStringCoder2();
34048
+ default:
34049
+ break;
34050
+ }
34051
+ const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
34052
+ if (stringMatch) {
34053
+ const length = parseInt(stringMatch.length, 10);
34054
+ return new StringCoder2(length);
34055
+ }
34056
+ const components = resolvedAbiType.components;
34057
+ const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
34058
+ if (arrayMatch) {
34059
+ const length = parseInt(arrayMatch.length, 10);
34060
+ const arg = components[0];
34061
+ if (!arg) {
34062
+ throw new FuelError(
34063
+ ErrorCode.INVALID_COMPONENT,
34064
+ `The provided Array type is missing an item of 'component'.`
34065
+ );
33852
34066
  }
33853
- if (this.components === null) {
33854
- return this.type;
34067
+ const arrayElementCoder = getCoder2(arg, { isSmallBytes: true });
34068
+ return new ArrayCoder(arrayElementCoder, length);
34069
+ }
34070
+ if (resolvedAbiType.type === VEC_CODER_TYPE) {
34071
+ const arg = findOrThrow(components, (c) => c.name === "buf").originalTypeArguments?.[0];
34072
+ if (!arg) {
34073
+ throw new FuelError(
34074
+ ErrorCode.INVALID_COMPONENT,
34075
+ `The provided Vec type is missing the 'type argument'.`
34076
+ );
33855
34077
  }
33856
- const arrayMatch = arrayRegEx.exec(this.type)?.groups;
33857
- if (arrayMatch) {
33858
- return `[${this.components[0].getSignature()};${arrayMatch.length}]`;
34078
+ const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
34079
+ const itemCoder = getCoder2(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
34080
+ return new VecCoder2(itemCoder);
34081
+ }
34082
+ const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
34083
+ if (structMatch) {
34084
+ const coders = getCoders(components, { isRightPadded: true, getCoder: getCoder2 });
34085
+ return new StructCoder2(structMatch.name, coders);
34086
+ }
34087
+ const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
34088
+ if (enumMatch) {
34089
+ const coders = getCoders(components, { getCoder: getCoder2 });
34090
+ const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
34091
+ if (isOptionEnum) {
34092
+ return new OptionCoder(enumMatch.name, coders);
33859
34093
  }
33860
- const typeArgumentsSignature = this.originalTypeArguments !== null ? `<${this.originalTypeArguments.map((a) => new ResolvedAbiType(this.abi, a).getSignature()).join(",")}>` : "";
33861
- const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
33862
- return `${typeArgumentsSignature}${componentsSignature}`;
34094
+ return new EnumCoder2(enumMatch.name, coders);
34095
+ }
34096
+ const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
34097
+ if (tupleMatch) {
34098
+ const coders = components.map(
34099
+ (component) => getCoder2(component, { isRightPadded: true, encoding: ENCODING_V0 })
34100
+ );
34101
+ return new TupleCoder2(coders);
34102
+ }
34103
+ if (resolvedAbiType.type === STR_SLICE_CODER_TYPE) {
34104
+ throw new FuelError(
34105
+ ErrorCode.INVALID_DATA,
34106
+ "String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
34107
+ );
33863
34108
  }
34109
+ throw new FuelError(
34110
+ ErrorCode.CODER_NOT_FOUND,
34111
+ `Coder not found: ${JSON.stringify(resolvedAbiType)}.`
34112
+ );
33864
34113
  };
34114
+ function getCoderForEncoding(encoding = ENCODING_V0) {
34115
+ switch (encoding) {
34116
+ case ENCODING_V1:
34117
+ return getCoder2;
34118
+ case ENCODING_V0:
34119
+ return getCoder;
34120
+ default:
34121
+ throw new FuelError(
34122
+ ErrorCode.UNSUPPORTED_ENCODING_VERSION,
34123
+ `Encoding version ${encoding} is unsupported.`
34124
+ );
34125
+ }
34126
+ }
33865
34127
  var AbiCoder = class {
33866
34128
  static getCoder(abi, argument, options = {
33867
34129
  isSmallBytes: false
33868
34130
  }) {
33869
34131
  const resolvedAbiType = new ResolvedAbiType(abi, argument);
33870
- return AbiCoder.getCoderImpl(resolvedAbiType, options);
34132
+ return getCoderForEncoding(options.encoding)(resolvedAbiType, options);
33871
34133
  }
33872
34134
  static encode(abi, argument, value, options) {
33873
34135
  return this.getCoder(abi, argument, options).encode(value);
@@ -33875,103 +34137,6 @@ spurious results.`);
33875
34137
  static decode(abi, argument, data, offset, options) {
33876
34138
  return this.getCoder(abi, argument, options).decode(data, offset);
33877
34139
  }
33878
- static getCoderImpl(resolvedAbiType, options = {
33879
- isSmallBytes: false
33880
- }) {
33881
- const { version: version2 } = options;
33882
- switch (resolvedAbiType.type) {
33883
- case "u8":
33884
- case "u16":
33885
- case "u32":
33886
- return version2 ? new NumberCoder2(resolvedAbiType.type) : new NumberCoder(resolvedAbiType.type, options);
33887
- case "u64":
33888
- case "raw untyped ptr":
33889
- return new U64Coder();
33890
- case "raw untyped slice":
33891
- return version2 ? new RawSliceCoder2() : new RawSliceCoder();
33892
- case "bool":
33893
- return version2 ? new BooleanCoder2() : new BooleanCoder(options);
33894
- case "b256":
33895
- return new B256Coder();
33896
- case "struct B512":
33897
- return new B512Coder();
33898
- case BYTES_CODER_TYPE:
33899
- return version2 ? new ByteCoder2() : new ByteCoder();
33900
- case STD_STRING_CODER_TYPE:
33901
- return version2 ? new StdStringCoder2() : new StdStringCoder();
33902
- default:
33903
- break;
33904
- }
33905
- const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
33906
- if (stringMatch) {
33907
- const length = parseInt(stringMatch.length, 10);
33908
- return version2 ? new StringCoder2(length) : new StringCoder(length);
33909
- }
33910
- const components = resolvedAbiType.components;
33911
- const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
33912
- if (arrayMatch) {
33913
- const length = parseInt(arrayMatch.length, 10);
33914
- const arg = components[0];
33915
- if (!arg) {
33916
- throw new FuelError(
33917
- ErrorCode.INVALID_COMPONENT,
33918
- `The provided Array type is missing an item of 'component'.`
33919
- );
33920
- }
33921
- const arrayElementCoder = AbiCoder.getCoderImpl(arg, { version: version2, isSmallBytes: true });
33922
- return new ArrayCoder(arrayElementCoder, length);
33923
- }
33924
- if (resolvedAbiType.type === VEC_CODER_TYPE) {
33925
- const arg = findOrThrow(components, (c) => c.name === "buf").originalTypeArguments?.[0];
33926
- if (!arg) {
33927
- throw new FuelError(
33928
- ErrorCode.INVALID_COMPONENT,
33929
- `The provided Vec type is missing the 'type argument'.`
33930
- );
33931
- }
33932
- const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
33933
- const itemCoder = AbiCoder.getCoderImpl(argType, { version: version2, isSmallBytes: true });
33934
- return version2 ? new VecCoder2(itemCoder) : new VecCoder(itemCoder);
33935
- }
33936
- const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
33937
- if (structMatch) {
33938
- const coders = AbiCoder.getCoders(components, { version: version2, isRightPadded: true });
33939
- return version2 ? new StructCoder2(structMatch.name, coders) : new StructCoder(structMatch.name, coders);
33940
- }
33941
- const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
33942
- if (enumMatch) {
33943
- const coders = AbiCoder.getCoders(components, { version: version2 });
33944
- const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
33945
- if (isOptionEnum) {
33946
- return new OptionCoder(enumMatch.name, coders);
33947
- }
33948
- return version2 ? new EnumCoder2(enumMatch.name, coders) : new EnumCoder(enumMatch.name, coders);
33949
- }
33950
- const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
33951
- if (tupleMatch) {
33952
- const coders = components.map(
33953
- (component) => AbiCoder.getCoderImpl(component, { version: version2, isRightPadded: true })
33954
- );
33955
- return version2 ? new TupleCoder2(coders) : new TupleCoder(coders);
33956
- }
33957
- if (resolvedAbiType.type === "str") {
33958
- throw new FuelError(
33959
- ErrorCode.INVALID_DATA,
33960
- "String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
33961
- );
33962
- }
33963
- throw new FuelError(
33964
- ErrorCode.CODER_NOT_FOUND,
33965
- `Coder not found: ${JSON.stringify(resolvedAbiType)}.`
33966
- );
33967
- }
33968
- static getCoders(components, options) {
33969
- return components.reduce((obj, component) => {
33970
- const o = obj;
33971
- o[component.name] = AbiCoder.getCoderImpl(component, options);
33972
- return o;
33973
- }, {});
33974
- }
33975
34140
  };
33976
34141
  var FunctionFragment = class {
33977
34142
  signature;
@@ -34066,7 +34231,7 @@ spurious results.`);
34066
34231
  throw new FuelError(ErrorCode.ABI_TYPES_AND_VALUES_MISMATCH, errorMsg);
34067
34232
  }
34068
34233
  decodeArguments(data) {
34069
- const bytes4 = getBytesCopy(data);
34234
+ const bytes4 = arrayify(data);
34070
34235
  const nonEmptyInputs = this.jsonFn.inputs.filter(
34071
34236
  (x) => findOrThrow(this.jsonAbi.types, (t) => t.typeId === x.type).type !== "()"
34072
34237
  );
@@ -34111,7 +34276,7 @@ spurious results.`);
34111
34276
  if (outputAbiType.type === "()") {
34112
34277
  return [void 0, 0];
34113
34278
  }
34114
- const bytes4 = getBytesCopy(data);
34279
+ const bytes4 = arrayify(data);
34115
34280
  const coder = AbiCoder.getCoder(this.jsonAbi, this.jsonFn.output);
34116
34281
  return coder.decode(bytes4, 0);
34117
34282
  }
@@ -34178,8 +34343,8 @@ spurious results.`);
34178
34343
  return externalInterface.decodeLog(data, logId, receiptId);
34179
34344
  }
34180
34345
  const { loggedType } = findOrThrow(this.jsonAbi.loggedTypes, (type3) => type3.logId === logId);
34181
- return AbiCoder.decode(this.jsonAbi, loggedType, getBytesCopy(data), 0, {
34182
- version: this.jsonAbi.encoding
34346
+ return AbiCoder.decode(this.jsonAbi, loggedType, arrayify(data), 0, {
34347
+ encoding: this.jsonAbi.encoding
34183
34348
  });
34184
34349
  }
34185
34350
  updateExternalLoggedTypes(id, loggedTypes) {
@@ -34235,12 +34400,12 @@ spurious results.`);
34235
34400
  }
34236
34401
  encode(value) {
34237
34402
  const parts = [];
34238
- const data = getBytesCopy(value);
34403
+ const data = arrayify(value);
34239
34404
  parts.push(data);
34240
34405
  if (this.#paddingLength) {
34241
34406
  parts.push(new Uint8Array(this.#paddingLength));
34242
34407
  }
34243
- return concat2(parts);
34408
+ return concat(parts);
34244
34409
  }
34245
34410
  decode(data, offset) {
34246
34411
  let decoded;
@@ -34286,7 +34451,7 @@ spurious results.`);
34286
34451
  parts.push(new NumberCoder("u32").encode(value.predicateDataLength));
34287
34452
  parts.push(new ByteArrayCoder(value.predicateLength).encode(value.predicate));
34288
34453
  parts.push(new ByteArrayCoder(value.predicateDataLength).encode(value.predicateData));
34289
- return concat2(parts);
34454
+ return concat(parts);
34290
34455
  }
34291
34456
  decode(data, offset) {
34292
34457
  let decoded;
@@ -34350,7 +34515,7 @@ spurious results.`);
34350
34515
  parts.push(new B256Coder().encode(value.stateRoot));
34351
34516
  parts.push(new TxPointerCoder().encode(value.txPointer));
34352
34517
  parts.push(new B256Coder().encode(value.contractID));
34353
- return concat2(parts);
34518
+ return concat(parts);
34354
34519
  }
34355
34520
  decode(data, offset) {
34356
34521
  let decoded;
@@ -34391,11 +34556,11 @@ spurious results.`);
34391
34556
  parts.push(new ByteArrayCoder(32).encode(value.recipient));
34392
34557
  parts.push(new ByteArrayCoder(32).encode(value.nonce));
34393
34558
  parts.push(new U64Coder().encode(value.amount));
34394
- parts.push(getBytesCopy(value.data || "0x"));
34395
- return sha2562(concat2(parts));
34559
+ parts.push(arrayify(value.data || "0x"));
34560
+ return sha2562(concat(parts));
34396
34561
  }
34397
34562
  static encodeData(messageData) {
34398
- const bytes4 = getBytesCopy(messageData || "0x");
34563
+ const bytes4 = arrayify(messageData || "0x");
34399
34564
  const dataLength2 = bytes4.length;
34400
34565
  return new ByteArrayCoder(dataLength2).encode(bytes4);
34401
34566
  }
@@ -34408,19 +34573,19 @@ spurious results.`);
34408
34573
  parts.push(new ByteArrayCoder(32).encode(value.nonce));
34409
34574
  parts.push(new NumberCoder("u8").encode(value.witnessIndex));
34410
34575
  parts.push(new U64Coder().encode(value.predicateGasUsed));
34411
- parts.push(new NumberCoder("u16").encode(data.length));
34412
- parts.push(new NumberCoder("u16").encode(value.predicateLength));
34413
- parts.push(new NumberCoder("u16").encode(value.predicateDataLength));
34576
+ parts.push(new NumberCoder("u32").encode(data.length));
34577
+ parts.push(new NumberCoder("u32").encode(value.predicateLength));
34578
+ parts.push(new NumberCoder("u32").encode(value.predicateDataLength));
34414
34579
  parts.push(new ByteArrayCoder(data.length).encode(data));
34415
34580
  parts.push(new ByteArrayCoder(value.predicateLength).encode(value.predicate));
34416
34581
  parts.push(new ByteArrayCoder(value.predicateDataLength).encode(value.predicateData));
34417
- return concat2(parts);
34582
+ return concat(parts);
34418
34583
  }
34419
34584
  static decodeData(messageData) {
34420
- const bytes4 = getBytesCopy(messageData);
34585
+ const bytes4 = arrayify(messageData);
34421
34586
  const dataLength2 = bytes4.length;
34422
34587
  const [data] = new ByteArrayCoder(dataLength2).decode(bytes4, 0);
34423
- return getBytesCopy(data);
34588
+ return arrayify(data);
34424
34589
  }
34425
34590
  decode(data, offset) {
34426
34591
  let decoded;
@@ -34437,11 +34602,11 @@ spurious results.`);
34437
34602
  const witnessIndex = Number(decoded);
34438
34603
  [decoded, o] = new U64Coder().decode(data, o);
34439
34604
  const predicateGasUsed = decoded;
34440
- [decoded, o] = new NumberCoder("u16").decode(data, o);
34441
- const predicateLength = decoded;
34442
- [decoded, o] = new NumberCoder("u16").decode(data, o);
34605
+ [decoded, o] = new NumberCoder("u32").decode(data, o);
34443
34606
  const dataLength2 = decoded;
34444
- [decoded, o] = new NumberCoder("u16").decode(data, o);
34607
+ [decoded, o] = new NumberCoder("u32").decode(data, o);
34608
+ const predicateLength = decoded;
34609
+ [decoded, o] = new NumberCoder("u32").decode(data, o);
34445
34610
  const predicateDataLength = decoded;
34446
34611
  [decoded, o] = new ByteArrayCoder(dataLength2).decode(data, o);
34447
34612
  const messageData = decoded;
@@ -34497,7 +34662,7 @@ spurious results.`);
34497
34662
  );
34498
34663
  }
34499
34664
  }
34500
- return concat2(parts);
34665
+ return concat(parts);
34501
34666
  }
34502
34667
  decode(data, offset) {
34503
34668
  let decoded;
@@ -34543,7 +34708,7 @@ spurious results.`);
34543
34708
  parts.push(new B256Coder().encode(value.to));
34544
34709
  parts.push(new U64Coder().encode(value.amount));
34545
34710
  parts.push(new B256Coder().encode(value.assetId));
34546
- return concat2(parts);
34711
+ return concat(parts);
34547
34712
  }
34548
34713
  decode(data, offset) {
34549
34714
  let decoded;
@@ -34574,7 +34739,7 @@ spurious results.`);
34574
34739
  parts.push(new NumberCoder("u8").encode(value.inputIndex));
34575
34740
  parts.push(new B256Coder().encode(value.balanceRoot));
34576
34741
  parts.push(new B256Coder().encode(value.stateRoot));
34577
- return concat2(parts);
34742
+ return concat(parts);
34578
34743
  }
34579
34744
  decode(data, offset) {
34580
34745
  let decoded;
@@ -34605,7 +34770,7 @@ spurious results.`);
34605
34770
  parts.push(new B256Coder().encode(value.to));
34606
34771
  parts.push(new U64Coder().encode(value.amount));
34607
34772
  parts.push(new B256Coder().encode(value.assetId));
34608
- return concat2(parts);
34773
+ return concat(parts);
34609
34774
  }
34610
34775
  decode(data, offset) {
34611
34776
  let decoded;
@@ -34636,7 +34801,7 @@ spurious results.`);
34636
34801
  parts.push(new B256Coder().encode(value.to));
34637
34802
  parts.push(new U64Coder().encode(value.amount));
34638
34803
  parts.push(new B256Coder().encode(value.assetId));
34639
- return concat2(parts);
34804
+ return concat(parts);
34640
34805
  }
34641
34806
  decode(data, offset) {
34642
34807
  let decoded;
@@ -34666,7 +34831,7 @@ spurious results.`);
34666
34831
  const parts = [];
34667
34832
  parts.push(new B256Coder().encode(value.contractId));
34668
34833
  parts.push(new B256Coder().encode(value.stateRoot));
34669
- return concat2(parts);
34834
+ return concat(parts);
34670
34835
  }
34671
34836
  decode(data, offset) {
34672
34837
  let decoded;
@@ -34721,7 +34886,7 @@ spurious results.`);
34721
34886
  );
34722
34887
  }
34723
34888
  }
34724
- return concat2(parts);
34889
+ return concat(parts);
34725
34890
  }
34726
34891
  decode(data, offset) {
34727
34892
  let decoded;
@@ -34801,7 +34966,7 @@ spurious results.`);
34801
34966
  }
34802
34967
  }
34803
34968
  });
34804
- return concat2(parts);
34969
+ return concat(parts);
34805
34970
  }
34806
34971
  decode(data, offset, policyTypes) {
34807
34972
  let o = offset;
@@ -34855,8 +35020,8 @@ spurious results.`);
34855
35020
  parts.push(new ByteArrayCoder(32).encode(value.recipient));
34856
35021
  parts.push(new ByteArrayCoder(32).encode(value.nonce));
34857
35022
  parts.push(new U64Coder().encode(value.amount));
34858
- parts.push(getBytesCopy(value.data || "0x"));
34859
- return sha2562(concat2(parts));
35023
+ parts.push(arrayify(value.data || "0x"));
35024
+ return sha2562(concat(parts));
34860
35025
  }
34861
35026
  encode(value) {
34862
35027
  const parts = [];
@@ -34867,7 +35032,7 @@ spurious results.`);
34867
35032
  parts.push(new NumberCoder("u16").encode(value.data.length));
34868
35033
  parts.push(new B256Coder().encode(value.digest));
34869
35034
  parts.push(new ByteArrayCoder(value.data.length).encode(value.data));
34870
- return concat2(parts);
35035
+ return concat(parts);
34871
35036
  }
34872
35037
  decode(data, offset) {
34873
35038
  let decoded;
@@ -34885,7 +35050,7 @@ spurious results.`);
34885
35050
  [decoded, o] = new B256Coder().decode(data, o);
34886
35051
  const digest = decoded;
34887
35052
  [decoded, o] = new ByteArrayCoder(len).decode(data, o);
34888
- const messageData = getBytesCopy(decoded);
35053
+ const messageData = arrayify(decoded);
34889
35054
  const receiptMessageOut = {
34890
35055
  type: 10,
34891
35056
  messageId: "",
@@ -34901,9 +35066,9 @@ spurious results.`);
34901
35066
  }
34902
35067
  };
34903
35068
  var getAssetId = (contractId, subId) => {
34904
- const contractIdBytes = getBytesCopy(contractId);
34905
- const subIdBytes = getBytesCopy(subId);
34906
- return sha2562(concat2([contractIdBytes, subIdBytes]));
35069
+ const contractIdBytes = arrayify(contractId);
35070
+ const subIdBytes = arrayify(subId);
35071
+ return sha2562(concat([contractIdBytes, subIdBytes]));
34907
35072
  };
34908
35073
  var ReceiptMintCoder = class extends Coder {
34909
35074
  constructor() {
@@ -34919,7 +35084,7 @@ spurious results.`);
34919
35084
  parts.push(new U64Coder().encode(value.val));
34920
35085
  parts.push(new U64Coder().encode(value.pc));
34921
35086
  parts.push(new U64Coder().encode(value.is));
34922
- return concat2(parts);
35087
+ return concat(parts);
34923
35088
  }
34924
35089
  decode(data, offset) {
34925
35090
  let decoded;
@@ -34961,7 +35126,7 @@ spurious results.`);
34961
35126
  parts.push(new U64Coder().encode(value.val));
34962
35127
  parts.push(new U64Coder().encode(value.pc));
34963
35128
  parts.push(new U64Coder().encode(value.is));
34964
- return concat2(parts);
35129
+ return concat(parts);
34965
35130
  }
34966
35131
  decode(data, offset) {
34967
35132
  let decoded;
@@ -35008,14 +35173,14 @@ spurious results.`);
35008
35173
  }
35009
35174
  encode(value) {
35010
35175
  const parts = [];
35011
- parts.push(new NumberCoder("u16").encode(value.dataLength));
35176
+ parts.push(new NumberCoder("u32").encode(value.dataLength));
35012
35177
  parts.push(new ByteArrayCoder(value.dataLength).encode(value.data));
35013
- return concat2(parts);
35178
+ return concat(parts);
35014
35179
  }
35015
35180
  decode(data, offset) {
35016
35181
  let decoded;
35017
35182
  let o = offset;
35018
- [decoded, o] = new NumberCoder("u16").decode(data, o);
35183
+ [decoded, o] = new NumberCoder("u32").decode(data, o);
35019
35184
  const dataLength2 = decoded;
35020
35185
  [decoded, o] = new ByteArrayCoder(dataLength2).decode(data, o);
35021
35186
  const witnessData = decoded;
@@ -35041,8 +35206,8 @@ spurious results.`);
35041
35206
  encode(value) {
35042
35207
  const parts = [];
35043
35208
  parts.push(new U64Coder().encode(value.scriptGasLimit));
35044
- parts.push(new NumberCoder("u16").encode(value.scriptLength));
35045
- parts.push(new NumberCoder("u16").encode(value.scriptDataLength));
35209
+ parts.push(new NumberCoder("u32").encode(value.scriptLength));
35210
+ parts.push(new NumberCoder("u32").encode(value.scriptDataLength));
35046
35211
  parts.push(new NumberCoder("u32").encode(value.policyTypes));
35047
35212
  parts.push(new NumberCoder("u8").encode(value.inputsCount));
35048
35213
  parts.push(new NumberCoder("u8").encode(value.outputsCount));
@@ -35054,16 +35219,16 @@ spurious results.`);
35054
35219
  parts.push(new ArrayCoder(new InputCoder(), value.inputsCount).encode(value.inputs));
35055
35220
  parts.push(new ArrayCoder(new OutputCoder(), value.outputsCount).encode(value.outputs));
35056
35221
  parts.push(new ArrayCoder(new WitnessCoder(), value.witnessesCount).encode(value.witnesses));
35057
- return concat2(parts);
35222
+ return concat(parts);
35058
35223
  }
35059
35224
  decode(data, offset) {
35060
35225
  let decoded;
35061
35226
  let o = offset;
35062
35227
  [decoded, o] = new U64Coder().decode(data, o);
35063
35228
  const scriptGasLimit = decoded;
35064
- [decoded, o] = new NumberCoder("u16").decode(data, o);
35229
+ [decoded, o] = new NumberCoder("u32").decode(data, o);
35065
35230
  const scriptLength = decoded;
35066
- [decoded, o] = new NumberCoder("u16").decode(data, o);
35231
+ [decoded, o] = new NumberCoder("u32").decode(data, o);
35067
35232
  const scriptDataLength = decoded;
35068
35233
  [decoded, o] = new NumberCoder("u32").decode(data, o);
35069
35234
  const policyTypes = decoded;
@@ -35115,7 +35280,7 @@ spurious results.`);
35115
35280
  }
35116
35281
  encode(value) {
35117
35282
  const parts = [];
35118
- parts.push(new NumberCoder("u16").encode(value.bytecodeLength));
35283
+ parts.push(new NumberCoder("u32").encode(value.bytecodeLength));
35119
35284
  parts.push(new NumberCoder("u8").encode(value.bytecodeWitnessIndex));
35120
35285
  parts.push(new NumberCoder("u32").encode(value.policyTypes));
35121
35286
  parts.push(new NumberCoder("u16").encode(value.storageSlotsCount));
@@ -35130,12 +35295,12 @@ spurious results.`);
35130
35295
  parts.push(new ArrayCoder(new InputCoder(), value.inputsCount).encode(value.inputs));
35131
35296
  parts.push(new ArrayCoder(new OutputCoder(), value.outputsCount).encode(value.outputs));
35132
35297
  parts.push(new ArrayCoder(new WitnessCoder(), value.witnessesCount).encode(value.witnesses));
35133
- return concat2(parts);
35298
+ return concat(parts);
35134
35299
  }
35135
35300
  decode(data, offset) {
35136
35301
  let decoded;
35137
35302
  let o = offset;
35138
- [decoded, o] = new NumberCoder("u16").decode(data, o);
35303
+ [decoded, o] = new NumberCoder("u32").decode(data, o);
35139
35304
  const bytecodeLength = decoded;
35140
35305
  [decoded, o] = new NumberCoder("u8").decode(data, o);
35141
35306
  const bytecodeWitnessIndex = decoded;
@@ -35193,7 +35358,7 @@ spurious results.`);
35193
35358
  parts.push(new OutputContractCoder().encode(value.outputContract));
35194
35359
  parts.push(new U64Coder().encode(value.mintAmount));
35195
35360
  parts.push(new B256Coder().encode(value.mintAssetId));
35196
- return concat2(parts);
35361
+ return concat(parts);
35197
35362
  }
35198
35363
  decode(data, offset) {
35199
35364
  let decoded;
@@ -35253,7 +35418,7 @@ spurious results.`);
35253
35418
  );
35254
35419
  }
35255
35420
  }
35256
- return concat2(parts);
35421
+ return concat(parts);
35257
35422
  }
35258
35423
  decode(data, offset) {
35259
35424
  let decoded;
@@ -35280,8 +35445,244 @@ spurious results.`);
35280
35445
  );
35281
35446
  }
35282
35447
  }
35283
- }
35448
+ }
35449
+ };
35450
+
35451
+ // ../../node_modules/.pnpm/@noble+curves@1.3.0/node_modules/@noble/curves/esm/abstract/utils.js
35452
+ var utils_exports = {};
35453
+ __export(utils_exports, {
35454
+ bitGet: () => bitGet,
35455
+ bitLen: () => bitLen,
35456
+ bitMask: () => bitMask,
35457
+ bitSet: () => bitSet,
35458
+ bytesToHex: () => bytesToHex2,
35459
+ bytesToNumberBE: () => bytesToNumberBE,
35460
+ bytesToNumberLE: () => bytesToNumberLE,
35461
+ concatBytes: () => concatBytes3,
35462
+ createHmacDrbg: () => createHmacDrbg,
35463
+ ensureBytes: () => ensureBytes,
35464
+ equalBytes: () => equalBytes,
35465
+ hexToBytes: () => hexToBytes2,
35466
+ hexToNumber: () => hexToNumber,
35467
+ isBytes: () => isBytes,
35468
+ numberToBytesBE: () => numberToBytesBE,
35469
+ numberToBytesLE: () => numberToBytesLE,
35470
+ numberToHexUnpadded: () => numberToHexUnpadded,
35471
+ numberToVarBytesBE: () => numberToVarBytesBE,
35472
+ utf8ToBytes: () => utf8ToBytes3,
35473
+ validateObject: () => validateObject
35474
+ });
35475
+ var _0n3 = BigInt(0);
35476
+ var _1n3 = BigInt(1);
35477
+ var _2n3 = BigInt(2);
35478
+ function isBytes(a) {
35479
+ return a instanceof Uint8Array || a != null && typeof a === "object" && a.constructor.name === "Uint8Array";
35480
+ }
35481
+ var hexes3 = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
35482
+ function bytesToHex2(bytes4) {
35483
+ if (!isBytes(bytes4))
35484
+ throw new Error("Uint8Array expected");
35485
+ let hex = "";
35486
+ for (let i = 0; i < bytes4.length; i++) {
35487
+ hex += hexes3[bytes4[i]];
35488
+ }
35489
+ return hex;
35490
+ }
35491
+ function numberToHexUnpadded(num) {
35492
+ const hex = num.toString(16);
35493
+ return hex.length & 1 ? `0${hex}` : hex;
35494
+ }
35495
+ function hexToNumber(hex) {
35496
+ if (typeof hex !== "string")
35497
+ throw new Error("hex string expected, got " + typeof hex);
35498
+ return BigInt(hex === "" ? "0" : `0x${hex}`);
35499
+ }
35500
+ var asciis = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 };
35501
+ function asciiToBase16(char) {
35502
+ if (char >= asciis._0 && char <= asciis._9)
35503
+ return char - asciis._0;
35504
+ if (char >= asciis._A && char <= asciis._F)
35505
+ return char - (asciis._A - 10);
35506
+ if (char >= asciis._a && char <= asciis._f)
35507
+ return char - (asciis._a - 10);
35508
+ return;
35509
+ }
35510
+ function hexToBytes2(hex) {
35511
+ if (typeof hex !== "string")
35512
+ throw new Error("hex string expected, got " + typeof hex);
35513
+ const hl = hex.length;
35514
+ const al = hl / 2;
35515
+ if (hl % 2)
35516
+ throw new Error("padded hex string expected, got unpadded hex of length " + hl);
35517
+ const array = new Uint8Array(al);
35518
+ for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
35519
+ const n1 = asciiToBase16(hex.charCodeAt(hi));
35520
+ const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
35521
+ if (n1 === void 0 || n2 === void 0) {
35522
+ const char = hex[hi] + hex[hi + 1];
35523
+ throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
35524
+ }
35525
+ array[ai] = n1 * 16 + n2;
35526
+ }
35527
+ return array;
35528
+ }
35529
+ function bytesToNumberBE(bytes4) {
35530
+ return hexToNumber(bytesToHex2(bytes4));
35531
+ }
35532
+ function bytesToNumberLE(bytes4) {
35533
+ if (!isBytes(bytes4))
35534
+ throw new Error("Uint8Array expected");
35535
+ return hexToNumber(bytesToHex2(Uint8Array.from(bytes4).reverse()));
35536
+ }
35537
+ function numberToBytesBE(n, len) {
35538
+ return hexToBytes2(n.toString(16).padStart(len * 2, "0"));
35539
+ }
35540
+ function numberToBytesLE(n, len) {
35541
+ return numberToBytesBE(n, len).reverse();
35542
+ }
35543
+ function numberToVarBytesBE(n) {
35544
+ return hexToBytes2(numberToHexUnpadded(n));
35545
+ }
35546
+ function ensureBytes(title, hex, expectedLength) {
35547
+ let res;
35548
+ if (typeof hex === "string") {
35549
+ try {
35550
+ res = hexToBytes2(hex);
35551
+ } catch (e) {
35552
+ throw new Error(`${title} must be valid hex string, got "${hex}". Cause: ${e}`);
35553
+ }
35554
+ } else if (isBytes(hex)) {
35555
+ res = Uint8Array.from(hex);
35556
+ } else {
35557
+ throw new Error(`${title} must be hex string or Uint8Array`);
35558
+ }
35559
+ const len = res.length;
35560
+ if (typeof expectedLength === "number" && len !== expectedLength)
35561
+ throw new Error(`${title} expected ${expectedLength} bytes, got ${len}`);
35562
+ return res;
35563
+ }
35564
+ function concatBytes3(...arrays) {
35565
+ let sum = 0;
35566
+ for (let i = 0; i < arrays.length; i++) {
35567
+ const a = arrays[i];
35568
+ if (!isBytes(a))
35569
+ throw new Error("Uint8Array expected");
35570
+ sum += a.length;
35571
+ }
35572
+ let res = new Uint8Array(sum);
35573
+ let pad3 = 0;
35574
+ for (let i = 0; i < arrays.length; i++) {
35575
+ const a = arrays[i];
35576
+ res.set(a, pad3);
35577
+ pad3 += a.length;
35578
+ }
35579
+ return res;
35580
+ }
35581
+ function equalBytes(a, b) {
35582
+ if (a.length !== b.length)
35583
+ return false;
35584
+ let diff = 0;
35585
+ for (let i = 0; i < a.length; i++)
35586
+ diff |= a[i] ^ b[i];
35587
+ return diff === 0;
35588
+ }
35589
+ function utf8ToBytes3(str) {
35590
+ if (typeof str !== "string")
35591
+ throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
35592
+ return new Uint8Array(new TextEncoder().encode(str));
35593
+ }
35594
+ function bitLen(n) {
35595
+ let len;
35596
+ for (len = 0; n > _0n3; n >>= _1n3, len += 1)
35597
+ ;
35598
+ return len;
35599
+ }
35600
+ function bitGet(n, pos) {
35601
+ return n >> BigInt(pos) & _1n3;
35602
+ }
35603
+ var bitSet = (n, pos, value) => {
35604
+ return n | (value ? _1n3 : _0n3) << BigInt(pos);
35605
+ };
35606
+ var bitMask = (n) => (_2n3 << BigInt(n - 1)) - _1n3;
35607
+ var u8n = (data) => new Uint8Array(data);
35608
+ var u8fr = (arr) => Uint8Array.from(arr);
35609
+ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
35610
+ if (typeof hashLen !== "number" || hashLen < 2)
35611
+ throw new Error("hashLen must be a number");
35612
+ if (typeof qByteLen !== "number" || qByteLen < 2)
35613
+ throw new Error("qByteLen must be a number");
35614
+ if (typeof hmacFn !== "function")
35615
+ throw new Error("hmacFn must be a function");
35616
+ let v = u8n(hashLen);
35617
+ let k = u8n(hashLen);
35618
+ let i = 0;
35619
+ const reset = () => {
35620
+ v.fill(1);
35621
+ k.fill(0);
35622
+ i = 0;
35623
+ };
35624
+ const h = (...b) => hmacFn(k, v, ...b);
35625
+ const reseed = (seed = u8n()) => {
35626
+ k = h(u8fr([0]), seed);
35627
+ v = h();
35628
+ if (seed.length === 0)
35629
+ return;
35630
+ k = h(u8fr([1]), seed);
35631
+ v = h();
35632
+ };
35633
+ const gen3 = () => {
35634
+ if (i++ >= 1e3)
35635
+ throw new Error("drbg: tried 1000 values");
35636
+ let len = 0;
35637
+ const out = [];
35638
+ while (len < qByteLen) {
35639
+ v = h();
35640
+ const sl = v.slice();
35641
+ out.push(sl);
35642
+ len += v.length;
35643
+ }
35644
+ return concatBytes3(...out);
35645
+ };
35646
+ const genUntil = (seed, pred) => {
35647
+ reset();
35648
+ reseed(seed);
35649
+ let res = void 0;
35650
+ while (!(res = pred(gen3())))
35651
+ reseed();
35652
+ reset();
35653
+ return res;
35654
+ };
35655
+ return genUntil;
35656
+ }
35657
+ var validatorFns = {
35658
+ bigint: (val) => typeof val === "bigint",
35659
+ function: (val) => typeof val === "function",
35660
+ boolean: (val) => typeof val === "boolean",
35661
+ string: (val) => typeof val === "string",
35662
+ stringOrUint8Array: (val) => typeof val === "string" || isBytes(val),
35663
+ isSafeInteger: (val) => Number.isSafeInteger(val),
35664
+ array: (val) => Array.isArray(val),
35665
+ field: (val, object) => object.Fp.isValid(val),
35666
+ hash: (val) => typeof val === "function" && Number.isSafeInteger(val.outputLen)
35284
35667
  };
35668
+ function validateObject(object, validators, optValidators = {}) {
35669
+ const checkField = (fieldName, type3, isOptional) => {
35670
+ const checkVal = validatorFns[type3];
35671
+ if (typeof checkVal !== "function")
35672
+ throw new Error(`Invalid validator "${type3}", expected function`);
35673
+ const val = object[fieldName];
35674
+ if (isOptional && val === void 0)
35675
+ return;
35676
+ if (!checkVal(val, object)) {
35677
+ throw new Error(`Invalid param ${String(fieldName)}=${val} (${typeof val}), expected ${type3}`);
35678
+ }
35679
+ };
35680
+ for (const [fieldName, type3] of Object.entries(validators))
35681
+ checkField(fieldName, type3, false);
35682
+ for (const [fieldName, type3] of Object.entries(optValidators))
35683
+ checkField(fieldName, type3, true);
35684
+ return object;
35685
+ }
35285
35686
 
35286
35687
  // src/providers/provider.ts
35287
35688
  var import_graphql_request = __toESM(require_dist2());
@@ -39405,67 +39806,63 @@ ${MessageCoinFragmentFragmentDoc}`;
39405
39806
  }
39406
39807
 
39407
39808
  // src/providers/fuel-graphql-subscriber.ts
39408
- var _FuelSubscriptionStream = class {
39409
- readable;
39410
- writable;
39411
- readableStreamController;
39412
- constructor() {
39413
- this.readable = new ReadableStream({
39414
- start: (controller) => {
39415
- this.readableStreamController = controller;
39416
- }
39417
- });
39418
- this.writable = new WritableStream({
39419
- write: (bytes4) => {
39420
- const text = _FuelSubscriptionStream.textDecoder.decode(bytes4);
39421
- if (text.startsWith("data:")) {
39422
- const { data, errors } = JSON.parse(text.split("data:")[1]);
39423
- if (Array.isArray(errors)) {
39424
- this.readableStreamController.enqueue(
39425
- new FuelError(
39426
- FuelError.CODES.INVALID_REQUEST,
39427
- errors.map((err) => err.message).join("\n\n")
39428
- )
39429
- );
39430
- } else {
39431
- this.readableStreamController.enqueue(data);
39432
- }
39433
- }
39809
+ var _FuelGraphqlSubscriber = class {
39810
+ constructor(options) {
39811
+ this.options = options;
39812
+ }
39813
+ stream;
39814
+ async setStream() {
39815
+ const { url, query, variables, fetchFn } = this.options;
39816
+ const response = await fetchFn(`${url}-sub`, {
39817
+ method: "POST",
39818
+ body: JSON.stringify({
39819
+ query: print(query),
39820
+ variables
39821
+ }),
39822
+ headers: {
39823
+ "Content-Type": "application/json",
39824
+ Accept: "text/event-stream"
39434
39825
  }
39435
39826
  });
39827
+ this.stream = response.body.getReader();
39436
39828
  }
39437
- };
39438
- var FuelSubscriptionStream = _FuelSubscriptionStream;
39439
- __publicField(FuelSubscriptionStream, "textDecoder", new TextDecoder());
39440
- async function* fuelGraphQLSubscriber({
39441
- url,
39442
- variables,
39443
- query,
39444
- fetchFn
39445
- }) {
39446
- const response = await fetchFn(`${url}-sub`, {
39447
- method: "POST",
39448
- body: JSON.stringify({
39449
- query: print(query),
39450
- variables
39451
- }),
39452
- headers: {
39453
- "Content-Type": "application/json",
39454
- Accept: "text/event-stream"
39829
+ async next() {
39830
+ if (!this.stream) {
39831
+ await this.setStream();
39455
39832
  }
39456
- });
39457
- const subscriptionStreamReader = response.body.pipeThrough(new FuelSubscriptionStream()).getReader();
39458
- while (true) {
39459
- const { value, done } = await subscriptionStreamReader.read();
39460
- if (value instanceof FuelError) {
39461
- throw value;
39462
- }
39463
- yield value;
39464
- if (done) {
39465
- break;
39833
+ while (true) {
39834
+ const { value, done } = await this.stream.read();
39835
+ if (done) {
39836
+ return { value, done };
39837
+ }
39838
+ const text = _FuelGraphqlSubscriber.textDecoder.decode(value);
39839
+ if (!text.startsWith("data:")) {
39840
+ continue;
39841
+ }
39842
+ const { data, errors } = JSON.parse(text.split("data:")[1]);
39843
+ if (Array.isArray(errors)) {
39844
+ throw new FuelError(
39845
+ FuelError.CODES.INVALID_REQUEST,
39846
+ errors.map((err) => err.message).join("\n\n")
39847
+ );
39848
+ }
39849
+ return { value: data, done: false };
39466
39850
  }
39467
39851
  }
39468
- }
39852
+ /**
39853
+ * Gets called when `break` is called in a `for-await-of` loop.
39854
+ */
39855
+ async return() {
39856
+ await this.stream.cancel();
39857
+ this.stream.releaseLock();
39858
+ return { done: true, value: void 0 };
39859
+ }
39860
+ [Symbol.asyncIterator]() {
39861
+ return this;
39862
+ }
39863
+ };
39864
+ var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
39865
+ __publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
39469
39866
 
39470
39867
  // src/providers/memory-cache.ts
39471
39868
  var cache = {};
@@ -39529,18 +39926,18 @@ ${MessageCoinFragmentFragmentDoc}`;
39529
39926
  const { type: type3 } = value;
39530
39927
  switch (value.type) {
39531
39928
  case InputType.Coin: {
39532
- const predicate = getBytesCopy(value.predicate ?? "0x");
39533
- const predicateData = getBytesCopy(value.predicateData ?? "0x");
39929
+ const predicate = arrayify(value.predicate ?? "0x");
39930
+ const predicateData = arrayify(value.predicateData ?? "0x");
39534
39931
  return {
39535
39932
  type: InputType.Coin,
39536
- txID: hexlify(getBytesCopy(value.id).slice(0, 32)),
39537
- outputIndex: getBytesCopy(value.id)[32],
39933
+ txID: hexlify(arrayify(value.id).slice(0, 32)),
39934
+ outputIndex: arrayify(value.id)[32],
39538
39935
  owner: hexlify(value.owner),
39539
39936
  amount: bn(value.amount),
39540
39937
  assetId: hexlify(value.assetId),
39541
39938
  txPointer: {
39542
- blockHeight: toNumber2(getBytesCopy(value.txPointer).slice(0, 8)),
39543
- txIndex: toNumber2(getBytesCopy(value.txPointer).slice(8, 16))
39939
+ blockHeight: toNumber2(arrayify(value.txPointer).slice(0, 8)),
39940
+ txIndex: toNumber2(arrayify(value.txPointer).slice(8, 16))
39544
39941
  },
39545
39942
  witnessIndex: value.witnessIndex,
39546
39943
  maturity: value.maturity ?? 0,
@@ -39559,16 +39956,16 @@ ${MessageCoinFragmentFragmentDoc}`;
39559
39956
  balanceRoot: ZeroBytes32,
39560
39957
  stateRoot: ZeroBytes32,
39561
39958
  txPointer: {
39562
- blockHeight: toNumber2(getBytesCopy(value.txPointer).slice(0, 8)),
39563
- txIndex: toNumber2(getBytesCopy(value.txPointer).slice(8, 16))
39959
+ blockHeight: toNumber2(arrayify(value.txPointer).slice(0, 8)),
39960
+ txIndex: toNumber2(arrayify(value.txPointer).slice(8, 16))
39564
39961
  },
39565
39962
  contractID: hexlify(value.contractId)
39566
39963
  };
39567
39964
  }
39568
39965
  case InputType.Message: {
39569
- const predicate = getBytesCopy(value.predicate ?? "0x");
39570
- const predicateData = getBytesCopy(value.predicateData ?? "0x");
39571
- const data = getBytesCopy(value.data ?? "0x");
39966
+ const predicate = arrayify(value.predicate ?? "0x");
39967
+ const predicateData = arrayify(value.predicateData ?? "0x");
39968
+ const data = arrayify(value.data ?? "0x");
39572
39969
  return {
39573
39970
  type: InputType.Message,
39574
39971
  sender: hexlify(value.sender),
@@ -39804,7 +40201,7 @@ ${MessageCoinFragmentFragmentDoc}`;
39804
40201
  const recipient = hexOrZero(receipt.recipient);
39805
40202
  const nonce = hexOrZero(receipt.nonce);
39806
40203
  const amount = bn(receipt.amount);
39807
- const data = receipt.data ? getBytesCopy(receipt.data) : Uint8Array.from([]);
40204
+ const data = receipt.data ? arrayify(receipt.data) : Uint8Array.from([]);
39808
40205
  const digest = hexOrZero(receipt.digest);
39809
40206
  const messageId = ReceiptMessageOutCoder.getMessageId({
39810
40207
  sender,
@@ -39946,9 +40343,7 @@ ${MessageCoinFragmentFragmentDoc}`;
39946
40343
  const totalGas = inputs.reduce((total, input) => {
39947
40344
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
39948
40345
  return total.add(
39949
- resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(
39950
- resolveGasDependentCosts(getBytesCopy(input.predicate).length, gasCosts.contractRoot)
39951
- ).add(bn(input.predicateGasUsed))
40346
+ resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts(arrayify(input.predicate).length, gasCosts.contractRoot)).add(bn(input.predicateGasUsed))
39952
40347
  );
39953
40348
  }
39954
40349
  if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
@@ -40062,7 +40457,7 @@ ${MessageCoinFragmentFragmentDoc}`;
40062
40457
 
40063
40458
  // src/providers/transaction-request/witness.ts
40064
40459
  var witnessify = (value) => {
40065
- const data = getBytesCopy(value);
40460
+ const data = arrayify(value);
40066
40461
  return {
40067
40462
  data: hexlify(data),
40068
40463
  dataLength: data.length
@@ -40534,19 +40929,27 @@ ${MessageCoinFragmentFragmentDoc}`;
40534
40929
  toJSON() {
40535
40930
  return normalizeJSON(this);
40536
40931
  }
40537
- /**
40538
- * @hidden
40539
- *
40540
- * Determines whether the transaction has a predicate input.
40541
- *
40542
- * @returns Whether the transaction has a predicate input.
40543
- */
40544
- hasPredicateInput() {
40545
- return Boolean(
40546
- this.inputs.find(
40547
- (input) => "predicate" in input && input.predicate && input.predicate !== getBytesCopy("0x")
40548
- )
40549
- );
40932
+ updatePredicateInputs(inputs) {
40933
+ this.inputs.forEach((i) => {
40934
+ let correspondingInput;
40935
+ switch (i.type) {
40936
+ case InputType.Coin:
40937
+ correspondingInput = inputs.find((x) => x.type === InputType.Coin && x.owner === i.owner);
40938
+ break;
40939
+ case InputType.Message:
40940
+ correspondingInput = inputs.find(
40941
+ (x) => x.type === InputType.Message && x.sender === i.sender
40942
+ );
40943
+ break;
40944
+ default:
40945
+ return;
40946
+ }
40947
+ if (correspondingInput && "predicateGasUsed" in correspondingInput && bn(correspondingInput.predicateGasUsed).gt(0)) {
40948
+ i.predicate = correspondingInput.predicate;
40949
+ i.predicateData = correspondingInput.predicateData;
40950
+ i.predicateGasUsed = correspondingInput.predicateGasUsed;
40951
+ }
40952
+ });
40550
40953
  }
40551
40954
  };
40552
40955
 
@@ -40633,7 +41036,7 @@ ${MessageCoinFragmentFragmentDoc}`;
40633
41036
  // src/providers/transaction-request/storage-slot.ts
40634
41037
  var getStorageValue = (value) => {
40635
41038
  const v = new Uint8Array(32);
40636
- v.set(getBytesCopy(value));
41039
+ v.set(arrayify(value));
40637
41040
  return v;
40638
41041
  };
40639
41042
  var storageSlotify = (storageSlot) => {
@@ -40738,7 +41141,7 @@ ${MessageCoinFragmentFragmentDoc}`;
40738
41141
  }
40739
41142
  metadataGas(gasCosts) {
40740
41143
  return calculateMetadataGasForTxCreate({
40741
- contractBytesSize: bn(getBytesCopy(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
41144
+ contractBytesSize: bn(arrayify(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
40742
41145
  gasCosts,
40743
41146
  stateRootSize: this.storageSlots.length,
40744
41147
  txBytesSize: this.byteSize()
@@ -40753,7 +41156,7 @@ ${MessageCoinFragmentFragmentDoc}`;
40753
41156
  Opcode::NOOP
40754
41157
  */
40755
41158
  // TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
40756
- bytes: getBytesCopy("0x24000000"),
41159
+ bytes: arrayify("0x24000000"),
40757
41160
  encodeScriptData: () => new Uint8Array(0)
40758
41161
  };
40759
41162
  var withdrawScript = {
@@ -40767,7 +41170,7 @@ ${MessageCoinFragmentFragmentDoc}`;
40767
41170
  00000000 00000000 [amount value]
40768
41171
  */
40769
41172
  // TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
40770
- bytes: getBytesCopy("0x5040C0105D44C0064C40001124000000"),
41173
+ bytes: arrayify("0x5040C0105D44C0064C40001124000000"),
40771
41174
  encodeScriptData: () => new Uint8Array(0)
40772
41175
  };
40773
41176
 
@@ -40795,8 +41198,8 @@ ${MessageCoinFragmentFragmentDoc}`;
40795
41198
  constructor({ script, scriptData, gasLimit, ...rest } = {}) {
40796
41199
  super(rest);
40797
41200
  this.gasLimit = bn(gasLimit);
40798
- this.script = getBytesCopy(script ?? returnZeroScript.bytes);
40799
- this.scriptData = getBytesCopy(scriptData ?? returnZeroScript.encodeScriptData());
41201
+ this.script = arrayify(script ?? returnZeroScript.bytes);
41202
+ this.scriptData = arrayify(scriptData ?? returnZeroScript.encodeScriptData());
40800
41203
  }
40801
41204
  /**
40802
41205
  * Converts the transaction request to a `TransactionScript`.
@@ -40804,8 +41207,8 @@ ${MessageCoinFragmentFragmentDoc}`;
40804
41207
  * @returns The transaction script object.
40805
41208
  */
40806
41209
  toTransaction() {
40807
- const script = getBytesCopy(this.script ?? "0x");
40808
- const scriptData = getBytesCopy(this.scriptData ?? "0x");
41210
+ const script = arrayify(this.script ?? "0x");
41211
+ const scriptData = arrayify(this.scriptData ?? "0x");
40809
41212
  return {
40810
41213
  type: TransactionType.Script,
40811
41214
  scriptGasLimit: this.gasLimit,
@@ -40968,7 +41371,7 @@ ${MessageCoinFragmentFragmentDoc}`;
40968
41371
  } = params;
40969
41372
  const gasPerByte = bn(feeParams.gasPerByte);
40970
41373
  const gasPriceFactor = bn(feeParams.gasPriceFactor);
40971
- const transactionBytes = getBytesCopy(rawPayload);
41374
+ const transactionBytes = arrayify(rawPayload);
40972
41375
  const [transaction] = new TransactionCoder().decode(transactionBytes, 0);
40973
41376
  if (transaction.type === TransactionType.Mint) {
40974
41377
  return {
@@ -40983,7 +41386,7 @@ ${MessageCoinFragmentFragmentDoc}`;
40983
41386
  let gasLimit = bn(0);
40984
41387
  if (type3 === TransactionType.Create) {
40985
41388
  const { bytecodeWitnessIndex, storageSlots } = transaction;
40986
- const contractBytesSize = bn(getBytesCopy(witnesses[bytecodeWitnessIndex].data).length);
41389
+ const contractBytesSize = bn(arrayify(witnesses[bytecodeWitnessIndex].data).length);
40987
41390
  metadataGas = calculateMetadataGasForTxCreate({
40988
41391
  contractBytesSize,
40989
41392
  gasCosts,
@@ -41172,7 +41575,6 @@ ${MessageCoinFragmentFragmentDoc}`;
41172
41575
  OperationName2["contractCreated"] = "Contract created";
41173
41576
  OperationName2["transfer"] = "Transfer asset";
41174
41577
  OperationName2["contractCall"] = "Contract call";
41175
- OperationName2["contractTransfer"] = "Contract transfer";
41176
41578
  OperationName2["receive"] = "Receive asset";
41177
41579
  OperationName2["mint"] = "Mint asset";
41178
41580
  OperationName2["predicatecall"] = "Predicate call";
@@ -41272,33 +41674,6 @@ ${MessageCoinFragmentFragmentDoc}`;
41272
41674
  function getReceiptsTransferOut(receipts) {
41273
41675
  return getReceiptsByType(receipts, ReceiptType.TransferOut);
41274
41676
  }
41275
- function getContractTransferOperations({ receipts }) {
41276
- const transferOutReceipts = getReceiptsTransferOut(receipts);
41277
- const contractTransferOperations = transferOutReceipts.reduce(
41278
- (prevContractTransferOps, receipt) => {
41279
- const newContractTransferOps = addOperation(prevContractTransferOps, {
41280
- name: "Contract transfer" /* contractTransfer */,
41281
- from: {
41282
- type: 0 /* contract */,
41283
- address: receipt.from
41284
- },
41285
- to: {
41286
- type: 1 /* account */,
41287
- address: receipt.to
41288
- },
41289
- assetsSent: [
41290
- {
41291
- amount: receipt.amount,
41292
- assetId: receipt.assetId
41293
- }
41294
- ]
41295
- });
41296
- return newContractTransferOps;
41297
- },
41298
- []
41299
- );
41300
- return contractTransferOperations;
41301
- }
41302
41677
  function getWithdrawFromFuelOperations({
41303
41678
  inputs,
41304
41679
  receipts
@@ -41396,70 +41771,77 @@ ${MessageCoinFragmentFragmentDoc}`;
41396
41771
  }, []);
41397
41772
  return contractCallOperations;
41398
41773
  }
41774
+ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
41775
+ const { to: toAddress, assetId, amount } = receipt;
41776
+ let { from: fromAddress } = receipt;
41777
+ const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
41778
+ if (ZeroBytes32 === fromAddress) {
41779
+ const change = changeOutputs.find((output4) => output4.assetId === assetId);
41780
+ fromAddress = change?.to || fromAddress;
41781
+ }
41782
+ const fromType = contractInputs.some((input) => input.contractID === fromAddress) ? 0 /* contract */ : 1 /* account */;
41783
+ return {
41784
+ name: "Transfer asset" /* transfer */,
41785
+ from: {
41786
+ type: fromType,
41787
+ address: fromAddress
41788
+ },
41789
+ to: {
41790
+ type: toType,
41791
+ address: toAddress
41792
+ },
41793
+ assetsSent: [
41794
+ {
41795
+ assetId: assetId.toString(),
41796
+ amount
41797
+ }
41798
+ ]
41799
+ };
41800
+ }
41399
41801
  function getTransferOperations({
41400
41802
  inputs,
41401
41803
  outputs,
41402
41804
  receipts
41403
41805
  }) {
41806
+ let operations = [];
41404
41807
  const coinOutputs = getOutputsCoin(outputs);
41405
- const [transferReceipt] = getReceiptsByType(
41808
+ const contractInputs = getInputsContract(inputs);
41809
+ const changeOutputs = getOutputsChange(outputs);
41810
+ coinOutputs.forEach((output4) => {
41811
+ const { amount, assetId, to } = output4;
41812
+ const changeOutput = changeOutputs.find((change) => change.assetId === assetId);
41813
+ if (changeOutput) {
41814
+ operations = addOperation(operations, {
41815
+ name: "Transfer asset" /* transfer */,
41816
+ from: {
41817
+ type: 1 /* account */,
41818
+ address: changeOutput.to
41819
+ },
41820
+ to: {
41821
+ type: 1 /* account */,
41822
+ address: to
41823
+ },
41824
+ assetsSent: [
41825
+ {
41826
+ assetId,
41827
+ amount
41828
+ }
41829
+ ]
41830
+ });
41831
+ }
41832
+ });
41833
+ const transferReceipts = getReceiptsByType(
41406
41834
  receipts,
41407
41835
  ReceiptType.Transfer
41408
41836
  );
41409
- let operations = [];
41410
- if (transferReceipt) {
41411
- const changeOutputs = getOutputsChange(outputs);
41412
- changeOutputs.forEach((output4) => {
41413
- const { assetId } = output4;
41414
- const [contractInput] = getInputsContract(inputs);
41415
- const utxo = getInputFromAssetId(inputs, assetId);
41416
- if (utxo && contractInput) {
41417
- const inputAddress = getInputAccountAddress(utxo);
41418
- operations = addOperation(operations, {
41419
- name: "Transfer asset" /* transfer */,
41420
- from: {
41421
- type: 1 /* account */,
41422
- address: inputAddress
41423
- },
41424
- to: {
41425
- type: 0 /* contract */,
41426
- address: contractInput.contractID
41427
- },
41428
- assetsSent: [
41429
- {
41430
- assetId: assetId.toString(),
41431
- amount: transferReceipt.amount
41432
- }
41433
- ]
41434
- });
41435
- }
41436
- });
41437
- } else {
41438
- coinOutputs.forEach((output4) => {
41439
- const input = getInputFromAssetId(inputs, output4.assetId);
41440
- if (input) {
41441
- const inputAddress = getInputAccountAddress(input);
41442
- const operationToAdd = {
41443
- name: "Transfer asset" /* transfer */,
41444
- from: {
41445
- type: 1 /* account */,
41446
- address: inputAddress
41447
- },
41448
- to: {
41449
- type: 1 /* account */,
41450
- address: output4.to.toString()
41451
- },
41452
- assetsSent: [
41453
- {
41454
- assetId: output4.assetId.toString(),
41455
- amount: output4.amount
41456
- }
41457
- ]
41458
- };
41459
- operations = addOperation(operations, operationToAdd);
41460
- }
41461
- });
41462
- }
41837
+ const transferOutReceipts = getReceiptsByType(
41838
+ receipts,
41839
+ ReceiptType.TransferOut
41840
+ );
41841
+ [...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
41842
+ const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
41843
+ operations = addOperation(operations, operation);
41844
+ });
41463
41845
  return operations;
41464
41846
  }
41465
41847
  function getPayProducerOperations(outputs) {
@@ -41532,7 +41914,6 @@ ${MessageCoinFragmentFragmentDoc}`;
41532
41914
  rawPayload,
41533
41915
  maxInputs
41534
41916
  }),
41535
- ...getContractTransferOperations({ receipts }),
41536
41917
  ...getWithdrawFromFuelOperations({ inputs, receipts })
41537
41918
  ];
41538
41919
  }
@@ -41776,7 +42157,7 @@ ${MessageCoinFragmentFragmentDoc}`;
41776
42157
  */
41777
42158
  decodeTransaction(transactionWithReceipts) {
41778
42159
  return new TransactionCoder().decode(
41779
- getBytesCopy(transactionWithReceipts.rawPayload),
42160
+ arrayify(transactionWithReceipts.rawPayload),
41780
42161
  0
41781
42162
  )?.[0];
41782
42163
  }
@@ -41802,7 +42183,7 @@ ${MessageCoinFragmentFragmentDoc}`;
41802
42183
  id: this.id,
41803
42184
  receipts,
41804
42185
  transaction: decodedTransaction,
41805
- transactionBytes: getBytesCopy(transaction.rawPayload),
42186
+ transactionBytes: arrayify(transaction.rawPayload),
41806
42187
  gqlTransactionStatus: transaction.status,
41807
42188
  gasPerByte,
41808
42189
  gasPriceFactor,
@@ -42101,7 +42482,7 @@ ${MessageCoinFragmentFragmentDoc}`;
42101
42482
  const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
42102
42483
  const isSubscription = opDefinition?.operation === "subscription";
42103
42484
  if (isSubscription) {
42104
- return fuelGraphQLSubscriber({
42485
+ return new FuelGraphqlSubscriber({
42105
42486
  url: this.url,
42106
42487
  query,
42107
42488
  fetchFn: (url, requestInit) => fetchFn(url, requestInit, this.options),
@@ -42234,7 +42615,7 @@ ${MessageCoinFragmentFragmentDoc}`;
42234
42615
  async call(transactionRequestLike, { utxoValidation, estimateTxDependencies = true } = {}) {
42235
42616
  const transactionRequest = transactionRequestify(transactionRequestLike);
42236
42617
  if (estimateTxDependencies) {
42237
- await this.estimateTxDependencies(transactionRequest);
42618
+ return this.estimateTxDependencies(transactionRequest);
42238
42619
  }
42239
42620
  const encodedTransaction = hexlify(transactionRequest.toTransactionBytes());
42240
42621
  const { dryRun: gqlReceipts } = await this.operations.dryRun({
@@ -42253,6 +42634,14 @@ ${MessageCoinFragmentFragmentDoc}`;
42253
42634
  * @returns A promise that resolves to the estimated transaction request object.
42254
42635
  */
42255
42636
  async estimatePredicates(transactionRequest) {
42637
+ const shouldEstimatePredicates = Boolean(
42638
+ transactionRequest.inputs.find(
42639
+ (input) => "predicate" in input && input.predicate && !equalBytes(arrayify(input.predicate), arrayify("0x")) && new BN(input.predicateGasUsed).isZero()
42640
+ )
42641
+ );
42642
+ if (!shouldEstimatePredicates) {
42643
+ return transactionRequest;
42644
+ }
42256
42645
  const encodedTransaction = hexlify(transactionRequest.toTransactionBytes());
42257
42646
  const response = await this.operations.estimatePredicates({
42258
42647
  encodedTransaction
@@ -42283,34 +42672,41 @@ ${MessageCoinFragmentFragmentDoc}`;
42283
42672
  * @returns A promise.
42284
42673
  */
42285
42674
  async estimateTxDependencies(transactionRequest) {
42286
- let missingOutputVariableCount = 0;
42287
- let missingOutputContractIdsCount = 0;
42288
- let tries = 0;
42289
42675
  if (transactionRequest.type === TransactionType.Create) {
42290
- return;
42291
- }
42292
- let txRequest = transactionRequest;
42293
- if (txRequest.hasPredicateInput()) {
42294
- txRequest = await this.estimatePredicates(txRequest);
42676
+ return {
42677
+ receipts: [],
42678
+ outputVariables: 0,
42679
+ missingContractIds: []
42680
+ };
42295
42681
  }
42296
- while (tries < MAX_RETRIES) {
42682
+ await this.estimatePredicates(transactionRequest);
42683
+ let receipts = [];
42684
+ const missingContractIds = [];
42685
+ let outputVariables = 0;
42686
+ for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
42297
42687
  const { dryRun: gqlReceipts } = await this.operations.dryRun({
42298
- encodedTransaction: hexlify(txRequest.toTransactionBytes()),
42688
+ encodedTransaction: hexlify(transactionRequest.toTransactionBytes()),
42299
42689
  utxoValidation: false
42300
42690
  });
42301
- const receipts = gqlReceipts.map(processGqlReceipt);
42691
+ receipts = gqlReceipts.map(processGqlReceipt);
42302
42692
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
42303
- missingOutputVariableCount = missingOutputVariables.length;
42304
- missingOutputContractIdsCount = missingOutputContractIds.length;
42305
- if (missingOutputVariableCount === 0 && missingOutputContractIdsCount === 0) {
42306
- return;
42693
+ const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
42694
+ if (hasMissingOutputs) {
42695
+ outputVariables += missingOutputVariables.length;
42696
+ transactionRequest.addVariableOutputs(missingOutputVariables.length);
42697
+ missingOutputContractIds.forEach(({ contractId }) => {
42698
+ transactionRequest.addContractInputAndOutput(Address.fromString(contractId));
42699
+ missingContractIds.push(contractId);
42700
+ });
42701
+ } else {
42702
+ break;
42307
42703
  }
42308
- txRequest.addVariableOutputs(missingOutputVariableCount);
42309
- missingOutputContractIds.forEach(
42310
- ({ contractId }) => txRequest.addContractInputAndOutput(Address.fromString(contractId))
42311
- );
42312
- tries += 1;
42313
42704
  }
42705
+ return {
42706
+ receipts,
42707
+ outputVariables,
42708
+ missingContractIds
42709
+ };
42314
42710
  }
42315
42711
  /**
42316
42712
  * Executes a signed transaction without applying the states changes
@@ -42325,7 +42721,7 @@ ${MessageCoinFragmentFragmentDoc}`;
42325
42721
  async simulate(transactionRequestLike, { estimateTxDependencies = true } = {}) {
42326
42722
  const transactionRequest = transactionRequestify(transactionRequestLike);
42327
42723
  if (estimateTxDependencies) {
42328
- await this.estimateTxDependencies(transactionRequest);
42724
+ return this.estimateTxDependencies(transactionRequest);
42329
42725
  }
42330
42726
  const encodedTransaction = hexlify(transactionRequest.toTransactionBytes());
42331
42727
  const { dryRun: gqlReceipts } = await this.operations.dryRun({
@@ -42357,35 +42753,37 @@ ${MessageCoinFragmentFragmentDoc}`;
42357
42753
  estimatePredicates = true,
42358
42754
  resourcesOwner
42359
42755
  } = {}) {
42360
- const transactionRequest = transactionRequestify(clone_default(transactionRequestLike));
42756
+ const txRequestClone = clone_default(transactionRequestify(transactionRequestLike));
42361
42757
  const chainInfo = this.getChain();
42362
42758
  const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
42363
- const gasPrice = max(transactionRequest.gasPrice, minGasPrice);
42364
- const isScriptTransaction = transactionRequest.type === TransactionType.Script;
42365
- if (transactionRequest.hasPredicateInput() && estimatePredicates) {
42759
+ const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
42760
+ const isScriptTransaction = txRequestClone.type === TransactionType.Script;
42761
+ const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
42762
+ const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
42763
+ txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
42764
+ if (estimatePredicates) {
42366
42765
  if (isScriptTransaction) {
42367
- transactionRequest.gasLimit = bn(0);
42766
+ txRequestClone.gasLimit = bn(0);
42767
+ }
42768
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
42769
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
42368
42770
  }
42369
- await this.estimatePredicates(transactionRequest);
42771
+ await this.estimatePredicates(txRequestClone);
42370
42772
  }
42371
- const minGas = transactionRequest.calculateMinGas(chainInfo);
42372
- const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
42373
- const coinOutputsQuantities = transactionRequest.getCoinOutputsQuantities();
42374
- const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
42375
- transactionRequest.fundWithFakeUtxos(allQuantities, resourcesOwner);
42376
- let gasUsed = minGas;
42773
+ const minGas = txRequestClone.calculateMinGas(chainInfo);
42774
+ const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
42377
42775
  let receipts = [];
42378
- if (isScriptTransaction) {
42379
- transactionRequest.gasPrice = bn(0);
42380
- transactionRequest.gasLimit = bn(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
42381
- const result = await this.call(transactionRequest, {
42382
- estimateTxDependencies
42383
- });
42776
+ let missingContractIds = [];
42777
+ let outputVariables = 0;
42778
+ if (isScriptTransaction && estimateTxDependencies) {
42779
+ txRequestClone.gasPrice = bn(0);
42780
+ txRequestClone.gasLimit = bn(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
42781
+ const result = await this.estimateTxDependencies(txRequestClone);
42384
42782
  receipts = result.receipts;
42385
- gasUsed = getGasUsedFromReceipts(receipts);
42386
- } else {
42387
- gasUsed = minGas;
42783
+ outputVariables = result.outputVariables;
42784
+ missingContractIds = result.missingContractIds;
42388
42785
  }
42786
+ const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
42389
42787
  const usedFee = calculatePriceWithFactor(
42390
42788
  gasUsed,
42391
42789
  gasPrice,
@@ -42403,7 +42801,10 @@ ${MessageCoinFragmentFragmentDoc}`;
42403
42801
  maxGas,
42404
42802
  usedFee,
42405
42803
  minFee,
42406
- maxFee
42804
+ maxFee,
42805
+ estimatedInputs: txRequestClone.inputs,
42806
+ outputVariables,
42807
+ missingContractIds
42407
42808
  };
42408
42809
  }
42409
42810
  async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
@@ -42571,7 +42972,7 @@ ${MessageCoinFragmentFragmentDoc}`;
42571
42972
  time: block2.header.time,
42572
42973
  transactionIds: block2.transactions.map((tx) => tx.id),
42573
42974
  transactions: block2.transactions.map(
42574
- (tx) => new TransactionCoder().decode(getBytesCopy(tx.rawPayload), 0)?.[0]
42975
+ (tx) => new TransactionCoder().decode(arrayify(tx.rawPayload), 0)?.[0]
42575
42976
  )
42576
42977
  };
42577
42978
  }
@@ -42587,7 +42988,7 @@ ${MessageCoinFragmentFragmentDoc}`;
42587
42988
  return null;
42588
42989
  }
42589
42990
  return new TransactionCoder().decode(
42590
- getBytesCopy(transaction.rawPayload),
42991
+ arrayify(transaction.rawPayload),
42591
42992
  0
42592
42993
  )?.[0];
42593
42994
  }
@@ -42826,7 +43227,7 @@ ${MessageCoinFragmentFragmentDoc}`;
42826
43227
  );
42827
43228
  }
42828
43229
  const [decodedTransaction] = new TransactionCoder().decode(
42829
- getBytesCopy(gqlTransaction.rawPayload),
43230
+ arrayify(gqlTransaction.rawPayload),
42830
43231
  0
42831
43232
  );
42832
43233
  const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
@@ -42837,7 +43238,7 @@ ${MessageCoinFragmentFragmentDoc}`;
42837
43238
  id: gqlTransaction.id,
42838
43239
  receipts,
42839
43240
  transaction: decodedTransaction,
42840
- transactionBytes: getBytesCopy(gqlTransaction.rawPayload),
43241
+ transactionBytes: arrayify(gqlTransaction.rawPayload),
42841
43242
  gqlTransactionStatus: gqlTransaction.status,
42842
43243
  gasPerByte: bn(gasPerByte),
42843
43244
  gasPriceFactor: bn(gasPriceFactor),
@@ -42879,13 +43280,13 @@ ${MessageCoinFragmentFragmentDoc}`;
42879
43280
  const transactions = edges.map((edge) => {
42880
43281
  const { node: gqlTransaction } = edge;
42881
43282
  const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
42882
- const [decodedTransaction] = new TransactionCoder().decode(getBytesCopy(rawPayload), 0);
43283
+ const [decodedTransaction] = new TransactionCoder().decode(arrayify(rawPayload), 0);
42883
43284
  const receipts = gqlReceipts?.map(processGqlReceipt) || [];
42884
43285
  const transactionSummary = assembleTransactionSummary({
42885
43286
  id,
42886
43287
  receipts,
42887
43288
  transaction: decodedTransaction,
42888
- transactionBytes: getBytesCopy(rawPayload),
43289
+ transactionBytes: arrayify(rawPayload),
42889
43290
  gqlTransactionStatus: status,
42890
43291
  abiMap,
42891
43292
  gasPerByte,
@@ -42905,6 +43306,127 @@ ${MessageCoinFragmentFragmentDoc}`;
42905
43306
  };
42906
43307
  }
42907
43308
 
43309
+ // src/providers/chains.ts
43310
+ var CHAIN_IDS = {
43311
+ eth: {
43312
+ sepolia: 11155111,
43313
+ foundry: 31337
43314
+ },
43315
+ fuel: {
43316
+ beta5: 0,
43317
+ devnet: 10
43318
+ }
43319
+ };
43320
+
43321
+ // src/providers/assets/utils/network.ts
43322
+ var getDefaultChainId = (networkType) => {
43323
+ if (networkType === "ethereum") {
43324
+ return CHAIN_IDS.eth.sepolia;
43325
+ }
43326
+ if (networkType === "fuel") {
43327
+ return CHAIN_IDS.fuel.beta5;
43328
+ }
43329
+ return void 0;
43330
+ };
43331
+ var getAssetNetwork = ({
43332
+ asset,
43333
+ chainId,
43334
+ networkType
43335
+ }) => {
43336
+ const network = asset.networks.find(
43337
+ (item) => item.chainId === chainId && item.type === networkType
43338
+ );
43339
+ return network;
43340
+ };
43341
+ var getAssetWithNetwork = ({
43342
+ asset,
43343
+ chainId,
43344
+ networkType
43345
+ }) => {
43346
+ const { networks: _, ...assetRest } = asset;
43347
+ const chainIdToUse = chainId ?? getDefaultChainId(networkType);
43348
+ if (chainIdToUse === void 0) {
43349
+ return void 0;
43350
+ }
43351
+ const assetNetwork = getAssetNetwork({
43352
+ asset,
43353
+ chainId: chainIdToUse,
43354
+ networkType
43355
+ });
43356
+ if (!assetNetwork) {
43357
+ return void 0;
43358
+ }
43359
+ return {
43360
+ ...assetRest,
43361
+ ...assetNetwork
43362
+ };
43363
+ };
43364
+ var getAssetEth = (asset, chainId) => getAssetWithNetwork({
43365
+ asset,
43366
+ networkType: "ethereum",
43367
+ chainId
43368
+ });
43369
+ var getAssetFuel = (asset, chainId) => getAssetWithNetwork({
43370
+ asset,
43371
+ networkType: "fuel",
43372
+ chainId
43373
+ });
43374
+
43375
+ // src/providers/assets/utils/url.ts
43376
+ var DELIMITER_PATH = "/";
43377
+ var trimRegex = /^\/|\/$/g;
43378
+ var trimPath = (path = "") => path.replace(trimRegex, "");
43379
+ function urlJoin(baseUrl, ...paths) {
43380
+ const hasBaseUrl = baseUrl !== null && baseUrl !== void 0;
43381
+ const rootPath = baseUrl?.[0] === "/" && baseUrl.length > 1;
43382
+ const allPaths = [baseUrl, ...paths].filter(Boolean).map(trimPath);
43383
+ if (rootPath && hasBaseUrl) {
43384
+ allPaths.unshift("");
43385
+ }
43386
+ return allPaths.join(DELIMITER_PATH);
43387
+ }
43388
+
43389
+ // src/providers/assets/utils/resolveIconPaths.ts
43390
+ function resolveIconPaths(assets2, basePath = "./") {
43391
+ return assets2.map((asset) => ({
43392
+ ...asset,
43393
+ icon: urlJoin(basePath, asset.icon)
43394
+ }));
43395
+ }
43396
+
43397
+ // src/providers/assets/index.ts
43398
+ var assets = [
43399
+ {
43400
+ name: "Ethereum",
43401
+ symbol: "ETH",
43402
+ icon: "eth.svg",
43403
+ networks: [
43404
+ {
43405
+ type: "ethereum",
43406
+ chainId: CHAIN_IDS.eth.sepolia,
43407
+ decimals: 18
43408
+ },
43409
+ {
43410
+ type: "ethereum",
43411
+ chainId: CHAIN_IDS.eth.foundry,
43412
+ decimals: 18
43413
+ },
43414
+ {
43415
+ type: "fuel",
43416
+ chainId: CHAIN_IDS.fuel.beta5,
43417
+ decimals: 9,
43418
+ assetId: "0x0000000000000000000000000000000000000000000000000000000000000000"
43419
+ },
43420
+ {
43421
+ type: "fuel",
43422
+ chainId: CHAIN_IDS.fuel.devnet,
43423
+ decimals: 9,
43424
+ assetId: "0x0000000000000000000000000000000000000000000000000000000000000000"
43425
+ }
43426
+ ]
43427
+ }
43428
+ ];
43429
+
42908
43430
  // src/utils/formatTransferToContractScriptData.ts
42909
43431
  var asm = __toESM(require_node());
42910
43432
  var formatTransferToContractScriptData = (params) => {
@@ -42912,9 +43434,9 @@ ${MessageCoinFragmentFragmentDoc}`;
42912
43434
  const numberCoder = new U64Coder();
42913
43435
  const encoded = numberCoder.encode(new BN(amountToTransfer).toNumber());
42914
43436
  const scriptData = Uint8Array.from([
42915
- ...getBytesCopy(hexlifiedContractId),
43437
+ ...arrayify(hexlifiedContractId),
42916
43438
  ...encoded,
42917
- ...getBytesCopy(assetId)
43439
+ ...arrayify(assetId)
42918
43440
  ]);
42919
43441
  return scriptData;
42920
43442
  };
@@ -43164,7 +43686,10 @@ ${MessageCoinFragmentFragmentDoc}`;
43164
43686
  const params = { gasPrice: minGasPrice, ...txParams };
43165
43687
  const request = new ScriptTransactionRequest(params);
43166
43688
  request.addCoinOutput(Address.fromAddressOrString(destination), amount, assetId);
43167
- const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(request);
43689
+ const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
43690
+ estimateTxDependencies: true,
43691
+ resourcesOwner: this
43692
+ });
43168
43693
  request.gasPrice = bn(txParams.gasPrice ?? minGasPrice);
43169
43694
  request.gasLimit = bn(txParams.gasLimit ?? gasUsed);
43170
43695
  this.validateGas({
@@ -43174,6 +43699,7 @@ ${MessageCoinFragmentFragmentDoc}`;
43174
43699
  minGasPrice
43175
43700
  });
43176
43701
  await this.fund(request, requiredQuantities, maxFee);
43702
+ request.updatePredicateInputs(estimatedInputs);
43177
43703
  return request;
43178
43704
  }
43179
43705
  /**
@@ -43187,7 +43713,7 @@ ${MessageCoinFragmentFragmentDoc}`;
43187
43713
  */
43188
43714
  async transfer(destination, amount, assetId = BaseAssetId, txParams = {}) {
43189
43715
  const request = await this.createTransfer(destination, amount, assetId, txParams);
43190
- return this.sendTransaction(request);
43716
+ return this.sendTransaction(request, { estimateTxDependencies: false });
43191
43717
  }
43192
43718
  /**
43193
43719
  * Transfers coins to a contract address.
@@ -43238,14 +43764,14 @@ ${MessageCoinFragmentFragmentDoc}`;
43238
43764
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
43239
43765
  const { minGasPrice } = this.provider.getGasConfig();
43240
43766
  const recipientAddress = Address.fromAddressOrString(recipient);
43241
- const recipientDataArray = getBytesCopy(
43767
+ const recipientDataArray = arrayify(
43242
43768
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
43243
43769
  );
43244
- const amountDataArray = getBytesCopy(
43770
+ const amountDataArray = arrayify(
43245
43771
  "0x".concat(bn(amount).toHex().substring(2).padStart(16, "0"))
43246
43772
  );
43247
43773
  const script = new Uint8Array([
43248
- ...getBytesCopy(withdrawScript.bytes),
43774
+ ...arrayify(withdrawScript.bytes),
43249
43775
  ...recipientDataArray,
43250
43776
  ...amountDataArray
43251
43777
  ]);
@@ -43278,16 +43804,18 @@ ${MessageCoinFragmentFragmentDoc}`;
43278
43804
  * @param transactionRequestLike - The transaction request to be sent.
43279
43805
  * @returns A promise that resolves to the transaction response.
43280
43806
  */
43281
- async sendTransaction(transactionRequestLike, options) {
43807
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
43282
43808
  if (this._connector) {
43283
43809
  return this.provider.getTransactionResponse(
43284
43810
  await this._connector.sendTransaction(this.address.toString(), transactionRequestLike)
43285
43811
  );
43286
43812
  }
43287
43813
  const transactionRequest = transactionRequestify(transactionRequestLike);
43288
- await this.provider.estimateTxDependencies(transactionRequest);
43814
+ if (estimateTxDependencies) {
43815
+ await this.provider.estimateTxDependencies(transactionRequest);
43816
+ }
43289
43817
  return this.provider.sendTransaction(transactionRequest, {
43290
- ...options,
43818
+ awaitExecution,
43291
43819
  estimateTxDependencies: false
43292
43820
  });
43293
43821
  }
@@ -43297,9 +43825,11 @@ ${MessageCoinFragmentFragmentDoc}`;
43297
43825
  * @param transactionRequestLike - The transaction request to be simulated.
43298
43826
  * @returns A promise that resolves to the call result.
43299
43827
  */
43300
- async simulateTransaction(transactionRequestLike) {
43828
+ async simulateTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
43301
43829
  const transactionRequest = transactionRequestify(transactionRequestLike);
43302
- await this.provider.estimateTxDependencies(transactionRequest);
43830
+ if (estimateTxDependencies) {
43831
+ await this.provider.estimateTxDependencies(transactionRequest);
43832
+ }
43303
43833
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
43304
43834
  }
43305
43835
  validateGas({
@@ -43328,11 +43858,11 @@ ${MessageCoinFragmentFragmentDoc}`;
43328
43858
  if (!Number.isSafeInteger(n) || n < 0)
43329
43859
  throw new Error(`Wrong positive integer: ${n}`);
43330
43860
  }
43331
- function isBytes(a) {
43861
+ function isBytes2(a) {
43332
43862
  return a instanceof Uint8Array || a != null && typeof a === "object" && a.constructor.name === "Uint8Array";
43333
43863
  }
43334
43864
  function bytes3(b, ...lengths) {
43335
- if (!isBytes(b))
43865
+ if (!isBytes2(b))
43336
43866
  throw new Error("Expected Uint8Array");
43337
43867
  if (lengths.length > 0 && !lengths.includes(b.length))
43338
43868
  throw new Error(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`);
@@ -43362,7 +43892,7 @@ ${MessageCoinFragmentFragmentDoc}`;
43362
43892
  var crypto5 = nc2 && typeof nc2 === "object" && "webcrypto" in nc2 ? nc2.webcrypto : void 0;
43363
43893
 
43364
43894
  // ../../node_modules/.pnpm/@noble+hashes@1.3.3/node_modules/@noble/hashes/esm/utils.js
43365
- function isBytes2(a) {
43895
+ function isBytes3(a) {
43366
43896
  return a instanceof Uint8Array || a != null && typeof a === "object" && a.constructor.name === "Uint8Array";
43367
43897
  }
43368
43898
  var createView3 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
@@ -43370,23 +43900,23 @@ ${MessageCoinFragmentFragmentDoc}`;
43370
43900
  var isLE3 = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
43371
43901
  if (!isLE3)
43372
43902
  throw new Error("Non little-endian hardware is not supported");
43373
- function utf8ToBytes3(str) {
43903
+ function utf8ToBytes4(str) {
43374
43904
  if (typeof str !== "string")
43375
43905
  throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
43376
43906
  return new Uint8Array(new TextEncoder().encode(str));
43377
43907
  }
43378
43908
  function toBytes4(data) {
43379
43909
  if (typeof data === "string")
43380
- data = utf8ToBytes3(data);
43381
- if (!isBytes2(data))
43910
+ data = utf8ToBytes4(data);
43911
+ if (!isBytes3(data))
43382
43912
  throw new Error(`expected Uint8Array, got ${typeof data}`);
43383
43913
  return data;
43384
43914
  }
43385
- function concatBytes3(...arrays) {
43915
+ function concatBytes4(...arrays) {
43386
43916
  let sum = 0;
43387
43917
  for (let i = 0; i < arrays.length; i++) {
43388
43918
  const a = arrays[i];
43389
- if (!isBytes2(a))
43919
+ if (!isBytes3(a))
43390
43920
  throw new Error("Uint8Array expected");
43391
43921
  sum += a.length;
43392
43922
  }
@@ -43672,242 +44202,6 @@ ${MessageCoinFragmentFragmentDoc}`;
43672
44202
  };
43673
44203
  var sha2563 = /* @__PURE__ */ wrapConstructor3(() => new SHA2562());
43674
44204
 
43675
- // ../../node_modules/.pnpm/@noble+curves@1.3.0/node_modules/@noble/curves/esm/abstract/utils.js
43676
- var utils_exports = {};
43677
- __export(utils_exports, {
43678
- bitGet: () => bitGet,
43679
- bitLen: () => bitLen,
43680
- bitMask: () => bitMask,
43681
- bitSet: () => bitSet,
43682
- bytesToHex: () => bytesToHex2,
43683
- bytesToNumberBE: () => bytesToNumberBE,
43684
- bytesToNumberLE: () => bytesToNumberLE,
43685
- concatBytes: () => concatBytes4,
43686
- createHmacDrbg: () => createHmacDrbg,
43687
- ensureBytes: () => ensureBytes,
43688
- equalBytes: () => equalBytes,
43689
- hexToBytes: () => hexToBytes2,
43690
- hexToNumber: () => hexToNumber,
43691
- isBytes: () => isBytes3,
43692
- numberToBytesBE: () => numberToBytesBE,
43693
- numberToBytesLE: () => numberToBytesLE,
43694
- numberToHexUnpadded: () => numberToHexUnpadded,
43695
- numberToVarBytesBE: () => numberToVarBytesBE,
43696
- utf8ToBytes: () => utf8ToBytes4,
43697
- validateObject: () => validateObject
43698
- });
43699
- var _0n3 = BigInt(0);
43700
- var _1n3 = BigInt(1);
43701
- var _2n3 = BigInt(2);
43702
- function isBytes3(a) {
43703
- return a instanceof Uint8Array || a != null && typeof a === "object" && a.constructor.name === "Uint8Array";
43704
- }
43705
- var hexes3 = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
43706
- function bytesToHex2(bytes4) {
43707
- if (!isBytes3(bytes4))
43708
- throw new Error("Uint8Array expected");
43709
- let hex = "";
43710
- for (let i = 0; i < bytes4.length; i++) {
43711
- hex += hexes3[bytes4[i]];
43712
- }
43713
- return hex;
43714
- }
43715
- function numberToHexUnpadded(num) {
43716
- const hex = num.toString(16);
43717
- return hex.length & 1 ? `0${hex}` : hex;
43718
- }
43719
- function hexToNumber(hex) {
43720
- if (typeof hex !== "string")
43721
- throw new Error("hex string expected, got " + typeof hex);
43722
- return BigInt(hex === "" ? "0" : `0x${hex}`);
43723
- }
43724
- var asciis = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 };
43725
- function asciiToBase16(char) {
43726
- if (char >= asciis._0 && char <= asciis._9)
43727
- return char - asciis._0;
43728
- if (char >= asciis._A && char <= asciis._F)
43729
- return char - (asciis._A - 10);
43730
- if (char >= asciis._a && char <= asciis._f)
43731
- return char - (asciis._a - 10);
43732
- return;
43733
- }
43734
- function hexToBytes2(hex) {
43735
- if (typeof hex !== "string")
43736
- throw new Error("hex string expected, got " + typeof hex);
43737
- const hl = hex.length;
43738
- const al = hl / 2;
43739
- if (hl % 2)
43740
- throw new Error("padded hex string expected, got unpadded hex of length " + hl);
43741
- const array = new Uint8Array(al);
43742
- for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
43743
- const n1 = asciiToBase16(hex.charCodeAt(hi));
43744
- const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
43745
- if (n1 === void 0 || n2 === void 0) {
43746
- const char = hex[hi] + hex[hi + 1];
43747
- throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
43748
- }
43749
- array[ai] = n1 * 16 + n2;
43750
- }
43751
- return array;
43752
- }
43753
- function bytesToNumberBE(bytes4) {
43754
- return hexToNumber(bytesToHex2(bytes4));
43755
- }
43756
- function bytesToNumberLE(bytes4) {
43757
- if (!isBytes3(bytes4))
43758
- throw new Error("Uint8Array expected");
43759
- return hexToNumber(bytesToHex2(Uint8Array.from(bytes4).reverse()));
43760
- }
43761
- function numberToBytesBE(n, len) {
43762
- return hexToBytes2(n.toString(16).padStart(len * 2, "0"));
43763
- }
43764
- function numberToBytesLE(n, len) {
43765
- return numberToBytesBE(n, len).reverse();
43766
- }
43767
- function numberToVarBytesBE(n) {
43768
- return hexToBytes2(numberToHexUnpadded(n));
43769
- }
43770
- function ensureBytes(title, hex, expectedLength) {
43771
- let res;
43772
- if (typeof hex === "string") {
43773
- try {
43774
- res = hexToBytes2(hex);
43775
- } catch (e) {
43776
- throw new Error(`${title} must be valid hex string, got "${hex}". Cause: ${e}`);
43777
- }
43778
- } else if (isBytes3(hex)) {
43779
- res = Uint8Array.from(hex);
43780
- } else {
43781
- throw new Error(`${title} must be hex string or Uint8Array`);
43782
- }
43783
- const len = res.length;
43784
- if (typeof expectedLength === "number" && len !== expectedLength)
43785
- throw new Error(`${title} expected ${expectedLength} bytes, got ${len}`);
43786
- return res;
43787
- }
43788
- function concatBytes4(...arrays) {
43789
- let sum = 0;
43790
- for (let i = 0; i < arrays.length; i++) {
43791
- const a = arrays[i];
43792
- if (!isBytes3(a))
43793
- throw new Error("Uint8Array expected");
43794
- sum += a.length;
43795
- }
43796
- let res = new Uint8Array(sum);
43797
- let pad3 = 0;
43798
- for (let i = 0; i < arrays.length; i++) {
43799
- const a = arrays[i];
43800
- res.set(a, pad3);
43801
- pad3 += a.length;
43802
- }
43803
- return res;
43804
- }
43805
- function equalBytes(a, b) {
43806
- if (a.length !== b.length)
43807
- return false;
43808
- let diff = 0;
43809
- for (let i = 0; i < a.length; i++)
43810
- diff |= a[i] ^ b[i];
43811
- return diff === 0;
43812
- }
43813
- function utf8ToBytes4(str) {
43814
- if (typeof str !== "string")
43815
- throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
43816
- return new Uint8Array(new TextEncoder().encode(str));
43817
- }
43818
- function bitLen(n) {
43819
- let len;
43820
- for (len = 0; n > _0n3; n >>= _1n3, len += 1)
43821
- ;
43822
- return len;
43823
- }
43824
- function bitGet(n, pos) {
43825
- return n >> BigInt(pos) & _1n3;
43826
- }
43827
- var bitSet = (n, pos, value) => {
43828
- return n | (value ? _1n3 : _0n3) << BigInt(pos);
43829
- };
43830
- var bitMask = (n) => (_2n3 << BigInt(n - 1)) - _1n3;
43831
- var u8n = (data) => new Uint8Array(data);
43832
- var u8fr = (arr) => Uint8Array.from(arr);
43833
- function createHmacDrbg(hashLen, qByteLen, hmacFn) {
43834
- if (typeof hashLen !== "number" || hashLen < 2)
43835
- throw new Error("hashLen must be a number");
43836
- if (typeof qByteLen !== "number" || qByteLen < 2)
43837
- throw new Error("qByteLen must be a number");
43838
- if (typeof hmacFn !== "function")
43839
- throw new Error("hmacFn must be a function");
43840
- let v = u8n(hashLen);
43841
- let k = u8n(hashLen);
43842
- let i = 0;
43843
- const reset = () => {
43844
- v.fill(1);
43845
- k.fill(0);
43846
- i = 0;
43847
- };
43848
- const h = (...b) => hmacFn(k, v, ...b);
43849
- const reseed = (seed = u8n()) => {
43850
- k = h(u8fr([0]), seed);
43851
- v = h();
43852
- if (seed.length === 0)
43853
- return;
43854
- k = h(u8fr([1]), seed);
43855
- v = h();
43856
- };
43857
- const gen3 = () => {
43858
- if (i++ >= 1e3)
43859
- throw new Error("drbg: tried 1000 values");
43860
- let len = 0;
43861
- const out = [];
43862
- while (len < qByteLen) {
43863
- v = h();
43864
- const sl = v.slice();
43865
- out.push(sl);
43866
- len += v.length;
43867
- }
43868
- return concatBytes4(...out);
43869
- };
43870
- const genUntil = (seed, pred) => {
43871
- reset();
43872
- reseed(seed);
43873
- let res = void 0;
43874
- while (!(res = pred(gen3())))
43875
- reseed();
43876
- reset();
43877
- return res;
43878
- };
43879
- return genUntil;
43880
- }
43881
- var validatorFns = {
43882
- bigint: (val) => typeof val === "bigint",
43883
- function: (val) => typeof val === "function",
43884
- boolean: (val) => typeof val === "boolean",
43885
- string: (val) => typeof val === "string",
43886
- stringOrUint8Array: (val) => typeof val === "string" || isBytes3(val),
43887
- isSafeInteger: (val) => Number.isSafeInteger(val),
43888
- array: (val) => Array.isArray(val),
43889
- field: (val, object) => object.Fp.isValid(val),
43890
- hash: (val) => typeof val === "function" && Number.isSafeInteger(val.outputLen)
43891
- };
43892
- function validateObject(object, validators, optValidators = {}) {
43893
- const checkField = (fieldName, type3, isOptional) => {
43894
- const checkVal = validatorFns[type3];
43895
- if (typeof checkVal !== "function")
43896
- throw new Error(`Invalid validator "${type3}", expected function`);
43897
- const val = object[fieldName];
43898
- if (isOptional && val === void 0)
43899
- return;
43900
- if (!checkVal(val, object)) {
43901
- throw new Error(`Invalid param ${String(fieldName)}=${val} (${typeof val}), expected ${type3}`);
43902
- }
43903
- };
43904
- for (const [fieldName, type3] of Object.entries(validators))
43905
- checkField(fieldName, type3, false);
43906
- for (const [fieldName, type3] of Object.entries(optValidators))
43907
- checkField(fieldName, type3, true);
43908
- return object;
43909
- }
43910
-
43911
44205
  // ../../node_modules/.pnpm/@noble+curves@1.3.0/node_modules/@noble/curves/esm/abstract/modular.js
43912
44206
  var _0n4 = BigInt(0);
43913
44207
  var _1n4 = BigInt(1);
@@ -44343,7 +44637,7 @@ ${MessageCoinFragmentFragmentDoc}`;
44343
44637
  toSig(hex) {
44344
44638
  const { Err: E } = DER;
44345
44639
  const data = typeof hex === "string" ? h2b(hex) : hex;
44346
- if (!isBytes3(data))
44640
+ if (!isBytes(data))
44347
44641
  throw new Error("ui8a expected");
44348
44642
  let l = data.length;
44349
44643
  if (l < 2 || data[0] != 48)
@@ -44381,7 +44675,7 @@ ${MessageCoinFragmentFragmentDoc}`;
44381
44675
  const { Fp: Fp2 } = CURVE;
44382
44676
  const toBytes5 = CURVE.toBytes || ((_c, point, _isCompressed) => {
44383
44677
  const a = point.toAffine();
44384
- return concatBytes4(Uint8Array.from([4]), Fp2.toBytes(a.x), Fp2.toBytes(a.y));
44678
+ return concatBytes3(Uint8Array.from([4]), Fp2.toBytes(a.x), Fp2.toBytes(a.y));
44385
44679
  });
44386
44680
  const fromBytes = CURVE.fromBytes || ((bytes4) => {
44387
44681
  const tail = bytes4.subarray(1);
@@ -44407,7 +44701,7 @@ ${MessageCoinFragmentFragmentDoc}`;
44407
44701
  function normPrivateKeyToScalar(key) {
44408
44702
  const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n } = CURVE;
44409
44703
  if (lengths && typeof key !== "bigint") {
44410
- if (isBytes3(key))
44704
+ if (isBytes(key))
44411
44705
  key = bytesToHex2(key);
44412
44706
  if (typeof key !== "string" || !lengths.includes(key.length))
44413
44707
  throw new Error("Invalid key");
@@ -44797,7 +45091,7 @@ ${MessageCoinFragmentFragmentDoc}`;
44797
45091
  toBytes(_c, point, isCompressed) {
44798
45092
  const a = point.toAffine();
44799
45093
  const x = Fp2.toBytes(a.x);
44800
- const cat = concatBytes4;
45094
+ const cat = concatBytes3;
44801
45095
  if (isCompressed) {
44802
45096
  return cat(Uint8Array.from([point.hasEvenY() ? 2 : 3]), x);
44803
45097
  } else {
@@ -44942,7 +45236,7 @@ ${MessageCoinFragmentFragmentDoc}`;
44942
45236
  return Point2.fromPrivateKey(privateKey).toRawBytes(isCompressed);
44943
45237
  }
44944
45238
  function isProbPub(item) {
44945
- const arr = isBytes3(item);
45239
+ const arr = isBytes(item);
44946
45240
  const str = typeof item === "string";
44947
45241
  const len = (arr || str) && item.length;
44948
45242
  if (arr)
@@ -44994,7 +45288,7 @@ ${MessageCoinFragmentFragmentDoc}`;
44994
45288
  const e = ent === true ? randomBytes5(Fp2.BYTES) : ent;
44995
45289
  seedArgs.push(ensureBytes("extraEntropy", e));
44996
45290
  }
44997
- const seed = concatBytes4(...seedArgs);
45291
+ const seed = concatBytes3(...seedArgs);
44998
45292
  const m = h1int;
44999
45293
  function k2sig(kBytes) {
45000
45294
  const k = bits2int(kBytes);
@@ -45037,7 +45331,7 @@ ${MessageCoinFragmentFragmentDoc}`;
45037
45331
  let _sig = void 0;
45038
45332
  let P;
45039
45333
  try {
45040
- if (typeof sg === "string" || isBytes3(sg)) {
45334
+ if (typeof sg === "string" || isBytes(sg)) {
45041
45335
  try {
45042
45336
  _sig = Signature2.fromDER(sg);
45043
45337
  } catch (derError) {
@@ -45153,7 +45447,7 @@ ${MessageCoinFragmentFragmentDoc}`;
45153
45447
  function getHash(hash6) {
45154
45448
  return {
45155
45449
  hash: hash6,
45156
- hmac: (key, ...msgs) => hmac2(hash6, key, concatBytes3(...msgs)),
45450
+ hmac: (key, ...msgs) => hmac2(hash6, key, concatBytes4(...msgs)),
45157
45451
  randomBytes: randomBytes4
45158
45452
  };
45159
45453
  }
@@ -45277,11 +45571,11 @@ ${MessageCoinFragmentFragmentDoc}`;
45277
45571
  * @returns hashed signature
45278
45572
  */
45279
45573
  sign(data) {
45280
- const signature = secp256k1.sign(getBytesCopy(data), getBytesCopy(this.privateKey));
45574
+ const signature = secp256k1.sign(arrayify(data), arrayify(this.privateKey));
45281
45575
  const r = toBytes3(`0x${signature.r.toString(16)}`, 32);
45282
45576
  const s = toBytes3(`0x${signature.s.toString(16)}`, 32);
45283
45577
  s[0] |= (signature.recovery || 0) << 7;
45284
- return concat([r, s]);
45578
+ return hexlify(concat([r, s]));
45285
45579
  }
45286
45580
  /**
45287
45581
  * Add point on the current elliptic curve
@@ -45290,8 +45584,8 @@ ${MessageCoinFragmentFragmentDoc}`;
45290
45584
  * @returns compressed point on the curve
45291
45585
  */
45292
45586
  addPoint(point) {
45293
- const p0 = secp256k1.ProjectivePoint.fromHex(getBytesCopy(this.compressedPublicKey));
45294
- const p1 = secp256k1.ProjectivePoint.fromHex(getBytesCopy(point));
45587
+ const p0 = secp256k1.ProjectivePoint.fromHex(arrayify(this.compressedPublicKey));
45588
+ const p1 = secp256k1.ProjectivePoint.fromHex(arrayify(point));
45295
45589
  const result = p0.add(p1);
45296
45590
  return `0x${result.toHex(true)}`;
45297
45591
  }
@@ -45303,7 +45597,7 @@ ${MessageCoinFragmentFragmentDoc}`;
45303
45597
  * @returns public key from signature from the
45304
45598
  */
45305
45599
  static recoverPublicKey(data, signature) {
45306
- const signedMessageBytes = getBytesCopy(signature);
45600
+ const signedMessageBytes = arrayify(signature);
45307
45601
  const r = signedMessageBytes.slice(0, 32);
45308
45602
  const s = signedMessageBytes.slice(32, 64);
45309
45603
  const recoveryParam = (s[0] & 128) >> 7;
@@ -45311,7 +45605,7 @@ ${MessageCoinFragmentFragmentDoc}`;
45311
45605
  const sig = new secp256k1.Signature(BigInt(hexlify(r)), BigInt(hexlify(s))).addRecoveryBit(
45312
45606
  recoveryParam
45313
45607
  );
45314
- const publicKey = sig.recoverPublicKey(getBytesCopy(data)).toRawBytes(false).slice(1);
45608
+ const publicKey = sig.recoverPublicKey(arrayify(data)).toRawBytes(false).slice(1);
45315
45609
  return hexlify(publicKey);
45316
45610
  }
45317
45611
  /**
@@ -45331,7 +45625,7 @@ ${MessageCoinFragmentFragmentDoc}`;
45331
45625
  * @returns random 32-byte hashed
45332
45626
  */
45333
45627
  static generatePrivateKey(entropy) {
45334
- return entropy ? hash3(concat([randomBytes22(32), getBytesCopy(entropy)])) : randomBytes22(32);
45628
+ return entropy ? hash3(concat([randomBytes22(32), arrayify(entropy)])) : randomBytes22(32);
45335
45629
  }
45336
45630
  /**
45337
45631
  * Extended publicKey from a compact publicKey
@@ -45340,7 +45634,7 @@ ${MessageCoinFragmentFragmentDoc}`;
45340
45634
  * @returns extended publicKey
45341
45635
  */
45342
45636
  static extendPublicKey(publicKey) {
45343
- const point = secp256k1.ProjectivePoint.fromHex(getBytesCopy(publicKey));
45637
+ const point = secp256k1.ProjectivePoint.fromHex(arrayify(publicKey));
45344
45638
  return hexlify(point.toRawBytes(false).slice(1));
45345
45639
  }
45346
45640
  };
@@ -45519,7 +45813,7 @@ ${MessageCoinFragmentFragmentDoc}`;
45519
45813
  */
45520
45814
  async signMessage(message) {
45521
45815
  const signedMessage = await this.signer().sign(hashMessage(message));
45522
- return signedMessage;
45816
+ return hexlify(signedMessage);
45523
45817
  }
45524
45818
  /**
45525
45819
  * Signs a transaction with the wallet's private key.
@@ -45532,7 +45826,7 @@ ${MessageCoinFragmentFragmentDoc}`;
45532
45826
  const chainId = this.provider.getChain().consensusParameters.chainId.toNumber();
45533
45827
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
45534
45828
  const signature = await this.signer().sign(hashedTransaction);
45535
- return signature;
45829
+ return hexlify(signature);
45536
45830
  }
45537
45831
  /**
45538
45832
  * Populates a transaction with the witnesses signature.
@@ -45552,12 +45846,14 @@ ${MessageCoinFragmentFragmentDoc}`;
45552
45846
  * @param transactionRequestLike - The transaction request to send.
45553
45847
  * @returns A promise that resolves to the TransactionResponse object.
45554
45848
  */
45555
- async sendTransaction(transactionRequestLike, options) {
45849
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
45556
45850
  const transactionRequest = transactionRequestify(transactionRequestLike);
45557
- await this.provider.estimateTxDependencies(transactionRequest);
45851
+ if (estimateTxDependencies) {
45852
+ await this.provider.estimateTxDependencies(transactionRequest);
45853
+ }
45558
45854
  return this.provider.sendTransaction(
45559
45855
  await this.populateTransactionWitnessesSignature(transactionRequest),
45560
- { ...options, estimateTxDependencies: false }
45856
+ { awaitExecution, estimateTxDependencies: false }
45561
45857
  );
45562
45858
  }
45563
45859
  /**
@@ -45566,9 +45862,11 @@ ${MessageCoinFragmentFragmentDoc}`;
45566
45862
  * @param transactionRequestLike - The transaction request to simulate.
45567
45863
  * @returns A promise that resolves to the CallResult object.
45568
45864
  */
45569
- async simulateTransaction(transactionRequestLike) {
45865
+ async simulateTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
45570
45866
  const transactionRequest = transactionRequestify(transactionRequestLike);
45571
- await this.provider.estimateTxDependencies(transactionRequest);
45867
+ if (estimateTxDependencies) {
45868
+ await this.provider.estimateTxDependencies(transactionRequest);
45869
+ }
45572
45870
  return this.provider.call(
45573
45871
  await this.populateTransactionWitnessesSignature(transactionRequest),
45574
45872
  {
@@ -47711,14 +48009,14 @@ ${MessageCoinFragmentFragmentDoc}`;
47711
48009
  }
47712
48010
  }
47713
48011
  const checksumBits = entropy.length / 4;
47714
- const checksum = getBytesCopy(sha2562(entropy))[0] & getUpperMask(checksumBits);
48012
+ const checksum = arrayify(sha2562(entropy))[0] & getUpperMask(checksumBits);
47715
48013
  indices[indices.length - 1] <<= checksumBits;
47716
48014
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
47717
48015
  return indices;
47718
48016
  }
47719
48017
  function mnemonicWordsToEntropy(words, wordlist) {
47720
48018
  const size = Math.ceil(11 * words.length / 8);
47721
- const entropy = getBytesCopy(new Uint8Array(size));
48019
+ const entropy = arrayify(new Uint8Array(size));
47722
48020
  let offset = 0;
47723
48021
  for (let i = 0; i < words.length; i += 1) {
47724
48022
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
@@ -47738,7 +48036,7 @@ ${MessageCoinFragmentFragmentDoc}`;
47738
48036
  const entropyBits = 32 * words.length / 3;
47739
48037
  const checksumBits = words.length / 3;
47740
48038
  const checksumMask = getUpperMask(checksumBits);
47741
- const checksum = getBytesCopy(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
48039
+ const checksum = arrayify(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
47742
48040
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
47743
48041
  throw new FuelError(
47744
48042
  ErrorCode.INVALID_CHECKSUM,
@@ -47821,7 +48119,7 @@ ${MessageCoinFragmentFragmentDoc}`;
47821
48119
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
47822
48120
  */
47823
48121
  static entropyToMnemonic(entropy, wordlist = english) {
47824
- const entropyBytes = getBytesCopy(entropy);
48122
+ const entropyBytes = arrayify(entropy);
47825
48123
  assertWordList(wordlist);
47826
48124
  assertEntropy(entropyBytes);
47827
48125
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -47890,14 +48188,14 @@ ${MessageCoinFragmentFragmentDoc}`;
47890
48188
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
47891
48189
  */
47892
48190
  static masterKeysFromSeed(seed) {
47893
- const seedArray = getBytesCopy(seed);
48191
+ const seedArray = arrayify(seed);
47894
48192
  if (seedArray.length < 16 || seedArray.length > 64) {
47895
48193
  throw new FuelError(
47896
48194
  ErrorCode.INVALID_SEED,
47897
48195
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
47898
48196
  );
47899
48197
  }
47900
- return getBytesCopy(computeHmac("sha512", MasterSecret, seedArray));
48198
+ return arrayify(computeHmac("sha512", MasterSecret, seedArray));
47901
48199
  }
47902
48200
  /**
47903
48201
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -47908,7 +48206,7 @@ ${MessageCoinFragmentFragmentDoc}`;
47908
48206
  */
47909
48207
  static seedToExtendedKey(seed, testnet = false) {
47910
48208
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
47911
- const prefix = getBytesCopy(testnet ? TestnetPRV : MainnetPRV);
48209
+ const prefix = arrayify(testnet ? TestnetPRV : MainnetPRV);
47912
48210
  const depth = "0x00";
47913
48211
  const fingerprint = "0x00000000";
47914
48212
  const index = "0x00000000";
@@ -47938,7 +48236,7 @@ ${MessageCoinFragmentFragmentDoc}`;
47938
48236
  * @returns A randomly generated mnemonic
47939
48237
  */
47940
48238
  static generate(size = 32, extraEntropy = "") {
47941
- const entropy = extraEntropy ? sha2562(concat([randomBytes22(size), getBytesCopy(extraEntropy)])) : randomBytes22(size);
48239
+ const entropy = extraEntropy ? sha2562(concat([randomBytes22(size), arrayify(extraEntropy)])) : randomBytes22(size);
47942
48240
  return Mnemonic.entropyToMnemonic(entropy);
47943
48241
  }
47944
48242
  };
@@ -48023,9 +48321,9 @@ ${MessageCoinFragmentFragmentDoc}`;
48023
48321
  * @returns A new instance of HDWallet on the derived index
48024
48322
  */
48025
48323
  deriveIndex(index) {
48026
- const privateKey = this.privateKey && getBytesCopy(this.privateKey);
48027
- const publicKey = getBytesCopy(this.publicKey);
48028
- const chainCode = getBytesCopy(this.chainCode);
48324
+ const privateKey = this.privateKey && arrayify(this.privateKey);
48325
+ const publicKey = arrayify(this.publicKey);
48326
+ const chainCode = arrayify(this.chainCode);
48029
48327
  const data = new Uint8Array(37);
48030
48328
  if (index & HARDENED_INDEX) {
48031
48329
  if (!privateKey) {
@@ -48036,10 +48334,10 @@ ${MessageCoinFragmentFragmentDoc}`;
48036
48334
  }
48037
48335
  data.set(privateKey, 1);
48038
48336
  } else {
48039
- data.set(getBytesCopy(this.publicKey));
48337
+ data.set(arrayify(this.publicKey));
48040
48338
  }
48041
48339
  data.set(toBytes3(index, 4), 33);
48042
- const bytes4 = getBytesCopy(computeHmac("sha512", chainCode, data));
48340
+ const bytes4 = arrayify(computeHmac("sha512", chainCode, data));
48043
48341
  const IL = bytes4.slice(0, 32);
48044
48342
  const IR = bytes4.slice(32);
48045
48343
  if (privateKey) {
@@ -48093,9 +48391,7 @@ ${MessageCoinFragmentFragmentDoc}`;
48093
48391
  const index = toHex(this.index, 4);
48094
48392
  const chainCode = this.chainCode;
48095
48393
  const key = this.privateKey != null && !isPublic ? concat(["0x00", this.privateKey]) : this.publicKey;
48096
- const extendedKey = getBytesCopy(
48097
- concat([prefix, depth, parentFingerprint, index, chainCode, key])
48098
- );
48394
+ const extendedKey = arrayify(concat([prefix, depth, parentFingerprint, index, chainCode, key]));
48099
48395
  return base58check(extendedKey);
48100
48396
  }
48101
48397
  /**
@@ -48107,13 +48403,13 @@ ${MessageCoinFragmentFragmentDoc}`;
48107
48403
  static fromSeed(seed) {
48108
48404
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
48109
48405
  return new HDWallet({
48110
- chainCode: getBytesCopy(masterKey.slice(32)),
48111
- privateKey: getBytesCopy(masterKey.slice(0, 32))
48406
+ chainCode: arrayify(masterKey.slice(32)),
48407
+ privateKey: arrayify(masterKey.slice(0, 32))
48112
48408
  });
48113
48409
  }
48114
48410
  static fromExtendedKey(extendedKey) {
48115
48411
  const decoded = toBeHex(decodeBase58(extendedKey));
48116
- const bytes4 = getBytesCopy(decoded);
48412
+ const bytes4 = arrayify(decoded);
48117
48413
  const validChecksum = base58check(bytes4.slice(0, 78)) === extendedKey;
48118
48414
  if (bytes4.length !== 82 || !isValidExtendedKey(bytes4)) {
48119
48415
  throw new FuelError(ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
@@ -48779,7 +49075,7 @@ ${MessageCoinFragmentFragmentDoc}`;
48779
49075
  // src/predicate/utils/getPredicateRoot.ts
48780
49076
  var getPredicateRoot = (bytecode) => {
48781
49077
  const chunkSize = 16 * 1024;
48782
- const bytes4 = getBytesCopy(bytecode);
49078
+ const bytes4 = arrayify(bytecode);
48783
49079
  const chunks = chunkAndPadBytes(bytes4, chunkSize);
48784
49080
  const codeRoot = calcRoot(chunks.map((c) => hexlify(c)));
48785
49081
  const predicateRoot = hash3(concat(["0x4655454C", codeRoot]));
@@ -48892,7 +49188,7 @@ ${MessageCoinFragmentFragmentDoc}`;
48892
49188
  * @returns An object containing the new predicate bytes and interface.
48893
49189
  */
48894
49190
  static processPredicateData(bytes4, jsonAbi, configurableConstants) {
48895
- let predicateBytes = getBytesCopy(bytes4);
49191
+ let predicateBytes = arrayify(bytes4);
48896
49192
  let abiInterface;
48897
49193
  if (jsonAbi) {
48898
49194
  abiInterface = new Interface(jsonAbi);
@@ -48992,17 +49288,6 @@ ${MessageCoinFragmentFragmentDoc}`;
48992
49288
  })(FuelConnectorEventTypes || {});
48993
49289
  var FuelConnectorEventType = "FuelConnector";
48994
49290
 
48995
- // src/connectors/types/data-type.ts
48996
- var MessageTypes = /* @__PURE__ */ ((MessageTypes2) => {
48997
- MessageTypes2["ping"] = "ping";
48998
- MessageTypes2["uiEvent"] = "uiEvent";
48999
- MessageTypes2["event"] = "event";
49000
- MessageTypes2["request"] = "request";
49001
- MessageTypes2["response"] = "response";
49002
- MessageTypes2["removeConnection"] = "removeConnection";
49003
- return MessageTypes2;
49004
- })(MessageTypes || {});
49005
-
49006
49291
  // src/connectors/types/local-storage.ts
49007
49292
  var LocalStorage = class {
49008
49293
  storage;
@@ -49291,6 +49576,7 @@ ${MessageCoinFragmentFragmentDoc}`;
49291
49576
  // src/connectors/fuel.ts
49292
49577
  var HAS_CONNECTOR_TIMEOUT = 2e3;
49293
49578
  var PING_CACHE_TIME = 5e3;
49579
+ var { warn } = console;
49294
49580
  var _Fuel = class extends FuelConnector {
49295
49581
  _storage = null;
49296
49582
  _connectors = [];
@@ -49559,14 +49845,12 @@ ${MessageCoinFragmentFragmentDoc}`;
49559
49845
  * Return a Fuel Provider instance with extends features to work with
49560
49846
  * connectors.
49561
49847
  *
49562
- * @deprecated Provider is going to be deprecated in the future.
49848
+ * @deprecated getProvider is deprecated and is going to be removed in the future, use getWallet instead.
49563
49849
  */
49564
49850
  async getProvider(providerOrNetwork) {
49565
- if (process.env.NODE_ENV !== "production") {
49566
- console.warn(
49567
- "Get provider is deprecated, use getWallet instead. Provider is going to be removed in the future."
49568
- );
49569
- }
49851
+ warn(
49852
+ "getProvider is deprecated and is going to be removed in the future, use getWallet instead."
49853
+ );
49570
49854
  return this._getProvider(providerOrNetwork);
49571
49855
  }
49572
49856
  /**
@@ -49583,7 +49867,7 @@ ${MessageCoinFragmentFragmentDoc}`;
49583
49867
  const currentNetwork = await this.currentNetwork();
49584
49868
  provider = await Provider.create(currentNetwork.url);
49585
49869
  } else {
49586
- throw new Error("Provider is not valid.");
49870
+ throw new FuelError(ErrorCode.INVALID_PROVIDER, "Provider is not valid.");
49587
49871
  }
49588
49872
  return provider;
49589
49873
  }
@@ -49646,12 +49930,12 @@ mime-types/index.js:
49646
49930
  @noble/hashes/esm/utils.js:
49647
49931
  (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
49648
49932
 
49649
- @noble/hashes/esm/utils.js:
49650
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
49651
-
49652
49933
  @noble/curves/esm/abstract/utils.js:
49653
49934
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
49654
49935
 
49936
+ @noble/hashes/esm/utils.js:
49937
+ (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
49938
+
49655
49939
  @noble/curves/esm/abstract/modular.js:
49656
49940
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
49657
49941