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()),
}
}
}