viem 0.0.1-alpha.26 → 0.0.1-alpha.27

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.
@@ -6,13 +6,177 @@ var __publicField = (obj, key, value) => {
6
6
  };
7
7
 
8
8
  // package.json
9
- var name = "viem";
10
- var version = "0.0.1-alpha.26";
9
+ var package_default = {
10
+ name: "viem",
11
+ description: "TypeScript Interface for Ethereum",
12
+ version: "0.0.1-alpha.26",
13
+ scripts: {
14
+ anvil: "source .env && anvil --fork-url $VITE_ANVIL_FORK_URL --fork-block-number $VITE_ANVIL_BLOCK_NUMBER --block-time $VITE_ANVIL_BLOCK_TIME",
15
+ bench: "vitest bench --no-threads",
16
+ "bench:ci": "CI=true vitest bench --no-threads",
17
+ build: "tsup",
18
+ changeset: "changeset",
19
+ "changeset:release": "pnpm build && changeset publish",
20
+ "changeset:version": "changeset version && pnpm install --lockfile-only",
21
+ clean: "rimraf dist chains contract ens public test utils wallet window",
22
+ "contracts:build": "wagmi generate",
23
+ dev: "DEV=true tsup",
24
+ "dev:docs": "pnpm -r --filter site dev",
25
+ format: "rome format src/ --write",
26
+ lint: "rome check .",
27
+ "lint:fix": "pnpm lint --apply-suggested",
28
+ playground: "pnpm --filter playground-browser dev",
29
+ postinstall: "pnpm dev && pnpm contracts:build",
30
+ preinstall: "npx only-allow pnpm",
31
+ prepublishOnly: "pnpm bun scripts/prepublishOnly.ts",
32
+ prepare: "npx simple-git-hooks",
33
+ test: "vitest dev --no-threads",
34
+ "test:cov": "vitest dev --coverage --no-threads",
35
+ "test:ci": "CI=true vitest --coverage --no-threads",
36
+ "test:ui": "vitest dev --ui --no-threads",
37
+ "ts-node": "bun",
38
+ typecheck: "tsc --noEmit"
39
+ },
40
+ tsup: {
41
+ entry: [
42
+ "src/index.ts",
43
+ "src/chains.ts",
44
+ "src/contract.ts",
45
+ "src/ens.ts",
46
+ "src/public.ts",
47
+ "src/test.ts",
48
+ "src/utils/index.ts",
49
+ "src/wallet.ts",
50
+ "src/window.ts"
51
+ ]
52
+ },
53
+ files: [
54
+ "/dist",
55
+ "/chains",
56
+ "/contract",
57
+ "/ens",
58
+ "/public",
59
+ "/test",
60
+ "/utils",
61
+ "/wallet",
62
+ "/window"
63
+ ],
64
+ exports: {
65
+ ".": {
66
+ types: "./dist/index.d.ts",
67
+ module: "./dist/index.mts",
68
+ default: "./dist/index.js"
69
+ },
70
+ "./chains": {
71
+ types: "./dist/chains.d.ts",
72
+ module: "./dist/chains.mts",
73
+ default: "./dist/chains.js"
74
+ },
75
+ "./contract": {
76
+ types: "./dist/contract.d.ts",
77
+ module: "./dist/contract.mts",
78
+ default: "./dist/contract.js"
79
+ },
80
+ "./ens": {
81
+ types: "./dist/ens.d.ts",
82
+ module: "./dist/ens.mts",
83
+ default: "./dist/ens.js"
84
+ },
85
+ "./public": {
86
+ types: "./dist/public.d.ts",
87
+ module: "./dist/public.mts",
88
+ default: "./dist/public.js"
89
+ },
90
+ "./test": {
91
+ types: "./dist/test.d.ts",
92
+ module: "./dist/test.mts",
93
+ default: "./dist/test.js"
94
+ },
95
+ "./utils": {
96
+ types: "./dist/utils/index.d.ts",
97
+ module: "./dist/utils/index.mts",
98
+ default: "./dist/utils/index.js"
99
+ },
100
+ "./wallet": {
101
+ types: "./dist/wallet.d.ts",
102
+ module: "./dist/wallet.mts",
103
+ default: "./dist/wallet.js"
104
+ },
105
+ "./window": {
106
+ types: "./dist/window.d.ts",
107
+ module: "./dist/window.mts",
108
+ default: "./dist/window.js"
109
+ },
110
+ "./package.json": "./package.json"
111
+ },
112
+ main: "dist/index.js",
113
+ module: "dist/index.mjs",
114
+ types: "dist/index.d.ts",
115
+ sideEffects: false,
116
+ dependencies: {
117
+ "@noble/hashes": "^1.1.2",
118
+ "@wagmi/chains": "~0.2.8",
119
+ abitype: "~0.3.0",
120
+ "idna-uts46-hx": "^4.1.2",
121
+ "isomorphic-ws": "^5.0.0",
122
+ ws: "^8.12.0"
123
+ },
124
+ devDependencies: {
125
+ "@actions/core": "^1.10.0",
126
+ "@actions/github": "^5.1.1",
127
+ "@adraffy/ens-normalize": "^1.8.9",
128
+ "@changesets/changelog-github": "^0.4.5",
129
+ "@changesets/cli": "^2.23.2",
130
+ "@types/dedent": "^0.7.0",
131
+ "@types/fs-extra": "^9.0.13",
132
+ "@types/node": "^17.0.45",
133
+ "@types/ws": "^8.5.4",
134
+ "@vitest/coverage-c8": "^0.24.3",
135
+ "@vitest/ui": "^0.19.1",
136
+ "@wagmi/cli": "^0.1.6",
137
+ bun: "^0.5.5",
138
+ bundlewatch: "^0.3.3",
139
+ dedent: "^0.7.0",
140
+ ethers: "^5.7.2",
141
+ "ethers@6": "npm:ethers@^6.0.2",
142
+ execa: "^6.1.0",
143
+ "fs-extra": "^10.1.0",
144
+ rimraf: "^4.1.2",
145
+ rome: "^11.0.0",
146
+ "simple-git-hooks": "^2.8.1",
147
+ tsup: "^6.6.0",
148
+ typescript: "^4.9.4",
149
+ vite: "^3.2.5",
150
+ vitest: "~0.25.8",
151
+ web3: "^1.8.1"
152
+ },
153
+ license: "MIT",
154
+ repository: "wagmi-dev/viem",
155
+ authors: [
156
+ "awkweb.eth",
157
+ "jxom.eth"
158
+ ],
159
+ keywords: [
160
+ "eth",
161
+ "ethereum",
162
+ "dapps",
163
+ "wallet",
164
+ "web3"
165
+ ],
166
+ "simple-git-hooks": {
167
+ "pre-commit": "pnpm format && pnpm lint:fix"
168
+ },
169
+ pnpm: {
170
+ patchedDependencies: {
171
+ "vitepress@1.0.0-alpha.34": "patches/vitepress@1.0.0-alpha.34.patch"
172
+ }
173
+ }
174
+ };
11
175
 
12
176
  // src/errors/utils.ts
13
177
  var getContractAddress = (address) => address;
14
178
  var getUrl = (url) => url;
15
- var getVersion = () => `${name}@${version}`;
179
+ var getVersion = () => `${package_default.name}@${package_default.version}`;
16
180
 
17
181
  // src/errors/base.ts
18
182
  var BaseError = class extends Error {
@@ -983,7 +1147,7 @@ function sliceHex(value_, start, end) {
983
1147
  return `0x${value}`;
984
1148
  }
985
1149
 
986
- // src/utils/encoding/encodeHex.ts
1150
+ // src/utils/encoding/toHex.ts
987
1151
  var hexes = Array.from(
988
1152
  { length: 256 },
989
1153
  (v, i) => i.toString(16).padStart(2, "0")
@@ -998,7 +1162,7 @@ function bytesToHex(value) {
998
1162
  }
999
1163
  return `0x${hex}`;
1000
1164
  }
1001
- function encodeHex(value) {
1165
+ function toHex(value) {
1002
1166
  if (typeof value === "number" || typeof value === "bigint")
1003
1167
  return numberToHex(value);
1004
1168
  if (typeof value === "string") {
@@ -1040,14 +1204,14 @@ function stringToHex(value) {
1040
1204
  return `0x${hex}`;
1041
1205
  }
1042
1206
 
1043
- // src/utils/encoding/encodeBytes.ts
1207
+ // src/utils/encoding/toBytes.ts
1044
1208
  var encoder = new TextEncoder();
1045
1209
  function boolToBytes(value) {
1046
1210
  const bytes = new Uint8Array(1);
1047
1211
  bytes[0] = Number(value);
1048
1212
  return bytes;
1049
1213
  }
1050
- function encodeBytes(value) {
1214
+ function toBytes(value) {
1051
1215
  if (typeof value === "number" || typeof value === "bigint")
1052
1216
  return numberToBytes(value);
1053
1217
  if (typeof value === "boolean")
@@ -1079,15 +1243,15 @@ function stringToBytes(value) {
1079
1243
  return encoder.encode(value);
1080
1244
  }
1081
1245
 
1082
- // src/utils/encoding/encodeRlp.ts
1083
- function encodeRlp(hexOrBytes, to_) {
1246
+ // src/utils/encoding/toRlp.ts
1247
+ function toRlp(hexOrBytes, to_) {
1084
1248
  const to = to_ || "hex";
1085
1249
  return format(bytesToRlp(parse(hexOrBytes)), to);
1086
1250
  }
1087
1251
  function parse(hexOrBytes) {
1088
1252
  if (Array.isArray(hexOrBytes))
1089
1253
  return hexOrBytes.map(parse);
1090
- return typeof hexOrBytes === "string" ? encodeBytes(hexOrBytes) : hexOrBytes;
1254
+ return typeof hexOrBytes === "string" ? toBytes(hexOrBytes) : hexOrBytes;
1091
1255
  }
1092
1256
  function format(bytes, type = "bytes") {
1093
1257
  return type === "hex" ? bytesToHex(bytes) : bytes;
@@ -1104,11 +1268,11 @@ function bytesToRlp(bytes) {
1104
1268
  function encodeLength(length, offset) {
1105
1269
  if (length < 56)
1106
1270
  return [offset + length];
1107
- return [encodeBytes(length).length + offset + 55, ...encodeBytes(length)];
1271
+ return [toBytes(length).length + offset + 55, ...toBytes(length)];
1108
1272
  }
1109
1273
 
1110
- // src/utils/encoding/decodeHex.ts
1111
- function decodeHex(hex, to) {
1274
+ // src/utils/encoding/fromHex.ts
1275
+ function fromHex(hex, to) {
1112
1276
  if (to === "number")
1113
1277
  return hexToNumber(hex);
1114
1278
  if (to === "bigint")
@@ -1145,8 +1309,8 @@ function hexToString(hex) {
1145
1309
  return new TextDecoder().decode(bytes);
1146
1310
  }
1147
1311
 
1148
- // src/utils/encoding/decodeBytes.ts
1149
- function decodeBytes(bytes, to) {
1312
+ // src/utils/encoding/fromBytes.ts
1313
+ function fromBytes(bytes, to) {
1150
1314
  if (to === "number")
1151
1315
  return bytesToNumber(bytes);
1152
1316
  if (to === "bigint")
@@ -1174,8 +1338,8 @@ function bytesToString(bytes) {
1174
1338
  return new TextDecoder().decode(bytes);
1175
1339
  }
1176
1340
 
1177
- // src/utils/encoding/decodeRlp.ts
1178
- function decodeRlp(value, to) {
1341
+ // src/utils/encoding/fromRlp.ts
1342
+ function fromRlp(value, to) {
1179
1343
  const bytes = parse2(value);
1180
1344
  const [data, consumed] = rlpToBytes(bytes);
1181
1345
  if (consumed < bytes.length)
@@ -1260,9 +1424,9 @@ var paramsRegex = /((function|event)\s)?(.*)(\((.*)\))/;
1260
1424
  function extractFunctionParts(def) {
1261
1425
  const parts = def.match(paramsRegex);
1262
1426
  const type = parts?.[2] || void 0;
1263
- const name2 = parts?.[3];
1427
+ const name = parts?.[3];
1264
1428
  const params = parts?.[5] || void 0;
1265
- return { type, name: name2, params };
1429
+ return { type, name, params };
1266
1430
  }
1267
1431
  function extractFunctionName(def) {
1268
1432
  return extractFunctionParts(def).name;
@@ -1319,17 +1483,17 @@ function keccak256(value, to_) {
1319
1483
  const bytes = keccak_256(value);
1320
1484
  if (to === "bytes")
1321
1485
  return bytes;
1322
- return encodeHex(bytes);
1486
+ return toHex(bytes);
1323
1487
  }
1324
1488
 
1325
1489
  // src/utils/hash/hashFunction.ts
1326
- var hash = (value) => keccak256(encodeBytes(value));
1490
+ var hash = (value) => keccak256(toBytes(value));
1327
1491
  function hashFunction(def) {
1328
- const name2 = extractFunctionName(def);
1492
+ const name = extractFunctionName(def);
1329
1493
  const params = extractFunctionParams(def);
1330
1494
  if (!params || params.length === 0)
1331
1495
  return hash(def.replace(/ /g, ""));
1332
- return hash(`${name2}(${params.map(({ type }) => type).join(",")})`);
1496
+ return hash(`${name}(${params.map(({ type }) => type).join(",")})`);
1333
1497
  }
1334
1498
 
1335
1499
  // src/utils/hash/getEventSignature.ts
@@ -1367,30 +1531,26 @@ function getContractAddress2(opts) {
1367
1531
  return getCreateAddress(opts);
1368
1532
  }
1369
1533
  function getCreateAddress(opts) {
1370
- const from = encodeBytes(getAddress(opts.from));
1371
- let nonce = encodeBytes(opts.nonce);
1534
+ const from = toBytes(getAddress(opts.from));
1535
+ let nonce = toBytes(opts.nonce);
1372
1536
  if (nonce[0] === 0)
1373
1537
  nonce = new Uint8Array([]);
1374
1538
  return getAddress(
1375
- `0x${keccak256(encodeRlp([from, nonce], "bytes")).slice(26)}`
1539
+ `0x${keccak256(toRlp([from, nonce], "bytes")).slice(26)}`
1376
1540
  );
1377
1541
  }
1378
1542
  function getCreate2Address(opts) {
1379
- const from = encodeBytes(getAddress(opts.from));
1380
- const salt = pad(
1381
- isBytes(opts.salt) ? opts.salt : encodeBytes(opts.salt),
1382
- { size: 32 }
1383
- );
1384
- const bytecodeHash = encodeBytes(
1543
+ const from = toBytes(getAddress(opts.from));
1544
+ const salt = pad(isBytes(opts.salt) ? opts.salt : toBytes(opts.salt), {
1545
+ size: 32
1546
+ });
1547
+ const bytecodeHash = toBytes(
1385
1548
  keccak256(
1386
- isBytes(opts.bytecode) ? opts.bytecode : encodeBytes(opts.bytecode)
1549
+ isBytes(opts.bytecode) ? opts.bytecode : toBytes(opts.bytecode)
1387
1550
  )
1388
1551
  );
1389
1552
  return getAddress(
1390
- slice(
1391
- keccak256(concat([encodeBytes("0xff"), from, salt, bytecodeHash])),
1392
- 12
1393
- )
1553
+ slice(keccak256(concat([toBytes("0xff"), from, salt, bytecodeHash])), 12)
1394
1554
  );
1395
1555
  }
1396
1556
 
@@ -1459,7 +1619,7 @@ function prepareParam({
1459
1619
  return encodeNumber(value, { signed });
1460
1620
  }
1461
1621
  if (param.type.startsWith("bytes")) {
1462
- return encodeBytes2(value, { param });
1622
+ return toBytes2(value, { param });
1463
1623
  }
1464
1624
  if (param.type === "string") {
1465
1625
  return encodeString(value);
@@ -1533,7 +1693,7 @@ function encodeArray(value, {
1533
1693
  encoded: concat(preparedParams.map(({ encoded }) => encoded))
1534
1694
  };
1535
1695
  }
1536
- function encodeBytes2(value, { param }) {
1696
+ function toBytes2(value, { param }) {
1537
1697
  const [_, size_] = param.type.split("bytes");
1538
1698
  if (!size_) {
1539
1699
  const partsLength = Math.floor(size(value) / 32);
@@ -1647,7 +1807,7 @@ function decodeParam({
1647
1807
  return decodeString(data, { position });
1648
1808
  }
1649
1809
  if (param.type.startsWith("bytes")) {
1650
- return decodeBytes2(data, { param, position });
1810
+ return fromBytes2(data, { param, position });
1651
1811
  }
1652
1812
  let value = slice(data, position, position + 32);
1653
1813
  if (param.type.startsWith("uint") || param.type.startsWith("int")) {
@@ -1720,7 +1880,7 @@ function decodeArray(data, {
1720
1880
  function decodeBool(value) {
1721
1881
  return { consumed: 32, value: hexToBool(value) };
1722
1882
  }
1723
- function decodeBytes2(data, { param, position }) {
1883
+ function fromBytes2(data, { param, position }) {
1724
1884
  const [_, size2] = param.type.split("bytes");
1725
1885
  if (!size2) {
1726
1886
  const offset = hexToNumber(slice(data, position, position + 32));
@@ -1748,7 +1908,7 @@ function decodeString(data, { position }) {
1748
1908
  return { consumed: 32, value };
1749
1909
  }
1750
1910
  function decodeTuple(data, { param, position }) {
1751
- const hasUnnamedChild = param.components.length === 0 || param.components.some(({ name: name2 }) => !name2);
1911
+ const hasUnnamedChild = param.components.length === 0 || param.components.some(({ name }) => !name);
1752
1912
  let value = hasUnnamedChild ? [] : {};
1753
1913
  let consumed = 0;
1754
1914
  if (hasDynamicChild(param)) {
@@ -1851,7 +2011,7 @@ function decodeEventLog({
1851
2011
  throw new AbiEventSignatureNotFoundError(signature, {
1852
2012
  docsPath: "/docs/contract/decodeEventLog"
1853
2013
  });
1854
- const { name: name2, inputs } = abiItem;
2014
+ const { name, inputs } = abiItem;
1855
2015
  const isUnnamed = inputs?.some((x) => !("name" in x && x.name));
1856
2016
  let args = isUnnamed ? [] : {};
1857
2017
  for (let i = 0; i < inputs.length; i++) {
@@ -1881,7 +2041,7 @@ function decodeEventLog({
1881
2041
  }
1882
2042
  }
1883
2043
  return {
1884
- eventName: name2,
2044
+ eventName: name,
1885
2045
  args: Object.values(args).length > 0 ? args : void 0
1886
2046
  };
1887
2047
  }
@@ -1909,8 +2069,8 @@ function decodeFunctionData({ abi, data }) {
1909
2069
  }
1910
2070
 
1911
2071
  // src/utils/abi/getAbiItem.ts
1912
- function getAbiItem({ abi, args = [], name: name2 }) {
1913
- const abiItems = abi.filter((x) => "name" in x && x.name === name2);
2072
+ function getAbiItem({ abi, args = [], name }) {
2073
+ const abiItems = abi.filter((x) => "name" in x && x.name === name);
1914
2074
  if (abiItems.length === 0)
1915
2075
  return void 0;
1916
2076
  if (abiItems.length === 1)
@@ -2076,7 +2236,7 @@ function encodeArg({
2076
2236
  value
2077
2237
  }) {
2078
2238
  if (param.type === "string" || param.type === "bytes")
2079
- return keccak256(encodeBytes(value));
2239
+ return keccak256(toBytes(value));
2080
2240
  if (param.type === "tuple" || param.type.match(/^(.*)\[(\d+)?\]$/))
2081
2241
  throw new FilterTypeNotSupportedError(param.type);
2082
2242
  return encodeAbi({ params: [param], values: [value] });
@@ -2470,7 +2630,6 @@ var defineTransactionRequest = defineFormatter({
2470
2630
  });
2471
2631
 
2472
2632
  // src/utils/rpc.ts
2473
- import fetch from "isomorphic-unfetch";
2474
2633
  import WebSocket from "isomorphic-ws";
2475
2634
 
2476
2635
  // src/utils/stringify.ts
@@ -2782,26 +2941,26 @@ export {
2782
2941
  sliceHex,
2783
2942
  boolToHex,
2784
2943
  bytesToHex,
2785
- encodeHex,
2944
+ toHex,
2786
2945
  numberToHex,
2787
2946
  stringToHex,
2788
2947
  boolToBytes,
2789
- encodeBytes,
2948
+ toBytes,
2790
2949
  hexToBytes,
2791
2950
  numberToBytes,
2792
2951
  stringToBytes,
2793
- encodeRlp,
2794
- decodeHex,
2952
+ toRlp,
2953
+ fromHex,
2795
2954
  hexToBigInt,
2796
2955
  hexToBool,
2797
2956
  hexToNumber,
2798
2957
  hexToString,
2799
- decodeBytes,
2958
+ fromBytes,
2800
2959
  bytesToBigint,
2801
2960
  bytesToBool,
2802
2961
  bytesToNumber,
2803
2962
  bytesToString,
2804
- decodeRlp,
2963
+ fromRlp,
2805
2964
  extractFunctionParts,
2806
2965
  extractFunctionName,
2807
2966
  extractFunctionParams,
@@ -2864,4 +3023,4 @@ export {
2864
3023
  parseEther,
2865
3024
  parseGwei
2866
3025
  };
2867
- //# sourceMappingURL=chunk-PRG3BBPZ.mjs.map
3026
+ //# sourceMappingURL=chunk-AKGXRZDN.mjs.map