From 373603067ca020be99e6c3cdc4147419f62ff6c0 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Tue, 19 Oct 2021 11:27:22 +1100 Subject: [PATCH] Decrypt and correctly unwrap Community Description messages --- .../status-communities/src/community.spec.ts | 29 +++++++++++++++++++ .../src/wire/community_description.ts | 10 ++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 packages/status-communities/src/community.spec.ts diff --git a/packages/status-communities/src/community.spec.ts b/packages/status-communities/src/community.spec.ts new file mode 100644 index 0000000..e1ab10e --- /dev/null +++ b/packages/status-communities/src/community.spec.ts @@ -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!"); + }); +}); diff --git a/packages/status-communities/src/wire/community_description.ts b/packages/status-communities/src/wire/community_description.ts index f86d95f..b4bef50 100644 --- a/packages/status-communities/src/wire/community_description.ts +++ b/packages/status-communities/src/wire/community_description.ts @@ -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(