From f30db4fc0d118be1cc975eec63dee621c3828c52 Mon Sep 17 00:00:00 2001 From: sysop1984 Date: Fri, 21 Aug 2026 21:12:07 +0200 Subject: [PATCH] Fix #70: Add threshold validation to __restore_secret The __restore_secret function performed Lagrange interpolation unconditionally over whatever shares were supplied. When fewer than threshold shares were provided, it silently returned a wrong secret with no error, leading to loss of access in wallet-recovery use cases. This fix adds a required threshold parameter and validates that at least threshold shares are present before performing interpolation. Fixes: #70 --- src/functions/shamir_secret_sharing.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/functions/shamir_secret_sharing.js b/src/functions/shamir_secret_sharing.js index def4f16..c7f649d 100644 --- a/src/functions/shamir_secret_sharing.js +++ b/src/functions/shamir_secret_sharing.js @@ -143,7 +143,14 @@ module.exports = function (S) { return shares; }; - S.__restore_secret = (shares) => { + S.__restore_secret = (shares, threshold) => { + if (threshold === undefined) { + throw new Error("Threshold parameter is required. Call __restore_secret(shares, threshold)"); + } + const shareCount = Object.keys(shares).length; + if (shareCount < threshold) { + throw new Error(`Need at least ${threshold} shares to recover the secret, but only ${shareCount} provided`); + } let secret = BF([]); let shareLength = null; let q = [];