Skip to content

Commit f2c5ac1

Browse files
committed
Extend BeefyKeystore to non-supported types
1 parent 3a9ecbb commit f2c5ac1

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

substrate/client/consensus/beefy/src/keystore.rs

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,25 @@ impl<AuthorityId: AuthorityIdBound> BeefyKeystore<AuthorityId> {
111111
sig_ref.to_vec()
112112
},
113113

114-
_ => Err(error::Error::Keystore("key type is not supported by BEEFY Keystore".into()))?,
114+
_ => {
115+
match store.sign_with(
116+
<AuthorityId as AppCrypto>::ID,
117+
<AuthorityId as AppCrypto>::CRYPTO_ID,
118+
public.as_slice(),
119+
&message,
120+
) {
121+
Ok(sig) => {
122+
sig.ok_or_else(|| error::Error::Signature("signature failed".to_string()))?
123+
},
124+
Err(err) => {
125+
warn!(target: LOG_TARGET, "🥩 Error signing commitment: {:?}", err);
126+
return Err(error::Error::Signature(format!(
127+
"Error signing commitment: {:?}",
128+
err
129+
)));
130+
},
131+
}
132+
},
115133
};
116134

117135
//check that `sig` has the expected result type
@@ -133,32 +151,15 @@ impl<AuthorityId: AuthorityIdBound> BeefyKeystore<AuthorityId> {
133151
pub fn public_keys(&self) -> Result<Vec<AuthorityId>, error::Error> {
134152
let store = self.0.clone().ok_or_else(|| error::Error::Keystore("no Keystore".into()))?;
135153

136-
let pk = match <AuthorityId as AppCrypto>::CRYPTO_ID {
137-
ecdsa::CRYPTO_ID => store
138-
.ecdsa_public_keys(BEEFY_KEY_TYPE)
139-
.drain(..)
140-
.map(|pk| AuthorityId::try_from(pk.as_ref()))
141-
.collect::<Result<Vec<_>, _>>()
142-
.or_else(|_| {
143-
Err(error::Error::Keystore(
144-
"unable to convert public key into authority id".into(),
145-
))
146-
}),
147-
148-
#[cfg(feature = "bls-experimental")]
149-
ecdsa_bls381::CRYPTO_ID => store
150-
.ecdsa_bls381_public_keys(BEEFY_KEY_TYPE)
151-
.drain(..)
152-
.map(|pk| AuthorityId::try_from(pk.as_ref()))
153-
.collect::<Result<Vec<_>, _>>()
154-
.or_else(|_| {
155-
Err(error::Error::Keystore(
156-
"unable to convert public key into authority id".into(),
157-
))
158-
}),
159-
160-
_ => Err(error::Error::Keystore("key type is not supported by BEEFY Keystore".into())),
161-
};
154+
let pk = store
155+
.keys(BEEFY_KEY_TYPE)
156+
.map_err(|e| error::Error::Keystore(e.to_string()))?
157+
.into_iter()
158+
.map(|pk| AuthorityId::try_from(pk.as_ref()))
159+
.collect::<Result<Vec<_>, _>>()
160+
.or_else(|_| {
161+
Err(error::Error::Keystore("unable to convert public key into authority id".into()))
162+
});
162163

163164
pk
164165
}

0 commit comments

Comments
 (0)