Skip to content

Instantly share code, notes, and snippets.

@rfunduk
Last active July 18, 2018 01:02
Show Gist options
  • Save rfunduk/85dce8e0ab856ecb9c96f32b4aeb590b to your computer and use it in GitHub Desktop.
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.
# 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