Danish Arora 87717981eb
chore: upgrade libp2p and related deps (#1482)
* chore: update noise

* update: package.lock

* update: @chainsafe/libp2p-gossipsub

* rm unwanted libp2p interface deps & bump up libp2p

* refactor code for new deps

* update: new package.lock

* setup prettier, refactor eslint  and rm trailing commas

* update package.lock

* fix build

* import type for interface

* fix imports for merge

* update typedoc exports

* add: CustomEvent import

* use new libp2p interface

* add aegir as dev dep for tests
2023-08-16 20:18:13 +05:30

45 lines
1.1 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) {}
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
*/
encode(): Uint8Array {
return proto.PeerExchangeRPC.encode(this.proto);
}
/**
* Decode the current PeerExchangeRPC request to bytes
* @returns Uint8Array
*/
static decode(bytes: Uint8ArrayList): PeerExchangeRPC {
const res = proto.PeerExchangeRPC.decode(bytes);
return new PeerExchangeRPC(res);
}
get query(): proto.PeerExchangeQuery | undefined {
return this.proto.query;
}
get response(): proto.PeerExchangeResponse | undefined {
return this.proto.response;
}
}