diff --git a/core/src/main/java/org/bitcoinj/core/ECKey.java b/core/src/main/java/org/bitcoinj/core/ECKey.java index 10bd089d2..53a529a7e 100644 --- a/core/src/main/java/org/bitcoinj/core/ECKey.java +++ b/core/src/main/java/org/bitcoinj/core/ECKey.java @@ -198,19 +198,19 @@ public class ECKey implements EncryptableItem { } /** - * Utility for compressing an elliptic curve point. Returns the same point if it's already compressed. - * See the ECKey class docs for a discussion of point compression. + * @deprecated Use {@link LazyECPoint#compress()} */ + @Deprecated public static LazyECPoint compressPoint(LazyECPoint point) { - return point.isCompressed() ? point : new LazyECPoint(point.get(), true); + return point.compress(); } /** - * Utility for decompressing an elliptic curve point. Returns the same point if it's already uncompressed. - * See the ECKey class docs for a discussion of point compression. + * @deprecated Use {@link LazyECPoint#decompress()} */ + @Deprecated public static LazyECPoint decompressPoint(LazyECPoint point) { - return !point.isCompressed() ? point : new LazyECPoint(point.get(), false); + return point.decompress(); } /** diff --git a/core/src/main/java/org/bitcoinj/crypto/DeterministicKey.java b/core/src/main/java/org/bitcoinj/crypto/DeterministicKey.java index 192a41c77..76f6827d9 100644 --- a/core/src/main/java/org/bitcoinj/crypto/DeterministicKey.java +++ b/core/src/main/java/org/bitcoinj/crypto/DeterministicKey.java @@ -67,7 +67,7 @@ public class DeterministicKey extends ECKey { LazyECPoint publicAsPoint, @Nullable BigInteger priv, @Nullable DeterministicKey parent) { - super(priv, compressPoint(checkNotNull(publicAsPoint))); + super(priv, publicAsPoint.compress()); checkArgument(chainCode.length == 32); this.parent = parent; this.childNumberPath = HDPath.M(checkNotNull(childNumberPath)); @@ -138,7 +138,7 @@ public class DeterministicKey extends ECKey { @Nullable DeterministicKey parent, int depth, int parentFingerprint) { - super(null, compressPoint(checkNotNull(publicAsPoint))); + super(null, publicAsPoint.compress()); checkArgument(chainCode.length == 32); this.parent = parent; this.childNumberPath = HDPath.M(checkNotNull(childNumberPath)); diff --git a/core/src/main/java/org/bitcoinj/crypto/LazyECPoint.java b/core/src/main/java/org/bitcoinj/crypto/LazyECPoint.java index 33b6b8084..6477c2708 100644 --- a/core/src/main/java/org/bitcoinj/crypto/LazyECPoint.java +++ b/core/src/main/java/org/bitcoinj/crypto/LazyECPoint.java @@ -70,6 +70,22 @@ public class LazyECPoint { this.bits = null; } + /** + * Returns a compressed version of this elliptic curve point. Returns the same point if it's already compressed. + * See the {@link ECKey} class docs for a discussion of point compression. + */ + public LazyECPoint compress() { + return compressed ? this : new LazyECPoint(get(), true); + } + + /** + * Returns a decompressed version of this elliptic curve point. Returns the same point if it's already compressed. + * See the {@link ECKey} class docs for a discussion of point compression. + */ + public LazyECPoint decompress() { + return !compressed ? this : new LazyECPoint(get(), false); + } + public ECPoint get() { if (point == null) point = curve.decodePoint(bits);