Skip to content
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
10 changes: 9 additions & 1 deletion app/components/ResultLog/ResultLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export enum LogMessages {
HasExpired = 'has expired',
NoExpirationDate = 'no expiration date set',
HasNotExpired = 'has not expired',
NotYetValid = 'is not yet valid',
GeneralError = 'There was an error verifing this credential.',
UnknownError = 'There was an unknown error verifing this credential.',
WellFormed = 'is in a supported credential format',
Expand Down Expand Up @@ -130,8 +131,9 @@ export const ResultLog = ({ verificationResult }: ResultLogProps) => {
const isMalformedError =
result?.error?.message ===
'Credential could not be checked for verification and may be malformed.';
const isNotYetValidError = result?.error?.message?.includes('will only be valid after');
const { credential } = result;
if (shouldShowKnownError) {
if (shouldShowKnownError && !isNotYetValidError) {
return (
<div>
<p data-testid={TestId.GeneralErrorMsg} className={styles.error}>{LogMessages.GeneralError}</p>
Expand All @@ -142,6 +144,12 @@ export const ResultLog = ({ verificationResult }: ResultLogProps) => {
)}
</div>
)
} else if (isNotYetValidError) {
return (
<div>
<p data-testid={TestId.GeneralErrorMsg} className={styles.error}>{error?.message}</p>
</div>
)
} else if (hasSigningError) {
return (
<div>
Expand Down
37 changes: 37 additions & 0 deletions app/lib/validate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as verifierCore from '@digitalcredentials/verifier-core';
import type { VerifiablePresentation } from '@/types/presentation.d';
import type { VerifiableCredential, CredentialError } from '@/types/credential.d';
import { getIssuanceDate } from './credentialValidityPeriod';
//import { CredentialErrorTypes } from '@/types/credential.d';
//import { KnownDidRegistries } from './../data/knownRegistries'

Expand All @@ -10,6 +11,7 @@ enum CredentialErrorTypes {
IsNotVerified = 'Credential is not verified.',
CouldNotBeVerified = 'Credential could not be checked for verification and may be malformed.',
DidNotInRegistry = 'Could not find issuer in registry with given DID.',
NotYetValid = 'This credential is not yet valid.',
}


Expand Down Expand Up @@ -59,6 +61,21 @@ export async function verifyCredential(credential: VerifiableCredential): Promis
};
*/

// Check if credential is not yet valid before verification
const issuanceDate = getIssuanceDate(credential);
if (issuanceDate) {
const validFromDate = new Date(issuanceDate);
const now = new Date();
if (validFromDate > now) {
const formattedDate = validFromDate.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
return createNotYetValidResult(credential, `This credential will only be valid after ${formattedDate}.`);
}
}

const response = await fetch("https://digitalcredentials.github.io/dcc-known-registries/known-did-registries.json");
const knownDIDRegistries = await response.json();

Expand Down Expand Up @@ -144,6 +161,26 @@ function createFatalErrorResult(credential: VerifiableCredential, message: strin
return result as VerifyResponse
}

function createNotYetValidResult(credential: VerifiableCredential, message: string): VerifyResponse {
const result = {
verified: false,
results: [
{
verified: false,
credential: credential,
log: [
{ id: 'expiration', valid: false },
{ id: 'valid_signature', valid: true },
{ id: 'issuer_did_resolves', valid: true },
{ id: 'revocation_status', valid: true }
]
}
]
}
addErrorToResult(result, message, false)
return result as VerifyResponse
}

function addErrorToResult(result: any, message: string, isFatal: boolean = true) {
result.results[0].error =
{
Expand Down