Fixed bug in channel hash calculation and decryption

This commit is contained in:
2026-03-14 19:26:53 +01:00
parent 38b7ea7517
commit 0feb4868e4
5 changed files with 146 additions and 88 deletions

View File

@@ -112,18 +112,12 @@ describe("PrivateKey", () => {
});
describe("SharedSecret", () => {
const secret = randomBytes(32);
const secret = randomBytes(16);
it("constructs from 32 bytes", () => {
it("constructs from 16 bytes", () => {
const ss = new SharedSecret(secret);
expect(ss.toBytes()).toEqual(secret);
});
it("pads if 16 bytes", () => {
const short = randomBytes(16);
const ss = new SharedSecret(short);
expect(ss.toBytes().length).toBe(32);
expect(Array.from(ss.toBytes()).slice(16)).toEqual(Array.from(short));
expect(ss.toBytes().length).toBe(16);
expect(bytesToHex(ss.toBytes())).toBe(bytesToHex(secret));
});
it("throws on invalid length", () => {
@@ -163,6 +157,9 @@ describe("SharedSecret", () => {
it('fromName "Public"', () => {
const ss = SharedSecret.fromName("Public");
expect(ss).toBeInstanceOf(SharedSecret);
const hash = ss.toHash();
expect(typeof hash).toBe("number");
expect(hash).toBe(0x11);
});
it("fromName with #group", () => {