Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// CLI for rust-cktap
use clap::{Parser, Subcommand};
use rpassword::read_password;
use rust_cktap::commands::{CkTransport, Read};
use rust_cktap::commands::{Authentication, CkTransport, Read, Wait};
#[cfg(feature = "emulator")]
use rust_cktap::emulator;
#[cfg(not(feature = "emulator"))]
Expand Down Expand Up @@ -41,6 +41,8 @@ enum SatsCardCommand {
Unseal,
/// Get the payment address and verify it follows from the chain code and master public key
Derive,
/// Call wait command until no auth delay
Wait,
}

/// TapSigner CLI
Expand Down Expand Up @@ -75,6 +77,8 @@ enum TapSignerCommand {
Change { new_cvc: String },
/// Sign a digest
Sign { to_sign: String },
/// Call wait command until no auth delay
Wait,
}

/// TapSigner CLI
Expand Down Expand Up @@ -107,6 +111,8 @@ enum SatsChipCommand {
Change { new_cvc: String },
/// Sign a digest
Sign { to_sign: String },
/// Call wait command until no auth delay
Wait,
}

#[tokio::main]
Expand Down Expand Up @@ -145,6 +151,7 @@ async fn main() -> Result<(), Error> {
SatsCardCommand::Derive => {
dbg!(&sc.derive().await);
}
SatsCardCommand::Wait => wait(sc).await,
}
}
CkTapCard::TapSigner(ts) => {
Expand Down Expand Up @@ -181,6 +188,7 @@ async fn main() -> Result<(), Error> {
let response = &ts.sign(digest, vec![], &cvc()).await;
println!("{response:?}");
}
TapSignerCommand::Wait => wait(ts).await,
}
}
CkTapCard::SatsChip(sc) => {
Expand Down Expand Up @@ -212,6 +220,7 @@ async fn main() -> Result<(), Error> {
let response = &sc.sign(digest, vec![], &cvc()).await;
println!("{response:?}");
}
SatsChipCommand::Wait => wait(sc).await,
}
}
}
Expand Down Expand Up @@ -254,3 +263,25 @@ fn cvc() -> String {
let cvc = read_password().unwrap();
cvc.trim().to_string()
}

async fn wait<C, T: CkTransport>(card: &mut C)
where
C: Authentication<T> + Wait<T>,
{
// if auth delay call wait
if card.auth_delay().is_some() {
let mut entered_cvc = None;
while card.auth_delay().is_some() {
if entered_cvc.is_none() {
entered_cvc = Some(cvc());
print!("Auth delay:");
io::stdout().flush().unwrap();
}
print!(" {}", card.auth_delay().unwrap());
io::stdout().flush().unwrap();
let _result = card.wait(entered_cvc.clone()).await.expect("wait failed");
}
println!();
}
println!("No auth delay.");
}
7 changes: 6 additions & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ pub mod apdu;
pub mod commands;
pub mod factory_root_key;

pub use bitcoin::secp256k1::{self, rand};
pub use bitcoin::{
Address, Network,
key::CompressedPublicKey,
key::UntweakedPublicKey,
secp256k1::{self, rand},
};

#[cfg(feature = "emulator")]
pub mod emulator;
Expand Down
1 change: 0 additions & 1 deletion lib/src/sats_card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ impl<T: CkTransport> SatsCard<T> {
}

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