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
@@ -324,6 +324,36 @@ describe('deserialize', () => {
324
324
  )
325
325
  })
326
326
 
327
+ test('authorization chainId above safe integer range', () => {
328
+ expect(() =>
329
+ TxEnvelopeEip7702.deserialize(
330
+ `0x04${Rlp.fromHex([
331
+ Hex.fromNumber(1), // chainId
332
+ '0x', // nonce
333
+ Hex.fromNumber(1), // maxPriorityFeePerGas
334
+ Hex.fromNumber(1), // maxFeePerGas
335
+ Hex.fromNumber(1), // gas
336
+ '0x0000000000000000000000000000000000000000', // to
337
+ '0x', // value
338
+ '0x', // data
339
+ [], // accessList
340
+ [
341
+ [
342
+ '0x20000000000001',
343
+ '0x0000000000000000000000000000000000000000',
344
+ '0x01',
345
+ '0x',
346
+ '0x01',
347
+ '0x02',
348
+ ],
349
+ ], // authorizationList
350
+ ]).slice(2)}`,
351
+ ),
352
+ ).toThrowErrorMatchingInlineSnapshot(
353
+ `[Hex.IntegerOutOfRangeError: Number \`9007199254740992\` is not in safe unsigned integer range (\`0\` to \`9007199254740991\`)]`,
354
+ )
355
+ })
356
+
327
357
  test('invalid access list (invalid address)', () => {
328
358
  expect(() =>
329
359
  TxEnvelopeEip7702.deserialize(
@@ -423,6 +453,109 @@ describe('deserialize', () => {
423
453
  Missing Attributes: r, s]
424
454
  `)
425
455
  })
456
+
457
+ describe('authorization tuple length', () => {
458
+ const address = '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c'
459
+ const r =
460
+ '0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90'
461
+ const s =
462
+ '0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'
463
+
464
+ const serialize = (authorization: readonly Hex.Hex[]) =>
465
+ `0x04${Rlp.fromHex([
466
+ '0x01', // chainId
467
+ '0x', // nonce
468
+ '0x01', // maxPriorityFeePerGas
469
+ '0x01', // maxFeePerGas
470
+ '0x01', // gas
471
+ '0x0000000000000000000000000000000000000000', // to
472
+ '0x', // value
473
+ '0x', // data
474
+ [], // accessList
475
+ [authorization], // authorizationList
476
+ '0x', // yParity
477
+ '0x01', // r
478
+ '0x02', // s
479
+ ]).slice(2)}` as const
480
+
481
+ test('6 fields round trip', () => {
482
+ const serialized = serialize(['0x01', address, '0x03', '0x01', r, s])
483
+ expect(
484
+ TxEnvelopeEip7702.serialize(
485
+ TxEnvelopeEip7702.deserialize(serialized),
486
+ ),
487
+ ).toBe(serialized)
488
+ })
489
+
490
+ test('3 fields', () => {
491
+ expect(() =>
492
+ TxEnvelopeEip7702.deserialize(serialize(['0x01', address, '0x03'])),
493
+ ).toThrowErrorMatchingInlineSnapshot(`
494
+ [Authorization.InvalidError: Invalid authorization.
495
+
496
+ Details: Expected [chainId, address, nonce, yParity, r, s].]
497
+ `)
498
+ })
499
+
500
+ test('4 fields', () => {
501
+ expect(() =>
502
+ TxEnvelopeEip7702.deserialize(
503
+ serialize(['0x01', address, '0x03', '0x01']),
504
+ ),
505
+ ).toThrowErrorMatchingInlineSnapshot(`
506
+ [Authorization.InvalidError: Invalid authorization.
507
+
508
+ Details: Expected [chainId, address, nonce, yParity, r, s].]
509
+ `)
510
+ })
511
+
512
+ test('5 fields', () => {
513
+ expect(() =>
514
+ TxEnvelopeEip7702.deserialize(
515
+ serialize(['0x01', address, '0x03', '0x01', r]),
516
+ ),
517
+ ).toThrowErrorMatchingInlineSnapshot(`
518
+ [Authorization.InvalidError: Invalid authorization.
519
+
520
+ Details: Expected [chainId, address, nonce, yParity, r, s].]
521
+ `)
522
+ })
523
+
524
+ test('7 fields', () => {
525
+ expect(() =>
526
+ TxEnvelopeEip7702.deserialize(
527
+ serialize(['0x01', address, '0x03', '0x01', r, s, '0xdeadbeef']),
528
+ ),
529
+ ).toThrowErrorMatchingInlineSnapshot(`
530
+ [Authorization.InvalidError: Invalid authorization.
531
+
532
+ Details: Expected [chainId, address, nonce, yParity, r, s].]
533
+ `)
534
+ })
535
+
536
+ test('not a list', () => {
537
+ expect(() =>
538
+ TxEnvelopeEip7702.deserialize(
539
+ `0x04${Rlp.fromHex([
540
+ '0x01', // chainId
541
+ '0x', // nonce
542
+ '0x01', // maxPriorityFeePerGas
543
+ '0x01', // maxFeePerGas
544
+ '0x01', // gas
545
+ '0x0000000000000000000000000000000000000000', // to
546
+ '0x', // value
547
+ '0x', // data
548
+ [], // accessList
549
+ ['0x010203040506'], // authorizationList
550
+ ]).slice(2)}`,
551
+ ),
552
+ ).toThrowErrorMatchingInlineSnapshot(`
553
+ [Authorization.InvalidError: Invalid authorization.
554
+
555
+ Details: Expected [chainId, address, nonce, yParity, r, s].]
556
+ `)
557
+ })
558
+ })
426
559
  })
427
560
  })
428
561
 
@@ -23,6 +23,34 @@ describe('assert', () => {
23
23
  )
24
24
  })
25
25
 
26
+ test('invalid chainId (not a positive safe integer)', () => {
27
+ expect(() =>
28
+ TxEnvelopeLegacy.assert({ chainId: Number.NaN }),
29
+ ).toThrowErrorMatchingInlineSnapshot(
30
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "NaN" is invalid.]`,
31
+ )
32
+ expect(() =>
33
+ TxEnvelopeLegacy.assert({ chainId: 1.5 }),
34
+ ).toThrowErrorMatchingInlineSnapshot(
35
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "1.5" is invalid.]`,
36
+ )
37
+ expect(() =>
38
+ TxEnvelopeLegacy.assert({ chainId: Number.MAX_SAFE_INTEGER + 1 }),
39
+ ).toThrowErrorMatchingInlineSnapshot(
40
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "9007199254740992" is invalid.]`,
41
+ )
42
+ expect(() =>
43
+ TxEnvelopeLegacy.assert({ chainId: '1' as never }),
44
+ ).toThrowErrorMatchingInlineSnapshot(
45
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "1" is invalid.]`,
46
+ )
47
+ expect(() =>
48
+ TxEnvelopeLegacy.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(() => TxEnvelopeLegacy.assert({ to: '0x123', chainId: 1 }))
28
56
  .toThrowErrorMatchingInlineSnapshot(`
@@ -266,6 +294,35 @@ describe('deserialize', () => {
266
294
  }
267
295
  `)
268
296
  })
297
+
298
+ test('largest safe v', () => {
299
+ const serialized = Rlp.fromHex([
300
+ '0x01', // nonce
301
+ '0x02', // gasPrice
302
+ '0x5208', // gas
303
+ '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', // to
304
+ '0x03', // value
305
+ '0x', // data
306
+ Hex.fromNumber(Number.MAX_SAFE_INTEGER), // v
307
+ `0x${'ff'.repeat(32)}`, // r
308
+ `0x${'ff'.repeat(32)}`, // s
309
+ ])
310
+ expect(TxEnvelopeLegacy.deserialize(serialized)).toMatchInlineSnapshot(`
311
+ {
312
+ "chainId": 4503599627370478,
313
+ "gas": 21000n,
314
+ "gasPrice": 2n,
315
+ "nonce": 1n,
316
+ "r": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
317
+ "s": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
318
+ "to": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
319
+ "type": "legacy",
320
+ "v": 9007199254740991,
321
+ "value": 3n,
322
+ "yParity": 0,
323
+ }
324
+ `)
325
+ })
269
326
  })
270
327
 
271
328
  describe('errors', () => {
@@ -362,6 +419,148 @@ describe('deserialize', () => {
362
419
  '[Signature.InvalidVError: Value `35` is an invalid v value. v must be 27, 28 or >=35.]',
363
420
  )
364
421
  })
422
+
423
+ const fields = [
424
+ '0x01', // nonce
425
+ '0x02', // gasPrice
426
+ '0x5208', // gas
427
+ '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', // to
428
+ '0x03', // value
429
+ '0x', // data
430
+ ] as const
431
+ const word =
432
+ '0x1111111111111111111111111111111111111111111111111111111111111111'
433
+
434
+ test('unsigned: invalid `to`', () => {
435
+ const to = '0x11111111111111111111111111111111111111'
436
+ expect(() =>
437
+ TxEnvelopeLegacy.deserialize(
438
+ Rlp.fromHex(['0x01', '0x02', '0x5208', to, '0x03', '0x']),
439
+ ),
440
+ ).toThrowErrorMatchingInlineSnapshot(`
441
+ [Address.InvalidAddressError: Address "0x11111111111111111111111111111111111111" is invalid.
442
+
443
+ Details: Address is not a 20 byte (40 hexadecimal character) value.]
444
+ `)
445
+ expect(() =>
446
+ TxEnvelopeLegacy.deserialize(
447
+ Rlp.fromHex([
448
+ '0x01',
449
+ '0x02',
450
+ '0x5208',
451
+ to,
452
+ '0x03',
453
+ '0x',
454
+ '0x01',
455
+ '0x',
456
+ '0x',
457
+ ]),
458
+ ),
459
+ ).toThrowErrorMatchingInlineSnapshot(`
460
+ [Address.InvalidAddressError: Address "0x11111111111111111111111111111111111111" is invalid.
461
+
462
+ Details: Address is not a 20 byte (40 hexadecimal character) value.]
463
+ `)
464
+ })
465
+
466
+ test('gasPrice longer than 32 bytes', () => {
467
+ const gasPrice = `0x01${'00'.repeat(32)}` as const
468
+ const [nonce, , ...rest] = fields
469
+ expect(() =>
470
+ TxEnvelopeLegacy.deserialize(Rlp.fromHex([nonce, gasPrice, ...rest])),
471
+ ).toThrowErrorMatchingInlineSnapshot(
472
+ `[TransactionEnvelope.GasPriceTooHighError: The gas price (\`gasPrice\`) cannot be higher than the maximum allowed value (2^256-1).]`,
473
+ )
474
+ expect(() =>
475
+ TxEnvelopeLegacy.deserialize(
476
+ Rlp.fromHex([nonce, gasPrice, ...rest, '0x25', word, word]),
477
+ ),
478
+ ).toThrowErrorMatchingInlineSnapshot(
479
+ `[TransactionEnvelope.GasPriceTooHighError: The gas price (\`gasPrice\`) cannot be higher than the maximum allowed value (2^256-1).]`,
480
+ )
481
+ })
482
+
483
+ test('r or s longer than 32 bytes', () => {
484
+ expect(() =>
485
+ TxEnvelopeLegacy.deserialize(
486
+ Rlp.fromHex([...fields, '0x25', `${word}11`, word]),
487
+ ),
488
+ ).toThrowErrorMatchingInlineSnapshot(
489
+ `[Signature.InvalidRError: Value \`0x111111111111111111111111111111111111111111111111111111111111111111\` is an invalid r value. r must be a positive integer less than 2^256.]`,
490
+ )
491
+ expect(() =>
492
+ TxEnvelopeLegacy.deserialize(
493
+ Rlp.fromHex([...fields, '0x25', word, `${word}11`]),
494
+ ),
495
+ ).toThrowErrorMatchingInlineSnapshot(
496
+ `[Signature.InvalidSError: Value \`0x111111111111111111111111111111111111111111111111111111111111111111\` is an invalid s value. s must be a positive integer less than 2^256.]`,
497
+ )
498
+ })
499
+
500
+ test('list in place of a field', () => {
501
+ const signed = [...fields, '0x25', word, word] as const
502
+ expect(() =>
503
+ TxEnvelopeLegacy.deserialize(
504
+ Rlp.fromHex([['0x01', '0x02'], ...fields.slice(1)]),
505
+ ),
506
+ ).toThrowErrorMatchingInlineSnapshot(`
507
+ [TransactionEnvelope.InvalidSerializedError: Invalid serialized transaction of type "legacy" was provided.
508
+
509
+ Serialized Transaction: "0xdec20102028252089470997970c51812dc3a010c7d01b50e0d17dc79c80380"]
510
+ `)
511
+ for (const tuple of [fields, signed])
512
+ for (let i = 0; i < tuple.length; i++)
513
+ expect(() =>
514
+ TxEnvelopeLegacy.deserialize(
515
+ Rlp.fromHex(tuple.map((x, j) => (i === j ? [x] : x))),
516
+ ),
517
+ ).toThrowError(
518
+ 'Invalid serialized transaction of type "legacy" was provided.',
519
+ )
520
+ expect(() =>
521
+ TxEnvelopeLegacy.deserialize(Rlp.fromHex([...fields, '0x25', [], []])),
522
+ ).toThrowError(
523
+ 'Invalid serialized transaction of type "legacy" was provided.',
524
+ )
525
+ })
526
+
527
+ test('byte string in place of the list', () => {
528
+ expect(() => TxEnvelopeLegacy.deserialize('0x86aabbccddeeff'))
529
+ .toThrowErrorMatchingInlineSnapshot(`
530
+ [TransactionEnvelope.InvalidSerializedError: Invalid serialized transaction of type "legacy" was provided.
531
+
532
+ Serialized Transaction: "0x86aabbccddeeff"]
533
+ `)
534
+ })
535
+
536
+ test('v above the safe integer range', () => {
537
+ // 2^53 + 15
538
+ expect(() =>
539
+ TxEnvelopeLegacy.deserialize(
540
+ Rlp.fromHex([...fields, '0x2000000000000f', word, word]),
541
+ ),
542
+ ).toThrowErrorMatchingInlineSnapshot(`
543
+ [TransactionEnvelope.InvalidSerializedError: Invalid serialized transaction of type "legacy" was provided.
544
+
545
+ Serialized Transaction: "0xf86601028252089470997970c51812dc3a010c7d01b50e0d17dc79c80380872000000000000fa01111111111111111111111111111111111111111111111111111111111111111a01111111111111111111111111111111111111111111111111111111111111111"]
546
+ `)
547
+ // 2^53 + 1 (unsigned)
548
+ expect(() =>
549
+ TxEnvelopeLegacy.deserialize(
550
+ Rlp.fromHex([...fields, '0x20000000000001', '0x', '0x']),
551
+ ),
552
+ ).toThrowError(
553
+ 'Invalid serialized transaction of type "legacy" was provided.',
554
+ )
555
+ // 2^1100
556
+ expect(() =>
557
+ TxEnvelopeLegacy.deserialize(
558
+ Rlp.fromHex([...fields, `0x10${'00'.repeat(137)}`, word, word]),
559
+ ),
560
+ ).toThrowError(
561
+ 'Invalid serialized transaction of type "legacy" was provided.',
562
+ )
563
+ })
365
564
  })
366
565
  })
367
566
 
@@ -507,6 +706,50 @@ describe('hash', () => {
507
706
  `"0x5e427e088ae00b084b41e198c52440aa43b2d6f8f1f01246fd25d4e9b6ebfdab"`,
508
707
  )
509
708
  })
709
+
710
+ test('options: presign: chain ID carried by `v`', () => {
711
+ const unsigned = {
712
+ gas: 21000n,
713
+ gasPrice: 1000000000n,
714
+ nonce: 665n,
715
+ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
716
+ value: 1000000000000000000n,
717
+ } as const
718
+ const payload = TxEnvelopeLegacy.getSignPayload(
719
+ TxEnvelopeLegacy.from({ ...unsigned, chainId: 1 }),
720
+ )
721
+ const { r, s, yParity } = Secp256k1.sign({
722
+ payload,
723
+ privateKey: accounts[0].privateKey,
724
+ })
725
+
726
+ // EIP-155 `v`, no `chainId`
727
+ const envelope = TxEnvelopeLegacy.from({
728
+ ...unsigned,
729
+ r,
730
+ s,
731
+ v: 37 + yParity,
732
+ })
733
+ expect(
734
+ TxEnvelopeLegacy.hash(envelope, { presign: true }),
735
+ ).toMatchInlineSnapshot(
736
+ `"0x4c1dec0d90aa1a17cb0aa735b5550e43a1bd27cd1cacb8987522576fa6220e46"`,
737
+ )
738
+ expect(TxEnvelopeLegacy.hash(envelope, { presign: true })).toBe(payload)
739
+ expect(TxEnvelopeLegacy.getSignPayload(envelope)).toBe(
740
+ TxEnvelopeLegacy.getSignPayload(
741
+ TxEnvelopeLegacy.deserialize(TxEnvelopeLegacy.serialize(envelope)),
742
+ ),
743
+ )
744
+
745
+ // pre-EIP-155 `v`, no `chainId`
746
+ expect(
747
+ TxEnvelopeLegacy.hash(
748
+ TxEnvelopeLegacy.from({ ...unsigned, r, s, v: 27 + yParity }),
749
+ { presign: true },
750
+ ),
751
+ ).toBe(TxEnvelopeLegacy.getSignPayload(TxEnvelopeLegacy.from(unsigned)))
752
+ })
510
753
  })
511
754
 
512
755
  describe('serialize', () => {
@@ -787,7 +1030,7 @@ describe('serialize', () => {
787
1030
  value: BigInt('0x0'),
788
1031
  })
789
1032
  expect(serialized).toEqual(
790
- '0xe280808305208094c00000000000000000000000000000000000000080808284d88080',
1033
+ '0xe280808305208094c00000000000000000000000000000000000000080808284f38080',
791
1034
  )
792
1035
  })
793
1036
 
@@ -803,6 +1046,84 @@ describe('serialize', () => {
803
1046
  '[Signature.InvalidVError: Value `29` is an invalid v value. v must be 27, 28 or >=35.]',
804
1047
  )
805
1048
  })
1049
+
1050
+ describe('v + chainId', () => {
1051
+ const signed = {
1052
+ ...transaction,
1053
+ chainId: 1,
1054
+ r: '0x60fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe',
1055
+ s: '0x60fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe',
1056
+ } as const
1057
+
1058
+ test('behavior: v as parity', () => {
1059
+ expect(
1060
+ [0, 1, 27, 28, 37, 38].map((v) => {
1061
+ const { chainId, v: v_ } = TxEnvelopeLegacy.deserialize(
1062
+ TxEnvelopeLegacy.serialize({ ...signed, v }),
1063
+ )
1064
+ return { chainId, v: v_ }
1065
+ }),
1066
+ ).toMatchInlineSnapshot(`
1067
+ [
1068
+ {
1069
+ "chainId": 1,
1070
+ "v": 37,
1071
+ },
1072
+ {
1073
+ "chainId": 1,
1074
+ "v": 38,
1075
+ },
1076
+ {
1077
+ "chainId": 1,
1078
+ "v": 37,
1079
+ },
1080
+ {
1081
+ "chainId": 1,
1082
+ "v": 38,
1083
+ },
1084
+ {
1085
+ "chainId": 1,
1086
+ "v": 37,
1087
+ },
1088
+ {
1089
+ "chainId": 1,
1090
+ "v": 38,
1091
+ },
1092
+ ]
1093
+ `)
1094
+ })
1095
+
1096
+ test('error: v encodes another chain', () => {
1097
+ expect(() =>
1098
+ TxEnvelopeLegacy.serialize({ ...signed, v: 40 }),
1099
+ ).toThrowErrorMatchingInlineSnapshot(
1100
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "1" is invalid.]`,
1101
+ )
1102
+ expect(() =>
1103
+ TxEnvelopeLegacy.serialize({ ...signed, v: 35 }),
1104
+ ).toThrowErrorMatchingInlineSnapshot(
1105
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "1" is invalid.]`,
1106
+ )
1107
+ expect(() =>
1108
+ TxEnvelopeLegacy.serialize({ ...signed, chainId: 17000, v: 37 }),
1109
+ ).toThrowErrorMatchingInlineSnapshot(
1110
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "17000" is invalid.]`,
1111
+ )
1112
+ })
1113
+
1114
+ test('error: invalid v', () => {
1115
+ expect(() =>
1116
+ TxEnvelopeLegacy.serialize({ ...signed, v: 29 }),
1117
+ ).toThrowErrorMatchingInlineSnapshot(
1118
+ `[Signature.InvalidVError: Value \`29\` is an invalid v value. v must be 27, 28 or >=35.]`,
1119
+ )
1120
+ expect(() =>
1121
+ TxEnvelopeLegacy.serialize({ ...signed, v: 2 }),
1122
+ ).toThrowErrorMatchingInlineSnapshot(
1123
+ `[Signature.InvalidVError: Value \`2\` is an invalid v value. v must be 27, 28 or >=35.]`,
1124
+ )
1125
+ })
1126
+ })
806
1127
  })
807
1128
 
808
1129
  describe('toRpc', () => {
@@ -4,6 +4,47 @@ import { describe, expect, test } from 'vp/test'
4
4
  import { anvilMainnet } from '../../../test/prool.js'
5
5
 
6
6
  describe('fromRpc', () => {
7
+ test('behavior: unknown status and type named like `Object.prototype` keys', () => {
8
+ const { frameReceipts, status, type } = TransactionReceipt.fromRpc({
9
+ blockHash:
10
+ '0xc350d807505fb835650f0013632c5515592987ba169bbc6626d9fc54d91f0f0b',
11
+ blockNumber: '0x12f296f',
12
+ contractAddress: null,
13
+ cumulativeGasUsed: '0x82515',
14
+ effectiveGasPrice: '0x21c2f6c09',
15
+ frameReceipts: [
16
+ {
17
+ executionGasUsed: '0x0',
18
+ gasUsed: '0x0',
19
+ logs: [],
20
+ stateGasUsed: '0x0',
21
+ status: 'constructor',
22
+ },
23
+ ],
24
+ from: '0x814e5e0e31016b9a7f138c76b7e7b2bb5c1ab6a6',
25
+ gasUsed: '0x2abba',
26
+ logs: [],
27
+ logsBloom: '0x',
28
+ status: '__proto__',
29
+ to: '0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad',
30
+ transactionHash:
31
+ '0x353fdfc38a2f26115daadee9f5b8392ce62b84f410957967e2ed56b35338cdd0',
32
+ transactionIndex: '0x2',
33
+ type: 'toString',
34
+ } as unknown as TransactionReceipt.Rpc)
35
+ expect({
36
+ frameStatus: frameReceipts?.[0]?.status,
37
+ status,
38
+ type,
39
+ }).toMatchInlineSnapshot(`
40
+ {
41
+ "frameStatus": undefined,
42
+ "status": undefined,
43
+ "type": "toString",
44
+ }
45
+ `)
46
+ })
47
+
7
48
  test('default', () => {
8
49
  const receipt = TransactionReceipt.fromRpc({
9
50
  blobGasPrice: '0x42069',