6 namespace org { namespace ldk { namespace structs {
9 * A trait to describe an object which can get user secrets and key material.
11 public class KeysInterface : CommonBase {
12 internal readonly bindings.LDKKeysInterface bindings_instance;
13 internal KeysInterface(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
14 private KeysInterface(bindings.LDKKeysInterface arg) : base(bindings.LDKKeysInterface_new(arg)) {
15 this.ptrs_to.AddLast(arg);
16 this.bindings_instance = arg;
19 if (ptr != 0) { bindings.KeysInterface_free(ptr); }
22 public interface KeysInterfaceInterface {
24 * Get node secret key based on the provided [`Recipient`].
26 * The `node_id`/`network_key` is the public key that corresponds to this secret key.
28 * This method must return the same value each time it is called with a given [`Recipient`]
31 * Errors if the [`Recipient`] variant is not supported by the implementation.
33 Result_SecretKeyNoneZ get_node_secret(Recipient _recipient);
35 * Get node id based on the provided [`Recipient`]. This public key corresponds to the secret in
36 * [`get_node_secret`].
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 * [`get_node_secret`]: Self::get_node_secret
45 Result_PublicKeyNoneZ get_node_id(Recipient _recipient);
47 * Gets the ECDH shared secret of our [`node secret`] and `other_key`, multiplying by `tweak` if
48 * one is provided. Note that this tweak can be applied to `other_key` instead of our node
49 * secret, though this is less efficient.
51 * Errors if the [`Recipient`] variant is not supported by the implementation.
53 * [`node secret`]: Self::get_node_secret
55 Result_SharedSecretNoneZ ecdh(Recipient _recipient, byte[] _other_key, Option_ScalarZ _tweak);
57 * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
59 * This method should return a different value each time it is called, to avoid linking
60 * on-chain funds across channels as controlled to the same user.
62 byte[] get_destination_script();
64 * Get a script pubkey which we will send funds to when closing a channel.
66 * This method should return a different value each time it is called, to avoid linking
67 * on-chain funds across channels as controlled to the same user.
69 ShutdownScript get_shutdown_scriptpubkey();
71 * Get a new set of [`Sign`] for per-channel secrets. These MUST be unique even if you
72 * restarted with some stale data!
74 * This method must return a different value each time it is called.
76 byte[] generate_channel_keys_id(bool _inbound, long _channel_value_satoshis, UInt128 _user_channel_id);
78 * Derives the private key material backing a `Signer`.
80 * To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
81 * [`KeysInterface::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
82 * re-derived from its `channel_keys_id`, which can be obtained through its trait method
83 * [`BaseSign::channel_keys_id`].
85 Sign derive_channel_signer(long _channel_value_satoshis, byte[] _channel_keys_id);
87 * Gets a unique, cryptographically-secure, random 32 byte value. This is used for encrypting
88 * onion packets and for temporary channel IDs. There is no requirement that these be
89 * persisted anywhere, though they must be unique across restarts.
91 * This method must return a different value each time it is called.
93 byte[] get_secure_random_bytes();
95 * Reads a [`Signer`] for this [`KeysInterface`] from the given input stream.
96 * This is only called during deserialization of other objects which contain
97 * [`Sign`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
98 * The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
99 * contain no versioning scheme. You may wish to include your own version prefix and ensure
100 * you've read all of the provided bytes to ensure no corruption occurred.
102 * This method is slowly being phased out -- it will only be called when reading objects
103 * written by LDK versions prior to 0.0.113.
105 * [`Signer`]: Self::Signer
106 * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
107 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
109 Result_SignDecodeErrorZ read_chan_signer(byte[] _reader);
112 * By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
113 * this trait to parse the invoice and make sure they're signing what they expect, rather than
114 * blindly signing the hash.
115 * The `hrp` is ASCII bytes, while the invoice data is base32-encoded.
117 * The secret key used to sign the invoice is dependent on the [`Recipient`].
119 * Errors if the [`Recipient`] variant is not supported by the implementation.
121 Result_RecoverableSignatureNoneZ sign_invoice(byte[] _hrp_bytes, UInt5[] _invoice_data, Recipient _receipient);
123 * Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
125 * If the implementor of this trait supports [phantom node payments], then every node that is
126 * intended to be included in the phantom invoice route hints must return the same value from
129 * This method must return the same value each time it is called.
131 * [phantom node payments]: PhantomKeysManager
133 byte[] get_inbound_payment_key_material();
135 private class LDKKeysInterfaceHolder { internal KeysInterface held; }
136 private class LDKKeysInterfaceImpl : bindings.LDKKeysInterface {
137 internal LDKKeysInterfaceImpl(KeysInterfaceInterface arg, LDKKeysInterfaceHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
138 private KeysInterfaceInterface arg;
139 private LDKKeysInterfaceHolder impl_holder;
140 public long get_node_secret(Recipient _recipient) {
141 Result_SecretKeyNoneZ ret = arg.get_node_secret(_recipient);
143 long result = ret == null ? 0 : ret.clone_ptr();
146 public long get_node_id(Recipient _recipient) {
147 Result_PublicKeyNoneZ ret = arg.get_node_id(_recipient);
149 long result = ret == null ? 0 : ret.clone_ptr();
152 public long ecdh(Recipient _recipient, byte[] _other_key, long _tweak) {
153 org.ldk.structs.Option_ScalarZ _tweak_hu_conv = org.ldk.structs.Option_ScalarZ.constr_from_ptr(_tweak);
154 if (_tweak_hu_conv != null) { _tweak_hu_conv.ptrs_to.AddLast(this); };
155 Result_SharedSecretNoneZ ret = arg.ecdh(_recipient, _other_key, _tweak_hu_conv);
157 long result = ret == null ? 0 : ret.clone_ptr();
160 public byte[] get_destination_script() {
161 byte[] ret = arg.get_destination_script();
165 public long get_shutdown_scriptpubkey() {
166 ShutdownScript ret = arg.get_shutdown_scriptpubkey();
168 long result = ret == null ? 0 : ret.clone_ptr();
171 public byte[] generate_channel_keys_id(bool _inbound, long _channel_value_satoshis, byte[] _user_channel_id) {
172 org.ldk.util.UInt128 _user_channel_id_conv = new org.ldk.util.UInt128(_user_channel_id);
173 byte[] ret = arg.generate_channel_keys_id(_inbound, _channel_value_satoshis, _user_channel_id_conv);
175 byte[] result = InternalUtils.check_arr_len(ret, 32);
178 public long derive_channel_signer(long _channel_value_satoshis, byte[] _channel_keys_id) {
179 Sign ret = arg.derive_channel_signer(_channel_value_satoshis, _channel_keys_id);
181 long result = ret == null ? 0 : ret.clone_ptr();
182 if (impl_holder.held != null) { impl_holder.held.ptrs_to.AddLast(ret); };
185 public byte[] get_secure_random_bytes() {
186 byte[] ret = arg.get_secure_random_bytes();
188 byte[] result = InternalUtils.check_arr_len(ret, 32);
191 public long read_chan_signer(byte[] _reader) {
192 Result_SignDecodeErrorZ ret = arg.read_chan_signer(_reader);
194 long result = ret == null ? 0 : ret.clone_ptr();
197 public long sign_invoice(byte[] _hrp_bytes, byte[] _invoice_data, Recipient _receipient) {
198 int _invoice_data_conv_7_len = _invoice_data.Length;
199 UInt5[] _invoice_data_conv_7_arr = new UInt5[_invoice_data_conv_7_len];
200 for (int h = 0; h < _invoice_data_conv_7_len; h++) {
201 byte _invoice_data_conv_7 = _invoice_data[h];
202 UInt5 _invoice_data_conv_7_conv = new UInt5(_invoice_data_conv_7);
203 _invoice_data_conv_7_arr[h] = _invoice_data_conv_7_conv;
205 Result_RecoverableSignatureNoneZ ret = arg.sign_invoice(_hrp_bytes, _invoice_data_conv_7_arr, _receipient);
207 long result = ret == null ? 0 : ret.clone_ptr();
210 public byte[] get_inbound_payment_key_material() {
211 byte[] ret = arg.get_inbound_payment_key_material();
213 byte[] result = InternalUtils.check_arr_len(ret, 32);
217 public static KeysInterface new_impl(KeysInterfaceInterface arg) {
218 LDKKeysInterfaceHolder impl_holder = new LDKKeysInterfaceHolder();
219 impl_holder.held = new KeysInterface(new LDKKeysInterfaceImpl(arg, impl_holder));
220 return impl_holder.held;
223 * Get node secret key based on the provided [`Recipient`].
225 * The `node_id`/`network_key` is the public key that corresponds to this secret key.
227 * This method must return the same value each time it is called with a given [`Recipient`]
230 * Errors if the [`Recipient`] variant is not supported by the implementation.
232 public Result_SecretKeyNoneZ get_node_secret(Recipient recipient) {
233 long ret = bindings.KeysInterface_get_node_secret(this.ptr, recipient);
235 GC.KeepAlive(recipient);
236 if (ret >= 0 && ret <= 4096) { return null; }
237 Result_SecretKeyNoneZ ret_hu_conv = Result_SecretKeyNoneZ.constr_from_ptr(ret);
242 * Get node id based on the provided [`Recipient`]. This public key corresponds to the secret in
243 * [`get_node_secret`].
245 * This method must return the same value each time it is called with a given [`Recipient`]
248 * Errors if the [`Recipient`] variant is not supported by the implementation.
250 * [`get_node_secret`]: Self::get_node_secret
252 public Result_PublicKeyNoneZ get_node_id(Recipient recipient) {
253 long ret = bindings.KeysInterface_get_node_id(this.ptr, recipient);
255 GC.KeepAlive(recipient);
256 if (ret >= 0 && ret <= 4096) { return null; }
257 Result_PublicKeyNoneZ ret_hu_conv = Result_PublicKeyNoneZ.constr_from_ptr(ret);
262 * Gets the ECDH shared secret of our [`node secret`] and `other_key`, multiplying by `tweak` if
263 * one is provided. Note that this tweak can be applied to `other_key` instead of our node
264 * secret, though this is less efficient.
266 * Errors if the [`Recipient`] variant is not supported by the implementation.
268 * [`node secret`]: Self::get_node_secret
270 public Result_SharedSecretNoneZ ecdh(Recipient recipient, byte[] other_key, org.ldk.structs.Option_ScalarZ tweak) {
271 long ret = bindings.KeysInterface_ecdh(this.ptr, recipient, InternalUtils.check_arr_len(other_key, 33), tweak.ptr);
273 GC.KeepAlive(recipient);
274 GC.KeepAlive(other_key);
276 if (ret >= 0 && ret <= 4096) { return null; }
277 Result_SharedSecretNoneZ ret_hu_conv = Result_SharedSecretNoneZ.constr_from_ptr(ret);
282 * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
284 * This method should return a different value each time it is called, to avoid linking
285 * on-chain funds across channels as controlled to the same user.
287 public byte[] get_destination_script() {
288 byte[] ret = bindings.KeysInterface_get_destination_script(this.ptr);
294 * Get a script pubkey which we will send funds to when closing a channel.
296 * This method should return a different value each time it is called, to avoid linking
297 * on-chain funds across channels as controlled to the same user.
299 public ShutdownScript get_shutdown_scriptpubkey() {
300 long ret = bindings.KeysInterface_get_shutdown_scriptpubkey(this.ptr);
302 if (ret >= 0 && ret <= 4096) { return null; }
303 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
304 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
309 * Get a new set of [`Sign`] for per-channel secrets. These MUST be unique even if you
310 * restarted with some stale data!
312 * This method must return a different value each time it is called.
314 public byte[] generate_channel_keys_id(bool inbound, long channel_value_satoshis, org.ldk.util.UInt128 user_channel_id) {
315 byte[] ret = bindings.KeysInterface_generate_channel_keys_id(this.ptr, inbound, channel_value_satoshis, user_channel_id.getLEBytes());
317 GC.KeepAlive(inbound);
318 GC.KeepAlive(channel_value_satoshis);
319 GC.KeepAlive(user_channel_id);
324 * Derives the private key material backing a `Signer`.
326 * To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
327 * [`KeysInterface::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
328 * re-derived from its `channel_keys_id`, which can be obtained through its trait method
329 * [`BaseSign::channel_keys_id`].
331 public Sign derive_channel_signer(long channel_value_satoshis, byte[] channel_keys_id) {
332 long ret = bindings.KeysInterface_derive_channel_signer(this.ptr, channel_value_satoshis, InternalUtils.check_arr_len(channel_keys_id, 32));
334 GC.KeepAlive(channel_value_satoshis);
335 GC.KeepAlive(channel_keys_id);
336 if (ret >= 0 && ret <= 4096) { return null; }
337 Sign ret_hu_conv = new Sign(null, ret);
338 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
343 * Gets a unique, cryptographically-secure, random 32 byte value. This is used for encrypting
344 * onion packets and for temporary channel IDs. There is no requirement that these be
345 * persisted anywhere, though they must be unique across restarts.
347 * This method must return a different value each time it is called.
349 public byte[] get_secure_random_bytes() {
350 byte[] ret = bindings.KeysInterface_get_secure_random_bytes(this.ptr);
356 * Reads a [`Signer`] for this [`KeysInterface`] from the given input stream.
357 * This is only called during deserialization of other objects which contain
358 * [`Sign`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
359 * The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
360 * contain no versioning scheme. You may wish to include your own version prefix and ensure
361 * you've read all of the provided bytes to ensure no corruption occurred.
363 * This method is slowly being phased out -- it will only be called when reading objects
364 * written by LDK versions prior to 0.0.113.
366 * [`Signer`]: Self::Signer
367 * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
368 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
370 public Result_SignDecodeErrorZ read_chan_signer(byte[] reader) {
371 long ret = bindings.KeysInterface_read_chan_signer(this.ptr, reader);
373 GC.KeepAlive(reader);
374 if (ret >= 0 && ret <= 4096) { return null; }
375 Result_SignDecodeErrorZ ret_hu_conv = Result_SignDecodeErrorZ.constr_from_ptr(ret);
381 * By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
382 * this trait to parse the invoice and make sure they're signing what they expect, rather than
383 * blindly signing the hash.
384 * The `hrp` is ASCII bytes, while the invoice data is base32-encoded.
386 * The secret key used to sign the invoice is dependent on the [`Recipient`].
388 * Errors if the [`Recipient`] variant is not supported by the implementation.
390 public Result_RecoverableSignatureNoneZ sign_invoice(byte[] hrp_bytes, UInt5[] invoice_data, Recipient receipient) {
391 long ret = bindings.KeysInterface_sign_invoice(this.ptr, hrp_bytes, invoice_data != null ? InternalUtils.convUInt5Array(invoice_data) : null, receipient);
393 GC.KeepAlive(hrp_bytes);
394 GC.KeepAlive(invoice_data);
395 GC.KeepAlive(receipient);
396 if (ret >= 0 && ret <= 4096) { return null; }
397 Result_RecoverableSignatureNoneZ ret_hu_conv = Result_RecoverableSignatureNoneZ.constr_from_ptr(ret);
402 * Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
404 * If the implementor of this trait supports [phantom node payments], then every node that is
405 * intended to be included in the phantom invoice route hints must return the same value from
408 * This method must return the same value each time it is called.
410 * [phantom node payments]: PhantomKeysManager
412 public byte[] get_inbound_payment_key_material() {
413 byte[] ret = bindings.KeysInterface_get_inbound_payment_key_material(this.ptr);