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