mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 16:51:03 +00:00
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:
@@ -19,8 +19,6 @@
|
||||
//! Cryptographic utilities.
|
||||
// end::description[]
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use crate::hexdisplay::HexDisplay;
|
||||
use crate::{ed25519, sr25519};
|
||||
#[cfg(feature = "std")]
|
||||
use base58::{FromBase58, ToBase58};
|
||||
@@ -487,10 +485,7 @@ pub trait ByteArray: AsRef<[u8]> + AsMut<[u8]> + for<'a> TryFrom<&'a [u8], Error
|
||||
}
|
||||
|
||||
/// Trait suitable for typical cryptographic PKI key public type.
|
||||
pub trait Public: ByteArray + Derive + CryptoType + PartialEq + Eq + Clone + Send + Sync {
|
||||
/// Return `CryptoTypePublicPair` from public key.
|
||||
fn to_public_crypto_pair(&self) -> CryptoTypePublicPair;
|
||||
}
|
||||
pub trait Public: ByteArray + Derive + CryptoType + PartialEq + Eq + Clone + Send + Sync {}
|
||||
|
||||
/// An opaque 32-byte cryptographic identifier.
|
||||
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, MaxEncodedLen, TypeInfo)]
|
||||
@@ -689,11 +684,7 @@ mod dummy {
|
||||
b""
|
||||
}
|
||||
}
|
||||
impl Public for Dummy {
|
||||
fn to_public_crypto_pair(&self) -> CryptoTypePublicPair {
|
||||
CryptoTypePublicPair(CryptoTypeId(*b"dumm"), <Self as ByteArray>::to_raw_vec(self))
|
||||
}
|
||||
}
|
||||
impl Public for Dummy {}
|
||||
|
||||
impl Pair for Dummy {
|
||||
type Public = Dummy;
|
||||
@@ -1118,24 +1109,6 @@ impl<'a> TryFrom<&'a str> for KeyTypeId {
|
||||
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct CryptoTypeId(pub [u8; 4]);
|
||||
|
||||
/// A type alias of CryptoTypeId & a public key
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct CryptoTypePublicPair(pub CryptoTypeId, pub Vec<u8>);
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl sp_std::fmt::Display for CryptoTypePublicPair {
|
||||
fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
|
||||
let id = match str::from_utf8(&(self.0).0[..]) {
|
||||
Ok(id) => id.to_string(),
|
||||
Err(_) => {
|
||||
format!("{:#?}", self.0)
|
||||
},
|
||||
};
|
||||
write!(f, "{}-{}", id, HexDisplay::from(&self.1))
|
||||
}
|
||||
}
|
||||
|
||||
/// Known key types; this also functions as a global registry of key types for projects wishing to
|
||||
/// avoid collisions with each other.
|
||||
///
|
||||
@@ -1223,11 +1196,7 @@ mod tests {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
impl Public for TestPublic {
|
||||
fn to_public_crypto_pair(&self) -> CryptoTypePublicPair {
|
||||
CryptoTypePublicPair(CryptoTypeId(*b"dumm"), self.to_raw_vec())
|
||||
}
|
||||
}
|
||||
impl Public for TestPublic {}
|
||||
impl Pair for TestPair {
|
||||
type Public = TestPublic;
|
||||
type Seed = [u8; 8];
|
||||
|
||||
Reference in New Issue
Block a user