Skip to content
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

Tl/crash #91

Closed
wants to merge 5 commits into from
Closed
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
1 change: 0 additions & 1 deletion components/ResultLog/ResultLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export const ResultLog = ({ verificationResult }: ResultLogProps) => {
return acc;
}, {}) ?? {};

console.log(verificationResult.results[0]);
let hasError = false;
let error: CredentialError;
if (verificationResult.results[0].error) {
Expand Down
72 changes: 0 additions & 72 deletions data/issuerDid.ts

This file was deleted.

1 change: 0 additions & 1 deletion lib/decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export async function credentialsFromQrText(text: string): Promise<VerifiableCre
return null;
}

// console.log(vp);
// TODO: We need to separate verificaiton of the presentation from the credentials inside.
// https://www.pivotaltracker.com/story/show/179830339
//const isVerified = await verifyPresentation(vp);
Expand Down
2 changes: 0 additions & 2 deletions lib/registry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { issuerDidRegistry, IssuerDidEntry } from '../data/issuerDid';
import { issuerAuthRegistry, IssuerAuthEntry } from '../data/issuerAuth';

type RegistryMetadata = {
Expand Down Expand Up @@ -35,6 +34,5 @@ class Registry<Entry> implements RegistryRaw<Entry> {
}

export const registries = {
issuerDid: new Registry<IssuerDidEntry>(issuerDidRegistry),
issuerAuth: new Registry<IssuerAuthEntry>(issuerAuthRegistry),
};
1 change: 0 additions & 1 deletion lib/useVerification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const useVerification = (credential?: VerifiableCredential) => {

const verifyCredential = useCallback(async () => {
if (credential === undefined) {
console.log("cred was undefined in verifyCred")
return;
}
setLoading(true);
Expand Down
56 changes: 52 additions & 4 deletions lib/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import vc from '@digitalcredentials/vc';
import { VerifiablePresentation, PresentationError } from 'types/presentation.d';
import { VerifiableCredential, CredentialError, CredentialErrorTypes } from 'types/credential.d';
import { securityLoader } from '@digitalcredentials/security-document-loader';
import { registries } from './registry';
import { extractCredentialsFrom } from './verifiableObject';
import { registryCollections } from '@digitalcredentials/issuer-registry-client';
const documentLoader = securityLoader().build();
const suite = new Ed25519Signature2020();
const presentationPurpose = new purposes.AssertionProofPurpose();
Expand Down Expand Up @@ -53,10 +53,15 @@ export async function verifyPresentation(
export async function verifyCredential(credential: VerifiableCredential): Promise<VerifyResponse> {
const { issuer } = credential;

const {malformed, message} = checkMalformed(credential);
if (malformed) { return createErrorMessage(credential, message); }

const issuerDid = typeof issuer === 'string' ? issuer : issuer.id;

if (!registries.issuerDid.isInRegistry(issuerDid)) {
throw new Error(CredentialErrorTypes.DidNotInRegistry);
const isInRegistry = await registryCollections.issuerDid.isInRegistryCollection(issuerDid);
if (isInRegistry) {
// throw new Error(CredentialErrorTypes.DidNotInRegistry);
return createErrorMessage(credential, CredentialErrorTypes.DidNotInRegistry)
}

try {
Expand All @@ -68,10 +73,53 @@ export async function verifyCredential(credential: VerifiableCredential): Promis
// Only check revocation status if VC has a 'credentialStatus' property
checkStatus: hasRevocation ? checkStatus : undefined
});

return result;
} catch (err) {
console.warn(err);
throw new Error(CredentialErrorTypes.CouldNotBeVerified);
}
}

function checkMalformed(credential: VerifiableCredential) {
let message = '';

// check credential for proof
if (!credential.proof){
message += 'This is not a Verifiable Credential (does not have a digital signature).'
}

if (message) {
return {malformed: true, message: message};
}
return {malformed: false, message: message};

}

function createErrorMessage(credential: VerifiableCredential, message: string) {
return {
verified: false,
results: [
{
verified: false,
credential: credential,
error: {
details: {
cause: {
message: message,
name: 'Error',
},
},
message: message,
name: 'Error',
},
log: [
{ id: 'expiration', valid: false },
{ id: 'valid_signature', valid: false },
{ id: 'issuer_did_resolves', valid: false },
{ id: 'revocation_status', valid: false }
],
}
]
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@digitalcredentials/did-method-key": "^2.0.3",
"@digitalcredentials/ed25519-signature-2020": "^3.0.2",
"@digitalcredentials/ed25519-verification-key-2020": "^3.2.2",
"@digitalcredentials/issuer-registry-client": "^1.0.0",
"@digitalcredentials/security-document-loader": "^3.1.0",
"@digitalcredentials/vc": "^6.0.0",
"@digitalcredentials/vc-status-list": "^5.0.2",
Expand Down
1 change: 0 additions & 1 deletion pages/credentials/[publicCredentialId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const CredentialPage: NextPage = () => {
const extract = (data: {vp: VerifiableObject}) => {
if (data !== undefined) {
const vp = data.vp;
console.log(data);
const creds = extractCredentialsFrom(vp);
setCredential(creds![0])
}
Expand Down
4 changes: 0 additions & 4 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ const Home: NextPage = () => {
history.pushState(null, '', '#verify/results');
// get first cred. this will eventually need to be changed
if(vc.length > 1) { setWasMulti(true); }
// console.log(vc);
// console.log(vc.length);
// console.log(wasMulti)
setCredential(vc[0]);
return result;
}
Expand All @@ -103,7 +100,6 @@ const Home: NextPage = () => {
try {
let response = await fetch(url);
let responseJson = await response.json(); //.json()
// console.log(responseJson);
return JSON.stringify(responseJson);
} catch (error) {
console.error(error);
Expand Down
8 changes: 4 additions & 4 deletions types/credential.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ export type CredentialError = {
details: ErrorDetails,
message: string,
name: string,
stack: string,
stack?: string,
}

export type ErrorDetails = {
cause: ErrorCause;
code: string;
url: string;
code?: string;
url?: string;
}

export type ErrorCause = {
message: string;
name: string;
stack: string
stack?: string
}

export type VerifyResultLog = {
Expand Down
Loading