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(RawBolt11Invoice invoice, 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.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.clone_ptr();
129 public long sign_invoice(long _invoice, Recipient _recipient) {
130 org.ldk.structs.RawBolt11Invoice _invoice_hu_conv = null; if (_invoice < 0 || _invoice > 4096) { _invoice_hu_conv = new org.ldk.structs.RawBolt11Invoice(null, _invoice); }
131 Result_RecoverableSignatureNoneZ ret = arg.sign_invoice(_invoice_hu_conv, _recipient);
133 long result = ret.clone_ptr();
136 public long sign_bolt12_invoice_request(long _invoice_request) {
137 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); }
138 Result_SchnorrSignatureNoneZ ret = arg.sign_bolt12_invoice_request(_invoice_request_hu_conv);
140 long result = ret.clone_ptr();
143 public long sign_bolt12_invoice(long _invoice) {
144 org.ldk.structs.UnsignedBolt12Invoice _invoice_hu_conv = null; if (_invoice < 0 || _invoice > 4096) { _invoice_hu_conv = new org.ldk.structs.UnsignedBolt12Invoice(null, _invoice); }
145 Result_SchnorrSignatureNoneZ ret = arg.sign_bolt12_invoice(_invoice_hu_conv);
147 long result = ret.clone_ptr();
150 public long sign_gossip_message(long _msg) {
151 org.ldk.structs.UnsignedGossipMessage _msg_hu_conv = org.ldk.structs.UnsignedGossipMessage.constr_from_ptr(_msg);
152 if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
153 Result_ECDSASignatureNoneZ ret = arg.sign_gossip_message(_msg_hu_conv);
155 long result = ret.clone_ptr();
160 /** Creates a new instance of NodeSigner from a given implementation */
161 public static NodeSigner new_impl(NodeSignerInterface arg) {
162 LDKNodeSignerHolder impl_holder = new LDKNodeSignerHolder();
163 LDKNodeSignerImpl impl = new LDKNodeSignerImpl(arg, impl_holder);
164 long[] ptr_idx = bindings.LDKNodeSigner_new(impl);
166 impl_holder.held = new NodeSigner(null, ptr_idx[0]);
167 impl_holder.held.instance_idx = ptr_idx[1];
168 impl_holder.held.bindings_instance = impl;
169 return impl_holder.held;
173 * Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
175 * If the implementor of this trait supports [phantom node payments], then every node that is
176 * intended to be included in the phantom invoice route hints must return the same value from
179 * This method must return the same value each time it is called.
181 * [phantom node payments]: PhantomKeysManager
183 public byte[] get_inbound_payment_key_material() {
184 long ret = bindings.NodeSigner_get_inbound_payment_key_material(this.ptr);
186 if (ret >= 0 && ret <= 4096) { return null; }
187 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
192 * Get node id based on the provided [`Recipient`].
194 * This method must return the same value each time it is called with a given [`Recipient`]
197 * Errors if the [`Recipient`] variant is not supported by the implementation.
199 public Result_PublicKeyNoneZ get_node_id(Recipient recipient) {
200 long ret = bindings.NodeSigner_get_node_id(this.ptr, recipient);
202 GC.KeepAlive(recipient);
203 if (ret >= 0 && ret <= 4096) { return null; }
204 Result_PublicKeyNoneZ ret_hu_conv = Result_PublicKeyNoneZ.constr_from_ptr(ret);
209 * Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
210 * one is provided. Note that this tweak can be applied to `other_key` instead of our node
211 * secret, though this is less efficient.
213 * Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
214 * should be resolved to allow LDK to resume forwarding HTLCs.
216 * Errors if the [`Recipient`] variant is not supported by the implementation.
218 public Result_ThirtyTwoBytesNoneZ ecdh(Recipient recipient, byte[] other_key, org.ldk.structs.Option_BigEndianScalarZ tweak) {
219 long ret = bindings.NodeSigner_ecdh(this.ptr, recipient, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(other_key, 33)), tweak.ptr);
221 GC.KeepAlive(recipient);
222 GC.KeepAlive(other_key);
224 if (ret >= 0 && ret <= 4096) { return null; }
225 Result_ThirtyTwoBytesNoneZ ret_hu_conv = Result_ThirtyTwoBytesNoneZ.constr_from_ptr(ret);
232 * By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
233 * this trait to parse the invoice and make sure they're signing what they expect, rather than
234 * blindly signing the hash.
236 * The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
238 * The secret key used to sign the invoice is dependent on the [`Recipient`].
240 * Errors if the [`Recipient`] variant is not supported by the implementation.
242 public Result_RecoverableSignatureNoneZ sign_invoice(org.ldk.structs.RawBolt11Invoice invoice, Recipient recipient) {
243 long ret = bindings.NodeSigner_sign_invoice(this.ptr, invoice.ptr, recipient);
245 GC.KeepAlive(invoice);
246 GC.KeepAlive(recipient);
247 if (ret >= 0 && ret <= 4096) { return null; }
248 Result_RecoverableSignatureNoneZ ret_hu_conv = Result_RecoverableSignatureNoneZ.constr_from_ptr(ret);
249 if (this != null) { this.ptrs_to.AddLast(invoice); };
254 * Signs the [`TaggedHash`] of a BOLT 12 invoice request.
256 * May be called by a function passed to [`UnsignedInvoiceRequest::sign`] where
257 * `invoice_request` is the callee.
259 * Implementors may check that the `invoice_request` is expected rather than blindly signing
260 * the tagged hash. An `Ok` result should sign `invoice_request.tagged_hash().as_digest()` with
261 * the node's signing key or an ephemeral key to preserve privacy, whichever is associated with
262 * [`UnsignedInvoiceRequest::payer_id`].
264 * [`TaggedHash`]: crate::offers::merkle::TaggedHash
266 public Result_SchnorrSignatureNoneZ sign_bolt12_invoice_request(org.ldk.structs.UnsignedInvoiceRequest invoice_request) {
267 long ret = bindings.NodeSigner_sign_bolt12_invoice_request(this.ptr, invoice_request.ptr);
269 GC.KeepAlive(invoice_request);
270 if (ret >= 0 && ret <= 4096) { return null; }
271 Result_SchnorrSignatureNoneZ ret_hu_conv = Result_SchnorrSignatureNoneZ.constr_from_ptr(ret);
272 if (this != null) { this.ptrs_to.AddLast(invoice_request); };
277 * Signs the [`TaggedHash`] of a BOLT 12 invoice.
279 * May be called by a function passed to [`UnsignedBolt12Invoice::sign`] where `invoice` is the
282 * Implementors may check that the `invoice` is expected rather than blindly signing the tagged
283 * hash. An `Ok` result should sign `invoice.tagged_hash().as_digest()` with the node's signing
284 * key or an ephemeral key to preserve privacy, whichever is associated with
285 * [`UnsignedBolt12Invoice::signing_pubkey`].
287 * [`TaggedHash`]: crate::offers::merkle::TaggedHash
289 public Result_SchnorrSignatureNoneZ sign_bolt12_invoice(org.ldk.structs.UnsignedBolt12Invoice invoice) {
290 long ret = bindings.NodeSigner_sign_bolt12_invoice(this.ptr, invoice.ptr);
292 GC.KeepAlive(invoice);
293 if (ret >= 0 && ret <= 4096) { return null; }
294 Result_SchnorrSignatureNoneZ ret_hu_conv = Result_SchnorrSignatureNoneZ.constr_from_ptr(ret);
295 if (this != null) { this.ptrs_to.AddLast(invoice); };
300 * Sign a gossip message.
302 * Note that if this fails, LDK may panic and the message will not be broadcast to the network
303 * or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
304 * message to be broadcast, as otherwise it may prevent one from receiving funds over the
305 * corresponding channel.
307 public Result_ECDSASignatureNoneZ sign_gossip_message(org.ldk.structs.UnsignedGossipMessage msg) {
308 long ret = bindings.NodeSigner_sign_gossip_message(this.ptr, msg.ptr);
311 if (ret >= 0 && ret <= 4096) { return null; }
312 Result_ECDSASignatureNoneZ ret_hu_conv = Result_ECDSASignatureNoneZ.constr_from_ptr(ret);