ox 0.14.68 → 0.14.70

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 (69) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/_cjs/core/Authorization.js +2 -0
  3. package/_cjs/core/Authorization.js.map +1 -1
  4. package/_cjs/core/BinaryStateTree.js +1 -1
  5. package/_cjs/core/BinaryStateTree.js.map +1 -1
  6. package/_cjs/core/Block.js +1 -0
  7. package/_cjs/core/Block.js.map +1 -1
  8. package/_cjs/core/BlockOverrides.js +1 -1
  9. package/_cjs/core/BlockOverrides.js.map +1 -1
  10. package/_cjs/core/Siwe.js +33 -7
  11. package/_cjs/core/Siwe.js.map +1 -1
  12. package/_cjs/core/Transaction.js +4 -1
  13. package/_cjs/core/Transaction.js.map +1 -1
  14. package/_cjs/core/internal/ens.js +4 -4
  15. package/_cjs/core/internal/ens.js.map +1 -1
  16. package/_cjs/version.js +1 -1
  17. package/_esm/core/AbiError.js +2 -2
  18. package/_esm/core/AbiEvent.js +2 -2
  19. package/_esm/core/Authorization.js +3 -0
  20. package/_esm/core/Authorization.js.map +1 -1
  21. package/_esm/core/BinaryStateTree.js +3 -1
  22. package/_esm/core/BinaryStateTree.js.map +1 -1
  23. package/_esm/core/Blobs.js +2 -2
  24. package/_esm/core/Block.js +1 -0
  25. package/_esm/core/Block.js.map +1 -1
  26. package/_esm/core/BlockOverrides.js +3 -2
  27. package/_esm/core/BlockOverrides.js.map +1 -1
  28. package/_esm/core/Ens.js +1 -1
  29. package/_esm/core/Hash.js +1 -1
  30. package/_esm/core/Siwe.js +38 -8
  31. package/_esm/core/Siwe.js.map +1 -1
  32. package/_esm/core/Transaction.js +5 -1
  33. package/_esm/core/Transaction.js.map +1 -1
  34. package/_esm/core/TypedData.js +2 -2
  35. package/_esm/core/internal/ens.js +1 -1
  36. package/_esm/core/internal/ens.js.map +1 -1
  37. package/_esm/version.js +1 -1
  38. package/_types/core/AbiError.d.ts +3 -3
  39. package/_types/core/AbiEvent.d.ts +2 -2
  40. package/_types/core/Authorization.d.ts.map +1 -1
  41. package/_types/core/Blobs.d.ts +2 -2
  42. package/_types/core/Block.d.ts +2 -0
  43. package/_types/core/Block.d.ts.map +1 -1
  44. package/_types/core/BlockOverrides.d.ts +2 -1
  45. package/_types/core/BlockOverrides.d.ts.map +1 -1
  46. package/_types/core/Ens.d.ts +1 -1
  47. package/_types/core/Hash.d.ts +1 -1
  48. package/_types/core/Siwe.d.ts +1 -0
  49. package/_types/core/Siwe.d.ts.map +1 -1
  50. package/_types/core/Transaction.d.ts.map +1 -1
  51. package/_types/core/TypedData.d.ts +2 -2
  52. package/_types/core/internal/ens.d.ts +1 -1
  53. package/_types/core/internal/ens.d.ts.map +1 -1
  54. package/_types/version.d.ts +1 -1
  55. package/core/AbiError.ts +3 -3
  56. package/core/AbiEvent.ts +2 -2
  57. package/core/Authorization.ts +3 -0
  58. package/core/BinaryStateTree.ts +4 -1
  59. package/core/Blobs.ts +2 -2
  60. package/core/Block.ts +3 -0
  61. package/core/BlockOverrides.ts +3 -2
  62. package/core/Ens.ts +1 -1
  63. package/core/Hash.ts +1 -1
  64. package/core/Siwe.ts +39 -8
  65. package/core/Transaction.ts +5 -1
  66. package/core/TypedData.ts +2 -2
  67. package/core/internal/ens.ts +1 -1
  68. package/package.json +1 -1
  69. package/version.ts +1 -1
package/core/Block.ts CHANGED
@@ -48,6 +48,8 @@ export type Block<
48
48
  parentHash: Hex.Hex
49
49
  /** Root of the this block’s receipts trie */
50
50
  receiptsRoot: Hex.Hex
51
+ /** EIP-7685 requests hash */
52
+ requestsHash?: Hex.Hex | undefined
51
53
  sealFields?: readonly Hex.Hex[] | undefined
52
54
  /** SHA3 of the uncles data in this block */
53
55
  sha3Uncles: Hex.Hex
@@ -185,6 +187,7 @@ export function toRpc<
185
187
  parentBeaconBlockRoot: block.parentBeaconBlockRoot,
186
188
  parentHash: block.parentHash,
187
189
  receiptsRoot: block.receiptsRoot,
190
+ requestsHash: block.requestsHash,
188
191
  sealFields: block.sealFields,
189
192
  sha3Uncles: block.sha3Uncles,
190
193
  size: Hex.fromNumber(block.size),
@@ -42,7 +42,8 @@ export type Rpc = BlockOverrides<Hex.Hex, Hex.Hex>
42
42
  * feeRecipient: '0x0000000000000000000000000000000000000000',
43
43
  * gasLimit: '0x4',
44
44
  * number: '0x5',
45
- * prevRandao: '0x6',
45
+ * prevRandao:
46
+ * '0x0000000000000000000000000000000000000000000000000000000000000006',
46
47
  * time: '0x1234567890',
47
48
  * withdrawals: [
48
49
  * {
@@ -134,7 +135,7 @@ export function toRpc(blockOverrides: BlockOverrides): Rpc {
134
135
  number: Hex.fromNumber(blockOverrides.number),
135
136
  }),
136
137
  ...(typeof blockOverrides.prevRandao === 'bigint' && {
137
- prevRandao: Hex.fromNumber(blockOverrides.prevRandao),
138
+ prevRandao: Hex.fromNumber(blockOverrides.prevRandao, { size: 32 }),
138
139
  }),
139
140
  ...(typeof blockOverrides.time === 'bigint' && {
140
141
  time: Hex.fromNumber(blockOverrides.time),
package/core/Ens.ts CHANGED
@@ -46,7 +46,7 @@ export declare namespace labelhash {
46
46
  * ```ts twoslash
47
47
  * import { Ens } from 'ox'
48
48
  * Ens.namehash('wevm.eth')
49
- * // @log: '0xf246651c1b9a6b141d19c2604e9a58f567973833990f830d882534a747801359'
49
+ * // @log: '0x08c85f2f4059e930c45a6aeff9dcd3bd95dc3c5c1cddef6a0626b31152248560'
50
50
  * ```
51
51
  *
52
52
  * @param name - ENS name.
package/core/Hash.ts CHANGED
@@ -26,7 +26,7 @@ import * as Hex from './Hex.js'
26
26
  * import { Hash, Hex } from 'ox'
27
27
  *
28
28
  * Hash.keccak256(Hex.fromString('hello world'))
29
- * // @log: '0x3ea2f1d0abf3fc66cf29eebb70cbd4e7fe762ef8a09bcc06c8edf641230afec0'
29
+ * // @log: '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad'
30
30
  * ```
31
31
  *
32
32
  * @example
package/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+-.]*):\/\/)?(?<domain>[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)?/
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
- if (statement?.includes('\n'))
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
  ],
@@ -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 && path.length >= 0)) return false
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 (scheme && message.scheme !== scheme) return false
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
  /**
@@ -498,8 +498,12 @@ export function toRpc<pending extends boolean = false>(
498
498
  rpc.r = Hex.fromNumber(transaction.r, { size: 32 })
499
499
  if (typeof transaction.s === 'bigint')
500
500
  rpc.s = Hex.fromNumber(transaction.s, { size: 32 })
501
+ // Legacy EIP-155 `v` is unsized; typed transactions keep a single byte.
501
502
  if (typeof transaction.v === 'number')
502
- rpc.v = Hex.fromNumber(transaction.v, { size: 1 })
503
+ rpc.v =
504
+ transaction.type === 'legacy'
505
+ ? Hex.fromNumber(transaction.v)
506
+ : Hex.fromNumber(transaction.v, { size: 1 })
503
507
  if (typeof transaction.yParity === 'number')
504
508
  rpc.yParity = transaction.yParity === 0 ? '0x0' : '0x1'
505
509
 
package/core/TypedData.ts CHANGED
@@ -493,7 +493,7 @@ export declare namespace getSignPayload {
493
493
  * verifyingContract: '0x0000000000000000000000000000000000000000',
494
494
  * },
495
495
  * })
496
- * // @log: '0x6192106f129ce05c9075d319c1fa6ea9b3ae37cbd0c1ef92e2be7137bb07baa1'
496
+ * // @log: '0x2fdf3441fcaf4f30c7e16292b258a5d7054a4e2e00dbd7b7d2f467f2b8fb9413'
497
497
  * ```
498
498
  *
499
499
  * @param value - The Typed Data domain and types.
@@ -549,7 +549,7 @@ export declare namespace hashDomain {
549
549
  * foo: '0xb9CAB4F0E46F7F6b1024b5A7463734fa68E633f9',
550
550
  * },
551
551
  * })
552
- * // @log: '0x996fb3b6d48c50312d69abdd4c1b6fb02057c85aa86bb8d04c6f023326a168ce'
552
+ * // @log: '0x4305429dd165189369e3373e404dac11fa3bc66d93d5231b00198cb578d402e0'
553
553
  * ```
554
554
  *
555
555
  * @param value - The Typed Data struct to hash.
@@ -1,4 +1,4 @@
1
- import { Bytes } from '../../index.js'
1
+ import * as Bytes from '../Bytes.js'
2
2
  import * as Ens from '../Ens.js'
3
3
  import type * as Errors from '../Errors.js'
4
4
  import * as Hex from '../Hex.js'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ox",
3
3
  "description": "Ethereum Standard Library",
4
- "version": "0.14.68",
4
+ "version": "0.14.70",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
package/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** @internal */
2
- export const version = '0.14.68'
2
+ export const version = '0.14.70'