Skip to content
This repository has been archived by the owner on Feb 25, 2021. It is now read-only.

Commit

Permalink
Upgrade to signatory v0.17 (informalsystems#89) (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
linfeng-crypto authored and tomtau committed Dec 13, 2019
1 parent 8e95731 commit 6fca043
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 27 deletions.
9 changes: 4 additions & 5 deletions tendermint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,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.16", features = ["ed25519", "ecdsa"] }
signatory-dalek = { version = "0.16" }
signatory-secp256k1 = { version = "0.16", optional = true }
signature = { version = "1.0.0-pre.1", default-features = false }
signatory = { version = "0.17", features = ["ed25519", "ecdsa"] }
signatory-dalek = "0.17"
signatory-secp256k1 = { version = "0.17", optional = true }
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 = "0.9" }
zeroize = { version = "1.1", features = ["zeroize_derive"] }

[dev-dependencies]
serde_json = "1"
Expand Down
2 changes: 1 addition & 1 deletion tendermint/src/amino_types/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,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().to_bytes().to_vec();
prop.signature = sig.as_ref().to_vec();
}
}
fn validate(&self) -> Result<(), ValidationError> {
Expand Down
2 changes: 1 addition & 1 deletion tendermint/src/amino_types/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,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().to_bytes().to_vec();
vt.signature = sig.as_ref().to_vec();
}
}
fn validate(&self) -> Result<(), ValidationError> {
Expand Down
15 changes: 10 additions & 5 deletions tendermint/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,16 @@ impl From<serde_json::error::Error> for Error {
}
}

impl From<signature::Error> for Error {
fn from(_err: signature::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")
}
}
}

impl From<subtle_encoding::Error> for Error {
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 signature::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.0,
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.to_bytes(),
};

String::from_utf8(base64::encode(&sig_bytes[..]))
String::from_utf8(base64::encode(self.as_ref()))
.unwrap()
.serialize(serializer)
}
Expand Down
10 changes: 5 additions & 5 deletions tendermint/src/validator.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Tendermint validators
use crate::amino_types::message::AminoMessage;
use crate::{account, lite, merkle, vote, Hash, PublicKey};
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 signature::{Signature, Verifier};
//use signature::{Signature, Verifier};
use subtle_encoding::base64;

/// Validator set contains a vector of validators
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 {
fn sign_bytes(&self) -> Vec<u8> {
self.vote.bytes_vec_length_delimited()
}

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

Expand Down

0 comments on commit 6fca043

Please sign in to comment.