Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #13 from davxy/davxyn-skalman-core-bls-crypto-generic
Browse files Browse the repository at this point in the history
First generic BLS draft
  • Loading branch information
davxy authored Mar 23, 2023
2 parents 7023c14 + 7177bb1 commit 9b320cd
Show file tree
Hide file tree
Showing 9 changed files with 399 additions and 332 deletions.
19 changes: 9 additions & 10 deletions client/keystore/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
//! Local keystore implementation

use parking_lot::RwLock;
use sp_application_crypto::{bls, ecdsa, ed25519, sr25519, AppKey, AppPair, IsWrappedBy};
use sp_application_crypto::{bls377, ecdsa, ed25519, sr25519, AppKey, AppPair, IsWrappedBy};
use sp_core::{
crypto::{
ByteArray, CryptoTypePublicPair, ExposeSecret, KeyTypeId, Pair as PairT, SecretString,
},
sr25519::{Pair as Sr25519Pair, Public as Sr25519Public},
Encode,
};
use sp_keystore::{
Expand Down Expand Up @@ -231,11 +230,11 @@ impl Keystore for LocalKeystore {
fn sr25519_vrf_sign(
&self,
key_type: KeyTypeId,
public: &Sr25519Public,
public: &sr25519::Public,
transcript_data: VRFTranscriptData,
) -> std::result::Result<Option<VRFSignature>, TraitError> {
let transcript = make_transcript(transcript_data);
let pair = self.0.read().key_pair_by_type::<Sr25519Pair>(public, key_type)?;
let pair = self.0.read().key_pair_by_type::<sr25519::Pair>(public, key_type)?;

if let Some(pair) = pair {
let (inout, proof, _) = pair.as_ref().vrf_sign(transcript);
Expand All @@ -257,7 +256,7 @@ impl Keystore for LocalKeystore {
}

/// Returns all bls public keys for the given key type.
fn bls_public_keys(&self, _id: KeyTypeId) -> Vec<bls::Public> {
fn bls377_public_keys(&self, _id: KeyTypeId) -> Vec<bls377::Public> {
unimplemented!()
}

Expand All @@ -266,11 +265,11 @@ impl Keystore for LocalKeystore {
/// If the given seed is `Some(_)`, the key pair will only be stored in memory.
///
/// Returns the public key of the generated key pair.
fn bls_generate_new(
fn bls377_generate_new(
&self,
_id: KeyTypeId,
_seed: Option<&str>,
) -> std::result::Result<bls::Public, TraitError> {
) -> std::result::Result<bls377::Public, TraitError> {
unimplemented!()
}

Expand All @@ -286,12 +285,12 @@ impl Keystore for LocalKeystore {
/// Returns an [`bls::Signature`] or `None` in case the given `id` and
/// `public` combination doesn't exist in the keystore. An `Err` will be
/// returned if generating the signature itself failed.
fn bls_sign(
fn bls377_sign(
&self,
_id: KeyTypeId,
_public: &bls::Public,
_public: &bls377::Public,
_msg: &[u8],
) -> std::result::Result<Option<bls::Signature>, TraitError> {
) -> std::result::Result<Option<bls377::Signature>, TraitError> {
unimplemented!()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! bls crypto types.
//! BLS12-377 crypto applications.

use crate::{KeyTypeId, RuntimePublic};

use sp_std::vec::Vec;

pub use sp_core::bls::*;
pub use sp_core::bls::bls377::*;

mod app {
use sp_core::testing::BLS;
use sp_core::testing::BLS377;

crate::app_crypto!(super, BLS);
crate::app_crypto!(super, BLS377);

impl crate::traits::BoundToRuntimeAppPublic for Public {
type Public = Self;
Expand All @@ -40,20 +40,20 @@ pub use app::{Public as AppPublic, Signature as AppSignature};
impl RuntimePublic for Public {
type Signature = Signature;

fn all(key_type: KeyTypeId) -> crate::Vec<Self> {
sp_io::crypto::bls_public_keys(key_type)
fn all(_key_type: KeyTypeId) -> crate::Vec<Self> {
unreachable!("no access to the host keystore from runtime")
}

fn generate_pair(key_type: KeyTypeId, seed: Option<Vec<u8>>) -> Self {
sp_io::crypto::bls_generate(key_type, seed)
fn generate_pair(_key_type: KeyTypeId, _seed: Option<Vec<u8>>) -> Self {
unreachable!("no access to the host keystore from runtime")
}

fn sign<M: AsRef<[u8]>>(&self, key_type: KeyTypeId, msg: &M) -> Option<Self::Signature> {
sp_io::crypto::bls_sign(key_type, self, msg.as_ref())
fn sign<M: AsRef<[u8]>>(&self, _key_type: KeyTypeId, _msg: &M) -> Option<Self::Signature> {
unreachable!("no access to the host keystore from runtime")
}

fn verify<M: AsRef<[u8]>>(&self, msg: &M, signature: &Self::Signature) -> bool {
sp_io::crypto::bls_verify(&signature, msg.as_ref(), self)
fn verify<M: AsRef<[u8]>>(&self, _msg: &M, _signature: &Self::Signature) -> bool {
unreachable!("no access to the host keystore from runtime")
}

fn to_raw_vec(&self) -> Vec<u8> {
Expand Down
2 changes: 1 addition & 1 deletion primitives/application-crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub use serde;
#[doc(hidden)]
pub use sp_std::{ops::Deref, vec::Vec};

pub mod bls;
pub mod bls377;
pub mod ecdsa;
pub mod ed25519;
pub mod sr25519;
Expand Down
Loading

0 comments on commit 9b320cd

Please sign in to comment.