@fuel-ts/account 0.0.0-rc-1832-20240415161726 → 0.0.0-rc-2034-20240415163000
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/index.global.js +139 -121
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +96 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -41
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +0 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +13 -2
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/test-utils.global.js +141 -122
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +93 -71
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +64 -42
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/index.mjs
CHANGED
@@ -1023,6 +1023,7 @@ var MemoryCache = class {
|
|
1023
1023
|
};
|
1024
1024
|
|
1025
1025
|
// src/providers/transaction-request/input.ts
|
1026
|
+
import { BYTES_32, UTXO_ID_LEN } from "@fuel-ts/abi-coder";
|
1026
1027
|
import { ZeroBytes32 } from "@fuel-ts/address/configs";
|
1027
1028
|
import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
|
1028
1029
|
import { bn as bn2, toNumber } from "@fuel-ts/math";
|
@@ -1036,8 +1037,8 @@ var inputify = (value) => {
|
|
1036
1037
|
const predicateData = arrayify(value.predicateData ?? "0x");
|
1037
1038
|
return {
|
1038
1039
|
type: InputType.Coin,
|
1039
|
-
txID: hexlify3(arrayify(value.id).slice(0,
|
1040
|
-
outputIndex: arrayify(value.id)
|
1040
|
+
txID: hexlify3(arrayify(value.id).slice(0, BYTES_32)),
|
1041
|
+
outputIndex: toNumber(arrayify(value.id).slice(BYTES_32, UTXO_ID_LEN)),
|
1041
1042
|
owner: hexlify3(value.owner),
|
1042
1043
|
amount: bn2(value.amount),
|
1043
1044
|
assetId: hexlify3(value.assetId),
|
@@ -1155,8 +1156,10 @@ var outputify = (value) => {
|
|
1155
1156
|
};
|
1156
1157
|
|
1157
1158
|
// src/providers/transaction-request/transaction-request.ts
|
1159
|
+
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1158
1160
|
import { Address, addressify } from "@fuel-ts/address";
|
1159
1161
|
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1162
|
+
import { randomBytes } from "@fuel-ts/crypto";
|
1160
1163
|
import { bn as bn7 } from "@fuel-ts/math";
|
1161
1164
|
import {
|
1162
1165
|
PolicyType,
|
@@ -1923,8 +1926,7 @@ var BaseTransactionRequest = class {
|
|
1923
1926
|
assetId,
|
1924
1927
|
txPointer: "0x00000000000000000000000000000000",
|
1925
1928
|
witnessIndex,
|
1926
|
-
predicate: predicate?.bytes
|
1927
|
-
predicateData: predicate?.predicateDataBytes
|
1929
|
+
predicate: predicate?.bytes
|
1928
1930
|
};
|
1929
1931
|
this.pushInput(input);
|
1930
1932
|
this.addChangeOutput(owner, assetId);
|
@@ -1956,8 +1958,7 @@ var BaseTransactionRequest = class {
|
|
1956
1958
|
recipient: recipient.toB256(),
|
1957
1959
|
amount,
|
1958
1960
|
witnessIndex,
|
1959
|
-
predicate: predicate?.bytes
|
1960
|
-
predicateData: predicate?.predicateDataBytes
|
1961
|
+
predicate: predicate?.bytes
|
1961
1962
|
};
|
1962
1963
|
this.pushInput(input);
|
1963
1964
|
this.addChangeOutput(recipient, assetId);
|
@@ -2112,12 +2113,6 @@ var BaseTransactionRequest = class {
|
|
2112
2113
|
* @param quantities - CoinQuantity Array.
|
2113
2114
|
*/
|
2114
2115
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2115
|
-
let idCounter = 0;
|
2116
|
-
const generateId = () => {
|
2117
|
-
const counterString = String(idCounter++);
|
2118
|
-
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
2119
|
-
return id;
|
2120
|
-
};
|
2121
2116
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2122
2117
|
if ("assetId" in input) {
|
2123
2118
|
return input.assetId === assetId;
|
@@ -2127,12 +2122,12 @@ var BaseTransactionRequest = class {
|
|
2127
2122
|
const updateAssetInput = (assetId, quantity) => {
|
2128
2123
|
const assetInput = findAssetInput(assetId);
|
2129
2124
|
if (assetInput && "assetId" in assetInput) {
|
2130
|
-
assetInput.id =
|
2125
|
+
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2131
2126
|
assetInput.amount = quantity;
|
2132
2127
|
} else {
|
2133
2128
|
this.addResources([
|
2134
2129
|
{
|
2135
|
-
id:
|
2130
|
+
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2136
2131
|
amount: quantity,
|
2137
2132
|
assetId,
|
2138
2133
|
owner: resourcesOwner || Address.fromRandom(),
|
@@ -4009,6 +4004,36 @@ var _Provider = class {
|
|
4009
4004
|
missingContractIds
|
4010
4005
|
};
|
4011
4006
|
}
|
4007
|
+
/**
|
4008
|
+
* Estimates the transaction gas and fee based on the provided transaction request.
|
4009
|
+
* @param transactionRequest - The transaction request object.
|
4010
|
+
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4011
|
+
*/
|
4012
|
+
estimateTxGasAndFee(params) {
|
4013
|
+
const { transactionRequest } = params;
|
4014
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4015
|
+
const chainInfo = this.getChain();
|
4016
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
4017
|
+
transactionRequest.gasPrice = gasPrice;
|
4018
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4019
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4020
|
+
if (transactionRequest.type === TransactionType8.Script) {
|
4021
|
+
if (transactionRequest.gasLimit.eq(0)) {
|
4022
|
+
transactionRequest.gasLimit = minGas;
|
4023
|
+
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4024
|
+
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4025
|
+
);
|
4026
|
+
}
|
4027
|
+
}
|
4028
|
+
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4029
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4030
|
+
return {
|
4031
|
+
minGas,
|
4032
|
+
minFee,
|
4033
|
+
maxGas,
|
4034
|
+
maxFee
|
4035
|
+
};
|
4036
|
+
}
|
4012
4037
|
/**
|
4013
4038
|
* Executes a signed transaction without applying the states changes
|
4014
4039
|
* on the chain.
|
@@ -4056,17 +4081,16 @@ var _Provider = class {
|
|
4056
4081
|
signatureCallback
|
4057
4082
|
} = {}) {
|
4058
4083
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
4059
|
-
const
|
4060
|
-
const
|
4061
|
-
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4084
|
+
const { minGasPrice } = this.getGasConfig();
|
4085
|
+
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4062
4086
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4063
4087
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4064
4088
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4065
4089
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4090
|
+
if (isScriptTransaction) {
|
4091
|
+
txRequestClone.gasLimit = bn15(0);
|
4092
|
+
}
|
4066
4093
|
if (estimatePredicates) {
|
4067
|
-
if (isScriptTransaction) {
|
4068
|
-
txRequestClone.gasLimit = bn15(0);
|
4069
|
-
}
|
4070
4094
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4071
4095
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4072
4096
|
}
|
@@ -4075,36 +4099,34 @@ var _Provider = class {
|
|
4075
4099
|
if (signatureCallback && isScriptTransaction) {
|
4076
4100
|
await signatureCallback(txRequestClone);
|
4077
4101
|
}
|
4078
|
-
|
4079
|
-
|
4102
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4103
|
+
transactionRequest: txRequestClone
|
4104
|
+
});
|
4080
4105
|
let receipts = [];
|
4081
4106
|
let missingContractIds = [];
|
4082
4107
|
let outputVariables = 0;
|
4108
|
+
let gasUsed = bn15(0);
|
4083
4109
|
if (isScriptTransaction && estimateTxDependencies) {
|
4084
4110
|
txRequestClone.gasPrice = bn15(0);
|
4085
|
-
txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4086
4111
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4087
4112
|
receipts = result.receipts;
|
4088
4113
|
outputVariables = result.outputVariables;
|
4089
4114
|
missingContractIds = result.missingContractIds;
|
4115
|
+
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4116
|
+
txRequestClone.gasLimit = gasUsed;
|
4117
|
+
txRequestClone.gasPrice = setGasPrice;
|
4118
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4119
|
+
transactionRequest: txRequestClone
|
4120
|
+
}));
|
4090
4121
|
}
|
4091
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
4092
|
-
const usedFee = calculatePriceWithFactor(
|
4093
|
-
gasUsed,
|
4094
|
-
gasPrice,
|
4095
|
-
gasPriceFactor
|
4096
|
-
).normalizeZeroToOne();
|
4097
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4098
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4099
4122
|
return {
|
4100
4123
|
requiredQuantities: allQuantities,
|
4101
4124
|
receipts,
|
4102
4125
|
gasUsed,
|
4103
4126
|
minGasPrice,
|
4104
|
-
gasPrice,
|
4127
|
+
gasPrice: setGasPrice,
|
4105
4128
|
minGas,
|
4106
4129
|
maxGas,
|
4107
|
-
usedFee,
|
4108
4130
|
minFee,
|
4109
4131
|
maxFee,
|
4110
4132
|
estimatedInputs: txRequestClone.inputs,
|
@@ -5198,7 +5220,7 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
5198
5220
|
|
5199
5221
|
// src/signer/signer.ts
|
5200
5222
|
import { Address as Address4 } from "@fuel-ts/address";
|
5201
|
-
import { randomBytes } from "@fuel-ts/crypto";
|
5223
|
+
import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
|
5202
5224
|
import { hash } from "@fuel-ts/hasher";
|
5203
5225
|
import { toBytes } from "@fuel-ts/math";
|
5204
5226
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -5291,7 +5313,7 @@ var Signer = class {
|
|
5291
5313
|
* @returns random 32-byte hashed
|
5292
5314
|
*/
|
5293
5315
|
static generatePrivateKey(entropy) {
|
5294
|
-
return entropy ? hash(concat3([
|
5316
|
+
return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
|
5295
5317
|
}
|
5296
5318
|
/**
|
5297
5319
|
* Extended publicKey from a compact publicKey
|
@@ -5310,7 +5332,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5310
5332
|
import {
|
5311
5333
|
bufferFromString,
|
5312
5334
|
keccak256,
|
5313
|
-
randomBytes as
|
5335
|
+
randomBytes as randomBytes3,
|
5314
5336
|
scrypt,
|
5315
5337
|
stringFromBuffer,
|
5316
5338
|
decryptJsonWalletData,
|
@@ -5333,7 +5355,7 @@ var removeHexPrefix = (hexString) => {
|
|
5333
5355
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5334
5356
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5335
5357
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5336
|
-
const salt =
|
5358
|
+
const salt = randomBytes3(DEFAULT_KEY_SIZE);
|
5337
5359
|
const key = scrypt({
|
5338
5360
|
password: bufferFromString(password),
|
5339
5361
|
salt,
|
@@ -5342,7 +5364,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5342
5364
|
r: DEFAULT_KDF_PARAMS_R,
|
5343
5365
|
p: DEFAULT_KDF_PARAMS_P
|
5344
5366
|
});
|
5345
|
-
const iv =
|
5367
|
+
const iv = randomBytes3(DEFAULT_IV_SIZE);
|
5346
5368
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5347
5369
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5348
5370
|
const macHashUint8Array = keccak256(data);
|
@@ -5524,7 +5546,7 @@ import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from
|
|
5524
5546
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5525
5547
|
|
5526
5548
|
// src/mnemonic/mnemonic.ts
|
5527
|
-
import { randomBytes as
|
5549
|
+
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
5528
5550
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5529
5551
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5530
5552
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -7885,7 +7907,7 @@ var Mnemonic = class {
|
|
7885
7907
|
* @returns A randomly generated mnemonic
|
7886
7908
|
*/
|
7887
7909
|
static generate(size = 32, extraEntropy = "") {
|
7888
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
7910
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
|
7889
7911
|
return Mnemonic.entropyToMnemonic(entropy);
|
7890
7912
|
}
|
7891
7913
|
};
|
@@ -8699,7 +8721,6 @@ var getPredicateRoot = (bytecode) => {
|
|
8699
8721
|
// src/predicate/predicate.ts
|
8700
8722
|
var Predicate = class extends Account {
|
8701
8723
|
bytes;
|
8702
|
-
predicateDataBytes = Uint8Array.from([]);
|
8703
8724
|
predicateData = [];
|
8704
8725
|
interface;
|
8705
8726
|
/**
|