mirror of https://github.com/waku-org/js-noise.git
fix tests & remove Sender
This commit is contained in:
parent
9eb817dd68
commit
00d552d659
|
@ -14,7 +14,7 @@ import {
|
|||
StepHandshakeParameters,
|
||||
} from "./handshake.js";
|
||||
import { MessageNametagBuffer } from "./messagenametag.js";
|
||||
import { InitiatorParameters, Responder, ResponderParameters, Sender, WakuPairing } from "./pairing.js";
|
||||
import { InitiatorParameters, Responder, ResponderParameters, WakuPairing } from "./pairing.js";
|
||||
import {
|
||||
HandshakePattern,
|
||||
MessageDirection,
|
||||
|
@ -49,4 +49,4 @@ export { ChaChaPolyCipherState, NoisePublicKey };
|
|||
export { MessageNametagBuffer };
|
||||
export { NoiseHandshakeDecoder, NoiseHandshakeEncoder, NoiseSecureTransferDecoder, NoiseSecureTransferEncoder };
|
||||
export { QR };
|
||||
export { InitiatorParameters, ResponderParameters, Sender, Responder, WakuPairing };
|
||||
export { InitiatorParameters, ResponderParameters, Responder, WakuPairing };
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { HMACDRBG } from "@stablelib/hmac-drbg";
|
||||
import { randomBytes } from "@stablelib/random";
|
||||
import type { IDecoder, IEncoder, IMessage } from "@waku/interfaces";
|
||||
import type { IDecoder, IEncoder, IMessage, ISender } from "@waku/interfaces";
|
||||
import { expect } from "chai";
|
||||
import { EventEmitter } from "eventemitter3";
|
||||
import { pEvent } from "p-event";
|
||||
|
@ -11,6 +11,8 @@ import { generateX25519KeyPair } from "./crypto";
|
|||
import { MessageNametagBufferSize } from "./messagenametag";
|
||||
import { ResponderParameters, WakuPairing } from "./pairing";
|
||||
|
||||
const PUBSUB_TOPIC = "default";
|
||||
|
||||
describe("js-noise: pairing object", () => {
|
||||
const rng = new HMACDRBG();
|
||||
|
||||
|
@ -23,10 +25,13 @@ describe("js-noise: pairing object", () => {
|
|||
// =================
|
||||
// Simulate waku. This code is not meant to be used IRL
|
||||
const msgEmitter = new EventEmitter();
|
||||
const sender = {
|
||||
async publish(encoder: IEncoder, msg: IMessage): Promise<void> {
|
||||
const sender: ISender = {
|
||||
async send(encoder: IEncoder, msg: IMessage) {
|
||||
const protoMsg = await encoder.toProtoObj(msg);
|
||||
msgEmitter.emit(encoder.contentTopic, protoMsg);
|
||||
return {
|
||||
recipients: [],
|
||||
};
|
||||
},
|
||||
};
|
||||
const decoderMap: { [key: string]: IDecoder<NoiseHandshakeMessage> } = {};
|
||||
|
@ -39,7 +44,7 @@ describe("js-noise: pairing object", () => {
|
|||
},
|
||||
async nextMessage(contentTopic: string): Promise<NoiseHandshakeMessage> {
|
||||
const msg = await pEvent(msgEmitter, contentTopic);
|
||||
const decodedMessage = await decoderMap[contentTopic].fromProtoObj(msg);
|
||||
const decodedMessage = await decoderMap[contentTopic].fromProtoObj(PUBSUB_TOPIC, msg);
|
||||
return decodedMessage!;
|
||||
},
|
||||
async stop(contentTopic: string): Promise<void> {
|
||||
|
@ -81,7 +86,7 @@ describe("js-noise: pairing object", () => {
|
|||
let message = randomBytes(32, rng);
|
||||
let encodedMsg = await aliceEncoder.toWire({ payload: message });
|
||||
let readMessageProto = await bobDecoder.fromWireToProtoObj(encodedMsg!);
|
||||
let readMessage = await bobDecoder.fromProtoObj(readMessageProto!);
|
||||
let readMessage = await bobDecoder.fromProtoObj(PUBSUB_TOPIC, readMessageProto!);
|
||||
|
||||
expect(uint8ArrayEquals(message, readMessage!.payload)).to.be.true;
|
||||
|
||||
|
@ -89,7 +94,7 @@ describe("js-noise: pairing object", () => {
|
|||
message = randomBytes(32, rng);
|
||||
encodedMsg = await bobEncoder.toWire({ payload: message });
|
||||
readMessageProto = await aliceDecoder.fromWireToProtoObj(encodedMsg!);
|
||||
readMessage = await aliceDecoder.fromProtoObj(readMessageProto!);
|
||||
readMessage = await aliceDecoder.fromProtoObj(PUBSUB_TOPIC, readMessageProto!);
|
||||
|
||||
expect(uint8ArrayEquals(message, readMessage!.payload)).to.be.true;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ import { NoiseHandshakePatterns } from "./patterns";
|
|||
import { NoisePublicKey } from "./publickey";
|
||||
import { QR } from "./qr";
|
||||
|
||||
const PUBSUB_TOPIC = "default";
|
||||
|
||||
describe("Waku Noise Sessions", () => {
|
||||
const rng = new HMACDRBG();
|
||||
|
||||
|
@ -113,12 +115,12 @@ describe("Waku Noise Sessions", () => {
|
|||
// We prepare a Waku message from Alice's payload2
|
||||
// At this point wakuMsg is sent over the Waku network and is received
|
||||
// We simulate this by creating the ProtoBuffer from wakuMsg
|
||||
let wakuMsgBytes = await encoder.toWire({});
|
||||
let wakuMsgBytes = await encoder.toWire({ payload: new Uint8Array() });
|
||||
|
||||
// We decode the WakuMessage from the ProtoBuffer
|
||||
let decoder = new NoiseHandshakeDecoder(contentTopic);
|
||||
let wakuMsgProto = await decoder.fromWireToProtoObj(wakuMsgBytes!);
|
||||
let v2Msg = await decoder.fromProtoObj(wakuMsgProto!);
|
||||
let v2Msg = await decoder.fromProtoObj(PUBSUB_TOPIC, wakuMsgProto!);
|
||||
|
||||
expect(v2Msg!.contentTopic).to.be.equals(contentTopic);
|
||||
expect(v2Msg?.payloadV2.equals(aliceStep.payload2)).to.be.true;
|
||||
|
@ -155,12 +157,12 @@ describe("Waku Noise Sessions", () => {
|
|||
|
||||
// At this point wakuMsg is sent over the Waku network and is received
|
||||
// We simulate this by creating the ProtoBuffer from wakuMsg
|
||||
wakuMsgBytes = await encoder.toWire({});
|
||||
wakuMsgBytes = await encoder.toWire({ payload: new Uint8Array() });
|
||||
|
||||
// We decode the WakuMessage from the ProtoBuffer
|
||||
decoder = new NoiseHandshakeDecoder(contentTopic);
|
||||
wakuMsgProto = await decoder.fromWireToProtoObj(wakuMsgBytes!);
|
||||
v2Msg = await decoder.fromProtoObj(wakuMsgProto!);
|
||||
v2Msg = await decoder.fromProtoObj(PUBSUB_TOPIC, wakuMsgProto!);
|
||||
|
||||
expect(v2Msg?.payloadV2.equals(bobStep.payload2)).to.be.true;
|
||||
|
||||
|
@ -192,12 +194,12 @@ describe("Waku Noise Sessions", () => {
|
|||
|
||||
// At this point wakuMsg is sent over the Waku network and is received
|
||||
// We simulate this by creating the ProtoBuffer from wakuMsg
|
||||
wakuMsgBytes = await encoder.toWire({});
|
||||
wakuMsgBytes = await encoder.toWire({ payload: new Uint8Array() });
|
||||
|
||||
// We decode the WakuMessage from the ProtoBuffer
|
||||
decoder = new NoiseHandshakeDecoder(contentTopic);
|
||||
wakuMsgProto = await decoder.fromWireToProtoObj(wakuMsgBytes!);
|
||||
v2Msg = await decoder.fromProtoObj(wakuMsgProto!);
|
||||
v2Msg = await decoder.fromProtoObj(PUBSUB_TOPIC, wakuMsgProto!);
|
||||
|
||||
expect(v2Msg?.payloadV2.equals(aliceStep.payload2)).to.be.true;
|
||||
|
||||
|
@ -231,7 +233,7 @@ describe("Waku Noise Sessions", () => {
|
|||
let message = randomBytes(32, rng);
|
||||
let encodedMsg = await aliceEncoder.toWire({ payload: message });
|
||||
let readMessageProto = await bobDecoder.fromWireToProtoObj(encodedMsg!);
|
||||
let readMessage = await bobDecoder.fromProtoObj(readMessageProto!);
|
||||
let readMessage = await bobDecoder.fromProtoObj(PUBSUB_TOPIC, readMessageProto!);
|
||||
|
||||
expect(uint8ArrayEquals(message, readMessage!.payload)).to.be.true;
|
||||
|
||||
|
@ -239,7 +241,7 @@ describe("Waku Noise Sessions", () => {
|
|||
message = randomBytes(32, rng);
|
||||
encodedMsg = await bobEncoder.toWire({ payload: message });
|
||||
readMessageProto = await aliceDecoder.fromWireToProtoObj(encodedMsg!);
|
||||
readMessage = await aliceDecoder.fromProtoObj(readMessageProto!);
|
||||
readMessage = await aliceDecoder.fromProtoObj(PUBSUB_TOPIC, readMessageProto!);
|
||||
|
||||
expect(uint8ArrayEquals(message, readMessage!.payload)).to.be.true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue