@fuel-ts/account 0.93.0 → 0.94.1

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.
Files changed (82) hide show
  1. package/README.md +9 -29
  2. package/dist/account.d.ts +2 -2
  3. package/dist/account.d.ts.map +1 -1
  4. package/dist/configs.d.ts +0 -2
  5. package/dist/configs.d.ts.map +1 -1
  6. package/dist/configs.global.js +0 -2
  7. package/dist/configs.global.js.map +1 -1
  8. package/dist/configs.js +0 -6
  9. package/dist/configs.js.map +1 -1
  10. package/dist/configs.mjs +0 -4
  11. package/dist/configs.mjs.map +1 -1
  12. package/dist/connectors/fuel-connector.d.ts.map +1 -1
  13. package/dist/connectors/fuel.d.ts.map +1 -1
  14. package/dist/connectors/utils/promises.d.ts.map +1 -1
  15. package/dist/index.global.js +1628 -930
  16. package/dist/index.global.js.map +1 -1
  17. package/dist/index.js +978 -603
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +706 -343
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/predicate/predicate.d.ts +15 -9
  22. package/dist/predicate/predicate.d.ts.map +1 -1
  23. package/dist/providers/__generated__/operations.d.ts +614 -1
  24. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  25. package/dist/providers/fuel-graphql-subscriber.d.ts +2 -3
  26. package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
  27. package/dist/providers/provider.d.ts +12 -6
  28. package/dist/providers/provider.d.ts.map +1 -1
  29. package/dist/providers/resource-cache.d.ts +14 -0
  30. package/dist/providers/resource-cache.d.ts.map +1 -0
  31. package/dist/providers/transaction-request/blob-transaction-request.d.ts +48 -0
  32. package/dist/providers/transaction-request/blob-transaction-request.d.ts.map +1 -0
  33. package/dist/providers/transaction-request/index.d.ts +1 -0
  34. package/dist/providers/transaction-request/index.d.ts.map +1 -1
  35. package/dist/providers/transaction-request/transaction-request.d.ts +4 -3
  36. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  37. package/dist/providers/transaction-request/types.d.ts +5 -2
  38. package/dist/providers/transaction-request/types.d.ts.map +1 -1
  39. package/dist/providers/transaction-request/utils.d.ts +9 -0
  40. package/dist/providers/transaction-request/utils.d.ts.map +1 -1
  41. package/dist/providers/transaction-response/transaction-response.d.ts +10 -5
  42. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  43. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +1 -1
  44. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
  45. package/dist/providers/transaction-summary/call.d.ts +4 -3
  46. package/dist/providers/transaction-summary/call.d.ts.map +1 -1
  47. package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
  48. package/dist/providers/transaction-summary/input.d.ts +6 -1
  49. package/dist/providers/transaction-summary/input.d.ts.map +1 -1
  50. package/dist/providers/transaction-summary/operations.d.ts +4 -2
  51. package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
  52. package/dist/providers/transaction-summary/types.d.ts +5 -2
  53. package/dist/providers/transaction-summary/types.d.ts.map +1 -1
  54. package/dist/providers/utils/gas.d.ts +6 -0
  55. package/dist/providers/utils/gas.d.ts.map +1 -1
  56. package/dist/test-utils/launchNode.d.ts +0 -18
  57. package/dist/test-utils/launchNode.d.ts.map +1 -1
  58. package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +1 -1
  59. package/dist/test-utils/test-asset-id.d.ts +8 -0
  60. package/dist/test-utils/test-asset-id.d.ts.map +1 -0
  61. package/dist/test-utils/test-message.d.ts +4 -2
  62. package/dist/test-utils/test-message.d.ts.map +1 -1
  63. package/dist/test-utils/wallet-config.d.ts +3 -3
  64. package/dist/test-utils/wallet-config.d.ts.map +1 -1
  65. package/dist/test-utils.d.ts +1 -3
  66. package/dist/test-utils.d.ts.map +1 -1
  67. package/dist/test-utils.global.js +40829 -40167
  68. package/dist/test-utils.global.js.map +1 -1
  69. package/dist/test-utils.js +1500 -1200
  70. package/dist/test-utils.js.map +1 -1
  71. package/dist/test-utils.mjs +1209 -910
  72. package/dist/test-utils.mjs.map +1 -1
  73. package/dist/wallet/keystore-wallet.d.ts.map +1 -1
  74. package/package.json +17 -19
  75. package/dist/providers/memory-cache.d.ts +0 -11
  76. package/dist/providers/memory-cache.d.ts.map +0 -1
  77. package/dist/test-utils/asset-id.d.ts +0 -8
  78. package/dist/test-utils/asset-id.d.ts.map +0 -1
  79. package/dist/test-utils/generateTestWallet.d.ts +0 -4
  80. package/dist/test-utils/generateTestWallet.d.ts.map +0 -1
  81. package/dist/test-utils/seedTestWallet.d.ts +0 -4
  82. package/dist/test-utils/seedTestWallet.d.ts.map +0 -1
@@ -48,34 +48,344 @@ var __privateMethod = (obj, member, method) => {
48
48
  // src/test-utils.ts
49
49
  var test_utils_exports = {};
50
50
  __export(test_utils_exports, {
51
- AssetId: () => AssetId,
51
+ TestAssetId: () => TestAssetId,
52
52
  TestMessage: () => TestMessage,
53
53
  WalletsConfig: () => WalletsConfig,
54
- generateTestWallet: () => generateTestWallet,
55
54
  launchNode: () => launchNode,
56
- launchNodeAndGetWallets: () => launchNodeAndGetWallets,
57
- seedTestWallet: () => seedTestWallet,
58
55
  setupTestProviderAndWallets: () => setupTestProviderAndWallets
59
56
  });
60
57
  module.exports = __toCommonJS(test_utils_exports);
61
58
 
62
- // src/wallet/base-wallet-unlocked.ts
63
- var import_hasher3 = require("@fuel-ts/hasher");
64
- var import_utils32 = require("@fuel-ts/utils");
65
-
66
- // src/account.ts
67
- var import_abi_coder7 = require("@fuel-ts/abi-coder");
68
- var import_address4 = require("@fuel-ts/address");
59
+ // src/test-utils/launchNode.ts
60
+ var import_abi_coder = require("@fuel-ts/abi-coder");
69
61
  var import_crypto2 = require("@fuel-ts/crypto");
70
- var import_errors16 = require("@fuel-ts/errors");
71
- var import_interfaces = require("@fuel-ts/interfaces");
72
- var import_math20 = require("@fuel-ts/math");
73
- var import_utils29 = require("@fuel-ts/utils");
74
- var import_ramda4 = require("ramda");
62
+ var import_errors = require("@fuel-ts/errors");
63
+ var import_utils2 = require("@fuel-ts/utils");
64
+ var import_fs = require("fs");
65
+ var import_os = __toESM(require("os"));
66
+ var import_path = __toESM(require("path"));
67
+ var import_portfinder = require("portfinder");
75
68
 
76
- // src/providers/coin-quantity.ts
69
+ // src/signer/signer.ts
70
+ var import_address = require("@fuel-ts/address");
71
+ var import_crypto = require("@fuel-ts/crypto");
72
+ var import_hasher = require("@fuel-ts/hasher");
77
73
  var import_math = require("@fuel-ts/math");
78
74
  var import_utils = require("@fuel-ts/utils");
75
+ var import_secp256k1 = require("@noble/curves/secp256k1");
76
+ var Signer = class {
77
+ address;
78
+ publicKey;
79
+ compressedPublicKey;
80
+ privateKey;
81
+ /**
82
+ * Create a Signer instance from a given private key
83
+ *
84
+ * @param privateKey - The private key to use for signing
85
+ * @returns A new Signer instance
86
+ */
87
+ constructor(privateKey) {
88
+ if (typeof privateKey === "string") {
89
+ if (privateKey.match(/^[0-9a-f]*$/i) && privateKey.length === 64) {
90
+ privateKey = `0x${privateKey}`;
91
+ }
92
+ }
93
+ const privateKeyBytes = (0, import_math.toBytes)(privateKey, 32);
94
+ this.privateKey = (0, import_utils.hexlify)(privateKeyBytes);
95
+ this.publicKey = (0, import_utils.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
96
+ this.compressedPublicKey = (0, import_utils.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
97
+ this.address = import_address.Address.fromPublicKey(this.publicKey);
98
+ }
99
+ /**
100
+ * Sign data using the Signer instance
101
+ *
102
+ * Signature is a 64 byte array of the concatenated r and s values with the compressed recoveryParam byte.
103
+ * @ignore
104
+ * [Read more](FuelLabs/fuel-specs/specs/protocol/cryptographic_primitives.md#public-key-cryptography)
105
+ *
106
+ * @param data - The data to be sign
107
+ * @returns hashed signature
108
+ */
109
+ sign(data) {
110
+ const signature = import_secp256k1.secp256k1.sign((0, import_utils.arrayify)(data), (0, import_utils.arrayify)(this.privateKey));
111
+ const r = (0, import_math.toBytes)(`0x${signature.r.toString(16)}`, 32);
112
+ const s = (0, import_math.toBytes)(`0x${signature.s.toString(16)}`, 32);
113
+ s[0] |= (signature.recovery || 0) << 7;
114
+ return (0, import_utils.hexlify)((0, import_utils.concat)([r, s]));
115
+ }
116
+ /**
117
+ * Add point on the current elliptic curve
118
+ *
119
+ * @param point - Point to add on the curve
120
+ * @returns compressed point on the curve
121
+ */
122
+ addPoint(point) {
123
+ const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils.arrayify)(this.compressedPublicKey));
124
+ const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils.arrayify)(point));
125
+ const result = p0.add(p1);
126
+ return `0x${result.toHex(true)}`;
127
+ }
128
+ /**
129
+ * Recover the public key from a signature performed with [`sign`](#sign).
130
+ *
131
+ * @param data - Data
132
+ * @param signature - hashed signature
133
+ * @returns public key from signature from the
134
+ */
135
+ static recoverPublicKey(data, signature) {
136
+ const signedMessageBytes = (0, import_utils.arrayify)(signature);
137
+ const r = signedMessageBytes.slice(0, 32);
138
+ const s = signedMessageBytes.slice(32, 64);
139
+ const recoveryParam = (s[0] & 128) >> 7;
140
+ s[0] &= 127;
141
+ const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils.hexlify)(r)), BigInt((0, import_utils.hexlify)(s))).addRecoveryBit(
142
+ recoveryParam
143
+ );
144
+ const publicKey = sig.recoverPublicKey((0, import_utils.arrayify)(data)).toRawBytes(false).slice(1);
145
+ return (0, import_utils.hexlify)(publicKey);
146
+ }
147
+ /**
148
+ * Recover the address from a signature performed with [`sign`](#sign).
149
+ *
150
+ * @param data - Data
151
+ * @param signature - Signature
152
+ * @returns Address from signature
153
+ */
154
+ static recoverAddress(data, signature) {
155
+ return import_address.Address.fromPublicKey(Signer.recoverPublicKey(data, signature));
156
+ }
157
+ /**
158
+ * Generate a random privateKey
159
+ *
160
+ * @param entropy - Adds extra entropy to generate the privateKey
161
+ * @returns random 32-byte hashed
162
+ */
163
+ static generatePrivateKey(entropy) {
164
+ return entropy ? (0, import_hasher.hash)((0, import_utils.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
165
+ }
166
+ /**
167
+ * Extended publicKey from a compact publicKey
168
+ *
169
+ * @param publicKey - Compact publicKey
170
+ * @returns extended publicKey
171
+ */
172
+ static extendPublicKey(publicKey) {
173
+ const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils.arrayify)(publicKey));
174
+ return (0, import_utils.hexlify)(point.toRawBytes(false).slice(1));
175
+ }
176
+ };
177
+
178
+ // src/test-utils/launchNode.ts
179
+ var getFlagValueFromArgs = (args, flag) => {
180
+ const flagIndex = args.indexOf(flag);
181
+ if (flagIndex === -1) {
182
+ return void 0;
183
+ }
184
+ return args[flagIndex + 1];
185
+ };
186
+ var extractRemainingArgs = (args, flagsToRemove) => {
187
+ const newArgs = [...args];
188
+ flagsToRemove.forEach((flag) => {
189
+ const flagIndex = newArgs.indexOf(flag);
190
+ if (flagIndex !== -1) {
191
+ newArgs.splice(flagIndex, 2);
192
+ }
193
+ });
194
+ return newArgs;
195
+ };
196
+ function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
197
+ const defaultCoins = import_utils2.defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
198
+ ...coin,
199
+ amount: "18446744073709551615"
200
+ }));
201
+ const defaultMessages = import_utils2.defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
202
+ ...message,
203
+ amount: "18446744073709551615"
204
+ }));
205
+ const coins = defaultCoins.concat(stateConfig.coins.map((coin) => ({ ...coin, amount: coin.amount.toString() }))).filter((coin, index, self) => self.findIndex((c) => c.tx_id === coin.tx_id) === index);
206
+ const messages = defaultMessages.concat(stateConfig.messages.map((msg) => ({ ...msg, amount: msg.amount.toString() }))).filter((msg, index, self) => self.findIndex((m) => m.nonce === msg.nonce) === index);
207
+ if (!process.env.GENESIS_SECRET) {
208
+ const pk = Signer.generatePrivateKey();
209
+ const signer = new Signer(pk);
210
+ process.env.GENESIS_SECRET = (0, import_utils2.hexlify)(pk);
211
+ coins.push({
212
+ tx_id: (0, import_utils2.hexlify)((0, import_crypto2.randomBytes)(import_abi_coder.BYTES_32)),
213
+ owner: signer.address.toHexString(),
214
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
215
+ amount: "18446744073709551615",
216
+ asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
217
+ output_index: 0,
218
+ tx_pointer_block_height: 0,
219
+ tx_pointer_tx_idx: 0
220
+ });
221
+ }
222
+ const json = JSON.stringify({
223
+ ...stateConfig,
224
+ coins,
225
+ messages
226
+ });
227
+ const regexMakeNumber = /("amount":)"(\d+)"/gm;
228
+ return json.replace(regexMakeNumber, "$1$2");
229
+ }
230
+ var launchNode = async ({
231
+ ip,
232
+ port,
233
+ args = [],
234
+ fuelCorePath = process.env.FUEL_CORE_PATH || void 0,
235
+ loggingEnabled = true,
236
+ basePath,
237
+ snapshotConfig = import_utils2.defaultSnapshotConfigs
238
+ } = {}) => (
239
+ // eslint-disable-next-line no-async-promise-executor
240
+ new Promise(async (resolve, reject) => {
241
+ const remainingArgs = extractRemainingArgs(args, [
242
+ "--snapshot",
243
+ "--consensus-key",
244
+ "--db-type",
245
+ "--poa-instant",
246
+ "--min-gas-price",
247
+ "--native-executor-version"
248
+ ]);
249
+ const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
250
+ const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils2.defaultConsensusKey;
251
+ const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
252
+ const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
253
+ const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
254
+ const poaInstant = poaInstantFlagValue === "true" || poaInstantFlagValue === void 0;
255
+ const nativeExecutorVersion = getFlagValueFromArgs(args, "--native-executor-version") || "0";
256
+ const minGasPrice = getFlagValueFromArgs(args, "--min-gas-price") || "1";
257
+ const graphQLStartSubstring = "Binding GraphQL provider to";
258
+ const command = fuelCorePath || "fuel-core";
259
+ const ipToUse = ip || "0.0.0.0";
260
+ const portToUse = port || (await (0, import_portfinder.getPortPromise)({
261
+ port: 4e3,
262
+ // tries 4000 first, then 4001, then 4002, etc.
263
+ stopPort: 5e3
264
+ // don't try ports above 5000
265
+ })).toString();
266
+ let snapshotDirToUse;
267
+ const prefix = basePath || import_os.default.tmpdir();
268
+ const suffix = basePath ? "" : (0, import_crypto2.randomUUID)();
269
+ const tempDir = import_path.default.join(prefix, ".fuels", suffix, "snapshotDir");
270
+ if (snapshotDir) {
271
+ snapshotDirToUse = snapshotDir;
272
+ } else {
273
+ if (!(0, import_fs.existsSync)(tempDir)) {
274
+ (0, import_fs.mkdirSync)(tempDir, { recursive: true });
275
+ }
276
+ const { metadata } = snapshotConfig;
277
+ const metadataPath = import_path.default.join(tempDir, "metadata.json");
278
+ const chainConfigPath = import_path.default.join(tempDir, metadata.chain_config);
279
+ const stateConfigPath = import_path.default.join(tempDir, metadata.table_encoding.Json.filepath);
280
+ const stateTransitionPath = import_path.default.join(tempDir, "state_transition_bytecode.wasm");
281
+ (0, import_fs.writeFileSync)(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
282
+ (0, import_fs.writeFileSync)(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
283
+ (0, import_fs.writeFileSync)(metadataPath, JSON.stringify(metadata), "utf8");
284
+ (0, import_fs.writeFileSync)(stateTransitionPath, JSON.stringify(""));
285
+ snapshotDirToUse = tempDir;
286
+ }
287
+ const { spawn } = await import("child_process");
288
+ const child = spawn(
289
+ command,
290
+ [
291
+ "run",
292
+ ["--ip", ipToUse],
293
+ ["--port", portToUse],
294
+ useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
295
+ ["--min-gas-price", minGasPrice],
296
+ poaInstant ? ["--poa-instant", "true"] : [],
297
+ ["--native-executor-version", nativeExecutorVersion],
298
+ ["--consensus-key", consensusKey],
299
+ ["--snapshot", snapshotDirToUse],
300
+ "--vm-backtrace",
301
+ "--utxo-validation",
302
+ "--debug",
303
+ ...remainingArgs
304
+ ].flat(),
305
+ { stdio: "pipe", detached: true }
306
+ );
307
+ if (loggingEnabled) {
308
+ child.stderr.on("data", (chunk) => {
309
+ console.log(chunk.toString());
310
+ });
311
+ }
312
+ const removeSideffects = () => {
313
+ child.stderr.removeAllListeners();
314
+ if ((0, import_fs.existsSync)(tempDir)) {
315
+ (0, import_fs.rmSync)(tempDir, { recursive: true });
316
+ }
317
+ };
318
+ child.on("error", removeSideffects);
319
+ child.on("exit", removeSideffects);
320
+ const childState = {
321
+ isDead: false
322
+ };
323
+ const cleanup = () => {
324
+ if (childState.isDead) {
325
+ return;
326
+ }
327
+ childState.isDead = true;
328
+ removeSideffects();
329
+ if (child.pid !== void 0) {
330
+ try {
331
+ process.kill(-child.pid);
332
+ } catch (e) {
333
+ const error = e;
334
+ if (error.code === "ESRCH") {
335
+ console.log(
336
+ `fuel-core node under pid ${child.pid} does not exist. The node might have been killed before cleanup was called. Exiting cleanly.`
337
+ );
338
+ } else {
339
+ throw e;
340
+ }
341
+ }
342
+ } else {
343
+ console.error("No PID available for the child process, unable to kill launched node");
344
+ }
345
+ };
346
+ child.stderr.on("data", (chunk) => {
347
+ const text = typeof chunk === "string" ? chunk : chunk.toString();
348
+ if (text.indexOf(graphQLStartSubstring) !== -1) {
349
+ const rows = text.split("\n");
350
+ const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
351
+ const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
352
+ setTimeout(
353
+ () => (
354
+ // Resolve with the cleanup method.
355
+ resolve({
356
+ cleanup,
357
+ ip: realIp,
358
+ port: realPort,
359
+ url: `http://${realIp}:${realPort}/v1/graphql`,
360
+ snapshotDir: snapshotDirToUse,
361
+ pid: child.pid
362
+ })
363
+ ),
364
+ 500
365
+ );
366
+ }
367
+ if (/error/i.test(text)) {
368
+ console.log(text);
369
+ reject(new import_errors.FuelError(import_errors.FuelError.CODES.NODE_LAUNCH_FAILED, text));
370
+ }
371
+ });
372
+ process.on("exit", cleanup);
373
+ process.on("SIGINT", cleanup);
374
+ process.on("SIGUSR1", cleanup);
375
+ process.on("SIGUSR2", cleanup);
376
+ process.on("beforeExit", cleanup);
377
+ process.on("uncaughtException", cleanup);
378
+ child.on("error", reject);
379
+ })
380
+ );
381
+
382
+ // src/test-utils/setup-test-provider-and-wallets.ts
383
+ var import_utils41 = require("@fuel-ts/utils");
384
+ var import_ramda5 = require("ramda");
385
+
386
+ // src/providers/coin-quantity.ts
387
+ var import_math2 = require("@fuel-ts/math");
388
+ var import_utils3 = require("@fuel-ts/utils");
79
389
  var coinQuantityfy = (coinQuantityLike) => {
80
390
  let assetId;
81
391
  let amount;
@@ -89,11 +399,11 @@ var coinQuantityfy = (coinQuantityLike) => {
89
399
  assetId = coinQuantityLike.assetId;
90
400
  max = coinQuantityLike.max ?? void 0;
91
401
  }
92
- const bnAmount = (0, import_math.bn)(amount);
402
+ const bnAmount = (0, import_math2.bn)(amount);
93
403
  return {
94
- assetId: (0, import_utils.hexlify)(assetId),
95
- amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
96
- max: max ? (0, import_math.bn)(max) : void 0
404
+ assetId: (0, import_utils3.hexlify)(assetId),
405
+ amount: bnAmount.lt(1) ? (0, import_math2.bn)(1) : bnAmount,
406
+ max: max ? (0, import_math2.bn)(max) : void 0
97
407
  };
98
408
  };
99
409
  var addAmountToCoinQuantities = (params) => {
@@ -109,26 +419,18 @@ var addAmountToCoinQuantities = (params) => {
109
419
  };
110
420
 
111
421
  // src/providers/provider.ts
112
- var import_address3 = require("@fuel-ts/address");
113
- var import_errors14 = require("@fuel-ts/errors");
114
- var import_math17 = require("@fuel-ts/math");
422
+ var import_address4 = require("@fuel-ts/address");
423
+ var import_errors16 = require("@fuel-ts/errors");
424
+ var import_math19 = require("@fuel-ts/math");
115
425
  var import_transactions20 = require("@fuel-ts/transactions");
116
- var import_utils23 = require("@fuel-ts/utils");
426
+ var import_utils26 = require("@fuel-ts/utils");
117
427
  var import_versions = require("@fuel-ts/versions");
118
- var import_utils24 = require("@noble/curves/abstract/utils");
428
+ var import_utils27 = require("@noble/curves/abstract/utils");
119
429
  var import_graphql_request = require("graphql-request");
120
430
  var import_ramda3 = require("ramda");
121
431
 
122
432
  // src/providers/__generated__/operations.ts
123
433
  var import_graphql_tag = __toESM(require("graphql-tag"));
124
- var TransactionStatusSubscriptionFragmentDoc = import_graphql_tag.default`
125
- fragment transactionStatusSubscriptionFragment on TransactionStatus {
126
- type: __typename
127
- ... on SqueezedOutStatus {
128
- reason
129
- }
130
- }
131
- `;
132
434
  var SubmittedStatusFragmentDoc = import_graphql_tag.default`
133
435
  fragment SubmittedStatusFragment on SubmittedStatus {
134
436
  type: __typename
@@ -185,6 +487,47 @@ var SuccessStatusFragmentDoc = import_graphql_tag.default`
185
487
  totalFee
186
488
  }
187
489
  ${ReceiptFragmentDoc}`;
490
+ var MalleableTransactionFieldsFragmentDoc = import_graphql_tag.default`
491
+ fragment malleableTransactionFieldsFragment on Transaction {
492
+ receiptsRoot
493
+ inputs {
494
+ type: __typename
495
+ ... on InputCoin {
496
+ txPointer
497
+ }
498
+ ... on InputContract {
499
+ txPointer
500
+ }
501
+ }
502
+ outputs {
503
+ type: __typename
504
+ ... on CoinOutput {
505
+ to
506
+ amount
507
+ assetId
508
+ }
509
+ ... on ContractOutput {
510
+ inputIndex
511
+ balanceRoot
512
+ stateRoot
513
+ }
514
+ ... on ChangeOutput {
515
+ to
516
+ amount
517
+ assetId
518
+ }
519
+ ... on VariableOutput {
520
+ to
521
+ amount
522
+ assetId
523
+ }
524
+ ... on ContractCreated {
525
+ contract
526
+ stateRoot
527
+ }
528
+ }
529
+ }
530
+ `;
188
531
  var FailureStatusFragmentDoc = import_graphql_tag.default`
189
532
  fragment FailureStatusFragment on FailureStatus {
190
533
  type: __typename
@@ -206,6 +549,32 @@ var SqueezedOutStatusFragmentDoc = import_graphql_tag.default`
206
549
  reason
207
550
  }
208
551
  `;
552
+ var TransactionStatusSubscriptionFragmentDoc = import_graphql_tag.default`
553
+ fragment transactionStatusSubscriptionFragment on TransactionStatus {
554
+ ... on SubmittedStatus {
555
+ ...SubmittedStatusFragment
556
+ }
557
+ ... on SuccessStatus {
558
+ ...SuccessStatusFragment
559
+ transaction {
560
+ ...malleableTransactionFieldsFragment
561
+ }
562
+ }
563
+ ... on FailureStatus {
564
+ ...FailureStatusFragment
565
+ transaction {
566
+ ...malleableTransactionFieldsFragment
567
+ }
568
+ }
569
+ ... on SqueezedOutStatus {
570
+ ...SqueezedOutStatusFragment
571
+ }
572
+ }
573
+ ${SubmittedStatusFragmentDoc}
574
+ ${SuccessStatusFragmentDoc}
575
+ ${MalleableTransactionFieldsFragmentDoc}
576
+ ${FailureStatusFragmentDoc}
577
+ ${SqueezedOutStatusFragmentDoc}`;
209
578
  var TransactionStatusFragmentDoc = import_graphql_tag.default`
210
579
  fragment transactionStatusFragment on TransactionStatus {
211
580
  ... on SubmittedStatus {
@@ -546,6 +915,12 @@ var GasCostsFragmentDoc = import_graphql_tag.default`
546
915
  alocDependentCost {
547
916
  ...DependentCostFragment
548
917
  }
918
+ bldd {
919
+ ...DependentCostFragment
920
+ }
921
+ bsiz {
922
+ ...DependentCostFragment
923
+ }
549
924
  cfe {
550
925
  ...DependentCostFragment
551
926
  }
@@ -564,6 +939,9 @@ var GasCostsFragmentDoc = import_graphql_tag.default`
564
939
  csiz {
565
940
  ...DependentCostFragment
566
941
  }
942
+ ed19DependentCost {
943
+ ...DependentCostFragment
944
+ }
567
945
  k256 {
568
946
  ...DependentCostFragment
569
947
  }
@@ -1092,15 +1470,14 @@ function getSdk(requester) {
1092
1470
  }
1093
1471
 
1094
1472
  // src/providers/fuel-graphql-subscriber.ts
1095
- var import_errors = require("@fuel-ts/errors");
1473
+ var import_errors2 = require("@fuel-ts/errors");
1096
1474
  var import_graphql = require("graphql");
1097
1475
  var _FuelGraphqlSubscriber = class {
1098
- constructor(options) {
1099
- this.options = options;
1476
+ constructor(stream) {
1477
+ this.stream = stream;
1100
1478
  }
1101
- stream;
1102
- async setStream() {
1103
- const { url, query, variables, fetchFn } = this.options;
1479
+ static async create(options) {
1480
+ const { url, query, variables, fetchFn } = options;
1104
1481
  const response = await fetchFn(`${url}-sub`, {
1105
1482
  method: "POST",
1106
1483
  body: JSON.stringify({
@@ -1112,20 +1489,17 @@ var _FuelGraphqlSubscriber = class {
1112
1489
  Accept: "text/event-stream"
1113
1490
  }
1114
1491
  });
1115
- this.stream = response.body.getReader();
1492
+ return new _FuelGraphqlSubscriber(response.body.getReader());
1116
1493
  }
1117
1494
  events = [];
1118
1495
  parsingLeftover = "";
1119
1496
  async next() {
1120
- if (!this.stream) {
1121
- await this.setStream();
1122
- }
1123
1497
  while (true) {
1124
1498
  if (this.events.length > 0) {
1125
1499
  const { data, errors } = this.events.shift();
1126
1500
  if (Array.isArray(errors)) {
1127
- throw new import_errors.FuelError(
1128
- import_errors.FuelError.CODES.INVALID_REQUEST,
1501
+ throw new import_errors2.FuelError(
1502
+ import_errors2.FuelError.CODES.INVALID_REQUEST,
1129
1503
  errors.map((err) => err.message).join("\n\n")
1130
1504
  );
1131
1505
  }
@@ -1146,8 +1520,8 @@ var _FuelGraphqlSubscriber = class {
1146
1520
  try {
1147
1521
  this.events.push(JSON.parse(match.replace(/^data:/, "")));
1148
1522
  } catch (e) {
1149
- throw new import_errors.FuelError(
1150
- import_errors.ErrorCode.STREAM_PARSING_ERROR,
1523
+ throw new import_errors2.FuelError(
1524
+ import_errors2.ErrorCode.STREAM_PARSING_ERROR,
1151
1525
  `Error while parsing stream data response: ${text}`
1152
1526
  );
1153
1527
  }
@@ -1170,95 +1544,98 @@ var _FuelGraphqlSubscriber = class {
1170
1544
  var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
1171
1545
  __publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
1172
1546
 
1173
- // src/providers/memory-cache.ts
1174
- var import_errors2 = require("@fuel-ts/errors");
1175
- var import_utils2 = require("@fuel-ts/utils");
1176
- var cache = {};
1177
- var DEFAULT_TTL_IN_MS = 30 * 1e3;
1178
- var MemoryCache = class {
1547
+ // src/providers/resource-cache.ts
1548
+ var import_errors3 = require("@fuel-ts/errors");
1549
+ var import_utils4 = require("@fuel-ts/utils");
1550
+ var cache = /* @__PURE__ */ new Map();
1551
+ var ResourceCache = class {
1179
1552
  ttl;
1180
- constructor(ttlInMs = DEFAULT_TTL_IN_MS) {
1181
- this.ttl = ttlInMs;
1182
- if (typeof ttlInMs !== "number" || this.ttl <= 0) {
1183
- throw new import_errors2.FuelError(
1184
- import_errors2.ErrorCode.INVALID_TTL,
1553
+ constructor(ttl) {
1554
+ this.ttl = ttl;
1555
+ if (typeof ttl !== "number" || this.ttl <= 0) {
1556
+ throw new import_errors3.FuelError(
1557
+ import_errors3.ErrorCode.INVALID_TTL,
1185
1558
  `Invalid TTL: ${this.ttl}. Use a value greater than zero.`
1186
1559
  );
1187
1560
  }
1188
1561
  }
1189
- get(value, isAutoExpiring = true) {
1190
- const key = (0, import_utils2.hexlify)(value);
1191
- if (cache[key]) {
1192
- if (!isAutoExpiring || cache[key].expires > Date.now()) {
1193
- return cache[key].value;
1194
- }
1195
- this.del(value);
1196
- }
1197
- return void 0;
1198
- }
1199
- set(value) {
1200
- const expiresAt = Date.now() + this.ttl;
1201
- const key = (0, import_utils2.hexlify)(value);
1202
- cache[key] = {
1203
- expires: expiresAt,
1204
- value
1562
+ // Add resources to the cache
1563
+ set(transactionId, resources) {
1564
+ const currentTime = Date.now();
1565
+ const existingResources = cache.get(transactionId) || {
1566
+ utxos: /* @__PURE__ */ new Set(),
1567
+ messages: /* @__PURE__ */ new Set(),
1568
+ timestamp: currentTime
1205
1569
  };
1206
- return expiresAt;
1570
+ resources.utxos.forEach((utxo) => existingResources.utxos.add((0, import_utils4.hexlify)(utxo)));
1571
+ resources.messages.forEach((message) => existingResources.messages.add((0, import_utils4.hexlify)(message)));
1572
+ cache.set(transactionId, existingResources);
1207
1573
  }
1208
- getAllData() {
1209
- return Object.keys(cache).reduce((list, key) => {
1210
- const data = this.get(key, false);
1211
- if (data) {
1212
- list.push(data);
1213
- }
1214
- return list;
1215
- }, []);
1574
+ // Remove resources from the cache for a given transaction ID
1575
+ unset(transactionId) {
1576
+ cache.delete(transactionId);
1216
1577
  }
1578
+ // Get all cached resources and remove expired ones
1217
1579
  getActiveData() {
1218
- return Object.keys(cache).reduce((list, key) => {
1219
- const data = this.get(key);
1220
- if (data) {
1221
- list.push(data);
1580
+ const allResources = { utxos: [], messages: [] };
1581
+ const currentTime = Date.now();
1582
+ cache.forEach((resource, transactionId) => {
1583
+ if (currentTime - resource.timestamp < this.ttl) {
1584
+ allResources.utxos.push(...resource.utxos);
1585
+ allResources.messages.push(...resource.messages);
1586
+ } else {
1587
+ cache.delete(transactionId);
1588
+ }
1589
+ });
1590
+ return allResources;
1591
+ }
1592
+ // Check if a UTXO ID or message nonce is already cached and not expired
1593
+ isCached(key) {
1594
+ const currentTime = Date.now();
1595
+ for (const [transactionId, resourceData] of cache.entries()) {
1596
+ if (currentTime - resourceData.timestamp > this.ttl) {
1597
+ cache.delete(transactionId);
1598
+ } else if (resourceData.utxos.has(key) || resourceData.messages.has(key)) {
1599
+ return true;
1222
1600
  }
1223
- return list;
1224
- }, []);
1601
+ }
1602
+ return false;
1225
1603
  }
1226
- del(value) {
1227
- const key = (0, import_utils2.hexlify)(value);
1228
- delete cache[key];
1604
+ clear() {
1605
+ cache.clear();
1229
1606
  }
1230
1607
  };
1231
1608
 
1232
1609
  // src/providers/transaction-request/input.ts
1233
- var import_abi_coder = require("@fuel-ts/abi-coder");
1610
+ var import_abi_coder2 = require("@fuel-ts/abi-coder");
1234
1611
  var import_configs = require("@fuel-ts/address/configs");
1235
- var import_errors3 = require("@fuel-ts/errors");
1236
- var import_math2 = require("@fuel-ts/math");
1612
+ var import_errors4 = require("@fuel-ts/errors");
1613
+ var import_math3 = require("@fuel-ts/math");
1237
1614
  var import_transactions = require("@fuel-ts/transactions");
1238
- var import_utils3 = require("@fuel-ts/utils");
1615
+ var import_utils5 = require("@fuel-ts/utils");
1239
1616
  var inputify = (value) => {
1240
1617
  const { type } = value;
1241
1618
  switch (value.type) {
1242
1619
  case import_transactions.InputType.Coin: {
1243
- const predicate = (0, import_utils3.arrayify)(value.predicate ?? "0x");
1244
- const predicateData = (0, import_utils3.arrayify)(value.predicateData ?? "0x");
1620
+ const predicate = (0, import_utils5.arrayify)(value.predicate ?? "0x");
1621
+ const predicateData = (0, import_utils5.arrayify)(value.predicateData ?? "0x");
1245
1622
  return {
1246
1623
  type: import_transactions.InputType.Coin,
1247
- txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, import_abi_coder.BYTES_32)),
1248
- outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(import_abi_coder.BYTES_32, import_abi_coder.UTXO_ID_LEN)),
1249
- owner: (0, import_utils3.hexlify)(value.owner),
1250
- amount: (0, import_math2.bn)(value.amount),
1251
- assetId: (0, import_utils3.hexlify)(value.assetId),
1624
+ txID: (0, import_utils5.hexlify)((0, import_utils5.arrayify)(value.id).slice(0, import_abi_coder2.BYTES_32)),
1625
+ outputIndex: (0, import_math3.toNumber)((0, import_utils5.arrayify)(value.id).slice(import_abi_coder2.BYTES_32, import_abi_coder2.UTXO_ID_LEN)),
1626
+ owner: (0, import_utils5.hexlify)(value.owner),
1627
+ amount: (0, import_math3.bn)(value.amount),
1628
+ assetId: (0, import_utils5.hexlify)(value.assetId),
1252
1629
  txPointer: {
1253
- blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
1254
- txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
1630
+ blockHeight: (0, import_math3.toNumber)((0, import_utils5.arrayify)(value.txPointer).slice(0, 8)),
1631
+ txIndex: (0, import_math3.toNumber)((0, import_utils5.arrayify)(value.txPointer).slice(8, 16))
1255
1632
  },
1256
1633
  witnessIndex: value.witnessIndex,
1257
- predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1258
- predicateLength: (0, import_math2.bn)(predicate.length),
1259
- predicateDataLength: (0, import_math2.bn)(predicateData.length),
1260
- predicate: (0, import_utils3.hexlify)(predicate),
1261
- predicateData: (0, import_utils3.hexlify)(predicateData)
1634
+ predicateGasUsed: (0, import_math3.bn)(value.predicateGasUsed),
1635
+ predicateLength: (0, import_math3.bn)(predicate.length),
1636
+ predicateDataLength: (0, import_math3.bn)(predicateData.length),
1637
+ predicate: (0, import_utils5.hexlify)(predicate),
1638
+ predicateData: (0, import_utils5.hexlify)(predicateData)
1262
1639
  };
1263
1640
  }
1264
1641
  case import_transactions.InputType.Contract: {
@@ -1269,35 +1646,35 @@ var inputify = (value) => {
1269
1646
  balanceRoot: import_configs.ZeroBytes32,
1270
1647
  stateRoot: import_configs.ZeroBytes32,
1271
1648
  txPointer: {
1272
- blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
1273
- txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
1649
+ blockHeight: (0, import_math3.toNumber)((0, import_utils5.arrayify)(value.txPointer).slice(0, 8)),
1650
+ txIndex: (0, import_math3.toNumber)((0, import_utils5.arrayify)(value.txPointer).slice(8, 16))
1274
1651
  },
1275
- contractID: (0, import_utils3.hexlify)(value.contractId)
1652
+ contractID: (0, import_utils5.hexlify)(value.contractId)
1276
1653
  };
1277
1654
  }
1278
1655
  case import_transactions.InputType.Message: {
1279
- const predicate = (0, import_utils3.arrayify)(value.predicate ?? "0x");
1280
- const predicateData = (0, import_utils3.arrayify)(value.predicateData ?? "0x");
1281
- const data = (0, import_utils3.arrayify)(value.data ?? "0x");
1656
+ const predicate = (0, import_utils5.arrayify)(value.predicate ?? "0x");
1657
+ const predicateData = (0, import_utils5.arrayify)(value.predicateData ?? "0x");
1658
+ const data = (0, import_utils5.arrayify)(value.data ?? "0x");
1282
1659
  return {
1283
1660
  type: import_transactions.InputType.Message,
1284
- sender: (0, import_utils3.hexlify)(value.sender),
1285
- recipient: (0, import_utils3.hexlify)(value.recipient),
1286
- amount: (0, import_math2.bn)(value.amount),
1287
- nonce: (0, import_utils3.hexlify)(value.nonce),
1661
+ sender: (0, import_utils5.hexlify)(value.sender),
1662
+ recipient: (0, import_utils5.hexlify)(value.recipient),
1663
+ amount: (0, import_math3.bn)(value.amount),
1664
+ nonce: (0, import_utils5.hexlify)(value.nonce),
1288
1665
  witnessIndex: value.witnessIndex,
1289
- predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1290
- predicateLength: (0, import_math2.bn)(predicate.length),
1291
- predicateDataLength: (0, import_math2.bn)(predicateData.length),
1292
- predicate: (0, import_utils3.hexlify)(predicate),
1293
- predicateData: (0, import_utils3.hexlify)(predicateData),
1294
- data: (0, import_utils3.hexlify)(data),
1666
+ predicateGasUsed: (0, import_math3.bn)(value.predicateGasUsed),
1667
+ predicateLength: (0, import_math3.bn)(predicate.length),
1668
+ predicateDataLength: (0, import_math3.bn)(predicateData.length),
1669
+ predicate: (0, import_utils5.hexlify)(predicate),
1670
+ predicateData: (0, import_utils5.hexlify)(predicateData),
1671
+ data: (0, import_utils5.hexlify)(data),
1295
1672
  dataLength: data.length
1296
1673
  };
1297
1674
  }
1298
1675
  default: {
1299
- throw new import_errors3.FuelError(
1300
- import_errors3.ErrorCode.INVALID_TRANSACTION_INPUT,
1676
+ throw new import_errors4.FuelError(
1677
+ import_errors4.ErrorCode.INVALID_TRANSACTION_INPUT,
1301
1678
  `Invalid transaction input type: ${type}.`
1302
1679
  );
1303
1680
  }
@@ -1306,19 +1683,19 @@ var inputify = (value) => {
1306
1683
 
1307
1684
  // src/providers/transaction-request/output.ts
1308
1685
  var import_configs2 = require("@fuel-ts/address/configs");
1309
- var import_errors4 = require("@fuel-ts/errors");
1310
- var import_math3 = require("@fuel-ts/math");
1686
+ var import_errors5 = require("@fuel-ts/errors");
1687
+ var import_math4 = require("@fuel-ts/math");
1311
1688
  var import_transactions2 = require("@fuel-ts/transactions");
1312
- var import_utils4 = require("@fuel-ts/utils");
1689
+ var import_utils6 = require("@fuel-ts/utils");
1313
1690
  var outputify = (value) => {
1314
1691
  const { type } = value;
1315
1692
  switch (type) {
1316
1693
  case import_transactions2.OutputType.Coin: {
1317
1694
  return {
1318
1695
  type: import_transactions2.OutputType.Coin,
1319
- to: (0, import_utils4.hexlify)(value.to),
1320
- amount: (0, import_math3.bn)(value.amount),
1321
- assetId: (0, import_utils4.hexlify)(value.assetId)
1696
+ to: (0, import_utils6.hexlify)(value.to),
1697
+ amount: (0, import_math4.bn)(value.amount),
1698
+ assetId: (0, import_utils6.hexlify)(value.assetId)
1322
1699
  };
1323
1700
  }
1324
1701
  case import_transactions2.OutputType.Contract: {
@@ -1332,29 +1709,29 @@ var outputify = (value) => {
1332
1709
  case import_transactions2.OutputType.Change: {
1333
1710
  return {
1334
1711
  type: import_transactions2.OutputType.Change,
1335
- to: (0, import_utils4.hexlify)(value.to),
1336
- amount: (0, import_math3.bn)(0),
1337
- assetId: (0, import_utils4.hexlify)(value.assetId)
1712
+ to: (0, import_utils6.hexlify)(value.to),
1713
+ amount: (0, import_math4.bn)(0),
1714
+ assetId: (0, import_utils6.hexlify)(value.assetId)
1338
1715
  };
1339
1716
  }
1340
1717
  case import_transactions2.OutputType.Variable: {
1341
1718
  return {
1342
1719
  type: import_transactions2.OutputType.Variable,
1343
1720
  to: import_configs2.ZeroBytes32,
1344
- amount: (0, import_math3.bn)(0),
1721
+ amount: (0, import_math4.bn)(0),
1345
1722
  assetId: import_configs2.ZeroBytes32
1346
1723
  };
1347
1724
  }
1348
1725
  case import_transactions2.OutputType.ContractCreated: {
1349
1726
  return {
1350
1727
  type: import_transactions2.OutputType.ContractCreated,
1351
- contractId: (0, import_utils4.hexlify)(value.contractId),
1352
- stateRoot: (0, import_utils4.hexlify)(value.stateRoot)
1728
+ contractId: (0, import_utils6.hexlify)(value.contractId),
1729
+ stateRoot: (0, import_utils6.hexlify)(value.stateRoot)
1353
1730
  };
1354
1731
  }
1355
1732
  default: {
1356
- throw new import_errors4.FuelError(
1357
- import_errors4.ErrorCode.INVALID_TRANSACTION_INPUT,
1733
+ throw new import_errors5.FuelError(
1734
+ import_errors5.ErrorCode.INVALID_TRANSACTION_INPUT,
1358
1735
  `Invalid transaction output type: ${type}.`
1359
1736
  );
1360
1737
  }
@@ -1362,24 +1739,25 @@ var outputify = (value) => {
1362
1739
  };
1363
1740
 
1364
1741
  // src/providers/transaction-request/transaction-request.ts
1365
- var import_abi_coder2 = require("@fuel-ts/abi-coder");
1366
- var import_address = require("@fuel-ts/address");
1742
+ var import_abi_coder3 = require("@fuel-ts/abi-coder");
1743
+ var import_address2 = require("@fuel-ts/address");
1367
1744
  var import_configs6 = require("@fuel-ts/address/configs");
1368
- var import_crypto = require("@fuel-ts/crypto");
1369
- var import_math8 = require("@fuel-ts/math");
1745
+ var import_crypto3 = require("@fuel-ts/crypto");
1746
+ var import_errors9 = require("@fuel-ts/errors");
1747
+ var import_math9 = require("@fuel-ts/math");
1370
1748
  var import_transactions7 = require("@fuel-ts/transactions");
1371
- var import_utils9 = require("@fuel-ts/utils");
1749
+ var import_utils11 = require("@fuel-ts/utils");
1372
1750
 
1373
1751
  // src/providers/resource.ts
1374
1752
  var isCoin = (resource) => "id" in resource;
1375
1753
 
1376
1754
  // src/providers/utils/receipts.ts
1377
1755
  var import_configs3 = require("@fuel-ts/address/configs");
1378
- var import_errors5 = require("@fuel-ts/errors");
1379
- var import_math4 = require("@fuel-ts/math");
1756
+ var import_errors6 = require("@fuel-ts/errors");
1757
+ var import_math5 = require("@fuel-ts/math");
1380
1758
  var import_transactions3 = require("@fuel-ts/transactions");
1381
1759
  var import_configs4 = require("@fuel-ts/transactions/configs");
1382
- var import_utils5 = require("@fuel-ts/utils");
1760
+ var import_utils7 = require("@fuel-ts/utils");
1383
1761
  var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs4.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
1384
1762
  var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
1385
1763
  var getReceiptsWithMissingData = (receipts) => receipts.reduce(
@@ -1406,13 +1784,13 @@ function assembleReceiptByType(receipt) {
1406
1784
  type: import_transactions3.ReceiptType.Call,
1407
1785
  from: hexOrZero(receipt.id || receipt.contractId),
1408
1786
  to: hexOrZero(receipt?.to),
1409
- amount: (0, import_math4.bn)(receipt.amount),
1787
+ amount: (0, import_math5.bn)(receipt.amount),
1410
1788
  assetId: hexOrZero(receipt.assetId),
1411
- gas: (0, import_math4.bn)(receipt.gas),
1412
- param1: (0, import_math4.bn)(receipt.param1),
1413
- param2: (0, import_math4.bn)(receipt.param2),
1414
- pc: (0, import_math4.bn)(receipt.pc),
1415
- is: (0, import_math4.bn)(receipt.is)
1789
+ gas: (0, import_math5.bn)(receipt.gas),
1790
+ param1: (0, import_math5.bn)(receipt.param1),
1791
+ param2: (0, import_math5.bn)(receipt.param2),
1792
+ pc: (0, import_math5.bn)(receipt.pc),
1793
+ is: (0, import_math5.bn)(receipt.is)
1416
1794
  };
1417
1795
  return callReceipt;
1418
1796
  }
@@ -1420,9 +1798,9 @@ function assembleReceiptByType(receipt) {
1420
1798
  const returnReceipt = {
1421
1799
  type: import_transactions3.ReceiptType.Return,
1422
1800
  id: hexOrZero(receipt.id || receipt.contractId),
1423
- val: (0, import_math4.bn)(receipt.val),
1424
- pc: (0, import_math4.bn)(receipt.pc),
1425
- is: (0, import_math4.bn)(receipt.is)
1801
+ val: (0, import_math5.bn)(receipt.val),
1802
+ pc: (0, import_math5.bn)(receipt.pc),
1803
+ is: (0, import_math5.bn)(receipt.is)
1426
1804
  };
1427
1805
  return returnReceipt;
1428
1806
  }
@@ -1430,11 +1808,11 @@ function assembleReceiptByType(receipt) {
1430
1808
  const returnDataReceipt = {
1431
1809
  type: import_transactions3.ReceiptType.ReturnData,
1432
1810
  id: hexOrZero(receipt.id || receipt.contractId),
1433
- ptr: (0, import_math4.bn)(receipt.ptr),
1434
- len: (0, import_math4.bn)(receipt.len),
1811
+ ptr: (0, import_math5.bn)(receipt.ptr),
1812
+ len: (0, import_math5.bn)(receipt.len),
1435
1813
  digest: hexOrZero(receipt.digest),
1436
- pc: (0, import_math4.bn)(receipt.pc),
1437
- is: (0, import_math4.bn)(receipt.is)
1814
+ pc: (0, import_math5.bn)(receipt.pc),
1815
+ is: (0, import_math5.bn)(receipt.is)
1438
1816
  };
1439
1817
  return returnDataReceipt;
1440
1818
  }
@@ -1442,9 +1820,9 @@ function assembleReceiptByType(receipt) {
1442
1820
  const panicReceipt = {
1443
1821
  type: import_transactions3.ReceiptType.Panic,
1444
1822
  id: hexOrZero(receipt.id),
1445
- reason: (0, import_math4.bn)(receipt.reason),
1446
- pc: (0, import_math4.bn)(receipt.pc),
1447
- is: (0, import_math4.bn)(receipt.is),
1823
+ reason: (0, import_math5.bn)(receipt.reason),
1824
+ pc: (0, import_math5.bn)(receipt.pc),
1825
+ is: (0, import_math5.bn)(receipt.is),
1448
1826
  contractId: hexOrZero(receipt.contractId)
1449
1827
  };
1450
1828
  return panicReceipt;
@@ -1453,9 +1831,9 @@ function assembleReceiptByType(receipt) {
1453
1831
  const revertReceipt = {
1454
1832
  type: import_transactions3.ReceiptType.Revert,
1455
1833
  id: hexOrZero(receipt.id || receipt.contractId),
1456
- val: (0, import_math4.bn)(receipt.ra),
1457
- pc: (0, import_math4.bn)(receipt.pc),
1458
- is: (0, import_math4.bn)(receipt.is)
1834
+ val: (0, import_math5.bn)(receipt.ra),
1835
+ pc: (0, import_math5.bn)(receipt.pc),
1836
+ is: (0, import_math5.bn)(receipt.is)
1459
1837
  };
1460
1838
  return revertReceipt;
1461
1839
  }
@@ -1463,12 +1841,12 @@ function assembleReceiptByType(receipt) {
1463
1841
  const logReceipt = {
1464
1842
  type: import_transactions3.ReceiptType.Log,
1465
1843
  id: hexOrZero(receipt.id || receipt.contractId),
1466
- val0: (0, import_math4.bn)(receipt.ra),
1467
- val1: (0, import_math4.bn)(receipt.rb),
1468
- val2: (0, import_math4.bn)(receipt.rc),
1469
- val3: (0, import_math4.bn)(receipt.rd),
1470
- pc: (0, import_math4.bn)(receipt.pc),
1471
- is: (0, import_math4.bn)(receipt.is)
1844
+ val0: (0, import_math5.bn)(receipt.ra),
1845
+ val1: (0, import_math5.bn)(receipt.rb),
1846
+ val2: (0, import_math5.bn)(receipt.rc),
1847
+ val3: (0, import_math5.bn)(receipt.rd),
1848
+ pc: (0, import_math5.bn)(receipt.pc),
1849
+ is: (0, import_math5.bn)(receipt.is)
1472
1850
  };
1473
1851
  return logReceipt;
1474
1852
  }
@@ -1476,13 +1854,13 @@ function assembleReceiptByType(receipt) {
1476
1854
  const logDataReceipt = {
1477
1855
  type: import_transactions3.ReceiptType.LogData,
1478
1856
  id: hexOrZero(receipt.id || receipt.contractId),
1479
- val0: (0, import_math4.bn)(receipt.ra),
1480
- val1: (0, import_math4.bn)(receipt.rb),
1481
- ptr: (0, import_math4.bn)(receipt.ptr),
1482
- len: (0, import_math4.bn)(receipt.len),
1857
+ val0: (0, import_math5.bn)(receipt.ra),
1858
+ val1: (0, import_math5.bn)(receipt.rb),
1859
+ ptr: (0, import_math5.bn)(receipt.ptr),
1860
+ len: (0, import_math5.bn)(receipt.len),
1483
1861
  digest: hexOrZero(receipt.digest),
1484
- pc: (0, import_math4.bn)(receipt.pc),
1485
- is: (0, import_math4.bn)(receipt.is)
1862
+ pc: (0, import_math5.bn)(receipt.pc),
1863
+ is: (0, import_math5.bn)(receipt.is)
1486
1864
  };
1487
1865
  return logDataReceipt;
1488
1866
  }
@@ -1491,10 +1869,10 @@ function assembleReceiptByType(receipt) {
1491
1869
  type: import_transactions3.ReceiptType.Transfer,
1492
1870
  from: hexOrZero(receipt.id || receipt.contractId),
1493
1871
  to: hexOrZero(receipt.toAddress || receipt?.to),
1494
- amount: (0, import_math4.bn)(receipt.amount),
1872
+ amount: (0, import_math5.bn)(receipt.amount),
1495
1873
  assetId: hexOrZero(receipt.assetId),
1496
- pc: (0, import_math4.bn)(receipt.pc),
1497
- is: (0, import_math4.bn)(receipt.is)
1874
+ pc: (0, import_math5.bn)(receipt.pc),
1875
+ is: (0, import_math5.bn)(receipt.is)
1498
1876
  };
1499
1877
  return transferReceipt;
1500
1878
  }
@@ -1503,18 +1881,18 @@ function assembleReceiptByType(receipt) {
1503
1881
  type: import_transactions3.ReceiptType.TransferOut,
1504
1882
  from: hexOrZero(receipt.id || receipt.contractId),
1505
1883
  to: hexOrZero(receipt.toAddress || receipt.to),
1506
- amount: (0, import_math4.bn)(receipt.amount),
1884
+ amount: (0, import_math5.bn)(receipt.amount),
1507
1885
  assetId: hexOrZero(receipt.assetId),
1508
- pc: (0, import_math4.bn)(receipt.pc),
1509
- is: (0, import_math4.bn)(receipt.is)
1886
+ pc: (0, import_math5.bn)(receipt.pc),
1887
+ is: (0, import_math5.bn)(receipt.is)
1510
1888
  };
1511
1889
  return transferOutReceipt;
1512
1890
  }
1513
1891
  case "SCRIPT_RESULT" /* ScriptResult */: {
1514
1892
  const scriptResultReceipt = {
1515
1893
  type: import_transactions3.ReceiptType.ScriptResult,
1516
- result: (0, import_math4.bn)(receipt.result),
1517
- gasUsed: (0, import_math4.bn)(receipt.gasUsed)
1894
+ result: (0, import_math5.bn)(receipt.result),
1895
+ gasUsed: (0, import_math5.bn)(receipt.gasUsed)
1518
1896
  };
1519
1897
  return scriptResultReceipt;
1520
1898
  }
@@ -1522,8 +1900,8 @@ function assembleReceiptByType(receipt) {
1522
1900
  const sender = hexOrZero(receipt.sender);
1523
1901
  const recipient = hexOrZero(receipt.recipient);
1524
1902
  const nonce = hexOrZero(receipt.nonce);
1525
- const amount = (0, import_math4.bn)(receipt.amount);
1526
- const data = receipt.data ? (0, import_utils5.arrayify)(receipt.data) : Uint8Array.from([]);
1903
+ const amount = (0, import_math5.bn)(receipt.amount);
1904
+ const data = receipt.data ? (0, import_utils7.arrayify)(receipt.data) : Uint8Array.from([]);
1527
1905
  const digest = hexOrZero(receipt.digest);
1528
1906
  const messageId = import_transactions3.ReceiptMessageOutCoder.getMessageId({
1529
1907
  sender,
@@ -1553,9 +1931,9 @@ function assembleReceiptByType(receipt) {
1553
1931
  subId,
1554
1932
  contractId,
1555
1933
  assetId,
1556
- val: (0, import_math4.bn)(receipt.val),
1557
- pc: (0, import_math4.bn)(receipt.pc),
1558
- is: (0, import_math4.bn)(receipt.is)
1934
+ val: (0, import_math5.bn)(receipt.val),
1935
+ pc: (0, import_math5.bn)(receipt.pc),
1936
+ is: (0, import_math5.bn)(receipt.is)
1559
1937
  };
1560
1938
  return mintReceipt;
1561
1939
  }
@@ -1568,38 +1946,38 @@ function assembleReceiptByType(receipt) {
1568
1946
  subId,
1569
1947
  contractId,
1570
1948
  assetId,
1571
- val: (0, import_math4.bn)(receipt.val),
1572
- pc: (0, import_math4.bn)(receipt.pc),
1573
- is: (0, import_math4.bn)(receipt.is)
1949
+ val: (0, import_math5.bn)(receipt.val),
1950
+ pc: (0, import_math5.bn)(receipt.pc),
1951
+ is: (0, import_math5.bn)(receipt.is)
1574
1952
  };
1575
1953
  return burnReceipt;
1576
1954
  }
1577
1955
  default:
1578
- throw new import_errors5.FuelError(import_errors5.ErrorCode.INVALID_RECEIPT_TYPE, `Invalid receipt type: ${receiptType}.`);
1956
+ throw new import_errors6.FuelError(import_errors6.ErrorCode.INVALID_RECEIPT_TYPE, `Invalid receipt type: ${receiptType}.`);
1579
1957
  }
1580
1958
  }
1581
1959
 
1582
1960
  // src/providers/utils/block-explorer.ts
1583
- var import_errors6 = require("@fuel-ts/errors");
1961
+ var import_errors7 = require("@fuel-ts/errors");
1584
1962
 
1585
1963
  // src/providers/utils/gas.ts
1586
- var import_math5 = require("@fuel-ts/math");
1964
+ var import_math6 = require("@fuel-ts/math");
1587
1965
  var import_transactions4 = require("@fuel-ts/transactions");
1588
- var import_utils6 = require("@fuel-ts/utils");
1966
+ var import_utils8 = require("@fuel-ts/utils");
1589
1967
  var getGasUsedFromReceipts = (receipts) => {
1590
1968
  const scriptResult = receipts.filter(
1591
1969
  (receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
1592
1970
  );
1593
- const gasUsed = scriptResult.reduce((prev, receipt) => prev.add(receipt.gasUsed), (0, import_math5.bn)(0));
1971
+ const gasUsed = scriptResult.reduce((prev, receipt) => prev.add(receipt.gasUsed), (0, import_math6.bn)(0));
1594
1972
  return gasUsed;
1595
1973
  };
1596
1974
  function resolveGasDependentCosts(byteSize, gasDependentCost) {
1597
- const base = (0, import_math5.bn)(gasDependentCost.base);
1598
- let dependentValue = (0, import_math5.bn)(0);
1975
+ const base = (0, import_math6.bn)(gasDependentCost.base);
1976
+ let dependentValue = (0, import_math6.bn)(0);
1599
1977
  if ("unitsPerGas" in gasDependentCost) {
1600
- dependentValue = (0, import_math5.bn)(byteSize).div((0, import_math5.bn)(gasDependentCost.unitsPerGas));
1978
+ dependentValue = (0, import_math6.bn)(byteSize).div((0, import_math6.bn)(gasDependentCost.unitsPerGas));
1601
1979
  } else {
1602
- dependentValue = (0, import_math5.bn)(byteSize).mul((0, import_math5.bn)(gasDependentCost.gasPerUnit));
1980
+ dependentValue = (0, import_math6.bn)(byteSize).mul((0, import_math6.bn)(gasDependentCost.gasPerUnit));
1603
1981
  }
1604
1982
  return base.add(dependentValue);
1605
1983
  }
@@ -1622,17 +2000,17 @@ function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1622
2000
  const totalGas = chargeableInputs.reduce((total, input) => {
1623
2001
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1624
2002
  return total.add(
1625
- vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
2003
+ vmInitializationCost.add(resolveGasDependentCosts((0, import_utils8.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math6.bn)(input.predicateGasUsed))
1626
2004
  );
1627
2005
  }
1628
2006
  return total.add(gasCosts.ecr1);
1629
- }, (0, import_math5.bn)(0));
2007
+ }, (0, import_math6.bn)(0));
1630
2008
  return totalGas;
1631
2009
  }
1632
2010
  function getMinGas(params) {
1633
2011
  const { gasCosts, gasPerByte, inputs, metadataGas, txBytesSize } = params;
1634
2012
  const vmInitGas = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1635
- const bytesGas = (0, import_math5.bn)(txBytesSize).mul(gasPerByte);
2013
+ const bytesGas = (0, import_math6.bn)(txBytesSize).mul(gasPerByte);
1636
2014
  const inputsGas = gasUsedByInputs(inputs, txBytesSize, gasCosts);
1637
2015
  const minGas = vmInitGas.add(bytesGas).add(inputsGas).add(metadataGas).maxU64();
1638
2016
  return minGas;
@@ -1643,12 +2021,12 @@ function getMaxGas(params) {
1643
2021
  witnessesLength,
1644
2022
  witnessLimit,
1645
2023
  minGas,
1646
- gasLimit = (0, import_math5.bn)(0),
2024
+ gasLimit = (0, import_math6.bn)(0),
1647
2025
  maxGasPerTx
1648
2026
  } = params;
1649
- let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
2027
+ let remainingAllowedWitnessGas = (0, import_math6.bn)(0);
1650
2028
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1651
- remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
2029
+ remainingAllowedWitnessGas = (0, import_math6.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1652
2030
  }
1653
2031
  const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1654
2032
  return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
@@ -1662,7 +2040,7 @@ function calculateMetadataGasForTxCreate({
1662
2040
  const contractRootGas = resolveGasDependentCosts(contractBytesSize, gasCosts.contractRoot);
1663
2041
  const stateRootGas = resolveGasDependentCosts(stateRootSize, gasCosts.stateRoot);
1664
2042
  const txIdGas = resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1665
- const contractIdInputSize = (0, import_math5.bn)(4 + 32 + 32 + 32);
2043
+ const contractIdInputSize = (0, import_math6.bn)(4 + 32 + 32 + 32);
1666
2044
  const contractIdGas = resolveGasDependentCosts(contractIdInputSize, gasCosts.s256);
1667
2045
  const metadataGas = contractRootGas.add(stateRootGas).add(txIdGas).add(contractIdGas);
1668
2046
  return metadataGas.maxU64();
@@ -1673,19 +2051,28 @@ function calculateMetadataGasForTxScript({
1673
2051
  }) {
1674
2052
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1675
2053
  }
2054
+ function calculateMetadataGasForTxBlob({
2055
+ gasCosts,
2056
+ txBytesSize,
2057
+ witnessBytesSize
2058
+ }) {
2059
+ const txId = resolveGasDependentCosts(txBytesSize, gasCosts.s256);
2060
+ const blobLen = resolveGasDependentCosts(witnessBytesSize, gasCosts.s256);
2061
+ return txId.add(blobLen);
2062
+ }
1676
2063
  var calculateGasFee = (params) => {
1677
2064
  const { gas, gasPrice, priceFactor, tip } = params;
1678
- return gas.mul(gasPrice).div(priceFactor).add((0, import_math5.bn)(tip));
2065
+ return gas.mul(gasPrice).div(priceFactor).add((0, import_math6.bn)(tip));
1679
2066
  };
1680
2067
 
1681
2068
  // src/providers/utils/json.ts
1682
- var import_utils7 = require("@fuel-ts/utils");
2069
+ var import_utils9 = require("@fuel-ts/utils");
1683
2070
  var import_ramda = require("ramda");
1684
2071
  function normalize(object) {
1685
2072
  Object.keys(object).forEach((key) => {
1686
2073
  switch (object[key]?.constructor.name) {
1687
2074
  case "Uint8Array":
1688
- object[key] = (0, import_utils7.hexlify)(object[key]);
2075
+ object[key] = (0, import_utils9.hexlify)(object[key]);
1689
2076
  break;
1690
2077
  case "Array":
1691
2078
  object[key] = normalize(object[key]);
@@ -1710,8 +2097,8 @@ function normalizeJSON(root) {
1710
2097
  }
1711
2098
 
1712
2099
  // src/providers/utils/extract-tx-error.ts
1713
- var import_errors7 = require("@fuel-ts/errors");
1714
- var import_math6 = require("@fuel-ts/math");
2100
+ var import_errors8 = require("@fuel-ts/errors");
2101
+ var import_math7 = require("@fuel-ts/math");
1715
2102
  var import_transactions5 = require("@fuel-ts/transactions");
1716
2103
  var import_configs5 = require("@fuel-ts/transactions/configs");
1717
2104
  var assemblePanicError = (statusReason, metadata) => {
@@ -1723,7 +2110,7 @@ You can read more about this error at:
1723
2110
 
1724
2111
  ${import_configs5.PANIC_DOC_URL}#variant.${statusReason}`;
1725
2112
  }
1726
- return new import_errors7.FuelError(import_errors7.ErrorCode.SCRIPT_REVERTED, errorMessage, {
2113
+ return new import_errors8.FuelError(import_errors8.ErrorCode.SCRIPT_REVERTED, errorMessage, {
1727
2114
  ...metadata,
1728
2115
  reason: statusReason
1729
2116
  });
@@ -1734,7 +2121,7 @@ var assembleRevertError = (receipts, logs, metadata) => {
1734
2121
  const revertReceipt = receipts.find(({ type }) => type === import_transactions5.ReceiptType.Revert);
1735
2122
  let reason = "";
1736
2123
  if (revertReceipt) {
1737
- const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
2124
+ const reasonHex = (0, import_math7.bn)(revertReceipt.val).toHex();
1738
2125
  switch (reasonHex) {
1739
2126
  case import_configs5.FAILED_REQUIRE_SIGNAL: {
1740
2127
  reason = "require";
@@ -1762,8 +2149,8 @@ var assembleRevertError = (receipts, logs, metadata) => {
1762
2149
  errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
1763
2150
  break;
1764
2151
  default:
1765
- throw new import_errors7.FuelError(
1766
- import_errors7.ErrorCode.UNKNOWN,
2152
+ throw new import_errors8.FuelError(
2153
+ import_errors8.ErrorCode.UNKNOWN,
1767
2154
  `The transaction reverted with an unknown reason: ${revertReceipt.val}`,
1768
2155
  {
1769
2156
  ...metadata,
@@ -1772,7 +2159,7 @@ var assembleRevertError = (receipts, logs, metadata) => {
1772
2159
  );
1773
2160
  }
1774
2161
  }
1775
- return new import_errors7.FuelError(import_errors7.ErrorCode.SCRIPT_REVERTED, errorMessage, {
2162
+ return new import_errors8.FuelError(import_errors8.ErrorCode.SCRIPT_REVERTED, errorMessage, {
1776
2163
  ...metadata,
1777
2164
  reason
1778
2165
  });
@@ -1805,7 +2192,7 @@ var NoWitnessAtIndexError = class extends Error {
1805
2192
  };
1806
2193
 
1807
2194
  // src/providers/transaction-request/helpers.ts
1808
- var import_math7 = require("@fuel-ts/math");
2195
+ var import_math8 = require("@fuel-ts/math");
1809
2196
  var import_transactions6 = require("@fuel-ts/transactions");
1810
2197
  var isRequestInputCoin = (input) => input.type === import_transactions6.InputType.Coin;
1811
2198
  var isRequestInputMessage = (input) => input.type === import_transactions6.InputType.Message;
@@ -1820,7 +2207,7 @@ var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filte
1820
2207
  return acc.add(input.amount);
1821
2208
  }
1822
2209
  return acc;
1823
- }, (0, import_math7.bn)(0));
2210
+ }, (0, import_math8.bn)(0));
1824
2211
  var cacheRequestInputsResourcesFromOwner = (inputs, owner) => inputs.reduce(
1825
2212
  (acc, input) => {
1826
2213
  if (isRequestInputCoin(input) && input.owner === owner.toB256()) {
@@ -1837,11 +2224,11 @@ var cacheRequestInputsResourcesFromOwner = (inputs, owner) => inputs.reduce(
1837
2224
  );
1838
2225
 
1839
2226
  // src/providers/transaction-request/witness.ts
1840
- var import_utils8 = require("@fuel-ts/utils");
2227
+ var import_utils10 = require("@fuel-ts/utils");
1841
2228
  var witnessify = (value) => {
1842
- const data = (0, import_utils8.arrayify)(value);
2229
+ const data = (0, import_utils10.arrayify)(value);
1843
2230
  return {
1844
- data: (0, import_utils8.hexlify)(data),
2231
+ data: (0, import_utils10.hexlify)(data),
1845
2232
  dataLength: data.length
1846
2233
  };
1847
2234
  };
@@ -1876,10 +2263,10 @@ var BaseTransactionRequest = class {
1876
2263
  outputs,
1877
2264
  witnesses
1878
2265
  } = {}) {
1879
- this.tip = tip ? (0, import_math8.bn)(tip) : void 0;
2266
+ this.tip = tip ? (0, import_math9.bn)(tip) : void 0;
1880
2267
  this.maturity = maturity && maturity > 0 ? maturity : void 0;
1881
- this.witnessLimit = (0, import_utils9.isDefined)(witnessLimit) ? (0, import_math8.bn)(witnessLimit) : void 0;
1882
- this.maxFee = (0, import_math8.bn)(maxFee);
2268
+ this.witnessLimit = (0, import_utils11.isDefined)(witnessLimit) ? (0, import_math9.bn)(witnessLimit) : void 0;
2269
+ this.maxFee = (0, import_math9.bn)(maxFee);
1883
2270
  this.inputs = inputs ?? [];
1884
2271
  this.outputs = outputs ?? [];
1885
2272
  this.witnesses = witnesses ?? [];
@@ -1888,13 +2275,13 @@ var BaseTransactionRequest = class {
1888
2275
  let policyTypes = 0;
1889
2276
  const policies = [];
1890
2277
  const { tip, witnessLimit, maturity } = req;
1891
- if ((0, import_math8.bn)(tip).gt(0)) {
2278
+ if ((0, import_math9.bn)(tip).gt(0)) {
1892
2279
  policyTypes += import_transactions7.PolicyType.Tip;
1893
- policies.push({ data: (0, import_math8.bn)(tip), type: import_transactions7.PolicyType.Tip });
2280
+ policies.push({ data: (0, import_math9.bn)(tip), type: import_transactions7.PolicyType.Tip });
1894
2281
  }
1895
- if ((0, import_utils9.isDefined)(witnessLimit) && (0, import_math8.bn)(witnessLimit).gte(0)) {
2282
+ if ((0, import_utils11.isDefined)(witnessLimit) && (0, import_math9.bn)(witnessLimit).gte(0)) {
1896
2283
  policyTypes += import_transactions7.PolicyType.WitnessLimit;
1897
- policies.push({ data: (0, import_math8.bn)(witnessLimit), type: import_transactions7.PolicyType.WitnessLimit });
2284
+ policies.push({ data: (0, import_math9.bn)(witnessLimit), type: import_transactions7.PolicyType.WitnessLimit });
1898
2285
  }
1899
2286
  if (maturity && maturity > 0) {
1900
2287
  policyTypes += import_transactions7.PolicyType.Maturity;
@@ -1974,7 +2361,7 @@ var BaseTransactionRequest = class {
1974
2361
  * @returns The index of the created witness.
1975
2362
  */
1976
2363
  addEmptyWitness() {
1977
- this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
2364
+ this.addWitness((0, import_utils11.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
1978
2365
  return this.witnesses.length - 1;
1979
2366
  }
1980
2367
  /**
@@ -1984,7 +2371,7 @@ var BaseTransactionRequest = class {
1984
2371
  * @param signature - The signature to update the witness with.
1985
2372
  */
1986
2373
  updateWitnessByOwner(address, signature) {
1987
- const ownerAddress = import_address.Address.fromAddressOrString(address);
2374
+ const ownerAddress = import_address2.Address.fromAddressOrString(address);
1988
2375
  const witnessIndex = this.getCoinInputWitnessIndexByOwner(ownerAddress);
1989
2376
  if (typeof witnessIndex === "number") {
1990
2377
  this.updateWitness(witnessIndex, signature);
@@ -2054,13 +2441,13 @@ var BaseTransactionRequest = class {
2054
2441
  * Returns the witnessIndex of the found CoinInput.
2055
2442
  */
2056
2443
  getCoinInputWitnessIndexByOwner(owner) {
2057
- const ownerAddress = (0, import_address.addressify)(owner);
2444
+ const ownerAddress = (0, import_address2.addressify)(owner);
2058
2445
  const found = this.inputs.find((input) => {
2059
2446
  switch (input.type) {
2060
2447
  case import_transactions7.InputType.Coin:
2061
- return (0, import_utils9.hexlify)(input.owner) === ownerAddress.toB256();
2448
+ return (0, import_utils11.hexlify)(input.owner) === ownerAddress.toB256();
2062
2449
  case import_transactions7.InputType.Message:
2063
- return (0, import_utils9.hexlify)(input.recipient) === ownerAddress.toB256();
2450
+ return (0, import_utils11.hexlify)(input.recipient) === ownerAddress.toB256();
2064
2451
  default:
2065
2452
  return false;
2066
2453
  }
@@ -2164,7 +2551,7 @@ var BaseTransactionRequest = class {
2164
2551
  addCoinOutput(to, amount, assetId) {
2165
2552
  this.pushOutput({
2166
2553
  type: import_transactions7.OutputType.Coin,
2167
- to: (0, import_address.addressify)(to).toB256(),
2554
+ to: (0, import_address2.addressify)(to).toB256(),
2168
2555
  amount,
2169
2556
  assetId
2170
2557
  });
@@ -2180,7 +2567,7 @@ var BaseTransactionRequest = class {
2180
2567
  quantities.map(coinQuantityfy).forEach((quantity) => {
2181
2568
  this.pushOutput({
2182
2569
  type: import_transactions7.OutputType.Coin,
2183
- to: (0, import_address.addressify)(to).toB256(),
2570
+ to: (0, import_address2.addressify)(to).toB256(),
2184
2571
  amount: quantity.amount,
2185
2572
  assetId: quantity.assetId
2186
2573
  });
@@ -2195,12 +2582,12 @@ var BaseTransactionRequest = class {
2195
2582
  */
2196
2583
  addChangeOutput(to, assetId) {
2197
2584
  const changeOutput = this.getChangeOutputs().find(
2198
- (output) => (0, import_utils9.hexlify)(output.assetId) === assetId
2585
+ (output) => (0, import_utils11.hexlify)(output.assetId) === assetId
2199
2586
  );
2200
2587
  if (!changeOutput) {
2201
2588
  this.pushOutput({
2202
2589
  type: import_transactions7.OutputType.Change,
2203
- to: (0, import_address.addressify)(to).toB256(),
2590
+ to: (0, import_address2.addressify)(to).toB256(),
2204
2591
  assetId
2205
2592
  });
2206
2593
  }
@@ -2215,7 +2602,7 @@ var BaseTransactionRequest = class {
2215
2602
  * @hidden
2216
2603
  */
2217
2604
  metadataGas(_gasCosts) {
2218
- throw new Error("Not implemented");
2605
+ throw new import_errors9.FuelError(import_errors9.FuelError.CODES.NOT_IMPLEMENTED, "Not implemented");
2219
2606
  }
2220
2607
  /**
2221
2608
  * @hidden
@@ -2270,26 +2657,27 @@ var BaseTransactionRequest = class {
2270
2657
  const assetInput = findAssetInput(assetId);
2271
2658
  let usedQuantity = quantity;
2272
2659
  if (assetId === baseAssetId) {
2273
- usedQuantity = (0, import_math8.bn)("1000000000000000000");
2660
+ usedQuantity = (0, import_math9.bn)("1000000000000000000");
2274
2661
  }
2275
2662
  if (assetInput && "assetId" in assetInput) {
2276
- assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
2663
+ assetInput.id = (0, import_utils11.hexlify)((0, import_crypto3.randomBytes)(import_abi_coder3.UTXO_ID_LEN));
2277
2664
  assetInput.amount = usedQuantity;
2278
2665
  } else {
2279
2666
  this.addResources([
2280
2667
  {
2281
- id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
2668
+ id: (0, import_utils11.hexlify)((0, import_crypto3.randomBytes)(import_abi_coder3.UTXO_ID_LEN)),
2282
2669
  amount: usedQuantity,
2283
2670
  assetId,
2284
- owner: resourcesOwner || import_address.Address.fromRandom(),
2285
- blockCreated: (0, import_math8.bn)(1),
2286
- txCreatedIdx: (0, import_math8.bn)(1)
2671
+ owner: resourcesOwner || import_address2.Address.fromRandom(),
2672
+ blockCreated: (0, import_math9.bn)(1),
2673
+ txCreatedIdx: (0, import_math9.bn)(1)
2287
2674
  }
2288
2675
  ]);
2289
2676
  }
2290
2677
  };
2291
- updateAssetInput(baseAssetId, (0, import_math8.bn)(1e11));
2678
+ updateAssetInput(baseAssetId, (0, import_math9.bn)(1e11));
2292
2679
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2680
+ return this;
2293
2681
  }
2294
2682
  /**
2295
2683
  * Retrieves an array of CoinQuantity for each coin output present in the transaction.
@@ -2299,7 +2687,7 @@ var BaseTransactionRequest = class {
2299
2687
  */
2300
2688
  getCoinOutputsQuantities() {
2301
2689
  const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
2302
- amount: (0, import_math8.bn)(amount),
2690
+ amount: (0, import_math9.bn)(amount),
2303
2691
  assetId: assetId.toString()
2304
2692
  }));
2305
2693
  return coinsQuantities;
@@ -2329,27 +2717,24 @@ var BaseTransactionRequest = class {
2329
2717
  this.inputs.filter(isRequestInputResource).forEach((i) => {
2330
2718
  const owner = getRequestInputResourceOwner(i);
2331
2719
  const correspondingInput = inputsToExtractGasUsed.find(
2332
- (x) => isRequestInputResourceFromOwner(x, import_address.Address.fromString(String(owner)))
2720
+ (x) => isRequestInputResourceFromOwner(x, import_address2.Address.fromString(String(owner)))
2333
2721
  );
2334
- if (correspondingInput && "predicateGasUsed" in correspondingInput && (0, import_math8.bn)(correspondingInput.predicateGasUsed).gt(0)) {
2722
+ if (correspondingInput && "predicateGasUsed" in correspondingInput && (0, import_math9.bn)(correspondingInput.predicateGasUsed).gt(0)) {
2335
2723
  i.predicateGasUsed = correspondingInput.predicateGasUsed;
2336
2724
  }
2337
2725
  });
2338
2726
  }
2727
+ byteLength() {
2728
+ return this.toTransactionBytes().byteLength;
2729
+ }
2339
2730
  };
2340
2731
 
2341
- // src/providers/transaction-request/create-transaction-request.ts
2342
- var import_configs8 = require("@fuel-ts/address/configs");
2343
- var import_math10 = require("@fuel-ts/math");
2344
- var import_transactions9 = require("@fuel-ts/transactions");
2345
- var import_utils13 = require("@fuel-ts/utils");
2346
-
2347
2732
  // src/providers/transaction-request/hash-transaction.ts
2348
2733
  var import_configs7 = require("@fuel-ts/address/configs");
2349
- var import_hasher = require("@fuel-ts/hasher");
2350
- var import_math9 = require("@fuel-ts/math");
2734
+ var import_hasher2 = require("@fuel-ts/hasher");
2735
+ var import_math10 = require("@fuel-ts/math");
2351
2736
  var import_transactions8 = require("@fuel-ts/transactions");
2352
- var import_utils11 = require("@fuel-ts/utils");
2737
+ var import_utils13 = require("@fuel-ts/utils");
2353
2738
  var import_ramda2 = require("ramda");
2354
2739
  function hashTransaction(transactionRequest, chainId) {
2355
2740
  const transaction = transactionRequest.toTransaction();
@@ -2364,11 +2749,11 @@ function hashTransaction(transactionRequest, chainId) {
2364
2749
  blockHeight: 0,
2365
2750
  txIndex: 0
2366
2751
  };
2367
- inputClone.predicateGasUsed = (0, import_math9.bn)(0);
2752
+ inputClone.predicateGasUsed = (0, import_math10.bn)(0);
2368
2753
  return inputClone;
2369
2754
  }
2370
2755
  case import_transactions8.InputType.Message: {
2371
- inputClone.predicateGasUsed = (0, import_math9.bn)(0);
2756
+ inputClone.predicateGasUsed = (0, import_math10.bn)(0);
2372
2757
  return inputClone;
2373
2758
  }
2374
2759
  case import_transactions8.InputType.Contract: {
@@ -2395,12 +2780,12 @@ function hashTransaction(transactionRequest, chainId) {
2395
2780
  return outputClone;
2396
2781
  }
2397
2782
  case import_transactions8.OutputType.Change: {
2398
- outputClone.amount = (0, import_math9.bn)(0);
2783
+ outputClone.amount = (0, import_math10.bn)(0);
2399
2784
  return outputClone;
2400
2785
  }
2401
2786
  case import_transactions8.OutputType.Variable: {
2402
2787
  outputClone.to = import_configs7.ZeroBytes32;
2403
- outputClone.amount = (0, import_math9.bn)(0);
2788
+ outputClone.amount = (0, import_math10.bn)(0);
2404
2789
  outputClone.assetId = import_configs7.ZeroBytes32;
2405
2790
  return outputClone;
2406
2791
  }
@@ -2410,16 +2795,86 @@ function hashTransaction(transactionRequest, chainId) {
2410
2795
  });
2411
2796
  transaction.witnessesCount = 0;
2412
2797
  transaction.witnesses = [];
2413
- const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
2414
- const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions8.TransactionCoder().encode(transaction)]);
2415
- return (0, import_hasher.sha256)(concatenatedData);
2798
+ const chainIdBytes = (0, import_hasher2.uint64ToBytesBE)(chainId);
2799
+ const concatenatedData = (0, import_utils13.concat)([chainIdBytes, new import_transactions8.TransactionCoder().encode(transaction)]);
2800
+ return (0, import_hasher2.sha256)(concatenatedData);
2416
2801
  }
2417
2802
 
2803
+ // src/providers/transaction-request/blob-transaction-request.ts
2804
+ var BlobTransactionRequest = class extends BaseTransactionRequest {
2805
+ static from(obj) {
2806
+ if (obj instanceof this) {
2807
+ return obj;
2808
+ }
2809
+ return new this(obj);
2810
+ }
2811
+ /** Type of the transaction */
2812
+ type = import_transactions7.TransactionType.Blob;
2813
+ /** Blob ID */
2814
+ blobId;
2815
+ /** Witness index of contract bytecode to create */
2816
+ witnessIndex;
2817
+ /**
2818
+ * Creates an instance `BlobTransactionRequest`.
2819
+ *
2820
+ * @param blobTransactionRequestLike - The initial values for the instance
2821
+ */
2822
+ constructor({ witnessIndex, blobId, ...rest }) {
2823
+ super(rest);
2824
+ this.blobId = blobId;
2825
+ this.witnessIndex = witnessIndex ?? 0;
2826
+ }
2827
+ /**
2828
+ * Converts the transaction request to a `TransactionBlob`.
2829
+ *
2830
+ * @returns The transaction create object.
2831
+ */
2832
+ toTransaction() {
2833
+ const baseTransaction = this.getBaseTransaction();
2834
+ const { witnessIndex, blobId } = this;
2835
+ return {
2836
+ type: import_transactions7.TransactionType.Blob,
2837
+ ...baseTransaction,
2838
+ blobId,
2839
+ witnessIndex
2840
+ };
2841
+ }
2842
+ /**
2843
+ * Gets the Transaction Request by hashing the transaction.
2844
+ *
2845
+ * @param chainId - The chain ID.
2846
+ *
2847
+ * @returns - A hash of the transaction, which is the transaction ID.
2848
+ */
2849
+ getTransactionId(chainId) {
2850
+ return hashTransaction(this, chainId);
2851
+ }
2852
+ /**
2853
+ * Calculates the metadata gas cost for a blob transaction.
2854
+ *
2855
+ * @param gasCosts - gas costs passed from the chain.
2856
+ * @returns metadata gas cost for the blob transaction.
2857
+ */
2858
+ metadataGas(gasCosts) {
2859
+ return calculateMetadataGasForTxBlob({
2860
+ gasCosts,
2861
+ txBytesSize: this.byteSize(),
2862
+ witnessBytesSize: this.witnesses[this.witnessIndex].length
2863
+ });
2864
+ }
2865
+ };
2866
+
2867
+ // src/providers/transaction-request/create-transaction-request.ts
2868
+ var import_configs8 = require("@fuel-ts/address/configs");
2869
+ var import_math11 = require("@fuel-ts/math");
2870
+ var import_transactions9 = require("@fuel-ts/transactions");
2871
+ var import_utils16 = require("@fuel-ts/utils");
2872
+
2418
2873
  // src/providers/transaction-request/storage-slot.ts
2419
- var import_utils12 = require("@fuel-ts/utils");
2874
+ var import_utils15 = require("@fuel-ts/utils");
2420
2875
  var getStorageValue = (value) => {
2421
2876
  const v = new Uint8Array(32);
2422
- v.set((0, import_utils12.arrayify)(value));
2877
+ v.set((0, import_utils15.arrayify)(value));
2423
2878
  return v;
2424
2879
  };
2425
2880
  var storageSlotify = (storageSlot) => {
@@ -2433,8 +2888,8 @@ var storageSlotify = (storageSlot) => {
2433
2888
  value = storageSlot.value;
2434
2889
  }
2435
2890
  return {
2436
- key: (0, import_utils12.hexlify)(key),
2437
- value: (0, import_utils12.hexlify)(getStorageValue(value))
2891
+ key: (0, import_utils15.hexlify)(key),
2892
+ value: (0, import_utils15.hexlify)(getStorageValue(value))
2438
2893
  };
2439
2894
  };
2440
2895
 
@@ -2462,7 +2917,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2462
2917
  constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
2463
2918
  super(rest);
2464
2919
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2465
- this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
2920
+ this.salt = (0, import_utils16.hexlify)(salt ?? import_configs8.ZeroBytes32);
2466
2921
  this.storageSlots = [...storageSlots ?? []];
2467
2922
  }
2468
2923
  /**
@@ -2478,8 +2933,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2478
2933
  type: import_transactions9.TransactionType.Create,
2479
2934
  ...baseTransaction,
2480
2935
  bytecodeWitnessIndex,
2481
- storageSlotsCount: (0, import_math10.bn)(storageSlots.length),
2482
- salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
2936
+ storageSlotsCount: (0, import_math11.bn)(storageSlots.length),
2937
+ salt: this.salt ? (0, import_utils16.hexlify)(this.salt) : import_configs8.ZeroBytes32,
2483
2938
  storageSlots
2484
2939
  };
2485
2940
  }
@@ -2518,7 +2973,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2518
2973
  }
2519
2974
  metadataGas(gasCosts) {
2520
2975
  return calculateMetadataGasForTxCreate({
2521
- contractBytesSize: (0, import_math10.bn)((0, import_utils13.arrayify)(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
2976
+ contractBytesSize: (0, import_math11.bn)((0, import_utils16.arrayify)(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
2522
2977
  gasCosts,
2523
2978
  stateRootSize: this.storageSlots.length,
2524
2979
  txBytesSize: this.byteSize()
@@ -2527,22 +2982,22 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2527
2982
  };
2528
2983
 
2529
2984
  // src/providers/transaction-request/script-transaction-request.ts
2530
- var import_abi_coder3 = require("@fuel-ts/abi-coder");
2531
- var import_address2 = require("@fuel-ts/address");
2985
+ var import_abi_coder4 = require("@fuel-ts/abi-coder");
2986
+ var import_address3 = require("@fuel-ts/address");
2532
2987
  var import_configs9 = require("@fuel-ts/address/configs");
2533
- var import_math11 = require("@fuel-ts/math");
2988
+ var import_math12 = require("@fuel-ts/math");
2534
2989
  var import_transactions10 = require("@fuel-ts/transactions");
2535
- var import_utils15 = require("@fuel-ts/utils");
2990
+ var import_utils18 = require("@fuel-ts/utils");
2536
2991
 
2537
2992
  // src/providers/transaction-request/scripts.ts
2538
- var import_utils14 = require("@fuel-ts/utils");
2993
+ var import_utils17 = require("@fuel-ts/utils");
2539
2994
  var returnZeroScript = {
2540
2995
  /*
2541
2996
  Opcode::RET(REG_ZERO)
2542
2997
  Opcode::NOOP
2543
2998
  */
2544
2999
  // TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
2545
- bytes: (0, import_utils14.arrayify)("0x24000000"),
3000
+ bytes: (0, import_utils17.arrayify)("0x24000000"),
2546
3001
  encodeScriptData: () => new Uint8Array(0)
2547
3002
  };
2548
3003
  var withdrawScript = {
@@ -2556,7 +3011,7 @@ var withdrawScript = {
2556
3011
  00000000 00000000 [amount value]
2557
3012
  */
2558
3013
  // TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
2559
- bytes: (0, import_utils14.arrayify)("0x5040C0105D44C0064C40001124000000"),
3014
+ bytes: (0, import_utils17.arrayify)("0x5040C0105D44C0064C40001124000000"),
2560
3015
  encodeScriptData: () => new Uint8Array(0)
2561
3016
  };
2562
3017
 
@@ -2584,9 +3039,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2584
3039
  */
2585
3040
  constructor({ script, scriptData, gasLimit, ...rest } = {}) {
2586
3041
  super(rest);
2587
- this.gasLimit = (0, import_math11.bn)(gasLimit);
2588
- this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
2589
- this.scriptData = (0, import_utils15.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
3042
+ this.gasLimit = (0, import_math12.bn)(gasLimit);
3043
+ this.script = (0, import_utils18.arrayify)(script ?? returnZeroScript.bytes);
3044
+ this.scriptData = (0, import_utils18.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
2590
3045
  this.abis = rest.abis;
2591
3046
  }
2592
3047
  /**
@@ -2595,17 +3050,17 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2595
3050
  * @returns The transaction script object.
2596
3051
  */
2597
3052
  toTransaction() {
2598
- const script = (0, import_utils15.arrayify)(this.script ?? "0x");
2599
- const scriptData = (0, import_utils15.arrayify)(this.scriptData ?? "0x");
3053
+ const script = (0, import_utils18.arrayify)(this.script ?? "0x");
3054
+ const scriptData = (0, import_utils18.arrayify)(this.scriptData ?? "0x");
2600
3055
  return {
2601
3056
  type: import_transactions10.TransactionType.Script,
2602
3057
  scriptGasLimit: this.gasLimit,
2603
3058
  ...super.getBaseTransaction(),
2604
- scriptLength: (0, import_math11.bn)(script.length),
2605
- scriptDataLength: (0, import_math11.bn)(scriptData.length),
3059
+ scriptLength: (0, import_math12.bn)(script.length),
3060
+ scriptDataLength: (0, import_math12.bn)(scriptData.length),
2606
3061
  receiptsRoot: import_configs9.ZeroBytes32,
2607
- script: (0, import_utils15.hexlify)(script),
2608
- scriptData: (0, import_utils15.hexlify)(scriptData)
3062
+ script: (0, import_utils18.hexlify)(script),
3063
+ scriptData: (0, import_utils18.hexlify)(scriptData)
2609
3064
  };
2610
3065
  }
2611
3066
  /**
@@ -2697,7 +3152,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2697
3152
  * @returns The current instance of the `ScriptTransactionRequest`.
2698
3153
  */
2699
3154
  addContractInputAndOutput(contract) {
2700
- const contractAddress = (0, import_address2.addressify)(contract);
3155
+ const contractAddress = (0, import_address3.addressify)(contract);
2701
3156
  if (this.getContractInputs().find((i) => i.contractId === contractAddress.toB256())) {
2702
3157
  return this;
2703
3158
  }
@@ -2730,7 +3185,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2730
3185
  * @returns The current instance of the `ScriptTransactionRequest`.
2731
3186
  */
2732
3187
  setData(abi, args) {
2733
- const abiInterface = new import_abi_coder3.Interface(abi);
3188
+ const abiInterface = new import_abi_coder4.Interface(abi);
2734
3189
  this.scriptData = abiInterface.functions.main.encodeArguments(args);
2735
3190
  return this;
2736
3191
  }
@@ -2743,10 +3198,10 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2743
3198
  };
2744
3199
 
2745
3200
  // src/providers/transaction-request/utils.ts
2746
- var import_errors9 = require("@fuel-ts/errors");
3201
+ var import_errors11 = require("@fuel-ts/errors");
2747
3202
  var import_transactions11 = require("@fuel-ts/transactions");
2748
3203
  var transactionRequestify = (obj) => {
2749
- if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
3204
+ if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest || obj instanceof BlobTransactionRequest) {
2750
3205
  return obj;
2751
3206
  }
2752
3207
  const { type } = obj;
@@ -2757,30 +3212,35 @@ var transactionRequestify = (obj) => {
2757
3212
  case import_transactions11.TransactionType.Create: {
2758
3213
  return CreateTransactionRequest.from(obj);
2759
3214
  }
3215
+ case import_transactions11.TransactionType.Blob: {
3216
+ return BlobTransactionRequest.from(obj);
3217
+ }
2760
3218
  default: {
2761
- throw new import_errors9.FuelError(
2762
- import_errors9.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,
3219
+ throw new import_errors11.FuelError(
3220
+ import_errors11.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,
2763
3221
  `Unsupported transaction type: ${type}.`
2764
3222
  );
2765
3223
  }
2766
3224
  }
2767
3225
  };
3226
+ var isTransactionTypeScript = (request) => request.type === import_transactions11.TransactionType.Script;
3227
+ var isTransactionTypeCreate = (request) => request.type === import_transactions11.TransactionType.Create;
2768
3228
 
2769
3229
  // src/providers/transaction-response/transaction-response.ts
2770
- var import_errors13 = require("@fuel-ts/errors");
2771
- var import_math16 = require("@fuel-ts/math");
3230
+ var import_errors15 = require("@fuel-ts/errors");
3231
+ var import_math18 = require("@fuel-ts/math");
2772
3232
  var import_transactions19 = require("@fuel-ts/transactions");
2773
- var import_utils20 = require("@fuel-ts/utils");
3233
+ var import_utils23 = require("@fuel-ts/utils");
2774
3234
 
2775
3235
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2776
- var import_math15 = require("@fuel-ts/math");
3236
+ var import_math17 = require("@fuel-ts/math");
2777
3237
  var import_transactions17 = require("@fuel-ts/transactions");
2778
- var import_utils18 = require("@fuel-ts/utils");
3238
+ var import_utils21 = require("@fuel-ts/utils");
2779
3239
 
2780
3240
  // src/providers/transaction-summary/calculate-tx-fee-for-summary.ts
2781
- var import_math12 = require("@fuel-ts/math");
3241
+ var import_math13 = require("@fuel-ts/math");
2782
3242
  var import_transactions12 = require("@fuel-ts/transactions");
2783
- var import_utils16 = require("@fuel-ts/utils");
3243
+ var import_utils19 = require("@fuel-ts/utils");
2784
3244
  var calculateTXFeeForSummary = (params) => {
2785
3245
  const {
2786
3246
  gasPrice,
@@ -2792,19 +3252,19 @@ var calculateTXFeeForSummary = (params) => {
2792
3252
  if (totalFee) {
2793
3253
  return totalFee;
2794
3254
  }
2795
- const gasPerByte = (0, import_math12.bn)(feeParams.gasPerByte);
2796
- const gasPriceFactor = (0, import_math12.bn)(feeParams.gasPriceFactor);
2797
- const transactionBytes = (0, import_utils16.arrayify)(rawPayload);
3255
+ const gasPerByte = (0, import_math13.bn)(feeParams.gasPerByte);
3256
+ const gasPriceFactor = (0, import_math13.bn)(feeParams.gasPriceFactor);
3257
+ const transactionBytes = (0, import_utils19.arrayify)(rawPayload);
2798
3258
  const [transaction] = new import_transactions12.TransactionCoder().decode(transactionBytes, 0);
2799
3259
  const { type, witnesses, inputs, policies } = transaction;
2800
- let metadataGas = (0, import_math12.bn)(0);
2801
- let gasLimit = (0, import_math12.bn)(0);
3260
+ let metadataGas = (0, import_math13.bn)(0);
3261
+ let gasLimit = (0, import_math13.bn)(0);
2802
3262
  if (type !== import_transactions12.TransactionType.Create && type !== import_transactions12.TransactionType.Script) {
2803
- return (0, import_math12.bn)(0);
3263
+ return (0, import_math13.bn)(0);
2804
3264
  }
2805
3265
  if (type === import_transactions12.TransactionType.Create) {
2806
3266
  const { bytecodeWitnessIndex, storageSlots } = transaction;
2807
- const contractBytesSize = (0, import_math12.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
3267
+ const contractBytesSize = (0, import_math13.bn)((0, import_utils19.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
2808
3268
  metadataGas = calculateMetadataGasForTxCreate({
2809
3269
  contractBytesSize,
2810
3270
  gasCosts,
@@ -2823,7 +3283,7 @@ var calculateTXFeeForSummary = (params) => {
2823
3283
  }
2824
3284
  const minGas = getMinGas({
2825
3285
  gasCosts,
2826
- gasPerByte: (0, import_math12.bn)(gasPerByte),
3286
+ gasPerByte: (0, import_math13.bn)(gasPerByte),
2827
3287
  inputs,
2828
3288
  metadataGas,
2829
3289
  txBytesSize: transactionBytes.length
@@ -2849,14 +3309,14 @@ var calculateTXFeeForSummary = (params) => {
2849
3309
 
2850
3310
  // src/providers/transaction-summary/operations.ts
2851
3311
  var import_configs10 = require("@fuel-ts/address/configs");
2852
- var import_errors11 = require("@fuel-ts/errors");
2853
- var import_math13 = require("@fuel-ts/math");
3312
+ var import_errors13 = require("@fuel-ts/errors");
3313
+ var import_math15 = require("@fuel-ts/math");
2854
3314
  var import_transactions15 = require("@fuel-ts/transactions");
2855
3315
 
2856
3316
  // src/providers/transaction-summary/call.ts
2857
- var import_abi_coder4 = require("@fuel-ts/abi-coder");
3317
+ var import_abi_coder5 = require("@fuel-ts/abi-coder");
2858
3318
  var getFunctionCall = ({ abi, receipt }) => {
2859
- const abiInterface = new import_abi_coder4.Interface(abi);
3319
+ const abiInterface = new import_abi_coder5.Interface(abi);
2860
3320
  const callFunctionSelector = receipt.param1.toHex(8);
2861
3321
  const functionFragment = abiInterface.getFunction(callFunctionSelector);
2862
3322
  const inputs = functionFragment.jsonFn.inputs;
@@ -2887,7 +3347,8 @@ var getFunctionCall = ({ abi, receipt }) => {
2887
3347
  };
2888
3348
 
2889
3349
  // src/providers/transaction-summary/input.ts
2890
- var import_errors10 = require("@fuel-ts/errors");
3350
+ var import_errors12 = require("@fuel-ts/errors");
3351
+ var import_math14 = require("@fuel-ts/math");
2891
3352
  var import_transactions13 = require("@fuel-ts/transactions");
2892
3353
  function getInputsByTypes(inputs, types) {
2893
3354
  return inputs.filter((i) => types.includes(i.type));
@@ -2904,17 +3365,47 @@ function getInputsMessage(inputs) {
2904
3365
  function getInputsCoinAndMessage(inputs) {
2905
3366
  return getInputsByTypes(inputs, [import_transactions13.InputType.Coin, import_transactions13.InputType.Message]);
2906
3367
  }
3368
+ function isInputCoin(input) {
3369
+ return input.type === import_transactions13.InputType.Coin;
3370
+ }
2907
3371
  function getInputsContract(inputs) {
2908
3372
  return getInputsByType(inputs, import_transactions13.InputType.Contract);
2909
3373
  }
2910
- function getInputFromAssetId(inputs, assetId) {
3374
+ function findCoinInput(inputs, assetId) {
2911
3375
  const coinInputs = getInputsCoin(inputs);
2912
- const messageInputs = getInputsMessage(inputs);
2913
- const coinInput = coinInputs.find((i) => i.assetId === assetId);
2914
- const messageInput = messageInputs.find(
2915
- (_) => assetId === "0x0000000000000000000000000000000000000000000000000000000000000000"
2916
- );
2917
- return coinInput || messageInput;
3376
+ return coinInputs.find((i) => i.assetId === assetId);
3377
+ }
3378
+ function aggregateInputsAmountsByAssetAndOwner(inputs, baseAssetID) {
3379
+ const aggregated = /* @__PURE__ */ new Map();
3380
+ getInputsCoinAndMessage(inputs).forEach((input) => {
3381
+ const assetId = isInputCoin(input) ? input.assetId : baseAssetID;
3382
+ const owner = isInputCoin(input) ? input.owner : input.recipient;
3383
+ let ownersMap = aggregated.get(assetId);
3384
+ if (!ownersMap) {
3385
+ ownersMap = /* @__PURE__ */ new Map();
3386
+ aggregated.set(assetId, ownersMap);
3387
+ }
3388
+ let ownerBalance = ownersMap.get(owner);
3389
+ if (!ownerBalance) {
3390
+ ownerBalance = new import_math14.BN(0);
3391
+ ownersMap.set(owner, ownerBalance);
3392
+ }
3393
+ ownersMap.set(owner, ownerBalance.add(input.amount));
3394
+ });
3395
+ return aggregated;
3396
+ }
3397
+ function findMessageInput(inputs) {
3398
+ return getInputsMessage(inputs)?.[0];
3399
+ }
3400
+ function getInputFromAssetId(inputs, assetId, isBaseAsset = false) {
3401
+ const coinInput = findCoinInput(inputs, assetId);
3402
+ if (coinInput) {
3403
+ return coinInput;
3404
+ }
3405
+ if (isBaseAsset) {
3406
+ return findMessageInput(inputs);
3407
+ }
3408
+ return void 0;
2918
3409
  }
2919
3410
  function getInputContractFromIndex(inputs, inputIndex) {
2920
3411
  if (inputIndex == null) {
@@ -2925,8 +3416,8 @@ function getInputContractFromIndex(inputs, inputIndex) {
2925
3416
  return void 0;
2926
3417
  }
2927
3418
  if (contractInput.type !== import_transactions13.InputType.Contract) {
2928
- throw new import_errors10.FuelError(
2929
- import_errors10.ErrorCode.INVALID_TRANSACTION_INPUT,
3419
+ throw new import_errors12.FuelError(
3420
+ import_errors12.ErrorCode.INVALID_TRANSACTION_INPUT,
2930
3421
  `Contract input should be of type 'contract'.`
2931
3422
  );
2932
3423
  }
@@ -2972,9 +3463,11 @@ function getTransactionTypeName(transactionType) {
2972
3463
  return "Create" /* Create */;
2973
3464
  case import_transactions15.TransactionType.Script:
2974
3465
  return "Script" /* Script */;
3466
+ case import_transactions15.TransactionType.Blob:
3467
+ return "Blob" /* Blob */;
2975
3468
  default:
2976
- throw new import_errors11.FuelError(
2977
- import_errors11.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,
3469
+ throw new import_errors13.FuelError(
3470
+ import_errors13.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,
2978
3471
  `Unsupported transaction type: ${transactionType}.`
2979
3472
  );
2980
3473
  }
@@ -2998,47 +3491,60 @@ function isTypeUpgrade(transactionType) {
2998
3491
  function isTypeUpload(transactionType) {
2999
3492
  return isType(transactionType, "Upload" /* Upload */);
3000
3493
  }
3494
+ function isTypeBlob(transactionType) {
3495
+ return isType(transactionType, "Blob" /* Blob */);
3496
+ }
3001
3497
  function getReceiptsCall(receipts) {
3002
3498
  return getReceiptsByType(receipts, import_transactions15.ReceiptType.Call);
3003
3499
  }
3004
3500
  function getReceiptsMessageOut(receipts) {
3005
3501
  return getReceiptsByType(receipts, import_transactions15.ReceiptType.MessageOut);
3006
3502
  }
3007
- var mergeAssets = (op1, op2) => {
3503
+ function mergeAssets(op1, op2) {
3008
3504
  const assets1 = op1.assetsSent || [];
3009
3505
  const assets2 = op2.assetsSent || [];
3010
- const filteredAssets = assets2.filter(
3011
- (asset2) => !assets1.some((asset1) => asset1.assetId === asset2.assetId)
3012
- );
3013
- const mergedAssets = assets1.map((asset1) => {
3014
- const matchingAsset = assets2.find((asset2) => asset2.assetId === asset1.assetId);
3015
- if (!matchingAsset) {
3016
- return asset1;
3506
+ const assetMap = /* @__PURE__ */ new Map();
3507
+ assets1.forEach((asset) => {
3508
+ assetMap.set(asset.assetId, { ...asset });
3509
+ });
3510
+ assets2.forEach((asset) => {
3511
+ const existingAsset = assetMap.get(asset.assetId);
3512
+ if (existingAsset) {
3513
+ existingAsset.amount = (0, import_math15.bn)(existingAsset.amount).add(asset.amount);
3514
+ } else {
3515
+ assetMap.set(asset.assetId, { ...asset });
3017
3516
  }
3018
- const mergedAmount = (0, import_math13.bn)(asset1.amount).add(matchingAsset.amount);
3019
- return { ...asset1, amount: mergedAmount };
3020
3517
  });
3021
- return mergedAssets.concat(filteredAssets);
3022
- };
3518
+ return Array.from(assetMap.values());
3519
+ }
3023
3520
  function isSameOperation(a, b) {
3024
3521
  return a.name === b.name && a.from?.address === b.from?.address && a.to?.address === b.to?.address && a.from?.type === b.from?.type && a.to?.type === b.to?.type;
3025
3522
  }
3523
+ function mergeAssetsSent(existing, toAdd) {
3524
+ if (!toAdd.assetsSent?.length) {
3525
+ return existing.assetsSent;
3526
+ }
3527
+ return existing.assetsSent?.length ? mergeAssets(existing, toAdd) : toAdd.assetsSent;
3528
+ }
3529
+ function mergeCalls(existing, toAdd) {
3530
+ if (!toAdd.calls?.length) {
3531
+ return existing.calls;
3532
+ }
3533
+ return [...existing.calls || [], ...toAdd.calls];
3534
+ }
3535
+ function mergeOperations(existing, toAdd) {
3536
+ return {
3537
+ ...existing,
3538
+ assetsSent: mergeAssetsSent(existing, toAdd),
3539
+ calls: mergeCalls(existing, toAdd)
3540
+ };
3541
+ }
3026
3542
  function addOperation(operations, toAdd) {
3027
- const allOperations = [...operations];
3028
- const index = allOperations.findIndex((op) => isSameOperation(op, toAdd));
3029
- if (allOperations[index]) {
3030
- const existentOperation = { ...allOperations[index] };
3031
- if (toAdd.assetsSent?.length) {
3032
- existentOperation.assetsSent = existentOperation.assetsSent?.length ? mergeAssets(existentOperation, toAdd) : toAdd.assetsSent;
3033
- }
3034
- if (toAdd.calls?.length) {
3035
- existentOperation.calls = [...existentOperation.calls || [], ...toAdd.calls];
3036
- }
3037
- allOperations[index] = existentOperation;
3038
- } else {
3039
- allOperations.push(toAdd);
3543
+ const existingIndex = operations.findIndex((op) => isSameOperation(op, toAdd));
3544
+ if (existingIndex === -1) {
3545
+ return [...operations, toAdd];
3040
3546
  }
3041
- return allOperations;
3547
+ return operations.map((op, index) => index === existingIndex ? mergeOperations(op, toAdd) : op);
3042
3548
  }
3043
3549
  function getWithdrawFromFuelOperations({
3044
3550
  inputs,
@@ -3048,7 +3554,7 @@ function getWithdrawFromFuelOperations({
3048
3554
  const messageOutReceipts = getReceiptsMessageOut(receipts);
3049
3555
  const withdrawFromFuelOperations = messageOutReceipts.reduce(
3050
3556
  (prevWithdrawFromFuelOps, receipt) => {
3051
- const input = getInputFromAssetId(inputs, baseAssetId);
3557
+ const input = getInputFromAssetId(inputs, baseAssetId, true);
3052
3558
  if (input) {
3053
3559
  const inputAddress = getInputAccountAddress(input);
3054
3560
  const newWithdrawFromFuelOps = addOperation(prevWithdrawFromFuelOps, {
@@ -3077,65 +3583,80 @@ function getWithdrawFromFuelOperations({
3077
3583
  );
3078
3584
  return withdrawFromFuelOperations;
3079
3585
  }
3586
+ function getContractCalls(contractInput, abiMap, receipt, rawPayload, maxInputs) {
3587
+ const abi = abiMap?.[contractInput.contractID];
3588
+ if (!abi) {
3589
+ return [];
3590
+ }
3591
+ return [
3592
+ getFunctionCall({
3593
+ abi,
3594
+ receipt,
3595
+ rawPayload,
3596
+ maxInputs
3597
+ })
3598
+ ];
3599
+ }
3600
+ function getAssetsSent(receipt) {
3601
+ return receipt.amount?.isZero() ? void 0 : [
3602
+ {
3603
+ amount: receipt.amount,
3604
+ assetId: receipt.assetId
3605
+ }
3606
+ ];
3607
+ }
3608
+ function processCallReceipt(receipt, contractInput, inputs, abiMap, rawPayload, maxInputs, baseAssetId) {
3609
+ const assetId = receipt.assetId === import_configs10.ZeroBytes32 ? baseAssetId : receipt.assetId;
3610
+ const input = getInputFromAssetId(inputs, assetId, assetId === baseAssetId);
3611
+ if (!input) {
3612
+ return [];
3613
+ }
3614
+ const inputAddress = getInputAccountAddress(input);
3615
+ const calls = getContractCalls(contractInput, abiMap, receipt, rawPayload, maxInputs);
3616
+ return [
3617
+ {
3618
+ name: "Contract call" /* contractCall */,
3619
+ from: {
3620
+ type: 1 /* account */,
3621
+ address: inputAddress
3622
+ },
3623
+ to: {
3624
+ type: 0 /* contract */,
3625
+ address: receipt.to
3626
+ },
3627
+ assetsSent: getAssetsSent(receipt),
3628
+ calls
3629
+ }
3630
+ ];
3631
+ }
3080
3632
  function getContractCallOperations({
3081
3633
  inputs,
3082
3634
  outputs,
3083
3635
  receipts,
3084
3636
  abiMap,
3085
3637
  rawPayload,
3086
- maxInputs
3638
+ maxInputs,
3639
+ baseAssetId
3087
3640
  }) {
3088
3641
  const contractCallReceipts = getReceiptsCall(receipts);
3089
3642
  const contractOutputs = getOutputsContract(outputs);
3090
- const contractCallOperations = contractOutputs.reduce((prevOutputCallOps, output) => {
3643
+ return contractOutputs.flatMap((output) => {
3091
3644
  const contractInput = getInputContractFromIndex(inputs, output.inputIndex);
3092
- if (contractInput) {
3093
- const newCallOps = contractCallReceipts.reduce((prevContractCallOps, receipt) => {
3094
- if (receipt.to === contractInput.contractID) {
3095
- const input = getInputFromAssetId(inputs, receipt.assetId);
3096
- if (input) {
3097
- const inputAddress = getInputAccountAddress(input);
3098
- const calls = [];
3099
- const abi = abiMap?.[contractInput.contractID];
3100
- if (abi) {
3101
- calls.push(
3102
- getFunctionCall({
3103
- abi,
3104
- receipt,
3105
- rawPayload,
3106
- maxInputs
3107
- })
3108
- );
3109
- }
3110
- const newContractCallOps = addOperation(prevContractCallOps, {
3111
- name: "Contract call" /* contractCall */,
3112
- from: {
3113
- type: 1 /* account */,
3114
- address: inputAddress
3115
- },
3116
- to: {
3117
- type: 0 /* contract */,
3118
- address: receipt.to
3119
- },
3120
- // if no amount is forwarded to the contract, skip showing assetsSent
3121
- assetsSent: receipt.amount?.isZero() ? void 0 : [
3122
- {
3123
- amount: receipt.amount,
3124
- assetId: receipt.assetId
3125
- }
3126
- ],
3127
- calls
3128
- });
3129
- return newContractCallOps;
3130
- }
3131
- }
3132
- return prevContractCallOps;
3133
- }, prevOutputCallOps);
3134
- return newCallOps;
3645
+ if (!contractInput) {
3646
+ return [];
3135
3647
  }
3136
- return prevOutputCallOps;
3137
- }, []);
3138
- return contractCallOperations;
3648
+ return contractCallReceipts.filter((receipt) => receipt.to === contractInput.contractID).flatMap(
3649
+ (receipt) => processCallReceipt(
3650
+ receipt,
3651
+ contractInput,
3652
+ inputs,
3653
+ abiMap,
3654
+ rawPayload,
3655
+ maxInputs,
3656
+ baseAssetId
3657
+ )
3658
+ );
3659
+ });
3139
3660
  }
3140
3661
  function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
3141
3662
  const { to: toAddress, assetId, amount } = receipt;
@@ -3167,32 +3688,40 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
3167
3688
  function getTransferOperations({
3168
3689
  inputs,
3169
3690
  outputs,
3170
- receipts
3691
+ receipts,
3692
+ baseAssetId
3171
3693
  }) {
3172
3694
  let operations = [];
3173
3695
  const coinOutputs = getOutputsCoin(outputs);
3174
3696
  const contractInputs = getInputsContract(inputs);
3175
3697
  const changeOutputs = getOutputsChange(outputs);
3176
- coinOutputs.forEach((output) => {
3177
- const { amount, assetId, to } = output;
3178
- const changeOutput = changeOutputs.find((change) => change.assetId === assetId);
3179
- if (changeOutput) {
3698
+ const aggregated = aggregateInputsAmountsByAssetAndOwner(inputs, baseAssetId);
3699
+ coinOutputs.forEach(({ amount, assetId, to }) => {
3700
+ const txPayers = aggregated.get(assetId) || /* @__PURE__ */ new Map();
3701
+ let selectedPayer;
3702
+ let fallbackPayer;
3703
+ for (const [address, payedAmount] of txPayers) {
3704
+ if (!fallbackPayer) {
3705
+ fallbackPayer = address;
3706
+ }
3707
+ if (payedAmount.gte(amount)) {
3708
+ selectedPayer = address;
3709
+ break;
3710
+ }
3711
+ }
3712
+ selectedPayer = selectedPayer || fallbackPayer;
3713
+ if (selectedPayer) {
3180
3714
  operations = addOperation(operations, {
3181
3715
  name: "Transfer asset" /* transfer */,
3182
3716
  from: {
3183
3717
  type: 1 /* account */,
3184
- address: changeOutput.to
3718
+ address: selectedPayer
3185
3719
  },
3186
3720
  to: {
3187
3721
  type: 1 /* account */,
3188
3722
  address: to
3189
3723
  },
3190
- assetsSent: [
3191
- {
3192
- assetId,
3193
- amount
3194
- }
3195
- ]
3724
+ assetsSent: [{ assetId, amount }]
3196
3725
  });
3197
3726
  }
3198
3727
  });
@@ -3265,21 +3794,19 @@ function getOperations({
3265
3794
  baseAssetId
3266
3795
  }) {
3267
3796
  if (isTypeCreate(transactionType)) {
3268
- return [
3269
- ...getContractCreatedOperations({ inputs, outputs }),
3270
- ...getTransferOperations({ inputs, outputs, receipts })
3271
- ];
3797
+ return [...getContractCreatedOperations({ inputs, outputs })];
3272
3798
  }
3273
3799
  if (isTypeScript(transactionType)) {
3274
3800
  return [
3275
- ...getTransferOperations({ inputs, outputs, receipts }),
3801
+ ...getTransferOperations({ inputs, outputs, receipts, baseAssetId }),
3276
3802
  ...getContractCallOperations({
3277
3803
  inputs,
3278
3804
  outputs,
3279
3805
  receipts,
3280
3806
  abiMap,
3281
3807
  rawPayload,
3282
- maxInputs
3808
+ maxInputs,
3809
+ baseAssetId
3283
3810
  }),
3284
3811
  ...getWithdrawFromFuelOperations({ inputs, receipts, baseAssetId })
3285
3812
  ];
@@ -3338,8 +3865,8 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
3338
3865
  };
3339
3866
 
3340
3867
  // src/providers/transaction-summary/status.ts
3341
- var import_errors12 = require("@fuel-ts/errors");
3342
- var import_math14 = require("@fuel-ts/math");
3868
+ var import_errors14 = require("@fuel-ts/errors");
3869
+ var import_math16 = require("@fuel-ts/math");
3343
3870
  var getTransactionStatusName = (gqlStatus) => {
3344
3871
  switch (gqlStatus) {
3345
3872
  case "FailureStatus":
@@ -3351,8 +3878,8 @@ var getTransactionStatusName = (gqlStatus) => {
3351
3878
  case "SqueezedOutStatus":
3352
3879
  return "squeezedout" /* squeezedout */;
3353
3880
  default:
3354
- throw new import_errors12.FuelError(
3355
- import_errors12.ErrorCode.INVALID_TRANSACTION_STATUS,
3881
+ throw new import_errors14.FuelError(
3882
+ import_errors14.ErrorCode.INVALID_TRANSACTION_STATUS,
3356
3883
  `Invalid transaction status: ${gqlStatus}.`
3357
3884
  );
3358
3885
  }
@@ -3373,15 +3900,15 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
3373
3900
  time = gqlTransactionStatus.time;
3374
3901
  blockId = gqlTransactionStatus.block.id;
3375
3902
  isStatusSuccess = true;
3376
- totalFee = (0, import_math14.bn)(gqlTransactionStatus.totalFee);
3377
- totalGas = (0, import_math14.bn)(gqlTransactionStatus.totalGas);
3903
+ totalFee = (0, import_math16.bn)(gqlTransactionStatus.totalFee);
3904
+ totalGas = (0, import_math16.bn)(gqlTransactionStatus.totalGas);
3378
3905
  break;
3379
3906
  case "FailureStatus":
3380
3907
  time = gqlTransactionStatus.time;
3381
3908
  blockId = gqlTransactionStatus.block.id;
3382
3909
  isStatusFailure = true;
3383
- totalFee = (0, import_math14.bn)(gqlTransactionStatus.totalFee);
3384
- totalGas = (0, import_math14.bn)(gqlTransactionStatus.totalGas);
3910
+ totalFee = (0, import_math16.bn)(gqlTransactionStatus.totalFee);
3911
+ totalGas = (0, import_math16.bn)(gqlTransactionStatus.totalGas);
3385
3912
  break;
3386
3913
  case "SubmittedStatus":
3387
3914
  time = gqlTransactionStatus.time;
@@ -3421,7 +3948,7 @@ function assembleTransactionSummary(params) {
3421
3948
  baseAssetId
3422
3949
  } = params;
3423
3950
  const gasUsed = getGasUsedFromReceipts(receipts);
3424
- const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
3951
+ const rawPayload = (0, import_utils21.hexlify)(transactionBytes);
3425
3952
  const operations = getOperations({
3426
3953
  transactionType: transaction.type,
3427
3954
  inputs: transaction.inputs || [],
@@ -3433,7 +3960,7 @@ function assembleTransactionSummary(params) {
3433
3960
  baseAssetId
3434
3961
  });
3435
3962
  const typeName = getTransactionTypeName(transaction.type);
3436
- const tip = (0, import_math15.bn)(transaction.policies?.find((policy) => policy.type === import_transactions17.PolicyType.Tip)?.data);
3963
+ const tip = (0, import_math17.bn)(transaction.policies?.find((policy) => policy.type === import_transactions17.PolicyType.Tip)?.data);
3437
3964
  const { isStatusFailure, isStatusPending, isStatusSuccess, blockId, status, time, totalFee } = processGraphqlStatus(gqlTransactionStatus);
3438
3965
  const fee = calculateTXFeeForSummary({
3439
3966
  totalFee,
@@ -3453,7 +3980,7 @@ function assembleTransactionSummary(params) {
3453
3980
  const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
3454
3981
  let date;
3455
3982
  if (time) {
3456
- date = import_utils18.DateTime.fromTai64(time);
3983
+ date = import_utils21.DateTime.fromTai64(time);
3457
3984
  }
3458
3985
  const transactionSummary = {
3459
3986
  id,
@@ -3473,6 +4000,7 @@ function assembleTransactionSummary(params) {
3473
4000
  isTypeScript: isTypeScript(transaction.type),
3474
4001
  isTypeUpgrade: isTypeUpgrade(transaction.type),
3475
4002
  isTypeUpload: isTypeUpload(transaction.type),
4003
+ isTypeBlob: isTypeBlob(transaction.type),
3476
4004
  isStatusFailure,
3477
4005
  isStatusSuccess,
3478
4006
  isStatusPending,
@@ -3483,13 +4011,13 @@ function assembleTransactionSummary(params) {
3483
4011
  }
3484
4012
 
3485
4013
  // src/providers/transaction-response/getDecodedLogs.ts
3486
- var import_abi_coder5 = require("@fuel-ts/abi-coder");
4014
+ var import_abi_coder6 = require("@fuel-ts/abi-coder");
3487
4015
  var import_transactions18 = require("@fuel-ts/transactions");
3488
4016
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3489
4017
  return receipts.reduce((logs, receipt) => {
3490
4018
  if (receipt.type === import_transactions18.ReceiptType.LogData || receipt.type === import_transactions18.ReceiptType.Log) {
3491
- const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
3492
- const data = receipt.type === import_transactions18.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
4019
+ const interfaceToUse = new import_abi_coder6.Interface(externalAbis[receipt.id] || mainAbi);
4020
+ const data = receipt.type === import_transactions18.ReceiptType.Log ? new import_abi_coder6.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3493
4021
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toString());
3494
4022
  logs.push(decodedLog);
3495
4023
  }
@@ -3498,26 +4026,59 @@ function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3498
4026
  }
3499
4027
 
3500
4028
  // src/providers/transaction-response/transaction-response.ts
4029
+ function mapGqlOutputsToTxOutputs(outputs) {
4030
+ return outputs.map((o) => {
4031
+ const obj = "amount" in o ? { ...o, amount: (0, import_math18.bn)(o.amount) } : o;
4032
+ switch (obj.type) {
4033
+ case "CoinOutput":
4034
+ return { ...obj, type: import_transactions19.OutputType.Coin };
4035
+ case "ContractOutput":
4036
+ return {
4037
+ ...obj,
4038
+ type: import_transactions19.OutputType.Contract,
4039
+ inputIndex: parseInt(obj.inputIndex, 10)
4040
+ };
4041
+ case "ChangeOutput":
4042
+ return {
4043
+ ...obj,
4044
+ type: import_transactions19.OutputType.Change
4045
+ };
4046
+ case "VariableOutput":
4047
+ return { ...obj, type: import_transactions19.OutputType.Variable };
4048
+ case "ContractCreated":
4049
+ return {
4050
+ ...obj,
4051
+ type: import_transactions19.OutputType.ContractCreated,
4052
+ contractId: obj.contract
4053
+ };
4054
+ default:
4055
+ return (0, import_utils23.assertUnreachable)(obj);
4056
+ }
4057
+ });
4058
+ }
3501
4059
  var TransactionResponse = class {
3502
4060
  /** Transaction ID */
3503
4061
  id;
3504
4062
  /** Current provider */
3505
4063
  provider;
3506
4064
  /** Gas used on the transaction */
3507
- gasUsed = (0, import_math16.bn)(0);
4065
+ gasUsed = (0, import_math18.bn)(0);
3508
4066
  /** The graphql Transaction with receipts object. */
3509
4067
  gqlTransaction;
4068
+ request;
4069
+ status;
3510
4070
  abis;
3511
4071
  /**
3512
4072
  * Constructor for `TransactionResponse`.
3513
4073
  *
3514
- * @param id - The transaction ID.
4074
+ * @param tx - The transaction ID or TransactionRequest.
3515
4075
  * @param provider - The provider.
3516
4076
  */
3517
- constructor(id, provider, abis) {
3518
- this.id = id;
4077
+ constructor(tx, provider, abis) {
4078
+ this.id = typeof tx === "string" ? tx : tx.getTransactionId(provider.getChainId());
3519
4079
  this.provider = provider;
3520
4080
  this.abis = abis;
4081
+ this.request = typeof tx === "string" ? void 0 : tx;
3521
4082
  }
3522
4083
  /**
3523
4084
  * Async constructor for `TransactionResponse`. This method can be used to create
@@ -3532,6 +4093,54 @@ var TransactionResponse = class {
3532
4093
  await response.fetch();
3533
4094
  return response;
3534
4095
  }
4096
+ applyMalleableSubscriptionFields(transaction) {
4097
+ const status = this.status;
4098
+ if (!status) {
4099
+ return;
4100
+ }
4101
+ const tx = transaction;
4102
+ if (status.type === "SuccessStatus" || status.type === "FailureStatus") {
4103
+ tx.inputs = tx.inputs.map((input, idx) => {
4104
+ if ("txPointer" in input) {
4105
+ const correspondingInput = status.transaction.inputs?.[idx];
4106
+ return {
4107
+ ...input,
4108
+ txPointer: import_transactions19.TxPointerCoder.decodeFromGqlScalar(correspondingInput.txPointer)
4109
+ };
4110
+ }
4111
+ return input;
4112
+ });
4113
+ tx.outputs = mapGqlOutputsToTxOutputs(status.transaction.outputs);
4114
+ if ("receiptsRoot" in status.transaction) {
4115
+ tx.receiptsRoot = status.transaction.receiptsRoot;
4116
+ }
4117
+ }
4118
+ }
4119
+ async getTransaction() {
4120
+ if (this.request) {
4121
+ const tx = this.request.toTransaction();
4122
+ this.applyMalleableSubscriptionFields(tx);
4123
+ return {
4124
+ tx,
4125
+ bytes: this.request.toTransactionBytes()
4126
+ };
4127
+ }
4128
+ const gqlTransaction = this.gqlTransaction ?? await this.fetch();
4129
+ return {
4130
+ tx: this.decodeTransaction(gqlTransaction),
4131
+ bytes: (0, import_utils23.arrayify)(gqlTransaction.rawPayload)
4132
+ };
4133
+ }
4134
+ getReceipts() {
4135
+ const status = this.status ?? this.gqlTransaction?.status;
4136
+ switch (status?.type) {
4137
+ case "SuccessStatus":
4138
+ case "FailureStatus":
4139
+ return status.receipts.map(processGqlReceipt);
4140
+ default:
4141
+ return [];
4142
+ }
4143
+ }
3535
4144
  /**
3536
4145
  * Fetch the transaction with receipts from the provider.
3537
4146
  *
@@ -3542,11 +4151,12 @@ var TransactionResponse = class {
3542
4151
  transactionId: this.id
3543
4152
  });
3544
4153
  if (!response.transaction) {
3545
- const subscription = this.provider.operations.statusChange({
4154
+ const subscription = await this.provider.operations.statusChange({
3546
4155
  transactionId: this.id
3547
4156
  });
3548
4157
  for await (const { statusChange } of subscription) {
3549
4158
  if (statusChange) {
4159
+ this.status = statusChange;
3550
4160
  break;
3551
4161
  }
3552
4162
  }
@@ -3563,7 +4173,7 @@ var TransactionResponse = class {
3563
4173
  */
3564
4174
  decodeTransaction(transactionWithReceipts) {
3565
4175
  return new import_transactions19.TransactionCoder().decode(
3566
- (0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
4176
+ (0, import_utils23.arrayify)(transactionWithReceipts.rawPayload),
3567
4177
  0
3568
4178
  )?.[0];
3569
4179
  }
@@ -3575,28 +4185,17 @@ var TransactionResponse = class {
3575
4185
  * @returns
3576
4186
  */
3577
4187
  async getTransactionSummary(contractsAbiMap) {
3578
- let transaction = this.gqlTransaction;
3579
- if (!transaction) {
3580
- transaction = await this.fetch();
3581
- }
3582
- const decodedTransaction = this.decodeTransaction(
3583
- transaction
3584
- );
3585
- let txReceipts = [];
3586
- if (transaction?.status && "receipts" in transaction.status) {
3587
- txReceipts = transaction.status.receipts;
3588
- }
3589
- const receipts = txReceipts.map(processGqlReceipt) || [];
4188
+ const { tx: transaction, bytes: transactionBytes } = await this.getTransaction();
3590
4189
  const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3591
4190
  const gasPrice = await this.provider.getLatestGasPrice();
3592
4191
  const maxInputs = this.provider.getChain().consensusParameters.txParameters.maxInputs;
3593
4192
  const baseAssetId = this.provider.getBaseAssetId();
3594
4193
  const transactionSummary = assembleTransactionSummary({
3595
4194
  id: this.id,
3596
- receipts,
3597
- transaction: decodedTransaction,
3598
- transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
3599
- gqlTransactionStatus: transaction.status,
4195
+ receipts: this.getReceipts(),
4196
+ transaction,
4197
+ transactionBytes,
4198
+ gqlTransactionStatus: this.status ?? this.gqlTransaction?.status,
3600
4199
  gasPerByte,
3601
4200
  gasPriceFactor,
3602
4201
  abiMap: contractsAbiMap,
@@ -3613,13 +4212,15 @@ var TransactionResponse = class {
3613
4212
  if (status && status !== "SubmittedStatus") {
3614
4213
  return;
3615
4214
  }
3616
- const subscription = this.provider.operations.statusChange({
4215
+ const subscription = await this.provider.operations.statusChange({
3617
4216
  transactionId: this.id
3618
4217
  });
3619
4218
  for await (const { statusChange } of subscription) {
4219
+ this.status = statusChange;
3620
4220
  if (statusChange.type === "SqueezedOutStatus") {
3621
- throw new import_errors13.FuelError(
3622
- import_errors13.ErrorCode.TRANSACTION_SQUEEZED_OUT,
4221
+ this.unsetResourceCache();
4222
+ throw new import_errors15.FuelError(
4223
+ import_errors15.ErrorCode.TRANSACTION_SQUEEZED_OUT,
3623
4224
  `Transaction Squeezed Out with reason: ${statusChange.reason}`
3624
4225
  );
3625
4226
  }
@@ -3627,7 +4228,6 @@ var TransactionResponse = class {
3627
4228
  break;
3628
4229
  }
3629
4230
  }
3630
- await this.fetch();
3631
4231
  }
3632
4232
  /**
3633
4233
  * Assembles the result of a transaction by retrieving the transaction summary,
@@ -3644,7 +4244,6 @@ var TransactionResponse = class {
3644
4244
  async assembleResult(contractsAbiMap) {
3645
4245
  const transactionSummary = await this.getTransactionSummary(contractsAbiMap);
3646
4246
  const transactionResult = {
3647
- gqlTransaction: this.gqlTransaction,
3648
4247
  ...transactionSummary
3649
4248
  };
3650
4249
  let logs = [];
@@ -3656,9 +4255,11 @@ var TransactionResponse = class {
3656
4255
  );
3657
4256
  transactionResult.logs = logs;
3658
4257
  }
3659
- const { gqlTransaction, receipts } = transactionResult;
3660
- if (gqlTransaction.status?.type === "FailureStatus") {
3661
- const { reason } = gqlTransaction.status;
4258
+ const { receipts } = transactionResult;
4259
+ const status = this.status ?? this.gqlTransaction?.status;
4260
+ if (status?.type === "FailureStatus") {
4261
+ this.unsetResourceCache();
4262
+ const { reason } = status;
3662
4263
  throw extractTxError({
3663
4264
  receipts,
3664
4265
  statusReason: reason,
@@ -3684,10 +4285,13 @@ var TransactionResponse = class {
3684
4285
  async wait(contractsAbiMap) {
3685
4286
  return this.waitForResult(contractsAbiMap);
3686
4287
  }
4288
+ unsetResourceCache() {
4289
+ this.provider.cache?.unset(this.id);
4290
+ }
3687
4291
  };
3688
4292
 
3689
4293
  // src/providers/utils/auto-retry-fetch.ts
3690
- var import_utils22 = require("@fuel-ts/utils");
4294
+ var import_utils25 = require("@fuel-ts/utils");
3691
4295
  function getWaitDelay(options, retryAttemptNum) {
3692
4296
  const duration = options.baseDelay ?? 150;
3693
4297
  switch (options.backoff) {
@@ -3717,7 +4321,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
3717
4321
  throw error;
3718
4322
  }
3719
4323
  const delay = getWaitDelay(options, retryNum);
3720
- await (0, import_utils22.sleep)(delay);
4324
+ await (0, import_utils25.sleep)(delay);
3721
4325
  return autoRetryFetch(fetchFn, options, retryNum)(...args);
3722
4326
  }
3723
4327
  };
@@ -3727,7 +4331,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
3727
4331
  var MAX_RETRIES = 10;
3728
4332
  var RESOURCES_PAGE_SIZE_LIMIT = 512;
3729
4333
  var BLOCKS_PAGE_SIZE_LIMIT = 5;
3730
- var DEFAULT_UTXOS_CACHE_TTL = 2e4;
4334
+ var DEFAULT_RESOURCE_CACHE_TTL = 2e4;
3731
4335
  var processGqlChain = (chain) => {
3732
4336
  const { name, daHeight, consensusParameters, latestBlock } = chain;
3733
4337
  const {
@@ -3743,47 +4347,47 @@ var processGqlChain = (chain) => {
3743
4347
  } = consensusParameters;
3744
4348
  return {
3745
4349
  name,
3746
- baseChainHeight: (0, import_math17.bn)(daHeight),
4350
+ baseChainHeight: (0, import_math19.bn)(daHeight),
3747
4351
  consensusParameters: {
3748
4352
  version,
3749
- chainId: (0, import_math17.bn)(chainId),
4353
+ chainId: (0, import_math19.bn)(chainId),
3750
4354
  baseAssetId,
3751
4355
  feeParameters: {
3752
4356
  version: feeParams.version,
3753
- gasPerByte: (0, import_math17.bn)(feeParams.gasPerByte),
3754
- gasPriceFactor: (0, import_math17.bn)(feeParams.gasPriceFactor)
4357
+ gasPerByte: (0, import_math19.bn)(feeParams.gasPerByte),
4358
+ gasPriceFactor: (0, import_math19.bn)(feeParams.gasPriceFactor)
3755
4359
  },
3756
4360
  contractParameters: {
3757
4361
  version: contractParams.version,
3758
- contractMaxSize: (0, import_math17.bn)(contractParams.contractMaxSize),
3759
- maxStorageSlots: (0, import_math17.bn)(contractParams.maxStorageSlots)
4362
+ contractMaxSize: (0, import_math19.bn)(contractParams.contractMaxSize),
4363
+ maxStorageSlots: (0, import_math19.bn)(contractParams.maxStorageSlots)
3760
4364
  },
3761
4365
  txParameters: {
3762
4366
  version: txParams.version,
3763
- maxInputs: (0, import_math17.bn)(txParams.maxInputs),
3764
- maxOutputs: (0, import_math17.bn)(txParams.maxOutputs),
3765
- maxWitnesses: (0, import_math17.bn)(txParams.maxWitnesses),
3766
- maxGasPerTx: (0, import_math17.bn)(txParams.maxGasPerTx),
3767
- maxSize: (0, import_math17.bn)(txParams.maxSize),
3768
- maxBytecodeSubsections: (0, import_math17.bn)(txParams.maxBytecodeSubsections)
4367
+ maxInputs: (0, import_math19.bn)(txParams.maxInputs),
4368
+ maxOutputs: (0, import_math19.bn)(txParams.maxOutputs),
4369
+ maxWitnesses: (0, import_math19.bn)(txParams.maxWitnesses),
4370
+ maxGasPerTx: (0, import_math19.bn)(txParams.maxGasPerTx),
4371
+ maxSize: (0, import_math19.bn)(txParams.maxSize),
4372
+ maxBytecodeSubsections: (0, import_math19.bn)(txParams.maxBytecodeSubsections)
3769
4373
  },
3770
4374
  predicateParameters: {
3771
4375
  version: predicateParams.version,
3772
- maxPredicateLength: (0, import_math17.bn)(predicateParams.maxPredicateLength),
3773
- maxPredicateDataLength: (0, import_math17.bn)(predicateParams.maxPredicateDataLength),
3774
- maxGasPerPredicate: (0, import_math17.bn)(predicateParams.maxGasPerPredicate),
3775
- maxMessageDataLength: (0, import_math17.bn)(predicateParams.maxMessageDataLength)
4376
+ maxPredicateLength: (0, import_math19.bn)(predicateParams.maxPredicateLength),
4377
+ maxPredicateDataLength: (0, import_math19.bn)(predicateParams.maxPredicateDataLength),
4378
+ maxGasPerPredicate: (0, import_math19.bn)(predicateParams.maxGasPerPredicate),
4379
+ maxMessageDataLength: (0, import_math19.bn)(predicateParams.maxMessageDataLength)
3776
4380
  },
3777
4381
  scriptParameters: {
3778
4382
  version: scriptParams.version,
3779
- maxScriptLength: (0, import_math17.bn)(scriptParams.maxScriptLength),
3780
- maxScriptDataLength: (0, import_math17.bn)(scriptParams.maxScriptDataLength)
4383
+ maxScriptLength: (0, import_math19.bn)(scriptParams.maxScriptLength),
4384
+ maxScriptDataLength: (0, import_math19.bn)(scriptParams.maxScriptDataLength)
3781
4385
  },
3782
4386
  gasCosts
3783
4387
  },
3784
4388
  latestBlock: {
3785
4389
  id: latestBlock.id,
3786
- height: (0, import_math17.bn)(latestBlock.height),
4390
+ height: (0, import_math19.bn)(latestBlock.height),
3787
4391
  time: latestBlock.header.time,
3788
4392
  transactions: latestBlock.transactions.map((i) => ({
3789
4393
  id: i.id
@@ -3810,22 +4414,22 @@ var _Provider = class {
3810
4414
  __publicField(this, "cache");
3811
4415
  __publicField(this, "options", {
3812
4416
  timeout: void 0,
3813
- cacheUtxo: void 0,
4417
+ resourceCacheTTL: void 0,
3814
4418
  fetch: void 0,
3815
4419
  retryOptions: void 0
3816
4420
  });
3817
4421
  this.options = { ...this.options, ...options };
3818
4422
  this.url = url;
3819
4423
  this.operations = this.createOperations();
3820
- const { cacheUtxo } = this.options;
3821
- if ((0, import_utils23.isDefined)(cacheUtxo)) {
3822
- if (cacheUtxo !== -1) {
3823
- this.cache = new MemoryCache(cacheUtxo);
4424
+ const { resourceCacheTTL } = this.options;
4425
+ if ((0, import_utils26.isDefined)(resourceCacheTTL)) {
4426
+ if (resourceCacheTTL !== -1) {
4427
+ this.cache = new ResourceCache(resourceCacheTTL);
3824
4428
  } else {
3825
4429
  this.cache = void 0;
3826
4430
  }
3827
4431
  } else {
3828
- this.cache = new MemoryCache(DEFAULT_UTXOS_CACHE_TTL);
4432
+ this.cache = new ResourceCache(DEFAULT_RESOURCE_CACHE_TTL);
3829
4433
  }
3830
4434
  }
3831
4435
  /** @hidden */
@@ -3870,8 +4474,8 @@ var _Provider = class {
3870
4474
  getChain() {
3871
4475
  const chain = _Provider.chainInfoCache[this.url];
3872
4476
  if (!chain) {
3873
- throw new import_errors14.FuelError(
3874
- import_errors14.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
4477
+ throw new import_errors16.FuelError(
4478
+ import_errors16.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
3875
4479
  "Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
3876
4480
  );
3877
4481
  }
@@ -3885,8 +4489,8 @@ var _Provider = class {
3885
4489
  getNode() {
3886
4490
  const node = _Provider.nodeInfoCache[this.url];
3887
4491
  if (!node) {
3888
- throw new import_errors14.FuelError(
3889
- import_errors14.ErrorCode.NODE_INFO_CACHE_EMPTY,
4492
+ throw new import_errors16.FuelError(
4493
+ import_errors16.ErrorCode.NODE_INFO_CACHE_EMPTY,
3890
4494
  "Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
3891
4495
  );
3892
4496
  }
@@ -3928,9 +4532,9 @@ var _Provider = class {
3928
4532
  * @returns A promise that resolves to the Chain and NodeInfo.
3929
4533
  */
3930
4534
  async fetchChainAndNodeInfo() {
3931
- const chain = await this.fetchChain();
3932
4535
  const nodeInfo = await this.fetchNode();
3933
4536
  _Provider.ensureClientVersionIsSupported(nodeInfo);
4537
+ const chain = await this.fetchChain();
3934
4538
  return {
3935
4539
  chain,
3936
4540
  nodeInfo
@@ -3964,8 +4568,8 @@ Supported fuel-core version: ${supportedVersion}.`
3964
4568
  if ("response" in response) {
3965
4569
  const graphQlResponse = response.response;
3966
4570
  if (Array.isArray(graphQlResponse?.errors)) {
3967
- throw new import_errors14.FuelError(
3968
- import_errors14.FuelError.CODES.INVALID_REQUEST,
4571
+ throw new import_errors16.FuelError(
4572
+ import_errors16.FuelError.CODES.INVALID_REQUEST,
3969
4573
  graphQlResponse.errors.map((err) => err.message).join("\n\n")
3970
4574
  );
3971
4575
  }
@@ -3976,7 +4580,7 @@ Supported fuel-core version: ${supportedVersion}.`
3976
4580
  const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
3977
4581
  const isSubscription = opDefinition?.operation === "subscription";
3978
4582
  if (isSubscription) {
3979
- return new FuelGraphqlSubscriber({
4583
+ return FuelGraphqlSubscriber.create({
3980
4584
  url: this.url,
3981
4585
  query,
3982
4586
  fetchFn: (url, requestInit) => fetchFn(url, requestInit, this.options),
@@ -4005,7 +4609,7 @@ Supported fuel-core version: ${supportedVersion}.`
4005
4609
  */
4006
4610
  async getBlockNumber() {
4007
4611
  const { chain } = await this.operations.getChain();
4008
- return (0, import_math17.bn)(chain.latestBlock.height, 10);
4612
+ return (0, import_math19.bn)(chain.latestBlock.height, 10);
4009
4613
  }
4010
4614
  /**
4011
4615
  * Returns the node information for the current provider network.
@@ -4015,8 +4619,8 @@ Supported fuel-core version: ${supportedVersion}.`
4015
4619
  async fetchNode() {
4016
4620
  const { nodeInfo } = await this.operations.getNodeInfo();
4017
4621
  const processedNodeInfo = {
4018
- maxDepth: (0, import_math17.bn)(nodeInfo.maxDepth),
4019
- maxTx: (0, import_math17.bn)(nodeInfo.maxTx),
4622
+ maxDepth: (0, import_math19.bn)(nodeInfo.maxDepth),
4623
+ maxTx: (0, import_math19.bn)(nodeInfo.maxTx),
4020
4624
  nodeVersion: nodeInfo.nodeVersion,
4021
4625
  utxoValidation: nodeInfo.utxoValidation,
4022
4626
  vmBacktrace: nodeInfo.vmBacktrace
@@ -4057,6 +4661,21 @@ Supported fuel-core version: ${supportedVersion}.`
4057
4661
  } = this.getChain();
4058
4662
  return baseAssetId;
4059
4663
  }
4664
+ validateTransaction(tx, consensusParameters) {
4665
+ const { maxOutputs, maxInputs } = consensusParameters.txParameters;
4666
+ if ((0, import_math19.bn)(tx.inputs.length).gt(maxInputs)) {
4667
+ throw new import_errors16.FuelError(
4668
+ import_errors16.ErrorCode.MAX_INPUTS_EXCEEDED,
4669
+ "The transaction exceeds the maximum allowed number of inputs."
4670
+ );
4671
+ }
4672
+ if ((0, import_math19.bn)(tx.outputs.length).gt(maxOutputs)) {
4673
+ throw new import_errors16.FuelError(
4674
+ import_errors16.ErrorCode.MAX_OUTPUTS_EXCEEDED,
4675
+ "The transaction exceeds the maximum allowed number of outputs."
4676
+ );
4677
+ }
4678
+ }
4060
4679
  /**
4061
4680
  * Submits a transaction to the chain to be executed.
4062
4681
  *
@@ -4073,16 +4692,18 @@ Supported fuel-core version: ${supportedVersion}.`
4073
4692
  if (estimateTxDependencies) {
4074
4693
  await this.estimateTxDependencies(transactionRequest);
4075
4694
  }
4076
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4695
+ const { consensusParameters } = this.getChain();
4696
+ this.validateTransaction(transactionRequest, consensusParameters);
4697
+ const encodedTransaction = (0, import_utils26.hexlify)(transactionRequest.toTransactionBytes());
4077
4698
  let abis;
4078
- if (transactionRequest.type === import_transactions20.TransactionType.Script) {
4699
+ if (isTransactionTypeScript(transactionRequest)) {
4079
4700
  abis = transactionRequest.abis;
4080
4701
  }
4081
4702
  const {
4082
4703
  submit: { id: transactionId }
4083
4704
  } = await this.operations.submit({ encodedTransaction });
4084
- __privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs);
4085
- return new TransactionResponse(transactionId, this, abis);
4705
+ __privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs, transactionId);
4706
+ return new TransactionResponse(transactionRequest, this, abis);
4086
4707
  }
4087
4708
  /**
4088
4709
  * Executes a transaction without actually submitting it to the chain.
@@ -4099,7 +4720,7 @@ Supported fuel-core version: ${supportedVersion}.`
4099
4720
  if (estimateTxDependencies) {
4100
4721
  return this.estimateTxDependencies(transactionRequest);
4101
4722
  }
4102
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4723
+ const encodedTransaction = (0, import_utils26.hexlify)(transactionRequest.toTransactionBytes());
4103
4724
  const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4104
4725
  encodedTransactions: encodedTransaction,
4105
4726
  utxoValidation: utxoValidation || false
@@ -4119,13 +4740,13 @@ Supported fuel-core version: ${supportedVersion}.`
4119
4740
  async estimatePredicates(transactionRequest) {
4120
4741
  const shouldEstimatePredicates = Boolean(
4121
4742
  transactionRequest.inputs.find(
4122
- (input) => "predicate" in input && input.predicate && !(0, import_utils24.equalBytes)((0, import_utils23.arrayify)(input.predicate), (0, import_utils23.arrayify)("0x")) && new import_math17.BN(input.predicateGasUsed).isZero()
4743
+ (input) => "predicate" in input && input.predicate && !(0, import_utils27.equalBytes)((0, import_utils26.arrayify)(input.predicate), (0, import_utils26.arrayify)("0x")) && new import_math19.BN(input.predicateGasUsed).isZero()
4123
4744
  )
4124
4745
  );
4125
4746
  if (!shouldEstimatePredicates) {
4126
4747
  return transactionRequest;
4127
4748
  }
4128
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4749
+ const encodedTransaction = (0, import_utils26.hexlify)(transactionRequest.toTransactionBytes());
4129
4750
  const response = await this.operations.estimatePredicates({
4130
4751
  encodedTransaction
4131
4752
  });
@@ -4134,7 +4755,7 @@ Supported fuel-core version: ${supportedVersion}.`
4134
4755
  } = response;
4135
4756
  if (inputs) {
4136
4757
  inputs.forEach((input, index) => {
4137
- if ("predicateGasUsed" in input && (0, import_math17.bn)(input.predicateGasUsed).gt(0)) {
4758
+ if ("predicateGasUsed" in input && (0, import_math19.bn)(input.predicateGasUsed).gt(0)) {
4138
4759
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
4139
4760
  }
4140
4761
  });
@@ -4151,7 +4772,7 @@ Supported fuel-core version: ${supportedVersion}.`
4151
4772
  * @returns A promise that resolves to the estimate transaction dependencies.
4152
4773
  */
4153
4774
  async estimateTxDependencies(transactionRequest) {
4154
- if (transactionRequest.type === import_transactions20.TransactionType.Create) {
4775
+ if (isTransactionTypeCreate(transactionRequest)) {
4155
4776
  return {
4156
4777
  receipts: [],
4157
4778
  outputVariables: 0,
@@ -4166,18 +4787,18 @@ Supported fuel-core version: ${supportedVersion}.`
4166
4787
  const {
4167
4788
  dryRun: [{ receipts: rawReceipts, status }]
4168
4789
  } = await this.operations.dryRun({
4169
- encodedTransactions: [(0, import_utils23.hexlify)(transactionRequest.toTransactionBytes())],
4790
+ encodedTransactions: [(0, import_utils26.hexlify)(transactionRequest.toTransactionBytes())],
4170
4791
  utxoValidation: false
4171
4792
  });
4172
4793
  receipts = rawReceipts.map(processGqlReceipt);
4173
4794
  dryRunStatus = status;
4174
4795
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
4175
4796
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
4176
- if (hasMissingOutputs) {
4797
+ if (hasMissingOutputs && isTransactionTypeScript(transactionRequest)) {
4177
4798
  outputVariables += missingOutputVariables.length;
4178
4799
  transactionRequest.addVariableOutputs(missingOutputVariables.length);
4179
4800
  missingOutputContractIds.forEach(({ contractId }) => {
4180
- transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4801
+ transactionRequest.addContractInputAndOutput(import_address4.Address.fromString(contractId));
4181
4802
  missingContractIds.push(contractId);
4182
4803
  });
4183
4804
  const { maxFee } = await this.estimateTxGasAndFee({
@@ -4215,8 +4836,8 @@ Supported fuel-core version: ${supportedVersion}.`
4215
4836
  const allRequests = (0, import_ramda3.clone)(transactionRequests);
4216
4837
  const serializedTransactionsMap = /* @__PURE__ */ new Map();
4217
4838
  allRequests.forEach((req, index) => {
4218
- if (req.type === import_transactions20.TransactionType.Script) {
4219
- serializedTransactionsMap.set(index, (0, import_utils23.hexlify)(req.toTransactionBytes()));
4839
+ if (isTransactionTypeScript(req)) {
4840
+ serializedTransactionsMap.set(index, (0, import_utils26.hexlify)(req.toTransactionBytes()));
4220
4841
  }
4221
4842
  });
4222
4843
  let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
@@ -4241,18 +4862,18 @@ Supported fuel-core version: ${supportedVersion}.`
4241
4862
  );
4242
4863
  const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4243
4864
  const request = allRequests[requestIdx];
4244
- if (hasMissingOutputs && request?.type === import_transactions20.TransactionType.Script) {
4865
+ if (hasMissingOutputs && isTransactionTypeScript(request)) {
4245
4866
  result.outputVariables += missingOutputVariables.length;
4246
4867
  request.addVariableOutputs(missingOutputVariables.length);
4247
4868
  missingOutputContractIds.forEach(({ contractId }) => {
4248
- request.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4869
+ request.addContractInputAndOutput(import_address4.Address.fromString(contractId));
4249
4870
  result.missingContractIds.push(contractId);
4250
4871
  });
4251
4872
  const { maxFee } = await this.estimateTxGasAndFee({
4252
4873
  transactionRequest: request
4253
4874
  });
4254
4875
  request.maxFee = maxFee;
4255
- serializedTransactionsMap.set(requestIdx, (0, import_utils23.hexlify)(request.toTransactionBytes()));
4876
+ serializedTransactionsMap.set(requestIdx, (0, import_utils26.hexlify)(request.toTransactionBytes()));
4256
4877
  nextRoundTransactions.push(requestIdx);
4257
4878
  }
4258
4879
  }
@@ -4273,7 +4894,7 @@ Supported fuel-core version: ${supportedVersion}.`
4273
4894
  if (estimateTxDependencies) {
4274
4895
  return this.estimateMultipleTxDependencies(transactionRequests);
4275
4896
  }
4276
- const encodedTransactions = transactionRequests.map((tx) => (0, import_utils23.hexlify)(tx.toTransactionBytes()));
4897
+ const encodedTransactions = transactionRequests.map((tx) => (0, import_utils26.hexlify)(tx.toTransactionBytes()));
4277
4898
  const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4278
4899
  encodedTransactions,
4279
4900
  utxoValidation: utxoValidation || false
@@ -4299,13 +4920,13 @@ Supported fuel-core version: ${supportedVersion}.`
4299
4920
  gasPrice = await this.estimateGasPrice(10);
4300
4921
  }
4301
4922
  const minFee = calculateGasFee({
4302
- gasPrice: (0, import_math17.bn)(gasPrice),
4923
+ gasPrice: (0, import_math19.bn)(gasPrice),
4303
4924
  gas: minGas,
4304
4925
  priceFactor: gasPriceFactor,
4305
4926
  tip: transactionRequest.tip
4306
4927
  }).add(1);
4307
- let gasLimit = (0, import_math17.bn)(0);
4308
- if (transactionRequest.type === import_transactions20.TransactionType.Script) {
4928
+ let gasLimit = (0, import_math19.bn)(0);
4929
+ if (isTransactionTypeScript(transactionRequest)) {
4309
4930
  gasLimit = transactionRequest.gasLimit;
4310
4931
  if (transactionRequest.gasLimit.eq(0)) {
4311
4932
  transactionRequest.gasLimit = minGas;
@@ -4317,7 +4938,7 @@ Supported fuel-core version: ${supportedVersion}.`
4317
4938
  }
4318
4939
  const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4319
4940
  const maxFee = calculateGasFee({
4320
- gasPrice: (0, import_math17.bn)(gasPrice),
4941
+ gasPrice: (0, import_math19.bn)(gasPrice),
4321
4942
  gas: maxGas,
4322
4943
  priceFactor: gasPriceFactor,
4323
4944
  tip: transactionRequest.tip
@@ -4347,7 +4968,7 @@ Supported fuel-core version: ${supportedVersion}.`
4347
4968
  if (estimateTxDependencies) {
4348
4969
  return this.estimateTxDependencies(transactionRequest);
4349
4970
  }
4350
- const encodedTransactions = [(0, import_utils23.hexlify)(transactionRequest.toTransactionBytes())];
4971
+ const encodedTransactions = [(0, import_utils26.hexlify)(transactionRequest.toTransactionBytes())];
4351
4972
  const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4352
4973
  encodedTransactions,
4353
4974
  utxoValidation: true
@@ -4373,14 +4994,14 @@ Supported fuel-core version: ${supportedVersion}.`
4373
4994
  */
4374
4995
  async getTransactionCost(transactionRequestLike, { signatureCallback } = {}) {
4375
4996
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
4376
- const isScriptTransaction = txRequestClone.type === import_transactions20.TransactionType.Script;
4377
4997
  const updateMaxFee = txRequestClone.maxFee.eq(0);
4998
+ const isScriptTransaction = isTransactionTypeScript(txRequestClone);
4378
4999
  if (isScriptTransaction) {
4379
- txRequestClone.gasLimit = (0, import_math17.bn)(0);
5000
+ txRequestClone.gasLimit = (0, import_math19.bn)(0);
4380
5001
  }
4381
5002
  const signedRequest = (0, import_ramda3.clone)(txRequestClone);
4382
5003
  let addedSignatures = 0;
4383
- if (signatureCallback && isScriptTransaction) {
5004
+ if (signatureCallback && isTransactionTypeScript(signedRequest)) {
4384
5005
  const lengthBefore = signedRequest.witnesses.length;
4385
5006
  await signatureCallback(signedRequest);
4386
5007
  addedSignatures = signedRequest.witnesses.length - lengthBefore;
@@ -4394,7 +5015,7 @@ Supported fuel-core version: ${supportedVersion}.`
4394
5015
  let dryRunStatus;
4395
5016
  let missingContractIds = [];
4396
5017
  let outputVariables = 0;
4397
- let gasUsed = (0, import_math17.bn)(0);
5018
+ let gasUsed = (0, import_math19.bn)(0);
4398
5019
  txRequestClone.maxFee = maxFee;
4399
5020
  if (isScriptTransaction) {
4400
5021
  txRequestClone.gasLimit = gasLimit;
@@ -4438,7 +5059,7 @@ Supported fuel-core version: ${supportedVersion}.`
4438
5059
  * @returns A promise that resolves to the coins.
4439
5060
  */
4440
5061
  async getCoins(owner, assetId, paginationArgs) {
4441
- const ownerAddress = import_address3.Address.fromAddressOrString(owner);
5062
+ const ownerAddress = import_address4.Address.fromAddressOrString(owner);
4442
5063
  const {
4443
5064
  coins: { edges, pageInfo }
4444
5065
  } = await this.operations.getCoins({
@@ -4446,15 +5067,15 @@ Supported fuel-core version: ${supportedVersion}.`
4446
5067
  paginationLimit: RESOURCES_PAGE_SIZE_LIMIT,
4447
5068
  inputArgs: paginationArgs
4448
5069
  }),
4449
- filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
5070
+ filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils26.hexlify)(assetId) }
4450
5071
  });
4451
5072
  const coins = edges.map(({ node }) => ({
4452
5073
  id: node.utxoId,
4453
5074
  assetId: node.assetId,
4454
- amount: (0, import_math17.bn)(node.amount),
4455
- owner: import_address3.Address.fromAddressOrString(node.owner),
4456
- blockCreated: (0, import_math17.bn)(node.blockCreated),
4457
- txCreatedIdx: (0, import_math17.bn)(node.txCreatedIdx)
5075
+ amount: (0, import_math19.bn)(node.amount),
5076
+ owner: import_address4.Address.fromAddressOrString(node.owner),
5077
+ blockCreated: (0, import_math19.bn)(node.blockCreated),
5078
+ txCreatedIdx: (0, import_math19.bn)(node.txCreatedIdx)
4458
5079
  }));
4459
5080
  return {
4460
5081
  coins,
@@ -4470,21 +5091,20 @@ Supported fuel-core version: ${supportedVersion}.`
4470
5091
  * @returns A promise that resolves to the resources.
4471
5092
  */
4472
5093
  async getResourcesToSpend(owner, quantities, excludedIds) {
4473
- const ownerAddress = import_address3.Address.fromAddressOrString(owner);
5094
+ const ownerAddress = import_address4.Address.fromAddressOrString(owner);
4474
5095
  const excludeInput = {
4475
- messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
4476
- utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
5096
+ messages: excludedIds?.messages?.map((nonce) => (0, import_utils26.hexlify)(nonce)) || [],
5097
+ utxos: excludedIds?.utxos?.map((id) => (0, import_utils26.hexlify)(id)) || []
4477
5098
  };
4478
5099
  if (this.cache) {
4479
- const uniqueUtxos = new Set(
4480
- excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
4481
- );
4482
- excludeInput.utxos = Array.from(uniqueUtxos);
5100
+ const cached = this.cache.getActiveData();
5101
+ excludeInput.messages.push(...cached.messages);
5102
+ excludeInput.utxos.push(...cached.utxos);
4483
5103
  }
4484
5104
  const coinsQuery = {
4485
5105
  owner: ownerAddress.toB256(),
4486
5106
  queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
4487
- assetId: (0, import_utils23.hexlify)(assetId),
5107
+ assetId: (0, import_utils26.hexlify)(assetId),
4488
5108
  amount: amount.toString(10),
4489
5109
  max: maxPerAsset ? maxPerAsset.toString(10) : void 0
4490
5110
  })),
@@ -4495,21 +5115,21 @@ Supported fuel-core version: ${supportedVersion}.`
4495
5115
  switch (coin.type) {
4496
5116
  case "MessageCoin":
4497
5117
  return {
4498
- amount: (0, import_math17.bn)(coin.amount),
5118
+ amount: (0, import_math19.bn)(coin.amount),
4499
5119
  assetId: coin.assetId,
4500
- daHeight: (0, import_math17.bn)(coin.daHeight),
4501
- sender: import_address3.Address.fromAddressOrString(coin.sender),
4502
- recipient: import_address3.Address.fromAddressOrString(coin.recipient),
5120
+ daHeight: (0, import_math19.bn)(coin.daHeight),
5121
+ sender: import_address4.Address.fromAddressOrString(coin.sender),
5122
+ recipient: import_address4.Address.fromAddressOrString(coin.recipient),
4503
5123
  nonce: coin.nonce
4504
5124
  };
4505
5125
  case "Coin":
4506
5126
  return {
4507
5127
  id: coin.utxoId,
4508
- amount: (0, import_math17.bn)(coin.amount),
5128
+ amount: (0, import_math19.bn)(coin.amount),
4509
5129
  assetId: coin.assetId,
4510
- owner: import_address3.Address.fromAddressOrString(coin.owner),
4511
- blockCreated: (0, import_math17.bn)(coin.blockCreated),
4512
- txCreatedIdx: (0, import_math17.bn)(coin.txCreatedIdx)
5130
+ owner: import_address4.Address.fromAddressOrString(coin.owner),
5131
+ blockCreated: (0, import_math19.bn)(coin.blockCreated),
5132
+ txCreatedIdx: (0, import_math19.bn)(coin.txCreatedIdx)
4513
5133
  };
4514
5134
  default:
4515
5135
  return null;
@@ -4526,13 +5146,13 @@ Supported fuel-core version: ${supportedVersion}.`
4526
5146
  async getBlock(idOrHeight) {
4527
5147
  let variables;
4528
5148
  if (typeof idOrHeight === "number") {
4529
- variables = { height: (0, import_math17.bn)(idOrHeight).toString(10) };
5149
+ variables = { height: (0, import_math19.bn)(idOrHeight).toString(10) };
4530
5150
  } else if (idOrHeight === "latest") {
4531
5151
  variables = { height: (await this.getBlockNumber()).toString(10) };
4532
5152
  } else if (idOrHeight.length === 66) {
4533
5153
  variables = { blockId: idOrHeight };
4534
5154
  } else {
4535
- variables = { blockId: (0, import_math17.bn)(idOrHeight).toString(10) };
5155
+ variables = { blockId: (0, import_math19.bn)(idOrHeight).toString(10) };
4536
5156
  }
4537
5157
  const { block } = await this.operations.getBlock(variables);
4538
5158
  if (!block) {
@@ -4540,7 +5160,7 @@ Supported fuel-core version: ${supportedVersion}.`
4540
5160
  }
4541
5161
  return {
4542
5162
  id: block.id,
4543
- height: (0, import_math17.bn)(block.height),
5163
+ height: (0, import_math19.bn)(block.height),
4544
5164
  time: block.header.time,
4545
5165
  transactionIds: block.transactions.map((tx) => tx.id)
4546
5166
  };
@@ -4562,7 +5182,7 @@ Supported fuel-core version: ${supportedVersion}.`
4562
5182
  });
4563
5183
  const blocks = edges.map(({ node: block }) => ({
4564
5184
  id: block.id,
4565
- height: (0, import_math17.bn)(block.height),
5185
+ height: (0, import_math19.bn)(block.height),
4566
5186
  time: block.header.time,
4567
5187
  transactionIds: block.transactions.map((tx) => tx.id)
4568
5188
  }));
@@ -4577,7 +5197,7 @@ Supported fuel-core version: ${supportedVersion}.`
4577
5197
  async getBlockWithTransactions(idOrHeight) {
4578
5198
  let variables;
4579
5199
  if (typeof idOrHeight === "number") {
4580
- variables = { blockHeight: (0, import_math17.bn)(idOrHeight).toString(10) };
5200
+ variables = { blockHeight: (0, import_math19.bn)(idOrHeight).toString(10) };
4581
5201
  } else if (idOrHeight === "latest") {
4582
5202
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4583
5203
  } else {
@@ -4589,11 +5209,11 @@ Supported fuel-core version: ${supportedVersion}.`
4589
5209
  }
4590
5210
  return {
4591
5211
  id: block.id,
4592
- height: (0, import_math17.bn)(block.height, 10),
5212
+ height: (0, import_math19.bn)(block.height, 10),
4593
5213
  time: block.header.time,
4594
5214
  transactionIds: block.transactions.map((tx) => tx.id),
4595
5215
  transactions: block.transactions.map(
4596
- (tx) => new import_transactions20.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
5216
+ (tx) => new import_transactions20.TransactionCoder().decode((0, import_utils26.arrayify)(tx.rawPayload), 0)?.[0]
4597
5217
  )
4598
5218
  };
4599
5219
  }
@@ -4609,7 +5229,7 @@ Supported fuel-core version: ${supportedVersion}.`
4609
5229
  return null;
4610
5230
  }
4611
5231
  return new import_transactions20.TransactionCoder().decode(
4612
- (0, import_utils23.arrayify)(transaction.rawPayload),
5232
+ (0, import_utils26.arrayify)(transaction.rawPayload),
4613
5233
  0
4614
5234
  )?.[0];
4615
5235
  }
@@ -4624,7 +5244,7 @@ Supported fuel-core version: ${supportedVersion}.`
4624
5244
  } = await this.operations.getTransactions(paginationArgs);
4625
5245
  const coder = new import_transactions20.TransactionCoder();
4626
5246
  const transactions = edges.map(
4627
- ({ node: { rawPayload } }) => coder.decode((0, import_utils23.arrayify)(rawPayload), 0)[0]
5247
+ ({ node: { rawPayload } }) => coder.decode((0, import_utils26.arrayify)(rawPayload), 0)[0]
4628
5248
  );
4629
5249
  return { transactions, pageInfo };
4630
5250
  }
@@ -4650,10 +5270,10 @@ Supported fuel-core version: ${supportedVersion}.`
4650
5270
  */
4651
5271
  async getContractBalance(contractId, assetId) {
4652
5272
  const { contractBalance } = await this.operations.getContractBalance({
4653
- contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4654
- asset: (0, import_utils23.hexlify)(assetId)
5273
+ contract: import_address4.Address.fromAddressOrString(contractId).toB256(),
5274
+ asset: (0, import_utils26.hexlify)(assetId)
4655
5275
  });
4656
- return (0, import_math17.bn)(contractBalance.amount, 10);
5276
+ return (0, import_math19.bn)(contractBalance.amount, 10);
4657
5277
  }
4658
5278
  /**
4659
5279
  * Returns the balance for the given owner for the given asset ID.
@@ -4664,10 +5284,10 @@ Supported fuel-core version: ${supportedVersion}.`
4664
5284
  */
4665
5285
  async getBalance(owner, assetId) {
4666
5286
  const { balance } = await this.operations.getBalance({
4667
- owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4668
- assetId: (0, import_utils23.hexlify)(assetId)
5287
+ owner: import_address4.Address.fromAddressOrString(owner).toB256(),
5288
+ assetId: (0, import_utils26.hexlify)(assetId)
4669
5289
  });
4670
- return (0, import_math17.bn)(balance.amount, 10);
5290
+ return (0, import_math19.bn)(balance.amount, 10);
4671
5291
  }
4672
5292
  /**
4673
5293
  * Returns balances for the given owner.
@@ -4685,11 +5305,11 @@ Supported fuel-core version: ${supportedVersion}.`
4685
5305
  * but the current Fuel-Core implementation does not support pagination yet.
4686
5306
  */
4687
5307
  first: 1e4,
4688
- filter: { owner: import_address3.Address.fromAddressOrString(owner).toB256() }
5308
+ filter: { owner: import_address4.Address.fromAddressOrString(owner).toB256() }
4689
5309
  });
4690
5310
  const balances = edges.map(({ node }) => ({
4691
5311
  assetId: node.assetId,
4692
- amount: (0, import_math17.bn)(node.amount)
5312
+ amount: (0, import_math19.bn)(node.amount)
4693
5313
  }));
4694
5314
  return { balances };
4695
5315
  }
@@ -4708,22 +5328,22 @@ Supported fuel-core version: ${supportedVersion}.`
4708
5328
  inputArgs: paginationArgs,
4709
5329
  paginationLimit: RESOURCES_PAGE_SIZE_LIMIT
4710
5330
  }),
4711
- owner: import_address3.Address.fromAddressOrString(address).toB256()
5331
+ owner: import_address4.Address.fromAddressOrString(address).toB256()
4712
5332
  });
4713
5333
  const messages = edges.map(({ node }) => ({
4714
5334
  messageId: import_transactions20.InputMessageCoder.getMessageId({
4715
5335
  sender: node.sender,
4716
5336
  recipient: node.recipient,
4717
5337
  nonce: node.nonce,
4718
- amount: (0, import_math17.bn)(node.amount),
5338
+ amount: (0, import_math19.bn)(node.amount),
4719
5339
  data: node.data
4720
5340
  }),
4721
- sender: import_address3.Address.fromAddressOrString(node.sender),
4722
- recipient: import_address3.Address.fromAddressOrString(node.recipient),
5341
+ sender: import_address4.Address.fromAddressOrString(node.sender),
5342
+ recipient: import_address4.Address.fromAddressOrString(node.recipient),
4723
5343
  nonce: node.nonce,
4724
- amount: (0, import_math17.bn)(node.amount),
5344
+ amount: (0, import_math19.bn)(node.amount),
4725
5345
  data: import_transactions20.InputMessageCoder.decodeData(node.data),
4726
- daHeight: (0, import_math17.bn)(node.daHeight)
5346
+ daHeight: (0, import_math19.bn)(node.daHeight)
4727
5347
  }));
4728
5348
  return {
4729
5349
  messages,
@@ -4745,8 +5365,8 @@ Supported fuel-core version: ${supportedVersion}.`
4745
5365
  nonce
4746
5366
  };
4747
5367
  if (commitBlockId && commitBlockHeight) {
4748
- throw new import_errors14.FuelError(
4749
- import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
5368
+ throw new import_errors16.FuelError(
5369
+ import_errors16.ErrorCode.INVALID_INPUT_PARAMETERS,
4750
5370
  "commitBlockId and commitBlockHeight cannot be used together"
4751
5371
  );
4752
5372
  }
@@ -4780,19 +5400,19 @@ Supported fuel-core version: ${supportedVersion}.`
4780
5400
  } = result.messageProof;
4781
5401
  return {
4782
5402
  messageProof: {
4783
- proofIndex: (0, import_math17.bn)(messageProof.proofIndex),
5403
+ proofIndex: (0, import_math19.bn)(messageProof.proofIndex),
4784
5404
  proofSet: messageProof.proofSet
4785
5405
  },
4786
5406
  blockProof: {
4787
- proofIndex: (0, import_math17.bn)(blockProof.proofIndex),
5407
+ proofIndex: (0, import_math19.bn)(blockProof.proofIndex),
4788
5408
  proofSet: blockProof.proofSet
4789
5409
  },
4790
5410
  messageBlockHeader: {
4791
5411
  id: messageBlockHeader.id,
4792
- daHeight: (0, import_math17.bn)(messageBlockHeader.daHeight),
5412
+ daHeight: (0, import_math19.bn)(messageBlockHeader.daHeight),
4793
5413
  transactionsCount: Number(messageBlockHeader.transactionsCount),
4794
5414
  transactionsRoot: messageBlockHeader.transactionsRoot,
4795
- height: (0, import_math17.bn)(messageBlockHeader.height),
5415
+ height: (0, import_math19.bn)(messageBlockHeader.height),
4796
5416
  prevRoot: messageBlockHeader.prevRoot,
4797
5417
  time: messageBlockHeader.time,
4798
5418
  applicationHash: messageBlockHeader.applicationHash,
@@ -4804,10 +5424,10 @@ Supported fuel-core version: ${supportedVersion}.`
4804
5424
  },
4805
5425
  commitBlockHeader: {
4806
5426
  id: commitBlockHeader.id,
4807
- daHeight: (0, import_math17.bn)(commitBlockHeader.daHeight),
5427
+ daHeight: (0, import_math19.bn)(commitBlockHeader.daHeight),
4808
5428
  transactionsCount: Number(commitBlockHeader.transactionsCount),
4809
5429
  transactionsRoot: commitBlockHeader.transactionsRoot,
4810
- height: (0, import_math17.bn)(commitBlockHeader.height),
5430
+ height: (0, import_math19.bn)(commitBlockHeader.height),
4811
5431
  prevRoot: commitBlockHeader.prevRoot,
4812
5432
  time: commitBlockHeader.time,
4813
5433
  applicationHash: commitBlockHeader.applicationHash,
@@ -4817,10 +5437,10 @@ Supported fuel-core version: ${supportedVersion}.`
4817
5437
  eventInboxRoot: commitBlockHeader.eventInboxRoot,
4818
5438
  stateTransitionBytecodeVersion: Number(commitBlockHeader.stateTransitionBytecodeVersion)
4819
5439
  },
4820
- sender: import_address3.Address.fromAddressOrString(sender),
4821
- recipient: import_address3.Address.fromAddressOrString(recipient),
5440
+ sender: import_address4.Address.fromAddressOrString(sender),
5441
+ recipient: import_address4.Address.fromAddressOrString(recipient),
4822
5442
  nonce,
4823
- amount: (0, import_math17.bn)(amount),
5443
+ amount: (0, import_math19.bn)(amount),
4824
5444
  data
4825
5445
  };
4826
5446
  }
@@ -4831,7 +5451,7 @@ Supported fuel-core version: ${supportedVersion}.`
4831
5451
  */
4832
5452
  async getLatestGasPrice() {
4833
5453
  const { latestGasPrice } = await this.operations.getLatestGasPrice();
4834
- return (0, import_math17.bn)(latestGasPrice.gasPrice);
5454
+ return (0, import_math19.bn)(latestGasPrice.gasPrice);
4835
5455
  }
4836
5456
  /**
4837
5457
  * Returns the estimate gas price for the given block horizon.
@@ -4843,7 +5463,7 @@ Supported fuel-core version: ${supportedVersion}.`
4843
5463
  const { estimateGasPrice } = await this.operations.estimateGasPrice({
4844
5464
  blockHorizon: String(blockHorizon)
4845
5465
  });
4846
- return (0, import_math17.bn)(estimateGasPrice.gasPrice);
5466
+ return (0, import_math19.bn)(estimateGasPrice.gasPrice);
4847
5467
  }
4848
5468
  /**
4849
5469
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
@@ -4864,10 +5484,10 @@ Supported fuel-core version: ${supportedVersion}.`
4864
5484
  */
4865
5485
  async produceBlocks(amount, startTime) {
4866
5486
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4867
- blocksToProduce: (0, import_math17.bn)(amount).toString(10),
4868
- startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
5487
+ blocksToProduce: (0, import_math19.bn)(amount).toString(10),
5488
+ startTimestamp: startTime ? import_utils26.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4869
5489
  });
4870
- return (0, import_math17.bn)(latestBlockHeight);
5490
+ return (0, import_math19.bn)(latestBlockHeight);
4871
5491
  }
4872
5492
  /**
4873
5493
  * Get the transaction response for the given transaction ID.
@@ -4914,26 +5534,26 @@ Supported fuel-core version: ${supportedVersion}.`
4914
5534
  const { paginationLimit, inputArgs = {} } = params;
4915
5535
  const { first, last, after, before } = inputArgs;
4916
5536
  if (after && before) {
4917
- throw new import_errors14.FuelError(
4918
- import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
5537
+ throw new import_errors16.FuelError(
5538
+ import_errors16.ErrorCode.INVALID_INPUT_PARAMETERS,
4919
5539
  'Pagination arguments "after" and "before" cannot be used together'
4920
5540
  );
4921
5541
  }
4922
5542
  if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
4923
- throw new import_errors14.FuelError(
4924
- import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
5543
+ throw new import_errors16.FuelError(
5544
+ import_errors16.ErrorCode.INVALID_INPUT_PARAMETERS,
4925
5545
  `Pagination limit for this query cannot exceed ${paginationLimit} items`
4926
5546
  );
4927
5547
  }
4928
5548
  if (first && before) {
4929
- throw new import_errors14.FuelError(
4930
- import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
5549
+ throw new import_errors16.FuelError(
5550
+ import_errors16.ErrorCode.INVALID_INPUT_PARAMETERS,
4931
5551
  'The use of pagination argument "first" with "before" is not supported'
4932
5552
  );
4933
5553
  }
4934
5554
  if (last && after) {
4935
- throw new import_errors14.FuelError(
4936
- import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
5555
+ throw new import_errors16.FuelError(
5556
+ import_errors16.ErrorCode.INVALID_INPUT_PARAMETERS,
4937
5557
  'The use of pagination argument "last" with "after" is not supported'
4938
5558
  );
4939
5559
  }
@@ -4964,15 +5584,22 @@ Supported fuel-core version: ${supportedVersion}.`
4964
5584
  };
4965
5585
  var Provider = _Provider;
4966
5586
  _cacheInputs = new WeakSet();
4967
- cacheInputs_fn = function(inputs) {
5587
+ cacheInputs_fn = function(inputs, transactionId) {
4968
5588
  if (!this.cache) {
4969
5589
  return;
4970
5590
  }
4971
- inputs.forEach((input) => {
4972
- if (input.type === import_transactions20.InputType.Coin) {
4973
- this.cache?.set(input.id);
4974
- }
4975
- });
5591
+ const inputsToCache = inputs.reduce(
5592
+ (acc, input) => {
5593
+ if (input.type === import_transactions20.InputType.Coin) {
5594
+ acc.utxos.push(input.id);
5595
+ } else if (input.type === import_transactions20.InputType.Message) {
5596
+ acc.messages.push(input.nonce);
5597
+ }
5598
+ return acc;
5599
+ },
5600
+ { utxos: [], messages: [] }
5601
+ );
5602
+ this.cache.set(transactionId, inputsToCache);
4976
5603
  };
4977
5604
  /** @hidden */
4978
5605
  __publicField(Provider, "chainInfoCache", {});
@@ -4980,10 +5607,10 @@ __publicField(Provider, "chainInfoCache", {});
4980
5607
  __publicField(Provider, "nodeInfoCache", {});
4981
5608
 
4982
5609
  // src/providers/transaction-summary/get-transaction-summary.ts
4983
- var import_errors15 = require("@fuel-ts/errors");
4984
- var import_math18 = require("@fuel-ts/math");
5610
+ var import_errors17 = require("@fuel-ts/errors");
5611
+ var import_math20 = require("@fuel-ts/math");
4985
5612
  var import_transactions21 = require("@fuel-ts/transactions");
4986
- var import_utils26 = require("@fuel-ts/utils");
5613
+ var import_utils29 = require("@fuel-ts/utils");
4987
5614
 
4988
5615
  // src/providers/chains.ts
4989
5616
  var CHAIN_IDS = {
@@ -5056,6 +5683,48 @@ var rawAssets = [
5056
5683
  ];
5057
5684
  var assets = resolveIconPaths(rawAssets, fuelAssetsBaseUrl);
5058
5685
 
5686
+ // src/test-utils/test-asset-id.ts
5687
+ var import_crypto4 = require("@fuel-ts/crypto");
5688
+ var import_utils31 = require("@fuel-ts/utils");
5689
+ var _TestAssetId = class {
5690
+ constructor(value) {
5691
+ this.value = value;
5692
+ }
5693
+ static random(count = 1) {
5694
+ const assetIds = [];
5695
+ for (let i = 0; i < count; i++) {
5696
+ assetIds.push(new _TestAssetId((0, import_utils31.hexlify)((0, import_crypto4.randomBytes)(32))));
5697
+ }
5698
+ return assetIds;
5699
+ }
5700
+ };
5701
+ var TestAssetId = _TestAssetId;
5702
+ __publicField(TestAssetId, "A", new _TestAssetId(
5703
+ "0x0101010101010101010101010101010101010101010101010101010101010101"
5704
+ ));
5705
+ __publicField(TestAssetId, "B", new _TestAssetId(
5706
+ "0x0202020202020202020202020202020202020202020202020202020202020202"
5707
+ ));
5708
+
5709
+ // src/test-utils/wallet-config.ts
5710
+ var import_crypto9 = require("@fuel-ts/crypto");
5711
+ var import_errors23 = require("@fuel-ts/errors");
5712
+ var import_utils40 = require("@fuel-ts/utils");
5713
+
5714
+ // src/wallet/base-wallet-unlocked.ts
5715
+ var import_hasher3 = require("@fuel-ts/hasher");
5716
+ var import_utils35 = require("@fuel-ts/utils");
5717
+
5718
+ // src/account.ts
5719
+ var import_abi_coder8 = require("@fuel-ts/abi-coder");
5720
+ var import_address5 = require("@fuel-ts/address");
5721
+ var import_crypto5 = require("@fuel-ts/crypto");
5722
+ var import_errors18 = require("@fuel-ts/errors");
5723
+ var import_interfaces = require("@fuel-ts/interfaces");
5724
+ var import_math22 = require("@fuel-ts/math");
5725
+ var import_utils33 = require("@fuel-ts/utils");
5726
+ var import_ramda4 = require("ramda");
5727
+
5059
5728
  // src/providers/utils/merge-quantities.ts
5060
5729
  var mergeQuantities = (...coinQuantities) => {
5061
5730
  const resultMap = {};
@@ -5071,18 +5740,18 @@ var mergeQuantities = (...coinQuantities) => {
5071
5740
  };
5072
5741
 
5073
5742
  // src/utils/formatTransferToContractScriptData.ts
5074
- var import_abi_coder6 = require("@fuel-ts/abi-coder");
5075
- var import_math19 = require("@fuel-ts/math");
5076
- var import_utils28 = require("@fuel-ts/utils");
5743
+ var import_abi_coder7 = require("@fuel-ts/abi-coder");
5744
+ var import_math21 = require("@fuel-ts/math");
5745
+ var import_utils32 = require("@fuel-ts/utils");
5077
5746
  var asm = __toESM(require("@fuels/vm-asm"));
5078
5747
  var formatTransferToContractScriptData = (params) => {
5079
5748
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
5080
- const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
5081
- const encoded = numberCoder.encode(new import_math19.BN(amountToTransfer).toNumber());
5749
+ const numberCoder = new import_abi_coder7.BigNumberCoder("u64");
5750
+ const encoded = numberCoder.encode(new import_math21.BN(amountToTransfer).toNumber());
5082
5751
  const scriptData = Uint8Array.from([
5083
- ...(0, import_utils28.arrayify)(hexlifiedContractId),
5752
+ ...(0, import_utils32.arrayify)(hexlifiedContractId),
5084
5753
  ...encoded,
5085
- ...(0, import_utils28.arrayify)(assetId)
5754
+ ...(0, import_utils32.arrayify)(assetId)
5086
5755
  ]);
5087
5756
  return scriptData;
5088
5757
  };
@@ -5107,7 +5776,7 @@ var assembleTransferToContractScript = async (params) => {
5107
5776
  };
5108
5777
 
5109
5778
  // src/account.ts
5110
- var MAX_FUNDING_ATTEMPTS = 2;
5779
+ var MAX_FUNDING_ATTEMPTS = 5;
5111
5780
  var Account = class extends import_interfaces.AbstractAccount {
5112
5781
  /**
5113
5782
  * The address associated with the account.
@@ -5132,7 +5801,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5132
5801
  super();
5133
5802
  this._provider = provider;
5134
5803
  this._connector = connector;
5135
- this.address = import_address4.Address.fromDynamicInput(address);
5804
+ this.address = import_address5.Address.fromDynamicInput(address);
5136
5805
  }
5137
5806
  /**
5138
5807
  * The provider used to interact with the network.
@@ -5143,7 +5812,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5143
5812
  */
5144
5813
  get provider() {
5145
5814
  if (!this._provider) {
5146
- throw new import_errors16.FuelError(import_errors16.ErrorCode.MISSING_PROVIDER, "Provider not set");
5815
+ throw new import_errors18.FuelError(import_errors18.ErrorCode.MISSING_PROVIDER, "Provider not set");
5147
5816
  }
5148
5817
  return this._provider;
5149
5818
  }
@@ -5220,12 +5889,12 @@ var Account = class extends import_interfaces.AbstractAccount {
5220
5889
  * @returns A promise that resolves to the funded transaction request.
5221
5890
  */
5222
5891
  async fund(request, params) {
5223
- const { addedSignatures, estimatedPredicates, requiredQuantities, updateMaxFee } = params;
5892
+ const { addedSignatures, estimatedPredicates, requiredQuantities, updateMaxFee, gasPrice } = params;
5224
5893
  const fee = request.maxFee;
5225
5894
  const baseAssetId = this.provider.getBaseAssetId();
5226
- const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math20.bn)(0);
5895
+ const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math22.bn)(0);
5227
5896
  const requiredQuantitiesWithFee = addAmountToCoinQuantities({
5228
- amount: (0, import_math20.bn)(fee),
5897
+ amount: (0, import_math22.bn)(fee),
5229
5898
  assetId: baseAssetId,
5230
5899
  coinQuantities: requiredQuantities
5231
5900
  });
@@ -5233,7 +5902,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5233
5902
  requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
5234
5903
  quantitiesDict[assetId] = {
5235
5904
  required: amount,
5236
- owned: (0, import_math20.bn)(0)
5905
+ owned: (0, import_math22.bn)(0)
5237
5906
  };
5238
5907
  });
5239
5908
  request.inputs.filter(isRequestInputResource).forEach((input) => {
@@ -5268,10 +5937,12 @@ var Account = class extends import_interfaces.AbstractAccount {
5268
5937
  );
5269
5938
  }
5270
5939
  if (!updateMaxFee) {
5940
+ needsToBeFunded = false;
5271
5941
  break;
5272
5942
  }
5273
5943
  const { maxFee: newFee } = await this.provider.estimateTxGasAndFee({
5274
- transactionRequest: requestToReestimate2
5944
+ transactionRequest: requestToReestimate2,
5945
+ gasPrice
5275
5946
  });
5276
5947
  const totalBaseAssetOnInputs = getAssetAmountInRequestInputs(
5277
5948
  request.inputs,
@@ -5291,6 +5962,12 @@ var Account = class extends import_interfaces.AbstractAccount {
5291
5962
  }
5292
5963
  fundingAttempts += 1;
5293
5964
  }
5965
+ if (needsToBeFunded) {
5966
+ throw new import_errors18.FuelError(
5967
+ import_errors18.ErrorCode.NOT_ENOUGH_FUNDS,
5968
+ `The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
5969
+ );
5970
+ }
5294
5971
  request.updatePredicateGasUsed(estimatedPredicates);
5295
5972
  const requestToReestimate = (0, import_ramda4.clone)(request);
5296
5973
  if (addedSignatures) {
@@ -5357,7 +6034,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5357
6034
  const { destination, amount, assetId } = transferParams;
5358
6035
  this.validateTransferAmount(amount);
5359
6036
  request.addCoinOutput(
5360
- import_address4.Address.fromAddressOrString(destination),
6037
+ import_address5.Address.fromAddressOrString(destination),
5361
6038
  amount,
5362
6039
  assetId ?? this.provider.getBaseAssetId()
5363
6040
  );
@@ -5391,17 +6068,17 @@ var Account = class extends import_interfaces.AbstractAccount {
5391
6068
  * @returns A promise that resolves to the transaction response.
5392
6069
  */
5393
6070
  async transferToContract(contractId, amount, assetId, txParams = {}) {
5394
- if ((0, import_math20.bn)(amount).lte(0)) {
5395
- throw new import_errors16.FuelError(
5396
- import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
6071
+ if ((0, import_math22.bn)(amount).lte(0)) {
6072
+ throw new import_errors18.FuelError(
6073
+ import_errors18.ErrorCode.INVALID_TRANSFER_AMOUNT,
5397
6074
  "Transfer amount must be a positive number."
5398
6075
  );
5399
6076
  }
5400
- const contractAddress = import_address4.Address.fromAddressOrString(contractId);
6077
+ const contractAddress = import_address5.Address.fromAddressOrString(contractId);
5401
6078
  const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5402
6079
  const { script, scriptData } = await assembleTransferToContractScript({
5403
6080
  hexlifiedContractId: contractAddress.toB256(),
5404
- amountToTransfer: (0, import_math20.bn)(amount),
6081
+ amountToTransfer: (0, import_math22.bn)(amount),
5405
6082
  assetId: assetIdToTransfer
5406
6083
  });
5407
6084
  let request = new ScriptTransactionRequest({
@@ -5411,7 +6088,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5411
6088
  });
5412
6089
  request.addContractInputAndOutput(contractAddress);
5413
6090
  const txCost = await this.getTransactionCost(request, {
5414
- quantities: [{ amount: (0, import_math20.bn)(amount), assetId: String(assetIdToTransfer) }]
6091
+ quantities: [{ amount: (0, import_math22.bn)(amount), assetId: String(assetIdToTransfer) }]
5415
6092
  });
5416
6093
  request = this.validateGasLimitAndMaxFee({
5417
6094
  transactionRequest: request,
@@ -5431,22 +6108,22 @@ var Account = class extends import_interfaces.AbstractAccount {
5431
6108
  * @returns A promise that resolves to the transaction response.
5432
6109
  */
5433
6110
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5434
- const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
5435
- const recipientDataArray = (0, import_utils29.arrayify)(
6111
+ const recipientAddress = import_address5.Address.fromAddressOrString(recipient);
6112
+ const recipientDataArray = (0, import_utils33.arrayify)(
5436
6113
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5437
6114
  );
5438
- const amountDataArray = (0, import_utils29.arrayify)(
5439
- "0x".concat((0, import_math20.bn)(amount).toHex().substring(2).padStart(16, "0"))
6115
+ const amountDataArray = (0, import_utils33.arrayify)(
6116
+ "0x".concat((0, import_math22.bn)(amount).toHex().substring(2).padStart(16, "0"))
5440
6117
  );
5441
6118
  const script = new Uint8Array([
5442
- ...(0, import_utils29.arrayify)(withdrawScript.bytes),
6119
+ ...(0, import_utils33.arrayify)(withdrawScript.bytes),
5443
6120
  ...recipientDataArray,
5444
6121
  ...amountDataArray
5445
6122
  ]);
5446
6123
  const params = { script, ...txParams };
5447
6124
  const baseAssetId = this.provider.getBaseAssetId();
5448
6125
  let request = new ScriptTransactionRequest(params);
5449
- const quantities = [{ amount: (0, import_math20.bn)(amount), assetId: baseAssetId }];
6126
+ const quantities = [{ amount: (0, import_math22.bn)(amount), assetId: baseAssetId }];
5450
6127
  const txCost = await this.getTransactionCost(request, { quantities });
5451
6128
  request = this.validateGasLimitAndMaxFee({
5452
6129
  transactionRequest: request,
@@ -5472,11 +6149,35 @@ var Account = class extends import_interfaces.AbstractAccount {
5472
6149
  const baseAssetId = this.provider.getBaseAssetId();
5473
6150
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
5474
6151
  const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
5475
- const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math20.bn)("100000000000000000") }];
5476
- const resources = this.generateFakeResources(
5477
- mergeQuantities(requiredQuantities, transactionFeeForDryRun)
6152
+ const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math22.bn)("100000000000000000") }];
6153
+ const findAssetInput = (assetId) => txRequestClone.inputs.find((input) => {
6154
+ if ("assetId" in input) {
6155
+ return input.assetId === assetId;
6156
+ }
6157
+ if ("recipient" in input) {
6158
+ return baseAssetId === assetId;
6159
+ }
6160
+ return false;
6161
+ });
6162
+ const updateAssetInput = (assetId, quantity) => {
6163
+ const assetInput = findAssetInput(assetId);
6164
+ const usedQuantity = quantity;
6165
+ if (assetInput && "amount" in assetInput) {
6166
+ assetInput.amount = usedQuantity;
6167
+ } else {
6168
+ txRequestClone.addResources(
6169
+ this.generateFakeResources([
6170
+ {
6171
+ amount: quantity,
6172
+ assetId
6173
+ }
6174
+ ])
6175
+ );
6176
+ }
6177
+ };
6178
+ mergeQuantities(requiredQuantities, transactionFeeForDryRun).forEach(
6179
+ ({ amount, assetId }) => updateAssetInput(assetId, amount)
5478
6180
  );
5479
- txRequestClone.addResources(resources);
5480
6181
  const txCost = await this.provider.getTransactionCost(txRequestClone, {
5481
6182
  signatureCallback
5482
6183
  });
@@ -5495,7 +6196,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5495
6196
  */
5496
6197
  async signMessage(message) {
5497
6198
  if (!this._connector) {
5498
- throw new import_errors16.FuelError(import_errors16.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
6199
+ throw new import_errors18.FuelError(import_errors18.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
5499
6200
  }
5500
6201
  return this._connector.signMessage(this.address.toString(), message);
5501
6202
  }
@@ -5507,8 +6208,8 @@ var Account = class extends import_interfaces.AbstractAccount {
5507
6208
  */
5508
6209
  async signTransaction(transactionRequestLike) {
5509
6210
  if (!this._connector) {
5510
- throw new import_errors16.FuelError(
5511
- import_errors16.ErrorCode.MISSING_CONNECTOR,
6211
+ throw new import_errors18.FuelError(
6212
+ import_errors18.ErrorCode.MISSING_CONNECTOR,
5512
6213
  "A connector is required to sign transactions."
5513
6214
  );
5514
6215
  }
@@ -5557,18 +6258,18 @@ var Account = class extends import_interfaces.AbstractAccount {
5557
6258
  */
5558
6259
  generateFakeResources(coins) {
5559
6260
  return coins.map((coin) => ({
5560
- id: (0, import_utils29.hexlify)((0, import_crypto2.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
6261
+ id: (0, import_utils33.hexlify)((0, import_crypto5.randomBytes)(import_abi_coder8.UTXO_ID_LEN)),
5561
6262
  owner: this.address,
5562
- blockCreated: (0, import_math20.bn)(1),
5563
- txCreatedIdx: (0, import_math20.bn)(1),
6263
+ blockCreated: (0, import_math22.bn)(1),
6264
+ txCreatedIdx: (0, import_math22.bn)(1),
5564
6265
  ...coin
5565
6266
  }));
5566
6267
  }
5567
6268
  /** @hidden * */
5568
6269
  validateTransferAmount(amount) {
5569
- if ((0, import_math20.bn)(amount).lte(0)) {
5570
- throw new import_errors16.FuelError(
5571
- import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
6270
+ if ((0, import_math22.bn)(amount).lte(0)) {
6271
+ throw new import_errors18.FuelError(
6272
+ import_errors18.ErrorCode.INVALID_TRANSFER_AMOUNT,
5572
6273
  "Transfer amount must be a positive number."
5573
6274
  );
5574
6275
  }
@@ -5594,19 +6295,19 @@ var Account = class extends import_interfaces.AbstractAccount {
5594
6295
  txParams: { gasLimit: setGasLimit, maxFee: setMaxFee }
5595
6296
  }) {
5596
6297
  const request = transactionRequestify(transactionRequest);
5597
- if (!(0, import_utils29.isDefined)(setGasLimit)) {
6298
+ if (!(0, import_utils33.isDefined)(setGasLimit)) {
5598
6299
  request.gasLimit = gasUsed;
5599
6300
  } else if (gasUsed.gt(setGasLimit)) {
5600
- throw new import_errors16.FuelError(
5601
- import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
6301
+ throw new import_errors18.FuelError(
6302
+ import_errors18.ErrorCode.GAS_LIMIT_TOO_LOW,
5602
6303
  `Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
5603
6304
  );
5604
6305
  }
5605
- if (!(0, import_utils29.isDefined)(setMaxFee)) {
6306
+ if (!(0, import_utils33.isDefined)(setMaxFee)) {
5606
6307
  request.maxFee = maxFee;
5607
6308
  } else if (maxFee.gt(setMaxFee)) {
5608
- throw new import_errors16.FuelError(
5609
- import_errors16.ErrorCode.MAX_FEE_TOO_LOW,
6309
+ throw new import_errors18.FuelError(
6310
+ import_errors18.ErrorCode.MAX_FEE_TOO_LOW,
5610
6311
  `Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
5611
6312
  );
5612
6313
  }
@@ -5614,121 +6315,11 @@ var Account = class extends import_interfaces.AbstractAccount {
5614
6315
  }
5615
6316
  };
5616
6317
 
5617
- // src/signer/signer.ts
5618
- var import_address5 = require("@fuel-ts/address");
5619
- var import_crypto3 = require("@fuel-ts/crypto");
5620
- var import_hasher2 = require("@fuel-ts/hasher");
5621
- var import_math21 = require("@fuel-ts/math");
5622
- var import_utils30 = require("@fuel-ts/utils");
5623
- var import_secp256k1 = require("@noble/curves/secp256k1");
5624
- var Signer = class {
5625
- address;
5626
- publicKey;
5627
- compressedPublicKey;
5628
- privateKey;
5629
- /**
5630
- * Create a Signer instance from a given private key
5631
- *
5632
- * @param privateKey - The private key to use for signing
5633
- * @returns A new Signer instance
5634
- */
5635
- constructor(privateKey) {
5636
- if (typeof privateKey === "string") {
5637
- if (privateKey.match(/^[0-9a-f]*$/i) && privateKey.length === 64) {
5638
- privateKey = `0x${privateKey}`;
5639
- }
5640
- }
5641
- const privateKeyBytes = (0, import_math21.toBytes)(privateKey, 32);
5642
- this.privateKey = (0, import_utils30.hexlify)(privateKeyBytes);
5643
- this.publicKey = (0, import_utils30.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5644
- this.compressedPublicKey = (0, import_utils30.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5645
- this.address = import_address5.Address.fromPublicKey(this.publicKey);
5646
- }
5647
- /**
5648
- * Sign data using the Signer instance
5649
- *
5650
- * Signature is a 64 byte array of the concatenated r and s values with the compressed recoveryParam byte.
5651
- * @ignore
5652
- * [Read more](FuelLabs/fuel-specs/specs/protocol/cryptographic_primitives.md#public-key-cryptography)
5653
- *
5654
- * @param data - The data to be sign
5655
- * @returns hashed signature
5656
- */
5657
- sign(data) {
5658
- const signature = import_secp256k1.secp256k1.sign((0, import_utils30.arrayify)(data), (0, import_utils30.arrayify)(this.privateKey));
5659
- const r = (0, import_math21.toBytes)(`0x${signature.r.toString(16)}`, 32);
5660
- const s = (0, import_math21.toBytes)(`0x${signature.s.toString(16)}`, 32);
5661
- s[0] |= (signature.recovery || 0) << 7;
5662
- return (0, import_utils30.hexlify)((0, import_utils30.concat)([r, s]));
5663
- }
5664
- /**
5665
- * Add point on the current elliptic curve
5666
- *
5667
- * @param point - Point to add on the curve
5668
- * @returns compressed point on the curve
5669
- */
5670
- addPoint(point) {
5671
- const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(this.compressedPublicKey));
5672
- const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(point));
5673
- const result = p0.add(p1);
5674
- return `0x${result.toHex(true)}`;
5675
- }
5676
- /**
5677
- * Recover the public key from a signature performed with [`sign`](#sign).
5678
- *
5679
- * @param data - Data
5680
- * @param signature - hashed signature
5681
- * @returns public key from signature from the
5682
- */
5683
- static recoverPublicKey(data, signature) {
5684
- const signedMessageBytes = (0, import_utils30.arrayify)(signature);
5685
- const r = signedMessageBytes.slice(0, 32);
5686
- const s = signedMessageBytes.slice(32, 64);
5687
- const recoveryParam = (s[0] & 128) >> 7;
5688
- s[0] &= 127;
5689
- const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils30.hexlify)(r)), BigInt((0, import_utils30.hexlify)(s))).addRecoveryBit(
5690
- recoveryParam
5691
- );
5692
- const publicKey = sig.recoverPublicKey((0, import_utils30.arrayify)(data)).toRawBytes(false).slice(1);
5693
- return (0, import_utils30.hexlify)(publicKey);
5694
- }
5695
- /**
5696
- * Recover the address from a signature performed with [`sign`](#sign).
5697
- *
5698
- * @param data - Data
5699
- * @param signature - Signature
5700
- * @returns Address from signature
5701
- */
5702
- static recoverAddress(data, signature) {
5703
- return import_address5.Address.fromPublicKey(Signer.recoverPublicKey(data, signature));
5704
- }
5705
- /**
5706
- * Generate a random privateKey
5707
- *
5708
- * @param entropy - Adds extra entropy to generate the privateKey
5709
- * @returns random 32-byte hashed
5710
- */
5711
- static generatePrivateKey(entropy) {
5712
- return entropy ? (0, import_hasher2.hash)((0, import_utils30.concat)([(0, import_crypto3.randomBytes)(32), (0, import_utils30.arrayify)(entropy)])) : (0, import_crypto3.randomBytes)(32);
5713
- }
5714
- /**
5715
- * Extended publicKey from a compact publicKey
5716
- *
5717
- * @param publicKey - Compact publicKey
5718
- * @returns extended publicKey
5719
- */
5720
- static extendPublicKey(publicKey) {
5721
- const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(publicKey));
5722
- return (0, import_utils30.hexlify)(point.toRawBytes(false).slice(1));
5723
- }
5724
- };
5725
-
5726
6318
  // src/wallet/keystore-wallet.ts
5727
6319
  var import_address6 = require("@fuel-ts/address");
5728
- var import_crypto4 = require("@fuel-ts/crypto");
5729
- var import_errors17 = require("@fuel-ts/errors");
5730
- var import_utils31 = require("@fuel-ts/utils");
5731
- var import_uuid = require("uuid");
6320
+ var import_crypto6 = require("@fuel-ts/crypto");
6321
+ var import_errors19 = require("@fuel-ts/errors");
6322
+ var import_utils34 = require("@fuel-ts/utils");
5732
6323
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
5733
6324
  var DEFAULT_KDF_PARAMS_R = 8;
5734
6325
  var DEFAULT_KDF_PARAMS_P = 1;
@@ -5741,38 +6332,38 @@ var removeHexPrefix = (hexString) => {
5741
6332
  return hexString;
5742
6333
  };
5743
6334
  async function encryptKeystoreWallet(privateKey, address, password) {
5744
- const privateKeyBuffer = (0, import_crypto4.bufferFromString)(removeHexPrefix(privateKey), "hex");
6335
+ const privateKeyBuffer = (0, import_crypto6.bufferFromString)(removeHexPrefix(privateKey), "hex");
5745
6336
  const ownerAddress = import_address6.Address.fromAddressOrString(address);
5746
- const salt = (0, import_crypto4.randomBytes)(DEFAULT_KEY_SIZE);
5747
- const key = (0, import_crypto4.scrypt)({
5748
- password: (0, import_crypto4.bufferFromString)(password),
6337
+ const salt = (0, import_crypto6.randomBytes)(DEFAULT_KEY_SIZE);
6338
+ const key = (0, import_crypto6.scrypt)({
6339
+ password: (0, import_crypto6.bufferFromString)(password),
5749
6340
  salt,
5750
6341
  dklen: DEFAULT_KEY_SIZE,
5751
6342
  n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
5752
6343
  r: DEFAULT_KDF_PARAMS_R,
5753
6344
  p: DEFAULT_KDF_PARAMS_P
5754
6345
  });
5755
- const iv = (0, import_crypto4.randomBytes)(DEFAULT_IV_SIZE);
5756
- const ciphertext = await (0, import_crypto4.encryptJsonWalletData)(privateKeyBuffer, key, iv);
6346
+ const iv = (0, import_crypto6.randomBytes)(DEFAULT_IV_SIZE);
6347
+ const ciphertext = await (0, import_crypto6.encryptJsonWalletData)(privateKeyBuffer, key, iv);
5757
6348
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
5758
- const macHashUint8Array = (0, import_crypto4.keccak256)(data);
5759
- const mac = (0, import_crypto4.stringFromBuffer)(macHashUint8Array, "hex");
6349
+ const macHashUint8Array = (0, import_crypto6.keccak256)(data);
6350
+ const mac = (0, import_crypto6.stringFromBuffer)(macHashUint8Array, "hex");
5760
6351
  const keystore = {
5761
- id: (0, import_uuid.v4)(),
6352
+ id: (0, import_crypto6.randomUUID)(),
5762
6353
  version: 3,
5763
6354
  address: removeHexPrefix(ownerAddress.toHexString()),
5764
6355
  crypto: {
5765
6356
  cipher: "aes-128-ctr",
5766
6357
  mac,
5767
- cipherparams: { iv: (0, import_crypto4.stringFromBuffer)(iv, "hex") },
5768
- ciphertext: (0, import_crypto4.stringFromBuffer)(ciphertext, "hex"),
6358
+ cipherparams: { iv: (0, import_crypto6.stringFromBuffer)(iv, "hex") },
6359
+ ciphertext: (0, import_crypto6.stringFromBuffer)(ciphertext, "hex"),
5769
6360
  kdf: "scrypt",
5770
6361
  kdfparams: {
5771
6362
  dklen: DEFAULT_KEY_SIZE,
5772
6363
  n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
5773
6364
  p: DEFAULT_KDF_PARAMS_P,
5774
6365
  r: DEFAULT_KDF_PARAMS_R,
5775
- salt: (0, import_crypto4.stringFromBuffer)(salt, "hex")
6366
+ salt: (0, import_crypto6.stringFromBuffer)(salt, "hex")
5776
6367
  }
5777
6368
  }
5778
6369
  };
@@ -5788,11 +6379,11 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5788
6379
  kdfparams: { dklen, n, r, p, salt }
5789
6380
  }
5790
6381
  } = keystoreWallet;
5791
- const ciphertextBuffer = (0, import_crypto4.bufferFromString)(ciphertext, "hex");
5792
- const ivBuffer = (0, import_crypto4.bufferFromString)(iv, "hex");
5793
- const saltBuffer = (0, import_crypto4.bufferFromString)(salt, "hex");
5794
- const passwordBuffer = (0, import_crypto4.bufferFromString)(password);
5795
- const key = (0, import_crypto4.scrypt)({
6382
+ const ciphertextBuffer = (0, import_crypto6.bufferFromString)(ciphertext, "hex");
6383
+ const ivBuffer = (0, import_crypto6.bufferFromString)(iv, "hex");
6384
+ const saltBuffer = (0, import_crypto6.bufferFromString)(salt, "hex");
6385
+ const passwordBuffer = (0, import_crypto6.bufferFromString)(password);
6386
+ const key = (0, import_crypto6.scrypt)({
5796
6387
  password: passwordBuffer,
5797
6388
  salt: saltBuffer,
5798
6389
  n,
@@ -5801,16 +6392,16 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5801
6392
  dklen
5802
6393
  });
5803
6394
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertextBuffer]);
5804
- const macHashUint8Array = (0, import_crypto4.keccak256)(data);
5805
- const macHash = (0, import_crypto4.stringFromBuffer)(macHashUint8Array, "hex");
6395
+ const macHashUint8Array = (0, import_crypto6.keccak256)(data);
6396
+ const macHash = (0, import_crypto6.stringFromBuffer)(macHashUint8Array, "hex");
5806
6397
  if (mac !== macHash) {
5807
- throw new import_errors17.FuelError(
5808
- import_errors17.ErrorCode.INVALID_PASSWORD,
6398
+ throw new import_errors19.FuelError(
6399
+ import_errors19.ErrorCode.INVALID_PASSWORD,
5809
6400
  "Failed to decrypt the keystore wallet, the provided password is incorrect."
5810
6401
  );
5811
6402
  }
5812
- const buffer = await (0, import_crypto4.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5813
- const privateKey = (0, import_utils31.hexlify)(buffer);
6403
+ const buffer = await (0, import_crypto6.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
6404
+ const privateKey = (0, import_utils34.hexlify)(buffer);
5814
6405
  return privateKey;
5815
6406
  }
5816
6407
 
@@ -5855,7 +6446,7 @@ var BaseWalletUnlocked = class extends Account {
5855
6446
  */
5856
6447
  async signMessage(message) {
5857
6448
  const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
5858
- return (0, import_utils32.hexlify)(signedMessage);
6449
+ return (0, import_utils35.hexlify)(signedMessage);
5859
6450
  }
5860
6451
  /**
5861
6452
  * Signs a transaction with the wallet's private key.
@@ -5868,7 +6459,7 @@ var BaseWalletUnlocked = class extends Account {
5868
6459
  const chainId = this.provider.getChainId();
5869
6460
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5870
6461
  const signature = await this.signer().sign(hashedTransaction);
5871
- return (0, import_utils32.hexlify)(signature);
6462
+ return (0, import_utils35.hexlify)(signature);
5872
6463
  }
5873
6464
  /**
5874
6465
  * Populates a transaction with the witnesses signature.
@@ -5934,17 +6525,17 @@ var BaseWalletUnlocked = class extends Account {
5934
6525
  __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5935
6526
 
5936
6527
  // src/hdwallet/hdwallet.ts
5937
- var import_crypto6 = require("@fuel-ts/crypto");
5938
- var import_errors20 = require("@fuel-ts/errors");
6528
+ var import_crypto8 = require("@fuel-ts/crypto");
6529
+ var import_errors22 = require("@fuel-ts/errors");
5939
6530
  var import_hasher6 = require("@fuel-ts/hasher");
5940
- var import_math22 = require("@fuel-ts/math");
5941
- var import_utils36 = require("@fuel-ts/utils");
6531
+ var import_math23 = require("@fuel-ts/math");
6532
+ var import_utils39 = require("@fuel-ts/utils");
5942
6533
 
5943
6534
  // src/mnemonic/mnemonic.ts
5944
- var import_crypto5 = require("@fuel-ts/crypto");
5945
- var import_errors19 = require("@fuel-ts/errors");
6535
+ var import_crypto7 = require("@fuel-ts/crypto");
6536
+ var import_errors21 = require("@fuel-ts/errors");
5946
6537
  var import_hasher5 = require("@fuel-ts/hasher");
5947
- var import_utils34 = require("@fuel-ts/utils");
6538
+ var import_utils37 = require("@fuel-ts/utils");
5948
6539
 
5949
6540
  // src/wordlists/words/english.ts
5950
6541
  var english = [
@@ -7999,9 +8590,9 @@ var english = [
7999
8590
  ];
8000
8591
 
8001
8592
  // src/mnemonic/utils.ts
8002
- var import_errors18 = require("@fuel-ts/errors");
8593
+ var import_errors20 = require("@fuel-ts/errors");
8003
8594
  var import_hasher4 = require("@fuel-ts/hasher");
8004
- var import_utils33 = require("@fuel-ts/utils");
8595
+ var import_utils36 = require("@fuel-ts/utils");
8005
8596
  function getLowerMask(bits) {
8006
8597
  return (1 << bits) - 1;
8007
8598
  }
@@ -8036,20 +8627,20 @@ function entropyToMnemonicIndices(entropy) {
8036
8627
  }
8037
8628
  }
8038
8629
  const checksumBits = entropy.length / 4;
8039
- const checksum = (0, import_utils33.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
8630
+ const checksum = (0, import_utils36.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
8040
8631
  indices[indices.length - 1] <<= checksumBits;
8041
8632
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
8042
8633
  return indices;
8043
8634
  }
8044
8635
  function mnemonicWordsToEntropy(words, wordlist) {
8045
8636
  const size = Math.ceil(11 * words.length / 8);
8046
- const entropy = (0, import_utils33.arrayify)(new Uint8Array(size));
8637
+ const entropy = (0, import_utils36.arrayify)(new Uint8Array(size));
8047
8638
  let offset = 0;
8048
8639
  for (let i = 0; i < words.length; i += 1) {
8049
8640
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
8050
8641
  if (index === -1) {
8051
- throw new import_errors18.FuelError(
8052
- import_errors18.ErrorCode.INVALID_MNEMONIC,
8642
+ throw new import_errors20.FuelError(
8643
+ import_errors20.ErrorCode.INVALID_MNEMONIC,
8053
8644
  `Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
8054
8645
  );
8055
8646
  }
@@ -8063,10 +8654,10 @@ function mnemonicWordsToEntropy(words, wordlist) {
8063
8654
  const entropyBits = 32 * words.length / 3;
8064
8655
  const checksumBits = words.length / 3;
8065
8656
  const checksumMask = getUpperMask(checksumBits);
8066
- const checksum = (0, import_utils33.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
8657
+ const checksum = (0, import_utils36.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
8067
8658
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
8068
- throw new import_errors18.FuelError(
8069
- import_errors18.ErrorCode.INVALID_CHECKSUM,
8659
+ throw new import_errors20.FuelError(
8660
+ import_errors20.ErrorCode.INVALID_CHECKSUM,
8070
8661
  "Checksum validation failed for the provided mnemonic."
8071
8662
  );
8072
8663
  }
@@ -8074,22 +8665,22 @@ function mnemonicWordsToEntropy(words, wordlist) {
8074
8665
  }
8075
8666
 
8076
8667
  // src/mnemonic/mnemonic.ts
8077
- var MasterSecret = (0, import_utils34.toUtf8Bytes)("Bitcoin seed");
8668
+ var MasterSecret = (0, import_utils37.toUtf8Bytes)("Bitcoin seed");
8078
8669
  var MainnetPRV = "0x0488ade4";
8079
8670
  var TestnetPRV = "0x04358394";
8080
8671
  var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
8081
8672
  function assertWordList(wordlist) {
8082
8673
  if (wordlist.length !== 2048) {
8083
- throw new import_errors19.FuelError(
8084
- import_errors19.ErrorCode.INVALID_WORD_LIST,
8674
+ throw new import_errors21.FuelError(
8675
+ import_errors21.ErrorCode.INVALID_WORD_LIST,
8085
8676
  `Expected word list length of 2048, but got ${wordlist.length}.`
8086
8677
  );
8087
8678
  }
8088
8679
  }
8089
8680
  function assertEntropy(entropy) {
8090
8681
  if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
8091
- throw new import_errors19.FuelError(
8092
- import_errors19.ErrorCode.INVALID_ENTROPY,
8682
+ throw new import_errors21.FuelError(
8683
+ import_errors21.ErrorCode.INVALID_ENTROPY,
8093
8684
  `Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
8094
8685
  );
8095
8686
  }
@@ -8099,7 +8690,7 @@ function assertMnemonic(words) {
8099
8690
  const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
8100
8691
  ", "
8101
8692
  )}] words, but got ${words.length}.`;
8102
- throw new import_errors19.FuelError(import_errors19.ErrorCode.INVALID_MNEMONIC, errorMsg);
8693
+ throw new import_errors21.FuelError(import_errors21.ErrorCode.INVALID_MNEMONIC, errorMsg);
8103
8694
  }
8104
8695
  }
8105
8696
  var Mnemonic = class {
@@ -8138,7 +8729,7 @@ var Mnemonic = class {
8138
8729
  static mnemonicToEntropy(phrase, wordlist = english) {
8139
8730
  const words = getWords(phrase);
8140
8731
  assertMnemonic(words);
8141
- return (0, import_utils34.hexlify)(mnemonicWordsToEntropy(words, wordlist));
8732
+ return (0, import_utils37.hexlify)(mnemonicWordsToEntropy(words, wordlist));
8142
8733
  }
8143
8734
  /**
8144
8735
  * @param entropy - Entropy source to the mnemonic phrase.
@@ -8146,7 +8737,7 @@ var Mnemonic = class {
8146
8737
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
8147
8738
  */
8148
8739
  static entropyToMnemonic(entropy, wordlist = english) {
8149
- const entropyBytes = (0, import_utils34.arrayify)(entropy);
8740
+ const entropyBytes = (0, import_utils37.arrayify)(entropy);
8150
8741
  assertWordList(wordlist);
8151
8742
  assertEntropy(entropyBytes);
8152
8743
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -8158,9 +8749,9 @@ var Mnemonic = class {
8158
8749
  */
8159
8750
  static mnemonicToSeed(phrase, passphrase = "") {
8160
8751
  assertMnemonic(getWords(phrase));
8161
- const phraseBytes = (0, import_utils34.toUtf8Bytes)(getPhrase(phrase));
8162
- const salt = (0, import_utils34.toUtf8Bytes)(`mnemonic${passphrase}`);
8163
- return (0, import_crypto5.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
8752
+ const phraseBytes = (0, import_utils37.toUtf8Bytes)(getPhrase(phrase));
8753
+ const salt = (0, import_utils37.toUtf8Bytes)(`mnemonic${passphrase}`);
8754
+ return (0, import_crypto7.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
8164
8755
  }
8165
8756
  /**
8166
8757
  * @param phrase - Mnemonic phrase composed by words from the provided wordlist
@@ -8215,14 +8806,14 @@ var Mnemonic = class {
8215
8806
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
8216
8807
  */
8217
8808
  static masterKeysFromSeed(seed) {
8218
- const seedArray = (0, import_utils34.arrayify)(seed);
8809
+ const seedArray = (0, import_utils37.arrayify)(seed);
8219
8810
  if (seedArray.length < 16 || seedArray.length > 64) {
8220
- throw new import_errors19.FuelError(
8221
- import_errors19.ErrorCode.INVALID_SEED,
8811
+ throw new import_errors21.FuelError(
8812
+ import_errors21.ErrorCode.INVALID_SEED,
8222
8813
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
8223
8814
  );
8224
8815
  }
8225
- return (0, import_utils34.arrayify)((0, import_crypto5.computeHmac)("sha512", MasterSecret, seedArray));
8816
+ return (0, import_utils37.arrayify)((0, import_crypto7.computeHmac)("sha512", MasterSecret, seedArray));
8226
8817
  }
8227
8818
  /**
8228
8819
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -8233,22 +8824,22 @@ var Mnemonic = class {
8233
8824
  */
8234
8825
  static seedToExtendedKey(seed, testnet = false) {
8235
8826
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
8236
- const prefix = (0, import_utils34.arrayify)(testnet ? TestnetPRV : MainnetPRV);
8827
+ const prefix = (0, import_utils37.arrayify)(testnet ? TestnetPRV : MainnetPRV);
8237
8828
  const depth = "0x00";
8238
8829
  const fingerprint = "0x00000000";
8239
8830
  const index = "0x00000000";
8240
8831
  const chainCode = masterKey.slice(32);
8241
8832
  const privateKey = masterKey.slice(0, 32);
8242
- const extendedKey = (0, import_utils34.concat)([
8833
+ const extendedKey = (0, import_utils37.concat)([
8243
8834
  prefix,
8244
8835
  depth,
8245
8836
  fingerprint,
8246
8837
  index,
8247
8838
  chainCode,
8248
- (0, import_utils34.concat)(["0x00", privateKey])
8839
+ (0, import_utils37.concat)(["0x00", privateKey])
8249
8840
  ]);
8250
- const checksum = (0, import_utils34.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
8251
- return (0, import_utils34.encodeBase58)((0, import_utils34.concat)([extendedKey, checksum]));
8841
+ const checksum = (0, import_utils37.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
8842
+ return (0, import_utils37.encodeBase58)((0, import_utils37.concat)([extendedKey, checksum]));
8252
8843
  }
8253
8844
  /**
8254
8845
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -8263,7 +8854,7 @@ var Mnemonic = class {
8263
8854
  * @returns A randomly generated mnemonic
8264
8855
  */
8265
8856
  static generate(size = 32, extraEntropy = "") {
8266
- const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils34.concat)([(0, import_crypto5.randomBytes)(size), (0, import_utils34.arrayify)(extraEntropy)])) : (0, import_crypto5.randomBytes)(size);
8857
+ const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils37.concat)([(0, import_crypto7.randomBytes)(size), (0, import_utils37.arrayify)(extraEntropy)])) : (0, import_crypto7.randomBytes)(size);
8267
8858
  return Mnemonic.entropyToMnemonic(entropy);
8268
8859
  }
8269
8860
  };
@@ -8271,12 +8862,12 @@ var mnemonic_default = Mnemonic;
8271
8862
 
8272
8863
  // src/hdwallet/hdwallet.ts
8273
8864
  var HARDENED_INDEX = 2147483648;
8274
- var MainnetPRV2 = (0, import_utils36.hexlify)("0x0488ade4");
8275
- var MainnetPUB = (0, import_utils36.hexlify)("0x0488b21e");
8276
- var TestnetPRV2 = (0, import_utils36.hexlify)("0x04358394");
8277
- var TestnetPUB = (0, import_utils36.hexlify)("0x043587cf");
8865
+ var MainnetPRV2 = (0, import_utils39.hexlify)("0x0488ade4");
8866
+ var MainnetPUB = (0, import_utils39.hexlify)("0x0488b21e");
8867
+ var TestnetPRV2 = (0, import_utils39.hexlify)("0x04358394");
8868
+ var TestnetPUB = (0, import_utils39.hexlify)("0x043587cf");
8278
8869
  function base58check(data) {
8279
- return (0, import_utils36.encodeBase58)((0, import_utils36.concat)([data, (0, import_utils36.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
8870
+ return (0, import_utils39.encodeBase58)((0, import_utils39.concat)([data, (0, import_utils39.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
8280
8871
  }
8281
8872
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8282
8873
  if (isPublic) {
@@ -8285,17 +8876,17 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8285
8876
  return testnet ? TestnetPRV2 : MainnetPRV2;
8286
8877
  }
8287
8878
  function isPublicExtendedKey(extendedKey) {
8288
- return [MainnetPUB, TestnetPUB].includes((0, import_utils36.hexlify)(extendedKey.slice(0, 4)));
8879
+ return [MainnetPUB, TestnetPUB].includes((0, import_utils39.hexlify)(extendedKey.slice(0, 4)));
8289
8880
  }
8290
8881
  function isValidExtendedKey(extendedKey) {
8291
8882
  return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
8292
- (0, import_utils36.hexlify)(extendedKey.slice(0, 4))
8883
+ (0, import_utils39.hexlify)(extendedKey.slice(0, 4))
8293
8884
  );
8294
8885
  }
8295
8886
  function parsePath(path2, depth = 0) {
8296
8887
  const components = path2.split("/");
8297
8888
  if (components.length === 0 || components[0] === "m" && depth !== 0) {
8298
- throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
8889
+ throw new import_errors22.FuelError(import_errors22.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
8299
8890
  }
8300
8891
  if (components[0] === "m") {
8301
8892
  components.shift();
@@ -8307,8 +8898,8 @@ function parsePath(path2, depth = 0) {
8307
8898
  var HDWallet = class {
8308
8899
  depth = 0;
8309
8900
  index = 0;
8310
- fingerprint = (0, import_utils36.hexlify)("0x00000000");
8311
- parentFingerprint = (0, import_utils36.hexlify)("0x00000000");
8901
+ fingerprint = (0, import_utils39.hexlify)("0x00000000");
8902
+ parentFingerprint = (0, import_utils39.hexlify)("0x00000000");
8312
8903
  privateKey;
8313
8904
  publicKey;
8314
8905
  chainCode;
@@ -8320,19 +8911,19 @@ var HDWallet = class {
8320
8911
  constructor(config) {
8321
8912
  if (config.privateKey) {
8322
8913
  const signer = new Signer(config.privateKey);
8323
- this.publicKey = (0, import_utils36.hexlify)(signer.compressedPublicKey);
8324
- this.privateKey = (0, import_utils36.hexlify)(config.privateKey);
8914
+ this.publicKey = (0, import_utils39.hexlify)(signer.compressedPublicKey);
8915
+ this.privateKey = (0, import_utils39.hexlify)(config.privateKey);
8325
8916
  } else {
8326
8917
  if (!config.publicKey) {
8327
- throw new import_errors20.FuelError(
8328
- import_errors20.ErrorCode.HD_WALLET_ERROR,
8918
+ throw new import_errors22.FuelError(
8919
+ import_errors22.ErrorCode.HD_WALLET_ERROR,
8329
8920
  "Both public and private Key cannot be missing. At least one should be provided."
8330
8921
  );
8331
8922
  }
8332
- this.publicKey = (0, import_utils36.hexlify)(config.publicKey);
8923
+ this.publicKey = (0, import_utils39.hexlify)(config.publicKey);
8333
8924
  }
8334
8925
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
8335
- this.fingerprint = (0, import_utils36.dataSlice)((0, import_crypto6.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8926
+ this.fingerprint = (0, import_utils39.dataSlice)((0, import_crypto8.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8336
8927
  this.depth = config.depth || this.depth;
8337
8928
  this.index = config.index || this.index;
8338
8929
  this.chainCode = config.chainCode;
@@ -8348,28 +8939,28 @@ var HDWallet = class {
8348
8939
  * @returns A new instance of HDWallet on the derived index
8349
8940
  */
8350
8941
  deriveIndex(index) {
8351
- const privateKey = this.privateKey && (0, import_utils36.arrayify)(this.privateKey);
8352
- const publicKey = (0, import_utils36.arrayify)(this.publicKey);
8353
- const chainCode = (0, import_utils36.arrayify)(this.chainCode);
8942
+ const privateKey = this.privateKey && (0, import_utils39.arrayify)(this.privateKey);
8943
+ const publicKey = (0, import_utils39.arrayify)(this.publicKey);
8944
+ const chainCode = (0, import_utils39.arrayify)(this.chainCode);
8354
8945
  const data = new Uint8Array(37);
8355
8946
  if (index & HARDENED_INDEX) {
8356
8947
  if (!privateKey) {
8357
- throw new import_errors20.FuelError(
8358
- import_errors20.ErrorCode.HD_WALLET_ERROR,
8948
+ throw new import_errors22.FuelError(
8949
+ import_errors22.ErrorCode.HD_WALLET_ERROR,
8359
8950
  "Cannot derive a hardened index without a private Key."
8360
8951
  );
8361
8952
  }
8362
8953
  data.set(privateKey, 1);
8363
8954
  } else {
8364
- data.set((0, import_utils36.arrayify)(this.publicKey));
8955
+ data.set((0, import_utils39.arrayify)(this.publicKey));
8365
8956
  }
8366
- data.set((0, import_math22.toBytes)(index, 4), 33);
8367
- const bytes = (0, import_utils36.arrayify)((0, import_crypto6.computeHmac)("sha512", chainCode, data));
8957
+ data.set((0, import_math23.toBytes)(index, 4), 33);
8958
+ const bytes = (0, import_utils39.arrayify)((0, import_crypto8.computeHmac)("sha512", chainCode, data));
8368
8959
  const IL = bytes.slice(0, 32);
8369
8960
  const IR = bytes.slice(32);
8370
8961
  if (privateKey) {
8371
8962
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
8372
- const ki = (0, import_math22.bn)(IL).add(privateKey).mod(N).toBytes(32);
8963
+ const ki = (0, import_math23.bn)(IL).add(privateKey).mod(N).toBytes(32);
8373
8964
  return new HDWallet({
8374
8965
  privateKey: ki,
8375
8966
  chainCode: IR,
@@ -8378,7 +8969,7 @@ var HDWallet = class {
8378
8969
  parentFingerprint: this.fingerprint
8379
8970
  });
8380
8971
  }
8381
- const signer = new Signer((0, import_utils36.hexlify)(IL));
8972
+ const signer = new Signer((0, import_utils39.hexlify)(IL));
8382
8973
  const Ki = signer.addPoint(publicKey);
8383
8974
  return new HDWallet({
8384
8975
  publicKey: Ki,
@@ -8407,18 +8998,18 @@ var HDWallet = class {
8407
8998
  */
8408
8999
  toExtendedKey(isPublic = false, testnet = false) {
8409
9000
  if (this.depth >= 256) {
8410
- throw new import_errors20.FuelError(
8411
- import_errors20.ErrorCode.HD_WALLET_ERROR,
9001
+ throw new import_errors22.FuelError(
9002
+ import_errors22.ErrorCode.HD_WALLET_ERROR,
8412
9003
  `Exceeded max depth of 255. Current depth: ${this.depth}.`
8413
9004
  );
8414
9005
  }
8415
9006
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
8416
- const depth = (0, import_utils36.hexlify)(Uint8Array.from([this.depth]));
9007
+ const depth = (0, import_utils39.hexlify)(Uint8Array.from([this.depth]));
8417
9008
  const parentFingerprint = this.parentFingerprint;
8418
- const index = (0, import_math22.toHex)(this.index, 4);
9009
+ const index = (0, import_math23.toHex)(this.index, 4);
8419
9010
  const chainCode = this.chainCode;
8420
- const key = this.privateKey != null && !isPublic ? (0, import_utils36.concat)(["0x00", this.privateKey]) : this.publicKey;
8421
- const extendedKey = (0, import_utils36.arrayify)((0, import_utils36.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
9011
+ const key = this.privateKey != null && !isPublic ? (0, import_utils39.concat)(["0x00", this.privateKey]) : this.publicKey;
9012
+ const extendedKey = (0, import_utils39.arrayify)((0, import_utils39.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8422
9013
  return base58check(extendedKey);
8423
9014
  }
8424
9015
  /**
@@ -8430,34 +9021,34 @@ var HDWallet = class {
8430
9021
  static fromSeed(seed) {
8431
9022
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
8432
9023
  return new HDWallet({
8433
- chainCode: (0, import_utils36.arrayify)(masterKey.slice(32)),
8434
- privateKey: (0, import_utils36.arrayify)(masterKey.slice(0, 32))
9024
+ chainCode: (0, import_utils39.arrayify)(masterKey.slice(32)),
9025
+ privateKey: (0, import_utils39.arrayify)(masterKey.slice(0, 32))
8435
9026
  });
8436
9027
  }
8437
9028
  static fromExtendedKey(extendedKey) {
8438
- const decoded = (0, import_utils36.hexlify)((0, import_math22.toBytes)((0, import_utils36.decodeBase58)(extendedKey)));
8439
- const bytes = (0, import_utils36.arrayify)(decoded);
9029
+ const decoded = (0, import_utils39.hexlify)((0, import_math23.toBytes)((0, import_utils39.decodeBase58)(extendedKey)));
9030
+ const bytes = (0, import_utils39.arrayify)(decoded);
8440
9031
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
8441
9032
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
8442
- throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
9033
+ throw new import_errors22.FuelError(import_errors22.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
8443
9034
  }
8444
9035
  if (!validChecksum) {
8445
- throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
9036
+ throw new import_errors22.FuelError(import_errors22.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
8446
9037
  }
8447
9038
  const depth = bytes[4];
8448
- const parentFingerprint = (0, import_utils36.hexlify)(bytes.slice(5, 9));
8449
- const index = parseInt((0, import_utils36.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8450
- const chainCode = (0, import_utils36.hexlify)(bytes.slice(13, 45));
9039
+ const parentFingerprint = (0, import_utils39.hexlify)(bytes.slice(5, 9));
9040
+ const index = parseInt((0, import_utils39.hexlify)(bytes.slice(9, 13)).substring(2), 16);
9041
+ const chainCode = (0, import_utils39.hexlify)(bytes.slice(13, 45));
8451
9042
  const key = bytes.slice(45, 78);
8452
9043
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
8453
- throw new import_errors20.FuelError(
8454
- import_errors20.ErrorCode.HD_WALLET_ERROR,
9044
+ throw new import_errors22.FuelError(
9045
+ import_errors22.ErrorCode.HD_WALLET_ERROR,
8455
9046
  "Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
8456
9047
  );
8457
9048
  }
8458
9049
  if (isPublicExtendedKey(bytes)) {
8459
9050
  if (key[0] !== 3) {
8460
- throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
9051
+ throw new import_errors22.FuelError(import_errors22.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
8461
9052
  }
8462
9053
  return new HDWallet({
8463
9054
  publicKey: key,
@@ -8468,7 +9059,7 @@ var HDWallet = class {
8468
9059
  });
8469
9060
  }
8470
9061
  if (key[0] !== 0) {
8471
- throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
9062
+ throw new import_errors22.FuelError(import_errors22.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
8472
9063
  }
8473
9064
  return new HDWallet({
8474
9065
  privateKey: key.slice(1),
@@ -8633,297 +9224,7 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
8633
9224
  */
8634
9225
  __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
8635
9226
 
8636
- // src/test-utils/seedTestWallet.ts
8637
- var import_crypto7 = require("@fuel-ts/crypto");
8638
- var seedTestWallet = async (wallet, quantities, utxosAmount = 1) => {
8639
- const accountsToBeFunded = Array.isArray(wallet) ? wallet : [wallet];
8640
- const [{ provider }] = accountsToBeFunded;
8641
- const genesisWallet = new WalletUnlocked(process.env.GENESIS_SECRET || (0, import_crypto7.randomBytes)(32), provider);
8642
- const request = new ScriptTransactionRequest();
8643
- quantities.map(coinQuantityfy).forEach(
8644
- ({ amount, assetId }) => accountsToBeFunded.forEach(({ address }) => {
8645
- for (let i = 0; i < utxosAmount; i++) {
8646
- request.addCoinOutput(address, amount.div(utxosAmount), assetId);
8647
- }
8648
- })
8649
- );
8650
- const txCost = await genesisWallet.getTransactionCost(request);
8651
- request.gasLimit = txCost.gasUsed;
8652
- request.maxFee = txCost.maxFee;
8653
- await genesisWallet.fund(request, txCost);
8654
- const submit = await genesisWallet.sendTransaction(request);
8655
- await submit.waitForResult();
8656
- };
8657
-
8658
- // src/test-utils/generateTestWallet.ts
8659
- var generateTestWallet = async (provider, quantities) => {
8660
- const wallet = Wallet.generate({ provider });
8661
- if (quantities) {
8662
- await seedTestWallet(wallet, quantities);
8663
- }
8664
- return wallet;
8665
- };
8666
-
8667
- // src/test-utils/launchNode.ts
8668
- var import_abi_coder8 = require("@fuel-ts/abi-coder");
8669
- var import_crypto8 = require("@fuel-ts/crypto");
8670
- var import_errors21 = require("@fuel-ts/errors");
8671
- var import_utils37 = require("@fuel-ts/utils");
8672
- var import_crypto9 = require("crypto");
8673
- var import_fs = require("fs");
8674
- var import_os = __toESM(require("os"));
8675
- var import_path = __toESM(require("path"));
8676
- var import_portfinder = require("portfinder");
8677
- var getFlagValueFromArgs = (args, flag) => {
8678
- const flagIndex = args.indexOf(flag);
8679
- if (flagIndex === -1) {
8680
- return void 0;
8681
- }
8682
- return args[flagIndex + 1];
8683
- };
8684
- var extractRemainingArgs = (args, flagsToRemove) => {
8685
- const newArgs = [...args];
8686
- flagsToRemove.forEach((flag) => {
8687
- const flagIndex = newArgs.indexOf(flag);
8688
- if (flagIndex !== -1) {
8689
- newArgs.splice(flagIndex, 2);
8690
- }
8691
- });
8692
- return newArgs;
8693
- };
8694
- function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
8695
- const defaultCoins = import_utils37.defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
8696
- ...coin,
8697
- amount: "18446744073709551615"
8698
- }));
8699
- const defaultMessages = import_utils37.defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
8700
- ...message,
8701
- amount: "18446744073709551615"
8702
- }));
8703
- const coins = defaultCoins.concat(stateConfig.coins.map((coin) => ({ ...coin, amount: coin.amount.toString() }))).filter((coin, index, self) => self.findIndex((c) => c.tx_id === coin.tx_id) === index);
8704
- const messages = defaultMessages.concat(stateConfig.messages.map((msg) => ({ ...msg, amount: msg.amount.toString() }))).filter((msg, index, self) => self.findIndex((m) => m.nonce === msg.nonce) === index);
8705
- if (!process.env.GENESIS_SECRET) {
8706
- const pk = Signer.generatePrivateKey();
8707
- const signer = new Signer(pk);
8708
- process.env.GENESIS_SECRET = (0, import_utils37.hexlify)(pk);
8709
- coins.push({
8710
- tx_id: (0, import_utils37.hexlify)((0, import_crypto8.randomBytes)(import_abi_coder8.BYTES_32)),
8711
- owner: signer.address.toHexString(),
8712
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8713
- amount: "18446744073709551615",
8714
- asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
8715
- output_index: 0,
8716
- tx_pointer_block_height: 0,
8717
- tx_pointer_tx_idx: 0
8718
- });
8719
- }
8720
- const json = JSON.stringify({
8721
- ...stateConfig,
8722
- coins,
8723
- messages
8724
- });
8725
- const regexMakeNumber = /("amount":)"(\d+)"/gm;
8726
- return json.replace(regexMakeNumber, "$1$2");
8727
- }
8728
- var launchNode = async ({
8729
- ip,
8730
- port,
8731
- args = [],
8732
- fuelCorePath = process.env.FUEL_CORE_PATH || void 0,
8733
- loggingEnabled = true,
8734
- basePath,
8735
- snapshotConfig = import_utils37.defaultSnapshotConfigs
8736
- } = {}) => (
8737
- // eslint-disable-next-line no-async-promise-executor
8738
- new Promise(async (resolve, reject) => {
8739
- const remainingArgs = extractRemainingArgs(args, [
8740
- "--snapshot",
8741
- "--consensus-key",
8742
- "--db-type",
8743
- "--poa-instant",
8744
- "--min-gas-price",
8745
- "--native-executor-version"
8746
- ]);
8747
- const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
8748
- const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils37.defaultConsensusKey;
8749
- const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
8750
- const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
8751
- const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
8752
- const poaInstant = poaInstantFlagValue === "true" || poaInstantFlagValue === void 0;
8753
- const nativeExecutorVersion = getFlagValueFromArgs(args, "--native-executor-version") || "0";
8754
- const minGasPrice = getFlagValueFromArgs(args, "--min-gas-price") || "1";
8755
- const graphQLStartSubstring = "Binding GraphQL provider to";
8756
- const command = fuelCorePath || "fuel-core";
8757
- const ipToUse = ip || "0.0.0.0";
8758
- const portToUse = port || (await (0, import_portfinder.getPortPromise)({
8759
- port: 4e3,
8760
- // tries 4000 first, then 4001, then 4002, etc.
8761
- stopPort: 5e3
8762
- // don't try ports above 5000
8763
- })).toString();
8764
- let snapshotDirToUse;
8765
- const prefix = basePath || import_os.default.tmpdir();
8766
- const suffix = basePath ? "" : (0, import_crypto9.randomUUID)();
8767
- const tempDir = import_path.default.join(prefix, ".fuels", suffix, "snapshotDir");
8768
- if (snapshotDir) {
8769
- snapshotDirToUse = snapshotDir;
8770
- } else {
8771
- if (!(0, import_fs.existsSync)(tempDir)) {
8772
- (0, import_fs.mkdirSync)(tempDir, { recursive: true });
8773
- }
8774
- const { metadata } = snapshotConfig;
8775
- const metadataPath = import_path.default.join(tempDir, "metadata.json");
8776
- const chainConfigPath = import_path.default.join(tempDir, metadata.chain_config);
8777
- const stateConfigPath = import_path.default.join(tempDir, metadata.table_encoding.Json.filepath);
8778
- const stateTransitionPath = import_path.default.join(tempDir, "state_transition_bytecode.wasm");
8779
- (0, import_fs.writeFileSync)(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
8780
- (0, import_fs.writeFileSync)(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
8781
- (0, import_fs.writeFileSync)(metadataPath, JSON.stringify(metadata), "utf8");
8782
- (0, import_fs.writeFileSync)(stateTransitionPath, JSON.stringify(""));
8783
- snapshotDirToUse = tempDir;
8784
- }
8785
- const { spawn } = await import("child_process");
8786
- const child = spawn(
8787
- command,
8788
- [
8789
- "run",
8790
- ["--ip", ipToUse],
8791
- ["--port", portToUse],
8792
- useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
8793
- ["--min-gas-price", minGasPrice],
8794
- poaInstant ? ["--poa-instant", "true"] : [],
8795
- ["--native-executor-version", nativeExecutorVersion],
8796
- ["--consensus-key", consensusKey],
8797
- ["--snapshot", snapshotDirToUse],
8798
- "--vm-backtrace",
8799
- "--utxo-validation",
8800
- "--debug",
8801
- ...remainingArgs
8802
- ].flat(),
8803
- { stdio: "pipe", detached: true }
8804
- );
8805
- if (loggingEnabled) {
8806
- child.stderr.on("data", (chunk) => {
8807
- console.log(chunk.toString());
8808
- });
8809
- }
8810
- const removeSideffects = () => {
8811
- child.stderr.removeAllListeners();
8812
- if ((0, import_fs.existsSync)(tempDir)) {
8813
- (0, import_fs.rmSync)(tempDir, { recursive: true });
8814
- }
8815
- };
8816
- child.on("error", removeSideffects);
8817
- child.on("exit", removeSideffects);
8818
- const childState = {
8819
- isDead: false
8820
- };
8821
- const cleanup = () => {
8822
- if (childState.isDead) {
8823
- return;
8824
- }
8825
- childState.isDead = true;
8826
- removeSideffects();
8827
- if (child.pid !== void 0) {
8828
- try {
8829
- process.kill(-child.pid);
8830
- } catch (e) {
8831
- const error = e;
8832
- if (error.code === "ESRCH") {
8833
- console.log(
8834
- `fuel-core node under pid ${child.pid} does not exist. The node might have been killed before cleanup was called. Exiting cleanly.`
8835
- );
8836
- } else {
8837
- throw e;
8838
- }
8839
- }
8840
- } else {
8841
- console.error("No PID available for the child process, unable to kill launched node");
8842
- }
8843
- };
8844
- child.stderr.on("data", (chunk) => {
8845
- const text = typeof chunk === "string" ? chunk : chunk.toString();
8846
- if (text.indexOf(graphQLStartSubstring) !== -1) {
8847
- const rows = text.split("\n");
8848
- const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
8849
- const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
8850
- resolve({
8851
- cleanup,
8852
- ip: realIp,
8853
- port: realPort,
8854
- url: `http://${realIp}:${realPort}/v1/graphql`,
8855
- snapshotDir: snapshotDirToUse,
8856
- pid: child.pid
8857
- });
8858
- }
8859
- if (/error/i.test(text)) {
8860
- console.log(text);
8861
- reject(new import_errors21.FuelError(import_errors21.FuelError.CODES.NODE_LAUNCH_FAILED, text));
8862
- }
8863
- });
8864
- process.on("exit", cleanup);
8865
- process.on("SIGINT", cleanup);
8866
- process.on("SIGUSR1", cleanup);
8867
- process.on("SIGUSR2", cleanup);
8868
- process.on("beforeExit", cleanup);
8869
- process.on("uncaughtException", cleanup);
8870
- child.on("error", reject);
8871
- })
8872
- );
8873
- var generateWallets = async (count, provider) => {
8874
- const baseAssetId = provider.getBaseAssetId();
8875
- const wallets = [];
8876
- for (let i = 0; i < count; i += 1) {
8877
- const wallet = await generateTestWallet(provider, [[1e5, baseAssetId]]);
8878
- wallets.push(wallet);
8879
- }
8880
- return wallets;
8881
- };
8882
- var launchNodeAndGetWallets = async ({
8883
- launchNodeOptions,
8884
- providerOptions,
8885
- walletCount = 10
8886
- } = {}) => {
8887
- const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
8888
- const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`, providerOptions);
8889
- const wallets = await generateWallets(walletCount, provider);
8890
- const cleanup = () => {
8891
- closeNode();
8892
- };
8893
- return { wallets, stop: cleanup, provider };
8894
- };
8895
-
8896
- // src/test-utils/setup-test-provider-and-wallets.ts
8897
- var import_utils40 = require("@fuel-ts/utils");
8898
- var import_ramda5 = require("ramda");
8899
-
8900
- // src/test-utils/asset-id.ts
8901
- var import_crypto10 = require("@fuel-ts/crypto");
8902
- var import_utils38 = require("@fuel-ts/utils");
8903
- var _AssetId = class {
8904
- constructor(value) {
8905
- this.value = value;
8906
- }
8907
- static random(count = 1) {
8908
- const assetIds = [];
8909
- for (let i = 0; i < count; i++) {
8910
- assetIds.push(new _AssetId((0, import_utils38.hexlify)((0, import_crypto10.randomBytes)(32))));
8911
- }
8912
- return assetIds;
8913
- }
8914
- };
8915
- var AssetId = _AssetId;
8916
- __publicField(AssetId, "A", new _AssetId(
8917
- "0x0101010101010101010101010101010101010101010101010101010101010101"
8918
- ));
8919
- __publicField(AssetId, "B", new _AssetId(
8920
- "0x0202020202020202020202020202020202020202020202020202020202020202"
8921
- ));
8922
-
8923
9227
  // src/test-utils/wallet-config.ts
8924
- var import_crypto11 = require("@fuel-ts/crypto");
8925
- var import_errors22 = require("@fuel-ts/errors");
8926
- var import_utils39 = require("@fuel-ts/utils");
8927
9228
  var WalletsConfig = class {
8928
9229
  initialState;
8929
9230
  options;
@@ -8931,7 +9232,7 @@ var WalletsConfig = class {
8931
9232
  generateWallets = () => {
8932
9233
  const generatedWallets = [];
8933
9234
  for (let index = 1; index <= this.options.count; index++) {
8934
- generatedWallets.push(new WalletUnlocked((0, import_crypto11.randomBytes)(32)));
9235
+ generatedWallets.push(new WalletUnlocked((0, import_crypto9.randomBytes)(32)));
8935
9236
  }
8936
9237
  return generatedWallets;
8937
9238
  };
@@ -8955,7 +9256,7 @@ var WalletsConfig = class {
8955
9256
  return {
8956
9257
  ...snapshotConfig,
8957
9258
  stateConfig: {
8958
- ...snapshotConfig?.stateConfig ?? import_utils39.defaultSnapshotConfigs.stateConfig,
9259
+ ...snapshotConfig?.stateConfig ?? import_utils40.defaultSnapshotConfigs.stateConfig,
8959
9260
  coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
8960
9261
  messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
8961
9262
  }
@@ -8976,7 +9277,7 @@ var WalletsConfig = class {
8976
9277
  if (Array.isArray(assets2)) {
8977
9278
  assetIds = assetIds.concat(assets2.map((a) => a.value));
8978
9279
  } else {
8979
- assetIds = assetIds.concat(AssetId.random(assets2 - 1).map((a) => a.value));
9280
+ assetIds = assetIds.concat(TestAssetId.random(assets2 - 1).map((a) => a.value));
8980
9281
  }
8981
9282
  wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
8982
9283
  assetIds.forEach((assetId) => {
@@ -8988,7 +9289,7 @@ var WalletsConfig = class {
8988
9289
  tx_pointer_block_height: 0,
8989
9290
  tx_pointer_tx_idx: 0,
8990
9291
  output_index: 0,
8991
- tx_id: (0, import_utils39.hexlify)((0, import_crypto11.randomBytes)(32))
9292
+ tx_id: (0, import_utils40.hexlify)((0, import_crypto9.randomBytes)(32))
8992
9293
  });
8993
9294
  }
8994
9295
  });
@@ -9002,27 +9303,27 @@ var WalletsConfig = class {
9002
9303
  amountPerCoin
9003
9304
  }) {
9004
9305
  if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
9005
- throw new import_errors22.FuelError(
9006
- import_errors22.FuelError.CODES.INVALID_INPUT_PARAMETERS,
9306
+ throw new import_errors23.FuelError(
9307
+ import_errors23.FuelError.CODES.INVALID_INPUT_PARAMETERS,
9007
9308
  "Number of wallets must be greater than zero."
9008
9309
  );
9009
9310
  }
9010
9311
  if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
9011
- throw new import_errors22.FuelError(
9012
- import_errors22.FuelError.CODES.INVALID_INPUT_PARAMETERS,
9312
+ throw new import_errors23.FuelError(
9313
+ import_errors23.FuelError.CODES.INVALID_INPUT_PARAMETERS,
9013
9314
  "Number of assets per wallet must be greater than zero."
9014
9315
  );
9015
9316
  }
9016
9317
  if (coinsPerAsset <= 0) {
9017
- throw new import_errors22.FuelError(
9018
- import_errors22.FuelError.CODES.INVALID_INPUT_PARAMETERS,
9318
+ throw new import_errors23.FuelError(
9319
+ import_errors23.FuelError.CODES.INVALID_INPUT_PARAMETERS,
9019
9320
  "Number of coins per asset must be greater than zero."
9020
9321
  );
9021
9322
  }
9022
- if (amountPerCoin <= 0) {
9023
- throw new import_errors22.FuelError(
9024
- import_errors22.FuelError.CODES.INVALID_INPUT_PARAMETERS,
9025
- "Amount per coin must be greater than zero."
9323
+ if (amountPerCoin < 0) {
9324
+ throw new import_errors23.FuelError(
9325
+ import_errors23.FuelError.CODES.INVALID_INPUT_PARAMETERS,
9326
+ "Amount per coin must be greater than or equal to zero."
9026
9327
  );
9027
9328
  }
9028
9329
  }
@@ -9031,7 +9332,7 @@ var WalletsConfig = class {
9031
9332
  // src/test-utils/setup-test-provider-and-wallets.ts
9032
9333
  var defaultWalletConfigOptions = {
9033
9334
  count: 2,
9034
- assets: [AssetId.A, AssetId.B],
9335
+ assets: [TestAssetId.A, TestAssetId.B],
9035
9336
  coinsPerAsset: 1,
9036
9337
  amountPerCoin: 1e10,
9037
9338
  messages: []
@@ -9044,7 +9345,7 @@ async function setupTestProviderAndWallets({
9044
9345
  } = {}) {
9045
9346
  Symbol.dispose ??= Symbol("Symbol.dispose");
9046
9347
  const walletsConfig = new WalletsConfig(
9047
- nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? import_utils40.defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.base_asset_id,
9348
+ nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? import_utils41.defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.base_asset_id,
9048
9349
  {
9049
9350
  ...defaultWalletConfigOptions,
9050
9351
  ...walletsConfigOptions
@@ -9054,10 +9355,10 @@ async function setupTestProviderAndWallets({
9054
9355
  loggingEnabled: false,
9055
9356
  ...nodeOptions,
9056
9357
  snapshotConfig: (0, import_ramda5.mergeDeepRight)(
9057
- import_utils40.defaultSnapshotConfigs,
9358
+ import_utils41.defaultSnapshotConfigs,
9058
9359
  walletsConfig.apply(nodeOptions?.snapshotConfig)
9059
9360
  ),
9060
- port: "0"
9361
+ port: nodeOptions.port || "0"
9061
9362
  };
9062
9363
  let cleanup;
9063
9364
  let url;
@@ -9093,9 +9394,9 @@ async function setupTestProviderAndWallets({
9093
9394
 
9094
9395
  // src/test-utils/test-message.ts
9095
9396
  var import_address7 = require("@fuel-ts/address");
9096
- var import_crypto12 = require("@fuel-ts/crypto");
9097
- var import_math23 = require("@fuel-ts/math");
9098
- var import_utils41 = require("@fuel-ts/utils");
9397
+ var import_crypto10 = require("@fuel-ts/crypto");
9398
+ var import_math24 = require("@fuel-ts/math");
9399
+ var import_utils42 = require("@fuel-ts/utils");
9099
9400
  var TestMessage = class {
9100
9401
  sender;
9101
9402
  recipient;
@@ -9112,9 +9413,10 @@ var TestMessage = class {
9112
9413
  constructor({
9113
9414
  sender = import_address7.Address.fromRandom(),
9114
9415
  recipient = import_address7.Address.fromRandom(),
9115
- nonce = (0, import_utils41.hexlify)((0, import_crypto12.randomBytes)(32)),
9416
+ nonce = (0, import_utils42.hexlify)((0, import_crypto10.randomBytes)(32)),
9116
9417
  amount = 1e6,
9117
- data = "02",
9418
+ data = "",
9419
+ // Will default to empty data in order to be a spendable message
9118
9420
  da_height = 0
9119
9421
  } = {}) {
9120
9422
  this.sender = sender;
@@ -9125,25 +9427,23 @@ var TestMessage = class {
9125
9427
  this.da_height = da_height;
9126
9428
  }
9127
9429
  toChainMessage(recipient) {
9430
+ const data = /^0x/.test(this.data) ? this.data.replace(/^0x/, "") : this.data;
9128
9431
  return {
9129
9432
  sender: this.sender.toB256(),
9130
9433
  recipient: recipient?.toB256() ?? this.recipient.toB256(),
9131
9434
  nonce: this.nonce,
9132
- amount: (0, import_math23.bn)(this.amount).toNumber(),
9133
- data: this.data,
9435
+ amount: (0, import_math24.bn)(this.amount).toNumber(),
9436
+ data,
9134
9437
  da_height: this.da_height
9135
9438
  };
9136
9439
  }
9137
9440
  };
9138
9441
  // Annotate the CommonJS export names for ESM import in node:
9139
9442
  0 && (module.exports = {
9140
- AssetId,
9443
+ TestAssetId,
9141
9444
  TestMessage,
9142
9445
  WalletsConfig,
9143
- generateTestWallet,
9144
9446
  launchNode,
9145
- launchNodeAndGetWallets,
9146
- seedTestWallet,
9147
9447
  setupTestProviderAndWallets
9148
9448
  });
9149
9449
  //# sourceMappingURL=test-utils.js.map