@synonymdev/react-native-pubky 0.7.1 → 0.9.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.
@@ -5,6 +5,7 @@ import com.facebook.react.bridge.ReactApplicationContext
5
5
  import com.facebook.react.bridge.ReactContextBaseJavaModule
6
6
  import com.facebook.react.bridge.ReactMethod
7
7
  import com.facebook.react.bridge.Promise
8
+ import com.facebook.react.modules.core.DeviceEventManagerModule
8
9
  import kotlinx.coroutines.CoroutineScope
9
10
  import kotlinx.coroutines.Dispatchers
10
11
  import kotlinx.coroutines.launch
@@ -12,273 +13,389 @@ import kotlinx.coroutines.withContext
12
13
  import uniffi.pubkymobile.*
13
14
 
14
15
  class PubkyModule(reactContext: ReactApplicationContext) :
15
- ReactContextBaseJavaModule(reactContext) {
16
+ ReactContextBaseJavaModule(reactContext) {
16
17
 
17
- override fun getName(): String {
18
- return NAME
19
- }
18
+ override fun getName(): String {
19
+ return NAME
20
+ }
20
21
 
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
- }
22
+ private val eventListener = object : EventListener {
23
+ override fun onEventOccurred(eventData: String) {
24
+ reactContext
25
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
26
+ .emit("PubkyEvent", eventData)
27
+ }
28
+ }
39
29
 
40
- @ReactMethod
41
- fun parseAuthUrl(url: String, promise: Promise) {
42
- try {
43
- val result = parseAuthUrl(url)
44
- val array = Arguments.createArray().apply {
45
- result.forEach { pushString(it) }
46
- }
47
- promise.resolve(array)
48
- } catch (e: Exception) {
49
- promise.reject("Error", e.message)
30
+ @ReactMethod
31
+ fun setEventListener(promise: Promise) {
32
+ CoroutineScope(Dispatchers.IO).launch {
33
+ try {
34
+ setEventListener(eventListener)
35
+ withContext(Dispatchers.Main) {
36
+ promise.resolve(null)
37
+ }
38
+ } catch (e: Exception) {
39
+ withContext(Dispatchers.Main) {
40
+ promise.reject("Error", e.message)
41
+ }
42
+ }
43
+ }
50
44
  }
51
- }
52
45
 
53
- @ReactMethod
54
- fun publish(recordName: String, recordContent: String, secretKey: String, promise: Promise) {
55
- CoroutineScope(Dispatchers.IO).launch {
56
- try {
57
- val result = publish(recordName, recordContent, secretKey)
58
- val array = Arguments.createArray().apply {
59
- result.forEach { pushString(it) }
60
- }
61
- withContext(Dispatchers.Main) {
62
- promise.resolve(array)
63
- }
64
- } catch (e: Exception) {
65
- withContext(Dispatchers.Main) {
66
- promise.reject("Error", e.message)
67
- }
68
- }
69
- }
70
- }
46
+ @ReactMethod
47
+ fun removeEventListener(promise: Promise) {
48
+ CoroutineScope(Dispatchers.IO).launch {
49
+ try {
50
+ removeEventListener()
51
+ withContext(Dispatchers.Main) {
52
+ promise.resolve(null)
53
+ }
54
+ } catch (e: Exception) {
55
+ withContext(Dispatchers.Main) {
56
+ promise.reject("Error", e.message)
57
+ }
58
+ }
59
+ }
60
+ }
71
61
 
72
- @ReactMethod
73
- fun resolve(publicKey: String, promise: Promise) {
74
- CoroutineScope(Dispatchers.IO).launch {
75
- try {
76
- val result = resolve(publicKey)
77
- val array = Arguments.createArray().apply {
78
- result.forEach { pushString(it) }
79
- }
80
- withContext(Dispatchers.Main) {
81
- promise.resolve(array)
82
- }
83
- } catch (e: Exception) {
84
- withContext(Dispatchers.Main) {
85
- promise.reject("Error", e.message)
86
- }
87
- }
88
- }
89
- }
62
+ @ReactMethod
63
+ fun deleteFile(url: String, promise: Promise) {
64
+ CoroutineScope(Dispatchers.IO).launch {
65
+ try {
66
+ val result = deleteFile(url)
67
+ val array = Arguments.createArray().apply {
68
+ result.forEach { pushString(it) }
69
+ }
70
+ withContext(Dispatchers.Main) {
71
+ promise.resolve(array)
72
+ }
73
+ } catch (e: Exception) {
74
+ withContext(Dispatchers.Main) {
75
+ promise.reject("Error", e.message)
76
+ }
77
+ }
78
+ }
79
+ }
90
80
 
91
- @ReactMethod
92
- fun signUp(secretKey: String, homeserver: String, promise: Promise) {
93
- CoroutineScope(Dispatchers.IO).launch {
94
- try {
95
- val result = signUp(secretKey, homeserver)
96
- val array = Arguments.createArray().apply {
97
- result.forEach { pushString(it) }
98
- }
99
- withContext(Dispatchers.Main) {
100
- promise.resolve(array)
101
- }
102
- } catch (e: Exception) {
103
- withContext(Dispatchers.Main) {
104
- promise.reject("Error", e.message)
105
- }
106
- }
107
- }
108
- }
81
+ @ReactMethod
82
+ fun session(pubky: String, promise: Promise) {
83
+ CoroutineScope(Dispatchers.IO).launch {
84
+ try {
85
+ val result = session(pubky)
86
+ val array = Arguments.createArray().apply {
87
+ result.forEach { pushString(it) }
88
+ }
89
+ withContext(Dispatchers.Main) {
90
+ promise.resolve(array)
91
+ }
92
+ } catch (e: Exception) {
93
+ withContext(Dispatchers.Main) {
94
+ promise.reject("Error", e.message)
95
+ }
96
+ }
97
+ }
98
+ }
109
99
 
110
- @ReactMethod
111
- fun signIn(secretKey: String, promise: Promise) {
112
- CoroutineScope(Dispatchers.IO).launch {
113
- try {
114
- val result = signIn(secretKey)
115
- val array = Arguments.createArray().apply {
116
- result.forEach { pushString(it) }
117
- }
118
- withContext(Dispatchers.Main) {
119
- promise.resolve(array)
120
- }
121
- } catch (e: Exception) {
122
- withContext(Dispatchers.Main) {
123
- promise.reject("Error", e.message)
124
- }
125
- }
126
- }
127
- }
100
+ @ReactMethod
101
+ fun auth(url: String, secretKey: String, promise: Promise) {
102
+ CoroutineScope(Dispatchers.IO).launch {
103
+ try {
104
+ val result = auth(url, secretKey)
105
+ val array = Arguments.createArray().apply {
106
+ result.forEach { pushString(it) }
107
+ }
108
+ withContext(Dispatchers.Main) {
109
+ promise.resolve(array)
110
+ }
111
+ } catch (e: Exception) {
112
+ withContext(Dispatchers.Main) {
113
+ promise.reject("Error", e.message)
114
+ }
115
+ }
116
+ }
117
+ }
128
118
 
129
- @ReactMethod
130
- fun signOut(secretKey: String, promise: Promise) {
131
- CoroutineScope(Dispatchers.IO).launch {
132
- try {
133
- val result = signOut(secretKey)
134
- val array = Arguments.createArray().apply {
135
- result.forEach { pushString(it) }
136
- }
137
- withContext(Dispatchers.Main) {
138
- promise.resolve(array)
139
- }
140
- } catch (e: Exception) {
141
- withContext(Dispatchers.Main) {
142
- promise.reject("Error", e.message)
143
- }
144
- }
145
- }
146
- }
119
+ @ReactMethod
120
+ fun parseAuthUrl(url: String, promise: Promise) {
121
+ try {
122
+ val result = parseAuthUrl(url)
123
+ val array = Arguments.createArray().apply {
124
+ result.forEach { pushString(it) }
125
+ }
126
+ promise.resolve(array)
127
+ } catch (e: Exception) {
128
+ promise.reject("Error", e.message)
129
+ }
130
+ }
147
131
 
148
- @ReactMethod
149
- fun put(url: String, content: String, promise: Promise) {
150
- CoroutineScope(Dispatchers.IO).launch {
151
- try {
152
- val result = put(url, content)
153
- val array = Arguments.createArray().apply {
154
- result.forEach { pushString(it) }
155
- }
156
- withContext(Dispatchers.Main) {
157
- promise.resolve(array)
158
- }
159
- } catch (e: Exception) {
160
- withContext(Dispatchers.Main) {
161
- promise.reject("Error", e.message)
162
- }
163
- }
164
- }
165
- }
132
+ @ReactMethod
133
+ fun publish(recordName: String, recordContent: String, secretKey: String, promise: Promise) {
134
+ CoroutineScope(Dispatchers.IO).launch {
135
+ try {
136
+ val result = publish(recordName, recordContent, secretKey)
137
+ val array = Arguments.createArray().apply {
138
+ result.forEach { pushString(it) }
139
+ }
140
+ withContext(Dispatchers.Main) {
141
+ promise.resolve(array)
142
+ }
143
+ } catch (e: Exception) {
144
+ withContext(Dispatchers.Main) {
145
+ promise.reject("Error", e.message)
146
+ }
147
+ }
148
+ }
149
+ }
166
150
 
167
- @ReactMethod
168
- fun get(url: String, promise: Promise) {
169
- CoroutineScope(Dispatchers.IO).launch {
170
- try {
171
- val result = get(url)
172
- val array = Arguments.createArray().apply {
173
- result.forEach { pushString(it) }
174
- }
175
- withContext(Dispatchers.Main) {
176
- promise.resolve(array)
177
- }
178
- } catch (e: Exception) {
179
- withContext(Dispatchers.Main) {
180
- promise.reject("Error", e.message)
181
- }
182
- }
183
- }
184
- }
151
+ @ReactMethod
152
+ fun resolve(publicKey: String, promise: Promise) {
153
+ CoroutineScope(Dispatchers.IO).launch {
154
+ try {
155
+ val result = resolve(publicKey)
156
+ val array = Arguments.createArray().apply {
157
+ result.forEach { pushString(it) }
158
+ }
159
+ withContext(Dispatchers.Main) {
160
+ promise.resolve(array)
161
+ }
162
+ } catch (e: Exception) {
163
+ withContext(Dispatchers.Main) {
164
+ promise.reject("Error", e.message)
165
+ }
166
+ }
167
+ }
168
+ }
185
169
 
186
- @ReactMethod
187
- fun publishHttps(recordName: String, target: String, secretKey: String, promise: Promise) {
188
- CoroutineScope(Dispatchers.IO).launch {
189
- try {
190
- val result = publishHttps(recordName, target, secretKey)
191
- val array = Arguments.createArray().apply {
192
- result.forEach { pushString(it) }
193
- }
194
- withContext(Dispatchers.Main) {
195
- promise.resolve(array)
196
- }
197
- } catch (e: Exception) {
198
- withContext(Dispatchers.Main) {
199
- promise.reject("Error", e.message)
200
- }
201
- }
202
- }
203
- }
170
+ @ReactMethod
171
+ fun signUp(secretKey: String, homeserver: String, promise: Promise) {
172
+ CoroutineScope(Dispatchers.IO).launch {
173
+ try {
174
+ val result = signUp(secretKey, homeserver)
175
+ val array = Arguments.createArray().apply {
176
+ result.forEach { pushString(it) }
177
+ }
178
+ withContext(Dispatchers.Main) {
179
+ promise.resolve(array)
180
+ }
181
+ } catch (e: Exception) {
182
+ withContext(Dispatchers.Main) {
183
+ promise.reject("Error", e.message)
184
+ }
185
+ }
186
+ }
187
+ }
204
188
 
205
- @ReactMethod
206
- fun resolveHttps(publicKey: String, promise: Promise) {
207
- CoroutineScope(Dispatchers.IO).launch {
208
- try {
209
- val result = resolveHttps(publicKey)
210
- val array = Arguments.createArray().apply {
211
- result.forEach { pushString(it) }
212
- }
213
- withContext(Dispatchers.Main) {
214
- promise.resolve(array)
215
- }
216
- } catch (e: Exception) {
217
- withContext(Dispatchers.Main) {
218
- promise.reject("Error", e.message)
219
- }
220
- }
221
- }
222
- }
189
+ @ReactMethod
190
+ fun signIn(secretKey: String, promise: Promise) {
191
+ CoroutineScope(Dispatchers.IO).launch {
192
+ try {
193
+ val result = signIn(secretKey)
194
+ val array = Arguments.createArray().apply {
195
+ result.forEach { pushString(it) }
196
+ }
197
+ withContext(Dispatchers.Main) {
198
+ promise.resolve(array)
199
+ }
200
+ } catch (e: Exception) {
201
+ withContext(Dispatchers.Main) {
202
+ promise.reject("Error", e.message)
203
+ }
204
+ }
205
+ }
206
+ }
223
207
 
224
- @ReactMethod
225
- fun list(url: String, promise: Promise) {
226
- CoroutineScope(Dispatchers.IO).launch {
227
- try {
228
- val result = list(url)
229
- val array = Arguments.createArray().apply {
230
- result.forEach { pushString(it) }
231
- }
232
- withContext(Dispatchers.Main) {
233
- promise.resolve(array)
234
- }
235
- } catch (e: Exception) {
236
- withContext(Dispatchers.Main) {
237
- promise.reject("Error", e.message)
238
- }
239
- }
240
- }
241
- }
208
+ @ReactMethod
209
+ fun signOut(secretKey: String, promise: Promise) {
210
+ CoroutineScope(Dispatchers.IO).launch {
211
+ try {
212
+ val result = signOut(secretKey)
213
+ val array = Arguments.createArray().apply {
214
+ result.forEach { pushString(it) }
215
+ }
216
+ withContext(Dispatchers.Main) {
217
+ promise.resolve(array)
218
+ }
219
+ } catch (e: Exception) {
220
+ withContext(Dispatchers.Main) {
221
+ promise.reject("Error", e.message)
222
+ }
223
+ }
224
+ }
225
+ }
242
226
 
243
- @ReactMethod
244
- fun generateSecretKey(promise: Promise) {
245
- CoroutineScope(Dispatchers.IO).launch {
246
- try {
247
- val result = generate_secret_key()
248
- val array = Arguments.createArray().apply {
249
- result.forEach { pushString(it) }
250
- }
251
- withContext(Dispatchers.Main) {
252
- promise.resolve(array)
253
- }
254
- } catch (e: Exception) {
255
- withContext(Dispatchers.Main) {
256
- promise.reject("Error", e.message)
257
- }
258
- }
259
- }
260
- }
227
+ @ReactMethod
228
+ fun put(url: String, content: String, promise: Promise) {
229
+ CoroutineScope(Dispatchers.IO).launch {
230
+ try {
231
+ val result = put(url, content)
232
+ val array = Arguments.createArray().apply {
233
+ result.forEach { pushString(it) }
234
+ }
235
+ withContext(Dispatchers.Main) {
236
+ promise.resolve(array)
237
+ }
238
+ } catch (e: Exception) {
239
+ withContext(Dispatchers.Main) {
240
+ promise.reject("Error", e.message)
241
+ }
242
+ }
243
+ }
244
+ }
261
245
 
262
- @ReactMethod
263
- fun getPublicKeyFromSecretKey(secretKey: String, promise: Promise) {
264
- CoroutineScope(Dispatchers.IO).launch {
265
- try {
266
- val result = getPublicKeyFromSecretKey(secretKey)
267
- val array = Arguments.createArray().apply {
268
- result.forEach { pushString(it) }
269
- }
270
- withContext(Dispatchers.Main) {
271
- promise.resolve(array)
272
- }
273
- } catch (e: Exception) {
274
- withContext(Dispatchers.Main) {
275
- promise.reject("Error", e.message)
276
- }
277
- }
278
- }
279
- }
246
+ @ReactMethod
247
+ fun get(url: String, promise: Promise) {
248
+ CoroutineScope(Dispatchers.IO).launch {
249
+ try {
250
+ val result = get(url)
251
+ val array = Arguments.createArray().apply {
252
+ result.forEach { pushString(it) }
253
+ }
254
+ withContext(Dispatchers.Main) {
255
+ promise.resolve(array)
256
+ }
257
+ } catch (e: Exception) {
258
+ withContext(Dispatchers.Main) {
259
+ promise.reject("Error", e.message)
260
+ }
261
+ }
262
+ }
263
+ }
280
264
 
281
- companion object {
282
- const val NAME = "Pubky"
283
- }
265
+ @ReactMethod
266
+ fun publishHttps(recordName: String, target: String, secretKey: String, promise: Promise) {
267
+ CoroutineScope(Dispatchers.IO).launch {
268
+ try {
269
+ val result = publishHttps(recordName, target, secretKey)
270
+ val array = Arguments.createArray().apply {
271
+ result.forEach { pushString(it) }
272
+ }
273
+ withContext(Dispatchers.Main) {
274
+ promise.resolve(array)
275
+ }
276
+ } catch (e: Exception) {
277
+ withContext(Dispatchers.Main) {
278
+ promise.reject("Error", e.message)
279
+ }
280
+ }
281
+ }
282
+ }
283
+
284
+ @ReactMethod
285
+ fun resolveHttps(publicKey: String, promise: Promise) {
286
+ CoroutineScope(Dispatchers.IO).launch {
287
+ try {
288
+ val result = resolveHttps(publicKey)
289
+ val array = Arguments.createArray().apply {
290
+ result.forEach { pushString(it) }
291
+ }
292
+ withContext(Dispatchers.Main) {
293
+ promise.resolve(array)
294
+ }
295
+ } catch (e: Exception) {
296
+ withContext(Dispatchers.Main) {
297
+ promise.reject("Error", e.message)
298
+ }
299
+ }
300
+ }
301
+ }
302
+
303
+ @ReactMethod
304
+ fun list(url: String, promise: Promise) {
305
+ CoroutineScope(Dispatchers.IO).launch {
306
+ try {
307
+ val result = list(url)
308
+ val array = Arguments.createArray().apply {
309
+ result.forEach { pushString(it) }
310
+ }
311
+ withContext(Dispatchers.Main) {
312
+ promise.resolve(array)
313
+ }
314
+ } catch (e: Exception) {
315
+ withContext(Dispatchers.Main) {
316
+ promise.reject("Error", e.message)
317
+ }
318
+ }
319
+ }
320
+ }
321
+
322
+ @ReactMethod
323
+ fun generateSecretKey(promise: Promise) {
324
+ CoroutineScope(Dispatchers.IO).launch {
325
+ try {
326
+ val result = generateSecretKey()
327
+ val array = Arguments.createArray().apply {
328
+ result.forEach { pushString(it) }
329
+ }
330
+ withContext(Dispatchers.Main) {
331
+ promise.resolve(array)
332
+ }
333
+ } catch (e: Exception) {
334
+ withContext(Dispatchers.Main) {
335
+ promise.reject("Error", e.message)
336
+ }
337
+ }
338
+ }
339
+ }
340
+
341
+ @ReactMethod
342
+ fun getPublicKeyFromSecretKey(secretKey: String, promise: Promise) {
343
+ CoroutineScope(Dispatchers.IO).launch {
344
+ try {
345
+ val result = getPublicKeyFromSecretKey(secretKey)
346
+ val array = Arguments.createArray().apply {
347
+ result.forEach { pushString(it) }
348
+ }
349
+ withContext(Dispatchers.Main) {
350
+ promise.resolve(array)
351
+ }
352
+ } catch (e: Exception) {
353
+ withContext(Dispatchers.Main) {
354
+ promise.reject("Error", e.message)
355
+ }
356
+ }
357
+ }
358
+ }
359
+
360
+ @ReactMethod
361
+ fun createRecoveryFile(secretKey: String, passphrase: String, promise: Promise) {
362
+ CoroutineScope(Dispatchers.IO).launch {
363
+ try {
364
+ val result = createRecoveryFile(secretKey, passphrase)
365
+ val array = Arguments.createArray().apply {
366
+ result.forEach { pushString(it) }
367
+ }
368
+ withContext(Dispatchers.Main) {
369
+ promise.resolve(array)
370
+ }
371
+ } catch (e: Exception) {
372
+ withContext(Dispatchers.Main) {
373
+ promise.reject("Error", e.message)
374
+ }
375
+ }
376
+ }
377
+ }
378
+
379
+ @ReactMethod
380
+ fun decryptRecoveryFile(recoveryFile: String, passphrase: String, promise: Promise) {
381
+ CoroutineScope(Dispatchers.IO).launch {
382
+ try {
383
+ val result = decryptRecoveryFile(recoveryFile, passphrase)
384
+ val array = Arguments.createArray().apply {
385
+ result.forEach { pushString(it) }
386
+ }
387
+ withContext(Dispatchers.Main) {
388
+ promise.resolve(array)
389
+ }
390
+ } catch (e: Exception) {
391
+ withContext(Dispatchers.Main) {
392
+ promise.reject("Error", e.message)
393
+ }
394
+ }
395
+ }
396
+ }
397
+
398
+ companion object {
399
+ const val NAME = "Pubky"
400
+ }
284
401
  }