bolt01

2.0.0 • Public • Published

BOLT 01

npm version

Methods relating to Lightning Network BOLT 01.

decodeBigSize

Given BOLT 01 "BigSize" bytes, return a corresponding numeric value

{
  encoded: <BigSize Encoded Value Hex String>
}

@throws
<Error>

@returns
{
  decoded: <Decoded Number String>
  length: <Encoding Byte Length Number>
}

Example:

const {decodeBigSize} = require('bolt01');

// Decode a zero value BigSize number
const {decoded} = decodeBigSize({encoded: '00'});

decodeTlvRecord

Decode an encoded TLV record

{
  encoded: <Encoded TLV Record Hex String>
  [offset]: <Record Offset By Bytes Number>
}

@throws
<Error>

@returns
{
  length: <Total Record Byte Length Number>
  type: <Message Type Number String>
  value: <Raw Value Hex String>
}

Example:

const {decodeTlvRecord} = require('bolt01');

// Type '1' and value '01'
const {type, value} = decodeTlvRecord({encoded: '010101'});

decodeTlvStream

Decode a TLV stream as key value pairs

{
  encoded: <TLV Records Stream Hex Encoded String>
}

@throws
<Error>

@returns
{
  records: [{
    type: <Message Type Number String>
    value: <Raw Value Hex String>
  }]
}

Example:

const {decodeTlvStream} = require('bolt01');

// {records: [{type: '1', value: '01}]}
const {records} = decodeTlvRecord({encoded: '010101'});

encodeBigSize

Given a numeric value, encode it as BOLT 01 "BigSize" bytes

{
  number: <Number String>
}

@throws
<Error>

@returns
{
  encoded: <BigSize Encoded Value Hex String>
}

Example:

const {encodeBigSize} = require('bolt01');

// Encode a zero value BigSize number
const {encoded} = encodeBigSize({number: '0'});

encodeTlvRecord

Encode data as a TLV record

{
  type: <Message Type Number String>
  value: <Raw Value Hex String>
}

@throws
<Error>

@returns
{
  encoded: <Encoded TLV Record Hex String>
}

Example:

const {encodeTlvRecord} = require('bolt01');

// encoded: '010101'
const {encoded} = encodeTlvRecord({type: '1', value: '01'});

encodeTlvStream

Encode key value pairs as a TLV stream

{
  records: [{
    type: <Message Type Number String>
    value: <Raw Value Hex String>
  }]
}

@throws
<Error>

@returns
{
  encoded: <TLV Records Stream Hex Encoded String>
}

Example:

const {encodeTlvStream} = require('bolt01');

// encoded: '010101'
const {encoded} = encodeTlvStream({records: [{type: '1', value: '01'}]});

Readme

Keywords

Package Sidebar

Install

npm i bolt01

Weekly Downloads

114

Version

2.0.0

License

MIT

Unpacked Size

27.5 kB

Total Files

25

Last publish

Collaborators

  • alexbosworth