KLY_Utils/signatures/threshold/tbls.js
KLY_Utils/signatures/threshold/tbls_index.js
Added share recovery mechanism for lost shares
Added share verification with commitments
Added share refreshing capability for increased security
Improved error handling and type safety
Added memory cleanup to prevent leaks
import * as dkg from './tbls_index.js';
import bls from 'bls-eth-wasm';
await bls.init(bls.BLS12_381);
export default {
// ... existing functions ...
// Add share recovery for lost shares
recoverShare: (threshold: number, shares: {index: number, value: string}[]): string => {
if (shares.length < threshold) {
throw new Error("Not enough shares for recovery");
}
const sk = new bls.SecretKey();
const indices = shares.map(s => s.index);
const values = shares.map(s => bls.deserializeHexStrToSecretKey(s.value));
sk.recover(values, indices);
const recoveredShare = sk.serializeToHexStr();
// Cleanup
sk.clear();
values.forEach(v => v.clear());
return recoveredShare;
},
// Add share verification with commitment
verifyShareWithCommitment: (
share: string,
commitment: string[],
index: number
): boolean => {
const sk = bls.deserializeHexStrToSecretKey(share);
const pk = sk.getPublicKey();
// Convert commitment to public keys
const commitmentPks = commitment.map(c =>
bls.deserializeHexStrToPublicKey(c)
);
// Verify against commitment
const derivedPk = new bls.PublicKey();
derivedPk.share(commitmentPks, index);
const isValid = pk.isEqual(derivedPk);
// Cleanup
sk.clear();
pk.clear();
derivedPk.clear();
commitmentPks.forEach(c => c.clear());
return isValid;
},
// Add refreshing of shares periodically
refreshShares: (
threshold: number,
currentShares: string[],
participants: number[]
): {newShares: string[], commitment: string[]} => {
// Generate new polynomial while preserving the secret
const contribution = dkg.generateContribution(bls, participants, threshold);
// Add current shares to new shares
const newShares = currentShares.map((share, i) => {
const current = bls.deserializeHexStrToSecretKey(share);
const refresh = bls.deserializeHexStrToSecretKey(
contribution.secretKeyContribution[i]
);
current.add(refresh);
const newShare = current.serializeToHexStr();
current.clear();
refresh.clear();
return newShare;
});
return {
newShares,
commitment: contribution.verificationVector.map(v =>
v.serializeToHexStr()
)
};
}
};
KLY_Utils/signatures/threshold/tbls.js
KLY_Utils/signatures/threshold/tbls_index.js
Added share recovery mechanism for lost shares
Added share verification with commitments
Added share refreshing capability for increased security
Improved error handling and type safety
Added memory cleanup to prevent leaks
import * as dkg from './tbls_index.js';
import bls from 'bls-eth-wasm';
await bls.init(bls.BLS12_381);
export default {
// ... existing functions ...
// Add share recovery for lost shares
recoverShare: (threshold: number, shares: {index: number, value: string}[]): string => {
if (shares.length < threshold) {
throw new Error("Not enough shares for recovery");
}
},
// Add share verification with commitment
verifyShareWithCommitment: (
share: string,
commitment: string[],
index: number
): boolean => {
const sk = bls.deserializeHexStrToSecretKey(share);
const pk = sk.getPublicKey();
},
// Add refreshing of shares periodically
refreshShares: (
threshold: number,
currentShares: string[],
participants: number[]
): {newShares: string[], commitment: string[]} => {
// Generate new polynomial while preserving the secret
const contribution = dkg.generateContribution(bls, participants, threshold);
}
};