From b3542b286b8450c51d40ca88fe3419923bd1932f Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 1 Apr 2017 19:15:08 +0200 Subject: [PATCH] Remove bitcoin validator --- Validation/BitcoinValidator.php | 107 -------------------------------- 1 file changed, 107 deletions(-) delete mode 100644 Validation/BitcoinValidator.php diff --git a/Validation/BitcoinValidator.php b/Validation/BitcoinValidator.php deleted file mode 100644 index a5746f2e7..000000000 --- a/Validation/BitcoinValidator.php +++ /dev/null @@ -1,107 +0,0 @@ - - * @author Dennis Eichhorn - * @copyright Dennis Eichhorn - * @license OMS License 1.0 - * @version 1.0.0 - * @link http://orange-management.com - */ -declare(strict_types=1); - -namespace phpOMS\Validation; - -/** - * Bitcoin validator. - * - * @category Framework - * @package phpOMS\Utils\TaskSchedule - * @author OMS Development Team - * @author Dennis Eichhorn - * @license OMS License 1.0 - * @link http://orange-management.com - * @since 1.0.0 - */ -class BitcoinValidator extends ValidatorAbstract -{ - /** - * Validate bitcoin. - * - * @param string $addr Bitcoin address - * - * @return bool - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public static function isValid(string $addr) : bool - { - try { - $decoded = self::decodeBase58($addr); - - $d1 = hash("sha256", substr($decoded, 0, 21), true); - $d2 = hash("sha256", $d1, true); - - if (substr_compare($decoded, $d2, 21, 4)) { - return false; - } - - return true; - } catch (\Exception $e) { - self::$msg = $e->getMessage(); - - return false; - } - } - - /** - * Decode base 58 bitcoin address. - * - * @param string $addr Bitcoin address - * - * @return string - * - * @throws \Exception - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - private static function decodeBase58(string $addr) : string - { - $alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'; - - $out = array_fill(0, 25, 0); - $length = strlen($addr); - - for ($i = 0; $i < $length; $i++) { - if (($p = strpos($alphabet, $addr[$i])) === false) { - throw new \Exception('Invalid character found in address.'); - } - - $c = $p; - for ($j = 25; $j--;) { - $c += (int) (58 * $out[$j]); - $out[$j] = (int) ($c % 256); - $c /= 256; - $c = (int) $c; - } - - if ($c !== 0) { - throw new \Exception('Bitcoin address too long.'); - } - } - - $result = ''; - foreach ($out as $val) { - $result .= chr($val); - } - - return $result; - } -} \ No newline at end of file