Add hash mod

This commit is contained in:
NicolasCantu 2025-06-06 22:44:12 +02:00
parent d256ac7074
commit f4baef4145
2 changed files with 21 additions and 0 deletions

20
src/hash.rs Normal file
View File

@ -0,0 +1,20 @@
use sp_client::bitcoin::{
consensus::{serialize, Encodable}, hashes::{sha256t_hash_newtype, Hash, HashEngine}, OutPoint
};
sha256t_hash_newtype! {
pub struct AnkPcdTag = hash_str("4nk/Pcd");
#[hash_newtype(forward)]
pub struct AnkPcdHash(_);
}
impl AnkPcdHash {
pub fn from_pcd_value(value: &[u8], label: &[u8], outpoint: &OutPoint) -> Self {
let mut eng = AnkPcdHash::engine();
eng.input(value);
eng.input(label);
serialize(outpoint).consensus_encode(&mut eng).expect("hash engine don't return errors");
AnkPcdHash::from_engine(eng)
}
}

View File

@ -16,6 +16,7 @@ pub use wasm_bindgen;
pub mod crypto;
pub mod device;
pub mod hash;
pub mod error;
pub mod network;
pub mod pcd;