Skip to content

Commit

Permalink
error check fixed for non commitment lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshuchawla009 committed Sep 5, 2024
1 parent 8d999e5 commit f83417e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
14 changes: 8 additions & 6 deletions src/helpers/nodeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const GetPubKeyOrKeyAssign = async (params: {
});

const errorResult = thresholdSame(
lookupPubKeys.map((x2) => x2 && x2.error),
lookupResults.map((x2) => x2 && x2.error),
minThreshold
);

Expand Down Expand Up @@ -191,7 +191,7 @@ export const VerifierLookupRequest = async (params: {
});

const errorResult = thresholdSame(
lookupPubKeys.map((x2) => x2 && x2.error),
lookupResults.map((x2) => x2 && x2.error),
minThreshold
);

Expand Down Expand Up @@ -283,19 +283,21 @@ export async function retrieveOrImportShare(params: {
}
finalImportedShares = newImportedShares;
} else if (!useDkg) {
// TODO: why use getrandombytes here?
const bufferKey = keyType === KEY_TYPE.SECP256K1 ? generatePrivateKey(ecCurve, Buffer) : await getRandomBytes(32);
const generatedShares = await generateShares(ecCurve, keyType, serverTimeOffset, indexes, nodePubkeys, Buffer.from(bufferKey));
finalImportedShares = [...finalImportedShares, ...generatedShares];
}
let existingPubKey;
// can only import shares if override existing key is allowed or for new non dkg registration
// can only import new shares if override existing key is allowed or when doing a new non dkg registration
if (finalImportedShares.length > 0) {
// in case not allowed to overide existing key for import request
// in case not allowed to override existing key for import request
// check if key exists
if (!overrideExistingKey) {
const keyLookupResult = await VerifierLookupRequest({ endpoints, verifier, verifierId: verifierParams.verifier_id, keyType });
if (keyLookupResult.errorResult) {
if (
keyLookupResult.errorResult &&
!(keyLookupResult.errorResult?.data as string)?.includes("Verifier + VerifierID has not yet been assigned")
) {
throw new Error(
`node results do not match at first lookup ${JSON.stringify(keyLookupResult.keyResult || {})}, ${JSON.stringify(keyLookupResult.errorResult || {})}`
);
Expand Down
7 changes: 1 addition & 6 deletions test/sapphire_devnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe.only("torus utils sapphire devnet", function () {
});
});

it.only("should be able to login a v1 user", async function () {
it("should be able to login a v1 user", async function () {
const email = "[email protected]";
const verifier = "google-lrc";
const token = generateIdToken(email, "ES256");
Expand Down Expand Up @@ -122,11 +122,6 @@ describe.only("torus utils sapphire devnet", function () {
},
nodesData: retrieveSharesResponse.nodesData,
});
const retrieveSharesResponse1 = await legacyTorus.retrieveShares(
getRetrieveSharesParams(torusNodeEndpoints, torusIndexes, TORUS_TEST_VERIFIER, { verifier_id: email }, token, torusNodePub)
);
// eslint-disable-next-line no-console
console.log("retrieveSharesResponse1", retrieveSharesResponse1);
});

it("should fetch user type and public address of legacy v2 user", async function () {
Expand Down
2 changes: 1 addition & 1 deletion test/testnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const TORUS_TEST_EMAIL = "[email protected]";
const TORUS_TEST_VERIFIER = "torus-test-health";
const TORUS_TEST_AGGREGATE_VERIFIER = "torus-test-health-aggregate";

describe("torus utils migrated testnet on sapphire", function () {
describe.only("torus utils migrated testnet on sapphire", function () {
let torus: TorusUtils;
let TORUS_NODE_MANAGER: NodeDetailManager;

Expand Down

0 comments on commit f83417e

Please sign in to comment.