@layerzerolabs/lz-v2-utilities 3.0.7 → 3.0.8
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/CHANGELOG.md +6 -0
- package/dist/index.cjs +415 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +130 -2
- package/dist/index.d.ts +130 -2
- package/dist/index.mjs +405 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -172,6 +172,7 @@ var ExecutorOptionType = /* @__PURE__ */ ((ExecutorOptionType2) => {
|
|
|
172
172
|
ExecutorOptionType2[ExecutorOptionType2["NATIVE_DROP"] = 2] = "NATIVE_DROP";
|
|
173
173
|
ExecutorOptionType2[ExecutorOptionType2["COMPOSE"] = 3] = "COMPOSE";
|
|
174
174
|
ExecutorOptionType2[ExecutorOptionType2["ORDERED"] = 4] = "ORDERED";
|
|
175
|
+
ExecutorOptionType2[ExecutorOptionType2["LZ_READ"] = 5] = "LZ_READ";
|
|
175
176
|
return ExecutorOptionType2;
|
|
176
177
|
})(ExecutorOptionType || {});
|
|
177
178
|
var VerifierOptionType = /* @__PURE__ */ ((VerifierOptionType2) => {
|
|
@@ -297,6 +298,16 @@ var Options = class _Options {
|
|
|
297
298
|
});
|
|
298
299
|
return this;
|
|
299
300
|
}
|
|
301
|
+
addExecutorLzReadOption(gasLimit, dataSize, nativeDrop = 0) {
|
|
302
|
+
const gasLimitBN = bignumber.BigNumber.from(gasLimit);
|
|
303
|
+
const dataSizeBN = bignumber.BigNumber.from(dataSize);
|
|
304
|
+
const nativeDropBN = bignumber.BigNumber.from(nativeDrop);
|
|
305
|
+
this.addOption(1 /* EXECUTOR */, {
|
|
306
|
+
type: 5 /* LZ_READ */,
|
|
307
|
+
params: nativeDropBN.eq(0) ? solidity.pack(["uint128", "uint32"], [gasLimitBN, dataSizeBN]) : solidity.pack(["uint128", "uint32", "uint128"], [gasLimitBN, dataSizeBN, nativeDropBN])
|
|
308
|
+
});
|
|
309
|
+
return this;
|
|
310
|
+
}
|
|
300
311
|
/**
|
|
301
312
|
* Add VerifierOptionType.PRECRIME option.
|
|
302
313
|
* @param {number} verifierIdx
|
|
@@ -431,6 +442,29 @@ var Options = class _Options {
|
|
|
431
442
|
const option = this.findOptions(1 /* EXECUTOR */, 4 /* ORDERED */);
|
|
432
443
|
return option !== void 0;
|
|
433
444
|
}
|
|
445
|
+
/**
|
|
446
|
+
* Decode ExecutorOptionType.LZ_READ options. Returns undefined if the options is not present.
|
|
447
|
+
*/
|
|
448
|
+
decodeExecutorLzReadOption() {
|
|
449
|
+
let options = this.findOptions(1 /* EXECUTOR */, 5 /* LZ_READ */);
|
|
450
|
+
if (options === void 0 || Array.isArray(options) && options.length === 0) {
|
|
451
|
+
return void 0;
|
|
452
|
+
}
|
|
453
|
+
let totalGas = bignumber.BigNumber.from(0).toBigInt();
|
|
454
|
+
let dataSize = bignumber.BigNumber.from(0).toBigInt();
|
|
455
|
+
let totalValue = bignumber.BigNumber.from(0).toBigInt();
|
|
456
|
+
options = Array.isArray(options) ? options : [options];
|
|
457
|
+
for (const option of options) {
|
|
458
|
+
const buffer = Buffer.from(trim0x(option.params), "hex");
|
|
459
|
+
const gas = bignumber.BigNumber.from(buffer.subarray(0, 16)).toBigInt();
|
|
460
|
+
const size = bignumber.BigNumber.from(buffer.subarray(16, 20)).toBigInt();
|
|
461
|
+
const value = bignumber.BigNumber.from(buffer.length === 20 ? 0 : buffer.subarray(20, 32)).toBigInt();
|
|
462
|
+
totalGas = totalGas + gas;
|
|
463
|
+
dataSize = dataSize + size;
|
|
464
|
+
totalValue = totalValue + value;
|
|
465
|
+
}
|
|
466
|
+
return { gas: totalGas, dataSize, value: totalValue };
|
|
467
|
+
}
|
|
434
468
|
findOptions(workerId, optionType) {
|
|
435
469
|
const worker = this.workerOptions.find((w) => w.workerId === workerId);
|
|
436
470
|
if (worker) {
|
|
@@ -605,15 +639,396 @@ var PacketSerializer = class {
|
|
|
605
639
|
}
|
|
606
640
|
};
|
|
607
641
|
|
|
642
|
+
// src/commandCodec/commandCodec.ts
|
|
643
|
+
var Codec = class {
|
|
644
|
+
byteLength;
|
|
645
|
+
constructor() {
|
|
646
|
+
this.byteLength = 0;
|
|
647
|
+
}
|
|
648
|
+
getByteLength() {
|
|
649
|
+
return this.byteLength;
|
|
650
|
+
}
|
|
651
|
+
getHexLength() {
|
|
652
|
+
return this.byteLength * 2;
|
|
653
|
+
}
|
|
654
|
+
static decode(hex) {
|
|
655
|
+
throw new Error("Not implemented");
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
var TimestampBlockConfiguration = /* @__PURE__ */ ((TimestampBlockConfiguration2) => {
|
|
659
|
+
TimestampBlockConfiguration2[TimestampBlockConfiguration2["Timestamp"] = 0] = "Timestamp";
|
|
660
|
+
TimestampBlockConfiguration2[TimestampBlockConfiguration2["BlockNumber"] = 1] = "BlockNumber";
|
|
661
|
+
return TimestampBlockConfiguration2;
|
|
662
|
+
})(TimestampBlockConfiguration || {});
|
|
663
|
+
var ResolverType = /* @__PURE__ */ ((ResolverType2) => {
|
|
664
|
+
ResolverType2[ResolverType2["SingleViewFunctionEVMCall"] = 1] = "SingleViewFunctionEVMCall";
|
|
665
|
+
return ResolverType2;
|
|
666
|
+
})(ResolverType || {});
|
|
667
|
+
var ComputeSetting = /* @__PURE__ */ ((ComputeSetting2) => {
|
|
668
|
+
ComputeSetting2[ComputeSetting2["OnlyMap"] = 0] = "OnlyMap";
|
|
669
|
+
ComputeSetting2[ComputeSetting2["OnlyReduce"] = 1] = "OnlyReduce";
|
|
670
|
+
ComputeSetting2[ComputeSetting2["MapReduce"] = 2] = "MapReduce";
|
|
671
|
+
return ComputeSetting2;
|
|
672
|
+
})(ComputeSetting || {});
|
|
673
|
+
var ComputeType = /* @__PURE__ */ ((ComputeType2) => {
|
|
674
|
+
ComputeType2[ComputeType2["SingleViewFunctionEVMCall"] = 1] = "SingleViewFunctionEVMCall";
|
|
675
|
+
return ComputeType2;
|
|
676
|
+
})(ComputeType || {});
|
|
677
|
+
var Header = class _Header extends Codec {
|
|
678
|
+
globalVersion;
|
|
679
|
+
// 2 bytes
|
|
680
|
+
appCommandLabel;
|
|
681
|
+
// 2 bytes
|
|
682
|
+
requestCount;
|
|
683
|
+
// 2 bytes
|
|
684
|
+
static GLOBAL_VERSION_BYTES = 2;
|
|
685
|
+
static APP_COMMAND_LABEL_BYTES = 2;
|
|
686
|
+
static REQUEST_COUNT_BYTES = 2;
|
|
687
|
+
constructor(globalVersion, appCommandLabel, requestCount) {
|
|
688
|
+
super();
|
|
689
|
+
this.globalVersion = globalVersion;
|
|
690
|
+
this.appCommandLabel = appCommandLabel;
|
|
691
|
+
this.requestCount = requestCount;
|
|
692
|
+
this.byteLength = _Header.GLOBAL_VERSION_BYTES + _Header.APP_COMMAND_LABEL_BYTES + _Header.REQUEST_COUNT_BYTES;
|
|
693
|
+
}
|
|
694
|
+
encode() {
|
|
695
|
+
const globalVersionHex = numberToHex(this.globalVersion, _Header.GLOBAL_VERSION_BYTES);
|
|
696
|
+
const appCommandLabelHex = this.appCommandLabel.padStart(bytesToHexLength(_Header.APP_COMMAND_LABEL_BYTES), "0");
|
|
697
|
+
const requestCountHex = numberToHex(this.requestCount, _Header.REQUEST_COUNT_BYTES);
|
|
698
|
+
return globalVersionHex + appCommandLabelHex + requestCountHex;
|
|
699
|
+
}
|
|
700
|
+
static decode(hex, offset) {
|
|
701
|
+
let internalOffset = offset ?? 0;
|
|
702
|
+
const globalVersion = hexToNumber(sliceHex(hex, internalOffset, _Header.GLOBAL_VERSION_BYTES));
|
|
703
|
+
internalOffset += bytesToHexLength(_Header.GLOBAL_VERSION_BYTES);
|
|
704
|
+
const appCommandLabel = sliceHex(hex, internalOffset, _Header.APP_COMMAND_LABEL_BYTES);
|
|
705
|
+
internalOffset += bytesToHexLength(_Header.APP_COMMAND_LABEL_BYTES);
|
|
706
|
+
const requestCount = hexToNumber(sliceHex(hex, internalOffset, _Header.REQUEST_COUNT_BYTES));
|
|
707
|
+
return new _Header(globalVersion, appCommandLabel, requestCount);
|
|
708
|
+
}
|
|
709
|
+
};
|
|
710
|
+
var RequestHeader = class _RequestHeader extends Codec {
|
|
711
|
+
requestVersion;
|
|
712
|
+
// 1 byte
|
|
713
|
+
appRequestLabel;
|
|
714
|
+
// 2 bytes (hex or string)
|
|
715
|
+
resolverType;
|
|
716
|
+
// 2 bytes
|
|
717
|
+
requestSize;
|
|
718
|
+
// 2 bytes
|
|
719
|
+
static REQUEST_VERSION_BYTES = 1;
|
|
720
|
+
static APP_REQUEST_LABEL_BYTES = 2;
|
|
721
|
+
static RESOLVER_TYPE_BYTES = 2;
|
|
722
|
+
static REQUEST_SIZE_BYTES = 2;
|
|
723
|
+
constructor(requestVersion, appRequestLabel, resolverType, requestSize) {
|
|
724
|
+
super();
|
|
725
|
+
this.requestVersion = requestVersion;
|
|
726
|
+
this.appRequestLabel = appRequestLabel;
|
|
727
|
+
this.resolverType = resolverType;
|
|
728
|
+
this.requestSize = requestSize;
|
|
729
|
+
this.byteLength = _RequestHeader.REQUEST_VERSION_BYTES + _RequestHeader.APP_REQUEST_LABEL_BYTES + _RequestHeader.RESOLVER_TYPE_BYTES + _RequestHeader.REQUEST_SIZE_BYTES;
|
|
730
|
+
}
|
|
731
|
+
encode() {
|
|
732
|
+
const requestVersionHex = numberToHex(this.requestVersion, _RequestHeader.REQUEST_VERSION_BYTES);
|
|
733
|
+
const appRequestLabelHex = this.appRequestLabel.padStart(
|
|
734
|
+
bytesToHexLength(_RequestHeader.APP_REQUEST_LABEL_BYTES),
|
|
735
|
+
"0"
|
|
736
|
+
);
|
|
737
|
+
const resolverTypeHex = numberToHex(this.resolverType, _RequestHeader.RESOLVER_TYPE_BYTES);
|
|
738
|
+
const requestSizeHex = numberToHex(this.requestSize, _RequestHeader.REQUEST_SIZE_BYTES);
|
|
739
|
+
return requestVersionHex + appRequestLabelHex + resolverTypeHex + requestSizeHex;
|
|
740
|
+
}
|
|
741
|
+
static decode(hex, offset) {
|
|
742
|
+
let internalOffset = offset ?? 0;
|
|
743
|
+
const requestVersion = hexToNumber(sliceHex(hex, internalOffset, _RequestHeader.REQUEST_VERSION_BYTES));
|
|
744
|
+
internalOffset += bytesToHexLength(_RequestHeader.REQUEST_VERSION_BYTES);
|
|
745
|
+
const appRequestLabel = sliceHex(hex, internalOffset, _RequestHeader.APP_REQUEST_LABEL_BYTES);
|
|
746
|
+
internalOffset += bytesToHexLength(_RequestHeader.APP_REQUEST_LABEL_BYTES);
|
|
747
|
+
const resolverType = hexToNumber(sliceHex(hex, internalOffset, _RequestHeader.RESOLVER_TYPE_BYTES));
|
|
748
|
+
internalOffset += bytesToHexLength(_RequestHeader.RESOLVER_TYPE_BYTES);
|
|
749
|
+
const requestSize = hexToNumber(sliceHex(hex, internalOffset, _RequestHeader.REQUEST_SIZE_BYTES));
|
|
750
|
+
return new _RequestHeader(requestVersion, appRequestLabel, resolverType, requestSize);
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
var EVMBase = class _EVMBase extends Codec {
|
|
754
|
+
targetEid;
|
|
755
|
+
// 4 bytes
|
|
756
|
+
timestampBlockFlag;
|
|
757
|
+
// 1 byte
|
|
758
|
+
blockConfirmations;
|
|
759
|
+
// 2 bytes
|
|
760
|
+
to;
|
|
761
|
+
// 20 bytes (hex or string)
|
|
762
|
+
timestamp;
|
|
763
|
+
// 8 bytes (if timestampBlockFlag indicates Unix timestamp)
|
|
764
|
+
blockNumber;
|
|
765
|
+
// 8 bytes (if timestampBlockFlag indicates block number)
|
|
766
|
+
static TARGET_EID_BYTES = 4;
|
|
767
|
+
static TIMESTAMP_BLOCK_FLAG_BYTES = 1;
|
|
768
|
+
static BLOCK_CONFIRMATIONS_BYTES = 2;
|
|
769
|
+
static TO_BYTES = 20;
|
|
770
|
+
static TIMESTAMP_BYTES = 8;
|
|
771
|
+
static BLOCK_NUMBER_BYTES = 8;
|
|
772
|
+
constructor(targetEid, timestampBlockFlag, blockConfirmations, to, timestamp, blockNumber) {
|
|
773
|
+
super();
|
|
774
|
+
this.targetEid = targetEid;
|
|
775
|
+
this.timestampBlockFlag = timestampBlockFlag;
|
|
776
|
+
this.blockConfirmations = blockConfirmations;
|
|
777
|
+
this.to = to;
|
|
778
|
+
this.timestamp = timestamp;
|
|
779
|
+
this.blockNumber = blockNumber;
|
|
780
|
+
this.byteLength = _EVMBase.TARGET_EID_BYTES + _EVMBase.TIMESTAMP_BLOCK_FLAG_BYTES + _EVMBase.BLOCK_CONFIRMATIONS_BYTES + _EVMBase.TO_BYTES + (timestamp !== void 0 ? _EVMBase.TIMESTAMP_BYTES : 0) + (blockNumber !== void 0 ? _EVMBase.BLOCK_NUMBER_BYTES : 0);
|
|
781
|
+
}
|
|
782
|
+
encode() {
|
|
783
|
+
const targetEidHex = numberToHex(this.targetEid, _EVMBase.TARGET_EID_BYTES);
|
|
784
|
+
const timestampBlockFlagHex = numberToHex(this.timestampBlockFlag, _EVMBase.TIMESTAMP_BLOCK_FLAG_BYTES);
|
|
785
|
+
const blockNumberHex = this.blockNumber !== void 0 ? bigIntToHex(this.blockNumber, _EVMBase.BLOCK_NUMBER_BYTES) : void 0;
|
|
786
|
+
const timestampHex = this.timestamp !== void 0 ? bigIntToHex(this.timestamp, _EVMBase.TIMESTAMP_BYTES) : void 0;
|
|
787
|
+
if (timestampHex !== void 0 && blockNumberHex !== void 0) {
|
|
788
|
+
throw new Error("Cannot have both timestamp and block number");
|
|
789
|
+
}
|
|
790
|
+
const blockConfirmationsHex = numberToHex(this.blockConfirmations, _EVMBase.BLOCK_CONFIRMATIONS_BYTES);
|
|
791
|
+
const toHex = this.to.padStart(bytesToHexLength(_EVMBase.TO_BYTES), "0");
|
|
792
|
+
const blockOrTimestampHex = blockNumberHex ?? timestampHex;
|
|
793
|
+
if (blockOrTimestampHex === void 0) {
|
|
794
|
+
throw new Error("Either block number or timestamp must be set");
|
|
795
|
+
}
|
|
796
|
+
return targetEidHex + timestampBlockFlagHex + blockOrTimestampHex + blockConfirmationsHex + toHex;
|
|
797
|
+
}
|
|
798
|
+
static decode(hex, offset) {
|
|
799
|
+
let internalOffset = offset ?? 0;
|
|
800
|
+
const targetEid = hexToNumber(sliceHex(hex, internalOffset, _EVMBase.TARGET_EID_BYTES));
|
|
801
|
+
internalOffset += bytesToHexLength(_EVMBase.TARGET_EID_BYTES);
|
|
802
|
+
const timestampBlockFlag = hexToNumber(
|
|
803
|
+
sliceHex(hex, internalOffset, _EVMBase.TIMESTAMP_BLOCK_FLAG_BYTES)
|
|
804
|
+
);
|
|
805
|
+
internalOffset += bytesToHexLength(_EVMBase.TIMESTAMP_BLOCK_FLAG_BYTES);
|
|
806
|
+
let timestamp;
|
|
807
|
+
let blockNumber;
|
|
808
|
+
if (timestampBlockFlag === 0 /* Timestamp */) {
|
|
809
|
+
timestamp = hexToBigInt(sliceHex(hex, internalOffset, _EVMBase.TIMESTAMP_BYTES));
|
|
810
|
+
internalOffset += bytesToHexLength(_EVMBase.TIMESTAMP_BYTES);
|
|
811
|
+
} else {
|
|
812
|
+
blockNumber = hexToBigInt(sliceHex(hex, internalOffset, _EVMBase.BLOCK_NUMBER_BYTES));
|
|
813
|
+
internalOffset += bytesToHexLength(_EVMBase.BLOCK_NUMBER_BYTES);
|
|
814
|
+
}
|
|
815
|
+
const blockConfirmations = hexToNumber(sliceHex(hex, internalOffset, _EVMBase.BLOCK_CONFIRMATIONS_BYTES));
|
|
816
|
+
internalOffset += bytesToHexLength(_EVMBase.BLOCK_CONFIRMATIONS_BYTES);
|
|
817
|
+
const to = sliceHex(hex, internalOffset, _EVMBase.TO_BYTES);
|
|
818
|
+
return new _EVMBase(targetEid, timestampBlockFlag, blockConfirmations, to, timestamp, blockNumber);
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
var SingleViewFunctionEVMCall = class _SingleViewFunctionEVMCall extends EVMBase {
|
|
822
|
+
requestHeader;
|
|
823
|
+
calldata;
|
|
824
|
+
// Calldata (size specified by calldataSize)
|
|
825
|
+
constructor(requestHeader, targetEid, timestampBlockFlag, blockConfirmations, to, calldata, timestamp, blockNumber) {
|
|
826
|
+
super(targetEid, timestampBlockFlag, blockConfirmations, to, timestamp, blockNumber);
|
|
827
|
+
this.requestHeader = requestHeader;
|
|
828
|
+
this.calldata = calldata;
|
|
829
|
+
const evmByteLength = super.getByteLength();
|
|
830
|
+
const callDataSize = this.requestHeader.requestSize - evmByteLength;
|
|
831
|
+
this.byteLength = this.requestHeader.getByteLength() + evmByteLength + callDataSize;
|
|
832
|
+
}
|
|
833
|
+
encode() {
|
|
834
|
+
const requestHeaderHex = this.requestHeader.encode();
|
|
835
|
+
const evmBaseHex = super.encode();
|
|
836
|
+
const callDataSize = this.requestHeader.requestSize - super.getByteLength();
|
|
837
|
+
const calldataHex = this.calldata.padStart(callDataSize * 2, "0");
|
|
838
|
+
return requestHeaderHex + evmBaseHex + calldataHex;
|
|
839
|
+
}
|
|
840
|
+
static decode(hex, offset) {
|
|
841
|
+
let internalOffset = offset ?? 0;
|
|
842
|
+
const requestHeader = RequestHeader.decode(hex, internalOffset);
|
|
843
|
+
internalOffset += requestHeader.getHexLength();
|
|
844
|
+
const evmBase = super.decode(hex, internalOffset);
|
|
845
|
+
internalOffset += evmBase.getHexLength();
|
|
846
|
+
const calldataSize = requestHeader.requestSize - evmBase.getByteLength();
|
|
847
|
+
const calldata = sliceHex(hex, internalOffset, calldataSize);
|
|
848
|
+
return new _SingleViewFunctionEVMCall(
|
|
849
|
+
requestHeader,
|
|
850
|
+
evmBase.targetEid,
|
|
851
|
+
evmBase.timestampBlockFlag,
|
|
852
|
+
evmBase.blockConfirmations,
|
|
853
|
+
evmBase.to,
|
|
854
|
+
calldata,
|
|
855
|
+
evmBase.timestamp,
|
|
856
|
+
evmBase.blockNumber
|
|
857
|
+
);
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
var ComputeHeader = class _ComputeHeader extends Codec {
|
|
861
|
+
computeVersion;
|
|
862
|
+
// 1 byte
|
|
863
|
+
computeType;
|
|
864
|
+
// 2 bytes
|
|
865
|
+
computeSetting;
|
|
866
|
+
// 1 byte
|
|
867
|
+
static COMPUTE_VERSION_BYTES = 1;
|
|
868
|
+
static COMPUTE_TYPE_BYTES = 2;
|
|
869
|
+
static COMPUTE_SETTING_BYTES = 1;
|
|
870
|
+
constructor(computeVersion, computeType, computeSetting) {
|
|
871
|
+
super();
|
|
872
|
+
this.computeVersion = computeVersion;
|
|
873
|
+
this.computeType = computeType;
|
|
874
|
+
this.computeSetting = computeSetting;
|
|
875
|
+
this.byteLength = _ComputeHeader.COMPUTE_VERSION_BYTES + _ComputeHeader.COMPUTE_TYPE_BYTES + _ComputeHeader.COMPUTE_SETTING_BYTES;
|
|
876
|
+
}
|
|
877
|
+
encode() {
|
|
878
|
+
const computeVersionHex = numberToHex(this.computeVersion, _ComputeHeader.COMPUTE_VERSION_BYTES);
|
|
879
|
+
const computeTypeHex = numberToHex(this.computeType, _ComputeHeader.COMPUTE_TYPE_BYTES);
|
|
880
|
+
const computeSettingHex = numberToHex(this.computeSetting, _ComputeHeader.COMPUTE_SETTING_BYTES);
|
|
881
|
+
return computeVersionHex + computeTypeHex + computeSettingHex;
|
|
882
|
+
}
|
|
883
|
+
static decode(hex, offset) {
|
|
884
|
+
let internalOffset = offset ?? 0;
|
|
885
|
+
const computeVersion = hexToNumber(sliceHex(hex, internalOffset, _ComputeHeader.COMPUTE_VERSION_BYTES));
|
|
886
|
+
internalOffset += bytesToHexLength(_ComputeHeader.COMPUTE_VERSION_BYTES);
|
|
887
|
+
const computeType = hexToNumber(sliceHex(hex, internalOffset, _ComputeHeader.COMPUTE_TYPE_BYTES));
|
|
888
|
+
internalOffset += bytesToHexLength(_ComputeHeader.COMPUTE_TYPE_BYTES);
|
|
889
|
+
const computeSetting = hexToNumber(sliceHex(hex, internalOffset, _ComputeHeader.COMPUTE_SETTING_BYTES));
|
|
890
|
+
return new _ComputeHeader(computeVersion, computeType, computeSetting);
|
|
891
|
+
}
|
|
892
|
+
};
|
|
893
|
+
var ComputeEVM = class _ComputeEVM extends EVMBase {
|
|
894
|
+
computeHeader;
|
|
895
|
+
constructor(computeHeader, targetEid, timestampBlockFlag, blockConfirmations, to, timestamp, blockNumber) {
|
|
896
|
+
super(targetEid, timestampBlockFlag, blockConfirmations, to, timestamp, blockNumber);
|
|
897
|
+
this.computeHeader = computeHeader;
|
|
898
|
+
const evmByteLength = super.getByteLength();
|
|
899
|
+
this.byteLength += evmByteLength + this.computeHeader.getByteLength();
|
|
900
|
+
}
|
|
901
|
+
encode() {
|
|
902
|
+
const computeHeaderHex = this.computeHeader.encode();
|
|
903
|
+
const evmBaseHex = super.encode();
|
|
904
|
+
return computeHeaderHex + evmBaseHex;
|
|
905
|
+
}
|
|
906
|
+
static decode(hex, offset) {
|
|
907
|
+
let internalOffset = offset ?? 0;
|
|
908
|
+
const computeHeader = ComputeHeader.decode(hex, internalOffset);
|
|
909
|
+
internalOffset += computeHeader.getHexLength();
|
|
910
|
+
const evmBase = EVMBase.decode(hex, internalOffset);
|
|
911
|
+
internalOffset += evmBase.getHexLength();
|
|
912
|
+
return new _ComputeEVM(
|
|
913
|
+
computeHeader,
|
|
914
|
+
evmBase.targetEid,
|
|
915
|
+
evmBase.timestampBlockFlag,
|
|
916
|
+
evmBase.blockConfirmations,
|
|
917
|
+
evmBase.to,
|
|
918
|
+
evmBase.timestamp,
|
|
919
|
+
evmBase.blockNumber
|
|
920
|
+
);
|
|
921
|
+
}
|
|
922
|
+
};
|
|
923
|
+
var Command = class _Command extends Codec {
|
|
924
|
+
header;
|
|
925
|
+
requests;
|
|
926
|
+
compute;
|
|
927
|
+
constructor(header, requests, compute) {
|
|
928
|
+
super();
|
|
929
|
+
this.header = header;
|
|
930
|
+
this.requests = requests;
|
|
931
|
+
this.compute = compute;
|
|
932
|
+
this.byteLength = this.header.getByteLength() + this.requests.reduce((acc, req) => acc + req.getByteLength(), 0) + (this.compute ? this.compute.getByteLength() : 0);
|
|
933
|
+
}
|
|
934
|
+
encodeCommandRequest(request) {
|
|
935
|
+
switch (request.requestHeader.resolverType) {
|
|
936
|
+
case 1 /* SingleViewFunctionEVMCall */:
|
|
937
|
+
return request.encode();
|
|
938
|
+
default:
|
|
939
|
+
throw new Error("Invalid resolver type");
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
encodeCompute() {
|
|
943
|
+
if (!this.compute) {
|
|
944
|
+
return "";
|
|
945
|
+
}
|
|
946
|
+
switch (this.compute.computeHeader.computeType) {
|
|
947
|
+
case 1 /* SingleViewFunctionEVMCall */:
|
|
948
|
+
return this.compute.encode();
|
|
949
|
+
default:
|
|
950
|
+
throw new Error("Invalid compute type");
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
encode() {
|
|
954
|
+
const headerHex = this.header.encode();
|
|
955
|
+
const requestsHex = this.requests.map((req) => this.encodeCommandRequest(req)).join("");
|
|
956
|
+
const computeHex = this.encodeCompute();
|
|
957
|
+
return headerHex + requestsHex + computeHex;
|
|
958
|
+
}
|
|
959
|
+
static decodeRequest(hex, offset) {
|
|
960
|
+
const requestHeader = RequestHeader.decode(hex, offset);
|
|
961
|
+
switch (requestHeader.resolverType) {
|
|
962
|
+
case 1 /* SingleViewFunctionEVMCall */:
|
|
963
|
+
return SingleViewFunctionEVMCall.decode(hex, offset);
|
|
964
|
+
default:
|
|
965
|
+
throw new Error("Invalid resolver type");
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
static decodeCompute(hex, offset) {
|
|
969
|
+
const computeHeader = ComputeHeader.decode(hex, offset);
|
|
970
|
+
switch (computeHeader.computeType) {
|
|
971
|
+
case 1 /* SingleViewFunctionEVMCall */:
|
|
972
|
+
return ComputeEVM.decode(hex, offset);
|
|
973
|
+
default:
|
|
974
|
+
throw new Error("Invalid compute type");
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
static decode(hex, offset) {
|
|
978
|
+
let internalOffset = offset ?? 0;
|
|
979
|
+
const header = Header.decode(hex, internalOffset);
|
|
980
|
+
internalOffset += header.getHexLength();
|
|
981
|
+
const requests = [];
|
|
982
|
+
for (let i = 0; i < header.requestCount; i++) {
|
|
983
|
+
const request = _Command.decodeRequest(hex, internalOffset);
|
|
984
|
+
requests.push(request);
|
|
985
|
+
internalOffset += request.getHexLength();
|
|
986
|
+
}
|
|
987
|
+
const command = internalOffset === hex.length ? new _Command(header, requests) : new _Command(header, requests, _Command.decodeCompute(hex, internalOffset));
|
|
988
|
+
return command;
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
function bytesToHexLength(bytes) {
|
|
992
|
+
return bytes * 2;
|
|
993
|
+
}
|
|
994
|
+
function sliceHex(hex, offset, bytes) {
|
|
995
|
+
const length = bytesToHexLength(bytes);
|
|
996
|
+
const slice = hex.slice(offset, offset + length);
|
|
997
|
+
return slice;
|
|
998
|
+
}
|
|
999
|
+
function hexToNumber(hexStr) {
|
|
1000
|
+
return parseInt(hexStr, 16);
|
|
1001
|
+
}
|
|
1002
|
+
function hexToBigInt(hexStr) {
|
|
1003
|
+
return BigInt(`0x${hexStr}`);
|
|
1004
|
+
}
|
|
1005
|
+
function numberToHex(num, bytes) {
|
|
1006
|
+
return num.toString(16).padStart(bytes * 2, "0");
|
|
1007
|
+
}
|
|
1008
|
+
function bigIntToHex(bigInt, bytes) {
|
|
1009
|
+
return bigInt.toString(16).padStart(bytes * 2, "0");
|
|
1010
|
+
}
|
|
1011
|
+
|
|
608
1012
|
Object.defineProperty(exports, "keccak256", {
|
|
609
1013
|
enumerable: true,
|
|
610
1014
|
get: function () { return keccak256.keccak256; }
|
|
611
1015
|
});
|
|
1016
|
+
exports.Command = Command;
|
|
1017
|
+
exports.ComputeEVM = ComputeEVM;
|
|
1018
|
+
exports.ComputeHeader = ComputeHeader;
|
|
1019
|
+
exports.ComputeSetting = ComputeSetting;
|
|
1020
|
+
exports.ComputeType = ComputeType;
|
|
1021
|
+
exports.EVMBase = EVMBase;
|
|
612
1022
|
exports.ExecutorOptionType = ExecutorOptionType;
|
|
1023
|
+
exports.Header = Header;
|
|
613
1024
|
exports.OptionType = OptionType;
|
|
614
1025
|
exports.Options = Options;
|
|
615
1026
|
exports.PacketSerializer = PacketSerializer;
|
|
616
1027
|
exports.PacketV1Codec = PacketV1Codec;
|
|
1028
|
+
exports.RequestHeader = RequestHeader;
|
|
1029
|
+
exports.ResolverType = ResolverType;
|
|
1030
|
+
exports.SingleViewFunctionEVMCall = SingleViewFunctionEVMCall;
|
|
1031
|
+
exports.TimestampBlockConfiguration = TimestampBlockConfiguration;
|
|
617
1032
|
exports.VerifierOptionType = VerifierOptionType;
|
|
618
1033
|
exports.WorkerId = WorkerId;
|
|
619
1034
|
exports.addressToBytes32 = addressToBytes32;
|