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 🙏

© 2024 – Pkg Stats / Ryan Hefner

invoices

v3.0.0

Published

Methods for working with BOLT 11 payment requests

Downloads

15,259

Readme

Invoices

Utility methods for parsing Lightning Network BOLT 11 payment requests, as well as encoding unsigned requests and signing payment requests.

Methods

byteDecodeRequest

Derive a payment request from request data.

{
  encoded: <Payment Request Details Hex String>
  [mtokens]: <Millitokens Number String>
  network: <Network Name String>
  words: <Words Count Number>
}

@throws
<Error>

@returns
{
  request: <BOLT 11 Encoded Payment Request String>
}

Example:

const {byteDecodeRequest} = require('invoices');

// Get a BOLT 11 payment request for this invoice data
const {request} = byteDecodeRequest({
  encoded: paymentRequestDetailsHexString,
  mtokens: '0',
  network: 'bitcoin',
});

byteEncodeRequest

Derive bytes for payment request details

{
  request: <BOLT 11 Encoded Payment Request String>
}

@throws
<Error>

@returns
{
  encoded: <Payment Request Details Hex String>
  mtokens: <Millitokens Number String>
  network: <Network Name String>
  words: <Word Length Number>
}

Example:

const {byteEncodeRequest} = require('invoices');

// Get the bytes for a payment request
const {encoded, mtokens, network} = byteEncodeRequest({
  request: bolt11EncodedPaymentRequestString,
});

createSignedRequest

Assemble a signed payment request

{
  destination: <Destination Public Key Hex String>
  hrp: <Request Human Readable Part String>
  signature: <Request Hash Signature Hex String>
  tags: [<Request Tag Word Number>]
}

@throws
<Error>

@returns
{
  request: <BOLT 11 Encoded Payment Request String>
}

Example:

const {createSignedRequest} = require('invoices');

// Get hrp and signature from createUnsignedRequest
// Get signature via standard private key signing, or LND signBytes
const {request} = createSignedRequest({
  destination: nodePublicKey,
  hrp: amountAndNetworkHrp,
  signature: signedPreimageHash,
  tags: paymentRequestTags,
});

createUnsignedRequest

Create an unsigned payment request

{
  [chain_addresses]: [<Chain Address String>]
  [cltv_delta]: <CLTV Delta Number>
  [created_at]: <Invoice Creation Date ISO 8601 String>
  [description]: <Description String>
  [description_hash]: <Description Hash Hex String>
  destination: <Public Key String>
  [expires_at]: <ISO 8601 Date String>
  features: [{
    bit: <BOLT 09 Feature Bit Number>
  }]
  id: <Preimage SHA256 Hash Hex String>
  [mtokens]: <Requested Milli-Tokens Value String> (can exceed Number limit)
  network: <Network Name String>
  [payment]: <Payment Identifier Hex String>
  [routes]: [[{
    [base_fee_mtokens]: <Base Fee Millitokens String>
    [channel]: <Standard Format Channel Id String>
    [cltv_delta]: <Final CLTV Expiration Blocks Delta Number>
    [fee_rate]: <Fee Rate Millitokens Per Million Number>
    public_key: <Forward Edge Public Key Hex String>
  }]]
  [tokens]: <Requested Chain Tokens Number> (note: can differ from mtokens)
}

@returns
{
  hash: <Payment Request Signature Hash Hex String>
  hrp: <Human Readable Part of Payment Request String>
  preimage: <Signature Hash Preimage Hex String>
  tags: [<Data Tag Number>]
}

Example:

const {createUnsignedRequest} = require('invoices');

const unsignedComponents = createUnsignedRequest({
  destination: nodePublicKey,
  id: rHashHexString,
  network: 'bitcoin',
});
// Use createSignedRequest and a signature to create a complete request

parsePaymentRequest

Parse a BOLT 11 payment request into its component data

Note: either description or description_hash will be returned

{
  request: <BOLT 11 Payment Request String>
}

@throws
<Error>

@returns
{
  [chain_addresses]: [<Chain Address String>]
  cltv_delta: <CLTV Delta Number>
  created_at: <Invoice Creation Date ISO 8601 String>
  [description]: <Description String>
  [description_hash]: <Description Hash Hex String>
  destination: <Public Key String>
  expires_at: <ISO 8601 Date String>
  features: [{
    bit: <BOLT 09 Feature Bit Number>
    is_required: <Feature Support is Required To Pay Bool>
    type: <Feature Type String>
  }]
  id: <Payment Request Hash String>
  is_expired: <Invoice is Expired Bool>
  [mtokens]: <Requested Milli-Tokens Value String> (can exceed Number limit)
  network: <Network Name String>
  [payment]: <Payment Identifier Hex Encoded String>
  [routes]: [[{
    [base_fee_mtokens]: <Base Fee Millitokens String>
    [channel]: <Standard Format Channel Id String>
    [cltv_delta]: <Final CLTV Expiration Blocks Delta Number>
    [fee_rate]: <Fee Rate Millitokens Per Million Number>
    public_key: <Forward Edge Public Key Hex String>
  }]]
  [safe_tokens]: <Requested Chain Tokens Rounded Up Number>
  [tokens]: <Requested Chain Tokens Number> (note: can differ from mtokens)
}
const {parsePaymentRequest} = require('invoices');

// Decoded details of the payment request
const requestDetails = parsePaymentRequest({request: 'paymentRequestString'});