Documentation ¶
Index ¶
- Constants
- Variables
- func AddPrivEZ(k *btcec.PrivateKey, b []byte)
- func AddPubsEZ(a, b [33]byte) [33]byte
- func BtI32(b []byte) int32
- func BtI64(b []byte) int64
- func BtU32(b []byte) uint32
- func BtU64(b []byte) uint64
- func CombinePrivKeyAndSubtract(k *btcec.PrivateKey, b []byte) [32]byte
- func CombinePrivKeyWithBytes(k *btcec.PrivateKey, b []byte) *btcec.PrivateKey
- func CombinePrivateKeys(keys ...*btcec.PrivateKey) *btcec.PrivateKey
- func CombinePubs(a, b [33]byte) [33]byte
- func CommitScript(RKey, TKey [33]byte, delay uint16) []byte
- func DirectWPKHScript(pub [33]byte) []byte
- func DirectWPKHScriptFromPKH(pkh [20]byte) []byte
- func ElkPointFromHash(in *chainhash.Hash) [33]byte
- func ElkScalar(in *chainhash.Hash) chainhash.Hash
- func FundTxOut(pubA, pubB [33]byte, amt int64) (*wire.TxOut, error)
- func FundTxScript(aPub, bPub [33]byte) ([]byte, bool, error)
- func I32tB(i int32) []byte
- func I64tB(i int64) []byte
- func KeyHashFromPkScript(pkscript []byte) []byte
- func LitAdrBytes(adr string) ([]byte, error)
- func LitAdrFromPubkey(in [33]byte) string
- func LitAdrOK(adr string) bool
- func LitFullAdrDecode(in string) ([33]byte, error)
- func LitFullKeyAdrEncode(in [33]byte) string
- func LitMsgEqual(msg LitMsg, msg2 LitMsg) bool
- func LoadKeyFromFileArg(filename string, pass []byte) (*[32]byte, error)
- func LoadKeyFromFileInteractive(filename string) (*[32]byte, error)
- func MultiplyPointByHash(k *btcec.PublicKey, h chainhash.Hash)
- func OptColor(optional ...interface{}) string
- func OutPointFromBytes(b [36]byte) *wire.OutPoint
- func OutPointToBytes(op wire.OutPoint) (b [36]byte)
- func OutPointsEqual(a, b wire.OutPoint) bool
- func P2WSHify(scriptBytes []byte) []byte
- func PrivKeyAddBytes(k *btcec.PrivateKey, b []byte)
- func PubFromHash(h chainhash.Hash) (p [33]byte)
- func PubKeyAddBytes(k *btcec.PublicKey, b []byte)
- func PubKeyArrAddBytes(p *[33]byte, b []byte) error
- func ReadKeyFile(filename string) (*[32]byte, error)
- func ReqColor(required ...interface{}) string
- func SatoshiColor(value int64) string
- func SaveKeyToFileArg(filename string, priv32 *[32]byte, pass []byte) error
- func SaveKeyToFileInteractive(filename string, priv32 *[32]byte) error
- func TxToString(tx *wire.MsgTx) string
- func U32tB(i uint32) []byte
- func U64tB(i uint64) []byte
- type ChanAckMsg
- type ChanDescMsg
- type ChatMsg
- type CloseReqMsg
- type CombinablePubKeySlice
- type DeltaSigMsg
- type GapSigRevMsg
- type LitMsg
- type OutPointEvent
- type PointReqMsg
- type PointRespMsg
- type RevMsg
- type SigProofMsg
- type SigRevMsg
- type TxAndHeight
- type WatchDelMsg
- type WatchDescMsg
- type WatchStateMsg
Constants ¶
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 ¶
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 ¶
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 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 ¶
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 ¶
CommitScript is the script for 0.13.1: OP_CHECKSIG turned into OP_CHECSIGVERIFY
func DirectWPKHScript ¶
func DirectWPKHScriptFromPKH ¶
func ElkPointFromHash ¶
ElkPoint returns the public key (point) which comes from a node in the elkrem tree (elkrem hash)
func ElkScalar ¶
ElkScalar returns the private key (scalar) which comes from a node in the elkrem tree (elkrem hash)
func FundTxOut ¶
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 ¶
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 KeyHashFromPkScript ¶
KeyHashFromPkScript extracts the 20 or 32 byte hash from a txout PkScript
func LitAdrBytes ¶
LitAdrBytes takes a lit address string and returns either 20 or 12 bytes. Or an error.
func LitAdrFromPubkey ¶
func LitAdrOK ¶
LitAdrOK make sure the address is OK. Either it has a valid checksum, or it's shortened and doesn't.
func LitFullAdrDecode ¶
func LitFullKeyAdrEncode ¶
func LitMsgEqual ¶
func LoadKeyFromFileArg ¶
LoadKeyFromFileArg opens the file and returns the key. If the key is unencrypted it will ignore the password argument.
func LoadKeyFromFileInteractive ¶
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 ¶
PubKeyMultiplyByHash multiplies a pubkey by a hash. returns nothing, modifies in place. Probably the slowest curve operation.
func OutPointFromBytes ¶
OutPointFromBytes gives you an outpoint from 36 bytes. since 36 is enforced, it doesn't error
func OutPointToBytes ¶
outPointToBytes turns an outpoint into 36 bytes.
func OutPointsEqual ¶
need this because before I was comparing pointers maybe? so they were the same outpoint but stored in 2 places so false negative?
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 ¶
HashToPub turns a 32 byte hash into a 33 byte serialized pubkey
func PubKeyAddBytes ¶
PubKeyAddBytes adds bytes to a public key. NOTE that this modifies the key in place, overwriting it!!!!!
func PubKeyArrAddBytes ¶
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 ¶
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 SatoshiColor ¶
func SaveKeyToFileArg ¶
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 ¶
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 ¶
TxToString prints out some info about a transaction. for testing / debugging
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 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 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 CloseReqMsg ¶
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 ¶
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 ¶
message for sending an amount with the signature
func NewDeltaSigMsg ¶
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 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
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 ¶
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 SigProofMsg ¶
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
type TxAndHeight ¶
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 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