partner_chains_cli/
keystore.rs

1pub struct KeyDefinition<'a> {
2	pub name: &'a str,
3	pub scheme: &'a str,
4	pub key_type: &'a str,
5}
6
7impl<'a> KeyDefinition<'a> {
8	pub fn key_type_hex(&self) -> String {
9		hex::encode(self.key_type)
10	}
11}
12
13pub const AURA: KeyDefinition<'static> =
14	KeyDefinition { name: "Aura", scheme: "sr25519", key_type: "aura" };
15pub const GRANDPA: KeyDefinition<'static> =
16	KeyDefinition { name: "Grandpa", scheme: "ed25519", key_type: "gran" };
17pub const CROSS_CHAIN: KeyDefinition<'static> =
18	KeyDefinition { name: "Cross-chain", scheme: "ecdsa", key_type: "crch" };
19
20pub fn keystore_path(substrate_node_base_path: &str) -> String {
21	format!("{substrate_node_base_path}/keystore")
22}
23
24pub fn find_existing_key(existing_keys: &[String], key_def: &KeyDefinition) -> Option<String> {
25	existing_keys
26		.iter()
27		.find_map(|key| key.strip_prefix(&key_def.key_type_hex()))
28		.map(String::from)
29		.clone()
30}