radroots_sdk.swift (70430B)
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(radroots_sdkFFI) 11 import radroots_sdkFFI 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_radroots_sdk_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_radroots_sdk_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 uniffiEnsureRadrootsSdkFfiInitialized() 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 FfiConverterUInt16: FfiConverterPrimitive { 404 typealias FfiType = UInt16 405 typealias SwiftType = UInt16 406 407 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt16 { 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 FfiConverterUInt32: FfiConverterPrimitive { 420 typealias FfiType = UInt32 421 typealias SwiftType = UInt32 422 423 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt32 { 424 return try lift(readInt(&buf)) 425 } 426 427 public static func write(_ value: SwiftType, into buf: inout [UInt8]) { 428 writeInt(&buf, lower(value)) 429 } 430 } 431 432 #if swift(>=5.8) 433 @_documentation(visibility: private) 434 #endif 435 fileprivate struct FfiConverterUInt64: FfiConverterPrimitive { 436 typealias FfiType = UInt64 437 typealias SwiftType = UInt64 438 439 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt64 { 440 return try lift(readInt(&buf)) 441 } 442 443 public static func write(_ value: SwiftType, into buf: inout [UInt8]) { 444 writeInt(&buf, lower(value)) 445 } 446 } 447 448 #if swift(>=5.8) 449 @_documentation(visibility: private) 450 #endif 451 fileprivate struct FfiConverterBool : FfiConverter { 452 typealias FfiType = Int8 453 typealias SwiftType = Bool 454 455 public static func lift(_ value: Int8) throws -> Bool { 456 return value != 0 457 } 458 459 public static func lower(_ value: Bool) -> Int8 { 460 return value ? 1 : 0 461 } 462 463 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool { 464 return try lift(readInt(&buf)) 465 } 466 467 public static func write(_ value: Bool, into buf: inout [UInt8]) { 468 writeInt(&buf, lower(value)) 469 } 470 } 471 472 #if swift(>=5.8) 473 @_documentation(visibility: private) 474 #endif 475 fileprivate struct FfiConverterString: FfiConverter { 476 typealias SwiftType = String 477 typealias FfiType = RustBuffer 478 479 public static func lift(_ value: RustBuffer) throws -> String { 480 defer { 481 value.deallocate() 482 } 483 if value.data == nil { 484 return String() 485 } 486 let bytes = UnsafeBufferPointer<UInt8>(start: value.data!, count: Int(value.len)) 487 return String(bytes: bytes, encoding: String.Encoding.utf8)! 488 } 489 490 public static func lower(_ value: String) -> RustBuffer { 491 return value.utf8CString.withUnsafeBufferPointer { ptr in 492 // The swift string gives us int8_t, we want uint8_t. 493 ptr.withMemoryRebound(to: UInt8.self) { ptr in 494 // The swift string gives us a trailing null byte, we don't want it. 495 let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1)) 496 return RustBuffer.from(buf) 497 } 498 } 499 } 500 501 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String { 502 let len: Int32 = try readInt(&buf) 503 return String(bytes: try readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)! 504 } 505 506 public static func write(_ value: String, into buf: inout [UInt8]) { 507 let len = Int32(value.utf8.count) 508 writeInt(&buf, len) 509 writeBytes(&buf, value.utf8) 510 } 511 } 512 513 #if swift(>=5.8) 514 @_documentation(visibility: private) 515 #endif 516 fileprivate struct FfiConverterData: FfiConverterRustBuffer { 517 typealias SwiftType = Data 518 519 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Data { 520 let len: Int32 = try readInt(&buf) 521 return Data(try readBytes(&buf, count: Int(len))) 522 } 523 524 public static func write(_ value: Data, into buf: inout [UInt8]) { 525 let len = Int32(value.count) 526 writeInt(&buf, len) 527 writeBytes(&buf, value) 528 } 529 } 530 531 532 533 534 /** 535 * Thread-safe mobile handle delegating lifecycle to [`radroots_sdk::Client`]. 536 */ 537 public protocol MobileClientProtocol: AnyObject, Sendable { 538 539 /** 540 * Returns stable capability DTOs without probing host resources. 541 */ 542 func capabilities() -> [CapabilityStatus] 543 544 /** 545 * Explicitly closes SDK-owned resources without installing a runtime. 546 */ 547 func close() async throws 548 549 /** 550 * Returns whether explicit SDK close completed across all clones. 551 */ 552 func isClosed() -> Bool 553 554 } 555 /** 556 * Thread-safe mobile handle delegating lifecycle to [`radroots_sdk::Client`]. 557 */ 558 open class MobileClient: MobileClientProtocol, @unchecked Sendable { 559 fileprivate let pointer: UnsafeMutableRawPointer! 560 561 /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. 562 #if swift(>=5.8) 563 @_documentation(visibility: private) 564 #endif 565 public struct NoPointer { 566 public init() {} 567 } 568 569 // TODO: We'd like this to be `private` but for Swifty reasons, 570 // we can't implement `FfiConverter` without making this `required` and we can't 571 // make it `required` without making it `public`. 572 #if swift(>=5.8) 573 @_documentation(visibility: private) 574 #endif 575 required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { 576 self.pointer = pointer 577 } 578 579 // This constructor can be used to instantiate a fake object. 580 // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. 581 // 582 // - Warning: 583 // 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. 584 #if swift(>=5.8) 585 @_documentation(visibility: private) 586 #endif 587 public init(noPointer: NoPointer) { 588 self.pointer = nil 589 } 590 591 #if swift(>=5.8) 592 @_documentation(visibility: private) 593 #endif 594 public func uniffiClonePointer() -> UnsafeMutableRawPointer { 595 return try! rustCall { uniffi_radroots_sdk_ffi_fn_clone_mobileclient(self.pointer, $0) } 596 } 597 // No primary constructor declared for this class. 598 599 deinit { 600 guard let pointer = pointer else { 601 return 602 } 603 604 try! rustCall { uniffi_radroots_sdk_ffi_fn_free_mobileclient(pointer, $0) } 605 } 606 607 608 /** 609 * Creates a deterministic, local-only memory client without I/O. 610 */ 611 public static func memory()throws -> MobileClient { 612 return try FfiConverterTypeMobileClient_lift(try rustCallWithError(FfiConverterTypeError_lift) { 613 uniffi_radroots_sdk_ffi_fn_constructor_mobileclient_memory($0 614 ) 615 }) 616 } 617 618 619 620 /** 621 * Returns stable capability DTOs without probing host resources. 622 */ 623 open func capabilities() -> [CapabilityStatus] { 624 return try! FfiConverterSequenceTypeCapabilityStatus.lift(try! rustCall() { 625 uniffi_radroots_sdk_ffi_fn_method_mobileclient_capabilities(self.uniffiClonePointer(),$0 626 ) 627 }) 628 } 629 630 /** 631 * Explicitly closes SDK-owned resources without installing a runtime. 632 */ 633 open func close()async throws { 634 return 635 try await uniffiRustCallAsync( 636 rustFutureFunc: { 637 uniffi_radroots_sdk_ffi_fn_method_mobileclient_close( 638 self.uniffiClonePointer() 639 640 ) 641 }, 642 pollFunc: ffi_radroots_sdk_ffi_rust_future_poll_void, 643 completeFunc: ffi_radroots_sdk_ffi_rust_future_complete_void, 644 freeFunc: ffi_radroots_sdk_ffi_rust_future_free_void, 645 liftFunc: { $0 }, 646 errorHandler: FfiConverterTypeError_lift 647 ) 648 } 649 650 /** 651 * Returns whether explicit SDK close completed across all clones. 652 */ 653 open func isClosed() -> Bool { 654 return try! FfiConverterBool.lift(try! rustCall() { 655 uniffi_radroots_sdk_ffi_fn_method_mobileclient_is_closed(self.uniffiClonePointer(),$0 656 ) 657 }) 658 } 659 660 661 } 662 663 664 #if swift(>=5.8) 665 @_documentation(visibility: private) 666 #endif 667 public struct FfiConverterTypeMobileClient: FfiConverter { 668 669 typealias FfiType = UnsafeMutableRawPointer 670 typealias SwiftType = MobileClient 671 672 public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> MobileClient { 673 return MobileClient(unsafeFromRawPointer: pointer) 674 } 675 676 public static func lower(_ value: MobileClient) -> UnsafeMutableRawPointer { 677 return value.uniffiClonePointer() 678 } 679 680 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MobileClient { 681 let v: UInt64 = try readInt(&buf) 682 // The Rust code won't compile if a pointer won't fit in a UInt64. 683 // We have to go via `UInt` because that's the thing that's the size of a pointer. 684 let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) 685 if (ptr == nil) { 686 throw UniffiInternalError.unexpectedNullPointer 687 } 688 return try lift(ptr!) 689 } 690 691 public static func write(_ value: MobileClient, into buf: inout [UInt8]) { 692 // This fiddling is because `Int` is the thing that's the same size as a pointer. 693 // The Rust code won't compile if a pointer won't fit in a `UInt64`. 694 writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) 695 } 696 } 697 698 699 #if swift(>=5.8) 700 @_documentation(visibility: private) 701 #endif 702 public func FfiConverterTypeMobileClient_lift(_ pointer: UnsafeMutableRawPointer) throws -> MobileClient { 703 return try FfiConverterTypeMobileClient.lift(pointer) 704 } 705 706 #if swift(>=5.8) 707 @_documentation(visibility: private) 708 #endif 709 public func FfiConverterTypeMobileClient_lower(_ value: MobileClient) -> UnsafeMutableRawPointer { 710 return FfiConverterTypeMobileClient.lower(value) 711 } 712 713 714 715 716 /** 717 * Versioned, presentation-independent capability observation. 718 */ 719 public struct CapabilityStatus { 720 public var id: String 721 public var compiled: Bool 722 public var configured: Bool 723 public var availability: CapabilityAvailability 724 public var maturity: CapabilityMaturity 725 726 // Default memberwise initializers are never public by default, so we 727 // declare one manually. 728 public init(id: String, compiled: Bool, configured: Bool, availability: CapabilityAvailability, maturity: CapabilityMaturity) { 729 self.id = id 730 self.compiled = compiled 731 self.configured = configured 732 self.availability = availability 733 self.maturity = maturity 734 } 735 } 736 737 #if compiler(>=6) 738 extension CapabilityStatus: Sendable {} 739 #endif 740 741 742 extension CapabilityStatus: Equatable, Hashable { 743 public static func ==(lhs: CapabilityStatus, rhs: CapabilityStatus) -> Bool { 744 if lhs.id != rhs.id { 745 return false 746 } 747 if lhs.compiled != rhs.compiled { 748 return false 749 } 750 if lhs.configured != rhs.configured { 751 return false 752 } 753 if lhs.availability != rhs.availability { 754 return false 755 } 756 if lhs.maturity != rhs.maturity { 757 return false 758 } 759 return true 760 } 761 762 public func hash(into hasher: inout Hasher) { 763 hasher.combine(id) 764 hasher.combine(compiled) 765 hasher.combine(configured) 766 hasher.combine(availability) 767 hasher.combine(maturity) 768 } 769 } 770 771 772 773 #if swift(>=5.8) 774 @_documentation(visibility: private) 775 #endif 776 public struct FfiConverterTypeCapabilityStatus: FfiConverterRustBuffer { 777 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> CapabilityStatus { 778 return 779 try CapabilityStatus( 780 id: FfiConverterString.read(from: &buf), 781 compiled: FfiConverterBool.read(from: &buf), 782 configured: FfiConverterBool.read(from: &buf), 783 availability: FfiConverterTypeCapabilityAvailability.read(from: &buf), 784 maturity: FfiConverterTypeCapabilityMaturity.read(from: &buf) 785 ) 786 } 787 788 public static func write(_ value: CapabilityStatus, into buf: inout [UInt8]) { 789 FfiConverterString.write(value.id, into: &buf) 790 FfiConverterBool.write(value.compiled, into: &buf) 791 FfiConverterBool.write(value.configured, into: &buf) 792 FfiConverterTypeCapabilityAvailability.write(value.availability, into: &buf) 793 FfiConverterTypeCapabilityMaturity.write(value.maturity, into: &buf) 794 } 795 } 796 797 798 #if swift(>=5.8) 799 @_documentation(visibility: private) 800 #endif 801 public func FfiConverterTypeCapabilityStatus_lift(_ buf: RustBuffer) throws -> CapabilityStatus { 802 return try FfiConverterTypeCapabilityStatus.lift(buf) 803 } 804 805 #if swift(>=5.8) 806 @_documentation(visibility: private) 807 #endif 808 public func FfiConverterTypeCapabilityStatus_lower(_ value: CapabilityStatus) -> RustBuffer { 809 return FfiConverterTypeCapabilityStatus.lower(value) 810 } 811 812 813 /** 814 * Verified final RHI attestation projection. 815 */ 816 public struct RhiEvidenceAttestation { 817 public var issuerPubkey: String 818 public var tradeId: String 819 public var claimMutationId: String 820 public var outcome: TradeEvidenceOutcome 821 public var observedAtUnixS: String 822 public var tradeGeneration: String 823 public var statementDigest: String 824 public var supersession: RhiEvidenceSupersession? 825 public var canonicalContent: String 826 827 // Default memberwise initializers are never public by default, so we 828 // declare one manually. 829 public init(issuerPubkey: String, tradeId: String, claimMutationId: String, outcome: TradeEvidenceOutcome, observedAtUnixS: String, tradeGeneration: String, statementDigest: String, supersession: RhiEvidenceSupersession?, canonicalContent: String) { 830 self.issuerPubkey = issuerPubkey 831 self.tradeId = tradeId 832 self.claimMutationId = claimMutationId 833 self.outcome = outcome 834 self.observedAtUnixS = observedAtUnixS 835 self.tradeGeneration = tradeGeneration 836 self.statementDigest = statementDigest 837 self.supersession = supersession 838 self.canonicalContent = canonicalContent 839 } 840 } 841 842 #if compiler(>=6) 843 extension RhiEvidenceAttestation: Sendable {} 844 #endif 845 846 847 extension RhiEvidenceAttestation: Equatable, Hashable { 848 public static func ==(lhs: RhiEvidenceAttestation, rhs: RhiEvidenceAttestation) -> Bool { 849 if lhs.issuerPubkey != rhs.issuerPubkey { 850 return false 851 } 852 if lhs.tradeId != rhs.tradeId { 853 return false 854 } 855 if lhs.claimMutationId != rhs.claimMutationId { 856 return false 857 } 858 if lhs.outcome != rhs.outcome { 859 return false 860 } 861 if lhs.observedAtUnixS != rhs.observedAtUnixS { 862 return false 863 } 864 if lhs.tradeGeneration != rhs.tradeGeneration { 865 return false 866 } 867 if lhs.statementDigest != rhs.statementDigest { 868 return false 869 } 870 if lhs.supersession != rhs.supersession { 871 return false 872 } 873 if lhs.canonicalContent != rhs.canonicalContent { 874 return false 875 } 876 return true 877 } 878 879 public func hash(into hasher: inout Hasher) { 880 hasher.combine(issuerPubkey) 881 hasher.combine(tradeId) 882 hasher.combine(claimMutationId) 883 hasher.combine(outcome) 884 hasher.combine(observedAtUnixS) 885 hasher.combine(tradeGeneration) 886 hasher.combine(statementDigest) 887 hasher.combine(supersession) 888 hasher.combine(canonicalContent) 889 } 890 } 891 892 893 894 #if swift(>=5.8) 895 @_documentation(visibility: private) 896 #endif 897 public struct FfiConverterTypeRhiEvidenceAttestation: FfiConverterRustBuffer { 898 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RhiEvidenceAttestation { 899 return 900 try RhiEvidenceAttestation( 901 issuerPubkey: FfiConverterString.read(from: &buf), 902 tradeId: FfiConverterString.read(from: &buf), 903 claimMutationId: FfiConverterString.read(from: &buf), 904 outcome: FfiConverterTypeTradeEvidenceOutcome.read(from: &buf), 905 observedAtUnixS: FfiConverterString.read(from: &buf), 906 tradeGeneration: FfiConverterString.read(from: &buf), 907 statementDigest: FfiConverterString.read(from: &buf), 908 supersession: FfiConverterOptionTypeRhiEvidenceSupersession.read(from: &buf), 909 canonicalContent: FfiConverterString.read(from: &buf) 910 ) 911 } 912 913 public static func write(_ value: RhiEvidenceAttestation, into buf: inout [UInt8]) { 914 FfiConverterString.write(value.issuerPubkey, into: &buf) 915 FfiConverterString.write(value.tradeId, into: &buf) 916 FfiConverterString.write(value.claimMutationId, into: &buf) 917 FfiConverterTypeTradeEvidenceOutcome.write(value.outcome, into: &buf) 918 FfiConverterString.write(value.observedAtUnixS, into: &buf) 919 FfiConverterString.write(value.tradeGeneration, into: &buf) 920 FfiConverterString.write(value.statementDigest, into: &buf) 921 FfiConverterOptionTypeRhiEvidenceSupersession.write(value.supersession, into: &buf) 922 FfiConverterString.write(value.canonicalContent, into: &buf) 923 } 924 } 925 926 927 #if swift(>=5.8) 928 @_documentation(visibility: private) 929 #endif 930 public func FfiConverterTypeRhiEvidenceAttestation_lift(_ buf: RustBuffer) throws -> RhiEvidenceAttestation { 931 return try FfiConverterTypeRhiEvidenceAttestation.lift(buf) 932 } 933 934 #if swift(>=5.8) 935 @_documentation(visibility: private) 936 #endif 937 public func FfiConverterTypeRhiEvidenceAttestation_lower(_ value: RhiEvidenceAttestation) -> RustBuffer { 938 return FfiConverterTypeRhiEvidenceAttestation.lower(value) 939 } 940 941 942 /** 943 * Bounded projection of one canonical RHI evidence report. 944 */ 945 public struct RhiEvidenceReport { 946 public var contractId: String 947 public var contractVersion: UInt16 948 public var issuerPubkey: String 949 public var tradeId: String 950 public var claimMutationId: String 951 public var outcome: TradeEvidenceOutcome 952 public var reasonCodes: [String] 953 public var projectionDigest: String 954 public var evidenceManifestDigest: String 955 public var evidencePolicyDigest: String 956 public var observedAtUnixS: String 957 public var tradeGeneration: String 958 public var statementDigest: String 959 public var supersession: RhiEvidenceSupersession? 960 public var canonicalContent: String 961 962 // Default memberwise initializers are never public by default, so we 963 // declare one manually. 964 public init(contractId: String, contractVersion: UInt16, issuerPubkey: String, tradeId: String, claimMutationId: String, outcome: TradeEvidenceOutcome, reasonCodes: [String], projectionDigest: String, evidenceManifestDigest: String, evidencePolicyDigest: String, observedAtUnixS: String, tradeGeneration: String, statementDigest: String, supersession: RhiEvidenceSupersession?, canonicalContent: String) { 965 self.contractId = contractId 966 self.contractVersion = contractVersion 967 self.issuerPubkey = issuerPubkey 968 self.tradeId = tradeId 969 self.claimMutationId = claimMutationId 970 self.outcome = outcome 971 self.reasonCodes = reasonCodes 972 self.projectionDigest = projectionDigest 973 self.evidenceManifestDigest = evidenceManifestDigest 974 self.evidencePolicyDigest = evidencePolicyDigest 975 self.observedAtUnixS = observedAtUnixS 976 self.tradeGeneration = tradeGeneration 977 self.statementDigest = statementDigest 978 self.supersession = supersession 979 self.canonicalContent = canonicalContent 980 } 981 } 982 983 #if compiler(>=6) 984 extension RhiEvidenceReport: Sendable {} 985 #endif 986 987 988 extension RhiEvidenceReport: Equatable, Hashable { 989 public static func ==(lhs: RhiEvidenceReport, rhs: RhiEvidenceReport) -> Bool { 990 if lhs.contractId != rhs.contractId { 991 return false 992 } 993 if lhs.contractVersion != rhs.contractVersion { 994 return false 995 } 996 if lhs.issuerPubkey != rhs.issuerPubkey { 997 return false 998 } 999 if lhs.tradeId != rhs.tradeId { 1000 return false 1001 } 1002 if lhs.claimMutationId != rhs.claimMutationId { 1003 return false 1004 } 1005 if lhs.outcome != rhs.outcome { 1006 return false 1007 } 1008 if lhs.reasonCodes != rhs.reasonCodes { 1009 return false 1010 } 1011 if lhs.projectionDigest != rhs.projectionDigest { 1012 return false 1013 } 1014 if lhs.evidenceManifestDigest != rhs.evidenceManifestDigest { 1015 return false 1016 } 1017 if lhs.evidencePolicyDigest != rhs.evidencePolicyDigest { 1018 return false 1019 } 1020 if lhs.observedAtUnixS != rhs.observedAtUnixS { 1021 return false 1022 } 1023 if lhs.tradeGeneration != rhs.tradeGeneration { 1024 return false 1025 } 1026 if lhs.statementDigest != rhs.statementDigest { 1027 return false 1028 } 1029 if lhs.supersession != rhs.supersession { 1030 return false 1031 } 1032 if lhs.canonicalContent != rhs.canonicalContent { 1033 return false 1034 } 1035 return true 1036 } 1037 1038 public func hash(into hasher: inout Hasher) { 1039 hasher.combine(contractId) 1040 hasher.combine(contractVersion) 1041 hasher.combine(issuerPubkey) 1042 hasher.combine(tradeId) 1043 hasher.combine(claimMutationId) 1044 hasher.combine(outcome) 1045 hasher.combine(reasonCodes) 1046 hasher.combine(projectionDigest) 1047 hasher.combine(evidenceManifestDigest) 1048 hasher.combine(evidencePolicyDigest) 1049 hasher.combine(observedAtUnixS) 1050 hasher.combine(tradeGeneration) 1051 hasher.combine(statementDigest) 1052 hasher.combine(supersession) 1053 hasher.combine(canonicalContent) 1054 } 1055 } 1056 1057 1058 1059 #if swift(>=5.8) 1060 @_documentation(visibility: private) 1061 #endif 1062 public struct FfiConverterTypeRhiEvidenceReport: FfiConverterRustBuffer { 1063 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RhiEvidenceReport { 1064 return 1065 try RhiEvidenceReport( 1066 contractId: FfiConverterString.read(from: &buf), 1067 contractVersion: FfiConverterUInt16.read(from: &buf), 1068 issuerPubkey: FfiConverterString.read(from: &buf), 1069 tradeId: FfiConverterString.read(from: &buf), 1070 claimMutationId: FfiConverterString.read(from: &buf), 1071 outcome: FfiConverterTypeTradeEvidenceOutcome.read(from: &buf), 1072 reasonCodes: FfiConverterSequenceString.read(from: &buf), 1073 projectionDigest: FfiConverterString.read(from: &buf), 1074 evidenceManifestDigest: FfiConverterString.read(from: &buf), 1075 evidencePolicyDigest: FfiConverterString.read(from: &buf), 1076 observedAtUnixS: FfiConverterString.read(from: &buf), 1077 tradeGeneration: FfiConverterString.read(from: &buf), 1078 statementDigest: FfiConverterString.read(from: &buf), 1079 supersession: FfiConverterOptionTypeRhiEvidenceSupersession.read(from: &buf), 1080 canonicalContent: FfiConverterString.read(from: &buf) 1081 ) 1082 } 1083 1084 public static func write(_ value: RhiEvidenceReport, into buf: inout [UInt8]) { 1085 FfiConverterString.write(value.contractId, into: &buf) 1086 FfiConverterUInt16.write(value.contractVersion, into: &buf) 1087 FfiConverterString.write(value.issuerPubkey, into: &buf) 1088 FfiConverterString.write(value.tradeId, into: &buf) 1089 FfiConverterString.write(value.claimMutationId, into: &buf) 1090 FfiConverterTypeTradeEvidenceOutcome.write(value.outcome, into: &buf) 1091 FfiConverterSequenceString.write(value.reasonCodes, into: &buf) 1092 FfiConverterString.write(value.projectionDigest, into: &buf) 1093 FfiConverterString.write(value.evidenceManifestDigest, into: &buf) 1094 FfiConverterString.write(value.evidencePolicyDigest, into: &buf) 1095 FfiConverterString.write(value.observedAtUnixS, into: &buf) 1096 FfiConverterString.write(value.tradeGeneration, into: &buf) 1097 FfiConverterString.write(value.statementDigest, into: &buf) 1098 FfiConverterOptionTypeRhiEvidenceSupersession.write(value.supersession, into: &buf) 1099 FfiConverterString.write(value.canonicalContent, into: &buf) 1100 } 1101 } 1102 1103 1104 #if swift(>=5.8) 1105 @_documentation(visibility: private) 1106 #endif 1107 public func FfiConverterTypeRhiEvidenceReport_lift(_ buf: RustBuffer) throws -> RhiEvidenceReport { 1108 return try FfiConverterTypeRhiEvidenceReport.lift(buf) 1109 } 1110 1111 #if swift(>=5.8) 1112 @_documentation(visibility: private) 1113 #endif 1114 public func FfiConverterTypeRhiEvidenceReport_lower(_ value: RhiEvidenceReport) -> RustBuffer { 1115 return FfiConverterTypeRhiEvidenceReport.lower(value) 1116 } 1117 1118 1119 /** 1120 * Exact immutable RHI supersession reference. 1121 */ 1122 public struct RhiEvidenceSupersession { 1123 public var reportId: String 1124 public var eventId: String 1125 1126 // Default memberwise initializers are never public by default, so we 1127 // declare one manually. 1128 public init(reportId: String, eventId: String) { 1129 self.reportId = reportId 1130 self.eventId = eventId 1131 } 1132 } 1133 1134 #if compiler(>=6) 1135 extension RhiEvidenceSupersession: Sendable {} 1136 #endif 1137 1138 1139 extension RhiEvidenceSupersession: Equatable, Hashable { 1140 public static func ==(lhs: RhiEvidenceSupersession, rhs: RhiEvidenceSupersession) -> Bool { 1141 if lhs.reportId != rhs.reportId { 1142 return false 1143 } 1144 if lhs.eventId != rhs.eventId { 1145 return false 1146 } 1147 return true 1148 } 1149 1150 public func hash(into hasher: inout Hasher) { 1151 hasher.combine(reportId) 1152 hasher.combine(eventId) 1153 } 1154 } 1155 1156 1157 1158 #if swift(>=5.8) 1159 @_documentation(visibility: private) 1160 #endif 1161 public struct FfiConverterTypeRhiEvidenceSupersession: FfiConverterRustBuffer { 1162 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RhiEvidenceSupersession { 1163 return 1164 try RhiEvidenceSupersession( 1165 reportId: FfiConverterString.read(from: &buf), 1166 eventId: FfiConverterString.read(from: &buf) 1167 ) 1168 } 1169 1170 public static func write(_ value: RhiEvidenceSupersession, into buf: inout [UInt8]) { 1171 FfiConverterString.write(value.reportId, into: &buf) 1172 FfiConverterString.write(value.eventId, into: &buf) 1173 } 1174 } 1175 1176 1177 #if swift(>=5.8) 1178 @_documentation(visibility: private) 1179 #endif 1180 public func FfiConverterTypeRhiEvidenceSupersession_lift(_ buf: RustBuffer) throws -> RhiEvidenceSupersession { 1181 return try FfiConverterTypeRhiEvidenceSupersession.lift(buf) 1182 } 1183 1184 #if swift(>=5.8) 1185 @_documentation(visibility: private) 1186 #endif 1187 public func FfiConverterTypeRhiEvidenceSupersession_lower(_ value: RhiEvidenceSupersession) -> RustBuffer { 1188 return FfiConverterTypeRhiEvidenceSupersession.lower(value) 1189 } 1190 1191 1192 /** 1193 * Signed NIP-01 event input for verified attestation admission. 1194 */ 1195 public struct SignedEvent { 1196 public var id: String 1197 public var authorPubkey: String 1198 public var createdAtUnixS: UInt64 1199 public var kind: UInt32 1200 public var tags: [[String]] 1201 public var content: String 1202 public var signature: String 1203 1204 // Default memberwise initializers are never public by default, so we 1205 // declare one manually. 1206 public init(id: String, authorPubkey: String, createdAtUnixS: UInt64, kind: UInt32, tags: [[String]], content: String, signature: String) { 1207 self.id = id 1208 self.authorPubkey = authorPubkey 1209 self.createdAtUnixS = createdAtUnixS 1210 self.kind = kind 1211 self.tags = tags 1212 self.content = content 1213 self.signature = signature 1214 } 1215 } 1216 1217 #if compiler(>=6) 1218 extension SignedEvent: Sendable {} 1219 #endif 1220 1221 1222 extension SignedEvent: Equatable, Hashable { 1223 public static func ==(lhs: SignedEvent, rhs: SignedEvent) -> Bool { 1224 if lhs.id != rhs.id { 1225 return false 1226 } 1227 if lhs.authorPubkey != rhs.authorPubkey { 1228 return false 1229 } 1230 if lhs.createdAtUnixS != rhs.createdAtUnixS { 1231 return false 1232 } 1233 if lhs.kind != rhs.kind { 1234 return false 1235 } 1236 if lhs.tags != rhs.tags { 1237 return false 1238 } 1239 if lhs.content != rhs.content { 1240 return false 1241 } 1242 if lhs.signature != rhs.signature { 1243 return false 1244 } 1245 return true 1246 } 1247 1248 public func hash(into hasher: inout Hasher) { 1249 hasher.combine(id) 1250 hasher.combine(authorPubkey) 1251 hasher.combine(createdAtUnixS) 1252 hasher.combine(kind) 1253 hasher.combine(tags) 1254 hasher.combine(content) 1255 hasher.combine(signature) 1256 } 1257 } 1258 1259 1260 1261 #if swift(>=5.8) 1262 @_documentation(visibility: private) 1263 #endif 1264 public struct FfiConverterTypeSignedEvent: FfiConverterRustBuffer { 1265 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SignedEvent { 1266 return 1267 try SignedEvent( 1268 id: FfiConverterString.read(from: &buf), 1269 authorPubkey: FfiConverterString.read(from: &buf), 1270 createdAtUnixS: FfiConverterUInt64.read(from: &buf), 1271 kind: FfiConverterUInt32.read(from: &buf), 1272 tags: FfiConverterSequenceSequenceString.read(from: &buf), 1273 content: FfiConverterString.read(from: &buf), 1274 signature: FfiConverterString.read(from: &buf) 1275 ) 1276 } 1277 1278 public static func write(_ value: SignedEvent, into buf: inout [UInt8]) { 1279 FfiConverterString.write(value.id, into: &buf) 1280 FfiConverterString.write(value.authorPubkey, into: &buf) 1281 FfiConverterUInt64.write(value.createdAtUnixS, into: &buf) 1282 FfiConverterUInt32.write(value.kind, into: &buf) 1283 FfiConverterSequenceSequenceString.write(value.tags, into: &buf) 1284 FfiConverterString.write(value.content, into: &buf) 1285 FfiConverterString.write(value.signature, into: &buf) 1286 } 1287 } 1288 1289 1290 #if swift(>=5.8) 1291 @_documentation(visibility: private) 1292 #endif 1293 public func FfiConverterTypeSignedEvent_lift(_ buf: RustBuffer) throws -> SignedEvent { 1294 return try FfiConverterTypeSignedEvent.lift(buf) 1295 } 1296 1297 #if swift(>=5.8) 1298 @_documentation(visibility: private) 1299 #endif 1300 public func FfiConverterTypeSignedEvent_lower(_ value: SignedEvent) -> RustBuffer { 1301 return FfiConverterTypeSignedEvent.lower(value) 1302 } 1303 1304 1305 /** 1306 * Bounded projection of one canonical evidence manifest. 1307 */ 1308 public struct TradeEvidenceManifest { 1309 public var contractId: String 1310 public var contractVersion: UInt16 1311 public var tradeId: String 1312 public var tradeGeneration: String 1313 public var observedAtUnixS: String 1314 public var coverage: TradeEvidenceCoverage 1315 public var evidencePolicyDigest: String 1316 public var manifestDigest: String 1317 public var canonicalBytesHex: String 1318 1319 // Default memberwise initializers are never public by default, so we 1320 // declare one manually. 1321 public init(contractId: String, contractVersion: UInt16, tradeId: String, tradeGeneration: String, observedAtUnixS: String, coverage: TradeEvidenceCoverage, evidencePolicyDigest: String, manifestDigest: String, canonicalBytesHex: String) { 1322 self.contractId = contractId 1323 self.contractVersion = contractVersion 1324 self.tradeId = tradeId 1325 self.tradeGeneration = tradeGeneration 1326 self.observedAtUnixS = observedAtUnixS 1327 self.coverage = coverage 1328 self.evidencePolicyDigest = evidencePolicyDigest 1329 self.manifestDigest = manifestDigest 1330 self.canonicalBytesHex = canonicalBytesHex 1331 } 1332 } 1333 1334 #if compiler(>=6) 1335 extension TradeEvidenceManifest: Sendable {} 1336 #endif 1337 1338 1339 extension TradeEvidenceManifest: Equatable, Hashable { 1340 public static func ==(lhs: TradeEvidenceManifest, rhs: TradeEvidenceManifest) -> Bool { 1341 if lhs.contractId != rhs.contractId { 1342 return false 1343 } 1344 if lhs.contractVersion != rhs.contractVersion { 1345 return false 1346 } 1347 if lhs.tradeId != rhs.tradeId { 1348 return false 1349 } 1350 if lhs.tradeGeneration != rhs.tradeGeneration { 1351 return false 1352 } 1353 if lhs.observedAtUnixS != rhs.observedAtUnixS { 1354 return false 1355 } 1356 if lhs.coverage != rhs.coverage { 1357 return false 1358 } 1359 if lhs.evidencePolicyDigest != rhs.evidencePolicyDigest { 1360 return false 1361 } 1362 if lhs.manifestDigest != rhs.manifestDigest { 1363 return false 1364 } 1365 if lhs.canonicalBytesHex != rhs.canonicalBytesHex { 1366 return false 1367 } 1368 return true 1369 } 1370 1371 public func hash(into hasher: inout Hasher) { 1372 hasher.combine(contractId) 1373 hasher.combine(contractVersion) 1374 hasher.combine(tradeId) 1375 hasher.combine(tradeGeneration) 1376 hasher.combine(observedAtUnixS) 1377 hasher.combine(coverage) 1378 hasher.combine(evidencePolicyDigest) 1379 hasher.combine(manifestDigest) 1380 hasher.combine(canonicalBytesHex) 1381 } 1382 } 1383 1384 1385 1386 #if swift(>=5.8) 1387 @_documentation(visibility: private) 1388 #endif 1389 public struct FfiConverterTypeTradeEvidenceManifest: FfiConverterRustBuffer { 1390 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TradeEvidenceManifest { 1391 return 1392 try TradeEvidenceManifest( 1393 contractId: FfiConverterString.read(from: &buf), 1394 contractVersion: FfiConverterUInt16.read(from: &buf), 1395 tradeId: FfiConverterString.read(from: &buf), 1396 tradeGeneration: FfiConverterString.read(from: &buf), 1397 observedAtUnixS: FfiConverterString.read(from: &buf), 1398 coverage: FfiConverterTypeTradeEvidenceCoverage.read(from: &buf), 1399 evidencePolicyDigest: FfiConverterString.read(from: &buf), 1400 manifestDigest: FfiConverterString.read(from: &buf), 1401 canonicalBytesHex: FfiConverterString.read(from: &buf) 1402 ) 1403 } 1404 1405 public static func write(_ value: TradeEvidenceManifest, into buf: inout [UInt8]) { 1406 FfiConverterString.write(value.contractId, into: &buf) 1407 FfiConverterUInt16.write(value.contractVersion, into: &buf) 1408 FfiConverterString.write(value.tradeId, into: &buf) 1409 FfiConverterString.write(value.tradeGeneration, into: &buf) 1410 FfiConverterString.write(value.observedAtUnixS, into: &buf) 1411 FfiConverterTypeTradeEvidenceCoverage.write(value.coverage, into: &buf) 1412 FfiConverterString.write(value.evidencePolicyDigest, into: &buf) 1413 FfiConverterString.write(value.manifestDigest, into: &buf) 1414 FfiConverterString.write(value.canonicalBytesHex, into: &buf) 1415 } 1416 } 1417 1418 1419 #if swift(>=5.8) 1420 @_documentation(visibility: private) 1421 #endif 1422 public func FfiConverterTypeTradeEvidenceManifest_lift(_ buf: RustBuffer) throws -> TradeEvidenceManifest { 1423 return try FfiConverterTypeTradeEvidenceManifest.lift(buf) 1424 } 1425 1426 #if swift(>=5.8) 1427 @_documentation(visibility: private) 1428 #endif 1429 public func FfiConverterTypeTradeEvidenceManifest_lower(_ value: TradeEvidenceManifest) -> RustBuffer { 1430 return FfiConverterTypeTradeEvidenceManifest.lower(value) 1431 } 1432 1433 1434 /** 1435 * One unsigned typed event plan ready for host-owned signing. 1436 */ 1437 public struct TypedEvidenceEventPlan { 1438 public var contractId: String 1439 public var kind: UInt32 1440 public var authorPubkey: String 1441 public var createdAtUnixS: String 1442 public var expectedEventId: String 1443 public var tags: [[String]] 1444 public var content: String 1445 1446 // Default memberwise initializers are never public by default, so we 1447 // declare one manually. 1448 public init(contractId: String, kind: UInt32, authorPubkey: String, createdAtUnixS: String, expectedEventId: String, tags: [[String]], content: String) { 1449 self.contractId = contractId 1450 self.kind = kind 1451 self.authorPubkey = authorPubkey 1452 self.createdAtUnixS = createdAtUnixS 1453 self.expectedEventId = expectedEventId 1454 self.tags = tags 1455 self.content = content 1456 } 1457 } 1458 1459 #if compiler(>=6) 1460 extension TypedEvidenceEventPlan: Sendable {} 1461 #endif 1462 1463 1464 extension TypedEvidenceEventPlan: Equatable, Hashable { 1465 public static func ==(lhs: TypedEvidenceEventPlan, rhs: TypedEvidenceEventPlan) -> Bool { 1466 if lhs.contractId != rhs.contractId { 1467 return false 1468 } 1469 if lhs.kind != rhs.kind { 1470 return false 1471 } 1472 if lhs.authorPubkey != rhs.authorPubkey { 1473 return false 1474 } 1475 if lhs.createdAtUnixS != rhs.createdAtUnixS { 1476 return false 1477 } 1478 if lhs.expectedEventId != rhs.expectedEventId { 1479 return false 1480 } 1481 if lhs.tags != rhs.tags { 1482 return false 1483 } 1484 if lhs.content != rhs.content { 1485 return false 1486 } 1487 return true 1488 } 1489 1490 public func hash(into hasher: inout Hasher) { 1491 hasher.combine(contractId) 1492 hasher.combine(kind) 1493 hasher.combine(authorPubkey) 1494 hasher.combine(createdAtUnixS) 1495 hasher.combine(expectedEventId) 1496 hasher.combine(tags) 1497 hasher.combine(content) 1498 } 1499 } 1500 1501 1502 1503 #if swift(>=5.8) 1504 @_documentation(visibility: private) 1505 #endif 1506 public struct FfiConverterTypeTypedEvidenceEventPlan: FfiConverterRustBuffer { 1507 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TypedEvidenceEventPlan { 1508 return 1509 try TypedEvidenceEventPlan( 1510 contractId: FfiConverterString.read(from: &buf), 1511 kind: FfiConverterUInt32.read(from: &buf), 1512 authorPubkey: FfiConverterString.read(from: &buf), 1513 createdAtUnixS: FfiConverterString.read(from: &buf), 1514 expectedEventId: FfiConverterString.read(from: &buf), 1515 tags: FfiConverterSequenceSequenceString.read(from: &buf), 1516 content: FfiConverterString.read(from: &buf) 1517 ) 1518 } 1519 1520 public static func write(_ value: TypedEvidenceEventPlan, into buf: inout [UInt8]) { 1521 FfiConverterString.write(value.contractId, into: &buf) 1522 FfiConverterUInt32.write(value.kind, into: &buf) 1523 FfiConverterString.write(value.authorPubkey, into: &buf) 1524 FfiConverterString.write(value.createdAtUnixS, into: &buf) 1525 FfiConverterString.write(value.expectedEventId, into: &buf) 1526 FfiConverterSequenceSequenceString.write(value.tags, into: &buf) 1527 FfiConverterString.write(value.content, into: &buf) 1528 } 1529 } 1530 1531 1532 #if swift(>=5.8) 1533 @_documentation(visibility: private) 1534 #endif 1535 public func FfiConverterTypeTypedEvidenceEventPlan_lift(_ buf: RustBuffer) throws -> TypedEvidenceEventPlan { 1536 return try FfiConverterTypeTypedEvidenceEventPlan.lift(buf) 1537 } 1538 1539 #if swift(>=5.8) 1540 @_documentation(visibility: private) 1541 #endif 1542 public func FfiConverterTypeTypedEvidenceEventPlan_lower(_ value: TypedEvidenceEventPlan) -> RustBuffer { 1543 return FfiConverterTypeTypedEvidenceEventPlan.lower(value) 1544 } 1545 1546 // Note that we don't yet support `indirect` for enums. 1547 // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. 1548 /** 1549 * Current side-effect-free capability availability. 1550 */ 1551 1552 public enum CapabilityAvailability { 1553 1554 case available 1555 case degraded 1556 case unavailable 1557 case unsupported 1558 } 1559 1560 1561 #if compiler(>=6) 1562 extension CapabilityAvailability: Sendable {} 1563 #endif 1564 1565 #if swift(>=5.8) 1566 @_documentation(visibility: private) 1567 #endif 1568 public struct FfiConverterTypeCapabilityAvailability: FfiConverterRustBuffer { 1569 typealias SwiftType = CapabilityAvailability 1570 1571 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> CapabilityAvailability { 1572 let variant: Int32 = try readInt(&buf) 1573 switch variant { 1574 1575 case 1: return .available 1576 1577 case 2: return .degraded 1578 1579 case 3: return .unavailable 1580 1581 case 4: return .unsupported 1582 1583 default: throw UniffiInternalError.unexpectedEnumCase 1584 } 1585 } 1586 1587 public static func write(_ value: CapabilityAvailability, into buf: inout [UInt8]) { 1588 switch value { 1589 1590 1591 case .available: 1592 writeInt(&buf, Int32(1)) 1593 1594 1595 case .degraded: 1596 writeInt(&buf, Int32(2)) 1597 1598 1599 case .unavailable: 1600 writeInt(&buf, Int32(3)) 1601 1602 1603 case .unsupported: 1604 writeInt(&buf, Int32(4)) 1605 1606 } 1607 } 1608 } 1609 1610 1611 #if swift(>=5.8) 1612 @_documentation(visibility: private) 1613 #endif 1614 public func FfiConverterTypeCapabilityAvailability_lift(_ buf: RustBuffer) throws -> CapabilityAvailability { 1615 return try FfiConverterTypeCapabilityAvailability.lift(buf) 1616 } 1617 1618 #if swift(>=5.8) 1619 @_documentation(visibility: private) 1620 #endif 1621 public func FfiConverterTypeCapabilityAvailability_lower(_ value: CapabilityAvailability) -> RustBuffer { 1622 return FfiConverterTypeCapabilityAvailability.lower(value) 1623 } 1624 1625 1626 extension CapabilityAvailability: Equatable, Hashable {} 1627 1628 1629 1630 1631 1632 1633 // Note that we don't yet support `indirect` for enums. 1634 // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. 1635 /** 1636 * Stable capability maturity independent of runtime availability. 1637 */ 1638 1639 public enum CapabilityMaturity { 1640 1641 case stable 1642 case preview 1643 case experimental 1644 } 1645 1646 1647 #if compiler(>=6) 1648 extension CapabilityMaturity: Sendable {} 1649 #endif 1650 1651 #if swift(>=5.8) 1652 @_documentation(visibility: private) 1653 #endif 1654 public struct FfiConverterTypeCapabilityMaturity: FfiConverterRustBuffer { 1655 typealias SwiftType = CapabilityMaturity 1656 1657 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> CapabilityMaturity { 1658 let variant: Int32 = try readInt(&buf) 1659 switch variant { 1660 1661 case 1: return .stable 1662 1663 case 2: return .preview 1664 1665 case 3: return .experimental 1666 1667 default: throw UniffiInternalError.unexpectedEnumCase 1668 } 1669 } 1670 1671 public static func write(_ value: CapabilityMaturity, into buf: inout [UInt8]) { 1672 switch value { 1673 1674 1675 case .stable: 1676 writeInt(&buf, Int32(1)) 1677 1678 1679 case .preview: 1680 writeInt(&buf, Int32(2)) 1681 1682 1683 case .experimental: 1684 writeInt(&buf, Int32(3)) 1685 1686 } 1687 } 1688 } 1689 1690 1691 #if swift(>=5.8) 1692 @_documentation(visibility: private) 1693 #endif 1694 public func FfiConverterTypeCapabilityMaturity_lift(_ buf: RustBuffer) throws -> CapabilityMaturity { 1695 return try FfiConverterTypeCapabilityMaturity.lift(buf) 1696 } 1697 1698 #if swift(>=5.8) 1699 @_documentation(visibility: private) 1700 #endif 1701 public func FfiConverterTypeCapabilityMaturity_lower(_ value: CapabilityMaturity) -> RustBuffer { 1702 return FfiConverterTypeCapabilityMaturity.lower(value) 1703 } 1704 1705 1706 extension CapabilityMaturity: Equatable, Hashable {} 1707 1708 1709 1710 1711 1712 1713 1714 /** 1715 * Secret-safe SDK failure at the language boundary. 1716 */ 1717 public enum Error: Swift.Error { 1718 1719 1720 1721 case Sdk(code: String, message: String, retryable: Bool 1722 ) 1723 } 1724 1725 1726 #if swift(>=5.8) 1727 @_documentation(visibility: private) 1728 #endif 1729 public struct FfiConverterTypeError: FfiConverterRustBuffer { 1730 typealias SwiftType = Error 1731 1732 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Error { 1733 let variant: Int32 = try readInt(&buf) 1734 switch variant { 1735 1736 1737 1738 1739 case 1: return .Sdk( 1740 code: try FfiConverterString.read(from: &buf), 1741 message: try FfiConverterString.read(from: &buf), 1742 retryable: try FfiConverterBool.read(from: &buf) 1743 ) 1744 1745 default: throw UniffiInternalError.unexpectedEnumCase 1746 } 1747 } 1748 1749 public static func write(_ value: Error, into buf: inout [UInt8]) { 1750 switch value { 1751 1752 1753 1754 1755 1756 case let .Sdk(code,message,retryable): 1757 writeInt(&buf, Int32(1)) 1758 FfiConverterString.write(code, into: &buf) 1759 FfiConverterString.write(message, into: &buf) 1760 FfiConverterBool.write(retryable, into: &buf) 1761 1762 } 1763 } 1764 } 1765 1766 1767 #if swift(>=5.8) 1768 @_documentation(visibility: private) 1769 #endif 1770 public func FfiConverterTypeError_lift(_ buf: RustBuffer) throws -> Error { 1771 return try FfiConverterTypeError.lift(buf) 1772 } 1773 1774 #if swift(>=5.8) 1775 @_documentation(visibility: private) 1776 #endif 1777 public func FfiConverterTypeError_lower(_ value: Error) -> RustBuffer { 1778 return FfiConverterTypeError.lower(value) 1779 } 1780 1781 1782 extension Error: Equatable, Hashable {} 1783 1784 1785 1786 1787 extension Error: Foundation.LocalizedError { 1788 public var errorDescription: String? { 1789 String(reflecting: self) 1790 } 1791 } 1792 1793 1794 1795 1796 // Note that we don't yet support `indirect` for enums. 1797 // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. 1798 /** 1799 * Final evidence coverage vocabulary. 1800 */ 1801 1802 public enum TradeEvidenceCoverage { 1803 1804 case missing 1805 case partial 1806 case scopeSatisfied 1807 case unsupported 1808 } 1809 1810 1811 #if compiler(>=6) 1812 extension TradeEvidenceCoverage: Sendable {} 1813 #endif 1814 1815 #if swift(>=5.8) 1816 @_documentation(visibility: private) 1817 #endif 1818 public struct FfiConverterTypeTradeEvidenceCoverage: FfiConverterRustBuffer { 1819 typealias SwiftType = TradeEvidenceCoverage 1820 1821 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TradeEvidenceCoverage { 1822 let variant: Int32 = try readInt(&buf) 1823 switch variant { 1824 1825 case 1: return .missing 1826 1827 case 2: return .partial 1828 1829 case 3: return .scopeSatisfied 1830 1831 case 4: return .unsupported 1832 1833 default: throw UniffiInternalError.unexpectedEnumCase 1834 } 1835 } 1836 1837 public static func write(_ value: TradeEvidenceCoverage, into buf: inout [UInt8]) { 1838 switch value { 1839 1840 1841 case .missing: 1842 writeInt(&buf, Int32(1)) 1843 1844 1845 case .partial: 1846 writeInt(&buf, Int32(2)) 1847 1848 1849 case .scopeSatisfied: 1850 writeInt(&buf, Int32(3)) 1851 1852 1853 case .unsupported: 1854 writeInt(&buf, Int32(4)) 1855 1856 } 1857 } 1858 } 1859 1860 1861 #if swift(>=5.8) 1862 @_documentation(visibility: private) 1863 #endif 1864 public func FfiConverterTypeTradeEvidenceCoverage_lift(_ buf: RustBuffer) throws -> TradeEvidenceCoverage { 1865 return try FfiConverterTypeTradeEvidenceCoverage.lift(buf) 1866 } 1867 1868 #if swift(>=5.8) 1869 @_documentation(visibility: private) 1870 #endif 1871 public func FfiConverterTypeTradeEvidenceCoverage_lower(_ value: TradeEvidenceCoverage) -> RustBuffer { 1872 return FfiConverterTypeTradeEvidenceCoverage.lower(value) 1873 } 1874 1875 1876 extension TradeEvidenceCoverage: Equatable, Hashable {} 1877 1878 1879 1880 1881 1882 1883 // Note that we don't yet support `indirect` for enums. 1884 // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. 1885 /** 1886 * Final evidence outcome vocabulary. 1887 */ 1888 1889 public enum TradeEvidenceOutcome { 1890 1891 case valid 1892 case invalid 1893 case indeterminate 1894 } 1895 1896 1897 #if compiler(>=6) 1898 extension TradeEvidenceOutcome: Sendable {} 1899 #endif 1900 1901 #if swift(>=5.8) 1902 @_documentation(visibility: private) 1903 #endif 1904 public struct FfiConverterTypeTradeEvidenceOutcome: FfiConverterRustBuffer { 1905 typealias SwiftType = TradeEvidenceOutcome 1906 1907 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TradeEvidenceOutcome { 1908 let variant: Int32 = try readInt(&buf) 1909 switch variant { 1910 1911 case 1: return .valid 1912 1913 case 2: return .invalid 1914 1915 case 3: return .indeterminate 1916 1917 default: throw UniffiInternalError.unexpectedEnumCase 1918 } 1919 } 1920 1921 public static func write(_ value: TradeEvidenceOutcome, into buf: inout [UInt8]) { 1922 switch value { 1923 1924 1925 case .valid: 1926 writeInt(&buf, Int32(1)) 1927 1928 1929 case .invalid: 1930 writeInt(&buf, Int32(2)) 1931 1932 1933 case .indeterminate: 1934 writeInt(&buf, Int32(3)) 1935 1936 } 1937 } 1938 } 1939 1940 1941 #if swift(>=5.8) 1942 @_documentation(visibility: private) 1943 #endif 1944 public func FfiConverterTypeTradeEvidenceOutcome_lift(_ buf: RustBuffer) throws -> TradeEvidenceOutcome { 1945 return try FfiConverterTypeTradeEvidenceOutcome.lift(buf) 1946 } 1947 1948 #if swift(>=5.8) 1949 @_documentation(visibility: private) 1950 #endif 1951 public func FfiConverterTypeTradeEvidenceOutcome_lower(_ value: TradeEvidenceOutcome) -> RustBuffer { 1952 return FfiConverterTypeTradeEvidenceOutcome.lower(value) 1953 } 1954 1955 1956 extension TradeEvidenceOutcome: Equatable, Hashable {} 1957 1958 1959 1960 1961 1962 1963 #if swift(>=5.8) 1964 @_documentation(visibility: private) 1965 #endif 1966 fileprivate struct FfiConverterOptionTypeRhiEvidenceSupersession: FfiConverterRustBuffer { 1967 typealias SwiftType = RhiEvidenceSupersession? 1968 1969 public static func write(_ value: SwiftType, into buf: inout [UInt8]) { 1970 guard let value = value else { 1971 writeInt(&buf, Int8(0)) 1972 return 1973 } 1974 writeInt(&buf, Int8(1)) 1975 FfiConverterTypeRhiEvidenceSupersession.write(value, into: &buf) 1976 } 1977 1978 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { 1979 switch try readInt(&buf) as Int8 { 1980 case 0: return nil 1981 case 1: return try FfiConverterTypeRhiEvidenceSupersession.read(from: &buf) 1982 default: throw UniffiInternalError.unexpectedOptionalTag 1983 } 1984 } 1985 } 1986 1987 #if swift(>=5.8) 1988 @_documentation(visibility: private) 1989 #endif 1990 fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer { 1991 typealias SwiftType = [String] 1992 1993 public static func write(_ value: [String], into buf: inout [UInt8]) { 1994 let len = Int32(value.count) 1995 writeInt(&buf, len) 1996 for item in value { 1997 FfiConverterString.write(item, into: &buf) 1998 } 1999 } 2000 2001 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String] { 2002 let len: Int32 = try readInt(&buf) 2003 var seq = [String]() 2004 seq.reserveCapacity(Int(len)) 2005 for _ in 0 ..< len { 2006 seq.append(try FfiConverterString.read(from: &buf)) 2007 } 2008 return seq 2009 } 2010 } 2011 2012 #if swift(>=5.8) 2013 @_documentation(visibility: private) 2014 #endif 2015 fileprivate struct FfiConverterSequenceTypeCapabilityStatus: FfiConverterRustBuffer { 2016 typealias SwiftType = [CapabilityStatus] 2017 2018 public static func write(_ value: [CapabilityStatus], into buf: inout [UInt8]) { 2019 let len = Int32(value.count) 2020 writeInt(&buf, len) 2021 for item in value { 2022 FfiConverterTypeCapabilityStatus.write(item, into: &buf) 2023 } 2024 } 2025 2026 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [CapabilityStatus] { 2027 let len: Int32 = try readInt(&buf) 2028 var seq = [CapabilityStatus]() 2029 seq.reserveCapacity(Int(len)) 2030 for _ in 0 ..< len { 2031 seq.append(try FfiConverterTypeCapabilityStatus.read(from: &buf)) 2032 } 2033 return seq 2034 } 2035 } 2036 2037 #if swift(>=5.8) 2038 @_documentation(visibility: private) 2039 #endif 2040 fileprivate struct FfiConverterSequenceSequenceString: FfiConverterRustBuffer { 2041 typealias SwiftType = [[String]] 2042 2043 public static func write(_ value: [[String]], into buf: inout [UInt8]) { 2044 let len = Int32(value.count) 2045 writeInt(&buf, len) 2046 for item in value { 2047 FfiConverterSequenceString.write(item, into: &buf) 2048 } 2049 } 2050 2051 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [[String]] { 2052 let len: Int32 = try readInt(&buf) 2053 var seq = [[String]]() 2054 seq.reserveCapacity(Int(len)) 2055 for _ in 0 ..< len { 2056 seq.append(try FfiConverterSequenceString.read(from: &buf)) 2057 } 2058 return seq 2059 } 2060 } 2061 private let UNIFFI_RUST_FUTURE_POLL_READY: Int8 = 0 2062 private let UNIFFI_RUST_FUTURE_POLL_MAYBE_READY: Int8 = 1 2063 2064 fileprivate let uniffiContinuationHandleMap = UniffiHandleMap<UnsafeContinuation<Int8, Never>>() 2065 2066 fileprivate func uniffiRustCallAsync<F, T>( 2067 rustFutureFunc: () -> UInt64, 2068 pollFunc: (UInt64, @escaping UniffiRustFutureContinuationCallback, UInt64) -> (), 2069 completeFunc: (UInt64, UnsafeMutablePointer<RustCallStatus>) -> F, 2070 freeFunc: (UInt64) -> (), 2071 liftFunc: (F) throws -> T, 2072 errorHandler: ((RustBuffer) throws -> Swift.Error)? 2073 ) async throws -> T { 2074 // Make sure to call the ensure init function since future creation doesn't have a 2075 // RustCallStatus param, so doesn't use makeRustCall() 2076 uniffiEnsureRadrootsSdkFfiInitialized() 2077 let rustFuture = rustFutureFunc() 2078 defer { 2079 freeFunc(rustFuture) 2080 } 2081 var pollResult: Int8; 2082 repeat { 2083 pollResult = await withUnsafeContinuation { 2084 pollFunc( 2085 rustFuture, 2086 uniffiFutureContinuationCallback, 2087 uniffiContinuationHandleMap.insert(obj: $0) 2088 ) 2089 } 2090 } while pollResult != UNIFFI_RUST_FUTURE_POLL_READY 2091 2092 return try liftFunc(makeRustCall( 2093 { completeFunc(rustFuture, $0) }, 2094 errorHandler: errorHandler 2095 )) 2096 } 2097 2098 // Callback handlers for an async calls. These are invoked by Rust when the future is ready. They 2099 // lift the return value or error and resume the suspended function. 2100 fileprivate func uniffiFutureContinuationCallback(handle: UInt64, pollResult: Int8) { 2101 if let continuation = try? uniffiContinuationHandleMap.remove(handle: handle) { 2102 continuation.resume(returning: pollResult) 2103 } else { 2104 print("uniffiFutureContinuationCallback invalid handle") 2105 } 2106 } 2107 public func parseRhiEvidenceReport(canonicalContent: String)throws -> RhiEvidenceReport { 2108 return try FfiConverterTypeRhiEvidenceReport_lift(try rustCallWithError(FfiConverterTypeError_lift) { 2109 uniffi_radroots_sdk_ffi_fn_func_parse_rhi_evidence_report( 2110 FfiConverterString.lower(canonicalContent),$0 2111 ) 2112 }) 2113 } 2114 public func parseTradeEvidenceManifest(canonicalBytes: Data)throws -> TradeEvidenceManifest { 2115 return try FfiConverterTypeTradeEvidenceManifest_lift(try rustCallWithError(FfiConverterTypeError_lift) { 2116 uniffi_radroots_sdk_ffi_fn_func_parse_trade_evidence_manifest( 2117 FfiConverterData.lower(canonicalBytes),$0 2118 ) 2119 }) 2120 } 2121 public func prepareRhiEvidenceAttestation(canonicalContent: String, createdAtUnixS: UInt64)throws -> TypedEvidenceEventPlan { 2122 return try FfiConverterTypeTypedEvidenceEventPlan_lift(try rustCallWithError(FfiConverterTypeError_lift) { 2123 uniffi_radroots_sdk_ffi_fn_func_prepare_rhi_evidence_attestation( 2124 FfiConverterString.lower(canonicalContent), 2125 FfiConverterUInt64.lower(createdAtUnixS),$0 2126 ) 2127 }) 2128 } 2129 public func validateRhiEvidenceAttestation(event: SignedEvent)throws -> RhiEvidenceAttestation { 2130 return try FfiConverterTypeRhiEvidenceAttestation_lift(try rustCallWithError(FfiConverterTypeError_lift) { 2131 uniffi_radroots_sdk_ffi_fn_func_validate_rhi_evidence_attestation( 2132 FfiConverterTypeSignedEvent_lower(event),$0 2133 ) 2134 }) 2135 } 2136 2137 private enum InitializationResult { 2138 case ok 2139 case contractVersionMismatch 2140 case apiChecksumMismatch 2141 } 2142 // Use a global variable to perform the versioning checks. Swift ensures that 2143 // the code inside is only computed once. 2144 private let initializationResult: InitializationResult = { 2145 // Get the bindings contract version from our ComponentInterface 2146 let bindings_contract_version = 29 2147 // Get the scaffolding contract version by calling the into the dylib 2148 let scaffolding_contract_version = ffi_radroots_sdk_ffi_uniffi_contract_version() 2149 if bindings_contract_version != scaffolding_contract_version { 2150 return InitializationResult.contractVersionMismatch 2151 } 2152 if (uniffi_radroots_sdk_ffi_checksum_func_parse_rhi_evidence_report() != 37549) { 2153 return InitializationResult.apiChecksumMismatch 2154 } 2155 if (uniffi_radroots_sdk_ffi_checksum_func_parse_trade_evidence_manifest() != 35922) { 2156 return InitializationResult.apiChecksumMismatch 2157 } 2158 if (uniffi_radroots_sdk_ffi_checksum_func_prepare_rhi_evidence_attestation() != 53127) { 2159 return InitializationResult.apiChecksumMismatch 2160 } 2161 if (uniffi_radroots_sdk_ffi_checksum_func_validate_rhi_evidence_attestation() != 46555) { 2162 return InitializationResult.apiChecksumMismatch 2163 } 2164 if (uniffi_radroots_sdk_ffi_checksum_method_mobileclient_capabilities() != 23938) { 2165 return InitializationResult.apiChecksumMismatch 2166 } 2167 if (uniffi_radroots_sdk_ffi_checksum_method_mobileclient_close() != 15210) { 2168 return InitializationResult.apiChecksumMismatch 2169 } 2170 if (uniffi_radroots_sdk_ffi_checksum_method_mobileclient_is_closed() != 40205) { 2171 return InitializationResult.apiChecksumMismatch 2172 } 2173 if (uniffi_radroots_sdk_ffi_checksum_constructor_mobileclient_memory() != 50243) { 2174 return InitializationResult.apiChecksumMismatch 2175 } 2176 2177 return InitializationResult.ok 2178 }() 2179 2180 // Make the ensure init function public so that other modules which have external type references to 2181 // our types can call it. 2182 public func uniffiEnsureRadrootsSdkFfiInitialized() { 2183 switch initializationResult { 2184 case .ok: 2185 break 2186 case .contractVersionMismatch: 2187 fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project") 2188 case .apiChecksumMismatch: 2189 fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") 2190 } 2191 } 2192 2193 // swiftlint:enable all