@@ -16,6 +16,7 @@ use bitcoin::blockdata::locktime::absolute::LockTime;
1616use bitcoin:: blockdata:: transaction:: { Transaction , TxOut , TxIn } ;
1717use bitcoin:: blockdata:: script:: { Script , ScriptBuf , Builder } ;
1818use bitcoin:: blockdata:: opcodes;
19+ use bitcoin:: ecdsa:: Signature as EcdsaSignature ;
1920use bitcoin:: network:: constants:: Network ;
2021use bitcoin:: psbt:: PartiallySignedTransaction ;
2122use bitcoin:: bip32:: { ExtendedPrivKey , ExtendedPubKey , ChildNumber } ;
@@ -1109,7 +1110,7 @@ impl InMemorySigner {
11091110 /// or if an output descriptor `script_pubkey` does not match the one we can spend.
11101111 ///
11111112 /// [`descriptor.outpoint`]: StaticPaymentOutputDescriptor::outpoint
1112- pub fn sign_counterparty_payment_input < C : Signing > ( & self , spend_tx : & Transaction , input_idx : usize , descriptor : & StaticPaymentOutputDescriptor , secp_ctx : & Secp256k1 < C > ) -> Result < Vec < Vec < u8 > > , ( ) > {
1113+ pub fn sign_counterparty_payment_input < C : Signing > ( & self , spend_tx : & Transaction , input_idx : usize , descriptor : & StaticPaymentOutputDescriptor , secp_ctx : & Secp256k1 < C > ) -> Result < Witness , ( ) > {
11131114 // TODO: We really should be taking the SigHashCache as a parameter here instead of
11141115 // spend_tx, but ideally the SigHashCache would expose the transaction's inputs read-only
11151116 // so that we can check them. This requires upstream rust-bitcoin changes (as well as
@@ -1148,7 +1149,7 @@ impl InMemorySigner {
11481149 } else {
11491150 witness. push ( remotepubkey. to_bytes ( ) ) ;
11501151 }
1151- Ok ( witness)
1152+ Ok ( witness. into ( ) )
11521153 }
11531154
11541155 /// Sign the single input of `spend_tx` at index `input_idx` which spends the output
@@ -1161,7 +1162,7 @@ impl InMemorySigner {
11611162 ///
11621163 /// [`descriptor.outpoint`]: DelayedPaymentOutputDescriptor::outpoint
11631164 /// [`descriptor.to_self_delay`]: DelayedPaymentOutputDescriptor::to_self_delay
1164- pub fn sign_dynamic_p2wsh_input < C : Signing > ( & self , spend_tx : & Transaction , input_idx : usize , descriptor : & DelayedPaymentOutputDescriptor , secp_ctx : & Secp256k1 < C > ) -> Result < Vec < Vec < u8 > > , ( ) > {
1165+ pub fn sign_dynamic_p2wsh_input < C : Signing > ( & self , spend_tx : & Transaction , input_idx : usize , descriptor : & DelayedPaymentOutputDescriptor , secp_ctx : & Secp256k1 < C > ) -> Result < Witness , ( ) > {
11651166 // TODO: We really should be taking the SigHashCache as a parameter here instead of
11661167 // spend_tx, but ideally the SigHashCache would expose the transaction's inputs read-only
11671168 // so that we can check them. This requires upstream rust-bitcoin changes (as well as
@@ -1175,17 +1176,19 @@ impl InMemorySigner {
11751176 let delayed_payment_pubkey = PublicKey :: from_secret_key ( & secp_ctx, & delayed_payment_key) ;
11761177 let witness_script = chan_utils:: get_revokeable_redeemscript ( & descriptor. revocation_pubkey , descriptor. to_self_delay , & delayed_payment_pubkey) ;
11771178 let sighash = hash_to_message ! ( & sighash:: SighashCache :: new( spend_tx) . segwit_signature_hash( input_idx, & witness_script, descriptor. output. value, EcdsaSighashType :: All ) . unwrap( ) [ ..] ) ;
1178- let local_delayedsig = sign_with_aux_rand ( secp_ctx, & sighash, & delayed_payment_key, & self ) ;
1179+ let local_delayedsig = EcdsaSignature {
1180+ sig : sign_with_aux_rand ( secp_ctx, & sighash, & delayed_payment_key, & self ) ,
1181+ hash_ty : EcdsaSighashType :: All ,
1182+ } ;
11791183 let payment_script = bitcoin:: Address :: p2wsh ( & witness_script, Network :: Bitcoin ) . script_pubkey ( ) ;
11801184
11811185 if descriptor. output . script_pubkey != payment_script { return Err ( ( ) ) ; }
11821186
1183- let mut witness = Vec :: with_capacity ( 3 ) ;
1184- witness. push ( local_delayedsig. serialize_der ( ) . to_vec ( ) ) ;
1185- witness[ 0 ] . push ( EcdsaSighashType :: All as u8 ) ;
1186- witness. push ( vec ! ( ) ) ; //MINIMALIF
1187- witness. push ( witness_script. clone ( ) . into_bytes ( ) ) ;
1188- Ok ( witness)
1187+ Ok ( Witness :: from_slice ( & [
1188+ & local_delayedsig. serialize ( ) [ ..] ,
1189+ & [ ] , // MINIMALIF
1190+ witness_script. as_bytes ( ) ,
1191+ ] ) )
11891192 }
11901193}
11911194
@@ -1614,7 +1617,7 @@ impl KeysManager {
16141617 }
16151618 keys_cache = Some ( ( signer, descriptor. channel_keys_id ) ) ;
16161619 }
1617- let witness = Witness :: from_vec ( keys_cache. as_ref ( ) . unwrap ( ) . 0 . sign_counterparty_payment_input ( & psbt. unsigned_tx , input_idx, & descriptor, & secp_ctx) ?) ;
1620+ let witness = keys_cache. as_ref ( ) . unwrap ( ) . 0 . sign_counterparty_payment_input ( & psbt. unsigned_tx , input_idx, & descriptor, & secp_ctx) ?;
16181621 psbt. inputs [ input_idx] . final_script_witness = Some ( witness) ;
16191622 } ,
16201623 SpendableOutputDescriptor :: DelayedPaymentOutput ( descriptor) => {
@@ -1624,7 +1627,7 @@ impl KeysManager {
16241627 self . derive_channel_keys ( descriptor. channel_value_satoshis , & descriptor. channel_keys_id ) ,
16251628 descriptor. channel_keys_id ) ) ;
16261629 }
1627- let witness = Witness :: from_vec ( keys_cache. as_ref ( ) . unwrap ( ) . 0 . sign_dynamic_p2wsh_input ( & psbt. unsigned_tx , input_idx, & descriptor, & secp_ctx) ?) ;
1630+ let witness = keys_cache. as_ref ( ) . unwrap ( ) . 0 . sign_dynamic_p2wsh_input ( & psbt. unsigned_tx , input_idx, & descriptor, & secp_ctx) ?;
16281631 psbt. inputs [ input_idx] . final_script_witness = Some ( witness) ;
16291632 } ,
16301633 SpendableOutputDescriptor :: StaticOutput { ref outpoint, ref output } => {
@@ -1659,7 +1662,7 @@ impl KeysManager {
16591662 let sig = sign_with_aux_rand ( secp_ctx, & sighash, & secret. private_key , & self ) ;
16601663 let mut sig_ser = sig. serialize_der ( ) . to_vec ( ) ;
16611664 sig_ser. push ( EcdsaSighashType :: All as u8 ) ;
1662- let witness = Witness :: from_vec ( vec ! [ sig_ser, pubkey. inner. serialize( ) . to_vec( ) ] ) ;
1665+ let witness = Witness :: from_slice ( & [ & sig_ser, & pubkey. inner . serialize ( ) . to_vec ( ) ] ) ;
16631666 psbt. inputs [ input_idx] . final_script_witness = Some ( witness) ;
16641667 } ,
16651668 }
0 commit comments