+/// Represents the compressed public key of a node
+#[derive(Clone, Copy)]
+pub struct NodeId([u8; PUBLIC_KEY_SIZE]);
+
+impl NodeId {
+ /// Create a new NodeId from a public key
+ pub fn from_pubkey(pubkey: &PublicKey) -> Self {
+ NodeId(pubkey.serialize())
+ }
+
+ /// Get the public key slice from this NodeId
+ pub fn as_slice(&self) -> &[u8] {
+ &self.0
+ }
+}
+
+impl fmt::Debug for NodeId {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "NodeId({})", log_bytes!(self.0))
+ }
+}
+
+impl core::hash::Hash for NodeId {
+ fn hash<H: core::hash::Hasher>(&self, hasher: &mut H) {
+ self.0.hash(hasher);
+ }
+}
+
+impl Eq for NodeId {}
+
+impl PartialEq for NodeId {
+ fn eq(&self, other: &Self) -> bool {
+ self.0[..] == other.0[..]
+ }
+}
+
+impl cmp::PartialOrd for NodeId {
+ fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
+ Some(self.cmp(other))
+ }
+}
+
+impl Ord for NodeId {
+ fn cmp(&self, other: &Self) -> cmp::Ordering {
+ self.0[..].cmp(&other.0[..])
+ }
+}
+
+impl Writeable for NodeId {
+ fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
+ writer.write_all(&self.0)?;
+ Ok(())
+ }
+}
+
+impl Readable for NodeId {
+ fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
+ let mut buf = [0; PUBLIC_KEY_SIZE];
+ reader.read_exact(&mut buf)?;
+ Ok(Self(buf))
+ }
+}
+