diff --git a/src/main/java/com/craigraw/drongo/protocol/Script.java b/src/main/java/com/craigraw/drongo/protocol/Script.java index 2e95543..5556ab3 100644 --- a/src/main/java/com/craigraw/drongo/protocol/Script.java +++ b/src/main/java/com/craigraw/drongo/protocol/Script.java @@ -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); } diff --git a/src/main/java/com/craigraw/drongo/protocol/ScriptPattern.java b/src/main/java/com/craigraw/drongo/protocol/ScriptPattern.java index b8192d3..b493c5b 100644 --- a/src/main/java/com/craigraw/drongo/protocol/ScriptPattern.java +++ b/src/main/java/com/craigraw/drongo/protocol/ScriptPattern.java @@ -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 chunks = script.chunks; if (chunks.size() < 4) return false; ScriptChunk chunk = chunks.get(chunks.size() - 1); diff --git a/src/main/java/com/craigraw/drongo/psbt/PSBT.java b/src/main/java/com/craigraw/drongo/psbt/PSBT.java index 72874fc..1a5cc3a 100644 --- a/src/main/java/com/craigraw/drongo/psbt/PSBT.java +++ b/src/main/java/com/craigraw/drongo/psbt/PSBT.java @@ -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); diff --git a/src/main/java/com/craigraw/drongo/psbt/PSBTInput.java b/src/main/java/com/craigraw/drongo/psbt/PSBTInput.java index 8dcb012..0521943 100644 --- a/src/main/java/com/craigraw/drongo/psbt/PSBTInput.java +++ b/src/main/java/com/craigraw/drongo/psbt/PSBTInput.java @@ -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) {