/** * A deterministic key is considered to be 'public key only' if it hasn't got a private key part and it cannot be * rederived. If the hierarchy is encrypted this returns true. */ @Override public boolean isPubKeyOnly() { return super.isPubKeyOnly() && (parent == null || parent.isPubKeyOnly()); }
/** * A deterministic key is considered to be 'public key only' if it hasn't got a private key part and it cannot be * rederived. If the hierarchy is encrypted this returns true. */ @Override public boolean isPubKeyOnly() { return super.isPubKeyOnly() && (parent == null || parent.isPubKeyOnly()); }
/** * A deterministic key is considered to be 'public key only' if it hasn't got a private key part and it cannot be * rederived. If the hierarchy is encrypted this returns true. */ @Override public boolean isPubKeyOnly() { return super.isPubKeyOnly() && (parent == null || parent.isPubKeyOnly()); }
/** Returns true if this key is watch only, meaning it has a public key but no private key. */ public boolean isWatching() { return isPubKeyOnly() && !isEncrypted(); }
/** * A deterministic key is considered to be 'public key only' if it hasn't got a private key part and it cannot be * rederived. If the hierarchy is encrypted this returns true. */ @Override public boolean isPubKeyOnly() { return super.isPubKeyOnly() && (parent == null || parent.isPubKeyOnly()); }
/** Returns true if this key is watch only, meaning it has a public key but no private key. */ public boolean isWatching() { return isPubKeyOnly() && !isEncrypted(); }
/** Returns true if this key is watch only, meaning it has a public key but no private key. */ public boolean isWatching() { return isPubKeyOnly() && !isEncrypted(); }
/** Returns true if this key is watch only, meaning it has a public key but no private key. */ public boolean isWatching() { return isPubKeyOnly() && !isEncrypted(); }
private String toString(boolean includePrivate, NetworkParameters params) { final MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(this).omitNullValues(); helper.add("pub HEX", getPublicKeyAsHex()); if (includePrivate) { try { helper.add("priv HEX", getPrivateKeyAsHex()); helper.add("priv WIF", getPrivateKeyAsWiF(params)); } catch (IllegalStateException e) { // TODO: Make hasPrivKey() work for deterministic keys and fix this. } catch (Exception e) { final String message = e.getMessage(); helper.add("priv EXCEPTION", e.getClass().getName() + (message != null ? ": " + message : "")); } } if (creationTimeSeconds > 0) helper.add("creationTimeSeconds", creationTimeSeconds); helper.add("keyCrypter", keyCrypter); if (includePrivate) helper.add("encryptedPrivateKey", encryptedPrivateKey); helper.add("isEncrypted", isEncrypted()); helper.add("isPubKeyOnly", isPubKeyOnly()); return helper.toString(); }
private String toString(boolean includePrivate, NetworkParameters params) { final MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(this).omitNullValues(); helper.add("pub HEX", getPublicKeyAsHex()); if (includePrivate) { try { helper.add("priv HEX", getPrivateKeyAsHex()); helper.add("priv WIF", getPrivateKeyAsWiF(params)); } catch (IllegalStateException e) { // TODO: Make hasPrivKey() work for deterministic keys and fix this. } catch (Exception e) { final String message = e.getMessage(); helper.add("priv EXCEPTION", e.getClass().getName() + (message != null ? ": " + message : "")); } } if (creationTimeSeconds > 0) helper.add("creationTimeSeconds", creationTimeSeconds); helper.add("keyCrypter", keyCrypter); if (includePrivate) helper.add("encryptedPrivateKey", encryptedPrivateKey); helper.add("isEncrypted", isEncrypted()); helper.add("isPubKeyOnly", isPubKeyOnly()); return helper.toString(); }
private String toString(boolean includePrivate, NetworkParameters params) { final MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(this).omitNullValues(); helper.add("pub HEX", getPublicKeyAsHex()); if (includePrivate) { try { helper.add("priv HEX", getPrivateKeyAsHex()); helper.add("priv WIF", getPrivateKeyAsWiF(params)); } catch (IllegalStateException e) { // TODO: Make hasPrivKey() work for deterministic keys and fix this. } catch (Exception e) { final String message = e.getMessage(); helper.add("priv EXCEPTION", e.getClass().getName() + (message != null ? ": " + message : "")); } } if (creationTimeSeconds > 0) helper.add("creationTimeSeconds", creationTimeSeconds); helper.add("keyCrypter", keyCrypter); if (includePrivate) helper.add("encryptedPrivateKey", encryptedPrivateKey); helper.add("isEncrypted", isEncrypted()); helper.add("isPubKeyOnly", isPubKeyOnly()); return helper.toString(); }
private String toString(boolean includePrivate, @Nullable KeyParameter aesKey, NetworkParameters params) { final MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(this).omitNullValues(); helper.add("pub HEX", getPublicKeyAsHex()); if (includePrivate) { ECKey decryptedKey = isEncrypted() ? decrypt(checkNotNull(aesKey)) : this; try { helper.add("priv HEX", decryptedKey.getPrivateKeyAsHex()); helper.add("priv WIF", decryptedKey.getPrivateKeyAsWiF(params)); } catch (IllegalStateException e) { // TODO: Make hasPrivKey() work for deterministic keys and fix this. } catch (Exception e) { final String message = e.getMessage(); helper.add("priv EXCEPTION", e.getClass().getName() + (message != null ? ": " + message : "")); } } if (creationTimeSeconds > 0) helper.add("creationTimeSeconds", creationTimeSeconds); helper.add("keyCrypter", keyCrypter); if (includePrivate) helper.add("encryptedPrivateKey", encryptedPrivateKey); helper.add("isEncrypted", isEncrypted()); helper.add("isPubKeyOnly", isPubKeyOnly()); return helper.toString(); }
@Test public void derive() throws Exception { ECKey key1 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertFalse(key1.isPubKeyOnly()); ECKey key2 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertFalse(key2.isPubKeyOnly()); final Address address = Address.fromBase58(UnitTestParams.get(), "n1bQNoEx8uhmCzzA5JPG6sFdtsUQhwiQJV"); assertEquals(address, key1.toAddress(UnitTestParams.get())); assertEquals("mnHUcqUVvrfi5kAaXJDQzBb9HsWs78b42R", key2.toAddress(UnitTestParams.get()).toString()); assertEquals(key1, chain.findKeyFromPubHash(address.getHash160())); assertEquals(key2, chain.findKeyFromPubKey(key2.getPubKey())); key1.sign(Sha256Hash.ZERO_HASH); assertFalse(key1.isPubKeyOnly()); ECKey key3 = chain.getKey(KeyChain.KeyPurpose.CHANGE); assertFalse(key3.isPubKeyOnly()); assertEquals("mqumHgVDqNzuXNrszBmi7A2UpmwaPMx4HQ", key3.toAddress(UnitTestParams.get()).toString()); key3.sign(Sha256Hash.ZERO_HASH); assertFalse(key3.isPubKeyOnly()); }
ECKey key = chain.findKeyFromPubKey(key1.getPubKey()); assertTrue(key.isEncrypted()); assertTrue(key.isPubKeyOnly()); assertFalse(key.isWatching()); assertNull(key.getSecretBytes()); key = chain.findKeyFromPubKey(key1.getPubKey()); assertFalse(key.isEncrypted()); assertFalse(key.isPubKeyOnly()); assertFalse(key.isWatching()); key.getPrivKeyBytes();