feat: introduce wallet crate for ed25519-bip32 key management (#342)

Co-authored-by: Santiago Carmuega <santiago@carmuega.me>
This commit is contained in:
Harper 2023-12-03 14:31:27 +00:00 committed by GitHub
parent f9ea2c4790
commit 90c66047c5
6 changed files with 265 additions and 2 deletions

View file

@ -1,6 +1,9 @@
use crate::{ComputeHash, OriginalHash};
use pallas_codec::utils::KeepRaw;
use pallas_crypto::hash::{Hash, Hasher};
use pallas_crypto::{
hash::{Hash, Hasher},
key::ed25519::PublicKey,
};
use pallas_primitives::{alonzo, babbage, byron, conway};
impl ComputeHash<32> for byron::EbbHead {
@ -168,6 +171,12 @@ impl OriginalHash<32> for KeepRaw<'_, conway::MintedTransactionBody<'_>> {
}
}
impl ComputeHash<28> for PublicKey {
fn compute_hash(&self) -> Hash<28> {
Hasher::<224>::hash(&Into::<[u8; PublicKey::SIZE]>::into(*self))
}
}
#[cfg(test)]
mod tests {
use crate::{Era, MultiEraTx};
@ -176,6 +185,7 @@ mod tests {
use pallas_codec::utils::Int;
use pallas_codec::{minicbor, utils::Bytes};
use pallas_crypto::hash::Hash;
use pallas_crypto::key::ed25519::PublicKey;
use pallas_primitives::babbage::MintedDatumOption;
use pallas_primitives::{alonzo, babbage, byron};
use std::str::FromStr;
@ -394,4 +404,19 @@ mod tests {
}
}
}
#[test]
fn test_public_key_hash() {
let key: [u8; 32] =
hex::decode("2354bc4e1ae230e3a9047b568848fdd4bccd8d9aa60e6d1426baa730908e662d")
.unwrap()
.try_into()
.unwrap();
let pk = PublicKey::from(key);
assert_eq!(
pk.compute_hash().to_vec(),
hex::decode("2b6b3949d380fea6cb1c1cf88490ea40b2c1ce87717df7869cb1c38e").unwrap()
)
}
}