mirror of https://github.com/waku-org/js-waku.git
feat: `DecryptionParams` may be passed when using `queryHistory`
This commit is contained in:
parent
f44e13885c
commit
e4d4fb1edd
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -38,7 +38,6 @@ export interface Options {
|
|||
sigPrivKey?: Uint8Array;
|
||||
}
|
||||
|
||||
// TODO: Use this in Options
|
||||
export interface DecryptionParams {
|
||||
key: Uint8Array;
|
||||
method?: DecryptionMethod;
|
||||
|
|
|
@ -184,7 +184,7 @@ export class WakuRelay extends GossipSub {
|
|||
"gossipsub:message",
|
||||
(event: CustomEvent<GossipsubMessage>) => {
|
||||
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");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<Uint8Array | string>;
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue