@synonymdev/react-native-pubky 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +13 -1
- package/android/src/main/java/com/pubky/PubkyModule.kt +14 -0
- package/android/src/main/java/uniffi/pubkymobile/pubkymobile.kt +22 -65
- package/android/src/main/jniLibs/arm64-v8a/libpubkymobile.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libpubkymobile.so +0 -0
- package/android/src/main/jniLibs/x86/libpubkymobile.so +0 -0
- package/android/src/main/jniLibs/x86_64/libpubkymobile.so +0 -0
- package/ios/Frameworks/PubkyMobile.xcframework/ios-arm64/Headers/pubkymobileFFI.h +6 -1
- package/ios/Frameworks/PubkyMobile.xcframework/ios-arm64/libpubkymobile.a +0 -0
- package/ios/Frameworks/PubkyMobile.xcframework/ios-arm64-simulator/Headers/pubkymobileFFI.h +6 -1
- package/ios/Frameworks/PubkyMobile.xcframework/ios-arm64-simulator/libpubkymobile.a +0 -0
- package/ios/Pubky.mm +4 -0
- package/ios/Pubky.swift +22 -11
- package/ios/pubkymobile.swift +16 -76
- package/lib/commonjs/index.js +13 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +12 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +11 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +11 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/index.tsx +26 -0
package/README.md
CHANGED
@@ -11,8 +11,8 @@ npm install @synonymdev/react-native-pubky
|
|
11
11
|
## Implementation Status
|
12
12
|
### Implemented Methods
|
13
13
|
- [x] [auth](#auth): Authentication functionality.
|
14
|
+
- [x] [parseAuthUrl](#parseAuthUrl): Method to decode an authUrl.
|
14
15
|
### Methods to be Implemented
|
15
|
-
- [ ] parseAuthUrl: Method to decode an authUrl.
|
16
16
|
- [ ] publish: Functionality to publish content.
|
17
17
|
- [ ] resolve: Functionality to resolve content.
|
18
18
|
- [ ] signIn: Functionality to sign in.
|
@@ -31,6 +31,18 @@ if (authRes.isErr()) {
|
|
31
31
|
}
|
32
32
|
console.log(authRes.value);
|
33
33
|
```
|
34
|
+
### <a name="parseAuthUrl"></a>parseAuthUrl
|
35
|
+
```js
|
36
|
+
import { parseAuthUrl } from '@synonymdev/react-native-pubky';
|
37
|
+
|
38
|
+
const pubkyAuthUrl = 'pubkyauth:///?relay=https://demo.httprelay.io/link&capabilities=/pub/pubky.app:rw,/pub/example.com/nested:rw&secret=FyzJ3gJ1W7boyFZC1Do9fYrRmDNgCLNRwEu_gaBgPUA';
|
39
|
+
const parseRes = await parseAuthUrl(pubkyAuthUrl);
|
40
|
+
if (parseRes.isErr()) {
|
41
|
+
console.log(parseRes.error.message);
|
42
|
+
return;
|
43
|
+
}
|
44
|
+
console.log(parseRes.value);
|
45
|
+
```
|
34
46
|
|
35
47
|
## Local Installation
|
36
48
|
|
@@ -10,6 +10,7 @@ import kotlinx.coroutines.Dispatchers
|
|
10
10
|
import kotlinx.coroutines.launch
|
11
11
|
import kotlinx.coroutines.withContext
|
12
12
|
import uniffi.pubkymobile.auth
|
13
|
+
import uniffi.pubkymobile.parseAuthUrl
|
13
14
|
|
14
15
|
class PubkyModule(reactContext: ReactApplicationContext) :
|
15
16
|
ReactContextBaseJavaModule(reactContext) {
|
@@ -37,6 +38,19 @@ class PubkyModule(reactContext: ReactApplicationContext) :
|
|
37
38
|
}
|
38
39
|
}
|
39
40
|
|
41
|
+
@ReactMethod
|
42
|
+
fun parseAuthUrl(url: String, promise: Promise) {
|
43
|
+
try {
|
44
|
+
val result = parseAuthUrl(url)
|
45
|
+
val array = Arguments.createArray().apply {
|
46
|
+
result.forEach { pushString(it) }
|
47
|
+
}
|
48
|
+
promise.resolve(array)
|
49
|
+
} catch (e: Exception) {
|
50
|
+
promise.reject("Error", e.message)
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
40
54
|
companion object {
|
41
55
|
const val NAME = "Pubky"
|
42
56
|
}
|
@@ -29,9 +29,6 @@ import java.nio.ByteOrder
|
|
29
29
|
import java.nio.CharBuffer
|
30
30
|
import java.nio.charset.CodingErrorAction
|
31
31
|
import java.util.concurrent.ConcurrentHashMap
|
32
|
-
import kotlin.coroutines.resume
|
33
|
-
import kotlinx.coroutines.CancellableContinuation
|
34
|
-
import kotlinx.coroutines.suspendCancellableCoroutine
|
35
32
|
|
36
33
|
// This is a helper for safely working with byte buffers returned from the Rust code.
|
37
34
|
// A rust-owned buffer is represented by its capacity, its current length, and a
|
@@ -380,13 +377,14 @@ internal interface _UniFFILib : Library {
|
|
380
377
|
.also { lib: _UniFFILib ->
|
381
378
|
uniffiCheckContractApiVersion(lib)
|
382
379
|
uniffiCheckApiChecksums(lib)
|
383
|
-
uniffiRustFutureContinuationCallback.register(lib)
|
384
380
|
}
|
385
381
|
}
|
386
382
|
}
|
387
383
|
|
388
|
-
fun uniffi_pubkymobile_fn_func_auth(`url`: RustBuffer.ByValue,`secretKey`: RustBuffer.ByValue,
|
389
|
-
):
|
384
|
+
fun uniffi_pubkymobile_fn_func_auth(`url`: RustBuffer.ByValue,`secretKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
385
|
+
): RustBuffer.ByValue
|
386
|
+
fun uniffi_pubkymobile_fn_func_parse_auth_url(`url`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
387
|
+
): RustBuffer.ByValue
|
390
388
|
fun ffi_pubkymobile_rustbuffer_alloc(`size`: Int,_uniffi_out_err: RustCallStatus,
|
391
389
|
): RustBuffer.ByValue
|
392
390
|
fun ffi_pubkymobile_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,_uniffi_out_err: RustCallStatus,
|
@@ -503,6 +501,8 @@ internal interface _UniFFILib : Library {
|
|
503
501
|
): Unit
|
504
502
|
fun uniffi_pubkymobile_checksum_func_auth(
|
505
503
|
): Short
|
504
|
+
fun uniffi_pubkymobile_checksum_func_parse_auth_url(
|
505
|
+
): Short
|
506
506
|
fun ffi_pubkymobile_uniffi_contract_version(
|
507
507
|
): Int
|
508
508
|
|
@@ -520,56 +520,15 @@ private fun uniffiCheckContractApiVersion(lib: _UniFFILib) {
|
|
520
520
|
|
521
521
|
@Suppress("UNUSED_PARAMETER")
|
522
522
|
private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
|
523
|
-
if (lib.uniffi_pubkymobile_checksum_func_auth() !=
|
523
|
+
if (lib.uniffi_pubkymobile_checksum_func_auth() != 61378.toShort()) {
|
524
524
|
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
525
525
|
}
|
526
|
-
|
527
|
-
|
528
|
-
// Async support
|
529
|
-
// Async return type handlers
|
530
|
-
|
531
|
-
internal const val UNIFFI_RUST_FUTURE_POLL_READY = 0.toShort()
|
532
|
-
internal const val UNIFFI_RUST_FUTURE_POLL_MAYBE_READY = 1.toShort()
|
533
|
-
|
534
|
-
internal val uniffiContinuationHandleMap = UniFfiHandleMap<CancellableContinuation<Short>>()
|
535
|
-
|
536
|
-
// FFI type for Rust future continuations
|
537
|
-
internal object uniffiRustFutureContinuationCallback: UniFffiRustFutureContinuationCallbackType {
|
538
|
-
override fun callback(continuationHandle: USize, pollResult: Short) {
|
539
|
-
uniffiContinuationHandleMap.remove(continuationHandle)?.resume(pollResult)
|
540
|
-
}
|
541
|
-
|
542
|
-
internal fun register(lib: _UniFFILib) {
|
543
|
-
lib.ffi_pubkymobile_rust_future_continuation_callback_set(this)
|
544
|
-
}
|
545
|
-
}
|
546
|
-
|
547
|
-
internal suspend fun<T, F, E: Exception> uniffiRustCallAsync(
|
548
|
-
rustFuture: Pointer,
|
549
|
-
pollFunc: (Pointer, USize) -> Unit,
|
550
|
-
completeFunc: (Pointer, RustCallStatus) -> F,
|
551
|
-
freeFunc: (Pointer) -> Unit,
|
552
|
-
liftFunc: (F) -> T,
|
553
|
-
errorHandler: CallStatusErrorHandler<E>
|
554
|
-
): T {
|
555
|
-
try {
|
556
|
-
do {
|
557
|
-
val pollResult = suspendCancellableCoroutine<Short> { continuation ->
|
558
|
-
pollFunc(
|
559
|
-
rustFuture,
|
560
|
-
uniffiContinuationHandleMap.insert(continuation)
|
561
|
-
)
|
562
|
-
}
|
563
|
-
} while (pollResult != UNIFFI_RUST_FUTURE_POLL_READY);
|
564
|
-
|
565
|
-
return liftFunc(
|
566
|
-
rustCallWithError(errorHandler, { status -> completeFunc(rustFuture, status) })
|
567
|
-
)
|
568
|
-
} finally {
|
569
|
-
freeFunc(rustFuture)
|
526
|
+
if (lib.uniffi_pubkymobile_checksum_func_parse_auth_url() != 29088.toShort()) {
|
527
|
+
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
570
528
|
}
|
571
529
|
}
|
572
530
|
|
531
|
+
// Async support
|
573
532
|
|
574
533
|
// Public interface members begin here.
|
575
534
|
|
@@ -653,21 +612,19 @@ public object FfiConverterSequenceString: FfiConverterRustBuffer<List<String>> {
|
|
653
612
|
}
|
654
613
|
}
|
655
614
|
|
615
|
+
fun `auth`(`url`: String, `secretKey`: String): List<String> {
|
616
|
+
return FfiConverterSequenceString.lift(
|
617
|
+
rustCall() { _status ->
|
618
|
+
_UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_auth(FfiConverterString.lower(`url`),FfiConverterString.lower(`secretKey`),_status)
|
619
|
+
})
|
620
|
+
}
|
656
621
|
|
657
622
|
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
_UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_auth(FfiConverterString.lower(`url`),FfiConverterString.lower(`secretKey`),),
|
664
|
-
{ future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_poll_rust_buffer(future, continuation) },
|
665
|
-
{ future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_complete_rust_buffer(future, continuation) },
|
666
|
-
{ future -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_free_rust_buffer(future) },
|
667
|
-
// lift function
|
668
|
-
{ FfiConverterSequenceString.lift(it) },
|
669
|
-
// Error FFI converter
|
670
|
-
NullCallStatusErrorHandler,
|
671
|
-
)
|
623
|
+
fun `parseAuthUrl`(`url`: String): List<String> {
|
624
|
+
return FfiConverterSequenceString.lift(
|
625
|
+
rustCall() { _status ->
|
626
|
+
_UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_parse_auth_url(FfiConverterString.lower(`url`),_status)
|
627
|
+
})
|
672
628
|
}
|
673
629
|
|
630
|
+
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -63,7 +63,9 @@ typedef struct RustCallStatus {
|
|
63
63
|
typedef void (*UniFfiRustFutureContinuation)(void * _Nonnull, int8_t);
|
64
64
|
|
65
65
|
// Scaffolding functions
|
66
|
-
|
66
|
+
RustBuffer uniffi_pubkymobile_fn_func_auth(RustBuffer url, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
|
67
|
+
);
|
68
|
+
RustBuffer uniffi_pubkymobile_fn_func_parse_auth_url(RustBuffer url, RustCallStatus *_Nonnull out_status
|
67
69
|
);
|
68
70
|
RustBuffer ffi_pubkymobile_rustbuffer_alloc(int32_t size, RustCallStatus *_Nonnull out_status
|
69
71
|
);
|
@@ -181,6 +183,9 @@ void ffi_pubkymobile_rust_future_complete_void(void* _Nonnull handle, RustCallSt
|
|
181
183
|
);
|
182
184
|
uint16_t uniffi_pubkymobile_checksum_func_auth(void
|
183
185
|
|
186
|
+
);
|
187
|
+
uint16_t uniffi_pubkymobile_checksum_func_parse_auth_url(void
|
188
|
+
|
184
189
|
);
|
185
190
|
uint32_t ffi_pubkymobile_uniffi_contract_version(void
|
186
191
|
|
Binary file
|
@@ -63,7 +63,9 @@ typedef struct RustCallStatus {
|
|
63
63
|
typedef void (*UniFfiRustFutureContinuation)(void * _Nonnull, int8_t);
|
64
64
|
|
65
65
|
// Scaffolding functions
|
66
|
-
|
66
|
+
RustBuffer uniffi_pubkymobile_fn_func_auth(RustBuffer url, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
|
67
|
+
);
|
68
|
+
RustBuffer uniffi_pubkymobile_fn_func_parse_auth_url(RustBuffer url, RustCallStatus *_Nonnull out_status
|
67
69
|
);
|
68
70
|
RustBuffer ffi_pubkymobile_rustbuffer_alloc(int32_t size, RustCallStatus *_Nonnull out_status
|
69
71
|
);
|
@@ -181,6 +183,9 @@ void ffi_pubkymobile_rust_future_complete_void(void* _Nonnull handle, RustCallSt
|
|
181
183
|
);
|
182
184
|
uint16_t uniffi_pubkymobile_checksum_func_auth(void
|
183
185
|
|
186
|
+
);
|
187
|
+
uint16_t uniffi_pubkymobile_checksum_func_parse_auth_url(void
|
188
|
+
|
184
189
|
);
|
185
190
|
uint32_t ffi_pubkymobile_uniffi_contract_version(void
|
186
191
|
|
Binary file
|
package/ios/Pubky.mm
CHANGED
@@ -7,6 +7,10 @@ RCT_EXTERN_METHOD(auth:(NSString *)url
|
|
7
7
|
withResolver:(RCTPromiseResolveBlock)resolve
|
8
8
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
9
9
|
|
10
|
+
RCT_EXTERN_METHOD(parseAuthUrl:(NSString *)url
|
11
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
12
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
13
|
+
|
10
14
|
+ (BOOL)requiresMainQueueSetup
|
11
15
|
{
|
12
16
|
return NO;
|
package/ios/Pubky.swift
CHANGED
@@ -2,15 +2,26 @@ import Foundation
|
|
2
2
|
|
3
3
|
@objc(Pubky)
|
4
4
|
class Pubky: NSObject {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
@objc(auth:secretKey:withResolver:withRejecter:)
|
6
|
+
func auth(_ url: String, secretKey: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
7
|
+
Task {
|
8
|
+
do {
|
9
|
+
let result = try await react_native_pubky.auth(url: url, secretKey: secretKey)
|
10
|
+
resolve(result)
|
11
|
+
} catch {
|
12
|
+
reject("auth Error", "Failed to auth", error)
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
16
|
+
@objc(parseAuthUrl:withResolver:withRejecter:)
|
17
|
+
func parseAuthUrl(_ url: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
18
|
+
Task {
|
19
|
+
do {
|
20
|
+
let result = react_native_pubky.parseAuthUrl(url: url)
|
21
|
+
resolve(result)
|
22
|
+
} catch {
|
23
|
+
reject("parseAuthUrl Error", "Failed to parse auth url", error)
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
16
27
|
}
|
package/ios/pubkymobile.swift
CHANGED
@@ -356,88 +356,26 @@ fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer {
|
|
356
356
|
return seq
|
357
357
|
}
|
358
358
|
}
|
359
|
-
private let UNIFFI_RUST_FUTURE_POLL_READY: Int8 = 0
|
360
|
-
private let UNIFFI_RUST_FUTURE_POLL_MAYBE_READY: Int8 = 1
|
361
|
-
|
362
|
-
fileprivate func uniffiRustCallAsync<F, T>(
|
363
|
-
rustFutureFunc: () -> UnsafeMutableRawPointer,
|
364
|
-
pollFunc: (UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> (),
|
365
|
-
completeFunc: (UnsafeMutableRawPointer, UnsafeMutablePointer<RustCallStatus>) -> F,
|
366
|
-
freeFunc: (UnsafeMutableRawPointer) -> (),
|
367
|
-
liftFunc: (F) throws -> T,
|
368
|
-
errorHandler: ((RustBuffer) throws -> Error)?
|
369
|
-
) async throws -> T {
|
370
|
-
// Make sure to call uniffiEnsureInitialized() since future creation doesn't have a
|
371
|
-
// RustCallStatus param, so doesn't use makeRustCall()
|
372
|
-
uniffiEnsureInitialized()
|
373
|
-
let rustFuture = rustFutureFunc()
|
374
|
-
defer {
|
375
|
-
freeFunc(rustFuture)
|
376
|
-
}
|
377
|
-
var pollResult: Int8;
|
378
|
-
repeat {
|
379
|
-
pollResult = await withUnsafeContinuation {
|
380
|
-
pollFunc(rustFuture, ContinuationHolder($0).toOpaque())
|
381
|
-
}
|
382
|
-
} while pollResult != UNIFFI_RUST_FUTURE_POLL_READY
|
383
|
-
|
384
|
-
return try liftFunc(makeRustCall(
|
385
|
-
{ completeFunc(rustFuture, $0) },
|
386
|
-
errorHandler: errorHandler
|
387
|
-
))
|
388
|
-
}
|
389
359
|
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
360
|
+
public func auth(url: String, secretKey: String) -> [String] {
|
361
|
+
return try! FfiConverterSequenceString.lift(
|
362
|
+
try! rustCall() {
|
363
|
+
uniffi_pubkymobile_fn_func_auth(
|
364
|
+
FfiConverterString.lower(url),
|
365
|
+
FfiConverterString.lower(secretKey),$0)
|
394
366
|
}
|
395
|
-
|
396
|
-
// Wraps UnsafeContinuation in a class so that we can use reference counting when passing it across
|
397
|
-
// the FFI
|
398
|
-
fileprivate class ContinuationHolder {
|
399
|
-
let continuation: UnsafeContinuation<Int8, Never>
|
400
|
-
|
401
|
-
init(_ continuation: UnsafeContinuation<Int8, Never>) {
|
402
|
-
self.continuation = continuation
|
403
|
-
}
|
404
|
-
|
405
|
-
func resume(_ pollResult: Int8) {
|
406
|
-
self.continuation.resume(returning: pollResult)
|
407
|
-
}
|
408
|
-
|
409
|
-
func toOpaque() -> UnsafeMutableRawPointer {
|
410
|
-
return Unmanaged<ContinuationHolder>.passRetained(self).toOpaque()
|
411
|
-
}
|
412
|
-
|
413
|
-
static func fromOpaque(_ ptr: UnsafeRawPointer) -> ContinuationHolder {
|
414
|
-
return Unmanaged<ContinuationHolder>.fromOpaque(ptr).takeRetainedValue()
|
415
|
-
}
|
367
|
+
)
|
416
368
|
}
|
417
369
|
|
418
|
-
|
419
|
-
|
370
|
+
public func parseAuthUrl(url: String) -> [String] {
|
371
|
+
return try! FfiConverterSequenceString.lift(
|
372
|
+
try! rustCall() {
|
373
|
+
uniffi_pubkymobile_fn_func_parse_auth_url(
|
374
|
+
FfiConverterString.lower(url),$0)
|
420
375
|
}
|
421
|
-
|
422
|
-
public func auth(url: String, secretKey: String) async -> [String] {
|
423
|
-
return try! await uniffiRustCallAsync(
|
424
|
-
rustFutureFunc: {
|
425
|
-
uniffi_pubkymobile_fn_func_auth(
|
426
|
-
FfiConverterString.lower(url),
|
427
|
-
FfiConverterString.lower(secretKey)
|
428
|
-
)
|
429
|
-
},
|
430
|
-
pollFunc: ffi_pubkymobile_rust_future_poll_rust_buffer,
|
431
|
-
completeFunc: ffi_pubkymobile_rust_future_complete_rust_buffer,
|
432
|
-
freeFunc: ffi_pubkymobile_rust_future_free_rust_buffer,
|
433
|
-
liftFunc: FfiConverterSequenceString.lift,
|
434
|
-
errorHandler: nil
|
435
|
-
|
436
376
|
)
|
437
377
|
}
|
438
378
|
|
439
|
-
|
440
|
-
|
441
379
|
private enum InitializationResult {
|
442
380
|
case ok
|
443
381
|
case contractVersionMismatch
|
@@ -453,11 +391,13 @@ private var initializationResult: InitializationResult {
|
|
453
391
|
if bindings_contract_version != scaffolding_contract_version {
|
454
392
|
return InitializationResult.contractVersionMismatch
|
455
393
|
}
|
456
|
-
if (uniffi_pubkymobile_checksum_func_auth() !=
|
394
|
+
if (uniffi_pubkymobile_checksum_func_auth() != 61378) {
|
395
|
+
return InitializationResult.apiChecksumMismatch
|
396
|
+
}
|
397
|
+
if (uniffi_pubkymobile_checksum_func_parse_auth_url() != 29088) {
|
457
398
|
return InitializationResult.apiChecksumMismatch
|
458
399
|
}
|
459
400
|
|
460
|
-
uniffiInitContinuationCallback()
|
461
401
|
return InitializationResult.ok
|
462
402
|
}
|
463
403
|
|
package/lib/commonjs/index.js
CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.auth = auth;
|
7
|
+
exports.parseAuthUrl = parseAuthUrl;
|
7
8
|
var _reactNative = require("react-native");
|
8
9
|
var _result = require("@synonymdev/result");
|
9
10
|
const LINKING_ERROR = `The package 'react-native-pubky' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
|
@@ -22,4 +23,16 @@ async function auth(url, secretKey) {
|
|
22
23
|
}
|
23
24
|
return (0, _result.ok)(res[1]);
|
24
25
|
}
|
26
|
+
async function parseAuthUrl(url) {
|
27
|
+
try {
|
28
|
+
const res = await Pubky.parseAuthUrl(url);
|
29
|
+
if (res[0] === 'error') {
|
30
|
+
return (0, _result.err)(res[1]);
|
31
|
+
}
|
32
|
+
const parsed = JSON.parse(res[1]);
|
33
|
+
return (0, _result.ok)(parsed);
|
34
|
+
} catch (e) {
|
35
|
+
return (0, _result.err)(JSON.stringify(e));
|
36
|
+
}
|
37
|
+
}
|
25
38
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_result","LINKING_ERROR","Platform","select","ios","default","Pubky","NativeModules","Proxy","get","Error","auth","url","secretKey","res","err","ok"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"
|
1
|
+
{"version":3,"names":["_reactNative","require","_result","LINKING_ERROR","Platform","select","ios","default","Pubky","NativeModules","Proxy","get","Error","auth","url","secretKey","res","err","ok","parseAuthUrl","parsed","JSON","parse","e","stringify"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAEA,MAAME,aAAa,GACjB,6EAA6E,GAC7EC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,KAAK,GAAGC,0BAAa,CAACD,KAAK,GAC7BC,0BAAa,CAACD,KAAK,GACnB,IAAIE,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACT,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEE,eAAeU,IAAIA,CACxBC,GAAW,EACXC,SAAiB,EACU;EAC3B,MAAMC,GAAG,GAAG,MAAMR,KAAK,CAACK,IAAI,CAACC,GAAG,EAAEC,SAAS,CAAC;EAC5C,IAAIC,GAAG,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE;IACtB,OAAO,IAAAC,WAAG,EAACD,GAAG,CAAC,CAAC,CAAC,CAAC;EACpB;EACA,OAAO,IAAAE,UAAE,EAACF,GAAG,CAAC,CAAC,CAAC,CAAC;AACnB;AAaO,eAAeG,YAAYA,CAChCL,GAAW,EACwB;EACnC,IAAI;IACF,MAAME,GAAG,GAAG,MAAMR,KAAK,CAACW,YAAY,CAACL,GAAG,CAAC;IACzC,IAAIE,GAAG,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE;MACtB,OAAO,IAAAC,WAAG,EAACD,GAAG,CAAC,CAAC,CAAC,CAAC;IACpB;IACA,MAAMI,MAAM,GAAGC,IAAI,CAACC,KAAK,CAACN,GAAG,CAAC,CAAC,CAAC,CAAC;IACjC,OAAO,IAAAE,UAAE,EAACE,MAAM,CAAC;EACnB,CAAC,CAAC,OAAOG,CAAC,EAAE;IACV,OAAO,IAAAN,WAAG,EAACI,IAAI,CAACG,SAAS,CAACD,CAAC,CAAC,CAAC;EAC/B;AACF","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
@@ -18,4 +18,16 @@ export async function auth(url, secretKey) {
|
|
18
18
|
}
|
19
19
|
return ok(res[1]);
|
20
20
|
}
|
21
|
+
export async function parseAuthUrl(url) {
|
22
|
+
try {
|
23
|
+
const res = await Pubky.parseAuthUrl(url);
|
24
|
+
if (res[0] === 'error') {
|
25
|
+
return err(res[1]);
|
26
|
+
}
|
27
|
+
const parsed = JSON.parse(res[1]);
|
28
|
+
return ok(parsed);
|
29
|
+
} catch (e) {
|
30
|
+
return err(JSON.stringify(e));
|
31
|
+
}
|
32
|
+
}
|
21
33
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["NativeModules","Platform","ok","err","LINKING_ERROR","select","ios","default","Pubky","Proxy","get","Error","auth","url","secretKey","res"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AACtD,SAASC,EAAE,EAAEC,GAAG,QAAqB,oBAAoB;AAEzD,MAAMC,aAAa,GACjB,6EAA6E,GAC7EH,QAAQ,CAACI,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,KAAK,GAAGR,aAAa,CAACQ,KAAK,GAC7BR,aAAa,CAACQ,KAAK,GACnB,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEL,OAAO,eAAeQ,IAAIA,CACxBC,GAAW,EACXC,SAAiB,EACU;EAC3B,MAAMC,GAAG,GAAG,MAAMP,KAAK,CAACI,IAAI,CAACC,GAAG,EAAEC,SAAS,CAAC;EAC5C,IAAIC,GAAG,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE;IACtB,OAAOZ,GAAG,CAACY,GAAG,CAAC,CAAC,CAAC,CAAC;EACpB;EACA,OAAOb,EAAE,CAACa,GAAG,CAAC,CAAC,CAAC,CAAC;AACnB","ignoreList":[]}
|
1
|
+
{"version":3,"names":["NativeModules","Platform","ok","err","LINKING_ERROR","select","ios","default","Pubky","Proxy","get","Error","auth","url","secretKey","res","parseAuthUrl","parsed","JSON","parse","e","stringify"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AACtD,SAASC,EAAE,EAAEC,GAAG,QAAqB,oBAAoB;AAEzD,MAAMC,aAAa,GACjB,6EAA6E,GAC7EH,QAAQ,CAACI,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,KAAK,GAAGR,aAAa,CAACQ,KAAK,GAC7BR,aAAa,CAACQ,KAAK,GACnB,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEL,OAAO,eAAeQ,IAAIA,CACxBC,GAAW,EACXC,SAAiB,EACU;EAC3B,MAAMC,GAAG,GAAG,MAAMP,KAAK,CAACI,IAAI,CAACC,GAAG,EAAEC,SAAS,CAAC;EAC5C,IAAIC,GAAG,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE;IACtB,OAAOZ,GAAG,CAACY,GAAG,CAAC,CAAC,CAAC,CAAC;EACpB;EACA,OAAOb,EAAE,CAACa,GAAG,CAAC,CAAC,CAAC,CAAC;AACnB;AAaA,OAAO,eAAeC,YAAYA,CAChCH,GAAW,EACwB;EACnC,IAAI;IACF,MAAME,GAAG,GAAG,MAAMP,KAAK,CAACQ,YAAY,CAACH,GAAG,CAAC;IACzC,IAAIE,GAAG,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE;MACtB,OAAOZ,GAAG,CAACY,GAAG,CAAC,CAAC,CAAC,CAAC;IACpB;IACA,MAAME,MAAM,GAAGC,IAAI,CAACC,KAAK,CAACJ,GAAG,CAAC,CAAC,CAAC,CAAC;IACjC,OAAOb,EAAE,CAACe,MAAM,CAAC;EACnB,CAAC,CAAC,OAAOG,CAAC,EAAE;IACV,OAAOjB,GAAG,CAACe,IAAI,CAACG,SAAS,CAACD,CAAC,CAAC,CAAC;EAC/B;AACF","ignoreList":[]}
|
@@ -1,3 +1,14 @@
|
|
1
1
|
import { type Result } from '@synonymdev/result';
|
2
2
|
export declare function auth(url: string, secretKey: string): Promise<Result<string[]>>;
|
3
|
+
type Capability = {
|
4
|
+
path: string;
|
5
|
+
permission: string;
|
6
|
+
};
|
7
|
+
type PubkyAuthDetails = {
|
8
|
+
relay: string;
|
9
|
+
capabilities: Capability[];
|
10
|
+
secret: string;
|
11
|
+
};
|
12
|
+
export declare function parseAuthUrl(url: string): Promise<Result<PubkyAuthDetails>>;
|
13
|
+
export {};
|
3
14
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAmB1D,wBAAsB,IAAI,CACxB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAM3B"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAmB1D,wBAAsB,IAAI,CACxB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAM3B;AAED,KAAK,UAAU,GAAG;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,gBAAgB,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,UAAU,EAAE,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAsB,YAAY,CAChC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAWnC"}
|
@@ -1,3 +1,14 @@
|
|
1
1
|
import { type Result } from '@synonymdev/result';
|
2
2
|
export declare function auth(url: string, secretKey: string): Promise<Result<string[]>>;
|
3
|
+
type Capability = {
|
4
|
+
path: string;
|
5
|
+
permission: string;
|
6
|
+
};
|
7
|
+
type PubkyAuthDetails = {
|
8
|
+
relay: string;
|
9
|
+
capabilities: Capability[];
|
10
|
+
secret: string;
|
11
|
+
};
|
12
|
+
export declare function parseAuthUrl(url: string): Promise<Result<PubkyAuthDetails>>;
|
13
|
+
export {};
|
3
14
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAmB1D,wBAAsB,IAAI,CACxB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAM3B"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAmB1D,wBAAsB,IAAI,CACxB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAM3B;AAED,KAAK,UAAU,GAAG;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,gBAAgB,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,UAAU,EAAE,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAsB,YAAY,CAChC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAWnC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@synonymdev/react-native-pubky",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.2.1",
|
4
4
|
"description": "React Native Implementation of Pubky",
|
5
5
|
"source": "./src/index.tsx",
|
6
6
|
"main": "./lib/commonjs/index.js",
|
@@ -49,7 +49,8 @@
|
|
49
49
|
"cargo-build": "cd rust && cargo build && cd pubky && cargo build && cd pubky && cargo build && cd ../ && cd pubky-common && cargo build && cd ../ && cd pubky-homeserver && cargo build && cd ../../../",
|
50
50
|
"update-bindings:ios": "npm run cargo-build && node setup-ios-bindings.js && npm run reinstall",
|
51
51
|
"update-bindings:android": "npm run cargo-build && node setup-android-bindings.js && npm run reinstall",
|
52
|
-
"update-bindings": "npm run reinstall && npm run cargo-build && npm run update-bindings:ios && npm run update-bindings:android"
|
52
|
+
"update-bindings": "npm run reinstall && npm run cargo-build && npm run update-bindings:ios && npm run update-bindings:android",
|
53
|
+
"rebuild": "rm -rf node_modules && cd example && rm -rf node_modules && cd ios && rm -rf Pods Podfile.lock build && cd ../../ && npm run cargo-build && yarn install && npm run update-bindings && cd example && yarn install && bundle install && cd ios && pod install && cd ../ && yarn build:ios && yarn ios"
|
53
54
|
},
|
54
55
|
"keywords": [
|
55
56
|
"pubky",
|
package/src/index.tsx
CHANGED
@@ -28,3 +28,29 @@ export async function auth(
|
|
28
28
|
}
|
29
29
|
return ok(res[1]);
|
30
30
|
}
|
31
|
+
|
32
|
+
type Capability = {
|
33
|
+
path: string;
|
34
|
+
permission: string;
|
35
|
+
};
|
36
|
+
|
37
|
+
type PubkyAuthDetails = {
|
38
|
+
relay: string;
|
39
|
+
capabilities: Capability[];
|
40
|
+
secret: string;
|
41
|
+
};
|
42
|
+
|
43
|
+
export async function parseAuthUrl(
|
44
|
+
url: string
|
45
|
+
): Promise<Result<PubkyAuthDetails>> {
|
46
|
+
try {
|
47
|
+
const res = await Pubky.parseAuthUrl(url);
|
48
|
+
if (res[0] === 'error') {
|
49
|
+
return err(res[1]);
|
50
|
+
}
|
51
|
+
const parsed = JSON.parse(res[1]);
|
52
|
+
return ok(parsed);
|
53
|
+
} catch (e) {
|
54
|
+
return err(JSON.stringify(e));
|
55
|
+
}
|
56
|
+
}
|