### Setup and Build Waku Browser Tests Source: https://github.com/waku-org/js-waku/blob/master/packages/browser-tests/README.md Instructions for installing project dependencies and building the Waku browser test application, including steps for both main and headless app dependencies. This prepares the environment for running the tests. ```bash # Install main dependencies npm install # Install headless app dependencies cd ../headless-tests npm install cd ../browser-tests ``` ```bash npm run build ``` -------------------------------- ### Manage Waku Node Lifecycle (Create, Start, Stop) Source: https://github.com/waku-org/js-waku/blob/master/packages/browser-tests/README.md Commands to manage the lifecycle of a Waku node through the server's administrative API endpoints. This includes creating a new node instance with specific network configurations, and then starting and stopping it. ```bash curl -X POST http://localhost:3000/admin/v1/create-node \ -H "Content-Type: application/json" \ -d '{ "defaultBootstrap": true, "networkConfig": { "clusterId": 1, "shards": [0, 1] } }' ``` ```bash # Start the node curl -X POST http://localhost:3000/admin/v1/start-node ``` ```bash # Stop the node curl -X POST http://localhost:3000/admin/v1/stop-node ``` -------------------------------- ### Run Waku Browser Test Server Source: https://github.com/waku-org/js-waku/blob/master/packages/browser-tests/README.md Command to start the Express server for the Waku browser tests. This initiates the headless browser, loads the Waku app, and exposes the API endpoints for interaction. ```bash npm run start:server ``` -------------------------------- ### Build the Waku Headless Test Application Source: https://github.com/waku-org/js-waku/blob/master/packages/headless-tests/README.md This command compiles and builds the Waku headless test application, preparing it for execution. It's a prerequisite step before starting the application or running tests. ```bash npm run build ``` -------------------------------- ### Install @waku/rln package via npm Source: https://github.com/waku-org/js-waku/blob/master/packages/rln/README.md This command installs the @waku/rln package, which provides Rate Limiting Nullifier (RLN) functionality for the Waku protocol, as a dependency in your project using the Node Package Manager (npm). ```bash npm install @waku/rln ``` -------------------------------- ### Start the Waku Headless Test Application Server Source: https://github.com/waku-org/js-waku/blob/master/packages/headless-tests/README.md This command initiates the server for the Waku headless test application. By default, the server will be accessible on port 8080, allowing interaction and testing of the Waku SDK. ```bash npm start ``` -------------------------------- ### Generate Local API Documentation for js-waku Source: https://github.com/waku-org/js-waku/blob/master/packages/core/README.md This shell script provides the steps to clone the js-waku repository, install its dependencies, and generate the API documentation locally. This is useful for developers who want to browse the API reference offline or contribute to the project. ```Shell git clone https://github.com/waku-org/js-waku.git cd js-waku npm install npm run doc ``` -------------------------------- ### Push Waku Message (Legacy and REST API Compatible) Source: https://github.com/waku-org/js-waku/blob/master/packages/browser-tests/README.md Examples demonstrating how to push messages to the Waku network using both the older `/push` endpoint and the newer, Waku REST API compatible `/lightpush/v1/message` endpoint. Both examples use `curl` to send JSON payloads. ```bash curl -X POST http://localhost:3000/push \ -H "Content-Type: application/json" \ -d '{"contentTopic": "/toy-chat/2/huilong/proto", "payload": [1, 2, 3]}' ``` ```bash curl -X POST http://localhost:3000/lightpush/v1/message \ -H "Content-Type: application/json" \ -d '{ "pubsubTopic": "/waku/2/rs/0/0", "message": { "payload": "SGVsbG8sIFdha3Uh", "contentTopic": "/toy-chat/2/huilong/proto", "timestamp": 1712135330213797632 } }' ``` -------------------------------- ### Generate Local API Documentation for js-waku Source: https://github.com/waku-org/js-waku/blob/master/README.md This shell script provides the necessary commands to clone the js-waku repository, install its dependencies, and generate the API documentation locally. This is useful for developers who want to browse the API reference offline or contribute to the project. ```shell git clone https://github.com/waku-org/js-waku.git cd js-waku npm install npm run doc ``` -------------------------------- ### Retrieve Stored Waku Messages (Filter v1) Source: https://github.com/waku-org/js-waku/blob/master/packages/browser-tests/README.md Examples of retrieving stored messages from a content topic using the `/filter/v1/messages/:contentTopic` endpoint. This demonstrates fetching recent messages and applying pagination and time-based filtering. ```bash # Get the most recent 20 messages curl http://localhost:3000/filter/v1/messages/%2Ftoy-chat%2F2%2Fhuilong%2Fproto ``` ```bash # Get messages with pagination and time filtering curl "http://localhost:3000/filter/v1/messages/%2Ftoy-chat%2F2%2Fhuilong%2Fproto?pageSize=10&startTime=1712000000000&endTime=1713000000000&ascending=true" ``` -------------------------------- ### Execute Generic Function via Waku Test Server Source: https://github.com/waku-org/js-waku/blob/master/packages/browser-tests/README.md Example of using the `/execute` endpoint to call a generic function, such as `getPeerInfo`, on the Waku node. This allows for flexible interaction with the Waku SDK's exposed functions. ```bash curl -X POST http://localhost:3000/execute \ -H "Content-Type: application/json" \ -d '{"functionName": "getPeerInfo", "params": []}' ``` -------------------------------- ### Dial Waku Peers (REST API and Execute Endpoint) Source: https://github.com/waku-org/js-waku/blob/master/packages/browser-tests/README.md Examples demonstrating how to connect to specific Waku peers. This can be done using the Waku REST API compatible `/admin/v1/peers` endpoint or by executing the `dialPeers` function via the generic `/execute` endpoint. ```bash curl -X POST http://localhost:3000/admin/v1/peers \ -H "Content-Type: application/json" \ -d '{ "peerMultiaddrs": [ "/ip4/127.0.0.1/tcp/8000/p2p/16Uiu2HAm4v8KuHUH6Cwz3upPeQbkyxQJsFGPdt7kHtkN8F79QiE6"] ] }' ``` ```bash curl -X POST http://localhost:3000/execute \ -H "Content-Type: application/json" \ -d '{ "functionName": "dialPeers", "params": [ ["/ip4/127.0.0.1/tcp/8000/p2p/16Uiu2HAm4v8KuHUH6Cwz3upPeQbkyxQJsFGPdt7kHtkN8F79QiE6"] ] }' ``` -------------------------------- ### Subscribe to Waku Messages (Filter v2 SSE) Source: https://github.com/waku-org/js-waku/blob/master/packages/browser-tests/README.md Examples of subscribing to messages on a specific content topic using the `/filter/v2/messages/:contentTopic` endpoint. This endpoint provides messages as Server-Sent Events (SSE) and supports optional clustering parameters. ```bash # Open a persistent connection to receive messages as Server-Sent Events curl -N http://localhost:3000/filter/v2/messages/%2Ftoy-chat%2F2%2Fhuilong%2Fproto ``` ```bash # You can also specify clustering options curl -N "http://localhost:3000/filter/v2/messages/%2Ftoy-chat%2F2%2Fhuilong%2Fproto?clusterId=0&shard=0" ``` -------------------------------- ### Import RLN module in TypeScript Source: https://github.com/waku-org/js-waku/blob/master/packages/rln/README.md This TypeScript snippet demonstrates how to import the RLN class from the @waku/rln package. Once imported, the RLN functionality can be utilized within your Waku application for rate-limiting purposes. Note that detailed usage examples are currently pending. ```typescript import { RLN } from '@waku/rln'; // Usage examples coming soon ``` -------------------------------- ### Build Local nwaku Docker Image Source: https://github.com/waku-org/js-waku/blob/master/packages/tests/README.md This command builds a Docker image for `nwaku` from a local Dockerfile path. The `-t` flag assigns a tag (image-name) to the built image, making it available for local testing against custom `nwaku` builds. ```bash docker build path-to-dockerfile -t image-name ``` -------------------------------- ### Run js-waku Tests with Default nwaku Docker Image Source: https://github.com/waku-org/js-waku/blob/master/packages/tests/README.md This command runs the `js-waku` interop tests using the default `nwaku` Docker image configured in the project. It's a convenient way to execute tests without specifying a custom image, relying on the project's predefined settings. ```bash npm run test:node ``` -------------------------------- ### Run Pre-commit Checks for js-waku Source: https://github.com/waku-org/js-waku/blob/master/CONTRIBUTING.md Instructions to run linting, formatting, and tests before committing changes. These commands help ensure that pull requests adhere to project standards and pass continuous integration checks. ```Shell npm run fix ``` ```Shell npm run check ``` ```Shell npm run test ``` -------------------------------- ### Run js-waku Tests with Specific nwaku Docker Image Source: https://github.com/waku-org/js-waku/blob/master/packages/tests/README.md This command executes the `js-waku` interop tests against a specified `nwaku` Docker image. The `WAKUNODE_IMAGE` environment variable defines the image name, which can be a pre-existing image from Docker Hub or a locally available one. ```bash WAKUNODE_IMAGE=explicit-image-name npm run test:node ``` -------------------------------- ### Build and Test js-waku Project Source: https://github.com/waku-org/js-waku/blob/master/CONTRIBUTING.md Commands to build the js-waku repository and run its tests. The build command resolves intra-dependencies, while the pretest command pulls necessary Docker images for interoperability testing with nim-waku. ```Shell npm run build ``` ```Shell npm run pretest ``` -------------------------------- ### Run js-waku Tests Against Local nwaku Docker Image Source: https://github.com/waku-org/js-waku/blob/master/packages/tests/README.md This command runs the `js-waku` interop tests against an `nwaku` Docker image that has been built locally. The `WAKUNODE_IMAGE` environment variable is set to the tag of the locally built image, enabling testing against custom `nwaku` checkouts. ```bash WAKUNODE_IMAGE=image-name npm run test:node ``` -------------------------------- ### Implement ECIES Encryption for Waku Messages Source: https://github.com/waku-org/js-waku/blob/master/packages/message-encryption/README.md Illustrates the use of ECIES encryption for Waku messages, enabling encryption with a public key and decryption with a private key. This snippet shows how to generate a private key, derive a public key, and then create encoders for sending messages to a recipient's public key and decoders for decrypting messages with a private key. ```typescript import { createDecoder, createEncoder, generatePrivateKey, getPublicKey } from "@waku/message-encryption/ecies"; // Generate a random private key const privateKey = generatePrivateKey(); // Keep the private key secure, provide the public key to the sender const publicKey = getPublicKey(privateKey); // To send messages, create an encoder const encoder = createEncoder(contentTopic, publicKey); // For example waku.lightPush.push(encoder, { payload }); // To receive messages, create a decoder const decoder = createDecoder(contentTopic, privateKey); // For example await waku.store.queryOrderedCallback([decoder], (msg) => { // ... }); ``` -------------------------------- ### Waku Browser Test Server API Endpoints Source: https://github.com/waku-org/js-waku/blob/master/packages/browser-tests/README.md Comprehensive documentation of the API endpoints exposed by the Waku browser test server. These endpoints allow interaction with the Waku node for information retrieval, message handling, and administrative tasks. ```APIDOC GET /info - Get general information about the Waku node. GET /debug/v1/info - Get detailed debug information from the Waku node. POST /push - Push a message to the Waku network (legacy endpoint). POST /lightpush/v1/message - Push a message to the Waku network (Waku REST API compatible). POST /admin/v1/create-node - Create a new Waku node instance. Requires a 'networkConfig' in the request body. POST /admin/v1/start-node - Start the initialized Waku node. POST /admin/v1/stop-node - Stop the running Waku node. POST /admin/v1/peers - Dial to specified peers (Waku REST API compatible). Expects 'peerMultiaddrs' in the request body. GET /filter/v2/messages/:contentTopic - Subscribe to messages on a specific content topic using Server-Sent Events (SSE). Waku REST API compatible. Supports optional 'clusterId' and 'shard' query parameters. GET /filter/v1/messages/:contentTopic - Retrieve stored messages from a content topic. Waku REST API compatible. Supports pagination ('pageSize', 'ascending') and time filtering ('startTime', 'endTime') query parameters. ``` -------------------------------- ### Run js-waku Longevity Test Source: https://github.com/waku-org/js-waku/blob/master/packages/reliability-tests/README.md This command executes the longevity test suite for the js-waku project. It initiates a continuous message sending and receiving scenario between js-waku and nwaku, designed to run for extended periods (e.g., 2 hours) to identify stability and reliability issues. ```bash npm run test:longevity ``` -------------------------------- ### Implement Symmetric Encryption for Waku Messages Source: https://github.com/waku-org/js-waku/blob/master/packages/message-encryption/README.md Demonstrates how to use symmetric encryption for Waku messages. This method uses a single shared key for both encryption and decryption. The snippet shows how to generate a symmetric key, create an encoder for sending messages, and a decoder for receiving messages, suitable for scenarios where a shared secret key is available. ```typescript import { createDecoder, createEncoder, generateSymmetricKey } from "@waku/message-encryption/symmetric"; // Generate a random key const key = generateSymmetricKey(); // To send messages, create an encoder const encoder = createEncoder(contentTopic, key); // For example waku.lightPush.push(encoder, { payload }); // To receive messages, create a decoder const decoder = createDecoder(contentTopic, key); // For example await waku.store.queryOrderedCallback([decoder], (msg) => { // ... }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.