mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-11-05 03:26:43 +00:00
add support for external message signers
This commit is contained in:
parent
e2a4c32db3
commit
b487396417
2 changed files with 13 additions and 1 deletions
|
@ -576,9 +576,13 @@ public class ECKey {
|
||||||
* @throws IllegalStateException if this ECKey does not have the private part.
|
* @throws IllegalStateException if this ECKey does not have the private part.
|
||||||
*/
|
*/
|
||||||
public String signMessage(String message, ScriptType scriptType) {
|
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);
|
byte[] data = formatMessageForSigning(message);
|
||||||
Sha256Hash hash = Sha256Hash.twiceOf(data);
|
Sha256Hash hash = Sha256Hash.twiceOf(data);
|
||||||
ECDSASignature sig = signEcdsa(hash);
|
ECDSASignature sig = ecdsaHashSigner.sign(hash);
|
||||||
byte recId = findRecoveryId(hash, sig);
|
byte recId = findRecoveryId(hash, sig);
|
||||||
int headerByte = recId + getSigningTypeConstant(scriptType);
|
int headerByte = recId + getSigningTypeConstant(scriptType);
|
||||||
byte[] sigData = new byte[65]; // 1 header + 32 bytes for R + 32 bytes for S
|
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.
|
throw new RuntimeException(e); // Cannot happen.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface ECDSAHashSigner {
|
||||||
|
ECDSASignature sign(Sha256Hash hash);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,10 @@ public enum WalletModel {
|
||||||
return (this == TREZOR_1 || this == KEEPKEY);
|
return (this == TREZOR_1 || this == KEEPKEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isCard() {
|
||||||
|
return (this == TAPSIGNER || this == SATSCARD);
|
||||||
|
}
|
||||||
|
|
||||||
public static WalletModel fromType(String type) {
|
public static WalletModel fromType(String type) {
|
||||||
for(WalletModel model : values()) {
|
for(WalletModel model : values()) {
|
||||||
if(model.getType().equalsIgnoreCase(type)) {
|
if(model.getType().equalsIgnoreCase(type)) {
|
||||||
|
|
Loading…
Reference in a new issue