lnutil

package
v0.0.0-...-793c700 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2017 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MSGID_TEXTCHAT = 0x00 // send a text message

	//Channel creation messages
	MSGID_POINTREQ  = 0x10
	MSGID_POINTRESP = 0x11
	MSGID_CHANDESC  = 0x12
	MSGID_CHANACK   = 0x13
	MSGID_SIGPROOF  = 0x14

	//Channel destruction messages
	MSGID_CLOSEREQ  = 0x20 // close channel
	MSGID_CLOSERESP = 0x21

	//Push Pull Messages
	MSGID_DELTASIG  = 0x30 // pushing funds in channel; request to send
	MSGID_SIGREV    = 0x31 // pulling funds; signing new state and revoking old
	MSGID_GAPSIGREV = 0x32 // resolving collision
	MSGID_REV       = 0x33 // pushing funds; revoking previous channel state

	//not implemented
	MSGID_FWDMSG     = 0x40
	MSGID_FWDAUTHREQ = 0x41

	//not implemented
	MSGID_SELFPUSH = 0x50

	//Tower Messages
	MSGID_WATCH_DESC     = 0x60 // desc describes a new channel
	MSGID_WATCH_STATEMSG = 0x61 // commsg is a single state in the channel
	MSGID_WATCH_DELETE   = 0x62 // Watch_clear marks a channel as ok to delete.  No further updates possible.
)

id numbers for messages, semi-arbitrary

Variables

View Source
var (
	White = color.New(color.FgHiWhite).SprintFunc()
	Green = color.New(color.FgHiGreen).SprintFunc()
	Red   = color.New(color.FgHiRed).SprintFunc()

	Header   = color.New(color.FgHiCyan).SprintFunc()
	Prompt   = color.New(color.FgHiYellow).SprintFunc()
	OutPoint = color.New(color.FgYellow).SprintFunc()
	Address  = color.New(color.FgMagenta).SprintFunc()
	BTC      = color.New(color.FgHiWhite).SprintFunc()
	Satoshi  = color.New(color.Faint).SprintFunc()
	MicroBTC = color.New(color.FgYellow, color.Faint).SprintFunc()
)

Functions

func AddPrivEZ

func AddPrivEZ(k *btcec.PrivateKey, b []byte)

AddPrivEZ adds the non-secret scalar to a private key

func AddPubsEZ

func AddPubsEZ(a, b [33]byte) [33]byte

AddPubsEZ is the easy derivation; A + sha(B, A)*G in LN this is used for everything but the revocable pubkey order matters. the first key is the base, the second is the elkpoint.

func BtI32

func BtI32(b []byte) int32

4 byte slice to int32. Returns 7fffffff if something doesn't work.

func BtI64

func BtI64(b []byte) int64

8 bytes to int64 (bitcoin amounts). returns 7fff... if it doesn't work.

func BtU32

func BtU32(b []byte) uint32

4 byte slice to uint32. Returns ffffffff if something doesn't work.

func BtU64

func BtU64(b []byte) uint64

8 bytes to uint64. returns ffff. if it doesn't work.

func CombinePrivKeyAndSubtract

func CombinePrivKeyAndSubtract(k *btcec.PrivateKey, b []byte) [32]byte

CombinePrivKeyAndSubtract uses the same delinearization scheme as CombinePrivateKeys, but once it gets the combined private key, it subtracts the original base key. It's weird, but it allows the porTxo standard to always add private keys and not need to be aware of different derivation methods.

func CombinePrivKeyWithBytes

func CombinePrivKeyWithBytes(k *btcec.PrivateKey, b []byte) *btcec.PrivateKey

PrivKeyCombineBytes combines a private key with a byte slice

func CombinePrivateKeys

func CombinePrivateKeys(keys ...*btcec.PrivateKey) *btcec.PrivateKey

CombinePrivateKeys takes a set of private keys and combines them in the same way as done for public keys. This only works if you know *all* of the private keys. If you don't, we'll do something with returning a scalar coefficient... I don't know how that's going to work. Schnorr stuff isn't decided yet.

func CombinePubs

func CombinePubs(a, b [33]byte) [33]byte

CombinePubs takes two 33 byte serialized points, and combines them with the deliniearized combination process. Returns empty array if there's an error.

func CommitScript

func CommitScript(RKey, TKey [33]byte, delay uint16) []byte

CommitScript is the script for 0.13.1: OP_CHECKSIG turned into OP_CHECSIGVERIFY

func DirectWPKHScript

func DirectWPKHScript(pub [33]byte) []byte

func DirectWPKHScriptFromPKH

func DirectWPKHScriptFromPKH(pkh [20]byte) []byte

func ElkPointFromHash

func ElkPointFromHash(in *chainhash.Hash) [33]byte

ElkPoint returns the public key (point) which comes from a node in the elkrem tree (elkrem hash)

func ElkScalar

func ElkScalar(in *chainhash.Hash) chainhash.Hash

ElkScalar returns the private key (scalar) which comes from a node in the elkrem tree (elkrem hash)

func FundTxOut

func FundTxOut(pubA, pubB [33]byte, amt int64) (*wire.TxOut, error)

FundTxOut creates a TxOut for the funding transaction. Give it the two pubkeys and it'll give you the p2sh'd txout. You don't have to remember the p2sh preimage, as long as you remember the pubkeys involved.

func FundTxScript

func FundTxScript(aPub, bPub [33]byte) ([]byte, bool, error)

FundMultiPre generates the non-p2sh'd multisig script for 2 of 2 pubkeys. useful for making transactions spending the fundtx. returns a bool which is true if swapping occurs.

func I32tB

func I32tB(i int32) []byte

int32 to 4 bytes. Always works.

func I64tB

func I64tB(i int64) []byte

int64 to 8 bytes. Always works.

func KeyHashFromPkScript

func KeyHashFromPkScript(pkscript []byte) []byte

KeyHashFromPkScript extracts the 20 or 32 byte hash from a txout PkScript

func LitAdrBytes

func LitAdrBytes(adr string) ([]byte, error)

LitAdrBytes takes a lit address string and returns either 20 or 12 bytes. Or an error.

func LitAdrFromPubkey

func LitAdrFromPubkey(in [33]byte) string

func LitAdrOK

func LitAdrOK(adr string) bool

LitAdrOK make sure the address is OK. Either it has a valid checksum, or it's shortened and doesn't.

func LitFullAdrDecode

func LitFullAdrDecode(in string) ([33]byte, error)

func LitFullKeyAdrEncode

func LitFullKeyAdrEncode(in [33]byte) string

func LitMsgEqual

func LitMsgEqual(msg LitMsg, msg2 LitMsg) bool

func LoadKeyFromFileArg

func LoadKeyFromFileArg(filename string, pass []byte) (*[32]byte, error)

LoadKeyFromFileArg opens the file and returns the key. If the key is unencrypted it will ignore the password argument.

func LoadKeyFromFileInteractive

func LoadKeyFromFileInteractive(filename string) (*[32]byte, error)

LoadKeyFromFileInteractive opens the file 'filename' and presents a keyboard prompt for the passphrase to decrypt it. It returns the key if decryption works, or errors out.

func MultiplyPointByHash

func MultiplyPointByHash(k *btcec.PublicKey, h chainhash.Hash)

PubKeyMultiplyByHash multiplies a pubkey by a hash. returns nothing, modifies in place. Probably the slowest curve operation.

func OptColor

func OptColor(optional ...interface{}) string

func OutPointFromBytes

func OutPointFromBytes(b [36]byte) *wire.OutPoint

OutPointFromBytes gives you an outpoint from 36 bytes. since 36 is enforced, it doesn't error

func OutPointToBytes

func OutPointToBytes(op wire.OutPoint) (b [36]byte)

outPointToBytes turns an outpoint into 36 bytes.

func OutPointsEqual

func OutPointsEqual(a, b wire.OutPoint) bool

need this because before I was comparing pointers maybe? so they were the same outpoint but stored in 2 places so false negative?

func P2WSHify

func P2WSHify(scriptBytes []byte) []byte

P2WSHify takes a script and turns it into a 34 byte long P2WSH PkScript

func PrivKeyAddBytes

func PrivKeyAddBytes(k *btcec.PrivateKey, b []byte)

PrivKeyAddBytes adds bytes to a private key. NOTE that this modifies the key in place, overwriting it!!!!! If k is nil, does nothing and doesn't error (k stays nil)

func PubFromHash

func PubFromHash(h chainhash.Hash) (p [33]byte)

HashToPub turns a 32 byte hash into a 33 byte serialized pubkey

func PubKeyAddBytes

func PubKeyAddBytes(k *btcec.PublicKey, b []byte)

PubKeyAddBytes adds bytes to a public key. NOTE that this modifies the key in place, overwriting it!!!!!

func PubKeyArrAddBytes

func PubKeyArrAddBytes(p *[33]byte, b []byte) error

PubKeyArrAddBytes adds a byte slice to a serialized point. You can't add scalars to a point, so you turn the bytes into a point, then add that point.

func ReadKeyFile

func ReadKeyFile(filename string) (*[32]byte, error)

ReadKeyFile returns an 32 byte key from a file. If there's no file there, it'll make one. If there's a password needed, it'll prompt for one. One stop function.

func ReqColor

func ReqColor(required ...interface{}) string

func SatoshiColor

func SatoshiColor(value int64) string

func SaveKeyToFileArg

func SaveKeyToFileArg(filename string, priv32 *[32]byte, pass []byte) error

saves a 32 byte key to a file, encrypting with pass. if pass is nil or zero length, doesn't encrypt and just saves in hex.

func SaveKeyToFileInteractive

func SaveKeyToFileInteractive(filename string, priv32 *[32]byte) error

saves a 32 byte key to file, prompting for passphrase. if user enters empty passphrase (hits enter twice), will be saved in the clear.

func TxToString

func TxToString(tx *wire.MsgTx) string

TxToString prints out some info about a transaction. for testing / debugging

func U32tB

func U32tB(i uint32) []byte

uint32 to 4 bytes. Always works.

func U64tB

func U64tB(i uint64) []byte

uint64 to 8 bytes. Always works.

Types

type ChanAckMsg

type ChanAckMsg struct {
	PeerIdx   uint32
	Outpoint  wire.OutPoint
	ElkZero   [33]byte
	ElkOne    [33]byte
	ElkTwo    [33]byte
	Signature [64]byte
}

message for channel acknowledgement after description message

func NewChanAckMsg

func NewChanAckMsg(peerid uint32, OP wire.OutPoint, ELKZero [33]byte, ELKOne [33]byte, ELKTwo [33]byte, SIG [64]byte) ChanAckMsg

func NewChanAckMsgFromBytes

func NewChanAckMsgFromBytes(b []byte, peerid uint32) (ChanAckMsg, error)

func (ChanAckMsg) Bytes

func (self ChanAckMsg) Bytes() []byte

func (ChanAckMsg) MsgType

func (self ChanAckMsg) MsgType() uint8

func (ChanAckMsg) Peer

func (self ChanAckMsg) Peer() uint32

type ChanDescMsg

type ChanDescMsg struct {
	PeerIdx   uint32
	Outpoint  wire.OutPoint
	PubKey    [33]byte
	RefundPub [33]byte
	HAKDbase  [33]byte

	CoinType    uint32
	Capacity    int64
	InitPayment int64

	ElkZero [33]byte //consider changing into array in future
	ElkOne  [33]byte
	ElkTwo  [33]byte
}

message with a channel's description

func NewChanDescMsg

func NewChanDescMsg(
	peerid uint32, OP wire.OutPoint,
	pubkey, refund, hakd [33]byte,
	cointype uint32,
	capacity int64, payment int64,
	ELKZero, ELKOne, ELKTwo [33]byte) ChanDescMsg

func NewChanDescMsgFromBytes

func NewChanDescMsgFromBytes(b []byte, peerid uint32) (ChanDescMsg, error)

func (ChanDescMsg) Bytes

func (self ChanDescMsg) Bytes() []byte

func (ChanDescMsg) MsgType

func (self ChanDescMsg) MsgType() uint8

func (ChanDescMsg) Peer

func (self ChanDescMsg) Peer() uint32

type ChatMsg

type ChatMsg struct {
	PeerIdx uint32
	Text    string
}

text message

func NewChatMsg

func NewChatMsg(peerid uint32, text string) ChatMsg

func NewChatMsgFromBytes

func NewChatMsgFromBytes(b []byte, peerid uint32) (ChatMsg, error)

func (ChatMsg) Bytes

func (self ChatMsg) Bytes() []byte

func (ChatMsg) MsgType

func (self ChatMsg) MsgType() uint8

func (ChatMsg) Peer

func (self ChatMsg) Peer() uint32

type CloseReqMsg

type CloseReqMsg struct {
	PeerIdx   uint32
	Outpoint  wire.OutPoint
	Signature [64]byte
}

message for closing a channel

func NewCloseReqMsg

func NewCloseReqMsg(peerid uint32, OP wire.OutPoint, SIG [64]byte) CloseReqMsg

func NewCloseReqMsgFromBytes

func NewCloseReqMsgFromBytes(b []byte, peerid uint32) (CloseReqMsg, error)

func (CloseReqMsg) Bytes

func (self CloseReqMsg) Bytes() []byte

func (CloseReqMsg) MsgType

func (self CloseReqMsg) MsgType() uint8

func (CloseReqMsg) Peer

func (self CloseReqMsg) Peer() uint32

type CombinablePubKeySlice

type CombinablePubKeySlice []*btcec.PublicKey

PubKeySlice are slices of pubkeys, which can be combined (and sorted)

func PubsFromArrs

func PubsFromArrs(arrSlice ...[33]byte) (CombinablePubKeySlice, error)

CombinableSliceFromArrSlice turns an array of 33 byte pubkey arrays into a CombinablePubKeySlice which can then be combined. Varadic. First time I've used that, seems appropriate here.

func (CombinablePubKeySlice) Combine

func (p CombinablePubKeySlice) Combine() *btcec.PublicKey

Combine combines pubkeys into one. Never errors; just returns empty pubkeys instead (which will trigger other errors because those aren't valid pubkeys) Careful to not modify the slice in place.

func (CombinablePubKeySlice) ComboCommit

func (p CombinablePubKeySlice) ComboCommit() chainhash.Hash

ComboCommit generates the "combination commitment" which contributes to the hash-coefficient for every key being combined.

func (CombinablePubKeySlice) Len

func (p CombinablePubKeySlice) Len() int

func (CombinablePubKeySlice) Less

func (p CombinablePubKeySlice) Less(i, j int) bool

func (CombinablePubKeySlice) Swap

func (p CombinablePubKeySlice) Swap(i, j int)

Make PubKeySlices sortable

type DeltaSigMsg

type DeltaSigMsg struct {
	PeerIdx   uint32
	Outpoint  wire.OutPoint
	Delta     int32
	Signature [64]byte
}

message for sending an amount with the signature

func NewDeltaSigMsg

func NewDeltaSigMsg(peerid uint32, OP wire.OutPoint, DELTA int32, SIG [64]byte) DeltaSigMsg

func NewDeltaSigMsgFromBytes

func NewDeltaSigMsgFromBytes(b []byte, peerid uint32) (DeltaSigMsg, error)

func (DeltaSigMsg) Bytes

func (self DeltaSigMsg) Bytes() []byte

func (DeltaSigMsg) MsgType

func (self DeltaSigMsg) MsgType() uint8

func (DeltaSigMsg) Peer

func (self DeltaSigMsg) Peer() uint32

type GapSigRevMsg

type GapSigRevMsg struct {
	PeerIdx    uint32
	Outpoint   wire.OutPoint
	Signature  [64]byte
	Elk        chainhash.Hash
	N2ElkPoint [33]byte
}

message for signaling state has moved, revoking old state

func NewGapSigRev

func NewGapSigRev(peerid uint32, OP wire.OutPoint, SIG [64]byte, ELK chainhash.Hash, N2ELK [33]byte) GapSigRevMsg

func NewGapSigRevFromBytes

func NewGapSigRevFromBytes(b []byte, peerId uint32) (GapSigRevMsg, error)

func (GapSigRevMsg) Bytes

func (self GapSigRevMsg) Bytes() []byte

func (GapSigRevMsg) MsgType

func (self GapSigRevMsg) MsgType() uint8

func (GapSigRevMsg) Peer

func (self GapSigRevMsg) Peer() uint32

type LitMsg

type LitMsg interface {
	Peer() uint32   //return PeerIdx
	MsgType() uint8 //returns Message Type (see constants above)
	Bytes() []byte  //returnns data of message as []byte with the MsgType() preceeding it
}

interface that all messages follow, for easy use

func LitMsgFromBytes

func LitMsgFromBytes(b []byte, peerid uint32) (LitMsg, error)

method for finding what type of message a generic []byte is

type OutPointEvent

type OutPointEvent struct {
	Op     wire.OutPoint // the outpoint being described
	Height int32         // the height of the event
	Tx     *wire.MsgTx   // the tx spending the outpoint
}

OutPointEvent is a message describing events concerning an outpoint. There's 2 event types: confirmation and spend. If the Tx pointer is nil, then it's a confirm. If the Tx has an actual MsgTx in there, it's a spend. The Height refers to either the confirmation height or the height at which it was spent. (0 means seen but unconfirmed)

type PointReqMsg

type PointReqMsg struct {
	PeerIdx  uint32
	Cointype uint32
}

message with no information, just shows a point is requested

func NewPointReqMsg

func NewPointReqMsg(peerid uint32, cointype uint32) PointReqMsg

func NewPointReqMsgFromBytes

func NewPointReqMsgFromBytes(b []byte, peerid uint32) (PointReqMsg, error)

func (PointReqMsg) Bytes

func (self PointReqMsg) Bytes() []byte

func (PointReqMsg) MsgType

func (self PointReqMsg) MsgType() uint8

func (PointReqMsg) Peer

func (self PointReqMsg) Peer() uint32

type PointRespMsg

type PointRespMsg struct {
	PeerIdx    uint32
	ChannelPub [33]byte
	RefundPub  [33]byte
	HAKDbase   [33]byte
}

message to be used for reply to point request

func NewPointRespMsg

func NewPointRespMsg(peerid uint32, chanpub [33]byte, refundpub [33]byte, HAKD [33]byte) PointRespMsg

func NewPointRespMsgFromBytes

func NewPointRespMsgFromBytes(b []byte, peerid uint32) (PointRespMsg, error)

func (PointRespMsg) Bytes

func (self PointRespMsg) Bytes() []byte

func (PointRespMsg) MsgType

func (self PointRespMsg) MsgType() uint8

func (PointRespMsg) Peer

func (self PointRespMsg) Peer() uint32

type RevMsg

type RevMsg struct {
	PeerIdx    uint32
	Outpoint   wire.OutPoint
	Elk        chainhash.Hash
	N2ElkPoint [33]byte
}

send message accross channel using Elk info

func NewRevMsg

func NewRevMsg(peerid uint32, OP wire.OutPoint, ELK chainhash.Hash, N2ELK [33]byte) RevMsg

func NewRevMsgFromBytes

func NewRevMsgFromBytes(b []byte, peerId uint32) (RevMsg, error)

func (RevMsg) Bytes

func (self RevMsg) Bytes() []byte

func (RevMsg) MsgType

func (self RevMsg) MsgType() uint8

func (RevMsg) Peer

func (self RevMsg) Peer() uint32

type SigProofMsg

type SigProofMsg struct {
	PeerIdx   uint32
	Outpoint  wire.OutPoint
	Signature [64]byte
}

message for proof for a signature

func NewSigProofMsg

func NewSigProofMsg(peerid uint32, OP wire.OutPoint, SIG [64]byte) SigProofMsg

func NewSigProofMsgFromBytes

func NewSigProofMsgFromBytes(b []byte, peerid uint32) (SigProofMsg, error)

func (SigProofMsg) Bytes

func (self SigProofMsg) Bytes() []byte

func (SigProofMsg) MsgType

func (self SigProofMsg) MsgType() uint8

func (SigProofMsg) Peer

func (self SigProofMsg) Peer() uint32

type SigRevMsg

type SigRevMsg struct {
	PeerIdx    uint32
	Outpoint   wire.OutPoint
	Signature  [64]byte
	Elk        chainhash.Hash
	N2ElkPoint [33]byte
}

a message that pushes using channel information

func NewSigRev

func NewSigRev(peerid uint32, OP wire.OutPoint, SIG [64]byte, ELK chainhash.Hash, N2ELK [33]byte) SigRevMsg

func NewSigRevFromBytes

func NewSigRevFromBytes(b []byte, peerid uint32) (SigRevMsg, error)

func (SigRevMsg) Bytes

func (self SigRevMsg) Bytes() []byte

func (SigRevMsg) MsgType

func (self SigRevMsg) MsgType() uint8

func (SigRevMsg) Peer

func (self SigRevMsg) Peer() uint32

type TxAndHeight

type TxAndHeight struct {
	Tx     *wire.MsgTx
	Height int32
}

TxAndHeight is just a tx, and the height at which it was confirmed.

type WatchDelMsg

type WatchDelMsg struct {
	PeerIdx  uint32
	DestPKH  [20]byte // identifier for channel; could be optimized away
	RevealPK [33]byte // reveal this pubkey, matches DestPKH

}

func NewWatchDelMsgFromBytes

func NewWatchDelMsgFromBytes(b []byte, peerIDX uint32) (WatchDelMsg, error)

ComMsgFromBytes turns 132 bytes into a SorceMsg Silently fails with wrong size input.

func (WatchDelMsg) Bytes

func (self WatchDelMsg) Bytes() []byte

Bytes turns a ComMsg into 132 bytes

func (WatchDelMsg) MsgType

func (self WatchDelMsg) MsgType() uint8

func (WatchDelMsg) Peer

func (self WatchDelMsg) Peer() uint32

type WatchDescMsg

type WatchDescMsg struct {
	PeerIdx       uint32
	CoinType      uint32   // what network this channel is on
	DestPKHScript [20]byte // PKH to grab to; main unique identifier.

	Delay uint16 // timeout in blocks
	Fee   int64  // fee to use for grab tx.  Or fee rate...?

	CustomerBasePoint  [33]byte // client's HAKD key base point
	AdversaryBasePoint [33]byte // potential attacker's timeout basepoint
}

WatchannelDescriptor is the initial message setting up a Watchannel

func NewWatchDescMsg

func NewWatchDescMsg(
	peeridx, coinType uint32, destScript [20]byte,
	delay uint16, fee int64, customerBase [33]byte,
	adversaryBase [33]byte) WatchDescMsg

NewWatchDescMsg turns 96 bytes into a WatchannelDescriptor Silently fails with incorrect size input, watch out.

func NewWatchDescMsgFromBytes

func NewWatchDescMsgFromBytes(b []byte, peerIDX uint32) (WatchDescMsg, error)

func (WatchDescMsg) Bytes

func (self WatchDescMsg) Bytes() []byte

Bytes turns a WatchannelDescriptor into 100 bytes

func (WatchDescMsg) MsgType

func (self WatchDescMsg) MsgType() uint8

func (WatchDescMsg) Peer

func (self WatchDescMsg) Peer() uint32

type WatchStateMsg

type WatchStateMsg struct {
	PeerIdx  uint32
	CoinType uint32         // could figure it out from PKH but this is easier
	DestPKH  [20]byte       // identifier for channel; could be optimized away
	Elk      chainhash.Hash // elkrem for this state index
	ParTxid  [16]byte       // 16 bytes of txid
	Sig      [64]byte       // 64 bytes of sig
}

ComMsg are 137 bytes. msgtype CoinType 4 PKH 20 txid 16 sig 64 elk 32

func NewComMsg

func NewComMsg(peerIdx, cointype uint32, destPKH [20]byte,
	elk chainhash.Hash, parTxid [16]byte, sig [64]byte) WatchStateMsg

func NewWatchStateMsgFromBytes

func NewWatchStateMsgFromBytes(b []byte, peerIDX uint32) (WatchStateMsg, error)

ComMsgFromBytes turns 132 bytes into a SorceMsg Silently fails with wrong size input.

func (WatchStateMsg) Bytes

func (self WatchStateMsg) Bytes() []byte

ToBytes turns a ComMsg into 132 bytes

func (WatchStateMsg) MsgType

func (self WatchStateMsg) MsgType() uint8

func (WatchStateMsg) Peer

func (self WatchStateMsg) Peer() uint32

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL