viem 2.36.0-jxom-erc8010-20250826223301 → 2.36.1-jxom-erc8010-20250901014739

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 (86) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/_cjs/actions/public/multicall.js.map +1 -1
  3. package/_cjs/actions/public/verifyHash.js +18 -12
  4. package/_cjs/actions/public/verifyHash.js.map +1 -1
  5. package/_cjs/chains/definitions/creditCoin3Mainnet.js +2 -2
  6. package/_cjs/chains/definitions/creditCoin3Mainnet.js.map +1 -1
  7. package/_cjs/chains/definitions/creditCoin3Testnet.js +2 -2
  8. package/_cjs/chains/definitions/creditCoin3Testnet.js.map +1 -1
  9. package/_cjs/chains/definitions/crossfi.js +24 -0
  10. package/_cjs/chains/definitions/crossfi.js.map +1 -0
  11. package/_cjs/chains/definitions/openledger.js +20 -0
  12. package/_cjs/chains/definitions/openledger.js.map +1 -0
  13. package/_cjs/chains/definitions/unichain.js +1 -0
  14. package/_cjs/chains/definitions/unichain.js.map +1 -1
  15. package/_cjs/chains/definitions/unichainSepolia.js +1 -0
  16. package/_cjs/chains/definitions/unichainSepolia.js.map +1 -1
  17. package/_cjs/chains/index.js +15 -11
  18. package/_cjs/chains/index.js.map +1 -1
  19. package/_cjs/errors/version.js +1 -1
  20. package/_cjs/utils/rpc/http.js +2 -2
  21. package/_cjs/utils/rpc/http.js.map +1 -1
  22. package/_cjs/utils/signature/parseErc8010Signature.js +3 -3
  23. package/_cjs/utils/signature/parseErc8010Signature.js.map +1 -1
  24. package/_cjs/utils/signature/serializeErc8010Signature.js +4 -2
  25. package/_cjs/utils/signature/serializeErc8010Signature.js.map +1 -1
  26. package/_esm/actions/public/multicall.js.map +1 -1
  27. package/_esm/actions/public/verifyHash.js +18 -12
  28. package/_esm/actions/public/verifyHash.js.map +1 -1
  29. package/_esm/chains/definitions/creditCoin3Mainnet.js +2 -2
  30. package/_esm/chains/definitions/creditCoin3Mainnet.js.map +1 -1
  31. package/_esm/chains/definitions/creditCoin3Testnet.js +2 -2
  32. package/_esm/chains/definitions/creditCoin3Testnet.js.map +1 -1
  33. package/_esm/chains/definitions/crossfi.js +21 -0
  34. package/_esm/chains/definitions/crossfi.js.map +1 -0
  35. package/_esm/chains/definitions/openledger.js +17 -0
  36. package/_esm/chains/definitions/openledger.js.map +1 -0
  37. package/_esm/chains/definitions/unichain.js +1 -0
  38. package/_esm/chains/definitions/unichain.js.map +1 -1
  39. package/_esm/chains/definitions/unichainSepolia.js +1 -0
  40. package/_esm/chains/definitions/unichainSepolia.js.map +1 -1
  41. package/_esm/chains/index.js +2 -0
  42. package/_esm/chains/index.js.map +1 -1
  43. package/_esm/errors/version.js +1 -1
  44. package/_esm/utils/rpc/http.js +2 -2
  45. package/_esm/utils/rpc/http.js.map +1 -1
  46. package/_esm/utils/signature/parseErc8010Signature.js +3 -3
  47. package/_esm/utils/signature/parseErc8010Signature.js.map +1 -1
  48. package/_esm/utils/signature/serializeErc8010Signature.js +4 -2
  49. package/_esm/utils/signature/serializeErc8010Signature.js.map +1 -1
  50. package/_types/actions/public/multicall.d.ts +3 -6
  51. package/_types/actions/public/multicall.d.ts.map +1 -1
  52. package/_types/actions/public/verifyHash.d.ts +14 -2
  53. package/_types/actions/public/verifyHash.d.ts.map +1 -1
  54. package/_types/chains/definitions/creditCoin3Mainnet.d.ts +2 -2
  55. package/_types/chains/definitions/creditCoin3Testnet.d.ts +3 -3
  56. package/_types/chains/definitions/crossfi.d.ts +39 -0
  57. package/_types/chains/definitions/crossfi.d.ts.map +1 -0
  58. package/_types/chains/definitions/openledger.d.ts +39 -0
  59. package/_types/chains/definitions/openledger.d.ts.map +1 -0
  60. package/_types/chains/definitions/unichain.d.ts +1 -1
  61. package/_types/chains/definitions/unichain.d.ts.map +1 -1
  62. package/_types/chains/definitions/unichainSepolia.d.ts +1 -1
  63. package/_types/chains/definitions/unichainSepolia.d.ts.map +1 -1
  64. package/_types/chains/index.d.ts +2 -0
  65. package/_types/chains/index.d.ts.map +1 -1
  66. package/_types/errors/version.d.ts +1 -1
  67. package/_types/utils/rpc/http.d.ts +4 -0
  68. package/_types/utils/rpc/http.d.ts.map +1 -1
  69. package/_types/utils/signature/parseErc8010Signature.d.ts +3 -0
  70. package/_types/utils/signature/parseErc8010Signature.d.ts.map +1 -1
  71. package/_types/utils/signature/serializeErc8010Signature.d.ts +3 -0
  72. package/_types/utils/signature/serializeErc8010Signature.d.ts.map +1 -1
  73. package/actions/public/multicall.ts +5 -11
  74. package/actions/public/verifyHash.ts +53 -16
  75. package/chains/definitions/creditCoin3Mainnet.ts +2 -2
  76. package/chains/definitions/creditCoin3Testnet.ts +2 -2
  77. package/chains/definitions/crossfi.ts +21 -0
  78. package/chains/definitions/openledger.ts +17 -0
  79. package/chains/definitions/unichain.ts +1 -0
  80. package/chains/definitions/unichainSepolia.ts +1 -0
  81. package/chains/index.ts +2 -0
  82. package/errors/version.ts +1 -1
  83. package/package.json +3 -3
  84. package/utils/rpc/http.ts +8 -1
  85. package/utils/signature/parseErc8010Signature.ts +7 -4
  86. package/utils/signature/serializeErc8010Signature.ts +7 -2
@@ -26,21 +26,39 @@ import {
26
26
  type EncodeDeployDataErrorType,
27
27
  encodeDeployData,
28
28
  } from '../../utils/abi/encodeDeployData.js'
29
- import { getAddress } from '../../utils/address/getAddress.js'
30
- import { isAddressEqual } from '../../utils/address/isAddressEqual.js'
29
+ import {
30
+ type EncodeFunctionDataErrorType,
31
+ encodeFunctionData,
32
+ } from '../../utils/abi/encodeFunctionData.js'
33
+ import {
34
+ type GetAddressErrorType,
35
+ getAddress,
36
+ } from '../../utils/address/getAddress.js'
37
+ import {
38
+ type IsAddressEqualErrorType,
39
+ isAddressEqual,
40
+ } from '../../utils/address/isAddressEqual.js'
41
+ import { type ConcatHexErrorType, concatHex } from '../../utils/data/concat.js'
31
42
  import { type IsHexErrorType, isHex } from '../../utils/data/isHex.js'
43
+ import { hexToBool } from '../../utils/encoding/fromHex.js'
32
44
  import {
45
+ type BytesToHexErrorType,
33
46
  bytesToHex,
47
+ type NumberToHexErrorType,
34
48
  numberToHex,
35
- type ToHexErrorType,
36
49
  } from '../../utils/encoding/toHex.js'
37
50
  import { getAction } from '../../utils/getAction.js'
38
- import { concatHex, encodeFunctionData, hexToBool } from '../../utils/index.js'
39
- import { recoverAddress } from '../../utils/signature/recoverAddress.js'
40
- import { serializeSignature } from '../../utils/signature/serializeSignature.js'
51
+ import {
52
+ type RecoverAddressErrorType,
53
+ recoverAddress,
54
+ } from '../../utils/signature/recoverAddress.js'
55
+ import {
56
+ type SerializeSignatureErrorType,
57
+ serializeSignature,
58
+ } from '../../utils/signature/serializeSignature.js'
41
59
  import { type CallErrorType, type CallParameters, call } from './call.js'
42
- import { getCode } from './getCode.js'
43
- import { readContract } from './readContract.js'
60
+ import { type GetCodeErrorType, getCode } from './getCode.js'
61
+ import { type ReadContractErrorType, readContract } from './readContract.js'
44
62
 
45
63
  export type VerifyHashParameters = Pick<
46
64
  CallParameters,
@@ -52,6 +70,8 @@ export type VerifyHashParameters = Pick<
52
70
  erc6492VerifierAddress?: Address | undefined
53
71
  /** The hash to be verified. */
54
72
  hash: Hex
73
+ /** Multicall3 address for ERC-8010 verification. */
74
+ multicallAddress?: Address | undefined
55
75
  /** The signature that was generated by signing the message with the address's private key. */
56
76
  signature: Hex | ByteArray | Signature
57
77
  /** @deprecated use `erc6492VerifierAddress` instead. */
@@ -61,12 +81,21 @@ export type VerifyHashParameters = Pick<
61
81
  export type VerifyHashReturnType = boolean
62
82
 
63
83
  export type VerifyHashErrorType =
84
+ | BytesToHexErrorType
64
85
  | CallErrorType
65
- | IsHexErrorType
66
- | ToHexErrorType
67
- | InvalidHexBooleanError
86
+ | ConcatHexErrorType
68
87
  | EncodeDeployDataErrorType
88
+ | EncodeFunctionDataErrorType
69
89
  | ErrorType
90
+ | GetAddressErrorType
91
+ | GetCodeErrorType
92
+ | InvalidHexBooleanError
93
+ | IsAddressEqualErrorType
94
+ | IsHexErrorType
95
+ | NumberToHexErrorType
96
+ | ReadContractErrorType
97
+ | RecoverAddressErrorType
98
+ | SerializeSignatureErrorType
70
99
 
71
100
  /**
72
101
  * Verifies a message hash onchain using ERC-6492.
@@ -85,6 +114,8 @@ export async function verifyHash<chain extends Chain | undefined>(
85
114
  erc6492VerifierAddress:
86
115
  verifierAddress = parameters.universalSignatureVerifierAddress ??
87
116
  client.chain?.contracts?.erc6492Verifier?.address,
117
+ multicallAddress = parameters.multicallAddress ??
118
+ client.chain?.contracts?.multicall3?.address,
88
119
  } = parameters
89
120
 
90
121
  const signature = (() => {
@@ -99,6 +130,7 @@ export async function verifyHash<chain extends Chain | undefined>(
99
130
  if (SignatureErc8010.validate(signature))
100
131
  return await verifyErc8010(client, {
101
132
  ...parameters,
133
+ multicallAddress,
102
134
  signature,
103
135
  })
104
136
  return await verifyErc6492(client, {
@@ -132,12 +164,13 @@ export async function verifyErc8010(
132
164
  client: Client,
133
165
  parameters: verifyErc8010.Parameters,
134
166
  ) {
135
- const { address, blockNumber, blockTag, hash } = parameters
167
+ const { address, blockNumber, blockTag, hash, multicallAddress } = parameters
136
168
 
137
169
  const {
138
170
  authorization,
139
171
  data: initData,
140
172
  signature,
173
+ to,
141
174
  } = SignatureErc8010.unwrap(parameters.signature)
142
175
 
143
176
  // Check if already delegated
@@ -163,6 +196,9 @@ export async function verifyErc8010(
163
196
  readContract,
164
197
  'readContract',
165
198
  )({
199
+ ...(multicallAddress
200
+ ? { address: multicallAddress }
201
+ : { code: multicall3Bytecode }),
166
202
  authorizationList: [
167
203
  {
168
204
  address: authorization.address,
@@ -176,21 +212,20 @@ export async function verifyErc8010(
176
212
  abi: multicall3Abi,
177
213
  blockNumber,
178
214
  blockTag: 'pending',
179
- code: multicall3Bytecode,
180
215
  functionName: 'aggregate3',
181
216
  args: [
182
217
  [
183
218
  ...(initData
184
219
  ? [
185
220
  {
186
- allowFailure: false,
187
- target: address,
221
+ allowFailure: true,
222
+ target: to ?? address,
188
223
  callData: initData,
189
224
  },
190
225
  ]
191
226
  : []),
192
227
  {
193
- allowFailure: false,
228
+ allowFailure: true,
194
229
  target: address,
195
230
  callData: encodeFunctionData({
196
231
  abi: erc1271Abi,
@@ -214,6 +249,8 @@ export namespace verifyErc8010 {
214
249
  address: Address
215
250
  /** The hash to be verified. */
216
251
  hash: Hex
252
+ /** Multicall3 address for ERC-8010 verification. */
253
+ multicallAddress?: Address | undefined
217
254
  /** The signature that was generated by signing the message with the address's private key. */
218
255
  signature: Hex
219
256
  }
@@ -2,8 +2,8 @@ import { defineChain } from '../../utils/chain/defineChain.js'
2
2
 
3
3
  export const creditCoin3Mainnet = /*#__PURE__*/ defineChain({
4
4
  id: 102030,
5
- name: 'Creditcoin3 Mainnet',
6
- nativeCurrency: { name: 'Creditcoin3 Mainnet', symbol: 'CTC', decimals: 18 },
5
+ name: 'Creditcoin',
6
+ nativeCurrency: { name: 'Creditcoin', symbol: 'CTC', decimals: 18 },
7
7
  rpcUrls: {
8
8
  default: {
9
9
  http: ['https://mainnet3.creditcoin.network'],
@@ -2,8 +2,8 @@ import { defineChain } from '../../utils/chain/defineChain.js'
2
2
 
3
3
  export const creditCoin3Testnet = /*#__PURE__*/ defineChain({
4
4
  id: 102031,
5
- name: 'Creditcoin3 Testnet',
6
- nativeCurrency: { name: 'Creditcoin3 Testnet', symbol: 'TCTC', decimals: 18 },
5
+ name: 'Creditcoin Testnet',
6
+ nativeCurrency: { name: 'Creditcoin Testnet', symbol: 'tCTC', decimals: 18 },
7
7
  rpcUrls: {
8
8
  default: {
9
9
  http: ['https://rpc.cc3-testnet.creditcoin.network'],
@@ -0,0 +1,21 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const crossfi = /*#__PURE__*/ defineChain({
4
+ id: 4_158,
5
+ name: 'CrossFi Mainnet',
6
+ nativeCurrency: {
7
+ decimals: 18,
8
+ name: 'CrossFi',
9
+ symbol: 'XFI',
10
+ },
11
+ rpcUrls: {
12
+ default: { http: ['https://rpc.mainnet.ms'] },
13
+ },
14
+ blockExplorers: {
15
+ default: {
16
+ name: 'CrossFi Blockchain Explorer',
17
+ url: 'https://xfiscan.com',
18
+ },
19
+ },
20
+ testnet: false,
21
+ })
@@ -0,0 +1,17 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const openledger = /*#__PURE__*/ defineChain({
4
+ id: 1612,
5
+ name: 'OpenLedger',
6
+ nativeCurrency: { name: 'Open', symbol: 'OPEN', decimals: 18 },
7
+ rpcUrls: {
8
+ default: { http: ['https://rpc.openledger.xyz'] },
9
+ },
10
+ blockExplorers: {
11
+ default: {
12
+ name: 'OpenLedger Explorer',
13
+ url: 'https://scan.openledger.xyz',
14
+ },
15
+ },
16
+ testnet: false,
17
+ })
@@ -8,6 +8,7 @@ export const unichain = /*#__PURE__*/ defineChain({
8
8
  id: 130,
9
9
  name: 'Unichain',
10
10
  nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
11
+ blockTime: 1_000,
11
12
  rpcUrls: {
12
13
  default: {
13
14
  http: ['https://mainnet.unichain.org/'],
@@ -12,6 +12,7 @@ export const unichainSepolia = /*#__PURE__*/ defineChain({
12
12
  symbol: 'ETH',
13
13
  decimals: 18,
14
14
  },
15
+ blockTime: 1_000,
15
16
  rpcUrls: {
16
17
  default: {
17
18
  http: ['https://sepolia.unichain.org'],
package/chains/index.ts CHANGED
@@ -119,6 +119,7 @@ export { cronosTestnet } from './definitions/cronosTestnet.js'
119
119
  export { cronoszkEVM } from './definitions/cronoszkEVM.js'
120
120
  export { cronoszkEVMTestnet } from './definitions/cronoszkEVMTestnet.js'
121
121
  export { crossbell } from './definitions/crossbell.js'
122
+ export { crossfi } from './definitions/crossfi.js'
122
123
  export { curtis } from './definitions/curtis.js'
123
124
  export { cyber } from './definitions/cyber.js'
124
125
  export { cyberTestnet } from './definitions/cyberTestnet.js'
@@ -394,6 +395,7 @@ export { oneWorld } from './definitions/oneWorld.js'
394
395
  export { oortMainnetDev } from './definitions/oortmainnetDev.js'
395
396
  export { opBNB } from './definitions/opBNB.js'
396
397
  export { opBNBTestnet } from './definitions/opBNBTestnet.js'
398
+ export { openledger } from './definitions/openledger.js'
397
399
  export { optimism } from './definitions/optimism.js'
398
400
  export { optimismGoerli } from './definitions/optimismGoerli.js'
399
401
  export { optimismSepolia } from './definitions/optimismSepolia.js'
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.36.0-jxom-erc8010-20250826223301'
1
+ export const version = '2.36.1-jxom-erc8010-20250901014739'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.36.0-jxom-erc8010-20250826223301",
4
+ "version": "2.36.1-jxom-erc8010-20250901014739",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -195,13 +195,13 @@
195
195
  }
196
196
  },
197
197
  "dependencies": {
198
- "@noble/curves": "1.9.6",
198
+ "@noble/curves": "1.9.1",
199
199
  "@noble/hashes": "1.8.0",
200
200
  "@scure/bip32": "1.7.0",
201
201
  "@scure/bip39": "1.6.0",
202
202
  "abitype": "1.0.8",
203
203
  "isows": "1.0.7",
204
- "ox": "0.9.1",
204
+ "ox": "0.9.3",
205
205
  "ws": "8.18.3"
206
206
  },
207
207
  "license": "MIT",
package/utils/rpc/http.ts CHANGED
@@ -15,6 +15,10 @@ import { stringify } from '../stringify.js'
15
15
  import { idCache } from './id.js'
16
16
 
17
17
  export type HttpRpcClientOptions = {
18
+ /** Override for the fetch function used to make requests. */
19
+ fetchFn?:
20
+ | ((input: string | URL | Request, init?: RequestInit) => Promise<Response>)
21
+ | undefined
18
22
  /** Request configuration to pass to `fetch`. */
19
23
  fetchOptions?: Omit<RequestInit, 'body'> | undefined
20
24
  /** A callback to handle the request. */
@@ -37,6 +41,8 @@ export type HttpRequestParameters<
37
41
  > = {
38
42
  /** The RPC request body. */
39
43
  body: body
44
+ /** Override for the fetch function used to make requests. */
45
+ fetchFn?: HttpRpcClientOptions['fetchFn'] | undefined
40
46
  /** Request configuration to pass to `fetch`. */
41
47
  fetchOptions?: HttpRpcClientOptions['fetchOptions'] | undefined
42
48
  /** A callback to handle the response. */
@@ -78,6 +84,7 @@ export function getHttpRpcClient(
78
84
  async request(params) {
79
85
  const {
80
86
  body,
87
+ fetchFn = options.fetchFn ?? fetch,
81
88
  onRequest = options.onRequest,
82
89
  onResponse = options.onResponse,
83
90
  timeout = options.timeout ?? 10_000,
@@ -117,7 +124,7 @@ export function getHttpRpcClient(
117
124
  }
118
125
  const request = new Request(url, init)
119
126
  const args = (await onRequest?.(request, init)) ?? { ...init, url }
120
- const response = await fetch(args.url ?? url, args)
127
+ const response = await fetchFn(args.url ?? url, args)
121
128
  return response
122
129
  },
123
130
  {
@@ -1,3 +1,4 @@
1
+ import type { Address } from 'abitype'
1
2
  import * as SignatureErc8010 from 'ox/erc8010/SignatureErc8010'
2
3
  import type { ErrorType } from '../../errors/utils.js'
3
4
  import type { SignedAuthorization } from '../../types/authorization.js'
@@ -14,6 +15,8 @@ export type ParseErc8010SignatureParameters = Hex
14
15
  export type ParseErc8010SignatureReturnType = Prettify<
15
16
  OneOf<
16
17
  | {
18
+ /** Address of the initializer. */
19
+ address?: Address | undefined
17
20
  /** Authorization signed by the delegatee. */
18
21
  authorization: SignedAuthorization
19
22
  /** Data to initialize the delegation. */
@@ -46,8 +49,8 @@ export function parseErc8010Signature(
46
49
 
47
50
  const {
48
51
  authorization: authorization_ox,
49
- data,
50
- signature: inner,
52
+ to,
53
+ ...rest
51
54
  } = SignatureErc8010.unwrap(signature)
52
55
  return {
53
56
  authorization: {
@@ -58,7 +61,7 @@ export function parseErc8010Signature(
58
61
  s: numberToHex(authorization_ox.s, { size: 32 }),
59
62
  yParity: authorization_ox.yParity,
60
63
  },
61
- data,
62
- signature: inner,
64
+ ...(to ? { address: to } : {}),
65
+ ...rest,
63
66
  }
64
67
  }
@@ -1,3 +1,4 @@
1
+ import type { Address } from 'abitype'
1
2
  import * as SignatureErc8010 from 'ox/erc8010/SignatureErc8010'
2
3
  import type { ErrorType } from '../../errors/utils.js'
3
4
  import type { SignedAuthorization } from '../../types/authorization.js'
@@ -7,6 +8,8 @@ import { hexToBytes } from '../encoding/toBytes.js'
7
8
  type To = 'bytes' | 'hex'
8
9
 
9
10
  export type SerializeErc8010SignatureParameters<to extends To = 'hex'> = {
11
+ /** Address of the initializer. */
12
+ address?: Address | undefined
10
13
  /** Authorization signed by the delegatee. */
11
14
  authorization: SignedAuthorization
12
15
  /** Data to initialize the delegation. */
@@ -31,9 +34,8 @@ export type SerializeErc8010SignatureErrorType = ErrorType
31
34
  export function serializeErc8010Signature<to extends To = 'hex'>(
32
35
  parameters: SerializeErc8010SignatureParameters<to>,
33
36
  ): SerializeErc8010SignatureReturnType<to> {
34
- const { to = 'hex' } = parameters
37
+ const { address, data, signature, to = 'hex' } = parameters
35
38
  const signature_ = SignatureErc8010.wrap({
36
- ...parameters,
37
39
  authorization: {
38
40
  address: parameters.authorization.address,
39
41
  chainId: parameters.authorization.chainId,
@@ -42,6 +44,9 @@ export function serializeErc8010Signature<to extends To = 'hex'>(
42
44
  s: BigInt(parameters.authorization.s),
43
45
  yParity: parameters.authorization.yParity!,
44
46
  },
47
+ data,
48
+ signature,
49
+ to: address,
45
50
  })
46
51
  if (to === 'hex') return signature_ as SerializeErc8010SignatureReturnType<to>
47
52
  return hexToBytes(signature_) as SerializeErc8010SignatureReturnType<to>