@fuel-ts/account 0.0.0-rc-2143-20240429105111 → 0.0.0-rc-2037-20240429115810
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 +69 -8
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +192 -118
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +107 -39
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +9 -2
- package/dist/predicate/predicate.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 +2 -0
- 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/launchNode.d.ts +2 -4
- package/dist/test-utils/launchNode.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 +63 -14
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +180 -117
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +104 -44
- 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/index.mjs
CHANGED
@@ -75,7 +75,7 @@ import { Address as Address2 } from "@fuel-ts/address";
|
|
75
75
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
76
76
|
import { BN, bn as bn16 } from "@fuel-ts/math";
|
77
77
|
import {
|
78
|
-
InputType as
|
78
|
+
InputType as InputType8,
|
79
79
|
TransactionType as TransactionType8,
|
80
80
|
InputMessageCoder,
|
81
81
|
TransactionCoder as TransactionCoder5
|
@@ -1240,7 +1240,7 @@ import { bn as bn7 } from "@fuel-ts/math";
|
|
1240
1240
|
import {
|
1241
1241
|
PolicyType,
|
1242
1242
|
TransactionCoder,
|
1243
|
-
InputType as
|
1243
|
+
InputType as InputType3,
|
1244
1244
|
OutputType as OutputType2,
|
1245
1245
|
TransactionType
|
1246
1246
|
} from "@fuel-ts/transactions";
|
@@ -1764,6 +1764,28 @@ var NoWitnessByOwnerError = class extends Error {
|
|
1764
1764
|
name = "NoWitnessByOwnerError";
|
1765
1765
|
};
|
1766
1766
|
|
1767
|
+
// src/providers/transaction-request/helpers.ts
|
1768
|
+
import { InputType as InputType2 } from "@fuel-ts/transactions";
|
1769
|
+
var isRequestInputCoin = (input) => input.type === InputType2.Coin;
|
1770
|
+
var isRequestInputMessage = (input) => input.type === InputType2.Message;
|
1771
|
+
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
1772
|
+
var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
|
1773
|
+
var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
|
1774
|
+
var cacheResources = (resources) => resources.reduce(
|
1775
|
+
(cache2, resource) => {
|
1776
|
+
if (isCoin(resource)) {
|
1777
|
+
cache2.utxos.push(resource.id);
|
1778
|
+
} else {
|
1779
|
+
cache2.messages.push(resource.nonce);
|
1780
|
+
}
|
1781
|
+
return cache2;
|
1782
|
+
},
|
1783
|
+
{
|
1784
|
+
utxos: [],
|
1785
|
+
messages: []
|
1786
|
+
}
|
1787
|
+
);
|
1788
|
+
|
1767
1789
|
// src/providers/transaction-request/witness.ts
|
1768
1790
|
import { arrayify as arrayify4, hexlify as hexlify6 } from "@fuel-ts/utils";
|
1769
1791
|
var witnessify = (value) => {
|
@@ -1954,7 +1976,7 @@ var BaseTransactionRequest = class {
|
|
1954
1976
|
*/
|
1955
1977
|
getCoinInputs() {
|
1956
1978
|
return this.inputs.filter(
|
1957
|
-
(input) => input.type ===
|
1979
|
+
(input) => input.type === InputType3.Coin
|
1958
1980
|
);
|
1959
1981
|
}
|
1960
1982
|
/**
|
@@ -1986,9 +2008,9 @@ var BaseTransactionRequest = class {
|
|
1986
2008
|
const ownerAddress = addressify(owner);
|
1987
2009
|
const found = this.inputs.find((input) => {
|
1988
2010
|
switch (input.type) {
|
1989
|
-
case
|
2011
|
+
case InputType3.Coin:
|
1990
2012
|
return hexlify7(input.owner) === ownerAddress.toB256();
|
1991
|
-
case
|
2013
|
+
case InputType3.Message:
|
1992
2014
|
return hexlify7(input.recipient) === ownerAddress.toB256();
|
1993
2015
|
default:
|
1994
2016
|
return false;
|
@@ -2003,7 +2025,7 @@ var BaseTransactionRequest = class {
|
|
2003
2025
|
* @param coin - Coin resource.
|
2004
2026
|
*/
|
2005
2027
|
addCoinInput(coin) {
|
2006
|
-
const { assetId, owner, amount } = coin;
|
2028
|
+
const { assetId, owner, amount, id, predicate } = coin;
|
2007
2029
|
let witnessIndex;
|
2008
2030
|
if (coin.predicate) {
|
2009
2031
|
witnessIndex = 0;
|
@@ -2014,13 +2036,14 @@ var BaseTransactionRequest = class {
|
|
2014
2036
|
}
|
2015
2037
|
}
|
2016
2038
|
const input = {
|
2017
|
-
|
2018
|
-
type:
|
2039
|
+
id,
|
2040
|
+
type: InputType3.Coin,
|
2019
2041
|
owner: owner.toB256(),
|
2020
2042
|
amount,
|
2021
2043
|
assetId,
|
2022
2044
|
txPointer: "0x00000000000000000000000000000000",
|
2023
|
-
witnessIndex
|
2045
|
+
witnessIndex,
|
2046
|
+
predicate
|
2024
2047
|
};
|
2025
2048
|
this.pushInput(input);
|
2026
2049
|
this.addChangeOutput(owner, assetId);
|
@@ -2032,7 +2055,7 @@ var BaseTransactionRequest = class {
|
|
2032
2055
|
* @param message - Message resource.
|
2033
2056
|
*/
|
2034
2057
|
addMessageInput(message) {
|
2035
|
-
const { recipient, sender, amount, assetId } = message;
|
2058
|
+
const { recipient, sender, amount, predicate, nonce, assetId } = message;
|
2036
2059
|
let witnessIndex;
|
2037
2060
|
if (message.predicate) {
|
2038
2061
|
witnessIndex = 0;
|
@@ -2043,12 +2066,13 @@ var BaseTransactionRequest = class {
|
|
2043
2066
|
}
|
2044
2067
|
}
|
2045
2068
|
const input = {
|
2046
|
-
|
2047
|
-
type:
|
2069
|
+
nonce,
|
2070
|
+
type: InputType3.Message,
|
2048
2071
|
sender: sender.toB256(),
|
2049
2072
|
recipient: recipient.toB256(),
|
2050
2073
|
amount,
|
2051
|
-
witnessIndex
|
2074
|
+
witnessIndex,
|
2075
|
+
predicate
|
2052
2076
|
};
|
2053
2077
|
this.pushInput(input);
|
2054
2078
|
this.addChangeOutput(recipient, assetId);
|
@@ -2232,16 +2256,27 @@ var BaseTransactionRequest = class {
|
|
2232
2256
|
toJSON() {
|
2233
2257
|
return normalizeJSON(this);
|
2234
2258
|
}
|
2259
|
+
removeWitness(index) {
|
2260
|
+
this.witnesses.splice(index, 1);
|
2261
|
+
this.adjustWitnessIndexes(index);
|
2262
|
+
}
|
2263
|
+
adjustWitnessIndexes(removedIndex) {
|
2264
|
+
this.inputs.filter(isRequestInputResource).forEach((input) => {
|
2265
|
+
if (input.witnessIndex > removedIndex) {
|
2266
|
+
input.witnessIndex -= 1;
|
2267
|
+
}
|
2268
|
+
});
|
2269
|
+
}
|
2235
2270
|
updatePredicateGasUsed(inputs) {
|
2236
2271
|
this.inputs.forEach((i) => {
|
2237
2272
|
let correspondingInput;
|
2238
2273
|
switch (i.type) {
|
2239
|
-
case
|
2240
|
-
correspondingInput = inputs.find((x) => x.type ===
|
2274
|
+
case InputType3.Coin:
|
2275
|
+
correspondingInput = inputs.find((x) => x.type === InputType3.Coin && x.owner === i.owner);
|
2241
2276
|
break;
|
2242
|
-
case
|
2277
|
+
case InputType3.Message:
|
2243
2278
|
correspondingInput = inputs.find(
|
2244
|
-
(x) => x.type ===
|
2279
|
+
(x) => x.type === InputType3.Message && x.sender === i.sender
|
2245
2280
|
);
|
2246
2281
|
break;
|
2247
2282
|
default:
|
@@ -2275,7 +2310,7 @@ import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
|
2275
2310
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2276
2311
|
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2277
2312
|
import { bn as bn8 } from "@fuel-ts/math";
|
2278
|
-
import { TransactionType as TransactionType2, InputType as
|
2313
|
+
import { TransactionType as TransactionType2, InputType as InputType4, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2279
2314
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2280
2315
|
import { clone as clone2 } from "ramda";
|
2281
2316
|
function hashTransaction(transactionRequest, chainId) {
|
@@ -2286,7 +2321,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2286
2321
|
transaction.inputs = transaction.inputs.map((input) => {
|
2287
2322
|
const inputClone = clone2(input);
|
2288
2323
|
switch (inputClone.type) {
|
2289
|
-
case
|
2324
|
+
case InputType4.Coin: {
|
2290
2325
|
inputClone.txPointer = {
|
2291
2326
|
blockHeight: 0,
|
2292
2327
|
txIndex: 0
|
@@ -2294,11 +2329,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2294
2329
|
inputClone.predicateGasUsed = bn8(0);
|
2295
2330
|
return inputClone;
|
2296
2331
|
}
|
2297
|
-
case
|
2332
|
+
case InputType4.Message: {
|
2298
2333
|
inputClone.predicateGasUsed = bn8(0);
|
2299
2334
|
return inputClone;
|
2300
2335
|
}
|
2301
|
-
case
|
2336
|
+
case InputType4.Contract: {
|
2302
2337
|
inputClone.txPointer = {
|
2303
2338
|
blockHeight: 0,
|
2304
2339
|
txIndex: 0
|
@@ -2458,7 +2493,7 @@ import { Interface } from "@fuel-ts/abi-coder";
|
|
2458
2493
|
import { addressify as addressify2 } from "@fuel-ts/address";
|
2459
2494
|
import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
2460
2495
|
import { bn as bn10 } from "@fuel-ts/math";
|
2461
|
-
import { InputType as
|
2496
|
+
import { InputType as InputType5, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2462
2497
|
import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
|
2463
2498
|
|
2464
2499
|
// src/providers/transaction-request/scripts.ts
|
@@ -2542,7 +2577,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2542
2577
|
*/
|
2543
2578
|
getContractInputs() {
|
2544
2579
|
return this.inputs.filter(
|
2545
|
-
(input) => input.type ===
|
2580
|
+
(input) => input.type === InputType5.Contract
|
2546
2581
|
);
|
2547
2582
|
}
|
2548
2583
|
/**
|
@@ -2619,7 +2654,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2619
2654
|
return this;
|
2620
2655
|
}
|
2621
2656
|
const inputIndex = super.pushInput({
|
2622
|
-
type:
|
2657
|
+
type: InputType5.Contract,
|
2623
2658
|
contractId: contractAddress.toB256(),
|
2624
2659
|
txPointer: "0x00000000000000000000000000000000"
|
2625
2660
|
});
|
@@ -2661,7 +2696,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2661
2696
|
|
2662
2697
|
// src/providers/transaction-request/utils.ts
|
2663
2698
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2664
|
-
import { TransactionType as TransactionType5, InputType as
|
2699
|
+
import { TransactionType as TransactionType5, InputType as InputType6 } from "@fuel-ts/transactions";
|
2665
2700
|
var transactionRequestify = (obj) => {
|
2666
2701
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2667
2702
|
return obj;
|
@@ -2681,10 +2716,10 @@ var transactionRequestify = (obj) => {
|
|
2681
2716
|
};
|
2682
2717
|
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2683
2718
|
(acc, input) => {
|
2684
|
-
if (input.type ===
|
2719
|
+
if (input.type === InputType6.Coin && input.owner === owner) {
|
2685
2720
|
acc.utxos.push(input.id);
|
2686
2721
|
}
|
2687
|
-
if (input.type ===
|
2722
|
+
if (input.type === InputType6.Message && input.recipient === owner) {
|
2688
2723
|
acc.messages.push(input.nonce);
|
2689
2724
|
}
|
2690
2725
|
return acc;
|
@@ -2838,7 +2873,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2838
2873
|
|
2839
2874
|
// src/providers/transaction-summary/input.ts
|
2840
2875
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2841
|
-
import { InputType as
|
2876
|
+
import { InputType as InputType7 } from "@fuel-ts/transactions";
|
2842
2877
|
function getInputsByTypes(inputs, types) {
|
2843
2878
|
return inputs.filter((i) => types.includes(i.type));
|
2844
2879
|
}
|
@@ -2846,16 +2881,16 @@ function getInputsByType(inputs, type) {
|
|
2846
2881
|
return inputs.filter((i) => i.type === type);
|
2847
2882
|
}
|
2848
2883
|
function getInputsCoin(inputs) {
|
2849
|
-
return getInputsByType(inputs,
|
2884
|
+
return getInputsByType(inputs, InputType7.Coin);
|
2850
2885
|
}
|
2851
2886
|
function getInputsMessage(inputs) {
|
2852
|
-
return getInputsByType(inputs,
|
2887
|
+
return getInputsByType(inputs, InputType7.Message);
|
2853
2888
|
}
|
2854
2889
|
function getInputsCoinAndMessage(inputs) {
|
2855
|
-
return getInputsByTypes(inputs, [
|
2890
|
+
return getInputsByTypes(inputs, [InputType7.Coin, InputType7.Message]);
|
2856
2891
|
}
|
2857
2892
|
function getInputsContract(inputs) {
|
2858
|
-
return getInputsByType(inputs,
|
2893
|
+
return getInputsByType(inputs, InputType7.Contract);
|
2859
2894
|
}
|
2860
2895
|
function getInputFromAssetId(inputs, assetId) {
|
2861
2896
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2874,7 +2909,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2874
2909
|
if (!contractInput) {
|
2875
2910
|
return void 0;
|
2876
2911
|
}
|
2877
|
-
if (contractInput.type !==
|
2912
|
+
if (contractInput.type !== InputType7.Contract) {
|
2878
2913
|
throw new FuelError9(
|
2879
2914
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2880
2915
|
`Contract input should be of type 'contract'.`
|
@@ -2883,10 +2918,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2883
2918
|
return contractInput;
|
2884
2919
|
}
|
2885
2920
|
function getInputAccountAddress(input) {
|
2886
|
-
if (input.type ===
|
2921
|
+
if (input.type === InputType7.Coin) {
|
2887
2922
|
return input.owner.toString();
|
2888
2923
|
}
|
2889
|
-
if (input.type ===
|
2924
|
+
if (input.type === InputType7.Message) {
|
2890
2925
|
return input.recipient.toString();
|
2891
2926
|
}
|
2892
2927
|
return "";
|
@@ -4770,7 +4805,7 @@ cacheInputs_fn = function(inputs) {
|
|
4770
4805
|
return;
|
4771
4806
|
}
|
4772
4807
|
inputs.forEach((input) => {
|
4773
|
-
if (input.type ===
|
4808
|
+
if (input.type === InputType8.Coin) {
|
4774
4809
|
this.cache?.set(input.id);
|
4775
4810
|
}
|
4776
4811
|
});
|
@@ -8952,7 +8987,7 @@ import {
|
|
8952
8987
|
} from "@fuel-ts/abi-coder";
|
8953
8988
|
import { Address as Address9 } from "@fuel-ts/address";
|
8954
8989
|
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8955
|
-
import { ByteArrayCoder
|
8990
|
+
import { ByteArrayCoder } from "@fuel-ts/transactions";
|
8956
8991
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
8957
8992
|
|
8958
8993
|
// src/predicate/utils/getPredicateRoot.ts
|
@@ -9011,10 +9046,15 @@ var Predicate = class extends Account {
|
|
9011
9046
|
populateTransactionPredicateData(transactionRequestLike) {
|
9012
9047
|
const request = transactionRequestify(transactionRequestLike);
|
9013
9048
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
9014
|
-
|
9015
|
-
|
9049
|
+
const placeholderIndex = this.getIndexFromPlaceholderWitness(request);
|
9050
|
+
if (placeholderIndex !== -1) {
|
9051
|
+
request.removeWitness(placeholderIndex);
|
9052
|
+
}
|
9053
|
+
request.inputs.filter(isRequestInputResource).forEach((input) => {
|
9054
|
+
if (isRequestInputResourceFromOwner(input, this.address)) {
|
9016
9055
|
input.predicate = hexlify19(this.bytes);
|
9017
9056
|
input.predicateData = hexlify19(this.getPredicateData(policies.length));
|
9057
|
+
input.witnessIndex = 0;
|
9018
9058
|
}
|
9019
9059
|
});
|
9020
9060
|
return request;
|
@@ -9137,6 +9177,28 @@ var Predicate = class extends Account {
|
|
9137
9177
|
}
|
9138
9178
|
return mutatedBytes;
|
9139
9179
|
}
|
9180
|
+
/**
|
9181
|
+
* Returns the index of the witness placeholder that was added to this predicate.
|
9182
|
+
* If no witness placeholder was added, it returns -1.
|
9183
|
+
* @param request - The transaction request.
|
9184
|
+
* @returns The index of the witness placeholder, or -1 if there is no witness placeholder.
|
9185
|
+
*/
|
9186
|
+
getIndexFromPlaceholderWitness(request) {
|
9187
|
+
const predicateInputs = request.inputs.filter(isRequestInputResource).filter((input) => isRequestInputResourceFromOwner(input, this.address));
|
9188
|
+
let index = -1;
|
9189
|
+
const hasEmptyPredicateInputs = predicateInputs.find((input) => !input.predicate);
|
9190
|
+
if (hasEmptyPredicateInputs) {
|
9191
|
+
index = hasEmptyPredicateInputs.witnessIndex;
|
9192
|
+
const allInputsAreEmpty = predicateInputs.every((input) => !input.predicate);
|
9193
|
+
if (!allInputsAreEmpty) {
|
9194
|
+
const wasFilledInputAddedFirst = !!predicateInputs[0]?.predicate;
|
9195
|
+
if (wasFilledInputAddedFirst) {
|
9196
|
+
index = -1;
|
9197
|
+
}
|
9198
|
+
}
|
9199
|
+
}
|
9200
|
+
return index;
|
9201
|
+
}
|
9140
9202
|
};
|
9141
9203
|
|
9142
9204
|
// src/connectors/fuel.ts
|
@@ -9859,6 +9921,7 @@ export {
|
|
9859
9921
|
assets,
|
9860
9922
|
buildBlockExplorerUrl,
|
9861
9923
|
cacheFor,
|
9924
|
+
cacheResources,
|
9862
9925
|
cacheTxInputsFromOwner,
|
9863
9926
|
calculateGasFee,
|
9864
9927
|
calculateMetadataGasForTxCreate,
|
@@ -9906,6 +9969,7 @@ export {
|
|
9906
9969
|
getReceiptsMessageOut,
|
9907
9970
|
getReceiptsTransferOut,
|
9908
9971
|
getReceiptsWithMissingData,
|
9972
|
+
getRequestInputResourceOwner,
|
9909
9973
|
getTransactionStatusName,
|
9910
9974
|
getTransactionSummary,
|
9911
9975
|
getTransactionSummaryFromRequest,
|
@@ -9919,6 +9983,10 @@ export {
|
|
9919
9983
|
isMessage,
|
9920
9984
|
isRawCoin,
|
9921
9985
|
isRawMessage,
|
9986
|
+
isRequestInputCoin,
|
9987
|
+
isRequestInputMessage,
|
9988
|
+
isRequestInputResource,
|
9989
|
+
isRequestInputResourceFromOwner,
|
9922
9990
|
isType,
|
9923
9991
|
isTypeCreate,
|
9924
9992
|
isTypeMint,
|