ox 1.8.18 → 1.8.20
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 +34 -0
- package/dist/core/AbiError.d.ts +3 -3
- package/dist/core/AbiError.js +2 -2
- package/dist/core/AbiEvent.d.ts +2 -2
- package/dist/core/AbiEvent.js +2 -2
- package/dist/core/Authorization.d.ts.map +1 -1
- package/dist/core/Authorization.js +6 -3
- package/dist/core/Authorization.js.map +1 -1
- package/dist/core/BinaryStateTree.js +3 -1
- package/dist/core/BinaryStateTree.js.map +1 -1
- package/dist/core/Blobs.d.ts +2 -2
- package/dist/core/Blobs.js +2 -2
- package/dist/core/Block.d.ts +2 -0
- package/dist/core/Block.d.ts.map +1 -1
- package/dist/core/Block.js +1 -0
- package/dist/core/Block.js.map +1 -1
- package/dist/core/BlockOverrides.d.ts +3 -2
- package/dist/core/BlockOverrides.d.ts.map +1 -1
- package/dist/core/BlockOverrides.js +4 -2
- package/dist/core/BlockOverrides.js.map +1 -1
- package/dist/core/Ens.d.ts +1 -1
- package/dist/core/Ens.js +1 -1
- package/dist/core/Hash.d.ts +1 -1
- package/dist/core/Hash.js +1 -1
- package/dist/core/Siwe.d.ts +1 -0
- package/dist/core/Siwe.d.ts.map +1 -1
- package/dist/core/Siwe.js +15 -8
- package/dist/core/Siwe.js.map +1 -1
- package/dist/core/Transaction.d.ts.map +1 -1
- package/dist/core/Transaction.js +5 -1
- package/dist/core/Transaction.js.map +1 -1
- package/dist/core/TypedData.d.ts +2 -2
- package/dist/core/TypedData.js +2 -2
- package/dist/core/internal/ens.d.ts +1 -1
- package/dist/core/internal/ens.d.ts.map +1 -1
- package/dist/core/internal/ens.js +1 -1
- package/dist/core/internal/ens.js.map +1 -1
- package/dist/zod/Authorization.d.ts +14 -14
- package/dist/zod/Authorization.d.ts.map +1 -1
- package/dist/zod/Authorization.js +9 -2
- package/dist/zod/Authorization.js.map +1 -1
- package/dist/zod/Block.d.ts +12 -6
- package/dist/zod/Block.d.ts.map +1 -1
- package/dist/zod/Block.js +1 -0
- package/dist/zod/Block.js.map +1 -1
- package/dist/zod/BlockOverrides.d.ts.map +1 -1
- package/dist/zod/BlockOverrides.js +15 -4
- package/dist/zod/BlockOverrides.js.map +1 -1
- package/dist/zod/RpcSchema.d.ts +58 -46
- package/dist/zod/RpcSchema.d.ts.map +1 -1
- package/dist/zod/Signature.d.ts.map +1 -1
- package/dist/zod/Signature.js +2 -1
- package/dist/zod/Signature.js.map +1 -1
- package/dist/zod/Transaction.d.ts +12 -12
- package/dist/zod/TransactionEnvelope.d.ts +8 -8
- package/dist/zod/TransactionRequest.d.ts +4 -4
- package/dist/zod/TxEnvelopeEip7702.d.ts +8 -8
- package/dist/zod/internal/rpcSchemas/Eth.d.ts +58 -46
- package/dist/zod/internal/rpcSchemas/Eth.d.ts.map +1 -1
- package/dist/zod/internal/rpcSchemas/Wallet.d.ts +4 -4
- package/dist/zod/tempo/RpcSchemaTempo.d.ts +16 -8
- package/dist/zod/tempo/RpcSchemaTempo.d.ts.map +1 -1
- package/dist/zod/tempo/Transaction.d.ts +6 -6
- package/package.json +1 -1
- package/src/core/AbiError.ts +3 -3
- package/src/core/AbiEvent.ts +2 -2
- package/src/core/Authorization.ts +6 -3
- package/src/core/BinaryStateTree.ts +4 -1
- package/src/core/Blobs.ts +2 -2
- package/src/core/Block.ts +3 -0
- package/src/core/BlockOverrides.ts +7 -3
- package/src/core/Ens.ts +1 -1
- package/src/core/Hash.ts +1 -1
- package/src/core/Siwe.ts +18 -8
- package/src/core/Transaction.ts +5 -1
- package/src/core/TypedData.ts +2 -2
- package/src/core/_test/Authorization.test.ts +36 -0
- package/src/core/_test/BinaryStateTree.test.ts +35 -0
- package/src/core/_test/Block.test.ts +54 -0
- package/src/core/_test/BlockOverrides.test.ts +14 -1
- package/src/core/_test/Siwe.test.ts +126 -1
- package/src/core/_test/Transaction.test.ts +30 -2
- package/src/core/_test/TransactionEnvelopeEip7702.test.ts +2 -2
- package/src/core/internal/ens.ts +1 -1
- package/src/erc4337/_test/UserOperation.test.ts +2 -2
- package/src/version.ts +1 -1
- package/src/zod/Authorization.ts +10 -2
- package/src/zod/Block.ts +1 -0
- package/src/zod/BlockOverrides.ts +26 -7
- package/src/zod/Signature.ts +2 -1
- package/src/zod/_test/Authorization.test.ts +26 -0
- package/src/zod/_test/Block.test-d.ts +6 -0
- package/src/zod/_test/Block.test.ts +5 -0
- package/src/zod/_test/BlockOverrides.test.ts +36 -1
- package/src/zod/_test/Signature.test.ts +12 -0
|
@@ -1776,8 +1776,8 @@ export declare const Transaction: z.ZodMiniUnion<readonly [z.ZodMiniCodec<z.ZodM
|
|
|
1776
1776
|
address: z.ZodMiniTemplateLiteral<`0x${string}`>;
|
|
1777
1777
|
chainId: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniNumberFormat>;
|
|
1778
1778
|
nonce: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniBigInt<bigint>>;
|
|
1779
|
-
r: z.ZodMiniTemplateLiteral<`0x${string}
|
|
1780
|
-
s: z.ZodMiniTemplateLiteral<`0x${string}
|
|
1779
|
+
r: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniTemplateLiteral<`0x${string}`>>;
|
|
1780
|
+
s: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniTemplateLiteral<`0x${string}`>>;
|
|
1781
1781
|
yParity: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniNumberFormat>;
|
|
1782
1782
|
}, z.core.$strip>>>;
|
|
1783
1783
|
maxFeePerGas: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniBigInt<bigint>>;
|
|
@@ -2383,8 +2383,8 @@ export declare const TransactionToRpc: z.ZodMiniUnion<readonly [z.ZodMiniCodec<z
|
|
|
2383
2383
|
address: z.ZodMiniTemplateLiteral<`0x${string}`>;
|
|
2384
2384
|
chainId: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniUnion<readonly [z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniNumberFormat]>>;
|
|
2385
2385
|
nonce: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniUnion<readonly [z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniBigInt<bigint>, z.ZodMiniNumberFormat]>>;
|
|
2386
|
-
r: z.ZodMiniTemplateLiteral<`0x${string}
|
|
2387
|
-
s: z.ZodMiniTemplateLiteral<`0x${string}
|
|
2386
|
+
r: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniTemplateLiteral<`0x${string}`>>;
|
|
2387
|
+
s: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniTemplateLiteral<`0x${string}`>>;
|
|
2388
2388
|
yParity: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniUnion<readonly [z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniNumberFormat]>>;
|
|
2389
2389
|
}, z.core.$strip>>>;
|
|
2390
2390
|
maxFeePerGas: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniUnion<readonly [z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniBigInt<bigint>, z.ZodMiniNumberFormat]>>;
|
|
@@ -3008,8 +3008,8 @@ export declare const Pending: z.ZodMiniUnion<readonly [z.ZodMiniCodec<z.ZodMiniO
|
|
|
3008
3008
|
address: z.ZodMiniTemplateLiteral<`0x${string}`>;
|
|
3009
3009
|
chainId: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniNumberFormat>;
|
|
3010
3010
|
nonce: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniBigInt<bigint>>;
|
|
3011
|
-
r: z.ZodMiniTemplateLiteral<`0x${string}
|
|
3012
|
-
s: z.ZodMiniTemplateLiteral<`0x${string}
|
|
3011
|
+
r: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniTemplateLiteral<`0x${string}`>>;
|
|
3012
|
+
s: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniTemplateLiteral<`0x${string}`>>;
|
|
3013
3013
|
yParity: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniNumberFormat>;
|
|
3014
3014
|
}, z.core.$strip>>>;
|
|
3015
3015
|
maxFeePerGas: z.ZodMiniCodec<z.ZodMiniTemplateLiteral<`0x${string}`>, z.ZodMiniBigInt<bigint>>;
|
package/package.json
CHANGED
package/src/core/AbiError.ts
CHANGED
|
@@ -408,7 +408,7 @@ export declare namespace extract {
|
|
|
408
408
|
* error, // [!code focus]
|
|
409
409
|
* [1n, 2n, 0] // [!code focus]
|
|
410
410
|
* ) // [!code focus]
|
|
411
|
-
* // @log: '
|
|
411
|
+
* // @log: '0xe466f0a5000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000'
|
|
412
412
|
* ```
|
|
413
413
|
*
|
|
414
414
|
* @example
|
|
@@ -751,7 +751,7 @@ export declare namespace fromAbi {
|
|
|
751
751
|
* const selector = AbiError.getSelector(
|
|
752
752
|
* 'error BadSignatureV(uint8 v)'
|
|
753
753
|
* )
|
|
754
|
-
* // @log: '
|
|
754
|
+
* // @log: '0x1f003d0a'
|
|
755
755
|
* ```
|
|
756
756
|
*
|
|
757
757
|
* @example
|
|
@@ -763,7 +763,7 @@ export declare namespace fromAbi {
|
|
|
763
763
|
* name: 'BadSignatureV',
|
|
764
764
|
* type: 'error'
|
|
765
765
|
* })
|
|
766
|
-
* // @log: '
|
|
766
|
+
* // @log: '0x1f003d0a'
|
|
767
767
|
* ```
|
|
768
768
|
*
|
|
769
769
|
* @param abiItem - The ABI item to compute the selector for.
|
package/src/core/AbiEvent.ts
CHANGED
|
@@ -1682,7 +1682,7 @@ export declare namespace fromAbi {
|
|
|
1682
1682
|
* const selector = AbiEvent.getSelector(
|
|
1683
1683
|
* 'event Transfer(address indexed from, address indexed to, uint256 value)'
|
|
1684
1684
|
* )
|
|
1685
|
-
* // @log: '
|
|
1685
|
+
* // @log: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
|
|
1686
1686
|
* ```
|
|
1687
1687
|
*
|
|
1688
1688
|
* @example
|
|
@@ -1698,7 +1698,7 @@ export declare namespace fromAbi {
|
|
|
1698
1698
|
* { name: 'value', type: 'uint256' }
|
|
1699
1699
|
* ]
|
|
1700
1700
|
* })
|
|
1701
|
-
* // @log: '
|
|
1701
|
+
* // @log: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
|
|
1702
1702
|
* ```
|
|
1703
1703
|
*
|
|
1704
1704
|
* @param abiItem - The ABI event to compute the selector for.
|
|
@@ -517,14 +517,17 @@ export declare namespace hash {
|
|
|
517
517
|
* @returns An RPC-formatted Authorization.
|
|
518
518
|
*/
|
|
519
519
|
export function toRpc(authorization: toRpc.Input): Rpc {
|
|
520
|
-
const { address, chainId, nonce,
|
|
521
|
-
assertYParity(Number(
|
|
520
|
+
const { address, chainId, nonce, r, s, yParity } = authorization
|
|
521
|
+
assertYParity(Number(yParity))
|
|
522
522
|
|
|
523
523
|
return {
|
|
524
524
|
address,
|
|
525
525
|
chainId: Quantity.fromNumberish(chainId),
|
|
526
526
|
nonce: Quantity.fromNumberish(nonce),
|
|
527
|
-
|
|
527
|
+
// `r` and `s` are `uint256` quantities over RPC, so drop leading zeros.
|
|
528
|
+
r: Hex.fromNumber(BigInt(r)),
|
|
529
|
+
s: Hex.fromNumber(BigInt(s)),
|
|
530
|
+
yParity: Quantity.fromNumberish(yParity),
|
|
528
531
|
}
|
|
529
532
|
}
|
|
530
533
|
|
|
@@ -274,6 +274,9 @@ function bitsToBytes(bits: number[]): Bytes.Bytes {
|
|
|
274
274
|
/** @internal */
|
|
275
275
|
function hash(bytes: Bytes.Bytes | undefined): Bytes.Bytes {
|
|
276
276
|
if (!bytes) return new Uint8Array(32).fill(0)
|
|
277
|
-
|
|
277
|
+
// EIP-7864 only hashes the 64-byte zero input to zero. A zero-valued leaf
|
|
278
|
+
// still hashes.
|
|
279
|
+
if (bytes.length === 64 && !bytes.some((byte) => byte !== 0))
|
|
280
|
+
return new Uint8Array(32).fill(0)
|
|
278
281
|
return engine.blake3(bytes)
|
|
279
282
|
}
|
package/src/core/Blobs.ts
CHANGED
|
@@ -366,7 +366,7 @@ export declare namespace from {
|
|
|
366
366
|
*
|
|
367
367
|
* const blobs = Blobs.from('0xdeadbeef')
|
|
368
368
|
* const data = Blobs.to(blobs, 'Bytes')
|
|
369
|
-
* // @log: Uint8Array [
|
|
369
|
+
* // @log: Uint8Array [ 222, 173, 190, 239 ]
|
|
370
370
|
* ```
|
|
371
371
|
*
|
|
372
372
|
* @param blobs - The {@link ox#Blobs.Blobs} to transform.
|
|
@@ -465,7 +465,7 @@ export declare namespace toHex {
|
|
|
465
465
|
*
|
|
466
466
|
* const blobs = Blobs.from('0xdeadbeef')
|
|
467
467
|
* const data = Blobs.toBytes(blobs) // [!code focus]
|
|
468
|
-
* // @log: Uint8Array [
|
|
468
|
+
* // @log: Uint8Array [ 222, 173, 190, 239 ]
|
|
469
469
|
* ```
|
|
470
470
|
*/
|
|
471
471
|
export function toBytes(
|
package/src/core/Block.ts
CHANGED
|
@@ -49,6 +49,8 @@ export type Block<
|
|
|
49
49
|
parentHash: Hex.Hex
|
|
50
50
|
/** Root of the this block’s receipts trie */
|
|
51
51
|
receiptsRoot: Hex.Hex
|
|
52
|
+
/** EIP-7685 requests hash */
|
|
53
|
+
requestsHash?: Hex.Hex | undefined
|
|
52
54
|
sealFields?: readonly Hex.Hex[] | undefined
|
|
53
55
|
/** SHA3 of the uncles data in this block */
|
|
54
56
|
sha3Uncles: Hex.Hex
|
|
@@ -174,6 +176,7 @@ export function toRpc<
|
|
|
174
176
|
parentBeaconBlockRoot: block.parentBeaconBlockRoot,
|
|
175
177
|
parentHash: block.parentHash,
|
|
176
178
|
receiptsRoot: block.receiptsRoot,
|
|
179
|
+
requestsHash: block.requestsHash,
|
|
177
180
|
sealFields: block.sealFields,
|
|
178
181
|
sha3Uncles: block.sha3Uncles,
|
|
179
182
|
size: Quantity.fromNumberish(block.size),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as Address from './Address.js'
|
|
2
|
-
import
|
|
2
|
+
import * as Hex from './Hex.js'
|
|
3
3
|
import * as Quantity from './internal/quantity.js'
|
|
4
4
|
import * as Withdrawal from './Withdrawal.js'
|
|
5
5
|
|
|
@@ -44,7 +44,8 @@ export type Rpc = BlockOverrides<Hex.Hex, Hex.Hex>
|
|
|
44
44
|
* '0x0000000000000000000000000000000000000000',
|
|
45
45
|
* gasLimit: '0x4',
|
|
46
46
|
* number: '0x5',
|
|
47
|
-
* prevRandao:
|
|
47
|
+
* prevRandao:
|
|
48
|
+
* '0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
48
49
|
* time: '0x1234567890',
|
|
49
50
|
* withdrawals: [
|
|
50
51
|
* {
|
|
@@ -126,7 +127,10 @@ export function toRpc(blockOverrides: toRpc.Input): Rpc {
|
|
|
126
127
|
if (blockOverrides.number !== undefined)
|
|
127
128
|
rpc.number = Quantity.fromNumberish(blockOverrides.number)
|
|
128
129
|
if (blockOverrides.prevRandao !== undefined)
|
|
129
|
-
rpc.prevRandao =
|
|
130
|
+
rpc.prevRandao = Hex.padLeft(
|
|
131
|
+
Quantity.fromNumberish(blockOverrides.prevRandao),
|
|
132
|
+
32,
|
|
133
|
+
)
|
|
130
134
|
if (blockOverrides.time !== undefined)
|
|
131
135
|
rpc.time = Quantity.fromNumberish(blockOverrides.time)
|
|
132
136
|
if (blockOverrides.withdrawals !== undefined)
|
package/src/core/Ens.ts
CHANGED
|
@@ -48,7 +48,7 @@ export declare namespace labelhash {
|
|
|
48
48
|
* ```ts twoslash
|
|
49
49
|
* import { Ens } from 'ox'
|
|
50
50
|
* Ens.namehash('wevm.eth')
|
|
51
|
-
* // @log: '
|
|
51
|
+
* // @log: '0x08c85f2f4059e930c45a6aeff9dcd3bd95dc3c5c1cddef6a0626b31152248560'
|
|
52
52
|
* ```
|
|
53
53
|
*
|
|
54
54
|
* @param name - ENS name.
|
package/src/core/Hash.ts
CHANGED
|
@@ -261,7 +261,7 @@ export declare namespace blake3 {
|
|
|
261
261
|
* import { Hash, Hex } from 'ox'
|
|
262
262
|
*
|
|
263
263
|
* Hash.keccak256(Hex.fromString('hello world'))
|
|
264
|
-
* // @log: '
|
|
264
|
+
* // @log: '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad'
|
|
265
265
|
* ```
|
|
266
266
|
*
|
|
267
267
|
* @example
|
package/src/core/Siwe.ts
CHANGED
|
@@ -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 =
|
|
@@ -29,6 +28,14 @@ const anchoredSuffixRegex = new RegExp(`^(?:${suffixRegex.source})$`)
|
|
|
29
28
|
const siweDateTimeRegex =
|
|
30
29
|
/^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])[Tt]([01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:[Zz]|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/
|
|
31
30
|
|
|
31
|
+
// `parseMessage` reads the statement with `.`, which stops at these.
|
|
32
|
+
const statementLineBreakRegex = /[\n\r\u2028\u2029]/
|
|
33
|
+
|
|
34
|
+
// An IP literal (IPv6 or IPvFuture) `domain` with an optional port. The
|
|
35
|
+
// literal itself is checked by `isAuthority`. `@` and `[` are excluded so a
|
|
36
|
+
// userinfo authority such as `[evil.com@[::1]` cannot pass as a literal.
|
|
37
|
+
const domainIpLiteralRegex = /^\[[^\]\s@[]+\](?::[0-9]{1,5})?$/
|
|
38
|
+
|
|
32
39
|
// URI validation (see `isUri`).
|
|
33
40
|
const uriIllegalCharacterRegex = /[^a-z0-9:/?#[\]@!$&'()*+,;=.\-_~%]/i
|
|
34
41
|
const uriInvalidEscapeRegex = /%[^0-9a-f]/i
|
|
@@ -185,7 +192,8 @@ export function createMessage(value: Message): string {
|
|
|
185
192
|
!(
|
|
186
193
|
domainRegex.test(domain) ||
|
|
187
194
|
ipRegex.test(domain) ||
|
|
188
|
-
localhostRegex.test(domain)
|
|
195
|
+
localhostRegex.test(domain) ||
|
|
196
|
+
(domainIpLiteralRegex.test(domain) && isAuthority(domain))
|
|
189
197
|
)
|
|
190
198
|
)
|
|
191
199
|
throw new InvalidMessageFieldError({
|
|
@@ -239,11 +247,11 @@ export function createMessage(value: Message): string {
|
|
|
239
247
|
],
|
|
240
248
|
})
|
|
241
249
|
const statement = value.statement
|
|
242
|
-
if (statement
|
|
250
|
+
if (statement && statementLineBreakRegex.test(statement))
|
|
243
251
|
throw new InvalidMessageFieldError({
|
|
244
252
|
field: 'statement',
|
|
245
253
|
metaMessages: [
|
|
246
|
-
"- Statement must not include '\\n'.",
|
|
254
|
+
"- Statement must not include a line break ('\\n', '\\r', '\\u2028' or '\\u2029').",
|
|
247
255
|
'',
|
|
248
256
|
`Provided value: ${statement}`,
|
|
249
257
|
],
|
|
@@ -359,7 +367,7 @@ export function isUri(value: string): false | string {
|
|
|
359
367
|
// if authority is present, the path must be empty or begin with a /
|
|
360
368
|
if (authority?.length) {
|
|
361
369
|
if (!(path.length === 0 || path.startsWith('/'))) return false
|
|
362
|
-
if (
|
|
370
|
+
if (!isAuthority(authority)) return false
|
|
363
371
|
} else {
|
|
364
372
|
// if authority is not present, the path must not start with //
|
|
365
373
|
if (path.startsWith('//')) return false
|
|
@@ -524,7 +532,8 @@ export function validateMessage(value: validateMessage.Value): boolean {
|
|
|
524
532
|
|
|
525
533
|
if (domain && message.domain !== domain) return false
|
|
526
534
|
if (nonce && message.nonce !== nonce) return false
|
|
527
|
-
if
|
|
535
|
+
// EIP-4361: if `scheme` is not specified, HTTPS is assumed by default.
|
|
536
|
+
if (scheme && (message.scheme ?? 'https') !== scheme) return false
|
|
528
537
|
|
|
529
538
|
// EIP-4361 requires `nonce = 8*( ALPHA / DIGIT )` and `version = "1"`.
|
|
530
539
|
if (message.nonce !== undefined && !nonceRegex.test(message.nonce))
|
|
@@ -572,6 +581,7 @@ export declare namespace validateMessage {
|
|
|
572
581
|
nonce?: string | undefined
|
|
573
582
|
/**
|
|
574
583
|
* [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986#section-3.1) URI scheme to check against.
|
|
584
|
+
* If the message omits `scheme`, `https` is assumed ([EIP-4361](https://eips.ethereum.org/EIPS/eip-4361)).
|
|
575
585
|
*/
|
|
576
586
|
scheme?: string | undefined
|
|
577
587
|
/**
|
package/src/core/Transaction.ts
CHANGED
|
@@ -523,8 +523,12 @@ export function toRpc<pending extends boolean = false>(
|
|
|
523
523
|
)
|
|
524
524
|
if (typeof transaction.r === 'string') rpc.r = transaction.r
|
|
525
525
|
if (typeof transaction.s === 'string') rpc.s = transaction.s
|
|
526
|
+
// Legacy EIP-155 `v` is unsized; typed transactions keep a single byte.
|
|
526
527
|
if (transaction.v !== undefined)
|
|
527
|
-
rpc.v =
|
|
528
|
+
rpc.v =
|
|
529
|
+
transaction.type === 'legacy'
|
|
530
|
+
? Quantity.fromNumberish(transaction.v)
|
|
531
|
+
: Quantity.fromNumberish(transaction.v, { size: 1 })
|
|
528
532
|
if (transaction.yParity !== undefined)
|
|
529
533
|
rpc.yParity = Quantity.fromNumberish(transaction.yParity)
|
|
530
534
|
|
package/src/core/TypedData.ts
CHANGED
|
@@ -534,7 +534,7 @@ export declare namespace getSignPayload {
|
|
|
534
534
|
* '0x0000000000000000000000000000000000000000'
|
|
535
535
|
* }
|
|
536
536
|
* })
|
|
537
|
-
* // @log: '
|
|
537
|
+
* // @log: '0x2fdf3441fcaf4f30c7e16292b258a5d7054a4e2e00dbd7b7d2f467f2b8fb9413'
|
|
538
538
|
* ```
|
|
539
539
|
*
|
|
540
540
|
* @param value - The Typed Data domain and types.
|
|
@@ -593,7 +593,7 @@ export declare namespace hashDomain {
|
|
|
593
593
|
* foo: '0xb9CAB4F0E46F7F6b1024b5A7463734fa68E633f9'
|
|
594
594
|
* }
|
|
595
595
|
* })
|
|
596
|
-
* // @log: '
|
|
596
|
+
* // @log: '0x4305429dd165189369e3373e404dac11fa3bc66d93d5231b00198cb578d402e0'
|
|
597
597
|
* ```
|
|
598
598
|
*
|
|
599
599
|
* @param value - The Typed Data struct to hash.
|
|
@@ -681,6 +681,42 @@ describe('toRpc', () => {
|
|
|
681
681
|
`)
|
|
682
682
|
})
|
|
683
683
|
|
|
684
|
+
test('behavior: r and s with leading zeros', () => {
|
|
685
|
+
// Authorization from mainnet tx 0x701f5911c66298aee60c1fc2b56063de81efcde3186d0ad317d083098bbb7b51.
|
|
686
|
+
const rpc = {
|
|
687
|
+
address: '0x77021100bd87b7008e5e1989d0eb38555d0d0000',
|
|
688
|
+
chainId: '0x1',
|
|
689
|
+
nonce: '0x0',
|
|
690
|
+
r: '0x3baad1283c99f51e583a6a11c677c1a0bdad1b544345cfbcbd52b15d98a01ab8',
|
|
691
|
+
s: '0xcd04e7ee3547adf0fb459aed29f7cf11f015574dfdfaf6b154d9946579ce84',
|
|
692
|
+
yParity: '0x1',
|
|
693
|
+
} as const
|
|
694
|
+
const authorization = Authorization.fromRpc(rpc)
|
|
695
|
+
expect(authorization.s).toMatchInlineSnapshot(
|
|
696
|
+
`"0x00cd04e7ee3547adf0fb459aed29f7cf11f015574dfdfaf6b154d9946579ce84"`,
|
|
697
|
+
)
|
|
698
|
+
expect(Authorization.toRpc(authorization)).toEqual(rpc)
|
|
699
|
+
expect(
|
|
700
|
+
Authorization.toRpc({
|
|
701
|
+
address: '0x0000000000000000000000000000000000000000',
|
|
702
|
+
chainId: 1,
|
|
703
|
+
nonce: 0n,
|
|
704
|
+
r: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
705
|
+
s: '0x0aae27418bfc5e027aad1241dd50ba59a0bf138a1860283f8cc01adc319e505a',
|
|
706
|
+
yParity: 0,
|
|
707
|
+
}),
|
|
708
|
+
).toMatchInlineSnapshot(`
|
|
709
|
+
{
|
|
710
|
+
"address": "0x0000000000000000000000000000000000000000",
|
|
711
|
+
"chainId": "0x1",
|
|
712
|
+
"nonce": "0x0",
|
|
713
|
+
"r": "0x0",
|
|
714
|
+
"s": "0xaae27418bfc5e027aad1241dd50ba59a0bf138a1860283f8cc01adc319e505a",
|
|
715
|
+
"yParity": "0x0",
|
|
716
|
+
}
|
|
717
|
+
`)
|
|
718
|
+
})
|
|
719
|
+
|
|
684
720
|
test('error: yParity above 2**8 - 1', () => {
|
|
685
721
|
expect(() =>
|
|
686
722
|
Authorization.toRpc({
|
|
@@ -180,3 +180,38 @@ describe('insert', () => {
|
|
|
180
180
|
)
|
|
181
181
|
})
|
|
182
182
|
})
|
|
183
|
+
|
|
184
|
+
describe('merkelize', () => {
|
|
185
|
+
test('behavior: single zero value', () => {
|
|
186
|
+
const tree = BinaryStateTree.create()
|
|
187
|
+
BinaryStateTree.insert(
|
|
188
|
+
tree,
|
|
189
|
+
Bytes.fromHex(('0x' + '00'.repeat(32)) as Hex.Hex),
|
|
190
|
+
Bytes.fromHex(('0x' + '00'.repeat(32)) as Hex.Hex),
|
|
191
|
+
)
|
|
192
|
+
expect(
|
|
193
|
+
Hex.fromBytes(BinaryStateTree.merkelize(tree)),
|
|
194
|
+
).toMatchInlineSnapshot(
|
|
195
|
+
`"0x03ecb31f2982654be96b0ced7a59db5e056a1511f6a01b7a6dab182a79ab3a83"`,
|
|
196
|
+
)
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
test('behavior: zero value next to non-zero value', () => {
|
|
200
|
+
const tree = BinaryStateTree.create()
|
|
201
|
+
BinaryStateTree.insert(
|
|
202
|
+
tree,
|
|
203
|
+
Bytes.fromHex(('0x' + '00'.repeat(32)) as Hex.Hex),
|
|
204
|
+
Bytes.fromHex(('0x' + '00'.repeat(32)) as Hex.Hex),
|
|
205
|
+
)
|
|
206
|
+
BinaryStateTree.insert(
|
|
207
|
+
tree,
|
|
208
|
+
Bytes.fromHex(('0x' + '00'.repeat(31) + '01') as Hex.Hex),
|
|
209
|
+
Bytes.fromHex(('0x' + '01'.repeat(32)) as Hex.Hex),
|
|
210
|
+
)
|
|
211
|
+
expect(
|
|
212
|
+
Hex.fromBytes(BinaryStateTree.merkelize(tree)),
|
|
213
|
+
).toMatchInlineSnapshot(
|
|
214
|
+
`"0x8b1fd0f39922fc0fe0633c4bb9bfe5cc92aabf717313fe0cdc6e985f0a5cb8c1"`,
|
|
215
|
+
)
|
|
216
|
+
})
|
|
217
|
+
})
|
|
@@ -508,6 +508,7 @@ describe('toRpc', () => {
|
|
|
508
508
|
"parentBeaconBlockRoot": undefined,
|
|
509
509
|
"parentHash": "0xe55516ad8029e53cd32087f14653d851401b05245abb1b2d6ed4ddcc597ac5a6",
|
|
510
510
|
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
|
511
|
+
"requestsHash": undefined,
|
|
511
512
|
"sealFields": [
|
|
512
513
|
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
513
514
|
"0x0000000000000000",
|
|
@@ -715,6 +716,7 @@ describe('toRpc', () => {
|
|
|
715
716
|
"parentBeaconBlockRoot": undefined,
|
|
716
717
|
"parentHash": "0xe55516ad8029e53cd32087f14653d851401b05245abb1b2d6ed4ddcc597ac5a6",
|
|
717
718
|
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
|
719
|
+
"requestsHash": undefined,
|
|
718
720
|
"sealFields": [
|
|
719
721
|
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
720
722
|
"0x0000000000000000",
|
|
@@ -734,6 +736,58 @@ describe('toRpc', () => {
|
|
|
734
736
|
}
|
|
735
737
|
`)
|
|
736
738
|
})
|
|
739
|
+
|
|
740
|
+
test('behavior: requestsHash', () => {
|
|
741
|
+
// Mainnet block 26428234 (post-Prague), trimmed to one transaction and one withdrawal.
|
|
742
|
+
const rpc = {
|
|
743
|
+
baseFeePerGas: '0x3b8ea6e7',
|
|
744
|
+
blobGasUsed: '0x2a0000',
|
|
745
|
+
difficulty: '0x0',
|
|
746
|
+
excessBlobGas: '0xc514585',
|
|
747
|
+
extraData: '0x546974616e2028746974616e6275696c6465722e78797a29',
|
|
748
|
+
gasLimit: '0x3938700',
|
|
749
|
+
gasUsed: '0x23a6eaa',
|
|
750
|
+
hash: '0xc0177acc8fe87d5eba942ebc003ffa8064ec63eec83ec5ded6b98d53dff487e2',
|
|
751
|
+
logsBloom:
|
|
752
|
+
'0xfee7fd7ef5fa1cfde8ea756da7dffda6dbfdf3fabfb09971efbbcffd765fffcfbc2f527af3fe2eef4b3befdce177b13fdb7beffffedfeffdf7971ffec7efaa86fc8d3feb96eceb7efdea777abaeff5ff46fdf1fdf3dfedff71d25a7fb0feb5ca3c4cc45fbb7ebb13df9f9bc536416fedfa5df5bfaddff7b25e85ce9e45effe69abe8bf6dfc5ab86fe5fdf76d0ef37bf7f331858ff70fffbffcafea5777de35d97feffbf3fdddfefefa397fee9f4bfdd477d67f77b179ae59ffeff62d4b8cfbf1ce5b7c57e7d9cbf7f29e7f32f7df78db759cabf6e7aca3dcf91737afde697ad6fddf7d6b8f77f9efb7ccfeef9baeb9eccdff553fbdebed431fa96e7fe566cee7',
|
|
753
|
+
miner: '0x4838b106fce9647bdf1e7877bf73ce8b0bad5f97',
|
|
754
|
+
mixHash:
|
|
755
|
+
'0x476de780f38343d977f060944820a57667e21e2e3eed284dbc0f0f45cb999f23',
|
|
756
|
+
nonce: '0x0000000000000000',
|
|
757
|
+
number: '0x193434a',
|
|
758
|
+
parentBeaconBlockRoot:
|
|
759
|
+
'0x645e5dd10df2fdcfceedcd462666cedd03117e061c9272187521b9d5dea80174',
|
|
760
|
+
parentHash:
|
|
761
|
+
'0xe350f46ce9c96bcb3a2f2a8a47b205b1e5afc4cd9d01872948636285a81c0554',
|
|
762
|
+
receiptsRoot:
|
|
763
|
+
'0x3a9b4be502301b9379d07b5e23519dd572180336ac427097476f2690d92c3dcd',
|
|
764
|
+
requestsHash:
|
|
765
|
+
'0x6bb55db879cfce5155bbf84c5036f07cd6692ce4a23929423f84a88cd2e9701c',
|
|
766
|
+
sha3Uncles:
|
|
767
|
+
'0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
|
|
768
|
+
size: '0x27ce4',
|
|
769
|
+
stateRoot:
|
|
770
|
+
'0x5aa416b56ad1464a1a88e38f7127b8f181319475911abb0f73a401f44392e532',
|
|
771
|
+
timestamp: '0x6afb1517',
|
|
772
|
+
transactions: [
|
|
773
|
+
'0x955efe228355dc2fedba87f948c28f79c591ede57eeffef5fdd7ae66650c32cd',
|
|
774
|
+
],
|
|
775
|
+
transactionsRoot:
|
|
776
|
+
'0xc0f6df9afa194592d42a662a6ed63ed2685496ecfab488aa4e38e3d6224bb3d6',
|
|
777
|
+
uncles: [],
|
|
778
|
+
withdrawals: [
|
|
779
|
+
{
|
|
780
|
+
address: '0xb9d7934878b5fb9610b3fe8a5e441e8fad7e293f',
|
|
781
|
+
amount: '0xbe7483',
|
|
782
|
+
index: '0x8f5478b',
|
|
783
|
+
validatorIndex: '0x22db72',
|
|
784
|
+
},
|
|
785
|
+
],
|
|
786
|
+
withdrawalsRoot:
|
|
787
|
+
'0xaeb0321b253d63f458b83a49fedbb1af38821135acd64df5c3c41841ec4cbdc7',
|
|
788
|
+
} as const
|
|
789
|
+
expect(Block.toRpc(Block.fromRpc(rpc))).toEqual(rpc)
|
|
790
|
+
})
|
|
737
791
|
})
|
|
738
792
|
|
|
739
793
|
test('exports', () => {
|
|
@@ -88,7 +88,7 @@ describe('toRpc', () => {
|
|
|
88
88
|
"feeRecipient": "0x0000000000000000000000000000000000000000",
|
|
89
89
|
"gasLimit": "0x4",
|
|
90
90
|
"number": "0x5",
|
|
91
|
-
"prevRandao": "
|
|
91
|
+
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000006",
|
|
92
92
|
"time": "0x1234567890",
|
|
93
93
|
"withdrawals": [
|
|
94
94
|
{
|
|
@@ -157,4 +157,17 @@ describe('toRpc', () => {
|
|
|
157
157
|
expect(fromBigint).toEqual(fromNumber)
|
|
158
158
|
expect(fromBigint).toEqual(fromHex)
|
|
159
159
|
})
|
|
160
|
+
|
|
161
|
+
test('behavior: prevRandao is a 32-byte hash', () => {
|
|
162
|
+
expect(BlockOverrides.toRpc({ prevRandao: 6n })).toMatchInlineSnapshot(`
|
|
163
|
+
{
|
|
164
|
+
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000006",
|
|
165
|
+
}
|
|
166
|
+
`)
|
|
167
|
+
expect(BlockOverrides.toRpc({ prevRandao: '0x6' })).toMatchInlineSnapshot(`
|
|
168
|
+
{
|
|
169
|
+
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000006",
|
|
170
|
+
}
|
|
171
|
+
`)
|
|
172
|
+
})
|
|
160
173
|
})
|