diff --git a/Sources/ElixxirDAppsSDK/ClientCreator.swift b/Sources/ElixxirDAppsSDK/ClientCreator.swift new file mode 100644 index 0000000000000000000000000000000000000000..e048227edb7b0db96fc42362725acb2bbf519d44 --- /dev/null +++ b/Sources/ElixxirDAppsSDK/ClientCreator.swift @@ -0,0 +1,32 @@ +import Bindings + +public struct ClientCreator { + public var create: (URL, Data, Data) throws -> Void + + public func callAsFunction(directoryURL: URL, ndf: Data, password: Data) throws { + try create(directoryURL, ndf, password) + } +} + +extension ClientCreator { + public static let live = ClientCreator { directoryURL, ndf, password in + var error: NSError? + let network = String(data: ndf, encoding: .utf8)! + let created = BindingsNewClient(network, directoryURL.path, password, nil, &error) + if let error = error { + throw error + } + if !created { + throw BindingsNewClientUnknownError() + } + } +} + +#if DEBUG +extension ClientCreator { + public static let failing = ClientCreator { _, _, _ in + struct NotImplemented: Error {} + throw NotImplemented() + } +} +#endif diff --git a/Sources/ElixxirDAppsSDK/Errors.swift b/Sources/ElixxirDAppsSDK/Errors.swift index 0f113897a48ac3055837e1256a4571da57b7f961..94f93f982e58bd8a3e26c4494c96f88697a6fb70 100644 --- a/Sources/ElixxirDAppsSDK/Errors.swift +++ b/Sources/ElixxirDAppsSDK/Errors.swift @@ -9,3 +9,7 @@ public struct BindingsGenerateSecretUnknownError: Error, Equatable { public struct PasswordStorageMissingPasswordError: Error, Equatable { public init() {} } + +public struct BindingsNewClientUnknownError: Error, Equatable { + public init() {} +}