Bitcoin Forum
May 09, 2024, 09:52:45 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: MoneyTree - a Ruby gem for creating HD Bitcoin Wallets  (Read 2667 times)
Wink (OP)
Newbie
*
Offline Offline

Activity: 15
Merit: 0


View Profile
September 17, 2013, 07:02:03 PM
 #1

Money Tree

I've just released an open-source Ruby gem for creating Hierarchical Deterministic Bitcoin Wallets. This gem will allow you to generate or import a random seed and create an entire tree of Bitcoin keypairs derived from that seed. So you don't need to backup all of your keypairs, you just need to backup the seed.

This gem follows the spec at https://en.bitcoin.it/wiki/BIP_0032 and passes all test vectors provided there.

Let me know what you think!

You can check out the repo at https://github.com/wink/money-tree

Why would I want an HD Wallet?
Hierarchical Deterministic (HD) Bitcoin Wallets offer several advantages over traditional Bitcoin wallets.

One of the problems with traditional Bitcoin wallets is that the wallet may hold a whole bunch of keypairs, each with Bitcoins attached to them. When you want to back up your wallet, you backup all of the current keys that you control in that wallet. However, if you later generate a new key, you need to make a brand new back up of your wallet. In fact, you need to back up your wallet every time you generate a new key.

Easy backups

HD wallets allow you to create a huge number of Bitcoin keys (keypairs) that all derive from a parent master key. This means that if you control the master key, you can generate the entire tree of children keys. So instead of needing to make repeated backups of your wallet, you can create a single backup when you create the wallet, and from then on to the end of time, you will never need to make a new backup, because you can just recreate ALL of the child keys from your master key.

Safely store your private keys offline

Additionally, HD wallets introduce cool new features to wallets, like being able to derive the entire tree of public keys from a parent public key without needing ANY private keys. For instance, let's say you have your master private key backed up on a paper wallet and stored offline in a safe somewhere, but you have the master public key available. Using just this public key, you can generate an entire tree of receive-only child public keys.

For instance, let's say you wanted to open a Bitcoin ecommerce website. With HD wallets, you can keep your master private key offline, and only put your public key onto the public webserver. Your website can then use that key to generate a receiving address for each and every product on your site, a unique address for each one of your customers, or even a key unique to each customer/product combo. (The uses are left up to your imagination.) And since the private key is stored offline, nobody will ever be able to hack your site and steal your Bitcoins.

Access controls

One bonus feature of HD Wallets is that they give you a lot of control over who in your organization has access to which keys. Like an organizational chart for a business, HD wallets are arranged in a tree formation. You could create whole branches of keypairs for each department in your organization, and by giving each department only the private key at the top of their department branch, each department will only be able to spend the coins on their branch. However, since you hold the master key, you can watch and spend ALL coins in the entire tree.

Accounting

Want to give your accountant access to view all transactions, but you don't want to give her access to spend any of your coins? No problem. You can simply give her the public key at any level in the tree that you desire, and she will be able to view transactions below that key in the tree, but won't be able to spend any of the coins.
1715248365
Hero Member
*
Offline Offline

Posts: 1715248365

View Profile Personal Message (Offline)

Ignore
1715248365
Reply with quote  #2

1715248365
Report to moderator
1715248365
Hero Member
*
Offline Offline

Posts: 1715248365

View Profile Personal Message (Offline)

Ignore
1715248365
Reply with quote  #2

1715248365
Report to moderator
1715248365
Hero Member
*
Offline Offline

Posts: 1715248365

View Profile Personal Message (Offline)

Ignore
1715248365
Reply with quote  #2

1715248365
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
Peter Todd
Legendary
*
expert
Offline Offline

Activity: 1120
Merit: 1150


View Profile
September 17, 2013, 07:34:26 PM
 #2

Not a ruby programmer myself, but just wanted to say thank you!

Wink (OP)
Newbie
*
Offline Offline

Activity: 15
Merit: 0


View Profile
September 17, 2013, 07:42:02 PM
 #3

Not a ruby programmer myself, but just wanted to say thank you!
I appreciate that! There is an enormous community of developers/startups/infrastructure built around the Ruby ecosystem, and it would be great to migrate more of those developers over to the Bitcoin community.
jyaken
Hero Member
*****
Offline Offline

Activity: 810
Merit: 1000


Your professional profile on the blockchain


View Profile
September 27, 2013, 08:33:03 AM
 #4

I appreciate your work and i need your help!
I also developing a brain wallet with ruby in my spare time.
I'm stucked when trying to generate public key by using existing private key
rather then generate key pairs.

my code:
Code:
    require 'openssl'
    include OpenSSL

    pk = '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'
    key = PKey::EC.new('secp256k1')
    key.private_key = pk.to_i(16)
    p key.public_key = PKey::EC::Point.new(key.group).mul(key.private_key) ## HERE!!
    puts key.to_text


and i also tried:
Code:
    PKey::EC::Point.new(key.group).mul(nil,key.private_key)
    PKey::EC::Point.new(key.group).mul(BN.new('whatever'),key.private_key)


None of these one got right answer.

I have read openssl wiki but still confused.
http://wiki.openssl.org/index.php/Elliptic_Curve_Cryptography

It looks like there is no corresponding methods of mul in ruby?
Could you please tell me what should I do in order to solve my problem?
Wink (OP)
Newbie
*
Offline Offline

Activity: 15
Merit: 0


View Profile
January 03, 2014, 08:30:09 AM
 #5

Sorry for the late reply. OpenSSL will only work with Ruby 2.0.0 and greater. This is because the version of OpenSSL included with previous versions of Ruby did not include an OpenSSL::PKey::EC::Point#mul (point multiplication) method, which is required in order to calculate a Bitcoin public key from a private key.
Boofhead
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
March 09, 2014, 01:54:06 PM
 #6

Hi, if I could ask a question, I'm looking to pick up another computer language after PHP and I want that language to be one that will give me a lot of options for working with bitcoin.
Does Ruby have a future with bitcoin? Or is it more practical working with Pythons mathematics library?
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!