Categorygithub.com/chainpoint/lightning-go
modulepackage
0.15.2
Repository: https://github.com/chainpoint/lightning-go.git
Documentation: pkg.go.dev

# README

lightning-go

License

This golang library is used by Chainpoint Core to connect with a Lightning Network Daemon over grpc. By default Lightning, Wallet, WalletUnlocker, and Invoice clients are available. A number of convenience methods for working with Lightning Service Authentication Tokens and interacting with the Bitcoin blockchain are also provided. By default this library is intended to work with Tierion Inc's fork of lnd, but other than exposing a block retrieval method, there is little difference from the original repository.

Install

This package requires Go modules.

go get github.com/chainpoint/lightning-go

Usage

A basic example of declaring the library is provided below.

package main

import (
    lightning "github.com/chainpoint/lightning-go"
    "encoding/json"
    "fmt"
    "time"
)

func main() {
    lndClient := lightning.LightningClient{
                        TlsPath:             "/home/ubuntu/.lnd/tls.cert",
                        MacPath:             "/home/ubuntu/.lnd/data/chain/bitcoin/mainnet/admin.macaroon",
                        ServerHostPort:      "127.0.0.1:10009",
                        LndLogLevel:         "error",
                        MinConfs:            3,
                        Testnet:             "mainnet",
                        WalletAddress:       "your_wallet_address",
                        WalletPass:          "your_wallet_password",
                        WalletSeed:          "your_wallet_seed",
                        HashPrice:           int64(2), //price to charge for issuing LSAT
                        SessionSecret:       "a mutual secret between lsat servers and clients",
                  }
     lndClient.WaitForConnection(5 * time.Minute)  //Wait until lnd is ready
     lndClient.Unlocker()                          //Unlock wallet 
     info, err := lndClient.GetInfo()              //Make a call to get lnd node info
     if err == nil {
         infoJson, _ := json.Marshal(info)
         fmt.Println(string(infoJson)) 
     }
}

Additionally an example of a server-side LSAT flow, RespondLSAT, is provided in lsat.go

# Functions

AddFirstPartyCaveats adds a set of caveats as first-party caveats to a macaroon.
CreateClient : creates a new basic client struct.
DecodeCaveat decodes a caveat from its string representation.
DecodeIdentifier decodes an LSAT's identifier according to its version.
EncodeCaveat encodes a caveat into its string representation.
EncodeIdentifier encodes an LSAT's identifier according to its version.
No description provided by the author
GenerateRandomBytes returns securely generated random bytes.
GetCurrentFuncName : get name of function being called.
GetIpFromUri : parses and IP from a uri as determined by IsLnUri.
HasCaveat checks whether the given macaroon has a caveat with the given condition, and if so, returns its value.
IsLnUri : determines if a url meets criteria <pub_key>@<ip>:<port>.
MakeIDFromString parses the hex encoded string and parses it into a token ID.
NewCaveat construct a new caveat with the given condition and value.

# Constants

LatestVersion is the latest version used for minting new LSATs.
PreimageKey is the key used for a payment preimage caveat.
SecretSize is the size in bytes of a LSAT's secret, also known as the root key of the macaroon.
TokenIDSize is the size in bytes of an LSAT's ID encoded in its macaroon identifier.

# Variables

ErrInvalidCaveat is an error returned when we attempt to decode a caveat with an invalid format.
ErrUnknownVersion is an error returned when attempting to decode an LSAT identifier with an unknown version.

# Structs

Caveat is a predicate that can be applied to an LSAT in order to restrict its use in some form.
Identifier contains the static identifying details of an LSAT.
No description provided by the author
No description provided by the author

# Type aliases

TokenID is the type that stores the token identifier of an LSAT token.