1
1
use std:: collections:: BTreeSet ;
2
2
3
+ use secp256k1:: SecretKey ;
3
4
use serde:: { Deserialize , Serialize } ;
4
5
5
6
use crate :: { ValidationError , contact:: Contact } ;
@@ -21,25 +22,31 @@ pub struct NostrContact {
21
22
pub trust_level : TrustLevel ,
22
23
/// The handshake status with this contact.
23
24
pub handshake_status : HandshakeStatus ,
25
+ /// The keys to decrypt private nostr contact details.
26
+ pub contact_private_key : Option < SecretKey > ,
24
27
}
25
28
26
29
impl NostrContact {
27
30
/// Creates a new Nostr contact from a contact. This is used when we have a contact and want to
28
31
/// create the Nostr contact from it. Handshake is set to complete and we trust the contact.
29
- pub fn from_contact ( contact : & Contact ) -> Result < Self , ValidationError > {
32
+ pub fn from_contact (
33
+ contact : & Contact ,
34
+ private_key : Option < SecretKey > ,
35
+ ) -> Result < Self , ValidationError > {
30
36
let npub = contact. node_id . npub ( ) ;
31
37
Ok ( Self {
32
38
npub,
33
39
name : Some ( contact. name . clone ( ) ) ,
34
40
relays : contact. nostr_relays . clone ( ) ,
35
41
trust_level : TrustLevel :: Trusted ,
36
42
handshake_status : HandshakeStatus :: Added ,
43
+ contact_private_key : private_key,
37
44
} )
38
45
}
39
46
40
47
/// Merges contact data into a nostr contact. This assumes at that point the handskake is
41
48
/// complete and we trust the contact.
42
- pub fn merge_contact ( & self , contact : & Contact ) -> Self {
49
+ pub fn merge_contact ( & self , contact : & Contact , private_key : Option < SecretKey > ) -> Self {
43
50
let mut relays: BTreeSet < String > = BTreeSet :: from_iter ( self . relays . clone ( ) ) ;
44
51
relays. extend ( contact. nostr_relays . clone ( ) ) ;
45
52
Self {
@@ -48,6 +55,7 @@ impl NostrContact {
48
55
relays : relays. into_iter ( ) . collect ( ) ,
49
56
trust_level : TrustLevel :: Trusted ,
50
57
handshake_status : HandshakeStatus :: Added ,
58
+ contact_private_key : private_key. or ( self . contact_private_key ) ,
51
59
}
52
60
}
53
61
}
0 commit comments