Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f7e81af48 | ||
|
|
4cc4c418c1 | ||
|
|
36cbbedfd6 | ||
|
|
1bc481dbc2 | ||
|
|
ce49dbb0f6 | ||
|
|
9033eba9d8 | ||
|
|
1462d1203e |
@ -22,6 +22,7 @@ var decoded = lightningPayReq.decode('lnbc20m1pvjluezhp58yjmdan79s6qqdhdzgynm4zw
|
||||
{
|
||||
"coinType": "bitcoin",
|
||||
"complete": true,
|
||||
"millisatoshi": "2000000000",
|
||||
"satoshis": 2000000,
|
||||
"payeeNodeKey": "03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad",
|
||||
"paymentRequest": "lnbc20m1pvjluezhp58yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqspp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqfppqw508d6qejxtdg4y5r3zarvary0c5xw7kepvrhrm9s57hejg0p662ur5j5cr03890fa7k2pypgttmh4897d3raaq85a293e9jpuqwl0rnfuwzam7yr8e690nd2ypcq9hlkdwdvycqa0qza8",
|
||||
@ -53,6 +54,9 @@ var decoded = lightningPayReq.decode('lnbc20m1pvjluezhp58yjmdan79s6qqdhdzgynm4zw
|
||||
*/
|
||||
```
|
||||
|
||||
### Warning
|
||||
The `"satoshis"` field will only be set if the invoice is for a whole number of satoshis. If it is in a fractional number of satoshis, the `"millisatoshis"` field must be used. 1000 millisatoshis is 1 satoshi.
|
||||
|
||||
### Encoding
|
||||
* MINIMUM NEED: `privateKey` and one `payment_hash` tag as well as one `description`
|
||||
* (`timestamp` defaults to current time, `description` defaults to empty string,
|
||||
|
||||
8
package-lock.json
generated
8
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "bolt11",
|
||||
"version": "1.2.5",
|
||||
"version": "1.2.6",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -1480,9 +1480,9 @@
|
||||
}
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.11",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
|
||||
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
|
||||
"version": "4.17.13",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.13.tgz",
|
||||
"integrity": "sha512-vm3/XWXfWtRua0FkUyEHBZy8kCPjErNBT9fJx8Zvs+U6zjqPbTUOpkaoum3O5uiA8sm+yNMHXfYkTUHFoMxFNA=="
|
||||
},
|
||||
"loose-envify": {
|
||||
"version": "1.4.0",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "bolt11",
|
||||
"version": "1.2.5",
|
||||
"version": "1.2.6",
|
||||
"description": "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).",
|
||||
"main": "payreq.js",
|
||||
"types": "payreq.d.ts",
|
||||
|
||||
6
payreq.d.ts
vendored
6
payreq.d.ts
vendored
@ -12,6 +12,10 @@ type FallbackAddress = {
|
||||
address: string;
|
||||
addressHash: string;
|
||||
};
|
||||
type Network = {
|
||||
[index: string]: any;
|
||||
bech32: string;
|
||||
};
|
||||
|
||||
// Start exports
|
||||
export declare type TagData = string | number | RoutingInfo | FallbackAddress;
|
||||
@ -36,7 +40,7 @@ export declare type PaymentRequestObject = {
|
||||
}>;
|
||||
};
|
||||
export declare function encode(inputData: PaymentRequestObject, addDefaults?: boolean): PaymentRequestObject;
|
||||
export declare function decode(paymentRequest: string): PaymentRequestObject;
|
||||
export declare function decode(paymentRequest: string, network?: Network): PaymentRequestObject;
|
||||
export declare function sign(inputPayReqObj: PaymentRequestObject, inputPrivateKey: string | Buffer): PaymentRequestObject;
|
||||
export declare function satToHrp(satoshis: number | string): string;
|
||||
export declare function millisatToHrp(millisatoshis: number | string): string;
|
||||
|
||||
16
payreq.js
16
payreq.js
@ -720,7 +720,7 @@ function encode (inputData, addDefaults) {
|
||||
|
||||
// decode will only have extra comments that aren't covered in encode comments.
|
||||
// also if anything is hard to read I'll comment.
|
||||
function decode (paymentRequest) {
|
||||
function decode (paymentRequest, network) {
|
||||
if (typeof paymentRequest !== 'string') throw new Error('Lightning Payment Request must be string')
|
||||
if (paymentRequest.slice(0, 2).toLowerCase() !== 'ln') throw new Error('Not a proper lightning payment request')
|
||||
let decoded = bech32.decode(paymentRequest, Number.MAX_SAFE_INTEGER)
|
||||
@ -755,12 +755,16 @@ function decode (paymentRequest) {
|
||||
throw new Error('Not a proper lightning payment request')
|
||||
}
|
||||
|
||||
let coinType = prefixMatches[1]
|
||||
let coinNetwork
|
||||
if (BECH32CODES[coinType]) {
|
||||
coinType = BECH32CODES[coinType]
|
||||
let bech32Prefix = prefixMatches[1]
|
||||
let coinNetwork, coinType
|
||||
if (BECH32CODES[bech32Prefix]) {
|
||||
coinType = BECH32CODES[bech32Prefix]
|
||||
coinNetwork = BITCOINJS_NETWORK_INFO[coinType]
|
||||
} else {
|
||||
} else if (network && network.bech32) {
|
||||
coinType = 'unknown'
|
||||
coinNetwork = network
|
||||
}
|
||||
if (!coinNetwork || coinNetwork.bech32 !== bech32Prefix) {
|
||||
throw new Error('Unknown coin bech32 prefix')
|
||||
}
|
||||
|
||||
|
||||
@ -237,3 +237,17 @@ tape(`can decode and encode payment request containing unknown tags`, (t) => {
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape(`can decode unknown network payment request`, (t) => {
|
||||
const network = { bech32: 'sb' }
|
||||
let decoded = lnpayreq.decode(
|
||||
'lnsb1u1pwslkj8pp52u27w39645j24a0zfxnwytshxserjchdqt8nz8uwv9fp8wasxrhsdq' +
|
||||
'l2pkxz7tfdenjqum0w4hxggrgv4kxj7qcqzpgnvqq8t63nxmgha5945s633fdd3p5x9k889' +
|
||||
'g6p02qsghx4vrgqgr3xzz3hgld8r84ellwgz3teexvqzwlxj7lgkhl8xh2p7dstq0fgsspa' +
|
||||
'5ldq6',
|
||||
network
|
||||
)
|
||||
t.ok(decoded.complete === true)
|
||||
t.ok(decoded.coinType === 'unknown')
|
||||
t.end()
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user