Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable Group Chat for Production #351

Merged
merged 3 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,26 @@ 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 = false
public var mlsEncryptionKey: Data?
public var mlsDbDirectory: String?
public var enableV3 = false
public var dbEncryptionKey: Data?
public var dbDirectory: String?

public init(
api: Api = Api(),
codecs: [any ContentCodec] = [],
preEnableIdentityCallback: PreEventCallback? = nil,
preCreateIdentityCallback: PreEventCallback? = nil,
mlsAlpha: Bool = false,
mlsEncryptionKey: Data? = nil,
mlsDbDirectory: String? = nil
enableV3: Bool = false,
encryptionKey: Data? = nil,
dbDirectory: String? = nil
) {
self.api = api
self.codecs = codecs
self.preEnableIdentityCallback = preEnableIdentityCallback
self.preCreateIdentityCallback = preCreateIdentityCallback
self.mlsAlpha = mlsAlpha
self.mlsEncryptionKey = mlsEncryptionKey
self.mlsDbDirectory = mlsDbDirectory
self.enableV3 = enableV3
self.dbEncryptionKey = encryptionKey
self.dbDirectory = dbDirectory
}
}

Expand Down Expand Up @@ -135,7 +135,7 @@ public final class Client {
privateKeyBundleV1: PrivateKeyBundleV1,
signingKey: SigningKey?
) async throws -> (FfiXmtpClient?, String) {
if options?.mlsAlpha == true, options?.api.env.supportsMLS == true {
if options?.enableV3 == true {
let address = accountAddress.lowercased()

var inboxId: String
Expand All @@ -150,7 +150,7 @@ public final class Client {
inboxId = generateInboxId(accountAddress: address, nonce: 0)
}

let mlsDbDirectory = options?.mlsDbDirectory
let mlsDbDirectory = options?.dbDirectory
var directoryURL: URL
if let mlsDbDirectory = mlsDbDirectory {
let fileManager = FileManager.default
Expand All @@ -170,7 +170,7 @@ public final class Client {
let alias = "xmtp-\(options?.api.env.rawValue ?? "")-\(inboxId).db3"
let dbURL = directoryURL.appendingPathComponent(alias).path

let encryptionKey = options?.mlsEncryptionKey
let encryptionKey = options?.dbEncryptionKey

let v3Client = try await LibXMTP.createClient(
logger: XMTPLogger(),
Expand Down
4 changes: 0 additions & 4 deletions Sources/XMTPiOS/XMTPEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ public enum XMTPEnvironment: String, Sendable {
}
}

public var supportsMLS: Bool {
self != .production
}

public var isSecure: Bool {
url.starts(with: "https")
}
Expand Down
58 changes: 29 additions & 29 deletions Tests/XMTPTests/ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class ClientTests: XCTestCase {
account: bo,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: true,
mlsEncryptionKey: key
enableV3: true,
encryptionKey: key
)
)
} catch {
Expand All @@ -45,8 +45,8 @@ class ClientTests: XCTestCase {
account: bo,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: true,
mlsEncryptionKey: key
enableV3: true,
encryptionKey: key
)
)

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

XCTAssertEqual(client.address, otherClient.address)
}

func testPassingMLSEncryptionKey() async throws {
func testPassingencryptionKey() async throws {
let bo = try PrivateKey.generate()
let key = try Crypto.secureRandomBytes(count: 32)

_ = try await Client.create(
account: bo,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: true,
mlsEncryptionKey: key
enableV3: true,
encryptionKey: key
)
)

Expand All @@ -82,8 +82,8 @@ class ClientTests: XCTestCase {
account: bo,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: true,
mlsEncryptionKey: nil // No key should error
enableV3: true,
encryptionKey: nil // No key should error
)
)

Expand All @@ -100,15 +100,15 @@ class ClientTests: XCTestCase {
account: bo,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: true
enableV3: true
)
)

let alixClient = try await Client.create(
account: alix,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: true
enableV3: true
)
)

Expand All @@ -124,7 +124,7 @@ class ClientTests: XCTestCase {
account: bo,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: true
enableV3: true
)
)

Expand All @@ -140,15 +140,15 @@ class ClientTests: XCTestCase {
account: bo,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: true
enableV3: true
)
)

let alixClient = try await Client.create(
account: alix,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: true
enableV3: true
)
)

Expand Down Expand Up @@ -285,17 +285,17 @@ class ClientTests: XCTestCase {
}
}

func testPassingMLSEncryptionKeyAndDatabaseDirectory() async throws {
func testPassingencryptionKeyAndDatabaseDirectory() async throws {
let bo = try PrivateKey.generate()
let key = try Crypto.secureRandomBytes(count: 32)

let client = try await Client.create(
account: bo,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: true,
mlsEncryptionKey: key,
mlsDbDirectory: "xmtp_db"
enableV3: true,
encryptionKey: key,
dbDirectory: "xmtp_db"
)
)

Expand All @@ -304,9 +304,9 @@ class ClientTests: XCTestCase {
bundle: keys,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: true,
mlsEncryptionKey: key,
mlsDbDirectory: "xmtp_db"
enableV3: true,
encryptionKey: key,
dbDirectory: "xmtp_db"
)
)

Expand All @@ -319,9 +319,9 @@ class ClientTests: XCTestCase {
bundle: keys,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: true,
mlsEncryptionKey: nil,
mlsDbDirectory: "xmtp_db"
enableV3: true,
encryptionKey: nil,
dbDirectory: "xmtp_db"
)
)
)
Expand All @@ -331,9 +331,9 @@ class ClientTests: XCTestCase {
bundle: keys,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: true,
mlsEncryptionKey: key,
mlsDbDirectory: nil
enableV3: true,
encryptionKey: key,
dbDirectory: nil
)
)
)
Expand Down
4 changes: 2 additions & 2 deletions Tests/XMTPTests/FramesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ final class FramesTests: XCTestCase {
account: bo,
options: .init(
api: .init(env: .local, isSecure: false),
mlsAlpha: true,
mlsEncryptionKey: key
enableV3: true,
encryptionKey: key
)
)

Expand Down
12 changes: 6 additions & 6 deletions Tests/XMTPTests/GroupPermissionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class GroupPermissionTests: XCTestCase {
options: .init(
api: .init(env: .local, isSecure: false),
codecs: [GroupUpdatedCodec()],
mlsAlpha: true,
mlsEncryptionKey: key
enableV3: true,
encryptionKey: key
)
)
let bob = try PrivateKey.generate()
Expand All @@ -41,8 +41,8 @@ class GroupPermissionTests: XCTestCase {
options: .init(
api: .init(env: .local, isSecure: false),
codecs: [GroupUpdatedCodec()],
mlsAlpha: true,
mlsEncryptionKey: key
enableV3: true,
encryptionKey: key
)
)
let caro = try PrivateKey.generate()
Expand All @@ -51,8 +51,8 @@ class GroupPermissionTests: XCTestCase {
options: .init(
api: .init(env: .local, isSecure: false),
codecs: [GroupUpdatedCodec()],
mlsAlpha: true,
mlsEncryptionKey: key
enableV3: true,
encryptionKey: key
)
)

Expand Down
12 changes: 6 additions & 6 deletions Tests/XMTPTests/GroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class GroupTests: XCTestCase {
options: .init(
api: .init(env: .local, isSecure: false),
codecs: [GroupUpdatedCodec()],
mlsAlpha: true,
mlsEncryptionKey: key
enableV3: true,
encryptionKey: key
)
)
let bob = try PrivateKey.generate()
Expand All @@ -62,8 +62,8 @@ class GroupTests: XCTestCase {
options: .init(
api: .init(env: .local, isSecure: false),
codecs: [GroupUpdatedCodec()],
mlsAlpha: true,
mlsEncryptionKey: key
enableV3: true,
encryptionKey: key
)
)
let fred = try PrivateKey.generate()
Expand All @@ -72,8 +72,8 @@ class GroupTests: XCTestCase {
options: .init(
api: .init(env: .local, isSecure: false),
codecs: [GroupUpdatedCodec()],
mlsAlpha: true,
mlsEncryptionKey: key
enableV3: true,
encryptionKey: key
)
)

Expand Down
2 changes: 1 addition & 1 deletion XMTP.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |spec|
#

spec.name = "XMTP"
spec.version = "0.11.7"
spec.version = "0.12.0"
spec.summary = "XMTP SDK Cocoapod"

# This description is used to generate tags and improve search results.
Expand Down
4 changes: 2 additions & 2 deletions XMTPiOSExample/XMTPiOSExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct ContentView: View {
options: .init(
api: .init(env: .local, isSecure: false),
codecs: [GroupUpdatedCodec()],
mlsAlpha: true
enableV3: true
)
)
await MainActor.run {
Expand Down Expand Up @@ -97,7 +97,7 @@ struct ContentView: View {
options: .init(
api: .init(env: .local, isSecure: false, appVersion: "XMTPTest/v1.0.0"),
codecs: [GroupUpdatedCodec()],
mlsAlpha: true
enableV3: true
)
)

Expand Down
2 changes: 1 addition & 1 deletion XMTPiOSExample/XMTPiOSExample/Views/LoginView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ struct LoginView: View {
options: .init(
api: .init(env: .local, isSecure: false),
codecs: [GroupUpdatedCodec()],
mlsAlpha: true
enableV3: true
)
)

Expand Down
Loading