/**
  * @param PublicKey $publicKey
  * @return Buffer
  */
 private function doSerialize(PublicKey $publicKey)
 {
     $math = $this->ecAdapter->getMath();
     $point = $publicKey->getPoint();
     $compressed = $publicKey->isCompressed();
     $parser = new Parser('', $math);
     $parser->writeBytes(1, $this->getPrefix($compressed, $point));
     $compressed ? $parser->writeBytes(32, Buffer::int($point->getX(), null, $math)) : $parser->writeBytes(32, Buffer::int($point->getX(), null, $math))->writeBytes(32, Buffer::int($point->getY(), null, $math));
     return $parser->getBuffer();
 }
 /**
  * @param SignatureInterface $signature
  * @return BufferInterface
  */
 public function serialize(SignatureInterface $signature)
 {
     $math = $this->ecAdapter->getMath();
     // Ensure that the R and S hex's are of even length
     $rBin = pack('H*', $math->decHex($signature->getR()));
     $sBin = pack('H*', $math->decHex($signature->getS()));
     // Pad R and S if their highest bit is flipped, ie,
     // they are negative.
     $rt = $rBin[0] & pack('H*', '80');
     if (ord($rt) === 128) {
         $rBin = pack('H*', '00') . $rBin;
     }
     $st = $sBin[0] & pack('H*', '80');
     if (ord($st) === 128) {
         $sBin = pack('H*', '00') . $sBin;
     }
     return $this->getOuterTemplate()->write([0x30, $this->getInnerTemplate()->write([0x2, new Buffer($rBin, null, $math), 0x2, new Buffer($sBin, null, $math)])]);
 }
 /**
  * @param PrivateKeyInterface $privateKey
  * @return BufferInterface
  */
 public function serialize(PrivateKeyInterface $privateKey)
 {
     return Buffer::int($privateKey->getSecretMultiplier(), 32, $this->ecAdapter->getMath());
 }
Example #4
0
 /**
  * @param NetworkInterface $network
  * @return string
  */
 public function toWif(NetworkInterface $network = null)
 {
     $network = $network ?: Bitcoin::getNetwork();
     $serializer = new WifPrivateKeySerializer($this->ecAdapter->getMath(), new PrivateKeySerializer($this->ecAdapter));
     return $serializer->serialize($network, $this);
 }
 /**
  * @param $string
  * @return CompactSignature
  * @throws ParserOutOfRange
  */
 public function parse($string)
 {
     return $this->fromParser(new Parser($string, $this->ecAdapter->getMath()));
 }