diff --git a/src/aggregate.rs b/src/aggregate.rs index 94e5209..14e0fbb 100644 --- a/src/aggregate.rs +++ b/src/aggregate.rs @@ -20,7 +20,9 @@ pub struct AggPublicKeyAndMusigCoeff { #[derive(Debug, Clone, PartialEq, Eq)] /// Data required to sign for the derived public key, this is generated when [`AggPublicKeyAndMusigCoeff::derive_key`] is called, /// and this needs to be passed to [`KeyPair::partial_sign_derived`] when signing -pub struct DerivationData(pub(crate) Scalar); +pub struct DerivationData { + pub(crate) scalar: Scalar +} impl AggPublicKeyAndMusigCoeff { /// Aggregate public keys. This creates a combined public key that requires both parties in order to sign messages. @@ -80,7 +82,7 @@ impl AggPublicKeyAndMusigCoeff { musig_coefficient: self.musig_coefficient, location: self.location, }, - DerivationData(delta), + DerivationData { scalar: delta }, ) } @@ -109,17 +111,19 @@ impl AggPublicKeyAndMusigCoeff { } /// The aggregated nonce of both parties, required for aggregating the signatures. -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct AggregatedNonce(pub(crate) EdwardsPoint); +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct AggregatedNonce { + pub(crate) point: EdwardsPoint +} impl AggregatedNonce { /// Serialize the aggregated nonce pub fn serialize(&self) -> [u8; 32] { - self.0.compress().0 + self.point.compress().0 } /// Deserialize the aggregated nonce pub fn deserialize(bytes: [u8; 32]) -> Option { - edwards_from_bytes(&bytes).map(Self) + edwards_from_bytes(&bytes).map(|x| Self { point: x }) } } diff --git a/src/keypair.rs b/src/keypair.rs index 26661ce..e5029eb 100644 --- a/src/keypair.rs +++ b/src/keypair.rs @@ -74,8 +74,8 @@ impl KeyPair { // Only one party needs to adjust the signature, so we limit to just the "first" party in the ordered set. if agg_public_key.location == KeySortedLocation::First { - let challenge = Signature::k(&nonce.0, &agg_public_key.agg_public_key, message); - sig.0 += derived_data.0 * challenge; + let challenge = Signature::k(&nonce.point, &agg_public_key.agg_public_key, message); + sig.scalar += derived_data.scalar * challenge; } (sig, nonce) } @@ -119,8 +119,8 @@ impl KeyPair { let partial_signature = effective_r + (agg_public_key.musig_coefficient * self.private_key * sig_challenge); ( - PartialSignature(partial_signature), - AggregatedNonce(effective_R), + PartialSignature { scalar: partial_signature }, + AggregatedNonce{ point: effective_R }, ) } diff --git a/src/partial_sig.rs b/src/partial_sig.rs index 2d72a40..16ffb5c 100644 --- a/src/partial_sig.rs +++ b/src/partial_sig.rs @@ -5,16 +5,18 @@ use curve25519_dalek::scalar::Scalar; /// A partial signature, should be aggregated with another partial signature under the same aggregated public key and message. #[derive(Debug, Clone, PartialEq, Eq)] -pub struct PartialSignature(pub(crate) Scalar); +pub struct PartialSignature{ + pub(crate) scalar: Scalar +} impl PartialSignature { /// Serialize the partial signature pub fn serialize(&self) -> [u8; 32] { - self.0.to_bytes() + self.scalar.to_bytes() } /// Deserialize the partial signature, returns None if the bytes cannot represent a signature. pub fn deserialize(bytes: [u8; 32]) -> Option { - scalar_from_bytes(&bytes).map(Self) + scalar_from_bytes(&bytes).map(|x| Self { scalar: x }) } } diff --git a/src/private_partial_nonces.rs b/src/private_partial_nonces.rs index 612e3e6..5052bcf 100644 --- a/src/private_partial_nonces.rs +++ b/src/private_partial_nonces.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; use zeroize::Zeroize; -#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] /// Private Partial Nonces, they should be kept until partially signing a message and then they should be discarded. /// /// SECURITY: Reusing them across signatures will cause the private key to leak diff --git a/src/signature.rs b/src/signature.rs index 734cc5e..81d0051 100644 --- a/src/signature.rs +++ b/src/signature.rs @@ -35,8 +35,8 @@ impl Signature { partial_sigs: [PartialSignature; 2], ) -> Self { Self { - R: aggregated_nonce.0, - s: partial_sigs[0].0 + partial_sigs[1].0, + R: aggregated_nonce.point, + s: partial_sigs[0].scalar + partial_sigs[1].scalar, } } /// Verify an ed25519 signature, this is a strict verification and requires both the public key