public static DeterministicKey deriveHardened(DeterministicKey node, int type) { return HDKeyDerivation.deriveChildKey(node, type | ChildNumber.HARDENED_BIT); } }
public static ECKey deriveECKey(DeterministicKey masterKey, int accountIndex) { DeterministicKey purposeKey = HDKeyDerivation.deriveChildKey(masterKey, DERIVATION_PATH_PURPOSE | ChildNumber.HARDENED_BIT); DeterministicKey rootKey = HDKeyDerivation.deriveChildKey(purposeKey, DERIVATION_PATH_COIN | ChildNumber.HARDENED_BIT); DeterministicKey accountKey = HDKeyDerivation.deriveChildKey(rootKey, accountIndex | ChildNumber.HARDENED_BIT); DeterministicKey changeKey = HDKeyDerivation.deriveChildKey(accountKey, CHANGE_INDEX); DeterministicKey addressKey = HDKeyDerivation.deriveChildKey(changeKey, ADDRESS_INDEX); return ECKey.fromPrivate(addressKey.getPrivKeyBytes()); }
/** * Derives a child at the given index using hardened derivation. Note: <code>index</code> is * not the "i" value. If you want the softened derivation, then use instead * <code>HDKeyDerivation.deriveChildKey(this, new ChildNumber(child, false))</code>. */ public DeterministicKey derive(int child) { return HDKeyDerivation.deriveChildKey(this, new ChildNumber(child, true)); }
private DeterministicKey deriveChild(DeterministicKey parent, ChildNumber createChildNumber) { DeterministicKey childKey = HDKeyDerivation.deriveChildKey(parent, createChildNumber); putKey(childKey); return childKey; }
/** * Derives a key given the "extended" child number, ie. the 0x80000000 bit of the value that you * pass for <code>childNumber</code> will determine whether to use hardened derivation or not. * Consider whether your code would benefit from the clarity of the equivalent, but explicit, form * of this method that takes a <code>ChildNumber</code> rather than an <code>int</code>, for example: * <code>deriveChildKey(parent, new ChildNumber(childNumber, true))</code> * where the value of the hardened bit of <code>childNumber</code> is zero. */ public static DeterministicKey deriveChildKey(DeterministicKey parent, int childNumber) { return deriveChildKey(parent, new ChildNumber(childNumber)); }
/** * Derives a key given the "extended" child number, ie. the 0x80000000 bit of the value that you * pass for <code>childNumber</code> will determine whether to use hardened derivation or not. * Consider whether your code would benefit from the clarity of the equivalent, but explicit, form * of this method that takes a <code>ChildNumber</code> rather than an <code>int</code>, for example: * <code>deriveChildKey(parent, new ChildNumber(childNumber, true))</code> * where the value of the hardened bit of <code>childNumber</code> is zero. */ public static DeterministicKey deriveChildKey(DeterministicKey parent, int childNumber) { return deriveChildKey(parent, new ChildNumber(childNumber)); }
/** * Derives a child at the given index using hardened derivation. Note: <code>index</code> is * not the "i" value. If you want the softened derivation, then use instead * <code>HDKeyDerivation.deriveChildKey(this, new ChildNumber(child, false))</code>. */ public DeterministicKey derive(int child) { return HDKeyDerivation.deriveChildKey(this, new ChildNumber(child, true)); }
private DeterministicKey deriveChild(DeterministicKey parent, ChildNumber createChildNumber) { DeterministicKey childKey = HDKeyDerivation.deriveChildKey(parent, createChildNumber); putKey(childKey); return childKey; }
/** * Derives a child at the given index using hardened derivation. Note: {@code index} is * not the "i" value. If you want the softened derivation, then use instead * {@code HDKeyDerivation.deriveChildKey(this, new ChildNumber(child, false))}. */ public DeterministicKey derive(int child) { return HDKeyDerivation.deriveChildKey(this, new ChildNumber(child, true)); }
/** * Derives a key given the "extended" child number, ie. the 0x80000000 bit of the value that you * pass for <code>childNumber</code> will determine whether to use hardened derivation or not. * Consider whether your code would benefit from the clarity of the equivalent, but explicit, form * of this method that takes a <code>ChildNumber</code> rather than an <code>int</code>, for example: * <code>deriveChildKey(parent, new ChildNumber(childNumber, true))</code> * where the value of the hardened bit of <code>childNumber</code> is zero. */ public static DeterministicKey deriveChildKey(DeterministicKey parent, int childNumber) { return deriveChildKey(parent, new ChildNumber(childNumber)); }
/** * Derives a child at the given index using hardened derivation. Note: <code>index</code> is * not the "i" value. If you want the softened derivation, then use instead * <code>HDKeyDerivation.deriveChildKey(this, new ChildNumber(child, false))</code>. */ public DeterministicKey derive(int child) { return HDKeyDerivation.deriveChildKey(this, new ChildNumber(child, true)); }
private DeterministicKey deriveChild(DeterministicKey parent, ChildNumber createChildNumber) { DeterministicKey childKey = HDKeyDerivation.deriveChildKey(parent, createChildNumber); putKey(childKey); return childKey; }
private DeterministicKey deriveChild(DeterministicKey parent, ChildNumber createChildNumber) { DeterministicKey childKey = HDKeyDerivation.deriveChildKey(parent, createChildNumber); putKey(childKey); return childKey; }
/** * Derives a key given the "extended" child number, ie. the 0x80000000 bit of the value that you * pass for {@code childNumber} will determine whether to use hardened derivation or not. * Consider whether your code would benefit from the clarity of the equivalent, but explicit, form * of this method that takes a {@code ChildNumber} rather than an {@code int}, for example: * {@code deriveChildKey(parent, new ChildNumber(childNumber, true))} * where the value of the hardened bit of {@code childNumber} is zero. */ public static DeterministicKey deriveChildKey(DeterministicKey parent, int childNumber) { return deriveChildKey(parent, new ChildNumber(childNumber)); }
public static DeterministicKey deriveMetadataNode(DeterministicKey node) throws UnsupportedEncodingException, NoSuchAlgorithmException { return HDKeyDerivation.deriveChildKey(node, getPurpose("metadata") | ChildNumber.HARDENED_BIT); }
public static DeterministicKey deriveSharedMetadataNode(DeterministicKey node) throws UnsupportedEncodingException, NoSuchAlgorithmException { return HDKeyDerivation.deriveChildKey(node, getPurpose("mdid") | ChildNumber.HARDENED_BIT); }
/** * Constructor for a chain. * * @param params NetworkParameters * @param aKey deterministic key for this chain * @param isReceive this is the receive chain */ public HDChain(NetworkParameters params, DeterministicKey aKey, boolean isReceive) { this.params = params; this.isReceive = isReceive; int chain = isReceive ? RECEIVE_CHAIN : CHANGE_CHAIN; cKey = HDKeyDerivation.deriveChildKey(aKey, chain); strPath = cKey.getPathAsString(); }
private BigInteger derivePrivateKeyDownwards(DeterministicKey cursor, byte[] parentalPrivateKeyBytes) { DeterministicKey downCursor = new DeterministicKey(cursor.childNumberPath, cursor.chainCode, cursor.pub, new BigInteger(1, parentalPrivateKeyBytes), cursor.parent); // Now we have to rederive the keys along the path back to ourselves. That path can be found by just truncating // our path with the length of the parents path. ImmutableList<ChildNumber> path = childNumberPath.subList(cursor.getPath().size(), childNumberPath.size()); for (ChildNumber num : path) { downCursor = HDKeyDerivation.deriveChildKey(downCursor, num); } // downCursor is now the same key as us, but with private key bytes. // If it's not, it means we tried decrypting with an invalid password and earlier checks e.g. for padding didn't // catch it. if (!downCursor.pub.equals(pub)) throw new KeyCrypterException("Could not decrypt bytes"); return checkNotNull(downCursor.priv); }
private BigInteger derivePrivateKeyDownwards(DeterministicKey cursor, byte[] parentalPrivateKeyBytes) { DeterministicKey downCursor = new DeterministicKey(cursor.childNumberPath, cursor.chainCode, cursor.pub, new BigInteger(1, parentalPrivateKeyBytes), cursor.parent); // Now we have to rederive the keys along the path back to ourselves. That path can be found by just truncating // our path with the length of the parents path. ImmutableList<ChildNumber> path = childNumberPath.subList(cursor.getPath().size(), childNumberPath.size()); for (ChildNumber num : path) { downCursor = HDKeyDerivation.deriveChildKey(downCursor, num); } // downCursor is now the same key as us, but with private key bytes. // If it's not, it means we tried decrypting with an invalid password and earlier checks e.g. for padding didn't // catch it. if (!downCursor.pub.equals(pub)) throw new KeyCrypterException("Could not decrypt bytes"); return checkNotNull(downCursor.priv); }
@Test public void parentlessDeserialization() { NetworkParameters params = UnitTestParams.get(); DeterministicKey key1 = HDKeyDerivation.createMasterPrivateKey("satoshi lives!".getBytes()); DeterministicKey key2 = HDKeyDerivation.deriveChildKey(key1, ChildNumber.ZERO_HARDENED); DeterministicKey key3 = HDKeyDerivation.deriveChildKey(key2, ChildNumber.ZERO_HARDENED); DeterministicKey key4 = HDKeyDerivation.deriveChildKey(key3, ChildNumber.ZERO_HARDENED); assertEquals(key4.getPath().size(), 3); assertEquals(DeterministicKey.deserialize(params, key4.serializePrivate(params), key3).getPath().size(), 3); assertEquals(DeterministicKey.deserialize(params, key4.serializePrivate(params), null).getPath().size(), 1); assertEquals(DeterministicKey.deserialize(params, key4.serializePrivate(params)).getPath().size(), 1); }