1extern crate core;
5
6pub use bitcoin::Network;
7pub use bitcoin::bip32::ChainCode;
8pub use bitcoin::key::FromSliceError;
9pub use bitcoin::psbt::{Psbt, PsbtParseError};
10pub use bitcoin::secp256k1::{Error as SecpError, rand};
11pub use bitcoin_hashes::sha256::Hash;
12pub use miniscript::descriptor;
13
14pub use error::{
15 CardError, CertsError, ChangeError, CkTapError, DeriveError, DumpError, ReadError,
16 SignPsbtError, StatusError, UnsealError, XpubError,
17};
18pub use shared::CkTransport;
19
20use bitcoin::key::rand::Rng as _;
21
22pub(crate) mod apdu;
23pub mod error;
24pub mod sats_card;
25pub mod sats_chip;
26pub mod shared;
27pub mod tap_signer;
28
29#[cfg(feature = "emulator")]
30pub mod emulator;
31
32#[cfg(feature = "pcsc")]
33pub mod pcsc;
34
35pub type SatsCard = sats_card::SatsCard;
36pub type TapSigner = tap_signer::TapSigner;
37pub type SatsChip = sats_chip::SatsChip;
38
39const BIP32_HARDENED_MASK: u32 = 1 << 31;
41
42pub enum CkTapCard {
43 SatsCard(SatsCard),
44 TapSigner(TapSigner),
45 SatsChip(SatsChip),
46}
47
48impl core::fmt::Debug for CkTapCard {
49 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
50 match &self {
51 CkTapCard::TapSigner(ts) => {
52 write!(f, "CkTap::TapSigner({ts:?})")
53 }
54 CkTapCard::SatsChip(sc) => {
55 write!(f, "CkTap::SatsChip({sc:?})")
56 }
57 CkTapCard::SatsCard(sc) => {
58 write!(f, "CkTap::SatsCard({sc:?})")
59 }
60 }
61 }
62}
63
64pub fn rand_chaincode() -> ChainCode {
67 let rng = &mut rand::thread_rng();
68 let mut chain_code = [0u8; 32];
69 rng.fill(&mut chain_code);
70 ChainCode::from(chain_code)
71}
72
73pub fn rand_nonce() -> [u8; 16] {
74 let rng = &mut rand::thread_rng();
75 let mut nonce = [0u8; 16];
76 rng.fill(&mut nonce);
77 nonce
78}