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.
- package/dist/KZGService-B7PJerOb.d.ts +146 -0
- package/dist/{X25519Test-DGsk1V9o.d.ts → X25519Test-C8Cicdd_.d.ts} +2 -139
- package/dist/crypto/index.d.ts +3 -2
- package/dist/{index-IgkEHjBe.d.ts → index-DsFjN_a3.d.ts} +17633 -11961
- package/dist/index.d.ts +3104 -938
- package/dist/index.js +4467 -2446
- package/dist/native/index.d.ts +14 -5
- package/dist/native/index.js +4489 -2468
- package/dist/primitives/index.d.ts +12 -4
- package/dist/primitives/index.js +3980 -2411
- package/package.json +2 -2
- package/src/crypto/Keccak256/index.ts +1 -0
- package/src/index.ts +2 -2
- package/src/primitives/Abi/decode.test.ts +38 -0
- package/src/primitives/Abi/decode.ts +67 -0
- package/src/primitives/Abi/decodeData.test.ts +37 -0
- package/src/primitives/Abi/decodeData.ts +77 -0
- package/src/primitives/Abi/decodeLog.test.ts +32 -0
- package/src/primitives/Abi/decodeLog.ts +81 -0
- package/src/primitives/Abi/decodeWrappedError.test.ts +41 -0
- package/src/primitives/Abi/decodeWrappedError.ts +68 -0
- package/src/primitives/Abi/encode.test.ts +43 -0
- package/src/primitives/Abi/encode.ts +67 -0
- package/src/primitives/Abi/encodePacked.test.ts +35 -0
- package/src/primitives/Abi/encodePacked.ts +62 -0
- package/src/primitives/Abi/encodeWrappedError.test.ts +21 -0
- package/src/primitives/Abi/encodeWrappedError.ts +64 -0
- package/src/primitives/Abi/findSelectorCollisions.test.ts +50 -0
- package/src/primitives/Abi/findSelectorCollisions.ts +83 -0
- package/src/primitives/Abi/index.ts +33 -7
- package/src/primitives/Abi/parseLogs.test.ts +37 -0
- package/src/primitives/Abi/parseLogs.ts +62 -0
- package/src/primitives/AccessList/AccessList.test.ts +229 -0
- package/src/primitives/AccessList/AccessListTypeSchema.ts +16 -0
- package/src/primitives/AccessList/addressCount.ts +21 -0
- package/src/primitives/AccessList/assertValid.ts +37 -0
- package/src/primitives/AccessList/create.ts +19 -0
- package/src/primitives/AccessList/deduplicate.ts +23 -0
- package/src/primitives/AccessList/from.ts +39 -0
- package/src/primitives/AccessList/fromBytes.ts +36 -0
- package/src/primitives/AccessList/gasCost.ts +22 -0
- package/src/primitives/AccessList/gasSavings.ts +26 -0
- package/src/primitives/AccessList/hasSavings.ts +23 -0
- package/src/primitives/AccessList/includesAddress.ts +25 -0
- package/src/primitives/AccessList/includesStorageKey.ts +28 -0
- package/src/primitives/AccessList/index.ts +99 -19
- package/src/primitives/AccessList/is.ts +23 -0
- package/src/primitives/AccessList/isEmpty.ts +23 -0
- package/src/primitives/AccessList/isItem.ts +22 -0
- package/src/primitives/AccessList/keysFor.ts +29 -0
- package/src/primitives/AccessList/merge.ts +24 -0
- package/src/primitives/AccessList/storageKeyCount.ts +21 -0
- package/src/primitives/AccessList/toBytes.ts +23 -0
- package/src/primitives/AccessList/withAddress.ts +27 -0
- package/src/primitives/AccessList/withStorageKey.ts +30 -0
- package/src/primitives/Address/Address.test.ts +146 -0
- package/src/primitives/Address/assert.ts +51 -0
- package/src/primitives/Address/calculateCreate2Address.ts +33 -0
- package/src/primitives/Address/calculateCreateAddress.ts +30 -0
- package/src/primitives/Address/deduplicateAddresses.ts +20 -0
- package/src/primitives/Address/from.ts +41 -0
- package/src/primitives/Address/fromAbiEncoded.ts +35 -0
- package/src/primitives/Address/fromBase64.ts +25 -0
- package/src/primitives/Address/fromBytes.ts +25 -0
- package/src/primitives/Address/fromHex.ts +31 -0
- package/src/primitives/Address/fromNumber.ts +25 -0
- package/src/primitives/Address/fromPrivateKey.ts +25 -0
- package/src/primitives/Address/fromPublicKey.ts +56 -0
- package/src/primitives/Address/index.ts +99 -35
- package/src/primitives/Address/is.ts +20 -0
- package/src/primitives/Address/isAddress.ts +22 -0
- package/src/primitives/Address/sortAddresses.ts +19 -0
- package/src/primitives/Address/toChecksummed.ts +32 -0
- package/src/primitives/Address/toHex.ts +18 -0
- package/src/primitives/Address/zero.ts +18 -0
- package/src/primitives/Base64/Base64.test.ts +75 -0
- package/src/primitives/Base64/convert.ts +37 -0
- package/src/primitives/Base64/decode.ts +59 -0
- package/src/primitives/Base64/encode.ts +42 -0
- package/src/primitives/Base64/from.ts +39 -0
- package/src/primitives/Base64/index.ts +81 -1
- package/src/primitives/Base64/size.ts +16 -0
- package/src/primitives/Base64/validation.ts +16 -0
- package/src/primitives/Blob/Blob.test.ts +292 -0
- package/src/primitives/Blob/calculateGas.ts +30 -0
- package/src/primitives/Blob/estimateBlobCount.ts +30 -0
- package/src/primitives/Blob/from.ts +38 -0
- package/src/primitives/Blob/fromData.ts +36 -0
- package/src/primitives/Blob/index.ts +99 -12
- package/src/primitives/Blob/isValidVersion.ts +27 -0
- package/src/primitives/Blob/joinData.ts +43 -0
- package/src/primitives/Blob/splitData.ts +36 -0
- package/src/primitives/Blob/toCommitment.ts +43 -0
- package/src/primitives/Blob/toProof.ts +50 -0
- package/src/primitives/Blob/toVersionedHash.ts +35 -0
- package/src/primitives/Blob/verify.ts +49 -0
- package/src/primitives/Blob/verifyBatch.ts +119 -0
- package/src/primitives/BloomFilter/BloomFilter.test.ts +138 -0
- package/src/primitives/BloomFilter/add.ts +23 -0
- package/src/primitives/BloomFilter/combine.ts +21 -0
- package/src/primitives/BloomFilter/contains.ts +26 -0
- package/src/primitives/BloomFilter/create.ts +35 -0
- package/src/primitives/BloomFilter/density.ts +22 -0
- package/src/primitives/BloomFilter/expectedFalsePositiveRate.ts +25 -0
- package/src/primitives/BloomFilter/fromHex.ts +37 -0
- package/src/primitives/BloomFilter/hash.ts +43 -0
- package/src/primitives/BloomFilter/index.ts +59 -37
- package/src/primitives/BloomFilter/isEmpty.ts +22 -0
- package/src/primitives/BloomFilter/merge.ts +24 -0
- package/src/primitives/BloomFilter/toHex.ts +22 -0
- package/src/primitives/Bytecode/analyze.ts +58 -0
- package/src/primitives/Bytecode/detectFusions.ts +10 -0
- package/src/primitives/Bytecode/equals.ts +10 -0
- package/src/primitives/Bytecode/extractRuntime.ts +12 -0
- package/src/primitives/Bytecode/format.ts +16 -0
- package/src/primitives/Bytecode/from.ts +16 -0
- package/src/primitives/Bytecode/fromHex.ts +14 -0
- package/src/primitives/Bytecode/getBlock.ts +12 -0
- package/src/primitives/Bytecode/getNextPc.ts +12 -0
- package/src/primitives/Bytecode/getPushSize.ts +8 -0
- package/src/primitives/Bytecode/hasMetadata.ts +10 -0
- package/src/primitives/Bytecode/hash.ts +9 -0
- package/src/primitives/Bytecode/index.ts +103 -13
- package/src/primitives/Bytecode/isPush.ts +8 -0
- package/src/primitives/Bytecode/isTerminator.ts +8 -0
- package/src/primitives/Bytecode/isValidJumpDest.ts +12 -0
- package/src/primitives/Bytecode/parseInstructions.ts +10 -0
- package/src/primitives/Bytecode/prettyPrint.ts +12 -0
- package/src/primitives/Bytecode/scan.ts +20 -0
- package/src/primitives/Bytecode/size.ts +9 -0
- package/src/primitives/Bytecode/stripMetadata.ts +10 -0
- package/src/primitives/Bytecode/toAbi.ts +10 -0
- package/src/primitives/Bytecode/toHex.ts +10 -0
- package/src/primitives/Bytecode/types.ts +23 -0
- package/src/primitives/Bytecode/validate.ts +9 -0
- package/src/primitives/Ens/Ens.test.ts +71 -0
- package/src/primitives/Ens/convert.ts +13 -0
- package/src/primitives/Ens/from.ts +32 -0
- package/src/primitives/Ens/hash.ts +46 -0
- package/src/primitives/Ens/index.ts +86 -4
- package/src/primitives/Ens/normalize.ts +45 -0
- package/src/primitives/Ens/validation.ts +38 -0
- package/src/primitives/EventLog/accessors.ts +32 -0
- package/src/primitives/EventLog/clone.ts +17 -0
- package/src/primitives/EventLog/create.ts +46 -0
- package/src/primitives/EventLog/filtering.ts +48 -0
- package/src/primitives/EventLog/index.ts +96 -6
- package/src/primitives/EventLog/status.ts +17 -0
- package/src/primitives/EventLog/toRpc.ts +49 -0
- package/src/primitives/Hardfork/HardforkSchema.ts +3 -3
- package/src/primitives/Hardfork/allIds.ts +13 -0
- package/src/primitives/Hardfork/allNames.ts +13 -0
- package/src/primitives/Hardfork/compare.ts +17 -0
- package/src/primitives/Hardfork/comparisons.ts +45 -0
- package/src/primitives/Hardfork/equals.ts +17 -0
- package/src/primitives/Hardfork/features.ts +61 -0
- package/src/primitives/Hardfork/fromString.ts +16 -0
- package/src/primitives/Hardfork/index.ts +128 -18
- package/src/primitives/Hardfork/isValidName.ts +14 -0
- package/src/primitives/Hardfork/minMax.ts +23 -0
- package/src/primitives/Hardfork/range.ts +19 -0
- package/src/primitives/Hardfork/toString.ts +16 -0
- package/src/primitives/Hash/Hash.test.ts +104 -0
- package/src/primitives/Hash/from.ts +47 -0
- package/src/primitives/Hash/fromBytes.ts +46 -0
- package/src/primitives/Hash/fromHex.ts +44 -0
- package/src/primitives/Hash/index.ts +45 -8
- package/src/primitives/Hash/isHash.ts +31 -0
- package/src/primitives/Hash/toHex.ts +29 -0
- package/src/primitives/Hex/Hex.test.ts +266 -155
- package/src/primitives/Hex/assertSize.ts +41 -0
- package/src/primitives/Hex/concat.ts +37 -0
- package/src/primitives/Hex/from.ts +38 -0
- package/src/primitives/Hex/fromBigInt.ts +40 -0
- package/src/primitives/Hex/fromBoolean.ts +29 -0
- package/src/primitives/Hex/fromNumber.ts +41 -0
- package/src/primitives/Hex/fromString.ts +28 -0
- package/src/primitives/Hex/index.ts +68 -37
- package/src/primitives/Hex/pad.ts +40 -0
- package/src/primitives/Hex/padRight.ts +39 -0
- package/src/primitives/Hex/size.ts +29 -0
- package/src/primitives/Hex/slice.ts +42 -0
- package/src/primitives/Hex/toBigInt.ts +27 -0
- package/src/primitives/Hex/toBoolean.ts +38 -0
- package/src/primitives/Hex/toNumber.ts +37 -0
- package/src/primitives/Hex/toStringHex.ts +39 -0
- package/src/primitives/Hex/trim.ts +27 -0
- package/src/primitives/Hex/validate.ts +37 -0
- package/src/primitives/Hex/xor.ts +39 -0
- package/src/primitives/Opcode/OpcodeSchema.ts +1 -1
- package/src/primitives/Opcode/disassemble.ts +15 -0
- package/src/primitives/Opcode/dupPosition.ts +15 -0
- package/src/primitives/Opcode/format.ts +15 -0
- package/src/primitives/Opcode/getters.ts +54 -0
- package/src/primitives/Opcode/index.ts +301 -11
- package/src/primitives/Opcode/info.ts +18 -0
- package/src/primitives/Opcode/jumpDests.ts +15 -0
- package/src/primitives/Opcode/logTopics.ts +15 -0
- package/src/primitives/Opcode/name.ts +15 -0
- package/src/primitives/Opcode/parse.ts +15 -0
- package/src/primitives/Opcode/predicates.ts +72 -0
- package/src/primitives/Opcode/pushBytes.ts +15 -0
- package/src/primitives/Opcode/pushOpcode.ts +15 -0
- package/src/primitives/Opcode/swapPosition.ts +15 -0
- package/src/primitives/Rlp/decodeBatch.ts +46 -0
- package/src/primitives/Rlp/decodeObject.ts +46 -0
- package/src/primitives/Rlp/decodeValue.ts +51 -0
- package/src/primitives/Rlp/encodeBatch.ts +50 -0
- package/src/primitives/Rlp/encodeObject.ts +48 -0
- package/src/primitives/Rlp/encodeVariadic.ts +49 -0
- package/src/primitives/Rlp/equals.ts +22 -0
- package/src/primitives/Rlp/from.ts +44 -0
- package/src/primitives/Rlp/fromJSON.ts +45 -0
- package/src/primitives/Rlp/getEncodedLength.ts +47 -0
- package/src/primitives/Rlp/getLength.ts +44 -0
- package/src/primitives/Rlp/index.ts +67 -14
- package/src/primitives/Rlp/isBytesData.ts +21 -0
- package/src/primitives/Rlp/isCanonical.ts +32 -0
- package/src/primitives/Rlp/isData.ts +21 -0
- package/src/primitives/Rlp/isList.ts +46 -0
- package/src/primitives/Rlp/isListData.ts +21 -0
- package/src/primitives/Rlp/isString.ts +46 -0
- package/src/primitives/Rlp/toJSON.ts +20 -0
- package/src/primitives/Rlp/toRaw.ts +31 -0
- package/src/primitives/Signature/Signature.test.ts +217 -0
- package/src/primitives/Signature/from.ts +38 -0
- package/src/primitives/Signature/fromBytes.ts +31 -0
- package/src/primitives/Signature/fromCompact.ts +33 -0
- package/src/primitives/Signature/fromDER.ts +35 -0
- package/src/primitives/Signature/fromEd25519.ts +24 -0
- package/src/primitives/Signature/fromHex.ts +29 -0
- package/src/primitives/Signature/fromP256.ts +25 -0
- package/src/primitives/Signature/fromRpc.ts +38 -0
- package/src/primitives/Signature/fromSecp256k1.ts +29 -0
- package/src/primitives/Signature/fromTuple.ts +33 -0
- package/src/primitives/Signature/getR.ts +24 -0
- package/src/primitives/Signature/getS.ts +24 -0
- package/src/primitives/Signature/getV.ts +24 -0
- package/src/primitives/Signature/index.ts +61 -11
- package/src/primitives/Signature/toDER.ts +24 -0
- package/src/primitives/Signature/toHex.ts +24 -0
- package/src/primitives/Signature/toRpc.ts +35 -0
- package/src/primitives/Signature/toTuple.ts +29 -0
- package/src/primitives/Signature/verify.ts +31 -0
- package/src/primitives/Siwe/create.ts +56 -0
- package/src/primitives/Siwe/hash.ts +27 -0
- package/src/primitives/Siwe/index.ts +57 -21
- package/src/primitives/Siwe/parse.ts +24 -0
- package/src/primitives/Siwe/verify.ts +47 -0
- package/src/primitives/Transaction/index.ts +467 -2
- package/src/primitives/Uint/Uint.test.ts +200 -0
- package/src/primitives/Uint/dividedBy.ts +34 -0
- package/src/primitives/Uint/from.ts +35 -0
- package/src/primitives/Uint/fromAbiEncoded.ts +29 -0
- package/src/primitives/Uint/fromBigInt.ts +30 -0
- package/src/primitives/Uint/fromBytes.ts +32 -0
- package/src/primitives/Uint/fromHex.ts +32 -0
- package/src/primitives/Uint/fromNumber.ts +30 -0
- package/src/primitives/Uint/index.ts +90 -45
- package/src/primitives/Uint/isUint256.ts +25 -0
- package/src/primitives/Uint/isValid.ts +25 -0
- package/src/primitives/Uint/modulo.ts +34 -0
- package/src/primitives/Uint/toHex.ts +31 -0
- package/src/primitives/Uint/tryFrom.ts +30 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module status
|
|
3
|
+
* @description Pure EventLog status functions
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import * as EventLog from "@tevm/voltaire/EventLog";
|
|
7
|
+
import type { EventLogType } from "@tevm/voltaire/EventLog";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Check if log was removed due to reorg
|
|
11
|
+
*/
|
|
12
|
+
export const isRemoved = (log: EventLogType): boolean => EventLog.isRemoved(log);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Check if log was removed (alias)
|
|
16
|
+
*/
|
|
17
|
+
export const wasRemoved = (log: EventLogType): boolean => EventLog.wasRemoved(log);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module toRpc
|
|
3
|
+
* @description Convert EventLog to RPC format
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import type { EventLogType } from "@tevm/voltaire/EventLog";
|
|
7
|
+
import * as Hex from "@tevm/voltaire/Hex";
|
|
8
|
+
|
|
9
|
+
interface RpcLog {
|
|
10
|
+
address: string;
|
|
11
|
+
topics: string[];
|
|
12
|
+
data: string;
|
|
13
|
+
blockNumber?: string;
|
|
14
|
+
transactionHash?: string;
|
|
15
|
+
transactionIndex?: string;
|
|
16
|
+
blockHash?: string;
|
|
17
|
+
logIndex?: string;
|
|
18
|
+
removed?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Convert EventLog to RPC response format
|
|
23
|
+
*/
|
|
24
|
+
export const toRpc = (log: EventLogType): RpcLog => {
|
|
25
|
+
const result: RpcLog = {
|
|
26
|
+
address: Hex.fromBytes(log.address),
|
|
27
|
+
topics: log.topics.map((t) => Hex.fromBytes(t)),
|
|
28
|
+
data: Hex.fromBytes(log.data),
|
|
29
|
+
};
|
|
30
|
+
if (log.blockNumber !== undefined) {
|
|
31
|
+
result.blockNumber = `0x${log.blockNumber.toString(16)}`;
|
|
32
|
+
}
|
|
33
|
+
if (log.transactionHash !== undefined) {
|
|
34
|
+
result.transactionHash = Hex.fromBytes(log.transactionHash);
|
|
35
|
+
}
|
|
36
|
+
if (log.transactionIndex !== undefined) {
|
|
37
|
+
result.transactionIndex = `0x${log.transactionIndex.toString(16)}`;
|
|
38
|
+
}
|
|
39
|
+
if (log.blockHash !== undefined) {
|
|
40
|
+
result.blockHash = Hex.fromBytes(log.blockHash);
|
|
41
|
+
}
|
|
42
|
+
if (log.logIndex !== undefined) {
|
|
43
|
+
result.logIndex = `0x${log.logIndex.toString(16)}`;
|
|
44
|
+
}
|
|
45
|
+
if (log.removed !== undefined) {
|
|
46
|
+
result.removed = log.removed;
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
@@ -22,13 +22,13 @@ const HardforkTypeSchema = S.declare<HardforkType>(
|
|
|
22
22
|
* @example
|
|
23
23
|
* ```ts
|
|
24
24
|
* import * as S from 'effect/Schema'
|
|
25
|
-
* import {
|
|
25
|
+
* import { HardforkSchema } from 'voltaire-effect/primitives/Hardfork'
|
|
26
26
|
*
|
|
27
|
-
* const fork = S.decodeSync(
|
|
27
|
+
* const fork = S.decodeSync(HardforkSchema)('london')
|
|
28
28
|
* ```
|
|
29
29
|
* @since 0.0.1
|
|
30
30
|
*/
|
|
31
|
-
export const
|
|
31
|
+
export const HardforkSchema: S.Schema<HardforkType, string> = S.transformOrFail(
|
|
32
32
|
S.String,
|
|
33
33
|
HardforkTypeSchema,
|
|
34
34
|
{
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module allIds
|
|
3
|
+
* @description Get all hardfork IDs (pure)
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Hardfork from "@tevm/voltaire/Hardfork";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Get all hardfork IDs in order
|
|
10
|
+
*
|
|
11
|
+
* @returns Array of all hardfork types in chronological order
|
|
12
|
+
*/
|
|
13
|
+
export const allIds = Hardfork.allIds;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module allNames
|
|
3
|
+
* @description Get all hardfork names (pure)
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Hardfork from "@tevm/voltaire/Hardfork";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Get all hardfork names in order
|
|
10
|
+
*
|
|
11
|
+
* @returns Array of all hardfork names in chronological order
|
|
12
|
+
*/
|
|
13
|
+
export const allNames = Hardfork.allNames;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module compare
|
|
3
|
+
* @description Compare hardforks (pure)
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Hardfork from "@tevm/voltaire/Hardfork";
|
|
7
|
+
import type { HardforkType } from "@tevm/voltaire/Hardfork";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Compare two hardforks chronologically
|
|
11
|
+
*
|
|
12
|
+
* @param a - First hardfork
|
|
13
|
+
* @param b - Second hardfork
|
|
14
|
+
* @returns -1 if a < b, 0 if equal, 1 if a > b
|
|
15
|
+
*/
|
|
16
|
+
export const compare: (a: HardforkType, b: HardforkType) => number =
|
|
17
|
+
Hardfork.compare;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module comparisons
|
|
3
|
+
* @description Hardfork comparison predicates (pure)
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Hardfork from "@tevm/voltaire/Hardfork";
|
|
7
|
+
import type { HardforkType } from "@tevm/voltaire/Hardfork";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Check if a > b chronologically
|
|
11
|
+
*/
|
|
12
|
+
export const gt: (a: HardforkType, b: HardforkType) => boolean = Hardfork.gt;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Check if a >= b chronologically
|
|
16
|
+
*/
|
|
17
|
+
export const gte: (a: HardforkType, b: HardforkType) => boolean = Hardfork.gte;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Check if a < b chronologically
|
|
21
|
+
*/
|
|
22
|
+
export const lt: (a: HardforkType, b: HardforkType) => boolean = Hardfork.lt;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Check if a <= b chronologically
|
|
26
|
+
*/
|
|
27
|
+
export const lte: (a: HardforkType, b: HardforkType) => boolean = Hardfork.lte;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Check if fork is after a minimum fork
|
|
31
|
+
*/
|
|
32
|
+
export const isAfter: (fork: HardforkType, minFork: HardforkType) => boolean =
|
|
33
|
+
Hardfork.isAfter;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Check if fork is at least a minimum fork
|
|
37
|
+
*/
|
|
38
|
+
export const isAtLeast: (fork: HardforkType, minFork: HardforkType) => boolean =
|
|
39
|
+
Hardfork.isAtLeast;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Check if fork is before a maximum fork
|
|
43
|
+
*/
|
|
44
|
+
export const isBefore: (fork: HardforkType, maxFork: HardforkType) => boolean =
|
|
45
|
+
Hardfork.isBefore;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module equals
|
|
3
|
+
* @description Check hardfork equality (pure)
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Hardfork from "@tevm/voltaire/Hardfork";
|
|
7
|
+
import type { HardforkType } from "@tevm/voltaire/Hardfork";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Check if two hardforks are equal
|
|
11
|
+
*
|
|
12
|
+
* @param a - First hardfork
|
|
13
|
+
* @param b - Second hardfork
|
|
14
|
+
* @returns true if hardforks are the same
|
|
15
|
+
*/
|
|
16
|
+
export const equals: (a: HardforkType, b: HardforkType) => boolean =
|
|
17
|
+
Hardfork.equals;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module features
|
|
3
|
+
* @description Hardfork feature checks (pure)
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Hardfork from "@tevm/voltaire/Hardfork";
|
|
7
|
+
import type { HardforkType } from "@tevm/voltaire/Hardfork";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Check if hardfork has EIP-1153 (transient storage)
|
|
11
|
+
*/
|
|
12
|
+
export const hasEIP1153: (fork: HardforkType) => boolean = Hardfork.hasEIP1153;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Check if hardfork has EIP-1559 (fee market)
|
|
16
|
+
*/
|
|
17
|
+
export const hasEIP1559: (fork: HardforkType) => boolean = Hardfork.hasEIP1559;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Check if hardfork has EIP-3855 (PUSH0)
|
|
21
|
+
*/
|
|
22
|
+
export const hasEIP3855: (fork: HardforkType) => boolean = Hardfork.hasEIP3855;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Check if hardfork has EIP-4844 (blobs)
|
|
26
|
+
*/
|
|
27
|
+
export const hasEIP4844: (fork: HardforkType) => boolean = Hardfork.hasEIP4844;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Check if hardfork supports blob transactions
|
|
31
|
+
*/
|
|
32
|
+
export const supportsBlobs: (fork: HardforkType) => boolean =
|
|
33
|
+
Hardfork.supportsBlobs;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Check if hardfork supports EIP-1559 fee market
|
|
37
|
+
*/
|
|
38
|
+
export const supportsEIP1559: (fork: HardforkType) => boolean =
|
|
39
|
+
Hardfork.supportsEIP1559;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Check if hardfork supports PUSH0 opcode
|
|
43
|
+
*/
|
|
44
|
+
export const supportsPUSH0: (fork: HardforkType) => boolean =
|
|
45
|
+
Hardfork.supportsPUSH0;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Check if hardfork supports transient storage
|
|
49
|
+
*/
|
|
50
|
+
export const supportsTransientStorage: (fork: HardforkType) => boolean =
|
|
51
|
+
Hardfork.supportsTransientStorage;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Check if hardfork is Proof of Stake
|
|
55
|
+
*/
|
|
56
|
+
export const isPoS: (fork: HardforkType) => boolean = Hardfork.isPoS;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Check if hardfork is post-Merge
|
|
60
|
+
*/
|
|
61
|
+
export const isPostMerge: (fork: HardforkType) => boolean = Hardfork.isPostMerge;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module fromString
|
|
3
|
+
* @description Parse hardfork from string (pure)
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Hardfork from "@tevm/voltaire/Hardfork";
|
|
7
|
+
import type { HardforkType } from "@tevm/voltaire/Hardfork";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Parse a hardfork from string name
|
|
11
|
+
*
|
|
12
|
+
* @param name - Hardfork name (case insensitive)
|
|
13
|
+
* @returns HardforkType or undefined if invalid
|
|
14
|
+
*/
|
|
15
|
+
export const fromString: (name: string) => HardforkType | undefined =
|
|
16
|
+
Hardfork.fromString;
|
|
@@ -1,39 +1,149 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Hardfork
|
|
3
|
-
* @description Ethereum hardfork constants and
|
|
3
|
+
* @description Ethereum hardfork constants and utilities.
|
|
4
|
+
*
|
|
5
|
+
* Hardforks represent protocol upgrades that change EVM behavior, gas costs,
|
|
6
|
+
* or add new features.
|
|
7
|
+
*
|
|
8
|
+
* ## Type Declarations
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import * as Hardfork from 'voltaire-effect/primitives/Hardfork'
|
|
12
|
+
*
|
|
13
|
+
* function checkFeatures(fork: Hardfork.HardforkType) {
|
|
14
|
+
* // ...
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
4
17
|
*
|
|
5
18
|
* ## Constants
|
|
6
19
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
20
|
+
* ```typescript
|
|
21
|
+
* Hardfork.FRONTIER // Original launch (July 2015)
|
|
22
|
+
* Hardfork.HOMESTEAD // First planned hardfork
|
|
23
|
+
* Hardfork.BYZANTIUM // Added REVERT, RETURNDATASIZE, etc.
|
|
24
|
+
* Hardfork.CONSTANTINOPLE // Added CREATE2, shift opcodes
|
|
25
|
+
* Hardfork.ISTANBUL // EIP-2200: Rebalanced SSTORE
|
|
26
|
+
* Hardfork.BERLIN // EIP-2929: Cold/warm access
|
|
27
|
+
* Hardfork.LONDON // EIP-1559: Base fee
|
|
28
|
+
* Hardfork.MERGE // Proof of Stake transition
|
|
29
|
+
* Hardfork.SHANGHAI // EIP-3855: PUSH0
|
|
30
|
+
* Hardfork.CANCUN // EIP-4844: Blobs, EIP-1153: TLOAD/TSTORE
|
|
31
|
+
* Hardfork.PRAGUE // EIP-2537: BLS12-381
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* ## Pure Functions
|
|
11
35
|
*
|
|
12
|
-
*
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // Parsing
|
|
38
|
+
* Hardfork.fromString(name) // HardforkType | undefined
|
|
39
|
+
* Hardfork.toString(fork) // string
|
|
40
|
+
* Hardfork.isValidName(name) // boolean
|
|
41
|
+
*
|
|
42
|
+
* // Listing
|
|
43
|
+
* Hardfork.allIds() // HardforkType[]
|
|
44
|
+
* Hardfork.allNames() // string[]
|
|
45
|
+
* Hardfork.range(start, end) // HardforkType[]
|
|
46
|
+
*
|
|
47
|
+
* // Comparison
|
|
48
|
+
* Hardfork.compare(a, b) // -1 | 0 | 1
|
|
49
|
+
* Hardfork.equals(a, b) // boolean
|
|
50
|
+
* Hardfork.gt(a, b) // boolean
|
|
51
|
+
* Hardfork.gte(a, b) // boolean
|
|
52
|
+
* Hardfork.lt(a, b) // boolean
|
|
53
|
+
* Hardfork.lte(a, b) // boolean
|
|
54
|
+
* Hardfork.isAfter(fork, min) // boolean
|
|
55
|
+
* Hardfork.isAtLeast(fork, min) // boolean
|
|
56
|
+
* Hardfork.isBefore(fork, max) // boolean
|
|
57
|
+
* Hardfork.min(forks) // HardforkType
|
|
58
|
+
* Hardfork.max(forks) // HardforkType
|
|
59
|
+
*
|
|
60
|
+
* // Feature checks
|
|
61
|
+
* Hardfork.hasEIP1153(fork) // boolean (transient storage)
|
|
62
|
+
* Hardfork.hasEIP1559(fork) // boolean (fee market)
|
|
63
|
+
* Hardfork.hasEIP3855(fork) // boolean (PUSH0)
|
|
64
|
+
* Hardfork.hasEIP4844(fork) // boolean (blobs)
|
|
65
|
+
* Hardfork.supportsBlobs(fork) // boolean
|
|
66
|
+
* Hardfork.supportsEIP1559(fork) // boolean
|
|
67
|
+
* Hardfork.supportsPUSH0(fork) // boolean
|
|
68
|
+
* Hardfork.supportsTransientStorage(fork) // boolean
|
|
69
|
+
* Hardfork.isPoS(fork) // boolean
|
|
70
|
+
* Hardfork.isPostMerge(fork) // boolean
|
|
71
|
+
* ```
|
|
13
72
|
*
|
|
73
|
+
* @example
|
|
14
74
|
* ```typescript
|
|
15
75
|
* import * as Hardfork from 'voltaire-effect/primitives/Hardfork'
|
|
16
76
|
*
|
|
17
|
-
* const
|
|
77
|
+
* const fork = Hardfork.CANCUN
|
|
78
|
+
*
|
|
79
|
+
* if (Hardfork.supportsBlobs(fork)) {
|
|
80
|
+
* console.log('Blob transactions supported!')
|
|
81
|
+
* }
|
|
82
|
+
*
|
|
83
|
+
* if (Hardfork.isAtLeast(fork, Hardfork.SHANGHAI)) {
|
|
84
|
+
* console.log('PUSH0 available')
|
|
85
|
+
* }
|
|
18
86
|
* ```
|
|
19
87
|
*
|
|
20
88
|
* @since 0.1.0
|
|
21
89
|
*/
|
|
90
|
+
|
|
91
|
+
// Re-export type
|
|
92
|
+
export type { HardforkType } from "@tevm/voltaire/Hardfork";
|
|
93
|
+
|
|
94
|
+
// Schema
|
|
95
|
+
export { HardforkSchema } from "./HardforkSchema.js";
|
|
96
|
+
|
|
97
|
+
// Parsing
|
|
98
|
+
export { fromString } from "./fromString.js";
|
|
99
|
+
export { toString } from "./toString.js";
|
|
100
|
+
export { isValidName } from "./isValidName.js";
|
|
101
|
+
|
|
102
|
+
// Listing
|
|
103
|
+
export { allIds } from "./allIds.js";
|
|
104
|
+
export { allNames } from "./allNames.js";
|
|
105
|
+
export { range } from "./range.js";
|
|
106
|
+
|
|
107
|
+
// Comparison
|
|
108
|
+
export { compare } from "./compare.js";
|
|
109
|
+
export { equals } from "./equals.js";
|
|
110
|
+
export { gt, gte, lt, lte, isAfter, isAtLeast, isBefore } from "./comparisons.js";
|
|
111
|
+
export { min, max } from "./minMax.js";
|
|
112
|
+
|
|
113
|
+
// Feature checks
|
|
114
|
+
export {
|
|
115
|
+
hasEIP1153,
|
|
116
|
+
hasEIP1559,
|
|
117
|
+
hasEIP3855,
|
|
118
|
+
hasEIP4844,
|
|
119
|
+
supportsBlobs,
|
|
120
|
+
supportsEIP1559,
|
|
121
|
+
supportsPUSH0,
|
|
122
|
+
supportsTransientStorage,
|
|
123
|
+
isPoS,
|
|
124
|
+
isPostMerge,
|
|
125
|
+
} from "./features.js";
|
|
126
|
+
|
|
127
|
+
// Constants
|
|
22
128
|
export {
|
|
23
|
-
ARROW_GLACIER,
|
|
24
|
-
BERLIN,
|
|
25
|
-
BYZANTIUM,
|
|
26
|
-
CANCUN,
|
|
27
|
-
CONSTANTINOPLE,
|
|
28
129
|
FRONTIER,
|
|
29
|
-
GRAY_GLACIER,
|
|
30
130
|
HOMESTEAD,
|
|
131
|
+
DAO,
|
|
132
|
+
TANGERINE_WHISTLE,
|
|
133
|
+
SPURIOUS_DRAGON,
|
|
134
|
+
BYZANTIUM,
|
|
135
|
+
CONSTANTINOPLE,
|
|
136
|
+
PETERSBURG,
|
|
31
137
|
ISTANBUL,
|
|
32
|
-
LONDON,
|
|
33
138
|
MUIR_GLACIER,
|
|
34
|
-
|
|
35
|
-
|
|
139
|
+
BERLIN,
|
|
140
|
+
LONDON,
|
|
141
|
+
ARROW_GLACIER,
|
|
142
|
+
GRAY_GLACIER,
|
|
143
|
+
MERGE,
|
|
36
144
|
SHANGHAI,
|
|
37
|
-
|
|
38
|
-
|
|
145
|
+
CANCUN,
|
|
146
|
+
PRAGUE,
|
|
147
|
+
OSAKA,
|
|
148
|
+
DEFAULT,
|
|
39
149
|
} from "@tevm/voltaire/Hardfork";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module isValidName
|
|
3
|
+
* @description Validate hardfork name (pure)
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Hardfork from "@tevm/voltaire/Hardfork";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Check if a string is a valid hardfork name
|
|
10
|
+
*
|
|
11
|
+
* @param name - Name to validate
|
|
12
|
+
* @returns true if name is a valid hardfork
|
|
13
|
+
*/
|
|
14
|
+
export const isValidName: (name: string) => boolean = Hardfork.isValidName;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module minMax
|
|
3
|
+
* @description Min/max hardfork functions (pure)
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Hardfork from "@tevm/voltaire/Hardfork";
|
|
7
|
+
import type { HardforkType } from "@tevm/voltaire/Hardfork";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get the minimum (earliest) hardfork from an array
|
|
11
|
+
*
|
|
12
|
+
* @param forks - Array of hardforks
|
|
13
|
+
* @returns Earliest hardfork
|
|
14
|
+
*/
|
|
15
|
+
export const min: (forks: HardforkType[]) => HardforkType = Hardfork.min;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get the maximum (latest) hardfork from an array
|
|
19
|
+
*
|
|
20
|
+
* @param forks - Array of hardforks
|
|
21
|
+
* @returns Latest hardfork
|
|
22
|
+
*/
|
|
23
|
+
export const max: (forks: HardforkType[]) => HardforkType = Hardfork.max;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module range
|
|
3
|
+
* @description Get range of hardforks (pure)
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Hardfork from "@tevm/voltaire/Hardfork";
|
|
7
|
+
import type { HardforkType } from "@tevm/voltaire/Hardfork";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get a range of hardforks between start and end (inclusive)
|
|
11
|
+
*
|
|
12
|
+
* @param start - Start hardfork
|
|
13
|
+
* @param end - End hardfork
|
|
14
|
+
* @returns Array of hardforks in range
|
|
15
|
+
*/
|
|
16
|
+
export const range: (
|
|
17
|
+
start: HardforkType,
|
|
18
|
+
end: HardforkType,
|
|
19
|
+
) => HardforkType[] = Hardfork.range;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module toString
|
|
3
|
+
* @description Convert hardfork to string (pure)
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Hardfork from "@tevm/voltaire/Hardfork";
|
|
7
|
+
import type { HardforkType } from "@tevm/voltaire/Hardfork";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Convert hardfork to string name
|
|
11
|
+
*
|
|
12
|
+
* @param fork - Hardfork to convert
|
|
13
|
+
* @returns Hardfork name string
|
|
14
|
+
*/
|
|
15
|
+
// biome-ignore lint/suspicious/noShadowRestrictedNames: toString is the function name in our API
|
|
16
|
+
export const toString: (fork: HardforkType) => string = Hardfork.toString;
|
|
@@ -564,6 +564,110 @@ describe("error cases", () => {
|
|
|
564
564
|
});
|
|
565
565
|
});
|
|
566
566
|
|
|
567
|
+
describe("from functions", () => {
|
|
568
|
+
describe("from", () => {
|
|
569
|
+
it("parses valid hex string", () => {
|
|
570
|
+
const hash = Effect.runSync(Hash.from(`0x${"ab".repeat(32)}`));
|
|
571
|
+
expect(hash.length).toBe(32);
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
it("parses valid Uint8Array", () => {
|
|
575
|
+
const hash = Effect.runSync(Hash.from(new Uint8Array(32).fill(0xab)));
|
|
576
|
+
expect(hash.length).toBe(32);
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
it("fails on invalid hex", () => {
|
|
580
|
+
expect(() => Effect.runSync(Hash.from("invalid"))).toThrow();
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
it("fails on wrong length bytes", () => {
|
|
584
|
+
expect(() => Effect.runSync(Hash.from(new Uint8Array(16)))).toThrow();
|
|
585
|
+
});
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
describe("fromHex", () => {
|
|
589
|
+
it("parses valid hex", () => {
|
|
590
|
+
const hash = Effect.runSync(Hash.fromHex(`0x${"ab".repeat(32)}`));
|
|
591
|
+
expect(hash.length).toBe(32);
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
it("parses hex without 0x prefix", () => {
|
|
595
|
+
const hash = Effect.runSync(Hash.fromHex("ab".repeat(32)));
|
|
596
|
+
expect(hash.length).toBe(32);
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
it("fails on invalid characters", () => {
|
|
600
|
+
expect(() =>
|
|
601
|
+
Effect.runSync(Hash.fromHex(`0x${"gg".repeat(32)}`)),
|
|
602
|
+
).toThrow();
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
it("fails on wrong length", () => {
|
|
606
|
+
expect(() => Effect.runSync(Hash.fromHex(`0x${"ab".repeat(16)}`))).toThrow();
|
|
607
|
+
});
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
describe("fromBytes", () => {
|
|
611
|
+
it("parses valid 32-byte array", () => {
|
|
612
|
+
const hash = Effect.runSync(Hash.fromBytes(new Uint8Array(32)));
|
|
613
|
+
expect(hash.length).toBe(32);
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
it("fails on wrong length (too short)", () => {
|
|
617
|
+
expect(() => Effect.runSync(Hash.fromBytes(new Uint8Array(31)))).toThrow();
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
it("fails on wrong length (too long)", () => {
|
|
621
|
+
expect(() => Effect.runSync(Hash.fromBytes(new Uint8Array(33)))).toThrow();
|
|
622
|
+
});
|
|
623
|
+
});
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
describe("isHash", () => {
|
|
627
|
+
it("returns true for valid hash", () => {
|
|
628
|
+
const hash = S.decodeSync(Hash.Hex)(`0x${"ab".repeat(32)}`);
|
|
629
|
+
expect(Hash.isHash(hash)).toBe(true);
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
it("returns false for wrong length", () => {
|
|
633
|
+
expect(Hash.isHash(new Uint8Array(16))).toBe(false);
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
it("returns false for non-Uint8Array", () => {
|
|
637
|
+
expect(Hash.isHash("0x" + "ab".repeat(32))).toBe(false);
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
it("returns false for null", () => {
|
|
641
|
+
expect(Hash.isHash(null)).toBe(false);
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
it("returns false for undefined", () => {
|
|
645
|
+
expect(Hash.isHash(undefined)).toBe(false);
|
|
646
|
+
});
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
describe("toHex", () => {
|
|
650
|
+
it("converts hash to hex string", () => {
|
|
651
|
+
const hash = S.decodeSync(Hash.Hex)(`0x${"ab".repeat(32)}`);
|
|
652
|
+
expect(Hash.toHex(hash)).toBe(`0x${"ab".repeat(32)}`);
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
it("returns lowercase hex", () => {
|
|
656
|
+
const hash = S.decodeSync(Hash.Hex)(`0x${"AB".repeat(32)}`);
|
|
657
|
+
expect(Hash.toHex(hash)).toBe(`0x${"ab".repeat(32)}`);
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
it("produces 66-character string", () => {
|
|
661
|
+
const hash = S.decodeSync(Hash.Hex)(`0x${"00".repeat(32)}`);
|
|
662
|
+
expect(Hash.toHex(hash).length).toBe(66);
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
it("starts with 0x", () => {
|
|
666
|
+
const hash = S.decodeSync(Hash.Hex)(`0x${"ab".repeat(32)}`);
|
|
667
|
+
expect(Hash.toHex(hash).startsWith("0x")).toBe(true);
|
|
668
|
+
});
|
|
669
|
+
});
|
|
670
|
+
|
|
567
671
|
describe("additional edge cases", () => {
|
|
568
672
|
it("isValidHex with missing 0x prefix accepts raw hex", () => {
|
|
569
673
|
const result = Effect.runSync(Hash.isValidHex("ab".repeat(32)));
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Create Hash from string or bytes.
|
|
3
|
+
*
|
|
4
|
+
* @module Hash/from
|
|
5
|
+
* @since 0.0.1
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { HashType } from "@tevm/voltaire/Hash";
|
|
9
|
+
import * as Hash from "@tevm/voltaire/Hash";
|
|
10
|
+
import * as Effect from "effect/Effect";
|
|
11
|
+
import { ValidationError } from "@tevm/voltaire/errors";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Create Hash from string or bytes.
|
|
15
|
+
*
|
|
16
|
+
* @description Parses hex string or Uint8Array into a 32-byte hash.
|
|
17
|
+
* Can fail if input is invalid format or wrong length.
|
|
18
|
+
*
|
|
19
|
+
* @param {string | Uint8Array} value - Hex string or Uint8Array
|
|
20
|
+
* @returns {Effect.Effect<HashType, ValidationError>} Effect containing the hash
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import * as Hash from 'voltaire-effect/primitives/Hash'
|
|
25
|
+
* import * as Effect from 'effect/Effect'
|
|
26
|
+
*
|
|
27
|
+
* const hash = Effect.runSync(Hash.from('0x' + 'ab'.repeat(32)))
|
|
28
|
+
* const hash2 = Effect.runSync(Hash.from(new Uint8Array(32)))
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @since 0.0.1
|
|
32
|
+
*/
|
|
33
|
+
export const from = (
|
|
34
|
+
value: string | Uint8Array,
|
|
35
|
+
): Effect.Effect<HashType, ValidationError> =>
|
|
36
|
+
Effect.try({
|
|
37
|
+
try: () => Hash.from(value),
|
|
38
|
+
catch: (error) =>
|
|
39
|
+
new ValidationError(
|
|
40
|
+
error instanceof Error ? error.message : "Invalid hash input",
|
|
41
|
+
{
|
|
42
|
+
value,
|
|
43
|
+
expected: "32-byte hash",
|
|
44
|
+
cause: error instanceof Error ? error : undefined,
|
|
45
|
+
},
|
|
46
|
+
),
|
|
47
|
+
});
|