From afe8552be66a05b379ddc7b5f78e40f8a76540b8 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 3 Jan 2024 11:07:03 +0000 Subject: =?UTF-8?q?com=C3=83poser=20add=20tephenhill/base58?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vendor/stephenhill/base58/src/Base58.php | 90 ++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 vendor/stephenhill/base58/src/Base58.php (limited to 'vendor/stephenhill/base58/src/Base58.php') diff --git a/vendor/stephenhill/base58/src/Base58.php b/vendor/stephenhill/base58/src/Base58.php new file mode 100644 index 000000000..75a2e0de4 --- /dev/null +++ b/vendor/stephenhill/base58/src/Base58.php @@ -0,0 +1,90 @@ + + * @copyright 2014 Stephen Hill + * @license http://www.opensource.org/licenses/MIT The MIT License + * @link https://github.com/stephen-hill/base58php + * @since Release v1.0.0 + */ +class Base58 +{ + /** + * @var StephenHill\ServiceInterface; + * @since v1.1.0 + */ + protected $service; + + /** + * Constructor + * + * @param string $alphabet optional + * @param ServiceInterface $service optional + * @since v1.0.0 + * @since v1.1.0 Added the optional $service argument. + */ + public function __construct( + $alphabet = null, + ServiceInterface $service = null + ) { + // Handle null alphabet + if (is_null($alphabet) === true) { + $alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'; + } + + // Type validation + if (is_string($alphabet) === false) { + throw new InvalidArgumentException('Argument $alphabet must be a string.'); + } + + // The alphabet must contain 58 characters + if (strlen($alphabet) !== 58) { + throw new InvalidArgumentException('Argument $alphabet must contain 58 characters.'); + } + + // Provide a default service if one isn't injected + if ($service === null) { + // Check for GMP support first + if (function_exists('\gmp_init') === true) { + $service = new GMPService($alphabet); + } + else if (function_exists('\bcmul') === true) { + $service = new BCMathService($alphabet); + } + else { + throw new \Exception('Please install the BC Math or GMP extension.'); + } + } + + $this->service = $service; + } + + /** + * Encode a string into base58. + * + * @param string $string The string you wish to encode. + * @since v1.0.0 + * @return string The Base58 encoded string. + */ + public function encode($string) + { + return $this->service->encode($string); + } + + /** + * Decode base58 into a PHP string. + * + * @param string $base58 The base58 encoded string. + * @since v1.0.0 + * @return string Returns the decoded string. + */ + public function decode($base58) + { + return $this->service->decode($base58); + } +} -- cgit v1.2.3