@fuel-ts/account 0.85.0 → 0.86.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 (42) hide show
  1. package/dist/account.d.ts.map +1 -1
  2. package/dist/hdwallet/hdwallet.d.ts.map +1 -1
  3. package/dist/index.global.js +1694 -2854
  4. package/dist/index.global.js.map +1 -1
  5. package/dist/index.js +304 -298
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +194 -201
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/mnemonic/mnemonic.d.ts.map +1 -1
  10. package/dist/mnemonic/utils.d.ts +0 -1
  11. package/dist/mnemonic/utils.d.ts.map +1 -1
  12. package/dist/predicate/predicate.d.ts +9 -2
  13. package/dist/predicate/predicate.d.ts.map +1 -1
  14. package/dist/providers/coin.d.ts +0 -1
  15. package/dist/providers/coin.d.ts.map +1 -1
  16. package/dist/providers/message.d.ts +0 -1
  17. package/dist/providers/message.d.ts.map +1 -1
  18. package/dist/providers/provider.d.ts +1 -1
  19. package/dist/providers/provider.d.ts.map +1 -1
  20. package/dist/providers/transaction-request/helpers.d.ts +4 -0
  21. package/dist/providers/transaction-request/helpers.d.ts.map +1 -1
  22. package/dist/providers/transaction-request/index.d.ts +1 -0
  23. package/dist/providers/transaction-request/index.d.ts.map +1 -1
  24. package/dist/providers/transaction-request/input.d.ts +0 -2
  25. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  26. package/dist/providers/transaction-request/transaction-request.d.ts +2 -1
  27. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  28. package/dist/providers/transaction-request/utils.d.ts +0 -4
  29. package/dist/providers/transaction-request/utils.d.ts.map +1 -1
  30. package/dist/providers/transaction-summary/call.d.ts +1 -1
  31. package/dist/providers/transaction-summary/call.d.ts.map +1 -1
  32. package/dist/test-utils/seedTestWallet.d.ts +1 -1
  33. package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
  34. package/dist/test-utils.global.js +1422 -2616
  35. package/dist/test-utils.global.js.map +1 -1
  36. package/dist/test-utils.js +247 -288
  37. package/dist/test-utils.js.map +1 -1
  38. package/dist/test-utils.mjs +147 -188
  39. package/dist/test-utils.mjs.map +1 -1
  40. package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
  41. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  42. package/package.json +15 -16
@@ -26,7 +26,7 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
26
26
  import { Address as Address3 } from "@fuel-ts/address";
27
27
  import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
28
28
  import { AbstractAccount } from "@fuel-ts/interfaces";
29
- import { bn as bn20 } from "@fuel-ts/math";
29
+ import { bn as bn19 } from "@fuel-ts/math";
30
30
  import { arrayify as arrayify14, isDefined as isDefined2 } from "@fuel-ts/utils";
31
31
  import { clone as clone4 } from "ramda";
32
32
 
@@ -1291,11 +1291,11 @@ import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
1291
1291
  import { Address, addressify } from "@fuel-ts/address";
1292
1292
  import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1293
1293
  import { randomBytes } from "@fuel-ts/crypto";
1294
- import { bn as bn7 } from "@fuel-ts/math";
1294
+ import { bn as bn8 } from "@fuel-ts/math";
1295
1295
  import {
1296
1296
  PolicyType,
1297
1297
  TransactionCoder,
1298
- InputType as InputType2,
1298
+ InputType as InputType3,
1299
1299
  OutputType as OutputType2,
1300
1300
  TransactionType
1301
1301
  } from "@fuel-ts/transactions";
@@ -1744,6 +1744,36 @@ var NoWitnessAtIndexError = class extends Error {
1744
1744
  name = "NoWitnessAtIndexError";
1745
1745
  };
1746
1746
 
1747
+ // src/providers/transaction-request/helpers.ts
1748
+ import { bn as bn7 } from "@fuel-ts/math";
1749
+ import { InputType as InputType2 } from "@fuel-ts/transactions";
1750
+ var isRequestInputCoin = (input) => input.type === InputType2.Coin;
1751
+ var isRequestInputMessage = (input) => input.type === InputType2.Message;
1752
+ var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
1753
+ var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
1754
+ if (isRequestInputCoin(input) && input.assetId === assetId) {
1755
+ return acc.add(input.amount);
1756
+ }
1757
+ if (isRequestInputMessage(input) && assetId === baseAsset) {
1758
+ return acc.add(input.amount);
1759
+ }
1760
+ return acc;
1761
+ }, bn7(0));
1762
+ var cacheRequestInputsResourcesFromOwner = (inputs, owner) => inputs.reduce(
1763
+ (acc, input) => {
1764
+ if (isRequestInputCoin(input) && input.owner === owner.toB256()) {
1765
+ acc.utxos.push(input.id);
1766
+ } else if (isRequestInputMessage(input) && input.recipient === owner.toB256()) {
1767
+ acc.messages.push(input.nonce);
1768
+ }
1769
+ return acc;
1770
+ },
1771
+ {
1772
+ utxos: [],
1773
+ messages: []
1774
+ }
1775
+ );
1776
+
1747
1777
  // src/providers/transaction-request/witness.ts
1748
1778
  import { arrayify as arrayify4, hexlify as hexlify6 } from "@fuel-ts/utils";
1749
1779
  var witnessify = (value) => {
@@ -1784,10 +1814,10 @@ var BaseTransactionRequest = class {
1784
1814
  outputs,
1785
1815
  witnesses
1786
1816
  } = {}) {
1787
- this.tip = tip ? bn7(tip) : void 0;
1817
+ this.tip = tip ? bn8(tip) : void 0;
1788
1818
  this.maturity = maturity && maturity > 0 ? maturity : void 0;
1789
- this.witnessLimit = isDefined(witnessLimit) ? bn7(witnessLimit) : void 0;
1790
- this.maxFee = bn7(maxFee);
1819
+ this.witnessLimit = isDefined(witnessLimit) ? bn8(witnessLimit) : void 0;
1820
+ this.maxFee = bn8(maxFee);
1791
1821
  this.inputs = inputs ?? [];
1792
1822
  this.outputs = outputs ?? [];
1793
1823
  this.witnesses = witnesses ?? [];
@@ -1796,13 +1826,13 @@ var BaseTransactionRequest = class {
1796
1826
  let policyTypes = 0;
1797
1827
  const policies = [];
1798
1828
  const { tip, witnessLimit, maturity } = req;
1799
- if (bn7(tip).gt(0)) {
1829
+ if (bn8(tip).gt(0)) {
1800
1830
  policyTypes += PolicyType.Tip;
1801
- policies.push({ data: bn7(tip), type: PolicyType.Tip });
1831
+ policies.push({ data: bn8(tip), type: PolicyType.Tip });
1802
1832
  }
1803
- if (isDefined(witnessLimit) && bn7(witnessLimit).gte(0)) {
1833
+ if (isDefined(witnessLimit) && bn8(witnessLimit).gte(0)) {
1804
1834
  policyTypes += PolicyType.WitnessLimit;
1805
- policies.push({ data: bn7(witnessLimit), type: PolicyType.WitnessLimit });
1835
+ policies.push({ data: bn8(witnessLimit), type: PolicyType.WitnessLimit });
1806
1836
  }
1807
1837
  if (maturity && maturity > 0) {
1808
1838
  policyTypes += PolicyType.Maturity;
@@ -1933,7 +1963,7 @@ var BaseTransactionRequest = class {
1933
1963
  */
1934
1964
  getCoinInputs() {
1935
1965
  return this.inputs.filter(
1936
- (input) => input.type === InputType2.Coin
1966
+ (input) => input.type === InputType3.Coin
1937
1967
  );
1938
1968
  }
1939
1969
  /**
@@ -1965,9 +1995,9 @@ var BaseTransactionRequest = class {
1965
1995
  const ownerAddress = addressify(owner);
1966
1996
  const found = this.inputs.find((input) => {
1967
1997
  switch (input.type) {
1968
- case InputType2.Coin:
1998
+ case InputType3.Coin:
1969
1999
  return hexlify7(input.owner) === ownerAddress.toB256();
1970
- case InputType2.Message:
2000
+ case InputType3.Message:
1971
2001
  return hexlify7(input.recipient) === ownerAddress.toB256();
1972
2002
  default:
1973
2003
  return false;
@@ -1982,7 +2012,7 @@ var BaseTransactionRequest = class {
1982
2012
  * @param coin - Coin resource.
1983
2013
  */
1984
2014
  addCoinInput(coin) {
1985
- const { assetId, owner, amount } = coin;
2015
+ const { assetId, owner, amount, id, predicate } = coin;
1986
2016
  let witnessIndex;
1987
2017
  if (coin.predicate) {
1988
2018
  witnessIndex = 0;
@@ -1993,13 +2023,14 @@ var BaseTransactionRequest = class {
1993
2023
  }
1994
2024
  }
1995
2025
  const input = {
1996
- ...coin,
1997
- type: InputType2.Coin,
2026
+ id,
2027
+ type: InputType3.Coin,
1998
2028
  owner: owner.toB256(),
1999
2029
  amount,
2000
2030
  assetId,
2001
2031
  txPointer: "0x00000000000000000000000000000000",
2002
- witnessIndex
2032
+ witnessIndex,
2033
+ predicate
2003
2034
  };
2004
2035
  this.pushInput(input);
2005
2036
  this.addChangeOutput(owner, assetId);
@@ -2011,7 +2042,7 @@ var BaseTransactionRequest = class {
2011
2042
  * @param message - Message resource.
2012
2043
  */
2013
2044
  addMessageInput(message) {
2014
- const { recipient, sender, amount, assetId } = message;
2045
+ const { recipient, sender, amount, predicate, nonce, assetId } = message;
2015
2046
  let witnessIndex;
2016
2047
  if (message.predicate) {
2017
2048
  witnessIndex = 0;
@@ -2022,12 +2053,13 @@ var BaseTransactionRequest = class {
2022
2053
  }
2023
2054
  }
2024
2055
  const input = {
2025
- ...message,
2026
- type: InputType2.Message,
2056
+ nonce,
2057
+ type: InputType3.Message,
2027
2058
  sender: sender.toB256(),
2028
2059
  recipient: recipient.toB256(),
2029
2060
  amount,
2030
- witnessIndex
2061
+ witnessIndex,
2062
+ predicate
2031
2063
  };
2032
2064
  this.pushInput(input);
2033
2065
  this.addChangeOutput(recipient, assetId);
@@ -2174,7 +2206,7 @@ var BaseTransactionRequest = class {
2174
2206
  const assetInput = findAssetInput(assetId);
2175
2207
  let usedQuantity = quantity;
2176
2208
  if (assetId === baseAssetId) {
2177
- usedQuantity = bn7("1000000000000000000");
2209
+ usedQuantity = bn8("1000000000000000000");
2178
2210
  }
2179
2211
  if (assetInput && "assetId" in assetInput) {
2180
2212
  assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
@@ -2186,13 +2218,13 @@ var BaseTransactionRequest = class {
2186
2218
  amount: usedQuantity,
2187
2219
  assetId,
2188
2220
  owner: resourcesOwner || Address.fromRandom(),
2189
- blockCreated: bn7(1),
2190
- txCreatedIdx: bn7(1)
2221
+ blockCreated: bn8(1),
2222
+ txCreatedIdx: bn8(1)
2191
2223
  }
2192
2224
  ]);
2193
2225
  }
2194
2226
  };
2195
- updateAssetInput(baseAssetId, bn7(1e11));
2227
+ updateAssetInput(baseAssetId, bn8(1e11));
2196
2228
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2197
2229
  }
2198
2230
  /**
@@ -2203,7 +2235,7 @@ var BaseTransactionRequest = class {
2203
2235
  */
2204
2236
  getCoinOutputsQuantities() {
2205
2237
  const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
2206
- amount: bn7(amount),
2238
+ amount: bn8(amount),
2207
2239
  assetId: assetId.toString()
2208
2240
  }));
2209
2241
  return coinsQuantities;
@@ -2217,50 +2249,52 @@ var BaseTransactionRequest = class {
2217
2249
  toJSON() {
2218
2250
  return normalizeJSON(this);
2219
2251
  }
2252
+ removeWitness(index) {
2253
+ this.witnesses.splice(index, 1);
2254
+ this.adjustWitnessIndexes(index);
2255
+ }
2256
+ adjustWitnessIndexes(removedIndex) {
2257
+ this.inputs.filter(isRequestInputResource).forEach((input) => {
2258
+ if (input.witnessIndex > removedIndex) {
2259
+ input.witnessIndex -= 1;
2260
+ }
2261
+ });
2262
+ }
2220
2263
  updatePredicateGasUsed(inputs) {
2221
2264
  this.inputs.forEach((i) => {
2222
2265
  let correspondingInput;
2223
2266
  switch (i.type) {
2224
- case InputType2.Coin:
2225
- correspondingInput = inputs.find((x) => x.type === InputType2.Coin && x.owner === i.owner);
2267
+ case InputType3.Coin:
2268
+ correspondingInput = inputs.find((x) => x.type === InputType3.Coin && x.owner === i.owner);
2226
2269
  break;
2227
- case InputType2.Message:
2270
+ case InputType3.Message:
2228
2271
  correspondingInput = inputs.find(
2229
- (x) => x.type === InputType2.Message && x.sender === i.sender
2272
+ (x) => x.type === InputType3.Message && x.sender === i.sender
2230
2273
  );
2231
2274
  break;
2232
2275
  default:
2233
2276
  return;
2234
2277
  }
2235
- if (correspondingInput && "predicateGasUsed" in correspondingInput && bn7(correspondingInput.predicateGasUsed).gt(0)) {
2278
+ if (correspondingInput && "predicateGasUsed" in correspondingInput && bn8(correspondingInput.predicateGasUsed).gt(0)) {
2236
2279
  i.predicate = correspondingInput.predicate;
2237
2280
  i.predicateData = correspondingInput.predicateData;
2238
2281
  i.predicateGasUsed = correspondingInput.predicateGasUsed;
2239
2282
  }
2240
2283
  });
2241
2284
  }
2242
- shiftPredicateData() {
2243
- this.inputs.forEach((input) => {
2244
- if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
2245
- input.predicateData = input.padPredicateData(
2246
- BaseTransactionRequest.getPolicyMeta(this).policies.length
2247
- );
2248
- }
2249
- });
2250
- }
2251
2285
  };
2252
2286
 
2253
2287
  // src/providers/transaction-request/create-transaction-request.ts
2254
2288
  import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
2255
- import { bn as bn9 } from "@fuel-ts/math";
2289
+ import { bn as bn10 } from "@fuel-ts/math";
2256
2290
  import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
2257
2291
  import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
2258
2292
 
2259
2293
  // src/providers/transaction-request/hash-transaction.ts
2260
2294
  import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
2261
2295
  import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
2262
- import { bn as bn8 } from "@fuel-ts/math";
2263
- import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2296
+ import { bn as bn9 } from "@fuel-ts/math";
2297
+ import { TransactionType as TransactionType2, InputType as InputType4, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2264
2298
  import { concat as concat2 } from "@fuel-ts/utils";
2265
2299
  import { clone as clone2 } from "ramda";
2266
2300
  function hashTransaction(transactionRequest, chainId) {
@@ -2271,19 +2305,19 @@ function hashTransaction(transactionRequest, chainId) {
2271
2305
  transaction.inputs = transaction.inputs.map((input) => {
2272
2306
  const inputClone = clone2(input);
2273
2307
  switch (inputClone.type) {
2274
- case InputType3.Coin: {
2308
+ case InputType4.Coin: {
2275
2309
  inputClone.txPointer = {
2276
2310
  blockHeight: 0,
2277
2311
  txIndex: 0
2278
2312
  };
2279
- inputClone.predicateGasUsed = bn8(0);
2313
+ inputClone.predicateGasUsed = bn9(0);
2280
2314
  return inputClone;
2281
2315
  }
2282
- case InputType3.Message: {
2283
- inputClone.predicateGasUsed = bn8(0);
2316
+ case InputType4.Message: {
2317
+ inputClone.predicateGasUsed = bn9(0);
2284
2318
  return inputClone;
2285
2319
  }
2286
- case InputType3.Contract: {
2320
+ case InputType4.Contract: {
2287
2321
  inputClone.txPointer = {
2288
2322
  blockHeight: 0,
2289
2323
  txIndex: 0
@@ -2307,12 +2341,12 @@ function hashTransaction(transactionRequest, chainId) {
2307
2341
  return outputClone;
2308
2342
  }
2309
2343
  case OutputType3.Change: {
2310
- outputClone.amount = bn8(0);
2344
+ outputClone.amount = bn9(0);
2311
2345
  return outputClone;
2312
2346
  }
2313
2347
  case OutputType3.Variable: {
2314
2348
  outputClone.to = ZeroBytes325;
2315
- outputClone.amount = bn8(0);
2349
+ outputClone.amount = bn9(0);
2316
2350
  outputClone.assetId = ZeroBytes325;
2317
2351
  return outputClone;
2318
2352
  }
@@ -2390,7 +2424,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2390
2424
  type: TransactionType3.Create,
2391
2425
  ...baseTransaction,
2392
2426
  bytecodeWitnessIndex,
2393
- storageSlotsCount: bn9(storageSlots.length),
2427
+ storageSlotsCount: bn10(storageSlots.length),
2394
2428
  salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
2395
2429
  storageSlots
2396
2430
  };
@@ -2430,7 +2464,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2430
2464
  }
2431
2465
  metadataGas(gasCosts) {
2432
2466
  return calculateMetadataGasForTxCreate({
2433
- contractBytesSize: bn9(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
2467
+ contractBytesSize: bn10(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
2434
2468
  gasCosts,
2435
2469
  stateRootSize: this.storageSlots.length,
2436
2470
  txBytesSize: this.byteSize()
@@ -2442,8 +2476,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2442
2476
  import { Interface } from "@fuel-ts/abi-coder";
2443
2477
  import { addressify as addressify2 } from "@fuel-ts/address";
2444
2478
  import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
2445
- import { bn as bn10 } from "@fuel-ts/math";
2446
- import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2479
+ import { bn as bn11 } from "@fuel-ts/math";
2480
+ import { InputType as InputType5, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2447
2481
  import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
2448
2482
 
2449
2483
  // src/providers/transaction-request/scripts.ts
@@ -2496,7 +2530,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2496
2530
  */
2497
2531
  constructor({ script, scriptData, gasLimit, ...rest } = {}) {
2498
2532
  super(rest);
2499
- this.gasLimit = bn10(gasLimit);
2533
+ this.gasLimit = bn11(gasLimit);
2500
2534
  this.script = arrayify8(script ?? returnZeroScript.bytes);
2501
2535
  this.scriptData = arrayify8(scriptData ?? returnZeroScript.encodeScriptData());
2502
2536
  this.abis = rest.abis;
@@ -2513,8 +2547,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2513
2547
  type: TransactionType4.Script,
2514
2548
  scriptGasLimit: this.gasLimit,
2515
2549
  ...super.getBaseTransaction(),
2516
- scriptLength: bn10(script.length),
2517
- scriptDataLength: bn10(scriptData.length),
2550
+ scriptLength: bn11(script.length),
2551
+ scriptDataLength: bn11(scriptData.length),
2518
2552
  receiptsRoot: ZeroBytes327,
2519
2553
  script: hexlify10(script),
2520
2554
  scriptData: hexlify10(scriptData)
@@ -2527,7 +2561,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2527
2561
  */
2528
2562
  getContractInputs() {
2529
2563
  return this.inputs.filter(
2530
- (input) => input.type === InputType4.Contract
2564
+ (input) => input.type === InputType5.Contract
2531
2565
  );
2532
2566
  }
2533
2567
  /**
@@ -2607,7 +2641,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2607
2641
  return this;
2608
2642
  }
2609
2643
  const inputIndex = super.pushInput({
2610
- type: InputType4.Contract,
2644
+ type: InputType5.Contract,
2611
2645
  contractId: contractAddress.toB256(),
2612
2646
  txPointer: "0x00000000000000000000000000000000"
2613
2647
  });
@@ -2649,7 +2683,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2649
2683
 
2650
2684
  // src/providers/transaction-request/utils.ts
2651
2685
  import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
2652
- import { TransactionType as TransactionType5, InputType as InputType5 } from "@fuel-ts/transactions";
2686
+ import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
2653
2687
  var transactionRequestify = (obj) => {
2654
2688
  if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
2655
2689
  return obj;
@@ -2667,21 +2701,6 @@ var transactionRequestify = (obj) => {
2667
2701
  }
2668
2702
  }
2669
2703
  };
2670
- var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2671
- (acc, input) => {
2672
- if (input.type === InputType5.Coin && input.owner === owner.toB256()) {
2673
- acc.utxos.push(input.id);
2674
- }
2675
- if (input.type === InputType5.Message && input.recipient === owner.toB256()) {
2676
- acc.messages.push(input.nonce);
2677
- }
2678
- return acc;
2679
- },
2680
- {
2681
- utxos: [],
2682
- messages: []
2683
- }
2684
- );
2685
2704
 
2686
2705
  // src/providers/transaction-response/transaction-response.ts
2687
2706
  import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
@@ -2695,7 +2714,7 @@ import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
2695
2714
  import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
2696
2715
 
2697
2716
  // src/providers/transaction-summary/calculate-tx-fee-for-summary.ts
2698
- import { bn as bn11 } from "@fuel-ts/math";
2717
+ import { bn as bn12 } from "@fuel-ts/math";
2699
2718
  import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
2700
2719
  import { arrayify as arrayify9 } from "@fuel-ts/utils";
2701
2720
  var calculateTXFeeForSummary = (params) => {
@@ -2709,19 +2728,19 @@ var calculateTXFeeForSummary = (params) => {
2709
2728
  if (totalFee) {
2710
2729
  return totalFee;
2711
2730
  }
2712
- const gasPerByte = bn11(feeParams.gasPerByte);
2713
- const gasPriceFactor = bn11(feeParams.gasPriceFactor);
2731
+ const gasPerByte = bn12(feeParams.gasPerByte);
2732
+ const gasPriceFactor = bn12(feeParams.gasPriceFactor);
2714
2733
  const transactionBytes = arrayify9(rawPayload);
2715
2734
  const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
2716
2735
  const { type, witnesses, inputs, policies } = transaction;
2717
- let metadataGas = bn11(0);
2718
- let gasLimit = bn11(0);
2736
+ let metadataGas = bn12(0);
2737
+ let gasLimit = bn12(0);
2719
2738
  if (type !== TransactionType6.Create && type !== TransactionType6.Script) {
2720
- return bn11(0);
2739
+ return bn12(0);
2721
2740
  }
2722
2741
  if (type === TransactionType6.Create) {
2723
2742
  const { bytecodeWitnessIndex, storageSlots } = transaction;
2724
- const contractBytesSize = bn11(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
2743
+ const contractBytesSize = bn12(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
2725
2744
  metadataGas = calculateMetadataGasForTxCreate({
2726
2745
  contractBytesSize,
2727
2746
  gasCosts,
@@ -2740,7 +2759,7 @@ var calculateTXFeeForSummary = (params) => {
2740
2759
  }
2741
2760
  const minGas = getMinGas({
2742
2761
  gasCosts,
2743
- gasPerByte: bn11(gasPerByte),
2762
+ gasPerByte: bn12(gasPerByte),
2744
2763
  inputs,
2745
2764
  metadataGas,
2746
2765
  txBytesSize: transactionBytes.length
@@ -2771,39 +2790,28 @@ import { bn as bn13 } from "@fuel-ts/math";
2771
2790
  import { ReceiptType as ReceiptType4, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
2772
2791
 
2773
2792
  // src/providers/transaction-summary/call.ts
2774
- import { Interface as Interface2, calculateVmTxMemory } from "@fuel-ts/abi-coder";
2775
- import { bn as bn12 } from "@fuel-ts/math";
2776
- var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2793
+ import { Interface as Interface2 } from "@fuel-ts/abi-coder";
2794
+ var getFunctionCall = ({ abi, receipt }) => {
2777
2795
  const abiInterface = new Interface2(abi);
2778
2796
  const callFunctionSelector = receipt.param1.toHex(8);
2779
2797
  const functionFragment = abiInterface.getFunction(callFunctionSelector);
2780
2798
  const inputs = functionFragment.jsonFn.inputs;
2781
- let encodedArgs;
2782
- if (functionFragment.isInputDataPointer) {
2783
- if (rawPayload) {
2784
- const argsOffset = bn12(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
2785
- encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
2786
- }
2787
- } else {
2788
- encodedArgs = receipt.param2.toHex();
2789
- }
2799
+ const encodedArgs = receipt.param2.toHex();
2790
2800
  let argumentsProvided;
2791
- if (encodedArgs) {
2792
- const data = functionFragment.decodeArguments(encodedArgs);
2793
- if (data) {
2794
- argumentsProvided = inputs.reduce((prev, input, index) => {
2795
- const value = data[index];
2796
- const name = input.name;
2797
- if (name) {
2798
- return {
2799
- ...prev,
2800
- // reparse to remove bn
2801
- [name]: JSON.parse(JSON.stringify(value))
2802
- };
2803
- }
2804
- return prev;
2805
- }, {});
2806
- }
2801
+ const data = functionFragment.decodeArguments(encodedArgs);
2802
+ if (data) {
2803
+ argumentsProvided = inputs.reduce((prev, input, index) => {
2804
+ const value = data[index];
2805
+ const name = input.name;
2806
+ if (name) {
2807
+ return {
2808
+ ...prev,
2809
+ // reparse to remove bn
2810
+ [name]: JSON.parse(JSON.stringify(value))
2811
+ };
2812
+ }
2813
+ return prev;
2814
+ }, {});
2807
2815
  }
2808
2816
  const call = {
2809
2817
  functionSignature: functionFragment.signature,
@@ -4857,22 +4865,6 @@ var rawAssets = [
4857
4865
  ];
4858
4866
  var assets = resolveIconPaths(rawAssets, fuelAssetsBaseUrl);
4859
4867
 
4860
- // src/providers/transaction-request/helpers.ts
4861
- import { bn as bn19 } from "@fuel-ts/math";
4862
- import { InputType as InputType8 } from "@fuel-ts/transactions";
4863
- var isRequestInputCoin = (input) => input.type === InputType8.Coin;
4864
- var isRequestInputMessage = (input) => input.type === InputType8.Message;
4865
- var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
4866
- var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
4867
- if (isRequestInputCoin(input) && input.assetId === assetId) {
4868
- return acc.add(input.amount);
4869
- }
4870
- if (isRequestInputMessage(input) && assetId === baseAsset) {
4871
- return acc.add(input.amount);
4872
- }
4873
- return acc;
4874
- }, bn19(0));
4875
-
4876
4868
  // src/utils/formatTransferToContractScriptData.ts
4877
4869
  import { BigNumberCoder as BigNumberCoder2 } from "@fuel-ts/abi-coder";
4878
4870
  import { BN as BN2 } from "@fuel-ts/math";
@@ -5076,9 +5068,9 @@ var Account = class extends AbstractAccount {
5076
5068
  const { addedSignatures, estimatedPredicates, requiredQuantities, updateMaxFee } = params;
5077
5069
  const fee = request.maxFee;
5078
5070
  const baseAssetId = this.provider.getBaseAssetId();
5079
- const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || bn20(0);
5071
+ const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || bn19(0);
5080
5072
  const requiredQuantitiesWithFee = addAmountToCoinQuantities({
5081
- amount: bn20(fee),
5073
+ amount: bn19(fee),
5082
5074
  assetId: baseAssetId,
5083
5075
  coinQuantities: requiredQuantities
5084
5076
  });
@@ -5086,7 +5078,7 @@ var Account = class extends AbstractAccount {
5086
5078
  requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
5087
5079
  quantitiesDict[assetId] = {
5088
5080
  required: amount,
5089
- owned: bn20(0)
5081
+ owned: bn19(0)
5090
5082
  };
5091
5083
  });
5092
5084
  request.inputs.filter(isRequestInputResource).forEach((input) => {
@@ -5110,10 +5102,9 @@ var Account = class extends AbstractAccount {
5110
5102
  while (needsToBeFunded && fundingAttempts < MAX_FUNDING_ATTEMPTS) {
5111
5103
  const resources = await this.getResourcesToSpend(
5112
5104
  missingQuantities,
5113
- cacheTxInputsFromOwner(request.inputs, this.address)
5105
+ cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
5114
5106
  );
5115
5107
  request.addResources(resources);
5116
- request.shiftPredicateData();
5117
5108
  request.updatePredicateGasUsed(estimatedPredicates);
5118
5109
  const requestToReestimate2 = clone4(request);
5119
5110
  if (addedSignatures) {
@@ -5145,7 +5136,6 @@ var Account = class extends AbstractAccount {
5145
5136
  }
5146
5137
  fundingAttempts += 1;
5147
5138
  }
5148
- request.shiftPredicateData();
5149
5139
  request.updatePredicateGasUsed(estimatedPredicates);
5150
5140
  const requestToReestimate = clone4(request);
5151
5141
  if (addedSignatures) {
@@ -5196,7 +5186,7 @@ var Account = class extends AbstractAccount {
5196
5186
  * @returns A promise that resolves to the transaction response.
5197
5187
  */
5198
5188
  async transfer(destination, amount, assetId, txParams = {}) {
5199
- if (bn20(amount).lte(0)) {
5189
+ if (bn19(amount).lte(0)) {
5200
5190
  throw new FuelError15(
5201
5191
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
5202
5192
  "Transfer amount must be a positive number."
@@ -5216,7 +5206,7 @@ var Account = class extends AbstractAccount {
5216
5206
  * @returns A promise that resolves to the transaction response.
5217
5207
  */
5218
5208
  async transferToContract(contractId, amount, assetId, txParams = {}) {
5219
- if (bn20(amount).lte(0)) {
5209
+ if (bn19(amount).lte(0)) {
5220
5210
  throw new FuelError15(
5221
5211
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
5222
5212
  "Transfer amount must be a positive number."
@@ -5226,7 +5216,7 @@ var Account = class extends AbstractAccount {
5226
5216
  const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5227
5217
  const { script, scriptData } = await assembleTransferToContractScript({
5228
5218
  hexlifiedContractId: contractAddress.toB256(),
5229
- amountToTransfer: bn20(amount),
5219
+ amountToTransfer: bn19(amount),
5230
5220
  assetId: assetIdToTransfer
5231
5221
  });
5232
5222
  let request = new ScriptTransactionRequest({
@@ -5237,7 +5227,7 @@ var Account = class extends AbstractAccount {
5237
5227
  request.addContractInputAndOutput(contractAddress);
5238
5228
  const txCost = await this.provider.getTransactionCost(request, {
5239
5229
  resourcesOwner: this,
5240
- quantitiesToContract: [{ amount: bn20(amount), assetId: String(assetIdToTransfer) }]
5230
+ quantitiesToContract: [{ amount: bn19(amount), assetId: String(assetIdToTransfer) }]
5241
5231
  });
5242
5232
  request = this.validateGasLimitAndMaxFee({
5243
5233
  transactionRequest: request,
@@ -5262,7 +5252,7 @@ var Account = class extends AbstractAccount {
5262
5252
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5263
5253
  );
5264
5254
  const amountDataArray = arrayify14(
5265
- "0x".concat(bn20(amount).toHex().substring(2).padStart(16, "0"))
5255
+ "0x".concat(bn19(amount).toHex().substring(2).padStart(16, "0"))
5266
5256
  );
5267
5257
  const script = new Uint8Array([
5268
5258
  ...arrayify14(withdrawScript.bytes),
@@ -5272,7 +5262,7 @@ var Account = class extends AbstractAccount {
5272
5262
  const params = { script, ...txParams };
5273
5263
  const baseAssetId = this.provider.getBaseAssetId();
5274
5264
  let request = new ScriptTransactionRequest(params);
5275
- const quantitiesToContract = [{ amount: bn20(amount), assetId: baseAssetId }];
5265
+ const quantitiesToContract = [{ amount: bn19(amount), assetId: baseAssetId }];
5276
5266
  const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5277
5267
  request = this.validateGasLimitAndMaxFee({
5278
5268
  transactionRequest: request,
@@ -5686,18 +5676,17 @@ var BaseWalletUnlocked = class extends Account {
5686
5676
  __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5687
5677
 
5688
5678
  // src/hdwallet/hdwallet.ts
5679
+ import { computeHmac as computeHmac2, ripemd160 } from "@fuel-ts/crypto";
5689
5680
  import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
5690
5681
  import { sha256 as sha2564 } from "@fuel-ts/hasher";
5691
- import { bn as bn21, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5692
- import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
5693
- import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
5682
+ import { bn as bn20, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5683
+ import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58 } from "@fuel-ts/utils";
5694
5684
 
5695
5685
  // src/mnemonic/mnemonic.ts
5696
- import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
5686
+ import { randomBytes as randomBytes4, pbkdf2, computeHmac } from "@fuel-ts/crypto";
5697
5687
  import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
5698
5688
  import { sha256 as sha2563 } from "@fuel-ts/hasher";
5699
- import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
5700
- import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
5689
+ import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4, dataSlice, encodeBase58, toUtf8Bytes } from "@fuel-ts/utils";
5701
5690
 
5702
5691
  // src/wordlists/words/english.ts
5703
5692
  var english = [
@@ -7755,38 +7744,6 @@ var english = [
7755
7744
  import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
7756
7745
  import { sha256 as sha2562 } from "@fuel-ts/hasher";
7757
7746
  import { arrayify as arrayify16 } from "@fuel-ts/utils";
7758
- function toUtf8Bytes(stri) {
7759
- const str = stri.normalize("NFKD");
7760
- const result = [];
7761
- for (let i = 0; i < str.length; i += 1) {
7762
- const c = str.charCodeAt(i);
7763
- if (c < 128) {
7764
- result.push(c);
7765
- } else if (c < 2048) {
7766
- result.push(c >> 6 | 192);
7767
- result.push(c & 63 | 128);
7768
- } else if ((c & 64512) === 55296) {
7769
- i += 1;
7770
- const c2 = str.charCodeAt(i);
7771
- if (i >= str.length || (c2 & 64512) !== 56320) {
7772
- throw new FuelError17(
7773
- ErrorCode17.INVALID_INPUT_PARAMETERS,
7774
- "Invalid UTF-8 in the input string."
7775
- );
7776
- }
7777
- const pair = 65536 + ((c & 1023) << 10) + (c2 & 1023);
7778
- result.push(pair >> 18 | 240);
7779
- result.push(pair >> 12 & 63 | 128);
7780
- result.push(pair >> 6 & 63 | 128);
7781
- result.push(pair & 63 | 128);
7782
- } else {
7783
- result.push(c >> 12 | 224);
7784
- result.push(c >> 6 & 63 | 128);
7785
- result.push(c & 63 | 128);
7786
- }
7787
- }
7788
- return Uint8Array.from(result);
7789
- }
7790
7747
  function getLowerMask(bits) {
7791
7748
  return (1 << bits) - 1;
7792
7749
  }
@@ -8154,7 +8111,7 @@ var HDWallet = class {
8154
8111
  const IR = bytes.slice(32);
8155
8112
  if (privateKey) {
8156
8113
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
8157
- const ki = bn21(IL).add(privateKey).mod(N).toBytes(32);
8114
+ const ki = bn20(IL).add(privateKey).mod(N).toBytes(32);
8158
8115
  return new HDWallet({
8159
8116
  privateKey: ki,
8160
8117
  chainCode: IR,
@@ -8220,7 +8177,7 @@ var HDWallet = class {
8220
8177
  });
8221
8178
  }
8222
8179
  static fromExtendedKey(extendedKey) {
8223
- const decoded = toBeHex(decodeBase58(extendedKey));
8180
+ const decoded = hexlify17(toBytes2(decodeBase58(extendedKey)));
8224
8181
  const bytes = arrayify18(decoded);
8225
8182
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
8226
8183
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
@@ -8420,16 +8377,18 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
8420
8377
 
8421
8378
  // src/test-utils/seedTestWallet.ts
8422
8379
  import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
8423
- var seedTestWallet = async (wallet, quantities) => {
8424
- const genesisWallet = new WalletUnlocked(
8425
- process.env.GENESIS_SECRET || randomBytes5(32),
8426
- wallet.provider
8427
- );
8380
+ var seedTestWallet = async (wallet, quantities, utxosAmount = 1) => {
8381
+ const accountsToBeFunded = Array.isArray(wallet) ? wallet : [wallet];
8382
+ const [{ provider }] = accountsToBeFunded;
8383
+ const genesisWallet = new WalletUnlocked(process.env.GENESIS_SECRET || randomBytes5(32), provider);
8428
8384
  const request = new ScriptTransactionRequest();
8429
- quantities.forEach((quantity) => {
8430
- const { amount, assetId } = coinQuantityfy(quantity);
8431
- request.addCoinOutput(wallet.address, amount, assetId);
8432
- });
8385
+ quantities.map(coinQuantityfy).forEach(
8386
+ ({ amount, assetId }) => accountsToBeFunded.forEach(({ address }) => {
8387
+ for (let i = 0; i < utxosAmount; i++) {
8388
+ request.addCoinOutput(address, amount.div(utxosAmount), assetId);
8389
+ }
8390
+ })
8391
+ );
8433
8392
  const txCost = await genesisWallet.provider.getTransactionCost(request);
8434
8393
  request.gasLimit = txCost.gasUsed;
8435
8394
  request.maxFee = txCost.maxFee;