Add signer module to gui

This commit is contained in:
edouard 2023-02-07 12:56:54 +01:00
parent f3f04a41b0
commit 1f09653198
2 changed files with 56 additions and 0 deletions

View File

@ -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;

55
gui/src/signer.rs Normal file
View File

@ -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<secp256k1::SignOnly>,
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<Self, SignerError> {
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<Psbt, SignerError> {
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)
}
}