Пример #1
0
 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.
   checkState(downCursor.pub.equals(pub));
   return checkNotNull(downCursor.priv);
 }
Пример #2
0
 /**
  * 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));
 }