LoginSignup
1
0

More than 5 years have passed since last update.

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

Posted at

環境

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

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0