mirror of
https://github.com/aljazceru/react-native-pubky.git
synced 2026-01-20 07:14:23 +01:00
feat: generate secret key
Adds generate_secret_key & get_public_key_from_secret_key functions. Adds generate_secret_key & get_public_key_from_secret_key functions examples to README.md. Fix list error on Android. Bump package version to 0.7.0.
This commit is contained in:
@@ -9,17 +9,7 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import uniffi.pubkymobile.auth
|
||||
import uniffi.pubkymobile.parseAuthUrl
|
||||
import uniffi.pubkymobile.publish
|
||||
import uniffi.pubkymobile.resolve
|
||||
import uniffi.pubkymobile.signUp
|
||||
import uniffi.pubkymobile.signIn
|
||||
import uniffi.pubkymobile.signOut
|
||||
import uniffi.pubkymobile.put
|
||||
import uniffi.pubkymobile.get
|
||||
import uniffi.pubkymobile.publishHttps
|
||||
import uniffi.pubkymobile.resolveHttps
|
||||
import uniffi.pubkymobile.*
|
||||
|
||||
class PubkyModule(reactContext: ReactApplicationContext) :
|
||||
ReactContextBaseJavaModule(reactContext) {
|
||||
@@ -250,6 +240,44 @@ class PubkyModule(reactContext: ReactApplicationContext) :
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
fun generateSecretKey(promise: Promise) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
val result = generate_secret_key()
|
||||
val array = Arguments.createArray().apply {
|
||||
result.forEach { pushString(it) }
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
promise.resolve(array)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
withContext(Dispatchers.Main) {
|
||||
promise.reject("Error", e.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
fun getPublicKeyFromSecretKey(secretKey: String, promise: Promise) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
val result = getPublicKeyFromSecretKey(secretKey)
|
||||
val array = Arguments.createArray().apply {
|
||||
result.forEach { pushString(it) }
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
promise.resolve(array)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
withContext(Dispatchers.Main) {
|
||||
promise.reject("Error", e.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val NAME = "Pubky"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user