mirror of
https://github.com/logos-messaging/js-noise.git
synced 2026-01-05 23:23:08 +00:00
up tests
This commit is contained in:
parent
64e59328fa
commit
10ce3a6dee
@ -11,7 +11,7 @@ import { DH25519 } from "./dh25519";
|
|||||||
import { MessageNametagBufferSize } from "./messagenametag";
|
import { MessageNametagBufferSize } from "./messagenametag";
|
||||||
import { ResponderParameters, WakuPairing } from "./pairing";
|
import { ResponderParameters, WakuPairing } from "./pairing";
|
||||||
|
|
||||||
const PUBSUB_TOPIC = "default";
|
const PUBSUB_TOPIC = "/waku/2/default-waku/proto";
|
||||||
|
|
||||||
const EMPTY_PROTOMESSAGE = {
|
const EMPTY_PROTOMESSAGE = {
|
||||||
timestamp: undefined,
|
timestamp: undefined,
|
||||||
@ -72,14 +72,14 @@ describe("js-noise: pairing object", () => {
|
|||||||
const aliceStaticKey = dhKey.generateKeyPair();
|
const aliceStaticKey = dhKey.generateKeyPair();
|
||||||
|
|
||||||
const recvParameters = new ResponderParameters();
|
const recvParameters = new ResponderParameters();
|
||||||
const bobPairingObj = new WakuPairing(sender, responder, bobStaticKey, recvParameters);
|
const bobPairingObj = new WakuPairing(PUBSUB_TOPIC, sender, responder, bobStaticKey, recvParameters);
|
||||||
const bobExecP1 = bobPairingObj.execute();
|
const bobExecP1 = bobPairingObj.execute();
|
||||||
|
|
||||||
// Confirmation is done by manually
|
// Confirmation is done by manually
|
||||||
confirmAuthCodeFlow(bobPairingObj, true);
|
confirmAuthCodeFlow(bobPairingObj, true);
|
||||||
|
|
||||||
const initParameters = bobPairingObj.getPairingInfo();
|
const initParameters = bobPairingObj.getPairingInfo();
|
||||||
const alicePairingObj = new WakuPairing(sender, responder, aliceStaticKey, initParameters);
|
const alicePairingObj = new WakuPairing(PUBSUB_TOPIC, sender, responder, aliceStaticKey, initParameters);
|
||||||
const aliceExecP1 = alicePairingObj.execute();
|
const aliceExecP1 = alicePairingObj.execute();
|
||||||
|
|
||||||
// Confirmation is done manually
|
// Confirmation is done manually
|
||||||
@ -115,8 +115,8 @@ describe("js-noise: pairing object", () => {
|
|||||||
|
|
||||||
it("should timeout", async function () {
|
it("should timeout", async function () {
|
||||||
const dhKey = new DH25519();
|
const dhKey = new DH25519();
|
||||||
const bobPairingObj = new WakuPairing(sender, responder, dhKey.generateKeyPair(), new ResponderParameters());
|
const bobPairingObj = new WakuPairing(PUBSUB_TOPIC, sender, responder, dhKey.generateKeyPair(), new ResponderParameters());
|
||||||
const alicePairingObj = new WakuPairing(sender, responder, dhKey.generateKeyPair(), bobPairingObj.getPairingInfo());
|
const alicePairingObj = new WakuPairing(PUBSUB_TOPIC, sender, responder, dhKey.generateKeyPair(), bobPairingObj.getPairingInfo());
|
||||||
|
|
||||||
const bobExecP1 = bobPairingObj.execute(1000);
|
const bobExecP1 = bobPairingObj.execute(1000);
|
||||||
const aliceExecP1 = alicePairingObj.execute(1000);
|
const aliceExecP1 = alicePairingObj.execute(1000);
|
||||||
@ -147,14 +147,14 @@ describe("js-noise: pairing object", () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const recvParameters = new ResponderParameters();
|
const recvParameters = new ResponderParameters();
|
||||||
const bobPairingObj = new WakuPairing(sender, responder, bobStaticKey, recvParameters, undefined, { metaSetter });
|
const bobPairingObj = new WakuPairing(PUBSUB_TOPIC, sender, responder, bobStaticKey, recvParameters, undefined, { metaSetter });
|
||||||
const bobExecP1 = bobPairingObj.execute();
|
const bobExecP1 = bobPairingObj.execute();
|
||||||
|
|
||||||
// Confirmation is done by manually
|
// Confirmation is done by manually
|
||||||
confirmAuthCodeFlow(bobPairingObj, true);
|
confirmAuthCodeFlow(bobPairingObj, true);
|
||||||
|
|
||||||
const initParameters = bobPairingObj.getPairingInfo();
|
const initParameters = bobPairingObj.getPairingInfo();
|
||||||
const alicePairingObj = new WakuPairing(sender, responder, aliceStaticKey, initParameters, undefined, {
|
const alicePairingObj = new WakuPairing(PUBSUB_TOPIC, sender, responder, aliceStaticKey, initParameters, undefined, {
|
||||||
metaSetter,
|
metaSetter,
|
||||||
});
|
});
|
||||||
const aliceExecP1 = alicePairingObj.execute();
|
const aliceExecP1 = alicePairingObj.execute();
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import { NoiseHandshakePatterns } from "./patterns.js";
|
|||||||
import { NoisePublicKey } from "./publickey.js";
|
import { NoisePublicKey } from "./publickey.js";
|
||||||
import { QR } from "./qr.js";
|
import { QR } from "./qr.js";
|
||||||
|
|
||||||
const PUBSUB_TOPIC = "default";
|
const PUBSUB_TOPIC = "/waku/2/default-waku/proto";
|
||||||
|
|
||||||
describe("Waku Noise Sessions", () => {
|
describe("Waku Noise Sessions", () => {
|
||||||
const rng = new HMACDRBG();
|
const rng = new HMACDRBG();
|
||||||
@ -114,7 +114,7 @@ describe("Waku Noise Sessions", () => {
|
|||||||
messageNametag: qrMessageNameTag,
|
messageNametag: qrMessageNameTag,
|
||||||
});
|
});
|
||||||
|
|
||||||
let encoder = new NoiseHandshakeEncoder(contentTopic, aliceStep);
|
let encoder = new NoiseHandshakeEncoder(contentTopic, PUBSUB_TOPIC, aliceStep);
|
||||||
|
|
||||||
// We prepare a Waku message from Alice's payload2
|
// We prepare a Waku message from Alice's payload2
|
||||||
// At this point wakuMsg is sent over the Waku network and is received
|
// At this point wakuMsg is sent over the Waku network and is received
|
||||||
@ -122,7 +122,7 @@ describe("Waku Noise Sessions", () => {
|
|||||||
let wakuMsgBytes = await encoder.toWire({ payload: new Uint8Array() });
|
let wakuMsgBytes = await encoder.toWire({ payload: new Uint8Array() });
|
||||||
|
|
||||||
// We decode the WakuMessage from the ProtoBuffer
|
// We decode the WakuMessage from the ProtoBuffer
|
||||||
let decoder = new NoiseHandshakeDecoder(contentTopic);
|
let decoder = new NoiseHandshakeDecoder(contentTopic, PUBSUB_TOPIC);
|
||||||
let wakuMsgProto = await decoder.fromWireToProtoObj(wakuMsgBytes!);
|
let wakuMsgProto = await decoder.fromWireToProtoObj(wakuMsgBytes!);
|
||||||
let v2Msg = await decoder.fromProtoObj(PUBSUB_TOPIC, wakuMsgProto!);
|
let v2Msg = await decoder.fromProtoObj(PUBSUB_TOPIC, wakuMsgProto!);
|
||||||
|
|
||||||
@ -157,14 +157,14 @@ describe("Waku Noise Sessions", () => {
|
|||||||
bobStep = bobHS.stepHandshake({ transportMessage: sentTransportMessage, messageNametag: bobMessageNametag });
|
bobStep = bobHS.stepHandshake({ transportMessage: sentTransportMessage, messageNametag: bobMessageNametag });
|
||||||
|
|
||||||
// We prepare a Waku message from Bob's payload2
|
// We prepare a Waku message from Bob's payload2
|
||||||
encoder = new NoiseHandshakeEncoder(contentTopic, bobStep);
|
encoder = new NoiseHandshakeEncoder(contentTopic, PUBSUB_TOPIC, bobStep);
|
||||||
|
|
||||||
// At this point wakuMsg is sent over the Waku network and is received
|
// At this point wakuMsg is sent over the Waku network and is received
|
||||||
// We simulate this by creating the ProtoBuffer from wakuMsg
|
// We simulate this by creating the ProtoBuffer from wakuMsg
|
||||||
wakuMsgBytes = await encoder.toWire({ payload: new Uint8Array() });
|
wakuMsgBytes = await encoder.toWire({ payload: new Uint8Array() });
|
||||||
|
|
||||||
// We decode the WakuMessage from the ProtoBuffer
|
// We decode the WakuMessage from the ProtoBuffer
|
||||||
decoder = new NoiseHandshakeDecoder(contentTopic);
|
decoder = new NoiseHandshakeDecoder(contentTopic, PUBSUB_TOPIC);
|
||||||
wakuMsgProto = await decoder.fromWireToProtoObj(wakuMsgBytes!);
|
wakuMsgProto = await decoder.fromWireToProtoObj(wakuMsgBytes!);
|
||||||
v2Msg = await decoder.fromProtoObj(PUBSUB_TOPIC, wakuMsgProto!);
|
v2Msg = await decoder.fromProtoObj(PUBSUB_TOPIC, wakuMsgProto!);
|
||||||
|
|
||||||
@ -194,14 +194,14 @@ describe("Waku Noise Sessions", () => {
|
|||||||
aliceStep = aliceHS.stepHandshake({ transportMessage: sentTransportMessage, messageNametag: aliceMessageNametag });
|
aliceStep = aliceHS.stepHandshake({ transportMessage: sentTransportMessage, messageNametag: aliceMessageNametag });
|
||||||
|
|
||||||
// We prepare a Waku message from Alice's payload2
|
// We prepare a Waku message from Alice's payload2
|
||||||
encoder = new NoiseHandshakeEncoder(contentTopic, aliceStep);
|
encoder = new NoiseHandshakeEncoder(contentTopic, PUBSUB_TOPIC, aliceStep);
|
||||||
|
|
||||||
// At this point wakuMsg is sent over the Waku network and is received
|
// At this point wakuMsg is sent over the Waku network and is received
|
||||||
// We simulate this by creating the ProtoBuffer from wakuMsg
|
// We simulate this by creating the ProtoBuffer from wakuMsg
|
||||||
wakuMsgBytes = await encoder.toWire({ payload: new Uint8Array() });
|
wakuMsgBytes = await encoder.toWire({ payload: new Uint8Array() });
|
||||||
|
|
||||||
// We decode the WakuMessage from the ProtoBuffer
|
// We decode the WakuMessage from the ProtoBuffer
|
||||||
decoder = new NoiseHandshakeDecoder(contentTopic);
|
decoder = new NoiseHandshakeDecoder(contentTopic, PUBSUB_TOPIC);
|
||||||
wakuMsgProto = await decoder.fromWireToProtoObj(wakuMsgBytes!);
|
wakuMsgProto = await decoder.fromWireToProtoObj(wakuMsgBytes!);
|
||||||
v2Msg = await decoder.fromProtoObj(PUBSUB_TOPIC, wakuMsgProto!);
|
v2Msg = await decoder.fromProtoObj(PUBSUB_TOPIC, wakuMsgProto!);
|
||||||
|
|
||||||
@ -224,11 +224,11 @@ describe("Waku Noise Sessions", () => {
|
|||||||
const aliceHSResult = aliceHS.finalizeHandshake();
|
const aliceHSResult = aliceHS.finalizeHandshake();
|
||||||
const bobHSResult = bobHS.finalizeHandshake();
|
const bobHSResult = bobHS.finalizeHandshake();
|
||||||
|
|
||||||
const aliceEncoder = new NoiseSecureTransferEncoder(contentTopic, aliceHSResult);
|
const aliceEncoder = new NoiseSecureTransferEncoder(contentTopic, PUBSUB_TOPIC, aliceHSResult);
|
||||||
const bobEncoder = new NoiseSecureTransferEncoder(contentTopic, bobHSResult);
|
const bobEncoder = new NoiseSecureTransferEncoder(contentTopic, PUBSUB_TOPIC, bobHSResult);
|
||||||
|
|
||||||
const aliceDecoder = new NoiseSecureTransferDecoder(contentTopic, aliceHSResult);
|
const aliceDecoder = new NoiseSecureTransferDecoder(contentTopic, PUBSUB_TOPIC, aliceHSResult);
|
||||||
const bobDecoder = new NoiseSecureTransferDecoder(contentTopic, bobHSResult);
|
const bobDecoder = new NoiseSecureTransferDecoder(contentTopic, PUBSUB_TOPIC, bobHSResult);
|
||||||
|
|
||||||
// We test read/write of random messages exchanged between Alice and Bob
|
// We test read/write of random messages exchanged between Alice and Bob
|
||||||
// Note that we exchange more than the number of messages contained in the nametag buffer to test if they are filled correctly as the communication proceeds
|
// Note that we exchange more than the number of messages contained in the nametag buffer to test if they are filled correctly as the communication proceeds
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user