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

Add getTrusteeContactsPublicKeys

parent cd7a4d55
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
This commit is part of merge request !88. Comments created here will be created in the context of that merge request.
......@@ -40,6 +40,12 @@ import {
STATUS_USER_BLOCKED
} from "../constants/statuses";
import generateQrCode from "../utilities/generateQrCode";
import {
generateRecoveryKey,
divideSecretToShares,
combineSecret,
encryptShare
} from "../utilities/secrets";
const penpalMethods = require("../../temp/penpal-methods").default;
const WopiAPI = require("./wopiapi-iframe");
......@@ -282,6 +288,28 @@ const handleIdentityLogin = (identity, uuid, token) => {
setKeyForUUID(uuid, publicKey);
};
const getTrusteeContactsPublicKeys = async () => {
const { viamApi } = window;
const response = await viamApi.contactsGetTrusteeContactsPublicKeys();
console.log({ response });
if (response.data.code !== "200") return response.data;
const sharesNumber = response.data.data;
const getThreshold = () =>
sharesNumber === 3 ? 2 : parseInt(sharesNumber / 2);
const threshold = getThreshold();
console.log({ threshold });
const recoveryKey = generateRecoveryKey(512);
const recoveryKeyShares = divideSecretToShares(
recoveryKey,
sharesNumber,
threshold
);
// Sanity check
const checkKey = combineSecret(recoveryKeyShares.slice(0, 1));
console.log("first sanity check", checkKey === recoveryKey);
};
async function executeRestfulFunction(type, that, fn, config, ...args) {
const {
currentlyAuthenticatedIdentity,
......@@ -394,7 +422,7 @@ function loadIdentityInternal(identityKey, pinCode) {
window.viamAnonymousApi.setIdentity(
window.currentlyLoadedIdentity.authentication.publicKey
);
getTrusteeContactsPublicKeys();
const { publicKey, x509Certificate } = loadedIdentity.authentication;
result({
......@@ -717,10 +745,7 @@ const connection = Penpal.connectToParent({
});
});
},
finalizeEmployeeRegistration: async (
identity,
identifier
) => {
finalizeEmployeeRegistration: async (identity, identifier) => {
viamApi.setIdentity(identity.authentication.publicKey);
return executeRestfulFunction(
"public",
......
......@@ -5,6 +5,7 @@ export /**
* Function generates a random bits length string, and output it in hexadecimal format
*
* @param {number} bits
* @returns {string} hex
*/
const generateRecoveryKey = bits => secrets.random(bits);
......@@ -15,6 +16,7 @@ const generateRecoveryKey = bits => secrets.random(bits);
* @param {number} numShares
* @param {number} threshold
* @param {number} [padLength=128]
* @returns {array}
*/
export const divideSecretToShares = (
secret,
......@@ -27,6 +29,7 @@ export const divideSecretToShares = (
* Reconstructs a secret from shares
*
* @param {array} shares
* @returns {string}
*/
export const combineSecret = shares => secrets.combine(shares);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment