3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-12 10:15:52 +00:00

WalletTool: Fix importing of private key in WIF (wallet import format).

This commit is contained in:
Andreas Schildbach 2019-02-03 16:57:13 +01:00
parent ac7a576b3d
commit 5464e5560e
2 changed files with 5 additions and 11 deletions

View File

@ -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));

View File

@ -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.