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