chore: update dependencies (#1460)

* update to latest prettier

* fix with prettier: added trailing comma

* remove deps from test package, add sinon types, fix type hack in a test, update esling prettier config

* update typescript eslint plugins

* update package-locks
This commit is contained in:
Sasha 2023-08-11 15:14:02 +02:00 committed by GitHub
parent 7227657d69
commit 51f9261a16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
104 changed files with 18699 additions and 26776 deletions

View File

@ -52,13 +52,15 @@
"no-console": "error", "no-console": "error",
"@typescript-eslint/no-floating-promises": "error", "@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/await-thenable": "error", "@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-misused-promises": "error" "@typescript-eslint/no-misused-promises": "error",
"@typescript-eslint/no-explicit-any": "warn"
}, },
"overrides": [ "overrides": [
{ {
"files": ["*.spec.ts", "**/test_utils/*.ts", "*.js", "*.cjs"], "files": ["*.spec.ts", "**/test_utils/*.ts", "*.js", "*.cjs"],
"rules": { "rules": {
"@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-explicit-any": "off",
"no-console": "off" "no-console": "off"
} }
}, },

30068
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -41,21 +41,21 @@
}, },
"devDependencies": { "devDependencies": {
"@size-limit/preset-big-lib": "^8.2.4", "@size-limit/preset-big-lib": "^8.2.4",
"gh-pages": "^5.0.0", "@typescript-eslint/eslint-plugin": "^6.2.1",
"husky": "^8.0.3", "@typescript-eslint/parser": "^6.0.0",
"lint-staged": "^13.2.2",
"size-limit": "^8.1.2",
"typedoc": "^0.23.26",
"typedoc-plugin-resolve-crossmodule-references": "^0.3.3",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.62.0",
"eslint": "^8.41.0", "eslint": "^8.41.0",
"eslint-config-prettier": "^8.6.0", "eslint-config-prettier": "^9.0.0",
"eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-functional": "^5.0.4", "eslint-plugin-functional": "^5.0.4",
"eslint-plugin-import": "^2.27.5", "eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1", "eslint-plugin-prettier": "^5.0.0",
"prettier": "^2.8.8" "gh-pages": "^5.0.0",
"husky": "^8.0.3",
"lint-staged": "^13.2.2",
"prettier": "^3.0.0",
"size-limit": "^8.1.2",
"typedoc": "^0.23.26",
"typedoc-plugin-resolve-crossmodule-references": "^0.3.3"
}, },
"lint-staged": { "lint-staged": {
"*.{ts,js}": [ "*.{ts,js}": [

View File

@ -110,7 +110,6 @@
"karma-webpack": "^5.0.0", "karma-webpack": "^5.0.0",
"mocha": "^10.2.0", "mocha": "^10.2.0",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"process": "^0.11.10", "process": "^0.11.10",
"puppeteer": "^20.4.0", "puppeteer": "^20.4.0",
"rollup": "^3.21.3", "rollup": "^3.21.3",

View File

@ -17,12 +17,15 @@ export class BaseProtocol implements IBaseProtocol {
public readonly addLibp2pEventListener: Libp2p["addEventListener"]; public readonly addLibp2pEventListener: Libp2p["addEventListener"];
public readonly removeLibp2pEventListener: Libp2p["removeEventListener"]; public readonly removeLibp2pEventListener: Libp2p["removeEventListener"];
constructor(public multicodec: string, private components: Libp2pComponents) { constructor(
public multicodec: string,
private components: Libp2pComponents,
) {
this.addLibp2pEventListener = components.events.addEventListener.bind( this.addLibp2pEventListener = components.events.addEventListener.bind(
components.events components.events,
); );
this.removeLibp2pEventListener = components.events.removeEventListener.bind( this.removeLibp2pEventListener = components.events.removeEventListener.bind(
components.events components.events,
); );
} }
@ -43,13 +46,13 @@ export class BaseProtocol implements IBaseProtocol {
const { peer } = await selectPeerForProtocol( const { peer } = await selectPeerForProtocol(
this.peerStore, this.peerStore,
[this.multicodec], [this.multicodec],
peerId peerId,
); );
return peer; return peer;
} }
protected async newStream(peer: Peer): Promise<Stream> { protected async newStream(peer: Peer): Promise<Stream> {
const connections = this.components.connectionManager.getConnections( const connections = this.components.connectionManager.getConnections(
peer.id peer.id,
); );
const connection = selectConnection(connections); const connection = selectConnection(connections);
if (!connection) { if (!connection) {

View File

@ -41,7 +41,7 @@ export class ConnectionManager
libp2p: Libp2p, libp2p: Libp2p,
keepAliveOptions: KeepAliveOptions, keepAliveOptions: KeepAliveOptions,
relay?: IRelay, relay?: IRelay,
options?: ConnectionManagerOptions options?: ConnectionManagerOptions,
): ConnectionManager { ): ConnectionManager {
let instance = ConnectionManager.instances.get(peerId); let instance = ConnectionManager.instances.get(peerId);
if (!instance) { if (!instance) {
@ -49,7 +49,7 @@ export class ConnectionManager
libp2p, libp2p,
keepAliveOptions, keepAliveOptions,
relay, relay,
options options,
); );
ConnectionManager.instances.set(peerId, instance); ConnectionManager.instances.set(peerId, instance);
} }
@ -105,7 +105,7 @@ export class ConnectionManager
libp2p: Libp2p, libp2p: Libp2p,
keepAliveOptions: KeepAliveOptions, keepAliveOptions: KeepAliveOptions,
relay?: IRelay, relay?: IRelay,
options?: Partial<ConnectionManagerOptions> options?: Partial<ConnectionManagerOptions>,
) { ) {
super(); super();
this.libp2p = libp2p; this.libp2p = libp2p;
@ -126,7 +126,7 @@ export class ConnectionManager
// which means that before the ConnectionManager is initialized, some peers may have been discovered // which means that before the ConnectionManager is initialized, some peers may have been discovered
// we will dial the peers in peerStore ONCE before we start to listen to the `peer:discovery` events within the ConnectionManager // we will dial the peers in peerStore ONCE before we start to listen to the `peer:discovery` events within the ConnectionManager
this.dialPeerStorePeers().catch((error) => this.dialPeerStorePeers().catch((error) =>
log(`Unexpected error while dialing peer store peers`, error) log(`Unexpected error while dialing peer store peers`, error),
); );
} }
@ -159,15 +159,15 @@ export class ConnectionManager
this.keepAliveManager.stopAll(); this.keepAliveManager.stopAll();
this.libp2p.removeEventListener( this.libp2p.removeEventListener(
"peer:connect", "peer:connect",
this.onEventHandlers["peer:connect"] this.onEventHandlers["peer:connect"],
); );
this.libp2p.removeEventListener( this.libp2p.removeEventListener(
"peer:disconnect", "peer:disconnect",
this.onEventHandlers["peer:disconnect"] this.onEventHandlers["peer:disconnect"],
); );
this.libp2p.removeEventListener( this.libp2p.removeEventListener(
"peer:discovery", "peer:discovery",
this.onEventHandlers["peer:discovery"] this.onEventHandlers["peer:discovery"],
); );
} }
@ -198,7 +198,7 @@ export class ConnectionManager
log( log(
`Error dialing peer ${peerId.toString()} - ${ `Error dialing peer ${peerId.toString()} - ${
(error as any).message (error as any).message
}` }`,
); );
} }
this.dialErrorsForPeer.set(peerId.toString(), error); this.dialErrorsForPeer.set(peerId.toString(), error);
@ -225,14 +225,14 @@ export class ConnectionManager
} }
log( log(
`Deleting undialable peer ${peerId.toString()} from peer store. Error: ${errorMessage}` `Deleting undialable peer ${peerId.toString()} from peer store. Error: ${errorMessage}`,
); );
this.dialErrorsForPeer.delete(peerId.toString()); this.dialErrorsForPeer.delete(peerId.toString());
await this.libp2p.peerStore.delete(peerId); await this.libp2p.peerStore.delete(peerId);
} catch (error) { } catch (error) {
throw new Error( throw new Error(
`Error deleting undialable peer ${peerId.toString()} from peer store - ${error}` `Error deleting undialable peer ${peerId.toString()} from peer store - ${error}`,
); );
} }
} }
@ -245,7 +245,7 @@ export class ConnectionManager
log(`Dropped connection with peer ${peerId.toString()}`); log(`Dropped connection with peer ${peerId.toString()}`);
} catch (error) { } catch (error) {
log( log(
`Error dropping connection with peer ${peerId.toString()} - ${error}` `Error dropping connection with peer ${peerId.toString()} - ${error}`,
); );
} }
} }
@ -266,14 +266,14 @@ export class ConnectionManager
private startPeerDiscoveryListener(): void { private startPeerDiscoveryListener(): void {
this.libp2p.addEventListener( this.libp2p.addEventListener(
"peer:discovery", "peer:discovery",
this.onEventHandlers["peer:discovery"] this.onEventHandlers["peer:discovery"],
); );
} }
private startPeerConnectionListener(): void { private startPeerConnectionListener(): void {
this.libp2p.addEventListener( this.libp2p.addEventListener(
"peer:connect", "peer:connect",
this.onEventHandlers["peer:connect"] this.onEventHandlers["peer:connect"],
); );
} }
@ -292,7 +292,7 @@ export class ConnectionManager
*/ */
this.libp2p.addEventListener( this.libp2p.addEventListener(
"peer:disconnect", "peer:disconnect",
this.onEventHandlers["peer:disconnect"] this.onEventHandlers["peer:disconnect"],
); );
} }
@ -315,7 +315,7 @@ export class ConnectionManager
const { id: peerId } = evt.detail; const { id: peerId } = evt.detail;
const isBootstrap = (await this.getTagNamesForPeer(peerId)).includes( const isBootstrap = (await this.getTagNamesForPeer(peerId)).includes(
Tags.BOOTSTRAP Tags.BOOTSTRAP,
); );
this.dispatchEvent( this.dispatchEvent(
@ -325,8 +325,8 @@ export class ConnectionManager
: EPeersByDiscoveryEvents.PEER_DISCOVERY_PEER_EXCHANGE, : EPeersByDiscoveryEvents.PEER_DISCOVERY_PEER_EXCHANGE,
{ {
detail: peerId, detail: peerId,
} },
) ),
); );
try { try {
@ -343,7 +343,7 @@ export class ConnectionManager
this.keepAliveManager.start(peerId, this.libp2p.services.ping); this.keepAliveManager.start(peerId, this.libp2p.services.ping);
const isBootstrap = (await this.getTagNamesForPeer(peerId)).includes( const isBootstrap = (await this.getTagNamesForPeer(peerId)).includes(
Tags.BOOTSTRAP Tags.BOOTSTRAP,
); );
if (isBootstrap) { if (isBootstrap) {
@ -362,8 +362,8 @@ export class ConnectionManager
EPeersByDiscoveryEvents.PEER_CONNECT_BOOTSTRAP, EPeersByDiscoveryEvents.PEER_CONNECT_BOOTSTRAP,
{ {
detail: peerId, detail: peerId,
} },
) ),
); );
} }
} else { } else {
@ -372,8 +372,8 @@ export class ConnectionManager
EPeersByDiscoveryEvents.PEER_CONNECT_PEER_EXCHANGE, EPeersByDiscoveryEvents.PEER_CONNECT_PEER_EXCHANGE,
{ {
detail: peerId, detail: peerId,
} },
) ),
); );
} }
})(); })();

View File

@ -35,7 +35,7 @@ export class FilterSubscribeRpc {
static createSubscribeRequest( static createSubscribeRequest(
pubsubTopic: string, pubsubTopic: string,
contentTopics: string[] contentTopics: string[],
): FilterSubscribeRpc { ): FilterSubscribeRpc {
return new FilterSubscribeRpc({ return new FilterSubscribeRpc({
requestId: uuid(), requestId: uuid(),
@ -48,7 +48,7 @@ export class FilterSubscribeRpc {
static createUnsubscribeRequest( static createUnsubscribeRequest(
pubsubTopic: string, pubsubTopic: string,
contentTopics: string[] contentTopics: string[],
): FilterSubscribeRpc { ): FilterSubscribeRpc {
return new FilterSubscribeRpc({ return new FilterSubscribeRpc({
requestId: uuid(), requestId: uuid(),

View File

@ -59,7 +59,7 @@ class Subscription {
constructor( constructor(
pubSubTopic: PubSubTopic, pubSubTopic: PubSubTopic,
remotePeer: Peer, remotePeer: Peer,
newStream: (peer: Peer) => Promise<Stream> newStream: (peer: Peer) => Promise<Stream>,
) { ) {
this.peer = remotePeer; this.peer = remotePeer;
this.pubSubTopic = pubSubTopic; this.pubSubTopic = pubSubTopic;
@ -69,7 +69,7 @@ class Subscription {
async subscribe<T extends IDecodedMessage>( async subscribe<T extends IDecodedMessage>(
decoders: IDecoder<T> | IDecoder<T>[], decoders: IDecoder<T> | IDecoder<T>[],
callback: Callback<T> callback: Callback<T>,
): Promise<void> { ): Promise<void> {
const decodersArray = Array.isArray(decoders) ? decoders : [decoders]; const decodersArray = Array.isArray(decoders) ? decoders : [decoders];
const decodersGroupedByCT = groupByContentTopic(decodersArray); const decodersGroupedByCT = groupByContentTopic(decodersArray);
@ -79,7 +79,7 @@ class Subscription {
const request = FilterSubscribeRpc.createSubscribeRequest( const request = FilterSubscribeRpc.createSubscribeRequest(
this.pubSubTopic, this.pubSubTopic,
contentTopics contentTopics,
); );
try { try {
@ -88,7 +88,7 @@ class Subscription {
lp.encode, lp.encode,
stream, stream,
lp.decode, lp.decode,
async (source) => await all(source) async (source) => await all(source),
); );
const { statusCode, requestId, statusDesc } = const { statusCode, requestId, statusDesc } =
@ -96,7 +96,7 @@ class Subscription {
if (statusCode < 200 || statusCode >= 300) { if (statusCode < 200 || statusCode >= 300) {
throw new Error( throw new Error(
`Filter subscribe request ${requestId} failed with status code ${statusCode}: ${statusDesc}` `Filter subscribe request ${requestId} failed with status code ${statusCode}: ${statusDesc}`,
); );
} }
@ -104,7 +104,7 @@ class Subscription {
"Subscribed to peer ", "Subscribed to peer ",
this.peer.id.toString(), this.peer.id.toString(),
"for content topics", "for content topics",
contentTopics contentTopics,
); );
} catch (e) { } catch (e) {
throw new Error( throw new Error(
@ -113,7 +113,7 @@ class Subscription {
" for content topics: " + " for content topics: " +
contentTopics + contentTopics +
": " + ": " +
e e,
); );
} }
@ -138,7 +138,7 @@ class Subscription {
const stream = await this.newStream(this.peer); const stream = await this.newStream(this.peer);
const unsubscribeRequest = FilterSubscribeRpc.createUnsubscribeRequest( const unsubscribeRequest = FilterSubscribeRpc.createUnsubscribeRequest(
this.pubSubTopic, this.pubSubTopic,
contentTopics contentTopics,
); );
try { try {
@ -163,7 +163,7 @@ class Subscription {
lp.encode, lp.encode,
stream, stream,
lp.decode, lp.decode,
async (source) => await all(source) async (source) => await all(source),
); );
const { statusCode, requestId, statusDesc } = const { statusCode, requestId, statusDesc } =
@ -171,7 +171,7 @@ class Subscription {
if (statusCode < 200 || statusCode >= 300) { if (statusCode < 200 || statusCode >= 300) {
throw new Error( throw new Error(
`Filter ping request ${requestId} failed with status code ${statusCode}: ${statusDesc}` `Filter ping request ${requestId} failed with status code ${statusCode}: ${statusDesc}`,
); );
} }
@ -186,7 +186,7 @@ class Subscription {
const stream = await this.newStream(this.peer); const stream = await this.newStream(this.peer);
const request = FilterSubscribeRpc.createUnsubscribeAllRequest( const request = FilterSubscribeRpc.createUnsubscribeAllRequest(
this.pubSubTopic this.pubSubTopic,
); );
try { try {
@ -195,7 +195,7 @@ class Subscription {
lp.encode, lp.encode,
stream, stream,
lp.decode, lp.decode,
async (source) => await all(source) async (source) => await all(source),
); );
const { statusCode, requestId, statusDesc } = const { statusCode, requestId, statusDesc } =
@ -203,7 +203,7 @@ class Subscription {
if (statusCode < 200 || statusCode >= 300) { if (statusCode < 200 || statusCode >= 300) {
throw new Error( throw new Error(
`Filter unsubscribe all request ${requestId} failed with status code ${statusCode}: ${statusDesc}` `Filter unsubscribe all request ${requestId} failed with status code ${statusCode}: ${statusDesc}`,
); );
} }
@ -231,7 +231,7 @@ class Filter extends BaseProtocol implements IReceiver {
private getActiveSubscription( private getActiveSubscription(
pubSubTopic: PubSubTopic, pubSubTopic: PubSubTopic,
peerIdStr: PeerIdStr peerIdStr: PeerIdStr,
): Subscription | undefined { ): Subscription | undefined {
return this.activeSubscriptions.get(`${pubSubTopic}_${peerIdStr}`); return this.activeSubscriptions.get(`${pubSubTopic}_${peerIdStr}`);
} }
@ -239,7 +239,7 @@ class Filter extends BaseProtocol implements IReceiver {
private setActiveSubscription( private setActiveSubscription(
pubSubTopic: PubSubTopic, pubSubTopic: PubSubTopic,
peerIdStr: PeerIdStr, peerIdStr: PeerIdStr,
subscription: Subscription subscription: Subscription,
): Subscription { ): Subscription {
this.activeSubscriptions.set(`${pubSubTopic}_${peerIdStr}`, subscription); this.activeSubscriptions.set(`${pubSubTopic}_${peerIdStr}`, subscription);
return subscription; return subscription;
@ -259,7 +259,7 @@ class Filter extends BaseProtocol implements IReceiver {
async createSubscription( async createSubscription(
pubSubTopic?: string, pubSubTopic?: string,
peerId?: PeerId peerId?: PeerId,
): Promise<Subscription> { ): Promise<Subscription> {
const _pubSubTopic = const _pubSubTopic =
pubSubTopic ?? this.options.pubSubTopic ?? DefaultPubSubTopic; pubSubTopic ?? this.options.pubSubTopic ?? DefaultPubSubTopic;
@ -271,7 +271,7 @@ class Filter extends BaseProtocol implements IReceiver {
this.setActiveSubscription( this.setActiveSubscription(
_pubSubTopic, _pubSubTopic,
peer.id.toString(), peer.id.toString(),
new Subscription(_pubSubTopic, peer, this.newStream.bind(this, peer)) new Subscription(_pubSubTopic, peer, this.newStream.bind(this, peer)),
); );
return subscription; return subscription;
@ -279,7 +279,7 @@ class Filter extends BaseProtocol implements IReceiver {
public toSubscriptionIterator<T extends IDecodedMessage>( public toSubscriptionIterator<T extends IDecodedMessage>(
decoders: IDecoder<T> | IDecoder<T>[], decoders: IDecoder<T> | IDecoder<T>[],
opts?: ProtocolOptions | undefined opts?: ProtocolOptions | undefined,
): Promise<IAsyncIterator<T>> { ): Promise<IAsyncIterator<T>> {
return toAsyncIterator(this, decoders, opts); return toAsyncIterator(this, decoders, opts);
} }
@ -302,7 +302,7 @@ class Filter extends BaseProtocol implements IReceiver {
async subscribe<T extends IDecodedMessage>( async subscribe<T extends IDecodedMessage>(
decoders: IDecoder<T> | IDecoder<T>[], decoders: IDecoder<T> | IDecoder<T>[],
callback: Callback<T>, callback: Callback<T>,
opts?: ProtocolOptions opts?: ProtocolOptions,
): Promise<Unsubscribe> { ): Promise<Unsubscribe> {
const subscription = await this.createSubscription(undefined, opts?.peerId); const subscription = await this.createSubscription(undefined, opts?.peerId);
@ -310,8 +310,8 @@ class Filter extends BaseProtocol implements IReceiver {
const contentTopics = Array.from( const contentTopics = Array.from(
groupByContentTopic( groupByContentTopic(
Array.isArray(decoders) ? decoders : [decoders] Array.isArray(decoders) ? decoders : [decoders],
).keys() ).keys(),
); );
return async () => { return async () => {
@ -341,7 +341,7 @@ class Filter extends BaseProtocol implements IReceiver {
const peerIdStr = streamData.connection.remotePeer.toString(); const peerIdStr = streamData.connection.remotePeer.toString();
const subscription = this.getActiveSubscription( const subscription = this.getActiveSubscription(
pubsubTopic, pubsubTopic,
peerIdStr peerIdStr,
); );
if (!subscription) { if (!subscription) {
@ -357,7 +357,7 @@ class Filter extends BaseProtocol implements IReceiver {
}, },
(e) => { (e) => {
log("Error with receiving pipe", e); log("Error with receiving pipe", e);
} },
); );
} catch (e) { } catch (e) {
log("Error decoding message", e); log("Error decoding message", e);
@ -366,7 +366,7 @@ class Filter extends BaseProtocol implements IReceiver {
} }
export function wakuFilter( export function wakuFilter(
init: Partial<ProtocolCreateOptions> = {} init: Partial<ProtocolCreateOptions> = {},
): (libp2p: Libp2p) => IFilter { ): (libp2p: Libp2p) => IFilter {
return (libp2p: Libp2p) => new Filter(libp2p, init); return (libp2p: Libp2p) => new Filter(libp2p, init);
} }
@ -374,7 +374,7 @@ export function wakuFilter(
async function pushMessage<T extends IDecodedMessage>( async function pushMessage<T extends IDecodedMessage>(
subscriptionCallback: SubscriptionCallback<T>, subscriptionCallback: SubscriptionCallback<T>,
pubSubTopic: PubSubTopic, pubSubTopic: PubSubTopic,
message: WakuMessage message: WakuMessage,
): Promise<void> { ): Promise<void> {
const { decoders, callback } = subscriptionCallback; const { decoders, callback } = subscriptionCallback;
@ -388,7 +388,7 @@ async function pushMessage<T extends IDecodedMessage>(
const decodePromises = decoders.map((dec) => const decodePromises = decoders.map((dec) =>
dec dec
.fromProtoObj(pubSubTopic, message as IProtoMessage) .fromProtoObj(pubSubTopic, message as IProtoMessage)
.then((decoded) => decoded || Promise.reject("Decoding failed")) .then((decoded) => decoded || Promise.reject("Decoding failed")),
); );
const decodedMessage = await Promise.any(decodePromises); const decodedMessage = await Promise.any(decodePromises);

View File

@ -41,7 +41,7 @@ class LightPush extends BaseProtocol implements ILightPush {
async send( async send(
encoder: IEncoder, encoder: IEncoder,
message: IMessage, message: IMessage,
opts?: ProtocolOptions opts?: ProtocolOptions,
): Promise<SendResult> { ): Promise<SendResult> {
const { pubSubTopic = DefaultPubSubTopic } = this.options; const { pubSubTopic = DefaultPubSubTopic } = this.options;
@ -74,7 +74,7 @@ class LightPush extends BaseProtocol implements ILightPush {
lp.encode, lp.encode,
stream, stream,
lp.decode, lp.decode,
async (source) => await all(source) async (source) => await all(source),
); );
try { try {
const bytes = new Uint8ArrayList(); const bytes = new Uint8ArrayList();
@ -106,7 +106,7 @@ class LightPush extends BaseProtocol implements ILightPush {
} }
export function wakuLightPush( export function wakuLightPush(
init: Partial<ProtocolCreateOptions> = {} init: Partial<ProtocolCreateOptions> = {},
): (libp2p: Libp2p) => ILightPush { ): (libp2p: Libp2p) => ILightPush {
return (libp2p: Libp2p) => new LightPush(libp2p, init); return (libp2p: Libp2p) => new LightPush(libp2p, init);
} }

View File

@ -7,7 +7,7 @@ export class PushRpc {
static createRequest( static createRequest(
message: proto.WakuMessage, message: proto.WakuMessage,
pubSubTopic: string pubSubTopic: string,
): PushRpc { ): PushRpc {
return new PushRpc({ return new PushRpc({
requestId: uuid(), requestId: uuid(),

View File

@ -20,7 +20,7 @@ describe("Waku Message version 0", function () {
const protoResult = await decoder.fromWireToProtoObj(bytes); const protoResult = await decoder.fromWireToProtoObj(bytes);
const result = (await decoder.fromProtoObj( const result = (await decoder.fromProtoObj(
pubSubTopic, pubSubTopic,
protoResult! protoResult!,
)) as DecodedMessage; )) as DecodedMessage;
expect(result.contentTopic).to.eq(contentTopic); expect(result.contentTopic).to.eq(contentTopic);
@ -29,8 +29,8 @@ describe("Waku Message version 0", function () {
expect(result.ephemeral).to.be.false; expect(result.ephemeral).to.be.false;
expect(result.payload).to.deep.eq(payload); expect(result.payload).to.deep.eq(payload);
expect(result.timestamp).to.not.be.undefined; expect(result.timestamp).to.not.be.undefined;
} },
) ),
); );
}); });
@ -50,12 +50,12 @@ describe("Waku Message version 0", function () {
const protoResult = await decoder.fromWireToProtoObj(bytes); const protoResult = await decoder.fromWireToProtoObj(bytes);
const result = (await decoder.fromProtoObj( const result = (await decoder.fromProtoObj(
pubSubTopic, pubSubTopic,
protoResult! protoResult!,
)) as DecodedMessage; )) as DecodedMessage;
expect(result.ephemeral).to.be.true; expect(result.ephemeral).to.be.true;
} },
) ),
); );
}); });
@ -69,7 +69,7 @@ describe("Waku Message version 0", function () {
// Encode the length of the payload // Encode the length of the payload
// Not a relevant real life example // Not a relevant real life example
const metaSetter = ( const metaSetter = (
msg: IProtoMessage & { meta: undefined } msg: IProtoMessage & { meta: undefined },
): Uint8Array => { ): Uint8Array => {
const buffer = new ArrayBuffer(4); const buffer = new ArrayBuffer(4);
const view = new DataView(buffer); const view = new DataView(buffer);
@ -87,7 +87,7 @@ describe("Waku Message version 0", function () {
const protoResult = await decoder.fromWireToProtoObj(bytes); const protoResult = await decoder.fromWireToProtoObj(bytes);
const result = (await decoder.fromProtoObj( const result = (await decoder.fromProtoObj(
pubSubTopic, pubSubTopic,
protoResult! protoResult!,
)) as DecodedMessage; )) as DecodedMessage;
const expectedMeta = metaSetter({ const expectedMeta = metaSetter({
@ -101,8 +101,8 @@ describe("Waku Message version 0", function () {
}); });
expect(result.meta).to.deep.eq(expectedMeta); expect(result.meta).to.deep.eq(expectedMeta);
} },
) ),
); );
}); });
}); });

View File

@ -18,7 +18,10 @@ export const Version = 0;
export { proto }; export { proto };
export class DecodedMessage implements IDecodedMessage { export class DecodedMessage implements IDecodedMessage {
constructor(public pubSubTopic: string, protected proto: proto.WakuMessage) {} constructor(
public pubSubTopic: string,
protected proto: proto.WakuMessage,
) {}
get ephemeral(): boolean { get ephemeral(): boolean {
return Boolean(this.proto.ephemeral); return Boolean(this.proto.ephemeral);
@ -70,7 +73,7 @@ export class Encoder implements IEncoder {
constructor( constructor(
public contentTopic: string, public contentTopic: string,
public ephemeral: boolean = false, public ephemeral: boolean = false,
public metaSetter?: IMetaSetter public metaSetter?: IMetaSetter,
) { ) {
if (!contentTopic || contentTopic === "") { if (!contentTopic || contentTopic === "") {
throw new Error("Content topic must be specified"); throw new Error("Content topic must be specified");
@ -143,7 +146,7 @@ export class Decoder implements IDecoder<DecodedMessage> {
async fromProtoObj( async fromProtoObj(
pubSubTopic: string, pubSubTopic: string,
proto: IProtoMessage proto: IProtoMessage,
): Promise<DecodedMessage | undefined> { ): Promise<DecodedMessage | undefined> {
// https://rfc.vac.dev/spec/14/ // https://rfc.vac.dev/spec/14/
// > If omitted, the value SHOULD be interpreted as version 0. // > If omitted, the value SHOULD be interpreted as version 0.
@ -152,7 +155,7 @@ export class Decoder implements IDecoder<DecodedMessage> {
"Failed to decode due to incorrect version, expected:", "Failed to decode due to incorrect version, expected:",
Version, Version,
", actual:", ", actual:",
proto.version proto.version,
); );
return Promise.resolve(undefined); return Promise.resolve(undefined);
} }

View File

@ -19,7 +19,7 @@ export enum Fleet {
*/ */
export function getPredefinedBootstrapNodes( export function getPredefinedBootstrapNodes(
fleet: Fleet = Fleet.Prod, fleet: Fleet = Fleet.Prod,
wantedNumber: number = DefaultWantedNumber wantedNumber: number = DefaultWantedNumber,
): string[] { ): string[] {
if (wantedNumber <= 0) { if (wantedNumber <= 0) {
return []; return [];

View File

@ -1,7 +1,7 @@
export function pushOrInitMapSet<K, V>( export function pushOrInitMapSet<K, V>(
map: Map<K, Set<V>>, map: Map<K, Set<V>>,
key: K, key: K,
newValue: V newValue: V,
): void { ): void {
let arr = map.get(key); let arr = map.get(key);
if (typeof arr === "undefined") { if (typeof arr === "undefined") {

View File

@ -80,7 +80,7 @@ export class HistoryRpc {
} }
function directionToProto( function directionToProto(
pageDirection: PageDirection pageDirection: PageDirection,
): proto.PagingInfo.Direction { ): proto.PagingInfo.Direction {
switch (pageDirection) { switch (pageDirection) {
case PageDirection.BACKWARD: case PageDirection.BACKWARD:

View File

@ -106,7 +106,7 @@ class Store extends BaseProtocol implements IStore {
async queryOrderedCallback<T extends IDecodedMessage>( async queryOrderedCallback<T extends IDecodedMessage>(
decoders: IDecoder<T>[], decoders: IDecoder<T>[],
callback: (message: T) => Promise<void | boolean> | boolean | void, callback: (message: T) => Promise<void | boolean> | boolean | void,
options?: QueryOptions options?: QueryOptions,
): Promise<void> { ): Promise<void> {
let abort = false; let abort = false;
for await (const promises of this.queryGenerator(decoders, options)) { for await (const promises of this.queryGenerator(decoders, options)) {
@ -129,7 +129,7 @@ class Store extends BaseProtocol implements IStore {
if (msg && !abort) { if (msg && !abort) {
abort = Boolean(await callback(msg)); abort = Boolean(await callback(msg));
} }
}) }),
); );
} }
} }
@ -155,9 +155,9 @@ class Store extends BaseProtocol implements IStore {
async queryCallbackOnPromise<T extends IDecodedMessage>( async queryCallbackOnPromise<T extends IDecodedMessage>(
decoders: IDecoder<T>[], decoders: IDecoder<T>[],
callback: ( callback: (
message: Promise<T | undefined> message: Promise<T | undefined>,
) => Promise<void | boolean> | boolean | void, ) => Promise<void | boolean> | boolean | void,
options?: QueryOptions options?: QueryOptions,
): Promise<void> { ): Promise<void> {
let abort = false; let abort = false;
let promises: Promise<void>[] = []; let promises: Promise<void>[] = [];
@ -192,7 +192,7 @@ class Store extends BaseProtocol implements IStore {
*/ */
async *queryGenerator<T extends IDecodedMessage>( async *queryGenerator<T extends IDecodedMessage>(
decoders: IDecoder<T>[], decoders: IDecoder<T>[],
options?: QueryOptions options?: QueryOptions,
): AsyncGenerator<Promise<T | undefined>[]> { ): AsyncGenerator<Promise<T | undefined>[]> {
const { pubSubTopic = DefaultPubSubTopic } = this.options; const { pubSubTopic = DefaultPubSubTopic } = this.options;
@ -207,7 +207,7 @@ class Store extends BaseProtocol implements IStore {
decoders.forEach((dec) => { decoders.forEach((dec) => {
if (decodersAsMap.has(dec.contentTopic)) { if (decodersAsMap.has(dec.contentTopic)) {
throw new Error( throw new Error(
"API does not support different decoder per content topic" "API does not support different decoder per content topic",
); );
} }
decodersAsMap.set(dec.contentTopic, dec); decodersAsMap.set(dec.contentTopic, dec);
@ -222,7 +222,7 @@ class Store extends BaseProtocol implements IStore {
pageSize: DefaultPageSize, pageSize: DefaultPageSize,
}, },
options, options,
{ contentTopics, startTime, endTime } { contentTopics, startTime, endTime },
); );
log("Querying history with the following options", { log("Querying history with the following options", {
@ -236,7 +236,7 @@ class Store extends BaseProtocol implements IStore {
this.newStream.bind(this, peer), this.newStream.bind(this, peer),
queryOpts, queryOpts,
decodersAsMap, decodersAsMap,
options?.cursor options?.cursor,
)) { )) {
yield messages; yield messages;
} }
@ -247,14 +247,14 @@ async function* paginate<T extends IDecodedMessage>(
streamFactory: () => Promise<Stream>, streamFactory: () => Promise<Stream>,
queryOpts: Params, queryOpts: Params,
decoders: Map<string, IDecoder<T>>, decoders: Map<string, IDecoder<T>>,
cursor?: Cursor cursor?: Cursor,
): AsyncGenerator<Promise<T | undefined>[]> { ): AsyncGenerator<Promise<T | undefined>[]> {
if ( if (
queryOpts.contentTopics.toString() !== queryOpts.contentTopics.toString() !==
Array.from(decoders.keys()).toString() Array.from(decoders.keys()).toString()
) { ) {
throw new Error( throw new Error(
"Internal error, the decoders should match the query's content topics" "Internal error, the decoders should match the query's content topics",
); );
} }
@ -267,7 +267,7 @@ async function* paginate<T extends IDecodedMessage>(
log( log(
"Querying store peer", "Querying store peer",
`for (${queryOpts.pubSubTopic})`, `for (${queryOpts.pubSubTopic})`,
queryOpts.contentTopics queryOpts.contentTopics,
); );
const stream = await streamFactory(); const stream = await streamFactory();
@ -277,7 +277,7 @@ async function* paginate<T extends IDecodedMessage>(
lp.encode, lp.encode,
stream, stream,
lp.decode, lp.decode,
async (source) => await all(source) async (source) => await all(source),
); );
const bytes = new Uint8ArrayList(); const bytes = new Uint8ArrayList();
@ -300,7 +300,7 @@ async function* paginate<T extends IDecodedMessage>(
if (!response.messages || !response.messages.length) { if (!response.messages || !response.messages.length) {
log( log(
"Stopping pagination due to store `response.messages` field missing or empty" "Stopping pagination due to store `response.messages` field missing or empty",
); );
break; break;
} }
@ -314,7 +314,7 @@ async function* paginate<T extends IDecodedMessage>(
if (decoder) { if (decoder) {
return decoder.fromProtoObj( return decoder.fromProtoObj(
queryOpts.pubSubTopic, queryOpts.pubSubTopic,
toProtoMessage(protoMsg) toProtoMessage(protoMsg),
); );
} }
} }
@ -326,7 +326,7 @@ async function* paginate<T extends IDecodedMessage>(
// If the server does not return cursor then there is an issue, // If the server does not return cursor then there is an issue,
// Need to abort, or we end up in an infinite loop // Need to abort, or we end up in an infinite loop
log( log(
"Stopping pagination due to `response.pagingInfo.cursor` missing from store response" "Stopping pagination due to `response.pagingInfo.cursor` missing from store response",
); );
break; break;
} }
@ -348,7 +348,7 @@ async function* paginate<T extends IDecodedMessage>(
export async function createCursor( export async function createCursor(
message: IDecodedMessage, message: IDecodedMessage,
pubsubTopic: string = DefaultPubSubTopic pubsubTopic: string = DefaultPubSubTopic,
): Promise<Cursor> { ): Promise<Cursor> {
if ( if (
!message || !message ||
@ -374,7 +374,7 @@ export async function createCursor(
} }
export function wakuStore( export function wakuStore(
init: Partial<ProtocolCreateOptions> = {} init: Partial<ProtocolCreateOptions> = {},
): (libp2p: Libp2p) => IStore { ): (libp2p: Libp2p) => IStore {
return (libp2p: Libp2p) => new Store(libp2p, init); return (libp2p: Libp2p) => new Store(libp2p, init);
} }

View File

@ -28,7 +28,7 @@ const log = debug("waku:wait-for-remote-peer");
export async function waitForRemotePeer( export async function waitForRemotePeer(
waku: Waku, waku: Waku,
protocols?: Protocols[], protocols?: Protocols[],
timeoutMs?: number timeoutMs?: number,
): Promise<void> { ): Promise<void> {
protocols = protocols ?? getEnabledProtocols(waku); protocols = protocols ?? getEnabledProtocols(waku);
@ -64,7 +64,7 @@ export async function waitForRemotePeer(
await rejectOnTimeout( await rejectOnTimeout(
Promise.all(promises), Promise.all(promises),
timeoutMs, timeoutMs,
"Timed out waiting for a remote peer." "Timed out waiting for a remote peer.",
); );
} else { } else {
await Promise.all(promises); await Promise.all(promises);
@ -114,7 +114,7 @@ const awaitTimeout = (ms: number, rejectReason: string): Promise<void> =>
async function rejectOnTimeout<T>( async function rejectOnTimeout<T>(
promise: Promise<T>, promise: Promise<T>,
timeoutMs: number, timeoutMs: number,
rejectReason: string rejectReason: string,
): Promise<void> { ): Promise<void> {
await Promise.race([promise, awaitTimeout(timeoutMs, rejectReason)]); await Promise.race([promise, awaitTimeout(timeoutMs, rejectReason)]);
} }

View File

@ -56,7 +56,7 @@ export class WakuNode implements Waku {
store?: (libp2p: Libp2p) => IStore, store?: (libp2p: Libp2p) => IStore,
lightPush?: (libp2p: Libp2p) => ILightPush, lightPush?: (libp2p: Libp2p) => ILightPush,
filter?: (libp2p: Libp2p) => IFilter, filter?: (libp2p: Libp2p) => IFilter,
relay?: (libp2p: Libp2p) => IRelay relay?: (libp2p: Libp2p) => IRelay,
) { ) {
this.libp2p = libp2p; this.libp2p = libp2p;
@ -86,14 +86,14 @@ export class WakuNode implements Waku {
peerId, peerId,
libp2p, libp2p,
{ pingKeepAlive, relayKeepAlive }, { pingKeepAlive, relayKeepAlive },
this.relay this.relay,
); );
log( log(
"Waku node created", "Waku node created",
peerId, peerId,
`relay: ${!!this.relay}, store: ${!!this.store}, light push: ${!!this `relay: ${!!this.relay}, store: ${!!this.store}, light push: ${!!this
.lightPush}, filter: ${!!this.filter}` .lightPush}, filter: ${!!this.filter}`,
); );
} }
@ -105,7 +105,7 @@ export class WakuNode implements Waku {
*/ */
async dial( async dial(
peer: PeerId | MultiaddrInput, peer: PeerId | MultiaddrInput,
protocols?: Protocols[] protocols?: Protocols[],
): Promise<Stream> { ): Promise<Stream> {
const _protocols = protocols ?? []; const _protocols = protocols ?? [];
const peerId = mapToPeerIdOrMultiaddr(peer); const peerId = mapToPeerIdOrMultiaddr(peer);
@ -121,11 +121,11 @@ export class WakuNode implements Waku {
if (_protocols.includes(Protocols.Relay)) { if (_protocols.includes(Protocols.Relay)) {
if (this.relay) { if (this.relay) {
this.relay.gossipSub.multicodecs.forEach((codec: string) => this.relay.gossipSub.multicodecs.forEach((codec: string) =>
codecs.push(codec) codecs.push(codec),
); );
} else { } else {
log( log(
"Relay codec not included in dial codec: protocol not mounted locally" "Relay codec not included in dial codec: protocol not mounted locally",
); );
} }
} }
@ -134,7 +134,7 @@ export class WakuNode implements Waku {
codecs.push(this.store.multicodec); codecs.push(this.store.multicodec);
} else { } else {
log( log(
"Store codec not included in dial codec: protocol not mounted locally" "Store codec not included in dial codec: protocol not mounted locally",
); );
} }
} }
@ -143,7 +143,7 @@ export class WakuNode implements Waku {
codecs.push(this.lightPush.multicodec); codecs.push(this.lightPush.multicodec);
} else { } else {
log( log(
"Light Push codec not included in dial codec: protocol not mounted locally" "Light Push codec not included in dial codec: protocol not mounted locally",
); );
} }
} }
@ -152,7 +152,7 @@ export class WakuNode implements Waku {
codecs.push(this.filter.multicodec); codecs.push(this.filter.multicodec);
} else { } else {
log( log(
"Filter codec not included in dial codec: protocol not mounted locally" "Filter codec not included in dial codec: protocol not mounted locally",
); );
} }
} }
@ -191,7 +191,7 @@ export class WakuNode implements Waku {
} }
} }
function mapToPeerIdOrMultiaddr( function mapToPeerIdOrMultiaddr(
peerId: PeerId | MultiaddrInput peerId: PeerId | MultiaddrInput,
): PeerId | Multiaddr { ): PeerId | Multiaddr {
return isPeerId(peerId) ? peerId : multiaddr(peerId); return isPeerId(peerId) ? peerId : multiaddr(peerId);
} }

View File

@ -80,7 +80,6 @@
"karma-webpack": "^5.0.0", "karma-webpack": "^5.0.0",
"mocha": "^10.2.0", "mocha": "^10.2.0",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"rollup": "^3.21.3", "rollup": "^3.21.3",
"ts-loader": "^9.4.2", "ts-loader": "^9.4.2",
"typescript": "^5.0.4" "typescript": "^5.0.4"

View File

@ -174,7 +174,7 @@ describe("DNS Node Discovery w/ capabilities", () => {
expect(peers.length).to.eq(1); expect(peers.length).to.eq(1);
expect(peers[0].peerId?.toString()).to.eq( expect(peers[0].peerId?.toString()).to.eq(
"16Uiu2HAmPsYLvfKafxgRsb6tioYyGnSvGXS2iuMigptHrqHPNPzx" "16Uiu2HAmPsYLvfKafxgRsb6tioYyGnSvGXS2iuMigptHrqHPNPzx",
); );
}); });
@ -189,7 +189,7 @@ describe("DNS Node Discovery w/ capabilities", () => {
expect(peers.length).to.eq(1); expect(peers.length).to.eq(1);
expect(peers[0].peerId?.toString()).to.eq( expect(peers[0].peerId?.toString()).to.eq(
"16Uiu2HAm2HyS6brcCspSbszG9i36re2bWBVjMe3tMdnFp1Hua34F" "16Uiu2HAm2HyS6brcCspSbszG9i36re2bWBVjMe3tMdnFp1Hua34F",
); );
}); });
@ -203,7 +203,7 @@ describe("DNS Node Discovery w/ capabilities", () => {
expect(peers.length).to.eq(1); expect(peers.length).to.eq(1);
expect(peers[0].peerId?.toString()).to.eq( expect(peers[0].peerId?.toString()).to.eq(
"16Uiu2HAkv3La3ECgQpdYeEJfrX36EWdhkUDv4C9wvXM8TFZ9dNgd" "16Uiu2HAkv3La3ECgQpdYeEJfrX36EWdhkUDv4C9wvXM8TFZ9dNgd",
); );
}); });
@ -224,10 +224,10 @@ describe("DNS Node Discovery w/ capabilities", () => {
expect(peers.length).to.eq(2); expect(peers.length).to.eq(2);
const peerIds = peers.map((p) => p.peerId?.toString()); const peerIds = peers.map((p) => p.peerId?.toString());
expect(peerIds).to.contain( expect(peerIds).to.contain(
"16Uiu2HAm2HyS6brcCspSbszG9i36re2bWBVjMe3tMdnFp1Hua34F" "16Uiu2HAm2HyS6brcCspSbszG9i36re2bWBVjMe3tMdnFp1Hua34F",
); );
expect(peerIds).to.contain( expect(peerIds).to.contain(
"16Uiu2HAmPsYLvfKafxgRsb6tioYyGnSvGXS2iuMigptHrqHPNPzx" "16Uiu2HAmPsYLvfKafxgRsb6tioYyGnSvGXS2iuMigptHrqHPNPzx",
); );
}); });
@ -250,13 +250,13 @@ describe("DNS Node Discovery w/ capabilities", () => {
expect(peers.length).to.eq(3); expect(peers.length).to.eq(3);
const peerIds = peers.map((p) => p.peerId?.toString()); const peerIds = peers.map((p) => p.peerId?.toString());
expect(peerIds).to.contain( expect(peerIds).to.contain(
"16Uiu2HAm2HyS6brcCspSbszG9i36re2bWBVjMe3tMdnFp1Hua34F" "16Uiu2HAm2HyS6brcCspSbszG9i36re2bWBVjMe3tMdnFp1Hua34F",
); );
expect(peerIds).to.contain( expect(peerIds).to.contain(
"16Uiu2HAmPsYLvfKafxgRsb6tioYyGnSvGXS2iuMigptHrqHPNPzx" "16Uiu2HAmPsYLvfKafxgRsb6tioYyGnSvGXS2iuMigptHrqHPNPzx",
); );
expect(peerIds).to.contain( expect(peerIds).to.contain(
"16Uiu2HAkv3La3ECgQpdYeEJfrX36EWdhkUDv4C9wvXM8TFZ9dNgd" "16Uiu2HAkv3La3ECgQpdYeEJfrX36EWdhkUDv4C9wvXM8TFZ9dNgd",
); );
}); });
}); });

View File

@ -34,7 +34,7 @@ export class DnsNodeDiscovery {
private readonly _errorTolerance: number = 10; private readonly _errorTolerance: number = 10;
public static async dnsOverHttp( public static async dnsOverHttp(
dnsClient?: DnsClient dnsClient?: DnsClient,
): Promise<DnsNodeDiscovery> { ): Promise<DnsNodeDiscovery> {
if (!dnsClient) { if (!dnsClient) {
dnsClient = await DnsOverHttps.create(); dnsClient = await DnsOverHttps.create();
@ -51,7 +51,7 @@ export class DnsNodeDiscovery {
*/ */
async getPeers( async getPeers(
enrTreeUrls: string[], enrTreeUrls: string[],
wantedNodeCapabilityCount: Partial<NodeCapabilityCount> wantedNodeCapabilityCount: Partial<NodeCapabilityCount>,
): Promise<IEnr[]> { ): Promise<IEnr[]> {
const networkIndex = Math.floor(Math.random() * enrTreeUrls.length); const networkIndex = Math.floor(Math.random() * enrTreeUrls.length);
const { publicKey, domain } = ENRTree.parseTree(enrTreeUrls[networkIndex]); const { publicKey, domain } = ENRTree.parseTree(enrTreeUrls[networkIndex]);
@ -64,7 +64,7 @@ export class DnsNodeDiscovery {
const peers = await fetchNodesUntilCapabilitiesFulfilled( const peers = await fetchNodesUntilCapabilitiesFulfilled(
wantedNodeCapabilityCount, wantedNodeCapabilityCount,
this._errorTolerance, this._errorTolerance,
() => this._search(domain, context) () => this._search(domain, context),
); );
log( log(
"retrieved peers: ", "retrieved peers: ",
@ -73,7 +73,7 @@ export class DnsNodeDiscovery {
id: peer.peerId?.toString(), id: peer.peerId?.toString(),
multiaddrs: peer.multiaddrs?.map((ma) => ma.toString()), multiaddrs: peer.multiaddrs?.map((ma) => ma.toString()),
}; };
}) }),
); );
return peers; return peers;
} }
@ -88,7 +88,7 @@ export class DnsNodeDiscovery {
*/ */
async *getNextPeer( async *getNextPeer(
enrTreeUrls: string[], enrTreeUrls: string[],
wantedNodeCapabilityCount: Partial<NodeCapabilityCount> wantedNodeCapabilityCount: Partial<NodeCapabilityCount>,
): AsyncGenerator<IEnr> { ): AsyncGenerator<IEnr> {
const networkIndex = Math.floor(Math.random() * enrTreeUrls.length); const networkIndex = Math.floor(Math.random() * enrTreeUrls.length);
const { publicKey, domain } = ENRTree.parseTree(enrTreeUrls[networkIndex]); const { publicKey, domain } = ENRTree.parseTree(enrTreeUrls[networkIndex]);
@ -101,7 +101,7 @@ export class DnsNodeDiscovery {
for await (const peer of yieldNodesUntilCapabilitiesFulfilled( for await (const peer of yieldNodesUntilCapabilitiesFulfilled(
wantedNodeCapabilityCount, wantedNodeCapabilityCount,
this._errorTolerance, this._errorTolerance,
() => this._search(domain, context) () => this._search(domain, context),
)) { )) {
yield peer; yield peer;
} }
@ -113,7 +113,7 @@ export class DnsNodeDiscovery {
*/ */
private async _search( private async _search(
subdomain: string, subdomain: string,
context: SearchContext context: SearchContext,
): Promise<ENR | null> { ): Promise<ENR | null> {
try { try {
const entry = await this._getTXTRecord(subdomain, context); const entry = await this._getTXTRecord(subdomain, context);
@ -139,7 +139,7 @@ export class DnsNodeDiscovery {
} }
} catch (error) { } catch (error) {
log( log(
`Failed to search DNS tree ${entryType} at subdomain ${subdomain}: ${error}` `Failed to search DNS tree ${entryType} at subdomain ${subdomain}: ${error}`,
); );
return null; return null;
} }
@ -157,7 +157,7 @@ export class DnsNodeDiscovery {
*/ */
private async _getTXTRecord( private async _getTXTRecord(
subdomain: string, subdomain: string,
context: SearchContext context: SearchContext,
): Promise<string> { ): Promise<string> {
if (this._DNSTreeCache[subdomain]) { if (this._DNSTreeCache[subdomain]) {
return this._DNSTreeCache[subdomain]; return this._DNSTreeCache[subdomain];

View File

@ -18,7 +18,7 @@ export class DnsOverHttps implements DnsClient {
*/ */
public static async create( public static async create(
endpoints?: Endpoint[], endpoints?: Endpoint[],
retries?: number retries?: number,
): Promise<DnsOverHttps> { ): Promise<DnsOverHttps> {
const _endpoints = endpoints ?? (await wellknown.endpoints("doh")); const _endpoints = endpoints ?? (await wellknown.endpoints("doh"));
@ -27,7 +27,7 @@ export class DnsOverHttps implements DnsClient {
private constructor( private constructor(
private endpoints: Endpoint[], private endpoints: Endpoint[],
private retries: number = 3 private retries: number = 3,
) {} ) {}
/** /**
@ -47,7 +47,7 @@ export class DnsOverHttps implements DnsClient {
{ {
endpoints: this.endpoints, endpoints: this.endpoints,
retries: this.retries, retries: this.retries,
} },
); );
answers = res.answers; answers = res.answers;
} catch (error) { } catch (error) {

View File

@ -19,7 +19,7 @@ describe("ENRTree", () => {
} catch (err: unknown) { } catch (err: unknown) {
const e = err as Error; const e = err as Error;
expect(e.toString()).includes( expect(e.toString()).includes(
"ENRTree root entry must start with 'enrtree-root:'" "ENRTree root entry must start with 'enrtree-root:'",
); );
} }
}); });
@ -56,7 +56,7 @@ describe("ENRTree", () => {
} catch (err: unknown) { } catch (err: unknown) {
const e = err as Error; const e = err as Error;
expect(e.toString()).includes( expect(e.toString()).includes(
"ENRTree tree entry must start with 'enrtree:'" "ENRTree tree entry must start with 'enrtree:'",
); );
} }
}); });
@ -88,7 +88,7 @@ describe("ENRTree", () => {
} catch (err: unknown) { } catch (err: unknown) {
const e = err as Error; const e = err as Error;
expect(e.toString()).includes( expect(e.toString()).includes(
"ENRTree branch entry must start with 'enrtree-branch:'" "ENRTree branch entry must start with 'enrtree-branch:'",
); );
} }
}); });

View File

@ -29,7 +29,7 @@ export class ENRTree {
static parseAndVerifyRoot(root: string, publicKey: string): string { static parseAndVerifyRoot(root: string, publicKey: string): string {
if (!root.startsWith(this.ROOT_PREFIX)) if (!root.startsWith(this.ROOT_PREFIX))
throw new Error( throw new Error(
`ENRTree root entry must start with '${this.ROOT_PREFIX}'` `ENRTree root entry must start with '${this.ROOT_PREFIX}'`,
); );
const rootValues = ENRTree.parseRootValues(root); const rootValues = ENRTree.parseRootValues(root);
@ -43,13 +43,13 @@ export class ENRTree {
const signedComponentBuffer = utf8ToBytes(signedComponent); const signedComponentBuffer = utf8ToBytes(signedComponent);
const signatureBuffer = fromString(rootValues.signature, "base64url").slice( const signatureBuffer = fromString(rootValues.signature, "base64url").slice(
0, 0,
64 64,
); );
const isVerified = verifySignature( const isVerified = verifySignature(
signatureBuffer, signatureBuffer,
keccak256(signedComponentBuffer), keccak256(signedComponentBuffer),
new Uint8Array(decodedPublicKey) new Uint8Array(decodedPublicKey),
); );
if (!isVerified) throw new Error("Unable to verify ENRTree root signature"); if (!isVerified) throw new Error("Unable to verify ENRTree root signature");
@ -59,7 +59,7 @@ export class ENRTree {
static parseRootValues(txt: string): ENRRootValues { static parseRootValues(txt: string): ENRRootValues {
const matches = txt.match( const matches = txt.match(
/^enrtree-root:v1 e=([^ ]+) l=([^ ]+) seq=(\d+) sig=([^ ]+)$/ /^enrtree-root:v1 e=([^ ]+) l=([^ ]+) seq=(\d+) sig=([^ ]+)$/,
); );
if (!Array.isArray(matches)) if (!Array.isArray(matches))
@ -89,7 +89,7 @@ export class ENRTree {
static parseTree(tree: string): ENRTreeValues { static parseTree(tree: string): ENRTreeValues {
if (!tree.startsWith(this.TREE_PREFIX)) if (!tree.startsWith(this.TREE_PREFIX))
throw new Error( throw new Error(
`ENRTree tree entry must start with '${this.TREE_PREFIX}'` `ENRTree tree entry must start with '${this.TREE_PREFIX}'`,
); );
const matches = tree.match(/^enrtree:\/\/([^@]+)@(.+)$/); const matches = tree.match(/^enrtree:\/\/([^@]+)@(.+)$/);
@ -115,7 +115,7 @@ export class ENRTree {
static parseBranch(branch: string): string[] { static parseBranch(branch: string): string[] {
if (!branch.startsWith(this.BRANCH_PREFIX)) if (!branch.startsWith(this.BRANCH_PREFIX))
throw new Error( throw new Error(
`ENRTree branch entry must start with '${this.BRANCH_PREFIX}'` `ENRTree branch entry must start with '${this.BRANCH_PREFIX}'`,
); );
return branch.split(this.BRANCH_PREFIX)[1].split(","); return branch.split(this.BRANCH_PREFIX)[1].split(",");

View File

@ -15,7 +15,7 @@ async function createEnr(waku2: Waku2): Promise<ENR> {
multiaddr("/dns4/node1.do-ams.wakuv2.test.statusim.net/tcp/443/wss"), multiaddr("/dns4/node1.do-ams.wakuv2.test.statusim.net/tcp/443/wss"),
multiaddr("/dns6/node2.ac-chi.wakuv2.test.statusim.net/tcp/443/wss"), multiaddr("/dns6/node2.ac-chi.wakuv2.test.statusim.net/tcp/443/wss"),
multiaddr( multiaddr(
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234/wss" "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234/wss",
), ),
]; ];
@ -39,7 +39,7 @@ describe("Fetch nodes until capabilities are fulfilled", function () {
const res = await fetchNodesUntilCapabilitiesFulfilled( const res = await fetchNodesUntilCapabilitiesFulfilled(
{ relay: 1 }, { relay: 1 },
0, 0,
getNode getNode,
); );
expect(res.length).to.eq(1); expect(res.length).to.eq(1);
@ -62,7 +62,7 @@ describe("Fetch nodes until capabilities are fulfilled", function () {
const res = await fetchNodesUntilCapabilitiesFulfilled( const res = await fetchNodesUntilCapabilitiesFulfilled(
{ store: 1 }, { store: 1 },
1, 1,
getNode getNode,
); );
expect(res.length).to.eq(1); expect(res.length).to.eq(1);
@ -91,7 +91,7 @@ describe("Fetch nodes until capabilities are fulfilled", function () {
const res = await fetchNodesUntilCapabilitiesFulfilled( const res = await fetchNodesUntilCapabilitiesFulfilled(
{ store: 1, relay: 2 }, { store: 1, relay: 2 },
1, 1,
getNode getNode,
); );
expect(res.length).to.eq(3); expect(res.length).to.eq(3);
@ -108,7 +108,7 @@ describe("Fetch nodes until capabilities are fulfilled", function () {
const res = await fetchNodesUntilCapabilitiesFulfilled( const res = await fetchNodesUntilCapabilitiesFulfilled(
{ filter: 1, relay: 1 }, { filter: 1, relay: 1 },
5, 5,
getNode getNode,
); );
expect(res.length).to.eq(1); expect(res.length).to.eq(1);

View File

@ -13,7 +13,7 @@ const log = debug("waku:discovery:fetch_nodes");
export async function fetchNodesUntilCapabilitiesFulfilled( export async function fetchNodesUntilCapabilitiesFulfilled(
wantedNodeCapabilityCount: Partial<NodeCapabilityCount>, wantedNodeCapabilityCount: Partial<NodeCapabilityCount>,
errorTolerance: number, errorTolerance: number,
getNode: () => Promise<IEnr | null> getNode: () => Promise<IEnr | null>,
): Promise<IEnr[]> { ): Promise<IEnr[]> {
const wanted = { const wanted = {
relay: wantedNodeCapabilityCount.relay ?? 0, relay: wantedNodeCapabilityCount.relay ?? 0,
@ -64,7 +64,7 @@ export async function fetchNodesUntilCapabilitiesFulfilled(
export async function* yieldNodesUntilCapabilitiesFulfilled( export async function* yieldNodesUntilCapabilitiesFulfilled(
wantedNodeCapabilityCount: Partial<NodeCapabilityCount>, wantedNodeCapabilityCount: Partial<NodeCapabilityCount>,
errorTolerance: number, errorTolerance: number,
getNode: () => Promise<IEnr | null> getNode: () => Promise<IEnr | null>,
): AsyncGenerator<IEnr> { ): AsyncGenerator<IEnr> {
const wanted = { const wanted = {
relay: wantedNodeCapabilityCount.relay ?? 0, relay: wantedNodeCapabilityCount.relay ?? 0,
@ -108,7 +108,7 @@ export async function* yieldNodesUntilCapabilitiesFulfilled(
function isSatisfied( function isSatisfied(
wanted: NodeCapabilityCount, wanted: NodeCapabilityCount,
actual: NodeCapabilityCount actual: NodeCapabilityCount,
): boolean { ): boolean {
return ( return (
actual.relay >= wanted.relay && actual.relay >= wanted.relay &&
@ -146,7 +146,7 @@ function addCapabilities(node: Waku2, total: NodeCapabilityCount): void {
function helpsSatisfyCapabilities( function helpsSatisfyCapabilities(
node: Waku2, node: Waku2,
wanted: NodeCapabilityCount, wanted: NodeCapabilityCount,
actual: NodeCapabilityCount actual: NodeCapabilityCount,
): boolean { ): boolean {
if (isSatisfied(wanted, actual)) { if (isSatisfied(wanted, actual)) {
throw "Internal Error: Waku2 wanted capabilities are already fulfilled"; throw "Internal Error: Waku2 wanted capabilities are already fulfilled";
@ -168,7 +168,7 @@ function helpsSatisfyCapabilities(
*/ */
function missingCapabilities( function missingCapabilities(
wanted: NodeCapabilityCount, wanted: NodeCapabilityCount,
actual: NodeCapabilityCount actual: NodeCapabilityCount,
): Waku2 { ): Waku2 {
return { return {
relay: actual.relay < wanted.relay, relay: actual.relay < wanted.relay,

View File

@ -93,7 +93,7 @@ export class PeerDiscoveryDns
this.nextPeer = dns.getNextPeer.bind( this.nextPeer = dns.getNextPeer.bind(
dns, dns,
enrUrls, enrUrls,
wantedNodeCapabilityCount wantedNodeCapabilityCount,
); );
} }
@ -135,7 +135,7 @@ export class PeerDiscoveryDns
if (isPeerChanged) { if (isPeerChanged) {
this.dispatchEvent( this.dispatchEvent(
new CustomEvent<PeerInfo>("peer", { detail: peerInfo }) new CustomEvent<PeerInfo>("peer", { detail: peerInfo }),
); );
} }
} }
@ -159,7 +159,7 @@ export class PeerDiscoveryDns
export function wakuDnsDiscovery( export function wakuDnsDiscovery(
enrUrls: string[], enrUrls: string[],
wantedNodeCapabilityCount: Partial<NodeCapabilityCount> wantedNodeCapabilityCount: Partial<NodeCapabilityCount>,
): (components: DnsDiscoveryComponents) => PeerDiscoveryDns { ): (components: DnsDiscoveryComponents) => PeerDiscoveryDns {
return (components: DnsDiscoveryComponents) => return (components: DnsDiscoveryComponents) =>
new PeerDiscoveryDns(components, { enrUrls, wantedNodeCapabilityCount }); new PeerDiscoveryDns(components, { enrUrls, wantedNodeCapabilityCount });

View File

@ -79,7 +79,6 @@
"karma-webpack": "^5.0.0", "karma-webpack": "^5.0.0",
"mocha": "^10.2.0", "mocha": "^10.2.0",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"process": "^0.11.10", "process": "^0.11.10",
"puppeteer": "^20.4.0", "puppeteer": "^20.4.0",
"rollup": "^3.21.3", "rollup": "^3.21.3",

View File

@ -9,7 +9,7 @@ import { getPublicKeyFromPeerId } from "./peer_id.js";
export class EnrCreator { export class EnrCreator {
static fromPublicKey( static fromPublicKey(
publicKey: Uint8Array, publicKey: Uint8Array,
kvs: Record<ENRKey, ENRValue> = {} kvs: Record<ENRKey, ENRValue> = {},
): Promise<ENR> { ): Promise<ENR> {
// EIP-778 specifies that the key must be in compressed format, 33 bytes // EIP-778 specifies that the key must be in compressed format, 33 bytes
if (publicKey.length !== 33) { if (publicKey.length !== 33) {
@ -24,7 +24,7 @@ export class EnrCreator {
static async fromPeerId( static async fromPeerId(
peerId: PeerId, peerId: PeerId,
kvs: Record<ENRKey, ENRValue> = {} kvs: Record<ENRKey, ENRValue> = {},
): Promise<ENR> { ): Promise<ENR> {
switch (peerId.type) { switch (peerId.type) {
case "secp256k1": case "secp256k1":

View File

@ -12,7 +12,7 @@ import sha3 from "js-sha3";
*/ */
export async function sign( export async function sign(
message: Uint8Array, message: Uint8Array,
privateKey: Uint8Array privateKey: Uint8Array,
): Promise<Uint8Array> { ): Promise<Uint8Array> {
const [signature, recoveryId] = await secp.sign(message, privateKey, { const [signature, recoveryId] = await secp.sign(message, privateKey, {
recovered: true, recovered: true,
@ -20,7 +20,7 @@ export async function sign(
}); });
return concat( return concat(
[signature, new Uint8Array([recoveryId])], [signature, new Uint8Array([recoveryId])],
signature.length + 1 signature.length + 1,
); );
} }
@ -42,7 +42,7 @@ export function compressPublicKey(publicKey: Uint8Array): Uint8Array {
export function verifySignature( export function verifySignature(
signature: Uint8Array, signature: Uint8Array,
message: Uint8Array | string, message: Uint8Array | string,
publicKey: Uint8Array publicKey: Uint8Array,
): boolean { ): boolean {
try { try {
const _signature = secp.Signature.fromCompact(signature.slice(0, 64)); const _signature = secp.Signature.fromCompact(signature.slice(0, 64));

View File

@ -10,7 +10,7 @@ export class EnrDecoder {
static fromString(encoded: string): Promise<ENR> { static fromString(encoded: string): Promise<ENR> {
if (!encoded.startsWith(ENR.RECORD_PREFIX)) { if (!encoded.startsWith(ENR.RECORD_PREFIX)) {
throw new Error( throw new Error(
`"string encoded ENR must start with '${ENR.RECORD_PREFIX}'` `"string encoded ENR must start with '${ENR.RECORD_PREFIX}'`,
); );
} }
return EnrDecoder.fromRLP(fromString(encoded.slice(4), "base64url")); return EnrDecoder.fromRLP(fromString(encoded.slice(4), "base64url"));
@ -64,7 +64,7 @@ function checkValues(values: Uint8Array[]): {
} }
if (!seq || Array.isArray(seq)) { if (!seq || Array.isArray(seq)) {
throw new Error( throw new Error(
"Decoded ENR invalid sequence number: must be a byte array" "Decoded ENR invalid sequence number: must be a byte array",
); );
} }
@ -75,7 +75,7 @@ function checkSignature(
seq: Uint8Array, seq: Uint8Array,
kvs: Uint8Array[], kvs: Uint8Array[],
enr: ENR, enr: ENR,
signature: Uint8Array signature: Uint8Array,
): void { ): void {
const rlpEncodedBytes = hexToBytes(RLP.encode([seq, ...kvs])); const rlpEncodedBytes = hexToBytes(RLP.encode([seq, ...kvs]));
if (!enr.verify(rlpEncodedBytes, signature)) { if (!enr.verify(rlpEncodedBytes, signature)) {

View File

@ -9,7 +9,7 @@ import { ENR } from "./enr.js";
export class EnrEncoder { export class EnrEncoder {
static async toValues( static async toValues(
enr: ENR, enr: ENR,
privateKey?: Uint8Array privateKey?: Uint8Array,
): Promise<(ENRKey | ENRValue | number[])[]> { ): Promise<(ENRKey | ENRValue | number[])[]> {
// sort keys and flatten into [k, v, k, v, ...] // sort keys and flatten into [k, v, k, v, ...]
const content: Array<ENRKey | ENRValue | number[]> = Array.from(enr.keys()) const content: Array<ENRKey | ENRValue | number[]> = Array.from(enr.keys())
@ -20,7 +20,7 @@ export class EnrEncoder {
content.unshift(new Uint8Array([Number(enr.seq)])); content.unshift(new Uint8Array([Number(enr.seq)]));
if (privateKey) { if (privateKey) {
content.unshift( content.unshift(
await enr.sign(hexToBytes(RLP.encode(content)), privateKey) await enr.sign(hexToBytes(RLP.encode(content)), privateKey),
); );
} else { } else {
if (!enr.signature) { if (!enr.signature) {
@ -33,7 +33,7 @@ export class EnrEncoder {
static async toBytes(enr: ENR, privateKey?: Uint8Array): Promise<Uint8Array> { static async toBytes(enr: ENR, privateKey?: Uint8Array): Promise<Uint8Array> {
const encoded = hexToBytes( const encoded = hexToBytes(
RLP.encode(await EnrEncoder.toValues(enr, privateKey)) RLP.encode(await EnrEncoder.toValues(enr, privateKey)),
); );
if (encoded.length >= MAX_RECORD_SIZE) { if (encoded.length >= MAX_RECORD_SIZE) {
throw new Error("ENR must be less than 300 bytes"); throw new Error("ENR must be less than 300 bytes");

View File

@ -29,7 +29,7 @@ describe("ENR", function () {
multiaddr("/dns4/node1.do-ams.wakuv2.test.statusim.net/tcp/443/wss"), multiaddr("/dns4/node1.do-ams.wakuv2.test.statusim.net/tcp/443/wss"),
multiaddr("/dns6/node2.ac-chi.wakuv2.test.statusim.net/tcp/443/wss"), multiaddr("/dns6/node2.ac-chi.wakuv2.test.statusim.net/tcp/443/wss"),
multiaddr( multiaddr(
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234/wss" "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234/wss",
), ),
]; ];
@ -53,13 +53,13 @@ describe("ENR", function () {
expect(enr2.multiaddrs!.length).to.be.equal(3); expect(enr2.multiaddrs!.length).to.be.equal(3);
const multiaddrsAsStr = enr2.multiaddrs!.map((ma) => ma.toString()); const multiaddrsAsStr = enr2.multiaddrs!.map((ma) => ma.toString());
expect(multiaddrsAsStr).to.include( expect(multiaddrsAsStr).to.include(
"/dns4/node1.do-ams.wakuv2.test.statusim.net/tcp/443/wss" "/dns4/node1.do-ams.wakuv2.test.statusim.net/tcp/443/wss",
); );
expect(multiaddrsAsStr).to.include( expect(multiaddrsAsStr).to.include(
"/dns6/node2.ac-chi.wakuv2.test.statusim.net/tcp/443/wss" "/dns6/node2.ac-chi.wakuv2.test.statusim.net/tcp/443/wss",
); );
expect(multiaddrsAsStr).to.include( expect(multiaddrsAsStr).to.include(
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234/wss" "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234/wss",
); );
expect(enr2.waku2).to.deep.equal({ expect(enr2.waku2).to.deep.equal({
relay: true, relay: true,
@ -87,13 +87,13 @@ describe("ENR", function () {
expect(enr.multiaddrs!.length).to.be.equal(3); expect(enr.multiaddrs!.length).to.be.equal(3);
const multiaddrsAsStr = enr.multiaddrs!.map((ma) => ma.toString()); const multiaddrsAsStr = enr.multiaddrs!.map((ma) => ma.toString());
expect(multiaddrsAsStr).to.include( expect(multiaddrsAsStr).to.include(
"/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/443/wss" "/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/443/wss",
); );
expect(multiaddrsAsStr).to.include( expect(multiaddrsAsStr).to.include(
"/dns6/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/443/wss" "/dns6/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/443/wss",
); );
expect(multiaddrsAsStr).to.include( expect(multiaddrsAsStr).to.include(
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234/wss" "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234/wss",
); );
}); });
@ -107,7 +107,7 @@ describe("ENR", function () {
expect(enr.ip).to.be.equal("134.209.139.210"); expect(enr.ip).to.be.equal("134.209.139.210");
expect(enr.publicKey).to.not.be.undefined; expect(enr.publicKey).to.not.be.undefined;
expect(enr.peerId?.toString()).to.be.equal( expect(enr.peerId?.toString()).to.be.equal(
"16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ" "16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ",
); );
}); });
@ -159,7 +159,7 @@ describe("ENR", function () {
const enr = await ENR.create( const enr = await ENR.create(
{ id: utf8ToBytes("v3") }, { id: utf8ToBytes("v3") },
BigInt(0), BigInt(0),
new Uint8Array() new Uint8Array(),
); );
enr.verify(new Uint8Array(), new Uint8Array()); enr.verify(new Uint8Array(), new Uint8Array());
assert.fail("Expect error here"); assert.fail("Expect error here");
@ -174,7 +174,7 @@ describe("ENR", function () {
const enr = await ENR.create( const enr = await ENR.create(
{ id: utf8ToBytes("v4") }, { id: utf8ToBytes("v4") },
BigInt(0), BigInt(0),
new Uint8Array() new Uint8Array(),
); );
enr.verify(new Uint8Array(), new Uint8Array()); enr.verify(new Uint8Array(), new Uint8Array());
assert.fail("Expect error here"); assert.fail("Expect error here");
@ -200,7 +200,7 @@ describe("ENR", function () {
beforeEach(async function () { beforeEach(async function () {
const seq = BigInt(1); const seq = BigInt(1);
privateKey = hexToBytes( privateKey = hexToBytes(
"b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291",
); );
record = await EnrCreator.fromPublicKey(secp.getPublicKey(privateKey)); record = await EnrCreator.fromPublicKey(secp.getPublicKey(privateKey));
record.setLocationMultiaddr(multiaddr("/ip4/127.0.0.1/udp/30303")); record.setLocationMultiaddr(multiaddr("/ip4/127.0.0.1/udp/30303"));
@ -210,7 +210,7 @@ describe("ENR", function () {
it("should properly compute the node id", () => { it("should properly compute the node id", () => {
expect(record.nodeId).to.equal( expect(record.nodeId).to.equal(
"a448f24c6d18e575453db13171562b71999873db5b286df957af199ec94617f7" "a448f24c6d18e575453db13171562b71999873db5b286df957af199ec94617f7",
); );
}); });
@ -245,7 +245,7 @@ describe("ENR", function () {
beforeEach(async () => { beforeEach(async () => {
privateKey = hexToBytes( privateKey = hexToBytes(
"b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" "b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291",
); );
record = await EnrCreator.fromPublicKey(secp.getPublicKey(privateKey)); record = await EnrCreator.fromPublicKey(secp.getPublicKey(privateKey));
}); });
@ -262,14 +262,14 @@ describe("ENR", function () {
record.set("udp", tuples0[1][1]); record.set("udp", tuples0[1][1]);
// and get the multiaddr // and get the multiaddr
expect( expect(
record.getLocationMultiaddr(TransportProtocol.UDP)!.toString() record.getLocationMultiaddr(TransportProtocol.UDP)!.toString(),
).to.equal(multi0.toString()); ).to.equal(multi0.toString());
// set the multiaddr // set the multiaddr
const multi1 = multiaddr("/ip4/0.0.0.0/udp/30300"); const multi1 = multiaddr("/ip4/0.0.0.0/udp/30300");
record.setLocationMultiaddr(multi1); record.setLocationMultiaddr(multi1);
// and get the multiaddr // and get the multiaddr
expect( expect(
record.getLocationMultiaddr(TransportProtocol.UDP)!.toString() record.getLocationMultiaddr(TransportProtocol.UDP)!.toString(),
).to.equal(multi1.toString()); ).to.equal(multi1.toString());
// and get the underlying records // and get the underlying records
const tuples1 = multi1.tuples(); const tuples1 = multi1.tuples();
@ -290,14 +290,14 @@ describe("ENR", function () {
record.set("tcp", tuples0[1][1]); record.set("tcp", tuples0[1][1]);
// and get the multiaddr // and get the multiaddr
expect( expect(
record.getLocationMultiaddr(TransportProtocol.TCP)!.toString() record.getLocationMultiaddr(TransportProtocol.TCP)!.toString(),
).to.equal(multi0.toString()); ).to.equal(multi0.toString());
// set the multiaddr // set the multiaddr
const multi1 = multiaddr("/ip4/0.0.0.0/tcp/30300"); const multi1 = multiaddr("/ip4/0.0.0.0/tcp/30300");
record.setLocationMultiaddr(multi1); record.setLocationMultiaddr(multi1);
// and get the multiaddr // and get the multiaddr
expect( expect(
record.getLocationMultiaddr(TransportProtocol.TCP)!.toString() record.getLocationMultiaddr(TransportProtocol.TCP)!.toString(),
).to.equal(multi1.toString()); ).to.equal(multi1.toString());
// and get the underlying records // and get the underlying records
const tuples1 = multi1.tuples(); const tuples1 = multi1.tuples();
@ -312,7 +312,7 @@ describe("ENR", function () {
const tcp = 8080; const tcp = 8080;
const udp = 8080; const udp = 8080;
const wsMultiaddr = multiaddr( const wsMultiaddr = multiaddr(
"/dns4/node-01.do-ams3.wakuv2.prod.statusim.net/tcp/8000/wss" "/dns4/node-01.do-ams3.wakuv2.prod.statusim.net/tcp/8000/wss",
); );
let peerId: PeerId; let peerId: PeerId;
let enr: ENR; let enr: ENR;
@ -331,43 +331,43 @@ describe("ENR", function () {
it("should properly create location multiaddrs - udp4", () => { it("should properly create location multiaddrs - udp4", () => {
expect( expect(
enr.getLocationMultiaddr(TransportProtocolPerIpVersion.UDP4) enr.getLocationMultiaddr(TransportProtocolPerIpVersion.UDP4),
).to.deep.equal(multiaddr(`/ip4/${ip4}/udp/${udp}`)); ).to.deep.equal(multiaddr(`/ip4/${ip4}/udp/${udp}`));
}); });
it("should properly create location multiaddrs - tcp4", () => { it("should properly create location multiaddrs - tcp4", () => {
expect( expect(
enr.getLocationMultiaddr(TransportProtocolPerIpVersion.TCP4) enr.getLocationMultiaddr(TransportProtocolPerIpVersion.TCP4),
).to.deep.equal(multiaddr(`/ip4/${ip4}/tcp/${tcp}`)); ).to.deep.equal(multiaddr(`/ip4/${ip4}/tcp/${tcp}`));
}); });
it("should properly create location multiaddrs - udp6", () => { it("should properly create location multiaddrs - udp6", () => {
expect( expect(
enr.getLocationMultiaddr(TransportProtocolPerIpVersion.UDP6) enr.getLocationMultiaddr(TransportProtocolPerIpVersion.UDP6),
).to.deep.equal(multiaddr(`/ip6/${ip6}/udp/${udp}`)); ).to.deep.equal(multiaddr(`/ip6/${ip6}/udp/${udp}`));
}); });
it("should properly create location multiaddrs - tcp6", () => { it("should properly create location multiaddrs - tcp6", () => {
expect( expect(
enr.getLocationMultiaddr(TransportProtocolPerIpVersion.TCP6) enr.getLocationMultiaddr(TransportProtocolPerIpVersion.TCP6),
).to.deep.equal(multiaddr(`/ip6/${ip6}/tcp/${tcp}`)); ).to.deep.equal(multiaddr(`/ip6/${ip6}/tcp/${tcp}`));
}); });
it("should properly create location multiaddrs - udp", () => { it("should properly create location multiaddrs - udp", () => {
// default to ip4 // default to ip4
expect(enr.getLocationMultiaddr(TransportProtocol.UDP)).to.deep.equal( expect(enr.getLocationMultiaddr(TransportProtocol.UDP)).to.deep.equal(
multiaddr(`/ip4/${ip4}/udp/${udp}`) multiaddr(`/ip4/${ip4}/udp/${udp}`),
); );
// if ip6 is set, use it // if ip6 is set, use it
enr.ip = undefined; enr.ip = undefined;
expect(enr.getLocationMultiaddr(TransportProtocol.UDP)).to.deep.equal( expect(enr.getLocationMultiaddr(TransportProtocol.UDP)).to.deep.equal(
multiaddr(`/ip6/${ip6}/udp/${udp}`) multiaddr(`/ip6/${ip6}/udp/${udp}`),
); );
// if ip6 does not exist, use ip4 // if ip6 does not exist, use ip4
enr.ip6 = undefined; enr.ip6 = undefined;
enr.ip = ip4; enr.ip = ip4;
expect(enr.getLocationMultiaddr(TransportProtocol.UDP)).to.deep.equal( expect(enr.getLocationMultiaddr(TransportProtocol.UDP)).to.deep.equal(
multiaddr(`/ip4/${ip4}/udp/${udp}`) multiaddr(`/ip4/${ip4}/udp/${udp}`),
); );
enr.ip6 = ip6; enr.ip6 = ip6;
}); });
@ -375,18 +375,18 @@ describe("ENR", function () {
it("should properly create location multiaddrs - tcp", () => { it("should properly create location multiaddrs - tcp", () => {
// default to ip4 // default to ip4
expect(enr.getLocationMultiaddr(TransportProtocol.TCP)).to.deep.equal( expect(enr.getLocationMultiaddr(TransportProtocol.TCP)).to.deep.equal(
multiaddr(`/ip4/${ip4}/tcp/${tcp}`) multiaddr(`/ip4/${ip4}/tcp/${tcp}`),
); );
// if ip6 is set, use it // if ip6 is set, use it
enr.ip = undefined; enr.ip = undefined;
expect(enr.getLocationMultiaddr(TransportProtocol.TCP)).to.deep.equal( expect(enr.getLocationMultiaddr(TransportProtocol.TCP)).to.deep.equal(
multiaddr(`/ip6/${ip6}/tcp/${tcp}`) multiaddr(`/ip6/${ip6}/tcp/${tcp}`),
); );
// if ip6 does not exist, use ip4 // if ip6 does not exist, use ip4
enr.ip6 = undefined; enr.ip6 = undefined;
enr.ip = ip4; enr.ip = ip4;
expect(enr.getLocationMultiaddr(TransportProtocol.TCP)).to.deep.equal( expect(enr.getLocationMultiaddr(TransportProtocol.TCP)).to.deep.equal(
multiaddr(`/ip4/${ip4}/tcp/${tcp}`) multiaddr(`/ip4/${ip4}/tcp/${tcp}`),
); );
enr.ip6 = ip6; enr.ip6 = ip6;
}); });
@ -397,19 +397,19 @@ describe("ENR", function () {
expect(peerInfo.id.toString()).to.equal(peerId.toString()); expect(peerInfo.id.toString()).to.equal(peerId.toString());
expect(peerInfo.multiaddrs.length).to.equal(5); expect(peerInfo.multiaddrs.length).to.equal(5);
expect(peerInfo.multiaddrs.map((ma) => ma.toString())).to.contain( expect(peerInfo.multiaddrs.map((ma) => ma.toString())).to.contain(
multiaddr(`/ip4/${ip4}/tcp/${tcp}`).toString() multiaddr(`/ip4/${ip4}/tcp/${tcp}`).toString(),
); );
expect(peerInfo.multiaddrs.map((ma) => ma.toString())).to.contain( expect(peerInfo.multiaddrs.map((ma) => ma.toString())).to.contain(
multiaddr(`/ip6/${ip6}/tcp/${tcp}`).toString() multiaddr(`/ip6/${ip6}/tcp/${tcp}`).toString(),
); );
expect(peerInfo.multiaddrs.map((ma) => ma.toString())).to.contain( expect(peerInfo.multiaddrs.map((ma) => ma.toString())).to.contain(
multiaddr(`/ip4/${ip4}/udp/${udp}`).toString() multiaddr(`/ip4/${ip4}/udp/${udp}`).toString(),
); );
expect(peerInfo.multiaddrs.map((ma) => ma.toString())).to.contain( expect(peerInfo.multiaddrs.map((ma) => ma.toString())).to.contain(
multiaddr(`/ip6/${ip6}/udp/${udp}`).toString() multiaddr(`/ip6/${ip6}/udp/${udp}`).toString(),
); );
expect(peerInfo.multiaddrs.map((ma) => ma.toString())).to.contain( expect(peerInfo.multiaddrs.map((ma) => ma.toString())).to.contain(
wsMultiaddr.toString() wsMultiaddr.toString(),
); );
}); });
}); });

View File

@ -37,7 +37,7 @@ export class ENR extends RawEnr implements IEnr {
static async create( static async create(
kvs: Record<ENRKey, ENRValue> = {}, kvs: Record<ENRKey, ENRValue> = {},
seq: SequenceNumber = BigInt(1), seq: SequenceNumber = BigInt(1),
signature?: Uint8Array signature?: Uint8Array,
): Promise<ENR> { ): Promise<ENR> {
const enr = new ENR(kvs, seq, signature); const enr = new ENR(kvs, seq, signature);
try { try {
@ -61,7 +61,7 @@ export class ENR extends RawEnr implements IEnr {
} }
} }
getLocationMultiaddr: ( getLocationMultiaddr: (
protocol: TransportProtocol | TransportProtocolPerIpVersion protocol: TransportProtocol | TransportProtocolPerIpVersion,
) => Multiaddr | undefined = locationMultiaddrFromEnrFields.bind({}, this); ) => Multiaddr | undefined = locationMultiaddrFromEnrFields.bind({}, this);
setLocationMultiaddr(multiaddr: Multiaddr): void { setLocationMultiaddr(multiaddr: Multiaddr): void {
@ -93,7 +93,7 @@ export class ENR extends RawEnr implements IEnr {
for (const protocol of Object.values(TransportProtocolPerIpVersion)) { for (const protocol of Object.values(TransportProtocolPerIpVersion)) {
const ma = this.getLocationMultiaddr( const ma = this.getLocationMultiaddr(
protocol as TransportProtocolPerIpVersion protocol as TransportProtocolPerIpVersion,
); );
if (ma) multiaddrs.push(ma); if (ma) multiaddrs.push(ma);
} }
@ -122,7 +122,7 @@ export class ENR extends RawEnr implements IEnr {
* @param protocol * @param protocol
*/ */
getFullMultiaddr( getFullMultiaddr(
protocol: TransportProtocol | TransportProtocolPerIpVersion protocol: TransportProtocol | TransportProtocolPerIpVersion,
): Multiaddr | undefined { ): Multiaddr | undefined {
if (this.peerId) { if (this.peerId) {
const locationMultiaddr = this.getLocationMultiaddr(protocol); const locationMultiaddr = this.getLocationMultiaddr(protocol);

View File

@ -5,7 +5,7 @@ import { multiaddrFromFields } from "./multiaddr_from_fields.js";
export function locationMultiaddrFromEnrFields( export function locationMultiaddrFromEnrFields(
enr: IEnr, enr: IEnr,
protocol: "udp" | "udp4" | "udp6" | "tcp" | "tcp4" | "tcp6" protocol: "udp" | "udp4" | "udp6" | "tcp" | "tcp4" | "tcp6",
): Multiaddr | undefined { ): Multiaddr | undefined {
switch (protocol) { switch (protocol) {
case "udp": case "udp":
@ -42,6 +42,6 @@ export function locationMultiaddrFromEnrFields(
isIpv6 ? "ip6" : "ip4", isIpv6 ? "ip6" : "ip4",
protoName, protoName,
ipVal, ipVal,
protoVal protoVal,
); );
} }

View File

@ -6,12 +6,12 @@ export function multiaddrFromFields(
ipFamily: string, ipFamily: string,
protocol: string, protocol: string,
ipBytes: Uint8Array, ipBytes: Uint8Array,
protocolBytes: Uint8Array protocolBytes: Uint8Array,
): Multiaddr { ): Multiaddr {
let ma = multiaddr("/" + ipFamily + "/" + convertToString(ipFamily, ipBytes)); let ma = multiaddr("/" + ipFamily + "/" + convertToString(ipFamily, ipBytes));
ma = ma.encapsulate( ma = ma.encapsulate(
multiaddr("/" + protocol + "/" + convertToString(protocol, protocolBytes)) multiaddr("/" + protocol + "/" + convertToString(protocol, protocolBytes)),
); );
return ma; return ma;

View File

@ -8,10 +8,10 @@ describe("ENR multiaddrs codec", function () {
const multiaddrs = [ const multiaddrs = [
multiaddr("/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/443/wss"), multiaddr("/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/443/wss"),
multiaddr( multiaddr(
"/dns6/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/443/wss" "/dns6/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/443/wss",
), ),
multiaddr( multiaddr(
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234/wss" "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234/wss",
), ),
]; ];
@ -20,13 +20,13 @@ describe("ENR multiaddrs codec", function () {
const multiaddrsAsStr = result.map((ma) => ma.toString()); const multiaddrsAsStr = result.map((ma) => ma.toString());
expect(multiaddrsAsStr).to.include( expect(multiaddrsAsStr).to.include(
"/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/443/wss" "/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/443/wss",
); );
expect(multiaddrsAsStr).to.include( expect(multiaddrsAsStr).to.include(
"/dns6/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/443/wss" "/dns6/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/443/wss",
); );
expect(multiaddrsAsStr).to.include( expect(multiaddrsAsStr).to.include(
"/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234/wss" "/onion3/vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd:1234/wss",
); );
}); });
}); });

View File

@ -12,7 +12,7 @@ export function decodeMultiaddrs(bytes: Uint8Array): Multiaddr[] {
const sizeDataView = new DataView( const sizeDataView = new DataView(
bytes.buffer, bytes.buffer,
index, index,
MULTIADDR_LENGTH_SIZE MULTIADDR_LENGTH_SIZE,
); );
const size = sizeDataView.getUint16(0); const size = sizeDataView.getUint16(0);
index += MULTIADDR_LENGTH_SIZE; index += MULTIADDR_LENGTH_SIZE;
@ -28,7 +28,7 @@ export function decodeMultiaddrs(bytes: Uint8Array): Multiaddr[] {
export function encodeMultiaddrs(multiaddrs: Multiaddr[]): Uint8Array { export function encodeMultiaddrs(multiaddrs: Multiaddr[]): Uint8Array {
const totalLength = multiaddrs.reduce( const totalLength = multiaddrs.reduce(
(acc, ma) => acc + MULTIADDR_LENGTH_SIZE + ma.bytes.length, (acc, ma) => acc + MULTIADDR_LENGTH_SIZE + ma.bytes.length,
0 0,
); );
const bytes = new Uint8Array(totalLength); const bytes = new Uint8Array(totalLength);
const dataView = new DataView(bytes.buffer); const dataView = new DataView(bytes.buffer);

View File

@ -4,7 +4,7 @@ import type { PeerId } from "@libp2p/interface-peer-id";
import { peerIdFromKeys } from "@libp2p/peer-id"; import { peerIdFromKeys } from "@libp2p/peer-id";
export function createPeerIdFromPublicKey( export function createPeerIdFromPublicKey(
publicKey: Uint8Array publicKey: Uint8Array,
): Promise<PeerId> { ): Promise<PeerId> {
const _publicKey = new supportedKeys.secp256k1.Secp256k1PublicKey(publicKey); const _publicKey = new supportedKeys.secp256k1.Secp256k1PublicKey(publicKey);
return peerIdFromKeys(_publicKey.bytes, undefined); return peerIdFromKeys(_publicKey.bytes, undefined);
@ -20,7 +20,7 @@ export function getPublicKeyFromPeerId(peerId: PeerId): Uint8Array {
// Only used in tests // Only used in tests
export async function getPrivateKeyFromPeerId( export async function getPrivateKeyFromPeerId(
peerId: PeerId peerId: PeerId,
): Promise<Uint8Array> { ): Promise<Uint8Array> {
if (peerId.type !== "secp256k1") { if (peerId.type !== "secp256k1") {
throw new Error("Unsupported peer id type"); throw new Error("Unsupported peer id type");

View File

@ -17,7 +17,7 @@ export class RawEnr extends Map<ENRKey, ENRValue> {
protected constructor( protected constructor(
kvs: Record<ENRKey, ENRValue> = {}, kvs: Record<ENRKey, ENRValue> = {},
seq: SequenceNumber = BigInt(1), seq: SequenceNumber = BigInt(1),
signature?: Uint8Array signature?: Uint8Array,
) { ) {
super(Object.entries(kvs)); super(Object.entries(kvs));
this.seq = seq; this.seq = seq;
@ -147,7 +147,7 @@ export class RawEnr extends Map<ENRKey, ENRValue> {
this, this,
"waku2", "waku2",
waku2, waku2,
(w) => new Uint8Array([encodeWaku2(w)]) (w) => new Uint8Array([encodeWaku2(w)]),
); );
} }
} }
@ -155,7 +155,7 @@ export class RawEnr extends Map<ENRKey, ENRValue> {
function getStringValue( function getStringValue(
map: Map<ENRKey, ENRValue>, map: Map<ENRKey, ENRValue>,
key: ENRKey, key: ENRKey,
proto: string proto: string,
): string | undefined { ): string | undefined {
const raw = map.get(key); const raw = map.get(key);
if (!raw) return; if (!raw) return;
@ -165,7 +165,7 @@ function getStringValue(
function getNumberAsStringValue( function getNumberAsStringValue(
map: Map<ENRKey, ENRValue>, map: Map<ENRKey, ENRValue>,
key: ENRKey, key: ENRKey,
proto: string proto: string,
): number | undefined { ): number | undefined {
const raw = map.get(key); const raw = map.get(key);
if (!raw) return; if (!raw) return;
@ -176,7 +176,7 @@ function setStringValue(
map: Map<ENRKey, ENRValue>, map: Map<ENRKey, ENRValue>,
key: ENRKey, key: ENRKey,
proto: string, proto: string,
value: string | undefined value: string | undefined,
): void { ): void {
deleteUndefined(map, key, value, convertToBytes.bind({}, proto)); deleteUndefined(map, key, value, convertToBytes.bind({}, proto));
} }
@ -185,7 +185,7 @@ function setNumberAsStringValue(
map: Map<ENRKey, ENRValue>, map: Map<ENRKey, ENRValue>,
key: ENRKey, key: ENRKey,
proto: string, proto: string,
value: number | undefined value: number | undefined,
): void { ): void {
setStringValue(map, key, proto, value?.toString(10)); setStringValue(map, key, proto, value?.toString(10));
} }
@ -194,7 +194,7 @@ function deleteUndefined<K, V, W>(
map: Map<K, W>, map: Map<K, W>,
key: K, key: K,
value: V | undefined, value: V | undefined,
transform: (v: V) => W transform: (v: V) => W,
): void { ): void {
if (value !== undefined) { if (value !== undefined) {
map.set(key, transform(value)); map.set(key, transform(value));

View File

@ -5,7 +5,7 @@ import { bytesToHex } from "@waku/utils/bytes";
import { keccak256 } from "./crypto.js"; import { keccak256 } from "./crypto.js";
export async function sign( export async function sign(
privKey: Uint8Array, privKey: Uint8Array,
msg: Uint8Array msg: Uint8Array,
): Promise<Uint8Array> { ): Promise<Uint8Array> {
return secp.sign(keccak256(msg), privKey, { return secp.sign(keccak256(msg), privKey, {
der: false, der: false,

View File

@ -58,7 +58,6 @@
"@multiformats/multiaddr": "^12.0.0", "@multiformats/multiaddr": "^12.0.0",
"cspell": "^6.31.1", "cspell": "^6.31.1",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"typescript": "^5.0.4", "typescript": "^5.0.4",
"libp2p": "^0.45.9" "libp2p": "^0.45.9"
}, },

View File

@ -12,7 +12,7 @@ export type ContentFilter = {
export interface IFilterSubscription { export interface IFilterSubscription {
subscribe<T extends IDecodedMessage>( subscribe<T extends IDecodedMessage>(
decoders: IDecoder<T> | IDecoder<T>[], decoders: IDecoder<T> | IDecoder<T>[],
callback: Callback<T> callback: Callback<T>,
): Promise<void>; ): Promise<void>;
unsubscribe(contentTopics: ContentTopic[]): Promise<void>; unsubscribe(contentTopics: ContentTopic[]): Promise<void>;
@ -26,6 +26,6 @@ export type IFilter = IReceiver &
IBaseProtocol & { IBaseProtocol & {
createSubscription( createSubscription(
pubSubTopic?: string, pubSubTopic?: string,
peerId?: PeerId peerId?: PeerId,
): Promise<IFilterSubscription>; ): Promise<IFilterSubscription>;
}; };

View File

@ -73,6 +73,6 @@ export interface IDecoder<T extends IDecodedMessage> {
fromWireToProtoObj: (bytes: Uint8Array) => Promise<IProtoMessage | undefined>; fromWireToProtoObj: (bytes: Uint8Array) => Promise<IProtoMessage | undefined>;
fromProtoObj: ( fromProtoObj: (
pubSubTopic: string, pubSubTopic: string,
proto: IProtoMessage proto: IProtoMessage,
) => Promise<T | undefined>; ) => Promise<T | undefined>;
} }

View File

@ -62,7 +62,7 @@ export type ProtocolOptions = {
}; };
export type Callback<T extends IDecodedMessage> = ( export type Callback<T extends IDecodedMessage> = (
msg: T msg: T,
) => void | Promise<void>; ) => void | Promise<void>;
export enum SendError { export enum SendError {

View File

@ -9,11 +9,11 @@ export type ActiveSubscriptions = Map<PubSubTopic, ContentTopic[]>;
export interface IReceiver { export interface IReceiver {
toSubscriptionIterator: <T extends IDecodedMessage>( toSubscriptionIterator: <T extends IDecodedMessage>(
decoders: IDecoder<T> | IDecoder<T>[], decoders: IDecoder<T> | IDecoder<T>[],
opts?: ProtocolOptions opts?: ProtocolOptions,
) => Promise<IAsyncIterator<T>>; ) => Promise<IAsyncIterator<T>>;
subscribe: <T extends IDecodedMessage>( subscribe: <T extends IDecodedMessage>(
decoders: IDecoder<T> | IDecoder<T>[], decoders: IDecoder<T> | IDecoder<T>[],
callback: Callback<T>, callback: Callback<T>,
opts?: ProtocolOptions opts?: ProtocolOptions,
) => Unsubscribe | Promise<Unsubscribe>; ) => Unsubscribe | Promise<Unsubscribe>;
} }

View File

@ -5,6 +5,6 @@ export interface ISender {
send: ( send: (
encoder: IEncoder, encoder: IEncoder,
message: IMessage, message: IMessage,
opts?: ProtocolOptions opts?: ProtocolOptions,
) => Promise<SendResult>; ) => Promise<SendResult>;
} }

View File

@ -49,17 +49,17 @@ export interface IStore extends IBaseProtocol {
queryOrderedCallback: <T extends IDecodedMessage>( queryOrderedCallback: <T extends IDecodedMessage>(
decoders: IDecoder<T>[], decoders: IDecoder<T>[],
callback: (message: T) => Promise<void | boolean> | boolean | void, callback: (message: T) => Promise<void | boolean> | boolean | void,
options?: StoreQueryOptions options?: StoreQueryOptions,
) => Promise<void>; ) => Promise<void>;
queryCallbackOnPromise: <T extends IDecodedMessage>( queryCallbackOnPromise: <T extends IDecodedMessage>(
decoders: IDecoder<T>[], decoders: IDecoder<T>[],
callback: ( callback: (
message: Promise<T | undefined> message: Promise<T | undefined>,
) => Promise<void | boolean> | boolean | void, ) => Promise<void | boolean> | boolean | void,
options?: StoreQueryOptions options?: StoreQueryOptions,
) => Promise<void>; ) => Promise<void>;
queryGenerator: <T extends IDecodedMessage>( queryGenerator: <T extends IDecodedMessage>(
decoders: IDecoder<T>[], decoders: IDecoder<T>[],
options?: StoreQueryOptions options?: StoreQueryOptions,
) => AsyncGenerator<Promise<T | undefined>[]>; ) => AsyncGenerator<Promise<T | undefined>[]>;
} }

View File

@ -101,7 +101,6 @@
"karma-webpack": "^5.0.0", "karma-webpack": "^5.0.0",
"mocha": "^10.2.0", "mocha": "^10.2.0",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"process": "^0.11.10", "process": "^0.11.10",
"puppeteer": "^20.4.0", "puppeteer": "^20.4.0",
"rollup": "^3.21.3", "rollup": "^3.21.3",

View File

@ -13,7 +13,7 @@ function kdf(secret: Uint8Array, outputLength: number): Promise<Uint8Array> {
const counters = new Uint8Array([ctr >> 24, ctr >> 16, ctr >> 8, ctr]); const counters = new Uint8Array([ctr >> 24, ctr >> 16, ctr >> 8, ctr]);
const countersSecret = concat( const countersSecret = concat(
[counters, secret], [counters, secret],
counters.length + secret.length counters.length + secret.length,
); );
const willBeHashResult = sha256(countersSecret); const willBeHashResult = sha256(countersSecret);
willBeResult = willBeResult.then((result) => willBeResult = willBeResult.then((result) =>
@ -21,9 +21,9 @@ function kdf(secret: Uint8Array, outputLength: number): Promise<Uint8Array> {
const _hashResult = new Uint8Array(hashResult); const _hashResult = new Uint8Array(hashResult);
return concat( return concat(
[result, _hashResult], [result, _hashResult],
result.length + _hashResult.length result.length + _hashResult.length,
); );
}) }),
); );
written += 32; written += 32;
ctr += 1; ctr += 1;
@ -34,7 +34,7 @@ function kdf(secret: Uint8Array, outputLength: number): Promise<Uint8Array> {
function aesCtrEncrypt( function aesCtrEncrypt(
counter: Uint8Array, counter: Uint8Array,
key: ArrayBufferLike, key: ArrayBufferLike,
data: ArrayBufferLike data: ArrayBufferLike,
): Promise<Uint8Array> { ): Promise<Uint8Array> {
return getSubtle() return getSubtle()
.importKey("raw", key, "AES-CTR", false, ["encrypt"]) .importKey("raw", key, "AES-CTR", false, ["encrypt"])
@ -42,8 +42,8 @@ function aesCtrEncrypt(
getSubtle().encrypt( getSubtle().encrypt(
{ name: "AES-CTR", counter: counter, length: 128 }, { name: "AES-CTR", counter: counter, length: 128 },
cryptoKey, cryptoKey,
data data,
) ),
) )
.then((bytes) => new Uint8Array(bytes)); .then((bytes) => new Uint8Array(bytes));
} }
@ -51,7 +51,7 @@ function aesCtrEncrypt(
function aesCtrDecrypt( function aesCtrDecrypt(
counter: Uint8Array, counter: Uint8Array,
key: ArrayBufferLike, key: ArrayBufferLike,
data: ArrayBufferLike data: ArrayBufferLike,
): Promise<Uint8Array> { ): Promise<Uint8Array> {
return getSubtle() return getSubtle()
.importKey("raw", key, "AES-CTR", false, ["decrypt"]) .importKey("raw", key, "AES-CTR", false, ["decrypt"])
@ -59,15 +59,15 @@ function aesCtrDecrypt(
getSubtle().decrypt( getSubtle().decrypt(
{ name: "AES-CTR", counter: counter, length: 128 }, { name: "AES-CTR", counter: counter, length: 128 },
cryptoKey, cryptoKey,
data data,
) ),
) )
.then((bytes) => new Uint8Array(bytes)); .then((bytes) => new Uint8Array(bytes));
} }
function hmacSha256Sign( function hmacSha256Sign(
key: ArrayBufferLike, key: ArrayBufferLike,
msg: ArrayBufferLike msg: ArrayBufferLike,
): PromiseLike<Uint8Array> { ): PromiseLike<Uint8Array> {
const algorithm = { name: "HMAC", hash: { name: "SHA-256" } }; const algorithm = { name: "HMAC", hash: { name: "SHA-256" } };
return getSubtle() return getSubtle()
@ -79,12 +79,12 @@ function hmacSha256Sign(
function hmacSha256Verify( function hmacSha256Verify(
key: ArrayBufferLike, key: ArrayBufferLike,
msg: ArrayBufferLike, msg: ArrayBufferLike,
sig: ArrayBufferLike sig: ArrayBufferLike,
): Promise<boolean> { ): Promise<boolean> {
const algorithm = { name: "HMAC", hash: { name: "SHA-256" } }; const algorithm = { name: "HMAC", hash: { name: "SHA-256" } };
const _key = getSubtle().importKey("raw", key, algorithm, false, ["verify"]); const _key = getSubtle().importKey("raw", key, algorithm, false, ["verify"]);
return _key.then((cryptoKey) => return _key.then((cryptoKey) =>
getSubtle().verify(algorithm, cryptoKey, sig, msg) getSubtle().verify(algorithm, cryptoKey, sig, msg),
); );
} }
@ -99,11 +99,11 @@ function hmacSha256Verify(
function derive(privateKeyA: Uint8Array, publicKeyB: Uint8Array): Uint8Array { function derive(privateKeyA: Uint8Array, publicKeyB: Uint8Array): Uint8Array {
if (privateKeyA.length !== 32) { if (privateKeyA.length !== 32) {
throw new Error( throw new Error(
`Bad private key, it should be 32 bytes but it's actually ${privateKeyA.length} bytes long` `Bad private key, it should be 32 bytes but it's actually ${privateKeyA.length} bytes long`,
); );
} else if (publicKeyB.length !== 65) { } else if (publicKeyB.length !== 65) {
throw new Error( throw new Error(
`Bad public key, it should be 65 bytes but it's actually ${publicKeyB.length} bytes long` `Bad public key, it should be 65 bytes but it's actually ${publicKeyB.length} bytes long`,
); );
} else if (publicKeyB[0] !== 4) { } else if (publicKeyB[0] !== 4) {
throw new Error("Bad public key, a valid public key would begin with 4"); throw new Error("Bad public key, a valid public key would begin with 4");
@ -123,7 +123,7 @@ function derive(privateKeyA: Uint8Array, publicKeyB: Uint8Array): Uint8Array {
*/ */
export async function encrypt( export async function encrypt(
publicKeyTo: Uint8Array, publicKeyTo: Uint8Array,
msg: Uint8Array msg: Uint8Array,
): Promise<Uint8Array> { ): Promise<Uint8Array> {
const ephemPrivateKey = randomBytes(32); const ephemPrivateKey = randomBytes(32);
@ -143,7 +143,7 @@ export async function encrypt(
return concat( return concat(
[ephemPublicKey, ivCipherText, hmac], [ephemPublicKey, ivCipherText, hmac],
ephemPublicKey.length + ivCipherText.length + hmac.length ephemPublicKey.length + ivCipherText.length + hmac.length,
); );
} }
@ -159,15 +159,15 @@ const metaLength = 1 + 64 + 16 + 32;
*/ */
export async function decrypt( export async function decrypt(
privateKey: Uint8Array, privateKey: Uint8Array,
encrypted: Uint8Array encrypted: Uint8Array,
): Promise<Uint8Array> { ): Promise<Uint8Array> {
if (encrypted.length <= metaLength) { if (encrypted.length <= metaLength) {
throw new Error( throw new Error(
`Invalid Ciphertext. Data is too small. It should ba at least ${metaLength} bytes` `Invalid Ciphertext. Data is too small. It should ba at least ${metaLength} bytes`,
); );
} else if (encrypted[0] !== 4) { } else if (encrypted[0] !== 4) {
throw new Error( throw new Error(
`Not a valid ciphertext. It should begin with 4 but actually begin with ${encrypted[0]}` `Not a valid ciphertext. It should begin with 4 but actually begin with ${encrypted[0]}`,
); );
} else { } else {
// deserialize // deserialize
@ -182,7 +182,7 @@ export async function decrypt(
const px = derive(privateKey, ephemPublicKey); const px = derive(privateKey, ephemPublicKey);
const hash = await kdf(px, 32); const hash = await kdf(px, 32);
const [encryptionKey, macKey] = await sha256(hash.slice(16)).then( const [encryptionKey, macKey] = await sha256(hash.slice(16)).then(
(macKey) => [hash.slice(0, 16), macKey] (macKey) => [hash.slice(0, 16), macKey],
); );
if (!(await hmacSha256Verify(macKey, cipherAndIv, msgMac))) { if (!(await hmacSha256Verify(macKey, cipherAndIv, msgMac))) {

View File

@ -19,7 +19,7 @@ export function getSubtle(): SubtleCrypto {
return crypto.node.webcrypto.subtle; return crypto.node.webcrypto.subtle;
} else { } else {
throw new Error( throw new Error(
"The environment doesn't have Crypto Subtle API (if in the browser, be sure to use to be in a secure context, ie, https)" "The environment doesn't have Crypto Subtle API (if in the browser, be sure to use to be in a secure context, ie, https)",
); );
} }
} }
@ -59,7 +59,7 @@ export const getPublicKey = secp.getPublicKey;
*/ */
export async function sign( export async function sign(
message: Uint8Array, message: Uint8Array,
privateKey: Uint8Array privateKey: Uint8Array,
): Promise<Uint8Array> { ): Promise<Uint8Array> {
const [signature, recoveryId] = await secp.sign(message, privateKey, { const [signature, recoveryId] = await secp.sign(message, privateKey, {
recovered: true, recovered: true,
@ -67,7 +67,7 @@ export async function sign(
}); });
return concat( return concat(
[signature, new Uint8Array([recoveryId])], [signature, new Uint8Array([recoveryId])],
signature.length + 1 signature.length + 1,
); );
} }

View File

@ -5,12 +5,12 @@ import { getSubtle, randomBytes } from "./index.js";
export async function encrypt( export async function encrypt(
iv: Uint8Array, iv: Uint8Array,
key: Uint8Array, key: Uint8Array,
clearText: Uint8Array clearText: Uint8Array,
): Promise<Uint8Array> { ): Promise<Uint8Array> {
return getSubtle() return getSubtle()
.importKey("raw", key, Symmetric.algorithm, false, ["encrypt"]) .importKey("raw", key, Symmetric.algorithm, false, ["encrypt"])
.then((cryptoKey) => .then((cryptoKey) =>
getSubtle().encrypt({ iv, ...Symmetric.algorithm }, cryptoKey, clearText) getSubtle().encrypt({ iv, ...Symmetric.algorithm }, cryptoKey, clearText),
) )
.then((cipher) => new Uint8Array(cipher)); .then((cipher) => new Uint8Array(cipher));
} }
@ -18,12 +18,16 @@ export async function encrypt(
export async function decrypt( export async function decrypt(
iv: Uint8Array, iv: Uint8Array,
key: Uint8Array, key: Uint8Array,
cipherText: Uint8Array cipherText: Uint8Array,
): Promise<Uint8Array> { ): Promise<Uint8Array> {
return getSubtle() return getSubtle()
.importKey("raw", key, Symmetric.algorithm, false, ["decrypt"]) .importKey("raw", key, Symmetric.algorithm, false, ["decrypt"])
.then((cryptoKey) => .then((cryptoKey) =>
getSubtle().decrypt({ iv, ...Symmetric.algorithm }, cryptoKey, cipherText) getSubtle().decrypt(
{ iv, ...Symmetric.algorithm },
cryptoKey,
cipherText,
),
) )
.then((clear) => new Uint8Array(clear)); .then((clear) => new Uint8Array(clear));
} }

View File

@ -15,7 +15,7 @@ export class DecodedMessage
proto: proto.WakuMessage, proto: proto.WakuMessage,
decodedPayload: Uint8Array, decodedPayload: Uint8Array,
public signature?: Uint8Array, public signature?: Uint8Array,
public signaturePublicKey?: Uint8Array public signaturePublicKey?: Uint8Array,
) { ) {
super(pubSubTopic, proto); super(pubSubTopic, proto);
this._decodedPayload = decodedPayload; this._decodedPayload = decodedPayload;

View File

@ -34,8 +34,8 @@ describe("Ecies Encryption", function () {
expect(result?.payload).to.deep.equal(payload); expect(result?.payload).to.deep.equal(payload);
expect(result.signature).to.be.undefined; expect(result.signature).to.be.undefined;
expect(result.signaturePublicKey).to.be.undefined; expect(result.signaturePublicKey).to.be.undefined;
} },
) ),
); );
}); });
@ -54,7 +54,7 @@ describe("Ecies Encryption", function () {
contentTopic, contentTopic,
payload, payload,
alicePrivateKey, alicePrivateKey,
bobPrivateKey bobPrivateKey,
) => { ) => {
const alicePublicKey = getPublicKey(alicePrivateKey); const alicePublicKey = getPublicKey(alicePrivateKey);
const bobPublicKey = getPublicKey(bobPrivateKey); const bobPublicKey = getPublicKey(bobPrivateKey);
@ -78,8 +78,8 @@ describe("Ecies Encryption", function () {
expect(result?.payload).to.deep.equal(payload); expect(result?.payload).to.deep.equal(payload);
expect(result.signature).to.not.be.undefined; expect(result.signature).to.not.be.undefined;
expect(result.signaturePublicKey).to.deep.eq(alicePublicKey); expect(result.signaturePublicKey).to.deep.eq(alicePublicKey);
} },
) ),
); );
}); });
@ -93,7 +93,7 @@ describe("Ecies Encryption", function () {
async (pubSubTopic, contentTopic, payload, privateKey) => { async (pubSubTopic, contentTopic, payload, privateKey) => {
const publicKey = getPublicKey(privateKey); const publicKey = getPublicKey(privateKey);
const metaSetter = ( const metaSetter = (
msg: IProtoMessage & { meta: undefined } msg: IProtoMessage & { meta: undefined },
): Uint8Array => { ): Uint8Array => {
const buffer = new ArrayBuffer(4); const buffer = new ArrayBuffer(4);
const view = new DataView(buffer); const view = new DataView(buffer);
@ -125,8 +125,8 @@ describe("Ecies Encryption", function () {
}); });
expect(result.meta).to.deep.equal(expectedMeta); expect(result.meta).to.deep.equal(expectedMeta);
} },
) ),
); );
}); });
}); });

View File

@ -36,7 +36,7 @@ class Encoder implements IEncoder {
private publicKey: Uint8Array, private publicKey: Uint8Array,
private sigPrivKey?: Uint8Array, private sigPrivKey?: Uint8Array,
public ephemeral: boolean = false, public ephemeral: boolean = false,
public metaSetter?: IMetaSetter public metaSetter?: IMetaSetter,
) { ) {
if (!contentTopic || contentTopic === "") { if (!contentTopic || contentTopic === "") {
throw new Error("Content topic must be specified"); throw new Error("Content topic must be specified");
@ -106,18 +106,21 @@ export function createEncoder({
publicKey, publicKey,
sigPrivKey, sigPrivKey,
ephemeral, ephemeral,
metaSetter metaSetter,
); );
} }
class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> { class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
constructor(contentTopic: string, private privateKey: Uint8Array) { constructor(
contentTopic: string,
private privateKey: Uint8Array,
) {
super(contentTopic); super(contentTopic);
} }
async fromProtoObj( async fromProtoObj(
pubSubTopic: string, pubSubTopic: string,
protoMessage: IProtoMessage protoMessage: IProtoMessage,
): Promise<DecodedMessage | undefined> { ): Promise<DecodedMessage | undefined> {
const cipherPayload = protoMessage.payload; const cipherPayload = protoMessage.payload;
@ -126,7 +129,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
"Failed to decrypt due to incorrect version, expected:", "Failed to decrypt due to incorrect version, expected:",
Version, Version,
", actual:", ", actual:",
protoMessage.version protoMessage.version,
); );
return; return;
} }
@ -138,7 +141,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
} catch (e) { } catch (e) {
log( log(
`Failed to decrypt message using asymmetric decryption for contentTopic: ${this.contentTopic}`, `Failed to decrypt message using asymmetric decryption for contentTopic: ${this.contentTopic}`,
e e,
); );
return; return;
} }
@ -161,7 +164,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
protoMessage, protoMessage,
res.payload, res.payload,
res.sig?.signature, res.sig?.signature,
res.sig?.publicKey res.sig?.publicKey,
); );
} }
} }
@ -181,7 +184,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
*/ */
export function createDecoder( export function createDecoder(
contentTopic: string, contentTopic: string,
privateKey: Uint8Array privateKey: Uint8Array,
): Decoder { ): Decoder {
return new Decoder(contentTopic, privateKey); return new Decoder(contentTopic, privateKey);
} }

View File

@ -32,8 +32,8 @@ describe("Symmetric Encryption", function () {
expect(result?.payload).to.deep.equal(payload); expect(result?.payload).to.deep.equal(payload);
expect(result.signature).to.be.undefined; expect(result.signature).to.be.undefined;
expect(result.signaturePublicKey).to.be.undefined; expect(result.signaturePublicKey).to.be.undefined;
} },
) ),
); );
}); });
@ -67,8 +67,8 @@ describe("Symmetric Encryption", function () {
expect(result?.payload).to.deep.equal(payload); expect(result?.payload).to.deep.equal(payload);
expect(result.signature).to.not.be.undefined; expect(result.signature).to.not.be.undefined;
expect(result.signaturePublicKey).to.deep.eq(sigPubKey); expect(result.signaturePublicKey).to.deep.eq(sigPubKey);
} },
) ),
); );
}); });
@ -81,7 +81,7 @@ describe("Symmetric Encryption", function () {
fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }), fc.uint8Array({ min: 1, minLength: 32, maxLength: 32 }),
async (pubSubTopic, contentTopic, payload, symKey) => { async (pubSubTopic, contentTopic, payload, symKey) => {
const metaSetter = ( const metaSetter = (
msg: IProtoMessage & { meta: undefined } msg: IProtoMessage & { meta: undefined },
): Uint8Array => { ): Uint8Array => {
const buffer = new ArrayBuffer(4); const buffer = new ArrayBuffer(4);
const view = new DataView(buffer); const view = new DataView(buffer);
@ -113,8 +113,8 @@ describe("Symmetric Encryption", function () {
}); });
expect(result.meta).to.deep.equal(expectedMeta); expect(result.meta).to.deep.equal(expectedMeta);
} },
) ),
); );
}); });
}); });

View File

@ -31,7 +31,7 @@ class Encoder implements IEncoder {
private symKey: Uint8Array, private symKey: Uint8Array,
private sigPrivKey?: Uint8Array, private sigPrivKey?: Uint8Array,
public ephemeral: boolean = false, public ephemeral: boolean = false,
public metaSetter?: IMetaSetter public metaSetter?: IMetaSetter,
) { ) {
if (!contentTopic || contentTopic === "") { if (!contentTopic || contentTopic === "") {
throw new Error("Content topic must be specified"); throw new Error("Content topic must be specified");
@ -101,13 +101,16 @@ export function createEncoder({
} }
class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> { class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
constructor(contentTopic: string, private symKey: Uint8Array) { constructor(
contentTopic: string,
private symKey: Uint8Array,
) {
super(contentTopic); super(contentTopic);
} }
async fromProtoObj( async fromProtoObj(
pubSubTopic: string, pubSubTopic: string,
protoMessage: IProtoMessage protoMessage: IProtoMessage,
): Promise<DecodedMessage | undefined> { ): Promise<DecodedMessage | undefined> {
const cipherPayload = protoMessage.payload; const cipherPayload = protoMessage.payload;
@ -116,7 +119,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
"Failed to decrypt due to incorrect version, expected:", "Failed to decrypt due to incorrect version, expected:",
Version, Version,
", actual:", ", actual:",
protoMessage.version protoMessage.version,
); );
return; return;
} }
@ -128,7 +131,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
} catch (e) { } catch (e) {
log( log(
`Failed to decrypt message using asymmetric decryption for contentTopic: ${this.contentTopic}`, `Failed to decrypt message using asymmetric decryption for contentTopic: ${this.contentTopic}`,
e e,
); );
return; return;
} }
@ -151,7 +154,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
protoMessage, protoMessage,
res.payload, res.payload,
res.sig?.signature, res.sig?.signature,
res.sig?.publicKey res.sig?.publicKey,
); );
} }
} }
@ -171,7 +174,7 @@ class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
*/ */
export function createDecoder( export function createDecoder(
contentTopic: string, contentTopic: string,
symKey: Uint8Array symKey: Uint8Array,
): Decoder { ): Decoder {
return new Decoder(contentTopic, symKey); return new Decoder(contentTopic, symKey);
} }

View File

@ -24,8 +24,8 @@ describe("Waku Payload", () => {
const res = await decryptAsymmetric(enc, privKey); const res = await decryptAsymmetric(enc, privKey);
expect(res).deep.equal(message); expect(res).deep.equal(message);
} },
) ),
); );
}); });
@ -39,8 +39,8 @@ describe("Waku Payload", () => {
const res = await decryptSymmetric(enc, key); const res = await decryptSymmetric(enc, key);
expect(res).deep.equal(message); expect(res).deep.equal(message);
} },
) ),
); );
}); });
@ -52,9 +52,9 @@ describe("Waku Payload", () => {
expect(res?.payload).deep.equal( expect(res?.payload).deep.equal(
message, message,
"Payload was not encrypted then decrypted correctly" "Payload was not encrypted then decrypted correctly",
); );
}) }),
); );
}); });
@ -71,14 +71,14 @@ describe("Waku Payload", () => {
expect(res?.payload).deep.equal( expect(res?.payload).deep.equal(
message, message,
"Payload was not encrypted then decrypted correctly" "Payload was not encrypted then decrypted correctly",
); );
expect(res?.sig?.publicKey).deep.equal( expect(res?.sig?.publicKey).deep.equal(
sigPubKey, sigPubKey,
"signature Public key was not recovered from encrypted then decrypted signature" "signature Public key was not recovered from encrypted then decrypted signature",
); );
} },
) ),
); );
}); });
}); });

View File

@ -21,7 +21,7 @@ function getSizeOfPayloadSizeField(message: Uint8Array): number {
function getPayloadSize( function getPayloadSize(
message: Uint8Array, message: Uint8Array,
sizeOfPayloadSizeField: number sizeOfPayloadSizeField: number,
): number { ): number {
let payloadSizeBytes = message.slice(1, 1 + sizeOfPayloadSizeField); let payloadSizeBytes = message.slice(1, 1 + sizeOfPayloadSizeField);
// int 32 == 4 bytes // int 32 == 4 bytes
@ -29,7 +29,7 @@ function getPayloadSize(
// If less than 4 bytes pad right (Little Endian). // If less than 4 bytes pad right (Little Endian).
payloadSizeBytes = concat( payloadSizeBytes = concat(
[payloadSizeBytes, new Uint8Array(4 - sizeOfPayloadSizeField)], [payloadSizeBytes, new Uint8Array(4 - sizeOfPayloadSizeField)],
4 4,
); );
} }
const payloadSizeDataView = new DataView(payloadSizeBytes.buffer); const payloadSizeDataView = new DataView(payloadSizeBytes.buffer);
@ -50,7 +50,7 @@ function isMessageSigned(message: Uint8Array): boolean {
*/ */
export async function encryptAsymmetric( export async function encryptAsymmetric(
data: Uint8Array, data: Uint8Array,
publicKey: Uint8Array | string publicKey: Uint8Array | string,
): Promise<Uint8Array> { ): Promise<Uint8Array> {
return ecies.encrypt(hexToBytes(publicKey), data); return ecies.encrypt(hexToBytes(publicKey), data);
} }
@ -63,7 +63,7 @@ export async function encryptAsymmetric(
*/ */
export async function decryptAsymmetric( export async function decryptAsymmetric(
payload: Uint8Array, payload: Uint8Array,
privKey: Uint8Array privKey: Uint8Array,
): Promise<Uint8Array> { ): Promise<Uint8Array> {
return ecies.decrypt(privKey, payload); return ecies.decrypt(privKey, payload);
} }
@ -79,7 +79,7 @@ export async function decryptAsymmetric(
*/ */
export async function encryptSymmetric( export async function encryptSymmetric(
data: Uint8Array, data: Uint8Array,
key: Uint8Array | string key: Uint8Array | string,
): Promise<Uint8Array> { ): Promise<Uint8Array> {
const iv = symmetric.generateIv(); const iv = symmetric.generateIv();
@ -99,7 +99,7 @@ export async function encryptSymmetric(
*/ */
export async function decryptSymmetric( export async function decryptSymmetric(
payload: Uint8Array, payload: Uint8Array,
key: Uint8Array | string key: Uint8Array | string,
): Promise<Uint8Array> { ): Promise<Uint8Array> {
const ivStart = payload.length - Symmetric.ivSize; const ivStart = payload.length - Symmetric.ivSize;
const cipher = payload.slice(0, ivStart); const cipher = payload.slice(0, ivStart);
@ -135,7 +135,7 @@ function computeSizeOfPayloadSizeField(payload: Uint8Array): number {
function validateDataIntegrity( function validateDataIntegrity(
value: Uint8Array, value: Uint8Array,
expectedSize: number expectedSize: number,
): boolean { ): boolean {
if (value.length !== expectedSize) { if (value.length !== expectedSize) {
return false; return false;
@ -157,7 +157,7 @@ function getHash(message: Uint8Array, isSigned: boolean): Uint8Array {
function ecRecoverPubKey( function ecRecoverPubKey(
messageHash: Uint8Array, messageHash: Uint8Array,
signature: Uint8Array signature: Uint8Array,
): Uint8Array | undefined { ): Uint8Array | undefined {
const recoveryDataView = new DataView(signature.slice(64).buffer); const recoveryDataView = new DataView(signature.slice(64).buffer);
const recovery = recoveryDataView.getUint8(0); const recovery = recoveryDataView.getUint8(0);
@ -175,7 +175,7 @@ function ecRecoverPubKey(
*/ */
export async function preCipher( export async function preCipher(
messagePayload: Uint8Array, messagePayload: Uint8Array,
sigPrivKey?: Uint8Array sigPrivKey?: Uint8Array,
): Promise<Uint8Array> { ): Promise<Uint8Array> {
let envelope = new Uint8Array([0]); // No flags let envelope = new Uint8Array([0]); // No flags
envelope = addPayloadSizeField(envelope, messagePayload); envelope = addPayloadSizeField(envelope, messagePayload);
@ -216,7 +216,7 @@ export async function preCipher(
* @internal * @internal
*/ */
export function postCipher( export function postCipher(
message: Uint8Array message: Uint8Array,
): { payload: Uint8Array; sig?: Signature } | undefined { ): { payload: Uint8Array; sig?: Signature } | undefined {
const sizeOfPayloadSizeField = getSizeOfPayloadSizeField(message); const sizeOfPayloadSizeField = getSizeOfPayloadSizeField(message);
if (sizeOfPayloadSizeField === 0) return; if (sizeOfPayloadSizeField === 0) return;

View File

@ -33,12 +33,10 @@
"build:esm": "tsc", "build:esm": "tsc",
"build:bundle": "rollup --config rollup.config.js", "build:bundle": "rollup --config rollup.config.js",
"fix": "run-s fix:*", "fix": "run-s fix:*",
"fix:prettier": "prettier . --write",
"fix:lint": "eslint src *.js --fix", "fix:lint": "eslint src *.js --fix",
"check": "run-s check:*", "check": "run-s check:*",
"check:tsc": "tsc -p tsconfig.dev.json", "check:tsc": "tsc -p tsconfig.dev.json",
"check:lint": "eslint src *.js", "check:lint": "eslint src *.js",
"check:prettier": "prettier . --list-different",
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"", "check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
"test": "run-s test:*", "test": "run-s test:*",
"test:node": "TS_NODE_PROJECT=./tsconfig.dev.json mocha", "test:node": "TS_NODE_PROJECT=./tsconfig.dev.json mocha",
@ -75,7 +73,6 @@
"karma-webpack": "^5.0.0", "karma-webpack": "^5.0.0",
"mocha": "^10.2.0", "mocha": "^10.2.0",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"prettier": "^2.8.4",
"process": "^0.11.10", "process": "^0.11.10",
"puppeteer": "^20.4.0", "puppeteer": "^20.4.0",
"rollup": "^3.15.0", "rollup": "^3.15.0",

View File

@ -8,7 +8,7 @@ import { concat, utf8ToBytes } from "@waku/utils/bytes";
*/ */
export function messageHash( export function messageHash(
pubsubTopic: string, pubsubTopic: string,
message: IProtoMessage message: IProtoMessage,
): Uint8Array { ): Uint8Array {
const pubsubTopicBytes = utf8ToBytes(pubsubTopic); const pubsubTopicBytes = utf8ToBytes(pubsubTopic);
const contentTopicBytes = utf8ToBytes(message.contentTopic); const contentTopicBytes = utf8ToBytes(message.contentTopic);

View File

@ -74,7 +74,6 @@
"chai": "^4.3.7", "chai": "^4.3.7",
"cspell": "^6.31.1", "cspell": "^6.31.1",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"rollup": "^3.21.3", "rollup": "^3.21.3",
"ts-loader": "^9.4.2", "ts-loader": "^9.4.2",
"typescript": "^5.0.4", "typescript": "^5.0.4",

View File

@ -37,7 +37,7 @@ export class WakuPeerExchange extends BaseProtocol implements IPeerExchange {
* Make a peer exchange query to a peer * Make a peer exchange query to a peer
*/ */
async query( async query(
params: PeerExchangeQueryParams params: PeerExchangeQueryParams,
): Promise<PeerInfo[] | undefined> { ): Promise<PeerInfo[] | undefined> {
const { numPeers } = params; const { numPeers } = params;
@ -54,7 +54,7 @@ export class WakuPeerExchange extends BaseProtocol implements IPeerExchange {
lp.encode, lp.encode,
stream, stream,
lp.decode, lp.decode,
async (source) => await all(source) async (source) => await all(source),
); );
try { try {
@ -76,7 +76,7 @@ export class WakuPeerExchange extends BaseProtocol implements IPeerExchange {
.filter(isDefined) .filter(isDefined)
.map(async (enr) => { .map(async (enr) => {
return { ENR: await EnrDecoder.fromRLP(enr) }; return { ENR: await EnrDecoder.fromRLP(enr) };
}) }),
); );
} catch (err) { } catch (err) {
log("Failed to decode push reply", err); log("Failed to decode push reply", err);
@ -90,7 +90,7 @@ export class WakuPeerExchange extends BaseProtocol implements IPeerExchange {
* @returns A function that creates a new peer exchange protocol * @returns A function that creates a new peer exchange protocol
*/ */
export function wakuPeerExchange(): ( export function wakuPeerExchange(): (
components: Libp2pComponents components: Libp2pComponents,
) => WakuPeerExchange { ) => WakuPeerExchange {
return (components: Libp2pComponents) => new WakuPeerExchange(components); return (components: Libp2pComponents) => new WakuPeerExchange(components);
} }

View File

@ -61,7 +61,7 @@ export class PeerExchangeDiscovery
private queryAttempts: Map<string, number> = new Map(); private queryAttempts: Map<string, number> = new Map();
private readonly handleDiscoveredPeer = ( private readonly handleDiscoveredPeer = (
event: CustomEvent<PeerUpdate> event: CustomEvent<PeerUpdate>,
): void => { ): void => {
const { const {
peer: { protocols, id: peerId }, peer: { protocols, id: peerId },
@ -74,7 +74,7 @@ export class PeerExchangeDiscovery
this.queryingPeers.add(peerId.toString()); this.queryingPeers.add(peerId.toString());
this.startRecurringQueries(peerId).catch((error) => this.startRecurringQueries(peerId).catch((error) =>
log(`Error querying peer ${error}`) log(`Error querying peer ${error}`),
); );
}; };
@ -99,7 +99,7 @@ export class PeerExchangeDiscovery
// might be better to use "peer:identify" or "peer:update" // might be better to use "peer:identify" or "peer:update"
this.components.events.addEventListener( this.components.events.addEventListener(
"peer:update", "peer:update",
this.handleDiscoveredPeer this.handleDiscoveredPeer,
); );
} }
@ -113,7 +113,7 @@ export class PeerExchangeDiscovery
this.queryingPeers.clear(); this.queryingPeers.clear();
this.components.events.removeEventListener( this.components.events.removeEventListener(
"peer:update", "peer:update",
this.handleDiscoveredPeer this.handleDiscoveredPeer,
); );
} }
@ -126,7 +126,7 @@ export class PeerExchangeDiscovery
} }
private readonly startRecurringQueries = async ( private readonly startRecurringQueries = async (
peerId: PeerId peerId: PeerId,
): Promise<void> => { ): Promise<void> => {
const peerIdStr = peerId.toString(); const peerIdStr = peerId.toString();
const { const {
@ -137,7 +137,7 @@ export class PeerExchangeDiscovery
log( log(
`Querying peer: ${peerIdStr} (attempt ${ `Querying peer: ${peerIdStr} (attempt ${
this.queryAttempts.get(peerIdStr) ?? 1 this.queryAttempts.get(peerIdStr) ?? 1
})` })`,
); );
await this.query(peerId); await this.query(peerId);
@ -204,7 +204,7 @@ export class PeerExchangeDiscovery
protocols: [], protocols: [],
multiaddrs: peerInfo.multiaddrs, multiaddrs: peerInfo.multiaddrs,
}, },
}) }),
); );
} }
} }
@ -217,7 +217,7 @@ export class PeerExchangeDiscovery
} }
export function wakuPeerExchangeDiscovery(): ( export function wakuPeerExchangeDiscovery(): (
components: Libp2pComponents components: Libp2pComponents,
) => PeerExchangeDiscovery { ) => PeerExchangeDiscovery {
return (components: Libp2pComponents) => return (components: Libp2pComponents) =>
new PeerExchangeDiscovery(components); new PeerExchangeDiscovery(components);

View File

@ -53,7 +53,6 @@
"@waku/build-utils": "*", "@waku/build-utils": "*",
"cspell": "^6.31.1", "cspell": "^6.31.1",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"protons": "^7.0.2", "protons": "^7.0.2",
"rollup": "^3.21.3", "rollup": "^3.21.3",
"typescript": "^5.0.4", "typescript": "^5.0.4",

View File

@ -60,7 +60,7 @@ export namespace FilterRequest {
} }
return obj; return obj;
} },
); );
} }
@ -130,8 +130,8 @@ export namespace FilterRequest {
obj.contentFilters.push( obj.contentFilters.push(
FilterRequest.ContentFilter.codec().decode( FilterRequest.ContentFilter.codec().decode(
reader, reader,
reader.uint32() reader.uint32(),
) ),
); );
break; break;
default: default:
@ -141,7 +141,7 @@ export namespace FilterRequest {
} }
return obj; return obj;
} },
); );
} }
@ -196,7 +196,7 @@ export namespace MessagePush {
switch (tag >>> 3) { switch (tag >>> 3) {
case 1: case 1:
obj.messages.push( obj.messages.push(
WakuMessage.codec().decode(reader, reader.uint32()) WakuMessage.codec().decode(reader, reader.uint32()),
); );
break; break;
default: default:
@ -206,7 +206,7 @@ export namespace MessagePush {
} }
return obj; return obj;
} },
); );
} }
@ -275,7 +275,7 @@ export namespace FilterRpc {
case 2: case 2:
obj.request = FilterRequest.codec().decode( obj.request = FilterRequest.codec().decode(
reader, reader,
reader.uint32() reader.uint32(),
); );
break; break;
case 3: case 3:
@ -288,7 +288,7 @@ export namespace FilterRpc {
} }
return obj; return obj;
} },
); );
} }
@ -409,7 +409,7 @@ export namespace RateLimitProof {
} }
return obj; return obj;
} },
); );
} }
@ -515,7 +515,7 @@ export namespace WakuMessage {
case 21: case 21:
obj.rateLimitProof = RateLimitProof.codec().decode( obj.rateLimitProof = RateLimitProof.codec().decode(
reader, reader,
reader.uint32() reader.uint32(),
); );
break; break;
case 31: case 31:
@ -528,7 +528,7 @@ export namespace WakuMessage {
} }
return obj; return obj;
} },
); );
} }

View File

@ -63,7 +63,7 @@ export namespace FilterSubscribeRequest {
w.uint32(16); w.uint32(16);
FilterSubscribeRequest.FilterSubscribeType.codec().encode( FilterSubscribeRequest.FilterSubscribeType.codec().encode(
obj.filterSubscribeType, obj.filterSubscribeType,
w w,
); );
} }
@ -102,7 +102,7 @@ export namespace FilterSubscribeRequest {
case 2: case 2:
obj.filterSubscribeType = obj.filterSubscribeType =
FilterSubscribeRequest.FilterSubscribeType.codec().decode( FilterSubscribeRequest.FilterSubscribeType.codec().decode(
reader reader,
); );
break; break;
case 10: case 10:
@ -118,7 +118,7 @@ export namespace FilterSubscribeRequest {
} }
return obj; return obj;
} },
); );
} }
@ -130,7 +130,7 @@ export namespace FilterSubscribeRequest {
}; };
export const decode = ( export const decode = (
buf: Uint8Array | Uint8ArrayList buf: Uint8Array | Uint8ArrayList,
): FilterSubscribeRequest => { ): FilterSubscribeRequest => {
return decodeMessage(buf, FilterSubscribeRequest.codec()); return decodeMessage(buf, FilterSubscribeRequest.codec());
}; };
@ -200,7 +200,7 @@ export namespace FilterSubscribeResponse {
} }
return obj; return obj;
} },
); );
} }
@ -212,7 +212,7 @@ export namespace FilterSubscribeResponse {
}; };
export const decode = ( export const decode = (
buf: Uint8Array | Uint8ArrayList buf: Uint8Array | Uint8ArrayList,
): FilterSubscribeResponse => { ): FilterSubscribeResponse => {
return decodeMessage(buf, FilterSubscribeResponse.codec()); return decodeMessage(buf, FilterSubscribeResponse.codec());
}; };
@ -260,7 +260,7 @@ export namespace MessagePush {
case 1: case 1:
obj.wakuMessage = WakuMessage.codec().decode( obj.wakuMessage = WakuMessage.codec().decode(
reader, reader,
reader.uint32() reader.uint32(),
); );
break; break;
case 2: case 2:
@ -273,7 +273,7 @@ export namespace MessagePush {
} }
return obj; return obj;
} },
); );
} }
@ -394,7 +394,7 @@ export namespace RateLimitProof {
} }
return obj; return obj;
} },
); );
} }
@ -500,7 +500,7 @@ export namespace WakuMessage {
case 21: case 21:
obj.rateLimitProof = RateLimitProof.codec().decode( obj.rateLimitProof = RateLimitProof.codec().decode(
reader, reader,
reader.uint32() reader.uint32(),
); );
break; break;
case 31: case 31:
@ -513,7 +513,7 @@ export namespace WakuMessage {
} }
return obj; return obj;
} },
); );
} }

View File

@ -55,7 +55,7 @@ export namespace PushRequest {
case 2: case 2:
obj.message = WakuMessage.codec().decode( obj.message = WakuMessage.codec().decode(
reader, reader,
reader.uint32() reader.uint32(),
); );
break; break;
default: default:
@ -65,7 +65,7 @@ export namespace PushRequest {
} }
return obj; return obj;
} },
); );
} }
@ -135,7 +135,7 @@ export namespace PushResponse {
} }
return obj; return obj;
} },
); );
} }
@ -204,13 +204,13 @@ export namespace PushRpc {
case 2: case 2:
obj.request = PushRequest.codec().decode( obj.request = PushRequest.codec().decode(
reader, reader,
reader.uint32() reader.uint32(),
); );
break; break;
case 3: case 3:
obj.response = PushResponse.codec().decode( obj.response = PushResponse.codec().decode(
reader, reader,
reader.uint32() reader.uint32(),
); );
break; break;
default: default:
@ -220,7 +220,7 @@ export namespace PushRpc {
} }
return obj; return obj;
} },
); );
} }
@ -341,7 +341,7 @@ export namespace RateLimitProof {
} }
return obj; return obj;
} },
); );
} }
@ -447,7 +447,7 @@ export namespace WakuMessage {
case 21: case 21:
obj.rateLimitProof = RateLimitProof.codec().decode( obj.rateLimitProof = RateLimitProof.codec().decode(
reader, reader,
reader.uint32() reader.uint32(),
); );
break; break;
case 31: case 31:
@ -460,7 +460,7 @@ export namespace WakuMessage {
} }
return obj; return obj;
} },
); );
} }

View File

@ -113,7 +113,7 @@ export namespace RateLimitProof {
} }
return obj; return obj;
} },
); );
} }
@ -219,7 +219,7 @@ export namespace WakuMessage {
case 21: case 21:
obj.rateLimitProof = RateLimitProof.codec().decode( obj.rateLimitProof = RateLimitProof.codec().decode(
reader, reader,
reader.uint32() reader.uint32(),
); );
break; break;
case 31: case 31:
@ -232,7 +232,7 @@ export namespace WakuMessage {
} }
return obj; return obj;
} },
); );
} }

View File

@ -51,7 +51,7 @@ export namespace PeerInfo {
} }
return obj; return obj;
} },
); );
} }
@ -110,7 +110,7 @@ export namespace PeerExchangeQuery {
} }
return obj; return obj;
} },
); );
} }
@ -122,7 +122,7 @@ export namespace PeerExchangeQuery {
}; };
export const decode = ( export const decode = (
buf: Uint8Array | Uint8ArrayList buf: Uint8Array | Uint8ArrayList,
): PeerExchangeQuery => { ): PeerExchangeQuery => {
return decodeMessage(buf, PeerExchangeQuery.codec()); return decodeMessage(buf, PeerExchangeQuery.codec());
}; };
@ -167,7 +167,7 @@ export namespace PeerExchangeResponse {
switch (tag >>> 3) { switch (tag >>> 3) {
case 1: case 1:
obj.peerInfos.push( obj.peerInfos.push(
PeerInfo.codec().decode(reader, reader.uint32()) PeerInfo.codec().decode(reader, reader.uint32()),
); );
break; break;
default: default:
@ -177,7 +177,7 @@ export namespace PeerExchangeResponse {
} }
return obj; return obj;
} },
); );
} }
@ -189,7 +189,7 @@ export namespace PeerExchangeResponse {
}; };
export const decode = ( export const decode = (
buf: Uint8Array | Uint8ArrayList buf: Uint8Array | Uint8ArrayList,
): PeerExchangeResponse => { ): PeerExchangeResponse => {
return decodeMessage(buf, PeerExchangeResponse.codec()); return decodeMessage(buf, PeerExchangeResponse.codec());
}; };
@ -237,13 +237,13 @@ export namespace PeerExchangeRPC {
case 1: case 1:
obj.query = PeerExchangeQuery.codec().decode( obj.query = PeerExchangeQuery.codec().decode(
reader, reader,
reader.uint32() reader.uint32(),
); );
break; break;
case 2: case 2:
obj.response = PeerExchangeResponse.codec().decode( obj.response = PeerExchangeResponse.codec().decode(
reader, reader,
reader.uint32() reader.uint32(),
); );
break; break;
default: default:
@ -253,7 +253,7 @@ export namespace PeerExchangeRPC {
} }
return obj; return obj;
} },
); );
} }

View File

@ -88,7 +88,7 @@ export namespace Index {
} }
return obj; return obj;
} },
); );
} }
@ -181,7 +181,7 @@ export namespace PagingInfo {
} }
return obj; return obj;
} },
); );
} }
@ -242,7 +242,7 @@ export namespace ContentFilter {
} }
return obj; return obj;
} },
); );
} }
@ -324,13 +324,13 @@ export namespace HistoryQuery {
break; break;
case 3: case 3:
obj.contentFilters.push( obj.contentFilters.push(
ContentFilter.codec().decode(reader, reader.uint32()) ContentFilter.codec().decode(reader, reader.uint32()),
); );
break; break;
case 4: case 4:
obj.pagingInfo = PagingInfo.codec().decode( obj.pagingInfo = PagingInfo.codec().decode(
reader, reader,
reader.uint32() reader.uint32(),
); );
break; break;
case 5: case 5:
@ -346,7 +346,7 @@ export namespace HistoryQuery {
} }
return obj; return obj;
} },
); );
} }
@ -430,13 +430,13 @@ export namespace HistoryResponse {
switch (tag >>> 3) { switch (tag >>> 3) {
case 2: case 2:
obj.messages.push( obj.messages.push(
WakuMessage.codec().decode(reader, reader.uint32()) WakuMessage.codec().decode(reader, reader.uint32()),
); );
break; break;
case 3: case 3:
obj.pagingInfo = PagingInfo.codec().decode( obj.pagingInfo = PagingInfo.codec().decode(
reader, reader,
reader.uint32() reader.uint32(),
); );
break; break;
case 4: case 4:
@ -449,7 +449,7 @@ export namespace HistoryResponse {
} }
return obj; return obj;
} },
); );
} }
@ -518,13 +518,13 @@ export namespace HistoryRpc {
case 2: case 2:
obj.query = HistoryQuery.codec().decode( obj.query = HistoryQuery.codec().decode(
reader, reader,
reader.uint32() reader.uint32(),
); );
break; break;
case 3: case 3:
obj.response = HistoryResponse.codec().decode( obj.response = HistoryResponse.codec().decode(
reader, reader,
reader.uint32() reader.uint32(),
); );
break; break;
default: default:
@ -534,7 +534,7 @@ export namespace HistoryRpc {
} }
return obj; return obj;
} },
); );
} }
@ -655,7 +655,7 @@ export namespace RateLimitProof {
} }
return obj; return obj;
} },
); );
} }
@ -761,7 +761,7 @@ export namespace WakuMessage {
case 21: case 21:
obj.rateLimitProof = RateLimitProof.codec().decode( obj.rateLimitProof = RateLimitProof.codec().decode(
reader, reader,
reader.uint32() reader.uint32(),
); );
break; break;
case 31: case 31:
@ -774,7 +774,7 @@ export namespace WakuMessage {
} }
return obj; return obj;
} },
); );
} }

View File

@ -53,7 +53,7 @@ export namespace TopicOnlyMessage {
} }
return obj; return obj;
} },
); );
} }
@ -65,7 +65,7 @@ export namespace TopicOnlyMessage {
}; };
export const decode = ( export const decode = (
buf: Uint8Array | Uint8ArrayList buf: Uint8Array | Uint8ArrayList,
): TopicOnlyMessage => { ): TopicOnlyMessage => {
return decodeMessage(buf, TopicOnlyMessage.codec()); return decodeMessage(buf, TopicOnlyMessage.codec());
}; };

File diff suppressed because it is too large Load Diff

View File

@ -61,7 +61,7 @@ class Relay implements IRelay {
constructor(libp2p: Libp2p, options?: Partial<RelayCreateOptions>) { constructor(libp2p: Libp2p, options?: Partial<RelayCreateOptions>) {
if (!this.isRelayPubSub(libp2p.services.pubsub)) { if (!this.isRelayPubSub(libp2p.services.pubsub)) {
throw Error( throw Error(
`Failed to initialize Relay. libp2p.pubsub does not support ${Relay.multicodec}` `Failed to initialize Relay. libp2p.pubsub does not support ${Relay.multicodec}`,
); );
} }
@ -125,7 +125,7 @@ class Relay implements IRelay {
*/ */
public subscribe<T extends IDecodedMessage>( public subscribe<T extends IDecodedMessage>(
decoders: IDecoder<T> | IDecoder<T>[], decoders: IDecoder<T> | IDecoder<T>[],
callback: Callback<T> callback: Callback<T>,
): () => void { ): () => void {
const contentTopicToObservers = Array.isArray(decoders) const contentTopicToObservers = Array.isArray(decoders)
? toObservers(decoders, callback) ? toObservers(decoders, callback)
@ -147,7 +147,7 @@ class Relay implements IRelay {
const nextObservers = leftMinusJoin( const nextObservers = leftMinusJoin(
currentObservers, currentObservers,
observersToRemove observersToRemove,
); );
if (nextObservers.size) { if (nextObservers.size) {
@ -161,7 +161,7 @@ class Relay implements IRelay {
public toSubscriptionIterator<T extends IDecodedMessage>( public toSubscriptionIterator<T extends IDecodedMessage>(
decoders: IDecoder<T> | IDecoder<T>[], decoders: IDecoder<T> | IDecoder<T>[],
opts?: ProtocolOptions | undefined opts?: ProtocolOptions | undefined,
): Promise<IAsyncIterator<T>> { ): Promise<IAsyncIterator<T>> {
return toAsyncIterator(this, decoders, opts); return toAsyncIterator(this, decoders, opts);
} }
@ -178,7 +178,7 @@ class Relay implements IRelay {
private async processIncomingMessage<T extends IDecodedMessage>( private async processIncomingMessage<T extends IDecodedMessage>(
pubSubTopic: string, pubSubTopic: string,
bytes: Uint8Array bytes: Uint8Array,
): Promise<void> { ): Promise<void> {
const topicOnlyMsg = await this.defaultDecoder.fromWireToProtoObj(bytes); const topicOnlyMsg = await this.defaultDecoder.fromWireToProtoObj(bytes);
if (!topicOnlyMsg || !topicOnlyMsg.contentTopic) { if (!topicOnlyMsg || !topicOnlyMsg.contentTopic) {
@ -199,7 +199,7 @@ class Relay implements IRelay {
const protoMsg = await decoder.fromWireToProtoObj(bytes); const protoMsg = await decoder.fromWireToProtoObj(bytes);
if (!protoMsg) { if (!protoMsg) {
log( log(
"Internal error: message previously decoded failed on 2nd pass." "Internal error: message previously decoded failed on 2nd pass.",
); );
return; return;
} }
@ -213,7 +213,7 @@ class Relay implements IRelay {
log("Error while decoding message:", error); log("Error while decoding message:", error);
} }
})(); })();
}) }),
); );
} }
@ -231,9 +231,9 @@ class Relay implements IRelay {
this.processIncomingMessage( this.processIncomingMessage(
event.detail.msg.topic, event.detail.msg.topic,
event.detail.msg.data event.detail.msg.data,
).catch((e) => log("Failed to process incoming message", e)); ).catch((e) => log("Failed to process incoming message", e));
} },
); );
this.gossipSub.topicValidators.set(pubSubTopic, messageValidator); this.gossipSub.topicValidators.set(pubSubTopic, messageValidator);
@ -246,13 +246,13 @@ class Relay implements IRelay {
} }
export function wakuRelay( export function wakuRelay(
init: Partial<ProtocolCreateOptions> = {} init: Partial<ProtocolCreateOptions> = {},
): (libp2p: Libp2p) => IRelay { ): (libp2p: Libp2p) => IRelay {
return (libp2p: Libp2p) => new Relay(libp2p, init); return (libp2p: Libp2p) => new Relay(libp2p, init);
} }
export function wakuGossipSub( export function wakuGossipSub(
init: Partial<RelayCreateOptions> = {} init: Partial<RelayCreateOptions> = {},
): (components: GossipSubComponents) => GossipSub { ): (components: GossipSubComponents) => GossipSub {
return (components: GossipSubComponents) => { return (components: GossipSubComponents) => {
init = { init = {
@ -270,10 +270,10 @@ export function wakuGossipSub(
function toObservers<T extends IDecodedMessage>( function toObservers<T extends IDecodedMessage>(
decoders: IDecoder<T>[], decoders: IDecoder<T>[],
callback: Callback<T> callback: Callback<T>,
): Map<ContentTopic, Set<Observer<T>>> { ): Map<ContentTopic, Set<Observer<T>>> {
const contentTopicToDecoders = Array.from( const contentTopicToDecoders = Array.from(
groupByContentTopic(decoders).entries() groupByContentTopic(decoders).entries(),
); );
const contentTopicToObserversEntries = contentTopicToDecoders.map( const contentTopicToObserversEntries = contentTopicToDecoders.map(
@ -286,10 +286,10 @@ function toObservers<T extends IDecodedMessage>(
({ ({
decoder, decoder,
callback, callback,
} as Observer<T>) }) as Observer<T>,
) ),
), ),
] as [ContentTopic, Set<Observer<T>>] ] as [ContentTopic, Set<Observer<T>>],
); );
return new Map(contentTopicToObserversEntries); return new Map(contentTopicToObserversEntries);

View File

@ -29,8 +29,8 @@ describe("Message Validator", () => {
const result = messageValidator(peerId, message); const result = messageValidator(peerId, message);
expect(result).to.eq(TopicValidatorResult.Accept); expect(result).to.eq(TopicValidatorResult.Accept);
} },
) ),
); );
}); });
@ -51,8 +51,8 @@ describe("Message Validator", () => {
const result = messageValidator(peerId, message); const result = messageValidator(peerId, message);
expect(result).to.eq(TopicValidatorResult.Reject); expect(result).to.eq(TopicValidatorResult.Reject);
} },
) ),
); );
}); });
}); });

View File

@ -8,7 +8,7 @@ const log = debug("waku:relay");
export function messageValidator( export function messageValidator(
peer: PeerId, peer: PeerId,
message: Message message: Message,
): TopicValidatorResult { ): TopicValidatorResult {
const startTime = performance.now(); const startTime = performance.now();
log(`validating message from ${peer} received on ${message.topic}`); log(`validating message from ${peer} received on ${message.topic}`);

View File

@ -17,7 +17,7 @@ export class TopicOnlyMessage implements IDecodedMessage {
constructor( constructor(
public pubSubTopic: string, public pubSubTopic: string,
private proto: ProtoTopicOnlyMessage private proto: ProtoTopicOnlyMessage,
) {} ) {}
get contentTopic(): string { get contentTopic(): string {
@ -44,7 +44,7 @@ export class TopicOnlyDecoder implements IDecoder<TopicOnlyMessage> {
async fromProtoObj( async fromProtoObj(
pubSubTopic: string, pubSubTopic: string,
proto: IProtoMessage proto: IProtoMessage,
): Promise<TopicOnlyMessage | undefined> { ): Promise<TopicOnlyMessage | undefined> {
return new TopicOnlyMessage(pubSubTopic, proto); return new TopicOnlyMessage(pubSubTopic, proto);
} }

View File

@ -81,7 +81,6 @@
"cspell": "^6.31.1", "cspell": "^6.31.1",
"interface-datastore": "^7.0.4", "interface-datastore": "^7.0.4",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"rollup": "^3.21.3", "rollup": "^3.21.3",
"typescript": "^5.0.4" "typescript": "^5.0.4"
}, },

View File

@ -40,7 +40,7 @@ export { Libp2pComponents };
* Uses Waku Filter V2 by default. * Uses Waku Filter V2 by default.
*/ */
export async function createLightNode( export async function createLightNode(
options?: ProtocolCreateOptions & WakuOptions options?: ProtocolCreateOptions & WakuOptions,
): Promise<LightNode> { ): Promise<LightNode> {
const libp2pOptions = options?.libp2p ?? {}; const libp2pOptions = options?.libp2p ?? {};
const peerDiscovery = libp2pOptions.peerDiscovery ?? []; const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
@ -52,7 +52,7 @@ export async function createLightNode(
const libp2p = await defaultLibp2p( const libp2p = await defaultLibp2p(
undefined, undefined,
libp2pOptions, libp2pOptions,
options?.userAgent options?.userAgent,
); );
const store = wakuStore(options); const store = wakuStore(options);
@ -64,7 +64,7 @@ export async function createLightNode(
libp2p, libp2p,
store, store,
lightPush, lightPush,
filter filter,
) as LightNode; ) as LightNode;
} }
@ -73,7 +73,7 @@ export async function createLightNode(
* enabling some privacy preserving properties. * enabling some privacy preserving properties.
*/ */
export async function createRelayNode( export async function createRelayNode(
options?: ProtocolCreateOptions & WakuOptions & Partial<RelayCreateOptions> options?: ProtocolCreateOptions & WakuOptions & Partial<RelayCreateOptions>,
): Promise<RelayNode> { ): Promise<RelayNode> {
const libp2pOptions = options?.libp2p ?? {}; const libp2pOptions = options?.libp2p ?? {};
const peerDiscovery = libp2pOptions.peerDiscovery ?? []; const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
@ -85,7 +85,7 @@ export async function createRelayNode(
const libp2p = await defaultLibp2p( const libp2p = await defaultLibp2p(
wakuGossipSub(options), wakuGossipSub(options),
libp2pOptions, libp2pOptions,
options?.userAgent options?.userAgent,
); );
const relay = wakuRelay(options); const relay = wakuRelay(options);
@ -96,7 +96,7 @@ export async function createRelayNode(
undefined, undefined,
undefined, undefined,
undefined, undefined,
relay relay,
) as RelayNode; ) as RelayNode;
} }
@ -114,7 +114,7 @@ export async function createRelayNode(
* @internal * @internal
*/ */
export async function createFullNode( export async function createFullNode(
options?: ProtocolCreateOptions & WakuOptions & Partial<RelayCreateOptions> options?: ProtocolCreateOptions & WakuOptions & Partial<RelayCreateOptions>,
): Promise<FullNode> { ): Promise<FullNode> {
const libp2pOptions = options?.libp2p ?? {}; const libp2pOptions = options?.libp2p ?? {};
const peerDiscovery = libp2pOptions.peerDiscovery ?? []; const peerDiscovery = libp2pOptions.peerDiscovery ?? [];
@ -126,7 +126,7 @@ export async function createFullNode(
const libp2p = await defaultLibp2p( const libp2p = await defaultLibp2p(
wakuGossipSub(options), wakuGossipSub(options),
libp2pOptions, libp2pOptions,
options?.userAgent options?.userAgent,
); );
const store = wakuStore(options); const store = wakuStore(options);
@ -140,12 +140,12 @@ export async function createFullNode(
store, store,
lightPush, lightPush,
filter, filter,
relay relay,
) as FullNode; ) as FullNode;
} }
export function defaultPeerDiscovery(): ( export function defaultPeerDiscovery(): (
components: Libp2pComponents components: Libp2pComponents,
) => PeerDiscovery { ) => PeerDiscovery {
return wakuDnsDiscovery([enrTree["PROD"]], DEFAULT_NODE_REQUIREMENTS); return wakuDnsDiscovery([enrTree["PROD"]], DEFAULT_NODE_REQUIREMENTS);
} }
@ -157,7 +157,7 @@ type PubsubService = {
export async function defaultLibp2p( export async function defaultLibp2p(
wakuGossipSub?: PubsubService["pubsub"], wakuGossipSub?: PubsubService["pubsub"],
options?: Partial<Libp2pOptions>, options?: Partial<Libp2pOptions>,
userAgent?: string userAgent?: string,
): Promise<Libp2p> { ): Promise<Libp2p> {
const pubsubService: PubsubService = wakuGossipSub const pubsubService: PubsubService = wakuGossipSub
? { pubsub: wakuGossipSub } ? { pubsub: wakuGossipSub }

View File

@ -66,22 +66,20 @@
"@libp2p/bootstrap": "^8.0.0", "@libp2p/bootstrap": "^8.0.0",
"@libp2p/interface-peer-discovery-compliance-tests": "^2.0.8", "@libp2p/interface-peer-discovery-compliance-tests": "^2.0.8",
"@libp2p/interface-peer-id": "^2.0.2", "@libp2p/interface-peer-id": "^2.0.2",
"@types/sinon": "^10.0.16",
"@types/chai": "^4.3.4", "@types/chai": "^4.3.4",
"@types/dockerode": "^3.3.17", "@types/dockerode": "^3.3.17",
"@types/mocha": "^10.0.1", "@types/mocha": "^10.0.1",
"@types/tail": "^2.2.1", "@types/tail": "^2.2.1",
"@typescript-eslint/eslint-plugin": "^5.57.0", "@waku/sdk": "*",
"@typescript-eslint/parser": "^5.62.0",
"@waku/dns-discovery": "*", "@waku/dns-discovery": "*",
"@waku/message-encryption": "*", "@waku/message-encryption": "*",
"@waku/peer-exchange": "*", "@waku/peer-exchange": "*",
"@waku/sdk": "*",
"chai": "^4.3.7", "chai": "^4.3.7",
"cspell": "^6.31.1", "cspell": "^6.31.1",
"debug": "^4.3.4", "debug": "^4.3.4",
"mocha": "^10.2.0", "mocha": "^10.2.0",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"typescript": "^5.0.4", "typescript": "^5.0.4",
"interface-datastore": "^8.2.3", "interface-datastore": "^8.2.3",
"libp2p": "^0.45.9", "libp2p": "^0.45.9",

View File

@ -12,7 +12,7 @@ export const NOISE_KEY_1 = new Uint8Array(
b.push(1); b.push(1);
} }
return b; return b;
})() })(),
); );
export const NOISE_KEY_2 = new Uint8Array( export const NOISE_KEY_2 = new Uint8Array(
@ -22,7 +22,7 @@ export const NOISE_KEY_2 = new Uint8Array(
b.push(2); b.push(2);
} }
return b; return b;
})() })(),
); );
export const NOISE_KEY_3 = new Uint8Array( export const NOISE_KEY_3 = new Uint8Array(
@ -32,5 +32,5 @@ export const NOISE_KEY_3 = new Uint8Array(
b.push(3); b.push(3);
} }
return b; return b;
})() })(),
); );

View File

@ -14,7 +14,7 @@ import { waitForFile } from "./async_fs.js";
export default async function waitForLine( export default async function waitForLine(
filepath: string, filepath: string,
logLine: string, logLine: string,
timeout: number timeout: number,
): Promise<void> { ): Promise<void> {
await pTimeout(waitForFile(filepath), { milliseconds: timeout }); await pTimeout(waitForFile(filepath), { milliseconds: timeout });

View File

@ -37,12 +37,12 @@ export default class Dockerode {
} }
private static async createNetwork( private static async createNetwork(
networkName: string = NETWORK_NAME networkName: string = NETWORK_NAME,
): Promise<Docker.Network> { ): Promise<Docker.Network> {
const docker = new Docker(); const docker = new Docker();
const networks = await docker.listNetworks(); const networks = await docker.listNetworks();
const existingNetwork = networks.find( const existingNetwork = networks.find(
(network) => network.Name === networkName (network) => network.Name === networkName,
); );
let network: Docker.Network; let network: Docker.Network;
@ -92,7 +92,7 @@ export default class Dockerode {
ports: number[], ports: number[],
args: Args, args: Args,
logPath: string, logPath: string,
wakuServiceNodeParams?: string wakuServiceNodeParams?: string,
): Promise<Docker.Container> { ): Promise<Docker.Container> {
const [rpcPort, tcpPort, websocketPort, discv5UdpPort] = ports; const [rpcPort, tcpPort, websocketPort, discv5UdpPort] = ports;
@ -150,7 +150,7 @@ export default class Dockerode {
if (stream) { if (stream) {
stream.pipe(logStream); stream.pipe(logStream);
} }
} },
); );
this.containerId = container.id; this.containerId = container.id;
@ -164,7 +164,7 @@ export default class Dockerode {
log( log(
`Shutting down container ID ${ `Shutting down container ID ${
this.containerId this.containerId
} at ${new Date().toLocaleTimeString()}` } at ${new Date().toLocaleTimeString()}`,
); );
await this.container.stop(); await this.container.stop();

View File

@ -136,7 +136,7 @@ export class NimGoNode {
...(isGoWaku && { minRelayPeersToPublish: 0, legacyFilter }), ...(isGoWaku && { minRelayPeersToPublish: 0, legacyFilter }),
}, },
{ rpcAddress: "0.0.0.0" }, { rpcAddress: "0.0.0.0" },
_args _args,
); );
process.env.WAKUNODE2_STORE_MESSAGE_DB_URL = ""; process.env.WAKUNODE2_STORE_MESSAGE_DB_URL = "";
@ -149,7 +149,7 @@ export class NimGoNode {
ports, ports,
mergedArgs, mergedArgs,
this.logPath, this.logPath,
WAKU_SERVICE_NODE_PARAMS WAKU_SERVICE_NODE_PARAMS,
); );
try { try {
@ -191,7 +191,7 @@ export class NimGoNode {
async sendMessage( async sendMessage(
message: MessageRpcQuery, message: MessageRpcQuery,
pubSubTopic: string = DefaultPubSubTopic pubSubTopic: string = DefaultPubSubTopic,
): Promise<boolean> { ): Promise<boolean> {
this.checkProcess(); this.checkProcess();
@ -206,13 +206,13 @@ export class NimGoNode {
} }
async messages( async messages(
pubsubTopic: string = DefaultPubSubTopic pubsubTopic: string = DefaultPubSubTopic,
): Promise<MessageRpcResponse[]> { ): Promise<MessageRpcResponse[]> {
this.checkProcess(); this.checkProcess();
const msgs = await this.rpcCall<MessageRpcResponse[]>( const msgs = await this.rpcCall<MessageRpcResponse[]>(
"get_waku_v2_relay_v1_messages", "get_waku_v2_relay_v1_messages",
[pubsubTopic] [pubsubTopic],
); );
return msgs.filter(isDefined); return msgs.filter(isDefined);
@ -239,7 +239,7 @@ export class NimGoNode {
async postAsymmetricMessage( async postAsymmetricMessage(
message: MessageRpcQuery, message: MessageRpcQuery,
publicKey: Uint8Array, publicKey: Uint8Array,
pubSubTopic?: string pubSubTopic?: string,
): Promise<boolean> { ): Promise<boolean> {
this.checkProcess(); this.checkProcess();
@ -256,7 +256,7 @@ export class NimGoNode {
async getAsymmetricMessages( async getAsymmetricMessages(
privateKey: Uint8Array, privateKey: Uint8Array,
pubSubTopic?: string pubSubTopic?: string,
): Promise<MessageRpcResponse[]> { ): Promise<MessageRpcResponse[]> {
this.checkProcess(); this.checkProcess();
@ -265,7 +265,7 @@ export class NimGoNode {
[ [
pubSubTopic ? pubSubTopic : DefaultPubSubTopic, pubSubTopic ? pubSubTopic : DefaultPubSubTopic,
"0x" + bytesToHex(privateKey), "0x" + bytesToHex(privateKey),
] ],
); );
} }
@ -274,14 +274,14 @@ export class NimGoNode {
return this.rpcCall<string>( return this.rpcCall<string>(
"get_waku_v2_private_v1_symmetric_key", "get_waku_v2_private_v1_symmetric_key",
[] [],
).then(hexToBytes); ).then(hexToBytes);
} }
async postSymmetricMessage( async postSymmetricMessage(
message: MessageRpcQuery, message: MessageRpcQuery,
symKey: Uint8Array, symKey: Uint8Array,
pubSubTopic?: string pubSubTopic?: string,
): Promise<boolean> { ): Promise<boolean> {
this.checkProcess(); this.checkProcess();
@ -298,7 +298,7 @@ export class NimGoNode {
async getSymmetricMessages( async getSymmetricMessages(
symKey: Uint8Array, symKey: Uint8Array,
pubSubTopic?: string pubSubTopic?: string,
): Promise<MessageRpcResponse[]> { ): Promise<MessageRpcResponse[]> {
this.checkProcess(); this.checkProcess();
@ -307,7 +307,7 @@ export class NimGoNode {
[ [
pubSubTopic ? pubSubTopic : DefaultPubSubTopic, pubSubTopic ? pubSubTopic : DefaultPubSubTopic,
"0x" + bytesToHex(symKey), "0x" + bytesToHex(symKey),
] ],
); );
} }
@ -323,7 +323,7 @@ export class NimGoNode {
const peerId = await this.getPeerId(); const peerId = await this.getPeerId();
this.multiaddrWithId = multiaddr( this.multiaddrWithId = multiaddr(
`/ip4/127.0.0.1/tcp/${this.websocketPort}/ws/p2p/${peerId.toString()}` `/ip4/127.0.0.1/tcp/${this.websocketPort}/ws/p2p/${peerId.toString()}`,
); );
return this.multiaddrWithId; return this.multiaddrWithId;
} }
@ -350,7 +350,7 @@ export class NimGoNode {
private async rpcCall<T>( private async rpcCall<T>(
method: string, method: string,
params: Array<string | number | unknown> params: Array<string | number | unknown>,
): Promise<T> { ): Promise<T> {
log("RPC Query: ", method, params); log("RPC Query: ", method, params);
const res = await fetch(this.rpcUrl, { const res = await fetch(this.rpcUrl, {

View File

@ -29,7 +29,7 @@ async function main() {
], ],
{ {
stdio: "inherit", stdio: "inherit",
} },
); );
mocha.on("error", (error) => { mocha.on("error", (error) => {

View File

@ -42,12 +42,12 @@ describe("ConnectionManager", function () {
EPeersByDiscoveryEvents.PEER_DISCOVERY_BOOTSTRAP, EPeersByDiscoveryEvents.PEER_DISCOVERY_BOOTSTRAP,
({ detail: receivedPeerId }) => { ({ detail: receivedPeerId }) => {
resolve(receivedPeerId.toString() === peerIdBootstrap.toString()); resolve(receivedPeerId.toString() === peerIdBootstrap.toString());
} },
); );
}); });
waku.libp2p.dispatchEvent( waku.libp2p.dispatchEvent(
new CustomEvent("peer", { detail: await createSecp256k1PeerId() }) new CustomEvent("peer", { detail: await createSecp256k1PeerId() }),
); );
expect(await peerDiscoveryBootstrap).to.eq(true); expect(await peerDiscoveryBootstrap).to.eq(true);
@ -70,12 +70,12 @@ describe("ConnectionManager", function () {
EPeersByDiscoveryEvents.PEER_DISCOVERY_PEER_EXCHANGE, EPeersByDiscoveryEvents.PEER_DISCOVERY_PEER_EXCHANGE,
({ detail: receivedPeerId }) => { ({ detail: receivedPeerId }) => {
resolve(receivedPeerId.toString() === peerIdPx.toString()); resolve(receivedPeerId.toString() === peerIdPx.toString());
} },
); );
}); });
waku.libp2p.dispatchEvent( waku.libp2p.dispatchEvent(
new CustomEvent("peer", { detail: peerIdPx }) new CustomEvent("peer", { detail: peerIdPx }),
); );
expect(await peerDiscoveryPeerExchange).to.eq(true); expect(await peerDiscoveryPeerExchange).to.eq(true);
@ -102,12 +102,12 @@ describe("ConnectionManager", function () {
EPeersByDiscoveryEvents.PEER_CONNECT_BOOTSTRAP, EPeersByDiscoveryEvents.PEER_CONNECT_BOOTSTRAP,
({ detail: receivedPeerId }) => { ({ detail: receivedPeerId }) => {
resolve(receivedPeerId.toString() === peerIdBootstrap.toString()); resolve(receivedPeerId.toString() === peerIdBootstrap.toString());
} },
); );
}); });
waku.libp2p.dispatchEvent( waku.libp2p.dispatchEvent(
new CustomEvent("peer:connect", { detail: peerIdBootstrap }) new CustomEvent("peer:connect", { detail: peerIdBootstrap }),
); );
expect(await peerConnectedBootstrap).to.eq(true); expect(await peerConnectedBootstrap).to.eq(true);
@ -129,12 +129,12 @@ describe("ConnectionManager", function () {
EPeersByDiscoveryEvents.PEER_CONNECT_PEER_EXCHANGE, EPeersByDiscoveryEvents.PEER_CONNECT_PEER_EXCHANGE,
({ detail: receivedPeerId }) => { ({ detail: receivedPeerId }) => {
resolve(receivedPeerId.toString() === peerIdPx.toString()); resolve(receivedPeerId.toString() === peerIdPx.toString());
} },
); );
}); });
waku.libp2p.dispatchEvent( waku.libp2p.dispatchEvent(
new CustomEvent("peer:connect", { detail: peerIdPx }) new CustomEvent("peer:connect", { detail: peerIdPx }),
); );
expect(await peerConnectedPeerExchange).to.eq(true); expect(await peerConnectedPeerExchange).to.eq(true);
@ -163,7 +163,7 @@ describe("ConnectionManager", function () {
beforeEach(function () { beforeEach(function () {
attemptDialSpy = sinon.spy( attemptDialSpy = sinon.spy(
waku.connectionManager as any, waku.connectionManager as any,
"attemptDial" "attemptDial",
); );
}); });
@ -177,7 +177,7 @@ describe("ConnectionManager", function () {
const totalPeerIds = 5; const totalPeerIds = 5;
for (let i = 1; i <= totalPeerIds; i++) { for (let i = 1; i <= totalPeerIds; i++) {
waku.libp2p.dispatchEvent( waku.libp2p.dispatchEvent(
new CustomEvent("peer:discovery", { detail: `peer-id-${i}` }) new CustomEvent("peer:discovery", { detail: `peer-id-${i}` }),
); );
} }
@ -186,7 +186,7 @@ describe("ConnectionManager", function () {
expect(attemptDialSpy.callCount).to.equal( expect(attemptDialSpy.callCount).to.equal(
totalPeerIds, totalPeerIds,
"attemptDial should be called once for each peer:discovery event" "attemptDial should be called once for each peer:discovery event",
); );
}); });
}); });
@ -195,11 +195,11 @@ describe("ConnectionManager", function () {
beforeEach(function () { beforeEach(function () {
getConnectionsStub = sinon.stub( getConnectionsStub = sinon.stub(
(waku.connectionManager as any).libp2p, (waku.connectionManager as any).libp2p,
"getConnections" "getConnections",
); );
getTagNamesForPeerStub = sinon.stub( getTagNamesForPeerStub = sinon.stub(
waku.connectionManager as any, waku.connectionManager as any,
"getTagNamesForPeer" "getTagNamesForPeer",
); );
dialPeerStub = sinon.stub(waku.connectionManager as any, "dialPeer"); dialPeerStub = sinon.stub(waku.connectionManager as any, "dialPeer");
}); });
@ -224,7 +224,7 @@ describe("ConnectionManager", function () {
// emit a peer:discovery event // emit a peer:discovery event
waku.libp2p.dispatchEvent( waku.libp2p.dispatchEvent(
new CustomEvent("peer:discovery", { detail: bootstrapPeer }) new CustomEvent("peer:discovery", { detail: bootstrapPeer }),
); );
// wait for the async function calls within attemptDial to finish // wait for the async function calls within attemptDial to finish
@ -233,7 +233,7 @@ describe("ConnectionManager", function () {
// check that dialPeer was called once // check that dialPeer was called once
expect(dialPeerStub.callCount).to.equal( expect(dialPeerStub.callCount).to.equal(
1, 1,
"dialPeer should be called for bootstrap peers" "dialPeer should be called for bootstrap peers",
); );
}); });
@ -248,7 +248,7 @@ describe("ConnectionManager", function () {
// emit first peer:discovery event // emit first peer:discovery event
waku.libp2p.dispatchEvent( waku.libp2p.dispatchEvent(
new CustomEvent("peer:discovery", { detail: "bootstrap-peer" }) new CustomEvent("peer:discovery", { detail: "bootstrap-peer" }),
); );
await delay(500); await delay(500);
@ -262,14 +262,14 @@ describe("ConnectionManager", function () {
waku.libp2p.dispatchEvent( waku.libp2p.dispatchEvent(
new CustomEvent("peer:discovery", { new CustomEvent("peer:discovery", {
detail: await createSecp256k1PeerId(), detail: await createSecp256k1PeerId(),
}) }),
); );
} }
// check that dialPeer was called only once // check that dialPeer was called only once
expect(dialPeerStub.callCount).to.equal( expect(dialPeerStub.callCount).to.equal(
1, 1,
"dialPeer should not be called more than once for bootstrap peers" "dialPeer should not be called more than once for bootstrap peers",
); );
}); });
}); });
@ -288,7 +288,7 @@ describe("ConnectionManager", function () {
// emit a peer:discovery event // emit a peer:discovery event
waku.libp2p.dispatchEvent( waku.libp2p.dispatchEvent(
new CustomEvent("peer:discovery", { detail: pxPeer }) new CustomEvent("peer:discovery", { detail: pxPeer }),
); );
// wait for the async function calls within attemptDial to finish // wait for the async function calls within attemptDial to finish
@ -297,7 +297,7 @@ describe("ConnectionManager", function () {
// check that dialPeer was called once // check that dialPeer was called once
expect(dialPeerStub.callCount).to.equal( expect(dialPeerStub.callCount).to.equal(
1, 1,
"dialPeer should be called for peers with PEER_EXCHANGE tags" "dialPeer should be called for peers with PEER_EXCHANGE tags",
); );
}); });
@ -316,7 +316,7 @@ describe("ConnectionManager", function () {
waku.libp2p.dispatchEvent( waku.libp2p.dispatchEvent(
new CustomEvent("peer:discovery", { new CustomEvent("peer:discovery", {
detail: await createSecp256k1PeerId(), detail: await createSecp256k1PeerId(),
}) }),
); );
await delay(500); await delay(500);
} }

View File

@ -12,7 +12,6 @@ import { Libp2pComponents } from "@waku/interfaces";
import { createLightNode } from "@waku/sdk"; import { createLightNode } from "@waku/sdk";
import { expect } from "chai"; import { expect } from "chai";
import { MemoryDatastore } from "datastore-core/memory"; import { MemoryDatastore } from "datastore-core/memory";
import { Datastore } from "interface-datastore";
import { delay } from "../src/delay.js"; import { delay } from "../src/delay.js";
@ -27,7 +26,7 @@ describe("DNS Discovery: Compliance Test", function () {
peerStore: new PersistentPeerStore({ peerStore: new PersistentPeerStore({
events: new EventEmitter(), events: new EventEmitter(),
peerId: await createSecp256k1PeerId(), peerId: await createSecp256k1PeerId(),
datastore: new MemoryDatastore() as any as Datastore, datastore: new MemoryDatastore(),
}), }),
} as unknown as Libp2pComponents; } as unknown as Libp2pComponents;

View File

@ -197,10 +197,10 @@ describe("Waku Message Ephemeral field", () => {
} }
const normalMsg = messages.find( const normalMsg = messages.find(
(msg) => bytesToUtf8(msg.payload) === normalTxt (msg) => bytesToUtf8(msg.payload) === normalTxt,
); );
const ephemeralMsg = messages.find( const ephemeralMsg = messages.find(
(msg) => bytesToUtf8(msg.payload) === ephemeralTxt (msg) => bytesToUtf8(msg.payload) === ephemeralTxt,
); );
expect(normalMsg).to.not.be.undefined; expect(normalMsg).to.not.be.undefined;
@ -246,10 +246,10 @@ describe("Waku Message Ephemeral field", () => {
} }
const normalMsg = messages.find( const normalMsg = messages.find(
(msg) => bytesToUtf8(msg.payload) === normalTxt (msg) => bytesToUtf8(msg.payload) === normalTxt,
); );
const ephemeralMsg = messages.find( const ephemeralMsg = messages.find(
(msg) => bytesToUtf8(msg.payload) === ephemeralTxt (msg) => bytesToUtf8(msg.payload) === ephemeralTxt,
); );
expect(normalMsg).to.not.be.undefined; expect(normalMsg).to.not.be.undefined;
@ -296,10 +296,10 @@ describe("Waku Message Ephemeral field", () => {
} }
const normalMsg = messages.find( const normalMsg = messages.find(
(msg) => bytesToUtf8(msg.payload) === normalTxt (msg) => bytesToUtf8(msg.payload) === normalTxt,
); );
const ephemeralMsg = messages.find( const ephemeralMsg = messages.find(
(msg) => bytesToUtf8(msg.payload) === ephemeralTxt (msg) => bytesToUtf8(msg.payload) === ephemeralTxt,
); );
expect(normalMsg).to.not.be.undefined; expect(normalMsg).to.not.be.undefined;

View File

@ -25,7 +25,7 @@ const TestEncoder = createEncoder({
async function runNodes( async function runNodes(
context: Mocha.Context, context: Mocha.Context,
pubSubTopic?: string pubSubTopic?: string,
): Promise<[NimGoNode, LightNode]> { ): Promise<[NimGoNode, LightNode]> {
const nwakuOptional = pubSubTopic ? { topic: pubSubTopic } : {}; const nwakuOptional = pubSubTopic ? { topic: pubSubTopic } : {};
const nwaku = new NimGoNode(makeLogFileName(context)); const nwaku = new NimGoNode(makeLogFileName(context));
@ -143,7 +143,7 @@ describe("Waku Light Push [node only] - custom pubsub topic", () => {
{ payload: utf8ToBytes(messageText) }, { payload: utf8ToBytes(messageText) },
{ {
peerId: nimPeerId, peerId: nimPeerId,
} },
); );
log("Ack received", pushResponse); log("Ack received", pushResponse);
expect(pushResponse.recipients[0].toString()).to.eq(nimPeerId.toString()); expect(pushResponse.recipients[0].toString()).to.eq(nimPeerId.toString());

View File

@ -74,7 +74,7 @@ describe("Peer Exchange", () => {
const doesPeerIdExistInResponse = const doesPeerIdExistInResponse =
peerInfos.find( peerInfos.find(
({ ENR }) => ENR?.peerInfo?.id.toString() === nwaku1PeerId.toString() ({ ENR }) => ENR?.peerInfo?.id.toString() === nwaku1PeerId.toString(),
) !== undefined; ) !== undefined;
expect(doesPeerIdExistInResponse).to.be.equal(true); expect(doesPeerIdExistInResponse).to.be.equal(true);

View File

@ -41,7 +41,7 @@ describe("Peer Exchange", () => {
waku.libp2p.addEventListener("peer:discovery", (evt) => { waku.libp2p.addEventListener("peer:discovery", (evt) => {
const peerId = evt.detail.id.toString(); const peerId = evt.detail.id.toString();
const isBootstrapNode = predefinedNodes.find((n) => const isBootstrapNode = predefinedNodes.find((n) =>
n.includes(peerId) n.includes(peerId),
); );
if (!isBootstrapNode) { if (!isBootstrapNode) {
resolve(true); resolve(true);

View File

@ -59,7 +59,7 @@ describe("Waku Relay [node only]", () => {
log("Starting JS Waku instances"); log("Starting JS Waku instances");
[waku1, waku2] = await Promise.all([ [waku1, waku2] = await Promise.all([
createRelayNode({ staticNoiseKey: NOISE_KEY_1 }).then((waku) => createRelayNode({ staticNoiseKey: NOISE_KEY_1 }).then((waku) =>
waku.start().then(() => waku) waku.start().then(() => waku),
), ),
createRelayNode({ createRelayNode({
staticNoiseKey: NOISE_KEY_2, staticNoiseKey: NOISE_KEY_2,
@ -121,7 +121,7 @@ describe("Waku Relay [node only]", () => {
const receivedMsgPromise: Promise<DecodedMessage> = new Promise( const receivedMsgPromise: Promise<DecodedMessage> = new Promise(
(resolve) => { (resolve) => {
void waku2.relay.subscribe([TestDecoder], resolve); void waku2.relay.subscribe([TestDecoder], resolve);
} },
); );
await waku1.relay.send(TestEncoder, message); await waku1.relay.send(TestEncoder, message);
@ -131,7 +131,7 @@ describe("Waku Relay [node only]", () => {
expect(receivedMsg.contentTopic).to.eq(TestContentTopic); expect(receivedMsg.contentTopic).to.eq(TestContentTopic);
expect(bytesToUtf8(receivedMsg.payload)).to.eq(messageText); expect(bytesToUtf8(receivedMsg.payload)).to.eq(messageText);
expect(receivedMsg.timestamp?.valueOf()).to.eq( expect(receivedMsg.timestamp?.valueOf()).to.eq(
messageTimestamp.valueOf() messageTimestamp.valueOf(),
); );
}); });
@ -240,11 +240,11 @@ describe("Waku Relay [node only]", () => {
(resolve, reject) => { (resolve, reject) => {
const deleteObserver = waku2.relay.subscribe( const deleteObserver = waku2.relay.subscribe(
[createDecoder(contentTopic)], [createDecoder(contentTopic)],
reject reject,
) as () => void; ) as () => void;
deleteObserver(); deleteObserver();
setTimeout(resolve, 500); setTimeout(resolve, 500);
} },
); );
await waku1.relay.send(createEncoder({ contentTopic }), { await waku1.relay.send(createEncoder({ contentTopic }), {
payload: utf8ToBytes(messageText), payload: utf8ToBytes(messageText),
@ -311,7 +311,7 @@ describe("Waku Relay [node only]", () => {
const waku2ReceivedMsgPromise: Promise<DecodedMessage> = new Promise( const waku2ReceivedMsgPromise: Promise<DecodedMessage> = new Promise(
(resolve) => { (resolve) => {
void waku2.relay.subscribe([TestDecoder], resolve); void waku2.relay.subscribe([TestDecoder], resolve);
} },
); );
// The promise **fails** if we receive a message on the default // The promise **fails** if we receive a message on the default
@ -320,7 +320,7 @@ describe("Waku Relay [node only]", () => {
(resolve, reject) => { (resolve, reject) => {
void waku3.relay.subscribe([TestDecoder], reject); void waku3.relay.subscribe([TestDecoder], reject);
setTimeout(resolve, 1000); setTimeout(resolve, 1000);
} },
); );
await waku1.relay.send(TestEncoder, { await waku1.relay.send(TestEncoder, {
@ -368,9 +368,9 @@ describe("Waku Relay [node only]", () => {
void waku2.relay.subscribe([TestDecoder], () => void waku2.relay.subscribe([TestDecoder], () =>
resolve({ resolve({
payload: new Uint8Array([]), payload: new Uint8Array([]),
} as DecodedMessage) } as DecodedMessage),
); );
} },
); );
let sendResult = await waku1.relay.send(TestEncoder, { let sendResult = await waku1.relay.send(TestEncoder, {
@ -430,7 +430,7 @@ describe("Waku Relay [node only]", () => {
const nimPeerId = await nwaku.getPeerId(); const nimPeerId = await nwaku.getPeerId();
expect(subscribers.map((p) => p.toString())).to.contain( expect(subscribers.map((p) => p.toString())).to.contain(
nimPeerId.toString() nimPeerId.toString(),
); );
}); });
@ -461,16 +461,16 @@ describe("Waku Relay [node only]", () => {
const receivedMsgPromise: Promise<DecodedMessage> = new Promise( const receivedMsgPromise: Promise<DecodedMessage> = new Promise(
(resolve) => { (resolve) => {
void waku.relay.subscribe<DecodedMessage>(TestDecoder, (msg) => void waku.relay.subscribe<DecodedMessage>(TestDecoder, (msg) =>
resolve(msg) resolve(msg),
); );
} },
); );
await nwaku.sendMessage( await nwaku.sendMessage(
NimGoNode.toMessageRpcQuery({ NimGoNode.toMessageRpcQuery({
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
payload: utf8ToBytes(messageText), payload: utf8ToBytes(messageText),
}) }),
); );
const receivedMsg = await receivedMsgPromise; const receivedMsg = await receivedMsgPromise;
@ -533,7 +533,7 @@ describe("Waku Relay [node only]", () => {
const waku2ReceivedMsgPromise: Promise<DecodedMessage> = new Promise( const waku2ReceivedMsgPromise: Promise<DecodedMessage> = new Promise(
(resolve) => { (resolve) => {
void waku2.relay.subscribe(TestDecoder, resolve); void waku2.relay.subscribe(TestDecoder, resolve);
} },
); );
await waku1.relay.send(TestEncoder, message); await waku1.relay.send(TestEncoder, message);

View File

@ -64,8 +64,8 @@ describe("Waku Store", () => {
NimGoNode.toMessageRpcQuery({ NimGoNode.toMessageRpcQuery({
payload: new Uint8Array([i]), payload: new Uint8Array([i]),
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
}) }),
) ),
).to.be.true; ).to.be.true;
} }
@ -134,8 +134,8 @@ describe("Waku Store", () => {
NimGoNode.toMessageRpcQuery({ NimGoNode.toMessageRpcQuery({
payload: utf8ToBytes(`Message ${i}`), payload: utf8ToBytes(`Message ${i}`),
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
}) }),
) ),
).to.be.true; ).to.be.true;
} }
@ -176,7 +176,7 @@ describe("Waku Store", () => {
expect(messages.length).be.eq(totalMsgs); expect(messages.length).be.eq(totalMsgs);
expect(bytesToUtf8(testMessage.payload)).to.be.eq( expect(bytesToUtf8(testMessage.payload)).to.be.eq(
bytesToUtf8(messages[cursorIndex + 1].payload) bytesToUtf8(messages[cursorIndex + 1].payload),
); );
}); });
@ -191,8 +191,8 @@ describe("Waku Store", () => {
NimGoNode.toMessageRpcQuery({ NimGoNode.toMessageRpcQuery({
payload: new Uint8Array([i]), payload: new Uint8Array([i]),
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
}) }),
) ),
).to.be.true; ).to.be.true;
} }
@ -211,7 +211,7 @@ describe("Waku Store", () => {
if (msg) { if (msg) {
messages.push(msg); messages.push(msg);
} }
} },
); );
expect(messages?.length).eq(totalMsgs); expect(messages?.length).eq(totalMsgs);
@ -232,8 +232,8 @@ describe("Waku Store", () => {
NimGoNode.toMessageRpcQuery({ NimGoNode.toMessageRpcQuery({
payload: new Uint8Array([i]), payload: new Uint8Array([i]),
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
}) }),
) ),
).to.be.true; ).to.be.true;
} }
@ -255,7 +255,7 @@ describe("Waku Store", () => {
} }
return messages.length >= desiredMsgs; return messages.length >= desiredMsgs;
}, },
{ pageSize: 7 } { pageSize: 7 },
); );
expect(messages?.length).eq(desiredMsgs); expect(messages?.length).eq(desiredMsgs);
@ -271,8 +271,8 @@ describe("Waku Store", () => {
NimGoNode.toMessageRpcQuery({ NimGoNode.toMessageRpcQuery({
payload: new Uint8Array([i]), payload: new Uint8Array([i]),
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
}) }),
) ),
).to.be.true; ).to.be.true;
await delay(1); // to ensure each timestamp is unique. await delay(1); // to ensure each timestamp is unique.
} }
@ -292,7 +292,7 @@ describe("Waku Store", () => {
}, },
{ {
pageDirection: PageDirection.FORWARD, pageDirection: PageDirection.FORWARD,
} },
); );
expect(messages?.length).eq(totalMsgs); expect(messages?.length).eq(totalMsgs);
@ -310,8 +310,8 @@ describe("Waku Store", () => {
NimGoNode.toMessageRpcQuery({ NimGoNode.toMessageRpcQuery({
payload: new Uint8Array([i]), payload: new Uint8Array([i]),
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
}) }),
) ),
).to.be.true; ).to.be.true;
await delay(1); // to ensure each timestamp is unique. await delay(1); // to ensure each timestamp is unique.
} }
@ -331,7 +331,7 @@ describe("Waku Store", () => {
}, },
{ {
pageDirection: PageDirection.BACKWARD, pageDirection: PageDirection.BACKWARD,
} },
); );
messages = messages.reverse(); messages = messages.reverse();
@ -476,8 +476,8 @@ describe("Waku Store", () => {
payload: new Uint8Array([i]), payload: new Uint8Array([i]),
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
timestamp: messageTimestamps[i], timestamp: messageTimestamps[i],
}) }),
) ),
).to.be.true; ).to.be.true;
} }
@ -501,7 +501,7 @@ describe("Waku Store", () => {
{ {
peerId: nwakuPeerId, peerId: nwakuPeerId,
timeFilter: { startTime, endTime: message1Timestamp }, timeFilter: { startTime, endTime: message1Timestamp },
} },
); );
const bothMessages: IMessage[] = []; const bothMessages: IMessage[] = [];
@ -516,7 +516,7 @@ describe("Waku Store", () => {
startTime, startTime,
endTime, endTime,
}, },
} },
); );
expect(firstMessages?.length).eq(1); expect(firstMessages?.length).eq(1);
@ -537,8 +537,8 @@ describe("Waku Store", () => {
NimGoNode.toMessageRpcQuery({ NimGoNode.toMessageRpcQuery({
payload: new Uint8Array([i]), payload: new Uint8Array([i]),
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
}) }),
) ),
).to.be.true; ).to.be.true;
await delay(1); // to ensure each timestamp is unique. await delay(1); // to ensure each timestamp is unique.
} }
@ -558,7 +558,7 @@ describe("Waku Store", () => {
messages.push(msg); messages.push(msg);
return messages.length >= desiredMsgs; return messages.length >= desiredMsgs;
}, },
{ pageSize: 7 } { pageSize: 7 },
); );
expect(messages?.length).eq(desiredMsgs); expect(messages?.length).eq(desiredMsgs);
@ -597,8 +597,8 @@ describe("Waku Store, custom pubsub topic", () => {
payload: new Uint8Array([i]), payload: new Uint8Array([i]),
contentTopic: TestContentTopic, contentTopic: TestContentTopic,
}), }),
customPubSubTopic customPubSubTopic,
) ),
).to.be.true; ).to.be.true;
} }

View File

@ -53,7 +53,7 @@ describe("Util: toAsyncIterator: Filter", () => {
waku.filter, waku.filter,
TestDecoder, TestDecoder,
{}, {},
{ timeoutMs: 1000 } { timeoutMs: 1000 },
); );
await waku.lightPush.send(TestEncoder, sent); await waku.lightPush.send(TestEncoder, sent);
@ -70,7 +70,7 @@ describe("Util: toAsyncIterator: Filter", () => {
waku.filter, waku.filter,
TestDecoder, TestDecoder,
{}, {},
{ timeoutMs: 1000 } { timeoutMs: 1000 },
); );
await waku.lightPush.send(TestEncoder, { await waku.lightPush.send(TestEncoder, {
@ -93,7 +93,7 @@ describe("Util: toAsyncIterator: Filter", () => {
waku.filter, waku.filter,
TestDecoder, TestDecoder,
{}, {},
{ timeoutMs: 1000 } { timeoutMs: 1000 },
); );
await waku.lightPush.send(TestEncoder, { await waku.lightPush.send(TestEncoder, {

View File

@ -88,7 +88,7 @@ describe("Wait for remote peer", function () {
(reason) => { (reason) => {
expect(reason).to.eq("Timed out waiting for a remote peer."); expect(reason).to.eq("Timed out waiting for a remote peer.");
done(); done();
} },
); );
}) })
.catch((e) => done(e)); .catch((e) => done(e));
@ -167,7 +167,7 @@ describe("Wait for remote peer", function () {
await waitForRemotePeer(waku2, [Protocols.LightPush]); await waitForRemotePeer(waku2, [Protocols.LightPush]);
const peers = (await waku2.lightPush.peers()).map((peer) => const peers = (await waku2.lightPush.peers()).map((peer) =>
peer.id.toString() peer.id.toString(),
); );
const nimPeerId = multiAddrWithId.getPeerId(); const nimPeerId = multiAddrWithId.getPeerId();
@ -195,7 +195,7 @@ describe("Wait for remote peer", function () {
await waitForRemotePeer(waku2, [Protocols.Filter]); await waitForRemotePeer(waku2, [Protocols.Filter]);
const peers = (await waku2.filter.peers()).map((peer) => const peers = (await waku2.filter.peers()).map((peer) =>
peer.id.toString() peer.id.toString(),
); );
const nimPeerId = multiAddrWithId.getPeerId(); const nimPeerId = multiAddrWithId.getPeerId();
@ -227,13 +227,13 @@ describe("Wait for remote peer", function () {
]); ]);
const filterPeers = (await waku2.filter.peers()).map((peer) => const filterPeers = (await waku2.filter.peers()).map((peer) =>
peer.id.toString() peer.id.toString(),
); );
const storePeers = (await waku2.store.peers()).map((peer) => const storePeers = (await waku2.store.peers()).map((peer) =>
peer.id.toString() peer.id.toString(),
); );
const lightPushPeers = (await waku2.lightPush.peers()).map((peer) => const lightPushPeers = (await waku2.lightPush.peers()).map((peer) =>
peer.id.toString() peer.id.toString(),
); );
const nimPeerId = multiAddrWithId.getPeerId(); const nimPeerId = multiAddrWithId.getPeerId();

View File

@ -34,7 +34,7 @@ describe("Use static and several ENR trees for bootstrap", function () {
bootstrap({ list: [multiAddrWithId.toString()] }), bootstrap({ list: [multiAddrWithId.toString()] }),
wakuDnsDiscovery( wakuDnsDiscovery(
[enrTree["PROD"], enrTree["TEST"]], [enrTree["PROD"], enrTree["TEST"]],
NODE_REQUIREMENTS NODE_REQUIREMENTS,
), ),
], ],
}, },
@ -48,8 +48,8 @@ describe("Use static and several ENR trees for bootstrap", function () {
// should also have the bootstrap peer // should also have the bootstrap peer
expect( expect(
peersDiscovered.find( peersDiscovered.find(
(p) => p.id.toString() === multiAddrWithId.getPeerId()?.toString() (p) => p.id.toString() === multiAddrWithId.getPeerId()?.toString(),
) ),
).to.not.be.undefined; ).to.not.be.undefined;
}); });
}); });

View File

@ -131,7 +131,7 @@ describe("Decryption Keys", () => {
this.timeout(5000); this.timeout(5000);
[waku1, waku2] = await Promise.all([ [waku1, waku2] = await Promise.all([
createRelayNode({ staticNoiseKey: NOISE_KEY_1 }).then((waku) => createRelayNode({ staticNoiseKey: NOISE_KEY_1 }).then((waku) =>
waku.start().then(() => waku) waku.start().then(() => waku),
), ),
createRelayNode({ createRelayNode({
staticNoiseKey: NOISE_KEY_2, staticNoiseKey: NOISE_KEY_2,
@ -175,7 +175,7 @@ describe("Decryption Keys", () => {
const receivedMsgPromise: Promise<DecodedMessage> = new Promise( const receivedMsgPromise: Promise<DecodedMessage> = new Promise(
(resolve) => { (resolve) => {
void waku2.relay.subscribe([decoder], resolve); void waku2.relay.subscribe([decoder], resolve);
} },
); );
await waku1.relay.send(encoder, message); await waku1.relay.send(encoder, message);
@ -225,10 +225,10 @@ describe("User Agent", () => {
]); ]);
expect(bytesToUtf8(waku1PeerInfo.metadata.get("AgentVersion")!)).to.eq( expect(bytesToUtf8(waku1PeerInfo.metadata.get("AgentVersion")!)).to.eq(
waku1UserAgent waku1UserAgent,
); );
expect(bytesToUtf8(waku2PeerInfo.metadata.get("AgentVersion")!)).to.eq( expect(bytesToUtf8(waku2PeerInfo.metadata.get("AgentVersion")!)).to.eq(
DefaultUserAgent DefaultUserAgent,
); );
}); });
}); });

File diff suppressed because it is too large Load Diff

View File

@ -79,7 +79,6 @@
"@waku/interfaces": "0.0.17", "@waku/interfaces": "0.0.17",
"cspell": "^6.31.1", "cspell": "^6.31.1",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"rollup": "^3.21.3", "rollup": "^3.21.3",
"typescript": "^5.0.4" "typescript": "^5.0.4"
}, },

View File

@ -35,7 +35,7 @@ export const utf8ToBytes = (s: string): Uint8Array => fromString(s, "utf8");
*/ */
export function concat( export function concat(
byteArrays: Uint8Array[], byteArrays: Uint8Array[],
totalLength?: number totalLength?: number,
): Uint8Array { ): Uint8Array {
const len = const len =
totalLength ?? byteArrays.reduce((acc, curr) => acc + curr.length, 0); totalLength ?? byteArrays.reduce((acc, curr) => acc + curr.length, 0);

Some files were not shown because too many files have changed in this diff Show More