feat: Rebrand Polkadot/Substrate references to PezkuwiChain
This commit systematically rebrands various references from Parity Technologies' Polkadot/Substrate ecosystem to PezkuwiChain within the kurdistan-sdk. Key changes include: - Updated external repository URLs (zombienet-sdk, parity-db, parity-scale-codec, wasm-instrument) to point to pezkuwichain forks. - Modified internal documentation and code comments to reflect PezkuwiChain naming and structure. - Replaced direct references to with or specific paths within the for XCM, Pezkuwi, and other modules. - Cleaned up deprecated issue and PR references in various and files, particularly in and modules. - Adjusted image and logo URLs in documentation to point to PezkuwiChain assets. - Removed or rephrased comments related to external Polkadot/Substrate PRs and issues. This is a significant step towards fully customizing the SDK for the PezkuwiChain ecosystem.
This commit is contained in:
@@ -0,0 +1,201 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! A set of well-known keys used for testing.
|
||||
|
||||
pub use pezsp_core::bandersnatch;
|
||||
|
||||
use crate::ParseKeyringError;
|
||||
#[cfg(feature = "std")]
|
||||
use pezsp_core::bandersnatch::Signature;
|
||||
use pezsp_core::{
|
||||
bandersnatch::{Pair, Public},
|
||||
crypto::UncheckedFrom,
|
||||
hex2array, ByteArray, Pair as PairT,
|
||||
};
|
||||
|
||||
extern crate alloc;
|
||||
use alloc::{format, str::FromStr, string::String, vec::Vec};
|
||||
|
||||
/// Set of test accounts.
|
||||
#[derive(
|
||||
Debug, Clone, Copy, PartialEq, Eq, Hash, strum::Display, strum::EnumIter, Ord, PartialOrd,
|
||||
)]
|
||||
pub enum Keyring {
|
||||
Alice,
|
||||
Bob,
|
||||
Charlie,
|
||||
Dave,
|
||||
Eve,
|
||||
Ferdie,
|
||||
One,
|
||||
Two,
|
||||
}
|
||||
|
||||
const PUBLIC_RAW_LEN: usize = <Public as ByteArray>::LEN;
|
||||
|
||||
impl Keyring {
|
||||
pub fn from_public(who: &Public) -> Option<Keyring> {
|
||||
Self::iter().find(|&k| &Public::from(k) == who)
|
||||
}
|
||||
|
||||
pub fn from_raw_public(who: [u8; PUBLIC_RAW_LEN]) -> Option<Keyring> {
|
||||
Self::from_public(&Public::unchecked_from(who))
|
||||
}
|
||||
|
||||
pub fn to_raw_public(self) -> [u8; PUBLIC_RAW_LEN] {
|
||||
*Public::from(self).as_ref()
|
||||
}
|
||||
|
||||
pub fn to_raw_public_vec(self) -> Vec<u8> {
|
||||
Public::from(self).to_raw_vec()
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub fn sign(self, msg: &[u8]) -> Signature {
|
||||
Pair::from(self).sign(msg)
|
||||
}
|
||||
|
||||
pub fn pair(self) -> Pair {
|
||||
Pair::from_string(&format!("//{}", <&'static str>::from(self)), None)
|
||||
.expect("static values are known good; qed")
|
||||
}
|
||||
|
||||
/// Returns an iterator over all test accounts.
|
||||
pub fn iter() -> impl Iterator<Item = Keyring> {
|
||||
<Self as strum::IntoEnumIterator>::iter()
|
||||
}
|
||||
|
||||
pub fn public(self) -> Public {
|
||||
Public::from(self)
|
||||
}
|
||||
|
||||
pub fn to_seed(self) -> String {
|
||||
format!("//{}", self)
|
||||
}
|
||||
|
||||
/// Create a crypto `Pair` from a numeric value.
|
||||
pub fn numeric(idx: usize) -> Pair {
|
||||
Pair::from_string(&format!("//{}", idx), None).expect("numeric values are known good; qed")
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for &'static str {
|
||||
fn from(k: Keyring) -> Self {
|
||||
match k {
|
||||
Keyring::Alice => "Alice",
|
||||
Keyring::Bob => "Bob",
|
||||
Keyring::Charlie => "Charlie",
|
||||
Keyring::Dave => "Dave",
|
||||
Keyring::Eve => "Eve",
|
||||
Keyring::Ferdie => "Ferdie",
|
||||
Keyring::One => "One",
|
||||
Keyring::Two => "Two",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Keyring {
|
||||
type Err = ParseKeyringError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {
|
||||
match s {
|
||||
"Alice" => Ok(Keyring::Alice),
|
||||
"Bob" => Ok(Keyring::Bob),
|
||||
"Charlie" => Ok(Keyring::Charlie),
|
||||
"Dave" => Ok(Keyring::Dave),
|
||||
"Eve" => Ok(Keyring::Eve),
|
||||
"Ferdie" => Ok(Keyring::Ferdie),
|
||||
"One" => Ok(Keyring::One),
|
||||
"Two" => Ok(Keyring::Two),
|
||||
_ => Err(ParseKeyringError),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for Public {
|
||||
fn from(k: Keyring) -> Self {
|
||||
Public::unchecked_from(<[u8; PUBLIC_RAW_LEN]>::from(k))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for Pair {
|
||||
fn from(k: Keyring) -> Self {
|
||||
k.pair()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for [u8; PUBLIC_RAW_LEN] {
|
||||
fn from(k: Keyring) -> Self {
|
||||
match k {
|
||||
Keyring::Alice => {
|
||||
hex2array!("4d8e57b723e8bb4eca5c28d79cb95b9e84b4e2319d9851d45504014633e55d01")
|
||||
},
|
||||
Keyring::Bob => {
|
||||
hex2array!("aa6daf4784d581804d8f5cc1edb2ad171dbdf9c5188ddc071b11c3479c150c37")
|
||||
},
|
||||
Keyring::Charlie => {
|
||||
hex2array!("331d681392223b35b92319e059d3dbc2869b2ef74400a70e678b4a5108c81ec0")
|
||||
},
|
||||
Keyring::Dave => {
|
||||
hex2array!("374384c19a877040c84bb07fcf3aac74ff7fafface0b1c01a93fd2ddbf5c1660")
|
||||
},
|
||||
Keyring::Eve => {
|
||||
hex2array!("14bdd9381e80c07b75b8f1e92d6b2e4652e5135beaad1eedb1b81ff01ee562ad")
|
||||
},
|
||||
Keyring::Ferdie => {
|
||||
hex2array!("e13bd31b0575076479914c16c5ad69779f206375dbf19519219eeba3b10cc063")
|
||||
},
|
||||
Keyring::One => {
|
||||
hex2array!("03466a4de97ae18bc4604a3c40dfbddc6bac9f707c9b3c31a94a2c1725a03253")
|
||||
},
|
||||
Keyring::Two => {
|
||||
hex2array!("0fda0d1336e8d6ee687ebf6d14eaa9b92b5601068e6159222623c8e14c004293")
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use pezsp_core::{bandersnatch::Pair, Pair as PairT};
|
||||
|
||||
#[test]
|
||||
fn should_work() {
|
||||
assert!(Pair::verify(
|
||||
&Keyring::Alice.sign(b"I am Alice!"),
|
||||
b"I am Alice!",
|
||||
&Keyring::Alice.public(),
|
||||
));
|
||||
assert!(!Pair::verify(
|
||||
&Keyring::Alice.sign(b"I am Alice!"),
|
||||
b"I am Bob!",
|
||||
&Keyring::Alice.public(),
|
||||
));
|
||||
assert!(!Pair::verify(
|
||||
&Keyring::Alice.sign(b"I am Alice!"),
|
||||
b"I am Alice!",
|
||||
&Keyring::Bob.public(),
|
||||
));
|
||||
}
|
||||
#[test]
|
||||
fn verify_static_public_keys() {
|
||||
assert!(Keyring::iter()
|
||||
.all(|k| { k.pair().public().as_ref() == <[u8; PUBLIC_RAW_LEN]>::from(k) }));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Support code for the runtime. A set of test accounts.
|
||||
|
||||
pub use pezsp_core::ed25519;
|
||||
|
||||
use crate::ParseKeyringError;
|
||||
#[cfg(feature = "std")]
|
||||
use pezsp_core::ed25519::Signature;
|
||||
use pezsp_core::{
|
||||
ed25519::{Pair, Public},
|
||||
hex2array, ByteArray, Pair as PairT, H256,
|
||||
};
|
||||
use pezsp_runtime::AccountId32;
|
||||
|
||||
extern crate alloc;
|
||||
use alloc::{format, str::FromStr, string::String, vec::Vec};
|
||||
|
||||
/// Set of test accounts.
|
||||
#[derive(
|
||||
Debug, Clone, Copy, PartialEq, Eq, Hash, strum::Display, strum::EnumIter, Ord, PartialOrd,
|
||||
)]
|
||||
pub enum Keyring {
|
||||
Alice,
|
||||
Bob,
|
||||
Charlie,
|
||||
Dave,
|
||||
Eve,
|
||||
Ferdie,
|
||||
AliceStash,
|
||||
BobStash,
|
||||
CharlieStash,
|
||||
DaveStash,
|
||||
EveStash,
|
||||
FerdieStash,
|
||||
One,
|
||||
Two,
|
||||
}
|
||||
|
||||
impl Keyring {
|
||||
pub fn from_public(who: &Public) -> Option<Keyring> {
|
||||
Self::iter().find(|&k| &Public::from(k) == who)
|
||||
}
|
||||
|
||||
pub fn from_account_id(who: &AccountId32) -> Option<Keyring> {
|
||||
Self::iter().find(|&k| &k.to_account_id() == who)
|
||||
}
|
||||
|
||||
pub fn from_raw_public(who: [u8; 32]) -> Option<Keyring> {
|
||||
Self::from_public(&Public::from_raw(who))
|
||||
}
|
||||
|
||||
pub fn to_raw_public(self) -> [u8; 32] {
|
||||
*Public::from(self).as_array_ref()
|
||||
}
|
||||
|
||||
pub fn from_h256_public(who: H256) -> Option<Keyring> {
|
||||
Self::from_public(&Public::from_raw(who.into()))
|
||||
}
|
||||
|
||||
pub fn to_h256_public(self) -> H256 {
|
||||
Public::from(self).as_array_ref().into()
|
||||
}
|
||||
|
||||
pub fn to_raw_public_vec(self) -> Vec<u8> {
|
||||
Public::from(self).to_raw_vec()
|
||||
}
|
||||
|
||||
pub fn to_account_id(self) -> AccountId32 {
|
||||
self.to_raw_public().into()
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub fn sign(self, msg: &[u8]) -> Signature {
|
||||
Pair::from(self).sign(msg)
|
||||
}
|
||||
|
||||
pub fn pair(self) -> Pair {
|
||||
Pair::from_string(&format!("//{}", <&'static str>::from(self)), None)
|
||||
.expect("static values are known good; qed")
|
||||
}
|
||||
|
||||
/// Returns an iterator over all test accounts.
|
||||
pub fn iter() -> impl Iterator<Item = Keyring> {
|
||||
<Self as strum::IntoEnumIterator>::iter()
|
||||
}
|
||||
|
||||
pub fn public(self) -> Public {
|
||||
Public::from(self)
|
||||
}
|
||||
|
||||
pub fn to_seed(self) -> String {
|
||||
format!("//{}", self)
|
||||
}
|
||||
|
||||
pub fn well_known() -> impl Iterator<Item = Keyring> {
|
||||
Self::iter().take(12)
|
||||
}
|
||||
|
||||
pub fn invulnerable() -> impl Iterator<Item = Keyring> {
|
||||
Self::iter().take(6)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for &'static str {
|
||||
fn from(k: Keyring) -> Self {
|
||||
match k {
|
||||
Keyring::Alice => "Alice",
|
||||
Keyring::Bob => "Bob",
|
||||
Keyring::Charlie => "Charlie",
|
||||
Keyring::Dave => "Dave",
|
||||
Keyring::Eve => "Eve",
|
||||
Keyring::Ferdie => "Ferdie",
|
||||
Keyring::AliceStash => "Alice//stash",
|
||||
Keyring::BobStash => "Bob//stash",
|
||||
Keyring::CharlieStash => "Charlie//stash",
|
||||
Keyring::DaveStash => "Dave//stash",
|
||||
Keyring::EveStash => "Eve//stash",
|
||||
Keyring::FerdieStash => "Ferdie//stash",
|
||||
Keyring::One => "One",
|
||||
Keyring::Two => "Two",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for pezsp_runtime::MultiSigner {
|
||||
fn from(x: Keyring) -> Self {
|
||||
pezsp_runtime::MultiSigner::Ed25519(x.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Keyring {
|
||||
type Err = ParseKeyringError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {
|
||||
match s {
|
||||
"Alice" | "alice" => Ok(Keyring::Alice),
|
||||
"Bob" | "bob" => Ok(Keyring::Bob),
|
||||
"Charlie" | "charlie" => Ok(Keyring::Charlie),
|
||||
"Dave" | "dave" => Ok(Keyring::Dave),
|
||||
"Eve" | "eve" => Ok(Keyring::Eve),
|
||||
"Ferdie" | "ferdie" => Ok(Keyring::Ferdie),
|
||||
"Alice//stash" | "alice//stash" => Ok(Keyring::AliceStash),
|
||||
"Bob//stash" | "bob//stash" => Ok(Keyring::BobStash),
|
||||
"Charlie//stash" | "charlie//stash" => Ok(Keyring::CharlieStash),
|
||||
"Dave//stash" | "dave//stash" => Ok(Keyring::DaveStash),
|
||||
"Eve//stash" | "eve//stash" => Ok(Keyring::EveStash),
|
||||
"Ferdie//stash" | "ferdie//stash" => Ok(Keyring::FerdieStash),
|
||||
"One" | "one" => Ok(Keyring::One),
|
||||
"Two" | "two" => Ok(Keyring::Two),
|
||||
_ => Err(ParseKeyringError),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for Public {
|
||||
fn from(k: Keyring) -> Self {
|
||||
Public::from_raw(k.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for AccountId32 {
|
||||
fn from(k: Keyring) -> Self {
|
||||
k.to_account_id()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for Pair {
|
||||
fn from(k: Keyring) -> Self {
|
||||
k.pair()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for [u8; 32] {
|
||||
fn from(k: Keyring) -> Self {
|
||||
match k {
|
||||
Keyring::Alice => {
|
||||
hex2array!("88dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee")
|
||||
},
|
||||
Keyring::Bob => {
|
||||
hex2array!("d17c2d7823ebf260fd138f2d7e27d114c0145d968b5ff5006125f2414fadae69")
|
||||
},
|
||||
Keyring::Charlie => {
|
||||
hex2array!("439660b36c6c03afafca027b910b4fecf99801834c62a5e6006f27d978de234f")
|
||||
},
|
||||
Keyring::Dave => {
|
||||
hex2array!("5e639b43e0052c47447dac87d6fd2b6ec50bdd4d0f614e4299c665249bbd09d9")
|
||||
},
|
||||
Keyring::Eve => {
|
||||
hex2array!("1dfe3e22cc0d45c70779c1095f7489a8ef3cf52d62fbd8c2fa38c9f1723502b5")
|
||||
},
|
||||
Keyring::Ferdie => {
|
||||
hex2array!("568cb4a574c6d178feb39c27dfc8b3f789e5f5423e19c71633c748b9acf086b5")
|
||||
},
|
||||
Keyring::AliceStash => {
|
||||
hex2array!("451781cd0c5504504f69ceec484cc66e4c22a2b6a9d20fb1a426d91ad074a2a8")
|
||||
},
|
||||
Keyring::BobStash => {
|
||||
hex2array!("292684abbb28def63807c5f6e84e9e8689769eb37b1ab130d79dbfbf1b9a0d44")
|
||||
},
|
||||
Keyring::CharlieStash => {
|
||||
hex2array!("dd6a6118b6c11c9c9e5a4f34ed3d545e2c74190f90365c60c230fa82e9423bb9")
|
||||
},
|
||||
Keyring::DaveStash => {
|
||||
hex2array!("1d0432d75331ab299065bee79cdb1bdc2497c597a3087b4d955c67e3c000c1e2")
|
||||
},
|
||||
Keyring::EveStash => {
|
||||
hex2array!("c833bdd2e1a7a18acc1c11f8596e2e697bb9b42d6b6051e474091a1d43a294d7")
|
||||
},
|
||||
Keyring::FerdieStash => {
|
||||
hex2array!("199d749dbf4b8135cb1f3c8fd697a390fc0679881a8a110c1d06375b3b62cd09")
|
||||
},
|
||||
Keyring::One => {
|
||||
hex2array!("16f97016bbea8f7b45ae6757b49efc1080accc175d8f018f9ba719b60b0815e4")
|
||||
},
|
||||
Keyring::Two => {
|
||||
hex2array!("5079bcd20fd97d7d2f752c4607012600b401950260a91821f73e692071c82bf5")
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for H256 {
|
||||
fn from(k: Keyring) -> Self {
|
||||
k.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use pezsp_core::{ed25519::Pair, Pair as PairT};
|
||||
|
||||
#[test]
|
||||
fn should_work() {
|
||||
assert!(Pair::verify(
|
||||
&Keyring::Alice.sign(b"I am Alice!"),
|
||||
b"I am Alice!",
|
||||
&Keyring::Alice.public(),
|
||||
));
|
||||
assert!(!Pair::verify(
|
||||
&Keyring::Alice.sign(b"I am Alice!"),
|
||||
b"I am Bob!",
|
||||
&Keyring::Alice.public(),
|
||||
));
|
||||
assert!(!Pair::verify(
|
||||
&Keyring::Alice.sign(b"I am Alice!"),
|
||||
b"I am Alice!",
|
||||
&Keyring::Bob.public(),
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_static_public_keys() {
|
||||
assert!(Keyring::iter().all(|k| { k.pair().public().as_ref() == <[u8; 32]>::from(k) }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_well_known() {
|
||||
assert_eq!(
|
||||
Keyring::well_known().collect::<Vec<Keyring>>(),
|
||||
vec![
|
||||
Keyring::Alice,
|
||||
Keyring::Bob,
|
||||
Keyring::Charlie,
|
||||
Keyring::Dave,
|
||||
Keyring::Eve,
|
||||
Keyring::Ferdie,
|
||||
Keyring::AliceStash,
|
||||
Keyring::BobStash,
|
||||
Keyring::CharlieStash,
|
||||
Keyring::DaveStash,
|
||||
Keyring::EveStash,
|
||||
Keyring::FerdieStash
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_invulnerable() {
|
||||
assert_eq!(
|
||||
Keyring::invulnerable().collect::<Vec<Keyring>>(),
|
||||
vec![
|
||||
Keyring::Alice,
|
||||
Keyring::Bob,
|
||||
Keyring::Charlie,
|
||||
Keyring::Dave,
|
||||
Keyring::Eve,
|
||||
Keyring::Ferdie
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Support code for the runtime. A set of test accounts.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
extern crate alloc;
|
||||
use alloc::fmt;
|
||||
|
||||
/// Test account crypto for sr25519.
|
||||
pub mod sr25519;
|
||||
|
||||
/// Test account crypto for ed25519.
|
||||
pub mod ed25519;
|
||||
|
||||
/// Test account crypto for bandersnatch.
|
||||
#[cfg(feature = "bandersnatch-experimental")]
|
||||
pub mod bandersnatch;
|
||||
|
||||
#[cfg(feature = "bandersnatch-experimental")]
|
||||
pub use bandersnatch::Keyring as BandersnatchKeyring;
|
||||
pub use ed25519::Keyring as Ed25519Keyring;
|
||||
pub use sr25519::Keyring as Sr25519Keyring;
|
||||
|
||||
#[derive(Debug)]
|
||||
/// Represents an error that occurs when parsing a string into a `KeyRing`.
|
||||
pub struct ParseKeyringError;
|
||||
|
||||
impl fmt::Display for ParseKeyringError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "ParseKeyringError")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,319 @@
|
||||
// This file is part of Bizinikiwi.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! Support code for the runtime. A set of test accounts.
|
||||
|
||||
pub use pezsp_core::sr25519;
|
||||
|
||||
use crate::ParseKeyringError;
|
||||
#[cfg(feature = "std")]
|
||||
use pezsp_core::sr25519::Signature;
|
||||
use pezsp_core::{
|
||||
hex2array,
|
||||
sr25519::{Pair, Public},
|
||||
ByteArray, Pair as PairT, H256,
|
||||
};
|
||||
use pezsp_runtime::AccountId32;
|
||||
|
||||
extern crate alloc;
|
||||
use alloc::{format, str::FromStr, string::String, vec::Vec};
|
||||
|
||||
/// Set of test accounts.
|
||||
#[derive(
|
||||
Debug, Clone, Copy, PartialEq, Eq, Hash, strum::Display, strum::EnumIter, Ord, PartialOrd,
|
||||
)]
|
||||
pub enum Keyring {
|
||||
Alice,
|
||||
Bob,
|
||||
Charlie,
|
||||
Dave,
|
||||
Eve,
|
||||
Ferdie,
|
||||
AliceStash,
|
||||
BobStash,
|
||||
CharlieStash,
|
||||
DaveStash,
|
||||
EveStash,
|
||||
FerdieStash,
|
||||
One,
|
||||
Two,
|
||||
}
|
||||
|
||||
impl Keyring {
|
||||
pub fn from_public(who: &Public) -> Option<Keyring> {
|
||||
Self::iter().find(|&k| &Public::from(k) == who)
|
||||
}
|
||||
|
||||
pub fn from_account_id(who: &AccountId32) -> Option<Keyring> {
|
||||
Self::iter().find(|&k| &k.to_account_id() == who)
|
||||
}
|
||||
|
||||
pub fn from_raw_public(who: [u8; 32]) -> Option<Keyring> {
|
||||
Self::from_public(&Public::from_raw(who))
|
||||
}
|
||||
|
||||
pub fn to_raw_public(self) -> [u8; 32] {
|
||||
*Public::from(self).as_array_ref()
|
||||
}
|
||||
|
||||
pub fn from_h256_public(who: H256) -> Option<Keyring> {
|
||||
Self::from_public(&Public::from_raw(who.into()))
|
||||
}
|
||||
|
||||
pub fn to_h256_public(self) -> H256 {
|
||||
Public::from(self).as_array_ref().into()
|
||||
}
|
||||
|
||||
pub fn to_raw_public_vec(self) -> Vec<u8> {
|
||||
Public::from(self).to_raw_vec()
|
||||
}
|
||||
|
||||
pub fn to_account_id(self) -> AccountId32 {
|
||||
self.to_raw_public().into()
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub fn sign(self, msg: &[u8]) -> Signature {
|
||||
Pair::from(self).sign(msg)
|
||||
}
|
||||
|
||||
pub fn pair(self) -> Pair {
|
||||
Pair::from_string(&format!("//{}", <&'static str>::from(self)), None)
|
||||
.expect("static values are known good; qed")
|
||||
}
|
||||
|
||||
/// Returns an iterator over all test accounts.
|
||||
pub fn iter() -> impl Iterator<Item = Keyring> {
|
||||
<Self as strum::IntoEnumIterator>::iter()
|
||||
}
|
||||
|
||||
pub fn public(self) -> Public {
|
||||
Public::from(self)
|
||||
}
|
||||
|
||||
pub fn to_seed(self) -> String {
|
||||
format!("//{}", self)
|
||||
}
|
||||
|
||||
/// Create a crypto `Pair` from a numeric value.
|
||||
pub fn numeric(idx: usize) -> Pair {
|
||||
Pair::from_string(&format!("//{}", idx), None).expect("numeric values are known good; qed")
|
||||
}
|
||||
|
||||
/// Get account id of a `numeric` account.
|
||||
pub fn numeric_id(idx: usize) -> AccountId32 {
|
||||
(*Self::numeric(idx).public().as_array_ref()).into()
|
||||
}
|
||||
|
||||
pub fn well_known() -> impl Iterator<Item = Keyring> {
|
||||
Self::iter().take(12)
|
||||
}
|
||||
|
||||
pub fn invulnerable() -> impl Iterator<Item = Keyring> {
|
||||
Self::iter().take(6)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for &'static str {
|
||||
fn from(k: Keyring) -> Self {
|
||||
match k {
|
||||
Keyring::Alice => "Alice",
|
||||
Keyring::Bob => "Bob",
|
||||
Keyring::Charlie => "Charlie",
|
||||
Keyring::Dave => "Dave",
|
||||
Keyring::Eve => "Eve",
|
||||
Keyring::Ferdie => "Ferdie",
|
||||
Keyring::AliceStash => "Alice//stash",
|
||||
Keyring::BobStash => "Bob//stash",
|
||||
Keyring::CharlieStash => "Charlie//stash",
|
||||
Keyring::DaveStash => "Dave//stash",
|
||||
Keyring::EveStash => "Eve//stash",
|
||||
Keyring::FerdieStash => "Ferdie//stash",
|
||||
Keyring::One => "One",
|
||||
Keyring::Two => "Two",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for pezsp_runtime::MultiSigner {
|
||||
fn from(x: Keyring) -> Self {
|
||||
pezsp_runtime::MultiSigner::Sr25519(x.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Keyring {
|
||||
type Err = ParseKeyringError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {
|
||||
match s {
|
||||
"Alice" | "alice" => Ok(Keyring::Alice),
|
||||
"Bob" | "bob" => Ok(Keyring::Bob),
|
||||
"Charlie" | "charlie" => Ok(Keyring::Charlie),
|
||||
"Dave" | "dave" => Ok(Keyring::Dave),
|
||||
"Eve" | "eve" => Ok(Keyring::Eve),
|
||||
"Ferdie" | "ferdie" => Ok(Keyring::Ferdie),
|
||||
"Alice//stash" | "alice//stash" => Ok(Keyring::AliceStash),
|
||||
"Bob//stash" | "bob//stash" => Ok(Keyring::BobStash),
|
||||
"Charlie//stash" | "charlie//stash" => Ok(Keyring::CharlieStash),
|
||||
"Dave//stash" | "dave//stash" => Ok(Keyring::DaveStash),
|
||||
"Eve//stash" | "eve//stash" => Ok(Keyring::EveStash),
|
||||
"Ferdie//stash" | "ferdie//stash" => Ok(Keyring::FerdieStash),
|
||||
"One" | "one" => Ok(Keyring::One),
|
||||
"Two" | "two" => Ok(Keyring::Two),
|
||||
_ => Err(ParseKeyringError),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for AccountId32 {
|
||||
fn from(k: Keyring) -> Self {
|
||||
k.to_account_id()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for Public {
|
||||
fn from(k: Keyring) -> Self {
|
||||
Public::from_raw(k.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for Pair {
|
||||
fn from(k: Keyring) -> Self {
|
||||
k.pair()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for [u8; 32] {
|
||||
fn from(k: Keyring) -> Self {
|
||||
match k {
|
||||
Keyring::Alice => {
|
||||
hex2array!("d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d")
|
||||
},
|
||||
Keyring::Bob => {
|
||||
hex2array!("8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48")
|
||||
},
|
||||
Keyring::Charlie => {
|
||||
hex2array!("90b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22")
|
||||
},
|
||||
Keyring::Dave => {
|
||||
hex2array!("306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc20")
|
||||
},
|
||||
Keyring::Eve => {
|
||||
hex2array!("e659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e")
|
||||
},
|
||||
Keyring::Ferdie => {
|
||||
hex2array!("1cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07c")
|
||||
},
|
||||
Keyring::AliceStash => {
|
||||
hex2array!("be5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f")
|
||||
},
|
||||
Keyring::BobStash => {
|
||||
hex2array!("fe65717dad0447d715f660a0a58411de509b42e6efb8375f562f58a554d5860e")
|
||||
},
|
||||
Keyring::CharlieStash => {
|
||||
hex2array!("1e07379407fecc4b89eb7dbd287c2c781cfb1907a96947a3eb18e4f8e7198625")
|
||||
},
|
||||
Keyring::DaveStash => {
|
||||
hex2array!("e860f1b1c7227f7c22602f53f15af80747814dffd839719731ee3bba6edc126c")
|
||||
},
|
||||
Keyring::EveStash => {
|
||||
hex2array!("8ac59e11963af19174d0b94d5d78041c233f55d2e19324665bafdfb62925af2d")
|
||||
},
|
||||
Keyring::FerdieStash => {
|
||||
hex2array!("101191192fc877c24d725b337120fa3edc63d227bbc92705db1e2cb65f56981a")
|
||||
},
|
||||
Keyring::One => {
|
||||
hex2array!("ac859f8a216eeb1b320b4c76d118da3d7407fa523484d0a980126d3b4d0d220a")
|
||||
},
|
||||
Keyring::Two => {
|
||||
hex2array!("1254f7017f0b8347ce7ab14f96d818802e7e9e0c0d1b7c9acb3c726b080e7a03")
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keyring> for H256 {
|
||||
fn from(k: Keyring) -> Self {
|
||||
k.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use pezsp_core::{sr25519::Pair, Pair as PairT};
|
||||
|
||||
#[test]
|
||||
fn should_work() {
|
||||
assert!(Pair::verify(
|
||||
&Keyring::Alice.sign(b"I am Alice!"),
|
||||
b"I am Alice!",
|
||||
&Keyring::Alice.public(),
|
||||
));
|
||||
assert!(!Pair::verify(
|
||||
&Keyring::Alice.sign(b"I am Alice!"),
|
||||
b"I am Bob!",
|
||||
&Keyring::Alice.public(),
|
||||
));
|
||||
assert!(!Pair::verify(
|
||||
&Keyring::Alice.sign(b"I am Alice!"),
|
||||
b"I am Alice!",
|
||||
&Keyring::Bob.public(),
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_static_public_keys() {
|
||||
assert!(Keyring::iter().all(|k| { k.pair().public().as_ref() == <[u8; 32]>::from(k) }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_well_known() {
|
||||
assert_eq!(
|
||||
Keyring::well_known().collect::<Vec<Keyring>>(),
|
||||
vec![
|
||||
Keyring::Alice,
|
||||
Keyring::Bob,
|
||||
Keyring::Charlie,
|
||||
Keyring::Dave,
|
||||
Keyring::Eve,
|
||||
Keyring::Ferdie,
|
||||
Keyring::AliceStash,
|
||||
Keyring::BobStash,
|
||||
Keyring::CharlieStash,
|
||||
Keyring::DaveStash,
|
||||
Keyring::EveStash,
|
||||
Keyring::FerdieStash
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_invulnerable() {
|
||||
assert_eq!(
|
||||
Keyring::invulnerable().collect::<Vec<Keyring>>(),
|
||||
vec![
|
||||
Keyring::Alice,
|
||||
Keyring::Bob,
|
||||
Keyring::Charlie,
|
||||
Keyring::Dave,
|
||||
Keyring::Eve,
|
||||
Keyring::Ferdie
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user