From 8bcfeae920480e637f1b6031f3d8e4723250be3b Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Tue, 3 Dec 2019 22:33:27 -0800 Subject: [PATCH] Add a basic test. This ran into problems with Clone/Copy bounds -- it seems like the derived impls require that the phantom type T also be Clone / Copy / Debug for the type to be. This commit does a hacky fix that makes it work for now, but it should be cleaned up later. --- Cargo.toml | 3 +++ src/lib.rs | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d5d0dcc..a17c9c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,5 +10,8 @@ thiserror = "1.0" blake2b_simd = "0.5" jubjub = { git = "https://github.com/zkcrypto/jubjub", rev = "e83f7d2bd136498a27f9d943fea635d8682bf2c6" } +[dev-dependencies] +rand = "0.7" + [features] nightly = [] diff --git a/src/lib.rs b/src/lib.rs index ec359c4..ca9fabd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,16 +39,18 @@ pub use signature::Signature; pub trait SigType: private::Sealed {} /// A type variable corresponding to Zcash's `BindingSig`. +#[derive(Copy, Clone, Debug)] pub struct Binding {} impl SigType for Binding {} /// A type variable corresponding to Zcash's `SpendAuthSig`. +#[derive(Copy, Clone, Debug)] pub struct SpendAuth {} impl SigType for SpendAuth {} pub(crate) mod private { use super::*; - pub trait Sealed { + pub trait Sealed: Copy + Clone + std::fmt::Debug { fn basepoint() -> jubjub::ExtendedPoint; } impl Sealed for Binding { @@ -66,3 +68,18 @@ pub(crate) mod private { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn sign_and_verify() { + let sk = SecretKey::::new(rand::thread_rng()); + let msg = b"test"; + let sig = sk.sign(rand::thread_rng(), msg); + let pk = PublicKey::from(&sk); + + assert_eq!(pk.verify(msg, &sig), Ok(())); + } +}