Skip to content

Commit 08c4a74

Browse files
committed
feat(cli): add wait commands
1 parent 9720d42 commit 08c4a74

3 files changed

Lines changed: 38 additions & 3 deletions

File tree

cli/src/main.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// CLI for rust-cktap
22
use clap::{Parser, Subcommand};
33
use rpassword::read_password;
4-
use rust_cktap::commands::{CkTransport, Read};
4+
use rust_cktap::commands::{Authentication, CkTransport, Read, Wait};
55
#[cfg(feature = "emulator")]
66
use rust_cktap::emulator;
77
#[cfg(not(feature = "emulator"))]
@@ -41,6 +41,8 @@ enum SatsCardCommand {
4141
Unseal,
4242
/// Get the payment address and verify it follows from the chain code and master public key
4343
Derive,
44+
/// Call wait command until no auth delay
45+
Wait,
4446
}
4547

4648
/// TapSigner CLI
@@ -75,6 +77,8 @@ enum TapSignerCommand {
7577
Change { new_cvc: String },
7678
/// Sign a digest
7779
Sign { to_sign: String },
80+
/// Call wait command until no auth delay
81+
Wait,
7882
}
7983

8084
/// TapSigner CLI
@@ -107,6 +111,8 @@ enum SatsChipCommand {
107111
Change { new_cvc: String },
108112
/// Sign a digest
109113
Sign { to_sign: String },
114+
/// Call wait command until no auth delay
115+
Wait,
110116
}
111117

112118
#[tokio::main]
@@ -145,6 +151,7 @@ async fn main() -> Result<(), Error> {
145151
SatsCardCommand::Derive => {
146152
dbg!(&sc.derive().await);
147153
}
154+
SatsCardCommand::Wait => wait(sc).await,
148155
}
149156
}
150157
CkTapCard::TapSigner(ts) => {
@@ -181,6 +188,7 @@ async fn main() -> Result<(), Error> {
181188
let response = &ts.sign(digest, vec![], &cvc()).await;
182189
println!("{response:?}");
183190
}
191+
TapSignerCommand::Wait => wait(ts).await,
184192
}
185193
}
186194
CkTapCard::SatsChip(sc) => {
@@ -212,6 +220,7 @@ async fn main() -> Result<(), Error> {
212220
let response = &sc.sign(digest, vec![], &cvc()).await;
213221
println!("{response:?}");
214222
}
223+
SatsChipCommand::Wait => wait(sc).await,
215224
}
216225
}
217226
}
@@ -254,3 +263,25 @@ fn cvc() -> String {
254263
let cvc = read_password().unwrap();
255264
cvc.trim().to_string()
256265
}
266+
267+
async fn wait<C, T: CkTransport>(card: &mut C)
268+
where
269+
C: Authentication<T> + Wait<T>,
270+
{
271+
// if auth delay call wait
272+
if card.auth_delay().is_some() {
273+
let mut entered_cvc = None;
274+
while card.auth_delay().is_some() {
275+
if entered_cvc.is_none() {
276+
entered_cvc = Some(cvc());
277+
print!("Auth delay:");
278+
io::stdout().flush().unwrap();
279+
}
280+
print!(" {}", card.auth_delay().unwrap());
281+
io::stdout().flush().unwrap();
282+
let _result = card.wait(entered_cvc.clone()).await.expect("wait failed");
283+
}
284+
println!();
285+
}
286+
println!("No auth delay.");
287+
}

lib/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ pub mod apdu;
77
pub mod commands;
88
pub mod factory_root_key;
99

10-
pub use bitcoin::secp256k1::{self, rand};
10+
pub use bitcoin::{
11+
Address, Network,
12+
key::CompressedPublicKey,
13+
key::UntweakedPublicKey,
14+
secp256k1::{self, rand},
15+
};
1116

1217
#[cfg(feature = "emulator")]
1318
pub mod emulator;

lib/src/sats_card.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ impl<T: CkTransport> SatsCard<T> {
145145
}
146146

147147
pub async fn address(&mut self) -> Result<String, Error> {
148-
// TODO: support testnet
149148
let network = Network::Bitcoin;
150149
let slot_pubkey = self.read(None).await?.pubkey;
151150
let pk = BitcoinPublicKey::from_slice(&slot_pubkey)?;

0 commit comments

Comments
 (0)