diff --git a/src/helpers/nodeUtils.ts b/src/helpers/nodeUtils.ts index ffc7cc3..f890d33 100644 --- a/src/helpers/nodeUtils.ts +++ b/src/helpers/nodeUtils.ts @@ -507,7 +507,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) { @@ -522,7 +525,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) { @@ -644,7 +650,12 @@ export async function retrieveOrImportShare(params: { throw new Error("could not derive private key"); } - const thresholdIsNewKey = thresholdSame(isNewKeyResponses, halfThreshold); + 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)); @@ -655,7 +666,7 @@ export async function retrieveOrImportShare(params: { thresholdNonceData, nodeIndexes, thresholdPubKey: thresholdPublicKey, - isNewKey: thresholdIsNewKey === "true", + isNewKey, serverTimeOffsetResponse: serverTimeOffset || calculateMedian(serverOffsetTimes), }; } diff --git a/src/torus.ts b/src/torus.ts index 404410c..08fe50c 100644 --- a/src/torus.ts +++ b/src/torus.ts @@ -128,6 +128,9 @@ class Torus { // for ed25519 keys import keys flows is the default let shouldUseDkg; if (typeof useDkg === "boolean") { + if (useDkg === false && LEGACY_NETWORKS_ROUTE_MAP[this.network as TORUS_LEGACY_NETWORK_TYPE]) { + throw new Error(`useDkg cannot be false for legacy network; ${this.network}`); + } shouldUseDkg = useDkg; } else if (this.keyType === KEY_TYPE.ED25519) { shouldUseDkg = false; @@ -176,6 +179,9 @@ class Torus { async importPrivateKey(params: ImportKeyParams): Promise { const { nodeIndexes, newPrivateKey, verifier, verifierParams, idToken, nodePubkeys, endpoints, extraParams = {} } = params; + if (LEGACY_NETWORKS_ROUTE_MAP[this.network as TORUS_LEGACY_NETWORK_TYPE]) { + throw new Error(`importPrivateKey is not supported by legacy network; ${this.network}`); + } if (endpoints.length !== nodeIndexes.length) { throw new Error(`length of endpoints array must be same as length of nodeIndexes array`); }