wormhole/lib/handshake.js

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