@synonymdev/react-native-pubky 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +57 -0
- package/android/build.gradle +101 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/pubky/PubkyModule.kt +43 -0
- package/android/src/main/java/com/pubky/PubkyPackage.kt +17 -0
- package/android/src/main/java/com/pubky/pubky.iml +11 -0
- package/android/src/main/java/uniffi/mobile/mobile.kt +688 -0
- package/android/src/main/jniLibs/arm64-v8a/libmobile.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libmobile.so +0 -0
- package/android/src/main/jniLibs/x86/libmobile.so +0 -0
- package/android/src/main/jniLibs/x86_64/libmobile.so +0 -0
- package/ios/Frameworks/Mobile.xcframework/Info.plist +47 -0
- package/ios/Frameworks/Mobile.xcframework/ios-arm64/Headers/mobileFFI.h +194 -0
- package/ios/Frameworks/Mobile.xcframework/ios-arm64/Headers/module.modulemap +6 -0
- package/ios/Frameworks/Mobile.xcframework/ios-arm64/libmobile.a +0 -0
- package/ios/Frameworks/Mobile.xcframework/ios-arm64-simulator/Headers/mobileFFI.h +194 -0
- package/ios/Frameworks/Mobile.xcframework/ios-arm64-simulator/Headers/module.modulemap +6 -0
- package/ios/Frameworks/Mobile.xcframework/ios-arm64-simulator/libmobile.a +0 -0
- package/ios/Pubky-Bridging-Header.h +2 -0
- package/ios/Pubky.mm +16 -0
- package/ios/Pubky.swift +16 -0
- package/ios/mobile.swift +484 -0
- package/lib/commonjs/index.js +25 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/index.js +21 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +3 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/index.d.ts +3 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/package.json +198 -0
- package/react-native-pubky.podspec +50 -0
- package/src/index.tsx +30 -0
package/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 pubky
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
6
|
+
in the Software without restriction, including without limitation the rights
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
9
|
+
furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
12
|
+
copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# react-native-pubky
|
2
|
+
|
3
|
+
React Native implementation of [pubky](https://github.com/pubky/pubky)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```sh
|
8
|
+
npm install @synonymdev/react-native-pubky
|
9
|
+
```
|
10
|
+
|
11
|
+
## Local Installation
|
12
|
+
|
13
|
+
1. Clone & npm install:
|
14
|
+
```sh
|
15
|
+
git clone git@github.com:pubky/react-native-pubky.git && cd react-native-pubky && npm i
|
16
|
+
```
|
17
|
+
2. Delete the `rust/pubky` directory to prevent a memory error (This step will be removed once pubky is public).
|
18
|
+
3. Yarn add it to your project:
|
19
|
+
```sh
|
20
|
+
yarn add path/to/react-native-pubky
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```js
|
26
|
+
import { auth } from '@synonymdev/react-native-pubky';
|
27
|
+
|
28
|
+
const authRes = await auth("pubkyAuthUrl", "secretKey");
|
29
|
+
if (authRes.isErr()) {
|
30
|
+
console.log(authRes.error.message);
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
console.log(authRes.value);
|
34
|
+
```
|
35
|
+
|
36
|
+
## Update Bindings
|
37
|
+
|
38
|
+
After making changes to any of the Rust files, the bindings will need to be updated. To do this, run the following command:
|
39
|
+
|
40
|
+
```sh
|
41
|
+
npm run update-bindings
|
42
|
+
```
|
43
|
+
|
44
|
+
Finally, ensure that `PubkyModule.kt`, `Pubky.swift`, `Pubky.mm` & `src/index.tsx` are updated accordingly based on the changes made to the Rust files.
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
MIT
|
49
|
+
|
50
|
+
---
|
51
|
+
|
52
|
+
## Resources
|
53
|
+
|
54
|
+
- Project created with: [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
55
|
+
- [Building an Android App with Rust Using UniFFI](https://forgen.tech/en/blog/post/building-an-android-app-with-rust-using-uniffi)
|
56
|
+
- [Building an iOS App with Rust Using UniFFI](https://forgen.tech/en/blog/post/building-an-ios-app-with-rust-using-uniffi)
|
57
|
+
|
@@ -0,0 +1,101 @@
|
|
1
|
+
buildscript {
|
2
|
+
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
|
3
|
+
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["Pubky_kotlinVersion"]
|
4
|
+
|
5
|
+
repositories {
|
6
|
+
google()
|
7
|
+
mavenCentral()
|
8
|
+
}
|
9
|
+
|
10
|
+
dependencies {
|
11
|
+
classpath "com.android.tools.build:gradle:7.2.1"
|
12
|
+
// noinspection DifferentKotlinGradleVersion
|
13
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
def reactNativeArchitectures() {
|
18
|
+
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
19
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
20
|
+
}
|
21
|
+
|
22
|
+
def isNewArchitectureEnabled() {
|
23
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
24
|
+
}
|
25
|
+
|
26
|
+
apply plugin: "com.android.library"
|
27
|
+
apply plugin: "kotlin-android"
|
28
|
+
|
29
|
+
if (isNewArchitectureEnabled()) {
|
30
|
+
apply plugin: "com.facebook.react"
|
31
|
+
}
|
32
|
+
|
33
|
+
def getExtOrDefault(name) {
|
34
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Pubky_" + name]
|
35
|
+
}
|
36
|
+
|
37
|
+
def getExtOrIntegerDefault(name) {
|
38
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Pubky_" + name]).toInteger()
|
39
|
+
}
|
40
|
+
|
41
|
+
def supportsNamespace() {
|
42
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
43
|
+
def major = parsed[0].toInteger()
|
44
|
+
def minor = parsed[1].toInteger()
|
45
|
+
|
46
|
+
// Namespace support was added in 7.3.0
|
47
|
+
return (major == 7 && minor >= 3) || major >= 8
|
48
|
+
}
|
49
|
+
|
50
|
+
android {
|
51
|
+
if (supportsNamespace()) {
|
52
|
+
namespace "com.pubky"
|
53
|
+
|
54
|
+
sourceSets {
|
55
|
+
main {
|
56
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
62
|
+
|
63
|
+
defaultConfig {
|
64
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
65
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
buildTypes {
|
70
|
+
release {
|
71
|
+
minifyEnabled false
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
lintOptions {
|
76
|
+
disable "GradleCompatible"
|
77
|
+
}
|
78
|
+
|
79
|
+
compileOptions {
|
80
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
81
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
repositories {
|
86
|
+
mavenCentral()
|
87
|
+
google()
|
88
|
+
}
|
89
|
+
|
90
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
91
|
+
|
92
|
+
dependencies {
|
93
|
+
// For < 0.71, this will be from the local maven repo
|
94
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
95
|
+
//noinspection GradleDynamicVersion
|
96
|
+
implementation "com.facebook.react:react-native:+"
|
97
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
98
|
+
implementation("net.java.dev.jna:jna:5.7.0@aar")
|
99
|
+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
|
100
|
+
}
|
101
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
package com.pubky
|
2
|
+
|
3
|
+
import com.facebook.react.bridge.Arguments
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
5
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
6
|
+
import com.facebook.react.bridge.ReactMethod
|
7
|
+
import com.facebook.react.bridge.Promise
|
8
|
+
import kotlinx.coroutines.CoroutineScope
|
9
|
+
import kotlinx.coroutines.Dispatchers
|
10
|
+
import kotlinx.coroutines.launch
|
11
|
+
import kotlinx.coroutines.withContext
|
12
|
+
import uniffi.mobile.auth
|
13
|
+
|
14
|
+
class PubkyModule(reactContext: ReactApplicationContext) :
|
15
|
+
ReactContextBaseJavaModule(reactContext) {
|
16
|
+
|
17
|
+
override fun getName(): String {
|
18
|
+
return NAME
|
19
|
+
}
|
20
|
+
|
21
|
+
@ReactMethod
|
22
|
+
fun auth(url: String, secretKey: String, promise: Promise) {
|
23
|
+
CoroutineScope(Dispatchers.IO).launch {
|
24
|
+
try {
|
25
|
+
val result = auth(url, secretKey)
|
26
|
+
val array = Arguments.createArray().apply {
|
27
|
+
result.forEach { pushString(it) }
|
28
|
+
}
|
29
|
+
withContext(Dispatchers.Main) {
|
30
|
+
promise.resolve(array)
|
31
|
+
}
|
32
|
+
} catch (e: Exception) {
|
33
|
+
withContext(Dispatchers.Main) {
|
34
|
+
promise.reject("Error", e.message)
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
companion object {
|
41
|
+
const val NAME = "Pubky"
|
42
|
+
}
|
43
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
package com.pubky
|
2
|
+
|
3
|
+
import com.facebook.react.ReactPackage
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
6
|
+
import com.facebook.react.uimanager.ViewManager
|
7
|
+
|
8
|
+
|
9
|
+
class PubkyPackage : ReactPackage {
|
10
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
11
|
+
return listOf(PubkyModule(reactContext))
|
12
|
+
}
|
13
|
+
|
14
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
15
|
+
return emptyList()
|
16
|
+
}
|
17
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="JAVA_MODULE" version="4">
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
4
|
+
<exclude-output />
|
5
|
+
<content url="file://$MODULE_DIR$">
|
6
|
+
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" packagePrefix="com.pubky" />
|
7
|
+
</content>
|
8
|
+
<orderEntry type="inheritedJdk" />
|
9
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
10
|
+
</component>
|
11
|
+
</module>
|