diff --git a/CHANGELOG.md b/CHANGELOG.md index a3886e5d51..374df414e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Simple connection management that selects the most recent connection for store, light push and filter requests. +### Changed + +- **breaking**: `DecryptionParams` may be passed when using `queryHistory` instead of just keys. + ## [0.25.0] - 2022-09-5 ### Changed diff --git a/src/lib/waku_filter/index.ts b/src/lib/waku_filter/index.ts index c63bfd0aae..bd3bc8e8c9 100644 --- a/src/lib/waku_filter/index.ts +++ b/src/lib/waku_filter/index.ts @@ -167,7 +167,7 @@ export class WakuFilter { return; } - const decryptionKeys = Array.from(this.decryptionKeys).map( + const decryptionParams = Array.from(this.decryptionKeys).map( ([key, { method, contentTopics }]) => { return { key, @@ -178,7 +178,7 @@ export class WakuFilter { ); for (const message of messages) { - const decoded = await WakuMessage.decodeProto(message, decryptionKeys); + const decoded = await WakuMessage.decodeProto(message, decryptionParams); if (!decoded) { log("Not able to decode message"); continue; diff --git a/src/lib/waku_message/index.ts b/src/lib/waku_message/index.ts index 1acee41889..0f4379b62a 100644 --- a/src/lib/waku_message/index.ts +++ b/src/lib/waku_message/index.ts @@ -38,7 +38,6 @@ export interface Options { sigPrivKey?: Uint8Array; } -// TODO: Use this in Options export interface DecryptionParams { key: Uint8Array; method?: DecryptionMethod; diff --git a/src/lib/waku_relay/index.ts b/src/lib/waku_relay/index.ts index c104f0b3ab..edb46d0e8c 100644 --- a/src/lib/waku_relay/index.ts +++ b/src/lib/waku_relay/index.ts @@ -184,7 +184,7 @@ export class WakuRelay extends GossipSub { "gossipsub:message", (event: CustomEvent) => { if (event.detail.msg.topic === pubSubTopic) { - const decryptionKeys = Array.from(this.decryptionKeys).map( + const decryptionParams = Array.from(this.decryptionKeys).map( ([key, { method, contentTopics }]) => { return { key, @@ -195,7 +195,7 @@ export class WakuRelay extends GossipSub { ); dbg(`Message received on ${pubSubTopic}`); - WakuMessage.decode(event.detail.msg.data, decryptionKeys) + WakuMessage.decode(event.detail.msg.data, decryptionParams) .then((wakuMsg) => { if (!wakuMsg) { dbg("Failed to decode Waku Message"); diff --git a/src/lib/waku_store/index.node.spec.ts b/src/lib/waku_store/index.node.spec.ts index 5a55ef8b34..2b05c1e21a 100644 --- a/src/lib/waku_store/index.node.spec.ts +++ b/src/lib/waku_store/index.node.spec.ts @@ -304,7 +304,7 @@ describe("Waku Store", () => { dbg("Retrieve messages from store"); const messages = await waku2.store.queryHistory([], { - decryptionKeys: [privateKey], + decryptionParams: [{ key: privateKey }], }); expect(messages?.length).eq(3); @@ -411,7 +411,7 @@ describe("Waku Store", () => { dbg("Retrieve messages from store"); const messages = await waku2.store.queryHistory([], { - decryptionKeys: [privateKey], + decryptionParams: [{ key: privateKey }], }); expect(messages?.length).eq(3); diff --git a/src/lib/waku_store/index.ts b/src/lib/waku_store/index.ts index d9486516be..82eddc1ded 100644 --- a/src/lib/waku_store/index.ts +++ b/src/lib/waku_store/index.ts @@ -13,7 +13,11 @@ import { DefaultPubSubTopic, StoreCodecs } from "../constants"; import { selectConnection } from "../select_connection"; import { getPeersForProtocol, selectRandomPeer } from "../select_peer"; import { hexToBytes } from "../utils"; -import { DecryptionMethod, WakuMessage } from "../waku_message"; +import { + DecryptionMethod, + DecryptionParams, + WakuMessage, +} from "../waku_message"; import { HistoryRPC, PageDirection } from "./history_rpc"; @@ -91,7 +95,7 @@ export interface QueryOptions { * It can be Asymmetric Private Keys and Symmetric Keys in the same array, * all keys will be tried with both methods. */ - decryptionKeys?: Array; + decryptionParams?: DecryptionParams[]; } /** @@ -176,26 +180,20 @@ export class WakuStore { if (!connection) throw "Failed to get a connection to the peer"; - const decryptionKeys = Array.from(this.decryptionKeys).map( - ([key, { method, contentTopics }]) => { - return { - key, - method, - contentTopics, - }; - } - ); + let decryptionParams: DecryptionParams[] = []; + + this.decryptionKeys.forEach(({ method, contentTopics }, key) => { + decryptionParams.push({ + key, + method, + contentTopics, + }); + }); // Add the decryption keys passed to this function against the // content topics also passed to this function. - if (opts.decryptionKeys) { - opts.decryptionKeys.forEach((key) => { - decryptionKeys.push({ - key: hexToBytes(key), - contentTopics: contentTopics.length ? contentTopics : undefined, - method: undefined, - }); - }); + if (opts.decryptionParams) { + decryptionParams = decryptionParams.concat(opts.decryptionParams); } const messages: WakuMessage[] = []; @@ -245,7 +243,7 @@ export class WakuStore { const pageMessages: WakuMessage[] = []; await Promise.all( response.messages.map(async (protoMsg) => { - const msg = await WakuMessage.decodeProto(protoMsg, decryptionKeys); + const msg = await WakuMessage.decodeProto(protoMsg, decryptionParams); if (msg) { messages.push(msg);