bip322_simple/
wallet.rs

1use bitcoin::{
2    secp256k1::{Secp256k1, Signing},
3    PrivateKey, PublicKey,
4};
5use miniscript::Descriptor;
6
7pub struct Wallet {
8    pub pubkey: PublicKey,
9    pub private_key: PrivateKey,
10    pub desc: Descriptor<PublicKey>,
11}
12pub enum WalletType {
13    NativeSegwit,
14    Taproot,
15}
16impl Wallet {
17    pub fn new<C: Signing>(wif: &str, wallet_type: WalletType, secp: &Secp256k1<C>) -> Self {
18        let private_key = PrivateKey::from_wif(wif).unwrap();
19        let pubkey = private_key.public_key(secp);
20        let desc = match wallet_type {
21            WalletType::NativeSegwit => Descriptor::new_wpkh(pubkey).unwrap(),
22            WalletType::Taproot => Descriptor::new_tr(pubkey, None).unwrap(),
23        };
24
25        Self {
26            pubkey,
27            private_key,
28            desc,
29        }
30    }
31}