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
520727f
commit 9fccdb2
Showing
13 changed files
with
309 additions
and
49 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,9 @@ | ||
//! ECDSA (secp256k1) signing keys | ||
pub use signatory::ecdsa::curve::secp256k1::{FixedSignature as Signature, PublicKey, SecretKey}; | ||
|
||
pub mod signer; | ||
#[cfg(feature = "softsign")] | ||
pub mod softsign; | ||
|
||
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 ECDSA 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 ECDSA 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))?) | ||
} | ||
} |
Oops, something went wrong.