Skip to content

Dependency free library for RLP encoding Uint8Arrays.

License

Notifications You must be signed in to change notification settings

Zoltu/rlp-encoder

Repository files navigation

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

About

Dependency free library for RLP encoding Uint8Arrays.

Resources

License

Stars

Watchers

Forks

Packages

No packages published