From e9d819dce891f649cae57b870e4ae01c57bc2e9b Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 12 Feb 2021 18:58:59 -0500 Subject: [PATCH] Update auto-generated bindings --- lightning-c-bindings/include/lightning.h | 68 +++++----- lightning-c-bindings/include/lightningpp.hpp | 63 ++++----- lightning-c-bindings/src/c_types/derived.rs | 35 ----- .../src/chain/keysinterface.rs | 126 ++++++++++-------- 4 files changed, 131 insertions(+), 161 deletions(-) diff --git a/lightning-c-bindings/include/lightning.h b/lightning-c-bindings/include/lightning.h index 2025fdf4f..d8299b407 100644 --- a/lightning-c-bindings/include/lightning.h +++ b/lightning-c-bindings/include/lightning.h @@ -241,10 +241,13 @@ typedef struct LDKPublicKey { uint8_t compressed_form[33]; } LDKPublicKey; -typedef struct LDKC2Tuple_u64u64Z { - uint64_t a; - uint64_t b; -} LDKC2Tuple_u64u64Z; +/** + * Arbitrary 32 bytes, which could represent one of a few different things. You probably want to + * look up the corresponding function in rust-lightning's docs. + */ +typedef struct LDKThirtyTwoBytes { + uint8_t data[32]; +} LDKThirtyTwoBytes; /** * When on-chain outputs are created by rust-lightning (which our counterparty is not able to @@ -255,9 +258,9 @@ typedef struct LDKC2Tuple_u64u64Z { */ typedef enum LDKSpendableOutputDescriptor_Tag { /** - * An output to a script which was provided via KeysInterface, thus you should already know - * how to spend it. No keys are provided as rust-lightning was never given any keys - only the - * script_pubkey as it appears in the output. + * An output to a script which was provided via KeysInterface directly, either from + * `get_destination_script()` or `get_shutdown_pubkey()`, thus you should already know how to + * spend it. No secret keys are provided as rust-lightning was never given any key. * These may include outputs from a transaction punishing our counterparty or claiming an HTLC * on-chain using the payment preimage or after it has timed out. */ @@ -319,14 +322,16 @@ typedef struct LDKSpendableOutputDescriptor_LDKDynamicOutputP2WSH_Body { struct LDKPublicKey per_commitment_point; uint16_t to_self_delay; struct LDKTxOut output; - struct LDKC2Tuple_u64u64Z key_derivation_params; struct LDKPublicKey revocation_pubkey; + struct LDKThirtyTwoBytes channel_keys_id; + uint64_t channel_value_satoshis; } LDKSpendableOutputDescriptor_LDKDynamicOutputP2WSH_Body; typedef struct LDKSpendableOutputDescriptor_LDKStaticOutputCounterpartyPayment_Body { struct LDKOutPoint outpoint; struct LDKTxOut output; - struct LDKC2Tuple_u64u64Z key_derivation_params; + struct LDKThirtyTwoBytes channel_keys_id; + uint64_t channel_value_satoshis; } LDKSpendableOutputDescriptor_LDKStaticOutputCounterpartyPayment_Body; typedef struct MUST_USE_STRUCT LDKSpendableOutputDescriptor { @@ -889,14 +894,6 @@ typedef struct LDKCVec_MessageSendEventZ { uintptr_t datalen; } LDKCVec_MessageSendEventZ; -/** - * Arbitrary 32 bytes, which could represent one of a few different things. You probably want to - * look up the corresponding function in rust-lightning's docs. - */ -typedef struct LDKThirtyTwoBytes { - uint8_t data[32]; -} LDKThirtyTwoBytes; - /** * An Event which you should probably take some action in response to. * @@ -1349,11 +1346,11 @@ typedef struct LDKChannelKeys { */ void (*set_pubkeys)(const struct LDKChannelKeys*NONNULL_PTR ); /** - * Gets arbitrary identifiers describing the set of keys which are provided back to you in - * some SpendableOutputDescriptor types. These should be sufficient to identify this + * Gets an arbitrary identifier describing the set of keys which are provided back to you in + * some SpendableOutputDescriptor types. This should be sufficient to identify this * ChannelKeys object uniquely and lookup or re-derive its keys. */ - struct LDKC2Tuple_u64u64Z (*key_derivation_params)(const void *this_arg); + struct LDKThirtyTwoBytes (*channel_keys_id)(const void *this_arg); /** * Create a signature for a counterparty's commitment transaction and associated HTLC transactions. * @@ -1849,26 +1846,39 @@ typedef struct LDKu8slice { typedef struct LDKKeysInterface { void *this_arg; /** - * Get node secret key (aka node_id or network_key) + * Get node secret key (aka node_id or network_key). + * + * This method must return the same value each time it is called. */ struct LDKSecretKey (*get_node_secret)(const void *this_arg); /** - * Get destination redeemScript to encumber static protocol exit points. + * 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. */ struct LDKCVec_u8Z (*get_destination_script)(const void *this_arg); /** - * Get shutdown_pubkey to use as PublicKey at channel closure + * Get a public key which we will send funds to (in the form of a P2WPKH output) 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. */ struct LDKPublicKey (*get_shutdown_pubkey)(const void *this_arg); /** * Get a new set of ChannelKeys for per-channel secrets. These MUST be unique even if you * restarted with some stale data! + * + * This method must return a different value each time it is called. */ struct LDKChannelKeys (*get_channel_keys)(const void *this_arg, bool inbound, uint64_t channel_value_satoshis); /** * Gets a unique, cryptographically-secure, random 32 byte value. This is used for encrypting * onion packets and for temporary channel IDs. There is no requirement that these be * persisted anywhere, though they must be unique across restarts. + * + * This method must return a different value each time it is called. */ struct LDKThirtyTwoBytes (*get_secure_random_bytes)(const void *this_arg); /** @@ -3548,12 +3558,6 @@ struct LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ CResult_C2Tuple_B void CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(struct LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ _res); -struct LDKC2Tuple_u64u64Z C2Tuple_u64u64Z_clone(const struct LDKC2Tuple_u64u64Z *NONNULL_PTR orig); - -struct LDKC2Tuple_u64u64Z C2Tuple_u64u64Z_new(uint64_t a, uint64_t b); - -void C2Tuple_u64u64Z_free(struct LDKC2Tuple_u64u64Z _res); - struct LDKCResult_SpendableOutputDescriptorDecodeErrorZ CResult_SpendableOutputDescriptorDecodeErrorZ_ok(struct LDKSpendableOutputDescriptor o); struct LDKCResult_SpendableOutputDescriptorDecodeErrorZ CResult_SpendableOutputDescriptorDecodeErrorZ_err(struct LDKDecodeError e); @@ -4686,7 +4690,7 @@ void InMemoryChannelKeys_set_commitment_seed(struct LDKInMemoryChannelKeys *NONN /** * Create a new InMemoryChannelKeys */ -MUST_USE_RES struct LDKInMemoryChannelKeys InMemoryChannelKeys_new(struct LDKSecretKey funding_key, struct LDKSecretKey revocation_base_key, struct LDKSecretKey payment_key, struct LDKSecretKey delayed_payment_base_key, struct LDKSecretKey htlc_base_key, struct LDKThirtyTwoBytes commitment_seed, uint64_t channel_value_satoshis, struct LDKC2Tuple_u64u64Z key_derivation_params); +MUST_USE_RES struct LDKInMemoryChannelKeys InMemoryChannelKeys_new(struct LDKSecretKey funding_key, struct LDKSecretKey revocation_base_key, struct LDKSecretKey payment_key, struct LDKSecretKey delayed_payment_base_key, struct LDKSecretKey htlc_base_key, struct LDKThirtyTwoBytes commitment_seed, uint64_t channel_value_satoshis, struct LDKThirtyTwoBytes channel_keys_id); /** * Counterparty pubkeys. @@ -4765,10 +4769,10 @@ MUST_USE_RES struct LDKKeysManager KeysManager_new(const uint8_t (*seed)[32], en * Derive an old set of ChannelKeys for per-channel secrets based on a key derivation * parameters. * Key derivation parameters are accessible through a per-channel secrets - * ChannelKeys::key_derivation_params and is provided inside DynamicOuputP2WSH in case of + * ChannelKeys::channel_keys_id and is provided inside DynamicOuputP2WSH in case of * onchain output detection for which a corresponding delayed_payment_key must be derived. */ -MUST_USE_RES struct LDKInMemoryChannelKeys KeysManager_derive_channel_keys(const struct LDKKeysManager *NONNULL_PTR this_arg, uint64_t channel_value_satoshis, uint64_t params_1, uint64_t params_2); +MUST_USE_RES struct LDKInMemoryChannelKeys KeysManager_derive_channel_keys(const struct LDKKeysManager *NONNULL_PTR this_arg, uint64_t channel_value_satoshis, const uint8_t (*params)[32]); struct LDKKeysInterface KeysManager_as_KeysInterface(const struct LDKKeysManager *NONNULL_PTR this_arg); diff --git a/lightning-c-bindings/include/lightningpp.hpp b/lightning-c-bindings/include/lightningpp.hpp index 4e4fbb46a..2d6473086 100644 --- a/lightning-c-bindings/include/lightningpp.hpp +++ b/lightning-c-bindings/include/lightningpp.hpp @@ -2096,21 +2096,6 @@ public: const LDKCVec_PublicKeyZ* operator &() const { return &self; } const LDKCVec_PublicKeyZ* operator ->() const { return &self; } }; -class C2Tuple_u64u64Z { -private: - LDKC2Tuple_u64u64Z self; -public: - C2Tuple_u64u64Z(const C2Tuple_u64u64Z&) = delete; - C2Tuple_u64u64Z(C2Tuple_u64u64Z&& o) : self(o.self) { memset(&o, 0, sizeof(C2Tuple_u64u64Z)); } - C2Tuple_u64u64Z(LDKC2Tuple_u64u64Z&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKC2Tuple_u64u64Z)); } - operator LDKC2Tuple_u64u64Z() && { LDKC2Tuple_u64u64Z res = self; memset(&self, 0, sizeof(LDKC2Tuple_u64u64Z)); return res; } - ~C2Tuple_u64u64Z() { C2Tuple_u64u64Z_free(self); } - C2Tuple_u64u64Z& operator=(C2Tuple_u64u64Z&& o) { C2Tuple_u64u64Z_free(self); self = o.self; memset(&o, 0, sizeof(C2Tuple_u64u64Z)); return *this; } - LDKC2Tuple_u64u64Z* operator &() { return &self; } - LDKC2Tuple_u64u64Z* operator ->() { return &self; } - const LDKC2Tuple_u64u64Z* operator &() const { return &self; } - const LDKC2Tuple_u64u64Z* operator ->() const { return &self; } -}; class C2Tuple_u32TxOutZ { private: LDKC2Tuple_u32TxOutZ self; @@ -2576,20 +2561,20 @@ public: const LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ* operator &() const { return &self; } const LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ* operator ->() const { return &self; } }; -class CVec_UpdateFailHTLCZ { +class CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ { private: - LDKCVec_UpdateFailHTLCZ self; + LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ self; public: - CVec_UpdateFailHTLCZ(const CVec_UpdateFailHTLCZ&) = delete; - CVec_UpdateFailHTLCZ(CVec_UpdateFailHTLCZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_UpdateFailHTLCZ)); } - CVec_UpdateFailHTLCZ(LDKCVec_UpdateFailHTLCZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_UpdateFailHTLCZ)); } - operator LDKCVec_UpdateFailHTLCZ() && { LDKCVec_UpdateFailHTLCZ res = self; memset(&self, 0, sizeof(LDKCVec_UpdateFailHTLCZ)); return res; } - ~CVec_UpdateFailHTLCZ() { CVec_UpdateFailHTLCZ_free(self); } - CVec_UpdateFailHTLCZ& operator=(CVec_UpdateFailHTLCZ&& o) { CVec_UpdateFailHTLCZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_UpdateFailHTLCZ)); return *this; } - LDKCVec_UpdateFailHTLCZ* operator &() { return &self; } - LDKCVec_UpdateFailHTLCZ* operator ->() { return &self; } - const LDKCVec_UpdateFailHTLCZ* operator &() const { return &self; } - const LDKCVec_UpdateFailHTLCZ* operator ->() const { return &self; } + CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ(const CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&) = delete; + CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); } + CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); } + operator LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ() && { LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); return res; } + ~CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ() { CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(self); } + CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ& operator=(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&& o) { CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); return *this; } + LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator &() { return &self; } + LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator ->() { return &self; } + const LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator &() const { return &self; } + const LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator ->() const { return &self; } }; class C2Tuple_OutPointScriptZ { private: @@ -2621,20 +2606,20 @@ public: const LDKCResult_InMemoryChannelKeysDecodeErrorZ* operator &() const { return &self; } const LDKCResult_InMemoryChannelKeysDecodeErrorZ* operator ->() const { return &self; } }; -class CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ { +class CVec_UpdateFailHTLCZ { private: - LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ self; + LDKCVec_UpdateFailHTLCZ self; public: - CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ(const CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&) = delete; - CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&& o) : self(o.self) { memset(&o, 0, sizeof(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); } - CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); } - operator LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ() && { LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ res = self; memset(&self, 0, sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); return res; } - ~CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ() { CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(self); } - CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ& operator=(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ&& o) { CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(self); self = o.self; memset(&o, 0, sizeof(CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ)); return *this; } - LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator &() { return &self; } - LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator ->() { return &self; } - const LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator &() const { return &self; } - const LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* operator ->() const { return &self; } + CVec_UpdateFailHTLCZ(const CVec_UpdateFailHTLCZ&) = delete; + CVec_UpdateFailHTLCZ(CVec_UpdateFailHTLCZ&& o) : self(o.self) { memset(&o, 0, sizeof(CVec_UpdateFailHTLCZ)); } + CVec_UpdateFailHTLCZ(LDKCVec_UpdateFailHTLCZ&& m_self) : self(m_self) { memset(&m_self, 0, sizeof(LDKCVec_UpdateFailHTLCZ)); } + operator LDKCVec_UpdateFailHTLCZ() && { LDKCVec_UpdateFailHTLCZ res = self; memset(&self, 0, sizeof(LDKCVec_UpdateFailHTLCZ)); return res; } + ~CVec_UpdateFailHTLCZ() { CVec_UpdateFailHTLCZ_free(self); } + CVec_UpdateFailHTLCZ& operator=(CVec_UpdateFailHTLCZ&& o) { CVec_UpdateFailHTLCZ_free(self); self = o.self; memset(&o, 0, sizeof(CVec_UpdateFailHTLCZ)); return *this; } + LDKCVec_UpdateFailHTLCZ* operator &() { return &self; } + LDKCVec_UpdateFailHTLCZ* operator ->() { return &self; } + const LDKCVec_UpdateFailHTLCZ* operator &() const { return &self; } + const LDKCVec_UpdateFailHTLCZ* operator ->() const { return &self; } }; class CResult_RouteDecodeErrorZ { private: diff --git a/lightning-c-bindings/src/c_types/derived.rs b/lightning-c-bindings/src/c_types/derived.rs index 6f703a5b1..d30163e60 100644 --- a/lightning-c-bindings/src/c_types/derived.rs +++ b/lightning-c-bindings/src/c_types/derived.rs @@ -711,41 +711,6 @@ impl From for C2Tuple_u64u64Z { - fn from (tup: (u64, u64)) -> Self { - Self { - a: tup.0, - b: tup.1, - } - } -} -impl C2Tuple_u64u64Z { - #[allow(unused)] pub(crate) fn to_rust(mut self) -> (u64, u64) { - (self.a, self.b) - } -} -impl Clone for C2Tuple_u64u64Z { - fn clone(&self) -> Self { - Self { - a: self.a.clone(), - b: self.b.clone(), - } - } -} -#[no_mangle] -pub extern "C" fn C2Tuple_u64u64Z_clone(orig: &C2Tuple_u64u64Z) -> C2Tuple_u64u64Z { orig.clone() } -#[no_mangle] -pub extern "C" fn C2Tuple_u64u64Z_new(a: u64, b: u64) -> C2Tuple_u64u64Z { - C2Tuple_u64u64Z { a, b, } -} - -#[no_mangle] -pub extern "C" fn C2Tuple_u64u64Z_free(_res: C2Tuple_u64u64Z) { } -#[repr(C)] pub union CResult_SpendableOutputDescriptorDecodeErrorZPtr { pub result: *mut crate::chain::keysinterface::SpendableOutputDescriptor, pub err: *mut crate::ln::msgs::DecodeError, diff --git a/lightning-c-bindings/src/chain/keysinterface.rs b/lightning-c-bindings/src/chain/keysinterface.rs index cef2cdd4d..37758e8bc 100644 --- a/lightning-c-bindings/src/chain/keysinterface.rs +++ b/lightning-c-bindings/src/chain/keysinterface.rs @@ -15,9 +15,9 @@ use crate::c_types::*; #[derive(Clone)] #[repr(C)] pub enum SpendableOutputDescriptor { - /// An output to a script which was provided via KeysInterface, thus you should already know - /// how to spend it. No keys are provided as rust-lightning was never given any keys - only the - /// script_pubkey as it appears in the output. + /// An output to a script which was provided via KeysInterface directly, either from + /// `get_destination_script()` or `get_shutdown_pubkey()`, thus you should already know how to + /// spend it. No secret keys are provided as rust-lightning was never given any key. /// These may include outputs from a transaction punishing our counterparty or claiming an HTLC /// on-chain using the payment preimage or after it has timed out. StaticOutput { @@ -57,8 +57,9 @@ pub enum SpendableOutputDescriptor { per_commitment_point: crate::c_types::PublicKey, to_self_delay: u16, output: crate::c_types::TxOut, - key_derivation_params: crate::c_types::derived::C2Tuple_u64u64Z, revocation_pubkey: crate::c_types::PublicKey, + channel_keys_id: crate::c_types::ThirtyTwoBytes, + channel_value_satoshis: u64, }, /// An output to a P2WPKH, spendable exclusively by our payment key (ie the private key which /// corresponds to the public key in ChannelKeys::pubkeys().payment_point). @@ -70,7 +71,8 @@ pub enum SpendableOutputDescriptor { StaticOutputCounterpartyPayment { outpoint: crate::chain::transaction::OutPoint, output: crate::c_types::TxOut, - key_derivation_params: crate::c_types::derived::C2Tuple_u64u64Z, + channel_keys_id: crate::c_types::ThirtyTwoBytes, + channel_value_satoshis: u64, }, } use lightning::chain::keysinterface::SpendableOutputDescriptor as nativeSpendableOutputDescriptor; @@ -86,32 +88,34 @@ impl SpendableOutputDescriptor { output: output_nonref.into_rust(), } }, - SpendableOutputDescriptor::DynamicOutputP2WSH {ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref key_derivation_params, ref revocation_pubkey, } => { + SpendableOutputDescriptor::DynamicOutputP2WSH {ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref revocation_pubkey, ref channel_keys_id, ref channel_value_satoshis, } => { let mut outpoint_nonref = (*outpoint).clone(); let mut per_commitment_point_nonref = (*per_commitment_point).clone(); let mut to_self_delay_nonref = (*to_self_delay).clone(); let mut output_nonref = (*output).clone(); - let mut key_derivation_params_nonref = (*key_derivation_params).clone(); - let (mut orig_key_derivation_params_nonref_0, mut orig_key_derivation_params_nonref_1) = key_derivation_params_nonref.to_rust(); let mut local_key_derivation_params_nonref = (orig_key_derivation_params_nonref_0, orig_key_derivation_params_nonref_1); let mut revocation_pubkey_nonref = (*revocation_pubkey).clone(); + let mut channel_keys_id_nonref = (*channel_keys_id).clone(); + let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone(); nativeSpendableOutputDescriptor::DynamicOutputP2WSH { outpoint: *unsafe { Box::from_raw(outpoint_nonref.take_inner()) }, per_commitment_point: per_commitment_point_nonref.into_rust(), to_self_delay: to_self_delay_nonref, output: output_nonref.into_rust(), - key_derivation_params: local_key_derivation_params_nonref, revocation_pubkey: revocation_pubkey_nonref.into_rust(), + channel_keys_id: channel_keys_id_nonref.data, + channel_value_satoshis: channel_value_satoshis_nonref, } }, - SpendableOutputDescriptor::StaticOutputCounterpartyPayment {ref outpoint, ref output, ref key_derivation_params, } => { + SpendableOutputDescriptor::StaticOutputCounterpartyPayment {ref outpoint, ref output, ref channel_keys_id, ref channel_value_satoshis, } => { let mut outpoint_nonref = (*outpoint).clone(); let mut output_nonref = (*output).clone(); - let mut key_derivation_params_nonref = (*key_derivation_params).clone(); - let (mut orig_key_derivation_params_nonref_0, mut orig_key_derivation_params_nonref_1) = key_derivation_params_nonref.to_rust(); let mut local_key_derivation_params_nonref = (orig_key_derivation_params_nonref_0, orig_key_derivation_params_nonref_1); + let mut channel_keys_id_nonref = (*channel_keys_id).clone(); + let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone(); nativeSpendableOutputDescriptor::StaticOutputCounterpartyPayment { outpoint: *unsafe { Box::from_raw(outpoint_nonref.take_inner()) }, output: output_nonref.into_rust(), - key_derivation_params: local_key_derivation_params_nonref, + channel_keys_id: channel_keys_id_nonref.data, + channel_value_satoshis: channel_value_satoshis_nonref, } }, } @@ -125,23 +129,23 @@ impl SpendableOutputDescriptor { output: output.into_rust(), } }, - SpendableOutputDescriptor::DynamicOutputP2WSH {mut outpoint, mut per_commitment_point, mut to_self_delay, mut output, mut key_derivation_params, mut revocation_pubkey, } => { - let (mut orig_key_derivation_params_0, mut orig_key_derivation_params_1) = key_derivation_params.to_rust(); let mut local_key_derivation_params = (orig_key_derivation_params_0, orig_key_derivation_params_1); + SpendableOutputDescriptor::DynamicOutputP2WSH {mut outpoint, mut per_commitment_point, mut to_self_delay, mut output, mut revocation_pubkey, mut channel_keys_id, mut channel_value_satoshis, } => { nativeSpendableOutputDescriptor::DynamicOutputP2WSH { outpoint: *unsafe { Box::from_raw(outpoint.take_inner()) }, per_commitment_point: per_commitment_point.into_rust(), to_self_delay: to_self_delay, output: output.into_rust(), - key_derivation_params: local_key_derivation_params, revocation_pubkey: revocation_pubkey.into_rust(), + channel_keys_id: channel_keys_id.data, + channel_value_satoshis: channel_value_satoshis, } }, - SpendableOutputDescriptor::StaticOutputCounterpartyPayment {mut outpoint, mut output, mut key_derivation_params, } => { - let (mut orig_key_derivation_params_0, mut orig_key_derivation_params_1) = key_derivation_params.to_rust(); let mut local_key_derivation_params = (orig_key_derivation_params_0, orig_key_derivation_params_1); + SpendableOutputDescriptor::StaticOutputCounterpartyPayment {mut outpoint, mut output, mut channel_keys_id, mut channel_value_satoshis, } => { nativeSpendableOutputDescriptor::StaticOutputCounterpartyPayment { outpoint: *unsafe { Box::from_raw(outpoint.take_inner()) }, output: output.into_rust(), - key_derivation_params: local_key_derivation_params, + channel_keys_id: channel_keys_id.data, + channel_value_satoshis: channel_value_satoshis, } }, } @@ -157,32 +161,34 @@ impl SpendableOutputDescriptor { output: crate::c_types::TxOut::from_rust(output_nonref), } }, - nativeSpendableOutputDescriptor::DynamicOutputP2WSH {ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref key_derivation_params, ref revocation_pubkey, } => { + nativeSpendableOutputDescriptor::DynamicOutputP2WSH {ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref revocation_pubkey, ref channel_keys_id, ref channel_value_satoshis, } => { let mut outpoint_nonref = (*outpoint).clone(); let mut per_commitment_point_nonref = (*per_commitment_point).clone(); let mut to_self_delay_nonref = (*to_self_delay).clone(); let mut output_nonref = (*output).clone(); - let mut key_derivation_params_nonref = (*key_derivation_params).clone(); - let (mut orig_key_derivation_params_nonref_0, mut orig_key_derivation_params_nonref_1) = key_derivation_params_nonref; let mut local_key_derivation_params_nonref = (orig_key_derivation_params_nonref_0, orig_key_derivation_params_nonref_1).into(); let mut revocation_pubkey_nonref = (*revocation_pubkey).clone(); + let mut channel_keys_id_nonref = (*channel_keys_id).clone(); + let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone(); SpendableOutputDescriptor::DynamicOutputP2WSH { outpoint: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(outpoint_nonref)), is_owned: true }, per_commitment_point: crate::c_types::PublicKey::from_rust(&per_commitment_point_nonref), to_self_delay: to_self_delay_nonref, output: crate::c_types::TxOut::from_rust(output_nonref), - key_derivation_params: local_key_derivation_params_nonref, revocation_pubkey: crate::c_types::PublicKey::from_rust(&revocation_pubkey_nonref), + channel_keys_id: crate::c_types::ThirtyTwoBytes { data: channel_keys_id_nonref }, + channel_value_satoshis: channel_value_satoshis_nonref, } }, - nativeSpendableOutputDescriptor::StaticOutputCounterpartyPayment {ref outpoint, ref output, ref key_derivation_params, } => { + nativeSpendableOutputDescriptor::StaticOutputCounterpartyPayment {ref outpoint, ref output, ref channel_keys_id, ref channel_value_satoshis, } => { let mut outpoint_nonref = (*outpoint).clone(); let mut output_nonref = (*output).clone(); - let mut key_derivation_params_nonref = (*key_derivation_params).clone(); - let (mut orig_key_derivation_params_nonref_0, mut orig_key_derivation_params_nonref_1) = key_derivation_params_nonref; let mut local_key_derivation_params_nonref = (orig_key_derivation_params_nonref_0, orig_key_derivation_params_nonref_1).into(); + let mut channel_keys_id_nonref = (*channel_keys_id).clone(); + let mut channel_value_satoshis_nonref = (*channel_value_satoshis).clone(); SpendableOutputDescriptor::StaticOutputCounterpartyPayment { outpoint: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(outpoint_nonref)), is_owned: true }, output: crate::c_types::TxOut::from_rust(output_nonref), - key_derivation_params: local_key_derivation_params_nonref, + channel_keys_id: crate::c_types::ThirtyTwoBytes { data: channel_keys_id_nonref }, + channel_value_satoshis: channel_value_satoshis_nonref, } }, } @@ -196,23 +202,23 @@ impl SpendableOutputDescriptor { output: crate::c_types::TxOut::from_rust(output), } }, - nativeSpendableOutputDescriptor::DynamicOutputP2WSH {mut outpoint, mut per_commitment_point, mut to_self_delay, mut output, mut key_derivation_params, mut revocation_pubkey, } => { - let (mut orig_key_derivation_params_0, mut orig_key_derivation_params_1) = key_derivation_params; let mut local_key_derivation_params = (orig_key_derivation_params_0, orig_key_derivation_params_1).into(); + nativeSpendableOutputDescriptor::DynamicOutputP2WSH {mut outpoint, mut per_commitment_point, mut to_self_delay, mut output, mut revocation_pubkey, mut channel_keys_id, mut channel_value_satoshis, } => { SpendableOutputDescriptor::DynamicOutputP2WSH { outpoint: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(outpoint)), is_owned: true }, per_commitment_point: crate::c_types::PublicKey::from_rust(&per_commitment_point), to_self_delay: to_self_delay, output: crate::c_types::TxOut::from_rust(output), - key_derivation_params: local_key_derivation_params, revocation_pubkey: crate::c_types::PublicKey::from_rust(&revocation_pubkey), + channel_keys_id: crate::c_types::ThirtyTwoBytes { data: channel_keys_id }, + channel_value_satoshis: channel_value_satoshis, } }, - nativeSpendableOutputDescriptor::StaticOutputCounterpartyPayment {mut outpoint, mut output, mut key_derivation_params, } => { - let (mut orig_key_derivation_params_0, mut orig_key_derivation_params_1) = key_derivation_params; let mut local_key_derivation_params = (orig_key_derivation_params_0, orig_key_derivation_params_1).into(); + nativeSpendableOutputDescriptor::StaticOutputCounterpartyPayment {mut outpoint, mut output, mut channel_keys_id, mut channel_value_satoshis, } => { SpendableOutputDescriptor::StaticOutputCounterpartyPayment { outpoint: crate::chain::transaction::OutPoint { inner: Box::into_raw(Box::new(outpoint)), is_owned: true }, output: crate::c_types::TxOut::from_rust(output), - key_derivation_params: local_key_derivation_params, + channel_keys_id: crate::c_types::ThirtyTwoBytes { data: channel_keys_id }, + channel_value_satoshis: channel_value_satoshis, } }, } @@ -281,11 +287,11 @@ pub struct ChannelKeys { /// Note that this takes a pointer to this object, not the this_ptr like other methods do /// This function pointer may be NULL if pubkeys is filled in when this object is created and never needs updating. pub set_pubkeys: Option, - /// Gets arbitrary identifiers describing the set of keys which are provided back to you in - /// some SpendableOutputDescriptor types. These should be sufficient to identify this + /// Gets an arbitrary identifier describing the set of keys which are provided back to you in + /// some SpendableOutputDescriptor types. This should be sufficient to identify this /// ChannelKeys object uniquely and lookup or re-derive its keys. #[must_use] - pub key_derivation_params: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::C2Tuple_u64u64Z, + pub channel_keys_id: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes, /// Create a signature for a counterparty's commitment transaction and associated HTLC transactions. /// /// Note that if signing fails or is rejected, the channel will be force-closed. @@ -381,7 +387,7 @@ pub extern "C" fn ChannelKeys_clone(orig: &ChannelKeys) -> ChannelKeys { release_commitment_secret: orig.release_commitment_secret.clone(), pubkeys: orig.pubkeys.clone(), set_pubkeys: orig.set_pubkeys.clone(), - key_derivation_params: orig.key_derivation_params.clone(), + channel_keys_id: orig.channel_keys_id.clone(), sign_counterparty_commitment: orig.sign_counterparty_commitment.clone(), sign_holder_commitment_and_htlcs: orig.sign_holder_commitment_and_htlcs.clone(), sign_justice_transaction: orig.sign_justice_transaction.clone(), @@ -422,10 +428,9 @@ impl rustChannelKeys for ChannelKeys { } unsafe { &*self.pubkeys.inner } } - fn key_derivation_params(&self) -> (u64, u64) { - let mut ret = (self.key_derivation_params)(self.this_arg); - let (mut orig_ret_0, mut orig_ret_1) = ret.to_rust(); let mut local_ret = (orig_ret_0, orig_ret_1); - local_ret + fn channel_keys_id(&self) -> [u8; 32] { + let mut ret = (self.channel_keys_id)(self.this_arg); + ret.data } fn sign_counterparty_commitment(&self, commitment_tx: &lightning::ln::chan_utils::CommitmentTransaction, _secp_ctx: &bitcoin::secp256k1::Secp256k1) -> Result<(bitcoin::secp256k1::Signature, Vec), ()> { let mut ret = (self.sign_counterparty_commitment)(self.this_arg, &crate::ln::chan_utils::CommitmentTransaction { inner: unsafe { (commitment_tx as *const _) as *mut _ }, is_owned: false }); @@ -488,22 +493,35 @@ impl Drop for ChannelKeys { #[repr(C)] pub struct KeysInterface { pub this_arg: *mut c_void, - /// Get node secret key (aka node_id or network_key) + /// Get node secret key (aka node_id or network_key). + /// + /// This method must return the same value each time it is called. #[must_use] pub get_node_secret: extern "C" fn (this_arg: *const c_void) -> crate::c_types::SecretKey, - /// Get destination redeemScript to encumber static protocol exit points. + /// 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 shutdown_pubkey to use as PublicKey at channel closure + /// Get a public key which we will send funds to (in the form of a P2WPKH output) 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_pubkey: extern "C" fn (this_arg: *const c_void) -> crate::c_types::PublicKey, /// Get a new set of ChannelKeys for per-channel secrets. These MUST be unique even if you /// restarted with some stale data! + /// + /// This method must return a different value each time it is called. #[must_use] pub get_channel_keys: extern "C" fn (this_arg: *const c_void, inbound: bool, channel_value_satoshis: u64) -> crate::chain::keysinterface::ChannelKeys, /// Gets a unique, cryptographically-secure, random 32 byte value. This is used for encrypting /// onion packets and for temporary channel IDs. There is no requirement that these be /// persisted anywhere, though they must be unique across restarts. + /// + /// This method must return a different value each time it is called. #[must_use] pub get_secure_random_bytes: extern "C" fn (this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes, /// Reads a `ChanKeySigner` for this `KeysInterface` from the given input stream. @@ -696,9 +714,8 @@ pub extern "C" fn InMemoryChannelKeys_set_commitment_seed(this_ptr: &mut InMemor /// Create a new InMemoryChannelKeys #[must_use] #[no_mangle] -pub extern "C" fn InMemoryChannelKeys_new(mut funding_key: crate::c_types::SecretKey, mut revocation_base_key: crate::c_types::SecretKey, mut payment_key: crate::c_types::SecretKey, mut delayed_payment_base_key: crate::c_types::SecretKey, mut htlc_base_key: crate::c_types::SecretKey, mut commitment_seed: crate::c_types::ThirtyTwoBytes, mut channel_value_satoshis: u64, mut key_derivation_params: crate::c_types::derived::C2Tuple_u64u64Z) -> crate::chain::keysinterface::InMemoryChannelKeys { - let (mut orig_key_derivation_params_0, mut orig_key_derivation_params_1) = key_derivation_params.to_rust(); let mut local_key_derivation_params = (orig_key_derivation_params_0, orig_key_derivation_params_1); - let mut ret = lightning::chain::keysinterface::InMemoryChannelKeys::new(&bitcoin::secp256k1::Secp256k1::new(), funding_key.into_rust(), revocation_base_key.into_rust(), payment_key.into_rust(), delayed_payment_base_key.into_rust(), htlc_base_key.into_rust(), commitment_seed.data, channel_value_satoshis, local_key_derivation_params); +pub extern "C" fn InMemoryChannelKeys_new(mut funding_key: crate::c_types::SecretKey, mut revocation_base_key: crate::c_types::SecretKey, mut payment_key: crate::c_types::SecretKey, mut delayed_payment_base_key: crate::c_types::SecretKey, mut htlc_base_key: crate::c_types::SecretKey, mut commitment_seed: crate::c_types::ThirtyTwoBytes, mut channel_value_satoshis: u64, mut channel_keys_id: crate::c_types::ThirtyTwoBytes) -> crate::chain::keysinterface::InMemoryChannelKeys { + let mut ret = lightning::chain::keysinterface::InMemoryChannelKeys::new(&bitcoin::secp256k1::Secp256k1::new(), funding_key.into_rust(), revocation_base_key.into_rust(), payment_key.into_rust(), delayed_payment_base_key.into_rust(), htlc_base_key.into_rust(), commitment_seed.data, channel_value_satoshis, channel_keys_id.data); crate::chain::keysinterface::InMemoryChannelKeys { inner: Box::into_raw(Box::new(ret)), is_owned: true } } @@ -782,7 +799,7 @@ pub extern "C" fn InMemoryChannelKeys_as_ChannelKeys(this_arg: &InMemoryChannelK pubkeys: crate::ln::chan_utils::ChannelPublicKeys { inner: std::ptr::null_mut(), is_owned: true }, set_pubkeys: Some(InMemoryChannelKeys_ChannelKeys_set_pubkeys), - key_derivation_params: InMemoryChannelKeys_ChannelKeys_key_derivation_params, + channel_keys_id: InMemoryChannelKeys_ChannelKeys_channel_keys_id, sign_counterparty_commitment: InMemoryChannelKeys_ChannelKeys_sign_counterparty_commitment, sign_holder_commitment_and_htlcs: InMemoryChannelKeys_ChannelKeys_sign_holder_commitment_and_htlcs, sign_justice_transaction: InMemoryChannelKeys_ChannelKeys_sign_justice_transaction, @@ -818,10 +835,9 @@ extern "C" fn InMemoryChannelKeys_ChannelKeys_set_pubkeys(trait_self_arg: &Chann } } #[must_use] -extern "C" fn InMemoryChannelKeys_ChannelKeys_key_derivation_params(this_arg: *const c_void) -> crate::c_types::derived::C2Tuple_u64u64Z { - let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.key_derivation_params(); - let (mut orig_ret_0, mut orig_ret_1) = ret; let mut local_ret = (orig_ret_0, orig_ret_1).into(); - local_ret +extern "C" fn InMemoryChannelKeys_ChannelKeys_channel_keys_id(this_arg: *const c_void) -> crate::c_types::ThirtyTwoBytes { + let mut ret = unsafe { &mut *(this_arg as *mut nativeInMemoryChannelKeys) }.channel_keys_id(); + crate::c_types::ThirtyTwoBytes { data: ret } } #[must_use] extern "C" fn InMemoryChannelKeys_ChannelKeys_sign_counterparty_commitment(this_arg: *const c_void, commitment_tx: &crate::ln::chan_utils::CommitmentTransaction) -> crate::c_types::derived::CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ { @@ -951,12 +967,12 @@ pub extern "C" fn KeysManager_new(seed: *const [u8; 32], mut network: crate::bit /// Derive an old set of ChannelKeys for per-channel secrets based on a key derivation /// parameters. /// Key derivation parameters are accessible through a per-channel secrets -/// ChannelKeys::key_derivation_params and is provided inside DynamicOuputP2WSH in case of +/// ChannelKeys::channel_keys_id and is provided inside DynamicOuputP2WSH in case of /// onchain output detection for which a corresponding delayed_payment_key must be derived. #[must_use] #[no_mangle] -pub extern "C" fn KeysManager_derive_channel_keys(this_arg: &KeysManager, mut channel_value_satoshis: u64, mut params_1: u64, mut params_2: u64) -> crate::chain::keysinterface::InMemoryChannelKeys { - let mut ret = unsafe { &*this_arg.inner }.derive_channel_keys(channel_value_satoshis, params_1, params_2); +pub extern "C" fn KeysManager_derive_channel_keys(this_arg: &KeysManager, mut channel_value_satoshis: u64, params: *const [u8; 32]) -> crate::chain::keysinterface::InMemoryChannelKeys { + let mut ret = unsafe { &*this_arg.inner }.derive_channel_keys(channel_value_satoshis, unsafe { &*params}); crate::chain::keysinterface::InMemoryChannelKeys { inner: Box::into_raw(Box::new(ret)), is_owned: true } } -- 2.39.5