Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianHymer committed Jan 2, 2025
1 parent 1ea12b8 commit a8ddd72
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
52 changes: 33 additions & 19 deletions iam/src/utils/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,45 @@ import {
ProviderContext,
VerifiedPayload,
VerifiableCredential,
ProofRecord,
} from "@gitcoin/passport-types";

import { getIssuerKey } from "../issuers.js";

// ---- Generate & Verify methods
import * as DIDKit from "@spruceid/didkit-wasm-node";
import { issueHashedCredential, verifyCredential } from "@gitcoin/passport-identity";
import { issueHashedCredential, objToSortedArray, 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;
};

const providerTypePlatformMap = Object.entries(platforms).reduce(
(acc, [platformName, { providers }]) => {
Expand Down Expand Up @@ -67,7 +93,8 @@ const issueCredentials = async (
results.map(async ({ verifyResult, code: verifyCode, error: verifyError, type }) => {
let code = verifyCode;
let error = verifyError;
let record, credential;
let record: ProofRecord | undefined;
let credential;

try {
// check if the request is valid against the selected Identity Provider
Expand All @@ -92,24 +119,11 @@ const issueCredentials = async (
verifyResult.expiresInSeconds,
payload.signatureType,
async () => {
// Need to do this here instead of in the identity package
// so that this isn't loaded in the browser
const mishtiWasm = await import("@holonym-foundation/mishtiwasm");

const wasmModuleBuffer = readFileSync(
"/Users/lucian/projects/passport/node_modules/@holonym-foundation/mishtiwasm/pkg/esm/mishtiwasm_bg.wasm"
);

console.log("Loaded wasm module");

mishtiWasm.initSync({ module: wasmModuleBuffer });

console.log("Initialized wasm module");
initializeMishti();

const nullifier = await mishtiWasm.generate_oprf(
process.env.TMP_PRIVATE_KEY,
// JSON.stringify(objToSortedArray(record)),
"usr:1234",
const nullifier = await generate_oprf(
process.env.MISHTI_CLIENT_PRIVATE_KEY,
JSON.stringify(objToSortedArray(record)),
"OPRFSecp256k1",
"http://127.0.0.1:8081"
);
Expand Down
12 changes: 10 additions & 2 deletions identity/src/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,15 @@ export const issueChallengeCredential = async (
} as IssuedCredential;
};

const getNullifier = ({ key, record, oprf }: { key: string; record: ProofRecord; oprf?: () => Promise<string> }) => {
const getNullifier = async ({
key,
record,
oprf,
}: {
key: string;
record: ProofRecord;
oprf?: () => Promise<string>;
}) => {
if (oprf) {
return oprf();
} else {
Expand All @@ -226,7 +234,7 @@ export const issueHashedCredential = async (
signatureType?: string,
oprf?: () => Promise<string>
): Promise<IssuedCredential> => {
const hash = getNullifier({ key, record, oprf });
const hash = await getNullifier({ key, record, oprf });

let credential: VerifiableCredential;
if (signatureType === "EIP712") {
Expand Down

0 comments on commit a8ddd72

Please sign in to comment.