npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

loopd-async

v0.4.4

Published

Loop gRPC client with native promise support and REST standalone server

Downloads

30

Readme

loopd-async

Overview

This library simplifies connecting to a Loop Daemon via gRPC. It wraps all callback functions in promises to make api calls easier to work with.

This library supports Loop version v0.2-alpha.

The gRPC wrapper of this library is a fork and adaptation of lnd-async, all credit is for lnd-async developers.

The project can be run alone to create a simplified REST interface on top of LOOP that exposes functionality to client applications, it's recommended to not expose the REST interface directly to the dangerous internet as that gives anyone control of your node.

Loop is in a early stage, for security reasons we should run this software on the same host where loopd is running, default port 11010.

Using gRPC

You can install loopd-async via npm

npm install loopd-async

To establish a connection to gRPC localhost:11010:

const loop = require('loopd-async');

async function loopInTerms() {
  const client = await loop.connect();
  return await client.getLoopInTerms({});
}
loopInTerms()
  .then(loop => console.log(loop))
  .catch(error => console.error(error));

If you need to add specific node IP and Port you can do it this way:

const loop = require('loopd-async');

async function loopInTerms() {
  const client = await loop.connect({
    loopHost: 'localhost',
    loopPort: 11010,
  });
  return await client.getLoopInTerms({});
}
loopInTerms()
  .then(loop => console.log(loop))
  .catch(error => console.error(error));

Using as a Stand-Alone REST API Server

git clone https://github.com/grunch/loopd-async.git
cd loopd-async
npm install

Configure

In REST mode:

For convenience in REST mode, you can make a .env file with KEY=VALUE pairs instead of setting environment variables.

Environment variables:

export LOOPD_HOST='localhost'
export LOOPD_PORT=11010
export LOOPD_BASIC_AUTH_USER='admin'
export LOOPD_BASIC_AUTH_PASSWORD='super_secret_passwd!'
export TLS_DIR='/home/your_user/.lnd/'

Setting environment variables in Linux:

  • Edit .bashrc or ~/.profile
  • $ source ~/.bashrc in the window you are running the service from

Setting environment variables in MacOS:

  • Edit ~/.bash_profile
  • $ . ~/.bash_profile in the window you are running the service from

Run the service:

npm start

REST API

Authentication is with Basic Authentication. Make sure that the request has an authorization header that contains Base64 encoded credentials.

Authorization: Basic {{TOKEN_GOES_HERE_WITHOUT_BRACES}}

To generate the Base64 encoded credentials you can:

> let username = 'admin';
// username must match the LOOPD_BASIC_AUTH_USER in your env variables
// if you don't indicate this, the default username is 'admin'
> let password = 'super_secret_passwd!';
// password must match the LOOPD_BASIC_AUTH_PASSWORD in your env variables.
> btoa(`${username}:${password}`);
// YWRtaW46c3VwZXJfc2VjcmV0X3Bhc3N3ZCE=

And then set the value of the Authorization header to the returned value YWRtaW46c3VwZXJfc2VjcmV0X3Bhc3N3ZCE=.

Methods

  • loopIn - LoopIn initiates a loop in swap.
  • getLoopInTerms - Returns the terms that the server enforces for swaps.
  • getLoopInQuote - Returns the terms that the server enforces for swaps.
  • loopOut - Initiates an loop out swap.
  • loopOutTerms - Returns the terms that the server enforces for a loop out swap.
  • loopOutQuote - Returns a quote for a loop out swap.

loopIn

Initiates a loop in swap with the given parameters. The call returns after the swap has been set up with the swap server. From that point onwards, progress can be tracked via the SwapStatus stream that is returned from Monitor().

{
  amt: <Requested swap amount in satoshis Number>
  max_swap_fee: <Maximum we are willing to pay the server for the swap Number>
  max_miner_fee: <Maximum in on-chain fees that we are willing to spent Number>
  loop_in_channel: <The channel to loop in>
  external_htlc: <If external_htlc is true, we expect the htlc to be published by an external Boolean>
}

@returns
{
  id: <Swap identifier to track status in the update stream String>
  htlc_address: <Htlc address String>
}

getLoopInTerms

GetTerms returns the terms that the server enforces for swaps.

{}

@returns
{
  swap_payment_dest: <The node pubkey where the swap payment needs to be paid to String>
  swap_fee_base: <The base fee for a swap (sat) Number>
  swap_fee_rate: <The fee rate for a swap (parts per million) Number>
  prepay_amt: <Required prepay amount Number>
  min_swap_amount: <Minimum swap amount (sat) Number>
  max_swap_amount: <Maximum swap amount (sat) Number>
  cltv_delta: <On-chain cltv expiry delta Number>
  max_cltv: <Maximum cltv expiry delta Number>
}

getLoopInQuote

Returns a quote for a loop out swap with the provided parameters.

{
  amt: <The amount to swap in satoshis Number>
}

@returns
{
  swap_fee: <The fee that the swap server is charging for the swap Number>
  prepay_amt: <The part of the swap fee that is requested as a prepayment Number>
  miner_fee: <An estimate of the on-chain fee that needs to be paid to sweep the HTLC Number>
}

loopOut

Initiates an loop out swap with the given parameters. The call returns after the swap has been set up with the swap server. From that point onwards, progress can be tracked via the SwapStatus stream that is returned from Monitor().

{
  amt: <Requested swap amount in satoshis Number>
  dest: <Base58 encoded destination address for the swap String>
  max_swap_routing_fee: <Maximum off-chain fee in msat that may be paid for payment to the server Number>
  max_prepay_routing_fee: <Maximum off-chain fee in msat that may be paid for payment to the server Number>
  max_swap_fee: <Maximum we are willing to pay the server for the swap Number>
  max_prepay_amt: <Maximum amount of the swap fee that may be charged as a prepayment Number>
  max_miner_fee: <Maximum in on-chain fees that we are willing to spent Number>
  loop_out_channel: <The channel to loop out String>
  conf_target: <The confirmation target that should be used by the swap server Number>
}

@returns
{
  id: <Swap identifier to track status in the update stream String>
  htlc_address: <Htlc address String>
}

loopOutTerms

Returns the terms that the server enforces for a loop out swap.

{}

@returns
{
  swap_payment_dest: <The node pubkey where the swap payment needs to be paid to String>
  swap_fee_base: <The base fee for a swap (sat) Number>
  swap_fee_rate: <The fee rate for a swap (parts per million) Number>
  prepay_amt: <Required prepay amount Number>
  min_swap_amount: <Minimum swap amount (sat) Number>
  max_swap_amount: <Maximum swap amount (sat) Number>
  cltv_delta: <On-chain cltv expiry delta Number>
  max_cltv: <Maximum cltv expiry delta Number>
}

loopOutQuote

Returns a quote for a loop out swap with the provided parameters.

{
  amt: <The amount to swap in satoshis Number>
  conf_target: <The confirmation target that should be used by the swap server Number>
}

@returns
{
  swap_fee: <The fee that the swap server is charging for the swap Number>
  prepay_amt: <The part of the swap fee that is requested as a prepayment Number>
  miner_fee: <An estimate of the on-chain fee that needs to be paid to sweep the HTLC Number>
}

Official API documentation

https://lightningloop.io