7 namespace org { namespace ldk { namespace structs {
11 /** An implementation of NodeSigner */
12 public interface NodeSignerInterface {
13 /**Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
15 * If the implementor of this trait supports [phantom node payments], then every node that is
16 * intended to be included in the phantom invoice route hints must return the same value from
19 * This method must return the same value each time it is called.
21 * [phantom node payments]: PhantomKeysManager
23 byte[] get_inbound_payment_key_material();
24 /**Get node id based on the provided [`Recipient`].
26 * This method must return the same value each time it is called with a given [`Recipient`]
29 * Errors if the [`Recipient`] variant is not supported by the implementation.
31 Result_PublicKeyNoneZ get_node_id(Recipient recipient);
32 /**Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
33 * one is provided. Note that this tweak can be applied to `other_key` instead of our node
34 * secret, though this is less efficient.
36 * Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
37 * should be resolved to allow LDK to resume forwarding HTLCs.
39 * Errors if the [`Recipient`] variant is not supported by the implementation.
41 Result_ThirtyTwoBytesNoneZ ecdh(Recipient recipient, byte[] other_key, Option_BigEndianScalarZ tweak);
44 * By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
45 * this trait to parse the invoice and make sure they're signing what they expect, rather than
46 * blindly signing the hash.
48 * The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
50 * The secret key used to sign the invoice is dependent on the [`Recipient`].
52 * Errors if the [`Recipient`] variant is not supported by the implementation.
54 Result_RecoverableSignatureNoneZ sign_invoice(byte[] hrp_bytes, UInt5[] invoice_data, Recipient recipient);
55 /**Signs the [`TaggedHash`] of a BOLT 12 invoice request.
57 * May be called by a function passed to [`UnsignedInvoiceRequest::sign`] where
58 * `invoice_request` is the callee.
60 * Implementors may check that the `invoice_request` is expected rather than blindly signing
61 * the tagged hash. An `Ok` result should sign `invoice_request.tagged_hash().as_digest()` with
62 * the node's signing key or an ephemeral key to preserve privacy, whichever is associated with
63 * [`UnsignedInvoiceRequest::payer_id`].
65 * [`TaggedHash`]: crate::offers::merkle::TaggedHash
67 Result_SchnorrSignatureNoneZ sign_bolt12_invoice_request(UnsignedInvoiceRequest invoice_request);
68 /**Signs the [`TaggedHash`] of a BOLT 12 invoice.
70 * May be called by a function passed to [`UnsignedBolt12Invoice::sign`] where `invoice` is the
73 * Implementors may check that the `invoice` is expected rather than blindly signing the tagged
74 * hash. An `Ok` result should sign `invoice.tagged_hash().as_digest()` with the node's signing
75 * key or an ephemeral key to preserve privacy, whichever is associated with
76 * [`UnsignedBolt12Invoice::signing_pubkey`].
78 * [`TaggedHash`]: crate::offers::merkle::TaggedHash
80 Result_SchnorrSignatureNoneZ sign_bolt12_invoice(UnsignedBolt12Invoice invoice);
81 /**Sign a gossip message.
83 * Note that if this fails, LDK may panic and the message will not be broadcast to the network
84 * or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
85 * message to be broadcast, as otherwise it may prevent one from receiving funds over the
86 * corresponding channel.
88 Result_ECDSASignatureNoneZ sign_gossip_message(UnsignedGossipMessage msg);
92 * A trait that can handle cryptographic operations at the scope level of a node.
94 public class NodeSigner : CommonBase {
95 internal bindings.LDKNodeSigner bindings_instance;
96 internal long instance_idx;
98 internal NodeSigner(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
100 if (ptr != 0) { bindings.NodeSigner_free(ptr); }
103 private class LDKNodeSignerHolder { internal NodeSigner held; }
104 private class LDKNodeSignerImpl : bindings.LDKNodeSigner {
105 internal LDKNodeSignerImpl(NodeSignerInterface arg, LDKNodeSignerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
106 private NodeSignerInterface arg;
107 private LDKNodeSignerHolder impl_holder;
108 public long get_inbound_payment_key_material() {
109 byte[] ret = arg.get_inbound_payment_key_material();
111 long result = InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(ret, 32));
114 public long get_node_id(Recipient _recipient) {
115 Result_PublicKeyNoneZ ret = arg.get_node_id(_recipient);
117 long result = ret == null ? 0 : ret.clone_ptr();
120 public long ecdh(Recipient _recipient, long _other_key, long _tweak) {
121 byte[] _other_key_conv = InternalUtils.decodeUint8Array(_other_key);
122 org.ldk.structs.Option_BigEndianScalarZ _tweak_hu_conv = org.ldk.structs.Option_BigEndianScalarZ.constr_from_ptr(_tweak);
123 if (_tweak_hu_conv != null) { _tweak_hu_conv.ptrs_to.AddLast(this); };
124 Result_ThirtyTwoBytesNoneZ ret = arg.ecdh(_recipient, _other_key_conv, _tweak_hu_conv);
126 long result = ret == null ? 0 : ret.clone_ptr();
129 public long sign_invoice(long _hrp_bytes, long _invoice_data, Recipient _recipient) {
130 byte[] _hrp_bytes_conv = InternalUtils.decodeUint8Array(_hrp_bytes);
131 int _invoice_data_conv_7_len = InternalUtils.getArrayLength(_invoice_data);
132 UInt5[] _invoice_data_conv_7_arr = new UInt5[_invoice_data_conv_7_len];
133 for (int h = 0; h < _invoice_data_conv_7_len; h++) {
134 byte _invoice_data_conv_7 = InternalUtils.getU8ArrayElem(_invoice_data, h);
135 UInt5 _invoice_data_conv_7_conv = new UInt5(_invoice_data_conv_7);
136 _invoice_data_conv_7_arr[h] = _invoice_data_conv_7_conv;
138 bindings.free_buffer(_invoice_data);
139 Result_RecoverableSignatureNoneZ ret = arg.sign_invoice(_hrp_bytes_conv, _invoice_data_conv_7_arr, _recipient);
141 long result = ret == null ? 0 : ret.clone_ptr();
144 public long sign_bolt12_invoice_request(long _invoice_request) {
145 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); }
146 Result_SchnorrSignatureNoneZ ret = arg.sign_bolt12_invoice_request(_invoice_request_hu_conv);
148 long result = ret == null ? 0 : ret.clone_ptr();
151 public long sign_bolt12_invoice(long _invoice) {
152 org.ldk.structs.UnsignedBolt12Invoice _invoice_hu_conv = null; if (_invoice < 0 || _invoice > 4096) { _invoice_hu_conv = new org.ldk.structs.UnsignedBolt12Invoice(null, _invoice); }
153 Result_SchnorrSignatureNoneZ ret = arg.sign_bolt12_invoice(_invoice_hu_conv);
155 long result = ret == null ? 0 : ret.clone_ptr();
158 public long sign_gossip_message(long _msg) {
159 org.ldk.structs.UnsignedGossipMessage _msg_hu_conv = org.ldk.structs.UnsignedGossipMessage.constr_from_ptr(_msg);
160 if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
161 Result_ECDSASignatureNoneZ ret = arg.sign_gossip_message(_msg_hu_conv);
163 long result = ret == null ? 0 : ret.clone_ptr();
168 /** Creates a new instance of NodeSigner from a given implementation */
169 public static NodeSigner new_impl(NodeSignerInterface arg) {
170 LDKNodeSignerHolder impl_holder = new LDKNodeSignerHolder();
171 LDKNodeSignerImpl impl = new LDKNodeSignerImpl(arg, impl_holder);
172 long[] ptr_idx = bindings.LDKNodeSigner_new(impl);
174 impl_holder.held = new NodeSigner(null, ptr_idx[0]);
175 impl_holder.held.instance_idx = ptr_idx[1];
176 impl_holder.held.bindings_instance = impl;
177 return impl_holder.held;
181 * Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
183 * If the implementor of this trait supports [phantom node payments], then every node that is
184 * intended to be included in the phantom invoice route hints must return the same value from
187 * This method must return the same value each time it is called.
189 * [phantom node payments]: PhantomKeysManager
191 public byte[] get_inbound_payment_key_material() {
192 long ret = bindings.NodeSigner_get_inbound_payment_key_material(this.ptr);
194 if (ret >= 0 && ret <= 4096) { return null; }
195 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
200 * Get node id based on the provided [`Recipient`].
202 * This method must return the same value each time it is called with a given [`Recipient`]
205 * Errors if the [`Recipient`] variant is not supported by the implementation.
207 public Result_PublicKeyNoneZ get_node_id(Recipient recipient) {
208 long ret = bindings.NodeSigner_get_node_id(this.ptr, recipient);
210 GC.KeepAlive(recipient);
211 if (ret >= 0 && ret <= 4096) { return null; }
212 Result_PublicKeyNoneZ ret_hu_conv = Result_PublicKeyNoneZ.constr_from_ptr(ret);
217 * Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
218 * one is provided. Note that this tweak can be applied to `other_key` instead of our node
219 * secret, though this is less efficient.
221 * Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
222 * should be resolved to allow LDK to resume forwarding HTLCs.
224 * Errors if the [`Recipient`] variant is not supported by the implementation.
226 public Result_ThirtyTwoBytesNoneZ ecdh(Recipient recipient, byte[] other_key, org.ldk.structs.Option_BigEndianScalarZ tweak) {
227 long ret = bindings.NodeSigner_ecdh(this.ptr, recipient, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(other_key, 33)), tweak.ptr);
229 GC.KeepAlive(recipient);
230 GC.KeepAlive(other_key);
232 if (ret >= 0 && ret <= 4096) { return null; }
233 Result_ThirtyTwoBytesNoneZ ret_hu_conv = Result_ThirtyTwoBytesNoneZ.constr_from_ptr(ret);
234 if (this != null) { this.ptrs_to.AddLast(tweak); };
241 * By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
242 * this trait to parse the invoice and make sure they're signing what they expect, rather than
243 * blindly signing the hash.
245 * The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
247 * The secret key used to sign the invoice is dependent on the [`Recipient`].
249 * Errors if the [`Recipient`] variant is not supported by the implementation.
251 public Result_RecoverableSignatureNoneZ sign_invoice(byte[] hrp_bytes, UInt5[] invoice_data, Recipient recipient) {
252 long ret = bindings.NodeSigner_sign_invoice(this.ptr, InternalUtils.encodeUint8Array(hrp_bytes), InternalUtils.encodeUint8Array(InternalUtils.convUInt5Array(invoice_data)), recipient);
254 GC.KeepAlive(hrp_bytes);
255 GC.KeepAlive(invoice_data);
256 GC.KeepAlive(recipient);
257 if (ret >= 0 && ret <= 4096) { return null; }
258 Result_RecoverableSignatureNoneZ ret_hu_conv = Result_RecoverableSignatureNoneZ.constr_from_ptr(ret);
263 * Signs the [`TaggedHash`] of a BOLT 12 invoice request.
265 * May be called by a function passed to [`UnsignedInvoiceRequest::sign`] where
266 * `invoice_request` is the callee.
268 * Implementors may check that the `invoice_request` is expected rather than blindly signing
269 * the tagged hash. An `Ok` result should sign `invoice_request.tagged_hash().as_digest()` with
270 * the node's signing key or an ephemeral key to preserve privacy, whichever is associated with
271 * [`UnsignedInvoiceRequest::payer_id`].
273 * [`TaggedHash`]: crate::offers::merkle::TaggedHash
275 public Result_SchnorrSignatureNoneZ sign_bolt12_invoice_request(org.ldk.structs.UnsignedInvoiceRequest invoice_request) {
276 long ret = bindings.NodeSigner_sign_bolt12_invoice_request(this.ptr, invoice_request == null ? 0 : invoice_request.ptr);
278 GC.KeepAlive(invoice_request);
279 if (ret >= 0 && ret <= 4096) { return null; }
280 Result_SchnorrSignatureNoneZ ret_hu_conv = Result_SchnorrSignatureNoneZ.constr_from_ptr(ret);
281 if (this != null) { this.ptrs_to.AddLast(invoice_request); };
286 * Signs the [`TaggedHash`] of a BOLT 12 invoice.
288 * May be called by a function passed to [`UnsignedBolt12Invoice::sign`] where `invoice` is the
291 * Implementors may check that the `invoice` is expected rather than blindly signing the tagged
292 * hash. An `Ok` result should sign `invoice.tagged_hash().as_digest()` with the node's signing
293 * key or an ephemeral key to preserve privacy, whichever is associated with
294 * [`UnsignedBolt12Invoice::signing_pubkey`].
296 * [`TaggedHash`]: crate::offers::merkle::TaggedHash
298 public Result_SchnorrSignatureNoneZ sign_bolt12_invoice(org.ldk.structs.UnsignedBolt12Invoice invoice) {
299 long ret = bindings.NodeSigner_sign_bolt12_invoice(this.ptr, invoice == null ? 0 : invoice.ptr);
301 GC.KeepAlive(invoice);
302 if (ret >= 0 && ret <= 4096) { return null; }
303 Result_SchnorrSignatureNoneZ ret_hu_conv = Result_SchnorrSignatureNoneZ.constr_from_ptr(ret);
304 if (this != null) { this.ptrs_to.AddLast(invoice); };
309 * Sign a gossip message.
311 * Note that if this fails, LDK may panic and the message will not be broadcast to the network
312 * or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
313 * message to be broadcast, as otherwise it may prevent one from receiving funds over the
314 * corresponding channel.
316 public Result_ECDSASignatureNoneZ sign_gossip_message(org.ldk.structs.UnsignedGossipMessage msg) {
317 long ret = bindings.NodeSigner_sign_gossip_message(this.ptr, msg.ptr);
320 if (ret >= 0 && ret <= 4096) { return null; }
321 Result_ECDSASignatureNoneZ ret_hu_conv = Result_ECDSASignatureNoneZ.constr_from_ptr(ret);
322 if (this != null) { this.ptrs_to.AddLast(msg); };