voltaire-effect 0.2.23 → 0.2.24

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 (264) hide show
  1. package/dist/KZGService-B7PJerOb.d.ts +146 -0
  2. package/dist/{X25519Test-DGsk1V9o.d.ts → X25519Test-C8Cicdd_.d.ts} +2 -139
  3. package/dist/crypto/index.d.ts +3 -2
  4. package/dist/{index-IgkEHjBe.d.ts → index-DsFjN_a3.d.ts} +17633 -11961
  5. package/dist/index.d.ts +3104 -938
  6. package/dist/index.js +4467 -2446
  7. package/dist/native/index.d.ts +14 -5
  8. package/dist/native/index.js +4489 -2468
  9. package/dist/primitives/index.d.ts +12 -4
  10. package/dist/primitives/index.js +3980 -2411
  11. package/package.json +2 -2
  12. package/src/crypto/Keccak256/index.ts +1 -0
  13. package/src/index.ts +2 -2
  14. package/src/primitives/Abi/decode.test.ts +38 -0
  15. package/src/primitives/Abi/decode.ts +67 -0
  16. package/src/primitives/Abi/decodeData.test.ts +37 -0
  17. package/src/primitives/Abi/decodeData.ts +77 -0
  18. package/src/primitives/Abi/decodeLog.test.ts +32 -0
  19. package/src/primitives/Abi/decodeLog.ts +81 -0
  20. package/src/primitives/Abi/decodeWrappedError.test.ts +41 -0
  21. package/src/primitives/Abi/decodeWrappedError.ts +68 -0
  22. package/src/primitives/Abi/encode.test.ts +43 -0
  23. package/src/primitives/Abi/encode.ts +67 -0
  24. package/src/primitives/Abi/encodePacked.test.ts +35 -0
  25. package/src/primitives/Abi/encodePacked.ts +62 -0
  26. package/src/primitives/Abi/encodeWrappedError.test.ts +21 -0
  27. package/src/primitives/Abi/encodeWrappedError.ts +64 -0
  28. package/src/primitives/Abi/findSelectorCollisions.test.ts +50 -0
  29. package/src/primitives/Abi/findSelectorCollisions.ts +83 -0
  30. package/src/primitives/Abi/index.ts +33 -7
  31. package/src/primitives/Abi/parseLogs.test.ts +37 -0
  32. package/src/primitives/Abi/parseLogs.ts +62 -0
  33. package/src/primitives/AccessList/AccessList.test.ts +229 -0
  34. package/src/primitives/AccessList/AccessListTypeSchema.ts +16 -0
  35. package/src/primitives/AccessList/addressCount.ts +21 -0
  36. package/src/primitives/AccessList/assertValid.ts +37 -0
  37. package/src/primitives/AccessList/create.ts +19 -0
  38. package/src/primitives/AccessList/deduplicate.ts +23 -0
  39. package/src/primitives/AccessList/from.ts +39 -0
  40. package/src/primitives/AccessList/fromBytes.ts +36 -0
  41. package/src/primitives/AccessList/gasCost.ts +22 -0
  42. package/src/primitives/AccessList/gasSavings.ts +26 -0
  43. package/src/primitives/AccessList/hasSavings.ts +23 -0
  44. package/src/primitives/AccessList/includesAddress.ts +25 -0
  45. package/src/primitives/AccessList/includesStorageKey.ts +28 -0
  46. package/src/primitives/AccessList/index.ts +99 -19
  47. package/src/primitives/AccessList/is.ts +23 -0
  48. package/src/primitives/AccessList/isEmpty.ts +23 -0
  49. package/src/primitives/AccessList/isItem.ts +22 -0
  50. package/src/primitives/AccessList/keysFor.ts +29 -0
  51. package/src/primitives/AccessList/merge.ts +24 -0
  52. package/src/primitives/AccessList/storageKeyCount.ts +21 -0
  53. package/src/primitives/AccessList/toBytes.ts +23 -0
  54. package/src/primitives/AccessList/withAddress.ts +27 -0
  55. package/src/primitives/AccessList/withStorageKey.ts +30 -0
  56. package/src/primitives/Address/Address.test.ts +146 -0
  57. package/src/primitives/Address/assert.ts +51 -0
  58. package/src/primitives/Address/calculateCreate2Address.ts +33 -0
  59. package/src/primitives/Address/calculateCreateAddress.ts +30 -0
  60. package/src/primitives/Address/deduplicateAddresses.ts +20 -0
  61. package/src/primitives/Address/from.ts +41 -0
  62. package/src/primitives/Address/fromAbiEncoded.ts +35 -0
  63. package/src/primitives/Address/fromBase64.ts +25 -0
  64. package/src/primitives/Address/fromBytes.ts +25 -0
  65. package/src/primitives/Address/fromHex.ts +31 -0
  66. package/src/primitives/Address/fromNumber.ts +25 -0
  67. package/src/primitives/Address/fromPrivateKey.ts +25 -0
  68. package/src/primitives/Address/fromPublicKey.ts +56 -0
  69. package/src/primitives/Address/index.ts +99 -35
  70. package/src/primitives/Address/is.ts +20 -0
  71. package/src/primitives/Address/isAddress.ts +22 -0
  72. package/src/primitives/Address/sortAddresses.ts +19 -0
  73. package/src/primitives/Address/toChecksummed.ts +32 -0
  74. package/src/primitives/Address/toHex.ts +18 -0
  75. package/src/primitives/Address/zero.ts +18 -0
  76. package/src/primitives/Base64/Base64.test.ts +75 -0
  77. package/src/primitives/Base64/convert.ts +37 -0
  78. package/src/primitives/Base64/decode.ts +59 -0
  79. package/src/primitives/Base64/encode.ts +42 -0
  80. package/src/primitives/Base64/from.ts +39 -0
  81. package/src/primitives/Base64/index.ts +81 -1
  82. package/src/primitives/Base64/size.ts +16 -0
  83. package/src/primitives/Base64/validation.ts +16 -0
  84. package/src/primitives/Blob/Blob.test.ts +292 -0
  85. package/src/primitives/Blob/calculateGas.ts +30 -0
  86. package/src/primitives/Blob/estimateBlobCount.ts +30 -0
  87. package/src/primitives/Blob/from.ts +38 -0
  88. package/src/primitives/Blob/fromData.ts +36 -0
  89. package/src/primitives/Blob/index.ts +99 -12
  90. package/src/primitives/Blob/isValidVersion.ts +27 -0
  91. package/src/primitives/Blob/joinData.ts +43 -0
  92. package/src/primitives/Blob/splitData.ts +36 -0
  93. package/src/primitives/Blob/toCommitment.ts +43 -0
  94. package/src/primitives/Blob/toProof.ts +50 -0
  95. package/src/primitives/Blob/toVersionedHash.ts +35 -0
  96. package/src/primitives/Blob/verify.ts +49 -0
  97. package/src/primitives/Blob/verifyBatch.ts +119 -0
  98. package/src/primitives/BloomFilter/BloomFilter.test.ts +138 -0
  99. package/src/primitives/BloomFilter/add.ts +23 -0
  100. package/src/primitives/BloomFilter/combine.ts +21 -0
  101. package/src/primitives/BloomFilter/contains.ts +26 -0
  102. package/src/primitives/BloomFilter/create.ts +35 -0
  103. package/src/primitives/BloomFilter/density.ts +22 -0
  104. package/src/primitives/BloomFilter/expectedFalsePositiveRate.ts +25 -0
  105. package/src/primitives/BloomFilter/fromHex.ts +37 -0
  106. package/src/primitives/BloomFilter/hash.ts +43 -0
  107. package/src/primitives/BloomFilter/index.ts +59 -37
  108. package/src/primitives/BloomFilter/isEmpty.ts +22 -0
  109. package/src/primitives/BloomFilter/merge.ts +24 -0
  110. package/src/primitives/BloomFilter/toHex.ts +22 -0
  111. package/src/primitives/Bytecode/analyze.ts +58 -0
  112. package/src/primitives/Bytecode/detectFusions.ts +10 -0
  113. package/src/primitives/Bytecode/equals.ts +10 -0
  114. package/src/primitives/Bytecode/extractRuntime.ts +12 -0
  115. package/src/primitives/Bytecode/format.ts +16 -0
  116. package/src/primitives/Bytecode/from.ts +16 -0
  117. package/src/primitives/Bytecode/fromHex.ts +14 -0
  118. package/src/primitives/Bytecode/getBlock.ts +12 -0
  119. package/src/primitives/Bytecode/getNextPc.ts +12 -0
  120. package/src/primitives/Bytecode/getPushSize.ts +8 -0
  121. package/src/primitives/Bytecode/hasMetadata.ts +10 -0
  122. package/src/primitives/Bytecode/hash.ts +9 -0
  123. package/src/primitives/Bytecode/index.ts +103 -13
  124. package/src/primitives/Bytecode/isPush.ts +8 -0
  125. package/src/primitives/Bytecode/isTerminator.ts +8 -0
  126. package/src/primitives/Bytecode/isValidJumpDest.ts +12 -0
  127. package/src/primitives/Bytecode/parseInstructions.ts +10 -0
  128. package/src/primitives/Bytecode/prettyPrint.ts +12 -0
  129. package/src/primitives/Bytecode/scan.ts +20 -0
  130. package/src/primitives/Bytecode/size.ts +9 -0
  131. package/src/primitives/Bytecode/stripMetadata.ts +10 -0
  132. package/src/primitives/Bytecode/toAbi.ts +10 -0
  133. package/src/primitives/Bytecode/toHex.ts +10 -0
  134. package/src/primitives/Bytecode/types.ts +23 -0
  135. package/src/primitives/Bytecode/validate.ts +9 -0
  136. package/src/primitives/Ens/Ens.test.ts +71 -0
  137. package/src/primitives/Ens/convert.ts +13 -0
  138. package/src/primitives/Ens/from.ts +32 -0
  139. package/src/primitives/Ens/hash.ts +46 -0
  140. package/src/primitives/Ens/index.ts +86 -4
  141. package/src/primitives/Ens/normalize.ts +45 -0
  142. package/src/primitives/Ens/validation.ts +38 -0
  143. package/src/primitives/EventLog/accessors.ts +32 -0
  144. package/src/primitives/EventLog/clone.ts +17 -0
  145. package/src/primitives/EventLog/create.ts +46 -0
  146. package/src/primitives/EventLog/filtering.ts +48 -0
  147. package/src/primitives/EventLog/index.ts +96 -6
  148. package/src/primitives/EventLog/status.ts +17 -0
  149. package/src/primitives/EventLog/toRpc.ts +49 -0
  150. package/src/primitives/Hardfork/HardforkSchema.ts +3 -3
  151. package/src/primitives/Hardfork/allIds.ts +13 -0
  152. package/src/primitives/Hardfork/allNames.ts +13 -0
  153. package/src/primitives/Hardfork/compare.ts +17 -0
  154. package/src/primitives/Hardfork/comparisons.ts +45 -0
  155. package/src/primitives/Hardfork/equals.ts +17 -0
  156. package/src/primitives/Hardfork/features.ts +61 -0
  157. package/src/primitives/Hardfork/fromString.ts +16 -0
  158. package/src/primitives/Hardfork/index.ts +128 -18
  159. package/src/primitives/Hardfork/isValidName.ts +14 -0
  160. package/src/primitives/Hardfork/minMax.ts +23 -0
  161. package/src/primitives/Hardfork/range.ts +19 -0
  162. package/src/primitives/Hardfork/toString.ts +16 -0
  163. package/src/primitives/Hash/Hash.test.ts +104 -0
  164. package/src/primitives/Hash/from.ts +47 -0
  165. package/src/primitives/Hash/fromBytes.ts +46 -0
  166. package/src/primitives/Hash/fromHex.ts +44 -0
  167. package/src/primitives/Hash/index.ts +45 -8
  168. package/src/primitives/Hash/isHash.ts +31 -0
  169. package/src/primitives/Hash/toHex.ts +29 -0
  170. package/src/primitives/Hex/Hex.test.ts +266 -155
  171. package/src/primitives/Hex/assertSize.ts +41 -0
  172. package/src/primitives/Hex/concat.ts +37 -0
  173. package/src/primitives/Hex/from.ts +38 -0
  174. package/src/primitives/Hex/fromBigInt.ts +40 -0
  175. package/src/primitives/Hex/fromBoolean.ts +29 -0
  176. package/src/primitives/Hex/fromNumber.ts +41 -0
  177. package/src/primitives/Hex/fromString.ts +28 -0
  178. package/src/primitives/Hex/index.ts +68 -37
  179. package/src/primitives/Hex/pad.ts +40 -0
  180. package/src/primitives/Hex/padRight.ts +39 -0
  181. package/src/primitives/Hex/size.ts +29 -0
  182. package/src/primitives/Hex/slice.ts +42 -0
  183. package/src/primitives/Hex/toBigInt.ts +27 -0
  184. package/src/primitives/Hex/toBoolean.ts +38 -0
  185. package/src/primitives/Hex/toNumber.ts +37 -0
  186. package/src/primitives/Hex/toStringHex.ts +39 -0
  187. package/src/primitives/Hex/trim.ts +27 -0
  188. package/src/primitives/Hex/validate.ts +37 -0
  189. package/src/primitives/Hex/xor.ts +39 -0
  190. package/src/primitives/Opcode/OpcodeSchema.ts +1 -1
  191. package/src/primitives/Opcode/disassemble.ts +15 -0
  192. package/src/primitives/Opcode/dupPosition.ts +15 -0
  193. package/src/primitives/Opcode/format.ts +15 -0
  194. package/src/primitives/Opcode/getters.ts +54 -0
  195. package/src/primitives/Opcode/index.ts +301 -11
  196. package/src/primitives/Opcode/info.ts +18 -0
  197. package/src/primitives/Opcode/jumpDests.ts +15 -0
  198. package/src/primitives/Opcode/logTopics.ts +15 -0
  199. package/src/primitives/Opcode/name.ts +15 -0
  200. package/src/primitives/Opcode/parse.ts +15 -0
  201. package/src/primitives/Opcode/predicates.ts +72 -0
  202. package/src/primitives/Opcode/pushBytes.ts +15 -0
  203. package/src/primitives/Opcode/pushOpcode.ts +15 -0
  204. package/src/primitives/Opcode/swapPosition.ts +15 -0
  205. package/src/primitives/Rlp/decodeBatch.ts +46 -0
  206. package/src/primitives/Rlp/decodeObject.ts +46 -0
  207. package/src/primitives/Rlp/decodeValue.ts +51 -0
  208. package/src/primitives/Rlp/encodeBatch.ts +50 -0
  209. package/src/primitives/Rlp/encodeObject.ts +48 -0
  210. package/src/primitives/Rlp/encodeVariadic.ts +49 -0
  211. package/src/primitives/Rlp/equals.ts +22 -0
  212. package/src/primitives/Rlp/from.ts +44 -0
  213. package/src/primitives/Rlp/fromJSON.ts +45 -0
  214. package/src/primitives/Rlp/getEncodedLength.ts +47 -0
  215. package/src/primitives/Rlp/getLength.ts +44 -0
  216. package/src/primitives/Rlp/index.ts +67 -14
  217. package/src/primitives/Rlp/isBytesData.ts +21 -0
  218. package/src/primitives/Rlp/isCanonical.ts +32 -0
  219. package/src/primitives/Rlp/isData.ts +21 -0
  220. package/src/primitives/Rlp/isList.ts +46 -0
  221. package/src/primitives/Rlp/isListData.ts +21 -0
  222. package/src/primitives/Rlp/isString.ts +46 -0
  223. package/src/primitives/Rlp/toJSON.ts +20 -0
  224. package/src/primitives/Rlp/toRaw.ts +31 -0
  225. package/src/primitives/Signature/Signature.test.ts +217 -0
  226. package/src/primitives/Signature/from.ts +38 -0
  227. package/src/primitives/Signature/fromBytes.ts +31 -0
  228. package/src/primitives/Signature/fromCompact.ts +33 -0
  229. package/src/primitives/Signature/fromDER.ts +35 -0
  230. package/src/primitives/Signature/fromEd25519.ts +24 -0
  231. package/src/primitives/Signature/fromHex.ts +29 -0
  232. package/src/primitives/Signature/fromP256.ts +25 -0
  233. package/src/primitives/Signature/fromRpc.ts +38 -0
  234. package/src/primitives/Signature/fromSecp256k1.ts +29 -0
  235. package/src/primitives/Signature/fromTuple.ts +33 -0
  236. package/src/primitives/Signature/getR.ts +24 -0
  237. package/src/primitives/Signature/getS.ts +24 -0
  238. package/src/primitives/Signature/getV.ts +24 -0
  239. package/src/primitives/Signature/index.ts +61 -11
  240. package/src/primitives/Signature/toDER.ts +24 -0
  241. package/src/primitives/Signature/toHex.ts +24 -0
  242. package/src/primitives/Signature/toRpc.ts +35 -0
  243. package/src/primitives/Signature/toTuple.ts +29 -0
  244. package/src/primitives/Signature/verify.ts +31 -0
  245. package/src/primitives/Siwe/create.ts +56 -0
  246. package/src/primitives/Siwe/hash.ts +27 -0
  247. package/src/primitives/Siwe/index.ts +57 -21
  248. package/src/primitives/Siwe/parse.ts +24 -0
  249. package/src/primitives/Siwe/verify.ts +47 -0
  250. package/src/primitives/Transaction/index.ts +467 -2
  251. package/src/primitives/Uint/Uint.test.ts +200 -0
  252. package/src/primitives/Uint/dividedBy.ts +34 -0
  253. package/src/primitives/Uint/from.ts +35 -0
  254. package/src/primitives/Uint/fromAbiEncoded.ts +29 -0
  255. package/src/primitives/Uint/fromBigInt.ts +30 -0
  256. package/src/primitives/Uint/fromBytes.ts +32 -0
  257. package/src/primitives/Uint/fromHex.ts +32 -0
  258. package/src/primitives/Uint/fromNumber.ts +30 -0
  259. package/src/primitives/Uint/index.ts +90 -45
  260. package/src/primitives/Uint/isUint256.ts +25 -0
  261. package/src/primitives/Uint/isValid.ts +25 -0
  262. package/src/primitives/Uint/modulo.ts +34 -0
  263. package/src/primitives/Uint/toHex.ts +31 -0
  264. package/src/primitives/Uint/tryFrom.ts +30 -0
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @module hash
3
+ * @description BloomFilter hash functions (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import * as BloomFilterModule from "@tevm/voltaire/BloomFilter";
7
+
8
+ /**
9
+ * Hash an item for BloomFilter insertion/lookup
10
+ *
11
+ * @param item - Item to hash
12
+ * @param seed - Hash function seed
13
+ * @param m - Filter size in bits
14
+ * @returns Hash value (bit position)
15
+ * @example
16
+ * ```typescript
17
+ * import * as BloomFilter from 'voltaire-effect/primitives/BloomFilter'
18
+ *
19
+ * const pos = BloomFilter.hash(item, 0, 2048)
20
+ * ```
21
+ */
22
+ export const hash = (item: Uint8Array, seed: number, m: number): number =>
23
+ BloomFilterModule.hash(item, seed, m);
24
+
25
+ /**
26
+ * Hash from pre-computed keccak hash
27
+ *
28
+ * @param keccakHash - Pre-computed keccak hash
29
+ * @param seed - Hash function seed
30
+ * @param m - Filter size in bits
31
+ * @returns Hash value (bit position)
32
+ * @example
33
+ * ```typescript
34
+ * import * as BloomFilter from 'voltaire-effect/primitives/BloomFilter'
35
+ *
36
+ * const pos = BloomFilter.hashFromKeccak(keccakResult, 0, 2048)
37
+ * ```
38
+ */
39
+ export const hashFromKeccak = (
40
+ keccakHash: Uint8Array,
41
+ seed: number,
42
+ m: number,
43
+ ): number => BloomFilterModule.hashFromKeccak(keccakHash, seed, m);
@@ -1,25 +1,42 @@
1
1
  /**
2
- * @fileoverview BloomFilter module for Ethereum log bloom filters.
3
2
  * @module BloomFilter
4
- * @since 0.0.1
3
+ * @description Effect Schemas and functions for Ethereum bloom filters.
5
4
  *
6
- * @description
7
5
  * Bloom filters are probabilistic data structures used in Ethereum for efficient
8
6
  * log searching. Each block contains a logs bloom filter (2048 bits, 3 hash functions)
9
7
  * that allows quick checking of whether a block might contain relevant logs.
10
8
  *
11
- * Key properties:
12
- * - False positives possible: "maybe in set" could be wrong
13
- * - False negatives impossible: "not in set" is always correct
14
- * - Space efficient: Compact representation of set membership
15
- * - Fast lookups: O(k) where k is number of hash functions
9
+ * ## Type Declarations
16
10
  *
17
- * This module provides:
18
- * - Creation of bloom filters with configurable parameters
19
- * - Adding items to filters
20
- * - Probabilistic membership testing
21
- * - Serialization to/from hex
22
- * - Effect Schema for validation
11
+ * ```typescript
12
+ * import * as BloomFilter from 'voltaire-effect/primitives/BloomFilter'
13
+ *
14
+ * function checkLogs(filter: BloomFilter.BloomFilterType) {
15
+ * // ...
16
+ * }
17
+ * ```
18
+ *
19
+ * ## Constructors (Effect-wrapped)
20
+ *
21
+ * ```typescript
22
+ * BloomFilter.create(m, k) // Effect<BloomFilterType, InvalidBloomFilterParameterError>
23
+ * BloomFilter.fromHex(hex, m, k) // Effect<BloomFilterType, InvalidBloomFilterLengthError>
24
+ * ```
25
+ *
26
+ * ## Pure Functions
27
+ *
28
+ * ```typescript
29
+ * BloomFilter.add(filter, item) // void (mutates in place)
30
+ * BloomFilter.contains(filter, item) // boolean
31
+ * BloomFilter.combine(...filters) // BloomFilterType
32
+ * BloomFilter.merge(f1, f2) // BloomFilterType
33
+ * BloomFilter.toHex(filter) // string
34
+ * BloomFilter.isEmpty(filter) // boolean
35
+ * BloomFilter.density(filter) // number
36
+ * BloomFilter.expectedFalsePositiveRate(filter, n) // number
37
+ * BloomFilter.hash(item, seed, m) // number
38
+ * BloomFilter.hashFromKeccak(hash, seed, m) // number
39
+ * ```
23
40
  *
24
41
  * @example
25
42
  * ```typescript
@@ -27,38 +44,43 @@
27
44
  * import * as Effect from 'effect/Effect'
28
45
  *
29
46
  * const program = Effect.gen(function* () {
30
- * // Create a filter (Ethereum uses 2048 bits, 3 hash functions)
31
47
  * const filter = yield* BloomFilter.create(2048, 3)
48
+ * BloomFilter.add(filter, transferEventTopic)
32
49
  *
33
- * // Add items
34
- * yield* BloomFilter.add(filter, transferEventTopic)
35
- * yield* BloomFilter.add(filter, contractAddress)
36
- *
37
- * // Check membership
38
50
  * if (BloomFilter.contains(filter, searchTopic)) {
39
51
  * console.log('Topic might be in filter')
40
52
  * }
41
53
  *
42
- * // Check if empty
43
- * console.log(BloomFilter.isEmpty(filter)) // false
44
- *
45
- * // Serialize for storage
46
- * const hex = BloomFilter.toHex(filter)
47
- *
48
- * // Restore later
49
- * const restored = yield* BloomFilter.fromHex(hex, 2048, 3)
50
- *
51
- * return filter
54
+ * return BloomFilter.toHex(filter)
52
55
  * })
53
56
  * ```
54
57
  *
55
- * @see {@link create} for creating new filters
56
- * @see {@link add} for adding items
57
- * @see {@link contains} for membership testing
58
- * @see {@link BloomFilterSchema} for Effect Schema validation
58
+ * @since 0.1.0
59
59
  */
60
60
 
61
+ // Re-export type
62
+ export type { BloomFilterType } from "@tevm/voltaire/BloomFilter";
63
+
64
+ // Re-export errors
61
65
  export {
62
- BloomFilterSchema,
63
- BloomFilterSchema as Schema,
64
- } from "./BloomFilterSchema.js";
66
+ InvalidBloomFilterLengthError,
67
+ InvalidBloomFilterParameterError,
68
+ } from "@tevm/voltaire/BloomFilter";
69
+
70
+ // Schema
71
+ export { BloomFilterSchema, BloomFilterSchema as Schema } from "./BloomFilterSchema.js";
72
+
73
+ // Constructors (Effect-wrapped)
74
+ export { create } from "./create.js";
75
+ export { fromHex } from "./fromHex.js";
76
+
77
+ // Pure functions
78
+ export { add } from "./add.js";
79
+ export { combine } from "./combine.js";
80
+ export { contains } from "./contains.js";
81
+ export { density } from "./density.js";
82
+ export { expectedFalsePositiveRate } from "./expectedFalsePositiveRate.js";
83
+ export { hash, hashFromKeccak } from "./hash.js";
84
+ export { isEmpty } from "./isEmpty.js";
85
+ export { merge } from "./merge.js";
86
+ export { toHex } from "./toHex.js";
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @module isEmpty
3
+ * @description Check if BloomFilter is empty (pure predicate)
4
+ * @since 0.1.0
5
+ */
6
+ import { BloomFilter, type BloomFilterType } from "@tevm/voltaire/BloomFilter";
7
+
8
+ /**
9
+ * Check if a BloomFilter is empty (all bits are zero)
10
+ *
11
+ * @param filter - The bloom filter
12
+ * @returns true if filter is empty
13
+ * @example
14
+ * ```typescript
15
+ * import * as BloomFilter from 'voltaire-effect/primitives/BloomFilter'
16
+ *
17
+ * const filter = await Effect.runPromise(BloomFilter.create(2048, 3))
18
+ * BloomFilter.isEmpty(filter) // true
19
+ * ```
20
+ */
21
+ export const isEmpty = (filter: BloomFilterType): boolean =>
22
+ BloomFilter.isEmpty(filter);
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @module merge
3
+ * @description Merge two BloomFilters into one (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import { BloomFilter, type BloomFilterType } from "@tevm/voltaire/BloomFilter";
7
+
8
+ /**
9
+ * Merge two BloomFilters into a single filter
10
+ *
11
+ * @param filter1 - First filter
12
+ * @param filter2 - Second filter
13
+ * @returns Merged bloom filter
14
+ * @example
15
+ * ```typescript
16
+ * import * as BloomFilter from 'voltaire-effect/primitives/BloomFilter'
17
+ *
18
+ * const merged = BloomFilter.merge(filter1, filter2)
19
+ * ```
20
+ */
21
+ export const merge = (
22
+ filter1: BloomFilterType,
23
+ filter2: BloomFilterType,
24
+ ): BloomFilterType => BloomFilter.merge(filter1, filter2);
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @module toHex
3
+ * @description Convert BloomFilter to hex string (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import { BloomFilter, type BloomFilterType } from "@tevm/voltaire/BloomFilter";
7
+
8
+ /**
9
+ * Convert BloomFilter to hex string
10
+ *
11
+ * @param filter - The bloom filter
12
+ * @returns Hex string representation
13
+ * @example
14
+ * ```typescript
15
+ * import * as BloomFilter from 'voltaire-effect/primitives/BloomFilter'
16
+ *
17
+ * const hex = BloomFilter.toHex(filter)
18
+ * console.log(hex) // '0x00...'
19
+ * ```
20
+ */
21
+ export const toHex = (filter: BloomFilterType): string =>
22
+ BloomFilter.toHex(filter);
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @module analyze
3
+ * @description Bytecode analysis functions (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import {
7
+ analyze as _analyze,
8
+ analyzeBlocks as _analyzeBlocks,
9
+ analyzeGas as _analyzeGas,
10
+ analyzeJumpDestinations as _analyzeJumpDestinations,
11
+ analyzeStack as _analyzeStack,
12
+ } from "@tevm/voltaire/Bytecode";
13
+ import type {
14
+ BrandedBytecode,
15
+ Analysis,
16
+ BasicBlock,
17
+ BlockAnalysisOptions,
18
+ GasAnalysis,
19
+ GasAnalysisOptions,
20
+ StackAnalysis,
21
+ StackAnalysisOptions,
22
+ } from "./types.js";
23
+
24
+ /**
25
+ * Analyze bytecode for jump destinations and instructions
26
+ */
27
+ export const analyze = (code: BrandedBytecode): Analysis => _analyze(code);
28
+
29
+ /**
30
+ * Analyze bytecode into basic blocks
31
+ */
32
+ export const analyzeBlocks = (
33
+ bytecode: BrandedBytecode,
34
+ options?: BlockAnalysisOptions,
35
+ ): BasicBlock[] => _analyzeBlocks(bytecode, options);
36
+
37
+ /**
38
+ * Analyze gas costs in bytecode
39
+ */
40
+ export const analyzeGas = (
41
+ bytecode: BrandedBytecode,
42
+ options?: GasAnalysisOptions,
43
+ ): GasAnalysis => _analyzeGas(bytecode, options);
44
+
45
+ /**
46
+ * Analyze jump destinations in bytecode
47
+ */
48
+ export const analyzeJumpDestinations = (
49
+ code: BrandedBytecode,
50
+ ): ReadonlySet<number> => _analyzeJumpDestinations(code);
51
+
52
+ /**
53
+ * Analyze stack effects in bytecode
54
+ */
55
+ export const analyzeStack = (
56
+ bytecode: BrandedBytecode,
57
+ options?: StackAnalysisOptions,
58
+ ): StackAnalysis => _analyzeStack(bytecode, options);
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @module detectFusions
3
+ * @description Detect fusion patterns in bytecode (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import { detectFusions as _detectFusions } from "@tevm/voltaire/Bytecode";
7
+ import type { BrandedBytecode } from "./types.js";
8
+
9
+ export const detectFusions = (code: BrandedBytecode): unknown =>
10
+ _detectFusions(code);
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @module equals
3
+ * @description Bytecode equality check (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import { equals as _equals } from "@tevm/voltaire/Bytecode";
7
+ import type { BrandedBytecode } from "./types.js";
8
+
9
+ export const equals = (a: BrandedBytecode, b: BrandedBytecode): boolean =>
10
+ _equals(a, b);
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @module extractRuntime
3
+ * @description Extract runtime bytecode from deploy bytecode (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import { extractRuntime as _extractRuntime } from "@tevm/voltaire/Bytecode";
7
+ import type { BrandedBytecode } from "./types.js";
8
+
9
+ export const extractRuntime = (
10
+ code: BrandedBytecode,
11
+ offset: number,
12
+ ): BrandedBytecode => _extractRuntime(code, offset);
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @module format
3
+ * @description Format bytecode instructions (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import {
7
+ formatInstruction as _formatInstruction,
8
+ formatInstructions as _formatInstructions,
9
+ } from "@tevm/voltaire/Bytecode";
10
+ import type { BrandedBytecode, Instruction } from "./types.js";
11
+
12
+ export const formatInstruction = (inst: Instruction): string =>
13
+ _formatInstruction(inst);
14
+
15
+ export const formatInstructions = (code: BrandedBytecode): string[] =>
16
+ _formatInstructions(code);
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @module from
3
+ * @description Create Bytecode from various input types with Effect error handling
4
+ * @since 0.1.0
5
+ */
6
+ import { Effect } from "effect";
7
+ import { from as _from } from "@tevm/voltaire/Bytecode";
8
+ import type { BrandedBytecode } from "./types.js";
9
+
10
+ export const from = (
11
+ value: string | Uint8Array,
12
+ ): Effect.Effect<BrandedBytecode, Error> =>
13
+ Effect.try({
14
+ try: () => _from(value),
15
+ catch: (e) => e as Error,
16
+ });
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @module fromHex
3
+ * @description Create Bytecode from hex string with Effect error handling
4
+ * @since 0.1.0
5
+ */
6
+ import { Effect } from "effect";
7
+ import { fromHex as _fromHex } from "@tevm/voltaire/Bytecode";
8
+ import type { BrandedBytecode } from "./types.js";
9
+
10
+ export const fromHex = (hex: string): Effect.Effect<BrandedBytecode, Error> =>
11
+ Effect.try({
12
+ try: () => _fromHex(hex),
13
+ catch: (e) => e as Error,
14
+ });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @module getBlock
3
+ * @description Get basic block at program counter (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import { getBlock as _getBlock } from "@tevm/voltaire/Bytecode";
7
+ import type { BrandedBytecode, BasicBlock } from "./types.js";
8
+
9
+ export const getBlock = (
10
+ code: BrandedBytecode,
11
+ pc: number,
12
+ ): BasicBlock | undefined => _getBlock(code, pc);
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @module getNextPc
3
+ * @description Get next program counter after instruction (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import { _getNextPc as __getNextPc } from "@tevm/voltaire/Bytecode";
7
+ import type { BrandedBytecode } from "./types.js";
8
+
9
+ export const _getNextPc = (
10
+ code: BrandedBytecode,
11
+ currentPc: number,
12
+ ): number => __getNextPc(code, currentPc) ?? currentPc + 1;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @module getPushSize
3
+ * @description Get PUSH instruction size (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import { getPushSize as _getPushSize } from "@tevm/voltaire/Bytecode";
7
+
8
+ export const getPushSize = (opcode: number): number => _getPushSize(opcode);
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @module hasMetadata
3
+ * @description Check if bytecode has CBOR metadata (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import { hasMetadata as _hasMetadata } from "@tevm/voltaire/Bytecode";
7
+ import type { BrandedBytecode } from "./types.js";
8
+
9
+ export const hasMetadata = (code: BrandedBytecode): boolean =>
10
+ _hasMetadata(code);
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @module hash
3
+ * @description Compute bytecode hash (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import { hash as _hash } from "@tevm/voltaire/Bytecode";
7
+ import type { BrandedBytecode } from "./types.js";
8
+
9
+ export const hash = (code: BrandedBytecode): string => _hash(code);
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @module Bytecode
3
- * @description Effect Schemas for EVM contract bytecode.
3
+ * @description Effect Schemas and functions for EVM contract bytecode.
4
4
  *
5
5
  * Bytecode is the compiled machine code executed by the EVM.
6
6
  *
@@ -9,7 +9,7 @@
9
9
  * ```typescript
10
10
  * import * as Bytecode from 'voltaire-effect/primitives/Bytecode'
11
11
  *
12
- * function deployContract(code: Bytecode.BytecodeType) {
12
+ * function deployContract(code: Bytecode.BrandedBytecode) {
13
13
  * // ...
14
14
  * }
15
15
  * ```
@@ -18,28 +18,118 @@
18
18
  *
19
19
  * | Schema | Input | Output |
20
20
  * |--------|-------|--------|
21
- * | `Bytecode.Hex` | hex string | BytecodeType |
22
- * | `Bytecode.Bytes` | Uint8Array | BytecodeType |
21
+ * | `Bytecode.Hex` | hex string | BrandedBytecode |
22
+ * | `Bytecode.Bytes` | Uint8Array | BrandedBytecode |
23
+ * | `Bytecode.Schema` | string or Uint8Array | BrandedBytecode |
23
24
  *
24
- * ## Usage
25
+ * ## Constructors (Effect-wrapped)
25
26
  *
26
27
  * ```typescript
27
- * import * as Bytecode from 'voltaire-effect/primitives/Bytecode'
28
- * import * as S from 'effect/Schema'
28
+ * Bytecode.from(value) // Effect<BrandedBytecode, Error>
29
+ * Bytecode.fromHex(hex) // Effect<BrandedBytecode, Error>
30
+ * ```
31
+ *
32
+ * ## Pure Functions
33
+ *
34
+ * ```typescript
35
+ * // Analysis
36
+ * Bytecode.analyze(code) // Analysis
37
+ * Bytecode.analyzeBlocks(code, opts) // BasicBlock[]
38
+ * Bytecode.analyzeGas(code, opts) // GasAnalysis
39
+ * Bytecode.analyzeJumpDestinations(code) // ReadonlySet<number>
40
+ * Bytecode.analyzeStack(code, opts) // StackAnalysis
41
+ * Bytecode.detectFusions(code) // fusion patterns
42
+ *
43
+ * // Comparison
44
+ * Bytecode.equals(a, b) // boolean
45
+ *
46
+ * // Extraction
47
+ * Bytecode.extractRuntime(code, offset) // BrandedBytecode
48
+ * Bytecode.stripMetadata(code) // BrandedBytecode
49
+ * Bytecode.toAbi(code) // BrandedAbi
29
50
  *
30
- * // From hex string
31
- * const code = S.decodeSync(Bytecode.Hex)('0x6080604052...')
51
+ * // Formatting
52
+ * Bytecode.formatInstruction(inst) // string
53
+ * Bytecode.formatInstructions(code) // string[]
54
+ * Bytecode.prettyPrint(code, opts) // string
32
55
  *
33
- * // From bytes
34
- * const code2 = S.decodeSync(Bytecode.Bytes)(bytes)
56
+ * // Navigation
57
+ * Bytecode.getBlock(code, pc) // BasicBlock | undefined
58
+ * Bytecode._getNextPc(code, pc) // number
59
+ * Bytecode.scan(code, opts) // Generator
35
60
  *
36
- * // Encode back to hex
37
- * const hex = S.encodeSync(Bytecode.Hex)(code)
61
+ * // Predicates
62
+ * Bytecode.getPushSize(opcode) // number
63
+ * Bytecode.hasMetadata(code) // boolean
64
+ * Bytecode.isPush(opcode) // boolean
65
+ * Bytecode.isTerminator(opcode) // boolean
66
+ * Bytecode.isValidJumpDest(code, offset) // boolean
67
+ * Bytecode.validate(code) // boolean
68
+ *
69
+ * // Conversion
70
+ * Bytecode.hash(code) // string
71
+ * Bytecode.parseInstructions(code) // Instruction[]
72
+ * Bytecode.size(code) // number
73
+ * Bytecode.toHex(code, prefix?) // string
38
74
  * ```
39
75
  *
40
76
  * @since 0.1.0
41
77
  */
42
78
 
79
+ // Re-export types
80
+ export type {
81
+ BrandedBytecode,
82
+ BrandedAbi,
83
+ Analysis,
84
+ BasicBlock,
85
+ BlockAnalysisOptions,
86
+ GasAnalysis,
87
+ GasAnalysisOptions,
88
+ Instruction,
89
+ PrettyPrintOptions,
90
+ ScanOptions,
91
+ StackAnalysis,
92
+ StackAnalysisOptions,
93
+ } from "@tevm/voltaire/Bytecode";
94
+
43
95
  export type { BytecodeType } from "./BytecodeSchema.js";
96
+
97
+ // Schemas
44
98
  export { Bytes } from "./Bytes.js";
45
99
  export { Hex } from "./Hex.js";
100
+ export { Schema } from "./BytecodeSchema.js";
101
+
102
+ // Constructors (Effect-wrapped)
103
+ export { from } from "./from.js";
104
+ export { fromHex } from "./fromHex.js";
105
+
106
+ // Analysis functions (pure)
107
+ export {
108
+ analyze,
109
+ analyzeBlocks,
110
+ analyzeGas,
111
+ analyzeJumpDestinations,
112
+ analyzeStack,
113
+ } from "./analyze.js";
114
+
115
+ // Transformation functions (pure)
116
+ export { detectFusions } from "./detectFusions.js";
117
+ export { equals } from "./equals.js";
118
+ export { extractRuntime } from "./extractRuntime.js";
119
+ export { formatInstruction, formatInstructions } from "./format.js";
120
+ export { getBlock } from "./getBlock.js";
121
+ export { _getNextPc } from "./getNextPc.js";
122
+ export { getPushSize } from "./getPushSize.js";
123
+ export { hash } from "./hash.js";
124
+ export { hasMetadata } from "./hasMetadata.js";
125
+ export { isPush } from "./isPush.js";
126
+ export { isTerminator } from "./isTerminator.js";
127
+ export { isValidJumpDest } from "./isValidJumpDest.js";
128
+ export { parseInstructions } from "./parseInstructions.js";
129
+ export { prettyPrint } from "./prettyPrint.js";
130
+ export { scan } from "./scan.js";
131
+ export { size } from "./size.js";
132
+ export { stripMetadata } from "./stripMetadata.js";
133
+ export { toAbi } from "./toAbi.js";
134
+ export { toHex } from "./toHex.js";
135
+ export { validate } from "./validate.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @module isPush
3
+ * @description Check if opcode is a PUSH instruction (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import { isPush as _isPush } from "@tevm/voltaire/Bytecode";
7
+
8
+ export const isPush = (opcode: number): boolean => _isPush(opcode);
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @module isTerminator
3
+ * @description Check if opcode is a block terminator (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import { isTerminator as _isTerminator } from "@tevm/voltaire/Bytecode";
7
+
8
+ export const isTerminator = (opcode: number): boolean => _isTerminator(opcode);
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @module isValidJumpDest
3
+ * @description Check if offset is a valid jump destination (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import { isValidJumpDest as _isValidJumpDest } from "@tevm/voltaire/Bytecode";
7
+ import type { BrandedBytecode } from "./types.js";
8
+
9
+ export const isValidJumpDest = (
10
+ code: BrandedBytecode,
11
+ offset: number,
12
+ ): boolean => _isValidJumpDest(code, offset);
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @module parseInstructions
3
+ * @description Parse bytecode into instructions (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import { parseInstructions as _parseInstructions } from "@tevm/voltaire/Bytecode";
7
+ import type { BrandedBytecode, Instruction } from "./types.js";
8
+
9
+ export const parseInstructions = (code: BrandedBytecode): Instruction[] =>
10
+ _parseInstructions(code);
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @module prettyPrint
3
+ * @description Pretty print bytecode disassembly (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import { prettyPrint as _prettyPrint } from "@tevm/voltaire/Bytecode";
7
+ import type { BrandedBytecode, PrettyPrintOptions } from "./types.js";
8
+
9
+ export const prettyPrint = (
10
+ bytecode: BrandedBytecode,
11
+ options?: PrettyPrintOptions,
12
+ ): string => _prettyPrint(bytecode, options);
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @module scan
3
+ * @description Iterator over bytecode instructions (pure)
4
+ * @since 0.1.0
5
+ */
6
+ import { scan as _scan } from "@tevm/voltaire/Bytecode";
7
+ import type { BrandedBytecode, ScanOptions } from "./types.js";
8
+
9
+ export const scan = (
10
+ bytecode: BrandedBytecode,
11
+ options?: ScanOptions,
12
+ ): Generator<{
13
+ pc: number;
14
+ opcode: number;
15
+ type: "push" | "regular";
16
+ size: number;
17
+ value?: bigint;
18
+ gas?: number;
19
+ stackEffect?: { pop: number; push: number };
20
+ }> => _scan(bytecode, options);