X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FKeysInterface.java;h=e4c8e486312e0a048b46ddfbe4addda6d90a28b3;hb=f3e670e9341decac613d33fc52febf19cea32f20;hp=bbb5df9856e0c9f78ed67f9362e9d266f80bc8b1;hpb=1b870a3ffab1c0024411e30102bc6d198300f095;p=ldk-java diff --git a/src/main/java/org/ldk/structs/KeysInterface.java b/src/main/java/org/ldk/structs/KeysInterface.java index bbb5df98..e4c8e486 100644 --- a/src/main/java/org/ldk/structs/KeysInterface.java +++ b/src/main/java/org/ldk/structs/KeysInterface.java @@ -4,6 +4,7 @@ import org.ldk.impl.bindings; import org.ldk.enums.*; import org.ldk.util.*; import java.util.Arrays; +import javax.annotation.Nullable; /** * A trait to describe an object which can get user secrets and key material. @@ -37,13 +38,12 @@ public class KeysInterface extends CommonBase { */ byte[] get_destination_script(); /** - * Get a public key which we will send funds to (in the form of a P2WPKH output) when closing - * a channel. + * Get a script pubkey which we will send funds to when closing a channel. * * This method should return a different value each time it is called, to avoid linking * on-chain funds across channels as controlled to the same user. */ - byte[] get_shutdown_pubkey(); + ShutdownScript get_shutdown_scriptpubkey(); /** * Get a new set of Sign for per-channel secrets. These MUST be unique even if you * restarted with some stale data! @@ -68,6 +68,13 @@ public class KeysInterface extends CommonBase { * you've read all of the provided bytes to ensure no corruption occurred. */ Result_SignDecodeErrorZ read_chan_signer(byte[] reader); + /** + * Sign an invoice's preimage (note that this is the preimage of the invoice, not the HTLC's + * preimage). By parameterizing by the preimage 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. + */ + Result_RecoverableSignatureNoneZ sign_invoice(byte[] invoice_preimage); } private static class LDKKeysInterfaceHolder { KeysInterface held; } public static KeysInterface new_impl(KeysInterfaceInterface arg) { @@ -75,29 +82,37 @@ public class KeysInterface extends CommonBase { impl_holder.held = new KeysInterface(new bindings.LDKKeysInterface() { @Override public byte[] get_node_secret() { byte[] ret = arg.get_node_secret(); - return ret; + byte[] result = InternalUtils.check_arr_len(ret, 32); + return result; } @Override public byte[] get_destination_script() { byte[] ret = arg.get_destination_script(); return ret; } - @Override public byte[] get_shutdown_pubkey() { - byte[] ret = arg.get_shutdown_pubkey(); - return ret; + @Override public long get_shutdown_scriptpubkey() { + ShutdownScript ret = arg.get_shutdown_scriptpubkey(); + long result = ret == null ? 0 : ret.clone_ptr(); + return result; } @Override public long get_channel_signer(boolean inbound, long channel_value_satoshis) { Sign ret = arg.get_channel_signer(inbound, channel_value_satoshis); - long result = ret == null ? 0 : ret.ptr; + long result = ret == null ? 0 : ret.clone_ptr(); impl_holder.held.ptrs_to.add(ret); return result; } @Override public byte[] get_secure_random_bytes() { byte[] ret = arg.get_secure_random_bytes(); - return ret; + byte[] result = InternalUtils.check_arr_len(ret, 32); + return result; } @Override public long read_chan_signer(byte[] reader) { Result_SignDecodeErrorZ ret = arg.read_chan_signer(reader); - long result = ret != null ? ret.ptr : 0; + long result = ret == null ? 0 : ret.clone_ptr(); + return result; + } + @Override public long sign_invoice(byte[] invoice_preimage) { + Result_RecoverableSignatureNoneZ ret = arg.sign_invoice(invoice_preimage); + long result = ret == null ? 0 : ret.clone_ptr(); return result; } }); @@ -125,15 +140,17 @@ public class KeysInterface extends CommonBase { } /** - * Get a public key which we will send funds to (in the form of a P2WPKH output) when closing - * a channel. + * Get a script pubkey which we will send funds to when closing a channel. * * This method should return a different value each time it is called, to avoid linking * on-chain funds across channels as controlled to the same user. */ - public byte[] get_shutdown_pubkey() { - byte[] ret = bindings.KeysInterface_get_shutdown_pubkey(this.ptr); - return ret; + public ShutdownScript get_shutdown_scriptpubkey() { + long ret = bindings.KeysInterface_get_shutdown_scriptpubkey(this.ptr); + if (ret >= 0 && ret <= 4096) { return null; } + ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ShutdownScript(null, ret); } + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; } /** @@ -144,6 +161,7 @@ public class KeysInterface extends CommonBase { */ public Sign get_channel_signer(boolean inbound, long channel_value_satoshis) { long ret = bindings.KeysInterface_get_channel_signer(this.ptr, inbound, channel_value_satoshis); + if (ret >= 0 && ret <= 4096) { return null; } Sign ret_hu_conv = new Sign(null, ret); ret_hu_conv.ptrs_to.add(this); return ret_hu_conv; @@ -171,8 +189,22 @@ public class KeysInterface extends CommonBase { */ public Result_SignDecodeErrorZ read_chan_signer(byte[] reader) { long ret = bindings.KeysInterface_read_chan_signer(this.ptr, reader); + if (ret >= 0 && ret <= 4096) { return null; } Result_SignDecodeErrorZ ret_hu_conv = Result_SignDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; } + /** + * Sign an invoice's preimage (note that this is the preimage of the invoice, not the HTLC's + * preimage). By parameterizing by the preimage 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. + */ + public Result_RecoverableSignatureNoneZ sign_invoice(byte[] invoice_preimage) { + long ret = bindings.KeysInterface_sign_invoice(this.ptr, invoice_preimage); + if (ret >= 0 && ret <= 4096) { return null; } + Result_RecoverableSignatureNoneZ ret_hu_conv = Result_RecoverableSignatureNoneZ.constr_from_ptr(ret); + return ret_hu_conv; + } + }