ox 0.14.67 → 0.14.69
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 +62 -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/Authorization.js +2 -0
- package/_cjs/core/Authorization.js.map +1 -1
- package/_cjs/core/Base58.js +14 -4
- package/_cjs/core/Base58.js.map +1 -1
- package/_cjs/core/BinaryStateTree.js +1 -1
- package/_cjs/core/BinaryStateTree.js.map +1 -1
- package/_cjs/core/Blobs.js +26 -34
- package/_cjs/core/Blobs.js.map +1 -1
- package/_cjs/core/Block.js +1 -0
- package/_cjs/core/Block.js.map +1 -1
- package/_cjs/core/BlockOverrides.js +1 -1
- package/_cjs/core/BlockOverrides.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 +35 -9
- package/_cjs/core/Siwe.js.map +1 -1
- package/_cjs/core/Transaction.js +10 -4
- 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/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/version.js +1 -1
- package/_esm/core/AbiError.js +2 -2
- package/_esm/core/AbiEvent.js +71 -2
- 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/Authorization.js +3 -0
- package/_esm/core/Authorization.js.map +1 -1
- package/_esm/core/Base58.js +16 -4
- package/_esm/core/Base58.js.map +1 -1
- package/_esm/core/BinaryStateTree.js +3 -1
- package/_esm/core/BinaryStateTree.js.map +1 -1
- package/_esm/core/Blobs.js +40 -41
- package/_esm/core/Blobs.js.map +1 -1
- package/_esm/core/Block.js +1 -0
- package/_esm/core/Block.js.map +1 -1
- package/_esm/core/BlockOverrides.js +3 -2
- package/_esm/core/BlockOverrides.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/Ens.js +1 -1
- package/_esm/core/FrameReceipt.js +6 -2
- package/_esm/core/FrameReceipt.js.map +1 -1
- package/_esm/core/Hash.js +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 +40 -10
- package/_esm/core/Siwe.js.map +1 -1
- package/_esm/core/Transaction.js +11 -4
- 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 +26 -10
- 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/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/version.js +1 -1
- package/_types/core/AbiError.d.ts +3 -3
- package/_types/core/AbiEvent.d.ts +38 -3
- 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/Authorization.d.ts.map +1 -1
- package/_types/core/Base58.d.ts.map +1 -1
- package/_types/core/Blobs.d.ts +4 -5
- package/_types/core/Blobs.d.ts.map +1 -1
- package/_types/core/Block.d.ts +2 -0
- package/_types/core/Block.d.ts.map +1 -1
- package/_types/core/BlockOverrides.d.ts +2 -1
- package/_types/core/BlockOverrides.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/Ens.d.ts +1 -1
- package/_types/core/FrameReceipt.d.ts.map +1 -1
- package/_types/core/Hash.d.ts +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 +1 -0
- 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 +2 -2
- 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/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/version.d.ts +1 -1
- package/core/AbiError.ts +3 -3
- package/core/AbiEvent.ts +74 -2
- package/core/AbiParameters.ts +8 -1
- package/core/Address.ts +25 -20
- package/core/Authorization.ts +3 -0
- package/core/Base58.ts +15 -4
- package/core/BinaryStateTree.ts +4 -1
- package/core/Blobs.ts +49 -53
- package/core/Block.ts +3 -0
- package/core/BlockOverrides.ts +3 -2
- package/core/Bytes.ts +68 -17
- package/core/Cbor.ts +33 -13
- package/core/Ens.ts +1 -1
- package/core/FrameReceipt.ts +6 -2
- package/core/Hash.ts +1 -1
- 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 +41 -10
- package/core/Transaction.ts +11 -4
- package/core/TransactionReceipt.ts +13 -4
- package/core/TransactionRequest.ts +10 -6
- package/core/TxEnvelopeEip4844.ts +1 -1
- package/core/TypedData.ts +28 -10
- 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/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/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})?$/
|
|
@@ -13,11 +13,10 @@ export const localhostRegex = /^localhost(:[0-9]{1,5})?$/
|
|
|
13
13
|
|
|
14
14
|
export const nonceRegex = /^[a-zA-Z0-9]{8,}$/
|
|
15
15
|
|
|
16
|
-
export const schemeRegex = /^([a-zA-Z][a-zA-Z0-9
|
|
16
|
+
export const schemeRegex = /^([a-zA-Z][a-zA-Z0-9+\-.]*)$/
|
|
17
17
|
|
|
18
|
-
// https://regexr.com/80gdj
|
|
19
18
|
export const prefixRegex =
|
|
20
|
-
/^(?:(?<scheme>[a-zA-Z][a-zA-Z0-9
|
|
19
|
+
/^(?:(?<scheme>[a-zA-Z][a-zA-Z0-9+\-.]*):\/\/)?(?<domain>(?:\[[^\]\s@[]+\]|[a-zA-Z0-9+-.]*)(?::[0-9]{1,5})?) (?:wants you to sign in with your Ethereum account:\n)(?<address>0x[a-fA-F0-9]{40})\n\n(?:(?<statement>.*)\n\n)?/
|
|
21
20
|
|
|
22
21
|
// https://regexr.com/80gf9
|
|
23
22
|
export const suffixRegex =
|
|
@@ -26,6 +25,11 @@ export const suffixRegex =
|
|
|
26
25
|
// Matches `suffixRegex` from the start of the input to its end.
|
|
27
26
|
const anchoredSuffixRegex = new RegExp(`^(?:${suffixRegex.source})$`)
|
|
28
27
|
|
|
28
|
+
// An IP literal (IPv6 or IPvFuture) `domain` with an optional port. The
|
|
29
|
+
// literal itself is checked by `isAuthority`. `@` and `[` are excluded so a
|
|
30
|
+
// userinfo authority such as `[evil.com@[::1]` cannot pass as a literal.
|
|
31
|
+
const domainIpLiteralRegex = /^\[[^\]\s@[]+\](?::[0-9]{1,5})?$/
|
|
32
|
+
|
|
29
33
|
// URI validation (see `isUri`).
|
|
30
34
|
const uriIllegalCharacterRegex = /[^a-z0-9:/?#[\]@!$&'()*+,;=.\-_~%]/i
|
|
31
35
|
const uriInvalidEscapeRegex = /%[^0-9a-f]/i
|
|
@@ -33,6 +37,10 @@ const uriIncompleteEscapeRegex = /%[0-9a-f](:?[^0-9a-f]|$)/i
|
|
|
33
37
|
const uriSchemeRegex = /^[a-z][a-z0-9+\-.]*$/
|
|
34
38
|
const uriPartsRegex =
|
|
35
39
|
/(?:([^:/?#]+):)?(?:\/\/([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/
|
|
40
|
+
const authorityHostRegex = /^(?:[a-z0-9._~!$&'()*+,;=:%-]*@)?(.*)$/i
|
|
41
|
+
const authorityIpLiteralRegex = /^\[([^\]]+)\](?::\d*)?$/
|
|
42
|
+
const authorityIpFutureRegex = /^v[0-9a-f]+\.[a-z0-9._~!$&'()*+,;=:-]+$/i
|
|
43
|
+
const authorityRegNameRegex = /^(?:[a-z0-9._~!$&'()*+,;=%-]*)(?::\d*)?$/i
|
|
36
44
|
|
|
37
45
|
/** [EIP-4361](https://eips.ethereum.org/EIPS/eip-4361) message fields. */
|
|
38
46
|
export type Message = {
|
|
@@ -151,7 +159,8 @@ export function createMessage(value: Message): string {
|
|
|
151
159
|
!(
|
|
152
160
|
domainRegex.test(domain) ||
|
|
153
161
|
ipRegex.test(domain) ||
|
|
154
|
-
localhostRegex.test(domain)
|
|
162
|
+
localhostRegex.test(domain) ||
|
|
163
|
+
(domainIpLiteralRegex.test(domain) && isAuthority(domain))
|
|
155
164
|
)
|
|
156
165
|
)
|
|
157
166
|
throw new InvalidMessageFieldError({
|
|
@@ -205,11 +214,12 @@ export function createMessage(value: Message): string {
|
|
|
205
214
|
],
|
|
206
215
|
})
|
|
207
216
|
const statement = value.statement
|
|
208
|
-
|
|
217
|
+
// `parseMessage` reads the statement with `.`, which stops at these.
|
|
218
|
+
if (statement && /[\n\r\u2028\u2029]/.test(statement))
|
|
209
219
|
throw new InvalidMessageFieldError({
|
|
210
220
|
field: 'statement',
|
|
211
221
|
metaMessages: [
|
|
212
|
-
"- Statement must not include '\\n'.",
|
|
222
|
+
"- Statement must not include a line break ('\\n', '\\r', '\\u2028' or '\\u2029').",
|
|
213
223
|
'',
|
|
214
224
|
`Provided value: ${statement}`,
|
|
215
225
|
],
|
|
@@ -285,7 +295,7 @@ export declare namespace createMessage {
|
|
|
285
295
|
* @returns Random nonce.
|
|
286
296
|
*/
|
|
287
297
|
export function generateNonce(): string {
|
|
288
|
-
return
|
|
298
|
+
return Hex.random(48).slice(2)
|
|
289
299
|
}
|
|
290
300
|
|
|
291
301
|
/**
|
|
@@ -320,11 +330,12 @@ export function isUri(value: string): false | string {
|
|
|
320
330
|
const fragment = splitted[5]
|
|
321
331
|
|
|
322
332
|
// scheme and path are required, though the path can be empty
|
|
323
|
-
if (!(scheme?.length && path
|
|
333
|
+
if (!(scheme?.length && path !== undefined)) return false
|
|
324
334
|
|
|
325
335
|
// if authority is present, the path must be empty or begin with a /
|
|
326
336
|
if (authority?.length) {
|
|
327
337
|
if (!(path.length === 0 || /^\//.test(path))) return false
|
|
338
|
+
if (!isAuthority(authority)) return false
|
|
328
339
|
} else {
|
|
329
340
|
// if authority is not present, the path must not start with //
|
|
330
341
|
if (/^\/\//.test(path)) return false
|
|
@@ -346,6 +357,24 @@ export function isUri(value: string): false | string {
|
|
|
346
357
|
return out
|
|
347
358
|
}
|
|
348
359
|
|
|
360
|
+
function isAuthority(value: string) {
|
|
361
|
+
const host = value.match(authorityHostRegex)?.[1]
|
|
362
|
+
if (host === undefined) return false
|
|
363
|
+
|
|
364
|
+
const ipLiteral = host.match(authorityIpLiteralRegex)?.[1]
|
|
365
|
+
if (ipLiteral) {
|
|
366
|
+
if (authorityIpFutureRegex.test(ipLiteral)) return true
|
|
367
|
+
try {
|
|
368
|
+
new URL(`http://[${ipLiteral}]`)
|
|
369
|
+
return true
|
|
370
|
+
} catch {
|
|
371
|
+
return false
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return authorityRegNameRegex.test(host)
|
|
376
|
+
}
|
|
377
|
+
|
|
349
378
|
function splitUri(value: string) {
|
|
350
379
|
return value.match(uriPartsRegex)!
|
|
351
380
|
}
|
|
@@ -469,7 +498,8 @@ export function validateMessage(value: validateMessage.Value): boolean {
|
|
|
469
498
|
|
|
470
499
|
if (domain && message.domain !== domain) return false
|
|
471
500
|
if (nonce && message.nonce !== nonce) return false
|
|
472
|
-
if
|
|
501
|
+
// EIP-4361: if `scheme` is not specified, HTTPS is assumed by default.
|
|
502
|
+
if (scheme && (message.scheme ?? 'https') !== scheme) return false
|
|
473
503
|
|
|
474
504
|
// EIP-4361 requires `nonce = 8*( ALPHA / DIGIT )` and `version = "1"`.
|
|
475
505
|
if (message.nonce !== undefined && !nonceRegex.test(message.nonce))
|
|
@@ -509,6 +539,7 @@ export declare namespace validateMessage {
|
|
|
509
539
|
nonce?: string | undefined
|
|
510
540
|
/**
|
|
511
541
|
* [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986#section-3.1) URI scheme to check against.
|
|
542
|
+
* If the message omits `scheme`, `https` is assumed ([EIP-4361](https://eips.ethereum.org/EIPS/eip-4361)).
|
|
512
543
|
*/
|
|
513
544
|
scheme?: string | undefined
|
|
514
545
|
/**
|
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)
|
|
@@ -495,8 +498,12 @@ export function toRpc<pending extends boolean = false>(
|
|
|
495
498
|
rpc.r = Hex.fromNumber(transaction.r, { size: 32 })
|
|
496
499
|
if (typeof transaction.s === 'bigint')
|
|
497
500
|
rpc.s = Hex.fromNumber(transaction.s, { size: 32 })
|
|
501
|
+
// Legacy EIP-155 `v` is unsized; typed transactions keep a single byte.
|
|
498
502
|
if (typeof transaction.v === 'number')
|
|
499
|
-
rpc.v =
|
|
503
|
+
rpc.v =
|
|
504
|
+
transaction.type === 'legacy'
|
|
505
|
+
? Hex.fromNumber(transaction.v)
|
|
506
|
+
: Hex.fromNumber(transaction.v, { size: 1 })
|
|
500
507
|
if (typeof transaction.yParity === 'number')
|
|
501
508
|
rpc.yParity = transaction.yParity === 0 ? '0x0' : '0x1'
|
|
502
509
|
|
|
@@ -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
|
|