diff options
24 files changed, 1091 insertions, 4 deletions
diff --git a/composer.json b/composer.json index cc334a181..e54229302 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,8 @@ "jbroadway/urlify": "^1.2", "chillerlan/php-qrcode": "^4.3", "spomky-labs/otphp": "^11.1", - "patrickschur/language-detection": "^5.3" + "patrickschur/language-detection": "^5.3", + "stephenhill/base58": "^1.1" }, "require-dev": { "phpunit/phpunit": "^9.4", diff --git a/composer.lock b/composer.lock index d091733a9..2a32f3440 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9405cfa865704905a31f52a966828381", + "content-hash": "12cae0f6c48ce883e11b85fdbcb4b786", "packages": [ { "name": "blueimp/jquery-file-upload", @@ -1912,6 +1912,48 @@ "time": "2023-03-16T19:16:25+00:00" }, { + "name": "stephenhill/base58", + "version": "v1.1.5", + "source": { + "type": "git", + "url": "https://github.com/stephen-hill/base58php.git", + "reference": "bd9fc19c788160a2f85ba0a19cd800eaf5ba5e99" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/stephen-hill/base58php/zipball/bd9fc19c788160a2f85ba0a19cd800eaf5ba5e99", + "reference": "bd9fc19c788160a2f85ba0a19cd800eaf5ba5e99", + "shasum": "" + }, + "require-dev": { + "athletic/athletic": "~0.1", + "phpunit/phpunit": "4.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "StephenHill\\": "src/", + "StephenHill\\Benchmarks\\": "benchmarks/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Stephen Hill", + "email": "stephen@gatekiller.co.uk" + } + ], + "description": "Base58 Encoding and Decoding Library for PHP", + "support": { + "issues": "https://github.com/stephen-hill/base58php/issues", + "source": "https://github.com/stephen-hill/base58php/tree/v1.1.5" + }, + "time": "2019-08-22T16:51:59+00:00" + }, + { "name": "symfony/polyfill-php81", "version": "v1.28.0", "source": { diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index c95fe5704..a604b0b37 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -1151,6 +1151,14 @@ return array( 'Smarty_Template_Source' => $vendorDir . '/smarty/smarty/libs/sysplugins/smarty_template_source.php', 'Smarty_Undefined_Variable' => $vendorDir . '/smarty/smarty/libs/sysplugins/smarty_undefined_variable.php', 'Smarty_Variable' => $vendorDir . '/smarty/smarty/libs/sysplugins/smarty_variable.php', + 'StephenHill\\BCMathService' => $vendorDir . '/stephenhill/base58/src/BCMathService.php', + 'StephenHill\\Base58' => $vendorDir . '/stephenhill/base58/src/Base58.php', + 'StephenHill\\Benchmarks\\Base16Event' => $vendorDir . '/stephenhill/base58/benchmarks/Base16Event.php', + 'StephenHill\\Benchmarks\\Base58BCMathEvent' => $vendorDir . '/stephenhill/base58/benchmarks/Base58BCMathEvent.php', + 'StephenHill\\Benchmarks\\Base58GMPEvent' => $vendorDir . '/stephenhill/base58/benchmarks/Base58GMPEvent.php', + 'StephenHill\\Benchmarks\\Base64Event' => $vendorDir . '/stephenhill/base58/benchmarks/Base64Event.php', + 'StephenHill\\GMPService' => $vendorDir . '/stephenhill/base58/src/GMPService.php', + 'StephenHill\\ServiceInterface' => $vendorDir . '/stephenhill/base58/src/ServiceInterface.php', 'Symfony\\Polyfill\\Php81\\Php81' => $vendorDir . '/symfony/polyfill-php81/Php81.php', 'TPC_yyStackEntry' => $vendorDir . '/smarty/smarty/libs/sysplugins/smarty_internal_configfileparser.php', 'TP_yyStackEntry' => $vendorDir . '/smarty/smarty/libs/sysplugins/smarty_internal_templateparser.php', diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php index ceeb74ea9..630675b4f 100644 --- a/vendor/composer/autoload_psr4.php +++ b/vendor/composer/autoload_psr4.php @@ -12,6 +12,8 @@ return array( 'chillerlan\\QRCode\\' => array($vendorDir . '/chillerlan/php-qrcode/src'), 'Zotlabs\\' => array($baseDir . '/Zotlabs'), 'Symfony\\Polyfill\\Php81\\' => array($vendorDir . '/symfony/polyfill-php81'), + 'StephenHill\\Benchmarks\\' => array($vendorDir . '/stephenhill/base58/benchmarks'), + 'StephenHill\\' => array($vendorDir . '/stephenhill/base58/src'), 'SimplePie\\' => array($vendorDir . '/simplepie/simplepie/src'), 'Sabre\\Xml\\' => array($vendorDir . '/sabre/xml/lib'), 'Sabre\\VObject\\' => array($vendorDir . '/sabre/vobject/lib'), diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index bba7367f7..eccce46ef 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -41,6 +41,8 @@ class ComposerStaticInit7b34d7e50a62201ec5d5e526a5b8b35d 'S' => array ( 'Symfony\\Polyfill\\Php81\\' => 23, + 'StephenHill\\Benchmarks\\' => 23, + 'StephenHill\\' => 12, 'SimplePie\\' => 10, 'Sabre\\Xml\\' => 10, 'Sabre\\VObject\\' => 14, @@ -116,6 +118,14 @@ class ComposerStaticInit7b34d7e50a62201ec5d5e526a5b8b35d array ( 0 => __DIR__ . '/..' . '/symfony/polyfill-php81', ), + 'StephenHill\\Benchmarks\\' => + array ( + 0 => __DIR__ . '/..' . '/stephenhill/base58/benchmarks', + ), + 'StephenHill\\' => + array ( + 0 => __DIR__ . '/..' . '/stephenhill/base58/src', + ), 'SimplePie\\' => array ( 0 => __DIR__ . '/..' . '/simplepie/simplepie/src', @@ -1378,6 +1388,14 @@ class ComposerStaticInit7b34d7e50a62201ec5d5e526a5b8b35d 'Smarty_Template_Source' => __DIR__ . '/..' . '/smarty/smarty/libs/sysplugins/smarty_template_source.php', 'Smarty_Undefined_Variable' => __DIR__ . '/..' . '/smarty/smarty/libs/sysplugins/smarty_undefined_variable.php', 'Smarty_Variable' => __DIR__ . '/..' . '/smarty/smarty/libs/sysplugins/smarty_variable.php', + 'StephenHill\\BCMathService' => __DIR__ . '/..' . '/stephenhill/base58/src/BCMathService.php', + 'StephenHill\\Base58' => __DIR__ . '/..' . '/stephenhill/base58/src/Base58.php', + 'StephenHill\\Benchmarks\\Base16Event' => __DIR__ . '/..' . '/stephenhill/base58/benchmarks/Base16Event.php', + 'StephenHill\\Benchmarks\\Base58BCMathEvent' => __DIR__ . '/..' . '/stephenhill/base58/benchmarks/Base58BCMathEvent.php', + 'StephenHill\\Benchmarks\\Base58GMPEvent' => __DIR__ . '/..' . '/stephenhill/base58/benchmarks/Base58GMPEvent.php', + 'StephenHill\\Benchmarks\\Base64Event' => __DIR__ . '/..' . '/stephenhill/base58/benchmarks/Base64Event.php', + 'StephenHill\\GMPService' => __DIR__ . '/..' . '/stephenhill/base58/src/GMPService.php', + 'StephenHill\\ServiceInterface' => __DIR__ . '/..' . '/stephenhill/base58/src/ServiceInterface.php', 'Symfony\\Polyfill\\Php81\\Php81' => __DIR__ . '/..' . '/symfony/polyfill-php81/Php81.php', 'TPC_yyStackEntry' => __DIR__ . '/..' . '/smarty/smarty/libs/sysplugins/smarty_internal_configfileparser.php', 'TP_yyStackEntry' => __DIR__ . '/..' . '/smarty/smarty/libs/sysplugins/smarty_internal_templateparser.php', diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 3be6a1e92..84ee74399 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -1982,6 +1982,51 @@ "install-path": "../spomky-labs/otphp" }, { + "name": "stephenhill/base58", + "version": "v1.1.5", + "version_normalized": "1.1.5.0", + "source": { + "type": "git", + "url": "https://github.com/stephen-hill/base58php.git", + "reference": "bd9fc19c788160a2f85ba0a19cd800eaf5ba5e99" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/stephen-hill/base58php/zipball/bd9fc19c788160a2f85ba0a19cd800eaf5ba5e99", + "reference": "bd9fc19c788160a2f85ba0a19cd800eaf5ba5e99", + "shasum": "" + }, + "require-dev": { + "athletic/athletic": "~0.1", + "phpunit/phpunit": "4.*" + }, + "time": "2019-08-22T16:51:59+00:00", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-4": { + "StephenHill\\": "src/", + "StephenHill\\Benchmarks\\": "benchmarks/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Stephen Hill", + "email": "stephen@gatekiller.co.uk" + } + ], + "description": "Base58 Encoding and Decoding Library for PHP", + "support": { + "issues": "https://github.com/stephen-hill/base58php/issues", + "source": "https://github.com/stephen-hill/base58php/tree/v1.1.5" + }, + "install-path": "../stephenhill/base58" + }, + { "name": "symfony/polyfill-php81", "version": "v1.28.0", "version_normalized": "1.28.0.0", diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 393977f73..aba97f8c4 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'zotlabs/hubzilla', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '85001c034b1353e7602911f9fbdf017188ed8b07', + 'reference' => 'cd0e50da249ba89252a6182b0ac239e003563f61', 'type' => 'application', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -268,6 +268,15 @@ 'aliases' => array(), 'dev_requirement' => false, ), + 'stephenhill/base58' => array( + 'pretty_version' => 'v1.1.5', + 'version' => '1.1.5.0', + 'reference' => 'bd9fc19c788160a2f85ba0a19cd800eaf5ba5e99', + 'type' => 'library', + 'install_path' => __DIR__ . '/../stephenhill/base58', + 'aliases' => array(), + 'dev_requirement' => false, + ), 'symfony/polyfill-php81' => array( 'pretty_version' => 'v1.28.0', 'version' => '1.28.0.0', @@ -313,7 +322,7 @@ 'zotlabs/hubzilla' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '85001c034b1353e7602911f9fbdf017188ed8b07', + 'reference' => 'cd0e50da249ba89252a6182b0ac239e003563f61', 'type' => 'application', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), diff --git a/vendor/stephenhill/base58/.gitignore b/vendor/stephenhill/base58/.gitignore new file mode 100644 index 000000000..b2df07bd9 --- /dev/null +++ b/vendor/stephenhill/base58/.gitignore @@ -0,0 +1,3 @@ +/vendor/ +/bin/ +composer.lock diff --git a/vendor/stephenhill/base58/.travis.yml b/vendor/stephenhill/base58/.travis.yml new file mode 100644 index 000000000..3e995f336 --- /dev/null +++ b/vendor/stephenhill/base58/.travis.yml @@ -0,0 +1,15 @@ +language: php + +before_script: + - composer install + +php: + - 5.3 + - 5.4 + - 5.5 + - 5.6 + - 7 + - 7.1 + - hhvm + +script: bin/phpunit diff --git a/vendor/stephenhill/base58/benchmarks/Base16Event.php b/vendor/stephenhill/base58/benchmarks/Base16Event.php new file mode 100644 index 000000000..f3ec0034d --- /dev/null +++ b/vendor/stephenhill/base58/benchmarks/Base16Event.php @@ -0,0 +1,24 @@ +<?php + +namespace StephenHill\Benchmarks; + +use Athletic\AthleticEvent; + +class Base16Event extends AthleticEvent +{ + /** + * @iterations 10000 + */ + public function encodeBase16() + { + bin2hex('Hello World'); + } + + /** + * @iterations 10000 + */ + public function decodeBase16() + { + pack('H*', '48656c6c6f20576f726c64'); + } +} diff --git a/vendor/stephenhill/base58/benchmarks/Base58BCMathEvent.php b/vendor/stephenhill/base58/benchmarks/Base58BCMathEvent.php new file mode 100644 index 000000000..fc8ec23ee --- /dev/null +++ b/vendor/stephenhill/base58/benchmarks/Base58BCMathEvent.php @@ -0,0 +1,33 @@ +<?php + +namespace StephenHill\Benchmarks; + +use Athletic\AthleticEvent; +use StephenHill\Base58; +use StephenHill\BCMathService; + +class Base58BCMathEvent extends AthleticEvent +{ + protected $base58; + + public function setUp() + { + $this->base58 = new Base58(null, new BCMathService()); + } + + /** + * @iterations 10000 + */ + public function encodeBase58() + { + $this->base58->encode('Hello World'); + } + + /** + * @iterations 10000 + */ + public function decodeBase58() + { + $this->base58->decode('JxF12TrwUP45BMd'); + } +} diff --git a/vendor/stephenhill/base58/benchmarks/Base58GMPEvent.php b/vendor/stephenhill/base58/benchmarks/Base58GMPEvent.php new file mode 100644 index 000000000..d8a4d20bf --- /dev/null +++ b/vendor/stephenhill/base58/benchmarks/Base58GMPEvent.php @@ -0,0 +1,33 @@ +<?php + +namespace StephenHill\Benchmarks; + +use Athletic\AthleticEvent; +use StephenHill\Base58; +use StephenHill\GMPService; + +class Base58GMPEvent extends AthleticEvent +{ + protected $base58; + + public function setUp() + { + $this->base58 = new Base58(null, new GMPService()); + } + + /** + * @iterations 10000 + */ + public function encodeBase58() + { + $this->base58->encode('Hello World'); + } + + /** + * @iterations 10000 + */ + public function decodeBase58() + { + $this->base58->decode('JxF12TrwUP45BMd'); + } +} diff --git a/vendor/stephenhill/base58/benchmarks/Base64Event.php b/vendor/stephenhill/base58/benchmarks/Base64Event.php new file mode 100644 index 000000000..a558968a3 --- /dev/null +++ b/vendor/stephenhill/base58/benchmarks/Base64Event.php @@ -0,0 +1,24 @@ +<?php + +namespace StephenHill\Benchmarks; + +use Athletic\AthleticEvent; + +class Base64Event extends AthleticEvent +{ + /** + * @iterations 10000 + */ + public function encodeBase64() + { + base64_encode('Hello World'); + } + + /** + * @iterations 10000 + */ + public function decodeBase64() + { + base64_decode('SGVsbG8gV29ybGQ='); + } +} diff --git a/vendor/stephenhill/base58/composer.json b/vendor/stephenhill/base58/composer.json new file mode 100644 index 000000000..560701f50 --- /dev/null +++ b/vendor/stephenhill/base58/composer.json @@ -0,0 +1,24 @@ +{ + "name": "stephenhill/base58", + "description": "Base58 Encoding and Decoding Library for PHP", + "require-dev": { + "phpunit/phpunit": "4.*", + "athletic/athletic": "~0.1" + }, + "license": "MIT", + "authors": [ + { + "name": "Stephen Hill", + "email": "stephen@gatekiller.co.uk" + } + ], + "config": { + "bin-dir": "bin" + }, + "autoload": { + "psr-4": { + "StephenHill\\": "src/", + "StephenHill\\Benchmarks\\": "benchmarks/" + } + } +}
\ No newline at end of file diff --git a/vendor/stephenhill/base58/contributing.md b/vendor/stephenhill/base58/contributing.md new file mode 100644 index 000000000..fbc33266d --- /dev/null +++ b/vendor/stephenhill/base58/contributing.md @@ -0,0 +1,24 @@ +# Contributing + +I welcome anyone to contribute to this project. All bug reports, feature requests, and pull requests are greatly appriciated. + +To contribute some code, please do the following: + +1. Fork this repository. +2. Create a new branch +3. Commit your changes to this branch. +4. Make sure your code follows the coding guidelines below. +5. When your happy with you changes, push this branch to Github. +6. Create a Pull Request into the master branch. + +## Coding Guidelines + +Please ensure your pull request adheres to the following: + +* New code should be properly tested, and all tests must pass +* PSR-1: Basic coding standard +* PSR-2: Coding style guide +* PSR-4: Autoloader +* Semantic Versioning 2.0.0 + +Thank you for your support!
\ No newline at end of file diff --git a/vendor/stephenhill/base58/docs/index.md b/vendor/stephenhill/base58/docs/index.md new file mode 100644 index 000000000..9723a91dd --- /dev/null +++ b/vendor/stephenhill/base58/docs/index.md @@ -0,0 +1,145 @@ +# Base58 Encoding and Decoding Library for PHP + +[![Build Status](https://travis-ci.org/stephen-hill/base58php.png)](https://travis-ci.org/stephen-hill/base58php) +[![Packagist Release](http://img.shields.io/packagist/v/stephenhill/base58.svg)](https://packagist.org/packages/stephenhill/base58) +[![MIT License](http://img.shields.io/packagist/l/stephenhill/base58.svg)](https://github.com/stephen-hill/base58php/blob/master/license) +[![Flattr this](https://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=stephen-hill&url=https%3A%2F%2Fgithub.com%2Fstephen-hill%2Fbase58php) + +## Long Term Support + +Each major version of this library will be supported for 5 years after it's initial release. Support will be provided for security and bug fixes. + +Version 1 will therefore be supported until the 11th September 2019. + +## Background + +I wanted a replacement for Base64 encoded strings and the [Base58 encoding used by Bitcoin](https://en.bitcoin.it/wiki/Base58Check_encoding) looked ideal. I looked around for an existing PHP library which would directly convert a string into Base58 but I couldn't find one, or at least one that worked correctly and was also well tested. + +So I decided to create a library with the following goals: + +- Encode/Decode PHP Strings +- Simple and easy to use +- Fully Tested +- Available via Composer + +## Requirements + +This library has the following requirements: + +- PHP => 5.3 +- BC Math Extension + +## Installation + +I recommend you install this library via Composer. + +```json +{ + "require": { + "stephenhill/base58": "~1.0" + } +} +``` + +## Basic Usage + +```php +require_once('vendor/autoload.php'); + +$base58 = new StephenHill\Base58(); + +$base58->encode('Hello World'); +$base58->decode('JxF12TrwUP45BMd'); +``` + +## Advanced Usage + +By default this library chooses the encoding service provider to use, either GMPService or BCMathService (in that order). +If you want to specify one of the included services or your own, you can inject it into the constructor. + +```php +require_once('vendor/autoload.php'); + +$gmp = new StephenHill\GMPService(); +$base58 = new StephenHill\Base58(null, $gmp); + +$base58->encode('Hello World'); +$base58->decode('JxF12TrwUP45BMd'); +``` + +Also by default, this library uses Bitcoin's Base58 alphabet. If you want to use another variant, you can do this in the constructor. + +```php +require_once('vendor/autoload.php'); + +// Flickr's Base58 Alphabet +$base58 = new StephenHill\Base58('123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'); + +$base58->encode('Hello World'); +$base58->decode('iXf12sRWto45bmC'); +``` + +## Testing + +This library is tested using PHPUnit. + +```bash +$ bin/phpunit +``` + +## Benchmarking + +You can benchmark this library using [Athletic](https://github.com/polyfractal/athletic). +The benchmarking suite also benchmarks PHP's built-in Base64 and Base16 encoding for comparison. + +```bash +$ bin/athletic -p benchmarks +``` + +Example output. + +``` +StephenHill\Benchmarks\Base16Event + Method Name Iterations Average Time Ops/second + ------------ ------------ -------------- ------------- + encodeBase16: [10,000 ] [0.0000010839939] [922,514.40637] + decodeBase16: [10,000 ] [0.0000011516809] [868,296.03561] + + +StephenHill\Benchmarks\Base58BCMathEvent + Method Name Iterations Average Time Ops/second + ------------ ------------ -------------- ------------- + encodeBase58: [10,000 ] [0.0001500048161] [6,666.45263] + decodeBase58: [10,000 ] [0.0001741812706] [5,741.14540] + + +StephenHill\Benchmarks\Base58GMPEvent + Method Name Iterations Average Time Ops/second + ------------ ------------ -------------- ------------- + encodeBase58: [10,000 ] [0.0001168665648] [8,556.76730] + decodeBase58: [10,000 ] [0.0001385705233] [7,216.54199] + + +StephenHill\Benchmarks\Base64Event + Method Name Iterations Average Time Ops/second + ------------ ------------ -------------- ------------- + encodeBase64: [10,000 ] [0.0000009050369] [1,104,927.29189] + decodeBase64: [10,000 ] [0.0000009787321] [1,021,730.04312] +``` + +## Contributing + +I welcome everyone to contribute to this library. Please see the Contributing document for details. + +## License + +This library is license under the MIT License (MIT). Please see License File for more information. + +## Credits + +This library was forked from [Jeremy Johnstone's](https://github.com/jsjohnst) Base58 methods on Gist https://gist.github.com/jsjohnst/126883. + +Some of the unit tests were based on the following: + +- https://code.google.com/p/bitcoinj/source/browse/core/src/test/java/com/google/bitcoin/core/Base58Test.java +- https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/fixtures/base58.json diff --git a/vendor/stephenhill/base58/docs/navbar.md b/vendor/stephenhill/base58/docs/navbar.md new file mode 100644 index 000000000..e11873d09 --- /dev/null +++ b/vendor/stephenhill/base58/docs/navbar.md @@ -0,0 +1,5 @@ +# Menu + +* [Home][home] + +[home]: /index.md diff --git a/vendor/stephenhill/base58/license b/vendor/stephenhill/base58/license new file mode 100644 index 000000000..be1ccaa5c --- /dev/null +++ b/vendor/stephenhill/base58/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Stephen Hill <stephen@gatekiller.co.uk> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE.
\ No newline at end of file diff --git a/vendor/stephenhill/base58/phpunit.xml b/vendor/stephenhill/base58/phpunit.xml new file mode 100644 index 000000000..06362417f --- /dev/null +++ b/vendor/stephenhill/base58/phpunit.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<phpunit + backupGlobals="false" + backupStaticAttributes="false" + bootstrap="tests/bootstrap.php" + colors="true" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" + processIsolation="true" + stopOnFailure="false" + syntaxCheck="true" + beStrictAboutTestsThatDoNotTestAnything="true" + beStrictAboutOutputDuringTests="true" + verbose="true" +> + <testsuites> + <testsuite name="Base58 Test Suite"> + <directory>./tests/</directory> + </testsuite> + </testsuites> + + <filter> + <whitelist addUncoveredFilesFromWhitelist="false"> + <directory suffix=".php">src</directory> + <exclude> + <directory suffix=".php">vendor</directory> + </exclude> + </whitelist> + </filter> +</phpunit> diff --git a/vendor/stephenhill/base58/readme.md b/vendor/stephenhill/base58/readme.md new file mode 100644 index 000000000..9723a91dd --- /dev/null +++ b/vendor/stephenhill/base58/readme.md @@ -0,0 +1,145 @@ +# Base58 Encoding and Decoding Library for PHP + +[![Build Status](https://travis-ci.org/stephen-hill/base58php.png)](https://travis-ci.org/stephen-hill/base58php) +[![Packagist Release](http://img.shields.io/packagist/v/stephenhill/base58.svg)](https://packagist.org/packages/stephenhill/base58) +[![MIT License](http://img.shields.io/packagist/l/stephenhill/base58.svg)](https://github.com/stephen-hill/base58php/blob/master/license) +[![Flattr this](https://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=stephen-hill&url=https%3A%2F%2Fgithub.com%2Fstephen-hill%2Fbase58php) + +## Long Term Support + +Each major version of this library will be supported for 5 years after it's initial release. Support will be provided for security and bug fixes. + +Version 1 will therefore be supported until the 11th September 2019. + +## Background + +I wanted a replacement for Base64 encoded strings and the [Base58 encoding used by Bitcoin](https://en.bitcoin.it/wiki/Base58Check_encoding) looked ideal. I looked around for an existing PHP library which would directly convert a string into Base58 but I couldn't find one, or at least one that worked correctly and was also well tested. + +So I decided to create a library with the following goals: + +- Encode/Decode PHP Strings +- Simple and easy to use +- Fully Tested +- Available via Composer + +## Requirements + +This library has the following requirements: + +- PHP => 5.3 +- BC Math Extension + +## Installation + +I recommend you install this library via Composer. + +```json +{ + "require": { + "stephenhill/base58": "~1.0" + } +} +``` + +## Basic Usage + +```php +require_once('vendor/autoload.php'); + +$base58 = new StephenHill\Base58(); + +$base58->encode('Hello World'); +$base58->decode('JxF12TrwUP45BMd'); +``` + +## Advanced Usage + +By default this library chooses the encoding service provider to use, either GMPService or BCMathService (in that order). +If you want to specify one of the included services or your own, you can inject it into the constructor. + +```php +require_once('vendor/autoload.php'); + +$gmp = new StephenHill\GMPService(); +$base58 = new StephenHill\Base58(null, $gmp); + +$base58->encode('Hello World'); +$base58->decode('JxF12TrwUP45BMd'); +``` + +Also by default, this library uses Bitcoin's Base58 alphabet. If you want to use another variant, you can do this in the constructor. + +```php +require_once('vendor/autoload.php'); + +// Flickr's Base58 Alphabet +$base58 = new StephenHill\Base58('123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'); + +$base58->encode('Hello World'); +$base58->decode('iXf12sRWto45bmC'); +``` + +## Testing + +This library is tested using PHPUnit. + +```bash +$ bin/phpunit +``` + +## Benchmarking + +You can benchmark this library using [Athletic](https://github.com/polyfractal/athletic). +The benchmarking suite also benchmarks PHP's built-in Base64 and Base16 encoding for comparison. + +```bash +$ bin/athletic -p benchmarks +``` + +Example output. + +``` +StephenHill\Benchmarks\Base16Event + Method Name Iterations Average Time Ops/second + ------------ ------------ -------------- ------------- + encodeBase16: [10,000 ] [0.0000010839939] [922,514.40637] + decodeBase16: [10,000 ] [0.0000011516809] [868,296.03561] + + +StephenHill\Benchmarks\Base58BCMathEvent + Method Name Iterations Average Time Ops/second + ------------ ------------ -------------- ------------- + encodeBase58: [10,000 ] [0.0001500048161] [6,666.45263] + decodeBase58: [10,000 ] [0.0001741812706] [5,741.14540] + + +StephenHill\Benchmarks\Base58GMPEvent + Method Name Iterations Average Time Ops/second + ------------ ------------ -------------- ------------- + encodeBase58: [10,000 ] [0.0001168665648] [8,556.76730] + decodeBase58: [10,000 ] [0.0001385705233] [7,216.54199] + + +StephenHill\Benchmarks\Base64Event + Method Name Iterations Average Time Ops/second + ------------ ------------ -------------- ------------- + encodeBase64: [10,000 ] [0.0000009050369] [1,104,927.29189] + decodeBase64: [10,000 ] [0.0000009787321] [1,021,730.04312] +``` + +## Contributing + +I welcome everyone to contribute to this library. Please see the Contributing document for details. + +## License + +This library is license under the MIT License (MIT). Please see License File for more information. + +## Credits + +This library was forked from [Jeremy Johnstone's](https://github.com/jsjohnst) Base58 methods on Gist https://gist.github.com/jsjohnst/126883. + +Some of the unit tests were based on the following: + +- https://code.google.com/p/bitcoinj/source/browse/core/src/test/java/com/google/bitcoin/core/Base58Test.java +- https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/fixtures/base58.json diff --git a/vendor/stephenhill/base58/src/BCMathService.php b/vendor/stephenhill/base58/src/BCMathService.php new file mode 100644 index 000000000..329e1ceba --- /dev/null +++ b/vendor/stephenhill/base58/src/BCMathService.php @@ -0,0 +1,165 @@ +<?php + +namespace StephenHill; + +use InvalidArgumentException; + +class BCMathService implements ServiceInterface +{ + /** + * @var string + * @since v1.1.0 + */ + protected $alphabet; + + /** + * @var int + * @since v1.1.0 + */ + protected $base; + + /** + * Constructor + * + * @param string $alphabet optional + * @since v1.1.0 + */ + public function __construct($alphabet = 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.'); + } + + $this->alphabet = $alphabet; + $this->base = strlen($alphabet); + } + /** + * Encode a string into base58. + * + * @param string $string The string you wish to encode. + * @since Release v1.1.0 + * @return string The Base58 encoded string. + */ + public function encode($string) + { + // Type validation + if (is_string($string) === false) { + throw new InvalidArgumentException('Argument $string must be a string.'); + } + + // If the string is empty, then the encoded string is obviously empty + if (strlen($string) === 0) { + return ''; + } + + // Strings in PHP are essentially 8-bit byte arrays + // so lets convert the string into a PHP array + $bytes = array_values(unpack('C*', $string)); + + // Now we need to convert the byte array into an arbitrary-precision decimal + // We basically do this by performing a base256 to base10 conversion + $decimal = $bytes[0]; + + for ($i = 1, $l = count($bytes); $i < $l; $i++) { + $decimal = bcmul($decimal, 256); + $decimal = bcadd($decimal, $bytes[$i]); + } + + // This loop now performs base 10 to base 58 conversion + // The remainder or modulo on each loop becomes a base 58 character + $output = ''; + while ($decimal >= $this->base) { + $div = bcdiv($decimal, $this->base, 0); + $mod = (int) bcmod($decimal, $this->base); + $output .= $this->alphabet[$mod]; + $decimal = $div; + } + + // If there's still a remainder, append it + if ($decimal > 0) { + $output .= $this->alphabet[$decimal]; + } + + // Now we need to reverse the encoded data + $output = strrev($output); + + // Now we need to add leading zeros + foreach ($bytes as $byte) { + if ($byte === 0) { + $output = $this->alphabet[0] . $output; + continue; + } + break; + } + + return (string) $output; + } + + /** + * Decode base58 into a PHP string. + * + * @param string $base58 The base58 encoded string. + * @since Release v1.1.0 + * @return string Returns the decoded string. + */ + public function decode($base58) + { + // Type Validation + if (is_string($base58) === false) { + throw new InvalidArgumentException('Argument $base58 must be a string.'); + } + + // If the string is empty, then the decoded string is obviously empty + if (strlen($base58) === 0) { + return ''; + } + + $indexes = array_flip(str_split($this->alphabet)); + $chars = str_split($base58); + + // Check for invalid characters in the supplied base58 string + foreach ($chars as $char) { + if (isset($indexes[$char]) === false) { + throw new InvalidArgumentException('Argument $base58 contains invalid characters. ($char: "'.$char.'" | $base58: "'.$base58.'") '); + } + } + + // Convert from base58 to base10 + $decimal = $indexes[$chars[0]]; + + for ($i = 1, $l = count($chars); $i < $l; $i++) { + $decimal = bcmul($decimal, $this->base); + $decimal = bcadd($decimal, $indexes[$chars[$i]]); + } + + // Convert from base10 to base256 (8-bit byte array) + $output = ''; + while ($decimal > 0) { + $byte = (int) bcmod($decimal, 256); + $output = pack('C', $byte) . $output; + $decimal = bcdiv($decimal, 256, 0); + } + + // Now we need to add leading zeros + foreach ($chars as $char) { + if ($indexes[$char] === 0) { + $output = "\x00" . $output; + continue; + } + break; + } + + return $output; + } +} 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 @@ +<?php + +namespace StephenHill; + +use InvalidArgumentException; + +/** + * @package StephenHill\Base58 + * @author Stephen Hill <stephen@gatekiller.co.uk> + * @copyright 2014 Stephen Hill <stephen@gatekiller.co.uk> + * @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); + } +} diff --git a/vendor/stephenhill/base58/src/GMPService.php b/vendor/stephenhill/base58/src/GMPService.php new file mode 100644 index 000000000..0dde30594 --- /dev/null +++ b/vendor/stephenhill/base58/src/GMPService.php @@ -0,0 +1,156 @@ +<?php + +namespace StephenHill; + +use InvalidArgumentException; + +class GMPService implements ServiceInterface +{ + /** + * @var string + * @since v1.1.0 + */ + protected $alphabet; + + /** + * @var int + * @since v1.1.0 + */ + protected $base; + + /** + * Constructor + * + * @param string $alphabet optional + * @since v1.1.0 + */ + public function __construct($alphabet = 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.'); + } + + $this->alphabet = $alphabet; + $this->base = strlen($alphabet); + } + /** + * Encode a string into base58. + * + * @param string $string The string you wish to encode. + * @since Release v1.1.0 + * @return string The Base58 encoded string. + */ + public function encode($string) + { + // Type validation + if (is_string($string) === false) { + throw new InvalidArgumentException('Argument $string must be a string.'); + } + + // If the string is empty, then the encoded string is obviously empty + if (strlen($string) === 0) { + return ''; + } + + // Now we need to convert the byte array into an arbitrary-precision decimal + // We basically do this by performing a base256 to base10 conversion + $hex = unpack('H*', $string); + $hex = reset($hex); + $decimal = gmp_init($hex, 16); + + // This loop now performs base 10 to base 58 conversion + // The remainder or modulo on each loop becomes a base 58 character + $output = ''; + while (gmp_cmp($decimal, $this->base) >= 0) { + list($decimal, $mod) = gmp_div_qr($decimal, $this->base); + $output .= $this->alphabet[gmp_intval($mod)]; + } + + // If there's still a remainder, append it + if (gmp_cmp($decimal, 0) > 0) { + $output .= $this->alphabet[gmp_intval($decimal)]; + } + + // Now we need to reverse the encoded data + $output = strrev($output); + + // Now we need to add leading zeros + $bytes = str_split($string); + foreach ($bytes as $byte) { + if ($byte === "\x00") { + $output = $this->alphabet[0] . $output; + continue; + } + break; + } + + return (string) $output; + } + + /** + * Decode base58 into a PHP string. + * + * @param string $base58 The base58 encoded string. + * @since Release v1.1.0 + * @return string Returns the decoded string. + */ + public function decode($base58) + { + // Type Validation + if (is_string($base58) === false) { + throw new InvalidArgumentException('Argument $base58 must be a string.'); + } + + // If the string is empty, then the decoded string is obviously empty + if (strlen($base58) === 0) { + return ''; + } + + $indexes = array_flip(str_split($this->alphabet)); + $chars = str_split($base58); + + // Check for invalid characters in the supplied base58 string + foreach ($chars as $char) { + if (isset($indexes[$char]) === false) { + throw new InvalidArgumentException('Argument $base58 contains invalid characters.'); + } + } + + // Convert from base58 to base10 + $decimal = gmp_init($indexes[$chars[0]], 10); + + for ($i = 1, $l = count($chars); $i < $l; $i++) { + $decimal = gmp_mul($decimal, $this->base); + $decimal = gmp_add($decimal, $indexes[$chars[$i]]); + } + + // Convert from base10 to base256 (8-bit byte array) + $output = ''; + while (gmp_cmp($decimal, 0) > 0) { + list($decimal, $byte) = gmp_div_qr($decimal, 256); + $output = pack('C', gmp_intval($byte)) . $output; + } + + // Now we need to add leading zeros + foreach ($chars as $char) { + if ($indexes[$char] === 0) { + $output = "\x00" . $output; + continue; + } + break; + } + + return $output; + } +} diff --git a/vendor/stephenhill/base58/src/ServiceInterface.php b/vendor/stephenhill/base58/src/ServiceInterface.php new file mode 100644 index 000000000..0fe374524 --- /dev/null +++ b/vendor/stephenhill/base58/src/ServiceInterface.php @@ -0,0 +1,24 @@ +<?php + +namespace StephenHill; + +interface ServiceInterface +{ + /** + * Encode a string into base58. + * + * @param string $string The string you wish to encode. + * @since v1.1.0 + * @return string The Base58 encoded string. + */ + public function encode($string); + + /** + * Decode base58 into a PHP string. + * + * @param string $base58 The base58 encoded string. + * @since v1.1.0 + * @return string Returns the decoded string. + */ + public function decode($base58); +} |