Skip to content

Commit

Permalink
Merge branch 'master' of github.com:wbobeirne/webln
Browse files Browse the repository at this point in the history
  • Loading branch information
wbobeirne committed Dec 4, 2018
2 parents b094cd9 + ad02311 commit 6ca06d4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
33 changes: 27 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Apps that want to enable WebLN payments can use the client library in

### requestProvider()

Attempts to acquire and enable a WebLN provider.
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.

#### Arguments

Expand All @@ -31,14 +33,32 @@ Promise<WebLNProvider> (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)

#### Example

```ts
import { requestProvider } from 'webln/lib/client';

let webln;
try {
webln = await requestProvider();
} catch (err) {
// Handle users without WebLN
}

// Elsewhere in the code...
if (webln) {
// Call webln functions
}
```



## Provider Spec

Providers must implement the interface provided in `webln/lib/provider`.
The spec is as follows:

```.ts
```ts
export interface WebLNProvider {
/* Determines if the WebLNProvider will allow the page to use it */
enable(): Promise<void>;
Expand All @@ -50,7 +70,7 @@ export interface WebLNProvider {
sendPayment(paymentRequest: string): Promise<SendPaymentResponse>;

/* Prompts the user to provide the page with an invoice */
makeInvoice(amount: string): Promise<RequestInvoiceResponse>;
makeInvoice(amount: string | number | RequestInvoiceArgs): Promise<RequestInvoiceResponse>;

/* Prompts the user to sign a message with their private key */
signMessage(message: string): Promise<SignMessageResponse>;
Expand All @@ -60,9 +80,10 @@ export interface WebLNProvider {
}
```

See the typescript definitions for more detail about 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.
See the [typescript definitions](https://github.com/wbobeirne/webln/blob/master/src/provider.ts)
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.


## Contributing
Expand Down
10 changes: 9 additions & 1 deletion src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ export interface SendPaymentResponse {
preimage: string;
}

export interface RequestInvoiceArgs {
amount?: string | number;
defaultAmount?: string | number;
minimumAmount?: string | number;
maximumAmount?: string | number;
defaultMemo?: string;
}

export interface RequestInvoiceResponse {
paymentRequest: string;
}
Expand All @@ -28,7 +36,7 @@ export interface WebLNProvider {
enable(): Promise<void>;
getInfo(): Promise<GetInfoResponse>;
sendPayment(paymentRequest: string): Promise<SendPaymentResponse>;
makeInvoice(amount: string): Promise<RequestInvoiceResponse>;
makeInvoice(args: string | number | RequestInvoiceArgs): Promise<RequestInvoiceResponse>;
signMessage(message: string): Promise<SignMessageResponse>;
verifyMessage(signedMessage: string, rawMessage: string): Promise<void>;
}

0 comments on commit 6ca06d4

Please sign in to comment.