Secure rpc-protocol over any duplex socket using noise-protocol.
npm install secure-rpc-protocol
// client.js
const secureRPC = require('secure-rpc-protocol')
const net = require('net')
const socket = new net.Socket()
socket.connect(8124, () => {
const rpc = secureRPC(socket, true)
rpc.call('echo', 'hello world', (err, res) => {
if (err) return console.error(err)
console.log(res) // [ 'hello world' ]
})
})
// server.js
const net = require('net')
const secureRPC = require('secure-rpc-protocol')
const server = net.createServer((socket) => {
const rpc = secureRPC(socket, false)
rpc.command('echo', (req) => {
console.log(req.arguments)
return req.arguments
})
})
server.listen(8124, () => {
console.log('server listening on 8124')
})
Import the secureRPC
factory function used to create a secureRPC instance.
Access to noise-peer. Useful for accessing peer.keygen
.
Pass in a duplex stream
and indicate if the stream isInitiator
according to what noise-protocol being used.
The opts
object is passed to noise-peer
with the exception of the encoder
property, which is passed to rpc-protocol.
See rpc-protocol docs on how to use the rpc api.
See noise-peer
and noise-protocol
and the included examples to understand the details of securing the connection.
- forward-secret-nn: Forward secret only, no authentication using the nn pattern.
- mutual-auth-xx: Mutual authentication using the xx pattern.
- client-auth-psk-xk: Client authentication with pre shared server key using the xk pattern.
- websockets: Example using
simple-websocket
demonstrating stream agnostic nature of the library.
- rpc-protocol
- noise-peer
- simple-handshake: Docs on the underlying handshake used by
noise-peer
- noise-protocol: Docs on the noise protocol itself.
- secret-handshake-over-hypercore: a precursor to this module.
- noise-network: Noise secured connections over hyperswarm.
- secure-wsnet: A precursor module specific to websockets.
- secure-websocket-rpc: A precursor module specific to websockets.
MIT