Skip to main content

keep_bitcoin/
lib.rs

1// SPDX-FileCopyrightText: © 2026 PrivKey LLC
2// SPDX-License-Identifier: MIT
3
4#![forbid(unsafe_code)]
5
6mod address;
7pub mod chain_view;
8mod descriptor;
9mod error;
10/// BIP-32 unhardened child-key primitives for FROST group keys (#487).
11///
12/// Re-exported from `keep_core::frost_bip32` so downstream call sites that
13/// used the pre-#487-PR2 path (`keep_bitcoin::frost_bip32::*`) keep
14/// compiling; the module lives in keep-core because bip32-composed FROST
15/// signing lives there and keep-bitcoin cannot depend upward on keep-core.
16pub use keep_core::frost_bip32;
17pub mod key_proof;
18pub mod psbt;
19pub mod recovery;
20pub mod recovery_tx;
21mod signer;
22
23pub use address::{AddressDerivation, DerivedAddress};
24#[cfg(feature = "esplora-chain-view")]
25pub use chain_view::{esplora_chain_view_from_env, EsploraChainView};
26pub use chain_view::{
27    validate_prevout_amounts_against_chain, ChainView, ChainViewError, KEEP_CHAIN_URL_ENV,
28};
29pub use descriptor::{
30    change_script_at_index, descriptor_address, descriptor_address_at_index,
31    descriptor_script_pubkey, multipath_from_external, xpub_to_x_only, DescriptorExport,
32};
33pub use error::{BitcoinError, Result};
34pub use key_proof::{build_key_proof_psbt, sign_key_proof, verify_key_proof};
35pub use psbt::{PsbtAnalysis, PsbtSigner};
36pub use recovery::{
37    PolicyInput, PolicyTierInput, RecoveryConfig, RecoveryOutput, RecoveryTier, SpendingTier,
38};
39pub use recovery_tx::{
40    merge_tap_script_sig, script_spend_sighashes, verify_all_script_spend_input_bindings,
41    verify_script_spend_input_binding, RecoveryTxBuilder, ScriptSpendSighash, SweepUtxo,
42    TAPROOT_DUST_LIMIT_SATS,
43};
44pub use signer::BitcoinSigner;
45
46pub use bitcoin;
47pub use bitcoin::Network;
48
49fn aux_rand() -> Result<zeroize::Zeroizing<[u8; 32]>> {
50    let mut buf = [0u8; 32];
51    getrandom::fill(&mut buf)
52        .map_err(|e| BitcoinError::Signing(format!("failed to get random bytes: {e}")))?;
53    let wrapped = zeroize::Zeroizing::new(buf);
54    zeroize::Zeroize::zeroize(&mut buf);
55    Ok(wrapped)
56}