From e825a756f4008481fc63839cfd0530a015319ab5 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Tue, 23 Oct 2018 18:28:32 -0700 Subject: [PATCH] watchtower/wtdb/session_id: adds SessoinID, client pubkey --- watchtower/wtdb/session_id.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 watchtower/wtdb/session_id.go diff --git a/watchtower/wtdb/session_id.go b/watchtower/wtdb/session_id.go new file mode 100644 index 00000000..7980b1f6 --- /dev/null +++ b/watchtower/wtdb/session_id.go @@ -0,0 +1,26 @@ +package wtdb + +import ( + "encoding/hex" + + "github.com/btcsuite/btcd/btcec" +) + +// SessionIDSize is 33-bytes; it is a serialized, compressed public key. +const SessionIDSize = 33 + +// SessionID is created from the remote public key of a client, and serves as a +// unique identifier and authentication for sending state updates. +type SessionID [SessionIDSize]byte + +// NewSessionIDFromPubKey creates a new SessionID from a public key. +func NewSessionIDFromPubKey(pubKey *btcec.PublicKey) SessionID { + var sid SessionID + copy(sid[:], pubKey.SerializeCompressed()) + return sid +} + +// String returns a hex encoding of the session id. +func (s SessionID) String() string { + return hex.EncodeToString(s[:]) +}