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

fixes is new key flag #161

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
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