アドレス生成の流れその2(bitcoin-ruby)
bitcoin-rubyを用いて秘密鍵からアドレス生成とredeem_scriptができるまでを理解する。
https://gyazo.com/c96010a6966e972d061b812dfbda1b65
まずは鍵を生成する
code:鍵生成
~ $bcli getnewaddress
2Muoa8kkkqYVwyfRuBfqAm8bKZf8q99KNRw
~ $bcli-dpk 2Muoa8kkkqYVwyfRuBfqAm8bKZf8q99KNRw
cUkowamtNZRsAxnLiE3hXGoRPdByXbH2XhB1WqHXc9TrzfuQqagy
code:address
key = Bitcoin::Key.from_base58("cUkowamtNZRsAxnLiE3hXGoRPdByXbH2XhB1WqHXc9TrzfuQqagy")
> key.priv
=> "d60fdd87d27cf50a8314217920402d082fce9433522e696c6162e499eefa2e02"
> key.pub
=> "022310a2585ee319408b002ab512ae83d3c87c7661e3f1fd59ee9f5debdb9fa6fb"
> Bitcoin.hash160("022310a2585ee319408b002ab512ae83d3c87c7661e3f1fd59ee9f5debdb9fa6fb")
=> "92d167a420eb807a6bea020532f550f99749112e"
> Bitcoin.encode_address("92d167a420eb807a6bea020532f550f99749112e", "6f")
=> "mtuFomLLXN2MwKpNDkTsWtVXg2KDYJ7AwE"
> Bitcoin.address_type("mtuFomLLXN2MwKpNDkTsWtVXg2KDYJ7AwE")
=> :hash160
> Bitcoin.pubkey_to_address("022310a2585ee319408b002ab512ae83d3c87c7661e3f1fd59ee9f5debdb9fa6fb")
=> "mtuFomLLXN2MwKpNDkTsWtVXg2KDYJ7AwE"
> Bitcoin.hash160("022310a2585ee319408b002ab512ae83d3c87c7661e3f1fd59ee9f5debdb9fa6fb")
=> "92d167a420eb807a6bea020532f550f99749112e"
> redeem_script = "0014" + "92d167a420eb807a6bea020532f550f99749112e"
=> "001492d167a420eb807a6bea020532f550f99749112e"
> Bitcoin.hash160(redeem_script)
=> "1c0e61220788ead488be2a57651f36a6e7033375"
> Bitcoin.encode_address("1c0e61220788ead488be2a57651f36a6e7033375", "c4")
=> "2Muoa8kkkqYVwyfRuBfqAm8bKZf8q99KNRw"