2022-11-17 22:58:44 +00:00
|
|
|
use rand::prelude::*;
|
|
|
|
|
|
|
|
use crate::enc;
|
|
|
|
|
|
|
|
pub use ed25519_dalek::{Keypair, PublicKey, SecretKey, Signature, Signer, Verifier};
|
|
|
|
|
|
|
|
pub fn generate_keypair() -> Keypair {
|
|
|
|
let mut csprng = thread_rng();
|
|
|
|
Keypair::generate(&mut csprng)
|
|
|
|
}
|
|
|
|
|
|
|
|
impl enc::Encode for Keypair {
|
|
|
|
fn term(&self) -> enc::Term<'_> {
|
|
|
|
enc::bytes(&self.to_bytes())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl enc::Encode for PublicKey {
|
|
|
|
fn term(&self) -> enc::Term<'_> {
|
|
|
|
enc::bytes(self.as_bytes())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl enc::Encode for SecretKey {
|
|
|
|
fn term(&self) -> enc::Term<'_> {
|
|
|
|
enc::bytes(self.as_bytes())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl enc::Encode for Signature {
|
|
|
|
fn term(&self) -> enc::Term<'_> {
|
|
|
|
enc::bytes(&self.to_bytes())
|
|
|
|
}
|
|
|
|
}
|