Skip to content

Commit

Permalink
working tests with hacky fix, need to remove
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianHymer committed Jan 4, 2025
1 parent a8ddd72 commit fe527f7
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 290 deletions.
7 changes: 6 additions & 1 deletion iam/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,12 +831,17 @@ describe("POST /verify", function () {
jest.spyOn(identityMock, "verifyCredential").mockResolvedValue(true);

// create a req against the express app
await request(app)
const response = await request(app)
.post("/api/v0.0.0/verify")
.send({ challenge, payload })
.set("Accept", "application/json")
.expect(200)
.expect("Content-Type", /json/);

response.body.forEach((item: any) => {
expect(item).toHaveProperty("record");
expect(item.record).toMatchObject({ type: "Simple" });
});
});
it("should not issue credential for additional signer when invalid address is provided", async () => {
(identityMock.verifyCredential as jest.Mock).mockResolvedValueOnce(true);
Expand Down
2 changes: 2 additions & 0 deletions iam/jest.setup.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ process.env.SCROLL_BADGE_PROVIDER_INFO =
'{"DeveloperList#PassportCommiterLevel1#6a51c84c":{"contractAddress":"0x71A848A38fFCcA5c7A431F2BB411Ab632Fa0c456","level":1}}';
process.env.SCROLL_BADGE_ATTESTATION_SCHEMA_UID =
"0xa35b5470ebb301aa5d309a8ee6ea258cad680ea112c86e456d5f2254448afc74";
process.env.MISHTI_CLIENT_PRIVATE_KEY =
"0x04d16281ff3bf268b29cdd684183f72542757d24ae9fdfb863e7c755e599163a";
70 changes: 18 additions & 52 deletions iam/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,58 +50,24 @@ import { filterRevokedCredentials } from "./utils/revocations.js";

// ---- Config - check for all required env variables
// We want to prevent the app from starting with default values or if it is misconfigured
const configErrors = [];

if (!process.env.IAM_JWK) {
configErrors.push("IAM_JWK is required");
}

if (!process.env.ATTESTATION_SIGNER_PRIVATE_KEY) {
configErrors.push("ATTESTATION_SIGNER_PRIVATE_KEY is required");
}

if (!process.env.TESTNET_ATTESTATION_SIGNER_PRIVATE_KEY) {
configErrors.push("TESTNET_ATTESTATION_SIGNER_PRIVATE_KEY is required");
}

if (!process.env.ALLO_SCORER_ID) {
configErrors.push("ALLO_SCORER_ID is required");
}

if (!process.env.SCORER_ENDPOINT) {
configErrors.push("SCORER_ENDPOINT is required");
}

if (!process.env.SCORER_API_KEY) {
configErrors.push("SCORER_API_KEY is required");
}

if (!process.env.EAS_GITCOIN_STAMP_SCHEMA) {
configErrors.push("EAS_GITCOIN_STAMP_SCHEMA is required");
}

if (!process.env.MORALIS_API_KEY) {
configErrors.push("MORALIS_API_KEY is required");
}

if (!process.env.IAM_JWK_EIP712) {
configErrors.push("IAM_JWK_EIP712 is required");
}

if (!process.env.EAS_FEE_USD) {
configErrors.push("EAS_FEE_USD is required");
}

if (!process.env.SCROLL_BADGE_PROVIDER_INFO) {
configErrors.push("SCROLL_BADGE_PROVIDER_INFO is required");
}

if (!process.env.SCROLL_BADGE_ATTESTATION_SCHEMA_UID) {
configErrors.push("SCROLL_BADGE_ATTESTATION_SCHEMA_UID is required");
}

if (configErrors.length > 0) {
configErrors.forEach((error) => console.error(error)); // eslint-disable-line no-console
const missingEnvVars = [
"IAM_JWK",
"ATTESTATION_SIGNER_PRIVATE_KEY",
"TESTNET_ATTESTATION_SIGNER_PRIVATE_KEY",
"ALLO_SCORER_ID",
"SCORER_ENDPOINT",
"SCORER_API_KEY",
"EAS_GITCOIN_STAMP_SCHEMA",
"MORALIS_API_KEY",
"IAM_JWK_EIP712",
"EAS_FEE_USD",
"SCROLL_BADGE_PROVIDER_INFO",
"SCROLL_BADGE_ATTESTATION_SCHEMA_UID",
"MISHTI_CLIENT_PRIVATE_KEY",
].filter((env) => !process.env[env]);

if (missingEnvVars.length > 0) {
missingEnvVars.forEach((envVar) => console.error(`${envVar} is required`));

Check warning on line 70 in iam/src/index.ts

View workflow job for this annotation

GitHub Actions / Build and Test

Unexpected console statement

Check warning on line 70 in iam/src/index.ts

View workflow job for this annotation

GitHub Actions / Check Provider Bitmaps

Unexpected console statement
throw new Error("Missing required configuration");
}

Expand Down
47 changes: 5 additions & 42 deletions iam/src/utils/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,13 @@ import { getIssuerKey } from "../issuers.js";

// ---- Generate & Verify methods
import * as DIDKit from "@spruceid/didkit-wasm-node";
import { issueHashedCredential, objToSortedArray, verifyCredential } from "@gitcoin/passport-identity";
import { issueHashedCredential, verifyCredential } from "@gitcoin/passport-identity";

// All provider exports from platforms
import { providers, platforms } from "@gitcoin/passport-platforms";
import { ApiError } from "./helpers.js";
import { checkCredentialBans } from "./bans.js";
import { readFileSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";

// Need to do this here instead of in the identity package
// so that this isn't loaded in the browser
import { initSync as mishtiInitSync, generate_oprf } from "@holonym-foundation/mishtiwasm";

let mishtiInitialized = false;
const initializeMishti = () => {
if (mishtiInitialized) return;

const __dirname = dirname(fileURLToPath(import.meta.url));
const modulePath = join(
__dirname,
"../../../../../",
"node_modules/@holonym-foundation/mishtiwasm/pkg/esm/mishtiwasm_bg.wasm"
);

// console.log("Loading wasm module", modulePath);
const wasmModuleBuffer = readFileSync(modulePath);

mishtiInitSync({ module: wasmModuleBuffer });

mishtiInitialized = true;
};
import { recordToNullifier } from "./oprf.js";

const providerTypePlatformMap = Object.entries(platforms).reduce(
(acc, [platformName, { providers }]) => {
Expand Down Expand Up @@ -118,23 +93,11 @@ const issueCredentials = async (
record,
verifyResult.expiresInSeconds,
payload.signatureType,
async () => {
initializeMishti();

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

console.log("nullifier", nullifier);

return nullifier;
}
() => recordToNullifier({ record })
));
}
} catch {
} catch (e) {
console.error(e);
error = "Unable to produce a verifiable credential";
code = 500;
}
Expand Down
55 changes: 55 additions & 0 deletions iam/src/utils/oprf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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";

// ---- Generate & Verify methods
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";

let mishtiInitialized = false;
const initializeMishti = async () => {
if (mishtiInitialized) return;

await Promise.resolve();
const monorepoBaseDir = dirname(process.cwd());
const wasmPath = join(monorepoBaseDir, "node_modules/@holonym-foundation/mishtiwasm/pkg/esm", "mishtiwasm_bg.wasm");

// console.log("Loading wasm module", wasmPath);
const wasmModuleBuffer = readFileSync(wasmPath);

mishtiInitSync({ module: wasmModuleBuffer });

mishtiInitialized = true;
};

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;
}
};
3 changes: 3 additions & 0 deletions identity/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ module.exports = {
"^.+\\.tsx?$": "ts-jest",
},
modulePathIgnorePatterns: ["<rootDir>/dist/"],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
};
Loading

0 comments on commit fe527f7

Please sign in to comment.