diff --git a/gui/src/lib.rs b/gui/src/lib.rs index 082e6287..8a377d14 100644 --- a/gui/src/lib.rs +++ b/gui/src/lib.rs @@ -4,6 +4,7 @@ pub mod hw; pub mod installer; pub mod launcher; pub mod loader; +pub mod signer; pub mod ui; pub mod utils; diff --git a/gui/src/signer.rs b/gui/src/signer.rs new file mode 100644 index 00000000..50f54861 --- /dev/null +++ b/gui/src/signer.rs @@ -0,0 +1,55 @@ +pub use liana::signer::SignerError; + +use liana::{ + miniscript::bitcoin::{ + secp256k1, + util::{ + bip32::{DerivationPath, ExtendedPubKey, Fingerprint}, + psbt::Psbt, + }, + Network, + }, + signer::HotSigner, +}; + +pub struct Signer { + curve: secp256k1::Secp256k1, + key: HotSigner, + fingerprint: Fingerprint, +} + +impl Signer { + pub fn new(key: HotSigner) -> Self { + let curve = secp256k1::Secp256k1::signing_only(); + let fingerprint = key.fingerprint(&curve); + Self { + key, + curve, + fingerprint, + } + } + + pub fn generate(network: Network) -> Result { + Ok(Self::new(HotSigner::generate(network)?)) + } + + pub fn fingerprint(&self) -> Fingerprint { + self.fingerprint + } + + pub fn get_extended_pubkey(&self, path: &DerivationPath) -> ExtendedPubKey { + self.key.xpub_at(path, &self.curve) + } + + pub fn sign_psbt(&self, psbt: Psbt) -> Result { + self.key.sign_psbt(psbt, &self.curve) + } + + pub fn store( + &self, + datadir_root: &std::path::Path, + network: Network, + ) -> Result<(), SignerError> { + self.key.store(datadir_root, network, &self.curve) + } +}