viem 0.2.0-jxom-local-accounts.20230321T210352 → 0.2.0-jxom-local-accounts.20230321T212822
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/accounts/package.json +4 -0
- package/dist/abi.js +2 -2
- package/dist/abi.mjs +1 -1
- package/dist/accounts/index.d.ts +33 -0
- package/dist/accounts/index.js +89 -0
- package/dist/accounts/index.js.map +1 -0
- package/dist/accounts/index.mjs +89 -0
- package/dist/accounts/index.mjs.map +1 -0
- package/dist/chains.js +63 -63
- package/dist/chains.mjs +1 -1
- package/dist/{chunk-IXGTN6B7.mjs → chunk-6UKHPIXX.mjs} +2 -2
- package/dist/chunk-FNVFGFWN.mjs +31 -0
- package/dist/chunk-FNVFGFWN.mjs.map +1 -0
- package/dist/chunk-FQM5MF6U.js +31 -0
- package/dist/chunk-FQM5MF6U.js.map +1 -0
- package/dist/{chunk-PB263D6W.mjs → chunk-IVRML3IK.mjs} +869 -880
- package/dist/chunk-IVRML3IK.mjs.map +1 -0
- package/dist/{chunk-K66BKQUH.js → chunk-LYQKHD7R.js} +19 -19
- package/dist/{chunk-FHJTO6BQ.js → chunk-NJSAEA2H.js} +821 -832
- package/dist/chunk-NJSAEA2H.js.map +1 -0
- package/dist/contract.d.ts +3 -2
- package/dist/contract.js +2 -2
- package/dist/contract.mjs +1 -1
- package/dist/{createPublicClient-62c74ebc.d.ts → createPublicClient-d2c37c92.d.ts} +2 -2
- package/dist/ens.d.ts +3 -2
- package/dist/ens.js +3 -3
- package/dist/ens.mjs +2 -2
- package/dist/ethers.d.ts +2 -1
- package/dist/ethers.js +5 -3
- package/dist/ethers.js.map +1 -1
- package/dist/ethers.mjs +4 -2
- package/dist/ethers.mjs.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +91 -91
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/parseAccount-2d7ea01d.d.ts +6 -0
- package/dist/{parseGwei-7efc43fc.d.ts → parseGwei-377678bc.d.ts} +7 -7
- package/dist/public.d.ts +3 -2
- package/dist/public.js +2 -2
- package/dist/public.mjs +1 -1
- package/dist/test.js +2 -2
- package/dist/test.mjs +1 -1
- package/dist/{typedData-0514bb3c.d.ts → typedData-ade018d6.d.ts} +19 -2
- package/dist/utils/index.d.ts +7 -5
- package/dist/utils/index.js +4 -2
- package/dist/utils/index.mjs +3 -1
- package/dist/wallet.d.ts +3 -2
- package/dist/wallet.js +2 -2
- package/dist/wallet.mjs +1 -1
- package/package.json +7 -1
- package/dist/chunk-FHJTO6BQ.js.map +0 -1
- package/dist/chunk-PB263D6W.mjs.map +0 -1
- /package/dist/{chunk-IXGTN6B7.mjs.map → chunk-6UKHPIXX.mjs.map} +0 -0
- /package/dist/{chunk-K66BKQUH.js.map → chunk-LYQKHD7R.js.map} +0 -0
@@ -25,7 +25,7 @@ var package_default = {
|
|
25
25
|
anvil: "source .env && anvil --fork-url $VITE_ANVIL_FORK_URL --fork-block-number $VITE_ANVIL_BLOCK_NUMBER --block-time $VITE_ANVIL_BLOCK_TIME",
|
26
26
|
bench: "vitest bench --no-threads",
|
27
27
|
"bench:ci": "CI=true vitest bench --no-threads",
|
28
|
-
build: "tsup",
|
28
|
+
build: "tsup && size-limit",
|
29
29
|
changeset: "changeset",
|
30
30
|
"changeset:release": "pnpm build && changeset publish",
|
31
31
|
"changeset:version": "changeset version && pnpm install --lockfile-only",
|
@@ -53,6 +53,7 @@ var package_default = {
|
|
53
53
|
entry: [
|
54
54
|
"src/index.ts",
|
55
55
|
"src/abi.ts",
|
56
|
+
"src/accounts/index.ts",
|
56
57
|
"src/chains.ts",
|
57
58
|
"src/contract.ts",
|
58
59
|
"src/ens.ts",
|
@@ -66,6 +67,7 @@ var package_default = {
|
|
66
67
|
},
|
67
68
|
files: [
|
68
69
|
"/abi",
|
70
|
+
"/accounts",
|
69
71
|
"/dist",
|
70
72
|
"/chains",
|
71
73
|
"/contract",
|
@@ -88,6 +90,11 @@ var package_default = {
|
|
88
90
|
module: "./dist/abi.mts",
|
89
91
|
default: "./dist/abi.js"
|
90
92
|
},
|
93
|
+
"./accounts": {
|
94
|
+
types: "./dist/accounts/index.d.ts",
|
95
|
+
module: "./dist/accounts/index.mts",
|
96
|
+
default: "./dist/accounts/index.js"
|
97
|
+
},
|
91
98
|
"./chains": {
|
92
99
|
types: "./dist/chains.d.ts",
|
93
100
|
module: "./dist/chains.mts",
|
@@ -156,6 +163,7 @@ var package_default = {
|
|
156
163
|
"@adraffy/ens-normalize": "^1.8.9",
|
157
164
|
"@changesets/changelog-github": "^0.4.5",
|
158
165
|
"@changesets/cli": "^2.23.2",
|
166
|
+
"@size-limit/preset-big-lib": "^8.2.4",
|
159
167
|
"@types/dedent": "^0.7.0",
|
160
168
|
"@types/fs-extra": "^9.0.13",
|
161
169
|
"@types/node": "^17.0.45",
|
@@ -173,6 +181,7 @@ var package_default = {
|
|
173
181
|
rimraf: "^4.1.2",
|
174
182
|
rome: "^11.0.0",
|
175
183
|
"simple-git-hooks": "^2.8.1",
|
184
|
+
"size-limit": "^8.2.4",
|
176
185
|
tsup: "^6.6.0",
|
177
186
|
typescript: "^4.9.4",
|
178
187
|
vite: "^4.1.4",
|
@@ -191,6 +200,11 @@ var package_default = {
|
|
191
200
|
"wallet",
|
192
201
|
"web3"
|
193
202
|
],
|
203
|
+
"size-limit": [
|
204
|
+
{
|
205
|
+
path: "dist/index.js"
|
206
|
+
}
|
207
|
+
],
|
194
208
|
"simple-git-hooks": {
|
195
209
|
"pre-commit": "pnpm format && pnpm lint:fix"
|
196
210
|
},
|
@@ -616,714 +630,157 @@ var ChainNotFoundError = class extends BaseError {
|
|
616
630
|
}
|
617
631
|
};
|
618
632
|
|
619
|
-
// src/
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
633
|
+
// src/constants/abis.ts
|
634
|
+
var multicall3Abi = [
|
635
|
+
{
|
636
|
+
inputs: [
|
637
|
+
{
|
638
|
+
components: [
|
639
|
+
{
|
640
|
+
name: "target",
|
641
|
+
type: "address"
|
642
|
+
},
|
643
|
+
{
|
644
|
+
name: "allowFailure",
|
645
|
+
type: "bool"
|
646
|
+
},
|
647
|
+
{
|
648
|
+
name: "callData",
|
649
|
+
type: "bytes"
|
650
|
+
}
|
651
|
+
],
|
652
|
+
name: "calls",
|
653
|
+
type: "tuple[]"
|
654
|
+
}
|
655
|
+
],
|
656
|
+
name: "aggregate3",
|
657
|
+
outputs: [
|
658
|
+
{
|
659
|
+
components: [
|
660
|
+
{
|
661
|
+
name: "success",
|
662
|
+
type: "bool"
|
663
|
+
},
|
664
|
+
{
|
665
|
+
name: "returnData",
|
666
|
+
type: "bytes"
|
667
|
+
}
|
668
|
+
],
|
669
|
+
name: "returnData",
|
670
|
+
type: "tuple[]"
|
671
|
+
}
|
672
|
+
],
|
673
|
+
stateMutability: "view",
|
674
|
+
type: "function"
|
645
675
|
}
|
646
|
-
|
647
|
-
}
|
648
|
-
function concatHex(values) {
|
649
|
-
return `0x${values.reduce(
|
650
|
-
(acc, x) => acc + x.replace("0x", ""),
|
651
|
-
""
|
652
|
-
)}`;
|
653
|
-
}
|
676
|
+
];
|
654
677
|
|
655
|
-
// src/
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
678
|
+
// src/constants/solidity.ts
|
679
|
+
var panicReasons = {
|
680
|
+
1: "An `assert` condition failed.",
|
681
|
+
17: "Arithmic operation resulted in underflow or overflow.",
|
682
|
+
18: "Division or modulo by zero (e.g. `5 / 0` or `23 % 0`).",
|
683
|
+
33: "Attempted to convert to an invalid type.",
|
684
|
+
34: "Attempted to access a storage byte array that is incorrectly encoded.",
|
685
|
+
49: "Performed `.pop()` on an empty array",
|
686
|
+
50: "Array index is out of bounds.",
|
687
|
+
65: "Allocated too much memory or created an array which is too large.",
|
688
|
+
81: "Attempted to call a zero-initialized variable of internal function type."
|
689
|
+
};
|
690
|
+
var solidityError = {
|
691
|
+
inputs: [
|
692
|
+
{
|
693
|
+
name: "message",
|
694
|
+
type: "string"
|
695
|
+
}
|
696
|
+
],
|
697
|
+
name: "Error",
|
698
|
+
type: "error"
|
699
|
+
};
|
700
|
+
var solidityPanic = {
|
701
|
+
inputs: [
|
702
|
+
{
|
703
|
+
name: "reason",
|
704
|
+
type: "uint256"
|
705
|
+
}
|
706
|
+
],
|
707
|
+
name: "Panic",
|
708
|
+
type: "error"
|
709
|
+
};
|
665
710
|
|
666
|
-
// src/
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
711
|
+
// src/constants/unit.ts
|
712
|
+
var etherUnits = {
|
713
|
+
gwei: 9,
|
714
|
+
wei: 18
|
715
|
+
};
|
716
|
+
var gweiUnits = {
|
717
|
+
ether: -9,
|
718
|
+
wei: 9
|
719
|
+
};
|
720
|
+
var weiUnits = {
|
721
|
+
ether: -18,
|
722
|
+
gwei: -9
|
723
|
+
};
|
674
724
|
|
675
|
-
// src/
|
676
|
-
function
|
677
|
-
|
678
|
-
|
679
|
-
|
725
|
+
// src/errors/transaction.ts
|
726
|
+
function prettyPrint(args) {
|
727
|
+
const entries = Object.entries(args).map(([key, value]) => {
|
728
|
+
if (value === void 0 || value === false)
|
729
|
+
return null;
|
730
|
+
return [key, value];
|
731
|
+
}).filter(Boolean);
|
732
|
+
const maxLength = entries.reduce((acc, [key]) => Math.max(acc, key.length), 0);
|
733
|
+
return entries.map(([key, value]) => ` ${`${key}:`.padEnd(maxLength + 1)} ${value}`).join("\n");
|
680
734
|
}
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
735
|
+
var FeeConflictError = class extends BaseError {
|
736
|
+
constructor() {
|
737
|
+
super(
|
738
|
+
[
|
739
|
+
"Cannot specify both a `gasPrice` and a `maxFeePerGas`/`maxPriorityFeePerGas`.",
|
740
|
+
"Use `maxFeePerGas`/`maxPriorityFeePerGas` for EIP-1559 compatible networks, and `gasPrice` for others."
|
741
|
+
].join("\n")
|
742
|
+
);
|
743
|
+
__publicField(this, "name", "FeeConflictError");
|
744
|
+
}
|
745
|
+
};
|
746
|
+
var TransactionExecutionError = class extends BaseError {
|
747
|
+
constructor(cause, {
|
748
|
+
account,
|
749
|
+
docsPath: docsPath6,
|
750
|
+
chain,
|
751
|
+
data,
|
752
|
+
gas,
|
753
|
+
gasPrice,
|
754
|
+
maxFeePerGas,
|
755
|
+
maxPriorityFeePerGas,
|
756
|
+
nonce,
|
757
|
+
to,
|
758
|
+
value
|
759
|
+
}) {
|
760
|
+
const prettyArgs = prettyPrint({
|
761
|
+
chain: chain && `${chain?.name} (id: ${chain?.id})`,
|
762
|
+
from: account?.address,
|
763
|
+
to,
|
764
|
+
value: typeof value !== "undefined" && `${formatEther(value)} ${chain?.nativeCurrency.symbol || "ETH"}`,
|
765
|
+
data,
|
766
|
+
gas,
|
767
|
+
gasPrice: typeof gasPrice !== "undefined" && `${formatGwei(gasPrice)} gwei`,
|
768
|
+
maxFeePerGas: typeof maxFeePerGas !== "undefined" && `${formatGwei(maxFeePerGas)} gwei`,
|
769
|
+
maxPriorityFeePerGas: typeof maxPriorityFeePerGas !== "undefined" && `${formatGwei(maxPriorityFeePerGas)} gwei`,
|
770
|
+
nonce
|
690
771
|
});
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
if (bytes.length > size2)
|
700
|
-
throw new SizeExceedsPaddingSizeError({
|
701
|
-
size: bytes.length,
|
702
|
-
targetSize: size2,
|
703
|
-
type: "bytes"
|
772
|
+
super(cause.shortMessage, {
|
773
|
+
cause,
|
774
|
+
docsPath: docsPath6,
|
775
|
+
metaMessages: [
|
776
|
+
...cause.metaMessages ? [...cause.metaMessages, " "] : [],
|
777
|
+
"Request Arguments:",
|
778
|
+
prettyArgs
|
779
|
+
].filter(Boolean)
|
704
780
|
});
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
paddedBytes[padEnd ? i : size2 - i - 1] = bytes[padEnd ? i : bytes.length - i - 1];
|
709
|
-
}
|
710
|
-
return paddedBytes;
|
711
|
-
}
|
712
|
-
|
713
|
-
// src/utils/data/trim.ts
|
714
|
-
function trim(hexOrBytes, { dir = "left" } = {}) {
|
715
|
-
let data = typeof hexOrBytes === "string" ? hexOrBytes.replace("0x", "") : hexOrBytes;
|
716
|
-
let sliceLength = 0;
|
717
|
-
for (let i = 0; i < data.length - 1; i++) {
|
718
|
-
if (data[dir === "left" ? i : data.length - i - 1].toString() === "0")
|
719
|
-
sliceLength++;
|
720
|
-
else
|
721
|
-
break;
|
722
|
-
}
|
723
|
-
data = dir === "left" ? data.slice(sliceLength) : data.slice(0, data.length - sliceLength);
|
724
|
-
if (typeof hexOrBytes === "string") {
|
725
|
-
if (data.length === 1 && dir === "right")
|
726
|
-
data = `${data}0`;
|
727
|
-
return `0x${data}`;
|
728
|
-
}
|
729
|
-
return data;
|
730
|
-
}
|
731
|
-
|
732
|
-
// src/utils/data/size.ts
|
733
|
-
function size(value) {
|
734
|
-
if (isHex(value))
|
735
|
-
return Math.ceil((value.length - 2) / 2);
|
736
|
-
return value.length;
|
737
|
-
}
|
738
|
-
|
739
|
-
// src/utils/data/slice.ts
|
740
|
-
function slice(value, start, end) {
|
741
|
-
if (isHex(value))
|
742
|
-
return sliceHex(value, start, end);
|
743
|
-
return sliceBytes(value, start, end);
|
744
|
-
}
|
745
|
-
function assertStartOffset(value, start) {
|
746
|
-
if (typeof start === "number" && start > 0 && start > size(value) - 1)
|
747
|
-
throw new Error(
|
748
|
-
`Slice starting at offset "${start}" is out-of-bounds (size: ${size(
|
749
|
-
value
|
750
|
-
)}).`
|
751
|
-
);
|
752
|
-
}
|
753
|
-
function sliceBytes(value, start, end) {
|
754
|
-
assertStartOffset(value, start);
|
755
|
-
return value.slice(start, end);
|
756
|
-
}
|
757
|
-
function sliceHex(value_, start, end) {
|
758
|
-
assertStartOffset(value_, start);
|
759
|
-
const value = value_.replace("0x", "").slice((start ?? 0) * 2, (end ?? value_.length) * 2);
|
760
|
-
return `0x${value}`;
|
761
|
-
}
|
762
|
-
|
763
|
-
// src/utils/encoding/toHex.ts
|
764
|
-
var hexes = Array.from(
|
765
|
-
{ length: 256 },
|
766
|
-
(_v, i) => i.toString(16).padStart(2, "0")
|
767
|
-
);
|
768
|
-
function boolToHex(value) {
|
769
|
-
return `0x${Number(value)}`;
|
770
|
-
}
|
771
|
-
function bytesToHex(value) {
|
772
|
-
let hex = "";
|
773
|
-
for (let i = 0; i < value.length; i++) {
|
774
|
-
hex += hexes[value[i]];
|
775
|
-
}
|
776
|
-
return `0x${hex}`;
|
777
|
-
}
|
778
|
-
function toHex(value) {
|
779
|
-
if (typeof value === "number" || typeof value === "bigint")
|
780
|
-
return numberToHex(value);
|
781
|
-
if (typeof value === "string") {
|
782
|
-
return stringToHex(value);
|
783
|
-
}
|
784
|
-
if (typeof value === "boolean")
|
785
|
-
return boolToHex(value);
|
786
|
-
return bytesToHex(value);
|
787
|
-
}
|
788
|
-
function numberToHex(value_, opts = {}) {
|
789
|
-
const { signed, size: size2 } = opts;
|
790
|
-
let value = BigInt(value_);
|
791
|
-
let maxValue;
|
792
|
-
if (size2) {
|
793
|
-
if (signed)
|
794
|
-
maxValue = (1n << BigInt(size2) * 8n - 1n) - 1n;
|
795
|
-
else
|
796
|
-
maxValue = 2n ** (BigInt(size2) * 8n) - 1n;
|
797
|
-
} else if (typeof value_ === "number") {
|
798
|
-
maxValue = BigInt(Number.MAX_SAFE_INTEGER);
|
799
|
-
}
|
800
|
-
const minValue = typeof maxValue === "bigint" && signed ? -maxValue - 1n : 0;
|
801
|
-
if (maxValue && value > maxValue || value < minValue) {
|
802
|
-
const suffix = typeof value_ === "bigint" ? "n" : "";
|
803
|
-
throw new IntegerOutOfRangeError({
|
804
|
-
max: maxValue ? `${maxValue}${suffix}` : void 0,
|
805
|
-
min: `${minValue}${suffix}`,
|
806
|
-
signed,
|
807
|
-
size: size2,
|
808
|
-
value: `${value_}${suffix}`
|
809
|
-
});
|
810
|
-
}
|
811
|
-
const hex = `0x${(signed && value < 0 ? (1n << BigInt(size2 * 8)) + BigInt(value) : value).toString(16)}`;
|
812
|
-
if (size2)
|
813
|
-
return pad(hex, { size: size2 });
|
814
|
-
return hex;
|
815
|
-
}
|
816
|
-
var encoder = new TextEncoder();
|
817
|
-
function stringToHex(value_) {
|
818
|
-
const value = encoder.encode(value_);
|
819
|
-
return toHex(value);
|
820
|
-
}
|
821
|
-
|
822
|
-
// src/utils/encoding/toBytes.ts
|
823
|
-
var encoder2 = new TextEncoder();
|
824
|
-
function toBytes(value) {
|
825
|
-
if (typeof value === "number" || typeof value === "bigint")
|
826
|
-
return numberToBytes(value);
|
827
|
-
if (typeof value === "boolean")
|
828
|
-
return boolToBytes(value);
|
829
|
-
if (value.startsWith("0x"))
|
830
|
-
return hexToBytes(value);
|
831
|
-
return stringToBytes(value);
|
832
|
-
}
|
833
|
-
function boolToBytes(value) {
|
834
|
-
const bytes = new Uint8Array(1);
|
835
|
-
bytes[0] = Number(value);
|
836
|
-
return bytes;
|
837
|
-
}
|
838
|
-
function hexToBytes(hex_) {
|
839
|
-
let hex = hex_.slice(2);
|
840
|
-
if (hex.length % 2)
|
841
|
-
hex = `0${hex}`;
|
842
|
-
const bytes = new Uint8Array(hex.length / 2);
|
843
|
-
for (let index = 0; index < bytes.length; index++) {
|
844
|
-
const start = index * 2;
|
845
|
-
const hexByte = hex.slice(start, start + 2);
|
846
|
-
const byte = Number.parseInt(hexByte, 16);
|
847
|
-
if (Number.isNaN(byte) || byte < 0)
|
848
|
-
throw new BaseError(`Invalid byte sequence ("${hexByte}" in "${hex}").`);
|
849
|
-
bytes[index] = byte;
|
850
|
-
}
|
851
|
-
return bytes;
|
852
|
-
}
|
853
|
-
function numberToBytes(value, opts) {
|
854
|
-
const hex = numberToHex(value, opts);
|
855
|
-
return hexToBytes(hex);
|
856
|
-
}
|
857
|
-
function stringToBytes(value) {
|
858
|
-
return encoder2.encode(value);
|
859
|
-
}
|
860
|
-
|
861
|
-
// src/utils/encoding/toRlp.ts
|
862
|
-
function toRlp(hexOrBytes, to_) {
|
863
|
-
const to = to_ || "hex";
|
864
|
-
return format(bytesToRlp(parse(hexOrBytes)), to);
|
865
|
-
}
|
866
|
-
function parse(hexOrBytes) {
|
867
|
-
if (Array.isArray(hexOrBytes))
|
868
|
-
return hexOrBytes.map(parse);
|
869
|
-
return typeof hexOrBytes === "string" ? toBytes(hexOrBytes) : hexOrBytes;
|
870
|
-
}
|
871
|
-
function format(bytes, type = "bytes") {
|
872
|
-
return type === "hex" ? bytesToHex(bytes) : bytes;
|
873
|
-
}
|
874
|
-
function bytesToRlp(bytes) {
|
875
|
-
if (Array.isArray(bytes)) {
|
876
|
-
const encoded = concat(bytes.map(bytesToRlp));
|
877
|
-
return new Uint8Array([...encodeLength(encoded.length, 192), ...encoded]);
|
878
|
-
}
|
879
|
-
if (bytes.length === 1 && bytes[0] < 128)
|
880
|
-
return bytes;
|
881
|
-
return new Uint8Array([...encodeLength(bytes.length, 128), ...bytes]);
|
882
|
-
}
|
883
|
-
function encodeLength(length, offset) {
|
884
|
-
if (length < 56)
|
885
|
-
return [offset + length];
|
886
|
-
return [toBytes(length).length + offset + 55, ...toBytes(length)];
|
887
|
-
}
|
888
|
-
|
889
|
-
// src/utils/encoding/fromHex.ts
|
890
|
-
function fromHex(hex, to) {
|
891
|
-
if (to === "number")
|
892
|
-
return hexToNumber(hex);
|
893
|
-
if (to === "bigint")
|
894
|
-
return hexToBigInt(hex);
|
895
|
-
if (to === "string")
|
896
|
-
return hexToString(hex);
|
897
|
-
if (to === "boolean")
|
898
|
-
return hexToBool(hex);
|
899
|
-
return hexToBytes(hex);
|
900
|
-
}
|
901
|
-
function hexToBigInt(hex, opts = {}) {
|
902
|
-
const { signed } = opts;
|
903
|
-
const value = BigInt(hex);
|
904
|
-
if (!signed)
|
905
|
-
return value;
|
906
|
-
const size2 = (hex.length - 2) / 2;
|
907
|
-
const max = (1n << BigInt(size2) * 8n - 1n) - 1n;
|
908
|
-
if (value <= max)
|
909
|
-
return value;
|
910
|
-
return value - BigInt(`0x${"f".padStart(size2 * 2, "f")}`) - 1n;
|
911
|
-
}
|
912
|
-
function hexToBool(hex) {
|
913
|
-
if (trim(hex) === "0x0")
|
914
|
-
return false;
|
915
|
-
if (trim(hex) === "0x1")
|
916
|
-
return true;
|
917
|
-
throw new InvalidHexBooleanError(hex);
|
918
|
-
}
|
919
|
-
function hexToNumber(hex, opts = {}) {
|
920
|
-
return Number(hexToBigInt(hex, opts));
|
921
|
-
}
|
922
|
-
function hexToString(hex) {
|
923
|
-
const bytes = hexToBytes(hex);
|
924
|
-
return new TextDecoder().decode(bytes);
|
925
|
-
}
|
926
|
-
|
927
|
-
// src/utils/encoding/fromBytes.ts
|
928
|
-
function fromBytes(bytes, to) {
|
929
|
-
if (to === "number")
|
930
|
-
return bytesToNumber(bytes);
|
931
|
-
if (to === "bigint")
|
932
|
-
return bytesToBigint(bytes);
|
933
|
-
if (to === "boolean")
|
934
|
-
return bytesToBool(bytes);
|
935
|
-
if (to === "string")
|
936
|
-
return bytesToString(bytes);
|
937
|
-
return bytesToHex(bytes);
|
938
|
-
}
|
939
|
-
function bytesToBigint(bytes) {
|
940
|
-
const hex = bytesToHex(bytes);
|
941
|
-
return hexToBigInt(hex);
|
942
|
-
}
|
943
|
-
function bytesToBool(bytes) {
|
944
|
-
if (bytes.length > 1 || bytes[0] > 1)
|
945
|
-
throw new InvalidBytesBooleanError(bytes);
|
946
|
-
return Boolean(bytes[0]);
|
947
|
-
}
|
948
|
-
function bytesToNumber(bytes) {
|
949
|
-
const hex = bytesToHex(bytes);
|
950
|
-
return hexToNumber(hex);
|
951
|
-
}
|
952
|
-
function bytesToString(bytes) {
|
953
|
-
return new TextDecoder().decode(bytes);
|
954
|
-
}
|
955
|
-
|
956
|
-
// src/utils/encoding/fromRlp.ts
|
957
|
-
function fromRlp(value, to) {
|
958
|
-
const bytes = parse2(value);
|
959
|
-
const [data, consumed] = rlpToBytes(bytes);
|
960
|
-
if (consumed < bytes.length)
|
961
|
-
throw new DataLengthTooLongError({
|
962
|
-
consumed,
|
963
|
-
length: bytes.length
|
964
|
-
});
|
965
|
-
return format2(data, to);
|
966
|
-
}
|
967
|
-
function parse2(value) {
|
968
|
-
if (typeof value === "string") {
|
969
|
-
if (value.length > 3 && value.length % 2 !== 0)
|
970
|
-
throw new InvalidHexValueError(value);
|
971
|
-
return hexToBytes(value);
|
972
|
-
}
|
973
|
-
return value;
|
974
|
-
}
|
975
|
-
function format2(bytes, to) {
|
976
|
-
if (Array.isArray(bytes))
|
977
|
-
return bytes.map((b) => format2(b, to));
|
978
|
-
return to === "hex" ? trim(bytesToHex(bytes)) : bytes;
|
979
|
-
}
|
980
|
-
function rlpToBytes(bytes, offset = 0) {
|
981
|
-
if (bytes.length === 0)
|
982
|
-
return [new Uint8Array([]), 0];
|
983
|
-
const prefix = bytes[offset];
|
984
|
-
if (prefix <= 127)
|
985
|
-
return [new Uint8Array([bytes[offset]]), 1];
|
986
|
-
if (prefix <= 183) {
|
987
|
-
const length2 = prefix - 128;
|
988
|
-
const offset_ = offset + 1;
|
989
|
-
if (offset_ + length2 > bytes.length)
|
990
|
-
throw new DataLengthTooShortError({
|
991
|
-
length: offset_ + length2,
|
992
|
-
dataLength: bytes.length
|
993
|
-
});
|
994
|
-
return [bytes.slice(offset_, offset_ + length2), 1 + length2];
|
995
|
-
}
|
996
|
-
if (prefix <= 191) {
|
997
|
-
const lengthOfLength2 = prefix - 183;
|
998
|
-
const offset_ = offset + 1;
|
999
|
-
const length2 = bytesToNumber(bytes.slice(offset_, offset_ + lengthOfLength2));
|
1000
|
-
if (offset_ + lengthOfLength2 + length2 > bytes.length)
|
1001
|
-
throw new DataLengthTooShortError({
|
1002
|
-
length: lengthOfLength2 + length2,
|
1003
|
-
dataLength: bytes.length - lengthOfLength2
|
1004
|
-
});
|
1005
|
-
return [
|
1006
|
-
bytes.slice(offset_ + lengthOfLength2, offset_ + lengthOfLength2 + length2),
|
1007
|
-
1 + lengthOfLength2 + length2
|
1008
|
-
];
|
1009
|
-
}
|
1010
|
-
let lengthOfLength = 0;
|
1011
|
-
let length = prefix - 192;
|
1012
|
-
if (prefix > 247) {
|
1013
|
-
lengthOfLength = prefix - 247;
|
1014
|
-
length = bytesToNumber(bytes.slice(offset + 1, offset + 1 + lengthOfLength));
|
1015
|
-
}
|
1016
|
-
let nextOffset = offset + 1 + lengthOfLength;
|
1017
|
-
if (nextOffset > bytes.length)
|
1018
|
-
throw new DataLengthTooShortError({
|
1019
|
-
length: nextOffset,
|
1020
|
-
dataLength: bytes.length
|
1021
|
-
});
|
1022
|
-
let consumed = 1 + lengthOfLength + length;
|
1023
|
-
let result = [];
|
1024
|
-
while (nextOffset < offset + consumed) {
|
1025
|
-
const decoded = rlpToBytes(bytes, nextOffset);
|
1026
|
-
result.push(decoded[0]);
|
1027
|
-
nextOffset += decoded[1];
|
1028
|
-
if (nextOffset > offset + consumed)
|
1029
|
-
throw new OffsetOutOfBoundsError({
|
1030
|
-
nextOffset,
|
1031
|
-
offset: offset + consumed
|
1032
|
-
});
|
1033
|
-
}
|
1034
|
-
return [result, consumed];
|
1035
|
-
}
|
1036
|
-
|
1037
|
-
// src/utils/contract/extractFunctionParts.ts
|
1038
|
-
var paramsRegex = /((function|event)\s)?(.*)(\((.*)\))/;
|
1039
|
-
function extractFunctionParts(def) {
|
1040
|
-
const parts = def.match(paramsRegex);
|
1041
|
-
const type = parts?.[2] || void 0;
|
1042
|
-
const name = parts?.[3];
|
1043
|
-
const params = parts?.[5] || void 0;
|
1044
|
-
return { type, name, params };
|
1045
|
-
}
|
1046
|
-
function extractFunctionName(def) {
|
1047
|
-
return extractFunctionParts(def).name;
|
1048
|
-
}
|
1049
|
-
function extractFunctionParams(def) {
|
1050
|
-
const params = extractFunctionParts(def).params;
|
1051
|
-
const splitParams = params?.split(",").map((x) => x.trim().split(" "));
|
1052
|
-
return splitParams?.map((param) => ({
|
1053
|
-
type: param[0],
|
1054
|
-
name: param[1] === "indexed" ? param[2] : param[1],
|
1055
|
-
...param[1] === "indexed" ? { indexed: true } : {}
|
1056
|
-
}));
|
1057
|
-
}
|
1058
|
-
function extractFunctionType(def) {
|
1059
|
-
return extractFunctionParts(def).type;
|
1060
|
-
}
|
1061
|
-
|
1062
|
-
// src/utils/hash/keccak256.ts
|
1063
|
-
import { keccak_256 } from "@noble/hashes/sha3";
|
1064
|
-
function keccak256(value, to_) {
|
1065
|
-
const to = to_ || "hex";
|
1066
|
-
const bytes = keccak_256(isHex(value) ? toBytes(value) : value);
|
1067
|
-
if (to === "bytes")
|
1068
|
-
return bytes;
|
1069
|
-
return toHex(bytes);
|
1070
|
-
}
|
1071
|
-
|
1072
|
-
// src/utils/hash/hashFunction.ts
|
1073
|
-
var hash = (value) => keccak256(toBytes(value));
|
1074
|
-
function hashFunction(def) {
|
1075
|
-
const name = extractFunctionName(def);
|
1076
|
-
const params = extractFunctionParams(def);
|
1077
|
-
if (!params || params.length === 0)
|
1078
|
-
return hash(def.replace(/ /g, ""));
|
1079
|
-
return hash(`${name}(${params.map(({ type }) => type).join(",")})`);
|
1080
|
-
}
|
1081
|
-
|
1082
|
-
// src/utils/hash/getEventSelector.ts
|
1083
|
-
var getEventSelector = (event) => hashFunction(event);
|
1084
|
-
|
1085
|
-
// src/utils/hash/getFunctionSelector.ts
|
1086
|
-
var getFunctionSelector = (fn) => slice(hashFunction(fn), 0, 4);
|
1087
|
-
|
1088
|
-
// src/utils/address/isAddress.ts
|
1089
|
-
var addressRegex = /^0x[a-fA-F0-9]{40}$/;
|
1090
|
-
function isAddress(address) {
|
1091
|
-
return addressRegex.test(address);
|
1092
|
-
}
|
1093
|
-
|
1094
|
-
// src/utils/address/getAddress.ts
|
1095
|
-
function checksumAddress(address_) {
|
1096
|
-
const hexAddress = address_.substring(2).toLowerCase();
|
1097
|
-
const hash2 = keccak256(stringToBytes(hexAddress), "bytes");
|
1098
|
-
let address = hexAddress.split("");
|
1099
|
-
for (let i = 0; i < 40; i += 2) {
|
1100
|
-
if (hash2[i >> 1] >> 4 >= 8 && address[i]) {
|
1101
|
-
address[i] = address[i].toUpperCase();
|
1102
|
-
}
|
1103
|
-
if ((hash2[i >> 1] & 15) >= 8 && address[i + 1]) {
|
1104
|
-
address[i + 1] = address[i + 1].toUpperCase();
|
1105
|
-
}
|
1106
|
-
}
|
1107
|
-
return `0x${address.join("")}`;
|
1108
|
-
}
|
1109
|
-
function getAddress(address) {
|
1110
|
-
if (!isAddress(address))
|
1111
|
-
throw new InvalidAddressError({ address });
|
1112
|
-
return checksumAddress(address);
|
1113
|
-
}
|
1114
|
-
|
1115
|
-
// src/utils/address/getContractAddress.ts
|
1116
|
-
function getContractAddress2(opts) {
|
1117
|
-
if (opts.opcode === "CREATE2")
|
1118
|
-
return getCreate2Address(opts);
|
1119
|
-
return getCreateAddress(opts);
|
1120
|
-
}
|
1121
|
-
function getCreateAddress(opts) {
|
1122
|
-
const from = toBytes(getAddress(opts.from));
|
1123
|
-
let nonce = toBytes(opts.nonce);
|
1124
|
-
if (nonce[0] === 0)
|
1125
|
-
nonce = new Uint8Array([]);
|
1126
|
-
return getAddress(
|
1127
|
-
`0x${keccak256(toRlp([from, nonce], "bytes")).slice(26)}`
|
1128
|
-
);
|
1129
|
-
}
|
1130
|
-
function getCreate2Address(opts) {
|
1131
|
-
const from = toBytes(getAddress(opts.from));
|
1132
|
-
const salt = pad(isBytes(opts.salt) ? opts.salt : toBytes(opts.salt), {
|
1133
|
-
size: 32
|
1134
|
-
});
|
1135
|
-
const bytecodeHash = toBytes(
|
1136
|
-
keccak256(
|
1137
|
-
isBytes(opts.bytecode) ? opts.bytecode : toBytes(opts.bytecode)
|
1138
|
-
)
|
1139
|
-
);
|
1140
|
-
return getAddress(
|
1141
|
-
slice(keccak256(concat([toBytes("0xff"), from, salt, bytecodeHash])), 12)
|
1142
|
-
);
|
1143
|
-
}
|
1144
|
-
|
1145
|
-
// src/utils/address/isAddressEqual.ts
|
1146
|
-
function isAddressEqual(a, b) {
|
1147
|
-
if (!isAddress(a))
|
1148
|
-
throw new InvalidAddressError({ address: a });
|
1149
|
-
if (!isAddress(b))
|
1150
|
-
throw new InvalidAddressError({ address: b });
|
1151
|
-
return a.toLowerCase() === b.toLowerCase();
|
1152
|
-
}
|
1153
|
-
|
1154
|
-
// src/accounts/toAccount.ts
|
1155
|
-
function toAccount(source) {
|
1156
|
-
if (typeof source === "string") {
|
1157
|
-
if (!isAddress(source))
|
1158
|
-
throw new InvalidAddressError({ address: source });
|
1159
|
-
return {
|
1160
|
-
address: source,
|
1161
|
-
type: "json-rpc"
|
1162
|
-
};
|
1163
|
-
}
|
1164
|
-
if (!isAddress(source.address))
|
1165
|
-
throw new InvalidAddressError({ address: source.address });
|
1166
|
-
return {
|
1167
|
-
address: source.address,
|
1168
|
-
signMessage: source.signMessage,
|
1169
|
-
signTransaction: source.signTransaction,
|
1170
|
-
signTypedData: source.signTypedData,
|
1171
|
-
source: "custom",
|
1172
|
-
type: "local"
|
1173
|
-
};
|
1174
|
-
}
|
1175
|
-
|
1176
|
-
// src/constants/abis.ts
|
1177
|
-
var multicall3Abi = [
|
1178
|
-
{
|
1179
|
-
inputs: [
|
1180
|
-
{
|
1181
|
-
components: [
|
1182
|
-
{
|
1183
|
-
name: "target",
|
1184
|
-
type: "address"
|
1185
|
-
},
|
1186
|
-
{
|
1187
|
-
name: "allowFailure",
|
1188
|
-
type: "bool"
|
1189
|
-
},
|
1190
|
-
{
|
1191
|
-
name: "callData",
|
1192
|
-
type: "bytes"
|
1193
|
-
}
|
1194
|
-
],
|
1195
|
-
name: "calls",
|
1196
|
-
type: "tuple[]"
|
1197
|
-
}
|
1198
|
-
],
|
1199
|
-
name: "aggregate3",
|
1200
|
-
outputs: [
|
1201
|
-
{
|
1202
|
-
components: [
|
1203
|
-
{
|
1204
|
-
name: "success",
|
1205
|
-
type: "bool"
|
1206
|
-
},
|
1207
|
-
{
|
1208
|
-
name: "returnData",
|
1209
|
-
type: "bytes"
|
1210
|
-
}
|
1211
|
-
],
|
1212
|
-
name: "returnData",
|
1213
|
-
type: "tuple[]"
|
1214
|
-
}
|
1215
|
-
],
|
1216
|
-
stateMutability: "view",
|
1217
|
-
type: "function"
|
1218
|
-
}
|
1219
|
-
];
|
1220
|
-
|
1221
|
-
// src/constants/solidity.ts
|
1222
|
-
var panicReasons = {
|
1223
|
-
1: "An `assert` condition failed.",
|
1224
|
-
17: "Arithmic operation resulted in underflow or overflow.",
|
1225
|
-
18: "Division or modulo by zero (e.g. `5 / 0` or `23 % 0`).",
|
1226
|
-
33: "Attempted to convert to an invalid type.",
|
1227
|
-
34: "Attempted to access a storage byte array that is incorrectly encoded.",
|
1228
|
-
49: "Performed `.pop()` on an empty array",
|
1229
|
-
50: "Array index is out of bounds.",
|
1230
|
-
65: "Allocated too much memory or created an array which is too large.",
|
1231
|
-
81: "Attempted to call a zero-initialized variable of internal function type."
|
1232
|
-
};
|
1233
|
-
var solidityError = {
|
1234
|
-
inputs: [
|
1235
|
-
{
|
1236
|
-
name: "message",
|
1237
|
-
type: "string"
|
1238
|
-
}
|
1239
|
-
],
|
1240
|
-
name: "Error",
|
1241
|
-
type: "error"
|
1242
|
-
};
|
1243
|
-
var solidityPanic = {
|
1244
|
-
inputs: [
|
1245
|
-
{
|
1246
|
-
name: "reason",
|
1247
|
-
type: "uint256"
|
1248
|
-
}
|
1249
|
-
],
|
1250
|
-
name: "Panic",
|
1251
|
-
type: "error"
|
1252
|
-
};
|
1253
|
-
|
1254
|
-
// src/constants/unit.ts
|
1255
|
-
var etherUnits = {
|
1256
|
-
gwei: 9,
|
1257
|
-
wei: 18
|
1258
|
-
};
|
1259
|
-
var gweiUnits = {
|
1260
|
-
ether: -9,
|
1261
|
-
wei: 9
|
1262
|
-
};
|
1263
|
-
var weiUnits = {
|
1264
|
-
ether: -18,
|
1265
|
-
gwei: -9
|
1266
|
-
};
|
1267
|
-
|
1268
|
-
// src/errors/transaction.ts
|
1269
|
-
function prettyPrint(args) {
|
1270
|
-
const entries = Object.entries(args).map(([key, value]) => {
|
1271
|
-
if (value === void 0 || value === false)
|
1272
|
-
return null;
|
1273
|
-
return [key, value];
|
1274
|
-
}).filter(Boolean);
|
1275
|
-
const maxLength = entries.reduce((acc, [key]) => Math.max(acc, key.length), 0);
|
1276
|
-
return entries.map(([key, value]) => ` ${`${key}:`.padEnd(maxLength + 1)} ${value}`).join("\n");
|
1277
|
-
}
|
1278
|
-
var FeeConflictError = class extends BaseError {
|
1279
|
-
constructor() {
|
1280
|
-
super(
|
1281
|
-
[
|
1282
|
-
"Cannot specify both a `gasPrice` and a `maxFeePerGas`/`maxPriorityFeePerGas`.",
|
1283
|
-
"Use `maxFeePerGas`/`maxPriorityFeePerGas` for EIP-1559 compatible networks, and `gasPrice` for others."
|
1284
|
-
].join("\n")
|
1285
|
-
);
|
1286
|
-
__publicField(this, "name", "FeeConflictError");
|
1287
|
-
}
|
1288
|
-
};
|
1289
|
-
var TransactionExecutionError = class extends BaseError {
|
1290
|
-
constructor(cause, {
|
1291
|
-
account,
|
1292
|
-
docsPath: docsPath6,
|
1293
|
-
chain,
|
1294
|
-
data,
|
1295
|
-
gas,
|
1296
|
-
gasPrice,
|
1297
|
-
maxFeePerGas,
|
1298
|
-
maxPriorityFeePerGas,
|
1299
|
-
nonce,
|
1300
|
-
to,
|
1301
|
-
value
|
1302
|
-
}) {
|
1303
|
-
const prettyArgs = prettyPrint({
|
1304
|
-
chain: chain && `${chain?.name} (id: ${chain?.id})`,
|
1305
|
-
from: account?.address,
|
1306
|
-
to,
|
1307
|
-
value: typeof value !== "undefined" && `${formatEther(value)} ${chain?.nativeCurrency.symbol || "ETH"}`,
|
1308
|
-
data,
|
1309
|
-
gas,
|
1310
|
-
gasPrice: typeof gasPrice !== "undefined" && `${formatGwei(gasPrice)} gwei`,
|
1311
|
-
maxFeePerGas: typeof maxFeePerGas !== "undefined" && `${formatGwei(maxFeePerGas)} gwei`,
|
1312
|
-
maxPriorityFeePerGas: typeof maxPriorityFeePerGas !== "undefined" && `${formatGwei(maxPriorityFeePerGas)} gwei`,
|
1313
|
-
nonce
|
1314
|
-
});
|
1315
|
-
super(cause.shortMessage, {
|
1316
|
-
cause,
|
1317
|
-
docsPath: docsPath6,
|
1318
|
-
metaMessages: [
|
1319
|
-
...cause.metaMessages ? [...cause.metaMessages, " "] : [],
|
1320
|
-
"Request Arguments:",
|
1321
|
-
prettyArgs
|
1322
|
-
].filter(Boolean)
|
1323
|
-
});
|
1324
|
-
__publicField(this, "cause");
|
1325
|
-
__publicField(this, "name", "TransactionExecutionError");
|
1326
|
-
this.cause = cause;
|
781
|
+
__publicField(this, "cause");
|
782
|
+
__publicField(this, "name", "TransactionExecutionError");
|
783
|
+
this.cause = cause;
|
1327
784
|
}
|
1328
785
|
};
|
1329
786
|
var TransactionNotFoundError = class extends BaseError {
|
@@ -1913,144 +1370,669 @@ var ResourceUnavailableRpcError = class extends RpcRequestError {
|
|
1913
1370
|
__publicField(this, "code", -32002);
|
1914
1371
|
}
|
1915
1372
|
};
|
1916
|
-
var TransactionRejectedRpcError = class extends RpcRequestError {
|
1917
|
-
constructor(err) {
|
1918
|
-
super(err, { shortMessage: "Transaction creation failed." });
|
1919
|
-
__publicField(this, "name", "TransactionRejectedRpcError");
|
1920
|
-
__publicField(this, "code", -32003);
|
1373
|
+
var TransactionRejectedRpcError = class extends RpcRequestError {
|
1374
|
+
constructor(err) {
|
1375
|
+
super(err, { shortMessage: "Transaction creation failed." });
|
1376
|
+
__publicField(this, "name", "TransactionRejectedRpcError");
|
1377
|
+
__publicField(this, "code", -32003);
|
1378
|
+
}
|
1379
|
+
};
|
1380
|
+
var MethodNotSupportedRpcError = class extends RpcRequestError {
|
1381
|
+
constructor(err) {
|
1382
|
+
super(err, { shortMessage: "Method is not implemented." });
|
1383
|
+
__publicField(this, "name", "MethodNotSupportedRpcError");
|
1384
|
+
__publicField(this, "code", -32004);
|
1385
|
+
}
|
1386
|
+
};
|
1387
|
+
var LimitExceededRpcError = class extends RpcRequestError {
|
1388
|
+
constructor(err) {
|
1389
|
+
super(err, { shortMessage: "Request exceeds defined limit." });
|
1390
|
+
__publicField(this, "name", "LimitExceededRpcError");
|
1391
|
+
__publicField(this, "code", -32005);
|
1392
|
+
}
|
1393
|
+
};
|
1394
|
+
var JsonRpcVersionUnsupportedError = class extends RpcRequestError {
|
1395
|
+
constructor(err) {
|
1396
|
+
super(err, {
|
1397
|
+
shortMessage: "Version of JSON-RPC protocol is not supported."
|
1398
|
+
});
|
1399
|
+
__publicField(this, "name", "JsonRpcVersionUnsupportedError");
|
1400
|
+
__publicField(this, "code", -32006);
|
1401
|
+
}
|
1402
|
+
};
|
1403
|
+
var UserRejectedRequestError = class extends RpcRequestError {
|
1404
|
+
constructor(err) {
|
1405
|
+
super(err, {
|
1406
|
+
shortMessage: "User rejected the request."
|
1407
|
+
});
|
1408
|
+
__publicField(this, "name", "UserRejectedRequestError");
|
1409
|
+
__publicField(this, "code", 4001);
|
1410
|
+
}
|
1411
|
+
};
|
1412
|
+
var SwitchChainError = class extends RpcRequestError {
|
1413
|
+
constructor(err) {
|
1414
|
+
super(err, {
|
1415
|
+
shortMessage: "An error occurred when attempting to switch chain."
|
1416
|
+
});
|
1417
|
+
__publicField(this, "name", "SwitchChainError");
|
1418
|
+
__publicField(this, "code", 4902);
|
1419
|
+
}
|
1420
|
+
};
|
1421
|
+
var UnknownRpcError = class extends RequestError {
|
1422
|
+
constructor(err) {
|
1423
|
+
super(err, {
|
1424
|
+
shortMessage: "An unknown RPC error occurred."
|
1425
|
+
});
|
1426
|
+
__publicField(this, "name", "UnknownRpcError");
|
1427
|
+
}
|
1428
|
+
};
|
1429
|
+
|
1430
|
+
// src/errors/rpc.ts
|
1431
|
+
var HttpRequestError = class extends BaseError {
|
1432
|
+
constructor({
|
1433
|
+
body,
|
1434
|
+
details,
|
1435
|
+
headers,
|
1436
|
+
status,
|
1437
|
+
url
|
1438
|
+
}) {
|
1439
|
+
super("HTTP request failed.", {
|
1440
|
+
details,
|
1441
|
+
metaMessages: [
|
1442
|
+
status && `Status: ${status}`,
|
1443
|
+
`URL: ${getUrl(url)}`,
|
1444
|
+
`Request body: ${stringify(body)}`
|
1445
|
+
].filter(Boolean)
|
1446
|
+
});
|
1447
|
+
__publicField(this, "name", "HttpRequestError");
|
1448
|
+
__publicField(this, "body");
|
1449
|
+
__publicField(this, "headers");
|
1450
|
+
__publicField(this, "status");
|
1451
|
+
__publicField(this, "url");
|
1452
|
+
this.body = body;
|
1453
|
+
this.headers = headers;
|
1454
|
+
this.status = status;
|
1455
|
+
this.url = url;
|
1456
|
+
}
|
1457
|
+
};
|
1458
|
+
var WebSocketRequestError = class extends BaseError {
|
1459
|
+
constructor({
|
1460
|
+
body,
|
1461
|
+
details,
|
1462
|
+
url
|
1463
|
+
}) {
|
1464
|
+
super("WebSocket request failed.", {
|
1465
|
+
details,
|
1466
|
+
metaMessages: [`URL: ${getUrl(url)}`, `Request body: ${stringify(body)}`]
|
1467
|
+
});
|
1468
|
+
__publicField(this, "name", "WebSocketRequestError");
|
1469
|
+
}
|
1470
|
+
};
|
1471
|
+
var RpcError = class extends BaseError {
|
1472
|
+
constructor({
|
1473
|
+
body,
|
1474
|
+
error,
|
1475
|
+
url
|
1476
|
+
}) {
|
1477
|
+
super("RPC Request failed.", {
|
1478
|
+
cause: error,
|
1479
|
+
details: error.message,
|
1480
|
+
metaMessages: [`URL: ${getUrl(url)}`, `Request body: ${stringify(body)}`]
|
1481
|
+
});
|
1482
|
+
__publicField(this, "code");
|
1483
|
+
__publicField(this, "name", "RpcError");
|
1484
|
+
this.code = error.code;
|
1921
1485
|
}
|
1922
1486
|
};
|
1923
|
-
var
|
1924
|
-
constructor(
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1487
|
+
var TimeoutError = class extends BaseError {
|
1488
|
+
constructor({
|
1489
|
+
body,
|
1490
|
+
url
|
1491
|
+
}) {
|
1492
|
+
super("The request took too long to respond.", {
|
1493
|
+
details: "The request timed out.",
|
1494
|
+
metaMessages: [`URL: ${getUrl(url)}`, `Request body: ${stringify(body)}`]
|
1495
|
+
});
|
1496
|
+
__publicField(this, "name", "TimeoutError");
|
1928
1497
|
}
|
1929
1498
|
};
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1499
|
+
|
1500
|
+
// src/errors/transport.ts
|
1501
|
+
var UrlRequiredError = class extends BaseError {
|
1502
|
+
constructor() {
|
1503
|
+
super(
|
1504
|
+
"No URL was provided to the Transport. Please provide a valid RPC URL to the Transport.",
|
1505
|
+
{
|
1506
|
+
docsPath: "/docs/clients/intro"
|
1507
|
+
}
|
1508
|
+
);
|
1935
1509
|
}
|
1936
1510
|
};
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1940
|
-
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
1511
|
+
|
1512
|
+
// src/utils/data/concat.ts
|
1513
|
+
function concat(values) {
|
1514
|
+
if (typeof values[0] === "string")
|
1515
|
+
return concatHex(values);
|
1516
|
+
return concatBytes(values);
|
1517
|
+
}
|
1518
|
+
function concatBytes(values) {
|
1519
|
+
let length = 0;
|
1520
|
+
for (const arr of values) {
|
1521
|
+
length += arr.length;
|
1944
1522
|
}
|
1945
|
-
|
1946
|
-
|
1947
|
-
|
1948
|
-
|
1949
|
-
|
1523
|
+
const result = new Uint8Array(length);
|
1524
|
+
let offset = 0;
|
1525
|
+
for (const arr of values) {
|
1526
|
+
result.set(arr, offset);
|
1527
|
+
offset += arr.length;
|
1528
|
+
}
|
1529
|
+
return result;
|
1530
|
+
}
|
1531
|
+
function concatHex(values) {
|
1532
|
+
return `0x${values.reduce(
|
1533
|
+
(acc, x) => acc + x.replace("0x", ""),
|
1534
|
+
""
|
1535
|
+
)}`;
|
1536
|
+
}
|
1537
|
+
|
1538
|
+
// src/utils/data/isBytes.ts
|
1539
|
+
function isBytes(value) {
|
1540
|
+
if (!value)
|
1541
|
+
return false;
|
1542
|
+
if (typeof value !== "object")
|
1543
|
+
return false;
|
1544
|
+
if (!("BYTES_PER_ELEMENT" in value))
|
1545
|
+
return false;
|
1546
|
+
return value.BYTES_PER_ELEMENT === 1 && value.constructor.name === "Uint8Array";
|
1547
|
+
}
|
1548
|
+
|
1549
|
+
// src/utils/data/isHex.ts
|
1550
|
+
function isHex(value) {
|
1551
|
+
if (!value)
|
1552
|
+
return false;
|
1553
|
+
if (typeof value !== "string")
|
1554
|
+
return false;
|
1555
|
+
return /^0x[0-9a-fA-F]*$/.test(value);
|
1556
|
+
}
|
1557
|
+
|
1558
|
+
// src/utils/data/pad.ts
|
1559
|
+
function pad(hexOrBytes, { dir, size: size2 = 32 } = {}) {
|
1560
|
+
if (typeof hexOrBytes === "string")
|
1561
|
+
return padHex(hexOrBytes, { dir, size: size2 });
|
1562
|
+
return padBytes(hexOrBytes, { dir, size: size2 });
|
1563
|
+
}
|
1564
|
+
function padHex(hex_, { dir, size: size2 = 32 } = {}) {
|
1565
|
+
if (size2 === null)
|
1566
|
+
return hex_;
|
1567
|
+
let hex = hex_.replace("0x", "");
|
1568
|
+
if (hex.length > size2 * 2)
|
1569
|
+
throw new SizeExceedsPaddingSizeError({
|
1570
|
+
size: Math.ceil(hex.length / 2),
|
1571
|
+
targetSize: size2,
|
1572
|
+
type: "hex"
|
1950
1573
|
});
|
1951
|
-
|
1952
|
-
|
1574
|
+
return `0x${hex[dir === "right" ? "padEnd" : "padStart"](
|
1575
|
+
size2 * 2,
|
1576
|
+
"0"
|
1577
|
+
)}`;
|
1578
|
+
}
|
1579
|
+
function padBytes(bytes, { dir, size: size2 = 32 } = {}) {
|
1580
|
+
if (size2 === null)
|
1581
|
+
return bytes;
|
1582
|
+
if (bytes.length > size2)
|
1583
|
+
throw new SizeExceedsPaddingSizeError({
|
1584
|
+
size: bytes.length,
|
1585
|
+
targetSize: size2,
|
1586
|
+
type: "bytes"
|
1587
|
+
});
|
1588
|
+
const paddedBytes = new Uint8Array(size2);
|
1589
|
+
for (let i = 0; i < size2; i++) {
|
1590
|
+
const padEnd = dir === "right";
|
1591
|
+
paddedBytes[padEnd ? i : size2 - i - 1] = bytes[padEnd ? i : bytes.length - i - 1];
|
1953
1592
|
}
|
1954
|
-
|
1955
|
-
|
1956
|
-
|
1957
|
-
|
1958
|
-
|
1593
|
+
return paddedBytes;
|
1594
|
+
}
|
1595
|
+
|
1596
|
+
// src/utils/data/trim.ts
|
1597
|
+
function trim(hexOrBytes, { dir = "left" } = {}) {
|
1598
|
+
let data = typeof hexOrBytes === "string" ? hexOrBytes.replace("0x", "") : hexOrBytes;
|
1599
|
+
let sliceLength = 0;
|
1600
|
+
for (let i = 0; i < data.length - 1; i++) {
|
1601
|
+
if (data[dir === "left" ? i : data.length - i - 1].toString() === "0")
|
1602
|
+
sliceLength++;
|
1603
|
+
else
|
1604
|
+
break;
|
1605
|
+
}
|
1606
|
+
data = dir === "left" ? data.slice(sliceLength) : data.slice(0, data.length - sliceLength);
|
1607
|
+
if (typeof hexOrBytes === "string") {
|
1608
|
+
if (data.length === 1 && dir === "right")
|
1609
|
+
data = `${data}0`;
|
1610
|
+
return `0x${data}`;
|
1611
|
+
}
|
1612
|
+
return data;
|
1613
|
+
}
|
1614
|
+
|
1615
|
+
// src/utils/data/size.ts
|
1616
|
+
function size(value) {
|
1617
|
+
if (isHex(value))
|
1618
|
+
return Math.ceil((value.length - 2) / 2);
|
1619
|
+
return value.length;
|
1620
|
+
}
|
1621
|
+
|
1622
|
+
// src/utils/data/slice.ts
|
1623
|
+
function slice(value, start, end) {
|
1624
|
+
if (isHex(value))
|
1625
|
+
return sliceHex(value, start, end);
|
1626
|
+
return sliceBytes(value, start, end);
|
1627
|
+
}
|
1628
|
+
function assertStartOffset(value, start) {
|
1629
|
+
if (typeof start === "number" && start > 0 && start > size(value) - 1)
|
1630
|
+
throw new Error(
|
1631
|
+
`Slice starting at offset "${start}" is out-of-bounds (size: ${size(
|
1632
|
+
value
|
1633
|
+
)}).`
|
1634
|
+
);
|
1635
|
+
}
|
1636
|
+
function sliceBytes(value, start, end) {
|
1637
|
+
assertStartOffset(value, start);
|
1638
|
+
return value.slice(start, end);
|
1639
|
+
}
|
1640
|
+
function sliceHex(value_, start, end) {
|
1641
|
+
assertStartOffset(value_, start);
|
1642
|
+
const value = value_.replace("0x", "").slice((start ?? 0) * 2, (end ?? value_.length) * 2);
|
1643
|
+
return `0x${value}`;
|
1644
|
+
}
|
1645
|
+
|
1646
|
+
// src/utils/encoding/toHex.ts
|
1647
|
+
var hexes = Array.from(
|
1648
|
+
{ length: 256 },
|
1649
|
+
(_v, i) => i.toString(16).padStart(2, "0")
|
1650
|
+
);
|
1651
|
+
function boolToHex(value) {
|
1652
|
+
return `0x${Number(value)}`;
|
1653
|
+
}
|
1654
|
+
function bytesToHex(value) {
|
1655
|
+
let hex = "";
|
1656
|
+
for (let i = 0; i < value.length; i++) {
|
1657
|
+
hex += hexes[value[i]];
|
1658
|
+
}
|
1659
|
+
return `0x${hex}`;
|
1660
|
+
}
|
1661
|
+
function toHex(value) {
|
1662
|
+
if (typeof value === "number" || typeof value === "bigint")
|
1663
|
+
return numberToHex(value);
|
1664
|
+
if (typeof value === "string") {
|
1665
|
+
return stringToHex(value);
|
1666
|
+
}
|
1667
|
+
if (typeof value === "boolean")
|
1668
|
+
return boolToHex(value);
|
1669
|
+
return bytesToHex(value);
|
1670
|
+
}
|
1671
|
+
function numberToHex(value_, opts = {}) {
|
1672
|
+
const { signed, size: size2 } = opts;
|
1673
|
+
let value = BigInt(value_);
|
1674
|
+
let maxValue;
|
1675
|
+
if (size2) {
|
1676
|
+
if (signed)
|
1677
|
+
maxValue = (1n << BigInt(size2) * 8n - 1n) - 1n;
|
1678
|
+
else
|
1679
|
+
maxValue = 2n ** (BigInt(size2) * 8n) - 1n;
|
1680
|
+
} else if (typeof value_ === "number") {
|
1681
|
+
maxValue = BigInt(Number.MAX_SAFE_INTEGER);
|
1682
|
+
}
|
1683
|
+
const minValue = typeof maxValue === "bigint" && signed ? -maxValue - 1n : 0;
|
1684
|
+
if (maxValue && value > maxValue || value < minValue) {
|
1685
|
+
const suffix = typeof value_ === "bigint" ? "n" : "";
|
1686
|
+
throw new IntegerOutOfRangeError({
|
1687
|
+
max: maxValue ? `${maxValue}${suffix}` : void 0,
|
1688
|
+
min: `${minValue}${suffix}`,
|
1689
|
+
signed,
|
1690
|
+
size: size2,
|
1691
|
+
value: `${value_}${suffix}`
|
1959
1692
|
});
|
1960
|
-
__publicField(this, "name", "SwitchChainError");
|
1961
|
-
__publicField(this, "code", 4902);
|
1962
1693
|
}
|
1963
|
-
}
|
1964
|
-
|
1965
|
-
|
1966
|
-
|
1967
|
-
|
1968
|
-
|
1969
|
-
|
1694
|
+
const hex = `0x${(signed && value < 0 ? (1n << BigInt(size2 * 8)) + BigInt(value) : value).toString(16)}`;
|
1695
|
+
if (size2)
|
1696
|
+
return pad(hex, { size: size2 });
|
1697
|
+
return hex;
|
1698
|
+
}
|
1699
|
+
var encoder = new TextEncoder();
|
1700
|
+
function stringToHex(value_) {
|
1701
|
+
const value = encoder.encode(value_);
|
1702
|
+
return toHex(value);
|
1703
|
+
}
|
1704
|
+
|
1705
|
+
// src/utils/encoding/toBytes.ts
|
1706
|
+
var encoder2 = new TextEncoder();
|
1707
|
+
function toBytes(value) {
|
1708
|
+
if (typeof value === "number" || typeof value === "bigint")
|
1709
|
+
return numberToBytes(value);
|
1710
|
+
if (typeof value === "boolean")
|
1711
|
+
return boolToBytes(value);
|
1712
|
+
if (value.startsWith("0x"))
|
1713
|
+
return hexToBytes(value);
|
1714
|
+
return stringToBytes(value);
|
1715
|
+
}
|
1716
|
+
function boolToBytes(value) {
|
1717
|
+
const bytes = new Uint8Array(1);
|
1718
|
+
bytes[0] = Number(value);
|
1719
|
+
return bytes;
|
1720
|
+
}
|
1721
|
+
function hexToBytes(hex_) {
|
1722
|
+
let hex = hex_.slice(2);
|
1723
|
+
if (hex.length % 2)
|
1724
|
+
hex = `0${hex}`;
|
1725
|
+
const bytes = new Uint8Array(hex.length / 2);
|
1726
|
+
for (let index = 0; index < bytes.length; index++) {
|
1727
|
+
const start = index * 2;
|
1728
|
+
const hexByte = hex.slice(start, start + 2);
|
1729
|
+
const byte = Number.parseInt(hexByte, 16);
|
1730
|
+
if (Number.isNaN(byte) || byte < 0)
|
1731
|
+
throw new BaseError(`Invalid byte sequence ("${hexByte}" in "${hex}").`);
|
1732
|
+
bytes[index] = byte;
|
1733
|
+
}
|
1734
|
+
return bytes;
|
1735
|
+
}
|
1736
|
+
function numberToBytes(value, opts) {
|
1737
|
+
const hex = numberToHex(value, opts);
|
1738
|
+
return hexToBytes(hex);
|
1739
|
+
}
|
1740
|
+
function stringToBytes(value) {
|
1741
|
+
return encoder2.encode(value);
|
1742
|
+
}
|
1743
|
+
|
1744
|
+
// src/utils/encoding/toRlp.ts
|
1745
|
+
function toRlp(hexOrBytes, to_) {
|
1746
|
+
const to = to_ || "hex";
|
1747
|
+
return format(bytesToRlp(parse(hexOrBytes)), to);
|
1748
|
+
}
|
1749
|
+
function parse(hexOrBytes) {
|
1750
|
+
if (Array.isArray(hexOrBytes))
|
1751
|
+
return hexOrBytes.map(parse);
|
1752
|
+
return typeof hexOrBytes === "string" ? toBytes(hexOrBytes) : hexOrBytes;
|
1753
|
+
}
|
1754
|
+
function format(bytes, type = "bytes") {
|
1755
|
+
return type === "hex" ? bytesToHex(bytes) : bytes;
|
1756
|
+
}
|
1757
|
+
function bytesToRlp(bytes) {
|
1758
|
+
if (Array.isArray(bytes)) {
|
1759
|
+
const encoded = concat(bytes.map(bytesToRlp));
|
1760
|
+
return new Uint8Array([...encodeLength(encoded.length, 192), ...encoded]);
|
1970
1761
|
}
|
1971
|
-
|
1762
|
+
if (bytes.length === 1 && bytes[0] < 128)
|
1763
|
+
return bytes;
|
1764
|
+
return new Uint8Array([...encodeLength(bytes.length, 128), ...bytes]);
|
1765
|
+
}
|
1766
|
+
function encodeLength(length, offset) {
|
1767
|
+
if (length < 56)
|
1768
|
+
return [offset + length];
|
1769
|
+
return [toBytes(length).length + offset + 55, ...toBytes(length)];
|
1770
|
+
}
|
1972
1771
|
|
1973
|
-
// src/
|
1974
|
-
|
1975
|
-
|
1976
|
-
|
1977
|
-
|
1978
|
-
|
1979
|
-
|
1980
|
-
|
1981
|
-
|
1982
|
-
|
1983
|
-
|
1984
|
-
|
1985
|
-
|
1986
|
-
|
1987
|
-
|
1988
|
-
|
1772
|
+
// src/utils/encoding/fromHex.ts
|
1773
|
+
function fromHex(hex, to) {
|
1774
|
+
if (to === "number")
|
1775
|
+
return hexToNumber(hex);
|
1776
|
+
if (to === "bigint")
|
1777
|
+
return hexToBigInt(hex);
|
1778
|
+
if (to === "string")
|
1779
|
+
return hexToString(hex);
|
1780
|
+
if (to === "boolean")
|
1781
|
+
return hexToBool(hex);
|
1782
|
+
return hexToBytes(hex);
|
1783
|
+
}
|
1784
|
+
function hexToBigInt(hex, opts = {}) {
|
1785
|
+
const { signed } = opts;
|
1786
|
+
const value = BigInt(hex);
|
1787
|
+
if (!signed)
|
1788
|
+
return value;
|
1789
|
+
const size2 = (hex.length - 2) / 2;
|
1790
|
+
const max = (1n << BigInt(size2) * 8n - 1n) - 1n;
|
1791
|
+
if (value <= max)
|
1792
|
+
return value;
|
1793
|
+
return value - BigInt(`0x${"f".padStart(size2 * 2, "f")}`) - 1n;
|
1794
|
+
}
|
1795
|
+
function hexToBool(hex) {
|
1796
|
+
if (trim(hex) === "0x0")
|
1797
|
+
return false;
|
1798
|
+
if (trim(hex) === "0x1")
|
1799
|
+
return true;
|
1800
|
+
throw new InvalidHexBooleanError(hex);
|
1801
|
+
}
|
1802
|
+
function hexToNumber(hex, opts = {}) {
|
1803
|
+
return Number(hexToBigInt(hex, opts));
|
1804
|
+
}
|
1805
|
+
function hexToString(hex) {
|
1806
|
+
const bytes = hexToBytes(hex);
|
1807
|
+
return new TextDecoder().decode(bytes);
|
1808
|
+
}
|
1809
|
+
|
1810
|
+
// src/utils/encoding/fromBytes.ts
|
1811
|
+
function fromBytes(bytes, to) {
|
1812
|
+
if (to === "number")
|
1813
|
+
return bytesToNumber(bytes);
|
1814
|
+
if (to === "bigint")
|
1815
|
+
return bytesToBigint(bytes);
|
1816
|
+
if (to === "boolean")
|
1817
|
+
return bytesToBool(bytes);
|
1818
|
+
if (to === "string")
|
1819
|
+
return bytesToString(bytes);
|
1820
|
+
return bytesToHex(bytes);
|
1821
|
+
}
|
1822
|
+
function bytesToBigint(bytes) {
|
1823
|
+
const hex = bytesToHex(bytes);
|
1824
|
+
return hexToBigInt(hex);
|
1825
|
+
}
|
1826
|
+
function bytesToBool(bytes) {
|
1827
|
+
if (bytes.length > 1 || bytes[0] > 1)
|
1828
|
+
throw new InvalidBytesBooleanError(bytes);
|
1829
|
+
return Boolean(bytes[0]);
|
1830
|
+
}
|
1831
|
+
function bytesToNumber(bytes) {
|
1832
|
+
const hex = bytesToHex(bytes);
|
1833
|
+
return hexToNumber(hex);
|
1834
|
+
}
|
1835
|
+
function bytesToString(bytes) {
|
1836
|
+
return new TextDecoder().decode(bytes);
|
1837
|
+
}
|
1838
|
+
|
1839
|
+
// src/utils/encoding/fromRlp.ts
|
1840
|
+
function fromRlp(value, to) {
|
1841
|
+
const bytes = parse2(value);
|
1842
|
+
const [data, consumed] = rlpToBytes(bytes);
|
1843
|
+
if (consumed < bytes.length)
|
1844
|
+
throw new DataLengthTooLongError({
|
1845
|
+
consumed,
|
1846
|
+
length: bytes.length
|
1989
1847
|
});
|
1990
|
-
|
1991
|
-
|
1992
|
-
|
1993
|
-
|
1994
|
-
|
1995
|
-
|
1996
|
-
|
1997
|
-
this.status = status;
|
1998
|
-
this.url = url;
|
1848
|
+
return format2(data, to);
|
1849
|
+
}
|
1850
|
+
function parse2(value) {
|
1851
|
+
if (typeof value === "string") {
|
1852
|
+
if (value.length > 3 && value.length % 2 !== 0)
|
1853
|
+
throw new InvalidHexValueError(value);
|
1854
|
+
return hexToBytes(value);
|
1999
1855
|
}
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2006
|
-
|
2007
|
-
|
2008
|
-
|
2009
|
-
|
2010
|
-
|
2011
|
-
|
1856
|
+
return value;
|
1857
|
+
}
|
1858
|
+
function format2(bytes, to) {
|
1859
|
+
if (Array.isArray(bytes))
|
1860
|
+
return bytes.map((b) => format2(b, to));
|
1861
|
+
return to === "hex" ? trim(bytesToHex(bytes)) : bytes;
|
1862
|
+
}
|
1863
|
+
function rlpToBytes(bytes, offset = 0) {
|
1864
|
+
if (bytes.length === 0)
|
1865
|
+
return [new Uint8Array([]), 0];
|
1866
|
+
const prefix = bytes[offset];
|
1867
|
+
if (prefix <= 127)
|
1868
|
+
return [new Uint8Array([bytes[offset]]), 1];
|
1869
|
+
if (prefix <= 183) {
|
1870
|
+
const length2 = prefix - 128;
|
1871
|
+
const offset_ = offset + 1;
|
1872
|
+
if (offset_ + length2 > bytes.length)
|
1873
|
+
throw new DataLengthTooShortError({
|
1874
|
+
length: offset_ + length2,
|
1875
|
+
dataLength: bytes.length
|
1876
|
+
});
|
1877
|
+
return [bytes.slice(offset_, offset_ + length2), 1 + length2];
|
2012
1878
|
}
|
2013
|
-
|
2014
|
-
|
2015
|
-
|
2016
|
-
|
2017
|
-
|
2018
|
-
|
2019
|
-
|
2020
|
-
|
2021
|
-
|
2022
|
-
|
2023
|
-
|
2024
|
-
|
2025
|
-
|
2026
|
-
__publicField(this, "name", "RpcError");
|
2027
|
-
this.code = error.code;
|
1879
|
+
if (prefix <= 191) {
|
1880
|
+
const lengthOfLength2 = prefix - 183;
|
1881
|
+
const offset_ = offset + 1;
|
1882
|
+
const length2 = bytesToNumber(bytes.slice(offset_, offset_ + lengthOfLength2));
|
1883
|
+
if (offset_ + lengthOfLength2 + length2 > bytes.length)
|
1884
|
+
throw new DataLengthTooShortError({
|
1885
|
+
length: lengthOfLength2 + length2,
|
1886
|
+
dataLength: bytes.length - lengthOfLength2
|
1887
|
+
});
|
1888
|
+
return [
|
1889
|
+
bytes.slice(offset_ + lengthOfLength2, offset_ + lengthOfLength2 + length2),
|
1890
|
+
1 + lengthOfLength2 + length2
|
1891
|
+
];
|
2028
1892
|
}
|
2029
|
-
|
2030
|
-
|
2031
|
-
|
2032
|
-
|
2033
|
-
|
2034
|
-
}
|
2035
|
-
|
2036
|
-
|
2037
|
-
|
1893
|
+
let lengthOfLength = 0;
|
1894
|
+
let length = prefix - 192;
|
1895
|
+
if (prefix > 247) {
|
1896
|
+
lengthOfLength = prefix - 247;
|
1897
|
+
length = bytesToNumber(bytes.slice(offset + 1, offset + 1 + lengthOfLength));
|
1898
|
+
}
|
1899
|
+
let nextOffset = offset + 1 + lengthOfLength;
|
1900
|
+
if (nextOffset > bytes.length)
|
1901
|
+
throw new DataLengthTooShortError({
|
1902
|
+
length: nextOffset,
|
1903
|
+
dataLength: bytes.length
|
2038
1904
|
});
|
2039
|
-
|
1905
|
+
let consumed = 1 + lengthOfLength + length;
|
1906
|
+
let result = [];
|
1907
|
+
while (nextOffset < offset + consumed) {
|
1908
|
+
const decoded = rlpToBytes(bytes, nextOffset);
|
1909
|
+
result.push(decoded[0]);
|
1910
|
+
nextOffset += decoded[1];
|
1911
|
+
if (nextOffset > offset + consumed)
|
1912
|
+
throw new OffsetOutOfBoundsError({
|
1913
|
+
nextOffset,
|
1914
|
+
offset: offset + consumed
|
1915
|
+
});
|
2040
1916
|
}
|
2041
|
-
|
1917
|
+
return [result, consumed];
|
1918
|
+
}
|
2042
1919
|
|
2043
|
-
// src/
|
2044
|
-
var
|
2045
|
-
|
2046
|
-
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2050
|
-
|
2051
|
-
|
1920
|
+
// src/utils/contract/extractFunctionParts.ts
|
1921
|
+
var paramsRegex = /((function|event)\s)?(.*)(\((.*)\))/;
|
1922
|
+
function extractFunctionParts(def) {
|
1923
|
+
const parts = def.match(paramsRegex);
|
1924
|
+
const type = parts?.[2] || void 0;
|
1925
|
+
const name = parts?.[3];
|
1926
|
+
const params = parts?.[5] || void 0;
|
1927
|
+
return { type, name, params };
|
1928
|
+
}
|
1929
|
+
function extractFunctionName(def) {
|
1930
|
+
return extractFunctionParts(def).name;
|
1931
|
+
}
|
1932
|
+
function extractFunctionParams(def) {
|
1933
|
+
const params = extractFunctionParts(def).params;
|
1934
|
+
const splitParams = params?.split(",").map((x) => x.trim().split(" "));
|
1935
|
+
return splitParams?.map((param) => ({
|
1936
|
+
type: param[0],
|
1937
|
+
name: param[1] === "indexed" ? param[2] : param[1],
|
1938
|
+
...param[1] === "indexed" ? { indexed: true } : {}
|
1939
|
+
}));
|
1940
|
+
}
|
1941
|
+
function extractFunctionType(def) {
|
1942
|
+
return extractFunctionParts(def).type;
|
1943
|
+
}
|
1944
|
+
|
1945
|
+
// src/utils/hash/keccak256.ts
|
1946
|
+
import { keccak_256 } from "@noble/hashes/sha3";
|
1947
|
+
function keccak256(value, to_) {
|
1948
|
+
const to = to_ || "hex";
|
1949
|
+
const bytes = keccak_256(isHex(value) ? toBytes(value) : value);
|
1950
|
+
if (to === "bytes")
|
1951
|
+
return bytes;
|
1952
|
+
return toHex(bytes);
|
1953
|
+
}
|
1954
|
+
|
1955
|
+
// src/utils/hash/hashFunction.ts
|
1956
|
+
var hash = (value) => keccak256(toBytes(value));
|
1957
|
+
function hashFunction(def) {
|
1958
|
+
const name = extractFunctionName(def);
|
1959
|
+
const params = extractFunctionParams(def);
|
1960
|
+
if (!params || params.length === 0)
|
1961
|
+
return hash(def.replace(/ /g, ""));
|
1962
|
+
return hash(`${name}(${params.map(({ type }) => type).join(",")})`);
|
1963
|
+
}
|
1964
|
+
|
1965
|
+
// src/utils/hash/getEventSelector.ts
|
1966
|
+
var getEventSelector = (event) => hashFunction(event);
|
1967
|
+
|
1968
|
+
// src/utils/hash/getFunctionSelector.ts
|
1969
|
+
var getFunctionSelector = (fn) => slice(hashFunction(fn), 0, 4);
|
1970
|
+
|
1971
|
+
// src/utils/address/isAddress.ts
|
1972
|
+
var addressRegex = /^0x[a-fA-F0-9]{40}$/;
|
1973
|
+
function isAddress(address) {
|
1974
|
+
return addressRegex.test(address);
|
1975
|
+
}
|
1976
|
+
|
1977
|
+
// src/utils/address/getAddress.ts
|
1978
|
+
function checksumAddress(address_) {
|
1979
|
+
const hexAddress = address_.substring(2).toLowerCase();
|
1980
|
+
const hash2 = keccak256(stringToBytes(hexAddress), "bytes");
|
1981
|
+
let address = hexAddress.split("");
|
1982
|
+
for (let i = 0; i < 40; i += 2) {
|
1983
|
+
if (hash2[i >> 1] >> 4 >= 8 && address[i]) {
|
1984
|
+
address[i] = address[i].toUpperCase();
|
1985
|
+
}
|
1986
|
+
if ((hash2[i >> 1] & 15) >= 8 && address[i + 1]) {
|
1987
|
+
address[i + 1] = address[i + 1].toUpperCase();
|
1988
|
+
}
|
2052
1989
|
}
|
2053
|
-
}
|
1990
|
+
return `0x${address.join("")}`;
|
1991
|
+
}
|
1992
|
+
function getAddress(address) {
|
1993
|
+
if (!isAddress(address))
|
1994
|
+
throw new InvalidAddressError({ address });
|
1995
|
+
return checksumAddress(address);
|
1996
|
+
}
|
1997
|
+
|
1998
|
+
// src/utils/address/getContractAddress.ts
|
1999
|
+
function getContractAddress2(opts) {
|
2000
|
+
if (opts.opcode === "CREATE2")
|
2001
|
+
return getCreate2Address(opts);
|
2002
|
+
return getCreateAddress(opts);
|
2003
|
+
}
|
2004
|
+
function getCreateAddress(opts) {
|
2005
|
+
const from = toBytes(getAddress(opts.from));
|
2006
|
+
let nonce = toBytes(opts.nonce);
|
2007
|
+
if (nonce[0] === 0)
|
2008
|
+
nonce = new Uint8Array([]);
|
2009
|
+
return getAddress(
|
2010
|
+
`0x${keccak256(toRlp([from, nonce], "bytes")).slice(26)}`
|
2011
|
+
);
|
2012
|
+
}
|
2013
|
+
function getCreate2Address(opts) {
|
2014
|
+
const from = toBytes(getAddress(opts.from));
|
2015
|
+
const salt = pad(isBytes(opts.salt) ? opts.salt : toBytes(opts.salt), {
|
2016
|
+
size: 32
|
2017
|
+
});
|
2018
|
+
const bytecodeHash = toBytes(
|
2019
|
+
keccak256(
|
2020
|
+
isBytes(opts.bytecode) ? opts.bytecode : toBytes(opts.bytecode)
|
2021
|
+
)
|
2022
|
+
);
|
2023
|
+
return getAddress(
|
2024
|
+
slice(keccak256(concat([toBytes("0xff"), from, salt, bytecodeHash])), 12)
|
2025
|
+
);
|
2026
|
+
}
|
2027
|
+
|
2028
|
+
// src/utils/address/isAddressEqual.ts
|
2029
|
+
function isAddressEqual(a, b) {
|
2030
|
+
if (!isAddress(a))
|
2031
|
+
throw new InvalidAddressError({ address: a });
|
2032
|
+
if (!isAddress(b))
|
2033
|
+
throw new InvalidAddressError({ address: b });
|
2034
|
+
return a.toLowerCase() === b.toLowerCase();
|
2035
|
+
}
|
2054
2036
|
|
2055
2037
|
// src/utils/abi/encodeAbiParameters.ts
|
2056
2038
|
function encodeAbiParameters(params, values) {
|
@@ -2893,6 +2875,13 @@ function formatAbiItemWithArgs({
|
|
2893
2875
|
).join(", ")})`;
|
2894
2876
|
}
|
2895
2877
|
|
2878
|
+
// src/accounts/utils/parseAccount.ts
|
2879
|
+
function parseAccount(account) {
|
2880
|
+
if (typeof account === "string")
|
2881
|
+
return { address: account, type: "json-rpc" };
|
2882
|
+
return account;
|
2883
|
+
}
|
2884
|
+
|
2896
2885
|
// src/utils/promise/withCache.ts
|
2897
2886
|
var promiseCache = /* @__PURE__ */ new Map();
|
2898
2887
|
var responseCache = /* @__PURE__ */ new Map();
|
@@ -3767,14 +3756,14 @@ function encodeField({
|
|
3767
3756
|
}
|
3768
3757
|
|
3769
3758
|
// src/utils/signature/recoverAddress.ts
|
3770
|
-
|
3771
|
-
function recoverAddress({
|
3759
|
+
async function recoverAddress({
|
3772
3760
|
hash: hash2,
|
3773
3761
|
signature
|
3774
3762
|
}) {
|
3775
3763
|
const signatureHex = isHex(signature) ? signature : toHex(signature);
|
3776
3764
|
const hashHex = isHex(hash2) ? hash2 : toHex(hash2);
|
3777
3765
|
const v = hexToNumber(`0x${signatureHex.slice(130)}`);
|
3766
|
+
const { recoverPublicKey } = await import("@noble/secp256k1");
|
3778
3767
|
const publicKey = toHex(
|
3779
3768
|
recoverPublicKey(
|
3780
3769
|
hashHex.substring(2),
|
@@ -3787,7 +3776,7 @@ function recoverAddress({
|
|
3787
3776
|
}
|
3788
3777
|
|
3789
3778
|
// src/utils/signature/recoverMessageAddress.ts
|
3790
|
-
function recoverMessageAddress({
|
3779
|
+
async function recoverMessageAddress({
|
3791
3780
|
message,
|
3792
3781
|
signature
|
3793
3782
|
}) {
|
@@ -3795,7 +3784,7 @@ function recoverMessageAddress({
|
|
3795
3784
|
}
|
3796
3785
|
|
3797
3786
|
// src/utils/signature/recoverTypedDataAddress.ts
|
3798
|
-
function recoverTypedDataAddress({
|
3787
|
+
async function recoverTypedDataAddress({
|
3799
3788
|
domain,
|
3800
3789
|
message,
|
3801
3790
|
primaryType,
|
@@ -3814,19 +3803,19 @@ function recoverTypedDataAddress({
|
|
3814
3803
|
}
|
3815
3804
|
|
3816
3805
|
// src/utils/signature/verifyMessage.ts
|
3817
|
-
function verifyMessage({
|
3806
|
+
async function verifyMessage({
|
3818
3807
|
address,
|
3819
3808
|
message,
|
3820
3809
|
signature
|
3821
3810
|
}) {
|
3822
3811
|
return isAddressEqual(
|
3823
3812
|
getAddress(address),
|
3824
|
-
recoverMessageAddress({ message, signature })
|
3813
|
+
await recoverMessageAddress({ message, signature })
|
3825
3814
|
);
|
3826
3815
|
}
|
3827
3816
|
|
3828
3817
|
// src/utils/signature/verifyTypedData.ts
|
3829
|
-
function verifyTypedData({
|
3818
|
+
async function verifyTypedData({
|
3830
3819
|
address,
|
3831
3820
|
domain,
|
3832
3821
|
message,
|
@@ -3836,7 +3825,7 @@ function verifyTypedData({
|
|
3836
3825
|
}) {
|
3837
3826
|
return isAddressEqual(
|
3838
3827
|
getAddress(address),
|
3839
|
-
recoverTypedDataAddress({
|
3828
|
+
await recoverTypedDataAddress({
|
3840
3829
|
domain,
|
3841
3830
|
message,
|
3842
3831
|
primaryType,
|
@@ -5425,7 +5414,7 @@ async function sendTransaction(client, args) {
|
|
5425
5414
|
}
|
5426
5415
|
|
5427
5416
|
// src/actions/wallet/signMessage.ts
|
5428
|
-
async function
|
5417
|
+
async function signMessage(client, {
|
5429
5418
|
account: account_ = client.account,
|
5430
5419
|
data,
|
5431
5420
|
message
|
@@ -5667,56 +5656,6 @@ export {
|
|
5667
5656
|
InvalidAddressError,
|
5668
5657
|
BlockNotFoundError,
|
5669
5658
|
ChainDoesNotSupportContract,
|
5670
|
-
parseAccount,
|
5671
|
-
concat,
|
5672
|
-
concatBytes,
|
5673
|
-
concatHex,
|
5674
|
-
isBytes,
|
5675
|
-
isHex,
|
5676
|
-
pad,
|
5677
|
-
padHex,
|
5678
|
-
padBytes,
|
5679
|
-
trim,
|
5680
|
-
size,
|
5681
|
-
slice,
|
5682
|
-
sliceBytes,
|
5683
|
-
sliceHex,
|
5684
|
-
boolToHex,
|
5685
|
-
bytesToHex,
|
5686
|
-
toHex,
|
5687
|
-
numberToHex,
|
5688
|
-
stringToHex,
|
5689
|
-
toBytes,
|
5690
|
-
boolToBytes,
|
5691
|
-
hexToBytes,
|
5692
|
-
numberToBytes,
|
5693
|
-
stringToBytes,
|
5694
|
-
toRlp,
|
5695
|
-
fromHex,
|
5696
|
-
hexToBigInt,
|
5697
|
-
hexToBool,
|
5698
|
-
hexToNumber,
|
5699
|
-
hexToString,
|
5700
|
-
fromBytes,
|
5701
|
-
bytesToBigint,
|
5702
|
-
bytesToBool,
|
5703
|
-
bytesToNumber,
|
5704
|
-
bytesToString,
|
5705
|
-
fromRlp,
|
5706
|
-
extractFunctionParts,
|
5707
|
-
extractFunctionName,
|
5708
|
-
extractFunctionParams,
|
5709
|
-
extractFunctionType,
|
5710
|
-
keccak256,
|
5711
|
-
getEventSelector,
|
5712
|
-
getFunctionSelector,
|
5713
|
-
isAddress,
|
5714
|
-
getAddress,
|
5715
|
-
getContractAddress2 as getContractAddress,
|
5716
|
-
getCreateAddress,
|
5717
|
-
getCreate2Address,
|
5718
|
-
isAddressEqual,
|
5719
|
-
toAccount,
|
5720
5659
|
multicall3Abi,
|
5721
5660
|
panicReasons,
|
5722
5661
|
etherUnits,
|
@@ -5774,6 +5713,55 @@ export {
|
|
5774
5713
|
RpcError,
|
5775
5714
|
TimeoutError,
|
5776
5715
|
UrlRequiredError,
|
5716
|
+
concat,
|
5717
|
+
concatBytes,
|
5718
|
+
concatHex,
|
5719
|
+
isBytes,
|
5720
|
+
isHex,
|
5721
|
+
pad,
|
5722
|
+
padHex,
|
5723
|
+
padBytes,
|
5724
|
+
trim,
|
5725
|
+
size,
|
5726
|
+
slice,
|
5727
|
+
sliceBytes,
|
5728
|
+
sliceHex,
|
5729
|
+
boolToHex,
|
5730
|
+
bytesToHex,
|
5731
|
+
toHex,
|
5732
|
+
numberToHex,
|
5733
|
+
stringToHex,
|
5734
|
+
toBytes,
|
5735
|
+
boolToBytes,
|
5736
|
+
hexToBytes,
|
5737
|
+
numberToBytes,
|
5738
|
+
stringToBytes,
|
5739
|
+
toRlp,
|
5740
|
+
fromHex,
|
5741
|
+
hexToBigInt,
|
5742
|
+
hexToBool,
|
5743
|
+
hexToNumber,
|
5744
|
+
hexToString,
|
5745
|
+
fromBytes,
|
5746
|
+
bytesToBigint,
|
5747
|
+
bytesToBool,
|
5748
|
+
bytesToNumber,
|
5749
|
+
bytesToString,
|
5750
|
+
fromRlp,
|
5751
|
+
extractFunctionParts,
|
5752
|
+
extractFunctionName,
|
5753
|
+
extractFunctionParams,
|
5754
|
+
extractFunctionType,
|
5755
|
+
keccak256,
|
5756
|
+
getEventSelector,
|
5757
|
+
getFunctionSelector,
|
5758
|
+
isAddress,
|
5759
|
+
checksumAddress,
|
5760
|
+
getAddress,
|
5761
|
+
getContractAddress2 as getContractAddress,
|
5762
|
+
getCreateAddress,
|
5763
|
+
getCreate2Address,
|
5764
|
+
isAddressEqual,
|
5777
5765
|
encodeAbiParameters,
|
5778
5766
|
decodeAbiParameters,
|
5779
5767
|
formatAbiItem,
|
@@ -5796,6 +5784,7 @@ export {
|
|
5796
5784
|
parseAbiItem,
|
5797
5785
|
parseAbiParameter,
|
5798
5786
|
parseAbiParameters,
|
5787
|
+
parseAccount,
|
5799
5788
|
isDeterministicError,
|
5800
5789
|
buildRequest,
|
5801
5790
|
defineChain,
|
@@ -5898,7 +5887,7 @@ export {
|
|
5898
5887
|
requestAddresses,
|
5899
5888
|
requestPermissions,
|
5900
5889
|
sendTransaction,
|
5901
|
-
|
5890
|
+
signMessage,
|
5902
5891
|
signTypedData,
|
5903
5892
|
switchChain,
|
5904
5893
|
watchAsset,
|
@@ -5911,4 +5900,4 @@ export {
|
|
5911
5900
|
formatGwei,
|
5912
5901
|
parseEther
|
5913
5902
|
};
|
5914
|
-
//# sourceMappingURL=chunk-
|
5903
|
+
//# sourceMappingURL=chunk-IVRML3IK.mjs.map
|