Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nakajima committed Feb 5, 2024
1 parent b74d035 commit f71a3d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
19 changes: 9 additions & 10 deletions Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ public enum ClientError: Error {
case creationError(String)
}

public enum MLSAlphaOption {
case disabled, enabled(SigningKey?)
}

/// Specify configuration options for creating a ``Client``.
public struct ClientOptions {
// Specify network options
Expand Down Expand Up @@ -48,15 +44,15 @@ public struct ClientOptions {
/// `preCreateIdentityCallback` will be called immediately before a Create Identity wallet signature is requested from the user.
public var preCreateIdentityCallback: PreEventCallback?

public var mlsAlpha: MLSAlphaOption = .disabled
public var mlsAlpha = false
public var mlsEncryptionKey: Data?

public init(
api: Api = Api(),
codecs: [any ContentCodec] = [],
preEnableIdentityCallback: PreEventCallback? = nil,
preCreateIdentityCallback: PreEventCallback? = nil,
mlsAlpha: MLSAlphaOption = .disabled,
mlsAlpha: Bool = false,
mlsEncryptionKey: Data? = nil
) {
self.api = api
Expand Down Expand Up @@ -120,9 +116,10 @@ public final class Client {
address: String,
options: ClientOptions?,
source: LegacyIdentitySource,
privateKeyBundleV1: PrivateKeyBundleV1
privateKeyBundleV1: PrivateKeyBundleV1,
signingKey: SigningKey?
) async throws -> FfiXmtpClient? {
if case let .enabled(signingKey) = options?.mlsAlpha, options?.api.env == .local {
if options?.mlsAlpha == true, options?.api.env == .local {
let dbURL = URL.documentsDirectory.appendingPathComponent("xmtp-\(options?.api.env.rawValue ?? "")-\(address).db3")
let v3Client = try await LibXMTP.createClient(
logger: XMTPLogger(),
Expand Down Expand Up @@ -159,7 +156,8 @@ public final class Client {
address: account.address,
options: options,
source: source,
privateKeyBundleV1: privateKeyBundleV1
privateKeyBundleV1: privateKeyBundleV1,
signingKey: account
)

if let textToSign = v3Client?.textToSign() {
Expand Down Expand Up @@ -255,7 +253,8 @@ public final class Client {
address: address,
options: options,
source: .static,
privateKeyBundleV1: v1Bundle
privateKeyBundleV1: v1Bundle,
signingKey: nil
)

let result = try Client(address: address, privateKeyBundleV1: v1Bundle, apiClient: apiClient, v3Client: v3Client)
Expand Down
10 changes: 5 additions & 5 deletions Tests/XMTPTests/ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ClientTests: XCTestCase {
account: bo,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: .enabled(bo)
mlsAlpha: true
)
)
} catch {
Expand All @@ -46,7 +46,7 @@ class ClientTests: XCTestCase {
account: bo,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: .enabled(bo)
mlsAlpha: true
)
)

Expand All @@ -56,7 +56,7 @@ class ClientTests: XCTestCase {
options: .init(
api: .init(env: .local, isSecure: false),
// Should not need to pass the signer again
mlsAlpha: .enabled(nil)
mlsAlpha: true
)
)

Expand All @@ -73,7 +73,7 @@ class ClientTests: XCTestCase {
account: bo,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: .enabled(bo),
mlsAlpha: true,
mlsEncryptionKey: key
)
)
Expand All @@ -83,7 +83,7 @@ class ClientTests: XCTestCase {
account: bo,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: .enabled(bo),
mlsAlpha: true,
mlsEncryptionKey: nil // No key should error
)
)
Expand Down

0 comments on commit f71a3d6

Please sign in to comment.