Skip to content

Commit

Permalink
Fix pub_keyed_hash utility fn.
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptoquick committed Mar 2, 2024
1 parent e33f76b commit 95e9039
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "carbonado"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
license = "MIT"
description = "An apocalypse-resistant data storage format for the truly paranoid."
Expand Down
8 changes: 7 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ pub fn bech32_decode(bech32_str: &str) -> Result<(String, Vec<u8>), CarbonadoErr
pub fn pub_keyed_hash(ss: &str, bytes: &[u8]) -> Result<String, CarbonadoError> {
let key = hex::decode(ss)?;
let key_bytes: [u8; 32] = key[0..32].try_into()?;
let pub_keyed_hash = blake3::keyed_hash(&key_bytes, bytes).to_hex().to_string();
let secp = secp256k1::Secp256k1::new();
let secret_key = secp256k1::SecretKey::from_slice(key_bytes.as_slice())?;
let pk = secret_key.public_key(&secp);
let (pk, _parity) = pk.x_only_public_key();
let pub_keyed_hash = blake3::keyed_hash(&pk.serialize(), bytes)
.to_hex()
.to_string();
Ok(pub_keyed_hash)
}

0 comments on commit 95e9039

Please sign in to comment.