ox 1.8.18 → 1.8.19

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.
Files changed (90) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/core/AbiError.d.ts +3 -3
  3. package/dist/core/AbiError.js +2 -2
  4. package/dist/core/AbiEvent.d.ts +2 -2
  5. package/dist/core/AbiEvent.js +2 -2
  6. package/dist/core/Authorization.d.ts.map +1 -1
  7. package/dist/core/Authorization.js +6 -3
  8. package/dist/core/Authorization.js.map +1 -1
  9. package/dist/core/BinaryStateTree.js +3 -1
  10. package/dist/core/BinaryStateTree.js.map +1 -1
  11. package/dist/core/Blobs.d.ts +2 -2
  12. package/dist/core/Blobs.js +2 -2
  13. package/dist/core/Block.d.ts +2 -0
  14. package/dist/core/Block.d.ts.map +1 -1
  15. package/dist/core/Block.js +1 -0
  16. package/dist/core/Block.js.map +1 -1
  17. package/dist/core/BlockOverrides.d.ts +3 -2
  18. package/dist/core/BlockOverrides.d.ts.map +1 -1
  19. package/dist/core/BlockOverrides.js +4 -2
  20. package/dist/core/BlockOverrides.js.map +1 -1
  21. package/dist/core/Ens.d.ts +1 -1
  22. package/dist/core/Ens.js +1 -1
  23. package/dist/core/Hash.d.ts +1 -1
  24. package/dist/core/Hash.js +1 -1
  25. package/dist/core/Siwe.d.ts +1 -0
  26. package/dist/core/Siwe.d.ts.map +1 -1
  27. package/dist/core/Siwe.js +15 -8
  28. package/dist/core/Siwe.js.map +1 -1
  29. package/dist/core/Transaction.d.ts.map +1 -1
  30. package/dist/core/Transaction.js +5 -1
  31. package/dist/core/Transaction.js.map +1 -1
  32. package/dist/core/TypedData.d.ts +2 -2
  33. package/dist/core/TypedData.js +2 -2
  34. package/dist/zod/Authorization.d.ts +14 -14
  35. package/dist/zod/Authorization.d.ts.map +1 -1
  36. package/dist/zod/Authorization.js +9 -2
  37. package/dist/zod/Authorization.js.map +1 -1
  38. package/dist/zod/Block.d.ts +12 -6
  39. package/dist/zod/Block.d.ts.map +1 -1
  40. package/dist/zod/Block.js +1 -0
  41. package/dist/zod/Block.js.map +1 -1
  42. package/dist/zod/BlockOverrides.d.ts.map +1 -1
  43. package/dist/zod/BlockOverrides.js +15 -4
  44. package/dist/zod/BlockOverrides.js.map +1 -1
  45. package/dist/zod/RpcSchema.d.ts +58 -46
  46. package/dist/zod/RpcSchema.d.ts.map +1 -1
  47. package/dist/zod/Signature.d.ts.map +1 -1
  48. package/dist/zod/Signature.js +2 -1
  49. package/dist/zod/Signature.js.map +1 -1
  50. package/dist/zod/Transaction.d.ts +12 -12
  51. package/dist/zod/TransactionEnvelope.d.ts +8 -8
  52. package/dist/zod/TransactionRequest.d.ts +4 -4
  53. package/dist/zod/TxEnvelopeEip7702.d.ts +8 -8
  54. package/dist/zod/internal/rpcSchemas/Eth.d.ts +58 -46
  55. package/dist/zod/internal/rpcSchemas/Eth.d.ts.map +1 -1
  56. package/dist/zod/internal/rpcSchemas/Wallet.d.ts +4 -4
  57. package/dist/zod/tempo/RpcSchemaTempo.d.ts +16 -8
  58. package/dist/zod/tempo/RpcSchemaTempo.d.ts.map +1 -1
  59. package/dist/zod/tempo/Transaction.d.ts +6 -6
  60. package/package.json +1 -1
  61. package/src/core/AbiError.ts +3 -3
  62. package/src/core/AbiEvent.ts +2 -2
  63. package/src/core/Authorization.ts +6 -3
  64. package/src/core/BinaryStateTree.ts +4 -1
  65. package/src/core/Blobs.ts +2 -2
  66. package/src/core/Block.ts +3 -0
  67. package/src/core/BlockOverrides.ts +7 -3
  68. package/src/core/Ens.ts +1 -1
  69. package/src/core/Hash.ts +1 -1
  70. package/src/core/Siwe.ts +18 -8
  71. package/src/core/Transaction.ts +5 -1
  72. package/src/core/TypedData.ts +2 -2
  73. package/src/core/_test/Authorization.test.ts +36 -0
  74. package/src/core/_test/BinaryStateTree.test.ts +35 -0
  75. package/src/core/_test/Block.test.ts +54 -0
  76. package/src/core/_test/BlockOverrides.test.ts +14 -1
  77. package/src/core/_test/Siwe.test.ts +126 -1
  78. package/src/core/_test/Transaction.test.ts +30 -2
  79. package/src/core/_test/TransactionEnvelopeEip7702.test.ts +2 -2
  80. package/src/erc4337/_test/UserOperation.test.ts +2 -2
  81. package/src/version.ts +1 -1
  82. package/src/zod/Authorization.ts +10 -2
  83. package/src/zod/Block.ts +1 -0
  84. package/src/zod/BlockOverrides.ts +26 -7
  85. package/src/zod/Signature.ts +2 -1
  86. package/src/zod/_test/Authorization.test.ts +26 -0
  87. package/src/zod/_test/Block.test-d.ts +6 -0
  88. package/src/zod/_test/Block.test.ts +5 -0
  89. package/src/zod/_test/BlockOverrides.test.ts +36 -1
  90. package/src/zod/_test/Signature.test.ts +12 -0
@@ -430,16 +430,59 @@ describe('createMessage', () => {
430
430
  `)
431
431
  })
432
432
 
433
+ test('behavior: invalid scheme (comma)', () => {
434
+ expect(() => Siwe.createMessage({ ...message, scheme: 'ht,tps' }))
435
+ .toThrowErrorMatchingInlineSnapshot(`
436
+ [Siwe.InvalidMessageFieldError: Invalid Sign-In with Ethereum message field "scheme".
437
+
438
+ - Scheme must be an RFC 3986 URI scheme.
439
+ - See https://www.rfc-editor.org/rfc/rfc3986#section-3.1
440
+
441
+ Provided value: ht,tps]
442
+ `)
443
+ for (const scheme of ['https', 'a+b', 'a-b', 'a.b'])
444
+ expect(() => Siwe.createMessage({ ...message, scheme })).not.toThrow()
445
+ })
446
+
433
447
  test('behavior: invalid statement', () => {
434
448
  expect(() => Siwe.createMessage({ ...message, statement: 'foo\nbar' }))
435
449
  .toThrowErrorMatchingInlineSnapshot(`
436
450
  [Siwe.InvalidMessageFieldError: Invalid Sign-In with Ethereum message field "statement".
437
451
 
438
- - Statement must not include '\\n'.
452
+ - Statement must not include a line break ('\\n', '\\r', '\\u2028' or '\\u2029').
439
453
 
440
454
  Provided value: foo
441
455
  bar]
442
456
  `)
457
+ expect(() =>
458
+ Siwe.createMessage({
459
+ ...message,
460
+ statement: 'foo\rURI: https://evil.example',
461
+ }),
462
+ ).toThrowErrorMatchingInlineSnapshot(`
463
+ [Siwe.InvalidMessageFieldError: Invalid Sign-In with Ethereum message field "statement".
464
+
465
+ - Statement must not include a line break ('\\n', '\\r', '\\u2028' or '\\u2029').
466
+
467
+ Provided value: foo
468
+ URI: https://evil.example]
469
+ `)
470
+ expect(() => Siwe.createMessage({ ...message, statement: 'foo\u2028bar' }))
471
+ .toThrowErrorMatchingInlineSnapshot(`
472
+ [Siwe.InvalidMessageFieldError: Invalid Sign-In with Ethereum message field "statement".
473
+
474
+ - Statement must not include a line break ('\\n', '\\r', '\\u2028' or '\\u2029').
475
+
476
+ Provided value: foo
bar]
477
+ `)
478
+ expect(() => Siwe.createMessage({ ...message, statement: 'foo\u2029bar' }))
479
+ .toThrowErrorMatchingInlineSnapshot(`
480
+ [Siwe.InvalidMessageFieldError: Invalid Sign-In with Ethereum message field "statement".
481
+
482
+ - Statement must not include a line break ('\\n', '\\r', '\\u2028' or '\\u2029').
483
+
484
+ Provided value: foo
bar]
485
+ `)
443
486
  })
444
487
 
445
488
  test('behavior: invalid requestId', () => {
@@ -492,6 +535,10 @@ describe('createMessage', () => {
492
535
  // 63 octets: "xn--" plus 59 LDH characters.
493
536
  `example.xn--${'a'.repeat(59)}`,
494
537
  `example.${'a'.repeat(63)}`,
538
+ '[::cafe]',
539
+ '[::1]:3000',
540
+ '[2001:db8::1]:443',
541
+ '[v1.fe]',
495
542
  ])('valid domain `%s`', (domain) => {
496
543
  expect(
497
544
  Siwe.createMessage({
@@ -517,6 +564,14 @@ describe('createMessage', () => {
517
564
  // 64 octets: one past the maximum label length.
518
565
  `example.xn--${'a'.repeat(60)}`,
519
566
  `example.${'a'.repeat(64)}`,
567
+ '[::1',
568
+ '[zzz]',
569
+ '[::300.0.0.0]',
570
+ '[::1]:123456',
571
+ 'user@[::1]',
572
+ '[::\t1]',
573
+ '[evil.com@[::1]',
574
+ '[a@[::1]',
520
575
  ])('invalid domain `%s`', (domain) => {
521
576
  expect(() =>
522
577
  Siwe.createMessage({
@@ -599,6 +654,31 @@ describe('isUri', () => {
599
654
  expect(Siwe.isUri(uri)).toMatchInlineSnapshot(`false`)
600
655
  })
601
656
 
657
+ test('behavior: authority variants with path', () => {
658
+ expect([
659
+ Siwe.isUri('https://[2001:db8::1]/login'),
660
+ Siwe.isUri('https://user:pass@example.com:8080/login'),
661
+ Siwe.isUri('foo://[v1.fe]/p'),
662
+ ]).toMatchInlineSnapshot(`
663
+ [
664
+ "https://[2001:db8::1]/login",
665
+ "https://user:pass@example.com:8080/login",
666
+ "foo://[v1.fe]/p",
667
+ ]
668
+ `)
669
+ })
670
+
671
+ test.each([
672
+ // https://github.com/spruceid/siwe/blob/main/test/invalid_uris.json
673
+ 'uri://[::0.0.0.256]/p/path',
674
+ 'uri://[::300.0.0.0]/p/path',
675
+ 'https://example.com:bad/login',
676
+ 'https://[:::]/login',
677
+ 'https://[::1/login',
678
+ ])('behavior: invalid authority with path `%s`', (uri) => {
679
+ expect(Siwe.isUri(uri)).toMatchInlineSnapshot(`false`)
680
+ })
681
+
602
682
  test('behavior: check for illegal characters', () => {
603
683
  expect(Siwe.isUri('^')).toBeFalsy()
604
684
  })
@@ -673,6 +753,30 @@ Issued At: 2023-02-01T00:00:00.000Z`
673
753
  expect(parsed.scheme).toMatchInlineSnapshot(`"https"`)
674
754
  })
675
755
 
756
+ test('behavior: scheme with a comma', () => {
757
+ const message = `ht,tps://example.com wants you to sign in with your Ethereum account:
758
+ 0xA0Cf798816D4b9b9866b5330EEa46a18382f251e
759
+
760
+ URI: https://example.com/path
761
+ Version: 1
762
+ Chain ID: 1
763
+ Nonce: foobarbaz
764
+ Issued At: 2023-02-01T00:00:00.000Z`
765
+ expect(Siwe.parseMessage(message)).toEqual({})
766
+ expect(
767
+ ['https', 'a+b', 'a-b', 'a.b'].map(
768
+ (scheme) => Siwe.parseMessage(message.replace('ht,tps', scheme)).scheme,
769
+ ),
770
+ ).toMatchInlineSnapshot(`
771
+ [
772
+ "https",
773
+ "a+b",
774
+ "a-b",
775
+ "a.b",
776
+ ]
777
+ `)
778
+ })
779
+
676
780
  test('behavior: domain with port', () => {
677
781
  const message = `example.com:8080 wants you to sign in with your Ethereum account:
678
782
  0xA0Cf798816D4b9b9866b5330EEa46a18382f251e
@@ -686,6 +790,22 @@ Issued At: 2023-02-01T00:00:00.000Z`
686
790
  expect(parsed.domain).toMatchInlineSnapshot(`"example.com:8080"`)
687
791
  })
688
792
 
793
+ test('behavior: ip literal domain', () => {
794
+ // https://github.com/spruceid/siwe/blob/main/test/parsing_positive.json
795
+ const message = `[::cafe] wants you to sign in with your Ethereum account:
796
+ 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
797
+
798
+
799
+ URI: https://service.org/login
800
+ Version: 1
801
+ Chain ID: 1
802
+ Nonce: 32891757
803
+ Issued At: 2021-09-30T16:25:24.000Z`
804
+ const parsed = Siwe.parseMessage(message)
805
+ expect(parsed.domain).toMatchInlineSnapshot(`"[::cafe]"`)
806
+ expect(Siwe.createMessage(parsed as Siwe.Message)).toBe(message)
807
+ })
808
+
689
809
  test('behavior: with statement', () => {
690
810
  const message = `example.com wants you to sign in with your Ethereum account:
691
811
  0xA0Cf798816D4b9b9866b5330EEa46a18382f251e
@@ -1211,6 +1331,11 @@ Issued At: 2023-02-01T00:00:00.000Z`)
1211
1331
  ).toBeFalsy()
1212
1332
  })
1213
1333
 
1334
+ test('behavior: scheme defaults to https when omitted', () => {
1335
+ expect(Siwe.validateMessage({ scheme: 'https', message })).toBeTruthy()
1336
+ expect(Siwe.validateMessage({ scheme: 'http', message })).toBeFalsy()
1337
+ })
1338
+
1214
1339
  test('behavior: time is after expirationTime', () => {
1215
1340
  expect(
1216
1341
  Siwe.validateMessage({
@@ -1199,7 +1199,7 @@ describe('toRpc', () => {
1199
1199
  "to": "0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad",
1200
1200
  "transactionIndex": "0x2",
1201
1201
  "type": "0x0",
1202
- "v": "0x00",
1202
+ "v": "0x0",
1203
1203
  "value": "0x0",
1204
1204
  "yParity": "0x0",
1205
1205
  }
@@ -1247,7 +1247,7 @@ describe('toRpc', () => {
1247
1247
  "to": "0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad",
1248
1248
  "transactionIndex": null,
1249
1249
  "type": "0x0",
1250
- "v": "0x00",
1250
+ "v": "0x0",
1251
1251
  "value": "0xde0b6b3a7640000",
1252
1252
  "yParity": "0x0",
1253
1253
  }
@@ -1277,6 +1277,34 @@ describe('toRpc', () => {
1277
1277
  })
1278
1278
  expect(rpc.transactionIndex).toBe('0x0')
1279
1279
  })
1280
+
1281
+ test('behavior: eip-155 v above 255', () => {
1282
+ // Polygon (chain ID 137) legacy transaction: `v = 137 * 2 + 35 + 1`.
1283
+ const rpc = {
1284
+ blockHash:
1285
+ '0x330e81a536bc43032035e696a9e5c88630d23e67b12051c0b620b350fbedd63a',
1286
+ blockNumber: '0x5ce8dff',
1287
+ chainId: '0x89',
1288
+ from: '0x58a62fbc2cd2353678784c08cccd73b0dc6d0486',
1289
+ gas: '0xaae60',
1290
+ gasPrice: '0xc23b0a3d0f',
1291
+ hash: '0xfa6c61184fac71fe4caa776aaaac01e73733c797933030ce89cee596f3a63d5d',
1292
+ input: '0xcf1393d9',
1293
+ nonce: '0xa7d2',
1294
+ r: '0xf998579579c97427c7a29412c659b27f31c1e59d27c7a9fbb6feb0b3bb379314',
1295
+ s: '0x2bf54bfd95b30c1390c10cfaccb50b069fff7bee0a89a9234ab7dc06786bb73a',
1296
+ to: '0x5c8138fa7d7a9c1e313931ad44a13969d05e3274',
1297
+ transactionIndex: '0x1',
1298
+ type: '0x0',
1299
+ v: '0x136',
1300
+ value: '0x0',
1301
+ } as const
1302
+ const { yParity, ...rest } = Transaction.toRpc(
1303
+ Transaction.fromRpc(rpc),
1304
+ ) as Transaction.LegacyRpc
1305
+ expect(yParity).toBe('0x1')
1306
+ expect(rest).toEqual(rpc)
1307
+ })
1280
1308
  })
1281
1309
 
1282
1310
  describe('eip1559', () => {
@@ -1139,8 +1139,8 @@ describe('toRpc', () => {
1139
1139
  "address": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
1140
1140
  "chainId": "0x1",
1141
1141
  "nonce": "0x0",
1142
- "r": "0x0000000000000000000000000000000000000000000000000000000000000001",
1143
- "s": "0x0000000000000000000000000000000000000000000000000000000000000002",
1142
+ "r": "0x1",
1143
+ "s": "0x2",
1144
1144
  "yParity": "0x0",
1145
1145
  },
1146
1146
  ],
@@ -1811,8 +1811,8 @@ describe('v0.8 authorization round-trip', () => {
1811
1811
  "address": "0x1234567890123456789012345678901234567890",
1812
1812
  "chainId": "0x1",
1813
1813
  "nonce": "0x0",
1814
- "r": "0x0000000000000000000000000000000000000000000000000000000000000001",
1815
- "s": "0x0000000000000000000000000000000000000000000000000000000000000002",
1814
+ "r": "0x1",
1815
+ "s": "0x2",
1816
1816
  "yParity": "0x0",
1817
1817
  }
1818
1818
  `)
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** @internal */
2
- export const version = '1.8.18'
2
+ export const version = '1.8.19'
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable jsdoc-js/require-jsdoc, jsdoc-js/require-description, jsdoc-js/require-example */
2
+ import * as core_Hex from '../core/Hex.js'
2
3
  import * as z_Address from './Address.js'
3
4
  import * as z_Hex from './Hex.js'
4
5
  import { quantityHex } from './internal/Integer.js'
@@ -10,6 +11,13 @@ import * as z from 'zod/mini'
10
11
  // every authorization schema accepts an 8-bit `yParity`.
11
12
  const yParityHex = quantityHex(8)
12
13
 
14
+ // `r` and `s` are `uint256` quantities over RPC, so accept them without
15
+ // leading zeros and decode them to 32-byte hex like `Authorization.fromRpc`.
16
+ const signatureScalar = z.codec(quantityHex(256), z_Hex.Hex32, {
17
+ decode: (value) => core_Hex.padLeft(value, 32),
18
+ encode: (value) => core_Hex.fromNumber(core_Hex.toBigInt(value)),
19
+ })
20
+
13
21
  /** Unsigned EIP-7702 authorization schema. */
14
22
  export const Unsigned = z.object(unsignedFields(z_Number.Number, z_Uint.Uint))
15
23
 
@@ -92,8 +100,8 @@ function signedFields<
92
100
  address: z_Address.Address,
93
101
  chainId: num,
94
102
  nonce: uint,
95
- r: z_Hex.Hex32,
96
- s: z_Hex.Hex32,
103
+ r: signatureScalar,
104
+ s: signatureScalar,
97
105
  yParity,
98
106
  }
99
107
  }
package/src/zod/Block.ts CHANGED
@@ -135,6 +135,7 @@ function commonFields<
135
135
  parentBeaconBlockRoot: z.optional(z_Hex.Hex),
136
136
  parentHash: z_Hex.Hex,
137
137
  receiptsRoot: z_Hex.Hex,
138
+ requestsHash: z.optional(z_Hex.Hex),
138
139
  sealFields: z.optional(z.readonly(z.array(z_Hex.Hex))),
139
140
  sha3Uncles: z_Hex.Hex,
140
141
  size: uint,
@@ -1,30 +1,49 @@
1
1
  /* eslint-disable jsdoc-js/require-jsdoc, jsdoc-js/require-description, jsdoc-js/require-example */
2
+ import * as core_Hex from '../core/Hex.js'
2
3
  import * as z_Address from './Address.js'
4
+ import {
5
+ encodeNumberish,
6
+ quantityHex,
7
+ uintBigint,
8
+ uintBigintNumberish,
9
+ } from './internal/Integer.js'
3
10
  import * as z_Uint from './Uint.js'
4
11
  import * as z_Withdrawal from './Withdrawal.js'
5
12
  import * as z from 'zod/mini'
6
13
 
14
+ /** `prevRandao` is a 32-byte hash on the wire, decoded as `bigint`. */
15
+ const PrevRandao = z.codec(quantityHex(256), uintBigint(256), {
16
+ decode: (value) => core_Hex.toBigInt(value),
17
+ encode: (value) => core_Hex.fromNumber(value, { size: 32 }),
18
+ })
19
+
20
+ const PrevRandaoToRpc = z.codec(quantityHex(256), uintBigintNumberish(256), {
21
+ decode: (value) => core_Hex.toBigInt(value),
22
+ encode: (value) => core_Hex.padLeft(encodeNumberish(value), 32),
23
+ })
24
+
7
25
  /** Block overrides schema. */
8
26
  export const BlockOverrides = z.object(
9
- fields(z_Uint.Uint, z_Withdrawal.Withdrawal),
27
+ fields(z_Uint.Uint, PrevRandao, z_Withdrawal.Withdrawal),
10
28
  )
11
29
 
12
30
  /** Encode-only block overrides schema accepting numberish `toRpc` inputs. */
13
31
  export const BlockOverridesToRpc = z.object(
14
- fields(z_Uint.UintToRpc, z_Withdrawal.WithdrawalToRpc),
32
+ fields(z_Uint.UintToRpc, PrevRandaoToRpc, z_Withdrawal.WithdrawalToRpc),
15
33
  )
16
34
 
17
- function fields<uint extends z.ZodMiniType, withdrawal extends z.ZodMiniType>(
18
- uint: uint,
19
- withdrawal: withdrawal,
20
- ) {
35
+ function fields<
36
+ uint extends z.ZodMiniType,
37
+ prevRandao extends z.ZodMiniType,
38
+ withdrawal extends z.ZodMiniType,
39
+ >(uint: uint, prevRandao: prevRandao, withdrawal: withdrawal) {
21
40
  return {
22
41
  baseFeePerGas: z.optional(uint),
23
42
  blobBaseFee: z.optional(uint),
24
43
  feeRecipient: z.optional(z_Address.Address),
25
44
  gasLimit: z.optional(uint),
26
45
  number: z.optional(uint),
27
- prevRandao: z.optional(uint),
46
+ prevRandao: z.optional(prevRandao),
28
47
  time: z.optional(uint),
29
48
  withdrawals: z.optional(z.array(withdrawal)),
30
49
  }
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable jsdoc-js/require-jsdoc, jsdoc-js/require-description, jsdoc-js/require-example */
2
2
  import * as z_Hex from './Hex.js'
3
+ import * as z_Number from './Number.js'
3
4
  import * as z_Uint from './Uint.js'
4
5
  import * as z from 'zod/mini'
5
6
 
@@ -39,7 +40,7 @@ export const SignatureToRpc = z.object({
39
40
  export const Legacy = z.object({
40
41
  r: z_Hex.Hex32,
41
42
  s: z_Hex.Hex32,
42
- v: z_Uint.Uint8,
43
+ v: z_Number.Number,
43
44
  })
44
45
 
45
46
  /** Signature tuple schema. */
@@ -198,6 +198,32 @@ describe('Authorization', () => {
198
198
  ).toMatchInlineSnapshot(`"0x1c"`)
199
199
  })
200
200
 
201
+ test('accepts r and s without leading zeros', () => {
202
+ // Authorization from mainnet tx 0x701f5911c66298aee60c1fc2b56063de81efcde3186d0ad317d083098bbb7b51.
203
+ const rpc = {
204
+ address: '0x77021100bd87b7008e5e1989d0eb38555d0d0000',
205
+ chainId: '0x1',
206
+ nonce: '0x0',
207
+ r: '0x3baad1283c99f51e583a6a11c677c1a0bdad1b544345cfbcbd52b15d98a01ab8',
208
+ s: '0xcd04e7ee3547adf0fb459aed29f7cf11f015574dfdfaf6b154d9946579ce84',
209
+ yParity: '0x1',
210
+ } as const
211
+ const decoded = z.decode(z_Authorization.Signed, rpc)
212
+ expect(decoded).toMatchInlineSnapshot(`
213
+ {
214
+ "address": "0x77021100bd87b7008e5e1989d0eb38555d0d0000",
215
+ "chainId": 1,
216
+ "nonce": 0n,
217
+ "r": "0x3baad1283c99f51e583a6a11c677c1a0bdad1b544345cfbcbd52b15d98a01ab8",
218
+ "s": "0x00cd04e7ee3547adf0fb459aed29f7cf11f015574dfdfaf6b154d9946579ce84",
219
+ "yParity": 1,
220
+ }
221
+ `)
222
+ expect(z.encode(z_Authorization.Signed, decoded)).toEqual(rpc)
223
+ expect(z.encode(z_Authorization.SignedToRpc, decoded)).toEqual(rpc)
224
+ expect(z.decode(z_Authorization.ListSigned, [rpc])).toEqual([decoded])
225
+ })
226
+
201
227
  test('rejects invalid signatures', () => {
202
228
  expect(
203
229
  z.safeDecode(z_Authorization.Signed, {
@@ -21,6 +21,12 @@ test('Block schemas preserve decoded and encoded types', () => {
21
21
  expectTypeOf<core_Block.Rpc<false>>().toMatchTypeOf<
22
22
  z.input<typeof z_Block.Block>
23
23
  >()
24
+ expectTypeOf<z.output<typeof z_Block.Block>['requestsHash']>().toEqualTypeOf<
25
+ core_Block.Block['requestsHash']
26
+ >()
27
+ expectTypeOf<z.input<typeof z_Block.Block>['requestsHash']>().toEqualTypeOf<
28
+ core_Block.Rpc<false>['requestsHash']
29
+ >()
24
30
  expectTypeOf<z.output<typeof z_Block.WithTransactions>>().toMatchTypeOf<
25
31
  core_Block.Block<true>
26
32
  >()
@@ -25,6 +25,7 @@ const blockRpc = {
25
25
  parentBeaconBlockRoot: hash,
26
26
  parentHash: hash,
27
27
  receiptsRoot: hash,
28
+ requestsHash: hash2,
28
29
  sealFields: [hash, '0x0000000000000000'],
29
30
  sha3Uncles: hash,
30
31
  size: '0x8',
@@ -60,6 +61,7 @@ describe('Block', () => {
60
61
  "parentBeaconBlockRoot": "0x1111111111111111111111111111111111111111111111111111111111111111",
61
62
  "parentHash": "0x1111111111111111111111111111111111111111111111111111111111111111",
62
63
  "receiptsRoot": "0x1111111111111111111111111111111111111111111111111111111111111111",
64
+ "requestsHash": "0x2222222222222222222222222222222222222222222222222222222222222222",
63
65
  "sealFields": [
64
66
  "0x1111111111111111111111111111111111111111111111111111111111111111",
65
67
  "0x0000000000000000",
@@ -105,6 +107,7 @@ describe('Block', () => {
105
107
  parentBeaconBlockRoot: hash,
106
108
  parentHash: hash,
107
109
  receiptsRoot: hash,
110
+ requestsHash: hash2,
108
111
  sealFields: [hash, '0x0000000000000000'],
109
112
  sha3Uncles: hash,
110
113
  size: 8n,
@@ -135,6 +138,7 @@ describe('Block', () => {
135
138
  "parentBeaconBlockRoot": "0x1111111111111111111111111111111111111111111111111111111111111111",
136
139
  "parentHash": "0x1111111111111111111111111111111111111111111111111111111111111111",
137
140
  "receiptsRoot": "0x1111111111111111111111111111111111111111111111111111111111111111",
141
+ "requestsHash": "0x2222222222222222222222222222222222222222222222222222222222222222",
138
142
  "sealFields": [
139
143
  "0x1111111111111111111111111111111111111111111111111111111111111111",
140
144
  "0x0000000000000000",
@@ -221,6 +225,7 @@ describe('Block', () => {
221
225
  parentBeaconBlockRoot: hash,
222
226
  parentHash: hash,
223
227
  receiptsRoot: hash,
228
+ requestsHash: hash2,
224
229
  sealFields: [hash, '0x0000000000000000'],
225
230
  sha3Uncles: hash,
226
231
  size: 8n,
@@ -68,7 +68,7 @@ describe('BlockOverrides', () => {
68
68
  "feeRecipient": "0x0000000000000000000000000000000000000000",
69
69
  "gasLimit": "0x3",
70
70
  "number": "0x4",
71
- "prevRandao": "0x5",
71
+ "prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000005",
72
72
  "time": "0x6",
73
73
  "withdrawals": [
74
74
  {
@@ -117,6 +117,41 @@ describe('BlockOverrides', () => {
117
117
  ).toEqual(expected)
118
118
  })
119
119
 
120
+ test('encodes prevRandao as a 32-byte hash', () => {
121
+ const expected = {
122
+ prevRandao:
123
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
124
+ } as const
125
+ expect(
126
+ z.encode(z_BlockOverrides.BlockOverrides, { prevRandao: 5n }),
127
+ ).toEqual(expected)
128
+ expect(
129
+ z.encode(z_BlockOverrides.BlockOverridesToRpc, { prevRandao: '0x5' }),
130
+ ).toEqual(expected)
131
+ expect(z.decode(z_BlockOverrides.BlockOverrides, expected)).toEqual({
132
+ prevRandao: 5n,
133
+ })
134
+ })
135
+
136
+ test('rejects prevRandao above 32 bytes', () => {
137
+ expect([
138
+ z.safeEncode(z_BlockOverrides.BlockOverrides, { prevRandao: 2n ** 256n })
139
+ .success,
140
+ z.safeEncode(z_BlockOverrides.BlockOverridesToRpc, {
141
+ prevRandao: 2n ** 256n,
142
+ }).success,
143
+ z.safeDecode(z_BlockOverrides.BlockOverrides, {
144
+ prevRandao: `0x01${'00'.repeat(32)}`,
145
+ }).success,
146
+ ]).toMatchInlineSnapshot(`
147
+ [
148
+ false,
149
+ false,
150
+ false,
151
+ ]
152
+ `)
153
+ })
154
+
120
155
  test('rejects invalid nested withdrawals', () => {
121
156
  expect(
122
157
  z.safeDecode(z_BlockOverrides.BlockOverrides, {
@@ -56,4 +56,16 @@ describe('Signature', () => {
56
56
  ).toBe(false)
57
57
  expect(z.safeDecode(z_Signature.Tuple, ['0x2', r, s]).success).toBe(false)
58
58
  })
59
+
60
+ test('decodes legacy signatures with EIP-155 v above 255', () => {
61
+ // Polygon (chain ID 137): v = 137 * 2 + 35 + 1 = 310.
62
+ expect(z.decode(z_Signature.Legacy, { r, s, v: '0x136' }))
63
+ .toMatchInlineSnapshot(`
64
+ {
65
+ "r": "0x1111111111111111111111111111111111111111111111111111111111111111",
66
+ "s": "0x2222222222222222222222222222222222222222222222222222222222222222",
67
+ "v": 310,
68
+ }
69
+ `)
70
+ })
59
71
  })