mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-11-02 18:26:43 +00:00
add tapsigner, minor refactoring
This commit is contained in:
parent
c642f7414a
commit
2168c56de9
4 changed files with 26 additions and 20 deletions
|
@ -128,6 +128,20 @@ public class Utils {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte[] xor(byte[] a, byte[] b) {
|
||||||
|
if(a.length != b.length) {
|
||||||
|
throw new IllegalArgumentException("Invalid length for xor: " + a.length + " vs " + b.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] ret = new byte[a.length];
|
||||||
|
|
||||||
|
for(int i = 0; i < a.length; i++) {
|
||||||
|
ret[i] = (byte) ((int) b[i] ^ (int) a[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/** Parse 4 bytes from the byte array (starting at the offset) as unsigned 32-bit integer in little endian format. */
|
/** Parse 4 bytes from the byte array (starting at the offset) as unsigned 32-bit integer in little endian format. */
|
||||||
public static long readUint32(byte[] bytes, int offset) {
|
public static long readUint32(byte[] bytes, int offset) {
|
||||||
return (bytes[offset] & 0xffl) |
|
return (bytes[offset] & 0xffl) |
|
||||||
|
|
|
@ -20,6 +20,8 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.sparrowwallet.drongo.Utils.xor;
|
||||||
|
|
||||||
public class PaymentCode {
|
public class PaymentCode {
|
||||||
private static final Logger log = LoggerFactory.getLogger(PaymentCode.class);
|
private static final Logger log = LoggerFactory.getLogger(PaymentCode.class);
|
||||||
|
|
||||||
|
@ -313,21 +315,6 @@ public class PaymentCode {
|
||||||
return HDKeyDerivation.createMasterPubKeyFromBytes(pubkey, chain);
|
return HDKeyDerivation.createMasterPubKeyFromBytes(pubkey, chain);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] xor(byte[] a, byte[] b) {
|
|
||||||
if(a.length != b.length) {
|
|
||||||
log.error("Invalid length for xor: " + a.length + " vs " + b.length);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] ret = new byte[a.length];
|
|
||||||
|
|
||||||
for(int i = 0; i < a.length; i++) {
|
|
||||||
ret[i] = (byte) ((int) b[i] ^ (int) a[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
try {
|
try {
|
||||||
byte[] pcodeBytes = Base58.decodeChecked(strPaymentCode);
|
byte[] pcodeBytes = Base58.decodeChecked(strPaymentCode);
|
||||||
|
|
|
@ -627,6 +627,14 @@ public class ECKey {
|
||||||
// This is what you get back from Bouncy Castle if base64 doesn't decode :(
|
// This is what you get back from Bouncy Castle if base64 doesn't decode :(
|
||||||
throw new SignatureException("Could not decode base64", e);
|
throw new SignatureException("Could not decode base64", e);
|
||||||
}
|
}
|
||||||
|
byte[] messageBytes = formatMessageForSigning(message);
|
||||||
|
// Note that the C++ code doesn't actually seem to specify any character encoding. Presumably it's whatever
|
||||||
|
// JSON-SPIRIT hands back. Assume UTF-8 for now.
|
||||||
|
Sha256Hash messageHash = Sha256Hash.twiceOf(messageBytes);
|
||||||
|
return signedHashToKey(messageHash, signatureEncoded, electrumFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ECKey signedHashToKey(Sha256Hash messageHash, byte[] signatureEncoded, boolean electrumFormat) throws SignatureException {
|
||||||
// Parse the signature bytes into r/s and the selector value.
|
// Parse the signature bytes into r/s and the selector value.
|
||||||
if(signatureEncoded.length < 65) {
|
if(signatureEncoded.length < 65) {
|
||||||
throw new SignatureException("Signature truncated, expected 65 bytes and got " + signatureEncoded.length);
|
throw new SignatureException("Signature truncated, expected 65 bytes and got " + signatureEncoded.length);
|
||||||
|
@ -640,10 +648,7 @@ public class ECKey {
|
||||||
BigInteger r = new BigInteger(1, Arrays.copyOfRange(signatureEncoded, 1, 33));
|
BigInteger r = new BigInteger(1, Arrays.copyOfRange(signatureEncoded, 1, 33));
|
||||||
BigInteger s = new BigInteger(1, Arrays.copyOfRange(signatureEncoded, 33, 65));
|
BigInteger s = new BigInteger(1, Arrays.copyOfRange(signatureEncoded, 33, 65));
|
||||||
ECDSASignature sig = new ECDSASignature(r, s);
|
ECDSASignature sig = new ECDSASignature(r, s);
|
||||||
byte[] messageBytes = formatMessageForSigning(message);
|
|
||||||
// Note that the C++ code doesn't actually seem to specify any character encoding. Presumably it's whatever
|
|
||||||
// JSON-SPIRIT hands back. Assume UTF-8 for now.
|
|
||||||
Sha256Hash messageHash = Sha256Hash.twiceOf(messageBytes);
|
|
||||||
boolean compressed = false;
|
boolean compressed = false;
|
||||||
if(header >= 39) { // this is a bech32 signature
|
if(header >= 39) { // this is a bech32 signature
|
||||||
header -= 12;
|
header -= 12;
|
||||||
|
|
|
@ -3,7 +3,7 @@ package com.sparrowwallet.drongo.wallet;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public enum WalletModel {
|
public enum WalletModel {
|
||||||
SEED, SPARROW, BITCOIN_CORE, ELECTRUM, TREZOR_1, TREZOR_T, COLDCARD, LEDGER_NANO_S, LEDGER_NANO_X, DIGITALBITBOX_01, KEEPKEY, SPECTER_DESKTOP, COBO_VAULT, BITBOX_02, SPECTER_DIY, PASSPORT, BLUE_WALLET, KEYSTONE, SEEDSIGNER, CARAVAN, GORDIAN_SEED_TOOL, JADE, LEDGER_NANO_S_PLUS, EPS;
|
SEED, SPARROW, BITCOIN_CORE, ELECTRUM, TREZOR_1, TREZOR_T, COLDCARD, LEDGER_NANO_S, LEDGER_NANO_X, DIGITALBITBOX_01, KEEPKEY, SPECTER_DESKTOP, COBO_VAULT, BITBOX_02, SPECTER_DIY, PASSPORT, BLUE_WALLET, KEYSTONE, SEEDSIGNER, CARAVAN, GORDIAN_SEED_TOOL, JADE, LEDGER_NANO_S_PLUS, EPS, TAPSIGNER;
|
||||||
|
|
||||||
public static WalletModel getModel(String model) {
|
public static WalletModel getModel(String model) {
|
||||||
return valueOf(model.toUpperCase(Locale.ROOT));
|
return valueOf(model.toUpperCase(Locale.ROOT));
|
||||||
|
|
Loading…
Reference in a new issue