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.
- package/CHANGELOG.md +30 -0
- package/_cjs/account-abstraction/actions/bundler/estimateUserOperationGas.js +1 -2
- package/_cjs/account-abstraction/actions/bundler/estimateUserOperationGas.js.map +1 -1
- package/_cjs/chains/definitions/marsCredit.js +23 -0
- package/_cjs/chains/definitions/marsCredit.js.map +1 -0
- package/_cjs/chains/index.js +10 -8
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/clients/createClient.js +1 -0
- package/_cjs/clients/createClient.js.map +1 -1
- package/_cjs/errors/encoding.js +13 -1
- package/_cjs/errors/encoding.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/index.js +8 -6
- package/_cjs/index.js.map +1 -1
- package/_cjs/tempo/Abis.js +49 -1
- package/_cjs/tempo/Abis.js.map +1 -1
- package/_cjs/tempo/Addresses.js +3 -1
- package/_cjs/tempo/Addresses.js.map +1 -1
- package/_cjs/tempo/Decorator.js.map +1 -1
- package/_cjs/tempo/Formatters.js +5 -1
- package/_cjs/tempo/Formatters.js.map +1 -1
- package/_cjs/tempo/Selectors.js +8 -1
- package/_cjs/tempo/Selectors.js.map +1 -1
- package/_cjs/tempo/Transaction.js.map +1 -1
- package/_cjs/tempo/actions/receivePolicy.js +29 -5
- package/_cjs/tempo/actions/receivePolicy.js.map +1 -1
- package/_cjs/tempo/actions/virtualAddress.js +2 -5
- package/_cjs/tempo/actions/virtualAddress.js.map +1 -1
- package/_cjs/tempo/actions/zone.js +69 -48
- package/_cjs/tempo/actions/zone.js.map +1 -1
- package/_cjs/tempo/chainConfig.js +11 -2
- package/_cjs/tempo/chainConfig.js.map +1 -1
- package/_cjs/utils/abi/decodeAbiParameters.js +11 -2
- package/_cjs/utils/abi/decodeAbiParameters.js.map +1 -1
- package/_cjs/utils/abi/encodeAbiParameters.js +26 -11
- package/_cjs/utils/abi/encodeAbiParameters.js.map +1 -1
- package/_cjs/utils/encoding/fromRlp.js +9 -0
- package/_cjs/utils/encoding/fromRlp.js.map +1 -1
- package/_esm/account-abstraction/actions/bundler/estimateUserOperationGas.js +1 -2
- package/_esm/account-abstraction/actions/bundler/estimateUserOperationGas.js.map +1 -1
- package/_esm/chains/definitions/marsCredit.js +20 -0
- package/_esm/chains/definitions/marsCredit.js.map +1 -0
- package/_esm/chains/index.js +1 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/clients/createClient.js +5 -3
- package/_esm/clients/createClient.js.map +1 -1
- package/_esm/errors/encoding.js +10 -0
- package/_esm/errors/encoding.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/index.js +1 -1
- package/_esm/index.js.map +1 -1
- package/_esm/tempo/Abis.js +48 -0
- package/_esm/tempo/Abis.js.map +1 -1
- package/_esm/tempo/Addresses.js +2 -0
- package/_esm/tempo/Addresses.js.map +1 -1
- package/_esm/tempo/Decorator.js.map +1 -1
- package/_esm/tempo/Formatters.js +7 -1
- package/_esm/tempo/Formatters.js.map +1 -1
- package/_esm/tempo/Selectors.js +7 -0
- package/_esm/tempo/Selectors.js.map +1 -1
- package/_esm/tempo/Transaction.js.map +1 -1
- package/_esm/tempo/actions/receivePolicy.js +32 -5
- package/_esm/tempo/actions/receivePolicy.js.map +1 -1
- package/_esm/tempo/actions/virtualAddress.js +2 -6
- package/_esm/tempo/actions/virtualAddress.js.map +1 -1
- package/_esm/tempo/actions/zone.js +96 -49
- package/_esm/tempo/actions/zone.js.map +1 -1
- package/_esm/tempo/chainConfig.js +11 -2
- package/_esm/tempo/chainConfig.js.map +1 -1
- package/_esm/utils/abi/decodeAbiParameters.js +18 -2
- package/_esm/utils/abi/decodeAbiParameters.js.map +1 -1
- package/_esm/utils/abi/encodeAbiParameters.js +30 -12
- package/_esm/utils/abi/encodeAbiParameters.js.map +1 -1
- package/_esm/utils/encoding/fromRlp.js +12 -1
- package/_esm/utils/encoding/fromRlp.js.map +1 -1
- package/_types/account-abstraction/actions/bundler/estimateUserOperationGas.d.ts.map +1 -1
- package/_types/chains/definitions/marsCredit.d.ts +50 -0
- package/_types/chains/definitions/marsCredit.d.ts.map +1 -0
- package/_types/chains/definitions/tempo.d.ts +42 -0
- package/_types/chains/definitions/tempo.d.ts.map +1 -1
- package/_types/chains/definitions/tempoDevnet.d.ts +42 -0
- package/_types/chains/definitions/tempoDevnet.d.ts.map +1 -1
- package/_types/chains/definitions/tempoLocalnet.d.ts +42 -0
- package/_types/chains/definitions/tempoLocalnet.d.ts.map +1 -1
- package/_types/chains/definitions/tempoModerato.d.ts +42 -0
- package/_types/chains/definitions/tempoModerato.d.ts.map +1 -1
- package/_types/chains/index.d.ts +1 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/clients/createClient.d.ts +4 -3
- package/_types/clients/createClient.d.ts.map +1 -1
- package/_types/errors/encoding.d.ts +17 -0
- package/_types/errors/encoding.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/index.d.ts +1 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/tempo/Abis.d.ts +119 -0
- package/_types/tempo/Abis.d.ts.map +1 -1
- package/_types/tempo/Addresses.d.ts +2 -0
- package/_types/tempo/Addresses.d.ts.map +1 -1
- package/_types/tempo/Decorator.d.ts +4 -0
- package/_types/tempo/Decorator.d.ts.map +1 -1
- package/_types/tempo/Formatters.d.ts.map +1 -1
- package/_types/tempo/Selectors.d.ts +7 -0
- package/_types/tempo/Selectors.d.ts.map +1 -1
- package/_types/tempo/Transaction.d.ts +11 -0
- package/_types/tempo/Transaction.d.ts.map +1 -1
- package/_types/tempo/actions/receivePolicy.d.ts +1 -1
- package/_types/tempo/actions/receivePolicy.d.ts.map +1 -1
- package/_types/tempo/actions/virtualAddress.d.ts.map +1 -1
- package/_types/tempo/actions/zone.d.ts +63 -3
- package/_types/tempo/actions/zone.d.ts.map +1 -1
- package/_types/tempo/chainConfig.d.ts +22 -0
- package/_types/tempo/chainConfig.d.ts.map +1 -1
- package/_types/tempo/zones/zone.d.ts +126 -0
- package/_types/tempo/zones/zone.d.ts.map +1 -1
- package/_types/utils/abi/decodeAbiParameters.d.ts.map +1 -1
- package/_types/utils/abi/encodeAbiParameters.d.ts +5 -5
- package/_types/utils/abi/encodeAbiParameters.d.ts.map +1 -1
- package/_types/utils/encoding/fromRlp.d.ts +3 -3
- package/_types/utils/encoding/fromRlp.d.ts.map +1 -1
- package/account-abstraction/actions/bundler/estimateUserOperationGas.ts +1 -2
- package/chains/definitions/marsCredit.ts +20 -0
- package/chains/index.ts +1 -0
- package/clients/createClient.ts +5 -3
- package/errors/encoding.ts +26 -0
- package/errors/version.ts +1 -1
- package/index.ts +4 -0
- package/package.json +3 -3
- package/tempo/Abis.ts +49 -0
- package/tempo/Addresses.ts +2 -0
- package/tempo/Decorator.ts +3 -0
- package/tempo/Formatters.ts +8 -0
- package/tempo/Selectors.ts +8 -0
- package/tempo/Transaction.ts +10 -0
- package/tempo/actions/receivePolicy.ts +39 -4
- package/tempo/actions/virtualAddress.ts +2 -8
- package/tempo/actions/zone.ts +164 -74
- package/tempo/chainConfig.ts +11 -2
- package/utils/abi/decodeAbiParameters.ts +17 -2
- package/utils/abi/encodeAbiParameters.ts +32 -15
- 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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
|
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
|
-
|
|
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:
|
|
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:
|
|
282
|
+
encoded: concatHex(preparedParams.map(({ encoded }) => encoded)),
|
|
282
283
|
}
|
|
283
284
|
}
|
|
284
285
|
|
|
285
286
|
type EncodeBytesErrorType =
|
|
286
287
|
| AbiEncodingBytesSizeMismatchErrorType
|
|
287
|
-
|
|
|
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:
|
|
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
|
-
|
|
|
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:
|
|
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
|
-
|
|
|
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
|
-
:
|
|
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
|
}
|