mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-26 01:56:44 +00:00
change fingerprint storage from int to byte array
This commit is contained in:
parent
d3d5fd4a80
commit
89e7892d7c
2 changed files with 15 additions and 12 deletions
|
@ -15,7 +15,7 @@ public class ExtendedPublicKey {
|
|||
private static final int bip32HeaderP2WPKHZPub = 0x04B24746; // The 4 byte header that serializes in base58 to "zpub"
|
||||
private static final int bip32HeaderP2WHSHPub = 0x2AA7ED3; // The 4 byte header that serializes in base58 to "Zpub"
|
||||
|
||||
private int parentFingerprint;
|
||||
private byte[] parentFingerprint;
|
||||
private String keyDerivationPath;
|
||||
private DeterministicKey pubKey;
|
||||
private String childDerivationPath;
|
||||
|
@ -23,7 +23,7 @@ public class ExtendedPublicKey {
|
|||
|
||||
private DeterministicHierarchy hierarchy;
|
||||
|
||||
public ExtendedPublicKey(int parentFingerprint, String keyDerivationPath, DeterministicKey pubKey, String childDerivationPath, ChildNumber pubKeyChildNumber) {
|
||||
public ExtendedPublicKey(byte[] parentFingerprint, String keyDerivationPath, DeterministicKey pubKey, String childDerivationPath, ChildNumber pubKeyChildNumber) {
|
||||
this.parentFingerprint = parentFingerprint;
|
||||
this.keyDerivationPath = keyDerivationPath;
|
||||
this.pubKey = pubKey;
|
||||
|
@ -33,10 +33,14 @@ public class ExtendedPublicKey {
|
|||
this.hierarchy = new DeterministicHierarchy(pubKey);
|
||||
}
|
||||
|
||||
public int getParentFingerprint() {
|
||||
public byte[] getParentFingerprint() {
|
||||
return parentFingerprint;
|
||||
}
|
||||
|
||||
public byte[] getFingerprint() {
|
||||
return pubKey.getFingerprint();
|
||||
}
|
||||
|
||||
public List<ChildNumber> getKeyDerivation() {
|
||||
return parsePath(keyDerivationPath);
|
||||
}
|
||||
|
@ -137,7 +141,7 @@ public class ExtendedPublicKey {
|
|||
int depth = 5 - childPath.size();
|
||||
buffer.put((byte)depth);
|
||||
|
||||
buffer.putInt(parentFingerprint);
|
||||
buffer.put(parentFingerprint);
|
||||
|
||||
buffer.putInt(pubKeyChildNumber.i());
|
||||
|
||||
|
@ -156,7 +160,8 @@ public class ExtendedPublicKey {
|
|||
}
|
||||
|
||||
int depth = buffer.get() & 0xFF; // convert signed byte to positive int since depth cannot be negative
|
||||
final int parentFingerprint = buffer.getInt();
|
||||
byte[] parentFingerprint = new byte[4];
|
||||
buffer.get(parentFingerprint);
|
||||
final int i = buffer.getInt();
|
||||
ChildNumber childNumber;
|
||||
List<ChildNumber> path;
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.craigraw.drongo.Utils;
|
|||
import com.craigraw.drongo.protocol.Base58;
|
||||
import com.craigraw.drongo.protocol.Sha256Hash;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -13,7 +12,7 @@ public class DeterministicKey extends ECKey {
|
|||
private final DeterministicKey parent;
|
||||
private final List<ChildNumber> childNumberPath;
|
||||
private final int depth;
|
||||
private int parentFingerprint; // 0 if this key is root node of key hierarchy
|
||||
private byte[] parentFingerprint; // 0 if this key is root node of key hierarchy
|
||||
|
||||
/** 32 bytes */
|
||||
private final byte[] chainCode;
|
||||
|
@ -27,7 +26,7 @@ public class DeterministicKey extends ECKey {
|
|||
byte[] chainCode,
|
||||
LazyECPoint publicAsPoint,
|
||||
int depth,
|
||||
int parentFingerprint) {
|
||||
byte[] parentFingerprint) {
|
||||
super(compressPoint(publicAsPoint));
|
||||
if(chainCode.length != 32) {
|
||||
throw new IllegalArgumentException("Chaincode not 32 bytes in length");
|
||||
|
@ -51,7 +50,7 @@ public class DeterministicKey extends ECKey {
|
|||
this.childNumberPath = childNumberPath;
|
||||
this.chainCode = Arrays.copyOf(chainCode, chainCode.length);
|
||||
this.depth = parent == null ? 0 : parent.depth + 1;
|
||||
this.parentFingerprint = (parent != null) ? parent.getFingerprint() : 0;
|
||||
this.parentFingerprint = (parent != null) ? parent.getFingerprint() : new byte[4];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,9 +63,8 @@ public class DeterministicKey extends ECKey {
|
|||
}
|
||||
|
||||
/** Returns the first 32 bits of the result of {@link #getIdentifier()}. */
|
||||
public int getFingerprint() {
|
||||
// TODO: why is this different than armory's fingerprint? BIP 32: "The first 32 bits of the identifier are called the fingerprint."
|
||||
return ByteBuffer.wrap(Arrays.copyOfRange(getIdentifier(), 0, 4)).getInt();
|
||||
public byte[] getFingerprint() {
|
||||
return Arrays.copyOfRange(getIdentifier(), 0, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue