@fuel-ts/account 0.0.0-rc-1356-20240514125020 → 0.0.0-rc-2238-20240514153703
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/dist/account.d.ts.map +1 -1
- package/dist/index.global.js +432 -1164
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +234 -254
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +118 -145
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +0 -1
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +0 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +0 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +0 -1
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-summary/call.d.ts +1 -1
- package/dist/providers/transaction-summary/call.d.ts.map +1 -1
- package/dist/providers/utils/auto-retry-fetch.d.ts.map +1 -1
- package/dist/providers/utils/index.d.ts +1 -0
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/providers/utils/sleep.d.ts +3 -0
- package/dist/providers/utils/sleep.d.ts.map +1 -0
- package/dist/test-utils/index.d.ts +0 -4
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +1 -8
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +428 -1475
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +272 -523
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +166 -413
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +15 -16
- package/dist/test-utils/asset-id.d.ts +0 -8
- package/dist/test-utils/asset-id.d.ts.map +0 -1
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts +0 -33
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +0 -1
- package/dist/test-utils/test-message.d.ts +0 -28
- package/dist/test-utils/test-message.d.ts.map +0 -1
- package/dist/test-utils/wallet-config.d.ts +0 -49
- package/dist/test-utils/wallet-config.d.ts.map +0 -1
package/dist/test-utils.js
CHANGED
@@ -48,28 +48,24 @@ var __privateMethod = (obj, member, method) => {
|
|
48
48
|
// src/test-utils/index.ts
|
49
49
|
var test_utils_exports = {};
|
50
50
|
__export(test_utils_exports, {
|
51
|
-
AssetId: () => AssetId,
|
52
|
-
TestMessage: () => TestMessage,
|
53
|
-
WalletConfig: () => WalletConfig,
|
54
51
|
generateTestWallet: () => generateTestWallet,
|
55
52
|
killNode: () => killNode,
|
56
53
|
launchNode: () => launchNode,
|
57
54
|
launchNodeAndGetWallets: () => launchNodeAndGetWallets,
|
58
|
-
seedTestWallet: () => seedTestWallet
|
59
|
-
setupTestProviderAndWallets: () => setupTestProviderAndWallets
|
55
|
+
seedTestWallet: () => seedTestWallet
|
60
56
|
});
|
61
57
|
module.exports = __toCommonJS(test_utils_exports);
|
62
58
|
|
63
59
|
// src/wallet/base-wallet-unlocked.ts
|
64
60
|
var import_hasher3 = require("@fuel-ts/hasher");
|
65
|
-
var
|
61
|
+
var import_utils31 = require("@fuel-ts/utils");
|
66
62
|
|
67
63
|
// src/account.ts
|
68
64
|
var import_address4 = require("@fuel-ts/address");
|
69
65
|
var import_errors16 = require("@fuel-ts/errors");
|
70
66
|
var import_interfaces = require("@fuel-ts/interfaces");
|
71
|
-
var
|
72
|
-
var
|
67
|
+
var import_math20 = require("@fuel-ts/math");
|
68
|
+
var import_utils28 = require("@fuel-ts/utils");
|
73
69
|
var import_ramda4 = require("ramda");
|
74
70
|
|
75
71
|
// src/providers/coin-quantity.ts
|
@@ -110,11 +106,11 @@ var addAmountToCoinQuantities = (params) => {
|
|
110
106
|
// src/providers/provider.ts
|
111
107
|
var import_address3 = require("@fuel-ts/address");
|
112
108
|
var import_errors14 = require("@fuel-ts/errors");
|
113
|
-
var
|
109
|
+
var import_math17 = require("@fuel-ts/math");
|
114
110
|
var import_transactions20 = require("@fuel-ts/transactions");
|
115
|
-
var
|
111
|
+
var import_utils22 = require("@fuel-ts/utils");
|
116
112
|
var import_versions = require("@fuel-ts/versions");
|
117
|
-
var
|
113
|
+
var import_utils23 = require("@noble/curves/abstract/utils");
|
118
114
|
var import_graphql_request = require("graphql-request");
|
119
115
|
var import_ramda3 = require("ramda");
|
120
116
|
|
@@ -1671,6 +1667,15 @@ function normalizeJSON(root) {
|
|
1671
1667
|
return normalize((0, import_ramda.clone)(root));
|
1672
1668
|
}
|
1673
1669
|
|
1670
|
+
// src/providers/utils/sleep.ts
|
1671
|
+
function sleep(time) {
|
1672
|
+
return new Promise((resolve) => {
|
1673
|
+
setTimeout(() => {
|
1674
|
+
resolve(true);
|
1675
|
+
}, time);
|
1676
|
+
});
|
1677
|
+
}
|
1678
|
+
|
1674
1679
|
// src/providers/utils/extract-tx-error.ts
|
1675
1680
|
var import_errors7 = require("@fuel-ts/errors");
|
1676
1681
|
var import_math6 = require("@fuel-ts/math");
|
@@ -2291,15 +2296,6 @@ var BaseTransactionRequest = class {
|
|
2291
2296
|
}
|
2292
2297
|
});
|
2293
2298
|
}
|
2294
|
-
shiftPredicateData() {
|
2295
|
-
this.inputs.forEach((input) => {
|
2296
|
-
if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
|
2297
|
-
input.predicateData = input.padPredicateData(
|
2298
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2299
|
-
);
|
2300
|
-
}
|
2301
|
-
});
|
2302
|
-
}
|
2303
2299
|
};
|
2304
2300
|
|
2305
2301
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2722,12 +2718,12 @@ var transactionRequestify = (obj) => {
|
|
2722
2718
|
|
2723
2719
|
// src/providers/transaction-response/transaction-response.ts
|
2724
2720
|
var import_errors13 = require("@fuel-ts/errors");
|
2725
|
-
var
|
2721
|
+
var import_math16 = require("@fuel-ts/math");
|
2726
2722
|
var import_transactions19 = require("@fuel-ts/transactions");
|
2727
2723
|
var import_utils20 = require("@fuel-ts/utils");
|
2728
2724
|
|
2729
2725
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2730
|
-
var
|
2726
|
+
var import_math15 = require("@fuel-ts/math");
|
2731
2727
|
var import_transactions17 = require("@fuel-ts/transactions");
|
2732
2728
|
var import_utils18 = require("@fuel-ts/utils");
|
2733
2729
|
|
@@ -2804,43 +2800,32 @@ var calculateTXFeeForSummary = (params) => {
|
|
2804
2800
|
// src/providers/transaction-summary/operations.ts
|
2805
2801
|
var import_configs10 = require("@fuel-ts/address/configs");
|
2806
2802
|
var import_errors11 = require("@fuel-ts/errors");
|
2807
|
-
var
|
2803
|
+
var import_math13 = require("@fuel-ts/math");
|
2808
2804
|
var import_transactions15 = require("@fuel-ts/transactions");
|
2809
2805
|
|
2810
2806
|
// src/providers/transaction-summary/call.ts
|
2811
2807
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
2812
|
-
var
|
2813
|
-
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2808
|
+
var getFunctionCall = ({ abi, receipt }) => {
|
2814
2809
|
const abiInterface = new import_abi_coder4.Interface(abi);
|
2815
2810
|
const callFunctionSelector = receipt.param1.toHex(8);
|
2816
2811
|
const functionFragment = abiInterface.getFunction(callFunctionSelector);
|
2817
2812
|
const inputs = functionFragment.jsonFn.inputs;
|
2818
|
-
|
2819
|
-
if (functionFragment.isInputDataPointer) {
|
2820
|
-
if (rawPayload) {
|
2821
|
-
const argsOffset = (0, import_math13.bn)(receipt.param2).sub((0, import_abi_coder4.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2822
|
-
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2823
|
-
}
|
2824
|
-
} else {
|
2825
|
-
encodedArgs = receipt.param2.toHex();
|
2826
|
-
}
|
2813
|
+
const encodedArgs = receipt.param2.toHex();
|
2827
2814
|
let argumentsProvided;
|
2828
|
-
|
2829
|
-
|
2830
|
-
|
2831
|
-
|
2832
|
-
|
2833
|
-
|
2834
|
-
|
2835
|
-
|
2836
|
-
|
2837
|
-
|
2838
|
-
|
2839
|
-
|
2840
|
-
|
2841
|
-
|
2842
|
-
}, {});
|
2843
|
-
}
|
2815
|
+
const data = functionFragment.decodeArguments(encodedArgs);
|
2816
|
+
if (data) {
|
2817
|
+
argumentsProvided = inputs.reduce((prev, input, index) => {
|
2818
|
+
const value = data[index];
|
2819
|
+
const name = input.name;
|
2820
|
+
if (name) {
|
2821
|
+
return {
|
2822
|
+
...prev,
|
2823
|
+
// reparse to remove bn
|
2824
|
+
[name]: JSON.parse(JSON.stringify(value))
|
2825
|
+
};
|
2826
|
+
}
|
2827
|
+
return prev;
|
2828
|
+
}, {});
|
2844
2829
|
}
|
2845
2830
|
const call = {
|
2846
2831
|
functionSignature: functionFragment.signature,
|
@@ -2980,7 +2965,7 @@ var mergeAssets = (op1, op2) => {
|
|
2980
2965
|
if (!matchingAsset) {
|
2981
2966
|
return asset1;
|
2982
2967
|
}
|
2983
|
-
const mergedAmount = (0,
|
2968
|
+
const mergedAmount = (0, import_math13.bn)(asset1.amount).add(matchingAsset.amount);
|
2984
2969
|
return { ...asset1, amount: mergedAmount };
|
2985
2970
|
});
|
2986
2971
|
return mergedAssets.concat(filteredAssets);
|
@@ -3303,7 +3288,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3303
3288
|
|
3304
3289
|
// src/providers/transaction-summary/status.ts
|
3305
3290
|
var import_errors12 = require("@fuel-ts/errors");
|
3306
|
-
var
|
3291
|
+
var import_math14 = require("@fuel-ts/math");
|
3307
3292
|
var getTransactionStatusName = (gqlStatus) => {
|
3308
3293
|
switch (gqlStatus) {
|
3309
3294
|
case "FailureStatus":
|
@@ -3337,15 +3322,15 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
|
|
3337
3322
|
time = gqlTransactionStatus.time;
|
3338
3323
|
blockId = gqlTransactionStatus.block.id;
|
3339
3324
|
isStatusSuccess = true;
|
3340
|
-
totalFee = (0,
|
3341
|
-
totalGas = (0,
|
3325
|
+
totalFee = (0, import_math14.bn)(gqlTransactionStatus.totalFee);
|
3326
|
+
totalGas = (0, import_math14.bn)(gqlTransactionStatus.totalGas);
|
3342
3327
|
break;
|
3343
3328
|
case "FailureStatus":
|
3344
3329
|
time = gqlTransactionStatus.time;
|
3345
3330
|
blockId = gqlTransactionStatus.block.id;
|
3346
3331
|
isStatusFailure = true;
|
3347
|
-
totalFee = (0,
|
3348
|
-
totalGas = (0,
|
3332
|
+
totalFee = (0, import_math14.bn)(gqlTransactionStatus.totalFee);
|
3333
|
+
totalGas = (0, import_math14.bn)(gqlTransactionStatus.totalGas);
|
3349
3334
|
break;
|
3350
3335
|
case "SubmittedStatus":
|
3351
3336
|
time = gqlTransactionStatus.time;
|
@@ -3395,7 +3380,7 @@ function assembleTransactionSummary(params) {
|
|
3395
3380
|
maxInputs
|
3396
3381
|
});
|
3397
3382
|
const typeName = getTransactionTypeName(transaction.type);
|
3398
|
-
const tip = (0,
|
3383
|
+
const tip = (0, import_math15.bn)(transaction.policies?.find((policy) => policy.type === import_transactions17.PolicyType.Tip)?.data);
|
3399
3384
|
const { isStatusFailure, isStatusPending, isStatusSuccess, blockId, status, time, totalFee } = processGraphqlStatus(gqlTransactionStatus);
|
3400
3385
|
const fee = calculateTXFeeForSummary({
|
3401
3386
|
totalFee,
|
@@ -3466,7 +3451,7 @@ var TransactionResponse = class {
|
|
3466
3451
|
/** Current provider */
|
3467
3452
|
provider;
|
3468
3453
|
/** Gas used on the transaction */
|
3469
|
-
gasUsed = (0,
|
3454
|
+
gasUsed = (0, import_math16.bn)(0);
|
3470
3455
|
/** The graphql Transaction with receipts object. */
|
3471
3456
|
gqlTransaction;
|
3472
3457
|
abis;
|
@@ -3634,7 +3619,6 @@ var TransactionResponse = class {
|
|
3634
3619
|
};
|
3635
3620
|
|
3636
3621
|
// src/providers/utils/auto-retry-fetch.ts
|
3637
|
-
var import_utils22 = require("@fuel-ts/utils");
|
3638
3622
|
function getWaitDelay(options, retryAttemptNum) {
|
3639
3623
|
const duration = options.baseDelay ?? 150;
|
3640
3624
|
switch (options.backoff) {
|
@@ -3664,7 +3648,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
3664
3648
|
throw error;
|
3665
3649
|
}
|
3666
3650
|
const delay = getWaitDelay(options, retryNum);
|
3667
|
-
await
|
3651
|
+
await sleep(delay);
|
3668
3652
|
return autoRetryFetch(fetchFn, options, retryNum)(...args);
|
3669
3653
|
}
|
3670
3654
|
};
|
@@ -3701,47 +3685,47 @@ var processGqlChain = (chain) => {
|
|
3701
3685
|
} = consensusParameters;
|
3702
3686
|
return {
|
3703
3687
|
name,
|
3704
|
-
baseChainHeight: (0,
|
3688
|
+
baseChainHeight: (0, import_math17.bn)(daHeight),
|
3705
3689
|
consensusParameters: {
|
3706
3690
|
version,
|
3707
|
-
chainId: (0,
|
3691
|
+
chainId: (0, import_math17.bn)(chainId),
|
3708
3692
|
baseAssetId,
|
3709
3693
|
feeParameters: {
|
3710
3694
|
version: feeParams.version,
|
3711
|
-
gasPerByte: (0,
|
3712
|
-
gasPriceFactor: (0,
|
3695
|
+
gasPerByte: (0, import_math17.bn)(feeParams.gasPerByte),
|
3696
|
+
gasPriceFactor: (0, import_math17.bn)(feeParams.gasPriceFactor)
|
3713
3697
|
},
|
3714
3698
|
contractParameters: {
|
3715
3699
|
version: contractParams.version,
|
3716
|
-
contractMaxSize: (0,
|
3717
|
-
maxStorageSlots: (0,
|
3700
|
+
contractMaxSize: (0, import_math17.bn)(contractParams.contractMaxSize),
|
3701
|
+
maxStorageSlots: (0, import_math17.bn)(contractParams.maxStorageSlots)
|
3718
3702
|
},
|
3719
3703
|
txParameters: {
|
3720
3704
|
version: txParams.version,
|
3721
|
-
maxInputs: (0,
|
3722
|
-
maxOutputs: (0,
|
3723
|
-
maxWitnesses: (0,
|
3724
|
-
maxGasPerTx: (0,
|
3725
|
-
maxSize: (0,
|
3726
|
-
maxBytecodeSubsections: (0,
|
3705
|
+
maxInputs: (0, import_math17.bn)(txParams.maxInputs),
|
3706
|
+
maxOutputs: (0, import_math17.bn)(txParams.maxOutputs),
|
3707
|
+
maxWitnesses: (0, import_math17.bn)(txParams.maxWitnesses),
|
3708
|
+
maxGasPerTx: (0, import_math17.bn)(txParams.maxGasPerTx),
|
3709
|
+
maxSize: (0, import_math17.bn)(txParams.maxSize),
|
3710
|
+
maxBytecodeSubsections: (0, import_math17.bn)(txParams.maxBytecodeSubsections)
|
3727
3711
|
},
|
3728
3712
|
predicateParameters: {
|
3729
3713
|
version: predicateParams.version,
|
3730
|
-
maxPredicateLength: (0,
|
3731
|
-
maxPredicateDataLength: (0,
|
3732
|
-
maxGasPerPredicate: (0,
|
3733
|
-
maxMessageDataLength: (0,
|
3714
|
+
maxPredicateLength: (0, import_math17.bn)(predicateParams.maxPredicateLength),
|
3715
|
+
maxPredicateDataLength: (0, import_math17.bn)(predicateParams.maxPredicateDataLength),
|
3716
|
+
maxGasPerPredicate: (0, import_math17.bn)(predicateParams.maxGasPerPredicate),
|
3717
|
+
maxMessageDataLength: (0, import_math17.bn)(predicateParams.maxMessageDataLength)
|
3734
3718
|
},
|
3735
3719
|
scriptParameters: {
|
3736
3720
|
version: scriptParams.version,
|
3737
|
-
maxScriptLength: (0,
|
3738
|
-
maxScriptDataLength: (0,
|
3721
|
+
maxScriptLength: (0, import_math17.bn)(scriptParams.maxScriptLength),
|
3722
|
+
maxScriptDataLength: (0, import_math17.bn)(scriptParams.maxScriptDataLength)
|
3739
3723
|
},
|
3740
3724
|
gasCosts
|
3741
3725
|
},
|
3742
3726
|
latestBlock: {
|
3743
3727
|
id: latestBlock.id,
|
3744
|
-
height: (0,
|
3728
|
+
height: (0, import_math17.bn)(latestBlock.height),
|
3745
3729
|
time: latestBlock.header.time,
|
3746
3730
|
transactions: latestBlock.transactions.map((i) => ({
|
3747
3731
|
id: i.id
|
@@ -3937,7 +3921,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
3937
3921
|
*/
|
3938
3922
|
async getBlockNumber() {
|
3939
3923
|
const { chain } = await this.operations.getChain();
|
3940
|
-
return (0,
|
3924
|
+
return (0, import_math17.bn)(chain.latestBlock.height, 10);
|
3941
3925
|
}
|
3942
3926
|
/**
|
3943
3927
|
* Returns the chain information.
|
@@ -3947,8 +3931,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
3947
3931
|
async fetchNode() {
|
3948
3932
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3949
3933
|
const processedNodeInfo = {
|
3950
|
-
maxDepth: (0,
|
3951
|
-
maxTx: (0,
|
3934
|
+
maxDepth: (0, import_math17.bn)(nodeInfo.maxDepth),
|
3935
|
+
maxTx: (0, import_math17.bn)(nodeInfo.maxTx),
|
3952
3936
|
nodeVersion: nodeInfo.nodeVersion,
|
3953
3937
|
utxoValidation: nodeInfo.utxoValidation,
|
3954
3938
|
vmBacktrace: nodeInfo.vmBacktrace
|
@@ -4004,7 +3988,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4004
3988
|
if (estimateTxDependencies) {
|
4005
3989
|
await this.estimateTxDependencies(transactionRequest);
|
4006
3990
|
}
|
4007
|
-
const encodedTransaction = (0,
|
3991
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4008
3992
|
let abis;
|
4009
3993
|
if (transactionRequest.type === import_transactions20.TransactionType.Script) {
|
4010
3994
|
abis = transactionRequest.abis;
|
@@ -4047,7 +4031,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4047
4031
|
if (estimateTxDependencies) {
|
4048
4032
|
return this.estimateTxDependencies(transactionRequest);
|
4049
4033
|
}
|
4050
|
-
const encodedTransaction = (0,
|
4034
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4051
4035
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4052
4036
|
encodedTransactions: encodedTransaction,
|
4053
4037
|
utxoValidation: utxoValidation || false
|
@@ -4065,13 +4049,13 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4065
4049
|
async estimatePredicates(transactionRequest) {
|
4066
4050
|
const shouldEstimatePredicates = Boolean(
|
4067
4051
|
transactionRequest.inputs.find(
|
4068
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
4052
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math17.BN(input.predicateGasUsed).isZero()
|
4069
4053
|
)
|
4070
4054
|
);
|
4071
4055
|
if (!shouldEstimatePredicates) {
|
4072
4056
|
return transactionRequest;
|
4073
4057
|
}
|
4074
|
-
const encodedTransaction = (0,
|
4058
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4075
4059
|
const response = await this.operations.estimatePredicates({
|
4076
4060
|
encodedTransaction
|
4077
4061
|
});
|
@@ -4080,7 +4064,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4080
4064
|
} = response;
|
4081
4065
|
if (inputs) {
|
4082
4066
|
inputs.forEach((input, index) => {
|
4083
|
-
if ("predicateGasUsed" in input && (0,
|
4067
|
+
if ("predicateGasUsed" in input && (0, import_math17.bn)(input.predicateGasUsed).gt(0)) {
|
4084
4068
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4085
4069
|
}
|
4086
4070
|
});
|
@@ -4113,7 +4097,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4113
4097
|
const {
|
4114
4098
|
dryRun: [{ receipts: rawReceipts, status }]
|
4115
4099
|
} = await this.operations.dryRun({
|
4116
|
-
encodedTransactions: [(0,
|
4100
|
+
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
4117
4101
|
utxoValidation: false
|
4118
4102
|
});
|
4119
4103
|
receipts = rawReceipts.map(processGqlReceipt);
|
@@ -4163,7 +4147,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4163
4147
|
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4164
4148
|
allRequests.forEach((req, index) => {
|
4165
4149
|
if (req.type === import_transactions20.TransactionType.Script) {
|
4166
|
-
serializedTransactionsMap.set(index, (0,
|
4150
|
+
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4167
4151
|
}
|
4168
4152
|
});
|
4169
4153
|
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
@@ -4199,7 +4183,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4199
4183
|
transactionRequest: request
|
4200
4184
|
});
|
4201
4185
|
request.maxFee = maxFee;
|
4202
|
-
serializedTransactionsMap.set(requestIdx, (0,
|
4186
|
+
serializedTransactionsMap.set(requestIdx, (0, import_utils22.hexlify)(request.toTransactionBytes()));
|
4203
4187
|
nextRoundTransactions.push(requestIdx);
|
4204
4188
|
}
|
4205
4189
|
}
|
@@ -4212,7 +4196,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4212
4196
|
if (estimateTxDependencies) {
|
4213
4197
|
return this.estimateMultipleTxDependencies(transactionRequests);
|
4214
4198
|
}
|
4215
|
-
const encodedTransactions = transactionRequests.map((tx) => (0,
|
4199
|
+
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4216
4200
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4217
4201
|
encodedTransactions,
|
4218
4202
|
utxoValidation: utxoValidation || false
|
@@ -4238,12 +4222,12 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4238
4222
|
gasPrice = await this.estimateGasPrice(10);
|
4239
4223
|
}
|
4240
4224
|
const minFee = calculateGasFee({
|
4241
|
-
gasPrice: (0,
|
4225
|
+
gasPrice: (0, import_math17.bn)(gasPrice),
|
4242
4226
|
gas: minGas,
|
4243
4227
|
priceFactor: gasPriceFactor,
|
4244
4228
|
tip: transactionRequest.tip
|
4245
4229
|
}).add(1);
|
4246
|
-
let gasLimit = (0,
|
4230
|
+
let gasLimit = (0, import_math17.bn)(0);
|
4247
4231
|
if (transactionRequest.type === import_transactions20.TransactionType.Script) {
|
4248
4232
|
gasLimit = transactionRequest.gasLimit;
|
4249
4233
|
if (transactionRequest.gasLimit.eq(0)) {
|
@@ -4256,7 +4240,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4256
4240
|
}
|
4257
4241
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4258
4242
|
const maxFee = calculateGasFee({
|
4259
|
-
gasPrice: (0,
|
4243
|
+
gasPrice: (0, import_math17.bn)(gasPrice),
|
4260
4244
|
gas: maxGas,
|
4261
4245
|
priceFactor: gasPriceFactor,
|
4262
4246
|
tip: transactionRequest.tip
|
@@ -4285,7 +4269,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4285
4269
|
if (estimateTxDependencies) {
|
4286
4270
|
return this.estimateTxDependencies(transactionRequest);
|
4287
4271
|
}
|
4288
|
-
const encodedTransactions = [(0,
|
4272
|
+
const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
|
4289
4273
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4290
4274
|
encodedTransactions,
|
4291
4275
|
utxoValidation: true
|
@@ -4321,7 +4305,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4321
4305
|
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
4322
4306
|
txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
|
4323
4307
|
if (isScriptTransaction) {
|
4324
|
-
txRequestClone.gasLimit = (0,
|
4308
|
+
txRequestClone.gasLimit = (0, import_math17.bn)(0);
|
4325
4309
|
}
|
4326
4310
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4327
4311
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
@@ -4342,7 +4326,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4342
4326
|
let dryRunStatus;
|
4343
4327
|
let missingContractIds = [];
|
4344
4328
|
let outputVariables = 0;
|
4345
|
-
let gasUsed = (0,
|
4329
|
+
let gasUsed = (0, import_math17.bn)(0);
|
4346
4330
|
txRequestClone.maxFee = maxFee;
|
4347
4331
|
if (isScriptTransaction) {
|
4348
4332
|
txRequestClone.gasLimit = gasLimit;
|
@@ -4401,16 +4385,16 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4401
4385
|
const result = await this.operations.getCoins({
|
4402
4386
|
first: 10,
|
4403
4387
|
...paginationArgs,
|
4404
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4388
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
|
4405
4389
|
});
|
4406
4390
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4407
4391
|
return coins.map((coin) => ({
|
4408
4392
|
id: coin.utxoId,
|
4409
4393
|
assetId: coin.assetId,
|
4410
|
-
amount: (0,
|
4394
|
+
amount: (0, import_math17.bn)(coin.amount),
|
4411
4395
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4412
|
-
blockCreated: (0,
|
4413
|
-
txCreatedIdx: (0,
|
4396
|
+
blockCreated: (0, import_math17.bn)(coin.blockCreated),
|
4397
|
+
txCreatedIdx: (0, import_math17.bn)(coin.txCreatedIdx)
|
4414
4398
|
}));
|
4415
4399
|
}
|
4416
4400
|
/**
|
@@ -4424,19 +4408,19 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4424
4408
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4425
4409
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4426
4410
|
const excludeInput = {
|
4427
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4428
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4411
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
|
4412
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
|
4429
4413
|
};
|
4430
4414
|
if (this.cache) {
|
4431
4415
|
const uniqueUtxos = new Set(
|
4432
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4416
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
|
4433
4417
|
);
|
4434
4418
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4435
4419
|
}
|
4436
4420
|
const coinsQuery = {
|
4437
4421
|
owner: ownerAddress.toB256(),
|
4438
4422
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4439
|
-
assetId: (0,
|
4423
|
+
assetId: (0, import_utils22.hexlify)(assetId),
|
4440
4424
|
amount: amount.toString(10),
|
4441
4425
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4442
4426
|
})),
|
@@ -4447,9 +4431,9 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4447
4431
|
switch (coin.type) {
|
4448
4432
|
case "MessageCoin":
|
4449
4433
|
return {
|
4450
|
-
amount: (0,
|
4434
|
+
amount: (0, import_math17.bn)(coin.amount),
|
4451
4435
|
assetId: coin.assetId,
|
4452
|
-
daHeight: (0,
|
4436
|
+
daHeight: (0, import_math17.bn)(coin.daHeight),
|
4453
4437
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4454
4438
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4455
4439
|
nonce: coin.nonce
|
@@ -4457,11 +4441,11 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4457
4441
|
case "Coin":
|
4458
4442
|
return {
|
4459
4443
|
id: coin.utxoId,
|
4460
|
-
amount: (0,
|
4444
|
+
amount: (0, import_math17.bn)(coin.amount),
|
4461
4445
|
assetId: coin.assetId,
|
4462
4446
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4463
|
-
blockCreated: (0,
|
4464
|
-
txCreatedIdx: (0,
|
4447
|
+
blockCreated: (0, import_math17.bn)(coin.blockCreated),
|
4448
|
+
txCreatedIdx: (0, import_math17.bn)(coin.txCreatedIdx)
|
4465
4449
|
};
|
4466
4450
|
default:
|
4467
4451
|
return null;
|
@@ -4478,13 +4462,13 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4478
4462
|
async getBlock(idOrHeight) {
|
4479
4463
|
let variables;
|
4480
4464
|
if (typeof idOrHeight === "number") {
|
4481
|
-
variables = { height: (0,
|
4465
|
+
variables = { height: (0, import_math17.bn)(idOrHeight).toString(10) };
|
4482
4466
|
} else if (idOrHeight === "latest") {
|
4483
4467
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4484
4468
|
} else if (idOrHeight.length === 66) {
|
4485
4469
|
variables = { blockId: idOrHeight };
|
4486
4470
|
} else {
|
4487
|
-
variables = { blockId: (0,
|
4471
|
+
variables = { blockId: (0, import_math17.bn)(idOrHeight).toString(10) };
|
4488
4472
|
}
|
4489
4473
|
const { block } = await this.operations.getBlock(variables);
|
4490
4474
|
if (!block) {
|
@@ -4492,7 +4476,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4492
4476
|
}
|
4493
4477
|
return {
|
4494
4478
|
id: block.id,
|
4495
|
-
height: (0,
|
4479
|
+
height: (0, import_math17.bn)(block.height),
|
4496
4480
|
time: block.header.time,
|
4497
4481
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4498
4482
|
};
|
@@ -4507,7 +4491,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4507
4491
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4508
4492
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4509
4493
|
id: block.id,
|
4510
|
-
height: (0,
|
4494
|
+
height: (0, import_math17.bn)(block.height),
|
4511
4495
|
time: block.header.time,
|
4512
4496
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4513
4497
|
}));
|
@@ -4522,7 +4506,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4522
4506
|
async getBlockWithTransactions(idOrHeight) {
|
4523
4507
|
let variables;
|
4524
4508
|
if (typeof idOrHeight === "number") {
|
4525
|
-
variables = { blockHeight: (0,
|
4509
|
+
variables = { blockHeight: (0, import_math17.bn)(idOrHeight).toString(10) };
|
4526
4510
|
} else if (idOrHeight === "latest") {
|
4527
4511
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4528
4512
|
} else {
|
@@ -4534,11 +4518,11 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4534
4518
|
}
|
4535
4519
|
return {
|
4536
4520
|
id: block.id,
|
4537
|
-
height: (0,
|
4521
|
+
height: (0, import_math17.bn)(block.height, 10),
|
4538
4522
|
time: block.header.time,
|
4539
4523
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4540
4524
|
transactions: block.transactions.map(
|
4541
|
-
(tx) => new import_transactions20.TransactionCoder().decode((0,
|
4525
|
+
(tx) => new import_transactions20.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
|
4542
4526
|
)
|
4543
4527
|
};
|
4544
4528
|
}
|
@@ -4554,7 +4538,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4554
4538
|
return null;
|
4555
4539
|
}
|
4556
4540
|
return new import_transactions20.TransactionCoder().decode(
|
4557
|
-
(0,
|
4541
|
+
(0, import_utils22.arrayify)(transaction.rawPayload),
|
4558
4542
|
0
|
4559
4543
|
)?.[0];
|
4560
4544
|
}
|
@@ -4581,9 +4565,9 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4581
4565
|
async getContractBalance(contractId, assetId) {
|
4582
4566
|
const { contractBalance } = await this.operations.getContractBalance({
|
4583
4567
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4584
|
-
asset: (0,
|
4568
|
+
asset: (0, import_utils22.hexlify)(assetId)
|
4585
4569
|
});
|
4586
|
-
return (0,
|
4570
|
+
return (0, import_math17.bn)(contractBalance.amount, 10);
|
4587
4571
|
}
|
4588
4572
|
/**
|
4589
4573
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4595,9 +4579,9 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4595
4579
|
async getBalance(owner, assetId) {
|
4596
4580
|
const { balance } = await this.operations.getBalance({
|
4597
4581
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4598
|
-
assetId: (0,
|
4582
|
+
assetId: (0, import_utils22.hexlify)(assetId)
|
4599
4583
|
});
|
4600
|
-
return (0,
|
4584
|
+
return (0, import_math17.bn)(balance.amount, 10);
|
4601
4585
|
}
|
4602
4586
|
/**
|
4603
4587
|
* Returns balances for the given owner.
|
@@ -4615,7 +4599,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4615
4599
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4616
4600
|
return balances.map((balance) => ({
|
4617
4601
|
assetId: balance.assetId,
|
4618
|
-
amount: (0,
|
4602
|
+
amount: (0, import_math17.bn)(balance.amount)
|
4619
4603
|
}));
|
4620
4604
|
}
|
4621
4605
|
/**
|
@@ -4637,15 +4621,15 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4637
4621
|
sender: message.sender,
|
4638
4622
|
recipient: message.recipient,
|
4639
4623
|
nonce: message.nonce,
|
4640
|
-
amount: (0,
|
4624
|
+
amount: (0, import_math17.bn)(message.amount),
|
4641
4625
|
data: message.data
|
4642
4626
|
}),
|
4643
4627
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4644
4628
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4645
4629
|
nonce: message.nonce,
|
4646
|
-
amount: (0,
|
4630
|
+
amount: (0, import_math17.bn)(message.amount),
|
4647
4631
|
data: import_transactions20.InputMessageCoder.decodeData(message.data),
|
4648
|
-
daHeight: (0,
|
4632
|
+
daHeight: (0, import_math17.bn)(message.daHeight)
|
4649
4633
|
}));
|
4650
4634
|
}
|
4651
4635
|
/**
|
@@ -4698,19 +4682,19 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4698
4682
|
} = result.messageProof;
|
4699
4683
|
return {
|
4700
4684
|
messageProof: {
|
4701
|
-
proofIndex: (0,
|
4685
|
+
proofIndex: (0, import_math17.bn)(messageProof.proofIndex),
|
4702
4686
|
proofSet: messageProof.proofSet
|
4703
4687
|
},
|
4704
4688
|
blockProof: {
|
4705
|
-
proofIndex: (0,
|
4689
|
+
proofIndex: (0, import_math17.bn)(blockProof.proofIndex),
|
4706
4690
|
proofSet: blockProof.proofSet
|
4707
4691
|
},
|
4708
4692
|
messageBlockHeader: {
|
4709
4693
|
id: messageBlockHeader.id,
|
4710
|
-
daHeight: (0,
|
4694
|
+
daHeight: (0, import_math17.bn)(messageBlockHeader.daHeight),
|
4711
4695
|
transactionsCount: Number(messageBlockHeader.transactionsCount),
|
4712
4696
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4713
|
-
height: (0,
|
4697
|
+
height: (0, import_math17.bn)(messageBlockHeader.height),
|
4714
4698
|
prevRoot: messageBlockHeader.prevRoot,
|
4715
4699
|
time: messageBlockHeader.time,
|
4716
4700
|
applicationHash: messageBlockHeader.applicationHash,
|
@@ -4722,10 +4706,10 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4722
4706
|
},
|
4723
4707
|
commitBlockHeader: {
|
4724
4708
|
id: commitBlockHeader.id,
|
4725
|
-
daHeight: (0,
|
4709
|
+
daHeight: (0, import_math17.bn)(commitBlockHeader.daHeight),
|
4726
4710
|
transactionsCount: Number(commitBlockHeader.transactionsCount),
|
4727
4711
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4728
|
-
height: (0,
|
4712
|
+
height: (0, import_math17.bn)(commitBlockHeader.height),
|
4729
4713
|
prevRoot: commitBlockHeader.prevRoot,
|
4730
4714
|
time: commitBlockHeader.time,
|
4731
4715
|
applicationHash: commitBlockHeader.applicationHash,
|
@@ -4738,19 +4722,19 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4738
4722
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4739
4723
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4740
4724
|
nonce,
|
4741
|
-
amount: (0,
|
4725
|
+
amount: (0, import_math17.bn)(amount),
|
4742
4726
|
data
|
4743
4727
|
};
|
4744
4728
|
}
|
4745
4729
|
async getLatestGasPrice() {
|
4746
4730
|
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4747
|
-
return (0,
|
4731
|
+
return (0, import_math17.bn)(latestGasPrice.gasPrice);
|
4748
4732
|
}
|
4749
4733
|
async estimateGasPrice(blockHorizon) {
|
4750
4734
|
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4751
4735
|
blockHorizon: String(blockHorizon)
|
4752
4736
|
});
|
4753
|
-
return (0,
|
4737
|
+
return (0, import_math17.bn)(estimateGasPrice.gasPrice);
|
4754
4738
|
}
|
4755
4739
|
/**
|
4756
4740
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
@@ -4771,10 +4755,10 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4771
4755
|
*/
|
4772
4756
|
async produceBlocks(amount, startTime) {
|
4773
4757
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4774
|
-
blocksToProduce: (0,
|
4775
|
-
startTimestamp: startTime ?
|
4758
|
+
blocksToProduce: (0, import_math17.bn)(amount).toString(10),
|
4759
|
+
startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4776
4760
|
});
|
4777
|
-
return (0,
|
4761
|
+
return (0, import_math17.bn)(latestBlockHeight);
|
4778
4762
|
}
|
4779
4763
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4780
4764
|
async getTransactionResponse(transactionId) {
|
@@ -4820,9 +4804,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4820
4804
|
|
4821
4805
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4822
4806
|
var import_errors15 = require("@fuel-ts/errors");
|
4823
|
-
var
|
4807
|
+
var import_math18 = require("@fuel-ts/math");
|
4824
4808
|
var import_transactions21 = require("@fuel-ts/transactions");
|
4825
|
-
var
|
4809
|
+
var import_utils25 = require("@fuel-ts/utils");
|
4826
4810
|
|
4827
4811
|
// src/providers/chains.ts
|
4828
4812
|
var CHAIN_IDS = {
|
@@ -4897,17 +4881,17 @@ var assets = resolveIconPaths(rawAssets, fuelAssetsBaseUrl);
|
|
4897
4881
|
|
4898
4882
|
// src/utils/formatTransferToContractScriptData.ts
|
4899
4883
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4900
|
-
var
|
4901
|
-
var
|
4884
|
+
var import_math19 = require("@fuel-ts/math");
|
4885
|
+
var import_utils27 = require("@fuel-ts/utils");
|
4902
4886
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4903
4887
|
var formatTransferToContractScriptData = (params) => {
|
4904
4888
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4905
4889
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4906
|
-
const encoded = numberCoder.encode(new
|
4890
|
+
const encoded = numberCoder.encode(new import_math19.BN(amountToTransfer).toNumber());
|
4907
4891
|
const scriptData = Uint8Array.from([
|
4908
|
-
...(0,
|
4892
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
4909
4893
|
...encoded,
|
4910
|
-
...(0,
|
4894
|
+
...(0, import_utils27.arrayify)(assetId)
|
4911
4895
|
]);
|
4912
4896
|
return scriptData;
|
4913
4897
|
};
|
@@ -5098,9 +5082,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5098
5082
|
const { addedSignatures, estimatedPredicates, requiredQuantities, updateMaxFee } = params;
|
5099
5083
|
const fee = request.maxFee;
|
5100
5084
|
const baseAssetId = this.provider.getBaseAssetId();
|
5101
|
-
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0,
|
5085
|
+
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math20.bn)(0);
|
5102
5086
|
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5103
|
-
amount: (0,
|
5087
|
+
amount: (0, import_math20.bn)(fee),
|
5104
5088
|
assetId: baseAssetId,
|
5105
5089
|
coinQuantities: requiredQuantities
|
5106
5090
|
});
|
@@ -5108,7 +5092,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5108
5092
|
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
5109
5093
|
quantitiesDict[assetId] = {
|
5110
5094
|
required: amount,
|
5111
|
-
owned: (0,
|
5095
|
+
owned: (0, import_math20.bn)(0)
|
5112
5096
|
};
|
5113
5097
|
});
|
5114
5098
|
request.inputs.filter(isRequestInputResource).forEach((input) => {
|
@@ -5135,7 +5119,6 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5135
5119
|
cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
|
5136
5120
|
);
|
5137
5121
|
request.addResources(resources);
|
5138
|
-
request.shiftPredicateData();
|
5139
5122
|
request.updatePredicateGasUsed(estimatedPredicates);
|
5140
5123
|
const requestToReestimate2 = (0, import_ramda4.clone)(request);
|
5141
5124
|
if (addedSignatures) {
|
@@ -5167,7 +5150,6 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5167
5150
|
}
|
5168
5151
|
fundingAttempts += 1;
|
5169
5152
|
}
|
5170
|
-
request.shiftPredicateData();
|
5171
5153
|
request.updatePredicateGasUsed(estimatedPredicates);
|
5172
5154
|
const requestToReestimate = (0, import_ramda4.clone)(request);
|
5173
5155
|
if (addedSignatures) {
|
@@ -5218,7 +5200,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5218
5200
|
* @returns A promise that resolves to the transaction response.
|
5219
5201
|
*/
|
5220
5202
|
async transfer(destination, amount, assetId, txParams = {}) {
|
5221
|
-
if ((0,
|
5203
|
+
if ((0, import_math20.bn)(amount).lte(0)) {
|
5222
5204
|
throw new import_errors16.FuelError(
|
5223
5205
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5224
5206
|
"Transfer amount must be a positive number."
|
@@ -5238,7 +5220,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5238
5220
|
* @returns A promise that resolves to the transaction response.
|
5239
5221
|
*/
|
5240
5222
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5241
|
-
if ((0,
|
5223
|
+
if ((0, import_math20.bn)(amount).lte(0)) {
|
5242
5224
|
throw new import_errors16.FuelError(
|
5243
5225
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5244
5226
|
"Transfer amount must be a positive number."
|
@@ -5248,7 +5230,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5248
5230
|
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5249
5231
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5250
5232
|
hexlifiedContractId: contractAddress.toB256(),
|
5251
|
-
amountToTransfer: (0,
|
5233
|
+
amountToTransfer: (0, import_math20.bn)(amount),
|
5252
5234
|
assetId: assetIdToTransfer
|
5253
5235
|
});
|
5254
5236
|
let request = new ScriptTransactionRequest({
|
@@ -5259,7 +5241,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5259
5241
|
request.addContractInputAndOutput(contractAddress);
|
5260
5242
|
const txCost = await this.provider.getTransactionCost(request, {
|
5261
5243
|
resourcesOwner: this,
|
5262
|
-
quantitiesToContract: [{ amount: (0,
|
5244
|
+
quantitiesToContract: [{ amount: (0, import_math20.bn)(amount), assetId: String(assetIdToTransfer) }]
|
5263
5245
|
});
|
5264
5246
|
request = this.validateGasLimitAndMaxFee({
|
5265
5247
|
transactionRequest: request,
|
@@ -5280,21 +5262,21 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5280
5262
|
*/
|
5281
5263
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5282
5264
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5283
|
-
const recipientDataArray = (0,
|
5265
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
5284
5266
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5285
5267
|
);
|
5286
|
-
const amountDataArray = (0,
|
5287
|
-
"0x".concat((0,
|
5268
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
5269
|
+
"0x".concat((0, import_math20.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5288
5270
|
);
|
5289
5271
|
const script = new Uint8Array([
|
5290
|
-
...(0,
|
5272
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
5291
5273
|
...recipientDataArray,
|
5292
5274
|
...amountDataArray
|
5293
5275
|
]);
|
5294
5276
|
const params = { script, ...txParams };
|
5295
5277
|
const baseAssetId = this.provider.getBaseAssetId();
|
5296
5278
|
let request = new ScriptTransactionRequest(params);
|
5297
|
-
const quantitiesToContract = [{ amount: (0,
|
5279
|
+
const quantitiesToContract = [{ amount: (0, import_math20.bn)(amount), assetId: baseAssetId }];
|
5298
5280
|
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5299
5281
|
request = this.validateGasLimitAndMaxFee({
|
5300
5282
|
transactionRequest: request,
|
@@ -5367,7 +5349,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5367
5349
|
txParams: { gasLimit: setGasLimit, maxFee: setMaxFee }
|
5368
5350
|
}) {
|
5369
5351
|
const request = transactionRequestify(transactionRequest);
|
5370
|
-
if (!(0,
|
5352
|
+
if (!(0, import_utils28.isDefined)(setGasLimit)) {
|
5371
5353
|
request.gasLimit = gasUsed;
|
5372
5354
|
} else if (gasUsed.gt(setGasLimit)) {
|
5373
5355
|
throw new import_errors16.FuelError(
|
@@ -5375,7 +5357,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5375
5357
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
5376
5358
|
);
|
5377
5359
|
}
|
5378
|
-
if (!(0,
|
5360
|
+
if (!(0, import_utils28.isDefined)(setMaxFee)) {
|
5379
5361
|
request.maxFee = maxFee;
|
5380
5362
|
} else if (maxFee.gt(setMaxFee)) {
|
5381
5363
|
throw new import_errors16.FuelError(
|
@@ -5391,8 +5373,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5391
5373
|
var import_address5 = require("@fuel-ts/address");
|
5392
5374
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5393
5375
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5394
|
-
var
|
5395
|
-
var
|
5376
|
+
var import_math21 = require("@fuel-ts/math");
|
5377
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5396
5378
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5397
5379
|
var Signer = class {
|
5398
5380
|
address;
|
@@ -5411,10 +5393,10 @@ var Signer = class {
|
|
5411
5393
|
privateKey = `0x${privateKey}`;
|
5412
5394
|
}
|
5413
5395
|
}
|
5414
|
-
const privateKeyBytes = (0,
|
5415
|
-
this.privateKey = (0,
|
5416
|
-
this.publicKey = (0,
|
5417
|
-
this.compressedPublicKey = (0,
|
5396
|
+
const privateKeyBytes = (0, import_math21.toBytes)(privateKey, 32);
|
5397
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
5398
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5399
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5418
5400
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5419
5401
|
}
|
5420
5402
|
/**
|
@@ -5428,11 +5410,11 @@ var Signer = class {
|
|
5428
5410
|
* @returns hashed signature
|
5429
5411
|
*/
|
5430
5412
|
sign(data) {
|
5431
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5432
|
-
const r = (0,
|
5433
|
-
const s = (0,
|
5413
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
5414
|
+
const r = (0, import_math21.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5415
|
+
const s = (0, import_math21.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5434
5416
|
s[0] |= (signature.recovery || 0) << 7;
|
5435
|
-
return (0,
|
5417
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
5436
5418
|
}
|
5437
5419
|
/**
|
5438
5420
|
* Add point on the current elliptic curve
|
@@ -5441,8 +5423,8 @@ var Signer = class {
|
|
5441
5423
|
* @returns compressed point on the curve
|
5442
5424
|
*/
|
5443
5425
|
addPoint(point) {
|
5444
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5445
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5426
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
5427
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
5446
5428
|
const result = p0.add(p1);
|
5447
5429
|
return `0x${result.toHex(true)}`;
|
5448
5430
|
}
|
@@ -5454,16 +5436,16 @@ var Signer = class {
|
|
5454
5436
|
* @returns public key from signature from the
|
5455
5437
|
*/
|
5456
5438
|
static recoverPublicKey(data, signature) {
|
5457
|
-
const signedMessageBytes = (0,
|
5439
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
5458
5440
|
const r = signedMessageBytes.slice(0, 32);
|
5459
5441
|
const s = signedMessageBytes.slice(32, 64);
|
5460
5442
|
const recoveryParam = (s[0] & 128) >> 7;
|
5461
5443
|
s[0] &= 127;
|
5462
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5444
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
5463
5445
|
recoveryParam
|
5464
5446
|
);
|
5465
|
-
const publicKey = sig.recoverPublicKey((0,
|
5466
|
-
return (0,
|
5447
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
5448
|
+
return (0, import_utils29.hexlify)(publicKey);
|
5467
5449
|
}
|
5468
5450
|
/**
|
5469
5451
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5482,7 +5464,7 @@ var Signer = class {
|
|
5482
5464
|
* @returns random 32-byte hashed
|
5483
5465
|
*/
|
5484
5466
|
static generatePrivateKey(entropy) {
|
5485
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5467
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
|
5486
5468
|
}
|
5487
5469
|
/**
|
5488
5470
|
* Extended publicKey from a compact publicKey
|
@@ -5491,8 +5473,8 @@ var Signer = class {
|
|
5491
5473
|
* @returns extended publicKey
|
5492
5474
|
*/
|
5493
5475
|
static extendPublicKey(publicKey) {
|
5494
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5495
|
-
return (0,
|
5476
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
5477
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
5496
5478
|
}
|
5497
5479
|
};
|
5498
5480
|
|
@@ -5500,7 +5482,7 @@ var Signer = class {
|
|
5500
5482
|
var import_address6 = require("@fuel-ts/address");
|
5501
5483
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5502
5484
|
var import_errors17 = require("@fuel-ts/errors");
|
5503
|
-
var
|
5485
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5504
5486
|
var import_uuid = require("uuid");
|
5505
5487
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5506
5488
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5583,7 +5565,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5583
5565
|
);
|
5584
5566
|
}
|
5585
5567
|
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5586
|
-
const privateKey = (0,
|
5568
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5587
5569
|
return privateKey;
|
5588
5570
|
}
|
5589
5571
|
|
@@ -5628,7 +5610,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5628
5610
|
*/
|
5629
5611
|
async signMessage(message) {
|
5630
5612
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5631
|
-
return (0,
|
5613
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5632
5614
|
}
|
5633
5615
|
/**
|
5634
5616
|
* Signs a transaction with the wallet's private key.
|
@@ -5641,7 +5623,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5641
5623
|
const chainId = this.provider.getChainId();
|
5642
5624
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5643
5625
|
const signature = await this.signer().sign(hashedTransaction);
|
5644
|
-
return (0,
|
5626
|
+
return (0, import_utils31.hexlify)(signature);
|
5645
5627
|
}
|
5646
5628
|
/**
|
5647
5629
|
* Populates a transaction with the witnesses signature.
|
@@ -5703,14 +5685,14 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5703
5685
|
var import_crypto5 = require("@fuel-ts/crypto");
|
5704
5686
|
var import_errors20 = require("@fuel-ts/errors");
|
5705
5687
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5706
|
-
var
|
5707
|
-
var
|
5688
|
+
var import_math22 = require("@fuel-ts/math");
|
5689
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5708
5690
|
|
5709
5691
|
// src/mnemonic/mnemonic.ts
|
5710
5692
|
var import_crypto4 = require("@fuel-ts/crypto");
|
5711
5693
|
var import_errors19 = require("@fuel-ts/errors");
|
5712
5694
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5713
|
-
var
|
5695
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5714
5696
|
|
5715
5697
|
// src/wordlists/words/english.ts
|
5716
5698
|
var english = [
|
@@ -7767,7 +7749,7 @@ var english = [
|
|
7767
7749
|
// src/mnemonic/utils.ts
|
7768
7750
|
var import_errors18 = require("@fuel-ts/errors");
|
7769
7751
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7770
|
-
var
|
7752
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7771
7753
|
function toUtf8Bytes(stri) {
|
7772
7754
|
const str = stri.normalize("NFKD");
|
7773
7755
|
const result = [];
|
@@ -7834,14 +7816,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7834
7816
|
}
|
7835
7817
|
}
|
7836
7818
|
const checksumBits = entropy.length / 4;
|
7837
|
-
const checksum = (0,
|
7819
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7838
7820
|
indices[indices.length - 1] <<= checksumBits;
|
7839
7821
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7840
7822
|
return indices;
|
7841
7823
|
}
|
7842
7824
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7843
7825
|
const size = Math.ceil(11 * words.length / 8);
|
7844
|
-
const entropy = (0,
|
7826
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
7845
7827
|
let offset = 0;
|
7846
7828
|
for (let i = 0; i < words.length; i += 1) {
|
7847
7829
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7861,7 +7843,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7861
7843
|
const entropyBits = 32 * words.length / 3;
|
7862
7844
|
const checksumBits = words.length / 3;
|
7863
7845
|
const checksumMask = getUpperMask(checksumBits);
|
7864
|
-
const checksum = (0,
|
7846
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7865
7847
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7866
7848
|
throw new import_errors18.FuelError(
|
7867
7849
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7936,7 +7918,7 @@ var Mnemonic = class {
|
|
7936
7918
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7937
7919
|
const words = getWords(phrase);
|
7938
7920
|
assertMnemonic(words);
|
7939
|
-
return (0,
|
7921
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7940
7922
|
}
|
7941
7923
|
/**
|
7942
7924
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7944,7 +7926,7 @@ var Mnemonic = class {
|
|
7944
7926
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7945
7927
|
*/
|
7946
7928
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7947
|
-
const entropyBytes = (0,
|
7929
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
7948
7930
|
assertWordList(wordlist);
|
7949
7931
|
assertEntropy(entropyBytes);
|
7950
7932
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -8013,14 +7995,14 @@ var Mnemonic = class {
|
|
8013
7995
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8014
7996
|
*/
|
8015
7997
|
static masterKeysFromSeed(seed) {
|
8016
|
-
const seedArray = (0,
|
7998
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
8017
7999
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
8018
8000
|
throw new import_errors19.FuelError(
|
8019
8001
|
import_errors19.ErrorCode.INVALID_SEED,
|
8020
8002
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
8021
8003
|
);
|
8022
8004
|
}
|
8023
|
-
return (0,
|
8005
|
+
return (0, import_utils33.arrayify)((0, import_crypto4.computeHmac)("sha512", MasterSecret, seedArray));
|
8024
8006
|
}
|
8025
8007
|
/**
|
8026
8008
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -8031,22 +8013,22 @@ var Mnemonic = class {
|
|
8031
8013
|
*/
|
8032
8014
|
static seedToExtendedKey(seed, testnet = false) {
|
8033
8015
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
8034
|
-
const prefix = (0,
|
8016
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
8035
8017
|
const depth = "0x00";
|
8036
8018
|
const fingerprint = "0x00000000";
|
8037
8019
|
const index = "0x00000000";
|
8038
8020
|
const chainCode = masterKey.slice(32);
|
8039
8021
|
const privateKey = masterKey.slice(0, 32);
|
8040
|
-
const extendedKey = (0,
|
8022
|
+
const extendedKey = (0, import_utils33.concat)([
|
8041
8023
|
prefix,
|
8042
8024
|
depth,
|
8043
8025
|
fingerprint,
|
8044
8026
|
index,
|
8045
8027
|
chainCode,
|
8046
|
-
(0,
|
8028
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
8047
8029
|
]);
|
8048
|
-
const checksum = (0,
|
8049
|
-
return (0,
|
8030
|
+
const checksum = (0, import_utils33.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
8031
|
+
return (0, import_utils33.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
8050
8032
|
}
|
8051
8033
|
/**
|
8052
8034
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -8061,7 +8043,7 @@ var Mnemonic = class {
|
|
8061
8043
|
* @returns A randomly generated mnemonic
|
8062
8044
|
*/
|
8063
8045
|
static generate(size = 32, extraEntropy = "") {
|
8064
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
8046
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
|
8065
8047
|
return Mnemonic.entropyToMnemonic(entropy);
|
8066
8048
|
}
|
8067
8049
|
};
|
@@ -8069,12 +8051,12 @@ var mnemonic_default = Mnemonic;
|
|
8069
8051
|
|
8070
8052
|
// src/hdwallet/hdwallet.ts
|
8071
8053
|
var HARDENED_INDEX = 2147483648;
|
8072
|
-
var MainnetPRV2 = (0,
|
8073
|
-
var MainnetPUB = (0,
|
8074
|
-
var TestnetPRV2 = (0,
|
8075
|
-
var TestnetPUB = (0,
|
8054
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
8055
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
8056
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
8057
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
8076
8058
|
function base58check(data) {
|
8077
|
-
return (0,
|
8059
|
+
return (0, import_utils35.encodeBase58)((0, import_utils35.concat)([data, (0, import_utils35.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
8078
8060
|
}
|
8079
8061
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
8080
8062
|
if (isPublic) {
|
@@ -8083,11 +8065,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8083
8065
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8084
8066
|
}
|
8085
8067
|
function isPublicExtendedKey(extendedKey) {
|
8086
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
8068
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
8087
8069
|
}
|
8088
8070
|
function isValidExtendedKey(extendedKey) {
|
8089
8071
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8090
|
-
(0,
|
8072
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
8091
8073
|
);
|
8092
8074
|
}
|
8093
8075
|
function parsePath(path2, depth = 0) {
|
@@ -8105,8 +8087,8 @@ function parsePath(path2, depth = 0) {
|
|
8105
8087
|
var HDWallet = class {
|
8106
8088
|
depth = 0;
|
8107
8089
|
index = 0;
|
8108
|
-
fingerprint = (0,
|
8109
|
-
parentFingerprint = (0,
|
8090
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
8091
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
8110
8092
|
privateKey;
|
8111
8093
|
publicKey;
|
8112
8094
|
chainCode;
|
@@ -8118,8 +8100,8 @@ var HDWallet = class {
|
|
8118
8100
|
constructor(config) {
|
8119
8101
|
if (config.privateKey) {
|
8120
8102
|
const signer = new Signer(config.privateKey);
|
8121
|
-
this.publicKey = (0,
|
8122
|
-
this.privateKey = (0,
|
8103
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
8104
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
8123
8105
|
} else {
|
8124
8106
|
if (!config.publicKey) {
|
8125
8107
|
throw new import_errors20.FuelError(
|
@@ -8127,10 +8109,10 @@ var HDWallet = class {
|
|
8127
8109
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8128
8110
|
);
|
8129
8111
|
}
|
8130
|
-
this.publicKey = (0,
|
8112
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
8131
8113
|
}
|
8132
8114
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8133
|
-
this.fingerprint = (0,
|
8115
|
+
this.fingerprint = (0, import_utils35.dataSlice)((0, import_crypto5.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
8134
8116
|
this.depth = config.depth || this.depth;
|
8135
8117
|
this.index = config.index || this.index;
|
8136
8118
|
this.chainCode = config.chainCode;
|
@@ -8146,9 +8128,9 @@ var HDWallet = class {
|
|
8146
8128
|
* @returns A new instance of HDWallet on the derived index
|
8147
8129
|
*/
|
8148
8130
|
deriveIndex(index) {
|
8149
|
-
const privateKey = this.privateKey && (0,
|
8150
|
-
const publicKey = (0,
|
8151
|
-
const chainCode = (0,
|
8131
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
8132
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
8133
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
8152
8134
|
const data = new Uint8Array(37);
|
8153
8135
|
if (index & HARDENED_INDEX) {
|
8154
8136
|
if (!privateKey) {
|
@@ -8159,15 +8141,15 @@ var HDWallet = class {
|
|
8159
8141
|
}
|
8160
8142
|
data.set(privateKey, 1);
|
8161
8143
|
} else {
|
8162
|
-
data.set((0,
|
8144
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
8163
8145
|
}
|
8164
|
-
data.set((0,
|
8165
|
-
const bytes = (0,
|
8146
|
+
data.set((0, import_math22.toBytes)(index, 4), 33);
|
8147
|
+
const bytes = (0, import_utils35.arrayify)((0, import_crypto5.computeHmac)("sha512", chainCode, data));
|
8166
8148
|
const IL = bytes.slice(0, 32);
|
8167
8149
|
const IR = bytes.slice(32);
|
8168
8150
|
if (privateKey) {
|
8169
8151
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8170
|
-
const ki = (0,
|
8152
|
+
const ki = (0, import_math22.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
8171
8153
|
return new HDWallet({
|
8172
8154
|
privateKey: ki,
|
8173
8155
|
chainCode: IR,
|
@@ -8176,7 +8158,7 @@ var HDWallet = class {
|
|
8176
8158
|
parentFingerprint: this.fingerprint
|
8177
8159
|
});
|
8178
8160
|
}
|
8179
|
-
const signer = new Signer((0,
|
8161
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
8180
8162
|
const Ki = signer.addPoint(publicKey);
|
8181
8163
|
return new HDWallet({
|
8182
8164
|
publicKey: Ki,
|
@@ -8211,12 +8193,12 @@ var HDWallet = class {
|
|
8211
8193
|
);
|
8212
8194
|
}
|
8213
8195
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8214
|
-
const depth = (0,
|
8196
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
8215
8197
|
const parentFingerprint = this.parentFingerprint;
|
8216
|
-
const index = (0,
|
8198
|
+
const index = (0, import_math22.toHex)(this.index, 4);
|
8217
8199
|
const chainCode = this.chainCode;
|
8218
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
8219
|
-
const extendedKey = (0,
|
8200
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
8201
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
8220
8202
|
return base58check(extendedKey);
|
8221
8203
|
}
|
8222
8204
|
/**
|
@@ -8228,13 +8210,13 @@ var HDWallet = class {
|
|
8228
8210
|
static fromSeed(seed) {
|
8229
8211
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8230
8212
|
return new HDWallet({
|
8231
|
-
chainCode: (0,
|
8232
|
-
privateKey: (0,
|
8213
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
8214
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
8233
8215
|
});
|
8234
8216
|
}
|
8235
8217
|
static fromExtendedKey(extendedKey) {
|
8236
|
-
const decoded = (0,
|
8237
|
-
const bytes = (0,
|
8218
|
+
const decoded = (0, import_utils35.hexlify)((0, import_math22.toBytes)((0, import_utils35.decodeBase58)(extendedKey)));
|
8219
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
8238
8220
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8239
8221
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8240
8222
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -8243,9 +8225,9 @@ var HDWallet = class {
|
|
8243
8225
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8244
8226
|
}
|
8245
8227
|
const depth = bytes[4];
|
8246
|
-
const parentFingerprint = (0,
|
8247
|
-
const index = parseInt((0,
|
8248
|
-
const chainCode = (0,
|
8228
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
8229
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8230
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
8249
8231
|
const key = bytes.slice(45, 78);
|
8250
8232
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8251
8233
|
throw new import_errors20.FuelError(
|
@@ -8464,7 +8446,7 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8464
8446
|
// src/test-utils/launchNode.ts
|
8465
8447
|
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
8466
8448
|
var import_crypto7 = require("@fuel-ts/crypto");
|
8467
|
-
var
|
8449
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8468
8450
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
8469
8451
|
var import_child_process = require("child_process");
|
8470
8452
|
var import_crypto8 = require("crypto");
|
@@ -8504,40 +8486,6 @@ var killNode = (params) => {
|
|
8504
8486
|
}
|
8505
8487
|
}
|
8506
8488
|
};
|
8507
|
-
function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
|
8508
|
-
const defaultCoins = import_utils37.defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
|
8509
|
-
...coin,
|
8510
|
-
amount: "18446744073709551615"
|
8511
|
-
}));
|
8512
|
-
const defaultMessages = import_utils37.defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
|
8513
|
-
...message,
|
8514
|
-
amount: "18446744073709551615"
|
8515
|
-
}));
|
8516
|
-
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);
|
8517
|
-
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);
|
8518
|
-
if (!process.env.GENESIS_SECRET) {
|
8519
|
-
const pk = Signer.generatePrivateKey();
|
8520
|
-
const signer = new Signer(pk);
|
8521
|
-
process.env.GENESIS_SECRET = (0, import_utils37.hexlify)(pk);
|
8522
|
-
coins.push({
|
8523
|
-
tx_id: (0, import_utils37.hexlify)((0, import_crypto7.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
|
8524
|
-
owner: signer.address.toHexString(),
|
8525
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8526
|
-
amount: "18446744073709551615",
|
8527
|
-
asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
|
8528
|
-
output_index: 0,
|
8529
|
-
tx_pointer_block_height: 0,
|
8530
|
-
tx_pointer_tx_idx: 0
|
8531
|
-
});
|
8532
|
-
}
|
8533
|
-
const json = JSON.stringify({
|
8534
|
-
...stateConfig,
|
8535
|
-
coins,
|
8536
|
-
messages
|
8537
|
-
});
|
8538
|
-
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8539
|
-
return json.replace(regexMakeNumber, "$1$2");
|
8540
|
-
}
|
8541
8489
|
var launchNode = async ({
|
8542
8490
|
ip,
|
8543
8491
|
port,
|
@@ -8545,8 +8493,7 @@ var launchNode = async ({
|
|
8545
8493
|
useSystemFuelCore = false,
|
8546
8494
|
loggingEnabled = true,
|
8547
8495
|
debugEnabled = false,
|
8548
|
-
basePath
|
8549
|
-
snapshotConfig = import_utils37.defaultSnapshotConfigs
|
8496
|
+
basePath
|
8550
8497
|
}) => (
|
8551
8498
|
// eslint-disable-next-line no-async-promise-executor
|
8552
8499
|
new Promise(async (resolve, reject) => {
|
@@ -8557,7 +8504,7 @@ var launchNode = async ({
|
|
8557
8504
|
"--poa-instant"
|
8558
8505
|
]);
|
8559
8506
|
const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
|
8560
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8507
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
|
8561
8508
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8562
8509
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
8563
8510
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -8575,23 +8522,56 @@ var launchNode = async ({
|
|
8575
8522
|
let snapshotDirToUse;
|
8576
8523
|
const prefix = basePath || import_os.default.tmpdir();
|
8577
8524
|
const suffix = basePath ? "" : (0, import_crypto8.randomUUID)();
|
8578
|
-
const
|
8525
|
+
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix, "snapshotDir");
|
8579
8526
|
if (snapshotDir) {
|
8580
8527
|
snapshotDirToUse = snapshotDir;
|
8581
8528
|
} else {
|
8582
|
-
if (!(0, import_fs.existsSync)(
|
8583
|
-
(0, import_fs.mkdirSync)(
|
8529
|
+
if (!(0, import_fs.existsSync)(tempDirPath)) {
|
8530
|
+
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
8584
8531
|
}
|
8585
|
-
|
8586
|
-
const
|
8587
|
-
|
8588
|
-
|
8589
|
-
|
8590
|
-
|
8591
|
-
|
8592
|
-
|
8593
|
-
|
8594
|
-
|
8532
|
+
let { stateConfigJson } = import_utils36.defaultSnapshotConfigs;
|
8533
|
+
const { chainConfigJson, metadataJson } = import_utils36.defaultSnapshotConfigs;
|
8534
|
+
stateConfigJson = {
|
8535
|
+
...stateConfigJson,
|
8536
|
+
coins: [
|
8537
|
+
...stateConfigJson.coins.map((coin) => ({
|
8538
|
+
...coin,
|
8539
|
+
amount: "18446744073709551615"
|
8540
|
+
}))
|
8541
|
+
],
|
8542
|
+
messages: stateConfigJson.messages.map((message) => ({
|
8543
|
+
...message,
|
8544
|
+
amount: "18446744073709551615"
|
8545
|
+
}))
|
8546
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8547
|
+
};
|
8548
|
+
if (!process.env.GENESIS_SECRET) {
|
8549
|
+
const pk = Signer.generatePrivateKey();
|
8550
|
+
const signer = new Signer(pk);
|
8551
|
+
process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
|
8552
|
+
stateConfigJson.coins.push({
|
8553
|
+
tx_id: (0, import_utils36.hexlify)((0, import_crypto7.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
|
8554
|
+
owner: signer.address.toHexString(),
|
8555
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8556
|
+
amount: "18446744073709551615",
|
8557
|
+
asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
|
8558
|
+
output_index: 0,
|
8559
|
+
tx_pointer_block_height: 0,
|
8560
|
+
tx_pointer_tx_idx: 0
|
8561
|
+
});
|
8562
|
+
}
|
8563
|
+
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8564
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8565
|
+
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8566
|
+
const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8567
|
+
const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
|
8568
|
+
const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
|
8569
|
+
const stateTransitionWritePath = import_path.default.join(tempDirPath, "state_transition_bytecode.wasm");
|
8570
|
+
(0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8571
|
+
(0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8572
|
+
(0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8573
|
+
(0, import_fs.writeFileSync)(stateTransitionWritePath, JSON.stringify(""));
|
8574
|
+
snapshotDirToUse = tempDirPath;
|
8595
8575
|
}
|
8596
8576
|
const child = (0, import_child_process.spawn)(
|
8597
8577
|
command,
|
@@ -8599,7 +8579,7 @@ var launchNode = async ({
|
|
8599
8579
|
"run",
|
8600
8580
|
["--ip", ipToUse],
|
8601
8581
|
["--port", portToUse],
|
8602
|
-
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path",
|
8582
|
+
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8603
8583
|
["--min-gas-price", "1"],
|
8604
8584
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8605
8585
|
["--consensus-key", consensusKey],
|
@@ -8621,28 +8601,23 @@ var launchNode = async ({
|
|
8621
8601
|
}
|
8622
8602
|
const cleanupConfig = {
|
8623
8603
|
child,
|
8624
|
-
configPath:
|
8604
|
+
configPath: tempDirPath,
|
8625
8605
|
killFn: import_tree_kill.default,
|
8626
8606
|
state: {
|
8627
8607
|
isDead: false
|
8628
8608
|
}
|
8629
8609
|
};
|
8630
8610
|
child.stderr.on("data", (chunk) => {
|
8631
|
-
|
8632
|
-
if (text.indexOf(graphQLStartSubstring) !== -1) {
|
8633
|
-
const rows = text.split("\n");
|
8634
|
-
const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
|
8635
|
-
const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
|
8611
|
+
if (chunk.indexOf(graphQLStartSubstring) !== -1) {
|
8636
8612
|
resolve({
|
8637
8613
|
cleanup: () => killNode(cleanupConfig),
|
8638
|
-
ip:
|
8639
|
-
port:
|
8640
|
-
url: `http://${realIp}:${realPort}/v1/graphql`,
|
8614
|
+
ip: ipToUse,
|
8615
|
+
port: portToUse,
|
8641
8616
|
snapshotDir: snapshotDirToUse
|
8642
8617
|
});
|
8643
8618
|
}
|
8644
|
-
if (/error/i.test(
|
8645
|
-
reject(
|
8619
|
+
if (/error/i.test(chunk)) {
|
8620
|
+
reject(chunk.toString());
|
8646
8621
|
}
|
8647
8622
|
});
|
8648
8623
|
process.on("exit", () => killNode(cleanupConfig));
|
@@ -8675,238 +8650,12 @@ var launchNodeAndGetWallets = async ({
|
|
8675
8650
|
};
|
8676
8651
|
return { wallets, stop: cleanup, provider };
|
8677
8652
|
};
|
8678
|
-
|
8679
|
-
// src/test-utils/setup-test-provider-and-wallets.ts
|
8680
|
-
var import_utils40 = require("@fuel-ts/utils");
|
8681
|
-
var import_ramda5 = require("ramda");
|
8682
|
-
|
8683
|
-
// src/test-utils/asset-id.ts
|
8684
|
-
var import_crypto9 = require("@fuel-ts/crypto");
|
8685
|
-
var import_utils38 = require("@fuel-ts/utils");
|
8686
|
-
var _AssetId = class {
|
8687
|
-
constructor(value) {
|
8688
|
-
this.value = value;
|
8689
|
-
}
|
8690
|
-
static random() {
|
8691
|
-
return new _AssetId((0, import_utils38.hexlify)((0, import_crypto9.randomBytes)(32)));
|
8692
|
-
}
|
8693
|
-
};
|
8694
|
-
var AssetId = _AssetId;
|
8695
|
-
__publicField(AssetId, "A", new _AssetId(
|
8696
|
-
"0x0101010101010101010101010101010101010101010101010101010101010101"
|
8697
|
-
));
|
8698
|
-
__publicField(AssetId, "B", new _AssetId(
|
8699
|
-
"0x0202020202020202020202020202020202020202020202020202020202020202"
|
8700
|
-
));
|
8701
|
-
|
8702
|
-
// src/test-utils/wallet-config.ts
|
8703
|
-
var import_crypto10 = require("@fuel-ts/crypto");
|
8704
|
-
var import_errors21 = require("@fuel-ts/errors");
|
8705
|
-
var import_utils39 = require("@fuel-ts/utils");
|
8706
|
-
var WalletConfig = class {
|
8707
|
-
initialState;
|
8708
|
-
options;
|
8709
|
-
wallets;
|
8710
|
-
generateWallets = () => {
|
8711
|
-
const generatedWallets = [];
|
8712
|
-
for (let index = 1; index <= this.options.count; index++) {
|
8713
|
-
generatedWallets.push(new WalletUnlocked((0, import_crypto10.randomBytes)(32)));
|
8714
|
-
}
|
8715
|
-
return generatedWallets;
|
8716
|
-
};
|
8717
|
-
constructor(baseAssetId, config) {
|
8718
|
-
const BASE_ASSET_ID = baseAssetId.startsWith("0x") ? baseAssetId : `0x${baseAssetId}`;
|
8719
|
-
WalletConfig.guard(config);
|
8720
|
-
this.options = config;
|
8721
|
-
const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
|
8722
|
-
this.wallets = this.generateWallets();
|
8723
|
-
this.initialState = {
|
8724
|
-
messages: WalletConfig.createMessages(this.wallets, messages),
|
8725
|
-
coins: WalletConfig.createCoins(
|
8726
|
-
this.wallets,
|
8727
|
-
BASE_ASSET_ID,
|
8728
|
-
assets2,
|
8729
|
-
coinsPerAsset,
|
8730
|
-
amountPerCoin
|
8731
|
-
)
|
8732
|
-
};
|
8733
|
-
}
|
8734
|
-
apply(snapshotConfig) {
|
8735
|
-
return {
|
8736
|
-
...snapshotConfig,
|
8737
|
-
stateConfig: {
|
8738
|
-
...snapshotConfig?.stateConfig ?? import_utils39.defaultSnapshotConfigs.stateConfig,
|
8739
|
-
coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
|
8740
|
-
messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
|
8741
|
-
}
|
8742
|
-
};
|
8743
|
-
}
|
8744
|
-
static createMessages(wallets, messages) {
|
8745
|
-
return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
|
8746
|
-
}
|
8747
|
-
static createCoins(wallets, baseAssetId, assets2, coinsPerAsset, amountPerCoin) {
|
8748
|
-
const coins = [];
|
8749
|
-
let assetIds = [baseAssetId];
|
8750
|
-
if (Array.isArray(assets2)) {
|
8751
|
-
assetIds = assetIds.concat(assets2.map((a) => a.value));
|
8752
|
-
} else {
|
8753
|
-
for (let index = 0; index < assets2 - 1; index++) {
|
8754
|
-
assetIds.push(AssetId.random().value);
|
8755
|
-
}
|
8756
|
-
}
|
8757
|
-
wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
|
8758
|
-
assetIds.forEach((assetId) => {
|
8759
|
-
for (let index = 0; index < coinsPerAsset; index++) {
|
8760
|
-
coins.push({
|
8761
|
-
amount: amountPerCoin,
|
8762
|
-
asset_id: assetId,
|
8763
|
-
owner: walletAddress,
|
8764
|
-
tx_pointer_block_height: 0,
|
8765
|
-
tx_pointer_tx_idx: 0,
|
8766
|
-
output_index: 0,
|
8767
|
-
tx_id: (0, import_utils39.hexlify)((0, import_crypto10.randomBytes)(32))
|
8768
|
-
});
|
8769
|
-
}
|
8770
|
-
});
|
8771
|
-
});
|
8772
|
-
return coins;
|
8773
|
-
}
|
8774
|
-
static guard({
|
8775
|
-
count: wallets,
|
8776
|
-
assets: assets2,
|
8777
|
-
coinsPerAsset,
|
8778
|
-
amountPerCoin
|
8779
|
-
}) {
|
8780
|
-
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
8781
|
-
throw new import_errors21.FuelError(
|
8782
|
-
import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
8783
|
-
"Number of wallets must be greater than zero."
|
8784
|
-
);
|
8785
|
-
}
|
8786
|
-
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
8787
|
-
throw new import_errors21.FuelError(
|
8788
|
-
import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
8789
|
-
"Number of assets per wallet must be greater than zero."
|
8790
|
-
);
|
8791
|
-
}
|
8792
|
-
if (coinsPerAsset <= 0) {
|
8793
|
-
throw new import_errors21.FuelError(
|
8794
|
-
import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
8795
|
-
"Number of coins per asset must be greater than zero."
|
8796
|
-
);
|
8797
|
-
}
|
8798
|
-
if (amountPerCoin <= 0) {
|
8799
|
-
throw new import_errors21.FuelError(
|
8800
|
-
import_errors21.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
8801
|
-
"Amount per coin must be greater than zero."
|
8802
|
-
);
|
8803
|
-
}
|
8804
|
-
}
|
8805
|
-
};
|
8806
|
-
|
8807
|
-
// src/test-utils/setup-test-provider-and-wallets.ts
|
8808
|
-
var defaultWalletConfigOptions = {
|
8809
|
-
count: 2,
|
8810
|
-
assets: [AssetId.A, AssetId.B],
|
8811
|
-
coinsPerAsset: 1,
|
8812
|
-
amountPerCoin: 1e10,
|
8813
|
-
messages: []
|
8814
|
-
};
|
8815
|
-
async function setupTestProviderAndWallets({
|
8816
|
-
walletConfig: walletConfigOptions = {},
|
8817
|
-
providerOptions,
|
8818
|
-
nodeOptions = {}
|
8819
|
-
} = {}) {
|
8820
|
-
Symbol.dispose ??= Symbol("Symbol.dispose");
|
8821
|
-
const walletConfig = new WalletConfig(
|
8822
|
-
nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? import_utils40.defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.base_asset_id,
|
8823
|
-
{
|
8824
|
-
...defaultWalletConfigOptions,
|
8825
|
-
...walletConfigOptions
|
8826
|
-
}
|
8827
|
-
);
|
8828
|
-
const { cleanup, url } = await launchNode({
|
8829
|
-
loggingEnabled: false,
|
8830
|
-
...nodeOptions,
|
8831
|
-
snapshotConfig: (0, import_ramda5.mergeDeepRight)(
|
8832
|
-
import_utils40.defaultSnapshotConfigs,
|
8833
|
-
walletConfig.apply(nodeOptions?.snapshotConfig)
|
8834
|
-
),
|
8835
|
-
port: "0"
|
8836
|
-
});
|
8837
|
-
let provider;
|
8838
|
-
try {
|
8839
|
-
provider = await Provider.create(url, providerOptions);
|
8840
|
-
} catch (err) {
|
8841
|
-
cleanup();
|
8842
|
-
throw err;
|
8843
|
-
}
|
8844
|
-
const wallets = walletConfig.wallets;
|
8845
|
-
wallets.forEach((wallet) => {
|
8846
|
-
wallet.connect(provider);
|
8847
|
-
});
|
8848
|
-
return {
|
8849
|
-
provider,
|
8850
|
-
wallets,
|
8851
|
-
cleanup,
|
8852
|
-
[Symbol.dispose]: cleanup
|
8853
|
-
};
|
8854
|
-
}
|
8855
|
-
|
8856
|
-
// src/test-utils/test-message.ts
|
8857
|
-
var import_address7 = require("@fuel-ts/address");
|
8858
|
-
var import_crypto11 = require("@fuel-ts/crypto");
|
8859
|
-
var import_math24 = require("@fuel-ts/math");
|
8860
|
-
var import_utils41 = require("@fuel-ts/utils");
|
8861
|
-
var TestMessage = class {
|
8862
|
-
sender;
|
8863
|
-
recipient;
|
8864
|
-
nonce;
|
8865
|
-
amount;
|
8866
|
-
data;
|
8867
|
-
da_height;
|
8868
|
-
/**
|
8869
|
-
* A helper class to create messages for testing purposes.
|
8870
|
-
*
|
8871
|
-
* Used in tandem with `WalletConfig`.
|
8872
|
-
* It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
|
8873
|
-
*/
|
8874
|
-
constructor({
|
8875
|
-
sender = import_address7.Address.fromRandom(),
|
8876
|
-
recipient = import_address7.Address.fromRandom(),
|
8877
|
-
nonce = (0, import_utils41.hexlify)((0, import_crypto11.randomBytes)(32)),
|
8878
|
-
amount = 1e6,
|
8879
|
-
data = "02",
|
8880
|
-
da_height = 0
|
8881
|
-
} = {}) {
|
8882
|
-
this.sender = sender;
|
8883
|
-
this.recipient = recipient;
|
8884
|
-
this.nonce = nonce;
|
8885
|
-
this.amount = amount;
|
8886
|
-
this.data = data;
|
8887
|
-
this.da_height = da_height;
|
8888
|
-
}
|
8889
|
-
toChainMessage(recipient) {
|
8890
|
-
return {
|
8891
|
-
sender: this.sender.toB256(),
|
8892
|
-
recipient: recipient?.toB256() ?? this.recipient.toB256(),
|
8893
|
-
nonce: this.nonce,
|
8894
|
-
amount: (0, import_math24.bn)(this.amount).toNumber(),
|
8895
|
-
data: this.data,
|
8896
|
-
da_height: this.da_height
|
8897
|
-
};
|
8898
|
-
}
|
8899
|
-
};
|
8900
8653
|
// Annotate the CommonJS export names for ESM import in node:
|
8901
8654
|
0 && (module.exports = {
|
8902
|
-
AssetId,
|
8903
|
-
TestMessage,
|
8904
|
-
WalletConfig,
|
8905
8655
|
generateTestWallet,
|
8906
8656
|
killNode,
|
8907
8657
|
launchNode,
|
8908
8658
|
launchNodeAndGetWallets,
|
8909
|
-
seedTestWallet
|
8910
|
-
setupTestProviderAndWallets
|
8659
|
+
seedTestWallet
|
8911
8660
|
});
|
8912
8661
|
//# sourceMappingURL=test-utils.js.map
|