wormhole/lib/handshake.js
2021-02-03 02:26:48 +02:00

17 lines
No EOL
530 B
JavaScript

const crypto = require('crypto');
const { handshakeGUID } = require('./constants');
const generateWebsocketAcceptValue = (websocketKey) => {
if (typeof websocketKey !== 'string' || typeof handshakeGUID !== 'string') {
// TODO: maybe throw error?
return;
}
const concatenated = websocketKey + handshakeGUID;
const sha1HashInBase64 = crypto.createHash('sha1').update(concatenated, 'binary').digest('base64');
return sha1HashInBase64;
};
module.exports = { generateWebsocketAcceptValue };