1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! Node Network ID
//! nodeId should authenticate a node, i.e. no other node should 
//! be able to steal or fake the nodeId. In the absence of a trustworthy 
//! authority we need to impede the Eclipse and Sybil attack with a crypto puzzle.


use schnorr::PublicKey;
use balloon::balloon;
use mohan::hash::{
    blake256,
    H256
};
use serde::{Deserialize, Serialize};


#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct NetworkID(H256);

//   /// Signing Key
//     pub_key: PublicKey,
//     /// HashCash of Public Key
//     id: H256,
//     /// Crypto Puzzel
//     nonce: u64

impl From<[u8; 32]> for NetworkID {
    fn from(v: [u8; 32]) -> Self {
        NetworkID(H256::from(v))
    }
}

#[cfg(test)]
mod test {
    use super::*;
    use quickcheck::{Arbitrary, Gen};

    impl Arbitrary for NetworkID {
        fn arbitrary<G: Gen>(g: &mut G) -> Self {
            let mut bytes = [0; 32];
            NetworkID::from(bytes)
        }
    }
}