mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-01-23 18:33:12 +00:00
* feat: introduce eslint flag * chore: update logger * chore: update enr * chore: update core * chore: update sdk * chore: update relay * chore: update discovery * chore: update message-encryption * chore: update tests * chore: fix modifiers * chore(tests): fix access modifiers * chore: fix rebase
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { proto_peer_exchange as proto } from "@waku/proto";
|
|
import type { Uint8ArrayList } from "uint8arraylist";
|
|
|
|
/**
|
|
* PeerExchangeRPC represents a message conforming to the Waku Peer Exchange protocol
|
|
*/
|
|
export class PeerExchangeRPC {
|
|
public constructor(public proto: proto.PeerExchangeRPC) {}
|
|
|
|
public static createRequest(
|
|
params: proto.PeerExchangeQuery
|
|
): PeerExchangeRPC {
|
|
const { numPeers } = params;
|
|
return new PeerExchangeRPC({
|
|
query: {
|
|
numPeers: numPeers
|
|
},
|
|
response: undefined
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Encode the current PeerExchangeRPC request to bytes
|
|
* @returns Uint8Array
|
|
*/
|
|
public encode(): Uint8Array {
|
|
return proto.PeerExchangeRPC.encode(this.proto);
|
|
}
|
|
|
|
/**
|
|
* Decode the current PeerExchangeRPC request to bytes
|
|
* @returns Uint8Array
|
|
*/
|
|
public static decode(bytes: Uint8ArrayList): PeerExchangeRPC {
|
|
const res = proto.PeerExchangeRPC.decode(bytes);
|
|
return new PeerExchangeRPC(res);
|
|
}
|
|
|
|
public get query(): proto.PeerExchangeQuery | undefined {
|
|
return this.proto.query;
|
|
}
|
|
|
|
public get response(): proto.PeerExchangeResponse | undefined {
|
|
return this.proto.response;
|
|
}
|
|
}
|