mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-28 06:21:05 +00:00
e17a23e907
* Add KEY_KIND_ID to the public trait This change is being introduced for the purpose of identifying a public key with it's identifier and algorithm "kind". * Use `sign_with` as implemented in BareCryptoStore * Implement `sign_with` in sc_keystore * Fix inconsistencies, use *_KIND_ID in sp_core testing * Rename KeyKindId to CryptoTypeId * Remove pair-returning functions from BareCryptoStore trait * Define CryptoTypeId in app-crypto macros * Add functions to get keys supported by keystore * Fix sign_with signature to include CryptoTypePublicPair * Add `sign_with_any` and `sign_with_all` * Use keystore.sign_with in auth_discovery * Rename get_supported_keys -> supported_keys * Added headers to function docstrings * Use chain instead of extending a temp vector * Fixed some code formatting * Restrict size of CryptoTypeId This is to be able to use Encode/Decode derives and the overcome having the size being unknown at compile-time. * Implement sign_with in the trait itself * Remove whitespace * Use key_type also as a CryptoTypeId in app_crypto macros * Rename `get_keys` to `keys` in BareCryptoStore * Remove usage of key_pair funcs in tests * Adjust docstring for *_CYPTO_ID constants * Fix failures * Simplify mapping on keys * Remove one let * Fixed typo * PR feedback * remove whitespace * Zip keys and signatures * Use into_iter & remove cloned * Pass index to MissingSignature * Use typed errors instead of strings for BareCryptoStore * Implement Debug for trait error * Use hashsets for better performance for supported_keys * Make sure keys are inserted into the keystore * Make sign_with_all return type consistent with `sign_with` * Rename Error to BareCryptoStoreError * Rename CRYPT_TYPE_ID -> CRYPTO_ID * Remove unnecessary CRYPTO_ID declaration in Public trait * Convert pub key to CryptoTypePublicPair * Fix use * Fix code style * Implement From on CryptoTypePublicPair in app_crypto macros * Change CryptoTypePublicPair to a struct * Implement Display on CryptoTypePublicPair * Pass CryptoTypePublicPair to MissingSignature error * Adjust docs according to function signature * Unify keys implementation * Fix RPC author tests * Fix stackoverflow * Tabify spaces * Pass KeyTypeId to error for easier debugging * Fix asserts * Use ToHex to format public key * Use constants from sp_core * Rename testing KeyTypeId constants * Please compiler * Restore KeyTypeId names apparently, they're not only used in tests * Use BareCryptoStoreError instead of String * Document return value * Fix borrow check * Convert to hashset internally * WIP - iter_keys * Return raw_public_keys * Address PR feedback * Address PR Feedback * Fix hexdisplay import error * Update primitives/core/src/traits.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
76 lines
2.1 KiB
Rust
76 lines
2.1 KiB
Rust
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
|
|
// This file is part of Substrate.
|
|
|
|
// Substrate is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Substrate is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! Ed25519 crypto types.
|
|
|
|
use crate::{RuntimePublic, KeyTypeId};
|
|
|
|
use sp_std::vec::Vec;
|
|
|
|
pub use sp_core::ed25519::*;
|
|
|
|
mod app {
|
|
use sp_core::crypto::{CryptoTypePublicPair, Public as TraitPublic};
|
|
use sp_core::testing::ED25519;
|
|
use sp_core::ed25519::CRYPTO_ID;
|
|
|
|
crate::app_crypto!(super, ED25519);
|
|
|
|
impl crate::traits::BoundToRuntimeAppPublic for Public {
|
|
type Public = Self;
|
|
}
|
|
|
|
impl From<Public> for CryptoTypePublicPair {
|
|
fn from(key: Public) -> Self {
|
|
(&key).into()
|
|
}
|
|
}
|
|
|
|
impl From<&Public> for CryptoTypePublicPair {
|
|
fn from(key: &Public) -> Self {
|
|
CryptoTypePublicPair(CRYPTO_ID, key.to_raw_vec())
|
|
}
|
|
}
|
|
}
|
|
|
|
pub use app::{Public as AppPublic, Signature as AppSignature};
|
|
#[cfg(feature = "full_crypto")]
|
|
pub use app::Pair as AppPair;
|
|
|
|
impl RuntimePublic for Public {
|
|
type Signature = Signature;
|
|
|
|
fn all(key_type: KeyTypeId) -> crate::Vec<Self> {
|
|
sp_io::crypto::ed25519_public_keys(key_type)
|
|
}
|
|
|
|
fn generate_pair(key_type: KeyTypeId, seed: Option<Vec<u8>>) -> Self {
|
|
sp_io::crypto::ed25519_generate(key_type, seed)
|
|
}
|
|
|
|
fn sign<M: AsRef<[u8]>>(&self, key_type: KeyTypeId, msg: &M) -> Option<Self::Signature> {
|
|
sp_io::crypto::ed25519_sign(key_type, self, msg.as_ref())
|
|
}
|
|
|
|
fn verify<M: AsRef<[u8]>>(&self, msg: &M, signature: &Self::Signature) -> bool {
|
|
sp_io::crypto::ed25519_verify(&signature, msg.as_ref(), self)
|
|
}
|
|
|
|
fn to_raw_vec(&self) -> Vec<u8> {
|
|
sp_core::crypto::Public::to_raw_vec(self)
|
|
}
|
|
}
|