Created
February 12, 2019 17:54
-
-
Save adrianbrink/b72d8a7329616a8d72fef0b6cf7d5563 to your computer and use it in GitHub Desktop.
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
Error: | |
``` | |
➜ kms git:(master) ✗ cargo build --features ledger | |
Compiling tmkms v0.3.0 (/Users/adrian/code/tendermint/kms) | |
error[E0599]: no method named `public_key` found for type `std::boxed::Box<signatory_ledger_cosval::Ed25519CosmosAppSigner>` in the current scope | |
--> src/keyring/ed25519/ledger.rs:24:18 | |
| | |
24 | provider.public_key()?, | |
| ^^^^^^^^^^ | |
| | |
= help: items from traits can only be used if the trait is in scope | |
= note: the following trait is implemented but not in scope, perhaps add a `use` for it: | |
`use signatory::public_key::PublicKeyed;` | |
error[E0277]: the trait bound `signatory_ledger_cosval::Ed25519CosmosAppSigner: signatory::Signer<signatory::Ed25519Signature>` is not satisfied | |
--> src/keyring/ed25519/ledger.rs:25:66 | |
| | |
25 | Signer::new(LEDGER_PROVIDER_LABEL, LEDGER_ID.to_owned(), provider), | |
| ^^^^^^^^ the trait `signatory::Signer<signatory::Ed25519Signature>` is not implemented for `signatory_ledger_cosval::Ed25519CosmosAppSigner` | |
| | |
= note: required for the cast to the object type `dyn signatory::Signer<signatory::Ed25519Signature>` | |
error: aborting due to 2 previous errors | |
``` | |
```rust | |
//! Ledger-based signer | |
use signatory_ledger_cosval::Ed25519CosmosAppSigner; | |
use signatory::PublicKeyed; | |
use crate::{ | |
config::provider::ledger::LedgerConfig, | |
error::KmsError, | |
keyring::{ed25519::Signer, KeyRing}, | |
}; | |
/// Label for ed25519-dalek provider | |
// TODO: use a non-string type for these, e.g. an enum | |
pub const LEDGER_PROVIDER_LABEL: &str = "ledger"; | |
// TODO: Maybe make this depend on the app. This may not matter since the Ledger doesn't hold multiple keys. Could work with HD deriv path. | |
pub const LEDGER_ID: &str = "1"; | |
/// Create hardware-backed YubiHSM signer objects from the given configuration | |
pub fn init(keyring: &mut KeyRing, ledger_configs: &[LedgerConfig]) -> Result<(), KmsError> { | |
// TODO: Maybe use the active field from the config. | |
let provider = Box::new(Ed25519CosmosAppSigner::connect().unwrap()); | |
keyring.add( | |
provider.public_key()?, | |
Signer::new(LEDGER_PROVIDER_LABEL, LEDGER_ID.to_owned(), provider), | |
)?; | |
Ok(()) | |
} | |
``` | |
```rust | |
use signatory::{ | |
ed25519, | |
error::{Error, ErrorKind}, | |
PublicKeyed, Signer, | |
}; | |
/// ed25519 signature provider for the ledger cosmos validator app | |
pub struct Ed25519CosmosAppSigner { | |
app: Arc<Mutex<ledger_cosmos::CosmosValidatorApp>>, | |
} | |
impl Ed25519CosmosAppSigner { | |
/// Create a new ed25519 signer based on ledger nano s - cosmos validator app | |
pub fn connect() -> Result<Self, Error> { | |
match ledger_cosmos::CosmosValidatorApp::connect() { | |
Ok(validator_app) => { | |
let app = Arc::new(Mutex::new(validator_app)); | |
let signer = Ed25519CosmosAppSigner { app }; | |
let _pk = signer.public_key().unwrap(); | |
Ok(signer) | |
} | |
Err(err) => Err(Error::new(ErrorKind::ProviderError, Some(&err.to_string()))), | |
} | |
} | |
} | |
impl PublicKeyed<ed25519::PublicKey> for Ed25519CosmosAppSigner { | |
/// Returns the public key that corresponds cosmos validator app connected to this signer | |
fn public_key(&self) -> Result<ed25519::PublicKey, Error> { | |
let app = self.app.lock().unwrap(); | |
match app.public_key() { | |
Ok(pk) => Ok(ed25519::PublicKey(pk)), | |
Err(err) => Err(Error::new(ErrorKind::ProviderError, Some(&err.to_string()))), | |
} | |
} | |
} | |
impl Signer<ed25519::Signature> for Ed25519CosmosAppSigner { | |
/// c: Compute a compact, fixed-sized signature of the given amino/json vote | |
fn sign(&self, msg: &[u8]) -> Result<ed25519::Signature, Error> { | |
let app = self.app.lock().unwrap(); | |
match app.sign(&msg) { | |
Ok(sig) => Ok(ed25519::Signature(sig)), | |
Err(err) => Err(Error::new(ErrorKind::ProviderError, Some(&err.to_string()))), | |
} | |
} | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment