// Example: consuming the pvtcoms UniFFI bindings from an iOS (Swift/SwiftUI) app.
// Add bindings/swift/* to the Xcode project and link the pvtcoms_ffi xcframework.
import Foundation

func demo(deviceKey: Data, sessionKey: Data) throws {
    let v = version()                                  // e.g. "0.1.8"

    // Identity is OPAQUE — the secret key stays inside Rust.
    let id = Identity()                                // == Identity.generate()
    let pub = id.publicKey()                           // Data (32 bytes)
    print("my id \(id.fingerprint())")
    let sig = id.sign(msg: Data("hello".utf8))
    let ok = try verify(publicKey: pub, msg: Data("hello".utf8), signature: sig)   // true

    // Persist: seal under the device key (from the iOS Keychain), restore later.
    let blob = try id.toSealed(storageKey: deviceKey)
    let restored = try Identity.fromSealed(storageKey: deviceKey, blob: blob)

    let emoji = try safetyNumber(sessionKey: sessionKey)   // 16-emoji safety number
}
