Pin compiler_builtins to 0.1.109 when building std
[ldk-c-bindings] / lightning-c-bindings / src / lightning / ln / channel_keys.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 //! Keys used to generate commitment transactions.
10 //! See: <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys>
11
12 use alloc::str::FromStr;
13 use alloc::string::String;
14 use core::ffi::c_void;
15 use core::convert::Infallible;
16 use bitcoin::hashes::Hash;
17 use crate::c_types::*;
18 #[cfg(feature="no-std")]
19 use alloc::{vec::Vec, boxed::Box};
20
21
22 use lightning::ln::channel_keys::DelayedPaymentBasepoint as nativeDelayedPaymentBasepointImport;
23 pub(crate) type nativeDelayedPaymentBasepoint = nativeDelayedPaymentBasepointImport;
24
25 /// Base key used in conjunction with a `per_commitment_point` to generate a [`DelayedPaymentKey`].
26 ///
27 /// The delayed payment key is used to pay the commitment state broadcaster their
28 /// non-HTLC-encumbered funds after a delay to give their counterparty a chance to punish if the
29 /// state broadcasted was previously revoked.
30 #[must_use]
31 #[repr(C)]
32 pub struct DelayedPaymentBasepoint {
33         /// A pointer to the opaque Rust object.
34
35         /// Nearly everywhere, inner must be non-null, however in places where
36         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
37         pub inner: *mut nativeDelayedPaymentBasepoint,
38         /// Indicates that this is the only struct which contains the same pointer.
39
40         /// Rust functions which take ownership of an object provided via an argument require
41         /// this to be true and invalidate the object pointed to by inner.
42         pub is_owned: bool,
43 }
44
45 impl Drop for DelayedPaymentBasepoint {
46         fn drop(&mut self) {
47                 if self.is_owned && !<*mut nativeDelayedPaymentBasepoint>::is_null(self.inner) {
48                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
49                 }
50         }
51 }
52 /// Frees any resources used by the DelayedPaymentBasepoint, if is_owned is set and inner is non-NULL.
53 #[no_mangle]
54 pub extern "C" fn DelayedPaymentBasepoint_free(this_obj: DelayedPaymentBasepoint) { }
55 #[allow(unused)]
56 /// Used only if an object of this type is returned as a trait impl by a method
57 pub(crate) extern "C" fn DelayedPaymentBasepoint_free_void(this_ptr: *mut c_void) {
58         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDelayedPaymentBasepoint) };
59 }
60 #[allow(unused)]
61 impl DelayedPaymentBasepoint {
62         pub(crate) fn get_native_ref(&self) -> &'static nativeDelayedPaymentBasepoint {
63                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
64         }
65         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDelayedPaymentBasepoint {
66                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
67         }
68         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
69         pub(crate) fn take_inner(mut self) -> *mut nativeDelayedPaymentBasepoint {
70                 assert!(self.is_owned);
71                 let ret = ObjOps::untweak_ptr(self.inner);
72                 self.inner = core::ptr::null_mut();
73                 ret
74         }
75 }
76 #[no_mangle]
77 pub extern "C" fn DelayedPaymentBasepoint_get_a(this_ptr: &DelayedPaymentBasepoint) -> crate::c_types::PublicKey {
78         let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
79         crate::c_types::PublicKey::from_rust(&inner_val)
80 }
81 #[no_mangle]
82 pub extern "C" fn DelayedPaymentBasepoint_set_a(this_ptr: &mut DelayedPaymentBasepoint, mut val: crate::c_types::PublicKey) {
83         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
84 }
85 /// Constructs a new DelayedPaymentBasepoint given each field
86 #[must_use]
87 #[no_mangle]
88 pub extern "C" fn DelayedPaymentBasepoint_new(mut a_arg: crate::c_types::PublicKey) -> DelayedPaymentBasepoint {
89         DelayedPaymentBasepoint { inner: ObjOps::heap_alloc(lightning::ln::channel_keys::DelayedPaymentBasepoint (
90                 a_arg.into_rust(),
91         )), is_owned: true }
92 }
93 /// Checks if two DelayedPaymentBasepoints contain equal inner contents.
94 /// This ignores pointers and is_owned flags and looks at the values in fields.
95 /// Two objects with NULL inner values will be considered "equal" here.
96 #[no_mangle]
97 pub extern "C" fn DelayedPaymentBasepoint_eq(a: &DelayedPaymentBasepoint, b: &DelayedPaymentBasepoint) -> bool {
98         if a.inner == b.inner { return true; }
99         if a.inner.is_null() || b.inner.is_null() { return false; }
100         if a.get_native_ref() == b.get_native_ref() { true } else { false }
101 }
102 impl Clone for DelayedPaymentBasepoint {
103         fn clone(&self) -> Self {
104                 Self {
105                         inner: if <*mut nativeDelayedPaymentBasepoint>::is_null(self.inner) { core::ptr::null_mut() } else {
106                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
107                         is_owned: true,
108                 }
109         }
110 }
111 #[allow(unused)]
112 /// Used only if an object of this type is returned as a trait impl by a method
113 pub(crate) extern "C" fn DelayedPaymentBasepoint_clone_void(this_ptr: *const c_void) -> *mut c_void {
114         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeDelayedPaymentBasepoint)).clone() })) as *mut c_void
115 }
116 #[no_mangle]
117 /// Creates a copy of the DelayedPaymentBasepoint
118 pub extern "C" fn DelayedPaymentBasepoint_clone(orig: &DelayedPaymentBasepoint) -> DelayedPaymentBasepoint {
119         orig.clone()
120 }
121 /// Get a string which allows debug introspection of a DelayedPaymentBasepoint object
122 pub extern "C" fn DelayedPaymentBasepoint_debug_str_void(o: *const c_void) -> Str {
123         alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channel_keys::DelayedPaymentBasepoint }).into()}
124 /// Generates a non-cryptographic 64-bit hash of the DelayedPaymentBasepoint.
125 #[no_mangle]
126 pub extern "C" fn DelayedPaymentBasepoint_hash(o: &DelayedPaymentBasepoint) -> u64 {
127         if o.inner.is_null() { return 0; }
128         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
129         #[allow(deprecated)]
130         let mut hasher = core::hash::SipHasher::new();
131         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
132         core::hash::Hasher::finish(&hasher)
133 }
134 /// Get inner Public Key
135 #[must_use]
136 #[no_mangle]
137 pub extern "C" fn DelayedPaymentBasepoint_to_public_key(this_arg: &crate::lightning::ln::channel_keys::DelayedPaymentBasepoint) -> crate::c_types::PublicKey {
138         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_public_key();
139         crate::c_types::PublicKey::from_rust(&ret)
140 }
141
142 ///Derives the \"tweak\" used in calculate [`DelayedPaymentKey::from_basepoint`].\n\n[`DelayedPaymentKey::from_basepoint`] calculates a private key as:\n`privkey = basepoint_secret + SHA256(per_commitment_point || basepoint)`\n\nThis calculates the hash part in the tweak derivation process, which is used to\nensure that each key is unique and cannot be guessed by an external party.
143 #[must_use]
144 #[no_mangle]
145 pub extern "C" fn DelayedPaymentBasepoint_derive_add_tweak(this_arg: &crate::lightning::ln::channel_keys::DelayedPaymentBasepoint, mut per_commitment_point: crate::c_types::PublicKey) -> crate::c_types::ThirtyTwoBytes {
146         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_add_tweak(&per_commitment_point.into_rust());
147         crate::c_types::ThirtyTwoBytes { data: *ret.as_ref() }
148 }
149
150 #[no_mangle]
151 /// Serialize the DelayedPaymentBasepoint object into a byte array which can be read by DelayedPaymentBasepoint_read
152 pub extern "C" fn DelayedPaymentBasepoint_write(obj: &crate::lightning::ln::channel_keys::DelayedPaymentBasepoint) -> crate::c_types::derived::CVec_u8Z {
153         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
154 }
155 #[allow(unused)]
156 pub(crate) extern "C" fn DelayedPaymentBasepoint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
157         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDelayedPaymentBasepoint) })
158 }
159 #[no_mangle]
160 /// Read a DelayedPaymentBasepoint from a byte array, created by DelayedPaymentBasepoint_write
161 pub extern "C" fn DelayedPaymentBasepoint_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DelayedPaymentBasepointDecodeErrorZ {
162         let res: Result<lightning::ln::channel_keys::DelayedPaymentBasepoint, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
163         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channel_keys::DelayedPaymentBasepoint { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
164         local_res
165 }
166
167 use lightning::ln::channel_keys::DelayedPaymentKey as nativeDelayedPaymentKeyImport;
168 pub(crate) type nativeDelayedPaymentKey = nativeDelayedPaymentKeyImport;
169
170 /// A derived key built from a [`DelayedPaymentBasepoint`] and `per_commitment_point`.
171 ///
172 /// The delayed payment key is used to pay the commitment state broadcaster their
173 /// non-HTLC-encumbered funds after a delay. This delay gives their counterparty a chance to
174 /// punish and claim all the channel funds if the state broadcasted was previously revoked.
175 ///
176 /// [See the BOLT specs]
177 /// (https://github.com/lightning/bolts/blob/master/03-transactions.md#localpubkey-local_htlcpubkey-remote_htlcpubkey-local_delayedpubkey-and-remote_delayedpubkey-derivation)
178 /// for more information on key derivation details.
179 #[must_use]
180 #[repr(C)]
181 pub struct DelayedPaymentKey {
182         /// A pointer to the opaque Rust object.
183
184         /// Nearly everywhere, inner must be non-null, however in places where
185         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
186         pub inner: *mut nativeDelayedPaymentKey,
187         /// Indicates that this is the only struct which contains the same pointer.
188
189         /// Rust functions which take ownership of an object provided via an argument require
190         /// this to be true and invalidate the object pointed to by inner.
191         pub is_owned: bool,
192 }
193
194 impl Drop for DelayedPaymentKey {
195         fn drop(&mut self) {
196                 if self.is_owned && !<*mut nativeDelayedPaymentKey>::is_null(self.inner) {
197                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
198                 }
199         }
200 }
201 /// Frees any resources used by the DelayedPaymentKey, if is_owned is set and inner is non-NULL.
202 #[no_mangle]
203 pub extern "C" fn DelayedPaymentKey_free(this_obj: DelayedPaymentKey) { }
204 #[allow(unused)]
205 /// Used only if an object of this type is returned as a trait impl by a method
206 pub(crate) extern "C" fn DelayedPaymentKey_free_void(this_ptr: *mut c_void) {
207         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDelayedPaymentKey) };
208 }
209 #[allow(unused)]
210 impl DelayedPaymentKey {
211         pub(crate) fn get_native_ref(&self) -> &'static nativeDelayedPaymentKey {
212                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
213         }
214         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDelayedPaymentKey {
215                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
216         }
217         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
218         pub(crate) fn take_inner(mut self) -> *mut nativeDelayedPaymentKey {
219                 assert!(self.is_owned);
220                 let ret = ObjOps::untweak_ptr(self.inner);
221                 self.inner = core::ptr::null_mut();
222                 ret
223         }
224 }
225 #[no_mangle]
226 pub extern "C" fn DelayedPaymentKey_get_a(this_ptr: &DelayedPaymentKey) -> crate::c_types::PublicKey {
227         let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
228         crate::c_types::PublicKey::from_rust(&inner_val)
229 }
230 #[no_mangle]
231 pub extern "C" fn DelayedPaymentKey_set_a(this_ptr: &mut DelayedPaymentKey, mut val: crate::c_types::PublicKey) {
232         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
233 }
234 /// Constructs a new DelayedPaymentKey given each field
235 #[must_use]
236 #[no_mangle]
237 pub extern "C" fn DelayedPaymentKey_new(mut a_arg: crate::c_types::PublicKey) -> DelayedPaymentKey {
238         DelayedPaymentKey { inner: ObjOps::heap_alloc(lightning::ln::channel_keys::DelayedPaymentKey (
239                 a_arg.into_rust(),
240         )), is_owned: true }
241 }
242 /// Checks if two DelayedPaymentKeys contain equal inner contents.
243 /// This ignores pointers and is_owned flags and looks at the values in fields.
244 /// Two objects with NULL inner values will be considered "equal" here.
245 #[no_mangle]
246 pub extern "C" fn DelayedPaymentKey_eq(a: &DelayedPaymentKey, b: &DelayedPaymentKey) -> bool {
247         if a.inner == b.inner { return true; }
248         if a.inner.is_null() || b.inner.is_null() { return false; }
249         if a.get_native_ref() == b.get_native_ref() { true } else { false }
250 }
251 impl Clone for DelayedPaymentKey {
252         fn clone(&self) -> Self {
253                 Self {
254                         inner: if <*mut nativeDelayedPaymentKey>::is_null(self.inner) { core::ptr::null_mut() } else {
255                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
256                         is_owned: true,
257                 }
258         }
259 }
260 #[allow(unused)]
261 /// Used only if an object of this type is returned as a trait impl by a method
262 pub(crate) extern "C" fn DelayedPaymentKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
263         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeDelayedPaymentKey)).clone() })) as *mut c_void
264 }
265 #[no_mangle]
266 /// Creates a copy of the DelayedPaymentKey
267 pub extern "C" fn DelayedPaymentKey_clone(orig: &DelayedPaymentKey) -> DelayedPaymentKey {
268         orig.clone()
269 }
270 /// Get a string which allows debug introspection of a DelayedPaymentKey object
271 pub extern "C" fn DelayedPaymentKey_debug_str_void(o: *const c_void) -> Str {
272         alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channel_keys::DelayedPaymentKey }).into()}
273 ///Derive a public delayedpubkey using one node\'s `per_commitment_point` and its countersignatory\'s `basepoint`
274 #[must_use]
275 #[no_mangle]
276 pub extern "C" fn DelayedPaymentKey_from_basepoint(countersignatory_basepoint: &crate::lightning::ln::channel_keys::DelayedPaymentBasepoint, mut per_commitment_point: crate::c_types::PublicKey) -> crate::lightning::ln::channel_keys::DelayedPaymentKey {
277         let mut ret = lightning::ln::channel_keys::DelayedPaymentKey::from_basepoint(secp256k1::global::SECP256K1, countersignatory_basepoint.get_native_ref(), &per_commitment_point.into_rust());
278         crate::lightning::ln::channel_keys::DelayedPaymentKey { inner: ObjOps::heap_alloc(ret), is_owned: true }
279 }
280
281 ///Build a delayedpubkey directly from an already-derived private key
282 #[must_use]
283 #[no_mangle]
284 pub extern "C" fn DelayedPaymentKey_from_secret_key(sk: *const [u8; 32]) -> crate::lightning::ln::channel_keys::DelayedPaymentKey {
285         let mut ret = lightning::ln::channel_keys::DelayedPaymentKey::from_secret_key(secp256k1::global::SECP256K1, &::bitcoin::secp256k1::SecretKey::from_slice(&unsafe { *sk}[..]).unwrap());
286         crate::lightning::ln::channel_keys::DelayedPaymentKey { inner: ObjOps::heap_alloc(ret), is_owned: true }
287 }
288
289 /// Get inner Public Key
290 #[must_use]
291 #[no_mangle]
292 pub extern "C" fn DelayedPaymentKey_to_public_key(this_arg: &crate::lightning::ln::channel_keys::DelayedPaymentKey) -> crate::c_types::PublicKey {
293         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_public_key();
294         crate::c_types::PublicKey::from_rust(&ret)
295 }
296
297 #[no_mangle]
298 /// Serialize the DelayedPaymentKey object into a byte array which can be read by DelayedPaymentKey_read
299 pub extern "C" fn DelayedPaymentKey_write(obj: &crate::lightning::ln::channel_keys::DelayedPaymentKey) -> crate::c_types::derived::CVec_u8Z {
300         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
301 }
302 #[allow(unused)]
303 pub(crate) extern "C" fn DelayedPaymentKey_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
304         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDelayedPaymentKey) })
305 }
306 #[no_mangle]
307 /// Read a DelayedPaymentKey from a byte array, created by DelayedPaymentKey_write
308 pub extern "C" fn DelayedPaymentKey_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DelayedPaymentKeyDecodeErrorZ {
309         let res: Result<lightning::ln::channel_keys::DelayedPaymentKey, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
310         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channel_keys::DelayedPaymentKey { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
311         local_res
312 }
313
314 use lightning::ln::channel_keys::HtlcBasepoint as nativeHtlcBasepointImport;
315 pub(crate) type nativeHtlcBasepoint = nativeHtlcBasepointImport;
316
317 /// Base key used in conjunction with a `per_commitment_point` to generate an [`HtlcKey`].
318 ///
319 /// HTLC keys are used to ensure only the recipient of an HTLC can claim it on-chain with the HTLC
320 /// preimage and that only the sender of an HTLC can claim it on-chain after it has timed out.
321 /// Thus, both channel counterparties' HTLC keys will appears in each HTLC output's script.
322 #[must_use]
323 #[repr(C)]
324 pub struct HtlcBasepoint {
325         /// A pointer to the opaque Rust object.
326
327         /// Nearly everywhere, inner must be non-null, however in places where
328         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
329         pub inner: *mut nativeHtlcBasepoint,
330         /// Indicates that this is the only struct which contains the same pointer.
331
332         /// Rust functions which take ownership of an object provided via an argument require
333         /// this to be true and invalidate the object pointed to by inner.
334         pub is_owned: bool,
335 }
336
337 impl Drop for HtlcBasepoint {
338         fn drop(&mut self) {
339                 if self.is_owned && !<*mut nativeHtlcBasepoint>::is_null(self.inner) {
340                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
341                 }
342         }
343 }
344 /// Frees any resources used by the HtlcBasepoint, if is_owned is set and inner is non-NULL.
345 #[no_mangle]
346 pub extern "C" fn HtlcBasepoint_free(this_obj: HtlcBasepoint) { }
347 #[allow(unused)]
348 /// Used only if an object of this type is returned as a trait impl by a method
349 pub(crate) extern "C" fn HtlcBasepoint_free_void(this_ptr: *mut c_void) {
350         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeHtlcBasepoint) };
351 }
352 #[allow(unused)]
353 impl HtlcBasepoint {
354         pub(crate) fn get_native_ref(&self) -> &'static nativeHtlcBasepoint {
355                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
356         }
357         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHtlcBasepoint {
358                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
359         }
360         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
361         pub(crate) fn take_inner(mut self) -> *mut nativeHtlcBasepoint {
362                 assert!(self.is_owned);
363                 let ret = ObjOps::untweak_ptr(self.inner);
364                 self.inner = core::ptr::null_mut();
365                 ret
366         }
367 }
368 #[no_mangle]
369 pub extern "C" fn HtlcBasepoint_get_a(this_ptr: &HtlcBasepoint) -> crate::c_types::PublicKey {
370         let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
371         crate::c_types::PublicKey::from_rust(&inner_val)
372 }
373 #[no_mangle]
374 pub extern "C" fn HtlcBasepoint_set_a(this_ptr: &mut HtlcBasepoint, mut val: crate::c_types::PublicKey) {
375         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
376 }
377 /// Constructs a new HtlcBasepoint given each field
378 #[must_use]
379 #[no_mangle]
380 pub extern "C" fn HtlcBasepoint_new(mut a_arg: crate::c_types::PublicKey) -> HtlcBasepoint {
381         HtlcBasepoint { inner: ObjOps::heap_alloc(lightning::ln::channel_keys::HtlcBasepoint (
382                 a_arg.into_rust(),
383         )), is_owned: true }
384 }
385 /// Checks if two HtlcBasepoints contain equal inner contents.
386 /// This ignores pointers and is_owned flags and looks at the values in fields.
387 /// Two objects with NULL inner values will be considered "equal" here.
388 #[no_mangle]
389 pub extern "C" fn HtlcBasepoint_eq(a: &HtlcBasepoint, b: &HtlcBasepoint) -> bool {
390         if a.inner == b.inner { return true; }
391         if a.inner.is_null() || b.inner.is_null() { return false; }
392         if a.get_native_ref() == b.get_native_ref() { true } else { false }
393 }
394 impl Clone for HtlcBasepoint {
395         fn clone(&self) -> Self {
396                 Self {
397                         inner: if <*mut nativeHtlcBasepoint>::is_null(self.inner) { core::ptr::null_mut() } else {
398                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
399                         is_owned: true,
400                 }
401         }
402 }
403 #[allow(unused)]
404 /// Used only if an object of this type is returned as a trait impl by a method
405 pub(crate) extern "C" fn HtlcBasepoint_clone_void(this_ptr: *const c_void) -> *mut c_void {
406         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeHtlcBasepoint)).clone() })) as *mut c_void
407 }
408 #[no_mangle]
409 /// Creates a copy of the HtlcBasepoint
410 pub extern "C" fn HtlcBasepoint_clone(orig: &HtlcBasepoint) -> HtlcBasepoint {
411         orig.clone()
412 }
413 /// Get a string which allows debug introspection of a HtlcBasepoint object
414 pub extern "C" fn HtlcBasepoint_debug_str_void(o: *const c_void) -> Str {
415         alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channel_keys::HtlcBasepoint }).into()}
416 /// Generates a non-cryptographic 64-bit hash of the HtlcBasepoint.
417 #[no_mangle]
418 pub extern "C" fn HtlcBasepoint_hash(o: &HtlcBasepoint) -> u64 {
419         if o.inner.is_null() { return 0; }
420         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
421         #[allow(deprecated)]
422         let mut hasher = core::hash::SipHasher::new();
423         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
424         core::hash::Hasher::finish(&hasher)
425 }
426 /// Get inner Public Key
427 #[must_use]
428 #[no_mangle]
429 pub extern "C" fn HtlcBasepoint_to_public_key(this_arg: &crate::lightning::ln::channel_keys::HtlcBasepoint) -> crate::c_types::PublicKey {
430         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_public_key();
431         crate::c_types::PublicKey::from_rust(&ret)
432 }
433
434 ///Derives the \"tweak\" used in calculate [`HtlcKey::from_basepoint`].\n\n[`HtlcKey::from_basepoint`] calculates a private key as:\n`privkey = basepoint_secret + SHA256(per_commitment_point || basepoint)`\n\nThis calculates the hash part in the tweak derivation process, which is used to\nensure that each key is unique and cannot be guessed by an external party.
435 #[must_use]
436 #[no_mangle]
437 pub extern "C" fn HtlcBasepoint_derive_add_tweak(this_arg: &crate::lightning::ln::channel_keys::HtlcBasepoint, mut per_commitment_point: crate::c_types::PublicKey) -> crate::c_types::ThirtyTwoBytes {
438         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_add_tweak(&per_commitment_point.into_rust());
439         crate::c_types::ThirtyTwoBytes { data: *ret.as_ref() }
440 }
441
442 #[no_mangle]
443 /// Serialize the HtlcBasepoint object into a byte array which can be read by HtlcBasepoint_read
444 pub extern "C" fn HtlcBasepoint_write(obj: &crate::lightning::ln::channel_keys::HtlcBasepoint) -> crate::c_types::derived::CVec_u8Z {
445         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
446 }
447 #[allow(unused)]
448 pub(crate) extern "C" fn HtlcBasepoint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
449         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHtlcBasepoint) })
450 }
451 #[no_mangle]
452 /// Read a HtlcBasepoint from a byte array, created by HtlcBasepoint_write
453 pub extern "C" fn HtlcBasepoint_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HtlcBasepointDecodeErrorZ {
454         let res: Result<lightning::ln::channel_keys::HtlcBasepoint, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
455         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channel_keys::HtlcBasepoint { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
456         local_res
457 }
458
459 use lightning::ln::channel_keys::HtlcKey as nativeHtlcKeyImport;
460 pub(crate) type nativeHtlcKey = nativeHtlcKeyImport;
461
462 /// A derived key built from a [`HtlcBasepoint`] and `per_commitment_point`.
463 ///
464 /// HTLC keys are used to ensure only the recipient of an HTLC can claim it on-chain with the HTLC
465 /// preimage and that only the sender of an HTLC can claim it on-chain after it has timed out.
466 /// Thus, both channel counterparties' HTLC keys will appears in each HTLC output's script.
467 ///
468 /// [See the BOLT specs]
469 /// (https://github.com/lightning/bolts/blob/master/03-transactions.md#localpubkey-local_htlcpubkey-remote_htlcpubkey-local_delayedpubkey-and-remote_delayedpubkey-derivation)
470 /// for more information on key derivation details.
471 #[must_use]
472 #[repr(C)]
473 pub struct HtlcKey {
474         /// A pointer to the opaque Rust object.
475
476         /// Nearly everywhere, inner must be non-null, however in places where
477         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
478         pub inner: *mut nativeHtlcKey,
479         /// Indicates that this is the only struct which contains the same pointer.
480
481         /// Rust functions which take ownership of an object provided via an argument require
482         /// this to be true and invalidate the object pointed to by inner.
483         pub is_owned: bool,
484 }
485
486 impl Drop for HtlcKey {
487         fn drop(&mut self) {
488                 if self.is_owned && !<*mut nativeHtlcKey>::is_null(self.inner) {
489                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
490                 }
491         }
492 }
493 /// Frees any resources used by the HtlcKey, if is_owned is set and inner is non-NULL.
494 #[no_mangle]
495 pub extern "C" fn HtlcKey_free(this_obj: HtlcKey) { }
496 #[allow(unused)]
497 /// Used only if an object of this type is returned as a trait impl by a method
498 pub(crate) extern "C" fn HtlcKey_free_void(this_ptr: *mut c_void) {
499         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeHtlcKey) };
500 }
501 #[allow(unused)]
502 impl HtlcKey {
503         pub(crate) fn get_native_ref(&self) -> &'static nativeHtlcKey {
504                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
505         }
506         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHtlcKey {
507                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
508         }
509         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
510         pub(crate) fn take_inner(mut self) -> *mut nativeHtlcKey {
511                 assert!(self.is_owned);
512                 let ret = ObjOps::untweak_ptr(self.inner);
513                 self.inner = core::ptr::null_mut();
514                 ret
515         }
516 }
517 #[no_mangle]
518 pub extern "C" fn HtlcKey_get_a(this_ptr: &HtlcKey) -> crate::c_types::PublicKey {
519         let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
520         crate::c_types::PublicKey::from_rust(&inner_val)
521 }
522 #[no_mangle]
523 pub extern "C" fn HtlcKey_set_a(this_ptr: &mut HtlcKey, mut val: crate::c_types::PublicKey) {
524         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
525 }
526 /// Constructs a new HtlcKey given each field
527 #[must_use]
528 #[no_mangle]
529 pub extern "C" fn HtlcKey_new(mut a_arg: crate::c_types::PublicKey) -> HtlcKey {
530         HtlcKey { inner: ObjOps::heap_alloc(lightning::ln::channel_keys::HtlcKey (
531                 a_arg.into_rust(),
532         )), is_owned: true }
533 }
534 /// Checks if two HtlcKeys contain equal inner contents.
535 /// This ignores pointers and is_owned flags and looks at the values in fields.
536 /// Two objects with NULL inner values will be considered "equal" here.
537 #[no_mangle]
538 pub extern "C" fn HtlcKey_eq(a: &HtlcKey, b: &HtlcKey) -> bool {
539         if a.inner == b.inner { return true; }
540         if a.inner.is_null() || b.inner.is_null() { return false; }
541         if a.get_native_ref() == b.get_native_ref() { true } else { false }
542 }
543 impl Clone for HtlcKey {
544         fn clone(&self) -> Self {
545                 Self {
546                         inner: if <*mut nativeHtlcKey>::is_null(self.inner) { core::ptr::null_mut() } else {
547                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
548                         is_owned: true,
549                 }
550         }
551 }
552 #[allow(unused)]
553 /// Used only if an object of this type is returned as a trait impl by a method
554 pub(crate) extern "C" fn HtlcKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
555         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeHtlcKey)).clone() })) as *mut c_void
556 }
557 #[no_mangle]
558 /// Creates a copy of the HtlcKey
559 pub extern "C" fn HtlcKey_clone(orig: &HtlcKey) -> HtlcKey {
560         orig.clone()
561 }
562 /// Get a string which allows debug introspection of a HtlcKey object
563 pub extern "C" fn HtlcKey_debug_str_void(o: *const c_void) -> Str {
564         alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channel_keys::HtlcKey }).into()}
565 ///Derive a public htlcpubkey using one node\'s `per_commitment_point` and its countersignatory\'s `basepoint`
566 #[must_use]
567 #[no_mangle]
568 pub extern "C" fn HtlcKey_from_basepoint(countersignatory_basepoint: &crate::lightning::ln::channel_keys::HtlcBasepoint, mut per_commitment_point: crate::c_types::PublicKey) -> crate::lightning::ln::channel_keys::HtlcKey {
569         let mut ret = lightning::ln::channel_keys::HtlcKey::from_basepoint(secp256k1::global::SECP256K1, countersignatory_basepoint.get_native_ref(), &per_commitment_point.into_rust());
570         crate::lightning::ln::channel_keys::HtlcKey { inner: ObjOps::heap_alloc(ret), is_owned: true }
571 }
572
573 ///Build a htlcpubkey directly from an already-derived private key
574 #[must_use]
575 #[no_mangle]
576 pub extern "C" fn HtlcKey_from_secret_key(sk: *const [u8; 32]) -> crate::lightning::ln::channel_keys::HtlcKey {
577         let mut ret = lightning::ln::channel_keys::HtlcKey::from_secret_key(secp256k1::global::SECP256K1, &::bitcoin::secp256k1::SecretKey::from_slice(&unsafe { *sk}[..]).unwrap());
578         crate::lightning::ln::channel_keys::HtlcKey { inner: ObjOps::heap_alloc(ret), is_owned: true }
579 }
580
581 /// Get inner Public Key
582 #[must_use]
583 #[no_mangle]
584 pub extern "C" fn HtlcKey_to_public_key(this_arg: &crate::lightning::ln::channel_keys::HtlcKey) -> crate::c_types::PublicKey {
585         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_public_key();
586         crate::c_types::PublicKey::from_rust(&ret)
587 }
588
589 #[no_mangle]
590 /// Serialize the HtlcKey object into a byte array which can be read by HtlcKey_read
591 pub extern "C" fn HtlcKey_write(obj: &crate::lightning::ln::channel_keys::HtlcKey) -> crate::c_types::derived::CVec_u8Z {
592         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
593 }
594 #[allow(unused)]
595 pub(crate) extern "C" fn HtlcKey_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
596         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHtlcKey) })
597 }
598 #[no_mangle]
599 /// Read a HtlcKey from a byte array, created by HtlcKey_write
600 pub extern "C" fn HtlcKey_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HtlcKeyDecodeErrorZ {
601         let res: Result<lightning::ln::channel_keys::HtlcKey, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
602         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channel_keys::HtlcKey { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
603         local_res
604 }
605 /// Adds a tweak to a public key to derive a new public key.
606 ///
607 /// May panic if `tweak` is not the output of a SHA-256 hash.
608 #[no_mangle]
609 pub extern "C" fn add_public_key_tweak(mut base_point: crate::c_types::PublicKey, tweak: *const [u8; 32]) -> crate::c_types::PublicKey {
610         let mut ret = lightning::ln::channel_keys::add_public_key_tweak(secp256k1::global::SECP256K1, &base_point.into_rust(), &::bitcoin::hashes::sha256::Hash::from_slice(&unsafe { &*tweak }[..]).unwrap());
611         crate::c_types::PublicKey::from_rust(&ret)
612 }
613
614
615 use lightning::ln::channel_keys::RevocationBasepoint as nativeRevocationBasepointImport;
616 pub(crate) type nativeRevocationBasepoint = nativeRevocationBasepointImport;
617
618 /// Master key used in conjunction with per_commitment_point to generate [htlcpubkey](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation) for the latest state of a channel.
619 /// A watcher can be given a [RevocationBasepoint] to generate per commitment [RevocationKey] to create justice transactions.
620 #[must_use]
621 #[repr(C)]
622 pub struct RevocationBasepoint {
623         /// A pointer to the opaque Rust object.
624
625         /// Nearly everywhere, inner must be non-null, however in places where
626         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
627         pub inner: *mut nativeRevocationBasepoint,
628         /// Indicates that this is the only struct which contains the same pointer.
629
630         /// Rust functions which take ownership of an object provided via an argument require
631         /// this to be true and invalidate the object pointed to by inner.
632         pub is_owned: bool,
633 }
634
635 impl Drop for RevocationBasepoint {
636         fn drop(&mut self) {
637                 if self.is_owned && !<*mut nativeRevocationBasepoint>::is_null(self.inner) {
638                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
639                 }
640         }
641 }
642 /// Frees any resources used by the RevocationBasepoint, if is_owned is set and inner is non-NULL.
643 #[no_mangle]
644 pub extern "C" fn RevocationBasepoint_free(this_obj: RevocationBasepoint) { }
645 #[allow(unused)]
646 /// Used only if an object of this type is returned as a trait impl by a method
647 pub(crate) extern "C" fn RevocationBasepoint_free_void(this_ptr: *mut c_void) {
648         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRevocationBasepoint) };
649 }
650 #[allow(unused)]
651 impl RevocationBasepoint {
652         pub(crate) fn get_native_ref(&self) -> &'static nativeRevocationBasepoint {
653                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
654         }
655         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRevocationBasepoint {
656                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
657         }
658         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
659         pub(crate) fn take_inner(mut self) -> *mut nativeRevocationBasepoint {
660                 assert!(self.is_owned);
661                 let ret = ObjOps::untweak_ptr(self.inner);
662                 self.inner = core::ptr::null_mut();
663                 ret
664         }
665 }
666 #[no_mangle]
667 pub extern "C" fn RevocationBasepoint_get_a(this_ptr: &RevocationBasepoint) -> crate::c_types::PublicKey {
668         let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
669         crate::c_types::PublicKey::from_rust(&inner_val)
670 }
671 #[no_mangle]
672 pub extern "C" fn RevocationBasepoint_set_a(this_ptr: &mut RevocationBasepoint, mut val: crate::c_types::PublicKey) {
673         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
674 }
675 /// Constructs a new RevocationBasepoint given each field
676 #[must_use]
677 #[no_mangle]
678 pub extern "C" fn RevocationBasepoint_new(mut a_arg: crate::c_types::PublicKey) -> RevocationBasepoint {
679         RevocationBasepoint { inner: ObjOps::heap_alloc(lightning::ln::channel_keys::RevocationBasepoint (
680                 a_arg.into_rust(),
681         )), is_owned: true }
682 }
683 /// Checks if two RevocationBasepoints contain equal inner contents.
684 /// This ignores pointers and is_owned flags and looks at the values in fields.
685 /// Two objects with NULL inner values will be considered "equal" here.
686 #[no_mangle]
687 pub extern "C" fn RevocationBasepoint_eq(a: &RevocationBasepoint, b: &RevocationBasepoint) -> bool {
688         if a.inner == b.inner { return true; }
689         if a.inner.is_null() || b.inner.is_null() { return false; }
690         if a.get_native_ref() == b.get_native_ref() { true } else { false }
691 }
692 impl Clone for RevocationBasepoint {
693         fn clone(&self) -> Self {
694                 Self {
695                         inner: if <*mut nativeRevocationBasepoint>::is_null(self.inner) { core::ptr::null_mut() } else {
696                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
697                         is_owned: true,
698                 }
699         }
700 }
701 #[allow(unused)]
702 /// Used only if an object of this type is returned as a trait impl by a method
703 pub(crate) extern "C" fn RevocationBasepoint_clone_void(this_ptr: *const c_void) -> *mut c_void {
704         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRevocationBasepoint)).clone() })) as *mut c_void
705 }
706 #[no_mangle]
707 /// Creates a copy of the RevocationBasepoint
708 pub extern "C" fn RevocationBasepoint_clone(orig: &RevocationBasepoint) -> RevocationBasepoint {
709         orig.clone()
710 }
711 /// Get a string which allows debug introspection of a RevocationBasepoint object
712 pub extern "C" fn RevocationBasepoint_debug_str_void(o: *const c_void) -> Str {
713         alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channel_keys::RevocationBasepoint }).into()}
714 /// Generates a non-cryptographic 64-bit hash of the RevocationBasepoint.
715 #[no_mangle]
716 pub extern "C" fn RevocationBasepoint_hash(o: &RevocationBasepoint) -> u64 {
717         if o.inner.is_null() { return 0; }
718         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
719         #[allow(deprecated)]
720         let mut hasher = core::hash::SipHasher::new();
721         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
722         core::hash::Hasher::finish(&hasher)
723 }
724 /// Get inner Public Key
725 #[must_use]
726 #[no_mangle]
727 pub extern "C" fn RevocationBasepoint_to_public_key(this_arg: &crate::lightning::ln::channel_keys::RevocationBasepoint) -> crate::c_types::PublicKey {
728         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_public_key();
729         crate::c_types::PublicKey::from_rust(&ret)
730 }
731
732 #[no_mangle]
733 /// Serialize the RevocationBasepoint object into a byte array which can be read by RevocationBasepoint_read
734 pub extern "C" fn RevocationBasepoint_write(obj: &crate::lightning::ln::channel_keys::RevocationBasepoint) -> crate::c_types::derived::CVec_u8Z {
735         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
736 }
737 #[allow(unused)]
738 pub(crate) extern "C" fn RevocationBasepoint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
739         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRevocationBasepoint) })
740 }
741 #[no_mangle]
742 /// Read a RevocationBasepoint from a byte array, created by RevocationBasepoint_write
743 pub extern "C" fn RevocationBasepoint_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RevocationBasepointDecodeErrorZ {
744         let res: Result<lightning::ln::channel_keys::RevocationBasepoint, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
745         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channel_keys::RevocationBasepoint { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
746         local_res
747 }
748
749 use lightning::ln::channel_keys::RevocationKey as nativeRevocationKeyImport;
750 pub(crate) type nativeRevocationKey = nativeRevocationKeyImport;
751
752 /// The revocation key is used to allow a channel party to revoke their state - giving their
753 /// counterparty the required material to claim all of their funds if they broadcast that state.
754 ///
755 /// Each commitment transaction has a revocation key based on the basepoint and
756 /// per_commitment_point which is used in both commitment and HTLC transactions.
757 ///
758 /// See [the BOLT spec for derivation details]
759 /// (https://github.com/lightning/bolts/blob/master/03-transactions.md#revocationpubkey-derivation)
760 #[must_use]
761 #[repr(C)]
762 pub struct RevocationKey {
763         /// A pointer to the opaque Rust object.
764
765         /// Nearly everywhere, inner must be non-null, however in places where
766         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
767         pub inner: *mut nativeRevocationKey,
768         /// Indicates that this is the only struct which contains the same pointer.
769
770         /// Rust functions which take ownership of an object provided via an argument require
771         /// this to be true and invalidate the object pointed to by inner.
772         pub is_owned: bool,
773 }
774
775 impl Drop for RevocationKey {
776         fn drop(&mut self) {
777                 if self.is_owned && !<*mut nativeRevocationKey>::is_null(self.inner) {
778                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
779                 }
780         }
781 }
782 /// Frees any resources used by the RevocationKey, if is_owned is set and inner is non-NULL.
783 #[no_mangle]
784 pub extern "C" fn RevocationKey_free(this_obj: RevocationKey) { }
785 #[allow(unused)]
786 /// Used only if an object of this type is returned as a trait impl by a method
787 pub(crate) extern "C" fn RevocationKey_free_void(this_ptr: *mut c_void) {
788         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRevocationKey) };
789 }
790 #[allow(unused)]
791 impl RevocationKey {
792         pub(crate) fn get_native_ref(&self) -> &'static nativeRevocationKey {
793                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
794         }
795         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRevocationKey {
796                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
797         }
798         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
799         pub(crate) fn take_inner(mut self) -> *mut nativeRevocationKey {
800                 assert!(self.is_owned);
801                 let ret = ObjOps::untweak_ptr(self.inner);
802                 self.inner = core::ptr::null_mut();
803                 ret
804         }
805 }
806 #[no_mangle]
807 pub extern "C" fn RevocationKey_get_a(this_ptr: &RevocationKey) -> crate::c_types::PublicKey {
808         let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
809         crate::c_types::PublicKey::from_rust(&inner_val)
810 }
811 #[no_mangle]
812 pub extern "C" fn RevocationKey_set_a(this_ptr: &mut RevocationKey, mut val: crate::c_types::PublicKey) {
813         unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
814 }
815 /// Constructs a new RevocationKey given each field
816 #[must_use]
817 #[no_mangle]
818 pub extern "C" fn RevocationKey_new(mut a_arg: crate::c_types::PublicKey) -> RevocationKey {
819         RevocationKey { inner: ObjOps::heap_alloc(lightning::ln::channel_keys::RevocationKey (
820                 a_arg.into_rust(),
821         )), is_owned: true }
822 }
823 /// Checks if two RevocationKeys contain equal inner contents.
824 /// This ignores pointers and is_owned flags and looks at the values in fields.
825 /// Two objects with NULL inner values will be considered "equal" here.
826 #[no_mangle]
827 pub extern "C" fn RevocationKey_eq(a: &RevocationKey, b: &RevocationKey) -> bool {
828         if a.inner == b.inner { return true; }
829         if a.inner.is_null() || b.inner.is_null() { return false; }
830         if a.get_native_ref() == b.get_native_ref() { true } else { false }
831 }
832 impl Clone for RevocationKey {
833         fn clone(&self) -> Self {
834                 Self {
835                         inner: if <*mut nativeRevocationKey>::is_null(self.inner) { core::ptr::null_mut() } else {
836                                 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
837                         is_owned: true,
838                 }
839         }
840 }
841 #[allow(unused)]
842 /// Used only if an object of this type is returned as a trait impl by a method
843 pub(crate) extern "C" fn RevocationKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
844         Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRevocationKey)).clone() })) as *mut c_void
845 }
846 #[no_mangle]
847 /// Creates a copy of the RevocationKey
848 pub extern "C" fn RevocationKey_clone(orig: &RevocationKey) -> RevocationKey {
849         orig.clone()
850 }
851 /// Get a string which allows debug introspection of a RevocationKey object
852 pub extern "C" fn RevocationKey_debug_str_void(o: *const c_void) -> Str {
853         alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channel_keys::RevocationKey }).into()}
854 /// Generates a non-cryptographic 64-bit hash of the RevocationKey.
855 #[no_mangle]
856 pub extern "C" fn RevocationKey_hash(o: &RevocationKey) -> u64 {
857         if o.inner.is_null() { return 0; }
858         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
859         #[allow(deprecated)]
860         let mut hasher = core::hash::SipHasher::new();
861         core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
862         core::hash::Hasher::finish(&hasher)
863 }
864 /// Derives a per-commitment-transaction revocation public key from one party's per-commitment
865 /// point and the other party's [`RevocationBasepoint`]. This is the public equivalent of
866 /// [`chan_utils::derive_private_revocation_key`] - using only public keys to derive a public
867 /// key instead of private keys.
868 ///
869 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
870 /// generated (ie our own).
871 ///
872 /// [`chan_utils::derive_private_revocation_key`]: crate::ln::chan_utils::derive_private_revocation_key
873 #[must_use]
874 #[no_mangle]
875 pub extern "C" fn RevocationKey_from_basepoint(countersignatory_basepoint: &crate::lightning::ln::channel_keys::RevocationBasepoint, mut per_commitment_point: crate::c_types::PublicKey) -> crate::lightning::ln::channel_keys::RevocationKey {
876         let mut ret = lightning::ln::channel_keys::RevocationKey::from_basepoint(secp256k1::global::SECP256K1, countersignatory_basepoint.get_native_ref(), &per_commitment_point.into_rust());
877         crate::lightning::ln::channel_keys::RevocationKey { inner: ObjOps::heap_alloc(ret), is_owned: true }
878 }
879
880 /// Get inner Public Key
881 #[must_use]
882 #[no_mangle]
883 pub extern "C" fn RevocationKey_to_public_key(this_arg: &crate::lightning::ln::channel_keys::RevocationKey) -> crate::c_types::PublicKey {
884         let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_public_key();
885         crate::c_types::PublicKey::from_rust(&ret)
886 }
887
888 #[no_mangle]
889 /// Serialize the RevocationKey object into a byte array which can be read by RevocationKey_read
890 pub extern "C" fn RevocationKey_write(obj: &crate::lightning::ln::channel_keys::RevocationKey) -> crate::c_types::derived::CVec_u8Z {
891         crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
892 }
893 #[allow(unused)]
894 pub(crate) extern "C" fn RevocationKey_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
895         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRevocationKey) })
896 }
897 #[no_mangle]
898 /// Read a RevocationKey from a byte array, created by RevocationKey_write
899 pub extern "C" fn RevocationKey_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RevocationKeyDecodeErrorZ {
900         let res: Result<lightning::ln::channel_keys::RevocationKey, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
901         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channel_keys::RevocationKey { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() };
902         local_res
903 }