bitcoin-rubyでsegwitアドレスのエンコードとデコード/ bech32


環境

bitcoin-ruby v0.0.18
ruby v2.5

こんな感じ

bech32.rb
require 'bitcoin'
include Bitcoin
include Util

Bitcoin.network = :regtest
p Util.encode_segwit_address(0, '67c6df70223a3cfbf241e7551057001707d72af9')
# => "bcrt1qvlrd7upz8g70hujpua23q4cqzuraw2he97gtyc"
# encode_segwit_address('segwitのversion', 'pubkey-hash-20byte')
# pubkey-hash-20byte => ripemd160(sha256(pubkey))

p Util.decode_segwit_address('bcrt1qvlrd7upz8g70hujpua23q4cqzuraw2he97gtyc')
# =>[0, "67c6df70223a3cfbf241e7551057001707d72af9"]

もっとくわしく!

bitcoin-ruby
BIP173/ Bech32
Segwitのアドレスフォーマットを定義したBIP-173