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 2 will be supported until the 1st Janurary 2031.
- Version 1 support expired on the 11th September 2019.
I wanted a replacement for Base64 encoded strings and the Base58 encoding used by Bitcoin 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
This library has the following requirements:
- PHP => 8.1
- GMP or BC Math Extension
I recommend you install this library via Composer.
{
"require": {
"stephenhill/base58": "~2.0"
}
}require_once('vendor/autoload.php');
$base58 = new StephenHill\Base58();
$base58->encode('Hello World');
$base58->decode('JxF12TrwUP45BMd');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.
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.
require_once('vendor/autoload.php');
// Flickr's Base58 Alphabet
$base58 = new StephenHill\Base58('123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ');
$base58->encode('Hello World');
$base58->decode('iXf12sRWto45bmC');This library is tested using PHPUnit.
$ bin/phpunitI welcome everyone to contribute to this library. Please see the Contributing document for details.
This library is license under the MIT License (MIT). Please see License File for more information.
This library was forked from Jeremy Johnstone's 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
In no particular order, I would like to thank the following for pushing me to release a PHP 8 compatible version: @git-marijus, @VandalorumRex, @bacheson, @kalifg