This repository has been archived by the owner on Jun 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for ECDSA (secp256k1) account keys, with the goal of using them to support KMS-backed Cosmos transaction signing (#386)
- Loading branch information
1 parent
30a7550
commit a323979
Showing
6 changed files
with
144 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//! ECDSA (secp256k1) signing keys | ||
pub use signatory::ecdsa::curve::secp256k1::{FixedSignature as Signature, PublicKey}; | ||
|
||
pub mod signer; | ||
|
||
pub use self::signer::Signer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//! ECDSA (secp256k1) signer | ||
use super::Signature; | ||
use crate::{ | ||
error::{Error, ErrorKind::*}, | ||
keyring::SigningProvider, | ||
prelude::*, | ||
}; | ||
use signatory::signature; | ||
use std::sync::Arc; | ||
use tendermint::TendermintKey; | ||
|
||
/// Trait object wrapper for an Ed25519 signers | ||
#[derive(Clone)] | ||
pub struct Signer { | ||
/// Provider for this signer | ||
provider: SigningProvider, | ||
|
||
/// Tendermint public key | ||
public_key: TendermintKey, | ||
|
||
/// Signer trait object | ||
signer: Arc<Box<dyn signature::Signer<Signature> + Send + Sync>>, | ||
} | ||
|
||
impl Signer { | ||
/// Create a new signer | ||
pub fn new( | ||
provider: SigningProvider, | ||
public_key: TendermintKey, | ||
signer: Box<dyn signature::Signer<Signature> + Send + Sync>, | ||
) -> Self { | ||
Self { | ||
provider, | ||
public_key, | ||
signer: Arc::new(signer), | ||
} | ||
} | ||
|
||
/// Get the Tendermint public key for this signer | ||
pub fn public_key(&self) -> TendermintKey { | ||
self.public_key | ||
} | ||
|
||
/// Get the provider for this signer | ||
pub fn provider(&self) -> SigningProvider { | ||
self.provider | ||
} | ||
|
||
/// Sign the given message using this signer | ||
pub fn sign(&self, msg: &[u8]) -> Result<Signature, Error> { | ||
Ok(self | ||
.signer | ||
.try_sign(msg) | ||
.map_err(|e| format_err!(SigningError, "{}", e))?) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
//! Wrapper for Ed25519 signers | ||
//! Ed25519 signer | ||
use crate::{ | ||
error::{Error, ErrorKind::*}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters