Weapon of Mass Decentralization
Provides a flexible, transport-layer abstraction for various network protocols. By utilizing a base transport class, newk
allows for easy extension and customization of network communication patterns. It comes with an NKN (New Kind of Network) and memory bus transport implementation and supports message routing, publish/subscribe patterns, and basic message handling.
- Transport-layer abstraction with a base class for easy extension.
- Built-in NKN transport implementation for decentralized communication.
- Support for Pub/Sub mechanisms.
- Extendable with various decorators for additional functionality.
- Straightforward message routing.
npm install newk
Import the Newk
class mixin from the package:
import Newk from 'newk'
or
const Newk = require('newk')
// Initialize with options
const options = {
identifier: 'your-identifier',
transport: 'bus', // or 'nkn'
decorators: ['pubsub', 'encryption'],
// ... other options
}
const newk = await Newk.init(options, transportType)
newk.addRoute('action', handlerFunction)
newk.addRoutes(anObjectContainingMethods) // each method that starts with `on` is route
await newk.send(destination, payload, options)
await newk.dispatch(destination, messageType, data, options)
await newk.subscribe(topic, metadata)
await newk.unsubscribe(topic)
await newk.publish(topic, payload)
await newk.broadcast(topic, messageType, data, options, excludeSelf)
await newk.getSubscribers(topic, metadata)
await newk.discover(topic, metadata, ...)
The onMessage
method is used to handle incoming messages:
newk.onMessage((message) => {
// Handle the message
})
To manage connections with NknConnect
:
const nknConnect = await NknConnect.init(options)
You can use onMessage
, onConnect
, and onWsError
methods to handle different connection events.
In order to run the test suite, simply clone the repository and install its dependencies:
git clone https://gitlab.com/basedwon/newk.git
cd newk
npm install
To run the tests:
npm test
Thank you! Please see our contributing guidelines for details.
If you find this project useful and want to help support further development, please send us some coin. We greatly appreciate any and all contributions. Thank you!
Bitcoin (BTC):
1JUb1yNFH6wjGekRUW6Dfgyg4J4h6wKKdF
Monero (XMR):
46uV2fMZT3EWkBrGUgszJCcbqFqEvqrB4bZBJwsbx7yA8e2WBakXzJSUK8aqT4GoqERzbg4oKT2SiPeCgjzVH6VpSQ5y7KQ
Newk is MIT licensed.