@fuel-ts/account 0.101.0 → 0.101.2
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.
- package/dist/account.d.ts +3 -1
- package/dist/account.d.ts.map +1 -1
- package/dist/connectors/fuel-connector.d.ts +3 -3
- package/dist/connectors/fuel-connector.d.ts.map +1 -1
- package/dist/connectors/types/connector-types.d.ts +1 -0
- package/dist/connectors/types/connector-types.d.ts.map +1 -1
- package/dist/index.global.js +223 -82
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +379 -243
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +312 -176
- package/dist/index.mjs.map +1 -1
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/call.d.ts +4 -7
- package/dist/providers/transaction-summary/call.d.ts.map +1 -1
- package/dist/providers/transaction-summary/operations.d.ts +1 -1
- package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
- package/dist/providers/utils/extract-tx-error.d.ts +10 -1
- package/dist/providers/utils/extract-tx-error.d.ts.map +1 -1
- package/dist/test-utils.global.js +221 -81
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +337 -204
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +273 -139
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +15 -15
package/dist/index.js
CHANGED
@@ -88,6 +88,7 @@ __export(src_exports, {
|
|
88
88
|
assemblePreConfirmationTransactionSummary: () => assemblePreConfirmationTransactionSummary,
|
89
89
|
assembleReceiptByType: () => assembleReceiptByType,
|
90
90
|
assembleRevertError: () => assembleRevertError,
|
91
|
+
assembleSignalErrorMessage: () => assembleSignalErrorMessage,
|
91
92
|
assembleTransactionSummary: () => assembleTransactionSummary,
|
92
93
|
assembleTransactionSummaryFromJson: () => assembleTransactionSummaryFromJson,
|
93
94
|
assets: () => assets,
|
@@ -927,13 +928,13 @@ var getAssetsByOwner = /* @__PURE__ */ __name(async (opts) => {
|
|
927
928
|
}, "getAssetsByOwner");
|
928
929
|
|
929
930
|
// src/account.ts
|
930
|
-
var
|
931
|
+
var import_abi_coder9 = require("@fuel-ts/abi-coder");
|
931
932
|
var import_address5 = require("@fuel-ts/address");
|
932
933
|
var import_crypto2 = require("@fuel-ts/crypto");
|
933
934
|
var import_errors22 = require("@fuel-ts/errors");
|
934
935
|
var import_math22 = require("@fuel-ts/math");
|
935
936
|
var import_transactions28 = require("@fuel-ts/transactions");
|
936
|
-
var
|
937
|
+
var import_utils37 = require("@fuel-ts/utils");
|
937
938
|
var import_ramda9 = require("ramda");
|
938
939
|
|
939
940
|
// src/providers/coin-quantity.ts
|
@@ -975,7 +976,7 @@ var import_address3 = require("@fuel-ts/address");
|
|
975
976
|
var import_errors20 = require("@fuel-ts/errors");
|
976
977
|
var import_math19 = require("@fuel-ts/math");
|
977
978
|
var import_transactions25 = require("@fuel-ts/transactions");
|
978
|
-
var
|
979
|
+
var import_utils32 = require("@fuel-ts/utils");
|
979
980
|
var import_versions = require("@fuel-ts/versions");
|
980
981
|
var import_graphql_request = require("graphql-request");
|
981
982
|
var import_graphql_tag2 = __toESM(require("graphql-tag"));
|
@@ -3482,58 +3483,97 @@ ${import_configs5.PANIC_DOC_URL}#variant.${statusReason}`;
|
|
3482
3483
|
});
|
3483
3484
|
}, "assemblePanicError");
|
3484
3485
|
var stringify = /* @__PURE__ */ __name((obj) => JSON.stringify(obj, null, 2), "stringify");
|
3485
|
-
var
|
3486
|
+
var assembleSignalErrorMessage = /* @__PURE__ */ __name((reasonHex, logs, metadata) => {
|
3486
3487
|
let errorMessage = "The transaction reverted with an unknown reason.";
|
3487
|
-
const revertReceipt = receipts.find(({ type }) => type === import_transactions7.ReceiptType.Revert);
|
3488
3488
|
let reason = "";
|
3489
|
-
|
3490
|
-
|
3491
|
-
|
3492
|
-
|
3493
|
-
|
3494
|
-
|
3495
|
-
|
3496
|
-
|
3497
|
-
|
3498
|
-
}
|
3499
|
-
|
3500
|
-
|
3501
|
-
|
3502
|
-
errorMessage = `The transaction reverted because of an "assert_eq" statement${suffix}`;
|
3503
|
-
break;
|
3504
|
-
}
|
3505
|
-
case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
|
3506
|
-
const suffix = logs.length >= 2 ? ` comparing ${stringify(lastButOneLog)} and ${stringify(lastLog)}.` : ".";
|
3507
|
-
reason = "assert_ne";
|
3508
|
-
errorMessage = `The transaction reverted because of an "assert_ne" statement${suffix}`;
|
3509
|
-
break;
|
3510
|
-
}
|
3511
|
-
case import_configs5.FAILED_ASSERT_SIGNAL:
|
3512
|
-
reason = "assert";
|
3513
|
-
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
3514
|
-
break;
|
3515
|
-
case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
3516
|
-
reason = "MissingOutputVariable";
|
3517
|
-
errorMessage = `The transaction reverted because it's missing an "OutputVariable".`;
|
3518
|
-
break;
|
3519
|
-
default:
|
3520
|
-
throw new import_errors8.FuelError(
|
3521
|
-
import_errors8.ErrorCode.UNKNOWN,
|
3522
|
-
`The transaction reverted with an unknown reason: ${revertReceipt.val}`,
|
3523
|
-
{
|
3524
|
-
...metadata,
|
3525
|
-
reason: "unknown"
|
3526
|
-
}
|
3527
|
-
);
|
3489
|
+
const lastLog = logs[logs.length - 1];
|
3490
|
+
const lastButOneLog = logs[logs.length - 2];
|
3491
|
+
switch (reasonHex) {
|
3492
|
+
case import_configs5.FAILED_REQUIRE_SIGNAL: {
|
3493
|
+
reason = "require";
|
3494
|
+
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(lastLog) : "an error."}.`;
|
3495
|
+
break;
|
3496
|
+
}
|
3497
|
+
case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
|
3498
|
+
const suffix = logs.length >= 2 ? ` comparing ${stringify(lastLog)} and ${stringify(lastButOneLog)}.` : ".";
|
3499
|
+
reason = "assert_eq";
|
3500
|
+
errorMessage = `The transaction reverted because of an "assert_eq" statement${suffix}`;
|
3501
|
+
break;
|
3528
3502
|
}
|
3503
|
+
case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
|
3504
|
+
const suffix = logs.length >= 2 ? ` comparing ${stringify(lastButOneLog)} and ${stringify(lastLog)}.` : ".";
|
3505
|
+
reason = "assert_ne";
|
3506
|
+
errorMessage = `The transaction reverted because of an "assert_ne" statement${suffix}`;
|
3507
|
+
break;
|
3508
|
+
}
|
3509
|
+
case import_configs5.FAILED_ASSERT_SIGNAL:
|
3510
|
+
reason = "assert";
|
3511
|
+
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
3512
|
+
break;
|
3513
|
+
case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
3514
|
+
reason = "MissingOutputVariable";
|
3515
|
+
errorMessage = `The transaction reverted because it's missing an "OutputVariable".`;
|
3516
|
+
break;
|
3517
|
+
default:
|
3518
|
+
reason = `revert_with_log`;
|
3519
|
+
errorMessage = `The transaction reverted because a "revert_with_log" statement has thrown ${logs.length ? stringify(lastLog) : "an error."}.`;
|
3520
|
+
break;
|
3529
3521
|
}
|
3530
3522
|
return new import_errors8.FuelError(import_errors8.ErrorCode.SCRIPT_REVERTED, errorMessage, {
|
3531
3523
|
...metadata,
|
3532
3524
|
reason
|
3533
3525
|
});
|
3526
|
+
}, "assembleSignalErrorMessage");
|
3527
|
+
function buildAbiErrorMessage(abiError, logs, metadata, reason) {
|
3528
|
+
const { pos, msg } = abiError;
|
3529
|
+
let errorMessage = "";
|
3530
|
+
const positionMessage = pos ? `
|
3531
|
+
|
3532
|
+
This error originated at ${JSON.stringify(pos, null, 2)}` : "";
|
3533
|
+
if (msg) {
|
3534
|
+
errorMessage = `A sway "panic" expression was invoked with the message: "${msg}".${positionMessage}`;
|
3535
|
+
} else {
|
3536
|
+
const value = logs[logs.length - 1];
|
3537
|
+
errorMessage = `A sway "panic" expression was invoked with the value: ${JSON.stringify(value)}.${positionMessage}`;
|
3538
|
+
}
|
3539
|
+
return new import_errors8.FuelError(import_errors8.ErrorCode.SCRIPT_REVERTED, errorMessage, {
|
3540
|
+
...metadata,
|
3541
|
+
reason
|
3542
|
+
});
|
3543
|
+
}
|
3544
|
+
__name(buildAbiErrorMessage, "buildAbiErrorMessage");
|
3545
|
+
function findErrorInAbis(statusReason, abis = []) {
|
3546
|
+
for (const abi of abis) {
|
3547
|
+
if (abi.errorCodes?.[statusReason]) {
|
3548
|
+
return abi.errorCodes[statusReason];
|
3549
|
+
}
|
3550
|
+
}
|
3551
|
+
return void 0;
|
3552
|
+
}
|
3553
|
+
__name(findErrorInAbis, "findErrorInAbis");
|
3554
|
+
var assembleRevertError = /* @__PURE__ */ __name((_receipts, logs, metadata, statusReason, abis) => {
|
3555
|
+
const match = statusReason.match(/Revert\((\d+)\)/);
|
3556
|
+
const reason = match?.[1] ?? statusReason;
|
3557
|
+
const reasonHex = (0, import_math7.bn)(reason).toHex();
|
3558
|
+
if (Object.values(import_configs5.SwaySignalErrors).includes(reasonHex)) {
|
3559
|
+
return assembleSignalErrorMessage(reasonHex, logs, metadata);
|
3560
|
+
}
|
3561
|
+
let abiError;
|
3562
|
+
if (abis) {
|
3563
|
+
const abisArr = [abis.main, ...Object.values(abis.otherContractsAbis)];
|
3564
|
+
abiError = findErrorInAbis(reason, abisArr);
|
3565
|
+
}
|
3566
|
+
if (abiError) {
|
3567
|
+
return buildAbiErrorMessage(abiError, logs, metadata, reason);
|
3568
|
+
}
|
3569
|
+
const errorMessage = `The transaction reverted with reason: ${reason}.`;
|
3570
|
+
return new import_errors8.FuelError(import_errors8.ErrorCode.SCRIPT_REVERTED, errorMessage, {
|
3571
|
+
...metadata,
|
3572
|
+
reason
|
3573
|
+
});
|
3534
3574
|
}, "assembleRevertError");
|
3535
3575
|
var extractTxError = /* @__PURE__ */ __name((params) => {
|
3536
|
-
const { receipts, statusReason, logs, groupedLogs } = params;
|
3576
|
+
const { receipts, statusReason, logs, groupedLogs, abis } = params;
|
3537
3577
|
const isPanic = receipts.some(({ type }) => type === import_transactions7.ReceiptType.Panic);
|
3538
3578
|
const isRevert = receipts.some(({ type }) => type === import_transactions7.ReceiptType.Revert);
|
3539
3579
|
const metadata = {
|
@@ -3547,7 +3587,7 @@ var extractTxError = /* @__PURE__ */ __name((params) => {
|
|
3547
3587
|
if (isPanic) {
|
3548
3588
|
return assemblePanicError(statusReason, metadata);
|
3549
3589
|
}
|
3550
|
-
return assembleRevertError(receipts, logs, metadata);
|
3590
|
+
return assembleRevertError(receipts, logs, metadata, statusReason, abis);
|
3551
3591
|
}, "extractTxError");
|
3552
3592
|
|
3553
3593
|
// src/providers/utils/merge-quantities.ts
|
@@ -5133,12 +5173,12 @@ var ResourceCache = class {
|
|
5133
5173
|
var import_errors18 = require("@fuel-ts/errors");
|
5134
5174
|
var import_math18 = require("@fuel-ts/math");
|
5135
5175
|
var import_transactions23 = require("@fuel-ts/transactions");
|
5136
|
-
var
|
5176
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5137
5177
|
|
5138
5178
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
5139
5179
|
var import_math17 = require("@fuel-ts/math");
|
5140
5180
|
var import_transactions21 = require("@fuel-ts/transactions");
|
5141
|
-
var
|
5181
|
+
var import_utils27 = require("@fuel-ts/utils");
|
5142
5182
|
|
5143
5183
|
// src/providers/transaction-summary/calculate-tx-fee-for-summary.ts
|
5144
5184
|
var import_math13 = require("@fuel-ts/math");
|
@@ -5211,6 +5251,45 @@ var import_configs11 = require("@fuel-ts/address/configs");
|
|
5211
5251
|
var import_errors16 = require("@fuel-ts/errors");
|
5212
5252
|
var import_math15 = require("@fuel-ts/math");
|
5213
5253
|
var import_transactions19 = require("@fuel-ts/transactions");
|
5254
|
+
var import_utils25 = require("@fuel-ts/utils");
|
5255
|
+
|
5256
|
+
// src/providers/transaction-summary/call.ts
|
5257
|
+
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
5258
|
+
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
5259
|
+
var getFunctionCall = /* @__PURE__ */ __name(({
|
5260
|
+
abi,
|
5261
|
+
receipt,
|
5262
|
+
offset,
|
5263
|
+
scriptData
|
5264
|
+
}) => {
|
5265
|
+
const [functionSelector, argumentsOffset] = new import_abi_coder4.StdStringCoder().decode(scriptData, offset);
|
5266
|
+
const abiInterface = new import_abi_coder5.Interface(abi);
|
5267
|
+
const functionFragment = abiInterface.getFunction(functionSelector);
|
5268
|
+
const inputs = functionFragment.jsonFn.inputs;
|
5269
|
+
let argumentsProvided;
|
5270
|
+
if (inputs.length) {
|
5271
|
+
const functionArgsBytes = scriptData.slice(argumentsOffset);
|
5272
|
+
const decodedArguments = functionFragment.decodeArguments(functionArgsBytes);
|
5273
|
+
argumentsProvided = inputs.reduce((prev, input, index) => {
|
5274
|
+
const value = decodedArguments?.[index];
|
5275
|
+
const name = input.name;
|
5276
|
+
if (name) {
|
5277
|
+
return {
|
5278
|
+
...prev,
|
5279
|
+
// reparse to remove bn
|
5280
|
+
[name]: JSON.parse(JSON.stringify(value))
|
5281
|
+
};
|
5282
|
+
}
|
5283
|
+
return prev;
|
5284
|
+
}, {});
|
5285
|
+
}
|
5286
|
+
return {
|
5287
|
+
functionSignature: functionFragment.signature,
|
5288
|
+
functionName: functionFragment.name,
|
5289
|
+
argumentsProvided,
|
5290
|
+
...receipt.amount?.isZero() ? {} : { amount: receipt.amount, assetId: receipt.assetId }
|
5291
|
+
};
|
5292
|
+
}, "getFunctionCall");
|
5214
5293
|
|
5215
5294
|
// src/providers/transaction-summary/input.ts
|
5216
5295
|
var import_errors15 = require("@fuel-ts/errors");
|
@@ -5545,12 +5624,45 @@ function getWithdrawFromFuelOperations({
|
|
5545
5624
|
return withdrawFromFuelOperations;
|
5546
5625
|
}
|
5547
5626
|
__name(getWithdrawFromFuelOperations, "getWithdrawFromFuelOperations");
|
5548
|
-
function
|
5549
|
-
|
5550
|
-
|
5551
|
-
|
5627
|
+
function findBytesSegmentIndex(whole, segment) {
|
5628
|
+
for (let i = 0; i <= whole.length - segment.length; i++) {
|
5629
|
+
let match = true;
|
5630
|
+
for (let j = 0; j < segment.length; j++) {
|
5631
|
+
if (whole[i + j] !== segment[j]) {
|
5632
|
+
match = false;
|
5633
|
+
break;
|
5634
|
+
}
|
5635
|
+
}
|
5636
|
+
if (match) {
|
5637
|
+
return i;
|
5638
|
+
}
|
5552
5639
|
}
|
5553
|
-
return
|
5640
|
+
return -1;
|
5641
|
+
}
|
5642
|
+
__name(findBytesSegmentIndex, "findBytesSegmentIndex");
|
5643
|
+
function getContractCalls(contractInput, abiMap, receipt, scriptData) {
|
5644
|
+
const calls = [];
|
5645
|
+
const abi = abiMap?.[contractInput.contractID];
|
5646
|
+
if (!abi || !scriptData) {
|
5647
|
+
return calls;
|
5648
|
+
}
|
5649
|
+
const bytesSegment = (0, import_utils25.concat)([
|
5650
|
+
(0, import_utils25.arrayify)(receipt.to),
|
5651
|
+
// Contract ID (32 bytes)
|
5652
|
+
(0, import_math15.toBytes)(receipt.param1.toHex(), 8),
|
5653
|
+
// Function selector offset (8 bytes)
|
5654
|
+
(0, import_math15.toBytes)(receipt.param2.toHex(), 8)
|
5655
|
+
// Function args offset (8 bytes)
|
5656
|
+
]);
|
5657
|
+
const segmentIndex = findBytesSegmentIndex(scriptData, bytesSegment);
|
5658
|
+
const canDecodeFunctionCall = segmentIndex !== -1;
|
5659
|
+
if (!canDecodeFunctionCall) {
|
5660
|
+
return calls;
|
5661
|
+
}
|
5662
|
+
const offset = segmentIndex + bytesSegment.length;
|
5663
|
+
const call = getFunctionCall({ abi, receipt, offset, scriptData });
|
5664
|
+
calls.push(call);
|
5665
|
+
return calls;
|
5554
5666
|
}
|
5555
5667
|
__name(getContractCalls, "getContractCalls");
|
5556
5668
|
function getAssetsSent(receipt) {
|
@@ -5562,14 +5674,14 @@ function getAssetsSent(receipt) {
|
|
5562
5674
|
];
|
5563
5675
|
}
|
5564
5676
|
__name(getAssetsSent, "getAssetsSent");
|
5565
|
-
function processCallReceipt(receipt, contractInput, inputs, abiMap,
|
5677
|
+
function processCallReceipt(receipt, contractInput, inputs, abiMap, scriptData, baseAssetId) {
|
5566
5678
|
const assetId = receipt.assetId === import_configs11.ZeroBytes32 ? baseAssetId : receipt.assetId;
|
5567
5679
|
const input = getInputFromAssetId(inputs, assetId, assetId === baseAssetId);
|
5568
5680
|
if (!input) {
|
5569
5681
|
return [];
|
5570
5682
|
}
|
5571
5683
|
const inputAddress = getInputAccountAddress(input);
|
5572
|
-
const calls = getContractCalls(contractInput, abiMap, receipt,
|
5684
|
+
const calls = getContractCalls(contractInput, abiMap, receipt, scriptData);
|
5573
5685
|
return [
|
5574
5686
|
{
|
5575
5687
|
name: "Contract call" /* contractCall */,
|
@@ -5594,7 +5706,6 @@ function getContractCallOperations({
|
|
5594
5706
|
receipts,
|
5595
5707
|
abiMap,
|
5596
5708
|
rawPayload,
|
5597
|
-
maxInputs,
|
5598
5709
|
baseAssetId
|
5599
5710
|
}) {
|
5600
5711
|
const contractCallReceipts = getReceiptsCall(receipts);
|
@@ -5604,16 +5715,15 @@ function getContractCallOperations({
|
|
5604
5715
|
if (!contractInput) {
|
5605
5716
|
return [];
|
5606
5717
|
}
|
5718
|
+
let scriptData;
|
5719
|
+
if (rawPayload) {
|
5720
|
+
const [transaction] = new import_transactions19.TransactionCoder().decode((0, import_utils25.arrayify)(rawPayload), 0);
|
5721
|
+
if (transaction.type === import_transactions19.TransactionType.Script) {
|
5722
|
+
scriptData = (0, import_utils25.arrayify)(transaction.scriptData);
|
5723
|
+
}
|
5724
|
+
}
|
5607
5725
|
return contractCallReceipts.filter((receipt) => receipt.to === contractInput.contractID).flatMap(
|
5608
|
-
(receipt) => processCallReceipt(
|
5609
|
-
receipt,
|
5610
|
-
contractInput,
|
5611
|
-
inputs,
|
5612
|
-
abiMap,
|
5613
|
-
rawPayload,
|
5614
|
-
maxInputs,
|
5615
|
-
baseAssetId
|
5616
|
-
)
|
5726
|
+
(receipt) => processCallReceipt(receipt, contractInput, inputs, abiMap, scriptData, baseAssetId)
|
5617
5727
|
);
|
5618
5728
|
});
|
5619
5729
|
}
|
@@ -5938,7 +6048,7 @@ function assembleTransactionSummary(params) {
|
|
5938
6048
|
baseAssetId
|
5939
6049
|
} = params;
|
5940
6050
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
5941
|
-
const rawPayload = (0,
|
6051
|
+
const rawPayload = (0, import_utils27.hexlify)(transactionBytes);
|
5942
6052
|
const operations = getOperations({
|
5943
6053
|
transactionType: transaction.type,
|
5944
6054
|
inputs: transaction.inputs || [],
|
@@ -5969,7 +6079,7 @@ function assembleTransactionSummary(params) {
|
|
5969
6079
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
5970
6080
|
let date;
|
5971
6081
|
if (time) {
|
5972
|
-
date =
|
6082
|
+
date = import_utils27.DateTime.fromTai64(time);
|
5973
6083
|
}
|
5974
6084
|
const transactionSummary = {
|
5975
6085
|
id,
|
@@ -6030,7 +6140,7 @@ function assemblePreConfirmationTransactionSummary(params) {
|
|
6030
6140
|
type = getTransactionTypeName(transaction.type);
|
6031
6141
|
tip = (0, import_math17.bn)(transaction.policies?.find((policy) => policy.type === import_transactions21.PolicyType.Tip)?.data);
|
6032
6142
|
if (receipts) {
|
6033
|
-
const rawPayload = (0,
|
6143
|
+
const rawPayload = (0, import_utils27.hexlify)(new import_transactions21.TransactionCoder().encode(transaction));
|
6034
6144
|
operations = getOperations({
|
6035
6145
|
transactionType: transaction.type,
|
6036
6146
|
inputs: transaction.inputs || [],
|
@@ -6076,7 +6186,7 @@ function assemblePreConfirmationTransactionSummary(params) {
|
|
6076
6186
|
__name(assemblePreConfirmationTransactionSummary, "assemblePreConfirmationTransactionSummary");
|
6077
6187
|
|
6078
6188
|
// src/providers/transaction-response/getAllDecodedLogs.ts
|
6079
|
-
var
|
6189
|
+
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
6080
6190
|
var import_configs12 = require("@fuel-ts/address/configs");
|
6081
6191
|
var import_transactions22 = require("@fuel-ts/transactions");
|
6082
6192
|
function getAllDecodedLogs(opts) {
|
@@ -6096,8 +6206,8 @@ function getAllDecodedLogs(opts) {
|
|
6096
6206
|
const isLogFromMainAbi = receipt.id === import_configs12.ZeroBytes32 || mainContract === receipt.id;
|
6097
6207
|
const isDecodable = isLogFromMainAbi || externalAbis[receipt.id];
|
6098
6208
|
if (isDecodable) {
|
6099
|
-
const interfaceToUse = isLogFromMainAbi ? new
|
6100
|
-
const data = receipt.type === import_transactions22.ReceiptType.Log ? new
|
6209
|
+
const interfaceToUse = isLogFromMainAbi ? new import_abi_coder6.Interface(mainAbi) : new import_abi_coder6.Interface(externalAbis[receipt.id]);
|
6210
|
+
const data = receipt.type === import_transactions22.ReceiptType.Log ? new import_abi_coder6.BigNumberCoder("u64").encode(receipt.ra) : receipt.data;
|
6101
6211
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
|
6102
6212
|
logs.push(decodedLog);
|
6103
6213
|
groupedLogs[receipt.id] = [...groupedLogs[receipt.id] || [], decodedLog];
|
@@ -6196,7 +6306,7 @@ var TransactionResponse = class _TransactionResponse {
|
|
6196
6306
|
}
|
6197
6307
|
const gqlTransaction = this.gqlTransaction ?? await this.fetch();
|
6198
6308
|
const { rawPayload } = gqlTransaction;
|
6199
|
-
const bytes = (0,
|
6309
|
+
const bytes = (0, import_utils29.arrayify)(rawPayload);
|
6200
6310
|
const [tx] = new import_transactions23.TransactionCoder().decode(bytes, 0);
|
6201
6311
|
return {
|
6202
6312
|
tx,
|
@@ -6384,6 +6494,7 @@ var TransactionResponse = class _TransactionResponse {
|
|
6384
6494
|
...transactionSummary
|
6385
6495
|
};
|
6386
6496
|
let { logs, groupedLogs } = { logs: [], groupedLogs: {} };
|
6497
|
+
let abis;
|
6387
6498
|
if (this.abis) {
|
6388
6499
|
({ logs, groupedLogs } = getAllDecodedLogs({
|
6389
6500
|
receipts: transactionSummary.receipts,
|
@@ -6392,6 +6503,7 @@ var TransactionResponse = class _TransactionResponse {
|
|
6392
6503
|
}));
|
6393
6504
|
transactionResult.logs = logs;
|
6394
6505
|
transactionResult.groupedLogs = groupedLogs;
|
6506
|
+
abis = this.abis;
|
6395
6507
|
}
|
6396
6508
|
const { receipts } = transactionResult;
|
6397
6509
|
const status = this.getTransactionStatus();
|
@@ -6401,7 +6513,8 @@ var TransactionResponse = class _TransactionResponse {
|
|
6401
6513
|
receipts,
|
6402
6514
|
statusReason: reason,
|
6403
6515
|
logs,
|
6404
|
-
groupedLogs
|
6516
|
+
groupedLogs,
|
6517
|
+
abis
|
6405
6518
|
});
|
6406
6519
|
}
|
6407
6520
|
return transactionResult;
|
@@ -6463,7 +6576,7 @@ var TransactionResponse = class _TransactionResponse {
|
|
6463
6576
|
};
|
6464
6577
|
|
6465
6578
|
// src/providers/transaction-response/getDecodedLogs.ts
|
6466
|
-
var
|
6579
|
+
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
6467
6580
|
var import_configs13 = require("@fuel-ts/address/configs");
|
6468
6581
|
var import_transactions24 = require("@fuel-ts/transactions");
|
6469
6582
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
@@ -6479,8 +6592,8 @@ function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
|
6479
6592
|
const isLogFromMainAbi = receipt.id === import_configs13.ZeroBytes32 || mainContract === receipt.id;
|
6480
6593
|
const isDecodable = isLogFromMainAbi || externalAbis[receipt.id];
|
6481
6594
|
if (isDecodable) {
|
6482
|
-
const interfaceToUse = isLogFromMainAbi ? new
|
6483
|
-
const data = receipt.type === import_transactions24.ReceiptType.Log ? new
|
6595
|
+
const interfaceToUse = isLogFromMainAbi ? new import_abi_coder7.Interface(mainAbi) : new import_abi_coder7.Interface(externalAbis[receipt.id]);
|
6596
|
+
const data = receipt.type === import_transactions24.ReceiptType.Log ? new import_abi_coder7.BigNumberCoder("u64").encode(receipt.ra) : receipt.data;
|
6484
6597
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
|
6485
6598
|
logs.push(decodedLog);
|
6486
6599
|
}
|
@@ -6491,7 +6604,7 @@ function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
|
6491
6604
|
__name(getDecodedLogs, "getDecodedLogs");
|
6492
6605
|
|
6493
6606
|
// src/providers/utils/auto-retry-fetch.ts
|
6494
|
-
var
|
6607
|
+
var import_utils31 = require("@fuel-ts/utils");
|
6495
6608
|
function getWaitDelay(options, retryAttemptNum) {
|
6496
6609
|
const duration = options.baseDelay ?? 150;
|
6497
6610
|
switch (options.backoff) {
|
@@ -6522,7 +6635,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
6522
6635
|
throw error;
|
6523
6636
|
}
|
6524
6637
|
const delay = getWaitDelay(options, retryNum);
|
6525
|
-
await (0,
|
6638
|
+
await (0, import_utils31.sleep)(delay);
|
6526
6639
|
return autoRetryFetch(fetchFn, options, retryNum)(...args);
|
6527
6640
|
}
|
6528
6641
|
};
|
@@ -6662,7 +6775,7 @@ var Provider = class _Provider {
|
|
6662
6775
|
return url.replace(/-sub$/, "");
|
6663
6776
|
}
|
6664
6777
|
static hasWriteOperationHappened(url) {
|
6665
|
-
return (0,
|
6778
|
+
return (0, import_utils32.isDefined)(_Provider.currentBlockHeightCache[this.normalizeUrl(url)]);
|
6666
6779
|
}
|
6667
6780
|
/**
|
6668
6781
|
* @hidden
|
@@ -6717,14 +6830,14 @@ var Provider = class _Provider {
|
|
6717
6830
|
}
|
6718
6831
|
const retryAttempt = retryOptions.maxRetries - retriesLeft + 1;
|
6719
6832
|
const sleepTime = getWaitDelay(retryOptions, retryAttempt);
|
6720
|
-
await (0,
|
6833
|
+
await (0, import_utils32.sleep)(sleepTime);
|
6721
6834
|
response = await fetchFn();
|
6722
6835
|
}
|
6723
6836
|
return response;
|
6724
6837
|
}
|
6725
6838
|
static setCurrentBlockHeight(url, height) {
|
6726
6839
|
const writeOperationHappened = _Provider.hasWriteOperationHappened(url);
|
6727
|
-
if (!(0,
|
6840
|
+
if (!(0, import_utils32.isDefined)(height) || !writeOperationHappened) {
|
6728
6841
|
return;
|
6729
6842
|
}
|
6730
6843
|
const normalizedUrl = _Provider.normalizeUrl(url);
|
@@ -6759,7 +6872,7 @@ var Provider = class _Provider {
|
|
6759
6872
|
_Provider.chainInfoCache[this.urlWithoutAuth] = chain;
|
6760
6873
|
_Provider.nodeInfoCache[this.urlWithoutAuth] = nodeInfo;
|
6761
6874
|
}
|
6762
|
-
if ((0,
|
6875
|
+
if ((0, import_utils32.isDefined)(resourceCacheTTL)) {
|
6763
6876
|
if (resourceCacheTTL !== -1) {
|
6764
6877
|
this.cache = new ResourceCache(resourceCacheTTL);
|
6765
6878
|
} else {
|
@@ -7122,7 +7235,7 @@ var Provider = class _Provider {
|
|
7122
7235
|
await this.estimateTxDependencies(transactionRequest);
|
7123
7236
|
}
|
7124
7237
|
await this.validateTransaction(transactionRequest);
|
7125
|
-
const encodedTransaction = (0,
|
7238
|
+
const encodedTransaction = (0, import_utils32.hexlify)(transactionRequest.toTransactionBytes());
|
7126
7239
|
let abis;
|
7127
7240
|
if (isTransactionTypeScript(transactionRequest)) {
|
7128
7241
|
abis = transactionRequest.abis;
|
@@ -7153,7 +7266,7 @@ var Provider = class _Provider {
|
|
7153
7266
|
if (estimateTxDependencies) {
|
7154
7267
|
return this.estimateTxDependencies(transactionRequest);
|
7155
7268
|
}
|
7156
|
-
const encodedTransaction = (0,
|
7269
|
+
const encodedTransaction = (0, import_utils32.hexlify)(transactionRequest.toTransactionBytes());
|
7157
7270
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
7158
7271
|
encodedTransactions: encodedTransaction,
|
7159
7272
|
utxoValidation: utxoValidation || false
|
@@ -7177,7 +7290,7 @@ var Provider = class _Provider {
|
|
7177
7290
|
if (!shouldEstimatePredicates) {
|
7178
7291
|
return transactionRequest;
|
7179
7292
|
}
|
7180
|
-
const encodedTransaction = (0,
|
7293
|
+
const encodedTransaction = (0, import_utils32.hexlify)(transactionRequest.toTransactionBytes());
|
7181
7294
|
const response = await this.operations.estimatePredicates({
|
7182
7295
|
encodedTransaction
|
7183
7296
|
});
|
@@ -7209,7 +7322,7 @@ var Provider = class _Provider {
|
|
7209
7322
|
estimatePredicates
|
7210
7323
|
} = await this.operations.estimatePredicatesAndGasPrice({
|
7211
7324
|
blockHorizon: String(blockHorizon),
|
7212
|
-
encodedTransaction: (0,
|
7325
|
+
encodedTransaction: (0, import_utils32.hexlify)(transactionRequest.toTransactionBytes())
|
7213
7326
|
});
|
7214
7327
|
transactionRequest = this.parseEstimatePredicatesResponse(
|
7215
7328
|
transactionRequest,
|
@@ -7247,7 +7360,7 @@ var Provider = class _Provider {
|
|
7247
7360
|
const {
|
7248
7361
|
dryRun: [{ receipts: serializedReceipts, status }]
|
7249
7362
|
} = await this.operations.dryRun({
|
7250
|
-
encodedTransactions: [(0,
|
7363
|
+
encodedTransactions: [(0, import_utils32.hexlify)(transactionRequest.toTransactionBytes())],
|
7251
7364
|
utxoValidation: false,
|
7252
7365
|
gasPrice: gasPrice.toString()
|
7253
7366
|
});
|
@@ -7302,7 +7415,7 @@ var Provider = class _Provider {
|
|
7302
7415
|
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
7303
7416
|
allRequests.forEach((req, index) => {
|
7304
7417
|
if (isTransactionTypeScript(req)) {
|
7305
|
-
serializedTransactionsMap.set(index, (0,
|
7418
|
+
serializedTransactionsMap.set(index, (0, import_utils32.hexlify)(req.toTransactionBytes()));
|
7306
7419
|
}
|
7307
7420
|
});
|
7308
7421
|
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
@@ -7338,7 +7451,7 @@ var Provider = class _Provider {
|
|
7338
7451
|
transactionRequest: request2
|
7339
7452
|
});
|
7340
7453
|
request2.maxFee = maxFee;
|
7341
|
-
serializedTransactionsMap.set(requestIdx, (0,
|
7454
|
+
serializedTransactionsMap.set(requestIdx, (0, import_utils32.hexlify)(request2.toTransactionBytes()));
|
7342
7455
|
nextRoundTransactions.push(requestIdx);
|
7343
7456
|
}
|
7344
7457
|
}
|
@@ -7359,7 +7472,7 @@ var Provider = class _Provider {
|
|
7359
7472
|
if (estimateTxDependencies) {
|
7360
7473
|
return this.estimateMultipleTxDependencies(transactionRequests);
|
7361
7474
|
}
|
7362
|
-
const encodedTransactions = transactionRequests.map((tx) => (0,
|
7475
|
+
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils32.hexlify)(tx.toTransactionBytes()));
|
7363
7476
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
7364
7477
|
encodedTransactions,
|
7365
7478
|
utxoValidation: utxoValidation || false
|
@@ -7409,7 +7522,7 @@ var Provider = class _Provider {
|
|
7409
7522
|
const chainInfo = await this.getChain();
|
7410
7523
|
const { gasPriceFactor, maxGasPerTx } = await this.getGasConfig();
|
7411
7524
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
7412
|
-
if (!(0,
|
7525
|
+
if (!(0, import_utils32.isDefined)(gasPrice)) {
|
7413
7526
|
gasPrice = await this.estimateGasPrice(10);
|
7414
7527
|
}
|
7415
7528
|
const minFee = calculateGasFee({
|
@@ -7461,7 +7574,7 @@ var Provider = class _Provider {
|
|
7461
7574
|
if (estimateTxDependencies) {
|
7462
7575
|
return this.estimateTxDependencies(transactionRequest);
|
7463
7576
|
}
|
7464
|
-
const encodedTransactions = [(0,
|
7577
|
+
const encodedTransactions = [(0, import_utils32.hexlify)(transactionRequest.toTransactionBytes())];
|
7465
7578
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
7466
7579
|
encodedTransactions,
|
7467
7580
|
utxoValidation: true
|
@@ -7624,7 +7737,7 @@ var Provider = class _Provider {
|
|
7624
7737
|
const {
|
7625
7738
|
assembleTx: { status, transaction: gqlTransaction, gasPrice }
|
7626
7739
|
} = await this.operations.assembleTx({
|
7627
|
-
tx: (0,
|
7740
|
+
tx: (0, import_utils32.hexlify)(request2.toTransactionBytes()),
|
7628
7741
|
blockHorizon: String(blockHorizon),
|
7629
7742
|
feeAddressIndex: String(feePayerIndex),
|
7630
7743
|
requiredBalances,
|
@@ -7676,7 +7789,7 @@ var Provider = class _Provider {
|
|
7676
7789
|
paginationLimit: RESOURCES_PAGE_SIZE_LIMIT,
|
7677
7790
|
inputArgs: paginationArgs
|
7678
7791
|
}),
|
7679
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
7792
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils32.hexlify)(assetId) }
|
7680
7793
|
});
|
7681
7794
|
const coins = edges.map(({ node }) => ({
|
7682
7795
|
id: node.utxoId,
|
@@ -7708,7 +7821,7 @@ var Provider = class _Provider {
|
|
7708
7821
|
const coinsQuery = {
|
7709
7822
|
owner: ownerAddress.toB256(),
|
7710
7823
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
7711
|
-
assetId: (0,
|
7824
|
+
assetId: (0, import_utils32.hexlify)(assetId),
|
7712
7825
|
amount: (amount.eqn(0) ? (0, import_math19.bn)(1) : amount).toString(10),
|
7713
7826
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
7714
7827
|
})),
|
@@ -7866,7 +7979,7 @@ var Provider = class _Provider {
|
|
7866
7979
|
},
|
7867
7980
|
transactionIds: block.transactions.map((tx) => tx.id),
|
7868
7981
|
transactions: block.transactions.map(
|
7869
|
-
(tx) => new import_transactions25.TransactionCoder().decode((0,
|
7982
|
+
(tx) => new import_transactions25.TransactionCoder().decode((0, import_utils32.arrayify)(tx.rawPayload), 0)?.[0]
|
7870
7983
|
)
|
7871
7984
|
};
|
7872
7985
|
}
|
@@ -7883,7 +7996,7 @@ var Provider = class _Provider {
|
|
7883
7996
|
}
|
7884
7997
|
try {
|
7885
7998
|
return new import_transactions25.TransactionCoder().decode(
|
7886
|
-
(0,
|
7999
|
+
(0, import_utils32.arrayify)(transaction.rawPayload),
|
7887
8000
|
0
|
7888
8001
|
)?.[0];
|
7889
8002
|
} catch (error) {
|
@@ -7911,7 +8024,7 @@ var Provider = class _Provider {
|
|
7911
8024
|
const coder = new import_transactions25.TransactionCoder();
|
7912
8025
|
const transactions = edges.map(({ node: { rawPayload } }) => {
|
7913
8026
|
try {
|
7914
|
-
return coder.decode((0,
|
8027
|
+
return coder.decode((0, import_utils32.arrayify)(rawPayload), 0)[0];
|
7915
8028
|
} catch (error) {
|
7916
8029
|
if (error instanceof import_errors20.FuelError && error.code === import_errors20.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
|
7917
8030
|
console.warn("Unsupported transaction type encountered");
|
@@ -7960,7 +8073,7 @@ var Provider = class _Provider {
|
|
7960
8073
|
async getContractBalance(contractId, assetId) {
|
7961
8074
|
const { contractBalance } = await this.operations.getContractBalance({
|
7962
8075
|
contract: new import_address3.Address(contractId).toB256(),
|
7963
|
-
asset: (0,
|
8076
|
+
asset: (0, import_utils32.hexlify)(assetId)
|
7964
8077
|
});
|
7965
8078
|
return (0, import_math19.bn)(contractBalance.amount, 10);
|
7966
8079
|
}
|
@@ -7974,7 +8087,7 @@ var Provider = class _Provider {
|
|
7974
8087
|
async getBalance(owner, assetId) {
|
7975
8088
|
const { balance } = await this.operations.getBalanceV2({
|
7976
8089
|
owner: new import_address3.Address(owner).toB256(),
|
7977
|
-
assetId: (0,
|
8090
|
+
assetId: (0, import_utils32.hexlify)(assetId)
|
7978
8091
|
});
|
7979
8092
|
return (0, import_math19.bn)(balance.amountU128, 10);
|
7980
8093
|
}
|
@@ -8179,7 +8292,7 @@ var Provider = class _Provider {
|
|
8179
8292
|
async produceBlocks(amount, startTime) {
|
8180
8293
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
8181
8294
|
blocksToProduce: (0, import_math19.bn)(amount).toString(10),
|
8182
|
-
startTimestamp: startTime ?
|
8295
|
+
startTimestamp: startTime ? import_utils32.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
8183
8296
|
});
|
8184
8297
|
return (0, import_math19.bn)(latestBlockHeight);
|
8185
8298
|
}
|
@@ -8282,18 +8395,21 @@ var Provider = class _Provider {
|
|
8282
8395
|
extractDryRunError(transactionRequest, receipts, reason) {
|
8283
8396
|
let logs = [];
|
8284
8397
|
let groupedLogs = {};
|
8398
|
+
let abis;
|
8285
8399
|
if (transactionRequest.type === import_transactions25.TransactionType.Script && transactionRequest.abis) {
|
8286
8400
|
({ logs, groupedLogs } = getAllDecodedLogs({
|
8287
8401
|
receipts,
|
8288
8402
|
mainAbi: transactionRequest.abis.main,
|
8289
8403
|
externalAbis: transactionRequest.abis.otherContractsAbis
|
8290
8404
|
}));
|
8405
|
+
abis = transactionRequest.abis;
|
8291
8406
|
}
|
8292
8407
|
return extractTxError({
|
8293
8408
|
logs,
|
8294
8409
|
groupedLogs,
|
8295
8410
|
receipts,
|
8296
|
-
statusReason: reason
|
8411
|
+
statusReason: reason,
|
8412
|
+
abis
|
8297
8413
|
});
|
8298
8414
|
}
|
8299
8415
|
/**
|
@@ -8332,8 +8448,8 @@ var Provider = class _Provider {
|
|
8332
8448
|
*/
|
8333
8449
|
async adjustResourcesToIgnoreForAddresses(addresses, resourcesIdsToIgnore) {
|
8334
8450
|
const final = {
|
8335
|
-
messages: resourcesIdsToIgnore?.messages?.map((nonce) => (0,
|
8336
|
-
utxos: resourcesIdsToIgnore?.utxos?.map((id) => (0,
|
8451
|
+
messages: resourcesIdsToIgnore?.messages?.map((nonce) => (0, import_utils32.hexlify)(nonce)) || [],
|
8452
|
+
utxos: resourcesIdsToIgnore?.utxos?.map((id) => (0, import_utils32.hexlify)(id)) || []
|
8337
8453
|
};
|
8338
8454
|
if (this.cache) {
|
8339
8455
|
const cache2 = this.cache;
|
@@ -8365,7 +8481,7 @@ var Provider = class _Provider {
|
|
8365
8481
|
var import_errors21 = require("@fuel-ts/errors");
|
8366
8482
|
var import_math20 = require("@fuel-ts/math");
|
8367
8483
|
var import_transactions26 = require("@fuel-ts/transactions");
|
8368
|
-
var
|
8484
|
+
var import_utils34 = require("@fuel-ts/utils");
|
8369
8485
|
async function getTransactionSummary(params) {
|
8370
8486
|
const { id, provider, abiMap } = params;
|
8371
8487
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
@@ -8378,7 +8494,7 @@ async function getTransactionSummary(params) {
|
|
8378
8494
|
);
|
8379
8495
|
}
|
8380
8496
|
const [decodedTransaction] = new import_transactions26.TransactionCoder().decode(
|
8381
|
-
(0,
|
8497
|
+
(0, import_utils34.arrayify)(gqlTransaction.rawPayload),
|
8382
8498
|
0
|
8383
8499
|
);
|
8384
8500
|
let txReceipts = [];
|
@@ -8400,7 +8516,7 @@ async function getTransactionSummary(params) {
|
|
8400
8516
|
id: gqlTransaction.id,
|
8401
8517
|
receipts,
|
8402
8518
|
transaction: decodedTransaction,
|
8403
|
-
transactionBytes: (0,
|
8519
|
+
transactionBytes: (0, import_utils34.arrayify)(gqlTransaction.rawPayload),
|
8404
8520
|
gqlTransactionStatus: gqlTransaction.status,
|
8405
8521
|
gasPerByte: (0, import_math20.bn)(gasPerByte),
|
8406
8522
|
gasPriceFactor: (0, import_math20.bn)(gasPriceFactor),
|
@@ -8466,7 +8582,7 @@ async function getTransactionsSummaries(params) {
|
|
8466
8582
|
const transactions = edges.map((edge) => {
|
8467
8583
|
const { node: gqlTransaction } = edge;
|
8468
8584
|
const { id, rawPayload, status } = gqlTransaction;
|
8469
|
-
const [decodedTransaction] = new import_transactions26.TransactionCoder().decode((0,
|
8585
|
+
const [decodedTransaction] = new import_transactions26.TransactionCoder().decode((0, import_utils34.arrayify)(rawPayload), 0);
|
8470
8586
|
let txReceipts = [];
|
8471
8587
|
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
8472
8588
|
txReceipts = gqlTransaction.status.receipts;
|
@@ -8476,7 +8592,7 @@ async function getTransactionsSummaries(params) {
|
|
8476
8592
|
id,
|
8477
8593
|
receipts,
|
8478
8594
|
transaction: decodedTransaction,
|
8479
|
-
transactionBytes: (0,
|
8595
|
+
transactionBytes: (0, import_utils34.arrayify)(rawPayload),
|
8480
8596
|
gqlTransactionStatus: status,
|
8481
8597
|
abiMap,
|
8482
8598
|
gasPerByte,
|
@@ -8502,7 +8618,7 @@ __name(getTransactionsSummaries, "getTransactionsSummaries");
|
|
8502
8618
|
// src/providers/transaction-summary/assemble-transaction-summary-from-serialized.ts
|
8503
8619
|
var import_math21 = require("@fuel-ts/math");
|
8504
8620
|
var import_transactions27 = require("@fuel-ts/transactions");
|
8505
|
-
var
|
8621
|
+
var import_utils35 = require("@fuel-ts/utils");
|
8506
8622
|
var assembleTransactionSummaryFromJson = /* @__PURE__ */ __name(async (opts) => {
|
8507
8623
|
const { provider, transactionSummary } = opts;
|
8508
8624
|
const { id, transactionBytes, gasPrice, receipts } = transactionSummary;
|
@@ -8514,7 +8630,7 @@ var assembleTransactionSummaryFromJson = /* @__PURE__ */ __name(async (opts) =>
|
|
8514
8630
|
gasCosts
|
8515
8631
|
}
|
8516
8632
|
} = await provider.getChain();
|
8517
|
-
const deserializedTransactionBytes = (0,
|
8633
|
+
const deserializedTransactionBytes = (0, import_utils35.arrayify)(transactionBytes);
|
8518
8634
|
const [transaction] = new import_transactions27.TransactionCoder().decode(deserializedTransactionBytes, 0);
|
8519
8635
|
return assembleTransactionSummary({
|
8520
8636
|
id,
|
@@ -8577,17 +8693,17 @@ var AbstractAccount = class {
|
|
8577
8693
|
};
|
8578
8694
|
|
8579
8695
|
// src/utils/formatTransferToContractScriptData.ts
|
8580
|
-
var
|
8696
|
+
var import_abi_coder8 = require("@fuel-ts/abi-coder");
|
8581
8697
|
var import_address4 = require("@fuel-ts/address");
|
8582
|
-
var
|
8698
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8583
8699
|
var asm = __toESM(require("@fuels/vm-asm"));
|
8584
8700
|
var formatTransferToContractScriptData = /* @__PURE__ */ __name((transferParams) => {
|
8585
|
-
const numberCoder = new
|
8701
|
+
const numberCoder = new import_abi_coder8.BigNumberCoder("u64");
|
8586
8702
|
return transferParams.reduce((acc, transferParam) => {
|
8587
8703
|
const { assetId, amount, contractId } = transferParam;
|
8588
8704
|
const encoded = numberCoder.encode(amount);
|
8589
|
-
const scriptData = (0,
|
8590
|
-
return (0,
|
8705
|
+
const scriptData = (0, import_utils36.concat)([new import_address4.Address(contractId).toBytes(), encoded, (0, import_utils36.arrayify)(assetId)]);
|
8706
|
+
return (0, import_utils36.concat)([acc, scriptData]);
|
8591
8707
|
}, new Uint8Array());
|
8592
8708
|
}, "formatTransferToContractScriptData");
|
8593
8709
|
var assembleTransferToContractScript = /* @__PURE__ */ __name(async (transferParams) => {
|
@@ -8595,24 +8711,24 @@ var assembleTransferToContractScript = /* @__PURE__ */ __name(async (transferPar
|
|
8595
8711
|
await asm.initWasm();
|
8596
8712
|
let script = new Uint8Array();
|
8597
8713
|
transferParams.forEach((_, i) => {
|
8598
|
-
const offset = (
|
8599
|
-
script = (0,
|
8714
|
+
const offset = (import_abi_coder8.CONTRACT_ID_LEN + import_abi_coder8.WORD_SIZE + import_abi_coder8.ASSET_ID_LEN) * i;
|
8715
|
+
script = (0, import_utils36.concat)([
|
8600
8716
|
script,
|
8601
8717
|
// Load ScriptData into register 0x10.
|
8602
8718
|
asm.gtf(16, 0, asm.GTFArgs.ScriptData).to_bytes(),
|
8603
8719
|
// Add the offset to 0x10 so it will point to the current contract ID, store in 0x11.
|
8604
8720
|
asm.addi(17, 16, offset).to_bytes(),
|
8605
8721
|
// Add CONTRACT_ID_LEN to 0x11 to point to the amount in the ScriptData, store in 0x12.
|
8606
|
-
asm.addi(18, 17,
|
8722
|
+
asm.addi(18, 17, import_abi_coder8.CONTRACT_ID_LEN).to_bytes(),
|
8607
8723
|
// Load word to the amount at 0x12 into register 0x13.
|
8608
8724
|
asm.lw(19, 18, 0).to_bytes(),
|
8609
8725
|
// Add WORD_SIZE to 0x12 to point to the asset ID in the ScriptData, store in 0x14.
|
8610
|
-
asm.addi(20, 18,
|
8726
|
+
asm.addi(20, 18, import_abi_coder8.WORD_SIZE).to_bytes(),
|
8611
8727
|
// Perform the transfer using contract ID in 0x11, amount in 0x13, and asset ID in 0x14.
|
8612
8728
|
asm.tr(17, 19, 20).to_bytes()
|
8613
8729
|
]);
|
8614
8730
|
});
|
8615
|
-
script = (0,
|
8731
|
+
script = (0, import_utils36.concat)([script, asm.ret(1).to_bytes()]);
|
8616
8732
|
return { script, scriptData };
|
8617
8733
|
}, "assembleTransferToContractScript");
|
8618
8734
|
|
@@ -8962,7 +9078,7 @@ var Account = class extends AbstractAccount {
|
|
8962
9078
|
const transferParams = contractTransferParams.map((transferParam) => {
|
8963
9079
|
const amount = (0, import_math22.bn)(transferParam.amount);
|
8964
9080
|
const contractAddress = new import_address5.Address(transferParam.contractId);
|
8965
|
-
const assetId = transferParam.assetId ? (0,
|
9081
|
+
const assetId = transferParam.assetId ? (0, import_utils37.hexlify)(transferParam.assetId) : defaultAssetId;
|
8966
9082
|
if (amount.lte(0)) {
|
8967
9083
|
throw new import_errors22.FuelError(
|
8968
9084
|
import_errors22.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
@@ -9000,14 +9116,14 @@ var Account = class extends AbstractAccount {
|
|
9000
9116
|
*/
|
9001
9117
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
9002
9118
|
const recipientAddress = new import_address5.Address(recipient);
|
9003
|
-
const recipientDataArray = (0,
|
9119
|
+
const recipientDataArray = (0, import_utils37.arrayify)(
|
9004
9120
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
9005
9121
|
);
|
9006
|
-
const amountDataArray = (0,
|
9122
|
+
const amountDataArray = (0, import_utils37.arrayify)(
|
9007
9123
|
"0x".concat((0, import_math22.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
9008
9124
|
);
|
9009
9125
|
const script = new Uint8Array([
|
9010
|
-
...(0,
|
9126
|
+
...(0, import_utils37.arrayify)(withdrawScript.bytes),
|
9011
9127
|
...recipientDataArray,
|
9012
9128
|
...amountDataArray
|
9013
9129
|
]);
|
@@ -9229,14 +9345,23 @@ var Account = class extends AbstractAccount {
|
|
9229
9345
|
* @param transactionRequestLike - The transaction request to sign.
|
9230
9346
|
* @returns A promise that resolves to the signature of the transaction.
|
9231
9347
|
*/
|
9232
|
-
async signTransaction(transactionRequestLike) {
|
9348
|
+
async signTransaction(transactionRequestLike, connectorOptions = {}) {
|
9233
9349
|
if (!this._connector) {
|
9234
9350
|
throw new import_errors22.FuelError(
|
9235
9351
|
import_errors22.ErrorCode.MISSING_CONNECTOR,
|
9236
9352
|
"A connector is required to sign transactions."
|
9237
9353
|
);
|
9238
9354
|
}
|
9239
|
-
|
9355
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9356
|
+
const { transactionRequest: requestToSign, connectorsSendTxParams } = await this.setTransactionStateForConnectors({
|
9357
|
+
transactionRequest,
|
9358
|
+
connectorOptions
|
9359
|
+
});
|
9360
|
+
return this._connector.signTransaction(
|
9361
|
+
this.address.toString(),
|
9362
|
+
requestToSign,
|
9363
|
+
connectorsSendTxParams
|
9364
|
+
);
|
9240
9365
|
}
|
9241
9366
|
/**
|
9242
9367
|
* Sends a transaction to the network.
|
@@ -9246,24 +9371,16 @@ var Account = class extends AbstractAccount {
|
|
9246
9371
|
* @returns A promise that resolves to the transaction response.
|
9247
9372
|
*/
|
9248
9373
|
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, ...connectorOptions } = {}) {
|
9249
|
-
|
9374
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9250
9375
|
if (this._connector) {
|
9251
|
-
const
|
9252
|
-
|
9253
|
-
|
9254
|
-
|
9255
|
-
skipCustomFee,
|
9256
|
-
provider: {
|
9257
|
-
url: this.provider.url,
|
9258
|
-
cache: await serializeProviderCache(this.provider)
|
9259
|
-
},
|
9260
|
-
transactionState: transactionRequest.flag.state,
|
9261
|
-
transactionSummary: await this.prepareTransactionSummary(transactionRequest)
|
9262
|
-
};
|
9376
|
+
const response = await this.setTransactionStateForConnectors({
|
9377
|
+
transactionRequest,
|
9378
|
+
connectorOptions
|
9379
|
+
});
|
9263
9380
|
const transaction = await this._connector.sendTransaction(
|
9264
9381
|
this.address.toString(),
|
9265
|
-
transactionRequest,
|
9266
|
-
|
9382
|
+
response.transactionRequest,
|
9383
|
+
response.connectorsSendTxParams
|
9267
9384
|
);
|
9268
9385
|
return typeof transaction === "string" ? this.provider.getTransactionResponse(transaction) : transaction;
|
9269
9386
|
}
|
@@ -9296,7 +9413,7 @@ var Account = class extends AbstractAccount {
|
|
9296
9413
|
*/
|
9297
9414
|
generateFakeResources(coins) {
|
9298
9415
|
return coins.map((coin) => ({
|
9299
|
-
id: (0,
|
9416
|
+
id: (0, import_utils37.hexlify)((0, import_crypto2.randomBytes)(import_abi_coder9.UTXO_ID_LEN)),
|
9300
9417
|
owner: this.address,
|
9301
9418
|
blockCreated: (0, import_math22.bn)(1),
|
9302
9419
|
txCreatedIdx: (0, import_math22.bn)(1),
|
@@ -9306,7 +9423,7 @@ var Account = class extends AbstractAccount {
|
|
9306
9423
|
/** @hidden */
|
9307
9424
|
async prepareTransactionForSend(request2) {
|
9308
9425
|
const { transactionId } = request2.flag;
|
9309
|
-
if (!(0,
|
9426
|
+
if (!(0, import_utils37.isDefined)(transactionId)) {
|
9310
9427
|
return request2;
|
9311
9428
|
}
|
9312
9429
|
const chainId = await this.provider.getChainId();
|
@@ -9319,10 +9436,10 @@ var Account = class extends AbstractAccount {
|
|
9319
9436
|
/** @hidden */
|
9320
9437
|
async prepareTransactionSummary(request2) {
|
9321
9438
|
const chainId = await this.provider.getChainId();
|
9322
|
-
return (0,
|
9439
|
+
return (0, import_utils37.isDefined)(request2.flag.summary) ? {
|
9323
9440
|
...request2.flag.summary,
|
9324
9441
|
id: request2.getTransactionId(chainId),
|
9325
|
-
transactionBytes: (0,
|
9442
|
+
transactionBytes: (0, import_utils37.hexlify)(request2.toTransactionBytes())
|
9326
9443
|
} : void 0;
|
9327
9444
|
}
|
9328
9445
|
/** @hidden * */
|
@@ -9367,7 +9484,7 @@ var Account = class extends AbstractAccount {
|
|
9367
9484
|
txParams: { gasLimit: setGasLimit, maxFee: setMaxFee }
|
9368
9485
|
}) {
|
9369
9486
|
const request2 = transactionRequestify(transactionRequest);
|
9370
|
-
if (!(0,
|
9487
|
+
if (!(0, import_utils37.isDefined)(setGasLimit)) {
|
9371
9488
|
request2.gasLimit = gasUsed;
|
9372
9489
|
} else if (gasUsed.gt(setGasLimit)) {
|
9373
9490
|
throw new import_errors22.FuelError(
|
@@ -9375,7 +9492,7 @@ var Account = class extends AbstractAccount {
|
|
9375
9492
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
9376
9493
|
);
|
9377
9494
|
}
|
9378
|
-
if (!(0,
|
9495
|
+
if (!(0, import_utils37.isDefined)(setMaxFee)) {
|
9379
9496
|
request2.maxFee = maxFee;
|
9380
9497
|
} else if (maxFee.gt(setMaxFee)) {
|
9381
9498
|
throw new import_errors22.FuelError(
|
@@ -9397,18 +9514,35 @@ var Account = class extends AbstractAccount {
|
|
9397
9514
|
);
|
9398
9515
|
}
|
9399
9516
|
}
|
9517
|
+
/** @hidden * */
|
9518
|
+
async setTransactionStateForConnectors(params) {
|
9519
|
+
const { transactionRequest: requestToPrepare, connectorOptions } = params;
|
9520
|
+
const { onBeforeSend, skipCustomFee = false } = connectorOptions;
|
9521
|
+
const transactionRequest = await this.prepareTransactionForSend(requestToPrepare);
|
9522
|
+
const connectorsSendTxParams = {
|
9523
|
+
onBeforeSend,
|
9524
|
+
skipCustomFee,
|
9525
|
+
provider: {
|
9526
|
+
url: this.provider.url,
|
9527
|
+
cache: await serializeProviderCache(this.provider)
|
9528
|
+
},
|
9529
|
+
transactionState: requestToPrepare.flag.state,
|
9530
|
+
transactionSummary: await this.prepareTransactionSummary(requestToPrepare)
|
9531
|
+
};
|
9532
|
+
return { transactionRequest, connectorsSendTxParams };
|
9533
|
+
}
|
9400
9534
|
};
|
9401
9535
|
|
9402
9536
|
// src/wallet/base-wallet-unlocked.ts
|
9403
9537
|
var import_hasher4 = require("@fuel-ts/hasher");
|
9404
|
-
var
|
9538
|
+
var import_utils40 = require("@fuel-ts/utils");
|
9405
9539
|
|
9406
9540
|
// src/signer/signer.ts
|
9407
9541
|
var import_address6 = require("@fuel-ts/address");
|
9408
9542
|
var import_crypto3 = require("@fuel-ts/crypto");
|
9409
9543
|
var import_hasher3 = require("@fuel-ts/hasher");
|
9410
9544
|
var import_math23 = require("@fuel-ts/math");
|
9411
|
-
var
|
9545
|
+
var import_utils38 = require("@fuel-ts/utils");
|
9412
9546
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
9413
9547
|
var Signer = class _Signer {
|
9414
9548
|
static {
|
@@ -9431,9 +9565,9 @@ var Signer = class _Signer {
|
|
9431
9565
|
}
|
9432
9566
|
}
|
9433
9567
|
const privateKeyBytes = (0, import_math23.toBytes)(privateKey, 32);
|
9434
|
-
this.privateKey = (0,
|
9435
|
-
this.publicKey = (0,
|
9436
|
-
this.compressedPublicKey = (0,
|
9568
|
+
this.privateKey = (0, import_utils38.hexlify)(privateKeyBytes);
|
9569
|
+
this.publicKey = (0, import_utils38.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
9570
|
+
this.compressedPublicKey = (0, import_utils38.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
9437
9571
|
this.address = new import_address6.Address(this.publicKey);
|
9438
9572
|
}
|
9439
9573
|
/**
|
@@ -9447,11 +9581,11 @@ var Signer = class _Signer {
|
|
9447
9581
|
* @returns hashed signature
|
9448
9582
|
*/
|
9449
9583
|
sign(data) {
|
9450
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
9584
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils38.arrayify)(data), (0, import_utils38.arrayify)(this.privateKey));
|
9451
9585
|
const r = (0, import_math23.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
9452
9586
|
const s = (0, import_math23.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
9453
9587
|
s[0] |= (signature.recovery || 0) << 7;
|
9454
|
-
return (0,
|
9588
|
+
return (0, import_utils38.hexlify)((0, import_utils38.concat)([r, s]));
|
9455
9589
|
}
|
9456
9590
|
/**
|
9457
9591
|
* Add point on the current elliptic curve
|
@@ -9460,8 +9594,8 @@ var Signer = class _Signer {
|
|
9460
9594
|
* @returns compressed point on the curve
|
9461
9595
|
*/
|
9462
9596
|
addPoint(point) {
|
9463
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
9464
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
9597
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils38.arrayify)(this.compressedPublicKey));
|
9598
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils38.arrayify)(point));
|
9465
9599
|
const result = p0.add(p1);
|
9466
9600
|
return `0x${result.toHex(true)}`;
|
9467
9601
|
}
|
@@ -9473,16 +9607,16 @@ var Signer = class _Signer {
|
|
9473
9607
|
* @returns public key from signature from the
|
9474
9608
|
*/
|
9475
9609
|
static recoverPublicKey(data, signature) {
|
9476
|
-
const signedMessageBytes = (0,
|
9610
|
+
const signedMessageBytes = (0, import_utils38.arrayify)(signature);
|
9477
9611
|
const r = signedMessageBytes.slice(0, 32);
|
9478
9612
|
const s = signedMessageBytes.slice(32, 64);
|
9479
9613
|
const recoveryParam = (s[0] & 128) >> 7;
|
9480
9614
|
s[0] &= 127;
|
9481
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
9615
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils38.hexlify)(r)), BigInt((0, import_utils38.hexlify)(s))).addRecoveryBit(
|
9482
9616
|
recoveryParam
|
9483
9617
|
);
|
9484
|
-
const publicKey = sig.recoverPublicKey((0,
|
9485
|
-
return (0,
|
9618
|
+
const publicKey = sig.recoverPublicKey((0, import_utils38.arrayify)(data)).toRawBytes(false).slice(1);
|
9619
|
+
return (0, import_utils38.hexlify)(publicKey);
|
9486
9620
|
}
|
9487
9621
|
/**
|
9488
9622
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -9501,7 +9635,7 @@ var Signer = class _Signer {
|
|
9501
9635
|
* @returns random 32-byte hashed
|
9502
9636
|
*/
|
9503
9637
|
static generatePrivateKey(entropy) {
|
9504
|
-
return entropy ? (0, import_hasher3.hash)((0,
|
9638
|
+
return entropy ? (0, import_hasher3.hash)((0, import_utils38.concat)([(0, import_crypto3.randomBytes)(32), (0, import_utils38.arrayify)(entropy)])) : (0, import_crypto3.randomBytes)(32);
|
9505
9639
|
}
|
9506
9640
|
/**
|
9507
9641
|
* Extended publicKey from a compact publicKey
|
@@ -9510,8 +9644,8 @@ var Signer = class _Signer {
|
|
9510
9644
|
* @returns extended publicKey
|
9511
9645
|
*/
|
9512
9646
|
static extendPublicKey(publicKey) {
|
9513
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
9514
|
-
return (0,
|
9647
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils38.arrayify)(publicKey));
|
9648
|
+
return (0, import_utils38.hexlify)(point.toRawBytes(false).slice(1));
|
9515
9649
|
}
|
9516
9650
|
};
|
9517
9651
|
|
@@ -9519,7 +9653,7 @@ var Signer = class _Signer {
|
|
9519
9653
|
var import_address7 = require("@fuel-ts/address");
|
9520
9654
|
var import_crypto4 = require("@fuel-ts/crypto");
|
9521
9655
|
var import_errors23 = require("@fuel-ts/errors");
|
9522
|
-
var
|
9656
|
+
var import_utils39 = require("@fuel-ts/utils");
|
9523
9657
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
9524
9658
|
var DEFAULT_KDF_PARAMS_R = 8;
|
9525
9659
|
var DEFAULT_KDF_PARAMS_P = 1;
|
@@ -9602,7 +9736,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
9602
9736
|
);
|
9603
9737
|
}
|
9604
9738
|
const buffer = await (0, import_crypto4.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
9605
|
-
const privateKey = (0,
|
9739
|
+
const privateKey = (0, import_utils39.hexlify)(buffer);
|
9606
9740
|
return privateKey;
|
9607
9741
|
}
|
9608
9742
|
__name(decryptKeystoreWallet, "decryptKeystoreWallet");
|
@@ -9655,7 +9789,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
9655
9789
|
*/
|
9656
9790
|
async signMessage(message) {
|
9657
9791
|
const signedMessage = await this.signer().sign((0, import_hasher4.hashMessage)(message));
|
9658
|
-
return (0,
|
9792
|
+
return (0, import_utils40.hexlify)(signedMessage);
|
9659
9793
|
}
|
9660
9794
|
/**
|
9661
9795
|
* Signs a transaction with the wallet's private key.
|
@@ -9668,7 +9802,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
9668
9802
|
const chainId = await this.provider.getChainId();
|
9669
9803
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
9670
9804
|
const signature = await this.signer().sign(hashedTransaction);
|
9671
|
-
return (0,
|
9805
|
+
return (0, import_utils40.hexlify)(signature);
|
9672
9806
|
}
|
9673
9807
|
/**
|
9674
9808
|
* Populates a transaction with the witnesses signature.
|
@@ -9739,13 +9873,13 @@ var import_crypto6 = require("@fuel-ts/crypto");
|
|
9739
9873
|
var import_errors26 = require("@fuel-ts/errors");
|
9740
9874
|
var import_hasher7 = require("@fuel-ts/hasher");
|
9741
9875
|
var import_math24 = require("@fuel-ts/math");
|
9742
|
-
var
|
9876
|
+
var import_utils44 = require("@fuel-ts/utils");
|
9743
9877
|
|
9744
9878
|
// src/mnemonic/mnemonic.ts
|
9745
9879
|
var import_crypto5 = require("@fuel-ts/crypto");
|
9746
9880
|
var import_errors25 = require("@fuel-ts/errors");
|
9747
9881
|
var import_hasher6 = require("@fuel-ts/hasher");
|
9748
|
-
var
|
9882
|
+
var import_utils42 = require("@fuel-ts/utils");
|
9749
9883
|
|
9750
9884
|
// src/wordlists/words/english.ts
|
9751
9885
|
var english = [
|
@@ -11808,7 +11942,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
11808
11942
|
// src/mnemonic/utils.ts
|
11809
11943
|
var import_errors24 = require("@fuel-ts/errors");
|
11810
11944
|
var import_hasher5 = require("@fuel-ts/hasher");
|
11811
|
-
var
|
11945
|
+
var import_utils41 = require("@fuel-ts/utils");
|
11812
11946
|
function getLowerMask(bits) {
|
11813
11947
|
return (1 << bits) - 1;
|
11814
11948
|
}
|
@@ -11847,7 +11981,7 @@ function entropyToMnemonicIndices(entropy) {
|
|
11847
11981
|
}
|
11848
11982
|
}
|
11849
11983
|
const checksumBits = entropy.length / 4;
|
11850
|
-
const checksum = (0,
|
11984
|
+
const checksum = (0, import_utils41.arrayify)((0, import_hasher5.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
11851
11985
|
indices[indices.length - 1] <<= checksumBits;
|
11852
11986
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
11853
11987
|
return indices;
|
@@ -11855,7 +11989,7 @@ function entropyToMnemonicIndices(entropy) {
|
|
11855
11989
|
__name(entropyToMnemonicIndices, "entropyToMnemonicIndices");
|
11856
11990
|
function mnemonicWordsToEntropy(words, wordlist) {
|
11857
11991
|
const size = Math.ceil(11 * words.length / 8);
|
11858
|
-
const entropy = (0,
|
11992
|
+
const entropy = (0, import_utils41.arrayify)(new Uint8Array(size));
|
11859
11993
|
let offset = 0;
|
11860
11994
|
for (let i = 0; i < words.length; i += 1) {
|
11861
11995
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -11875,7 +12009,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
11875
12009
|
const entropyBits = 32 * words.length / 3;
|
11876
12010
|
const checksumBits = words.length / 3;
|
11877
12011
|
const checksumMask = getUpperMask(checksumBits);
|
11878
|
-
const checksum = (0,
|
12012
|
+
const checksum = (0, import_utils41.arrayify)((0, import_hasher5.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
11879
12013
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
11880
12014
|
throw new import_errors24.FuelError(
|
11881
12015
|
import_errors24.ErrorCode.INVALID_CHECKSUM,
|
@@ -11887,7 +12021,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
11887
12021
|
__name(mnemonicWordsToEntropy, "mnemonicWordsToEntropy");
|
11888
12022
|
|
11889
12023
|
// src/mnemonic/mnemonic.ts
|
11890
|
-
var MasterSecret = (0,
|
12024
|
+
var MasterSecret = (0, import_utils42.toUtf8Bytes)("Bitcoin seed");
|
11891
12025
|
var MainnetPRV = "0x0488ade4";
|
11892
12026
|
var TestnetPRV = "0x04358394";
|
11893
12027
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
@@ -11957,7 +12091,7 @@ var Mnemonic = class _Mnemonic {
|
|
11957
12091
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
11958
12092
|
const words = getWords(phrase);
|
11959
12093
|
assertMnemonic(words);
|
11960
|
-
return (0,
|
12094
|
+
return (0, import_utils42.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
11961
12095
|
}
|
11962
12096
|
/**
|
11963
12097
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -11965,7 +12099,7 @@ var Mnemonic = class _Mnemonic {
|
|
11965
12099
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
11966
12100
|
*/
|
11967
12101
|
static entropyToMnemonic(entropy, wordlist = english) {
|
11968
|
-
const entropyBytes = (0,
|
12102
|
+
const entropyBytes = (0, import_utils42.arrayify)(entropy);
|
11969
12103
|
assertWordList(wordlist);
|
11970
12104
|
assertEntropy(entropyBytes);
|
11971
12105
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -11977,8 +12111,8 @@ var Mnemonic = class _Mnemonic {
|
|
11977
12111
|
*/
|
11978
12112
|
static mnemonicToSeed(phrase, passphrase = "") {
|
11979
12113
|
assertMnemonic(getWords(phrase));
|
11980
|
-
const phraseBytes = (0,
|
11981
|
-
const salt = (0,
|
12114
|
+
const phraseBytes = (0, import_utils42.toUtf8Bytes)(getPhrase(phrase));
|
12115
|
+
const salt = (0, import_utils42.toUtf8Bytes)(`mnemonic${passphrase}`);
|
11982
12116
|
return (0, import_crypto5.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
|
11983
12117
|
}
|
11984
12118
|
/**
|
@@ -12034,14 +12168,14 @@ var Mnemonic = class _Mnemonic {
|
|
12034
12168
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
12035
12169
|
*/
|
12036
12170
|
static masterKeysFromSeed(seed) {
|
12037
|
-
const seedArray = (0,
|
12171
|
+
const seedArray = (0, import_utils42.arrayify)(seed);
|
12038
12172
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
12039
12173
|
throw new import_errors25.FuelError(
|
12040
12174
|
import_errors25.ErrorCode.INVALID_SEED,
|
12041
12175
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
12042
12176
|
);
|
12043
12177
|
}
|
12044
|
-
return (0,
|
12178
|
+
return (0, import_utils42.arrayify)((0, import_crypto5.computeHmac)("sha512", MasterSecret, seedArray));
|
12045
12179
|
}
|
12046
12180
|
/**
|
12047
12181
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -12052,22 +12186,22 @@ var Mnemonic = class _Mnemonic {
|
|
12052
12186
|
*/
|
12053
12187
|
static seedToExtendedKey(seed, testnet = false) {
|
12054
12188
|
const masterKey = _Mnemonic.masterKeysFromSeed(seed);
|
12055
|
-
const prefix = (0,
|
12189
|
+
const prefix = (0, import_utils42.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
12056
12190
|
const depth = "0x00";
|
12057
12191
|
const fingerprint = "0x00000000";
|
12058
12192
|
const index = "0x00000000";
|
12059
12193
|
const chainCode = masterKey.slice(32);
|
12060
12194
|
const privateKey = masterKey.slice(0, 32);
|
12061
|
-
const extendedKey = (0,
|
12195
|
+
const extendedKey = (0, import_utils42.concat)([
|
12062
12196
|
prefix,
|
12063
12197
|
depth,
|
12064
12198
|
fingerprint,
|
12065
12199
|
index,
|
12066
12200
|
chainCode,
|
12067
|
-
(0,
|
12201
|
+
(0, import_utils42.concat)(["0x00", privateKey])
|
12068
12202
|
]);
|
12069
|
-
const checksum = (0,
|
12070
|
-
return (0,
|
12203
|
+
const checksum = (0, import_utils42.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(extendedKey)), 0, 4);
|
12204
|
+
return (0, import_utils42.encodeBase58)((0, import_utils42.concat)([extendedKey, checksum]));
|
12071
12205
|
}
|
12072
12206
|
/**
|
12073
12207
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -12082,7 +12216,7 @@ var Mnemonic = class _Mnemonic {
|
|
12082
12216
|
* @returns A randomly generated mnemonic
|
12083
12217
|
*/
|
12084
12218
|
static generate(size = 32, extraEntropy = "") {
|
12085
|
-
const entropy = extraEntropy ? (0, import_hasher6.sha256)((0,
|
12219
|
+
const entropy = extraEntropy ? (0, import_hasher6.sha256)((0, import_utils42.concat)([(0, import_crypto5.randomBytes)(size), (0, import_utils42.arrayify)(extraEntropy)])) : (0, import_crypto5.randomBytes)(size);
|
12086
12220
|
return _Mnemonic.entropyToMnemonic(entropy);
|
12087
12221
|
}
|
12088
12222
|
};
|
@@ -12090,12 +12224,12 @@ var mnemonic_default = Mnemonic;
|
|
12090
12224
|
|
12091
12225
|
// src/hdwallet/hdwallet.ts
|
12092
12226
|
var HARDENED_INDEX = 2147483648;
|
12093
|
-
var MainnetPRV2 = (0,
|
12094
|
-
var MainnetPUB = (0,
|
12095
|
-
var TestnetPRV2 = (0,
|
12096
|
-
var TestnetPUB = (0,
|
12227
|
+
var MainnetPRV2 = (0, import_utils44.hexlify)("0x0488ade4");
|
12228
|
+
var MainnetPUB = (0, import_utils44.hexlify)("0x0488b21e");
|
12229
|
+
var TestnetPRV2 = (0, import_utils44.hexlify)("0x04358394");
|
12230
|
+
var TestnetPUB = (0, import_utils44.hexlify)("0x043587cf");
|
12097
12231
|
function base58check(data) {
|
12098
|
-
return (0,
|
12232
|
+
return (0, import_utils44.encodeBase58)((0, import_utils44.concat)([data, (0, import_utils44.dataSlice)((0, import_hasher7.sha256)((0, import_hasher7.sha256)(data)), 0, 4)]));
|
12099
12233
|
}
|
12100
12234
|
__name(base58check, "base58check");
|
12101
12235
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
@@ -12106,12 +12240,12 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
12106
12240
|
}
|
12107
12241
|
__name(getExtendedKeyPrefix, "getExtendedKeyPrefix");
|
12108
12242
|
function isPublicExtendedKey(extendedKey) {
|
12109
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
12243
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils44.hexlify)(extendedKey.slice(0, 4)));
|
12110
12244
|
}
|
12111
12245
|
__name(isPublicExtendedKey, "isPublicExtendedKey");
|
12112
12246
|
function isValidExtendedKey(extendedKey) {
|
12113
12247
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
12114
|
-
(0,
|
12248
|
+
(0, import_utils44.hexlify)(extendedKey.slice(0, 4))
|
12115
12249
|
);
|
12116
12250
|
}
|
12117
12251
|
__name(isValidExtendedKey, "isValidExtendedKey");
|
@@ -12134,8 +12268,8 @@ var HDWallet = class _HDWallet {
|
|
12134
12268
|
}
|
12135
12269
|
depth = 0;
|
12136
12270
|
index = 0;
|
12137
|
-
fingerprint = (0,
|
12138
|
-
parentFingerprint = (0,
|
12271
|
+
fingerprint = (0, import_utils44.hexlify)("0x00000000");
|
12272
|
+
parentFingerprint = (0, import_utils44.hexlify)("0x00000000");
|
12139
12273
|
privateKey;
|
12140
12274
|
publicKey;
|
12141
12275
|
chainCode;
|
@@ -12147,8 +12281,8 @@ var HDWallet = class _HDWallet {
|
|
12147
12281
|
constructor(config) {
|
12148
12282
|
if (config.privateKey) {
|
12149
12283
|
const signer = new Signer(config.privateKey);
|
12150
|
-
this.publicKey = (0,
|
12151
|
-
this.privateKey = (0,
|
12284
|
+
this.publicKey = (0, import_utils44.hexlify)(signer.compressedPublicKey);
|
12285
|
+
this.privateKey = (0, import_utils44.hexlify)(config.privateKey);
|
12152
12286
|
} else {
|
12153
12287
|
if (!config.publicKey) {
|
12154
12288
|
throw new import_errors26.FuelError(
|
@@ -12156,10 +12290,10 @@ var HDWallet = class _HDWallet {
|
|
12156
12290
|
"Both public and private Key cannot be missing. At least one should be provided."
|
12157
12291
|
);
|
12158
12292
|
}
|
12159
|
-
this.publicKey = (0,
|
12293
|
+
this.publicKey = (0, import_utils44.hexlify)(config.publicKey);
|
12160
12294
|
}
|
12161
12295
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
12162
|
-
this.fingerprint = (0,
|
12296
|
+
this.fingerprint = (0, import_utils44.dataSlice)((0, import_crypto6.ripemd160)((0, import_hasher7.sha256)(this.publicKey)), 0, 4);
|
12163
12297
|
this.depth = config.depth || this.depth;
|
12164
12298
|
this.index = config.index || this.index;
|
12165
12299
|
this.chainCode = config.chainCode;
|
@@ -12175,9 +12309,9 @@ var HDWallet = class _HDWallet {
|
|
12175
12309
|
* @returns A new instance of HDWallet on the derived index
|
12176
12310
|
*/
|
12177
12311
|
deriveIndex(index) {
|
12178
|
-
const privateKey = this.privateKey && (0,
|
12179
|
-
const publicKey = (0,
|
12180
|
-
const chainCode = (0,
|
12312
|
+
const privateKey = this.privateKey && (0, import_utils44.arrayify)(this.privateKey);
|
12313
|
+
const publicKey = (0, import_utils44.arrayify)(this.publicKey);
|
12314
|
+
const chainCode = (0, import_utils44.arrayify)(this.chainCode);
|
12181
12315
|
const data = new Uint8Array(37);
|
12182
12316
|
if (index & HARDENED_INDEX) {
|
12183
12317
|
if (!privateKey) {
|
@@ -12188,10 +12322,10 @@ var HDWallet = class _HDWallet {
|
|
12188
12322
|
}
|
12189
12323
|
data.set(privateKey, 1);
|
12190
12324
|
} else {
|
12191
|
-
data.set((0,
|
12325
|
+
data.set((0, import_utils44.arrayify)(this.publicKey));
|
12192
12326
|
}
|
12193
12327
|
data.set((0, import_math24.toBytes)(index, 4), 33);
|
12194
|
-
const bytes = (0,
|
12328
|
+
const bytes = (0, import_utils44.arrayify)((0, import_crypto6.computeHmac)("sha512", chainCode, data));
|
12195
12329
|
const IL = bytes.slice(0, 32);
|
12196
12330
|
const IR = bytes.slice(32);
|
12197
12331
|
if (privateKey) {
|
@@ -12205,7 +12339,7 @@ var HDWallet = class _HDWallet {
|
|
12205
12339
|
parentFingerprint: this.fingerprint
|
12206
12340
|
});
|
12207
12341
|
}
|
12208
|
-
const signer = new Signer((0,
|
12342
|
+
const signer = new Signer((0, import_utils44.hexlify)(IL));
|
12209
12343
|
const Ki = signer.addPoint(publicKey);
|
12210
12344
|
return new _HDWallet({
|
12211
12345
|
publicKey: Ki,
|
@@ -12240,12 +12374,12 @@ var HDWallet = class _HDWallet {
|
|
12240
12374
|
);
|
12241
12375
|
}
|
12242
12376
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
12243
|
-
const depth = (0,
|
12377
|
+
const depth = (0, import_utils44.hexlify)(Uint8Array.from([this.depth]));
|
12244
12378
|
const parentFingerprint = this.parentFingerprint;
|
12245
12379
|
const index = (0, import_math24.toHex)(this.index, 4);
|
12246
12380
|
const chainCode = this.chainCode;
|
12247
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
12248
|
-
const extendedKey = (0,
|
12381
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils44.concat)(["0x00", this.privateKey]) : this.publicKey;
|
12382
|
+
const extendedKey = (0, import_utils44.arrayify)((0, import_utils44.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
12249
12383
|
return base58check(extendedKey);
|
12250
12384
|
}
|
12251
12385
|
/**
|
@@ -12257,13 +12391,13 @@ var HDWallet = class _HDWallet {
|
|
12257
12391
|
static fromSeed(seed) {
|
12258
12392
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
12259
12393
|
return new _HDWallet({
|
12260
|
-
chainCode: (0,
|
12261
|
-
privateKey: (0,
|
12394
|
+
chainCode: (0, import_utils44.arrayify)(masterKey.slice(32)),
|
12395
|
+
privateKey: (0, import_utils44.arrayify)(masterKey.slice(0, 32))
|
12262
12396
|
});
|
12263
12397
|
}
|
12264
12398
|
static fromExtendedKey(extendedKey) {
|
12265
|
-
const decoded = (0,
|
12266
|
-
const bytes = (0,
|
12399
|
+
const decoded = (0, import_utils44.hexlify)((0, import_math24.toBytes)((0, import_utils44.decodeBase58)(extendedKey)));
|
12400
|
+
const bytes = (0, import_utils44.arrayify)(decoded);
|
12267
12401
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
12268
12402
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
12269
12403
|
throw new import_errors26.FuelError(import_errors26.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -12272,9 +12406,9 @@ var HDWallet = class _HDWallet {
|
|
12272
12406
|
throw new import_errors26.FuelError(import_errors26.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
12273
12407
|
}
|
12274
12408
|
const depth = bytes[4];
|
12275
|
-
const parentFingerprint = (0,
|
12276
|
-
const index = parseInt((0,
|
12277
|
-
const chainCode = (0,
|
12409
|
+
const parentFingerprint = (0, import_utils44.hexlify)(bytes.slice(5, 9));
|
12410
|
+
const index = parseInt((0, import_utils44.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
12411
|
+
const chainCode = (0, import_utils44.hexlify)(bytes.slice(13, 45));
|
12278
12412
|
const key = bytes.slice(45, 78);
|
12279
12413
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
12280
12414
|
throw new import_errors26.FuelError(
|
@@ -12890,19 +13024,19 @@ var StorageAbstract = class {
|
|
12890
13024
|
};
|
12891
13025
|
|
12892
13026
|
// src/predicate/predicate.ts
|
12893
|
-
var
|
13027
|
+
var import_abi_coder11 = require("@fuel-ts/abi-coder");
|
12894
13028
|
var import_address11 = require("@fuel-ts/address");
|
12895
13029
|
var import_errors32 = require("@fuel-ts/errors");
|
12896
|
-
var
|
13030
|
+
var import_utils48 = require("@fuel-ts/utils");
|
12897
13031
|
|
12898
13032
|
// src/utils/deployScriptOrPredicate.ts
|
12899
13033
|
var import_errors31 = require("@fuel-ts/errors");
|
12900
|
-
var
|
13034
|
+
var import_utils46 = require("@fuel-ts/utils");
|
12901
13035
|
|
12902
13036
|
// src/utils/predicate-script-loader-instructions.ts
|
12903
|
-
var
|
13037
|
+
var import_abi_coder10 = require("@fuel-ts/abi-coder");
|
12904
13038
|
var import_hasher8 = require("@fuel-ts/hasher");
|
12905
|
-
var
|
13039
|
+
var import_utils45 = require("@fuel-ts/utils");
|
12906
13040
|
var asm2 = __toESM(require("@fuels/vm-asm"));
|
12907
13041
|
var BLOB_ID_SIZE = 32;
|
12908
13042
|
var REG_ADDRESS_OF_DATA_AFTER_CODE = 16;
|
@@ -12912,12 +13046,12 @@ var WORD_SIZE2 = 8;
|
|
12912
13046
|
var DATA_OFFSET_INDEX = 8;
|
12913
13047
|
var CONFIGURABLE_OFFSET_INDEX = 16;
|
12914
13048
|
function getBytecodeDataOffset(bytecode) {
|
12915
|
-
const [offset] = new
|
13049
|
+
const [offset] = new import_abi_coder10.BigNumberCoder("u64").decode(bytecode, DATA_OFFSET_INDEX);
|
12916
13050
|
return offset.toNumber();
|
12917
13051
|
}
|
12918
13052
|
__name(getBytecodeDataOffset, "getBytecodeDataOffset");
|
12919
13053
|
function getBytecodeConfigurableOffset(bytecode) {
|
12920
|
-
const [offset] = new
|
13054
|
+
const [offset] = new import_abi_coder10.BigNumberCoder("u64").decode(bytecode, CONFIGURABLE_OFFSET_INDEX);
|
12921
13055
|
return offset.toNumber();
|
12922
13056
|
}
|
12923
13057
|
__name(getBytecodeConfigurableOffset, "getBytecodeConfigurableOffset");
|
@@ -13028,7 +13162,7 @@ function getPredicateScriptLoaderInstructions(originalBinary, blobId) {
|
|
13028
13162
|
...dataSectionLenBytes
|
13029
13163
|
]);
|
13030
13164
|
return {
|
13031
|
-
loaderBytecode: (0,
|
13165
|
+
loaderBytecode: (0, import_utils45.concat)([loaderBytecode2, configurableSection]),
|
13032
13166
|
blobOffset: loaderBytecode2.length
|
13033
13167
|
};
|
13034
13168
|
}
|
@@ -13072,8 +13206,8 @@ async function deployScriptOrPredicate({
|
|
13072
13206
|
abi,
|
13073
13207
|
loaderInstanceCallback
|
13074
13208
|
}) {
|
13075
|
-
const blobId = getBytecodeId((0,
|
13076
|
-
const configurableOffset = getBytecodeConfigurableOffset((0,
|
13209
|
+
const blobId = getBytecodeId((0, import_utils46.arrayify)(bytecode));
|
13210
|
+
const configurableOffset = getBytecodeConfigurableOffset((0, import_utils46.arrayify)(bytecode));
|
13077
13211
|
const byteCodeWithoutConfigurableSection = bytecode.slice(0, configurableOffset);
|
13078
13212
|
const blobTxRequest = new BlobTransactionRequest({
|
13079
13213
|
blobId,
|
@@ -13081,8 +13215,8 @@ async function deployScriptOrPredicate({
|
|
13081
13215
|
witnesses: [byteCodeWithoutConfigurableSection]
|
13082
13216
|
});
|
13083
13217
|
const { loaderBytecode, blobOffset } = getPredicateScriptLoaderInstructions(
|
13084
|
-
(0,
|
13085
|
-
(0,
|
13218
|
+
(0, import_utils46.arrayify)(bytecode),
|
13219
|
+
(0, import_utils46.arrayify)(blobId)
|
13086
13220
|
);
|
13087
13221
|
const newConfigurableOffsetDiff = byteCodeWithoutConfigurableSection.length - (blobOffset || 0);
|
13088
13222
|
const newAbi = adjustConfigurableOffsets(abi, newConfigurableOffsetDiff);
|
@@ -13117,13 +13251,13 @@ __name(deployScriptOrPredicate, "deployScriptOrPredicate");
|
|
13117
13251
|
// src/predicate/utils/getPredicateRoot.ts
|
13118
13252
|
var import_hasher9 = require("@fuel-ts/hasher");
|
13119
13253
|
var import_merkle = require("@fuel-ts/merkle");
|
13120
|
-
var
|
13254
|
+
var import_utils47 = require("@fuel-ts/utils");
|
13121
13255
|
var getPredicateRoot = /* @__PURE__ */ __name((bytecode) => {
|
13122
13256
|
const chunkSize = 16 * 1024;
|
13123
|
-
const bytes = (0,
|
13124
|
-
const chunks = (0,
|
13125
|
-
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0,
|
13126
|
-
const predicateRoot = (0, import_hasher9.hash)((0,
|
13257
|
+
const bytes = (0, import_utils47.arrayify)(bytecode);
|
13258
|
+
const chunks = (0, import_utils47.chunkAndPadBytes)(bytes, chunkSize);
|
13259
|
+
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils47.hexlify)(c)));
|
13260
|
+
const predicateRoot = (0, import_hasher9.hash)((0, import_utils47.concat)(["0x4655454C", codeRoot]));
|
13127
13261
|
return predicateRoot;
|
13128
13262
|
}, "getPredicateRoot");
|
13129
13263
|
|
@@ -13160,7 +13294,7 @@ var Predicate = class _Predicate extends Account {
|
|
13160
13294
|
);
|
13161
13295
|
const address = new import_address11.Address(getPredicateRoot(predicateBytes));
|
13162
13296
|
super(address, provider);
|
13163
|
-
this.initialBytecode = (0,
|
13297
|
+
this.initialBytecode = (0, import_utils48.arrayify)(bytecode);
|
13164
13298
|
this.bytes = predicateBytes;
|
13165
13299
|
this.interface = predicateInterface;
|
13166
13300
|
this.configurableConstants = configurableConstants;
|
@@ -13182,8 +13316,8 @@ var Predicate = class _Predicate extends Account {
|
|
13182
13316
|
}
|
13183
13317
|
request2.inputs.filter(isRequestInputCoinOrMessage).forEach((input) => {
|
13184
13318
|
if (isRequestInputResourceFromOwner(input, this.address)) {
|
13185
|
-
input.predicate = (0,
|
13186
|
-
input.predicateData = (0,
|
13319
|
+
input.predicate = (0, import_utils48.hexlify)(this.bytes);
|
13320
|
+
input.predicateData = (0, import_utils48.hexlify)(this.getPredicateData());
|
13187
13321
|
input.witnessIndex = 0;
|
13188
13322
|
}
|
13189
13323
|
});
|
@@ -13252,8 +13386,8 @@ var Predicate = class _Predicate extends Account {
|
|
13252
13386
|
* @returns An object containing the new predicate bytes and interface.
|
13253
13387
|
*/
|
13254
13388
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
13255
|
-
let predicateBytes = (0,
|
13256
|
-
const abiInterface = new
|
13389
|
+
let predicateBytes = (0, import_utils48.arrayify)(bytes);
|
13390
|
+
const abiInterface = new import_abi_coder11.Interface(jsonAbi);
|
13257
13391
|
if (abiInterface.functions.main === void 0) {
|
13258
13392
|
throw new import_errors32.FuelError(
|
13259
13393
|
import_errors32.ErrorCode.ABI_MAIN_METHOD_MISSING,
|
@@ -13287,8 +13421,8 @@ var Predicate = class _Predicate extends Account {
|
|
13287
13421
|
);
|
13288
13422
|
return resources.map((resource) => ({
|
13289
13423
|
...resource,
|
13290
|
-
predicate: (0,
|
13291
|
-
predicateData: (0,
|
13424
|
+
predicate: (0, import_utils48.hexlify)(this.bytes),
|
13425
|
+
predicateData: (0, import_utils48.hexlify)(this.getPredicateData())
|
13292
13426
|
}));
|
13293
13427
|
}
|
13294
13428
|
/**
|
@@ -13300,8 +13434,8 @@ var Predicate = class _Predicate extends Account {
|
|
13300
13434
|
generateFakeResources(coins) {
|
13301
13435
|
return super.generateFakeResources(coins).map((coin) => ({
|
13302
13436
|
...coin,
|
13303
|
-
predicate: (0,
|
13304
|
-
predicateData: (0,
|
13437
|
+
predicate: (0, import_utils48.hexlify)(this.bytes),
|
13438
|
+
predicateData: (0, import_utils48.hexlify)(this.getPredicateData())
|
13305
13439
|
}));
|
13306
13440
|
}
|
13307
13441
|
/**
|
@@ -13402,6 +13536,7 @@ var FuelConnectorMethods = /* @__PURE__ */ ((FuelConnectorMethods2) => {
|
|
13402
13536
|
FuelConnectorMethods2["isConnected"] = "isConnected";
|
13403
13537
|
FuelConnectorMethods2["accounts"] = "accounts";
|
13404
13538
|
FuelConnectorMethods2["currentAccount"] = "currentAccount";
|
13539
|
+
FuelConnectorMethods2["signTransaction"] = "signTransaction";
|
13405
13540
|
FuelConnectorMethods2["signMessage"] = "signMessage";
|
13406
13541
|
FuelConnectorMethods2["sendTransaction"] = "sendTransaction";
|
13407
13542
|
FuelConnectorMethods2["assets"] = "assets";
|
@@ -13543,7 +13678,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13543
13678
|
*
|
13544
13679
|
* @returns Transaction signature
|
13545
13680
|
*/
|
13546
|
-
async signTransaction(_address, _transaction) {
|
13681
|
+
async signTransaction(_address, _transaction, _params) {
|
13547
13682
|
throw new import_errors33.FuelError(import_errors33.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13548
13683
|
}
|
13549
13684
|
/**
|
@@ -14147,6 +14282,7 @@ var Fuel = class _Fuel extends FuelConnector {
|
|
14147
14282
|
assemblePreConfirmationTransactionSummary,
|
14148
14283
|
assembleReceiptByType,
|
14149
14284
|
assembleRevertError,
|
14285
|
+
assembleSignalErrorMessage,
|
14150
14286
|
assembleTransactionSummary,
|
14151
14287
|
assembleTransactionSummaryFromJson,
|
14152
14288
|
assets,
|