[Java] Handle nullable arrays
[ldk-java] / src / main / java / org / ldk / structs / KeysInterface.java
index fbaf6c85a7ec30211df1aa99e3b6155dcbed2b57..bc3aaf5645d7f62d67a373c0e2ffbd8a33a22d2c 100644 (file)
@@ -26,12 +26,22 @@ public class KeysInterface extends CommonBase {
 
        public static interface KeysInterfaceInterface {
                /**
-                * Get node secret key (aka node_id or network_key) based on the provided [`Recipient`].
+                * Get node secret key based on the provided [`Recipient`].
+                * 
+                * The node_id/network_key is the public key that corresponds to this secret key.
                 * 
                 * This method must return the same value each time it is called with a given `Recipient`
                 * parameter.
                 */
                Result_SecretKeyNoneZ get_node_secret(Recipient recipient);
+               /**
+                * 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.
+                * 
+                * [`node secret`]: Self::get_node_secret
+                */
+               Result_SharedSecretNoneZ ecdh(Recipient recipient, byte[] other_key, Option_ScalarZ tweak);
                /**
                 * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
                 * 
@@ -103,6 +113,14 @@ public class KeysInterface extends CommonBase {
                                long result = ret == null ? 0 : ret.clone_ptr();
                                return result;
                        }
+                       @Override public long ecdh(Recipient recipient, byte[] other_key, long tweak) {
+                               org.ldk.structs.Option_ScalarZ tweak_hu_conv = org.ldk.structs.Option_ScalarZ.constr_from_ptr(tweak);
+                               if (tweak_hu_conv != null) { tweak_hu_conv.ptrs_to.add(this); };
+                               Result_SharedSecretNoneZ ret = arg.ecdh(recipient, other_key, tweak_hu_conv);
+                               Reference.reachabilityFence(arg);
+                               long result = ret == null ? 0 : ret.clone_ptr();
+                               return result;
+                       }
                        @Override public byte[] get_destination_script() {
                                byte[] ret = arg.get_destination_script();
                                Reference.reachabilityFence(arg);
@@ -118,7 +136,7 @@ public class KeysInterface extends CommonBase {
                                Sign ret = arg.get_channel_signer(inbound, channel_value_satoshis);
                                Reference.reachabilityFence(arg);
                                long result = ret == null ? 0 : ret.clone_ptr();
-                               impl_holder.held.ptrs_to.add(ret);
+                               if (impl_holder.held != null) { impl_holder.held.ptrs_to.add(ret); };
                                return result;
                        }
                        @Override public byte[] get_secure_random_bytes() {
@@ -156,7 +174,9 @@ public class KeysInterface extends CommonBase {
                return impl_holder.held;
        }
        /**
-        * Get node secret key (aka node_id or network_key) based on the provided [`Recipient`].
+        * Get node secret key based on the provided [`Recipient`].
+        * 
+        * The node_id/network_key is the public key that corresponds to this secret key.
         * 
         * This method must return the same value each time it is called with a given `Recipient`
         * parameter.
@@ -170,6 +190,24 @@ public class KeysInterface extends CommonBase {
                return ret_hu_conv;
        }
 
+       /**
+        * 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.
+        * 
+        * [`node secret`]: Self::get_node_secret
+        */
+       public Result_SharedSecretNoneZ ecdh(org.ldk.enums.Recipient recipient, byte[] other_key, Option_ScalarZ tweak) {
+               long ret = bindings.KeysInterface_ecdh(this.ptr, recipient, InternalUtils.check_arr_len(other_key, 33), tweak.ptr);
+               Reference.reachabilityFence(this);
+               Reference.reachabilityFence(recipient);
+               Reference.reachabilityFence(other_key);
+               Reference.reachabilityFence(tweak);
+               if (ret >= 0 && ret <= 4096) { return null; }
+               Result_SharedSecretNoneZ ret_hu_conv = Result_SharedSecretNoneZ.constr_from_ptr(ret);
+               return ret_hu_conv;
+       }
+
        /**
         * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
         * 
@@ -193,7 +231,7 @@ public class KeysInterface extends CommonBase {
                Reference.reachabilityFence(this);
                if (ret >= 0 && ret <= 4096) { return null; }
                org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
-               ret_hu_conv.ptrs_to.add(this);
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
                return ret_hu_conv;
        }
 
@@ -210,7 +248,7 @@ public class KeysInterface extends CommonBase {
                Reference.reachabilityFence(channel_value_satoshis);
                if (ret >= 0 && ret <= 4096) { return null; }
                Sign ret_hu_conv = new Sign(null, ret);
-               ret_hu_conv.ptrs_to.add(this);
+               if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
                return ret_hu_conv;
        }