/** * 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 ChildNumber getNextChildNumberToDerive(ImmutableList<ChildNumber> path, boolean privateDerivation) { ChildNumber lastChildNumber = lastChildNumbers.get(path); ChildNumber nextChildNumber = new ChildNumber(lastChildNumber != null ? lastChildNumber.num() + 1 : 0, privateDerivation); lastChildNumbers.put(path, nextChildNumber); return nextChildNumber; }
/** * 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)); }
/** * 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)); }
private ChildNumber getNextChildNumberToDerive(ImmutableList<ChildNumber> path, boolean privateDerivation) { ChildNumber lastChildNumber = lastChildNumbers.get(path); ChildNumber nextChildNumber = new ChildNumber(lastChildNumber != null ? lastChildNumber.num() + 1 : 0, privateDerivation); lastChildNumbers.put(path, nextChildNumber); return nextChildNumber; }
/** * 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 ChildNumber getNextChildNumberToDerive(ImmutableList<ChildNumber> path, boolean privateDerivation) { ChildNumber lastChildNumber = lastChildNumbers.get(path); ChildNumber nextChildNumber = new ChildNumber(lastChildNumber != null ? lastChildNumber.num() + 1 : 0, privateDerivation); lastChildNumbers.put(path, nextChildNumber); return nextChildNumber; }
/** * 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 ChildNumber getNextChildNumberToDerive(ImmutableList<ChildNumber> path, boolean privateDerivation) { ChildNumber lastChildNumber = lastChildNumbers.get(path); ChildNumber nextChildNumber = new ChildNumber(lastChildNumber != null ? lastChildNumber.num() + 1 : 0, privateDerivation); lastChildNumbers.put(path, nextChildNumber); return nextChildNumber; }
/** * 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)); }
/** * The path is a human-friendly representation of the deterministic path. For example: * * "44H / 0H / 0H / 1 / 1" * * Where a letter "H" means hardened key. Spaces are ignored. */ public static List<ChildNumber> parsePath(@Nonnull String path) { String[] parsedNodes = path.replace("M", "").split("/"); List<ChildNumber> nodes = new ArrayList<ChildNumber>(); for (String n : parsedNodes) { n = n.replaceAll(" ", ""); if (n.length() == 0) continue; boolean isHard = n.endsWith("H"); if (isHard) n = n.substring(0, n.length() - 1); int nodeNumber = Integer.parseInt(n); nodes.add(new ChildNumber(nodeNumber, isHard)); } return nodes; } }
public static ImmutableList<ChildNumber> getKeyProtoPath(Protos.Key key) { ImmutableList.Builder<ChildNumber> pathBuilder = ImmutableList.builder(); for (int i : key.getDeterministicKey().getPathList()) { pathBuilder.add(new ChildNumber(i)); } return pathBuilder.build(); }
public static ImmutableList<ChildNumber> getKeyProtoPath(Protos.Key key) { ImmutableList.Builder<ChildNumber> pathBuilder = ImmutableList.builder(); for (int i : key.getDeterministicKey().getPathList()) { pathBuilder.add(new ChildNumber(i)); } return pathBuilder.build(); }
/** * Generate the DeterministicKey from the private master key for a Trezor wallet * <p/> * For a real Trezor device this will be the result of a GetPublicKey of the M/44'/0'/0' path, received as an xpub and then converted to a DeterministicKey * * @param privateMasterKey the private master key derived from the wallet seed * * @return the public only DeterministicSeed corresponding to the root Trezor wallet node e.g. M/44'/0'/0' */ public static DeterministicKey generateTrezorWalletRootNode(DeterministicKey privateMasterKey) { DeterministicKey key_m_44h = HDKeyDerivation.deriveChildKey(privateMasterKey, new ChildNumber(44 | ChildNumber.HARDENED_BIT)); log.debug("key_m_44h deterministic key = " + key_m_44h); DeterministicKey key_m_44h_0h = HDKeyDerivation.deriveChildKey(key_m_44h, ChildNumber.ZERO_HARDENED); log.debug("key_m_44h_0h deterministic key = " + key_m_44h_0h); DeterministicKey key_m_44h_0h_0h = HDKeyDerivation.deriveChildKey(key_m_44h_0h, ChildNumber.ZERO_HARDENED); log.debug("key_m_44h_0h_0h = " + key_m_44h_0h_0h); return key_m_44h_0h_0h; }
/** * Derives a key of the "extended" child number, ie. with the 0x80000000 bit specifying whether to use * hardened derivation or not. If derivation fails, tries a next child. */ public static DeterministicKey deriveThisOrNextChildKey(DeterministicKey parent, int childNumber) { int nAttempts = 0; ChildNumber child = new ChildNumber(childNumber); boolean isHardened = child.isHardened(); while (nAttempts < MAX_CHILD_DERIVATION_ATTEMPTS) { try { child = new ChildNumber(child.num() + nAttempts, isHardened); return deriveChildKey(parent, child); } catch (HDDerivationException ignore) { } nAttempts++; } throw new HDDerivationException("Maximum number of child derivation attempts reached, this is probably an indication of a bug."); }
/** * Derives a key of the "extended" child number, ie. with the 0x80000000 bit specifying whether to use * hardened derivation or not. If derivation fails, tries a next child. */ public static DeterministicKey deriveThisOrNextChildKey(DeterministicKey parent, int childNumber) { int nAttempts = 0; ChildNumber child = new ChildNumber(childNumber); boolean isHardened = child.isHardened(); while (nAttempts < MAX_CHILD_DERIVATION_ATTEMPTS) { try { child = new ChildNumber(child.num() + nAttempts, isHardened); return deriveChildKey(parent, child); } catch (HDDerivationException ignore) { } nAttempts++; } throw new HDDerivationException("Maximum number of child derivation attempts reached, this is probably an indication of a bug."); }
/** * Derives a key of the "extended" child number, ie. with the 0x80000000 bit specifying whether to use * hardened derivation or not. If derivation fails, tries a next child. */ public static DeterministicKey deriveThisOrNextChildKey(DeterministicKey parent, int childNumber) { int nAttempts = 0; ChildNumber child = new ChildNumber(childNumber); boolean isHardened = child.isHardened(); while (nAttempts < MAX_CHILD_DERIVATION_ATTEMPTS) { try { child = new ChildNumber(child.num() + nAttempts, isHardened); return deriveChildKey(parent, child); } catch (HDDerivationException ignore) { } nAttempts++; } throw new HDDerivationException("Maximum number of child derivation attempts reached, this is probably an indication of a bug."); }
/** * Derives a key of the "extended" child number, ie. with the 0x80000000 bit specifying whether to use * hardened derivation or not. If derivation fails, tries a next child. */ public static DeterministicKey deriveThisOrNextChildKey(DeterministicKey parent, int childNumber) { int nAttempts = 0; ChildNumber child = new ChildNumber(childNumber); boolean isHardened = child.isHardened(); while (nAttempts < MAX_CHILD_DERIVATION_ATTEMPTS) { try { child = new ChildNumber(child.num() + nAttempts, isHardened); return deriveChildKey(parent, child); } catch (HDDerivationException ignore) { } nAttempts++; } throw new HDDerivationException("Maximum number of child derivation attempts reached, this is probably an indication of a bug."); }