Convert

class Convert<T>(value: T, kind: EncodingFormat? = null)

A utility class Convert to facilitate various conversions including Base64 and Base58BTC.

Parameters

T

The type of the value to be converted.

value

The actual value to be converted.

kind

Specifies the kind of conversion (optional parameter).

Note: Usage of this class should ensure that the type T and kind are compatible with the conversion methods, as certain methods may not support all data types or kinds

Example Usage:

// Example 1: Convert a ByteArray to a Base64Url encoded string without padding
val byteArray = byteArrayOf(1, 2, 3)
val base64Url = Convert(byteArray).toBase64Url() // same as .toBase64Url(padding = false)
println(base64Url) // Output should be a Base64Url encoded string without padding

// Example 2: Convert a Base64Url encoded string to a ByteArray
val base64Str = "AQID"
val originalByteArray = Convert(base64Str, EncodingFormat.Base64Url).toByteArray()

// Example 3: Convert a ByteArray to a Base58Btc encoded string
val byteArray = byteArrayOf(1, 2, 3)
val base58BtcStr = Convert(byteArray).toBase58Btc()
println(base58BtcStr) // Output should be a Base58Btc encoded string

// Example 4: Convert a Base64Url encoded string to a regular string
val base64UrlStr = "SGVsbG8gd29ybGQ="
val decodedStr = Convert(base64UrlStr, EncodingFormat.Base64Url).toStr()
println(decodedStr) // Output should be: "Hello world"

Constructors

Link copied to clipboard
constructor(value: T, kind: EncodingFormat? = null)

Functions

Link copied to clipboard

Converts the value to a Base58BTC-encoded string.

Link copied to clipboard
fun toBase64Url(padding: Boolean = false): String

Converts the value to a Base64Url-encoded string.

Link copied to clipboard

Converts the value to a byte array representation.

Link copied to clipboard
fun toStr(): String

Converts the value to a string representation.

Link copied to clipboard

Converts the value to a ZBase32-encoded string.