Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mafintosh/noise-network
Authenticated P2P network backed by Hyperswarm and Noise
https://github.com/mafintosh/noise-network
Last synced: about 1 month ago
JSON representation
Authenticated P2P network backed by Hyperswarm and Noise
- Host: GitHub
- URL: https://github.com/mafintosh/noise-network
- Owner: mafintosh
- License: mit
- Created: 2018-11-22T07:12:29.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-23T08:01:51.000Z (over 5 years ago)
- Last Synced: 2024-10-16T23:33:50.867Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 17.6 KB
- Stars: 96
- Watchers: 7
- Forks: 13
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-peer-to-peer - noise-network
- awesome-peer-to-peer - noise-network
README
# noise-network
Authenticated network P2P backed by [Hyperswarm](https://github.com/hyperswarm) and [Noise](https://github.com/emilbayes/noise-peer)
## Usage
First spin up a server
```js
const noise = require('noise-network')const server = noise.createServer()
server.on('connection', function (encryptedStream) {
console.log('new encrypted stream!')// encryptedStream is a noise-peer stream instance
encryptedStream.on('data', function (data) {
console.log('client wrote:', data)
})
})const keyPair = noise.keygen()
// Announce ourself to the HyperSwarm DHT on the following keyPair's publicKey
server.listen(keyPair, function () {
console.log('Server is listening on:', server.publicKey.toString('hex'))
})
```Then connect to the server by connecting to the public key
```js
// noise guarantees that we connect to the server in a E2E encrypted stream
const client = noise.connect('{public key from above}')// client is a noise-peer stream instance
client.write('hello server')
```## API
#### `const server = noise.createServer([options])`
Create a new Noise server.
Options include:
```js
{
// validate the remote client's public key before allowing them to connect
validate (remoteKey, done) { ... },
// you can add the onconnection handler here also
onconnection (connection) { ... }
}
```#### `const client = noise.connect(serverPublicKey, [keyPair])`
Connect to a server. Does UDP hole punching if necessary.
`serverPublicKey` must be of type Buffer or hex.## License
MIT