mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +00:00
Make BEEFY client keystore generic over BEEFY AuthorityId type (#2258)
This is the significant step to make BEEFY client able to handle both ECDSA and (ECDSA, BLS) type signature. The idea is having BEEFY Client generic on crypto types makes migration to new types smoother. This makes the BEEFY Keystore generic over AuthorityId and extends its tests to cover the case when the AuthorityId is of type (ECDSA, BLS12-377) --------- Co-authored-by: Davide Galassi <davxy@datawok.net> Co-authored-by: Robert Hambrock <roberthambrock@gmail.com>
This commit is contained in:
@@ -22,7 +22,7 @@ use crate::{Error, Keystore, KeystorePtr};
|
||||
#[cfg(feature = "bandersnatch-experimental")]
|
||||
use sp_core::bandersnatch;
|
||||
#[cfg(feature = "bls-experimental")]
|
||||
use sp_core::{bls377, bls381, ecdsa_bls377};
|
||||
use sp_core::{bls377, bls381, ecdsa_bls377, KeccakHasher};
|
||||
use sp_core::{
|
||||
crypto::{ByteArray, KeyTypeId, Pair, VrfSecret},
|
||||
ecdsa, ed25519, sr25519,
|
||||
@@ -346,6 +346,19 @@ impl Keystore for MemoryKeystore {
|
||||
self.sign::<ecdsa_bls377::Pair>(key_type, public, msg)
|
||||
}
|
||||
|
||||
#[cfg(feature = "bls-experimental")]
|
||||
fn ecdsa_bls377_sign_with_keccak256(
|
||||
&self,
|
||||
key_type: KeyTypeId,
|
||||
public: &ecdsa_bls377::Public,
|
||||
msg: &[u8],
|
||||
) -> Result<Option<ecdsa_bls377::Signature>, Error> {
|
||||
let sig = self
|
||||
.pair::<ecdsa_bls377::Pair>(key_type, public)
|
||||
.map(|pair| pair.sign_with_hasher::<KeccakHasher>(msg));
|
||||
Ok(sig)
|
||||
}
|
||||
|
||||
fn insert(&self, key_type: KeyTypeId, suri: &str, public: &[u8]) -> Result<(), ()> {
|
||||
self.keys
|
||||
.write()
|
||||
@@ -493,6 +506,38 @@ mod tests {
|
||||
assert!(res.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "bls-experimental")]
|
||||
fn ecdsa_bls377_sign_with_keccak_works() {
|
||||
use sp_core::testing::ECDSA_BLS377;
|
||||
|
||||
let store = MemoryKeystore::new();
|
||||
|
||||
let suri = "//Alice";
|
||||
let pair = ecdsa_bls377::Pair::from_string(suri, None).unwrap();
|
||||
|
||||
let msg = b"this should be a normal unhashed message not ";
|
||||
|
||||
// insert key, sign again
|
||||
store.insert(ECDSA_BLS377, suri, pair.public().as_ref()).unwrap();
|
||||
|
||||
let res = store
|
||||
.ecdsa_bls377_sign_with_keccak256(ECDSA_BLS377, &pair.public(), &msg[..])
|
||||
.unwrap();
|
||||
|
||||
assert!(res.is_some());
|
||||
|
||||
// does not verify with default out-of-the-box verification
|
||||
assert!(!ecdsa_bls377::Pair::verify(&res.clone().unwrap(), &msg[..], &pair.public()));
|
||||
|
||||
// should verify using keccak256 as hasher
|
||||
assert!(ecdsa_bls377::Pair::verify_with_hasher::<KeccakHasher>(
|
||||
&res.unwrap(),
|
||||
msg,
|
||||
&pair.public()
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "bandersnatch-experimental")]
|
||||
fn bandersnatch_vrf_sign() {
|
||||
|
||||
Reference in New Issue
Block a user