Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/xmtp/xmtp-ios into np/add-s…
Browse files Browse the repository at this point in the history
…mart-contract-wallet
  • Loading branch information
nplasterer committed Aug 30, 2024
2 parents 8077be1 + 3fe600e commit b6ceda0
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/xmtp/libxmtp-swift.git",
"state" : {
"revision" : "6ddc5a583663560698d66a7f99852ccb093cf4a5",
"version" : "0.5.7-beta2"
"revision" : "c27b586925714a253e5e9b3875788571552f46d6",
"version" : "0.5.8-beta1"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let package = Package(
.package(url: "https://github.com/1024jp/GzipSwift", from: "5.2.0"),
.package(url: "https://github.com/bufbuild/connect-swift", exact: "0.12.0"),
.package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"),
.package(url: "https://github.com/xmtp/libxmtp-swift.git", exact: "0.5.7-beta3"),
.package(url: "https://github.com/xmtp/libxmtp-swift.git", exact: "0.5.8-beta3"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
25 changes: 24 additions & 1 deletion Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ public final class Client {
}

public func deleteLocalDatabase() throws {
try dropLocalDatabaseConnection()
let fm = FileManager.default
try fm.removeItem(atPath: dbPath)
}
Expand Down Expand Up @@ -640,7 +641,7 @@ public final class Client {
try await signatureRequest.addEcdsaSignature(signatureBytes: signedData.rawData)
}

try await client.registerIdentity(signatureRequest: signatureRequest)
try await client.applySignatureRequest(signatureRequest: signatureRequest)
} catch {
throw ClientError.addWalletError("Failed to sign the message: \(error.localizedDescription)")
}
Expand All @@ -663,4 +664,26 @@ public final class Client {
return false
}
}

public func revokeAllOtherInstallations(signingKey: SigningKey) async throws {
guard let client = v3Client else {
throw ClientError.noV3Client("Error: No V3 client initialized")
}

let signatureRequest = try await client.revokeAllOtherInstallations()
do {
let signedData = try await signingKey.sign(message: signatureRequest.signatureText())
try await signatureRequest.addEcdsaSignature(signatureBytes: signedData.rawData)
try await client.applySignatureRequest(signatureRequest: signatureRequest)
} catch {
throw ClientError.creationError("Failed to sign the message: \(error.localizedDescription)")
}
}

public func inboxState(refreshFromNetwork: Bool) async throws -> InboxState {
guard let client = v3Client else {
throw ClientError.noV3Client("Error: No V3 client initialized")
}
return InboxState(ffiInboxState: try await client.inboxState(refreshFromNetwork: refreshFromNetwork))
}
}
7 changes: 7 additions & 0 deletions Sources/XMTPiOS/Conversations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ public actor Conversations {
}
try await v3Client.conversations().sync()
}

public func syncAllGroups() async throws -> UInt32 {
guard let v3Client = client.v3Client else {
return 0
}
return try await v3Client.conversations().syncAllGroups()
}

public func groups(createdAfter: Date? = nil, createdBefore: Date? = nil, limit: Int? = nil) async throws -> [Group] {
guard let v3Client = client.v3Client else {
Expand Down
34 changes: 34 additions & 0 deletions Sources/XMTPiOS/Mls/InboxState.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// InboxState.swift
//
//
// Created by Naomi Plasterer on 8/21/24.
//

import Foundation
import LibXMTP

public struct InboxState {
var ffiInboxState: FfiInboxState

init(ffiInboxState: FfiInboxState) {
self.ffiInboxState = ffiInboxState
}

public var inboxId: String {
ffiInboxState.inboxId
}

public var addresses: [String] {
ffiInboxState.accountAddresses
}

public var installationIds: [String] {
ffiInboxState.installationIds.map { $0.toHex }
}

public var recoveryAddress: String {
ffiInboxState.recoveryAddress
}

}
36 changes: 36 additions & 0 deletions Tests/XMTPTests/ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -530,5 +530,41 @@ class ClientTests: XCTestCase {
self.key = key
}
}

func testRevokesAllOtherInstallations() async throws {
let key = try Crypto.secureRandomBytes(count: 32)
let alix = try PrivateKey.generate()
let options = ClientOptions.init(
api: .init(env: .local, isSecure: false),
enableV3: true,
encryptionKey: key
)

let alixClient = try await Client.create(
account: alix,
options: options
)
try alixClient.dropLocalDatabaseConnection()
try alixClient.deleteLocalDatabase()

let alixClient2 = try await Client.create(
account: alix,
options: options
)
try alixClient2.dropLocalDatabaseConnection()
try alixClient2.deleteLocalDatabase()

let alixClient3 = try await Client.create(
account: alix,
options: options
)

let state = try await alixClient3.inboxState(refreshFromNetwork: true)
XCTAssertEqual(state.installationIds.count, 3)

try await alixClient3.revokeAllOtherInstallations(signingKey: alix)

let newState = try await alixClient3.inboxState(refreshFromNetwork: true)
XCTAssertEqual(newState.installationIds.count, 1)
}
}
45 changes: 45 additions & 0 deletions Tests/XMTPTests/GroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,51 @@ class GroupTests: XCTestCase {
XCTAssertEqual(preparedMessageId, messages.first!.id)
}

func testCanSyncManyGroupsInUnderASecond() async throws {
let fixtures = try await localFixtures()
var groups: [Group] = []

for _ in 0..<100 {
var group = try await fixtures.aliceClient.conversations.newGroup(with: [fixtures.bob.address])
groups.append(group)
}
try await fixtures.bobClient.conversations.sync()
let bobGroup = try fixtures.bobClient.findGroup(groupId: groups[0].id)
try await groups[0].send(content: "hi")
let messageCount = try await bobGroup!.messages().count
XCTAssertEqual(messageCount, 0)
do {
let start = Date()
let numGroupsSynced = try await fixtures.bobClient.conversations.syncAllGroups()
let end = Date()
print(end.timeIntervalSince(start))
XCTAssert(end.timeIntervalSince(start) < 1)
XCTAssert(numGroupsSynced == 100)
} catch {
print("Failed to list groups members: \(error)")
throw error // Rethrow the error to fail the test if group creation fails
}

let messageCount2 = try await bobGroup!.messages().count
XCTAssertEqual(messageCount2, 1)

for aliceConv in try await fixtures.aliceClient.conversations.list(includeGroups: true) {
guard case let .group(aliceGroup) = aliceConv else {
XCTFail("failed converting conversation to group")
return
}
try await aliceGroup.removeMembers(addresses: [fixtures.bobClient.address])
}

// first syncAllGroups after removal still sync groups in order to process the removal
var numGroupsSynced = try await fixtures.bobClient.conversations.syncAllGroups()
XCTAssert(numGroupsSynced == 100)

// next syncAllGroups only will sync active groups
numGroupsSynced = try await fixtures.bobClient.conversations.syncAllGroups()
XCTAssert(numGroupsSynced == 0)
}

func testCanListManyMembersInParallelInUnderASecond() async throws {
let fixtures = try await localFixtures()
var groups: [Group] = []
Expand Down
4 changes: 2 additions & 2 deletions 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.14.6"
spec.version = "0.14.10"
spec.summary = "XMTP SDK Cocoapod"

# This description is used to generate tags and improve search results.
Expand Down Expand Up @@ -44,5 +44,5 @@ Pod::Spec.new do |spec|
spec.dependency "web3.swift"
spec.dependency "GzipSwift"
spec.dependency "Connect-Swift", "= 0.12.0"
spec.dependency 'LibXMTP', '= 0.5.7-beta3'
spec.dependency 'LibXMTP', '= 0.5.8-beta3'
end
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,16 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/xmtp/libxmtp-swift.git",
"state" : {
<<<<<<< HEAD
"revision" : "65e9a6eed3db394c1afad7d895b89a0c1cae914b",
"version" : "0.5.7-beta0"
||||||| 135991e
"revision" : "0b2d92a8da6caa2e5f16a2ea060b099278354d74",
"version" : "0.5.7-beta3"
=======
"revision" : "06e890646a32c3ae9b9ac78150a7ec4971e54c9d",
"version" : "0.5.8-beta3"
>>>>>>> 3fe600e493b3d2964d91d4a54047d9c56fd5ec46
}
},
{
Expand Down

0 comments on commit b6ceda0

Please sign in to comment.