diff --git a/Package.swift b/Package.swift index 1ecb5bc9..4513363a 100644 --- a/Package.swift +++ b/Package.swift @@ -20,7 +20,7 @@ let package = Package( .package(url: "https://github.com/tesseract-one/CSecp256k1.swift.git", from: "0.2.0"), .package(url: "https://github.com/bufbuild/connect-swift", exact: "1.0.0"), .package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.4.3"), - .package(url: "https://github.com/xmtp/libxmtp-swift.git", exact: "3.0.3"), + .package(url: "https://github.com/xmtp/libxmtp-swift.git", exact: "3.0.5"), .package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", exact: "1.8.3") ], targets: [ diff --git a/Sources/XMTPiOS/Client.swift b/Sources/XMTPiOS/Client.swift index eb0a1e37..3fac8c1b 100644 --- a/Sources/XMTPiOS/Client.swift +++ b/Sources/XMTPiOS/Client.swift @@ -379,6 +379,30 @@ public final class Client { return try ffiClient.signWithInstallationKey(text: message) } + public func verifySignature(message: String, signature: Data) throws -> Bool + { + do { + try ffiClient.verifySignedWithInstallationKey( + signatureText: message, signatureBytes: signature) + return true + } catch { + return false + } + } + + public func verifySignatureWithInstallationId( + message: String, signature: Data, installationId: String + ) throws -> Bool { + do { + try ffiClient.verifySignedWithPublicKey( + signatureText: message, signatureBytes: signature, + publicKey: installationId.hexToData) + return true + } catch { + return false + } + } + public func findGroup(groupId: String) throws -> Group? { do { return Group( diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index 3a64a270..fa292697 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -398,4 +398,71 @@ class ClientTests: XCTestCase { )) } + func testSignatures() async throws { + let fixtures = try await fixtures() + + // Signing with installation key + let signature = try fixtures.alixClient.signWithInstallationKey( + message: "Testing") + XCTAssertTrue( + try fixtures.alixClient.verifySignature( + message: "Testing", signature: signature)) + XCTAssertFalse( + try fixtures.alixClient.verifySignature( + message: "Not Testing", signature: signature)) + + let alixInstallationId = fixtures.alixClient.installationID + + XCTAssertTrue( + try fixtures.alixClient.verifySignatureWithInstallationId( + message: "Testing", + signature: signature, + installationId: alixInstallationId + )) + XCTAssertFalse( + try fixtures.alixClient.verifySignatureWithInstallationId( + message: "Not Testing", + signature: signature, + installationId: alixInstallationId + )) + XCTAssertFalse( + try fixtures.alixClient.verifySignatureWithInstallationId( + message: "Testing", + signature: signature, + installationId: fixtures.boClient.installationID + )) + XCTAssertTrue( + try fixtures.boClient.verifySignatureWithInstallationId( + message: "Testing", + signature: signature, + installationId: alixInstallationId + )) + + try fixtures.alixClient.deleteLocalDatabase() + let key = try Crypto.secureRandomBytes(count: 32) + let options = ClientOptions.init( + api: .init(env: .local, isSecure: false), + dbEncryptionKey: key + ) + + // Creating a new client + let alixClient2 = try await Client.create( + account: fixtures.alix, + options: options + ) + + XCTAssertTrue( + try alixClient2.verifySignatureWithInstallationId( + message: "Testing", + signature: signature, + installationId: alixInstallationId + )) + XCTAssertFalse( + try alixClient2.verifySignatureWithInstallationId( + message: "Testing2", + signature: signature, + installationId: alixInstallationId + )) + } + } diff --git a/XMTP.podspec b/XMTP.podspec index 93f3dd12..b1c63778 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = "XMTP" - spec.version = "3.0.7" + spec.version = "3.0.8" spec.summary = "XMTP SDK Cocoapod" spec.description = <<-DESC @@ -22,7 +22,7 @@ Pod::Spec.new do |spec| spec.dependency 'CSecp256k1', '~> 0.2' spec.dependency "Connect-Swift", "= 1.0.0" - spec.dependency 'LibXMTP', '= 3.0.3' + spec.dependency 'LibXMTP', '= 3.0.5' spec.dependency 'CryptoSwift', '= 1.8.3' spec.ios.deployment_target = '14.0' diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 21d422e2..14a2f437 100644 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -41,8 +41,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/xmtp/libxmtp-swift.git", "state" : { - "revision" : "d44798db766bd82e93c4f49f9997b5369f927971", - "version" : "3.0.3" + "revision" : "77fd4bb5a04281b30e887dcc8739497acaa7a3a6", + "version" : "3.0.5" } }, {