From 5464e5560eb3bac5f67562ebc6b261c46e3e0913 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Sun, 3 Feb 2019 16:57:13 +0100 Subject: [PATCH] WalletTool: Fix importing of private key in WIF (wallet import format). --- .../main/java/org/bitcoinj/tools/WalletTool.java | 14 ++++---------- .../org/bitcoinj/tools/wallet-tool-help.txt | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/tools/src/main/java/org/bitcoinj/tools/WalletTool.java b/tools/src/main/java/org/bitcoinj/tools/WalletTool.java index b4430a00..0211ede9 100644 --- a/tools/src/main/java/org/bitcoinj/tools/WalletTool.java +++ b/tools/src/main/java/org/bitcoinj/tools/WalletTool.java @@ -1406,19 +1406,13 @@ public class WalletTool { long creationTimeSeconds = getCreationTimeSeconds(); if (options.has("privkey")) { String data = (String) options.valueOf("privkey"); - if (data.startsWith("5J") || data.startsWith("5H") || data.startsWith("5K")) { - DumpedPrivateKey dpk; - try { - dpk = DumpedPrivateKey.fromBase58(params, data); - } catch (AddressFormatException e) { - System.err.println("Could not parse dumped private key " + data); - return; - } + try { + DumpedPrivateKey dpk = DumpedPrivateKey.fromBase58(params, data); // WIF key = dpk.getKey(); - } else { + } catch (AddressFormatException e) { byte[] decode = parseAsHexOrBase58(data); if (decode == null) { - System.err.println("Could not understand --privkey as either hex or base58: " + data); + System.err.println("Could not understand --privkey as either WIF, hex or base58: " + data); return; } key = ECKey.fromPrivate(new BigInteger(1, decode)); diff --git a/tools/src/main/resources/org/bitcoinj/tools/wallet-tool-help.txt b/tools/src/main/resources/org/bitcoinj/tools/wallet-tool-help.txt index 1dce207f..a9a618a4 100644 --- a/tools/src/main/resources/org/bitcoinj/tools/wallet-tool-help.txt +++ b/tools/src/main/resources/org/bitcoinj/tools/wallet-tool-help.txt @@ -19,7 +19,7 @@ Usage: wallet-tool --flags action-name add-key Adds a new key to the wallet, either specified or freshly generated. If --date is specified, that's the creation date. If --unixtime is specified, that's the creation time and it overrides --date. - If --privkey is specified, use as a hex/base58 encoded private key. + If --privkey is specified, use as a WIF-, hex- or base58-encoded private key. Don't specify --pubkey in that case, it will be derived automatically. If --pubkey is specified, use as a hex/base58 encoded non-compressed public key. If --lookahead-size is specified, pre-generate at least this many keys ahead of where we are.