Skip to content

Latest commit

 

History

History
16 lines (15 loc) · 1.06 KB

README.md

File metadata and controls

16 lines (15 loc) · 1.06 KB

RLP Encoder

A 0-depnedency simple RLP encoder that only encodes Uint8Arrays and arrays of them (including nested). It is up to the user to appropriately convert their numbers, bigints, strings, etc. into Uint8Arrays since the RLP specification does not prescribe how such things are encoded prior to being RLP encoded.

Usage

npm install @zoltu/rlp-encoder
const input = [
	[new Uint8Array([0x6b, 0x65, 0x79, 0x31]), new Uint8Array([0x76, 0x61, 0x6c, 0x31])],
	[new Uint8Array([0x6b, 0x65, 0x79, 0x32]), new Uint8Array([0x76, 0x61, 0x6c, 0x32])],
	[new Uint8Array([0x6b, 0x65, 0x79, 0x33]), new Uint8Array([0x76, 0x61, 0x6c, 0x33])],
	[new Uint8Array([0x6b, 0x65, 0x79, 0x34]), new Uint8Array([0x76, 0x61, 0x6c, 0x34])],
]
const actual = rlpEncode(input) // [0xec, 0xca, 0x84, 0x6b, 0x65, 0x79, 0x31, 0x84, 0x76, 0x61, 0x6c, 0x31, 0xca, 0x84, 0x6b, 0x65, 0x79, 0x32, 0x84, 0x76, 0x61, 0x6c, 0x32, 0xca, 0x84, 0x6b, 0x65, 0x79, 0x33, 0x84, 0x76, 0x61, 0x6c, 0x33, 0xca, 0x84, 0x6b, 0x65, 0x79, 0x34, 0x84, 0x76, 0x61, 0x6c, 0x34] as Uint8Array