Skip to content

Instantly share code, notes, and snippets.

@Alex8Efremov
Last active October 3, 2022 20:40
Show Gist options
  • Save Alex8Efremov/e50a6a017de67709288ea42656fe7756 to your computer and use it in GitHub Desktop.
Save Alex8Efremov/e50a6a017de67709288ea42656fe7756 to your computer and use it in GitHub Desktop.
for vlad
extern crate rand;
extern crate ed25519_dalek;
extern crate base64;
use rand::rngs::OsRng;
use sha2::Sha512;
use uuid::Uuid;
#[derive(Debug)]
pub struct PublicKey {
pub inner: ed25519_dalek::PublicKey,
}
pub struct SecretKey {
pub inner: ed25519_dalek::Keypair,
}
pub fn generate_relay_id() -> RelayId {
Uuid::new_v4()
}
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();
let secret = base64::encode_config(&kp.secret.to_bytes()[..], base64::URL_SAFE_NO_PAD);
let public = base64::encode_config(&kp.public.to_bytes()[..], base64::URL_SAFE_NO_PAD);
println!("Secret {}\nPublic {}\n", secret,public);
(SecretKey { inner: kp }, PublicKey { inner: pk })
}
pub fn main() {
generate_key_pair();
let (id) = generate_relay_id();
println!("{}", id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment