diff --git a/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java b/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java index 17f19cb..be966e0 100644 --- a/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java +++ b/src/main/java/com/sparrowwallet/drongo/crypto/ECKey.java @@ -326,6 +326,17 @@ public class ECKey { return priv; } + /** + * Exports the private key in the form used by Bitcoin Core's "dumpprivkey" and "importprivkey" commands. Use + * the {@link DumpedPrivateKey#toString()} method to get the string. + * + * @return Private key bytes as a {@link DumpedPrivateKey}. + * @throws IllegalStateException if the private key is not available. + */ + public DumpedPrivateKey getPrivateKeyEncoded() { + return new DumpedPrivateKey(getPrivKeyBytes(), isCompressed()); + } + /** * Returns whether this key is using the compressed form or not. Compressed pubkeys are only 33 bytes, not 64. */