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
use safe_nd::{AppFullId, ClientFullId, PublicId, Signature};
use std::sync::Arc;
use threshold_crypto::SecretKey as BlsSecretKey;
#[derive(Clone)]
pub enum SafeKey {
App(Arc<AppFullId>),
Client(Arc<ClientFullId>),
}
impl SafeKey {
pub fn client(full_id: ClientFullId) -> Self {
Self::Client(Arc::new(full_id))
}
pub fn client_from_bls_key(bls_sk: BlsSecretKey) -> Self {
Self::client(ClientFullId::with_bls_key(bls_sk))
}
pub fn app(full_id: AppFullId) -> Self {
Self::App(Arc::new(full_id))
}
pub fn sign(&self, msg: &[u8]) -> Signature {
match self {
Self::App(app_full_id) => app_full_id.sign(msg),
Self::Client(client_full_id) => client_full_id.sign(msg),
}
}
pub fn public_id(&self) -> PublicId {
match self {
Self::App(app_full_id) => PublicId::App(app_full_id.public_id().clone()),
Self::Client(client_full_id) => PublicId::Client(client_full_id.public_id().clone()),
}
}
}