viem 0.1.9 → 0.1.11
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-81b3f26c.d.ts → chain-41dcec4b.d.ts} +1 -1
- package/dist/{chain-d64be356.d.ts → chain-792d51c3.d.ts} +113 -137
- package/dist/chains.d.ts +3 -3
- package/dist/chains.js +63 -63
- package/dist/chains.mjs +1 -1
- package/dist/{chunk-JTX5BKWL.js → chunk-ADJTWF45.js} +19 -19
- package/dist/{chunk-GQ3EDBYX.mjs → chunk-H6AQHA74.mjs} +110 -6
- package/dist/chunk-H6AQHA74.mjs.map +1 -0
- package/dist/{chunk-BYG4UCLI.mjs → chunk-IAY6WXS3.mjs} +2 -2
- package/dist/{chunk-NJT5TACH.js → chunk-YZCQ7AL7.js} +111 -7
- package/dist/{chunk-GQ3EDBYX.mjs.map → chunk-YZCQ7AL7.js.map} +1 -1
- package/dist/contract.d.ts +8 -8
- package/dist/contract.js +2 -2
- package/dist/contract.mjs +1 -1
- package/dist/{createClient-8575dcd6.d.ts → createClient-6cd6daa3.d.ts} +2 -2
- package/dist/{createPublicClient-4d54af8a.d.ts → createPublicClient-34d3ba9d.d.ts} +117 -72
- package/dist/{eip1193-029d52f0.d.ts → eip1193-2f116cf7.d.ts} +4 -4
- package/dist/{encodeFunctionResult-12963e93.d.ts → encodeFunctionResult-874fe003.d.ts} +1 -1
- package/dist/{encodePacked-98b20b4d.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/{formatAbiItem-8ee3a7fa.d.ts → formatAbiItem-1bdb43d3.d.ts} +1 -1
- package/dist/{getAbiItem-de103f9b.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-66ef1ac7.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-f964519b.d.ts → test-6b2b1b0d.d.ts} +3 -3
- package/dist/test.d.ts +6 -6
- 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/package.json +2 -2
- package/dist/chunk-NJT5TACH.js.map +0 -1
- /package/dist/{chunk-JTX5BKWL.js.map → chunk-ADJTWF45.js.map} +0 -0
- /package/dist/{chunk-BYG4UCLI.mjs.map → chunk-IAY6WXS3.mjs.map} +0 -0
@@ -11,27 +11,27 @@
|
|
11
11
|
|
12
12
|
|
13
13
|
|
14
|
-
var
|
14
|
+
var _chunkYZCQ7AL7js = require('./chunk-YZCQ7AL7.js');
|
15
15
|
|
16
16
|
// src/utils/ens/labelhash.ts
|
17
17
|
function labelhash(label) {
|
18
18
|
let result = new Uint8Array(32).fill(0);
|
19
19
|
if (!label)
|
20
|
-
return
|
21
|
-
return
|
20
|
+
return _chunkYZCQ7AL7js.bytesToHex.call(void 0, result);
|
21
|
+
return _chunkYZCQ7AL7js.keccak256.call(void 0, _chunkYZCQ7AL7js.stringToBytes.call(void 0, label));
|
22
22
|
}
|
23
23
|
|
24
24
|
// src/utils/ens/namehash.ts
|
25
25
|
function namehash(name) {
|
26
26
|
let result = new Uint8Array(32).fill(0);
|
27
27
|
if (!name)
|
28
|
-
return
|
28
|
+
return _chunkYZCQ7AL7js.bytesToHex.call(void 0, result);
|
29
29
|
const labels = name.split(".");
|
30
30
|
for (let i = labels.length - 1; i >= 0; i -= 1) {
|
31
|
-
const hashed =
|
32
|
-
result =
|
31
|
+
const hashed = _chunkYZCQ7AL7js.keccak256.call(void 0, _chunkYZCQ7AL7js.stringToBytes.call(void 0, labels[i]), "bytes");
|
32
|
+
result = _chunkYZCQ7AL7js.keccak256.call(void 0, _chunkYZCQ7AL7js.concat.call(void 0, [result, hashed]), "bytes");
|
33
33
|
}
|
34
|
-
return
|
34
|
+
return _chunkYZCQ7AL7js.bytesToHex.call(void 0, result);
|
35
35
|
}
|
36
36
|
|
37
37
|
// src/utils/ens/packetToBytes.ts
|
@@ -39,7 +39,7 @@ function packetToBytes(packet) {
|
|
39
39
|
function length(value2) {
|
40
40
|
if (value2 === "." || value2 === "..")
|
41
41
|
return 1;
|
42
|
-
return
|
42
|
+
return _chunkYZCQ7AL7js.toBytes.call(void 0, value2.replace(/^\.|\.$/gm, "")).length + 2;
|
43
43
|
}
|
44
44
|
const bytes = new Uint8Array(length(packet));
|
45
45
|
const value = packet.replace(/^\.|\.$/gm, "");
|
@@ -48,7 +48,7 @@ function packetToBytes(packet) {
|
|
48
48
|
let offset = 0;
|
49
49
|
const list = value.split(".");
|
50
50
|
for (let i = 0; i < list.length; i++) {
|
51
|
-
const encoded =
|
51
|
+
const encoded = _chunkYZCQ7AL7js.toBytes.call(void 0, list[i]);
|
52
52
|
bytes[offset] = encoded.length;
|
53
53
|
bytes.set(encoded, offset + 1);
|
54
54
|
offset += encoded.length + 1;
|
@@ -69,13 +69,13 @@ async function getEnsAddress(client, {
|
|
69
69
|
throw new Error(
|
70
70
|
"client chain not configured. universalResolverAddress is required."
|
71
71
|
);
|
72
|
-
universalResolverAddress =
|
72
|
+
universalResolverAddress = _chunkYZCQ7AL7js.getChainContractAddress.call(void 0, {
|
73
73
|
blockNumber,
|
74
74
|
chain: client.chain,
|
75
75
|
contract: "ensUniversalResolver"
|
76
76
|
});
|
77
77
|
}
|
78
|
-
const res = await
|
78
|
+
const res = await _chunkYZCQ7AL7js.readContract.call(void 0, client, {
|
79
79
|
address: universalResolverAddress,
|
80
80
|
abi: [
|
81
81
|
{
|
@@ -94,8 +94,8 @@ async function getEnsAddress(client, {
|
|
94
94
|
],
|
95
95
|
functionName: "resolve",
|
96
96
|
args: [
|
97
|
-
|
98
|
-
|
97
|
+
_chunkYZCQ7AL7js.toHex.call(void 0, packetToBytes(name)),
|
98
|
+
_chunkYZCQ7AL7js.encodeFunctionData.call(void 0, {
|
99
99
|
abi: [
|
100
100
|
{
|
101
101
|
name: "addr",
|
@@ -112,7 +112,7 @@ async function getEnsAddress(client, {
|
|
112
112
|
blockNumber,
|
113
113
|
blockTag
|
114
114
|
});
|
115
|
-
return
|
115
|
+
return _chunkYZCQ7AL7js.decodeFunctionResult.call(void 0, {
|
116
116
|
abi: [
|
117
117
|
{
|
118
118
|
name: "addr",
|
@@ -140,7 +140,7 @@ async function getEnsName(client, {
|
|
140
140
|
throw new Error(
|
141
141
|
"client chain not configured. universalResolverAddress is required."
|
142
142
|
);
|
143
|
-
universalResolverAddress =
|
143
|
+
universalResolverAddress = _chunkYZCQ7AL7js.getChainContractAddress.call(void 0, {
|
144
144
|
blockNumber,
|
145
145
|
chain: client.chain,
|
146
146
|
contract: "ensUniversalResolver"
|
@@ -148,7 +148,7 @@ async function getEnsName(client, {
|
|
148
148
|
}
|
149
149
|
const reverseNode = `${address.toLowerCase().substring(2)}.addr.reverse`;
|
150
150
|
try {
|
151
|
-
const res = await
|
151
|
+
const res = await _chunkYZCQ7AL7js.readContract.call(void 0, client, {
|
152
152
|
address: universalResolverAddress,
|
153
153
|
abi: [
|
154
154
|
{
|
@@ -165,13 +165,13 @@ async function getEnsName(client, {
|
|
165
165
|
}
|
166
166
|
],
|
167
167
|
functionName: "reverse",
|
168
|
-
args: [
|
168
|
+
args: [_chunkYZCQ7AL7js.toHex.call(void 0, packetToBytes(reverseNode))],
|
169
169
|
blockNumber,
|
170
170
|
blockTag
|
171
171
|
});
|
172
172
|
return res[0];
|
173
173
|
} catch (error) {
|
174
|
-
if (error instanceof
|
174
|
+
if (error instanceof _chunkYZCQ7AL7js.ContractFunctionExecutionError && error.cause.reason === _chunkYZCQ7AL7js.panicReasons[50])
|
175
175
|
return null;
|
176
176
|
throw error;
|
177
177
|
}
|
@@ -183,4 +183,4 @@ async function getEnsName(client, {
|
|
183
183
|
|
184
184
|
|
185
185
|
exports.labelhash = labelhash; exports.namehash = namehash; exports.getEnsAddress = getEnsAddress; exports.getEnsName = getEnsName;
|
186
|
-
//# sourceMappingURL=chunk-
|
186
|
+
//# sourceMappingURL=chunk-ADJTWF45.js.map
|
@@ -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.11",
|
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",
|
@@ -131,7 +131,7 @@ var package_default = {
|
|
131
131
|
dependencies: {
|
132
132
|
"@noble/hashes": "^1.1.2",
|
133
133
|
"@wagmi/chains": "~0.2.11",
|
134
|
-
abitype: "~0.
|
134
|
+
abitype: "~0.7.1",
|
135
135
|
"idna-uts46-hx": "^4.1.2",
|
136
136
|
"isomorphic-ws": "^5.0.0",
|
137
137
|
ws: "^8.12.0"
|
@@ -936,6 +936,20 @@ var DataLengthTooShortError = class extends BaseError {
|
|
936
936
|
__publicField(this, "name", "DataLengthTooShortError");
|
937
937
|
}
|
938
938
|
};
|
939
|
+
var IntegerOutOfRangeError = class extends BaseError {
|
940
|
+
constructor({
|
941
|
+
max,
|
942
|
+
min,
|
943
|
+
signed,
|
944
|
+
size: size2,
|
945
|
+
value
|
946
|
+
}) {
|
947
|
+
super(
|
948
|
+
`Number "${value}" is not in safe ${size2 ? `${size2 * 8}-bit ${signed ? "signed" : "unsigned"} ` : ""}integer range ${max ? `(${min} to ${max})` : `(above ${min})`}`
|
949
|
+
);
|
950
|
+
__publicField(this, "name", "IntegerOutOfRangeError");
|
951
|
+
}
|
952
|
+
};
|
939
953
|
var InvalidBytesBooleanError = class extends BaseError {
|
940
954
|
constructor(bytes) {
|
941
955
|
super(
|
@@ -1589,9 +1603,13 @@ function numberToHex(value_, opts = {}) {
|
|
1589
1603
|
const minValue = typeof maxValue === "bigint" && signed ? -maxValue - 1n : 0;
|
1590
1604
|
if (maxValue && value > maxValue || value < minValue) {
|
1591
1605
|
const suffix = typeof value_ === "bigint" ? "n" : "";
|
1592
|
-
throw new
|
1593
|
-
|
1594
|
-
|
1606
|
+
throw new IntegerOutOfRangeError({
|
1607
|
+
max: maxValue ? `${maxValue}${suffix}` : void 0,
|
1608
|
+
min: `${minValue}${suffix}`,
|
1609
|
+
signed,
|
1610
|
+
size: size2,
|
1611
|
+
value: `${value_}${suffix}`
|
1612
|
+
});
|
1595
1613
|
}
|
1596
1614
|
const hex = `0x${(signed && value < 0 ? (1n << BigInt(size2 * 8)) + BigInt(value) : value).toString(16)}`;
|
1597
1615
|
if (size2)
|
@@ -4987,6 +5005,91 @@ async function signMessage(client, { account, data }) {
|
|
4987
5005
|
});
|
4988
5006
|
}
|
4989
5007
|
|
5008
|
+
// src/actions/wallet/signTypedData.ts
|
5009
|
+
async function signTypedData(client, {
|
5010
|
+
account,
|
5011
|
+
domain,
|
5012
|
+
message,
|
5013
|
+
primaryType,
|
5014
|
+
types: types_
|
5015
|
+
}) {
|
5016
|
+
const types = {
|
5017
|
+
EIP712Domain: [
|
5018
|
+
domain?.name && { name: "name", type: "string" },
|
5019
|
+
domain?.version && { name: "version", type: "string" },
|
5020
|
+
domain?.chainId && { name: "chainId", type: "uint256" },
|
5021
|
+
domain?.verifyingContract && {
|
5022
|
+
name: "verifyingContract",
|
5023
|
+
type: "address"
|
5024
|
+
},
|
5025
|
+
domain?.salt && { name: "salt", type: "bytes32" }
|
5026
|
+
].filter(Boolean),
|
5027
|
+
...types_
|
5028
|
+
};
|
5029
|
+
validateTypedData({
|
5030
|
+
domain,
|
5031
|
+
message,
|
5032
|
+
primaryType,
|
5033
|
+
types
|
5034
|
+
});
|
5035
|
+
if (account.type === "local")
|
5036
|
+
return account.signTypedData({
|
5037
|
+
domain,
|
5038
|
+
primaryType,
|
5039
|
+
types,
|
5040
|
+
message
|
5041
|
+
});
|
5042
|
+
const typedData = stringify(
|
5043
|
+
{ domain: domain ?? {}, primaryType, types, message },
|
5044
|
+
(_, value) => isHex(value) ? value.toLowerCase() : value
|
5045
|
+
);
|
5046
|
+
return client.request({
|
5047
|
+
method: "eth_signTypedData_v4",
|
5048
|
+
params: [account.address, typedData]
|
5049
|
+
});
|
5050
|
+
}
|
5051
|
+
function validateTypedData({
|
5052
|
+
domain,
|
5053
|
+
message,
|
5054
|
+
primaryType,
|
5055
|
+
types: types_
|
5056
|
+
}) {
|
5057
|
+
const types = types_;
|
5058
|
+
const validateData = (struct, value_) => {
|
5059
|
+
for (const param of struct) {
|
5060
|
+
const { name, type: type_ } = param;
|
5061
|
+
const type2 = type_;
|
5062
|
+
const value = value_[name];
|
5063
|
+
const integerMatch = type2.match(integerRegex);
|
5064
|
+
if (integerMatch && (typeof value === "number" || typeof value === "bigint")) {
|
5065
|
+
const [_type, base, size_] = integerMatch;
|
5066
|
+
numberToHex(value, {
|
5067
|
+
signed: base === "int",
|
5068
|
+
size: parseInt(size_) / 8
|
5069
|
+
});
|
5070
|
+
}
|
5071
|
+
if (type2 === "address" && typeof value === "string" && !isAddress(value))
|
5072
|
+
throw new InvalidAddressError({ address: value });
|
5073
|
+
const bytesMatch = type2.match(bytesRegex);
|
5074
|
+
if (bytesMatch) {
|
5075
|
+
const [_type, size_] = bytesMatch;
|
5076
|
+
if (size_ && size(value) !== parseInt(size_))
|
5077
|
+
throw new BytesSizeMismatchError({
|
5078
|
+
expectedSize: parseInt(size_),
|
5079
|
+
givenSize: size(value)
|
5080
|
+
});
|
5081
|
+
}
|
5082
|
+
const struct2 = types[type2];
|
5083
|
+
if (struct2)
|
5084
|
+
validateData(struct2, value);
|
5085
|
+
}
|
5086
|
+
};
|
5087
|
+
if (types["EIP712Domain"] && domain)
|
5088
|
+
validateData(types["EIP712Domain"], domain);
|
5089
|
+
const type = types[primaryType];
|
5090
|
+
validateData(type, message);
|
5091
|
+
}
|
5092
|
+
|
4990
5093
|
// src/actions/wallet/switchChain.ts
|
4991
5094
|
async function switchChain(client, { id: id2 }) {
|
4992
5095
|
await client.request({
|
@@ -5370,6 +5473,7 @@ export {
|
|
5370
5473
|
requestPermissions,
|
5371
5474
|
sendTransaction,
|
5372
5475
|
signMessage,
|
5476
|
+
signTypedData,
|
5373
5477
|
switchChain,
|
5374
5478
|
watchAsset,
|
5375
5479
|
writeContract,
|
@@ -5381,4 +5485,4 @@ export {
|
|
5381
5485
|
formatGwei,
|
5382
5486
|
parseEther
|
5383
5487
|
};
|
5384
|
-
//# sourceMappingURL=chunk-
|
5488
|
+
//# sourceMappingURL=chunk-H6AQHA74.mjs.map
|