@synonymdev/react-native-pubky 0.2.0 → 0.2.2

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.
@@ -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,12 @@ 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
- ): Pointer
384
+ fun uniffi_pubkymobile_fn_func_auth(`url`: RustBuffer.ByValue,`secretKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
385
+ ): RustBuffer.ByValue
390
386
  fun uniffi_pubkymobile_fn_func_parse_auth_url(`url`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
391
387
  ): RustBuffer.ByValue
392
388
  fun ffi_pubkymobile_rustbuffer_alloc(`size`: Int,_uniffi_out_err: RustCallStatus,
@@ -524,7 +520,7 @@ private fun uniffiCheckContractApiVersion(lib: _UniFFILib) {
524
520
 
525
521
  @Suppress("UNUSED_PARAMETER")
526
522
  private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
527
- if (lib.uniffi_pubkymobile_checksum_func_auth() != 46918.toShort()) {
523
+ if (lib.uniffi_pubkymobile_checksum_func_auth() != 61378.toShort()) {
528
524
  throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
529
525
  }
530
526
  if (lib.uniffi_pubkymobile_checksum_func_parse_auth_url() != 29088.toShort()) {
@@ -533,50 +529,6 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
533
529
  }
534
530
 
535
531
  // Async support
536
- // Async return type handlers
537
-
538
- internal const val UNIFFI_RUST_FUTURE_POLL_READY = 0.toShort()
539
- internal const val UNIFFI_RUST_FUTURE_POLL_MAYBE_READY = 1.toShort()
540
-
541
- internal val uniffiContinuationHandleMap = UniFfiHandleMap<CancellableContinuation<Short>>()
542
-
543
- // FFI type for Rust future continuations
544
- internal object uniffiRustFutureContinuationCallback: UniFffiRustFutureContinuationCallbackType {
545
- override fun callback(continuationHandle: USize, pollResult: Short) {
546
- uniffiContinuationHandleMap.remove(continuationHandle)?.resume(pollResult)
547
- }
548
-
549
- internal fun register(lib: _UniFFILib) {
550
- lib.ffi_pubkymobile_rust_future_continuation_callback_set(this)
551
- }
552
- }
553
-
554
- internal suspend fun<T, F, E: Exception> uniffiRustCallAsync(
555
- rustFuture: Pointer,
556
- pollFunc: (Pointer, USize) -> Unit,
557
- completeFunc: (Pointer, RustCallStatus) -> F,
558
- freeFunc: (Pointer) -> Unit,
559
- liftFunc: (F) -> T,
560
- errorHandler: CallStatusErrorHandler<E>
561
- ): T {
562
- try {
563
- do {
564
- val pollResult = suspendCancellableCoroutine<Short> { continuation ->
565
- pollFunc(
566
- rustFuture,
567
- uniffiContinuationHandleMap.insert(continuation)
568
- )
569
- }
570
- } while (pollResult != UNIFFI_RUST_FUTURE_POLL_READY);
571
-
572
- return liftFunc(
573
- rustCallWithError(errorHandler, { status -> completeFunc(rustFuture, status) })
574
- )
575
- } finally {
576
- freeFunc(rustFuture)
577
- }
578
- }
579
-
580
532
 
581
533
  // Public interface members begin here.
582
534
 
@@ -660,24 +612,14 @@ public object FfiConverterSequenceString: FfiConverterRustBuffer<List<String>> {
660
612
  }
661
613
  }
662
614
 
663
-
664
-
665
-
666
-
667
- @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
668
- suspend fun `auth`(`url`: String, `secretKey`: String) : List<String> {
669
- return uniffiRustCallAsync(
670
- _UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_auth(FfiConverterString.lower(`url`),FfiConverterString.lower(`secretKey`),),
671
- { future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_poll_rust_buffer(future, continuation) },
672
- { future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_complete_rust_buffer(future, continuation) },
673
- { future -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_free_rust_buffer(future) },
674
- // lift function
675
- { FfiConverterSequenceString.lift(it) },
676
- // Error FFI converter
677
- NullCallStatusErrorHandler,
678
- )
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
+ })
679
620
  }
680
621
 
622
+
681
623
  fun `parseAuthUrl`(`url`: String): List<String> {
682
624
  return FfiConverterSequenceString.lift(
683
625
  rustCall() { _status ->
@@ -10,7 +10,7 @@
10
10
  <key>HeadersPath</key>
11
11
  <string>Headers</string>
12
12
  <key>LibraryIdentifier</key>
13
- <string>ios-arm64-simulator</string>
13
+ <string>ios-arm64</string>
14
14
  <key>LibraryPath</key>
15
15
  <string>libpubkymobile.a</string>
16
16
  <key>SupportedArchitectures</key>
@@ -19,8 +19,6 @@
19
19
  </array>
20
20
  <key>SupportedPlatform</key>
21
21
  <string>ios</string>
22
- <key>SupportedPlatformVariant</key>
23
- <string>simulator</string>
24
22
  </dict>
25
23
  <dict>
26
24
  <key>BinaryPath</key>
@@ -28,7 +26,7 @@
28
26
  <key>HeadersPath</key>
29
27
  <string>Headers</string>
30
28
  <key>LibraryIdentifier</key>
31
- <string>ios-arm64</string>
29
+ <string>ios-arm64-simulator</string>
32
30
  <key>LibraryPath</key>
33
31
  <string>libpubkymobile.a</string>
34
32
  <key>SupportedArchitectures</key>
@@ -37,6 +35,8 @@
37
35
  </array>
38
36
  <key>SupportedPlatform</key>
39
37
  <string>ios</string>
38
+ <key>SupportedPlatformVariant</key>
39
+ <string>simulator</string>
40
40
  </dict>
41
41
  </array>
42
42
  <key>CFBundlePackageType</key>
@@ -63,7 +63,7 @@ typedef struct RustCallStatus {
63
63
  typedef void (*UniFfiRustFutureContinuation)(void * _Nonnull, int8_t);
64
64
 
65
65
  // Scaffolding functions
66
- void* _Nonnull uniffi_pubkymobile_fn_func_auth(RustBuffer url, RustBuffer secret_key
66
+ RustBuffer uniffi_pubkymobile_fn_func_auth(RustBuffer url, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
67
67
  );
68
68
  RustBuffer uniffi_pubkymobile_fn_func_parse_auth_url(RustBuffer url, RustCallStatus *_Nonnull out_status
69
69
  );
@@ -63,7 +63,7 @@ typedef struct RustCallStatus {
63
63
  typedef void (*UniFfiRustFutureContinuation)(void * _Nonnull, int8_t);
64
64
 
65
65
  // Scaffolding functions
66
- void* _Nonnull uniffi_pubkymobile_fn_func_auth(RustBuffer url, RustBuffer secret_key
66
+ RustBuffer uniffi_pubkymobile_fn_func_auth(RustBuffer url, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
67
67
  );
68
68
  RustBuffer uniffi_pubkymobile_fn_func_parse_auth_url(RustBuffer url, RustCallStatus *_Nonnull out_status
69
69
  );
@@ -356,88 +356,17 @@ 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
-
390
- // Callback handlers for an async calls. These are invoked by Rust when the future is ready. They
391
- // lift the return value or error and resume the suspended function.
392
- fileprivate func uniffiFutureContinuationCallback(ptr: UnsafeMutableRawPointer, pollResult: Int8) {
393
- ContinuationHolder.fromOpaque(ptr).resume(pollResult)
394
- }
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
- }
416
- }
417
359
 
418
- fileprivate func uniffiInitContinuationCallback() {
419
- ffi_pubkymobile_rust_future_continuation_callback_set(uniffiFutureContinuationCallback)
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)
420
366
  }
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
367
  )
437
368
  }
438
369
 
439
-
440
-
441
370
  public func parseAuthUrl(url: String) -> [String] {
442
371
  return try! FfiConverterSequenceString.lift(
443
372
  try! rustCall() {
@@ -462,14 +391,13 @@ private var initializationResult: InitializationResult {
462
391
  if bindings_contract_version != scaffolding_contract_version {
463
392
  return InitializationResult.contractVersionMismatch
464
393
  }
465
- if (uniffi_pubkymobile_checksum_func_auth() != 46918) {
394
+ if (uniffi_pubkymobile_checksum_func_auth() != 61378) {
466
395
  return InitializationResult.apiChecksumMismatch
467
396
  }
468
397
  if (uniffi_pubkymobile_checksum_func_parse_auth_url() != 29088) {
469
398
  return InitializationResult.apiChecksumMismatch
470
399
  }
471
400
 
472
- uniffiInitContinuationCallback()
473
401
  return InitializationResult.ok
474
402
  }
475
403
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synonymdev/react-native-pubky",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "React Native Implementation of Pubky",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",