2017 © Pedro Peláez
 

library base58

Base58 Encoding and Decoding Library for PHP

image

stephenhill/base58

Base58 Encoding and Decoding Library for PHP

  • Thursday, December 15, 2016
  • by stephen-hill
  • Repository
  • 4 Watchers
  • 38 Stars
  • 81,851 Installations
  • PHP
  • 20 Dependents
  • 0 Suggesters
  • 10 Forks
  • 3 Open issues
  • 14 Versions
  • 19 % Grown

The README.md

Base58 Encoding and Decoding Library for PHP

Build Status Packagist Release MIT License Flattr this, (*1)

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., (*2)

Version 1 will therefore be supported until the 11th September 2019., (*3)

Background

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., (*4)

So I decided to create a library with the following goals:, (*5)

  • Encode/Decode PHP Strings
  • Simple and easy to use
  • Fully Tested
  • Available via Composer

Requirements

This library has the following requirements:, (*6)

  • PHP => 5.3
  • BC Math Extension

Installation

I recommend you install this library via Composer., (*7)

{
    "require": {
        "stephenhill/base58": "~1.0"
    }
}

Basic Usage

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., (*8)

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., (*9)

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., (*10)

$ bin/phpunit

Benchmarking

You can benchmark this library using Athletic. The benchmarking suite also benchmarks PHP's built-in Base64 and Base16 encoding for comparison., (*11)

$ bin/athletic -p benchmarks

Example output., (*12)

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., (*13)

License

This library is license under the MIT License (MIT). Please see License File for more information., (*14)

Credits

This library was forked from Jeremy Johnstone's Base58 methods on Gist https://gist.github.com/jsjohnst/126883., (*15)

Some of the unit tests were based on the following:, (*16)

  • 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

The Versions

15/12 2016

dev-master

9999999-dev

Base58 Encoding and Decoding Library for PHP

  Sources   Download

MIT

The Development Requires

by Stephen Hill

20/07 2016

v1.1.4

1.1.4.0

Base58 Encoding and Decoding Library for PHP

  Sources   Download

MIT

The Development Requires

by Stephen Hill

19/07 2016

dev-travis-7.1

dev-travis-7.1

Base58 Encoding and Decoding Library for PHP

  Sources   Download

MIT

The Development Requires

by Stephen Hill

28/03 2016

dev-static

dev-static

Base58 Encoding and Decoding Library for PHP

  Sources   Download

MIT

The Development Requires

by Stephen Hill

08/10 2015

dev-setAlphabet

dev-setAlphabet

Base58 Encoding and Decoding Library for PHP

  Sources   Download

MIT

The Development Requires

by Stephen Hill

16/07 2015

dev-ImprovedInvalidBase58Exception

dev-ImprovedInvalidBase58Exception

Base58 Encoding and Decoding Library for PHP

  Sources   Download

MIT

The Development Requires

by Stephen Hill

08/07 2015

v1.1.3

1.1.3.0

Base58 Encoding and Decoding Library for PHP

  Sources   Download

MIT

The Development Requires

by Stephen Hill

09/03 2015

dev-WhatIsBase58

dev-WhatIsBase58

Base58 Encoding and Decoding Library for PHP

  Sources   Download

MIT

The Development Requires

by Stephen Hill

11/09 2014

v1.1.2

1.1.2.0

Base58 Encoding and Decoding Library for PHP

  Sources   Download

MIT

The Development Requires

by Stephen Hill

11/09 2014

v1.1.1

1.1.1.0

Base58 Encoding and Decoding Library for PHP

  Sources   Download

MIT

The Development Requires

by Stephen Hill

08/09 2014

v1.1.0

1.1.0.0

Base58 Encoding and Decoding Library for PHP

  Sources   Download

MIT

The Development Requires

by Stephen Hill

01/09 2014

v1.0.2

1.0.2.0

Base58 Encoding and Decoding Library for PHP

  Sources   Download

MIT

The Development Requires

by Stephen Hill

31/08 2014

v1.0.1

1.0.1.0

Base58 Encoding and Decoding Library for PHP

  Sources   Download

MIT

The Development Requires

by Stephen Hill

30/08 2014

v1.0.0

1.0.0.0

Base58 Encoding and Decoding Library for PHP

  Sources   Download

MIT

The Development Requires

by Stephen Hill