/**
  * @param string $hex
  * @param bool $compressed
  * @param EcAdapterInterface|null $ecAdapter
  * @return PrivateKey
  */
 public static function fromHex($hex, $compressed = false, EcAdapterInterface $ecAdapter = null)
 {
     $hex = Buffer::hex($hex);
     $ecAdapter = $ecAdapter ?: Bitcoin::getEcAdapter();
     $hexSerializer = new HexPrivateKeySerializer($ecAdapter);
     return $hexSerializer->parse($hex)->setCompressed($compressed);
 }
 /**
  * @param $wif
  * @return PrivateKey
  * @throws InvalidPrivateKey
  * @throws Base58ChecksumFailure
  */
 public function parse($wif)
 {
     $payload = Base58::decodeCheck($wif)->slice(1);
     $size = $payload->getSize();
     if (!in_array($size, [32, 33])) {
         throw new InvalidPrivateKey("Private key should be always be 32 or 33 bytes (depending on if it's compressed)");
     }
     return $this->hexSerializer->parse($payload->slice(0, 32))->setCompressed($size === 33);
 }
Example #3
0
 /**
  * @return \BitWasp\Buffertools\Buffer
  */
 public function getBuffer()
 {
     $hexSerializer = new HexPrivateKeySerializer($this->ecAdapter);
     return $hexSerializer->serialize($this);
 }