Improve message-signing ergonomics

This commit is contained in:
Greg Fitzgerald
2019-01-25 23:41:20 -07:00
parent 1bae87d4b3
commit 33f921235d
8 changed files with 36 additions and 39 deletions

View File

@@ -35,7 +35,7 @@ impl Signature {
pub trait Signable {
fn sign(&mut self, keypair: &Keypair) {
let data = self.signable_data();
self.set_signature(Signature::new(&keypair.sign(&data).as_ref()));
self.set_signature(keypair.sign_message(&data));
}
fn verify(&self) -> bool {
self.get_signature()
@@ -69,6 +69,7 @@ impl fmt::Display for Signature {
pub trait KeypairUtil {
fn new() -> Self;
fn pubkey(&self) -> Pubkey;
fn sign_message(&self, message: &[u8]) -> Signature;
}
impl KeypairUtil for Ed25519KeyPair {
@@ -83,6 +84,10 @@ impl KeypairUtil for Ed25519KeyPair {
fn pubkey(&self) -> Pubkey {
Pubkey::new(self.public_key_bytes())
}
fn sign_message(&self, message: &[u8]) -> Signature {
Signature::new(self.sign(message).as_ref())
}
}
pub fn read_pkcs8(path: &str) -> Result<Vec<u8>, Box<error::Error>> {