From 3b26ce32f2c3b9a5bd0ee46767b1cef1b09a5d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noe=CC=81=20Malzieu?= Date: Wed, 11 Sep 2024 15:48:49 +0200 Subject: [PATCH] Signature not always the same --- Tests/XMTPTests/ClientTests.swift | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Tests/XMTPTests/ClientTests.swift b/Tests/XMTPTests/ClientTests.swift index 27c0381a..1927c2b7 100644 --- a/Tests/XMTPTests/ClientTests.swift +++ b/Tests/XMTPTests/ClientTests.swift @@ -492,4 +492,41 @@ class ClientTests: XCTestCase { let newState = try await alixClient3.inboxState(refreshFromNetwork: true) XCTAssertEqual(newState.installationIds.count, 1) } + + func testSignMessage() 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 + ) + let privateKey = try PrivateKey(alixClient.keys.identityKey) + + let stringToSign1 = "TEST_STRING_TO_SIGN" + + let signature1_1 = try await privateKey.sign(stringToSign1.data(using: .utf8)!) + let uint1_1 = try [UInt8](signature1_1.serializedData()) + + let signature1_2 = try await privateKey.sign(stringToSign1.data(using: .utf8)!) + let uint1_2 = try [UInt8](signature1_2.serializedData()) + + XCTAssertEqual(uint1_1, uint1_2) + + let stringToSign2 = "short" + + let signature2_1 = try await privateKey.sign(stringToSign2.data(using: .utf8)!) + let uint2_1 = try [UInt8](signature2_1.serializedData()) + + let signature2_2 = try await privateKey.sign(stringToSign2.data(using: .utf8)!) + let uint2_2 = try [UInt8](signature2_2.serializedData()) + + XCTAssertEqual(uint2_1, uint2_2) + } + }