partner_chains_cli/
keystore.rs

1/// Contains key definition
2pub struct KeyDefinition<'a> {
3	/// Display name of the key
4	pub name: &'a str,
5	/// Encryption scheme, one of sr25519, ed25519, or ecdsa
6	pub scheme: &'a str,
7	/// polkadot-sdk KeyTypeId in human readable form
8	pub key_type: &'a str,
9}
10
11impl<'a> KeyDefinition<'a> {
12	/// Hex encoded key type id of given key
13	pub fn key_type_hex(&self) -> String {
14		hex::encode(self.key_type)
15	}
16}
17
18/// Well known definition of AURA key
19pub const AURA: KeyDefinition<'static> =
20	KeyDefinition { name: "AURA", scheme: "sr25519", key_type: "aura" };
21/// Well known definition of Grandpa key
22pub const GRANDPA: KeyDefinition<'static> =
23	KeyDefinition { name: "Grandpa", scheme: "ed25519", key_type: "gran" };
24/// Definition of Partner-chains key
25pub 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}