@synonymdev/react-native-pubky 0.8.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. package/README.md +52 -9
  2. package/android/src/main/java/com/pubky/PubkyModule.kt +364 -273
  3. package/android/src/main/java/uniffi/pubkycore/pubkycore.kt +1327 -0
  4. package/android/src/main/jniLibs/arm64-v8a/libpubkycore.so +0 -0
  5. package/android/src/main/jniLibs/armeabi-v7a/libpubkycore.so +0 -0
  6. package/android/src/main/jniLibs/x86/libpubkycore.so +0 -0
  7. package/android/src/main/jniLibs/x86_64/libpubkycore.so +0 -0
  8. package/ios/Frameworks/{PubkyMobile.xcframework → PubkyCore.xcframework}/Info.plist +8 -8
  9. package/ios/Frameworks/{PubkyMobile.xcframework → PubkyCore.xcframework}/ios-arm64/Headers/module.modulemap +2 -2
  10. package/ios/Frameworks/PubkyCore.xcframework/ios-arm64/Headers/pubkycoreFFI.h +297 -0
  11. package/ios/Frameworks/{PubkyMobile.xcframework/ios-arm64/libpubkymobile.a → PubkyCore.xcframework/ios-arm64/libpubkycore.a} +0 -0
  12. package/ios/Frameworks/{PubkyMobile.xcframework → PubkyCore.xcframework}/ios-arm64-simulator/Headers/module.modulemap +2 -2
  13. package/ios/Frameworks/PubkyCore.xcframework/ios-arm64-simulator/Headers/pubkycoreFFI.h +297 -0
  14. package/ios/Frameworks/{PubkyMobile.xcframework/ios-arm64-simulator/libpubkymobile.a → PubkyCore.xcframework/ios-arm64-simulator/libpubkycore.a} +0 -0
  15. package/ios/Pubky-Bridging-Header.h +1 -0
  16. package/ios/Pubky.mm +16 -1
  17. package/ios/Pubky.swift +64 -1
  18. package/ios/{pubkymobile.swift → pubkycore.swift} +354 -37
  19. package/lib/commonjs/index.js +45 -0
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/module/index.js +42 -1
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/typescript/commonjs/src/index.d.ts +16 -9
  24. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  25. package/lib/typescript/module/src/index.d.ts +16 -9
  26. package/lib/typescript/module/src/index.d.ts.map +1 -1
  27. package/package.json +12 -7
  28. package/react-native-pubky.podspec +1 -1
  29. package/src/index.tsx +62 -9
  30. package/android/src/main/java/uniffi/pubkymobile/pubkymobile.kt +0 -862
  31. package/android/src/main/jniLibs/arm64-v8a/libpubkymobile.so +0 -0
  32. package/android/src/main/jniLibs/armeabi-v7a/libpubkymobile.so +0 -0
  33. package/android/src/main/jniLibs/x86/libpubkymobile.so +0 -0
  34. package/android/src/main/jniLibs/x86_64/libpubkymobile.so +0 -0
  35. package/ios/Frameworks/PubkyMobile.xcframework/ios-arm64/Headers/mobileFFI.h +0 -188
  36. package/ios/Frameworks/PubkyMobile.xcframework/ios-arm64/Headers/pubkymobileFFI.h +0 -264
  37. package/ios/Frameworks/PubkyMobile.xcframework/ios-arm64/libmobile.a +0 -0
  38. package/ios/Frameworks/PubkyMobile.xcframework/ios-arm64-simulator/Headers/mobileFFI.h +0 -188
  39. package/ios/Frameworks/PubkyMobile.xcframework/ios-arm64-simulator/Headers/pubkymobileFFI.h +0 -264
  40. package/ios/Frameworks/PubkyMobile.xcframework/ios-arm64-simulator/libmobile.a +0 -0
@@ -1,862 +0,0 @@
1
- // This file was autogenerated by some hot garbage in the `uniffi` crate.
2
- // Trust me, you don't want to mess with it!
3
-
4
- @file:Suppress("NAME_SHADOWING")
5
-
6
- package uniffi.pubkymobile;
7
-
8
- // Common helper code.
9
- //
10
- // Ideally this would live in a separate .kt file where it can be unittested etc
11
- // in isolation, and perhaps even published as a re-useable package.
12
- //
13
- // However, it's important that the details of how this helper code works (e.g. the
14
- // way that different builtin types are passed across the FFI) exactly match what's
15
- // expected by the Rust code on the other side of the interface. In practice right
16
- // now that means coming from the exact some version of `uniffi` that was used to
17
- // compile the Rust component. The easiest way to ensure this is to bundle the Kotlin
18
- // helpers directly inline like we're doing here.
19
-
20
- import com.sun.jna.Library
21
- import com.sun.jna.IntegerType
22
- import com.sun.jna.Native
23
- import com.sun.jna.Pointer
24
- import com.sun.jna.Structure
25
- import com.sun.jna.Callback
26
- import com.sun.jna.ptr.*
27
- import java.nio.ByteBuffer
28
- import java.nio.ByteOrder
29
- import java.nio.CharBuffer
30
- import java.nio.charset.CodingErrorAction
31
- import java.util.concurrent.ConcurrentHashMap
32
- import kotlin.coroutines.resume
33
- import kotlinx.coroutines.CancellableContinuation
34
- import kotlinx.coroutines.suspendCancellableCoroutine
35
-
36
- // This is a helper for safely working with byte buffers returned from the Rust code.
37
- // A rust-owned buffer is represented by its capacity, its current length, and a
38
- // pointer to the underlying data.
39
-
40
- @Structure.FieldOrder("capacity", "len", "data")
41
- open class RustBuffer : Structure() {
42
- @JvmField var capacity: Int = 0
43
- @JvmField var len: Int = 0
44
- @JvmField var data: Pointer? = null
45
-
46
- class ByValue: RustBuffer(), Structure.ByValue
47
- class ByReference: RustBuffer(), Structure.ByReference
48
-
49
- companion object {
50
- internal fun alloc(size: Int = 0) = rustCall() { status ->
51
- _UniFFILib.INSTANCE.ffi_pubkymobile_rustbuffer_alloc(size, status)
52
- }.also {
53
- if(it.data == null) {
54
- throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=${size})")
55
- }
56
- }
57
-
58
- internal fun create(capacity: Int, len: Int, data: Pointer?): RustBuffer.ByValue {
59
- var buf = RustBuffer.ByValue()
60
- buf.capacity = capacity
61
- buf.len = len
62
- buf.data = data
63
- return buf
64
- }
65
-
66
- internal fun free(buf: RustBuffer.ByValue) = rustCall() { status ->
67
- _UniFFILib.INSTANCE.ffi_pubkymobile_rustbuffer_free(buf, status)
68
- }
69
- }
70
-
71
- @Suppress("TooGenericExceptionThrown")
72
- fun asByteBuffer() =
73
- this.data?.getByteBuffer(0, this.len.toLong())?.also {
74
- it.order(ByteOrder.BIG_ENDIAN)
75
- }
76
- }
77
-
78
- /**
79
- * The equivalent of the `*mut RustBuffer` type.
80
- * Required for callbacks taking in an out pointer.
81
- *
82
- * Size is the sum of all values in the struct.
83
- */
84
- class RustBufferByReference : ByReference(16) {
85
- /**
86
- * Set the pointed-to `RustBuffer` to the given value.
87
- */
88
- fun setValue(value: RustBuffer.ByValue) {
89
- // NOTE: The offsets are as they are in the C-like struct.
90
- val pointer = getPointer()
91
- pointer.setInt(0, value.capacity)
92
- pointer.setInt(4, value.len)
93
- pointer.setPointer(8, value.data)
94
- }
95
-
96
- /**
97
- * Get a `RustBuffer.ByValue` from this reference.
98
- */
99
- fun getValue(): RustBuffer.ByValue {
100
- val pointer = getPointer()
101
- val value = RustBuffer.ByValue()
102
- value.writeField("capacity", pointer.getInt(0))
103
- value.writeField("len", pointer.getInt(4))
104
- value.writeField("data", pointer.getPointer(8))
105
-
106
- return value
107
- }
108
- }
109
-
110
- // This is a helper for safely passing byte references into the rust code.
111
- // It's not actually used at the moment, because there aren't many things that you
112
- // can take a direct pointer to in the JVM, and if we're going to copy something
113
- // then we might as well copy it into a `RustBuffer`. But it's here for API
114
- // completeness.
115
-
116
- @Structure.FieldOrder("len", "data")
117
- open class ForeignBytes : Structure() {
118
- @JvmField var len: Int = 0
119
- @JvmField var data: Pointer? = null
120
-
121
- class ByValue : ForeignBytes(), Structure.ByValue
122
- }
123
- // The FfiConverter interface handles converter types to and from the FFI
124
- //
125
- // All implementing objects should be public to support external types. When a
126
- // type is external we need to import it's FfiConverter.
127
- public interface FfiConverter<KotlinType, FfiType> {
128
- // Convert an FFI type to a Kotlin type
129
- fun lift(value: FfiType): KotlinType
130
-
131
- // Convert an Kotlin type to an FFI type
132
- fun lower(value: KotlinType): FfiType
133
-
134
- // Read a Kotlin type from a `ByteBuffer`
135
- fun read(buf: ByteBuffer): KotlinType
136
-
137
- // Calculate bytes to allocate when creating a `RustBuffer`
138
- //
139
- // This must return at least as many bytes as the write() function will
140
- // write. It can return more bytes than needed, for example when writing
141
- // Strings we can't know the exact bytes needed until we the UTF-8
142
- // encoding, so we pessimistically allocate the largest size possible (3
143
- // bytes per codepoint). Allocating extra bytes is not really a big deal
144
- // because the `RustBuffer` is short-lived.
145
- fun allocationSize(value: KotlinType): Int
146
-
147
- // Write a Kotlin type to a `ByteBuffer`
148
- fun write(value: KotlinType, buf: ByteBuffer)
149
-
150
- // Lower a value into a `RustBuffer`
151
- //
152
- // This method lowers a value into a `RustBuffer` rather than the normal
153
- // FfiType. It's used by the callback interface code. Callback interface
154
- // returns are always serialized into a `RustBuffer` regardless of their
155
- // normal FFI type.
156
- fun lowerIntoRustBuffer(value: KotlinType): RustBuffer.ByValue {
157
- val rbuf = RustBuffer.alloc(allocationSize(value))
158
- try {
159
- val bbuf = rbuf.data!!.getByteBuffer(0, rbuf.capacity.toLong()).also {
160
- it.order(ByteOrder.BIG_ENDIAN)
161
- }
162
- write(value, bbuf)
163
- rbuf.writeField("len", bbuf.position())
164
- return rbuf
165
- } catch (e: Throwable) {
166
- RustBuffer.free(rbuf)
167
- throw e
168
- }
169
- }
170
-
171
- // Lift a value from a `RustBuffer`.
172
- //
173
- // This here mostly because of the symmetry with `lowerIntoRustBuffer()`.
174
- // It's currently only used by the `FfiConverterRustBuffer` class below.
175
- fun liftFromRustBuffer(rbuf: RustBuffer.ByValue): KotlinType {
176
- val byteBuf = rbuf.asByteBuffer()!!
177
- try {
178
- val item = read(byteBuf)
179
- if (byteBuf.hasRemaining()) {
180
- throw RuntimeException("junk remaining in buffer after lifting, something is very wrong!!")
181
- }
182
- return item
183
- } finally {
184
- RustBuffer.free(rbuf)
185
- }
186
- }
187
- }
188
-
189
- // FfiConverter that uses `RustBuffer` as the FfiType
190
- public interface FfiConverterRustBuffer<KotlinType>: FfiConverter<KotlinType, RustBuffer.ByValue> {
191
- override fun lift(value: RustBuffer.ByValue) = liftFromRustBuffer(value)
192
- override fun lower(value: KotlinType) = lowerIntoRustBuffer(value)
193
- }
194
- // A handful of classes and functions to support the generated data structures.
195
- // This would be a good candidate for isolating in its own ffi-support lib.
196
- // Error runtime.
197
- @Structure.FieldOrder("code", "error_buf")
198
- internal open class RustCallStatus : Structure() {
199
- @JvmField var code: Byte = 0
200
- @JvmField var error_buf: RustBuffer.ByValue = RustBuffer.ByValue()
201
-
202
- class ByValue: RustCallStatus(), Structure.ByValue
203
-
204
- fun isSuccess(): Boolean {
205
- return code == 0.toByte()
206
- }
207
-
208
- fun isError(): Boolean {
209
- return code == 1.toByte()
210
- }
211
-
212
- fun isPanic(): Boolean {
213
- return code == 2.toByte()
214
- }
215
- }
216
-
217
- class InternalException(message: String) : Exception(message)
218
-
219
- // Each top-level error class has a companion object that can lift the error from the call status's rust buffer
220
- interface CallStatusErrorHandler<E> {
221
- fun lift(error_buf: RustBuffer.ByValue): E;
222
- }
223
-
224
- // Helpers for calling Rust
225
- // In practice we usually need to be synchronized to call this safely, so it doesn't
226
- // synchronize itself
227
-
228
- // Call a rust function that returns a Result<>. Pass in the Error class companion that corresponds to the Err
229
- private inline fun <U, E: Exception> rustCallWithError(errorHandler: CallStatusErrorHandler<E>, callback: (RustCallStatus) -> U): U {
230
- var status = RustCallStatus();
231
- val return_value = callback(status)
232
- checkCallStatus(errorHandler, status)
233
- return return_value
234
- }
235
-
236
- // Check RustCallStatus and throw an error if the call wasn't successful
237
- private fun<E: Exception> checkCallStatus(errorHandler: CallStatusErrorHandler<E>, status: RustCallStatus) {
238
- if (status.isSuccess()) {
239
- return
240
- } else if (status.isError()) {
241
- throw errorHandler.lift(status.error_buf)
242
- } else if (status.isPanic()) {
243
- // when the rust code sees a panic, it tries to construct a rustbuffer
244
- // with the message. but if that code panics, then it just sends back
245
- // an empty buffer.
246
- if (status.error_buf.len > 0) {
247
- throw InternalException(FfiConverterString.lift(status.error_buf))
248
- } else {
249
- throw InternalException("Rust panic")
250
- }
251
- } else {
252
- throw InternalException("Unknown rust call status: $status.code")
253
- }
254
- }
255
-
256
- // CallStatusErrorHandler implementation for times when we don't expect a CALL_ERROR
257
- object NullCallStatusErrorHandler: CallStatusErrorHandler<InternalException> {
258
- override fun lift(error_buf: RustBuffer.ByValue): InternalException {
259
- RustBuffer.free(error_buf)
260
- return InternalException("Unexpected CALL_ERROR")
261
- }
262
- }
263
-
264
- // Call a rust function that returns a plain value
265
- private inline fun <U> rustCall(callback: (RustCallStatus) -> U): U {
266
- return rustCallWithError(NullCallStatusErrorHandler, callback);
267
- }
268
-
269
- // IntegerType that matches Rust's `usize` / C's `size_t`
270
- public class USize(value: Long = 0) : IntegerType(Native.SIZE_T_SIZE, value, true) {
271
- // This is needed to fill in the gaps of IntegerType's implementation of Number for Kotlin.
272
- override fun toByte() = toInt().toByte()
273
- // Needed until https://youtrack.jetbrains.com/issue/KT-47902 is fixed.
274
- @Deprecated("`toInt().toChar()` is deprecated")
275
- override fun toChar() = toInt().toChar()
276
- override fun toShort() = toInt().toShort()
277
-
278
- fun writeToBuffer(buf: ByteBuffer) {
279
- // Make sure we always write usize integers using native byte-order, since they may be
280
- // casted to pointer values
281
- buf.order(ByteOrder.nativeOrder())
282
- try {
283
- when (Native.SIZE_T_SIZE) {
284
- 4 -> buf.putInt(toInt())
285
- 8 -> buf.putLong(toLong())
286
- else -> throw RuntimeException("Invalid SIZE_T_SIZE: ${Native.SIZE_T_SIZE}")
287
- }
288
- } finally {
289
- buf.order(ByteOrder.BIG_ENDIAN)
290
- }
291
- }
292
-
293
- companion object {
294
- val size: Int
295
- get() = Native.SIZE_T_SIZE
296
-
297
- fun readFromBuffer(buf: ByteBuffer) : USize {
298
- // Make sure we always read usize integers using native byte-order, since they may be
299
- // casted from pointer values
300
- buf.order(ByteOrder.nativeOrder())
301
- try {
302
- return when (Native.SIZE_T_SIZE) {
303
- 4 -> USize(buf.getInt().toLong())
304
- 8 -> USize(buf.getLong())
305
- else -> throw RuntimeException("Invalid SIZE_T_SIZE: ${Native.SIZE_T_SIZE}")
306
- }
307
- } finally {
308
- buf.order(ByteOrder.BIG_ENDIAN)
309
- }
310
- }
311
- }
312
- }
313
-
314
-
315
- // Map handles to objects
316
- //
317
- // This is used when the Rust code expects an opaque pointer to represent some foreign object.
318
- // Normally we would pass a pointer to the object, but JNA doesn't support getting a pointer from an
319
- // object reference , nor does it support leaking a reference to Rust.
320
- //
321
- // Instead, this class maps USize values to objects so that we can pass a pointer-sized type to
322
- // Rust when it needs an opaque pointer.
323
- //
324
- // TODO: refactor callbacks to use this class
325
- internal class UniFfiHandleMap<T: Any> {
326
- private val map = ConcurrentHashMap<USize, T>()
327
- // Use AtomicInteger for our counter, since we may be on a 32-bit system. 4 billion possible
328
- // values seems like enough. If somehow we generate 4 billion handles, then this will wrap
329
- // around back to zero and we can assume the first handle generated will have been dropped by
330
- // then.
331
- private val counter = java.util.concurrent.atomic.AtomicInteger(0)
332
-
333
- val size: Int
334
- get() = map.size
335
-
336
- fun insert(obj: T): USize {
337
- val handle = USize(counter.getAndAdd(1).toLong())
338
- map.put(handle, obj)
339
- return handle
340
- }
341
-
342
- fun get(handle: USize): T? {
343
- return map.get(handle)
344
- }
345
-
346
- fun remove(handle: USize): T? {
347
- return map.remove(handle)
348
- }
349
- }
350
-
351
- // FFI type for Rust future continuations
352
- internal interface UniFffiRustFutureContinuationCallbackType : com.sun.jna.Callback {
353
- fun callback(continuationHandle: USize, pollResult: Short);
354
- }
355
-
356
- // Contains loading, initialization code,
357
- // and the FFI Function declarations in a com.sun.jna.Library.
358
- @Synchronized
359
- private fun findLibraryName(componentName: String): String {
360
- val libOverride = System.getProperty("uniffi.component.$componentName.libraryOverride")
361
- if (libOverride != null) {
362
- return libOverride
363
- }
364
- return "pubkymobile"
365
- }
366
-
367
- private inline fun <reified Lib : Library> loadIndirect(
368
- componentName: String
369
- ): Lib {
370
- return Native.load<Lib>(findLibraryName(componentName), Lib::class.java)
371
- }
372
-
373
- // A JNA Library to expose the extern-C FFI definitions.
374
- // This is an implementation detail which will be called internally by the public API.
375
-
376
- internal interface _UniFFILib : Library {
377
- companion object {
378
- internal val INSTANCE: _UniFFILib by lazy {
379
- loadIndirect<_UniFFILib>(componentName = "pubkymobile")
380
- .also { lib: _UniFFILib ->
381
- uniffiCheckContractApiVersion(lib)
382
- uniffiCheckApiChecksums(lib)
383
- uniffiRustFutureContinuationCallback.register(lib)
384
- }
385
- }
386
- }
387
-
388
- fun uniffi_pubkymobile_fn_func_auth(`url`: RustBuffer.ByValue,`secretKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
389
- ): RustBuffer.ByValue
390
- fun uniffi_pubkymobile_fn_func_get(`url`: RustBuffer.ByValue,
391
- ): Pointer
392
- fun uniffi_pubkymobile_fn_func_list(`url`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
393
- ): RustBuffer.ByValue
394
- fun uniffi_pubkymobile_fn_func_parse_auth_url(`url`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
395
- ): RustBuffer.ByValue
396
- fun uniffi_pubkymobile_fn_func_publish(`recordName`: RustBuffer.ByValue,`recordContent`: RustBuffer.ByValue,`secretKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
397
- ): RustBuffer.ByValue
398
- fun uniffi_pubkymobile_fn_func_publish_https(`recordName`: RustBuffer.ByValue,`target`: RustBuffer.ByValue,`secretKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
399
- ): RustBuffer.ByValue
400
- fun uniffi_pubkymobile_fn_func_put(`url`: RustBuffer.ByValue,`content`: RustBuffer.ByValue,
401
- ): Pointer
402
- fun uniffi_pubkymobile_fn_func_resolve(`publicKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
403
- ): RustBuffer.ByValue
404
- fun uniffi_pubkymobile_fn_func_resolve_https(`publicKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
405
- ): RustBuffer.ByValue
406
- fun uniffi_pubkymobile_fn_func_sign_in(`secretKey`: RustBuffer.ByValue,
407
- ): Pointer
408
- fun uniffi_pubkymobile_fn_func_sign_out(`secretKey`: RustBuffer.ByValue,
409
- ): Pointer
410
- fun uniffi_pubkymobile_fn_func_sign_up(`secretKey`: RustBuffer.ByValue,`homeserver`: RustBuffer.ByValue,
411
- ): Pointer
412
- fun ffi_pubkymobile_rustbuffer_alloc(`size`: Int,_uniffi_out_err: RustCallStatus,
413
- ): RustBuffer.ByValue
414
- fun ffi_pubkymobile_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,_uniffi_out_err: RustCallStatus,
415
- ): RustBuffer.ByValue
416
- fun ffi_pubkymobile_rustbuffer_free(`buf`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
417
- ): Unit
418
- fun ffi_pubkymobile_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Int,_uniffi_out_err: RustCallStatus,
419
- ): RustBuffer.ByValue
420
- fun ffi_pubkymobile_rust_future_continuation_callback_set(`callback`: UniFffiRustFutureContinuationCallbackType,
421
- ): Unit
422
- fun ffi_pubkymobile_rust_future_poll_u8(`handle`: Pointer,`uniffiCallback`: USize,
423
- ): Unit
424
- fun ffi_pubkymobile_rust_future_cancel_u8(`handle`: Pointer,
425
- ): Unit
426
- fun ffi_pubkymobile_rust_future_free_u8(`handle`: Pointer,
427
- ): Unit
428
- fun ffi_pubkymobile_rust_future_complete_u8(`handle`: Pointer,_uniffi_out_err: RustCallStatus,
429
- ): Byte
430
- fun ffi_pubkymobile_rust_future_poll_i8(`handle`: Pointer,`uniffiCallback`: USize,
431
- ): Unit
432
- fun ffi_pubkymobile_rust_future_cancel_i8(`handle`: Pointer,
433
- ): Unit
434
- fun ffi_pubkymobile_rust_future_free_i8(`handle`: Pointer,
435
- ): Unit
436
- fun ffi_pubkymobile_rust_future_complete_i8(`handle`: Pointer,_uniffi_out_err: RustCallStatus,
437
- ): Byte
438
- fun ffi_pubkymobile_rust_future_poll_u16(`handle`: Pointer,`uniffiCallback`: USize,
439
- ): Unit
440
- fun ffi_pubkymobile_rust_future_cancel_u16(`handle`: Pointer,
441
- ): Unit
442
- fun ffi_pubkymobile_rust_future_free_u16(`handle`: Pointer,
443
- ): Unit
444
- fun ffi_pubkymobile_rust_future_complete_u16(`handle`: Pointer,_uniffi_out_err: RustCallStatus,
445
- ): Short
446
- fun ffi_pubkymobile_rust_future_poll_i16(`handle`: Pointer,`uniffiCallback`: USize,
447
- ): Unit
448
- fun ffi_pubkymobile_rust_future_cancel_i16(`handle`: Pointer,
449
- ): Unit
450
- fun ffi_pubkymobile_rust_future_free_i16(`handle`: Pointer,
451
- ): Unit
452
- fun ffi_pubkymobile_rust_future_complete_i16(`handle`: Pointer,_uniffi_out_err: RustCallStatus,
453
- ): Short
454
- fun ffi_pubkymobile_rust_future_poll_u32(`handle`: Pointer,`uniffiCallback`: USize,
455
- ): Unit
456
- fun ffi_pubkymobile_rust_future_cancel_u32(`handle`: Pointer,
457
- ): Unit
458
- fun ffi_pubkymobile_rust_future_free_u32(`handle`: Pointer,
459
- ): Unit
460
- fun ffi_pubkymobile_rust_future_complete_u32(`handle`: Pointer,_uniffi_out_err: RustCallStatus,
461
- ): Int
462
- fun ffi_pubkymobile_rust_future_poll_i32(`handle`: Pointer,`uniffiCallback`: USize,
463
- ): Unit
464
- fun ffi_pubkymobile_rust_future_cancel_i32(`handle`: Pointer,
465
- ): Unit
466
- fun ffi_pubkymobile_rust_future_free_i32(`handle`: Pointer,
467
- ): Unit
468
- fun ffi_pubkymobile_rust_future_complete_i32(`handle`: Pointer,_uniffi_out_err: RustCallStatus,
469
- ): Int
470
- fun ffi_pubkymobile_rust_future_poll_u64(`handle`: Pointer,`uniffiCallback`: USize,
471
- ): Unit
472
- fun ffi_pubkymobile_rust_future_cancel_u64(`handle`: Pointer,
473
- ): Unit
474
- fun ffi_pubkymobile_rust_future_free_u64(`handle`: Pointer,
475
- ): Unit
476
- fun ffi_pubkymobile_rust_future_complete_u64(`handle`: Pointer,_uniffi_out_err: RustCallStatus,
477
- ): Long
478
- fun ffi_pubkymobile_rust_future_poll_i64(`handle`: Pointer,`uniffiCallback`: USize,
479
- ): Unit
480
- fun ffi_pubkymobile_rust_future_cancel_i64(`handle`: Pointer,
481
- ): Unit
482
- fun ffi_pubkymobile_rust_future_free_i64(`handle`: Pointer,
483
- ): Unit
484
- fun ffi_pubkymobile_rust_future_complete_i64(`handle`: Pointer,_uniffi_out_err: RustCallStatus,
485
- ): Long
486
- fun ffi_pubkymobile_rust_future_poll_f32(`handle`: Pointer,`uniffiCallback`: USize,
487
- ): Unit
488
- fun ffi_pubkymobile_rust_future_cancel_f32(`handle`: Pointer,
489
- ): Unit
490
- fun ffi_pubkymobile_rust_future_free_f32(`handle`: Pointer,
491
- ): Unit
492
- fun ffi_pubkymobile_rust_future_complete_f32(`handle`: Pointer,_uniffi_out_err: RustCallStatus,
493
- ): Float
494
- fun ffi_pubkymobile_rust_future_poll_f64(`handle`: Pointer,`uniffiCallback`: USize,
495
- ): Unit
496
- fun ffi_pubkymobile_rust_future_cancel_f64(`handle`: Pointer,
497
- ): Unit
498
- fun ffi_pubkymobile_rust_future_free_f64(`handle`: Pointer,
499
- ): Unit
500
- fun ffi_pubkymobile_rust_future_complete_f64(`handle`: Pointer,_uniffi_out_err: RustCallStatus,
501
- ): Double
502
- fun ffi_pubkymobile_rust_future_poll_pointer(`handle`: Pointer,`uniffiCallback`: USize,
503
- ): Unit
504
- fun ffi_pubkymobile_rust_future_cancel_pointer(`handle`: Pointer,
505
- ): Unit
506
- fun ffi_pubkymobile_rust_future_free_pointer(`handle`: Pointer,
507
- ): Unit
508
- fun ffi_pubkymobile_rust_future_complete_pointer(`handle`: Pointer,_uniffi_out_err: RustCallStatus,
509
- ): Pointer
510
- fun ffi_pubkymobile_rust_future_poll_rust_buffer(`handle`: Pointer,`uniffiCallback`: USize,
511
- ): Unit
512
- fun ffi_pubkymobile_rust_future_cancel_rust_buffer(`handle`: Pointer,
513
- ): Unit
514
- fun ffi_pubkymobile_rust_future_free_rust_buffer(`handle`: Pointer,
515
- ): Unit
516
- fun ffi_pubkymobile_rust_future_complete_rust_buffer(`handle`: Pointer,_uniffi_out_err: RustCallStatus,
517
- ): RustBuffer.ByValue
518
- fun ffi_pubkymobile_rust_future_poll_void(`handle`: Pointer,`uniffiCallback`: USize,
519
- ): Unit
520
- fun ffi_pubkymobile_rust_future_cancel_void(`handle`: Pointer,
521
- ): Unit
522
- fun ffi_pubkymobile_rust_future_free_void(`handle`: Pointer,
523
- ): Unit
524
- fun ffi_pubkymobile_rust_future_complete_void(`handle`: Pointer,_uniffi_out_err: RustCallStatus,
525
- ): Unit
526
- fun uniffi_pubkymobile_checksum_func_auth(
527
- ): Short
528
- fun uniffi_pubkymobile_checksum_func_get(
529
- ): Short
530
- fun uniffi_pubkymobile_checksum_func_list(
531
- ): Short
532
- fun uniffi_pubkymobile_checksum_func_parse_auth_url(
533
- ): Short
534
- fun uniffi_pubkymobile_checksum_func_publish(
535
- ): Short
536
- fun uniffi_pubkymobile_checksum_func_publish_https(
537
- ): Short
538
- fun uniffi_pubkymobile_checksum_func_put(
539
- ): Short
540
- fun uniffi_pubkymobile_checksum_func_resolve(
541
- ): Short
542
- fun uniffi_pubkymobile_checksum_func_resolve_https(
543
- ): Short
544
- fun uniffi_pubkymobile_checksum_func_sign_in(
545
- ): Short
546
- fun uniffi_pubkymobile_checksum_func_sign_out(
547
- ): Short
548
- fun uniffi_pubkymobile_checksum_func_sign_up(
549
- ): Short
550
- fun ffi_pubkymobile_uniffi_contract_version(
551
- ): Int
552
-
553
- }
554
-
555
- private fun uniffiCheckContractApiVersion(lib: _UniFFILib) {
556
- // Get the bindings contract version from our ComponentInterface
557
- val bindings_contract_version = 24
558
- // Get the scaffolding contract version by calling the into the dylib
559
- val scaffolding_contract_version = lib.ffi_pubkymobile_uniffi_contract_version()
560
- if (bindings_contract_version != scaffolding_contract_version) {
561
- throw RuntimeException("UniFFI contract version mismatch: try cleaning and rebuilding your project")
562
- }
563
- }
564
-
565
- @Suppress("UNUSED_PARAMETER")
566
- private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
567
- if (lib.uniffi_pubkymobile_checksum_func_auth() != 61378.toShort()) {
568
- throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
569
- }
570
- if (lib.uniffi_pubkymobile_checksum_func_get() != 5395.toShort()) {
571
- throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
572
- }
573
- if (lib.uniffi_pubkymobile_checksum_func_list() != 8522.toShort()) {
574
- throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
575
- }
576
- if (lib.uniffi_pubkymobile_checksum_func_parse_auth_url() != 29088.toShort()) {
577
- throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
578
- }
579
- if (lib.uniffi_pubkymobile_checksum_func_publish() != 20156.toShort()) {
580
- throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
581
- }
582
- if (lib.uniffi_pubkymobile_checksum_func_publish_https() != 14705.toShort()) {
583
- throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
584
- }
585
- if (lib.uniffi_pubkymobile_checksum_func_put() != 47594.toShort()) {
586
- throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
587
- }
588
- if (lib.uniffi_pubkymobile_checksum_func_resolve() != 18303.toShort()) {
589
- throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
590
- }
591
- if (lib.uniffi_pubkymobile_checksum_func_resolve_https() != 34593.toShort()) {
592
- throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
593
- }
594
- if (lib.uniffi_pubkymobile_checksum_func_sign_in() != 53969.toShort()) {
595
- throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
596
- }
597
- if (lib.uniffi_pubkymobile_checksum_func_sign_out() != 32961.toShort()) {
598
- throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
599
- }
600
- if (lib.uniffi_pubkymobile_checksum_func_sign_up() != 28083.toShort()) {
601
- throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
602
- }
603
- }
604
-
605
- // Async support
606
- // Async return type handlers
607
-
608
- internal const val UNIFFI_RUST_FUTURE_POLL_READY = 0.toShort()
609
- internal const val UNIFFI_RUST_FUTURE_POLL_MAYBE_READY = 1.toShort()
610
-
611
- internal val uniffiContinuationHandleMap = UniFfiHandleMap<CancellableContinuation<Short>>()
612
-
613
- // FFI type for Rust future continuations
614
- internal object uniffiRustFutureContinuationCallback: UniFffiRustFutureContinuationCallbackType {
615
- override fun callback(continuationHandle: USize, pollResult: Short) {
616
- uniffiContinuationHandleMap.remove(continuationHandle)?.resume(pollResult)
617
- }
618
-
619
- internal fun register(lib: _UniFFILib) {
620
- lib.ffi_pubkymobile_rust_future_continuation_callback_set(this)
621
- }
622
- }
623
-
624
- internal suspend fun<T, F, E: Exception> uniffiRustCallAsync(
625
- rustFuture: Pointer,
626
- pollFunc: (Pointer, USize) -> Unit,
627
- completeFunc: (Pointer, RustCallStatus) -> F,
628
- freeFunc: (Pointer) -> Unit,
629
- liftFunc: (F) -> T,
630
- errorHandler: CallStatusErrorHandler<E>
631
- ): T {
632
- try {
633
- do {
634
- val pollResult = suspendCancellableCoroutine<Short> { continuation ->
635
- pollFunc(
636
- rustFuture,
637
- uniffiContinuationHandleMap.insert(continuation)
638
- )
639
- }
640
- } while (pollResult != UNIFFI_RUST_FUTURE_POLL_READY);
641
-
642
- return liftFunc(
643
- rustCallWithError(errorHandler, { status -> completeFunc(rustFuture, status) })
644
- )
645
- } finally {
646
- freeFunc(rustFuture)
647
- }
648
- }
649
-
650
-
651
- // Public interface members begin here.
652
-
653
-
654
- public object FfiConverterString: FfiConverter<String, RustBuffer.ByValue> {
655
- // Note: we don't inherit from FfiConverterRustBuffer, because we use a
656
- // special encoding when lowering/lifting. We can use `RustBuffer.len` to
657
- // store our length and avoid writing it out to the buffer.
658
- override fun lift(value: RustBuffer.ByValue): String {
659
- try {
660
- val byteArr = ByteArray(value.len)
661
- value.asByteBuffer()!!.get(byteArr)
662
- return byteArr.toString(Charsets.UTF_8)
663
- } finally {
664
- RustBuffer.free(value)
665
- }
666
- }
667
-
668
- override fun read(buf: ByteBuffer): String {
669
- val len = buf.getInt()
670
- val byteArr = ByteArray(len)
671
- buf.get(byteArr)
672
- return byteArr.toString(Charsets.UTF_8)
673
- }
674
-
675
- fun toUtf8(value: String): ByteBuffer {
676
- // Make sure we don't have invalid UTF-16, check for lone surrogates.
677
- return Charsets.UTF_8.newEncoder().run {
678
- onMalformedInput(CodingErrorAction.REPORT)
679
- encode(CharBuffer.wrap(value))
680
- }
681
- }
682
-
683
- override fun lower(value: String): RustBuffer.ByValue {
684
- val byteBuf = toUtf8(value)
685
- // Ideally we'd pass these bytes to `ffi_bytebuffer_from_bytes`, but doing so would require us
686
- // to copy them into a JNA `Memory`. So we might as well directly copy them into a `RustBuffer`.
687
- val rbuf = RustBuffer.alloc(byteBuf.limit())
688
- rbuf.asByteBuffer()!!.put(byteBuf)
689
- return rbuf
690
- }
691
-
692
- // We aren't sure exactly how many bytes our string will be once it's UTF-8
693
- // encoded. Allocate 3 bytes per UTF-16 code unit which will always be
694
- // enough.
695
- override fun allocationSize(value: String): Int {
696
- val sizeForLength = 4
697
- val sizeForString = value.length * 3
698
- return sizeForLength + sizeForString
699
- }
700
-
701
- override fun write(value: String, buf: ByteBuffer) {
702
- val byteBuf = toUtf8(value)
703
- buf.putInt(byteBuf.limit())
704
- buf.put(byteBuf)
705
- }
706
- }
707
-
708
-
709
-
710
-
711
- public object FfiConverterSequenceString: FfiConverterRustBuffer<List<String>> {
712
- override fun read(buf: ByteBuffer): List<String> {
713
- val len = buf.getInt()
714
- return List<String>(len) {
715
- FfiConverterString.read(buf)
716
- }
717
- }
718
-
719
- override fun allocationSize(value: List<String>): Int {
720
- val sizeForLength = 4
721
- val sizeForItems = value.map { FfiConverterString.allocationSize(it) }.sum()
722
- return sizeForLength + sizeForItems
723
- }
724
-
725
- override fun write(value: List<String>, buf: ByteBuffer) {
726
- buf.putInt(value.size)
727
- value.forEach {
728
- FfiConverterString.write(it, buf)
729
- }
730
- }
731
- }
732
-
733
-
734
-
735
-
736
-
737
- fun `auth`(`url`: String, `secretKey`: String): List<String> {
738
- return FfiConverterSequenceString.lift(
739
- rustCall() { _status ->
740
- _UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_auth(FfiConverterString.lower(`url`),FfiConverterString.lower(`secretKey`),_status)
741
- })
742
- }
743
-
744
-
745
- @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
746
- suspend fun `get`(`url`: String) : List<String> {
747
- return uniffiRustCallAsync(
748
- _UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_get(FfiConverterString.lower(`url`),),
749
- { future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_poll_rust_buffer(future, continuation) },
750
- { future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_complete_rust_buffer(future, continuation) },
751
- { future -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_free_rust_buffer(future) },
752
- // lift function
753
- { FfiConverterSequenceString.lift(it) },
754
- // Error FFI converter
755
- NullCallStatusErrorHandler,
756
- )
757
- }
758
-
759
- fun `list`(`url`: String): List<String> {
760
- return FfiConverterSequenceString.lift(
761
- rustCall() { _status ->
762
- _UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_list(FfiConverterString.lower(`url`),_status)
763
- })
764
- }
765
-
766
-
767
- fun `parseAuthUrl`(`url`: String): List<String> {
768
- return FfiConverterSequenceString.lift(
769
- rustCall() { _status ->
770
- _UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_parse_auth_url(FfiConverterString.lower(`url`),_status)
771
- })
772
- }
773
-
774
-
775
- fun `publish`(`recordName`: String, `recordContent`: String, `secretKey`: String): List<String> {
776
- return FfiConverterSequenceString.lift(
777
- rustCall() { _status ->
778
- _UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_publish(FfiConverterString.lower(`recordName`),FfiConverterString.lower(`recordContent`),FfiConverterString.lower(`secretKey`),_status)
779
- })
780
- }
781
-
782
-
783
- fun `publishHttps`(`recordName`: String, `target`: String, `secretKey`: String): List<String> {
784
- return FfiConverterSequenceString.lift(
785
- rustCall() { _status ->
786
- _UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_publish_https(FfiConverterString.lower(`recordName`),FfiConverterString.lower(`target`),FfiConverterString.lower(`secretKey`),_status)
787
- })
788
- }
789
-
790
-
791
- @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
792
- suspend fun `put`(`url`: String, `content`: String) : List<String> {
793
- return uniffiRustCallAsync(
794
- _UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_put(FfiConverterString.lower(`url`),FfiConverterString.lower(`content`),),
795
- { future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_poll_rust_buffer(future, continuation) },
796
- { future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_complete_rust_buffer(future, continuation) },
797
- { future -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_free_rust_buffer(future) },
798
- // lift function
799
- { FfiConverterSequenceString.lift(it) },
800
- // Error FFI converter
801
- NullCallStatusErrorHandler,
802
- )
803
- }
804
-
805
- fun `resolve`(`publicKey`: String): List<String> {
806
- return FfiConverterSequenceString.lift(
807
- rustCall() { _status ->
808
- _UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_resolve(FfiConverterString.lower(`publicKey`),_status)
809
- })
810
- }
811
-
812
-
813
- fun `resolveHttps`(`publicKey`: String): List<String> {
814
- return FfiConverterSequenceString.lift(
815
- rustCall() { _status ->
816
- _UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_resolve_https(FfiConverterString.lower(`publicKey`),_status)
817
- })
818
- }
819
-
820
-
821
- @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
822
- suspend fun `signIn`(`secretKey`: String) : List<String> {
823
- return uniffiRustCallAsync(
824
- _UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_sign_in(FfiConverterString.lower(`secretKey`),),
825
- { future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_poll_rust_buffer(future, continuation) },
826
- { future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_complete_rust_buffer(future, continuation) },
827
- { future -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_free_rust_buffer(future) },
828
- // lift function
829
- { FfiConverterSequenceString.lift(it) },
830
- // Error FFI converter
831
- NullCallStatusErrorHandler,
832
- )
833
- }
834
-
835
- @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
836
- suspend fun `signOut`(`secretKey`: String) : List<String> {
837
- return uniffiRustCallAsync(
838
- _UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_sign_out(FfiConverterString.lower(`secretKey`),),
839
- { future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_poll_rust_buffer(future, continuation) },
840
- { future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_complete_rust_buffer(future, continuation) },
841
- { future -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_free_rust_buffer(future) },
842
- // lift function
843
- { FfiConverterSequenceString.lift(it) },
844
- // Error FFI converter
845
- NullCallStatusErrorHandler,
846
- )
847
- }
848
-
849
- @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
850
- suspend fun `signUp`(`secretKey`: String, `homeserver`: String) : List<String> {
851
- return uniffiRustCallAsync(
852
- _UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_sign_up(FfiConverterString.lower(`secretKey`),FfiConverterString.lower(`homeserver`),),
853
- { future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_poll_rust_buffer(future, continuation) },
854
- { future, continuation -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_complete_rust_buffer(future, continuation) },
855
- { future -> _UniFFILib.INSTANCE.ffi_pubkymobile_rust_future_free_rust_buffer(future) },
856
- // lift function
857
- { FfiConverterSequenceString.lift(it) },
858
- // Error FFI converter
859
- NullCallStatusErrorHandler,
860
- )
861
- }
862
-