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,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type RlpDecodingError,
|
|
3
|
+
RlpDecodingError as RlpDecodingErrorClass,
|
|
4
|
+
Rlp as VoltaireRlp,
|
|
5
|
+
} from "@tevm/voltaire/Rlp";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
|
|
8
|
+
const isRlpDecodingError = (e: unknown): e is RlpDecodingError =>
|
|
9
|
+
e instanceof RlpDecodingErrorClass ||
|
|
10
|
+
(e !== null &&
|
|
11
|
+
typeof e === "object" &&
|
|
12
|
+
"name" in e &&
|
|
13
|
+
e.name === "RlpDecodingError");
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Decodes RLP-encoded bytes to an object with known keys.
|
|
17
|
+
*
|
|
18
|
+
* @param data - RLP-encoded data
|
|
19
|
+
* @returns Effect that succeeds with decoded object or fails with RlpDecodingError
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import * as Effect from 'effect/Effect'
|
|
24
|
+
* import { decodeObject, encodeObject } from 'voltaire-effect/primitives/Rlp'
|
|
25
|
+
*
|
|
26
|
+
* const encoded = Effect.runSync(encodeObject({
|
|
27
|
+
* name: new Uint8Array([65, 66]),
|
|
28
|
+
* age: new Uint8Array([25])
|
|
29
|
+
* }))
|
|
30
|
+
* const decoded = Effect.runSync(decodeObject(encoded))
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @since 0.0.1
|
|
34
|
+
*/
|
|
35
|
+
export const decodeObject = (
|
|
36
|
+
data: Uint8Array,
|
|
37
|
+
): Effect.Effect<Record<string, unknown>, RlpDecodingError> =>
|
|
38
|
+
Effect.try({
|
|
39
|
+
try: () => VoltaireRlp.decodeObject(data),
|
|
40
|
+
catch: (e) =>
|
|
41
|
+
isRlpDecodingError(e)
|
|
42
|
+
? e
|
|
43
|
+
: new RlpDecodingErrorClass("RLP object decoding failed", {
|
|
44
|
+
cause: e instanceof Error ? e : undefined,
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type RlpDecodingError,
|
|
3
|
+
RlpDecodingError as RlpDecodingErrorClass,
|
|
4
|
+
Rlp as VoltaireRlp,
|
|
5
|
+
} from "@tevm/voltaire/Rlp";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
|
|
8
|
+
const isRlpDecodingError = (e: unknown): e is RlpDecodingError =>
|
|
9
|
+
e instanceof RlpDecodingErrorClass ||
|
|
10
|
+
(e !== null &&
|
|
11
|
+
typeof e === "object" &&
|
|
12
|
+
"name" in e &&
|
|
13
|
+
e.name === "RlpDecodingError");
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Decodes RLP-encoded bytes and returns the value directly.
|
|
17
|
+
*
|
|
18
|
+
* This is a convenience wrapper around decode() that returns just the decoded value
|
|
19
|
+
* without the metadata wrapper.
|
|
20
|
+
*
|
|
21
|
+
* @param bytes - RLP-encoded data
|
|
22
|
+
* @returns Effect that succeeds with decoded value or fails with RlpDecodingError
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import * as Effect from 'effect/Effect'
|
|
27
|
+
* import { decodeValue } from 'voltaire-effect/primitives/Rlp'
|
|
28
|
+
*
|
|
29
|
+
* // Decode bytes - returns Uint8Array directly
|
|
30
|
+
* const value = Effect.runSync(decodeValue(new Uint8Array([0x83, 1, 2, 3])))
|
|
31
|
+
* // => Uint8Array([1, 2, 3])
|
|
32
|
+
*
|
|
33
|
+
* // Decode list - returns nested arrays
|
|
34
|
+
* const items = Effect.runSync(decodeValue(new Uint8Array([0xc3, 0x01, 0x02, 0x03])))
|
|
35
|
+
* // => [Uint8Array([1]), Uint8Array([2]), Uint8Array([3])]
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @since 0.0.1
|
|
39
|
+
*/
|
|
40
|
+
export const decodeValue = (
|
|
41
|
+
bytes: Uint8Array,
|
|
42
|
+
): Effect.Effect<Uint8Array | unknown[], RlpDecodingError> =>
|
|
43
|
+
Effect.try({
|
|
44
|
+
try: () => VoltaireRlp.decodeValue(bytes),
|
|
45
|
+
catch: (e) =>
|
|
46
|
+
isRlpDecodingError(e)
|
|
47
|
+
? e
|
|
48
|
+
: new RlpDecodingErrorClass("RLP value decoding failed", {
|
|
49
|
+
cause: e instanceof Error ? e : undefined,
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type BrandedRlp,
|
|
3
|
+
type RlpEncodingError,
|
|
4
|
+
RlpEncodingError as RlpEncodingErrorClass,
|
|
5
|
+
Rlp as VoltaireRlp,
|
|
6
|
+
} from "@tevm/voltaire/Rlp";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
|
|
9
|
+
type Encodable = Uint8Array | BrandedRlp | Encodable[];
|
|
10
|
+
|
|
11
|
+
const isRlpEncodingError = (e: unknown): e is RlpEncodingError =>
|
|
12
|
+
e instanceof RlpEncodingErrorClass ||
|
|
13
|
+
(e !== null &&
|
|
14
|
+
typeof e === "object" &&
|
|
15
|
+
"name" in e &&
|
|
16
|
+
e.name === "RlpEncodingError");
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Encodes multiple items efficiently.
|
|
20
|
+
*
|
|
21
|
+
* @param items - Array of items to encode
|
|
22
|
+
* @returns Effect that succeeds with array of RLP-encoded results or fails with RlpEncodingError
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import * as Effect from 'effect/Effect'
|
|
27
|
+
* import { encodeBatch } from 'voltaire-effect/primitives/Rlp'
|
|
28
|
+
*
|
|
29
|
+
* const items = [
|
|
30
|
+
* [new Uint8Array([1, 2]), new Uint8Array([3, 4])],
|
|
31
|
+
* [new Uint8Array([5, 6]), new Uint8Array([7, 8])]
|
|
32
|
+
* ]
|
|
33
|
+
* const encoded = Effect.runSync(encodeBatch(items))
|
|
34
|
+
* // => [Uint8Array(...), Uint8Array(...)]
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @since 0.0.1
|
|
38
|
+
*/
|
|
39
|
+
export const encodeBatch = (
|
|
40
|
+
items: Encodable[][],
|
|
41
|
+
): Effect.Effect<Uint8Array[], RlpEncodingError> =>
|
|
42
|
+
Effect.try({
|
|
43
|
+
try: () => VoltaireRlp.encodeBatch(items),
|
|
44
|
+
catch: (e) =>
|
|
45
|
+
isRlpEncodingError(e)
|
|
46
|
+
? e
|
|
47
|
+
: new RlpEncodingErrorClass("RLP batch encoding failed", {
|
|
48
|
+
cause: e instanceof Error ? e : undefined,
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type BrandedRlp,
|
|
3
|
+
type RlpEncodingError,
|
|
4
|
+
RlpEncodingError as RlpEncodingErrorClass,
|
|
5
|
+
Rlp as VoltaireRlp,
|
|
6
|
+
} from "@tevm/voltaire/Rlp";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
|
|
9
|
+
type Encodable = Uint8Array | BrandedRlp | Encodable[];
|
|
10
|
+
|
|
11
|
+
const isRlpEncodingError = (e: unknown): e is RlpEncodingError =>
|
|
12
|
+
e instanceof RlpEncodingErrorClass ||
|
|
13
|
+
(e !== null &&
|
|
14
|
+
typeof e === "object" &&
|
|
15
|
+
"name" in e &&
|
|
16
|
+
e.name === "RlpEncodingError");
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Encodes an object (key-value pairs) to RLP format.
|
|
20
|
+
*
|
|
21
|
+
* @param obj - Object to encode
|
|
22
|
+
* @returns Effect that succeeds with RLP-encoded bytes or fails with RlpEncodingError
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import * as Effect from 'effect/Effect'
|
|
27
|
+
* import { encodeObject } from 'voltaire-effect/primitives/Rlp'
|
|
28
|
+
*
|
|
29
|
+
* const encoded = Effect.runSync(encodeObject({
|
|
30
|
+
* name: new Uint8Array([65, 66, 67]),
|
|
31
|
+
* age: new Uint8Array([25])
|
|
32
|
+
* }))
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @since 0.0.1
|
|
36
|
+
*/
|
|
37
|
+
export const encodeObject = (
|
|
38
|
+
obj: Record<string, Encodable>,
|
|
39
|
+
): Effect.Effect<Uint8Array, RlpEncodingError> =>
|
|
40
|
+
Effect.try({
|
|
41
|
+
try: () => VoltaireRlp.encodeObject(obj),
|
|
42
|
+
catch: (e) =>
|
|
43
|
+
isRlpEncodingError(e)
|
|
44
|
+
? e
|
|
45
|
+
: new RlpEncodingErrorClass("RLP object encoding failed", {
|
|
46
|
+
cause: e instanceof Error ? e : undefined,
|
|
47
|
+
}),
|
|
48
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type BrandedRlp,
|
|
3
|
+
type RlpEncodingError,
|
|
4
|
+
RlpEncodingError as RlpEncodingErrorClass,
|
|
5
|
+
Rlp as VoltaireRlp,
|
|
6
|
+
} from "@tevm/voltaire/Rlp";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
|
|
9
|
+
type Encodable = Uint8Array | BrandedRlp | Encodable[];
|
|
10
|
+
|
|
11
|
+
const isRlpEncodingError = (e: unknown): e is RlpEncodingError =>
|
|
12
|
+
e instanceof RlpEncodingErrorClass ||
|
|
13
|
+
(e !== null &&
|
|
14
|
+
typeof e === "object" &&
|
|
15
|
+
"name" in e &&
|
|
16
|
+
e.name === "RlpEncodingError");
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Encodes a variadic list of items to RLP format.
|
|
20
|
+
*
|
|
21
|
+
* @param items - Items to encode
|
|
22
|
+
* @returns Effect that succeeds with RLP-encoded bytes or fails with RlpEncodingError
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import * as Effect from 'effect/Effect'
|
|
27
|
+
* import { encodeVariadic } from 'voltaire-effect/primitives/Rlp'
|
|
28
|
+
*
|
|
29
|
+
* const encoded = Effect.runSync(encodeVariadic(
|
|
30
|
+
* new Uint8Array([1, 2]),
|
|
31
|
+
* new Uint8Array([3, 4]),
|
|
32
|
+
* new Uint8Array([5, 6])
|
|
33
|
+
* ))
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @since 0.0.1
|
|
37
|
+
*/
|
|
38
|
+
export const encodeVariadic = (
|
|
39
|
+
...items: Encodable[]
|
|
40
|
+
): Effect.Effect<Uint8Array, RlpEncodingError> =>
|
|
41
|
+
Effect.try({
|
|
42
|
+
try: () => VoltaireRlp.encodeVariadic(...items),
|
|
43
|
+
catch: (e) =>
|
|
44
|
+
isRlpEncodingError(e)
|
|
45
|
+
? e
|
|
46
|
+
: new RlpEncodingErrorClass("RLP variadic encoding failed", {
|
|
47
|
+
cause: e instanceof Error ? e : undefined,
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type BrandedRlp, Rlp as VoltaireRlp } from "@tevm/voltaire/Rlp";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if two RLP Data structures are equal.
|
|
5
|
+
*
|
|
6
|
+
* @param data - First RLP data structure
|
|
7
|
+
* @param other - Second RLP data structure
|
|
8
|
+
* @returns True if structures are deeply equal
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { equals } from 'voltaire-effect/primitives/Rlp'
|
|
13
|
+
*
|
|
14
|
+
* const a = { type: 'bytes', value: new Uint8Array([1, 2]) }
|
|
15
|
+
* const b = { type: 'bytes', value: new Uint8Array([1, 2]) }
|
|
16
|
+
* equals(a, b) // => true
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @since 0.0.1
|
|
20
|
+
*/
|
|
21
|
+
export const equals = (data: BrandedRlp, other: BrandedRlp): boolean =>
|
|
22
|
+
VoltaireRlp.equals(data, other);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type BrandedRlp,
|
|
3
|
+
type RlpEncodingError,
|
|
4
|
+
RlpEncodingError as RlpEncodingErrorClass,
|
|
5
|
+
Rlp as VoltaireRlp,
|
|
6
|
+
} from "@tevm/voltaire/Rlp";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
|
|
9
|
+
const isRlpEncodingError = (e: unknown): e is RlpEncodingError =>
|
|
10
|
+
e instanceof RlpEncodingErrorClass ||
|
|
11
|
+
(e !== null &&
|
|
12
|
+
typeof e === "object" &&
|
|
13
|
+
"name" in e &&
|
|
14
|
+
e.name === "RlpEncodingError");
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates an RLP data structure from various inputs.
|
|
18
|
+
*
|
|
19
|
+
* @param value - Uint8Array (bytes), BrandedRlp, or array (list)
|
|
20
|
+
* @returns Effect that succeeds with RLP data structure or fails with RlpEncodingError
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import * as Effect from 'effect/Effect'
|
|
25
|
+
* import { from } from 'voltaire-effect/primitives/Rlp'
|
|
26
|
+
*
|
|
27
|
+
* const rlp = Effect.runSync(from(new Uint8Array([1, 2, 3])))
|
|
28
|
+
* // => { type: 'bytes', value: Uint8Array([1, 2, 3]) }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @since 0.0.1
|
|
32
|
+
*/
|
|
33
|
+
export const from = (
|
|
34
|
+
value: Uint8Array | BrandedRlp | BrandedRlp[],
|
|
35
|
+
): Effect.Effect<BrandedRlp, RlpEncodingError> =>
|
|
36
|
+
Effect.try({
|
|
37
|
+
try: () => VoltaireRlp.from(value),
|
|
38
|
+
catch: (e) =>
|
|
39
|
+
isRlpEncodingError(e)
|
|
40
|
+
? e
|
|
41
|
+
: new RlpEncodingErrorClass("RLP from failed", {
|
|
42
|
+
cause: e instanceof Error ? e : undefined,
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type BrandedRlp,
|
|
3
|
+
type RlpDecodingError,
|
|
4
|
+
RlpDecodingError as RlpDecodingErrorClass,
|
|
5
|
+
Rlp as VoltaireRlp,
|
|
6
|
+
} from "@tevm/voltaire/Rlp";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
|
|
9
|
+
const isRlpDecodingError = (e: unknown): e is RlpDecodingError =>
|
|
10
|
+
e instanceof RlpDecodingErrorClass ||
|
|
11
|
+
(e !== null &&
|
|
12
|
+
typeof e === "object" &&
|
|
13
|
+
"name" in e &&
|
|
14
|
+
e.name === "RlpDecodingError");
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Converts JSON representation back to RLP Data.
|
|
18
|
+
*
|
|
19
|
+
* @param json - JSON object from toJSON
|
|
20
|
+
* @returns Effect that succeeds with RLP data structure or fails with RlpDecodingError
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import * as Effect from 'effect/Effect'
|
|
25
|
+
* import { fromJSON } from 'voltaire-effect/primitives/Rlp'
|
|
26
|
+
*
|
|
27
|
+
* const json = { type: 'bytes', value: [1, 2, 3] }
|
|
28
|
+
* const data = Effect.runSync(fromJSON(json))
|
|
29
|
+
* // => { type: 'bytes', value: Uint8Array([1, 2, 3]) }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @since 0.0.1
|
|
33
|
+
*/
|
|
34
|
+
export const fromJSON = (
|
|
35
|
+
json: unknown,
|
|
36
|
+
): Effect.Effect<BrandedRlp, RlpDecodingError> =>
|
|
37
|
+
Effect.try({
|
|
38
|
+
try: () => VoltaireRlp.fromJSON(json),
|
|
39
|
+
catch: (e) =>
|
|
40
|
+
isRlpDecodingError(e)
|
|
41
|
+
? e
|
|
42
|
+
: new RlpDecodingErrorClass("RLP fromJSON failed", {
|
|
43
|
+
cause: e instanceof Error ? e : undefined,
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type BrandedRlp,
|
|
3
|
+
type RlpEncodingError,
|
|
4
|
+
RlpEncodingError as RlpEncodingErrorClass,
|
|
5
|
+
Rlp as VoltaireRlp,
|
|
6
|
+
} from "@tevm/voltaire/Rlp";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
|
|
9
|
+
type Encodable = Uint8Array | BrandedRlp | Encodable[];
|
|
10
|
+
|
|
11
|
+
const isRlpEncodingError = (e: unknown): e is RlpEncodingError =>
|
|
12
|
+
e instanceof RlpEncodingErrorClass ||
|
|
13
|
+
(e !== null &&
|
|
14
|
+
typeof e === "object" &&
|
|
15
|
+
"name" in e &&
|
|
16
|
+
e.name === "RlpEncodingError");
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Gets the total byte length of RLP-encoded data without actually encoding.
|
|
20
|
+
*
|
|
21
|
+
* @param data - Data to measure
|
|
22
|
+
* @returns Effect that succeeds with length in bytes after RLP encoding or fails with RlpEncodingError
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import * as Effect from 'effect/Effect'
|
|
27
|
+
* import { getEncodedLength } from 'voltaire-effect/primitives/Rlp'
|
|
28
|
+
*
|
|
29
|
+
* const bytes = new Uint8Array([1, 2, 3])
|
|
30
|
+
* const length = Effect.runSync(getEncodedLength(bytes))
|
|
31
|
+
* // => 4 (0x83 prefix + 3 bytes)
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @since 0.0.1
|
|
35
|
+
*/
|
|
36
|
+
export const getEncodedLength = (
|
|
37
|
+
data: Encodable,
|
|
38
|
+
): Effect.Effect<number, RlpEncodingError> =>
|
|
39
|
+
Effect.try({
|
|
40
|
+
try: () => VoltaireRlp.getEncodedLength(data),
|
|
41
|
+
catch: (e) =>
|
|
42
|
+
isRlpEncodingError(e)
|
|
43
|
+
? e
|
|
44
|
+
: new RlpEncodingErrorClass("getEncodedLength failed", {
|
|
45
|
+
cause: e instanceof Error ? e : undefined,
|
|
46
|
+
}),
|
|
47
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type RlpDecodingError,
|
|
3
|
+
RlpDecodingError as RlpDecodingErrorClass,
|
|
4
|
+
Rlp as VoltaireRlp,
|
|
5
|
+
} from "@tevm/voltaire/Rlp";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
|
|
8
|
+
const isRlpDecodingError = (e: unknown): e is RlpDecodingError =>
|
|
9
|
+
e instanceof RlpDecodingErrorClass ||
|
|
10
|
+
(e !== null &&
|
|
11
|
+
typeof e === "object" &&
|
|
12
|
+
"name" in e &&
|
|
13
|
+
e.name === "RlpDecodingError");
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Gets the total length of an RLP item (prefix + payload).
|
|
17
|
+
*
|
|
18
|
+
* @param data - RLP-encoded data
|
|
19
|
+
* @returns Effect that succeeds with total length in bytes or fails with RlpDecodingError
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import * as Effect from 'effect/Effect'
|
|
24
|
+
* import { getLength } from 'voltaire-effect/primitives/Rlp'
|
|
25
|
+
*
|
|
26
|
+
* const encoded = new Uint8Array([0x83, 1, 2, 3])
|
|
27
|
+
* const length = Effect.runSync(getLength(encoded))
|
|
28
|
+
* // => 4 (1 byte prefix + 3 bytes payload)
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @since 0.0.1
|
|
32
|
+
*/
|
|
33
|
+
export const getLength = (
|
|
34
|
+
data: Uint8Array,
|
|
35
|
+
): Effect.Effect<number, RlpDecodingError> =>
|
|
36
|
+
Effect.try({
|
|
37
|
+
try: () => VoltaireRlp.getLength(data),
|
|
38
|
+
catch: (e) =>
|
|
39
|
+
isRlpDecodingError(e)
|
|
40
|
+
? e
|
|
41
|
+
: new RlpDecodingErrorClass("getLength failed", {
|
|
42
|
+
cause: e instanceof Error ? e : undefined,
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
@@ -21,21 +21,44 @@
|
|
|
21
21
|
* |--------|-------|--------|
|
|
22
22
|
* | `Rlp.Schema` | Uint8Array | BrandedRlp |
|
|
23
23
|
*
|
|
24
|
-
* ##
|
|
24
|
+
* ## API Design
|
|
25
25
|
*
|
|
26
|
-
*
|
|
27
|
-
* - `
|
|
28
|
-
* - `
|
|
29
|
-
* - `
|
|
30
|
-
* - `
|
|
26
|
+
* ### Pure Functions (Direct Return)
|
|
27
|
+
* - `equals(a, b)` - boolean
|
|
28
|
+
* - `isData(value)` - boolean (type guard)
|
|
29
|
+
* - `isBytesData(value)` - boolean (type guard)
|
|
30
|
+
* - `isListData(value)` - boolean (type guard)
|
|
31
|
+
* - `isCanonical(bytes)` - boolean
|
|
32
|
+
* - `toJSON(data)` - unknown
|
|
33
|
+
* - `toRaw(data)` - Uint8Array | unknown[]
|
|
31
34
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
+
* ### Effect-Returning Functions (Fallible)
|
|
36
|
+
*
|
|
37
|
+
* Encoding:
|
|
38
|
+
* - `encode(data)` - Effect<Uint8Array, RlpEncodingError>
|
|
39
|
+
* - `encodeBytes(bytes)` - Effect<Uint8Array>
|
|
40
|
+
* - `encodeList(items)` - Effect<Uint8Array>
|
|
41
|
+
* - `encodeArray(items)` - Effect<Uint8Array>
|
|
42
|
+
* - `encodeObject(obj)` - Effect<Uint8Array, RlpEncodingError>
|
|
43
|
+
* - `encodeBatch(items)` - Effect<Uint8Array[], RlpEncodingError>
|
|
44
|
+
* - `encodeVariadic(...items)` - Effect<Uint8Array, RlpEncodingError>
|
|
45
|
+
*
|
|
46
|
+
* Decoding:
|
|
47
|
+
* - `decode(bytes)` - Effect<Decoded, RlpDecodingError>
|
|
48
|
+
* - `decodeArray(bytes)` - Effect<unknown[], RlpDecodingError>
|
|
49
|
+
* - `decodeObject(bytes)` - Effect<Record<string, unknown>, RlpDecodingError>
|
|
50
|
+
* - `decodeValue(bytes)` - Effect<Uint8Array | unknown[], RlpDecodingError>
|
|
51
|
+
* - `decodeBatch(items)` - Effect<unknown[][], RlpDecodingError>
|
|
35
52
|
*
|
|
36
53
|
* Utilities:
|
|
37
|
-
* - `
|
|
38
|
-
* - `
|
|
54
|
+
* - `from(value)` - Effect<BrandedRlp, RlpEncodingError>
|
|
55
|
+
* - `fromJSON(json)` - Effect<BrandedRlp, RlpDecodingError>
|
|
56
|
+
* - `flatten(data)` - Effect<Array<BrandedRlp & { type: "bytes" }>>
|
|
57
|
+
* - `validate(bytes)` - Effect<boolean>
|
|
58
|
+
* - `isList(bytes)` - Effect<boolean, RlpDecodingError>
|
|
59
|
+
* - `isString(bytes)` - Effect<boolean, RlpDecodingError>
|
|
60
|
+
* - `getLength(bytes)` - Effect<number, RlpDecodingError>
|
|
61
|
+
* - `getEncodedLength(data)` - Effect<number, RlpEncodingError>
|
|
39
62
|
*
|
|
40
63
|
* @example Schema usage
|
|
41
64
|
* ```typescript
|
|
@@ -62,13 +85,43 @@
|
|
|
62
85
|
* @since 0.1.0
|
|
63
86
|
*/
|
|
64
87
|
|
|
88
|
+
// Type exports
|
|
65
89
|
export type { BrandedRlp } from "@tevm/voltaire/Rlp";
|
|
66
|
-
|
|
67
|
-
|
|
90
|
+
|
|
91
|
+
// Schema and errors
|
|
92
|
+
export { RlpDecodingError, RlpEncodingError, Schema } from "./RlpSchema.js";
|
|
93
|
+
|
|
94
|
+
// Pure functions (direct return)
|
|
95
|
+
export { equals } from "./equals.js";
|
|
96
|
+
export { isCanonical } from "./isCanonical.js";
|
|
97
|
+
export { isBytesData } from "./isBytesData.js";
|
|
98
|
+
export { isData } from "./isData.js";
|
|
99
|
+
export { isListData } from "./isListData.js";
|
|
100
|
+
export { toJSON } from "./toJSON.js";
|
|
101
|
+
export { toRaw } from "./toRaw.js";
|
|
102
|
+
|
|
103
|
+
// Effect-returning encoding functions
|
|
68
104
|
export { encode } from "./encode.js";
|
|
69
105
|
export { encodeArray } from "./encodeArray.js";
|
|
106
|
+
export { encodeBatch } from "./encodeBatch.js";
|
|
70
107
|
export { encodeBytes } from "./encodeBytes.js";
|
|
71
108
|
export { encodeList } from "./encodeList.js";
|
|
109
|
+
export { encodeObject } from "./encodeObject.js";
|
|
110
|
+
export { encodeVariadic } from "./encodeVariadic.js";
|
|
111
|
+
|
|
112
|
+
// Effect-returning decoding functions
|
|
113
|
+
export { type Decoded, decode } from "./decode.js";
|
|
114
|
+
export { decodeArray } from "./decodeArray.js";
|
|
115
|
+
export { decodeBatch } from "./decodeBatch.js";
|
|
116
|
+
export { decodeObject } from "./decodeObject.js";
|
|
117
|
+
export { decodeValue } from "./decodeValue.js";
|
|
118
|
+
|
|
119
|
+
// Effect-returning utility functions
|
|
72
120
|
export { flatten } from "./flatten.js";
|
|
73
|
-
export {
|
|
121
|
+
export { from } from "./from.js";
|
|
122
|
+
export { fromJSON } from "./fromJSON.js";
|
|
123
|
+
export { getEncodedLength } from "./getEncodedLength.js";
|
|
124
|
+
export { getLength } from "./getLength.js";
|
|
125
|
+
export { isList } from "./isList.js";
|
|
126
|
+
export { isString } from "./isString.js";
|
|
74
127
|
export { validate } from "./validate.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type BrandedRlp, Rlp as VoltaireRlp } from "@tevm/voltaire/Rlp";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if value is RLP bytes data.
|
|
5
|
+
*
|
|
6
|
+
* @param value - Value to check
|
|
7
|
+
* @returns True if value is RLP bytes data structure
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { isBytesData } from 'voltaire-effect/primitives/Rlp'
|
|
12
|
+
*
|
|
13
|
+
* isBytesData({ type: 'bytes', value: new Uint8Array([1]) }) // => true
|
|
14
|
+
* isBytesData({ type: 'list', value: [] }) // => false
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @since 0.0.1
|
|
18
|
+
*/
|
|
19
|
+
export const isBytesData = (
|
|
20
|
+
value: unknown,
|
|
21
|
+
): value is BrandedRlp & { type: "bytes" } => VoltaireRlp.isBytesData(value);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Rlp as VoltaireRlp } from "@tevm/voltaire/Rlp";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Validates if RLP encoding is canonical.
|
|
5
|
+
*
|
|
6
|
+
* Canonical encoding rules:
|
|
7
|
+
* - Integers must use minimum bytes (no leading zeros)
|
|
8
|
+
* - Strings/bytes must use shortest length prefix
|
|
9
|
+
* - Single byte < 0x80 must not be encoded as string
|
|
10
|
+
* - Length prefix must use minimum bytes
|
|
11
|
+
*
|
|
12
|
+
* @param bytes - RLP-encoded data
|
|
13
|
+
* @param depth - Current recursion depth (internal)
|
|
14
|
+
* @returns True if encoding is canonical
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { isCanonical } from 'voltaire-effect/primitives/Rlp'
|
|
19
|
+
*
|
|
20
|
+
* // Canonical encoding
|
|
21
|
+
* const canonical = new Uint8Array([0x83, 0x64, 0x6f, 0x67]) // "dog"
|
|
22
|
+
* isCanonical(canonical) // => true
|
|
23
|
+
*
|
|
24
|
+
* // Non-canonical: single byte should not be prefixed
|
|
25
|
+
* const nonCanonical = new Uint8Array([0x81, 0x7f]) // should be just 0x7f
|
|
26
|
+
* isCanonical(nonCanonical) // => false
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @since 0.0.1
|
|
30
|
+
*/
|
|
31
|
+
export const isCanonical = (bytes: Uint8Array, depth?: number): boolean =>
|
|
32
|
+
VoltaireRlp.isCanonical(bytes, depth);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type BrandedRlp, Rlp as VoltaireRlp } from "@tevm/voltaire/Rlp";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if value is an RLP Data structure.
|
|
5
|
+
*
|
|
6
|
+
* @param value - Value to check
|
|
7
|
+
* @returns True if value is valid RLP data structure
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { isData } from 'voltaire-effect/primitives/Rlp'
|
|
12
|
+
*
|
|
13
|
+
* isData({ type: 'bytes', value: new Uint8Array([1]) }) // => true
|
|
14
|
+
* isData({ type: 'list', value: [] }) // => true
|
|
15
|
+
* isData('invalid') // => false
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @since 0.0.1
|
|
19
|
+
*/
|
|
20
|
+
export const isData = (value: unknown): value is BrandedRlp =>
|
|
21
|
+
VoltaireRlp.isData(value);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type RlpDecodingError,
|
|
3
|
+
RlpDecodingError as RlpDecodingErrorClass,
|
|
4
|
+
Rlp as VoltaireRlp,
|
|
5
|
+
} from "@tevm/voltaire/Rlp";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
|
|
8
|
+
const isRlpDecodingError = (e: unknown): e is RlpDecodingError =>
|
|
9
|
+
e instanceof RlpDecodingErrorClass ||
|
|
10
|
+
(e !== null &&
|
|
11
|
+
typeof e === "object" &&
|
|
12
|
+
"name" in e &&
|
|
13
|
+
e.name === "RlpDecodingError");
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Checks if RLP-encoded data represents a list.
|
|
17
|
+
*
|
|
18
|
+
* @param data - RLP-encoded data
|
|
19
|
+
* @returns Effect that succeeds with boolean or fails with RlpDecodingError
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import * as Effect from 'effect/Effect'
|
|
24
|
+
* import { isList } from 'voltaire-effect/primitives/Rlp'
|
|
25
|
+
*
|
|
26
|
+
* const list = new Uint8Array([0xc3, 0x01, 0x02, 0x03])
|
|
27
|
+
* Effect.runSync(isList(list)) // => true
|
|
28
|
+
*
|
|
29
|
+
* const bytes = new Uint8Array([0x83, 0x01, 0x02, 0x03])
|
|
30
|
+
* Effect.runSync(isList(bytes)) // => false
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @since 0.0.1
|
|
34
|
+
*/
|
|
35
|
+
export const isList = (
|
|
36
|
+
data: Uint8Array,
|
|
37
|
+
): Effect.Effect<boolean, RlpDecodingError> =>
|
|
38
|
+
Effect.try({
|
|
39
|
+
try: () => VoltaireRlp.isList(data),
|
|
40
|
+
catch: (e) =>
|
|
41
|
+
isRlpDecodingError(e)
|
|
42
|
+
? e
|
|
43
|
+
: new RlpDecodingErrorClass("isList check failed", {
|
|
44
|
+
cause: e instanceof Error ? e : undefined,
|
|
45
|
+
}),
|
|
46
|
+
});
|