Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianHymer committed Jan 6, 2025
1 parent fe527f7 commit 903faca
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 187 deletions.
11 changes: 11 additions & 0 deletions iam/__tests__/additional_signer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ import { getEip712Issuer } from "../src/issuers.js";

const issuer = getEip712Issuer();

jest.mock("../src/utils/oprf", () => ({
recordToNullifier: async ({ record }: any) => {
const crypto = await import("crypto");
const hash = crypto.createHash("sha256");

hash.update(JSON.stringify(record));

return hash.digest("hex");
},
}));

jest.mock("../src/utils/bans", () => ({
checkCredentialBans: jest.fn().mockImplementation((input) => Promise.resolve(input)),
}));
Expand Down
11 changes: 11 additions & 0 deletions iam/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ import { toJsonObject } from "../src/utils/json.js";

const issuer = getEip712Issuer();

jest.mock("../src/utils/oprf", () => ({
recordToNullifier: async ({ record }: any) => {
const crypto = await import("crypto");
const hash = crypto.createHash("sha256");

hash.update(JSON.stringify(record));

return hash.digest("hex");
},
}));

jest.mock("../src/utils/bans", () => ({
checkCredentialBans: jest.fn().mockImplementation((input) => Promise.resolve(input)),
}));
Expand Down
1 change: 1 addition & 0 deletions iam/jest.setup.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ process.env.SCROLL_BADGE_ATTESTATION_SCHEMA_UID =
"0xa35b5470ebb301aa5d309a8ee6ea258cad680ea112c86e456d5f2254448afc74";
process.env.MISHTI_CLIENT_PRIVATE_KEY =
"0x04d16281ff3bf268b29cdd684183f72542757d24ae9fdfb863e7c755e599163a";
process.env.MISHTI_RELAY_URL = "http://127.0.0.1:8081";
1 change: 1 addition & 0 deletions iam/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const missingEnvVars = [
"SCROLL_BADGE_PROVIDER_INFO",
"SCROLL_BADGE_ATTESTATION_SCHEMA_UID",
"MISHTI_CLIENT_PRIVATE_KEY",
"MISHTI_RELAY_URL",
].filter((env) => !process.env[env]);

if (missingEnvVars.length > 0) {
Expand Down
32 changes: 11 additions & 21 deletions iam/src/utils/oprf.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Need to do this here instead of in the identity package
// so that this isn't loaded in the browser

// ---- Web3 packages
import { keccak256 } from "ethers";

// ---- Types
import { ProofRecord } from "@gitcoin/passport-types";

Expand All @@ -13,7 +10,6 @@ import { objToSortedArray } from "@gitcoin/passport-identity";
// All provider exports from platforms
import { readFileSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";

import { initSync as mishtiInitSync, generate_oprf } from "@holonym-foundation/mishtiwasm";

Expand All @@ -35,21 +31,15 @@ const initializeMishti = async () => {

export const recordToNullifier = async ({ record }: { record: ProofRecord }) => {
const cleartextNullifier = JSON.stringify(objToSortedArray(record));
// TODO
if (process.env.NODE_ENV === "TEST") {
return keccak256(cleartextNullifier);
} else {
await initializeMishti();

const nullifier = await generate_oprf(
process.env.MISHTI_CLIENT_PRIVATE_KEY,
cleartextNullifier,
"OPRFSecp256k1",
"http://127.0.0.1:8081"
);

console.log("nullifier", nullifier);

return nullifier;
}
await initializeMishti();

const nullifier = await generate_oprf(
process.env.MISHTI_CLIENT_PRIVATE_KEY,
cleartextNullifier,
"OPRFSecp256k1",
process.env.MISHTI_RELAY_URL
);

// console.log("nullifier", nullifier);
return nullifier;
};
Loading

0 comments on commit 903faca

Please sign in to comment.