Decrypt and correctly unwrap Community Description messages
This commit is contained in:
parent
e25f3c0b44
commit
373603067c
|
@ -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!");
|
||||
});
|
||||
});
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue