diff --git a/src/main/java/com/craigraw/drongo/ExtendedPublicKey.java b/src/main/java/com/craigraw/drongo/ExtendedPublicKey.java index 48888a8..cde44d1 100644 --- a/src/main/java/com/craigraw/drongo/ExtendedPublicKey.java +++ b/src/main/java/com/craigraw/drongo/ExtendedPublicKey.java @@ -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 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 path; diff --git a/src/main/java/com/craigraw/drongo/crypto/DeterministicKey.java b/src/main/java/com/craigraw/drongo/crypto/DeterministicKey.java index 88e8645..a4193d6 100644 --- a/src/main/java/com/craigraw/drongo/crypto/DeterministicKey.java +++ b/src/main/java/com/craigraw/drongo/crypto/DeterministicKey.java @@ -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 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); } /**