Skip to content

Commit 7c11641

Browse files
authored
Merge pull request #2089 from mintlayer/ledger_update_repo_ref_and_fix_reconnection
Update ledger repo ref; fix device discovery and reconnection
2 parents 82cdd44 + c866a6f commit 7c11641

15 files changed

Lines changed: 1179 additions & 178 deletions

File tree

Cargo.lock

Lines changed: 8 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ serde = "1.0"
243243
serde_json = "1.0"
244244
serde_test = "1.0"
245245
serde_with = "3.6"
246-
serial_test = "3.2"
246+
serial_test = "3.5"
247247
sha-1 = "0.10"
248248
sha2 = "0.10"
249249
sha3 = "0.10"
@@ -300,8 +300,8 @@ rev = "c8ed12e89788e78d77cdc0dc9fb8a4bd4dc24b89"
300300

301301
[workspace.dependencies.mintlayer-ledger-messages]
302302
git = "https://github.com/mintlayer/mintlayer-ledger-app"
303-
# The commit "Merge pull request #22 from mintlayer/fix_core_repo_build"
304-
rev = "44988a5ba1efc8b008a8ec61f32e4d7596999023"
303+
# The commit "Merge pull request #23 from mintlayer/bugfixing"
304+
rev = "16cc563caa5d3f746cc1b62608b88c3bdb284fa4"
305305
package = "mintlayer-messages"
306306

307307
[workspace.dependencies.trezor-client]

supply-chain/config.toml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,10 +1188,6 @@ criteria = "safe-to-deploy"
11881188
version = "0.14.1"
11891189
criteria = "safe-to-deploy"
11901190

1191-
[[exemptions.scc]]
1192-
version = "2.4.0"
1193-
criteria = "safe-to-run"
1194-
11951191
[[exemptions.schannel]]
11961192
version = "0.1.28"
11971193
criteria = "safe-to-deploy"
@@ -1208,10 +1204,6 @@ criteria = "safe-to-deploy"
12081204
version = "0.10.1"
12091205
criteria = "safe-to-deploy"
12101206

1211-
[[exemptions.sdd]]
1212-
version = "3.0.10"
1213-
criteria = "safe-to-run"
1214-
12151207
[[exemptions.security-framework]]
12161208
version = "2.11.1"
12171209
criteria = "safe-to-run"
@@ -1249,11 +1241,11 @@ version = "3.16.1"
12491241
criteria = "safe-to-deploy"
12501242

12511243
[[exemptions.serial_test]]
1252-
version = "3.3.1"
1244+
version = "3.5.0"
12531245
criteria = "safe-to-run"
12541246

12551247
[[exemptions.serial_test_derive]]
1256-
version = "3.3.1"
1248+
version = "3.5.0"
12571249
criteria = "safe-to-run"
12581250

12591251
[[exemptions.signal-hook]]

supply-chain/imports.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ user-login = "taiki-e"
428428
user-name = "Taiki Endo"
429429

430430
[[publisher.crossbeam-epoch]]
431-
version = "0.9.18"
432-
when = "2024-01-08"
431+
version = "0.9.20"
432+
when = "2026-07-06"
433433
user-id = 33035
434434
user-login = "taiki-e"
435435
user-name = "Taiki Endo"

wallet/LEDGER_SUPPORT.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Using Mintlayer with Ledger
2+
3+
At this moment Mintlayer Ledger App is not among the official Ledger apps, so you'll have to build
4+
and install it yourself. See https://github.com/mintlayer/mintlayer-ledger-app/blob/master/README.md
5+
for the details on how to do it.
6+
7+
ℹ️ If you want to use a Mintlayer wallet with Mintlayer Ledger App running in the emulator (Speculos),
8+
note that the wallet expects the emulator to be available on port 1237, while the instructions
9+
in the app's README use port 9999. Make sure you pass 1237 as `--apdu-port` to Speculos, or, if you're
10+
running it in the Docker container, map the host port 1237 to whatever you use inside the container,
11+
e.g. `--publish 1237:9999`.

wallet/src/key_chain/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ pub fn make_path_to_vrf_key(chain_config: &ChainConfig, account_index: U31) -> D
350350
path.try_into().expect("Path creation should not fail")
351351
}
352352

353-
fn get_purpose_and_index(
353+
pub fn get_purpose_and_index(
354354
derivation_path: &DerivationPath,
355355
) -> KeyChainResult<(KeyPurpose, ChildNumber)> {
356356
// Check that derivation path has the expected number of nodes

wallet/src/send_request/mod.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -210,35 +210,6 @@ impl SendRequest {
210210
Ok(())
211211
}
212212

213-
pub fn from_transaction<'a, PoolDataGetter>(
214-
transaction: Transaction,
215-
utxos: Vec<TxOutput>,
216-
pool_data_getter: &PoolDataGetter,
217-
) -> WalletResult<Self>
218-
where
219-
PoolDataGetter: Fn(&PoolId) -> Option<&'a PoolData>,
220-
{
221-
let destinations = utxos
222-
.iter()
223-
.map(|utxo| {
224-
get_tx_output_destination(utxo, &pool_data_getter, HtlcSpendingCondition::Skip)
225-
.ok_or_else(|| {
226-
WalletError::UnsupportedTransactionOutput(Box::new(utxo.clone()))
227-
})
228-
})
229-
.collect::<WalletResult<Vec<_>>>()?;
230-
231-
Ok(Self {
232-
flags: transaction.flags(),
233-
utxos: utxos.into_iter().map(Some).collect(),
234-
destinations,
235-
inputs: transaction.inputs().to_vec(),
236-
outputs: transaction.outputs().to_vec(),
237-
htlc_secrets: vec![None; transaction.inputs().len()],
238-
fees: BTreeMap::new(),
239-
})
240-
}
241-
242213
pub fn inputs(&self) -> &[TxInput] {
243214
&self.inputs
244215
}

wallet/src/signer/ledger_signer/ledger_messages.rs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crypto::key::{
2525
};
2626
use utils::ensure;
2727

28-
use crate::signer::ledger_signer::LedgerError;
28+
use crate::signer::ledger_signer::{LedgerError, SHORT_TIMEOUT_DUR, TIMEOUT_DUR};
2929

3030
use 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
5447
fn 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

129122
pub 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)]
166168
pub 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

178175
pub 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

221218
pub 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

Comments
 (0)