Keystore overhaul (final) (#13683)

* Introduce keystore specialized sign methods

* Get rid of 'AppKey::UntypedGeneric' associated type.

Untyped generics are accessible using associated types 'Generic' associated type.
I.e. <T as AppKey>::Public::Generic

* Get rid of 'CryptoTypePublicPair'

* Trivial fix

* Small refactory of local keystore implementations

* Remove 'crypto_id' method from 'Public'

* Trivial rename of 'AppKey' to 'AppCrypto'

* Remove unused import

* Improve docs

* Better signature related errors for authority-discovery

* Apply review suggestion

* Apply review suggestions

Co-authored-by: Koute <koute@users.noreply.github.com>

* Authority discoverty signing error revisited

* Signing error revisited for babe and aura as well

* Further cleanup

---------

Co-authored-by: Koute <koute@users.noreply.github.com>
This commit is contained in:
Davide Galassi
2023-03-24 14:46:02 +01:00
committed by GitHub
parent 370e71cb20
commit 40e1704e1c
27 changed files with 552 additions and 616 deletions
@@ -17,8 +17,11 @@
//! Integration tests for ecdsa
use sp_api::ProvideRuntimeApi;
use sp_application_crypto::ecdsa::{AppPair, AppPublic};
use sp_core::{crypto::Pair, testing::ECDSA};
use sp_application_crypto::ecdsa::AppPair;
use sp_core::{
crypto::{ByteArray, Pair},
testing::ECDSA,
};
use sp_keystore::{testing::MemoryKeystore, Keystore};
use std::sync::Arc;
use substrate_test_runtime_client::{
@@ -35,6 +38,6 @@ fn ecdsa_works_in_runtime() {
.expect("Tests `ecdsa` crypto.");
let supported_keys = keystore.keys(ECDSA).unwrap();
assert!(supported_keys.contains(&public.clone().into()));
assert!(AppPair::verify(&signature, "ecdsa", &AppPublic::from(public)));
assert!(supported_keys.contains(&public.to_raw_vec()));
assert!(AppPair::verify(&signature, "ecdsa", &public));
}
@@ -18,8 +18,11 @@
//! Integration tests for ed25519
use sp_api::ProvideRuntimeApi;
use sp_application_crypto::ed25519::{AppPair, AppPublic};
use sp_core::{crypto::Pair, testing::ED25519};
use sp_application_crypto::ed25519::AppPair;
use sp_core::{
crypto::{ByteArray, Pair},
testing::ED25519,
};
use sp_keystore::{testing::MemoryKeystore, Keystore};
use std::sync::Arc;
use substrate_test_runtime_client::{
@@ -36,6 +39,6 @@ fn ed25519_works_in_runtime() {
.expect("Tests `ed25519` crypto.");
let supported_keys = keystore.keys(ED25519).unwrap();
assert!(supported_keys.contains(&public.clone().into()));
assert!(AppPair::verify(&signature, "ed25519", &AppPublic::from(public)));
assert!(supported_keys.contains(&public.to_raw_vec()));
assert!(AppPair::verify(&signature, "ed25519", &public));
}
@@ -18,8 +18,11 @@
//! Integration tests for sr25519
use sp_api::ProvideRuntimeApi;
use sp_application_crypto::sr25519::{AppPair, AppPublic};
use sp_core::{crypto::Pair, testing::SR25519};
use sp_application_crypto::sr25519::AppPair;
use sp_core::{
crypto::{ByteArray, Pair},
testing::SR25519,
};
use sp_keystore::{testing::MemoryKeystore, Keystore};
use std::sync::Arc;
use substrate_test_runtime_client::{
@@ -36,6 +39,6 @@ fn sr25519_works_in_runtime() {
.expect("Tests `sr25519` crypto.");
let supported_keys = keystore.keys(SR25519).unwrap();
assert!(supported_keys.contains(&public.clone().into()));
assert!(AppPair::verify(&signature, "sr25519", &AppPublic::from(public)));
assert!(supported_keys.contains(&public.to_raw_vec()));
assert!(AppPair::verify(&signature, "sr25519", &public));
}