1414// limitations under the License.
1515
1616mod ledger_messages;
17- use std:: { borrow:: Cow , collections:: BTreeMap , sync:: Arc } ;
1817
19- use async_trait:: async_trait;
20- use itertools:: { izip, Itertools } ;
18+ use std:: { borrow:: Cow , collections:: BTreeMap , sync:: Arc } ;
2119
20+ use crate :: {
21+ key_chain:: { make_account_path, AccountKeyChains , FoundPubKey } ,
22+ signer:: {
23+ ledger_signer:: ledger_messages:: {
24+ check_current_app, get_app_name, get_extended_public_key, sign_challenge, sign_tx,
25+ LedgerBip32Path , LedgerInputAddressPath , LedgerSignature , LedgerTxInput ,
26+ LedgerTxInputCommitment , LedgerTxOutput ,
27+ } ,
28+ signer_utils:: { is_htlc_utxo, sign_input_with_standalone_key} ,
29+ Signer , SignerError , SignerResult ,
30+ } ,
31+ } ;
2232use common:: {
2333 chain:: {
2434 config:: ChainType ,
@@ -54,36 +64,26 @@ use crypto::key::{
5464 signature:: SignatureKind ,
5565 PrivateKey , SigAuxDataProvider , Signature , SignatureError ,
5666} ;
57- use ledger_lib:: { Exchange , Filters , LedgerHandle , LedgerProvider , Transport } ;
58- use randomness:: make_true_rng;
5967use serialization:: Encode ;
60- use tokio:: sync:: Mutex ;
6168use utils:: ensure;
6269use wallet_storage:: { WalletStorageReadLocked , WalletStorageReadUnlocked } ;
6370use wallet_types:: {
6471 hw_data:: LedgerData , partially_signed_transaction:: PartiallySignedTransaction ,
6572 signature_status:: SignatureStatus ,
6673} ;
6774
68- use crate :: {
69- key_chain:: { make_account_path, AccountKeyChains , FoundPubKey } ,
70- signer:: {
71- ledger_signer:: ledger_messages:: {
72- check_current_app, get_app_name, get_extended_public_key, sign_challenge, sign_tx,
73- LedgerBip32Path , LedgerInputAddressPath , LedgerSignature , LedgerTxInput ,
74- LedgerTxInputCommitment , LedgerTxOutput ,
75- } ,
76- signer_utils:: { is_htlc_utxo, sign_input_with_standalone_key} ,
77- Signer , SignerError , SignerResult ,
78- } ,
79- } ;
75+ use async_trait:: async_trait;
76+ use itertools:: { izip, Itertools } ;
77+ use ledger_lib:: { Exchange , Filters , LedgerHandle , LedgerProvider , Transport } ;
78+ use randomness:: make_true_rng;
79+ use tokio:: sync:: Mutex ;
8080
8181/// Signer errors
8282#[ derive( thiserror:: Error , Debug , Eq , PartialEq ) ]
8383pub enum LedgerError {
8484 #[ error( "No connected Ledger device found" ) ]
8585 NoDeviceFound ,
86- #[ error( "Different active app: \" {0}\" , opened on the Ledger. Please open the Mintlayer app." ) ]
86+ #[ error( "A different app is currently open on your Ledger device : \" {0}\" . Please close it and open the Mintlayer app instead ." ) ]
8787 DifferentActiveApp ( String ) ,
8888 #[ error( "Received an invalid response from the Ledger device" ) ]
8989 InvalidResponse ,
@@ -93,7 +93,7 @@ pub enum LedgerError {
9393 DeviceError ( String ) ,
9494 #[ error( "Missing hardware wallet data in database" ) ]
9595 MissingHardwareWalletData ,
96- #[ error( "Derivation path is to long to send to Ledger" ) ]
96+ #[ error( "Derivation path is too long to send to Ledger" ) ]
9797 PathToLong ,
9898 #[ error( "Invalid public key returned from Ledger" ) ]
9999 InvalidKey ,
@@ -105,7 +105,7 @@ pub enum LedgerError {
105105 MultipleSignaturesReturned ,
106106 #[ error( "Missing multisig index for signature returned from Device" ) ]
107107 MissingMultisigIndexForSignature ,
108- #[ error( "Invalid Signature error: {0}" ) ]
108+ #[ error( "Signature error: {0}" ) ]
109109 SignatureError ( #[ from] SignatureError ) ,
110110}
111111
@@ -117,13 +117,13 @@ struct StandaloneInput {
117117type StandaloneInputs = BTreeMap < /*input index*/ u32 , Vec < StandaloneInput > > ;
118118
119119#[ async_trait]
120- pub trait LProvider {
121- type L ;
120+ pub trait LedgerFinder {
121+ type Ledger ;
122122
123123 async fn find_ledger_device_from_db < T : WalletStorageReadLocked + Send > (
124124 & self ,
125125 db_tx : T ,
126- ) -> ( T , SignerResult < ( Self :: L , LedgerData ) > ) ;
126+ ) -> ( T , SignerResult < ( Self :: Ledger , LedgerData ) > ) ;
127127}
128128
129129pub struct LedgerSigner < L , P > {
@@ -136,7 +136,7 @@ pub struct LedgerSigner<L, P> {
136136impl < L , P > LedgerSigner < L , P >
137137where
138138 L : Exchange + Send ,
139- P : LProvider < L = L > ,
139+ P : LedgerFinder < Ledger = L > ,
140140{
141141 pub fn new ( chain_config : Arc < ChainConfig > , client : Arc < Mutex < L > > , provider : P ) -> Self {
142142 Self :: new_with_sig_aux_data_provider (
@@ -245,20 +245,20 @@ where
245245 }
246246
247247 #[ allow( clippy:: too_many_arguments) ]
248- fn make_signature < ' a , ' b , F , F2 > (
248+ fn make_signature < ' a , ' b , MakeWitnessFn , StandaloneSignerFn > (
249249 & self ,
250250 signatures : & [ LedgerSignature ] ,
251251 standalone_inputs : & ' a [ StandaloneInput ] ,
252252 destination : & ' b Destination ,
253253 sighash_type : SigHashType ,
254254 sighash : H256 ,
255255 key_chain : & impl AccountKeyChains ,
256- make_witness : F ,
257- sign_with_standalone_private_key : F2 ,
256+ make_witness : MakeWitnessFn ,
257+ sign_with_standalone_private_key : StandaloneSignerFn ,
258258 ) -> SignerResult < ( Option < InputWitness > , SignatureStatus ) >
259259 where
260- F : Fn ( StandardInputSignature ) -> InputWitness ,
261- F2 : Fn ( & ' a StandaloneInput , & ' b Destination ) -> SignerResult < InputWitness > ,
260+ MakeWitnessFn : Fn ( StandardInputSignature ) -> InputWitness ,
261+ StandaloneSignerFn : Fn ( & ' a StandaloneInput , & ' b Destination ) -> SignerResult < InputWitness > ,
262262 {
263263 match destination {
264264 Destination :: AnyoneCanSpend => Ok ( (
@@ -359,7 +359,7 @@ where
359359 . collect ( )
360360 }
361361
362- fn check_signature_status (
362+ fn check_multisig_signature_status (
363363 & self ,
364364 sighash : H256 ,
365365 current_signatures : & AuthorizedClassicalMultisigSpend ,
@@ -401,7 +401,7 @@ where
401401 current_signatures. add_signature ( idx as u8 , sig) ;
402402 }
403403
404- let status = self . check_signature_status ( sighash, & current_signatures) ?;
404+ let status = self . check_multisig_signature_status ( sighash, & current_signatures) ?;
405405
406406 Ok ( ( current_signatures, status) )
407407 }
@@ -459,7 +459,7 @@ where
459459impl < L , P > Signer for LedgerSigner < L , P >
460460where
461461 L : Exchange + Send ,
462- P : Send + Sync + LProvider < L = L > ,
462+ P : Send + Sync + LedgerFinder < Ledger = L > ,
463463{
464464 async fn sign_tx < T : WalletStorageReadUnlocked + Send > (
465465 & mut self ,
@@ -1162,4 +1162,4 @@ mod tests;
11621162
11631163#[ cfg( feature = "enable-ledger-device-tests" ) ]
11641164#[ cfg( test) ]
1165- mod speculus ;
1165+ mod speculos ;
0 commit comments