mirror of
https://github.com/aljazceru/react-native-pubky.git
synced 2025-12-17 14:44:26 +01:00
Merge pull request #8 from pubky/setup-new-methods
feat: setup new methods
This commit is contained in:
@@ -15,9 +15,11 @@ npm install @synonymdev/react-native-pubky
|
|||||||
- [x] [publish](#publish): Functionality to publish content.
|
- [x] [publish](#publish): Functionality to publish content.
|
||||||
- [x] [resolve](#resolve): Functionality to resolve content.
|
- [x] [resolve](#resolve): Functionality to resolve content.
|
||||||
### Methods to be Implemented
|
### Methods to be Implemented
|
||||||
- [ ] signIn: Functionality to sign in.
|
- [ ] signIn: Sign-in to a homeserver.
|
||||||
- [ ] signUp: Functionality to sign up.
|
- [ ] signUp: Sign-up to a homeserver and update Pkarr accordingly.
|
||||||
- [ ] signOut: Functionality to sign out.
|
- [ ] signOut: Sign-out from a homeserver.
|
||||||
|
- [ ] put: Upload a small payload to a given path.
|
||||||
|
- [ ] get: Download a small payload from a given path relative to a pubky author.
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ import uniffi.pubkymobile.auth
|
|||||||
import uniffi.pubkymobile.parseAuthUrl
|
import uniffi.pubkymobile.parseAuthUrl
|
||||||
import uniffi.pubkymobile.publish
|
import uniffi.pubkymobile.publish
|
||||||
import uniffi.pubkymobile.resolve
|
import uniffi.pubkymobile.resolve
|
||||||
|
import uniffi.pubkymobile.signUp
|
||||||
|
import uniffi.pubkymobile.signIn
|
||||||
|
import uniffi.pubkymobile.signOut
|
||||||
|
import uniffi.pubkymobile.put
|
||||||
|
import uniffi.pubkymobile.get
|
||||||
|
|
||||||
class PubkyModule(reactContext: ReactApplicationContext) :
|
class PubkyModule(reactContext: ReactApplicationContext) :
|
||||||
ReactContextBaseJavaModule(reactContext) {
|
ReactContextBaseJavaModule(reactContext) {
|
||||||
@@ -91,6 +96,101 @@ class PubkyModule(reactContext: ReactApplicationContext) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
fun signUp(secretKey: String, homeserver: String, promise: Promise) {
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
try {
|
||||||
|
val result = signUp(secretKey, homeserver)
|
||||||
|
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 signIn(secretKey: String, promise: Promise) {
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
try {
|
||||||
|
val result = signIn(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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
fun signOut(secretKey: String, promise: Promise) {
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
try {
|
||||||
|
val result = signOut(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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
fun put(url: String, content: String, promise: Promise) {
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
try {
|
||||||
|
val result = put(url, content)
|
||||||
|
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 get(url: String, promise: Promise) {
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
try {
|
||||||
|
val result = get(url)
|
||||||
|
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 {
|
companion object {
|
||||||
const val NAME = "Pubky"
|
const val NAME = "Pubky"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ import java.nio.ByteOrder
|
|||||||
import java.nio.CharBuffer
|
import java.nio.CharBuffer
|
||||||
import java.nio.charset.CodingErrorAction
|
import java.nio.charset.CodingErrorAction
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
import kotlinx.coroutines.CancellableContinuation
|
||||||
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
|
|
||||||
// This is a helper for safely working with byte buffers returned from the Rust code.
|
// This is a helper for safely working with byte buffers returned from the Rust code.
|
||||||
// A rust-owned buffer is represented by its capacity, its current length, and a
|
// A rust-owned buffer is represented by its capacity, its current length, and a
|
||||||
@@ -377,18 +380,29 @@ internal interface _UniFFILib : Library {
|
|||||||
.also { lib: _UniFFILib ->
|
.also { lib: _UniFFILib ->
|
||||||
uniffiCheckContractApiVersion(lib)
|
uniffiCheckContractApiVersion(lib)
|
||||||
uniffiCheckApiChecksums(lib)
|
uniffiCheckApiChecksums(lib)
|
||||||
|
uniffiRustFutureContinuationCallback.register(lib)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun uniffi_pubkymobile_fn_func_auth(`url`: RustBuffer.ByValue,`secretKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
fun uniffi_pubkymobile_fn_func_auth(`url`: RustBuffer.ByValue,`secretKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
||||||
): RustBuffer.ByValue
|
): RustBuffer.ByValue
|
||||||
|
fun uniffi_pubkymobile_fn_func_get(`url`: RustBuffer.ByValue,
|
||||||
|
): Pointer
|
||||||
fun uniffi_pubkymobile_fn_func_parse_auth_url(`url`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
fun uniffi_pubkymobile_fn_func_parse_auth_url(`url`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
||||||
): RustBuffer.ByValue
|
): RustBuffer.ByValue
|
||||||
fun uniffi_pubkymobile_fn_func_publish(`recordName`: RustBuffer.ByValue,`recordContent`: RustBuffer.ByValue,`secretKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
fun uniffi_pubkymobile_fn_func_publish(`recordName`: RustBuffer.ByValue,`recordContent`: RustBuffer.ByValue,`secretKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
||||||
): RustBuffer.ByValue
|
): RustBuffer.ByValue
|
||||||
|
fun uniffi_pubkymobile_fn_func_put(`url`: RustBuffer.ByValue,`content`: RustBuffer.ByValue,
|
||||||
|
): Pointer
|
||||||
fun uniffi_pubkymobile_fn_func_resolve(`publicKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
fun uniffi_pubkymobile_fn_func_resolve(`publicKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
||||||
): RustBuffer.ByValue
|
): RustBuffer.ByValue
|
||||||
|
fun uniffi_pubkymobile_fn_func_sign_in(`secretKey`: RustBuffer.ByValue,
|
||||||
|
): Pointer
|
||||||
|
fun uniffi_pubkymobile_fn_func_sign_out(`secretKey`: RustBuffer.ByValue,
|
||||||
|
): Pointer
|
||||||
|
fun uniffi_pubkymobile_fn_func_sign_up(`secretKey`: RustBuffer.ByValue,`homeserver`: RustBuffer.ByValue,
|
||||||
|
): Pointer
|
||||||
fun ffi_pubkymobile_rustbuffer_alloc(`size`: Int,_uniffi_out_err: RustCallStatus,
|
fun ffi_pubkymobile_rustbuffer_alloc(`size`: Int,_uniffi_out_err: RustCallStatus,
|
||||||
): RustBuffer.ByValue
|
): RustBuffer.ByValue
|
||||||
fun ffi_pubkymobile_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,_uniffi_out_err: RustCallStatus,
|
fun ffi_pubkymobile_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,_uniffi_out_err: RustCallStatus,
|
||||||
@@ -505,12 +519,22 @@ internal interface _UniFFILib : Library {
|
|||||||
): Unit
|
): Unit
|
||||||
fun uniffi_pubkymobile_checksum_func_auth(
|
fun uniffi_pubkymobile_checksum_func_auth(
|
||||||
): Short
|
): Short
|
||||||
|
fun uniffi_pubkymobile_checksum_func_get(
|
||||||
|
): Short
|
||||||
fun uniffi_pubkymobile_checksum_func_parse_auth_url(
|
fun uniffi_pubkymobile_checksum_func_parse_auth_url(
|
||||||
): Short
|
): Short
|
||||||
fun uniffi_pubkymobile_checksum_func_publish(
|
fun uniffi_pubkymobile_checksum_func_publish(
|
||||||
): Short
|
): Short
|
||||||
|
fun uniffi_pubkymobile_checksum_func_put(
|
||||||
|
): Short
|
||||||
fun uniffi_pubkymobile_checksum_func_resolve(
|
fun uniffi_pubkymobile_checksum_func_resolve(
|
||||||
): Short
|
): Short
|
||||||
|
fun uniffi_pubkymobile_checksum_func_sign_in(
|
||||||
|
): Short
|
||||||
|
fun uniffi_pubkymobile_checksum_func_sign_out(
|
||||||
|
): Short
|
||||||
|
fun uniffi_pubkymobile_checksum_func_sign_up(
|
||||||
|
): Short
|
||||||
fun ffi_pubkymobile_uniffi_contract_version(
|
fun ffi_pubkymobile_uniffi_contract_version(
|
||||||
): Int
|
): Int
|
||||||
|
|
||||||
@@ -531,18 +555,77 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
|
|||||||
if (lib.uniffi_pubkymobile_checksum_func_auth() != 61378.toShort()) {
|
if (lib.uniffi_pubkymobile_checksum_func_auth() != 61378.toShort()) {
|
||||||
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
||||||
}
|
}
|
||||||
|
if (lib.uniffi_pubkymobile_checksum_func_get() != 5395.toShort()) {
|
||||||
|
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
||||||
|
}
|
||||||
if (lib.uniffi_pubkymobile_checksum_func_parse_auth_url() != 29088.toShort()) {
|
if (lib.uniffi_pubkymobile_checksum_func_parse_auth_url() != 29088.toShort()) {
|
||||||
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
||||||
}
|
}
|
||||||
if (lib.uniffi_pubkymobile_checksum_func_publish() != 20156.toShort()) {
|
if (lib.uniffi_pubkymobile_checksum_func_publish() != 20156.toShort()) {
|
||||||
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
||||||
}
|
}
|
||||||
|
if (lib.uniffi_pubkymobile_checksum_func_put() != 47594.toShort()) {
|
||||||
|
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
||||||
|
}
|
||||||
if (lib.uniffi_pubkymobile_checksum_func_resolve() != 18303.toShort()) {
|
if (lib.uniffi_pubkymobile_checksum_func_resolve() != 18303.toShort()) {
|
||||||
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
||||||
}
|
}
|
||||||
|
if (lib.uniffi_pubkymobile_checksum_func_sign_in() != 53969.toShort()) {
|
||||||
|
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
||||||
|
}
|
||||||
|
if (lib.uniffi_pubkymobile_checksum_func_sign_out() != 32961.toShort()) {
|
||||||
|
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
||||||
|
}
|
||||||
|
if (lib.uniffi_pubkymobile_checksum_func_sign_up() != 28083.toShort()) {
|
||||||
|
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Async support
|
// Async support
|
||||||
|
// Async return type handlers
|
||||||
|
|
||||||
|
internal const val UNIFFI_RUST_FUTURE_POLL_READY = 0.toShort()
|
||||||
|
internal const val UNIFFI_RUST_FUTURE_POLL_MAYBE_READY = 1.toShort()
|
||||||
|
|
||||||
|
internal val uniffiContinuationHandleMap = UniFfiHandleMap<CancellableContinuation<Short>>()
|
||||||
|
|
||||||
|
// FFI type for Rust future continuations
|
||||||
|
internal object uniffiRustFutureContinuationCallback: UniFffiRustFutureContinuationCallbackType {
|
||||||
|
override fun callback(continuationHandle: USize, pollResult: Short) {
|
||||||
|
uniffiContinuationHandleMap.remove(continuationHandle)?.resume(pollResult)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun register(lib: _UniFFILib) {
|
||||||
|
lib.ffi_pubkymobile_rust_future_continuation_callback_set(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal suspend fun<T, F, E: Exception> uniffiRustCallAsync(
|
||||||
|
rustFuture: Pointer,
|
||||||
|
pollFunc: (Pointer, USize) -> Unit,
|
||||||
|
completeFunc: (Pointer, RustCallStatus) -> F,
|
||||||
|
freeFunc: (Pointer) -> Unit,
|
||||||
|
liftFunc: (F) -> T,
|
||||||
|
errorHandler: CallStatusErrorHandler<E>
|
||||||
|
): T {
|
||||||
|
try {
|
||||||
|
do {
|
||||||
|
val pollResult = suspendCancellableCoroutine<Short> { continuation ->
|
||||||
|
pollFunc(
|
||||||
|
rustFuture,
|
||||||
|
uniffiContinuationHandleMap.insert(continuation)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} while (pollResult != UNIFFI_RUST_FUTURE_POLL_READY);
|
||||||
|
|
||||||
|
return liftFunc(
|
||||||
|
rustCallWithError(errorHandler, { status -> completeFunc(rustFuture, status) })
|
||||||
|
)
|
||||||
|
} finally {
|
||||||
|
freeFunc(rustFuture)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Public interface members begin here.
|
// Public interface members begin here.
|
||||||
|
|
||||||
@@ -626,6 +709,10 @@ public object FfiConverterSequenceString: FfiConverterRustBuffer<List<String>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun `auth`(`url`: String, `secretKey`: String): List<String> {
|
fun `auth`(`url`: String, `secretKey`: String): List<String> {
|
||||||
return FfiConverterSequenceString.lift(
|
return FfiConverterSequenceString.lift(
|
||||||
rustCall() { _status ->
|
rustCall() { _status ->
|
||||||
@@ -634,6 +721,20 @@ fun `auth`(`url`: String, `secretKey`: String): List<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
|
||||||
|
suspend fun `get`(`url`: String) : List<String> {
|
||||||
|
return uniffiRustCallAsync(
|
||||||
|
_UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_get(FfiConverterString.lower(`url`),),
|
||||||
|
{ future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_poll_rust_buffer(future, continuation) },
|
||||||
|
{ future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_complete_rust_buffer(future, continuation) },
|
||||||
|
{ future -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_free_rust_buffer(future) },
|
||||||
|
// lift function
|
||||||
|
{ FfiConverterSequenceString.lift(it) },
|
||||||
|
// Error FFI converter
|
||||||
|
NullCallStatusErrorHandler,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun `parseAuthUrl`(`url`: String): List<String> {
|
fun `parseAuthUrl`(`url`: String): List<String> {
|
||||||
return FfiConverterSequenceString.lift(
|
return FfiConverterSequenceString.lift(
|
||||||
rustCall() { _status ->
|
rustCall() { _status ->
|
||||||
@@ -650,6 +751,20 @@ fun `publish`(`recordName`: String, `recordContent`: String, `secretKey`: String
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
|
||||||
|
suspend fun `put`(`url`: String, `content`: String) : List<String> {
|
||||||
|
return uniffiRustCallAsync(
|
||||||
|
_UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_put(FfiConverterString.lower(`url`),FfiConverterString.lower(`content`),),
|
||||||
|
{ future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_poll_rust_buffer(future, continuation) },
|
||||||
|
{ future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_complete_rust_buffer(future, continuation) },
|
||||||
|
{ future -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_free_rust_buffer(future) },
|
||||||
|
// lift function
|
||||||
|
{ FfiConverterSequenceString.lift(it) },
|
||||||
|
// Error FFI converter
|
||||||
|
NullCallStatusErrorHandler,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun `resolve`(`publicKey`: String): List<String> {
|
fun `resolve`(`publicKey`: String): List<String> {
|
||||||
return FfiConverterSequenceString.lift(
|
return FfiConverterSequenceString.lift(
|
||||||
rustCall() { _status ->
|
rustCall() { _status ->
|
||||||
@@ -658,3 +773,45 @@ fun `resolve`(`publicKey`: String): List<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
|
||||||
|
suspend fun `signIn`(`secretKey`: String) : List<String> {
|
||||||
|
return uniffiRustCallAsync(
|
||||||
|
_UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_sign_in(FfiConverterString.lower(`secretKey`),),
|
||||||
|
{ future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_poll_rust_buffer(future, continuation) },
|
||||||
|
{ future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_complete_rust_buffer(future, continuation) },
|
||||||
|
{ future -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_free_rust_buffer(future) },
|
||||||
|
// lift function
|
||||||
|
{ FfiConverterSequenceString.lift(it) },
|
||||||
|
// Error FFI converter
|
||||||
|
NullCallStatusErrorHandler,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
|
||||||
|
suspend fun `signOut`(`secretKey`: String) : List<String> {
|
||||||
|
return uniffiRustCallAsync(
|
||||||
|
_UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_sign_out(FfiConverterString.lower(`secretKey`),),
|
||||||
|
{ future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_poll_rust_buffer(future, continuation) },
|
||||||
|
{ future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_complete_rust_buffer(future, continuation) },
|
||||||
|
{ future -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_free_rust_buffer(future) },
|
||||||
|
// lift function
|
||||||
|
{ FfiConverterSequenceString.lift(it) },
|
||||||
|
// Error FFI converter
|
||||||
|
NullCallStatusErrorHandler,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
|
||||||
|
suspend fun `signUp`(`secretKey`: String, `homeserver`: String) : List<String> {
|
||||||
|
return uniffiRustCallAsync(
|
||||||
|
_UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_sign_up(FfiConverterString.lower(`secretKey`),FfiConverterString.lower(`homeserver`),),
|
||||||
|
{ future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_poll_rust_buffer(future, continuation) },
|
||||||
|
{ future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_complete_rust_buffer(future, continuation) },
|
||||||
|
{ future -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_free_rust_buffer(future) },
|
||||||
|
// lift function
|
||||||
|
{ FfiConverterSequenceString.lift(it) },
|
||||||
|
// Error FFI converter
|
||||||
|
NullCallStatusErrorHandler,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -4,6 +4,11 @@ import {
|
|||||||
parseAuthUrl,
|
parseAuthUrl,
|
||||||
publish,
|
publish,
|
||||||
resolve,
|
resolve,
|
||||||
|
signUp,
|
||||||
|
signIn,
|
||||||
|
signOut,
|
||||||
|
put,
|
||||||
|
get,
|
||||||
} from '@synonymdev/react-native-pubky';
|
} from '@synonymdev/react-native-pubky';
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
@@ -31,9 +36,9 @@ export default function App() {
|
|||||||
title={'parseAuthUrl'}
|
title={'parseAuthUrl'}
|
||||||
onPress={async (): Promise<void> => {
|
onPress={async (): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const res = await parseAuthUrl(
|
const pubkyAuthUrl =
|
||||||
'pubkyauth:///?relay=https://demo.httprelay.io/link&capabilities=/pub/pubky.app:rw,/pub/example.com/nested:rw&secret=FyzJ3gJ1W7boyFZC1Do9fYrRmDNgCLNRwEu_gaBgPUA'
|
'pubkyauth:///?relay=https://demo.httprelay.io/link&capabilities=/pub/pubky.app:rw,/pub/example.com/nested:rw&secret=FyzJ3gJ1W7boyFZC1Do9fYrRmDNgCLNRwEu_gaBgPUA';
|
||||||
);
|
const res = await parseAuthUrl(pubkyAuthUrl);
|
||||||
if (res.isErr()) {
|
if (res.isErr()) {
|
||||||
console.log(res.error.message);
|
console.log(res.error.message);
|
||||||
return;
|
return;
|
||||||
@@ -49,9 +54,9 @@ export default function App() {
|
|||||||
onPress={async (): Promise<void> => {
|
onPress={async (): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const res = await publish(
|
const res = await publish(
|
||||||
'recordnametest',
|
'recordnametest', // Record Name
|
||||||
'recordcontenttest',
|
'recordcontenttest', // Record Content
|
||||||
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
|
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' // Secret Key
|
||||||
);
|
);
|
||||||
if (res.isErr()) {
|
if (res.isErr()) {
|
||||||
console.log(res.error.message);
|
console.log(res.error.message);
|
||||||
@@ -68,7 +73,7 @@ export default function App() {
|
|||||||
onPress={async (): Promise<void> => {
|
onPress={async (): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const res = await resolve(
|
const res = await resolve(
|
||||||
'z4e8s17cou9qmuwen8p1556jzhf1wktmzo6ijsfnri9c4hnrdfty'
|
'z4e8s17cou9qmuwen8p1556jzhf1wktmzo6ijsfnri9c4hnrdfty' // Public key
|
||||||
);
|
);
|
||||||
if (res.isErr()) {
|
if (res.isErr()) {
|
||||||
console.log(res.error.message);
|
console.log(res.error.message);
|
||||||
@@ -80,6 +85,88 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<Button
|
||||||
|
title={'signup'}
|
||||||
|
onPress={async (): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const res = await signUp(
|
||||||
|
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', // Secret Key
|
||||||
|
'pubky://8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo' // Homeserver
|
||||||
|
);
|
||||||
|
if (res.isErr()) {
|
||||||
|
console.log(res.error.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(res.value);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
title={'signin'}
|
||||||
|
onPress={async (): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const res = await signIn(
|
||||||
|
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' // Secret Key
|
||||||
|
);
|
||||||
|
if (res.isErr()) {
|
||||||
|
console.log(res.error.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(res.value);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
title={'signout'}
|
||||||
|
onPress={async (): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const res = await signOut(
|
||||||
|
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' // Secret Key
|
||||||
|
);
|
||||||
|
if (res.isErr()) {
|
||||||
|
console.log(res.error.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(res.value);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
title={'put'}
|
||||||
|
onPress={async (): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const res = await put('', { data: 'test data' });
|
||||||
|
if (res.isErr()) {
|
||||||
|
console.log(res.error.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(res.value);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
title={'get'}
|
||||||
|
onPress={async (): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const res = await get('');
|
||||||
|
if (res.isErr()) {
|
||||||
|
console.log(res.error.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(res.value);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,12 +65,22 @@ typedef void (*UniFfiRustFutureContinuation)(void * _Nonnull, int8_t);
|
|||||||
// Scaffolding functions
|
// Scaffolding functions
|
||||||
RustBuffer uniffi_pubkymobile_fn_func_auth(RustBuffer url, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
|
RustBuffer uniffi_pubkymobile_fn_func_auth(RustBuffer url, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
|
||||||
);
|
);
|
||||||
|
void* _Nonnull uniffi_pubkymobile_fn_func_get(RustBuffer url
|
||||||
|
);
|
||||||
RustBuffer uniffi_pubkymobile_fn_func_parse_auth_url(RustBuffer url, RustCallStatus *_Nonnull out_status
|
RustBuffer uniffi_pubkymobile_fn_func_parse_auth_url(RustBuffer url, RustCallStatus *_Nonnull out_status
|
||||||
);
|
);
|
||||||
RustBuffer uniffi_pubkymobile_fn_func_publish(RustBuffer record_name, RustBuffer record_content, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
|
RustBuffer uniffi_pubkymobile_fn_func_publish(RustBuffer record_name, RustBuffer record_content, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
|
||||||
);
|
);
|
||||||
|
void* _Nonnull uniffi_pubkymobile_fn_func_put(RustBuffer url, RustBuffer content
|
||||||
|
);
|
||||||
RustBuffer uniffi_pubkymobile_fn_func_resolve(RustBuffer public_key, RustCallStatus *_Nonnull out_status
|
RustBuffer uniffi_pubkymobile_fn_func_resolve(RustBuffer public_key, RustCallStatus *_Nonnull out_status
|
||||||
);
|
);
|
||||||
|
void* _Nonnull uniffi_pubkymobile_fn_func_sign_in(RustBuffer secret_key
|
||||||
|
);
|
||||||
|
void* _Nonnull uniffi_pubkymobile_fn_func_sign_out(RustBuffer secret_key
|
||||||
|
);
|
||||||
|
void* _Nonnull uniffi_pubkymobile_fn_func_sign_up(RustBuffer secret_key, RustBuffer homeserver
|
||||||
|
);
|
||||||
RustBuffer ffi_pubkymobile_rustbuffer_alloc(int32_t size, RustCallStatus *_Nonnull out_status
|
RustBuffer ffi_pubkymobile_rustbuffer_alloc(int32_t size, RustCallStatus *_Nonnull out_status
|
||||||
);
|
);
|
||||||
RustBuffer ffi_pubkymobile_rustbuffer_from_bytes(ForeignBytes bytes, RustCallStatus *_Nonnull out_status
|
RustBuffer ffi_pubkymobile_rustbuffer_from_bytes(ForeignBytes bytes, RustCallStatus *_Nonnull out_status
|
||||||
@@ -187,15 +197,30 @@ void ffi_pubkymobile_rust_future_complete_void(void* _Nonnull handle, RustCallSt
|
|||||||
);
|
);
|
||||||
uint16_t uniffi_pubkymobile_checksum_func_auth(void
|
uint16_t uniffi_pubkymobile_checksum_func_auth(void
|
||||||
|
|
||||||
|
);
|
||||||
|
uint16_t uniffi_pubkymobile_checksum_func_get(void
|
||||||
|
|
||||||
);
|
);
|
||||||
uint16_t uniffi_pubkymobile_checksum_func_parse_auth_url(void
|
uint16_t uniffi_pubkymobile_checksum_func_parse_auth_url(void
|
||||||
|
|
||||||
);
|
);
|
||||||
uint16_t uniffi_pubkymobile_checksum_func_publish(void
|
uint16_t uniffi_pubkymobile_checksum_func_publish(void
|
||||||
|
|
||||||
|
);
|
||||||
|
uint16_t uniffi_pubkymobile_checksum_func_put(void
|
||||||
|
|
||||||
);
|
);
|
||||||
uint16_t uniffi_pubkymobile_checksum_func_resolve(void
|
uint16_t uniffi_pubkymobile_checksum_func_resolve(void
|
||||||
|
|
||||||
|
);
|
||||||
|
uint16_t uniffi_pubkymobile_checksum_func_sign_in(void
|
||||||
|
|
||||||
|
);
|
||||||
|
uint16_t uniffi_pubkymobile_checksum_func_sign_out(void
|
||||||
|
|
||||||
|
);
|
||||||
|
uint16_t uniffi_pubkymobile_checksum_func_sign_up(void
|
||||||
|
|
||||||
);
|
);
|
||||||
uint32_t ffi_pubkymobile_uniffi_contract_version(void
|
uint32_t ffi_pubkymobile_uniffi_contract_version(void
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -65,12 +65,22 @@ typedef void (*UniFfiRustFutureContinuation)(void * _Nonnull, int8_t);
|
|||||||
// Scaffolding functions
|
// Scaffolding functions
|
||||||
RustBuffer uniffi_pubkymobile_fn_func_auth(RustBuffer url, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
|
RustBuffer uniffi_pubkymobile_fn_func_auth(RustBuffer url, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
|
||||||
);
|
);
|
||||||
|
void* _Nonnull uniffi_pubkymobile_fn_func_get(RustBuffer url
|
||||||
|
);
|
||||||
RustBuffer uniffi_pubkymobile_fn_func_parse_auth_url(RustBuffer url, RustCallStatus *_Nonnull out_status
|
RustBuffer uniffi_pubkymobile_fn_func_parse_auth_url(RustBuffer url, RustCallStatus *_Nonnull out_status
|
||||||
);
|
);
|
||||||
RustBuffer uniffi_pubkymobile_fn_func_publish(RustBuffer record_name, RustBuffer record_content, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
|
RustBuffer uniffi_pubkymobile_fn_func_publish(RustBuffer record_name, RustBuffer record_content, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
|
||||||
);
|
);
|
||||||
|
void* _Nonnull uniffi_pubkymobile_fn_func_put(RustBuffer url, RustBuffer content
|
||||||
|
);
|
||||||
RustBuffer uniffi_pubkymobile_fn_func_resolve(RustBuffer public_key, RustCallStatus *_Nonnull out_status
|
RustBuffer uniffi_pubkymobile_fn_func_resolve(RustBuffer public_key, RustCallStatus *_Nonnull out_status
|
||||||
);
|
);
|
||||||
|
void* _Nonnull uniffi_pubkymobile_fn_func_sign_in(RustBuffer secret_key
|
||||||
|
);
|
||||||
|
void* _Nonnull uniffi_pubkymobile_fn_func_sign_out(RustBuffer secret_key
|
||||||
|
);
|
||||||
|
void* _Nonnull uniffi_pubkymobile_fn_func_sign_up(RustBuffer secret_key, RustBuffer homeserver
|
||||||
|
);
|
||||||
RustBuffer ffi_pubkymobile_rustbuffer_alloc(int32_t size, RustCallStatus *_Nonnull out_status
|
RustBuffer ffi_pubkymobile_rustbuffer_alloc(int32_t size, RustCallStatus *_Nonnull out_status
|
||||||
);
|
);
|
||||||
RustBuffer ffi_pubkymobile_rustbuffer_from_bytes(ForeignBytes bytes, RustCallStatus *_Nonnull out_status
|
RustBuffer ffi_pubkymobile_rustbuffer_from_bytes(ForeignBytes bytes, RustCallStatus *_Nonnull out_status
|
||||||
@@ -187,15 +197,30 @@ void ffi_pubkymobile_rust_future_complete_void(void* _Nonnull handle, RustCallSt
|
|||||||
);
|
);
|
||||||
uint16_t uniffi_pubkymobile_checksum_func_auth(void
|
uint16_t uniffi_pubkymobile_checksum_func_auth(void
|
||||||
|
|
||||||
|
);
|
||||||
|
uint16_t uniffi_pubkymobile_checksum_func_get(void
|
||||||
|
|
||||||
);
|
);
|
||||||
uint16_t uniffi_pubkymobile_checksum_func_parse_auth_url(void
|
uint16_t uniffi_pubkymobile_checksum_func_parse_auth_url(void
|
||||||
|
|
||||||
);
|
);
|
||||||
uint16_t uniffi_pubkymobile_checksum_func_publish(void
|
uint16_t uniffi_pubkymobile_checksum_func_publish(void
|
||||||
|
|
||||||
|
);
|
||||||
|
uint16_t uniffi_pubkymobile_checksum_func_put(void
|
||||||
|
|
||||||
);
|
);
|
||||||
uint16_t uniffi_pubkymobile_checksum_func_resolve(void
|
uint16_t uniffi_pubkymobile_checksum_func_resolve(void
|
||||||
|
|
||||||
|
);
|
||||||
|
uint16_t uniffi_pubkymobile_checksum_func_sign_in(void
|
||||||
|
|
||||||
|
);
|
||||||
|
uint16_t uniffi_pubkymobile_checksum_func_sign_out(void
|
||||||
|
|
||||||
|
);
|
||||||
|
uint16_t uniffi_pubkymobile_checksum_func_sign_up(void
|
||||||
|
|
||||||
);
|
);
|
||||||
uint32_t ffi_pubkymobile_uniffi_contract_version(void
|
uint32_t ffi_pubkymobile_uniffi_contract_version(void
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
22
ios/Pubky.mm
22
ios/Pubky.mm
@@ -21,6 +21,28 @@ RCT_EXTERN_METHOD(resolve:(NSString *)publicKey
|
|||||||
withResolver:(RCTPromiseResolveBlock)resolve
|
withResolver:(RCTPromiseResolveBlock)resolve
|
||||||
withRejecter:(RCTPromiseRejectBlock)reject)
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
||||||
|
|
||||||
|
RCT_EXTERN_METHOD(signUp:(NSString *)secretKey
|
||||||
|
homeserver:(NSString *)homeserver
|
||||||
|
withResolver:(RCTPromiseResolveBlock)resolve
|
||||||
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
||||||
|
|
||||||
|
RCT_EXTERN_METHOD(signIn:(NSString *)secretKey
|
||||||
|
withResolver:(RCTPromiseResolveBlock)resolve
|
||||||
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
||||||
|
|
||||||
|
RCT_EXTERN_METHOD(signOut:(NSString *)secretKey
|
||||||
|
withResolver:(RCTPromiseResolveBlock)resolve
|
||||||
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
||||||
|
|
||||||
|
RCT_EXTERN_METHOD(put:(NSString *)url
|
||||||
|
content:(NSString *)content
|
||||||
|
withResolver:(RCTPromiseResolveBlock)resolve
|
||||||
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
||||||
|
|
||||||
|
RCT_EXTERN_METHOD(get:(NSString *)url
|
||||||
|
withResolver:(RCTPromiseResolveBlock)resolve
|
||||||
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
||||||
|
|
||||||
+ (BOOL)requiresMainQueueSetup
|
+ (BOOL)requiresMainQueueSetup
|
||||||
{
|
{
|
||||||
return NO;
|
return NO;
|
||||||
|
|||||||
@@ -49,4 +49,64 @@ class Pubky: NSObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc(signUp:homeserver:withResolver:withRejecter:)
|
||||||
|
func signUp(_ secretKey: String, homeserver: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
let result = try await react_native_pubky.signUp(secretKey: secretKey, homeserver: homeserver)
|
||||||
|
resolve(result)
|
||||||
|
} catch {
|
||||||
|
reject("signUp Error", "Failed to sign up", error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc(signIn:withResolver:withRejecter:)
|
||||||
|
func signIn(_ secretKey: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
let result = try await react_native_pubky.signIn(secretKey: secretKey)
|
||||||
|
resolve(result)
|
||||||
|
} catch {
|
||||||
|
reject("signIn Error", "Failed to sign in", error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc(signOut:withResolver:withRejecter:)
|
||||||
|
func signOut(_ secretKey: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
let result = try await react_native_pubky.signOut(secretKey: secretKey)
|
||||||
|
resolve(result)
|
||||||
|
} catch {
|
||||||
|
reject("signOut Error", "Failed to sign out", error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc(put:content:withResolver:withRejecter:)
|
||||||
|
func put(_ url: String, content: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
let result = try await react_native_pubky.put(url: url, content: content)
|
||||||
|
resolve(result)
|
||||||
|
} catch {
|
||||||
|
reject("put Error", "Failed to put", error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc(get:withResolver:withRejecter:)
|
||||||
|
func get(_ url: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
let result = try await react_native_pubky.get(url: url)
|
||||||
|
resolve(result)
|
||||||
|
} catch {
|
||||||
|
reject("get Error", "Failed to get", error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -356,6 +356,68 @@ fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer {
|
|||||||
return seq
|
return seq
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private let UNIFFI_RUST_FUTURE_POLL_READY: Int8 = 0
|
||||||
|
private let UNIFFI_RUST_FUTURE_POLL_MAYBE_READY: Int8 = 1
|
||||||
|
|
||||||
|
fileprivate func uniffiRustCallAsync<F, T>(
|
||||||
|
rustFutureFunc: () -> UnsafeMutableRawPointer,
|
||||||
|
pollFunc: (UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> (),
|
||||||
|
completeFunc: (UnsafeMutableRawPointer, UnsafeMutablePointer<RustCallStatus>) -> F,
|
||||||
|
freeFunc: (UnsafeMutableRawPointer) -> (),
|
||||||
|
liftFunc: (F) throws -> T,
|
||||||
|
errorHandler: ((RustBuffer) throws -> Error)?
|
||||||
|
) async throws -> T {
|
||||||
|
// Make sure to call uniffiEnsureInitialized() since future creation doesn't have a
|
||||||
|
// RustCallStatus param, so doesn't use makeRustCall()
|
||||||
|
uniffiEnsureInitialized()
|
||||||
|
let rustFuture = rustFutureFunc()
|
||||||
|
defer {
|
||||||
|
freeFunc(rustFuture)
|
||||||
|
}
|
||||||
|
var pollResult: Int8;
|
||||||
|
repeat {
|
||||||
|
pollResult = await withUnsafeContinuation {
|
||||||
|
pollFunc(rustFuture, ContinuationHolder($0).toOpaque())
|
||||||
|
}
|
||||||
|
} while pollResult != UNIFFI_RUST_FUTURE_POLL_READY
|
||||||
|
|
||||||
|
return try liftFunc(makeRustCall(
|
||||||
|
{ completeFunc(rustFuture, $0) },
|
||||||
|
errorHandler: errorHandler
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Callback handlers for an async calls. These are invoked by Rust when the future is ready. They
|
||||||
|
// lift the return value or error and resume the suspended function.
|
||||||
|
fileprivate func uniffiFutureContinuationCallback(ptr: UnsafeMutableRawPointer, pollResult: Int8) {
|
||||||
|
ContinuationHolder.fromOpaque(ptr).resume(pollResult)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wraps UnsafeContinuation in a class so that we can use reference counting when passing it across
|
||||||
|
// the FFI
|
||||||
|
fileprivate class ContinuationHolder {
|
||||||
|
let continuation: UnsafeContinuation<Int8, Never>
|
||||||
|
|
||||||
|
init(_ continuation: UnsafeContinuation<Int8, Never>) {
|
||||||
|
self.continuation = continuation
|
||||||
|
}
|
||||||
|
|
||||||
|
func resume(_ pollResult: Int8) {
|
||||||
|
self.continuation.resume(returning: pollResult)
|
||||||
|
}
|
||||||
|
|
||||||
|
func toOpaque() -> UnsafeMutableRawPointer {
|
||||||
|
return Unmanaged<ContinuationHolder>.passRetained(self).toOpaque()
|
||||||
|
}
|
||||||
|
|
||||||
|
static func fromOpaque(_ ptr: UnsafeRawPointer) -> ContinuationHolder {
|
||||||
|
return Unmanaged<ContinuationHolder>.fromOpaque(ptr).takeRetainedValue()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate func uniffiInitContinuationCallback() {
|
||||||
|
ffi_pubkymobile_rust_future_continuation_callback_set(uniffiFutureContinuationCallback)
|
||||||
|
}
|
||||||
|
|
||||||
public func auth(url: String, secretKey: String) -> [String] {
|
public func auth(url: String, secretKey: String) -> [String] {
|
||||||
return try! FfiConverterSequenceString.lift(
|
return try! FfiConverterSequenceString.lift(
|
||||||
@@ -367,6 +429,24 @@ public func auth(url: String, secretKey: String) -> [String] {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func get(url: String) async -> [String] {
|
||||||
|
return try! await uniffiRustCallAsync(
|
||||||
|
rustFutureFunc: {
|
||||||
|
uniffi_pubkymobile_fn_func_get(
|
||||||
|
FfiConverterString.lower(url)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
pollFunc: ffi_pubkymobile_rust_future_poll_rust_buffer,
|
||||||
|
completeFunc: ffi_pubkymobile_rust_future_complete_rust_buffer,
|
||||||
|
freeFunc: ffi_pubkymobile_rust_future_free_rust_buffer,
|
||||||
|
liftFunc: FfiConverterSequenceString.lift,
|
||||||
|
errorHandler: nil
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public func parseAuthUrl(url: String) -> [String] {
|
public func parseAuthUrl(url: String) -> [String] {
|
||||||
return try! FfiConverterSequenceString.lift(
|
return try! FfiConverterSequenceString.lift(
|
||||||
try! rustCall() {
|
try! rustCall() {
|
||||||
@@ -387,6 +467,25 @@ public func publish(recordName: String, recordContent: String, secretKey: String
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func put(url: String, content: String) async -> [String] {
|
||||||
|
return try! await uniffiRustCallAsync(
|
||||||
|
rustFutureFunc: {
|
||||||
|
uniffi_pubkymobile_fn_func_put(
|
||||||
|
FfiConverterString.lower(url),
|
||||||
|
FfiConverterString.lower(content)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
pollFunc: ffi_pubkymobile_rust_future_poll_rust_buffer,
|
||||||
|
completeFunc: ffi_pubkymobile_rust_future_complete_rust_buffer,
|
||||||
|
freeFunc: ffi_pubkymobile_rust_future_free_rust_buffer,
|
||||||
|
liftFunc: FfiConverterSequenceString.lift,
|
||||||
|
errorHandler: nil
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public func resolve(publicKey: String) -> [String] {
|
public func resolve(publicKey: String) -> [String] {
|
||||||
return try! FfiConverterSequenceString.lift(
|
return try! FfiConverterSequenceString.lift(
|
||||||
try! rustCall() {
|
try! rustCall() {
|
||||||
@@ -396,6 +495,61 @@ public func resolve(publicKey: String) -> [String] {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func signIn(secretKey: String) async -> [String] {
|
||||||
|
return try! await uniffiRustCallAsync(
|
||||||
|
rustFutureFunc: {
|
||||||
|
uniffi_pubkymobile_fn_func_sign_in(
|
||||||
|
FfiConverterString.lower(secretKey)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
pollFunc: ffi_pubkymobile_rust_future_poll_rust_buffer,
|
||||||
|
completeFunc: ffi_pubkymobile_rust_future_complete_rust_buffer,
|
||||||
|
freeFunc: ffi_pubkymobile_rust_future_free_rust_buffer,
|
||||||
|
liftFunc: FfiConverterSequenceString.lift,
|
||||||
|
errorHandler: nil
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public func signOut(secretKey: String) async -> [String] {
|
||||||
|
return try! await uniffiRustCallAsync(
|
||||||
|
rustFutureFunc: {
|
||||||
|
uniffi_pubkymobile_fn_func_sign_out(
|
||||||
|
FfiConverterString.lower(secretKey)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
pollFunc: ffi_pubkymobile_rust_future_poll_rust_buffer,
|
||||||
|
completeFunc: ffi_pubkymobile_rust_future_complete_rust_buffer,
|
||||||
|
freeFunc: ffi_pubkymobile_rust_future_free_rust_buffer,
|
||||||
|
liftFunc: FfiConverterSequenceString.lift,
|
||||||
|
errorHandler: nil
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public func signUp(secretKey: String, homeserver: String) async -> [String] {
|
||||||
|
return try! await uniffiRustCallAsync(
|
||||||
|
rustFutureFunc: {
|
||||||
|
uniffi_pubkymobile_fn_func_sign_up(
|
||||||
|
FfiConverterString.lower(secretKey),
|
||||||
|
FfiConverterString.lower(homeserver)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
pollFunc: ffi_pubkymobile_rust_future_poll_rust_buffer,
|
||||||
|
completeFunc: ffi_pubkymobile_rust_future_complete_rust_buffer,
|
||||||
|
freeFunc: ffi_pubkymobile_rust_future_free_rust_buffer,
|
||||||
|
liftFunc: FfiConverterSequenceString.lift,
|
||||||
|
errorHandler: nil
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private enum InitializationResult {
|
private enum InitializationResult {
|
||||||
case ok
|
case ok
|
||||||
case contractVersionMismatch
|
case contractVersionMismatch
|
||||||
@@ -414,16 +568,32 @@ private var initializationResult: InitializationResult {
|
|||||||
if (uniffi_pubkymobile_checksum_func_auth() != 61378) {
|
if (uniffi_pubkymobile_checksum_func_auth() != 61378) {
|
||||||
return InitializationResult.apiChecksumMismatch
|
return InitializationResult.apiChecksumMismatch
|
||||||
}
|
}
|
||||||
|
if (uniffi_pubkymobile_checksum_func_get() != 5395) {
|
||||||
|
return InitializationResult.apiChecksumMismatch
|
||||||
|
}
|
||||||
if (uniffi_pubkymobile_checksum_func_parse_auth_url() != 29088) {
|
if (uniffi_pubkymobile_checksum_func_parse_auth_url() != 29088) {
|
||||||
return InitializationResult.apiChecksumMismatch
|
return InitializationResult.apiChecksumMismatch
|
||||||
}
|
}
|
||||||
if (uniffi_pubkymobile_checksum_func_publish() != 20156) {
|
if (uniffi_pubkymobile_checksum_func_publish() != 20156) {
|
||||||
return InitializationResult.apiChecksumMismatch
|
return InitializationResult.apiChecksumMismatch
|
||||||
}
|
}
|
||||||
|
if (uniffi_pubkymobile_checksum_func_put() != 47594) {
|
||||||
|
return InitializationResult.apiChecksumMismatch
|
||||||
|
}
|
||||||
if (uniffi_pubkymobile_checksum_func_resolve() != 18303) {
|
if (uniffi_pubkymobile_checksum_func_resolve() != 18303) {
|
||||||
return InitializationResult.apiChecksumMismatch
|
return InitializationResult.apiChecksumMismatch
|
||||||
}
|
}
|
||||||
|
if (uniffi_pubkymobile_checksum_func_sign_in() != 53969) {
|
||||||
|
return InitializationResult.apiChecksumMismatch
|
||||||
|
}
|
||||||
|
if (uniffi_pubkymobile_checksum_func_sign_out() != 32961) {
|
||||||
|
return InitializationResult.apiChecksumMismatch
|
||||||
|
}
|
||||||
|
if (uniffi_pubkymobile_checksum_func_sign_up() != 28083) {
|
||||||
|
return InitializationResult.apiChecksumMismatch
|
||||||
|
}
|
||||||
|
|
||||||
|
uniffiInitContinuationCallback()
|
||||||
return InitializationResult.ok
|
return InitializationResult.ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,18 +13,6 @@ pub async fn authorize(url: String, secret_key: String) -> Vec<String> {
|
|||||||
Err(error) => return create_response_vector(true, error),
|
Err(error) => return create_response_vector(true, error),
|
||||||
};
|
};
|
||||||
|
|
||||||
// const HOMESERVER: &'static str = "8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo";
|
|
||||||
// const URL: &'static str = "http://localhost:6287?relay=http://demo.httprelay.io/link";
|
|
||||||
// match client.signin(&keypair).await {
|
|
||||||
// Ok(_) => {}, // Signin successful, continue to send_auth_token
|
|
||||||
// Err(_) => {
|
|
||||||
// match client.signup(&keypair, &PublicKey::try_from(HOMESERVER).unwrap()).await {
|
|
||||||
// Ok(_) => {}, // Signup successful, continue to send_auth_token
|
|
||||||
// Err(error) => return create_response_vector(true, format!("Failed to signup: {}", error)),
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
let parsed_url = match Url::parse(&url) {
|
let parsed_url = match Url::parse(&url) {
|
||||||
Ok(url) => url,
|
Ok(url) => url,
|
||||||
Err(_) => return create_response_vector(true, "Failed to parse URL".to_string()),
|
Err(_) => return create_response_vector(true, "Failed to parse URL".to_string()),
|
||||||
|
|||||||
@@ -24,6 +24,85 @@ use pkarr::dns::ResourceRecord;
|
|||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use utils::*;
|
use utils::*;
|
||||||
|
|
||||||
|
#[uniffi::export]
|
||||||
|
pub async fn sign_up(secret_key: String, homeserver: String) -> Vec<String> {
|
||||||
|
let client = PubkyClient::testnet();
|
||||||
|
let keypair = match get_keypair_from_secret_key(&secret_key) {
|
||||||
|
Ok(keypair) => keypair,
|
||||||
|
Err(error) => return create_response_vector(true, error),
|
||||||
|
};
|
||||||
|
|
||||||
|
let homeserver_public_key = match PublicKey::try_from(homeserver) {
|
||||||
|
Ok(key) => key,
|
||||||
|
Err(error) => return create_response_vector(true, format!("Invalid homeserver public key: {}", error)),
|
||||||
|
};
|
||||||
|
|
||||||
|
match client.signup(&keypair, &homeserver_public_key).await {
|
||||||
|
Ok(_) => create_response_vector(false, "signup success".to_string()),
|
||||||
|
Err(error) => create_response_vector(true, format!("signup failure: {}", error)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[uniffi::export]
|
||||||
|
pub async fn sign_in(secret_key: String) -> Vec<String> {
|
||||||
|
let client = PubkyClient::testnet();
|
||||||
|
let keypair = match get_keypair_from_secret_key(&secret_key) {
|
||||||
|
Ok(keypair) => keypair,
|
||||||
|
Err(error) => return create_response_vector(true, error),
|
||||||
|
};
|
||||||
|
match client.signin(&keypair).await {
|
||||||
|
Ok(_) => create_response_vector(false, "Sign in success".to_string()),
|
||||||
|
Err(error) => {
|
||||||
|
create_response_vector(true, format!("Failed to sign in: {}", error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[uniffi::export]
|
||||||
|
pub async fn sign_out(secret_key: String) -> Vec<String> {
|
||||||
|
let client = PubkyClient::testnet();
|
||||||
|
let keypair = match get_keypair_from_secret_key(&secret_key) {
|
||||||
|
Ok(keypair) => keypair,
|
||||||
|
Err(error) => return create_response_vector(true, error),
|
||||||
|
};
|
||||||
|
match client.signout(&keypair.public_key()).await {
|
||||||
|
Ok(_) => create_response_vector(false, "Sign out success".to_string()),
|
||||||
|
Err(error) => {
|
||||||
|
create_response_vector(true, format!("Failed to sign out: {}", error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[uniffi::export]
|
||||||
|
pub async fn put(url: String, content: String) -> Vec<String> {
|
||||||
|
let client = PubkyClient::testnet();
|
||||||
|
let parsed_url = match Url::parse(&url) {
|
||||||
|
Ok(url) => url,
|
||||||
|
Err(_) => return create_response_vector(true, "Failed to parse URL".to_string()),
|
||||||
|
};
|
||||||
|
match client.put(parsed_url, &content.as_bytes()).await {
|
||||||
|
Ok(_) => create_response_vector(false, "Put success".to_string()),
|
||||||
|
Err(error) => {
|
||||||
|
create_response_vector(true, format!("Failed to put: {}", error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[uniffi::export]
|
||||||
|
pub async fn get(url: String) -> Vec<String> {
|
||||||
|
let client = PubkyClient::testnet();
|
||||||
|
let parsed_url = match Url::parse(&url) {
|
||||||
|
Ok(url) => url,
|
||||||
|
Err(_) => return create_response_vector(true, "Failed to parse URL".to_string()),
|
||||||
|
};
|
||||||
|
match client.get(parsed_url).await {
|
||||||
|
Ok(_) => create_response_vector(false, "Get success".to_string()),
|
||||||
|
Err(error) => {
|
||||||
|
create_response_vector(true, format!("Failed to get: {}", error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[uniffi::export]
|
#[uniffi::export]
|
||||||
fn resolve(public_key: String) -> Vec<String> {
|
fn resolve(public_key: String) -> Vec<String> {
|
||||||
let public_key = match public_key.as_str().try_into() {
|
let public_key = match public_key.as_str().try_into() {
|
||||||
|
|||||||
@@ -99,3 +99,69 @@ export async function resolve(publicKey: string): Promise<Result<IDNSPacket>> {
|
|||||||
return err(JSON.stringify(e));
|
return err(JSON.stringify(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function signUp(
|
||||||
|
secretKey: string,
|
||||||
|
homeserver: string
|
||||||
|
): Promise<Result<string[]>> {
|
||||||
|
try {
|
||||||
|
const res = await Pubky.signUp(secretKey, homeserver);
|
||||||
|
if (res[0] === 'error') {
|
||||||
|
return err(res[1]);
|
||||||
|
}
|
||||||
|
return ok(res[1]);
|
||||||
|
} catch (e) {
|
||||||
|
return err(JSON.stringify(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function signIn(secretKey: string): Promise<Result<string[]>> {
|
||||||
|
try {
|
||||||
|
const res = await Pubky.signIn(secretKey);
|
||||||
|
if (res[0] === 'error') {
|
||||||
|
return err(res[1]);
|
||||||
|
}
|
||||||
|
return ok(res[1]);
|
||||||
|
} catch (e) {
|
||||||
|
return err(JSON.stringify(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function signOut(secretKey: string): Promise<Result<string[]>> {
|
||||||
|
try {
|
||||||
|
const res = await Pubky.signOut(secretKey);
|
||||||
|
if (res[0] === 'error') {
|
||||||
|
return err(res[1]);
|
||||||
|
}
|
||||||
|
return ok(res[1]);
|
||||||
|
} catch (e) {
|
||||||
|
return err(JSON.stringify(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function get(url: string): Promise<Result<string[]>> {
|
||||||
|
try {
|
||||||
|
const res = await Pubky.get(url);
|
||||||
|
if (res[0] === 'error') {
|
||||||
|
return err(res[1]);
|
||||||
|
}
|
||||||
|
return ok(JSON.parse(res[1]));
|
||||||
|
} catch (e) {
|
||||||
|
return err(JSON.stringify(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function put(
|
||||||
|
url: string,
|
||||||
|
content: Object
|
||||||
|
): Promise<Result<string[]>> {
|
||||||
|
try {
|
||||||
|
const res = await Pubky.put(url, JSON.stringify(content));
|
||||||
|
if (res[0] === 'error') {
|
||||||
|
return err(res[1]);
|
||||||
|
}
|
||||||
|
return ok(res[1]);
|
||||||
|
} catch (e) {
|
||||||
|
return err(JSON.stringify(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user