viem 0.2.0-jxom-local-accounts.20230321T212822 → 0.2.0-main.20230323T084936
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/abi.d.ts +3 -3
- package/dist/abi.js +2 -2
- package/dist/abi.mjs +1 -1
- package/dist/{chain-75b0942e.d.ts → chain-1b53ef88.d.ts} +48 -53
- package/dist/{chain-f8db473f.d.ts → chain-ec8c485d.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-NJSAEA2H.js → chunk-BHAAXXGO.js} +154 -461
- package/dist/chunk-BHAAXXGO.js.map +1 -0
- package/dist/{chunk-IVRML3IK.mjs → chunk-FOJL5WVL.mjs} +85 -392
- package/dist/chunk-FOJL5WVL.mjs.map +1 -0
- package/dist/{chunk-6UKHPIXX.mjs → chunk-R7WEI5MQ.mjs} +2 -2
- package/dist/chunk-R7WEI5MQ.mjs.map +1 -0
- package/dist/{chunk-LYQKHD7R.js → chunk-ZIT7BMZO.js} +19 -19
- package/dist/{chunk-LYQKHD7R.js.map → chunk-ZIT7BMZO.js.map} +1 -1
- package/dist/contract.d.ts +7 -9
- package/dist/contract.js +2 -2
- package/dist/contract.mjs +1 -1
- package/dist/{createClient-f87255c1.d.ts → createClient-a28317a9.d.ts} +6 -6
- package/dist/{createPublicClient-d2c37c92.d.ts → createPublicClient-75540130.d.ts} +206 -160
- package/dist/{eip1193-ae706fd8.d.ts → eip1193-4f4e240c.d.ts} +1 -1
- package/dist/{encodeFunctionResult-4792a6a3.d.ts → encodeFunctionResult-1f324375.d.ts} +1 -1
- package/dist/{encodePacked-3fcdd54b.d.ts → encodePacked-d5d5264a.d.ts} +1 -1
- package/dist/ens.d.ts +4 -6
- package/dist/ens.js +3 -3
- package/dist/ens.mjs +2 -2
- package/dist/ethers.d.ts +6 -5
- package/dist/ethers.js +5 -7
- package/dist/ethers.js.map +1 -1
- package/dist/ethers.mjs +5 -7
- package/dist/ethers.mjs.map +1 -1
- package/dist/{formatAbiItem-765ebc53.d.ts → formatAbiItem-15e8817d.d.ts} +1 -1
- package/dist/{getAbiItem-693e6e1b.d.ts → getAbiItem-3e809ff9.d.ts} +1 -1
- package/dist/index.d.ts +13 -15
- package/dist/index.js +91 -99
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -13
- package/dist/index.mjs.map +1 -1
- package/dist/{parseGwei-377678bc.d.ts → parseGwei-6fff7cbe.d.ts} +13 -49
- package/dist/public.d.ts +4 -6
- package/dist/public.js +2 -2
- package/dist/public.mjs +1 -1
- package/dist/{test-98c0b642.d.ts → test-2bd23d7e.d.ts} +32 -33
- package/dist/test.d.ts +10 -10
- package/dist/test.js +2 -2
- package/dist/test.mjs +1 -1
- package/dist/utils/index.d.ts +18 -30
- package/dist/utils/index.js +2 -10
- package/dist/utils/index.mjs +5 -13
- package/dist/wallet.d.ts +4 -6
- package/dist/wallet.js +2 -2
- package/dist/wallet.mjs +1 -1
- package/dist/window.d.ts +2 -2
- package/package.json +1 -9
- package/accounts/package.json +0 -4
- package/dist/accounts/index.d.ts +0 -33
- package/dist/accounts/index.js +0 -89
- package/dist/accounts/index.js.map +0 -1
- package/dist/accounts/index.mjs +0 -89
- package/dist/accounts/index.mjs.map +0 -1
- package/dist/chunk-6UKHPIXX.mjs.map +0 -1
- package/dist/chunk-FNVFGFWN.mjs +0 -31
- package/dist/chunk-FNVFGFWN.mjs.map +0 -1
- package/dist/chunk-FQM5MF6U.js +0 -31
- package/dist/chunk-FQM5MF6U.js.map +0 -1
- package/dist/chunk-IVRML3IK.mjs.map +0 -1
- package/dist/chunk-NJSAEA2H.js.map +0 -1
- package/dist/parseAccount-2d7ea01d.d.ts +0 -6
- package/dist/typedData-ade018d6.d.ts +0 -93
@@ -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",
|
29
29
|
changeset: "changeset",
|
30
30
|
"changeset:release": "pnpm build && changeset publish",
|
31
31
|
"changeset:version": "changeset version && pnpm install --lockfile-only",
|
@@ -53,7 +53,6 @@ var package_default = {
|
|
53
53
|
entry: [
|
54
54
|
"src/index.ts",
|
55
55
|
"src/abi.ts",
|
56
|
-
"src/accounts/index.ts",
|
57
56
|
"src/chains.ts",
|
58
57
|
"src/contract.ts",
|
59
58
|
"src/ens.ts",
|
@@ -67,7 +66,6 @@ var package_default = {
|
|
67
66
|
},
|
68
67
|
files: [
|
69
68
|
"/abi",
|
70
|
-
"/accounts",
|
71
69
|
"/dist",
|
72
70
|
"/chains",
|
73
71
|
"/contract",
|
@@ -90,11 +88,6 @@ var package_default = {
|
|
90
88
|
module: "./dist/abi.mts",
|
91
89
|
default: "./dist/abi.js"
|
92
90
|
},
|
93
|
-
"./accounts": {
|
94
|
-
types: "./dist/accounts/index.d.ts",
|
95
|
-
module: "./dist/accounts/index.mts",
|
96
|
-
default: "./dist/accounts/index.js"
|
97
|
-
},
|
98
91
|
"./chains": {
|
99
92
|
types: "./dist/chains.d.ts",
|
100
93
|
module: "./dist/chains.mts",
|
@@ -149,8 +142,6 @@ var package_default = {
|
|
149
142
|
dependencies: {
|
150
143
|
"@noble/hashes": "^1.1.2",
|
151
144
|
"@noble/secp256k1": "^1.7.1",
|
152
|
-
"@scure/bip32": "^1.2.0",
|
153
|
-
"@scure/bip39": "^1.1.1",
|
154
145
|
"@wagmi/chains": "~0.2.11",
|
155
146
|
abitype: "~0.7.1",
|
156
147
|
"idna-uts46-hx": "^4.1.2",
|
@@ -163,7 +154,6 @@ var package_default = {
|
|
163
154
|
"@adraffy/ens-normalize": "^1.8.9",
|
164
155
|
"@changesets/changelog-github": "^0.4.5",
|
165
156
|
"@changesets/cli": "^2.23.2",
|
166
|
-
"@size-limit/preset-big-lib": "^8.2.4",
|
167
157
|
"@types/dedent": "^0.7.0",
|
168
158
|
"@types/fs-extra": "^9.0.13",
|
169
159
|
"@types/node": "^17.0.45",
|
@@ -181,7 +171,6 @@ var package_default = {
|
|
181
171
|
rimraf: "^4.1.2",
|
182
172
|
rome: "^11.0.0",
|
183
173
|
"simple-git-hooks": "^2.8.1",
|
184
|
-
"size-limit": "^8.2.4",
|
185
174
|
tsup: "^6.6.0",
|
186
175
|
typescript: "^4.9.4",
|
187
176
|
vite: "^4.1.4",
|
@@ -200,17 +189,12 @@ var package_default = {
|
|
200
189
|
"wallet",
|
201
190
|
"web3"
|
202
191
|
],
|
203
|
-
"size-limit": [
|
204
|
-
{
|
205
|
-
path: "dist/index.js"
|
206
|
-
}
|
207
|
-
],
|
208
192
|
"simple-git-hooks": {
|
209
193
|
"pre-commit": "pnpm format && pnpm lint:fix"
|
210
194
|
},
|
211
195
|
pnpm: {
|
212
196
|
patchedDependencies: {
|
213
|
-
"vitepress@1.0.0-alpha.
|
197
|
+
"vitepress@1.0.0-alpha.61": "patches/vitepress@1.0.0-alpha.61.patch"
|
214
198
|
},
|
215
199
|
peerDependencyRules: {
|
216
200
|
ignoreMissing: [
|
@@ -234,9 +218,7 @@ var BaseError = class extends Error {
|
|
234
218
|
shortMessage || "An error occurred.",
|
235
219
|
"",
|
236
220
|
...args.metaMessages ? [...args.metaMessages, ""] : [],
|
237
|
-
...docsPath6 ? [
|
238
|
-
`Docs: https://viem.sh${docsPath6}.html${args.docsSlug ? `#${args.docsSlug}` : ""}`
|
239
|
-
] : [],
|
221
|
+
...docsPath6 ? [`Docs: https://viem.sh${docsPath6}.html`] : [],
|
240
222
|
...details ? [`Details: ${details}`] : [],
|
241
223
|
`Version: ${getVersion()}`
|
242
224
|
].join("\n");
|
@@ -537,23 +519,6 @@ var UnsupportedPackedAbiType = class extends BaseError {
|
|
537
519
|
}
|
538
520
|
};
|
539
521
|
|
540
|
-
// src/errors/account.ts
|
541
|
-
var AccountNotFoundError = class extends BaseError {
|
542
|
-
constructor({ docsPath: docsPath6 } = {}) {
|
543
|
-
super(
|
544
|
-
[
|
545
|
-
"Could not find an Account to execute with this Action.",
|
546
|
-
"Please provide an Account with the `account` argument on the Action, or by supplying an `account` to the WalletClient."
|
547
|
-
].join("\n"),
|
548
|
-
{
|
549
|
-
docsPath: docsPath6,
|
550
|
-
docsSlug: "account"
|
551
|
-
}
|
552
|
-
);
|
553
|
-
__publicField(this, "name", "AccountNotFoundError");
|
554
|
-
}
|
555
|
-
};
|
556
|
-
|
557
522
|
// src/errors/address.ts
|
558
523
|
var InvalidAddressError = class extends BaseError {
|
559
524
|
constructor({ address }) {
|
@@ -618,17 +583,6 @@ var ChainMismatchError = class extends BaseError {
|
|
618
583
|
__publicField(this, "name", "ChainMismatchError");
|
619
584
|
}
|
620
585
|
};
|
621
|
-
var ChainNotFoundError = class extends BaseError {
|
622
|
-
constructor() {
|
623
|
-
super(
|
624
|
-
[
|
625
|
-
"No chain was provided to the request.",
|
626
|
-
"Please provide a chain with the `chain` argument on the Action, or by supplying a `chain` to WalletClient."
|
627
|
-
].join("\n")
|
628
|
-
);
|
629
|
-
__publicField(this, "name", "ChainNotFoundError");
|
630
|
-
}
|
631
|
-
};
|
632
586
|
|
633
587
|
// src/constants/abis.ts
|
634
588
|
var multicall3Abi = [
|
@@ -759,7 +713,7 @@ var TransactionExecutionError = class extends BaseError {
|
|
759
713
|
}) {
|
760
714
|
const prettyArgs = prettyPrint({
|
761
715
|
chain: chain && `${chain?.name} (id: ${chain?.id})`,
|
762
|
-
from: account
|
716
|
+
from: account.address,
|
763
717
|
to,
|
764
718
|
value: typeof value !== "undefined" && `${formatEther(value)} ${chain?.nativeCurrency.symbol || "ETH"}`,
|
765
719
|
data,
|
@@ -824,7 +778,7 @@ var WaitForTransactionReceiptTimeoutError = class extends BaseError {
|
|
824
778
|
// src/errors/contract.ts
|
825
779
|
var CallExecutionError = class extends BaseError {
|
826
780
|
constructor(cause, {
|
827
|
-
account
|
781
|
+
account,
|
828
782
|
docsPath: docsPath6,
|
829
783
|
chain,
|
830
784
|
data,
|
@@ -836,7 +790,6 @@ var CallExecutionError = class extends BaseError {
|
|
836
790
|
to,
|
837
791
|
value
|
838
792
|
}) {
|
839
|
-
const account = account_ ? parseAccount(account_) : void 0;
|
840
793
|
const prettyArgs = prettyPrint({
|
841
794
|
from: account?.address,
|
842
795
|
to,
|
@@ -1079,7 +1032,7 @@ var EstimateGasExecutionError = class extends BaseError {
|
|
1079
1032
|
value
|
1080
1033
|
}) {
|
1081
1034
|
const prettyArgs = prettyPrint({
|
1082
|
-
from: account
|
1035
|
+
from: account.address,
|
1083
1036
|
to,
|
1084
1037
|
value: typeof value !== "undefined" && `${formatEther(value)} ${chain?.nativeCurrency.symbol || "ETH"}`,
|
1085
1038
|
data,
|
@@ -1858,7 +1811,7 @@ function parse2(value) {
|
|
1858
1811
|
function format2(bytes, to) {
|
1859
1812
|
if (Array.isArray(bytes))
|
1860
1813
|
return bytes.map((b) => format2(b, to));
|
1861
|
-
return to === "hex" ?
|
1814
|
+
return to === "hex" ? bytesToHex(bytes) : bytes;
|
1862
1815
|
}
|
1863
1816
|
function rlpToBytes(bytes, offset = 0) {
|
1864
1817
|
if (bytes.length === 0)
|
@@ -2875,11 +2828,19 @@ function formatAbiItemWithArgs({
|
|
2875
2828
|
).join(", ")})`;
|
2876
2829
|
}
|
2877
2830
|
|
2878
|
-
// src/
|
2879
|
-
function
|
2880
|
-
if (typeof account === "string")
|
2831
|
+
// src/utils/account.ts
|
2832
|
+
function getAccount(account) {
|
2833
|
+
if (typeof account === "string") {
|
2834
|
+
if (!isAddress(account))
|
2835
|
+
throw new InvalidAddressError({ address: account });
|
2881
2836
|
return { address: account, type: "json-rpc" };
|
2882
|
-
|
2837
|
+
}
|
2838
|
+
if (!isAddress(account.address))
|
2839
|
+
throw new InvalidAddressError({ address: account.address });
|
2840
|
+
return {
|
2841
|
+
...account,
|
2842
|
+
type: "local"
|
2843
|
+
};
|
2883
2844
|
}
|
2884
2845
|
|
2885
2846
|
// src/utils/promise/withCache.ts
|
@@ -3546,224 +3507,15 @@ ${messageBytes.length}`
|
|
3546
3507
|
return keccak256(concat([prefixBytes, messageBytes]), to_);
|
3547
3508
|
}
|
3548
3509
|
|
3549
|
-
// src/utils/typedData.ts
|
3550
|
-
function validateTypedData({
|
3551
|
-
domain,
|
3552
|
-
message,
|
3553
|
-
primaryType,
|
3554
|
-
types: types_
|
3555
|
-
}) {
|
3556
|
-
const types = types_;
|
3557
|
-
const validateData = (struct, value_) => {
|
3558
|
-
for (const param of struct) {
|
3559
|
-
const { name, type: type_ } = param;
|
3560
|
-
const type = type_;
|
3561
|
-
const value = value_[name];
|
3562
|
-
const integerMatch = type.match(integerRegex);
|
3563
|
-
if (integerMatch && (typeof value === "number" || typeof value === "bigint")) {
|
3564
|
-
const [_type, base, size_] = integerMatch;
|
3565
|
-
numberToHex(value, {
|
3566
|
-
signed: base === "int",
|
3567
|
-
size: parseInt(size_) / 8
|
3568
|
-
});
|
3569
|
-
}
|
3570
|
-
if (type === "address" && typeof value === "string" && !isAddress(value))
|
3571
|
-
throw new InvalidAddressError({ address: value });
|
3572
|
-
const bytesMatch = type.match(bytesRegex);
|
3573
|
-
if (bytesMatch) {
|
3574
|
-
const [_type, size_] = bytesMatch;
|
3575
|
-
if (size_ && size(value) !== parseInt(size_))
|
3576
|
-
throw new BytesSizeMismatchError({
|
3577
|
-
expectedSize: parseInt(size_),
|
3578
|
-
givenSize: size(value)
|
3579
|
-
});
|
3580
|
-
}
|
3581
|
-
const struct2 = types[type];
|
3582
|
-
if (struct2)
|
3583
|
-
validateData(struct2, value);
|
3584
|
-
}
|
3585
|
-
};
|
3586
|
-
if (types["EIP712Domain"] && domain)
|
3587
|
-
validateData(types["EIP712Domain"], domain);
|
3588
|
-
if (primaryType !== "EIP712Domain") {
|
3589
|
-
const type = types[primaryType];
|
3590
|
-
validateData(type, message);
|
3591
|
-
}
|
3592
|
-
}
|
3593
|
-
|
3594
|
-
// src/utils/signature/hashTypedData.ts
|
3595
|
-
function hashTypedData({
|
3596
|
-
domain: domain_,
|
3597
|
-
message,
|
3598
|
-
primaryType,
|
3599
|
-
types: types_
|
3600
|
-
}) {
|
3601
|
-
const domain = typeof domain_ === "undefined" ? {} : domain_;
|
3602
|
-
const types = {
|
3603
|
-
EIP712Domain: [
|
3604
|
-
domain?.name && { name: "name", type: "string" },
|
3605
|
-
domain?.version && { name: "version", type: "string" },
|
3606
|
-
domain?.chainId && { name: "chainId", type: "uint256" },
|
3607
|
-
domain?.verifyingContract && {
|
3608
|
-
name: "verifyingContract",
|
3609
|
-
type: "address"
|
3610
|
-
},
|
3611
|
-
domain?.salt && { name: "salt", type: "bytes32" }
|
3612
|
-
].filter(Boolean),
|
3613
|
-
...types_
|
3614
|
-
};
|
3615
|
-
validateTypedData({
|
3616
|
-
domain,
|
3617
|
-
message,
|
3618
|
-
primaryType,
|
3619
|
-
types
|
3620
|
-
});
|
3621
|
-
let parts = ["0x1901"];
|
3622
|
-
if (domain)
|
3623
|
-
parts.push(
|
3624
|
-
hashDomain({
|
3625
|
-
domain,
|
3626
|
-
types
|
3627
|
-
})
|
3628
|
-
);
|
3629
|
-
if (primaryType !== "EIP712Domain") {
|
3630
|
-
parts.push(
|
3631
|
-
hashStruct({
|
3632
|
-
data: message,
|
3633
|
-
primaryType,
|
3634
|
-
types
|
3635
|
-
})
|
3636
|
-
);
|
3637
|
-
}
|
3638
|
-
return keccak256(concat(parts));
|
3639
|
-
}
|
3640
|
-
function hashDomain({
|
3641
|
-
domain,
|
3642
|
-
types
|
3643
|
-
}) {
|
3644
|
-
return hashStruct({
|
3645
|
-
data: domain,
|
3646
|
-
primaryType: "EIP712Domain",
|
3647
|
-
types
|
3648
|
-
});
|
3649
|
-
}
|
3650
|
-
function hashStruct({
|
3651
|
-
data,
|
3652
|
-
primaryType,
|
3653
|
-
types
|
3654
|
-
}) {
|
3655
|
-
const encoded = encodeData({
|
3656
|
-
data,
|
3657
|
-
primaryType,
|
3658
|
-
types
|
3659
|
-
});
|
3660
|
-
return keccak256(encoded);
|
3661
|
-
}
|
3662
|
-
function encodeData({
|
3663
|
-
data,
|
3664
|
-
primaryType,
|
3665
|
-
types
|
3666
|
-
}) {
|
3667
|
-
let encodedTypes = [{ type: "bytes32" }];
|
3668
|
-
const encodedValues = [hashType({ primaryType, types })];
|
3669
|
-
for (const field of types[primaryType]) {
|
3670
|
-
const [type, value] = encodeField({
|
3671
|
-
types,
|
3672
|
-
name: field.name,
|
3673
|
-
type: field.type,
|
3674
|
-
value: data[field.name]
|
3675
|
-
});
|
3676
|
-
encodedTypes.push(type);
|
3677
|
-
encodedValues.push(value);
|
3678
|
-
}
|
3679
|
-
return encodeAbiParameters(encodedTypes, encodedValues);
|
3680
|
-
}
|
3681
|
-
function hashType({
|
3682
|
-
primaryType,
|
3683
|
-
types
|
3684
|
-
}) {
|
3685
|
-
const encodedHashType = toHex(encodeType({ primaryType, types }));
|
3686
|
-
return keccak256(encodedHashType);
|
3687
|
-
}
|
3688
|
-
function encodeType({
|
3689
|
-
primaryType,
|
3690
|
-
types
|
3691
|
-
}) {
|
3692
|
-
let result = "";
|
3693
|
-
const unsortedDeps = findTypeDependencies({ primaryType, types });
|
3694
|
-
unsortedDeps.delete(primaryType);
|
3695
|
-
const deps = [primaryType, ...Array.from(unsortedDeps).sort()];
|
3696
|
-
for (const type of deps) {
|
3697
|
-
result += `${type}(${types[type].map(({ name, type: t }) => `${t} ${name}`).join(",")})`;
|
3698
|
-
}
|
3699
|
-
return result;
|
3700
|
-
}
|
3701
|
-
function findTypeDependencies({
|
3702
|
-
primaryType: primaryType_,
|
3703
|
-
types
|
3704
|
-
}, results = /* @__PURE__ */ new Set()) {
|
3705
|
-
const match = primaryType_.match(/^\w*/u);
|
3706
|
-
const primaryType = match?.[0];
|
3707
|
-
if (results.has(primaryType) || types[primaryType] === void 0) {
|
3708
|
-
return results;
|
3709
|
-
}
|
3710
|
-
results.add(primaryType);
|
3711
|
-
for (const field of types[primaryType]) {
|
3712
|
-
findTypeDependencies({ primaryType: field.type, types }, results);
|
3713
|
-
}
|
3714
|
-
return results;
|
3715
|
-
}
|
3716
|
-
function encodeField({
|
3717
|
-
types,
|
3718
|
-
name,
|
3719
|
-
type,
|
3720
|
-
value
|
3721
|
-
}) {
|
3722
|
-
if (types[type] !== void 0) {
|
3723
|
-
return [
|
3724
|
-
{ type: "bytes32" },
|
3725
|
-
keccak256(encodeData({ data: value, primaryType: type, types }))
|
3726
|
-
];
|
3727
|
-
}
|
3728
|
-
if (type === "bytes") {
|
3729
|
-
const prepend = value.length % 2 ? "0" : "";
|
3730
|
-
value = `0x${prepend + value.slice(2)}`;
|
3731
|
-
return [{ type: "bytes32" }, keccak256(value)];
|
3732
|
-
}
|
3733
|
-
if (type === "string")
|
3734
|
-
return [{ type: "bytes32" }, keccak256(toHex(value))];
|
3735
|
-
if (type.lastIndexOf("]") === type.length - 1) {
|
3736
|
-
const parsedType = type.slice(0, type.lastIndexOf("["));
|
3737
|
-
const typeValuePairs = value.map(
|
3738
|
-
(item) => encodeField({
|
3739
|
-
name,
|
3740
|
-
type: parsedType,
|
3741
|
-
types,
|
3742
|
-
value: item
|
3743
|
-
})
|
3744
|
-
);
|
3745
|
-
return [
|
3746
|
-
{ type: "bytes32" },
|
3747
|
-
keccak256(
|
3748
|
-
encodeAbiParameters(
|
3749
|
-
typeValuePairs.map(([t]) => t),
|
3750
|
-
typeValuePairs.map(([, v]) => v)
|
3751
|
-
)
|
3752
|
-
)
|
3753
|
-
];
|
3754
|
-
}
|
3755
|
-
return [{ type }, value];
|
3756
|
-
}
|
3757
|
-
|
3758
3510
|
// src/utils/signature/recoverAddress.ts
|
3759
|
-
|
3511
|
+
import { recoverPublicKey } from "@noble/secp256k1";
|
3512
|
+
function recoverAddress({
|
3760
3513
|
hash: hash2,
|
3761
3514
|
signature
|
3762
3515
|
}) {
|
3763
3516
|
const signatureHex = isHex(signature) ? signature : toHex(signature);
|
3764
3517
|
const hashHex = isHex(hash2) ? hash2 : toHex(hash2);
|
3765
3518
|
const v = hexToNumber(`0x${signatureHex.slice(130)}`);
|
3766
|
-
const { recoverPublicKey } = await import("@noble/secp256k1");
|
3767
3519
|
const publicKey = toHex(
|
3768
3520
|
recoverPublicKey(
|
3769
3521
|
hashHex.substring(2),
|
@@ -3776,75 +3528,28 @@ async function recoverAddress({
|
|
3776
3528
|
}
|
3777
3529
|
|
3778
3530
|
// src/utils/signature/recoverMessageAddress.ts
|
3779
|
-
|
3531
|
+
function recoverMessageAddress({
|
3780
3532
|
message,
|
3781
3533
|
signature
|
3782
3534
|
}) {
|
3783
3535
|
return recoverAddress({ hash: hashMessage(message), signature });
|
3784
3536
|
}
|
3785
3537
|
|
3786
|
-
// src/utils/signature/recoverTypedDataAddress.ts
|
3787
|
-
async function recoverTypedDataAddress({
|
3788
|
-
domain,
|
3789
|
-
message,
|
3790
|
-
primaryType,
|
3791
|
-
signature,
|
3792
|
-
types
|
3793
|
-
}) {
|
3794
|
-
return recoverAddress({
|
3795
|
-
hash: hashTypedData({
|
3796
|
-
domain,
|
3797
|
-
message,
|
3798
|
-
primaryType,
|
3799
|
-
types
|
3800
|
-
}),
|
3801
|
-
signature
|
3802
|
-
});
|
3803
|
-
}
|
3804
|
-
|
3805
3538
|
// src/utils/signature/verifyMessage.ts
|
3806
|
-
|
3539
|
+
function verifyMessage({
|
3807
3540
|
address,
|
3808
3541
|
message,
|
3809
3542
|
signature
|
3810
3543
|
}) {
|
3811
3544
|
return isAddressEqual(
|
3812
3545
|
getAddress(address),
|
3813
|
-
|
3814
|
-
);
|
3815
|
-
}
|
3816
|
-
|
3817
|
-
// src/utils/signature/verifyTypedData.ts
|
3818
|
-
async function verifyTypedData({
|
3819
|
-
address,
|
3820
|
-
domain,
|
3821
|
-
message,
|
3822
|
-
primaryType,
|
3823
|
-
signature,
|
3824
|
-
types
|
3825
|
-
}) {
|
3826
|
-
return isAddressEqual(
|
3827
|
-
getAddress(address),
|
3828
|
-
await recoverTypedDataAddress({
|
3829
|
-
domain,
|
3830
|
-
message,
|
3831
|
-
primaryType,
|
3832
|
-
signature,
|
3833
|
-
types
|
3834
|
-
})
|
3546
|
+
recoverMessageAddress({ message, signature })
|
3835
3547
|
);
|
3836
3548
|
}
|
3837
3549
|
|
3838
3550
|
// src/utils/transaction/assertRequest.ts
|
3839
3551
|
function assertRequest(args) {
|
3840
|
-
const {
|
3841
|
-
account: account_,
|
3842
|
-
gasPrice,
|
3843
|
-
maxFeePerGas,
|
3844
|
-
maxPriorityFeePerGas,
|
3845
|
-
to
|
3846
|
-
} = args;
|
3847
|
-
const account = account_ ? parseAccount(account_) : void 0;
|
3552
|
+
const { account, gasPrice, maxFeePerGas, maxPriorityFeePerGas, to } = args;
|
3848
3553
|
if (account && !isAddress(account.address))
|
3849
3554
|
throw new InvalidAddressError({ address: account.address });
|
3850
3555
|
if (to && !isAddress(to))
|
@@ -3860,7 +3565,7 @@ function assertRequest(args) {
|
|
3860
3565
|
// src/actions/public/call.ts
|
3861
3566
|
async function call(client, args) {
|
3862
3567
|
const {
|
3863
|
-
account
|
3568
|
+
account,
|
3864
3569
|
blockNumber,
|
3865
3570
|
blockTag = "latest",
|
3866
3571
|
accessList,
|
@@ -3874,7 +3579,6 @@ async function call(client, args) {
|
|
3874
3579
|
value,
|
3875
3580
|
...rest
|
3876
3581
|
} = args;
|
3877
|
-
const account = account_ ? parseAccount(account_) : void 0;
|
3878
3582
|
try {
|
3879
3583
|
assertRequest(args);
|
3880
3584
|
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : void 0;
|
@@ -3908,7 +3612,6 @@ async function call(client, args) {
|
|
3908
3612
|
} catch (err) {
|
3909
3613
|
throw getCallError(err, {
|
3910
3614
|
...args,
|
3911
|
-
account,
|
3912
3615
|
chain: client.chain
|
3913
3616
|
});
|
3914
3617
|
}
|
@@ -3922,7 +3625,6 @@ async function simulateContract(client, {
|
|
3922
3625
|
functionName,
|
3923
3626
|
...callRequest
|
3924
3627
|
}) {
|
3925
|
-
const account = callRequest.account ? parseAccount(callRequest.account) : void 0;
|
3926
3628
|
const calldata = encodeFunctionData({
|
3927
3629
|
abi,
|
3928
3630
|
args,
|
@@ -3957,7 +3659,7 @@ async function simulateContract(client, {
|
|
3957
3659
|
args,
|
3958
3660
|
docsPath: "/docs/contract/simulateContract",
|
3959
3661
|
functionName,
|
3960
|
-
sender: account?.address
|
3662
|
+
sender: callRequest.account?.address
|
3961
3663
|
});
|
3962
3664
|
}
|
3963
3665
|
}
|
@@ -4049,13 +3751,9 @@ async function createContractEventFilter(client, {
|
|
4049
3751
|
|
4050
3752
|
// src/actions/public/estimateGas.ts
|
4051
3753
|
async function estimateGas(client, args) {
|
4052
|
-
if (!args.account)
|
4053
|
-
throw new AccountNotFoundError({
|
4054
|
-
docsPath: "/docs/actions/public/estimateGas"
|
4055
|
-
});
|
4056
|
-
const account = parseAccount(args.account);
|
4057
3754
|
try {
|
4058
3755
|
const {
|
3756
|
+
account,
|
4059
3757
|
accessList,
|
4060
3758
|
blockNumber,
|
4061
3759
|
blockTag = "latest",
|
@@ -4068,7 +3766,7 @@ async function estimateGas(client, args) {
|
|
4068
3766
|
to,
|
4069
3767
|
value,
|
4070
3768
|
...rest
|
4071
|
-
} = account.type === "local" ? await prepareRequest(client, args) : args;
|
3769
|
+
} = args.account.type === "local" ? await prepareRequest(client, args) : args;
|
4072
3770
|
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : void 0;
|
4073
3771
|
assertRequest(args);
|
4074
3772
|
const formatter = client.chain?.formatters?.transactionRequest;
|
@@ -4099,7 +3797,6 @@ async function estimateGas(client, args) {
|
|
4099
3797
|
} catch (err) {
|
4100
3798
|
throw getEstimateGasError(err, {
|
4101
3799
|
...args,
|
4102
|
-
account,
|
4103
3800
|
chain: client.chain
|
4104
3801
|
});
|
4105
3802
|
}
|
@@ -4113,7 +3810,6 @@ async function estimateContractGas(client, {
|
|
4113
3810
|
functionName,
|
4114
3811
|
...request
|
4115
3812
|
}) {
|
4116
|
-
const account = parseAccount(request.account);
|
4117
3813
|
const data = encodeFunctionData({
|
4118
3814
|
abi,
|
4119
3815
|
args,
|
@@ -4133,7 +3829,7 @@ async function estimateContractGas(client, {
|
|
4133
3829
|
args,
|
4134
3830
|
docsPath: "/docs/contract/simulateContract",
|
4135
3831
|
functionName,
|
4136
|
-
sender: account?.address
|
3832
|
+
sender: request.account?.address
|
4137
3833
|
});
|
4138
3834
|
}
|
4139
3835
|
}
|
@@ -5284,12 +4980,7 @@ async function addChain(client, { chain }) {
|
|
5284
4980
|
}
|
5285
4981
|
|
5286
4982
|
// src/actions/wallet/deployContract.ts
|
5287
|
-
function deployContract(walletClient, {
|
5288
|
-
abi,
|
5289
|
-
args,
|
5290
|
-
bytecode,
|
5291
|
-
...request
|
5292
|
-
}) {
|
4983
|
+
function deployContract(walletClient, { abi, args, bytecode, ...request }) {
|
5293
4984
|
const calldata = encodeDeployData({
|
5294
4985
|
abi,
|
5295
4986
|
args,
|
@@ -5330,9 +5021,10 @@ async function requestPermissions(client, permissions) {
|
|
5330
5021
|
// src/actions/wallet/sendTransaction.ts
|
5331
5022
|
async function sendTransaction(client, args) {
|
5332
5023
|
const {
|
5333
|
-
account
|
5024
|
+
account,
|
5334
5025
|
chain = client.chain,
|
5335
5026
|
accessList,
|
5027
|
+
assertChain = true,
|
5336
5028
|
data,
|
5337
5029
|
gas,
|
5338
5030
|
gasPrice,
|
@@ -5343,20 +5035,13 @@ async function sendTransaction(client, args) {
|
|
5343
5035
|
value,
|
5344
5036
|
...rest
|
5345
5037
|
} = args;
|
5346
|
-
if (!account_)
|
5347
|
-
throw new AccountNotFoundError({
|
5348
|
-
docsPath: "/docs/actions/wallet/sendTransaction"
|
5349
|
-
});
|
5350
|
-
const account = parseAccount(account_);
|
5351
5038
|
try {
|
5352
5039
|
assertRequest(args);
|
5353
|
-
const
|
5354
|
-
if (
|
5355
|
-
|
5356
|
-
throw new ChainNotFoundError();
|
5357
|
-
throw new ChainMismatchError({ chain, currentChainId: chainId });
|
5358
|
-
}
|
5040
|
+
const currentChainId = await getChainId(client);
|
5041
|
+
if (assertChain && chain && currentChainId !== chain?.id)
|
5042
|
+
throw new ChainMismatchError({ chain, currentChainId });
|
5359
5043
|
if (account.type === "local") {
|
5044
|
+
const chainId = chain?.id ?? currentChainId;
|
5360
5045
|
const request2 = await prepareRequest(client, {
|
5361
5046
|
account,
|
5362
5047
|
accessList,
|
@@ -5405,28 +5090,15 @@ async function sendTransaction(client, args) {
|
|
5405
5090
|
params: [request]
|
5406
5091
|
});
|
5407
5092
|
} catch (err) {
|
5408
|
-
throw getTransactionError(err,
|
5409
|
-
...args,
|
5410
|
-
account,
|
5411
|
-
chain: args.chain || void 0
|
5412
|
-
});
|
5093
|
+
throw getTransactionError(err, args);
|
5413
5094
|
}
|
5414
5095
|
}
|
5415
5096
|
|
5416
5097
|
// src/actions/wallet/signMessage.ts
|
5417
|
-
async function signMessage(client, {
|
5418
|
-
account: account_ = client.account,
|
5419
|
-
data,
|
5420
|
-
message
|
5421
|
-
}) {
|
5422
|
-
if (!account_)
|
5423
|
-
throw new AccountNotFoundError({
|
5424
|
-
docsPath: "/docs/actions/wallet/signMessage"
|
5425
|
-
});
|
5426
|
-
const account = parseAccount(account_);
|
5098
|
+
async function signMessage(client, { account, data, message }) {
|
5427
5099
|
const message_ = message || data;
|
5428
5100
|
if (account.type === "local")
|
5429
|
-
return account.signMessage(
|
5101
|
+
return account.signMessage(message_);
|
5430
5102
|
return client.request({
|
5431
5103
|
method: "personal_sign",
|
5432
5104
|
params: [toHex(message_), account.address]
|
@@ -5435,17 +5107,12 @@ async function signMessage(client, {
|
|
5435
5107
|
|
5436
5108
|
// src/actions/wallet/signTypedData.ts
|
5437
5109
|
async function signTypedData(client, {
|
5438
|
-
account
|
5110
|
+
account,
|
5439
5111
|
domain,
|
5440
5112
|
message,
|
5441
5113
|
primaryType,
|
5442
5114
|
types: types_
|
5443
5115
|
}) {
|
5444
|
-
if (!account_)
|
5445
|
-
throw new AccountNotFoundError({
|
5446
|
-
docsPath: "/docs/actions/wallet/signTypedData"
|
5447
|
-
});
|
5448
|
-
const account = parseAccount(account_);
|
5449
5116
|
const types = {
|
5450
5117
|
EIP712Domain: [
|
5451
5118
|
domain?.name && { name: "name", type: "string" },
|
@@ -5481,6 +5148,47 @@ async function signTypedData(client, {
|
|
5481
5148
|
params: [account.address, typedData]
|
5482
5149
|
});
|
5483
5150
|
}
|
5151
|
+
function validateTypedData({
|
5152
|
+
domain,
|
5153
|
+
message,
|
5154
|
+
primaryType,
|
5155
|
+
types: types_
|
5156
|
+
}) {
|
5157
|
+
const types = types_;
|
5158
|
+
const validateData = (struct, value_) => {
|
5159
|
+
for (const param of struct) {
|
5160
|
+
const { name, type: type_ } = param;
|
5161
|
+
const type2 = type_;
|
5162
|
+
const value = value_[name];
|
5163
|
+
const integerMatch = type2.match(integerRegex);
|
5164
|
+
if (integerMatch && (typeof value === "number" || typeof value === "bigint")) {
|
5165
|
+
const [_type, base, size_] = integerMatch;
|
5166
|
+
numberToHex(value, {
|
5167
|
+
signed: base === "int",
|
5168
|
+
size: parseInt(size_) / 8
|
5169
|
+
});
|
5170
|
+
}
|
5171
|
+
if (type2 === "address" && typeof value === "string" && !isAddress(value))
|
5172
|
+
throw new InvalidAddressError({ address: value });
|
5173
|
+
const bytesMatch = type2.match(bytesRegex);
|
5174
|
+
if (bytesMatch) {
|
5175
|
+
const [_type, size_] = bytesMatch;
|
5176
|
+
if (size_ && size(value) !== parseInt(size_))
|
5177
|
+
throw new BytesSizeMismatchError({
|
5178
|
+
expectedSize: parseInt(size_),
|
5179
|
+
givenSize: size(value)
|
5180
|
+
});
|
5181
|
+
}
|
5182
|
+
const struct2 = types[type2];
|
5183
|
+
if (struct2)
|
5184
|
+
validateData(struct2, value);
|
5185
|
+
}
|
5186
|
+
};
|
5187
|
+
if (types["EIP712Domain"] && domain)
|
5188
|
+
validateData(types["EIP712Domain"], domain);
|
5189
|
+
const type = types[primaryType];
|
5190
|
+
validateData(type, message);
|
5191
|
+
}
|
5484
5192
|
|
5485
5193
|
// src/actions/wallet/switchChain.ts
|
5486
5194
|
async function switchChain(client, { id: id2 }) {
|
@@ -5554,17 +5262,7 @@ function parseGwei(ether, unit = "wei") {
|
|
5554
5262
|
// src/utils/transaction/prepareRequest.ts
|
5555
5263
|
var defaultTip = parseGwei("1.5");
|
5556
5264
|
async function prepareRequest(client, args) {
|
5557
|
-
const {
|
5558
|
-
account: account_,
|
5559
|
-
gas,
|
5560
|
-
gasPrice,
|
5561
|
-
maxFeePerGas,
|
5562
|
-
maxPriorityFeePerGas,
|
5563
|
-
nonce
|
5564
|
-
} = args;
|
5565
|
-
if (!account_)
|
5566
|
-
throw new AccountNotFoundError();
|
5567
|
-
const account = parseAccount(account_);
|
5265
|
+
const { account, gas, gasPrice, maxFeePerGas, maxPriorityFeePerGas, nonce } = args;
|
5568
5266
|
const block = await getBlock(client, { blockTag: "latest" });
|
5569
5267
|
const request = { ...args, from: account.address };
|
5570
5268
|
if (typeof nonce === "undefined")
|
@@ -5756,7 +5454,6 @@ export {
|
|
5756
5454
|
getEventSelector,
|
5757
5455
|
getFunctionSelector,
|
5758
5456
|
isAddress,
|
5759
|
-
checksumAddress,
|
5760
5457
|
getAddress,
|
5761
5458
|
getContractAddress2 as getContractAddress,
|
5762
5459
|
getCreateAddress,
|
@@ -5784,7 +5481,7 @@ export {
|
|
5784
5481
|
parseAbiItem,
|
5785
5482
|
parseAbiParameter,
|
5786
5483
|
parseAbiParameters,
|
5787
|
-
|
5484
|
+
getAccount,
|
5788
5485
|
isDeterministicError,
|
5789
5486
|
buildRequest,
|
5790
5487
|
defineChain,
|
@@ -5810,13 +5507,9 @@ export {
|
|
5810
5507
|
getSocket,
|
5811
5508
|
rpc,
|
5812
5509
|
hashMessage,
|
5813
|
-
validateTypedData,
|
5814
|
-
hashTypedData,
|
5815
5510
|
recoverAddress,
|
5816
5511
|
recoverMessageAddress,
|
5817
|
-
recoverTypedDataAddress,
|
5818
5512
|
verifyMessage,
|
5819
|
-
verifyTypedData,
|
5820
5513
|
assertRequest,
|
5821
5514
|
call,
|
5822
5515
|
simulateContract,
|
@@ -5900,4 +5593,4 @@ export {
|
|
5900
5593
|
formatGwei,
|
5901
5594
|
parseEther
|
5902
5595
|
};
|
5903
|
-
//# sourceMappingURL=chunk-
|
5596
|
+
//# sourceMappingURL=chunk-FOJL5WVL.mjs.map
|