+pub struct NodeSigner {
+ /// An opaque pointer which is passed to your function implementations as an argument.
+ /// This has no meaning in the LDK, and can be NULL or any other value.
+ pub this_arg: *mut c_void,
+ /// Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
+ ///
+ /// If the implementor of this trait supports [phantom node payments], then every node that is
+ /// intended to be included in the phantom invoice route hints must return the same value from
+ /// this method.
+ ///
+ /// This method must return the same value each time it is called.
+ ///
+ /// [phantom node payments]: PhantomKeysManager
+ #[must_use]
+ pub get_inbound_payment_key_material: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes,
+ /// Get node id based on the provided [`Recipient`].
+ ///
+ /// This method must return the same value each time it is called with a given [`Recipient`]
+ /// parameter.
+ ///
+ /// Errors if the [`Recipient`] variant is not supported by the implementation.
+ #[must_use]
+ pub get_node_id: extern "C" fn (this_arg: *const c_void, recipient: crate::lightning::chain::keysinterface::Recipient) -> crate::c_types::derived::CResult_PublicKeyNoneZ,
+ /// Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
+ /// one is provided. Note that this tweak can be applied to `other_key` instead of our node
+ /// secret, though this is less efficient.
+ ///
+ /// Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
+ /// should be resolved to allow LDK to resume forwarding HTLCs.
+ ///
+ /// Errors if the [`Recipient`] variant is not supported by the implementation.
+ #[must_use]
+ pub ecdh: extern "C" fn (this_arg: *const c_void, recipient: crate::lightning::chain::keysinterface::Recipient, other_key: crate::c_types::PublicKey, tweak: crate::c_types::derived::COption_ScalarZ) -> crate::c_types::derived::CResult_SharedSecretNoneZ,
+ /// Sign an invoice.
+ ///
+ /// By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
+ /// this trait to parse the invoice and make sure they're signing what they expect, rather than
+ /// blindly signing the hash.
+ ///
+ /// The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
+ ///
+ /// The secret key used to sign the invoice is dependent on the [`Recipient`].
+ ///
+ /// Errors if the [`Recipient`] variant is not supported by the implementation.
+ #[must_use]
+ pub sign_invoice: extern "C" fn (this_arg: *const c_void, hrp_bytes: crate::c_types::u8slice, invoice_data: crate::c_types::derived::CVec_U5Z, recipient: crate::lightning::chain::keysinterface::Recipient) -> crate::c_types::derived::CResult_RecoverableSignatureNoneZ,
+ /// Sign a gossip message.
+ ///
+ /// Note that if this fails, LDK may panic and the message will not be broadcast to the network
+ /// or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
+ /// message to be broadcast, as otherwise it may prevent one from receiving funds over the
+ /// corresponding channel.
+ #[must_use]
+ pub sign_gossip_message: extern "C" fn (this_arg: *const c_void, msg: crate::lightning::ln::msgs::UnsignedGossipMessage) -> crate::c_types::derived::CResult_SignatureNoneZ,
+ /// Frees any resources associated with this object given its this_arg pointer.
+ /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
+ pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
+}
+unsafe impl Send for NodeSigner {}
+unsafe impl Sync for NodeSigner {}
+#[no_mangle]
+pub(crate) extern "C" fn NodeSigner_clone_fields(orig: &NodeSigner) -> NodeSigner {
+ NodeSigner {
+ this_arg: orig.this_arg,
+ get_inbound_payment_key_material: Clone::clone(&orig.get_inbound_payment_key_material),
+ get_node_id: Clone::clone(&orig.get_node_id),
+ ecdh: Clone::clone(&orig.ecdh),
+ sign_invoice: Clone::clone(&orig.sign_invoice),
+ sign_gossip_message: Clone::clone(&orig.sign_gossip_message),
+ free: Clone::clone(&orig.free),
+ }
+}
+
+use lightning::chain::keysinterface::NodeSigner as rustNodeSigner;
+impl rustNodeSigner for NodeSigner {
+ fn get_inbound_payment_key_material(&self) -> lightning::chain::keysinterface::KeyMaterial {
+ let mut ret = (self.get_inbound_payment_key_material)(self.this_arg);
+ ::lightning::chain::keysinterface::KeyMaterial(ret.data)
+ }
+ fn get_node_id(&self, mut recipient: lightning::chain::keysinterface::Recipient) -> Result<bitcoin::secp256k1::PublicKey, ()> {
+ let mut ret = (self.get_node_id)(self.this_arg, crate::lightning::chain::keysinterface::Recipient::native_into(recipient));
+ let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
+ local_ret
+ }
+ fn ecdh(&self, mut recipient: lightning::chain::keysinterface::Recipient, mut other_key: &bitcoin::secp256k1::PublicKey, mut tweak: Option<&bitcoin::secp256k1::Scalar>) -> Result<bitcoin::secp256k1::ecdh::SharedSecret, ()> {
+ let mut local_tweak = if tweak.is_none() { crate::c_types::derived::COption_ScalarZ::None } else { crate::c_types::derived::COption_ScalarZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option<Enum> is otherwise un-expressable. */ { crate::c_types::BigEndianScalar::from_rust(&(*tweak.as_ref().unwrap()).clone()) }) };
+ let mut ret = (self.ecdh)(self.this_arg, crate::lightning::chain::keysinterface::Recipient::native_into(recipient), crate::c_types::PublicKey::from_rust(&other_key), local_tweak);
+ let mut local_ret = match ret.result_ok { true => Ok( { ::bitcoin::secp256k1::ecdh::SharedSecret::from_bytes((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).data) }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
+ local_ret
+ }
+ fn sign_invoice(&self, mut hrp_bytes: &[u8], mut invoice_data: &[bitcoin::bech32::u5], mut recipient: lightning::chain::keysinterface::Recipient) -> Result<bitcoin::secp256k1::ecdsa::RecoverableSignature, ()> {
+ let mut local_hrp_bytes = crate::c_types::u8slice::from_slice(hrp_bytes);
+ let mut local_invoice_data_clone = Vec::new(); local_invoice_data_clone.extend_from_slice(invoice_data); let mut invoice_data = local_invoice_data_clone; let mut local_invoice_data = Vec::new(); for mut item in invoice_data.drain(..) { local_invoice_data.push( { item.into() }); };
+ let mut ret = (self.sign_invoice)(self.this_arg, local_hrp_bytes, local_invoice_data.into(), crate::lightning::chain::keysinterface::Recipient::native_into(recipient));
+ let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
+ local_ret
+ }
+ fn sign_gossip_message(&self, mut msg: lightning::ln::msgs::UnsignedGossipMessage) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
+ let mut ret = (self.sign_gossip_message)(self.this_arg, crate::lightning::ln::msgs::UnsignedGossipMessage::native_into(msg));
+ let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }).into_rust() }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })};
+ local_ret
+ }
+}
+
+// We're essentially a pointer already, or at least a set of pointers, so allow us to be used
+// directly as a Deref trait in higher-level structs:
+impl core::ops::Deref for NodeSigner {
+ type Target = Self;
+ fn deref(&self) -> &Self {
+ self
+ }
+}
+/// Calls the free function if one is set
+#[no_mangle]
+pub extern "C" fn NodeSigner_free(this_ptr: NodeSigner) { }
+impl Drop for NodeSigner {
+ fn drop(&mut self) {
+ if let Some(f) = self.free {
+ f(self.this_arg);
+ }
+ }
+}
+/// A trait that can return signer instances for individual channels.
+#[repr(C)]
+pub struct SignerProvider {
+ /// An opaque pointer which is passed to your function implementations as an argument.
+ /// This has no meaning in the LDK, and can be NULL or any other value.
+ pub this_arg: *mut c_void,
+ /// Generates a unique `channel_keys_id` that can be used to obtain a [`Self::Signer`] through
+ /// [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow
+ /// implementations of [`SignerProvider`] to maintain a mapping between itself and the generated
+ /// `channel_keys_id`.
+ ///
+ /// This method must return a different value each time it is called.
+ #[must_use]
+ pub generate_channel_keys_id: extern "C" fn (this_arg: *const c_void, inbound: bool, channel_value_satoshis: u64, user_channel_id: crate::c_types::U128) -> crate::c_types::ThirtyTwoBytes,
+ /// Derives the private key material backing a `Signer`.
+ ///
+ /// To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
+ /// [`SignerProvider::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
+ /// re-derived from its `channel_keys_id`, which can be obtained through its trait method
+ /// [`ChannelSigner::channel_keys_id`].
+ #[must_use]
+ pub derive_channel_signer: extern "C" fn (this_arg: *const c_void, channel_value_satoshis: u64, channel_keys_id: crate::c_types::ThirtyTwoBytes) -> crate::lightning::chain::keysinterface::WriteableEcdsaChannelSigner,
+ /// Reads a [`Signer`] for this [`SignerProvider`] from the given input stream.
+ /// This is only called during deserialization of other objects which contain
+ /// [`WriteableEcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
+ /// The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
+ /// contain no versioning scheme. You may wish to include your own version prefix and ensure
+ /// you've read all of the provided bytes to ensure no corruption occurred.
+ ///
+ /// This method is slowly being phased out -- it will only be called when reading objects
+ /// written by LDK versions prior to 0.0.113.
+ ///
+ /// [`Signer`]: Self::Signer
+ /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
+ /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
+ #[must_use]
+ pub read_chan_signer: extern "C" fn (this_arg: *const c_void, reader: crate::c_types::u8slice) -> crate::c_types::derived::CResult_WriteableEcdsaChannelSignerDecodeErrorZ,
+ /// Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
+ ///
+ /// This method should return a different value each time it is called, to avoid linking
+ /// on-chain funds across channels as controlled to the same user.
+ #[must_use]
+ pub get_destination_script: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,
+ /// Get a script pubkey which we will send funds to when closing a channel.
+ ///
+ /// This method should return a different value each time it is called, to avoid linking
+ /// on-chain funds across channels as controlled to the same user.
+ #[must_use]
+ pub get_shutdown_scriptpubkey: extern "C" fn (this_arg: *const c_void) -> crate::lightning::ln::script::ShutdownScript,
+ /// Frees any resources associated with this object given its this_arg pointer.
+ /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
+ pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
+}
+unsafe impl Send for SignerProvider {}
+unsafe impl Sync for SignerProvider {}
+#[no_mangle]
+pub(crate) extern "C" fn SignerProvider_clone_fields(orig: &SignerProvider) -> SignerProvider {
+ SignerProvider {
+ this_arg: orig.this_arg,
+ generate_channel_keys_id: Clone::clone(&orig.generate_channel_keys_id),
+ derive_channel_signer: Clone::clone(&orig.derive_channel_signer),
+ read_chan_signer: Clone::clone(&orig.read_chan_signer),
+ get_destination_script: Clone::clone(&orig.get_destination_script),
+ get_shutdown_scriptpubkey: Clone::clone(&orig.get_shutdown_scriptpubkey),
+ free: Clone::clone(&orig.free),
+ }
+}
+
+use lightning::chain::keysinterface::SignerProvider as rustSignerProvider;
+impl rustSignerProvider for SignerProvider {
+ type Signer = crate::lightning::chain::keysinterface::WriteableEcdsaChannelSigner;
+ fn generate_channel_keys_id(&self, mut inbound: bool, mut channel_value_satoshis: u64, mut user_channel_id: u128) -> [u8; 32] {
+ let mut ret = (self.generate_channel_keys_id)(self.this_arg, inbound, channel_value_satoshis, user_channel_id.into());
+ ret.data
+ }
+ fn derive_channel_signer(&self, mut channel_value_satoshis: u64, mut channel_keys_id: [u8; 32]) -> crate::lightning::chain::keysinterface::WriteableEcdsaChannelSigner {
+ let mut ret = (self.derive_channel_signer)(self.this_arg, channel_value_satoshis, crate::c_types::ThirtyTwoBytes { data: channel_keys_id });
+ ret
+ }
+ fn read_chan_signer(&self, mut reader: &[u8]) -> Result<crate::lightning::chain::keysinterface::WriteableEcdsaChannelSigner, lightning::ln::msgs::DecodeError> {
+ let mut local_reader = crate::c_types::u8slice::from_slice(reader);
+ let mut ret = (self.read_chan_signer)(self.this_arg, local_reader);
+ let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }) }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).into_native() })};
+ local_ret
+ }
+ fn get_destination_script(&self) -> bitcoin::blockdata::script::Script {
+ let mut ret = (self.get_destination_script)(self.this_arg);
+ ::bitcoin::blockdata::script::Script::from(ret.into_rust())
+ }
+ fn get_shutdown_scriptpubkey(&self) -> lightning::ln::script::ShutdownScript {
+ let mut ret = (self.get_shutdown_scriptpubkey)(self.this_arg);
+ *unsafe { Box::from_raw(ret.take_inner()) }
+ }
+}
+
+// We're essentially a pointer already, or at least a set of pointers, so allow us to be used
+// directly as a Deref trait in higher-level structs:
+impl core::ops::Deref for SignerProvider {
+ type Target = Self;
+ fn deref(&self) -> &Self {
+ self
+ }
+}
+/// Calls the free function if one is set
+#[no_mangle]
+pub extern "C" fn SignerProvider_free(this_ptr: SignerProvider) { }
+impl Drop for SignerProvider {
+ fn drop(&mut self) {
+ if let Some(f) = self.free {
+ f(self.this_arg);
+ }
+ }
+}
+
+use lightning::chain::keysinterface::InMemorySigner as nativeInMemorySignerImport;
+pub(crate) type nativeInMemorySigner = nativeInMemorySignerImport;
+
+/// A simple implementation of [`WriteableEcdsaChannelSigner`] that just keeps the private keys in memory.
+///
+/// This implementation performs no policy checks and is insufficient by itself as
+/// a secure external signer.
+#[must_use]
+#[repr(C)]
+pub struct InMemorySigner {
+ /// A pointer to the opaque Rust object.
+
+ /// Nearly everywhere, inner must be non-null, however in places where
+ /// the Rust equivalent takes an Option, it may be set to null to indicate None.
+ pub inner: *mut nativeInMemorySigner,
+ /// Indicates that this is the only struct which contains the same pointer.
+
+ /// Rust functions which take ownership of an object provided via an argument require
+ /// this to be true and invalidate the object pointed to by inner.
+ pub is_owned: bool,
+}
+
+impl Drop for InMemorySigner {