Struct sp_consensus_vrf::schnorrkel::PublicKey
source · pub struct PublicKey(_);Expand description
A Ristretto Schnorr public key.
Internally, these are represented as a RistrettoPoint, meaning
an Edwards point with a static guarantee to be 2-torsion free.
At present, we decompress PublicKeys into this representation
during deserialization, which improves error handling, but costs
a compression during signing and verifiaction.
Implementations§
source§impl PublicKey
impl PublicKey
sourcepub fn as_compressed(&self) -> &CompressedRistretto
pub fn as_compressed(&self) -> &CompressedRistretto
Access the compressed Ristretto form
sourcepub fn into_compressed(self) -> CompressedRistretto
pub fn into_compressed(self) -> CompressedRistretto
Extract the compressed Ristretto form
sourcepub fn as_point(&self) -> &RistrettoPoint
pub fn as_point(&self) -> &RistrettoPoint
Access the point form
sourcepub fn into_point(self) -> RistrettoPoint
pub fn into_point(self) -> RistrettoPoint
Extract the point form
sourcepub fn from_compressed(
compressed: CompressedRistretto
) -> Result<PublicKey, SignatureError>
pub fn from_compressed(
compressed: CompressedRistretto
) -> Result<PublicKey, SignatureError>
Decompress into the PublicKey format that also retains the
compressed form.
sourcepub fn from_point(point: RistrettoPoint) -> PublicKey
pub fn from_point(point: RistrettoPoint) -> PublicKey
Compress into the PublicKey format that also retains the
uncompressed form.
sourcepub fn to_bytes(&self) -> [u8; 32]
pub fn to_bytes(&self) -> [u8; 32]
Convert this public key to a byte array.
Example
use schnorrkel::{SecretKey, PublicKey, PUBLIC_KEY_LENGTH, SignatureError};
let public_key: PublicKey = SecretKey::generate().to_public();
let public_key_bytes = public_key.to_bytes();
let public_key_again: PublicKey = PublicKey::from_bytes(&public_key_bytes[..]).unwrap();
assert_eq!(public_key_bytes, public_key_again.to_bytes());sourcepub fn from_bytes(bytes: &[u8]) -> Result<PublicKey, SignatureError>
pub fn from_bytes(bytes: &[u8]) -> Result<PublicKey, SignatureError>
Construct a PublicKey from a slice of bytes.
Example
use schnorrkel::{PublicKey, PUBLIC_KEY_LENGTH, SignatureError};
let public_key_bytes: [u8; PUBLIC_KEY_LENGTH] = [
208, 120, 140, 129, 177, 179, 237, 159,
252, 160, 028, 013, 206, 005, 211, 241,
192, 218, 001, 097, 130, 241, 020, 169,
119, 046, 246, 029, 079, 080, 077, 084];
let public_key = PublicKey::from_bytes(&public_key_bytes).unwrap();
assert_eq!(public_key.to_bytes(), public_key_bytes);Returns
A Result whose okay value is an EdDSA PublicKey or whose error value
is an SignatureError describing the error that occurred.
source§impl PublicKey
impl PublicKey
sourcepub fn verify<T>(&self, t: T, signature: &Signature) -> Result<(), SignatureError>where
T: SigningTranscript,
pub fn verify<T>(&self, t: T, signature: &Signature) -> Result<(), SignatureError>where
T: SigningTranscript,
Verify a signature by this public key on a transcript.
Requires a SigningTranscript, normally created from a
SigningContext and a message, as well as the signature
to be verified.
sourcepub fn verify_simple(
&self,
ctx: &[u8],
msg: &[u8],
signature: &Signature
) -> Result<(), SignatureError>
pub fn verify_simple(
&self,
ctx: &[u8],
msg: &[u8],
signature: &Signature
) -> Result<(), SignatureError>
Verify a signature by this public key on a message.
sourcepub fn verify_simple_preaudit_deprecated(
&self,
ctx: &'static [u8],
msg: &[u8],
sig: &[u8]
) -> Result<(), SignatureError>
pub fn verify_simple_preaudit_deprecated(
&self,
ctx: &'static [u8],
msg: &[u8],
sig: &[u8]
) -> Result<(), SignatureError>
A temporary verification routine for use in transitioning substrate testnets only.
source§impl PublicKey
impl PublicKey
sourcepub fn vrf_hash<T>(&self, t: T) -> RistrettoBothwhere
T: VRFSigningTranscript,
pub fn vrf_hash<T>(&self, t: T) -> RistrettoBothwhere
T: VRFSigningTranscript,
Create a non-malleable VRF input point by hashing a transcript to a point.
sourcepub fn vrf_attach_hash<T>(
&self,
output: VRFOutput,
t: T
) -> Result<VRFInOut, SignatureError>where
T: VRFSigningTranscript,
pub fn vrf_attach_hash<T>(
&self,
output: VRFOutput,
t: T
) -> Result<VRFInOut, SignatureError>where
T: VRFSigningTranscript,
Pair a non-malleable VRF output with the hash of the given transcript.
source§impl PublicKey
impl PublicKey
sourcepub fn vrfs_merge<B>(&self, ps: &[B], vartime: bool) -> VRFInOutwhere
B: Borrow<VRFInOut>,
pub fn vrfs_merge<B>(&self, ps: &[B], vartime: bool) -> VRFInOutwhere
B: Borrow<VRFInOut>,
Merge VRF input and output pairs from the same signer, using variable time arithmetic
You should use vartime=true when verifying VRF proofs batched
by the singer. You could usually use vartime=true even when
producing proofs, provided the set being signed is not secret.
There is sadly no constant time 128 bit multiplication in dalek,
making vartime=false somewhat slower than necessary. It should
only impact signers in niche scenarios however, so the slower
variant should normally be unnecessary.
Panics if given an empty points list.
TODO: Add constant time 128 bit batched multiplication to dalek.
TODO: Is rand_chacha’s gen::<u128>() standardizable enough to
prefer it over merlin for the output?
source§impl PublicKey
impl PublicKey
sourcepub fn dleq_verify<T>(
&self,
t: T,
p: &VRFInOut,
proof: &VRFProof,
kusama: bool
) -> Result<VRFProofBatchable, SignatureError>where
T: SigningTranscript,
pub fn dleq_verify<T>(
&self,
t: T,
p: &VRFInOut,
proof: &VRFProof,
kusama: bool
) -> Result<VRFProofBatchable, SignatureError>where
T: SigningTranscript,
Verify DLEQ proof that p.output = s * p.input where self
s times the basepoint.
We return an enlarged VRFProofBatchable instead of just true,
so that verifiers can forward batchable proofs.
In principle, one might provide “blindly verifiable” VRFs that
avoid requiring self here, but naively such constructions
risk the same flaws as DLEQ based blind signatures, and this
version exploits the slightly faster basepoint arithmetic.
sourcepub fn vrf_verify<T>(
&self,
t: T,
out: &VRFOutput,
proof: &VRFProof
) -> Result<(VRFInOut, VRFProofBatchable), SignatureError>where
T: VRFSigningTranscript,
pub fn vrf_verify<T>(
&self,
t: T,
out: &VRFOutput,
proof: &VRFProof
) -> Result<(VRFInOut, VRFProofBatchable), SignatureError>where
T: VRFSigningTranscript,
Verify VRF proof for one single input transcript and corresponding output.
sourcepub fn vrf_verify_extra<T, E>(
&self,
t: T,
out: &VRFOutput,
proof: &VRFProof,
extra: E
) -> Result<(VRFInOut, VRFProofBatchable), SignatureError>where
T: VRFSigningTranscript,
E: SigningTranscript,
pub fn vrf_verify_extra<T, E>(
&self,
t: T,
out: &VRFOutput,
proof: &VRFProof,
extra: E
) -> Result<(VRFInOut, VRFProofBatchable), SignatureError>where
T: VRFSigningTranscript,
E: SigningTranscript,
Verify VRF proof for one single input transcript and corresponding output.
sourcepub fn vrfs_verify<T, I, O>(
&self,
transcripts: I,
outs: &[O],
proof: &VRFProof
) -> Result<(Box<[VRFInOut], Global>, VRFProofBatchable), SignatureError>where
T: VRFSigningTranscript,
I: IntoIterator<Item = T>,
O: Borrow<VRFOutput>,
pub fn vrfs_verify<T, I, O>(
&self,
transcripts: I,
outs: &[O],
proof: &VRFProof
) -> Result<(Box<[VRFInOut], Global>, VRFProofBatchable), SignatureError>where
T: VRFSigningTranscript,
I: IntoIterator<Item = T>,
O: Borrow<VRFOutput>,
Verify a common VRF short proof for several input transcripts and corresponding outputs.
sourcepub fn vrfs_verify_extra<T, E, I, O>(
&self,
transcripts: I,
outs: &[O],
proof: &VRFProof,
extra: E
) -> Result<(Box<[VRFInOut], Global>, VRFProofBatchable), SignatureError>where
T: VRFSigningTranscript,
E: SigningTranscript,
I: IntoIterator<Item = T>,
O: Borrow<VRFOutput>,
pub fn vrfs_verify_extra<T, E, I, O>(
&self,
transcripts: I,
outs: &[O],
proof: &VRFProof,
extra: E
) -> Result<(Box<[VRFInOut], Global>, VRFProofBatchable), SignatureError>where
T: VRFSigningTranscript,
E: SigningTranscript,
I: IntoIterator<Item = T>,
O: Borrow<VRFOutput>,
Verify a common VRF short proof for several input transcripts and corresponding outputs.
source§impl PublicKey
impl PublicKey
sourcepub fn accept_ecqv_cert<T>(
&self,
t: T,
seed_secret_key: &SecretKey,
cert_secret: ECQVCertSecret
) -> Result<(ECQVCertPublic, SecretKey), SignatureError>where
T: SigningTranscript,
pub fn accept_ecqv_cert<T>(
&self,
t: T,
seed_secret_key: &SecretKey,
cert_secret: ECQVCertSecret
) -> Result<(ECQVCertPublic, SecretKey), SignatureError>where
T: SigningTranscript,
Accept an ECQV implicit certificate
We request an ECQV implicit certificate by first creating an
ephemeral Keypair and sending the public portion to the issuer
as seed_public_key. An issuer issues the certificat by replying
with the ECQVCertSecret created by issue_ecqv_cert.
Aside from the issuer PublicKey supplied as self, you provide
(1) a SigningTranscript called t that incorporates both the context
and the certificate requester’s identity,
(2) the seed_secret_key corresponding to the seed_public_key
they sent to the issuer by the certificate recipient in their
certificate request, and
(3) the ECQVCertSecret send by the issuer to the certificate
requester.
We return both your certificate’s new SecretKey as well as
an ECQVCertPublic from which third parties may derive
corresponding public key from h and the issuer’s public key.
source§impl PublicKey
impl PublicKey
sourcepub fn open_ecqv_cert<T>(
&self,
t: T,
cert_public: &ECQVCertPublic
) -> Result<PublicKey, SignatureError>where
T: SigningTranscript,
pub fn open_ecqv_cert<T>(
&self,
t: T,
cert_public: &ECQVCertPublic
) -> Result<PublicKey, SignatureError>where
T: SigningTranscript,
Trait Implementations§
source§impl Derivation for PublicKey
impl Derivation for PublicKey
source§fn derived_key<T>(&self, t: T, cc: ChainCode) -> (PublicKey, ChainCode)where
T: SigningTranscript,
fn derived_key<T>(&self, t: T, cc: ChainCode) -> (PublicKey, ChainCode)where
T: SigningTranscript,
SigningTranscript, and a chain code. Read moresource§impl Ord for PublicKey
impl Ord for PublicKey
source§impl PartialOrd<PublicKey> for PublicKey
impl PartialOrd<PublicKey> for PublicKey
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moreimpl Copy for PublicKey
impl Eq for PublicKey
impl StructuralEq for PublicKey
impl StructuralPartialEq for PublicKey
Auto Trait Implementations§
impl RefUnwindSafe for PublicKey
impl Send for PublicKey
impl Sync for PublicKey
impl Unpin for PublicKey
impl UnwindSafe for PublicKey
Blanket Implementations§
source§impl<T, U> AsByteSlice<T> for Uwhere
T: ToByteSlice,
U: AsRef<[T]> + ?Sized,
impl<T, U> AsByteSlice<T> for Uwhere
T: ToByteSlice,
U: AsRef<[T]> + ?Sized,
fn as_byte_slice(&self) -> &[u8] ⓘ
source§impl<U> AsSliceOf for Uwhere
U: AsRef<[u8]> + ?Sized,
impl<U> AsSliceOf for Uwhere
U: AsRef<[u8]> + ?Sized,
fn as_slice_of<T>(&self) -> Result<&[T], Error>where
T: FromByteSlice,
source§impl<T> CallHasher for Twhere
T: Hash + ?Sized,
impl<T> CallHasher for Twhere
T: Hash + ?Sized,
source§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read moresource§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read moresource§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s. Read moresource§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s. Read moresource§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T, Outer> IsWrappedBy<Outer> for Twhere
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
impl<T, Outer> IsWrappedBy<Outer> for Twhere
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
source§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
source§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
T. Read moresource§impl<T> ToHex for Twhere
T: AsRef<[u8]>,
impl<T> ToHex for Twhere
T: AsRef<[u8]>,
source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca) Read moresource§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA) Read moresource§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from.source§impl<T, S> UniqueSaturatedInto<T> for Swhere
T: Bounded,
S: TryInto<T>,
impl<T, S> UniqueSaturatedInto<T> for Swhere
T: Bounded,
S: TryInto<T>,
source§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T.