Coder Social home page Coder Social logo

lightning's Introduction

Lightning

npm version

Methods for working with the Lightning Network

Selected Projects using Lightning

LND Authentication

To connect to an LND node, authentication details are required.

Export credentials via CLI: balanceofsatoshis: npm install -g balanceofsatoshis and export via bos credentials --cleartext

Or export them manually:

Run base64 on the tls.cert and admin.macaroon files to get the encoded authentication data to create the LND connection. You can find these files in the LND directory. (~/.lnd or ~/Library/Application Support/Lnd)

base64 -w0 ~/.lnd/tls.cert
base64 -w0 ~/.lnd/data/chain/bitcoin/mainnet/admin.macaroon

You can then use these to interact with your LND node directly:

const {authenticatedLndGrpc} = require('lightning');

const {lnd} = authenticatedLndGrpc({
  cert: 'base64 encoded tls.cert file',
  macaroon: 'base64 encoded admin.macaroon file',
  socket: '127.0.0.1:10009',
});

To access unauthenticated methods like the wallet unlocker, use unauthenticatedLndGrpc instead.

Debugging

If you encounter any issues connecting and wish to view detailed information about the underlying grpc calls, you can run Node with these environment variables set:

GRPC_VERBOSITY=DEBUG GRPC_TRACE=all node YOURSCRIPTNAME.js

Methods

lightning's People

Contributors

alexbosworth avatar apotdevin avatar atomicinnovation321 avatar bkiac avatar chrischo-h avatar dolcalmi avatar hsjoberg avatar nicolasburtey avatar rsafier avatar severinalexb avatar swissrouting avatar twshelton avatar unclesamtoshi avatar vindard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lightning's Issues

mtokens as string?

is there a reason why there are attributes like mtokens that are string?

I have not checked as the grpc, and not sure how the definition has been created (manually or programmatically from the protobuf?)

Typescript for `openChannel`, `openChannels`

In release 6.2.0 support is added for base_fee_mtokens and fee_rate on openChannel and openChannels

base_fee_mtokens is a string for the mtokens to charge for base fee on routing to be set on channel open
fee_rate is a number which is the ppm fee to charge for routing to be set on channel open

ping @bkiac for typescript support on these fields

`paths` property on attempts in `GetPaymentsResult`

Description

We're looking at parsing/persisting payments data that we get back from this library in different ways and had a question about a new approach we're trying now.

We'd like to use the getPayments method to get info about distinct attempts related to a single payment (hash?). We noticed that for the getPayment method in its getPaymentResult object there is a paths property under the pending/payment property that would contain all the paths that a payment would take in the case of an MPP payment being done. Ideally we'd like to get this info from the getPayments call as well but we're not sure how this would be reflected within the attempts array in the GetPaymentsResult object.

Can there be more than one successful attempt in the attempts array in the case of an MPP attempt where parts of the MPP can succeed but the entire thing fails?


This was hard to phrase as a question, please do ask for clarification on any part of this that is unclear ๐Ÿ˜…

Tagging @jireva as well as the co-author of this

Migrate to TypeScript

I think it would be great to migrate the source code to TypeScript:

  • type tests can be removed because the compiler would catch the errors
  • JSDocs in a single file (the reason I'm copying the documentation from the JS files now is that it shows up in the context window on hover in IDEs)
    image
  • I find that TypeScript is generally easier to maintain; it would be easier for other developers to contribute to the project

The biggest blocker is getting the build, test, and publish process right. Then we can refactor incrementally.

We can keep the TypeScript rules lenient initially, so the development process doesn't have to change.

@alexbosworth, what do you think? I can set up an initial PR with the build tools, and after that, it should be straightforward to refactor individual files.

reconnect to a restarted lnd

I have a long lived node that is fetching the online status of a lnd.
if lnd restarts, trying to connect back to it using the saved {lnd} I have doesn't work:

    err: [
      503,
      "FailedToConnectToDaemon"
    ]

but even if I try to recreated the lnd object, I still have the same issue. any idea what could be wrong?

Type definitions on `GetPaymentResult`

I'm currently working on something that is pulling the type definitions from this library and I noticed there were some properties missing on the GetPaymentResult type that comes back in the method response.

Specifically it looks like these are missing from the "payment" property:

  • fee
  • paths

Does this look right, and would you be open to adding these to the type (I don't mind helping here)?

Help request: Loading *.proto files fails on nextjs / serverless function

Hi!

I was hoping one of you could give me an advice, runnning lightning client as a serverless function fails in Nextjs, because of file not found. Do any of you have a tip/quickfix/hack to load the proto files?

Like copying them to the project and telling lighning where to find them?

I made a simple repo here to illustrate the issue: https://github.com/richard87/test-grpc

or the discussion about the root issue: vercel/next.js#8251

And feel free to close the issue, as its probably out of scope for the project!

[Feature Idea]: Add support for REST API endpoint

For LND methods, an opaque LND object is passed to execute the actual request and return a response

In addition to the gateway protocol LND and direct grpc LND, a REST LND could be passed which would translate the REST requests and responses back into gRPC style arguments so that the caller could use either endpoint at their discretion

Remove channel type data from channels

Since LND is breaking backwards compatibility with the channel type message with potentially no deprecation window, the results of channel type cannot be trusted in a backwards compatible way:
lightningnetwork/lnd#5890

To fix this issue, remove all references to what type of channel a channel is and wait for a future time when there is a reliable signal that can be used

More examples?

Some context first:

I'm thinking of switching from lnService in favor or a more lightweight library on the server-side. The goal is to unify the API; as on the wallet-side I'm currently mostly using GRPC directly. Because lnService heavily changes variable name/ has specific ways to interpret GRPC responses, this is an overhead in the long run.

I guess this is the goal of this library, but I'm not too sure. some examples would be great to understand this better.

getState as probe?

Is the new getState call available as a probe or is it only exposed through the emitter interface? I would like to use it for a liveness check in Kubernetes so we would need to probe the node instead of listening for events. I would be happy to submit a PR if necessary.

Legacy address support for `getChainFeeEstimate` function

Just double-checking, is there support for legacy addresses with this function?

I tried calling it with 1lhuauzvup3wvkn4ptgcsqwxqknswujqnw and got back the error:

err: [
    503,
    "UnexpectedErrEstimatingFeeForChainSend",
    {
    "err": {
        "code": 2,
        "details": "decoded address is of unknown format",
        "metadata": {
        "content-type": [
            "application/grpc"
        ]
        }
    }
    }
]

Adding support for lndconnect

It would be nice to be able to pass an LND connect URI for authenticating clients.

const lndConnect = 'lndconnect://1.2.3.4:10009?cert=MIICuDCCAl...&macaroon=0201036c6...'
const authenticatedClient = authenticatedLndGrpc({ lndConnect });

It could rely on an already existing library like LN-Zap/node-lndconnect.

Unimplemented error when trying to make payments

Hi, I am trying to make a payment (payViaPaymentRequest) using a btcpay server deployed on lunanode with a self signed certificate and I am getting UnexpectedPaymentError.

This is the code that is rising the error:

	try {
		payment = await payViaPaymentRequest({
		  	lnd,
	  		request: paymentData.request,
		});
	} catch (e) {
		console.error(e);
		return res.status(500).send({ error: 'Payment failed' });
	}

and this is the error:

        [
	  503,
	  'UnexpectedPaymentError',
	  {
	    err: Error: 12 UNIMPLEMENTED: 
	        at Object.callErrorFromStatus (/code/node_modules/@grpc/grpc-js/build/src/call.js:31:26)
	        at Object.onReceiveStatus (/code/node_modules/@grpc/grpc-js/build/src/client.js:331:49)
	        at Object.onReceiveStatus (/code/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:299:181)
	        at /code/node_modules/@grpc/grpc-js/build/src/call-stream.js:160:78
	        at processTicksAndRejections (node:internal/process/task_queues:78:11) {
	      code: 12,
	      details: '',
	      metadata: [Metadata]
	    }
	  }
	]

If I try to get payments (getPayments) or get and create invoices (getInvoices, createInvoice) it works

Add getPendingPayments or allow to pass include_incomplete

Trying to create a fallback for this lightningnetwork/lnd#6249 we found that there is no way to get pending payments (and now we know that we can't trust in trackpayment response).

Do you prefer getPendingPayments or include include_incomplete in getPayments?

Let us know what you prefer to push a PR

thanks in advance

ps: also would be useful get the raw status https://github.com/alexbosworth/lightning/blob/master/lnd_responses/rpc_payment_as_payment.js#L206 because we delete failed attemps so is not possible to compare against track payment

open telemetry?

we have had some peek some days ago where we had thousands of request per minutes, and our app went offline for a brief period. to better understand how to properly scale the backend we would like to add open telemetry and a jaeger or jaeger-equivalent to trace all the internal queries and understand which one takes longer under heavy load.

if it something you'd like add to this repo, or be ok to merge a PR if we're doing one? I have not look at GRPC with open telemetry but I think we may have this ability to trace GRPC calls without the need to change something on the lnd side, but still something to investigate.

Add support for `skip_temp_err` to `payViaRoutes`

When paying via routes in an MPP context, any error will cause the entire payment to no longer be accessible for new shards

In LND 0.15.1 there was a change in the API surface that allows for attaching new shards if the failure on the route is a temporary channel failure

Potentially this flag should be added to every invocation of the API since it in theory it is always safe, testing is needed to confirm that is in fact the case

Typescript for trusted funding

5.17.0 adds the following changes:

getChannels: Add support for is_trusted_funding and other_ids
getClosedChannels: Add support for other_ids
getEphemeralChannelIds: Add method to get other channel ids
openChannels: Add support for is_trusted_funding for instant opening
subscribeToChannels: Add support for is_trusted_funding, other_ids
subscribeToOpenRequests: Add support for is_trusted_funding

These can be updated in typescript definitions, ping @bkiac

is_trusted_funding is always a boolean or undefined
other ids is always an array of strings (standard format channel ids)

Typescript for locked utxos

Version 5.20.0 adds preparatory support for LND 0.15.1 new locked utxos fields:

getLockedUtxos:

  • output_script: output script serialized as hex string
  • tokens: value of the outpoint number

These values are undefined on LND 0.15.0 and below when not present in response

Need expanded definitions for method result

ping @bkiac

Two events with differing data fired

I am using subscribeToForwards to monitor forwards through my node and record the fee earned for accounting purposes.
While testing out on regtest, I found that each forward was generating two events, and both contained slightly different data.

{
  forward: {
    at: '2021-04-01T18:41:33.333Z',
    cltv_delta: 60,
    external_failure: undefined,
    fee: 1,
    fee_mtokens: '1000',
    in_channel: '454x1x0',
    in_payment: 1,
    internal_failure: undefined,
    is_confirmed: false,
    is_failed: false,
    is_receive: false,
    is_send: false,
    mtokens: '20000',
    out_channel: '555x1x0',
    out_payment: 1,
    timeout: 623,
    tokens: 20
  }
}
{
  forward: {
    at: '2021-04-01T18:41:33.436Z',
    cltv_delta: undefined,
    external_failure: undefined,
    fee: undefined,
    fee_mtokens: undefined,
    in_channel: '454x1x0',
    in_payment: 1,
    internal_failure: undefined,
    is_confirmed: true,
    is_failed: false,
    is_receive: false,
    is_send: false,
    mtokens: undefined,
    out_channel: '555x1x0',
    out_payment: 1,
    timeout: undefined,
    tokens: undefined
  }
}

As can be seen, the first event has the fee related info that I want, but the is_confirmed field is false, hence I do not want to use this data. I want to use the data (fee_mtokens specifically) from the event where the is_confirmed is true. However, all the forwards result in these two objects where in the second object, the is_confirmed is true but the fee data is undefined.

Missing types

lnd_methods are fully typed now, what other modules/methods are you planning to export that still need types? Since the project isn't written in TypeScript creating types for internal methods is unnecessary.

Dependency of node 12?

Trying to update ln-service give me this error:

$ yarn upgrade ln-service
yarn upgrade v1.21.1
[1/5] ๐Ÿ”  Validating package.json...
[2/5] ๐Ÿ”  Resolving packages...
warning ln-service > [email protected]: Development of this module has been stopped.
warning ln-service > lightning > [email protected]: Development of this module has been stopped.
[3/5] ๐Ÿšš  Fetching packages...
error [email protected]: The engine "node" is incompatible with this module. Expected version ">=12.0.0". Got "10.16.3"
error Found incompatible module.

I'm running my code on the firebase function (ie: "serverless") which has not yet an engine for node 12 so I'm wondering if this is something that can be easily worked around

`pending` array missing from `getPayment` method return

For cases where the payment is pending, according to the function's documentation we should see a payment pending property with an array of the payments. This is usually missing from the return from my testing so far:

// Object returned from `getPayment` when payment is pending
{
  failed: undefined,
  is_confirmed: false,
  is_failed: false,
  is_pending: true,
  payment: undefined
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.