Is it possible to add support for other cryptographic algorithms, or are we only allowed to use the implemented ones?
The implemented ones are sr25519, ed25519, ecdsa(secp256k1, not secp256r1).
I tried following this oracle example, but it seems to only wrap around sr25519. I then tried to mirror the ecdsa implementation but now I got to the point of trying to implement the RuntimePublic trait, but I see that for other algorithms, it is calling functions that talk to the Keystore through the Crypto trait
I finally saw that getting keys of a certain algorithm is hardcoded in the Keystore, and when getting all of the keys regardless of the algo used, it still converts it into those 3 algorithms.
It seems that substrate only lets you define crypto types only as a renamed version of the same algorithm, and not create new ones on other elliptic curves for example. Is this the case?
Hardcoded crypto conversions of public keys from the Keystore:
impl SyncCryptoStore for LocalKeystore {
fn keys(&self, id: KeyTypeId) -> std::result::Result<Vec<CryptoTypePublicPair>, TraitError> {
let raw_keys = self.0.read().raw_public_keys(id)?;
Ok(raw_keys.into_iter().fold(Vec::new(), |mut v, k| {
v.push(CryptoTypePublicPair(sr25519::CRYPTO_ID, k.clone()));
v.push(CryptoTypePublicPair(ed25519::CRYPTO_ID, k.clone()));
v.push(CryptoTypePublicPair(ecdsa::CRYPTO_ID, k));
v
}))
}
How an algorithm like secp256k1 retrieves from the Keystore:
...
fn ecdsa_public_keys(&self, key_type: KeyTypeId) -> Vec<ecdsa::Public> {
self.0
.read()
.raw_public_keys(key_type)
.map(|v| {
v.into_iter()
.filter_map(|k| ecdsa::Public::from_slice(k.as_slice()).ok())
.collect()
})
.unwrap_or_default()
}
} // impl SyncCryptoStore for LocalKeystore