viem 0.1.10 → 0.1.12
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-f8edc5d7.d.ts → chain-41dcec4b.d.ts} +1 -1
- package/dist/{chain-94f99620.d.ts → chain-792d51c3.d.ts} +107 -107
- package/dist/chains.d.ts +3 -3
- package/dist/chains.js +63 -63
- package/dist/chains.mjs +1 -1
- package/dist/{chunk-5FH7E6C5.js → chunk-2TGSUQZ6.js} +19 -19
- package/dist/{chunk-6YZF7223.mjs → chunk-6C7XIWBD.mjs} +2 -2
- package/dist/{chunk-L5P7BYGT.js → chunk-Q6OIGGTK.js} +117 -6
- package/dist/chunk-Q6OIGGTK.js.map +1 -0
- package/dist/{chunk-UI4RZ2SR.mjs → chunk-XULBGJK5.mjs} +116 -5
- package/dist/chunk-XULBGJK5.mjs.map +1 -0
- package/dist/contract.d.ts +7 -7
- package/dist/contract.js +2 -2
- package/dist/contract.mjs +1 -1
- package/dist/{createClient-ff222f1b.d.ts → createClient-6cd6daa3.d.ts} +2 -2
- package/dist/{createPublicClient-110e0ff7.d.ts → createPublicClient-34d3ba9d.d.ts} +117 -72
- package/dist/{eip1193-e31a0368.d.ts → eip1193-2f116cf7.d.ts} +4 -4
- package/dist/{encodeFunctionResult-5455530b.d.ts → encodeFunctionResult-874fe003.d.ts} +1 -1
- package/dist/{encodePacked-de79982f.d.ts → encodePacked-9ab98aa9.d.ts} +1 -1
- package/dist/ens.d.ts +4 -4
- package/dist/ens.js +3 -3
- package/dist/ens.mjs +2 -2
- package/dist/ethers.d.ts +29 -0
- package/dist/ethers.js +30 -0
- package/dist/ethers.js.map +1 -0
- package/dist/ethers.mjs +30 -0
- package/dist/ethers.mjs.map +1 -0
- package/dist/{formatAbiItem-62cbb896.d.ts → formatAbiItem-1bdb43d3.d.ts} +1 -1
- package/dist/{getAbiItem-46aa68bf.d.ts → getAbiItem-f19d50a2.d.ts} +1 -1
- package/dist/index.d.ts +13 -13
- package/dist/index.js +91 -89
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -2
- package/dist/index.mjs.map +1 -1
- package/dist/{parseGwei-d221a29d.d.ts → parseGwei-faf061db.d.ts} +3 -3
- package/dist/public.d.ts +4 -4
- package/dist/public.js +2 -2
- package/dist/public.mjs +1 -1
- package/dist/{test-796738d1.d.ts → test-6b2b1b0d.d.ts} +3 -3
- package/dist/test.d.ts +5 -5
- package/dist/test.js +2 -2
- package/dist/test.mjs +1 -1
- package/dist/utils/index.d.ts +13 -13
- package/dist/utils/index.js +2 -2
- package/dist/utils/index.mjs +1 -1
- package/dist/wallet.d.ts +4 -4
- package/dist/wallet.js +4 -2
- package/dist/wallet.mjs +3 -1
- package/dist/window.d.ts +2 -2
- package/ethers/package.json +4 -0
- package/package.json +7 -1
- package/dist/chunk-L5P7BYGT.js.map +0 -1
- package/dist/chunk-UI4RZ2SR.mjs.map +0 -1
- /package/dist/{chunk-5FH7E6C5.js.map → chunk-2TGSUQZ6.js.map} +0 -0
- /package/dist/{chunk-6YZF7223.mjs.map → chunk-6C7XIWBD.mjs.map} +0 -0
@@ -17,7 +17,7 @@ import {
|
|
17
17
|
var package_default = {
|
18
18
|
name: "viem",
|
19
19
|
description: "TypeScript Interface for Ethereum",
|
20
|
-
version: "0.1.
|
20
|
+
version: "0.1.12",
|
21
21
|
scripts: {
|
22
22
|
anvil: "source .env && anvil --fork-url $VITE_ANVIL_FORK_URL --fork-block-number $VITE_ANVIL_BLOCK_NUMBER --block-time $VITE_ANVIL_BLOCK_TIME",
|
23
23
|
bench: "vitest bench --no-threads",
|
@@ -52,6 +52,7 @@ var package_default = {
|
|
52
52
|
"src/chains.ts",
|
53
53
|
"src/contract.ts",
|
54
54
|
"src/ens.ts",
|
55
|
+
"src/ethers.ts",
|
55
56
|
"src/public.ts",
|
56
57
|
"src/test.ts",
|
57
58
|
"src/utils/index.ts",
|
@@ -65,6 +66,7 @@ var package_default = {
|
|
65
66
|
"/chains",
|
66
67
|
"/contract",
|
67
68
|
"/ens",
|
69
|
+
"/ethers",
|
68
70
|
"/public",
|
69
71
|
"/test",
|
70
72
|
"/utils",
|
@@ -97,6 +99,11 @@ var package_default = {
|
|
97
99
|
module: "./dist/ens.mts",
|
98
100
|
default: "./dist/ens.js"
|
99
101
|
},
|
102
|
+
"./ethers": {
|
103
|
+
types: "./dist/ethers.d.ts",
|
104
|
+
module: "./dist/ethers.mts",
|
105
|
+
default: "./dist/ethers.js"
|
106
|
+
},
|
100
107
|
"./public": {
|
101
108
|
types: "./dist/public.d.ts",
|
102
109
|
module: "./dist/public.mts",
|
@@ -936,6 +943,20 @@ var DataLengthTooShortError = class extends BaseError {
|
|
936
943
|
__publicField(this, "name", "DataLengthTooShortError");
|
937
944
|
}
|
938
945
|
};
|
946
|
+
var IntegerOutOfRangeError = class extends BaseError {
|
947
|
+
constructor({
|
948
|
+
max,
|
949
|
+
min,
|
950
|
+
signed,
|
951
|
+
size: size2,
|
952
|
+
value
|
953
|
+
}) {
|
954
|
+
super(
|
955
|
+
`Number "${value}" is not in safe ${size2 ? `${size2 * 8}-bit ${signed ? "signed" : "unsigned"} ` : ""}integer range ${max ? `(${min} to ${max})` : `(above ${min})`}`
|
956
|
+
);
|
957
|
+
__publicField(this, "name", "IntegerOutOfRangeError");
|
958
|
+
}
|
959
|
+
};
|
939
960
|
var InvalidBytesBooleanError = class extends BaseError {
|
940
961
|
constructor(bytes) {
|
941
962
|
super(
|
@@ -1589,9 +1610,13 @@ function numberToHex(value_, opts = {}) {
|
|
1589
1610
|
const minValue = typeof maxValue === "bigint" && signed ? -maxValue - 1n : 0;
|
1590
1611
|
if (maxValue && value > maxValue || value < minValue) {
|
1591
1612
|
const suffix = typeof value_ === "bigint" ? "n" : "";
|
1592
|
-
throw new
|
1593
|
-
|
1594
|
-
|
1613
|
+
throw new IntegerOutOfRangeError({
|
1614
|
+
max: maxValue ? `${maxValue}${suffix}` : void 0,
|
1615
|
+
min: `${minValue}${suffix}`,
|
1616
|
+
signed,
|
1617
|
+
size: size2,
|
1618
|
+
value: `${value_}${suffix}`
|
1619
|
+
});
|
1595
1620
|
}
|
1596
1621
|
const hex = `0x${(signed && value < 0 ? (1n << BigInt(size2 * 8)) + BigInt(value) : value).toString(16)}`;
|
1597
1622
|
if (size2)
|
@@ -4987,6 +5012,91 @@ async function signMessage(client, { account, data }) {
|
|
4987
5012
|
});
|
4988
5013
|
}
|
4989
5014
|
|
5015
|
+
// src/actions/wallet/signTypedData.ts
|
5016
|
+
async function signTypedData(client, {
|
5017
|
+
account,
|
5018
|
+
domain,
|
5019
|
+
message,
|
5020
|
+
primaryType,
|
5021
|
+
types: types_
|
5022
|
+
}) {
|
5023
|
+
const types = {
|
5024
|
+
EIP712Domain: [
|
5025
|
+
domain?.name && { name: "name", type: "string" },
|
5026
|
+
domain?.version && { name: "version", type: "string" },
|
5027
|
+
domain?.chainId && { name: "chainId", type: "uint256" },
|
5028
|
+
domain?.verifyingContract && {
|
5029
|
+
name: "verifyingContract",
|
5030
|
+
type: "address"
|
5031
|
+
},
|
5032
|
+
domain?.salt && { name: "salt", type: "bytes32" }
|
5033
|
+
].filter(Boolean),
|
5034
|
+
...types_
|
5035
|
+
};
|
5036
|
+
validateTypedData({
|
5037
|
+
domain,
|
5038
|
+
message,
|
5039
|
+
primaryType,
|
5040
|
+
types
|
5041
|
+
});
|
5042
|
+
if (account.type === "local")
|
5043
|
+
return account.signTypedData({
|
5044
|
+
domain,
|
5045
|
+
primaryType,
|
5046
|
+
types,
|
5047
|
+
message
|
5048
|
+
});
|
5049
|
+
const typedData = stringify(
|
5050
|
+
{ domain: domain ?? {}, primaryType, types, message },
|
5051
|
+
(_, value) => isHex(value) ? value.toLowerCase() : value
|
5052
|
+
);
|
5053
|
+
return client.request({
|
5054
|
+
method: "eth_signTypedData_v4",
|
5055
|
+
params: [account.address, typedData]
|
5056
|
+
});
|
5057
|
+
}
|
5058
|
+
function validateTypedData({
|
5059
|
+
domain,
|
5060
|
+
message,
|
5061
|
+
primaryType,
|
5062
|
+
types: types_
|
5063
|
+
}) {
|
5064
|
+
const types = types_;
|
5065
|
+
const validateData = (struct, value_) => {
|
5066
|
+
for (const param of struct) {
|
5067
|
+
const { name, type: type_ } = param;
|
5068
|
+
const type2 = type_;
|
5069
|
+
const value = value_[name];
|
5070
|
+
const integerMatch = type2.match(integerRegex);
|
5071
|
+
if (integerMatch && (typeof value === "number" || typeof value === "bigint")) {
|
5072
|
+
const [_type, base, size_] = integerMatch;
|
5073
|
+
numberToHex(value, {
|
5074
|
+
signed: base === "int",
|
5075
|
+
size: parseInt(size_) / 8
|
5076
|
+
});
|
5077
|
+
}
|
5078
|
+
if (type2 === "address" && typeof value === "string" && !isAddress(value))
|
5079
|
+
throw new InvalidAddressError({ address: value });
|
5080
|
+
const bytesMatch = type2.match(bytesRegex);
|
5081
|
+
if (bytesMatch) {
|
5082
|
+
const [_type, size_] = bytesMatch;
|
5083
|
+
if (size_ && size(value) !== parseInt(size_))
|
5084
|
+
throw new BytesSizeMismatchError({
|
5085
|
+
expectedSize: parseInt(size_),
|
5086
|
+
givenSize: size(value)
|
5087
|
+
});
|
5088
|
+
}
|
5089
|
+
const struct2 = types[type2];
|
5090
|
+
if (struct2)
|
5091
|
+
validateData(struct2, value);
|
5092
|
+
}
|
5093
|
+
};
|
5094
|
+
if (types["EIP712Domain"] && domain)
|
5095
|
+
validateData(types["EIP712Domain"], domain);
|
5096
|
+
const type = types[primaryType];
|
5097
|
+
validateData(type, message);
|
5098
|
+
}
|
5099
|
+
|
4990
5100
|
// src/actions/wallet/switchChain.ts
|
4991
5101
|
async function switchChain(client, { id: id2 }) {
|
4992
5102
|
await client.request({
|
@@ -5370,6 +5480,7 @@ export {
|
|
5370
5480
|
requestPermissions,
|
5371
5481
|
sendTransaction,
|
5372
5482
|
signMessage,
|
5483
|
+
signTypedData,
|
5373
5484
|
switchChain,
|
5374
5485
|
watchAsset,
|
5375
5486
|
writeContract,
|
@@ -5381,4 +5492,4 @@ export {
|
|
5381
5492
|
formatGwei,
|
5382
5493
|
parseEther
|
5383
5494
|
};
|
5384
|
-
//# sourceMappingURL=chunk-
|
5495
|
+
//# sourceMappingURL=chunk-XULBGJK5.mjs.map
|