mirror of
https://github.com/aljazceru/react-native-pubky.git
synced 2025-12-17 14:44:26 +01:00
refactor: add getHomeserver
Adds getHomeserver method. Updates example app. Bumps version to 0.10.2. Updates README.md.
This commit is contained in:
16
README.md
16
README.md
@@ -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] [getPublicKeyFromSecretKey](#getPublicKeyFromSecretKey): Get the public key string and uri from a secret key.
|
||||||
- [x] [create_recovery_file](#createRecoveryFile): Create a recovery file.
|
- [x] [create_recovery_file](#createRecoveryFile): Create a recovery file.
|
||||||
- [x] [decrypt_recovery_file](#decryptRecoveryFile): Decrypt a recovery file.
|
- [x] [decrypt_recovery_file](#decryptRecoveryFile): Decrypt a recovery file.
|
||||||
|
- [x] [getHomeserver](#getHomeserver): Get homeserver URL from a public key.
|
||||||
## Usage
|
## Usage
|
||||||
### <a name="auth"></a>Auth
|
### <a name="auth"></a>Auth
|
||||||
```js
|
```js
|
||||||
@@ -283,6 +284,20 @@ if (sessionRes.isErr()) {
|
|||||||
console.log(sessionRes.value);
|
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
|
### <a name="signOut"></a>signIn
|
||||||
```js
|
```js
|
||||||
import { signOut } from '@synonymdev/react-native-pubky';
|
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)
|
- 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 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)
|
- [Building an iOS App with Rust Using UniFFI](https://forgen.tech/en/blog/post/building-an-ios-app-with-rust-using-uniffi)
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
companion object {
|
||||||
const val NAME = "Pubky"
|
const val NAME = "Pubky"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -402,6 +402,8 @@ internal interface _UniFFILib : Library {
|
|||||||
): RustBuffer.ByValue
|
): RustBuffer.ByValue
|
||||||
fun uniffi_pubkycore_fn_func_get(`url`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
fun uniffi_pubkycore_fn_func_get(`url`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
||||||
): RustBuffer.ByValue
|
): 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,
|
fun uniffi_pubkycore_fn_func_get_public_key_from_secret_key(`secretKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
||||||
): RustBuffer.ByValue
|
): RustBuffer.ByValue
|
||||||
fun uniffi_pubkycore_fn_func_get_signup_token(`homeserverPubky`: RustBuffer.ByValue,`adminPassword`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
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
|
): Short
|
||||||
fun uniffi_pubkycore_checksum_func_get(
|
fun uniffi_pubkycore_checksum_func_get(
|
||||||
): Short
|
): Short
|
||||||
|
fun uniffi_pubkycore_checksum_func_get_homeserver(
|
||||||
|
): Short
|
||||||
fun uniffi_pubkycore_checksum_func_get_public_key_from_secret_key(
|
fun uniffi_pubkycore_checksum_func_get_public_key_from_secret_key(
|
||||||
): Short
|
): Short
|
||||||
fun uniffi_pubkycore_checksum_func_get_signup_token(
|
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()) {
|
if (lib.uniffi_pubkycore_checksum_func_get() != 6591.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_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()) {
|
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")
|
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> {
|
fun `getPublicKeyFromSecretKey`(`secretKey`: String): List<String> {
|
||||||
return FfiConverterSequenceString.lift(
|
return FfiConverterSequenceString.lift(
|
||||||
rustCall() { _status ->
|
rustCall() { _status ->
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1237,7 +1237,7 @@ PODS:
|
|||||||
- ReactCommon/turbomodule/bridging
|
- ReactCommon/turbomodule/bridging
|
||||||
- ReactCommon/turbomodule/core
|
- ReactCommon/turbomodule/core
|
||||||
- Yoga
|
- Yoga
|
||||||
- react-native-pubky (0.10.1):
|
- react-native-pubky (0.10.2):
|
||||||
- DoubleConversion
|
- DoubleConversion
|
||||||
- glog
|
- glog
|
||||||
- hermes-engine
|
- hermes-engine
|
||||||
@@ -1757,7 +1757,7 @@ SPEC CHECKSUMS:
|
|||||||
React-logger: 4072f39df335ca443932e0ccece41fbeb5ca8404
|
React-logger: 4072f39df335ca443932e0ccece41fbeb5ca8404
|
||||||
React-Mapbuffer: 714f2fae68edcabfc332b754e9fbaa8cfc68fdd4
|
React-Mapbuffer: 714f2fae68edcabfc332b754e9fbaa8cfc68fdd4
|
||||||
React-microtasksnativemodule: 4943ad8f99be8ccf5a63329fa7d269816609df9e
|
React-microtasksnativemodule: 4943ad8f99be8ccf5a63329fa7d269816609df9e
|
||||||
react-native-pubky: 223d9be8cf0ca3f97fc4202779dc6629bc0bf8a2
|
react-native-pubky: b75611d5a4e02c66967555b7be2f837fc3628b8e
|
||||||
React-nativeconfig: 4a9543185905fe41014c06776bf126083795aed9
|
React-nativeconfig: 4a9543185905fe41014c06776bf126083795aed9
|
||||||
React-NativeModulesApple: 0506da59fc40d2e1e6e12a233db5e81c46face27
|
React-NativeModulesApple: 0506da59fc40d2e1e6e12a233db5e81c46face27
|
||||||
React-perflogger: 3bbb82f18e9ac29a1a6931568e99d6305ef4403b
|
React-perflogger: 3bbb82f18e9ac29a1a6931568e99d6305ef4403b
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import {
|
|||||||
session,
|
session,
|
||||||
deleteFile,
|
deleteFile,
|
||||||
getSignupToken,
|
getSignupToken,
|
||||||
|
getHomeserver,
|
||||||
} from '@synonymdev/react-native-pubky';
|
} from '@synonymdev/react-native-pubky';
|
||||||
|
|
||||||
const HOMESERVER = '8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo';
|
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
|
<Button
|
||||||
title={'signout'}
|
title={'signout'}
|
||||||
onPress={async (): Promise<void> => {
|
onPress={async (): Promise<void> => {
|
||||||
|
|||||||
@@ -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(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_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
|
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(void
|
||||||
|
|
||||||
|
);
|
||||||
|
uint16_t uniffi_pubkycore_checksum_func_get_homeserver(void
|
||||||
|
|
||||||
);
|
);
|
||||||
uint16_t uniffi_pubkycore_checksum_func_get_public_key_from_secret_key(void
|
uint16_t uniffi_pubkycore_checksum_func_get_public_key_from_secret_key(void
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -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(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_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
|
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(void
|
||||||
|
|
||||||
|
);
|
||||||
|
uint16_t uniffi_pubkycore_checksum_func_get_homeserver(void
|
||||||
|
|
||||||
);
|
);
|
||||||
uint16_t uniffi_pubkycore_checksum_func_get_public_key_from_secret_key(void
|
uint16_t uniffi_pubkycore_checksum_func_get_public_key_from_secret_key(void
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -100,6 +100,10 @@ RCT_EXTERN_METHOD(decryptRecoveryFile:(NSString *)recoveryFile
|
|||||||
withResolver:(RCTPromiseResolveBlock)resolve
|
withResolver:(RCTPromiseResolveBlock)resolve
|
||||||
withRejecter:(RCTPromiseRejectBlock)reject)
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
||||||
|
|
||||||
|
RCT_EXTERN_METHOD(getHomeserver:(NSString *)pubky
|
||||||
|
withResolver:(RCTPromiseResolveBlock)resolve
|
||||||
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
||||||
|
|
||||||
+ (BOOL)requiresMainQueueSetup
|
+ (BOOL)requiresMainQueueSetup
|
||||||
{
|
{
|
||||||
return NO;
|
return NO;
|
||||||
|
|||||||
@@ -274,4 +274,16 @@ class Pubky: RCTEventEmitter {
|
|||||||
reject("decryptRecoveryFile Error", "Failed to decrypt recovery file", error)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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] {
|
public func getPublicKeyFromSecretKey(secretKey: String) -> [String] {
|
||||||
return try! FfiConverterSequenceString.lift(
|
return try! FfiConverterSequenceString.lift(
|
||||||
try! rustCall() {
|
try! rustCall() {
|
||||||
@@ -883,6 +892,9 @@ private var initializationResult: InitializationResult {
|
|||||||
if (uniffi_pubkycore_checksum_func_get() != 6591) {
|
if (uniffi_pubkycore_checksum_func_get() != 6591) {
|
||||||
return InitializationResult.apiChecksumMismatch
|
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) {
|
if (uniffi_pubkycore_checksum_func_get_public_key_from_secret_key() != 40316) {
|
||||||
return InitializationResult.apiChecksumMismatch
|
return InitializationResult.apiChecksumMismatch
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@synonymdev/react-native-pubky",
|
"name": "@synonymdev/react-native-pubky",
|
||||||
"version": "0.10.1",
|
"version": "0.10.2",
|
||||||
"description": "React Native Implementation of Pubky",
|
"description": "React Native Implementation of Pubky",
|
||||||
"source": "./src/index.tsx",
|
"source": "./src/index.tsx",
|
||||||
"main": "./lib/commonjs/index.js",
|
"main": "./lib/commonjs/index.js",
|
||||||
|
|||||||
@@ -374,3 +374,15 @@ export async function decryptRecoveryFile(
|
|||||||
return err(JSON.stringify(e));
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user