/**
  * @param CompactSignature $signature
  * @return BufferInterface
  */
 private function doSerialize(CompactSignature $signature)
 {
     $sig_t = '';
     $recid = '';
     if (!secp256k1_ecdsa_recoverable_signature_serialize_compact($this->ecAdapter->getContext(), $signature->getResource(), $sig_t, $recid)) {
         throw new \RuntimeException('Secp256k1 serialize compact failure');
     }
     return new Buffer(chr((int) $signature->getFlags()) . $sig_t, 65, $this->ecAdapter->getMath());
 }
Пример #2
0
 /**
  * @param BufferInterface $msg32
  * @param CompactSignature $compactSig
  * @return PublicKey
  */
 private function doRecover(BufferInterface $msg32, CompactSignature $compactSig)
 {
     $publicKey = '';
     /** @var resource $publicKey */
     $context = $this->context;
     $sig = $compactSig->getResource();
     if (1 !== secp256k1_ecdsa_recover($context, $msg32->getBinary(), $sig, $publicKey)) {
         throw new \RuntimeException('Unable to recover Public Key');
     }
     return new PublicKey($this, $publicKey, $compactSig->isCompressed());
 }