import XCTest @testable import LChatCore // Pins the open-group key wire shape shared with the web (shell.js // createThread / loadThreads): open_key = {k: } // encrypted under the instance key; the group name decrypts with the carried // thread key. If either side changes the envelope, this breaks here rather // than as a silently-undecryptable directory in production. final class OpenKeyRoundTripTests: XCTestCase { func testOpenKeyWireShapeRoundTrips() throws { let ik = try GroupKey(rawKey: ECIES.randomAESKey()) let threadRaw = ECIES.randomAESKey() // What createChat(openGroup:) writes… let openKey = try ik.encryptJSON(["k": threadRaw.base64urlEncodedString()]) // …and what the fold / discoverGroups read back. let payload = try ik.decryptJSON(OpenKeyPayload.self, blob: openKey) XCTAssertEqual(Data(base64urlEncoded: payload.k), threadRaw) let key = try GroupKey(rawKey: Data(base64urlEncoded: payload.k)!) let nameBlob = try key.encryptJSON(["name": "Fáilte 🏠"]) XCTAssertEqual(try key.decryptJSON(GroupNamePayload.self, blob: nameBlob).name, "Fáilte 🏠") } }