handshake buffer generator in pure javascript