From 16b3c045ca599f5512df1d9637d90d36020ec772 Mon Sep 17 00:00:00 2001
From: Vladimir Komendantskiy <komendantsky@gmail.com>
Date: Tue, 12 Jun 2018 10:24:09 +0100
Subject: [PATCH] extended the common coin nonce with a global UID and the
 top-level epoch

---
 mod.rs | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/mod.rs b/mod.rs
index db100c4..8d2aa02 100644
--- a/mod.rs
+++ b/mod.rs
@@ -4,6 +4,9 @@ pub mod keygen;
 mod serde_impl;
 
 use self::keygen::{Commitment, Poly};
+
+use std::fmt;
+
 use byteorder::{BigEndian, ByteOrder};
 use init_with::InitWith;
 use pairing::{CurveAffine, CurveProjective, Engine, Field, PrimeField};
@@ -11,6 +14,7 @@ use rand::{ChaChaRng, OsRng, Rng, SeedableRng};
 use ring::digest;
 
 use self::error::{ErrorKind, Result};
+use fmt::HexBytes;
 
 /// The number of words (`u32`) in a ChaCha RNG seed.
 const CHACHA_RNG_SEED_SIZE: usize = 8;
@@ -56,12 +60,25 @@ impl<E: Engine> PublicKey<E> {
         let w = hash_g1_g2::<E, _>(u, &v).into_affine().mul(r);
         Ciphertext(u, v, w)
     }
+
+    /// Returns a byte string representation of the public key.
+    pub fn to_bytes(&self) -> Vec<u8> {
+        self.0.into_affine().into_compressed().as_ref().to_vec()
+    }
 }
 
 /// A signature, or a signature share.
-#[derive(Clone, Debug, PartialOrd)]
+#[derive(Clone, PartialOrd)]
 pub struct Signature<E: Engine>(E::G2);
 
+impl<E: Engine> fmt::Debug for Signature<E> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        let uncomp = self.0.into_affine().into_uncompressed();
+        let bytes = uncomp.as_ref();
+        write!(f, "{:?}", HexBytes(bytes))
+    }
+}
+
 impl<E: Engine> PartialEq for Signature<E> {
     fn eq(&self, other: &Signature<E>) -> bool {
         self.0 == other.0
@@ -73,8 +90,8 @@ impl<E: Engine> Signature<E> {
         let uncomp = self.0.into_affine().into_uncompressed();
         let bytes = uncomp.as_ref();
         let xor_bytes: u8 = bytes.iter().fold(0, |result, byte| result ^ byte);
-        let parity = 0 == xor_bytes % 2;
-        debug!("Signature: {:?}, output: {}", bytes, parity);
+        let parity = 0 != xor_bytes % 2;
+        debug!("Signature: {:?}, output: {}", HexBytes(bytes), parity);
         parity
     }
 }