From dd96dc2212626ab63601ce5aa3192740891d2072 Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Sun, 25 Jun 2023 16:59:30 +0300 Subject: [PATCH] ed_privkey_to_pubkey --- p2p-repo/src/utils.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/p2p-repo/src/utils.rs b/p2p-repo/src/utils.rs index ffcef32..da6b56f 100644 --- a/p2p-repo/src/utils.rs +++ b/p2p-repo/src/utils.rs @@ -26,6 +26,12 @@ pub fn decode_key(key_string: &str) -> Result<[u8; 32], ()> { .map_err(|_| log_err!("key has invalid content array"))?) } +pub fn ed_privkey_to_pubkey(privkey: &PrivKey) -> PubKey { + let sk = SecretKey::from_bytes(privkey.slice()).unwrap(); + let pk: PublicKey = (&sk).into(); + PubKey::Ed25519PubKey(pk.to_bytes()) +} + pub fn generate_null_keypair() -> (PrivKey, PubKey) { let master_key: [u8; 32] = [0; 32]; let sk = SecretKey::from_bytes(&master_key).unwrap();