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

Signature verification #437

Merged
merged 25 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ede8122
update package
nplasterer Sep 13, 2024
70c3a41
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Sep 13, 2024
c72c33c
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Sep 20, 2024
bc9fb62
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Sep 22, 2024
3e6c8e2
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Sep 26, 2024
558729b
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Sep 26, 2024
709cd72
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Sep 26, 2024
6af3b08
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Oct 1, 2024
e499905
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Oct 9, 2024
c18f087
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Oct 24, 2024
380f36c
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Oct 25, 2024
8128559
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 1, 2024
2a93ced
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 4, 2024
c2da259
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 8, 2024
21cfe68
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 8, 2024
cce1b4c
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 10, 2024
ef869d2
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 11, 2024
8b85235
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 12, 2024
fb85455
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 13, 2024
2e145f8
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 15, 2024
36dea14
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 19, 2024
101e708
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 21, 2024
3b9c313
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 21, 2024
bd15754
bump the version
nplasterer Nov 21, 2024
919865c
get on the latest version and write a test
nplasterer Nov 22, 2024
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
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
Loading