@@ -4,19 +4,18 @@ use std::io::Read;
44
55use anyhow:: Result ;
66use chacha20poly1305:: { ChaCha20Poly1305 , Key , KeyInit , Nonce } ;
7- use ed25519_dalek:: { Keypair , PublicKey , SecretKey , Signer } ;
7+ use ed25519_dalek:: { Keypair , PublicKey , SecretKey } ;
88use rand:: Rng ;
99use secstr:: SecUtf8 ;
1010use serde:: { Deserialize , Serialize } ;
1111
12- use nekoton_utils:: * ;
13-
1412use super :: mnemonic:: * ;
1513use super :: {
16- default_key_name, extend_with_signature_id , Password , PasswordCache , PasswordCacheTransaction ,
17- PubKey , SharedSecret , SignatureId , Signer as StoreSigner , SignerContext , SignerEntry ,
18- SignerStorage ,
14+ default_key_name, signature_domain :: SignatureDomain , Password , PasswordCache ,
15+ PasswordCacheTransaction , PubKey , SharedSecret , Signer as StoreSigner , SignerContext ,
16+ SignerEntry , SignerStorage ,
1917} ;
18+ use nekoton_utils:: * ;
2019
2120#[ derive( Default , Clone , Debug , Eq , PartialEq ) ]
2221pub struct EncryptedKeySigner {
@@ -194,7 +193,7 @@ impl StoreSigner for EncryptedKeySigner {
194193 & self ,
195194 ctx : SignerContext < ' _ > ,
196195 data : & [ u8 ] ,
197- signature_id : Option < SignatureId > ,
196+ signature_domain : SignatureDomain ,
198197 input : Self :: SignInput ,
199198 ) -> Result < [ u8 ; 64 ] > {
200199 let key = self . get_key ( & input. public_key ) ?;
@@ -203,7 +202,7 @@ impl StoreSigner for EncryptedKeySigner {
203202 . password_cache
204203 . process_password ( input. public_key . to_bytes ( ) , input. password ) ?;
205204
206- let signature = key. sign ( data , signature_id , password. as_ref ( ) ) ?;
205+ let signature = key. sign ( signature_domain , data , password. as_ref ( ) ) ?;
207206
208207 password. proceed ( ) ;
209208 Ok ( signature)
@@ -470,11 +469,11 @@ impl EncryptedKey {
470469
471470 pub fn sign (
472471 & self ,
472+ signature_domain : SignatureDomain ,
473473 data : & [ u8 ] ,
474- signature_id : Option < SignatureId > ,
475474 password : & str ,
476475 ) -> Result < [ u8 ; ed25519_dalek:: SIGNATURE_LENGTH ] > {
477- self . inner . sign ( data , signature_id , password)
476+ self . inner . sign ( signature_domain , data , password)
478477 }
479478
480479 pub fn compute_shared_keys (
@@ -531,17 +530,17 @@ struct CryptoData {
531530impl CryptoData {
532531 pub fn sign (
533532 & self ,
533+ signature_domain : SignatureDomain ,
534534 data : & [ u8 ] ,
535- signature_id : Option < SignatureId > ,
536535 password : & str ,
537536 ) -> Result < [ u8 ; ed25519_dalek:: SIGNATURE_LENGTH ] > {
538537 let secret = self . decrypt_secret ( password) ?;
539538 let pair = Keypair {
540539 secret,
541540 public : self . pubkey ,
542541 } ;
543- let data = extend_with_signature_id ( data , signature_id ) ;
544- Ok ( pair . sign ( & data ) . to_bytes ( ) )
542+ let signature = signature_domain . sign ( & pair , data ) ;
543+ Ok ( signature . to_bytes ( ) )
545544 }
546545
547546 pub fn compute_shared_keys (
@@ -705,7 +704,7 @@ mod tests {
705704 . unwrap ( ) ;
706705
707706 assert ! ( !signer. as_json( ) . is_empty( ) ) ;
708- let result = signer. sign ( b"lol" , None , "lol" ) ;
707+ let result = signer. sign ( SignatureDomain :: Empty , b"lol" , "lol" ) ;
709708 assert ! ( result. is_err( ) ) ;
710709 }
711710
0 commit comments