Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to signatory v0.17 #89

Merged
merged 1 commit into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tendermint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ prost-amino-derive = { version = "0.4.0" }
rand_os = { version = "0.1" }
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1" }
signatory = { version = "0.12", features = ["ed25519", "ecdsa"] }
signatory-dalek = { version = "0.12" }
signatory = { version = "0.17", features = ["ed25519", "ecdsa"] }
signatory-dalek = "0.17"
signatory-secp256k1 = "0.17"
sha2 = { version = "0.8", default-features = false }
subtle = "2"
subtle-encoding = { version = "0.3", features = ["bech32-preview"] }
tai64 = { version = "3", features = ["chrono"] }
toml = { version = "0.5" }
uuid = { version = "0.7", default-features = false }
zeroize = { version = "1.0", features = ["zeroize_derive"] }
ed25519-dalek = {version = "1.0.0-pre.3", features = ["rand"]}
zeroize = { version = "1.1", features = ["zeroize_derive"] }

[dev-dependencies]
serde_json = "1"
Expand Down
4 changes: 2 additions & 2 deletions tendermint/src/amino_types/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
};
use bytes::BufMut;
use prost::{EncodeError, Message};
use signatory::{ed25519, Signature};
use signatory::ed25519;
use std::convert::TryFrom;

#[derive(Clone, PartialEq, Message)]
Expand Down Expand Up @@ -125,7 +125,7 @@ impl SignableMsg for SignProposalRequest {
}
fn set_signature(&mut self, sig: &ed25519::Signature) {
if let Some(ref mut prop) = self.proposal {
prop.signature = sig.clone().into_vec();
prop.signature = sig.as_ref().to_vec();
}
}
fn validate(&self) -> Result<(), ValidationError> {
Expand Down
4 changes: 2 additions & 2 deletions tendermint/src/amino_types/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
};
use bytes::BufMut;
use prost::{error::EncodeError, Message};
use signatory::{ed25519, Signature};
use signatory::ed25519;
use std::convert::TryFrom;

const VALIDATOR_ADDR_SIZE: usize = 20;
Expand Down Expand Up @@ -177,7 +177,7 @@ impl SignableMsg for SignVoteRequest {
}
fn set_signature(&mut self, sig: &ed25519::Signature) {
if let Some(ref mut vt) = self.vote {
vt.signature = sig.clone().into_vec();
vt.signature = sig.as_ref().to_vec();
}
}
fn validate(&self) -> Result<(), ValidationError> {
Expand Down
13 changes: 9 additions & 4 deletions tendermint/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,15 @@ impl From<serde_json::error::Error> for Error {
}
}

impl From<signatory::Error> for Error {
fn from(_err: signatory::Error) -> Self {
// `signatory::Error` is opaque
err!(ErrorKind::Crypto, "signature error")
impl From<signatory::signature::Error> for Error {
fn from(err: signatory::signature::Error) -> Self {
use std::error::Error as _;

if let Some(source) = err.source() {
err!(ErrorKind::Crypto, "signature error: {}", source)
} else {
err!(ErrorKind::Crypto, "signature error")
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tendermint/src/private_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::public_key::PublicKey;
use serde::{de, de::Error as _, ser, Deserialize, Serialize};
use signatory::ed25519;
use signatory::PublicKeyed;
use signatory::public_key::PublicKeyed;
use signatory_dalek::Ed25519Signer;
use subtle_encoding::{Base64, Encoding};
use zeroize::{Zeroize, Zeroizing};
Expand Down
4 changes: 2 additions & 2 deletions tendermint/src/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use subtle_encoding::{bech32, hex};
/// Public keys allowed in Tendermint protocols
#[derive(Serialize, Deserialize)]
#[serde(tag = "type", content = "value")]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub enum PublicKey {
/// Ed25519 keys
#[serde(
Expand Down Expand Up @@ -104,7 +104,7 @@ impl From<secp256k1::PublicKey> for PublicKey {
}

/// Public key roles used in Tendermint networks
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub enum TendermintKey {
/// User signing keys used for interacting with accounts in the state machine
AccountKey(PublicKey),
Expand Down
16 changes: 9 additions & 7 deletions tendermint/src/signature.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Cryptographic (a.k.a. digital) signatures

use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer};
use signatory::Signature as SignatureTrait;
use signatory::signature::Signature as _;
use subtle_encoding::base64;

/// Signatures
Expand All @@ -21,8 +21,14 @@ impl Signature {

/// Return the raw bytes of this signature
pub fn as_bytes(&self) -> &[u8] {
self.as_ref()
}
}

impl AsRef<[u8]> for Signature {
fn as_ref(&self) -> &[u8] {
match self {
Signature::Ed25519(sig) => sig.as_bytes(),
Signature::Ed25519(sig) => sig.as_ref(),
}
}
}
Expand All @@ -41,11 +47,7 @@ impl<'de> Deserialize<'de> for Signature {

impl Serialize for Signature {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let sig_bytes = match self {
Signature::Ed25519(sig) => sig.as_bytes(),
};

String::from_utf8(base64::encode(&sig_bytes[..]))
String::from_utf8(base64::encode(self.as_ref()))
.unwrap()
.serialize(serializer)
}
Expand Down
8 changes: 4 additions & 4 deletions tendermint/src/validator.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Tendermint validators

use crate::validator::signatory::{Signature, Verifier};
use crate::{account, lite, merkle, vote, Hash, PublicKey};
use prost::Message;
use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer};
use signatory;
use signatory::ed25519;
use signatory_dalek;
use signatory::{
ed25519,
signature::{Signature, Verifier},
};
use signatory_dalek::Ed25519Verifier;
use subtle_encoding::base64;

Expand Down
5 changes: 2 additions & 3 deletions tendermint/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ impl lite::Vote for SignedVote {
self.vote.encode(&mut sign_bytes).unwrap();
sign_bytes
}

fn signature(&self) -> &[u8] {
match &self.signature {
Signature::Ed25519(sig) => sig.as_bytes(),
}
self.signature.as_ref()
}
}

Expand Down