mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 08:41:07 +00:00
VRF refactory (#13889)
* First iteration to encapsulate schnorrkel and merlin usage * Remove schnorkel direct dependency from BABE pallet * Remove schnorrkel direct dependency from BABE client * Trivial renaming for VrfTranscript data and value * Better errors * Expose a function to get a schnorrkel friendly transcript * Keep the vrf signature stuff together (preventing some clones around) * Fix tests * Remove vrf agnostic transcript and define it as an associated type for VrfSigner and VrfVerifier * Fix babe pallet mock * Inner types are required to be public for polkadot * Update client/consensus/babe/src/verification.rs Co-authored-by: Koute <koute@users.noreply.github.com> * Nit * Remove Deref implementations * make_bytes as a method * Trigger CI --------- Co-authored-by: Koute <koute@users.noreply.github.com>
This commit is contained in:
@@ -20,13 +20,10 @@
|
||||
use parking_lot::RwLock;
|
||||
use sp_application_crypto::{AppCrypto, AppPair, IsWrappedBy};
|
||||
use sp_core::{
|
||||
crypto::{ByteArray, ExposeSecret, KeyTypeId, Pair as CorePair, SecretString},
|
||||
crypto::{ByteArray, ExposeSecret, KeyTypeId, Pair as CorePair, SecretString, VrfSigner},
|
||||
ecdsa, ed25519, sr25519,
|
||||
};
|
||||
use sp_keystore::{
|
||||
vrf::{make_transcript, VRFSignature, VRFTranscriptData},
|
||||
Error as TraitError, Keystore, KeystorePtr,
|
||||
};
|
||||
use sp_keystore::{Error as TraitError, Keystore, KeystorePtr};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fs::{self, File},
|
||||
@@ -100,6 +97,20 @@ impl LocalKeystore {
|
||||
.map(|pair| pair.sign(msg));
|
||||
Ok(signature)
|
||||
}
|
||||
|
||||
fn vrf_sign<T: CorePair + VrfSigner>(
|
||||
&self,
|
||||
key_type: KeyTypeId,
|
||||
public: &T::Public,
|
||||
transcript: &T::VrfInput,
|
||||
) -> std::result::Result<Option<T::VrfSignature>, TraitError> {
|
||||
let sig = self
|
||||
.0
|
||||
.read()
|
||||
.key_pair_by_type::<T>(public, key_type)?
|
||||
.map(|pair| pair.vrf_sign(transcript));
|
||||
Ok(sig)
|
||||
}
|
||||
}
|
||||
|
||||
impl Keystore for LocalKeystore {
|
||||
@@ -131,14 +142,9 @@ impl Keystore for LocalKeystore {
|
||||
&self,
|
||||
key_type: KeyTypeId,
|
||||
public: &sr25519::Public,
|
||||
transcript_data: VRFTranscriptData,
|
||||
) -> std::result::Result<Option<VRFSignature>, TraitError> {
|
||||
let sig = self.0.read().key_pair_by_type::<sr25519::Pair>(public, key_type)?.map(|pair| {
|
||||
let transcript = make_transcript(transcript_data);
|
||||
let (inout, proof, _) = pair.as_ref().vrf_sign(transcript);
|
||||
VRFSignature { output: inout.to_output(), proof }
|
||||
});
|
||||
Ok(sig)
|
||||
transcript: &sr25519::vrf::VrfTranscript,
|
||||
) -> std::result::Result<Option<sr25519::vrf::VrfSignature>, TraitError> {
|
||||
self.vrf_sign::<sr25519::Pair>(key_type, public, transcript)
|
||||
}
|
||||
|
||||
fn ed25519_public_keys(&self, key_type: KeyTypeId) -> Vec<ed25519::Public> {
|
||||
|
||||
Reference in New Issue
Block a user