viem 0.1.10 → 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.
Files changed (52) hide show
  1. package/dist/abi.d.ts +3 -3
  2. package/dist/abi.js +2 -2
  3. package/dist/abi.mjs +1 -1
  4. package/dist/{chain-f8edc5d7.d.ts → chain-41dcec4b.d.ts} +1 -1
  5. package/dist/{chain-94f99620.d.ts → chain-792d51c3.d.ts} +107 -107
  6. package/dist/chains.d.ts +3 -3
  7. package/dist/chains.js +63 -63
  8. package/dist/chains.mjs +1 -1
  9. package/dist/{chunk-5FH7E6C5.js → chunk-ADJTWF45.js} +19 -19
  10. package/dist/{chunk-UI4RZ2SR.mjs → chunk-H6AQHA74.mjs} +109 -5
  11. package/dist/chunk-H6AQHA74.mjs.map +1 -0
  12. package/dist/{chunk-6YZF7223.mjs → chunk-IAY6WXS3.mjs} +2 -2
  13. package/dist/{chunk-L5P7BYGT.js → chunk-YZCQ7AL7.js} +110 -6
  14. package/dist/chunk-YZCQ7AL7.js.map +1 -0
  15. package/dist/contract.d.ts +7 -7
  16. package/dist/contract.js +2 -2
  17. package/dist/contract.mjs +1 -1
  18. package/dist/{createClient-ff222f1b.d.ts → createClient-6cd6daa3.d.ts} +2 -2
  19. package/dist/{createPublicClient-110e0ff7.d.ts → createPublicClient-34d3ba9d.d.ts} +117 -72
  20. package/dist/{eip1193-e31a0368.d.ts → eip1193-2f116cf7.d.ts} +4 -4
  21. package/dist/{encodeFunctionResult-5455530b.d.ts → encodeFunctionResult-874fe003.d.ts} +1 -1
  22. package/dist/{encodePacked-de79982f.d.ts → encodePacked-9ab98aa9.d.ts} +1 -1
  23. package/dist/ens.d.ts +4 -4
  24. package/dist/ens.js +3 -3
  25. package/dist/ens.mjs +2 -2
  26. package/dist/{formatAbiItem-62cbb896.d.ts → formatAbiItem-1bdb43d3.d.ts} +1 -1
  27. package/dist/{getAbiItem-46aa68bf.d.ts → getAbiItem-f19d50a2.d.ts} +1 -1
  28. package/dist/index.d.ts +13 -13
  29. package/dist/index.js +91 -89
  30. package/dist/index.js.map +1 -1
  31. package/dist/index.mjs +4 -2
  32. package/dist/index.mjs.map +1 -1
  33. package/dist/{parseGwei-d221a29d.d.ts → parseGwei-faf061db.d.ts} +3 -3
  34. package/dist/public.d.ts +4 -4
  35. package/dist/public.js +2 -2
  36. package/dist/public.mjs +1 -1
  37. package/dist/{test-796738d1.d.ts → test-6b2b1b0d.d.ts} +3 -3
  38. package/dist/test.d.ts +5 -5
  39. package/dist/test.js +2 -2
  40. package/dist/test.mjs +1 -1
  41. package/dist/utils/index.d.ts +13 -13
  42. package/dist/utils/index.js +2 -2
  43. package/dist/utils/index.mjs +1 -1
  44. package/dist/wallet.d.ts +4 -4
  45. package/dist/wallet.js +4 -2
  46. package/dist/wallet.mjs +3 -1
  47. package/dist/window.d.ts +2 -2
  48. package/package.json +1 -1
  49. package/dist/chunk-L5P7BYGT.js.map +0 -1
  50. package/dist/chunk-UI4RZ2SR.mjs.map +0 -1
  51. /package/dist/{chunk-5FH7E6C5.js.map → chunk-ADJTWF45.js.map} +0 -0
  52. /package/dist/{chunk-6YZF7223.mjs.map → chunk-IAY6WXS3.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.10",
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",
@@ -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 Error(
1593
- `Number "${value_}${suffix}" is not in safe ${size2 ? `${size2 * 8}-bit ${signed ? "signed" : "unsigned"} ` : ""}integer range ${maxValue ? `(${minValue}${suffix} to ${maxValue}${suffix})` : `(above ${minValue})`}`
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-UI4RZ2SR.mjs.map
5488
+ //# sourceMappingURL=chunk-H6AQHA74.mjs.map