6 namespace org { namespace ldk { namespace structs {
9 * A trait that can handle cryptographic operations at the scope level of a node.
11 public class NodeSigner : CommonBase {
12 internal readonly bindings.LDKNodeSigner bindings_instance;
13 internal NodeSigner(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
14 private NodeSigner(bindings.LDKNodeSigner arg) : base(bindings.LDKNodeSigner_new(arg)) {
15 this.ptrs_to.AddLast(arg);
16 this.bindings_instance = arg;
19 if (ptr != 0) { bindings.NodeSigner_free(ptr); }
22 public interface NodeSignerInterface {
24 * Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
26 * If the implementor of this trait supports [phantom node payments], then every node that is
27 * intended to be included in the phantom invoice route hints must return the same value from
30 * This method must return the same value each time it is called.
32 * [phantom node payments]: PhantomKeysManager
34 byte[] get_inbound_payment_key_material();
36 * Get node id based on the provided [`Recipient`].
38 * This method must return the same value each time it is called with a given [`Recipient`]
41 * Errors if the [`Recipient`] variant is not supported by the implementation.
43 Result_PublicKeyNoneZ get_node_id(Recipient _recipient);
45 * Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
46 * one is provided. Note that this tweak can be applied to `other_key` instead of our node
47 * secret, though this is less efficient.
49 * Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
50 * should be resolved to allow LDK to resume forwarding HTLCs.
52 * Errors if the [`Recipient`] variant is not supported by the implementation.
54 Result_SharedSecretNoneZ ecdh(Recipient _recipient, byte[] _other_key, Option_ScalarZ _tweak);
58 * By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
59 * this trait to parse the invoice and make sure they're signing what they expect, rather than
60 * blindly signing the hash.
62 * The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
64 * The secret key used to sign the invoice is dependent on the [`Recipient`].
66 * Errors if the [`Recipient`] variant is not supported by the implementation.
68 Result_RecoverableSignatureNoneZ sign_invoice(byte[] _hrp_bytes, UInt5[] _invoice_data, Recipient _recipient);
70 * Sign a gossip message.
72 * Note that if this fails, LDK may panic and the message will not be broadcast to the network
73 * or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
74 * message to be broadcast, as otherwise it may prevent one from receiving funds over the
75 * corresponding channel.
77 Result_SignatureNoneZ sign_gossip_message(UnsignedGossipMessage _msg);
79 private class LDKNodeSignerHolder { internal NodeSigner held; }
80 private class LDKNodeSignerImpl : bindings.LDKNodeSigner {
81 internal LDKNodeSignerImpl(NodeSignerInterface arg, LDKNodeSignerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
82 private NodeSignerInterface arg;
83 private LDKNodeSignerHolder impl_holder;
84 public byte[] get_inbound_payment_key_material() {
85 byte[] ret = arg.get_inbound_payment_key_material();
87 byte[] result = InternalUtils.check_arr_len(ret, 32);
90 public long get_node_id(Recipient _recipient) {
91 Result_PublicKeyNoneZ ret = arg.get_node_id(_recipient);
93 long result = ret == null ? 0 : ret.clone_ptr();
96 public long ecdh(Recipient _recipient, byte[] _other_key, long _tweak) {
97 org.ldk.structs.Option_ScalarZ _tweak_hu_conv = org.ldk.structs.Option_ScalarZ.constr_from_ptr(_tweak);
98 if (_tweak_hu_conv != null) { _tweak_hu_conv.ptrs_to.AddLast(this); };
99 Result_SharedSecretNoneZ ret = arg.ecdh(_recipient, _other_key, _tweak_hu_conv);
101 long result = ret == null ? 0 : ret.clone_ptr();
104 public long sign_invoice(byte[] _hrp_bytes, byte[] _invoice_data, Recipient _recipient) {
105 int _invoice_data_conv_7_len = _invoice_data.Length;
106 UInt5[] _invoice_data_conv_7_arr = new UInt5[_invoice_data_conv_7_len];
107 for (int h = 0; h < _invoice_data_conv_7_len; h++) {
108 byte _invoice_data_conv_7 = _invoice_data[h];
109 UInt5 _invoice_data_conv_7_conv = new UInt5(_invoice_data_conv_7);
110 _invoice_data_conv_7_arr[h] = _invoice_data_conv_7_conv;
112 Result_RecoverableSignatureNoneZ ret = arg.sign_invoice(_hrp_bytes, _invoice_data_conv_7_arr, _recipient);
114 long result = ret == null ? 0 : ret.clone_ptr();
117 public long sign_gossip_message(long _msg) {
118 org.ldk.structs.UnsignedGossipMessage _msg_hu_conv = org.ldk.structs.UnsignedGossipMessage.constr_from_ptr(_msg);
119 if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
120 Result_SignatureNoneZ ret = arg.sign_gossip_message(_msg_hu_conv);
122 long result = ret == null ? 0 : ret.clone_ptr();
126 public static NodeSigner new_impl(NodeSignerInterface arg) {
127 LDKNodeSignerHolder impl_holder = new LDKNodeSignerHolder();
128 impl_holder.held = new NodeSigner(new LDKNodeSignerImpl(arg, impl_holder));
129 return impl_holder.held;
132 * Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
134 * If the implementor of this trait supports [phantom node payments], then every node that is
135 * intended to be included in the phantom invoice route hints must return the same value from
138 * This method must return the same value each time it is called.
140 * [phantom node payments]: PhantomKeysManager
142 public byte[] get_inbound_payment_key_material() {
143 byte[] ret = bindings.NodeSigner_get_inbound_payment_key_material(this.ptr);
149 * Get node id based on the provided [`Recipient`].
151 * This method must return the same value each time it is called with a given [`Recipient`]
154 * Errors if the [`Recipient`] variant is not supported by the implementation.
156 public Result_PublicKeyNoneZ get_node_id(Recipient recipient) {
157 long ret = bindings.NodeSigner_get_node_id(this.ptr, recipient);
159 GC.KeepAlive(recipient);
160 if (ret >= 0 && ret <= 4096) { return null; }
161 Result_PublicKeyNoneZ ret_hu_conv = Result_PublicKeyNoneZ.constr_from_ptr(ret);
166 * Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
167 * one is provided. Note that this tweak can be applied to `other_key` instead of our node
168 * secret, though this is less efficient.
170 * Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
171 * should be resolved to allow LDK to resume forwarding HTLCs.
173 * Errors if the [`Recipient`] variant is not supported by the implementation.
175 public Result_SharedSecretNoneZ ecdh(Recipient recipient, byte[] other_key, org.ldk.structs.Option_ScalarZ tweak) {
176 long ret = bindings.NodeSigner_ecdh(this.ptr, recipient, InternalUtils.check_arr_len(other_key, 33), tweak.ptr);
178 GC.KeepAlive(recipient);
179 GC.KeepAlive(other_key);
181 if (ret >= 0 && ret <= 4096) { return null; }
182 Result_SharedSecretNoneZ ret_hu_conv = Result_SharedSecretNoneZ.constr_from_ptr(ret);
183 if (this != null) { this.ptrs_to.AddLast(tweak); };
190 * By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
191 * this trait to parse the invoice and make sure they're signing what they expect, rather than
192 * blindly signing the hash.
194 * The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
196 * The secret key used to sign the invoice is dependent on the [`Recipient`].
198 * Errors if the [`Recipient`] variant is not supported by the implementation.
200 public Result_RecoverableSignatureNoneZ sign_invoice(byte[] hrp_bytes, UInt5[] invoice_data, Recipient recipient) {
201 long ret = bindings.NodeSigner_sign_invoice(this.ptr, hrp_bytes, invoice_data != null ? InternalUtils.convUInt5Array(invoice_data) : null, recipient);
203 GC.KeepAlive(hrp_bytes);
204 GC.KeepAlive(invoice_data);
205 GC.KeepAlive(recipient);
206 if (ret >= 0 && ret <= 4096) { return null; }
207 Result_RecoverableSignatureNoneZ ret_hu_conv = Result_RecoverableSignatureNoneZ.constr_from_ptr(ret);
212 * Sign a gossip message.
214 * Note that if this fails, LDK may panic and the message will not be broadcast to the network
215 * or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
216 * message to be broadcast, as otherwise it may prevent one from receiving funds over the
217 * corresponding channel.
219 public Result_SignatureNoneZ sign_gossip_message(org.ldk.structs.UnsignedGossipMessage msg) {
220 long ret = bindings.NodeSigner_sign_gossip_message(this.ptr, msg.ptr);
223 if (ret >= 0 && ret <= 4096) { return null; }
224 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
225 if (this != null) { this.ptrs_to.AddLast(msg); };