Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
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
41 changes: 11 additions & 30 deletions primitives/core/src/sr25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,14 @@ pub mod vrf {
#[cfg(feature = "full_crypto")]
use crate::crypto::VrfSigner;
use crate::crypto::{VrfCrypto, VrfVerifier};
pub use schnorrkel::vrf::VRF_OUTPUT_LENGTH;
use schnorrkel::{errors::MultiSignatureStage, vrf::VRF_PROOF_LENGTH, SignatureError};
use schnorrkel::{
errors::MultiSignatureStage,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're going to deprecate the current multi-sig there btw, but maybe that does not help you right now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that schnorrkel 0.11 is coming soon. As soon as it is released there will be a follow up PR with renaming of VrfOutput -> VrfPreOut, and all not required stuff removal.

This PR is mostly to prepare the soil for a painless introduction of bandersnatch-vrf

vrf::{VRF_OUTPUT_LENGTH, VRF_PROOF_LENGTH},
SignatureError,
};

/// VRF transcript ready to be used for VRF sign/verify operations.
pub struct VrfTranscript(merlin::Transcript);
pub struct VrfTranscript(pub merlin::Transcript);

impl VrfTranscript {
/// Build a new transcript ready to be used by a VRF signer/verifier.
Expand All @@ -562,14 +565,6 @@ pub mod vrf {
}
}

impl Deref for VrfTranscript {
type Target = merlin::Transcript;

fn deref(&self) -> &Self::Target {
&self.0
}
}

/// VRF signature data
#[derive(Clone, Debug, PartialEq, Eq, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub struct VrfSignature {
Expand All @@ -583,14 +578,6 @@ pub mod vrf {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct VrfOutput(pub schnorrkel::vrf::VRFOutput);

impl Deref for VrfOutput {
type Target = schnorrkel::vrf::VRFOutput;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl Encode for VrfOutput {
fn encode(&self) -> Vec<u8> {
self.0.as_bytes().encode()
Expand Down Expand Up @@ -622,14 +609,6 @@ pub mod vrf {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct VrfProof(pub schnorrkel::vrf::VRFProof);

impl Deref for VrfProof {
type Target = schnorrkel::vrf::VRFProof;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl Encode for VrfProof {
fn encode(&self) -> Vec<u8> {
self.0.to_bytes().encode()
Expand Down Expand Up @@ -680,7 +659,7 @@ pub mod vrf {
fn vrf_verify(&self, transcript: &Self::VrfInput, signature: &Self::VrfSignature) -> bool {
schnorrkel::PublicKey::from_bytes(self)
.and_then(|public| {
public.vrf_verify(transcript.0.clone(), &signature.output, &signature.proof)
public.vrf_verify(transcript.0.clone(), &signature.output.0, &signature.proof.0)
})
.is_ok()
}
Expand Down Expand Up @@ -725,8 +704,10 @@ pub mod vrf {
output: &VrfOutput,
) -> Result<B, codec::Error> {
let pubkey = schnorrkel::PublicKey::from_bytes(public).map_err(convert_error)?;
let inout =
output.attach_input_hash(&pubkey, transcript.0.clone()).map_err(convert_error)?;
let inout = output
.0
.attach_input_hash(&pubkey, transcript.0.clone())
.map_err(convert_error)?;
Ok(inout.make_bytes::<B>(context))
}
}
Expand Down