Created
October 3, 2022 09:36
-
-
Save Alex8Efremov/359a7a25b15df007bc35da26b345ec2b to your computer and use it in GitHub Desktop.
for rust community
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate rand; | |
extern crate ed25519_dalek; | |
use rand::rngs::OsRng; | |
use sha2::Sha512; | |
use ed25519_dalek::KEYPAIR_LENGTH; | |
#[derive(Debug)] | |
pub struct PublicKey { | |
pub inner: ed25519_dalek::PublicKey, | |
} | |
pub struct SecretKey { | |
pub inner: ed25519_dalek::Keypair, | |
} | |
pub fn generate_key_pair() -> (SecretKey, PublicKey) { | |
let mut csprng = OsRng::new().unwrap(); | |
let kp = ed25519_dalek::Keypair::generate::<Sha512, _>(&mut csprng); | |
let pk = ed25519_dalek::PublicKey::from_bytes(&kp.public.as_bytes()[..]).unwrap(); | |
println!("kp.sec \n{:?}\n", kp); | |
let keypair_bytes: [u8; KEYPAIR_LENGTH] = kp.to_bytes(); | |
println!("{:?}\n",(keypair_bytes)); | |
(SecretKey { inner: kp }, PublicKey { inner: pk }) | |
} | |
pub fn main() { | |
generate_key_pair(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment