Add decryption keys

This commit is contained in:
Nicholas Molnar 2022-05-16 08:55:02 -07:00 committed by Franck Royer
parent 4734e4b7c7
commit 5faa186b34
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 13 additions and 3 deletions

View File

@ -1,5 +1,4 @@
import debug from "debug"; import debug from "debug";
// import concat from "it-concat";
import lp from "it-length-prefixed"; import lp from "it-length-prefixed";
import { pipe } from "it-pipe"; import { pipe } from "it-pipe";
import Libp2p from "libp2p"; import Libp2p from "libp2p";
@ -62,7 +61,7 @@ export class WakuFilter {
const { stream } = await connection.newStream(FilterCodec); const { stream } = await connection.newStream(FilterCodec);
try { try {
await pipe([request.encode()], lp.encode(), stream.sink); await pipe([request.encode()], lp.encode(), stream);
} catch (e) { } catch (e) {
log("Error subscribing", e); log("Error subscribing", e);
} }
@ -104,8 +103,19 @@ export class WakuFilter {
console.warn(`No callback registered for request ID ${requestId}`); console.warn(`No callback registered for request ID ${requestId}`);
return; return;
} }
const decryptionKeys = Array.from(this.decryptionKeys).map(
([key, { method, contentTopics }]) => {
return {
key,
method,
contentTopics,
};
}
);
for (const message of messages) { for (const message of messages) {
const decoded = await WakuMessage.decodeProto(message, []); const decoded = await WakuMessage.decodeProto(message, decryptionKeys);
if (!decoded) { if (!decoded) {
console.error("Not able to decode message"); console.error("Not able to decode message");
continue; continue;