From 95e903970c18af7a4b942c710b45fc5977bcb9cb Mon Sep 17 00:00:00 2001 From: Hunter Trujillo Date: Sat, 2 Mar 2024 12:17:14 -0700 Subject: [PATCH] Fix pub_keyed_hash utility fn. --- Cargo.toml | 2 +- src/utils.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 64f87d5..1a0ab61 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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." diff --git a/src/utils.rs b/src/utils.rs index 14972b8..b308094 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -67,6 +67,12 @@ pub fn bech32_decode(bech32_str: &str) -> Result<(String, Vec), CarbonadoErr pub fn pub_keyed_hash(ss: &str, bytes: &[u8]) -> Result { 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) }