Test asymmetric encryption against nim-waku

This commit is contained in:
Franck Royer 2021-07-09 10:37:29 +10:00
parent f95d9aec3c
commit f123cd7e62
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 40 additions and 0 deletions

View File

@ -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);
});
});

View File

@ -236,6 +236,21 @@ export class NimWaku {
]);
}
async getAsymmetricMessages(
privateKey: Uint8Array,
pubsubTopic?: string
): Promise<WakuRelayMessage[]> {
this.checkProcess();
return await this.rpcCall<WakuRelayMessage[]>(
'get_waku_v2_private_v1_asymmetric_messages',
[
pubsubTopic ? pubsubTopic : DefaultPubsubTopic,
'0x' + bufToHex(privateKey),
]
);
}
async getPeerId(): Promise<PeerId> {
return await this.setPeerId().then((res) => res.peerId);
}