@fuel-ts/account 0.0.0-rc-2034-20240410133013 → 0.0.0-rc-1976-20240410141707
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/dist/account.d.ts.map +1 -1
- package/dist/index.global.js +90 -113
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +127 -132
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -89
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +2 -2
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +9 -15
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +5 -2
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +94 -116
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +128 -132
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +87 -91
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.mjs
CHANGED
@@ -24,14 +24,12 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
24
24
|
|
25
25
|
// src/account.ts
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
|
-
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
28
27
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
29
28
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
30
29
|
import { bn as bn17 } from "@fuel-ts/math";
|
31
30
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
32
31
|
|
33
32
|
// src/providers/coin-quantity.ts
|
34
|
-
import { BaseAssetId } from "@fuel-ts/address/configs";
|
35
33
|
import { bn } from "@fuel-ts/math";
|
36
34
|
import { hexlify } from "@fuel-ts/utils";
|
37
35
|
var coinQuantityfy = (coinQuantityLike) => {
|
@@ -40,11 +38,11 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
40
38
|
let max2;
|
41
39
|
if (Array.isArray(coinQuantityLike)) {
|
42
40
|
amount = coinQuantityLike[0];
|
43
|
-
assetId = coinQuantityLike[1]
|
44
|
-
max2 = coinQuantityLike[2]
|
41
|
+
assetId = coinQuantityLike[1];
|
42
|
+
max2 = coinQuantityLike[2];
|
45
43
|
} else {
|
46
44
|
amount = coinQuantityLike.amount;
|
47
|
-
assetId = coinQuantityLike.assetId
|
45
|
+
assetId = coinQuantityLike.assetId;
|
48
46
|
max2 = coinQuantityLike.max ?? void 0;
|
49
47
|
}
|
50
48
|
const bnAmount = bn(amount);
|
@@ -1032,7 +1030,7 @@ var inputify = (value) => {
|
|
1032
1030
|
return {
|
1033
1031
|
type: InputType.Coin,
|
1034
1032
|
txID: hexlify3(arrayify(value.id).slice(0, 32)),
|
1035
|
-
outputIndex:
|
1033
|
+
outputIndex: arrayify(value.id)[32],
|
1036
1034
|
owner: hexlify3(value.owner),
|
1037
1035
|
amount: bn2(value.amount),
|
1038
1036
|
assetId: hexlify3(value.assetId),
|
@@ -1151,7 +1149,7 @@ var outputify = (value) => {
|
|
1151
1149
|
|
1152
1150
|
// src/providers/transaction-request/transaction-request.ts
|
1153
1151
|
import { Address, addressify } from "@fuel-ts/address";
|
1154
|
-
import {
|
1152
|
+
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1155
1153
|
import { bn as bn7 } from "@fuel-ts/math";
|
1156
1154
|
import {
|
1157
1155
|
PolicyType,
|
@@ -1161,7 +1159,6 @@ import {
|
|
1161
1159
|
TransactionType
|
1162
1160
|
} from "@fuel-ts/transactions";
|
1163
1161
|
import { concat, hexlify as hexlify7 } from "@fuel-ts/utils";
|
1164
|
-
import { randomBytes } from "ethers";
|
1165
1162
|
|
1166
1163
|
// src/providers/resource.ts
|
1167
1164
|
var isCoin = (resource) => "id" in resource;
|
@@ -1612,6 +1609,8 @@ var BaseTransactionRequest = class {
|
|
1612
1609
|
outputs = [];
|
1613
1610
|
/** List of witnesses */
|
1614
1611
|
witnesses = [];
|
1612
|
+
/** Base asset ID - should be fetched from the chain */
|
1613
|
+
baseAssetId = ZeroBytes324;
|
1615
1614
|
/**
|
1616
1615
|
* Constructor for initializing a base transaction request.
|
1617
1616
|
*
|
@@ -1624,7 +1623,8 @@ var BaseTransactionRequest = class {
|
|
1624
1623
|
witnessLimit,
|
1625
1624
|
inputs,
|
1626
1625
|
outputs,
|
1627
|
-
witnesses
|
1626
|
+
witnesses,
|
1627
|
+
baseAssetId
|
1628
1628
|
} = {}) {
|
1629
1629
|
this.gasPrice = bn7(gasPrice);
|
1630
1630
|
this.maturity = maturity ?? 0;
|
@@ -1633,6 +1633,7 @@ var BaseTransactionRequest = class {
|
|
1633
1633
|
this.inputs = inputs ?? [];
|
1634
1634
|
this.outputs = outputs ?? [];
|
1635
1635
|
this.witnesses = witnesses ?? [];
|
1636
|
+
this.baseAssetId = baseAssetId ?? ZeroBytes324;
|
1636
1637
|
}
|
1637
1638
|
static getPolicyMeta(req) {
|
1638
1639
|
let policyTypes = 0;
|
@@ -1856,11 +1857,9 @@ var BaseTransactionRequest = class {
|
|
1856
1857
|
*
|
1857
1858
|
* @param message - Message resource.
|
1858
1859
|
* @param predicate - Predicate bytes.
|
1859
|
-
* @param predicateData - Predicate data bytes.
|
1860
1860
|
*/
|
1861
1861
|
addMessageInput(message, predicate) {
|
1862
1862
|
const { recipient, sender, amount } = message;
|
1863
|
-
const assetId = BaseAssetId2;
|
1864
1863
|
let witnessIndex;
|
1865
1864
|
if (predicate) {
|
1866
1865
|
witnessIndex = 0;
|
@@ -1880,7 +1879,7 @@ var BaseTransactionRequest = class {
|
|
1880
1879
|
predicate: predicate?.bytes
|
1881
1880
|
};
|
1882
1881
|
this.pushInput(input);
|
1883
|
-
this.addChangeOutput(recipient,
|
1882
|
+
this.addChangeOutput(recipient, this.baseAssetId);
|
1884
1883
|
}
|
1885
1884
|
/**
|
1886
1885
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1941,12 +1940,12 @@ var BaseTransactionRequest = class {
|
|
1941
1940
|
* @param amount - Amount of coin.
|
1942
1941
|
* @param assetId - Asset ID of coin.
|
1943
1942
|
*/
|
1944
|
-
addCoinOutput(to, amount, assetId
|
1943
|
+
addCoinOutput(to, amount, assetId) {
|
1945
1944
|
this.pushOutput({
|
1946
1945
|
type: OutputType2.Coin,
|
1947
1946
|
to: addressify(to).toB256(),
|
1948
1947
|
amount,
|
1949
|
-
assetId
|
1948
|
+
assetId: assetId ?? this.baseAssetId
|
1950
1949
|
});
|
1951
1950
|
return this;
|
1952
1951
|
}
|
@@ -1973,7 +1972,7 @@ var BaseTransactionRequest = class {
|
|
1973
1972
|
* @param to - Address of the owner.
|
1974
1973
|
* @param assetId - Asset ID of coin.
|
1975
1974
|
*/
|
1976
|
-
addChangeOutput(to, assetId
|
1975
|
+
addChangeOutput(to, assetId) {
|
1977
1976
|
const changeOutput = this.getChangeOutputs().find(
|
1978
1977
|
(output) => hexlify7(output.assetId) === assetId
|
1979
1978
|
);
|
@@ -1981,7 +1980,7 @@ var BaseTransactionRequest = class {
|
|
1981
1980
|
this.pushOutput({
|
1982
1981
|
type: OutputType2.Change,
|
1983
1982
|
to: addressify(to).toB256(),
|
1984
|
-
assetId
|
1983
|
+
assetId: assetId ?? this.baseAssetId
|
1985
1984
|
});
|
1986
1985
|
}
|
1987
1986
|
}
|
@@ -2032,6 +2031,12 @@ var BaseTransactionRequest = class {
|
|
2032
2031
|
* @param quantities - CoinQuantity Array.
|
2033
2032
|
*/
|
2034
2033
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2034
|
+
let idCounter = 0;
|
2035
|
+
const generateId = () => {
|
2036
|
+
const counterString = String(idCounter++);
|
2037
|
+
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
2038
|
+
return id;
|
2039
|
+
};
|
2035
2040
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2036
2041
|
if ("assetId" in input) {
|
2037
2042
|
return input.assetId === assetId;
|
@@ -2041,12 +2046,12 @@ var BaseTransactionRequest = class {
|
|
2041
2046
|
const updateAssetInput = (assetId, quantity) => {
|
2042
2047
|
const assetInput = findAssetInput(assetId);
|
2043
2048
|
if (assetInput && "assetId" in assetInput) {
|
2044
|
-
assetInput.id =
|
2049
|
+
assetInput.id = generateId();
|
2045
2050
|
assetInput.amount = quantity;
|
2046
2051
|
} else {
|
2047
2052
|
this.addResources([
|
2048
2053
|
{
|
2049
|
-
id:
|
2054
|
+
id: generateId(),
|
2050
2055
|
amount: quantity,
|
2051
2056
|
assetId,
|
2052
2057
|
owner: resourcesOwner || Address.fromRandom(),
|
@@ -2057,7 +2062,7 @@ var BaseTransactionRequest = class {
|
|
2057
2062
|
]);
|
2058
2063
|
}
|
2059
2064
|
};
|
2060
|
-
updateAssetInput(
|
2065
|
+
updateAssetInput(this.baseAssetId, bn7(1e11));
|
2061
2066
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2062
2067
|
}
|
2063
2068
|
/**
|
@@ -3484,6 +3489,7 @@ var processGqlChain = (chain) => {
|
|
3484
3489
|
gasPerByte: bn15(feeParams.gasPerByte),
|
3485
3490
|
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3486
3491
|
chainId: bn15(consensusParameters.chainId),
|
3492
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3487
3493
|
gasCosts
|
3488
3494
|
},
|
3489
3495
|
gasCosts,
|
@@ -3726,6 +3732,17 @@ var _Provider = class {
|
|
3726
3732
|
} = this.getChain();
|
3727
3733
|
return chainId.toNumber();
|
3728
3734
|
}
|
3735
|
+
/**
|
3736
|
+
* Returns the base asset ID
|
3737
|
+
*
|
3738
|
+
* @returns A promise that resolves to the base asset ID
|
3739
|
+
*/
|
3740
|
+
getBaseAssetId() {
|
3741
|
+
const {
|
3742
|
+
consensusParameters: { baseAssetId }
|
3743
|
+
} = this.getChain();
|
3744
|
+
return baseAssetId;
|
3745
|
+
}
|
3729
3746
|
/**
|
3730
3747
|
* Submits a transaction to the chain to be executed.
|
3731
3748
|
*
|
@@ -3876,37 +3893,6 @@ var _Provider = class {
|
|
3876
3893
|
missingContractIds
|
3877
3894
|
};
|
3878
3895
|
}
|
3879
|
-
/**
|
3880
|
-
* Estimates the transaction gas and fee based on the provided transaction request.
|
3881
|
-
* @param transactionRequest - The transaction request object.
|
3882
|
-
* @param optimizeGas - Optional. Specifies whether to optimize the gas. Default is false.
|
3883
|
-
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3884
|
-
*/
|
3885
|
-
estimateTxGasAndFee(params) {
|
3886
|
-
const { transactionRequest } = params;
|
3887
|
-
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3888
|
-
const chainInfo = this.getChain();
|
3889
|
-
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3890
|
-
transactionRequest.gasPrice = gasPrice;
|
3891
|
-
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
3892
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3893
|
-
if (transactionRequest.type === TransactionType8.Script) {
|
3894
|
-
if (transactionRequest.gasLimit.eq(0)) {
|
3895
|
-
transactionRequest.gasLimit = minGas;
|
3896
|
-
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3897
|
-
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3898
|
-
);
|
3899
|
-
}
|
3900
|
-
}
|
3901
|
-
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
3902
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3903
|
-
return {
|
3904
|
-
minGas,
|
3905
|
-
minFee,
|
3906
|
-
maxGas,
|
3907
|
-
maxFee
|
3908
|
-
};
|
3909
|
-
}
|
3910
3896
|
/**
|
3911
3897
|
* Executes a signed transaction without applying the states changes
|
3912
3898
|
* on the chain.
|
@@ -3954,16 +3940,17 @@ var _Provider = class {
|
|
3954
3940
|
signatureCallback
|
3955
3941
|
} = {}) {
|
3956
3942
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3957
|
-
const
|
3958
|
-
const
|
3943
|
+
const chainInfo = this.getChain();
|
3944
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3945
|
+
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3959
3946
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
3960
3947
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3961
3948
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3962
3949
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3963
|
-
if (isScriptTransaction) {
|
3964
|
-
txRequestClone.gasLimit = bn15(0);
|
3965
|
-
}
|
3966
3950
|
if (estimatePredicates) {
|
3951
|
+
if (isScriptTransaction) {
|
3952
|
+
txRequestClone.gasLimit = bn15(0);
|
3953
|
+
}
|
3967
3954
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3968
3955
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3969
3956
|
}
|
@@ -3972,34 +3959,36 @@ var _Provider = class {
|
|
3972
3959
|
if (signatureCallback && isScriptTransaction) {
|
3973
3960
|
await signatureCallback(txRequestClone);
|
3974
3961
|
}
|
3975
|
-
|
3976
|
-
|
3977
|
-
});
|
3962
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
3963
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
3978
3964
|
let receipts = [];
|
3979
3965
|
let missingContractIds = [];
|
3980
3966
|
let outputVariables = 0;
|
3981
|
-
let gasUsed = bn15(0);
|
3982
3967
|
if (isScriptTransaction && estimateTxDependencies) {
|
3983
3968
|
txRequestClone.gasPrice = bn15(0);
|
3969
|
+
txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3984
3970
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3985
3971
|
receipts = result.receipts;
|
3986
3972
|
outputVariables = result.outputVariables;
|
3987
3973
|
missingContractIds = result.missingContractIds;
|
3988
|
-
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
3989
|
-
txRequestClone.gasLimit = gasUsed;
|
3990
|
-
txRequestClone.gasPrice = setGasPrice;
|
3991
|
-
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3992
|
-
transactionRequest: txRequestClone
|
3993
|
-
}));
|
3994
3974
|
}
|
3975
|
+
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3976
|
+
const usedFee = calculatePriceWithFactor(
|
3977
|
+
gasUsed,
|
3978
|
+
gasPrice,
|
3979
|
+
gasPriceFactor
|
3980
|
+
).normalizeZeroToOne();
|
3981
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3982
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3995
3983
|
return {
|
3996
3984
|
requiredQuantities: allQuantities,
|
3997
3985
|
receipts,
|
3998
3986
|
gasUsed,
|
3999
3987
|
minGasPrice,
|
4000
|
-
gasPrice
|
3988
|
+
gasPrice,
|
4001
3989
|
minGas,
|
4002
3990
|
maxGas,
|
3991
|
+
usedFee,
|
4003
3992
|
minFee,
|
4004
3993
|
maxFee,
|
4005
3994
|
estimatedInputs: txRequestClone.inputs,
|
@@ -4624,8 +4613,9 @@ var Account = class extends AbstractAccount {
|
|
4624
4613
|
* @param assetId - The asset ID to check the balance for.
|
4625
4614
|
* @returns A promise that resolves to the balance amount.
|
4626
4615
|
*/
|
4627
|
-
async getBalance(assetId
|
4628
|
-
const
|
4616
|
+
async getBalance(assetId) {
|
4617
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4618
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4629
4619
|
return amount;
|
4630
4620
|
}
|
4631
4621
|
/**
|
@@ -4663,9 +4653,10 @@ var Account = class extends AbstractAccount {
|
|
4663
4653
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4664
4654
|
*/
|
4665
4655
|
async fund(request, coinQuantities, fee) {
|
4656
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4666
4657
|
const updatedQuantities = addAmountToAsset({
|
4667
4658
|
amount: bn17(fee),
|
4668
|
-
assetId:
|
4659
|
+
assetId: baseAssetId,
|
4669
4660
|
coinQuantities
|
4670
4661
|
});
|
4671
4662
|
const quantitiesDict = {};
|
@@ -4689,8 +4680,8 @@ var Account = class extends AbstractAccount {
|
|
4689
4680
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4690
4681
|
cachedUtxos.push(input.id);
|
4691
4682
|
}
|
4692
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
4693
|
-
quantitiesDict[
|
4683
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
4684
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
4694
4685
|
cachedMessages.push(input.nonce);
|
4695
4686
|
}
|
4696
4687
|
}
|
@@ -4722,11 +4713,12 @@ var Account = class extends AbstractAccount {
|
|
4722
4713
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4723
4714
|
* @returns A promise that resolves to the prepared transaction request.
|
4724
4715
|
*/
|
4725
|
-
async createTransfer(destination, amount, assetId
|
4716
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4726
4717
|
const { minGasPrice } = this.provider.getGasConfig();
|
4718
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4727
4719
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4728
4720
|
const request = new ScriptTransactionRequest(params);
|
4729
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount,
|
4721
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4730
4722
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4731
4723
|
estimateTxDependencies: true,
|
4732
4724
|
resourcesOwner: this
|
@@ -4752,14 +4744,15 @@ var Account = class extends AbstractAccount {
|
|
4752
4744
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4753
4745
|
* @returns A promise that resolves to the transaction response.
|
4754
4746
|
*/
|
4755
|
-
async transfer(destination, amount, assetId
|
4747
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
4756
4748
|
if (bn17(amount).lte(0)) {
|
4757
4749
|
throw new FuelError15(
|
4758
4750
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4759
4751
|
"Transfer amount must be a positive number."
|
4760
4752
|
);
|
4761
4753
|
}
|
4762
|
-
const
|
4754
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4755
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4763
4756
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4764
4757
|
}
|
4765
4758
|
/**
|
@@ -4771,7 +4764,7 @@ var Account = class extends AbstractAccount {
|
|
4771
4764
|
* @param txParams - The optional transaction parameters.
|
4772
4765
|
* @returns A promise that resolves to the transaction response.
|
4773
4766
|
*/
|
4774
|
-
async transferToContract(contractId, amount, assetId
|
4767
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4775
4768
|
if (bn17(amount).lte(0)) {
|
4776
4769
|
throw new FuelError15(
|
4777
4770
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
@@ -4780,11 +4773,12 @@ var Account = class extends AbstractAccount {
|
|
4780
4773
|
}
|
4781
4774
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4782
4775
|
const { minGasPrice } = this.provider.getGasConfig();
|
4776
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4783
4777
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4784
4778
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4785
4779
|
hexlifiedContractId: contractAddress.toB256(),
|
4786
4780
|
amountToTransfer: bn17(amount),
|
4787
|
-
assetId
|
4781
|
+
assetId: assetIdToTransfer
|
4788
4782
|
});
|
4789
4783
|
const request = new ScriptTransactionRequest({
|
4790
4784
|
...params,
|
@@ -4794,7 +4788,7 @@ var Account = class extends AbstractAccount {
|
|
4794
4788
|
request.addContractInputAndOutput(contractAddress);
|
4795
4789
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4796
4790
|
request,
|
4797
|
-
[{ amount: bn17(amount), assetId: String(
|
4791
|
+
[{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
|
4798
4792
|
);
|
4799
4793
|
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4800
4794
|
this.validateGas({
|
@@ -4816,6 +4810,7 @@ var Account = class extends AbstractAccount {
|
|
4816
4810
|
*/
|
4817
4811
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4818
4812
|
const { minGasPrice } = this.provider.getGasConfig();
|
4813
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4819
4814
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
4820
4815
|
const recipientDataArray = arrayify14(
|
4821
4816
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
@@ -4830,7 +4825,7 @@ var Account = class extends AbstractAccount {
|
|
4830
4825
|
]);
|
4831
4826
|
const params = { script, gasPrice: minGasPrice, ...txParams };
|
4832
4827
|
const request = new ScriptTransactionRequest(params);
|
4833
|
-
const forwardingQuantities = [{ amount: bn17(amount), assetId:
|
4828
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
|
4834
4829
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4835
4830
|
request,
|
4836
4831
|
forwardingQuantities
|
@@ -4923,7 +4918,7 @@ var Account = class extends AbstractAccount {
|
|
4923
4918
|
|
4924
4919
|
// src/signer/signer.ts
|
4925
4920
|
import { Address as Address4 } from "@fuel-ts/address";
|
4926
|
-
import { randomBytes
|
4921
|
+
import { randomBytes } from "@fuel-ts/crypto";
|
4927
4922
|
import { hash } from "@fuel-ts/hasher";
|
4928
4923
|
import { toBytes } from "@fuel-ts/math";
|
4929
4924
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -5016,7 +5011,7 @@ var Signer = class {
|
|
5016
5011
|
* @returns random 32-byte hashed
|
5017
5012
|
*/
|
5018
5013
|
static generatePrivateKey(entropy) {
|
5019
|
-
return entropy ? hash(concat3([
|
5014
|
+
return entropy ? hash(concat3([randomBytes(32), arrayify15(entropy)])) : randomBytes(32);
|
5020
5015
|
}
|
5021
5016
|
/**
|
5022
5017
|
* Extended publicKey from a compact publicKey
|
@@ -5035,7 +5030,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5035
5030
|
import {
|
5036
5031
|
bufferFromString,
|
5037
5032
|
keccak256,
|
5038
|
-
randomBytes as
|
5033
|
+
randomBytes as randomBytes2,
|
5039
5034
|
scrypt,
|
5040
5035
|
stringFromBuffer,
|
5041
5036
|
decryptJsonWalletData,
|
@@ -5058,7 +5053,7 @@ var removeHexPrefix = (hexString) => {
|
|
5058
5053
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5059
5054
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5060
5055
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5061
|
-
const salt =
|
5056
|
+
const salt = randomBytes2(DEFAULT_KEY_SIZE);
|
5062
5057
|
const key = scrypt({
|
5063
5058
|
password: bufferFromString(password),
|
5064
5059
|
salt,
|
@@ -5067,7 +5062,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5067
5062
|
r: DEFAULT_KDF_PARAMS_R,
|
5068
5063
|
p: DEFAULT_KDF_PARAMS_P
|
5069
5064
|
});
|
5070
|
-
const iv =
|
5065
|
+
const iv = randomBytes2(DEFAULT_IV_SIZE);
|
5071
5066
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5072
5067
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5073
5068
|
const macHashUint8Array = keccak256(data);
|
@@ -5249,7 +5244,7 @@ import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from
|
|
5249
5244
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5250
5245
|
|
5251
5246
|
// src/mnemonic/mnemonic.ts
|
5252
|
-
import { randomBytes as
|
5247
|
+
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5253
5248
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5254
5249
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5255
5250
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -7604,7 +7599,7 @@ var Mnemonic = class {
|
|
7604
7599
|
* @returns A randomly generated mnemonic
|
7605
7600
|
*/
|
7606
7601
|
static generate(size = 32, extraEntropy = "") {
|
7607
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
7602
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size), arrayify17(extraEntropy)])) : randomBytes3(size);
|
7608
7603
|
return Mnemonic.entropyToMnemonic(entropy);
|
7609
7604
|
}
|
7610
7605
|
};
|
@@ -7975,10 +7970,10 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
7975
7970
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
7976
7971
|
|
7977
7972
|
// src/test-utils/seedTestWallet.ts
|
7978
|
-
import { randomBytes as
|
7973
|
+
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
7979
7974
|
var seedTestWallet = async (wallet, quantities) => {
|
7980
7975
|
const genesisWallet = new WalletUnlocked(
|
7981
|
-
process.env.GENESIS_SECRET ||
|
7976
|
+
process.env.GENESIS_SECRET || randomBytes4(32),
|
7982
7977
|
wallet.provider
|
7983
7978
|
);
|
7984
7979
|
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
@@ -8002,7 +7997,7 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8002
7997
|
};
|
8003
7998
|
|
8004
7999
|
// src/test-utils/launchNode.ts
|
8005
|
-
import {
|
8000
|
+
import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
|
8006
8001
|
import { toHex as toHex2 } from "@fuel-ts/math";
|
8007
8002
|
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8008
8003
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
@@ -8102,7 +8097,7 @@ var launchNode = async ({
|
|
8102
8097
|
{
|
8103
8098
|
owner: signer.address.toHexString(),
|
8104
8099
|
amount: toHex2(1e9),
|
8105
|
-
asset_id:
|
8100
|
+
asset_id: defaultChainConfig?.consensus_parameters?.base_asset_id ?? ZeroBytes329
|
8106
8101
|
}
|
8107
8102
|
]
|
8108
8103
|
}
|
@@ -8168,9 +8163,10 @@ var launchNode = async ({
|
|
8168
8163
|
})
|
8169
8164
|
);
|
8170
8165
|
var generateWallets = async (count, provider) => {
|
8166
|
+
const baseAssetId = provider.getBaseAssetId();
|
8171
8167
|
const wallets = [];
|
8172
8168
|
for (let i = 0; i < count; i += 1) {
|
8173
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8169
|
+
const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
|
8174
8170
|
wallets.push(wallet);
|
8175
8171
|
}
|
8176
8172
|
return wallets;
|