Ruby Quiz - Challenge #15 - Generate the Bitcoin (Base58) Address from the (Elliptic Curve) Public Key

Gerald Bauer <[email protected]> Fri, 19 Jul 2019 16:36:29 +0200
Newsgroups gmane.comp.lang.ruby.general
Message-ID <CAAxEZd_pFcxcK1F9pmR-B4rN0zdbyKsO8BrHP_0CJAapErEbCA@mail.gmail.com>
Hello,

  I've posted a new ruby quiz:

   Challenge #15 - Generate the Bitcoin (Base58) Address from the
(Elliptic Curve) Public Key [1].

   Start from scratch or, yes, use any library / gem you can find.

   To qualify for solving the code challenge / puzzle you must pass
the test [2]:

``` ruby
   require 'minitest/autorun'

   class RubyQuizTest < MiniTest::Test

     def test_addr
       pubkey =
'0250863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352'

       pkh = pk_to_pkh( pubkey )
       assert_equal 'f54a5851e9372b87810a8e60cdd2e7cfd80b6e31', pkh

       prefix = '00'    ## version prefix
       h = checksum( prefix + pkh )
       assert_equal
'c7f18fe8fcbed6396741e58ad259b5cb16b7fd7f041904147ba1dcffabf747fd', h
       assert_equal 'c7f18fe8', h[0..7]

       addr = base58( prefix + pkh + h[0..7] )
       assert_equal '1PMycacnJaSqwwJqjawXBErnLsZ7RkXUAs', addr
     end # method test_addr
   end # class RubyQuizTest
```

   Post your code snippets on the "official" Ruby Quiz Channel,
   that is, the ruby-talk mailing list right here.

   Happy hacking and crypto hashing with Ruby. Cheers. Prost.

[1] https://github.com/planetruby/quiz/tree/master/015
[2] https://github.com/planetruby/quiz/blob/master/015/test.rb

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>