Skip to content

Latest commit

 

History

History
55 lines (42 loc) · 1.64 KB

README.md

File metadata and controls

55 lines (42 loc) · 1.64 KB

KBech32

KBech32 is a Kotlin multiplatform implementation of the Bech32 address format.

The implementation is heavily based on Bitcoinj Bech32 implementation.

Downloading

This library is available on Jitpack:

In order to download it, firstly include the Jitpack repository on your project build.gradle file:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Then, insert the following dependency inside your module's build.gradle file:

dependencies {
    implementation 'com.github.komputing.KBech32:core-{platform}:{version}'
}

The latest version is the one published on Jitpack:

Supported platforms

Platform Usage
common Common Kotlin multiplatform projects
jvm Kotlin-JVM modules/projects
js Kotlin-JS modules/projects
native Kotlin-native modules/projects

Usage

// Encode given a human readable part and a byte array
val encoded = Bech32.encode(humanReadablePart = "bc", data = byteArrayOf(1, 2 ,3))

// Encode by wrapping the data into a Bech32Data object
val data = Bech32Data(
  humanReadablePart = "bc",
  data = byteArrayOf(1, 2, 3)
)

// Decode the data
val bech32Value = "abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw"
val (humanReadablePart, data) = Bech32.decode(bech32Value)