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,40 @@
1
+ /**
2
+ * @fileoverview Effect wrapper for Hex.fromBigInt.
3
+ * Converts a bigint to Hex string.
4
+ * @module voltaire-effect/primitives/Hex/fromBigInt
5
+ * @since 0.1.0
6
+ */
7
+
8
+ import {
9
+ type HexType,
10
+ Hex as VoltaireHex,
11
+ NegativeNumberError,
12
+ } from "@tevm/voltaire/Hex";
13
+ import { Effect } from "effect";
14
+
15
+ /**
16
+ * Convert bigint to Hex string.
17
+ *
18
+ * @param value - BigInt to convert
19
+ * @param size - Optional byte size for padding
20
+ * @returns Effect with HexType or NegativeNumberError
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import * as Hex from 'voltaire-effect/primitives/Hex'
25
+ * import { Effect } from 'effect'
26
+ *
27
+ * const hex = yield* Hex.fromBigInt(255n) // '0xff'
28
+ * const padded = yield* Hex.fromBigInt(255n, 2) // '0x00ff'
29
+ * ```
30
+ *
31
+ * @since 0.1.0
32
+ */
33
+ export const fromBigInt = (
34
+ value: bigint,
35
+ size?: number,
36
+ ): Effect.Effect<HexType, NegativeNumberError> =>
37
+ Effect.try({
38
+ try: () => VoltaireHex.fromBigInt(value, size),
39
+ catch: (e) => e as NegativeNumberError,
40
+ });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @fileoverview Effect wrapper for Hex.fromBoolean.
3
+ * Converts a boolean to Hex string.
4
+ * @module voltaire-effect/primitives/Hex/fromBoolean
5
+ * @since 0.1.0
6
+ */
7
+
8
+ import { type Sized, Hex as VoltaireHex } from "@tevm/voltaire/Hex";
9
+
10
+ /**
11
+ * Convert boolean to Hex string.
12
+ *
13
+ * This is an infallible operation - booleans always convert cleanly.
14
+ *
15
+ * @param value - Boolean to convert
16
+ * @returns Hex string ('0x01' for true, '0x00' for false)
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import * as Hex from 'voltaire-effect/primitives/Hex'
21
+ *
22
+ * Hex.fromBoolean(true) // '0x01'
23
+ * Hex.fromBoolean(false) // '0x00'
24
+ * ```
25
+ *
26
+ * @since 0.1.0
27
+ */
28
+ export const fromBoolean = (value: boolean): Sized<1> =>
29
+ VoltaireHex.fromBoolean(value);
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @fileoverview Effect wrapper for Hex.fromNumber.
3
+ * Converts a number to Hex string.
4
+ * @module voltaire-effect/primitives/Hex/fromNumber
5
+ * @since 0.1.0
6
+ */
7
+
8
+ import {
9
+ type HexType,
10
+ Hex as VoltaireHex,
11
+ NegativeNumberError,
12
+ NonIntegerError,
13
+ } from "@tevm/voltaire/Hex";
14
+ import { Effect } from "effect";
15
+
16
+ /**
17
+ * Convert number to Hex string.
18
+ *
19
+ * @param value - Number to convert (must be non-negative integer)
20
+ * @param size - Optional byte size for padding
21
+ * @returns Effect with HexType or error
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import * as Hex from 'voltaire-effect/primitives/Hex'
26
+ * import { Effect } from 'effect'
27
+ *
28
+ * const hex = yield* Hex.fromNumber(255) // '0xff'
29
+ * const padded = yield* Hex.fromNumber(255, 2) // '0x00ff'
30
+ * ```
31
+ *
32
+ * @since 0.1.0
33
+ */
34
+ export const fromNumber = (
35
+ value: number,
36
+ size?: number,
37
+ ): Effect.Effect<HexType, NegativeNumberError | NonIntegerError> =>
38
+ Effect.try({
39
+ try: () => VoltaireHex.fromNumber(value, size),
40
+ catch: (e) => e as NegativeNumberError | NonIntegerError,
41
+ });
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @fileoverview Effect wrapper for Hex.fromString.
3
+ * Converts a UTF-8 string to Hex (encodes string bytes).
4
+ * @module voltaire-effect/primitives/Hex/fromString
5
+ * @since 0.1.0
6
+ */
7
+
8
+ import { type HexType, Hex as VoltaireHex } from "@tevm/voltaire/Hex";
9
+
10
+ /**
11
+ * Convert UTF-8 string to Hex (encodes string bytes).
12
+ *
13
+ * This is an infallible operation - any string can be encoded.
14
+ *
15
+ * @param value - UTF-8 string to encode
16
+ * @returns Hex-encoded string bytes
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import * as Hex from 'voltaire-effect/primitives/Hex'
21
+ *
22
+ * Hex.fromString('hello') // '0x68656c6c6f'
23
+ * ```
24
+ *
25
+ * @since 0.1.0
26
+ */
27
+ export const fromString = (value: string): HexType =>
28
+ VoltaireHex.fromString(value);
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @module Hex
3
- * @description Effect Schemas for Ethereum hex strings.
3
+ * @description Effect wrappers for Ethereum hex strings.
4
4
  *
5
5
  * ## Type Declarations
6
6
  *
@@ -19,64 +19,95 @@
19
19
  * | `Hex.String` | string | HexType |
20
20
  * | `Hex.Bytes` | Uint8Array | HexType |
21
21
  *
22
- * ## Usage
23
- *
24
- * ```typescript
25
- * import * as Hex from 'voltaire-effect/primitives/Hex'
26
- * import * as S from 'effect/Schema'
27
- *
28
- * // Decode (parse input)
29
- * const hex = S.decodeSync(Hex.String)('0xdeadbeef')
30
- *
31
- * // Encode (format output)
32
- * const str = S.encodeSync(Hex.String)(hex)
33
- *
34
- * // From bytes
35
- * const hexFromBytes = S.decodeSync(Hex.Bytes)(new Uint8Array([0xde, 0xad]))
36
- * const bytes = S.encodeSync(Hex.Bytes)(hex)
37
- * ```
38
- *
39
22
  * ## API Design
40
23
  *
41
- * This module follows Effect best practices for function signatures:
24
+ * This module follows Effect best practices:
42
25
  *
43
26
  * ### Direct Return (Infallible Operations)
44
- * Operations that cannot fail return their value directly:
45
27
  * - `clone(hex)` - HexType
46
28
  * - `equals(a, b)` - boolean
47
29
  * - `isHex(str)` - boolean
48
30
  * - `isSized(hex, size)` - boolean
49
31
  * - `zero(size)` - HexType
50
32
  * - `random(size)` - HexType
33
+ * - `fromBoolean(bool)` - Sized<1>
34
+ * - `fromString(str)` - HexType
35
+ * - `trim(hex)` - HexType
36
+ * - `size(hex)` - number
37
+ * - `toBigInt(hex)` - bigint
51
38
  *
52
39
  * ### Effect Return (Fallible Operations)
53
- * Operations that can fail return Effect with typed error:
54
- * - Schema decode/encode operations via `S.decodeSync(Hex.String)(...)` etc.
55
- *
56
- * @example
57
- * ```typescript
58
- * // Infallible - use directly
59
- * const cloned = Hex.clone(hex);
60
- * const isValid = Hex.isHex('0x1234');
61
- * const zeros = Hex.zero(32);
62
- * const rand = Hex.random(16);
63
- *
64
- * // Fallible - use Schema
65
- * const parsed = S.decodeSync(Hex.String)('0x...');
66
- * ```
40
+ * - `from(value)` - Effect<HexType, InvalidFormatError>
41
+ * - `fromBigInt(value, size?)` - Effect<HexType, NegativeNumberError>
42
+ * - `fromNumber(value, size?)` - Effect<HexType, NegativeNumberError | NonIntegerError>
43
+ * - `toBoolean(hex)` - Effect<boolean, InvalidBooleanHexError>
44
+ * - `toNumber(hex)` - Effect<number, UnsafeIntegerError>
45
+ * - `toStringHex(hex)` - Effect<string, InvalidFormatError>
46
+ * - `concat(...hexes)` - Effect<HexType, InvalidFormatError>
47
+ * - `pad(hex, size)` - Effect<HexType, SizeExceededError | InvalidSizeError>
48
+ * - `padRight(hex, size)` - Effect<HexType, InvalidSizeError>
49
+ * - `slice(hex, start, end?)` - Effect<HexType, InvalidSizeError>
50
+ * - `validate(value)` - Effect<HexType, InvalidFormatError>
51
+ * - `xor(hex, other)` - Effect<HexType, InvalidLengthError>
52
+ * - `assertSize(hex, size)` - Effect<Sized<T>, InvalidLengthError>
67
53
  *
68
54
  * @since 0.1.0
69
55
  */
70
56
 
71
- export type { Hex as HexBrand, HexType } from "@tevm/voltaire/Hex";
57
+ export type { Hex as HexBrand, HexType, Sized } from "@tevm/voltaire/Hex";
58
+
59
+ // Re-export error types for typed error handling
60
+ export {
61
+ InvalidBooleanHexError,
62
+ InvalidCharacterError,
63
+ InvalidFormatError,
64
+ InvalidHexCharacterError,
65
+ InvalidHexFormatError,
66
+ InvalidHexLengthError,
67
+ InvalidLengthError,
68
+ InvalidSizeError,
69
+ NegativeNumberError,
70
+ NonIntegerError,
71
+ OddLengthError,
72
+ OddLengthHexError,
73
+ SizeExceededError,
74
+ UnsafeIntegerError,
75
+ } from "@tevm/voltaire/Hex";
76
+
77
+ // Re-export direct conversion functions from voltaire for convenience
78
+ export { fromBytes, toBytes } from "@tevm/voltaire/Hex";
79
+
80
+ // Re-export the Hex namespace constructor
81
+ export { Hex } from "@tevm/voltaire/Hex";
72
82
 
73
83
  // Schemas
74
84
  export { Bytes } from "./Bytes.js";
75
- // Pure functions
85
+ export { String } from "./String.js";
86
+
87
+ // Pure functions (infallible)
76
88
  export { clone } from "./clone.js";
77
89
  export { equals } from "./equals.js";
90
+ export { fromBoolean } from "./fromBoolean.js";
91
+ export { fromString } from "./fromString.js";
78
92
  export { isHex } from "./isHex.js";
79
93
  export { isSized } from "./isSized.js";
80
94
  export { random } from "./random.js";
81
- export { String } from "./String.js";
95
+ export { size } from "./size.js";
96
+ export { toBigInt } from "./toBigInt.js";
97
+ export { trim } from "./trim.js";
82
98
  export { zero } from "./zero.js";
99
+
100
+ // Effect-returning functions (fallible)
101
+ export { assertSize } from "./assertSize.js";
102
+ export { concat } from "./concat.js";
103
+ export { from } from "./from.js";
104
+ export { fromBigInt } from "./fromBigInt.js";
105
+ export { fromNumber } from "./fromNumber.js";
106
+ export { pad } from "./pad.js";
107
+ export { padRight } from "./padRight.js";
108
+ export { slice } from "./slice.js";
109
+ export { toBoolean } from "./toBoolean.js";
110
+ export { toNumber } from "./toNumber.js";
111
+ export { toStringHex } from "./toStringHex.js";
112
+ export { validate } from "./validate.js";
113
+ export { xor } from "./xor.js";
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @fileoverview Effect wrapper for Hex.pad.
3
+ * Left-pads Hex to target size with zeros.
4
+ * @module voltaire-effect/primitives/Hex/pad
5
+ * @since 0.1.0
6
+ */
7
+
8
+ import {
9
+ type HexType,
10
+ Hex as VoltaireHex,
11
+ SizeExceededError,
12
+ InvalidSizeError,
13
+ } from "@tevm/voltaire/Hex";
14
+ import { Effect } from "effect";
15
+
16
+ /**
17
+ * Left-pad Hex to target size with zeros.
18
+ *
19
+ * @param hex - Hex string to pad
20
+ * @param targetSize - Target size in bytes
21
+ * @returns Effect with padded HexType or SizeExceededError/InvalidSizeError
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import * as Hex from 'voltaire-effect/primitives/Hex'
26
+ * import { Effect } from 'effect'
27
+ *
28
+ * const padded = yield* Hex.pad('0x12', 4) // '0x00000012'
29
+ * ```
30
+ *
31
+ * @since 0.1.0
32
+ */
33
+ export const pad = (
34
+ hex: HexType,
35
+ targetSize: number,
36
+ ): Effect.Effect<HexType, SizeExceededError | InvalidSizeError> =>
37
+ Effect.try({
38
+ try: () => VoltaireHex.pad(hex, targetSize) as HexType,
39
+ catch: (e) => e as SizeExceededError | InvalidSizeError,
40
+ });
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @fileoverview Effect wrapper for Hex.padRight.
3
+ * Right-pads Hex to target size with zeros.
4
+ * @module voltaire-effect/primitives/Hex/padRight
5
+ * @since 0.1.0
6
+ */
7
+
8
+ import {
9
+ type HexType,
10
+ Hex as VoltaireHex,
11
+ InvalidSizeError,
12
+ } from "@tevm/voltaire/Hex";
13
+ import { Effect } from "effect";
14
+
15
+ /**
16
+ * Right-pad Hex to target size with zeros.
17
+ *
18
+ * @param hex - Hex string to pad
19
+ * @param targetSize - Target size in bytes
20
+ * @returns Effect with padded HexType or InvalidSizeError
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import * as Hex from 'voltaire-effect/primitives/Hex'
25
+ * import { Effect } from 'effect'
26
+ *
27
+ * const padded = yield* Hex.padRight('0x12', 4) // '0x12000000'
28
+ * ```
29
+ *
30
+ * @since 0.1.0
31
+ */
32
+ export const padRight = (
33
+ hex: HexType,
34
+ targetSize: number,
35
+ ): Effect.Effect<HexType, InvalidSizeError> =>
36
+ Effect.try({
37
+ try: () => VoltaireHex.padRight(hex, targetSize) as HexType,
38
+ catch: (e) => e as InvalidSizeError,
39
+ });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @fileoverview Hex size function.
3
+ * Returns the byte size of a Hex string.
4
+ * @module voltaire-effect/primitives/Hex/size
5
+ * @since 0.1.0
6
+ */
7
+
8
+ import { type HexType, Hex as VoltaireHex } from "@tevm/voltaire/Hex";
9
+
10
+ /**
11
+ * Get the byte size of a Hex string.
12
+ *
13
+ * This is an infallible operation.
14
+ *
15
+ * @param hex - Hex string
16
+ * @returns Size in bytes
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import * as Hex from 'voltaire-effect/primitives/Hex'
21
+ *
22
+ * Hex.size('0x1234') // 2
23
+ * Hex.size('0xdeadbeef') // 4
24
+ * Hex.size('0x') // 0
25
+ * ```
26
+ *
27
+ * @since 0.1.0
28
+ */
29
+ export const size = (hex: HexType): number => VoltaireHex.size(hex);
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @fileoverview Effect wrapper for Hex.slice.
3
+ * Extracts a portion of Hex by byte indices.
4
+ * @module voltaire-effect/primitives/Hex/slice
5
+ * @since 0.1.0
6
+ */
7
+
8
+ import {
9
+ type HexType,
10
+ Hex as VoltaireHex,
11
+ InvalidSizeError,
12
+ } from "@tevm/voltaire/Hex";
13
+ import { Effect } from "effect";
14
+
15
+ /**
16
+ * Slice Hex string by byte indices.
17
+ *
18
+ * @param hex - Hex string to slice
19
+ * @param start - Start byte index
20
+ * @param end - End byte index (optional)
21
+ * @returns Effect with sliced HexType or InvalidSizeError
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import * as Hex from 'voltaire-effect/primitives/Hex'
26
+ * import { Effect } from 'effect'
27
+ *
28
+ * const sliced = yield* Hex.slice('0x123456', 1) // '0x3456'
29
+ * const range = yield* Hex.slice('0x123456', 0, 1) // '0x12'
30
+ * ```
31
+ *
32
+ * @since 0.1.0
33
+ */
34
+ export const slice = (
35
+ hex: HexType,
36
+ start: number,
37
+ end?: number,
38
+ ): Effect.Effect<HexType, InvalidSizeError> =>
39
+ Effect.try({
40
+ try: () => VoltaireHex.slice(hex, start, end),
41
+ catch: (e) => e as InvalidSizeError,
42
+ });
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @fileoverview Effect wrapper for Hex.toBigInt.
3
+ * Converts Hex to bigint.
4
+ * @module voltaire-effect/primitives/Hex/toBigInt
5
+ * @since 0.1.0
6
+ */
7
+
8
+ import { type HexType, Hex as VoltaireHex } from "@tevm/voltaire/Hex";
9
+
10
+ /**
11
+ * Convert Hex to bigint.
12
+ *
13
+ * This is an infallible operation - hex always converts to bigint.
14
+ *
15
+ * @param hex - Hex string to convert
16
+ * @returns bigint value
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import * as Hex from 'voltaire-effect/primitives/Hex'
21
+ *
22
+ * Hex.toBigInt('0xff' as HexType) // 255n
23
+ * ```
24
+ *
25
+ * @since 0.1.0
26
+ */
27
+ export const toBigInt = (hex: HexType): bigint => VoltaireHex.toBigInt(hex);
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @fileoverview Effect wrapper for Hex.toBoolean.
3
+ * Converts Hex to boolean.
4
+ * @module voltaire-effect/primitives/Hex/toBoolean
5
+ * @since 0.1.0
6
+ */
7
+
8
+ import {
9
+ type HexType,
10
+ Hex as VoltaireHex,
11
+ InvalidBooleanHexError,
12
+ } from "@tevm/voltaire/Hex";
13
+ import { Effect } from "effect";
14
+
15
+ /**
16
+ * Convert Hex to boolean.
17
+ *
18
+ * @param hex - Hex string ('0x01'/'0x1' for true, '0x00'/'0x0' for false)
19
+ * @returns Effect with boolean or InvalidBooleanHexError
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import * as Hex from 'voltaire-effect/primitives/Hex'
24
+ * import { Effect } from 'effect'
25
+ *
26
+ * const t = yield* Hex.toBoolean('0x01') // true
27
+ * const f = yield* Hex.toBoolean('0x00') // false
28
+ * ```
29
+ *
30
+ * @since 0.1.0
31
+ */
32
+ export const toBoolean = (
33
+ hex: HexType,
34
+ ): Effect.Effect<boolean, InvalidBooleanHexError> =>
35
+ Effect.try({
36
+ try: () => VoltaireHex.toBoolean(hex),
37
+ catch: (e) => e as InvalidBooleanHexError,
38
+ });
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @fileoverview Effect wrapper for Hex.toNumber.
3
+ * Converts Hex to number.
4
+ * @module voltaire-effect/primitives/Hex/toNumber
5
+ * @since 0.1.0
6
+ */
7
+
8
+ import {
9
+ type HexType,
10
+ Hex as VoltaireHex,
11
+ UnsafeIntegerError,
12
+ } from "@tevm/voltaire/Hex";
13
+ import { Effect } from "effect";
14
+
15
+ /**
16
+ * Convert Hex to number.
17
+ *
18
+ * @param hex - Hex string to convert
19
+ * @returns Effect with number or UnsafeIntegerError
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import * as Hex from 'voltaire-effect/primitives/Hex'
24
+ * import { Effect } from 'effect'
25
+ *
26
+ * const value = yield* Hex.toNumber('0xff') // 255
27
+ * ```
28
+ *
29
+ * @since 0.1.0
30
+ */
31
+ export const toNumber = (
32
+ hex: HexType,
33
+ ): Effect.Effect<number, UnsafeIntegerError> =>
34
+ Effect.try({
35
+ try: () => VoltaireHex.toNumber(hex),
36
+ catch: (e) => e as UnsafeIntegerError,
37
+ });
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @fileoverview Effect wrapper for Hex.toString.
3
+ * Decodes Hex to UTF-8 string.
4
+ * @module voltaire-effect/primitives/Hex/toStringHex
5
+ * @since 0.1.0
6
+ */
7
+
8
+ import {
9
+ type HexType,
10
+ Hex as VoltaireHex,
11
+ InvalidFormatError,
12
+ } from "@tevm/voltaire/Hex";
13
+ import { Effect } from "effect";
14
+
15
+ /**
16
+ * Decode Hex to UTF-8 string.
17
+ *
18
+ * Note: Named `toStringHex` to avoid conflict with native `toString`.
19
+ *
20
+ * @param hex - Hex string to decode
21
+ * @returns Effect with decoded string or InvalidFormatError
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import * as Hex from 'voltaire-effect/primitives/Hex'
26
+ * import { Effect } from 'effect'
27
+ *
28
+ * const str = yield* Hex.toStringHex('0x68656c6c6f') // 'hello'
29
+ * ```
30
+ *
31
+ * @since 0.1.0
32
+ */
33
+ export const toStringHex = (
34
+ hex: HexType,
35
+ ): Effect.Effect<string, InvalidFormatError> =>
36
+ Effect.try({
37
+ try: () => VoltaireHex.toString(hex),
38
+ catch: (e) => e as InvalidFormatError,
39
+ });
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @fileoverview Effect wrapper for Hex.trim.
3
+ * Trims leading zeros from Hex.
4
+ * @module voltaire-effect/primitives/Hex/trim
5
+ * @since 0.1.0
6
+ */
7
+
8
+ import { type HexType, Hex as VoltaireHex } from "@tevm/voltaire/Hex";
9
+
10
+ /**
11
+ * Trim leading zeros from Hex.
12
+ *
13
+ * This is an infallible operation.
14
+ *
15
+ * @param hex - Hex string to trim
16
+ * @returns Trimmed HexType
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import * as Hex from 'voltaire-effect/primitives/Hex'
21
+ *
22
+ * Hex.trim('0x00001234') // '0x1234'
23
+ * ```
24
+ *
25
+ * @since 0.1.0
26
+ */
27
+ export const trim = (hex: HexType): HexType => VoltaireHex.trim(hex);
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @fileoverview Effect wrapper for Hex.validate.
3
+ * Validates and returns Hex string.
4
+ * @module voltaire-effect/primitives/Hex/validate
5
+ * @since 0.1.0
6
+ */
7
+
8
+ import {
9
+ type HexType,
10
+ Hex as VoltaireHex,
11
+ InvalidFormatError,
12
+ } from "@tevm/voltaire/Hex";
13
+ import { Effect } from "effect";
14
+
15
+ /**
16
+ * Validate and return Hex string.
17
+ *
18
+ * @param value - String to validate
19
+ * @returns Effect with validated HexType or InvalidFormatError
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import * as Hex from 'voltaire-effect/primitives/Hex'
24
+ * import { Effect } from 'effect'
25
+ *
26
+ * const valid = yield* Hex.validate('0x1234')
27
+ * ```
28
+ *
29
+ * @since 0.1.0
30
+ */
31
+ export const validate = (
32
+ value: string,
33
+ ): Effect.Effect<HexType, InvalidFormatError> =>
34
+ Effect.try({
35
+ try: () => VoltaireHex.validate(value),
36
+ catch: (e) => e as InvalidFormatError,
37
+ });
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @fileoverview Effect wrapper for Hex.xor.
3
+ * XORs two Hex strings.
4
+ * @module voltaire-effect/primitives/Hex/xor
5
+ * @since 0.1.0
6
+ */
7
+
8
+ import {
9
+ type HexType,
10
+ Hex as VoltaireHex,
11
+ InvalidLengthError,
12
+ } from "@tevm/voltaire/Hex";
13
+ import { Effect } from "effect";
14
+
15
+ /**
16
+ * XOR two Hex strings.
17
+ *
18
+ * @param hex - First Hex string
19
+ * @param other - Second Hex string
20
+ * @returns Effect with XOR result or InvalidLengthError if lengths don't match
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import * as Hex from 'voltaire-effect/primitives/Hex'
25
+ * import { Effect } from 'effect'
26
+ *
27
+ * const result = yield* Hex.xor('0xff00', '0x00ff') // '0xffff'
28
+ * ```
29
+ *
30
+ * @since 0.1.0
31
+ */
32
+ export const xor = (
33
+ hex: HexType,
34
+ other: HexType,
35
+ ): Effect.Effect<HexType, InvalidLengthError> =>
36
+ Effect.try({
37
+ try: () => VoltaireHex.xor(hex, other),
38
+ catch: (e) => e as InvalidLengthError,
39
+ });