2019-03-30 03:27:37 +00:00
|
|
|
use std::fmt::Display;
|
|
|
|
use types::{Keypair, PublicKey, Signature};
|
2019-03-29 05:33:27 +00:00
|
|
|
|
|
|
|
/// Signs message using an internally-maintained private key.
|
2019-03-30 03:48:43 +00:00
|
|
|
pub trait Signer: Display + Send + Sync + Clone {
|
2019-03-30 06:06:43 +00:00
|
|
|
fn sign_message(&self, message: &[u8], domain: u64) -> Option<Signature>;
|
2019-03-30 03:27:37 +00:00
|
|
|
/// Returns a public key for the signer object.
|
|
|
|
fn to_public(&self) -> PublicKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Implements Display and Signer for Keypair */
|
|
|
|
|
|
|
|
impl Signer for Keypair {
|
|
|
|
fn to_public(&self) -> PublicKey {
|
|
|
|
self.pk.clone()
|
|
|
|
}
|
|
|
|
|
2019-03-30 06:06:43 +00:00
|
|
|
fn sign_message(&self, message: &[u8], domain: u64) -> Option<Signature> {
|
2019-03-30 03:27:37 +00:00
|
|
|
Some(Signature::new(message, domain, &self.sk))
|
|
|
|
}
|
2019-03-29 05:33:27 +00:00
|
|
|
}
|