Last active
July 18, 2018 01:02
-
-
Save rfunduk/85dce8e0ab856ecb9c96f32b4aeb590b to your computer and use it in GitHub Desktop.
Using bitcoin-ruby to convert from Cosmos Amino encoded public key values to bech32.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Prerequisites: | |
# gem install bitcoin-ruby | |
require 'bitcoin' | |
def amino_to_bech32( base64_pubkey_value ) | |
bytes = [ | |
*["1624DE6420"].pack('H*').bytes, | |
*Base64.decode64( base64_pubkey_value ).bytes | |
] | |
Bitcoin::Bech32.encode( | |
'cosmosvalpub', | |
Bitcoin::Bech32.convert_bits( | |
bytes, | |
from_bits: 8, to_bits: 5, pad: true | |
) | |
) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment