From 0966c1152e0ee22273341994c35f06e7f20b3884 Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Thu, 2 Jun 2022 10:33:39 +0200 Subject: [PATCH] Add IdentityMaker --- Sources/ElixxirDAppsSDK/Client.swift | 7 ++++-- Sources/ElixxirDAppsSDK/IdentityMaker.swift | 26 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 Sources/ElixxirDAppsSDK/IdentityMaker.swift diff --git a/Sources/ElixxirDAppsSDK/Client.swift b/Sources/ElixxirDAppsSDK/Client.swift index 7183cc63..6cfc8fe9 100644 --- a/Sources/ElixxirDAppsSDK/Client.swift +++ b/Sources/ElixxirDAppsSDK/Client.swift @@ -3,13 +3,15 @@ import Bindings public struct Client { public var networkFollower: NetworkFollower public var waitForNetwork: NetworkWaiter + public var makeIdentity: IdentityMaker } extension Client { public static func live(bindingsClient: BindingsClient) -> Client { Client( networkFollower: .live(bindingsClient: bindingsClient), - waitForNetwork: .live(bindingsClient: bindingsClient) + waitForNetwork: .live(bindingsClient: bindingsClient), + makeIdentity: .live(bindingsClient: bindingsClient) ) } } @@ -18,7 +20,8 @@ extension Client { extension Client { public static let failing = Client( networkFollower: .failing, - waitForNetwork: .failing + waitForNetwork: .failing, + makeIdentity: .failing ) } #endif diff --git a/Sources/ElixxirDAppsSDK/IdentityMaker.swift b/Sources/ElixxirDAppsSDK/IdentityMaker.swift new file mode 100644 index 00000000..91e7eeed --- /dev/null +++ b/Sources/ElixxirDAppsSDK/IdentityMaker.swift @@ -0,0 +1,26 @@ +import Bindings + +public struct IdentityMaker { + public var make: () throws -> Data + + public func callAsFunction() throws -> Data { + try make() + } +} + +extension IdentityMaker { + public static func live(bindingsClient: BindingsClient) -> IdentityMaker { + IdentityMaker { + try bindingsClient.makeIdentity() + } + } +} + +#if DEBUG +extension IdentityMaker { + public static let failing = IdentityMaker { + struct NotImplemented: Error {} + throw NotImplemented() + } +} +#endif -- GitLab