/** * @param Buffer $hash * @param int|string $nBits * @return bool */ public function check(Buffer $hash, $nBits) { $negative = false; $overflow = false; $target = $this->math->writeCompact($nBits, $negative, $overflow); if ($negative || $overflow || $this->math->cmp($target, 0) === 0 || $this->math->cmp($target, $this->getMaxTarget()) > 0) { throw new \RuntimeException('nBits below minimum work'); } if ($this->math->cmp($hash->getInt(), $target) > 0) { throw new \RuntimeException("Hash doesn't match nBits"); } return true; }