altangent / lightnode-invoice Goto Github PK
View Code? Open in Web Editor NEWLightning Network invoice protocol library
License: MIT License
Lightning Network invoice protocol library
License: MIT License
I wrote some Typescript typings for this library, which I am using in my local project. I would be more than happy to open a PR against DefinitelyTyped so they can be published under the npm @types org. Alternatively, they could live in this project.
Let me know your thoughts. Thanks!
Types:
declare module 'lightnode-invoice' {
/**
* Decodes a bech32 encoded lightning invoice. Exceptions are thrown for invalid invoices.
* @param invoice The bech32 encoded lightning invoice.
*/
function decode(invoice: string): Invoice;
/**
* Encodes an invoice into a bech32 encoded lightning invoice.
* @param invoice The invoice class instance.
* @param privKey The private key used to sign the invoice.
*/
function encode(invoice: Invoice, privKey: string): string;
/**
* Represents a payment invoice.
*/
class Invoice {
/**
* Network prefix.
*/
public network: 'bc' | 'tb' | 'crt' | 'sm';
/**
* Amount in bitcoin.
*/
public amount: number;
/**
* Timestamp of the invoice.
*/
public timestamp: number;
/**
* Raw fields that are known in BOLT 11.
*/
public fields: any[];
/**
* Raw fields that are unknown in BOLT 11.
*/
public unknownFields: any[];
/**
* Signature that was used to sign the invoice.
*/
public signature: Signature;
/**
* Pubkey that was recovered from the signature or provided in an n field.
*/
public pubkey: Pubkey
/**
* SHA256 of the data that was signed.
*/
public hashData: Buffer;
/**
* Expiry time in seconds, defaults to 3600 (per BOLT 11).
*/
public readonly expiry: number;
/**
* SHA256 of the payment_preimage provided in return for payment.
*/
public paymentHash: Buffer;
/**
* Short description.
*/
public shortDesc: string;
/**
* Hash of the long description.
*/
public hashDesc: Buffer;
/**
* Optional pubkey of the payee node.
*/
public payeeNode: Buffer;
/**
* min_final_cltv_expiry to use for the last node, defaults to 9 (per BOLT 11).
*/
public minFinalCltvExpiry: number;
/**
* List of on-chain addresses to fall back if payment fails. Supports version 0, 17, 18 addresses.
*/
public readonly fallbackAddresses: FallbackAddress[];
/**
* List of routes that should be used.
*/
public readonly routes: Route[];
/**
* Add a P2PKH or P2SH address in base58check or bech32 encoding.
* @param addrStr The address string.
*/
public addFallbackAddress(addrStr: string): void;
/**
* Adds a new private route
* @param routes The private routes
*/
public addRoute(routes: Route[]): void;
}
export interface Signature {
r: Buffer;
s: Buffer;
recoveryFlag: number;
}
export interface Pubkey {
x: Buffer;
y: Buffer;
}
export interface FallbackAddress {
version: number;
address: Buffer;
}
export interface Route {
pubkey: Buffer;
short_channel_id: Buffer;
fee_base_msat: number;
fee_proportional_millionths: number;
cltv_expiry_delta: number;
}
export {
decode,
encode,
Invoice,
};
}
JS floats are imprecise and are limited to 32 bits. Numbers should probably be dealt with in satoshis as strings rather than bitcoins as numbers, and internally it should probably be managed using a library like bn.js.
Ability to encode lightning invoices needs to be added. Will create a lightning invoice object and add a encode method that will serialize it into bech32. Test vectors should follow the reverse decode vectors.
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.