@fuel-ts/account 0.0.0-rc-1815-20240322115843 → 0.0.0-rc-1356-20240322130951
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 +0 -7
- package/dist/account.d.ts.map +1 -1
- package/dist/connectors/fuel-connector.d.ts +0 -10
- package/dist/connectors/fuel-connector.d.ts.map +1 -1
- package/dist/index.global.js +12 -70
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +107 -173
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -71
- package/dist/index.mjs.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +1 -20
- 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 +0 -1
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils/asset-id.d.ts +9 -0
- package/dist/test-utils/asset-id.d.ts.map +1 -0
- package/dist/test-utils/index.d.ts +4 -0
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +8 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts +33 -0
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +1 -0
- package/dist/test-utils/test-message.d.ts +28 -0
- package/dist/test-utils/test-message.d.ts.map +1 -0
- package/dist/test-utils/wallet-config.d.ts +49 -0
- package/dist/test-utils/wallet-config.d.ts.map +1 -0
- package/dist/test-utils.global.js +328 -70
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +332 -164
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +235 -71
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +17 -16
- package/dist/providers/utils/sleep.d.ts +0 -3
- package/dist/providers/utils/sleep.d.ts.map +0 -1
package/dist/test-utils.js
CHANGED
@@ -48,17 +48,21 @@ 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,
|
51
54
|
generateTestWallet: () => generateTestWallet,
|
52
55
|
killNode: () => killNode,
|
53
56
|
launchNode: () => launchNode,
|
54
57
|
launchNodeAndGetWallets: () => launchNodeAndGetWallets,
|
55
|
-
seedTestWallet: () => seedTestWallet
|
58
|
+
seedTestWallet: () => seedTestWallet,
|
59
|
+
setupTestProviderAndWallets: () => setupTestProviderAndWallets
|
56
60
|
});
|
57
61
|
module.exports = __toCommonJS(test_utils_exports);
|
58
62
|
|
59
63
|
// src/wallet/base-wallet-unlocked.ts
|
60
64
|
var import_hasher3 = require("@fuel-ts/hasher");
|
61
|
-
var
|
65
|
+
var import_utils31 = require("@fuel-ts/utils");
|
62
66
|
|
63
67
|
// src/account.ts
|
64
68
|
var import_address4 = require("@fuel-ts/address");
|
@@ -66,7 +70,7 @@ var import_configs11 = require("@fuel-ts/address/configs");
|
|
66
70
|
var import_errors15 = require("@fuel-ts/errors");
|
67
71
|
var import_interfaces = require("@fuel-ts/interfaces");
|
68
72
|
var import_math17 = require("@fuel-ts/math");
|
69
|
-
var
|
73
|
+
var import_utils28 = require("@fuel-ts/utils");
|
70
74
|
|
71
75
|
// src/providers/coin-quantity.ts
|
72
76
|
var import_configs = require("@fuel-ts/address/configs");
|
@@ -109,9 +113,9 @@ var import_address3 = require("@fuel-ts/address");
|
|
109
113
|
var import_errors13 = require("@fuel-ts/errors");
|
110
114
|
var import_math14 = require("@fuel-ts/math");
|
111
115
|
var import_transactions17 = require("@fuel-ts/transactions");
|
112
|
-
var
|
116
|
+
var import_utils23 = require("@fuel-ts/utils");
|
113
117
|
var import_versions = require("@fuel-ts/versions");
|
114
|
-
var
|
118
|
+
var import_utils24 = require("@noble/curves/abstract/utils");
|
115
119
|
var import_ethers = require("ethers");
|
116
120
|
var import_graphql_request = require("graphql-request");
|
117
121
|
var import_ramda3 = require("ramda");
|
@@ -1508,15 +1512,6 @@ function normalizeJSON(root) {
|
|
1508
1512
|
return normalize((0, import_ramda.clone)(root));
|
1509
1513
|
}
|
1510
1514
|
|
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
|
-
|
1520
1515
|
// src/providers/transaction-request/errors.ts
|
1521
1516
|
var NoWitnessAtIndexError = class extends Error {
|
1522
1517
|
constructor(index) {
|
@@ -1646,27 +1641,13 @@ var BaseTransactionRequest = class {
|
|
1646
1641
|
this.outputs.push(output);
|
1647
1642
|
return this.outputs.length - 1;
|
1648
1643
|
}
|
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
|
-
}
|
1661
1644
|
/**
|
1662
1645
|
* @hidden
|
1663
1646
|
*
|
1664
1647
|
* Creates an empty witness without any side effects and returns the index
|
1665
|
-
*
|
1666
|
-
* @returns The index of the created witness.
|
1667
1648
|
*/
|
1668
|
-
|
1669
|
-
this.
|
1649
|
+
createWitness() {
|
1650
|
+
this.witnesses.push((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
|
1670
1651
|
return this.witnesses.length - 1;
|
1671
1652
|
}
|
1672
1653
|
/**
|
@@ -1695,21 +1676,6 @@ var BaseTransactionRequest = class {
|
|
1695
1676
|
}
|
1696
1677
|
this.witnesses[index] = witness;
|
1697
1678
|
}
|
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
|
-
}
|
1713
1679
|
/**
|
1714
1680
|
* Gets the coin inputs for a transaction.
|
1715
1681
|
*
|
@@ -1775,7 +1741,7 @@ var BaseTransactionRequest = class {
|
|
1775
1741
|
} else {
|
1776
1742
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
1777
1743
|
if (typeof witnessIndex !== "number") {
|
1778
|
-
witnessIndex = this.
|
1744
|
+
witnessIndex = this.createWitness();
|
1779
1745
|
}
|
1780
1746
|
}
|
1781
1747
|
const input = {
|
@@ -1809,7 +1775,7 @@ var BaseTransactionRequest = class {
|
|
1809
1775
|
} else {
|
1810
1776
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
1811
1777
|
if (typeof witnessIndex !== "number") {
|
1812
|
-
witnessIndex = this.
|
1778
|
+
witnessIndex = this.createWitness();
|
1813
1779
|
}
|
1814
1780
|
}
|
1815
1781
|
const input = {
|
@@ -3331,6 +3297,7 @@ var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
|
3331
3297
|
var import_transactions16 = require("@fuel-ts/transactions");
|
3332
3298
|
|
3333
3299
|
// src/providers/utils/auto-retry-fetch.ts
|
3300
|
+
var import_utils22 = require("@fuel-ts/utils");
|
3334
3301
|
function getWaitDelay(options, retryAttemptNum) {
|
3335
3302
|
const duration = options.baseDelay ?? 150;
|
3336
3303
|
switch (options.backoff) {
|
@@ -3360,7 +3327,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
3360
3327
|
throw error;
|
3361
3328
|
}
|
3362
3329
|
const delay = getWaitDelay(options, retryNum);
|
3363
|
-
await sleep(delay);
|
3330
|
+
await (0, import_utils22.sleep)(delay);
|
3364
3331
|
return autoRetryFetch(fetchFn, options, retryNum)(...args);
|
3365
3332
|
}
|
3366
3333
|
};
|
@@ -3663,7 +3630,7 @@ var _Provider = class {
|
|
3663
3630
|
if (estimateTxDependencies) {
|
3664
3631
|
await this.estimateTxDependencies(transactionRequest);
|
3665
3632
|
}
|
3666
|
-
const encodedTransaction = (0,
|
3633
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3667
3634
|
if (awaitExecution) {
|
3668
3635
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3669
3636
|
for await (const { submitAndAwait } of subscription) {
|
@@ -3702,7 +3669,7 @@ var _Provider = class {
|
|
3702
3669
|
if (estimateTxDependencies) {
|
3703
3670
|
return this.estimateTxDependencies(transactionRequest);
|
3704
3671
|
}
|
3705
|
-
const encodedTransaction = (0,
|
3672
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3706
3673
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3707
3674
|
encodedTransaction,
|
3708
3675
|
utxoValidation: utxoValidation || false
|
@@ -3721,13 +3688,13 @@ var _Provider = class {
|
|
3721
3688
|
async estimatePredicates(transactionRequest) {
|
3722
3689
|
const shouldEstimatePredicates = Boolean(
|
3723
3690
|
transactionRequest.inputs.find(
|
3724
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3691
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils24.equalBytes)((0, import_utils23.arrayify)(input.predicate), (0, import_utils23.arrayify)("0x")) && new import_math14.BN(input.predicateGasUsed).isZero()
|
3725
3692
|
)
|
3726
3693
|
);
|
3727
3694
|
if (!shouldEstimatePredicates) {
|
3728
3695
|
return transactionRequest;
|
3729
3696
|
}
|
3730
|
-
const encodedTransaction = (0,
|
3697
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3731
3698
|
const response = await this.operations.estimatePredicates({
|
3732
3699
|
encodedTransaction
|
3733
3700
|
});
|
@@ -3770,7 +3737,7 @@ var _Provider = class {
|
|
3770
3737
|
let outputVariables = 0;
|
3771
3738
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3772
3739
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3773
|
-
encodedTransaction: (0,
|
3740
|
+
encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
|
3774
3741
|
utxoValidation: false
|
3775
3742
|
});
|
3776
3743
|
receipts = gqlReceipts.map(processGqlReceipt);
|
@@ -3808,7 +3775,7 @@ var _Provider = class {
|
|
3808
3775
|
if (estimateTxDependencies) {
|
3809
3776
|
return this.estimateTxDependencies(transactionRequest);
|
3810
3777
|
}
|
3811
|
-
const encodedTransaction = (0,
|
3778
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3812
3779
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3813
3780
|
encodedTransaction,
|
3814
3781
|
utxoValidation: true
|
@@ -3918,7 +3885,7 @@ var _Provider = class {
|
|
3918
3885
|
const result = await this.operations.getCoins({
|
3919
3886
|
first: 10,
|
3920
3887
|
...paginationArgs,
|
3921
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
3888
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
3922
3889
|
});
|
3923
3890
|
const coins = result.coins.edges.map((edge) => edge.node);
|
3924
3891
|
return coins.map((coin) => ({
|
@@ -3942,19 +3909,19 @@ var _Provider = class {
|
|
3942
3909
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
3943
3910
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
3944
3911
|
const excludeInput = {
|
3945
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
3946
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
3912
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
3913
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
3947
3914
|
};
|
3948
3915
|
if (this.cache) {
|
3949
3916
|
const uniqueUtxos = new Set(
|
3950
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
3917
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
3951
3918
|
);
|
3952
3919
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
3953
3920
|
}
|
3954
3921
|
const coinsQuery = {
|
3955
3922
|
owner: ownerAddress.toB256(),
|
3956
3923
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
3957
|
-
assetId: (0,
|
3924
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
3958
3925
|
amount: amount.toString(10),
|
3959
3926
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
3960
3927
|
})),
|
@@ -4057,7 +4024,7 @@ var _Provider = class {
|
|
4057
4024
|
time: block.header.time,
|
4058
4025
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4059
4026
|
transactions: block.transactions.map(
|
4060
|
-
(tx) => new import_transactions17.TransactionCoder().decode((0,
|
4027
|
+
(tx) => new import_transactions17.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4061
4028
|
)
|
4062
4029
|
};
|
4063
4030
|
}
|
@@ -4073,7 +4040,7 @@ var _Provider = class {
|
|
4073
4040
|
return null;
|
4074
4041
|
}
|
4075
4042
|
return new import_transactions17.TransactionCoder().decode(
|
4076
|
-
(0,
|
4043
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4077
4044
|
0
|
4078
4045
|
)?.[0];
|
4079
4046
|
}
|
@@ -4100,7 +4067,7 @@ var _Provider = class {
|
|
4100
4067
|
async getContractBalance(contractId, assetId) {
|
4101
4068
|
const { contractBalance } = await this.operations.getContractBalance({
|
4102
4069
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4103
|
-
asset: (0,
|
4070
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4104
4071
|
});
|
4105
4072
|
return (0, import_math14.bn)(contractBalance.amount, 10);
|
4106
4073
|
}
|
@@ -4114,7 +4081,7 @@ var _Provider = class {
|
|
4114
4081
|
async getBalance(owner, assetId) {
|
4115
4082
|
const { balance } = await this.operations.getBalance({
|
4116
4083
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4117
|
-
assetId: (0,
|
4084
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4118
4085
|
});
|
4119
4086
|
return (0, import_math14.bn)(balance.amount, 10);
|
4120
4087
|
}
|
@@ -4275,7 +4242,7 @@ var _Provider = class {
|
|
4275
4242
|
async produceBlocks(amount, startTime) {
|
4276
4243
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4277
4244
|
blocksToProduce: (0, import_math14.bn)(amount).toString(10),
|
4278
|
-
startTimestamp: startTime ?
|
4245
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4279
4246
|
});
|
4280
4247
|
return (0, import_math14.bn)(latestBlockHeight);
|
4281
4248
|
}
|
@@ -4303,7 +4270,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4303
4270
|
var import_errors14 = require("@fuel-ts/errors");
|
4304
4271
|
var import_math15 = require("@fuel-ts/math");
|
4305
4272
|
var import_transactions18 = require("@fuel-ts/transactions");
|
4306
|
-
var
|
4273
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4307
4274
|
|
4308
4275
|
// src/providers/chains.ts
|
4309
4276
|
var CHAIN_IDS = {
|
@@ -4353,16 +4320,16 @@ var assets = [
|
|
4353
4320
|
// src/utils/formatTransferToContractScriptData.ts
|
4354
4321
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
4355
4322
|
var import_math16 = require("@fuel-ts/math");
|
4356
|
-
var
|
4323
|
+
var import_utils27 = require("@fuel-ts/utils");
|
4357
4324
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4358
4325
|
var formatTransferToContractScriptData = (params) => {
|
4359
4326
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4360
4327
|
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
4361
4328
|
const encoded = numberCoder.encode(new import_math16.BN(amountToTransfer).toNumber());
|
4362
4329
|
const scriptData = Uint8Array.from([
|
4363
|
-
...(0,
|
4330
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
4364
4331
|
...encoded,
|
4365
|
-
...(0,
|
4332
|
+
...(0, import_utils27.arrayify)(assetId)
|
4366
4333
|
]);
|
4367
4334
|
return scriptData;
|
4368
4335
|
};
|
@@ -4702,14 +4669,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4702
4669
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4703
4670
|
const { minGasPrice } = this.provider.getGasConfig();
|
4704
4671
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
4705
|
-
const recipientDataArray = (0,
|
4672
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
4706
4673
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4707
4674
|
);
|
4708
|
-
const amountDataArray = (0,
|
4675
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
4709
4676
|
"0x".concat((0, import_math17.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
4710
4677
|
);
|
4711
4678
|
const script = new Uint8Array([
|
4712
|
-
...(0,
|
4679
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
4713
4680
|
...recipientDataArray,
|
4714
4681
|
...amountDataArray
|
4715
4682
|
]);
|
@@ -4736,21 +4703,6 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4736
4703
|
}
|
4737
4704
|
return this._connector.signMessage(this.address.toString(), message);
|
4738
4705
|
}
|
4739
|
-
/**
|
4740
|
-
* Signs a transaction with the wallet's private key.
|
4741
|
-
*
|
4742
|
-
* @param transactionRequestLike - The transaction request to sign.
|
4743
|
-
* @returns A promise that resolves to the signature of the transaction.
|
4744
|
-
*/
|
4745
|
-
async signTransaction(transactionRequestLike) {
|
4746
|
-
if (!this._connector) {
|
4747
|
-
throw new import_errors15.FuelError(
|
4748
|
-
import_errors15.ErrorCode.MISSING_CONNECTOR,
|
4749
|
-
"A connector is required to sign transactions."
|
4750
|
-
);
|
4751
|
-
}
|
4752
|
-
return this._connector.signTransaction(this.address.toString(), transactionRequestLike);
|
4753
|
-
}
|
4754
4706
|
/**
|
4755
4707
|
* Sends a transaction to the network.
|
4756
4708
|
*
|
@@ -4811,7 +4763,7 @@ var import_address5 = require("@fuel-ts/address");
|
|
4811
4763
|
var import_crypto = require("@fuel-ts/crypto");
|
4812
4764
|
var import_hasher2 = require("@fuel-ts/hasher");
|
4813
4765
|
var import_math18 = require("@fuel-ts/math");
|
4814
|
-
var
|
4766
|
+
var import_utils29 = require("@fuel-ts/utils");
|
4815
4767
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
4816
4768
|
var Signer = class {
|
4817
4769
|
address;
|
@@ -4831,9 +4783,9 @@ var Signer = class {
|
|
4831
4783
|
}
|
4832
4784
|
}
|
4833
4785
|
const privateKeyBytes = (0, import_math18.toBytes)(privateKey, 32);
|
4834
|
-
this.privateKey = (0,
|
4835
|
-
this.publicKey = (0,
|
4836
|
-
this.compressedPublicKey = (0,
|
4786
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
4787
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
4788
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
4837
4789
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
4838
4790
|
}
|
4839
4791
|
/**
|
@@ -4847,11 +4799,11 @@ var Signer = class {
|
|
4847
4799
|
* @returns hashed signature
|
4848
4800
|
*/
|
4849
4801
|
sign(data) {
|
4850
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
4802
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
4851
4803
|
const r = (0, import_math18.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
4852
4804
|
const s = (0, import_math18.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
4853
4805
|
s[0] |= (signature.recovery || 0) << 7;
|
4854
|
-
return (0,
|
4806
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
4855
4807
|
}
|
4856
4808
|
/**
|
4857
4809
|
* Add point on the current elliptic curve
|
@@ -4860,8 +4812,8 @@ var Signer = class {
|
|
4860
4812
|
* @returns compressed point on the curve
|
4861
4813
|
*/
|
4862
4814
|
addPoint(point) {
|
4863
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4864
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4815
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
4816
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
4865
4817
|
const result = p0.add(p1);
|
4866
4818
|
return `0x${result.toHex(true)}`;
|
4867
4819
|
}
|
@@ -4873,16 +4825,16 @@ var Signer = class {
|
|
4873
4825
|
* @returns public key from signature from the
|
4874
4826
|
*/
|
4875
4827
|
static recoverPublicKey(data, signature) {
|
4876
|
-
const signedMessageBytes = (0,
|
4828
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
4877
4829
|
const r = signedMessageBytes.slice(0, 32);
|
4878
4830
|
const s = signedMessageBytes.slice(32, 64);
|
4879
4831
|
const recoveryParam = (s[0] & 128) >> 7;
|
4880
4832
|
s[0] &= 127;
|
4881
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
4833
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
4882
4834
|
recoveryParam
|
4883
4835
|
);
|
4884
|
-
const publicKey = sig.recoverPublicKey((0,
|
4885
|
-
return (0,
|
4836
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
4837
|
+
return (0, import_utils29.hexlify)(publicKey);
|
4886
4838
|
}
|
4887
4839
|
/**
|
4888
4840
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -4901,7 +4853,7 @@ var Signer = class {
|
|
4901
4853
|
* @returns random 32-byte hashed
|
4902
4854
|
*/
|
4903
4855
|
static generatePrivateKey(entropy) {
|
4904
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
4856
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
|
4905
4857
|
}
|
4906
4858
|
/**
|
4907
4859
|
* Extended publicKey from a compact publicKey
|
@@ -4910,8 +4862,8 @@ var Signer = class {
|
|
4910
4862
|
* @returns extended publicKey
|
4911
4863
|
*/
|
4912
4864
|
static extendPublicKey(publicKey) {
|
4913
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4914
|
-
return (0,
|
4865
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
4866
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
4915
4867
|
}
|
4916
4868
|
};
|
4917
4869
|
|
@@ -4919,7 +4871,7 @@ var Signer = class {
|
|
4919
4871
|
var import_address6 = require("@fuel-ts/address");
|
4920
4872
|
var import_crypto2 = require("@fuel-ts/crypto");
|
4921
4873
|
var import_errors16 = require("@fuel-ts/errors");
|
4922
|
-
var
|
4874
|
+
var import_utils30 = require("@fuel-ts/utils");
|
4923
4875
|
var import_uuid = require("uuid");
|
4924
4876
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
4925
4877
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5002,7 +4954,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5002
4954
|
);
|
5003
4955
|
}
|
5004
4956
|
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5005
|
-
const privateKey = (0,
|
4957
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5006
4958
|
return privateKey;
|
5007
4959
|
}
|
5008
4960
|
|
@@ -5047,7 +4999,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5047
4999
|
*/
|
5048
5000
|
async signMessage(message) {
|
5049
5001
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5050
|
-
return (0,
|
5002
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5051
5003
|
}
|
5052
5004
|
/**
|
5053
5005
|
* Signs a transaction with the wallet's private key.
|
@@ -5057,10 +5009,10 @@ var BaseWalletUnlocked = class extends Account {
|
|
5057
5009
|
*/
|
5058
5010
|
async signTransaction(transactionRequestLike) {
|
5059
5011
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5060
|
-
const chainId = this.provider.
|
5012
|
+
const chainId = this.provider.getChain().consensusParameters.chainId.toNumber();
|
5061
5013
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5062
5014
|
const signature = await this.signer().sign(hashedTransaction);
|
5063
|
-
return (0,
|
5015
|
+
return (0, import_utils31.hexlify)(signature);
|
5064
5016
|
}
|
5065
5017
|
/**
|
5066
5018
|
* Populates a transaction with the witnesses signature.
|
@@ -5122,14 +5074,14 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5122
5074
|
var import_errors19 = require("@fuel-ts/errors");
|
5123
5075
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5124
5076
|
var import_math19 = require("@fuel-ts/math");
|
5125
|
-
var
|
5077
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5126
5078
|
var import_ethers3 = require("ethers");
|
5127
5079
|
|
5128
5080
|
// src/mnemonic/mnemonic.ts
|
5129
5081
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5130
5082
|
var import_errors18 = require("@fuel-ts/errors");
|
5131
5083
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5132
|
-
var
|
5084
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5133
5085
|
var import_ethers2 = require("ethers");
|
5134
5086
|
|
5135
5087
|
// src/wordlists/words/english.ts
|
@@ -7187,7 +7139,7 @@ var english = [
|
|
7187
7139
|
// src/mnemonic/utils.ts
|
7188
7140
|
var import_errors17 = require("@fuel-ts/errors");
|
7189
7141
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7190
|
-
var
|
7142
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7191
7143
|
function toUtf8Bytes(stri) {
|
7192
7144
|
const str = stri.normalize("NFKD");
|
7193
7145
|
const result = [];
|
@@ -7254,14 +7206,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7254
7206
|
}
|
7255
7207
|
}
|
7256
7208
|
const checksumBits = entropy.length / 4;
|
7257
|
-
const checksum = (0,
|
7209
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7258
7210
|
indices[indices.length - 1] <<= checksumBits;
|
7259
7211
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7260
7212
|
return indices;
|
7261
7213
|
}
|
7262
7214
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7263
7215
|
const size = Math.ceil(11 * words.length / 8);
|
7264
|
-
const entropy = (0,
|
7216
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
7265
7217
|
let offset = 0;
|
7266
7218
|
for (let i = 0; i < words.length; i += 1) {
|
7267
7219
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7281,7 +7233,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7281
7233
|
const entropyBits = 32 * words.length / 3;
|
7282
7234
|
const checksumBits = words.length / 3;
|
7283
7235
|
const checksumMask = getUpperMask(checksumBits);
|
7284
|
-
const checksum = (0,
|
7236
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7285
7237
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7286
7238
|
throw new import_errors17.FuelError(
|
7287
7239
|
import_errors17.ErrorCode.INVALID_CHECKSUM,
|
@@ -7356,7 +7308,7 @@ var Mnemonic = class {
|
|
7356
7308
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7357
7309
|
const words = getWords(phrase);
|
7358
7310
|
assertMnemonic(words);
|
7359
|
-
return (0,
|
7311
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7360
7312
|
}
|
7361
7313
|
/**
|
7362
7314
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7364,7 +7316,7 @@ var Mnemonic = class {
|
|
7364
7316
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7365
7317
|
*/
|
7366
7318
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7367
|
-
const entropyBytes = (0,
|
7319
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
7368
7320
|
assertWordList(wordlist);
|
7369
7321
|
assertEntropy(entropyBytes);
|
7370
7322
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7433,14 +7385,14 @@ var Mnemonic = class {
|
|
7433
7385
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7434
7386
|
*/
|
7435
7387
|
static masterKeysFromSeed(seed) {
|
7436
|
-
const seedArray = (0,
|
7388
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
7437
7389
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7438
7390
|
throw new import_errors18.FuelError(
|
7439
7391
|
import_errors18.ErrorCode.INVALID_SEED,
|
7440
7392
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7441
7393
|
);
|
7442
7394
|
}
|
7443
|
-
return (0,
|
7395
|
+
return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7444
7396
|
}
|
7445
7397
|
/**
|
7446
7398
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7451,22 +7403,22 @@ var Mnemonic = class {
|
|
7451
7403
|
*/
|
7452
7404
|
static seedToExtendedKey(seed, testnet = false) {
|
7453
7405
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7454
|
-
const prefix = (0,
|
7406
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7455
7407
|
const depth = "0x00";
|
7456
7408
|
const fingerprint = "0x00000000";
|
7457
7409
|
const index = "0x00000000";
|
7458
7410
|
const chainCode = masterKey.slice(32);
|
7459
7411
|
const privateKey = masterKey.slice(0, 32);
|
7460
|
-
const extendedKey = (0,
|
7412
|
+
const extendedKey = (0, import_utils33.concat)([
|
7461
7413
|
prefix,
|
7462
7414
|
depth,
|
7463
7415
|
fingerprint,
|
7464
7416
|
index,
|
7465
7417
|
chainCode,
|
7466
|
-
(0,
|
7418
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
7467
7419
|
]);
|
7468
7420
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7469
|
-
return (0, import_ethers2.encodeBase58)((0,
|
7421
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
7470
7422
|
}
|
7471
7423
|
/**
|
7472
7424
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7481,7 +7433,7 @@ var Mnemonic = class {
|
|
7481
7433
|
* @returns A randomly generated mnemonic
|
7482
7434
|
*/
|
7483
7435
|
static generate(size = 32, extraEntropy = "") {
|
7484
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7436
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
|
7485
7437
|
return Mnemonic.entropyToMnemonic(entropy);
|
7486
7438
|
}
|
7487
7439
|
};
|
@@ -7489,12 +7441,12 @@ var mnemonic_default = Mnemonic;
|
|
7489
7441
|
|
7490
7442
|
// src/hdwallet/hdwallet.ts
|
7491
7443
|
var HARDENED_INDEX = 2147483648;
|
7492
|
-
var MainnetPRV2 = (0,
|
7493
|
-
var MainnetPUB = (0,
|
7494
|
-
var TestnetPRV2 = (0,
|
7495
|
-
var TestnetPUB = (0,
|
7444
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
7445
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
7446
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
7447
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
7496
7448
|
function base58check(data) {
|
7497
|
-
return (0, import_ethers3.encodeBase58)((0,
|
7449
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils35.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
7498
7450
|
}
|
7499
7451
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7500
7452
|
if (isPublic) {
|
@@ -7503,11 +7455,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7503
7455
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7504
7456
|
}
|
7505
7457
|
function isPublicExtendedKey(extendedKey) {
|
7506
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7458
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
7507
7459
|
}
|
7508
7460
|
function isValidExtendedKey(extendedKey) {
|
7509
7461
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7510
|
-
(0,
|
7462
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
7511
7463
|
);
|
7512
7464
|
}
|
7513
7465
|
function parsePath(path2, depth = 0) {
|
@@ -7525,8 +7477,8 @@ function parsePath(path2, depth = 0) {
|
|
7525
7477
|
var HDWallet = class {
|
7526
7478
|
depth = 0;
|
7527
7479
|
index = 0;
|
7528
|
-
fingerprint = (0,
|
7529
|
-
parentFingerprint = (0,
|
7480
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7481
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7530
7482
|
privateKey;
|
7531
7483
|
publicKey;
|
7532
7484
|
chainCode;
|
@@ -7538,8 +7490,8 @@ var HDWallet = class {
|
|
7538
7490
|
constructor(config) {
|
7539
7491
|
if (config.privateKey) {
|
7540
7492
|
const signer = new Signer(config.privateKey);
|
7541
|
-
this.publicKey = (0,
|
7542
|
-
this.privateKey = (0,
|
7493
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
7494
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
7543
7495
|
} else {
|
7544
7496
|
if (!config.publicKey) {
|
7545
7497
|
throw new import_errors19.FuelError(
|
@@ -7547,7 +7499,7 @@ var HDWallet = class {
|
|
7547
7499
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7548
7500
|
);
|
7549
7501
|
}
|
7550
|
-
this.publicKey = (0,
|
7502
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
7551
7503
|
}
|
7552
7504
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7553
7505
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -7566,9 +7518,9 @@ var HDWallet = class {
|
|
7566
7518
|
* @returns A new instance of HDWallet on the derived index
|
7567
7519
|
*/
|
7568
7520
|
deriveIndex(index) {
|
7569
|
-
const privateKey = this.privateKey && (0,
|
7570
|
-
const publicKey = (0,
|
7571
|
-
const chainCode = (0,
|
7521
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
7522
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
7523
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
7572
7524
|
const data = new Uint8Array(37);
|
7573
7525
|
if (index & HARDENED_INDEX) {
|
7574
7526
|
if (!privateKey) {
|
@@ -7579,10 +7531,10 @@ var HDWallet = class {
|
|
7579
7531
|
}
|
7580
7532
|
data.set(privateKey, 1);
|
7581
7533
|
} else {
|
7582
|
-
data.set((0,
|
7534
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
7583
7535
|
}
|
7584
7536
|
data.set((0, import_math19.toBytes)(index, 4), 33);
|
7585
|
-
const bytes = (0,
|
7537
|
+
const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
7586
7538
|
const IL = bytes.slice(0, 32);
|
7587
7539
|
const IR = bytes.slice(32);
|
7588
7540
|
if (privateKey) {
|
@@ -7596,7 +7548,7 @@ var HDWallet = class {
|
|
7596
7548
|
parentFingerprint: this.fingerprint
|
7597
7549
|
});
|
7598
7550
|
}
|
7599
|
-
const signer = new Signer((0,
|
7551
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
7600
7552
|
const Ki = signer.addPoint(publicKey);
|
7601
7553
|
return new HDWallet({
|
7602
7554
|
publicKey: Ki,
|
@@ -7631,12 +7583,12 @@ var HDWallet = class {
|
|
7631
7583
|
);
|
7632
7584
|
}
|
7633
7585
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7634
|
-
const depth = (0,
|
7586
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
7635
7587
|
const parentFingerprint = this.parentFingerprint;
|
7636
7588
|
const index = (0, import_math19.toHex)(this.index, 4);
|
7637
7589
|
const chainCode = this.chainCode;
|
7638
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7639
|
-
const extendedKey = (0,
|
7590
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
7591
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7640
7592
|
return base58check(extendedKey);
|
7641
7593
|
}
|
7642
7594
|
/**
|
@@ -7648,13 +7600,13 @@ var HDWallet = class {
|
|
7648
7600
|
static fromSeed(seed) {
|
7649
7601
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
7650
7602
|
return new HDWallet({
|
7651
|
-
chainCode: (0,
|
7652
|
-
privateKey: (0,
|
7603
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
7604
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
7653
7605
|
});
|
7654
7606
|
}
|
7655
7607
|
static fromExtendedKey(extendedKey) {
|
7656
7608
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
7657
|
-
const bytes = (0,
|
7609
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
7658
7610
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7659
7611
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7660
7612
|
throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -7663,9 +7615,9 @@ var HDWallet = class {
|
|
7663
7615
|
throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7664
7616
|
}
|
7665
7617
|
const depth = bytes[4];
|
7666
|
-
const parentFingerprint = (0,
|
7667
|
-
const index = parseInt((0,
|
7668
|
-
const chainCode = (0,
|
7618
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
7619
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
7620
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
7669
7621
|
const key = bytes.slice(45, 78);
|
7670
7622
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7671
7623
|
throw new import_errors19.FuelError(
|
@@ -7881,7 +7833,7 @@ var generateTestWallet = async (provider, quantities) => {
|
|
7881
7833
|
// src/test-utils/launchNode.ts
|
7882
7834
|
var import_configs12 = require("@fuel-ts/address/configs");
|
7883
7835
|
var import_math20 = require("@fuel-ts/math");
|
7884
|
-
var
|
7836
|
+
var import_utils36 = require("@fuel-ts/utils");
|
7885
7837
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
7886
7838
|
var import_child_process = require("child_process");
|
7887
7839
|
var import_crypto5 = require("crypto");
|
@@ -7928,7 +7880,8 @@ var launchNode = async ({
|
|
7928
7880
|
useSystemFuelCore = false,
|
7929
7881
|
loggingEnabled = true,
|
7930
7882
|
debugEnabled = false,
|
7931
|
-
basePath
|
7883
|
+
basePath,
|
7884
|
+
chainConfig = import_utils36.defaultChainConfig
|
7932
7885
|
}) => (
|
7933
7886
|
// eslint-disable-next-line no-async-promise-executor
|
7934
7887
|
new Promise(async (resolve, reject) => {
|
@@ -7939,7 +7892,7 @@ var launchNode = async ({
|
|
7939
7892
|
"--poa-instant"
|
7940
7893
|
]);
|
7941
7894
|
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
7942
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
7895
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
|
7943
7896
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
7944
7897
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
7945
7898
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -7965,17 +7918,17 @@ var launchNode = async ({
|
|
7965
7918
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
7966
7919
|
}
|
7967
7920
|
const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
7968
|
-
let
|
7921
|
+
let generatedChainConfig = chainConfig;
|
7969
7922
|
if (!process.env.GENESIS_SECRET) {
|
7970
7923
|
const pk = Signer.generatePrivateKey();
|
7971
7924
|
const signer = new Signer(pk);
|
7972
|
-
process.env.GENESIS_SECRET = (0,
|
7973
|
-
|
7974
|
-
...
|
7925
|
+
process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
|
7926
|
+
generatedChainConfig = {
|
7927
|
+
...generatedChainConfig,
|
7975
7928
|
initial_state: {
|
7976
|
-
...
|
7929
|
+
...generatedChainConfig.initial_state,
|
7977
7930
|
coins: [
|
7978
|
-
...
|
7931
|
+
...generatedChainConfig.initial_state.coins,
|
7979
7932
|
{
|
7980
7933
|
owner: signer.address.toHexString(),
|
7981
7934
|
amount: (0, import_math20.toHex)(1e9),
|
@@ -7985,7 +7938,7 @@ var launchNode = async ({
|
|
7985
7938
|
}
|
7986
7939
|
};
|
7987
7940
|
}
|
7988
|
-
(0, import_fs.writeFileSync)(tempChainConfigFilePath, JSON.stringify(
|
7941
|
+
(0, import_fs.writeFileSync)(tempChainConfigFilePath, JSON.stringify(generatedChainConfig), "utf8");
|
7989
7942
|
chainConfigPathToUse = tempChainConfigFilePath;
|
7990
7943
|
}
|
7991
7944
|
const child = (0, import_child_process.spawn)(
|
@@ -8023,16 +7976,21 @@ var launchNode = async ({
|
|
8023
7976
|
}
|
8024
7977
|
};
|
8025
7978
|
child.stderr.on("data", (chunk) => {
|
8026
|
-
|
7979
|
+
const text = typeof chunk === "string" ? chunk : chunk.toString();
|
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(":");
|
8027
7984
|
resolve({
|
8028
7985
|
cleanup: () => killNode(cleanupConfig),
|
8029
|
-
ip:
|
8030
|
-
port:
|
7986
|
+
ip: realIp,
|
7987
|
+
port: realPort,
|
7988
|
+
url: `http://${realIp}:${realPort}/graphql`,
|
8031
7989
|
chainConfigPath: chainConfigPathToUse
|
8032
7990
|
});
|
8033
7991
|
}
|
8034
|
-
if (/error/i.test(
|
8035
|
-
reject(
|
7992
|
+
if (/error/i.test(text)) {
|
7993
|
+
reject(text.toString());
|
8036
7994
|
}
|
8037
7995
|
});
|
8038
7996
|
process.on("exit", () => killNode(cleanupConfig));
|
@@ -8064,12 +8022,222 @@ var launchNodeAndGetWallets = async ({
|
|
8064
8022
|
};
|
8065
8023
|
return { wallets, stop: cleanup, provider };
|
8066
8024
|
};
|
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
|
+
};
|
8067
8231
|
// Annotate the CommonJS export names for ESM import in node:
|
8068
8232
|
0 && (module.exports = {
|
8233
|
+
AssetId,
|
8234
|
+
TestMessage,
|
8235
|
+
WalletConfig,
|
8069
8236
|
generateTestWallet,
|
8070
8237
|
killNode,
|
8071
8238
|
launchNode,
|
8072
8239
|
launchNodeAndGetWallets,
|
8073
|
-
seedTestWallet
|
8240
|
+
seedTestWallet,
|
8241
|
+
setupTestProviderAndWallets
|
8074
8242
|
});
|
8075
8243
|
//# sourceMappingURL=test-utils.js.map
|