refactor: add getHomeserver

Adds getHomeserver method.
Updates example app.
Bumps version to 0.10.2.
Updates README.md.
This commit is contained in:
coreyphillips
2025-03-22 12:41:30 -04:00
parent 45190e6a29
commit 989b7252a0
19 changed files with 1860 additions and 1644 deletions

View File

@@ -30,6 +30,7 @@ npm install @synonymdev/react-native-pubky
- [x] [getPublicKeyFromSecretKey](#getPublicKeyFromSecretKey): Get the public key string and uri from a secret key.
- [x] [create_recovery_file](#createRecoveryFile): Create a recovery file.
- [x] [decrypt_recovery_file](#decryptRecoveryFile): Decrypt a recovery file.
- [x] [getHomeserver](#getHomeserver): Get homeserver URL from a public key.
## Usage
### <a name="auth"></a>Auth
```js
@@ -283,6 +284,20 @@ if (sessionRes.isErr()) {
console.log(sessionRes.value);
```
### <a name="getHomeserver"></a>getHomeserver
```js
import { getHomeserver } from '@synonymdev/react-native-pubky';
const getHomeserverRes = await getHomeserver(
'z4e8s17cou9qmuwen8p1556jzhf1wktmzo6ijsfnri9c4hnrdfty' // Public Key
);
if (getHomeserverRes.isErr()) {
console.log(getHomeserverRes.error.message);
return;
}
console.log(getHomeserverRes.value);
```
### <a name="signOut"></a>signIn
```js
import { signOut } from '@synonymdev/react-native-pubky';
@@ -378,4 +393,3 @@ MIT
- Project created with: [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
- [Building an Android App with Rust Using UniFFI](https://forgen.tech/en/blog/post/building-an-android-app-with-rust-using-uniffi)
- [Building an iOS App with Rust Using UniFFI](https://forgen.tech/en/blog/post/building-an-ios-app-with-rust-using-uniffi)

View File

@@ -433,6 +433,25 @@ class PubkyModule(reactContext: ReactApplicationContext) :
}
}
@ReactMethod
fun getHomeserver(pubky: String, promise: Promise) {
CoroutineScope(Dispatchers.IO).launch {
try {
val result = getHomeserver(pubky)
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"
}

View File

@@ -402,6 +402,8 @@ internal interface _UniFFILib : Library {
): RustBuffer.ByValue
fun uniffi_pubkycore_fn_func_get(`url`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_pubkycore_fn_func_get_homeserver(`pubky`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_pubkycore_fn_func_get_public_key_from_secret_key(`secretKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_pubkycore_fn_func_get_signup_token(`homeserverPubky`: RustBuffer.ByValue,`adminPassword`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
@@ -562,6 +564,8 @@ internal interface _UniFFILib : Library {
): Short
fun uniffi_pubkycore_checksum_func_get(
): Short
fun uniffi_pubkycore_checksum_func_get_homeserver(
): Short
fun uniffi_pubkycore_checksum_func_get_public_key_from_secret_key(
): Short
fun uniffi_pubkycore_checksum_func_get_signup_token(
@@ -633,6 +637,9 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
if (lib.uniffi_pubkycore_checksum_func_get() != 6591.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_pubkycore_checksum_func_get_homeserver() != 40658.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_pubkycore_checksum_func_get_public_key_from_secret_key() != 40316.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
@@ -1248,6 +1255,14 @@ fun `get`(`url`: String): List<String> {
}
fun `getHomeserver`(`pubky`: String): List<String> {
return FfiConverterSequenceString.lift(
rustCall() { _status ->
_UniFFILib.INSTANCE.uniffi_pubkycore_fn_func_get_homeserver(FfiConverterString.lower(`pubky`),_status)
})
}
fun `getPublicKeyFromSecretKey`(`secretKey`: String): List<String> {
return FfiConverterSequenceString.lift(
rustCall() { _status ->

View File

@@ -1237,7 +1237,7 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-pubky (0.10.1):
- react-native-pubky (0.10.2):
- DoubleConversion
- glog
- hermes-engine
@@ -1757,7 +1757,7 @@ SPEC CHECKSUMS:
React-logger: 4072f39df335ca443932e0ccece41fbeb5ca8404
React-Mapbuffer: 714f2fae68edcabfc332b754e9fbaa8cfc68fdd4
React-microtasksnativemodule: 4943ad8f99be8ccf5a63329fa7d269816609df9e
react-native-pubky: 223d9be8cf0ca3f97fc4202779dc6629bc0bf8a2
react-native-pubky: b75611d5a4e02c66967555b7be2f837fc3628b8e
React-nativeconfig: 4a9543185905fe41014c06776bf126083795aed9
React-NativeModulesApple: 0506da59fc40d2e1e6e12a233db5e81c46face27
React-perflogger: 3bbb82f18e9ac29a1a6931568e99d6305ef4403b

View File

@@ -22,6 +22,7 @@ import {
session,
deleteFile,
getSignupToken,
getHomeserver,
} from '@synonymdev/react-native-pubky';
const HOMESERVER = '8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo';
@@ -190,6 +191,23 @@ export default function App() {
}
}}
/>
<Button
title={'getHomeserver'}
onPress={async (): Promise<void> => {
try {
const res = await getHomeserver(
PUBLIC_KEY // Public 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> => {

View File

@@ -80,6 +80,8 @@ RustBuffer uniffi_pubkycore_fn_func_generate_secret_key(RustCallStatus *_Nonnull
);
RustBuffer uniffi_pubkycore_fn_func_get(RustBuffer url, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_pubkycore_fn_func_get_homeserver(RustBuffer pubky, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_pubkycore_fn_func_get_public_key_from_secret_key(RustBuffer secret_key, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_pubkycore_fn_func_get_signup_token(RustBuffer homeserver_pubky, RustBuffer admin_password, RustCallStatus *_Nonnull out_status
@@ -246,6 +248,9 @@ uint16_t uniffi_pubkycore_checksum_func_generate_secret_key(void
);
uint16_t uniffi_pubkycore_checksum_func_get(void
);
uint16_t uniffi_pubkycore_checksum_func_get_homeserver(void
);
uint16_t uniffi_pubkycore_checksum_func_get_public_key_from_secret_key(void

View File

@@ -80,6 +80,8 @@ RustBuffer uniffi_pubkycore_fn_func_generate_secret_key(RustCallStatus *_Nonnull
);
RustBuffer uniffi_pubkycore_fn_func_get(RustBuffer url, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_pubkycore_fn_func_get_homeserver(RustBuffer pubky, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_pubkycore_fn_func_get_public_key_from_secret_key(RustBuffer secret_key, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_pubkycore_fn_func_get_signup_token(RustBuffer homeserver_pubky, RustBuffer admin_password, RustCallStatus *_Nonnull out_status
@@ -246,6 +248,9 @@ uint16_t uniffi_pubkycore_checksum_func_generate_secret_key(void
);
uint16_t uniffi_pubkycore_checksum_func_get(void
);
uint16_t uniffi_pubkycore_checksum_func_get_homeserver(void
);
uint16_t uniffi_pubkycore_checksum_func_get_public_key_from_secret_key(void

View File

@@ -100,6 +100,10 @@ RCT_EXTERN_METHOD(decryptRecoveryFile:(NSString *)recoveryFile
withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(getHomeserver:(NSString *)pubky
withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)
+ (BOOL)requiresMainQueueSetup
{
return NO;

View File

@@ -274,4 +274,16 @@ class Pubky: RCTEventEmitter {
reject("decryptRecoveryFile Error", "Failed to decrypt recovery file", error)
}
}
@objc(getHomeserver:withResolver:withRejecter:)
func getHomeserver(_ pubky: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
Task {
do {
let result = try await react_native_pubky.getHomeserver(pubky: pubky)
resolve(result)
} catch {
reject("getHomeserver Error", "Failed to get homeserver", error)
}
}
}
}

View File

@@ -689,6 +689,15 @@ public func get(url: String) -> [String] {
)
}
public func getHomeserver(pubky: String) -> [String] {
return try! FfiConverterSequenceString.lift(
try! rustCall() {
uniffi_pubkycore_fn_func_get_homeserver(
FfiConverterString.lower(pubky),$0)
}
)
}
public func getPublicKeyFromSecretKey(secretKey: String) -> [String] {
return try! FfiConverterSequenceString.lift(
try! rustCall() {
@@ -883,6 +892,9 @@ private var initializationResult: InitializationResult {
if (uniffi_pubkycore_checksum_func_get() != 6591) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_pubkycore_checksum_func_get_homeserver() != 40658) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_pubkycore_checksum_func_get_public_key_from_secret_key() != 40316) {
return InitializationResult.apiChecksumMismatch
}

View File

@@ -1,6 +1,6 @@
{
"name": "@synonymdev/react-native-pubky",
"version": "0.10.1",
"version": "0.10.2",
"description": "React Native Implementation of Pubky",
"source": "./src/index.tsx",
"main": "./lib/commonjs/index.js",

View File

@@ -374,3 +374,15 @@ export async function decryptRecoveryFile(
return err(JSON.stringify(e));
}
}
export async function getHomeserver(pubky: string): Promise<Result<string>> {
try {
const res = await Pubky.getHomeserver(pubky);
if (res[0] === 'error') {
return err(res[1]);
}
return ok(res[1]);
} catch (e) {
return err(JSON.stringify(e));
}
}

3380
yarn.lock

File diff suppressed because it is too large Load Diff