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