Skip to content
Snippets Groups Projects
Commit 165c12ad authored by Sasha Ilieva's avatar Sasha Ilieva
Browse files

Fix checkRecoveryKeyCombine

parent 006aac5c
No related branches found
No related tags found
1 merge request!88908 account recovery ability to add contacts to trusted contacts list for account recovery
export const RECOMMENDED_TRUSTEES = 3;
export const THRESHOLD = 2;
......@@ -2,8 +2,7 @@ import secrets from "../lib/secrets";
import { encryptMessage } from "./signingUtilities";
import { encodeResponse } from "./appUtility";
import { getSliceRange } from "./numberUtilities";
const THRESHOLD = 2;
import { THRESHOLD } from "../constants/secrets";
/** Initialize
*/
......@@ -58,21 +57,29 @@ export const getRecoveryKeyShares = (recoveryKey, sharesNumber) => {
return divideSecretToShares(recoveryKey, sharesNumber, THRESHOLD);
};
function getSecretSliceRange(max) {
const { beginIndex, endIndex } = getSliceRange(max);
if (endIndex - beginIndex < THRESHOLD) {
return getSecretSliceRange(max);
}
return { beginIndex, endIndex };
}
export const checkRecoveryKeyCombine = (recoveryKey, recoveryKeyShares) => {
let checkKey;
if (recoveryKeyShares.length > 1) {
const { beginIndex, endIndex } = getSliceRange(
recoveryKeyShares.length - 1
);
checkKey = combineSecret(recoveryKeyShares.slice(beginIndex, endIndex));
if (checkKey !== recoveryKey) {
return encodeResponse("400", "", "First sanity check failed");
}
checkKey = combineSecret(recoveryKeyShares.slice(0, 1));
if (checkKey === recoveryKey) {
return encodeResponse("400", "", "Second sanity check failed");
}
const { beginIndex, endIndex } = getSecretSliceRange(
recoveryKeyShares.length + 1
);
console.log({ beginIndex, endIndex });
checkKey = combineSecret(recoveryKeyShares.slice(beginIndex, endIndex));
if (checkKey !== recoveryKey) {
return encodeResponse("400", "", "First sanity check failed");
}
checkKey = combineSecret(recoveryKeyShares.slice(0, 2));
if (checkKey === recoveryKey) {
return encodeResponse("400", "", "Second sanity check failed");
}
checkKey = combineSecret(recoveryKeyShares);
if (checkKey !== recoveryKey) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment