Search in sources :

Example 1 with ECDSASignature

use of com.sparrowwallet.drongo.crypto.ECDSASignature in project drongo by sparrowwallet.

the class PSBTInput method sign.

public boolean sign(ECKey privKey) {
    SigHash localSigHash = getSigHash();
    if (localSigHash == null) {
        localSigHash = getDefaultSigHash();
    }
    if (getNonWitnessUtxo() != null || getWitnessUtxo() != null) {
        Script signingScript = getSigningScript();
        if (signingScript != null) {
            Sha256Hash hash = getHashForSignature(signingScript, localSigHash);
            if (isTaproot()) {
                SchnorrSignature schnorrSignature = privKey.signSchnorr(hash);
                tapKeyPathSignature = new TransactionSignature(schnorrSignature, localSigHash);
                return true;
            } else {
                ECDSASignature ecdsaSignature = privKey.signEcdsa(hash);
                TransactionSignature transactionSignature = new TransactionSignature(ecdsaSignature, localSigHash);
                ECKey pubKey = ECKey.fromPublicOnly(privKey);
                getPartialSignatures().put(pubKey, transactionSignature);
                return true;
            }
        }
    }
    return false;
}
Also used : SchnorrSignature(com.sparrowwallet.drongo.crypto.SchnorrSignature) ECDSASignature(com.sparrowwallet.drongo.crypto.ECDSASignature) ECKey(com.sparrowwallet.drongo.crypto.ECKey)

Aggregations

ECDSASignature (com.sparrowwallet.drongo.crypto.ECDSASignature)1 ECKey (com.sparrowwallet.drongo.crypto.ECKey)1 SchnorrSignature (com.sparrowwallet.drongo.crypto.SchnorrSignature)1