Skip to content

Commit

Permalink
update the SCW functionality and message listing
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Oct 23, 2024
1 parent 4f36f8c commit e704cea
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Sources/XMTPTestHelpers/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public struct FakeSCWWallet: SigningKey {
walletAddress
}

public var isSmartContractWallet: Bool {
true
public var type: WalletType {
WalletType.SCW
}

public var chainId: Int64 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public final class Client {
if let signatureRequest = v3Client.signatureRequest() {
if let signingKey = signingKey {
do {
if signingKey.isSmartContractWallet {
if signingKey.type == WalletType.SCW {
guard let chainId = signingKey.chainId else {
throw ClientError.creationError("Chain id must be present to sign Smart Contract Wallet")
}
Expand Down
37 changes: 27 additions & 10 deletions Sources/XMTPiOS/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ public struct Group: Identifiable, Equatable, Hashable {
sentBeforeNs: nil,
sentAfterNs: nil,
limit: nil,
deliveryStatus: nil
deliveryStatus: nil,
direction: nil
)

if let before {
Expand Down Expand Up @@ -402,16 +403,20 @@ public struct Group: Identifiable, Equatable, Hashable {
}()

options.deliveryStatus = status

let direction: FfiDirection? = {
switch direction {
case .ascending:
return FfiDirection.ascending
default:
return FfiDirection.descending
}
}()

let messages = try ffiGroup.findMessages(opts: options).compactMap { ffiMessage in
return MessageV3(client: self.client, ffiMessage: ffiMessage).decodeOrNull()
}
options.direction = direction

switch direction {
case .ascending:
return messages
default:
return messages.reversed()
return try ffiGroup.findMessages(opts: options).compactMap { ffiMessage in
return MessageV3(client: self.client, ffiMessage: ffiMessage).decodeOrNull()
}
}

Expand All @@ -426,7 +431,8 @@ public struct Group: Identifiable, Equatable, Hashable {
sentBeforeNs: nil,
sentAfterNs: nil,
limit: nil,
deliveryStatus: nil
deliveryStatus: nil,
direction: nil
)

if let before {
Expand Down Expand Up @@ -455,6 +461,17 @@ public struct Group: Identifiable, Equatable, Hashable {
}()

options.deliveryStatus = status

let direction: FfiDirection? = {
switch direction {
case .ascending:
return FfiDirection.ascending
default:
return FfiDirection.descending
}
}()

options.direction = direction

let messages = try ffiGroup.findMessages(opts: options).compactMap { ffiMessage in
return MessageV3(client: self.client, ffiMessage: ffiMessage).decryptOrNull()
Expand Down
12 changes: 8 additions & 4 deletions Sources/XMTPiOS/SigningKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import Foundation
import web3
import LibXMTP

public enum WalletType {
case EOA, SCW
}

/// Defines a type that is used by a ``Client`` to sign keys and messages.
///
/// You can use ``Account`` for an easier WalletConnect flow, or ``PrivateKey``
Expand All @@ -20,8 +24,8 @@ public protocol SigningKey {
/// A wallet address for this key
var address: String { get }

/// If this signing key is a smart contract wallet
var isSmartContractWallet: Bool { get }
/// The wallet type if Smart Contract Wallet this should be type SCW. Default EOA
var type: WalletType { get }

/// The name of the chainId for example "1"
var chainId: Int64? { get }
Expand All @@ -41,8 +45,8 @@ public protocol SigningKey {
}

extension SigningKey {
public var isSmartContractWallet: Bool {
return false
public var type: WalletType {
return WalletType.EOA
}

public var chainId: Int64? {
Expand Down
19 changes: 19 additions & 0 deletions Tests/XMTPTests/ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -521,4 +521,23 @@ class ClientTests: XCTestCase {
let newState = try await alixClient3.inboxState(refreshFromNetwork: true)
XCTAssertEqual(newState.installations.count, 1)
}

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


let inboxId = try await Client.getOrCreateInboxId(options: options, address: alix.address)
let alixClient = try await Client.createV3(
account: alix,
options: options
)

XCTAssertEqual(inboxId, alixClient.inboxID)
}
}

0 comments on commit e704cea

Please sign in to comment.