All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.eqoty.secretk.crypto.Slip10RawIndex.kt Maven / Gradle / Ivy

Go to download

A Kotlin multiplatform REST client utilizing secret network's gRPC gateway endpoints.

There is a newer version: 6.4.1-rc
Show newest version
package io.eqoty.secretk.crypto

import kotlin.jvm.JvmInline
import kotlin.math.pow

@JvmInline
value class Slip10RawIndex(val data: UInt) {

    companion object {
        fun hardened(hardenedIndex: UInt): Slip10RawIndex =
            Slip10RawIndex(hardenedIndex + 2.toDouble().pow(31.toDouble()).toUInt())

        fun normal(normalIndex: UInt): Slip10RawIndex =
            Slip10RawIndex(normalIndex)
    }

    fun isHardened(): Boolean {
        return this.data >= 2.toDouble().pow(31.toDouble()).toUInt()
    }

    infix fun shr(bitCount: Int): UInt =
        data.shr(bitCount)

    fun toInt(): Int = data.toInt()

    infix fun and(i: Long): UInt = data.and(i.toUInt())

    fun toUByte(): UByte = data.toUByte()

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy