Giter Site home page Giter Site logo

bitcoinjs / bolt11 Goto Github PK

View Code? Open in Web Editor NEW
92.0 13.0 64.0 436 KB

A library for encoding and decoding lightning network payment requests as defined in BOLT #11.

License: MIT License

JavaScript 100.00%
invoice payment request lightning network bolt11 bech32 bitcoin

bolt11's People

Contributors

afilini avatar apotdevin avatar dcousens avatar dependabot[bot] avatar junderw avatar motorina0 avatar mrfelton avatar sword-smith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bolt11's Issues

where is note(description) field ?

In bolt11, my invoice contains the description field, but here when I decode using this libarary, I do not have any description field, can you please add one, as description and note are important part of the lightning invoice

Runkit.com: Error: Cannot find module 'secp256k1'

A bit weird I can use bitcoinjs-lib on runkit with no issues

Error: Cannot find module 'secp256k1'
Require stack:
- /app/available_modules/1617109044000/bolt11/payreq.js
- /app/index.js
at Module._resolveFilename in core node:internal/modules/cjs/loader — line 924
at Module._load in core node:internal/modules/cjs/loader — line 769
at Module.require in core node:internal/modules/cjs/loader — line 996
at require in core node:internal/modules/cjs/helpers — line 92
 in bolt11/payreq.js — line 5

image

Serve minified version through a CDN

We are using the bolt11 library as part of a webservice running on nginx. Due to the atypical nature of our CI/CD pipeline, we have to resort to a rather clunky workaround to run the minification process.
It would be great if bolt11 was served from a CDN like cdjns. It would also result in a much better experience for other users who would like to use this library inside the browser.

Encoding with small timestamp values result in bad payment request

If I encode an invoice using a payment_hash tag and a small timestamp value such as 0 or 1, either by manually setting it as a parameter on the encode() call or by mocking the time such that new Date() returns the epoch date, the encoded & signed payment request is corrupted without any of the expected tags or signature.

Make modules tree-shakeable

I haven't done extensive testing on this, so I may be wrong, but the way this package is currently set up isn't tree-shakeable by compilers that have that capability. This could be done by splitting files up and only importing what each export needs. The way I imagine this working is having an encode.js and a decode.js and having them import only the utility functions they need. The main file would simply be an export of those two (along with the other utility functions currently exported.)

This would also allow people who don't have tree shaking setup to import specific exports, like so:

import decode from 'bolt11/decode';

More info about Webpack's approach to tree shaking here: https://webpack.js.org/guides/tree-shaking/

millisatoshis is a string?

satoshis is returned as a number
millisatoshis as a string

Is that intended? Because of javascript issue with big numbers?

Tag names matching bolt11 rfc spec

expire_time is used instead of expiry.
Seems some small modifications to other tags as well.
Any reason they don't follow the tags named here: https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md

I'd be happy to change them to match.

Also, it'd probably be a bit confusing for new users to not see timeExpireDateString if the invoice doesn't have and expiry, (default implying 3600) would if be okay if I made a pull req so that decode returns expiry with timestamp + implied default when no expiry tag is present?

lnd simnet payment request not supported

For local development purposes I am using a lnd simnet cluster as described here in the lnd docs

bolt11 currently does not support decoding payment requests created from a lnd node running in simnet.

Code

var lightningPayReq = require('bolt11');

var decoded = lightningPayReq.decode('lnsb1u1pwslkj8pp52u27w39645j24a0zfxnwytshxserjchdqt8nz8uwv9fp8wasxrhsdql2pkxz7tfdenjqum0w4hxggrgv4kxj7qcqzpgnvqq8t63nxmgha5945s633fdd3p5x9k889g6p02qsghx4vrgqgr3xzz3hgld8r84ellwgz3teexvqzwlxj7lgkhl8xh2p7dstq0fgsspa5ldq6');

Error:

lightning/joule-extension@autopay  » node bolt11.js 
/home/bumi/src/lightning/joule-extension/node_modules/bolt11/payreq.js:764
    throw new Error('Unknown coin bech32 prefix')
    ^

Error: Unknown coin bech32 prefix
    at Object.decode (/home/bumi/src/lightning/joule-extension/node_modules/bolt11/payreq.js:764:11)
    at Object.<anonymous> (/home/bumi/src/lightning/joule-extension/bolt11.js:3:31)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:877:12)
    at internal/main/run_main_module.js:21:11

Error: Invalid argument

I'm trying to decode a valid invoice to get the amount and this error happens:

Error: Invalid argument
    at Object.ecdsaRecover (file:///home/me/.cache/deno/npm/registry.npmjs.org/secp256k1/4.0.3/lib/index.js:300:25)
    at Object.decode (file:///home/winlectro/.cache/deno/npm/registry.npmjs.org/bolt11/1.4.1/payreq.js:981:43)
    at getAmount (file:///home/me/Documents/Dev/ditto/src/utils/bolt11.ts:8:28)
    at file:///home/me/Documents/Dev/ditto/src/utils/bolt11.test.ts:6:5
    at innerWrapped (ext:cli/40_test.js:191:11)
    at exitSanitizer (ext:cli/40_test.js:107:33)
    at outerWrapped (ext:cli/40_test.js:134:20)

I am using Deno and running it as a test

Here's my code:

  1 import bolt11 from 'bolt11';                                                               
  2                                                                                                   
  3 /** Decodes the invoice and returns the amount in millisatoshis */                                                                                            
  4 function getAmount(invoice: string | undefined): string | undefined {
  5   if (!invoice) return;                                                                           
  6 
  7   try {                                                                                           
  8     const decoded = bolt11.decode(invoice);                                                                                                                                               
  9     return decoded?.millisatoshis ?? undefined;                                                   
 10   } catch (e) {                                                                                                                                           
 11     console.log(e);                                                                                                              
 12     return;                                                                                                                           
 13   }                                                                                                                                                                     
 14 }                                                                                                 
 15   
 16 export { getAmount };

Travis updates

@dcousens I noticed the builds were failing for travis on Node 4 and 5.

Default node when installing apt on Ubuntu 16.04 is v6

Which is already getting pretty old.
What are your thoughts on removing v4 and v5 from the supported versions?

private key used in example

How the private key used in the README.md has been derived?

I'm trying to do with bitcoinJS

bitcoin.ECPair.fromWIF("e126f68f7eafcc8b74f54d269fe206be715000f94dac067d1c04a8ca3b2db734", bitcoin.networks.testnet)

but I got Error: Non-base58 character

Update bitcoinjs-lib dependency to the latest version (from v3.3.1 to v6.0)

Currently bolt11 uses bitcoinjs-lib v3.3.1. This is a very old version.

The API used from bitcoinjs-lib is:

  • toBase58Check()
  • fromBase58Check()
  • toBech32()
  • fromBech32()

Please let me know if it is OK to:

  • update to the latest bitcoinjs-lib version (6.0)
  • bump the version of this lib to 1.3.3 (from 1.3.2)

If yes, then I will open a PR with the changes.

LND chan id is not 8bytes

If I try to encode the routing info passing the chan id I get with lnd in regtest

$ lncli -n=regtest listchannels
....
"chan_id": "286972534915072"

In the LND doc chan_id is defined as The first 3 bytes are the block height, the next 3 the index within the block, and the last 2 bytes are the output index for the channel.

npm package outdated

Hi, i want to use you code to build a better version of https://lndecode.com/ . One that shows the payee node public key, so one can use it at yalls.org for example. Could you npm publish the current version so i can properly use it. Right now i just copied it over.

Support Satoshis only [for now]

On a discussion with @Roasbeef, the suggestion was that msats will be too confusing in the short term, and

I don't really see msat being used for anything, at least in the short term

and

lnd always display sat, and accepts sat (on the rpc layer)

I propose, until the use cases come out, we temporarily drop the support and deal only in satoshis.

Thoughts @junderw ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.