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 2 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
5 changes: 5 additions & 0 deletions data/issuerDid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export const issuerDidRegistry: RegistryRaw<IssuerDidEntry> = {
name:'College Unbound',
location:'Providence, RI, USA',
url:'https://collegeunbound.edu',
},
'did:key:z6MkgPBJwKZD8FeFYpps9opan1VdVAeo8EvzJc15BofGujkV':{
lautom36 marked this conversation as resolved.
Show resolved Hide resolved
name: 'Digital Credentials Consortium Test Issuer',
location: 'Cambridge, MA, USA',
url: 'https://dcconsortium.org',
}
},
};
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
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
60 changes: 56 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,57 @@ 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 !== '') {
lautom36 marked this conversation as resolved.
Show resolved Hide resolved
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',
stack: 'temp'
lautom36 marked this conversation as resolved.
Show resolved Hide resolved
},
code: 'temp',
url: 'temp',
},
message: message,
name: 'Error',
stack: 'temp',
},
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
Loading