viem 2.0.10 → 2.1.0
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 +12 -0
- package/_cjs/chains/definitions/baseSepolia.js +4 -0
- package/_cjs/chains/definitions/baseSepolia.js.map +1 -1
- package/_cjs/chains/definitions/palm.js +32 -0
- package/_cjs/chains/definitions/palm.js.map +1 -0
- package/_cjs/chains/definitions/palmTestnet.js +33 -0
- package/_cjs/chains/definitions/palmTestnet.js.map +1 -0
- package/_cjs/chains/index.js +6 -2
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/errors/cursor.js +13 -1
- package/_cjs/errors/cursor.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/errors/version.js.map +1 -1
- package/_cjs/utils/abi/decodeAbiParameters.js +117 -126
- package/_cjs/utils/abi/decodeAbiParameters.js.map +1 -1
- package/_cjs/utils/abi/decodeEventLog.js +7 -4
- package/_cjs/utils/abi/decodeEventLog.js.map +1 -1
- package/_cjs/utils/cursor.js +40 -3
- package/_cjs/utils/cursor.js.map +1 -1
- package/_cjs/utils/encoding/fromBytes.js +2 -2
- package/_cjs/utils/encoding/fromBytes.js.map +1 -1
- package/_cjs/utils/encoding/fromRlp.js +1 -1
- package/_cjs/utils/encoding/fromRlp.js.map +1 -1
- package/_esm/chains/definitions/baseSepolia.js +4 -0
- package/_esm/chains/definitions/baseSepolia.js.map +1 -1
- package/_esm/chains/definitions/palm.js +29 -0
- package/_esm/chains/definitions/palm.js.map +1 -0
- package/_esm/chains/definitions/palmTestnet.js +30 -0
- package/_esm/chains/definitions/palmTestnet.js.map +1 -0
- package/_esm/chains/index.js +2 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/errors/cursor.js +11 -0
- package/_esm/errors/cursor.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/errors/version.js.map +1 -1
- package/_esm/utils/abi/decodeAbiParameters.js +145 -140
- package/_esm/utils/abi/decodeAbiParameters.js.map +1 -1
- package/_esm/utils/abi/decodeEventLog.js +7 -4
- package/_esm/utils/abi/decodeEventLog.js.map +1 -1
- package/_esm/utils/cursor.js +41 -4
- package/_esm/utils/cursor.js.map +1 -1
- package/_esm/utils/encoding/fromBytes.js +2 -2
- package/_esm/utils/encoding/fromBytes.js.map +1 -1
- package/_esm/utils/encoding/fromRlp.js +1 -1
- package/_esm/utils/encoding/fromRlp.js.map +1 -1
- package/_types/chains/definitions/baseSepolia.d.ts +4 -0
- package/_types/chains/definitions/baseSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/palm.d.ts +33 -0
- package/_types/chains/definitions/palm.d.ts.map +1 -0
- package/_types/chains/definitions/palmTestnet.d.ts +33 -0
- package/_types/chains/definitions/palmTestnet.d.ts.map +1 -0
- package/_types/chains/index.d.ts +2 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/errors/cursor.d.ts +10 -0
- package/_types/errors/cursor.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/errors/version.d.ts.map +1 -1
- package/_types/utils/abi/decodeAbiParameters.d.ts +18 -19
- package/_types/utils/abi/decodeAbiParameters.d.ts.map +1 -1
- package/_types/utils/abi/decodeEventLog.d.ts.map +1 -1
- package/_types/utils/cursor.d.ts +13 -3
- package/_types/utils/cursor.d.ts.map +1 -1
- package/chains/definitions/baseSepolia.ts +4 -0
- package/chains/definitions/palm.ts +29 -0
- package/chains/definitions/palmTestnet.ts +30 -0
- package/chains/index.ts +2 -0
- package/errors/cursor.ts +13 -0
- package/errors/version.ts +1 -1
- package/package.json +1 -1
- package/utils/abi/decodeAbiParameters.ts +226 -249
- package/utils/abi/decodeEventLog.ts +9 -4
- package/utils/cursor.ts +53 -6
- package/utils/encoding/fromBytes.ts +2 -2
- package/utils/encoding/fromRlp.ts +1 -1
package/utils/cursor.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import {
|
2
2
|
NegativeOffsetError,
|
3
3
|
PositionOutOfBoundsError,
|
4
|
+
RecursiveReadLimitExceededError,
|
4
5
|
} from '../errors/cursor.js'
|
5
6
|
import type { ErrorType } from '../errors/utils.js'
|
6
7
|
import type { ByteArray } from '../types/misc.js'
|
@@ -9,8 +10,13 @@ export type Cursor = {
|
|
9
10
|
bytes: ByteArray
|
10
11
|
dataView: DataView
|
11
12
|
position: number
|
13
|
+
positionReadCount: Map<number, number>
|
14
|
+
recursiveReadCount: number
|
15
|
+
recursiveReadLimit: number
|
16
|
+
assertReadLimit(position?: number): void
|
12
17
|
assertPosition(position: number): void
|
13
18
|
decrementPosition(offset: number): void
|
19
|
+
getReadCount(position?: number): number
|
14
20
|
incrementPosition(offset: number): void
|
15
21
|
inspectByte(position?: number): ByteArray[number]
|
16
22
|
inspectBytes(length: number, position?: number): ByteArray
|
@@ -25,12 +31,13 @@ export type Cursor = {
|
|
25
31
|
pushUint24(value: number): void
|
26
32
|
pushUint32(value: number): void
|
27
33
|
readByte(): ByteArray[number]
|
28
|
-
readBytes(length: number): ByteArray
|
34
|
+
readBytes(length: number, size?: number): ByteArray
|
29
35
|
readUint8(): number
|
30
36
|
readUint16(): number
|
31
37
|
readUint24(): number
|
32
38
|
readUint32(): number
|
33
|
-
setPosition(position: number): void
|
39
|
+
setPosition(position: number): () => void
|
40
|
+
_touch(): void
|
34
41
|
}
|
35
42
|
|
36
43
|
export type CreateCursorErrorType = ErrorType
|
@@ -51,6 +58,16 @@ const staticCursor: Cursor = {
|
|
51
58
|
bytes: new Uint8Array(),
|
52
59
|
dataView: new DataView(new ArrayBuffer(0)),
|
53
60
|
position: 0,
|
61
|
+
positionReadCount: new Map(),
|
62
|
+
recursiveReadCount: 0,
|
63
|
+
recursiveReadLimit: Infinity,
|
64
|
+
assertReadLimit() {
|
65
|
+
if (this.recursiveReadCount >= this.recursiveReadLimit)
|
66
|
+
throw new RecursiveReadLimitExceededError({
|
67
|
+
count: this.recursiveReadCount + 1,
|
68
|
+
limit: this.recursiveReadLimit,
|
69
|
+
})
|
70
|
+
},
|
54
71
|
assertPosition(position) {
|
55
72
|
if (position < 0 || position > this.bytes.length - 1)
|
56
73
|
throw new PositionOutOfBoundsError({
|
@@ -64,6 +81,9 @@ const staticCursor: Cursor = {
|
|
64
81
|
this.assertPosition(position)
|
65
82
|
this.position = position
|
66
83
|
},
|
84
|
+
getReadCount(position) {
|
85
|
+
return this.positionReadCount.get(position || this.position) || 0
|
86
|
+
},
|
67
87
|
incrementPosition(offset) {
|
68
88
|
if (offset < 0) throw new NegativeOffsetError({ offset })
|
69
89
|
const position = this.position + offset
|
@@ -135,48 +155,75 @@ const staticCursor: Cursor = {
|
|
135
155
|
this.position += 4
|
136
156
|
},
|
137
157
|
readByte() {
|
158
|
+
this.assertReadLimit()
|
159
|
+
this._touch()
|
138
160
|
const value = this.inspectByte()
|
139
161
|
this.position++
|
140
162
|
return value
|
141
163
|
},
|
142
|
-
readBytes(length) {
|
164
|
+
readBytes(length, size) {
|
165
|
+
this.assertReadLimit()
|
166
|
+
this._touch()
|
143
167
|
const value = this.inspectBytes(length)
|
144
|
-
this.position += length
|
168
|
+
this.position += size ?? length
|
145
169
|
return value
|
146
170
|
},
|
147
171
|
readUint8() {
|
172
|
+
this.assertReadLimit()
|
173
|
+
this._touch()
|
148
174
|
const value = this.inspectUint8()
|
149
175
|
this.position += 1
|
150
176
|
return value
|
151
177
|
},
|
152
178
|
readUint16() {
|
179
|
+
this.assertReadLimit()
|
180
|
+
this._touch()
|
153
181
|
const value = this.inspectUint16()
|
154
182
|
this.position += 2
|
155
183
|
return value
|
156
184
|
},
|
157
185
|
readUint24() {
|
186
|
+
this.assertReadLimit()
|
187
|
+
this._touch()
|
158
188
|
const value = this.inspectUint24()
|
159
189
|
this.position += 3
|
160
190
|
return value
|
161
191
|
},
|
162
192
|
readUint32() {
|
193
|
+
this.assertReadLimit()
|
194
|
+
this._touch()
|
163
195
|
const value = this.inspectUint32()
|
164
196
|
this.position += 4
|
165
197
|
return value
|
166
198
|
},
|
167
199
|
setPosition(position) {
|
200
|
+
const oldPosition = this.position
|
168
201
|
this.assertPosition(position)
|
169
202
|
this.position = position
|
203
|
+
return () => (this.position = oldPosition)
|
204
|
+
},
|
205
|
+
_touch() {
|
206
|
+
if (this.recursiveReadLimit === Infinity) return
|
207
|
+
const count = this.getReadCount()
|
208
|
+
this.positionReadCount.set(this.position, count + 1)
|
209
|
+
if (count > 0) this.recursiveReadCount++
|
170
210
|
},
|
171
211
|
}
|
172
212
|
|
173
|
-
|
174
|
-
|
213
|
+
type CursorConfig = { recursiveReadLimit?: number }
|
214
|
+
|
215
|
+
export function createCursor(
|
216
|
+
bytes: ByteArray,
|
217
|
+
{ recursiveReadLimit = 8_192 }: CursorConfig = {},
|
218
|
+
): Cursor {
|
219
|
+
const cursor: Cursor = Object.create(staticCursor)
|
175
220
|
cursor.bytes = bytes
|
176
221
|
cursor.dataView = new DataView(
|
177
222
|
bytes.buffer,
|
178
223
|
bytes.byteOffset,
|
179
224
|
bytes.byteLength,
|
180
225
|
)
|
226
|
+
cursor.positionReadCount = new Map()
|
227
|
+
cursor.recursiveReadLimit = recursiveReadLimit
|
181
228
|
return cursor
|
182
229
|
}
|
@@ -119,7 +119,7 @@ export function bytesToBigInt(
|
|
119
119
|
): bigint {
|
120
120
|
if (typeof opts.size !== 'undefined') assertSize(bytes, { size: opts.size })
|
121
121
|
const hex = bytesToHex(bytes, opts)
|
122
|
-
return hexToBigInt(hex)
|
122
|
+
return hexToBigInt(hex, opts)
|
123
123
|
}
|
124
124
|
|
125
125
|
export type BytesToBoolOpts = {
|
@@ -187,7 +187,7 @@ export function bytesToNumber(
|
|
187
187
|
): number {
|
188
188
|
if (typeof opts.size !== 'undefined') assertSize(bytes, { size: opts.size })
|
189
189
|
const hex = bytesToHex(bytes, opts)
|
190
|
-
return hexToNumber(hex)
|
190
|
+
return hexToNumber(hex, opts)
|
191
191
|
}
|
192
192
|
|
193
193
|
export type BytesToStringOpts = {
|
@@ -41,7 +41,7 @@ export function fromRlp<to extends To = 'hex'>(
|
|
41
41
|
return value
|
42
42
|
})()
|
43
43
|
|
44
|
-
const cursor = createCursor(bytes)
|
44
|
+
const cursor = createCursor(bytes, { recursiveReadLimit: Infinity })
|
45
45
|
const result = fromRlpCursor(cursor, to)
|
46
46
|
|
47
47
|
return result as FromRlpReturnType<to>
|