From b4491d6d60d240cb9462b625d890474c3df0a503 Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Fri, 6 Jun 2025 22:44:12 +0200 Subject: [PATCH] Add hash mod --- src/hash.rs | 20 ++++++++++++++++++++ src/lib.rs | 1 + 2 files changed, 21 insertions(+) create mode 100644 src/hash.rs diff --git a/src/hash.rs b/src/hash.rs new file mode 100644 index 0000000..ab87874 --- /dev/null +++ b/src/hash.rs @@ -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) + } +} diff --git a/src/lib.rs b/src/lib.rs index d878123..3b9e08e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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;