Skip to main content
import * as Rlp from 'voltaire-effect/primitives/Rlp'
import { Effect } from 'effect'

const encoded = Effect.runSync(Rlp.encode(new Uint8Array([1, 2, 3])))

Schema

Schema — Validates RLP-encoded data.
import * as S from 'effect/Schema'
const rlp = S.decodeSync(Rlp.Schema)(rlpBytes)

Pure Functions

equals(a, b) — Checks if two RLP Data structures are equal. isData(value) — Type guard for RLP data structure. isBytesData(value) — Type guard for RLP bytes data. isListData(value) — Type guard for RLP list data. isCanonical(bytes) — Validates canonical RLP encoding. toJSON(data) — Converts RLP Data to JSON format. toRaw(data) — Converts RLP Data to raw JavaScript values.

Encoding Functions

encode(data) — RLP-encodes bytes or nested arrays.
Rlp.encode(new Uint8Array([1, 2, 3]))
Rlp.encode([
  new Uint8Array([1]),
  [new Uint8Array([2]), new Uint8Array([3])]
])
encodeBytes(bytes) — Encodes a single byte array. encodeList(items) — Encodes a list of items. encodeArray(items) — Encodes array to RLP bytes. encodeObject(obj) — Encodes key-value pairs to RLP. encodeBatch(items) — Encodes multiple items efficiently. encodeVariadic(…items) — Encodes variadic arguments as list.

Decoding Functions

decode(bytes, stream?) — RLP-decodes bytes. Returns { data, remainder }.
const { data, remainder } = Effect.runSync(Rlp.decode(rlpBytes))
decodeArray(bytes) — Decodes to array. decodeObject(bytes) — Decodes to object with string keys. decodeValue(bytes) — Decodes and returns value directly (no metadata). decodeBatch(items) — Decodes multiple items.

Utility Functions

from(value) — Creates RLP data structure from input. fromJSON(json) — Converts JSON back to RLP Data. flatten(data) — Flattens nested RLP to array of bytes. validate(bytes) — Checks if bytes are valid RLP. isList(bytes) — Checks if RLP represents a list. isString(bytes) — Checks if RLP represents a string. getLength(bytes) — Gets total RLP item length. getEncodedLength(data) — Predicts encoded length without encoding.

Types

type BrandedRlp = { type: 'bytes'; value: Uint8Array } | { type: 'list'; value: BrandedRlp[] }
interface Decoded { data: BrandedRlp; remainder: Uint8Array }

Errors

  • RlpEncodingError — Encoding failed
  • RlpDecodingError — Invalid prefix, insufficient bytes, non-canonical encoding