@@ -8,6 +8,7 @@ use core::cell::OnceCell;
8
8
use core:: cmp;
9
9
use core:: hash:: Hash ;
10
10
use core:: hash:: Hasher ;
11
+ use ed25519_dalek:: SecretKey ;
11
12
use ed25519_dalek:: Signer ;
12
13
use ed25519_dalek:: SigningKey ;
13
14
use ed25519_dalek:: Verifier ;
@@ -80,6 +81,15 @@ impl Secret {
80
81
}
81
82
}
82
83
84
+ #[ must_use]
85
+ pub fn from_secret_keys ( secret_key_1 : & SecretKey , secret_key_2 : & SecretKey ) -> Self {
86
+ Self {
87
+ signing_key : SigningKey :: from_bytes ( secret_key_1) ,
88
+ decryption_key : StaticSecret :: from ( * secret_key_2) ,
89
+ identity : OnceCell :: new ( ) ,
90
+ }
91
+ }
92
+
83
93
#[ inline]
84
94
#[ must_use]
85
95
pub fn signing_key ( & self ) -> & SigningKey {
@@ -320,8 +330,10 @@ mod tests {
320
330
use super :: Identity ;
321
331
use super :: Secret ;
322
332
use ed25519_dalek:: Signature ;
333
+ use ed25519_dalek:: SigningKey ;
323
334
use hex_literal:: hex;
324
335
use rand:: thread_rng;
336
+ use x25519_dalek:: StaticSecret ;
325
337
326
338
#[ test]
327
339
fn secret_to_identity ( ) {
@@ -330,6 +342,16 @@ mod tests {
330
342
id. verify ( ) . expect ( "verification failed" ) ;
331
343
}
332
344
345
+ #[ test]
346
+ fn from_secret_keys ( ) {
347
+ let mut rng = thread_rng ( ) ;
348
+ let secret_key_1 = SigningKey :: generate ( & mut rng) ;
349
+ let secret_key_2 = StaticSecret :: random_from_rng ( & mut rng) ;
350
+ let id = Secret :: from_secret_keys ( secret_key_1. as_bytes ( ) , secret_key_2. as_bytes ( ) )
351
+ . to_identity ( ) ;
352
+ id. verify ( ) . expect ( "verification failed" ) ;
353
+ }
354
+
333
355
#[ test]
334
356
fn secret_deserialization ( ) {
335
357
let secret = Secret :: random ( thread_rng ( ) ) ;
0 commit comments