mirror of
https://github.com/logos-messaging/js-noise.git
synced 2026-01-02 05:33:09 +00:00
feat: determine pubsubTopic based on contentTopic
This commit is contained in:
parent
da1f593fb5
commit
3fb88c12dc
1
package-lock.json
generated
1
package-lock.json
generated
@ -17,6 +17,7 @@
|
|||||||
"@stablelib/x25519": "^1.0.1",
|
"@stablelib/x25519": "^1.0.1",
|
||||||
"@waku/core": "0.0.28",
|
"@waku/core": "0.0.28",
|
||||||
"@waku/proto": "0.0.6",
|
"@waku/proto": "0.0.6",
|
||||||
|
"@waku/utils": "^0.0.16",
|
||||||
"bn.js": "^5.2.1",
|
"bn.js": "^5.2.1",
|
||||||
"eventemitter3": "^5.0.0",
|
"eventemitter3": "^5.0.0",
|
||||||
"p-event": "^5.0.1",
|
"p-event": "^5.0.1",
|
||||||
|
|||||||
@ -123,6 +123,7 @@
|
|||||||
"@stablelib/x25519": "^1.0.1",
|
"@stablelib/x25519": "^1.0.1",
|
||||||
"@waku/core": "0.0.28",
|
"@waku/core": "0.0.28",
|
||||||
"@waku/proto": "0.0.6",
|
"@waku/proto": "0.0.6",
|
||||||
|
"@waku/utils": "^0.0.16",
|
||||||
"bn.js": "^5.2.1",
|
"bn.js": "^5.2.1",
|
||||||
"eventemitter3": "^5.0.0",
|
"eventemitter3": "^5.0.0",
|
||||||
"p-event": "^5.0.1",
|
"p-event": "^5.0.1",
|
||||||
@ -130,4 +131,4 @@
|
|||||||
"uint8arraylist": "^2.3.2",
|
"uint8arraylist": "^2.3.2",
|
||||||
"uint8arrays": "^4.0.2"
|
"uint8arrays": "^4.0.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
27
src/codec.ts
27
src/codec.ts
@ -9,6 +9,7 @@ import {
|
|||||||
type IProtoMessage,
|
type IProtoMessage,
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { WakuMessage } from "@waku/proto";
|
import { WakuMessage } from "@waku/proto";
|
||||||
|
import { contentTopicToPubsubTopic } from "@waku/utils";
|
||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
|
|
||||||
import { HandshakeResult, HandshakeStepResult } from "./handshake.js";
|
import { HandshakeResult, HandshakeStepResult } from "./handshake.js";
|
||||||
@ -25,8 +26,6 @@ const version = 2;
|
|||||||
* Used internally in the pairing object to represent a handshake message
|
* Used internally in the pairing object to represent a handshake message
|
||||||
*/
|
*/
|
||||||
export class NoiseHandshakeMessage extends DecodedMessage implements IDecodedMessage {
|
export class NoiseHandshakeMessage extends DecodedMessage implements IDecodedMessage {
|
||||||
pubSubTopic = DefaultPubsubTopic;
|
|
||||||
|
|
||||||
get payloadV2(): PayloadV2 {
|
get payloadV2(): PayloadV2 {
|
||||||
if (!this.payload) throw new Error("no payload available");
|
if (!this.payload) throw new Error("no payload available");
|
||||||
return PayloadV2.deserialize(this.payload);
|
return PayloadV2.deserialize(this.payload);
|
||||||
@ -43,13 +42,15 @@ export class NoiseHandshakeEncoder implements IEncoder {
|
|||||||
* @param hsStepResult the result of a step executed while performing the handshake process
|
* @param hsStepResult the result of a step executed while performing the handshake process
|
||||||
* @param ephemeral makes messages ephemeral in the Waku network
|
* @param ephemeral makes messages ephemeral in the Waku network
|
||||||
*/
|
*/
|
||||||
pubsubTopic = DefaultPubsubTopic;
|
pubsubTopic: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public contentTopic: string,
|
public contentTopic: string,
|
||||||
private hsStepResult: HandshakeStepResult,
|
private hsStepResult: HandshakeStepResult,
|
||||||
public ephemeral: boolean = true
|
public ephemeral: boolean = true
|
||||||
) {}
|
) {
|
||||||
|
this.pubsubTopic = contentTopicToPubsubTopic(contentTopic);
|
||||||
|
}
|
||||||
|
|
||||||
async toWire(message: IMessage): Promise<Uint8Array | undefined> {
|
async toWire(message: IMessage): Promise<Uint8Array | undefined> {
|
||||||
const protoMessage = await this.toProtoObj(message);
|
const protoMessage = await this.toProtoObj(message);
|
||||||
@ -79,9 +80,11 @@ export class NoiseHandshakeDecoder implements IDecoder<NoiseHandshakeMessage> {
|
|||||||
/**
|
/**
|
||||||
* @param contentTopic content topic on which the encoded WakuMessages were sent
|
* @param contentTopic content topic on which the encoded WakuMessages were sent
|
||||||
*/
|
*/
|
||||||
pubsubTopic = DefaultPubsubTopic;
|
pubsubTopic: string;
|
||||||
|
|
||||||
constructor(public contentTopic: string) {}
|
constructor(public contentTopic: string) {
|
||||||
|
this.pubsubTopic = contentTopicToPubsubTopic(contentTopic);
|
||||||
|
}
|
||||||
|
|
||||||
fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined> {
|
fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined> {
|
||||||
const protoMessage = WakuMessage.decode(bytes);
|
const protoMessage = WakuMessage.decode(bytes);
|
||||||
@ -141,14 +144,16 @@ export class NoiseSecureTransferEncoder implements IEncoder {
|
|||||||
* @param ephemeral whether messages should be tagged as ephemeral defaults to true.
|
* @param ephemeral whether messages should be tagged as ephemeral defaults to true.
|
||||||
* @param metaSetter callback function that set the `meta` field.
|
* @param metaSetter callback function that set the `meta` field.
|
||||||
*/
|
*/
|
||||||
pubsubTopic = DefaultPubsubTopic;
|
pubsubTopic: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public contentTopic: string,
|
public contentTopic: string,
|
||||||
private hsResult: HandshakeResult,
|
private hsResult: HandshakeResult,
|
||||||
public ephemeral: boolean = true,
|
public ephemeral: boolean = true,
|
||||||
public metaSetter?: IMetaSetter
|
public metaSetter?: IMetaSetter
|
||||||
) {}
|
) {
|
||||||
|
this.pubsubTopic = contentTopicToPubsubTopic(contentTopic);
|
||||||
|
}
|
||||||
|
|
||||||
async toWire(message: IMessage): Promise<Uint8Array | undefined> {
|
async toWire(message: IMessage): Promise<Uint8Array | undefined> {
|
||||||
const protoMessage = await this.toProtoObj(message);
|
const protoMessage = await this.toProtoObj(message);
|
||||||
@ -197,9 +202,11 @@ export class NoiseSecureTransferDecoder implements IDecoder<NoiseSecureMessage>
|
|||||||
* @param contentTopic content topic on which the encoded WakuMessages were sent
|
* @param contentTopic content topic on which the encoded WakuMessages were sent
|
||||||
* @param hsResult handshake result obtained after the handshake is successful
|
* @param hsResult handshake result obtained after the handshake is successful
|
||||||
*/
|
*/
|
||||||
pubsubTopic = DefaultPubsubTopic;
|
pubsubTopic: string;
|
||||||
|
|
||||||
constructor(public contentTopic: string, private hsResult: HandshakeResult) {}
|
constructor(public contentTopic: string, private hsResult: HandshakeResult) {
|
||||||
|
this.pubsubTopic = contentTopicToPubsubTopic(contentTopic);
|
||||||
|
}
|
||||||
|
|
||||||
fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined> {
|
fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined> {
|
||||||
const protoMessage = WakuMessage.decode(bytes);
|
const protoMessage = WakuMessage.decode(bytes);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user