[C#] Update auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / NodeSigner.cs
index e454bb17fb5b8ee4ebcb62bb84d213031c571f7d..033f93acf3ff707358946b44ca10ce34bde3c461 100644 (file)
@@ -1,3 +1,4 @@
+
 using org.ldk.impl;
 using org.ldk.enums;
 using org.ldk.util;
@@ -5,86 +6,109 @@ using System;
 
 namespace org { namespace ldk { namespace structs {
 
+
+
+/** An implementation of NodeSigner */
+public interface NodeSignerInterface {
+       /**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
+        */
+       byte[] get_inbound_payment_key_material();
+       /**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.
+        */
+       Result_PublicKeyNoneZ get_node_id(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.
+        * 
+        * 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.
+        */
+       Result_ThirtyTwoBytesNoneZ ecdh(Recipient recipient, byte[] other_key, Option_BigEndianScalarZ tweak);
+       /**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.
+        */
+       Result_RecoverableSignatureNoneZ sign_invoice(byte[] hrp_bytes, UInt5[] invoice_data, Recipient recipient);
+       /**Signs the [`TaggedHash`] of a BOLT 12 invoice request.
+        * 
+        * May be called by a function passed to [`UnsignedInvoiceRequest::sign`] where
+        * `invoice_request` is the callee.
+        * 
+        * Implementors may check that the `invoice_request` is expected rather than blindly signing
+        * the tagged hash. An `Ok` result should sign `invoice_request.tagged_hash().as_digest()` with
+        * the node's signing key or an ephemeral key to preserve privacy, whichever is associated with
+        * [`UnsignedInvoiceRequest::payer_id`].
+        * 
+        * [`TaggedHash`]: crate::offers::merkle::TaggedHash
+        */
+       Result_SchnorrSignatureNoneZ sign_bolt12_invoice_request(UnsignedInvoiceRequest invoice_request);
+       /**Signs the [`TaggedHash`] of a BOLT 12 invoice.
+        * 
+        * May be called by a function passed to [`UnsignedBolt12Invoice::sign`] where `invoice` is the
+        * callee.
+        * 
+        * Implementors may check that the `invoice` is expected rather than blindly signing the tagged
+        * hash. An `Ok` result should sign `invoice.tagged_hash().as_digest()` with the node's signing
+        * key or an ephemeral key to preserve privacy, whichever is associated with
+        * [`UnsignedBolt12Invoice::signing_pubkey`].
+        * 
+        * [`TaggedHash`]: crate::offers::merkle::TaggedHash
+        */
+       Result_SchnorrSignatureNoneZ sign_bolt12_invoice(UnsignedBolt12Invoice invoice);
+       /**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.
+        */
+       Result_ECDSASignatureNoneZ sign_gossip_message(UnsignedGossipMessage msg);
+}
+
 /**
  * A trait that can handle cryptographic operations at the scope level of a node.
  */
 public class NodeSigner : CommonBase {
-       internal readonly bindings.LDKNodeSigner bindings_instance;
+       internal bindings.LDKNodeSigner bindings_instance;
+       internal long instance_idx;
+
        internal NodeSigner(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
-       private NodeSigner(bindings.LDKNodeSigner arg) : base(bindings.LDKNodeSigner_new(arg)) {
-               this.ptrs_to.AddLast(arg);
-               this.bindings_instance = arg;
-       }
        ~NodeSigner() {
                if (ptr != 0) { bindings.NodeSigner_free(ptr); }
        }
 
-       public interface NodeSignerInterface {
-               /**
-                * 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
-                */
-               byte[] get_inbound_payment_key_material();
-               /**
-                * 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.
-                */
-               Result_PublicKeyNoneZ get_node_id(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.
-                * 
-                * 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.
-                */
-               Result_SharedSecretNoneZ ecdh(Recipient _recipient, byte[] _other_key, Option_ScalarZ _tweak);
-               /**
-                * 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.
-                */
-               Result_RecoverableSignatureNoneZ sign_invoice(byte[] _hrp_bytes, UInt5[] _invoice_data, Recipient _recipient);
-               /**
-                * 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.
-                */
-               Result_SignatureNoneZ sign_gossip_message(UnsignedGossipMessage _msg);
-       }
        private class LDKNodeSignerHolder { internal NodeSigner held; }
        private class LDKNodeSignerImpl : bindings.LDKNodeSigner {
                internal LDKNodeSignerImpl(NodeSignerInterface arg, LDKNodeSignerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
                private NodeSignerInterface arg;
                private LDKNodeSignerHolder impl_holder;
-               public byte[] get_inbound_payment_key_material() {
+               public long get_inbound_payment_key_material() {
                        byte[] ret = arg.get_inbound_payment_key_material();
                                GC.KeepAlive(arg);
-                       byte[] result = InternalUtils.check_arr_len(ret, 32);
+                       long result = InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(ret, 32));
                        return result;
                }
                public long get_node_id(Recipient _recipient) {
@@ -93,23 +117,40 @@ public class NodeSigner : CommonBase {
                        long result = ret == null ? 0 : ret.clone_ptr();
                        return result;
                }
-               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);
+               public long ecdh(Recipient _recipient, long _other_key, long _tweak) {
+                       byte[] _other_key_conv = InternalUtils.decodeUint8Array(_other_key);
+                       org.ldk.structs.Option_BigEndianScalarZ _tweak_hu_conv = org.ldk.structs.Option_BigEndianScalarZ.constr_from_ptr(_tweak);
                        if (_tweak_hu_conv != null) { _tweak_hu_conv.ptrs_to.AddLast(this); };
-                       Result_SharedSecretNoneZ ret = arg.ecdh(_recipient, _other_key, _tweak_hu_conv);
+                       Result_ThirtyTwoBytesNoneZ ret = arg.ecdh(_recipient, _other_key_conv, _tweak_hu_conv);
                                GC.KeepAlive(arg);
                        long result = ret == null ? 0 : ret.clone_ptr();
                        return result;
                }
-               public long sign_invoice(byte[] _hrp_bytes, byte[] _invoice_data, Recipient _recipient) {
-                       int _invoice_data_conv_7_len = _invoice_data.Length;
+               public long sign_invoice(long _hrp_bytes, long _invoice_data, Recipient _recipient) {
+                       byte[] _hrp_bytes_conv = InternalUtils.decodeUint8Array(_hrp_bytes);
+                       int _invoice_data_conv_7_len = InternalUtils.getArrayLength(_invoice_data);
                        UInt5[] _invoice_data_conv_7_arr = new UInt5[_invoice_data_conv_7_len];
                        for (int h = 0; h < _invoice_data_conv_7_len; h++) {
-                               byte _invoice_data_conv_7 = _invoice_data[h];
+                               byte _invoice_data_conv_7 = InternalUtils.getU8ArrayElem(_invoice_data, h);
                                UInt5 _invoice_data_conv_7_conv = new UInt5(_invoice_data_conv_7);
                                _invoice_data_conv_7_arr[h] = _invoice_data_conv_7_conv;
                        }
-                       Result_RecoverableSignatureNoneZ ret = arg.sign_invoice(_hrp_bytes, _invoice_data_conv_7_arr, _recipient);
+                       bindings.free_buffer(_invoice_data);
+                       Result_RecoverableSignatureNoneZ ret = arg.sign_invoice(_hrp_bytes_conv, _invoice_data_conv_7_arr, _recipient);
+                               GC.KeepAlive(arg);
+                       long result = ret == null ? 0 : ret.clone_ptr();
+                       return result;
+               }
+               public long sign_bolt12_invoice_request(long _invoice_request) {
+                       org.ldk.structs.UnsignedInvoiceRequest _invoice_request_hu_conv = null; if (_invoice_request < 0 || _invoice_request > 4096) { _invoice_request_hu_conv = new org.ldk.structs.UnsignedInvoiceRequest(null, _invoice_request); }
+                       Result_SchnorrSignatureNoneZ ret = arg.sign_bolt12_invoice_request(_invoice_request_hu_conv);
+                               GC.KeepAlive(arg);
+                       long result = ret == null ? 0 : ret.clone_ptr();
+                       return result;
+               }
+               public long sign_bolt12_invoice(long _invoice) {
+                       org.ldk.structs.UnsignedBolt12Invoice _invoice_hu_conv = null; if (_invoice < 0 || _invoice > 4096) { _invoice_hu_conv = new org.ldk.structs.UnsignedBolt12Invoice(null, _invoice); }
+                       Result_SchnorrSignatureNoneZ ret = arg.sign_bolt12_invoice(_invoice_hu_conv);
                                GC.KeepAlive(arg);
                        long result = ret == null ? 0 : ret.clone_ptr();
                        return result;
@@ -117,17 +158,25 @@ public class NodeSigner : CommonBase {
                public long sign_gossip_message(long _msg) {
                        org.ldk.structs.UnsignedGossipMessage _msg_hu_conv = org.ldk.structs.UnsignedGossipMessage.constr_from_ptr(_msg);
                        if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
-                       Result_SignatureNoneZ ret = arg.sign_gossip_message(_msg_hu_conv);
+                       Result_ECDSASignatureNoneZ ret = arg.sign_gossip_message(_msg_hu_conv);
                                GC.KeepAlive(arg);
                        long result = ret == null ? 0 : ret.clone_ptr();
                        return result;
                }
        }
+
+       /** Creates a new instance of NodeSigner from a given implementation */
        public static NodeSigner new_impl(NodeSignerInterface arg) {
                LDKNodeSignerHolder impl_holder = new LDKNodeSignerHolder();
-               impl_holder.held = new NodeSigner(new LDKNodeSignerImpl(arg, impl_holder));
+               LDKNodeSignerImpl impl = new LDKNodeSignerImpl(arg, impl_holder);
+               long[] ptr_idx = bindings.LDKNodeSigner_new(impl);
+
+               impl_holder.held = new NodeSigner(null, ptr_idx[0]);
+               impl_holder.held.instance_idx = ptr_idx[1];
+               impl_holder.held.bindings_instance = impl;
                return impl_holder.held;
        }
+
        /**
         * Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
         * 
@@ -140,9 +189,11 @@ public class NodeSigner : CommonBase {
         * [phantom node payments]: PhantomKeysManager
         */
        public byte[] get_inbound_payment_key_material() {
-               byte[] ret = bindings.NodeSigner_get_inbound_payment_key_material(this.ptr);
+               long ret = bindings.NodeSigner_get_inbound_payment_key_material(this.ptr);
                GC.KeepAlive(this);
-               return ret;
+               if (ret >= 0 && ret <= 4096) { return null; }
+               byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
+               return ret_conv;
        }
 
        /**
@@ -172,14 +223,14 @@ public class NodeSigner : CommonBase {
         * 
         * Errors if the [`Recipient`] variant is not supported by the implementation.
         */
-       public Result_SharedSecretNoneZ ecdh(Recipient recipient, byte[] other_key, org.ldk.structs.Option_ScalarZ tweak) {
-               long ret = bindings.NodeSigner_ecdh(this.ptr, recipient, InternalUtils.check_arr_len(other_key, 33), tweak.ptr);
+       public Result_ThirtyTwoBytesNoneZ ecdh(Recipient recipient, byte[] other_key, org.ldk.structs.Option_BigEndianScalarZ tweak) {
+               long ret = bindings.NodeSigner_ecdh(this.ptr, recipient, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(other_key, 33)), tweak.ptr);
                GC.KeepAlive(this);
                GC.KeepAlive(recipient);
                GC.KeepAlive(other_key);
                GC.KeepAlive(tweak);
                if (ret >= 0 && ret <= 4096) { return null; }
-               Result_SharedSecretNoneZ ret_hu_conv = Result_SharedSecretNoneZ.constr_from_ptr(ret);
+               Result_ThirtyTwoBytesNoneZ ret_hu_conv = Result_ThirtyTwoBytesNoneZ.constr_from_ptr(ret);
                if (this != null) { this.ptrs_to.AddLast(tweak); };
                return ret_hu_conv;
        }
@@ -198,7 +249,7 @@ public class NodeSigner : CommonBase {
         * Errors if the [`Recipient`] variant is not supported by the implementation.
         */
        public Result_RecoverableSignatureNoneZ sign_invoice(byte[] hrp_bytes, UInt5[] invoice_data, Recipient recipient) {
-               long ret = bindings.NodeSigner_sign_invoice(this.ptr, hrp_bytes, invoice_data != null ? InternalUtils.convUInt5Array(invoice_data) : null, recipient);
+               long ret = bindings.NodeSigner_sign_invoice(this.ptr, InternalUtils.encodeUint8Array(hrp_bytes), InternalUtils.encodeUint8Array(InternalUtils.convUInt5Array(invoice_data)), recipient);
                GC.KeepAlive(this);
                GC.KeepAlive(hrp_bytes);
                GC.KeepAlive(invoice_data);
@@ -208,6 +259,52 @@ public class NodeSigner : CommonBase {
                return ret_hu_conv;
        }
 
+       /**
+        * Signs the [`TaggedHash`] of a BOLT 12 invoice request.
+        * 
+        * May be called by a function passed to [`UnsignedInvoiceRequest::sign`] where
+        * `invoice_request` is the callee.
+        * 
+        * Implementors may check that the `invoice_request` is expected rather than blindly signing
+        * the tagged hash. An `Ok` result should sign `invoice_request.tagged_hash().as_digest()` with
+        * the node's signing key or an ephemeral key to preserve privacy, whichever is associated with
+        * [`UnsignedInvoiceRequest::payer_id`].
+        * 
+        * [`TaggedHash`]: crate::offers::merkle::TaggedHash
+        */
+       public Result_SchnorrSignatureNoneZ sign_bolt12_invoice_request(org.ldk.structs.UnsignedInvoiceRequest invoice_request) {
+               long ret = bindings.NodeSigner_sign_bolt12_invoice_request(this.ptr, invoice_request == null ? 0 : invoice_request.ptr);
+               GC.KeepAlive(this);
+               GC.KeepAlive(invoice_request);
+               if (ret >= 0 && ret <= 4096) { return null; }
+               Result_SchnorrSignatureNoneZ ret_hu_conv = Result_SchnorrSignatureNoneZ.constr_from_ptr(ret);
+               if (this != null) { this.ptrs_to.AddLast(invoice_request); };
+               return ret_hu_conv;
+       }
+
+       /**
+        * Signs the [`TaggedHash`] of a BOLT 12 invoice.
+        * 
+        * May be called by a function passed to [`UnsignedBolt12Invoice::sign`] where `invoice` is the
+        * callee.
+        * 
+        * Implementors may check that the `invoice` is expected rather than blindly signing the tagged
+        * hash. An `Ok` result should sign `invoice.tagged_hash().as_digest()` with the node's signing
+        * key or an ephemeral key to preserve privacy, whichever is associated with
+        * [`UnsignedBolt12Invoice::signing_pubkey`].
+        * 
+        * [`TaggedHash`]: crate::offers::merkle::TaggedHash
+        */
+       public Result_SchnorrSignatureNoneZ sign_bolt12_invoice(org.ldk.structs.UnsignedBolt12Invoice invoice) {
+               long ret = bindings.NodeSigner_sign_bolt12_invoice(this.ptr, invoice == null ? 0 : invoice.ptr);
+               GC.KeepAlive(this);
+               GC.KeepAlive(invoice);
+               if (ret >= 0 && ret <= 4096) { return null; }
+               Result_SchnorrSignatureNoneZ ret_hu_conv = Result_SchnorrSignatureNoneZ.constr_from_ptr(ret);
+               if (this != null) { this.ptrs_to.AddLast(invoice); };
+               return ret_hu_conv;
+       }
+
        /**
         * Sign a gossip message.
         * 
@@ -216,12 +313,12 @@ public class NodeSigner : CommonBase {
         * message to be broadcast, as otherwise it may prevent one from receiving funds over the
         * corresponding channel.
         */
-       public Result_SignatureNoneZ sign_gossip_message(org.ldk.structs.UnsignedGossipMessage msg) {
+       public Result_ECDSASignatureNoneZ sign_gossip_message(org.ldk.structs.UnsignedGossipMessage msg) {
                long ret = bindings.NodeSigner_sign_gossip_message(this.ptr, msg.ptr);
                GC.KeepAlive(this);
                GC.KeepAlive(msg);
                if (ret >= 0 && ret <= 4096) { return null; }
-               Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
+               Result_ECDSASignatureNoneZ ret_hu_conv = Result_ECDSASignatureNoneZ.constr_from_ptr(ret);
                if (this != null) { this.ptrs_to.AddLast(msg); };
                return ret_hu_conv;
        }