Decrypt and correctly unwrap Community Description messages

This commit is contained in:
Franck Royer 2021-10-19 11:27:22 +11:00
parent e25f3c0b44
commit 373603067c
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 38 additions and 1 deletions

View File

@ -0,0 +1,29 @@
import { expect } from "chai";
import { Waku } from "js-waku";
import { Community } from "./community";
import { CommunityDescription } from "./wire/community_description";
describe("Community", () => {
it.skip("Retrieves community description For DappConnect Test from Waku prod fleet", async function () {
this.timeout(20000);
const waku = await Waku.create({ bootstrap: true });
await waku.waitForConnectedPeer();
const community = await Community.instantiateCommunity(
"0x0262c65c881f5a9f79343a26faaa02aad3af7c533d9445fb1939ed11b8bf4d2abd",
waku
);
await community.refreshCommunityDescription();
const desc = community.description as CommunityDescription;
expect(desc).to.not.be.undefined;
expect(desc.identity?.displayName).to.eq("DappConnect Test");
const chats = Array.from(desc.chats.values()).map(
(chat) => chat?.identity?.displayName
);
expect(chats).to.include("foobar");
expect(chats).to.include("another-channel!");
});
});

View File

@ -3,9 +3,11 @@ import { WakuMessage, WakuStore } from "js-waku";
import { Reader } from "protobufjs";
import { idToContentTopic } from "../contentTopic";
import { createSymKeyFromPassword } from "../encryption";
import * as proto from "../proto/communities/v1/communities";
import { bufToHex } from "../utils";
import { ApplicationMetadataMessage } from "./application_metadata_message";
import { ChatIdentity } from "./chat_identity";
import { CommunityChat } from "./community_chat";
@ -45,8 +47,11 @@ export class CommunityDescription {
orderedMessages.forEach((message: WakuMessage) => {
if (!message.payload) return;
try {
const metadata = ApplicationMetadataMessage.decode(message.payload);
if (!metadata.payload) return;
const _communityDescription = CommunityDescription.decode(
message.payload
metadata.payload
);
if (!_communityDescription.identity) return;
@ -61,9 +66,12 @@ export class CommunityDescription {
});
};
const symKey = await createSymKeyFromPassword(hexCommunityPublicKey);
await wakuStore
.queryHistory([contentTopic], {
callback,
decryptionKeys: [symKey],
})
.catch((e) => {
dbg(