@@ -25,7 +25,7 @@ use crypto::key::{
2525} ;
2626use utils:: ensure;
2727
28- use crate :: signer:: ledger_signer:: LedgerError ;
28+ use crate :: signer:: ledger_signer:: { LedgerError , SHORT_TIMEOUT_DUR , TIMEOUT_DUR } ;
2929
3030use super :: LedgerSignature ;
3131
@@ -43,13 +43,6 @@ macro_rules! ensure_response_type {
4343 } ;
4444}
4545
46- /// Timeout duration for normal Ledger operations
47- const TIMEOUT_DUR : Duration = Duration :: from_secs ( 100 ) ;
48- /// While trying to get a successful operation use a short timeout.
49- /// Used in between normal operations when the screen is showing success/failure,
50- /// and the Ledger app doesn't respond with any response so no need to wait for a long time.
51- const SHORT_TIMEOUT_DUR : Duration = Duration :: from_millis ( 200 ) ;
52-
5346/// Check that the response ends with the OK status code and return the rest of the response back
5447fn extract_response_apdu_data ( mut resp : Vec < u8 > ) -> Result < Vec < u8 > , LedgerError > {
5548 let ( _, status_code) = resp. split_last_chunk ( ) . ok_or ( LedgerError :: InvalidResponseApdu ) ?;
@@ -128,13 +121,13 @@ fn make_apdu<'a>(
128121
129122pub async fn sign_challenge < L : Exchange > (
130123 ledger : & mut L ,
131- coin : ledger_msg:: CoinType ,
124+ coin_type : ledger_msg:: CoinType ,
132125 path : ledger_msg:: Bip32Path ,
133126 addr_type : ledger_msg:: AddrType ,
134127 message : & [ u8 ] ,
135128) -> Result < ledger_msg:: Signature , LedgerError > {
136129 let req = ledger_msg:: SignMessageStartReq {
137- coin ,
130+ coin_type ,
138131 addr_type,
139132 path,
140133 } ;
@@ -143,7 +136,7 @@ pub async fn sign_challenge<L: Exchange>(
143136 ledger,
144137 ledger_msg:: Ins :: SIGN_MSG ,
145138 ledger_msg:: SignMsgP1 :: Start . into ( ) ,
146- & ledger_msg:: encode ( req) ,
139+ & ledger_msg:: encode ( & req) ,
147140 )
148141 . await ?;
149142 let resp = decode_response ( & resp) ?;
@@ -163,16 +156,20 @@ pub async fn sign_challenge<L: Exchange>(
163156 Ok ( resp. signature )
164157}
165158
159+ pub fn check_current_app_info ( info : ledger_lib:: info:: AppInfo ) -> Result < String , LedgerError > {
160+ ensure ! (
161+ info. name == "Mintlayer" ,
162+ LedgerError :: DifferentActiveApp ( info. name)
163+ ) ;
164+ Ok ( info. version )
165+ }
166+
167+ #[ allow( unused) ]
166168pub async fn check_current_app < L : Exchange + Device + Send > (
167169 ledger : & mut L ,
168170) -> Result < String , LedgerError > {
169171 let info = ledger. app_info ( TIMEOUT_DUR ) . await ?;
170- let name = info. name ;
171- let app_version = info. version ;
172-
173- ensure ! ( name == "Mintlayer" , LedgerError :: DifferentActiveApp ( name) ) ;
174-
175- Ok ( app_version)
172+ check_current_app_info ( info)
176173}
177174
178175pub async fn ping < L : Exchange > ( ledger : & mut L ) -> Result < ( ) , LedgerError > {
@@ -202,7 +199,7 @@ pub async fn get_extended_public_key<L: Exchange>(
202199 ledger,
203200 ledger_msg:: Ins :: GET_PUB_KEY ,
204201 ledger_msg:: GetPubKeyP1 :: NoDisplayAddress . into ( ) ,
205- & ledger_msg:: encode ( req) ,
202+ & ledger_msg:: encode ( & req) ,
206203 )
207204 . await ?;
208205
@@ -220,13 +217,13 @@ pub async fn get_extended_public_key<L: Exchange>(
220217
221218pub async fn sign_tx < L : Exchange > (
222219 ledger : & mut L ,
223- chain_type : ledger_msg:: CoinType ,
220+ coin_type : ledger_msg:: CoinType ,
224221 inputs : Vec < ledger_msg:: TxInputData > ,
225222 input_commitments : Vec < ledger_msg:: SighashInputCommitment > ,
226223 outputs : Vec < ledger_msg:: TxOutputData > ,
227224) -> Result < BTreeMap < usize , Vec < LedgerSignature > > , LedgerError > {
228- let start_req = ledger_msg:: encode ( ledger_msg:: SignTxStartReq {
229- coin : chain_type ,
225+ let start_req = ledger_msg:: encode ( & ledger_msg:: SignTxStartReq {
226+ coin_type ,
230227 version : ledger_msg:: TransactionVersion :: V1 ,
231228 num_inputs : inputs. len ( ) as u32 ,
232229 num_outputs : outputs. len ( ) as u32 ,
@@ -247,7 +244,7 @@ pub async fn sign_tx<L: Exchange>(
247244 ledger,
248245 ledger_msg:: Ins :: SIGN_TX ,
249246 ledger_msg:: SignTxP1 :: Next . into ( ) ,
250- & ledger_msg:: encode ( ledger_msg:: SignTxNextReq :: ProcessInput ( Box :: new ( input) ) ) ,
247+ & ledger_msg:: encode ( & ledger_msg:: SignTxNextReq :: ProcessInput ( Box :: new ( input) ) ) ,
251248 )
252249 . await ?;
253250 let resp = decode_response ( & resp) ?;
@@ -259,9 +256,9 @@ pub async fn sign_tx<L: Exchange>(
259256 ledger,
260257 ledger_msg:: Ins :: SIGN_TX ,
261258 ledger_msg:: SignTxP1 :: Next . into ( ) ,
262- & ledger_msg:: encode ( ledger_msg:: SignTxNextReq :: ProcessInputCommitment ( Box :: new (
263- ledger_msg:: TxInputCommitmentData { commitment } ,
264- ) ) ) ,
259+ & ledger_msg:: encode ( & ledger_msg:: SignTxNextReq :: ProcessInputCommitment (
260+ Box :: new ( ledger_msg:: TxInputCommitmentData { commitment } ) ,
261+ ) ) ,
265262 )
266263 . await ?;
267264 let resp = decode_response ( & resp) ?;
@@ -273,7 +270,7 @@ pub async fn sign_tx<L: Exchange>(
273270 ledger,
274271 ledger_msg:: Ins :: SIGN_TX ,
275272 ledger_msg:: SignTxP1 :: Next . into ( ) ,
276- & ledger_msg:: encode ( ledger_msg:: SignTxNextReq :: ProcessOutput ( Box :: new ( output) ) ) ,
273+ & ledger_msg:: encode ( & ledger_msg:: SignTxNextReq :: ProcessOutput ( Box :: new ( output) ) ) ,
277274 )
278275 . await ?;
279276
@@ -282,7 +279,7 @@ pub async fn sign_tx<L: Exchange>(
282279 }
283280
284281 let next_sig_raw_req = {
285- let next_sig = ledger_msg:: encode ( ledger_msg:: SignTxNextReq :: ReturnNextSignature ) ;
282+ let next_sig = ledger_msg:: encode ( & ledger_msg:: SignTxNextReq :: ReturnNextSignature ) ;
286283 let apdu = make_apdu (
287284 ledger_msg:: Ins :: SIGN_TX ,
288285 ledger_msg:: SignTxP1 :: Next . into ( ) ,
0 commit comments