2017 © Pedro Peláez
 

library bip39

Easy to use, multi-language BIP39 implementation for PHP.

image

blocker/bip39

Easy to use, multi-language BIP39 implementation for PHP.

  • Thursday, April 26, 2018
  • by hernandev
  • Repository
  • 2 Watchers
  • 1 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 1800 % Grown

The README.md

PHP BIP39

Latest Stable Version License, (*1)

An easy to use, multilingual, stand alone, and blockchain independent implementation of the **BIP39 proposal for PHP., (*2)

This library allows encoding and decoding data, on the 128-256 bit range into Mnemonic word lists., (*3)

Have you ever used a local Bitcoin wallet? remember those 12 words you type to backup your private key? This library allows that functionality on PHP., (*4)

1. Background.

This library was built with both, production usage readiness and conceptual learning in mind., (*5)

It means all code is over commented with detailed information about each single aspect of encoding and decoding BIP39 word sequences., (*6)

2. Install:

Standard composer installation:, (*7)

composer require blocker/bip39

3. Concepts:

While implementing this library in your projects, you will need to understand some key factors:, (*8)

3.1. Entropy:

On this library implementation, we call entropy a given set of data, which bits are within the 128 bit to 256 bit., (*9)

This means, for example, that you may generate a 256 bit private key for ECDSA, and allow your users to encode this random, hard to remember key into a set of words., (*10)

Ways for obtaining entropy:, (*11)

If you already have a value you want to encode:, (*12)

<?php

// aliases.
use Blocker\Bip39\Util\Entropy;

$entropy = new Entropy($dataInHexadecimal);

or, if you want to generate some data to then create a private key, one could:, (*13)

<?php

// aliases.
use Blocker\Bip39\Util\Entropy;

// the parameter here is the size, in bits, of the random data to be generated.
// values can be between 128 and 256, and must be multiples of 32.
$entropy = Entropy::random(128);

3.2. Encoding and Decoding.

Just as simple as using the entropy, parsing from entropy into a word sequence and vice versa is really easy:, (*14)


// aliases. use Blocker\Bip39\Bip39; use Blocker\Bip39\Util\Entropy; // a word sequence provided by the user. $some128bitValueAlreadyEncoded = 'walnut antenna forward shuffle invest legal confirm polar hope timber pear cover'; // create a bip39 instance. $bip39 = new Bip39('en'); // decode the given word list into an entropy instance. $entropy = $bip39->decode($some128bitValueAlreadyEncoded); // decode the provided word sequence into a hexadecimal encoded entropy. echo (string) $entropy; // "f6c1396f63b75efecbbd3b6d7c468818"

And, just as easy as encoding:, (*15)


// aliases. use Blocker\Bip39\Bip39; use Blocker\Bip39\Util\Entropy; // some entropy value to be encoded with BIP39. $previousGeneratedEntropyHex = 'f6c1396f63b75efecbbd3b6d7c468818'; //$some128bitValueAlreadyEncoded = 'walnut antenna forward shuffle invest legal confirm polar hope timber pear cover'; // create a bip39 instance. $bip39 = new Bip39('en'); // create an entropy instance from it's hex representation. $entropy = new Entropy($previousGeneratedEntropyHex); echo (string) $bip39->setEntropy($entropy)->encode(); // 'walnut antenna forward shuffle invest legal confirm polar hope timber pear cover'

Easy right?, (*16)

3.3. Supported Languages:

  • [en] English
  • [es] Spanish
  • [fr] French
  • [it] Italian
  • [ja] Japanese
  • [ko] Korean
  • [zh] Chinese (Simplified).

Just use the language locale on the Bip39 constructor:, (*17)

$bip39 = new Bip39('en');
$bip39 = new Bip39('es');
$bip39 = new Bip39('fr');
// ...

3.4. Special Features.

As mentioned earlier, this library was built with education also in mind, so, there's a buffered binary operations class, classed BitBuffer and some utils that will help you understand a lot of different concepts., (*18)

Good Leaning!, (*19)

The Versions

26/04 2018

dev-master

9999999-dev

Easy to use, multi-language BIP39 implementation for PHP.

  Sources   Download

MIT

The Requires

 

by Diego Hernandes

26/04 2018

dev-develop

dev-develop

Easy to use, multi-language BIP39 implementation for PHP.

  Sources   Download

MIT

The Requires

 

by Diego Hernandes

21/03 2018

0.9.0

0.9.0.0

Easy to use, multi-language BIP39 implementation for PHP.

  Sources   Download

MIT

The Requires

 

by Diego Hernandes