Refactoring - WIP

This commit is contained in:
zuzanna-maria 2024-12-05 14:00:35 +01:00
parent ccfe1472e6
commit 9c87556332
4 changed files with 21 additions and 30 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;
});

View File

@ -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;