bip136
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

bip136js

GitHub Actions Build Coverage Security Rating Reliability Rating Maintainability RatingLines of Code Socket Badge License: ISC

A javascript library for encoding and decoding BIP 136 TxRefs. This package passes all test cases from the spec.

This library goes beyond the spec to attempt to decode TxRefs that have had the Human-Readable Part (HRP) stripped off but are otherwise valid.

Installation

npm i bip136

Usage

import * as bip136 from 'bip136';

// decodes TxRefs with separators
bip136.decode('tx1:r29u-mqjx-putt-3p0');
// { network: 'mainnet', blockHeight: 456789, txIndex: 1234 }

// decodes TxRefs without separators
bip136.decode('TX1R29UMQJXPUTT3P0');
// { network: 'mainnet', blockHeight: 456789, txIndex: 1234 }

// decodes TxRefs with invalid characters
bip136.decode('tx1!r29u/mqj*x-putt^^3p0');
// { network: 'mainnet', blockHeight: 456789, txIndex: 1234 }

// decodes TxRefs with outpoints
bip136.decode('tx1:y7ll-llll-lpqq-s4qz-hw');
// { network: 'mainnet', blockHeight: 16777215, txIndex: 32767, outpoint: 1 }

// decodes TxRefs with the HRP stripped off
bip136.decode('xz8e-kyyp-qmff-zyt');
// { network: 'testnet', blockHeight: 2470513, txIndex: 36 }

// encodes TxRefs
bip136.encode({
  blockHeight: 709635,
  txIndex: 60,
});
// 'tx1:rxq2-tpup-q0nd-lah'

Package Sidebar

Install

npm i bip136

Weekly Downloads

4

Version

1.0.2

License

ISC

Unpacked Size

11.4 kB

Total Files

5

Last publish

Collaborators

  • sangaman