How to use bolt11 - 10 common examples

To help you get started, we’ve selected a few bolt11 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BlueWallet / LndHub / class / User.js View on Github external
async getUserInvoices() {
    let range = await this._redis.lrange('userinvoices_for_' + this._userid, 0, -1);
    let result = [];
    for (let invoice of range) {
      invoice = JSON.parse(invoice);
      let decoded = lightningPayReq.decode(invoice.payment_request);
      invoice.description = '';
      for (let tag of decoded.tags) {
        if (tag.tagName === 'description') {
          invoice.description += decodeURIComponent(tag.data);
        }
        if (tag.tagName === 'payment_hash') {
          invoice.payment_hash = tag.data;
        }
      }

      invoice.ispaid = _invoice_ispaid_cache[invoice.payment_hash] || !!(await this.getPaymentHashPaid(invoice.payment_hash));
      if (!invoice.ispaid) {
        if (decoded && decoded.timestamp > ((+new Date()) / 1000 - 3600 * 24 * 5)) {
          // if invoice is not too old we query lnd to find out if its paid
          let lookup_info = await this.lookupInvoice(invoice.payment_hash);
          invoice.ispaid = lookup_info.settled; // TODO: start using `state` instead as its future proof, and this one might get deprecated
github submarineswaps / swaps-service / test / macros / parse_lightning_invoice.js View on Github external
module.exports = ({invoice}, cbk) => {
  if (!invoice) {
    return cbk([0, 'Expected invoice']);
  }

  try {
    const {tags} = decode(invoice);

    const [paymentHashTag] = tags.filter(t => t.tagName === 'payment_hash');

    return cbk(null, {id: paymentHashTag.data});
  } catch (e) {
    return cbk([0, 'Error parsing invoice', e]);
  }
};
github LN-Zap / zap-desktop / app / lib / utils / crypto.js View on Github external
export const isLn = (input, chain = 'bitcoin', network = 'mainnet') => {
  if (!input || typeof input !== 'string') {
    return false
  }
  try {
    const decoded = lightningRequestReq.decode(input)
    if (decoded.coinType !== get(coinTypes, `${chain}.${network}`)) {
      throw new Error('Invalid coin type')
    }
    return true
  } catch (e) {
    return false
  }
}
github BlueWallet / LndHub / class / User.js View on Github external
async saveUserInvoice(doc) {
    let decoded = lightningPayReq.decode(doc.payment_request);
    let payment_hash;
    for (let tag of decoded.tags) {
      if (tag.tagName === 'payment_hash') {
        payment_hash = tag.data;
      }
    }

    await this._redis.set('payment_hash_' + payment_hash, this._userid);
    return await this._redis.rpush('userinvoices_for_' + this._userid, JSON.stringify(doc));
  }
github LN-Zap / zap-desktop / utils / crypto.js View on Github external
export const decodePayReq = (payReq, addDefaults = true) => {
  const data = lightningRequestReq.decode(payReq)
  const expiry = getTag(data, 'expire_time')
  if (addDefaults && !expiry) {
    data.tags.push({
      tagName: 'expire_time',
      data: 3600,
    })
    data.timeExpireDate = data.timestamp + 3600
    data.timeExpireDateString = new Date(data.timeExpireDate * 1000).toISOString()
  }
  return data
}
github LN-Zap / zap-desktop / app / lib / utils / crypto.js View on Github external
export const decodePayReq = (payReq, addDefaults = true) => {
  const data = lightningRequestReq.decode(payReq)
  const expiry = data.tags.find(t => t.tagName === 'expire_time')
  if (addDefaults && !expiry) {
    data.tags.push({
      tagName: 'expire_time',
      data: 3600,
    })
    data.timeExpireDate = data.timestamp + 3600
    data.timeExpireDateString = new Date(data.timeExpireDate * 1000).toISOString()
  }
  return data
}
github LN-Zap / zap-desktop / utils / crypto.js View on Github external
export const isLn = (input, chain = 'bitcoin', network = 'mainnet') => {
  if (!input || typeof input !== 'string') {
    return false
  }
  try {
    const decoded = lightningRequestReq.decode(input)
    if (decoded.coinType !== get(coinTypes, `${chain}.${network}`)) {
      throw new Error('Invalid coin type')
    }
    return true
  } catch (e) {
    return false
  }
}
github BlueWallet / LndHub / class / Paym.js View on Github external
decodePayReqLocally(payReq) {
    this._decoded_locally = lightningPayReq.decode(payReq);
  }
github LN-Zap / zap-desktop / stories / helpers.js View on Github external
tagName: 'payment_hash',
        data: '0001020304050607080900010203040506070809000102030405060708090102',
      },
      {
        tagName: 'expire_time',
        data: 30,
      },
      {
        tagName: 'description',
        data: memo,
      },
    ],
  }
  data[unit] = amount

  var encoded = lightningPayReq.encode(data)
  var privateKeyHex = 'e126f68f7eafcc8b74f54d269fe206be715000f94dac067d1c04a8ca3b2db734'
  var signed = lightningPayReq.sign(encoded, privateKeyHex)
  return signed.paymentRequest
}
github LN-Zap / zap-desktop / stories / containers / request / request.component.stories.js View on Github external
const mockCreateInvoice = async (amount, currency, memo = '') => {
  const satoshis = convert(currency, 'sats', amount)
  const encoded = lightningPayReq.encode({
    coinType: 'bitcoin',
    satoshis,
    tags: [
      {
        tagName: 'purpose_commit_hash',
        data: '3925b6f67e2c340036ed12093dd44e0368df1b6ea26c53dbe4811f58fd5db8c1',
      },
      {
        tagName: 'payment_hash',
        data: '0001020304050607080900010203040506070809000102030405060708090102',
      },
      {
        tagName: 'expire_time',
        data: 30,
      },
      {

bolt11

A library for encoding and decoding lightning network payment requests as defined in [BOLT #11](https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md).

MIT
Latest version published 2 years ago

Package Health Score

54 / 100
Full package analysis

Popular bolt11 functions