Exemplo n.º 1
0
 /**
  * @param CompactSignature $signature
  * @param Buffer $messageHash
  * @return \BitWasp\Bitcoin\Key\PublicKey
  * @throws \Exception
  */
 public function recoverCompact(Buffer $messageHash, CompactSignature $signature)
 {
     $pubkey = '';
     $ret = \secp256k1_ecdsa_recover_compact($messageHash->getBinary(), $signature->getBuffer()->slice(1)->getBinary(), (int) $signature->getRecoveryId(), (int) $signature->isCompressed(), $pubkey);
     if ($ret === 1) {
         $publicKey = PublicKeyFactory::fromHex(bin2hex($pubkey));
         return $publicKey->setCompressed($signature->isCompressed());
     }
     throw new \Exception('Unable to recover public key from compact signature');
 }