@fuel-ts/account 0.0.0-rc-2034-20240410133013 → 0.0.0-rc-1976-20240410142521
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 +103 -124
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +140 -143
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +97 -100
- 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/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/script-transaction-request.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/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +109 -127
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +143 -143
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +102 -102
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/index.mjs
CHANGED
@@ -29,14 +29,12 @@ var __privateMethod = (obj, member, method) => {
|
|
29
29
|
|
30
30
|
// src/account.ts
|
31
31
|
import { Address as Address3 } from "@fuel-ts/address";
|
32
|
-
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
33
32
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
34
33
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
35
34
|
import { bn as bn17 } from "@fuel-ts/math";
|
36
35
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
37
36
|
|
38
37
|
// src/providers/coin-quantity.ts
|
39
|
-
import { BaseAssetId } from "@fuel-ts/address/configs";
|
40
38
|
import { bn } from "@fuel-ts/math";
|
41
39
|
import { hexlify } from "@fuel-ts/utils";
|
42
40
|
var coinQuantityfy = (coinQuantityLike) => {
|
@@ -45,11 +43,11 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
45
43
|
let max2;
|
46
44
|
if (Array.isArray(coinQuantityLike)) {
|
47
45
|
amount = coinQuantityLike[0];
|
48
|
-
assetId = coinQuantityLike[1]
|
49
|
-
max2 = coinQuantityLike[2]
|
46
|
+
assetId = coinQuantityLike[1];
|
47
|
+
max2 = coinQuantityLike[2];
|
50
48
|
} else {
|
51
49
|
amount = coinQuantityLike.amount;
|
52
|
-
assetId = coinQuantityLike.assetId
|
50
|
+
assetId = coinQuantityLike.assetId;
|
53
51
|
max2 = coinQuantityLike.max ?? void 0;
|
54
52
|
}
|
55
53
|
const bnAmount = bn(amount);
|
@@ -1037,7 +1035,7 @@ var inputify = (value) => {
|
|
1037
1035
|
return {
|
1038
1036
|
type: InputType.Coin,
|
1039
1037
|
txID: hexlify3(arrayify(value.id).slice(0, 32)),
|
1040
|
-
outputIndex:
|
1038
|
+
outputIndex: arrayify(value.id)[32],
|
1041
1039
|
owner: hexlify3(value.owner),
|
1042
1040
|
amount: bn2(value.amount),
|
1043
1041
|
assetId: hexlify3(value.assetId),
|
@@ -1156,7 +1154,7 @@ var outputify = (value) => {
|
|
1156
1154
|
|
1157
1155
|
// src/providers/transaction-request/transaction-request.ts
|
1158
1156
|
import { Address, addressify } from "@fuel-ts/address";
|
1159
|
-
import {
|
1157
|
+
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1160
1158
|
import { bn as bn7 } from "@fuel-ts/math";
|
1161
1159
|
import {
|
1162
1160
|
PolicyType,
|
@@ -1166,7 +1164,6 @@ import {
|
|
1166
1164
|
TransactionType
|
1167
1165
|
} from "@fuel-ts/transactions";
|
1168
1166
|
import { concat, hexlify as hexlify7 } from "@fuel-ts/utils";
|
1169
|
-
import { randomBytes } from "ethers";
|
1170
1167
|
|
1171
1168
|
// src/providers/resource.ts
|
1172
1169
|
var isRawCoin = (resource) => "utxoId" in resource;
|
@@ -1691,6 +1688,8 @@ var BaseTransactionRequest = class {
|
|
1691
1688
|
outputs = [];
|
1692
1689
|
/** List of witnesses */
|
1693
1690
|
witnesses = [];
|
1691
|
+
/** Base asset ID - should be fetched from the chain */
|
1692
|
+
baseAssetId;
|
1694
1693
|
/**
|
1695
1694
|
* Constructor for initializing a base transaction request.
|
1696
1695
|
*
|
@@ -1703,8 +1702,9 @@ var BaseTransactionRequest = class {
|
|
1703
1702
|
witnessLimit,
|
1704
1703
|
inputs,
|
1705
1704
|
outputs,
|
1706
|
-
witnesses
|
1707
|
-
|
1705
|
+
witnesses,
|
1706
|
+
baseAssetId
|
1707
|
+
}) {
|
1708
1708
|
this.gasPrice = bn7(gasPrice);
|
1709
1709
|
this.maturity = maturity ?? 0;
|
1710
1710
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
@@ -1712,6 +1712,7 @@ var BaseTransactionRequest = class {
|
|
1712
1712
|
this.inputs = inputs ?? [];
|
1713
1713
|
this.outputs = outputs ?? [];
|
1714
1714
|
this.witnesses = witnesses ?? [];
|
1715
|
+
this.baseAssetId = baseAssetId;
|
1715
1716
|
}
|
1716
1717
|
static getPolicyMeta(req) {
|
1717
1718
|
let policyTypes = 0;
|
@@ -1935,11 +1936,9 @@ var BaseTransactionRequest = class {
|
|
1935
1936
|
*
|
1936
1937
|
* @param message - Message resource.
|
1937
1938
|
* @param predicate - Predicate bytes.
|
1938
|
-
* @param predicateData - Predicate data bytes.
|
1939
1939
|
*/
|
1940
1940
|
addMessageInput(message, predicate) {
|
1941
1941
|
const { recipient, sender, amount } = message;
|
1942
|
-
const assetId = BaseAssetId2;
|
1943
1942
|
let witnessIndex;
|
1944
1943
|
if (predicate) {
|
1945
1944
|
witnessIndex = 0;
|
@@ -1959,7 +1958,7 @@ var BaseTransactionRequest = class {
|
|
1959
1958
|
predicate: predicate?.bytes
|
1960
1959
|
};
|
1961
1960
|
this.pushInput(input);
|
1962
|
-
this.addChangeOutput(recipient,
|
1961
|
+
this.addChangeOutput(recipient, this.baseAssetId);
|
1963
1962
|
}
|
1964
1963
|
/**
|
1965
1964
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2020,12 +2019,12 @@ var BaseTransactionRequest = class {
|
|
2020
2019
|
* @param amount - Amount of coin.
|
2021
2020
|
* @param assetId - Asset ID of coin.
|
2022
2021
|
*/
|
2023
|
-
addCoinOutput(to, amount, assetId
|
2022
|
+
addCoinOutput(to, amount, assetId) {
|
2024
2023
|
this.pushOutput({
|
2025
2024
|
type: OutputType2.Coin,
|
2026
2025
|
to: addressify(to).toB256(),
|
2027
2026
|
amount,
|
2028
|
-
assetId
|
2027
|
+
assetId: assetId ?? this.baseAssetId
|
2029
2028
|
});
|
2030
2029
|
return this;
|
2031
2030
|
}
|
@@ -2052,7 +2051,7 @@ var BaseTransactionRequest = class {
|
|
2052
2051
|
* @param to - Address of the owner.
|
2053
2052
|
* @param assetId - Asset ID of coin.
|
2054
2053
|
*/
|
2055
|
-
addChangeOutput(to, assetId
|
2054
|
+
addChangeOutput(to, assetId) {
|
2056
2055
|
const changeOutput = this.getChangeOutputs().find(
|
2057
2056
|
(output) => hexlify7(output.assetId) === assetId
|
2058
2057
|
);
|
@@ -2060,7 +2059,7 @@ var BaseTransactionRequest = class {
|
|
2060
2059
|
this.pushOutput({
|
2061
2060
|
type: OutputType2.Change,
|
2062
2061
|
to: addressify(to).toB256(),
|
2063
|
-
assetId
|
2062
|
+
assetId: assetId ?? this.baseAssetId
|
2064
2063
|
});
|
2065
2064
|
}
|
2066
2065
|
}
|
@@ -2111,6 +2110,12 @@ var BaseTransactionRequest = class {
|
|
2111
2110
|
* @param quantities - CoinQuantity Array.
|
2112
2111
|
*/
|
2113
2112
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2113
|
+
let idCounter = 0;
|
2114
|
+
const generateId = () => {
|
2115
|
+
const counterString = String(idCounter++);
|
2116
|
+
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
2117
|
+
return id;
|
2118
|
+
};
|
2114
2119
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2115
2120
|
if ("assetId" in input) {
|
2116
2121
|
return input.assetId === assetId;
|
@@ -2120,12 +2125,12 @@ var BaseTransactionRequest = class {
|
|
2120
2125
|
const updateAssetInput = (assetId, quantity) => {
|
2121
2126
|
const assetInput = findAssetInput(assetId);
|
2122
2127
|
if (assetInput && "assetId" in assetInput) {
|
2123
|
-
assetInput.id =
|
2128
|
+
assetInput.id = generateId();
|
2124
2129
|
assetInput.amount = quantity;
|
2125
2130
|
} else {
|
2126
2131
|
this.addResources([
|
2127
2132
|
{
|
2128
|
-
id:
|
2133
|
+
id: generateId(),
|
2129
2134
|
amount: quantity,
|
2130
2135
|
assetId,
|
2131
2136
|
owner: resourcesOwner || Address.fromRandom(),
|
@@ -2136,7 +2141,7 @@ var BaseTransactionRequest = class {
|
|
2136
2141
|
]);
|
2137
2142
|
}
|
2138
2143
|
};
|
2139
|
-
updateAssetInput(
|
2144
|
+
updateAssetInput(this.baseAssetId, bn7(1e11));
|
2140
2145
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2141
2146
|
}
|
2142
2147
|
/**
|
@@ -2306,12 +2311,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2306
2311
|
*
|
2307
2312
|
* @param createTransactionRequestLike - The initial values for the instance
|
2308
2313
|
*/
|
2309
|
-
constructor({
|
2310
|
-
bytecodeWitnessIndex,
|
2311
|
-
salt,
|
2312
|
-
storageSlots,
|
2313
|
-
...rest
|
2314
|
-
} = {}) {
|
2314
|
+
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2315
2315
|
super(rest);
|
2316
2316
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2317
2317
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2435,7 +2435,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2435
2435
|
*
|
2436
2436
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2437
2437
|
*/
|
2438
|
-
constructor({ script, scriptData, gasLimit, ...rest }
|
2438
|
+
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2439
2439
|
super(rest);
|
2440
2440
|
this.gasLimit = bn10(gasLimit);
|
2441
2441
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
@@ -3610,6 +3610,7 @@ var processGqlChain = (chain) => {
|
|
3610
3610
|
gasPerByte: bn15(feeParams.gasPerByte),
|
3611
3611
|
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3612
3612
|
chainId: bn15(consensusParameters.chainId),
|
3613
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3613
3614
|
gasCosts
|
3614
3615
|
},
|
3615
3616
|
gasCosts,
|
@@ -3852,6 +3853,17 @@ var _Provider = class {
|
|
3852
3853
|
} = this.getChain();
|
3853
3854
|
return chainId.toNumber();
|
3854
3855
|
}
|
3856
|
+
/**
|
3857
|
+
* Returns the base asset ID
|
3858
|
+
*
|
3859
|
+
* @returns A promise that resolves to the base asset ID
|
3860
|
+
*/
|
3861
|
+
getBaseAssetId() {
|
3862
|
+
const {
|
3863
|
+
consensusParameters: { baseAssetId }
|
3864
|
+
} = this.getChain();
|
3865
|
+
return baseAssetId;
|
3866
|
+
}
|
3855
3867
|
/**
|
3856
3868
|
* Submits a transaction to the chain to be executed.
|
3857
3869
|
*
|
@@ -4002,37 +4014,6 @@ var _Provider = class {
|
|
4002
4014
|
missingContractIds
|
4003
4015
|
};
|
4004
4016
|
}
|
4005
|
-
/**
|
4006
|
-
* Estimates the transaction gas and fee based on the provided transaction request.
|
4007
|
-
* @param transactionRequest - The transaction request object.
|
4008
|
-
* @param optimizeGas - Optional. Specifies whether to optimize the gas. Default is false.
|
4009
|
-
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4010
|
-
*/
|
4011
|
-
estimateTxGasAndFee(params) {
|
4012
|
-
const { transactionRequest } = params;
|
4013
|
-
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4014
|
-
const chainInfo = this.getChain();
|
4015
|
-
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
4016
|
-
transactionRequest.gasPrice = gasPrice;
|
4017
|
-
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4018
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4019
|
-
if (transactionRequest.type === TransactionType8.Script) {
|
4020
|
-
if (transactionRequest.gasLimit.eq(0)) {
|
4021
|
-
transactionRequest.gasLimit = minGas;
|
4022
|
-
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4023
|
-
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4024
|
-
);
|
4025
|
-
}
|
4026
|
-
}
|
4027
|
-
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4028
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4029
|
-
return {
|
4030
|
-
minGas,
|
4031
|
-
minFee,
|
4032
|
-
maxGas,
|
4033
|
-
maxFee
|
4034
|
-
};
|
4035
|
-
}
|
4036
4017
|
/**
|
4037
4018
|
* Executes a signed transaction without applying the states changes
|
4038
4019
|
* on the chain.
|
@@ -4080,16 +4061,17 @@ var _Provider = class {
|
|
4080
4061
|
signatureCallback
|
4081
4062
|
} = {}) {
|
4082
4063
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
4083
|
-
const
|
4084
|
-
const
|
4064
|
+
const chainInfo = this.getChain();
|
4065
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4066
|
+
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4085
4067
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4086
4068
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4087
4069
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4088
4070
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4089
|
-
if (isScriptTransaction) {
|
4090
|
-
txRequestClone.gasLimit = bn15(0);
|
4091
|
-
}
|
4092
4071
|
if (estimatePredicates) {
|
4072
|
+
if (isScriptTransaction) {
|
4073
|
+
txRequestClone.gasLimit = bn15(0);
|
4074
|
+
}
|
4093
4075
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4094
4076
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4095
4077
|
}
|
@@ -4098,34 +4080,36 @@ var _Provider = class {
|
|
4098
4080
|
if (signatureCallback && isScriptTransaction) {
|
4099
4081
|
await signatureCallback(txRequestClone);
|
4100
4082
|
}
|
4101
|
-
|
4102
|
-
|
4103
|
-
});
|
4083
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
4084
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
4104
4085
|
let receipts = [];
|
4105
4086
|
let missingContractIds = [];
|
4106
4087
|
let outputVariables = 0;
|
4107
|
-
let gasUsed = bn15(0);
|
4108
4088
|
if (isScriptTransaction && estimateTxDependencies) {
|
4109
4089
|
txRequestClone.gasPrice = bn15(0);
|
4090
|
+
txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4110
4091
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4111
4092
|
receipts = result.receipts;
|
4112
4093
|
outputVariables = result.outputVariables;
|
4113
4094
|
missingContractIds = result.missingContractIds;
|
4114
|
-
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4115
|
-
txRequestClone.gasLimit = gasUsed;
|
4116
|
-
txRequestClone.gasPrice = setGasPrice;
|
4117
|
-
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4118
|
-
transactionRequest: txRequestClone
|
4119
|
-
}));
|
4120
4095
|
}
|
4096
|
+
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
4097
|
+
const usedFee = calculatePriceWithFactor(
|
4098
|
+
gasUsed,
|
4099
|
+
gasPrice,
|
4100
|
+
gasPriceFactor
|
4101
|
+
).normalizeZeroToOne();
|
4102
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4103
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4121
4104
|
return {
|
4122
4105
|
requiredQuantities: allQuantities,
|
4123
4106
|
receipts,
|
4124
4107
|
gasUsed,
|
4125
4108
|
minGasPrice,
|
4126
|
-
gasPrice
|
4109
|
+
gasPrice,
|
4127
4110
|
minGas,
|
4128
4111
|
maxGas,
|
4112
|
+
usedFee,
|
4129
4113
|
minFee,
|
4130
4114
|
maxFee,
|
4131
4115
|
estimatedInputs: txRequestClone.inputs,
|
@@ -4916,8 +4900,9 @@ var Account = class extends AbstractAccount {
|
|
4916
4900
|
* @param assetId - The asset ID to check the balance for.
|
4917
4901
|
* @returns A promise that resolves to the balance amount.
|
4918
4902
|
*/
|
4919
|
-
async getBalance(assetId
|
4920
|
-
const
|
4903
|
+
async getBalance(assetId) {
|
4904
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4905
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4921
4906
|
return amount;
|
4922
4907
|
}
|
4923
4908
|
/**
|
@@ -4955,9 +4940,10 @@ var Account = class extends AbstractAccount {
|
|
4955
4940
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4956
4941
|
*/
|
4957
4942
|
async fund(request, coinQuantities, fee) {
|
4943
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4958
4944
|
const updatedQuantities = addAmountToAsset({
|
4959
4945
|
amount: bn17(fee),
|
4960
|
-
assetId:
|
4946
|
+
assetId: baseAssetId,
|
4961
4947
|
coinQuantities
|
4962
4948
|
});
|
4963
4949
|
const quantitiesDict = {};
|
@@ -4981,8 +4967,8 @@ var Account = class extends AbstractAccount {
|
|
4981
4967
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4982
4968
|
cachedUtxos.push(input.id);
|
4983
4969
|
}
|
4984
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
4985
|
-
quantitiesDict[
|
4970
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
4971
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
4986
4972
|
cachedMessages.push(input.nonce);
|
4987
4973
|
}
|
4988
4974
|
}
|
@@ -5014,11 +5000,13 @@ var Account = class extends AbstractAccount {
|
|
5014
5000
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5015
5001
|
* @returns A promise that resolves to the prepared transaction request.
|
5016
5002
|
*/
|
5017
|
-
async createTransfer(destination, amount, assetId
|
5003
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
5018
5004
|
const { minGasPrice } = this.provider.getGasConfig();
|
5019
|
-
const
|
5005
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5006
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5007
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5020
5008
|
const request = new ScriptTransactionRequest(params);
|
5021
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount,
|
5009
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
5022
5010
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5023
5011
|
estimateTxDependencies: true,
|
5024
5012
|
resourcesOwner: this
|
@@ -5044,14 +5032,15 @@ var Account = class extends AbstractAccount {
|
|
5044
5032
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5045
5033
|
* @returns A promise that resolves to the transaction response.
|
5046
5034
|
*/
|
5047
|
-
async transfer(destination, amount, assetId
|
5035
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
5048
5036
|
if (bn17(amount).lte(0)) {
|
5049
5037
|
throw new FuelError15(
|
5050
5038
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5051
5039
|
"Transfer amount must be a positive number."
|
5052
5040
|
);
|
5053
5041
|
}
|
5054
|
-
const
|
5042
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5043
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5055
5044
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5056
5045
|
}
|
5057
5046
|
/**
|
@@ -5063,7 +5052,7 @@ var Account = class extends AbstractAccount {
|
|
5063
5052
|
* @param txParams - The optional transaction parameters.
|
5064
5053
|
* @returns A promise that resolves to the transaction response.
|
5065
5054
|
*/
|
5066
|
-
async transferToContract(contractId, amount, assetId
|
5055
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5067
5056
|
if (bn17(amount).lte(0)) {
|
5068
5057
|
throw new FuelError15(
|
5069
5058
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
@@ -5072,11 +5061,13 @@ var Account = class extends AbstractAccount {
|
|
5072
5061
|
}
|
5073
5062
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
5074
5063
|
const { minGasPrice } = this.provider.getGasConfig();
|
5075
|
-
const
|
5064
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5065
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5066
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5076
5067
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5077
5068
|
hexlifiedContractId: contractAddress.toB256(),
|
5078
5069
|
amountToTransfer: bn17(amount),
|
5079
|
-
assetId
|
5070
|
+
assetId: assetIdToTransfer
|
5080
5071
|
});
|
5081
5072
|
const request = new ScriptTransactionRequest({
|
5082
5073
|
...params,
|
@@ -5086,7 +5077,7 @@ var Account = class extends AbstractAccount {
|
|
5086
5077
|
request.addContractInputAndOutput(contractAddress);
|
5087
5078
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5088
5079
|
request,
|
5089
|
-
[{ amount: bn17(amount), assetId: String(
|
5080
|
+
[{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
|
5090
5081
|
);
|
5091
5082
|
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5092
5083
|
this.validateGas({
|
@@ -5108,6 +5099,7 @@ var Account = class extends AbstractAccount {
|
|
5108
5099
|
*/
|
5109
5100
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5110
5101
|
const { minGasPrice } = this.provider.getGasConfig();
|
5102
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5111
5103
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5112
5104
|
const recipientDataArray = arrayify14(
|
5113
5105
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
@@ -5120,9 +5112,14 @@ var Account = class extends AbstractAccount {
|
|
5120
5112
|
...recipientDataArray,
|
5121
5113
|
...amountDataArray
|
5122
5114
|
]);
|
5123
|
-
const params = {
|
5115
|
+
const params = {
|
5116
|
+
script,
|
5117
|
+
gasPrice: minGasPrice,
|
5118
|
+
baseAssetId,
|
5119
|
+
...txParams
|
5120
|
+
};
|
5124
5121
|
const request = new ScriptTransactionRequest(params);
|
5125
|
-
const forwardingQuantities = [{ amount: bn17(amount), assetId:
|
5122
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
|
5126
5123
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5127
5124
|
request,
|
5128
5125
|
forwardingQuantities
|
@@ -5219,7 +5216,7 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
5219
5216
|
|
5220
5217
|
// src/signer/signer.ts
|
5221
5218
|
import { Address as Address4 } from "@fuel-ts/address";
|
5222
|
-
import { randomBytes
|
5219
|
+
import { randomBytes } from "@fuel-ts/crypto";
|
5223
5220
|
import { hash } from "@fuel-ts/hasher";
|
5224
5221
|
import { toBytes } from "@fuel-ts/math";
|
5225
5222
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -5312,7 +5309,7 @@ var Signer = class {
|
|
5312
5309
|
* @returns random 32-byte hashed
|
5313
5310
|
*/
|
5314
5311
|
static generatePrivateKey(entropy) {
|
5315
|
-
return entropy ? hash(concat3([
|
5312
|
+
return entropy ? hash(concat3([randomBytes(32), arrayify15(entropy)])) : randomBytes(32);
|
5316
5313
|
}
|
5317
5314
|
/**
|
5318
5315
|
* Extended publicKey from a compact publicKey
|
@@ -5331,7 +5328,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5331
5328
|
import {
|
5332
5329
|
bufferFromString,
|
5333
5330
|
keccak256,
|
5334
|
-
randomBytes as
|
5331
|
+
randomBytes as randomBytes2,
|
5335
5332
|
scrypt,
|
5336
5333
|
stringFromBuffer,
|
5337
5334
|
decryptJsonWalletData,
|
@@ -5354,7 +5351,7 @@ var removeHexPrefix = (hexString) => {
|
|
5354
5351
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5355
5352
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5356
5353
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5357
|
-
const salt =
|
5354
|
+
const salt = randomBytes2(DEFAULT_KEY_SIZE);
|
5358
5355
|
const key = scrypt({
|
5359
5356
|
password: bufferFromString(password),
|
5360
5357
|
salt,
|
@@ -5363,7 +5360,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5363
5360
|
r: DEFAULT_KDF_PARAMS_R,
|
5364
5361
|
p: DEFAULT_KDF_PARAMS_P
|
5365
5362
|
});
|
5366
|
-
const iv =
|
5363
|
+
const iv = randomBytes2(DEFAULT_IV_SIZE);
|
5367
5364
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5368
5365
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5369
5366
|
const macHashUint8Array = keccak256(data);
|
@@ -5545,7 +5542,7 @@ import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from
|
|
5545
5542
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5546
5543
|
|
5547
5544
|
// src/mnemonic/mnemonic.ts
|
5548
|
-
import { randomBytes as
|
5545
|
+
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5549
5546
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5550
5547
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5551
5548
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -7906,7 +7903,7 @@ var Mnemonic = class {
|
|
7906
7903
|
* @returns A randomly generated mnemonic
|
7907
7904
|
*/
|
7908
7905
|
static generate(size = 32, extraEntropy = "") {
|
7909
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
7906
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size), arrayify17(extraEntropy)])) : randomBytes3(size);
|
7910
7907
|
return Mnemonic.entropyToMnemonic(entropy);
|
7911
7908
|
}
|
7912
7909
|
};
|
@@ -8699,7 +8696,6 @@ import {
|
|
8699
8696
|
SCRIPT_FIXED_SIZE
|
8700
8697
|
} from "@fuel-ts/abi-coder";
|
8701
8698
|
import { Address as Address9 } from "@fuel-ts/address";
|
8702
|
-
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8703
8699
|
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8704
8700
|
import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
|
8705
8701
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
@@ -8777,8 +8773,9 @@ var Predicate = class extends Account {
|
|
8777
8773
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
8778
8774
|
* @returns A promise that resolves to the prepared transaction request.
|
8779
8775
|
*/
|
8780
|
-
async createTransfer(destination, amount, assetId
|
8781
|
-
const
|
8776
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8777
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
8778
|
+
const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
8782
8779
|
return this.populateTransactionPredicateData(request);
|
8783
8780
|
}
|
8784
8781
|
/**
|