@bubolabs/wallet-rn-sdk 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/BuboWalletRnSdk.podspec +29 -0
  2. package/README.md +71 -0
  3. package/android/build.gradle +46 -0
  4. package/android/consumer-rules.pro +1 -0
  5. package/android/src/main/AndroidManifest.xml +1 -0
  6. package/android/src/main/java/com/bubo/wallet/BuboWalletSmokeModule.kt +65 -0
  7. package/android/src/main/java/com/bubo/wallet/BuboWalletSmokePackage.kt +18 -0
  8. package/android/src/main/java/uniffi/bubo_wallet_ffi/WalletLibSmoke.kt +92 -0
  9. package/android/src/main/java/uniffi/bubo_wallet_ffi/bubo_wallet_ffi.kt +1664 -0
  10. package/android/src/main/jniLibs/arm64-v8a/libbubo_wallet_ffi.so +0 -0
  11. package/android/src/main/jniLibs/arm64-v8a/libuniffi_bubo_wallet_ffi.so +0 -0
  12. package/android/src/main/jniLibs/armeabi-v7a/libbubo_wallet_ffi.so +0 -0
  13. package/android/src/main/jniLibs/armeabi-v7a/libuniffi_bubo_wallet_ffi.so +0 -0
  14. package/android/src/main/jniLibs/x86/libbubo_wallet_ffi.so +0 -0
  15. package/android/src/main/jniLibs/x86/libuniffi_bubo_wallet_ffi.so +0 -0
  16. package/android/src/main/jniLibs/x86_64/libbubo_wallet_ffi.so +0 -0
  17. package/android/src/main/jniLibs/x86_64/libuniffi_bubo_wallet_ffi.so +0 -0
  18. package/dist/index.d.ts +4 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +8 -0
  21. package/dist/native.d.ts +18 -0
  22. package/dist/native.d.ts.map +1 -0
  23. package/dist/native.js +37 -0
  24. package/dist/smoke.d.ts +4 -0
  25. package/dist/smoke.d.ts.map +1 -0
  26. package/dist/smoke.js +82 -0
  27. package/dist/types.d.ts +18 -0
  28. package/dist/types.d.ts.map +1 -0
  29. package/dist/types.js +12 -0
  30. package/ios/BuboWalletSmoke.swift +110 -0
  31. package/ios/BuboWalletSmokeModule.m +11 -0
  32. package/ios/BuboWalletSmokeModule.swift +51 -0
  33. package/ios/bubo_wallet_ffi.swift +905 -0
  34. package/ios/bubo_wallet_ffiFFI.h +606 -0
  35. package/ios/bubo_wallet_ffiFFI.modulemap +7 -0
  36. package/ios/lib/BuboWalletFFI.xcframework/Info.plist +48 -0
  37. package/ios/lib/BuboWalletFFI.xcframework/ios-arm64/Headers/bubo_wallet_ffiFFI.h +606 -0
  38. package/ios/lib/BuboWalletFFI.xcframework/ios-arm64/Headers/module.modulemap +7 -0
  39. package/ios/lib/BuboWalletFFI.xcframework/ios-arm64/libbubo_wallet_ffi.a +0 -0
  40. package/ios/lib/BuboWalletFFI.xcframework/ios-arm64_x86_64-simulator/Headers/bubo_wallet_ffiFFI.h +606 -0
  41. package/ios/lib/BuboWalletFFI.xcframework/ios-arm64_x86_64-simulator/Headers/module.modulemap +7 -0
  42. package/ios/lib/BuboWalletFFI.xcframework/ios-arm64_x86_64-simulator/libbubo_wallet_ffi.a +0 -0
  43. package/package.json +47 -0
  44. package/react-native.config.js +12 -0
@@ -0,0 +1,1664 @@
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.bubo_wallet_ffi
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.atomic.AtomicLong
32
+ import java.util.concurrent.ConcurrentHashMap
33
+ import java.util.concurrent.atomic.AtomicBoolean
34
+
35
+ // This is a helper for safely working with byte buffers returned from the Rust code.
36
+ // A rust-owned buffer is represented by its capacity, its current length, and a
37
+ // pointer to the underlying data.
38
+
39
+ /**
40
+ * @suppress
41
+ */
42
+ @Structure.FieldOrder("capacity", "len", "data")
43
+ open class RustBuffer : Structure() {
44
+ // Note: `capacity` and `len` are actually `ULong` values, but JVM only supports signed values.
45
+ // When dealing with these fields, make sure to call `toULong()`.
46
+ @JvmField var capacity: Long = 0
47
+ @JvmField var len: Long = 0
48
+ @JvmField var data: Pointer? = null
49
+
50
+ class ByValue: RustBuffer(), Structure.ByValue
51
+ class ByReference: RustBuffer(), Structure.ByReference
52
+
53
+ internal fun setValue(other: RustBuffer) {
54
+ capacity = other.capacity
55
+ len = other.len
56
+ data = other.data
57
+ }
58
+
59
+ companion object {
60
+ internal fun alloc(size: ULong = 0UL) = uniffiRustCall() { status ->
61
+ // Note: need to convert the size to a `Long` value to make this work with JVM.
62
+ UniffiLib.INSTANCE.ffi_bubo_wallet_ffi_rustbuffer_alloc(size.toLong(), status)
63
+ }.also {
64
+ if(it.data == null) {
65
+ throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=${size})")
66
+ }
67
+ }
68
+
69
+ internal fun create(capacity: ULong, len: ULong, data: Pointer?): RustBuffer.ByValue {
70
+ var buf = RustBuffer.ByValue()
71
+ buf.capacity = capacity.toLong()
72
+ buf.len = len.toLong()
73
+ buf.data = data
74
+ return buf
75
+ }
76
+
77
+ internal fun free(buf: RustBuffer.ByValue) = uniffiRustCall() { status ->
78
+ UniffiLib.INSTANCE.ffi_bubo_wallet_ffi_rustbuffer_free(buf, status)
79
+ }
80
+ }
81
+
82
+ @Suppress("TooGenericExceptionThrown")
83
+ fun asByteBuffer() =
84
+ this.data?.getByteBuffer(0, this.len.toLong())?.also {
85
+ it.order(ByteOrder.BIG_ENDIAN)
86
+ }
87
+ }
88
+
89
+ /**
90
+ * The equivalent of the `*mut RustBuffer` type.
91
+ * Required for callbacks taking in an out pointer.
92
+ *
93
+ * Size is the sum of all values in the struct.
94
+ *
95
+ * @suppress
96
+ */
97
+ class RustBufferByReference : ByReference(16) {
98
+ /**
99
+ * Set the pointed-to `RustBuffer` to the given value.
100
+ */
101
+ fun setValue(value: RustBuffer.ByValue) {
102
+ // NOTE: The offsets are as they are in the C-like struct.
103
+ val pointer = getPointer()
104
+ pointer.setLong(0, value.capacity)
105
+ pointer.setLong(8, value.len)
106
+ pointer.setPointer(16, value.data)
107
+ }
108
+
109
+ /**
110
+ * Get a `RustBuffer.ByValue` from this reference.
111
+ */
112
+ fun getValue(): RustBuffer.ByValue {
113
+ val pointer = getPointer()
114
+ val value = RustBuffer.ByValue()
115
+ value.writeField("capacity", pointer.getLong(0))
116
+ value.writeField("len", pointer.getLong(8))
117
+ value.writeField("data", pointer.getLong(16))
118
+
119
+ return value
120
+ }
121
+ }
122
+
123
+ // This is a helper for safely passing byte references into the rust code.
124
+ // It's not actually used at the moment, because there aren't many things that you
125
+ // can take a direct pointer to in the JVM, and if we're going to copy something
126
+ // then we might as well copy it into a `RustBuffer`. But it's here for API
127
+ // completeness.
128
+
129
+ @Structure.FieldOrder("len", "data")
130
+ internal open class ForeignBytes : Structure() {
131
+ @JvmField var len: Int = 0
132
+ @JvmField var data: Pointer? = null
133
+
134
+ class ByValue : ForeignBytes(), Structure.ByValue
135
+ }
136
+ /**
137
+ * The FfiConverter interface handles converter types to and from the FFI
138
+ *
139
+ * All implementing objects should be public to support external types. When a
140
+ * type is external we need to import it's FfiConverter.
141
+ *
142
+ * @suppress
143
+ */
144
+ public interface FfiConverter<KotlinType, FfiType> {
145
+ // Convert an FFI type to a Kotlin type
146
+ fun lift(value: FfiType): KotlinType
147
+
148
+ // Convert an Kotlin type to an FFI type
149
+ fun lower(value: KotlinType): FfiType
150
+
151
+ // Read a Kotlin type from a `ByteBuffer`
152
+ fun read(buf: ByteBuffer): KotlinType
153
+
154
+ // Calculate bytes to allocate when creating a `RustBuffer`
155
+ //
156
+ // This must return at least as many bytes as the write() function will
157
+ // write. It can return more bytes than needed, for example when writing
158
+ // Strings we can't know the exact bytes needed until we the UTF-8
159
+ // encoding, so we pessimistically allocate the largest size possible (3
160
+ // bytes per codepoint). Allocating extra bytes is not really a big deal
161
+ // because the `RustBuffer` is short-lived.
162
+ fun allocationSize(value: KotlinType): ULong
163
+
164
+ // Write a Kotlin type to a `ByteBuffer`
165
+ fun write(value: KotlinType, buf: ByteBuffer)
166
+
167
+ // Lower a value into a `RustBuffer`
168
+ //
169
+ // This method lowers a value into a `RustBuffer` rather than the normal
170
+ // FfiType. It's used by the callback interface code. Callback interface
171
+ // returns are always serialized into a `RustBuffer` regardless of their
172
+ // normal FFI type.
173
+ fun lowerIntoRustBuffer(value: KotlinType): RustBuffer.ByValue {
174
+ val rbuf = RustBuffer.alloc(allocationSize(value))
175
+ try {
176
+ val bbuf = rbuf.data!!.getByteBuffer(0, rbuf.capacity).also {
177
+ it.order(ByteOrder.BIG_ENDIAN)
178
+ }
179
+ write(value, bbuf)
180
+ rbuf.writeField("len", bbuf.position().toLong())
181
+ return rbuf
182
+ } catch (e: Throwable) {
183
+ RustBuffer.free(rbuf)
184
+ throw e
185
+ }
186
+ }
187
+
188
+ // Lift a value from a `RustBuffer`.
189
+ //
190
+ // This here mostly because of the symmetry with `lowerIntoRustBuffer()`.
191
+ // It's currently only used by the `FfiConverterRustBuffer` class below.
192
+ fun liftFromRustBuffer(rbuf: RustBuffer.ByValue): KotlinType {
193
+ val byteBuf = rbuf.asByteBuffer()!!
194
+ try {
195
+ val item = read(byteBuf)
196
+ if (byteBuf.hasRemaining()) {
197
+ throw RuntimeException("junk remaining in buffer after lifting, something is very wrong!!")
198
+ }
199
+ return item
200
+ } finally {
201
+ RustBuffer.free(rbuf)
202
+ }
203
+ }
204
+ }
205
+
206
+ /**
207
+ * FfiConverter that uses `RustBuffer` as the FfiType
208
+ *
209
+ * @suppress
210
+ */
211
+ public interface FfiConverterRustBuffer<KotlinType>: FfiConverter<KotlinType, RustBuffer.ByValue> {
212
+ override fun lift(value: RustBuffer.ByValue) = liftFromRustBuffer(value)
213
+ override fun lower(value: KotlinType) = lowerIntoRustBuffer(value)
214
+ }
215
+ // A handful of classes and functions to support the generated data structures.
216
+ // This would be a good candidate for isolating in its own ffi-support lib.
217
+
218
+ internal const val UNIFFI_CALL_SUCCESS = 0.toByte()
219
+ internal const val UNIFFI_CALL_ERROR = 1.toByte()
220
+ internal const val UNIFFI_CALL_UNEXPECTED_ERROR = 2.toByte()
221
+
222
+ @Structure.FieldOrder("code", "error_buf")
223
+ internal open class UniffiRustCallStatus : Structure() {
224
+ @JvmField var code: Byte = 0
225
+ @JvmField var error_buf: RustBuffer.ByValue = RustBuffer.ByValue()
226
+
227
+ class ByValue: UniffiRustCallStatus(), Structure.ByValue
228
+
229
+ fun isSuccess(): Boolean {
230
+ return code == UNIFFI_CALL_SUCCESS
231
+ }
232
+
233
+ fun isError(): Boolean {
234
+ return code == UNIFFI_CALL_ERROR
235
+ }
236
+
237
+ fun isPanic(): Boolean {
238
+ return code == UNIFFI_CALL_UNEXPECTED_ERROR
239
+ }
240
+
241
+ companion object {
242
+ fun create(code: Byte, errorBuf: RustBuffer.ByValue): UniffiRustCallStatus.ByValue {
243
+ val callStatus = UniffiRustCallStatus.ByValue()
244
+ callStatus.code = code
245
+ callStatus.error_buf = errorBuf
246
+ return callStatus
247
+ }
248
+ }
249
+ }
250
+
251
+ class InternalException(message: String) : kotlin.Exception(message)
252
+
253
+ /**
254
+ * Each top-level error class has a companion object that can lift the error from the call status's rust buffer
255
+ *
256
+ * @suppress
257
+ */
258
+ interface UniffiRustCallStatusErrorHandler<E> {
259
+ fun lift(error_buf: RustBuffer.ByValue): E;
260
+ }
261
+
262
+ // Helpers for calling Rust
263
+ // In practice we usually need to be synchronized to call this safely, so it doesn't
264
+ // synchronize itself
265
+
266
+ // Call a rust function that returns a Result<>. Pass in the Error class companion that corresponds to the Err
267
+ private inline fun <U, E: kotlin.Exception> uniffiRustCallWithError(errorHandler: UniffiRustCallStatusErrorHandler<E>, callback: (UniffiRustCallStatus) -> U): U {
268
+ var status = UniffiRustCallStatus()
269
+ val return_value = callback(status)
270
+ uniffiCheckCallStatus(errorHandler, status)
271
+ return return_value
272
+ }
273
+
274
+ // Check UniffiRustCallStatus and throw an error if the call wasn't successful
275
+ private fun<E: kotlin.Exception> uniffiCheckCallStatus(errorHandler: UniffiRustCallStatusErrorHandler<E>, status: UniffiRustCallStatus) {
276
+ if (status.isSuccess()) {
277
+ return
278
+ } else if (status.isError()) {
279
+ throw errorHandler.lift(status.error_buf)
280
+ } else if (status.isPanic()) {
281
+ // when the rust code sees a panic, it tries to construct a rustbuffer
282
+ // with the message. but if that code panics, then it just sends back
283
+ // an empty buffer.
284
+ if (status.error_buf.len > 0) {
285
+ throw InternalException(FfiConverterString.lift(status.error_buf))
286
+ } else {
287
+ throw InternalException("Rust panic")
288
+ }
289
+ } else {
290
+ throw InternalException("Unknown rust call status: $status.code")
291
+ }
292
+ }
293
+
294
+ /**
295
+ * UniffiRustCallStatusErrorHandler implementation for times when we don't expect a CALL_ERROR
296
+ *
297
+ * @suppress
298
+ */
299
+ object UniffiNullRustCallStatusErrorHandler: UniffiRustCallStatusErrorHandler<InternalException> {
300
+ override fun lift(error_buf: RustBuffer.ByValue): InternalException {
301
+ RustBuffer.free(error_buf)
302
+ return InternalException("Unexpected CALL_ERROR")
303
+ }
304
+ }
305
+
306
+ // Call a rust function that returns a plain value
307
+ private inline fun <U> uniffiRustCall(callback: (UniffiRustCallStatus) -> U): U {
308
+ return uniffiRustCallWithError(UniffiNullRustCallStatusErrorHandler, callback)
309
+ }
310
+
311
+ internal inline fun<T> uniffiTraitInterfaceCall(
312
+ callStatus: UniffiRustCallStatus,
313
+ makeCall: () -> T,
314
+ writeReturn: (T) -> Unit,
315
+ ) {
316
+ try {
317
+ writeReturn(makeCall())
318
+ } catch(e: kotlin.Exception) {
319
+ callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
320
+ callStatus.error_buf = FfiConverterString.lower(e.toString())
321
+ }
322
+ }
323
+
324
+ internal inline fun<T, reified E: Throwable> uniffiTraitInterfaceCallWithError(
325
+ callStatus: UniffiRustCallStatus,
326
+ makeCall: () -> T,
327
+ writeReturn: (T) -> Unit,
328
+ lowerError: (E) -> RustBuffer.ByValue
329
+ ) {
330
+ try {
331
+ writeReturn(makeCall())
332
+ } catch(e: kotlin.Exception) {
333
+ if (e is E) {
334
+ callStatus.code = UNIFFI_CALL_ERROR
335
+ callStatus.error_buf = lowerError(e)
336
+ } else {
337
+ callStatus.code = UNIFFI_CALL_UNEXPECTED_ERROR
338
+ callStatus.error_buf = FfiConverterString.lower(e.toString())
339
+ }
340
+ }
341
+ }
342
+ // Map handles to objects
343
+ //
344
+ // This is used pass an opaque 64-bit handle representing a foreign object to the Rust code.
345
+ internal class UniffiHandleMap<T: Any> {
346
+ private val map = ConcurrentHashMap<Long, T>()
347
+ private val counter = java.util.concurrent.atomic.AtomicLong(0)
348
+
349
+ val size: Int
350
+ get() = map.size
351
+
352
+ // Insert a new object into the handle map and get a handle for it
353
+ fun insert(obj: T): Long {
354
+ val handle = counter.getAndAdd(1)
355
+ map.put(handle, obj)
356
+ return handle
357
+ }
358
+
359
+ // Get an object from the handle map
360
+ fun get(handle: Long): T {
361
+ return map.get(handle) ?: throw InternalException("UniffiHandleMap.get: Invalid handle")
362
+ }
363
+
364
+ // Remove an entry from the handlemap and get the Kotlin object back
365
+ fun remove(handle: Long): T {
366
+ return map.remove(handle) ?: throw InternalException("UniffiHandleMap: Invalid handle")
367
+ }
368
+ }
369
+
370
+ // Contains loading, initialization code,
371
+ // and the FFI Function declarations in a com.sun.jna.Library.
372
+ @Synchronized
373
+ private fun findLibraryName(componentName: String): String {
374
+ val libOverride = System.getProperty("uniffi.component.$componentName.libraryOverride")
375
+ if (libOverride != null) {
376
+ return libOverride
377
+ }
378
+ return "bubo_wallet_ffi"
379
+ }
380
+
381
+ private inline fun <reified Lib : Library> loadIndirect(
382
+ componentName: String
383
+ ): Lib {
384
+ return Native.load<Lib>(findLibraryName(componentName), Lib::class.java)
385
+ }
386
+
387
+ // Define FFI callback types
388
+ internal interface UniffiRustFutureContinuationCallback : com.sun.jna.Callback {
389
+ fun callback(`data`: Long,`pollResult`: Byte,)
390
+ }
391
+ internal interface UniffiForeignFutureFree : com.sun.jna.Callback {
392
+ fun callback(`handle`: Long,)
393
+ }
394
+ internal interface UniffiCallbackInterfaceFree : com.sun.jna.Callback {
395
+ fun callback(`handle`: Long,)
396
+ }
397
+ @Structure.FieldOrder("handle", "free")
398
+ internal open class UniffiForeignFuture(
399
+ @JvmField internal var `handle`: Long = 0.toLong(),
400
+ @JvmField internal var `free`: UniffiForeignFutureFree? = null,
401
+ ) : Structure() {
402
+ class UniffiByValue(
403
+ `handle`: Long = 0.toLong(),
404
+ `free`: UniffiForeignFutureFree? = null,
405
+ ): UniffiForeignFuture(`handle`,`free`,), Structure.ByValue
406
+
407
+ internal fun uniffiSetValue(other: UniffiForeignFuture) {
408
+ `handle` = other.`handle`
409
+ `free` = other.`free`
410
+ }
411
+
412
+ }
413
+ @Structure.FieldOrder("returnValue", "callStatus")
414
+ internal open class UniffiForeignFutureStructU8(
415
+ @JvmField internal var `returnValue`: Byte = 0.toByte(),
416
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
417
+ ) : Structure() {
418
+ class UniffiByValue(
419
+ `returnValue`: Byte = 0.toByte(),
420
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
421
+ ): UniffiForeignFutureStructU8(`returnValue`,`callStatus`,), Structure.ByValue
422
+
423
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructU8) {
424
+ `returnValue` = other.`returnValue`
425
+ `callStatus` = other.`callStatus`
426
+ }
427
+
428
+ }
429
+ internal interface UniffiForeignFutureCompleteU8 : com.sun.jna.Callback {
430
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU8.UniffiByValue,)
431
+ }
432
+ @Structure.FieldOrder("returnValue", "callStatus")
433
+ internal open class UniffiForeignFutureStructI8(
434
+ @JvmField internal var `returnValue`: Byte = 0.toByte(),
435
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
436
+ ) : Structure() {
437
+ class UniffiByValue(
438
+ `returnValue`: Byte = 0.toByte(),
439
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
440
+ ): UniffiForeignFutureStructI8(`returnValue`,`callStatus`,), Structure.ByValue
441
+
442
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructI8) {
443
+ `returnValue` = other.`returnValue`
444
+ `callStatus` = other.`callStatus`
445
+ }
446
+
447
+ }
448
+ internal interface UniffiForeignFutureCompleteI8 : com.sun.jna.Callback {
449
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI8.UniffiByValue,)
450
+ }
451
+ @Structure.FieldOrder("returnValue", "callStatus")
452
+ internal open class UniffiForeignFutureStructU16(
453
+ @JvmField internal var `returnValue`: Short = 0.toShort(),
454
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
455
+ ) : Structure() {
456
+ class UniffiByValue(
457
+ `returnValue`: Short = 0.toShort(),
458
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
459
+ ): UniffiForeignFutureStructU16(`returnValue`,`callStatus`,), Structure.ByValue
460
+
461
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructU16) {
462
+ `returnValue` = other.`returnValue`
463
+ `callStatus` = other.`callStatus`
464
+ }
465
+
466
+ }
467
+ internal interface UniffiForeignFutureCompleteU16 : com.sun.jna.Callback {
468
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU16.UniffiByValue,)
469
+ }
470
+ @Structure.FieldOrder("returnValue", "callStatus")
471
+ internal open class UniffiForeignFutureStructI16(
472
+ @JvmField internal var `returnValue`: Short = 0.toShort(),
473
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
474
+ ) : Structure() {
475
+ class UniffiByValue(
476
+ `returnValue`: Short = 0.toShort(),
477
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
478
+ ): UniffiForeignFutureStructI16(`returnValue`,`callStatus`,), Structure.ByValue
479
+
480
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructI16) {
481
+ `returnValue` = other.`returnValue`
482
+ `callStatus` = other.`callStatus`
483
+ }
484
+
485
+ }
486
+ internal interface UniffiForeignFutureCompleteI16 : com.sun.jna.Callback {
487
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI16.UniffiByValue,)
488
+ }
489
+ @Structure.FieldOrder("returnValue", "callStatus")
490
+ internal open class UniffiForeignFutureStructU32(
491
+ @JvmField internal var `returnValue`: Int = 0,
492
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
493
+ ) : Structure() {
494
+ class UniffiByValue(
495
+ `returnValue`: Int = 0,
496
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
497
+ ): UniffiForeignFutureStructU32(`returnValue`,`callStatus`,), Structure.ByValue
498
+
499
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructU32) {
500
+ `returnValue` = other.`returnValue`
501
+ `callStatus` = other.`callStatus`
502
+ }
503
+
504
+ }
505
+ internal interface UniffiForeignFutureCompleteU32 : com.sun.jna.Callback {
506
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU32.UniffiByValue,)
507
+ }
508
+ @Structure.FieldOrder("returnValue", "callStatus")
509
+ internal open class UniffiForeignFutureStructI32(
510
+ @JvmField internal var `returnValue`: Int = 0,
511
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
512
+ ) : Structure() {
513
+ class UniffiByValue(
514
+ `returnValue`: Int = 0,
515
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
516
+ ): UniffiForeignFutureStructI32(`returnValue`,`callStatus`,), Structure.ByValue
517
+
518
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructI32) {
519
+ `returnValue` = other.`returnValue`
520
+ `callStatus` = other.`callStatus`
521
+ }
522
+
523
+ }
524
+ internal interface UniffiForeignFutureCompleteI32 : com.sun.jna.Callback {
525
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI32.UniffiByValue,)
526
+ }
527
+ @Structure.FieldOrder("returnValue", "callStatus")
528
+ internal open class UniffiForeignFutureStructU64(
529
+ @JvmField internal var `returnValue`: Long = 0.toLong(),
530
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
531
+ ) : Structure() {
532
+ class UniffiByValue(
533
+ `returnValue`: Long = 0.toLong(),
534
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
535
+ ): UniffiForeignFutureStructU64(`returnValue`,`callStatus`,), Structure.ByValue
536
+
537
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructU64) {
538
+ `returnValue` = other.`returnValue`
539
+ `callStatus` = other.`callStatus`
540
+ }
541
+
542
+ }
543
+ internal interface UniffiForeignFutureCompleteU64 : com.sun.jna.Callback {
544
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructU64.UniffiByValue,)
545
+ }
546
+ @Structure.FieldOrder("returnValue", "callStatus")
547
+ internal open class UniffiForeignFutureStructI64(
548
+ @JvmField internal var `returnValue`: Long = 0.toLong(),
549
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
550
+ ) : Structure() {
551
+ class UniffiByValue(
552
+ `returnValue`: Long = 0.toLong(),
553
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
554
+ ): UniffiForeignFutureStructI64(`returnValue`,`callStatus`,), Structure.ByValue
555
+
556
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructI64) {
557
+ `returnValue` = other.`returnValue`
558
+ `callStatus` = other.`callStatus`
559
+ }
560
+
561
+ }
562
+ internal interface UniffiForeignFutureCompleteI64 : com.sun.jna.Callback {
563
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructI64.UniffiByValue,)
564
+ }
565
+ @Structure.FieldOrder("returnValue", "callStatus")
566
+ internal open class UniffiForeignFutureStructF32(
567
+ @JvmField internal var `returnValue`: Float = 0.0f,
568
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
569
+ ) : Structure() {
570
+ class UniffiByValue(
571
+ `returnValue`: Float = 0.0f,
572
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
573
+ ): UniffiForeignFutureStructF32(`returnValue`,`callStatus`,), Structure.ByValue
574
+
575
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructF32) {
576
+ `returnValue` = other.`returnValue`
577
+ `callStatus` = other.`callStatus`
578
+ }
579
+
580
+ }
581
+ internal interface UniffiForeignFutureCompleteF32 : com.sun.jna.Callback {
582
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructF32.UniffiByValue,)
583
+ }
584
+ @Structure.FieldOrder("returnValue", "callStatus")
585
+ internal open class UniffiForeignFutureStructF64(
586
+ @JvmField internal var `returnValue`: Double = 0.0,
587
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
588
+ ) : Structure() {
589
+ class UniffiByValue(
590
+ `returnValue`: Double = 0.0,
591
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
592
+ ): UniffiForeignFutureStructF64(`returnValue`,`callStatus`,), Structure.ByValue
593
+
594
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructF64) {
595
+ `returnValue` = other.`returnValue`
596
+ `callStatus` = other.`callStatus`
597
+ }
598
+
599
+ }
600
+ internal interface UniffiForeignFutureCompleteF64 : com.sun.jna.Callback {
601
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructF64.UniffiByValue,)
602
+ }
603
+ @Structure.FieldOrder("returnValue", "callStatus")
604
+ internal open class UniffiForeignFutureStructPointer(
605
+ @JvmField internal var `returnValue`: Pointer = Pointer.NULL,
606
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
607
+ ) : Structure() {
608
+ class UniffiByValue(
609
+ `returnValue`: Pointer = Pointer.NULL,
610
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
611
+ ): UniffiForeignFutureStructPointer(`returnValue`,`callStatus`,), Structure.ByValue
612
+
613
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructPointer) {
614
+ `returnValue` = other.`returnValue`
615
+ `callStatus` = other.`callStatus`
616
+ }
617
+
618
+ }
619
+ internal interface UniffiForeignFutureCompletePointer : com.sun.jna.Callback {
620
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructPointer.UniffiByValue,)
621
+ }
622
+ @Structure.FieldOrder("returnValue", "callStatus")
623
+ internal open class UniffiForeignFutureStructRustBuffer(
624
+ @JvmField internal var `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
625
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
626
+ ) : Structure() {
627
+ class UniffiByValue(
628
+ `returnValue`: RustBuffer.ByValue = RustBuffer.ByValue(),
629
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
630
+ ): UniffiForeignFutureStructRustBuffer(`returnValue`,`callStatus`,), Structure.ByValue
631
+
632
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructRustBuffer) {
633
+ `returnValue` = other.`returnValue`
634
+ `callStatus` = other.`callStatus`
635
+ }
636
+
637
+ }
638
+ internal interface UniffiForeignFutureCompleteRustBuffer : com.sun.jna.Callback {
639
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructRustBuffer.UniffiByValue,)
640
+ }
641
+ @Structure.FieldOrder("callStatus")
642
+ internal open class UniffiForeignFutureStructVoid(
643
+ @JvmField internal var `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
644
+ ) : Structure() {
645
+ class UniffiByValue(
646
+ `callStatus`: UniffiRustCallStatus.ByValue = UniffiRustCallStatus.ByValue(),
647
+ ): UniffiForeignFutureStructVoid(`callStatus`,), Structure.ByValue
648
+
649
+ internal fun uniffiSetValue(other: UniffiForeignFutureStructVoid) {
650
+ `callStatus` = other.`callStatus`
651
+ }
652
+
653
+ }
654
+ internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback {
655
+ fun callback(`callbackData`: Long,`result`: UniffiForeignFutureStructVoid.UniffiByValue,)
656
+ }
657
+
658
+
659
+
660
+
661
+
662
+
663
+
664
+
665
+
666
+
667
+
668
+
669
+
670
+
671
+
672
+
673
+
674
+
675
+
676
+
677
+
678
+
679
+
680
+
681
+
682
+
683
+
684
+
685
+
686
+
687
+
688
+
689
+
690
+
691
+
692
+
693
+
694
+
695
+
696
+
697
+
698
+
699
+
700
+
701
+
702
+
703
+
704
+
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+
719
+
720
+
721
+
722
+
723
+
724
+
725
+
726
+
727
+ // For large crates we prevent `MethodTooLargeException` (see #2340)
728
+ // N.B. the name of the extension is very misleading, since it is
729
+ // rather `InterfaceTooLargeException`, caused by too many methods
730
+ // in the interface for large crates.
731
+ //
732
+ // By splitting the otherwise huge interface into two parts
733
+ // * UniffiLib
734
+ // * IntegrityCheckingUniffiLib (this)
735
+ // we allow for ~2x as many methods in the UniffiLib interface.
736
+ //
737
+ // The `ffi_uniffi_contract_version` method and all checksum methods are put
738
+ // into `IntegrityCheckingUniffiLib` and these methods are called only once,
739
+ // when the library is loaded.
740
+ internal interface IntegrityCheckingUniffiLib : Library {
741
+ // Integrity check functions only
742
+ fun uniffi_bubo_wallet_ffi_checksum_method_walletlib_build_and_sign(
743
+ ): Short
744
+ fun uniffi_bubo_wallet_ffi_checksum_method_walletlib_derive_address(
745
+ ): Short
746
+ fun uniffi_bubo_wallet_ffi_checksum_method_walletlib_init(
747
+ ): Short
748
+ fun uniffi_bubo_wallet_ffi_checksum_method_walletlib_list_supported_chains(
749
+ ): Short
750
+ fun uniffi_bubo_wallet_ffi_checksum_constructor_walletlib_new(
751
+ ): Short
752
+ fun ffi_bubo_wallet_ffi_uniffi_contract_version(
753
+ ): Int
754
+
755
+ }
756
+
757
+ // A JNA Library to expose the extern-C FFI definitions.
758
+ // This is an implementation detail which will be called internally by the public API.
759
+ internal interface UniffiLib : Library {
760
+ companion object {
761
+ internal val INSTANCE: UniffiLib by lazy {
762
+ val componentName = "bubo_wallet_ffi"
763
+ // For large crates we prevent `MethodTooLargeException` (see #2340)
764
+ // N.B. the name of the extension is very misleading, since it is
765
+ // rather `InterfaceTooLargeException`, caused by too many methods
766
+ // in the interface for large crates.
767
+ //
768
+ // By splitting the otherwise huge interface into two parts
769
+ // * UniffiLib (this)
770
+ // * IntegrityCheckingUniffiLib
771
+ // And all checksum methods are put into `IntegrityCheckingUniffiLib`
772
+ // we allow for ~2x as many methods in the UniffiLib interface.
773
+ //
774
+ // Thus we first load the library with `loadIndirect` as `IntegrityCheckingUniffiLib`
775
+ // so that we can (optionally!) call `uniffiCheckApiChecksums`...
776
+ loadIndirect<IntegrityCheckingUniffiLib>(componentName)
777
+ .also { lib: IntegrityCheckingUniffiLib ->
778
+ uniffiCheckContractApiVersion(lib)
779
+ uniffiCheckApiChecksums(lib)
780
+ }
781
+ // ... and then we load the library as `UniffiLib`
782
+ // N.B. we cannot use `loadIndirect` once and then try to cast it to `UniffiLib`
783
+ // => results in `java.lang.ClassCastException: com.sun.proxy.$Proxy cannot be cast to ...`
784
+ // error. So we must call `loadIndirect` twice. For crates large enough
785
+ // to trigger this issue, the performance impact is negligible, running on
786
+ // a macOS M1 machine the `loadIndirect` call takes ~50ms.
787
+ val lib = loadIndirect<UniffiLib>(componentName)
788
+ // No need to check the contract version and checksums, since
789
+ // we already did that with `IntegrityCheckingUniffiLib` above.
790
+ // Loading of library with integrity check done.
791
+ lib
792
+ }
793
+
794
+ // The Cleaner for the whole library
795
+ internal val CLEANER: UniffiCleaner by lazy {
796
+ UniffiCleaner.create()
797
+ }
798
+ }
799
+
800
+ // FFI functions
801
+ fun uniffi_bubo_wallet_ffi_fn_clone_walletlib(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
802
+ ): Pointer
803
+ fun uniffi_bubo_wallet_ffi_fn_free_walletlib(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
804
+ ): Unit
805
+ fun uniffi_bubo_wallet_ffi_fn_constructor_walletlib_new(uniffi_out_err: UniffiRustCallStatus,
806
+ ): Pointer
807
+ fun uniffi_bubo_wallet_ffi_fn_method_walletlib_build_and_sign(`ptr`: Pointer,`chainId`: RustBuffer.ByValue,`mnemonic`: RustBuffer.ByValue,`txPayload`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
808
+ ): RustBuffer.ByValue
809
+ fun uniffi_bubo_wallet_ffi_fn_method_walletlib_derive_address(`ptr`: Pointer,`chainId`: RustBuffer.ByValue,`mnemonic`: RustBuffer.ByValue,`account`: Int,`index`: Int,`passphrase`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
810
+ ): RustBuffer.ByValue
811
+ fun uniffi_bubo_wallet_ffi_fn_method_walletlib_init(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
812
+ ): Unit
813
+ fun uniffi_bubo_wallet_ffi_fn_method_walletlib_list_supported_chains(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
814
+ ): RustBuffer.ByValue
815
+ fun ffi_bubo_wallet_ffi_rustbuffer_alloc(`size`: Long,uniffi_out_err: UniffiRustCallStatus,
816
+ ): RustBuffer.ByValue
817
+ fun ffi_bubo_wallet_ffi_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,uniffi_out_err: UniffiRustCallStatus,
818
+ ): RustBuffer.ByValue
819
+ fun ffi_bubo_wallet_ffi_rustbuffer_free(`buf`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
820
+ ): Unit
821
+ fun ffi_bubo_wallet_ffi_rustbuffer_reserve(`buf`: RustBuffer.ByValue,`additional`: Long,uniffi_out_err: UniffiRustCallStatus,
822
+ ): RustBuffer.ByValue
823
+ fun ffi_bubo_wallet_ffi_rust_future_poll_u8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
824
+ ): Unit
825
+ fun ffi_bubo_wallet_ffi_rust_future_cancel_u8(`handle`: Long,
826
+ ): Unit
827
+ fun ffi_bubo_wallet_ffi_rust_future_free_u8(`handle`: Long,
828
+ ): Unit
829
+ fun ffi_bubo_wallet_ffi_rust_future_complete_u8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
830
+ ): Byte
831
+ fun ffi_bubo_wallet_ffi_rust_future_poll_i8(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
832
+ ): Unit
833
+ fun ffi_bubo_wallet_ffi_rust_future_cancel_i8(`handle`: Long,
834
+ ): Unit
835
+ fun ffi_bubo_wallet_ffi_rust_future_free_i8(`handle`: Long,
836
+ ): Unit
837
+ fun ffi_bubo_wallet_ffi_rust_future_complete_i8(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
838
+ ): Byte
839
+ fun ffi_bubo_wallet_ffi_rust_future_poll_u16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
840
+ ): Unit
841
+ fun ffi_bubo_wallet_ffi_rust_future_cancel_u16(`handle`: Long,
842
+ ): Unit
843
+ fun ffi_bubo_wallet_ffi_rust_future_free_u16(`handle`: Long,
844
+ ): Unit
845
+ fun ffi_bubo_wallet_ffi_rust_future_complete_u16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
846
+ ): Short
847
+ fun ffi_bubo_wallet_ffi_rust_future_poll_i16(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
848
+ ): Unit
849
+ fun ffi_bubo_wallet_ffi_rust_future_cancel_i16(`handle`: Long,
850
+ ): Unit
851
+ fun ffi_bubo_wallet_ffi_rust_future_free_i16(`handle`: Long,
852
+ ): Unit
853
+ fun ffi_bubo_wallet_ffi_rust_future_complete_i16(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
854
+ ): Short
855
+ fun ffi_bubo_wallet_ffi_rust_future_poll_u32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
856
+ ): Unit
857
+ fun ffi_bubo_wallet_ffi_rust_future_cancel_u32(`handle`: Long,
858
+ ): Unit
859
+ fun ffi_bubo_wallet_ffi_rust_future_free_u32(`handle`: Long,
860
+ ): Unit
861
+ fun ffi_bubo_wallet_ffi_rust_future_complete_u32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
862
+ ): Int
863
+ fun ffi_bubo_wallet_ffi_rust_future_poll_i32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
864
+ ): Unit
865
+ fun ffi_bubo_wallet_ffi_rust_future_cancel_i32(`handle`: Long,
866
+ ): Unit
867
+ fun ffi_bubo_wallet_ffi_rust_future_free_i32(`handle`: Long,
868
+ ): Unit
869
+ fun ffi_bubo_wallet_ffi_rust_future_complete_i32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
870
+ ): Int
871
+ fun ffi_bubo_wallet_ffi_rust_future_poll_u64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
872
+ ): Unit
873
+ fun ffi_bubo_wallet_ffi_rust_future_cancel_u64(`handle`: Long,
874
+ ): Unit
875
+ fun ffi_bubo_wallet_ffi_rust_future_free_u64(`handle`: Long,
876
+ ): Unit
877
+ fun ffi_bubo_wallet_ffi_rust_future_complete_u64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
878
+ ): Long
879
+ fun ffi_bubo_wallet_ffi_rust_future_poll_i64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
880
+ ): Unit
881
+ fun ffi_bubo_wallet_ffi_rust_future_cancel_i64(`handle`: Long,
882
+ ): Unit
883
+ fun ffi_bubo_wallet_ffi_rust_future_free_i64(`handle`: Long,
884
+ ): Unit
885
+ fun ffi_bubo_wallet_ffi_rust_future_complete_i64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
886
+ ): Long
887
+ fun ffi_bubo_wallet_ffi_rust_future_poll_f32(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
888
+ ): Unit
889
+ fun ffi_bubo_wallet_ffi_rust_future_cancel_f32(`handle`: Long,
890
+ ): Unit
891
+ fun ffi_bubo_wallet_ffi_rust_future_free_f32(`handle`: Long,
892
+ ): Unit
893
+ fun ffi_bubo_wallet_ffi_rust_future_complete_f32(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
894
+ ): Float
895
+ fun ffi_bubo_wallet_ffi_rust_future_poll_f64(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
896
+ ): Unit
897
+ fun ffi_bubo_wallet_ffi_rust_future_cancel_f64(`handle`: Long,
898
+ ): Unit
899
+ fun ffi_bubo_wallet_ffi_rust_future_free_f64(`handle`: Long,
900
+ ): Unit
901
+ fun ffi_bubo_wallet_ffi_rust_future_complete_f64(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
902
+ ): Double
903
+ fun ffi_bubo_wallet_ffi_rust_future_poll_pointer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
904
+ ): Unit
905
+ fun ffi_bubo_wallet_ffi_rust_future_cancel_pointer(`handle`: Long,
906
+ ): Unit
907
+ fun ffi_bubo_wallet_ffi_rust_future_free_pointer(`handle`: Long,
908
+ ): Unit
909
+ fun ffi_bubo_wallet_ffi_rust_future_complete_pointer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
910
+ ): Pointer
911
+ fun ffi_bubo_wallet_ffi_rust_future_poll_rust_buffer(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
912
+ ): Unit
913
+ fun ffi_bubo_wallet_ffi_rust_future_cancel_rust_buffer(`handle`: Long,
914
+ ): Unit
915
+ fun ffi_bubo_wallet_ffi_rust_future_free_rust_buffer(`handle`: Long,
916
+ ): Unit
917
+ fun ffi_bubo_wallet_ffi_rust_future_complete_rust_buffer(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
918
+ ): RustBuffer.ByValue
919
+ fun ffi_bubo_wallet_ffi_rust_future_poll_void(`handle`: Long,`callback`: UniffiRustFutureContinuationCallback,`callbackData`: Long,
920
+ ): Unit
921
+ fun ffi_bubo_wallet_ffi_rust_future_cancel_void(`handle`: Long,
922
+ ): Unit
923
+ fun ffi_bubo_wallet_ffi_rust_future_free_void(`handle`: Long,
924
+ ): Unit
925
+ fun ffi_bubo_wallet_ffi_rust_future_complete_void(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
926
+ ): Unit
927
+
928
+ }
929
+
930
+ private fun uniffiCheckContractApiVersion(lib: IntegrityCheckingUniffiLib) {
931
+ // Get the bindings contract version from our ComponentInterface
932
+ val bindings_contract_version = 29
933
+ // Get the scaffolding contract version by calling the into the dylib
934
+ val scaffolding_contract_version = lib.ffi_bubo_wallet_ffi_uniffi_contract_version()
935
+ if (bindings_contract_version != scaffolding_contract_version) {
936
+ throw RuntimeException("UniFFI contract version mismatch: try cleaning and rebuilding your project")
937
+ }
938
+ }
939
+ @Suppress("UNUSED_PARAMETER")
940
+ private fun uniffiCheckApiChecksums(lib: IntegrityCheckingUniffiLib) {
941
+ if (lib.uniffi_bubo_wallet_ffi_checksum_method_walletlib_build_and_sign() != 27726.toShort()) {
942
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
943
+ }
944
+ if (lib.uniffi_bubo_wallet_ffi_checksum_method_walletlib_derive_address() != 5086.toShort()) {
945
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
946
+ }
947
+ if (lib.uniffi_bubo_wallet_ffi_checksum_method_walletlib_init() != 27966.toShort()) {
948
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
949
+ }
950
+ if (lib.uniffi_bubo_wallet_ffi_checksum_method_walletlib_list_supported_chains() != 37171.toShort()) {
951
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
952
+ }
953
+ if (lib.uniffi_bubo_wallet_ffi_checksum_constructor_walletlib_new() != 51053.toShort()) {
954
+ throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
955
+ }
956
+ }
957
+
958
+ /**
959
+ * @suppress
960
+ */
961
+ public fun uniffiEnsureInitialized() {
962
+ UniffiLib.INSTANCE
963
+ }
964
+
965
+ // Async support
966
+
967
+ // Public interface members begin here.
968
+
969
+
970
+ // Interface implemented by anything that can contain an object reference.
971
+ //
972
+ // Such types expose a `destroy()` method that must be called to cleanly
973
+ // dispose of the contained objects. Failure to call this method may result
974
+ // in memory leaks.
975
+ //
976
+ // The easiest way to ensure this method is called is to use the `.use`
977
+ // helper method to execute a block and destroy the object at the end.
978
+ interface Disposable {
979
+ fun destroy()
980
+ companion object {
981
+ fun destroy(vararg args: Any?) {
982
+ for (arg in args) {
983
+ when (arg) {
984
+ is Disposable -> arg.destroy()
985
+ is ArrayList<*> -> {
986
+ for (idx in arg.indices) {
987
+ val element = arg[idx]
988
+ if (element is Disposable) {
989
+ element.destroy()
990
+ }
991
+ }
992
+ }
993
+ is Map<*, *> -> {
994
+ for (element in arg.values) {
995
+ if (element is Disposable) {
996
+ element.destroy()
997
+ }
998
+ }
999
+ }
1000
+ is Iterable<*> -> {
1001
+ for (element in arg) {
1002
+ if (element is Disposable) {
1003
+ element.destroy()
1004
+ }
1005
+ }
1006
+ }
1007
+ }
1008
+ }
1009
+ }
1010
+ }
1011
+ }
1012
+
1013
+ /**
1014
+ * @suppress
1015
+ */
1016
+ inline fun <T : Disposable?, R> T.use(block: (T) -> R) =
1017
+ try {
1018
+ block(this)
1019
+ } finally {
1020
+ try {
1021
+ // N.B. our implementation is on the nullable type `Disposable?`.
1022
+ this?.destroy()
1023
+ } catch (e: Throwable) {
1024
+ // swallow
1025
+ }
1026
+ }
1027
+
1028
+ /**
1029
+ * Used to instantiate an interface without an actual pointer, for fakes in tests, mostly.
1030
+ *
1031
+ * @suppress
1032
+ * */
1033
+ object NoPointer
1034
+ /**
1035
+ * The cleaner interface for Object finalization code to run.
1036
+ * This is the entry point to any implementation that we're using.
1037
+ *
1038
+ * The cleaner registers objects and returns cleanables, so now we are
1039
+ * defining a `UniffiCleaner` with a `UniffiClenaer.Cleanable` to abstract the
1040
+ * different implmentations available at compile time.
1041
+ *
1042
+ * @suppress
1043
+ */
1044
+ interface UniffiCleaner {
1045
+ interface Cleanable {
1046
+ fun clean()
1047
+ }
1048
+
1049
+ fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable
1050
+
1051
+ companion object
1052
+ }
1053
+
1054
+ // The fallback Jna cleaner, which is available for both Android, and the JVM.
1055
+ private class UniffiJnaCleaner : UniffiCleaner {
1056
+ private val cleaner = com.sun.jna.internal.Cleaner.getCleaner()
1057
+
1058
+ override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable =
1059
+ UniffiJnaCleanable(cleaner.register(value, cleanUpTask))
1060
+ }
1061
+
1062
+ private class UniffiJnaCleanable(
1063
+ private val cleanable: com.sun.jna.internal.Cleaner.Cleanable,
1064
+ ) : UniffiCleaner.Cleanable {
1065
+ override fun clean() = cleanable.clean()
1066
+ }
1067
+
1068
+
1069
+ // We decide at uniffi binding generation time whether we were
1070
+ // using Android or not.
1071
+ // There are further runtime checks to chose the correct implementation
1072
+ // of the cleaner.
1073
+ private fun UniffiCleaner.Companion.create(): UniffiCleaner =
1074
+ try {
1075
+ // For safety's sake: if the library hasn't been run in android_cleaner = true
1076
+ // mode, but is being run on Android, then we still need to think about
1077
+ // Android API versions.
1078
+ // So we check if java.lang.ref.Cleaner is there, and use that…
1079
+ java.lang.Class.forName("java.lang.ref.Cleaner")
1080
+ JavaLangRefCleaner()
1081
+ } catch (e: ClassNotFoundException) {
1082
+ // … otherwise, fallback to the JNA cleaner.
1083
+ UniffiJnaCleaner()
1084
+ }
1085
+
1086
+ private class JavaLangRefCleaner : UniffiCleaner {
1087
+ val cleaner = java.lang.ref.Cleaner.create()
1088
+
1089
+ override fun register(value: Any, cleanUpTask: Runnable): UniffiCleaner.Cleanable =
1090
+ JavaLangRefCleanable(cleaner.register(value, cleanUpTask))
1091
+ }
1092
+
1093
+ private class JavaLangRefCleanable(
1094
+ val cleanable: java.lang.ref.Cleaner.Cleanable
1095
+ ) : UniffiCleaner.Cleanable {
1096
+ override fun clean() = cleanable.clean()
1097
+ }
1098
+
1099
+ /**
1100
+ * @suppress
1101
+ */
1102
+ public object FfiConverterUInt: FfiConverter<UInt, Int> {
1103
+ override fun lift(value: Int): UInt {
1104
+ return value.toUInt()
1105
+ }
1106
+
1107
+ override fun read(buf: ByteBuffer): UInt {
1108
+ return lift(buf.getInt())
1109
+ }
1110
+
1111
+ override fun lower(value: UInt): Int {
1112
+ return value.toInt()
1113
+ }
1114
+
1115
+ override fun allocationSize(value: UInt) = 4UL
1116
+
1117
+ override fun write(value: UInt, buf: ByteBuffer) {
1118
+ buf.putInt(value.toInt())
1119
+ }
1120
+ }
1121
+
1122
+ /**
1123
+ * @suppress
1124
+ */
1125
+ public object FfiConverterString: FfiConverter<String, RustBuffer.ByValue> {
1126
+ // Note: we don't inherit from FfiConverterRustBuffer, because we use a
1127
+ // special encoding when lowering/lifting. We can use `RustBuffer.len` to
1128
+ // store our length and avoid writing it out to the buffer.
1129
+ override fun lift(value: RustBuffer.ByValue): String {
1130
+ try {
1131
+ val byteArr = ByteArray(value.len.toInt())
1132
+ value.asByteBuffer()!!.get(byteArr)
1133
+ return byteArr.toString(Charsets.UTF_8)
1134
+ } finally {
1135
+ RustBuffer.free(value)
1136
+ }
1137
+ }
1138
+
1139
+ override fun read(buf: ByteBuffer): String {
1140
+ val len = buf.getInt()
1141
+ val byteArr = ByteArray(len)
1142
+ buf.get(byteArr)
1143
+ return byteArr.toString(Charsets.UTF_8)
1144
+ }
1145
+
1146
+ fun toUtf8(value: String): ByteBuffer {
1147
+ // Make sure we don't have invalid UTF-16, check for lone surrogates.
1148
+ return Charsets.UTF_8.newEncoder().run {
1149
+ onMalformedInput(CodingErrorAction.REPORT)
1150
+ encode(CharBuffer.wrap(value))
1151
+ }
1152
+ }
1153
+
1154
+ override fun lower(value: String): RustBuffer.ByValue {
1155
+ val byteBuf = toUtf8(value)
1156
+ // Ideally we'd pass these bytes to `ffi_bytebuffer_from_bytes`, but doing so would require us
1157
+ // to copy them into a JNA `Memory`. So we might as well directly copy them into a `RustBuffer`.
1158
+ val rbuf = RustBuffer.alloc(byteBuf.limit().toULong())
1159
+ rbuf.asByteBuffer()!!.put(byteBuf)
1160
+ return rbuf
1161
+ }
1162
+
1163
+ // We aren't sure exactly how many bytes our string will be once it's UTF-8
1164
+ // encoded. Allocate 3 bytes per UTF-16 code unit which will always be
1165
+ // enough.
1166
+ override fun allocationSize(value: String): ULong {
1167
+ val sizeForLength = 4UL
1168
+ val sizeForString = value.length.toULong() * 3UL
1169
+ return sizeForLength + sizeForString
1170
+ }
1171
+
1172
+ override fun write(value: String, buf: ByteBuffer) {
1173
+ val byteBuf = toUtf8(value)
1174
+ buf.putInt(byteBuf.limit())
1175
+ buf.put(byteBuf)
1176
+ }
1177
+ }
1178
+
1179
+ /**
1180
+ * @suppress
1181
+ */
1182
+ public object FfiConverterByteArray: FfiConverterRustBuffer<ByteArray> {
1183
+ override fun read(buf: ByteBuffer): ByteArray {
1184
+ val len = buf.getInt()
1185
+ val byteArr = ByteArray(len)
1186
+ buf.get(byteArr)
1187
+ return byteArr
1188
+ }
1189
+ override fun allocationSize(value: ByteArray): ULong {
1190
+ return 4UL + value.size.toULong()
1191
+ }
1192
+ override fun write(value: ByteArray, buf: ByteBuffer) {
1193
+ buf.putInt(value.size)
1194
+ buf.put(value)
1195
+ }
1196
+ }
1197
+
1198
+
1199
+ // This template implements a class for working with a Rust struct via a Pointer/Arc<T>
1200
+ // to the live Rust struct on the other side of the FFI.
1201
+ //
1202
+ // Each instance implements core operations for working with the Rust `Arc<T>` and the
1203
+ // Kotlin Pointer to work with the live Rust struct on the other side of the FFI.
1204
+ //
1205
+ // There's some subtlety here, because we have to be careful not to operate on a Rust
1206
+ // struct after it has been dropped, and because we must expose a public API for freeing
1207
+ // theq Kotlin wrapper object in lieu of reliable finalizers. The core requirements are:
1208
+ //
1209
+ // * Each instance holds an opaque pointer to the underlying Rust struct.
1210
+ // Method calls need to read this pointer from the object's state and pass it in to
1211
+ // the Rust FFI.
1212
+ //
1213
+ // * When an instance is no longer needed, its pointer should be passed to a
1214
+ // special destructor function provided by the Rust FFI, which will drop the
1215
+ // underlying Rust struct.
1216
+ //
1217
+ // * Given an instance, calling code is expected to call the special
1218
+ // `destroy` method in order to free it after use, either by calling it explicitly
1219
+ // or by using a higher-level helper like the `use` method. Failing to do so risks
1220
+ // leaking the underlying Rust struct.
1221
+ //
1222
+ // * We can't assume that calling code will do the right thing, and must be prepared
1223
+ // to handle Kotlin method calls executing concurrently with or even after a call to
1224
+ // `destroy`, and to handle multiple (possibly concurrent!) calls to `destroy`.
1225
+ //
1226
+ // * We must never allow Rust code to operate on the underlying Rust struct after
1227
+ // the destructor has been called, and must never call the destructor more than once.
1228
+ // Doing so may trigger memory unsafety.
1229
+ //
1230
+ // * To mitigate many of the risks of leaking memory and use-after-free unsafety, a `Cleaner`
1231
+ // is implemented to call the destructor when the Kotlin object becomes unreachable.
1232
+ // This is done in a background thread. This is not a panacea, and client code should be aware that
1233
+ // 1. the thread may starve if some there are objects that have poorly performing
1234
+ // `drop` methods or do significant work in their `drop` methods.
1235
+ // 2. the thread is shared across the whole library. This can be tuned by using `android_cleaner = true`,
1236
+ // or `android = true` in the [`kotlin` section of the `uniffi.toml` file](https://mozilla.github.io/uniffi-rs/kotlin/configuration.html).
1237
+ //
1238
+ // If we try to implement this with mutual exclusion on access to the pointer, there is the
1239
+ // possibility of a race between a method call and a concurrent call to `destroy`:
1240
+ //
1241
+ // * Thread A starts a method call, reads the value of the pointer, but is interrupted
1242
+ // before it can pass the pointer over the FFI to Rust.
1243
+ // * Thread B calls `destroy` and frees the underlying Rust struct.
1244
+ // * Thread A resumes, passing the already-read pointer value to Rust and triggering
1245
+ // a use-after-free.
1246
+ //
1247
+ // One possible solution would be to use a `ReadWriteLock`, with each method call taking
1248
+ // a read lock (and thus allowed to run concurrently) and the special `destroy` method
1249
+ // taking a write lock (and thus blocking on live method calls). However, we aim not to
1250
+ // generate methods with any hidden blocking semantics, and a `destroy` method that might
1251
+ // block if called incorrectly seems to meet that bar.
1252
+ //
1253
+ // So, we achieve our goals by giving each instance an associated `AtomicLong` counter to track
1254
+ // the number of in-flight method calls, and an `AtomicBoolean` flag to indicate whether `destroy`
1255
+ // has been called. These are updated according to the following rules:
1256
+ //
1257
+ // * The initial value of the counter is 1, indicating a live object with no in-flight calls.
1258
+ // The initial value for the flag is false.
1259
+ //
1260
+ // * At the start of each method call, we atomically check the counter.
1261
+ // If it is 0 then the underlying Rust struct has already been destroyed and the call is aborted.
1262
+ // If it is nonzero them we atomically increment it by 1 and proceed with the method call.
1263
+ //
1264
+ // * At the end of each method call, we atomically decrement and check the counter.
1265
+ // If it has reached zero then we destroy the underlying Rust struct.
1266
+ //
1267
+ // * When `destroy` is called, we atomically flip the flag from false to true.
1268
+ // If the flag was already true we silently fail.
1269
+ // Otherwise we atomically decrement and check the counter.
1270
+ // If it has reached zero then we destroy the underlying Rust struct.
1271
+ //
1272
+ // Astute readers may observe that this all sounds very similar to the way that Rust's `Arc<T>` works,
1273
+ // and indeed it is, with the addition of a flag to guard against multiple calls to `destroy`.
1274
+ //
1275
+ // The overall effect is that the underlying Rust struct is destroyed only when `destroy` has been
1276
+ // called *and* all in-flight method calls have completed, avoiding violating any of the expectations
1277
+ // of the underlying Rust code.
1278
+ //
1279
+ // This makes a cleaner a better alternative to _not_ calling `destroy()` as
1280
+ // and when the object is finished with, but the abstraction is not perfect: if the Rust object's `drop`
1281
+ // method is slow, and/or there are many objects to cleanup, and it's on a low end Android device, then the cleaner
1282
+ // thread may be starved, and the app will leak memory.
1283
+ //
1284
+ // In this case, `destroy`ing manually may be a better solution.
1285
+ //
1286
+ // The cleaner can live side by side with the manual calling of `destroy`. In the order of responsiveness, uniffi objects
1287
+ // with Rust peers are reclaimed:
1288
+ //
1289
+ // 1. By calling the `destroy` method of the object, which calls `rustObject.free()`. If that doesn't happen:
1290
+ // 2. When the object becomes unreachable, AND the Cleaner thread gets to call `rustObject.free()`. If the thread is starved then:
1291
+ // 3. The memory is reclaimed when the process terminates.
1292
+ //
1293
+ // [1] https://stackoverflow.com/questions/24376768/can-java-finalize-an-object-when-it-is-still-in-scope/24380219
1294
+ //
1295
+
1296
+
1297
+ public interface WalletLibInterface {
1298
+
1299
+ fun `buildAndSign`(`chainId`: kotlin.String, `mnemonic`: kotlin.String, `txPayload`: kotlin.ByteArray): kotlin.ByteArray
1300
+
1301
+ fun `deriveAddress`(`chainId`: kotlin.String, `mnemonic`: kotlin.String, `account`: kotlin.UInt, `index`: kotlin.UInt, `passphrase`: kotlin.String?): kotlin.String
1302
+
1303
+ fun `init`()
1304
+
1305
+ fun `listSupportedChains`(): List<SupportedChainInfo>
1306
+
1307
+ companion object
1308
+ }
1309
+
1310
+ open class WalletLib: Disposable, AutoCloseable, WalletLibInterface
1311
+ {
1312
+
1313
+ constructor(pointer: Pointer) {
1314
+ this.pointer = pointer
1315
+ this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer))
1316
+ }
1317
+
1318
+ /**
1319
+ * This constructor can be used to instantiate a fake object. Only used for tests. Any
1320
+ * attempt to actually use an object constructed this way will fail as there is no
1321
+ * connected Rust object.
1322
+ */
1323
+ @Suppress("UNUSED_PARAMETER")
1324
+ constructor(noPointer: NoPointer) {
1325
+ this.pointer = null
1326
+ this.cleanable = UniffiLib.CLEANER.register(this, UniffiCleanAction(pointer))
1327
+ }
1328
+ constructor() :
1329
+ this(
1330
+ uniffiRustCall() { _status ->
1331
+ UniffiLib.INSTANCE.uniffi_bubo_wallet_ffi_fn_constructor_walletlib_new(
1332
+ _status)
1333
+ }
1334
+ )
1335
+
1336
+ protected val pointer: Pointer?
1337
+ protected val cleanable: UniffiCleaner.Cleanable
1338
+
1339
+ private val wasDestroyed = AtomicBoolean(false)
1340
+ private val callCounter = AtomicLong(1)
1341
+
1342
+ override fun destroy() {
1343
+ // Only allow a single call to this method.
1344
+ // TODO: maybe we should log a warning if called more than once?
1345
+ if (this.wasDestroyed.compareAndSet(false, true)) {
1346
+ // This decrement always matches the initial count of 1 given at creation time.
1347
+ if (this.callCounter.decrementAndGet() == 0L) {
1348
+ cleanable.clean()
1349
+ }
1350
+ }
1351
+ }
1352
+
1353
+ @Synchronized
1354
+ override fun close() {
1355
+ this.destroy()
1356
+ }
1357
+
1358
+ internal inline fun <R> callWithPointer(block: (ptr: Pointer) -> R): R {
1359
+ // Check and increment the call counter, to keep the object alive.
1360
+ // This needs a compare-and-set retry loop in case of concurrent updates.
1361
+ do {
1362
+ val c = this.callCounter.get()
1363
+ if (c == 0L) {
1364
+ throw IllegalStateException("${this.javaClass.simpleName} object has already been destroyed")
1365
+ }
1366
+ if (c == Long.MAX_VALUE) {
1367
+ throw IllegalStateException("${this.javaClass.simpleName} call counter would overflow")
1368
+ }
1369
+ } while (! this.callCounter.compareAndSet(c, c + 1L))
1370
+ // Now we can safely do the method call without the pointer being freed concurrently.
1371
+ try {
1372
+ return block(this.uniffiClonePointer())
1373
+ } finally {
1374
+ // This decrement always matches the increment we performed above.
1375
+ if (this.callCounter.decrementAndGet() == 0L) {
1376
+ cleanable.clean()
1377
+ }
1378
+ }
1379
+ }
1380
+
1381
+ // Use a static inner class instead of a closure so as not to accidentally
1382
+ // capture `this` as part of the cleanable's action.
1383
+ private class UniffiCleanAction(private val pointer: Pointer?) : Runnable {
1384
+ override fun run() {
1385
+ pointer?.let { ptr ->
1386
+ uniffiRustCall { status ->
1387
+ UniffiLib.INSTANCE.uniffi_bubo_wallet_ffi_fn_free_walletlib(ptr, status)
1388
+ }
1389
+ }
1390
+ }
1391
+ }
1392
+
1393
+ fun uniffiClonePointer(): Pointer {
1394
+ return uniffiRustCall() { status ->
1395
+ UniffiLib.INSTANCE.uniffi_bubo_wallet_ffi_fn_clone_walletlib(pointer!!, status)
1396
+ }
1397
+ }
1398
+
1399
+
1400
+ @Throws(FfiException::class)override fun `buildAndSign`(`chainId`: kotlin.String, `mnemonic`: kotlin.String, `txPayload`: kotlin.ByteArray): kotlin.ByteArray {
1401
+ return FfiConverterByteArray.lift(
1402
+ callWithPointer {
1403
+ uniffiRustCallWithError(FfiException) { _status ->
1404
+ UniffiLib.INSTANCE.uniffi_bubo_wallet_ffi_fn_method_walletlib_build_and_sign(
1405
+ it, FfiConverterString.lower(`chainId`),FfiConverterString.lower(`mnemonic`),FfiConverterByteArray.lower(`txPayload`),_status)
1406
+ }
1407
+ }
1408
+ )
1409
+ }
1410
+
1411
+
1412
+
1413
+ @Throws(FfiException::class)override fun `deriveAddress`(`chainId`: kotlin.String, `mnemonic`: kotlin.String, `account`: kotlin.UInt, `index`: kotlin.UInt, `passphrase`: kotlin.String?): kotlin.String {
1414
+ return FfiConverterString.lift(
1415
+ callWithPointer {
1416
+ uniffiRustCallWithError(FfiException) { _status ->
1417
+ UniffiLib.INSTANCE.uniffi_bubo_wallet_ffi_fn_method_walletlib_derive_address(
1418
+ it, FfiConverterString.lower(`chainId`),FfiConverterString.lower(`mnemonic`),FfiConverterUInt.lower(`account`),FfiConverterUInt.lower(`index`),FfiConverterOptionalString.lower(`passphrase`),_status)
1419
+ }
1420
+ }
1421
+ )
1422
+ }
1423
+
1424
+
1425
+
1426
+ @Throws(FfiException::class)override fun `init`()
1427
+ =
1428
+ callWithPointer {
1429
+ uniffiRustCallWithError(FfiException) { _status ->
1430
+ UniffiLib.INSTANCE.uniffi_bubo_wallet_ffi_fn_method_walletlib_init(
1431
+ it, _status)
1432
+ }
1433
+ }
1434
+
1435
+
1436
+
1437
+
1438
+ @Throws(FfiException::class)override fun `listSupportedChains`(): List<SupportedChainInfo> {
1439
+ return FfiConverterSequenceTypeSupportedChainInfo.lift(
1440
+ callWithPointer {
1441
+ uniffiRustCallWithError(FfiException) { _status ->
1442
+ UniffiLib.INSTANCE.uniffi_bubo_wallet_ffi_fn_method_walletlib_list_supported_chains(
1443
+ it, _status)
1444
+ }
1445
+ }
1446
+ )
1447
+ }
1448
+
1449
+
1450
+
1451
+
1452
+
1453
+
1454
+ companion object
1455
+
1456
+ }
1457
+
1458
+ /**
1459
+ * @suppress
1460
+ */
1461
+ public object FfiConverterTypeWalletLib: FfiConverter<WalletLib, Pointer> {
1462
+
1463
+ override fun lower(value: WalletLib): Pointer {
1464
+ return value.uniffiClonePointer()
1465
+ }
1466
+
1467
+ override fun lift(value: Pointer): WalletLib {
1468
+ return WalletLib(value)
1469
+ }
1470
+
1471
+ override fun read(buf: ByteBuffer): WalletLib {
1472
+ // The Rust code always writes pointers as 8 bytes, and will
1473
+ // fail to compile if they don't fit.
1474
+ return lift(Pointer(buf.getLong()))
1475
+ }
1476
+
1477
+ override fun allocationSize(value: WalletLib) = 8UL
1478
+
1479
+ override fun write(value: WalletLib, buf: ByteBuffer) {
1480
+ // The Rust code always expects pointers written as 8 bytes,
1481
+ // and will fail to compile if they don't fit.
1482
+ buf.putLong(Pointer.nativeValue(lower(value)))
1483
+ }
1484
+ }
1485
+
1486
+
1487
+
1488
+ data class SupportedChainInfo (
1489
+ var `chainId`: kotlin.String,
1490
+ var `capabilities`: List<kotlin.String>
1491
+ ) {
1492
+
1493
+ companion object
1494
+ }
1495
+
1496
+ /**
1497
+ * @suppress
1498
+ */
1499
+ public object FfiConverterTypeSupportedChainInfo: FfiConverterRustBuffer<SupportedChainInfo> {
1500
+ override fun read(buf: ByteBuffer): SupportedChainInfo {
1501
+ return SupportedChainInfo(
1502
+ FfiConverterString.read(buf),
1503
+ FfiConverterSequenceString.read(buf),
1504
+ )
1505
+ }
1506
+
1507
+ override fun allocationSize(value: SupportedChainInfo) = (
1508
+ FfiConverterString.allocationSize(value.`chainId`) +
1509
+ FfiConverterSequenceString.allocationSize(value.`capabilities`)
1510
+ )
1511
+
1512
+ override fun write(value: SupportedChainInfo, buf: ByteBuffer) {
1513
+ FfiConverterString.write(value.`chainId`, buf)
1514
+ FfiConverterSequenceString.write(value.`capabilities`, buf)
1515
+ }
1516
+ }
1517
+
1518
+
1519
+
1520
+
1521
+
1522
+ sealed class FfiException: kotlin.Exception() {
1523
+
1524
+ class Failure(
1525
+
1526
+ val `reason`: kotlin.String
1527
+ ) : FfiException() {
1528
+ override val message
1529
+ get() = "reason=${ `reason` }"
1530
+ }
1531
+
1532
+
1533
+ companion object ErrorHandler : UniffiRustCallStatusErrorHandler<FfiException> {
1534
+ override fun lift(error_buf: RustBuffer.ByValue): FfiException = FfiConverterTypeFfiError.lift(error_buf)
1535
+ }
1536
+
1537
+
1538
+ }
1539
+
1540
+ /**
1541
+ * @suppress
1542
+ */
1543
+ public object FfiConverterTypeFfiError : FfiConverterRustBuffer<FfiException> {
1544
+ override fun read(buf: ByteBuffer): FfiException {
1545
+
1546
+
1547
+ return when(buf.getInt()) {
1548
+ 1 -> FfiException.Failure(
1549
+ FfiConverterString.read(buf),
1550
+ )
1551
+ else -> throw RuntimeException("invalid error enum value, something is very wrong!!")
1552
+ }
1553
+ }
1554
+
1555
+ override fun allocationSize(value: FfiException): ULong {
1556
+ return when(value) {
1557
+ is FfiException.Failure -> (
1558
+ // Add the size for the Int that specifies the variant plus the size needed for all fields
1559
+ 4UL
1560
+ + FfiConverterString.allocationSize(value.`reason`)
1561
+ )
1562
+ }
1563
+ }
1564
+
1565
+ override fun write(value: FfiException, buf: ByteBuffer) {
1566
+ when(value) {
1567
+ is FfiException.Failure -> {
1568
+ buf.putInt(1)
1569
+ FfiConverterString.write(value.`reason`, buf)
1570
+ Unit
1571
+ }
1572
+ }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ }
1573
+ }
1574
+
1575
+ }
1576
+
1577
+
1578
+
1579
+
1580
+ /**
1581
+ * @suppress
1582
+ */
1583
+ public object FfiConverterOptionalString: FfiConverterRustBuffer<kotlin.String?> {
1584
+ override fun read(buf: ByteBuffer): kotlin.String? {
1585
+ if (buf.get().toInt() == 0) {
1586
+ return null
1587
+ }
1588
+ return FfiConverterString.read(buf)
1589
+ }
1590
+
1591
+ override fun allocationSize(value: kotlin.String?): ULong {
1592
+ if (value == null) {
1593
+ return 1UL
1594
+ } else {
1595
+ return 1UL + FfiConverterString.allocationSize(value)
1596
+ }
1597
+ }
1598
+
1599
+ override fun write(value: kotlin.String?, buf: ByteBuffer) {
1600
+ if (value == null) {
1601
+ buf.put(0)
1602
+ } else {
1603
+ buf.put(1)
1604
+ FfiConverterString.write(value, buf)
1605
+ }
1606
+ }
1607
+ }
1608
+
1609
+
1610
+
1611
+
1612
+ /**
1613
+ * @suppress
1614
+ */
1615
+ public object FfiConverterSequenceString: FfiConverterRustBuffer<List<kotlin.String>> {
1616
+ override fun read(buf: ByteBuffer): List<kotlin.String> {
1617
+ val len = buf.getInt()
1618
+ return List<kotlin.String>(len) {
1619
+ FfiConverterString.read(buf)
1620
+ }
1621
+ }
1622
+
1623
+ override fun allocationSize(value: List<kotlin.String>): ULong {
1624
+ val sizeForLength = 4UL
1625
+ val sizeForItems = value.map { FfiConverterString.allocationSize(it) }.sum()
1626
+ return sizeForLength + sizeForItems
1627
+ }
1628
+
1629
+ override fun write(value: List<kotlin.String>, buf: ByteBuffer) {
1630
+ buf.putInt(value.size)
1631
+ value.iterator().forEach {
1632
+ FfiConverterString.write(it, buf)
1633
+ }
1634
+ }
1635
+ }
1636
+
1637
+
1638
+
1639
+
1640
+ /**
1641
+ * @suppress
1642
+ */
1643
+ public object FfiConverterSequenceTypeSupportedChainInfo: FfiConverterRustBuffer<List<SupportedChainInfo>> {
1644
+ override fun read(buf: ByteBuffer): List<SupportedChainInfo> {
1645
+ val len = buf.getInt()
1646
+ return List<SupportedChainInfo>(len) {
1647
+ FfiConverterTypeSupportedChainInfo.read(buf)
1648
+ }
1649
+ }
1650
+
1651
+ override fun allocationSize(value: List<SupportedChainInfo>): ULong {
1652
+ val sizeForLength = 4UL
1653
+ val sizeForItems = value.map { FfiConverterTypeSupportedChainInfo.allocationSize(it) }.sum()
1654
+ return sizeForLength + sizeForItems
1655
+ }
1656
+
1657
+ override fun write(value: List<SupportedChainInfo>, buf: ByteBuffer) {
1658
+ buf.putInt(value.size)
1659
+ value.iterator().forEach {
1660
+ FfiConverterTypeSupportedChainInfo.write(it, buf)
1661
+ }
1662
+ }
1663
+ }
1664
+