
Encodes and decodes binary data to compact, human-friendly Base58 strings (plain, no checksum); includes fixed-width typed helpers (ints, UUIDs), preserves leading zeros, rejects invalid input.
kotlin-base58 is a Kotlin Multiplatform library for encoding binary data as compact,
human-friendly Base58 strings and decoding those strings back to bytes or typed values.
It is designed for cases where hexadecimal is too long and Base64 is too punctuation-heavy, especially for IDs that humans may need to read, paste, or type.
The Base58 alphabet removes visually ambiguous characters:
0OIlThat makes it useful for invitation codes, external IDs, short opaque tokens, and UUID-like values that should stay copyable without looking noisy.
This library implements plain Base58 encoding. It does not implement Base58Check or any checksum-bearing Bitcoin-specific format.
repositories {
mavenCentral()
}
dependencies {
implementation("one.wabbit:kotlin-base58:1.1.1")
}import one.wabbit.base58.Base58
val payload = "Hello, world!".encodeToByteArray()
val encoded = Base58.encode(payload)
val decoded = Base58.decode(encoded).decodeToString()
check(encoded == "72k1xXWG59wUsYv7h2")
check(decoded == "Hello, world!")The library also supports typed helpers for fixed-width values:
import one.wabbit.base58.Base58
val orderId = 42
val encodedOrderId = Base58.encodeInt(orderId)
val decodedOrderId = Base58.decodeInt(encodedOrderId)
check(decodedOrderId == orderId)These helpers use fixed-width big-endian byte order, which keeps the encoding deterministic across JVMs and interoperable with non-Kotlin implementations that use the same convention.
They are binary serialization helpers, not compact numeric Base58 helpers. For example, encodeInt(42) encodes the four-byte sequence 00 00 00 2A, so decodeInt("j") fails even though "j" is the compact Base58 representation of numeric 42.
import one.wabbit.base58.Base58
import kotlin.uuid.ExperimentalUuidApi
import kotlin.uuid.Uuid
@OptIn(ExperimentalUuidApi::class)
fun example() {
val sessionId = Uuid.parse("123e4567-e89b-12d3-a456-426614174000")
val encodedSessionId = Base58.encodeUuid(sessionId)
val decodedSessionId = Base58.decodeUuid(encodedSessionId)
check(decodedSessionId == sessionId)
}The UUID helpers use Kotlin's experimental kotlin.uuid.Uuid type, so call sites may need to opt in
with @OptIn(ExperimentalUuidApi::class).
Leading zero bytes are preserved. That matters when you are encoding binary identifiers instead of text:
import one.wabbit.base58.Base58
val bytes = byteArrayOf(0, 0, 1, 2, 3)
val encoded = Base58.encode(bytes)
val decoded = Base58.decode(encoded)
check(decoded.contentEquals(bytes))Base58.decode and the typed decode helpers throw Base58DecodingException when:
For example, decodeUuid rejects values that do not decode to exactly 16 bytes.
This library is small and stable in scope. It implements plain Base58 only; checksum-bearing formats such as Base58Check are intentionally out of scope.
Generated API docs can be built locally with Dokka. See API reference notes for the command.
This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0) for open source use.
For commercial use, contact Wabbit Consulting Corporation at wabbit@wabbit.one.
Before contributions can be merged, contributors need to agree to the repository CLA.
kotlin-base58 is a Kotlin Multiplatform library for encoding binary data as compact,
human-friendly Base58 strings and decoding those strings back to bytes or typed values.
It is designed for cases where hexadecimal is too long and Base64 is too punctuation-heavy, especially for IDs that humans may need to read, paste, or type.
The Base58 alphabet removes visually ambiguous characters:
0OIlThat makes it useful for invitation codes, external IDs, short opaque tokens, and UUID-like values that should stay copyable without looking noisy.
This library implements plain Base58 encoding. It does not implement Base58Check or any checksum-bearing Bitcoin-specific format.
repositories {
mavenCentral()
}
dependencies {
implementation("one.wabbit:kotlin-base58:1.1.1")
}import one.wabbit.base58.Base58
val payload = "Hello, world!".encodeToByteArray()
val encoded = Base58.encode(payload)
val decoded = Base58.decode(encoded).decodeToString()
check(encoded == "72k1xXWG59wUsYv7h2")
check(decoded == "Hello, world!")The library also supports typed helpers for fixed-width values:
import one.wabbit.base58.Base58
val orderId = 42
val encodedOrderId = Base58.encodeInt(orderId)
val decodedOrderId = Base58.decodeInt(encodedOrderId)
check(decodedOrderId == orderId)These helpers use fixed-width big-endian byte order, which keeps the encoding deterministic across JVMs and interoperable with non-Kotlin implementations that use the same convention.
They are binary serialization helpers, not compact numeric Base58 helpers. For example, encodeInt(42) encodes the four-byte sequence 00 00 00 2A, so decodeInt("j") fails even though "j" is the compact Base58 representation of numeric 42.
import one.wabbit.base58.Base58
import kotlin.uuid.ExperimentalUuidApi
import kotlin.uuid.Uuid
@OptIn(ExperimentalUuidApi::class)
fun example() {
val sessionId = Uuid.parse("123e4567-e89b-12d3-a456-426614174000")
val encodedSessionId = Base58.encodeUuid(sessionId)
val decodedSessionId = Base58.decodeUuid(encodedSessionId)
check(decodedSessionId == sessionId)
}The UUID helpers use Kotlin's experimental kotlin.uuid.Uuid type, so call sites may need to opt in
with @OptIn(ExperimentalUuidApi::class).
Leading zero bytes are preserved. That matters when you are encoding binary identifiers instead of text:
import one.wabbit.base58.Base58
val bytes = byteArrayOf(0, 0, 1, 2, 3)
val encoded = Base58.encode(bytes)
val decoded = Base58.decode(encoded)
check(decoded.contentEquals(bytes))Base58.decode and the typed decode helpers throw Base58DecodingException when:
For example, decodeUuid rejects values that do not decode to exactly 16 bytes.
This library is small and stable in scope. It implements plain Base58 only; checksum-bearing formats such as Base58Check are intentionally out of scope.
Generated API docs can be built locally with Dokka. See API reference notes for the command.
This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0) for open source use.
For commercial use, contact Wabbit Consulting Corporation at wabbit@wabbit.one.
Before contributions can be merged, contributors need to agree to the repository CLA.