Skip to main content

domain_test_service/
keyring.rs

1//! Set of test accounts.
2use 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    /// Sign `msg`.
22    pub fn sign(self, msg: &[u8]) -> Signature {
23        let msg = keccak_256(msg);
24        self.pair().sign_prehashed(&msg)
25    }
26
27    /// Return key pair.
28    pub fn pair(self) -> Pair {
29        ecdsa::Pair::from_string(self.to_seed().as_str(), None).unwrap()
30    }
31
32    /// Return public key.
33    pub fn public(self) -> Public {
34        self.pair().public()
35    }
36
37    /// Return seed string.
38    pub fn to_seed(self) -> String {
39        format!("//{self:?}")
40    }
41
42    /// Return account id
43    pub fn to_account_id(self) -> AccountId20 {
44        self.public().into()
45    }
46}