mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 15:02:20 +01:00
Adopting (W)PubkeyHash types
This commit is contained in:
parent
27079e04d7
commit
dde344a51d
6 changed files with 20 additions and 26 deletions
|
@ -17,9 +17,8 @@ use bitcoin::blockdata::opcodes;
|
||||||
use bitcoin::network::constants::Network;
|
use bitcoin::network::constants::Network;
|
||||||
|
|
||||||
use bitcoin::hashes::Hash as TraitImport;
|
use bitcoin::hashes::Hash as TraitImport;
|
||||||
use bitcoin::hashes::hash160::Hash as Hash160;
|
|
||||||
use bitcoin::hashes::sha256::Hash as Sha256;
|
use bitcoin::hashes::sha256::Hash as Sha256;
|
||||||
use bitcoin::hash_types::BlockHash;
|
use bitcoin::hash_types::{BlockHash, WPubkeyHash};
|
||||||
|
|
||||||
use lightning::chain::chaininterface;
|
use lightning::chain::chaininterface;
|
||||||
use lightning::chain::transaction::OutPoint;
|
use lightning::chain::transaction::OutPoint;
|
||||||
|
@ -144,7 +143,7 @@ impl KeysInterface for KeyProvider {
|
||||||
fn get_destination_script(&self) -> Script {
|
fn get_destination_script(&self) -> Script {
|
||||||
let secp_ctx = Secp256k1::signing_only();
|
let secp_ctx = Secp256k1::signing_only();
|
||||||
let channel_monitor_claim_key = SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, self.node_id]).unwrap();
|
let channel_monitor_claim_key = SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, self.node_id]).unwrap();
|
||||||
let our_channel_monitor_claim_key_hash = Hash160::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
|
let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
|
||||||
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
|
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,8 @@ use bitcoin::util::hash::BitcoinHash;
|
||||||
|
|
||||||
use bitcoin::hashes::Hash as TraitImport;
|
use bitcoin::hashes::Hash as TraitImport;
|
||||||
use bitcoin::hashes::HashEngine as TraitImportEngine;
|
use bitcoin::hashes::HashEngine as TraitImportEngine;
|
||||||
use bitcoin::hashes::hash160::Hash as Hash160;
|
|
||||||
use bitcoin::hashes::sha256::Hash as Sha256;
|
use bitcoin::hashes::sha256::Hash as Sha256;
|
||||||
use bitcoin::hash_types::{Txid, BlockHash};
|
use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
|
||||||
|
|
||||||
use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,ChainListener,FeeEstimator,ChainWatchInterfaceUtil};
|
use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,ChainListener,FeeEstimator,ChainWatchInterfaceUtil};
|
||||||
use lightning::chain::transaction::OutPoint;
|
use lightning::chain::transaction::OutPoint;
|
||||||
|
@ -240,7 +239,7 @@ impl KeysInterface for KeyProvider {
|
||||||
fn get_destination_script(&self) -> Script {
|
fn get_destination_script(&self) -> Script {
|
||||||
let secp_ctx = Secp256k1::signing_only();
|
let secp_ctx = Secp256k1::signing_only();
|
||||||
let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
|
let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
|
||||||
let our_channel_monitor_claim_key_hash = <Hash160 as bitcoin::hashes::Hash>::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
|
let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
|
||||||
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
|
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ use bitcoin::hashes::{Hash, HashEngine};
|
||||||
use bitcoin::hashes::sha256::HashEngine as Sha256State;
|
use bitcoin::hashes::sha256::HashEngine as Sha256State;
|
||||||
use bitcoin::hashes::sha256::Hash as Sha256;
|
use bitcoin::hashes::sha256::Hash as Sha256;
|
||||||
use bitcoin::hashes::sha256d::Hash as Sha256dHash;
|
use bitcoin::hashes::sha256d::Hash as Sha256dHash;
|
||||||
use bitcoin::hashes::hash160::Hash as Hash160;
|
use bitcoin::hash_types::WPubkeyHash;
|
||||||
|
|
||||||
use bitcoin::secp256k1::key::{SecretKey, PublicKey};
|
use bitcoin::secp256k1::key::{SecretKey, PublicKey};
|
||||||
use bitcoin::secp256k1::{Secp256k1, Signature, Signing};
|
use bitcoin::secp256k1::{Secp256k1, Signature, Signing};
|
||||||
|
@ -513,9 +513,9 @@ impl KeysManager {
|
||||||
let node_secret = master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(0).unwrap()).expect("Your RNG is busted").private_key.key;
|
let node_secret = master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(0).unwrap()).expect("Your RNG is busted").private_key.key;
|
||||||
let destination_script = match master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(1).unwrap()) {
|
let destination_script = match master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(1).unwrap()) {
|
||||||
Ok(destination_key) => {
|
Ok(destination_key) => {
|
||||||
let pubkey_hash160 = Hash160::hash(&ExtendedPubKey::from_private(&secp_ctx, &destination_key).public_key.key.serialize()[..]);
|
let wpubkey_hash = WPubkeyHash::hash(&ExtendedPubKey::from_private(&secp_ctx, &destination_key).public_key.to_bytes());
|
||||||
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
|
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
|
||||||
.push_slice(&pubkey_hash160.into_inner())
|
.push_slice(&wpubkey_hash.into_inner())
|
||||||
.into_script()
|
.into_script()
|
||||||
},
|
},
|
||||||
Err(_) => panic!("Your RNG is busted"),
|
Err(_) => panic!("Your RNG is busted"),
|
||||||
|
|
|
@ -11,8 +11,7 @@ use bitcoin::util::bip143;
|
||||||
use bitcoin::hashes::{Hash, HashEngine};
|
use bitcoin::hashes::{Hash, HashEngine};
|
||||||
use bitcoin::hashes::sha256::Hash as Sha256;
|
use bitcoin::hashes::sha256::Hash as Sha256;
|
||||||
use bitcoin::hashes::ripemd160::Hash as Ripemd160;
|
use bitcoin::hashes::ripemd160::Hash as Ripemd160;
|
||||||
use bitcoin::hashes::hash160::Hash as Hash160;
|
use bitcoin::hash_types::{Txid, PubkeyHash};
|
||||||
use bitcoin::hash_types::Txid;
|
|
||||||
|
|
||||||
use ln::channelmanager::{PaymentHash, PaymentPreimage};
|
use ln::channelmanager::{PaymentHash, PaymentPreimage};
|
||||||
use ln::msgs::DecodeError;
|
use ln::msgs::DecodeError;
|
||||||
|
@ -364,7 +363,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
|
||||||
if htlc.offered {
|
if htlc.offered {
|
||||||
Builder::new().push_opcode(opcodes::all::OP_DUP)
|
Builder::new().push_opcode(opcodes::all::OP_DUP)
|
||||||
.push_opcode(opcodes::all::OP_HASH160)
|
.push_opcode(opcodes::all::OP_HASH160)
|
||||||
.push_slice(&Hash160::hash(&revocation_key.serialize())[..])
|
.push_slice(&PubkeyHash::hash(&revocation_key.serialize())[..])
|
||||||
.push_opcode(opcodes::all::OP_EQUAL)
|
.push_opcode(opcodes::all::OP_EQUAL)
|
||||||
.push_opcode(opcodes::all::OP_IF)
|
.push_opcode(opcodes::all::OP_IF)
|
||||||
.push_opcode(opcodes::all::OP_CHECKSIG)
|
.push_opcode(opcodes::all::OP_CHECKSIG)
|
||||||
|
@ -392,7 +391,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
|
||||||
} else {
|
} else {
|
||||||
Builder::new().push_opcode(opcodes::all::OP_DUP)
|
Builder::new().push_opcode(opcodes::all::OP_DUP)
|
||||||
.push_opcode(opcodes::all::OP_HASH160)
|
.push_opcode(opcodes::all::OP_HASH160)
|
||||||
.push_slice(&Hash160::hash(&revocation_key.serialize())[..])
|
.push_slice(&PubkeyHash::hash(&revocation_key.serialize())[..])
|
||||||
.push_opcode(opcodes::all::OP_EQUAL)
|
.push_opcode(opcodes::all::OP_EQUAL)
|
||||||
.push_opcode(opcodes::all::OP_IF)
|
.push_opcode(opcodes::all::OP_IF)
|
||||||
.push_opcode(opcodes::all::OP_CHECKSIG)
|
.push_opcode(opcodes::all::OP_CHECKSIG)
|
||||||
|
|
|
@ -8,8 +8,7 @@ use bitcoin::consensus::encode;
|
||||||
|
|
||||||
use bitcoin::hashes::{Hash, HashEngine};
|
use bitcoin::hashes::{Hash, HashEngine};
|
||||||
use bitcoin::hashes::sha256::Hash as Sha256;
|
use bitcoin::hashes::sha256::Hash as Sha256;
|
||||||
use bitcoin::hashes::hash160::Hash as Hash160;
|
use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
|
||||||
use bitcoin::hash_types::{Txid, BlockHash};
|
|
||||||
|
|
||||||
use bitcoin::secp256k1::key::{PublicKey,SecretKey};
|
use bitcoin::secp256k1::key::{PublicKey,SecretKey};
|
||||||
use bitcoin::secp256k1::{Secp256k1,Signature};
|
use bitcoin::secp256k1::{Secp256k1,Signature};
|
||||||
|
@ -983,7 +982,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
|
||||||
log_trace!(self, " ...including {} output with value {}", if local { "to_remote" } else { "to_local" }, value_to_b);
|
log_trace!(self, " ...including {} output with value {}", if local { "to_remote" } else { "to_local" }, value_to_b);
|
||||||
txouts.push((TxOut {
|
txouts.push((TxOut {
|
||||||
script_pubkey: Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
|
script_pubkey: Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
|
||||||
.push_slice(&Hash160::hash(&keys.b_payment_key.serialize())[..])
|
.push_slice(&WPubkeyHash::hash(&keys.b_payment_key.serialize())[..])
|
||||||
.into_script(),
|
.into_script(),
|
||||||
value: value_to_b as u64
|
value: value_to_b as u64
|
||||||
}, None));
|
}, None));
|
||||||
|
@ -1025,7 +1024,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_closing_scriptpubkey(&self) -> Script {
|
fn get_closing_scriptpubkey(&self) -> Script {
|
||||||
let our_channel_close_key_hash = Hash160::hash(&self.shutdown_pubkey.serialize());
|
let our_channel_close_key_hash = WPubkeyHash::hash(&self.shutdown_pubkey.serialize());
|
||||||
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script()
|
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4310,9 +4309,8 @@ mod tests {
|
||||||
use bitcoin::secp256k1::{Secp256k1, Message, Signature, All};
|
use bitcoin::secp256k1::{Secp256k1, Message, Signature, All};
|
||||||
use bitcoin::secp256k1::key::{SecretKey,PublicKey};
|
use bitcoin::secp256k1::key::{SecretKey,PublicKey};
|
||||||
use bitcoin::hashes::sha256::Hash as Sha256;
|
use bitcoin::hashes::sha256::Hash as Sha256;
|
||||||
use bitcoin::hashes::hash160::Hash as Hash160;
|
|
||||||
use bitcoin::hashes::Hash;
|
use bitcoin::hashes::Hash;
|
||||||
use bitcoin::hash_types::Txid;
|
use bitcoin::hash_types::{Txid, WPubkeyHash};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use rand::{thread_rng,Rng};
|
use rand::{thread_rng,Rng};
|
||||||
|
|
||||||
|
@ -4341,7 +4339,7 @@ mod tests {
|
||||||
fn get_destination_script(&self) -> Script {
|
fn get_destination_script(&self) -> Script {
|
||||||
let secp_ctx = Secp256k1::signing_only();
|
let secp_ctx = Secp256k1::signing_only();
|
||||||
let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
|
let channel_monitor_claim_key = SecretKey::from_slice(&hex::decode("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap();
|
||||||
let our_channel_monitor_claim_key_hash = Hash160::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
|
let our_channel_monitor_claim_key_hash = WPubkeyHash::hash(&PublicKey::from_secret_key(&secp_ctx, &channel_monitor_claim_key).serialize());
|
||||||
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
|
Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,7 @@ use bitcoin::util::hash::BitcoinHash;
|
||||||
|
|
||||||
use bitcoin::hashes::Hash;
|
use bitcoin::hashes::Hash;
|
||||||
use bitcoin::hashes::sha256::Hash as Sha256;
|
use bitcoin::hashes::sha256::Hash as Sha256;
|
||||||
use bitcoin::hashes::hash160::Hash as Hash160;
|
use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
|
||||||
use bitcoin::hash_types::{Txid, BlockHash};
|
|
||||||
|
|
||||||
use bitcoin::secp256k1::{Secp256k1,Signature};
|
use bitcoin::secp256k1::{Secp256k1,Signature};
|
||||||
use bitcoin::secp256k1::key::{SecretKey,PublicKey};
|
use bitcoin::secp256k1::key::{SecretKey,PublicKey};
|
||||||
|
@ -1061,7 +1060,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
|
||||||
logger: Arc<Logger>) -> ChannelMonitor<ChanSigner> {
|
logger: Arc<Logger>) -> ChannelMonitor<ChanSigner> {
|
||||||
|
|
||||||
assert!(commitment_transaction_number_obscure_factor <= (1 << 48));
|
assert!(commitment_transaction_number_obscure_factor <= (1 << 48));
|
||||||
let our_channel_close_key_hash = Hash160::hash(&shutdown_pubkey.serialize());
|
let our_channel_close_key_hash = WPubkeyHash::hash(&shutdown_pubkey.serialize());
|
||||||
let shutdown_script = Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script();
|
let shutdown_script = Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script();
|
||||||
|
|
||||||
let mut onchain_tx_handler = OnchainTxHandler::new(destination_script.clone(), keys.clone(), their_to_self_delay, logger.clone());
|
let mut onchain_tx_handler = OnchainTxHandler::new(destination_script.clone(), keys.clone(), their_to_self_delay, logger.clone());
|
||||||
|
@ -1231,7 +1230,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
|
||||||
pub(super) fn provide_rescue_remote_commitment_tx_info(&mut self, their_revocation_point: PublicKey) {
|
pub(super) fn provide_rescue_remote_commitment_tx_info(&mut self, their_revocation_point: PublicKey) {
|
||||||
if let Ok(payment_key) = chan_utils::derive_public_key(&self.secp_ctx, &their_revocation_point, &self.keys.pubkeys().payment_basepoint) {
|
if let Ok(payment_key) = chan_utils::derive_public_key(&self.secp_ctx, &their_revocation_point, &self.keys.pubkeys().payment_basepoint) {
|
||||||
let to_remote_script = Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
|
let to_remote_script = Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0)
|
||||||
.push_slice(&Hash160::hash(&payment_key.serialize())[..])
|
.push_slice(&WPubkeyHash::hash(&payment_key.serialize())[..])
|
||||||
.into_script();
|
.into_script();
|
||||||
if let Ok(to_remote_key) = chan_utils::derive_private_key(&self.secp_ctx, &their_revocation_point, &self.keys.payment_base_key()) {
|
if let Ok(to_remote_key) = chan_utils::derive_private_key(&self.secp_ctx, &their_revocation_point, &self.keys.payment_base_key()) {
|
||||||
self.broadcasted_remote_payment_script = Some((to_remote_script, to_remote_key));
|
self.broadcasted_remote_payment_script = Some((to_remote_script, to_remote_key));
|
||||||
|
@ -1460,7 +1459,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
|
||||||
self.broadcasted_remote_payment_script = {
|
self.broadcasted_remote_payment_script = {
|
||||||
// Note that the Network here is ignored as we immediately drop the address for the
|
// Note that the Network here is ignored as we immediately drop the address for the
|
||||||
// script_pubkey version
|
// script_pubkey version
|
||||||
let payment_hash160 = Hash160::hash(&PublicKey::from_secret_key(&self.secp_ctx, &local_payment_key).serialize());
|
let payment_hash160 = WPubkeyHash::hash(&PublicKey::from_secret_key(&self.secp_ctx, &local_payment_key).serialize());
|
||||||
Some((Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&payment_hash160[..]).into_script(), local_payment_key))
|
Some((Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&payment_hash160[..]).into_script(), local_payment_key))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1609,7 +1608,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
|
||||||
self.broadcasted_remote_payment_script = {
|
self.broadcasted_remote_payment_script = {
|
||||||
// Note that the Network here is ignored as we immediately drop the address for the
|
// Note that the Network here is ignored as we immediately drop the address for the
|
||||||
// script_pubkey version
|
// script_pubkey version
|
||||||
let payment_hash160 = Hash160::hash(&PublicKey::from_secret_key(&self.secp_ctx, &local_payment_key).serialize());
|
let payment_hash160 = WPubkeyHash::hash(&PublicKey::from_secret_key(&self.secp_ctx, &local_payment_key).serialize());
|
||||||
Some((Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&payment_hash160[..]).into_script(), local_payment_key))
|
Some((Builder::new().push_opcode(opcodes::all::OP_PUSHBYTES_0).push_slice(&payment_hash160[..]).into_script(), local_payment_key))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue