bitcoinjs / bolt11 Goto Github PK
View Code? Open in Web Editor NEWA library for encoding and decoding lightning network payment requests as defined in BOLT #11.
License: MIT License
A library for encoding and decoding lightning network payment requests as defined in BOLT #11.
License: MIT License
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
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
Seems that in latest code regtest is no longer a recognised network
custom signet BOLT11 invoices fail validation.
This will break since it requires a new field as MUST.
Major version bump and README explanation will be needed... will look at the timeline of LND c-lightning and eclair to see when we should push this out.
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.
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.
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/
satoshis is returned as a number
millisatoshis as a string
Is that intended? Because of javascript issue with big numbers?
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?
My c-lightning implementation verifies that this is a valid bolt11 invoice. But the satoshis
field is not set for this invoice. Is that because it is not a whole number of satoshis, s.t. we must use the millisatoshis
field instead?
I have created a small web app that uses bolt11
You can find it here:
https://bitcoincore.tech/apps/bolt11-ui/index.html
Github Repo:
https://github.com/bitcoincoretech/bolt11-ui
I have created a short gif
, but it should be fairly easy to use.
It supports:
It includes the latest tags: payment secret, feature bits.
Any feedback is appreciated!
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.
var lightningPayReq = require('bolt11');
var decoded = lightningPayReq.decode('lnsb1u1pwslkj8pp52u27w39645j24a0zfxnwytshxserjchdqt8nz8uwv9fp8wasxrhsdql2pkxz7tfdenjqum0w4hxggrgv4kxj7qcqzpgnvqq8t63nxmgha5945s633fdd3p5x9k889g6p02qsghx4vrgqgr3xzz3hgld8r84ellwgz3teexvqzwlxj7lgkhl8xh2p7dstq0fgsspa5ldq6');
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
Would like to encode an invoice and include the "h" tag
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 };
@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?
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
If I dont pass a valid invoice to decode I get an error. How can I catch this error before?
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:
bitcoinjs-lib
version (6.0)1.3.3
(from 1.3.2)If yes, then I will open a PR with the changes.
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.
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.
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 ?
Currently invoices with a 'p' divisor fail saying "Amount is outside of valid range"
See payreq.js line 318
The standard as defined by BOLT#11 allows for pico (p) encoding.
The Blockstream store are generating LN invoices in millisatoshis.
It's likely, then, that other services that use the ElementsProject c-lightning implementation will also use millisatoshis.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.