update to refactor signature verification

This commit is contained in:
Craig Raw 2020-03-30 11:41:02 +02:00
parent fd94e885b8
commit a1696ec2e8
4 changed files with 20 additions and 20 deletions

View file

@ -110,7 +110,7 @@ public class Script {
* Returns true if this script has the required form to contain a destination address
*/
public boolean containsToAddress() {
return ScriptPattern.isP2PK(this) || ScriptPattern.isP2PKH(this) || ScriptPattern.isP2SH(this) || ScriptPattern.isP2WPKH(this) || ScriptPattern.isP2WSH(this) || ScriptPattern.isSentToMultisig(this);
return ScriptPattern.isP2PK(this) || ScriptPattern.isP2PKH(this) || ScriptPattern.isP2SH(this) || ScriptPattern.isP2WPKH(this) || ScriptPattern.isP2WSH(this) || ScriptPattern.isMultisig(this);
}
/**
@ -143,7 +143,7 @@ public class Script {
return new Address[] { new P2WPKHAddress(ScriptPattern.extractHashFromP2WH(this)) };
else if (ScriptPattern.isP2WSH(this))
return new Address[] { new P2WSHAddress(ScriptPattern.extractHashFromP2WH(this)) };
else if (ScriptPattern.isSentToMultisig(this))
else if (ScriptPattern.isMultisig(this))
return ScriptPattern.extractMultisigAddresses(this);
else
throw new NonStandardScriptException("Cannot find addresses in non standard script: " + toString());
@ -154,7 +154,7 @@ public class Script {
return 1;
}
if(ScriptPattern.isSentToMultisig(this)) {
if(ScriptPattern.isMultisig(this)) {
return ScriptPattern.extractMultisigThreshold(this);
}

View file

@ -110,7 +110,7 @@ public class ScriptPattern {
* Returns whether this script matches the format used for multisig outputs:
* {@code [n] [keys...] [m] CHECKMULTISIG}
*/
public static boolean isSentToMultisig(Script script) {
public static boolean isMultisig(Script script) {
List<ScriptChunk> chunks = script.chunks;
if (chunks.size() < 4) return false;
ScriptChunk chunk = chunks.get(chunks.size() - 1);

View file

@ -251,8 +251,8 @@ public class PSBT {
PSBTInput input = new PSBTInput(inputEntries, transaction, inputIndex);
boolean verified = input.verifySignatures();
if(verified) {
log.debug("Verified signatures on input #" + inputIndex);
if(!verified && input.getPartialSignatures().size() > 0) {
throw new IllegalStateException("Unverifiable partial signatures provided");
}
this.psbtInputs.add(input);

View file

@ -240,7 +240,7 @@ public class PSBTInput {
public boolean isSigned() throws NonStandardScriptException {
//All partial sigs are already verified
int reqSigs = getConnectedScript().getNumRequiredSignatures();
int reqSigs = getSigningScript().getNumRequiredSignatures();
int sigs = getPartialSignatures().size();
return sigs == reqSigs;
}
@ -253,9 +253,9 @@ public class PSBTInput {
}
if(getNonWitnessUtxo() != null || getWitnessUtxo() != null) {
Script connectedScript = getConnectedScript();
if(connectedScript != null) {
Sha256Hash hash = getHashForSignature(connectedScript, localSigHash);
Script signingScript = getSigningScript();
if(signingScript != null) {
Sha256Hash hash = getHashForSignature(signingScript, localSigHash);
for(ECKey sigPublicKey : getPartialSignatures().keySet()) {
TransactionSignature signature = getPartialSignature(sigPublicKey);
@ -271,30 +271,30 @@ public class PSBTInput {
return false;
}
public Script getConnectedScript() {
public Script getSigningScript() {
int vout = (int)transaction.getInputs().get(index).getOutpoint().getIndex();
Script connectedScript = getNonWitnessUtxo() != null ? getNonWitnessUtxo().getOutputs().get(vout).getScript() : getWitnessUtxo().getScript();
Script signingScript = getNonWitnessUtxo() != null ? getNonWitnessUtxo().getOutputs().get(vout).getScript() : getWitnessUtxo().getScript();
if(ScriptPattern.isP2SH(connectedScript)) {
if(ScriptPattern.isP2SH(signingScript)) {
if(getRedeemScript() == null) {
return null;
} else {
connectedScript = getRedeemScript();
signingScript = getRedeemScript();
}
}
if(ScriptPattern.isP2WPKH(connectedScript)) {
Address address = new P2PKHAddress(connectedScript.getPubKeyHash());
connectedScript = address.getOutputScript();
} else if(ScriptPattern.isP2WSH(connectedScript)) {
if(ScriptPattern.isP2WPKH(signingScript)) {
Address address = new P2PKHAddress(signingScript.getPubKeyHash());
signingScript = address.getOutputScript();
} else if(ScriptPattern.isP2WSH(signingScript)) {
if(getWitnessScript() == null) {
return null;
} else {
connectedScript = getWitnessScript();
signingScript = getWitnessScript();
}
}
return connectedScript;
return signingScript;
}
private Sha256Hash getHashForSignature(Script connectedScript, Transaction.SigHash localSigHash) {