Skip to content

Commit

Permalink
fixes isNewKey flag
Browse files Browse the repository at this point in the history
  • Loading branch information
arch1995 committed Aug 26, 2024
1 parent 6d4c657 commit 3835d23
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/helpers/nodeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,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;
}[] = [];
const serverTimeOffsetResponses: string[] = [];

for (let i = 0; i < completedRequests.length; i += 1) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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));
Expand All @@ -542,7 +554,7 @@ export async function retrieveOrImportShare(params: {
sessionTokenData,
thresholdNonceData,
nodeIndexes,
isNewKey: thresholdIsNewKey === "true",
isNewKey,
serverTimeOffsetResponse: serverTimeOffset || calculateMedian(serverOffsetTimes),
};
}
Expand All @@ -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
}`
);
});
})
Expand Down

0 comments on commit 3835d23

Please sign in to comment.