Base58Check

object Base58Check

https://en.bitcoin.it/wiki/Base58Check_encoding Base58Check is a format based on Base58 and used a lot in bitcoin, for encoding addresses and private keys for example. It includes a prefix (usually a single byte) and a checksum so you know what has been encoded, and that it has been transmitted correctly. For example, to create an address for a public key you could write: {{{ val pub: BinaryData = "0202a406624211f2abbdc68da3df929f938c3399dd79fac1b51b0e4ad1d26a47aa" val address = Base58Check.encode(Base58.Prefix.PubkeyAddress, Crypto.hash160(pub)) }}} And to decode a private key you could write: {{{ // check that is it a mainnet private key val (Base58.Prefix.SecretKey, priv) = Base58Check.decode("5J3mBbAH58CpQ3Y5RNJpUKPE62SQ5tfcvU2JpbnkeyhfsYB1Jcn") }}}

Functions

Link copied to clipboard
fun checksum(data: ByteArray): ByteArray
Link copied to clipboard
fun decode(encoded: String): Pair<Byte, ByteArray>

Decodes Base58 data that has been encoded with a single byte prefix

Link copied to clipboard
fun decodeWithIntPrefix(encoded: String): Pair<Int, ByteArray>

Decodes Base58 data that has been encoded with an integer prefix

Link copied to clipboard
fun decodeWithPrefixLen(encoded: String, prefixLen: Int): Pair<ByteArray, ByteArray>

Decodes Base58 data that has been encoded with several bytes prefix

Link copied to clipboard
fun encode(prefix: Byte, data: ByteVector): String
fun encode(prefix: ByteArray, data: ByteArray): String
fun encode(prefix: Int, data: ByteArray): String

fun encode(prefix: Byte, data: ByteArray): String

Encode data in Base58Check format. For example, to create an address from a public key you could use: