ox 0.14.68 → 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.
Files changed (62) hide show
  1. package/CHANGELOG.md +26 -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/version.js +1 -1
  15. package/_esm/core/AbiError.js +2 -2
  16. package/_esm/core/AbiEvent.js +2 -2
  17. package/_esm/core/Authorization.js +3 -0
  18. package/_esm/core/Authorization.js.map +1 -1
  19. package/_esm/core/BinaryStateTree.js +3 -1
  20. package/_esm/core/BinaryStateTree.js.map +1 -1
  21. package/_esm/core/Blobs.js +2 -2
  22. package/_esm/core/Block.js +1 -0
  23. package/_esm/core/Block.js.map +1 -1
  24. package/_esm/core/BlockOverrides.js +3 -2
  25. package/_esm/core/BlockOverrides.js.map +1 -1
  26. package/_esm/core/Ens.js +1 -1
  27. package/_esm/core/Hash.js +1 -1
  28. package/_esm/core/Siwe.js +38 -8
  29. package/_esm/core/Siwe.js.map +1 -1
  30. package/_esm/core/Transaction.js +5 -1
  31. package/_esm/core/Transaction.js.map +1 -1
  32. package/_esm/core/TypedData.js +2 -2
  33. package/_esm/version.js +1 -1
  34. package/_types/core/AbiError.d.ts +3 -3
  35. package/_types/core/AbiEvent.d.ts +2 -2
  36. package/_types/core/Authorization.d.ts.map +1 -1
  37. package/_types/core/Blobs.d.ts +2 -2
  38. package/_types/core/Block.d.ts +2 -0
  39. package/_types/core/Block.d.ts.map +1 -1
  40. package/_types/core/BlockOverrides.d.ts +2 -1
  41. package/_types/core/BlockOverrides.d.ts.map +1 -1
  42. package/_types/core/Ens.d.ts +1 -1
  43. package/_types/core/Hash.d.ts +1 -1
  44. package/_types/core/Siwe.d.ts +1 -0
  45. package/_types/core/Siwe.d.ts.map +1 -1
  46. package/_types/core/Transaction.d.ts.map +1 -1
  47. package/_types/core/TypedData.d.ts +2 -2
  48. package/_types/version.d.ts +1 -1
  49. package/core/AbiError.ts +3 -3
  50. package/core/AbiEvent.ts +2 -2
  51. package/core/Authorization.ts +3 -0
  52. package/core/BinaryStateTree.ts +4 -1
  53. package/core/Blobs.ts +2 -2
  54. package/core/Block.ts +3 -0
  55. package/core/BlockOverrides.ts +3 -2
  56. package/core/Ens.ts +1 -1
  57. package/core/Hash.ts +1 -1
  58. package/core/Siwe.ts +39 -8
  59. package/core/Transaction.ts +5 -1
  60. package/core/TypedData.ts +2 -2
  61. package/package.json +1 -1
  62. package/version.ts +1 -1
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.
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.69",
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.69'