@fuel-ts/account 0.0.0-rc-1976-20240415100843 → 0.0.0-rc-2040-20240415161332
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 +75 -119
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +150 -194
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -122
- 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 +2 -20
- 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/input.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 +2 -5
- 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 +78 -125
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +147 -194
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +80 -127
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/index.mjs
CHANGED
@@ -29,12 +29,14 @@ 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";
|
32
33
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
33
34
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
34
35
|
import { bn as bn17 } from "@fuel-ts/math";
|
35
36
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
36
37
|
|
37
38
|
// src/providers/coin-quantity.ts
|
39
|
+
import { BaseAssetId } from "@fuel-ts/address/configs";
|
38
40
|
import { bn } from "@fuel-ts/math";
|
39
41
|
import { hexlify } from "@fuel-ts/utils";
|
40
42
|
var coinQuantityfy = (coinQuantityLike) => {
|
@@ -43,11 +45,11 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
43
45
|
let max2;
|
44
46
|
if (Array.isArray(coinQuantityLike)) {
|
45
47
|
amount = coinQuantityLike[0];
|
46
|
-
assetId = coinQuantityLike[1];
|
47
|
-
max2 = coinQuantityLike[2];
|
48
|
+
assetId = coinQuantityLike[1] ?? BaseAssetId;
|
49
|
+
max2 = coinQuantityLike[2] ?? void 0;
|
48
50
|
} else {
|
49
51
|
amount = coinQuantityLike.amount;
|
50
|
-
assetId = coinQuantityLike.assetId;
|
52
|
+
assetId = coinQuantityLike.assetId ?? BaseAssetId;
|
51
53
|
max2 = coinQuantityLike.max ?? void 0;
|
52
54
|
}
|
53
55
|
const bnAmount = bn(amount);
|
@@ -1021,7 +1023,6 @@ var MemoryCache = class {
|
|
1021
1023
|
};
|
1022
1024
|
|
1023
1025
|
// src/providers/transaction-request/input.ts
|
1024
|
-
import { BYTES_32, UTXO_ID_LEN } from "@fuel-ts/abi-coder";
|
1025
1026
|
import { ZeroBytes32 } from "@fuel-ts/address/configs";
|
1026
1027
|
import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
|
1027
1028
|
import { bn as bn2, toNumber } from "@fuel-ts/math";
|
@@ -1035,8 +1036,8 @@ var inputify = (value) => {
|
|
1035
1036
|
const predicateData = arrayify(value.predicateData ?? "0x");
|
1036
1037
|
return {
|
1037
1038
|
type: InputType.Coin,
|
1038
|
-
txID: hexlify3(arrayify(value.id).slice(0,
|
1039
|
-
outputIndex:
|
1039
|
+
txID: hexlify3(arrayify(value.id).slice(0, 32)),
|
1040
|
+
outputIndex: arrayify(value.id)[32],
|
1040
1041
|
owner: hexlify3(value.owner),
|
1041
1042
|
amount: bn2(value.amount),
|
1042
1043
|
assetId: hexlify3(value.assetId),
|
@@ -1154,10 +1155,8 @@ var outputify = (value) => {
|
|
1154
1155
|
};
|
1155
1156
|
|
1156
1157
|
// src/providers/transaction-request/transaction-request.ts
|
1157
|
-
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1158
1158
|
import { Address, addressify } from "@fuel-ts/address";
|
1159
|
-
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1160
|
-
import { randomBytes } from "@fuel-ts/crypto";
|
1159
|
+
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1161
1160
|
import { bn as bn7 } from "@fuel-ts/math";
|
1162
1161
|
import {
|
1163
1162
|
PolicyType,
|
@@ -1691,8 +1690,6 @@ var BaseTransactionRequest = class {
|
|
1691
1690
|
outputs = [];
|
1692
1691
|
/** List of witnesses */
|
1693
1692
|
witnesses = [];
|
1694
|
-
/** Base asset ID - should be fetched from the chain */
|
1695
|
-
baseAssetId;
|
1696
1693
|
/**
|
1697
1694
|
* Constructor for initializing a base transaction request.
|
1698
1695
|
*
|
@@ -1705,9 +1702,8 @@ var BaseTransactionRequest = class {
|
|
1705
1702
|
witnessLimit,
|
1706
1703
|
inputs,
|
1707
1704
|
outputs,
|
1708
|
-
witnesses
|
1709
|
-
|
1710
|
-
}) {
|
1705
|
+
witnesses
|
1706
|
+
} = {}) {
|
1711
1707
|
this.gasPrice = bn7(gasPrice);
|
1712
1708
|
this.maturity = maturity ?? 0;
|
1713
1709
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
@@ -1715,7 +1711,6 @@ var BaseTransactionRequest = class {
|
|
1715
1711
|
this.inputs = inputs ?? [];
|
1716
1712
|
this.outputs = outputs ?? [];
|
1717
1713
|
this.witnesses = witnesses ?? [];
|
1718
|
-
this.baseAssetId = baseAssetId;
|
1719
1714
|
}
|
1720
1715
|
static getPolicyMeta(req) {
|
1721
1716
|
let policyTypes = 0;
|
@@ -1939,9 +1934,11 @@ var BaseTransactionRequest = class {
|
|
1939
1934
|
*
|
1940
1935
|
* @param message - Message resource.
|
1941
1936
|
* @param predicate - Predicate bytes.
|
1937
|
+
* @param predicateData - Predicate data bytes.
|
1942
1938
|
*/
|
1943
1939
|
addMessageInput(message, predicate) {
|
1944
1940
|
const { recipient, sender, amount } = message;
|
1941
|
+
const assetId = BaseAssetId2;
|
1945
1942
|
let witnessIndex;
|
1946
1943
|
if (predicate) {
|
1947
1944
|
witnessIndex = 0;
|
@@ -1961,7 +1958,7 @@ var BaseTransactionRequest = class {
|
|
1961
1958
|
predicate: predicate?.bytes
|
1962
1959
|
};
|
1963
1960
|
this.pushInput(input);
|
1964
|
-
this.addChangeOutput(recipient,
|
1961
|
+
this.addChangeOutput(recipient, assetId);
|
1965
1962
|
}
|
1966
1963
|
/**
|
1967
1964
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2022,12 +2019,12 @@ var BaseTransactionRequest = class {
|
|
2022
2019
|
* @param amount - Amount of coin.
|
2023
2020
|
* @param assetId - Asset ID of coin.
|
2024
2021
|
*/
|
2025
|
-
addCoinOutput(to, amount, assetId) {
|
2022
|
+
addCoinOutput(to, amount, assetId = BaseAssetId2) {
|
2026
2023
|
this.pushOutput({
|
2027
2024
|
type: OutputType2.Coin,
|
2028
2025
|
to: addressify(to).toB256(),
|
2029
2026
|
amount,
|
2030
|
-
assetId
|
2027
|
+
assetId
|
2031
2028
|
});
|
2032
2029
|
return this;
|
2033
2030
|
}
|
@@ -2054,7 +2051,7 @@ var BaseTransactionRequest = class {
|
|
2054
2051
|
* @param to - Address of the owner.
|
2055
2052
|
* @param assetId - Asset ID of coin.
|
2056
2053
|
*/
|
2057
|
-
addChangeOutput(to, assetId) {
|
2054
|
+
addChangeOutput(to, assetId = BaseAssetId2) {
|
2058
2055
|
const changeOutput = this.getChangeOutputs().find(
|
2059
2056
|
(output) => hexlify7(output.assetId) === assetId
|
2060
2057
|
);
|
@@ -2062,7 +2059,7 @@ var BaseTransactionRequest = class {
|
|
2062
2059
|
this.pushOutput({
|
2063
2060
|
type: OutputType2.Change,
|
2064
2061
|
to: addressify(to).toB256(),
|
2065
|
-
assetId
|
2062
|
+
assetId
|
2066
2063
|
});
|
2067
2064
|
}
|
2068
2065
|
}
|
@@ -2113,6 +2110,12 @@ var BaseTransactionRequest = class {
|
|
2113
2110
|
* @param quantities - CoinQuantity Array.
|
2114
2111
|
*/
|
2115
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
|
+
};
|
2116
2119
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2117
2120
|
if ("assetId" in input) {
|
2118
2121
|
return input.assetId === assetId;
|
@@ -2122,12 +2125,12 @@ var BaseTransactionRequest = class {
|
|
2122
2125
|
const updateAssetInput = (assetId, quantity) => {
|
2123
2126
|
const assetInput = findAssetInput(assetId);
|
2124
2127
|
if (assetInput && "assetId" in assetInput) {
|
2125
|
-
assetInput.id =
|
2128
|
+
assetInput.id = generateId();
|
2126
2129
|
assetInput.amount = quantity;
|
2127
2130
|
} else {
|
2128
2131
|
this.addResources([
|
2129
2132
|
{
|
2130
|
-
id:
|
2133
|
+
id: generateId(),
|
2131
2134
|
amount: quantity,
|
2132
2135
|
assetId,
|
2133
2136
|
owner: resourcesOwner || Address.fromRandom(),
|
@@ -2138,7 +2141,7 @@ var BaseTransactionRequest = class {
|
|
2138
2141
|
]);
|
2139
2142
|
}
|
2140
2143
|
};
|
2141
|
-
updateAssetInput(
|
2144
|
+
updateAssetInput(BaseAssetId2, bn7(1e11));
|
2142
2145
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2143
2146
|
}
|
2144
2147
|
/**
|
@@ -2308,7 +2311,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2308
2311
|
*
|
2309
2312
|
* @param createTransactionRequestLike - The initial values for the instance
|
2310
2313
|
*/
|
2311
|
-
constructor({
|
2314
|
+
constructor({
|
2315
|
+
bytecodeWitnessIndex,
|
2316
|
+
salt,
|
2317
|
+
storageSlots,
|
2318
|
+
...rest
|
2319
|
+
} = {}) {
|
2312
2320
|
super(rest);
|
2313
2321
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2314
2322
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2432,7 +2440,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2432
2440
|
*
|
2433
2441
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2434
2442
|
*/
|
2435
|
-
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2443
|
+
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2436
2444
|
super(rest);
|
2437
2445
|
this.gasLimit = bn10(gasLimit);
|
2438
2446
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
@@ -3607,7 +3615,6 @@ var processGqlChain = (chain) => {
|
|
3607
3615
|
gasPerByte: bn15(feeParams.gasPerByte),
|
3608
3616
|
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3609
3617
|
chainId: bn15(consensusParameters.chainId),
|
3610
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3611
3618
|
gasCosts
|
3612
3619
|
},
|
3613
3620
|
gasCosts,
|
@@ -3850,17 +3857,6 @@ var _Provider = class {
|
|
3850
3857
|
} = this.getChain();
|
3851
3858
|
return chainId.toNumber();
|
3852
3859
|
}
|
3853
|
-
/**
|
3854
|
-
* Returns the base asset ID
|
3855
|
-
*
|
3856
|
-
* @returns A promise that resolves to the base asset ID
|
3857
|
-
*/
|
3858
|
-
getBaseAssetId() {
|
3859
|
-
const {
|
3860
|
-
consensusParameters: { baseAssetId }
|
3861
|
-
} = this.getChain();
|
3862
|
-
return baseAssetId;
|
3863
|
-
}
|
3864
3860
|
/**
|
3865
3861
|
* Submits a transaction to the chain to be executed.
|
3866
3862
|
*
|
@@ -4011,36 +4007,6 @@ var _Provider = class {
|
|
4011
4007
|
missingContractIds
|
4012
4008
|
};
|
4013
4009
|
}
|
4014
|
-
/**
|
4015
|
-
* Estimates the transaction gas and fee based on the provided transaction request.
|
4016
|
-
* @param transactionRequest - The transaction request object.
|
4017
|
-
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4018
|
-
*/
|
4019
|
-
estimateTxGasAndFee(params) {
|
4020
|
-
const { transactionRequest } = params;
|
4021
|
-
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4022
|
-
const chainInfo = this.getChain();
|
4023
|
-
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
4024
|
-
transactionRequest.gasPrice = gasPrice;
|
4025
|
-
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4026
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4027
|
-
if (transactionRequest.type === TransactionType8.Script) {
|
4028
|
-
if (transactionRequest.gasLimit.eq(0)) {
|
4029
|
-
transactionRequest.gasLimit = minGas;
|
4030
|
-
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4031
|
-
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4032
|
-
);
|
4033
|
-
}
|
4034
|
-
}
|
4035
|
-
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4036
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4037
|
-
return {
|
4038
|
-
minGas,
|
4039
|
-
minFee,
|
4040
|
-
maxGas,
|
4041
|
-
maxFee
|
4042
|
-
};
|
4043
|
-
}
|
4044
4010
|
/**
|
4045
4011
|
* Executes a signed transaction without applying the states changes
|
4046
4012
|
* on the chain.
|
@@ -4088,16 +4054,17 @@ var _Provider = class {
|
|
4088
4054
|
signatureCallback
|
4089
4055
|
} = {}) {
|
4090
4056
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
4091
|
-
const
|
4092
|
-
const
|
4057
|
+
const chainInfo = this.getChain();
|
4058
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4059
|
+
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4093
4060
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4094
4061
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4095
4062
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4096
4063
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4097
|
-
if (isScriptTransaction) {
|
4098
|
-
txRequestClone.gasLimit = bn15(0);
|
4099
|
-
}
|
4100
4064
|
if (estimatePredicates) {
|
4065
|
+
if (isScriptTransaction) {
|
4066
|
+
txRequestClone.gasLimit = bn15(0);
|
4067
|
+
}
|
4101
4068
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4102
4069
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4103
4070
|
}
|
@@ -4106,34 +4073,36 @@ var _Provider = class {
|
|
4106
4073
|
if (signatureCallback && isScriptTransaction) {
|
4107
4074
|
await signatureCallback(txRequestClone);
|
4108
4075
|
}
|
4109
|
-
|
4110
|
-
|
4111
|
-
});
|
4076
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
4077
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
4112
4078
|
let receipts = [];
|
4113
4079
|
let missingContractIds = [];
|
4114
4080
|
let outputVariables = 0;
|
4115
|
-
let gasUsed = bn15(0);
|
4116
4081
|
if (isScriptTransaction && estimateTxDependencies) {
|
4117
4082
|
txRequestClone.gasPrice = bn15(0);
|
4083
|
+
txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4118
4084
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4119
4085
|
receipts = result.receipts;
|
4120
4086
|
outputVariables = result.outputVariables;
|
4121
4087
|
missingContractIds = result.missingContractIds;
|
4122
|
-
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4123
|
-
txRequestClone.gasLimit = gasUsed;
|
4124
|
-
txRequestClone.gasPrice = setGasPrice;
|
4125
|
-
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4126
|
-
transactionRequest: txRequestClone
|
4127
|
-
}));
|
4128
4088
|
}
|
4089
|
+
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
4090
|
+
const usedFee = calculatePriceWithFactor(
|
4091
|
+
gasUsed,
|
4092
|
+
gasPrice,
|
4093
|
+
gasPriceFactor
|
4094
|
+
).normalizeZeroToOne();
|
4095
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4096
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4129
4097
|
return {
|
4130
4098
|
requiredQuantities: allQuantities,
|
4131
4099
|
receipts,
|
4132
4100
|
gasUsed,
|
4133
4101
|
minGasPrice,
|
4134
|
-
gasPrice
|
4102
|
+
gasPrice,
|
4135
4103
|
minGas,
|
4136
4104
|
maxGas,
|
4105
|
+
usedFee,
|
4137
4106
|
minFee,
|
4138
4107
|
maxFee,
|
4139
4108
|
estimatedInputs: txRequestClone.inputs,
|
@@ -4924,9 +4893,8 @@ var Account = class extends AbstractAccount {
|
|
4924
4893
|
* @param assetId - The asset ID to check the balance for.
|
4925
4894
|
* @returns A promise that resolves to the balance amount.
|
4926
4895
|
*/
|
4927
|
-
async getBalance(assetId) {
|
4928
|
-
const
|
4929
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4896
|
+
async getBalance(assetId = BaseAssetId3) {
|
4897
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4930
4898
|
return amount;
|
4931
4899
|
}
|
4932
4900
|
/**
|
@@ -4964,10 +4932,9 @@ var Account = class extends AbstractAccount {
|
|
4964
4932
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4965
4933
|
*/
|
4966
4934
|
async fund(request, coinQuantities, fee) {
|
4967
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4968
4935
|
const updatedQuantities = addAmountToAsset({
|
4969
4936
|
amount: bn17(fee),
|
4970
|
-
assetId:
|
4937
|
+
assetId: BaseAssetId3,
|
4971
4938
|
coinQuantities
|
4972
4939
|
});
|
4973
4940
|
const quantitiesDict = {};
|
@@ -4991,8 +4958,8 @@ var Account = class extends AbstractAccount {
|
|
4991
4958
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4992
4959
|
cachedUtxos.push(input.id);
|
4993
4960
|
}
|
4994
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
4995
|
-
quantitiesDict[
|
4961
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
|
4962
|
+
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4996
4963
|
cachedMessages.push(input.nonce);
|
4997
4964
|
}
|
4998
4965
|
}
|
@@ -5024,13 +4991,11 @@ var Account = class extends AbstractAccount {
|
|
5024
4991
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5025
4992
|
* @returns A promise that resolves to the prepared transaction request.
|
5026
4993
|
*/
|
5027
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4994
|
+
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5028
4995
|
const { minGasPrice } = this.provider.getGasConfig();
|
5029
|
-
const
|
5030
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5031
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4996
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5032
4997
|
const request = new ScriptTransactionRequest(params);
|
5033
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount,
|
4998
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
5034
4999
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5035
5000
|
estimateTxDependencies: true,
|
5036
5001
|
resourcesOwner: this
|
@@ -5056,15 +5021,14 @@ var Account = class extends AbstractAccount {
|
|
5056
5021
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5057
5022
|
* @returns A promise that resolves to the transaction response.
|
5058
5023
|
*/
|
5059
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
5024
|
+
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5060
5025
|
if (bn17(amount).lte(0)) {
|
5061
5026
|
throw new FuelError15(
|
5062
5027
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5063
5028
|
"Transfer amount must be a positive number."
|
5064
5029
|
);
|
5065
5030
|
}
|
5066
|
-
const
|
5067
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5031
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
5068
5032
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5069
5033
|
}
|
5070
5034
|
/**
|
@@ -5076,7 +5040,7 @@ var Account = class extends AbstractAccount {
|
|
5076
5040
|
* @param txParams - The optional transaction parameters.
|
5077
5041
|
* @returns A promise that resolves to the transaction response.
|
5078
5042
|
*/
|
5079
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5043
|
+
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
5080
5044
|
if (bn17(amount).lte(0)) {
|
5081
5045
|
throw new FuelError15(
|
5082
5046
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
@@ -5085,13 +5049,11 @@ var Account = class extends AbstractAccount {
|
|
5085
5049
|
}
|
5086
5050
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
5087
5051
|
const { minGasPrice } = this.provider.getGasConfig();
|
5088
|
-
const
|
5089
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5090
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5052
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5091
5053
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5092
5054
|
hexlifiedContractId: contractAddress.toB256(),
|
5093
5055
|
amountToTransfer: bn17(amount),
|
5094
|
-
assetId
|
5056
|
+
assetId
|
5095
5057
|
});
|
5096
5058
|
const request = new ScriptTransactionRequest({
|
5097
5059
|
...params,
|
@@ -5101,7 +5063,7 @@ var Account = class extends AbstractAccount {
|
|
5101
5063
|
request.addContractInputAndOutput(contractAddress);
|
5102
5064
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5103
5065
|
request,
|
5104
|
-
[{ amount: bn17(amount), assetId: String(
|
5066
|
+
[{ amount: bn17(amount), assetId: String(assetId) }]
|
5105
5067
|
);
|
5106
5068
|
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5107
5069
|
this.validateGas({
|
@@ -5123,7 +5085,6 @@ var Account = class extends AbstractAccount {
|
|
5123
5085
|
*/
|
5124
5086
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5125
5087
|
const { minGasPrice } = this.provider.getGasConfig();
|
5126
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
5127
5088
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5128
5089
|
const recipientDataArray = arrayify14(
|
5129
5090
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
@@ -5136,14 +5097,9 @@ var Account = class extends AbstractAccount {
|
|
5136
5097
|
...recipientDataArray,
|
5137
5098
|
...amountDataArray
|
5138
5099
|
]);
|
5139
|
-
const params = {
|
5140
|
-
script,
|
5141
|
-
gasPrice: minGasPrice,
|
5142
|
-
baseAssetId,
|
5143
|
-
...txParams
|
5144
|
-
};
|
5100
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5145
5101
|
const request = new ScriptTransactionRequest(params);
|
5146
|
-
const forwardingQuantities = [{ amount: bn17(amount), assetId:
|
5102
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
|
5147
5103
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5148
5104
|
request,
|
5149
5105
|
forwardingQuantities
|
@@ -5240,7 +5196,7 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
5240
5196
|
|
5241
5197
|
// src/signer/signer.ts
|
5242
5198
|
import { Address as Address4 } from "@fuel-ts/address";
|
5243
|
-
import { randomBytes
|
5199
|
+
import { randomBytes } from "@fuel-ts/crypto";
|
5244
5200
|
import { hash } from "@fuel-ts/hasher";
|
5245
5201
|
import { toBytes } from "@fuel-ts/math";
|
5246
5202
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -5333,7 +5289,7 @@ var Signer = class {
|
|
5333
5289
|
* @returns random 32-byte hashed
|
5334
5290
|
*/
|
5335
5291
|
static generatePrivateKey(entropy) {
|
5336
|
-
return entropy ? hash(concat3([
|
5292
|
+
return entropy ? hash(concat3([randomBytes(32), arrayify15(entropy)])) : randomBytes(32);
|
5337
5293
|
}
|
5338
5294
|
/**
|
5339
5295
|
* Extended publicKey from a compact publicKey
|
@@ -5352,7 +5308,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5352
5308
|
import {
|
5353
5309
|
bufferFromString,
|
5354
5310
|
keccak256,
|
5355
|
-
randomBytes as
|
5311
|
+
randomBytes as randomBytes2,
|
5356
5312
|
scrypt,
|
5357
5313
|
stringFromBuffer,
|
5358
5314
|
decryptJsonWalletData,
|
@@ -5375,7 +5331,7 @@ var removeHexPrefix = (hexString) => {
|
|
5375
5331
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5376
5332
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5377
5333
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5378
|
-
const salt =
|
5334
|
+
const salt = randomBytes2(DEFAULT_KEY_SIZE);
|
5379
5335
|
const key = scrypt({
|
5380
5336
|
password: bufferFromString(password),
|
5381
5337
|
salt,
|
@@ -5384,7 +5340,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5384
5340
|
r: DEFAULT_KDF_PARAMS_R,
|
5385
5341
|
p: DEFAULT_KDF_PARAMS_P
|
5386
5342
|
});
|
5387
|
-
const iv =
|
5343
|
+
const iv = randomBytes2(DEFAULT_IV_SIZE);
|
5388
5344
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5389
5345
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5390
5346
|
const macHashUint8Array = keccak256(data);
|
@@ -5566,7 +5522,7 @@ import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from
|
|
5566
5522
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5567
5523
|
|
5568
5524
|
// src/mnemonic/mnemonic.ts
|
5569
|
-
import { randomBytes as
|
5525
|
+
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5570
5526
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5571
5527
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5572
5528
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -7927,7 +7883,7 @@ var Mnemonic = class {
|
|
7927
7883
|
* @returns A randomly generated mnemonic
|
7928
7884
|
*/
|
7929
7885
|
static generate(size = 32, extraEntropy = "") {
|
7930
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
7886
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size), arrayify17(extraEntropy)])) : randomBytes3(size);
|
7931
7887
|
return Mnemonic.entropyToMnemonic(entropy);
|
7932
7888
|
}
|
7933
7889
|
};
|
@@ -8720,6 +8676,7 @@ import {
|
|
8720
8676
|
SCRIPT_FIXED_SIZE
|
8721
8677
|
} from "@fuel-ts/abi-coder";
|
8722
8678
|
import { Address as Address9 } from "@fuel-ts/address";
|
8679
|
+
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8723
8680
|
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8724
8681
|
import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
|
8725
8682
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
@@ -8797,9 +8754,8 @@ var Predicate = class extends Account {
|
|
8797
8754
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
8798
8755
|
* @returns A promise that resolves to the prepared transaction request.
|
8799
8756
|
*/
|
8800
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8801
|
-
const
|
8802
|
-
const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
8757
|
+
async createTransfer(destination, amount, assetId = BaseAssetId4, txParams = {}) {
|
8758
|
+
const request = await super.createTransfer(destination, amount, assetId, txParams);
|
8803
8759
|
return this.populateTransactionPredicateData(request);
|
8804
8760
|
}
|
8805
8761
|
/**
|