crypto-keygen-suite
Version:
Key generation utilities for cryptographic operations. YES I RENAMED IT OMG BASES AND PROTOCOLS!!! See its folder for all <3
23 lines (20 loc) • 641 B
JavaScript
function combineShares(shares) {
const totalShares = shares.length;
const secretLength = shares[0].length;
let reconstructedSecret = new Array(secretLength).fill(0);
}
for (let i = 0; i < totalShares; i++) {
const share = shares[i];
const x_i = share[0];
const y_i = share[1];
for (let j = 0; j < totalShares; j++) {
if (i !== j) {
const x_j = shares[j][0];
const lagrangeCoefficient = x_j / (x_j - x_i);
for (let k = 0; k < secretLength; k++) {
reconstructedSecret[k] += y_i * lagrangeCoefficient;
}
}
}
}
return reconstructedSecret;