diff --git a/README.md b/README.md index c4613e1..7cc99ec 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,9 @@ npm install @synonymdev/react-native-pubky - [x] [list](#list): Returns a list of Pubky URLs of the files in the path of the `url` provided. - [x] [generateSecretKey](#generateSecretKey): Generate 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] [decrypt_recovery_file](#decryptRecoveryFile): Decrypt a recovery file. +- ### Methods to be Implemented - [ ] getProfile: Retrieve the profile of a user. - [ ] editProfile: Submit changes to the specified profile. @@ -225,6 +228,36 @@ if (signOutRes.isErr()) { console.log(signOutRes.value); ``` +### createRecoveryFile +```js +import { createRecoveryFile } from '@synonymdev/react-native-pubky'; + +const createRecoveryFileRes = await createRecoveryFile( + 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', // Secret Key + 'passphrase', // Passphrase +); +if (createRecoveryFileRes.isErr()) { + console.log(createRecoveryFileRes.error.message); + return; +} +console.log(createRecoveryFileRes.value); +``` + +### decryptRecoveryFile +```js +import { decryptRecoveryFile } from '@synonymdev/react-native-pubky'; + +const decryptRecoveryFileRes = await decryptRecoveryFile( + 'cHVia3kub3JnL3JlY292ZXJ5CkZRt1NHIjxyTo0whSSgTgNrH56MPpGrSxvAQSE0x5FeklVJpNJqcNP4zjdwW/OpdBOsEC1qZ5MI/mcEUKFKVAEZwikdclsLZg==', // Recovery File + 'passphrase', // Passphrase +); +if (decryptRecoveryFileRes.isErr()) { + console.log(decryptRecoveryFileRes.error.message); + return; +} +console.log(decryptRecoveryFileRes.value); +``` + ## Local Installation 1. Clone & npm install: diff --git a/android/src/main/java/com/pubky/PubkyModule.kt b/android/src/main/java/com/pubky/PubkyModule.kt index b9f9e51..d5ac9d8 100644 --- a/android/src/main/java/com/pubky/PubkyModule.kt +++ b/android/src/main/java/com/pubky/PubkyModule.kt @@ -278,6 +278,32 @@ class PubkyModule(reactContext: ReactApplicationContext) : } } +@ReactMethod +fun createRecoveryFile(secretKey: String, passphrase: String, promise: Promise) { + try { + val result = createRecoveryFile(secretKey, passphrase) + val array = Arguments.createArray().apply { + result.forEach { pushString(it) } + } + promise.resolve(array) + } catch (e: Exception) { + promise.reject("Error", e.message) + } +} + +@ReactMethod +fun decryptRecoveryFile(recoveryFile: String, passphrase: String, promise: Promise) { + try { + val result = decryptRecoveryFile(recoveryFile, passphrase) + val array = Arguments.createArray().apply { + result.forEach { pushString(it) } + } + promise.resolve(array) + } catch (e: Exception) { + promise.reject("Error", e.message) + } +} + companion object { const val NAME = "Pubky" } diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 8080bf3..96f43ec 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.7.1): + - react-native-pubky (0.8.0): - DoubleConversion - glog - hermes-engine @@ -1757,7 +1757,7 @@ SPEC CHECKSUMS: React-logger: 4072f39df335ca443932e0ccece41fbeb5ca8404 React-Mapbuffer: 714f2fae68edcabfc332b754e9fbaa8cfc68fdd4 React-microtasksnativemodule: 4943ad8f99be8ccf5a63329fa7d269816609df9e - react-native-pubky: 1740252f1e510886c4239242d0b731bc4d96b91b + react-native-pubky: 1da8f3324a665ecf4495652efe0e67820a22f3a2 React-nativeconfig: 4a9543185905fe41014c06776bf126083795aed9 React-NativeModulesApple: 0506da59fc40d2e1e6e12a233db5e81c46face27 React-perflogger: 3bbb82f18e9ac29a1a6931568e99d6305ef4403b diff --git a/example/src/App.tsx b/example/src/App.tsx index a395143..fcd64a0 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -14,6 +14,8 @@ import { list, generateSecretKey, getPublicKeyFromSecretKey, + decryptRecoveryFile, + createRecoveryFile, } from '@synonymdev/react-native-pubky'; const HOMESERVER = '8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo'; @@ -268,6 +270,44 @@ export default function App() { } }} /> + +