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
@@ -84,11 +84,17 @@ export function from(value: Hex.Hex | Bytes.Bytes) {
84
84
  ? BigInt(Hex.fromBytes(bytes))
85
85
  : BigInt(value as string)
86
86
 
87
+ // Divide by 58^9, the largest power of 58 below 2^53, so each BigInt
88
+ // division yields nine digits that number arithmetic can split.
87
89
  let result = ''
88
90
  while (integer > 0n) {
89
- const remainder = Number(integer % 58n)
90
- integer = integer / 58n
91
- result = integerToAlphabet[remainder] + result
91
+ let remainder = Number(integer % 7_427_658_739_644_928n)
92
+ integer /= 7_427_658_739_644_928n
93
+ // Every chunk but the most significant one is zero-padded to nine digits.
94
+ for (let i = 0; i < 9 && (remainder > 0 || integer > 0n); i++) {
95
+ result = integerToAlphabet[remainder % 58] + result
96
+ remainder = Math.floor(remainder / 58)
97
+ }
92
98
  }
93
99
 
94
100
  return '1'.repeat(pad) + result
@@ -1,6 +1,6 @@
1
1
  import type * as Address from '../Address.js'
2
2
  import type * as Hex from '../Hex.js'
3
- import { BoundedMap } from './lru.js'
3
+ import { BoundedMap, weakCache } from './lru.js'
4
4
 
5
5
  /**
6
6
  * Global caches, cleared together by `Caches.clear` and on every engine change.
@@ -9,4 +9,6 @@ import { BoundedMap } from './lru.js'
9
9
  export const caches = {
10
10
  checksum: /*#__PURE__*/ new BoundedMap<Address.Address>(32_768),
11
11
  signatureHash: /*#__PURE__*/ new BoundedMap<Hex.Hex>(8_192),
12
+ typeHash: /*#__PURE__*/ new BoundedMap<Hex.Hex>(1_024),
13
+ signatureHashByItem: /*#__PURE__*/ weakCache<object, Hex.Hex>(),
12
14
  }
@@ -8,8 +8,12 @@ const hexes = /*#__PURE__*/ Array.from({ length: 256 }, (_v, i) =>
8
8
  i.toString(16).padStart(2, '0'),
9
9
  )
10
10
 
11
- // Char-code → 4-bit nibble lookup table. Sentinel `0xff` = invalid.
12
- const nibbleTable = /*#__PURE__*/ (() => {
11
+ /**
12
+ * Char-code → 4-bit nibble lookup table. Sentinel `0xff` = invalid.
13
+ *
14
+ * @internal
15
+ */
16
+ export const nibbleTable = /*#__PURE__*/ (() => {
13
17
  const table = new Uint8Array(256).fill(0xff)
14
18
  for (let i = 0; i < 10; i++) table[48 + i] = i // '0'-'9'
15
19
  for (let i = 0; i < 6; i++) {
@@ -179,6 +183,27 @@ export function hexToBytesLoop(value: string, length: number): Uint8Array {
179
183
  return out
180
184
  }
181
185
 
186
+ /**
187
+ * Throws exactly what {@link hexToBytes} throws for `value`, without decoding
188
+ * it, for callers that read the hex string directly.
189
+ *
190
+ * @internal
191
+ */
192
+ export function assertHexBytes(value: string): void {
193
+ if (
194
+ typeof value !== 'string' ||
195
+ value.length < 2 ||
196
+ value.charCodeAt(0) !== 48 /* '0' */ ||
197
+ value.charCodeAt(1) !== 120 /* 'x' */
198
+ )
199
+ throw new InvalidHexValueError(value)
200
+ if (((value.length - 2) & 1) !== 0) throw new InvalidLengthError(value as Hex)
201
+ // A regular expression scans about twice as fast as a lookup-table loop.
202
+ if (!hexRegex.test(value)) throw new InvalidHexValueError(value)
203
+ }
204
+
205
+ const hexRegex = /^0x[0-9a-fA-F]*$/
206
+
182
207
  /** @internal */
183
208
  export function charCodeToBase16(char: number): number | undefined {
184
209
  const v = nibbleTable[char] ?? 0xff
@@ -1,6 +1,15 @@
1
1
  import * as Errors from '../../Errors.js'
2
2
  import { bytesToHex } from './hex.js'
3
3
 
4
+ /**
5
+ * Significant byte count up to which {@link bytesToBigInt} shifts 8-byte chunks
6
+ * into the result. Each shift copies the result so far, so the loop is
7
+ * quadratic, and parsing hex overtakes it past 64 bytes on Node 24 and Bun.
8
+ *
9
+ * @internal
10
+ */
11
+ const shiftMaxBytes = 64
12
+
4
13
  /**
5
14
  * Decodes a big-endian unsigned `Uint8Array` into a `bigint`. When `signed` is
6
15
  * true, applies twos-complement on the high bit.
@@ -10,36 +19,35 @@ import { bytesToHex } from './hex.js'
10
19
  export function bytesToBigInt(value: Uint8Array, signed?: boolean): bigint {
11
20
  const len = value.length
12
21
  if (len === 0) return 0n
13
-
14
- // Fast path: unsigned big-endian read using DataView for 8-byte chunks,
15
- // skipping the hex round-trip.
16
- if (!signed) {
17
- let val = 0n
18
- let i = 0
19
- if (len >= 8) {
20
- const view = new DataView(value.buffer, value.byteOffset, len)
21
- const tail = len & 7
22
- const fullEnd = len - tail
23
- while (i < fullEnd) {
24
- val = (val << 64n) | view.getBigUint64(i, false)
25
- i += 8
26
- }
27
- }
28
- while (i < len) {
29
- val = (val << 8n) | BigInt(value[i]!)
30
- i++
22
+ // Two's complement of the unsigned value, without the hex round-trip.
23
+ if (signed) return BigInt.asIntN(len * 8, bytesToBigInt(value))
24
+
25
+ // Skip leading zeros first: ABI words are 32 bytes but usually hold small
26
+ // values, which then fit a Number and skip the BigInt arithmetic.
27
+ let i = 0
28
+ while (i < len && value[i] === 0) i++
29
+ if (len - i <= 6) {
30
+ let n = 0
31
+ for (; i < len; i++) n = n * 256 + value[i]!
32
+ return BigInt(n)
33
+ }
34
+ if (len - i > shiftMaxBytes) return BigInt(bytesToHex(value))
35
+
36
+ // Unsigned big-endian read using DataView for 8-byte chunks.
37
+ let val = 0n
38
+ const fullEnd = len - ((len - i) & 7)
39
+ if (i < fullEnd) {
40
+ const view = new DataView(value.buffer, value.byteOffset, len)
41
+ while (i < fullEnd) {
42
+ val = (val << 64n) | view.getBigUint64(i, false)
43
+ i += 8
31
44
  }
32
- return val
33
45
  }
34
-
35
- // Signed: BigInt parses hex strings faster than the per-byte loop for
36
- // > 8-byte inputs in V8/JSC, so route through `bytesToHex`.
37
- const hex = bytesToHex(value)
38
- const n = hex === '0x' ? 0n : BigInt(hex)
39
- const max_unsigned = 1n << (BigInt(len) * 8n)
40
- const max_signed = max_unsigned >> 1n
41
- if (n < max_signed) return n
42
- return n - max_unsigned
46
+ while (i < len) {
47
+ val = (val << 8n) | BigInt(value[i]!)
48
+ i++
49
+ }
50
+ return val
43
51
  }
44
52
 
45
53
  /**
@@ -49,11 +57,16 @@ export function bytesToBigInt(value: Uint8Array, signed?: boolean): bigint {
49
57
  * @internal
50
58
  */
51
59
  export function bytesToSafeNumber(value: Uint8Array, signed?: boolean): number {
52
- if (!signed && value.length <= 6) {
60
+ if (!signed) {
53
61
  // Small unsigned values fit in a number directly without BigInt round-trip.
54
- let n = 0
55
- for (let i = 0; i < value.length; i++) n = n * 256 + value[i]!
56
- return n
62
+ const length = value.length
63
+ let i = 0
64
+ while (i < length && value[i] === 0) i++
65
+ if (length - i <= 6) {
66
+ let n = 0
67
+ for (; i < length; i++) n = n * 256 + value[i]!
68
+ return n
69
+ }
57
70
  }
58
71
  const big = bytesToBigInt(value, signed)
59
72
  const num = Number(big)
@@ -4,17 +4,29 @@ import * as Errors from '../Errors.js'
4
4
  /** @internal */
5
5
  export type Cursor = {
6
6
  bytes: Bytes
7
- dataView: DataView
7
+ /** Lazy: created on first access, since most cursors never use it. */
8
+ readonly dataView: DataView
9
+ /** Backing field of `dataView`. */
10
+ _dataView: DataView | undefined
8
11
  position: number
9
- /** Lazy: only allocated when slow-path tracking kicks in. */
10
- positionReadCount: Map<number, number> | undefined
12
+ /**
13
+ * Positions read so far, so a repeated read can be counted. Word-aligned
14
+ * positions, where ABI data is read, go in a bit set with one bit per 32
15
+ * bytes; other positions go in a set. Both are allocated on first use.
16
+ */
17
+ alignedReads: Uint8Array | undefined
18
+ unalignedReads: Set<number> | undefined
19
+ /** Total number of bytes read. */
20
+ readSize: number
21
+ /** Maximum total number of bytes that can be read. */
22
+ readSizeLimit: number
11
23
  recursiveReadCount: number
12
24
  recursiveReadLimit: number
13
25
  remaining: number
14
26
  assertReadLimit(position?: number): void
27
+ assertReadSize(length: number): void
15
28
  assertPosition(position: number): void
16
29
  decrementPosition(offset: number): void
17
- getReadCount(position?: number): number
18
30
  incrementPosition(offset: number): void
19
31
  inspectByte(position?: number): Bytes[number]
20
32
  inspectBytes(length: number, position?: number): Bytes
@@ -40,9 +52,19 @@ export type Cursor = {
40
52
 
41
53
  const staticCursor: Cursor = {
42
54
  bytes: new Uint8Array(),
43
- dataView: new DataView(new ArrayBuffer(0)),
55
+ get dataView() {
56
+ return (this._dataView ??= new DataView(
57
+ this.bytes.buffer,
58
+ this.bytes.byteOffset,
59
+ this.bytes.byteLength,
60
+ ))
61
+ },
62
+ _dataView: undefined,
44
63
  position: 0,
45
- positionReadCount: undefined,
64
+ alignedReads: undefined,
65
+ unalignedReads: undefined,
66
+ readSize: 0,
67
+ readSizeLimit: Number.POSITIVE_INFINITY,
46
68
  recursiveReadCount: 0,
47
69
  recursiveReadLimit: Number.POSITIVE_INFINITY,
48
70
  assertReadLimit() {
@@ -52,6 +74,14 @@ const staticCursor: Cursor = {
52
74
  limit: this.recursiveReadLimit,
53
75
  })
54
76
  },
77
+ assertReadSize(length) {
78
+ this.readSize += length
79
+ if (this.readSize > this.readSizeLimit)
80
+ throw new ReadSizeLimitExceededError({
81
+ limit: this.readSizeLimit,
82
+ size: this.readSize,
83
+ })
84
+ },
55
85
  assertPosition(position) {
56
86
  if (position < 0 || position > this.bytes.length - 1)
57
87
  throw new PositionOutOfBoundsError({
@@ -65,9 +95,6 @@ const staticCursor: Cursor = {
65
95
  this.assertPosition(position)
66
96
  this.position = position
67
97
  },
68
- getReadCount(position) {
69
- return this.positionReadCount?.get(position || this.position) || 0
70
- },
71
98
  incrementPosition(offset) {
72
99
  if (offset < 0) throw new NegativeOffsetError({ offset })
73
100
  const position = this.position + offset
@@ -142,6 +169,7 @@ const staticCursor: Cursor = {
142
169
  this.assertReadLimit()
143
170
  this._touch()
144
171
  const value = this.inspectByte()
172
+ this.assertReadSize(1)
145
173
  this.position++
146
174
  return value
147
175
  },
@@ -149,6 +177,7 @@ const staticCursor: Cursor = {
149
177
  this.assertReadLimit()
150
178
  this._touch()
151
179
  const value = this.inspectBytes(length)
180
+ this.assertReadSize(length)
152
181
  this.position += size ?? length
153
182
  return value
154
183
  },
@@ -156,6 +185,7 @@ const staticCursor: Cursor = {
156
185
  this.assertReadLimit()
157
186
  this._touch()
158
187
  const value = this.inspectUint8()
188
+ this.assertReadSize(1)
159
189
  this.position += 1
160
190
  return value
161
191
  },
@@ -163,6 +193,7 @@ const staticCursor: Cursor = {
163
193
  this.assertReadLimit()
164
194
  this._touch()
165
195
  const value = this.inspectUint16()
196
+ this.assertReadSize(2)
166
197
  this.position += 2
167
198
  return value
168
199
  },
@@ -170,6 +201,7 @@ const staticCursor: Cursor = {
170
201
  this.assertReadLimit()
171
202
  this._touch()
172
203
  const value = this.inspectUint24()
204
+ this.assertReadSize(3)
173
205
  this.position += 3
174
206
  return value
175
207
  },
@@ -177,6 +209,7 @@ const staticCursor: Cursor = {
177
209
  this.assertReadLimit()
178
210
  this._touch()
179
211
  const value = this.inspectUint32()
212
+ this.assertReadSize(4)
180
213
  this.position += 4
181
214
  return value
182
215
  },
@@ -191,10 +224,29 @@ const staticCursor: Cursor = {
191
224
  },
192
225
  _touch() {
193
226
  if (this.recursiveReadLimit === Number.POSITIVE_INFINITY) return
194
- const map = (this.positionReadCount ??= new Map())
195
- const count = map.get(this.position) || 0
196
- map.set(this.position, count + 1)
197
- if (count > 0) this.recursiveReadCount++
227
+ const { position } = this
228
+ if (position % 32 !== 0 || position > this.bytes.length) {
229
+ const reads = (this.unalignedReads ??= new Set())
230
+ if (reads.has(position)) this.recursiveReadCount++
231
+ else reads.add(position)
232
+ return
233
+ }
234
+ // One bit per 32-byte word, so the set is 1/256 the size of the data. It
235
+ // is sized from the data's length at the time of the read, so a resizable
236
+ // buffer that grows while decoding still has every read counted.
237
+ const word = position / 32
238
+ const index = Math.floor(word / 8)
239
+ let reads = this.alignedReads
240
+ if (!reads || index >= reads.length) {
241
+ const grown = new Uint8Array(
242
+ Math.max(Math.floor(this.bytes.length / 256) + 1, index + 1),
243
+ )
244
+ if (reads) grown.set(reads)
245
+ reads = this.alignedReads = grown
246
+ }
247
+ const bit = 1 << (word & 7)
248
+ if (reads[index]! & bit) this.recursiveReadCount++
249
+ else reads[index]! |= bit
198
250
  },
199
251
  }
200
252
 
@@ -205,13 +257,15 @@ export function create(
205
257
  ): Cursor {
206
258
  const cursor: Cursor = Object.create(staticCursor)
207
259
  cursor.bytes = bytes
208
- cursor.dataView = new DataView(
209
- bytes.buffer,
210
- bytes.byteOffset,
211
- bytes.byteLength,
212
- )
213
- cursor.positionReadCount = undefined
260
+ cursor._dataView = undefined
261
+ cursor.alignedReads = undefined
262
+ cursor.unalignedReads = undefined
214
263
  cursor.recursiveReadLimit = recursiveReadLimit
264
+ // A well-formed payload reads each byte once. Allow twice that, plus as many
265
+ // bytes as `recursiveReadLimit` repeated 32-byte reads (256 KiB by default),
266
+ // so that offsets pointing many times at one region can add at most that
267
+ // fixed amount to the decoded output, whatever the size of the data.
268
+ cursor.readSizeLimit = 2 * bytes.length + 32 * recursiveReadLimit
215
269
  return cursor
216
270
  }
217
271
 
@@ -242,6 +296,17 @@ export class PositionOutOfBoundsError extends Errors.BaseError {
242
296
  }
243
297
  }
244
298
 
299
+ /** @internal */
300
+ export class ReadSizeLimitExceededError extends Errors.BaseError {
301
+ override readonly name = 'Cursor.ReadSizeLimitExceededError'
302
+
303
+ constructor({ limit, size }: { limit: number; size: number }) {
304
+ super(
305
+ `Read size limit of \`${limit}\` bytes exceeded (read size: \`${size}\` bytes).`,
306
+ )
307
+ }
308
+ }
309
+
245
310
  /** @internal */
246
311
  export class RecursiveReadLimitExceededError extends Errors.BaseError {
247
312
  override readonly name = 'Cursor.RecursiveReadLimitExceededError'
@@ -1,10 +1,10 @@
1
1
  /**
2
- * Map with a LRU (Least recently used) policy.
2
+ * Map with a bounded FIFO eviction policy. Reads do not reorder entries; only
3
+ * writes touch the eviction queue.
3
4
  *
4
- * @see https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU
5
5
  * @internal
6
6
  */
7
- export class LruMap<value = unknown> extends Map<string, value> {
7
+ export class BoundedMap<value = unknown> extends Map<string, value> {
8
8
  maxSize: number
9
9
 
10
10
  constructor(size: number) {
@@ -12,47 +12,33 @@ export class LruMap<value = unknown> extends Map<string, value> {
12
12
  this.maxSize = size
13
13
  }
14
14
 
15
- override get(key: string) {
16
- const value = super.get(key)
17
-
18
- if (super.has(key) && value !== undefined) {
19
- this.delete(key)
20
- super.set(key, value)
21
- }
22
-
23
- return value
24
- }
25
-
26
15
  override set(key: string, value: value) {
27
- super.set(key, value)
28
- if (this.maxSize && this.size > this.maxSize) {
16
+ if (!super.has(key) && this.maxSize && this.size >= this.maxSize) {
29
17
  const firstKey = this.keys().next().value
30
- if (firstKey) this.delete(firstKey)
18
+ if (firstKey !== undefined) this.delete(firstKey)
31
19
  }
32
- return this
20
+ return super.set(key, value)
33
21
  }
34
22
  }
35
23
 
36
24
  /**
37
- * Map with a bounded FIFO eviction policy. Cheaper than {@link LruMap} on hot
38
- * `get` paths because reads do not reorder entries; only writes touch the
39
- * eviction queue.
25
+ * Cache keyed by object identity. Entries live as long as their key, and
26
+ * `clear` drops them all by swapping in a new `WeakMap`, which has no `clear`
27
+ * of its own.
40
28
  *
41
29
  * @internal
42
30
  */
43
- export class BoundedMap<value = unknown> extends Map<string, value> {
44
- maxSize: number
45
-
46
- constructor(size: number) {
47
- super()
48
- this.maxSize = size
49
- }
50
-
51
- override set(key: string, value: value) {
52
- if (!super.has(key) && this.maxSize && this.size >= this.maxSize) {
53
- const firstKey = this.keys().next().value
54
- if (firstKey !== undefined) this.delete(firstKey)
55
- }
56
- return super.set(key, value)
31
+ export function weakCache<key extends object, value>() {
32
+ let map = new WeakMap<key, value>()
33
+ return {
34
+ clear() {
35
+ map = new WeakMap()
36
+ },
37
+ get(key: key) {
38
+ return map.get(key)
39
+ },
40
+ set(key: key, value: value) {
41
+ map.set(key, value)
42
+ },
57
43
  }
58
44
  }
@@ -5,9 +5,12 @@ export function withTimeout<data>(
5
5
  fn: withTimeout.Fn<data>,
6
6
  options: withTimeout.Options,
7
7
  ): Promise<data> {
8
- const { errorInstance = new TimeoutError(), timeout, signal } = options
8
+ const { timeout, signal } = options
9
9
  // Fast path: no timeout, skip allocating Promise wrapper and AbortController.
10
10
  if (!(timeout > 0)) return fn({ signal: null })
11
+ // Built only on timeout: an error captures a stack trace, which costs more
12
+ // than the request bookkeeping around it.
13
+ const error = () => options.errorInstance ?? new TimeoutError()
11
14
  return new Promise((resolve, reject) => {
12
15
  void (async () => {
13
16
  let timeoutId: any
@@ -16,13 +19,16 @@ export function withTimeout<data>(
16
19
  try {
17
20
  timeoutId = setTimeout(() => {
18
21
  timedOut = true
19
- if (controller) controller.abort()
20
- else reject(errorInstance)
22
+ controller?.abort()
23
+ // Reject as well as abort: `fn` may ignore the signal and never
24
+ // settle.
25
+ reject(error())
21
26
  }, timeout)
22
27
  resolve(await fn({ signal: controller?.signal ?? null }))
23
28
  } catch (err) {
24
- if (timedOut || (err as Error)?.name === 'AbortError')
25
- reject(errorInstance)
29
+ // A timeout has rejected already.
30
+ if (timedOut) return
31
+ if ((err as Error)?.name === 'AbortError') reject(error())
26
32
  else reject(err)
27
33
  } finally {
28
34
  clearTimeout(timeoutId)
@@ -612,10 +612,9 @@ export function hash<
612
612
  callGasLimit,
613
613
  )
614
614
  const gasFees = packUint128Pair(maxPriorityFeePerGas, maxFeePerGas)
615
- const initCode_hashed =
616
- factory && factoryData
617
- ? Hash.keccak256(Hex.concat(factory, factoryData))
618
- : EMPTY_KECCAK
615
+ const initCode_hashed = Hash.keccak256(
616
+ toInitCode({ factory, factoryData }),
617
+ )
619
618
  const paymasterAndData_hashed = paymaster
620
619
  ? Hash.keccak256(
621
620
  Hex.concat(
@@ -1,4 +1,4 @@
1
- import { Hex, Signature } from 'ox'
1
+ import { AbiParameters, Hash, Hex, Signature } from 'ox'
2
2
  import { UserOperation } from 'ox/erc4337'
3
3
  import { describe, expect, test } from 'vp/test'
4
4
 
@@ -552,6 +552,64 @@ describe('hash', () => {
552
552
  )
553
553
  })
554
554
 
555
+ test('args: factory without factoryData', () => {
556
+ const userOperation = {
557
+ callData: '0x',
558
+ callGasLimit: 6942069n,
559
+ factory: '0x1234567890123456789012345678901234567890',
560
+ maxFeePerGas: 69420n,
561
+ maxPriorityFeePerGas: 69n,
562
+ nonce: 0n,
563
+ preVerificationGas: 6942069n,
564
+ sender: '0x1234567890123456789012345678901234567890',
565
+ signature: '0x',
566
+ verificationGasLimit: 6942069n,
567
+ } as const
568
+ const options = {
569
+ chainId: 1,
570
+ entryPointAddress: '0x1234567890123456789012345678901234567890',
571
+ entryPointVersion: '0.7',
572
+ } as const
573
+
574
+ // EntryPoint 0.7 `getUserOpHash` over the packed user operation.
575
+ const packed = UserOperation.toPacked(userOperation)
576
+ expect(packed.initCode).toBe(userOperation.factory)
577
+ const expected = Hash.keccak256(
578
+ AbiParameters.encode(AbiParameters.from('bytes32, address, uint256'), [
579
+ Hash.keccak256(
580
+ AbiParameters.encode(
581
+ AbiParameters.from(
582
+ 'address, uint256, bytes32, bytes32, bytes32, uint256, bytes32, bytes32',
583
+ ),
584
+ [
585
+ packed.sender,
586
+ packed.nonce,
587
+ Hash.keccak256(packed.initCode),
588
+ Hash.keccak256(packed.callData),
589
+ packed.accountGasLimits,
590
+ packed.preVerificationGas,
591
+ packed.gasFees,
592
+ Hash.keccak256(packed.paymasterAndData),
593
+ ],
594
+ ),
595
+ ),
596
+ options.entryPointAddress,
597
+ BigInt(options.chainId),
598
+ ]),
599
+ )
600
+ expect(expected).toMatchInlineSnapshot(
601
+ `"0x3990ff4fd5d4f830db9a8a7b75c4c20107d60a58d3819caea8eab03d03fe6ae6"`,
602
+ )
603
+
604
+ expect(UserOperation.hash(userOperation, options)).toBe(expected)
605
+ expect(
606
+ UserOperation.hash({ ...userOperation, factoryData: '0x' }, options),
607
+ ).toBe(expected)
608
+ expect(
609
+ UserOperation.hash(UserOperation.fromPacked(packed), options),
610
+ ).toBe(expected)
611
+ })
612
+
555
613
  test('args: paymaster', () => {
556
614
  expect(
557
615
  UserOperation.hash(
@@ -33,7 +33,7 @@ const wrappedParameters = /*#__PURE__*/ AbiParameters.from(
33
33
  * Deployless ERC-6492 signature verification bytecode.
34
34
  */
35
35
  export const universalSignatureValidatorBytecode =
36
- '0x608060405234801561001057600080fd5b5060405161069438038061069483398101604081905261002f9161051e565b600061003c848484610048565b9050806000526001601ff35b60007f64926492649264926492649264926492649264926492649264926492649264926100748361040c565b036101e7576000606080848060200190518101906100929190610577565b60405192955090935091506000906001600160a01b038516906100b69085906105dd565b6000604051808303816000865af19150503d80600081146100f3576040519150601f19603f3d011682016040523d82523d6000602084013e6100f8565b606091505b50509050876001600160a01b03163b60000361016057806101605760405162461bcd60e51b815260206004820152601e60248201527f5369676e617475726556616c696461746f723a206465706c6f796d656e74000060448201526064015b60405180910390fd5b604051630b135d3f60e11b808252906001600160a01b038a1690631626ba7e90610190908b9087906004016105f9565b602060405180830381865afa1580156101ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101d19190610633565b6001600160e01b03191614945050505050610405565b6001600160a01b0384163b1561027a57604051630b135d3f60e11b808252906001600160a01b03861690631626ba7e9061022790879087906004016105f9565b602060405180830381865afa158015610244573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102689190610633565b6001600160e01b031916149050610405565b81516041146102df5760405162461bcd60e51b815260206004820152603a602482015260008051602061067483398151915260448201527f3a20696e76616c6964207369676e6174757265206c656e6774680000000000006064820152608401610157565b6102e7610425565b5060208201516040808401518451859392600091859190811061030c5761030c61065d565b016020015160f81c9050601b811480159061032b57508060ff16601c14155b1561038c5760405162461bcd60e51b815260206004820152603b602482015260008051602061067483398151915260448201527f3a20696e76616c6964207369676e617475726520762076616c756500000000006064820152608401610157565b60408051600081526020810180835289905260ff83169181019190915260608101849052608081018390526001600160a01b0389169060019060a0016020604051602081039080840390855afa1580156103ea573d6000803e3d6000fd5b505050602060405103516001600160a01b0316149450505050505b9392505050565b600060208251101561041d57600080fd5b508051015190565b60405180606001604052806003906020820280368337509192915050565b6001600160a01b038116811461045857600080fd5b50565b634e487b7160e01b600052604160045260246000fd5b60005b8381101561048c578181015183820152602001610474565b50506000910152565b600082601f8301126104a657600080fd5b81516001600160401b038111156104bf576104bf61045b565b604051601f8201601f19908116603f011681016001600160401b03811182821017156104ed576104ed61045b565b60405281815283820160200185101561050557600080fd5b610516826020830160208701610471565b949350505050565b60008060006060848603121561053357600080fd5b835161053e81610443565b6020850151604086015191945092506001600160401b0381111561056157600080fd5b61056d86828701610495565b9150509250925092565b60008060006060848603121561058c57600080fd5b835161059781610443565b60208501519093506001600160401b038111156105b357600080fd5b6105bf86828701610495565b604086015190935090506001600160401b0381111561056157600080fd5b600082516105ef818460208701610471565b9190910192915050565b828152604060208201526000825180604084015261061e816060850160208701610471565b601f01601f1916919091016060019392505050565b60006020828403121561064557600080fd5b81516001600160e01b03198116811461040557600080fd5b634e487b7160e01b600052603260045260246000fdfe5369676e617475726556616c696461746f72237265636f7665725369676e6572'
36
+ '0x608060405234801561001057600080fd5b506040516106ad3803806106ad83398101604081905261002f91610537565b600061003c848484610048565b9050806000526001601ff35b60007f649264926492649264926492649264926492649264926492649264926492649261007483610425565b036101e7576000606080848060200190518101906100929190610590565b60405192955090935091506000906001600160a01b038516906100b69085906105f6565b6000604051808303816000865af19150503d80600081146100f3576040519150601f19603f3d011682016040523d82523d6000602084013e6100f8565b606091505b50509050876001600160a01b03163b60000361016057806101605760405162461bcd60e51b815260206004820152601e60248201527f5369676e617475726556616c696461746f723a206465706c6f796d656e74000060448201526064015b60405180910390fd5b604051630b135d3f60e11b808252906001600160a01b038a1690631626ba7e90610190908b908790600401610612565b602060405180830381865afa1580156101ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101d1919061064c565b6001600160e01b0319161494505050505061041e565b6001600160a01b0384163b1561027a57604051630b135d3f60e11b808252906001600160a01b03861690631626ba7e906102279087908790600401610612565b602060405180830381865afa158015610244573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610268919061064c565b6001600160e01b03191614905061041e565b81516041146102df5760405162461bcd60e51b815260206004820152603a602482015260008051602061068d83398151915260448201527f3a20696e76616c6964207369676e6174757265206c656e6774680000000000006064820152608401610157565b6102e761043e565b5060208201516040808401518451859392600091859190811061030c5761030c610676565b016020015160f81c9050601b811480159061032b57508060ff16601c14155b1561038c5760405162461bcd60e51b815260206004820152603b602482015260008051602061068d83398151915260448201527f3a20696e76616c6964207369676e617475726520762076616c756500000000006064820152608401610157565b604080516000808252602082018084528a905260ff841692820192909252606081018590526080810184905260019060a0016020604051602081039080840390855afa1580156103e0573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116158015906104165750886001600160a01b0316816001600160a01b0316145b955050505050505b9392505050565b600060208251101561043657600080fd5b508051015190565b60405180606001604052806003906020820280368337509192915050565b6001600160a01b038116811461047157600080fd5b50565b634e487b7160e01b600052604160045260246000fd5b60005b838110156104a557818101518382015260200161048d565b50506000910152565b600082601f8301126104bf57600080fd5b81516001600160401b038111156104d8576104d8610474565b604051601f8201601f19908116603f011681016001600160401b038111828210171561050657610506610474565b60405281815283820160200185101561051e57600080fd5b61052f82602083016020870161048a565b949350505050565b60008060006060848603121561054c57600080fd5b83516105578161045c565b6020850151604086015191945092506001600160401b0381111561057a57600080fd5b610586868287016104ae565b9150509250925092565b6000806000606084860312156105a557600080fd5b83516105b08161045c565b60208501519093506001600160401b038111156105cc57600080fd5b6105d8868287016104ae565b604086015190935090506001600160401b0381111561057a57600080fd5b6000825161060881846020870161048a565b9190910192915050565b828152604060208201526000825180604084015261063781606085016020870161048a565b601f01601f1916919091016060019392505050565b60006020828403121561065e57600080fd5b81516001600160e01b03198116811461041e57600080fd5b634e487b7160e01b600052603260045260246000fdfe5369676e617475726556616c696461746f72237265636f7665725369676e6572'
37
37
 
38
38
  /**
39
39
  * ABI for the ERC-6492 universal deployless signature validator contract.
@@ -1,7 +1,8 @@
1
- import { Secp256k1, Signature } from 'ox'
1
+ import { AbiConstructor, Hex, Secp256k1, Signature } from 'ox'
2
2
  import { SignatureErc6492 } from 'ox/erc6492'
3
3
  import { describe, expect, test } from 'vp/test'
4
4
  import { accounts } from '../../../test/constants/accounts.js'
5
+ import { anvilMainnet } from '../../../test/prool.js'
5
6
 
6
7
  describe('assert', () => {
7
8
  test('default', () => {
@@ -159,3 +160,49 @@ describe('from: validates object inputs', () => {
159
160
  expect(SignatureErc6492.from(args)).toEqual(args)
160
161
  })
161
162
  })
163
+
164
+ describe('universalSignatureValidatorBytecode', () => {
165
+ const constructor = AbiConstructor.fromAbi(
166
+ SignatureErc6492.universalSignatureValidatorAbi,
167
+ )
168
+
169
+ function verify(args: readonly [Hex.Hex, Hex.Hex, Hex.Hex]) {
170
+ return anvilMainnet.request({
171
+ method: 'eth_call',
172
+ params: [
173
+ {
174
+ data: AbiConstructor.encode(constructor, {
175
+ args,
176
+ bytecode: SignatureErc6492.universalSignatureValidatorBytecode,
177
+ }),
178
+ },
179
+ ],
180
+ })
181
+ }
182
+
183
+ const hash = Hex.padLeft('0xdeadbeef', 32)
184
+
185
+ test('behavior: valid signature', async () => {
186
+ const signature = Secp256k1.sign({
187
+ payload: hash,
188
+ privateKey: accounts[0].privateKey,
189
+ })
190
+
191
+ expect(
192
+ await verify([accounts[0].address, hash, Signature.toHex(signature)]),
193
+ ).toMatchInlineSnapshot(`"0x01"`)
194
+ })
195
+
196
+ test('behavior: zero address with a signature that recovers to it', async () => {
197
+ // `r = 0` and `s = 0` with `v = 27`, which `ecrecover` maps to the zero address.
198
+ const signature = Hex.concat(Hex.fromNumber(0, { size: 64 }), '0x1b')
199
+
200
+ expect(
201
+ await verify([
202
+ '0x0000000000000000000000000000000000000000',
203
+ hash,
204
+ signature,
205
+ ]),
206
+ ).toMatchInlineSnapshot(`"0x00"`)
207
+ })
208
+ })