Skip to content

Commit 133237d

Browse files
committed
feat(ffi): add satscard waitStep for auth delay progress
1 parent 5ea2991 commit 133237d

File tree

4 files changed

+459
-278
lines changed

4 files changed

+459
-278
lines changed

cktap-ffi/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::sats_chip::SatsChip;
1414
use crate::tap_signer::TapSigner;
1515
use futures::lock::Mutex;
1616
use rust_cktap::shared::FactoryRootKey;
17-
use rust_cktap::shared::{Certificate, Read};
17+
use rust_cktap::shared::{Certificate, Read, Wait};
1818
use std::fmt::Debug;
1919
use std::sync::Arc;
2020

@@ -84,3 +84,12 @@ async fn check_cert(card: &mut (impl Certificate + Send + Sync)) -> Result<(), C
8484
}),
8585
}
8686
}
87+
88+
async fn wait_step(card: &mut (impl Wait + Send + Sync)) -> Result<Option<u8>, CkTapError> {
89+
if card.auth_delay().is_none() {
90+
return Ok(None);
91+
}
92+
93+
let remaining_delay = card.wait(None).await.map_err(CkTapError::from)?;
94+
Ok(remaining_delay.map(|delay| delay as u8))
95+
}

cktap-ffi/src/sats_card.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright (c) 2025 rust-cktap contributors
22
// SPDX-License-Identifier: MIT OR Apache-2.0
33

4-
use crate::check_cert;
54
use crate::error::{
65
CertsError, CkTapError, DeriveError, DumpError, ReadError, SignPsbtError, UnsealError,
76
};
7+
use crate::{check_cert, wait_step};
88
use futures::lock::Mutex;
99
use rust_cktap::descriptor::Wpkh;
1010
use rust_cktap::shared::{Authentication, Nfc, Read, Wait};
@@ -77,6 +77,12 @@ impl SatsCard {
7777
Ok(())
7878
}
7979

80+
/// Wait one second of auth delay and return the remaining delay, if any.
81+
pub async fn wait_step(&self) -> Result<Option<u8>, CkTapError> {
82+
let mut card = self.0.lock().await;
83+
wait_step(&mut *card).await
84+
}
85+
8086
/// Verify the card has authentic Coinkite root certificate
8187
pub async fn check_cert(&self) -> Result<(), CertsError> {
8288
let mut card = self.0.lock().await;

0 commit comments

Comments
 (0)