Skip to content

Instantly share code, notes, and snippets.

@mattm
Created November 19, 2021 18:18
Show Gist options
  • Save mattm/cbc93312213e291c541a610d89920524 to your computer and use it in GitHub Desktop.
Save mattm/cbc93312213e291c541a610d89920524 to your computer and use it in GitHub Desktop.
require_relative "base58"
def bytes_to_base58(bytes)
hex = bytes.pack("C*").unpack("H*").first
Base58.encode(hex)
end
keypair = "6Tyktf6mEqUMEKm2ZpLn3srEwk9zsT5jiE54EgPgToikMFYww1LGFUXgwgr6hvc9CikpaNaBH2vmkmqN3Usrxpd"
keypair_hex = Base58.decode(keypair).rjust(128, "0")
keypair_bytes = [keypair_hex].pack('H*').bytes.to_a
private_key_bytes = keypair_bytes[0, 32]
public_key_bytes = keypair_bytes[32..-1]
puts "Public Key:", bytes_to_base58(public_key_bytes)
puts "\nPrivate Key:", bytes_to_base58(private_key_bytes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment