1pub use platform_value::Identifier;
2pub use platform_value::IDENTIFIER_MEDIA_TYPE as MEDIA_TYPE;
3use sha2::{Digest, Sha256};
4
5pub trait MasternodeIdentifiers {
6 fn create_voter_identifier(pro_tx_hash: &[u8; 32], voting_address: &[u8; 20]) -> Identifier;
7
8 fn create_operator_identifier(pro_tx_hash: &[u8; 32], pub_key_operator: &[u8]) -> Identifier;
9}
10
11trait IdentifierConstructorPrivate {
12 fn hash_protxhash_with_key_data(pro_tx_hash: &[u8; 32], key_data: &[u8]) -> Identifier;
13}
14impl MasternodeIdentifiers for Identifier {
15 fn create_voter_identifier(pro_tx_hash: &[u8; 32], voting_address: &[u8; 20]) -> Identifier {
16 Self::hash_protxhash_with_key_data(pro_tx_hash, voting_address)
17 }
18
19 fn create_operator_identifier(pro_tx_hash: &[u8; 32], pub_key_operator: &[u8]) -> Identifier {
20 Self::hash_protxhash_with_key_data(pro_tx_hash, pub_key_operator)
21 }
22}
23
24impl IdentifierConstructorPrivate for Identifier {
25 fn hash_protxhash_with_key_data(pro_tx_hash: &[u8; 32], key_data: &[u8]) -> Identifier {
26 let mut hasher = Sha256::new();
27 hasher.update(pro_tx_hash);
28 hasher.update(key_data);
29 let bytes: [u8; 32] = hasher.finalize().into();
30 bytes.into()
31 }
32}