npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rgb-lninvoice-decoder

v1.0.5

Published

JavaScript library to parse RGB Lightning Network invoices compatible with rgb-lightning-node decodelninvoice API

Readme

RGB Lightning Invoice Decoder

A JavaScript library for parsing RGB Lightning Network invoices, compatible with the rgb-lightning-node decodelninvoice API.

Features

  • ✅ Supports RGB Lightning Invoice parsing
  • ✅ Compatible with rgb-lightning-node API format
  • ✅ Supports multiple module formats (ES Modules, CommonJS, UMD, IIFE)
  • ✅ Works in both Node.js and browser environments
  • ✅ TypeScript type support (coming soon)
  • ✅ Comprehensive test coverage

Installation

# Using yarn
yarn add rgb-lninvoice-decoder

# Using npm
npm install rgb-lninvoice-decoder

Usage

Node.js (ES Modules)

// Using the primary function names
import { decodeRGBLNInvoice, isValidRGBLNInvoice } from 'rgb-lninvoice-decoder';

// Or using compatibility aliases
import { decodeLNInvoice, isValidLNInvoice } from 'rgb-lninvoice-decoder';

const invoice = "lnbcrt30u1p5zlun0...";

// Validate invoice
const isValid = isValidRGBLNInvoice(invoice);
console.log('Invoice is valid:', isValid);

// Decode invoice
const decoded = decodeRGBLNInvoice(invoice);
console.log('Decoded invoice:', decoded);

Node.js (CommonJS)

const { decodeRGBLNInvoice, isValidRGBLNInvoice } = require('rgb-lninvoice-decoder');

const invoice = "lnbcrt30u1p5zlun0...";

// Validate invoice
const isValid = isValidRGBLNInvoice(invoice);
console.log('Invoice is valid:', isValid);

// Decode invoice
const decoded = decodeRGBLNInvoice(invoice);
console.log('Decoded invoice:', decoded);

Browser (UMD)

<!DOCTYPE html>
<html>
<head>
    <script src="https://unpkg.com/[email protected]/lib/index.js"></script>
    <script src="https://unpkg.com/rgb-lninvoice-decoder/dist/rgb-lninvoice-decoder.umd.js"></script>
</head>
<body>
    <script>
        const invoice = "lnbcrt30u1p5zlun0...";
        
        // Validate invoice
        const isValid = RGBLNInvoiceDecoder.isValidRGBLNInvoice(invoice);
        console.log('Invoice is valid:', isValid);
        
        // Decode invoice
        const decoded = RGBLNInvoiceDecoder.decodeRGBLNInvoice(invoice);
        console.log('Decoded invoice:', decoded);
    </script>
</body>
</html>

React/Vue/Other Frontend Frameworks

import { decodeRGBLNInvoice, isValidRGBLNInvoice } from 'rgb-lninvoice-decoder';

function MyComponent() {
  const handleDecodeInvoice = (invoice) => {
    try {
      if (isValidRGBLNInvoice(invoice)) {
        const decoded = decodeRGBLNInvoice(invoice);
        console.log('Decoded:', decoded);
      }
    } catch (error) {
      console.error('Error:', error.message);
    }
  };

  return (
    // Your component JSX
  );
}

API Reference

decodeRGBLNInvoice(invoice: string): Object

Parses an RGB Lightning Invoice and returns structured data.

Parameters:

  • invoice (string): The BOLT 11 Lightning Invoice string

Returns:

{
  amt_msat: number,           // Amount in millisatoshis
  expiry_sec: number,         // Expiry time in seconds
  timestamp: number,          // Timestamp of creation
  asset_id: string | null,    // RGB asset ID
  asset_amount: number | null, // Quantity of the RGB asset
  payment_hash: string,       // Payment hash
  payment_secret: string,     // Payment secret
  payee_pubkey: string,       // Payee's public key
  network: string             // Network type
}

isValidRGBLNInvoice(invoice: string): boolean

Validates the format of a Lightning Invoice.

Parameters:

  • invoice (string): The BOLT 11 Lightning Invoice string to validate

Returns:

  • boolean: true if the invoice format is valid, false otherwise

Development

Building the library

# Install dependencies
yarn install

# Build the library
yarn build

# Development mode (watches for file changes)
yarn dev

Testing

# Run tests
yarn test

# Test ES Modules example
node examples/node-esm.js

# Test CommonJS example
node examples/node-cjs.cjs

Build Output

After building, the dist/ directory will contain the following files:

  • rgb-lninvoice-decoder.mjs - ES Modules format
  • rgb-lninvoice-decoder.cjs - CommonJS format
  • rgb-lninvoice-decoder.umd.js - UMD format (for browsers)
  • rgb-lninvoice-decoder.iife.js - IIFE format (for direct browser use)
  • Corresponding source map files

Dependencies

  • bech32 - Bech32 encoding/decoding library

License

MIT License

Contribution

Feel free to open Issues and Pull Requests!

Changelog

v1.0.2

  • Added compatibility exports: decodeLNInvoice and isValidLNInvoice as aliases
  • Fixed issue with direct imports from dist directory

v1.0.1

  • Added support for direct imports from dist directory

v1.0.0

  • Initial release
  • Support for RGB Lightning Invoice parsing
  • Multi-module format support
  • Node.js and browser compatibility