This repository was archived by the owner on Mar 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
This repository was archived by the owner on Mar 17, 2019. It is now read-only.
Typescript Typings #5
Copy link
Copy link
Open
Description
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,
};
}Metadata
Metadata
Assignees
Labels
No labels