rlp-kind

Bindings for Kind's implementation of RLP encoding.

Usage no npm install needed!

<script type="module">
  import rlpKind from 'https://cdn.skypack.dev/rlp-kind';
</script>

README

rlp-kind

Node.js wrapper for the RLP Encoding library written in Kind.

We provide a proof to ensure that all encoded RLPs will be correctly decoded in the underlying implementation.

DEMO.

Install

npm install --save rlp-kind
yarn add rlp-kind

Install globally if you want to use the CLI:

npm install -g rlp-kind
yarn global add rlp-kind

Usage

API

import * as assert from 'assert'
import * as rlp from 'rlp-kind'

const nestedList = [[], [[]], [[], [[]]]]
const encoded = rlp.encode(nestedList)
const decoded = rlp.decode(encoded)
assert.deepEqual(nestedList, decoded)

encode

encode(input: InputTree): Buffer

RLP encodes a tree of data (Buffers, Strings etc) and returns a Buffer.

decode

decode(input: Input): BufferTree

Decodes an RLP encoded Buffer, String etc and returns a tree of Buffers.

The input will be converted to a buffer.

Types

type Input =
  | Buffer
  | string
  | number
  | bigint
  | Uint8Array
  | BN
  | null

type InputTree =
  | InputTree[]
  | Input
type BufferTree = Buffer | BufferTree[]

CLI

$ rlp encode '[ 5 ]'
c105
$ rlp decode '0xc105'
[ '05' ]