viem 0.2.0-0-2-0.20230320T235312 → 0.2.0-0-2-0.20230328T063845
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.d.ts +3 -3
- package/dist/abi.js +2 -2
- package/dist/abi.mjs +1 -1
- package/dist/accounts/index.d.ts +90 -0
- package/dist/accounts/index.js +152 -0
- package/dist/accounts/index.js.map +1 -0
- package/dist/accounts/index.mjs +152 -0
- package/dist/accounts/index.mjs.map +1 -0
- package/dist/{chain-b2e88e30.d.ts → chain-5b28fc53.d.ts} +121 -85
- package/dist/{chain-c4f924cf.d.ts → chain-e9b996ff.d.ts} +1 -1
- package/dist/chains.d.ts +3 -3
- package/dist/chains.js +63 -63
- package/dist/chains.mjs +1 -1
- package/dist/{chunk-T4AH4Y6Y.js → chunk-564BCC7H.js} +813 -206
- package/dist/chunk-564BCC7H.js.map +1 -0
- package/dist/chunk-7QEOFHC7.mjs +31 -0
- package/dist/chunk-7QEOFHC7.mjs.map +1 -0
- package/dist/{chunk-4DIN6KDM.mjs → chunk-BJ5KRDTG.mjs} +2 -2
- package/dist/chunk-BJ5KRDTG.mjs.map +1 -0
- package/dist/{chunk-BLB7NERO.js → chunk-CXE4XSMF.js} +19 -19
- package/dist/chunk-CXE4XSMF.js.map +1 -0
- package/dist/chunk-D3ALNUWN.js +31 -0
- package/dist/chunk-D3ALNUWN.js.map +1 -0
- package/dist/{chunk-KOAJUBTN.mjs → chunk-UCZWRYV5.mjs} +803 -196
- package/dist/chunk-UCZWRYV5.mjs.map +1 -0
- package/dist/contract.d.ts +9 -8
- package/dist/contract.js +2 -2
- package/dist/contract.mjs +1 -1
- package/dist/{createClient-d4f1dea1.d.ts → createClient-e52de308.d.ts} +23 -9
- package/dist/{eip1193-cd3e872a.d.ts → eip1193-9080db42.d.ts} +1 -1
- package/dist/{encodeFunctionResult-750c9055.d.ts → encodeFunctionResult-47ad60ed.d.ts} +1 -1
- package/dist/{encodePacked-de74201f.d.ts → encodePacked-35c796fb.d.ts} +1 -1
- package/dist/ens.d.ts +6 -5
- package/dist/ens.js +3 -3
- package/dist/ens.mjs +2 -2
- package/dist/ethers.d.ts +5 -4
- package/dist/ethers.js +7 -5
- package/dist/ethers.js.map +1 -1
- package/dist/ethers.mjs +7 -5
- package/dist/ethers.mjs.map +1 -1
- package/dist/{formatAbiItem-fdbdda39.d.ts → formatAbiItem-d9e801dd.d.ts} +1 -1
- package/dist/{getAbiItem-9d709e3b.d.ts → getAbiItem-1d94ae0e.d.ts} +1 -1
- package/dist/index.d.ts +23 -16
- package/dist/index.js +130 -103
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -45
- package/dist/index.mjs.map +1 -1
- package/dist/parseAccount-4209fa24.d.ts +6 -0
- package/dist/{parseGwei-f930d155.d.ts → parseGwei-85b2bbc3.d.ts} +61 -18
- package/dist/public.d.ts +6 -5
- package/dist/public.js +2 -2
- package/dist/public.mjs +1 -1
- package/dist/test-f3d06763.d.ts +198 -0
- package/dist/test.d.ts +11 -11
- package/dist/test.js +2 -2
- package/dist/test.mjs +1 -1
- package/dist/{account-07d04222.d.ts → typedData-42b43450.d.ts} +46 -27
- package/dist/utils/index.d.ts +17 -35
- package/dist/utils/index.js +18 -2
- package/dist/utils/index.mjs +19 -3
- package/dist/wallet.d.ts +6 -5
- package/dist/wallet.js +2 -2
- package/dist/wallet.mjs +1 -1
- package/dist/{createPublicClient-3a714a8d.d.ts → watchPendingTransactions-ad90553c.d.ts} +336 -301
- package/dist/window.d.ts +2 -2
- package/package.json +9 -1
- package/dist/chunk-4DIN6KDM.mjs.map +0 -1
- package/dist/chunk-BLB7NERO.js.map +0 -1
- package/dist/chunk-KOAJUBTN.mjs.map +0 -1
- package/dist/chunk-T4AH4Y6Y.js.map +0 -1
- package/dist/test-c70126a6.d.ts +0 -206
@@ -20,12 +20,12 @@ import "abitype";
|
|
20
20
|
var package_default = {
|
21
21
|
name: "viem",
|
22
22
|
description: "TypeScript Interface for Ethereum",
|
23
|
-
version: "0.1.
|
23
|
+
version: "0.1.23",
|
24
24
|
scripts: {
|
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",
|
@@ -142,6 +149,8 @@ var package_default = {
|
|
142
149
|
dependencies: {
|
143
150
|
"@noble/hashes": "^1.1.2",
|
144
151
|
"@noble/secp256k1": "^1.7.1",
|
152
|
+
"@scure/bip32": "^1.2.0",
|
153
|
+
"@scure/bip39": "^1.1.1",
|
145
154
|
"@wagmi/chains": "~0.2.11",
|
146
155
|
abitype: "~0.7.1",
|
147
156
|
"idna-uts46-hx": "^4.1.2",
|
@@ -154,6 +163,7 @@ var package_default = {
|
|
154
163
|
"@adraffy/ens-normalize": "^1.8.9",
|
155
164
|
"@changesets/changelog-github": "^0.4.5",
|
156
165
|
"@changesets/cli": "^2.23.2",
|
166
|
+
"@size-limit/preset-big-lib": "^8.2.4",
|
157
167
|
"@types/dedent": "^0.7.0",
|
158
168
|
"@types/fs-extra": "^9.0.13",
|
159
169
|
"@types/node": "^17.0.45",
|
@@ -171,6 +181,7 @@ var package_default = {
|
|
171
181
|
rimraf: "^4.1.2",
|
172
182
|
rome: "^11.0.0",
|
173
183
|
"simple-git-hooks": "^2.8.1",
|
184
|
+
"size-limit": "^8.2.4",
|
174
185
|
tsup: "^6.6.0",
|
175
186
|
typescript: "^4.9.4",
|
176
187
|
vite: "^4.1.4",
|
@@ -189,12 +200,17 @@ var package_default = {
|
|
189
200
|
"wallet",
|
190
201
|
"web3"
|
191
202
|
],
|
203
|
+
"size-limit": [
|
204
|
+
{
|
205
|
+
path: "dist/index.js"
|
206
|
+
}
|
207
|
+
],
|
192
208
|
"simple-git-hooks": {
|
193
209
|
"pre-commit": "pnpm format && pnpm lint:fix"
|
194
210
|
},
|
195
211
|
pnpm: {
|
196
212
|
patchedDependencies: {
|
197
|
-
"vitepress@1.0.0-alpha.
|
213
|
+
"vitepress@1.0.0-alpha.61": "patches/vitepress@1.0.0-alpha.61.patch"
|
198
214
|
},
|
199
215
|
peerDependencyRules: {
|
200
216
|
ignoreMissing: [
|
@@ -613,6 +629,12 @@ var ChainNotFoundError = class extends BaseError {
|
|
613
629
|
__publicField(this, "name", "ChainNotFoundError");
|
614
630
|
}
|
615
631
|
};
|
632
|
+
var InvalidChainIdError = class extends BaseError {
|
633
|
+
constructor({ chainId }) {
|
634
|
+
super(`Chain ID "${chainId}" is invalid.`);
|
635
|
+
__publicField(this, "name", "InvalidChainIdError");
|
636
|
+
}
|
637
|
+
};
|
616
638
|
|
617
639
|
// src/constants/abis.ts
|
618
640
|
var multicall3Abi = [
|
@@ -727,6 +749,69 @@ var FeeConflictError = class extends BaseError {
|
|
727
749
|
__publicField(this, "name", "FeeConflictError");
|
728
750
|
}
|
729
751
|
};
|
752
|
+
var InvalidLegacyVError = class extends BaseError {
|
753
|
+
constructor({ v }) {
|
754
|
+
super(`Invalid \`v\` value "${v}". Expected 27 or 28.`);
|
755
|
+
__publicField(this, "name", "InvalidLegacyVError");
|
756
|
+
}
|
757
|
+
};
|
758
|
+
var InvalidSerializableTransactionError = class extends BaseError {
|
759
|
+
constructor({ transaction }) {
|
760
|
+
super("Cannot infer a transaction type from provided transaction.", {
|
761
|
+
metaMessages: [
|
762
|
+
"Provided Transaction:",
|
763
|
+
"{",
|
764
|
+
prettyPrint(transaction),
|
765
|
+
"}",
|
766
|
+
"",
|
767
|
+
"To infer the type, either provide:",
|
768
|
+
"- a `type` to the Transaction, or",
|
769
|
+
"- an EIP-1559 Transaction with `maxFeePerGas`, or",
|
770
|
+
"- an EIP-2930 Transaction with `gasPrice` & `accessList`, or",
|
771
|
+
"- a Legacy Transaction with `gasPrice`"
|
772
|
+
]
|
773
|
+
});
|
774
|
+
__publicField(this, "name", "InvalidSerializableTransactionError");
|
775
|
+
}
|
776
|
+
};
|
777
|
+
var InvalidSerializedTransactionTypeError = class extends BaseError {
|
778
|
+
constructor({ serializedType }) {
|
779
|
+
super(`Serialized transaction type "${serializedType}" is invalid.`);
|
780
|
+
__publicField(this, "name", "InvalidSerializedTransactionType");
|
781
|
+
__publicField(this, "serializedType");
|
782
|
+
this.serializedType = serializedType;
|
783
|
+
}
|
784
|
+
};
|
785
|
+
var InvalidSerializedTransactionError = class extends BaseError {
|
786
|
+
constructor({
|
787
|
+
attributes,
|
788
|
+
serializedTransaction,
|
789
|
+
type
|
790
|
+
}) {
|
791
|
+
const missing = Object.entries(attributes).map(([key, value]) => typeof value === "undefined" ? key : void 0).filter(Boolean);
|
792
|
+
super(`Invalid serialized transaction of type "${type}" was provided.`, {
|
793
|
+
metaMessages: [
|
794
|
+
`Serialized Transaction: "${serializedTransaction}"`,
|
795
|
+
missing.length > 0 ? `Missing Attributes: ${missing.join(", ")}` : ""
|
796
|
+
].filter(Boolean)
|
797
|
+
});
|
798
|
+
__publicField(this, "name", "InvalidSerializedTransactionError");
|
799
|
+
__publicField(this, "serializedTransaction");
|
800
|
+
__publicField(this, "type");
|
801
|
+
this.serializedTransaction = serializedTransaction;
|
802
|
+
this.type = type;
|
803
|
+
}
|
804
|
+
};
|
805
|
+
var InvalidStorageKeySizeError = class extends BaseError {
|
806
|
+
constructor({ storageKey }) {
|
807
|
+
super(
|
808
|
+
`Size for storage key "${storageKey}" is invalid. Expected 32 bytes. Got ${Math.floor(
|
809
|
+
(storageKey.length - 2) / 2
|
810
|
+
)} bytes.`
|
811
|
+
);
|
812
|
+
__publicField(this, "name", "InvalidStorageKeySizeError");
|
813
|
+
}
|
814
|
+
};
|
730
815
|
var TransactionExecutionError = class extends BaseError {
|
731
816
|
constructor(cause, {
|
732
817
|
account,
|
@@ -1842,7 +1927,7 @@ function parse2(value) {
|
|
1842
1927
|
function format2(bytes, to) {
|
1843
1928
|
if (Array.isArray(bytes))
|
1844
1929
|
return bytes.map((b) => format2(b, to));
|
1845
|
-
return to === "hex" ?
|
1930
|
+
return to === "hex" ? bytesToHex(bytes) : bytes;
|
1846
1931
|
}
|
1847
1932
|
function rlpToBytes(bytes, offset = 0) {
|
1848
1933
|
if (bytes.length === 0)
|
@@ -1952,6 +2037,11 @@ var getEventSelector = (event) => hashFunction(event);
|
|
1952
2037
|
// src/utils/hash/getFunctionSelector.ts
|
1953
2038
|
var getFunctionSelector = (fn) => slice(hashFunction(fn), 0, 4);
|
1954
2039
|
|
2040
|
+
// src/utils/hash/isHash.ts
|
2041
|
+
function isHash(hash2) {
|
2042
|
+
return hash2.startsWith("0x") && size(hash2) === 32;
|
2043
|
+
}
|
2044
|
+
|
1955
2045
|
// src/utils/address/isAddress.ts
|
1956
2046
|
var addressRegex = /^0x[a-fA-F0-9]{40}$/;
|
1957
2047
|
function isAddress(address) {
|
@@ -2859,26 +2949,7 @@ function formatAbiItemWithArgs({
|
|
2859
2949
|
).join(", ")})`;
|
2860
2950
|
}
|
2861
2951
|
|
2862
|
-
// src/utils/
|
2863
|
-
function getAccount(source) {
|
2864
|
-
if (typeof source === "string") {
|
2865
|
-
if (!isAddress(source))
|
2866
|
-
throw new InvalidAddressError({ address: source });
|
2867
|
-
return {
|
2868
|
-
address: source,
|
2869
|
-
type: "json-rpc"
|
2870
|
-
};
|
2871
|
-
}
|
2872
|
-
if (!isAddress(source.address))
|
2873
|
-
throw new InvalidAddressError({ address: source.address });
|
2874
|
-
return {
|
2875
|
-
address: source.address,
|
2876
|
-
signMessage: source.signMessage,
|
2877
|
-
signTransaction: source.signTransaction,
|
2878
|
-
signTypedData: source.signTypedData,
|
2879
|
-
type: "local"
|
2880
|
-
};
|
2881
|
-
}
|
2952
|
+
// src/accounts/utils/parseAccount.ts
|
2882
2953
|
function parseAccount(account) {
|
2883
2954
|
if (typeof account === "string")
|
2884
2955
|
return { address: account, type: "json-rpc" };
|
@@ -3549,13 +3620,59 @@ ${messageBytes.length}`
|
|
3549
3620
|
return keccak256(concat([prefixBytes, messageBytes]), to_);
|
3550
3621
|
}
|
3551
3622
|
|
3623
|
+
// src/utils/typedData.ts
|
3624
|
+
function validateTypedData({
|
3625
|
+
domain,
|
3626
|
+
message,
|
3627
|
+
primaryType,
|
3628
|
+
types: types_
|
3629
|
+
}) {
|
3630
|
+
const types = types_;
|
3631
|
+
const validateData = (struct, value_) => {
|
3632
|
+
for (const param of struct) {
|
3633
|
+
const { name, type: type_ } = param;
|
3634
|
+
const type = type_;
|
3635
|
+
const value = value_[name];
|
3636
|
+
const integerMatch = type.match(integerRegex);
|
3637
|
+
if (integerMatch && (typeof value === "number" || typeof value === "bigint")) {
|
3638
|
+
const [_type, base, size_] = integerMatch;
|
3639
|
+
numberToHex(value, {
|
3640
|
+
signed: base === "int",
|
3641
|
+
size: parseInt(size_) / 8
|
3642
|
+
});
|
3643
|
+
}
|
3644
|
+
if (type === "address" && typeof value === "string" && !isAddress(value))
|
3645
|
+
throw new InvalidAddressError({ address: value });
|
3646
|
+
const bytesMatch = type.match(bytesRegex);
|
3647
|
+
if (bytesMatch) {
|
3648
|
+
const [_type, size_] = bytesMatch;
|
3649
|
+
if (size_ && size(value) !== parseInt(size_))
|
3650
|
+
throw new BytesSizeMismatchError({
|
3651
|
+
expectedSize: parseInt(size_),
|
3652
|
+
givenSize: size(value)
|
3653
|
+
});
|
3654
|
+
}
|
3655
|
+
const struct2 = types[type];
|
3656
|
+
if (struct2)
|
3657
|
+
validateData(struct2, value);
|
3658
|
+
}
|
3659
|
+
};
|
3660
|
+
if (types["EIP712Domain"] && domain)
|
3661
|
+
validateData(types["EIP712Domain"], domain);
|
3662
|
+
if (primaryType !== "EIP712Domain") {
|
3663
|
+
const type = types[primaryType];
|
3664
|
+
validateData(type, message);
|
3665
|
+
}
|
3666
|
+
}
|
3667
|
+
|
3552
3668
|
// src/utils/signature/hashTypedData.ts
|
3553
3669
|
function hashTypedData({
|
3554
|
-
domain,
|
3670
|
+
domain: domain_,
|
3555
3671
|
message,
|
3556
3672
|
primaryType,
|
3557
3673
|
types: types_
|
3558
3674
|
}) {
|
3675
|
+
const domain = typeof domain_ === "undefined" ? {} : domain_;
|
3559
3676
|
const types = {
|
3560
3677
|
EIP712Domain: [
|
3561
3678
|
domain?.name && { name: "name", type: "string" },
|
@@ -3569,6 +3686,12 @@ function hashTypedData({
|
|
3569
3686
|
].filter(Boolean),
|
3570
3687
|
...types_
|
3571
3688
|
};
|
3689
|
+
validateTypedData({
|
3690
|
+
domain,
|
3691
|
+
message,
|
3692
|
+
primaryType,
|
3693
|
+
types
|
3694
|
+
});
|
3572
3695
|
let parts = ["0x1901"];
|
3573
3696
|
if (domain)
|
3574
3697
|
parts.push(
|
@@ -3707,14 +3830,14 @@ function encodeField({
|
|
3707
3830
|
}
|
3708
3831
|
|
3709
3832
|
// src/utils/signature/recoverAddress.ts
|
3710
|
-
|
3711
|
-
function recoverAddress({
|
3833
|
+
async function recoverAddress({
|
3712
3834
|
hash: hash2,
|
3713
3835
|
signature
|
3714
3836
|
}) {
|
3715
3837
|
const signatureHex = isHex(signature) ? signature : toHex(signature);
|
3716
3838
|
const hashHex = isHex(hash2) ? hash2 : toHex(hash2);
|
3717
3839
|
const v = hexToNumber(`0x${signatureHex.slice(130)}`);
|
3840
|
+
const { recoverPublicKey } = await import("@noble/secp256k1");
|
3718
3841
|
const publicKey = toHex(
|
3719
3842
|
recoverPublicKey(
|
3720
3843
|
hashHex.substring(2),
|
@@ -3727,7 +3850,7 @@ function recoverAddress({
|
|
3727
3850
|
}
|
3728
3851
|
|
3729
3852
|
// src/utils/signature/recoverMessageAddress.ts
|
3730
|
-
function recoverMessageAddress({
|
3853
|
+
async function recoverMessageAddress({
|
3731
3854
|
message,
|
3732
3855
|
signature
|
3733
3856
|
}) {
|
@@ -3735,7 +3858,7 @@ function recoverMessageAddress({
|
|
3735
3858
|
}
|
3736
3859
|
|
3737
3860
|
// src/utils/signature/recoverTypedDataAddress.ts
|
3738
|
-
function recoverTypedDataAddress({
|
3861
|
+
async function recoverTypedDataAddress({
|
3739
3862
|
domain,
|
3740
3863
|
message,
|
3741
3864
|
primaryType,
|
@@ -3754,19 +3877,19 @@ function recoverTypedDataAddress({
|
|
3754
3877
|
}
|
3755
3878
|
|
3756
3879
|
// src/utils/signature/verifyMessage.ts
|
3757
|
-
function verifyMessage({
|
3880
|
+
async function verifyMessage({
|
3758
3881
|
address,
|
3759
3882
|
message,
|
3760
3883
|
signature
|
3761
3884
|
}) {
|
3762
3885
|
return isAddressEqual(
|
3763
3886
|
getAddress(address),
|
3764
|
-
recoverMessageAddress({ message, signature })
|
3887
|
+
await recoverMessageAddress({ message, signature })
|
3765
3888
|
);
|
3766
3889
|
}
|
3767
3890
|
|
3768
3891
|
// src/utils/signature/verifyTypedData.ts
|
3769
|
-
function verifyTypedData({
|
3892
|
+
async function verifyTypedData({
|
3770
3893
|
address,
|
3771
3894
|
domain,
|
3772
3895
|
message,
|
@@ -3776,7 +3899,7 @@ function verifyTypedData({
|
|
3776
3899
|
}) {
|
3777
3900
|
return isAddressEqual(
|
3778
3901
|
getAddress(address),
|
3779
|
-
recoverTypedDataAddress({
|
3902
|
+
await recoverTypedDataAddress({
|
3780
3903
|
domain,
|
3781
3904
|
message,
|
3782
3905
|
primaryType,
|
@@ -3808,6 +3931,32 @@ function assertRequest(args) {
|
|
3808
3931
|
throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas });
|
3809
3932
|
}
|
3810
3933
|
|
3934
|
+
// src/utils/transaction/getSerializedTransactionType.ts
|
3935
|
+
function getSerializedTransactionType(serializedTransaction) {
|
3936
|
+
const serializedType = sliceHex(serializedTransaction, 0, 1);
|
3937
|
+
if (serializedType === "0x02")
|
3938
|
+
return "eip1559";
|
3939
|
+
if (serializedType === "0x01")
|
3940
|
+
return "eip2930";
|
3941
|
+
if (serializedType !== "0x" && hexToNumber(serializedType) >= 192)
|
3942
|
+
return "legacy";
|
3943
|
+
throw new InvalidSerializedTransactionTypeError({ serializedType });
|
3944
|
+
}
|
3945
|
+
|
3946
|
+
// src/utils/transaction/getTransactionType.ts
|
3947
|
+
function getTransactionType(transaction) {
|
3948
|
+
if (transaction.type)
|
3949
|
+
return transaction.type;
|
3950
|
+
if ("maxFeePerGas" in transaction || "maxPriorityFeePerGas" in transaction)
|
3951
|
+
return "eip1559";
|
3952
|
+
if ("gasPrice" in transaction) {
|
3953
|
+
if ("accessList" in transaction)
|
3954
|
+
return "eip2930";
|
3955
|
+
return "legacy";
|
3956
|
+
}
|
3957
|
+
throw new InvalidSerializableTransactionError({ transaction });
|
3958
|
+
}
|
3959
|
+
|
3811
3960
|
// src/actions/public/call.ts
|
3812
3961
|
async function call(client, args) {
|
3813
3962
|
const {
|
@@ -4575,6 +4724,7 @@ async function waitForTransactionReceipt(client, {
|
|
4575
4724
|
const unwatch = watchBlockNumber(client, {
|
4576
4725
|
emitMissed: true,
|
4577
4726
|
emitOnBegin: true,
|
4727
|
+
poll: true,
|
4578
4728
|
pollingInterval,
|
4579
4729
|
async onBlockNumber(blockNumber) {
|
4580
4730
|
const done = async (fn) => {
|
@@ -4667,47 +4817,79 @@ function watchBlockNumber(client, {
|
|
4667
4817
|
emitMissed = false,
|
4668
4818
|
onBlockNumber,
|
4669
4819
|
onError,
|
4820
|
+
poll: poll_,
|
4670
4821
|
pollingInterval = client.pollingInterval
|
4671
4822
|
}) {
|
4672
|
-
const
|
4673
|
-
"watchBlockNumber",
|
4674
|
-
client.uid,
|
4675
|
-
emitOnBegin,
|
4676
|
-
emitMissed,
|
4677
|
-
pollingInterval
|
4678
|
-
]);
|
4823
|
+
const enablePolling = typeof poll_ !== "undefined" ? poll_ : client.transport.type !== "webSocket";
|
4679
4824
|
let prevBlockNumber;
|
4680
|
-
|
4681
|
-
observerId
|
4682
|
-
|
4683
|
-
|
4684
|
-
|
4685
|
-
|
4686
|
-
|
4687
|
-
|
4688
|
-
|
4689
|
-
|
4690
|
-
|
4691
|
-
|
4692
|
-
|
4693
|
-
|
4825
|
+
const pollBlockNumber = () => {
|
4826
|
+
const observerId = JSON.stringify([
|
4827
|
+
"watchBlockNumber",
|
4828
|
+
client.uid,
|
4829
|
+
emitOnBegin,
|
4830
|
+
emitMissed,
|
4831
|
+
pollingInterval
|
4832
|
+
]);
|
4833
|
+
return observe(
|
4834
|
+
observerId,
|
4835
|
+
{ onBlockNumber, onError },
|
4836
|
+
(emit) => poll(
|
4837
|
+
async () => {
|
4838
|
+
try {
|
4839
|
+
const blockNumber = await getBlockNumber(client, { maxAge: 0 });
|
4840
|
+
if (prevBlockNumber) {
|
4841
|
+
if (blockNumber === prevBlockNumber)
|
4842
|
+
return;
|
4843
|
+
if (blockNumber - prevBlockNumber > 1 && emitMissed) {
|
4844
|
+
for (let i = prevBlockNumber + 1n; i < blockNumber; i++) {
|
4845
|
+
emit.onBlockNumber(i, prevBlockNumber);
|
4846
|
+
prevBlockNumber = i;
|
4847
|
+
}
|
4694
4848
|
}
|
4695
4849
|
}
|
4850
|
+
if (!prevBlockNumber || blockNumber > prevBlockNumber) {
|
4851
|
+
emit.onBlockNumber(blockNumber, prevBlockNumber);
|
4852
|
+
prevBlockNumber = blockNumber;
|
4853
|
+
}
|
4854
|
+
} catch (err) {
|
4855
|
+
emit.onError?.(err);
|
4696
4856
|
}
|
4697
|
-
|
4698
|
-
|
4857
|
+
},
|
4858
|
+
{
|
4859
|
+
emitOnBegin,
|
4860
|
+
interval: pollingInterval
|
4861
|
+
}
|
4862
|
+
)
|
4863
|
+
);
|
4864
|
+
};
|
4865
|
+
const subscribeBlockNumber = () => {
|
4866
|
+
let active = true;
|
4867
|
+
let unsubscribe = () => active = false;
|
4868
|
+
(async () => {
|
4869
|
+
try {
|
4870
|
+
const { unsubscribe: unsubscribe_ } = await client.transport.subscribe({
|
4871
|
+
params: ["newHeads"],
|
4872
|
+
onData(data) {
|
4873
|
+
if (!active)
|
4874
|
+
return;
|
4875
|
+
const blockNumber = hexToBigInt(data.result?.number);
|
4876
|
+
onBlockNumber(blockNumber, prevBlockNumber);
|
4699
4877
|
prevBlockNumber = blockNumber;
|
4878
|
+
},
|
4879
|
+
onError(error) {
|
4880
|
+
onError?.(error);
|
4700
4881
|
}
|
4701
|
-
}
|
4702
|
-
|
4703
|
-
|
4704
|
-
|
4705
|
-
{
|
4706
|
-
|
4707
|
-
interval: pollingInterval
|
4882
|
+
});
|
4883
|
+
unsubscribe = unsubscribe_;
|
4884
|
+
if (!active)
|
4885
|
+
unsubscribe();
|
4886
|
+
} catch (err) {
|
4887
|
+
onError?.(err);
|
4708
4888
|
}
|
4709
|
-
)
|
4710
|
-
|
4889
|
+
})();
|
4890
|
+
return unsubscribe;
|
4891
|
+
};
|
4892
|
+
return enablePolling ? pollBlockNumber() : subscribeBlockNumber();
|
4711
4893
|
}
|
4712
4894
|
|
4713
4895
|
// src/actions/public/watchBlocks.ts
|
@@ -4718,61 +4900,93 @@ function watchBlocks(client, {
|
|
4718
4900
|
onBlock,
|
4719
4901
|
onError,
|
4720
4902
|
includeTransactions = false,
|
4903
|
+
poll: poll_,
|
4721
4904
|
pollingInterval = client.pollingInterval
|
4722
4905
|
}) {
|
4723
|
-
const
|
4724
|
-
"watchBlocks",
|
4725
|
-
client.uid,
|
4726
|
-
emitMissed,
|
4727
|
-
emitOnBegin,
|
4728
|
-
includeTransactions,
|
4729
|
-
pollingInterval
|
4730
|
-
]);
|
4906
|
+
const enablePolling = typeof poll_ !== "undefined" ? poll_ : client.transport.type !== "webSocket";
|
4731
4907
|
let prevBlock;
|
4732
|
-
|
4733
|
-
observerId
|
4734
|
-
|
4735
|
-
|
4736
|
-
|
4737
|
-
|
4738
|
-
|
4739
|
-
|
4740
|
-
|
4741
|
-
|
4742
|
-
|
4743
|
-
|
4744
|
-
|
4745
|
-
|
4746
|
-
|
4747
|
-
|
4748
|
-
|
4749
|
-
|
4750
|
-
|
4751
|
-
|
4752
|
-
|
4908
|
+
const pollBlocks = () => {
|
4909
|
+
const observerId = JSON.stringify([
|
4910
|
+
"watchBlocks",
|
4911
|
+
client.uid,
|
4912
|
+
emitMissed,
|
4913
|
+
emitOnBegin,
|
4914
|
+
includeTransactions,
|
4915
|
+
pollingInterval
|
4916
|
+
]);
|
4917
|
+
return observe(
|
4918
|
+
observerId,
|
4919
|
+
{ onBlock, onError },
|
4920
|
+
(emit) => poll(
|
4921
|
+
async () => {
|
4922
|
+
try {
|
4923
|
+
const block = await getBlock(client, {
|
4924
|
+
blockTag,
|
4925
|
+
includeTransactions
|
4926
|
+
});
|
4927
|
+
if (block.number && prevBlock?.number) {
|
4928
|
+
if (block.number === prevBlock.number)
|
4929
|
+
return;
|
4930
|
+
if (block.number - prevBlock.number > 1 && emitMissed) {
|
4931
|
+
for (let i = prevBlock?.number + 1n; i < block.number; i++) {
|
4932
|
+
const block2 = await getBlock(client, {
|
4933
|
+
blockNumber: i,
|
4934
|
+
includeTransactions
|
4935
|
+
});
|
4936
|
+
emit.onBlock(block2, prevBlock);
|
4937
|
+
prevBlock = block2;
|
4938
|
+
}
|
4753
4939
|
}
|
4754
4940
|
}
|
4941
|
+
if (
|
4942
|
+
// If no previous block exists, emit.
|
4943
|
+
!prevBlock?.number || // If the block tag is "pending" with no block number, emit.
|
4944
|
+
blockTag === "pending" && !block?.number || // If the next block number is greater than the previous block number, emit.
|
4945
|
+
// We don't want to emit blocks in the past.
|
4946
|
+
block.number && block.number > prevBlock.number
|
4947
|
+
) {
|
4948
|
+
emit.onBlock(block, prevBlock);
|
4949
|
+
prevBlock = block;
|
4950
|
+
}
|
4951
|
+
} catch (err) {
|
4952
|
+
emit.onError?.(err);
|
4755
4953
|
}
|
4756
|
-
|
4757
|
-
|
4758
|
-
|
4759
|
-
|
4760
|
-
|
4761
|
-
|
4762
|
-
|
4763
|
-
|
4954
|
+
},
|
4955
|
+
{
|
4956
|
+
emitOnBegin,
|
4957
|
+
interval: pollingInterval
|
4958
|
+
}
|
4959
|
+
)
|
4960
|
+
);
|
4961
|
+
};
|
4962
|
+
const subscribeBlocks = () => {
|
4963
|
+
let active = true;
|
4964
|
+
let unsubscribe = () => active = false;
|
4965
|
+
(async () => {
|
4966
|
+
try {
|
4967
|
+
const { unsubscribe: unsubscribe_ } = await client.transport.subscribe({
|
4968
|
+
params: ["newHeads"],
|
4969
|
+
onData(data) {
|
4970
|
+
if (!active)
|
4971
|
+
return;
|
4972
|
+
const block = data.result;
|
4973
|
+
onBlock(block, prevBlock);
|
4764
4974
|
prevBlock = block;
|
4975
|
+
},
|
4976
|
+
onError(error) {
|
4977
|
+
onError?.(error);
|
4765
4978
|
}
|
4766
|
-
}
|
4767
|
-
|
4768
|
-
|
4769
|
-
|
4770
|
-
{
|
4771
|
-
|
4772
|
-
interval: pollingInterval
|
4979
|
+
});
|
4980
|
+
unsubscribe = unsubscribe_;
|
4981
|
+
if (!active)
|
4982
|
+
unsubscribe();
|
4983
|
+
} catch (err) {
|
4984
|
+
onError?.(err);
|
4773
4985
|
}
|
4774
|
-
)
|
4775
|
-
|
4986
|
+
})();
|
4987
|
+
return unsubscribe;
|
4988
|
+
};
|
4989
|
+
return enablePolling ? pollBlocks() : subscribeBlocks();
|
4776
4990
|
}
|
4777
4991
|
|
4778
4992
|
// src/actions/public/watchContractEvent.ts
|
@@ -4943,50 +5157,81 @@ function watchPendingTransactions(client, {
|
|
4943
5157
|
batch = true,
|
4944
5158
|
onError,
|
4945
5159
|
onTransactions,
|
5160
|
+
poll: poll_,
|
4946
5161
|
pollingInterval = client.pollingInterval
|
4947
5162
|
}) {
|
4948
|
-
const
|
4949
|
-
|
4950
|
-
|
4951
|
-
|
4952
|
-
|
4953
|
-
|
4954
|
-
|
4955
|
-
|
4956
|
-
|
4957
|
-
|
4958
|
-
|
4959
|
-
|
4960
|
-
|
4961
|
-
|
4962
|
-
|
4963
|
-
|
4964
|
-
|
4965
|
-
|
5163
|
+
const enablePolling = typeof poll_ !== "undefined" ? poll_ : client.transport.type !== "webSocket";
|
5164
|
+
const pollPendingTransactions = () => {
|
5165
|
+
const observerId = JSON.stringify([
|
5166
|
+
"watchPendingTransactions",
|
5167
|
+
client.uid,
|
5168
|
+
batch,
|
5169
|
+
pollingInterval
|
5170
|
+
]);
|
5171
|
+
return observe(observerId, { onTransactions, onError }, (emit) => {
|
5172
|
+
let filter;
|
5173
|
+
const unwatch = poll(
|
5174
|
+
async () => {
|
5175
|
+
try {
|
5176
|
+
if (!filter) {
|
5177
|
+
try {
|
5178
|
+
filter = await createPendingTransactionFilter(client);
|
5179
|
+
return;
|
5180
|
+
} catch (err) {
|
5181
|
+
unwatch();
|
5182
|
+
throw err;
|
5183
|
+
}
|
4966
5184
|
}
|
5185
|
+
const hashes = await getFilterChanges(client, { filter });
|
5186
|
+
if (hashes.length === 0)
|
5187
|
+
return;
|
5188
|
+
if (batch)
|
5189
|
+
emit.onTransactions(hashes);
|
5190
|
+
else
|
5191
|
+
hashes.forEach((hash2) => emit.onTransactions([hash2]));
|
5192
|
+
} catch (err) {
|
5193
|
+
emit.onError?.(err);
|
4967
5194
|
}
|
4968
|
-
|
4969
|
-
|
4970
|
-
|
4971
|
-
|
4972
|
-
emit.onTransactions(hashes);
|
4973
|
-
else
|
4974
|
-
hashes.forEach((hash2) => emit.onTransactions([hash2]));
|
4975
|
-
} catch (err) {
|
4976
|
-
emit.onError?.(err);
|
5195
|
+
},
|
5196
|
+
{
|
5197
|
+
emitOnBegin: true,
|
5198
|
+
interval: pollingInterval
|
4977
5199
|
}
|
4978
|
-
|
4979
|
-
{
|
4980
|
-
|
4981
|
-
|
5200
|
+
);
|
5201
|
+
return async () => {
|
5202
|
+
if (filter)
|
5203
|
+
await uninstallFilter(client, { filter });
|
5204
|
+
unwatch();
|
5205
|
+
};
|
5206
|
+
});
|
5207
|
+
};
|
5208
|
+
const subscribePendingTransactions = () => {
|
5209
|
+
let active = true;
|
5210
|
+
let unsubscribe = () => active = false;
|
5211
|
+
(async () => {
|
5212
|
+
try {
|
5213
|
+
const { unsubscribe: unsubscribe_ } = await client.transport.subscribe({
|
5214
|
+
params: ["newPendingTransactions"],
|
5215
|
+
onData(data) {
|
5216
|
+
if (!active)
|
5217
|
+
return;
|
5218
|
+
const transaction = data.result;
|
5219
|
+
onTransactions([transaction]);
|
5220
|
+
},
|
5221
|
+
onError(error) {
|
5222
|
+
onError?.(error);
|
5223
|
+
}
|
5224
|
+
});
|
5225
|
+
unsubscribe = unsubscribe_;
|
5226
|
+
if (!active)
|
5227
|
+
unsubscribe();
|
5228
|
+
} catch (err) {
|
5229
|
+
onError?.(err);
|
4982
5230
|
}
|
4983
|
-
);
|
4984
|
-
return
|
4985
|
-
|
4986
|
-
|
4987
|
-
unwatch();
|
4988
|
-
};
|
4989
|
-
});
|
5231
|
+
})();
|
5232
|
+
return unsubscribe;
|
5233
|
+
};
|
5234
|
+
return enablePolling ? pollPendingTransactions() : subscribePendingTransactions();
|
4990
5235
|
}
|
4991
5236
|
|
4992
5237
|
// src/actions/test/dropTransaction.ts
|
@@ -5367,7 +5612,6 @@ async function sendTransaction(client, args) {
|
|
5367
5612
|
// src/actions/wallet/signMessage.ts
|
5368
5613
|
async function signMessage(client, {
|
5369
5614
|
account: account_ = client.account,
|
5370
|
-
data,
|
5371
5615
|
message
|
5372
5616
|
}) {
|
5373
5617
|
if (!account_)
|
@@ -5375,12 +5619,11 @@ async function signMessage(client, {
|
|
5375
5619
|
docsPath: "/docs/actions/wallet/signMessage"
|
5376
5620
|
});
|
5377
5621
|
const account = parseAccount(account_);
|
5378
|
-
const message_ = message || data;
|
5379
5622
|
if (account.type === "local")
|
5380
|
-
return account.signMessage(
|
5623
|
+
return account.signMessage({ message });
|
5381
5624
|
return client.request({
|
5382
5625
|
method: "personal_sign",
|
5383
|
-
params: [toHex(
|
5626
|
+
params: [toHex(message), account.address]
|
5384
5627
|
});
|
5385
5628
|
}
|
5386
5629
|
|
@@ -5432,47 +5675,6 @@ async function signTypedData(client, {
|
|
5432
5675
|
params: [account.address, typedData]
|
5433
5676
|
});
|
5434
5677
|
}
|
5435
|
-
function validateTypedData({
|
5436
|
-
domain,
|
5437
|
-
message,
|
5438
|
-
primaryType,
|
5439
|
-
types: types_
|
5440
|
-
}) {
|
5441
|
-
const types = types_;
|
5442
|
-
const validateData = (struct, value_) => {
|
5443
|
-
for (const param of struct) {
|
5444
|
-
const { name, type: type_ } = param;
|
5445
|
-
const type2 = type_;
|
5446
|
-
const value = value_[name];
|
5447
|
-
const integerMatch = type2.match(integerRegex);
|
5448
|
-
if (integerMatch && (typeof value === "number" || typeof value === "bigint")) {
|
5449
|
-
const [_type, base, size_] = integerMatch;
|
5450
|
-
numberToHex(value, {
|
5451
|
-
signed: base === "int",
|
5452
|
-
size: parseInt(size_) / 8
|
5453
|
-
});
|
5454
|
-
}
|
5455
|
-
if (type2 === "address" && typeof value === "string" && !isAddress(value))
|
5456
|
-
throw new InvalidAddressError({ address: value });
|
5457
|
-
const bytesMatch = type2.match(bytesRegex);
|
5458
|
-
if (bytesMatch) {
|
5459
|
-
const [_type, size_] = bytesMatch;
|
5460
|
-
if (size_ && size(value) !== parseInt(size_))
|
5461
|
-
throw new BytesSizeMismatchError({
|
5462
|
-
expectedSize: parseInt(size_),
|
5463
|
-
givenSize: size(value)
|
5464
|
-
});
|
5465
|
-
}
|
5466
|
-
const struct2 = types[type2];
|
5467
|
-
if (struct2)
|
5468
|
-
validateData(struct2, value);
|
5469
|
-
}
|
5470
|
-
};
|
5471
|
-
if (types["EIP712Domain"] && domain)
|
5472
|
-
validateData(types["EIP712Domain"], domain);
|
5473
|
-
const type = types[primaryType];
|
5474
|
-
validateData(type, message);
|
5475
|
-
}
|
5476
5678
|
|
5477
5679
|
// src/actions/wallet/switchChain.ts
|
5478
5680
|
async function switchChain(client, { id: id2 }) {
|
@@ -5593,6 +5795,400 @@ async function prepareRequest(client, args) {
|
|
5593
5795
|
return request;
|
5594
5796
|
}
|
5595
5797
|
|
5798
|
+
// src/utils/transaction/assertTransaction.ts
|
5799
|
+
function assertTransactionEIP1559(transaction) {
|
5800
|
+
const { chainId, maxPriorityFeePerGas, gasPrice, maxFeePerGas, to } = transaction;
|
5801
|
+
if (chainId <= 0)
|
5802
|
+
throw new InvalidChainIdError({ chainId });
|
5803
|
+
if (to && !isAddress(to))
|
5804
|
+
throw new InvalidAddressError({ address: to });
|
5805
|
+
if (gasPrice)
|
5806
|
+
throw new BaseError(
|
5807
|
+
"`gasPrice` is not a valid EIP-1559 Transaction attribute."
|
5808
|
+
);
|
5809
|
+
if (maxFeePerGas && maxFeePerGas > 2n ** 256n - 1n)
|
5810
|
+
throw new FeeCapTooHighError({ maxFeePerGas });
|
5811
|
+
if (maxPriorityFeePerGas && maxFeePerGas && maxPriorityFeePerGas > maxFeePerGas)
|
5812
|
+
throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas });
|
5813
|
+
}
|
5814
|
+
function assertTransactionEIP2930(transaction) {
|
5815
|
+
const { chainId, maxPriorityFeePerGas, gasPrice, maxFeePerGas, to } = transaction;
|
5816
|
+
if (chainId <= 0)
|
5817
|
+
throw new InvalidChainIdError({ chainId });
|
5818
|
+
if (to && !isAddress(to))
|
5819
|
+
throw new InvalidAddressError({ address: to });
|
5820
|
+
if (maxPriorityFeePerGas || maxFeePerGas)
|
5821
|
+
throw new BaseError(
|
5822
|
+
"`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute."
|
5823
|
+
);
|
5824
|
+
if (gasPrice && gasPrice > 2n ** 256n - 1n)
|
5825
|
+
throw new FeeCapTooHighError({ maxFeePerGas: gasPrice });
|
5826
|
+
}
|
5827
|
+
function assertTransactionLegacy(transaction) {
|
5828
|
+
const {
|
5829
|
+
chainId,
|
5830
|
+
maxPriorityFeePerGas,
|
5831
|
+
gasPrice,
|
5832
|
+
maxFeePerGas,
|
5833
|
+
to,
|
5834
|
+
accessList
|
5835
|
+
} = transaction;
|
5836
|
+
if (to && !isAddress(to))
|
5837
|
+
throw new InvalidAddressError({ address: to });
|
5838
|
+
if (typeof chainId !== "undefined" && chainId <= 0)
|
5839
|
+
throw new InvalidChainIdError({ chainId });
|
5840
|
+
if (maxPriorityFeePerGas || maxFeePerGas)
|
5841
|
+
throw new BaseError(
|
5842
|
+
"`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute."
|
5843
|
+
);
|
5844
|
+
if (gasPrice && gasPrice > 2n ** 256n - 1n)
|
5845
|
+
throw new FeeCapTooHighError({ maxFeePerGas: gasPrice });
|
5846
|
+
if (accessList)
|
5847
|
+
throw new BaseError(
|
5848
|
+
"`accessList` is not a valid Legacy Transaction attribute."
|
5849
|
+
);
|
5850
|
+
}
|
5851
|
+
|
5852
|
+
// src/utils/transaction/parseTransaction.ts
|
5853
|
+
function parseTransaction(serializedTransaction) {
|
5854
|
+
const type = getSerializedTransactionType(serializedTransaction);
|
5855
|
+
if (type === "eip1559")
|
5856
|
+
return parseTransactionEIP1559(
|
5857
|
+
serializedTransaction
|
5858
|
+
);
|
5859
|
+
if (type === "eip2930")
|
5860
|
+
return parseTransactionEIP2930(
|
5861
|
+
serializedTransaction
|
5862
|
+
);
|
5863
|
+
return parseTransactionLegacy(
|
5864
|
+
serializedTransaction
|
5865
|
+
);
|
5866
|
+
}
|
5867
|
+
function parseTransactionEIP1559(serializedTransaction) {
|
5868
|
+
const transactionArray = fromRlp(
|
5869
|
+
`0x${serializedTransaction.slice(4)}`,
|
5870
|
+
"hex"
|
5871
|
+
);
|
5872
|
+
const [
|
5873
|
+
chainId,
|
5874
|
+
nonce,
|
5875
|
+
maxPriorityFeePerGas,
|
5876
|
+
maxFeePerGas,
|
5877
|
+
gas,
|
5878
|
+
to,
|
5879
|
+
value,
|
5880
|
+
data,
|
5881
|
+
accessList,
|
5882
|
+
v,
|
5883
|
+
r,
|
5884
|
+
s
|
5885
|
+
] = transactionArray;
|
5886
|
+
if (!(transactionArray.length === 9 || transactionArray.length === 12))
|
5887
|
+
throw new InvalidSerializedTransactionError({
|
5888
|
+
attributes: {
|
5889
|
+
chainId,
|
5890
|
+
nonce,
|
5891
|
+
maxPriorityFeePerGas,
|
5892
|
+
maxFeePerGas,
|
5893
|
+
gas,
|
5894
|
+
to,
|
5895
|
+
value,
|
5896
|
+
data,
|
5897
|
+
accessList,
|
5898
|
+
...transactionArray.length > 9 ? {
|
5899
|
+
v,
|
5900
|
+
r,
|
5901
|
+
s
|
5902
|
+
} : {}
|
5903
|
+
},
|
5904
|
+
serializedTransaction,
|
5905
|
+
type: "eip1559"
|
5906
|
+
});
|
5907
|
+
let transaction = {
|
5908
|
+
chainId: hexToNumber(chainId),
|
5909
|
+
type: "eip1559"
|
5910
|
+
};
|
5911
|
+
if (isHex(to) && to !== "0x")
|
5912
|
+
transaction.to = to;
|
5913
|
+
if (isHex(gas) && gas !== "0x")
|
5914
|
+
transaction.gas = hexToBigInt(gas);
|
5915
|
+
if (isHex(data) && data !== "0x")
|
5916
|
+
transaction.data = data;
|
5917
|
+
if (isHex(nonce) && nonce !== "0x")
|
5918
|
+
transaction.nonce = hexToNumber(nonce);
|
5919
|
+
if (isHex(value) && value !== "0x")
|
5920
|
+
transaction.value = hexToBigInt(value);
|
5921
|
+
if (isHex(maxFeePerGas) && maxFeePerGas !== "0x")
|
5922
|
+
transaction.maxFeePerGas = hexToBigInt(maxFeePerGas);
|
5923
|
+
if (isHex(maxPriorityFeePerGas) && maxPriorityFeePerGas !== "0x")
|
5924
|
+
transaction.maxPriorityFeePerGas = hexToBigInt(maxPriorityFeePerGas);
|
5925
|
+
if (accessList.length !== 0 && accessList !== "0x")
|
5926
|
+
transaction.accessList = parseAccessList(accessList);
|
5927
|
+
assertTransactionEIP1559(transaction);
|
5928
|
+
const signature = transactionArray.length === 12 ? parseEIP155Signature(transactionArray) : void 0;
|
5929
|
+
return { ...signature, ...transaction };
|
5930
|
+
}
|
5931
|
+
function parseTransactionEIP2930(serializedTransaction) {
|
5932
|
+
const transactionArray = fromRlp(
|
5933
|
+
`0x${serializedTransaction.slice(4)}`,
|
5934
|
+
"hex"
|
5935
|
+
);
|
5936
|
+
const [chainId, nonce, gasPrice, gas, to, value, data, accessList, v, r, s] = transactionArray;
|
5937
|
+
if (!(transactionArray.length === 8 || transactionArray.length === 11))
|
5938
|
+
throw new InvalidSerializedTransactionError({
|
5939
|
+
attributes: {
|
5940
|
+
chainId,
|
5941
|
+
nonce,
|
5942
|
+
gasPrice,
|
5943
|
+
gas,
|
5944
|
+
to,
|
5945
|
+
value,
|
5946
|
+
data,
|
5947
|
+
accessList,
|
5948
|
+
...transactionArray.length > 8 ? {
|
5949
|
+
v,
|
5950
|
+
r,
|
5951
|
+
s
|
5952
|
+
} : {}
|
5953
|
+
},
|
5954
|
+
serializedTransaction,
|
5955
|
+
type: "eip2930"
|
5956
|
+
});
|
5957
|
+
let transaction = {
|
5958
|
+
chainId: hexToNumber(chainId),
|
5959
|
+
type: "eip2930"
|
5960
|
+
};
|
5961
|
+
if (isHex(to) && to !== "0x")
|
5962
|
+
transaction.to = to;
|
5963
|
+
if (isHex(gas) && gas !== "0x")
|
5964
|
+
transaction.gas = hexToBigInt(gas);
|
5965
|
+
if (isHex(data) && data !== "0x")
|
5966
|
+
transaction.data = data;
|
5967
|
+
if (isHex(nonce) && nonce !== "0x")
|
5968
|
+
transaction.nonce = hexToNumber(nonce);
|
5969
|
+
if (isHex(value) && value !== "0x")
|
5970
|
+
transaction.value = hexToBigInt(value);
|
5971
|
+
if (isHex(gasPrice) && gasPrice !== "0x")
|
5972
|
+
transaction.gasPrice = hexToBigInt(gasPrice);
|
5973
|
+
if (accessList.length !== 0 && accessList !== "0x")
|
5974
|
+
transaction.accessList = parseAccessList(accessList);
|
5975
|
+
assertTransactionEIP2930(transaction);
|
5976
|
+
const signature = transactionArray.length === 11 ? parseEIP155Signature(transactionArray) : void 0;
|
5977
|
+
return { ...signature, ...transaction };
|
5978
|
+
}
|
5979
|
+
function parseTransactionLegacy(serializedTransaction) {
|
5980
|
+
const transactionArray = fromRlp(serializedTransaction, "hex");
|
5981
|
+
const [nonce, gasPrice, gas, to, value, data, chainIdOrV_, r, s] = transactionArray;
|
5982
|
+
if (!(transactionArray.length === 6 || transactionArray.length === 9))
|
5983
|
+
throw new InvalidSerializedTransactionError({
|
5984
|
+
attributes: {
|
5985
|
+
nonce,
|
5986
|
+
gasPrice,
|
5987
|
+
gas,
|
5988
|
+
to,
|
5989
|
+
value,
|
5990
|
+
data,
|
5991
|
+
...transactionArray.length > 6 ? {
|
5992
|
+
v: chainIdOrV_,
|
5993
|
+
r,
|
5994
|
+
s
|
5995
|
+
} : {}
|
5996
|
+
},
|
5997
|
+
serializedTransaction,
|
5998
|
+
type: "legacy"
|
5999
|
+
});
|
6000
|
+
let transaction = {
|
6001
|
+
type: "legacy"
|
6002
|
+
};
|
6003
|
+
if (isHex(to) && to !== "0x")
|
6004
|
+
transaction.to = to;
|
6005
|
+
if (isHex(gas) && gas !== "0x")
|
6006
|
+
transaction.gas = hexToBigInt(gas);
|
6007
|
+
if (isHex(data) && data !== "0x")
|
6008
|
+
transaction.data = data;
|
6009
|
+
if (isHex(nonce) && nonce !== "0x")
|
6010
|
+
transaction.nonce = hexToNumber(nonce);
|
6011
|
+
if (isHex(value) && value !== "0x")
|
6012
|
+
transaction.value = hexToBigInt(value);
|
6013
|
+
if (isHex(gasPrice) && gasPrice !== "0x")
|
6014
|
+
transaction.gasPrice = hexToBigInt(gasPrice);
|
6015
|
+
assertTransactionLegacy(transaction);
|
6016
|
+
if (transactionArray.length === 6)
|
6017
|
+
return transaction;
|
6018
|
+
const chainIdOrV = isHex(chainIdOrV_) && chainIdOrV_ !== "0x" ? hexToBigInt(chainIdOrV_) : 0n;
|
6019
|
+
if (s === "0x" && r === "0x") {
|
6020
|
+
if (chainIdOrV > 0)
|
6021
|
+
transaction.chainId = Number(chainIdOrV);
|
6022
|
+
return transaction;
|
6023
|
+
}
|
6024
|
+
const v = chainIdOrV;
|
6025
|
+
let chainId = Number((v - 35n) / 2n);
|
6026
|
+
if (chainId > 0)
|
6027
|
+
transaction.chainId = chainId;
|
6028
|
+
else if (v !== 27n && v !== 28n)
|
6029
|
+
throw new InvalidLegacyVError({ v });
|
6030
|
+
transaction.v = v;
|
6031
|
+
transaction.s = s;
|
6032
|
+
transaction.r = r;
|
6033
|
+
return transaction;
|
6034
|
+
}
|
6035
|
+
function parseAccessList(accessList_) {
|
6036
|
+
let accessList = [];
|
6037
|
+
for (let i = 0; i < accessList_.length; i++) {
|
6038
|
+
const [address, storageKeys] = accessList_[i];
|
6039
|
+
if (!isAddress(address))
|
6040
|
+
throw new InvalidAddressError({ address });
|
6041
|
+
accessList.push({
|
6042
|
+
address,
|
6043
|
+
storageKeys: storageKeys.map((key) => isHash(key) ? key : trim(key))
|
6044
|
+
});
|
6045
|
+
}
|
6046
|
+
return accessList;
|
6047
|
+
}
|
6048
|
+
function parseEIP155Signature(transactionArray) {
|
6049
|
+
const signature = transactionArray.slice(-3);
|
6050
|
+
const v = signature[0] === "0x" || hexToBigInt(signature[0]) === 0n ? 27n : 28n;
|
6051
|
+
return {
|
6052
|
+
r: padHex(signature[1], { size: 32 }),
|
6053
|
+
s: padHex(signature[2], { size: 32 }),
|
6054
|
+
v,
|
6055
|
+
yParity: v === 27n ? 0 : 1
|
6056
|
+
};
|
6057
|
+
}
|
6058
|
+
|
6059
|
+
// src/utils/transaction/serializeTransaction.ts
|
6060
|
+
function serializeTransaction(transaction, signature) {
|
6061
|
+
const type = getTransactionType(transaction);
|
6062
|
+
if (type === "eip1559")
|
6063
|
+
return serializeTransactionEIP1559(
|
6064
|
+
transaction,
|
6065
|
+
signature
|
6066
|
+
);
|
6067
|
+
if (type === "eip2930")
|
6068
|
+
return serializeTransactionEIP2930(
|
6069
|
+
transaction,
|
6070
|
+
signature
|
6071
|
+
);
|
6072
|
+
return serializeTransactionLegacy(
|
6073
|
+
transaction,
|
6074
|
+
signature
|
6075
|
+
);
|
6076
|
+
}
|
6077
|
+
function serializeTransactionEIP1559(transaction, signature) {
|
6078
|
+
const {
|
6079
|
+
chainId,
|
6080
|
+
gas,
|
6081
|
+
nonce,
|
6082
|
+
to,
|
6083
|
+
value,
|
6084
|
+
maxFeePerGas,
|
6085
|
+
maxPriorityFeePerGas,
|
6086
|
+
accessList,
|
6087
|
+
data
|
6088
|
+
} = transaction;
|
6089
|
+
assertTransactionEIP1559(transaction);
|
6090
|
+
const serializedAccessList = serializeAccessList(accessList);
|
6091
|
+
const serializedTransaction = [
|
6092
|
+
toHex(chainId),
|
6093
|
+
typeof nonce !== "undefined" ? toHex(nonce) : "0x",
|
6094
|
+
typeof maxPriorityFeePerGas !== "undefined" ? toHex(maxPriorityFeePerGas) : "0x",
|
6095
|
+
typeof maxFeePerGas !== "undefined" ? toHex(maxFeePerGas) : "0x",
|
6096
|
+
typeof gas !== "undefined" ? toHex(gas) : "0x",
|
6097
|
+
to ?? "0x",
|
6098
|
+
typeof value !== "undefined" ? toHex(value) : "0x",
|
6099
|
+
data ?? "0x",
|
6100
|
+
serializedAccessList
|
6101
|
+
];
|
6102
|
+
if (signature)
|
6103
|
+
serializedTransaction.push(
|
6104
|
+
signature.v === 27n ? "0x" : toHex(1),
|
6105
|
+
// yParity
|
6106
|
+
signature.r,
|
6107
|
+
signature.s
|
6108
|
+
);
|
6109
|
+
return concatHex([
|
6110
|
+
"0x02",
|
6111
|
+
toRlp(serializedTransaction)
|
6112
|
+
]);
|
6113
|
+
}
|
6114
|
+
function serializeTransactionEIP2930(transaction, signature) {
|
6115
|
+
const { chainId, gas, data, nonce, to, value, accessList, gasPrice } = transaction;
|
6116
|
+
assertTransactionEIP2930(transaction);
|
6117
|
+
const serializedAccessList = serializeAccessList(accessList);
|
6118
|
+
const serializedTransaction = [
|
6119
|
+
toHex(chainId),
|
6120
|
+
typeof nonce !== "undefined" ? toHex(nonce) : "0x",
|
6121
|
+
typeof gasPrice !== "undefined" ? toHex(gasPrice) : "0x",
|
6122
|
+
typeof gas !== "undefined" ? toHex(gas) : "0x",
|
6123
|
+
to ?? "0x",
|
6124
|
+
typeof value !== "undefined" ? toHex(value) : "0x",
|
6125
|
+
data ?? "0x",
|
6126
|
+
serializedAccessList
|
6127
|
+
];
|
6128
|
+
if (signature)
|
6129
|
+
serializedTransaction.push(
|
6130
|
+
signature.v === 27n ? "0x" : toHex(1),
|
6131
|
+
// yParity
|
6132
|
+
signature.r,
|
6133
|
+
signature.s
|
6134
|
+
);
|
6135
|
+
return concatHex([
|
6136
|
+
"0x01",
|
6137
|
+
toRlp(serializedTransaction)
|
6138
|
+
]);
|
6139
|
+
}
|
6140
|
+
function serializeTransactionLegacy(transaction, signature) {
|
6141
|
+
const { chainId = 0, gas, data, nonce, to, value, gasPrice } = transaction;
|
6142
|
+
assertTransactionLegacy(transaction);
|
6143
|
+
let serializedTransaction = [
|
6144
|
+
typeof nonce !== "undefined" ? toHex(nonce) : "0x",
|
6145
|
+
typeof gasPrice !== "undefined" ? toHex(gasPrice) : "0x",
|
6146
|
+
typeof gas !== "undefined" ? toHex(gas) : "0x",
|
6147
|
+
to ?? "0x",
|
6148
|
+
typeof value !== "undefined" ? toHex(value) : "0x",
|
6149
|
+
data ?? "0x"
|
6150
|
+
];
|
6151
|
+
if (signature) {
|
6152
|
+
let v = 27n + (signature.v === 27n ? 0n : 1n);
|
6153
|
+
if (chainId > 0)
|
6154
|
+
v = BigInt(chainId * 2) + BigInt(35n + signature.v - 27n);
|
6155
|
+
else if (signature.v !== v)
|
6156
|
+
throw new InvalidLegacyVError({ v: signature.v });
|
6157
|
+
serializedTransaction = [
|
6158
|
+
...serializedTransaction,
|
6159
|
+
toHex(v),
|
6160
|
+
signature.r,
|
6161
|
+
signature.s
|
6162
|
+
];
|
6163
|
+
} else if (chainId > 0) {
|
6164
|
+
serializedTransaction = [
|
6165
|
+
...serializedTransaction,
|
6166
|
+
toHex(chainId),
|
6167
|
+
"0x",
|
6168
|
+
"0x"
|
6169
|
+
];
|
6170
|
+
}
|
6171
|
+
return toRlp(serializedTransaction);
|
6172
|
+
}
|
6173
|
+
function serializeAccessList(accessList) {
|
6174
|
+
if (!accessList || accessList.length === 0)
|
6175
|
+
return [];
|
6176
|
+
let serializedAccessList = [];
|
6177
|
+
for (let i = 0; i < accessList.length; i++) {
|
6178
|
+
const { address, storageKeys } = accessList[i];
|
6179
|
+
for (let j = 0; j < storageKeys.length; j++) {
|
6180
|
+
if (storageKeys[j].length - 2 !== 64) {
|
6181
|
+
throw new InvalidStorageKeySizeError({ storageKey: storageKeys[j] });
|
6182
|
+
}
|
6183
|
+
}
|
6184
|
+
if (!isAddress(address)) {
|
6185
|
+
throw new InvalidAddressError({ address });
|
6186
|
+
}
|
6187
|
+
serializedAccessList.push([address, storageKeys]);
|
6188
|
+
}
|
6189
|
+
return serializedAccessList;
|
6190
|
+
}
|
6191
|
+
|
5596
6192
|
// src/utils/unit/formatUnits.ts
|
5597
6193
|
function formatUnits(value, decimals) {
|
5598
6194
|
let display = value.toString();
|
@@ -5648,11 +6244,13 @@ export {
|
|
5648
6244
|
InvalidAddressError,
|
5649
6245
|
BlockNotFoundError,
|
5650
6246
|
ChainDoesNotSupportContract,
|
6247
|
+
InvalidChainIdError,
|
5651
6248
|
multicall3Abi,
|
5652
6249
|
panicReasons,
|
5653
6250
|
etherUnits,
|
5654
6251
|
gweiUnits,
|
5655
6252
|
weiUnits,
|
6253
|
+
InvalidLegacyVError,
|
5656
6254
|
TransactionExecutionError,
|
5657
6255
|
TransactionNotFoundError,
|
5658
6256
|
TransactionReceiptNotFoundError,
|
@@ -5747,7 +6345,9 @@ export {
|
|
5747
6345
|
keccak256,
|
5748
6346
|
getEventSelector,
|
5749
6347
|
getFunctionSelector,
|
6348
|
+
isHash,
|
5750
6349
|
isAddress,
|
6350
|
+
checksumAddress,
|
5751
6351
|
getAddress,
|
5752
6352
|
getContractAddress2 as getContractAddress,
|
5753
6353
|
getCreateAddress,
|
@@ -5775,7 +6375,6 @@ export {
|
|
5775
6375
|
parseAbiItem,
|
5776
6376
|
parseAbiParameter,
|
5777
6377
|
parseAbiParameters,
|
5778
|
-
getAccount,
|
5779
6378
|
parseAccount,
|
5780
6379
|
isDeterministicError,
|
5781
6380
|
buildRequest,
|
@@ -5802,6 +6401,7 @@ export {
|
|
5802
6401
|
getSocket,
|
5803
6402
|
rpc,
|
5804
6403
|
hashMessage,
|
6404
|
+
validateTypedData,
|
5805
6405
|
hashTypedData,
|
5806
6406
|
recoverAddress,
|
5807
6407
|
recoverMessageAddress,
|
@@ -5809,6 +6409,8 @@ export {
|
|
5809
6409
|
verifyMessage,
|
5810
6410
|
verifyTypedData,
|
5811
6411
|
assertRequest,
|
6412
|
+
getSerializedTransactionType,
|
6413
|
+
getTransactionType,
|
5812
6414
|
call,
|
5813
6415
|
simulateContract,
|
5814
6416
|
createPendingTransactionFilter,
|
@@ -5886,9 +6488,14 @@ export {
|
|
5886
6488
|
parseUnits,
|
5887
6489
|
parseGwei,
|
5888
6490
|
prepareRequest,
|
6491
|
+
assertTransactionEIP1559,
|
6492
|
+
assertTransactionEIP2930,
|
6493
|
+
assertTransactionLegacy,
|
6494
|
+
parseTransaction,
|
6495
|
+
serializeTransaction,
|
5889
6496
|
formatUnits,
|
5890
6497
|
formatEther,
|
5891
6498
|
formatGwei,
|
5892
6499
|
parseEther
|
5893
6500
|
};
|
5894
|
-
//# sourceMappingURL=chunk-
|
6501
|
+
//# sourceMappingURL=chunk-UCZWRYV5.mjs.map
|