mirror of
https://github.com/aljazceru/react-native-pubky.git
synced 2025-12-17 22:54:29 +01:00
feat: republish homeserver
Adds republishHomeserver method. Upgrades bindings. Updates README.md.
This commit is contained in:
16
README.md
16
README.md
@@ -18,6 +18,7 @@ npm install @synonymdev/react-native-pubky
|
|||||||
- [x] [resolveHttps](#resolveHttps): Resolve HTTPS records.
|
- [x] [resolveHttps](#resolveHttps): Resolve HTTPS records.
|
||||||
- [x] [getSignupToken](#getSignupToken): Get a signup token from a homeserver with admin credentials.
|
- [x] [getSignupToken](#getSignupToken): Get a signup token from a homeserver with admin credentials.
|
||||||
- [x] [signUp](#signUp): Sign-up to a homeserver and update Pkarr accordingly, with optional signup token support.
|
- [x] [signUp](#signUp): Sign-up to a homeserver and update Pkarr accordingly, with optional signup token support.
|
||||||
|
- [x] [republishHomeserver](#republishHomeserver): Republish homeserver information to the DHT.
|
||||||
- [x] [signIn](#signIn): Sign-in to a homeserver.
|
- [x] [signIn](#signIn): Sign-in to a homeserver.
|
||||||
- [x] [session](#session): Check the current session for a given Pubky in its homeserver.
|
- [x] [session](#session): Check the current session for a given Pubky in its homeserver.
|
||||||
- [x] [signOut](#signOut): Sign-out from a homeserver.
|
- [x] [signOut](#signOut): Sign-out from a homeserver.
|
||||||
@@ -239,6 +240,21 @@ if (signUpWithTokenRes.isErr()) {
|
|||||||
console.log(signUpWithTokenRes.value);
|
console.log(signUpWithTokenRes.value);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <a name="republishHomeserver"></a>republishHomeserver
|
||||||
|
```js
|
||||||
|
import { republishHomeserver } from '@synonymdev/react-native-pubky';
|
||||||
|
|
||||||
|
const republishRes = await republishHomeserver(
|
||||||
|
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', // Secret Key
|
||||||
|
'pubky://8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo' // Homeserver
|
||||||
|
);
|
||||||
|
if (republishRes.isErr()) {
|
||||||
|
console.log(republishRes.error.message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(republishRes.value); // "Homeserver republished successfully"
|
||||||
|
```
|
||||||
|
|
||||||
### <a name="signIn"></a>signIn
|
### <a name="signIn"></a>signIn
|
||||||
```js
|
```js
|
||||||
import { signIn } from '@synonymdev/react-native-pubky';
|
import { signIn } from '@synonymdev/react-native-pubky';
|
||||||
|
|||||||
@@ -205,6 +205,25 @@ class PubkyModule(reactContext: ReactApplicationContext) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
fun republishHomeserver(secretKey: String, homeserver: String, promise: Promise) {
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
try {
|
||||||
|
val result = republishHomeserver(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
|
@ReactMethod
|
||||||
fun signIn(secretKey: String, promise: Promise) {
|
fun signIn(secretKey: String, promise: Promise) {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
|||||||
@@ -418,6 +418,8 @@ internal interface _UniFFILib : Library {
|
|||||||
): RustBuffer.ByValue
|
): RustBuffer.ByValue
|
||||||
fun uniffi_pubkycore_fn_func_remove_event_listener(_uniffi_out_err: RustCallStatus,
|
fun uniffi_pubkycore_fn_func_remove_event_listener(_uniffi_out_err: RustCallStatus,
|
||||||
): Unit
|
): Unit
|
||||||
|
fun uniffi_pubkycore_fn_func_republish_homeserver(`secretKey`: RustBuffer.ByValue,`homeserver`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
||||||
|
): RustBuffer.ByValue
|
||||||
fun uniffi_pubkycore_fn_func_resolve(`publicKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
fun uniffi_pubkycore_fn_func_resolve(`publicKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
||||||
): RustBuffer.ByValue
|
): RustBuffer.ByValue
|
||||||
fun uniffi_pubkycore_fn_func_resolve_https(`publicKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
fun uniffi_pubkycore_fn_func_resolve_https(`publicKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
||||||
@@ -576,6 +578,8 @@ internal interface _UniFFILib : Library {
|
|||||||
): Short
|
): Short
|
||||||
fun uniffi_pubkycore_checksum_func_remove_event_listener(
|
fun uniffi_pubkycore_checksum_func_remove_event_listener(
|
||||||
): Short
|
): Short
|
||||||
|
fun uniffi_pubkycore_checksum_func_republish_homeserver(
|
||||||
|
): Short
|
||||||
fun uniffi_pubkycore_checksum_func_resolve(
|
fun uniffi_pubkycore_checksum_func_resolve(
|
||||||
): Short
|
): Short
|
||||||
fun uniffi_pubkycore_checksum_func_resolve_https(
|
fun uniffi_pubkycore_checksum_func_resolve_https(
|
||||||
@@ -653,6 +657,9 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
|
|||||||
if (lib.uniffi_pubkycore_checksum_func_remove_event_listener() != 23534.toShort()) {
|
if (lib.uniffi_pubkycore_checksum_func_remove_event_listener() != 23534.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_republish_homeserver() != 63919.toShort()) {
|
||||||
|
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
||||||
|
}
|
||||||
if (lib.uniffi_pubkycore_checksum_func_resolve() != 34317.toShort()) {
|
if (lib.uniffi_pubkycore_checksum_func_resolve() != 34317.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")
|
||||||
}
|
}
|
||||||
@@ -1305,6 +1312,14 @@ fun `removeEventListener`() =
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fun `republishHomeserver`(`secretKey`: String, `homeserver`: String): List<String> {
|
||||||
|
return FfiConverterSequenceString.lift(
|
||||||
|
rustCall() { _status ->
|
||||||
|
_UniFFILib.INSTANCE.uniffi_pubkycore_fn_func_republish_homeserver(FfiConverterString.lower(`secretKey`),FfiConverterString.lower(`homeserver`),_status)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fun `resolve`(`publicKey`: String): List<String> {
|
fun `resolve`(`publicKey`: 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.
@@ -4,22 +4,6 @@
|
|||||||
<dict>
|
<dict>
|
||||||
<key>AvailableLibraries</key>
|
<key>AvailableLibraries</key>
|
||||||
<array>
|
<array>
|
||||||
<dict>
|
|
||||||
<key>BinaryPath</key>
|
|
||||||
<string>libpubkycore.a</string>
|
|
||||||
<key>HeadersPath</key>
|
|
||||||
<string>Headers</string>
|
|
||||||
<key>LibraryIdentifier</key>
|
|
||||||
<string>ios-arm64</string>
|
|
||||||
<key>LibraryPath</key>
|
|
||||||
<string>libpubkycore.a</string>
|
|
||||||
<key>SupportedArchitectures</key>
|
|
||||||
<array>
|
|
||||||
<string>arm64</string>
|
|
||||||
</array>
|
|
||||||
<key>SupportedPlatform</key>
|
|
||||||
<string>ios</string>
|
|
||||||
</dict>
|
|
||||||
<dict>
|
<dict>
|
||||||
<key>BinaryPath</key>
|
<key>BinaryPath</key>
|
||||||
<string>libpubkycore.a</string>
|
<string>libpubkycore.a</string>
|
||||||
@@ -38,6 +22,22 @@
|
|||||||
<key>SupportedPlatformVariant</key>
|
<key>SupportedPlatformVariant</key>
|
||||||
<string>simulator</string>
|
<string>simulator</string>
|
||||||
</dict>
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>BinaryPath</key>
|
||||||
|
<string>libpubkycore.a</string>
|
||||||
|
<key>HeadersPath</key>
|
||||||
|
<string>Headers</string>
|
||||||
|
<key>LibraryIdentifier</key>
|
||||||
|
<string>ios-arm64</string>
|
||||||
|
<key>LibraryPath</key>
|
||||||
|
<string>libpubkycore.a</string>
|
||||||
|
<key>SupportedArchitectures</key>
|
||||||
|
<array>
|
||||||
|
<string>arm64</string>
|
||||||
|
</array>
|
||||||
|
<key>SupportedPlatform</key>
|
||||||
|
<string>ios</string>
|
||||||
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>XFWK</string>
|
<string>XFWK</string>
|
||||||
|
|||||||
@@ -96,6 +96,8 @@ RustBuffer uniffi_pubkycore_fn_func_put(RustBuffer url, RustBuffer content, Rust
|
|||||||
);
|
);
|
||||||
void uniffi_pubkycore_fn_func_remove_event_listener(RustCallStatus *_Nonnull out_status
|
void uniffi_pubkycore_fn_func_remove_event_listener(RustCallStatus *_Nonnull out_status
|
||||||
|
|
||||||
|
);
|
||||||
|
RustBuffer uniffi_pubkycore_fn_func_republish_homeserver(RustBuffer secret_key, RustBuffer homeserver, RustCallStatus *_Nonnull out_status
|
||||||
);
|
);
|
||||||
RustBuffer uniffi_pubkycore_fn_func_resolve(RustBuffer public_key, RustCallStatus *_Nonnull out_status
|
RustBuffer uniffi_pubkycore_fn_func_resolve(RustBuffer public_key, RustCallStatus *_Nonnull out_status
|
||||||
);
|
);
|
||||||
@@ -268,6 +270,9 @@ uint16_t uniffi_pubkycore_checksum_func_put(void
|
|||||||
);
|
);
|
||||||
uint16_t uniffi_pubkycore_checksum_func_remove_event_listener(void
|
uint16_t uniffi_pubkycore_checksum_func_remove_event_listener(void
|
||||||
|
|
||||||
|
);
|
||||||
|
uint16_t uniffi_pubkycore_checksum_func_republish_homeserver(void
|
||||||
|
|
||||||
);
|
);
|
||||||
uint16_t uniffi_pubkycore_checksum_func_resolve(void
|
uint16_t uniffi_pubkycore_checksum_func_resolve(void
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -96,6 +96,8 @@ RustBuffer uniffi_pubkycore_fn_func_put(RustBuffer url, RustBuffer content, Rust
|
|||||||
);
|
);
|
||||||
void uniffi_pubkycore_fn_func_remove_event_listener(RustCallStatus *_Nonnull out_status
|
void uniffi_pubkycore_fn_func_remove_event_listener(RustCallStatus *_Nonnull out_status
|
||||||
|
|
||||||
|
);
|
||||||
|
RustBuffer uniffi_pubkycore_fn_func_republish_homeserver(RustBuffer secret_key, RustBuffer homeserver, RustCallStatus *_Nonnull out_status
|
||||||
);
|
);
|
||||||
RustBuffer uniffi_pubkycore_fn_func_resolve(RustBuffer public_key, RustCallStatus *_Nonnull out_status
|
RustBuffer uniffi_pubkycore_fn_func_resolve(RustBuffer public_key, RustCallStatus *_Nonnull out_status
|
||||||
);
|
);
|
||||||
@@ -268,6 +270,9 @@ uint16_t uniffi_pubkycore_checksum_func_put(void
|
|||||||
);
|
);
|
||||||
uint16_t uniffi_pubkycore_checksum_func_remove_event_listener(void
|
uint16_t uniffi_pubkycore_checksum_func_remove_event_listener(void
|
||||||
|
|
||||||
|
);
|
||||||
|
uint16_t uniffi_pubkycore_checksum_func_republish_homeserver(void
|
||||||
|
|
||||||
);
|
);
|
||||||
uint16_t uniffi_pubkycore_checksum_func_resolve(void
|
uint16_t uniffi_pubkycore_checksum_func_resolve(void
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -47,6 +47,11 @@ RCT_EXTERN_METHOD(signUp:(NSString *)secretKey
|
|||||||
withResolver:(RCTPromiseResolveBlock)resolve
|
withResolver:(RCTPromiseResolveBlock)resolve
|
||||||
withRejecter:(RCTPromiseRejectBlock)reject)
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
||||||
|
|
||||||
|
RCT_EXTERN_METHOD(republishHomeserver:(NSString *)secretKey
|
||||||
|
homeserver:(NSString *)homeserver
|
||||||
|
withResolver:(RCTPromiseResolveBlock)resolve
|
||||||
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
||||||
|
|
||||||
RCT_EXTERN_METHOD(signIn:(NSString *)secretKey
|
RCT_EXTERN_METHOD(signIn:(NSString *)secretKey
|
||||||
withResolver:(RCTPromiseResolveBlock)resolve
|
withResolver:(RCTPromiseResolveBlock)resolve
|
||||||
withRejecter:(RCTPromiseRejectBlock)reject)
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
||||||
|
|||||||
@@ -111,6 +111,18 @@ class Pubky: RCTEventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc(republishHomeserver:homeserver:withResolver:withRejecter:)
|
||||||
|
func republishHomeserver(_ secretKey: String, homeserver: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
let result = try await react_native_pubky.republishHomeserver(secretKey: secretKey, homeserver: homeserver)
|
||||||
|
resolve(result)
|
||||||
|
} catch {
|
||||||
|
reject("republishHomeserver Error", "Failed to republish homeserver", error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@objc(signIn:withResolver:withRejecter:)
|
@objc(signIn:withResolver:withRejecter:)
|
||||||
func signIn(_ secretKey: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
func signIn(_ secretKey: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
||||||
Task {
|
Task {
|
||||||
|
|||||||
@@ -766,6 +766,16 @@ public func removeEventListener() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public func republishHomeserver(secretKey: String, homeserver: String) -> [String] {
|
||||||
|
return try! FfiConverterSequenceString.lift(
|
||||||
|
try! rustCall() {
|
||||||
|
uniffi_pubkycore_fn_func_republish_homeserver(
|
||||||
|
FfiConverterString.lower(secretKey),
|
||||||
|
FfiConverterString.lower(homeserver),$0)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
public func resolve(publicKey: String) -> [String] {
|
public func resolve(publicKey: String) -> [String] {
|
||||||
return try! FfiConverterSequenceString.lift(
|
return try! FfiConverterSequenceString.lift(
|
||||||
try! rustCall() {
|
try! rustCall() {
|
||||||
@@ -897,6 +907,9 @@ private var initializationResult: InitializationResult {
|
|||||||
if (uniffi_pubkycore_checksum_func_remove_event_listener() != 23534) {
|
if (uniffi_pubkycore_checksum_func_remove_event_listener() != 23534) {
|
||||||
return InitializationResult.apiChecksumMismatch
|
return InitializationResult.apiChecksumMismatch
|
||||||
}
|
}
|
||||||
|
if (uniffi_pubkycore_checksum_func_republish_homeserver() != 63919) {
|
||||||
|
return InitializationResult.apiChecksumMismatch
|
||||||
|
}
|
||||||
if (uniffi_pubkycore_checksum_func_resolve() != 34317) {
|
if (uniffi_pubkycore_checksum_func_resolve() != 34317) {
|
||||||
return InitializationResult.apiChecksumMismatch
|
return InitializationResult.apiChecksumMismatch
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,6 +160,21 @@ export async function signUp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function republishHomeserver(
|
||||||
|
secretKey: string,
|
||||||
|
homeserver: string
|
||||||
|
): Promise<Result<string>> {
|
||||||
|
try {
|
||||||
|
const res = await Pubky.republishHomeserver(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<SessionInfo>> {
|
export async function signIn(secretKey: string): Promise<Result<SessionInfo>> {
|
||||||
try {
|
try {
|
||||||
const res = await Pubky.signIn(secretKey);
|
const res = await Pubky.signIn(secretKey);
|
||||||
|
|||||||
Reference in New Issue
Block a user