ox 1.8.15 → 1.8.18

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 (292) hide show
  1. package/CHANGELOG.md +108 -0
  2. package/dist/core/AbiError.d.ts +52 -6
  3. package/dist/core/AbiError.d.ts.map +1 -1
  4. package/dist/core/AbiError.js +60 -4
  5. package/dist/core/AbiError.js.map +1 -1
  6. package/dist/core/AbiEvent.d.ts +5 -3
  7. package/dist/core/AbiEvent.d.ts.map +1 -1
  8. package/dist/core/AbiEvent.js +89 -58
  9. package/dist/core/AbiEvent.js.map +1 -1
  10. package/dist/core/AbiFunction.d.ts +48 -2
  11. package/dist/core/AbiFunction.d.ts.map +1 -1
  12. package/dist/core/AbiFunction.js +59 -3
  13. package/dist/core/AbiFunction.js.map +1 -1
  14. package/dist/core/AbiItem.d.ts.map +1 -1
  15. package/dist/core/AbiItem.js +15 -5
  16. package/dist/core/AbiItem.js.map +1 -1
  17. package/dist/core/AbiParameters.d.ts +1 -1
  18. package/dist/core/AbiParameters.d.ts.map +1 -1
  19. package/dist/core/AbiParameters.js +8 -2
  20. package/dist/core/AbiParameters.js.map +1 -1
  21. package/dist/core/Address.d.ts +17 -2
  22. package/dist/core/Address.d.ts.map +1 -1
  23. package/dist/core/Address.js +17 -1
  24. package/dist/core/Address.js.map +1 -1
  25. package/dist/core/Authorization.d.ts +24 -2
  26. package/dist/core/Authorization.d.ts.map +1 -1
  27. package/dist/core/Authorization.js +29 -2
  28. package/dist/core/Authorization.js.map +1 -1
  29. package/dist/core/Base58.d.ts.map +1 -1
  30. package/dist/core/Base58.js +16 -4
  31. package/dist/core/Base58.js.map +1 -1
  32. package/dist/core/Blobs.d.ts +2 -3
  33. package/dist/core/Blobs.d.ts.map +1 -1
  34. package/dist/core/Blobs.js +38 -43
  35. package/dist/core/Blobs.js.map +1 -1
  36. package/dist/core/Bytes.d.ts.map +1 -1
  37. package/dist/core/Bytes.js +10 -2
  38. package/dist/core/Bytes.js.map +1 -1
  39. package/dist/core/Cbor.d.ts +13 -6
  40. package/dist/core/Cbor.d.ts.map +1 -1
  41. package/dist/core/Cbor.js +31 -18
  42. package/dist/core/Cbor.js.map +1 -1
  43. package/dist/core/Ens.js +2 -2
  44. package/dist/core/Ens.js.map +1 -1
  45. package/dist/core/FrameReceipt.d.ts.map +1 -1
  46. package/dist/core/FrameReceipt.js +4 -1
  47. package/dist/core/FrameReceipt.js.map +1 -1
  48. package/dist/core/Hex.d.ts.map +1 -1
  49. package/dist/core/Hex.js +34 -31
  50. package/dist/core/Hex.js.map +1 -1
  51. package/dist/core/Keystore.d.ts +31 -2
  52. package/dist/core/Keystore.d.ts.map +1 -1
  53. package/dist/core/Keystore.js +28 -2
  54. package/dist/core/Keystore.js.map +1 -1
  55. package/dist/core/Rlp.d.ts +1 -1
  56. package/dist/core/Rlp.d.ts.map +1 -1
  57. package/dist/core/Rlp.js +107 -0
  58. package/dist/core/Rlp.js.map +1 -1
  59. package/dist/core/RpcTransport.d.ts.map +1 -1
  60. package/dist/core/RpcTransport.js +3 -1
  61. package/dist/core/RpcTransport.js.map +1 -1
  62. package/dist/core/Secp256k1.d.ts.map +1 -1
  63. package/dist/core/Secp256k1.js +4 -1
  64. package/dist/core/Secp256k1.js.map +1 -1
  65. package/dist/core/Signature.d.ts +1 -1
  66. package/dist/core/Signature.d.ts.map +1 -1
  67. package/dist/core/Signature.js +4 -2
  68. package/dist/core/Signature.js.map +1 -1
  69. package/dist/core/Siwe.d.ts +4 -0
  70. package/dist/core/Siwe.d.ts.map +1 -1
  71. package/dist/core/Siwe.js +29 -3
  72. package/dist/core/Siwe.js.map +1 -1
  73. package/dist/core/Transaction.d.ts.map +1 -1
  74. package/dist/core/Transaction.js +4 -2
  75. package/dist/core/Transaction.js.map +1 -1
  76. package/dist/core/TransactionReceipt.d.ts.map +1 -1
  77. package/dist/core/TransactionReceipt.js +8 -2
  78. package/dist/core/TransactionReceipt.js.map +1 -1
  79. package/dist/core/TxEnvelopeEip1559.d.ts.map +1 -1
  80. package/dist/core/TxEnvelopeEip1559.js +2 -1
  81. package/dist/core/TxEnvelopeEip1559.js.map +1 -1
  82. package/dist/core/TxEnvelopeEip2930.d.ts.map +1 -1
  83. package/dist/core/TxEnvelopeEip2930.js +2 -1
  84. package/dist/core/TxEnvelopeEip2930.js.map +1 -1
  85. package/dist/core/TxEnvelopeEip7702.d.ts +1 -1
  86. package/dist/core/TxEnvelopeEip7702.d.ts.map +1 -1
  87. package/dist/core/TxEnvelopeEip7702.js +6 -1
  88. package/dist/core/TxEnvelopeEip7702.js.map +1 -1
  89. package/dist/core/TxEnvelopeLegacy.d.ts.map +1 -1
  90. package/dist/core/TxEnvelopeLegacy.js +49 -7
  91. package/dist/core/TxEnvelopeLegacy.js.map +1 -1
  92. package/dist/core/TypedData.d.ts +3 -1
  93. package/dist/core/TypedData.d.ts.map +1 -1
  94. package/dist/core/TypedData.js +23 -11
  95. package/dist/core/TypedData.js.map +1 -1
  96. package/dist/core/Value.d.ts.map +1 -1
  97. package/dist/core/Value.js +14 -3
  98. package/dist/core/Value.js.map +1 -1
  99. package/dist/core/internal/abiParameters.d.ts +3 -3
  100. package/dist/core/internal/abiParameters.d.ts.map +1 -1
  101. package/dist/core/internal/abiParameters.js +99 -69
  102. package/dist/core/internal/abiParameters.js.map +1 -1
  103. package/dist/core/internal/base58.d.ts.map +1 -1
  104. package/dist/core/internal/base58.js +9 -3
  105. package/dist/core/internal/base58.js.map +1 -1
  106. package/dist/core/internal/caches.d.ts +6 -0
  107. package/dist/core/internal/caches.d.ts.map +1 -1
  108. package/dist/core/internal/caches.js +3 -1
  109. package/dist/core/internal/caches.js.map +1 -1
  110. package/dist/core/internal/codec/hex.d.ts +13 -0
  111. package/dist/core/internal/codec/hex.d.ts.map +1 -1
  112. package/dist/core/internal/codec/hex.js +25 -2
  113. package/dist/core/internal/codec/hex.js.map +1 -1
  114. package/dist/core/internal/codec/int.d.ts.map +1 -1
  115. package/dist/core/internal/codec/int.js +48 -32
  116. package/dist/core/internal/codec/int.js.map +1 -1
  117. package/dist/core/internal/cursor.d.ts +24 -4
  118. package/dist/core/internal/cursor.d.ts.map +1 -1
  119. package/dist/core/internal/cursor.js +62 -11
  120. package/dist/core/internal/cursor.js.map +1 -1
  121. package/dist/core/internal/lru.d.ts +11 -12
  122. package/dist/core/internal/lru.d.ts.map +1 -1
  123. package/dist/core/internal/lru.js +22 -32
  124. package/dist/core/internal/lru.js.map +1 -1
  125. package/dist/core/internal/promise.d.ts.map +1 -1
  126. package/dist/core/internal/promise.js +13 -7
  127. package/dist/core/internal/promise.js.map +1 -1
  128. package/dist/erc4337/UserOperation.d.ts.map +1 -1
  129. package/dist/erc4337/UserOperation.js +1 -3
  130. package/dist/erc4337/UserOperation.js.map +1 -1
  131. package/dist/erc6492/SignatureErc6492.d.ts +1 -1
  132. package/dist/erc6492/SignatureErc6492.d.ts.map +1 -1
  133. package/dist/erc6492/SignatureErc6492.js +1 -1
  134. package/dist/erc6492/SignatureErc6492.js.map +1 -1
  135. package/dist/erc7821/Execute.d.ts +45 -0
  136. package/dist/erc7821/Execute.d.ts.map +1 -1
  137. package/dist/erc7821/Execute.js +70 -2
  138. package/dist/erc7821/Execute.js.map +1 -1
  139. package/dist/index.d.ts +1 -1
  140. package/dist/index.js +1 -1
  141. package/dist/tempo/KeyAuthorization.d.ts +9 -3
  142. package/dist/tempo/KeyAuthorization.d.ts.map +1 -1
  143. package/dist/tempo/KeyAuthorization.js +16 -0
  144. package/dist/tempo/KeyAuthorization.js.map +1 -1
  145. package/dist/tempo/SignatureEnvelope.d.ts +1 -1
  146. package/dist/tempo/SignatureEnvelope.d.ts.map +1 -1
  147. package/dist/tempo/SignatureEnvelope.js +53 -54
  148. package/dist/tempo/SignatureEnvelope.js.map +1 -1
  149. package/dist/tempo/TransactionReceipt.d.ts.map +1 -1
  150. package/dist/tempo/TransactionReceipt.js +4 -1
  151. package/dist/tempo/TransactionReceipt.js.map +1 -1
  152. package/dist/tempo/TransactionRequest.d.ts +1 -1
  153. package/dist/tempo/TransactionRequest.d.ts.map +1 -1
  154. package/dist/tempo/TransactionRequest.js +5 -2
  155. package/dist/tempo/TransactionRequest.js.map +1 -1
  156. package/dist/tempo/TxEnvelopeTempo.d.ts +30 -1
  157. package/dist/tempo/TxEnvelopeTempo.d.ts.map +1 -1
  158. package/dist/tempo/TxEnvelopeTempo.js +51 -2
  159. package/dist/tempo/TxEnvelopeTempo.js.map +1 -1
  160. package/dist/tempo/ZoneId.d.ts +3 -1
  161. package/dist/tempo/ZoneId.d.ts.map +1 -1
  162. package/dist/tempo/ZoneId.js +7 -1
  163. package/dist/tempo/ZoneId.js.map +1 -1
  164. package/dist/tempo/internal/virtualMasterPool.d.ts.map +1 -1
  165. package/dist/tempo/internal/virtualMasterPool.js +17 -6
  166. package/dist/tempo/internal/virtualMasterPool.js.map +1 -1
  167. package/dist/tempo/internal/webauthnData.d.ts +23 -0
  168. package/dist/tempo/internal/webauthnData.d.ts.map +1 -0
  169. package/dist/tempo/internal/webauthnData.js +75 -0
  170. package/dist/tempo/internal/webauthnData.js.map +1 -0
  171. package/dist/webauthn/Registration.d.ts +2 -0
  172. package/dist/webauthn/Registration.d.ts.map +1 -1
  173. package/dist/webauthn/Registration.js +2 -6
  174. package/dist/webauthn/Registration.js.map +1 -1
  175. package/dist/zod/TypedData.d.ts +4 -4
  176. package/dist/zod/tempo/KeyAuthorization.d.ts.map +1 -1
  177. package/dist/zod/tempo/KeyAuthorization.js +4 -2
  178. package/dist/zod/tempo/KeyAuthorization.js.map +1 -1
  179. package/dist/zod/tempo/SignatureEnvelope.d.ts.map +1 -1
  180. package/dist/zod/tempo/SignatureEnvelope.js +29 -29
  181. package/dist/zod/tempo/SignatureEnvelope.js.map +1 -1
  182. package/package.json +2 -2
  183. package/src/core/AbiError.ts +82 -8
  184. package/src/core/AbiEvent.bench.ts +45 -0
  185. package/src/core/AbiEvent.ts +120 -68
  186. package/src/core/AbiFunction.bench.ts +16 -0
  187. package/src/core/AbiFunction.ts +76 -4
  188. package/src/core/AbiItem.ts +13 -4
  189. package/src/core/AbiParameters.bench.ts +33 -0
  190. package/src/core/AbiParameters.ts +8 -1
  191. package/src/core/Address.ts +18 -1
  192. package/src/core/Authorization.ts +34 -4
  193. package/src/core/Base58.bench.ts +28 -0
  194. package/src/core/Base58.ts +15 -4
  195. package/src/core/Blobs.bench.ts +40 -0
  196. package/src/core/Blobs.ts +47 -55
  197. package/src/core/Bytes.bench.ts +34 -0
  198. package/src/core/Bytes.ts +10 -2
  199. package/src/core/Cbor.ts +36 -14
  200. package/src/core/Ens.ts +2 -2
  201. package/src/core/FrameReceipt.ts +4 -1
  202. package/src/core/Hex.bench.ts +17 -0
  203. package/src/core/Hex.ts +29 -32
  204. package/src/core/Keystore.ts +40 -3
  205. package/src/core/Rlp.ts +139 -1
  206. package/src/core/Rlp_tx.bench.ts +55 -0
  207. package/src/core/RpcTransport.ts +3 -1
  208. package/src/core/Secp256k1.ts +4 -1
  209. package/src/core/Signature.ts +7 -3
  210. package/src/core/Siwe.ts +29 -3
  211. package/src/core/Transaction.ts +4 -2
  212. package/src/core/TransactionReceipt.ts +8 -2
  213. package/src/core/TxEnvelopeEip1559.ts +4 -1
  214. package/src/core/TxEnvelopeEip2930.ts +4 -1
  215. package/src/core/TxEnvelopeEip7702.ts +9 -2
  216. package/src/core/TxEnvelopeLegacy.ts +58 -7
  217. package/src/core/TypedData.bench.ts +50 -0
  218. package/src/core/TypedData.ts +24 -11
  219. package/src/core/Value.ts +14 -3
  220. package/src/core/_test/AbiError.test.ts +105 -2
  221. package/src/core/_test/AbiEvent.fuzz.ts +1 -1
  222. package/src/core/_test/AbiEvent.test-d.ts +46 -0
  223. package/src/core/_test/AbiEvent.test.ts +646 -11
  224. package/src/core/_test/AbiFunction.test.ts +79 -6
  225. package/src/core/_test/AbiParameters.adversarial.fuzz.ts +1 -0
  226. package/src/core/_test/AbiParameters.decode.test.ts +143 -0
  227. package/src/core/_test/AbiParameters.encode.test.ts +36 -1
  228. package/src/core/_test/AbiParameters.test.ts +15 -0
  229. package/src/core/_test/Address.test.ts +41 -0
  230. package/src/core/_test/Authorization.test.ts +130 -0
  231. package/src/core/_test/Bytes.test.ts +33 -0
  232. package/src/core/_test/Caches.test.ts +20 -1
  233. package/src/core/_test/Cbor.test.ts +26 -0
  234. package/src/core/_test/FrameReceipt.test.ts +13 -0
  235. package/src/core/_test/Keystore.test.ts +65 -1
  236. package/src/core/_test/Rlp.fuzz.ts +55 -1
  237. package/src/core/_test/Rlp.test.ts +64 -0
  238. package/src/core/_test/RpcTransport.test.ts +15 -2
  239. package/src/core/_test/Secp256k1.test.ts +36 -0
  240. package/src/core/_test/Signature.test.ts +102 -0
  241. package/src/core/_test/Siwe.test.ts +123 -0
  242. package/src/core/_test/Transaction.test.ts +17 -0
  243. package/src/core/_test/TransactionEnvelopeEip1559.test.ts +28 -0
  244. package/src/core/_test/TransactionEnvelopeEip2930.test.ts +28 -0
  245. package/src/core/_test/TransactionEnvelopeEip7702.test.ts +133 -0
  246. package/src/core/_test/TransactionEnvelopeLegacy.test.ts +322 -1
  247. package/src/core/_test/TransactionReceipt.test.ts +41 -0
  248. package/src/core/_test/TypedData.test.ts +197 -0
  249. package/src/core/_test/Value.test.ts +21 -0
  250. package/src/core/_test/internal/cursor.test.ts +71 -0
  251. package/src/core/internal/abiParameters.ts +123 -81
  252. package/src/core/internal/base58.ts +9 -3
  253. package/src/core/internal/caches.ts +3 -1
  254. package/src/core/internal/codec/hex.ts +27 -2
  255. package/src/core/internal/codec/int.ts +45 -32
  256. package/src/core/internal/cursor.ts +84 -19
  257. package/src/core/internal/lru.ts +21 -35
  258. package/src/core/internal/promise.ts +11 -5
  259. package/src/erc4337/UserOperation.ts +3 -4
  260. package/src/erc4337/_test/UserOperation.test.ts +59 -1
  261. package/src/erc6492/SignatureErc6492.ts +1 -1
  262. package/src/erc6492/_test/SignatureErc6492.test.ts +48 -1
  263. package/src/erc7821/Execute.ts +83 -2
  264. package/src/erc7821/_test/Execute.test.ts +217 -1
  265. package/src/index.ts +1 -1
  266. package/src/tempo/KeyAuthorization.test.ts +91 -0
  267. package/src/tempo/KeyAuthorization.ts +32 -3
  268. package/src/tempo/SignatureEnvelope.test.ts +300 -28
  269. package/src/tempo/SignatureEnvelope.ts +62 -54
  270. package/src/tempo/TransactionReceipt.test.ts +8 -0
  271. package/src/tempo/TransactionReceipt.ts +4 -1
  272. package/src/tempo/TransactionRequest.test.ts +30 -0
  273. package/src/tempo/TransactionRequest.ts +7 -2
  274. package/src/tempo/TxEnvelopeTempo.test.ts +310 -0
  275. package/src/tempo/TxEnvelopeTempo.ts +64 -1
  276. package/src/tempo/VirtualMaster.bench.ts +7 -0
  277. package/src/tempo/ZoneId.test.ts +11 -0
  278. package/src/tempo/ZoneId.ts +7 -1
  279. package/src/tempo/configurableAccounts.e2e.test.ts +1 -1
  280. package/src/tempo/internal/virtualMasterPool.ts +20 -6
  281. package/src/tempo/internal/webauthnData.ts +84 -0
  282. package/src/version.ts +1 -1
  283. package/src/webauthn/Registration.ts +4 -6
  284. package/src/webauthn/_test/Registration.browser.test.ts +14 -0
  285. package/src/webauthn/_test/Registration.test.ts +60 -0
  286. package/src/zod/tempo/KeyAuthorization.ts +12 -5
  287. package/src/zod/tempo/SignatureEnvelope.ts +38 -32
  288. package/src/zod/tempo/_test/KeyAuthorization.test.ts +36 -0
  289. package/src/zod/tempo/_test/SignatureEnvelope.test.ts +138 -4
  290. package/src/core/_test/internal/lru.test.ts +0 -38
  291. package/src/core/_test/internal/uid.test.ts +0 -7
  292. package/src/core/internal/uid.ts +0 -15
@@ -46,6 +46,19 @@ describe('fromRpc', () => {
46
46
  status: expected,
47
47
  })
48
48
  })
49
+
50
+ test('behavior: unknown status named like an `Object.prototype` key', () => {
51
+ for (const status of ['__proto__', 'constructor', 'toString'])
52
+ expect(
53
+ FrameReceipt.fromRpc({
54
+ executionGasUsed: '0x0',
55
+ gasUsed: '0x0',
56
+ logs: [],
57
+ stateGasUsed: '0x0',
58
+ status: status as never,
59
+ }).status,
60
+ ).toBeUndefined()
61
+ })
49
62
  })
50
63
 
51
64
  describe('toRpc', () => {
@@ -1,6 +1,6 @@
1
1
  // Vectors from https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition
2
2
 
3
- import { Bytes, Keystore } from 'ox'
3
+ import { Bytes, Hex, Keystore } from 'ox'
4
4
  import { describe, expect, test } from 'vp/test'
5
5
 
6
6
  describe('encrypt/decrypt', () => {
@@ -320,6 +320,70 @@ describe('encrypt/decrypt', () => {
320
320
  const decrypted = Keystore.decrypt(encrypted, key())
321
321
  expect(decrypted).toEqual(secret)
322
322
  })
323
+
324
+ test('behavior: key longer than 32 bytes', () => {
325
+ const [key, opts] = Keystore.scrypt({
326
+ iv: '0x83dbcc02d8ccb40e466191a123791e0e',
327
+ salt: '0xab0c7876052600dd703518d6fc3fe8984592145b591fc8fb5c6d43190334ba19',
328
+ password: 'testpassword',
329
+ n: 1024,
330
+ })
331
+ const longKey = Hex.concat(key(), '0xdeadbeef')
332
+
333
+ const secret =
334
+ '0x7a28b5ba57c53603b0b07b56bba752f7784bf506fa95edc395f5cf6c7514fe9d'
335
+
336
+ const encrypted = Keystore.encrypt(secret, longKey, { ...opts, id: 'id' })
337
+ expect(encrypted).toEqual(
338
+ Keystore.encrypt(secret, key(), { ...opts, id: 'id' }),
339
+ )
340
+ expect(Keystore.decrypt(encrypted, longKey)).toEqual(secret)
341
+ })
342
+
343
+ test('error: key shorter than 32 bytes', () => {
344
+ const [key, opts] = Keystore.scrypt({
345
+ iv: '0x83dbcc02d8ccb40e466191a123791e0e',
346
+ salt: '0xab0c7876052600dd703518d6fc3fe8984592145b591fc8fb5c6d43190334ba19',
347
+ password: 'testpassword',
348
+ n: 1024,
349
+ })
350
+
351
+ const secret =
352
+ '0x7a28b5ba57c53603b0b07b56bba752f7784bf506fa95edc395f5cf6c7514fe9d'
353
+ const encrypted = Keystore.encrypt(secret, key(), opts)
354
+
355
+ expect(() =>
356
+ Keystore.encrypt(secret, Hex.slice(key(), 0, 17), opts),
357
+ ).toThrowErrorMatchingInlineSnapshot(
358
+ `[Keystore.InvalidKeySizeError: Key must contain at least 32 bytes. Received 17 bytes.]`,
359
+ )
360
+ expect(() =>
361
+ Keystore.encrypt(secret, Hex.slice(key(), 0, 31), opts),
362
+ ).toThrowErrorMatchingInlineSnapshot(
363
+ `[Keystore.InvalidKeySizeError: Key must contain at least 32 bytes. Received 31 bytes.]`,
364
+ )
365
+ expect(() =>
366
+ Keystore.encrypt(secret, () => Hex.slice(key(), 0, 31), opts),
367
+ ).toThrowErrorMatchingInlineSnapshot(
368
+ `[Keystore.InvalidKeySizeError: Key must contain at least 32 bytes. Received 31 bytes.]`,
369
+ )
370
+
371
+ expect(() =>
372
+ Keystore.decrypt(encrypted, Hex.slice(key(), 0, 17)),
373
+ ).toThrowErrorMatchingInlineSnapshot(
374
+ `[Keystore.InvalidKeySizeError: Key must contain at least 32 bytes. Received 17 bytes.]`,
375
+ )
376
+ expect(() =>
377
+ Keystore.decrypt(encrypted, Hex.slice(key(), 0, 31)),
378
+ ).toThrowErrorMatchingInlineSnapshot(
379
+ `[Keystore.InvalidKeySizeError: Key must contain at least 32 bytes. Received 31 bytes.]`,
380
+ )
381
+ expect(() =>
382
+ Keystore.decrypt(encrypted, () => Hex.slice(key(), 0, 31)),
383
+ ).toThrowErrorMatchingInlineSnapshot(
384
+ `[Keystore.InvalidKeySizeError: Key must contain at least 32 bytes. Received 31 bytes.]`,
385
+ )
386
+ })
323
387
  })
324
388
 
325
389
  describe('pbkdf2', () => {
@@ -1,4 +1,4 @@
1
- import { test } from '@fast-check/vitest'
1
+ import { fc, test } from '@fast-check/vitest'
2
2
  import { type Bytes, Hex, Rlp } from 'ox'
3
3
  import { describe, expect } from 'vp/test'
4
4
 
@@ -36,8 +36,62 @@ describe('Rlp round-trip', () => {
36
36
  expect(asHex).toEqual(Hex.fromBytes(asBytes))
37
37
  },
38
38
  )
39
+
40
+ test.prop(
41
+ {
42
+ edit: fc.tuple(
43
+ fc.nat(),
44
+ fc.nat(0xff),
45
+ fc.constantFrom('cut', 'set', 'add', 'char'),
46
+ ),
47
+ tree: arbitraryRecursiveRlpHex(),
48
+ },
49
+ { numRuns },
50
+ )(
51
+ 'hex and bytes decode paths agree on mutated encodings, errors included',
52
+ ({ edit: [at, byte, kind], tree }) => {
53
+ const body = Rlp.from(tree, { as: 'Hex' }).slice(2)
54
+ const index = (at % (body.length / 2 + 1)) * 2
55
+ const pair = byte.toString(16).padStart(2, '0')
56
+ const mutated = `0x${(() => {
57
+ if (kind === 'cut') return body.slice(0, index)
58
+ if (kind === 'set')
59
+ return `${body.slice(0, index)}${pair}${body.slice(index + 2)}`
60
+ if (kind === 'add')
61
+ return `${body.slice(0, index)}${pair}${body.slice(index)}`
62
+ return `${body.slice(0, index)}g${body.slice(index + 1)}`
63
+ })()}` as Hex.Hex
64
+ expect(outcome(() => Rlp.toHex(mutated))).toEqual(
65
+ outcome(() => normalizeBytesToHex(Rlp.toBytes(mutated))),
66
+ )
67
+ },
68
+ )
39
69
  })
40
70
 
71
+ /**
72
+ * Returns a decode result or its error, so that two decode paths can be
73
+ * compared on malformed input.
74
+ *
75
+ * @internal
76
+ */
77
+ function outcome(fn: () => unknown) {
78
+ try {
79
+ return { value: fn() }
80
+ } catch (error) {
81
+ return { error: `${(error as Error).name}: ${(error as Error).message}` }
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Converts `Uint8Array` leaves to hex, as `Rlp.toHex` returns them.
87
+ *
88
+ * @internal
89
+ */
90
+ function normalizeBytesToHex(value: RecursiveArray<Bytes.Bytes>): unknown {
91
+ if (Array.isArray(value)) return value.map(normalizeBytesToHex)
92
+ return Hex.fromBytes(value as Uint8Array)
93
+ }
94
+
41
95
  /**
42
96
  * Lower-case any hex string in a recursive tree. The encoder emits
43
97
  * lowercase but the arbitrary may produce mixed casing in the future,
@@ -157,6 +157,70 @@ describe('Rlp.to', () => {
157
157
  expect(Rlp.toHex(rlpBytes)).toEqual('0x')
158
158
  })
159
159
 
160
+ test('behavior: hex leaves of a hex input', () => {
161
+ // Short and long leaves, nested, in short and long (> 4096 hex
162
+ // characters) inputs.
163
+ for (const length of [32, 4_096]) {
164
+ const value = [
165
+ '0x0a',
166
+ '0x',
167
+ `0x${'ab'.repeat(20)}`,
168
+ [[`0x${'cd'.repeat(length)}`], '0x7f', '0x80'],
169
+ `0x${'ef'.repeat(56)}`,
170
+ ] as const
171
+ const encoded = Rlp.fromHex(value as never)
172
+ expect(Rlp.toHex(encoded)).toEqual(value)
173
+ // Leaves are lowercase, as `Hex.fromBytes` writes them.
174
+ expect(Rlp.toHex(`0x${encoded.slice(2).toUpperCase()}`)).toEqual(value)
175
+ }
176
+ })
177
+
178
+ test('behavior: hex input decodes and fails like byte input', () => {
179
+ // Decoding to bytes always goes through `Bytes.fromHex` and the cursor,
180
+ // which short hex input to hex skips.
181
+ const toHex = (value: unknown): unknown =>
182
+ Array.isArray(value) ? value.map(toHex) : Hex.fromBytes(value as never)
183
+ const outcome = (fn: () => unknown) => {
184
+ try {
185
+ return { value: fn() }
186
+ } catch (error) {
187
+ return {
188
+ error: `${(error as Error).name}: ${(error as Error).message}`,
189
+ }
190
+ }
191
+ }
192
+ for (const value of [
193
+ '0x',
194
+ '0x00',
195
+ '0x7F',
196
+ '0x8180',
197
+ '0xC88363617483646F67',
198
+ '0xc0',
199
+ '0xzz',
200
+ '0x8',
201
+ '0x0\u0130',
202
+ '0x82',
203
+ '0x8201',
204
+ '0xb8',
205
+ '0xb801ff',
206
+ '0xb838',
207
+ '0xb90001',
208
+ '0xbc',
209
+ '0x8100',
210
+ '0x817f',
211
+ '0xc20102',
212
+ '0xc1c0c0',
213
+ '0xc3010203ff',
214
+ '0xc28201',
215
+ '0xff',
216
+ '0x0101',
217
+ `0x${'c1'.repeat(1_025)}`,
218
+ ] as const)
219
+ expect(outcome(() => Rlp.toHex(value as Hex.Hex))).toEqual(
220
+ outcome(() => toHex(Rlp.toBytes(value as Hex.Hex))),
221
+ )
222
+ })
223
+
160
224
  describe('prefix < 0x80', () => {
161
225
  test('bytes -> bytes', () => {
162
226
  expect(Rlp.toBytes(Rlp.fromBytes(Bytes.fromHex('0x00')))).toEqual(
@@ -224,7 +224,7 @@ describe('fromHttp', () => {
224
224
 
225
225
  Status: 400
226
226
  URL: https://oxlib.sh/rpc
227
- Body: "{\\"id\\":0,\\"method\\":\\"eth_accounts\\",\\"jsonrpc\\":\\"2.0\\"}"
227
+ Body: {"id":0,"method":"eth_accounts","jsonrpc":"2.0"}
228
228
 
229
229
  Details: Bad Request]
230
230
  `)
@@ -244,7 +244,7 @@ describe('fromHttp', () => {
244
244
 
245
245
  Status: 400
246
246
  URL: https://oxlib.sh/rpc
247
- Body: "{\\"id\\":0,\\"method\\":\\"eth_accounts\\",\\"jsonrpc\\":\\"2.0\\"}"
247
+ Body: {"id":0,"method":"eth_accounts","jsonrpc":"2.0"}
248
248
 
249
249
  Details: bad]
250
250
  `)
@@ -317,6 +317,19 @@ describe('fromHttp', () => {
317
317
  }
318
318
  })
319
319
 
320
+ test('behavior: timeout rejects when `fetchFn` ignores the signal', async () => {
321
+ const transport = RpcTransport.fromHttp('https://example.com', {
322
+ fetchFn: () => new Promise<Response>(() => {}),
323
+ timeout: 50,
324
+ })
325
+
326
+ await expect(() =>
327
+ transport.request({ method: 'eth_accounts' }),
328
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
329
+ `[Promise.TimeoutError: Operation timed out.]`,
330
+ )
331
+ })
332
+
320
333
  test('behavior: timeout covers a response body that stalls after its headers', async () => {
321
334
  const server = await createHttpServer(async (_, res) => {
322
335
  res.writeHead(200, { 'Content-Type': 'application/json' })
@@ -672,6 +672,42 @@ describe('verify', () => {
672
672
  Secp256k1.verify({ hash: true, publicKey, payload, signature: { r, s } }),
673
673
  ).toBe(true)
674
674
  })
675
+
676
+ test('options: hash w/ address', () => {
677
+ const payload = '0xdeadbeef'
678
+ const publicKey = Secp256k1.getPublicKey({ privateKey })
679
+
680
+ // Signature over `sha256(payload)`.
681
+ {
682
+ const signature = Secp256k1.sign({ hash: true, payload, privateKey })
683
+ expect(
684
+ Secp256k1.verify({ address, hash: true, payload, signature }),
685
+ ).toBe(true)
686
+ expect(
687
+ Secp256k1.verify({
688
+ address,
689
+ hash: true,
690
+ payload: Bytes.fromHex(payload),
691
+ signature,
692
+ }),
693
+ ).toBe(true)
694
+ expect(
695
+ Secp256k1.verify({ hash: true, payload, publicKey, signature }),
696
+ ).toBe(true)
697
+ expect(Secp256k1.verify({ address, payload, signature })).toBe(false)
698
+ }
699
+
700
+ // Signature over the payload itself.
701
+ {
702
+ const signature = Secp256k1.sign({ payload, privateKey })
703
+ expect(
704
+ Secp256k1.verify({ address, hash: true, payload, signature }),
705
+ ).toBe(false)
706
+ expect(
707
+ Secp256k1.verify({ hash: true, payload, publicKey, signature }),
708
+ ).toBe(false)
709
+ }
710
+ })
675
711
  })
676
712
 
677
713
  test('exports', () => {
@@ -92,6 +92,54 @@ describe('assert', () => {
92
92
  '[Signature.InvalidSError: Value `0x10000000000000000000000000000000000000000000000000000000000000000` is an invalid s value. s must be a positive integer less than 2^256.]',
93
93
  )
94
94
  })
95
+
96
+ test('error: yParity that is not exactly 0 or 1', () => {
97
+ const r =
98
+ '0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf'
99
+ const s =
100
+ '0x4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db8'
101
+
102
+ expect(() =>
103
+ Signature.assert({ r, s, yParity: '0x1' as never }),
104
+ ).toThrowErrorMatchingInlineSnapshot(
105
+ `[Signature.InvalidYParityError: Value \`0x1\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
106
+ )
107
+ expect(() =>
108
+ Signature.assert({ r, s, yParity: 1n as never }),
109
+ ).toThrowErrorMatchingInlineSnapshot(
110
+ `[Signature.InvalidYParityError: Value \`1\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
111
+ )
112
+ expect(() =>
113
+ Signature.assert({ r, s, yParity: true as never }),
114
+ ).toThrowErrorMatchingInlineSnapshot(
115
+ `[Signature.InvalidYParityError: Value \`true\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
116
+ )
117
+ expect(() =>
118
+ Signature.assert({ r, s, yParity: null as never }),
119
+ ).toThrowErrorMatchingInlineSnapshot(
120
+ `[Signature.InvalidYParityError: Value \`null\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
121
+ )
122
+ expect(() =>
123
+ Signature.assert({ r, s, yParity: {} as never }),
124
+ ).toThrowErrorMatchingInlineSnapshot(
125
+ `[Signature.InvalidYParityError: Value \`[object Object]\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
126
+ )
127
+ })
128
+
129
+ test('options: recovered: null yParity is missing', () => {
130
+ expect(() =>
131
+ Signature.assert(
132
+ {
133
+ r: '0x0000000000000000000000000000000000000000000000000000000000000000',
134
+ s: '0x0000000000000000000000000000000000000000000000000000000000000000',
135
+ yParity: null as never,
136
+ },
137
+ { recovered: true },
138
+ ),
139
+ ).toThrowErrorMatchingInlineSnapshot(
140
+ `[Signature.MissingPropertiesError: Signature \`{"r":"0x0000000000000000000000000000000000000000000000000000000000000000","s":"0x0000000000000000000000000000000000000000000000000000000000000000","yParity":null}\` is missing either an \`r\`, \`s\`, or \`yParity\` property.]`,
141
+ )
142
+ })
95
143
  })
96
144
 
97
145
  describe('fromHex', () => {
@@ -994,6 +1042,34 @@ describe('toTuple', () => {
994
1042
  ]
995
1043
  `)
996
1044
  })
1045
+
1046
+ test('error: yParity that is not exactly 0 or 1', () => {
1047
+ const r =
1048
+ '0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf'
1049
+ const s =
1050
+ '0x4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db8'
1051
+
1052
+ expect(() =>
1053
+ Signature.toTuple({ r, s, yParity: 27 }),
1054
+ ).toThrowErrorMatchingInlineSnapshot(
1055
+ `[Signature.InvalidYParityError: Value \`27\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
1056
+ )
1057
+ expect(() =>
1058
+ Signature.toTuple({ r, s, yParity: 27n as never }),
1059
+ ).toThrowErrorMatchingInlineSnapshot(
1060
+ `[Signature.InvalidYParityError: Value \`27\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
1061
+ )
1062
+ expect(() =>
1063
+ Signature.toTuple({ r, s, yParity: '0x0' as never }),
1064
+ ).toThrowErrorMatchingInlineSnapshot(
1065
+ `[Signature.InvalidYParityError: Value \`0x0\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
1066
+ )
1067
+ expect(() =>
1068
+ Signature.toTuple({ r, s } as never),
1069
+ ).toThrowErrorMatchingInlineSnapshot(
1070
+ `[Signature.MissingPropertiesError: Signature \`{"r":"0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf","s":"0x4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db8"}\` is missing either an \`r\`, \`s\`, or \`yParity\` property.]`,
1071
+ )
1072
+ })
997
1073
  })
998
1074
 
999
1075
  describe('validate', () => {
@@ -1013,6 +1089,32 @@ describe('validate', () => {
1013
1089
  }),
1014
1090
  ).toBe(false)
1015
1091
  })
1092
+
1093
+ test('behavior: yParity that is not exactly 0 or 1', () => {
1094
+ const r =
1095
+ '0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf'
1096
+ const s =
1097
+ '0x4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db8'
1098
+
1099
+ expect(
1100
+ [2, '0x5', 2n, 27n, true, null, {}].map((yParity) =>
1101
+ Signature.validate({ r, s, yParity: yParity as never }),
1102
+ ),
1103
+ ).toMatchInlineSnapshot(`
1104
+ [
1105
+ false,
1106
+ false,
1107
+ false,
1108
+ false,
1109
+ false,
1110
+ false,
1111
+ false,
1112
+ ]
1113
+ `)
1114
+ expect(
1115
+ Signature.validate({ r, s, yParity: null as never }, { recovered: true }),
1116
+ ).toMatchInlineSnapshot(`false`)
1117
+ })
1016
1118
  })
1017
1119
 
1018
1120
  describe('vToYParity', () => {
@@ -442,6 +442,27 @@ describe('createMessage', () => {
442
442
  `)
443
443
  })
444
444
 
445
+ test('behavior: invalid requestId', () => {
446
+ expect(() => Siwe.createMessage({ ...message, requestId: 'foo\nbar' }))
447
+ .toThrowErrorMatchingInlineSnapshot(`
448
+ [Siwe.InvalidMessageFieldError: Invalid Sign-In with Ethereum message field "requestId".
449
+
450
+ - Request ID must not include '\\n' or '\\r'.
451
+
452
+ Provided value: foo
453
+ bar]
454
+ `)
455
+ expect(() => Siwe.createMessage({ ...message, requestId: 'foo\rbar' }))
456
+ .toThrowErrorMatchingInlineSnapshot(`
457
+ [Siwe.InvalidMessageFieldError: Invalid Sign-In with Ethereum message field "requestId".
458
+
459
+ - Request ID must not include '\\n' or '\\r'.
460
+
461
+ Provided value: foo
462
+ bar]
463
+ `)
464
+ })
465
+
445
466
  test('behavior: invalid resources', () => {
446
467
  expect(() =>
447
468
  Siwe.createMessage({
@@ -1013,6 +1034,76 @@ Request ID: 123e4567-e89b-12d3-a456-426614174000`
1013
1034
  const parsed = Siwe.parseMessage(message)
1014
1035
  expect(parsed).toMatchInlineSnapshot('{}')
1015
1036
  })
1037
+
1038
+ test.each([
1039
+ {
1040
+ name: 'expirationTime after notBefore',
1041
+ tail: '\nNot Before: 2023-02-01T00:00:00.000Z\nExpiration Time: 2023-03-01T00:00:00.000Z',
1042
+ },
1043
+ {
1044
+ name: 'expirationTime after requestId',
1045
+ tail: '\nRequest ID: foo\nExpiration Time: 2023-03-01T00:00:00.000Z',
1046
+ },
1047
+ {
1048
+ name: 'notBefore after resources',
1049
+ tail: '\nResources:\n- https://example.com/foo\nNot Before: 2023-02-01T00:00:00.000Z',
1050
+ },
1051
+ {
1052
+ name: 'blank line before expirationTime',
1053
+ tail: '\n\nExpiration Time: 2023-03-01T00:00:00.000Z',
1054
+ },
1055
+ {
1056
+ name: 'unknown field label',
1057
+ tail: '\nExpiration Time: 2023-03-01T00:00:00.000Z',
1058
+ },
1059
+ { name: 'trailing line feed', tail: '\n' },
1060
+ ])('behavior: text after the suffix ($name)', ({ tail }) => {
1061
+ const message = `example.com wants you to sign in with your Ethereum account:
1062
+ 0xA0Cf798816D4b9b9866b5330EEa46a18382f251e
1063
+
1064
+ I accept the ExampleOrg Terms of Service: https://example.com/tos
1065
+
1066
+ URI: https://example.com/path
1067
+ Version: 1
1068
+ Chain ID: 1
1069
+ Nonce: foobarbaz
1070
+ Issued At: 2023-02-01T00:00:00.000Z`
1071
+ expect(Siwe.parseMessage(message + tail)).toEqual({})
1072
+ })
1073
+
1074
+ test('behavior: text between the prefix and the suffix', () => {
1075
+ const message = `example.com wants you to sign in with your Ethereum account:
1076
+ 0xA0Cf798816D4b9b9866b5330EEa46a18382f251e
1077
+
1078
+ I accept the ExampleOrg Terms of Service: https://example.com/tos
1079
+
1080
+ foo
1081
+ URI: https://example.com/path
1082
+ Version: 1
1083
+ Chain ID: 1
1084
+ Nonce: foobarbaz
1085
+ Issued At: 2023-02-01T00:00:00.000Z`
1086
+ expect(Siwe.parseMessage(message)).toMatchInlineSnapshot('{}')
1087
+ })
1088
+
1089
+ test('behavior: text before the suffix without a prefix', () => {
1090
+ const message = `foo
1091
+ URI: https://example.com/path
1092
+ Version: 1
1093
+ Chain ID: 1
1094
+ Nonce: foobarbaz
1095
+ Issued At: 2023-02-01T00:00:00.000Z`
1096
+ expect(Siwe.parseMessage(message)).toMatchInlineSnapshot('{}')
1097
+ })
1098
+
1099
+ test(
1100
+ 'behavior: long message of repeated field labels',
1101
+ { timeout: 5_000 },
1102
+ () => {
1103
+ const message = 'URI: '.repeat(60_000)
1104
+ expect(Siwe.parseMessage(message)).toMatchInlineSnapshot('{}')
1105
+ },
1106
+ )
1016
1107
  })
1017
1108
 
1018
1109
  describe('validateMessage', () => {
@@ -1132,6 +1223,38 @@ Issued At: 2023-02-01T00:00:00.000Z`)
1132
1223
  ).toBeFalsy()
1133
1224
  })
1134
1225
 
1226
+ test('behavior: parsed message with expirationTime out of order', () => {
1227
+ const message = Siwe.createMessage({
1228
+ address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
1229
+ chainId: 1,
1230
+ domain: 'example.com',
1231
+ issuedAt: new Date(Date.UTC(2024, 0, 1)),
1232
+ nonce: 'foobarbaz',
1233
+ uri: 'https://example.com/path',
1234
+ version: '1',
1235
+ })
1236
+ const time = new Date(Date.UTC(2025, 1, 1))
1237
+ expect(
1238
+ Siwe.validateMessage({ message: Siwe.parseMessage(message), time }),
1239
+ ).toBeTruthy()
1240
+ expect(
1241
+ Siwe.validateMessage({
1242
+ message: Siwe.parseMessage(
1243
+ `${message}\nExpiration Time: 2024-02-01T00:00:00.000Z`,
1244
+ ),
1245
+ time,
1246
+ }),
1247
+ ).toBeFalsy()
1248
+ expect(
1249
+ Siwe.validateMessage({
1250
+ message: Siwe.parseMessage(
1251
+ `${message}\nNot Before: 2024-01-01T00:00:00.000Z\nExpiration Time: 2024-02-01T00:00:00.000Z`,
1252
+ ),
1253
+ time,
1254
+ }),
1255
+ ).toBeFalsy()
1256
+ })
1257
+
1135
1258
  test.each(['expirationTime', 'notBefore'] as const)(
1136
1259
  'behavior: invalid %s',
1137
1260
  (field) => {
@@ -13,6 +13,23 @@ import { accounts } from '../../../test/constants/accounts.js'
13
13
  import { anvilMainnet } from '../../../test/prool.js'
14
14
 
15
15
  describe('fromRpc', () => {
16
+ test('behavior: unknown type named like an `Object.prototype` key', () => {
17
+ const transaction = Transaction.fromRpc({
18
+ blockHash: null,
19
+ blockNumber: null,
20
+ from: '0x814e5e0e31016b9a7f138c76b7e7b2bb5c1ab6a6',
21
+ gas: '0x5208',
22
+ hash: '0x353fdfc38a2f26115daadee9f5b8392ce62b84f410957967e2ed56b35338cdd0',
23
+ input: '0x',
24
+ nonce: '0x0',
25
+ to: null,
26
+ transactionIndex: null,
27
+ type: 'constructor',
28
+ value: '0x0',
29
+ } as unknown as Transaction.Rpc)
30
+ expect(transaction.type).toMatchInlineSnapshot(`"constructor"`)
31
+ })
32
+
16
33
  describe('legacy', () => {
17
34
  test('default', () => {
18
35
  expect(
@@ -47,6 +47,34 @@ describe('assert', () => {
47
47
  )
48
48
  })
49
49
 
50
+ test('invalid chainId (not a positive safe integer)', () => {
51
+ expect(() =>
52
+ TxEnvelopeEip1559.assert({ chainId: Number.NaN }),
53
+ ).toThrowErrorMatchingInlineSnapshot(
54
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "NaN" is invalid.]`,
55
+ )
56
+ expect(() =>
57
+ TxEnvelopeEip1559.assert({ chainId: 1.5 }),
58
+ ).toThrowErrorMatchingInlineSnapshot(
59
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "1.5" is invalid.]`,
60
+ )
61
+ expect(() =>
62
+ TxEnvelopeEip1559.assert({ chainId: Number.MAX_SAFE_INTEGER + 1 }),
63
+ ).toThrowErrorMatchingInlineSnapshot(
64
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "9007199254740992" is invalid.]`,
65
+ )
66
+ expect(() =>
67
+ TxEnvelopeEip1559.assert({ chainId: '1' as never }),
68
+ ).toThrowErrorMatchingInlineSnapshot(
69
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "1" is invalid.]`,
70
+ )
71
+ expect(() =>
72
+ TxEnvelopeEip1559.assert({ chainId: 1n as never }),
73
+ ).toThrowErrorMatchingInlineSnapshot(
74
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "1" is invalid.]`,
75
+ )
76
+ })
77
+
50
78
  test('invalid address', () => {
51
79
  expect(() => TxEnvelopeEip1559.assert({ to: '0x123', chainId: 1 }))
52
80
  .toThrowErrorMatchingInlineSnapshot(`
@@ -23,6 +23,34 @@ describe('assert', () => {
23
23
  )
24
24
  })
25
25
 
26
+ test('invalid chainId (not a positive safe integer)', () => {
27
+ expect(() =>
28
+ TxEnvelopeEip2930.assert({ chainId: Number.NaN }),
29
+ ).toThrowErrorMatchingInlineSnapshot(
30
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "NaN" is invalid.]`,
31
+ )
32
+ expect(() =>
33
+ TxEnvelopeEip2930.assert({ chainId: 1.5 }),
34
+ ).toThrowErrorMatchingInlineSnapshot(
35
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "1.5" is invalid.]`,
36
+ )
37
+ expect(() =>
38
+ TxEnvelopeEip2930.assert({ chainId: Number.MAX_SAFE_INTEGER + 1 }),
39
+ ).toThrowErrorMatchingInlineSnapshot(
40
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "9007199254740992" is invalid.]`,
41
+ )
42
+ expect(() =>
43
+ TxEnvelopeEip2930.assert({ chainId: '1' as never }),
44
+ ).toThrowErrorMatchingInlineSnapshot(
45
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "1" is invalid.]`,
46
+ )
47
+ expect(() =>
48
+ TxEnvelopeEip2930.assert({ chainId: 1n as never }),
49
+ ).toThrowErrorMatchingInlineSnapshot(
50
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "1" is invalid.]`,
51
+ )
52
+ })
53
+
26
54
  test('invalid address', () => {
27
55
  expect(() => TxEnvelopeEip2930.assert({ to: '0x123', chainId: 1 }))
28
56
  .toThrowErrorMatchingInlineSnapshot(`