From cd971a5a513342ce8a6437c34ceee1266a9cb574 Mon Sep 17 00:00:00 2001 From: Lucian Hymer Date: Thu, 2 Jan 2025 08:53:29 -0800 Subject: [PATCH] successful init --- iam/package.json | 2 +- iam/src/index.ts | 1 + iam/src/utils/credentials.ts | 62 ++++++++++++++++-------------------- yarn.lock | 8 ++--- 4 files changed, 34 insertions(+), 39 deletions(-) diff --git a/iam/package.json b/iam/package.json index 44dae83246..68a79088b3 100644 --- a/iam/package.json +++ b/iam/package.json @@ -31,7 +31,7 @@ "@gitcoin/passport-identity": "^1.0.0", "@gitcoin/passport-platforms": "^1.0.0", "@gitcoin/passport-types": "^1.0.0", - "@holonym-foundation/mishtiwasm": "^0.3.0-robustnet", + "@holonym-foundation/mishtiwasm": "0.2.2", "@ipld/dag-cbor": "^7.0.3", "@spruceid/didkit-wasm-node": "^0.2.1", "axios": "^1.7.9", diff --git a/iam/src/index.ts b/iam/src/index.ts index 958e37207f..31140b2d59 100644 --- a/iam/src/index.ts +++ b/iam/src/index.ts @@ -254,6 +254,7 @@ app.post("/api/v0.0.0/verify", (req: Request, res: Response): void => { return void errorRes(res, "Unable to verify payload", 401); }) .catch((error) => { + console.log("ERROR", error); if (error instanceof ApiError) { return void errorRes(res, error.message, error.code); } diff --git a/iam/src/utils/credentials.ts b/iam/src/utils/credentials.ts index 2124c127f6..f57b6c94a5 100644 --- a/iam/src/utils/credentials.ts +++ b/iam/src/utils/credentials.ts @@ -12,11 +12,6 @@ import { import { getIssuerKey } from "../issuers.js"; -// Need to do this here instead of in the identity package -// so that this isn't loaded in the browser -import initMishtiWasm, { generate_oprf } from "@holonym-foundation/mishtiwasm"; -let mishtiWasmInitialized = false; - // ---- Generate & Verify methods import * as DIDKit from "@spruceid/didkit-wasm-node"; import { issueHashedCredential, verifyCredential } from "@gitcoin/passport-identity"; @@ -25,31 +20,26 @@ import { issueHashedCredential, verifyCredential } from "@gitcoin/passport-ident import { providers, platforms } from "@gitcoin/passport-platforms"; import { ApiError } from "./helpers.js"; import { checkCredentialBans } from "./bans.js"; +import { readFileSync } from "fs"; -const providerTypePlatformMap = Object.entries(platforms).reduce( - (acc, [platformName, { providers }]) => { - providers.forEach(({ type }) => { - acc[type] = platformName; - }); +const providerTypePlatformMap = Object.entries(platforms).reduce((acc, [platformName, { providers }]) => { + providers.forEach(({ type }) => { + acc[type] = platformName; + }); - return acc; - }, - {} as { [k: string]: string } -); + return acc; +}, {} as { [k: string]: string }); function groupProviderTypesByPlatform(types: string[]): string[][] { return Object.values( - types.reduce( - (groupedProviders, type) => { - const platform = providerTypePlatformMap[type] || "generic"; + types.reduce((groupedProviders, type) => { + const platform = providerTypePlatformMap[type] || "generic"; - if (!groupedProviders[platform]) groupedProviders[platform] = []; - groupedProviders[platform].push(type); + if (!groupedProviders[platform]) groupedProviders[platform] = []; + groupedProviders[platform].push(type); - return groupedProviders; - }, - {} as { [k: keyof typeof platforms]: string[] } - ) + return groupedProviders; + }, {} as { [k: keyof typeof platforms]: string[] }) ); } @@ -59,10 +49,6 @@ const issueCredentials = async ( address: string, payload: RequestPayload ): Promise => { - if (!mishtiWasmInitialized) { - await initMishtiWasm(); - mishtiWasmInitialized = true; - } // if the payload includes an additional signer, use that to issue credential. if (payload.signer) { // We can assume that the signer is a valid address because the challenge was verified within the /verify endpoint @@ -100,17 +86,25 @@ const issueCredentials = async ( verifyResult.expiresInSeconds, payload.signatureType, async () => { - const nullifier = await generate_oprf( - process.env.TMP_PRIVATE_KEY, - // JSON.stringify(objToSortedArray(record)), - "usr:1234", - "OPRFSecp256k1", - "http://192.168.0.33:8081" + // 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(wasmModuleBuffer); + + console.log("Initialized wasm module"); + + const nullifier = await mishtiWasm.make_jwt_request("abc", "def"); + console.log("nullifier", nullifier); - return nullifier; + return nullifier as string; } )); } diff --git a/yarn.lock b/yarn.lock index 6da6d9860f..1585e93db5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6046,10 +6046,10 @@ resolved "https://registry.yarnpkg.com/@heroicons/react/-/react-2.0.17.tgz#42a8086bc434ceefc03592f20c4e81b11e915cf8" integrity sha512-90GMZktkA53YbNzHp6asVEDevUQCMtxWH+2UK2S8OpnLEu7qckTJPhNxNQG52xIR1WFTwFqtH6bt7a60ZNcLLA== -"@holonym-foundation/mishtiwasm@^0.3.0-robustnet": - version "0.3.0-robustnet" - resolved "https://registry.yarnpkg.com/@holonym-foundation/mishtiwasm/-/mishtiwasm-0.3.0-robustnet.tgz#621cec90bae996aeb0eb396f77d256b3abe81668" - integrity sha512-0wCFQdeDx1XDsKcc7/jnnADY60kBf1HhbswS5rZ46kD9ZbPzm1LDYAmC5k7FLmgaCmyJdeGewLiSX1xSzFOFZQ== +"@holonym-foundation/mishtiwasm@0.2.2": + version "0.2.2" + resolved "https://registry.yarnpkg.com/@holonym-foundation/mishtiwasm/-/mishtiwasm-0.2.2.tgz#1910c16c5f7cc606d26dbb91be69ddc5d420abd1" + integrity sha512-mVE5qGrOfqhruwm9sehrEjMLXrcsp0HbTIlkttvGOP6HNajMsyF53jRd+E77OgQuLARguhwgJJmvp4L5GVdcEA== "@humanwhocodes/config-array@^0.11.13": version "0.11.14"