|
6 | 6 | } from "@waku/core";
|
7 | 7 | import type { IFilterSubscription, LightNode } from "@waku/interfaces";
|
8 | 8 | import { Protocols } from "@waku/interfaces";
|
| 9 | +import { ecies, symmetric } from "@waku/message-encryption"; |
9 | 10 | import { utf8ToBytes } from "@waku/utils/bytes";
|
10 | 11 | import { expect } from "chai";
|
11 | 12 |
|
@@ -65,6 +66,49 @@ describe("Waku Filter V2: Subscribe", function () {
|
65 | 66 | expect((await nwaku.messages()).length).to.eq(1);
|
66 | 67 | });
|
67 | 68 |
|
| 69 | + it("Subscribe and receive ecies encrypted messages via lightPush", async function () { |
| 70 | + const privateKey = ecies.generatePrivateKey(); |
| 71 | + const publicKey = ecies.getPublicKey(privateKey); |
| 72 | + const encoder = ecies.createEncoder({ |
| 73 | + contentTopic: TestContentTopic, |
| 74 | + publicKey |
| 75 | + }); |
| 76 | + const decoder = ecies.createDecoder(TestContentTopic, privateKey); |
| 77 | + |
| 78 | + await subscription.subscribe([decoder], messageCollector.callback); |
| 79 | + |
| 80 | + await waku.lightPush.send(encoder, messagePayload); |
| 81 | + |
| 82 | + expect(await messageCollector.waitForMessages(1)).to.eq(true); |
| 83 | + messageCollector.verifyReceivedMessage(0, { |
| 84 | + expectedMessageText: messageText, |
| 85 | + expectedContentTopic: TestContentTopic, |
| 86 | + expectedVersion: 1 |
| 87 | + }); |
| 88 | + expect((await nwaku.messages()).length).to.eq(1); |
| 89 | + }); |
| 90 | + |
| 91 | + it("Subscribe and receive symmetrically encrypted messages via lightPush", async function () { |
| 92 | + const symKey = symmetric.generateSymmetricKey(); |
| 93 | + const encoder = symmetric.createEncoder({ |
| 94 | + contentTopic: TestContentTopic, |
| 95 | + symKey |
| 96 | + }); |
| 97 | + const decoder = symmetric.createDecoder(TestContentTopic, symKey); |
| 98 | + |
| 99 | + await subscription.subscribe([decoder], messageCollector.callback); |
| 100 | + |
| 101 | + await waku.lightPush.send(encoder, messagePayload); |
| 102 | + |
| 103 | + expect(await messageCollector.waitForMessages(1)).to.eq(true); |
| 104 | + messageCollector.verifyReceivedMessage(0, { |
| 105 | + expectedMessageText: messageText, |
| 106 | + expectedContentTopic: TestContentTopic, |
| 107 | + expectedVersion: 1 |
| 108 | + }); |
| 109 | + expect((await nwaku.messages()).length).to.eq(1); |
| 110 | + }); |
| 111 | + |
68 | 112 | it("Subscribe and receive messages via waku relay post", async function () {
|
69 | 113 | await subscription.subscribe([TestDecoder], messageCollector.callback);
|
70 | 114 |
|
|
0 commit comments