Skip to content

Commit 77e5660

Browse files
committed
feat: add 'xpub' command to cli
1 parent edcae83 commit 77e5660

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

cli/src/main.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ enum TapSignerCommand {
114114
Wait,
115115
/// Get the card's nfc URL
116116
Nfc,
117+
/// Read the xpub (requires CVC)
118+
Xpub {
119+
/// Give master (`m`) XPUB, otherwise derived XPUB
120+
#[clap(short, long)]
121+
master: bool,
122+
},
117123
}
118124

119125
/// TapSigner CLI
@@ -150,6 +156,12 @@ enum SatsChipCommand {
150156
Wait,
151157
/// Get the card's nfc URL
152158
Nfc,
159+
/// Read the xpub (requires CVC)
160+
Xpub {
161+
/// Give master (`m`) XPUB, otherwise derived XPUB
162+
#[clap(short, long)]
163+
master: bool,
164+
},
153165
}
154166

155167
#[tokio::main]
@@ -238,6 +250,7 @@ async fn main() -> Result<(), CliError> {
238250
}
239251
TapSignerCommand::Wait => wait(ts).await,
240252
TapSignerCommand::Nfc => nfc(ts).await,
253+
TapSignerCommand::Xpub { master } => xpub(ts, master).await,
241254
}
242255
}
243256
CkTapCard::SatsChip(sc) => {
@@ -270,6 +283,7 @@ async fn main() -> Result<(), CliError> {
270283
}
271284
SatsChipCommand::Wait => wait(sc).await,
272285
SatsChipCommand::Nfc => nfc(sc).await,
286+
SatsChipCommand::Xpub { master } => xpub(sc, master).await,
273287
}
274288
}
275289
}
@@ -336,3 +350,13 @@ where
336350
let nfc = card.nfc().await.expect("nfc failed");
337351
println!("{nfc}");
338352
}
353+
354+
async fn xpub<C>(card: &mut C, master: bool)
355+
where
356+
C: TapSignerShared + Send,
357+
{
358+
dbg!(master);
359+
let xpub = card.xpub(master, &cvc()).await.expect("xpub failed");
360+
dbg!(&xpub);
361+
println!("{}", xpub.to_string());
362+
}

lib/src/tap_signer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ pub trait TapSignerShared: Authentication {
316316
Ok(())
317317
}
318318

319-
async fn xpub(&mut self, cvc: &str, master: bool) -> Result<Xpub, XpubError> {
319+
async fn xpub(&mut self, master: bool, cvc: &str) -> Result<Xpub, XpubError> {
320320
let (_, epubkey, xcvc) = self.calc_ekeys_xcvc(cvc, XpubCommand::name());
321321
let xpub_command = XpubCommand::new(master, epubkey, xcvc);
322322
let xpub_response: XpubResponse = transmit(self.transport(), &xpub_command).await?;
@@ -420,9 +420,9 @@ mod test {
420420
let emulator = find_emulator(pipe_path).await.unwrap();
421421
if let CkTapCard::TapSigner(mut ts) = emulator {
422422
ts.init(rand_chaincode(), "123456").await.unwrap();
423-
let xpub = ts.xpub("123456", false).await.unwrap();
423+
let xpub = ts.xpub(false, "123456").await.unwrap();
424424
assert_eq!(xpub.depth, 3);
425-
let master_xpub = ts.xpub("123456", true).await.unwrap();
425+
let master_xpub = ts.xpub(true, "123456").await.unwrap();
426426
assert_eq!(master_xpub.depth, 0);
427427
}
428428
drop(python);

0 commit comments

Comments
 (0)