@@ -11,6 +11,7 @@ use crate::data::{
1111use crate :: persistence:: file_upload:: FileUploadStoreApi ;
1212use crate :: persistence:: identity:: IdentityChainStoreApi ;
1313use async_trait:: async_trait;
14+ use bcr_ebill_core:: identity:: ActiveIdentityState ;
1415use log:: info;
1516use std:: sync:: Arc ;
1617
@@ -61,6 +62,15 @@ pub trait IdentityServiceApi: Send + Sync {
6162 file_name : & str ,
6263 private_key : & str ,
6364 ) -> Result < Vec < u8 > > ;
65+
66+ /// gets the currently set identity
67+ async fn get_current_identity ( & self ) -> Result < ActiveIdentityState > ;
68+
69+ /// sets the active identity to the given personal node id
70+ async fn set_current_personal_identity ( & self , node_id : & str ) -> Result < ( ) > ;
71+
72+ /// sets the active identity to the given company node id
73+ async fn set_current_company_identity ( & self , node_id : & str ) -> Result < ( ) > ;
6474}
6575
6676/// The identity service is responsible for managing the local identity
@@ -345,6 +355,32 @@ impl IdentityServiceApi for IdentityService {
345355 let decrypted = util:: crypto:: decrypt_ecies ( & read_file, private_key) ?;
346356 Ok ( decrypted)
347357 }
358+
359+ async fn get_current_identity ( & self ) -> Result < ActiveIdentityState > {
360+ let active_identity = self . store . get_current_identity ( ) . await ?;
361+ Ok ( active_identity)
362+ }
363+
364+ async fn set_current_personal_identity ( & self , node_id : & str ) -> Result < ( ) > {
365+ self . store
366+ . set_current_identity ( & ActiveIdentityState {
367+ personal : node_id. to_owned ( ) ,
368+ company : None ,
369+ } )
370+ . await ?;
371+ Ok ( ( ) )
372+ }
373+
374+ async fn set_current_company_identity ( & self , node_id : & str ) -> Result < ( ) > {
375+ let active_identity = self . store . get_current_identity ( ) . await ?;
376+ self . store
377+ . set_current_identity ( & ActiveIdentityState {
378+ personal : active_identity. personal ,
379+ company : Some ( node_id. to_owned ( ) ) ,
380+ } )
381+ . await ?;
382+ Ok ( ( ) )
383+ }
348384}
349385
350386#[ cfg( test) ]
0 commit comments