viem 2.44.0 → 2.44.2

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 (73) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/_cjs/chains/definitions/adi.js +26 -0
  3. package/_cjs/chains/definitions/adi.js.map +1 -0
  4. package/_cjs/chains/definitions/tempo.js +28 -0
  5. package/_cjs/chains/definitions/tempo.js.map +1 -0
  6. package/_cjs/chains/definitions/zkXPLA.js +28 -0
  7. package/_cjs/chains/definitions/zkXPLA.js.map +1 -0
  8. package/_cjs/chains/definitions/zkXPLATestnet.js +28 -0
  9. package/_cjs/chains/definitions/zkXPLATestnet.js.map +1 -0
  10. package/_cjs/chains/index.js +22 -14
  11. package/_cjs/chains/index.js.map +1 -1
  12. package/_cjs/errors/version.js +1 -1
  13. package/_cjs/tempo/chainConfig.js +7 -1
  14. package/_cjs/tempo/chainConfig.js.map +1 -1
  15. package/_cjs/utils/encoding/fromHex.js +11 -1
  16. package/_cjs/utils/encoding/fromHex.js.map +1 -1
  17. package/_cjs/utils/rpc/http.js +25 -1
  18. package/_cjs/utils/rpc/http.js.map +1 -1
  19. package/_esm/chains/definitions/adi.js +23 -0
  20. package/_esm/chains/definitions/adi.js.map +1 -0
  21. package/_esm/chains/definitions/tempo.js +25 -0
  22. package/_esm/chains/definitions/tempo.js.map +1 -0
  23. package/_esm/chains/definitions/zkXPLA.js +25 -0
  24. package/_esm/chains/definitions/zkXPLA.js.map +1 -0
  25. package/_esm/chains/definitions/zkXPLATestnet.js +25 -0
  26. package/_esm/chains/definitions/zkXPLATestnet.js.map +1 -0
  27. package/_esm/chains/index.js +4 -0
  28. package/_esm/chains/index.js.map +1 -1
  29. package/_esm/errors/version.js +1 -1
  30. package/_esm/tempo/chainConfig.js +8 -1
  31. package/_esm/tempo/chainConfig.js.map +1 -1
  32. package/_esm/utils/encoding/fromHex.js +12 -2
  33. package/_esm/utils/encoding/fromHex.js.map +1 -1
  34. package/_esm/utils/rpc/http.js +26 -1
  35. package/_esm/utils/rpc/http.js.map +1 -1
  36. package/_types/chains/definitions/adi.d.ts +48 -0
  37. package/_types/chains/definitions/adi.d.ts.map +1 -0
  38. package/_types/chains/definitions/tempo.d.ts +916 -0
  39. package/_types/chains/definitions/tempo.d.ts.map +1 -0
  40. package/_types/chains/definitions/tempoAndantino.d.ts +6 -2
  41. package/_types/chains/definitions/tempoAndantino.d.ts.map +1 -1
  42. package/_types/chains/definitions/tempoDevnet.d.ts +6 -2
  43. package/_types/chains/definitions/tempoDevnet.d.ts.map +1 -1
  44. package/_types/chains/definitions/tempoLocalnet.d.ts +6 -2
  45. package/_types/chains/definitions/tempoLocalnet.d.ts.map +1 -1
  46. package/_types/chains/definitions/tempoModerato.d.ts +6 -2
  47. package/_types/chains/definitions/tempoModerato.d.ts.map +1 -1
  48. package/_types/chains/definitions/zkXPLA.d.ts +50 -0
  49. package/_types/chains/definitions/zkXPLA.d.ts.map +1 -0
  50. package/_types/chains/definitions/zkXPLATestnet.d.ts +50 -0
  51. package/_types/chains/definitions/zkXPLATestnet.d.ts.map +1 -0
  52. package/_types/chains/index.d.ts +4 -0
  53. package/_types/chains/index.d.ts.map +1 -1
  54. package/_types/errors/version.d.ts +1 -1
  55. package/_types/tempo/chainConfig.d.ts +3 -1
  56. package/_types/tempo/chainConfig.d.ts.map +1 -1
  57. package/_types/tempo/internal/types.d.ts +1 -1
  58. package/_types/tempo/internal/types.d.ts.map +1 -1
  59. package/_types/utils/encoding/fromHex.d.ts +2 -2
  60. package/_types/utils/encoding/fromHex.d.ts.map +1 -1
  61. package/_types/utils/rpc/http.d.ts +8 -1
  62. package/_types/utils/rpc/http.d.ts.map +1 -1
  63. package/chains/definitions/adi.ts +23 -0
  64. package/chains/definitions/tempo.ts +25 -0
  65. package/chains/definitions/zkXPLA.ts +25 -0
  66. package/chains/definitions/zkXPLATestnet.ts +25 -0
  67. package/chains/index.ts +4 -0
  68. package/errors/version.ts +1 -1
  69. package/package.json +1 -1
  70. package/tempo/chainConfig.ts +11 -1
  71. package/tempo/internal/types.ts +6 -1
  72. package/utils/encoding/fromHex.ts +17 -2
  73. package/utils/rpc/http.ts +31 -1
@@ -0,0 +1,25 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const zkXPLATestnet = /*#__PURE__*/ defineChain({
4
+ id: 475,
5
+ name: 'zkXPLA Testnet',
6
+ network: 'zkxpla-testnet',
7
+ nativeCurrency: {
8
+ decimals: 18,
9
+ name: 'Ether',
10
+ symbol: 'ETH',
11
+ },
12
+ rpcUrls: {
13
+ default: {
14
+ http: ['https://testnet-rpc.zkxpla.io'],
15
+ },
16
+ },
17
+ blockExplorers: {
18
+ default: {
19
+ name: 'zkXPLA Testnet Explorer',
20
+ url: 'https://testnet-explorer.zkxpla.io',
21
+ apiUrl: 'https://testnet-explorer.zkxpla.io/api',
22
+ },
23
+ },
24
+ testnet: true,
25
+ })
package/chains/index.ts CHANGED
@@ -15,6 +15,7 @@ export { abstractTestnet } from './definitions/abstractTestnet.js'
15
15
  export { acala } from './definitions/acala.js'
16
16
  export { acria } from './definitions/acria.js'
17
17
  export { adf } from './definitions/adf.js'
18
+ export { adi } from './definitions/adi.js'
18
19
  export { agungTestnet } from './definitions/agungTestnet.js'
19
20
  export { aioz } from './definitions/aioz.js'
20
21
  export { alephZero } from './definitions/alephZero.js'
@@ -618,6 +619,7 @@ export { teaSepolia } from './definitions/teaSepolia.js'
618
619
  export { telcoinTestnet } from './definitions/telcoinTestnet.js'
619
620
  export { telos } from './definitions/telos.js'
620
621
  export { telosTestnet } from './definitions/telosTestnet.js'
622
+ export { tempo } from './definitions/tempo.js'
621
623
  export {
622
624
  /** @deprecated Use `tempoModerato` instead. */
623
625
  tempoAndantino,
@@ -735,6 +737,8 @@ export {
735
737
  zksyncSepoliaTestnet as zkSyncSepoliaTestnet,
736
738
  zksyncSepoliaTestnet,
737
739
  } from './definitions/zksyncSepoliaTestnet.js'
740
+ export { zkXPLA } from './definitions/zkXPLA.js'
741
+ export { zkXPLATestnet } from './definitions/zkXPLATestnet.js'
738
742
  export { zora } from './definitions/zora.js'
739
743
  export { zoraSepolia } from './definitions/zoraSepolia.js'
740
744
  export { zoraTestnet } from './definitions/zoraTestnet.js'
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.44.0'
1
+ export const version = '2.44.2'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.44.0",
4
+ "version": "2.44.2",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -31,7 +31,7 @@ export const chainConfig = {
31
31
  }),
32
32
  },
33
33
  prepareTransactionRequest: [
34
- async (r) => {
34
+ async (r, { phase }) => {
35
35
  const request = r as Transaction.TransactionRequest & {
36
36
  account?: Account | undefined
37
37
  chain?:
@@ -39,6 +39,16 @@ export const chainConfig = {
39
39
  | undefined
40
40
  }
41
41
 
42
+ // FIXME: node does not account for fee payer + key authorization combinartion; bump gas for now.
43
+ if (phase === 'afterFillParameters') {
44
+ if (
45
+ request.feePayer &&
46
+ request.keyAuthorization?.signature.type === 'webAuthn'
47
+ )
48
+ request.gas = (request.gas ?? 0n) + 20_000n
49
+ return request as unknown as typeof r
50
+ }
51
+
42
52
  request.nonceKey = (() => {
43
53
  if (
44
54
  typeof request.nonceKey !== 'undefined' &&
@@ -51,5 +51,10 @@ export type WriteParameters<
51
51
  > &
52
52
  UnionPick<
53
53
  TransactionRequestTempo,
54
- 'feeToken' | 'feePayer' | 'nonceKey' | 'validAfter' | 'validBefore'
54
+ | 'keyAuthorization'
55
+ | 'feeToken'
56
+ | 'feePayer'
57
+ | 'nonceKey'
58
+ | 'validAfter'
59
+ | 'validBefore'
55
60
  >
@@ -1,4 +1,6 @@
1
1
  import {
2
+ IntegerOutOfRangeError,
3
+ type IntegerOutOfRangeErrorType,
2
4
  InvalidHexBooleanError,
3
5
  type InvalidHexBooleanErrorType,
4
6
  SizeOverflowError,
@@ -185,7 +187,10 @@ export function hexToBool(hex_: Hex, opts: HexToBoolOpts = {}): boolean {
185
187
 
186
188
  export type HexToNumberOpts = HexToBigIntOpts
187
189
 
188
- export type HexToNumberErrorType = HexToBigIntErrorType | ErrorType
190
+ export type HexToNumberErrorType =
191
+ | HexToBigIntErrorType
192
+ | IntegerOutOfRangeErrorType
193
+ | ErrorType
189
194
 
190
195
  /**
191
196
  * Decodes a hex string into a number.
@@ -207,7 +212,17 @@ export type HexToNumberErrorType = HexToBigIntErrorType | ErrorType
207
212
  * // 420
208
213
  */
209
214
  export function hexToNumber(hex: Hex, opts: HexToNumberOpts = {}): number {
210
- return Number(hexToBigInt(hex, opts))
215
+ const value = hexToBigInt(hex, opts)
216
+ const number = Number(value)
217
+ if (!Number.isSafeInteger(number))
218
+ throw new IntegerOutOfRangeError({
219
+ max: `${Number.MAX_SAFE_INTEGER}`,
220
+ min: `${Number.MIN_SAFE_INTEGER}`,
221
+ signed: opts.signed,
222
+ size: opts.size,
223
+ value: `${value}n`,
224
+ })
225
+ return number
211
226
  }
212
227
 
213
228
  export type HexToStringOpts = {
package/utils/rpc/http.ts CHANGED
@@ -77,9 +77,11 @@ export type HttpRpcClient = {
77
77
  }
78
78
 
79
79
  export function getHttpRpcClient(
80
- url: string,
80
+ url_: string,
81
81
  options: HttpRpcClientOptions = {},
82
82
  ): HttpRpcClient {
83
+ const { url, headers: headers_url } = parseUrl(url_)
84
+
83
85
  return {
84
86
  async request(params) {
85
87
  const {
@@ -116,6 +118,7 @@ export function getHttpRpcClient(
116
118
  ...body,
117
119
  }),
118
120
  headers: {
121
+ ...headers_url,
119
122
  'Content-Type': 'application/json',
120
123
  ...headers,
121
124
  },
@@ -174,3 +177,30 @@ export function getHttpRpcClient(
174
177
  },
175
178
  }
176
179
  }
180
+
181
+ /** @internal */
182
+ export function parseUrl(url_: string) {
183
+ try {
184
+ const url = new URL(url_)
185
+
186
+ const result = (() => {
187
+ // Handle Basic authentication credentials
188
+ if (url.username) {
189
+ const credentials = `${decodeURIComponent(url.username)}:${decodeURIComponent(url.password)}`
190
+ url.username = ''
191
+ url.password = ''
192
+
193
+ return {
194
+ url: url.toString(),
195
+ headers: { Authorization: `Basic ${btoa(credentials)}` },
196
+ }
197
+ }
198
+
199
+ return
200
+ })()
201
+
202
+ return { url: url.toString(), ...result }
203
+ } catch {
204
+ return { url: url_ }
205
+ }
206
+ }