HDetEcKey is a Ruby implement of Hierachical Deterministic wallets according to the specification BIP0032.

What is use for ?

How to get it !

git clone https://gitlab.com/elionne/hdet-ec-key.git

Or in a neer future:

gem install hdet-ec-key

Prerequistes

  • Ruby 2.5.0

  • Openssl (ruby included)

Support of other version of Ruby should be possible.

Usage

For more details about how Herarchical Deterministic Wallet works, please see the BIP0032 specifications.

Generate master key

First you need to generate the first key. The point where all keys starts. The BIP32 standard specify simple method with HMAC512. The default key is Bitcoin seed and the seed is choosen by the user.

To generate a master key:

seed = ["000102030405060708090a0b0c0d0e0f"].pack("H*")
master_key = HDetEc::Key.generate_master_key(seed)

No convertion of the given string is operated, the seed is used as is. The key can be change by setting the second parameter:

master_key = HDetEc::Key.generate_master_key(seed, "my special key")

Public key, private and public derivation

To get the public key from the a key:

pub = master_key.public_key

# or a more verbose version
pub = master.public_key_from_private

Then you can derive, ether public or private key:

pub.derive([0, 1, 2000])
master_key.derive(0, 1.h, 2000)

The derivation path is determined by an array of index. the #h function for interger means harderned index, only available for private key derivation.

Serialization

Each keys can be serialized in BIP32 specified form:

pub.serialize # xpub.....
master_key.serialize # xprv.....