@fuel-ts/account 0.0.0-rc-2045-20240415152456 → 0.0.0-rc-1832-20240415161726
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 +124 -142
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +75 -96
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -62
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +1 -0
- package/dist/predicate/predicate.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.map +1 -1
- package/dist/test-utils.global.js +125 -144
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +71 -93
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +42 -64
- 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,
|
@@ -1926,7 +1923,8 @@ var BaseTransactionRequest = class {
|
|
1926
1923
|
assetId,
|
1927
1924
|
txPointer: "0x00000000000000000000000000000000",
|
1928
1925
|
witnessIndex,
|
1929
|
-
predicate: predicate?.bytes
|
1926
|
+
predicate: predicate?.bytes,
|
1927
|
+
predicateData: predicate?.predicateDataBytes
|
1930
1928
|
};
|
1931
1929
|
this.pushInput(input);
|
1932
1930
|
this.addChangeOutput(owner, assetId);
|
@@ -1958,7 +1956,8 @@ var BaseTransactionRequest = class {
|
|
1958
1956
|
recipient: recipient.toB256(),
|
1959
1957
|
amount,
|
1960
1958
|
witnessIndex,
|
1961
|
-
predicate: predicate?.bytes
|
1959
|
+
predicate: predicate?.bytes,
|
1960
|
+
predicateData: predicate?.predicateDataBytes
|
1962
1961
|
};
|
1963
1962
|
this.pushInput(input);
|
1964
1963
|
this.addChangeOutput(recipient, assetId);
|
@@ -2113,6 +2112,12 @@ var BaseTransactionRequest = class {
|
|
2113
2112
|
* @param quantities - CoinQuantity Array.
|
2114
2113
|
*/
|
2115
2114
|
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
|
+
};
|
2116
2121
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2117
2122
|
if ("assetId" in input) {
|
2118
2123
|
return input.assetId === assetId;
|
@@ -2122,12 +2127,12 @@ var BaseTransactionRequest = class {
|
|
2122
2127
|
const updateAssetInput = (assetId, quantity) => {
|
2123
2128
|
const assetInput = findAssetInput(assetId);
|
2124
2129
|
if (assetInput && "assetId" in assetInput) {
|
2125
|
-
assetInput.id =
|
2130
|
+
assetInput.id = generateId();
|
2126
2131
|
assetInput.amount = quantity;
|
2127
2132
|
} else {
|
2128
2133
|
this.addResources([
|
2129
2134
|
{
|
2130
|
-
id:
|
2135
|
+
id: generateId(),
|
2131
2136
|
amount: quantity,
|
2132
2137
|
assetId,
|
2133
2138
|
owner: resourcesOwner || Address.fromRandom(),
|
@@ -4004,36 +4009,6 @@ var _Provider = class {
|
|
4004
4009
|
missingContractIds
|
4005
4010
|
};
|
4006
4011
|
}
|
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
4012
|
/**
|
4038
4013
|
* Executes a signed transaction without applying the states changes
|
4039
4014
|
* on the chain.
|
@@ -4081,16 +4056,17 @@ var _Provider = class {
|
|
4081
4056
|
signatureCallback
|
4082
4057
|
} = {}) {
|
4083
4058
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
4084
|
-
const
|
4085
|
-
const
|
4059
|
+
const chainInfo = this.getChain();
|
4060
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4061
|
+
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4086
4062
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4087
4063
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4088
4064
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4089
4065
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4090
|
-
if (isScriptTransaction) {
|
4091
|
-
txRequestClone.gasLimit = bn15(0);
|
4092
|
-
}
|
4093
4066
|
if (estimatePredicates) {
|
4067
|
+
if (isScriptTransaction) {
|
4068
|
+
txRequestClone.gasLimit = bn15(0);
|
4069
|
+
}
|
4094
4070
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4095
4071
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4096
4072
|
}
|
@@ -4099,34 +4075,36 @@ var _Provider = class {
|
|
4099
4075
|
if (signatureCallback && isScriptTransaction) {
|
4100
4076
|
await signatureCallback(txRequestClone);
|
4101
4077
|
}
|
4102
|
-
|
4103
|
-
|
4104
|
-
});
|
4078
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
4079
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
4105
4080
|
let receipts = [];
|
4106
4081
|
let missingContractIds = [];
|
4107
4082
|
let outputVariables = 0;
|
4108
|
-
let gasUsed = bn15(0);
|
4109
4083
|
if (isScriptTransaction && estimateTxDependencies) {
|
4110
4084
|
txRequestClone.gasPrice = bn15(0);
|
4085
|
+
txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4111
4086
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4112
4087
|
receipts = result.receipts;
|
4113
4088
|
outputVariables = result.outputVariables;
|
4114
4089
|
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
4090
|
}
|
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();
|
4122
4099
|
return {
|
4123
4100
|
requiredQuantities: allQuantities,
|
4124
4101
|
receipts,
|
4125
4102
|
gasUsed,
|
4126
4103
|
minGasPrice,
|
4127
|
-
gasPrice
|
4104
|
+
gasPrice,
|
4128
4105
|
minGas,
|
4129
4106
|
maxGas,
|
4107
|
+
usedFee,
|
4130
4108
|
minFee,
|
4131
4109
|
maxFee,
|
4132
4110
|
estimatedInputs: txRequestClone.inputs,
|
@@ -5220,7 +5198,7 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
5220
5198
|
|
5221
5199
|
// src/signer/signer.ts
|
5222
5200
|
import { Address as Address4 } from "@fuel-ts/address";
|
5223
|
-
import { randomBytes
|
5201
|
+
import { randomBytes } from "@fuel-ts/crypto";
|
5224
5202
|
import { hash } from "@fuel-ts/hasher";
|
5225
5203
|
import { toBytes } from "@fuel-ts/math";
|
5226
5204
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -5313,7 +5291,7 @@ var Signer = class {
|
|
5313
5291
|
* @returns random 32-byte hashed
|
5314
5292
|
*/
|
5315
5293
|
static generatePrivateKey(entropy) {
|
5316
|
-
return entropy ? hash(concat3([
|
5294
|
+
return entropy ? hash(concat3([randomBytes(32), arrayify15(entropy)])) : randomBytes(32);
|
5317
5295
|
}
|
5318
5296
|
/**
|
5319
5297
|
* Extended publicKey from a compact publicKey
|
@@ -5332,7 +5310,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5332
5310
|
import {
|
5333
5311
|
bufferFromString,
|
5334
5312
|
keccak256,
|
5335
|
-
randomBytes as
|
5313
|
+
randomBytes as randomBytes2,
|
5336
5314
|
scrypt,
|
5337
5315
|
stringFromBuffer,
|
5338
5316
|
decryptJsonWalletData,
|
@@ -5355,7 +5333,7 @@ var removeHexPrefix = (hexString) => {
|
|
5355
5333
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5356
5334
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5357
5335
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5358
|
-
const salt =
|
5336
|
+
const salt = randomBytes2(DEFAULT_KEY_SIZE);
|
5359
5337
|
const key = scrypt({
|
5360
5338
|
password: bufferFromString(password),
|
5361
5339
|
salt,
|
@@ -5364,7 +5342,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5364
5342
|
r: DEFAULT_KDF_PARAMS_R,
|
5365
5343
|
p: DEFAULT_KDF_PARAMS_P
|
5366
5344
|
});
|
5367
|
-
const iv =
|
5345
|
+
const iv = randomBytes2(DEFAULT_IV_SIZE);
|
5368
5346
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5369
5347
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5370
5348
|
const macHashUint8Array = keccak256(data);
|
@@ -5546,7 +5524,7 @@ import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from
|
|
5546
5524
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5547
5525
|
|
5548
5526
|
// src/mnemonic/mnemonic.ts
|
5549
|
-
import { randomBytes as
|
5527
|
+
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5550
5528
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5551
5529
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5552
5530
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -7907,7 +7885,7 @@ var Mnemonic = class {
|
|
7907
7885
|
* @returns A randomly generated mnemonic
|
7908
7886
|
*/
|
7909
7887
|
static generate(size = 32, extraEntropy = "") {
|
7910
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
7888
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size), arrayify17(extraEntropy)])) : randomBytes3(size);
|
7911
7889
|
return Mnemonic.entropyToMnemonic(entropy);
|
7912
7890
|
}
|
7913
7891
|
};
|
@@ -8721,6 +8699,7 @@ var getPredicateRoot = (bytecode) => {
|
|
8721
8699
|
// src/predicate/predicate.ts
|
8722
8700
|
var Predicate = class extends Account {
|
8723
8701
|
bytes;
|
8702
|
+
predicateDataBytes = Uint8Array.from([]);
|
8724
8703
|
predicateData = [];
|
8725
8704
|
interface;
|
8726
8705
|
/**
|