Pin compiler_builtins to 0.1.109 when building std
[ldk-c-bindings] / lightning-c-bindings / src / lightning / sign / ecdsa.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
8
9 //! Defines ECDSA-specific signer types.
10
11 use alloc::str::FromStr;
12 use alloc::string::String;
13 use core::ffi::c_void;
14 use core::convert::Infallible;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17 #[cfg(feature="no-std")]
18 use alloc::{vec::Vec, boxed::Box};
19
20 /// A trait to sign Lightning channel transactions as described in
21 /// [BOLT 3](https://github.com/lightning/bolts/blob/master/03-transactions.md).
22 ///
23 /// Signing services could be implemented on a hardware wallet and should implement signing
24 /// policies in order to be secure. Please refer to the [VLS Policy
25 /// Controls](https://gitlab.com/lightning-signer/validating-lightning-signer/-/blob/main/docs/policy-controls.md)
26 /// for an example of such policies.
27 #[repr(C)]
28 pub struct EcdsaChannelSigner {
29         /// An opaque pointer which is passed to your function implementations as an argument.
30         /// This has no meaning in the LDK, and can be NULL or any other value.
31         pub this_arg: *mut c_void,
32         /// Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
33         ///
34         /// Note that if signing fails or is rejected, the channel will be force-closed.
35         ///
36         /// Policy checks should be implemented in this function, including checking the amount
37         /// sent to us and checking the HTLCs.
38         ///
39         /// The preimages of outbound and inbound HTLCs that were fulfilled since the last commitment
40         /// are provided. A validating signer should ensure that an outbound HTLC output is removed
41         /// only when the matching preimage is provided and after the corresponding inbound HTLC has
42         /// been removed for forwarded payments.
43         ///
44         /// Note that all the relevant preimages will be provided, but there may also be additional
45         /// irrelevant or duplicate preimages.
46         pub sign_counterparty_commitment: extern "C" fn (this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::CommitmentTransaction, inbound_htlc_preimages: crate::c_types::derived::CVec_ThirtyTwoBytesZ, outbound_htlc_preimages: crate::c_types::derived::CVec_ThirtyTwoBytesZ) -> crate::c_types::derived::CResult_C2Tuple_ECDSASignatureCVec_ECDSASignatureZZNoneZ,
47         /// Creates a signature for a holder's commitment transaction.
48         ///
49         /// This will be called
50         /// - with a non-revoked `commitment_tx`.
51         /// - with the latest `commitment_tx` when we initiate a force-close.
52         ///
53         /// This may be called multiple times for the same transaction.
54         ///
55         /// An external signer implementation should check that the commitment has not been revoked.
56         ///
57         /// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
58         /// signature and should be retried later. Once the signer is ready to provide a signature after
59         /// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
60         /// monitor.
61         ///
62         /// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
63         pub sign_holder_commitment: extern "C" fn (this_arg: *const c_void, commitment_tx: &crate::lightning::ln::chan_utils::HolderCommitmentTransaction) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
64         /// Create a signature for the given input in a transaction spending an HTLC transaction output
65         /// or a commitment transaction `to_local` output when our counterparty broadcasts an old state.
66         ///
67         /// A justice transaction may claim multiple outputs at the same time if timelocks are
68         /// similar, but only a signature for the input at index `input` should be signed for here.
69         /// It may be called multiple times for same output(s) if a fee-bump is needed with regards
70         /// to an upcoming timelock expiration.
71         ///
72         /// Amount is value of the output spent by this input, committed to in the BIP 143 signature.
73         ///
74         /// `per_commitment_key` is revocation secret which was provided by our counterparty when they
75         /// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
76         /// not allow the spending of any funds by itself (you need our holder `revocation_secret` to do
77         /// so).
78         ///
79         /// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
80         /// signature and should be retried later. Once the signer is ready to provide a signature after
81         /// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
82         /// monitor.
83         ///
84         /// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
85         pub sign_justice_revoked_output: extern "C" fn (this_arg: *const c_void, justice_tx: crate::c_types::Transaction, input: usize, amount: u64, per_commitment_key: *const [u8; 32]) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
86         /// Create a signature for the given input in a transaction spending a commitment transaction
87         /// HTLC output when our counterparty broadcasts an old state.
88         ///
89         /// A justice transaction may claim multiple outputs at the same time if timelocks are
90         /// similar, but only a signature for the input at index `input` should be signed for here.
91         /// It may be called multiple times for same output(s) if a fee-bump is needed with regards
92         /// to an upcoming timelock expiration.
93         ///
94         /// `amount` is the value of the output spent by this input, committed to in the BIP 143
95         /// signature.
96         ///
97         /// `per_commitment_key` is revocation secret which was provided by our counterparty when they
98         /// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
99         /// not allow the spending of any funds by itself (you need our holder revocation_secret to do
100         /// so).
101         ///
102         /// `htlc` holds HTLC elements (hash, timelock), thus changing the format of the witness script
103         /// (which is committed to in the BIP 143 signatures).
104         ///
105         /// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
106         /// signature and should be retried later. Once the signer is ready to provide a signature after
107         /// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
108         /// monitor.
109         ///
110         /// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
111         pub sign_justice_revoked_htlc: extern "C" fn (this_arg: *const c_void, justice_tx: crate::c_types::Transaction, input: usize, amount: u64, per_commitment_key: *const [u8; 32], htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
112         /// Computes the signature for a commitment transaction's HTLC output used as an input within
113         /// `htlc_tx`, which spends the commitment transaction at index `input`. The signature returned
114         /// must be be computed using [`EcdsaSighashType::All`].
115         ///
116         /// Note that this may be called for HTLCs in the penultimate commitment transaction if a
117         /// [`ChannelMonitor`] [replica](https://github.com/lightningdevkit/rust-lightning/blob/main/GLOSSARY.md#monitor-replicas)
118         /// broadcasts it before receiving the update for the latest commitment transaction.
119         ///
120         /// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
121         /// signature and should be retried later. Once the signer is ready to provide a signature after
122         /// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
123         /// monitor.
124         ///
125         /// [`EcdsaSighashType::All`]: bitcoin::sighash::EcdsaSighashType::All
126         /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
127         /// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
128         pub sign_holder_htlc_transaction: extern "C" fn (this_arg: *const c_void, htlc_tx: crate::c_types::Transaction, input: usize, htlc_descriptor: &crate::lightning::sign::HTLCDescriptor) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
129         /// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
130         /// transaction, either offered or received.
131         ///
132         /// Such a transaction may claim multiples offered outputs at same time if we know the
133         /// preimage for each when we create it, but only the input at index `input` should be
134         /// signed for here. It may be called multiple times for same output(s) if a fee-bump is
135         /// needed with regards to an upcoming timelock expiration.
136         ///
137         /// `witness_script` is either an offered or received script as defined in BOLT3 for HTLC
138         /// outputs.
139         ///
140         /// `amount` is value of the output spent by this input, committed to in the BIP 143 signature.
141         ///
142         /// `per_commitment_point` is the dynamic point corresponding to the channel state
143         /// detected onchain. It has been generated by our counterparty and is used to derive
144         /// channel state keys, which are then included in the witness script and committed to in the
145         /// BIP 143 signature.
146         ///
147         /// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
148         /// signature and should be retried later. Once the signer is ready to provide a signature after
149         /// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
150         /// monitor.
151         ///
152         /// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
153         pub sign_counterparty_htlc_transaction: extern "C" fn (this_arg: *const c_void, htlc_tx: crate::c_types::Transaction, input: usize, amount: u64, per_commitment_point: crate::c_types::PublicKey, htlc: &crate::lightning::ln::chan_utils::HTLCOutputInCommitment) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
154         /// Create a signature for a (proposed) closing transaction.
155         ///
156         /// Note that, due to rounding, there may be one \"missing\" satoshi, and either party may have
157         /// chosen to forgo their output as dust.
158         pub sign_closing_transaction: extern "C" fn (this_arg: *const c_void, closing_tx: &crate::lightning::ln::chan_utils::ClosingTransaction) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
159         /// Computes the signature for a commitment transaction's anchor output used as an
160         /// input within `anchor_tx`, which spends the commitment transaction, at index `input`.
161         ///
162         /// An `Err` can be returned to signal that the signer is unavailable/cannot produce a valid
163         /// signature and should be retried later. Once the signer is ready to provide a signature after
164         /// previously returning an `Err`, [`ChannelMonitor::signer_unblocked`] must be called on its
165         /// monitor.
166         ///
167         /// [`ChannelMonitor::signer_unblocked`]: crate::chain::channelmonitor::ChannelMonitor::signer_unblocked
168         pub sign_holder_anchor_input: extern "C" fn (this_arg: *const c_void, anchor_tx: crate::c_types::Transaction, input: usize) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
169         /// Signs a channel announcement message with our funding key proving it comes from one of the
170         /// channel participants.
171         ///
172         /// Channel announcements also require a signature from each node's network key. Our node
173         /// signature is computed through [`NodeSigner::sign_gossip_message`].
174         ///
175         /// Note that if this fails or is rejected, the channel will not be publicly announced and
176         /// our counterparty may (though likely will not) close the channel on us for violating the
177         /// protocol.
178         ///
179         /// [`NodeSigner::sign_gossip_message`]: crate::sign::NodeSigner::sign_gossip_message
180         pub sign_channel_announcement_with_funding_key: extern "C" fn (this_arg: *const c_void, msg: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CResult_ECDSASignatureNoneZ,
181         /// Implementation of ChannelSigner for this object.
182         pub ChannelSigner: crate::lightning::sign::ChannelSigner,
183         /// Frees any resources associated with this object given its this_arg pointer.
184         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
185         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
186 }
187 unsafe impl Send for EcdsaChannelSigner {}
188 unsafe impl Sync for EcdsaChannelSigner {}
189 #[allow(unused)]
190 pub(crate) fn EcdsaChannelSigner_clone_fields(orig: &EcdsaChannelSigner) -> EcdsaChannelSigner {
191         EcdsaChannelSigner {
192                 this_arg: orig.this_arg,
193                 sign_counterparty_commitment: Clone::clone(&orig.sign_counterparty_commitment),
194                 sign_holder_commitment: Clone::clone(&orig.sign_holder_commitment),
195                 sign_justice_revoked_output: Clone::clone(&orig.sign_justice_revoked_output),
196                 sign_justice_revoked_htlc: Clone::clone(&orig.sign_justice_revoked_htlc),
197                 sign_holder_htlc_transaction: Clone::clone(&orig.sign_holder_htlc_transaction),
198                 sign_counterparty_htlc_transaction: Clone::clone(&orig.sign_counterparty_htlc_transaction),
199                 sign_closing_transaction: Clone::clone(&orig.sign_closing_transaction),
200                 sign_holder_anchor_input: Clone::clone(&orig.sign_holder_anchor_input),
201                 sign_channel_announcement_with_funding_key: Clone::clone(&orig.sign_channel_announcement_with_funding_key),
202                 ChannelSigner: crate::lightning::sign::ChannelSigner_clone_fields(&orig.ChannelSigner),
203                 free: Clone::clone(&orig.free),
204         }
205 }
206 impl lightning::sign::ChannelSigner for EcdsaChannelSigner {
207         fn get_per_commitment_point(&self, mut idx: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> bitcoin::secp256k1::PublicKey {
208                 let mut ret = (self.ChannelSigner.get_per_commitment_point)(self.ChannelSigner.this_arg, idx);
209                 ret.into_rust()
210         }
211         fn release_commitment_secret(&self, mut idx: u64) -> [u8; 32] {
212                 let mut ret = (self.ChannelSigner.release_commitment_secret)(self.ChannelSigner.this_arg, idx);
213                 ret.data
214         }
215         fn validate_holder_commitment(&self, mut holder_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut outbound_htlc_preimages: Vec<lightning::ln::types::PaymentPreimage>) -> Result<(), ()> {
216                 let mut local_outbound_htlc_preimages = Vec::new(); for mut item in outbound_htlc_preimages.drain(..) { local_outbound_htlc_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
217                 let mut ret = (self.ChannelSigner.validate_holder_commitment)(self.ChannelSigner.this_arg, &crate::lightning::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((holder_tx as *const lightning::ln::chan_utils::HolderCommitmentTransaction<>) as *mut _) }, is_owned: false }, local_outbound_htlc_preimages.into());
218                 let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
219                 local_ret
220         }
221         fn validate_counterparty_revocation(&self, mut idx: u64, mut secret: &bitcoin::secp256k1::SecretKey) -> Result<(), ()> {
222                 let mut ret = (self.ChannelSigner.validate_counterparty_revocation)(self.ChannelSigner.this_arg, idx, secret.as_ref());
223                 let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
224                 local_ret
225         }
226         fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
227                 if let Some(f) = self.ChannelSigner.set_pubkeys {
228                         (f)(&self.ChannelSigner);
229                 }
230                 unsafe { &*self.ChannelSigner.pubkeys.get() }.get_native_ref()
231         }
232         fn channel_keys_id(&self) -> [u8; 32] {
233                 let mut ret = (self.ChannelSigner.channel_keys_id)(self.ChannelSigner.this_arg);
234                 ret.data
235         }
236         fn provide_channel_parameters(&mut self, mut channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
237                 (self.ChannelSigner.provide_channel_parameters)(self.ChannelSigner.this_arg, &crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((channel_parameters as *const lightning::ln::chan_utils::ChannelTransactionParameters<>) as *mut _) }, is_owned: false })
238         }
239 }
240
241 use lightning::sign::ecdsa::EcdsaChannelSigner as rustEcdsaChannelSigner;
242 impl rustEcdsaChannelSigner for EcdsaChannelSigner {
243         fn sign_counterparty_commitment(&self, mut commitment_tx: &lightning::ln::chan_utils::CommitmentTransaction, mut inbound_htlc_preimages: Vec<lightning::ln::types::PaymentPreimage>, mut outbound_htlc_preimages: Vec<lightning::ln::types::PaymentPreimage>, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<(bitcoin::secp256k1::ecdsa::Signature, Vec<bitcoin::secp256k1::ecdsa::Signature>), ()> {
244                 let mut local_inbound_htlc_preimages = Vec::new(); for mut item in inbound_htlc_preimages.drain(..) { local_inbound_htlc_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
245                 let mut local_outbound_htlc_preimages = Vec::new(); for mut item in outbound_htlc_preimages.drain(..) { local_outbound_htlc_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
246                 let mut ret = (self.sign_counterparty_commitment)(self.this_arg, &crate::lightning::ln::chan_utils::CommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((commitment_tx as *const lightning::ln::chan_utils::CommitmentTransaction<>) as *mut _) }, is_owned: false }, local_inbound_htlc_preimages.into(), local_outbound_htlc_preimages.into());
247                 let mut local_ret = match ret.result_ok { true => Ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).to_rust(); let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.into_rust().drain(..) { local_orig_ret_0_1.push( { item.into_rust() }); }; let mut local_ret_0 = (orig_ret_0_0.into_rust(), local_orig_ret_0_1); local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
248                 local_ret
249         }
250         fn sign_holder_commitment(&self, mut commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
251                 let mut ret = (self.sign_holder_commitment)(self.this_arg, &crate::lightning::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((commitment_tx as *const lightning::ln::chan_utils::HolderCommitmentTransaction<>) as *mut _) }, is_owned: false });
252                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
253                 local_ret
254         }
255         fn sign_justice_revoked_output(&self, mut justice_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut amount: u64, mut per_commitment_key: &bitcoin::secp256k1::SecretKey, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
256                 let mut ret = (self.sign_justice_revoked_output)(self.this_arg, crate::c_types::Transaction::from_bitcoin(justice_tx), input, amount, per_commitment_key.as_ref());
257                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
258                 local_ret
259         }
260         fn sign_justice_revoked_htlc(&self, mut justice_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut amount: u64, mut per_commitment_key: &bitcoin::secp256k1::SecretKey, mut htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
261                 let mut ret = (self.sign_justice_revoked_htlc)(self.this_arg, crate::c_types::Transaction::from_bitcoin(justice_tx), input, amount, per_commitment_key.as_ref(), &crate::lightning::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { ObjOps::nonnull_ptr_to_inner((htlc as *const lightning::ln::chan_utils::HTLCOutputInCommitment<>) as *mut _) }, is_owned: false });
262                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
263                 local_ret
264         }
265         fn sign_holder_htlc_transaction(&self, mut htlc_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut htlc_descriptor: &lightning::sign::HTLCDescriptor, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
266                 let mut ret = (self.sign_holder_htlc_transaction)(self.this_arg, crate::c_types::Transaction::from_bitcoin(htlc_tx), input, &crate::lightning::sign::HTLCDescriptor { inner: unsafe { ObjOps::nonnull_ptr_to_inner((htlc_descriptor as *const lightning::sign::HTLCDescriptor<>) as *mut _) }, is_owned: false });
267                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
268                 local_ret
269         }
270         fn sign_counterparty_htlc_transaction(&self, mut htlc_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut amount: u64, mut per_commitment_point: &bitcoin::secp256k1::PublicKey, mut htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
271                 let mut ret = (self.sign_counterparty_htlc_transaction)(self.this_arg, crate::c_types::Transaction::from_bitcoin(htlc_tx), input, amount, crate::c_types::PublicKey::from_rust(&per_commitment_point), &crate::lightning::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { ObjOps::nonnull_ptr_to_inner((htlc as *const lightning::ln::chan_utils::HTLCOutputInCommitment<>) as *mut _) }, is_owned: false });
272                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
273                 local_ret
274         }
275         fn sign_closing_transaction(&self, mut closing_tx: &lightning::ln::chan_utils::ClosingTransaction, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
276                 let mut ret = (self.sign_closing_transaction)(self.this_arg, &crate::lightning::ln::chan_utils::ClosingTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((closing_tx as *const lightning::ln::chan_utils::ClosingTransaction<>) as *mut _) }, is_owned: false });
277                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
278                 local_ret
279         }
280         fn sign_holder_anchor_input(&self, mut anchor_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
281                 let mut ret = (self.sign_holder_anchor_input)(self.this_arg, crate::c_types::Transaction::from_bitcoin(anchor_tx), input);
282                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
283                 local_ret
284         }
285         fn sign_channel_announcement_with_funding_key(&self, mut msg: &lightning::ln::msgs::UnsignedChannelAnnouncement, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
286                 let mut ret = (self.sign_channel_announcement_with_funding_key)(self.this_arg, &crate::lightning::ln::msgs::UnsignedChannelAnnouncement { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::UnsignedChannelAnnouncement<>) as *mut _) }, is_owned: false });
287                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
288                 local_ret
289         }
290 }
291
292 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
293 // directly as a Deref trait in higher-level structs:
294 impl core::ops::Deref for EcdsaChannelSigner {
295         type Target = Self;
296         fn deref(&self) -> &Self {
297                 self
298         }
299 }
300 impl core::ops::DerefMut for EcdsaChannelSigner {
301         fn deref_mut(&mut self) -> &mut Self {
302                 self
303         }
304 }
305 /// Calls the free function if one is set
306 #[no_mangle]
307 pub extern "C" fn EcdsaChannelSigner_free(this_ptr: EcdsaChannelSigner) { }
308 impl Drop for EcdsaChannelSigner {
309         fn drop(&mut self) {
310                 if let Some(f) = self.free {
311                         f(self.this_arg);
312                 }
313         }
314 }
315 /// A writeable signer.
316 ///
317 /// There will always be two instances of a signer per channel, one occupied by the
318 /// [`ChannelManager`] and another by the channel's [`ChannelMonitor`].
319 ///
320 /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
321 /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
322 #[repr(C)]
323 pub struct WriteableEcdsaChannelSigner {
324         /// An opaque pointer which is passed to your function implementations as an argument.
325         /// This has no meaning in the LDK, and can be NULL or any other value.
326         pub this_arg: *mut c_void,
327         /// Implementation of EcdsaChannelSigner for this object.
328         pub EcdsaChannelSigner: crate::lightning::sign::ecdsa::EcdsaChannelSigner,
329         /// Serialize the object into a byte array
330         pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
331         /// Called, if set, after this WriteableEcdsaChannelSigner has been cloned into a duplicate object.
332         /// The new WriteableEcdsaChannelSigner is provided, and should be mutated as needed to perform a
333         /// deep copy of the object pointed to by this_arg or avoid any double-freeing.
334         pub cloned: Option<extern "C" fn (new_WriteableEcdsaChannelSigner: &mut WriteableEcdsaChannelSigner)>,
335         /// Frees any resources associated with this object given its this_arg pointer.
336         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
337         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
338 }
339 unsafe impl Send for WriteableEcdsaChannelSigner {}
340 unsafe impl Sync for WriteableEcdsaChannelSigner {}
341 #[allow(unused)]
342 pub(crate) fn WriteableEcdsaChannelSigner_clone_fields(orig: &WriteableEcdsaChannelSigner) -> WriteableEcdsaChannelSigner {
343         WriteableEcdsaChannelSigner {
344                 this_arg: orig.this_arg,
345                 EcdsaChannelSigner: crate::lightning::sign::ecdsa::EcdsaChannelSigner_clone_fields(&orig.EcdsaChannelSigner),
346                 write: Clone::clone(&orig.write),
347                 cloned: Clone::clone(&orig.cloned),
348                 free: Clone::clone(&orig.free),
349         }
350 }
351 impl lightning::sign::ecdsa::EcdsaChannelSigner for WriteableEcdsaChannelSigner {
352         fn sign_counterparty_commitment(&self, mut commitment_tx: &lightning::ln::chan_utils::CommitmentTransaction, mut inbound_htlc_preimages: Vec<lightning::ln::types::PaymentPreimage>, mut outbound_htlc_preimages: Vec<lightning::ln::types::PaymentPreimage>, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<(bitcoin::secp256k1::ecdsa::Signature, Vec<bitcoin::secp256k1::ecdsa::Signature>), ()> {
353                 let mut local_inbound_htlc_preimages = Vec::new(); for mut item in inbound_htlc_preimages.drain(..) { local_inbound_htlc_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
354                 let mut local_outbound_htlc_preimages = Vec::new(); for mut item in outbound_htlc_preimages.drain(..) { local_outbound_htlc_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
355                 let mut ret = (self.EcdsaChannelSigner.sign_counterparty_commitment)(self.EcdsaChannelSigner.this_arg, &crate::lightning::ln::chan_utils::CommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((commitment_tx as *const lightning::ln::chan_utils::CommitmentTransaction<>) as *mut _) }, is_owned: false }, local_inbound_htlc_preimages.into(), local_outbound_htlc_preimages.into());
356                 let mut local_ret = match ret.result_ok { true => Ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).to_rust(); let mut local_orig_ret_0_1 = Vec::new(); for mut item in orig_ret_0_1.into_rust().drain(..) { local_orig_ret_0_1.push( { item.into_rust() }); }; let mut local_ret_0 = (orig_ret_0_0.into_rust(), local_orig_ret_0_1); local_ret_0 }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
357                 local_ret
358         }
359         fn sign_holder_commitment(&self, mut commitment_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
360                 let mut ret = (self.EcdsaChannelSigner.sign_holder_commitment)(self.EcdsaChannelSigner.this_arg, &crate::lightning::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((commitment_tx as *const lightning::ln::chan_utils::HolderCommitmentTransaction<>) as *mut _) }, is_owned: false });
361                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
362                 local_ret
363         }
364         fn sign_justice_revoked_output(&self, mut justice_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut amount: u64, mut per_commitment_key: &bitcoin::secp256k1::SecretKey, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
365                 let mut ret = (self.EcdsaChannelSigner.sign_justice_revoked_output)(self.EcdsaChannelSigner.this_arg, crate::c_types::Transaction::from_bitcoin(justice_tx), input, amount, per_commitment_key.as_ref());
366                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
367                 local_ret
368         }
369         fn sign_justice_revoked_htlc(&self, mut justice_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut amount: u64, mut per_commitment_key: &bitcoin::secp256k1::SecretKey, mut htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
370                 let mut ret = (self.EcdsaChannelSigner.sign_justice_revoked_htlc)(self.EcdsaChannelSigner.this_arg, crate::c_types::Transaction::from_bitcoin(justice_tx), input, amount, per_commitment_key.as_ref(), &crate::lightning::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { ObjOps::nonnull_ptr_to_inner((htlc as *const lightning::ln::chan_utils::HTLCOutputInCommitment<>) as *mut _) }, is_owned: false });
371                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
372                 local_ret
373         }
374         fn sign_holder_htlc_transaction(&self, mut htlc_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut htlc_descriptor: &lightning::sign::HTLCDescriptor, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
375                 let mut ret = (self.EcdsaChannelSigner.sign_holder_htlc_transaction)(self.EcdsaChannelSigner.this_arg, crate::c_types::Transaction::from_bitcoin(htlc_tx), input, &crate::lightning::sign::HTLCDescriptor { inner: unsafe { ObjOps::nonnull_ptr_to_inner((htlc_descriptor as *const lightning::sign::HTLCDescriptor<>) as *mut _) }, is_owned: false });
376                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
377                 local_ret
378         }
379         fn sign_counterparty_htlc_transaction(&self, mut htlc_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut amount: u64, mut per_commitment_point: &bitcoin::secp256k1::PublicKey, mut htlc: &lightning::ln::chan_utils::HTLCOutputInCommitment, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
380                 let mut ret = (self.EcdsaChannelSigner.sign_counterparty_htlc_transaction)(self.EcdsaChannelSigner.this_arg, crate::c_types::Transaction::from_bitcoin(htlc_tx), input, amount, crate::c_types::PublicKey::from_rust(&per_commitment_point), &crate::lightning::ln::chan_utils::HTLCOutputInCommitment { inner: unsafe { ObjOps::nonnull_ptr_to_inner((htlc as *const lightning::ln::chan_utils::HTLCOutputInCommitment<>) as *mut _) }, is_owned: false });
381                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
382                 local_ret
383         }
384         fn sign_closing_transaction(&self, mut closing_tx: &lightning::ln::chan_utils::ClosingTransaction, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
385                 let mut ret = (self.EcdsaChannelSigner.sign_closing_transaction)(self.EcdsaChannelSigner.this_arg, &crate::lightning::ln::chan_utils::ClosingTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((closing_tx as *const lightning::ln::chan_utils::ClosingTransaction<>) as *mut _) }, is_owned: false });
386                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
387                 local_ret
388         }
389         fn sign_holder_anchor_input(&self, mut anchor_tx: &bitcoin::blockdata::transaction::Transaction, mut input: usize, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
390                 let mut ret = (self.EcdsaChannelSigner.sign_holder_anchor_input)(self.EcdsaChannelSigner.this_arg, crate::c_types::Transaction::from_bitcoin(anchor_tx), input);
391                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
392                 local_ret
393         }
394         fn sign_channel_announcement_with_funding_key(&self, mut msg: &lightning::ln::msgs::UnsignedChannelAnnouncement, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
395                 let mut ret = (self.EcdsaChannelSigner.sign_channel_announcement_with_funding_key)(self.EcdsaChannelSigner.this_arg, &crate::lightning::ln::msgs::UnsignedChannelAnnouncement { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::UnsignedChannelAnnouncement<>) as *mut _) }, is_owned: false });
396                 let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
397                 local_ret
398         }
399 }
400 impl lightning::sign::ChannelSigner for WriteableEcdsaChannelSigner {
401         fn get_per_commitment_point(&self, mut idx: u64, mut _secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>) -> bitcoin::secp256k1::PublicKey {
402                 let mut ret = (self.EcdsaChannelSigner.ChannelSigner.get_per_commitment_point)(self.EcdsaChannelSigner.ChannelSigner.this_arg, idx);
403                 ret.into_rust()
404         }
405         fn release_commitment_secret(&self, mut idx: u64) -> [u8; 32] {
406                 let mut ret = (self.EcdsaChannelSigner.ChannelSigner.release_commitment_secret)(self.EcdsaChannelSigner.ChannelSigner.this_arg, idx);
407                 ret.data
408         }
409         fn validate_holder_commitment(&self, mut holder_tx: &lightning::ln::chan_utils::HolderCommitmentTransaction, mut outbound_htlc_preimages: Vec<lightning::ln::types::PaymentPreimage>) -> Result<(), ()> {
410                 let mut local_outbound_htlc_preimages = Vec::new(); for mut item in outbound_htlc_preimages.drain(..) { local_outbound_htlc_preimages.push( { crate::c_types::ThirtyTwoBytes { data: item.0 } }); };
411                 let mut ret = (self.EcdsaChannelSigner.ChannelSigner.validate_holder_commitment)(self.EcdsaChannelSigner.ChannelSigner.this_arg, &crate::lightning::ln::chan_utils::HolderCommitmentTransaction { inner: unsafe { ObjOps::nonnull_ptr_to_inner((holder_tx as *const lightning::ln::chan_utils::HolderCommitmentTransaction<>) as *mut _) }, is_owned: false }, local_outbound_htlc_preimages.into());
412                 let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
413                 local_ret
414         }
415         fn validate_counterparty_revocation(&self, mut idx: u64, mut secret: &bitcoin::secp256k1::SecretKey) -> Result<(), ()> {
416                 let mut ret = (self.EcdsaChannelSigner.ChannelSigner.validate_counterparty_revocation)(self.EcdsaChannelSigner.ChannelSigner.this_arg, idx, secret.as_ref());
417                 let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
418                 local_ret
419         }
420         fn pubkeys(&self) -> &lightning::ln::chan_utils::ChannelPublicKeys {
421                 if let Some(f) = self.EcdsaChannelSigner.ChannelSigner.set_pubkeys {
422                         (f)(&self.EcdsaChannelSigner.ChannelSigner);
423                 }
424                 unsafe { &*self.EcdsaChannelSigner.ChannelSigner.pubkeys.get() }.get_native_ref()
425         }
426         fn channel_keys_id(&self) -> [u8; 32] {
427                 let mut ret = (self.EcdsaChannelSigner.ChannelSigner.channel_keys_id)(self.EcdsaChannelSigner.ChannelSigner.this_arg);
428                 ret.data
429         }
430         fn provide_channel_parameters(&mut self, mut channel_parameters: &lightning::ln::chan_utils::ChannelTransactionParameters) {
431                 (self.EcdsaChannelSigner.ChannelSigner.provide_channel_parameters)(self.EcdsaChannelSigner.ChannelSigner.this_arg, &crate::lightning::ln::chan_utils::ChannelTransactionParameters { inner: unsafe { ObjOps::nonnull_ptr_to_inner((channel_parameters as *const lightning::ln::chan_utils::ChannelTransactionParameters<>) as *mut _) }, is_owned: false })
432         }
433 }
434 impl lightning::util::ser::Writeable for WriteableEcdsaChannelSigner {
435         fn write<W: lightning::util::ser::Writer>(&self, w: &mut W) -> Result<(), crate::c_types::io::Error> {
436                 let vec = (self.write)(self.this_arg);
437                 w.write_all(vec.as_slice())
438         }
439 }
440 #[no_mangle]
441 /// Creates a copy of a WriteableEcdsaChannelSigner
442 pub extern "C" fn WriteableEcdsaChannelSigner_clone(orig: &WriteableEcdsaChannelSigner) -> WriteableEcdsaChannelSigner {
443         let mut res = WriteableEcdsaChannelSigner_clone_fields(orig);
444         if let Some(f) = orig.cloned { (f)(&mut res) };
445         res
446 }
447 impl Clone for WriteableEcdsaChannelSigner {
448         fn clone(&self) -> Self {
449                 WriteableEcdsaChannelSigner_clone(self)
450         }
451 }
452
453 use lightning::sign::ecdsa::WriteableEcdsaChannelSigner as rustWriteableEcdsaChannelSigner;
454 impl rustWriteableEcdsaChannelSigner for WriteableEcdsaChannelSigner {
455 }
456
457 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
458 // directly as a Deref trait in higher-level structs:
459 impl core::ops::Deref for WriteableEcdsaChannelSigner {
460         type Target = Self;
461         fn deref(&self) -> &Self {
462                 self
463         }
464 }
465 impl core::ops::DerefMut for WriteableEcdsaChannelSigner {
466         fn deref_mut(&mut self) -> &mut Self {
467                 self
468         }
469 }
470 /// Calls the free function if one is set
471 #[no_mangle]
472 pub extern "C" fn WriteableEcdsaChannelSigner_free(this_ptr: WriteableEcdsaChannelSigner) { }
473 impl Drop for WriteableEcdsaChannelSigner {
474         fn drop(&mut self) {
475                 if let Some(f) = self.free {
476                         f(self.this_arg);
477                 }
478         }
479 }