wormhole/lib/handshake.js

17 lines
534 B
JavaScript
Raw Normal View History

2021-01-26 12:04:53 +02:00
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 sha1HashedInBase64 = crypto.createHash('sha1').update(concatenated, 'binary').digest('base64');
return sha1HashedInBase64;
};
module.exports = { generateWebsocketAcceptValue };