github.com/decred/dcrlnd@v0.7.6/watchtower/wtdb/session_id.go (about) 1 package wtdb 2 3 import ( 4 "encoding/hex" 5 6 "github.com/decred/dcrd/dcrec/secp256k1/v4" 7 ) 8 9 // SessionIDSize is 33-bytes; it is a serialized, compressed public key. 10 const SessionIDSize = 33 11 12 // SessionID is created from the remote public key of a client, and serves as a 13 // unique identifier and authentication for sending state updates. 14 type SessionID [SessionIDSize]byte 15 16 // NewSessionIDFromPubKey creates a new SessionID from a public key. 17 func NewSessionIDFromPubKey(pubKey *secp256k1.PublicKey) SessionID { 18 var sid SessionID 19 copy(sid[:], pubKey.SerializeCompressed()) 20 return sid 21 } 22 23 // String returns a hex encoding of the session id. 24 func (s SessionID) String() string { 25 return hex.EncodeToString(s[:]) 26 }