Пример #1
0
 /**
  * Derive a child key
  *
  * @param $sequence
  * @return HierarchicalKey
  * @throws \Exception
  */
 public function deriveChild($sequence)
 {
     $chain = Buffer::int($this->getChainCode(), 32, $this->ecAdapter->getMath());
     $hash = Hash::hmac('sha512', $this->getHmacSeed($sequence), $chain);
     $offset = $hash->slice(0, 32);
     $chain = $hash->slice(32);
     $key = $this->isPrivate() ? $this->getPrivateKey() : $this->getPublicKey();
     if (false === $this->ecAdapter->validatePrivateKey($offset)) {
         return $this->deriveChild($sequence + 1);
     }
     return new HierarchicalKey($this->ecAdapter, $this->getDepth() + 1, $this->getChildFingerprint(), $sequence, $chain->getInt(), $key->tweakAdd($offset->getInt()));
 }