@tevm/voltaire / primitives/Rlp
primitives/Rlp
Classes
Error
Defined in: src/primitives/Rlp/errors.js:6Extends
Error
Constructors
Constructor
new Error(Defined in: src/primitives/Rlp/errors.js:11type,message?):Error
Parameters
type
ErrorType
message?
string
Returns
Error
Overrides
globalThis.Error.constructor
Properties
name
name: string
Defined in: src/primitives/Rlp/errors.js:13
Inherited from
globalThis.Error.name
type
type: ErrorType
Defined in: src/primitives/Rlp/errors.js:14
Type Aliases
BrandedRlp
BrandedRlp = {Defined in: src/primitives/Rlp/RlpType.ts:4 Branded RLP data typetype:"bytes";value:Uint8Array; } | {type:"list";value:BrandedRlp[]; }
Encodable
Encodable =Defined in: src/primitives/Rlp/RlpType.ts:11 Type that can be RLP-encodedUint8Array|BrandedRlp|Encodable[]
ErrorType
ErrorType<> =Defined in: src/primitives/Rlp/errors.js:2"InputTooShort"|"InputTooLong"|"LeadingZeros"|"NonCanonicalSize"|"InvalidLength"|"UnexpectedInput"|"InvalidRemainder"|"ExtraZeros"|"RecursionDepthExceeded"
Type Parameters
Variables
MAX_DEPTH
Defined in: src/primitives/Rlp/constants.js:13 Maximum recursion depth to prevent stack overflow attacksconstMAX_DEPTH:number=32
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Example
RlpError
Defined in: src/primitives/Rlp/errors.js:19constRlpError: typeofError=Error
Functions
decode()
decode(Defined in: src/primitives/Rlp/decode.js:75 Decodes RLP-encoded bytesbytes,stream?):Decoded
Parameters
bytes
Uint8Array<ArrayBufferLike>
RLP-encoded data
stream?
boolean = false
If true, allows extra data after decoded value. If false, expects exact match
Returns
Decoded
Decoded RLP data with remainder
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
If input is too short, invalid, or has unexpected remainder (when stream=false)Example
decodeArray()
decodeArray(Defined in: src/primitives/Rlp/decodeArray.js:23 Decodes RLP-encoded bytes to an arraydata):any[]
Parameters
data
Uint8Array<ArrayBufferLike>
RLP-encoded data
Returns
any[]
Decoded array
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
If decoding failsExample
decodeBatch()
decodeBatch(Defined in: src/primitives/Rlp/decodeBatch.js:23 Decodes multiple RLP-encoded itemsdata):any[][]
Parameters
data
Uint8Array<ArrayBufferLike>[]
Array of RLP-encoded data
Returns
any[][]
Array of decoded results
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
If decoding fails for any itemExample
decodeObject()
decodeObject(Defined in: src/primitives/Rlp/decodeObject.js:20 Decodes RLP-encoded bytes to an object with known keysdata):Record<string,any>
Parameters
data
Uint8Array<ArrayBufferLike>
RLP-encoded data
Returns
Record<string, any>
Decoded object
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
If decoding fails or data format is invalidExample
encode()
encode(Defined in: src/primitives/Rlp/encode.js:47 Encodes data to RLP formatdata):Uint8Array<ArrayBufferLike>
Parameters
data
Encodable
Data to encode (Uint8Array, RlpData, or array)
Returns
Uint8Array<ArrayBufferLike>
RLP-encoded bytes
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
If data type is invalid or encoding failsExample
encodeArray()
encodeArray(Defined in: src/primitives/Rlp/encodeArray.js:25 Encodes an array of values to RLP formatitems):Uint8Array<ArrayBufferLike>
Parameters
items
Encodable[]
Array of values to encode
Returns
Uint8Array<ArrayBufferLike>
RLP-encoded bytes
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
If encoding failsExample
encodeBatch()
encodeBatch(Defined in: src/primitives/Rlp/encodeBatch.js:26 Encodes multiple items efficientlyitems):Uint8Array<ArrayBufferLike>[]
Parameters
items
Encodable[][]
Array of items to encode
Returns
Uint8Array<ArrayBufferLike>[]
Array of RLP-encoded results
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
If encoding fails for any itemExample
encodeBytes()
encodeBytes(Defined in: src/primitives/Rlp/encodeBytes.js:30 Encodes a byte array according to RLP string rulesbytes):Uint8Array<ArrayBufferLike>
Parameters
bytes
Uint8Array<ArrayBufferLike>
Byte array to encode
Returns
Uint8Array<ArrayBufferLike>
RLP-encoded bytes
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
If encoding failsExample
encodeList()
encodeList(Defined in: src/primitives/Rlp/encodeList.js:29 Encodes a list of RLP-encodable itemsitems):Uint8Array<ArrayBufferLike>
Parameters
items
(any[] | Uint8Array<ArrayBufferLike> | BrandedRlp)[]
Array of items to encode
Returns
Uint8Array<ArrayBufferLike>
RLP-encoded list
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
If encoding failsExample
encodeObject()
encodeObject(Defined in: src/primitives/Rlp/encodeObject.js:26 Encodes an object (key-value pairs) to RLP format Converts object to array of [key, value] pairs and encodesobj):Uint8Array<ArrayBufferLike>
Parameters
obj
Record<string, Encodable>
Object to encode
Returns
Uint8Array<ArrayBufferLike>
RLP-encoded bytes
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
If encoding failsExample
encodeVariadic()
encodeVariadic(…Defined in: src/primitives/Rlp/encodeVariadic.js:25 Encodes a variadic list of items to RLP formatitems):Uint8Array<ArrayBufferLike>
Parameters
items
…Encodable[]
Items to encode
Returns
Uint8Array<ArrayBufferLike>
RLP-encoded bytes
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
If encoding failsExample
equals()
equals(Defined in: src/primitives/Rlp/equals.js:19 Check if two RLP Data structures are equaldata,other):boolean
Parameters
data
BrandedRlp
First RLP data structure
other
BrandedRlp
Second RLP data structure
Returns
boolean
True if structures are deeply equal
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
Example
flatten()
flatten(Defined in: src/primitives/Rlp/flatten.js:29 Flatten nested list Data into array of bytes Data (depth-first)data):BrandedRlp&object[]
Parameters
data
BrandedRlp
RLP data structure to flatten
Returns
BrandedRlp & object[]
Array of bytes data (all nested lists flattened)
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
Example
from()
from(Defined in: src/primitives/Rlp/from.js:20 Create RLP data from various inputsvalue):BrandedRlp
Parameters
value
Uint8Array (bytes), RlpData, or array (list)Uint8Array<ArrayBufferLike> | BrandedRlp | BrandedRlp[]
Returns
BrandedRlp
RLP data structure
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
If input type is invalidExample
fromJSON()
fromJSON(Defined in: src/primitives/Rlp/fromJSON.js:19 Convert JSON representation back to RLP Datajson):BrandedRlp
Parameters
json
unknown
JSON object from toJSON
Returns
BrandedRlp
RLP data structure
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
If JSON format is invalid or type is unrecognizedExample
getEncodedLength()
getEncodedLength(Defined in: src/primitives/Rlp/getEncodedLength.js:21 Get the total byte length of RLP-encoded data without actually encodingdata):number
Parameters
data
Data to measureany[] | Uint8Array<ArrayBufferLike> | BrandedRlp
Returns
number
Length in bytes after RLP encoding
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
If data type is invalidExample
getLength()
getLength(Defined in: src/primitives/Rlp/getLength.js:20 Gets the total length of an RLP item (prefix + payload)data):number
Parameters
data
Uint8Array<ArrayBufferLike>
RLP-encoded data
Returns
number
Total length in bytes
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
If data is empty, too short, or has invalid prefixExample
isBytesData()
isBytesData(Defined in: src/primitives/Rlp/isBytesData.js:20 Check if value is RLP bytes datavalue):boolean
Parameters
value
unknown
Value to check
Returns
boolean
True if value is RLP bytes data structure
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
Example
isCanonical()
isCanonical(Defined in: src/primitives/Rlp/isCanonical.js:34 Validates if RLP encoding is canonical Canonical encoding rules:bytes,depth?):boolean
- Integers must use minimum bytes (no leading zeros)
- Strings/bytes must use shortest length prefix
- Single byte < 0x80 must not be encoded as string
- Length prefix must use minimum bytes
Parameters
bytes
Uint8Array<ArrayBufferLike>
RLP-encoded data
depth?
number = 0
Current recursion depth (internal)
Returns
boolean
True if encoding is canonical
See
- https://voltaire.tevm.sh/primitives/rlp for RLP documentation
- https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/ for canonical rules
Since
0.0.0Throws
Example
isData()
isData(Defined in: src/primitives/Rlp/isData.js:20 Check if value is RLP Data structurevalue):value is BrandedRlp
Parameters
value
unknown
Value to check
Returns
value is BrandedRlp
True if value is valid RLP data structure
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
Example
isList()
isList(Defined in: src/primitives/Rlp/isList.js:23 Checks if RLP-encoded data represents a listdata):boolean
Parameters
data
Uint8Array<ArrayBufferLike>
RLP-encoded data
Returns
boolean
True if data encodes a list
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
If data is emptyExample
isListData()
isListData(Defined in: src/primitives/Rlp/isListData.js:20 Check if value is RLP list datavalue):boolean
Parameters
value
unknown
Value to check
Returns
boolean
True if value is RLP list data structure
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
Example
isString()
isString(Defined in: src/primitives/Rlp/isString.js:23 Checks if RLP-encoded data represents a string (byte array)data):boolean
Parameters
data
Uint8Array<ArrayBufferLike>
RLP-encoded data
Returns
boolean
True if data encodes a string
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
If data is emptyExample
Rlp()
Rlp(Defined in: src/primitives/Rlp/index.ts:20 Creates an RLP data structure from various inputsvalue):BrandedRlp
Parameters
value
RlpInput
Uint8Array, BrandedRlp, or array to convert
Returns
BrandedRlp
BrandedRlp data structure
Example
toJSON()
toJSON(Defined in: src/primitives/Rlp/toJSON.js:17 Convert RLP Data to human-readable JSON formatdata):unknown
Parameters
data
BrandedRlp
RLP data structure
Returns
unknown
JSON-serializable representation
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
Example
toRaw()
toRaw(Defined in: src/primitives/Rlp/toRaw.js:27 Converts RLP Data structure to raw JavaScript values (Uint8Array or nested arrays)data):any[] |Uint8Array<ArrayBufferLike>
Parameters
data
BrandedRlp
RLP data structure to convert
Returns
any[] | Uint8Array<ArrayBufferLike>
Raw value (Uint8Array for bytes, array for list)
See
https://voltaire.tevm.sh/primitives/rlp for RLP documentationSince
0.0.0Throws
Example
validate()
validate(Defined in: src/primitives/Rlp/validate.js:21 Validates if data is valid RLP encodingdata):boolean
Parameters
data
Uint8Array<ArrayBufferLike>
Data to validate
Returns
boolean
True if valid RLP encoding

