Last active
January 20, 2020 14:18
-
-
Save tomusdrw/a227b0c387e5cf636b92b7af2875c90c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub type AccountId = u64; | |
mod sp_core_crypto_dummy { | |
use primitives::crypto::*; | |
use codec::{Encode, Decode}; | |
/// Dummy cryptography. Doesn't do anything. | |
#[derive(Clone, Hash, Default, Eq, PartialEq, Encode, Decode, Debug, Ord, PartialOrd)] | |
pub struct Dummy; | |
impl std::fmt::Display for Dummy { | |
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result { | |
write!(fmt, "DummyCrypto") | |
} | |
} | |
impl sp_runtime::app_crypto::RuntimePublic for Dummy { | |
type Signature = Self; | |
fn all(_key_type: KeyTypeId) -> crate::Vec<Self> { | |
vec![Dummy] | |
} | |
fn generate_pair(key_type: KeyTypeId, seed: Option<Vec<u8>>) -> Self { | |
Dummy | |
} | |
fn sign<M: AsRef<[u8]>>(&self, key_type: KeyTypeId, msg: &M) -> Option<Self::Signature> { | |
Some(self.clone()) | |
} | |
fn verify<M: AsRef<[u8]>>(&self, msg: &M, signature: &Self::Signature) -> bool { | |
true | |
} | |
} | |
impl AsRef<[u8]> for Dummy { | |
fn as_ref(&self) -> &[u8] { &b""[..] } | |
} | |
impl AsMut<[u8]> for Dummy { | |
fn as_mut(&mut self) -> &mut [u8] { | |
unsafe { | |
#[allow(mutable_transmutes)] | |
//sp_std::mem::transmute::<_, &'static mut [u8]>(&b""[..]) | |
unimplemented!() | |
} | |
} | |
} | |
impl CryptoType for Dummy { | |
type Pair = Dummy; | |
} | |
impl Derive for Dummy {} | |
impl Public for Dummy { | |
fn from_slice(_: &[u8]) -> Self { Self } | |
#[cfg(feature = "std")] | |
fn to_raw_vec(&self) -> Vec<u8> { vec![] } | |
fn as_slice(&self) -> &[u8] { b"" } | |
} | |
impl Pair for Dummy { | |
type Public = Dummy; | |
type Seed = Dummy; | |
type Signature = Dummy; | |
type DeriveError = (); | |
#[cfg(feature = "std")] | |
fn generate_with_phrase(_: Option<&str>) -> (Self, String, Self::Seed) { Default::default() } | |
#[cfg(feature = "std")] | |
fn from_phrase(_: &str, _: Option<&str>) | |
-> Result<(Self, Self::Seed), SecretStringError> | |
{ | |
Ok(Default::default()) | |
} | |
fn derive< | |
Iter: Iterator<Item=DeriveJunction>, | |
>(&self, _: Iter, _: Option<Dummy>) -> Result<(Self, Option<Dummy>), Self::DeriveError> { Ok((Self, None)) } | |
fn from_seed(_: &Self::Seed) -> Self { Self } | |
fn from_seed_slice(_: &[u8]) -> Result<Self, SecretStringError> { Ok(Self) } | |
fn sign(&self, _: &[u8]) -> Self::Signature { Self } | |
fn verify<M: AsRef<[u8]>>(_: &Self::Signature, _: M, _: &Self::Public) -> bool { true } | |
fn verify_weak<P: AsRef<[u8]>, M: AsRef<[u8]>>(_: &[u8], _: M, _: P) -> bool { true } | |
fn public(&self) -> Self::Public { Self } | |
fn to_raw_vec(&self) -> Vec<u8> { vec![] } | |
} | |
} | |
mod crypto { | |
use super::*; | |
use sp_runtime::app_crypto::{app_crypto, key_types::DUMMY}; | |
mod dummy { | |
use crate::tests::sp_core_crypto_dummy::Dummy; | |
pub type Public = Dummy; | |
pub type Private = Dummy; | |
pub type Signature = Dummy; | |
pub type Pair = Dummy; | |
} | |
app_crypto!(dummy, DUMMY); | |
impl sp_runtime::traits::IdentifyAccount for Public { | |
type AccountId = AccountId; | |
// TODO | |
fn into_account(self) -> Self::AccountId { 11u64 } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment