diff --git a/rust-k256/Cargo.toml b/rust-k256/Cargo.toml index 5d3df2e..688e946 100644 --- a/rust-k256/Cargo.toml +++ b/rust-k256/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "plume_rustcrypto" -version = "0.2.0" +version = "0.2.1" edition = "2021" license = "MIT" description = "Implementation of PLUME: nullifier friendly signature scheme on ECDSA; using the k256 library" @@ -17,7 +17,12 @@ num-bigint = "~0.4.3" num-integer = "~0.1.45" k256 = {version = "~0.13.3", features = ["arithmetic", "hash2curve", "expose-field", "sha2"]} signature = "^2.2.0" +serde = { version = "^1.0.0", features = ["derive"], optional = true } [dev-dependencies] hex = "0.4.3" -hex-literal = "0.3.4" \ No newline at end of file +hex-literal = "0.3.4" + +[features] +default = ["serde"] +serde = ["dep:serde", "k256/serde"] diff --git a/rust-k256/src/lib.rs b/rust-k256/src/lib.rs index 6af0ca4..f0e66dc 100644 --- a/rust-k256/src/lib.rs +++ b/rust-k256/src/lib.rs @@ -44,6 +44,10 @@ pub use k256::{AffinePoint, NonZeroScalar, SecretKey}; /// Re-exports the [`CryptoRngCore`] trait from the [`rand_core`] crate. /// This allows it to be used from the current module. pub use rand_core::CryptoRngCore; +#[cfg(feature = "serde")] +/// Provides the ability to serialize and deserialize data using the Serde library. +/// The `Serialize` and `Deserialize` traits from the Serde library are re-exported for convenience. +pub use serde::{Deserialize, Serialize}; mod utils; // not published due to use of `Projective...`; these utils can be found in other crates @@ -59,6 +63,7 @@ pub const DST: &[u8] = b"QUUX-V01-CS02-with-secp256k1_XMD:SHA-256_SSWU_RO_"; // /// Struct holding signature data for a PLUME signature. /// /// `v1specific` field differintiate whether V1 or V2 protocol will be used. +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct PlumeSignature { /// The message that was signed. pub message: Vec, @@ -75,6 +80,7 @@ pub struct PlumeSignature { } /// Nested struct holding additional signature data used in variant 1 of the protocol. #[derive(Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct PlumeSignatureV1Fields { /// Part of the signature data, a curve point. pub r_point: AffinePoint, diff --git a/rust-k256/src/randomizedsigner.rs b/rust-k256/src/randomizedsigner.rs index bb0d14a..e066467 100644 --- a/rust-k256/src/randomizedsigner.rs +++ b/rust-k256/src/randomizedsigner.rs @@ -15,10 +15,13 @@ use k256::{ use signature::{Error, RandomizedSigner}; /// `PlumeSigner` is a `struct` that contains a reference to a secret key and a -/// boolean defining output [`PlumeSignature`] variant. It implements the -/// `RandomizedSigner` trait to generate signatures using the provided secret -/// key. The struct is generic over the lifetime of the secret key reference -/// so that the key can be borrowed immutably. +/// boolean defining output [`PlumeSignature`] variant. +/// +/// It implements the `RandomizedSigner` trait to generate signatures using the provided secret +/// key. The struct is generic over the lifetime of the secret key reference so that the key can be borrowed immutably. +/// +/// `serde` traits aren't added to this struct on purpose. It's a wrapper around [`SecretKey`] which provides variety of serialization formats (SEC1, bytes, ...). +/// Also it uses just a reference to the secret key itself, so the choices for handling the key is kept open here. pub struct PlumeSigner<'signing> { /// The secret key to use for signing. This is borrowed immutably. secret_key: &'signing SecretKey,