/** * @throws HDDerivationException if privKeyBytes is invalid (0 or >= n). */ public static DeterministicKey createMasterPrivKeyFromBytes(byte[] privKeyBytes, byte[] chainCode) throws HDDerivationException { BigInteger priv = new BigInteger(1, privKeyBytes); assertNonZero(priv, "Generated master key is invalid."); assertLessThanN(priv, "Generated master key is invalid."); return new DeterministicKey(ImmutableList.<ChildNumber>of(), chainCode, priv, null); }
/** * @throws HDDerivationException if privKeyBytes is invalid (0 or >= n). */ public static DeterministicKey createMasterPrivKeyFromBytes(byte[] privKeyBytes, byte[] chainCode) throws HDDerivationException { BigInteger priv = new BigInteger(1, privKeyBytes); assertNonZero(priv, "Generated master key is invalid."); assertLessThanN(priv, "Generated master key is invalid."); return new DeterministicKey(ImmutableList.<ChildNumber>of(), chainCode, priv, null); }
/** * @throws HDDerivationException if privKeyBytes is invalid (0 or >= n). */ public static DeterministicKey createMasterPrivKeyFromBytes(byte[] privKeyBytes, byte[] chainCode) throws HDDerivationException { BigInteger priv = new BigInteger(1, privKeyBytes); assertNonZero(priv, "Generated master key is invalid."); assertLessThanN(priv, "Generated master key is invalid."); return new DeterministicKey(ImmutableList.<ChildNumber>of(), chainCode, priv, null); }
/** * @throws HDDerivationException if privKeyBytes is invalid (0 or >= n). */ public static DeterministicKey createMasterPrivKeyFromBytes(byte[] privKeyBytes, byte[] chainCode, ImmutableList<ChildNumber> childNumberPath) throws HDDerivationException { BigInteger priv = new BigInteger(1, privKeyBytes); assertNonZero(priv, "Generated master key is invalid."); assertLessThanN(priv, "Generated master key is invalid."); return new DeterministicKey(childNumberPath, chainCode, priv, null); }
/** * <p>Returns the same key with the parent pointer removed (it still knows its own path and the parent fingerprint).</p> * * <p>If this key doesn't have private key bytes stored/cached itself, but could rederive them from the parent, then * the new key returned by this method won't be able to do that. Thus, using dropPrivateBytes().dropParent() on a * regular DeterministicKey will yield a new DeterministicKey that cannot sign or do other things involving the * private key at all.</p> */ public DeterministicKey dropParent() { DeterministicKey key = new DeterministicKey(getPath(), getChainCode(), pub, priv, null); key.parentFingerprint = parentFingerprint; return key; }
/** * <p>Returns the same key with the parent pointer removed (it still knows its own path and the parent fingerprint).</p> * * <p>If this key doesn't have private key bytes stored/cached itself, but could rederive them from the parent, then * the new key returned by this method won't be able to do that. Thus, using dropPrivateBytes().dropParent() on a * regular DeterministicKey will yield a new DeterministicKey that cannot sign or do other things involving the * private key at all.</p> */ public DeterministicKey dropParent() { DeterministicKey key = new DeterministicKey(getPath(), getChainCode(), pub, priv, null); key.parentFingerprint = parentFingerprint; return key; }
/** * <p>Returns the same key with the parent pointer removed (it still knows its own path and the parent fingerprint).</p> * * <p>If this key doesn't have private key bytes stored/cached itself, but could rederive them from the parent, then * the new key returned by this method won't be able to do that. Thus, using dropPrivateBytes().dropParent() on a * regular DeterministicKey will yield a new DeterministicKey that cannot sign or do other things involving the * private key at all.</p> */ public DeterministicKey dropParent() { DeterministicKey key = new DeterministicKey(getPath(), getChainCode(), pub, priv, null); key.parentFingerprint = parentFingerprint; return key; }
/** * <p>Returns the same key with the parent pointer removed (it still knows its own path and the parent fingerprint).</p> * * <p>If this key doesn't have private key bytes stored/cached itself, but could rederive them from the parent, then * the new key returned by this method won't be able to do that. Thus, using dropPrivateBytes().dropParent() on a * regular DeterministicKey will yield a new DeterministicKey that cannot sign or do other things involving the * private key at all.</p> */ public DeterministicKey dropParent() { DeterministicKey key = new DeterministicKey(getPath(), getChainCode(), pub, priv, null); key.parentFingerprint = parentFingerprint; return key; }
public DeterministicKey encrypt(KeyCrypter keyCrypter, KeyParameter aesKey, @Nullable DeterministicKey newParent) throws KeyCrypterException { // Same as the parent code, except we construct a DeterministicKey instead of an ECKey. checkNotNull(keyCrypter); if (newParent != null) checkArgument(newParent.isEncrypted()); final byte[] privKeyBytes = getPrivKeyBytes(); checkState(privKeyBytes != null, "Private key is not available"); EncryptedData encryptedPrivateKey = keyCrypter.encrypt(privKeyBytes, aesKey); DeterministicKey key = new DeterministicKey(childNumberPath, chainCode, keyCrypter, pub, encryptedPrivateKey, newParent); if (newParent == null) key.setCreationTimeSeconds(getCreationTimeSeconds()); return key; }
public DeterministicKey encrypt(KeyCrypter keyCrypter, KeyParameter aesKey, @Nullable DeterministicKey newParent) throws KeyCrypterException { // Same as the parent code, except we construct a DeterministicKey instead of an ECKey. checkNotNull(keyCrypter); if (newParent != null) checkArgument(newParent.isEncrypted()); final byte[] privKeyBytes = getPrivKeyBytes(); checkState(privKeyBytes != null, "Private key is not available"); EncryptedData encryptedPrivateKey = keyCrypter.encrypt(privKeyBytes, aesKey); DeterministicKey key = new DeterministicKey(childNumberPath, chainCode, keyCrypter, pub, encryptedPrivateKey, newParent); if (newParent == null) key.setCreationTimeSeconds(getCreationTimeSeconds()); return key; }
public static DeterministicKey createMasterPubKeyFromBytes(byte[] pubKeyBytes, byte[] chainCode) { return new DeterministicKey(ImmutableList.<ChildNumber>of(), chainCode, new LazyECPoint(ECKey.CURVE.getCurve(), pubKeyBytes), null, null); }
public DeterministicKey encrypt(KeyCrypter keyCrypter, KeyParameter aesKey, @Nullable DeterministicKey newParent) throws KeyCrypterException { // Same as the parent code, except we construct a DeterministicKey instead of an ECKey. checkNotNull(keyCrypter); if (newParent != null) checkArgument(newParent.isEncrypted()); final byte[] privKeyBytes = getPrivKeyBytes(); checkState(privKeyBytes != null, "Private key is not available"); EncryptedData encryptedPrivateKey = keyCrypter.encrypt(privKeyBytes, aesKey); DeterministicKey key = new DeterministicKey(childNumberPath, chainCode, keyCrypter, pub, encryptedPrivateKey, newParent); if (newParent == null) key.setCreationTimeSeconds(getCreationTimeSeconds()); return key; }
public static DeterministicKey createMasterPubKeyFromBytes(byte[] pubKeyBytes, byte[] chainCode) { return new DeterministicKey(ImmutableList.<ChildNumber>of(), chainCode, new LazyECPoint(ECKey.CURVE.getCurve(), pubKeyBytes), null, null); }
/** * Returns the same key with the private bytes removed. May return the same instance. The purpose of this is to save * memory: the private key can always be very efficiently rederived from a parent that a private key, so storing * all the private keys in RAM is a poor tradeoff especially on constrained devices. This means that the returned * key may still be usable for signing and so on, so don't expect it to be a true pubkey-only object! If you want * that then you should follow this call with a call to {@link #dropParent()}. */ public DeterministicKey dropPrivateBytes() { if (isPubKeyOnly()) return this; else return new DeterministicKey(getPath(), getChainCode(), pub, null, parent); }
/** * Returns the same key with the private bytes removed. May return the same instance. The purpose of this is to save * memory: the private key can always be very efficiently rederived from a parent that a private key, so storing * all the private keys in RAM is a poor tradeoff especially on constrained devices. This means that the returned * key may still be usable for signing and so on, so don't expect it to be a true pubkey-only object! If you want * that then you should follow this call with a call to {@link #dropParent()}. */ public DeterministicKey dropPrivateBytes() { if (isPubKeyOnly()) return this; else return new DeterministicKey(getPath(), getChainCode(), pub, null, parent); }
/** * Returns the same key with the private bytes removed. May return the same instance. The purpose of this is to save * memory: the private key can always be very efficiently rederived from a parent that a private key, so storing * all the private keys in RAM is a poor tradeoff especially on constrained devices. This means that the returned * key may still be usable for signing and so on, so don't expect it to be a true pubkey-only object! If you want * that then you should follow this call with a call to {@link #dropParent()}. */ public DeterministicKey dropPrivateBytes() { if (isPubKeyOnly()) return this; else return new DeterministicKey(getPath(), getChainCode(), pub, null, parent); }
/** * Returns the same key with the private bytes removed. May return the same instance. The purpose of this is to save * memory: the private key can always be very efficiently rederived from a parent that a private key, so storing * all the private keys in RAM is a poor tradeoff especially on constrained devices. This means that the returned * key may still be usable for signing and so on, so don't expect it to be a true pubkey-only object! If you want * that then you should follow this call with a call to {@link #dropParent()}. */ public DeterministicKey dropPrivateBytes() { if (isPubKeyOnly()) return this; else return new DeterministicKey(getPath(), getChainCode(), pub, null, parent); }
@Override public String getPublicKeySerialized() { // Change the path of the key to match the BIP32 paths i.e. 0H/<account index>H DeterministicKey key = keys.getWatchingKey(); ImmutableList<ChildNumber> path = ImmutableList.of(key.getChildNumber()); key = new DeterministicKey(path, key.getChainCode(), key.getPubKeyPoint(), null, null); return key.serializePubB58(); }
@Override public DeterministicKey decrypt(KeyCrypter keyCrypter, KeyParameter aesKey) throws KeyCrypterException { checkNotNull(keyCrypter); // Check that the keyCrypter matches the one used to encrypt the keys, if set. if (this.keyCrypter != null && !this.keyCrypter.equals(keyCrypter)) throw new KeyCrypterException("The keyCrypter being used to decrypt the key is different to the one that was used to encrypt it"); BigInteger privKey = findOrDeriveEncryptedPrivateKey(keyCrypter, aesKey); DeterministicKey key = new DeterministicKey(childNumberPath, chainCode, privKey, parent); if (!Arrays.equals(key.getPubKey(), getPubKey())) throw new KeyCrypterException("Provided AES key is wrong"); if (parent == null) key.setCreationTimeSeconds(getCreationTimeSeconds()); return key; }
@Override public String getPublicKeySerialized() { // Change the path of the key to match the BIP32 paths i.e. 0H/<account index>H DeterministicKey key = keys.getWatchingKey(); ImmutableList<ChildNumber> path = ImmutableList.of(key.getChildNumber()); key = new DeterministicKey(path, key.getChainCode(), key.getPubKeyPoint(), null, null); return key.serializePubB58(); }