commonMain.kr.jadekim.chameleon.terra.wallet.TerraWallet.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of chameleon-terra-wallet-jvm Show documentation
Show all versions of chameleon-terra-wallet-jvm Show documentation
Crypto Wallet SDK for multiple blockchains
The newest version!
package kr.jadekim.chameleon.terra.wallet
import kr.jadekim.chameleon.core.wallet.Wallet
import kr.jadekim.chameleon.terra.key.TerraKeyPair
import kr.jadekim.chameleon.terra.key.TerraMnemonicKey
import kr.jadekim.chameleon.terra.key.TerraPublicKey
import kr.jadekim.common.encoder.decodeHex
class TerraWallet(override val address: TerraAddress, override val key: TerraPublicKey? = null) : Wallet {
companion object {
@JvmStatic
@JvmOverloads
fun create(index: Int = 0, passphrase: String? = null): Pair {
val key = TerraMnemonicKey.create(index, passphrase)
return TerraWallet(key) to key
}
@JvmStatic
@JvmOverloads
fun fromMnemonic(
mnemonic: String,
index: Int = 0,
passphrase: String? = null,
) = TerraWallet(TerraMnemonicKey(mnemonic, index, passphrase))
@JvmStatic
@JvmOverloads
fun fromKeyPair(
privateKey: ByteArray,
publicKey: ByteArray? = null,
) = TerraWallet(TerraKeyPair(privateKey, publicKey))
@JvmStatic
@JvmOverloads
fun fromKeyPair(
privateKey: String,
publicKey: String? = null,
) = TerraWallet(TerraKeyPair(privateKey.decodeHex(), publicKey?.decodeHex()))
}
constructor(key: TerraPublicKey) : this(TerraAddress.createAccountAddress(key), key)
constructor(publicKey: ByteArray) : this(TerraPublicKey(publicKey))
}