FastKrypto

AndroidiOSJVMmacOSLinux

FastKrypto provides Kotlin Multiplatform bindings to the high-performance fastcrypto Rust library. It is the primary cryptography implementation used by ksui and other McXross Sui SDKs.

Get safe, cross-platform implementations of Ed25519, Secp256k1, Secp256r1, mnemonic/HD derivation, and common hashes.

Key Features

  • Generate, sign, and verify keys for Ed25519, Secp256k1, and Secp256r1.
  • Get recoverable signatures on the secp curves.
  • Generate and derive keys from BIP-39 mnemonics.
  • Have access to fast hash functions (SHA-256, Keccak, Blake2b-256, etc.) and HKDF/HMAC.
  • Private key material is zeroized after use where possible.
  • The library works on all major Kotlin targets.

Installation

Add the dependency to your KMP project. Use platform-specific artifacts for best results.

Code
// commonMain implementation("xyz.mcxross.fastkrypto:fastkrypto:0.1.3")

Platform artifacts are published:

Code
implementation("xyz.mcxross.fastkrypto:fastkrypto-jvm:0.1.3") implementation("xyz.mcxross.fastkrypto:fastkrypto-android:0.1.3") implementation("xyz.mcxross.fastkrypto:fastkrypto-iosarm64:0.1.3") // ... other native targets

For snapshots:

Code
repositories { maven("https://central.sonatype.com/repository/maven-snapshots") }

Quick Start

Key generation and signing (Ed25519)

Code
import xyz.mcxross.fastkrypto.ed25519GenerateKeypair import xyz.mcxross.fastkrypto.ed25519Sign import xyz.mcxross.fastkrypto.ed25519Verify val keypair = ed25519GenerateKeypair() val message = "hello fastkrypto".encodeToByteArray() val signature = ed25519Sign(keypair.privateKey, message) val isValid = ed25519Verify(keypair.publicKey, message, signature) println("Verified: $isValid")

All cryptographic operations can throw FastCryptoFfiException on invalid input lengths or bad data.

Mnemonic and key derivation

Code
import xyz.mcxross.fastkrypto.mnemonicGenerate import xyz.mcxross.fastkrypto.mnemonicValidate import xyz.mcxross.fastkrypto.mnemonicDeriveKeypair import xyz.mcxross.fastkrypto.SignatureScheme val phrase = mnemonicGenerate(12u) check(mnemonicValidate(phrase)) val path = "m/44'/784'/0'/0/0" val keypair = mnemonicDeriveKeypair(phrase, "", SignatureScheme.ED25519, path) println("Private key length: ${keypair.privateKey.size}")

Hashes

Code
import xyz.mcxross.fastkrypto.sha256 import xyz.mcxross.fastkrypto.blake2b256 import xyz.mcxross.fastkrypto.keccak256 val data = "some data".encodeToByteArray() val sha = sha256(data) val blake = blake2b256(data) val keccak = keccak256(data)

Supported Curves & Functions

SchemeGenerateSignVerifyRecoverablePublic from Private
Ed25519
Secp256k1
Secp256r1

Mnemonic / HD Derivation

  • mnemonicGenerate(wordCount)
  • mnemonicValidate(phrase)
  • mnemonicToSeed(phrase, passphrase)
  • mnemonicDerivePrivateKey(...)
  • mnemonicDerivePublicKey(...)
  • mnemonicDeriveKeypair(...)

Use standard BIP-44 paths (e.g. m/44'/784'/0'/0/0 for Sui).

Hashes & KDF

  • sha256, sha3_256, sha512, sha3_512
  • keccak256
  • blake2b256
  • hmac_sha3_256_digest
  • hkdf_sha3_256_expand

Error Handling

Operations that can fail throw FastCryptoFfiException.

Reference & Resources