viem 2.54.1 → 2.54.3

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 (141) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/_cjs/account-abstraction/actions/bundler/estimateUserOperationGas.js +1 -2
  3. package/_cjs/account-abstraction/actions/bundler/estimateUserOperationGas.js.map +1 -1
  4. package/_cjs/chains/definitions/marsCredit.js +23 -0
  5. package/_cjs/chains/definitions/marsCredit.js.map +1 -0
  6. package/_cjs/chains/index.js +10 -8
  7. package/_cjs/chains/index.js.map +1 -1
  8. package/_cjs/clients/createClient.js +1 -0
  9. package/_cjs/clients/createClient.js.map +1 -1
  10. package/_cjs/errors/encoding.js +13 -1
  11. package/_cjs/errors/encoding.js.map +1 -1
  12. package/_cjs/errors/version.js +1 -1
  13. package/_cjs/index.js +8 -6
  14. package/_cjs/index.js.map +1 -1
  15. package/_cjs/tempo/Abis.js +49 -1
  16. package/_cjs/tempo/Abis.js.map +1 -1
  17. package/_cjs/tempo/Addresses.js +3 -1
  18. package/_cjs/tempo/Addresses.js.map +1 -1
  19. package/_cjs/tempo/Decorator.js.map +1 -1
  20. package/_cjs/tempo/Formatters.js +5 -1
  21. package/_cjs/tempo/Formatters.js.map +1 -1
  22. package/_cjs/tempo/Selectors.js +8 -1
  23. package/_cjs/tempo/Selectors.js.map +1 -1
  24. package/_cjs/tempo/Transaction.js.map +1 -1
  25. package/_cjs/tempo/actions/receivePolicy.js +29 -5
  26. package/_cjs/tempo/actions/receivePolicy.js.map +1 -1
  27. package/_cjs/tempo/actions/virtualAddress.js +2 -5
  28. package/_cjs/tempo/actions/virtualAddress.js.map +1 -1
  29. package/_cjs/tempo/actions/zone.js +69 -48
  30. package/_cjs/tempo/actions/zone.js.map +1 -1
  31. package/_cjs/tempo/chainConfig.js +11 -2
  32. package/_cjs/tempo/chainConfig.js.map +1 -1
  33. package/_cjs/utils/abi/decodeAbiParameters.js +11 -2
  34. package/_cjs/utils/abi/decodeAbiParameters.js.map +1 -1
  35. package/_cjs/utils/abi/encodeAbiParameters.js +26 -11
  36. package/_cjs/utils/abi/encodeAbiParameters.js.map +1 -1
  37. package/_cjs/utils/encoding/fromRlp.js +9 -0
  38. package/_cjs/utils/encoding/fromRlp.js.map +1 -1
  39. package/_esm/account-abstraction/actions/bundler/estimateUserOperationGas.js +1 -2
  40. package/_esm/account-abstraction/actions/bundler/estimateUserOperationGas.js.map +1 -1
  41. package/_esm/chains/definitions/marsCredit.js +20 -0
  42. package/_esm/chains/definitions/marsCredit.js.map +1 -0
  43. package/_esm/chains/index.js +1 -0
  44. package/_esm/chains/index.js.map +1 -1
  45. package/_esm/clients/createClient.js +5 -3
  46. package/_esm/clients/createClient.js.map +1 -1
  47. package/_esm/errors/encoding.js +10 -0
  48. package/_esm/errors/encoding.js.map +1 -1
  49. package/_esm/errors/version.js +1 -1
  50. package/_esm/index.js +1 -1
  51. package/_esm/index.js.map +1 -1
  52. package/_esm/tempo/Abis.js +48 -0
  53. package/_esm/tempo/Abis.js.map +1 -1
  54. package/_esm/tempo/Addresses.js +2 -0
  55. package/_esm/tempo/Addresses.js.map +1 -1
  56. package/_esm/tempo/Decorator.js.map +1 -1
  57. package/_esm/tempo/Formatters.js +7 -1
  58. package/_esm/tempo/Formatters.js.map +1 -1
  59. package/_esm/tempo/Selectors.js +7 -0
  60. package/_esm/tempo/Selectors.js.map +1 -1
  61. package/_esm/tempo/Transaction.js.map +1 -1
  62. package/_esm/tempo/actions/receivePolicy.js +32 -5
  63. package/_esm/tempo/actions/receivePolicy.js.map +1 -1
  64. package/_esm/tempo/actions/virtualAddress.js +2 -6
  65. package/_esm/tempo/actions/virtualAddress.js.map +1 -1
  66. package/_esm/tempo/actions/zone.js +96 -49
  67. package/_esm/tempo/actions/zone.js.map +1 -1
  68. package/_esm/tempo/chainConfig.js +11 -2
  69. package/_esm/tempo/chainConfig.js.map +1 -1
  70. package/_esm/utils/abi/decodeAbiParameters.js +18 -2
  71. package/_esm/utils/abi/decodeAbiParameters.js.map +1 -1
  72. package/_esm/utils/abi/encodeAbiParameters.js +30 -12
  73. package/_esm/utils/abi/encodeAbiParameters.js.map +1 -1
  74. package/_esm/utils/encoding/fromRlp.js +12 -1
  75. package/_esm/utils/encoding/fromRlp.js.map +1 -1
  76. package/_types/account-abstraction/actions/bundler/estimateUserOperationGas.d.ts.map +1 -1
  77. package/_types/chains/definitions/marsCredit.d.ts +50 -0
  78. package/_types/chains/definitions/marsCredit.d.ts.map +1 -0
  79. package/_types/chains/definitions/tempo.d.ts +42 -0
  80. package/_types/chains/definitions/tempo.d.ts.map +1 -1
  81. package/_types/chains/definitions/tempoDevnet.d.ts +42 -0
  82. package/_types/chains/definitions/tempoDevnet.d.ts.map +1 -1
  83. package/_types/chains/definitions/tempoLocalnet.d.ts +42 -0
  84. package/_types/chains/definitions/tempoLocalnet.d.ts.map +1 -1
  85. package/_types/chains/definitions/tempoModerato.d.ts +42 -0
  86. package/_types/chains/definitions/tempoModerato.d.ts.map +1 -1
  87. package/_types/chains/index.d.ts +1 -0
  88. package/_types/chains/index.d.ts.map +1 -1
  89. package/_types/clients/createClient.d.ts +4 -3
  90. package/_types/clients/createClient.d.ts.map +1 -1
  91. package/_types/errors/encoding.d.ts +17 -0
  92. package/_types/errors/encoding.d.ts.map +1 -1
  93. package/_types/errors/version.d.ts +1 -1
  94. package/_types/index.d.ts +1 -1
  95. package/_types/index.d.ts.map +1 -1
  96. package/_types/tempo/Abis.d.ts +119 -0
  97. package/_types/tempo/Abis.d.ts.map +1 -1
  98. package/_types/tempo/Addresses.d.ts +2 -0
  99. package/_types/tempo/Addresses.d.ts.map +1 -1
  100. package/_types/tempo/Decorator.d.ts +4 -0
  101. package/_types/tempo/Decorator.d.ts.map +1 -1
  102. package/_types/tempo/Formatters.d.ts.map +1 -1
  103. package/_types/tempo/Selectors.d.ts +7 -0
  104. package/_types/tempo/Selectors.d.ts.map +1 -1
  105. package/_types/tempo/Transaction.d.ts +11 -0
  106. package/_types/tempo/Transaction.d.ts.map +1 -1
  107. package/_types/tempo/actions/receivePolicy.d.ts +1 -1
  108. package/_types/tempo/actions/receivePolicy.d.ts.map +1 -1
  109. package/_types/tempo/actions/virtualAddress.d.ts.map +1 -1
  110. package/_types/tempo/actions/zone.d.ts +63 -3
  111. package/_types/tempo/actions/zone.d.ts.map +1 -1
  112. package/_types/tempo/chainConfig.d.ts +22 -0
  113. package/_types/tempo/chainConfig.d.ts.map +1 -1
  114. package/_types/tempo/zones/zone.d.ts +126 -0
  115. package/_types/tempo/zones/zone.d.ts.map +1 -1
  116. package/_types/utils/abi/decodeAbiParameters.d.ts.map +1 -1
  117. package/_types/utils/abi/encodeAbiParameters.d.ts +5 -5
  118. package/_types/utils/abi/encodeAbiParameters.d.ts.map +1 -1
  119. package/_types/utils/encoding/fromRlp.d.ts +3 -3
  120. package/_types/utils/encoding/fromRlp.d.ts.map +1 -1
  121. package/account-abstraction/actions/bundler/estimateUserOperationGas.ts +1 -2
  122. package/chains/definitions/marsCredit.ts +20 -0
  123. package/chains/index.ts +1 -0
  124. package/clients/createClient.ts +5 -3
  125. package/errors/encoding.ts +26 -0
  126. package/errors/version.ts +1 -1
  127. package/index.ts +4 -0
  128. package/package.json +3 -3
  129. package/tempo/Abis.ts +49 -0
  130. package/tempo/Addresses.ts +2 -0
  131. package/tempo/Decorator.ts +3 -0
  132. package/tempo/Formatters.ts +8 -0
  133. package/tempo/Selectors.ts +8 -0
  134. package/tempo/Transaction.ts +10 -0
  135. package/tempo/actions/receivePolicy.ts +39 -4
  136. package/tempo/actions/virtualAddress.ts +2 -8
  137. package/tempo/actions/zone.ts +164 -74
  138. package/tempo/chainConfig.ts +11 -2
  139. package/utils/abi/decodeAbiParameters.ts +17 -2
  140. package/utils/abi/encodeAbiParameters.ts +32 -15
  141. package/utils/encoding/fromRlp.ts +18 -1
@@ -26,7 +26,7 @@ import { IntegerOutOfRangeError } from '../../errors/encoding.js'
26
26
  import type { ErrorType } from '../../errors/utils.js'
27
27
  import type { Hex } from '../../types/misc.js'
28
28
  import { type IsAddressErrorType, isAddress } from '../address/isAddress.js'
29
- import { type ConcatErrorType, concat } from '../data/concat.js'
29
+ import { type ConcatHexErrorType, concatHex } from '../data/concat.js'
30
30
  import { type PadHexErrorType, padHex } from '../data/pad.js'
31
31
  import { type SizeErrorType, size } from '../data/size.js'
32
32
  import { type SliceErrorType, slice } from '../data/slice.js'
@@ -101,9 +101,7 @@ export function encodeAbiParameters<
101
101
  params: params as readonly AbiParameter[],
102
102
  values: values as any,
103
103
  })
104
- const data = encodeParams(preparedParams)
105
- if (data.length === 0) return '0x'
106
- return data
104
+ return encodeParams(preparedParams)
107
105
  }
108
106
 
109
107
  /////////////////////////////////////////////////////////////////
@@ -212,7 +210,8 @@ function encodeParams(preparedParams: PreparedParam[]): Hex {
212
210
  }
213
211
 
214
212
  // 3. Concatenate static and dynamic parts.
215
- return concat([...staticParams, ...dynamicParams])
213
+ // `concatHex` returns `'0x'` for empty input (zero-width parameters).
214
+ return concatHex([...staticParams, ...dynamicParams])
216
215
  }
217
216
 
218
217
  /////////////////////////////////////////////////////////////////
@@ -229,7 +228,7 @@ function encodeAddress(value: Hex): PreparedParam {
229
228
 
230
229
  type EncodeArrayErrorType =
231
230
  | AbiEncodingArrayLengthMismatchErrorType
232
- | ConcatErrorType
231
+ | ConcatHexErrorType
233
232
  | EncodeParamsErrorType
234
233
  | InvalidArrayErrorType
235
234
  | NumberToHexErrorType
@@ -257,7 +256,9 @@ function encodeArray<const param extends AbiParameter>(
257
256
  type: `${param.type}[${length}]`,
258
257
  })
259
258
 
260
- let dynamicChild = false
259
+ // Zero-length fixed arrays of dynamic types (e.g. `string[0]`) are dynamic
260
+ // per the ABI spec, even though they have no elements to inspect.
261
+ let dynamicChild = value.length === 0 && isDynamicType(param)
261
262
  const preparedParams: PreparedParam[] = []
262
263
  for (let i = 0; i < value.length; i++) {
263
264
  const preparedParam = prepareParam({ param, value: value[i] })
@@ -271,20 +272,20 @@ function encodeArray<const param extends AbiParameter>(
271
272
  const length = numberToHex(preparedParams.length, { size: 32 })
272
273
  return {
273
274
  dynamic: true,
274
- encoded: preparedParams.length > 0 ? concat([length, data]) : length,
275
+ encoded: concatHex([length, data]),
275
276
  }
276
277
  }
277
278
  if (dynamicChild) return { dynamic: true, encoded: data }
278
279
  }
279
280
  return {
280
281
  dynamic: false,
281
- encoded: concat(preparedParams.map(({ encoded }) => encoded)),
282
+ encoded: concatHex(preparedParams.map(({ encoded }) => encoded)),
282
283
  }
283
284
  }
284
285
 
285
286
  type EncodeBytesErrorType =
286
287
  | AbiEncodingBytesSizeMismatchErrorType
287
- | ConcatErrorType
288
+ | ConcatHexErrorType
288
289
  | PadHexErrorType
289
290
  | NumberToHexErrorType
290
291
  | SizeErrorType
@@ -307,7 +308,10 @@ function encodeBytes<const param extends AbiParameter>(
307
308
  })
308
309
  return {
309
310
  dynamic: true,
310
- encoded: concat([padHex(numberToHex(bytesSize, { size: 32 })), value_]),
311
+ encoded: concatHex([
312
+ padHex(numberToHex(bytesSize, { size: 32 })),
313
+ value_,
314
+ ]),
311
315
  }
312
316
  }
313
317
  if (bytesSize !== Number.parseInt(paramSize, 10))
@@ -356,7 +360,7 @@ function encodeNumber(
356
360
  }
357
361
 
358
362
  type EncodeStringErrorType =
359
- | ConcatErrorType
363
+ | ConcatHexErrorType
360
364
  | NumberToHexErrorType
361
365
  | PadHexErrorType
362
366
  | SizeErrorType
@@ -377,7 +381,7 @@ function encodeString(value: string): PreparedParam {
377
381
  }
378
382
  return {
379
383
  dynamic: true,
380
- encoded: concat([
384
+ encoded: concatHex([
381
385
  padHex(numberToHex(size(hexValue), { size: 32 })),
382
386
  ...parts,
383
387
  ]),
@@ -385,7 +389,7 @@ function encodeString(value: string): PreparedParam {
385
389
  }
386
390
 
387
391
  type EncodeTupleErrorType =
388
- | ConcatErrorType
392
+ | ConcatHexErrorType
389
393
  | EncodeParamsErrorType
390
394
  // TODO: Add back once circular type reference is resolved
391
395
  // | PrepareParamErrorType
@@ -413,7 +417,7 @@ function encodeTuple<
413
417
  dynamic,
414
418
  encoded: dynamic
415
419
  ? encodeParams(preparedParams)
416
- : concat(preparedParams.map(({ encoded }) => encoded)),
420
+ : concatHex(preparedParams.map(({ encoded }) => encoded)),
417
421
  }
418
422
  }
419
423
 
@@ -428,3 +432,16 @@ export function getArrayComponents(
428
432
  [matches[2] ? Number(matches[2]) : null, matches[1]]
429
433
  : undefined
430
434
  }
435
+
436
+ function isDynamicType(param: AbiParameter): boolean {
437
+ const { type } = param
438
+ if (type === 'string') return true
439
+ if (type === 'bytes') return true
440
+ if (type.endsWith('[]')) return true
441
+ if (type === 'tuple')
442
+ return (param as TupleAbiParameter).components.some(isDynamicType)
443
+ const arrayComponents = getArrayComponents(type)
444
+ if (arrayComponents)
445
+ return isDynamicType({ ...param, type: arrayComponents[1] })
446
+ return false
447
+ }
@@ -4,6 +4,10 @@ import {
4
4
  type InvalidHexValueErrorType,
5
5
  RlpDepthLimitExceededError,
6
6
  type RlpDepthLimitExceededErrorType,
7
+ RlpListBoundaryExceededError,
8
+ type RlpListBoundaryExceededErrorType,
9
+ RlpTrailingBytesError,
10
+ type RlpTrailingBytesErrorType,
7
11
  } from '../../errors/encoding.js'
8
12
  import type { ErrorType } from '../../errors/utils.js'
9
13
  import type { ByteArray, Hex } from '../../types/misc.js'
@@ -31,6 +35,7 @@ export type FromRlpErrorType =
31
35
  | HexToBytesErrorType
32
36
  | InvalidHexValueErrorType
33
37
  | RlpDepthLimitExceededErrorType
38
+ | RlpTrailingBytesErrorType
34
39
  | ErrorType
35
40
 
36
41
  export function fromRlp<to extends To = 'hex'>(
@@ -51,6 +56,12 @@ export function fromRlp<to extends To = 'hex'>(
51
56
  })
52
57
  const result = fromRlpCursor(cursor, to)
53
58
 
59
+ // RLP payloads encode exactly one item (Yellow Paper, Appendix B).
60
+ if (cursor.position < cursor.bytes.length)
61
+ throw new RlpTrailingBytesError({
62
+ count: cursor.bytes.length - cursor.position,
63
+ })
64
+
54
65
  return result as FromRlpReturnType<to>
55
66
  }
56
67
 
@@ -105,7 +116,7 @@ function readLength(cursor: Cursor, prefix: number, offset: number) {
105
116
  throw new BaseError('Invalid RLP prefix')
106
117
  }
107
118
 
108
- type ReadListErrorType = ErrorType
119
+ type ReadListErrorType = RlpListBoundaryExceededErrorType | ErrorType
109
120
 
110
121
  function readList<to extends To>(
111
122
  cursor: Cursor,
@@ -117,5 +128,11 @@ function readList<to extends To>(
117
128
  const value: FromRlpReturnType<to>[] = []
118
129
  while (cursor.position - position < length)
119
130
  value.push(fromRlpCursor(cursor, to, recursiveDepth))
131
+ // Items must consume exactly the declared list length.
132
+ if (cursor.position - position !== length)
133
+ throw new RlpListBoundaryExceededError({
134
+ consumed: cursor.position - position,
135
+ declared: length,
136
+ })
120
137
  return value
121
138
  }