50 lines
1.5 KiB
Kotlin
50 lines
1.5 KiB
Kotlin
package swiss.qpq.gajumobile.security
|
|
|
|
object GajuNative {
|
|
var loadError: String? = null
|
|
private set
|
|
|
|
init {
|
|
try {
|
|
System.loadLibrary("gaju-native")
|
|
// Register as the default signing provider for TransactionService
|
|
swiss.qpq.gajumaru.core.tools.TransactionService.setProvider(NativeSigningProvider())
|
|
} catch (e: Throwable) {
|
|
loadError = e.message ?: e.toString()
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Zeros out the provided byte array using native memset.
|
|
*/
|
|
@JvmStatic
|
|
external fun memzero(array: ByteArray)
|
|
|
|
/**
|
|
* Generates an Ed25519 keypair from a 32-byte seed.
|
|
* @param seed 32-byte seed.
|
|
* @return 96-byte array containing public key (32 bytes) followed by secret key (64 bytes).
|
|
*/
|
|
@JvmStatic
|
|
external fun cryptoSignSeedKeypair(seed: ByteArray): ByteArray?
|
|
|
|
/**
|
|
* Signs a message using Ed25519.
|
|
* @param message The message to sign.
|
|
* @param secretKey 64-byte secret key.
|
|
* @return 64-byte detached signature.
|
|
*/
|
|
@JvmStatic
|
|
external fun cryptoSignDetached(message: ByteArray, secretKey: ByteArray): ByteArray?
|
|
|
|
/**
|
|
* Verifies an Ed25519 detached signature.
|
|
* @param signature 64-byte signature.
|
|
* @param message The message.
|
|
* @param publicKey 32-byte public key.
|
|
* @return true if valid, false otherwise.
|
|
*/
|
|
@JvmStatic
|
|
external fun cryptoSignVerifyDetached(signature: ByteArray, message: ByteArray, publicKey: ByteArray): Boolean
|
|
}
|