Skip to content

Commit

Permalink
fixes for isNewKey flag
Browse files Browse the repository at this point in the history
  • Loading branch information
arch1995 committed Aug 26, 2024
1 parent 6f308ae commit def8983
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/helpers/nodeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,10 @@ export async function retrieveOrImportShare(params: {
const sessionTokenPromises: Promise<void | Buffer>[] = [];
const nodeIndexes: BN[] = [];
const sessionTokenData: SessionToken[] = [];
const isNewKeyResponses: string[] = [];
const isNewKeyResponses: {
isNewKey: string;
publicKey: string;
}[] = [];

for (let i = 0; i < completedRequests.length; i += 1) {
const currentShareResponse = completedRequests[i] as JRPCResponse<ShareRequestResult>;
Expand All @@ -372,7 +375,10 @@ export async function retrieveOrImportShare(params: {
is_new_key: isNewKey,
} = currentShareResponse.result;

isNewKeyResponses.push(isNewKey);
isNewKeyResponses.push({
isNewKey,
publicKey: currentShareResponse.result?.keys[0]?.public_key?.X || "",
});

if (sessionTokenSigs?.length > 0) {
// decrypt sessionSig if enc metadata is sent
Expand Down Expand Up @@ -494,9 +500,15 @@ export async function retrieveOrImportShare(params: {
if (privateKey === undefined || privateKey === null) {
throw new Error("could not derive private key");
}
const thresholdIsNewKey = thresholdSame(isNewKeyResponses, ~~(endpoints.length / 2) + 1);
let isNewKey = false;

return { privateKey, sessionTokenData, thresholdNonceData, nodeIndexes, isNewKey: thresholdIsNewKey === "true" };
isNewKeyResponses.forEach((x) => {
if (x.isNewKey === "true" && x.publicKey.toLowerCase() === thresholdPublicKey.X.toLowerCase()) {
isNewKey = true;
}
});

return { privateKey, sessionTokenData, thresholdNonceData, nodeIndexes, isNewKey };
}
throw new Error("Invalid");
});
Expand Down

0 comments on commit def8983

Please sign in to comment.