X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FBaseSign.java;h=b502674c740885f1cd262e2a184468c037a5dd61;hb=c6bac88847b7c09560af81f00ba8dd3c2ebe3a19;hp=b94a5c1bdee0aa6c270b89a55c22c3bcbedf0c25;hpb=b0c50b891cbca28d3bd1d86276c132ff5221d8e4;p=ldk-java diff --git a/src/main/java/org/ldk/structs/BaseSign.java b/src/main/java/org/ldk/structs/BaseSign.java index b94a5c1b..b502674c 100644 --- a/src/main/java/org/ldk/structs/BaseSign.java +++ b/src/main/java/org/ldk/structs/BaseSign.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 sign lightning channel transactions as described in BOLT 3. @@ -31,7 +32,6 @@ public class BaseSign extends CommonBase { private BaseSign(bindings.LDKBaseSign arg, ChannelPublicKeys pubkeys) { super(bindings.LDKBaseSign_new(arg, pubkeys == null ? 0 : pubkeys.ptr & ~1)); this.ptrs_to.add(arg); - this.ptrs_to.add(pubkeys); this.bindings_instance = arg; } @Override @SuppressWarnings("deprecation") @@ -57,6 +57,15 @@ public class BaseSign extends CommonBase { * Note that the commitment number starts at (1 << 48) - 1 and counts backwards. */ byte[] release_commitment_secret(long idx); + /** + * Validate the counterparty's signatures on the holder commitment transaction and HTLCs. + * + * This is required in order for the signer to make sure that releasing a commitment + * secret won't leave us without a broadcastable holder transaction. + * Policy checks should be implemented in this function, including checking the amount + * sent to us and checking the HTLCs. + */ + Result_NoneNoneZ validate_holder_commitment(HolderCommitmentTransaction holder_tx); /** * Gets an arbitrary identifier describing the set of keys which are provided back to you in * some SpendableOutputDescriptor types. This should be sufficient to identify this @@ -67,8 +76,18 @@ public class BaseSign extends CommonBase { * Create a signature for a counterparty's commitment transaction and associated HTLC transactions. * * Note that if signing fails or is rejected, the channel will be force-closed. + * + * Policy checks should be implemented in this function, including checking the amount + * sent to us and checking the HTLCs. */ Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(CommitmentTransaction commitment_tx); + /** + * Validate the counterparty's revocation. + * + * This is required in order for the signer to make sure that the state has moved + * forward and it is safe to sign the next counterparty commitment. + */ + Result_NoneNoneZ validate_counterparty_revocation(long idx, byte[] secret); /** * Create a signatures for a holder's commitment transaction and its claiming HTLC transactions. * This will only ever be called with a non-revoked commitment_tx. This will be called with the @@ -146,7 +165,7 @@ public class BaseSign extends CommonBase { * Note that, due to rounding, there may be one \"missing\" satoshi, and either party may have * chosen to forgo their output as dust. */ - Result_SignatureNoneZ sign_closing_transaction(byte[] closing_tx); + Result_SignatureNoneZ sign_closing_transaction(ClosingTransaction closing_tx); /** * Signs a channel announcement message with our funding key, proving it comes from one * of the channel participants. @@ -182,18 +201,29 @@ public class BaseSign extends CommonBase { byte[] ret = arg.release_commitment_secret(idx); return ret; } + @Override public long validate_holder_commitment(long holder_tx) { + HolderCommitmentTransaction holder_tx_hu_conv = null; if (holder_tx < 0 || holder_tx > 4096) { holder_tx_hu_conv = new HolderCommitmentTransaction(null, holder_tx); } + Result_NoneNoneZ ret = arg.validate_holder_commitment(holder_tx_hu_conv); + long result = ret != null ? ret.ptr : 0; + return result; + } @Override public byte[] channel_keys_id() { byte[] ret = arg.channel_keys_id(); return ret; } @Override public long sign_counterparty_commitment(long commitment_tx) { - CommitmentTransaction commitment_tx_hu_conv = new CommitmentTransaction(null, commitment_tx); + CommitmentTransaction commitment_tx_hu_conv = null; if (commitment_tx < 0 || commitment_tx > 4096) { commitment_tx_hu_conv = new CommitmentTransaction(null, commitment_tx); } Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret = arg.sign_counterparty_commitment(commitment_tx_hu_conv); long result = ret != null ? ret.ptr : 0; return result; } + @Override public long validate_counterparty_revocation(long idx, byte[] secret) { + Result_NoneNoneZ ret = arg.validate_counterparty_revocation(idx, secret); + long result = ret != null ? ret.ptr : 0; + return result; + } @Override public long sign_holder_commitment_and_htlcs(long commitment_tx) { - HolderCommitmentTransaction commitment_tx_hu_conv = new HolderCommitmentTransaction(null, commitment_tx); + HolderCommitmentTransaction commitment_tx_hu_conv = null; if (commitment_tx < 0 || commitment_tx > 4096) { commitment_tx_hu_conv = new HolderCommitmentTransaction(null, commitment_tx); } Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret = arg.sign_holder_commitment_and_htlcs(commitment_tx_hu_conv); long result = ret != null ? ret.ptr : 0; return result; @@ -204,30 +234,31 @@ public class BaseSign extends CommonBase { return result; } @Override public long sign_justice_revoked_htlc(byte[] justice_tx, long input, long amount, byte[] per_commitment_key, long htlc) { - HTLCOutputInCommitment htlc_hu_conv = new HTLCOutputInCommitment(null, htlc); + HTLCOutputInCommitment htlc_hu_conv = null; if (htlc < 0 || htlc > 4096) { htlc_hu_conv = new HTLCOutputInCommitment(null, htlc); } Result_SignatureNoneZ ret = arg.sign_justice_revoked_htlc(justice_tx, input, amount, per_commitment_key, htlc_hu_conv); long result = ret != null ? ret.ptr : 0; return result; } @Override public long sign_counterparty_htlc_transaction(byte[] htlc_tx, long input, long amount, byte[] per_commitment_point, long htlc) { - HTLCOutputInCommitment htlc_hu_conv = new HTLCOutputInCommitment(null, htlc); + HTLCOutputInCommitment htlc_hu_conv = null; if (htlc < 0 || htlc > 4096) { htlc_hu_conv = new HTLCOutputInCommitment(null, htlc); } Result_SignatureNoneZ ret = arg.sign_counterparty_htlc_transaction(htlc_tx, input, amount, per_commitment_point, htlc_hu_conv); long result = ret != null ? ret.ptr : 0; return result; } - @Override public long sign_closing_transaction(byte[] closing_tx) { - Result_SignatureNoneZ ret = arg.sign_closing_transaction(closing_tx); + @Override public long sign_closing_transaction(long closing_tx) { + ClosingTransaction closing_tx_hu_conv = null; if (closing_tx < 0 || closing_tx > 4096) { closing_tx_hu_conv = new ClosingTransaction(null, closing_tx); } + Result_SignatureNoneZ ret = arg.sign_closing_transaction(closing_tx_hu_conv); long result = ret != null ? ret.ptr : 0; return result; } @Override public long sign_channel_announcement(long msg) { - UnsignedChannelAnnouncement msg_hu_conv = new UnsignedChannelAnnouncement(null, msg); + UnsignedChannelAnnouncement msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new UnsignedChannelAnnouncement(null, msg); } Result_SignatureNoneZ ret = arg.sign_channel_announcement(msg_hu_conv); long result = ret != null ? ret.ptr : 0; return result; } @Override public void ready_channel(long channel_parameters) { - ChannelTransactionParameters channel_parameters_hu_conv = new ChannelTransactionParameters(null, channel_parameters); + ChannelTransactionParameters channel_parameters_hu_conv = null; if (channel_parameters < 0 || channel_parameters > 4096) { channel_parameters_hu_conv = new ChannelTransactionParameters(null, channel_parameters); } arg.ready_channel(channel_parameters_hu_conv); } }, pubkeys); @@ -258,6 +289,22 @@ public class BaseSign extends CommonBase { return ret; } + /** + * Validate the counterparty's signatures on the holder commitment transaction and HTLCs. + * + * This is required in order for the signer to make sure that releasing a commitment + * secret won't leave us without a broadcastable holder transaction. + * Policy checks should be implemented in this function, including checking the amount + * sent to us and checking the HTLCs. + */ + public Result_NoneNoneZ validate_holder_commitment(HolderCommitmentTransaction holder_tx) { + long ret = bindings.BaseSign_validate_holder_commitment(this.ptr, holder_tx == null ? 0 : holder_tx.ptr & ~1); + if (ret >= 0 && ret <= 4096) { return null; } + Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret); + this.ptrs_to.add(holder_tx); + return ret_hu_conv; + } + /** * Gets an arbitrary identifier describing the set of keys which are provided back to you in * some SpendableOutputDescriptor types. This should be sufficient to identify this @@ -272,14 +319,31 @@ public class BaseSign extends CommonBase { * Create a signature for a counterparty's commitment transaction and associated HTLC transactions. * * Note that if signing fails or is rejected, the channel will be force-closed. + * + * Policy checks should be implemented in this function, including checking the amount + * sent to us and checking the HTLCs. */ public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(CommitmentTransaction commitment_tx) { long ret = bindings.BaseSign_sign_counterparty_commitment(this.ptr, commitment_tx == null ? 0 : commitment_tx.ptr & ~1); + if (ret >= 0 && ret <= 4096) { return null; } Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_hu_conv = Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.constr_from_ptr(ret); this.ptrs_to.add(commitment_tx); return ret_hu_conv; } + /** + * Validate the counterparty's revocation. + * + * This is required in order for the signer to make sure that the state has moved + * forward and it is safe to sign the next counterparty commitment. + */ + public Result_NoneNoneZ validate_counterparty_revocation(long idx, byte[] secret) { + long ret = bindings.BaseSign_validate_counterparty_revocation(this.ptr, idx, secret); + if (ret >= 0 && ret <= 4096) { return null; } + Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret); + return ret_hu_conv; + } + /** * Create a signatures for a holder's commitment transaction and its claiming HTLC transactions. * This will only ever be called with a non-revoked commitment_tx. This will be called with the @@ -295,6 +359,7 @@ public class BaseSign extends CommonBase { */ public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_holder_commitment_and_htlcs(HolderCommitmentTransaction commitment_tx) { long ret = bindings.BaseSign_sign_holder_commitment_and_htlcs(this.ptr, commitment_tx == null ? 0 : commitment_tx.ptr & ~1); + if (ret >= 0 && ret <= 4096) { return null; } Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_hu_conv = Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.constr_from_ptr(ret); this.ptrs_to.add(commitment_tx); return ret_hu_conv; @@ -318,6 +383,7 @@ public class BaseSign extends CommonBase { */ public Result_SignatureNoneZ sign_justice_revoked_output(byte[] justice_tx, long input, long amount, byte[] per_commitment_key) { long ret = bindings.BaseSign_sign_justice_revoked_output(this.ptr, justice_tx, input, amount, per_commitment_key); + if (ret >= 0 && ret <= 4096) { return null; } Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret); return ret_hu_conv; } @@ -343,6 +409,7 @@ public class BaseSign extends CommonBase { */ public Result_SignatureNoneZ sign_justice_revoked_htlc(byte[] justice_tx, long input, long amount, byte[] per_commitment_key, HTLCOutputInCommitment htlc) { long ret = bindings.BaseSign_sign_justice_revoked_htlc(this.ptr, justice_tx, input, amount, per_commitment_key, htlc == null ? 0 : htlc.ptr & ~1); + if (ret >= 0 && ret <= 4096) { return null; } Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret); this.ptrs_to.add(htlc); return ret_hu_conv; @@ -369,6 +436,7 @@ public class BaseSign extends CommonBase { */ public Result_SignatureNoneZ sign_counterparty_htlc_transaction(byte[] htlc_tx, long input, long amount, byte[] per_commitment_point, HTLCOutputInCommitment htlc) { long ret = bindings.BaseSign_sign_counterparty_htlc_transaction(this.ptr, htlc_tx, input, amount, per_commitment_point, htlc == null ? 0 : htlc.ptr & ~1); + if (ret >= 0 && ret <= 4096) { return null; } Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret); this.ptrs_to.add(htlc); return ret_hu_conv; @@ -380,9 +448,11 @@ public class BaseSign extends CommonBase { * Note that, due to rounding, there may be one \"missing\" satoshi, and either party may have * chosen to forgo their output as dust. */ - public Result_SignatureNoneZ sign_closing_transaction(byte[] closing_tx) { - long ret = bindings.BaseSign_sign_closing_transaction(this.ptr, closing_tx); + public Result_SignatureNoneZ sign_closing_transaction(ClosingTransaction closing_tx) { + long ret = bindings.BaseSign_sign_closing_transaction(this.ptr, closing_tx == null ? 0 : closing_tx.ptr & ~1); + if (ret >= 0 && ret <= 4096) { return null; } Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret); + this.ptrs_to.add(closing_tx); return ret_hu_conv; } @@ -396,6 +466,7 @@ public class BaseSign extends CommonBase { */ public Result_SignatureNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg) { long ret = bindings.BaseSign_sign_channel_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1); + if (ret >= 0 && ret <= 4096) { return null; } Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret); this.ptrs_to.add(msg); return ret_hu_conv; @@ -424,7 +495,8 @@ public class BaseSign extends CommonBase { */ public ChannelPublicKeys get_pubkeys() { long ret = bindings.BaseSign_get_pubkeys(this.ptr); - ChannelPublicKeys ret_hu_conv = new ChannelPublicKeys(null, ret); + if (ret >= 0 && ret <= 4096) { return null; } + ChannelPublicKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelPublicKeys(null, ret); } ret_hu_conv.ptrs_to.add(this); return ret_hu_conv; }