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