mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-11-03 05:57:21 +00:00
Payment channels: Add KeyParameter arguments to Transaction.calculateSignature
This commit is contained in:
committed by
Andreas Schildbach
parent
2e09ed8581
commit
56f1db8dd8
@@ -31,6 +31,7 @@ import com.google.common.primitives.Ints;
|
||||
import com.google.common.primitives.Longs;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.spongycastle.crypto.params.KeyParameter;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.*;
|
||||
@@ -908,6 +909,49 @@ public class Transaction extends ChildMessage {
|
||||
return new TransactionSignature(key.sign(hash), hashType, anyoneCanPay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates a signature that is valid for being inserted into the input at the given position. This is simply
|
||||
* a wrapper around calling {@link Transaction#hashForSignature(int, byte[], org.bitcoinj.core.Transaction.SigHash, boolean)}
|
||||
* followed by {@link ECKey#sign(Sha256Hash)} and then returning a new {@link TransactionSignature}. The key
|
||||
* must be usable for signing as-is: if the key is encrypted it must be decrypted first external to this method.
|
||||
*
|
||||
* @param inputIndex Which input to calculate the signature for, as an index.
|
||||
* @param key The private key used to calculate the signature.
|
||||
* @param aesKey The AES key to use for decryption of the private key. If null then no decryption is required.
|
||||
* @param redeemScript Byte-exact contents of the scriptPubKey that is being satisified, or the P2SH redeem script.
|
||||
* @param hashType Signing mode, see the enum for documentation.
|
||||
* @param anyoneCanPay Signing mode, see the SigHash enum for documentation.
|
||||
* @return A newly calculated signature object that wraps the r, s and sighash components.
|
||||
*/
|
||||
public TransactionSignature calculateSignature(int inputIndex, ECKey key,
|
||||
@Nullable KeyParameter aesKey,
|
||||
byte[] redeemScript,
|
||||
SigHash hashType, boolean anyoneCanPay) {
|
||||
Sha256Hash hash = hashForSignature(inputIndex, redeemScript, hashType, anyoneCanPay);
|
||||
return new TransactionSignature(key.sign(hash, aesKey), hashType, anyoneCanPay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates a signature that is valid for being inserted into the input at the given position. This is simply
|
||||
* a wrapper around calling {@link Transaction#hashForSignature(int, byte[], org.bitcoinj.core.Transaction.SigHash, boolean)}
|
||||
* followed by {@link ECKey#sign(Sha256Hash)} and then returning a new {@link TransactionSignature}.
|
||||
*
|
||||
* @param inputIndex Which input to calculate the signature for, as an index.
|
||||
* @param key The private key used to calculate the signature.
|
||||
* @param aesKey The AES key to use for decryption of the private key. If null then no decryption is required.
|
||||
* @param redeemScript The scriptPubKey that is being satisified, or the P2SH redeem script.
|
||||
* @param hashType Signing mode, see the enum for documentation.
|
||||
* @param anyoneCanPay Signing mode, see the SigHash enum for documentation.
|
||||
* @return A newly calculated signature object that wraps the r, s and sighash components.
|
||||
*/
|
||||
public TransactionSignature calculateSignature(int inputIndex, ECKey key,
|
||||
@Nullable KeyParameter aesKey,
|
||||
Script redeemScript,
|
||||
SigHash hashType, boolean anyoneCanPay) {
|
||||
Sha256Hash hash = hashForSignature(inputIndex, redeemScript.getProgram(), hashType, anyoneCanPay);
|
||||
return new TransactionSignature(key.sign(hash, aesKey), hashType, anyoneCanPay);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Calculates a signature hash, that is, a hash of a simplified form of the transaction. How exactly the transaction
|
||||
* is simplified is specified by the type and anyoneCanPay parameters.</p>
|
||||
|
||||
Reference in New Issue
Block a user