@fuel-ts/account 0.0.0-pr-1699-20240214162434 → 0.0.0-pr-1784-20240221124858
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 +7 -4
- package/dist/account.d.ts.map +1 -1
- package/dist/connectors/fuel.d.ts +5 -6
- package/dist/connectors/fuel.d.ts.map +1 -1
- package/dist/connectors/index.d.ts +0 -2
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/types/asset.d.ts +0 -14
- package/dist/connectors/types/asset.d.ts.map +1 -1
- package/dist/connectors/types/data-type.d.ts +0 -4
- package/dist/connectors/types/data-type.d.ts.map +1 -1
- package/dist/connectors/types/events.d.ts +0 -5
- package/dist/connectors/types/events.d.ts.map +1 -1
- package/dist/connectors/types/index.d.ts +0 -2
- package/dist/connectors/types/index.d.ts.map +1 -1
- package/dist/connectors/utils/cache.d.ts.map +1 -1
- package/dist/connectors/utils/index.d.ts +0 -1
- package/dist/connectors/utils/index.d.ts.map +1 -1
- package/dist/index.global.js +718 -605
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +278 -162
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +336 -220
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/assets/index.d.ts +4 -0
- package/dist/providers/assets/index.d.ts.map +1 -0
- package/dist/providers/assets/types.d.ts +36 -0
- package/dist/providers/assets/types.d.ts.map +1 -0
- package/dist/providers/assets/utils/index.d.ts +4 -0
- package/dist/providers/assets/utils/index.d.ts.map +1 -0
- package/dist/providers/assets/utils/network.d.ts +33 -0
- package/dist/providers/assets/utils/network.d.ts.map +1 -0
- package/dist/providers/assets/utils/resolveIconPaths.d.ts +14 -0
- package/dist/providers/assets/utils/resolveIconPaths.d.ts.map +1 -0
- package/dist/providers/assets/utils/url.d.ts +2 -0
- package/dist/providers/assets/utils/url.d.ts.map +1 -0
- package/dist/providers/chains.d.ts +11 -0
- package/dist/providers/chains.d.ts.map +1 -0
- package/dist/providers/index.d.ts +2 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +14 -6
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +3 -10
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/utils/json.d.ts.map +1 -1
- package/dist/test-utils.global.js +593 -496
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +176 -79
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +231 -134
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts +3 -3
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +17 -17
- package/dist/connectors/fixtures/generate-accounts.d.ts +0 -2
- package/dist/connectors/fixtures/generate-accounts.d.ts.map +0 -1
- package/dist/connectors/fixtures/mocked-connector.d.ts +0 -45
- package/dist/connectors/fixtures/mocked-connector.d.ts.map +0 -1
- package/dist/connectors/fixtures/promise-callback.d.ts +0 -7
- package/dist/connectors/fixtures/promise-callback.d.ts.map +0 -1
- package/dist/connectors/fuel-wallet-locked.d.ts +0 -13
- package/dist/connectors/fuel-wallet-locked.d.ts.map +0 -1
- package/dist/connectors/fuel-wallet-provider.d.ts +0 -14
- package/dist/connectors/fuel-wallet-provider.d.ts.map +0 -1
- package/dist/connectors/types/connection.d.ts +0 -7
- package/dist/connectors/types/connection.d.ts.map +0 -1
- package/dist/connectors/types/nertwork-data.d.ts +0 -7
- package/dist/connectors/types/nertwork-data.d.ts.map +0 -1
- package/dist/connectors/utils/get-asset-by-chain.d.ts +0 -3
- package/dist/connectors/utils/get-asset-by-chain.d.ts.map +0 -1
package/dist/test-utils.mjs
CHANGED
@@ -27,7 +27,7 @@ import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
|
27
27
|
import { ErrorCode as ErrorCode13, FuelError as FuelError14 } from "@fuel-ts/errors";
|
28
28
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
29
29
|
import { bn as bn16 } from "@fuel-ts/math";
|
30
|
-
import { getBytesCopy as
|
30
|
+
import { getBytesCopy as getBytesCopy14 } from "ethers";
|
31
31
|
|
32
32
|
// src/providers/coin-quantity.ts
|
33
33
|
import { BaseAssetId } from "@fuel-ts/address/configs";
|
@@ -68,15 +68,17 @@ var addAmountToAsset = (params) => {
|
|
68
68
|
// src/providers/provider.ts
|
69
69
|
import { Address as Address2 } from "@fuel-ts/address";
|
70
70
|
import { ErrorCode as ErrorCode11, FuelError as FuelError12 } from "@fuel-ts/errors";
|
71
|
-
import { bn as bn14, max } from "@fuel-ts/math";
|
71
|
+
import { BN, bn as bn14, max } from "@fuel-ts/math";
|
72
72
|
import {
|
73
73
|
InputType as InputType6,
|
74
74
|
TransactionType as TransactionType8,
|
75
75
|
InputMessageCoder,
|
76
76
|
TransactionCoder as TransactionCoder5
|
77
77
|
} from "@fuel-ts/transactions";
|
78
|
+
import { arrayify } from "@fuel-ts/utils";
|
78
79
|
import { checkFuelCoreVersionCompatibility } from "@fuel-ts/versions";
|
79
|
-
import {
|
80
|
+
import { equalBytes } from "@noble/curves/abstract/utils";
|
81
|
+
import { getBytesCopy as getBytesCopy11, hexlify as hexlify12, Network } from "ethers";
|
80
82
|
import { GraphQLClient } from "graphql-request";
|
81
83
|
import { clone as clone3 } from "ramda";
|
82
84
|
|
@@ -1149,7 +1151,7 @@ import {
|
|
1149
1151
|
OutputType as OutputType2,
|
1150
1152
|
TransactionType
|
1151
1153
|
} from "@fuel-ts/transactions";
|
1152
|
-
import { concat,
|
1154
|
+
import { concat, hexlify as hexlify7 } from "ethers";
|
1153
1155
|
|
1154
1156
|
// src/providers/resource.ts
|
1155
1157
|
var isCoin = (resource) => "id" in resource;
|
@@ -1917,7 +1919,7 @@ var BaseTransactionRequest = class {
|
|
1917
1919
|
*
|
1918
1920
|
* @param quantities - CoinQuantity Array.
|
1919
1921
|
*/
|
1920
|
-
fundWithFakeUtxos(quantities) {
|
1922
|
+
fundWithFakeUtxos(quantities, resourcesOwner) {
|
1921
1923
|
let idCounter = 0;
|
1922
1924
|
const generateId = () => {
|
1923
1925
|
const counterString = String(idCounter++);
|
@@ -1941,7 +1943,7 @@ var BaseTransactionRequest = class {
|
|
1941
1943
|
id: generateId(),
|
1942
1944
|
amount: quantity,
|
1943
1945
|
assetId,
|
1944
|
-
owner: Address.fromRandom(),
|
1946
|
+
owner: resourcesOwner || Address.fromRandom(),
|
1945
1947
|
maturity: 0,
|
1946
1948
|
blockCreated: bn6(1),
|
1947
1949
|
txCreatedIdx: bn6(1)
|
@@ -1974,19 +1976,29 @@ var BaseTransactionRequest = class {
|
|
1974
1976
|
toJSON() {
|
1975
1977
|
return normalizeJSON(this);
|
1976
1978
|
}
|
1977
|
-
|
1978
|
-
|
1979
|
-
|
1980
|
-
|
1981
|
-
|
1982
|
-
|
1983
|
-
|
1984
|
-
|
1985
|
-
|
1986
|
-
|
1987
|
-
|
1988
|
-
|
1989
|
-
|
1979
|
+
updatePredicateInputs(inputs) {
|
1980
|
+
this.inputs.forEach((i) => {
|
1981
|
+
let correspondingInput;
|
1982
|
+
switch (i.type) {
|
1983
|
+
case InputType2.Contract:
|
1984
|
+
return;
|
1985
|
+
case InputType2.Coin:
|
1986
|
+
correspondingInput = inputs.find((x) => x.type === InputType2.Coin && x.owner === i.owner);
|
1987
|
+
break;
|
1988
|
+
case InputType2.Message:
|
1989
|
+
correspondingInput = inputs.find(
|
1990
|
+
(x) => x.type === InputType2.Message && x.sender === i.sender
|
1991
|
+
);
|
1992
|
+
break;
|
1993
|
+
default:
|
1994
|
+
break;
|
1995
|
+
}
|
1996
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && bn6(correspondingInput.predicateGasUsed).gt(0)) {
|
1997
|
+
i.predicate = correspondingInput.predicate;
|
1998
|
+
i.predicateData = correspondingInput.predicateData;
|
1999
|
+
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
2000
|
+
}
|
2001
|
+
});
|
1990
2002
|
}
|
1991
2003
|
};
|
1992
2004
|
|
@@ -1994,7 +2006,7 @@ var BaseTransactionRequest = class {
|
|
1994
2006
|
import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
|
1995
2007
|
import { bn as bn8 } from "@fuel-ts/math";
|
1996
2008
|
import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
|
1997
|
-
import { getBytesCopy as
|
2009
|
+
import { getBytesCopy as getBytesCopy6, hexlify as hexlify9 } from "ethers";
|
1998
2010
|
|
1999
2011
|
// src/providers/transaction-request/hash-transaction.ts
|
2000
2012
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
@@ -2068,10 +2080,10 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2068
2080
|
}
|
2069
2081
|
|
2070
2082
|
// src/providers/transaction-request/storage-slot.ts
|
2071
|
-
import { getBytesCopy as
|
2083
|
+
import { getBytesCopy as getBytesCopy5, hexlify as hexlify8 } from "ethers";
|
2072
2084
|
var getStorageValue = (value) => {
|
2073
2085
|
const v = new Uint8Array(32);
|
2074
|
-
v.set(
|
2086
|
+
v.set(getBytesCopy5(value));
|
2075
2087
|
return v;
|
2076
2088
|
};
|
2077
2089
|
var storageSlotify = (storageSlot) => {
|
@@ -2176,7 +2188,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2176
2188
|
}
|
2177
2189
|
metadataGas(gasCosts) {
|
2178
2190
|
return calculateMetadataGasForTxCreate({
|
2179
|
-
contractBytesSize: bn8(
|
2191
|
+
contractBytesSize: bn8(getBytesCopy6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2180
2192
|
gasCosts,
|
2181
2193
|
stateRootSize: this.storageSlots.length,
|
2182
2194
|
txBytesSize: this.byteSize()
|
@@ -2190,17 +2202,17 @@ import { addressify as addressify2 } from "@fuel-ts/address";
|
|
2190
2202
|
import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
2191
2203
|
import { bn as bn9 } from "@fuel-ts/math";
|
2192
2204
|
import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2193
|
-
import { getBytesCopy as
|
2205
|
+
import { getBytesCopy as getBytesCopy8, hexlify as hexlify10 } from "ethers";
|
2194
2206
|
|
2195
2207
|
// src/providers/transaction-request/scripts.ts
|
2196
|
-
import { getBytesCopy as
|
2208
|
+
import { getBytesCopy as getBytesCopy7 } from "ethers";
|
2197
2209
|
var returnZeroScript = {
|
2198
2210
|
/*
|
2199
2211
|
Opcode::RET(REG_ZERO)
|
2200
2212
|
Opcode::NOOP
|
2201
2213
|
*/
|
2202
2214
|
// TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
|
2203
|
-
bytes:
|
2215
|
+
bytes: getBytesCopy7("0x24000000"),
|
2204
2216
|
encodeScriptData: () => new Uint8Array(0)
|
2205
2217
|
};
|
2206
2218
|
var withdrawScript = {
|
@@ -2214,7 +2226,7 @@ var withdrawScript = {
|
|
2214
2226
|
00000000 00000000 [amount value]
|
2215
2227
|
*/
|
2216
2228
|
// TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
|
2217
|
-
bytes:
|
2229
|
+
bytes: getBytesCopy7("0x5040C0105D44C0064C40001124000000"),
|
2218
2230
|
encodeScriptData: () => new Uint8Array(0)
|
2219
2231
|
};
|
2220
2232
|
|
@@ -2242,8 +2254,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2242
2254
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2243
2255
|
super(rest);
|
2244
2256
|
this.gasLimit = bn9(gasLimit);
|
2245
|
-
this.script =
|
2246
|
-
this.scriptData =
|
2257
|
+
this.script = getBytesCopy8(script ?? returnZeroScript.bytes);
|
2258
|
+
this.scriptData = getBytesCopy8(scriptData ?? returnZeroScript.encodeScriptData());
|
2247
2259
|
}
|
2248
2260
|
/**
|
2249
2261
|
* Converts the transaction request to a `TransactionScript`.
|
@@ -2251,8 +2263,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2251
2263
|
* @returns The transaction script object.
|
2252
2264
|
*/
|
2253
2265
|
toTransaction() {
|
2254
|
-
const script =
|
2255
|
-
const scriptData =
|
2266
|
+
const script = getBytesCopy8(this.script ?? "0x");
|
2267
|
+
const scriptData = getBytesCopy8(this.scriptData ?? "0x");
|
2256
2268
|
return {
|
2257
2269
|
type: TransactionType4.Script,
|
2258
2270
|
scriptGasLimit: this.gasLimit,
|
@@ -2412,7 +2424,7 @@ var transactionRequestify = (obj) => {
|
|
2412
2424
|
import { ErrorCode as ErrorCode10, FuelError as FuelError11 } from "@fuel-ts/errors";
|
2413
2425
|
import { bn as bn13 } from "@fuel-ts/math";
|
2414
2426
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2415
|
-
import { getBytesCopy as
|
2427
|
+
import { getBytesCopy as getBytesCopy10 } from "ethers";
|
2416
2428
|
|
2417
2429
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2418
2430
|
import { hexlify as hexlify11 } from "ethers";
|
@@ -2420,7 +2432,7 @@ import { hexlify as hexlify11 } from "ethers";
|
|
2420
2432
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2421
2433
|
import { bn as bn10 } from "@fuel-ts/math";
|
2422
2434
|
import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
|
2423
|
-
import { getBytesCopy as
|
2435
|
+
import { getBytesCopy as getBytesCopy9 } from "ethers";
|
2424
2436
|
var calculateTransactionFee = (params) => {
|
2425
2437
|
const {
|
2426
2438
|
gasUsed,
|
@@ -2429,7 +2441,7 @@ var calculateTransactionFee = (params) => {
|
|
2429
2441
|
} = params;
|
2430
2442
|
const gasPerByte = bn10(feeParams.gasPerByte);
|
2431
2443
|
const gasPriceFactor = bn10(feeParams.gasPriceFactor);
|
2432
|
-
const transactionBytes =
|
2444
|
+
const transactionBytes = getBytesCopy9(rawPayload);
|
2433
2445
|
const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
|
2434
2446
|
if (transaction.type === TransactionType6.Mint) {
|
2435
2447
|
return {
|
@@ -2444,7 +2456,7 @@ var calculateTransactionFee = (params) => {
|
|
2444
2456
|
let gasLimit = bn10(0);
|
2445
2457
|
if (type === TransactionType6.Create) {
|
2446
2458
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2447
|
-
const contractBytesSize = bn10(
|
2459
|
+
const contractBytesSize = bn10(getBytesCopy9(witnesses[bytecodeWitnessIndex].data).length);
|
2448
2460
|
metadataGas = calculateMetadataGasForTxCreate({
|
2449
2461
|
contractBytesSize,
|
2450
2462
|
gasCosts,
|
@@ -3203,7 +3215,7 @@ var TransactionResponse = class {
|
|
3203
3215
|
*/
|
3204
3216
|
decodeTransaction(transactionWithReceipts) {
|
3205
3217
|
return new TransactionCoder4().decode(
|
3206
|
-
|
3218
|
+
getBytesCopy10(transactionWithReceipts.rawPayload),
|
3207
3219
|
0
|
3208
3220
|
)?.[0];
|
3209
3221
|
}
|
@@ -3229,7 +3241,7 @@ var TransactionResponse = class {
|
|
3229
3241
|
id: this.id,
|
3230
3242
|
receipts,
|
3231
3243
|
transaction: decodedTransaction,
|
3232
|
-
transactionBytes:
|
3244
|
+
transactionBytes: getBytesCopy10(transaction.rawPayload),
|
3233
3245
|
gqlTransactionStatus: transaction.status,
|
3234
3246
|
gasPerByte,
|
3235
3247
|
gasPriceFactor,
|
@@ -3652,7 +3664,7 @@ var _Provider = class {
|
|
3652
3664
|
async call(transactionRequestLike, { utxoValidation, estimateTxDependencies = true } = {}) {
|
3653
3665
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
3654
3666
|
if (estimateTxDependencies) {
|
3655
|
-
|
3667
|
+
return this.estimateTxDependencies(transactionRequest);
|
3656
3668
|
}
|
3657
3669
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3658
3670
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
@@ -3671,6 +3683,14 @@ var _Provider = class {
|
|
3671
3683
|
* @returns A promise that resolves to the estimated transaction request object.
|
3672
3684
|
*/
|
3673
3685
|
async estimatePredicates(transactionRequest) {
|
3686
|
+
const shouldEstimatePredicates = Boolean(
|
3687
|
+
transactionRequest.inputs.find(
|
3688
|
+
(input) => "predicate" in input && input.predicate && !equalBytes(arrayify(input.predicate), arrayify("0x")) && new BN(input.predicateGasUsed).isZero()
|
3689
|
+
)
|
3690
|
+
);
|
3691
|
+
if (!shouldEstimatePredicates) {
|
3692
|
+
return transactionRequest;
|
3693
|
+
}
|
3674
3694
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3675
3695
|
const response = await this.operations.estimatePredicates({
|
3676
3696
|
encodedTransaction
|
@@ -3701,34 +3721,33 @@ var _Provider = class {
|
|
3701
3721
|
* @returns A promise.
|
3702
3722
|
*/
|
3703
3723
|
async estimateTxDependencies(transactionRequest) {
|
3704
|
-
let missingOutputVariableCount = 0;
|
3705
|
-
let missingOutputContractIdsCount = 0;
|
3706
|
-
let tries = 0;
|
3707
3724
|
if (transactionRequest.type === TransactionType8.Create) {
|
3708
|
-
return
|
3709
|
-
|
3710
|
-
|
3711
|
-
if (txRequest.hasPredicateInput()) {
|
3712
|
-
txRequest = await this.estimatePredicates(txRequest);
|
3725
|
+
return {
|
3726
|
+
receipts: []
|
3727
|
+
};
|
3713
3728
|
}
|
3714
|
-
|
3729
|
+
await this.estimatePredicates(transactionRequest);
|
3730
|
+
let receipts = [];
|
3731
|
+
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3715
3732
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3716
|
-
encodedTransaction: hexlify12(
|
3733
|
+
encodedTransaction: hexlify12(transactionRequest.toTransactionBytes()),
|
3717
3734
|
utxoValidation: false
|
3718
3735
|
});
|
3719
|
-
|
3736
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
3720
3737
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3721
|
-
|
3722
|
-
|
3723
|
-
|
3724
|
-
|
3738
|
+
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3739
|
+
if (hasMissingOutputs) {
|
3740
|
+
transactionRequest.addVariableOutputs(missingOutputVariables.length);
|
3741
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
3742
|
+
transactionRequest.addContractInputAndOutput(Address2.fromString(contractId));
|
3743
|
+
});
|
3744
|
+
} else {
|
3745
|
+
break;
|
3725
3746
|
}
|
3726
|
-
txRequest.addVariableOutputs(missingOutputVariableCount);
|
3727
|
-
missingOutputContractIds.forEach(
|
3728
|
-
({ contractId }) => txRequest.addContractInputAndOutput(Address2.fromString(contractId))
|
3729
|
-
);
|
3730
|
-
tries += 1;
|
3731
3747
|
}
|
3748
|
+
return {
|
3749
|
+
receipts
|
3750
|
+
};
|
3732
3751
|
}
|
3733
3752
|
/**
|
3734
3753
|
* Executes a signed transaction without applying the states changes
|
@@ -3743,7 +3762,7 @@ var _Provider = class {
|
|
3743
3762
|
async simulate(transactionRequestLike, { estimateTxDependencies = true } = {}) {
|
3744
3763
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
3745
3764
|
if (estimateTxDependencies) {
|
3746
|
-
|
3765
|
+
return this.estimateTxDependencies(transactionRequest);
|
3747
3766
|
}
|
3748
3767
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3749
3768
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
@@ -3770,36 +3789,38 @@ var _Provider = class {
|
|
3770
3789
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
3771
3790
|
* @returns A promise that resolves to the transaction cost object.
|
3772
3791
|
*/
|
3773
|
-
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3774
|
-
|
3792
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3793
|
+
estimateTxDependencies = true,
|
3794
|
+
estimatePredicates = true,
|
3795
|
+
resourcesOwner
|
3796
|
+
} = {}) {
|
3797
|
+
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3775
3798
|
const chainInfo = this.getChain();
|
3776
3799
|
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3777
|
-
const gasPrice = max(
|
3778
|
-
const isScriptTransaction =
|
3779
|
-
|
3800
|
+
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3801
|
+
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
3802
|
+
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3803
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3804
|
+
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3805
|
+
if (estimatePredicates) {
|
3780
3806
|
if (isScriptTransaction) {
|
3781
|
-
|
3807
|
+
txRequestClone.gasLimit = bn14(0);
|
3808
|
+
}
|
3809
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3810
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3782
3811
|
}
|
3783
|
-
await this.estimatePredicates(
|
3812
|
+
await this.estimatePredicates(txRequestClone);
|
3784
3813
|
}
|
3785
|
-
const minGas =
|
3786
|
-
const maxGas =
|
3787
|
-
const coinOutputsQuantities = transactionRequest.getCoinOutputsQuantities();
|
3788
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3789
|
-
transactionRequest.fundWithFakeUtxos(allQuantities);
|
3790
|
-
let gasUsed = minGas;
|
3814
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
3815
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
3791
3816
|
let receipts = [];
|
3792
|
-
if (isScriptTransaction) {
|
3793
|
-
|
3794
|
-
|
3795
|
-
const result = await this.
|
3796
|
-
estimateTxDependencies
|
3797
|
-
});
|
3817
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
3818
|
+
txRequestClone.gasPrice = bn14(0);
|
3819
|
+
txRequestClone.gasLimit = bn14(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3820
|
+
const result = await this.estimateTxDependencies(txRequestClone);
|
3798
3821
|
receipts = result.receipts;
|
3799
|
-
gasUsed = getGasUsedFromReceipts(receipts);
|
3800
|
-
} else {
|
3801
|
-
gasUsed = minGas;
|
3802
3822
|
}
|
3823
|
+
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3803
3824
|
const usedFee = calculatePriceWithFactor(
|
3804
3825
|
gasUsed,
|
3805
3826
|
gasPrice,
|
@@ -3817,7 +3838,9 @@ var _Provider = class {
|
|
3817
3838
|
maxGas,
|
3818
3839
|
usedFee,
|
3819
3840
|
minFee,
|
3820
|
-
maxFee
|
3841
|
+
maxFee,
|
3842
|
+
estimatedInputs: txRequestClone.inputs,
|
3843
|
+
estimatedOutputs: txRequestClone.outputs
|
3821
3844
|
};
|
3822
3845
|
}
|
3823
3846
|
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
@@ -3985,7 +4008,7 @@ var _Provider = class {
|
|
3985
4008
|
time: block.header.time,
|
3986
4009
|
transactionIds: block.transactions.map((tx) => tx.id),
|
3987
4010
|
transactions: block.transactions.map(
|
3988
|
-
(tx) => new TransactionCoder5().decode(
|
4011
|
+
(tx) => new TransactionCoder5().decode(getBytesCopy11(tx.rawPayload), 0)?.[0]
|
3989
4012
|
)
|
3990
4013
|
};
|
3991
4014
|
}
|
@@ -4001,7 +4024,7 @@ var _Provider = class {
|
|
4001
4024
|
return null;
|
4002
4025
|
}
|
4003
4026
|
return new TransactionCoder5().decode(
|
4004
|
-
|
4027
|
+
getBytesCopy11(transaction.rawPayload),
|
4005
4028
|
0
|
4006
4029
|
)?.[0];
|
4007
4030
|
}
|
@@ -4207,6 +4230,10 @@ var _Provider = class {
|
|
4207
4230
|
});
|
4208
4231
|
return bn14(latestBlockHeight);
|
4209
4232
|
}
|
4233
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
4234
|
+
async getTransactionResponse(transactionId) {
|
4235
|
+
return new TransactionResponse(transactionId, this);
|
4236
|
+
}
|
4210
4237
|
};
|
4211
4238
|
var Provider = _Provider;
|
4212
4239
|
_cacheInputs = new WeakSet();
|
@@ -4227,21 +4254,66 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4227
4254
|
import { ErrorCode as ErrorCode12, FuelError as FuelError13 } from "@fuel-ts/errors";
|
4228
4255
|
import { bn as bn15 } from "@fuel-ts/math";
|
4229
4256
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4230
|
-
import { getBytesCopy as
|
4257
|
+
import { getBytesCopy as getBytesCopy12 } from "ethers";
|
4258
|
+
|
4259
|
+
// src/providers/chains.ts
|
4260
|
+
var CHAIN_IDS = {
|
4261
|
+
eth: {
|
4262
|
+
sepolia: 11155111,
|
4263
|
+
foundry: 31337
|
4264
|
+
},
|
4265
|
+
fuel: {
|
4266
|
+
beta5: 0,
|
4267
|
+
devnet: 10
|
4268
|
+
}
|
4269
|
+
};
|
4270
|
+
|
4271
|
+
// src/providers/assets/index.ts
|
4272
|
+
var assets = [
|
4273
|
+
{
|
4274
|
+
name: "Ethereum",
|
4275
|
+
symbol: "ETH",
|
4276
|
+
icon: "eth.svg",
|
4277
|
+
networks: [
|
4278
|
+
{
|
4279
|
+
type: "ethereum",
|
4280
|
+
chainId: CHAIN_IDS.eth.sepolia,
|
4281
|
+
decimals: 18
|
4282
|
+
},
|
4283
|
+
{
|
4284
|
+
type: "ethereum",
|
4285
|
+
chainId: CHAIN_IDS.eth.foundry,
|
4286
|
+
decimals: 18
|
4287
|
+
},
|
4288
|
+
{
|
4289
|
+
type: "fuel",
|
4290
|
+
chainId: CHAIN_IDS.fuel.beta5,
|
4291
|
+
decimals: 9,
|
4292
|
+
assetId: "0x0000000000000000000000000000000000000000000000000000000000000000"
|
4293
|
+
},
|
4294
|
+
{
|
4295
|
+
type: "fuel",
|
4296
|
+
chainId: CHAIN_IDS.fuel.devnet,
|
4297
|
+
decimals: 9,
|
4298
|
+
assetId: "0x0000000000000000000000000000000000000000000000000000000000000000"
|
4299
|
+
}
|
4300
|
+
]
|
4301
|
+
}
|
4302
|
+
];
|
4231
4303
|
|
4232
4304
|
// src/utils/formatTransferToContractScriptData.ts
|
4233
4305
|
import { U64Coder as U64Coder2 } from "@fuel-ts/abi-coder";
|
4234
|
-
import { BN } from "@fuel-ts/math";
|
4306
|
+
import { BN as BN2 } from "@fuel-ts/math";
|
4235
4307
|
import * as asm from "@fuels/vm-asm";
|
4236
|
-
import { getBytesCopy as
|
4308
|
+
import { getBytesCopy as getBytesCopy13 } from "ethers";
|
4237
4309
|
var formatTransferToContractScriptData = (params) => {
|
4238
4310
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4239
4311
|
const numberCoder = new U64Coder2();
|
4240
|
-
const encoded = numberCoder.encode(new
|
4312
|
+
const encoded = numberCoder.encode(new BN2(amountToTransfer).toNumber());
|
4241
4313
|
const scriptData = Uint8Array.from([
|
4242
|
-
...
|
4314
|
+
...getBytesCopy13(hexlifiedContractId),
|
4243
4315
|
...encoded,
|
4244
|
-
...
|
4316
|
+
...getBytesCopy13(assetId)
|
4245
4317
|
]);
|
4246
4318
|
return scriptData;
|
4247
4319
|
};
|
@@ -4275,15 +4347,17 @@ var Account = class extends AbstractAccount {
|
|
4275
4347
|
* The provider used to interact with the network.
|
4276
4348
|
*/
|
4277
4349
|
_provider;
|
4350
|
+
_connector;
|
4278
4351
|
/**
|
4279
4352
|
* Creates a new Account instance.
|
4280
4353
|
*
|
4281
4354
|
* @param address - The address of the account.
|
4282
4355
|
* @param provider - A Provider instance (optional).
|
4283
4356
|
*/
|
4284
|
-
constructor(address, provider) {
|
4357
|
+
constructor(address, provider, connector) {
|
4285
4358
|
super();
|
4286
4359
|
this._provider = provider;
|
4360
|
+
this._connector = connector;
|
4287
4361
|
this.address = Address3.fromDynamicInput(address);
|
4288
4362
|
}
|
4289
4363
|
/**
|
@@ -4489,7 +4563,10 @@ var Account = class extends AbstractAccount {
|
|
4489
4563
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4490
4564
|
const request = new ScriptTransactionRequest(params);
|
4491
4565
|
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
4492
|
-
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(request
|
4566
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4567
|
+
estimateTxDependencies: true,
|
4568
|
+
resourcesOwner: this
|
4569
|
+
});
|
4493
4570
|
request.gasPrice = bn16(txParams.gasPrice ?? minGasPrice);
|
4494
4571
|
request.gasLimit = bn16(txParams.gasLimit ?? gasUsed);
|
4495
4572
|
this.validateGas({
|
@@ -4499,6 +4576,7 @@ var Account = class extends AbstractAccount {
|
|
4499
4576
|
minGasPrice
|
4500
4577
|
});
|
4501
4578
|
await this.fund(request, requiredQuantities, maxFee);
|
4579
|
+
request.updatePredicateInputs(estimatedInputs);
|
4502
4580
|
return request;
|
4503
4581
|
}
|
4504
4582
|
/**
|
@@ -4512,7 +4590,7 @@ var Account = class extends AbstractAccount {
|
|
4512
4590
|
*/
|
4513
4591
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4514
4592
|
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4515
|
-
return this.sendTransaction(request);
|
4593
|
+
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4516
4594
|
}
|
4517
4595
|
/**
|
4518
4596
|
* Transfers coins to a contract address.
|
@@ -4563,14 +4641,14 @@ var Account = class extends AbstractAccount {
|
|
4563
4641
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4564
4642
|
const { minGasPrice } = this.provider.getGasConfig();
|
4565
4643
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
4566
|
-
const recipientDataArray =
|
4644
|
+
const recipientDataArray = getBytesCopy14(
|
4567
4645
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4568
4646
|
);
|
4569
|
-
const amountDataArray =
|
4647
|
+
const amountDataArray = getBytesCopy14(
|
4570
4648
|
"0x".concat(bn16(amount).toHex().substring(2).padStart(16, "0"))
|
4571
4649
|
);
|
4572
4650
|
const script = new Uint8Array([
|
4573
|
-
...
|
4651
|
+
...getBytesCopy14(withdrawScript.bytes),
|
4574
4652
|
...recipientDataArray,
|
4575
4653
|
...amountDataArray
|
4576
4654
|
]);
|
@@ -4591,17 +4669,30 @@ var Account = class extends AbstractAccount {
|
|
4591
4669
|
await this.fund(request, requiredQuantities, maxFee);
|
4592
4670
|
return this.sendTransaction(request);
|
4593
4671
|
}
|
4672
|
+
async signMessage(message) {
|
4673
|
+
if (!this._connector) {
|
4674
|
+
throw new FuelError14(ErrorCode13.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
4675
|
+
}
|
4676
|
+
return this._connector.signMessage(this.address.toString(), message);
|
4677
|
+
}
|
4594
4678
|
/**
|
4595
4679
|
* Sends a transaction to the network.
|
4596
4680
|
*
|
4597
4681
|
* @param transactionRequestLike - The transaction request to be sent.
|
4598
4682
|
* @returns A promise that resolves to the transaction response.
|
4599
4683
|
*/
|
4600
|
-
async sendTransaction(transactionRequestLike,
|
4684
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
4685
|
+
if (this._connector) {
|
4686
|
+
return this.provider.getTransactionResponse(
|
4687
|
+
await this._connector.sendTransaction(this.address.toString(), transactionRequestLike)
|
4688
|
+
);
|
4689
|
+
}
|
4601
4690
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
4602
|
-
|
4691
|
+
if (estimateTxDependencies) {
|
4692
|
+
await this.provider.estimateTxDependencies(transactionRequest);
|
4693
|
+
}
|
4603
4694
|
return this.provider.sendTransaction(transactionRequest, {
|
4604
|
-
|
4695
|
+
awaitExecution,
|
4605
4696
|
estimateTxDependencies: false
|
4606
4697
|
});
|
4607
4698
|
}
|
@@ -4611,9 +4702,11 @@ var Account = class extends AbstractAccount {
|
|
4611
4702
|
* @param transactionRequestLike - The transaction request to be simulated.
|
4612
4703
|
* @returns A promise that resolves to the call result.
|
4613
4704
|
*/
|
4614
|
-
async simulateTransaction(transactionRequestLike) {
|
4705
|
+
async simulateTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
|
4615
4706
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
4616
|
-
|
4707
|
+
if (estimateTxDependencies) {
|
4708
|
+
await this.provider.estimateTxDependencies(transactionRequest);
|
4709
|
+
}
|
4617
4710
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
4618
4711
|
}
|
4619
4712
|
validateGas({
|
@@ -4643,7 +4736,7 @@ import { randomBytes } from "@fuel-ts/crypto";
|
|
4643
4736
|
import { hash } from "@fuel-ts/hasher";
|
4644
4737
|
import { toBytes } from "@fuel-ts/math";
|
4645
4738
|
import { secp256k1 } from "@noble/curves/secp256k1";
|
4646
|
-
import { hexlify as hexlify13, concat as concat3, getBytesCopy as
|
4739
|
+
import { hexlify as hexlify13, concat as concat3, getBytesCopy as getBytesCopy15 } from "ethers";
|
4647
4740
|
var Signer = class {
|
4648
4741
|
address;
|
4649
4742
|
publicKey;
|
@@ -4678,7 +4771,7 @@ var Signer = class {
|
|
4678
4771
|
* @returns hashed signature
|
4679
4772
|
*/
|
4680
4773
|
sign(data) {
|
4681
|
-
const signature = secp256k1.sign(
|
4774
|
+
const signature = secp256k1.sign(getBytesCopy15(data), getBytesCopy15(this.privateKey));
|
4682
4775
|
const r = toBytes(`0x${signature.r.toString(16)}`, 32);
|
4683
4776
|
const s = toBytes(`0x${signature.s.toString(16)}`, 32);
|
4684
4777
|
s[0] |= (signature.recovery || 0) << 7;
|
@@ -4691,8 +4784,8 @@ var Signer = class {
|
|
4691
4784
|
* @returns compressed point on the curve
|
4692
4785
|
*/
|
4693
4786
|
addPoint(point) {
|
4694
|
-
const p0 = secp256k1.ProjectivePoint.fromHex(
|
4695
|
-
const p1 = secp256k1.ProjectivePoint.fromHex(
|
4787
|
+
const p0 = secp256k1.ProjectivePoint.fromHex(getBytesCopy15(this.compressedPublicKey));
|
4788
|
+
const p1 = secp256k1.ProjectivePoint.fromHex(getBytesCopy15(point));
|
4696
4789
|
const result = p0.add(p1);
|
4697
4790
|
return `0x${result.toHex(true)}`;
|
4698
4791
|
}
|
@@ -4704,7 +4797,7 @@ var Signer = class {
|
|
4704
4797
|
* @returns public key from signature from the
|
4705
4798
|
*/
|
4706
4799
|
static recoverPublicKey(data, signature) {
|
4707
|
-
const signedMessageBytes =
|
4800
|
+
const signedMessageBytes = getBytesCopy15(signature);
|
4708
4801
|
const r = signedMessageBytes.slice(0, 32);
|
4709
4802
|
const s = signedMessageBytes.slice(32, 64);
|
4710
4803
|
const recoveryParam = (s[0] & 128) >> 7;
|
@@ -4712,7 +4805,7 @@ var Signer = class {
|
|
4712
4805
|
const sig = new secp256k1.Signature(BigInt(hexlify13(r)), BigInt(hexlify13(s))).addRecoveryBit(
|
4713
4806
|
recoveryParam
|
4714
4807
|
);
|
4715
|
-
const publicKey = sig.recoverPublicKey(
|
4808
|
+
const publicKey = sig.recoverPublicKey(getBytesCopy15(data)).toRawBytes(false).slice(1);
|
4716
4809
|
return hexlify13(publicKey);
|
4717
4810
|
}
|
4718
4811
|
/**
|
@@ -4732,7 +4825,7 @@ var Signer = class {
|
|
4732
4825
|
* @returns random 32-byte hashed
|
4733
4826
|
*/
|
4734
4827
|
static generatePrivateKey(entropy) {
|
4735
|
-
return entropy ? hash(concat3([randomBytes(32),
|
4828
|
+
return entropy ? hash(concat3([randomBytes(32), getBytesCopy15(entropy)])) : randomBytes(32);
|
4736
4829
|
}
|
4737
4830
|
/**
|
4738
4831
|
* Extended publicKey from a compact publicKey
|
@@ -4741,7 +4834,7 @@ var Signer = class {
|
|
4741
4834
|
* @returns extended publicKey
|
4742
4835
|
*/
|
4743
4836
|
static extendPublicKey(publicKey) {
|
4744
|
-
const point = secp256k1.ProjectivePoint.fromHex(
|
4837
|
+
const point = secp256k1.ProjectivePoint.fromHex(getBytesCopy15(publicKey));
|
4745
4838
|
return hexlify13(point.toRawBytes(false).slice(1));
|
4746
4839
|
}
|
4747
4840
|
};
|
@@ -4919,12 +5012,14 @@ var BaseWalletUnlocked = class extends Account {
|
|
4919
5012
|
* @param transactionRequestLike - The transaction request to send.
|
4920
5013
|
* @returns A promise that resolves to the TransactionResponse object.
|
4921
5014
|
*/
|
4922
|
-
async sendTransaction(transactionRequestLike,
|
5015
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
4923
5016
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
4924
|
-
|
5017
|
+
if (estimateTxDependencies) {
|
5018
|
+
await this.provider.estimateTxDependencies(transactionRequest);
|
5019
|
+
}
|
4925
5020
|
return this.provider.sendTransaction(
|
4926
5021
|
await this.populateTransactionWitnessesSignature(transactionRequest),
|
4927
|
-
{
|
5022
|
+
{ awaitExecution, estimateTxDependencies: false }
|
4928
5023
|
);
|
4929
5024
|
}
|
4930
5025
|
/**
|
@@ -4933,9 +5028,11 @@ var BaseWalletUnlocked = class extends Account {
|
|
4933
5028
|
* @param transactionRequestLike - The transaction request to simulate.
|
4934
5029
|
* @returns A promise that resolves to the CallResult object.
|
4935
5030
|
*/
|
4936
|
-
async simulateTransaction(transactionRequestLike) {
|
5031
|
+
async simulateTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
|
4937
5032
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
4938
|
-
|
5033
|
+
if (estimateTxDependencies) {
|
5034
|
+
await this.provider.estimateTxDependencies(transactionRequest);
|
5035
|
+
}
|
4939
5036
|
return this.provider.call(
|
4940
5037
|
await this.populateTransactionWitnessesSignature(transactionRequest),
|
4941
5038
|
{
|
@@ -4965,7 +5062,7 @@ import {
|
|
4965
5062
|
sha256 as sha2564,
|
4966
5063
|
computeHmac as computeHmac2,
|
4967
5064
|
ripemd160,
|
4968
|
-
getBytesCopy as
|
5065
|
+
getBytesCopy as getBytesCopy18,
|
4969
5066
|
concat as concat5
|
4970
5067
|
} from "ethers";
|
4971
5068
|
|
@@ -4980,7 +5077,7 @@ import {
|
|
4980
5077
|
sha256 as sha2563,
|
4981
5078
|
computeHmac,
|
4982
5079
|
encodeBase58,
|
4983
|
-
getBytesCopy as
|
5080
|
+
getBytesCopy as getBytesCopy17
|
4984
5081
|
} from "ethers";
|
4985
5082
|
|
4986
5083
|
// src/wordlists/words/english.ts
|
@@ -7037,7 +7134,7 @@ var english = [
|
|
7037
7134
|
|
7038
7135
|
// src/mnemonic/utils.ts
|
7039
7136
|
import { ErrorCode as ErrorCode15, FuelError as FuelError16 } from "@fuel-ts/errors";
|
7040
|
-
import { getBytesCopy as
|
7137
|
+
import { getBytesCopy as getBytesCopy16, sha256 as sha2562 } from "ethers";
|
7041
7138
|
function toUtf8Bytes(stri) {
|
7042
7139
|
const str = stri.normalize("NFKD");
|
7043
7140
|
const result = [];
|
@@ -7104,14 +7201,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7104
7201
|
}
|
7105
7202
|
}
|
7106
7203
|
const checksumBits = entropy.length / 4;
|
7107
|
-
const checksum =
|
7204
|
+
const checksum = getBytesCopy16(sha2562(entropy))[0] & getUpperMask(checksumBits);
|
7108
7205
|
indices[indices.length - 1] <<= checksumBits;
|
7109
7206
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7110
7207
|
return indices;
|
7111
7208
|
}
|
7112
7209
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7113
7210
|
const size = Math.ceil(11 * words.length / 8);
|
7114
|
-
const entropy =
|
7211
|
+
const entropy = getBytesCopy16(new Uint8Array(size));
|
7115
7212
|
let offset = 0;
|
7116
7213
|
for (let i = 0; i < words.length; i += 1) {
|
7117
7214
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7131,7 +7228,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7131
7228
|
const entropyBits = 32 * words.length / 3;
|
7132
7229
|
const checksumBits = words.length / 3;
|
7133
7230
|
const checksumMask = getUpperMask(checksumBits);
|
7134
|
-
const checksum =
|
7231
|
+
const checksum = getBytesCopy16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7135
7232
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7136
7233
|
throw new FuelError16(
|
7137
7234
|
ErrorCode15.INVALID_CHECKSUM,
|
@@ -7214,7 +7311,7 @@ var Mnemonic = class {
|
|
7214
7311
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7215
7312
|
*/
|
7216
7313
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7217
|
-
const entropyBytes =
|
7314
|
+
const entropyBytes = getBytesCopy17(entropy);
|
7218
7315
|
assertWordList(wordlist);
|
7219
7316
|
assertEntropy(entropyBytes);
|
7220
7317
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7283,14 +7380,14 @@ var Mnemonic = class {
|
|
7283
7380
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7284
7381
|
*/
|
7285
7382
|
static masterKeysFromSeed(seed) {
|
7286
|
-
const seedArray =
|
7383
|
+
const seedArray = getBytesCopy17(seed);
|
7287
7384
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7288
7385
|
throw new FuelError17(
|
7289
7386
|
ErrorCode16.INVALID_SEED,
|
7290
7387
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7291
7388
|
);
|
7292
7389
|
}
|
7293
|
-
return
|
7390
|
+
return getBytesCopy17(computeHmac("sha512", MasterSecret, seedArray));
|
7294
7391
|
}
|
7295
7392
|
/**
|
7296
7393
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7301,7 +7398,7 @@ var Mnemonic = class {
|
|
7301
7398
|
*/
|
7302
7399
|
static seedToExtendedKey(seed, testnet = false) {
|
7303
7400
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7304
|
-
const prefix =
|
7401
|
+
const prefix = getBytesCopy17(testnet ? TestnetPRV : MainnetPRV);
|
7305
7402
|
const depth = "0x00";
|
7306
7403
|
const fingerprint = "0x00000000";
|
7307
7404
|
const index = "0x00000000";
|
@@ -7331,7 +7428,7 @@ var Mnemonic = class {
|
|
7331
7428
|
* @returns A randomly generated mnemonic
|
7332
7429
|
*/
|
7333
7430
|
static generate(size = 32, extraEntropy = "") {
|
7334
|
-
const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size),
|
7431
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size), getBytesCopy17(extraEntropy)])) : randomBytes3(size);
|
7335
7432
|
return Mnemonic.entropyToMnemonic(entropy);
|
7336
7433
|
}
|
7337
7434
|
};
|
@@ -7416,9 +7513,9 @@ var HDWallet = class {
|
|
7416
7513
|
* @returns A new instance of HDWallet on the derived index
|
7417
7514
|
*/
|
7418
7515
|
deriveIndex(index) {
|
7419
|
-
const privateKey = this.privateKey &&
|
7420
|
-
const publicKey =
|
7421
|
-
const chainCode =
|
7516
|
+
const privateKey = this.privateKey && getBytesCopy18(this.privateKey);
|
7517
|
+
const publicKey = getBytesCopy18(this.publicKey);
|
7518
|
+
const chainCode = getBytesCopy18(this.chainCode);
|
7422
7519
|
const data = new Uint8Array(37);
|
7423
7520
|
if (index & HARDENED_INDEX) {
|
7424
7521
|
if (!privateKey) {
|
@@ -7429,10 +7526,10 @@ var HDWallet = class {
|
|
7429
7526
|
}
|
7430
7527
|
data.set(privateKey, 1);
|
7431
7528
|
} else {
|
7432
|
-
data.set(
|
7529
|
+
data.set(getBytesCopy18(this.publicKey));
|
7433
7530
|
}
|
7434
7531
|
data.set(toBytes2(index, 4), 33);
|
7435
|
-
const bytes =
|
7532
|
+
const bytes = getBytesCopy18(computeHmac2("sha512", chainCode, data));
|
7436
7533
|
const IL = bytes.slice(0, 32);
|
7437
7534
|
const IR = bytes.slice(32);
|
7438
7535
|
if (privateKey) {
|
@@ -7486,7 +7583,7 @@ var HDWallet = class {
|
|
7486
7583
|
const index = toHex(this.index, 4);
|
7487
7584
|
const chainCode = this.chainCode;
|
7488
7585
|
const key = this.privateKey != null && !isPublic ? concat5(["0x00", this.privateKey]) : this.publicKey;
|
7489
|
-
const extendedKey =
|
7586
|
+
const extendedKey = getBytesCopy18(
|
7490
7587
|
concat5([prefix, depth, parentFingerprint, index, chainCode, key])
|
7491
7588
|
);
|
7492
7589
|
return base58check(extendedKey);
|
@@ -7500,13 +7597,13 @@ var HDWallet = class {
|
|
7500
7597
|
static fromSeed(seed) {
|
7501
7598
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
7502
7599
|
return new HDWallet({
|
7503
|
-
chainCode:
|
7504
|
-
privateKey:
|
7600
|
+
chainCode: getBytesCopy18(masterKey.slice(32)),
|
7601
|
+
privateKey: getBytesCopy18(masterKey.slice(0, 32))
|
7505
7602
|
});
|
7506
7603
|
}
|
7507
7604
|
static fromExtendedKey(extendedKey) {
|
7508
7605
|
const decoded = toBeHex(decodeBase58(extendedKey));
|
7509
|
-
const bytes =
|
7606
|
+
const bytes = getBytesCopy18(decoded);
|
7510
7607
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7511
7608
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7512
7609
|
throw new FuelError18(ErrorCode17.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|