| 1 | // The reverse-direction cross-implementation gate: the committed fixture was |
| 2 | // encrypted by the NATIVE client (LChatCore's GroupKey.encryptJSON — see |
| 3 | // NativeMessageVectorTests, regenerated with RECORD_VECTORS=1 swift test), and |
| 4 | // the web's crypto.js must open it. messageblob.test.mjs proves web→native; |
| 5 | // this proves native→web — together they pin the native send path, so a |
| 6 | // message sent from the Mac app provably renders for every web member. |
| 7 | import { readFileSync } from "node:fs"; |
| 8 | import { fileURLToPath } from "node:url"; |
| 9 | import { dirname, join } from "node:path"; |
| 10 | import { importKey, decrypt } from "../web/static/crypto.js"; |
| 11 | |
| 12 | const here = dirname(fileURLToPath(import.meta.url)); |
| 13 | const fixturePath = join( |
| 14 | here, "..", "ios", "LChatCore", "Tests", "LChatCoreTests", "Fixtures", "native-message-vector.json" |
| 15 | ); |
| 16 | |
| 17 | function assert(cond, msg) { |
| 18 | if (!cond) { |
| 19 | console.error("FAIL:", msg); |
| 20 | process.exit(1); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | const fx = JSON.parse(readFileSync(fixturePath, "utf8")); |
| 25 | const got = await decrypt(await importKey(fx.keyB64), fx.blob); |
| 26 | for (const [k, v] of Object.entries(fx.expect)) { |
| 27 | assert(JSON.stringify(got[k]) === JSON.stringify(v), `field ${k}: ${JSON.stringify(got[k])} != ${JSON.stringify(v)}`); |
| 28 | } |
| 29 | console.log("nativeblob.test.mjs OK"); |
| 30 | |