use rand::rngs::OsRng;
use ed25519_dalek::{ Keypair, Signer, Verifier };
use x25519_dalek::{ EphemeralSecret, PublicKey };

fn main() {
    let mut csprng = OsRng{};
    let keypair = Keypair::generate(&mut csprng);
    println!("Key pair: {:#?}", keypair);

    let message = b"This is sign test message.";
    let signature = keypair.sign(message);
    println!("Signature: {}", hex::encode(signature));

    let public_key = keypair.public;
    println!("Verify result: {:?}", public_key.verify(message, &signature));

    // key exchange
    let alice_secret = EphemeralSecret::new(OsRng);
    let alice_public = PublicKey::from(&alice_secret);
    let bob_secret = EphemeralSecret::new(OsRng);
    let bob_public = PublicKey::from(&bob_secret);
    
    let alice_shared_secret = alice_secret.diffie_hellman(&bob_public);
    let bob_shared_secret = bob_secret.diffie_hellman(&alice_public);

    println!("Alice shared secret: {}", hex::encode(alice_shared_secret.as_bytes()));
    println!("Bob   shared secret: {}", hex::encode(bob_shared_secret.as_bytes()));
}
