|
1 | 1 | /// CLI for rust-cktap |
2 | 2 | use clap::{Parser, Subcommand}; |
3 | 3 | use rpassword::read_password; |
4 | | -use rust_cktap::commands::{CkTransport, Read}; |
| 4 | +use rust_cktap::commands::{Authentication, CkTransport, Read, Wait}; |
5 | 5 | #[cfg(feature = "emulator")] |
6 | 6 | use rust_cktap::emulator; |
7 | 7 | #[cfg(not(feature = "emulator"))] |
@@ -41,6 +41,8 @@ enum SatsCardCommand { |
41 | 41 | Unseal, |
42 | 42 | /// Get the payment address and verify it follows from the chain code and master public key |
43 | 43 | Derive, |
| 44 | + /// Call wait command until no auth delay |
| 45 | + Wait, |
44 | 46 | } |
45 | 47 |
|
46 | 48 | /// TapSigner CLI |
@@ -75,6 +77,8 @@ enum TapSignerCommand { |
75 | 77 | Change { new_cvc: String }, |
76 | 78 | /// Sign a digest |
77 | 79 | Sign { to_sign: String }, |
| 80 | + /// Call wait command until no auth delay |
| 81 | + Wait, |
78 | 82 | } |
79 | 83 |
|
80 | 84 | /// TapSigner CLI |
@@ -107,6 +111,8 @@ enum SatsChipCommand { |
107 | 111 | Change { new_cvc: String }, |
108 | 112 | /// Sign a digest |
109 | 113 | Sign { to_sign: String }, |
| 114 | + /// Call wait command until no auth delay |
| 115 | + Wait, |
110 | 116 | } |
111 | 117 |
|
112 | 118 | #[tokio::main] |
@@ -145,6 +151,7 @@ async fn main() -> Result<(), Error> { |
145 | 151 | SatsCardCommand::Derive => { |
146 | 152 | dbg!(&sc.derive().await); |
147 | 153 | } |
| 154 | + SatsCardCommand::Wait => wait(sc).await, |
148 | 155 | } |
149 | 156 | } |
150 | 157 | CkTapCard::TapSigner(ts) => { |
@@ -181,6 +188,7 @@ async fn main() -> Result<(), Error> { |
181 | 188 | let response = &ts.sign(digest, vec![], &cvc()).await; |
182 | 189 | println!("{response:?}"); |
183 | 190 | } |
| 191 | + TapSignerCommand::Wait => wait(ts).await, |
184 | 192 | } |
185 | 193 | } |
186 | 194 | CkTapCard::SatsChip(sc) => { |
@@ -212,6 +220,7 @@ async fn main() -> Result<(), Error> { |
212 | 220 | let response = &sc.sign(digest, vec![], &cvc()).await; |
213 | 221 | println!("{response:?}"); |
214 | 222 | } |
| 223 | + SatsChipCommand::Wait => wait(sc).await, |
215 | 224 | } |
216 | 225 | } |
217 | 226 | } |
@@ -254,3 +263,25 @@ fn cvc() -> String { |
254 | 263 | let cvc = read_password().unwrap(); |
255 | 264 | cvc.trim().to_string() |
256 | 265 | } |
| 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 | +} |
0 commit comments