fi_common/
keys.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use serde::{Deserialize, Serialize};

use crate::error::Error;

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct KeyPair {
    pub id: Option<String>,
    #[serde(rename = "type")]
    pub _type: String,
    #[serde(rename = "@context")]
    pub context: Option<String>,
    pub public_key_base58: Option<String>,
    pub private_key_base58: Option<String>,
    pub public_key_multibase: Option<String>,
    pub private_key_multibase: Option<String>,
    pub revoked: bool,
    pub controller: Option<String>,
}

pub trait VerificationKey {
    fn from_fingerprint(fingerprint: &str) -> Result<Self, Error>
    where
        Self: Sized;

    fn get_suite_id() -> &'static str
    where
        Self: Sized;

    fn get_current_suite_id(&self) -> &'static str;

    fn get_suite_context() -> &'static str
    where
        Self: Sized;

    fn get_current_suite_context(&self) -> &'static str;

    fn get_controller(&self) -> &Option<String>;

    fn get_type(&self) -> String;

    fn get_private_key_content(&self) -> &Option<String>;
    fn get_public_key_content(&self) -> &String;

    fn export(&self, public_key: bool, private_key: bool, include_context: bool) -> KeyPair;
}

pub trait AgreementKey {
    fn get_suite_context() -> &'static str
    where
        Self: Sized;

    fn get_current_suite_context(&self) -> &'static str;

    fn get_controller(&self) -> &Option<String>;

    fn get_private_key_content(&self) -> &Option<String>;
    fn get_public_key_content(&self) -> &String;

    fn export(&self, public_key: bool, private_key: bool, include_context: bool) -> KeyPair;
}