mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-11-02 18:26:43 +00:00
add support for external psbt signers
This commit is contained in:
parent
a14b23f2fa
commit
e2a4c32db3
2 changed files with 27 additions and 2 deletions
|
@ -519,6 +519,20 @@ public class PSBTInput {
|
|||
}
|
||||
|
||||
public boolean sign(ECKey privKey) {
|
||||
return sign(new PSBTInputSigner() {
|
||||
@Override
|
||||
public TransactionSignature sign(Sha256Hash hash, SigHash sigHash, TransactionSignature.Type signatureType) {
|
||||
return privKey.sign(hash, sigHash, signatureType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ECKey getPubKey() {
|
||||
return ECKey.fromPublicOnly(privKey);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean sign(PSBTInputSigner psbtInputSigner) {
|
||||
SigHash localSigHash = getSigHash();
|
||||
if(localSigHash == null) {
|
||||
localSigHash = getDefaultSigHash();
|
||||
|
@ -529,12 +543,12 @@ public class PSBTInput {
|
|||
if(signingScript != null) {
|
||||
Sha256Hash hash = getHashForSignature(signingScript, localSigHash);
|
||||
TransactionSignature.Type type = isTaproot() ? SCHNORR : ECDSA;
|
||||
TransactionSignature transactionSignature = privKey.sign(hash, localSigHash, type);
|
||||
TransactionSignature transactionSignature = psbtInputSigner.sign(hash, localSigHash, type);
|
||||
|
||||
if(type == SCHNORR) {
|
||||
tapKeyPathSignature = transactionSignature;
|
||||
} else {
|
||||
ECKey pubKey = ECKey.fromPublicOnly(privKey);
|
||||
ECKey pubKey = psbtInputSigner.getPubKey();
|
||||
getPartialSignatures().put(pubKey, transactionSignature);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package com.sparrowwallet.drongo.psbt;
|
||||
|
||||
import com.sparrowwallet.drongo.crypto.ECKey;
|
||||
import com.sparrowwallet.drongo.protocol.Sha256Hash;
|
||||
import com.sparrowwallet.drongo.protocol.SigHash;
|
||||
import com.sparrowwallet.drongo.protocol.TransactionSignature;
|
||||
|
||||
public interface PSBTInputSigner {
|
||||
TransactionSignature sign(Sha256Hash hash, SigHash sigHash, TransactionSignature.Type signatureType);
|
||||
ECKey getPubKey();
|
||||
}
|
Loading…
Reference in a new issue