@synonymdev/react-native-pubky 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -16,15 +16,17 @@ npm install @synonymdev/react-native-pubky
16
16
  - [x] [resolve](#resolve): Functionality to resolve content.
17
17
  - [x] [publishHttps](#publishHttps): Publish HTTPS records.
18
18
  - [x] [resolveHttps](#resolveHttps): Resolve HTTPS records.
19
+ - [x] [signUp](#signUp): Sign-up to a homeserver and update Pkarr accordingly.
20
+ - [x] [signIn](#signIn): Sign-in to a homeserver.
21
+ - [x] [signOut](#signOut): Sign-out from a homeserver.
19
22
  - [x] [put](#put): Upload a small payload to a given path.
20
23
  - [x] [get](#get): Download a small payload from a given path relative to a pubky author.
21
24
  - [x] [list](#list): Returns a list of Pubky URLs of the files in the path of the `url` provided.
22
25
  - [x] [generateSecretKey](#generateSecretKey): Generate a secret key.
23
26
  - [x] [getPublicKeyFromSecretKey](#getPublicKeyFromSecretKey): Get the public key string and uri from a secret key.
24
27
  ### Methods to be Implemented
25
- - [ ] signIn: Sign-in to a homeserver.
26
- - [ ] signUp: Sign-up to a homeserver and update Pkarr accordingly.
27
- - [ ] signOut: Sign-out from a homeserver.
28
+ - [ ] getProfile: Retrieve the profile of a user.
29
+ - [ ] editProfile: Submit changes to the specified profile.
28
30
 
29
31
 
30
32
  ## Usage
@@ -118,8 +120,8 @@ console.log(resolveHttpsRes.value);
118
120
  import { put } from '@synonymdev/react-native-pubky';
119
121
 
120
122
  const putRes = await put(
121
- 'url', // URL
122
- 'content', // Content
123
+ 'pubky://z4e8s17cou9qmuwen8p1556jzhf1wktmzo6ijsfnri9c4hnrdfty/pub/synonym.to', // URL
124
+ { data: 'test content' }, // Content
123
125
  );
124
126
  if (putRes.isErr()) {
125
127
  console.log(putRes.error.message);
@@ -133,7 +135,7 @@ console.log(putRes.value);
133
135
  import { get } from '@synonymdev/react-native-pubky';
134
136
 
135
137
  const getRes = await get(
136
- 'url' // URL
138
+ 'pubky://z4e8s17cou9qmuwen8p1556jzhf1wktmzo6ijsfnri9c4hnrdfty/pub/synonym.to' // URL
137
139
  );
138
140
  if (getRes.isErr()) {
139
141
  console.log(getRes.error.message);
@@ -147,7 +149,7 @@ console.log(getRes.value);
147
149
  import { list } from '@synonymdev/react-native-pubky';
148
150
 
149
151
  const listRes = await list(
150
- 'url' // URL
152
+ 'pubky://z4e8s17cou9qmuwen8p1556jzhf1wktmzo6ijsfnri9c4hnrdfty/pub/' // URL
151
153
  );
152
154
  if (listRes.isErr()) {
153
155
  console.log(listRes.error.message);
@@ -180,6 +182,49 @@ if (getPublicKeyFromSecretKeyRes.isErr()) {
180
182
  console.log(getPublicKeyFromSecretKeyRes.value);
181
183
  ```
182
184
 
185
+ ### <a name="signUp"></a>signUp
186
+ ```js
187
+ import { signUp } from '@synonymdev/react-native-pubky';
188
+
189
+ const signUpRes = await signUp(
190
+ 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', // Secret
191
+ 'pubky://8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo', // Homeserver
192
+ );
193
+ if (signUpRes.isErr()) {
194
+ console.log(signUpRes.error.message);
195
+ return;
196
+ }
197
+ console.log(signUpRes.value);
198
+ ```
199
+
200
+ ### <a name="signIn"></a>signIn
201
+ ```js
202
+ import { signIn } from '@synonymdev/react-native-pubky';
203
+
204
+ const signInRes = await signIn(
205
+ 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' // Secret Key
206
+ );
207
+ if (signInRes.isErr()) {
208
+ console.log(signInRes.error.message);
209
+ return;
210
+ }
211
+ console.log(signInRes.value);
212
+ ```
213
+
214
+ ### <a name="signOut"></a>signIn
215
+ ```js
216
+ import { signOut } from '@synonymdev/react-native-pubky';
217
+
218
+ const signOutRes = await signOut(
219
+ 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' // Secret Key
220
+ );
221
+ if (signOutRes.isErr()) {
222
+ console.log(signOutRes.error.message);
223
+ return;
224
+ }
225
+ console.log(signOutRes.value);
226
+ ```
227
+
183
228
  ## Local Installation
184
229
 
185
230
  1. Clone & npm install:
@@ -10,7 +10,7 @@
10
10
  <key>HeadersPath</key>
11
11
  <string>Headers</string>
12
12
  <key>LibraryIdentifier</key>
13
- <string>ios-arm64</string>
13
+ <string>ios-arm64-simulator</string>
14
14
  <key>LibraryPath</key>
15
15
  <string>libpubkymobile.a</string>
16
16
  <key>SupportedArchitectures</key>
@@ -19,6 +19,8 @@
19
19
  </array>
20
20
  <key>SupportedPlatform</key>
21
21
  <string>ios</string>
22
+ <key>SupportedPlatformVariant</key>
23
+ <string>simulator</string>
22
24
  </dict>
23
25
  <dict>
24
26
  <key>BinaryPath</key>
@@ -26,7 +28,7 @@
26
28
  <key>HeadersPath</key>
27
29
  <string>Headers</string>
28
30
  <key>LibraryIdentifier</key>
29
- <string>ios-arm64-simulator</string>
31
+ <string>ios-arm64</string>
30
32
  <key>LibraryPath</key>
31
33
  <string>libpubkymobile.a</string>
32
34
  <key>SupportedArchitectures</key>
@@ -35,8 +37,6 @@
35
37
  </array>
36
38
  <key>SupportedPlatform</key>
37
39
  <string>ios</string>
38
- <key>SupportedPlatformVariant</key>
39
- <string>simulator</string>
40
40
  </dict>
41
41
  </array>
42
42
  <key>CFBundlePackageType</key>
@@ -68,7 +68,7 @@ RustBuffer uniffi_pubkymobile_fn_func_auth(RustBuffer url, RustBuffer secret_key
68
68
  RustBuffer uniffi_pubkymobile_fn_func_generate_secret_key(RustCallStatus *_Nonnull out_status
69
69
 
70
70
  );
71
- void* _Nonnull uniffi_pubkymobile_fn_func_get(RustBuffer url
71
+ RustBuffer uniffi_pubkymobile_fn_func_get(RustBuffer url, RustCallStatus *_Nonnull out_status
72
72
  );
73
73
  RustBuffer uniffi_pubkymobile_fn_func_get_public_key_from_secret_key(RustBuffer secret_key, RustCallStatus *_Nonnull out_status
74
74
  );
@@ -80,17 +80,17 @@ RustBuffer uniffi_pubkymobile_fn_func_publish(RustBuffer record_name, RustBuffer
80
80
  );
81
81
  RustBuffer uniffi_pubkymobile_fn_func_publish_https(RustBuffer record_name, RustBuffer target, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
82
82
  );
83
- void* _Nonnull uniffi_pubkymobile_fn_func_put(RustBuffer url, RustBuffer content
83
+ RustBuffer uniffi_pubkymobile_fn_func_put(RustBuffer url, RustBuffer content, RustCallStatus *_Nonnull out_status
84
84
  );
85
85
  RustBuffer uniffi_pubkymobile_fn_func_resolve(RustBuffer public_key, RustCallStatus *_Nonnull out_status
86
86
  );
87
87
  RustBuffer uniffi_pubkymobile_fn_func_resolve_https(RustBuffer public_key, RustCallStatus *_Nonnull out_status
88
88
  );
89
- void* _Nonnull uniffi_pubkymobile_fn_func_sign_in(RustBuffer secret_key
89
+ RustBuffer uniffi_pubkymobile_fn_func_sign_in(RustBuffer secret_key, RustCallStatus *_Nonnull out_status
90
90
  );
91
- void* _Nonnull uniffi_pubkymobile_fn_func_sign_out(RustBuffer secret_key
91
+ RustBuffer uniffi_pubkymobile_fn_func_sign_out(RustBuffer secret_key, RustCallStatus *_Nonnull out_status
92
92
  );
93
- void* _Nonnull uniffi_pubkymobile_fn_func_sign_up(RustBuffer secret_key, RustBuffer homeserver
93
+ RustBuffer uniffi_pubkymobile_fn_func_sign_up(RustBuffer secret_key, RustBuffer homeserver, RustCallStatus *_Nonnull out_status
94
94
  );
95
95
  RustBuffer ffi_pubkymobile_rustbuffer_alloc(int32_t size, RustCallStatus *_Nonnull out_status
96
96
  );
@@ -68,7 +68,7 @@ RustBuffer uniffi_pubkymobile_fn_func_auth(RustBuffer url, RustBuffer secret_key
68
68
  RustBuffer uniffi_pubkymobile_fn_func_generate_secret_key(RustCallStatus *_Nonnull out_status
69
69
 
70
70
  );
71
- void* _Nonnull uniffi_pubkymobile_fn_func_get(RustBuffer url
71
+ RustBuffer uniffi_pubkymobile_fn_func_get(RustBuffer url, RustCallStatus *_Nonnull out_status
72
72
  );
73
73
  RustBuffer uniffi_pubkymobile_fn_func_get_public_key_from_secret_key(RustBuffer secret_key, RustCallStatus *_Nonnull out_status
74
74
  );
@@ -80,17 +80,17 @@ RustBuffer uniffi_pubkymobile_fn_func_publish(RustBuffer record_name, RustBuffer
80
80
  );
81
81
  RustBuffer uniffi_pubkymobile_fn_func_publish_https(RustBuffer record_name, RustBuffer target, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
82
82
  );
83
- void* _Nonnull uniffi_pubkymobile_fn_func_put(RustBuffer url, RustBuffer content
83
+ RustBuffer uniffi_pubkymobile_fn_func_put(RustBuffer url, RustBuffer content, RustCallStatus *_Nonnull out_status
84
84
  );
85
85
  RustBuffer uniffi_pubkymobile_fn_func_resolve(RustBuffer public_key, RustCallStatus *_Nonnull out_status
86
86
  );
87
87
  RustBuffer uniffi_pubkymobile_fn_func_resolve_https(RustBuffer public_key, RustCallStatus *_Nonnull out_status
88
88
  );
89
- void* _Nonnull uniffi_pubkymobile_fn_func_sign_in(RustBuffer secret_key
89
+ RustBuffer uniffi_pubkymobile_fn_func_sign_in(RustBuffer secret_key, RustCallStatus *_Nonnull out_status
90
90
  );
91
- void* _Nonnull uniffi_pubkymobile_fn_func_sign_out(RustBuffer secret_key
91
+ RustBuffer uniffi_pubkymobile_fn_func_sign_out(RustBuffer secret_key, RustCallStatus *_Nonnull out_status
92
92
  );
93
- void* _Nonnull uniffi_pubkymobile_fn_func_sign_up(RustBuffer secret_key, RustBuffer homeserver
93
+ RustBuffer uniffi_pubkymobile_fn_func_sign_up(RustBuffer secret_key, RustBuffer homeserver, RustCallStatus *_Nonnull out_status
94
94
  );
95
95
  RustBuffer ffi_pubkymobile_rustbuffer_alloc(int32_t size, RustCallStatus *_Nonnull out_status
96
96
  );
@@ -356,68 +356,6 @@ 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
-
418
- fileprivate func uniffiInitContinuationCallback() {
419
- ffi_pubkymobile_rust_future_continuation_callback_set(uniffiFutureContinuationCallback)
420
- }
421
359
 
422
360
  public func auth(url: String, secretKey: String) -> [String] {
423
361
  return try! FfiConverterSequenceString.lift(
@@ -437,24 +375,15 @@ public func generateSecretKey() -> [String] {
437
375
  )
438
376
  }
439
377
 
440
- public func get(url: String) async -> [String] {
441
- return try! await uniffiRustCallAsync(
442
- rustFutureFunc: {
443
- uniffi_pubkymobile_fn_func_get(
444
- FfiConverterString.lower(url)
445
- )
446
- },
447
- pollFunc: ffi_pubkymobile_rust_future_poll_rust_buffer,
448
- completeFunc: ffi_pubkymobile_rust_future_complete_rust_buffer,
449
- freeFunc: ffi_pubkymobile_rust_future_free_rust_buffer,
450
- liftFunc: FfiConverterSequenceString.lift,
451
- errorHandler: nil
452
-
378
+ public func get(url: String) -> [String] {
379
+ return try! FfiConverterSequenceString.lift(
380
+ try! rustCall() {
381
+ uniffi_pubkymobile_fn_func_get(
382
+ FfiConverterString.lower(url),$0)
383
+ }
453
384
  )
454
385
  }
455
386
 
456
-
457
-
458
387
  public func getPublicKeyFromSecretKey(secretKey: String) -> [String] {
459
388
  return try! FfiConverterSequenceString.lift(
460
389
  try! rustCall() {
@@ -504,25 +433,16 @@ public func publishHttps(recordName: String, target: String, secretKey: String)
504
433
  )
505
434
  }
506
435
 
507
- public func put(url: String, content: String) async -> [String] {
508
- return try! await uniffiRustCallAsync(
509
- rustFutureFunc: {
510
- uniffi_pubkymobile_fn_func_put(
511
- FfiConverterString.lower(url),
512
- FfiConverterString.lower(content)
513
- )
514
- },
515
- pollFunc: ffi_pubkymobile_rust_future_poll_rust_buffer,
516
- completeFunc: ffi_pubkymobile_rust_future_complete_rust_buffer,
517
- freeFunc: ffi_pubkymobile_rust_future_free_rust_buffer,
518
- liftFunc: FfiConverterSequenceString.lift,
519
- errorHandler: nil
520
-
436
+ public func put(url: String, content: String) -> [String] {
437
+ return try! FfiConverterSequenceString.lift(
438
+ try! rustCall() {
439
+ uniffi_pubkymobile_fn_func_put(
440
+ FfiConverterString.lower(url),
441
+ FfiConverterString.lower(content),$0)
442
+ }
521
443
  )
522
444
  }
523
445
 
524
-
525
-
526
446
  public func resolve(publicKey: String) -> [String] {
527
447
  return try! FfiConverterSequenceString.lift(
528
448
  try! rustCall() {
@@ -541,61 +461,34 @@ public func resolveHttps(publicKey: String) -> [String] {
541
461
  )
542
462
  }
543
463
 
544
- public func signIn(secretKey: String) async -> [String] {
545
- return try! await uniffiRustCallAsync(
546
- rustFutureFunc: {
547
- uniffi_pubkymobile_fn_func_sign_in(
548
- FfiConverterString.lower(secretKey)
549
- )
550
- },
551
- pollFunc: ffi_pubkymobile_rust_future_poll_rust_buffer,
552
- completeFunc: ffi_pubkymobile_rust_future_complete_rust_buffer,
553
- freeFunc: ffi_pubkymobile_rust_future_free_rust_buffer,
554
- liftFunc: FfiConverterSequenceString.lift,
555
- errorHandler: nil
556
-
464
+ public func signIn(secretKey: String) -> [String] {
465
+ return try! FfiConverterSequenceString.lift(
466
+ try! rustCall() {
467
+ uniffi_pubkymobile_fn_func_sign_in(
468
+ FfiConverterString.lower(secretKey),$0)
469
+ }
557
470
  )
558
471
  }
559
472
 
560
-
561
-
562
- public func signOut(secretKey: String) async -> [String] {
563
- return try! await uniffiRustCallAsync(
564
- rustFutureFunc: {
565
- uniffi_pubkymobile_fn_func_sign_out(
566
- FfiConverterString.lower(secretKey)
567
- )
568
- },
569
- pollFunc: ffi_pubkymobile_rust_future_poll_rust_buffer,
570
- completeFunc: ffi_pubkymobile_rust_future_complete_rust_buffer,
571
- freeFunc: ffi_pubkymobile_rust_future_free_rust_buffer,
572
- liftFunc: FfiConverterSequenceString.lift,
573
- errorHandler: nil
574
-
473
+ public func signOut(secretKey: String) -> [String] {
474
+ return try! FfiConverterSequenceString.lift(
475
+ try! rustCall() {
476
+ uniffi_pubkymobile_fn_func_sign_out(
477
+ FfiConverterString.lower(secretKey),$0)
478
+ }
575
479
  )
576
480
  }
577
481
 
578
-
579
-
580
- public func signUp(secretKey: String, homeserver: String) async -> [String] {
581
- return try! await uniffiRustCallAsync(
582
- rustFutureFunc: {
583
- uniffi_pubkymobile_fn_func_sign_up(
584
- FfiConverterString.lower(secretKey),
585
- FfiConverterString.lower(homeserver)
586
- )
587
- },
588
- pollFunc: ffi_pubkymobile_rust_future_poll_rust_buffer,
589
- completeFunc: ffi_pubkymobile_rust_future_complete_rust_buffer,
590
- freeFunc: ffi_pubkymobile_rust_future_free_rust_buffer,
591
- liftFunc: FfiConverterSequenceString.lift,
592
- errorHandler: nil
593
-
482
+ public func signUp(secretKey: String, homeserver: String) -> [String] {
483
+ return try! FfiConverterSequenceString.lift(
484
+ try! rustCall() {
485
+ uniffi_pubkymobile_fn_func_sign_up(
486
+ FfiConverterString.lower(secretKey),
487
+ FfiConverterString.lower(homeserver),$0)
488
+ }
594
489
  )
595
490
  }
596
491
 
597
-
598
-
599
492
  private enum InitializationResult {
600
493
  case ok
601
494
  case contractVersionMismatch
@@ -617,7 +510,7 @@ private var initializationResult: InitializationResult {
617
510
  if (uniffi_pubkymobile_checksum_func_generate_secret_key() != 63116) {
618
511
  return InitializationResult.apiChecksumMismatch
619
512
  }
620
- if (uniffi_pubkymobile_checksum_func_get() != 5395) {
513
+ if (uniffi_pubkymobile_checksum_func_get() != 21596) {
621
514
  return InitializationResult.apiChecksumMismatch
622
515
  }
623
516
  if (uniffi_pubkymobile_checksum_func_get_public_key_from_secret_key() != 23603) {
@@ -635,7 +528,7 @@ private var initializationResult: InitializationResult {
635
528
  if (uniffi_pubkymobile_checksum_func_publish_https() != 14705) {
636
529
  return InitializationResult.apiChecksumMismatch
637
530
  }
638
- if (uniffi_pubkymobile_checksum_func_put() != 47594) {
531
+ if (uniffi_pubkymobile_checksum_func_put() != 51107) {
639
532
  return InitializationResult.apiChecksumMismatch
640
533
  }
641
534
  if (uniffi_pubkymobile_checksum_func_resolve() != 18303) {
@@ -644,17 +537,16 @@ private var initializationResult: InitializationResult {
644
537
  if (uniffi_pubkymobile_checksum_func_resolve_https() != 34593) {
645
538
  return InitializationResult.apiChecksumMismatch
646
539
  }
647
- if (uniffi_pubkymobile_checksum_func_sign_in() != 53969) {
540
+ if (uniffi_pubkymobile_checksum_func_sign_in() != 21006) {
648
541
  return InitializationResult.apiChecksumMismatch
649
542
  }
650
- if (uniffi_pubkymobile_checksum_func_sign_out() != 32961) {
543
+ if (uniffi_pubkymobile_checksum_func_sign_out() != 59116) {
651
544
  return InitializationResult.apiChecksumMismatch
652
545
  }
653
- if (uniffi_pubkymobile_checksum_func_sign_up() != 28083) {
546
+ if (uniffi_pubkymobile_checksum_func_sign_up() != 58756) {
654
547
  return InitializationResult.apiChecksumMismatch
655
548
  }
656
549
 
657
- uniffiInitContinuationCallback()
658
550
  return InitializationResult.ok
659
551
  }
660
552
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synonymdev/react-native-pubky",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "React Native Implementation of Pubky",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",