@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.mjs
CHANGED
@@ -710,7 +710,7 @@ import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
|
|
710
710
|
import { ErrorCode as ErrorCode19, FuelError as FuelError21 } from "@fuel-ts/errors";
|
711
711
|
import { bn as bn21 } from "@fuel-ts/math";
|
712
712
|
import { InputType as InputType8, OutputType as OutputType9 } from "@fuel-ts/transactions";
|
713
|
-
import { arrayify as
|
713
|
+
import { arrayify as arrayify17, hexlify as hexlify18, isDefined as isDefined4 } from "@fuel-ts/utils";
|
714
714
|
import { clone as clone9 } from "ramda";
|
715
715
|
|
716
716
|
// src/providers/coin-quantity.ts
|
@@ -751,8 +751,8 @@ var addAmountToCoinQuantities = /* @__PURE__ */ __name((params) => {
|
|
751
751
|
import { Address as Address2, isB256 } from "@fuel-ts/address";
|
752
752
|
import { ErrorCode as ErrorCode17, FuelError as FuelError19 } from "@fuel-ts/errors";
|
753
753
|
import { bn as bn18 } from "@fuel-ts/math";
|
754
|
-
import { InputMessageCoder as InputMessageCoder2, TransactionCoder as
|
755
|
-
import { arrayify as
|
754
|
+
import { InputMessageCoder as InputMessageCoder2, TransactionCoder as TransactionCoder7, TransactionType as TransactionType11 } from "@fuel-ts/transactions";
|
755
|
+
import { arrayify as arrayify13, hexlify as hexlify17, DateTime as DateTime2, isDefined as isDefined3, sleep as sleep2 } from "@fuel-ts/utils";
|
756
756
|
import { checkFuelCoreVersionCompatibility, versions } from "@fuel-ts/versions";
|
757
757
|
import { GraphQLClient } from "graphql-request";
|
758
758
|
import gql2 from "graphql-tag";
|
@@ -3262,7 +3262,8 @@ import {
|
|
3262
3262
|
FAILED_ASSERT_SIGNAL,
|
3263
3263
|
FAILED_TRANSFER_TO_ADDRESS_SIGNAL as FAILED_TRANSFER_TO_ADDRESS_SIGNAL2,
|
3264
3264
|
PANIC_REASONS,
|
3265
|
-
PANIC_DOC_URL
|
3265
|
+
PANIC_DOC_URL,
|
3266
|
+
SwaySignalErrors
|
3266
3267
|
} from "@fuel-ts/transactions/configs";
|
3267
3268
|
var assemblePanicError = /* @__PURE__ */ __name((statusReason, metadata) => {
|
3268
3269
|
let errorMessage = `The transaction reverted with reason: "${statusReason}".`;
|
@@ -3279,58 +3280,97 @@ ${PANIC_DOC_URL}#variant.${statusReason}`;
|
|
3279
3280
|
});
|
3280
3281
|
}, "assemblePanicError");
|
3281
3282
|
var stringify = /* @__PURE__ */ __name((obj) => JSON.stringify(obj, null, 2), "stringify");
|
3282
|
-
var
|
3283
|
+
var assembleSignalErrorMessage = /* @__PURE__ */ __name((reasonHex, logs, metadata) => {
|
3283
3284
|
let errorMessage = "The transaction reverted with an unknown reason.";
|
3284
|
-
const revertReceipt = receipts.find(({ type }) => type === ReceiptType4.Revert);
|
3285
3285
|
let reason = "";
|
3286
|
-
|
3287
|
-
|
3288
|
-
|
3289
|
-
|
3290
|
-
|
3291
|
-
|
3292
|
-
|
3293
|
-
|
3294
|
-
|
3295
|
-
}
|
3296
|
-
|
3297
|
-
|
3298
|
-
|
3299
|
-
|
3300
|
-
|
3301
|
-
}
|
3302
|
-
|
3303
|
-
|
3304
|
-
|
3305
|
-
|
3306
|
-
|
3307
|
-
|
3308
|
-
|
3309
|
-
|
3310
|
-
|
3311
|
-
|
3312
|
-
|
3313
|
-
|
3314
|
-
|
3315
|
-
|
3316
|
-
|
3317
|
-
|
3318
|
-
|
3319
|
-
|
3320
|
-
|
3321
|
-
|
3322
|
-
|
3323
|
-
|
3324
|
-
|
3286
|
+
const lastLog = logs[logs.length - 1];
|
3287
|
+
const lastButOneLog = logs[logs.length - 2];
|
3288
|
+
switch (reasonHex) {
|
3289
|
+
case FAILED_REQUIRE_SIGNAL: {
|
3290
|
+
reason = "require";
|
3291
|
+
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(lastLog) : "an error."}.`;
|
3292
|
+
break;
|
3293
|
+
}
|
3294
|
+
case FAILED_ASSERT_EQ_SIGNAL: {
|
3295
|
+
const suffix = logs.length >= 2 ? ` comparing ${stringify(lastLog)} and ${stringify(lastButOneLog)}.` : ".";
|
3296
|
+
reason = "assert_eq";
|
3297
|
+
errorMessage = `The transaction reverted because of an "assert_eq" statement${suffix}`;
|
3298
|
+
break;
|
3299
|
+
}
|
3300
|
+
case FAILED_ASSERT_NE_SIGNAL: {
|
3301
|
+
const suffix = logs.length >= 2 ? ` comparing ${stringify(lastButOneLog)} and ${stringify(lastLog)}.` : ".";
|
3302
|
+
reason = "assert_ne";
|
3303
|
+
errorMessage = `The transaction reverted because of an "assert_ne" statement${suffix}`;
|
3304
|
+
break;
|
3305
|
+
}
|
3306
|
+
case FAILED_ASSERT_SIGNAL:
|
3307
|
+
reason = "assert";
|
3308
|
+
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
3309
|
+
break;
|
3310
|
+
case FAILED_TRANSFER_TO_ADDRESS_SIGNAL2:
|
3311
|
+
reason = "MissingOutputVariable";
|
3312
|
+
errorMessage = `The transaction reverted because it's missing an "OutputVariable".`;
|
3313
|
+
break;
|
3314
|
+
default:
|
3315
|
+
reason = `revert_with_log`;
|
3316
|
+
errorMessage = `The transaction reverted because a "revert_with_log" statement has thrown ${logs.length ? stringify(lastLog) : "an error."}.`;
|
3317
|
+
break;
|
3318
|
+
}
|
3319
|
+
return new FuelError8(ErrorCode8.SCRIPT_REVERTED, errorMessage, {
|
3320
|
+
...metadata,
|
3321
|
+
reason
|
3322
|
+
});
|
3323
|
+
}, "assembleSignalErrorMessage");
|
3324
|
+
function buildAbiErrorMessage(abiError, logs, metadata, reason) {
|
3325
|
+
const { pos, msg } = abiError;
|
3326
|
+
let errorMessage = "";
|
3327
|
+
const positionMessage = pos ? `
|
3328
|
+
|
3329
|
+
This error originated at ${JSON.stringify(pos, null, 2)}` : "";
|
3330
|
+
if (msg) {
|
3331
|
+
errorMessage = `A sway "panic" expression was invoked with the message: "${msg}".${positionMessage}`;
|
3332
|
+
} else {
|
3333
|
+
const value = logs[logs.length - 1];
|
3334
|
+
errorMessage = `A sway "panic" expression was invoked with the value: ${JSON.stringify(value)}.${positionMessage}`;
|
3335
|
+
}
|
3336
|
+
return new FuelError8(ErrorCode8.SCRIPT_REVERTED, errorMessage, {
|
3337
|
+
...metadata,
|
3338
|
+
reason
|
3339
|
+
});
|
3340
|
+
}
|
3341
|
+
__name(buildAbiErrorMessage, "buildAbiErrorMessage");
|
3342
|
+
function findErrorInAbis(statusReason, abis = []) {
|
3343
|
+
for (const abi of abis) {
|
3344
|
+
if (abi.errorCodes?.[statusReason]) {
|
3345
|
+
return abi.errorCodes[statusReason];
|
3325
3346
|
}
|
3326
3347
|
}
|
3348
|
+
return void 0;
|
3349
|
+
}
|
3350
|
+
__name(findErrorInAbis, "findErrorInAbis");
|
3351
|
+
var assembleRevertError = /* @__PURE__ */ __name((_receipts, logs, metadata, statusReason, abis) => {
|
3352
|
+
const match = statusReason.match(/Revert\((\d+)\)/);
|
3353
|
+
const reason = match?.[1] ?? statusReason;
|
3354
|
+
const reasonHex = bn7(reason).toHex();
|
3355
|
+
if (Object.values(SwaySignalErrors).includes(reasonHex)) {
|
3356
|
+
return assembleSignalErrorMessage(reasonHex, logs, metadata);
|
3357
|
+
}
|
3358
|
+
let abiError;
|
3359
|
+
if (abis) {
|
3360
|
+
const abisArr = [abis.main, ...Object.values(abis.otherContractsAbis)];
|
3361
|
+
abiError = findErrorInAbis(reason, abisArr);
|
3362
|
+
}
|
3363
|
+
if (abiError) {
|
3364
|
+
return buildAbiErrorMessage(abiError, logs, metadata, reason);
|
3365
|
+
}
|
3366
|
+
const errorMessage = `The transaction reverted with reason: ${reason}.`;
|
3327
3367
|
return new FuelError8(ErrorCode8.SCRIPT_REVERTED, errorMessage, {
|
3328
3368
|
...metadata,
|
3329
3369
|
reason
|
3330
3370
|
});
|
3331
3371
|
}, "assembleRevertError");
|
3332
3372
|
var extractTxError = /* @__PURE__ */ __name((params) => {
|
3333
|
-
const { receipts, statusReason, logs, groupedLogs } = params;
|
3373
|
+
const { receipts, statusReason, logs, groupedLogs, abis } = params;
|
3334
3374
|
const isPanic = receipts.some(({ type }) => type === ReceiptType4.Panic);
|
3335
3375
|
const isRevert = receipts.some(({ type }) => type === ReceiptType4.Revert);
|
3336
3376
|
const metadata = {
|
@@ -3344,7 +3384,7 @@ var extractTxError = /* @__PURE__ */ __name((params) => {
|
|
3344
3384
|
if (isPanic) {
|
3345
3385
|
return assemblePanicError(statusReason, metadata);
|
3346
3386
|
}
|
3347
|
-
return assembleRevertError(receipts, logs, metadata);
|
3387
|
+
return assembleRevertError(receipts, logs, metadata, statusReason, abis);
|
3348
3388
|
}, "extractTxError");
|
3349
3389
|
|
3350
3390
|
// src/providers/utils/merge-quantities.ts
|
@@ -4932,12 +4972,12 @@ var ResourceCache = class {
|
|
4932
4972
|
// src/providers/transaction-response/transaction-response.ts
|
4933
4973
|
import { ErrorCode as ErrorCode15, FuelError as FuelError17 } from "@fuel-ts/errors";
|
4934
4974
|
import { bn as bn17 } from "@fuel-ts/math";
|
4935
|
-
import { TransactionCoder as
|
4936
|
-
import { arrayify as
|
4975
|
+
import { TransactionCoder as TransactionCoder6, TxPointerCoder } from "@fuel-ts/transactions";
|
4976
|
+
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4937
4977
|
|
4938
4978
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
4939
4979
|
import { bn as bn16 } from "@fuel-ts/math";
|
4940
|
-
import { PolicyType as PolicyType3, TransactionCoder as
|
4980
|
+
import { PolicyType as PolicyType3, TransactionCoder as TransactionCoder5 } from "@fuel-ts/transactions";
|
4941
4981
|
import { DateTime, hexlify as hexlify16 } from "@fuel-ts/utils";
|
4942
4982
|
|
4943
4983
|
// src/providers/transaction-summary/calculate-tx-fee-for-summary.ts
|
@@ -5009,8 +5049,47 @@ var calculateTXFeeForSummary = /* @__PURE__ */ __name((params) => {
|
|
5009
5049
|
// src/providers/transaction-summary/operations.ts
|
5010
5050
|
import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
|
5011
5051
|
import { ErrorCode as ErrorCode13, FuelError as FuelError15 } from "@fuel-ts/errors";
|
5012
|
-
import { bn as bn14 } from "@fuel-ts/math";
|
5013
|
-
import { ReceiptType as ReceiptType5, TransactionType as TransactionType10 } from "@fuel-ts/transactions";
|
5052
|
+
import { bn as bn14, toBytes } from "@fuel-ts/math";
|
5053
|
+
import { ReceiptType as ReceiptType5, TransactionCoder as TransactionCoder4, TransactionType as TransactionType10 } from "@fuel-ts/transactions";
|
5054
|
+
import { arrayify as arrayify11, concat as concat3 } from "@fuel-ts/utils";
|
5055
|
+
|
5056
|
+
// src/providers/transaction-summary/call.ts
|
5057
|
+
import { StdStringCoder } from "@fuel-ts/abi-coder";
|
5058
|
+
import { Interface as Interface2 } from "@fuel-ts/abi-coder";
|
5059
|
+
var getFunctionCall = /* @__PURE__ */ __name(({
|
5060
|
+
abi,
|
5061
|
+
receipt,
|
5062
|
+
offset,
|
5063
|
+
scriptData
|
5064
|
+
}) => {
|
5065
|
+
const [functionSelector, argumentsOffset] = new StdStringCoder().decode(scriptData, offset);
|
5066
|
+
const abiInterface = new Interface2(abi);
|
5067
|
+
const functionFragment = abiInterface.getFunction(functionSelector);
|
5068
|
+
const inputs = functionFragment.jsonFn.inputs;
|
5069
|
+
let argumentsProvided;
|
5070
|
+
if (inputs.length) {
|
5071
|
+
const functionArgsBytes = scriptData.slice(argumentsOffset);
|
5072
|
+
const decodedArguments = functionFragment.decodeArguments(functionArgsBytes);
|
5073
|
+
argumentsProvided = inputs.reduce((prev, input, index) => {
|
5074
|
+
const value = decodedArguments?.[index];
|
5075
|
+
const name = input.name;
|
5076
|
+
if (name) {
|
5077
|
+
return {
|
5078
|
+
...prev,
|
5079
|
+
// reparse to remove bn
|
5080
|
+
[name]: JSON.parse(JSON.stringify(value))
|
5081
|
+
};
|
5082
|
+
}
|
5083
|
+
return prev;
|
5084
|
+
}, {});
|
5085
|
+
}
|
5086
|
+
return {
|
5087
|
+
functionSignature: functionFragment.signature,
|
5088
|
+
functionName: functionFragment.name,
|
5089
|
+
argumentsProvided,
|
5090
|
+
...receipt.amount?.isZero() ? {} : { amount: receipt.amount, assetId: receipt.assetId }
|
5091
|
+
};
|
5092
|
+
}, "getFunctionCall");
|
5014
5093
|
|
5015
5094
|
// src/providers/transaction-summary/input.ts
|
5016
5095
|
import { ErrorCode as ErrorCode12, FuelError as FuelError14 } from "@fuel-ts/errors";
|
@@ -5345,12 +5424,45 @@ function getWithdrawFromFuelOperations({
|
|
5345
5424
|
return withdrawFromFuelOperations;
|
5346
5425
|
}
|
5347
5426
|
__name(getWithdrawFromFuelOperations, "getWithdrawFromFuelOperations");
|
5348
|
-
function
|
5349
|
-
|
5350
|
-
|
5351
|
-
|
5427
|
+
function findBytesSegmentIndex(whole, segment) {
|
5428
|
+
for (let i = 0; i <= whole.length - segment.length; i++) {
|
5429
|
+
let match = true;
|
5430
|
+
for (let j = 0; j < segment.length; j++) {
|
5431
|
+
if (whole[i + j] !== segment[j]) {
|
5432
|
+
match = false;
|
5433
|
+
break;
|
5434
|
+
}
|
5435
|
+
}
|
5436
|
+
if (match) {
|
5437
|
+
return i;
|
5438
|
+
}
|
5352
5439
|
}
|
5353
|
-
return
|
5440
|
+
return -1;
|
5441
|
+
}
|
5442
|
+
__name(findBytesSegmentIndex, "findBytesSegmentIndex");
|
5443
|
+
function getContractCalls(contractInput, abiMap, receipt, scriptData) {
|
5444
|
+
const calls = [];
|
5445
|
+
const abi = abiMap?.[contractInput.contractID];
|
5446
|
+
if (!abi || !scriptData) {
|
5447
|
+
return calls;
|
5448
|
+
}
|
5449
|
+
const bytesSegment = concat3([
|
5450
|
+
arrayify11(receipt.to),
|
5451
|
+
// Contract ID (32 bytes)
|
5452
|
+
toBytes(receipt.param1.toHex(), 8),
|
5453
|
+
// Function selector offset (8 bytes)
|
5454
|
+
toBytes(receipt.param2.toHex(), 8)
|
5455
|
+
// Function args offset (8 bytes)
|
5456
|
+
]);
|
5457
|
+
const segmentIndex = findBytesSegmentIndex(scriptData, bytesSegment);
|
5458
|
+
const canDecodeFunctionCall = segmentIndex !== -1;
|
5459
|
+
if (!canDecodeFunctionCall) {
|
5460
|
+
return calls;
|
5461
|
+
}
|
5462
|
+
const offset = segmentIndex + bytesSegment.length;
|
5463
|
+
const call = getFunctionCall({ abi, receipt, offset, scriptData });
|
5464
|
+
calls.push(call);
|
5465
|
+
return calls;
|
5354
5466
|
}
|
5355
5467
|
__name(getContractCalls, "getContractCalls");
|
5356
5468
|
function getAssetsSent(receipt) {
|
@@ -5362,14 +5474,14 @@ function getAssetsSent(receipt) {
|
|
5362
5474
|
];
|
5363
5475
|
}
|
5364
5476
|
__name(getAssetsSent, "getAssetsSent");
|
5365
|
-
function processCallReceipt(receipt, contractInput, inputs, abiMap,
|
5477
|
+
function processCallReceipt(receipt, contractInput, inputs, abiMap, scriptData, baseAssetId) {
|
5366
5478
|
const assetId = receipt.assetId === ZeroBytes329 ? baseAssetId : receipt.assetId;
|
5367
5479
|
const input = getInputFromAssetId(inputs, assetId, assetId === baseAssetId);
|
5368
5480
|
if (!input) {
|
5369
5481
|
return [];
|
5370
5482
|
}
|
5371
5483
|
const inputAddress = getInputAccountAddress(input);
|
5372
|
-
const calls = getContractCalls(contractInput, abiMap, receipt,
|
5484
|
+
const calls = getContractCalls(contractInput, abiMap, receipt, scriptData);
|
5373
5485
|
return [
|
5374
5486
|
{
|
5375
5487
|
name: "Contract call" /* contractCall */,
|
@@ -5394,7 +5506,6 @@ function getContractCallOperations({
|
|
5394
5506
|
receipts,
|
5395
5507
|
abiMap,
|
5396
5508
|
rawPayload,
|
5397
|
-
maxInputs,
|
5398
5509
|
baseAssetId
|
5399
5510
|
}) {
|
5400
5511
|
const contractCallReceipts = getReceiptsCall(receipts);
|
@@ -5404,16 +5515,15 @@ function getContractCallOperations({
|
|
5404
5515
|
if (!contractInput) {
|
5405
5516
|
return [];
|
5406
5517
|
}
|
5518
|
+
let scriptData;
|
5519
|
+
if (rawPayload) {
|
5520
|
+
const [transaction] = new TransactionCoder4().decode(arrayify11(rawPayload), 0);
|
5521
|
+
if (transaction.type === TransactionType10.Script) {
|
5522
|
+
scriptData = arrayify11(transaction.scriptData);
|
5523
|
+
}
|
5524
|
+
}
|
5407
5525
|
return contractCallReceipts.filter((receipt) => receipt.to === contractInput.contractID).flatMap(
|
5408
|
-
(receipt) => processCallReceipt(
|
5409
|
-
receipt,
|
5410
|
-
contractInput,
|
5411
|
-
inputs,
|
5412
|
-
abiMap,
|
5413
|
-
rawPayload,
|
5414
|
-
maxInputs,
|
5415
|
-
baseAssetId
|
5416
|
-
)
|
5526
|
+
(receipt) => processCallReceipt(receipt, contractInput, inputs, abiMap, scriptData, baseAssetId)
|
5417
5527
|
);
|
5418
5528
|
});
|
5419
5529
|
}
|
@@ -5830,7 +5940,7 @@ function assemblePreConfirmationTransactionSummary(params) {
|
|
5830
5940
|
type = getTransactionTypeName(transaction.type);
|
5831
5941
|
tip = bn16(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
5832
5942
|
if (receipts) {
|
5833
|
-
const rawPayload = hexlify16(new
|
5943
|
+
const rawPayload = hexlify16(new TransactionCoder5().encode(transaction));
|
5834
5944
|
operations = getOperations({
|
5835
5945
|
transactionType: transaction.type,
|
5836
5946
|
inputs: transaction.inputs || [],
|
@@ -5876,7 +5986,7 @@ function assemblePreConfirmationTransactionSummary(params) {
|
|
5876
5986
|
__name(assemblePreConfirmationTransactionSummary, "assemblePreConfirmationTransactionSummary");
|
5877
5987
|
|
5878
5988
|
// src/providers/transaction-response/getAllDecodedLogs.ts
|
5879
|
-
import { Interface as
|
5989
|
+
import { Interface as Interface3, BigNumberCoder } from "@fuel-ts/abi-coder";
|
5880
5990
|
import { ZeroBytes32 as ZeroBytes3210 } from "@fuel-ts/address/configs";
|
5881
5991
|
import { ReceiptType as ReceiptType7 } from "@fuel-ts/transactions";
|
5882
5992
|
function getAllDecodedLogs(opts) {
|
@@ -5896,7 +6006,7 @@ function getAllDecodedLogs(opts) {
|
|
5896
6006
|
const isLogFromMainAbi = receipt.id === ZeroBytes3210 || mainContract === receipt.id;
|
5897
6007
|
const isDecodable = isLogFromMainAbi || externalAbis[receipt.id];
|
5898
6008
|
if (isDecodable) {
|
5899
|
-
const interfaceToUse = isLogFromMainAbi ? new
|
6009
|
+
const interfaceToUse = isLogFromMainAbi ? new Interface3(mainAbi) : new Interface3(externalAbis[receipt.id]);
|
5900
6010
|
const data = receipt.type === ReceiptType7.Log ? new BigNumberCoder("u64").encode(receipt.ra) : receipt.data;
|
5901
6011
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
|
5902
6012
|
logs.push(decodedLog);
|
@@ -5996,8 +6106,8 @@ var TransactionResponse = class _TransactionResponse {
|
|
5996
6106
|
}
|
5997
6107
|
const gqlTransaction = this.gqlTransaction ?? await this.fetch();
|
5998
6108
|
const { rawPayload } = gqlTransaction;
|
5999
|
-
const bytes =
|
6000
|
-
const [tx] = new
|
6109
|
+
const bytes = arrayify12(rawPayload);
|
6110
|
+
const [tx] = new TransactionCoder6().decode(bytes, 0);
|
6001
6111
|
return {
|
6002
6112
|
tx,
|
6003
6113
|
bytes
|
@@ -6184,6 +6294,7 @@ var TransactionResponse = class _TransactionResponse {
|
|
6184
6294
|
...transactionSummary
|
6185
6295
|
};
|
6186
6296
|
let { logs, groupedLogs } = { logs: [], groupedLogs: {} };
|
6297
|
+
let abis;
|
6187
6298
|
if (this.abis) {
|
6188
6299
|
({ logs, groupedLogs } = getAllDecodedLogs({
|
6189
6300
|
receipts: transactionSummary.receipts,
|
@@ -6192,6 +6303,7 @@ var TransactionResponse = class _TransactionResponse {
|
|
6192
6303
|
}));
|
6193
6304
|
transactionResult.logs = logs;
|
6194
6305
|
transactionResult.groupedLogs = groupedLogs;
|
6306
|
+
abis = this.abis;
|
6195
6307
|
}
|
6196
6308
|
const { receipts } = transactionResult;
|
6197
6309
|
const status = this.getTransactionStatus();
|
@@ -6201,7 +6313,8 @@ var TransactionResponse = class _TransactionResponse {
|
|
6201
6313
|
receipts,
|
6202
6314
|
statusReason: reason,
|
6203
6315
|
logs,
|
6204
|
-
groupedLogs
|
6316
|
+
groupedLogs,
|
6317
|
+
abis
|
6205
6318
|
});
|
6206
6319
|
}
|
6207
6320
|
return transactionResult;
|
@@ -6263,7 +6376,7 @@ var TransactionResponse = class _TransactionResponse {
|
|
6263
6376
|
};
|
6264
6377
|
|
6265
6378
|
// src/providers/transaction-response/getDecodedLogs.ts
|
6266
|
-
import { Interface as
|
6379
|
+
import { Interface as Interface4, BigNumberCoder as BigNumberCoder2 } from "@fuel-ts/abi-coder";
|
6267
6380
|
import { ZeroBytes32 as ZeroBytes3211 } from "@fuel-ts/address/configs";
|
6268
6381
|
import { ReceiptType as ReceiptType8 } from "@fuel-ts/transactions";
|
6269
6382
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
@@ -6279,7 +6392,7 @@ function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
|
6279
6392
|
const isLogFromMainAbi = receipt.id === ZeroBytes3211 || mainContract === receipt.id;
|
6280
6393
|
const isDecodable = isLogFromMainAbi || externalAbis[receipt.id];
|
6281
6394
|
if (isDecodable) {
|
6282
|
-
const interfaceToUse = isLogFromMainAbi ? new
|
6395
|
+
const interfaceToUse = isLogFromMainAbi ? new Interface4(mainAbi) : new Interface4(externalAbis[receipt.id]);
|
6283
6396
|
const data = receipt.type === ReceiptType8.Log ? new BigNumberCoder2("u64").encode(receipt.ra) : receipt.data;
|
6284
6397
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
|
6285
6398
|
logs.push(decodedLog);
|
@@ -7666,7 +7779,7 @@ var Provider = class _Provider {
|
|
7666
7779
|
},
|
7667
7780
|
transactionIds: block.transactions.map((tx) => tx.id),
|
7668
7781
|
transactions: block.transactions.map(
|
7669
|
-
(tx) => new
|
7782
|
+
(tx) => new TransactionCoder7().decode(arrayify13(tx.rawPayload), 0)?.[0]
|
7670
7783
|
)
|
7671
7784
|
};
|
7672
7785
|
}
|
@@ -7682,8 +7795,8 @@ var Provider = class _Provider {
|
|
7682
7795
|
return null;
|
7683
7796
|
}
|
7684
7797
|
try {
|
7685
|
-
return new
|
7686
|
-
|
7798
|
+
return new TransactionCoder7().decode(
|
7799
|
+
arrayify13(transaction.rawPayload),
|
7687
7800
|
0
|
7688
7801
|
)?.[0];
|
7689
7802
|
} catch (error) {
|
@@ -7708,10 +7821,10 @@ var Provider = class _Provider {
|
|
7708
7821
|
paginationLimit: TRANSACTIONS_PAGE_SIZE_LIMIT
|
7709
7822
|
})
|
7710
7823
|
});
|
7711
|
-
const coder = new
|
7824
|
+
const coder = new TransactionCoder7();
|
7712
7825
|
const transactions = edges.map(({ node: { rawPayload } }) => {
|
7713
7826
|
try {
|
7714
|
-
return coder.decode(
|
7827
|
+
return coder.decode(arrayify13(rawPayload), 0)[0];
|
7715
7828
|
} catch (error) {
|
7716
7829
|
if (error instanceof FuelError19 && error.code === ErrorCode17.UNSUPPORTED_TRANSACTION_TYPE) {
|
7717
7830
|
console.warn("Unsupported transaction type encountered");
|
@@ -8082,18 +8195,21 @@ var Provider = class _Provider {
|
|
8082
8195
|
extractDryRunError(transactionRequest, receipts, reason) {
|
8083
8196
|
let logs = [];
|
8084
8197
|
let groupedLogs = {};
|
8198
|
+
let abis;
|
8085
8199
|
if (transactionRequest.type === TransactionType11.Script && transactionRequest.abis) {
|
8086
8200
|
({ logs, groupedLogs } = getAllDecodedLogs({
|
8087
8201
|
receipts,
|
8088
8202
|
mainAbi: transactionRequest.abis.main,
|
8089
8203
|
externalAbis: transactionRequest.abis.otherContractsAbis
|
8090
8204
|
}));
|
8205
|
+
abis = transactionRequest.abis;
|
8091
8206
|
}
|
8092
8207
|
return extractTxError({
|
8093
8208
|
logs,
|
8094
8209
|
groupedLogs,
|
8095
8210
|
receipts,
|
8096
|
-
statusReason: reason
|
8211
|
+
statusReason: reason,
|
8212
|
+
abis
|
8097
8213
|
});
|
8098
8214
|
}
|
8099
8215
|
/**
|
@@ -8164,8 +8280,8 @@ var Provider = class _Provider {
|
|
8164
8280
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
8165
8281
|
import { ErrorCode as ErrorCode18, FuelError as FuelError20 } from "@fuel-ts/errors";
|
8166
8282
|
import { bn as bn19 } from "@fuel-ts/math";
|
8167
|
-
import { TransactionCoder as
|
8168
|
-
import { arrayify as
|
8283
|
+
import { TransactionCoder as TransactionCoder8 } from "@fuel-ts/transactions";
|
8284
|
+
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
8169
8285
|
async function getTransactionSummary(params) {
|
8170
8286
|
const { id, provider, abiMap } = params;
|
8171
8287
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
@@ -8177,8 +8293,8 @@ async function getTransactionSummary(params) {
|
|
8177
8293
|
`Transaction not found for given id: ${id}.`
|
8178
8294
|
);
|
8179
8295
|
}
|
8180
|
-
const [decodedTransaction] = new
|
8181
|
-
|
8296
|
+
const [decodedTransaction] = new TransactionCoder8().decode(
|
8297
|
+
arrayify14(gqlTransaction.rawPayload),
|
8182
8298
|
0
|
8183
8299
|
);
|
8184
8300
|
let txReceipts = [];
|
@@ -8200,7 +8316,7 @@ async function getTransactionSummary(params) {
|
|
8200
8316
|
id: gqlTransaction.id,
|
8201
8317
|
receipts,
|
8202
8318
|
transaction: decodedTransaction,
|
8203
|
-
transactionBytes:
|
8319
|
+
transactionBytes: arrayify14(gqlTransaction.rawPayload),
|
8204
8320
|
gqlTransactionStatus: gqlTransaction.status,
|
8205
8321
|
gasPerByte: bn19(gasPerByte),
|
8206
8322
|
gasPriceFactor: bn19(gasPriceFactor),
|
@@ -8266,7 +8382,7 @@ async function getTransactionsSummaries(params) {
|
|
8266
8382
|
const transactions = edges.map((edge) => {
|
8267
8383
|
const { node: gqlTransaction } = edge;
|
8268
8384
|
const { id, rawPayload, status } = gqlTransaction;
|
8269
|
-
const [decodedTransaction] = new
|
8385
|
+
const [decodedTransaction] = new TransactionCoder8().decode(arrayify14(rawPayload), 0);
|
8270
8386
|
let txReceipts = [];
|
8271
8387
|
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
8272
8388
|
txReceipts = gqlTransaction.status.receipts;
|
@@ -8276,7 +8392,7 @@ async function getTransactionsSummaries(params) {
|
|
8276
8392
|
id,
|
8277
8393
|
receipts,
|
8278
8394
|
transaction: decodedTransaction,
|
8279
|
-
transactionBytes:
|
8395
|
+
transactionBytes: arrayify14(rawPayload),
|
8280
8396
|
gqlTransactionStatus: status,
|
8281
8397
|
abiMap,
|
8282
8398
|
gasPerByte,
|
@@ -8301,8 +8417,8 @@ __name(getTransactionsSummaries, "getTransactionsSummaries");
|
|
8301
8417
|
|
8302
8418
|
// src/providers/transaction-summary/assemble-transaction-summary-from-serialized.ts
|
8303
8419
|
import { bn as bn20 } from "@fuel-ts/math";
|
8304
|
-
import { TransactionCoder as
|
8305
|
-
import { arrayify as
|
8420
|
+
import { TransactionCoder as TransactionCoder9 } from "@fuel-ts/transactions";
|
8421
|
+
import { arrayify as arrayify15 } from "@fuel-ts/utils";
|
8306
8422
|
var assembleTransactionSummaryFromJson = /* @__PURE__ */ __name(async (opts) => {
|
8307
8423
|
const { provider, transactionSummary } = opts;
|
8308
8424
|
const { id, transactionBytes, gasPrice, receipts } = transactionSummary;
|
@@ -8314,8 +8430,8 @@ var assembleTransactionSummaryFromJson = /* @__PURE__ */ __name(async (opts) =>
|
|
8314
8430
|
gasCosts
|
8315
8431
|
}
|
8316
8432
|
} = await provider.getChain();
|
8317
|
-
const deserializedTransactionBytes =
|
8318
|
-
const [transaction] = new
|
8433
|
+
const deserializedTransactionBytes = arrayify15(transactionBytes);
|
8434
|
+
const [transaction] = new TransactionCoder9().decode(deserializedTransactionBytes, 0);
|
8319
8435
|
return assembleTransactionSummary({
|
8320
8436
|
id,
|
8321
8437
|
transaction,
|
@@ -8379,15 +8495,15 @@ var AbstractAccount = class {
|
|
8379
8495
|
// src/utils/formatTransferToContractScriptData.ts
|
8380
8496
|
import { ASSET_ID_LEN, BigNumberCoder as BigNumberCoder3, CONTRACT_ID_LEN, WORD_SIZE } from "@fuel-ts/abi-coder";
|
8381
8497
|
import { Address as Address3 } from "@fuel-ts/address";
|
8382
|
-
import { arrayify as
|
8498
|
+
import { arrayify as arrayify16, concat as concat4 } from "@fuel-ts/utils";
|
8383
8499
|
import * as asm from "@fuels/vm-asm";
|
8384
8500
|
var formatTransferToContractScriptData = /* @__PURE__ */ __name((transferParams) => {
|
8385
8501
|
const numberCoder = new BigNumberCoder3("u64");
|
8386
8502
|
return transferParams.reduce((acc, transferParam) => {
|
8387
8503
|
const { assetId, amount, contractId } = transferParam;
|
8388
8504
|
const encoded = numberCoder.encode(amount);
|
8389
|
-
const scriptData =
|
8390
|
-
return
|
8505
|
+
const scriptData = concat4([new Address3(contractId).toBytes(), encoded, arrayify16(assetId)]);
|
8506
|
+
return concat4([acc, scriptData]);
|
8391
8507
|
}, new Uint8Array());
|
8392
8508
|
}, "formatTransferToContractScriptData");
|
8393
8509
|
var assembleTransferToContractScript = /* @__PURE__ */ __name(async (transferParams) => {
|
@@ -8396,7 +8512,7 @@ var assembleTransferToContractScript = /* @__PURE__ */ __name(async (transferPar
|
|
8396
8512
|
let script = new Uint8Array();
|
8397
8513
|
transferParams.forEach((_, i) => {
|
8398
8514
|
const offset = (CONTRACT_ID_LEN + WORD_SIZE + ASSET_ID_LEN) * i;
|
8399
|
-
script =
|
8515
|
+
script = concat4([
|
8400
8516
|
script,
|
8401
8517
|
// Load ScriptData into register 0x10.
|
8402
8518
|
asm.gtf(16, 0, asm.GTFArgs.ScriptData).to_bytes(),
|
@@ -8412,7 +8528,7 @@ var assembleTransferToContractScript = /* @__PURE__ */ __name(async (transferPar
|
|
8412
8528
|
asm.tr(17, 19, 20).to_bytes()
|
8413
8529
|
]);
|
8414
8530
|
});
|
8415
|
-
script =
|
8531
|
+
script = concat4([script, asm.ret(1).to_bytes()]);
|
8416
8532
|
return { script, scriptData };
|
8417
8533
|
}, "assembleTransferToContractScript");
|
8418
8534
|
|
@@ -8800,14 +8916,14 @@ var Account = class extends AbstractAccount {
|
|
8800
8916
|
*/
|
8801
8917
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
8802
8918
|
const recipientAddress = new Address4(recipient);
|
8803
|
-
const recipientDataArray =
|
8919
|
+
const recipientDataArray = arrayify17(
|
8804
8920
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
8805
8921
|
);
|
8806
|
-
const amountDataArray =
|
8922
|
+
const amountDataArray = arrayify17(
|
8807
8923
|
"0x".concat(bn21(amount).toHex().substring(2).padStart(16, "0"))
|
8808
8924
|
);
|
8809
8925
|
const script = new Uint8Array([
|
8810
|
-
...
|
8926
|
+
...arrayify17(withdrawScript.bytes),
|
8811
8927
|
...recipientDataArray,
|
8812
8928
|
...amountDataArray
|
8813
8929
|
]);
|
@@ -9029,14 +9145,23 @@ var Account = class extends AbstractAccount {
|
|
9029
9145
|
* @param transactionRequestLike - The transaction request to sign.
|
9030
9146
|
* @returns A promise that resolves to the signature of the transaction.
|
9031
9147
|
*/
|
9032
|
-
async signTransaction(transactionRequestLike) {
|
9148
|
+
async signTransaction(transactionRequestLike, connectorOptions = {}) {
|
9033
9149
|
if (!this._connector) {
|
9034
9150
|
throw new FuelError21(
|
9035
9151
|
ErrorCode19.MISSING_CONNECTOR,
|
9036
9152
|
"A connector is required to sign transactions."
|
9037
9153
|
);
|
9038
9154
|
}
|
9039
|
-
|
9155
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9156
|
+
const { transactionRequest: requestToSign, connectorsSendTxParams } = await this.setTransactionStateForConnectors({
|
9157
|
+
transactionRequest,
|
9158
|
+
connectorOptions
|
9159
|
+
});
|
9160
|
+
return this._connector.signTransaction(
|
9161
|
+
this.address.toString(),
|
9162
|
+
requestToSign,
|
9163
|
+
connectorsSendTxParams
|
9164
|
+
);
|
9040
9165
|
}
|
9041
9166
|
/**
|
9042
9167
|
* Sends a transaction to the network.
|
@@ -9046,24 +9171,16 @@ var Account = class extends AbstractAccount {
|
|
9046
9171
|
* @returns A promise that resolves to the transaction response.
|
9047
9172
|
*/
|
9048
9173
|
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, ...connectorOptions } = {}) {
|
9049
|
-
|
9174
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9050
9175
|
if (this._connector) {
|
9051
|
-
const
|
9052
|
-
|
9053
|
-
|
9054
|
-
|
9055
|
-
skipCustomFee,
|
9056
|
-
provider: {
|
9057
|
-
url: this.provider.url,
|
9058
|
-
cache: await serializeProviderCache(this.provider)
|
9059
|
-
},
|
9060
|
-
transactionState: transactionRequest.flag.state,
|
9061
|
-
transactionSummary: await this.prepareTransactionSummary(transactionRequest)
|
9062
|
-
};
|
9176
|
+
const response = await this.setTransactionStateForConnectors({
|
9177
|
+
transactionRequest,
|
9178
|
+
connectorOptions
|
9179
|
+
});
|
9063
9180
|
const transaction = await this._connector.sendTransaction(
|
9064
9181
|
this.address.toString(),
|
9065
|
-
transactionRequest,
|
9066
|
-
|
9182
|
+
response.transactionRequest,
|
9183
|
+
response.connectorsSendTxParams
|
9067
9184
|
);
|
9068
9185
|
return typeof transaction === "string" ? this.provider.getTransactionResponse(transaction) : transaction;
|
9069
9186
|
}
|
@@ -9197,6 +9314,23 @@ var Account = class extends AbstractAccount {
|
|
9197
9314
|
);
|
9198
9315
|
}
|
9199
9316
|
}
|
9317
|
+
/** @hidden * */
|
9318
|
+
async setTransactionStateForConnectors(params) {
|
9319
|
+
const { transactionRequest: requestToPrepare, connectorOptions } = params;
|
9320
|
+
const { onBeforeSend, skipCustomFee = false } = connectorOptions;
|
9321
|
+
const transactionRequest = await this.prepareTransactionForSend(requestToPrepare);
|
9322
|
+
const connectorsSendTxParams = {
|
9323
|
+
onBeforeSend,
|
9324
|
+
skipCustomFee,
|
9325
|
+
provider: {
|
9326
|
+
url: this.provider.url,
|
9327
|
+
cache: await serializeProviderCache(this.provider)
|
9328
|
+
},
|
9329
|
+
transactionState: requestToPrepare.flag.state,
|
9330
|
+
transactionSummary: await this.prepareTransactionSummary(requestToPrepare)
|
9331
|
+
};
|
9332
|
+
return { transactionRequest, connectorsSendTxParams };
|
9333
|
+
}
|
9200
9334
|
};
|
9201
9335
|
|
9202
9336
|
// src/wallet/base-wallet-unlocked.ts
|
@@ -9207,8 +9341,8 @@ import { hexlify as hexlify21 } from "@fuel-ts/utils";
|
|
9207
9341
|
import { Address as Address5 } from "@fuel-ts/address";
|
9208
9342
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
9209
9343
|
import { hash as hash2 } from "@fuel-ts/hasher";
|
9210
|
-
import { toBytes } from "@fuel-ts/math";
|
9211
|
-
import { hexlify as hexlify19, concat as
|
9344
|
+
import { toBytes as toBytes2 } from "@fuel-ts/math";
|
9345
|
+
import { hexlify as hexlify19, concat as concat5, arrayify as arrayify18 } from "@fuel-ts/utils";
|
9212
9346
|
import { secp256k1 } from "@noble/curves/secp256k1";
|
9213
9347
|
var Signer = class _Signer {
|
9214
9348
|
static {
|
@@ -9230,7 +9364,7 @@ var Signer = class _Signer {
|
|
9230
9364
|
privateKey = `0x${privateKey}`;
|
9231
9365
|
}
|
9232
9366
|
}
|
9233
|
-
const privateKeyBytes =
|
9367
|
+
const privateKeyBytes = toBytes2(privateKey, 32);
|
9234
9368
|
this.privateKey = hexlify19(privateKeyBytes);
|
9235
9369
|
this.publicKey = hexlify19(secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
9236
9370
|
this.compressedPublicKey = hexlify19(secp256k1.getPublicKey(privateKeyBytes, true));
|
@@ -9247,11 +9381,11 @@ var Signer = class _Signer {
|
|
9247
9381
|
* @returns hashed signature
|
9248
9382
|
*/
|
9249
9383
|
sign(data) {
|
9250
|
-
const signature = secp256k1.sign(
|
9251
|
-
const r =
|
9252
|
-
const s =
|
9384
|
+
const signature = secp256k1.sign(arrayify18(data), arrayify18(this.privateKey));
|
9385
|
+
const r = toBytes2(`0x${signature.r.toString(16)}`, 32);
|
9386
|
+
const s = toBytes2(`0x${signature.s.toString(16)}`, 32);
|
9253
9387
|
s[0] |= (signature.recovery || 0) << 7;
|
9254
|
-
return hexlify19(
|
9388
|
+
return hexlify19(concat5([r, s]));
|
9255
9389
|
}
|
9256
9390
|
/**
|
9257
9391
|
* Add point on the current elliptic curve
|
@@ -9260,8 +9394,8 @@ var Signer = class _Signer {
|
|
9260
9394
|
* @returns compressed point on the curve
|
9261
9395
|
*/
|
9262
9396
|
addPoint(point) {
|
9263
|
-
const p0 = secp256k1.ProjectivePoint.fromHex(
|
9264
|
-
const p1 = secp256k1.ProjectivePoint.fromHex(
|
9397
|
+
const p0 = secp256k1.ProjectivePoint.fromHex(arrayify18(this.compressedPublicKey));
|
9398
|
+
const p1 = secp256k1.ProjectivePoint.fromHex(arrayify18(point));
|
9265
9399
|
const result = p0.add(p1);
|
9266
9400
|
return `0x${result.toHex(true)}`;
|
9267
9401
|
}
|
@@ -9273,7 +9407,7 @@ var Signer = class _Signer {
|
|
9273
9407
|
* @returns public key from signature from the
|
9274
9408
|
*/
|
9275
9409
|
static recoverPublicKey(data, signature) {
|
9276
|
-
const signedMessageBytes =
|
9410
|
+
const signedMessageBytes = arrayify18(signature);
|
9277
9411
|
const r = signedMessageBytes.slice(0, 32);
|
9278
9412
|
const s = signedMessageBytes.slice(32, 64);
|
9279
9413
|
const recoveryParam = (s[0] & 128) >> 7;
|
@@ -9281,7 +9415,7 @@ var Signer = class _Signer {
|
|
9281
9415
|
const sig = new secp256k1.Signature(BigInt(hexlify19(r)), BigInt(hexlify19(s))).addRecoveryBit(
|
9282
9416
|
recoveryParam
|
9283
9417
|
);
|
9284
|
-
const publicKey = sig.recoverPublicKey(
|
9418
|
+
const publicKey = sig.recoverPublicKey(arrayify18(data)).toRawBytes(false).slice(1);
|
9285
9419
|
return hexlify19(publicKey);
|
9286
9420
|
}
|
9287
9421
|
/**
|
@@ -9301,7 +9435,7 @@ var Signer = class _Signer {
|
|
9301
9435
|
* @returns random 32-byte hashed
|
9302
9436
|
*/
|
9303
9437
|
static generatePrivateKey(entropy) {
|
9304
|
-
return entropy ? hash2(
|
9438
|
+
return entropy ? hash2(concat5([randomBytes3(32), arrayify18(entropy)])) : randomBytes3(32);
|
9305
9439
|
}
|
9306
9440
|
/**
|
9307
9441
|
* Extended publicKey from a compact publicKey
|
@@ -9310,7 +9444,7 @@ var Signer = class _Signer {
|
|
9310
9444
|
* @returns extended publicKey
|
9311
9445
|
*/
|
9312
9446
|
static extendPublicKey(publicKey) {
|
9313
|
-
const point = secp256k1.ProjectivePoint.fromHex(
|
9447
|
+
const point = secp256k1.ProjectivePoint.fromHex(arrayify18(publicKey));
|
9314
9448
|
return hexlify19(point.toRawBytes(false).slice(1));
|
9315
9449
|
}
|
9316
9450
|
};
|
@@ -9547,14 +9681,14 @@ var BaseWalletUnlocked = class extends Account {
|
|
9547
9681
|
import { computeHmac as computeHmac2, ripemd160 } from "@fuel-ts/crypto";
|
9548
9682
|
import { ErrorCode as ErrorCode23, FuelError as FuelError25 } from "@fuel-ts/errors";
|
9549
9683
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
9550
|
-
import { bn as bn22, toBytes as
|
9551
|
-
import { arrayify as
|
9684
|
+
import { bn as bn22, toBytes as toBytes3, toHex } from "@fuel-ts/math";
|
9685
|
+
import { arrayify as arrayify21, hexlify as hexlify23, concat as concat7, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58 } from "@fuel-ts/utils";
|
9552
9686
|
|
9553
9687
|
// src/mnemonic/mnemonic.ts
|
9554
9688
|
import { randomBytes as randomBytes5, pbkdf2, computeHmac } from "@fuel-ts/crypto";
|
9555
9689
|
import { ErrorCode as ErrorCode22, FuelError as FuelError24 } from "@fuel-ts/errors";
|
9556
9690
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
9557
|
-
import { arrayify as
|
9691
|
+
import { arrayify as arrayify20, hexlify as hexlify22, concat as concat6, dataSlice, encodeBase58, toUtf8Bytes } from "@fuel-ts/utils";
|
9558
9692
|
|
9559
9693
|
// src/wordlists/words/english.ts
|
9560
9694
|
var english = [
|
@@ -11617,7 +11751,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
11617
11751
|
// src/mnemonic/utils.ts
|
11618
11752
|
import { ErrorCode as ErrorCode21, FuelError as FuelError23 } from "@fuel-ts/errors";
|
11619
11753
|
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
11620
|
-
import { arrayify as
|
11754
|
+
import { arrayify as arrayify19 } from "@fuel-ts/utils";
|
11621
11755
|
function getLowerMask(bits) {
|
11622
11756
|
return (1 << bits) - 1;
|
11623
11757
|
}
|
@@ -11656,7 +11790,7 @@ function entropyToMnemonicIndices(entropy) {
|
|
11656
11790
|
}
|
11657
11791
|
}
|
11658
11792
|
const checksumBits = entropy.length / 4;
|
11659
|
-
const checksum =
|
11793
|
+
const checksum = arrayify19(sha2562(entropy))[0] & getUpperMask(checksumBits);
|
11660
11794
|
indices[indices.length - 1] <<= checksumBits;
|
11661
11795
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
11662
11796
|
return indices;
|
@@ -11664,7 +11798,7 @@ function entropyToMnemonicIndices(entropy) {
|
|
11664
11798
|
__name(entropyToMnemonicIndices, "entropyToMnemonicIndices");
|
11665
11799
|
function mnemonicWordsToEntropy(words, wordlist) {
|
11666
11800
|
const size = Math.ceil(11 * words.length / 8);
|
11667
|
-
const entropy =
|
11801
|
+
const entropy = arrayify19(new Uint8Array(size));
|
11668
11802
|
let offset = 0;
|
11669
11803
|
for (let i = 0; i < words.length; i += 1) {
|
11670
11804
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -11684,7 +11818,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
11684
11818
|
const entropyBits = 32 * words.length / 3;
|
11685
11819
|
const checksumBits = words.length / 3;
|
11686
11820
|
const checksumMask = getUpperMask(checksumBits);
|
11687
|
-
const checksum =
|
11821
|
+
const checksum = arrayify19(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
11688
11822
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
11689
11823
|
throw new FuelError23(
|
11690
11824
|
ErrorCode21.INVALID_CHECKSUM,
|
@@ -11774,7 +11908,7 @@ var Mnemonic = class _Mnemonic {
|
|
11774
11908
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
11775
11909
|
*/
|
11776
11910
|
static entropyToMnemonic(entropy, wordlist = english) {
|
11777
|
-
const entropyBytes =
|
11911
|
+
const entropyBytes = arrayify20(entropy);
|
11778
11912
|
assertWordList(wordlist);
|
11779
11913
|
assertEntropy(entropyBytes);
|
11780
11914
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -11843,14 +11977,14 @@ var Mnemonic = class _Mnemonic {
|
|
11843
11977
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
11844
11978
|
*/
|
11845
11979
|
static masterKeysFromSeed(seed) {
|
11846
|
-
const seedArray =
|
11980
|
+
const seedArray = arrayify20(seed);
|
11847
11981
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
11848
11982
|
throw new FuelError24(
|
11849
11983
|
ErrorCode22.INVALID_SEED,
|
11850
11984
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
11851
11985
|
);
|
11852
11986
|
}
|
11853
|
-
return
|
11987
|
+
return arrayify20(computeHmac("sha512", MasterSecret, seedArray));
|
11854
11988
|
}
|
11855
11989
|
/**
|
11856
11990
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -11861,22 +11995,22 @@ var Mnemonic = class _Mnemonic {
|
|
11861
11995
|
*/
|
11862
11996
|
static seedToExtendedKey(seed, testnet = false) {
|
11863
11997
|
const masterKey = _Mnemonic.masterKeysFromSeed(seed);
|
11864
|
-
const prefix =
|
11998
|
+
const prefix = arrayify20(testnet ? TestnetPRV : MainnetPRV);
|
11865
11999
|
const depth = "0x00";
|
11866
12000
|
const fingerprint = "0x00000000";
|
11867
12001
|
const index = "0x00000000";
|
11868
12002
|
const chainCode = masterKey.slice(32);
|
11869
12003
|
const privateKey = masterKey.slice(0, 32);
|
11870
|
-
const extendedKey =
|
12004
|
+
const extendedKey = concat6([
|
11871
12005
|
prefix,
|
11872
12006
|
depth,
|
11873
12007
|
fingerprint,
|
11874
12008
|
index,
|
11875
12009
|
chainCode,
|
11876
|
-
|
12010
|
+
concat6(["0x00", privateKey])
|
11877
12011
|
]);
|
11878
12012
|
const checksum = dataSlice(sha2563(sha2563(extendedKey)), 0, 4);
|
11879
|
-
return encodeBase58(
|
12013
|
+
return encodeBase58(concat6([extendedKey, checksum]));
|
11880
12014
|
}
|
11881
12015
|
/**
|
11882
12016
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -11891,7 +12025,7 @@ var Mnemonic = class _Mnemonic {
|
|
11891
12025
|
* @returns A randomly generated mnemonic
|
11892
12026
|
*/
|
11893
12027
|
static generate(size = 32, extraEntropy = "") {
|
11894
|
-
const entropy = extraEntropy ? sha2563(
|
12028
|
+
const entropy = extraEntropy ? sha2563(concat6([randomBytes5(size), arrayify20(extraEntropy)])) : randomBytes5(size);
|
11895
12029
|
return _Mnemonic.entropyToMnemonic(entropy);
|
11896
12030
|
}
|
11897
12031
|
};
|
@@ -11904,7 +12038,7 @@ var MainnetPUB = hexlify23("0x0488b21e");
|
|
11904
12038
|
var TestnetPRV2 = hexlify23("0x04358394");
|
11905
12039
|
var TestnetPUB = hexlify23("0x043587cf");
|
11906
12040
|
function base58check(data) {
|
11907
|
-
return encodeBase582(
|
12041
|
+
return encodeBase582(concat7([data, dataSlice2(sha2564(sha2564(data)), 0, 4)]));
|
11908
12042
|
}
|
11909
12043
|
__name(base58check, "base58check");
|
11910
12044
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
@@ -11984,9 +12118,9 @@ var HDWallet = class _HDWallet {
|
|
11984
12118
|
* @returns A new instance of HDWallet on the derived index
|
11985
12119
|
*/
|
11986
12120
|
deriveIndex(index) {
|
11987
|
-
const privateKey = this.privateKey &&
|
11988
|
-
const publicKey =
|
11989
|
-
const chainCode =
|
12121
|
+
const privateKey = this.privateKey && arrayify21(this.privateKey);
|
12122
|
+
const publicKey = arrayify21(this.publicKey);
|
12123
|
+
const chainCode = arrayify21(this.chainCode);
|
11990
12124
|
const data = new Uint8Array(37);
|
11991
12125
|
if (index & HARDENED_INDEX) {
|
11992
12126
|
if (!privateKey) {
|
@@ -11997,10 +12131,10 @@ var HDWallet = class _HDWallet {
|
|
11997
12131
|
}
|
11998
12132
|
data.set(privateKey, 1);
|
11999
12133
|
} else {
|
12000
|
-
data.set(
|
12134
|
+
data.set(arrayify21(this.publicKey));
|
12001
12135
|
}
|
12002
|
-
data.set(
|
12003
|
-
const bytes =
|
12136
|
+
data.set(toBytes3(index, 4), 33);
|
12137
|
+
const bytes = arrayify21(computeHmac2("sha512", chainCode, data));
|
12004
12138
|
const IL = bytes.slice(0, 32);
|
12005
12139
|
const IR = bytes.slice(32);
|
12006
12140
|
if (privateKey) {
|
@@ -12053,8 +12187,8 @@ var HDWallet = class _HDWallet {
|
|
12053
12187
|
const parentFingerprint = this.parentFingerprint;
|
12054
12188
|
const index = toHex(this.index, 4);
|
12055
12189
|
const chainCode = this.chainCode;
|
12056
|
-
const key = this.privateKey != null && !isPublic ?
|
12057
|
-
const extendedKey =
|
12190
|
+
const key = this.privateKey != null && !isPublic ? concat7(["0x00", this.privateKey]) : this.publicKey;
|
12191
|
+
const extendedKey = arrayify21(concat7([prefix, depth, parentFingerprint, index, chainCode, key]));
|
12058
12192
|
return base58check(extendedKey);
|
12059
12193
|
}
|
12060
12194
|
/**
|
@@ -12066,13 +12200,13 @@ var HDWallet = class _HDWallet {
|
|
12066
12200
|
static fromSeed(seed) {
|
12067
12201
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
12068
12202
|
return new _HDWallet({
|
12069
|
-
chainCode:
|
12070
|
-
privateKey:
|
12203
|
+
chainCode: arrayify21(masterKey.slice(32)),
|
12204
|
+
privateKey: arrayify21(masterKey.slice(0, 32))
|
12071
12205
|
});
|
12072
12206
|
}
|
12073
12207
|
static fromExtendedKey(extendedKey) {
|
12074
|
-
const decoded = hexlify23(
|
12075
|
-
const bytes =
|
12208
|
+
const decoded = hexlify23(toBytes3(decodeBase58(extendedKey)));
|
12209
|
+
const bytes = arrayify21(decoded);
|
12076
12210
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
12077
12211
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
12078
12212
|
throw new FuelError25(ErrorCode23.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -12699,19 +12833,19 @@ var StorageAbstract = class {
|
|
12699
12833
|
};
|
12700
12834
|
|
12701
12835
|
// src/predicate/predicate.ts
|
12702
|
-
import { Interface as
|
12836
|
+
import { Interface as Interface5 } from "@fuel-ts/abi-coder";
|
12703
12837
|
import { Address as Address10 } from "@fuel-ts/address";
|
12704
12838
|
import { ErrorCode as ErrorCode29, FuelError as FuelError31 } from "@fuel-ts/errors";
|
12705
|
-
import { arrayify as
|
12839
|
+
import { arrayify as arrayify24, hexlify as hexlify25 } from "@fuel-ts/utils";
|
12706
12840
|
|
12707
12841
|
// src/utils/deployScriptOrPredicate.ts
|
12708
12842
|
import { FuelError as FuelError30, ErrorCode as ErrorCode28 } from "@fuel-ts/errors";
|
12709
|
-
import { arrayify as
|
12843
|
+
import { arrayify as arrayify22 } from "@fuel-ts/utils";
|
12710
12844
|
|
12711
12845
|
// src/utils/predicate-script-loader-instructions.ts
|
12712
12846
|
import { BigNumberCoder as BigNumberCoder4 } from "@fuel-ts/abi-coder";
|
12713
12847
|
import { sha256 as sha2565 } from "@fuel-ts/hasher";
|
12714
|
-
import { concat as
|
12848
|
+
import { concat as concat8 } from "@fuel-ts/utils";
|
12715
12849
|
import * as asm2 from "@fuels/vm-asm";
|
12716
12850
|
var BLOB_ID_SIZE = 32;
|
12717
12851
|
var REG_ADDRESS_OF_DATA_AFTER_CODE = 16;
|
@@ -12837,7 +12971,7 @@ function getPredicateScriptLoaderInstructions(originalBinary, blobId) {
|
|
12837
12971
|
...dataSectionLenBytes
|
12838
12972
|
]);
|
12839
12973
|
return {
|
12840
|
-
loaderBytecode:
|
12974
|
+
loaderBytecode: concat8([loaderBytecode2, configurableSection]),
|
12841
12975
|
blobOffset: loaderBytecode2.length
|
12842
12976
|
};
|
12843
12977
|
}
|
@@ -12881,8 +13015,8 @@ async function deployScriptOrPredicate({
|
|
12881
13015
|
abi,
|
12882
13016
|
loaderInstanceCallback
|
12883
13017
|
}) {
|
12884
|
-
const blobId = getBytecodeId(
|
12885
|
-
const configurableOffset = getBytecodeConfigurableOffset(
|
13018
|
+
const blobId = getBytecodeId(arrayify22(bytecode));
|
13019
|
+
const configurableOffset = getBytecodeConfigurableOffset(arrayify22(bytecode));
|
12886
13020
|
const byteCodeWithoutConfigurableSection = bytecode.slice(0, configurableOffset);
|
12887
13021
|
const blobTxRequest = new BlobTransactionRequest({
|
12888
13022
|
blobId,
|
@@ -12890,8 +13024,8 @@ async function deployScriptOrPredicate({
|
|
12890
13024
|
witnesses: [byteCodeWithoutConfigurableSection]
|
12891
13025
|
});
|
12892
13026
|
const { loaderBytecode, blobOffset } = getPredicateScriptLoaderInstructions(
|
12893
|
-
|
12894
|
-
|
13027
|
+
arrayify22(bytecode),
|
13028
|
+
arrayify22(blobId)
|
12895
13029
|
);
|
12896
13030
|
const newConfigurableOffsetDiff = byteCodeWithoutConfigurableSection.length - (blobOffset || 0);
|
12897
13031
|
const newAbi = adjustConfigurableOffsets(abi, newConfigurableOffsetDiff);
|
@@ -12926,13 +13060,13 @@ __name(deployScriptOrPredicate, "deployScriptOrPredicate");
|
|
12926
13060
|
// src/predicate/utils/getPredicateRoot.ts
|
12927
13061
|
import { hash as hash3 } from "@fuel-ts/hasher";
|
12928
13062
|
import { calcRoot } from "@fuel-ts/merkle";
|
12929
|
-
import { chunkAndPadBytes, hexlify as hexlify24, concat as
|
13063
|
+
import { chunkAndPadBytes, hexlify as hexlify24, concat as concat9, arrayify as arrayify23 } from "@fuel-ts/utils";
|
12930
13064
|
var getPredicateRoot = /* @__PURE__ */ __name((bytecode) => {
|
12931
13065
|
const chunkSize = 16 * 1024;
|
12932
|
-
const bytes =
|
13066
|
+
const bytes = arrayify23(bytecode);
|
12933
13067
|
const chunks = chunkAndPadBytes(bytes, chunkSize);
|
12934
13068
|
const codeRoot = calcRoot(chunks.map((c) => hexlify24(c)));
|
12935
|
-
const predicateRoot = hash3(
|
13069
|
+
const predicateRoot = hash3(concat9(["0x4655454C", codeRoot]));
|
12936
13070
|
return predicateRoot;
|
12937
13071
|
}, "getPredicateRoot");
|
12938
13072
|
|
@@ -12969,7 +13103,7 @@ var Predicate = class _Predicate extends Account {
|
|
12969
13103
|
);
|
12970
13104
|
const address = new Address10(getPredicateRoot(predicateBytes));
|
12971
13105
|
super(address, provider);
|
12972
|
-
this.initialBytecode =
|
13106
|
+
this.initialBytecode = arrayify24(bytecode);
|
12973
13107
|
this.bytes = predicateBytes;
|
12974
13108
|
this.interface = predicateInterface;
|
12975
13109
|
this.configurableConstants = configurableConstants;
|
@@ -13061,8 +13195,8 @@ var Predicate = class _Predicate extends Account {
|
|
13061
13195
|
* @returns An object containing the new predicate bytes and interface.
|
13062
13196
|
*/
|
13063
13197
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
13064
|
-
let predicateBytes =
|
13065
|
-
const abiInterface = new
|
13198
|
+
let predicateBytes = arrayify24(bytes);
|
13199
|
+
const abiInterface = new Interface5(jsonAbi);
|
13066
13200
|
if (abiInterface.functions.main === void 0) {
|
13067
13201
|
throw new FuelError31(
|
13068
13202
|
ErrorCode29.ABI_MAIN_METHOD_MISSING,
|
@@ -13211,6 +13345,7 @@ var FuelConnectorMethods = /* @__PURE__ */ ((FuelConnectorMethods2) => {
|
|
13211
13345
|
FuelConnectorMethods2["isConnected"] = "isConnected";
|
13212
13346
|
FuelConnectorMethods2["accounts"] = "accounts";
|
13213
13347
|
FuelConnectorMethods2["currentAccount"] = "currentAccount";
|
13348
|
+
FuelConnectorMethods2["signTransaction"] = "signTransaction";
|
13214
13349
|
FuelConnectorMethods2["signMessage"] = "signMessage";
|
13215
13350
|
FuelConnectorMethods2["sendTransaction"] = "sendTransaction";
|
13216
13351
|
FuelConnectorMethods2["assets"] = "assets";
|
@@ -13352,7 +13487,7 @@ var FuelConnector = class extends EventEmitter2 {
|
|
13352
13487
|
*
|
13353
13488
|
* @returns Transaction signature
|
13354
13489
|
*/
|
13355
|
-
async signTransaction(_address, _transaction) {
|
13490
|
+
async signTransaction(_address, _transaction, _params) {
|
13356
13491
|
throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13357
13492
|
}
|
13358
13493
|
/**
|
@@ -13955,6 +14090,7 @@ export {
|
|
13955
14090
|
assemblePreConfirmationTransactionSummary,
|
13956
14091
|
assembleReceiptByType,
|
13957
14092
|
assembleRevertError,
|
14093
|
+
assembleSignalErrorMessage,
|
13958
14094
|
assembleTransactionSummary,
|
13959
14095
|
assembleTransactionSummaryFromJson,
|
13960
14096
|
assets,
|