@@ -11,6 +11,7 @@ use crate::data::{
11
11
use crate :: persistence:: file_upload:: FileUploadStoreApi ;
12
12
use crate :: persistence:: identity:: IdentityChainStoreApi ;
13
13
use async_trait:: async_trait;
14
+ use bcr_ebill_core:: identity:: ActiveIdentityState ;
14
15
use log:: info;
15
16
use std:: sync:: Arc ;
16
17
@@ -61,6 +62,15 @@ pub trait IdentityServiceApi: Send + Sync {
61
62
file_name : & str ,
62
63
private_key : & str ,
63
64
) -> 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 < ( ) > ;
64
74
}
65
75
66
76
/// The identity service is responsible for managing the local identity
@@ -345,6 +355,32 @@ impl IdentityServiceApi for IdentityService {
345
355
let decrypted = util:: crypto:: decrypt_ecies ( & read_file, private_key) ?;
346
356
Ok ( decrypted)
347
357
}
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
+ }
348
384
}
349
385
350
386
#[ cfg( test) ]
0 commit comments