From 3835d23a1615d8aee4071368111a92eab8b09abb Mon Sep 17 00:00:00 2001 From: Archit Date: Mon, 26 Aug 2024 14:32:23 +0530 Subject: [PATCH] fixes isNewKey flag --- src/helpers/nodeUtils.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/helpers/nodeUtils.ts b/src/helpers/nodeUtils.ts index 377c573..9f1191e 100644 --- a/src/helpers/nodeUtils.ts +++ b/src/helpers/nodeUtils.ts @@ -394,7 +394,10 @@ export async function retrieveOrImportShare(params: { const sessionTokenPromises: Promise[] = []; const nodeIndexes: BN[] = []; const sessionTokenData: SessionToken[] = []; - const isNewKeyResponses: string[] = []; + const isNewKeyResponses: { + isNewKey: string; + publicKey: string; + }[] = []; const serverTimeOffsetResponses: string[] = []; for (let i = 0; i < completedRequests.length; i += 1) { @@ -409,7 +412,10 @@ export async function retrieveOrImportShare(params: { server_time_offset: serverTimeOffsetResponse, } = currentShareResponse.result; - isNewKeyResponses.push(isNewKey); + isNewKeyResponses.push({ + isNewKey, + publicKey: currentShareResponse.result?.keys[0]?.public_key?.X || "", + }); serverTimeOffsetResponses.push(serverTimeOffsetResponse || "0"); if (sessionTokenSigs?.length > 0) { @@ -531,7 +537,13 @@ export async function retrieveOrImportShare(params: { if (privateKey === undefined || privateKey === null) { throw new Error("could not derive private key"); } - const thresholdIsNewKey = thresholdSame(isNewKeyResponses, minThreshold); + let isNewKey = false; + + isNewKeyResponses.forEach((x) => { + if (x.isNewKey === "true" && x.publicKey.toLowerCase() === thresholdPublicKey.X.toLowerCase()) { + isNewKey = true; + } + }); // Convert each string timestamp to a number const serverOffsetTimes = serverTimeOffsetResponses.map((timestamp) => Number.parseInt(timestamp, 10)); @@ -542,7 +554,7 @@ export async function retrieveOrImportShare(params: { sessionTokenData, thresholdNonceData, nodeIndexes, - isNewKey: thresholdIsNewKey === "true", + isNewKey, serverTimeOffsetResponse: serverTimeOffset || calculateMedian(serverOffsetTimes), }; } @@ -551,7 +563,9 @@ export async function retrieveOrImportShare(params: { throw new Error(`Waiting for results from more nodes, pending: ${thresholdReqCount - completedRequests.length}`); } throw new Error( - `Invalid results, threshold pub key: ${thresholdPublicKey}, nonce data found: ${!!thresholdNonceData}, extended verifierId: ${verifierParams.extended_verifier_id}` + `Invalid results, threshold pub key: ${thresholdPublicKey}, nonce data found: ${!!thresholdNonceData}, extended verifierId: ${ + verifierParams.extended_verifier_id + }` ); }); })