viem 1.15.5 → 1.16.1

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 (89) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/_cjs/actions/public/getProof.js +16 -0
  3. package/_cjs/actions/public/getProof.js.map +1 -0
  4. package/_cjs/clients/decorators/public.js +2 -0
  5. package/_cjs/clients/decorators/public.js.map +1 -1
  6. package/_cjs/errors/node.js +11 -11
  7. package/_cjs/errors/node.js.map +1 -1
  8. package/_cjs/errors/rpc.js +18 -18
  9. package/_cjs/errors/rpc.js.map +1 -1
  10. package/_cjs/errors/version.js +1 -1
  11. package/_cjs/index.js.map +1 -1
  12. package/_cjs/types/eip1193.js.map +1 -1
  13. package/_cjs/types/proof.js +3 -0
  14. package/_cjs/types/proof.js.map +1 -0
  15. package/_cjs/types/withdrawal.js +3 -0
  16. package/_cjs/types/withdrawal.js.map +1 -0
  17. package/_cjs/utils/formatters/proof.js +22 -0
  18. package/_cjs/utils/formatters/proof.js.map +1 -0
  19. package/_esm/actions/public/getProof.js +37 -0
  20. package/_esm/actions/public/getProof.js.map +1 -0
  21. package/_esm/clients/decorators/public.js +2 -0
  22. package/_esm/clients/decorators/public.js.map +1 -1
  23. package/_esm/errors/node.js +22 -11
  24. package/_esm/errors/node.js.map +1 -1
  25. package/_esm/errors/rpc.js +36 -18
  26. package/_esm/errors/rpc.js.map +1 -1
  27. package/_esm/errors/version.js +1 -1
  28. package/_esm/index.js.map +1 -1
  29. package/_esm/types/eip1193.js.map +1 -1
  30. package/_esm/types/proof.js +2 -0
  31. package/_esm/types/proof.js.map +1 -0
  32. package/_esm/types/withdrawal.js +2 -0
  33. package/_esm/types/withdrawal.js.map +1 -0
  34. package/_esm/utils/formatters/proof.js +18 -0
  35. package/_esm/utils/formatters/proof.js.map +1 -0
  36. package/_types/actions/public/getProof.d.ts +57 -0
  37. package/_types/actions/public/getProof.d.ts.map +1 -0
  38. package/_types/chains/celo/formatters.d.ts +2 -0
  39. package/_types/chains/celo/formatters.d.ts.map +1 -1
  40. package/_types/chains/definitions/base.d.ts +2 -0
  41. package/_types/chains/definitions/base.d.ts.map +1 -1
  42. package/_types/chains/definitions/baseGoerli.d.ts +2 -0
  43. package/_types/chains/definitions/baseGoerli.d.ts.map +1 -1
  44. package/_types/chains/definitions/celo.d.ts +2 -0
  45. package/_types/chains/definitions/celo.d.ts.map +1 -1
  46. package/_types/chains/definitions/celoAlfajores.d.ts +2 -0
  47. package/_types/chains/definitions/celoAlfajores.d.ts.map +1 -1
  48. package/_types/chains/definitions/celoCannoli.d.ts +2 -0
  49. package/_types/chains/definitions/celoCannoli.d.ts.map +1 -1
  50. package/_types/chains/definitions/optimism.d.ts +2 -0
  51. package/_types/chains/definitions/optimism.d.ts.map +1 -1
  52. package/_types/chains/definitions/optimismGoerli.d.ts +2 -0
  53. package/_types/chains/definitions/optimismGoerli.d.ts.map +1 -1
  54. package/_types/chains/definitions/optimismSepolia.d.ts +2 -0
  55. package/_types/chains/definitions/optimismSepolia.d.ts.map +1 -1
  56. package/_types/chains/definitions/zora.d.ts +2 -0
  57. package/_types/chains/definitions/zora.d.ts.map +1 -1
  58. package/_types/chains/definitions/zoraTestnet.d.ts +2 -0
  59. package/_types/chains/definitions/zoraTestnet.d.ts.map +1 -1
  60. package/_types/chains/optimism/formatters.d.ts +2 -0
  61. package/_types/chains/optimism/formatters.d.ts.map +1 -1
  62. package/_types/clients/decorators/public.d.ts +26 -0
  63. package/_types/clients/decorators/public.d.ts.map +1 -1
  64. package/_types/errors/version.d.ts +1 -1
  65. package/_types/index.d.ts +1 -0
  66. package/_types/index.d.ts.map +1 -1
  67. package/_types/types/block.d.ts +5 -0
  68. package/_types/types/block.d.ts.map +1 -1
  69. package/_types/types/eip1193.d.ts +21 -1
  70. package/_types/types/eip1193.d.ts.map +1 -1
  71. package/_types/types/proof.d.ts +18 -0
  72. package/_types/types/proof.d.ts.map +1 -0
  73. package/_types/types/rpc.d.ts +2 -0
  74. package/_types/types/rpc.d.ts.map +1 -1
  75. package/_types/types/withdrawal.d.ts +8 -0
  76. package/_types/types/withdrawal.d.ts.map +1 -0
  77. package/_types/utils/formatters/proof.d.ts +6 -0
  78. package/_types/utils/formatters/proof.d.ts.map +1 -0
  79. package/actions/public/getProof.ts +93 -0
  80. package/clients/decorators/public.ts +31 -0
  81. package/errors/version.ts +1 -1
  82. package/index.ts +1 -0
  83. package/package.json +2 -2
  84. package/types/block.ts +5 -0
  85. package/types/eip1193.ts +21 -0
  86. package/types/proof.ts +20 -0
  87. package/types/rpc.ts +2 -0
  88. package/types/withdrawal.ts +8 -0
  89. package/utils/formatters/proof.ts +24 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withdrawal.d.ts","sourceRoot":"","sources":["../../types/withdrawal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAEpC,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,GAAG,CAAA;IACZ,MAAM,EAAE,GAAG,CAAA;IACX,KAAK,EAAE,GAAG,CAAA;IACV,cAAc,EAAE,GAAG,CAAA;CACpB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import type { ErrorType } from '../../errors/utils.js';
2
+ import type { Proof } from '../../types/proof.js';
3
+ import type { RpcProof } from '../../types/rpc.js';
4
+ export type FormatProofErrorType = ErrorType;
5
+ export declare function formatProof(proof: Partial<RpcProof>): Proof;
6
+ //# sourceMappingURL=proof.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proof.d.ts","sourceRoot":"","sources":["../../../utils/formatters/proof.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAGlD,MAAM,MAAM,oBAAoB,GAAG,SAAS,CAAA;AAS5C,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,SASnD"}
@@ -0,0 +1,93 @@
1
+ import type { Address } from 'abitype'
2
+ import type { Client } from '../../clients/createClient.js'
3
+ import type { Transport } from '../../clients/transports/createTransport.js'
4
+ import type { ErrorType } from '../../errors/utils.js'
5
+ import type { BlockTag } from '../../types/block.js'
6
+ import type { Chain } from '../../types/chain.js'
7
+ import type { Hash } from '../../types/misc.js'
8
+ import type { Proof } from '../../types/proof.js'
9
+ import type { RequestErrorType } from '../../utils/buildRequest.js'
10
+ import {
11
+ type NumberToHexErrorType,
12
+ numberToHex,
13
+ } from '../../utils/encoding/toHex.js'
14
+ import {
15
+ type FormatProofErrorType,
16
+ formatProof,
17
+ } from '../../utils/formatters/proof.js'
18
+
19
+ export type GetProofParameters = {
20
+ /** Account address. */
21
+ address: Address
22
+ /** Array of storage-keys that should be proofed and included. */
23
+ storageKeys: Hash[]
24
+ } & (
25
+ | {
26
+ /** The block number. */
27
+ blockNumber?: bigint
28
+ blockTag?: never
29
+ }
30
+ | {
31
+ blockNumber?: never
32
+ /**
33
+ * The block tag.
34
+ * @default 'latest'
35
+ */
36
+ blockTag?: BlockTag
37
+ }
38
+ )
39
+
40
+ export type GetProofReturnType = Proof
41
+
42
+ export type GetProofErrorType =
43
+ | NumberToHexErrorType
44
+ | FormatProofErrorType
45
+ | RequestErrorType
46
+ | ErrorType
47
+
48
+ /**
49
+ * Returns the account and storage values of the specified account including the Merkle-proof.
50
+ *
51
+ * - Docs: https://viem.sh/docs/actions/public/getProof.html
52
+ * - JSON-RPC Methods:
53
+ * - Calls [`eth_getProof`](https://eips.ethereum.org/EIPS/eip-1186)
54
+ *
55
+ * @param client - Client to use
56
+ * @param parameters - {@link GetProofParameters}
57
+ * @returns Proof data. {@link GetProofReturnType}
58
+ *
59
+ * @example
60
+ * import { createPublicClient, http } from 'viem'
61
+ * import { mainnet } from 'viem/chains'
62
+ * import { getProof } from 'viem/public'
63
+ *
64
+ * const client = createPublicClient({
65
+ * chain: mainnet,
66
+ * transport: http(),
67
+ * })
68
+ * const block = await getProof(client, {
69
+ * address: '0x...',
70
+ * storageKeys: ['0x...'],
71
+ * })
72
+ */
73
+ export async function getProof<TChain extends Chain | undefined>(
74
+ client: Client<Transport, TChain>,
75
+ {
76
+ address,
77
+ blockNumber,
78
+ blockTag: blockTag_,
79
+ storageKeys,
80
+ }: GetProofParameters,
81
+ ): Promise<GetProofReturnType> {
82
+ const blockTag = blockTag_ ?? 'latest'
83
+
84
+ const blockNumberHex =
85
+ blockNumber !== undefined ? numberToHex(blockNumber) : undefined
86
+
87
+ const proof = await client.request({
88
+ method: 'eth_getProof',
89
+ params: [address, storageKeys, blockNumberHex || blockTag],
90
+ })
91
+
92
+ return formatProof(proof)
93
+ }
@@ -126,6 +126,11 @@ import {
126
126
  type GetLogsReturnType,
127
127
  getLogs,
128
128
  } from '../../actions/public/getLogs.js'
129
+ import {
130
+ type GetProofParameters,
131
+ type GetProofReturnType,
132
+ getProof,
133
+ } from '../../actions/public/getProof.js'
129
134
  import {
130
135
  type GetStorageAtParameters,
131
136
  type GetStorageAtReturnType,
@@ -1065,6 +1070,31 @@ export type PublicActions<
1065
1070
  ) => Promise<
1066
1071
  GetLogsReturnType<TAbiEvent, TAbiEvents, TStrict, TFromBlock, TToBlock>
1067
1072
  >
1073
+ /**
1074
+ * Returns the account and storage values of the specified account including the Merkle-proof.
1075
+ *
1076
+ * - Docs: https://viem.sh/docs/actions/public/getProof.html
1077
+ * - JSON-RPC Methods:
1078
+ * - Calls [`eth_getProof`](https://eips.ethereum.org/EIPS/eip-1186)
1079
+ *
1080
+ * @param client - Client to use
1081
+ * @param parameters - {@link GetProofParameters}
1082
+ * @returns Proof data. {@link GetProofReturnType}
1083
+ *
1084
+ * @example
1085
+ * import { createPublicClient, http } from 'viem'
1086
+ * import { mainnet } from 'viem/chains'
1087
+ *
1088
+ * const client = createPublicClient({
1089
+ * chain: mainnet,
1090
+ * transport: http(),
1091
+ * })
1092
+ * const block = await client.getProof({
1093
+ * address: '0x...',
1094
+ * storageKeys: ['0x...'],
1095
+ * })
1096
+ */
1097
+ getProof: (args: GetProofParameters) => Promise<GetProofReturnType>
1068
1098
  /**
1069
1099
  * Returns an estimate for the max priority fee per gas (in wei) for a transaction
1070
1100
  * to be included in the next block.
@@ -1684,6 +1714,7 @@ export function publicActions<
1684
1714
  getFilterLogs: (args) => getFilterLogs(client, args),
1685
1715
  getGasPrice: () => getGasPrice(client),
1686
1716
  getLogs: (args) => getLogs(client, args as any),
1717
+ getProof: (args) => getProof(client, args),
1687
1718
  estimateMaxPriorityFeePerGas: (args) =>
1688
1719
  estimateMaxPriorityFeePerGas(client, args),
1689
1720
  getStorageAt: (args) => getStorageAt(client, args),
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.15.5'
1
+ export const version = '1.16.0'
package/index.ts CHANGED
@@ -948,6 +948,7 @@ export type {
948
948
  RpcTransactionRequest,
949
949
  RpcUncle,
950
950
  } from './types/rpc.js'
951
+ export type { Withdrawal } from './types/withdrawal.js'
951
952
  export { labelhash, type LabelhashErrorType } from './utils/ens/labelhash.js'
952
953
  export { namehash, type NamehashErrorType } from './utils/ens/namehash.js'
953
954
  export {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "1.15.5",
4
+ "version": "1.16.1",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -139,7 +139,7 @@
139
139
  "@scure/bip32": "1.3.2",
140
140
  "@scure/bip39": "1.2.1",
141
141
  "abitype": "0.9.8",
142
- "isows": "1.0.2",
142
+ "isows": "1.0.3",
143
143
  "ws": "8.13.0"
144
144
  },
145
145
  "license": "MIT",
package/types/block.ts CHANGED
@@ -2,6 +2,7 @@ import type { Address } from 'abitype'
2
2
 
3
3
  import type { Hash, Hex } from './misc.js'
4
4
  import type { Transaction } from './transaction.js'
5
+ import type { Withdrawal } from './withdrawal.js'
5
6
 
6
7
  export type Block<
7
8
  TQuantity = bigint,
@@ -56,6 +57,10 @@ export type Block<
56
57
  transactionsRoot: Hash
57
58
  /** List of uncle hashes */
58
59
  uncles: Hash[]
60
+ /** List of withdrawal objects */
61
+ withdrawals?: Withdrawal[]
62
+ /** Root of the this block’s withdrawals trie */
63
+ withdrawalsRoot?: Hex
59
64
  }
60
65
 
61
66
  export type BlockIdentifier<TQuantity = bigint> = {
package/types/eip1193.ts CHANGED
@@ -9,6 +9,7 @@ import type {
9
9
  RpcBlockNumber as BlockNumber,
10
10
  RpcFeeHistory as FeeHistory,
11
11
  RpcLog as Log,
12
+ RpcProof as Proof,
12
13
  RpcTransaction as Transaction,
13
14
  RpcTransactionReceipt as TransactionReceipt,
14
15
  RpcTransactionRequest as TransactionRequest,
@@ -447,6 +448,26 @@ export type PublicRpcSchema = [
447
448
  ]
448
449
  ReturnType: Log[]
449
450
  },
451
+ /**
452
+ * @description Returns the account and storage values of the specified account including the Merkle-proof.
453
+ * @link https://eips.ethereum.org/EIPS/eip-1186
454
+ * @example
455
+ * provider.request({ method: 'eth_getProof', params: ['0x...', ['0x...'], 'latest'] })
456
+ * // => {
457
+ * // ...
458
+ * // }
459
+ */
460
+ {
461
+ Method: 'eth_getProof'
462
+ Parameters: [
463
+ /** Address of the account. */
464
+ address: Address,
465
+ /** An array of storage-keys that should be proofed and included. */
466
+ storageKeys: Hash[],
467
+ block: BlockNumber | BlockTag,
468
+ ]
469
+ ReturnType: Proof
470
+ },
450
471
  /**
451
472
  * @description Returns the value from a storage position at an address
452
473
  * @link https://eips.ethereum.org/EIPS/eip-1474
package/types/proof.ts ADDED
@@ -0,0 +1,20 @@
1
+ import type { Address } from 'abitype'
2
+ import type { Hash } from './misc.js'
3
+
4
+ export type AccountProof = Hash
5
+
6
+ export type StorageProof<TQuantity = bigint> = {
7
+ key: Hash
8
+ proof: Hash[]
9
+ value: TQuantity
10
+ }
11
+
12
+ export type Proof<TQuantity = bigint, TIndex = number> = {
13
+ address: Address
14
+ balance: TQuantity
15
+ codeHash: Hash
16
+ nonce: TIndex
17
+ storageHash: Hash
18
+ accountProof: AccountProof[]
19
+ storageProof: StorageProof<TQuantity>[]
20
+ }
package/types/rpc.ts CHANGED
@@ -7,6 +7,7 @@ import type {
7
7
  } from './block.js'
8
8
  import type { FeeHistory, FeeValues } from './fee.js'
9
9
  import type { Log } from './log.js'
10
+ import type { Proof } from './proof.js'
10
11
  import type {
11
12
  TransactionEIP1559,
12
13
  TransactionEIP2930,
@@ -34,6 +35,7 @@ export type RpcUncle = Uncle<Quantity>
34
35
  export type RpcFeeHistory = FeeHistory<Quantity>
35
36
  export type RpcFeeValues = FeeValues<Quantity>
36
37
  export type RpcLog = Log<Quantity, Index>
38
+ export type RpcProof = Proof<Quantity, Index>
37
39
  export type RpcTransactionReceipt = TransactionReceipt<
38
40
  Quantity,
39
41
  Index,
@@ -0,0 +1,8 @@
1
+ import type { Hex } from './misc.js'
2
+
3
+ export type Withdrawal = {
4
+ address: Hex
5
+ amount: Hex
6
+ index: Hex
7
+ validatorIndex: Hex
8
+ }
@@ -0,0 +1,24 @@
1
+ import type { ErrorType } from '../../errors/utils.js'
2
+ import type { Proof } from '../../types/proof.js'
3
+ import type { RpcProof } from '../../types/rpc.js'
4
+ import { hexToNumber } from '../index.js'
5
+
6
+ export type FormatProofErrorType = ErrorType
7
+
8
+ function formatStorageProof(storageProof: RpcProof['storageProof']) {
9
+ return storageProof.map((proof) => ({
10
+ ...proof,
11
+ value: BigInt(proof.value),
12
+ }))
13
+ }
14
+
15
+ export function formatProof(proof: Partial<RpcProof>) {
16
+ return {
17
+ ...proof,
18
+ balance: proof.balance ? BigInt(proof.balance) : undefined,
19
+ nonce: proof.nonce ? hexToNumber(proof.nonce) : undefined,
20
+ storageProof: proof.storageProof
21
+ ? formatStorageProof(proof.storageProof)
22
+ : undefined,
23
+ } as Proof
24
+ }