From 9c87556332838473584f105bec92df7ea1b63cd7 Mon Sep 17 00:00:00 2001 From: zuzanna-maria Date: Thu, 5 Dec 2024 14:00:35 +0100 Subject: [PATCH] Refactoring - WIP --- www/common/cryptpad-common.js | 11 +++++++++++ www/common/sframe-common-outer.js | 12 +----------- www/form/export.js | 12 ++++++------ www/form/main.js | 16 +++------------- 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index ada56e9be..bf7ea514d 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -2449,6 +2449,17 @@ define([ window.RTCPeerConnection); }; + common.getAnonymousKeys = function (formSeed, channel, Utils) { + var array = window.nacl.util.decodeBase64(formSeed + channel); + var hash = window.nacl.hash(array); + var secretKey = window.nacl.util.encodeBase64(hash.subarray(32)); + var publicKey = Utils.Hash.getCurvePublicFromPrivate(secretKey); + return { + curvePrivate: secretKey, + curvePublic: publicKey, + }; + }; + common.ready = (function () { var env = {}; var initialized = false; diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 53bda5d9e..036e7edfd 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -353,18 +353,8 @@ define([ })); }).nThen(function () { if (!network) { return void cb({error: "E_CONNECT"}); } - var getAnonymousKeys = function (formSeed, channel) { - var array = Nacl.util.decodeBase64(formSeed + channel); - var hash = Nacl.hash(array); - var secretKey = Nacl.util.encodeBase64(hash.subarray(32)); - var publicKey = Utils.Hash.getCurvePublicFromPrivate(secretKey); - return { - curvePrivate: secretKey, - curvePublic: publicKey, - }; - }; if (myFormKeys.formSeed) { - myFormKeys = getAnonymousKeys(myFormKeys.formSeed, data.channel); + myFormKeys = _Cryptpad.getAnonymousKeys(myFormKeys.formSeed, data.channel, Utils); } var keys; var privateKey, publicKey; diff --git a/www/form/export.js b/www/form/export.js index 9ced9c83b..a3b3a1c3f 100644 --- a/www/form/export.js +++ b/www/form/export.js @@ -4,7 +4,7 @@ define([ '/common/common-util.js', - '/customize/messages.js', + '/customize/messages.js' ], function (Util, Messages) { var Export = { ext: '.json' @@ -194,11 +194,11 @@ define([ } var json = Util.clone(content || {}); - delete json.answers; - cb(new Blob([JSON.stringify(json, 0, 2)], { - type: 'application/json;charset=utf-8' - })); - }; + delete json.answers; + cb(new Blob([JSON.stringify(json, 0, 2)], { + type: 'application/json;charset=utf-8' + })); + }; return Export; }); diff --git a/www/form/main.js b/www/form/main.js index dab04bb8f..aa47abf73 100644 --- a/www/form/main.js +++ b/www/form/main.js @@ -64,16 +64,6 @@ define([ if (!a) { sframeChan.event('EV_POPUP_BLOCKED'); } delete sessionStorage.CP_formExportSheet; }); - var getAnonymousKeys = function (formSeed, channel) { - var array = Nacl.util.decodeBase64(formSeed + channel); - var hash = Nacl.hash(array); - var secretKey = Nacl.util.encodeBase64(hash.subarray(32)); - var publicKey = Utils.Hash.getCurvePublicFromPrivate(secretKey); - return { - curvePrivate: secretKey, - curvePublic: publicKey, - }; - }; var u8_concat = function (A) { var length = 0; A.forEach(function (a) { length += a.length; }); @@ -150,7 +140,7 @@ define([ console.error('ANONYMOUS_ERROR', answer); return; } - finalKeys = getAnonymousKeys(myKeys.formSeed, data.channel); + finalKeys = Cryptpad.getAnonymousKeys(myKeys.formSeed, data.channel, Utils); } Cryptpad.getHistoryRange({ channel: data.channel, @@ -209,9 +199,9 @@ define([ var myAnonymousKeys; if (data.anonymous) { if (!myKeys.formSeed) { return void cb({ error: "ANONYMOUS_ERROR" }); } - myKeys = getAnonymousKeys(myKeys.formSeed, box.channel); + myKeys = Cryptpad.getAnonymousKeys(myKeys.formSeed, box.channel, Utils); } else { - myAnonymousKeys = getAnonymousKeys(myKeys.formSeed, box.channel); + myAnonymousKeys = Cryptpad.getAnonymousKeys(myKeys.formSeed, box.channel, Utils); } var keys = Utils.secret && Utils.secret.keys; myKeys.signingKey = keys.secondarySignKey;