domain_test_service/
keyring.rs1use fp_account::AccountId20;
3use sp_core::ecdsa::{Pair, Public, Signature};
4use sp_core::{Pair as PairT, ecdsa};
5use sp_crypto_hashing::keccak_256;
6
7#[allow(missing_docs)]
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9pub enum Keyring {
10 Alice,
11 Bob,
12 Charlie,
13 Dave,
14 Eve,
15 Ferdie,
16 One,
17 Two,
18}
19
20impl Keyring {
21 pub fn sign(self, msg: &[u8]) -> Signature {
23 let msg = keccak_256(msg);
24 self.pair().sign_prehashed(&msg)
25 }
26
27 pub fn pair(self) -> Pair {
29 ecdsa::Pair::from_string(self.to_seed().as_str(), None).unwrap()
30 }
31
32 pub fn public(self) -> Public {
34 self.pair().public()
35 }
36
37 pub fn to_seed(self) -> String {
39 format!("//{self:?}")
40 }
41
42 pub fn to_account_id(self) -> AccountId20 {
44 self.public().into()
45 }
46}