Skip to content

Commit

Permalink
chore: merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
martines3000 committed Apr 22, 2024
2 parents 7814db7 + d5601e5 commit b016cc8
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-icons-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blockchain-lab-um/masca": patch
---

Use external verification for verifyData rpc.
5 changes: 5 additions & 0 deletions .changeset/eleven-eyes-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blockchain-lab-um/dapp": patch
---

Replaced shared presentation verifying lib.
1 change: 1 addition & 0 deletions packages/dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"dependencies": {
"@blockchain-lab-um/did-provider-key": "1.0.8",
"@blockchain-lab-um/extended-verification": "0.1.2",
"@blockchain-lab-um/masca-connector": "1.3.2",
"@blockchain-lab-um/oidc-types": "0.0.8",
"@headlessui/react": "^1.7.18",
Expand Down
37 changes: 29 additions & 8 deletions packages/dapp/src/app/api/share/presentation/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import jwt from 'jsonwebtoken';
import { type NextRequest, NextResponse } from 'next/server';
import {
type VerificationResult,
VerificationService,
} from '@blockchain-lab-um/extended-verification';

import { getAgent } from '../../veramoSetup';
import { supabaseServiceRoleClient } from '@/utils/supabase/supabaseServiceRoleClient';
import type { W3CVerifiablePresentation } from '@veramo/core';
import { isError, type Result } from '@blockchain-lab-um/masca-connector';

const CORS_HEADERS = {
'Access-Control-Allow-Origin': '*',
Expand Down Expand Up @@ -54,20 +59,36 @@ export async function POST(request: NextRequest) {
});
}

const agent = await getAgent();
const { verified } = await agent.verifyPresentation({
presentation,
});
await VerificationService.init();
const verifiedResult: Result<VerificationResult> =
await VerificationService.verify(
presentation as W3CVerifiablePresentation
);

if (!verified) {
return new NextResponse('Presentation not valid', {
status: 400,
if (isError(verifiedResult)) {
return new NextResponse('Failed to verify presentation', {
status: 500,
headers: {
...CORS_HEADERS,
},
});
}

if (!verifiedResult.data.verified) {
return NextResponse.json(
{
message: 'Invalid presentation',
details: verifiedResult.data.details,
},
{
status: 400,
headers: {
...CORS_HEADERS,
},
}
);
}

const supabase = supabaseServiceRoleClient();

const { data, error } = await supabase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const RequirementDisplay = ({
if (!issuer) return acc;

if (
!issuer.includes('did:poylgonid') &&
!issuer.includes('did:polygonid') &&
!issuer.includes('did:iden3')
) {
acc.push(credential);
Expand Down
1 change: 0 additions & 1 deletion packages/dapp/src/components/CampaignsDisplay/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client';

import React from 'react';
import { CampaignDisplay } from './CampaignDisplay';
import { useCampaigns } from '@/hooks';
import { Spinner } from '@nextui-org/react';
Expand Down
15 changes: 12 additions & 3 deletions packages/dapp/src/components/ShareCredentialModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,13 @@ export const ShareCredentialModal = () => {
try {
const result = await shareResponse.json();

if (!result.presentationId)
throw new Error('Failed to share presentation');
if (!result.presentationId) {
throw new Error(
result.message === 'Invalid presentation'
? 'Invalid presentation'
: 'Failed to share presentation'
);
}

setShareLink(
`${window.location.origin}/app/share-presentation/${result.presentationId}`
Expand All @@ -165,7 +170,10 @@ export const ShareCredentialModal = () => {
setTimeout(() => {
useToastStore.setState({
open: true,
title: t('share-presentation-error'),
title:
(e as Error).message === 'Invalid presentation'
? t('share-error-invalid')
: t('share-presentation-error'),
type: 'error',
loading: false,
link: null,
Expand All @@ -183,6 +191,7 @@ export const ShareCredentialModal = () => {
backdrop="blur"
size="4xl"
isOpen={isOpen}
isDismissable={false}
onClose={() => setIsOpen(false)}
hideCloseButton={true}
placement="center"
Expand Down
3 changes: 2 additions & 1 deletion packages/dapp/src/hooks/useCampaignClaims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ export type Campaigns = Campaign[];
export const useCampaignClaims = (token: string | null) => {
return useQuery({
queryKey: ['claims'],
enabled: !!token,
queryFn: async () => {
const res = await fetch('/api/campaigns/claims', {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
...(token && { Authorization: `Bearer ${token}` }),
},
cache: 'no-store',
});
Expand Down
1 change: 1 addition & 0 deletions packages/dapp/src/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@
"placeholder": "Enter a title for the presentation. This can't be changed later.",
"please-sign-in": "Please sign in to share your credentials",
"selected": "Selected Credentials",
"share-error-invalid": "One or more credentials in the presentation are invalid.",
"share-presentation-error": "Failed to share presentation",
"share-presentation-success": "Successfully shared presentation",
"share-link-description": "Share your credential:",
Expand Down
1 change: 1 addition & 0 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"dependencies": {
"@0xpolygonid/js-sdk": "1.10.4",
"@blockchain-lab-um/did-provider-key": "1.0.8",
"@blockchain-lab-um/extended-verification": "0.1.2",
"@blockchain-lab-um/masca-types": "1.3.2",
"@blockchain-lab-um/oidc-client-plugin": "0.3.1",
"@blockchain-lab-um/oidc-types": "0.0.8",
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"./files/circuits/credentialAtomicQuerySigV2/circuit_final.zkey",
"./files/circuits/credentialAtomicQuerySigV2/verification_key.json"
],
"shasum": "RytAvQQBPXQc6700bTYaN/kV4WO0i6s+gkRoJuBKcQQ="
"shasum": "ZUSWLDLE5CPcpB41V3aqEuQY96qKaQJTEBbwB2SNpPk="
},
"initialPermissions": {
"endowment:ethereum-provider": {},
Expand Down
1 change: 0 additions & 1 deletion packages/snap/src/Snap.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ class SnapService {

const res = await VeramoService.verifyData(params);

if (res.error) throw new Error(res.error.message);
return verbose ? res : res.verified;
}

Expand Down
39 changes: 19 additions & 20 deletions packages/snap/src/veramo/Veramo.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
type VerificationResult,
VerificationService,
} from '@blockchain-lab-um/extended-verification';
import {
KeyDIDProvider,
getDidKeyResolver as keyDidResolver,
Expand Down Expand Up @@ -111,6 +115,7 @@ class VeramoService {

static async init(): Promise<void> {
VeramoService.instance = await VeramoService.createAgent();
await VerificationService.init();
}

/**
Expand Down Expand Up @@ -516,28 +521,22 @@ class VeramoService {
static async verifyData(
params: VerifyDataRequestParams
): Promise<IVerifyResult> {
try {
const { credential, presentation } = params;
const { credential, presentation } = params;

if (credential) {
const vcResult = await VeramoService.instance.verifyCredential({
credential,
});
return JSON.parse(JSON.stringify(vcResult)) as IVerifyResult;
}
if (presentation) {
const vpResult = await VeramoService.instance.verifyPresentation({
presentation,
});
return JSON.parse(JSON.stringify(vpResult)) as IVerifyResult;
}
return {
verified: false,
error: new Error('No valid credential or presentation.'),
} as IVerifyResult;
} catch (error: unknown) {
return { verified: false, error: error as Error } as IVerifyResult;
let result: Result<VerificationResult> | undefined = undefined;
if (credential) {
result = await VerificationService.verify(credential);
} else if (presentation) {
result = await VerificationService.verify(presentation);
}

if (!result) throw new Error('No valid credential or presentation.');

if (isError(result)) {
throw new Error(result.error);
}

return result.data as IVerifyResult;
}

static async handleOIDCCredentialOffer(params: {
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b016cc8

Please sign in to comment.