Skip to content

Commit

Permalink
fix client keystore compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
clangenb committed Sep 14, 2023
1 parent 7217d43 commit 4eb31ff
Showing 1 changed file with 10 additions and 87 deletions.
97 changes: 10 additions & 87 deletions client-keystore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
use parking_lot::RwLock;
use sp_application_crypto::{AppCrypto, AppPair, IsWrappedBy};
use sp_core::{
crypto::{ByteArray, ExposeSecret, KeyTypeId, Pair as CorePair, SecretString, VrfSecret},
crypto::{ByteArray, ExposeSecret, KeyTypeId, Pair as CorePair, SecretString, VrfSigner},
ecdsa, ed25519, sr25519,
};
use sp_keystore::{Error as TraitError, Keystore, KeystorePtr};
use std::{
collections::HashMap,
fs::{self, File},
Expand All @@ -37,7 +38,6 @@ use sc_keystore::{Error, Result};

mod keystore_ext;
pub use keystore_ext::KeystoreExt;
pub use sp_keystore::{Error as TraitError, Keystore, KeystorePtr};

/// A local based keystore that is either memory-based or filesystem-based.
pub struct LocalKeystore(RwLock<KeystoreInner>);
Expand Down Expand Up @@ -103,33 +103,19 @@ impl LocalKeystore {
Ok(signature)
}

fn vrf_sign<T: CorePair + VrfSecret>(
fn vrf_sign<T: CorePair + VrfSigner>(
&self,
key_type: KeyTypeId,
public: &T::Public,
data: &T::VrfSignData,
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(data));
.map(|pair| pair.vrf_sign(transcript));
Ok(sig)
}

fn vrf_output<T: CorePair + VrfSecret>(
&self,
key_type: KeyTypeId,
public: &T::Public,
input: &T::VrfInput,
) -> std::result::Result<Option<T::VrfOutput>, TraitError> {
let preout = self
.0
.read()
.key_pair_by_type::<T>(public, key_type)?
.map(|pair| pair.vrf_output(input));
Ok(preout)
}
}

impl Keystore for LocalKeystore {
Expand All @@ -139,7 +125,7 @@ impl Keystore for LocalKeystore {

/// Generate a new pair compatible with the 'ed25519' signature scheme.
///
/// If `[seed]` is `Some` then the key will be ephemeral and stored in memory.
/// If the `[seed]` is `Some` then the key will be ephemeral and stored in memory.
fn sr25519_generate_new(
&self,
key_type: KeyTypeId,
Expand All @@ -161,18 +147,9 @@ impl Keystore for LocalKeystore {
&self,
key_type: KeyTypeId,
public: &sr25519::Public,
data: &sr25519::vrf::VrfSignData,
transcript: &sr25519::vrf::VrfTranscript,
) -> std::result::Result<Option<sr25519::vrf::VrfSignature>, TraitError> {
self.vrf_sign::<sr25519::Pair>(key_type, public, data)
}

fn sr25519_vrf_output(
&self,
key_type: KeyTypeId,
public: &sr25519::Public,
input: &sr25519::vrf::VrfInput,
) -> std::result::Result<Option<sr25519::vrf::VrfOutput>, TraitError> {
self.vrf_output::<sr25519::Pair>(key_type, public, input)
self.vrf_sign::<sr25519::Pair>(key_type, public, transcript)
}

fn ed25519_public_keys(&self, key_type: KeyTypeId) -> Vec<ed25519::Public> {
Expand All @@ -181,7 +158,7 @@ impl Keystore for LocalKeystore {

/// Generate a new pair compatible with the 'sr25519' signature scheme.
///
/// If `[seed]` is `Some` then the key will be ephemeral and stored in memory.
/// If the `[seed]` is `Some` then the key will be ephemeral and stored in memory.
fn ed25519_generate_new(
&self,
key_type: KeyTypeId,
Expand All @@ -205,7 +182,7 @@ impl Keystore for LocalKeystore {

/// Generate a new pair compatible with the 'ecdsa' signature scheme.
///
/// If `[seed]` is `Some` then the key will be ephemeral and stored in memory.
/// If the `[seed]` is `Some` then the key will be ephemeral and stored in memory.
fn ecdsa_generate_new(
&self,
key_type: KeyTypeId,
Expand Down Expand Up @@ -237,60 +214,6 @@ impl Keystore for LocalKeystore {
Ok(sig)
}

#[cfg(feature = "bls-experimental")]
fn bls381_public_keys(&self, key_type: KeyTypeId) -> Vec<bls381::Public> {
self.public_keys::<bls381::Pair>(key_type)
}

#[cfg(feature = "bls-experimental")]
/// Generate a new pair compatible with the 'bls381' signature scheme.
///
/// If `[seed]` is `Some` then the key will be ephemeral and stored in memory.
fn bls381_generate_new(
&self,
key_type: KeyTypeId,
seed: Option<&str>,
) -> std::result::Result<bls381::Public, TraitError> {
self.generate_new::<bls381::Pair>(key_type, seed)
}

#[cfg(feature = "bls-experimental")]
fn bls381_sign(
&self,
key_type: KeyTypeId,
public: &bls381::Public,
msg: &[u8],
) -> std::result::Result<Option<bls381::Signature>, TraitError> {
self.sign::<bls381::Pair>(key_type, public, msg)
}

#[cfg(feature = "bls-experimental")]
fn bls377_public_keys(&self, key_type: KeyTypeId) -> Vec<bls377::Public> {
self.public_keys::<bls377::Pair>(key_type)
}

#[cfg(feature = "bls-experimental")]
/// Generate a new pair compatible with the 'bls377' signature scheme.
///
/// If `[seed]` is `Some` then the key will be ephemeral and stored in memory.
fn bls377_generate_new(
&self,
key_type: KeyTypeId,
seed: Option<&str>,
) -> std::result::Result<bls377::Public, TraitError> {
self.generate_new::<bls377::Pair>(key_type, seed)
}

#[cfg(feature = "bls-experimental")]
fn bls377_sign(
&self,
key_type: KeyTypeId,
public: &bls377::Public,
msg: &[u8],
) -> std::result::Result<Option<bls377::Signature>, TraitError> {
self.sign::<bls377::Pair>(key_type, public, msg)
}

fn insert(
&self,
key_type: KeyTypeId,
Expand Down

0 comments on commit 4eb31ff

Please sign in to comment.