@fuel-ts/account 0.0.0-rc-2034-20240411123358 → 0.0.0-rc-2037-20240411135757
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 +56 -89
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +93 -128
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -94
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +9 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +2 -1
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -0
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +2 -13
- 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 +2 -20
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/test-utils.global.js +43 -91
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +75 -125
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +46 -96
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/index.mjs
CHANGED
@@ -1023,7 +1023,6 @@ 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";
|
1027
1026
|
import { ZeroBytes32 } from "@fuel-ts/address/configs";
|
1028
1027
|
import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
|
1029
1028
|
import { bn as bn2, toNumber } from "@fuel-ts/math";
|
@@ -1037,8 +1036,8 @@ var inputify = (value) => {
|
|
1037
1036
|
const predicateData = arrayify(value.predicateData ?? "0x");
|
1038
1037
|
return {
|
1039
1038
|
type: InputType.Coin,
|
1040
|
-
txID: hexlify3(arrayify(value.id).slice(0,
|
1041
|
-
outputIndex:
|
1039
|
+
txID: hexlify3(arrayify(value.id).slice(0, 32)),
|
1040
|
+
outputIndex: arrayify(value.id)[32],
|
1042
1041
|
owner: hexlify3(value.owner),
|
1043
1042
|
amount: bn2(value.amount),
|
1044
1043
|
assetId: hexlify3(value.assetId),
|
@@ -1156,10 +1155,8 @@ var outputify = (value) => {
|
|
1156
1155
|
};
|
1157
1156
|
|
1158
1157
|
// src/providers/transaction-request/transaction-request.ts
|
1159
|
-
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1160
1158
|
import { Address, addressify } from "@fuel-ts/address";
|
1161
1159
|
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1162
|
-
import { randomBytes } from "@fuel-ts/crypto";
|
1163
1160
|
import { bn as bn7 } from "@fuel-ts/math";
|
1164
1161
|
import {
|
1165
1162
|
PolicyType,
|
@@ -1907,8 +1904,8 @@ var BaseTransactionRequest = class {
|
|
1907
1904
|
* @param predicate - Predicate bytes.
|
1908
1905
|
* @param predicateData - Predicate data bytes.
|
1909
1906
|
*/
|
1910
|
-
addCoinInput(coin
|
1911
|
-
const { assetId, owner, amount } = coin;
|
1907
|
+
addCoinInput(coin) {
|
1908
|
+
const { assetId, owner, amount, id, predicate } = coin;
|
1912
1909
|
let witnessIndex;
|
1913
1910
|
if (predicate) {
|
1914
1911
|
witnessIndex = 0;
|
@@ -1919,14 +1916,14 @@ var BaseTransactionRequest = class {
|
|
1919
1916
|
}
|
1920
1917
|
}
|
1921
1918
|
const input = {
|
1922
|
-
|
1919
|
+
id,
|
1923
1920
|
type: InputType2.Coin,
|
1924
1921
|
owner: owner.toB256(),
|
1925
1922
|
amount,
|
1926
1923
|
assetId,
|
1927
1924
|
txPointer: "0x00000000000000000000000000000000",
|
1928
1925
|
witnessIndex,
|
1929
|
-
predicate
|
1926
|
+
predicate
|
1930
1927
|
};
|
1931
1928
|
this.pushInput(input);
|
1932
1929
|
this.addChangeOutput(owner, assetId);
|
@@ -1939,8 +1936,8 @@ var BaseTransactionRequest = class {
|
|
1939
1936
|
* @param predicate - Predicate bytes.
|
1940
1937
|
* @param predicateData - Predicate data bytes.
|
1941
1938
|
*/
|
1942
|
-
addMessageInput(message
|
1943
|
-
const { recipient, sender, amount } = message;
|
1939
|
+
addMessageInput(message) {
|
1940
|
+
const { recipient, sender, amount, predicate, nonce } = message;
|
1944
1941
|
const assetId = BaseAssetId2;
|
1945
1942
|
let witnessIndex;
|
1946
1943
|
if (predicate) {
|
@@ -1952,13 +1949,13 @@ var BaseTransactionRequest = class {
|
|
1952
1949
|
}
|
1953
1950
|
}
|
1954
1951
|
const input = {
|
1955
|
-
|
1952
|
+
nonce,
|
1956
1953
|
type: InputType2.Message,
|
1957
1954
|
sender: sender.toB256(),
|
1958
1955
|
recipient: recipient.toB256(),
|
1959
1956
|
amount,
|
1960
1957
|
witnessIndex,
|
1961
|
-
predicate
|
1958
|
+
predicate
|
1962
1959
|
};
|
1963
1960
|
this.pushInput(input);
|
1964
1961
|
this.addChangeOutput(recipient, assetId);
|
@@ -1989,32 +1986,6 @@ var BaseTransactionRequest = class {
|
|
1989
1986
|
resources.forEach((resource) => this.addResource(resource));
|
1990
1987
|
return this;
|
1991
1988
|
}
|
1992
|
-
/**
|
1993
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1994
|
-
* outputs from the related assetIds.
|
1995
|
-
*
|
1996
|
-
* @param resources - The resources to add.
|
1997
|
-
* @returns This transaction.
|
1998
|
-
*/
|
1999
|
-
addPredicateResource(resource, predicate) {
|
2000
|
-
if (isCoin(resource)) {
|
2001
|
-
this.addCoinInput(resource, predicate);
|
2002
|
-
} else {
|
2003
|
-
this.addMessageInput(resource, predicate);
|
2004
|
-
}
|
2005
|
-
return this;
|
2006
|
-
}
|
2007
|
-
/**
|
2008
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
2009
|
-
* from the related assetIds.
|
2010
|
-
*
|
2011
|
-
* @param resources - The resources to add.
|
2012
|
-
* @returns This transaction.
|
2013
|
-
*/
|
2014
|
-
addPredicateResources(resources, predicate) {
|
2015
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
2016
|
-
return this;
|
2017
|
-
}
|
2018
1989
|
/**
|
2019
1990
|
* Adds a coin output to the transaction.
|
2020
1991
|
*
|
@@ -2113,6 +2084,12 @@ var BaseTransactionRequest = class {
|
|
2113
2084
|
* @param quantities - CoinQuantity Array.
|
2114
2085
|
*/
|
2115
2086
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2087
|
+
let idCounter = 0;
|
2088
|
+
const generateId = () => {
|
2089
|
+
const counterString = String(idCounter++);
|
2090
|
+
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
2091
|
+
return id;
|
2092
|
+
};
|
2116
2093
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2117
2094
|
if ("assetId" in input) {
|
2118
2095
|
return input.assetId === assetId;
|
@@ -2122,12 +2099,12 @@ var BaseTransactionRequest = class {
|
|
2122
2099
|
const updateAssetInput = (assetId, quantity) => {
|
2123
2100
|
const assetInput = findAssetInput(assetId);
|
2124
2101
|
if (assetInput && "assetId" in assetInput) {
|
2125
|
-
assetInput.id =
|
2102
|
+
assetInput.id = generateId();
|
2126
2103
|
assetInput.amount = quantity;
|
2127
2104
|
} else {
|
2128
2105
|
this.addResources([
|
2129
2106
|
{
|
2130
|
-
id:
|
2107
|
+
id: generateId(),
|
2131
2108
|
amount: quantity,
|
2132
2109
|
assetId,
|
2133
2110
|
owner: resourcesOwner || Address.fromRandom(),
|
@@ -4004,36 +3981,6 @@ var _Provider = class {
|
|
4004
3981
|
missingContractIds
|
4005
3982
|
};
|
4006
3983
|
}
|
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
|
-
}
|
4037
3984
|
/**
|
4038
3985
|
* Executes a signed transaction without applying the states changes
|
4039
3986
|
* on the chain.
|
@@ -4081,16 +4028,17 @@ var _Provider = class {
|
|
4081
4028
|
signatureCallback
|
4082
4029
|
} = {}) {
|
4083
4030
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
4084
|
-
const
|
4085
|
-
const
|
4031
|
+
const chainInfo = this.getChain();
|
4032
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4033
|
+
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4086
4034
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4087
4035
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4088
4036
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4089
4037
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4090
|
-
if (isScriptTransaction) {
|
4091
|
-
txRequestClone.gasLimit = bn15(0);
|
4092
|
-
}
|
4093
4038
|
if (estimatePredicates) {
|
4039
|
+
if (isScriptTransaction) {
|
4040
|
+
txRequestClone.gasLimit = bn15(0);
|
4041
|
+
}
|
4094
4042
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4095
4043
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4096
4044
|
}
|
@@ -4099,34 +4047,36 @@ var _Provider = class {
|
|
4099
4047
|
if (signatureCallback && isScriptTransaction) {
|
4100
4048
|
await signatureCallback(txRequestClone);
|
4101
4049
|
}
|
4102
|
-
|
4103
|
-
|
4104
|
-
});
|
4050
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
4051
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
4105
4052
|
let receipts = [];
|
4106
4053
|
let missingContractIds = [];
|
4107
4054
|
let outputVariables = 0;
|
4108
|
-
let gasUsed = bn15(0);
|
4109
4055
|
if (isScriptTransaction && estimateTxDependencies) {
|
4110
4056
|
txRequestClone.gasPrice = bn15(0);
|
4057
|
+
txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4111
4058
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4112
4059
|
receipts = result.receipts;
|
4113
4060
|
outputVariables = result.outputVariables;
|
4114
4061
|
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
|
-
}));
|
4121
4062
|
}
|
4063
|
+
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
4064
|
+
const usedFee = calculatePriceWithFactor(
|
4065
|
+
gasUsed,
|
4066
|
+
gasPrice,
|
4067
|
+
gasPriceFactor
|
4068
|
+
).normalizeZeroToOne();
|
4069
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4070
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4122
4071
|
return {
|
4123
4072
|
requiredQuantities: allQuantities,
|
4124
4073
|
receipts,
|
4125
4074
|
gasUsed,
|
4126
4075
|
minGasPrice,
|
4127
|
-
gasPrice
|
4076
|
+
gasPrice,
|
4128
4077
|
minGas,
|
4129
4078
|
maxGas,
|
4079
|
+
usedFee,
|
4130
4080
|
minFee,
|
4131
4081
|
maxFee,
|
4132
4082
|
estimatedInputs: txRequestClone.inputs,
|
@@ -5220,7 +5170,7 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
5220
5170
|
|
5221
5171
|
// src/signer/signer.ts
|
5222
5172
|
import { Address as Address4 } from "@fuel-ts/address";
|
5223
|
-
import { randomBytes
|
5173
|
+
import { randomBytes } from "@fuel-ts/crypto";
|
5224
5174
|
import { hash } from "@fuel-ts/hasher";
|
5225
5175
|
import { toBytes } from "@fuel-ts/math";
|
5226
5176
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -5313,7 +5263,7 @@ var Signer = class {
|
|
5313
5263
|
* @returns random 32-byte hashed
|
5314
5264
|
*/
|
5315
5265
|
static generatePrivateKey(entropy) {
|
5316
|
-
return entropy ? hash(concat3([
|
5266
|
+
return entropy ? hash(concat3([randomBytes(32), arrayify15(entropy)])) : randomBytes(32);
|
5317
5267
|
}
|
5318
5268
|
/**
|
5319
5269
|
* Extended publicKey from a compact publicKey
|
@@ -5332,7 +5282,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5332
5282
|
import {
|
5333
5283
|
bufferFromString,
|
5334
5284
|
keccak256,
|
5335
|
-
randomBytes as
|
5285
|
+
randomBytes as randomBytes2,
|
5336
5286
|
scrypt,
|
5337
5287
|
stringFromBuffer,
|
5338
5288
|
decryptJsonWalletData,
|
@@ -5355,7 +5305,7 @@ var removeHexPrefix = (hexString) => {
|
|
5355
5305
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5356
5306
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5357
5307
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5358
|
-
const salt =
|
5308
|
+
const salt = randomBytes2(DEFAULT_KEY_SIZE);
|
5359
5309
|
const key = scrypt({
|
5360
5310
|
password: bufferFromString(password),
|
5361
5311
|
salt,
|
@@ -5364,7 +5314,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5364
5314
|
r: DEFAULT_KDF_PARAMS_R,
|
5365
5315
|
p: DEFAULT_KDF_PARAMS_P
|
5366
5316
|
});
|
5367
|
-
const iv =
|
5317
|
+
const iv = randomBytes2(DEFAULT_IV_SIZE);
|
5368
5318
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5369
5319
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5370
5320
|
const macHashUint8Array = keccak256(data);
|
@@ -5546,7 +5496,7 @@ import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from
|
|
5546
5496
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5547
5497
|
|
5548
5498
|
// src/mnemonic/mnemonic.ts
|
5549
|
-
import { randomBytes as
|
5499
|
+
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5550
5500
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5551
5501
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5552
5502
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -7907,7 +7857,7 @@ var Mnemonic = class {
|
|
7907
7857
|
* @returns A randomly generated mnemonic
|
7908
7858
|
*/
|
7909
7859
|
static generate(size = 32, extraEntropy = "") {
|
7910
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
7860
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size), arrayify17(extraEntropy)])) : randomBytes3(size);
|
7911
7861
|
return Mnemonic.entropyToMnemonic(entropy);
|
7912
7862
|
}
|
7913
7863
|
};
|
@@ -8765,6 +8715,7 @@ var Predicate = class extends Account {
|
|
8765
8715
|
if (input.type === InputType7.Coin && hexlify19(input.owner) === this.address.toB256()) {
|
8766
8716
|
input.predicate = this.bytes;
|
8767
8717
|
input.predicateData = this.getPredicateData(policies.length);
|
8718
|
+
input.witnessIndex = 0;
|
8768
8719
|
}
|
8769
8720
|
});
|
8770
8721
|
return request;
|
@@ -8802,6 +8753,20 @@ var Predicate = class extends Account {
|
|
8802
8753
|
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8803
8754
|
return super.simulateTransaction(transactionRequest);
|
8804
8755
|
}
|
8756
|
+
/**
|
8757
|
+
* Retrieves resources satisfying the spend query for the account.
|
8758
|
+
*
|
8759
|
+
* @param quantities - IDs of coins to exclude.
|
8760
|
+
* @param excludedIds - IDs of resources to be excluded from the query.
|
8761
|
+
* @returns A promise that resolves to an array of Resources.
|
8762
|
+
*/
|
8763
|
+
async getResourcesToSpend(quantities, excludedIds) {
|
8764
|
+
const resources = await super.getResourcesToSpend(quantities, excludedIds);
|
8765
|
+
return resources.map((resource) => ({
|
8766
|
+
...resource,
|
8767
|
+
predicate: hexlify19(this.bytes)
|
8768
|
+
}));
|
8769
|
+
}
|
8805
8770
|
getPredicateData(policiesLength) {
|
8806
8771
|
if (!this.predicateData.length) {
|
8807
8772
|
return new Uint8Array();
|