@synonymdev/react-native-pubky 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -63,12 +63,18 @@ typedef struct RustCallStatus {
63
63
  typedef void (*UniFfiRustFutureContinuation)(void * _Nonnull, int8_t);
64
64
 
65
65
  // Scaffolding functions
66
+ void uniffi_pubkymobile_fn_free_eventnotifier(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status
67
+ );
68
+ void uniffi_pubkymobile_fn_init_callback_eventlistener(ForeignCallback _Nonnull callback_stub, RustCallStatus *_Nonnull out_status
69
+ );
66
70
  RustBuffer uniffi_pubkymobile_fn_func_auth(RustBuffer url, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
67
71
  );
68
72
  RustBuffer uniffi_pubkymobile_fn_func_create_recovery_file(RustBuffer secret_key, RustBuffer passphrase, RustCallStatus *_Nonnull out_status
69
73
  );
70
74
  RustBuffer uniffi_pubkymobile_fn_func_decrypt_recovery_file(RustBuffer recovery_file, RustBuffer passphrase, RustCallStatus *_Nonnull out_status
71
75
  );
76
+ RustBuffer uniffi_pubkymobile_fn_func_delete_file(RustBuffer url, RustCallStatus *_Nonnull out_status
77
+ );
72
78
  RustBuffer uniffi_pubkymobile_fn_func_generate_secret_key(RustCallStatus *_Nonnull out_status
73
79
 
74
80
  );
@@ -85,11 +91,18 @@ RustBuffer uniffi_pubkymobile_fn_func_publish(RustBuffer record_name, RustBuffer
85
91
  RustBuffer uniffi_pubkymobile_fn_func_publish_https(RustBuffer record_name, RustBuffer target, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
86
92
  );
87
93
  RustBuffer uniffi_pubkymobile_fn_func_put(RustBuffer url, RustBuffer content, RustCallStatus *_Nonnull out_status
94
+ );
95
+ void uniffi_pubkymobile_fn_func_remove_event_listener(RustCallStatus *_Nonnull out_status
96
+
88
97
  );
89
98
  RustBuffer uniffi_pubkymobile_fn_func_resolve(RustBuffer public_key, RustCallStatus *_Nonnull out_status
90
99
  );
91
100
  RustBuffer uniffi_pubkymobile_fn_func_resolve_https(RustBuffer public_key, RustCallStatus *_Nonnull out_status
92
101
  );
102
+ RustBuffer uniffi_pubkymobile_fn_func_session(RustBuffer pubky, RustCallStatus *_Nonnull out_status
103
+ );
104
+ void uniffi_pubkymobile_fn_func_set_event_listener(uint64_t listener, RustCallStatus *_Nonnull out_status
105
+ );
93
106
  RustBuffer uniffi_pubkymobile_fn_func_sign_in(RustBuffer secret_key, RustCallStatus *_Nonnull out_status
94
107
  );
95
108
  RustBuffer uniffi_pubkymobile_fn_func_sign_out(RustBuffer secret_key, RustCallStatus *_Nonnull out_status
@@ -218,6 +231,9 @@ uint16_t uniffi_pubkymobile_checksum_func_create_recovery_file(void
218
231
  );
219
232
  uint16_t uniffi_pubkymobile_checksum_func_decrypt_recovery_file(void
220
233
 
234
+ );
235
+ uint16_t uniffi_pubkymobile_checksum_func_delete_file(void
236
+
221
237
  );
222
238
  uint16_t uniffi_pubkymobile_checksum_func_generate_secret_key(void
223
239
 
@@ -242,12 +258,21 @@ uint16_t uniffi_pubkymobile_checksum_func_publish_https(void
242
258
  );
243
259
  uint16_t uniffi_pubkymobile_checksum_func_put(void
244
260
 
261
+ );
262
+ uint16_t uniffi_pubkymobile_checksum_func_remove_event_listener(void
263
+
245
264
  );
246
265
  uint16_t uniffi_pubkymobile_checksum_func_resolve(void
247
266
 
248
267
  );
249
268
  uint16_t uniffi_pubkymobile_checksum_func_resolve_https(void
250
269
 
270
+ );
271
+ uint16_t uniffi_pubkymobile_checksum_func_session(void
272
+
273
+ );
274
+ uint16_t uniffi_pubkymobile_checksum_func_set_event_listener(void
275
+
251
276
  );
252
277
  uint16_t uniffi_pubkymobile_checksum_func_sign_in(void
253
278
 
@@ -257,6 +282,9 @@ uint16_t uniffi_pubkymobile_checksum_func_sign_out(void
257
282
  );
258
283
  uint16_t uniffi_pubkymobile_checksum_func_sign_up(void
259
284
 
285
+ );
286
+ uint16_t uniffi_pubkymobile_checksum_method_eventlistener_on_event_occurred(void
287
+
260
288
  );
261
289
  uint32_t ffi_pubkymobile_uniffi_contract_version(void
262
290
 
@@ -63,12 +63,18 @@ typedef struct RustCallStatus {
63
63
  typedef void (*UniFfiRustFutureContinuation)(void * _Nonnull, int8_t);
64
64
 
65
65
  // Scaffolding functions
66
+ void uniffi_pubkymobile_fn_free_eventnotifier(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status
67
+ );
68
+ void uniffi_pubkymobile_fn_init_callback_eventlistener(ForeignCallback _Nonnull callback_stub, RustCallStatus *_Nonnull out_status
69
+ );
66
70
  RustBuffer uniffi_pubkymobile_fn_func_auth(RustBuffer url, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
67
71
  );
68
72
  RustBuffer uniffi_pubkymobile_fn_func_create_recovery_file(RustBuffer secret_key, RustBuffer passphrase, RustCallStatus *_Nonnull out_status
69
73
  );
70
74
  RustBuffer uniffi_pubkymobile_fn_func_decrypt_recovery_file(RustBuffer recovery_file, RustBuffer passphrase, RustCallStatus *_Nonnull out_status
71
75
  );
76
+ RustBuffer uniffi_pubkymobile_fn_func_delete_file(RustBuffer url, RustCallStatus *_Nonnull out_status
77
+ );
72
78
  RustBuffer uniffi_pubkymobile_fn_func_generate_secret_key(RustCallStatus *_Nonnull out_status
73
79
 
74
80
  );
@@ -85,11 +91,18 @@ RustBuffer uniffi_pubkymobile_fn_func_publish(RustBuffer record_name, RustBuffer
85
91
  RustBuffer uniffi_pubkymobile_fn_func_publish_https(RustBuffer record_name, RustBuffer target, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
86
92
  );
87
93
  RustBuffer uniffi_pubkymobile_fn_func_put(RustBuffer url, RustBuffer content, RustCallStatus *_Nonnull out_status
94
+ );
95
+ void uniffi_pubkymobile_fn_func_remove_event_listener(RustCallStatus *_Nonnull out_status
96
+
88
97
  );
89
98
  RustBuffer uniffi_pubkymobile_fn_func_resolve(RustBuffer public_key, RustCallStatus *_Nonnull out_status
90
99
  );
91
100
  RustBuffer uniffi_pubkymobile_fn_func_resolve_https(RustBuffer public_key, RustCallStatus *_Nonnull out_status
92
101
  );
102
+ RustBuffer uniffi_pubkymobile_fn_func_session(RustBuffer pubky, RustCallStatus *_Nonnull out_status
103
+ );
104
+ void uniffi_pubkymobile_fn_func_set_event_listener(uint64_t listener, RustCallStatus *_Nonnull out_status
105
+ );
93
106
  RustBuffer uniffi_pubkymobile_fn_func_sign_in(RustBuffer secret_key, RustCallStatus *_Nonnull out_status
94
107
  );
95
108
  RustBuffer uniffi_pubkymobile_fn_func_sign_out(RustBuffer secret_key, RustCallStatus *_Nonnull out_status
@@ -218,6 +231,9 @@ uint16_t uniffi_pubkymobile_checksum_func_create_recovery_file(void
218
231
  );
219
232
  uint16_t uniffi_pubkymobile_checksum_func_decrypt_recovery_file(void
220
233
 
234
+ );
235
+ uint16_t uniffi_pubkymobile_checksum_func_delete_file(void
236
+
221
237
  );
222
238
  uint16_t uniffi_pubkymobile_checksum_func_generate_secret_key(void
223
239
 
@@ -242,12 +258,21 @@ uint16_t uniffi_pubkymobile_checksum_func_publish_https(void
242
258
  );
243
259
  uint16_t uniffi_pubkymobile_checksum_func_put(void
244
260
 
261
+ );
262
+ uint16_t uniffi_pubkymobile_checksum_func_remove_event_listener(void
263
+
245
264
  );
246
265
  uint16_t uniffi_pubkymobile_checksum_func_resolve(void
247
266
 
248
267
  );
249
268
  uint16_t uniffi_pubkymobile_checksum_func_resolve_https(void
250
269
 
270
+ );
271
+ uint16_t uniffi_pubkymobile_checksum_func_session(void
272
+
273
+ );
274
+ uint16_t uniffi_pubkymobile_checksum_func_set_event_listener(void
275
+
251
276
  );
252
277
  uint16_t uniffi_pubkymobile_checksum_func_sign_in(void
253
278
 
@@ -257,6 +282,9 @@ uint16_t uniffi_pubkymobile_checksum_func_sign_out(void
257
282
  );
258
283
  uint16_t uniffi_pubkymobile_checksum_func_sign_up(void
259
284
 
285
+ );
286
+ uint16_t uniffi_pubkymobile_checksum_method_eventlistener_on_event_occurred(void
287
+
260
288
  );
261
289
  uint32_t ffi_pubkymobile_uniffi_contract_version(void
262
290
 
@@ -1,2 +1,3 @@
1
1
  #import <React/RCTBridgeModule.h>
2
2
  #import <React/RCTViewManager.h>
3
+ #import <React/RCTEventEmitter.h>
package/ios/Pubky.mm CHANGED
@@ -1,6 +1,21 @@
1
1
  #import <React/RCTBridgeModule.h>
2
+ #import <React/RCTEventEmitter.h>
2
3
 
3
- @interface RCT_EXTERN_MODULE(Pubky, NSObject)
4
+ @interface RCT_EXTERN_MODULE(Pubky, RCTEventEmitter)
5
+
6
+ RCT_EXTERN_METHOD(setEventListener:(RCTPromiseResolveBlock)resolve
7
+ withRejecter:(RCTPromiseRejectBlock)reject)
8
+
9
+ RCT_EXTERN_METHOD(removeEventListener:(RCTPromiseResolveBlock)resolve
10
+ withRejecter:(RCTPromiseRejectBlock)reject)
11
+
12
+ RCT_EXTERN_METHOD(deleteFile:(NSString *)url
13
+ withResolver:(RCTPromiseResolveBlock)resolve
14
+ withRejecter:(RCTPromiseRejectBlock)reject)
15
+
16
+ RCT_EXTERN_METHOD(session:(NSString *)pubky
17
+ withResolver:(RCTPromiseResolveBlock)resolve
18
+ withRejecter:(RCTPromiseRejectBlock)reject)
4
19
 
5
20
  RCT_EXTERN_METHOD(auth:(NSString *)url
6
21
  secretKey:(NSString *)secretKey
package/ios/Pubky.swift CHANGED
@@ -1,7 +1,46 @@
1
1
  import Foundation
2
+ import React
2
3
 
3
4
  @objc(Pubky)
4
- class Pubky: NSObject {
5
+ class Pubky: RCTEventEmitter {
6
+
7
+ override init() {
8
+ super.init()
9
+ }
10
+
11
+ @objc override static func requiresMainQueueSetup() -> Bool {
12
+ return false
13
+ }
14
+
15
+ override func supportedEvents() -> [String]! {
16
+ return ["PubkyEvent"]
17
+ }
18
+
19
+ class EventListenerImpl: EventListener {
20
+ weak var pubky: Pubky?
21
+
22
+ init(pubky: Pubky) {
23
+ self.pubky = pubky
24
+ }
25
+
26
+ func onEventOccurred(eventData: String) {
27
+ pubky?.sendEvent(withName: "PubkyEvent", body: eventData)
28
+ }
29
+ }
30
+
31
+ @objc(setEventListener:withRejecter:)
32
+ func setEventListener(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
33
+ let listener = EventListenerImpl(pubky: self)
34
+ react_native_pubky.setEventListener(listener: listener)
35
+ resolve(nil)
36
+ }
37
+
38
+ @objc(removeEventListener:withRejecter:)
39
+ func removeEventListener(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
40
+ react_native_pubky.removeEventListener()
41
+ resolve(nil)
42
+ }
43
+
5
44
  @objc(auth:secretKey:withResolver:withRejecter:)
6
45
  func auth(_ url: String, secretKey: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
7
46
  Task {
@@ -144,6 +183,30 @@ class Pubky: NSObject {
144
183
  }
145
184
  }
146
185
 
186
+ @objc(deleteFile:withResolver:withRejecter:)
187
+ func deleteFile(_ url: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
188
+ Task {
189
+ do {
190
+ let result = try await react_native_pubky.deleteFile(url: url)
191
+ resolve(result)
192
+ } catch {
193
+ reject("list Error", "Failed to deleteFile", error)
194
+ }
195
+ }
196
+ }
197
+
198
+ @objc(session:withResolver:withRejecter:)
199
+ func session(_ pubky: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
200
+ Task {
201
+ do {
202
+ let result = react_native_pubky.session(pubky: pubky)
203
+ resolve(result)
204
+ } catch {
205
+ reject("session Error", "Failed to get session", error)
206
+ }
207
+ }
208
+ }
209
+
147
210
  @objc(generateSecretKey:withRejecter:)
148
211
  func generateSecretKey(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
149
212
  Task {
@@ -335,6 +335,240 @@ fileprivate struct FfiConverterString: FfiConverter {
335
335
  }
336
336
  }
337
337
 
338
+
339
+ public protocol EventNotifierProtocol {
340
+
341
+ }
342
+
343
+ public class EventNotifier: EventNotifierProtocol {
344
+ fileprivate let pointer: UnsafeMutableRawPointer
345
+
346
+ // TODO: We'd like this to be `private` but for Swifty reasons,
347
+ // we can't implement `FfiConverter` without making this `required` and we can't
348
+ // make it `required` without making it `public`.
349
+ required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
350
+ self.pointer = pointer
351
+ }
352
+
353
+ deinit {
354
+ try! rustCall { uniffi_pubkymobile_fn_free_eventnotifier(pointer, $0) }
355
+ }
356
+
357
+
358
+
359
+
360
+
361
+ }
362
+
363
+ public struct FfiConverterTypeEventNotifier: FfiConverter {
364
+ typealias FfiType = UnsafeMutableRawPointer
365
+ typealias SwiftType = EventNotifier
366
+
367
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> EventNotifier {
368
+ let v: UInt64 = try readInt(&buf)
369
+ // The Rust code won't compile if a pointer won't fit in a UInt64.
370
+ // We have to go via `UInt` because that's the thing that's the size of a pointer.
371
+ let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v))
372
+ if (ptr == nil) {
373
+ throw UniffiInternalError.unexpectedNullPointer
374
+ }
375
+ return try lift(ptr!)
376
+ }
377
+
378
+ public static func write(_ value: EventNotifier, into buf: inout [UInt8]) {
379
+ // This fiddling is because `Int` is the thing that's the same size as a pointer.
380
+ // The Rust code won't compile if a pointer won't fit in a `UInt64`.
381
+ writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
382
+ }
383
+
384
+ public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> EventNotifier {
385
+ return EventNotifier(unsafeFromRawPointer: pointer)
386
+ }
387
+
388
+ public static func lower(_ value: EventNotifier) -> UnsafeMutableRawPointer {
389
+ return value.pointer
390
+ }
391
+ }
392
+
393
+
394
+ public func FfiConverterTypeEventNotifier_lift(_ pointer: UnsafeMutableRawPointer) throws -> EventNotifier {
395
+ return try FfiConverterTypeEventNotifier.lift(pointer)
396
+ }
397
+
398
+ public func FfiConverterTypeEventNotifier_lower(_ value: EventNotifier) -> UnsafeMutableRawPointer {
399
+ return FfiConverterTypeEventNotifier.lower(value)
400
+ }
401
+
402
+ fileprivate extension NSLock {
403
+ func withLock<T>(f: () throws -> T) rethrows -> T {
404
+ self.lock()
405
+ defer { self.unlock() }
406
+ return try f()
407
+ }
408
+ }
409
+
410
+ fileprivate typealias UniFFICallbackHandle = UInt64
411
+ fileprivate class UniFFICallbackHandleMap<T> {
412
+ private var leftMap: [UniFFICallbackHandle: T] = [:]
413
+ private var counter: [UniFFICallbackHandle: UInt64] = [:]
414
+ private var rightMap: [ObjectIdentifier: UniFFICallbackHandle] = [:]
415
+
416
+ private let lock = NSLock()
417
+ private var currentHandle: UniFFICallbackHandle = 0
418
+ private let stride: UniFFICallbackHandle = 1
419
+
420
+ func insert(obj: T) -> UniFFICallbackHandle {
421
+ lock.withLock {
422
+ let id = ObjectIdentifier(obj as AnyObject)
423
+ let handle = rightMap[id] ?? {
424
+ currentHandle += stride
425
+ let handle = currentHandle
426
+ leftMap[handle] = obj
427
+ rightMap[id] = handle
428
+ return handle
429
+ }()
430
+ counter[handle] = (counter[handle] ?? 0) + 1
431
+ return handle
432
+ }
433
+ }
434
+
435
+ func get(handle: UniFFICallbackHandle) -> T? {
436
+ lock.withLock {
437
+ leftMap[handle]
438
+ }
439
+ }
440
+
441
+ func delete(handle: UniFFICallbackHandle) {
442
+ remove(handle: handle)
443
+ }
444
+
445
+ @discardableResult
446
+ func remove(handle: UniFFICallbackHandle) -> T? {
447
+ lock.withLock {
448
+ defer { counter[handle] = (counter[handle] ?? 1) - 1 }
449
+ guard counter[handle] == 1 else { return leftMap[handle] }
450
+ let obj = leftMap.removeValue(forKey: handle)
451
+ if let obj = obj {
452
+ rightMap.removeValue(forKey: ObjectIdentifier(obj as AnyObject))
453
+ }
454
+ return obj
455
+ }
456
+ }
457
+ }
458
+
459
+ // Magic number for the Rust proxy to call using the same mechanism as every other method,
460
+ // to free the callback once it's dropped by Rust.
461
+ private let IDX_CALLBACK_FREE: Int32 = 0
462
+ // Callback return codes
463
+ private let UNIFFI_CALLBACK_SUCCESS: Int32 = 0
464
+ private let UNIFFI_CALLBACK_ERROR: Int32 = 1
465
+ private let UNIFFI_CALLBACK_UNEXPECTED_ERROR: Int32 = 2
466
+
467
+ // Declaration and FfiConverters for EventListener Callback Interface
468
+
469
+ public protocol EventListener : AnyObject {
470
+ func onEventOccurred(eventData: String)
471
+
472
+ }
473
+
474
+ // The ForeignCallback that is passed to Rust.
475
+ fileprivate let foreignCallbackCallbackInterfaceEventListener : ForeignCallback =
476
+ { (handle: UniFFICallbackHandle, method: Int32, argsData: UnsafePointer<UInt8>, argsLen: Int32, out_buf: UnsafeMutablePointer<RustBuffer>) -> Int32 in
477
+
478
+
479
+ func invokeOnEventOccurred(_ swiftCallbackInterface: EventListener, _ argsData: UnsafePointer<UInt8>, _ argsLen: Int32, _ out_buf: UnsafeMutablePointer<RustBuffer>) throws -> Int32 {
480
+ var reader = createReader(data: Data(bytes: argsData, count: Int(argsLen)))
481
+ func makeCall() throws -> Int32 {
482
+ try swiftCallbackInterface.onEventOccurred(
483
+ eventData: try FfiConverterString.read(from: &reader)
484
+ )
485
+ return UNIFFI_CALLBACK_SUCCESS
486
+ }
487
+ return try makeCall()
488
+ }
489
+
490
+
491
+ switch method {
492
+ case IDX_CALLBACK_FREE:
493
+ FfiConverterCallbackInterfaceEventListener.drop(handle: handle)
494
+ // Sucessful return
495
+ // See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs`
496
+ return UNIFFI_CALLBACK_SUCCESS
497
+ case 1:
498
+ let cb: EventListener
499
+ do {
500
+ cb = try FfiConverterCallbackInterfaceEventListener.lift(handle)
501
+ } catch {
502
+ out_buf.pointee = FfiConverterString.lower("EventListener: Invalid handle")
503
+ return UNIFFI_CALLBACK_UNEXPECTED_ERROR
504
+ }
505
+ do {
506
+ return try invokeOnEventOccurred(cb, argsData, argsLen, out_buf)
507
+ } catch let error {
508
+ out_buf.pointee = FfiConverterString.lower(String(describing: error))
509
+ return UNIFFI_CALLBACK_UNEXPECTED_ERROR
510
+ }
511
+
512
+ // This should never happen, because an out of bounds method index won't
513
+ // ever be used. Once we can catch errors, we should return an InternalError.
514
+ // https://github.com/mozilla/uniffi-rs/issues/351
515
+ default:
516
+ // An unexpected error happened.
517
+ // See docs of ForeignCallback in `uniffi_core/src/ffi/foreigncallbacks.rs`
518
+ return UNIFFI_CALLBACK_UNEXPECTED_ERROR
519
+ }
520
+ }
521
+
522
+ // FfiConverter protocol for callback interfaces
523
+ fileprivate struct FfiConverterCallbackInterfaceEventListener {
524
+ private static let initCallbackOnce: () = {
525
+ // Swift ensures this initializer code will once run once, even when accessed by multiple threads.
526
+ try! rustCall { (err: UnsafeMutablePointer<RustCallStatus>) in
527
+ uniffi_pubkymobile_fn_init_callback_eventlistener(foreignCallbackCallbackInterfaceEventListener, err)
528
+ }
529
+ }()
530
+
531
+ private static func ensureCallbackinitialized() {
532
+ _ = initCallbackOnce
533
+ }
534
+
535
+ static func drop(handle: UniFFICallbackHandle) {
536
+ handleMap.remove(handle: handle)
537
+ }
538
+
539
+ private static var handleMap = UniFFICallbackHandleMap<EventListener>()
540
+ }
541
+
542
+ extension FfiConverterCallbackInterfaceEventListener : FfiConverter {
543
+ typealias SwiftType = EventListener
544
+ // We can use Handle as the FfiType because it's a typealias to UInt64
545
+ typealias FfiType = UniFFICallbackHandle
546
+
547
+ public static func lift(_ handle: UniFFICallbackHandle) throws -> SwiftType {
548
+ ensureCallbackinitialized();
549
+ guard let callback = handleMap.get(handle: handle) else {
550
+ throw UniffiInternalError.unexpectedStaleHandle
551
+ }
552
+ return callback
553
+ }
554
+
555
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
556
+ ensureCallbackinitialized();
557
+ let handle: UniFFICallbackHandle = try readInt(&buf)
558
+ return try lift(handle)
559
+ }
560
+
561
+ public static func lower(_ v: SwiftType) -> UniFFICallbackHandle {
562
+ ensureCallbackinitialized();
563
+ return handleMap.insert(obj: v)
564
+ }
565
+
566
+ public static func write(_ v: SwiftType, into buf: inout [UInt8]) {
567
+ ensureCallbackinitialized();
568
+ writeInt(&buf, lower(v))
569
+ }
570
+ }
571
+
338
572
  fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer {
339
573
  typealias SwiftType = [String]
340
574
 
@@ -387,6 +621,15 @@ public func decryptRecoveryFile(recoveryFile: String, passphrase: String) -> [S
387
621
  )
388
622
  }
389
623
 
624
+ public func deleteFile(url: String) -> [String] {
625
+ return try! FfiConverterSequenceString.lift(
626
+ try! rustCall() {
627
+ uniffi_pubkymobile_fn_func_delete_file(
628
+ FfiConverterString.lower(url),$0)
629
+ }
630
+ )
631
+ }
632
+
390
633
  public func generateSecretKey() -> [String] {
391
634
  return try! FfiConverterSequenceString.lift(
392
635
  try! rustCall() {
@@ -463,6 +706,14 @@ public func put(url: String, content: String) -> [String] {
463
706
  )
464
707
  }
465
708
 
709
+ public func removeEventListener() {
710
+ try! rustCall() {
711
+ uniffi_pubkymobile_fn_func_remove_event_listener($0)
712
+ }
713
+ }
714
+
715
+
716
+
466
717
  public func resolve(publicKey: String) -> [String] {
467
718
  return try! FfiConverterSequenceString.lift(
468
719
  try! rustCall() {
@@ -481,6 +732,24 @@ public func resolveHttps(publicKey: String) -> [String] {
481
732
  )
482
733
  }
483
734
 
735
+ public func session(pubky: String) -> [String] {
736
+ return try! FfiConverterSequenceString.lift(
737
+ try! rustCall() {
738
+ uniffi_pubkymobile_fn_func_session(
739
+ FfiConverterString.lower(pubky),$0)
740
+ }
741
+ )
742
+ }
743
+
744
+ public func setEventListener(listener: EventListener) {
745
+ try! rustCall() {
746
+ uniffi_pubkymobile_fn_func_set_event_listener(
747
+ FfiConverterCallbackInterfaceEventListener.lower(listener),$0)
748
+ }
749
+ }
750
+
751
+
752
+
484
753
  public func signIn(secretKey: String) -> [String] {
485
754
  return try! FfiConverterSequenceString.lift(
486
755
  try! rustCall() {
@@ -533,6 +802,9 @@ private var initializationResult: InitializationResult {
533
802
  if (uniffi_pubkymobile_checksum_func_decrypt_recovery_file() != 59688) {
534
803
  return InitializationResult.apiChecksumMismatch
535
804
  }
805
+ if (uniffi_pubkymobile_checksum_func_delete_file() != 57905) {
806
+ return InitializationResult.apiChecksumMismatch
807
+ }
536
808
  if (uniffi_pubkymobile_checksum_func_generate_secret_key() != 63116) {
537
809
  return InitializationResult.apiChecksumMismatch
538
810
  }
@@ -557,12 +829,21 @@ private var initializationResult: InitializationResult {
557
829
  if (uniffi_pubkymobile_checksum_func_put() != 51107) {
558
830
  return InitializationResult.apiChecksumMismatch
559
831
  }
832
+ if (uniffi_pubkymobile_checksum_func_remove_event_listener() != 6794) {
833
+ return InitializationResult.apiChecksumMismatch
834
+ }
560
835
  if (uniffi_pubkymobile_checksum_func_resolve() != 18303) {
561
836
  return InitializationResult.apiChecksumMismatch
562
837
  }
563
838
  if (uniffi_pubkymobile_checksum_func_resolve_https() != 34593) {
564
839
  return InitializationResult.apiChecksumMismatch
565
840
  }
841
+ if (uniffi_pubkymobile_checksum_func_session() != 65177) {
842
+ return InitializationResult.apiChecksumMismatch
843
+ }
844
+ if (uniffi_pubkymobile_checksum_func_set_event_listener() != 19468) {
845
+ return InitializationResult.apiChecksumMismatch
846
+ }
566
847
  if (uniffi_pubkymobile_checksum_func_sign_in() != 21006) {
567
848
  return InitializationResult.apiChecksumMismatch
568
849
  }
@@ -572,6 +853,9 @@ private var initializationResult: InitializationResult {
572
853
  if (uniffi_pubkymobile_checksum_func_sign_up() != 58756) {
573
854
  return InitializationResult.apiChecksumMismatch
574
855
  }
856
+ if (uniffi_pubkymobile_checksum_method_eventlistener_on_event_occurred() != 39865) {
857
+ return InitializationResult.apiChecksumMismatch
858
+ }
575
859
 
576
860
  return InitializationResult.ok
577
861
  }
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.auth = auth;
7
7
  exports.createRecoveryFile = createRecoveryFile;
8
8
  exports.decryptRecoveryFile = decryptRecoveryFile;
9
+ exports.deleteFile = deleteFile;
9
10
  exports.generateSecretKey = generateSecretKey;
10
11
  exports.get = get;
11
12
  exports.getPublicKeyFromSecretKey = getPublicKeyFromSecretKey;
@@ -14,8 +15,11 @@ exports.parseAuthUrl = parseAuthUrl;
14
15
  exports.publish = publish;
15
16
  exports.publishHttps = publishHttps;
16
17
  exports.put = put;
18
+ exports.removeEventListener = removeEventListener;
17
19
  exports.resolve = resolve;
18
20
  exports.resolveHttps = resolveHttps;
21
+ exports.session = session;
22
+ exports.setEventListener = setEventListener;
19
23
  exports.signIn = signIn;
20
24
  exports.signOut = signOut;
21
25
  exports.signUp = signUp;
@@ -30,6 +34,25 @@ const Pubky = _reactNative.NativeModules.Pubky ? _reactNative.NativeModules.Pubk
30
34
  throw new Error(LINKING_ERROR);
31
35
  }
32
36
  });
37
+ const eventEmitter = new _reactNative.NativeEventEmitter(Pubky);
38
+ async function setEventListener(callback) {
39
+ try {
40
+ await Pubky.setEventListener();
41
+ eventEmitter.addListener('PubkyEvent', callback);
42
+ return (0, _result.ok)(undefined);
43
+ } catch (e) {
44
+ return (0, _result.err)(JSON.stringify(e));
45
+ }
46
+ }
47
+ async function removeEventListener() {
48
+ try {
49
+ //await Pubky.removeEventListener();
50
+ eventEmitter.removeAllListeners('PubkyEvent');
51
+ return (0, _result.ok)(undefined);
52
+ } catch (e) {
53
+ return (0, _result.err)(JSON.stringify(e));
54
+ }
55
+ }
33
56
  async function auth(url, secretKey) {
34
57
  const res = await Pubky.auth(url, secretKey);
35
58
  if (res[0] === 'error') {
@@ -159,6 +182,28 @@ async function list(url) {
159
182
  return (0, _result.err)(JSON.stringify(e));
160
183
  }
161
184
  }
185
+ async function deleteFile(url) {
186
+ try {
187
+ const res = await Pubky.deleteFile(url);
188
+ if (res[0] === 'error') {
189
+ return (0, _result.err)(res[1]);
190
+ }
191
+ return (0, _result.ok)(res[1]);
192
+ } catch (e) {
193
+ return (0, _result.err)(JSON.stringify(e));
194
+ }
195
+ }
196
+ async function session(pubky) {
197
+ try {
198
+ const res = await Pubky.session(pubky);
199
+ if (res[0] === 'error') {
200
+ return (0, _result.err)(res[1]);
201
+ }
202
+ return (0, _result.ok)(JSON.parse(res[1]));
203
+ } catch (e) {
204
+ return (0, _result.err)(JSON.stringify(e));
205
+ }
206
+ }
162
207
  async function generateSecretKey() {
163
208
  try {
164
209
  const res = await Pubky.generateSecretKey();