rewrite bot in TypeScript and add locale switching

This commit is contained in:
Alex Getman
2026-08-12 13:12:04 +03:00
parent 905b69f568
commit 2cb8740e06
121 changed files with 5230 additions and 15333 deletions
+18
View File
@@ -0,0 +1,18 @@
import { describe, expect, test } from "bun:test";
import { buildEncryptedParams, computeSignedNonce, decryptData, encryptData } from "../src/xiaomi/client.js";
describe("Xiaomi crypto", () => {
test("round-trips encrypted payloads and request params", () => {
const ssecurity = Buffer.from("test-ssecurity-key").toString("base64");
const nonce = Buffer.from("123456789012").toString("base64");
const signed = computeSignedNonce(ssecurity, nonce);
expect(decryptData(signed, encryptData(signed, '{"中文":"тест"}'))).toBe('{"中文":"тест"}');
const params = buildEncryptedParams("POST", "/test", ssecurity, { test: "hello", num: 42 });
expect(JSON.parse(decryptData(computeSignedNonce(ssecurity, params._nonce ?? ""), params.data ?? ""))).toEqual({
test: "hello",
num: 42,
});
expect(params.signature).toBeString();
expect(params.rc4_hash__).toBeString();
});
});