|
| 1 | +//! WalletInterface is *not* a wallet, only an interface to bridge between |
| 2 | +//! user wallet and ChannelMonitor. If this last one discover on-chain outputs they will |
| 3 | +//! be send with associate data as events::Event::SpendableOutputs to be at the disposal of wallet. |
| 4 | +//! |
| 5 | +//! KeysInterface is no more a wallet, just an entity to get secret from user wallet and derive |
| 6 | +//! appropriate keyring materials to others lightning components, as such node_id, destination_script. |
| 7 | +//! |
| 8 | +
|
| 9 | +use bitcoin::blockdata::transaction::OutPoint; |
| 10 | +use bitcoin::blockdata::script::Script; |
| 11 | + |
| 12 | +use secp256k1::key::SecretKey; |
| 13 | + |
| 14 | +use util::events; |
| 15 | + |
| 16 | +/// A trait to describe a wallet which sould receive data to be able to spend onchain outputs |
| 17 | +/// fron a lightning channel |
| 18 | +pub trait WalletInterface: Send + Sync { |
| 19 | + /// Handle an incoming SpendableOutputs event from SimpleManyChannelMonitor containing a |
| 20 | + /// CustomOutputScriptDesctitpor. Follow doc of the latter to know how to spend the output. |
| 21 | + fn handle_spendable_output(&self, event: events::Event); |
| 22 | +} |
| 23 | + |
| 24 | +/// Hacky custom output script descriptors to ease spending of onchain outputs by user wallet |
| 25 | +/// Maybe should be changed by real ones when merged into rust-bitcoin. |
| 26 | +/// StaticOutputs commit to a static pubkey, i.e one derived once for node operation lifetime. |
| 27 | +/// DynamicOutputs commit to a dynamic local_delayedpubkey, i.e one which change for each per_commitment_point |
| 28 | +pub enum CustomOutputScriptDescriptor { |
| 29 | + /// Outpoint commits to a P2PWKH, should be spend by the following witness : |
| 30 | + /// <signature> <pubkey> |
| 31 | + /// With pubkey being bip32 /1' from HMAC-Sha512 of user-provided seed as master private key |
| 32 | + StaticOutput { |
| 33 | + /// Outpoint spendable by user wallet |
| 34 | + outpoint: OutPoint, |
| 35 | + }, |
| 36 | + /// Outpoint commits to a P2WSH, should be spend by the following witness : |
| 37 | + /// <local_delayedsig> 0 <witnessScript> |
| 38 | + /// With input nSequence set to_self_delay. |
| 39 | + DynamicOutput { |
| 40 | + /// Outpoint spendable by user wallet |
| 41 | + outpoint: OutPoint, |
| 42 | + /// local_delayedkey = delayed_payment_basepoint_secret + SHA256(per_commitment_point || delayed_payment_basepoint |
| 43 | + local_delayedkey: SecretKey, |
| 44 | + /// witness redeemScript encumbering output |
| 45 | + witness_script: Script, |
| 46 | + /// nSequence input must commit to self_delay to satisfy script's OP_CSV |
| 47 | + to_self_delay: u16, |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +impl CustomOutputScriptDescriptor { |
| 52 | + /// Build a StaticOuput descriptor |
| 53 | + pub fn static_key(outpoint: OutPoint) -> Self { |
| 54 | + CustomOutputScriptDescriptor::StaticOutput { |
| 55 | + outpoint, |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + /// Build a DynamicOuput descriptor |
| 60 | + pub fn dynamic_key(outpoint: OutPoint, local_delayedkey: SecretKey, witness_script: Script, to_self_delay: u16) -> Self { |
| 61 | + CustomOutputScriptDescriptor::DynamicOutput { |
| 62 | + outpoint, |
| 63 | + local_delayedkey, |
| 64 | + witness_script, |
| 65 | + to_self_delay, |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments