From d79b5ae6a9e51da8e9510df4bdec1fa85ad633dd Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Mon, 25 Jul 2022 17:12:54 +0100
Subject: [PATCH] Add E2EHasAuthenticatedChannel functor

---
 Sources/ElixxirDAppsSDK/E2E.swift             |  3 +++
 .../E2EHasAuthenticatedChannel.swift          | 26 +++++++++++++++++++
 2 files changed, 29 insertions(+)
 create mode 100644 Sources/ElixxirDAppsSDK/E2EHasAuthenticatedChannel.swift

diff --git a/Sources/ElixxirDAppsSDK/E2E.swift b/Sources/ElixxirDAppsSDK/E2E.swift
index 24e443ae..20a900d8 100644
--- a/Sources/ElixxirDAppsSDK/E2E.swift
+++ b/Sources/ElixxirDAppsSDK/E2E.swift
@@ -12,6 +12,7 @@ public struct E2E {
   public var addPartnerCallback: E2EAddPartnerCallback
   public var addService: E2EAddService
   public var removeService: E2ERemoveService
+  public var hasAuthenticatedChannel: E2EHasAuthenticatedChannel
   public var send: E2ESend
 
   // TODO:
@@ -31,6 +32,7 @@ extension E2E {
       addPartnerCallback: .live(bindingsE2E),
       addService: .live(bindingsE2E),
       removeService: .live(bindingsE2E),
+      hasAuthenticatedChannel: .live(bindingsE2E),
       send: .live(bindingsE2E)
     )
   }
@@ -49,6 +51,7 @@ extension E2E {
     addPartnerCallback: .unimplemented,
     addService: .unimplemented,
     removeService: .unimplemented,
+    hasAuthenticatedChannel: .unimplemented,
     send: .unimplemented
   )
 }
diff --git a/Sources/ElixxirDAppsSDK/E2EHasAuthenticatedChannel.swift b/Sources/ElixxirDAppsSDK/E2EHasAuthenticatedChannel.swift
new file mode 100644
index 00000000..3871ce86
--- /dev/null
+++ b/Sources/ElixxirDAppsSDK/E2EHasAuthenticatedChannel.swift
@@ -0,0 +1,26 @@
+import Bindings
+import XCTestDynamicOverlay
+
+public struct E2EHasAuthenticatedChannel {
+  public var run: (Data) throws -> Bool
+
+  public func callAsFunction(partnerId: Data) throws -> Bool {
+    try run(partnerId)
+  }
+}
+
+extension E2EHasAuthenticatedChannel {
+  public static func live(_ bindingsE2E: BindingsE2e) -> E2EHasAuthenticatedChannel {
+    E2EHasAuthenticatedChannel { partnerId in
+      var result: ObjCBool = false
+      try bindingsE2E.hasAuthenticatedChannel(partnerId, ret0_: &result)
+      return result.boolValue
+    }
+  }
+}
+
+extension E2EHasAuthenticatedChannel {
+  public static let unimplemented = E2EHasAuthenticatedChannel(
+    run: XCTUnimplemented("\(Self.self)")
+  )
+}
-- 
GitLab