@fuel-ts/account 0.0.0-rc-2045-20240417092921 → 0.0.0-rc-2037-20240417131250
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 +85 -39
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +200 -141
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +117 -64
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +11 -2
- 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/transaction-request/helpers.d.ts +10 -0
- package/dist/providers/transaction-request/helpers.d.ts.map +1 -0
- package/dist/providers/transaction-request/index.d.ts +1 -0
- package/dist/providers/transaction-request/index.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +4 -20
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/test-utils/index.d.ts +1 -0
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/resources.d.ts +4 -0
- package/dist/test-utils/resources.d.ts.map +1 -0
- package/dist/test-utils/seedTestWallet.d.ts +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils/transactionRequest.d.ts +5 -0
- package/dist/test-utils/transactionRequest.d.ts.map +1 -0
- package/dist/test-utils.global.js +64 -40
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +173 -135
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +99 -64
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +15 -15
package/dist/test-utils.mjs
CHANGED
@@ -71,7 +71,7 @@ import { Address as Address2 } from "@fuel-ts/address";
|
|
71
71
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
72
72
|
import { BN, bn as bn15, max } from "@fuel-ts/math";
|
73
73
|
import {
|
74
|
-
InputType as
|
74
|
+
InputType as InputType7,
|
75
75
|
TransactionType as TransactionType8,
|
76
76
|
InputMessageCoder,
|
77
77
|
TransactionCoder as TransactionCoder5
|
@@ -1168,7 +1168,7 @@ import { bn as bn7 } from "@fuel-ts/math";
|
|
1168
1168
|
import {
|
1169
1169
|
PolicyType,
|
1170
1170
|
TransactionCoder,
|
1171
|
-
InputType as
|
1171
|
+
InputType as InputType3,
|
1172
1172
|
OutputType as OutputType2,
|
1173
1173
|
TransactionType
|
1174
1174
|
} from "@fuel-ts/transactions";
|
@@ -1597,6 +1597,12 @@ var NoWitnessAtIndexError = class extends Error {
|
|
1597
1597
|
name = "NoWitnessAtIndexError";
|
1598
1598
|
};
|
1599
1599
|
|
1600
|
+
// src/providers/transaction-request/helpers.ts
|
1601
|
+
import { InputType as InputType2 } from "@fuel-ts/transactions";
|
1602
|
+
var isRequestInputCoin = (input) => input.type === InputType2.Coin;
|
1603
|
+
var isRequestInputMessage = (input) => input.type === InputType2.Message;
|
1604
|
+
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
1605
|
+
|
1600
1606
|
// src/providers/transaction-request/witness.ts
|
1601
1607
|
import { arrayify as arrayify4, hexlify as hexlify6 } from "@fuel-ts/utils";
|
1602
1608
|
var witnessify = (value) => {
|
@@ -1787,7 +1793,7 @@ var BaseTransactionRequest = class {
|
|
1787
1793
|
*/
|
1788
1794
|
getCoinInputs() {
|
1789
1795
|
return this.inputs.filter(
|
1790
|
-
(input) => input.type ===
|
1796
|
+
(input) => input.type === InputType3.Coin
|
1791
1797
|
);
|
1792
1798
|
}
|
1793
1799
|
/**
|
@@ -1819,9 +1825,9 @@ var BaseTransactionRequest = class {
|
|
1819
1825
|
const ownerAddress = addressify(owner);
|
1820
1826
|
const found = this.inputs.find((input) => {
|
1821
1827
|
switch (input.type) {
|
1822
|
-
case
|
1828
|
+
case InputType3.Coin:
|
1823
1829
|
return hexlify7(input.owner) === ownerAddress.toB256();
|
1824
|
-
case
|
1830
|
+
case InputType3.Message:
|
1825
1831
|
return hexlify7(input.recipient) === ownerAddress.toB256();
|
1826
1832
|
default:
|
1827
1833
|
return false;
|
@@ -1837,8 +1843,8 @@ var BaseTransactionRequest = class {
|
|
1837
1843
|
* @param predicate - Predicate bytes.
|
1838
1844
|
* @param predicateData - Predicate data bytes.
|
1839
1845
|
*/
|
1840
|
-
addCoinInput(coin
|
1841
|
-
const { assetId, owner, amount } = coin;
|
1846
|
+
addCoinInput(coin) {
|
1847
|
+
const { assetId, owner, amount, id, predicate } = coin;
|
1842
1848
|
let witnessIndex;
|
1843
1849
|
if (predicate) {
|
1844
1850
|
witnessIndex = 0;
|
@@ -1849,14 +1855,14 @@ var BaseTransactionRequest = class {
|
|
1849
1855
|
}
|
1850
1856
|
}
|
1851
1857
|
const input = {
|
1852
|
-
|
1853
|
-
type:
|
1858
|
+
id,
|
1859
|
+
type: InputType3.Coin,
|
1854
1860
|
owner: owner.toB256(),
|
1855
1861
|
amount,
|
1856
1862
|
assetId,
|
1857
1863
|
txPointer: "0x00000000000000000000000000000000",
|
1858
1864
|
witnessIndex,
|
1859
|
-
predicate
|
1865
|
+
predicate
|
1860
1866
|
};
|
1861
1867
|
this.pushInput(input);
|
1862
1868
|
this.addChangeOutput(owner, assetId);
|
@@ -1869,8 +1875,8 @@ var BaseTransactionRequest = class {
|
|
1869
1875
|
* @param predicate - Predicate bytes.
|
1870
1876
|
* @param predicateData - Predicate data bytes.
|
1871
1877
|
*/
|
1872
|
-
addMessageInput(message
|
1873
|
-
const { recipient, sender, amount } = message;
|
1878
|
+
addMessageInput(message) {
|
1879
|
+
const { recipient, sender, amount, predicate, nonce } = message;
|
1874
1880
|
const assetId = BaseAssetId2;
|
1875
1881
|
let witnessIndex;
|
1876
1882
|
if (predicate) {
|
@@ -1882,13 +1888,13 @@ var BaseTransactionRequest = class {
|
|
1882
1888
|
}
|
1883
1889
|
}
|
1884
1890
|
const input = {
|
1885
|
-
|
1886
|
-
type:
|
1891
|
+
nonce,
|
1892
|
+
type: InputType3.Message,
|
1887
1893
|
sender: sender.toB256(),
|
1888
1894
|
recipient: recipient.toB256(),
|
1889
1895
|
amount,
|
1890
1896
|
witnessIndex,
|
1891
|
-
predicate
|
1897
|
+
predicate
|
1892
1898
|
};
|
1893
1899
|
this.pushInput(input);
|
1894
1900
|
this.addChangeOutput(recipient, assetId);
|
@@ -1919,32 +1925,6 @@ var BaseTransactionRequest = class {
|
|
1919
1925
|
resources.forEach((resource) => this.addResource(resource));
|
1920
1926
|
return this;
|
1921
1927
|
}
|
1922
|
-
/**
|
1923
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1924
|
-
* outputs from the related assetIds.
|
1925
|
-
*
|
1926
|
-
* @param resources - The resources to add.
|
1927
|
-
* @returns This transaction.
|
1928
|
-
*/
|
1929
|
-
addPredicateResource(resource, predicate) {
|
1930
|
-
if (isCoin(resource)) {
|
1931
|
-
this.addCoinInput(resource, predicate);
|
1932
|
-
} else {
|
1933
|
-
this.addMessageInput(resource, predicate);
|
1934
|
-
}
|
1935
|
-
return this;
|
1936
|
-
}
|
1937
|
-
/**
|
1938
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1939
|
-
* from the related assetIds.
|
1940
|
-
*
|
1941
|
-
* @param resources - The resources to add.
|
1942
|
-
* @returns This transaction.
|
1943
|
-
*/
|
1944
|
-
addPredicateResources(resources, predicate) {
|
1945
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1946
|
-
return this;
|
1947
|
-
}
|
1948
1928
|
/**
|
1949
1929
|
* Adds a coin output to the transaction.
|
1950
1930
|
*
|
@@ -2093,16 +2073,20 @@ var BaseTransactionRequest = class {
|
|
2093
2073
|
toJSON() {
|
2094
2074
|
return normalizeJSON(this);
|
2095
2075
|
}
|
2076
|
+
removeWitness(index) {
|
2077
|
+
this.witnesses.splice(index, 1);
|
2078
|
+
this.adjustWitnessIndexes(index);
|
2079
|
+
}
|
2096
2080
|
updatePredicateInputs(inputs) {
|
2097
2081
|
this.inputs.forEach((i) => {
|
2098
2082
|
let correspondingInput;
|
2099
2083
|
switch (i.type) {
|
2100
|
-
case
|
2101
|
-
correspondingInput = inputs.find((x) => x.type ===
|
2084
|
+
case InputType3.Coin:
|
2085
|
+
correspondingInput = inputs.find((x) => x.type === InputType3.Coin && x.owner === i.owner);
|
2102
2086
|
break;
|
2103
|
-
case
|
2087
|
+
case InputType3.Message:
|
2104
2088
|
correspondingInput = inputs.find(
|
2105
|
-
(x) => x.type ===
|
2089
|
+
(x) => x.type === InputType3.Message && x.sender === i.sender
|
2106
2090
|
);
|
2107
2091
|
break;
|
2108
2092
|
default:
|
@@ -2115,6 +2099,13 @@ var BaseTransactionRequest = class {
|
|
2115
2099
|
}
|
2116
2100
|
});
|
2117
2101
|
}
|
2102
|
+
adjustWitnessIndexes(removedIndex) {
|
2103
|
+
this.inputs.filter(isRequestInputResource).forEach((input) => {
|
2104
|
+
if (input.witnessIndex > removedIndex) {
|
2105
|
+
input.witnessIndex -= 1;
|
2106
|
+
}
|
2107
|
+
});
|
2108
|
+
}
|
2118
2109
|
};
|
2119
2110
|
|
2120
2111
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2127,7 +2118,7 @@ import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
|
2127
2118
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2128
2119
|
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2129
2120
|
import { bn as bn8 } from "@fuel-ts/math";
|
2130
|
-
import { TransactionType as TransactionType2, InputType as
|
2121
|
+
import { TransactionType as TransactionType2, InputType as InputType4, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2131
2122
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2132
2123
|
import { clone as clone2 } from "ramda";
|
2133
2124
|
function hashTransaction(transactionRequest, chainId) {
|
@@ -2138,7 +2129,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2138
2129
|
transaction.inputs = transaction.inputs.map((input) => {
|
2139
2130
|
const inputClone = clone2(input);
|
2140
2131
|
switch (inputClone.type) {
|
2141
|
-
case
|
2132
|
+
case InputType4.Coin: {
|
2142
2133
|
inputClone.txPointer = {
|
2143
2134
|
blockHeight: 0,
|
2144
2135
|
txIndex: 0
|
@@ -2146,11 +2137,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2146
2137
|
inputClone.predicateGasUsed = bn8(0);
|
2147
2138
|
return inputClone;
|
2148
2139
|
}
|
2149
|
-
case
|
2140
|
+
case InputType4.Message: {
|
2150
2141
|
inputClone.predicateGasUsed = bn8(0);
|
2151
2142
|
return inputClone;
|
2152
2143
|
}
|
2153
|
-
case
|
2144
|
+
case InputType4.Contract: {
|
2154
2145
|
inputClone.txPointer = {
|
2155
2146
|
blockHeight: 0,
|
2156
2147
|
txIndex: 0
|
@@ -2316,7 +2307,7 @@ import { Interface } from "@fuel-ts/abi-coder";
|
|
2316
2307
|
import { addressify as addressify2 } from "@fuel-ts/address";
|
2317
2308
|
import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
2318
2309
|
import { bn as bn10 } from "@fuel-ts/math";
|
2319
|
-
import { InputType as
|
2310
|
+
import { InputType as InputType5, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2320
2311
|
import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
|
2321
2312
|
|
2322
2313
|
// src/providers/transaction-request/scripts.ts
|
@@ -2400,7 +2391,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2400
2391
|
*/
|
2401
2392
|
getContractInputs() {
|
2402
2393
|
return this.inputs.filter(
|
2403
|
-
(input) => input.type ===
|
2394
|
+
(input) => input.type === InputType5.Contract
|
2404
2395
|
);
|
2405
2396
|
}
|
2406
2397
|
/**
|
@@ -2476,7 +2467,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2476
2467
|
return this;
|
2477
2468
|
}
|
2478
2469
|
const inputIndex = super.pushInput({
|
2479
|
-
type:
|
2470
|
+
type: InputType5.Contract,
|
2480
2471
|
contractId: contractAddress.toB256(),
|
2481
2472
|
txPointer: "0x00000000000000000000000000000000"
|
2482
2473
|
});
|
@@ -2671,7 +2662,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2671
2662
|
|
2672
2663
|
// src/providers/transaction-summary/input.ts
|
2673
2664
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2674
|
-
import { InputType as
|
2665
|
+
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
2675
2666
|
function getInputsByTypes(inputs, types) {
|
2676
2667
|
return inputs.filter((i) => types.includes(i.type));
|
2677
2668
|
}
|
@@ -2679,16 +2670,16 @@ function getInputsByType(inputs, type) {
|
|
2679
2670
|
return inputs.filter((i) => i.type === type);
|
2680
2671
|
}
|
2681
2672
|
function getInputsCoin(inputs) {
|
2682
|
-
return getInputsByType(inputs,
|
2673
|
+
return getInputsByType(inputs, InputType6.Coin);
|
2683
2674
|
}
|
2684
2675
|
function getInputsMessage(inputs) {
|
2685
|
-
return getInputsByType(inputs,
|
2676
|
+
return getInputsByType(inputs, InputType6.Message);
|
2686
2677
|
}
|
2687
2678
|
function getInputsCoinAndMessage(inputs) {
|
2688
|
-
return getInputsByTypes(inputs, [
|
2679
|
+
return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
|
2689
2680
|
}
|
2690
2681
|
function getInputsContract(inputs) {
|
2691
|
-
return getInputsByType(inputs,
|
2682
|
+
return getInputsByType(inputs, InputType6.Contract);
|
2692
2683
|
}
|
2693
2684
|
function getInputFromAssetId(inputs, assetId) {
|
2694
2685
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2707,7 +2698,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2707
2698
|
if (!contractInput) {
|
2708
2699
|
return void 0;
|
2709
2700
|
}
|
2710
|
-
if (contractInput.type !==
|
2701
|
+
if (contractInput.type !== InputType6.Contract) {
|
2711
2702
|
throw new FuelError9(
|
2712
2703
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2713
2704
|
`Contract input should be of type 'contract'.`
|
@@ -2716,10 +2707,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2716
2707
|
return contractInput;
|
2717
2708
|
}
|
2718
2709
|
function getInputAccountAddress(input) {
|
2719
|
-
if (input.type ===
|
2710
|
+
if (input.type === InputType6.Coin) {
|
2720
2711
|
return input.owner.toString();
|
2721
2712
|
}
|
2722
|
-
if (input.type ===
|
2713
|
+
if (input.type === InputType6.Message) {
|
2723
2714
|
return input.recipient.toString();
|
2724
2715
|
}
|
2725
2716
|
return "";
|
@@ -4416,7 +4407,7 @@ cacheInputs_fn = function(inputs) {
|
|
4416
4407
|
return;
|
4417
4408
|
}
|
4418
4409
|
inputs.forEach((input) => {
|
4419
|
-
if (input.type ===
|
4410
|
+
if (input.type === InputType7.Coin) {
|
4420
4411
|
this.cache?.set(input.id);
|
4421
4412
|
}
|
4422
4413
|
});
|
@@ -7986,10 +7977,11 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
7986
7977
|
|
7987
7978
|
// src/test-utils/seedTestWallet.ts
|
7988
7979
|
import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
|
7989
|
-
var seedTestWallet = async (wallet, quantities) => {
|
7980
|
+
var seedTestWallet = async (wallet, quantities, utxosAmount = 1) => {
|
7981
|
+
const toFundAccounts = Array.isArray(wallet) ? wallet : [wallet];
|
7990
7982
|
const genesisWallet = new WalletUnlocked(
|
7991
7983
|
process.env.GENESIS_SECRET || randomBytes5(32),
|
7992
|
-
|
7984
|
+
toFundAccounts[0].provider
|
7993
7985
|
);
|
7994
7986
|
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
7995
7987
|
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
@@ -7998,7 +7990,13 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
7998
7990
|
gasPrice: minGasPrice
|
7999
7991
|
});
|
8000
7992
|
request.addResources(resources);
|
8001
|
-
quantities.map(coinQuantityfy).forEach(
|
7993
|
+
quantities.map(coinQuantityfy).forEach(
|
7994
|
+
({ amount, assetId }) => toFundAccounts.forEach(({ address }) => {
|
7995
|
+
for (let i = 0; i < utxosAmount; i++) {
|
7996
|
+
request.addCoinOutput(address, amount.div(utxosAmount), assetId);
|
7997
|
+
}
|
7998
|
+
})
|
7999
|
+
);
|
8002
8000
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8003
8001
|
};
|
8004
8002
|
|
@@ -8197,7 +8195,44 @@ var launchNodeAndGetWallets = async ({
|
|
8197
8195
|
};
|
8198
8196
|
return { wallets, stop: cleanup, provider };
|
8199
8197
|
};
|
8198
|
+
|
8199
|
+
// src/test-utils/transactionRequest.ts
|
8200
|
+
import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
|
8201
|
+
import { getRandomB256 } from "@fuel-ts/address";
|
8202
|
+
import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
|
8203
|
+
import { randomBytes as randomBytes6 } from "@fuel-ts/crypto";
|
8204
|
+
import { bn as bn19 } from "@fuel-ts/math";
|
8205
|
+
import { InputType as InputType8 } from "@fuel-ts/transactions";
|
8206
|
+
import { hexlify as hexlify19 } from "@fuel-ts/utils";
|
8207
|
+
var generateFakeRequestInputCoin = (partial = {}) => ({
|
8208
|
+
id: hexlify19(randomBytes6(UTXO_ID_LEN3)),
|
8209
|
+
type: InputType8.Coin,
|
8210
|
+
owner: getRandomB256(),
|
8211
|
+
amount: bn19(100),
|
8212
|
+
assetId: ZeroBytes329,
|
8213
|
+
txPointer: "0x00000000000000000000000000000000",
|
8214
|
+
witnessIndex: 0,
|
8215
|
+
...partial
|
8216
|
+
});
|
8217
|
+
var generateFakeRequestInputMessage = (partial = {}) => ({
|
8218
|
+
nonce: getRandomB256(),
|
8219
|
+
type: InputType8.Message,
|
8220
|
+
sender: getRandomB256(),
|
8221
|
+
recipient: getRandomB256(),
|
8222
|
+
amount: bn19(100),
|
8223
|
+
witnessIndex: 0,
|
8224
|
+
...partial
|
8225
|
+
});
|
8226
|
+
var generateFakeRequestInputContract = (partial = {}) => ({
|
8227
|
+
contractId: getRandomB256(),
|
8228
|
+
type: InputType8.Contract,
|
8229
|
+
txPointer: "0x00000000000000000000000000000000",
|
8230
|
+
...partial
|
8231
|
+
});
|
8200
8232
|
export {
|
8233
|
+
generateFakeRequestInputCoin,
|
8234
|
+
generateFakeRequestInputContract,
|
8235
|
+
generateFakeRequestInputMessage,
|
8201
8236
|
generateTestWallet,
|
8202
8237
|
killNode,
|
8203
8238
|
launchNode,
|