diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..3d45a3a --- /dev/null +++ b/.npmignore @@ -0,0 +1,2 @@ +example/ +rust/ diff --git a/android/src/main/java/com/pubky/PubkyModule.kt b/android/src/main/java/com/pubky/PubkyModule.kt index 95237a4..599087a 100644 --- a/android/src/main/java/com/pubky/PubkyModule.kt +++ b/android/src/main/java/com/pubky/PubkyModule.kt @@ -11,6 +11,8 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import uniffi.pubkymobile.auth import uniffi.pubkymobile.parseAuthUrl +import uniffi.pubkymobile.publish +import uniffi.pubkymobile.resolve class PubkyModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { @@ -51,6 +53,44 @@ class PubkyModule(reactContext: ReactApplicationContext) : } } + @ReactMethod + fun publish(recordName: String, recordContent: String, secretKey: String, promise: Promise) { + CoroutineScope(Dispatchers.IO).launch { + try { + val result = publish(recordName, recordContent, 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 resolve(publicKey: String, promise: Promise) { + CoroutineScope(Dispatchers.IO).launch { + try { + val result = resolve(publicKey) + 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" } diff --git a/android/src/main/java/uniffi/pubkymobile/pubkymobile.kt b/android/src/main/java/uniffi/pubkymobile/pubkymobile.kt index 1639053..6973574 100644 --- a/android/src/main/java/uniffi/pubkymobile/pubkymobile.kt +++ b/android/src/main/java/uniffi/pubkymobile/pubkymobile.kt @@ -385,6 +385,10 @@ internal interface _UniFFILib : Library { ): RustBuffer.ByValue fun uniffi_pubkymobile_fn_func_parse_auth_url(`url`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue + fun uniffi_pubkymobile_fn_func_publish(`recordName`: RustBuffer.ByValue,`recordContent`: RustBuffer.ByValue,`secretKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + ): RustBuffer.ByValue + fun uniffi_pubkymobile_fn_func_resolve(`publicKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + ): RustBuffer.ByValue fun ffi_pubkymobile_rustbuffer_alloc(`size`: Int,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue fun ffi_pubkymobile_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,_uniffi_out_err: RustCallStatus, @@ -503,6 +507,10 @@ internal interface _UniFFILib : Library { ): Short fun uniffi_pubkymobile_checksum_func_parse_auth_url( ): Short + fun uniffi_pubkymobile_checksum_func_publish( + ): Short + fun uniffi_pubkymobile_checksum_func_resolve( + ): Short fun ffi_pubkymobile_uniffi_contract_version( ): Int @@ -526,6 +534,12 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) { if (lib.uniffi_pubkymobile_checksum_func_parse_auth_url() != 29088.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } + if (lib.uniffi_pubkymobile_checksum_func_publish() != 20156.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_pubkymobile_checksum_func_resolve() != 18303.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } } // Async support @@ -628,3 +642,19 @@ fun `parseAuthUrl`(`url`: String): List { } +fun `publish`(`recordName`: String, `recordContent`: String, `secretKey`: String): List { + return FfiConverterSequenceString.lift( + rustCall() { _status -> + _UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_publish(FfiConverterString.lower(`recordName`),FfiConverterString.lower(`recordContent`),FfiConverterString.lower(`secretKey`),_status) +}) +} + + +fun `resolve`(`publicKey`: String): List { + return FfiConverterSequenceString.lift( + rustCall() { _status -> + _UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_resolve(FfiConverterString.lower(`publicKey`),_status) +}) +} + + diff --git a/android/src/main/jniLibs/arm64-v8a/libpubkymobile.so b/android/src/main/jniLibs/arm64-v8a/libpubkymobile.so index 8581dd5..5963a27 100755 Binary files a/android/src/main/jniLibs/arm64-v8a/libpubkymobile.so and b/android/src/main/jniLibs/arm64-v8a/libpubkymobile.so differ diff --git a/android/src/main/jniLibs/armeabi-v7a/libpubkymobile.so b/android/src/main/jniLibs/armeabi-v7a/libpubkymobile.so index b3c9957..f7d3b11 100755 Binary files a/android/src/main/jniLibs/armeabi-v7a/libpubkymobile.so and b/android/src/main/jniLibs/armeabi-v7a/libpubkymobile.so differ diff --git a/android/src/main/jniLibs/x86/libpubkymobile.so b/android/src/main/jniLibs/x86/libpubkymobile.so index 7b8a00d..4e4e245 100755 Binary files a/android/src/main/jniLibs/x86/libpubkymobile.so and b/android/src/main/jniLibs/x86/libpubkymobile.so differ diff --git a/android/src/main/jniLibs/x86_64/libpubkymobile.so b/android/src/main/jniLibs/x86_64/libpubkymobile.so index f1f7c1b..409b497 100755 Binary files a/android/src/main/jniLibs/x86_64/libpubkymobile.so and b/android/src/main/jniLibs/x86_64/libpubkymobile.so differ diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 0f5621f..421e917 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1237,7 +1237,7 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - react-native-pubky (0.2.3): + - react-native-pubky (0.3.0): - DoubleConversion - glog - hermes-engine @@ -1757,7 +1757,7 @@ SPEC CHECKSUMS: React-logger: 4072f39df335ca443932e0ccece41fbeb5ca8404 React-Mapbuffer: 714f2fae68edcabfc332b754e9fbaa8cfc68fdd4 React-microtasksnativemodule: 4943ad8f99be8ccf5a63329fa7d269816609df9e - react-native-pubky: 71108903c771df07c623ed14196f0c49d0d49810 + react-native-pubky: 9fd2633ee974bafa9b77e0cd59e2619a0d9d708d React-nativeconfig: 4a9543185905fe41014c06776bf126083795aed9 React-NativeModulesApple: 0506da59fc40d2e1e6e12a233db5e81c46face27 React-perflogger: 3bbb82f18e9ac29a1a6931568e99d6305ef4403b diff --git a/example/package.json b/example/package.json index 702efb9..8613227 100644 --- a/example/package.json +++ b/example/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "android": "react-native run-android", - "ios": "bundle install && cd ios && pod install && cd ../ && react-native run-ios", + "ios": "bundle install && cd ios && pod install && cd ../ && react-native run-ios --simulator \"iPhone 15 Pro\"", "start": "react-native start", "build:android": "react-native build-android --extra-params \"--no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a\"", "install-pods": "bundle install && cd ios && pod install && cd ../", diff --git a/example/src/App.tsx b/example/src/App.tsx index 052895a..d13bd08 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,5 +1,10 @@ import { StyleSheet, View, Button } from 'react-native'; -import { auth, parseAuthUrl } from '@synonymdev/react-native-pubky'; +import { + auth, + parseAuthUrl, + publish, + resolve, +} from '@synonymdev/react-native-pubky'; export default function App() { return ( @@ -9,7 +14,7 @@ export default function App() { onPress={async (): Promise => { try { const res = await auth( - 'pubkyauth:///?caps=/pub/pubky.app/:rw,/pub/foo.bar/file:r&secret=_K8yj2nS4naHWytpECCX48XhjhGc8KAhlpnuLUiHYBI&relay=http://localhost:52244/', + 'pubkyauth:///?caps=/pub/pubky.app/:rw,/pub/foo.bar/file:r&secret=U55XnoH6vsMCpx1pxHtt8fReVg4Brvu9C0gUBuw-Jkw&relay=http://167.86.102.121:4173/', 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' ); if (res.isErr()) { @@ -39,6 +44,42 @@ export default function App() { } }} /> +