Skip to content

Wip/verify unime core compat #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: wip/verify
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/components/Credentials/CredentialInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const CredentialInfo = ({ credential, mainClassName = "text-sm lg:text-base w-fu
const { isOnline } = useContext(StatusContext);
const [parsedCredential, setParsedCredential] = useState(null);
const [credentialFormat, setCredentialFormat] = useState('');
const [issuerName, setIssuerName] = useState('');
const [credentialSubjectRows, setCredentialSubjectRows] = useState([]);
const container = useContext(ContainerContext);
const { api } = useContext(SessionContext);
Expand All @@ -84,6 +85,7 @@ const CredentialInfo = ({ credential, mainClassName = "text-sm lg:text-base w-fu
}

setParsedCredential(c.beautifiedForm);
setIssuerName(c.beautifiedForm.issuer?.name || '');

let iss = c.beautifiedForm.iss;

Expand Down Expand Up @@ -212,7 +214,7 @@ const CredentialInfo = ({ credential, mainClassName = "text-sm lg:text-base w-fu
{!credentialSubjectRows.some(row => row.name === 'institution') && renderRow('institution', 'Institution', parsedCredential?.vc?.credentialSubject?.institution, screenType)}
{!credentialSubjectRows.some(row => row.name === 'valid_from') && renderRow('valid_from', 'Valid from', parsedCredential?.vc?.credentialSubject?.valid_from, screenType)}
{!credentialSubjectRows.some(row => row.name === 'valid_until') && renderRow('valid_until', 'Valid until', parsedCredential?.vc?.credentialSubject?.valid_until, screenType)}
{!credentialSubjectRows.some(row => row.name === 'issuer') && renderRow('issuer', 'Issuer', parsedCredential?.vc?.credentialSubject?.issuer, screenType)}
{!credentialSubjectRows.some(row => row.name === 'issuer') && renderRow('issuer', 'Issuer', parsedCredential?.vc?.credentialSubject?.issuer || issuerName, screenType)}
</>
)
}
Expand Down
1 change: 1 addition & 0 deletions src/context/ContainerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ export const ContainerContextProvider = ({ children }) => {

if (isOpenBadgeCredential) return beautifiedForm.credentialSubject.achievement.name;
if (t.includes('SupportCredential') || t.includes('ExamEnrollmentCredential')) return beautifiedForm.credentialSubject.title;
if (t.includes('AcademicEnrollmentCredential')) return beautifiedForm.credentialSubject.name;
if (storedCredentialConfigurationId === 'EduID') return 'eduID'

Comment on lines 270 to 274
Copy link
Preview

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This growing chain of if statements for credential types may become hard to extend. Consider refactoring into a mapping or switch statement to improve readability and make future additions simpler.

Suggested change
if (isOpenBadgeCredential) return beautifiedForm.credentialSubject.achievement.name;
if (t.includes('SupportCredential') || t.includes('ExamEnrollmentCredential')) return beautifiedForm.credentialSubject.title;
if (t.includes('AcademicEnrollmentCredential')) return beautifiedForm.credentialSubject.name;
if (storedCredentialConfigurationId === 'EduID') return 'eduID'
const credentialTypeMapping: Record<string, () => string> = {
'OpenBadgeCredential': () => beautifiedForm.credentialSubject.achievement.name,
'SupportCredential': () => beautifiedForm.credentialSubject.title,
'ExamEnrollmentCredential': () => beautifiedForm.credentialSubject.title,
'AcademicEnrollmentCredential': () => beautifiedForm.credentialSubject.name,
};
if (storedCredentialConfigurationId === 'EduID') return 'eduID';
for (const [key, getName] of Object.entries(credentialTypeMapping)) {
if (t.includes(key)) {
return getName();
}
}

Copilot uses AI. Check for mistakes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a temporary solution pending a discussion pertaining to credential card title display logic. There is no need to optimize it right now.

return result.beautifiedForm.name || credentialConfiguration?.display?.[0]?.name || 'Credential';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/schemas/OpenidCredentialIssuerMetadataSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const OpenidCredentialIssuerMetadataSchema = z.object({
authorization_servers: z.array(z.string()).optional(),
display: z.array(z.object({
name: z.string(),
locale: z.string(),
locale: z.string().optional()
})).optional(),
batch_credential_issuance: z.object({
batch_size: z.number(),
Expand Down
15 changes: 10 additions & 5 deletions src/lib/services/credential-offer.service.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { CredentialOfferSchema } from '../schemas/CredentialOfferSchema';
import { CredentialOfferSchema } from "../schemas/CredentialOfferSchema";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just keep single quotes unless double quotes is the preferred formatting. In the latter case, please also update the formatting in other touched files.


const PARAM_CREDENTIAL_OFFER = 'credential_offer';
const PARAM_CREDENTIAL_OFFER_URI = 'credential_offer_uri';
const PARAM_CREDENTIAL_OFFER = "credential_offer";
const PARAM_CREDENTIAL_OFFER_URI = "credential_offer_uri";

// @todo: return type
export const credentialOfferFromUrl = async (url: string) => {
const parsedUrl = new URL(url);
if (parsedUrl.searchParams.get(PARAM_CREDENTIAL_OFFER)) {
return CredentialOfferSchema.parse(JSON.parse(parsedUrl.searchParams.get(PARAM_CREDENTIAL_OFFER)));
return CredentialOfferSchema.parse(
JSON.parse(parsedUrl.searchParams.get(PARAM_CREDENTIAL_OFFER)),
);
}
try {
const response = await fetch(parsedUrl.searchParams.get(PARAM_CREDENTIAL_OFFER_URI), {});
const offerURI =
parsedUrl.searchParams.get(PARAM_CREDENTIAL_OFFER_URI) || "";
Copy link
Preview

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using || '' for credential_offer_uri means offerURI can be empty and lead to fetch(''). Add a guard to return an error or throw if the parameter is missing before attempting to fetch.

Suggested change
parsedUrl.searchParams.get(PARAM_CREDENTIAL_OFFER_URI) || "";
parsedUrl.searchParams.get(PARAM_CREDENTIAL_OFFER_URI);
if (!offerURI) {
throw new Error(`Missing or empty parameter: ${PARAM_CREDENTIAL_OFFER_URI}`);
}

Copilot uses AI. Check for mistakes.

const decodedOfferURI = decodeURIComponent(offerURI);
const response = await fetch(decodedOfferURI, {});
Copy link
Preview

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After fetching the credential offer, check response.ok and handle non-2xx statuses (e.g., throw or return a structured error) before calling response.json() to improve error clarity.

Suggested change
const response = await fetch(decodedOfferURI, {});
const response = await fetch(decodedOfferURI, {});
if (!response.ok) {
throw new Error(`Failed to fetch credential offer: ${response.status} ${response.statusText}`);
}

Copilot uses AI. Check for mistakes.

return await response.json();
} catch (err) {
console.error(err);
Expand Down