add support for external message signers

This commit is contained in:
Craig Raw 2023-01-30 09:40:35 +02:00
parent e2a4c32db3
commit b487396417
2 changed files with 13 additions and 1 deletions

View file

@ -576,9 +576,13 @@ public class ECKey {
* @throws IllegalStateException if this ECKey does not have the private part.
*/
public String signMessage(String message, ScriptType scriptType) {
return signMessage(message, scriptType, this::signEcdsa);
}
public String signMessage(String message, ScriptType scriptType, ECDSAHashSigner ecdsaHashSigner) {
byte[] data = formatMessageForSigning(message);
Sha256Hash hash = Sha256Hash.twiceOf(data);
ECDSASignature sig = signEcdsa(hash);
ECDSASignature sig = ecdsaHashSigner.sign(hash);
byte recId = findRecoveryId(hash, sig);
int headerByte = recId + getSigningTypeConstant(scriptType);
byte[] sigData = new byte[65]; // 1 header + 32 bytes for R + 32 bytes for S
@ -868,4 +872,8 @@ public class ECKey {
throw new RuntimeException(e); // Cannot happen.
}
}
public interface ECDSAHashSigner {
ECDSASignature sign(Sha256Hash hash);
}
}

View file

@ -66,6 +66,10 @@ public enum WalletModel {
return (this == TREZOR_1 || this == KEEPKEY);
}
public boolean isCard() {
return (this == TAPSIGNER || this == SATSCARD);
}
public static WalletModel fromType(String type) {
for(WalletModel model : values()) {
if(model.getType().equalsIgnoreCase(type)) {