Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #96 from niteshbalusu11:niteshbalusu11/issue78
Browse files Browse the repository at this point in the history
[lnurl]: Added support for lnurl command
  • Loading branch information
niteshbalusu11 authored Aug 22, 2022
2 parents 2f3b9ac + a789fbf commit 088b625
Show file tree
Hide file tree
Showing 46 changed files with 2,387 additions and 255 deletions.
170 changes: 169 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ bos forwards
# Look up the channels and fee rates of a node by its public key
bos graph "pubkey"

# Collection of lnurl features
bos lnurl --url "lnurl"

# Pay a payment request (invoice), probing first
bos pay "payment_request"

Expand Down Expand Up @@ -1260,6 +1263,171 @@ try {

<br></br>

### Lnurl

```javascript
/**
@GetRequest
@Url
http://localhost:8055/api/lnurl
Supported functions: auth, channel, pay, withdraw
Function auth: Request authorization
@Query
{
message_id: <DateTime stamp string>
[node]: <Saved Node String>
function: <Lnurl Function String>
url: <Url String>
}
@Response
{
is_authenticated: <Is Authenticated Bool>
}
====================================================
Function channel: Request an incoming payment channel
@Query
{
message_id: <DateTime stamp string>
[node]: <Saved Node String>
function: <Lnurl Function String>
url: <Url String>
}
@Response
{
is_authenticated: <Is Authenticated Bool>
}
====================================================
Function pay: Pay to an lnurl/lightning address
@Query
{
amount: <Amount to Pay Number>
[avoid]: [<Avoid Forwarding Through String>]
function: <Lnurl Function String>
[max_fee]: <Maximum Fee Tokens Number>
[max_paths]: <Max Paths to take Number>
message_id: <DateTime stamp string>
[node]: <Saved Node String>
[out]: [<Pay Out Through Peer String Array>]
url: <Lnurl/Lightning Address String>
}
@Response
{
[fee]: <Fee Tokens To Destination Number>
[id]: <Payment Hash Hex String>
[latency_ms]: <Latency Milliseconds Number>
[paid]: <Paid Tokens Number>
[preimage]: <Payment HTLC Preimage Hex String>
[relays]: [<Relaying Node Public Key Hex String]
[success]: [<Standard Format Channel Id String>]
}
====================================================
Function withdraw: Will create an invoice and send it to a service
@Query
{
amount: <Amount for withdraw Request Number>
message_id: <DateTime stamp string>
[node]: <Saved Node String>
function: <Lnurl Function String>
url: <Url String>
}
@Response
{
withdrawal_request_sent: <Is Withdraw Request Sent Bool>
}
*/

import { io } from 'socket.io-client';

try {
const url = 'http://localhost:8055/api/lnurl';

// Unique connection name for websocket connection.
const dateString = Date.now().toString();

// Supported functions: auth, channel, pay, withdraw

// Query for auth function
const query = {
function: 'auth',
message_id: dateString,
};

// Query for channel function
const query = {
function: 'channel',
is_private: true,
message_id: dateString,
};

// Query for pay function
const query = {
avoid: ['ban'],
function: 'pay',
max_fee: 20,
max_paths: 2,
message_id: dateString,
out: ['02ce4aea072f54422d35eb8d82aebe966b033d4e98b470907f601a025c5c29a7dc'],
};

// Query for withdraw function
const query = {
amount: 100,
function: 'withdraw',
message_id: dateString,
};


// To get live logs while working with lnurl, you can start a websocket connection with the server and add an event listener.
// Websocket url is the same as the server url http://localhost:8055
// Messages from the server are passed to client using the dateString passed from above.
const socket = io();

socket.on('connect', () => {
console.log('connected');
});

socket.on('disconnect', () => {
console.log('disconnected');
});

// Make sure to pass the same dateString from above
socket.on(`${dateString}`, data => {
console.log(data);
});

socket.on('error', err => {
throw err;
});

// End websocket code.

const response = await axios.get(url, {
params: query,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`,
},
});
} catch (error) {
console.error(error);
}
```

<br></br>

### Pay

```javascript
Expand Down Expand Up @@ -1312,7 +1480,7 @@ try {
request: 'lnbcrt500n1p30ust0pp5n07x3ckwhxunpxy4gp2azckwqk8tlaqgl3hu036u5qa77dfj2f6sdqqcqzpgxqyz5vqsp54eg7zhnnrcnkhr848asghvuu349k00a5cltx56ctnt7a80jcjgxq9qyyssqsms9wv8d9244l03wasz40mfaw3xgfxjth4c02mk958gjj0yzm6cx6mne28auz3vk0kypqwnsp37pde958wxu7vrqmmpxp9f3td64jnqp0q0gas',
};

// To get live logs while pushing a payment, you can start a websocket connection with the server and add an event listener.
// To get live logs while paying an invoice, you can start a websocket connection with the server and add an event listener.
// Websocket url is the same as the server url http://localhost:8055
// Messages from the server are passed to client using the dateString passed from above.
const socket = io();
Expand Down
21 changes: 21 additions & 0 deletions src/client/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,27 @@ const commands: Commands = [
sort: 'Sort',
},
},
{
name: 'Lnurl',
value: 'Lnurl',
description: 'Collection of lnurl features',
longDescription: 'Functions: auth, channel, pay, withdraw. lnurl auth will request authorization. lnurl channel will request an incoming payment channel. lnurl pay will request a payment request from a service. lnurl withdraw will create an invoice and send it to a service',
args: {
auth: 'auth',
channel: 'channel',
pay: 'pay',
withdraw: 'withdraw',
},
flags: {
amount: 'Amount',
avoid: 'Avoid',
is_private: 'Private',
max_fee: 'MaxFee',
max_paths: 'MaxPaths',
out: 'Out',
url: 'Url',
}
},
{
name: 'Pay',
value: 'Pay',
Expand Down
Loading

0 comments on commit 088b625

Please sign in to comment.