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 acca116 + d5601e5 commit 54745dc
Show file tree
Hide file tree
Showing 27 changed files with 149 additions and 69 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.
8 changes: 6 additions & 2 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@
"@blockchain-lab-um/masca": "1.2.2",
"@blockchain-lab-um/masca-types": "1.3.2"
},
"changesets": []
}
"changesets": [
"five-poets-yell",
"rich-pandas-add",
"young-forks-jog"
]
}
5 changes: 5 additions & 0 deletions .changeset/young-forks-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blockchain-lab-um/masca": patch
---

Adjust nbf and iat for idtoken signing
8 changes: 8 additions & 0 deletions packages/dapp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @blockchain-lab-um/dapp

## 1.3.2-beta.0

### Patch Changes

- [#609](https://github.com/blockchain-lab-um/masca/pull/609) [`5cb712a`](https://github.com/blockchain-lab-um/masca/commit/5cb712ad40156207f41c3f2fd863f0ad0472791a) Thanks [@pseudobun](https://github.com/pseudobun)! - Adds reclaim option for campaigns.

- [#614](https://github.com/blockchain-lab-um/masca/pull/614) [`fc1f796`](https://github.com/blockchain-lab-um/masca/commit/fc1f796ad66b5dbceccd0d96f64e2d98cfca71f0) Thanks [@tadejpodrekar](https://github.com/tadejpodrekar)! - Adds campaign issue checks.

## 1.3.1

### Patch Changes
Expand Down
1 change: 1 addition & 0 deletions packages/dapp/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const nextConfig = {
},

webpack: (config) => {
config.externals.push('pino-pretty');
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
Expand Down
3 changes: 2 additions & 1 deletion packages/dapp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blockchain-lab-um/dapp",
"version": "1.3.1",
"version": "1.3.2-beta.0",
"private": true,
"license": "(Apache-2.0 AND MIT)",
"type": "commonjs",
Expand All @@ -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
15 changes: 4 additions & 11 deletions packages/dapp/src/app/api/og/route.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { formatDid } from '@/utils/format';
import { ImageResponse } from '@vercel/og';
import type { NextRequest } from 'next/server';

Expand Down Expand Up @@ -96,7 +97,7 @@ export async function GET(req: NextRequest) {
fontWeight: 'normal',
}}
>
{credentialIssuer}
{formatDid(credentialIssuer)}
</div>
<div tw="text-md text-orange-100 mt-4">ACHIEVED</div>
<div
Expand Down Expand Up @@ -218,11 +219,7 @@ export async function GET(req: NextRequest) {
fontWeight: 'normal',
}}
>
{credentialIssuer.substring(0, 10)}...
{credentialIssuer.substring(
holder.length,
holder.length - 10
)}
{formatDid(credentialIssuer)}
</div>
<div tw="text-md text-orange-100 mt-4">ISSUED TO</div>
<div
Expand All @@ -232,11 +229,7 @@ export async function GET(req: NextRequest) {
fontWeight: 'normal',
}}
>
{credentialSubject.substring(0, 10)}...
{credentialSubject.substring(
holder.length,
holder.length - 10
)}
{formatDid(credentialSubject)}
</div>
<div tw="text-md text-orange-100 mt-4">ISSUED ON</div>
<div
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
2 changes: 1 addition & 1 deletion packages/dapp/src/components/AddressPopover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const AddressPopover = ({ did, disconnect }: AddressPopoverProps) => {
<div className="dark:text-navy-blue-100 text-sm text-gray-700">
DID
</div>
<div className="mt-2 flex items-center justify-center">
<div className="mt-2 flex items-center justify-left">
{did ? (
<a
href={`https://dev.uniresolver.io/#${did}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@ export const RequirementDisplay = ({
const queryCredentialsResult = await api.queryCredentials();

if (isError(queryCredentialsResult)) {
useToastStore.setState({
open: true,
title: t('requirements-not-met'),
type: 'error',
loading: false,
link: null,
});
setStartedVerifying(false);
return;
}

// Create a presentation from all the user's credentials except the polygonid ones
const createPresentationResult = await api.createPresentation({
vcs: queryCredentialsResult.data.reduce((acc, queryResult) => {
Expand All @@ -106,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
2 changes: 1 addition & 1 deletion packages/dapp/src/components/ConnectedProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const ConnectedProvider = ({ children }: ConnectedProviderProps) => {
return isConnected ? (
<>{children}</>
) : (
<div className="flex flex-col items-center justify-center px-6 sm:px-12 dark:bg-navy-blue-800 dark:text-navy-blue-400 py-12 rounded-3xl bg-white shadow-lg">
<div className="flex flex-col items-center h-full justify-center px-6 sm:px-12 dark:bg-navy-blue-800 dark:text-navy-blue-400 py-12 rounded-3xl bg-white shadow-lg">
<div className="flex flex-col">
<div className="flex w-full flex-col items-center justify-center">
<h3 className="text-h4 sm:text-h3 dark:text-navy-blue-50 text-center text-gray-900">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export const CredentialTypes = () => {
);
}}
>
clear ({credentialTypes.filter((type) => type.selected).length})
{t('clear')} (
{credentialTypes.filter((type) => type.selected).length})
</button>
) : (
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ function FilterPopover({ vcs }: FilterPopoverProps) {
return;
}
vc.data.type.forEach((type: string) => {
if (type !== 'VerifiableCredential') allCredentialTypes.push(type);
// if (type !== 'VerifiableCredential')
allCredentialTypes.push(type);
});
});
const availableCredentialTypes = [...new Set(allCredentialTypes)];
Expand Down
15 changes: 12 additions & 3 deletions packages/dapp/src/components/CreateCredentialDisplay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import ToggleSwitch from '@/components/Switch';
import { useMascaStore, useToastStore } from '@/stores';
import DropdownMultiselect from '../DropdownMultiselect';
import VCModal from '../VCModal';
import { capitalizeString } from '@/utils/format';

const proofFormats: Record<string, SupportedProofFormats> = {
JWT: 'jwt',
Expand Down Expand Up @@ -139,7 +140,9 @@ const CreateCredentialDisplay = () => {
proofFormat: proofFormats[format],
options: {
save,
store: selectedItems, // TODO: fix this doesn't create new credential
store: selectedItems.map((store) =>
store.toLowerCase()
) as AvailableCredentialStores[],
},
});

Expand Down Expand Up @@ -259,8 +262,14 @@ const CreateCredentialDisplay = () => {
</span>
<div className="flex flex-1">
<DropdownMultiselect
items={availableStores}
selectedItems={selectedItems}
items={availableStores.map((store) =>
capitalizeString(store)
)}
selectedItems={
selectedItems.map((store) =>
capitalizeString(store)
) as AvailableCredentialStores[]
}
setSelectedItems={setSelectedItems}
placeholder={t('save.select-storage-placeholder')}
name="storage"
Expand Down
6 changes: 2 additions & 4 deletions packages/dapp/src/components/DashboardDisplay/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,13 @@ export const filterColumnsType = (
const availableTypes = types
.filter((type) => type.selected)
.map((type) => type.type);

const filteredList = credentialList.filter((credential) => {
const { type } = credential.data;
if (!type) return false;

for (const typ of availableTypes) {
if (
(typeof type === 'string' && type === typ) ||
(Array.isArray(type) && type.indexOf(typ) >= 0)
) {
if ((typeof type === 'string' && type === typ) || Array.isArray(type)) {
return true;
}
}
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
6 changes: 4 additions & 2 deletions packages/dapp/src/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@
"rewards": "Rewards"
},
"RequirementDisplay": {
"verify": "Verify"
"verify": "Verify",
"requirements-not-met": "You do not meet the requirements"
},
"RewardDisplay": {},
"CredentialCard": {
Expand Down Expand Up @@ -365,7 +366,7 @@
"title": "Delete Shared Presentation"
},
"FilterPopover": {
"clear": "clear",
"clear": "Clear",
"datastore": "Data Store",
"ecosystem": "Ecosystem",
"filter": "Filter",
Expand Down Expand Up @@ -603,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
6 changes: 6 additions & 0 deletions packages/snap/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.2.3-beta.0

### Patch Changes

- [#625](https://github.com/blockchain-lab-um/masca/pull/625) [`f29e494`](https://github.com/blockchain-lab-um/masca/commit/f29e494a8cb6a9de30682a59feb6adee7e15b1e7) Thanks [@martines3000](https://github.com/martines3000)! - Adjust nbf and iat for idtoken signing

## 1.2.2

### Patch Changes
Expand Down
3 changes: 2 additions & 1 deletion packages/snap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blockchain-lab-um/masca",
"version": "1.2.2",
"version": "1.2.3-beta.0",
"description": "Snap for managing VCs and VPs in MetaMask",
"keywords": [
"MetaMask",
Expand Down Expand Up @@ -56,6 +56,7 @@
"dependencies": {
"@0xpolygonid/js-sdk": "1.9.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
Loading

0 comments on commit 54745dc

Please sign in to comment.