diff --git a/src/lib/waku_message/index.spec.ts b/src/lib/waku_message/index.spec.ts index e114cacbd6..bb02bb8cb5 100644 --- a/src/lib/waku_message/index.spec.ts +++ b/src/lib/waku_message/index.spec.ts @@ -148,4 +148,29 @@ describe('Interop: Nim', function () { expect(receivedMsg.version).to.eq(1); expect(receivedMsg.payloadAsUtf8).to.eq(messageText); }); + + it('Js encrypts message for nim [asymmetric, no signature]', async function () { + this.timeout(5000); + + const keyPair = await nimWaku.getAsymmetricKeyPair(); + const privateKey = hexToBuf(keyPair.privateKey); + const publicKey = hexToBuf(keyPair.publicKey); + + const messageText = 'This is a message I am going to encrypt'; + const message = await WakuMessage.fromUtf8String(messageText, { + encPublicKey: publicKey, + }); + + await waku.relay.send(message); + + let msgs: WakuRelayMessage[] = []; + + while (msgs.length === 0) { + await delay(200); + msgs = await nimWaku.getAsymmetricMessages(privateKey); + } + + expect(msgs[0].contentTopic).to.equal(message.contentTopic); + expect(hexToBuf(msgs[0].payload).toString('utf-8')).to.equal(messageText); + }); }); diff --git a/src/test_utils/nim_waku.ts b/src/test_utils/nim_waku.ts index 334e87db47..cef77d7c4c 100644 --- a/src/test_utils/nim_waku.ts +++ b/src/test_utils/nim_waku.ts @@ -236,6 +236,21 @@ export class NimWaku { ]); } + async getAsymmetricMessages( + privateKey: Uint8Array, + pubsubTopic?: string + ): Promise { + this.checkProcess(); + + return await this.rpcCall( + 'get_waku_v2_private_v1_asymmetric_messages', + [ + pubsubTopic ? pubsubTopic : DefaultPubsubTopic, + '0x' + bufToHex(privateKey), + ] + ); + } + async getPeerId(): Promise { return await this.setPeerId().then((res) => res.peerId); }