@fuel-ts/account 0.76.0 → 0.77.0
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/hdwallet/hdwallet.d.ts.map +1 -1
- package/dist/index.global.js +840 -1334
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +85 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +145 -115
- package/dist/index.mjs.map +1 -1
- package/dist/mnemonic/mnemonic.d.ts.map +1 -1
- package/dist/mnemonic/utils.d.ts.map +1 -1
- package/dist/predicate/predicate.d.ts +16 -15
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +9 -0
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/assets/index.d.ts +1 -0
- package/dist/providers/assets/index.d.ts.map +1 -1
- package/dist/providers/assets/types.d.ts +5 -5
- package/dist/providers/assets/types.d.ts.map +1 -1
- package/dist/providers/assets/utils/network.d.ts +4 -4
- package/dist/providers/assets/utils/network.d.ts.map +1 -1
- package/dist/providers/assets/utils/resolveIconPaths.d.ts +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +23 -14
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/hash-transaction.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/test-utils.global.js +817 -1308
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +64 -26
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +105 -75
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.js
CHANGED
@@ -112,7 +112,7 @@ var import_transactions17 = require("@fuel-ts/transactions");
|
|
112
112
|
var import_utils22 = require("@fuel-ts/utils");
|
113
113
|
var import_versions = require("@fuel-ts/versions");
|
114
114
|
var import_utils23 = require("@noble/curves/abstract/utils");
|
115
|
-
var
|
115
|
+
var import_ethers = require("ethers");
|
116
116
|
var import_graphql_request = require("graphql-request");
|
117
117
|
var import_ramda3 = require("ramda");
|
118
118
|
|
@@ -177,6 +177,9 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
177
177
|
time
|
178
178
|
reason
|
179
179
|
}
|
180
|
+
... on SqueezedOutStatus {
|
181
|
+
reason
|
182
|
+
}
|
180
183
|
}
|
181
184
|
`;
|
182
185
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
@@ -954,7 +957,16 @@ var _FuelGraphqlSubscriber = class {
|
|
954
957
|
if (!text.startsWith("data:")) {
|
955
958
|
continue;
|
956
959
|
}
|
957
|
-
|
960
|
+
let data;
|
961
|
+
let errors;
|
962
|
+
try {
|
963
|
+
({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
|
964
|
+
} catch (e) {
|
965
|
+
throw new import_errors.FuelError(
|
966
|
+
import_errors.ErrorCode.STREAM_PARSING_ERROR,
|
967
|
+
`Error while parsing stream data response: ${text}`
|
968
|
+
);
|
969
|
+
}
|
958
970
|
if (Array.isArray(errors)) {
|
959
971
|
throw new import_errors.FuelError(
|
960
972
|
import_errors.FuelError.CODES.INVALID_REQUEST,
|
@@ -1746,7 +1758,7 @@ var BaseTransactionRequest = class {
|
|
1746
1758
|
txPointer: "0x00000000000000000000000000000000",
|
1747
1759
|
witnessIndex,
|
1748
1760
|
predicate: predicate?.bytes,
|
1749
|
-
predicateData: predicate?.
|
1761
|
+
predicateData: predicate?.predicateDataBytes
|
1750
1762
|
};
|
1751
1763
|
this.pushInput(input);
|
1752
1764
|
this.addChangeOutput(owner, assetId);
|
@@ -1779,7 +1791,7 @@ var BaseTransactionRequest = class {
|
|
1779
1791
|
amount,
|
1780
1792
|
witnessIndex,
|
1781
1793
|
predicate: predicate?.bytes,
|
1782
|
-
predicateData: predicate?.
|
1794
|
+
predicateData: predicate?.predicateDataBytes
|
1783
1795
|
};
|
1784
1796
|
this.pushInput(input);
|
1785
1797
|
this.addChangeOutput(recipient, assetId);
|
@@ -2026,7 +2038,6 @@ var import_hasher = require("@fuel-ts/hasher");
|
|
2026
2038
|
var import_math7 = require("@fuel-ts/math");
|
2027
2039
|
var import_transactions6 = require("@fuel-ts/transactions");
|
2028
2040
|
var import_utils11 = require("@fuel-ts/utils");
|
2029
|
-
var import_ethers = require("ethers");
|
2030
2041
|
var import_ramda2 = require("ramda");
|
2031
2042
|
function hashTransaction(transactionRequest, chainId) {
|
2032
2043
|
const transaction = transactionRequest.toTransaction();
|
@@ -2089,7 +2100,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2089
2100
|
transaction.witnesses = [];
|
2090
2101
|
const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
|
2091
2102
|
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions6.TransactionCoder().encode(transaction)]);
|
2092
|
-
return (0,
|
2103
|
+
return (0, import_hasher.sha256)(concatenatedData);
|
2093
2104
|
}
|
2094
2105
|
|
2095
2106
|
// src/providers/transaction-request/storage-slot.ts
|
@@ -3243,6 +3254,12 @@ var TransactionResponse = class {
|
|
3243
3254
|
transactionId: this.id
|
3244
3255
|
});
|
3245
3256
|
for await (const { statusChange } of subscription) {
|
3257
|
+
if (statusChange.type === "SqueezedOutStatus") {
|
3258
|
+
throw new import_errors12.FuelError(
|
3259
|
+
import_errors12.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
3260
|
+
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3261
|
+
);
|
3262
|
+
}
|
3246
3263
|
if (statusChange.type !== "SubmittedStatus") {
|
3247
3264
|
break;
|
3248
3265
|
}
|
@@ -3407,14 +3424,15 @@ var _Provider = class {
|
|
3407
3424
|
}
|
3408
3425
|
static getFetchFn(options) {
|
3409
3426
|
const { retryOptions, timeout } = options;
|
3410
|
-
return autoRetryFetch((...args) => {
|
3411
|
-
if (options.fetch) {
|
3412
|
-
return options.fetch(...args);
|
3413
|
-
}
|
3427
|
+
return autoRetryFetch(async (...args) => {
|
3414
3428
|
const url = args[0];
|
3415
3429
|
const request = args[1];
|
3416
3430
|
const signal = timeout ? AbortSignal.timeout(timeout) : void 0;
|
3417
|
-
|
3431
|
+
let fullRequest = { ...request, signal };
|
3432
|
+
if (options.requestMiddleware) {
|
3433
|
+
fullRequest = await options.requestMiddleware(fullRequest);
|
3434
|
+
}
|
3435
|
+
return options.fetch ? options.fetch(url, fullRequest, options) : fetch(url, fullRequest);
|
3418
3436
|
}, retryOptions);
|
3419
3437
|
}
|
3420
3438
|
/**
|
@@ -3548,7 +3566,7 @@ var _Provider = class {
|
|
3548
3566
|
name,
|
3549
3567
|
consensusParameters: { chainId }
|
3550
3568
|
} = await this.getChain();
|
3551
|
-
const network = new
|
3569
|
+
const network = new import_ethers.Network(name, chainId.toNumber());
|
3552
3570
|
return Promise.resolve(network);
|
3553
3571
|
}
|
3554
3572
|
/**
|
@@ -3620,6 +3638,12 @@ var _Provider = class {
|
|
3620
3638
|
if (awaitExecution) {
|
3621
3639
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3622
3640
|
for await (const { submitAndAwait } of subscription) {
|
3641
|
+
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3642
|
+
throw new import_errors13.FuelError(
|
3643
|
+
import_errors13.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
3644
|
+
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3645
|
+
);
|
3646
|
+
}
|
3623
3647
|
if (submitAndAwait.type !== "SubmittedStatus") {
|
3624
3648
|
break;
|
3625
3649
|
}
|
@@ -4585,6 +4609,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4585
4609
|
* @returns A promise that resolves to the transaction response.
|
4586
4610
|
*/
|
4587
4611
|
async transfer(destination, amount, assetId = import_configs11.BaseAssetId, txParams = {}) {
|
4612
|
+
if ((0, import_math17.bn)(amount).lte(0)) {
|
4613
|
+
throw new import_errors15.FuelError(
|
4614
|
+
import_errors15.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4615
|
+
"Transfer amount must be a positive number."
|
4616
|
+
);
|
4617
|
+
}
|
4588
4618
|
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4589
4619
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4590
4620
|
}
|
@@ -4598,6 +4628,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4598
4628
|
* @returns A promise that resolves to the transaction response.
|
4599
4629
|
*/
|
4600
4630
|
async transferToContract(contractId, amount, assetId = import_configs11.BaseAssetId, txParams = {}) {
|
4631
|
+
if ((0, import_math17.bn)(amount).lte(0)) {
|
4632
|
+
throw new import_errors15.FuelError(
|
4633
|
+
import_errors15.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4634
|
+
"Transfer amount must be a positive number."
|
4635
|
+
);
|
4636
|
+
}
|
4601
4637
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4602
4638
|
const { minGasPrice } = this.provider.getGasConfig();
|
4603
4639
|
const params = { gasPrice: minGasPrice, ...txParams };
|
@@ -5040,15 +5076,17 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5040
5076
|
|
5041
5077
|
// src/hdwallet/hdwallet.ts
|
5042
5078
|
var import_errors19 = require("@fuel-ts/errors");
|
5079
|
+
var import_hasher6 = require("@fuel-ts/hasher");
|
5043
5080
|
var import_math19 = require("@fuel-ts/math");
|
5044
5081
|
var import_utils34 = require("@fuel-ts/utils");
|
5045
|
-
var
|
5082
|
+
var import_ethers3 = require("ethers");
|
5046
5083
|
|
5047
5084
|
// src/mnemonic/mnemonic.ts
|
5048
5085
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5049
5086
|
var import_errors18 = require("@fuel-ts/errors");
|
5087
|
+
var import_hasher5 = require("@fuel-ts/hasher");
|
5050
5088
|
var import_utils32 = require("@fuel-ts/utils");
|
5051
|
-
var
|
5089
|
+
var import_ethers2 = require("ethers");
|
5052
5090
|
|
5053
5091
|
// src/wordlists/words/english.ts
|
5054
5092
|
var english = [
|
@@ -7104,8 +7142,8 @@ var english = [
|
|
7104
7142
|
|
7105
7143
|
// src/mnemonic/utils.ts
|
7106
7144
|
var import_errors17 = require("@fuel-ts/errors");
|
7145
|
+
var import_hasher4 = require("@fuel-ts/hasher");
|
7107
7146
|
var import_utils31 = require("@fuel-ts/utils");
|
7108
|
-
var import_ethers3 = require("ethers");
|
7109
7147
|
function toUtf8Bytes(stri) {
|
7110
7148
|
const str = stri.normalize("NFKD");
|
7111
7149
|
const result = [];
|
@@ -7172,7 +7210,7 @@ function entropyToMnemonicIndices(entropy) {
|
|
7172
7210
|
}
|
7173
7211
|
}
|
7174
7212
|
const checksumBits = entropy.length / 4;
|
7175
|
-
const checksum = (0, import_utils31.arrayify)((0,
|
7213
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7176
7214
|
indices[indices.length - 1] <<= checksumBits;
|
7177
7215
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7178
7216
|
return indices;
|
@@ -7199,7 +7237,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7199
7237
|
const entropyBits = 32 * words.length / 3;
|
7200
7238
|
const checksumBits = words.length / 3;
|
7201
7239
|
const checksumMask = getUpperMask(checksumBits);
|
7202
|
-
const checksum = (0, import_utils31.arrayify)((0,
|
7240
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7203
7241
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7204
7242
|
throw new import_errors17.FuelError(
|
7205
7243
|
import_errors17.ErrorCode.INVALID_CHECKSUM,
|
@@ -7296,7 +7334,7 @@ var Mnemonic = class {
|
|
7296
7334
|
assertMnemonic(getWords(phrase));
|
7297
7335
|
const phraseBytes = toUtf8Bytes(getPhrase(phrase));
|
7298
7336
|
const salt = toUtf8Bytes(`mnemonic${passphrase}`);
|
7299
|
-
return (0,
|
7337
|
+
return (0, import_ethers2.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
|
7300
7338
|
}
|
7301
7339
|
/**
|
7302
7340
|
* @param phrase - Mnemonic phrase composed by words from the provided wordlist
|
@@ -7358,7 +7396,7 @@ var Mnemonic = class {
|
|
7358
7396
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7359
7397
|
);
|
7360
7398
|
}
|
7361
|
-
return (0, import_utils32.arrayify)((0,
|
7399
|
+
return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7362
7400
|
}
|
7363
7401
|
/**
|
7364
7402
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7383,8 +7421,8 @@ var Mnemonic = class {
|
|
7383
7421
|
chainCode,
|
7384
7422
|
(0, import_utils32.concat)(["0x00", privateKey])
|
7385
7423
|
]);
|
7386
|
-
const checksum = (0,
|
7387
|
-
return (0,
|
7424
|
+
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7425
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
|
7388
7426
|
}
|
7389
7427
|
/**
|
7390
7428
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7399,7 +7437,7 @@ var Mnemonic = class {
|
|
7399
7437
|
* @returns A randomly generated mnemonic
|
7400
7438
|
*/
|
7401
7439
|
static generate(size = 32, extraEntropy = "") {
|
7402
|
-
const entropy = extraEntropy ? (0,
|
7440
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
|
7403
7441
|
return Mnemonic.entropyToMnemonic(entropy);
|
7404
7442
|
}
|
7405
7443
|
};
|
@@ -7412,7 +7450,7 @@ var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
|
|
7412
7450
|
var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
|
7413
7451
|
var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
|
7414
7452
|
function base58check(data) {
|
7415
|
-
return (0,
|
7453
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
7416
7454
|
}
|
7417
7455
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7418
7456
|
if (isPublic) {
|
@@ -7468,7 +7506,7 @@ var HDWallet = class {
|
|
7468
7506
|
this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
|
7469
7507
|
}
|
7470
7508
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7471
|
-
this.fingerprint = (0,
|
7509
|
+
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
7472
7510
|
this.depth = config.depth || this.depth;
|
7473
7511
|
this.index = config.index || this.index;
|
7474
7512
|
this.chainCode = config.chainCode;
|
@@ -7500,7 +7538,7 @@ var HDWallet = class {
|
|
7500
7538
|
data.set((0, import_utils34.arrayify)(this.publicKey));
|
7501
7539
|
}
|
7502
7540
|
data.set((0, import_math19.toBytes)(index, 4), 33);
|
7503
|
-
const bytes = (0, import_utils34.arrayify)((0,
|
7541
|
+
const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
7504
7542
|
const IL = bytes.slice(0, 32);
|
7505
7543
|
const IR = bytes.slice(32);
|
7506
7544
|
if (privateKey) {
|
@@ -7571,7 +7609,7 @@ var HDWallet = class {
|
|
7571
7609
|
});
|
7572
7610
|
}
|
7573
7611
|
static fromExtendedKey(extendedKey) {
|
7574
|
-
const decoded = (0,
|
7612
|
+
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
7575
7613
|
const bytes = (0, import_utils34.arrayify)(decoded);
|
7576
7614
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7577
7615
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|