@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,905 @@
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
+ // swiftlint:disable all
5
+ import Foundation
6
+
7
+ // Depending on the consumer's build setup, the low-level FFI code
8
+ // might be in a separate module, or it might be compiled inline into
9
+ // this module. This is a bit of light hackery to work with both.
10
+ #if canImport(bubo_wallet_ffiFFI)
11
+ import bubo_wallet_ffiFFI
12
+ #endif
13
+
14
+ fileprivate extension RustBuffer {
15
+ // Allocate a new buffer, copying the contents of a `UInt8` array.
16
+ init(bytes: [UInt8]) {
17
+ let rbuf = bytes.withUnsafeBufferPointer { ptr in
18
+ RustBuffer.from(ptr)
19
+ }
20
+ self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data)
21
+ }
22
+
23
+ static func empty() -> RustBuffer {
24
+ RustBuffer(capacity: 0, len:0, data: nil)
25
+ }
26
+
27
+ static func from(_ ptr: UnsafeBufferPointer<UInt8>) -> RustBuffer {
28
+ try! rustCall { ffi_bubo_wallet_ffi_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) }
29
+ }
30
+
31
+ // Frees the buffer in place.
32
+ // The buffer must not be used after this is called.
33
+ func deallocate() {
34
+ try! rustCall { ffi_bubo_wallet_ffi_rustbuffer_free(self, $0) }
35
+ }
36
+ }
37
+
38
+ fileprivate extension ForeignBytes {
39
+ init(bufferPointer: UnsafeBufferPointer<UInt8>) {
40
+ self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress)
41
+ }
42
+ }
43
+
44
+ // For every type used in the interface, we provide helper methods for conveniently
45
+ // lifting and lowering that type from C-compatible data, and for reading and writing
46
+ // values of that type in a buffer.
47
+
48
+ // Helper classes/extensions that don't change.
49
+ // Someday, this will be in a library of its own.
50
+
51
+ fileprivate extension Data {
52
+ init(rustBuffer: RustBuffer) {
53
+ self.init(
54
+ bytesNoCopy: rustBuffer.data!,
55
+ count: Int(rustBuffer.len),
56
+ deallocator: .none
57
+ )
58
+ }
59
+ }
60
+
61
+ // Define reader functionality. Normally this would be defined in a class or
62
+ // struct, but we use standalone functions instead in order to make external
63
+ // types work.
64
+ //
65
+ // With external types, one swift source file needs to be able to call the read
66
+ // method on another source file's FfiConverter, but then what visibility
67
+ // should Reader have?
68
+ // - If Reader is fileprivate, then this means the read() must also
69
+ // be fileprivate, which doesn't work with external types.
70
+ // - If Reader is internal/public, we'll get compile errors since both source
71
+ // files will try define the same type.
72
+ //
73
+ // Instead, the read() method and these helper functions input a tuple of data
74
+
75
+ fileprivate func createReader(data: Data) -> (data: Data, offset: Data.Index) {
76
+ (data: data, offset: 0)
77
+ }
78
+
79
+ // Reads an integer at the current offset, in big-endian order, and advances
80
+ // the offset on success. Throws if reading the integer would move the
81
+ // offset past the end of the buffer.
82
+ fileprivate func readInt<T: FixedWidthInteger>(_ reader: inout (data: Data, offset: Data.Index)) throws -> T {
83
+ let range = reader.offset..<reader.offset + MemoryLayout<T>.size
84
+ guard reader.data.count >= range.upperBound else {
85
+ throw UniffiInternalError.bufferOverflow
86
+ }
87
+ if T.self == UInt8.self {
88
+ let value = reader.data[reader.offset]
89
+ reader.offset += 1
90
+ return value as! T
91
+ }
92
+ var value: T = 0
93
+ let _ = withUnsafeMutableBytes(of: &value, { reader.data.copyBytes(to: $0, from: range)})
94
+ reader.offset = range.upperBound
95
+ return value.bigEndian
96
+ }
97
+
98
+ // Reads an arbitrary number of bytes, to be used to read
99
+ // raw bytes, this is useful when lifting strings
100
+ fileprivate func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> Array<UInt8> {
101
+ let range = reader.offset..<(reader.offset+count)
102
+ guard reader.data.count >= range.upperBound else {
103
+ throw UniffiInternalError.bufferOverflow
104
+ }
105
+ var value = [UInt8](repeating: 0, count: count)
106
+ value.withUnsafeMutableBufferPointer({ buffer in
107
+ reader.data.copyBytes(to: buffer, from: range)
108
+ })
109
+ reader.offset = range.upperBound
110
+ return value
111
+ }
112
+
113
+ // Reads a float at the current offset.
114
+ fileprivate func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float {
115
+ return Float(bitPattern: try readInt(&reader))
116
+ }
117
+
118
+ // Reads a float at the current offset.
119
+ fileprivate func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double {
120
+ return Double(bitPattern: try readInt(&reader))
121
+ }
122
+
123
+ // Indicates if the offset has reached the end of the buffer.
124
+ fileprivate func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool {
125
+ return reader.offset < reader.data.count
126
+ }
127
+
128
+ // Define writer functionality. Normally this would be defined in a class or
129
+ // struct, but we use standalone functions instead in order to make external
130
+ // types work. See the above discussion on Readers for details.
131
+
132
+ fileprivate func createWriter() -> [UInt8] {
133
+ return []
134
+ }
135
+
136
+ fileprivate func writeBytes<S>(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 {
137
+ writer.append(contentsOf: byteArr)
138
+ }
139
+
140
+ // Writes an integer in big-endian order.
141
+ //
142
+ // Warning: make sure what you are trying to write
143
+ // is in the correct type!
144
+ fileprivate func writeInt<T: FixedWidthInteger>(_ writer: inout [UInt8], _ value: T) {
145
+ var value = value.bigEndian
146
+ withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) }
147
+ }
148
+
149
+ fileprivate func writeFloat(_ writer: inout [UInt8], _ value: Float) {
150
+ writeInt(&writer, value.bitPattern)
151
+ }
152
+
153
+ fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) {
154
+ writeInt(&writer, value.bitPattern)
155
+ }
156
+
157
+ // Protocol for types that transfer other types across the FFI. This is
158
+ // analogous to the Rust trait of the same name.
159
+ fileprivate protocol FfiConverter {
160
+ associatedtype FfiType
161
+ associatedtype SwiftType
162
+
163
+ static func lift(_ value: FfiType) throws -> SwiftType
164
+ static func lower(_ value: SwiftType) -> FfiType
165
+ static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType
166
+ static func write(_ value: SwiftType, into buf: inout [UInt8])
167
+ }
168
+
169
+ // Types conforming to `Primitive` pass themselves directly over the FFI.
170
+ fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { }
171
+
172
+ extension FfiConverterPrimitive {
173
+ #if swift(>=5.8)
174
+ @_documentation(visibility: private)
175
+ #endif
176
+ public static func lift(_ value: FfiType) throws -> SwiftType {
177
+ return value
178
+ }
179
+
180
+ #if swift(>=5.8)
181
+ @_documentation(visibility: private)
182
+ #endif
183
+ public static func lower(_ value: SwiftType) -> FfiType {
184
+ return value
185
+ }
186
+ }
187
+
188
+ // Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`.
189
+ // Used for complex types where it's hard to write a custom lift/lower.
190
+ fileprivate protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {}
191
+
192
+ extension FfiConverterRustBuffer {
193
+ #if swift(>=5.8)
194
+ @_documentation(visibility: private)
195
+ #endif
196
+ public static func lift(_ buf: RustBuffer) throws -> SwiftType {
197
+ var reader = createReader(data: Data(rustBuffer: buf))
198
+ let value = try read(from: &reader)
199
+ if hasRemaining(reader) {
200
+ throw UniffiInternalError.incompleteData
201
+ }
202
+ buf.deallocate()
203
+ return value
204
+ }
205
+
206
+ #if swift(>=5.8)
207
+ @_documentation(visibility: private)
208
+ #endif
209
+ public static func lower(_ value: SwiftType) -> RustBuffer {
210
+ var writer = createWriter()
211
+ write(value, into: &writer)
212
+ return RustBuffer(bytes: writer)
213
+ }
214
+ }
215
+ // An error type for FFI errors. These errors occur at the UniFFI level, not
216
+ // the library level.
217
+ fileprivate enum UniffiInternalError: LocalizedError {
218
+ case bufferOverflow
219
+ case incompleteData
220
+ case unexpectedOptionalTag
221
+ case unexpectedEnumCase
222
+ case unexpectedNullPointer
223
+ case unexpectedRustCallStatusCode
224
+ case unexpectedRustCallError
225
+ case unexpectedStaleHandle
226
+ case rustPanic(_ message: String)
227
+
228
+ public var errorDescription: String? {
229
+ switch self {
230
+ case .bufferOverflow: return "Reading the requested value would read past the end of the buffer"
231
+ case .incompleteData: return "The buffer still has data after lifting its containing value"
232
+ case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1"
233
+ case .unexpectedEnumCase: return "Raw enum value doesn't match any cases"
234
+ case .unexpectedNullPointer: return "Raw pointer value was null"
235
+ case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code"
236
+ case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified"
237
+ case .unexpectedStaleHandle: return "The object in the handle map has been dropped already"
238
+ case let .rustPanic(message): return message
239
+ }
240
+ }
241
+ }
242
+
243
+ fileprivate extension NSLock {
244
+ func withLock<T>(f: () throws -> T) rethrows -> T {
245
+ self.lock()
246
+ defer { self.unlock() }
247
+ return try f()
248
+ }
249
+ }
250
+
251
+ fileprivate let CALL_SUCCESS: Int8 = 0
252
+ fileprivate let CALL_ERROR: Int8 = 1
253
+ fileprivate let CALL_UNEXPECTED_ERROR: Int8 = 2
254
+ fileprivate let CALL_CANCELLED: Int8 = 3
255
+
256
+ fileprivate extension RustCallStatus {
257
+ init() {
258
+ self.init(
259
+ code: CALL_SUCCESS,
260
+ errorBuf: RustBuffer.init(
261
+ capacity: 0,
262
+ len: 0,
263
+ data: nil
264
+ )
265
+ )
266
+ }
267
+ }
268
+
269
+ private func rustCall<T>(_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
270
+ let neverThrow: ((RustBuffer) throws -> Never)? = nil
271
+ return try makeRustCall(callback, errorHandler: neverThrow)
272
+ }
273
+
274
+ private func rustCallWithError<T, E: Swift.Error>(
275
+ _ errorHandler: @escaping (RustBuffer) throws -> E,
276
+ _ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
277
+ try makeRustCall(callback, errorHandler: errorHandler)
278
+ }
279
+
280
+ private func makeRustCall<T, E: Swift.Error>(
281
+ _ callback: (UnsafeMutablePointer<RustCallStatus>) -> T,
282
+ errorHandler: ((RustBuffer) throws -> E)?
283
+ ) throws -> T {
284
+ uniffiEnsureBuboWalletFfiInitialized()
285
+ var callStatus = RustCallStatus.init()
286
+ let returnedVal = callback(&callStatus)
287
+ try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler)
288
+ return returnedVal
289
+ }
290
+
291
+ private func uniffiCheckCallStatus<E: Swift.Error>(
292
+ callStatus: RustCallStatus,
293
+ errorHandler: ((RustBuffer) throws -> E)?
294
+ ) throws {
295
+ switch callStatus.code {
296
+ case CALL_SUCCESS:
297
+ return
298
+
299
+ case CALL_ERROR:
300
+ if let errorHandler = errorHandler {
301
+ throw try errorHandler(callStatus.errorBuf)
302
+ } else {
303
+ callStatus.errorBuf.deallocate()
304
+ throw UniffiInternalError.unexpectedRustCallError
305
+ }
306
+
307
+ case CALL_UNEXPECTED_ERROR:
308
+ // When the rust code sees a panic, it tries to construct a RustBuffer
309
+ // with the message. But if that code panics, then it just sends back
310
+ // an empty buffer.
311
+ if callStatus.errorBuf.len > 0 {
312
+ throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf))
313
+ } else {
314
+ callStatus.errorBuf.deallocate()
315
+ throw UniffiInternalError.rustPanic("Rust panic")
316
+ }
317
+
318
+ case CALL_CANCELLED:
319
+ fatalError("Cancellation not supported yet")
320
+
321
+ default:
322
+ throw UniffiInternalError.unexpectedRustCallStatusCode
323
+ }
324
+ }
325
+
326
+ private func uniffiTraitInterfaceCall<T>(
327
+ callStatus: UnsafeMutablePointer<RustCallStatus>,
328
+ makeCall: () throws -> T,
329
+ writeReturn: (T) -> ()
330
+ ) {
331
+ do {
332
+ try writeReturn(makeCall())
333
+ } catch let error {
334
+ callStatus.pointee.code = CALL_UNEXPECTED_ERROR
335
+ callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
336
+ }
337
+ }
338
+
339
+ private func uniffiTraitInterfaceCallWithError<T, E>(
340
+ callStatus: UnsafeMutablePointer<RustCallStatus>,
341
+ makeCall: () throws -> T,
342
+ writeReturn: (T) -> (),
343
+ lowerError: (E) -> RustBuffer
344
+ ) {
345
+ do {
346
+ try writeReturn(makeCall())
347
+ } catch let error as E {
348
+ callStatus.pointee.code = CALL_ERROR
349
+ callStatus.pointee.errorBuf = lowerError(error)
350
+ } catch {
351
+ callStatus.pointee.code = CALL_UNEXPECTED_ERROR
352
+ callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
353
+ }
354
+ }
355
+ fileprivate final class UniffiHandleMap<T>: @unchecked Sendable {
356
+ // All mutation happens with this lock held, which is why we implement @unchecked Sendable.
357
+ private let lock = NSLock()
358
+ private var map: [UInt64: T] = [:]
359
+ private var currentHandle: UInt64 = 1
360
+
361
+ func insert(obj: T) -> UInt64 {
362
+ lock.withLock {
363
+ let handle = currentHandle
364
+ currentHandle += 1
365
+ map[handle] = obj
366
+ return handle
367
+ }
368
+ }
369
+
370
+ func get(handle: UInt64) throws -> T {
371
+ try lock.withLock {
372
+ guard let obj = map[handle] else {
373
+ throw UniffiInternalError.unexpectedStaleHandle
374
+ }
375
+ return obj
376
+ }
377
+ }
378
+
379
+ @discardableResult
380
+ func remove(handle: UInt64) throws -> T {
381
+ try lock.withLock {
382
+ guard let obj = map.removeValue(forKey: handle) else {
383
+ throw UniffiInternalError.unexpectedStaleHandle
384
+ }
385
+ return obj
386
+ }
387
+ }
388
+
389
+ var count: Int {
390
+ get {
391
+ map.count
392
+ }
393
+ }
394
+ }
395
+
396
+
397
+ // Public interface members begin here.
398
+
399
+
400
+ #if swift(>=5.8)
401
+ @_documentation(visibility: private)
402
+ #endif
403
+ fileprivate struct FfiConverterUInt32: FfiConverterPrimitive {
404
+ typealias FfiType = UInt32
405
+ typealias SwiftType = UInt32
406
+
407
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt32 {
408
+ return try lift(readInt(&buf))
409
+ }
410
+
411
+ public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
412
+ writeInt(&buf, lower(value))
413
+ }
414
+ }
415
+
416
+ #if swift(>=5.8)
417
+ @_documentation(visibility: private)
418
+ #endif
419
+ fileprivate struct FfiConverterString: FfiConverter {
420
+ typealias SwiftType = String
421
+ typealias FfiType = RustBuffer
422
+
423
+ public static func lift(_ value: RustBuffer) throws -> String {
424
+ defer {
425
+ value.deallocate()
426
+ }
427
+ if value.data == nil {
428
+ return String()
429
+ }
430
+ let bytes = UnsafeBufferPointer<UInt8>(start: value.data!, count: Int(value.len))
431
+ return String(bytes: bytes, encoding: String.Encoding.utf8)!
432
+ }
433
+
434
+ public static func lower(_ value: String) -> RustBuffer {
435
+ return value.utf8CString.withUnsafeBufferPointer { ptr in
436
+ // The swift string gives us int8_t, we want uint8_t.
437
+ ptr.withMemoryRebound(to: UInt8.self) { ptr in
438
+ // The swift string gives us a trailing null byte, we don't want it.
439
+ let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1))
440
+ return RustBuffer.from(buf)
441
+ }
442
+ }
443
+ }
444
+
445
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String {
446
+ let len: Int32 = try readInt(&buf)
447
+ return String(bytes: try readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)!
448
+ }
449
+
450
+ public static func write(_ value: String, into buf: inout [UInt8]) {
451
+ let len = Int32(value.utf8.count)
452
+ writeInt(&buf, len)
453
+ writeBytes(&buf, value.utf8)
454
+ }
455
+ }
456
+
457
+ #if swift(>=5.8)
458
+ @_documentation(visibility: private)
459
+ #endif
460
+ fileprivate struct FfiConverterData: FfiConverterRustBuffer {
461
+ typealias SwiftType = Data
462
+
463
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Data {
464
+ let len: Int32 = try readInt(&buf)
465
+ return Data(try readBytes(&buf, count: Int(len)))
466
+ }
467
+
468
+ public static func write(_ value: Data, into buf: inout [UInt8]) {
469
+ let len = Int32(value.count)
470
+ writeInt(&buf, len)
471
+ writeBytes(&buf, value)
472
+ }
473
+ }
474
+
475
+
476
+
477
+
478
+ public protocol WalletLibProtocol: AnyObject, Sendable {
479
+
480
+ func buildAndSign(chainId: String, mnemonic: String, txPayload: Data) throws -> Data
481
+
482
+ func deriveAddress(chainId: String, mnemonic: String, account: UInt32, index: UInt32, passphrase: String?) throws -> String
483
+
484
+ func `init`() throws
485
+
486
+ func listSupportedChains() throws -> [SupportedChainInfo]
487
+
488
+ }
489
+ open class WalletLib: WalletLibProtocol, @unchecked Sendable {
490
+ fileprivate let pointer: UnsafeMutableRawPointer!
491
+
492
+ /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly.
493
+ #if swift(>=5.8)
494
+ @_documentation(visibility: private)
495
+ #endif
496
+ public struct NoPointer {
497
+ public init() {}
498
+ }
499
+
500
+ // TODO: We'd like this to be `private` but for Swifty reasons,
501
+ // we can't implement `FfiConverter` without making this `required` and we can't
502
+ // make it `required` without making it `public`.
503
+ #if swift(>=5.8)
504
+ @_documentation(visibility: private)
505
+ #endif
506
+ required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
507
+ self.pointer = pointer
508
+ }
509
+
510
+ // This constructor can be used to instantiate a fake object.
511
+ // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
512
+ //
513
+ // - Warning:
514
+ // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash.
515
+ #if swift(>=5.8)
516
+ @_documentation(visibility: private)
517
+ #endif
518
+ public init(noPointer: NoPointer) {
519
+ self.pointer = nil
520
+ }
521
+
522
+ #if swift(>=5.8)
523
+ @_documentation(visibility: private)
524
+ #endif
525
+ public func uniffiClonePointer() -> UnsafeMutableRawPointer {
526
+ return try! rustCall { uniffi_bubo_wallet_ffi_fn_clone_walletlib(self.pointer, $0) }
527
+ }
528
+ public convenience init() {
529
+ let pointer =
530
+ try! rustCall() {
531
+ uniffi_bubo_wallet_ffi_fn_constructor_walletlib_new($0
532
+ )
533
+ }
534
+ self.init(unsafeFromRawPointer: pointer)
535
+ }
536
+
537
+ deinit {
538
+ guard let pointer = pointer else {
539
+ return
540
+ }
541
+
542
+ try! rustCall { uniffi_bubo_wallet_ffi_fn_free_walletlib(pointer, $0) }
543
+ }
544
+
545
+
546
+
547
+
548
+ open func buildAndSign(chainId: String, mnemonic: String, txPayload: Data)throws -> Data {
549
+ return try FfiConverterData.lift(try rustCallWithError(FfiConverterTypeFfiError_lift) {
550
+ uniffi_bubo_wallet_ffi_fn_method_walletlib_build_and_sign(self.uniffiClonePointer(),
551
+ FfiConverterString.lower(chainId),
552
+ FfiConverterString.lower(mnemonic),
553
+ FfiConverterData.lower(txPayload),$0
554
+ )
555
+ })
556
+ }
557
+
558
+ open func deriveAddress(chainId: String, mnemonic: String, account: UInt32, index: UInt32, passphrase: String?)throws -> String {
559
+ return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeFfiError_lift) {
560
+ uniffi_bubo_wallet_ffi_fn_method_walletlib_derive_address(self.uniffiClonePointer(),
561
+ FfiConverterString.lower(chainId),
562
+ FfiConverterString.lower(mnemonic),
563
+ FfiConverterUInt32.lower(account),
564
+ FfiConverterUInt32.lower(index),
565
+ FfiConverterOptionString.lower(passphrase),$0
566
+ )
567
+ })
568
+ }
569
+
570
+ open func `init`()throws {try rustCallWithError(FfiConverterTypeFfiError_lift) {
571
+ uniffi_bubo_wallet_ffi_fn_method_walletlib_init(self.uniffiClonePointer(),$0
572
+ )
573
+ }
574
+ }
575
+
576
+ open func listSupportedChains()throws -> [SupportedChainInfo] {
577
+ return try FfiConverterSequenceTypeSupportedChainInfo.lift(try rustCallWithError(FfiConverterTypeFfiError_lift) {
578
+ uniffi_bubo_wallet_ffi_fn_method_walletlib_list_supported_chains(self.uniffiClonePointer(),$0
579
+ )
580
+ })
581
+ }
582
+
583
+
584
+ }
585
+
586
+
587
+ #if swift(>=5.8)
588
+ @_documentation(visibility: private)
589
+ #endif
590
+ public struct FfiConverterTypeWalletLib: FfiConverter {
591
+
592
+ typealias FfiType = UnsafeMutableRawPointer
593
+ typealias SwiftType = WalletLib
594
+
595
+ public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> WalletLib {
596
+ return WalletLib(unsafeFromRawPointer: pointer)
597
+ }
598
+
599
+ public static func lower(_ value: WalletLib) -> UnsafeMutableRawPointer {
600
+ return value.uniffiClonePointer()
601
+ }
602
+
603
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> WalletLib {
604
+ let v: UInt64 = try readInt(&buf)
605
+ // The Rust code won't compile if a pointer won't fit in a UInt64.
606
+ // We have to go via `UInt` because that's the thing that's the size of a pointer.
607
+ let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v))
608
+ if (ptr == nil) {
609
+ throw UniffiInternalError.unexpectedNullPointer
610
+ }
611
+ return try lift(ptr!)
612
+ }
613
+
614
+ public static func write(_ value: WalletLib, into buf: inout [UInt8]) {
615
+ // This fiddling is because `Int` is the thing that's the same size as a pointer.
616
+ // The Rust code won't compile if a pointer won't fit in a `UInt64`.
617
+ writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
618
+ }
619
+ }
620
+
621
+
622
+ #if swift(>=5.8)
623
+ @_documentation(visibility: private)
624
+ #endif
625
+ public func FfiConverterTypeWalletLib_lift(_ pointer: UnsafeMutableRawPointer) throws -> WalletLib {
626
+ return try FfiConverterTypeWalletLib.lift(pointer)
627
+ }
628
+
629
+ #if swift(>=5.8)
630
+ @_documentation(visibility: private)
631
+ #endif
632
+ public func FfiConverterTypeWalletLib_lower(_ value: WalletLib) -> UnsafeMutableRawPointer {
633
+ return FfiConverterTypeWalletLib.lower(value)
634
+ }
635
+
636
+
637
+
638
+
639
+ public struct SupportedChainInfo {
640
+ public var chainId: String
641
+ public var capabilities: [String]
642
+
643
+ // Default memberwise initializers are never public by default, so we
644
+ // declare one manually.
645
+ public init(chainId: String, capabilities: [String]) {
646
+ self.chainId = chainId
647
+ self.capabilities = capabilities
648
+ }
649
+ }
650
+
651
+ #if compiler(>=6)
652
+ extension SupportedChainInfo: Sendable {}
653
+ #endif
654
+
655
+
656
+ extension SupportedChainInfo: Equatable, Hashable {
657
+ public static func ==(lhs: SupportedChainInfo, rhs: SupportedChainInfo) -> Bool {
658
+ if lhs.chainId != rhs.chainId {
659
+ return false
660
+ }
661
+ if lhs.capabilities != rhs.capabilities {
662
+ return false
663
+ }
664
+ return true
665
+ }
666
+
667
+ public func hash(into hasher: inout Hasher) {
668
+ hasher.combine(chainId)
669
+ hasher.combine(capabilities)
670
+ }
671
+ }
672
+
673
+
674
+
675
+ #if swift(>=5.8)
676
+ @_documentation(visibility: private)
677
+ #endif
678
+ public struct FfiConverterTypeSupportedChainInfo: FfiConverterRustBuffer {
679
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SupportedChainInfo {
680
+ return
681
+ try SupportedChainInfo(
682
+ chainId: FfiConverterString.read(from: &buf),
683
+ capabilities: FfiConverterSequenceString.read(from: &buf)
684
+ )
685
+ }
686
+
687
+ public static func write(_ value: SupportedChainInfo, into buf: inout [UInt8]) {
688
+ FfiConverterString.write(value.chainId, into: &buf)
689
+ FfiConverterSequenceString.write(value.capabilities, into: &buf)
690
+ }
691
+ }
692
+
693
+
694
+ #if swift(>=5.8)
695
+ @_documentation(visibility: private)
696
+ #endif
697
+ public func FfiConverterTypeSupportedChainInfo_lift(_ buf: RustBuffer) throws -> SupportedChainInfo {
698
+ return try FfiConverterTypeSupportedChainInfo.lift(buf)
699
+ }
700
+
701
+ #if swift(>=5.8)
702
+ @_documentation(visibility: private)
703
+ #endif
704
+ public func FfiConverterTypeSupportedChainInfo_lower(_ value: SupportedChainInfo) -> RustBuffer {
705
+ return FfiConverterTypeSupportedChainInfo.lower(value)
706
+ }
707
+
708
+
709
+ public enum FfiError: Swift.Error {
710
+
711
+
712
+
713
+ case Failure(reason: String
714
+ )
715
+ }
716
+
717
+
718
+ #if swift(>=5.8)
719
+ @_documentation(visibility: private)
720
+ #endif
721
+ public struct FfiConverterTypeFfiError: FfiConverterRustBuffer {
722
+ typealias SwiftType = FfiError
723
+
724
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> FfiError {
725
+ let variant: Int32 = try readInt(&buf)
726
+ switch variant {
727
+
728
+
729
+
730
+
731
+ case 1: return .Failure(
732
+ reason: try FfiConverterString.read(from: &buf)
733
+ )
734
+
735
+ default: throw UniffiInternalError.unexpectedEnumCase
736
+ }
737
+ }
738
+
739
+ public static func write(_ value: FfiError, into buf: inout [UInt8]) {
740
+ switch value {
741
+
742
+
743
+
744
+
745
+
746
+ case let .Failure(reason):
747
+ writeInt(&buf, Int32(1))
748
+ FfiConverterString.write(reason, into: &buf)
749
+
750
+ }
751
+ }
752
+ }
753
+
754
+
755
+ #if swift(>=5.8)
756
+ @_documentation(visibility: private)
757
+ #endif
758
+ public func FfiConverterTypeFfiError_lift(_ buf: RustBuffer) throws -> FfiError {
759
+ return try FfiConverterTypeFfiError.lift(buf)
760
+ }
761
+
762
+ #if swift(>=5.8)
763
+ @_documentation(visibility: private)
764
+ #endif
765
+ public func FfiConverterTypeFfiError_lower(_ value: FfiError) -> RustBuffer {
766
+ return FfiConverterTypeFfiError.lower(value)
767
+ }
768
+
769
+
770
+ extension FfiError: Equatable, Hashable {}
771
+
772
+
773
+
774
+
775
+ extension FfiError: Foundation.LocalizedError {
776
+ public var errorDescription: String? {
777
+ String(reflecting: self)
778
+ }
779
+ }
780
+
781
+
782
+
783
+
784
+ #if swift(>=5.8)
785
+ @_documentation(visibility: private)
786
+ #endif
787
+ fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer {
788
+ typealias SwiftType = String?
789
+
790
+ public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
791
+ guard let value = value else {
792
+ writeInt(&buf, Int8(0))
793
+ return
794
+ }
795
+ writeInt(&buf, Int8(1))
796
+ FfiConverterString.write(value, into: &buf)
797
+ }
798
+
799
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
800
+ switch try readInt(&buf) as Int8 {
801
+ case 0: return nil
802
+ case 1: return try FfiConverterString.read(from: &buf)
803
+ default: throw UniffiInternalError.unexpectedOptionalTag
804
+ }
805
+ }
806
+ }
807
+
808
+ #if swift(>=5.8)
809
+ @_documentation(visibility: private)
810
+ #endif
811
+ fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer {
812
+ typealias SwiftType = [String]
813
+
814
+ public static func write(_ value: [String], into buf: inout [UInt8]) {
815
+ let len = Int32(value.count)
816
+ writeInt(&buf, len)
817
+ for item in value {
818
+ FfiConverterString.write(item, into: &buf)
819
+ }
820
+ }
821
+
822
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String] {
823
+ let len: Int32 = try readInt(&buf)
824
+ var seq = [String]()
825
+ seq.reserveCapacity(Int(len))
826
+ for _ in 0 ..< len {
827
+ seq.append(try FfiConverterString.read(from: &buf))
828
+ }
829
+ return seq
830
+ }
831
+ }
832
+
833
+ #if swift(>=5.8)
834
+ @_documentation(visibility: private)
835
+ #endif
836
+ fileprivate struct FfiConverterSequenceTypeSupportedChainInfo: FfiConverterRustBuffer {
837
+ typealias SwiftType = [SupportedChainInfo]
838
+
839
+ public static func write(_ value: [SupportedChainInfo], into buf: inout [UInt8]) {
840
+ let len = Int32(value.count)
841
+ writeInt(&buf, len)
842
+ for item in value {
843
+ FfiConverterTypeSupportedChainInfo.write(item, into: &buf)
844
+ }
845
+ }
846
+
847
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [SupportedChainInfo] {
848
+ let len: Int32 = try readInt(&buf)
849
+ var seq = [SupportedChainInfo]()
850
+ seq.reserveCapacity(Int(len))
851
+ for _ in 0 ..< len {
852
+ seq.append(try FfiConverterTypeSupportedChainInfo.read(from: &buf))
853
+ }
854
+ return seq
855
+ }
856
+ }
857
+
858
+ private enum InitializationResult {
859
+ case ok
860
+ case contractVersionMismatch
861
+ case apiChecksumMismatch
862
+ }
863
+ // Use a global variable to perform the versioning checks. Swift ensures that
864
+ // the code inside is only computed once.
865
+ private let initializationResult: InitializationResult = {
866
+ // Get the bindings contract version from our ComponentInterface
867
+ let bindings_contract_version = 29
868
+ // Get the scaffolding contract version by calling the into the dylib
869
+ let scaffolding_contract_version = ffi_bubo_wallet_ffi_uniffi_contract_version()
870
+ if bindings_contract_version != scaffolding_contract_version {
871
+ return InitializationResult.contractVersionMismatch
872
+ }
873
+ if (uniffi_bubo_wallet_ffi_checksum_method_walletlib_build_and_sign() != 27726) {
874
+ return InitializationResult.apiChecksumMismatch
875
+ }
876
+ if (uniffi_bubo_wallet_ffi_checksum_method_walletlib_derive_address() != 5086) {
877
+ return InitializationResult.apiChecksumMismatch
878
+ }
879
+ if (uniffi_bubo_wallet_ffi_checksum_method_walletlib_init() != 27966) {
880
+ return InitializationResult.apiChecksumMismatch
881
+ }
882
+ if (uniffi_bubo_wallet_ffi_checksum_method_walletlib_list_supported_chains() != 37171) {
883
+ return InitializationResult.apiChecksumMismatch
884
+ }
885
+ if (uniffi_bubo_wallet_ffi_checksum_constructor_walletlib_new() != 51053) {
886
+ return InitializationResult.apiChecksumMismatch
887
+ }
888
+
889
+ return InitializationResult.ok
890
+ }()
891
+
892
+ // Make the ensure init function public so that other modules which have external type references to
893
+ // our types can call it.
894
+ public func uniffiEnsureBuboWalletFfiInitialized() {
895
+ switch initializationResult {
896
+ case .ok:
897
+ break
898
+ case .contractVersionMismatch:
899
+ fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
900
+ case .apiChecksumMismatch:
901
+ fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
902
+ }
903
+ }
904
+
905
+ // swiftlint:enable all