= HDetEcKey
HDetEcKey is a Ruby implement of https://en.bitcoin.it/wiki/Deterministic_Wallet[Hierachical Deterministic wallets] according to the specification https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki[BIP0032].
== What is use for ?
== How to get it !
[source, bash]
Or in a neer future:
[source, bash]
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 https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki[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:
[source, ruby]
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:
[source, ruby]
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:
[source, ruby]
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:
[source, ruby]
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:
[source,ruby]
pub.serialize # xpub.....
master_key.serialize # xprv.....