/** * @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); }
/** * @param string $address * @param NetworkInterface $network * @return AddressInterface * @throws \BitWasp\Bitcoin\Exceptions\Base58ChecksumFailure */ public static function fromString($address, NetworkInterface $network = null) { $network = $network ?: Bitcoin::getNetwork(); $data = Base58::decodeCheck($address); $prefixByte = $data->slice(0, 1)->getHex(); if ($prefixByte === $network->getP2shByte()) { return new ScriptHashAddress($data->slice(1)); } else { if ($prefixByte === $network->getAddressByte()) { return new PayToPubKeyHashAddress($data->slice(1)); } else { throw new \InvalidArgumentException("Invalid prefix [{$prefixByte}]"); } } }
/** * @param string $wif * @return PrivateKeyInterface * @throws InvalidPrivateKey * @throws Base58ChecksumFailure */ public function parse($wif) { $payload = Base58::decodeCheck($wif)->slice(1); $size = $payload->getSize(); if (33 === $size) { $compressed = true; $payload = $payload->slice(0, 32); } else { if (32 === $size) { $compressed = false; } else { throw new InvalidPrivateKey("Private key should be always be 32 or 33 bytes (depending on if it's compressed)"); } } return PrivateKeyFactory::fromInt($payload->getInt(), $compressed); }
/** * @param string $base58 * @return HierarchicalKey * @throws \BitWasp\Bitcoin\Exceptions\Base58ChecksumFailure * @throws \BitWasp\Buffertools\Exceptions\ParserOutOfRange * @throws \Exception */ public function parse($base58) { $payload = Base58::decodeCheck($base58); return $this->hexSerializer->parse($payload); }