JavaScript implementation of Waku v2 https://js.waku.org
Go to file
Franck Royer 90c90dea11
Merge pull request #176 from status-im/doc-no-inherit
Do not inherit doc for Waku Relay
2021-05-21 15:40:11 +10:00
.github Mergify does odd manipulation of tokens 2021-05-18 16:11:18 +10:00
.vscode Format json files 2021-05-04 10:49:14 +10:00
examples Remove outdated comment 2021-05-19 12:29:30 +10:00
nim-waku@44cafcfee3 Upgrade nim-waku to v0.3 2021-05-16 14:43:07 +10:00
proto Implement Light Push protocol 2021-05-19 12:29:29 +10:00
src Do not inherit doc for Waku Relay 2021-05-21 11:47:17 +10:00
.cspell.json Implement Light Push protocol 2021-05-19 12:29:29 +10:00
.editorconfig Initial commit 2021-03-05 09:34:01 +11:00
.eslintrc.json Exclude test files from build 2021-05-11 14:05:12 +10:00
.gitignore Check in protobuf generated files 2021-04-20 15:32:10 +10:00
.gitmodules Re-add nim-waku submodule 2021-03-19 11:23:34 +11:00
.mocharc.json Move mocha --exit to config file 2021-05-05 09:59:32 +10:00
.prettierignore Use waku messages over waku relay 2021-03-10 16:22:49 +11:00
CHANGELOG.md Add `--help` command 2021-05-19 12:29:30 +10:00
CONTRIBUTING.md Revert naming to js-waku 2021-05-13 20:27:38 +10:00
LICENSE-APACHE-v2 Apply MIT or Apache V2.0 License 2021-04-28 21:27:26 +10:00
LICENSE-MIT Apply MIT or Apache V2.0 License 2021-04-28 21:27:26 +10:00
README.md Implement Light Push protocol 2021-05-19 12:29:29 +10:00
buf.gen.yaml Implement chat message protobuf to support nick and time handles 2021-04-01 11:01:15 +11:00
buf.yaml Use waku messages over waku relay 2021-03-10 16:22:49 +11:00
netlify.toml Add netlify config 2021-05-11 10:50:58 +10:00
package-lock.json Do not inherit doc for Waku Relay 2021-05-21 11:47:17 +10:00
package.json Do not inherit doc for Waku Relay 2021-05-21 11:47:17 +10:00
tsconfig.dev.json Exclude test files from build 2021-05-11 14:05:12 +10:00
tsconfig.json Exclude test files from build 2021-05-11 14:05:12 +10:00
tsconfig.module.json Exclude test files from build 2021-05-11 14:05:12 +10:00

README.md

js-waku

A JavaScript implementation of the Waku v2 protocol.

Usage

Install js-waku package:

npm install js-waku

Start a waku node:

import { Waku } from 'js-waku';

const waku = await Waku.create();

Connect to a new peer:

import { multiaddr } from 'multiaddr';
import PeerId from 'peer-id';

// Directly dial a new peer
await waku.dial('/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ');

// Or, add peer to address book so it auto dials in the background
waku.addPeerToAddressBook(
  '16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ',
  ['/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/443/wss']
);

You can also use getStatusFleetNodes to connect to nodes run by Status:

import { getStatusFleetNodes } from 'js-waku';

const nodes = await getStatusFleetNodes();
await Promise.all(
  nodes.map((addr) => {
    return waku.dial(addr);
  })
);

The contentTopic is a metadata string that allows categorization of messages on the waku network. Depending on your use case, you can either create one (or several) new contentTopic(s) or look at the RFCs and use an existing contentTopic. See the Waku v2 Message spec for more details.

For example, if you were to use a new contentTopic such as "my-cool-app", here is how to listen to new messages received via Waku v2 Relay:

waku.relay.addObserver((msg) => {
  console.log("Message received:", msg.payloadAsUtf8)
}, ["my-cool-app"]);

Note that the guidelines regarding content topic format are yet to be defined, see vacp2p/rfc#364. The examples chat apps currently use content topic "dingpu".

Send a message on the waku relay network:

import { WakuMessage } from 'js-waku';

const msg = WakuMessage.fromUtf8String("Here is a message!", "my-cool-app")
await waku.relay.send(msg);

The Waku v2 Store protocol enables full nodes to store messages received via relay and clients to retrieve them (e.g. after resuming connectivity). The protocol implements pagination meaning that it may take several queries to retrieve all messages.

Query a waku store peer to check historical messages:

// Process messages once they are all retrieved:
const messages = await waku.store.queryHistory(storePeerId, ["my-cool-app"]);
messages.forEach((msg) => {
  console.log("Message retrieved:", msg.payloadAsUtf8)
})

// Or, pass a callback function to be executed as pages are received:
waku.store.queryHistory(storePeerId, ["my-cool-app"],
  (messages) => {
    messages.forEach((msg) => {
      console.log("Message retrieved:", msg.payloadAsUtf8)
    })
  });

Find more examples below or checkout the latest main branch documentation at https://status-im.github.io/js-waku/docs/.

Docs can also be generated locally using:

npm install
npm run doc

Changelog

Release changelog can be found here.

Waku Protocol Support

You can track progress on the project board.

  • ✔: Supported
  • 🚧: Implementation in progress
  • : Support is not planned
Spec Implementation Status
6/WAKU1
7/WAKU-DATA
8/WAKU-MAIL
9/WAKU-RPC
10/WAKU2 🚧
11/WAKU2-RELAY
12/WAKU2-FILTER
13/WAKU2-STORE ✔ (querying node only)
14/WAKU2-MESSAGE
15/WAKU2-BRIDGE
16/WAKU2-RPC
17/WAKU2-RLNRELAY
18/WAKU2-SWAP
19/WAKU2-LIGHTPUSH

Bugs, Questions & Features

If you encounter any bug or would like to propose new features, feel free to open an issue.

For support, questions & more general topics, please join the discussion on the Vac forum (use #js-waku tag) or #waku-support on Status Discord.

Examples

Web Chat App (ReactJS)

A ReactJS chat app is provided as a showcase of the library used in the browser. A deployed version is available at https://status-im.github.io/js-waku/

Find the code in the examples folder.

To run a development version locally, do:

git clone https://github.com/status-im/js-waku/ ; cd js-waku
npm install   # Install dependencies for js-waku
npm run build # Build js-waku
cd examples/web-chat   
npm install   # Install dependencies for the web app
npm run start # Start development server to serve the web app on http://localhost:3000/js-waku

Use /help to see the available commands.

CLI Chat App (NodeJS)

A node chat app is provided as a working example of the library. It is interoperable with the nim-waku chat app example.

Find the code in the examples folder.

To run the chat app, first ensure you have Node.js v14 or above:

node --version

Then, install and run:

git clone https://github.com/status-im/js-waku/ ; cd js-waku
npm install   # Install dependencies for js-waku
npm run build # Build js-waku
cd examples/cli-chat
npm install # Install dependencies for the cli app
npm run start -- --autoDial

You can also specify an optional listenAddr parameter (.e.g --listenAddr /ip4/0.0.0.0/tcp/7777/ws). This is only useful if you want a remote node to dial to your chat app, it is not necessary in normal usage when you just connect to the fleet.

Contributing

See CONTRIBUTING.md.

License

Licensed and distributed under either of

or

at your option. These files may not be copied, modified, or distributed except according to those terms.