This library provides the spec and client libraries for WebLN, a way of interacting with a user's Lightning node via the browser.
Heads up: This spec is in early alpha, and is subject to a lot of change. Join in the discussion in the issue queue, and try not to build any mainnet software off of it yet!
Apps that want to enable WebLN payments can use the client library in
webln/lib/client
. It provides the following functions:
Attempts to acquire and enable a WebLN provider. It's recommended
you wait to run this until after DOMContentLoaded
to ensure that
any client providers have had time to inject the WebLN instance.
N/A
Promise (see below) that's already been enable()
d.
- If no providers are available
- If the provider rejects the
enable()
call (e.g. user doesn't confirm)
import { requestProvider } from 'webln';
let webln;
try {
webln = await requestProvider();
} catch (err) {
// Handle users without WebLN
}
// Elsewhere in the code...
if (webln) {
// Call webln functions
}
Providers must implement the interface provided in webln/lib/provider
.
The spec is as follows:
export interface WebLNProvider {
/* Determines if the WebLNProvider will allow the page to use it */
enable(): Promise<void>;
/* Returns some basic information about the node */
getInfo(): Promise<GetInfoResponse>;
/* Prompts the user with a BOLT-11 payment request */
sendPayment(paymentRequest: string): Promise<SendPaymentResponse>;
/* Prompts the user to provide the page with an invoice */
makeInvoice(amount: string | number | RequestInvoiceArgs): Promise<RequestInvoiceResponse>;
/* Prompts the user to sign a message with their private key */
signMessage(message: string): Promise<SignMessageResponse>;
/* Shows the user a view that verifies a signed message */
verifyMessage(signedMessage: string, rawMessage: string): Promise<void>;
}
See the typescript definitions for more detail about request objects and response shapes. The spec is far from complete, and will need more functions to be fully-fledged, but these methods should cover most use-cases.
Please join the issue queue to discuss the future of the WebLN spec.