ox 0.14.66 → 0.14.68
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 +42 -0
- package/_cjs/core/AbiEvent.js +45 -1
- package/_cjs/core/AbiEvent.js.map +1 -1
- package/_cjs/core/AbiParameters.js +6 -2
- package/_cjs/core/AbiParameters.js.map +1 -1
- package/_cjs/core/Address.js +24 -21
- package/_cjs/core/Address.js.map +1 -1
- package/_cjs/core/Base58.js +14 -4
- package/_cjs/core/Base58.js.map +1 -1
- package/_cjs/core/Blobs.js +26 -34
- package/_cjs/core/Blobs.js.map +1 -1
- package/_cjs/core/Bytes.js +56 -13
- package/_cjs/core/Bytes.js.map +1 -1
- package/_cjs/core/Cbor.js +33 -18
- package/_cjs/core/Cbor.js.map +1 -1
- package/_cjs/core/FrameReceipt.js +6 -2
- package/_cjs/core/FrameReceipt.js.map +1 -1
- package/_cjs/core/Hex.js +54 -21
- package/_cjs/core/Hex.js.map +1 -1
- package/_cjs/core/Json.js +15 -2
- package/_cjs/core/Json.js.map +1 -1
- package/_cjs/core/Rlp.js +138 -94
- package/_cjs/core/Rlp.js.map +1 -1
- package/_cjs/core/RpcTransport.js +3 -1
- package/_cjs/core/RpcTransport.js.map +1 -1
- package/_cjs/core/Siwe.js +2 -2
- package/_cjs/core/Siwe.js.map +1 -1
- package/_cjs/core/Transaction.js +6 -3
- package/_cjs/core/Transaction.js.map +1 -1
- package/_cjs/core/TransactionReceipt.js +12 -4
- package/_cjs/core/TransactionReceipt.js.map +1 -1
- package/_cjs/core/TransactionRequest.js +6 -2
- package/_cjs/core/TransactionRequest.js.map +1 -1
- package/_cjs/core/TxEnvelopeEip4844.js +1 -1
- package/_cjs/core/TxEnvelopeEip4844.js.map +1 -1
- package/_cjs/core/TypedData.js +19 -8
- package/_cjs/core/TypedData.js.map +1 -1
- package/_cjs/core/internal/abiParameters.js +59 -18
- package/_cjs/core/internal/abiParameters.js.map +1 -1
- package/_cjs/core/internal/address.js +32 -0
- package/_cjs/core/internal/address.js.map +1 -0
- package/_cjs/core/internal/base58.js +11 -9
- package/_cjs/core/internal/base58.js.map +1 -1
- package/_cjs/core/internal/bytes.js +13 -22
- package/_cjs/core/internal/bytes.js.map +1 -1
- package/_cjs/core/internal/caches.js +1 -0
- package/_cjs/core/internal/caches.js.map +1 -1
- package/_cjs/core/internal/cursor.js +32 -10
- package/_cjs/core/internal/cursor.js.map +1 -1
- package/_cjs/core/internal/hex.js +3 -3
- package/_cjs/core/internal/hex.js.map +1 -1
- package/_cjs/core/internal/lru.js +6 -5
- package/_cjs/core/internal/lru.js.map +1 -1
- package/_cjs/core/internal/promise.js +3 -3
- package/_cjs/core/internal/promise.js.map +1 -1
- package/_cjs/erc6492/SignatureErc6492.js +1 -1
- package/_cjs/erc6492/SignatureErc6492.js.map +1 -1
- package/_cjs/tempo/SignatureEnvelope.js +7 -38
- package/_cjs/tempo/SignatureEnvelope.js.map +1 -1
- package/_cjs/tempo/Transaction.js +13 -7
- package/_cjs/tempo/Transaction.js.map +1 -1
- package/_cjs/tempo/TransactionRequest.js +23 -19
- package/_cjs/tempo/TransactionRequest.js.map +1 -1
- package/_cjs/tempo/TxEnvelopeTempo.js +23 -4
- package/_cjs/tempo/TxEnvelopeTempo.js.map +1 -1
- package/_cjs/tempo/ZoneId.js +3 -0
- package/_cjs/tempo/ZoneId.js.map +1 -1
- package/_cjs/tempo/internal/virtualMasterPool.js +12 -3
- package/_cjs/tempo/internal/virtualMasterPool.js.map +1 -1
- package/_cjs/tempo/internal/webauthnData.js +57 -0
- package/_cjs/tempo/internal/webauthnData.js.map +1 -0
- package/_cjs/version.js +1 -1
- package/_esm/core/AbiEvent.js +69 -0
- package/_esm/core/AbiEvent.js.map +1 -1
- package/_esm/core/AbiParameters.js +8 -2
- package/_esm/core/AbiParameters.js.map +1 -1
- package/_esm/core/Address.js +27 -21
- package/_esm/core/Address.js.map +1 -1
- package/_esm/core/Base58.js +16 -4
- package/_esm/core/Base58.js.map +1 -1
- package/_esm/core/Blobs.js +38 -39
- package/_esm/core/Blobs.js.map +1 -1
- package/_esm/core/Bytes.js +66 -13
- package/_esm/core/Bytes.js.map +1 -1
- package/_esm/core/Cbor.js +33 -17
- package/_esm/core/Cbor.js.map +1 -1
- package/_esm/core/FrameReceipt.js +6 -2
- package/_esm/core/FrameReceipt.js.map +1 -1
- package/_esm/core/Hex.js +70 -21
- package/_esm/core/Hex.js.map +1 -1
- package/_esm/core/Json.js +21 -2
- package/_esm/core/Json.js.map +1 -1
- package/_esm/core/Rlp.js +146 -97
- package/_esm/core/Rlp.js.map +1 -1
- package/_esm/core/RpcTransport.js +4 -1
- package/_esm/core/RpcTransport.js.map +1 -1
- package/_esm/core/Siwe.js +2 -2
- package/_esm/core/Siwe.js.map +1 -1
- package/_esm/core/Transaction.js +6 -3
- package/_esm/core/Transaction.js.map +1 -1
- package/_esm/core/TransactionReceipt.js +12 -4
- package/_esm/core/TransactionReceipt.js.map +1 -1
- package/_esm/core/TransactionRequest.js +6 -2
- package/_esm/core/TransactionRequest.js.map +1 -1
- package/_esm/core/TxEnvelopeEip4844.js +1 -1
- package/_esm/core/TxEnvelopeEip4844.js.map +1 -1
- package/_esm/core/TypedData.js +24 -8
- package/_esm/core/TypedData.js.map +1 -1
- package/_esm/core/internal/abiParameters.js +78 -18
- package/_esm/core/internal/abiParameters.js.map +1 -1
- package/_esm/core/internal/address.js +41 -0
- package/_esm/core/internal/address.js.map +1 -0
- package/_esm/core/internal/base58.js +15 -9
- package/_esm/core/internal/base58.js.map +1 -1
- package/_esm/core/internal/bytes.js +14 -22
- package/_esm/core/internal/bytes.js.map +1 -1
- package/_esm/core/internal/caches.js +1 -0
- package/_esm/core/internal/caches.js.map +1 -1
- package/_esm/core/internal/cursor.js +37 -10
- package/_esm/core/internal/cursor.js.map +1 -1
- package/_esm/core/internal/hex.js +5 -3
- package/_esm/core/internal/hex.js.map +1 -1
- package/_esm/core/internal/lru.js +7 -5
- package/_esm/core/internal/lru.js.map +1 -1
- package/_esm/core/internal/promise.js +4 -3
- package/_esm/core/internal/promise.js.map +1 -1
- package/_esm/erc6492/SignatureErc6492.js +1 -1
- package/_esm/erc6492/SignatureErc6492.js.map +1 -1
- package/_esm/tempo/SignatureEnvelope.js +7 -41
- package/_esm/tempo/SignatureEnvelope.js.map +1 -1
- package/_esm/tempo/Transaction.js +15 -7
- package/_esm/tempo/Transaction.js.map +1 -1
- package/_esm/tempo/TransactionRequest.js +25 -19
- package/_esm/tempo/TransactionRequest.js.map +1 -1
- package/_esm/tempo/TxEnvelopeTempo.js +30 -4
- package/_esm/tempo/TxEnvelopeTempo.js.map +1 -1
- package/_esm/tempo/ZoneId.js +7 -1
- package/_esm/tempo/ZoneId.js.map +1 -1
- package/_esm/tempo/internal/virtualMasterPool.js +16 -3
- package/_esm/tempo/internal/virtualMasterPool.js.map +1 -1
- package/_esm/tempo/internal/webauthnData.js +79 -0
- package/_esm/tempo/internal/webauthnData.js.map +1 -0
- package/_esm/version.js +1 -1
- package/_types/core/AbiEvent.d.ts +36 -1
- package/_types/core/AbiEvent.d.ts.map +1 -1
- package/_types/core/AbiParameters.d.ts +1 -1
- package/_types/core/AbiParameters.d.ts.map +1 -1
- package/_types/core/Address.d.ts.map +1 -1
- package/_types/core/Base58.d.ts.map +1 -1
- package/_types/core/Blobs.d.ts +2 -3
- package/_types/core/Blobs.d.ts.map +1 -1
- package/_types/core/Bytes.d.ts +2 -0
- package/_types/core/Bytes.d.ts.map +1 -1
- package/_types/core/Cbor.d.ts +13 -6
- package/_types/core/Cbor.d.ts.map +1 -1
- package/_types/core/FrameReceipt.d.ts.map +1 -1
- package/_types/core/Hex.d.ts +3 -1
- package/_types/core/Hex.d.ts.map +1 -1
- package/_types/core/Json.d.ts.map +1 -1
- package/_types/core/Rlp.d.ts +38 -9
- package/_types/core/Rlp.d.ts.map +1 -1
- package/_types/core/RpcTransport.d.ts.map +1 -1
- package/_types/core/Siwe.d.ts.map +1 -1
- package/_types/core/Transaction.d.ts.map +1 -1
- package/_types/core/TransactionReceipt.d.ts.map +1 -1
- package/_types/core/TransactionRequest.d.ts.map +1 -1
- package/_types/core/TypedData.d.ts.map +1 -1
- package/_types/core/internal/abiParameters.d.ts +5 -5
- package/_types/core/internal/abiParameters.d.ts.map +1 -1
- package/_types/core/internal/address.d.ts +14 -0
- package/_types/core/internal/address.d.ts.map +1 -0
- package/_types/core/internal/base58.d.ts.map +1 -1
- package/_types/core/internal/bytes.d.ts +1 -10
- package/_types/core/internal/bytes.d.ts.map +1 -1
- package/_types/core/internal/caches.d.ts +1 -0
- package/_types/core/internal/caches.d.ts.map +1 -1
- package/_types/core/internal/cursor.d.ts +7 -2
- package/_types/core/internal/cursor.d.ts.map +1 -1
- package/_types/core/internal/hex.d.ts.map +1 -1
- package/_types/core/internal/lru.d.ts.map +1 -1
- package/_types/core/internal/promise.d.ts.map +1 -1
- package/_types/erc6492/SignatureErc6492.d.ts +1 -1
- package/_types/erc6492/SignatureErc6492.d.ts.map +1 -1
- package/_types/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/_types/tempo/Transaction.d.ts.map +1 -1
- package/_types/tempo/TransactionRequest.d.ts.map +1 -1
- package/_types/tempo/TxEnvelopeTempo.d.ts.map +1 -1
- package/_types/tempo/ZoneId.d.ts +3 -1
- package/_types/tempo/ZoneId.d.ts.map +1 -1
- package/_types/tempo/internal/virtualMasterPool.d.ts.map +1 -1
- package/_types/tempo/internal/webauthnData.d.ts +26 -0
- package/_types/tempo/internal/webauthnData.d.ts.map +1 -0
- package/_types/version.d.ts +1 -1
- package/core/AbiEvent.ts +72 -0
- package/core/AbiParameters.ts +8 -1
- package/core/Address.ts +25 -20
- package/core/Base58.ts +15 -4
- package/core/Blobs.ts +47 -51
- package/core/Bytes.ts +68 -17
- package/core/Cbor.ts +33 -13
- package/core/FrameReceipt.ts +6 -2
- package/core/Hex.ts +79 -22
- package/core/Json.ts +23 -2
- package/core/Rlp.ts +184 -94
- package/core/RpcTransport.ts +4 -1
- package/core/Siwe.ts +2 -2
- package/core/Transaction.ts +6 -3
- package/core/TransactionReceipt.ts +13 -4
- package/core/TransactionRequest.ts +10 -6
- package/core/TxEnvelopeEip4844.ts +1 -1
- package/core/TypedData.ts +26 -8
- package/core/internal/abiParameters.ts +82 -23
- package/core/internal/address.ts +38 -0
- package/core/internal/base58.ts +14 -9
- package/core/internal/bytes.ts +13 -23
- package/core/internal/caches.ts +1 -0
- package/core/internal/cursor.ts +44 -16
- package/core/internal/hex.ts +5 -3
- package/core/internal/lru.ts +6 -7
- package/core/internal/promise.ts +5 -3
- package/erc6492/SignatureErc6492.ts +1 -1
- package/package.json +1 -1
- package/tempo/AccountSimulation.test.ts +1 -1
- package/tempo/SignatureEnvelope.test.ts +89 -1
- package/tempo/SignatureEnvelope.ts +7 -43
- package/tempo/SignaturePreAuthorized.test.ts +1 -1
- package/tempo/Transaction.ts +15 -9
- package/tempo/TransactionRequest.ts +31 -24
- package/tempo/TxEnvelopeTempo.test.ts +52 -0
- package/tempo/TxEnvelopeTempo.ts +32 -6
- package/tempo/ZoneId.test.ts +11 -0
- package/tempo/ZoneId.ts +7 -1
- package/tempo/internal/virtualMasterPool.ts +18 -4
- package/tempo/internal/webauthnData.ts +89 -0
- package/version.ts +1 -1
- package/_cjs/core/internal/uid.js +0 -17
- package/_cjs/core/internal/uid.js.map +0 -1
- package/_esm/core/internal/uid.js +0 -15
- package/_esm/core/internal/uid.js.map +0 -1
- package/_types/core/internal/uid.d.ts +0 -3
- package/_types/core/internal/uid.d.ts.map +0 -1
- package/core/internal/uid.ts +0 -15
package/core/Rlp.ts
CHANGED
|
@@ -4,6 +4,9 @@ import * as Hex from './Hex.js'
|
|
|
4
4
|
import * as Cursor from './internal/cursor.js'
|
|
5
5
|
import type { ExactPartial, RecursiveArray } from './internal/types.js'
|
|
6
6
|
|
|
7
|
+
/** Maximum nesting depth permitted when decoding an RLP value. */
|
|
8
|
+
const depthLimit = 1_024
|
|
9
|
+
|
|
7
10
|
/**
|
|
8
11
|
* Decodes a Recursive-Length Prefix (RLP) value into a {@link ox#Bytes.Bytes} value.
|
|
9
12
|
*
|
|
@@ -68,10 +71,12 @@ export function to<
|
|
|
68
71
|
return value as Bytes.Bytes
|
|
69
72
|
})()
|
|
70
73
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
const state: State = { bytes, position: 0 }
|
|
75
|
+
const result = decodeRlpCursor(state, to_)
|
|
76
|
+
|
|
77
|
+
// RLP payloads encode exactly one item (Yellow Paper, Appendix B).
|
|
78
|
+
if (state.position < bytes.length)
|
|
79
|
+
throw new TrailingBytesError({ count: bytes.length - state.position })
|
|
75
80
|
|
|
76
81
|
return result as to.ReturnType<to>
|
|
77
82
|
}
|
|
@@ -85,46 +90,65 @@ export declare namespace to {
|
|
|
85
90
|
type ErrorType =
|
|
86
91
|
| Bytes.fromHex.ErrorType
|
|
87
92
|
| decodeRlpCursor.ErrorType
|
|
88
|
-
| Cursor.create.ErrorType
|
|
89
93
|
| Hex.InvalidLengthError
|
|
94
|
+
| TrailingBytesError
|
|
90
95
|
| Errors.GlobalErrorType
|
|
91
96
|
}
|
|
92
97
|
|
|
93
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* Decoder position over the encoded bytes. A `Cursor` satisfies it, but the
|
|
100
|
+
* decoder only reads `bytes` and moves `position`.
|
|
101
|
+
*
|
|
102
|
+
* @internal
|
|
103
|
+
*/
|
|
104
|
+
type State = Pick<Cursor.Cursor, 'bytes' | 'position'>
|
|
94
105
|
|
|
95
106
|
/** @internal */
|
|
96
107
|
export function decodeRlpCursor<to extends 'Hex' | 'Bytes' = 'Hex'>(
|
|
97
|
-
cursor:
|
|
108
|
+
cursor: State,
|
|
98
109
|
to: to | 'Hex' | 'Bytes' | undefined = 'Hex',
|
|
110
|
+
depth = 0,
|
|
99
111
|
): decodeRlpCursor.ReturnType<to> {
|
|
100
|
-
if (
|
|
112
|
+
if (depth >= depthLimit)
|
|
113
|
+
throw new DepthLimitExceededError({ limit: depthLimit })
|
|
114
|
+
|
|
115
|
+
const { bytes } = cursor
|
|
116
|
+
if (bytes.length === 0)
|
|
101
117
|
return (
|
|
102
|
-
to === 'Hex' ? Hex.fromBytes(
|
|
118
|
+
to === 'Hex' ? Hex.fromBytes(bytes) : bytes
|
|
103
119
|
) as decodeRlpCursor.ReturnType<to>
|
|
104
120
|
|
|
105
|
-
|
|
106
|
-
|
|
121
|
+
assertPosition(bytes, cursor.position)
|
|
122
|
+
const prefix = bytes[cursor.position]!
|
|
123
|
+
if (prefix >= 0x80) cursor.position++
|
|
107
124
|
|
|
108
125
|
// bytes
|
|
109
126
|
if (prefix < 0xc0) {
|
|
110
127
|
const length = readLength(cursor, prefix, 0x80)
|
|
111
|
-
|
|
128
|
+
if (length > 0) assertPosition(bytes, cursor.position + length - 1)
|
|
129
|
+
const data = bytes.subarray(cursor.position, cursor.position + length)
|
|
130
|
+
cursor.position += length
|
|
112
131
|
// A single byte below `0x80` must be its own encoding (no length
|
|
113
132
|
// prefix); wrapping it in an explicit one-byte-length prefix is a
|
|
114
133
|
// non-canonical alternate encoding of the same value (Yellow Paper,
|
|
115
134
|
// Appendix B).
|
|
116
|
-
if (prefix >= 0x80 && length === 1 &&
|
|
135
|
+
if (prefix >= 0x80 && length === 1 && data[0]! < 0x80)
|
|
117
136
|
throw new NonCanonicalError({
|
|
118
|
-
reason: `single byte \`0x${
|
|
137
|
+
reason: `single byte \`0x${data[0]!.toString(16).padStart(2, '0')}\` is wrapped in an explicit length prefix instead of being encoded as itself`,
|
|
119
138
|
})
|
|
120
139
|
return (
|
|
121
|
-
to === 'Hex' ? Hex.fromBytes(
|
|
140
|
+
to === 'Hex' ? Hex.fromBytes(data) : data
|
|
122
141
|
) as decodeRlpCursor.ReturnType<to>
|
|
123
142
|
}
|
|
124
143
|
|
|
125
144
|
// list
|
|
126
145
|
const length = readLength(cursor, prefix, 0xc0)
|
|
127
|
-
return readList(
|
|
146
|
+
return readList(
|
|
147
|
+
cursor,
|
|
148
|
+
length,
|
|
149
|
+
to,
|
|
150
|
+
depth + 1,
|
|
151
|
+
) as {} as decodeRlpCursor.ReturnType<to>
|
|
128
152
|
}
|
|
129
153
|
|
|
130
154
|
/** @internal */
|
|
@@ -134,16 +158,14 @@ export declare namespace decodeRlpCursor {
|
|
|
134
158
|
| Hex.fromBytes.ErrorType
|
|
135
159
|
| readLength.ErrorType
|
|
136
160
|
| readList.ErrorType
|
|
161
|
+
| Cursor.PositionOutOfBoundsError
|
|
162
|
+
| DepthLimitExceededError
|
|
137
163
|
| NonCanonicalError
|
|
138
164
|
| Errors.GlobalErrorType
|
|
139
165
|
}
|
|
140
166
|
|
|
141
167
|
/** @internal */
|
|
142
|
-
export function readLength(
|
|
143
|
-
cursor: Cursor.Cursor,
|
|
144
|
-
prefix: number,
|
|
145
|
-
offset: number,
|
|
146
|
-
) {
|
|
168
|
+
export function readLength(cursor: State, prefix: number, offset: number) {
|
|
147
169
|
if (offset === 0x80 && prefix < 0x80) return 1
|
|
148
170
|
if (prefix <= offset + 55) return prefix - offset
|
|
149
171
|
// Long-form lengths must use the minimal number of length-bytes: a value
|
|
@@ -151,7 +173,7 @@ export function readLength(
|
|
|
151
173
|
// a longer form is a non-canonical alternate encoding of the same value
|
|
152
174
|
// (Yellow Paper, Appendix B).
|
|
153
175
|
if (prefix === offset + 55 + 1) {
|
|
154
|
-
const length = cursor
|
|
176
|
+
const length = readUint(cursor, 1)
|
|
155
177
|
if (length <= 55)
|
|
156
178
|
throw new NonCanonicalError({
|
|
157
179
|
reason: `length \`${length}\` fits in the short form and must not use a one-byte length prefix`,
|
|
@@ -159,7 +181,7 @@ export function readLength(
|
|
|
159
181
|
return length
|
|
160
182
|
}
|
|
161
183
|
if (prefix === offset + 55 + 2) {
|
|
162
|
-
const length = cursor
|
|
184
|
+
const length = readUint(cursor, 2)
|
|
163
185
|
if (length <= 0xff)
|
|
164
186
|
throw new NonCanonicalError({
|
|
165
187
|
reason: `length \`${length}\` fits in fewer length-bytes and must not use a two-byte length prefix`,
|
|
@@ -167,7 +189,7 @@ export function readLength(
|
|
|
167
189
|
return length
|
|
168
190
|
}
|
|
169
191
|
if (prefix === offset + 55 + 3) {
|
|
170
|
-
const length = cursor
|
|
192
|
+
const length = readUint(cursor, 3)
|
|
171
193
|
if (length <= 0xffff)
|
|
172
194
|
throw new NonCanonicalError({
|
|
173
195
|
reason: `length \`${length}\` fits in fewer length-bytes and must not use a three-byte length prefix`,
|
|
@@ -175,7 +197,7 @@ export function readLength(
|
|
|
175
197
|
return length
|
|
176
198
|
}
|
|
177
199
|
if (prefix === offset + 55 + 4) {
|
|
178
|
-
const length = cursor
|
|
200
|
+
const length = readUint(cursor, 4)
|
|
179
201
|
if (length <= 0xffffff)
|
|
180
202
|
throw new NonCanonicalError({
|
|
181
203
|
reason: `length \`${length}\` fits in fewer length-bytes and must not use a four-byte length prefix`,
|
|
@@ -187,30 +209,57 @@ export function readLength(
|
|
|
187
209
|
|
|
188
210
|
/** @internal */
|
|
189
211
|
export declare namespace readLength {
|
|
190
|
-
type ErrorType =
|
|
212
|
+
type ErrorType =
|
|
213
|
+
| Cursor.PositionOutOfBoundsError
|
|
214
|
+
| NonCanonicalError
|
|
215
|
+
| Errors.BaseError
|
|
216
|
+
| Errors.GlobalErrorType
|
|
191
217
|
}
|
|
192
218
|
|
|
193
219
|
/** @internal */
|
|
194
220
|
export function readList<to extends 'Hex' | 'Bytes'>(
|
|
195
|
-
cursor:
|
|
221
|
+
cursor: State,
|
|
196
222
|
length: number,
|
|
197
223
|
to: to | 'Hex' | 'Bytes',
|
|
224
|
+
depth = 0,
|
|
198
225
|
) {
|
|
199
226
|
const position = cursor.position
|
|
200
227
|
const value: decodeRlpCursor.ReturnType<to>[] = []
|
|
201
228
|
while (cursor.position - position < length)
|
|
202
|
-
value.push(decodeRlpCursor(cursor, to))
|
|
229
|
+
value.push(decodeRlpCursor(cursor, to, depth))
|
|
230
|
+
// Items must consume exactly the declared list length.
|
|
231
|
+
if (cursor.position - position !== length)
|
|
232
|
+
throw new ListBoundaryExceededError({
|
|
233
|
+
consumed: cursor.position - position,
|
|
234
|
+
declared: length,
|
|
235
|
+
})
|
|
203
236
|
return value
|
|
204
237
|
}
|
|
205
238
|
|
|
206
239
|
/** @internal */
|
|
207
240
|
export declare namespace readList {
|
|
208
|
-
type ErrorType =
|
|
241
|
+
type ErrorType =
|
|
242
|
+
| DepthLimitExceededError
|
|
243
|
+
| ListBoundaryExceededError
|
|
244
|
+
| Errors.GlobalErrorType
|
|
209
245
|
}
|
|
210
246
|
|
|
211
|
-
|
|
212
|
-
length
|
|
213
|
-
|
|
247
|
+
function assertPosition(bytes: Bytes.Bytes, position: number) {
|
|
248
|
+
if (position < 0 || position > bytes.length - 1)
|
|
249
|
+
throw new Cursor.PositionOutOfBoundsError({
|
|
250
|
+
length: bytes.length,
|
|
251
|
+
position,
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Reads a big-endian unsigned integer of up to 4 bytes.
|
|
256
|
+
function readUint(cursor: State, size: number) {
|
|
257
|
+
const { bytes, position } = cursor
|
|
258
|
+
assertPosition(bytes, position + size - 1)
|
|
259
|
+
let value = 0
|
|
260
|
+
for (let i = 0; i < size; i++) value = value * 256 + bytes[position + i]!
|
|
261
|
+
cursor.position += size
|
|
262
|
+
return value
|
|
214
263
|
}
|
|
215
264
|
|
|
216
265
|
/**
|
|
@@ -237,12 +286,15 @@ export function from<as extends 'Hex' | 'Bytes'>(
|
|
|
237
286
|
): from.ReturnType<as> {
|
|
238
287
|
const { as } = options
|
|
239
288
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
289
|
+
// Two passes without a per-node closure tree: `measure` decodes leaves and
|
|
290
|
+
// records list body lengths in visit order, and `write` reads both back in
|
|
291
|
+
// the same order into a pre-sized buffer.
|
|
292
|
+
const ctx: EncodeContext = { bodies: [], leaves: [] }
|
|
293
|
+
const bytes = new Uint8Array(measure(value, ctx))
|
|
294
|
+
write(value, bytes, ctx, { body: 0, leaf: 0, offset: 0 })
|
|
243
295
|
|
|
244
|
-
if (as === 'Hex') return Hex.fromBytes(
|
|
245
|
-
return
|
|
296
|
+
if (as === 'Hex') return Hex.fromBytes(bytes) as from.ReturnType<as>
|
|
297
|
+
return bytes as from.ReturnType<as>
|
|
246
298
|
}
|
|
247
299
|
|
|
248
300
|
export declare namespace from {
|
|
@@ -256,7 +308,6 @@ export declare namespace from {
|
|
|
256
308
|
| (as extends 'Hex' ? Hex.Hex : never)
|
|
257
309
|
|
|
258
310
|
type ErrorType =
|
|
259
|
-
| Cursor.create.ErrorType
|
|
260
311
|
| Hex.fromBytes.ErrorType
|
|
261
312
|
| Bytes.fromHex.ErrorType
|
|
262
313
|
| Errors.GlobalErrorType
|
|
@@ -332,71 +383,77 @@ export declare namespace fromHex {
|
|
|
332
383
|
// Internal
|
|
333
384
|
/////////////////////////////////////////////////////////////////////////////////
|
|
334
385
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
return getEncodableBytes(bytes as any)
|
|
386
|
+
type EncodeContext = {
|
|
387
|
+
/** Body length of each list, in visit order. */
|
|
388
|
+
bodies: number[]
|
|
389
|
+
/** Bytes of each leaf, in visit order. */
|
|
390
|
+
leaves: Bytes.Bytes[]
|
|
341
391
|
}
|
|
342
392
|
|
|
343
|
-
function
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
393
|
+
function measure(
|
|
394
|
+
value: RecursiveArray<Bytes.Bytes> | RecursiveArray<Hex.Hex>,
|
|
395
|
+
ctx: EncodeContext,
|
|
396
|
+
): number {
|
|
397
|
+
if (Array.isArray(value)) {
|
|
398
|
+
// Reserve this list's slot before its children's, in visit order.
|
|
399
|
+
const index = ctx.bodies.length
|
|
400
|
+
ctx.bodies.push(0)
|
|
401
|
+
let bodyLength = 0
|
|
402
|
+
for (let i = 0; i < value.length; i++) bodyLength += measure(value[i], ctx)
|
|
403
|
+
ctx.bodies[index] = bodyLength
|
|
348
404
|
if (bodyLength <= 55) return 1 + bodyLength
|
|
349
|
-
return 1 +
|
|
350
|
-
})()
|
|
351
|
-
|
|
352
|
-
return {
|
|
353
|
-
length,
|
|
354
|
-
encode(cursor: Cursor.Cursor) {
|
|
355
|
-
if (bodyLength <= 55) {
|
|
356
|
-
cursor.pushByte(0xc0 + bodyLength)
|
|
357
|
-
} else {
|
|
358
|
-
cursor.pushByte(0xc0 + 55 + sizeOfBodyLength)
|
|
359
|
-
if (sizeOfBodyLength === 1) cursor.pushUint8(bodyLength)
|
|
360
|
-
else if (sizeOfBodyLength === 2) cursor.pushUint16(bodyLength)
|
|
361
|
-
else if (sizeOfBodyLength === 3) cursor.pushUint24(bodyLength)
|
|
362
|
-
else cursor.pushUint32(bodyLength)
|
|
363
|
-
}
|
|
364
|
-
for (const { encode } of list) {
|
|
365
|
-
encode(cursor)
|
|
366
|
-
}
|
|
367
|
-
},
|
|
405
|
+
return 1 + getSizeOfLength(bodyLength) + bodyLength
|
|
368
406
|
}
|
|
369
|
-
}
|
|
370
407
|
|
|
371
|
-
function getEncodableBytes(bytesOrHex: Bytes.Bytes | Hex.Hex): Encodable {
|
|
372
408
|
const bytes =
|
|
373
|
-
typeof
|
|
374
|
-
|
|
409
|
+
typeof value === 'string'
|
|
410
|
+
? Bytes.fromHex(value as Hex.Hex)
|
|
411
|
+
: (value as Bytes.Bytes)
|
|
412
|
+
ctx.leaves.push(bytes)
|
|
375
413
|
const sizeOfBytesLength = getSizeOfLength(bytes.length)
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
})()
|
|
414
|
+
if (bytes.length === 1 && bytes[0]! < 0x80) return 1
|
|
415
|
+
if (bytes.length <= 55) return 1 + bytes.length
|
|
416
|
+
return 1 + sizeOfBytesLength + bytes.length
|
|
417
|
+
}
|
|
381
418
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
419
|
+
function write(
|
|
420
|
+
value: RecursiveArray<Bytes.Bytes> | RecursiveArray<Hex.Hex>,
|
|
421
|
+
out: Bytes.Bytes,
|
|
422
|
+
ctx: EncodeContext,
|
|
423
|
+
state: { body: number; leaf: number; offset: number },
|
|
424
|
+
) {
|
|
425
|
+
if (Array.isArray(value)) {
|
|
426
|
+
writePrefix(out, state, 0xc0, ctx.bodies[state.body++]!)
|
|
427
|
+
for (let i = 0; i < value.length; i++) write(value[i], out, ctx, state)
|
|
428
|
+
return
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const bytes = ctx.leaves[state.leaf++]!
|
|
432
|
+
if (bytes.length === 1 && bytes[0]! < 0x80) {
|
|
433
|
+
out[state.offset++] = bytes[0]!
|
|
434
|
+
return
|
|
435
|
+
}
|
|
436
|
+
writePrefix(out, state, 0x80, bytes.length)
|
|
437
|
+
out.set(bytes, state.offset)
|
|
438
|
+
state.offset += bytes.length
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function writePrefix(
|
|
442
|
+
out: Bytes.Bytes,
|
|
443
|
+
state: { offset: number },
|
|
444
|
+
offset: number,
|
|
445
|
+
length: number,
|
|
446
|
+
) {
|
|
447
|
+
if (length <= 55) {
|
|
448
|
+
out[state.offset++] = offset + length
|
|
449
|
+
return
|
|
399
450
|
}
|
|
451
|
+
const size = getSizeOfLength(length)
|
|
452
|
+
out[state.offset++] = offset + 55 + size
|
|
453
|
+
// Big-endian length in `size` bytes.
|
|
454
|
+
for (let i = size - 1, n = length; i >= 0; i--, n = Math.floor(n / 256))
|
|
455
|
+
out[state.offset + i] = n % 256
|
|
456
|
+
state.offset += size
|
|
400
457
|
}
|
|
401
458
|
|
|
402
459
|
function getSizeOfLength(length: number) {
|
|
@@ -407,6 +464,39 @@ function getSizeOfLength(length: number) {
|
|
|
407
464
|
throw new Errors.BaseError('Length is too large.')
|
|
408
465
|
}
|
|
409
466
|
|
|
467
|
+
/** Thrown when an RLP value nests deeper than the decode depth limit. */
|
|
468
|
+
export class DepthLimitExceededError extends Errors.BaseError {
|
|
469
|
+
override readonly name = 'Rlp.DepthLimitExceededError'
|
|
470
|
+
|
|
471
|
+
constructor({ limit }: { limit: number }) {
|
|
472
|
+
super(`RLP depth limit of \`${limit}\` exceeded.`)
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/** Thrown when RLP list items overrun the list's declared length. */
|
|
477
|
+
export class ListBoundaryExceededError extends Errors.BaseError {
|
|
478
|
+
override readonly name = 'Rlp.ListBoundaryExceededError'
|
|
479
|
+
|
|
480
|
+
constructor({ consumed, declared }: { consumed: number; declared: number }) {
|
|
481
|
+
super(
|
|
482
|
+
`RLP list items consumed \`${consumed}\` bytes but the list declared a length of \`${declared}\`.`,
|
|
483
|
+
)
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/** Thrown when an RLP payload contains bytes after the decoded item. */
|
|
488
|
+
export class TrailingBytesError extends Errors.BaseError {
|
|
489
|
+
override readonly name = 'Rlp.TrailingBytesError'
|
|
490
|
+
|
|
491
|
+
constructor({ count }: { count: number }) {
|
|
492
|
+
super(
|
|
493
|
+
`RLP payload encodes a single item, but \`${count}\` trailing ${
|
|
494
|
+
count === 1 ? 'byte remains' : 'bytes remain'
|
|
495
|
+
}.`,
|
|
496
|
+
)
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
410
500
|
/** Thrown when an RLP payload uses a non-canonical alternate encoding of a value. */
|
|
411
501
|
export class NonCanonicalError extends Errors.BaseError {
|
|
412
502
|
override readonly name = 'Rlp.NonCanonicalError'
|
package/core/RpcTransport.ts
CHANGED
|
@@ -202,7 +202,10 @@ export class HttpError extends Errors.BaseError {
|
|
|
202
202
|
metaMessages: [
|
|
203
203
|
`Status: ${response.status}`,
|
|
204
204
|
`URL: ${getUrl(url)}`,
|
|
205
|
-
body
|
|
205
|
+
// The request body is usually already JSON.
|
|
206
|
+
body
|
|
207
|
+
? `Body: ${typeof body === 'string' ? body : JSON.stringify(body)}`
|
|
208
|
+
: undefined,
|
|
206
209
|
],
|
|
207
210
|
})
|
|
208
211
|
}
|
package/core/Siwe.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Address from './Address.js'
|
|
2
2
|
import * as Errors from './Errors.js'
|
|
3
|
+
import * as Hex from './Hex.js'
|
|
3
4
|
import type { ExactPartial } from './internal/types.js'
|
|
4
|
-
import { uid } from './internal/uid.js'
|
|
5
5
|
|
|
6
6
|
export const domainRegex =
|
|
7
7
|
/^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+(?:[a-zA-Z]{2,63}|[xX][nN]--[a-zA-Z0-9-]{0,58}[a-zA-Z0-9])(:[0-9]{1,5})?$/
|
|
@@ -285,7 +285,7 @@ export declare namespace createMessage {
|
|
|
285
285
|
* @returns Random nonce.
|
|
286
286
|
*/
|
|
287
287
|
export function generateNonce(): string {
|
|
288
|
-
return
|
|
288
|
+
return Hex.random(48).slice(2)
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
/**
|
package/core/Transaction.ts
CHANGED
|
@@ -389,8 +389,9 @@ export function fromRpc<
|
|
|
389
389
|
if (transaction.maxPriorityFeePerGas)
|
|
390
390
|
transaction_.maxPriorityFeePerGas = BigInt(transaction.maxPriorityFeePerGas)
|
|
391
391
|
if (transaction.type)
|
|
392
|
-
transaction_.type =
|
|
393
|
-
(fromRpcType as any)[transaction.type]
|
|
392
|
+
transaction_.type = Object.hasOwn(fromRpcType, transaction.type)
|
|
393
|
+
? (fromRpcType as any)[transaction.type]
|
|
394
|
+
: transaction.type
|
|
394
395
|
if (signature) transaction_.v = Signature.yParityToV(signature.yParity)
|
|
395
396
|
|
|
396
397
|
return transaction_ as never
|
|
@@ -467,7 +468,9 @@ export function toRpc<pending extends boolean = false>(
|
|
|
467
468
|
rpc.transactionIndex = transaction.transactionIndex
|
|
468
469
|
? Hex.fromNumber(transaction.transactionIndex)
|
|
469
470
|
: null
|
|
470
|
-
rpc.type = (toRpcType
|
|
471
|
+
rpc.type = Object.hasOwn(toRpcType, transaction.type)
|
|
472
|
+
? (toRpcType as any)[transaction.type]
|
|
473
|
+
: transaction.type
|
|
471
474
|
rpc.value = Hex.fromNumber(transaction.value ?? 0n)
|
|
472
475
|
|
|
473
476
|
if (transaction.type === 'eip8141' && transaction.nonceKeys !== undefined)
|
|
@@ -266,9 +266,14 @@ export function fromRpc<const receipt extends Rpc | null>(
|
|
|
266
266
|
effectiveGasPrice: BigInt(receipt.effectiveGasPrice ?? 0n),
|
|
267
267
|
gasUsed: BigInt(receipt.gasUsed ?? 0n),
|
|
268
268
|
logs: receipt.logs.map((log) => Log.fromRpc(log, { pending: false })),
|
|
269
|
-
status: fromRpcStatus
|
|
269
|
+
status: Object.hasOwn(fromRpcStatus, receipt.status)
|
|
270
|
+
? fromRpcStatus[receipt.status]
|
|
271
|
+
: (undefined as never),
|
|
270
272
|
transactionIndex: Number(receipt.transactionIndex ?? 0),
|
|
271
|
-
type:
|
|
273
|
+
type:
|
|
274
|
+
(Object.hasOwn(fromRpcType, receipt.type) &&
|
|
275
|
+
(fromRpcType as any)[receipt.type]) ||
|
|
276
|
+
receipt.type,
|
|
272
277
|
} as never
|
|
273
278
|
}
|
|
274
279
|
|
|
@@ -354,11 +359,15 @@ export function toRpc(receipt: TransactionReceipt): Rpc {
|
|
|
354
359
|
logs: receipt.logs.map(Log.toRpc as never),
|
|
355
360
|
logsBloom: receipt.logsBloom,
|
|
356
361
|
root: receipt.root,
|
|
357
|
-
status: toRpcStatus
|
|
362
|
+
status: Object.hasOwn(toRpcStatus, receipt.status)
|
|
363
|
+
? toRpcStatus[receipt.status]
|
|
364
|
+
: (undefined as never),
|
|
358
365
|
to: receipt.to,
|
|
359
366
|
transactionHash: receipt.transactionHash,
|
|
360
367
|
transactionIndex: Hex.fromNumber(receipt.transactionIndex),
|
|
361
|
-
type: (toRpcType
|
|
368
|
+
type: Object.hasOwn(toRpcType, receipt.type)
|
|
369
|
+
? (toRpcType as any)[receipt.type]
|
|
370
|
+
: receipt.type,
|
|
362
371
|
}
|
|
363
372
|
}
|
|
364
373
|
|
|
@@ -114,9 +114,11 @@ export function fromRpc(request: Rpc): TransactionRequest {
|
|
|
114
114
|
request_.nonceKeys = FrameNonce.fromRpc(request.nonceKeys, request.nonce)
|
|
115
115
|
if (typeof request.type !== 'undefined')
|
|
116
116
|
request_.type =
|
|
117
|
-
Transaction.fromRpcType
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
(Object.hasOwn(Transaction.fromRpcType, request.type) &&
|
|
118
|
+
Transaction.fromRpcType[
|
|
119
|
+
request.type as keyof typeof Transaction.fromRpcType
|
|
120
|
+
]) ||
|
|
121
|
+
request.type
|
|
120
122
|
if (typeof request.value !== 'undefined')
|
|
121
123
|
request_.value = Hex.toBigInt(request.value)
|
|
122
124
|
|
|
@@ -222,9 +224,11 @@ export function toRpc(request: TransactionRequest): Rpc {
|
|
|
222
224
|
if (typeof request.to !== 'undefined') request_rpc.to = request.to
|
|
223
225
|
if (typeof request.type !== 'undefined')
|
|
224
226
|
request_rpc.type =
|
|
225
|
-
Transaction.toRpcType
|
|
226
|
-
|
|
227
|
-
|
|
227
|
+
(Object.hasOwn(Transaction.toRpcType, request.type) &&
|
|
228
|
+
Transaction.toRpcType[
|
|
229
|
+
request.type as keyof typeof Transaction.toRpcType
|
|
230
|
+
]) ||
|
|
231
|
+
request.type
|
|
228
232
|
if (typeof request.value !== 'undefined')
|
|
229
233
|
request_rpc.value = Hex.fromNumber(request.value)
|
|
230
234
|
|
|
@@ -79,9 +79,9 @@ export function assert(envelope: PartialBy<TxEnvelopeEip4844, 'type'>) {
|
|
|
79
79
|
throw new Blobs.EmptyBlobVersionedHashesError()
|
|
80
80
|
for (const hash of blobVersionedHashes) {
|
|
81
81
|
const size = Hex.size(hash)
|
|
82
|
-
const version = Hex.toNumber(Hex.slice(hash, 0, 1))
|
|
83
82
|
if (size !== 32)
|
|
84
83
|
throw new Blobs.InvalidVersionedHashSizeError({ hash, size })
|
|
84
|
+
const version = Hex.toNumber(Hex.slice(hash, 0, 1))
|
|
85
85
|
if (version !== Kzg.versionedHashVersion)
|
|
86
86
|
throw new Blobs.InvalidVersionedHashVersionError({
|
|
87
87
|
hash,
|
package/core/TypedData.ts
CHANGED
|
@@ -5,6 +5,7 @@ import * as Bytes from './Bytes.js'
|
|
|
5
5
|
import * as Errors from './Errors.js'
|
|
6
6
|
import * as Hash from './Hash.js'
|
|
7
7
|
import * as Hex from './Hex.js'
|
|
8
|
+
import { caches } from './internal/caches.js'
|
|
8
9
|
import type { Compute } from './internal/types.js'
|
|
9
10
|
import * as Json from './Json.js'
|
|
10
11
|
import * as Solidity from './Solidity.js'
|
|
@@ -169,7 +170,8 @@ export function assert<
|
|
|
169
170
|
|
|
170
171
|
// Validate message types.
|
|
171
172
|
if (primaryType !== 'EIP712Domain') {
|
|
172
|
-
if (types
|
|
173
|
+
if (Object.hasOwn(types, primaryType) && types[primaryType])
|
|
174
|
+
validateData(types[primaryType], message)
|
|
173
175
|
else throw new InvalidPrimaryTypeError({ primaryType, types })
|
|
174
176
|
}
|
|
175
177
|
}
|
|
@@ -355,7 +357,7 @@ export function encodeType(value: encodeType.Value): string {
|
|
|
355
357
|
|
|
356
358
|
const deps = [primaryType, ...Array.from(unsortedDeps).sort()]
|
|
357
359
|
for (const type of deps) {
|
|
358
|
-
result += `${type}(${(types[type]
|
|
360
|
+
result += `${type}(${((Object.hasOwn(types, type) && types[type]) || [])
|
|
359
361
|
.map(({ name, type: t }) => `${t} ${name}`)
|
|
360
362
|
.join(',')})`
|
|
361
363
|
}
|
|
@@ -644,7 +646,7 @@ export function serialize<
|
|
|
644
646
|
|
|
645
647
|
const message = (() => {
|
|
646
648
|
if (primaryType === 'EIP712Domain') return undefined
|
|
647
|
-
if (!types[primaryType]) return {}
|
|
649
|
+
if (!Object.hasOwn(types, primaryType) || !types[primaryType]) return {}
|
|
648
650
|
return normalizeData(types[primaryType], message_)
|
|
649
651
|
})()
|
|
650
652
|
|
|
@@ -790,7 +792,8 @@ export function encodeData(value: {
|
|
|
790
792
|
const encodedTypes: AbiParameters.Parameter[] = [{ type: 'bytes32' }]
|
|
791
793
|
const encodedValues: unknown[] = [hashType({ primaryType, types })]
|
|
792
794
|
|
|
793
|
-
|
|
795
|
+
const fields = (Object.hasOwn(types, primaryType) && types[primaryType]) || []
|
|
796
|
+
for (const field of fields) {
|
|
794
797
|
const [type, value] = encodeField({
|
|
795
798
|
types,
|
|
796
799
|
name: field.name,
|
|
@@ -813,14 +816,25 @@ export declare namespace encodeData {
|
|
|
813
816
|
| Errors.GlobalErrorType
|
|
814
817
|
}
|
|
815
818
|
|
|
819
|
+
/** Longest encoded type kept in the type-hash cache. */
|
|
820
|
+
const typeHashCacheMaxLength = 4_096
|
|
821
|
+
|
|
816
822
|
/** @internal */
|
|
817
823
|
export function hashType(value: {
|
|
818
824
|
primaryType: string
|
|
819
825
|
types: TypedData
|
|
820
826
|
}): Hex.Hex {
|
|
821
827
|
const { primaryType, types } = value
|
|
822
|
-
|
|
823
|
-
|
|
828
|
+
// Keyed by the encoded type, so equal struct definitions share one hash
|
|
829
|
+
// across calls, whichever object their types came from.
|
|
830
|
+
const type = encodeType({ primaryType, types })
|
|
831
|
+
const cached = caches.typeHash.get(type)
|
|
832
|
+
if (cached) return cached
|
|
833
|
+
const hash = Hash.keccak256(Hex.fromString(type))
|
|
834
|
+
// The cache is bounded by entries, not bytes, so only cache encoded types of
|
|
835
|
+
// ordinary size: retained memory then stays bounded whatever types are passed.
|
|
836
|
+
if (type.length <= typeHashCacheMaxLength) caches.typeHash.set(type, hash)
|
|
837
|
+
return hash
|
|
824
838
|
}
|
|
825
839
|
|
|
826
840
|
/** @internal */
|
|
@@ -841,7 +855,7 @@ export function encodeField(properties: {
|
|
|
841
855
|
}): [type: AbiParameters.Parameter, value: Hex.Hex] {
|
|
842
856
|
let { types, name, type, value } = properties
|
|
843
857
|
|
|
844
|
-
if (types[type] !== undefined)
|
|
858
|
+
if (Object.hasOwn(types, type) && types[type] !== undefined)
|
|
845
859
|
return [
|
|
846
860
|
{ type: 'bytes32' },
|
|
847
861
|
Hash.keccak256(encodeData({ data: value, primaryType: type, types })),
|
|
@@ -907,7 +921,11 @@ export function findTypeDependencies(
|
|
|
907
921
|
): Set<string> {
|
|
908
922
|
const { primaryType: primaryType_, types } = value
|
|
909
923
|
const primaryType = primaryType_.replace(arraySuffixRegex, '')
|
|
910
|
-
if (
|
|
924
|
+
if (
|
|
925
|
+
results.has(primaryType) ||
|
|
926
|
+
!Object.hasOwn(types, primaryType) ||
|
|
927
|
+
types[primaryType] === undefined
|
|
928
|
+
)
|
|
911
929
|
return results
|
|
912
930
|
|
|
913
931
|
results.add(primaryType)
|