-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
52 lines (44 loc) · 1.55 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var sws = require('./sws');
module.exports = sws.SecureWebSocket;
module.exports.Server = require('./SecureWebSocketServer');
module.exports.Stream = require('./SecureStream');
module.exports.createServer = function (options, connectionListener) {
var kp;
// check on secinfo
if (!(options.secinfo && typeof options.secinfo === 'object')) {
kp = sws.keyPair();
options.secinfo = {myPublicKey: kp.publicKey, mySecretKey: kp.mySecretKey};
}
var server = new module.exports.Server(options, options.secinfo);
if (typeof connectionListener === 'function') {
server.on('connection', connectionListener);
}
return server;
};
module.exports.connect = module.exports.createConnection = function (address, secinfo, openListener) {
var kp;
// check on secinfo
if (secinfo && typeof secinfo === 'function') {
openListener = secinfo;
kp = sws.keyPair();
secinfo = {myPublicKey: kp.publicKey, mySecretKey: kp.mySecretKey};
} else if (!(secinfo && typeof secinfo === 'object')) {
kp = sws.keyPair();
secinfo = {myPublicKey: kp.publicKey, mySecretKey: kp.mySecretKey};
}
var client = new module.exports(address, secinfo);
if (typeof openListener === 'function') {
client.on('open', openListener);
}
return client;
};
// NACL
module.exports.keyPair = sws.keyPair;
module.exports.Box = sws.Box;
module.exports.SecretBox = sws.SecretBox;
// NACL Cert System
module.exports.Naclcert = sws.Naclcert;
// Utils
module.exports.ArrayToUint8 = sws.ArrayToUint8;
module.exports.Uint8ToArray = sws.Uint8ToArray;
module.exports.Uint8ToBuffer = sws.Uint8ToBuffer;