Skip to content

Commit

Permalink
successful init
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianHymer committed Jan 2, 2025
1 parent 2a487be commit cd971a5
Showing 4 changed files with 34 additions and 39 deletions.
2 changes: 1 addition & 1 deletion iam/package.json
Original file line number Diff line number Diff line change
@@ -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",
1 change: 1 addition & 0 deletions iam/src/index.ts
Original file line number Diff line number Diff line change
@@ -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);

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

GitHub Actions / Build and Test

Unexpected console statement

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

GitHub Actions / Check Provider Bitmaps

Unexpected console statement
if (error instanceof ApiError) {
return void errorRes(res, error.message, error.code);
}
62 changes: 28 additions & 34 deletions iam/src/utils/credentials.ts
Original file line number Diff line number Diff line change
@@ -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 }]) => {

Check failure on line 25 in iam/src/utils/credentials.ts

GitHub Actions / Build and Test

Insert `⏎··`

Check failure on line 25 in iam/src/utils/credentials.ts

GitHub Actions / Check Provider Bitmaps

Insert `⏎··`
providers.forEach(({ type }) => {

Check failure on line 26 in iam/src/utils/credentials.ts

GitHub Actions / Build and Test

Insert `··`

Check failure on line 26 in iam/src/utils/credentials.ts

GitHub Actions / Check Provider Bitmaps

Insert `··`
acc[type] = platformName;

Check failure on line 27 in iam/src/utils/credentials.ts

GitHub Actions / Build and Test

Replace `····` with `······`

Check failure on line 27 in iam/src/utils/credentials.ts

GitHub Actions / Check Provider Bitmaps

Replace `····` with `······`
});

Check failure on line 28 in iam/src/utils/credentials.ts

GitHub Actions / Build and Test

Insert `··`

Check failure on line 28 in iam/src/utils/credentials.ts

GitHub Actions / Check Provider Bitmaps

Insert `··`

return acc;
},
{} as { [k: string]: string }
);
return acc;

Check failure on line 30 in iam/src/utils/credentials.ts

GitHub Actions / Build and Test

Insert `··`

Check failure on line 30 in iam/src/utils/credentials.ts

GitHub Actions / Check Provider Bitmaps

Insert `··`
}, {} as { [k: string]: string });

Check failure on line 31 in iam/src/utils/credentials.ts

GitHub Actions / Build and Test

Replace `},·{}·as·{·[k:·string]:·string·}` with `··},⏎··{}·as·{·[k:·string]:·string·}⏎`

Check failure on line 31 in iam/src/utils/credentials.ts

GitHub Actions / Check Provider Bitmaps

Replace `},·{}·as·{·[k:·string]:·string·}` with `··},⏎··{}·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) => {

Check failure on line 35 in iam/src/utils/credentials.ts

GitHub Actions / Build and Test

Insert `⏎······`

Check failure on line 35 in iam/src/utils/credentials.ts

GitHub Actions / Check Provider Bitmaps

Insert `⏎······`
const platform = providerTypePlatformMap[type] || "generic";

Check failure on line 36 in iam/src/utils/credentials.ts

GitHub Actions / Build and Test

Insert `··`

Check failure on line 36 in iam/src/utils/credentials.ts

GitHub Actions / Check Provider Bitmaps

Insert `··`

if (!groupedProviders[platform]) groupedProviders[platform] = [];
groupedProviders[platform].push(type);
if (!groupedProviders[platform]) groupedProviders[platform] = [];

Check failure on line 38 in iam/src/utils/credentials.ts

GitHub Actions / Build and Test

Insert `··`

Check failure on line 38 in iam/src/utils/credentials.ts

GitHub Actions / Check Provider Bitmaps

Insert `··`
groupedProviders[platform].push(type);

Check failure on line 39 in iam/src/utils/credentials.ts

GitHub Actions / Build and Test

Replace `······` with `········`

Check failure on line 39 in iam/src/utils/credentials.ts

GitHub Actions / Check Provider Bitmaps

Replace `······` with `········`

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<CredentialResponseBody[]> => {
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;
}
));
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit cd971a5

Please sign in to comment.