viem 0.2.0-jxom-async-verify-message.20230321T000803 → 0.2.0-jxom-local-accounts.20230321T212822

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 (69) hide show
  1. package/accounts/package.json +4 -0
  2. package/dist/abi.d.ts +3 -3
  3. package/dist/abi.js +2 -2
  4. package/dist/abi.mjs +1 -1
  5. package/dist/accounts/index.d.ts +33 -0
  6. package/dist/accounts/index.js +89 -0
  7. package/dist/accounts/index.js.map +1 -0
  8. package/dist/accounts/index.mjs +89 -0
  9. package/dist/accounts/index.mjs.map +1 -0
  10. package/dist/{chain-b2e88e30.d.ts → chain-75b0942e.d.ts} +60 -60
  11. package/dist/{chain-c4f924cf.d.ts → chain-f8db473f.d.ts} +1 -1
  12. package/dist/chains.d.ts +3 -3
  13. package/dist/chains.js +63 -63
  14. package/dist/chains.mjs +1 -1
  15. package/dist/{chunk-OZCG5IO7.mjs → chunk-6UKHPIXX.mjs} +2 -2
  16. package/dist/chunk-FNVFGFWN.mjs +31 -0
  17. package/dist/chunk-FNVFGFWN.mjs.map +1 -0
  18. package/dist/chunk-FQM5MF6U.js +31 -0
  19. package/dist/chunk-FQM5MF6U.js.map +1 -0
  20. package/dist/{chunk-FEPL5HFW.mjs → chunk-IVRML3IK.mjs} +75 -66
  21. package/dist/chunk-IVRML3IK.mjs.map +1 -0
  22. package/dist/{chunk-2NJCP2DN.js → chunk-LYQKHD7R.js} +19 -19
  23. package/dist/{chunk-22BDIC7J.js → chunk-NJSAEA2H.js} +75 -66
  24. package/dist/chunk-NJSAEA2H.js.map +1 -0
  25. package/dist/contract.d.ts +9 -8
  26. package/dist/contract.js +2 -2
  27. package/dist/contract.mjs +1 -1
  28. package/dist/{createClient-d4f1dea1.d.ts → createClient-f87255c1.d.ts} +2 -2
  29. package/dist/{createPublicClient-3a714a8d.d.ts → createPublicClient-d2c37c92.d.ts} +12 -5
  30. package/dist/{eip1193-cd3e872a.d.ts → eip1193-ae706fd8.d.ts} +1 -1
  31. package/dist/{encodeFunctionResult-750c9055.d.ts → encodeFunctionResult-4792a6a3.d.ts} +1 -1
  32. package/dist/{encodePacked-de74201f.d.ts → encodePacked-3fcdd54b.d.ts} +1 -1
  33. package/dist/ens.d.ts +6 -5
  34. package/dist/ens.js +3 -3
  35. package/dist/ens.mjs +2 -2
  36. package/dist/ethers.d.ts +5 -4
  37. package/dist/ethers.js +7 -5
  38. package/dist/ethers.js.map +1 -1
  39. package/dist/ethers.mjs +7 -5
  40. package/dist/ethers.mjs.map +1 -1
  41. package/dist/{formatAbiItem-fdbdda39.d.ts → formatAbiItem-765ebc53.d.ts} +1 -1
  42. package/dist/{getAbiItem-9d709e3b.d.ts → getAbiItem-693e6e1b.d.ts} +1 -1
  43. package/dist/index.d.ts +15 -14
  44. package/dist/index.js +91 -91
  45. package/dist/index.js.map +1 -1
  46. package/dist/index.mjs +4 -4
  47. package/dist/index.mjs.map +1 -1
  48. package/dist/parseAccount-2d7ea01d.d.ts +6 -0
  49. package/dist/{parseGwei-b138c041.d.ts → parseGwei-377678bc.d.ts} +10 -11
  50. package/dist/public.d.ts +6 -5
  51. package/dist/public.js +2 -2
  52. package/dist/public.mjs +1 -1
  53. package/dist/{test-c70126a6.d.ts → test-98c0b642.d.ts} +3 -3
  54. package/dist/test.d.ts +5 -5
  55. package/dist/test.js +2 -2
  56. package/dist/test.mjs +1 -1
  57. package/dist/{account-07d04222.d.ts → typedData-ade018d6.d.ts} +46 -27
  58. package/dist/utils/index.d.ts +16 -14
  59. package/dist/utils/index.js +2 -2
  60. package/dist/utils/index.mjs +3 -3
  61. package/dist/wallet.d.ts +6 -5
  62. package/dist/wallet.js +2 -2
  63. package/dist/wallet.mjs +1 -1
  64. package/dist/window.d.ts +2 -2
  65. package/package.json +9 -1
  66. package/dist/chunk-22BDIC7J.js.map +0 -1
  67. package/dist/chunk-FEPL5HFW.mjs.map +0 -1
  68. /package/dist/{chunk-OZCG5IO7.mjs.map → chunk-6UKHPIXX.mjs.map} +0 -0
  69. /package/dist/{chunk-2NJCP2DN.js.map → chunk-LYQKHD7R.js.map} +0 -0
@@ -0,0 +1,31 @@
1
+ import {
2
+ InvalidAddressError,
3
+ isAddress
4
+ } from "./chunk-IVRML3IK.mjs";
5
+
6
+ // src/accounts/toAccount.ts
7
+ function toAccount(source) {
8
+ if (typeof source === "string") {
9
+ if (!isAddress(source))
10
+ throw new InvalidAddressError({ address: source });
11
+ return {
12
+ address: source,
13
+ type: "json-rpc"
14
+ };
15
+ }
16
+ if (!isAddress(source.address))
17
+ throw new InvalidAddressError({ address: source.address });
18
+ return {
19
+ address: source.address,
20
+ signMessage: source.signMessage,
21
+ signTransaction: source.signTransaction,
22
+ signTypedData: source.signTypedData,
23
+ source: "custom",
24
+ type: "local"
25
+ };
26
+ }
27
+
28
+ export {
29
+ toAccount
30
+ };
31
+ //# sourceMappingURL=chunk-FNVFGFWN.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/accounts/toAccount.ts"],"sourcesContent":["import { InvalidAddressError } from '../errors'\nimport type { Address } from '../types'\nimport { isAddress } from '../utils'\nimport type {\n AccountSource,\n CustomSource,\n JsonRpcAccount,\n LocalAccount,\n} from './types'\n\ntype GetAccountReturnType<TAccountSource extends AccountSource> =\n | (TAccountSource extends Address ? JsonRpcAccount : never)\n | (TAccountSource extends CustomSource ? LocalAccount : never)\n\nexport function toAccount<TAccountSource extends AccountSource>(\n source: TAccountSource,\n): GetAccountReturnType<TAccountSource> {\n if (typeof source === 'string') {\n if (!isAddress(source)) throw new InvalidAddressError({ address: source })\n return {\n address: source,\n type: 'json-rpc',\n } as GetAccountReturnType<TAccountSource>\n }\n\n if (!isAddress(source.address))\n throw new InvalidAddressError({ address: source.address })\n return {\n address: source.address,\n signMessage: source.signMessage,\n signTransaction: source.signTransaction,\n signTypedData: source.signTypedData,\n source: 'custom',\n type: 'local',\n } as GetAccountReturnType<TAccountSource>\n}\n"],"mappings":";;;;;;AAcO,SAAS,UACd,QACsC;AACtC,MAAI,OAAO,WAAW,UAAU;AAC9B,QAAI,CAAC,UAAU,MAAM;AAAG,YAAM,IAAI,oBAAoB,EAAE,SAAS,OAAO,CAAC;AACzE,WAAO;AAAA,MACL,SAAS;AAAA,MACT,MAAM;AAAA,IACR;AAAA,EACF;AAEA,MAAI,CAAC,UAAU,OAAO,OAAO;AAC3B,UAAM,IAAI,oBAAoB,EAAE,SAAS,OAAO,QAAQ,CAAC;AAC3D,SAAO;AAAA,IACL,SAAS,OAAO;AAAA,IAChB,aAAa,OAAO;AAAA,IACpB,iBAAiB,OAAO;AAAA,IACxB,eAAe,OAAO;AAAA,IACtB,QAAQ;AAAA,IACR,MAAM;AAAA,EACR;AACF;","names":[]}
@@ -0,0 +1,31 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkNJSAEA2Hjs = require('./chunk-NJSAEA2H.js');
5
+
6
+ // src/accounts/toAccount.ts
7
+ function toAccount(source) {
8
+ if (typeof source === "string") {
9
+ if (!_chunkNJSAEA2Hjs.isAddress.call(void 0, source))
10
+ throw new (0, _chunkNJSAEA2Hjs.InvalidAddressError)({ address: source });
11
+ return {
12
+ address: source,
13
+ type: "json-rpc"
14
+ };
15
+ }
16
+ if (!_chunkNJSAEA2Hjs.isAddress.call(void 0, source.address))
17
+ throw new (0, _chunkNJSAEA2Hjs.InvalidAddressError)({ address: source.address });
18
+ return {
19
+ address: source.address,
20
+ signMessage: source.signMessage,
21
+ signTransaction: source.signTransaction,
22
+ signTypedData: source.signTypedData,
23
+ source: "custom",
24
+ type: "local"
25
+ };
26
+ }
27
+
28
+
29
+
30
+ exports.toAccount = toAccount;
31
+ //# sourceMappingURL=chunk-FQM5MF6U.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/accounts/toAccount.ts"],"names":[],"mappings":";;;;;;AAcO,SAAS,UACd,QACsC;AACtC,MAAI,OAAO,WAAW,UAAU;AAC9B,QAAI,CAAC,UAAU,MAAM;AAAG,YAAM,IAAI,oBAAoB,EAAE,SAAS,OAAO,CAAC;AACzE,WAAO;AAAA,MACL,SAAS;AAAA,MACT,MAAM;AAAA,IACR;AAAA,EACF;AAEA,MAAI,CAAC,UAAU,OAAO,OAAO;AAC3B,UAAM,IAAI,oBAAoB,EAAE,SAAS,OAAO,QAAQ,CAAC;AAC3D,SAAO;AAAA,IACL,SAAS,OAAO;AAAA,IAChB,aAAa,OAAO;AAAA,IACpB,iBAAiB,OAAO;AAAA,IACxB,eAAe,OAAO;AAAA,IACtB,QAAQ;AAAA,IACR,MAAM;AAAA,EACR;AACF","sourcesContent":["import { InvalidAddressError } from '../errors'\nimport type { Address } from '../types'\nimport { isAddress } from '../utils'\nimport type {\n AccountSource,\n CustomSource,\n JsonRpcAccount,\n LocalAccount,\n} from './types'\n\ntype GetAccountReturnType<TAccountSource extends AccountSource> =\n | (TAccountSource extends Address ? JsonRpcAccount : never)\n | (TAccountSource extends CustomSource ? LocalAccount : never)\n\nexport function toAccount<TAccountSource extends AccountSource>(\n source: TAccountSource,\n): GetAccountReturnType<TAccountSource> {\n if (typeof source === 'string') {\n if (!isAddress(source)) throw new InvalidAddressError({ address: source })\n return {\n address: source,\n type: 'json-rpc',\n } as GetAccountReturnType<TAccountSource>\n }\n\n if (!isAddress(source.address))\n throw new InvalidAddressError({ address: source.address })\n return {\n address: source.address,\n signMessage: source.signMessage,\n signTransaction: source.signTransaction,\n signTypedData: source.signTypedData,\n source: 'custom',\n type: 'local',\n } as GetAccountReturnType<TAccountSource>\n}\n"]}
@@ -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 && size-limit",
29
29
  changeset: "changeset",
30
30
  "changeset:release": "pnpm build && changeset publish",
31
31
  "changeset:version": "changeset version && pnpm install --lockfile-only",
@@ -53,6 +53,7 @@ var package_default = {
53
53
  entry: [
54
54
  "src/index.ts",
55
55
  "src/abi.ts",
56
+ "src/accounts/index.ts",
56
57
  "src/chains.ts",
57
58
  "src/contract.ts",
58
59
  "src/ens.ts",
@@ -66,6 +67,7 @@ var package_default = {
66
67
  },
67
68
  files: [
68
69
  "/abi",
70
+ "/accounts",
69
71
  "/dist",
70
72
  "/chains",
71
73
  "/contract",
@@ -88,6 +90,11 @@ var package_default = {
88
90
  module: "./dist/abi.mts",
89
91
  default: "./dist/abi.js"
90
92
  },
93
+ "./accounts": {
94
+ types: "./dist/accounts/index.d.ts",
95
+ module: "./dist/accounts/index.mts",
96
+ default: "./dist/accounts/index.js"
97
+ },
91
98
  "./chains": {
92
99
  types: "./dist/chains.d.ts",
93
100
  module: "./dist/chains.mts",
@@ -142,6 +149,8 @@ var package_default = {
142
149
  dependencies: {
143
150
  "@noble/hashes": "^1.1.2",
144
151
  "@noble/secp256k1": "^1.7.1",
152
+ "@scure/bip32": "^1.2.0",
153
+ "@scure/bip39": "^1.1.1",
145
154
  "@wagmi/chains": "~0.2.11",
146
155
  abitype: "~0.7.1",
147
156
  "idna-uts46-hx": "^4.1.2",
@@ -154,6 +163,7 @@ var package_default = {
154
163
  "@adraffy/ens-normalize": "^1.8.9",
155
164
  "@changesets/changelog-github": "^0.4.5",
156
165
  "@changesets/cli": "^2.23.2",
166
+ "@size-limit/preset-big-lib": "^8.2.4",
157
167
  "@types/dedent": "^0.7.0",
158
168
  "@types/fs-extra": "^9.0.13",
159
169
  "@types/node": "^17.0.45",
@@ -171,6 +181,7 @@ var package_default = {
171
181
  rimraf: "^4.1.2",
172
182
  rome: "^11.0.0",
173
183
  "simple-git-hooks": "^2.8.1",
184
+ "size-limit": "^8.2.4",
174
185
  tsup: "^6.6.0",
175
186
  typescript: "^4.9.4",
176
187
  vite: "^4.1.4",
@@ -189,6 +200,11 @@ var package_default = {
189
200
  "wallet",
190
201
  "web3"
191
202
  ],
203
+ "size-limit": [
204
+ {
205
+ path: "dist/index.js"
206
+ }
207
+ ],
192
208
  "simple-git-hooks": {
193
209
  "pre-commit": "pnpm format && pnpm lint:fix"
194
210
  },
@@ -2859,26 +2875,7 @@ function formatAbiItemWithArgs({
2859
2875
  ).join(", ")})`;
2860
2876
  }
2861
2877
 
2862
- // src/utils/account.ts
2863
- function getAccount(source) {
2864
- if (typeof source === "string") {
2865
- if (!isAddress(source))
2866
- throw new InvalidAddressError({ address: source });
2867
- return {
2868
- address: source,
2869
- type: "json-rpc"
2870
- };
2871
- }
2872
- if (!isAddress(source.address))
2873
- throw new InvalidAddressError({ address: source.address });
2874
- return {
2875
- address: source.address,
2876
- signMessage: source.signMessage,
2877
- signTransaction: source.signTransaction,
2878
- signTypedData: source.signTypedData,
2879
- type: "local"
2880
- };
2881
- }
2878
+ // src/accounts/utils/parseAccount.ts
2882
2879
  function parseAccount(account) {
2883
2880
  if (typeof account === "string")
2884
2881
  return { address: account, type: "json-rpc" };
@@ -3549,13 +3546,59 @@ ${messageBytes.length}`
3549
3546
  return keccak256(concat([prefixBytes, messageBytes]), to_);
3550
3547
  }
3551
3548
 
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
+
3552
3594
  // src/utils/signature/hashTypedData.ts
3553
3595
  function hashTypedData({
3554
- domain,
3596
+ domain: domain_,
3555
3597
  message,
3556
3598
  primaryType,
3557
3599
  types: types_
3558
3600
  }) {
3601
+ const domain = typeof domain_ === "undefined" ? {} : domain_;
3559
3602
  const types = {
3560
3603
  EIP712Domain: [
3561
3604
  domain?.name && { name: "name", type: "string" },
@@ -3569,6 +3612,12 @@ function hashTypedData({
3569
3612
  ].filter(Boolean),
3570
3613
  ...types_
3571
3614
  };
3615
+ validateTypedData({
3616
+ domain,
3617
+ message,
3618
+ primaryType,
3619
+ types
3620
+ });
3572
3621
  let parts = ["0x1901"];
3573
3622
  if (domain)
3574
3623
  parts.push(
@@ -5377,7 +5426,7 @@ async function signMessage(client, {
5377
5426
  const account = parseAccount(account_);
5378
5427
  const message_ = message || data;
5379
5428
  if (account.type === "local")
5380
- return account.signMessage(message_);
5429
+ return account.signMessage({ message: message_ });
5381
5430
  return client.request({
5382
5431
  method: "personal_sign",
5383
5432
  params: [toHex(message_), account.address]
@@ -5432,47 +5481,6 @@ async function signTypedData(client, {
5432
5481
  params: [account.address, typedData]
5433
5482
  });
5434
5483
  }
5435
- function validateTypedData({
5436
- domain,
5437
- message,
5438
- primaryType,
5439
- types: types_
5440
- }) {
5441
- const types = types_;
5442
- const validateData = (struct, value_) => {
5443
- for (const param of struct) {
5444
- const { name, type: type_ } = param;
5445
- const type2 = type_;
5446
- const value = value_[name];
5447
- const integerMatch = type2.match(integerRegex);
5448
- if (integerMatch && (typeof value === "number" || typeof value === "bigint")) {
5449
- const [_type, base, size_] = integerMatch;
5450
- numberToHex(value, {
5451
- signed: base === "int",
5452
- size: parseInt(size_) / 8
5453
- });
5454
- }
5455
- if (type2 === "address" && typeof value === "string" && !isAddress(value))
5456
- throw new InvalidAddressError({ address: value });
5457
- const bytesMatch = type2.match(bytesRegex);
5458
- if (bytesMatch) {
5459
- const [_type, size_] = bytesMatch;
5460
- if (size_ && size(value) !== parseInt(size_))
5461
- throw new BytesSizeMismatchError({
5462
- expectedSize: parseInt(size_),
5463
- givenSize: size(value)
5464
- });
5465
- }
5466
- const struct2 = types[type2];
5467
- if (struct2)
5468
- validateData(struct2, value);
5469
- }
5470
- };
5471
- if (types["EIP712Domain"] && domain)
5472
- validateData(types["EIP712Domain"], domain);
5473
- const type = types[primaryType];
5474
- validateData(type, message);
5475
- }
5476
5484
 
5477
5485
  // src/actions/wallet/switchChain.ts
5478
5486
  async function switchChain(client, { id: id2 }) {
@@ -5748,6 +5756,7 @@ export {
5748
5756
  getEventSelector,
5749
5757
  getFunctionSelector,
5750
5758
  isAddress,
5759
+ checksumAddress,
5751
5760
  getAddress,
5752
5761
  getContractAddress2 as getContractAddress,
5753
5762
  getCreateAddress,
@@ -5775,7 +5784,6 @@ export {
5775
5784
  parseAbiItem,
5776
5785
  parseAbiParameter,
5777
5786
  parseAbiParameters,
5778
- getAccount,
5779
5787
  parseAccount,
5780
5788
  isDeterministicError,
5781
5789
  buildRequest,
@@ -5802,6 +5810,7 @@ export {
5802
5810
  getSocket,
5803
5811
  rpc,
5804
5812
  hashMessage,
5813
+ validateTypedData,
5805
5814
  hashTypedData,
5806
5815
  recoverAddress,
5807
5816
  recoverMessageAddress,
@@ -5891,4 +5900,4 @@ export {
5891
5900
  formatGwei,
5892
5901
  parseEther
5893
5902
  };
5894
- //# sourceMappingURL=chunk-FEPL5HFW.mjs.map
5903
+ //# sourceMappingURL=chunk-IVRML3IK.mjs.map