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,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Effect-based Uint256 division.
|
|
3
|
+
* @module dividedBy
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Uint256, type Type as Uint256Type } from "@tevm/voltaire/Uint";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Divide two Uint256 values.
|
|
12
|
+
*
|
|
13
|
+
* @description
|
|
14
|
+
* Floor division (a / b). Fails if divisor is zero.
|
|
15
|
+
*
|
|
16
|
+
* @param a - Dividend
|
|
17
|
+
* @param b - Divisor
|
|
18
|
+
* @returns Effect yielding quotient
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const quotient = Effect.runSync(Uint.dividedBy(a, b))
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @since 0.0.1
|
|
26
|
+
*/
|
|
27
|
+
export const dividedBy = (
|
|
28
|
+
a: Uint256Type,
|
|
29
|
+
b: Uint256Type,
|
|
30
|
+
): Effect.Effect<Uint256Type, Error> =>
|
|
31
|
+
Effect.try({
|
|
32
|
+
try: () => Uint256.dividedBy(a, b),
|
|
33
|
+
catch: (e) => (e instanceof Error ? e : new Error(String(e))),
|
|
34
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Effect-based Uint256 creation from various inputs.
|
|
3
|
+
* @module from
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Uint256, type Type as Uint256Type } from "@tevm/voltaire/Uint";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create Uint256 from bigint, number, or string.
|
|
12
|
+
*
|
|
13
|
+
* @description
|
|
14
|
+
* Accepts decimal strings, hex strings (0x-prefixed), numbers, or bigints.
|
|
15
|
+
* Fails on invalid format, negative values, or overflow.
|
|
16
|
+
*
|
|
17
|
+
* @param value - Input value
|
|
18
|
+
* @returns Effect yielding Uint256
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const a = Effect.runSync(Uint.from(100n))
|
|
23
|
+
* const b = Effect.runSync(Uint.from("0xff"))
|
|
24
|
+
* const c = Effect.runSync(Uint.from(42))
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @since 0.0.1
|
|
28
|
+
*/
|
|
29
|
+
export const from = (
|
|
30
|
+
value: bigint | number | string,
|
|
31
|
+
): Effect.Effect<Uint256Type, Error> =>
|
|
32
|
+
Effect.try({
|
|
33
|
+
try: () => Uint256.from(value),
|
|
34
|
+
catch: (e) => (e instanceof Error ? e : new Error(String(e))),
|
|
35
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Effect-based Uint256 creation from ABI-encoded bytes.
|
|
3
|
+
* @module fromAbiEncoded
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Uint256, type Type as Uint256Type } from "@tevm/voltaire/Uint";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create Uint256 from ABI-encoded bytes (32 bytes, big-endian).
|
|
12
|
+
*
|
|
13
|
+
* @param data - 32-byte ABI-encoded data
|
|
14
|
+
* @returns Effect yielding Uint256
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const value = Effect.runSync(Uint.fromAbiEncoded(bytes))
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @since 0.0.1
|
|
22
|
+
*/
|
|
23
|
+
export const fromAbiEncoded = (
|
|
24
|
+
data: Uint8Array,
|
|
25
|
+
): Effect.Effect<Uint256Type, Error> =>
|
|
26
|
+
Effect.try({
|
|
27
|
+
try: () => Uint256.fromAbiEncoded(data),
|
|
28
|
+
catch: (e) => (e instanceof Error ? e : new Error(String(e))),
|
|
29
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Effect-based Uint256 creation from bigint.
|
|
3
|
+
* @module fromBigInt
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Uint256, type Type as Uint256Type } from "@tevm/voltaire/Uint";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create Uint256 from bigint.
|
|
12
|
+
*
|
|
13
|
+
* @description
|
|
14
|
+
* Fails on negative values or values exceeding 2^256-1.
|
|
15
|
+
*
|
|
16
|
+
* @param value - bigint value
|
|
17
|
+
* @returns Effect yielding Uint256
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const value = Effect.runSync(Uint.fromBigInt(1000000000000000000n))
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @since 0.0.1
|
|
25
|
+
*/
|
|
26
|
+
export const fromBigInt = (value: bigint): Effect.Effect<Uint256Type, Error> =>
|
|
27
|
+
Effect.try({
|
|
28
|
+
try: () => Uint256.fromBigInt(value),
|
|
29
|
+
catch: (e) => (e instanceof Error ? e : new Error(String(e))),
|
|
30
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Effect-based Uint256 creation from bytes.
|
|
3
|
+
* @module fromBytes
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Uint256, type Type as Uint256Type } from "@tevm/voltaire/Uint";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create Uint256 from bytes (big-endian).
|
|
12
|
+
*
|
|
13
|
+
* @description
|
|
14
|
+
* Interprets bytes as big-endian unsigned integer.
|
|
15
|
+
* Fails if bytes exceed 32 bytes.
|
|
16
|
+
*
|
|
17
|
+
* @param bytes - Input bytes
|
|
18
|
+
* @returns Effect yielding Uint256
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const value = Effect.runSync(Uint.fromBytes(new Uint8Array([0xff])))
|
|
23
|
+
* // 255n
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @since 0.0.1
|
|
27
|
+
*/
|
|
28
|
+
export const fromBytes = (bytes: Uint8Array): Effect.Effect<Uint256Type, Error> =>
|
|
29
|
+
Effect.try({
|
|
30
|
+
try: () => Uint256.fromBytes(bytes),
|
|
31
|
+
catch: (e) => (e instanceof Error ? e : new Error(String(e))),
|
|
32
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Effect-based Uint256 creation from hex string.
|
|
3
|
+
* @module fromHex
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Uint256, type Type as Uint256Type } from "@tevm/voltaire/Uint";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create Uint256 from hex string.
|
|
12
|
+
*
|
|
13
|
+
* @description
|
|
14
|
+
* Accepts hex strings with or without 0x prefix.
|
|
15
|
+
* Fails on invalid hex or overflow.
|
|
16
|
+
*
|
|
17
|
+
* @param hex - Hex string
|
|
18
|
+
* @returns Effect yielding Uint256
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const value = Effect.runSync(Uint.fromHex("0xde0b6b3a7640000"))
|
|
23
|
+
* // 1000000000000000000n
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @since 0.0.1
|
|
27
|
+
*/
|
|
28
|
+
export const fromHex = (hex: string): Effect.Effect<Uint256Type, Error> =>
|
|
29
|
+
Effect.try({
|
|
30
|
+
try: () => Uint256.fromHex(hex),
|
|
31
|
+
catch: (e) => (e instanceof Error ? e : new Error(String(e))),
|
|
32
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Effect-based Uint256 creation from number.
|
|
3
|
+
* @module fromNumber
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Uint256, type Type as Uint256Type } from "@tevm/voltaire/Uint";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create Uint256 from number.
|
|
12
|
+
*
|
|
13
|
+
* @description
|
|
14
|
+
* Fails on negative, non-integer, or unsafe integer values.
|
|
15
|
+
*
|
|
16
|
+
* @param value - Number value
|
|
17
|
+
* @returns Effect yielding Uint256
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const value = Effect.runSync(Uint.fromNumber(42))
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @since 0.0.1
|
|
25
|
+
*/
|
|
26
|
+
export const fromNumber = (value: number): Effect.Effect<Uint256Type, Error> =>
|
|
27
|
+
Effect.try({
|
|
28
|
+
try: () => Uint256.fromNumber(value),
|
|
29
|
+
catch: (e) => (e instanceof Error ? e : new Error(String(e))),
|
|
30
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module Uint
|
|
3
|
-
* @description Effect
|
|
3
|
+
* @description Effect wrappers for 256-bit unsigned integers (Uint256).
|
|
4
4
|
*
|
|
5
5
|
* ## Schemas
|
|
6
6
|
*
|
|
@@ -12,27 +12,43 @@
|
|
|
12
12
|
* | `Uint.Hex` | hex string | Uint256Type |
|
|
13
13
|
* | `Uint.Bytes` | Uint8Array | Uint256Type |
|
|
14
14
|
*
|
|
15
|
-
* ##
|
|
15
|
+
* ## Constructors (Effect-wrapped)
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* import * as S from 'effect/Schema'
|
|
17
|
+
* - `from`, `fromBigInt`, `fromNumber`, `fromHex`, `fromBytes`, `fromAbiEncoded`
|
|
18
|
+
* - `tryFrom` (returns Option)
|
|
20
19
|
*
|
|
21
|
-
*
|
|
22
|
-
* const value = S.decodeSync(Uint.BigInt)(1000000000000000000n)
|
|
20
|
+
* ## Type Guards (pure)
|
|
23
21
|
*
|
|
24
|
-
*
|
|
25
|
-
* const bigint = S.encodeSync(Uint.BigInt)(value)
|
|
26
|
-
* const hex = S.encodeSync(Uint.Hex)(value)
|
|
27
|
-
* ```
|
|
22
|
+
* - `isUint256`, `isValid`
|
|
28
23
|
*
|
|
29
|
-
* ##
|
|
24
|
+
* ## Arithmetic (pure, wrapping)
|
|
25
|
+
*
|
|
26
|
+
* - `plus`, `minus`, `times`, `toPower`
|
|
27
|
+
*
|
|
28
|
+
* ## Arithmetic (Effect-wrapped, can fail)
|
|
29
|
+
*
|
|
30
|
+
* - `dividedBy`, `modulo` (division by zero)
|
|
31
|
+
*
|
|
32
|
+
* ## Bitwise (pure)
|
|
30
33
|
*
|
|
31
|
-
* Arithmetic, comparison, and bitwise operations are available as pure functions:
|
|
32
|
-
* - `plus`, `minus`, `times`, `dividedBy`, `modulo`
|
|
33
|
-
* - `equals`, `lessThan`, `greaterThan`, `lessThanOrEqual`, `greaterThanOrEqual`
|
|
34
34
|
* - `bitwiseAnd`, `bitwiseOr`, `bitwiseXor`, `bitwiseNot`, `shiftLeft`, `shiftRight`
|
|
35
|
-
*
|
|
35
|
+
*
|
|
36
|
+
* ## Comparison (pure)
|
|
37
|
+
*
|
|
38
|
+
* - `equals`, `notEquals`, `lessThan`, `lessThanOrEqual`, `greaterThan`, `greaterThanOrEqual`, `isZero`
|
|
39
|
+
*
|
|
40
|
+
* ## Bit utilities (pure)
|
|
41
|
+
*
|
|
42
|
+
* - `bitLength`, `leadingZeros`, `popCount`, `isPowerOf2`
|
|
43
|
+
*
|
|
44
|
+
* ## Math utilities
|
|
45
|
+
*
|
|
46
|
+
* - `gcd`, `lcm`, `clone`
|
|
47
|
+
* - `min`, `max`, `minimum`, `maximum`, `sum`, `product` (Effect-wrapped)
|
|
48
|
+
*
|
|
49
|
+
* ## Converters (Effect-wrapped)
|
|
50
|
+
*
|
|
51
|
+
* - `toBigInt`, `toNumber`, `toHex`, `toBytes`, `toAbiEncoded`, `toString`
|
|
36
52
|
*
|
|
37
53
|
* @since 0.1.0
|
|
38
54
|
*/
|
|
@@ -40,46 +56,75 @@
|
|
|
40
56
|
// Schemas
|
|
41
57
|
export { BigInt } from "./BigInt.js";
|
|
42
58
|
export { Bytes } from "./Bytes.js";
|
|
43
|
-
|
|
59
|
+
export { Hex } from "./Hex.js";
|
|
60
|
+
export { Number } from "./Number.js";
|
|
61
|
+
export { String } from "./String.js";
|
|
62
|
+
|
|
63
|
+
// Constructors (fallible)
|
|
64
|
+
export { from } from "./from.js";
|
|
65
|
+
export { fromAbiEncoded } from "./fromAbiEncoded.js";
|
|
66
|
+
export { fromBigInt } from "./fromBigInt.js";
|
|
67
|
+
export { fromBytes } from "./fromBytes.js";
|
|
68
|
+
export { fromHex } from "./fromHex.js";
|
|
69
|
+
export { fromNumber } from "./fromNumber.js";
|
|
70
|
+
export { tryFrom } from "./tryFrom.js";
|
|
71
|
+
|
|
72
|
+
// Type guards (pure)
|
|
73
|
+
export { isUint256 } from "./isUint256.js";
|
|
74
|
+
export { isValid } from "./isValid.js";
|
|
75
|
+
|
|
76
|
+
// Bit utilities (pure)
|
|
44
77
|
export { bitLength } from "./bitLength.js";
|
|
45
|
-
|
|
78
|
+
export { leadingZeros } from "./leadingZeros.js";
|
|
79
|
+
export { popCount } from "./popCount.js";
|
|
80
|
+
export { isPowerOf2 } from "./isPowerOf2.js";
|
|
81
|
+
|
|
82
|
+
// Bitwise (pure)
|
|
46
83
|
export { bitwiseAnd } from "./bitwiseAnd.js";
|
|
47
84
|
export { bitwiseNot } from "./bitwiseNot.js";
|
|
48
85
|
export { bitwiseOr } from "./bitwiseOr.js";
|
|
49
86
|
export { bitwiseXor } from "./bitwiseXor.js";
|
|
50
|
-
export {
|
|
51
|
-
|
|
52
|
-
|
|
87
|
+
export { shiftLeft } from "./shiftLeft.js";
|
|
88
|
+
export { shiftRight } from "./shiftRight.js";
|
|
89
|
+
|
|
90
|
+
// Comparison (pure)
|
|
53
91
|
export { equals } from "./equals.js";
|
|
54
|
-
|
|
55
|
-
export {
|
|
92
|
+
export { notEquals } from "./notEquals.js";
|
|
93
|
+
export { lessThan } from "./lessThan.js";
|
|
94
|
+
export { lessThanOrEqual } from "./lessThanOrEqual.js";
|
|
56
95
|
export { greaterThan } from "./greaterThan.js";
|
|
57
96
|
export { greaterThanOrEqual } from "./greaterThanOrEqual.js";
|
|
58
|
-
export { Hex } from "./Hex.js";
|
|
59
|
-
export { isPowerOf2 } from "./isPowerOf2.js";
|
|
60
97
|
export { isZero } from "./isZero.js";
|
|
98
|
+
|
|
99
|
+
// Arithmetic (wrapping, pure)
|
|
100
|
+
export { plus } from "./plus.js";
|
|
101
|
+
export { minus } from "./minus.js";
|
|
102
|
+
export { times } from "./times.js";
|
|
103
|
+
export { toPower } from "./toPower.js";
|
|
104
|
+
|
|
105
|
+
// Arithmetic (fallible - division by zero)
|
|
106
|
+
export { dividedBy } from "./dividedBy.js";
|
|
107
|
+
export { modulo } from "./modulo.js";
|
|
108
|
+
|
|
109
|
+
// Math utilities (pure)
|
|
110
|
+
export { gcd } from "./gcd.js";
|
|
61
111
|
export { lcm } from "./lcm.js";
|
|
62
|
-
export {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
export { max } from "./max.js";
|
|
66
|
-
export { maximum } from "./maximum.js";
|
|
112
|
+
export { clone } from "./clone.js";
|
|
113
|
+
|
|
114
|
+
// Min/Max (Effect-wrapped)
|
|
67
115
|
export { min } from "./min.js";
|
|
68
|
-
|
|
116
|
+
export { max } from "./max.js";
|
|
69
117
|
export { minimum } from "./minimum.js";
|
|
70
|
-
export {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// Arithmetic (wrapping, infallible)
|
|
74
|
-
export { plus } from "./plus.js";
|
|
75
|
-
export { popCount } from "./popCount.js";
|
|
76
|
-
export { product } from "./product.js";
|
|
77
|
-
export { String } from "./String.js";
|
|
78
|
-
export { shiftLeft } from "./shiftLeft.js";
|
|
79
|
-
export { shiftRight } from "./shiftRight.js";
|
|
80
|
-
// Aggregate (infallible)
|
|
118
|
+
export { maximum } from "./maximum.js";
|
|
119
|
+
|
|
120
|
+
// Aggregate (Effect-wrapped)
|
|
81
121
|
export { sum } from "./sum.js";
|
|
82
|
-
export {
|
|
122
|
+
export { product } from "./product.js";
|
|
123
|
+
|
|
124
|
+
// Converters (Effect-wrapped)
|
|
83
125
|
export { toAbiEncoded } from "./toAbiEncoded.js";
|
|
84
|
-
|
|
85
|
-
export {
|
|
126
|
+
export { toBigInt } from "./toBigInt.js";
|
|
127
|
+
export { toBytes } from "./toBytes.js";
|
|
128
|
+
export { toHex } from "./toHex.js";
|
|
129
|
+
export { toNumber } from "./toNumber.js";
|
|
130
|
+
export { toString } from "./toString.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Uint256 type guard.
|
|
3
|
+
* @module isUint256
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Uint256, type Type as Uint256Type } from "@tevm/voltaire/Uint";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Type guard for Uint256.
|
|
11
|
+
*
|
|
12
|
+
* @param value - Value to check
|
|
13
|
+
* @returns true if value is valid Uint256
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* if (Uint.isUint256(value)) {
|
|
18
|
+
* const hex = Uint.toHex(value)
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @since 0.0.1
|
|
23
|
+
*/
|
|
24
|
+
export const isUint256 = (value: unknown): value is Uint256Type =>
|
|
25
|
+
Uint256.isValid(value);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Uint256 validation check.
|
|
3
|
+
* @module isValid
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Uint256, type Type as Uint256Type } from "@tevm/voltaire/Uint";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Check if value is a valid Uint256.
|
|
11
|
+
*
|
|
12
|
+
* @param value - Value to check
|
|
13
|
+
* @returns true if value is valid Uint256
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* Uint.isValid(100n) // true
|
|
18
|
+
* Uint.isValid(-1n) // false
|
|
19
|
+
* Uint.isValid("hello") // false
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @since 0.0.1
|
|
23
|
+
*/
|
|
24
|
+
export const isValid = (value: unknown): value is Uint256Type =>
|
|
25
|
+
Uint256.isValid(value);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Effect-based Uint256 modulo operation.
|
|
3
|
+
* @module modulo
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Uint256, type Type as Uint256Type } from "@tevm/voltaire/Uint";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Modulo operation on Uint256 values.
|
|
12
|
+
*
|
|
13
|
+
* @description
|
|
14
|
+
* Computes remainder (a % b). Fails if divisor is zero.
|
|
15
|
+
*
|
|
16
|
+
* @param a - Dividend
|
|
17
|
+
* @param b - Divisor
|
|
18
|
+
* @returns Effect yielding remainder
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const remainder = Effect.runSync(Uint.modulo(a, b))
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @since 0.0.1
|
|
26
|
+
*/
|
|
27
|
+
export const modulo = (
|
|
28
|
+
a: Uint256Type,
|
|
29
|
+
b: Uint256Type,
|
|
30
|
+
): Effect.Effect<Uint256Type, Error> =>
|
|
31
|
+
Effect.try({
|
|
32
|
+
try: () => Uint256.modulo(a, b),
|
|
33
|
+
catch: (e) => (e instanceof Error ? e : new Error(String(e))),
|
|
34
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Effect-based Uint256 to hex string conversion.
|
|
3
|
+
* @module toHex
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Uint256, type Type as Uint256Type } from "@tevm/voltaire/Uint";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Converts a Uint256 to hex string.
|
|
12
|
+
*
|
|
13
|
+
* @param uint - The Uint256 to convert
|
|
14
|
+
* @param padded - Whether to pad to 64 characters (default true)
|
|
15
|
+
* @returns Effect yielding hex string with 0x prefix
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const hex = Effect.runSync(Uint.toHex(uint))
|
|
20
|
+
* // "0x00000000000000000000000000000000000000000000000000000000000000ff"
|
|
21
|
+
*
|
|
22
|
+
* const unpadded = Effect.runSync(Uint.toHex(uint, false))
|
|
23
|
+
* // "0xff"
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @since 0.0.1
|
|
27
|
+
*/
|
|
28
|
+
export const toHex = (
|
|
29
|
+
uint: Uint256Type,
|
|
30
|
+
padded?: boolean,
|
|
31
|
+
): Effect.Effect<string> => Effect.sync(() => Uint256.toHex(uint, padded));
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Effect-based Uint256 try-from with Option result.
|
|
3
|
+
* @module tryFrom
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Uint256, type Type as Uint256Type } from "@tevm/voltaire/Uint";
|
|
8
|
+
import * as Option from "effect/Option";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Try to create Uint256, returns Option.
|
|
12
|
+
*
|
|
13
|
+
* @description
|
|
14
|
+
* Returns Some(value) on success, None on failure.
|
|
15
|
+
* Does not throw.
|
|
16
|
+
*
|
|
17
|
+
* @param value - Input value
|
|
18
|
+
* @returns Option of Uint256
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const result = Uint.tryFrom(100n) // Some(100n)
|
|
23
|
+
* const invalid = Uint.tryFrom(-1n) // None
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @since 0.0.1
|
|
27
|
+
*/
|
|
28
|
+
export const tryFrom = (
|
|
29
|
+
value: bigint | number | string,
|
|
30
|
+
): Option.Option<Uint256Type> => Option.fromNullable(Uint256.tryFrom(value));
|