secure-wsnet
A secure websocket server and client network interface built on top of secret-handshake-over-hypercore to enable end-to-end encryption over web sockets.
Installation
$ npm install secure-wsnet
Usage
const wsnet = const sharedKey = Bufferconst server = wsnetserver const socket = wsnetsocket
API
server = new wsnet.Server(opts)
Creates a web socket server where opts
can be:
opts.sharedKey
is the shared key given to secret-handshake-over-hypercoreopts.capabilities
is an array of capabilities given to secret-handshake-over-hypercore
The rest of the opts
are passed directly to the simple-websocket
server.
const server = opts
server = wsnet.createServer(opts[, onconnection])
Where opts
is passed to new wsnet.Server(opts)
and then onconnection
callback will be called when the 'connection'
event is emitted.
const server = wsnetserver { conn}
addrinfo = server.address()
Returns the address
, family
, and port
that the server is bound to.
console // { address: '127.0.0.68', family: 'IPv4', port: 3000 }
server.listen(port[, hostname[, onlistening]])
Listen on a specified port on an optional host. The onlistening(err)
callback will be called with on error or when the servers 'listening'
event has been emitted.
server
server.listen(host[, onlistening]])
Listen on a specified host that can contain both the hostname and port
as a URI like ws:///localhost:3000
.
server
server.listen(opts[, onlistening]])
Listen based on options opts
that are passed directly to the simple-websocket
server. The
onlistening(err)
callback will be called with on error or when the
servers 'listening'
event has been emitted.
server
socket = new wsnet.Socket(opts)
Creates a new secure web socket where opts
can be
opts.sharedKey
is the shared key given to secret-handshake-over-hypercoreopts.capabilities
is an array of capabilities given to secret-handshake-over-hypercore
The rest of the opts
are passed directly to
secret-handshake-over-hypercore's Connection() constructor.
const socket = opts
socket.localAddress
The local address of the Socket
.
socket.localPort
The local port of the Socket
.
socket.remoteAddress
The remote address of the Socket
connection. This value is populated
after the 'connect'
event.
socket.remoteFamily
The remote family of the Socket
connection. This value is populated
after the 'connect'
event.
socket.remotePort
The remote port of the Socket
connection. This value is populated
after the 'connect'
event.
socket.connect(port[, hostname[, onconnect]])
Connect to a host specified by port
and hostname
calling
onconnect(err)
when connected to the host.
socket
socket = wsnet.connect(port[, hostname], opts[, onconnect])
Connect to a host specified by port
and hostname
. If you do not
provide a hostname
and window.location.hostname
will be used if you
are in a browser otherwise 'localhost'
.
const socket = wsnet
socket = wsnet.connect(port, opts[, onconnect])
Connect to 'localhost'
or opts.host
at port
.
const socket = wsnet
socket = wsnet.connect(opts[, onconnect])
Connect to a host specified by opts.host
and opts.port
.
const socket = wsnet
License
MIT