@fuel-ts/account 0.0.0-rc-1356-20240322130951 → 0.0.0-rc-1815-20240322131329
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 +7 -0
- package/dist/account.d.ts.map +1 -1
- package/dist/connectors/fuel-connector.d.ts +10 -0
- package/dist/connectors/fuel-connector.d.ts.map +1 -1
- package/dist/index.global.js +75 -13
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +178 -108
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +76 -7
- package/dist/index.mjs.map +1 -1
- package/dist/providers/provider.d.ts +3 -2
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +20 -1
- package/dist/providers/transaction-request/transaction-request.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 +75 -329
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +169 -333
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +76 -236
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +16 -17
- package/dist/test-utils/asset-id.d.ts +0 -9
- 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,21 +48,17 @@ 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_utils30 = require("@fuel-ts/utils");
|
66
62
|
|
67
63
|
// src/account.ts
|
68
64
|
var import_address4 = require("@fuel-ts/address");
|
@@ -70,7 +66,7 @@ var import_configs11 = require("@fuel-ts/address/configs");
|
|
70
66
|
var import_errors15 = require("@fuel-ts/errors");
|
71
67
|
var import_interfaces = require("@fuel-ts/interfaces");
|
72
68
|
var import_math17 = require("@fuel-ts/math");
|
73
|
-
var
|
69
|
+
var import_utils27 = require("@fuel-ts/utils");
|
74
70
|
|
75
71
|
// src/providers/coin-quantity.ts
|
76
72
|
var import_configs = require("@fuel-ts/address/configs");
|
@@ -113,9 +109,9 @@ var import_address3 = require("@fuel-ts/address");
|
|
113
109
|
var import_errors13 = require("@fuel-ts/errors");
|
114
110
|
var import_math14 = require("@fuel-ts/math");
|
115
111
|
var import_transactions17 = require("@fuel-ts/transactions");
|
116
|
-
var
|
112
|
+
var import_utils22 = require("@fuel-ts/utils");
|
117
113
|
var import_versions = require("@fuel-ts/versions");
|
118
|
-
var
|
114
|
+
var import_utils23 = require("@noble/curves/abstract/utils");
|
119
115
|
var import_ethers = require("ethers");
|
120
116
|
var import_graphql_request = require("graphql-request");
|
121
117
|
var import_ramda3 = require("ramda");
|
@@ -1512,6 +1508,15 @@ function normalizeJSON(root) {
|
|
1512
1508
|
return normalize((0, import_ramda.clone)(root));
|
1513
1509
|
}
|
1514
1510
|
|
1511
|
+
// src/providers/utils/sleep.ts
|
1512
|
+
function sleep(time) {
|
1513
|
+
return new Promise((resolve) => {
|
1514
|
+
setTimeout(() => {
|
1515
|
+
resolve(true);
|
1516
|
+
}, time);
|
1517
|
+
});
|
1518
|
+
}
|
1519
|
+
|
1515
1520
|
// src/providers/transaction-request/errors.ts
|
1516
1521
|
var NoWitnessAtIndexError = class extends Error {
|
1517
1522
|
constructor(index) {
|
@@ -1641,13 +1646,27 @@ var BaseTransactionRequest = class {
|
|
1641
1646
|
this.outputs.push(output);
|
1642
1647
|
return this.outputs.length - 1;
|
1643
1648
|
}
|
1649
|
+
/**
|
1650
|
+
* @hidden
|
1651
|
+
*
|
1652
|
+
* Pushes a witness to the list and returns the index
|
1653
|
+
*
|
1654
|
+
* @param signature - The signature to add to the witness.
|
1655
|
+
* @returns The index of the created witness.
|
1656
|
+
*/
|
1657
|
+
addWitness(signature) {
|
1658
|
+
this.witnesses.push(signature);
|
1659
|
+
return this.witnesses.length - 1;
|
1660
|
+
}
|
1644
1661
|
/**
|
1645
1662
|
* @hidden
|
1646
1663
|
*
|
1647
1664
|
* Creates an empty witness without any side effects and returns the index
|
1665
|
+
*
|
1666
|
+
* @returns The index of the created witness.
|
1648
1667
|
*/
|
1649
|
-
|
1650
|
-
this.
|
1668
|
+
addEmptyWitness() {
|
1669
|
+
this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
|
1651
1670
|
return this.witnesses.length - 1;
|
1652
1671
|
}
|
1653
1672
|
/**
|
@@ -1676,6 +1695,21 @@ var BaseTransactionRequest = class {
|
|
1676
1695
|
}
|
1677
1696
|
this.witnesses[index] = witness;
|
1678
1697
|
}
|
1698
|
+
/**
|
1699
|
+
* Helper function to add an external signature to the transaction.
|
1700
|
+
*
|
1701
|
+
* @param account - The account/s to sign to the transaction.
|
1702
|
+
* @returns The transaction with the signature witness added.
|
1703
|
+
*/
|
1704
|
+
async addAccountWitnesses(account) {
|
1705
|
+
const accounts = Array.isArray(account) ? account : [account];
|
1706
|
+
await Promise.all(
|
1707
|
+
accounts.map(async (acc) => {
|
1708
|
+
this.addWitness(await acc.signTransaction(this));
|
1709
|
+
})
|
1710
|
+
);
|
1711
|
+
return this;
|
1712
|
+
}
|
1679
1713
|
/**
|
1680
1714
|
* Gets the coin inputs for a transaction.
|
1681
1715
|
*
|
@@ -1741,7 +1775,7 @@ var BaseTransactionRequest = class {
|
|
1741
1775
|
} else {
|
1742
1776
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
1743
1777
|
if (typeof witnessIndex !== "number") {
|
1744
|
-
witnessIndex = this.
|
1778
|
+
witnessIndex = this.addEmptyWitness();
|
1745
1779
|
}
|
1746
1780
|
}
|
1747
1781
|
const input = {
|
@@ -1775,7 +1809,7 @@ var BaseTransactionRequest = class {
|
|
1775
1809
|
} else {
|
1776
1810
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
1777
1811
|
if (typeof witnessIndex !== "number") {
|
1778
|
-
witnessIndex = this.
|
1812
|
+
witnessIndex = this.addEmptyWitness();
|
1779
1813
|
}
|
1780
1814
|
}
|
1781
1815
|
const input = {
|
@@ -3297,7 +3331,6 @@ var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
|
3297
3331
|
var import_transactions16 = require("@fuel-ts/transactions");
|
3298
3332
|
|
3299
3333
|
// src/providers/utils/auto-retry-fetch.ts
|
3300
|
-
var import_utils22 = require("@fuel-ts/utils");
|
3301
3334
|
function getWaitDelay(options, retryAttemptNum) {
|
3302
3335
|
const duration = options.baseDelay ?? 150;
|
3303
3336
|
switch (options.backoff) {
|
@@ -3327,7 +3360,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
3327
3360
|
throw error;
|
3328
3361
|
}
|
3329
3362
|
const delay = getWaitDelay(options, retryNum);
|
3330
|
-
await
|
3363
|
+
await sleep(delay);
|
3331
3364
|
return autoRetryFetch(fetchFn, options, retryNum)(...args);
|
3332
3365
|
}
|
3333
3366
|
};
|
@@ -3630,7 +3663,7 @@ var _Provider = class {
|
|
3630
3663
|
if (estimateTxDependencies) {
|
3631
3664
|
await this.estimateTxDependencies(transactionRequest);
|
3632
3665
|
}
|
3633
|
-
const encodedTransaction = (0,
|
3666
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3634
3667
|
if (awaitExecution) {
|
3635
3668
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3636
3669
|
for await (const { submitAndAwait } of subscription) {
|
@@ -3669,7 +3702,7 @@ var _Provider = class {
|
|
3669
3702
|
if (estimateTxDependencies) {
|
3670
3703
|
return this.estimateTxDependencies(transactionRequest);
|
3671
3704
|
}
|
3672
|
-
const encodedTransaction = (0,
|
3705
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3673
3706
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3674
3707
|
encodedTransaction,
|
3675
3708
|
utxoValidation: utxoValidation || false
|
@@ -3688,13 +3721,13 @@ var _Provider = class {
|
|
3688
3721
|
async estimatePredicates(transactionRequest) {
|
3689
3722
|
const shouldEstimatePredicates = Boolean(
|
3690
3723
|
transactionRequest.inputs.find(
|
3691
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3724
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math14.BN(input.predicateGasUsed).isZero()
|
3692
3725
|
)
|
3693
3726
|
);
|
3694
3727
|
if (!shouldEstimatePredicates) {
|
3695
3728
|
return transactionRequest;
|
3696
3729
|
}
|
3697
|
-
const encodedTransaction = (0,
|
3730
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3698
3731
|
const response = await this.operations.estimatePredicates({
|
3699
3732
|
encodedTransaction
|
3700
3733
|
});
|
@@ -3737,7 +3770,7 @@ var _Provider = class {
|
|
3737
3770
|
let outputVariables = 0;
|
3738
3771
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3739
3772
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3740
|
-
encodedTransaction: (0,
|
3773
|
+
encodedTransaction: (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes()),
|
3741
3774
|
utxoValidation: false
|
3742
3775
|
});
|
3743
3776
|
receipts = gqlReceipts.map(processGqlReceipt);
|
@@ -3775,7 +3808,7 @@ var _Provider = class {
|
|
3775
3808
|
if (estimateTxDependencies) {
|
3776
3809
|
return this.estimateTxDependencies(transactionRequest);
|
3777
3810
|
}
|
3778
|
-
const encodedTransaction = (0,
|
3811
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3779
3812
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3780
3813
|
encodedTransaction,
|
3781
3814
|
utxoValidation: true
|
@@ -3803,7 +3836,8 @@ var _Provider = class {
|
|
3803
3836
|
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3804
3837
|
estimateTxDependencies = true,
|
3805
3838
|
estimatePredicates = true,
|
3806
|
-
resourcesOwner
|
3839
|
+
resourcesOwner,
|
3840
|
+
signatureCallback
|
3807
3841
|
} = {}) {
|
3808
3842
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
3809
3843
|
const chainInfo = this.getChain();
|
@@ -3822,6 +3856,9 @@ var _Provider = class {
|
|
3822
3856
|
}
|
3823
3857
|
await this.estimatePredicates(txRequestClone);
|
3824
3858
|
}
|
3859
|
+
if (signatureCallback && isScriptTransaction) {
|
3860
|
+
await signatureCallback(txRequestClone);
|
3861
|
+
}
|
3825
3862
|
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
3826
3863
|
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
3827
3864
|
let receipts = [];
|
@@ -3885,7 +3922,7 @@ var _Provider = class {
|
|
3885
3922
|
const result = await this.operations.getCoins({
|
3886
3923
|
first: 10,
|
3887
3924
|
...paginationArgs,
|
3888
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
3925
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
|
3889
3926
|
});
|
3890
3927
|
const coins = result.coins.edges.map((edge) => edge.node);
|
3891
3928
|
return coins.map((coin) => ({
|
@@ -3909,19 +3946,19 @@ var _Provider = class {
|
|
3909
3946
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
3910
3947
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
3911
3948
|
const excludeInput = {
|
3912
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
3913
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
3949
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
|
3950
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
|
3914
3951
|
};
|
3915
3952
|
if (this.cache) {
|
3916
3953
|
const uniqueUtxos = new Set(
|
3917
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
3954
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
|
3918
3955
|
);
|
3919
3956
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
3920
3957
|
}
|
3921
3958
|
const coinsQuery = {
|
3922
3959
|
owner: ownerAddress.toB256(),
|
3923
3960
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
3924
|
-
assetId: (0,
|
3961
|
+
assetId: (0, import_utils22.hexlify)(assetId),
|
3925
3962
|
amount: amount.toString(10),
|
3926
3963
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
3927
3964
|
})),
|
@@ -4024,7 +4061,7 @@ var _Provider = class {
|
|
4024
4061
|
time: block.header.time,
|
4025
4062
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4026
4063
|
transactions: block.transactions.map(
|
4027
|
-
(tx) => new import_transactions17.TransactionCoder().decode((0,
|
4064
|
+
(tx) => new import_transactions17.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
|
4028
4065
|
)
|
4029
4066
|
};
|
4030
4067
|
}
|
@@ -4040,7 +4077,7 @@ var _Provider = class {
|
|
4040
4077
|
return null;
|
4041
4078
|
}
|
4042
4079
|
return new import_transactions17.TransactionCoder().decode(
|
4043
|
-
(0,
|
4080
|
+
(0, import_utils22.arrayify)(transaction.rawPayload),
|
4044
4081
|
0
|
4045
4082
|
)?.[0];
|
4046
4083
|
}
|
@@ -4067,7 +4104,7 @@ var _Provider = class {
|
|
4067
4104
|
async getContractBalance(contractId, assetId) {
|
4068
4105
|
const { contractBalance } = await this.operations.getContractBalance({
|
4069
4106
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4070
|
-
asset: (0,
|
4107
|
+
asset: (0, import_utils22.hexlify)(assetId)
|
4071
4108
|
});
|
4072
4109
|
return (0, import_math14.bn)(contractBalance.amount, 10);
|
4073
4110
|
}
|
@@ -4081,7 +4118,7 @@ var _Provider = class {
|
|
4081
4118
|
async getBalance(owner, assetId) {
|
4082
4119
|
const { balance } = await this.operations.getBalance({
|
4083
4120
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4084
|
-
assetId: (0,
|
4121
|
+
assetId: (0, import_utils22.hexlify)(assetId)
|
4085
4122
|
});
|
4086
4123
|
return (0, import_math14.bn)(balance.amount, 10);
|
4087
4124
|
}
|
@@ -4242,7 +4279,7 @@ var _Provider = class {
|
|
4242
4279
|
async produceBlocks(amount, startTime) {
|
4243
4280
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4244
4281
|
blocksToProduce: (0, import_math14.bn)(amount).toString(10),
|
4245
|
-
startTimestamp: startTime ?
|
4282
|
+
startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4246
4283
|
});
|
4247
4284
|
return (0, import_math14.bn)(latestBlockHeight);
|
4248
4285
|
}
|
@@ -4270,7 +4307,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4270
4307
|
var import_errors14 = require("@fuel-ts/errors");
|
4271
4308
|
var import_math15 = require("@fuel-ts/math");
|
4272
4309
|
var import_transactions18 = require("@fuel-ts/transactions");
|
4273
|
-
var
|
4310
|
+
var import_utils25 = require("@fuel-ts/utils");
|
4274
4311
|
|
4275
4312
|
// src/providers/chains.ts
|
4276
4313
|
var CHAIN_IDS = {
|
@@ -4320,16 +4357,16 @@ var assets = [
|
|
4320
4357
|
// src/utils/formatTransferToContractScriptData.ts
|
4321
4358
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
4322
4359
|
var import_math16 = require("@fuel-ts/math");
|
4323
|
-
var
|
4360
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4324
4361
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4325
4362
|
var formatTransferToContractScriptData = (params) => {
|
4326
4363
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4327
4364
|
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
4328
4365
|
const encoded = numberCoder.encode(new import_math16.BN(amountToTransfer).toNumber());
|
4329
4366
|
const scriptData = Uint8Array.from([
|
4330
|
-
...(0,
|
4367
|
+
...(0, import_utils26.arrayify)(hexlifiedContractId),
|
4331
4368
|
...encoded,
|
4332
|
-
...(0,
|
4369
|
+
...(0, import_utils26.arrayify)(assetId)
|
4333
4370
|
]);
|
4334
4371
|
return scriptData;
|
4335
4372
|
};
|
@@ -4669,14 +4706,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4669
4706
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4670
4707
|
const { minGasPrice } = this.provider.getGasConfig();
|
4671
4708
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
4672
|
-
const recipientDataArray = (0,
|
4709
|
+
const recipientDataArray = (0, import_utils27.arrayify)(
|
4673
4710
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4674
4711
|
);
|
4675
|
-
const amountDataArray = (0,
|
4712
|
+
const amountDataArray = (0, import_utils27.arrayify)(
|
4676
4713
|
"0x".concat((0, import_math17.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
4677
4714
|
);
|
4678
4715
|
const script = new Uint8Array([
|
4679
|
-
...(0,
|
4716
|
+
...(0, import_utils27.arrayify)(withdrawScript.bytes),
|
4680
4717
|
...recipientDataArray,
|
4681
4718
|
...amountDataArray
|
4682
4719
|
]);
|
@@ -4703,6 +4740,21 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4703
4740
|
}
|
4704
4741
|
return this._connector.signMessage(this.address.toString(), message);
|
4705
4742
|
}
|
4743
|
+
/**
|
4744
|
+
* Signs a transaction with the wallet's private key.
|
4745
|
+
*
|
4746
|
+
* @param transactionRequestLike - The transaction request to sign.
|
4747
|
+
* @returns A promise that resolves to the signature of the transaction.
|
4748
|
+
*/
|
4749
|
+
async signTransaction(transactionRequestLike) {
|
4750
|
+
if (!this._connector) {
|
4751
|
+
throw new import_errors15.FuelError(
|
4752
|
+
import_errors15.ErrorCode.MISSING_CONNECTOR,
|
4753
|
+
"A connector is required to sign transactions."
|
4754
|
+
);
|
4755
|
+
}
|
4756
|
+
return this._connector.signTransaction(this.address.toString(), transactionRequestLike);
|
4757
|
+
}
|
4706
4758
|
/**
|
4707
4759
|
* Sends a transaction to the network.
|
4708
4760
|
*
|
@@ -4763,7 +4815,7 @@ var import_address5 = require("@fuel-ts/address");
|
|
4763
4815
|
var import_crypto = require("@fuel-ts/crypto");
|
4764
4816
|
var import_hasher2 = require("@fuel-ts/hasher");
|
4765
4817
|
var import_math18 = require("@fuel-ts/math");
|
4766
|
-
var
|
4818
|
+
var import_utils28 = require("@fuel-ts/utils");
|
4767
4819
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
4768
4820
|
var Signer = class {
|
4769
4821
|
address;
|
@@ -4783,9 +4835,9 @@ var Signer = class {
|
|
4783
4835
|
}
|
4784
4836
|
}
|
4785
4837
|
const privateKeyBytes = (0, import_math18.toBytes)(privateKey, 32);
|
4786
|
-
this.privateKey = (0,
|
4787
|
-
this.publicKey = (0,
|
4788
|
-
this.compressedPublicKey = (0,
|
4838
|
+
this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
|
4839
|
+
this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
4840
|
+
this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
4789
4841
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
4790
4842
|
}
|
4791
4843
|
/**
|
@@ -4799,11 +4851,11 @@ var Signer = class {
|
|
4799
4851
|
* @returns hashed signature
|
4800
4852
|
*/
|
4801
4853
|
sign(data) {
|
4802
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
4854
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
|
4803
4855
|
const r = (0, import_math18.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
4804
4856
|
const s = (0, import_math18.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
4805
4857
|
s[0] |= (signature.recovery || 0) << 7;
|
4806
|
-
return (0,
|
4858
|
+
return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
|
4807
4859
|
}
|
4808
4860
|
/**
|
4809
4861
|
* Add point on the current elliptic curve
|
@@ -4812,8 +4864,8 @@ var Signer = class {
|
|
4812
4864
|
* @returns compressed point on the curve
|
4813
4865
|
*/
|
4814
4866
|
addPoint(point) {
|
4815
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4816
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4867
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
|
4868
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
|
4817
4869
|
const result = p0.add(p1);
|
4818
4870
|
return `0x${result.toHex(true)}`;
|
4819
4871
|
}
|
@@ -4825,16 +4877,16 @@ var Signer = class {
|
|
4825
4877
|
* @returns public key from signature from the
|
4826
4878
|
*/
|
4827
4879
|
static recoverPublicKey(data, signature) {
|
4828
|
-
const signedMessageBytes = (0,
|
4880
|
+
const signedMessageBytes = (0, import_utils28.arrayify)(signature);
|
4829
4881
|
const r = signedMessageBytes.slice(0, 32);
|
4830
4882
|
const s = signedMessageBytes.slice(32, 64);
|
4831
4883
|
const recoveryParam = (s[0] & 128) >> 7;
|
4832
4884
|
s[0] &= 127;
|
4833
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
4885
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
|
4834
4886
|
recoveryParam
|
4835
4887
|
);
|
4836
|
-
const publicKey = sig.recoverPublicKey((0,
|
4837
|
-
return (0,
|
4888
|
+
const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
|
4889
|
+
return (0, import_utils28.hexlify)(publicKey);
|
4838
4890
|
}
|
4839
4891
|
/**
|
4840
4892
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -4853,7 +4905,7 @@ var Signer = class {
|
|
4853
4905
|
* @returns random 32-byte hashed
|
4854
4906
|
*/
|
4855
4907
|
static generatePrivateKey(entropy) {
|
4856
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
4908
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils28.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils28.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
|
4857
4909
|
}
|
4858
4910
|
/**
|
4859
4911
|
* Extended publicKey from a compact publicKey
|
@@ -4862,8 +4914,8 @@ var Signer = class {
|
|
4862
4914
|
* @returns extended publicKey
|
4863
4915
|
*/
|
4864
4916
|
static extendPublicKey(publicKey) {
|
4865
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4866
|
-
return (0,
|
4917
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
|
4918
|
+
return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
|
4867
4919
|
}
|
4868
4920
|
};
|
4869
4921
|
|
@@ -4871,7 +4923,7 @@ var Signer = class {
|
|
4871
4923
|
var import_address6 = require("@fuel-ts/address");
|
4872
4924
|
var import_crypto2 = require("@fuel-ts/crypto");
|
4873
4925
|
var import_errors16 = require("@fuel-ts/errors");
|
4874
|
-
var
|
4926
|
+
var import_utils29 = require("@fuel-ts/utils");
|
4875
4927
|
var import_uuid = require("uuid");
|
4876
4928
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
4877
4929
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -4954,7 +5006,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
4954
5006
|
);
|
4955
5007
|
}
|
4956
5008
|
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
4957
|
-
const privateKey = (0,
|
5009
|
+
const privateKey = (0, import_utils29.hexlify)(buffer);
|
4958
5010
|
return privateKey;
|
4959
5011
|
}
|
4960
5012
|
|
@@ -4999,7 +5051,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
4999
5051
|
*/
|
5000
5052
|
async signMessage(message) {
|
5001
5053
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5002
|
-
return (0,
|
5054
|
+
return (0, import_utils30.hexlify)(signedMessage);
|
5003
5055
|
}
|
5004
5056
|
/**
|
5005
5057
|
* Signs a transaction with the wallet's private key.
|
@@ -5009,10 +5061,10 @@ var BaseWalletUnlocked = class extends Account {
|
|
5009
5061
|
*/
|
5010
5062
|
async signTransaction(transactionRequestLike) {
|
5011
5063
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5012
|
-
const chainId = this.provider.
|
5064
|
+
const chainId = this.provider.getChainId();
|
5013
5065
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5014
5066
|
const signature = await this.signer().sign(hashedTransaction);
|
5015
|
-
return (0,
|
5067
|
+
return (0, import_utils30.hexlify)(signature);
|
5016
5068
|
}
|
5017
5069
|
/**
|
5018
5070
|
* Populates a transaction with the witnesses signature.
|
@@ -5074,14 +5126,14 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5074
5126
|
var import_errors19 = require("@fuel-ts/errors");
|
5075
5127
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5076
5128
|
var import_math19 = require("@fuel-ts/math");
|
5077
|
-
var
|
5129
|
+
var import_utils34 = require("@fuel-ts/utils");
|
5078
5130
|
var import_ethers3 = require("ethers");
|
5079
5131
|
|
5080
5132
|
// src/mnemonic/mnemonic.ts
|
5081
5133
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5082
5134
|
var import_errors18 = require("@fuel-ts/errors");
|
5083
5135
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5084
|
-
var
|
5136
|
+
var import_utils32 = require("@fuel-ts/utils");
|
5085
5137
|
var import_ethers2 = require("ethers");
|
5086
5138
|
|
5087
5139
|
// src/wordlists/words/english.ts
|
@@ -7139,7 +7191,7 @@ var english = [
|
|
7139
7191
|
// src/mnemonic/utils.ts
|
7140
7192
|
var import_errors17 = require("@fuel-ts/errors");
|
7141
7193
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7142
|
-
var
|
7194
|
+
var import_utils31 = require("@fuel-ts/utils");
|
7143
7195
|
function toUtf8Bytes(stri) {
|
7144
7196
|
const str = stri.normalize("NFKD");
|
7145
7197
|
const result = [];
|
@@ -7206,14 +7258,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7206
7258
|
}
|
7207
7259
|
}
|
7208
7260
|
const checksumBits = entropy.length / 4;
|
7209
|
-
const checksum = (0,
|
7261
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7210
7262
|
indices[indices.length - 1] <<= checksumBits;
|
7211
7263
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7212
7264
|
return indices;
|
7213
7265
|
}
|
7214
7266
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7215
7267
|
const size = Math.ceil(11 * words.length / 8);
|
7216
|
-
const entropy = (0,
|
7268
|
+
const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
|
7217
7269
|
let offset = 0;
|
7218
7270
|
for (let i = 0; i < words.length; i += 1) {
|
7219
7271
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7233,7 +7285,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7233
7285
|
const entropyBits = 32 * words.length / 3;
|
7234
7286
|
const checksumBits = words.length / 3;
|
7235
7287
|
const checksumMask = getUpperMask(checksumBits);
|
7236
|
-
const checksum = (0,
|
7288
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7237
7289
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7238
7290
|
throw new import_errors17.FuelError(
|
7239
7291
|
import_errors17.ErrorCode.INVALID_CHECKSUM,
|
@@ -7308,7 +7360,7 @@ var Mnemonic = class {
|
|
7308
7360
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7309
7361
|
const words = getWords(phrase);
|
7310
7362
|
assertMnemonic(words);
|
7311
|
-
return (0,
|
7363
|
+
return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7312
7364
|
}
|
7313
7365
|
/**
|
7314
7366
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7316,7 +7368,7 @@ var Mnemonic = class {
|
|
7316
7368
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7317
7369
|
*/
|
7318
7370
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7319
|
-
const entropyBytes = (0,
|
7371
|
+
const entropyBytes = (0, import_utils32.arrayify)(entropy);
|
7320
7372
|
assertWordList(wordlist);
|
7321
7373
|
assertEntropy(entropyBytes);
|
7322
7374
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7385,14 +7437,14 @@ var Mnemonic = class {
|
|
7385
7437
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7386
7438
|
*/
|
7387
7439
|
static masterKeysFromSeed(seed) {
|
7388
|
-
const seedArray = (0,
|
7440
|
+
const seedArray = (0, import_utils32.arrayify)(seed);
|
7389
7441
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7390
7442
|
throw new import_errors18.FuelError(
|
7391
7443
|
import_errors18.ErrorCode.INVALID_SEED,
|
7392
7444
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7393
7445
|
);
|
7394
7446
|
}
|
7395
|
-
return (0,
|
7447
|
+
return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7396
7448
|
}
|
7397
7449
|
/**
|
7398
7450
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7403,22 +7455,22 @@ var Mnemonic = class {
|
|
7403
7455
|
*/
|
7404
7456
|
static seedToExtendedKey(seed, testnet = false) {
|
7405
7457
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7406
|
-
const prefix = (0,
|
7458
|
+
const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7407
7459
|
const depth = "0x00";
|
7408
7460
|
const fingerprint = "0x00000000";
|
7409
7461
|
const index = "0x00000000";
|
7410
7462
|
const chainCode = masterKey.slice(32);
|
7411
7463
|
const privateKey = masterKey.slice(0, 32);
|
7412
|
-
const extendedKey = (0,
|
7464
|
+
const extendedKey = (0, import_utils32.concat)([
|
7413
7465
|
prefix,
|
7414
7466
|
depth,
|
7415
7467
|
fingerprint,
|
7416
7468
|
index,
|
7417
7469
|
chainCode,
|
7418
|
-
(0,
|
7470
|
+
(0, import_utils32.concat)(["0x00", privateKey])
|
7419
7471
|
]);
|
7420
7472
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7421
|
-
return (0, import_ethers2.encodeBase58)((0,
|
7473
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
|
7422
7474
|
}
|
7423
7475
|
/**
|
7424
7476
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7433,7 +7485,7 @@ var Mnemonic = class {
|
|
7433
7485
|
* @returns A randomly generated mnemonic
|
7434
7486
|
*/
|
7435
7487
|
static generate(size = 32, extraEntropy = "") {
|
7436
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7488
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
|
7437
7489
|
return Mnemonic.entropyToMnemonic(entropy);
|
7438
7490
|
}
|
7439
7491
|
};
|
@@ -7441,12 +7493,12 @@ var mnemonic_default = Mnemonic;
|
|
7441
7493
|
|
7442
7494
|
// src/hdwallet/hdwallet.ts
|
7443
7495
|
var HARDENED_INDEX = 2147483648;
|
7444
|
-
var MainnetPRV2 = (0,
|
7445
|
-
var MainnetPUB = (0,
|
7446
|
-
var TestnetPRV2 = (0,
|
7447
|
-
var TestnetPUB = (0,
|
7496
|
+
var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
|
7497
|
+
var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
|
7498
|
+
var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
|
7499
|
+
var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
|
7448
7500
|
function base58check(data) {
|
7449
|
-
return (0, import_ethers3.encodeBase58)((0,
|
7501
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
7450
7502
|
}
|
7451
7503
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7452
7504
|
if (isPublic) {
|
@@ -7455,11 +7507,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7455
7507
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7456
7508
|
}
|
7457
7509
|
function isPublicExtendedKey(extendedKey) {
|
7458
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7510
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
|
7459
7511
|
}
|
7460
7512
|
function isValidExtendedKey(extendedKey) {
|
7461
7513
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7462
|
-
(0,
|
7514
|
+
(0, import_utils34.hexlify)(extendedKey.slice(0, 4))
|
7463
7515
|
);
|
7464
7516
|
}
|
7465
7517
|
function parsePath(path2, depth = 0) {
|
@@ -7477,8 +7529,8 @@ function parsePath(path2, depth = 0) {
|
|
7477
7529
|
var HDWallet = class {
|
7478
7530
|
depth = 0;
|
7479
7531
|
index = 0;
|
7480
|
-
fingerprint = (0,
|
7481
|
-
parentFingerprint = (0,
|
7532
|
+
fingerprint = (0, import_utils34.hexlify)("0x00000000");
|
7533
|
+
parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
|
7482
7534
|
privateKey;
|
7483
7535
|
publicKey;
|
7484
7536
|
chainCode;
|
@@ -7490,8 +7542,8 @@ var HDWallet = class {
|
|
7490
7542
|
constructor(config) {
|
7491
7543
|
if (config.privateKey) {
|
7492
7544
|
const signer = new Signer(config.privateKey);
|
7493
|
-
this.publicKey = (0,
|
7494
|
-
this.privateKey = (0,
|
7545
|
+
this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
|
7546
|
+
this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
|
7495
7547
|
} else {
|
7496
7548
|
if (!config.publicKey) {
|
7497
7549
|
throw new import_errors19.FuelError(
|
@@ -7499,7 +7551,7 @@ var HDWallet = class {
|
|
7499
7551
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7500
7552
|
);
|
7501
7553
|
}
|
7502
|
-
this.publicKey = (0,
|
7554
|
+
this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
|
7503
7555
|
}
|
7504
7556
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7505
7557
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -7518,9 +7570,9 @@ var HDWallet = class {
|
|
7518
7570
|
* @returns A new instance of HDWallet on the derived index
|
7519
7571
|
*/
|
7520
7572
|
deriveIndex(index) {
|
7521
|
-
const privateKey = this.privateKey && (0,
|
7522
|
-
const publicKey = (0,
|
7523
|
-
const chainCode = (0,
|
7573
|
+
const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
|
7574
|
+
const publicKey = (0, import_utils34.arrayify)(this.publicKey);
|
7575
|
+
const chainCode = (0, import_utils34.arrayify)(this.chainCode);
|
7524
7576
|
const data = new Uint8Array(37);
|
7525
7577
|
if (index & HARDENED_INDEX) {
|
7526
7578
|
if (!privateKey) {
|
@@ -7531,10 +7583,10 @@ var HDWallet = class {
|
|
7531
7583
|
}
|
7532
7584
|
data.set(privateKey, 1);
|
7533
7585
|
} else {
|
7534
|
-
data.set((0,
|
7586
|
+
data.set((0, import_utils34.arrayify)(this.publicKey));
|
7535
7587
|
}
|
7536
7588
|
data.set((0, import_math19.toBytes)(index, 4), 33);
|
7537
|
-
const bytes = (0,
|
7589
|
+
const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
7538
7590
|
const IL = bytes.slice(0, 32);
|
7539
7591
|
const IR = bytes.slice(32);
|
7540
7592
|
if (privateKey) {
|
@@ -7548,7 +7600,7 @@ var HDWallet = class {
|
|
7548
7600
|
parentFingerprint: this.fingerprint
|
7549
7601
|
});
|
7550
7602
|
}
|
7551
|
-
const signer = new Signer((0,
|
7603
|
+
const signer = new Signer((0, import_utils34.hexlify)(IL));
|
7552
7604
|
const Ki = signer.addPoint(publicKey);
|
7553
7605
|
return new HDWallet({
|
7554
7606
|
publicKey: Ki,
|
@@ -7583,12 +7635,12 @@ var HDWallet = class {
|
|
7583
7635
|
);
|
7584
7636
|
}
|
7585
7637
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7586
|
-
const depth = (0,
|
7638
|
+
const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
|
7587
7639
|
const parentFingerprint = this.parentFingerprint;
|
7588
7640
|
const index = (0, import_math19.toHex)(this.index, 4);
|
7589
7641
|
const chainCode = this.chainCode;
|
7590
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7591
|
-
const extendedKey = (0,
|
7642
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
|
7643
|
+
const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7592
7644
|
return base58check(extendedKey);
|
7593
7645
|
}
|
7594
7646
|
/**
|
@@ -7600,13 +7652,13 @@ var HDWallet = class {
|
|
7600
7652
|
static fromSeed(seed) {
|
7601
7653
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
7602
7654
|
return new HDWallet({
|
7603
|
-
chainCode: (0,
|
7604
|
-
privateKey: (0,
|
7655
|
+
chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
|
7656
|
+
privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
|
7605
7657
|
});
|
7606
7658
|
}
|
7607
7659
|
static fromExtendedKey(extendedKey) {
|
7608
7660
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
7609
|
-
const bytes = (0,
|
7661
|
+
const bytes = (0, import_utils34.arrayify)(decoded);
|
7610
7662
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7611
7663
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7612
7664
|
throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -7615,9 +7667,9 @@ var HDWallet = class {
|
|
7615
7667
|
throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7616
7668
|
}
|
7617
7669
|
const depth = bytes[4];
|
7618
|
-
const parentFingerprint = (0,
|
7619
|
-
const index = parseInt((0,
|
7620
|
-
const chainCode = (0,
|
7670
|
+
const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
|
7671
|
+
const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
7672
|
+
const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
|
7621
7673
|
const key = bytes.slice(45, 78);
|
7622
7674
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7623
7675
|
throw new import_errors19.FuelError(
|
@@ -7833,7 +7885,7 @@ var generateTestWallet = async (provider, quantities) => {
|
|
7833
7885
|
// src/test-utils/launchNode.ts
|
7834
7886
|
var import_configs12 = require("@fuel-ts/address/configs");
|
7835
7887
|
var import_math20 = require("@fuel-ts/math");
|
7836
|
-
var
|
7888
|
+
var import_utils35 = require("@fuel-ts/utils");
|
7837
7889
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
7838
7890
|
var import_child_process = require("child_process");
|
7839
7891
|
var import_crypto5 = require("crypto");
|
@@ -7880,8 +7932,7 @@ var launchNode = async ({
|
|
7880
7932
|
useSystemFuelCore = false,
|
7881
7933
|
loggingEnabled = true,
|
7882
7934
|
debugEnabled = false,
|
7883
|
-
basePath
|
7884
|
-
chainConfig = import_utils36.defaultChainConfig
|
7935
|
+
basePath
|
7885
7936
|
}) => (
|
7886
7937
|
// eslint-disable-next-line no-async-promise-executor
|
7887
7938
|
new Promise(async (resolve, reject) => {
|
@@ -7892,7 +7943,7 @@ var launchNode = async ({
|
|
7892
7943
|
"--poa-instant"
|
7893
7944
|
]);
|
7894
7945
|
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
7895
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
7946
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils35.defaultConsensusKey;
|
7896
7947
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
7897
7948
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
7898
7949
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -7918,17 +7969,17 @@ var launchNode = async ({
|
|
7918
7969
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
7919
7970
|
}
|
7920
7971
|
const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
7921
|
-
let
|
7972
|
+
let chainConfig = import_utils35.defaultChainConfig;
|
7922
7973
|
if (!process.env.GENESIS_SECRET) {
|
7923
7974
|
const pk = Signer.generatePrivateKey();
|
7924
7975
|
const signer = new Signer(pk);
|
7925
|
-
process.env.GENESIS_SECRET = (0,
|
7926
|
-
|
7927
|
-
...
|
7976
|
+
process.env.GENESIS_SECRET = (0, import_utils35.hexlify)(pk);
|
7977
|
+
chainConfig = {
|
7978
|
+
...import_utils35.defaultChainConfig,
|
7928
7979
|
initial_state: {
|
7929
|
-
...
|
7980
|
+
...import_utils35.defaultChainConfig.initial_state,
|
7930
7981
|
coins: [
|
7931
|
-
...
|
7982
|
+
...import_utils35.defaultChainConfig.initial_state.coins,
|
7932
7983
|
{
|
7933
7984
|
owner: signer.address.toHexString(),
|
7934
7985
|
amount: (0, import_math20.toHex)(1e9),
|
@@ -7938,7 +7989,7 @@ var launchNode = async ({
|
|
7938
7989
|
}
|
7939
7990
|
};
|
7940
7991
|
}
|
7941
|
-
(0, import_fs.writeFileSync)(tempChainConfigFilePath, JSON.stringify(
|
7992
|
+
(0, import_fs.writeFileSync)(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
|
7942
7993
|
chainConfigPathToUse = tempChainConfigFilePath;
|
7943
7994
|
}
|
7944
7995
|
const child = (0, import_child_process.spawn)(
|
@@ -7976,21 +8027,16 @@ var launchNode = async ({
|
|
7976
8027
|
}
|
7977
8028
|
};
|
7978
8029
|
child.stderr.on("data", (chunk) => {
|
7979
|
-
|
7980
|
-
if (text.indexOf(graphQLStartSubstring) !== -1) {
|
7981
|
-
const rows = text.split("\n");
|
7982
|
-
const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
|
7983
|
-
const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
|
8030
|
+
if (chunk.indexOf(graphQLStartSubstring) !== -1) {
|
7984
8031
|
resolve({
|
7985
8032
|
cleanup: () => killNode(cleanupConfig),
|
7986
|
-
ip:
|
7987
|
-
port:
|
7988
|
-
url: `http://${realIp}:${realPort}/graphql`,
|
8033
|
+
ip: ipToUse,
|
8034
|
+
port: portToUse,
|
7989
8035
|
chainConfigPath: chainConfigPathToUse
|
7990
8036
|
});
|
7991
8037
|
}
|
7992
|
-
if (/error/i.test(
|
7993
|
-
reject(
|
8038
|
+
if (/error/i.test(chunk)) {
|
8039
|
+
reject(chunk.toString());
|
7994
8040
|
}
|
7995
8041
|
});
|
7996
8042
|
process.on("exit", () => killNode(cleanupConfig));
|
@@ -8022,222 +8068,12 @@ var launchNodeAndGetWallets = async ({
|
|
8022
8068
|
};
|
8023
8069
|
return { wallets, stop: cleanup, provider };
|
8024
8070
|
};
|
8025
|
-
|
8026
|
-
// src/test-utils/setup-test-provider-and-wallets.ts
|
8027
|
-
var import_utils38 = require("@fuel-ts/utils");
|
8028
|
-
var import_ramda4 = require("ramda");
|
8029
|
-
|
8030
|
-
// src/test-utils/asset-id.ts
|
8031
|
-
var import_configs13 = require("@fuel-ts/address/configs");
|
8032
|
-
var import_crypto6 = require("@fuel-ts/crypto");
|
8033
|
-
var import_utils37 = require("@fuel-ts/utils");
|
8034
|
-
var _AssetId = class {
|
8035
|
-
constructor(value) {
|
8036
|
-
this.value = value;
|
8037
|
-
}
|
8038
|
-
static random() {
|
8039
|
-
return new _AssetId((0, import_utils37.hexlify)((0, import_crypto6.randomBytes)(32)));
|
8040
|
-
}
|
8041
|
-
};
|
8042
|
-
var AssetId = _AssetId;
|
8043
|
-
__publicField(AssetId, "BaseAssetId", new _AssetId(import_configs13.BaseAssetId));
|
8044
|
-
__publicField(AssetId, "A", new _AssetId(
|
8045
|
-
"0x0101010101010101010101010101010101010101010101010101010101010101"
|
8046
|
-
));
|
8047
|
-
__publicField(AssetId, "B", new _AssetId(
|
8048
|
-
"0x0202020202020202020202020202020202020202020202020202020202020202"
|
8049
|
-
));
|
8050
|
-
|
8051
|
-
// src/test-utils/wallet-config.ts
|
8052
|
-
var import_crypto7 = require("@fuel-ts/crypto");
|
8053
|
-
var import_errors20 = require("@fuel-ts/errors");
|
8054
|
-
var import_math21 = require("@fuel-ts/math");
|
8055
|
-
var WalletConfig = class {
|
8056
|
-
initialState;
|
8057
|
-
options;
|
8058
|
-
wallets;
|
8059
|
-
generateWallets = () => {
|
8060
|
-
const generatedWallets = [];
|
8061
|
-
for (let index = 1; index <= this.options.count; index++) {
|
8062
|
-
generatedWallets.push(new WalletUnlocked((0, import_crypto7.randomBytes)(32)));
|
8063
|
-
}
|
8064
|
-
return generatedWallets;
|
8065
|
-
};
|
8066
|
-
constructor(config) {
|
8067
|
-
WalletConfig.guard(config);
|
8068
|
-
this.options = config;
|
8069
|
-
const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
|
8070
|
-
this.wallets = this.generateWallets();
|
8071
|
-
this.initialState = {
|
8072
|
-
messages: WalletConfig.createMessages(this.wallets, messages),
|
8073
|
-
coins: WalletConfig.createCoins(this.wallets, assets2, coinsPerAsset, amountPerCoin)
|
8074
|
-
};
|
8075
|
-
}
|
8076
|
-
apply(chainConfig) {
|
8077
|
-
return {
|
8078
|
-
...chainConfig,
|
8079
|
-
initial_state: {
|
8080
|
-
...chainConfig?.initial_state,
|
8081
|
-
coins: this.initialState.coins.concat(chainConfig?.initial_state?.coins || []),
|
8082
|
-
messages: this.initialState.messages.concat(chainConfig?.initial_state?.messages ?? [])
|
8083
|
-
}
|
8084
|
-
};
|
8085
|
-
}
|
8086
|
-
static createMessages(wallets, messages) {
|
8087
|
-
return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
|
8088
|
-
}
|
8089
|
-
static createCoins(wallets, assets2, coinsPerAsset, amountPerCoin) {
|
8090
|
-
const coins = [];
|
8091
|
-
let assetIds = [AssetId.BaseAssetId.value];
|
8092
|
-
if (Array.isArray(assets2)) {
|
8093
|
-
assetIds = assetIds.concat(assets2.map((a) => a.value));
|
8094
|
-
} else {
|
8095
|
-
for (let index = 0; index < assets2 - 1; index++) {
|
8096
|
-
assetIds.push(AssetId.random().value);
|
8097
|
-
}
|
8098
|
-
}
|
8099
|
-
wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
|
8100
|
-
assetIds.forEach((assetId) => {
|
8101
|
-
for (let index = 0; index < coinsPerAsset; index++) {
|
8102
|
-
coins.push({
|
8103
|
-
amount: (0, import_math21.toHex)(amountPerCoin, 8),
|
8104
|
-
asset_id: assetId,
|
8105
|
-
owner: walletAddress
|
8106
|
-
});
|
8107
|
-
}
|
8108
|
-
});
|
8109
|
-
});
|
8110
|
-
return coins;
|
8111
|
-
}
|
8112
|
-
static guard({
|
8113
|
-
count: wallets,
|
8114
|
-
assets: assets2,
|
8115
|
-
coinsPerAsset,
|
8116
|
-
amountPerCoin
|
8117
|
-
}) {
|
8118
|
-
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
8119
|
-
throw new import_errors20.FuelError(
|
8120
|
-
import_errors20.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
8121
|
-
"Number of wallets must be greater than zero."
|
8122
|
-
);
|
8123
|
-
}
|
8124
|
-
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
8125
|
-
throw new import_errors20.FuelError(
|
8126
|
-
import_errors20.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
8127
|
-
"Number of assets per wallet must be greater than zero."
|
8128
|
-
);
|
8129
|
-
}
|
8130
|
-
if (coinsPerAsset <= 0) {
|
8131
|
-
throw new import_errors20.FuelError(
|
8132
|
-
import_errors20.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
8133
|
-
"Number of coins per asset must be greater than zero."
|
8134
|
-
);
|
8135
|
-
}
|
8136
|
-
if (amountPerCoin <= 0) {
|
8137
|
-
throw new import_errors20.FuelError(
|
8138
|
-
import_errors20.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
8139
|
-
"Amount per coin must be greater than zero."
|
8140
|
-
);
|
8141
|
-
}
|
8142
|
-
}
|
8143
|
-
};
|
8144
|
-
|
8145
|
-
// src/test-utils/setup-test-provider-and-wallets.ts
|
8146
|
-
var defaultWalletConfigOptions = {
|
8147
|
-
count: 2,
|
8148
|
-
assets: [AssetId.A, AssetId.B],
|
8149
|
-
coinsPerAsset: 1,
|
8150
|
-
amountPerCoin: 1e10,
|
8151
|
-
messages: []
|
8152
|
-
};
|
8153
|
-
async function setupTestProviderAndWallets({
|
8154
|
-
walletConfig: walletConfigOptions = {},
|
8155
|
-
providerOptions,
|
8156
|
-
nodeOptions = {}
|
8157
|
-
} = {}) {
|
8158
|
-
Symbol.dispose ??= Symbol("Symbol.dispose");
|
8159
|
-
const walletConfig = new WalletConfig({
|
8160
|
-
...defaultWalletConfigOptions,
|
8161
|
-
...walletConfigOptions
|
8162
|
-
});
|
8163
|
-
const { cleanup, url } = await launchNode({
|
8164
|
-
...nodeOptions,
|
8165
|
-
chainConfig: (0, import_ramda4.mergeDeepRight)(import_utils38.defaultChainConfig, walletConfig.apply(nodeOptions?.chainConfig)),
|
8166
|
-
port: "0"
|
8167
|
-
});
|
8168
|
-
let provider;
|
8169
|
-
try {
|
8170
|
-
provider = await Provider.create(url, providerOptions);
|
8171
|
-
} catch (err) {
|
8172
|
-
cleanup();
|
8173
|
-
throw err;
|
8174
|
-
}
|
8175
|
-
const wallets = walletConfig.wallets;
|
8176
|
-
wallets.forEach((wallet) => {
|
8177
|
-
wallet.connect(provider);
|
8178
|
-
});
|
8179
|
-
return {
|
8180
|
-
provider,
|
8181
|
-
wallets,
|
8182
|
-
cleanup,
|
8183
|
-
[Symbol.dispose]: cleanup
|
8184
|
-
};
|
8185
|
-
}
|
8186
|
-
|
8187
|
-
// src/test-utils/test-message.ts
|
8188
|
-
var import_address7 = require("@fuel-ts/address");
|
8189
|
-
var import_crypto8 = require("@fuel-ts/crypto");
|
8190
|
-
var import_math22 = require("@fuel-ts/math");
|
8191
|
-
var import_utils39 = require("@fuel-ts/utils");
|
8192
|
-
var TestMessage = class {
|
8193
|
-
sender;
|
8194
|
-
recipient;
|
8195
|
-
nonce;
|
8196
|
-
amount;
|
8197
|
-
data;
|
8198
|
-
da_height;
|
8199
|
-
/**
|
8200
|
-
* A helper class to create messages for testing purposes.
|
8201
|
-
*
|
8202
|
-
* Used in tandem with `WalletConfig`.
|
8203
|
-
* It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
|
8204
|
-
*/
|
8205
|
-
constructor({
|
8206
|
-
sender = import_address7.Address.fromRandom(),
|
8207
|
-
recipient = import_address7.Address.fromRandom(),
|
8208
|
-
nonce = (0, import_utils39.hexlify)((0, import_crypto8.randomBytes)(32)),
|
8209
|
-
amount = 1e6,
|
8210
|
-
data = "02",
|
8211
|
-
da_height = "0x00"
|
8212
|
-
} = {}) {
|
8213
|
-
this.sender = sender;
|
8214
|
-
this.recipient = recipient;
|
8215
|
-
this.nonce = nonce;
|
8216
|
-
this.amount = amount;
|
8217
|
-
this.data = data;
|
8218
|
-
this.da_height = da_height;
|
8219
|
-
}
|
8220
|
-
toChainMessage(recipient) {
|
8221
|
-
return {
|
8222
|
-
sender: this.sender.toB256(),
|
8223
|
-
recipient: recipient?.toB256() ?? this.recipient.toB256(),
|
8224
|
-
nonce: this.nonce,
|
8225
|
-
amount: new import_math22.BN(this.amount).toHex(8),
|
8226
|
-
data: this.data,
|
8227
|
-
da_height: this.da_height
|
8228
|
-
};
|
8229
|
-
}
|
8230
|
-
};
|
8231
8071
|
// Annotate the CommonJS export names for ESM import in node:
|
8232
8072
|
0 && (module.exports = {
|
8233
|
-
AssetId,
|
8234
|
-
TestMessage,
|
8235
|
-
WalletConfig,
|
8236
8073
|
generateTestWallet,
|
8237
8074
|
killNode,
|
8238
8075
|
launchNode,
|
8239
8076
|
launchNodeAndGetWallets,
|
8240
|
-
seedTestWallet
|
8241
|
-
setupTestProviderAndWallets
|
8077
|
+
seedTestWallet
|
8242
8078
|
});
|
8243
8079
|
//# sourceMappingURL=test-utils.js.map
|