Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/is-new-key-flag #159

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading