Skip to content

Commit

Permalink
Signature verification (#437)
Browse files Browse the repository at this point in the history
* update package

* bump the version

* get on the latest version and write a test
  • Loading branch information
nplasterer authored Nov 22, 2024
1 parent 9830fe8 commit 19a55aa
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
24 changes: 24 additions & 0 deletions Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
67 changes: 67 additions & 0 deletions Tests/XMTPTests/ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
))
}

}
4 changes: 2 additions & 2 deletions XMTP.podspec
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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'
Expand Down
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" : "d44798db766bd82e93c4f49f9997b5369f927971",
"version" : "3.0.3"
"revision" : "77fd4bb5a04281b30e887dcc8739497acaa7a3a6",
"version" : "3.0.5"
}
},
{
Expand Down

0 comments on commit 19a55aa

Please sign in to comment.