@fuel-ts/account 0.94.3 → 0.94.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account.d.ts.map +1 -1
- package/dist/index.global.js +391 -436
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +345 -195
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +427 -285
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +250 -0
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +3 -0
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +36 -3
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/blob-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/helpers.d.ts +2 -0
- package/dist/providers/transaction-request/helpers.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +4 -2
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts +3 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/utils/extract-tx-error.d.ts.map +1 -1
- package/dist/providers/utils/handle-gql-error-message.d.ts +6 -0
- package/dist/providers/utils/handle-gql-error-message.d.ts.map +1 -0
- package/dist/providers/utils/receipts.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +235 -286
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +300 -162
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +372 -239
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.mjs
CHANGED
@@ -311,20 +311,14 @@ var launchNode = async ({
|
|
311
311
|
const rows = text.split("\n");
|
312
312
|
const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
|
313
313
|
const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
snapshotDir: snapshotDirToUse,
|
323
|
-
pid: child.pid
|
324
|
-
})
|
325
|
-
),
|
326
|
-
500
|
327
|
-
);
|
314
|
+
resolve({
|
315
|
+
cleanup,
|
316
|
+
ip: realIp,
|
317
|
+
port: realPort,
|
318
|
+
url: `http://${realIp}:${realPort}/v1/graphql`,
|
319
|
+
snapshotDir: snapshotDirToUse,
|
320
|
+
pid: child.pid
|
321
|
+
});
|
328
322
|
}
|
329
323
|
if (/error/i.test(text)) {
|
330
324
|
console.log(text);
|
@@ -382,14 +376,15 @@ var addAmountToCoinQuantities = (params) => {
|
|
382
376
|
|
383
377
|
// src/providers/provider.ts
|
384
378
|
import { Address as Address3 } from "@fuel-ts/address";
|
385
|
-
import { ErrorCode as
|
379
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError16 } from "@fuel-ts/errors";
|
386
380
|
import { BN as BN2, bn as bn17 } from "@fuel-ts/math";
|
387
|
-
import { InputType as InputType7, InputMessageCoder, TransactionCoder as TransactionCoder5 } from "@fuel-ts/transactions";
|
388
|
-
import { arrayify as arrayify12, hexlify as
|
381
|
+
import { InputType as InputType7, InputMessageCoder as InputMessageCoder2, TransactionCoder as TransactionCoder5 } from "@fuel-ts/transactions";
|
382
|
+
import { arrayify as arrayify12, hexlify as hexlify15, DateTime as DateTime2, isDefined as isDefined2 } from "@fuel-ts/utils";
|
389
383
|
import { checkFuelCoreVersionCompatibility } from "@fuel-ts/versions";
|
390
384
|
import { equalBytes } from "@noble/curves/abstract/utils";
|
391
385
|
import { GraphQLClient } from "graphql-request";
|
392
|
-
import
|
386
|
+
import gql2 from "graphql-tag";
|
387
|
+
import { clone as clone6 } from "ramda";
|
393
388
|
|
394
389
|
// src/providers/__generated__/operations.ts
|
395
390
|
import gql from "graphql-tag";
|
@@ -722,6 +717,14 @@ var BlockFragmentDoc = gql`
|
|
722
717
|
height
|
723
718
|
header {
|
724
719
|
time
|
720
|
+
daHeight
|
721
|
+
stateTransitionBytecodeVersion
|
722
|
+
transactionsCount
|
723
|
+
transactionsRoot
|
724
|
+
messageOutboxRoot
|
725
|
+
eventInboxRoot
|
726
|
+
prevRoot
|
727
|
+
applicationHash
|
725
728
|
}
|
726
729
|
transactions {
|
727
730
|
id
|
@@ -1329,6 +1332,13 @@ var SubmitAndAwaitDocument = gql`
|
|
1329
1332
|
}
|
1330
1333
|
}
|
1331
1334
|
${TransactionStatusSubscriptionFragmentDoc}`;
|
1335
|
+
var SubmitAndAwaitStatusDocument = gql`
|
1336
|
+
subscription submitAndAwaitStatus($encodedTransaction: HexString!) {
|
1337
|
+
submitAndAwaitStatus(tx: $encodedTransaction) {
|
1338
|
+
...transactionStatusSubscriptionFragment
|
1339
|
+
}
|
1340
|
+
}
|
1341
|
+
${TransactionStatusSubscriptionFragmentDoc}`;
|
1332
1342
|
var StatusChangeDocument = gql`
|
1333
1343
|
subscription statusChange($transactionId: TransactionId!) {
|
1334
1344
|
statusChange(id: $transactionId) {
|
@@ -1425,6 +1435,9 @@ function getSdk(requester) {
|
|
1425
1435
|
submitAndAwait(variables, options) {
|
1426
1436
|
return requester(SubmitAndAwaitDocument, variables, options);
|
1427
1437
|
},
|
1438
|
+
submitAndAwaitStatus(variables, options) {
|
1439
|
+
return requester(SubmitAndAwaitStatusDocument, variables, options);
|
1440
|
+
},
|
1428
1441
|
statusChange(variables, options) {
|
1429
1442
|
return requester(StatusChangeDocument, variables, options);
|
1430
1443
|
}
|
@@ -1451,7 +1464,9 @@ var _FuelGraphqlSubscriber = class {
|
|
1451
1464
|
Accept: "text/event-stream"
|
1452
1465
|
}
|
1453
1466
|
});
|
1454
|
-
|
1467
|
+
const [errorReader, resultReader] = response.body.tee().map((stream) => stream.getReader());
|
1468
|
+
await new _FuelGraphqlSubscriber(errorReader).next();
|
1469
|
+
return new _FuelGraphqlSubscriber(resultReader);
|
1455
1470
|
}
|
1456
1471
|
events = [];
|
1457
1472
|
parsingLeftover = "";
|
@@ -1494,10 +1509,8 @@ var _FuelGraphqlSubscriber = class {
|
|
1494
1509
|
/**
|
1495
1510
|
* Gets called when `break` is called in a `for-await-of` loop.
|
1496
1511
|
*/
|
1497
|
-
|
1498
|
-
|
1499
|
-
this.stream.releaseLock();
|
1500
|
-
return { done: true, value: void 0 };
|
1512
|
+
return() {
|
1513
|
+
return Promise.resolve({ done: true, value: void 0 });
|
1501
1514
|
}
|
1502
1515
|
[Symbol.asyncIterator]() {
|
1503
1516
|
return this;
|
@@ -1714,7 +1727,10 @@ import {
|
|
1714
1727
|
OutputType as OutputType2,
|
1715
1728
|
TransactionType
|
1716
1729
|
} from "@fuel-ts/transactions";
|
1717
|
-
import { concat as concat2, hexlify as
|
1730
|
+
import { concat as concat2, hexlify as hexlify10, isDefined } from "@fuel-ts/utils";
|
1731
|
+
|
1732
|
+
// src/providers/message.ts
|
1733
|
+
var isMessageCoin = (message) => !("data" in message);
|
1718
1734
|
|
1719
1735
|
// src/providers/resource.ts
|
1720
1736
|
var isCoin = (resource) => "id" in resource;
|
@@ -1723,14 +1739,9 @@ var isCoin = (resource) => "id" in resource;
|
|
1723
1739
|
import { ZeroBytes32 as ZeroBytes323 } from "@fuel-ts/address/configs";
|
1724
1740
|
import { ErrorCode as ErrorCode5, FuelError as FuelError6 } from "@fuel-ts/errors";
|
1725
1741
|
import { bn as bn4 } from "@fuel-ts/math";
|
1726
|
-
import {
|
1727
|
-
ReceiptBurnCoder,
|
1728
|
-
ReceiptMessageOutCoder,
|
1729
|
-
ReceiptMintCoder,
|
1730
|
-
ReceiptType
|
1731
|
-
} from "@fuel-ts/transactions";
|
1742
|
+
import { getMintedAssetId, InputMessageCoder, ReceiptType } from "@fuel-ts/transactions";
|
1732
1743
|
import { FAILED_TRANSFER_TO_ADDRESS_SIGNAL } from "@fuel-ts/transactions/configs";
|
1733
|
-
import { arrayify as arrayify3 } from "@fuel-ts/utils";
|
1744
|
+
import { arrayify as arrayify3, hexlify as hexlify7 } from "@fuel-ts/utils";
|
1734
1745
|
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === ReceiptType.Revert && receipt.val.toString("hex") === FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1735
1746
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1736
1747
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
@@ -1876,12 +1887,12 @@ function assembleReceiptByType(receipt) {
|
|
1876
1887
|
const amount = bn4(receipt.amount);
|
1877
1888
|
const data = receipt.data ? arrayify3(receipt.data) : Uint8Array.from([]);
|
1878
1889
|
const digest = hexOrZero(receipt.digest);
|
1879
|
-
const messageId =
|
1890
|
+
const messageId = InputMessageCoder.getMessageId({
|
1880
1891
|
sender,
|
1881
1892
|
recipient,
|
1882
1893
|
nonce,
|
1883
1894
|
amount,
|
1884
|
-
data
|
1895
|
+
data: hexlify7(data)
|
1885
1896
|
});
|
1886
1897
|
const receiptMessageOut = {
|
1887
1898
|
type: ReceiptType.MessageOut,
|
@@ -1898,7 +1909,7 @@ function assembleReceiptByType(receipt) {
|
|
1898
1909
|
case "MINT" /* Mint */: {
|
1899
1910
|
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1900
1911
|
const subId = hexOrZero(receipt.subId);
|
1901
|
-
const assetId =
|
1912
|
+
const assetId = getMintedAssetId(contractId, subId);
|
1902
1913
|
const mintReceipt = {
|
1903
1914
|
type: ReceiptType.Mint,
|
1904
1915
|
subId,
|
@@ -1913,7 +1924,7 @@ function assembleReceiptByType(receipt) {
|
|
1913
1924
|
case "BURN" /* Burn */: {
|
1914
1925
|
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1915
1926
|
const subId = hexOrZero(receipt.subId);
|
1916
|
-
const assetId =
|
1927
|
+
const assetId = getMintedAssetId(contractId, subId);
|
1917
1928
|
const burnReceipt = {
|
1918
1929
|
type: ReceiptType.Burn,
|
1919
1930
|
subId,
|
@@ -2039,13 +2050,13 @@ var calculateGasFee = (params) => {
|
|
2039
2050
|
};
|
2040
2051
|
|
2041
2052
|
// src/providers/utils/json.ts
|
2042
|
-
import { hexlify as
|
2053
|
+
import { hexlify as hexlify8 } from "@fuel-ts/utils";
|
2043
2054
|
import { clone } from "ramda";
|
2044
2055
|
function normalize(object) {
|
2045
2056
|
Object.keys(object).forEach((key) => {
|
2046
2057
|
switch (object[key]?.constructor.name) {
|
2047
2058
|
case "Uint8Array":
|
2048
|
-
object[key] =
|
2059
|
+
object[key] = hexlify8(object[key]);
|
2049
2060
|
break;
|
2050
2061
|
case "Array":
|
2051
2062
|
object[key] = normalize(object[key]);
|
@@ -2103,20 +2114,22 @@ var assembleRevertError = (receipts, logs, metadata) => {
|
|
2103
2114
|
let reason = "";
|
2104
2115
|
if (revertReceipt) {
|
2105
2116
|
const reasonHex = bn6(revertReceipt.val).toHex();
|
2117
|
+
const lastLog = logs[logs.length - 1];
|
2118
|
+
const lastButOneLog = logs[logs.length - 2];
|
2106
2119
|
switch (reasonHex) {
|
2107
2120
|
case FAILED_REQUIRE_SIGNAL: {
|
2108
2121
|
reason = "require";
|
2109
|
-
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(
|
2122
|
+
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(lastLog) : "an error."}.`;
|
2110
2123
|
break;
|
2111
2124
|
}
|
2112
2125
|
case FAILED_ASSERT_EQ_SIGNAL: {
|
2113
|
-
const sufix = logs.length >= 2 ? ` comparing ${stringify(
|
2126
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(lastLog)} and ${stringify(lastButOneLog)}.` : ".";
|
2114
2127
|
reason = "assert_eq";
|
2115
2128
|
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
2116
2129
|
break;
|
2117
2130
|
}
|
2118
2131
|
case FAILED_ASSERT_NE_SIGNAL: {
|
2119
|
-
const sufix = logs.length >= 2 ? ` comparing ${stringify(
|
2132
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(lastButOneLog)} and ${stringify(lastLog)}.` : ".";
|
2120
2133
|
reason = "assert_ne";
|
2121
2134
|
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
2122
2135
|
break;
|
@@ -2177,7 +2190,9 @@ import { bn as bn7 } from "@fuel-ts/math";
|
|
2177
2190
|
import { InputType as InputType2 } from "@fuel-ts/transactions";
|
2178
2191
|
var isRequestInputCoin = (input) => input.type === InputType2.Coin;
|
2179
2192
|
var isRequestInputMessage = (input) => input.type === InputType2.Message;
|
2180
|
-
var
|
2193
|
+
var isRequestInputMessageWithoutData = (input) => input.type === InputType2.Message && bn7(input.data).isZero();
|
2194
|
+
var isRequestInputCoinOrMessage = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
2195
|
+
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessageWithoutData(input);
|
2181
2196
|
var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
|
2182
2197
|
var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
|
2183
2198
|
var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
|
@@ -2205,11 +2220,11 @@ var cacheRequestInputsResourcesFromOwner = (inputs, owner) => inputs.reduce(
|
|
2205
2220
|
);
|
2206
2221
|
|
2207
2222
|
// src/providers/transaction-request/witness.ts
|
2208
|
-
import { arrayify as arrayify5, hexlify as
|
2223
|
+
import { arrayify as arrayify5, hexlify as hexlify9 } from "@fuel-ts/utils";
|
2209
2224
|
var witnessify = (value) => {
|
2210
2225
|
const data = arrayify5(value);
|
2211
2226
|
return {
|
2212
|
-
data:
|
2227
|
+
data: hexlify9(data),
|
2213
2228
|
dataLength: data.length
|
2214
2229
|
};
|
2215
2230
|
};
|
@@ -2426,9 +2441,9 @@ var BaseTransactionRequest = class {
|
|
2426
2441
|
const found = this.inputs.find((input) => {
|
2427
2442
|
switch (input.type) {
|
2428
2443
|
case InputType3.Coin:
|
2429
|
-
return
|
2444
|
+
return hexlify10(input.owner) === ownerAddress.toB256();
|
2430
2445
|
case InputType3.Message:
|
2431
|
-
return
|
2446
|
+
return hexlify10(input.recipient) === ownerAddress.toB256();
|
2432
2447
|
default:
|
2433
2448
|
return false;
|
2434
2449
|
}
|
@@ -2473,7 +2488,7 @@ var BaseTransactionRequest = class {
|
|
2473
2488
|
* @param message - Message resource.
|
2474
2489
|
*/
|
2475
2490
|
addMessageInput(message) {
|
2476
|
-
const { recipient, sender, amount, predicate, nonce,
|
2491
|
+
const { recipient, sender, amount, predicate, nonce, predicateData } = message;
|
2477
2492
|
let witnessIndex;
|
2478
2493
|
if (message.predicate) {
|
2479
2494
|
witnessIndex = 0;
|
@@ -2488,13 +2503,16 @@ var BaseTransactionRequest = class {
|
|
2488
2503
|
type: InputType3.Message,
|
2489
2504
|
sender: sender.toB256(),
|
2490
2505
|
recipient: recipient.toB256(),
|
2506
|
+
data: isMessageCoin(message) ? "0x" : message.data,
|
2491
2507
|
amount,
|
2492
2508
|
witnessIndex,
|
2493
2509
|
predicate,
|
2494
2510
|
predicateData
|
2495
2511
|
};
|
2496
2512
|
this.pushInput(input);
|
2497
|
-
|
2513
|
+
if (isMessageCoin(message)) {
|
2514
|
+
this.addChangeOutput(recipient, message.assetId);
|
2515
|
+
}
|
2498
2516
|
}
|
2499
2517
|
/**
|
2500
2518
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2563,7 +2581,7 @@ var BaseTransactionRequest = class {
|
|
2563
2581
|
*/
|
2564
2582
|
addChangeOutput(to, assetId) {
|
2565
2583
|
const changeOutput = this.getChangeOutputs().find(
|
2566
|
-
(output) =>
|
2584
|
+
(output) => hexlify10(output.assetId) === assetId
|
2567
2585
|
);
|
2568
2586
|
if (!changeOutput) {
|
2569
2587
|
this.pushOutput({
|
@@ -2626,6 +2644,8 @@ var BaseTransactionRequest = class {
|
|
2626
2644
|
*
|
2627
2645
|
* @param quantities - CoinQuantity Array.
|
2628
2646
|
* @param baseAssetId - The base asset to fund the transaction.
|
2647
|
+
* @deprecated - This method is deprecated and will be removed in future versions.
|
2648
|
+
* Please use `Account.generateFakeResources` along with `this.addResources` instead.
|
2629
2649
|
*/
|
2630
2650
|
fundWithFakeUtxos(quantities, baseAssetId, resourcesOwner) {
|
2631
2651
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
@@ -2641,12 +2661,12 @@ var BaseTransactionRequest = class {
|
|
2641
2661
|
usedQuantity = bn8("1000000000000000000");
|
2642
2662
|
}
|
2643
2663
|
if (assetInput && "assetId" in assetInput) {
|
2644
|
-
assetInput.id =
|
2664
|
+
assetInput.id = hexlify10(randomBytes3(UTXO_ID_LEN2));
|
2645
2665
|
assetInput.amount = usedQuantity;
|
2646
2666
|
} else {
|
2647
2667
|
this.addResources([
|
2648
2668
|
{
|
2649
|
-
id:
|
2669
|
+
id: hexlify10(randomBytes3(UTXO_ID_LEN2)),
|
2650
2670
|
amount: usedQuantity,
|
2651
2671
|
assetId,
|
2652
2672
|
owner: resourcesOwner || Address2.fromRandom(),
|
@@ -2694,7 +2714,7 @@ var BaseTransactionRequest = class {
|
|
2694
2714
|
});
|
2695
2715
|
}
|
2696
2716
|
updatePredicateGasUsed(inputs) {
|
2697
|
-
const inputsToExtractGasUsed = inputs.filter(
|
2717
|
+
const inputsToExtractGasUsed = inputs.filter(isRequestInputCoinOrMessage);
|
2698
2718
|
this.inputs.filter(isRequestInputResource).forEach((i) => {
|
2699
2719
|
const owner = getRequestInputResourceOwner(i);
|
2700
2720
|
const correspondingInput = inputsToExtractGasUsed.find(
|
@@ -2710,6 +2730,9 @@ var BaseTransactionRequest = class {
|
|
2710
2730
|
}
|
2711
2731
|
};
|
2712
2732
|
|
2733
|
+
// src/providers/transaction-request/blob-transaction-request.ts
|
2734
|
+
import { clone as clone3 } from "ramda";
|
2735
|
+
|
2713
2736
|
// src/providers/transaction-request/hash-transaction.ts
|
2714
2737
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2715
2738
|
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
@@ -2784,10 +2807,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2784
2807
|
// src/providers/transaction-request/blob-transaction-request.ts
|
2785
2808
|
var BlobTransactionRequest = class extends BaseTransactionRequest {
|
2786
2809
|
static from(obj) {
|
2787
|
-
|
2788
|
-
return obj;
|
2789
|
-
}
|
2790
|
-
return new this(obj);
|
2810
|
+
return new this(clone3(obj));
|
2791
2811
|
}
|
2792
2812
|
/** Type of the transaction */
|
2793
2813
|
type = TransactionType.Blob;
|
@@ -2849,10 +2869,11 @@ var BlobTransactionRequest = class extends BaseTransactionRequest {
|
|
2849
2869
|
import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
|
2850
2870
|
import { bn as bn10 } from "@fuel-ts/math";
|
2851
2871
|
import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
|
2852
|
-
import { arrayify as arrayify7, hexlify as
|
2872
|
+
import { arrayify as arrayify7, hexlify as hexlify12 } from "@fuel-ts/utils";
|
2873
|
+
import { clone as clone4 } from "ramda";
|
2853
2874
|
|
2854
2875
|
// src/providers/transaction-request/storage-slot.ts
|
2855
|
-
import { arrayify as arrayify6, hexlify as
|
2876
|
+
import { arrayify as arrayify6, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2856
2877
|
var getStorageValue = (value) => {
|
2857
2878
|
const v = new Uint8Array(32);
|
2858
2879
|
v.set(arrayify6(value));
|
@@ -2869,18 +2890,15 @@ var storageSlotify = (storageSlot) => {
|
|
2869
2890
|
value = storageSlot.value;
|
2870
2891
|
}
|
2871
2892
|
return {
|
2872
|
-
key:
|
2873
|
-
value:
|
2893
|
+
key: hexlify11(key),
|
2894
|
+
value: hexlify11(getStorageValue(value))
|
2874
2895
|
};
|
2875
2896
|
};
|
2876
2897
|
|
2877
2898
|
// src/providers/transaction-request/create-transaction-request.ts
|
2878
2899
|
var CreateTransactionRequest = class extends BaseTransactionRequest {
|
2879
2900
|
static from(obj) {
|
2880
|
-
|
2881
|
-
return obj;
|
2882
|
-
}
|
2883
|
-
return new this(obj);
|
2901
|
+
return new this(clone4(obj));
|
2884
2902
|
}
|
2885
2903
|
/** Type of the transaction */
|
2886
2904
|
type = TransactionType3.Create;
|
@@ -2898,7 +2916,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2898
2916
|
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2899
2917
|
super(rest);
|
2900
2918
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2901
|
-
this.salt =
|
2919
|
+
this.salt = hexlify12(salt ?? ZeroBytes326);
|
2902
2920
|
this.storageSlots = [...storageSlots ?? []];
|
2903
2921
|
}
|
2904
2922
|
/**
|
@@ -2915,7 +2933,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2915
2933
|
...baseTransaction,
|
2916
2934
|
bytecodeWitnessIndex,
|
2917
2935
|
storageSlotsCount: bn10(storageSlots.length),
|
2918
|
-
salt: this.salt ?
|
2936
|
+
salt: this.salt ? hexlify12(this.salt) : ZeroBytes326,
|
2919
2937
|
storageSlots
|
2920
2938
|
};
|
2921
2939
|
}
|
@@ -2968,7 +2986,8 @@ import { addressify as addressify2 } from "@fuel-ts/address";
|
|
2968
2986
|
import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
2969
2987
|
import { bn as bn11 } from "@fuel-ts/math";
|
2970
2988
|
import { InputType as InputType5, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2971
|
-
import { arrayify as arrayify9, hexlify as
|
2989
|
+
import { arrayify as arrayify9, hexlify as hexlify13 } from "@fuel-ts/utils";
|
2990
|
+
import { clone as clone5 } from "ramda";
|
2972
2991
|
|
2973
2992
|
// src/providers/transaction-request/scripts.ts
|
2974
2993
|
import { arrayify as arrayify8 } from "@fuel-ts/utils";
|
@@ -2999,10 +3018,7 @@ var withdrawScript = {
|
|
2999
3018
|
// src/providers/transaction-request/script-transaction-request.ts
|
3000
3019
|
var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
3001
3020
|
static from(obj) {
|
3002
|
-
|
3003
|
-
return obj;
|
3004
|
-
}
|
3005
|
-
return new this(obj);
|
3021
|
+
return new this(clone5(obj));
|
3006
3022
|
}
|
3007
3023
|
/** Type of the transaction */
|
3008
3024
|
type = TransactionType4.Script;
|
@@ -3040,8 +3056,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3040
3056
|
scriptLength: bn11(script.length),
|
3041
3057
|
scriptDataLength: bn11(scriptData.length),
|
3042
3058
|
receiptsRoot: ZeroBytes327,
|
3043
|
-
script:
|
3044
|
-
scriptData:
|
3059
|
+
script: hexlify13(script),
|
3060
|
+
scriptData: hexlify13(scriptData)
|
3045
3061
|
};
|
3046
3062
|
}
|
3047
3063
|
/**
|
@@ -3216,7 +3232,7 @@ import { arrayify as arrayify11, assertUnreachable } from "@fuel-ts/utils";
|
|
3216
3232
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
3217
3233
|
import { bn as bn15 } from "@fuel-ts/math";
|
3218
3234
|
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
3219
|
-
import { DateTime, hexlify as
|
3235
|
+
import { DateTime, hexlify as hexlify14 } from "@fuel-ts/utils";
|
3220
3236
|
|
3221
3237
|
// src/providers/transaction-summary/calculate-tx-fee-for-summary.ts
|
3222
3238
|
import { bn as bn12 } from "@fuel-ts/math";
|
@@ -3929,7 +3945,7 @@ function assembleTransactionSummary(params) {
|
|
3929
3945
|
baseAssetId
|
3930
3946
|
} = params;
|
3931
3947
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3932
|
-
const rawPayload =
|
3948
|
+
const rawPayload = hexlify14(transactionBytes);
|
3933
3949
|
const operations = getOperations({
|
3934
3950
|
transactionType: transaction.type,
|
3935
3951
|
inputs: transaction.inputs || [],
|
@@ -4038,29 +4054,30 @@ function mapGqlOutputsToTxOutputs(outputs) {
|
|
4038
4054
|
});
|
4039
4055
|
}
|
4040
4056
|
var TransactionResponse = class {
|
4041
|
-
/** Transaction ID */
|
4042
|
-
id;
|
4043
|
-
/** Current provider */
|
4044
|
-
provider;
|
4045
|
-
/** Gas used on the transaction */
|
4046
|
-
gasUsed = bn16(0);
|
4047
|
-
/** The graphql Transaction with receipts object. */
|
4048
|
-
gqlTransaction;
|
4049
|
-
request;
|
4050
|
-
status;
|
4051
|
-
abis;
|
4052
4057
|
/**
|
4053
4058
|
* Constructor for `TransactionResponse`.
|
4054
4059
|
*
|
4055
4060
|
* @param tx - The transaction ID or TransactionRequest.
|
4056
4061
|
* @param provider - The provider.
|
4057
4062
|
*/
|
4058
|
-
constructor(tx, provider, abis) {
|
4063
|
+
constructor(tx, provider, abis, submitTxSubscription) {
|
4064
|
+
this.submitTxSubscription = submitTxSubscription;
|
4059
4065
|
this.id = typeof tx === "string" ? tx : tx.getTransactionId(provider.getChainId());
|
4060
4066
|
this.provider = provider;
|
4061
4067
|
this.abis = abis;
|
4062
4068
|
this.request = typeof tx === "string" ? void 0 : tx;
|
4063
4069
|
}
|
4070
|
+
/** Transaction ID */
|
4071
|
+
id;
|
4072
|
+
/** Current provider */
|
4073
|
+
provider;
|
4074
|
+
/** Gas used on the transaction */
|
4075
|
+
gasUsed = bn16(0);
|
4076
|
+
/** The graphql Transaction with receipts object. */
|
4077
|
+
gqlTransaction;
|
4078
|
+
request;
|
4079
|
+
status;
|
4080
|
+
abis;
|
4064
4081
|
/**
|
4065
4082
|
* Async constructor for `TransactionResponse`. This method can be used to create
|
4066
4083
|
* an instance of `TransactionResponse` and wait for the transaction to be fetched
|
@@ -4193,10 +4210,11 @@ var TransactionResponse = class {
|
|
4193
4210
|
if (status && status !== "SubmittedStatus") {
|
4194
4211
|
return;
|
4195
4212
|
}
|
4196
|
-
const subscription = await this.provider.operations.statusChange({
|
4213
|
+
const subscription = this.submitTxSubscription ?? await this.provider.operations.statusChange({
|
4197
4214
|
transactionId: this.id
|
4198
4215
|
});
|
4199
|
-
for await (const
|
4216
|
+
for await (const sub of subscription) {
|
4217
|
+
const statusChange = "statusChange" in sub ? sub.statusChange : sub.submitAndAwaitStatus;
|
4200
4218
|
this.status = statusChange;
|
4201
4219
|
if (statusChange.type === "SqueezedOutStatus") {
|
4202
4220
|
this.unsetResourceCache();
|
@@ -4308,6 +4326,22 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
4308
4326
|
};
|
4309
4327
|
}
|
4310
4328
|
|
4329
|
+
// src/providers/utils/handle-gql-error-message.ts
|
4330
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError15 } from "@fuel-ts/errors";
|
4331
|
+
var handleGqlErrorMessage = (errorMessage, rawError) => {
|
4332
|
+
switch (errorMessage) {
|
4333
|
+
case "not enough coins to fit the target" /* NOT_ENOUGH_COINS */:
|
4334
|
+
throw new FuelError15(
|
4335
|
+
ErrorCode13.NOT_ENOUGH_FUNDS,
|
4336
|
+
`The account(s) sending the transaction don't have enough funds to cover the transaction.`,
|
4337
|
+
{},
|
4338
|
+
rawError
|
4339
|
+
);
|
4340
|
+
default:
|
4341
|
+
throw new FuelError15(ErrorCode13.INVALID_REQUEST, errorMessage);
|
4342
|
+
}
|
4343
|
+
};
|
4344
|
+
|
4311
4345
|
// src/providers/provider.ts
|
4312
4346
|
var MAX_RETRIES = 10;
|
4313
4347
|
var RESOURCES_PAGE_SIZE_LIMIT = 512;
|
@@ -4434,6 +4468,17 @@ var _Provider = class {
|
|
4434
4468
|
return options.fetch ? options.fetch(url, fullRequest, options) : fetch(url, fullRequest);
|
4435
4469
|
}, retryOptions);
|
4436
4470
|
}
|
4471
|
+
static extractBasicAuth(url) {
|
4472
|
+
const parsedUrl = new URL(url);
|
4473
|
+
const username = parsedUrl.username;
|
4474
|
+
const password = parsedUrl.password;
|
4475
|
+
const urlNoBasicAuth = `${parsedUrl.origin}${parsedUrl.pathname}`;
|
4476
|
+
if (!(username && password)) {
|
4477
|
+
return { url, auth: void 0 };
|
4478
|
+
}
|
4479
|
+
const auth = `Basic ${btoa(`${username}:${password}`)}`;
|
4480
|
+
return { url: urlNoBasicAuth, auth };
|
4481
|
+
}
|
4437
4482
|
/**
|
4438
4483
|
* Creates a new instance of the Provider class. This is the recommended way to initialize a Provider.
|
4439
4484
|
*
|
@@ -4443,7 +4488,17 @@ var _Provider = class {
|
|
4443
4488
|
* @returns A promise that resolves to a Provider instance.
|
4444
4489
|
*/
|
4445
4490
|
static async create(url, options = {}) {
|
4446
|
-
const
|
4491
|
+
const { url: urlToUse, auth } = this.extractBasicAuth(url);
|
4492
|
+
const provider = new _Provider(urlToUse, {
|
4493
|
+
...options,
|
4494
|
+
requestMiddleware: async (request) => {
|
4495
|
+
if (auth && request) {
|
4496
|
+
request.headers ??= {};
|
4497
|
+
request.headers.Authorization = auth;
|
4498
|
+
}
|
4499
|
+
return options.requestMiddleware?.(request) ?? request;
|
4500
|
+
}
|
4501
|
+
});
|
4447
4502
|
await provider.fetchChainAndNodeInfo();
|
4448
4503
|
return provider;
|
4449
4504
|
}
|
@@ -4455,8 +4510,8 @@ var _Provider = class {
|
|
4455
4510
|
getChain() {
|
4456
4511
|
const chain = _Provider.chainInfoCache[this.url];
|
4457
4512
|
if (!chain) {
|
4458
|
-
throw new
|
4459
|
-
|
4513
|
+
throw new FuelError16(
|
4514
|
+
ErrorCode14.CHAIN_INFO_CACHE_EMPTY,
|
4460
4515
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4461
4516
|
);
|
4462
4517
|
}
|
@@ -4470,8 +4525,8 @@ var _Provider = class {
|
|
4470
4525
|
getNode() {
|
4471
4526
|
const node = _Provider.nodeInfoCache[this.url];
|
4472
4527
|
if (!node) {
|
4473
|
-
throw new
|
4474
|
-
|
4528
|
+
throw new FuelError16(
|
4529
|
+
ErrorCode14.NODE_INFO_CACHE_EMPTY,
|
4475
4530
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4476
4531
|
);
|
4477
4532
|
}
|
@@ -4549,10 +4604,9 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4549
4604
|
if ("response" in response) {
|
4550
4605
|
const graphQlResponse = response.response;
|
4551
4606
|
if (Array.isArray(graphQlResponse?.errors)) {
|
4552
|
-
|
4553
|
-
|
4554
|
-
|
4555
|
-
);
|
4607
|
+
for (const error of graphQlResponse.errors) {
|
4608
|
+
handleGqlErrorMessage(error.message, error);
|
4609
|
+
}
|
4556
4610
|
}
|
4557
4611
|
}
|
4558
4612
|
}
|
@@ -4570,7 +4624,26 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4570
4624
|
}
|
4571
4625
|
return gqlClient.request(query, vars);
|
4572
4626
|
};
|
4573
|
-
|
4627
|
+
const customOperations = (requester) => ({
|
4628
|
+
getBlobs(variables) {
|
4629
|
+
const queryParams = variables.blobIds.map((_, i) => `$blobId${i}: BlobId!`).join(", ");
|
4630
|
+
const blobParams = variables.blobIds.map((_, i) => `blob${i}: blob(id: $blobId${i}) { id }`).join("\n");
|
4631
|
+
const updatedVariables = variables.blobIds.reduce(
|
4632
|
+
(acc, blobId, i) => {
|
4633
|
+
acc[`blobId${i}`] = blobId;
|
4634
|
+
return acc;
|
4635
|
+
},
|
4636
|
+
{}
|
4637
|
+
);
|
4638
|
+
const document = gql2`
|
4639
|
+
query getBlobs(${queryParams}) {
|
4640
|
+
${blobParams}
|
4641
|
+
}
|
4642
|
+
`;
|
4643
|
+
return requester(document, updatedVariables);
|
4644
|
+
}
|
4645
|
+
});
|
4646
|
+
return { ...getSdk(executeQuery), ...customOperations(executeQuery) };
|
4574
4647
|
}
|
4575
4648
|
/**
|
4576
4649
|
* Returns the version of the connected node.
|
@@ -4645,14 +4718,14 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4645
4718
|
validateTransaction(tx, consensusParameters) {
|
4646
4719
|
const { maxOutputs, maxInputs } = consensusParameters.txParameters;
|
4647
4720
|
if (bn17(tx.inputs.length).gt(maxInputs)) {
|
4648
|
-
throw new
|
4649
|
-
|
4721
|
+
throw new FuelError16(
|
4722
|
+
ErrorCode14.MAX_INPUTS_EXCEEDED,
|
4650
4723
|
"The transaction exceeds the maximum allowed number of inputs."
|
4651
4724
|
);
|
4652
4725
|
}
|
4653
4726
|
if (bn17(tx.outputs.length).gt(maxOutputs)) {
|
4654
|
-
throw new
|
4655
|
-
|
4727
|
+
throw new FuelError16(
|
4728
|
+
ErrorCode14.MAX_OUTPUTS_EXCEEDED,
|
4656
4729
|
"The transaction exceeds the maximum allowed number of outputs."
|
4657
4730
|
);
|
4658
4731
|
}
|
@@ -4674,16 +4747,14 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4674
4747
|
}
|
4675
4748
|
const { consensusParameters } = this.getChain();
|
4676
4749
|
this.validateTransaction(transactionRequest, consensusParameters);
|
4677
|
-
const encodedTransaction =
|
4750
|
+
const encodedTransaction = hexlify15(transactionRequest.toTransactionBytes());
|
4678
4751
|
let abis;
|
4679
4752
|
if (isTransactionTypeScript(transactionRequest)) {
|
4680
4753
|
abis = transactionRequest.abis;
|
4681
4754
|
}
|
4682
|
-
const {
|
4683
|
-
|
4684
|
-
|
4685
|
-
__privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs, transactionId);
|
4686
|
-
return new TransactionResponse(transactionRequest, this, abis);
|
4755
|
+
const subscription = await this.operations.submitAndAwaitStatus({ encodedTransaction });
|
4756
|
+
__privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs, transactionRequest.getTransactionId(this.getChainId()));
|
4757
|
+
return new TransactionResponse(transactionRequest, this, abis, subscription);
|
4687
4758
|
}
|
4688
4759
|
/**
|
4689
4760
|
* Executes a transaction without actually submitting it to the chain.
|
@@ -4700,7 +4771,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4700
4771
|
if (estimateTxDependencies) {
|
4701
4772
|
return this.estimateTxDependencies(transactionRequest);
|
4702
4773
|
}
|
4703
|
-
const encodedTransaction =
|
4774
|
+
const encodedTransaction = hexlify15(transactionRequest.toTransactionBytes());
|
4704
4775
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4705
4776
|
encodedTransactions: encodedTransaction,
|
4706
4777
|
utxoValidation: utxoValidation || false
|
@@ -4726,7 +4797,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4726
4797
|
if (!shouldEstimatePredicates) {
|
4727
4798
|
return transactionRequest;
|
4728
4799
|
}
|
4729
|
-
const encodedTransaction =
|
4800
|
+
const encodedTransaction = hexlify15(transactionRequest.toTransactionBytes());
|
4730
4801
|
const response = await this.operations.estimatePredicates({
|
4731
4802
|
encodedTransaction
|
4732
4803
|
});
|
@@ -4767,7 +4838,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4767
4838
|
const {
|
4768
4839
|
dryRun: [{ receipts: rawReceipts, status }]
|
4769
4840
|
} = await this.operations.dryRun({
|
4770
|
-
encodedTransactions: [
|
4841
|
+
encodedTransactions: [hexlify15(transactionRequest.toTransactionBytes())],
|
4771
4842
|
utxoValidation: false
|
4772
4843
|
});
|
4773
4844
|
receipts = rawReceipts.map(processGqlReceipt);
|
@@ -4813,11 +4884,11 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4813
4884
|
missingContractIds: [],
|
4814
4885
|
dryRunStatus: void 0
|
4815
4886
|
}));
|
4816
|
-
const allRequests =
|
4887
|
+
const allRequests = clone6(transactionRequests);
|
4817
4888
|
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4818
4889
|
allRequests.forEach((req, index) => {
|
4819
4890
|
if (isTransactionTypeScript(req)) {
|
4820
|
-
serializedTransactionsMap.set(index,
|
4891
|
+
serializedTransactionsMap.set(index, hexlify15(req.toTransactionBytes()));
|
4821
4892
|
}
|
4822
4893
|
});
|
4823
4894
|
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
@@ -4853,7 +4924,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4853
4924
|
transactionRequest: request
|
4854
4925
|
});
|
4855
4926
|
request.maxFee = maxFee;
|
4856
|
-
serializedTransactionsMap.set(requestIdx,
|
4927
|
+
serializedTransactionsMap.set(requestIdx, hexlify15(request.toTransactionBytes()));
|
4857
4928
|
nextRoundTransactions.push(requestIdx);
|
4858
4929
|
}
|
4859
4930
|
}
|
@@ -4874,7 +4945,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4874
4945
|
if (estimateTxDependencies) {
|
4875
4946
|
return this.estimateMultipleTxDependencies(transactionRequests);
|
4876
4947
|
}
|
4877
|
-
const encodedTransactions = transactionRequests.map((tx) =>
|
4948
|
+
const encodedTransactions = transactionRequests.map((tx) => hexlify15(tx.toTransactionBytes()));
|
4878
4949
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4879
4950
|
encodedTransactions,
|
4880
4951
|
utxoValidation: utxoValidation || false
|
@@ -4948,7 +5019,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4948
5019
|
if (estimateTxDependencies) {
|
4949
5020
|
return this.estimateTxDependencies(transactionRequest);
|
4950
5021
|
}
|
4951
|
-
const encodedTransactions = [
|
5022
|
+
const encodedTransactions = [hexlify15(transactionRequest.toTransactionBytes())];
|
4952
5023
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4953
5024
|
encodedTransactions,
|
4954
5025
|
utxoValidation: true
|
@@ -4973,13 +5044,13 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4973
5044
|
* @returns A promise that resolves to the transaction cost object.
|
4974
5045
|
*/
|
4975
5046
|
async getTransactionCost(transactionRequestLike, { signatureCallback } = {}) {
|
4976
|
-
const txRequestClone =
|
5047
|
+
const txRequestClone = clone6(transactionRequestify(transactionRequestLike));
|
4977
5048
|
const updateMaxFee = txRequestClone.maxFee.eq(0);
|
4978
5049
|
const isScriptTransaction = isTransactionTypeScript(txRequestClone);
|
4979
5050
|
if (isScriptTransaction) {
|
4980
5051
|
txRequestClone.gasLimit = bn17(0);
|
4981
5052
|
}
|
4982
|
-
const signedRequest =
|
5053
|
+
const signedRequest = clone6(txRequestClone);
|
4983
5054
|
let addedSignatures = 0;
|
4984
5055
|
if (signatureCallback && isTransactionTypeScript(signedRequest)) {
|
4985
5056
|
const lengthBefore = signedRequest.witnesses.length;
|
@@ -5047,7 +5118,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5047
5118
|
paginationLimit: RESOURCES_PAGE_SIZE_LIMIT,
|
5048
5119
|
inputArgs: paginationArgs
|
5049
5120
|
}),
|
5050
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId &&
|
5121
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && hexlify15(assetId) }
|
5051
5122
|
});
|
5052
5123
|
const coins = edges.map(({ node }) => ({
|
5053
5124
|
id: node.utxoId,
|
@@ -5073,8 +5144,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5073
5144
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
5074
5145
|
const ownerAddress = Address3.fromAddressOrString(owner);
|
5075
5146
|
const excludeInput = {
|
5076
|
-
messages: excludedIds?.messages?.map((nonce) =>
|
5077
|
-
utxos: excludedIds?.utxos?.map((id) =>
|
5147
|
+
messages: excludedIds?.messages?.map((nonce) => hexlify15(nonce)) || [],
|
5148
|
+
utxos: excludedIds?.utxos?.map((id) => hexlify15(id)) || []
|
5078
5149
|
};
|
5079
5150
|
if (this.cache) {
|
5080
5151
|
const cached = this.cache.getActiveData();
|
@@ -5084,7 +5155,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5084
5155
|
const coinsQuery = {
|
5085
5156
|
owner: ownerAddress.toB256(),
|
5086
5157
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
5087
|
-
assetId:
|
5158
|
+
assetId: hexlify15(assetId),
|
5088
5159
|
amount: amount.toString(10),
|
5089
5160
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
5090
5161
|
})),
|
@@ -5117,6 +5188,21 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5117
5188
|
}).filter((v) => !!v);
|
5118
5189
|
return coins;
|
5119
5190
|
}
|
5191
|
+
/**
|
5192
|
+
* Returns an array of blobIds that exist on chain, for a given array of blobIds.
|
5193
|
+
*
|
5194
|
+
* @param blobIds - blobIds to check.
|
5195
|
+
* @returns - A promise that resolves to an array of blobIds that exist on chain.
|
5196
|
+
*/
|
5197
|
+
async getBlobs(blobIds) {
|
5198
|
+
const res = await this.operations.getBlobs({ blobIds });
|
5199
|
+
const blobs = [];
|
5200
|
+
Object.keys(res).forEach((key) => {
|
5201
|
+
const val = res[key];
|
5202
|
+
blobs.push(val?.id ?? null);
|
5203
|
+
});
|
5204
|
+
return blobs.filter((v) => v);
|
5205
|
+
}
|
5120
5206
|
/**
|
5121
5207
|
* Returns block matching the given ID or height.
|
5122
5208
|
*
|
@@ -5138,11 +5224,22 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5138
5224
|
if (!block) {
|
5139
5225
|
return null;
|
5140
5226
|
}
|
5227
|
+
const { header, height, id, transactions } = block;
|
5141
5228
|
return {
|
5142
|
-
id
|
5143
|
-
height: bn17(
|
5144
|
-
time:
|
5145
|
-
|
5229
|
+
id,
|
5230
|
+
height: bn17(height),
|
5231
|
+
time: header.time,
|
5232
|
+
header: {
|
5233
|
+
applicationHash: header.applicationHash,
|
5234
|
+
daHeight: bn17(header.daHeight),
|
5235
|
+
eventInboxRoot: header.eventInboxRoot,
|
5236
|
+
messageOutboxRoot: header.messageOutboxRoot,
|
5237
|
+
prevRoot: header.prevRoot,
|
5238
|
+
stateTransitionBytecodeVersion: header.stateTransitionBytecodeVersion,
|
5239
|
+
transactionsCount: header.transactionsCount,
|
5240
|
+
transactionsRoot: header.transactionsRoot
|
5241
|
+
},
|
5242
|
+
transactionIds: transactions.map((tx) => tx.id)
|
5146
5243
|
};
|
5147
5244
|
}
|
5148
5245
|
/**
|
@@ -5164,6 +5261,16 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5164
5261
|
id: block.id,
|
5165
5262
|
height: bn17(block.height),
|
5166
5263
|
time: block.header.time,
|
5264
|
+
header: {
|
5265
|
+
applicationHash: block.header.applicationHash,
|
5266
|
+
daHeight: bn17(block.header.daHeight),
|
5267
|
+
eventInboxRoot: block.header.eventInboxRoot,
|
5268
|
+
messageOutboxRoot: block.header.messageOutboxRoot,
|
5269
|
+
prevRoot: block.header.prevRoot,
|
5270
|
+
stateTransitionBytecodeVersion: block.header.stateTransitionBytecodeVersion,
|
5271
|
+
transactionsCount: block.header.transactionsCount,
|
5272
|
+
transactionsRoot: block.header.transactionsRoot
|
5273
|
+
},
|
5167
5274
|
transactionIds: block.transactions.map((tx) => tx.id)
|
5168
5275
|
}));
|
5169
5276
|
return { blocks, pageInfo };
|
@@ -5191,6 +5298,16 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5191
5298
|
id: block.id,
|
5192
5299
|
height: bn17(block.height, 10),
|
5193
5300
|
time: block.header.time,
|
5301
|
+
header: {
|
5302
|
+
applicationHash: block.header.applicationHash,
|
5303
|
+
daHeight: bn17(block.header.daHeight),
|
5304
|
+
eventInboxRoot: block.header.eventInboxRoot,
|
5305
|
+
messageOutboxRoot: block.header.messageOutboxRoot,
|
5306
|
+
prevRoot: block.header.prevRoot,
|
5307
|
+
stateTransitionBytecodeVersion: block.header.stateTransitionBytecodeVersion,
|
5308
|
+
transactionsCount: block.header.transactionsCount,
|
5309
|
+
transactionsRoot: block.header.transactionsRoot
|
5310
|
+
},
|
5194
5311
|
transactionIds: block.transactions.map((tx) => tx.id),
|
5195
5312
|
transactions: block.transactions.map(
|
5196
5313
|
(tx) => new TransactionCoder5().decode(arrayify12(tx.rawPayload), 0)?.[0]
|
@@ -5214,7 +5331,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5214
5331
|
0
|
5215
5332
|
)?.[0];
|
5216
5333
|
} catch (error) {
|
5217
|
-
if (error instanceof
|
5334
|
+
if (error instanceof FuelError16 && error.code === ErrorCode14.UNSUPPORTED_TRANSACTION_TYPE) {
|
5218
5335
|
console.warn("Unsupported transaction type encountered");
|
5219
5336
|
return null;
|
5220
5337
|
}
|
@@ -5235,7 +5352,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5235
5352
|
try {
|
5236
5353
|
return coder.decode(arrayify12(rawPayload), 0)[0];
|
5237
5354
|
} catch (error) {
|
5238
|
-
if (error instanceof
|
5355
|
+
if (error instanceof FuelError16 && error.code === ErrorCode14.UNSUPPORTED_TRANSACTION_TYPE) {
|
5239
5356
|
console.warn("Unsupported transaction type encountered");
|
5240
5357
|
return null;
|
5241
5358
|
}
|
@@ -5267,7 +5384,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5267
5384
|
async getContractBalance(contractId, assetId) {
|
5268
5385
|
const { contractBalance } = await this.operations.getContractBalance({
|
5269
5386
|
contract: Address3.fromAddressOrString(contractId).toB256(),
|
5270
|
-
asset:
|
5387
|
+
asset: hexlify15(assetId)
|
5271
5388
|
});
|
5272
5389
|
return bn17(contractBalance.amount, 10);
|
5273
5390
|
}
|
@@ -5281,7 +5398,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5281
5398
|
async getBalance(owner, assetId) {
|
5282
5399
|
const { balance } = await this.operations.getBalance({
|
5283
5400
|
owner: Address3.fromAddressOrString(owner).toB256(),
|
5284
|
-
assetId:
|
5401
|
+
assetId: hexlify15(assetId)
|
5285
5402
|
});
|
5286
5403
|
return bn17(balance.amount, 10);
|
5287
5404
|
}
|
@@ -5327,7 +5444,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5327
5444
|
owner: Address3.fromAddressOrString(address).toB256()
|
5328
5445
|
});
|
5329
5446
|
const messages = edges.map(({ node }) => ({
|
5330
|
-
messageId:
|
5447
|
+
messageId: InputMessageCoder2.getMessageId({
|
5331
5448
|
sender: node.sender,
|
5332
5449
|
recipient: node.recipient,
|
5333
5450
|
nonce: node.nonce,
|
@@ -5338,7 +5455,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5338
5455
|
recipient: Address3.fromAddressOrString(node.recipient),
|
5339
5456
|
nonce: node.nonce,
|
5340
5457
|
amount: bn17(node.amount),
|
5341
|
-
data:
|
5458
|
+
data: InputMessageCoder2.decodeData(node.data),
|
5342
5459
|
daHeight: bn17(node.daHeight)
|
5343
5460
|
}));
|
5344
5461
|
return {
|
@@ -5361,8 +5478,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5361
5478
|
nonce
|
5362
5479
|
};
|
5363
5480
|
if (commitBlockId && commitBlockHeight) {
|
5364
|
-
throw new
|
5365
|
-
|
5481
|
+
throw new FuelError16(
|
5482
|
+
ErrorCode14.INVALID_INPUT_PARAMETERS,
|
5366
5483
|
"commitBlockId and commitBlockHeight cannot be used together"
|
5367
5484
|
);
|
5368
5485
|
}
|
@@ -5502,10 +5619,25 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5502
5619
|
* @returns A promise that resolves to the Message object or null.
|
5503
5620
|
*/
|
5504
5621
|
async getMessageByNonce(nonce) {
|
5505
|
-
const { message } = await this.operations.getMessageByNonce({ nonce });
|
5506
|
-
if (!
|
5622
|
+
const { message: rawMessage } = await this.operations.getMessageByNonce({ nonce });
|
5623
|
+
if (!rawMessage) {
|
5507
5624
|
return null;
|
5508
5625
|
}
|
5626
|
+
const message = {
|
5627
|
+
messageId: InputMessageCoder2.getMessageId({
|
5628
|
+
sender: rawMessage.sender,
|
5629
|
+
recipient: rawMessage.recipient,
|
5630
|
+
nonce: rawMessage.nonce,
|
5631
|
+
amount: bn17(rawMessage.amount),
|
5632
|
+
data: rawMessage.data
|
5633
|
+
}),
|
5634
|
+
sender: Address3.fromAddressOrString(rawMessage.sender),
|
5635
|
+
recipient: Address3.fromAddressOrString(rawMessage.recipient),
|
5636
|
+
nonce: rawMessage.nonce,
|
5637
|
+
amount: bn17(rawMessage.amount),
|
5638
|
+
data: InputMessageCoder2.decodeData(rawMessage.data),
|
5639
|
+
daHeight: bn17(rawMessage.daHeight)
|
5640
|
+
};
|
5509
5641
|
return message;
|
5510
5642
|
}
|
5511
5643
|
/**
|
@@ -5530,26 +5662,26 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5530
5662
|
const { paginationLimit, inputArgs = {} } = params;
|
5531
5663
|
const { first, last, after, before } = inputArgs;
|
5532
5664
|
if (after && before) {
|
5533
|
-
throw new
|
5534
|
-
|
5665
|
+
throw new FuelError16(
|
5666
|
+
ErrorCode14.INVALID_INPUT_PARAMETERS,
|
5535
5667
|
'Pagination arguments "after" and "before" cannot be used together'
|
5536
5668
|
);
|
5537
5669
|
}
|
5538
5670
|
if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
|
5539
|
-
throw new
|
5540
|
-
|
5671
|
+
throw new FuelError16(
|
5672
|
+
ErrorCode14.INVALID_INPUT_PARAMETERS,
|
5541
5673
|
`Pagination limit for this query cannot exceed ${paginationLimit} items`
|
5542
5674
|
);
|
5543
5675
|
}
|
5544
5676
|
if (first && before) {
|
5545
|
-
throw new
|
5546
|
-
|
5677
|
+
throw new FuelError16(
|
5678
|
+
ErrorCode14.INVALID_INPUT_PARAMETERS,
|
5547
5679
|
'The use of pagination argument "first" with "before" is not supported'
|
5548
5680
|
);
|
5549
5681
|
}
|
5550
5682
|
if (last && after) {
|
5551
|
-
throw new
|
5552
|
-
|
5683
|
+
throw new FuelError16(
|
5684
|
+
ErrorCode14.INVALID_INPUT_PARAMETERS,
|
5553
5685
|
'The use of pagination argument "last" with "after" is not supported'
|
5554
5686
|
);
|
5555
5687
|
}
|
@@ -5603,7 +5735,7 @@ __publicField(Provider, "chainInfoCache", {});
|
|
5603
5735
|
__publicField(Provider, "nodeInfoCache", {});
|
5604
5736
|
|
5605
5737
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
5606
|
-
import { ErrorCode as
|
5738
|
+
import { ErrorCode as ErrorCode15, FuelError as FuelError17 } from "@fuel-ts/errors";
|
5607
5739
|
import { bn as bn18 } from "@fuel-ts/math";
|
5608
5740
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
5609
5741
|
import { arrayify as arrayify13 } from "@fuel-ts/utils";
|
@@ -5681,7 +5813,7 @@ var assets = resolveIconPaths(rawAssets, fuelAssetsBaseUrl);
|
|
5681
5813
|
|
5682
5814
|
// src/test-utils/test-asset-id.ts
|
5683
5815
|
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
5684
|
-
import { hexlify as
|
5816
|
+
import { hexlify as hexlify16 } from "@fuel-ts/utils";
|
5685
5817
|
var _TestAssetId = class {
|
5686
5818
|
constructor(value) {
|
5687
5819
|
this.value = value;
|
@@ -5689,7 +5821,7 @@ var _TestAssetId = class {
|
|
5689
5821
|
static random(count = 1) {
|
5690
5822
|
const assetIds = [];
|
5691
5823
|
for (let i = 0; i < count; i++) {
|
5692
|
-
assetIds.push(new _TestAssetId(
|
5824
|
+
assetIds.push(new _TestAssetId(hexlify16(randomBytes4(32))));
|
5693
5825
|
}
|
5694
5826
|
return assetIds;
|
5695
5827
|
}
|
@@ -5704,22 +5836,23 @@ __publicField(TestAssetId, "B", new _TestAssetId(
|
|
5704
5836
|
|
5705
5837
|
// src/test-utils/wallet-config.ts
|
5706
5838
|
import { randomBytes as randomBytes8 } from "@fuel-ts/crypto";
|
5707
|
-
import { FuelError as
|
5708
|
-
import { defaultSnapshotConfigs as defaultSnapshotConfigs2, hexlify as
|
5839
|
+
import { FuelError as FuelError23 } from "@fuel-ts/errors";
|
5840
|
+
import { defaultSnapshotConfigs as defaultSnapshotConfigs2, hexlify as hexlify22 } from "@fuel-ts/utils";
|
5709
5841
|
|
5710
5842
|
// src/wallet/base-wallet-unlocked.ts
|
5711
5843
|
import { hashMessage } from "@fuel-ts/hasher";
|
5712
|
-
import { hexlify as
|
5844
|
+
import { hexlify as hexlify19 } from "@fuel-ts/utils";
|
5713
5845
|
|
5714
5846
|
// src/account.ts
|
5715
5847
|
import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
|
5716
5848
|
import { Address as Address4 } from "@fuel-ts/address";
|
5717
5849
|
import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
|
5718
|
-
import { ErrorCode as
|
5850
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5719
5851
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
5720
5852
|
import { bn as bn19 } from "@fuel-ts/math";
|
5721
|
-
import {
|
5722
|
-
import {
|
5853
|
+
import { InputType as InputType8 } from "@fuel-ts/transactions";
|
5854
|
+
import { arrayify as arrayify15, hexlify as hexlify17, isDefined as isDefined3 } from "@fuel-ts/utils";
|
5855
|
+
import { clone as clone7 } from "ramda";
|
5723
5856
|
|
5724
5857
|
// src/providers/utils/merge-quantities.ts
|
5725
5858
|
var mergeQuantities = (...coinQuantities) => {
|
@@ -5808,7 +5941,7 @@ var Account = class extends AbstractAccount {
|
|
5808
5941
|
*/
|
5809
5942
|
get provider() {
|
5810
5943
|
if (!this._provider) {
|
5811
|
-
throw new
|
5944
|
+
throw new FuelError18(ErrorCode16.MISSING_PROVIDER, "Provider not set");
|
5812
5945
|
}
|
5813
5946
|
return this._provider;
|
5814
5947
|
}
|
@@ -5926,7 +6059,7 @@ var Account = class extends AbstractAccount {
|
|
5926
6059
|
);
|
5927
6060
|
request.addResources(resources);
|
5928
6061
|
request.updatePredicateGasUsed(estimatedPredicates);
|
5929
|
-
const requestToReestimate2 =
|
6062
|
+
const requestToReestimate2 = clone7(request);
|
5930
6063
|
if (addedSignatures) {
|
5931
6064
|
Array.from({ length: addedSignatures }).forEach(
|
5932
6065
|
() => requestToReestimate2.addEmptyWitness()
|
@@ -5941,7 +6074,7 @@ var Account = class extends AbstractAccount {
|
|
5941
6074
|
gasPrice
|
5942
6075
|
});
|
5943
6076
|
const totalBaseAssetOnInputs = getAssetAmountInRequestInputs(
|
5944
|
-
request.inputs,
|
6077
|
+
request.inputs.filter(isRequestInputResource),
|
5945
6078
|
baseAssetId,
|
5946
6079
|
baseAssetId
|
5947
6080
|
);
|
@@ -5959,13 +6092,13 @@ var Account = class extends AbstractAccount {
|
|
5959
6092
|
fundingAttempts += 1;
|
5960
6093
|
}
|
5961
6094
|
if (needsToBeFunded) {
|
5962
|
-
throw new
|
5963
|
-
|
6095
|
+
throw new FuelError18(
|
6096
|
+
ErrorCode16.NOT_ENOUGH_FUNDS,
|
5964
6097
|
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
5965
6098
|
);
|
5966
6099
|
}
|
5967
6100
|
request.updatePredicateGasUsed(estimatedPredicates);
|
5968
|
-
const requestToReestimate =
|
6101
|
+
const requestToReestimate = clone7(request);
|
5969
6102
|
if (addedSignatures) {
|
5970
6103
|
Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
|
5971
6104
|
}
|
@@ -6065,8 +6198,8 @@ var Account = class extends AbstractAccount {
|
|
6065
6198
|
*/
|
6066
6199
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
6067
6200
|
if (bn19(amount).lte(0)) {
|
6068
|
-
throw new
|
6069
|
-
|
6201
|
+
throw new FuelError18(
|
6202
|
+
ErrorCode16.INVALID_TRANSFER_AMOUNT,
|
6070
6203
|
"Transfer amount must be a positive number."
|
6071
6204
|
);
|
6072
6205
|
}
|
@@ -6141,16 +6274,16 @@ var Account = class extends AbstractAccount {
|
|
6141
6274
|
* @returns A promise that resolves to the transaction cost object.
|
6142
6275
|
*/
|
6143
6276
|
async getTransactionCost(transactionRequestLike, { signatureCallback, quantities = [] } = {}) {
|
6144
|
-
const txRequestClone =
|
6277
|
+
const txRequestClone = clone7(transactionRequestify(transactionRequestLike));
|
6145
6278
|
const baseAssetId = this.provider.getBaseAssetId();
|
6146
6279
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
6147
6280
|
const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
|
6148
6281
|
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: bn19("100000000000000000") }];
|
6149
6282
|
const findAssetInput = (assetId) => txRequestClone.inputs.find((input) => {
|
6150
|
-
if (
|
6283
|
+
if (input.type === InputType8.Coin) {
|
6151
6284
|
return input.assetId === assetId;
|
6152
6285
|
}
|
6153
|
-
if (
|
6286
|
+
if (isRequestInputMessageWithoutData(input)) {
|
6154
6287
|
return baseAssetId === assetId;
|
6155
6288
|
}
|
6156
6289
|
return false;
|
@@ -6192,7 +6325,7 @@ var Account = class extends AbstractAccount {
|
|
6192
6325
|
*/
|
6193
6326
|
async signMessage(message) {
|
6194
6327
|
if (!this._connector) {
|
6195
|
-
throw new
|
6328
|
+
throw new FuelError18(ErrorCode16.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
6196
6329
|
}
|
6197
6330
|
return this._connector.signMessage(this.address.toString(), message);
|
6198
6331
|
}
|
@@ -6204,8 +6337,8 @@ var Account = class extends AbstractAccount {
|
|
6204
6337
|
*/
|
6205
6338
|
async signTransaction(transactionRequestLike) {
|
6206
6339
|
if (!this._connector) {
|
6207
|
-
throw new
|
6208
|
-
|
6340
|
+
throw new FuelError18(
|
6341
|
+
ErrorCode16.MISSING_CONNECTOR,
|
6209
6342
|
"A connector is required to sign transactions."
|
6210
6343
|
);
|
6211
6344
|
}
|
@@ -6254,7 +6387,7 @@ var Account = class extends AbstractAccount {
|
|
6254
6387
|
*/
|
6255
6388
|
generateFakeResources(coins) {
|
6256
6389
|
return coins.map((coin) => ({
|
6257
|
-
id:
|
6390
|
+
id: hexlify17(randomBytes5(UTXO_ID_LEN3)),
|
6258
6391
|
owner: this.address,
|
6259
6392
|
blockCreated: bn19(1),
|
6260
6393
|
txCreatedIdx: bn19(1),
|
@@ -6264,8 +6397,8 @@ var Account = class extends AbstractAccount {
|
|
6264
6397
|
/** @hidden * */
|
6265
6398
|
validateTransferAmount(amount) {
|
6266
6399
|
if (bn19(amount).lte(0)) {
|
6267
|
-
throw new
|
6268
|
-
|
6400
|
+
throw new FuelError18(
|
6401
|
+
ErrorCode16.INVALID_TRANSFER_AMOUNT,
|
6269
6402
|
"Transfer amount must be a positive number."
|
6270
6403
|
);
|
6271
6404
|
}
|
@@ -6294,16 +6427,16 @@ var Account = class extends AbstractAccount {
|
|
6294
6427
|
if (!isDefined3(setGasLimit)) {
|
6295
6428
|
request.gasLimit = gasUsed;
|
6296
6429
|
} else if (gasUsed.gt(setGasLimit)) {
|
6297
|
-
throw new
|
6298
|
-
|
6430
|
+
throw new FuelError18(
|
6431
|
+
ErrorCode16.GAS_LIMIT_TOO_LOW,
|
6299
6432
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
6300
6433
|
);
|
6301
6434
|
}
|
6302
6435
|
if (!isDefined3(setMaxFee)) {
|
6303
6436
|
request.maxFee = maxFee;
|
6304
6437
|
} else if (maxFee.gt(setMaxFee)) {
|
6305
|
-
throw new
|
6306
|
-
|
6438
|
+
throw new FuelError18(
|
6439
|
+
ErrorCode16.MAX_FEE_TOO_LOW,
|
6307
6440
|
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
6308
6441
|
);
|
6309
6442
|
}
|
@@ -6323,8 +6456,8 @@ import {
|
|
6323
6456
|
encryptJsonWalletData,
|
6324
6457
|
randomUUID as randomUUID2
|
6325
6458
|
} from "@fuel-ts/crypto";
|
6326
|
-
import { ErrorCode as
|
6327
|
-
import { hexlify as
|
6459
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError19 } from "@fuel-ts/errors";
|
6460
|
+
import { hexlify as hexlify18 } from "@fuel-ts/utils";
|
6328
6461
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
6329
6462
|
var DEFAULT_KDF_PARAMS_R = 8;
|
6330
6463
|
var DEFAULT_KDF_PARAMS_P = 1;
|
@@ -6400,13 +6533,13 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
6400
6533
|
const macHashUint8Array = keccak256(data);
|
6401
6534
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
6402
6535
|
if (mac !== macHash) {
|
6403
|
-
throw new
|
6404
|
-
|
6536
|
+
throw new FuelError19(
|
6537
|
+
ErrorCode17.INVALID_PASSWORD,
|
6405
6538
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
6406
6539
|
);
|
6407
6540
|
}
|
6408
6541
|
const buffer = await decryptJsonWalletData(ciphertextBuffer, key, ivBuffer);
|
6409
|
-
const privateKey =
|
6542
|
+
const privateKey = hexlify18(buffer);
|
6410
6543
|
return privateKey;
|
6411
6544
|
}
|
6412
6545
|
|
@@ -6451,7 +6584,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
6451
6584
|
*/
|
6452
6585
|
async signMessage(message) {
|
6453
6586
|
const signedMessage = await this.signer().sign(hashMessage(message));
|
6454
|
-
return
|
6587
|
+
return hexlify19(signedMessage);
|
6455
6588
|
}
|
6456
6589
|
/**
|
6457
6590
|
* Signs a transaction with the wallet's private key.
|
@@ -6464,7 +6597,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
6464
6597
|
const chainId = this.provider.getChainId();
|
6465
6598
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
6466
6599
|
const signature = await this.signer().sign(hashedTransaction);
|
6467
|
-
return
|
6600
|
+
return hexlify19(signature);
|
6468
6601
|
}
|
6469
6602
|
/**
|
6470
6603
|
* Populates a transaction with the witnesses signature.
|
@@ -6531,16 +6664,16 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
6531
6664
|
|
6532
6665
|
// src/hdwallet/hdwallet.ts
|
6533
6666
|
import { computeHmac as computeHmac2, ripemd160 } from "@fuel-ts/crypto";
|
6534
|
-
import { ErrorCode as
|
6667
|
+
import { ErrorCode as ErrorCode20, FuelError as FuelError22 } from "@fuel-ts/errors";
|
6535
6668
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
6536
6669
|
import { bn as bn20, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
6537
|
-
import { arrayify as arrayify18, hexlify as
|
6670
|
+
import { arrayify as arrayify18, hexlify as hexlify21, concat as concat5, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58 } from "@fuel-ts/utils";
|
6538
6671
|
|
6539
6672
|
// src/mnemonic/mnemonic.ts
|
6540
6673
|
import { randomBytes as randomBytes7, pbkdf2, computeHmac } from "@fuel-ts/crypto";
|
6541
|
-
import { ErrorCode as
|
6674
|
+
import { ErrorCode as ErrorCode19, FuelError as FuelError21 } from "@fuel-ts/errors";
|
6542
6675
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
6543
|
-
import { arrayify as arrayify17, hexlify as
|
6676
|
+
import { arrayify as arrayify17, hexlify as hexlify20, concat as concat4, dataSlice, encodeBase58, toUtf8Bytes } from "@fuel-ts/utils";
|
6544
6677
|
|
6545
6678
|
// src/wordlists/words/english.ts
|
6546
6679
|
var english = [
|
@@ -8595,7 +8728,7 @@ var english = [
|
|
8595
8728
|
];
|
8596
8729
|
|
8597
8730
|
// src/mnemonic/utils.ts
|
8598
|
-
import { ErrorCode as
|
8731
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError20 } from "@fuel-ts/errors";
|
8599
8732
|
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
8600
8733
|
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
8601
8734
|
function getLowerMask(bits) {
|
@@ -8644,8 +8777,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
8644
8777
|
for (let i = 0; i < words.length; i += 1) {
|
8645
8778
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
8646
8779
|
if (index === -1) {
|
8647
|
-
throw new
|
8648
|
-
|
8780
|
+
throw new FuelError20(
|
8781
|
+
ErrorCode18.INVALID_MNEMONIC,
|
8649
8782
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
8650
8783
|
);
|
8651
8784
|
}
|
@@ -8661,8 +8794,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
8661
8794
|
const checksumMask = getUpperMask(checksumBits);
|
8662
8795
|
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
8663
8796
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
8664
|
-
throw new
|
8665
|
-
|
8797
|
+
throw new FuelError20(
|
8798
|
+
ErrorCode18.INVALID_CHECKSUM,
|
8666
8799
|
"Checksum validation failed for the provided mnemonic."
|
8667
8800
|
);
|
8668
8801
|
}
|
@@ -8676,16 +8809,16 @@ var TestnetPRV = "0x04358394";
|
|
8676
8809
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
8677
8810
|
function assertWordList(wordlist) {
|
8678
8811
|
if (wordlist.length !== 2048) {
|
8679
|
-
throw new
|
8680
|
-
|
8812
|
+
throw new FuelError21(
|
8813
|
+
ErrorCode19.INVALID_WORD_LIST,
|
8681
8814
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
8682
8815
|
);
|
8683
8816
|
}
|
8684
8817
|
}
|
8685
8818
|
function assertEntropy(entropy) {
|
8686
8819
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
8687
|
-
throw new
|
8688
|
-
|
8820
|
+
throw new FuelError21(
|
8821
|
+
ErrorCode19.INVALID_ENTROPY,
|
8689
8822
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
8690
8823
|
);
|
8691
8824
|
}
|
@@ -8695,7 +8828,7 @@ function assertMnemonic(words) {
|
|
8695
8828
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
8696
8829
|
", "
|
8697
8830
|
)}] words, but got ${words.length}.`;
|
8698
|
-
throw new
|
8831
|
+
throw new FuelError21(ErrorCode19.INVALID_MNEMONIC, errorMsg);
|
8699
8832
|
}
|
8700
8833
|
}
|
8701
8834
|
var Mnemonic = class {
|
@@ -8734,7 +8867,7 @@ var Mnemonic = class {
|
|
8734
8867
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
8735
8868
|
const words = getWords(phrase);
|
8736
8869
|
assertMnemonic(words);
|
8737
|
-
return
|
8870
|
+
return hexlify20(mnemonicWordsToEntropy(words, wordlist));
|
8738
8871
|
}
|
8739
8872
|
/**
|
8740
8873
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -8813,8 +8946,8 @@ var Mnemonic = class {
|
|
8813
8946
|
static masterKeysFromSeed(seed) {
|
8814
8947
|
const seedArray = arrayify17(seed);
|
8815
8948
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
8816
|
-
throw new
|
8817
|
-
|
8949
|
+
throw new FuelError21(
|
8950
|
+
ErrorCode19.INVALID_SEED,
|
8818
8951
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
8819
8952
|
);
|
8820
8953
|
}
|
@@ -8867,10 +9000,10 @@ var mnemonic_default = Mnemonic;
|
|
8867
9000
|
|
8868
9001
|
// src/hdwallet/hdwallet.ts
|
8869
9002
|
var HARDENED_INDEX = 2147483648;
|
8870
|
-
var MainnetPRV2 =
|
8871
|
-
var MainnetPUB =
|
8872
|
-
var TestnetPRV2 =
|
8873
|
-
var TestnetPUB =
|
9003
|
+
var MainnetPRV2 = hexlify21("0x0488ade4");
|
9004
|
+
var MainnetPUB = hexlify21("0x0488b21e");
|
9005
|
+
var TestnetPRV2 = hexlify21("0x04358394");
|
9006
|
+
var TestnetPUB = hexlify21("0x043587cf");
|
8874
9007
|
function base58check(data) {
|
8875
9008
|
return encodeBase582(concat5([data, dataSlice2(sha2564(sha2564(data)), 0, 4)]));
|
8876
9009
|
}
|
@@ -8881,17 +9014,17 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8881
9014
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8882
9015
|
}
|
8883
9016
|
function isPublicExtendedKey(extendedKey) {
|
8884
|
-
return [MainnetPUB, TestnetPUB].includes(
|
9017
|
+
return [MainnetPUB, TestnetPUB].includes(hexlify21(extendedKey.slice(0, 4)));
|
8885
9018
|
}
|
8886
9019
|
function isValidExtendedKey(extendedKey) {
|
8887
9020
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8888
|
-
|
9021
|
+
hexlify21(extendedKey.slice(0, 4))
|
8889
9022
|
);
|
8890
9023
|
}
|
8891
9024
|
function parsePath(path2, depth = 0) {
|
8892
9025
|
const components = path2.split("/");
|
8893
9026
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
8894
|
-
throw new
|
9027
|
+
throw new FuelError22(ErrorCode20.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
8895
9028
|
}
|
8896
9029
|
if (components[0] === "m") {
|
8897
9030
|
components.shift();
|
@@ -8903,8 +9036,8 @@ function parsePath(path2, depth = 0) {
|
|
8903
9036
|
var HDWallet = class {
|
8904
9037
|
depth = 0;
|
8905
9038
|
index = 0;
|
8906
|
-
fingerprint =
|
8907
|
-
parentFingerprint =
|
9039
|
+
fingerprint = hexlify21("0x00000000");
|
9040
|
+
parentFingerprint = hexlify21("0x00000000");
|
8908
9041
|
privateKey;
|
8909
9042
|
publicKey;
|
8910
9043
|
chainCode;
|
@@ -8916,16 +9049,16 @@ var HDWallet = class {
|
|
8916
9049
|
constructor(config) {
|
8917
9050
|
if (config.privateKey) {
|
8918
9051
|
const signer = new Signer(config.privateKey);
|
8919
|
-
this.publicKey =
|
8920
|
-
this.privateKey =
|
9052
|
+
this.publicKey = hexlify21(signer.compressedPublicKey);
|
9053
|
+
this.privateKey = hexlify21(config.privateKey);
|
8921
9054
|
} else {
|
8922
9055
|
if (!config.publicKey) {
|
8923
|
-
throw new
|
8924
|
-
|
9056
|
+
throw new FuelError22(
|
9057
|
+
ErrorCode20.HD_WALLET_ERROR,
|
8925
9058
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8926
9059
|
);
|
8927
9060
|
}
|
8928
|
-
this.publicKey =
|
9061
|
+
this.publicKey = hexlify21(config.publicKey);
|
8929
9062
|
}
|
8930
9063
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8931
9064
|
this.fingerprint = dataSlice2(ripemd160(sha2564(this.publicKey)), 0, 4);
|
@@ -8950,8 +9083,8 @@ var HDWallet = class {
|
|
8950
9083
|
const data = new Uint8Array(37);
|
8951
9084
|
if (index & HARDENED_INDEX) {
|
8952
9085
|
if (!privateKey) {
|
8953
|
-
throw new
|
8954
|
-
|
9086
|
+
throw new FuelError22(
|
9087
|
+
ErrorCode20.HD_WALLET_ERROR,
|
8955
9088
|
"Cannot derive a hardened index without a private Key."
|
8956
9089
|
);
|
8957
9090
|
}
|
@@ -8974,7 +9107,7 @@ var HDWallet = class {
|
|
8974
9107
|
parentFingerprint: this.fingerprint
|
8975
9108
|
});
|
8976
9109
|
}
|
8977
|
-
const signer = new Signer(
|
9110
|
+
const signer = new Signer(hexlify21(IL));
|
8978
9111
|
const Ki = signer.addPoint(publicKey);
|
8979
9112
|
return new HDWallet({
|
8980
9113
|
publicKey: Ki,
|
@@ -9003,13 +9136,13 @@ var HDWallet = class {
|
|
9003
9136
|
*/
|
9004
9137
|
toExtendedKey(isPublic = false, testnet = false) {
|
9005
9138
|
if (this.depth >= 256) {
|
9006
|
-
throw new
|
9007
|
-
|
9139
|
+
throw new FuelError22(
|
9140
|
+
ErrorCode20.HD_WALLET_ERROR,
|
9008
9141
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
9009
9142
|
);
|
9010
9143
|
}
|
9011
9144
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
9012
|
-
const depth =
|
9145
|
+
const depth = hexlify21(Uint8Array.from([this.depth]));
|
9013
9146
|
const parentFingerprint = this.parentFingerprint;
|
9014
9147
|
const index = toHex(this.index, 4);
|
9015
9148
|
const chainCode = this.chainCode;
|
@@ -9031,29 +9164,29 @@ var HDWallet = class {
|
|
9031
9164
|
});
|
9032
9165
|
}
|
9033
9166
|
static fromExtendedKey(extendedKey) {
|
9034
|
-
const decoded =
|
9167
|
+
const decoded = hexlify21(toBytes2(decodeBase58(extendedKey)));
|
9035
9168
|
const bytes = arrayify18(decoded);
|
9036
9169
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
9037
9170
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
9038
|
-
throw new
|
9171
|
+
throw new FuelError22(ErrorCode20.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
9039
9172
|
}
|
9040
9173
|
if (!validChecksum) {
|
9041
|
-
throw new
|
9174
|
+
throw new FuelError22(ErrorCode20.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
9042
9175
|
}
|
9043
9176
|
const depth = bytes[4];
|
9044
|
-
const parentFingerprint =
|
9045
|
-
const index = parseInt(
|
9046
|
-
const chainCode =
|
9177
|
+
const parentFingerprint = hexlify21(bytes.slice(5, 9));
|
9178
|
+
const index = parseInt(hexlify21(bytes.slice(9, 13)).substring(2), 16);
|
9179
|
+
const chainCode = hexlify21(bytes.slice(13, 45));
|
9047
9180
|
const key = bytes.slice(45, 78);
|
9048
9181
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
9049
|
-
throw new
|
9050
|
-
|
9182
|
+
throw new FuelError22(
|
9183
|
+
ErrorCode20.HD_WALLET_ERROR,
|
9051
9184
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
9052
9185
|
);
|
9053
9186
|
}
|
9054
9187
|
if (isPublicExtendedKey(bytes)) {
|
9055
9188
|
if (key[0] !== 3) {
|
9056
|
-
throw new
|
9189
|
+
throw new FuelError22(ErrorCode20.HD_WALLET_ERROR, "Invalid public extended key.");
|
9057
9190
|
}
|
9058
9191
|
return new HDWallet({
|
9059
9192
|
publicKey: key,
|
@@ -9064,7 +9197,7 @@ var HDWallet = class {
|
|
9064
9197
|
});
|
9065
9198
|
}
|
9066
9199
|
if (key[0] !== 0) {
|
9067
|
-
throw new
|
9200
|
+
throw new FuelError22(ErrorCode20.HD_WALLET_ERROR, "Invalid private extended key.");
|
9068
9201
|
}
|
9069
9202
|
return new HDWallet({
|
9070
9203
|
privateKey: key.slice(1),
|
@@ -9294,7 +9427,7 @@ var WalletsConfig = class {
|
|
9294
9427
|
tx_pointer_block_height: 0,
|
9295
9428
|
tx_pointer_tx_idx: 0,
|
9296
9429
|
output_index: 0,
|
9297
|
-
tx_id:
|
9430
|
+
tx_id: hexlify22(randomBytes8(32))
|
9298
9431
|
});
|
9299
9432
|
}
|
9300
9433
|
});
|
@@ -9308,26 +9441,26 @@ var WalletsConfig = class {
|
|
9308
9441
|
amountPerCoin
|
9309
9442
|
}) {
|
9310
9443
|
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
9311
|
-
throw new
|
9312
|
-
|
9444
|
+
throw new FuelError23(
|
9445
|
+
FuelError23.CODES.INVALID_INPUT_PARAMETERS,
|
9313
9446
|
"Number of wallets must be greater than zero."
|
9314
9447
|
);
|
9315
9448
|
}
|
9316
9449
|
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
9317
|
-
throw new
|
9318
|
-
|
9450
|
+
throw new FuelError23(
|
9451
|
+
FuelError23.CODES.INVALID_INPUT_PARAMETERS,
|
9319
9452
|
"Number of assets per wallet must be greater than zero."
|
9320
9453
|
);
|
9321
9454
|
}
|
9322
9455
|
if (coinsPerAsset <= 0) {
|
9323
|
-
throw new
|
9324
|
-
|
9456
|
+
throw new FuelError23(
|
9457
|
+
FuelError23.CODES.INVALID_INPUT_PARAMETERS,
|
9325
9458
|
"Number of coins per asset must be greater than zero."
|
9326
9459
|
);
|
9327
9460
|
}
|
9328
9461
|
if (amountPerCoin < 0) {
|
9329
|
-
throw new
|
9330
|
-
|
9462
|
+
throw new FuelError23(
|
9463
|
+
FuelError23.CODES.INVALID_INPUT_PARAMETERS,
|
9331
9464
|
"Amount per coin must be greater than or equal to zero."
|
9332
9465
|
);
|
9333
9466
|
}
|
@@ -9401,7 +9534,7 @@ async function setupTestProviderAndWallets({
|
|
9401
9534
|
import { Address as Address6 } from "@fuel-ts/address";
|
9402
9535
|
import { randomBytes as randomBytes9 } from "@fuel-ts/crypto";
|
9403
9536
|
import { bn as bn21 } from "@fuel-ts/math";
|
9404
|
-
import { hexlify as
|
9537
|
+
import { hexlify as hexlify23 } from "@fuel-ts/utils";
|
9405
9538
|
var TestMessage = class {
|
9406
9539
|
sender;
|
9407
9540
|
recipient;
|
@@ -9418,7 +9551,7 @@ var TestMessage = class {
|
|
9418
9551
|
constructor({
|
9419
9552
|
sender = Address6.fromRandom(),
|
9420
9553
|
recipient = Address6.fromRandom(),
|
9421
|
-
nonce =
|
9554
|
+
nonce = hexlify23(randomBytes9(32)),
|
9422
9555
|
amount = 1e6,
|
9423
9556
|
data = "",
|
9424
9557
|
// Will default to empty data in order to be a spendable message
|