Seperated common crypto operations to common file and made common toolbar used for both pad and spreadsheet

This commit is contained in:
Caleb James DeLisle
2015-01-30 16:52:23 +01:00
parent e039e90a24
commit 0e44b10aeb
5 changed files with 156 additions and 218 deletions

View File

@@ -2,39 +2,22 @@ define([
'/api/config?cb=' + Math.random().toString(16).substring(2),
'/pad/realtime-wysiwyg.js',
'/common/messages.js',
'/common/crypto.js',
'/bower_components/jquery/dist/jquery.min.js',
'/bower_components/ckeditor/ckeditor.js',
'/bower_components/tweetnacl/nacl-fast.min.js',
], function (Config, RTWysiwyg, Messages) {
], function (Config, RTWysiwyg, Messages, Crypto) {
var Ckeditor = window.CKEDITOR;
var Nacl = window.nacl;
var $ = jQuery;
var module = { exports: {} };
var parseKey = function (str) {
var array = Nacl.util.decodeBase64(str);
var hash = Nacl.hash(array);
return { lookupKey: hash.subarray(32), cryptKey: hash.subarray(0,32) };
};
var genKey = function () {
return Nacl.util.encodeBase64(Nacl.randomBytes(18));
};
var userName = function () {
return Nacl.util.encodeBase64(Nacl.randomBytes(8));
};
var $ = window.jQuery;
$(function () {
$(window).on('hashchange', function() {
window.location.reload();
});
if (window.location.href.indexOf('#') === -1) {
window.location.href = window.location.href + '#' + genKey();
window.location.href = window.location.href + '#' + Crypto.genKey();
return;
}
var key = parseKey(window.location.hash.substring(1));
var key = Crypto.parseKey(window.location.hash.substring(1));
var editor = Ckeditor.replace('editor1', {
removeButtons: 'Source,Maximize',
// This plugin inserts html crap into the document which is not part of the document
@@ -48,8 +31,8 @@ define([
var rtw =
RTWysiwyg.start(Config.websocketURL,
userName(),
Nacl.util.encodeBase64(key.lookupKey).substring(0,10),
Crypto.rand64(8),
key.channel,
key.cryptKey);
editor.on('change', function () { rtw.onEvent(); });
});