Skip to content

Commit

Permalink
Minimal code for verification
Browse files Browse the repository at this point in the history
  • Loading branch information
Wes Biggs committed Aug 30, 2024
1 parent af7a90c commit 6ac29fd
Showing 1 changed file with 10 additions and 45 deletions.
55 changes: 10 additions & 45 deletions verify.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,43 @@
import * as Ed25519Multikey from "@digitalbazaar/ed25519-multikey";
import { cryptosuite } from "@digitalbazaar/eddsa-rdfc-2022-cryptosuite";
import { DataIntegrityProof } from "@digitalbazaar/data-integrity";
import * as vc from '@digitalbazaar/vc';
import jsig from "jsonld-signatures";
const { extendContextLoader } = jsig;
import jsonld from "jsonld";
import dataIntegrityContext from "@digitalbazaar/data-integrity-context";
import * as credentialsContext from "@digitalbazaar/credentials-context";
import emailCredential from "./docs/email.json" assert { type: "json" };
import { CachedResolver } from "@digitalbazaar/did-io";
import * as didWeb from "@digitalbazaar/did-method-web";

const nodeDocumentLoader = jsonld.documentLoaders.node();
// The credential we're verifying
import emailCredential from "./docs/email.json" assert { type: "json" };

const suite = new DataIntegrityProof({ signer: null, cryptosuite });
const suite = new DataIntegrityProof({ cryptosuite });

const loaderCache = {};
function addToCache(options) {
loaderCache[options.documentUrl] = { ...options };
}

addToCache({
document: dataIntegrityContext.CONTEXT,
documentUrl: dataIntegrityContext.CONTEXT_URL,
});

["v1", "v2", "undefined-terms-v2"].forEach((shortName) => {
["v2", "undefined-terms-v2"].forEach((shortName) => {
const contextMetadata = credentialsContext.named.get(shortName);
addToCache({
document: contextMetadata.context,
documentUrl: contextMetadata.id,
});
});

let didResolver = new CachedResolver();
const didResolver = new CachedResolver();
didResolver.use(didWeb.driver());

let documentLoader = extendContextLoader(async (url) => {
async function documentLoader(url) {
if (url.startsWith("did:")) {
const fragmentIndex = url.lastIndexOf("#");
const baseDid =
fragmentIndex === -1 ? url : url.substring(0, fragmentIndex);
const didDocument = await didResolver.get({ did: baseDid });
if (didDocument) {
let document = didDocument;
// We have a DID document, but might only need a key identified by fragment

if (fragmentIndex !== -1) {
document = findAssertionMethod(
didDocument,
url.substring(fragmentIndex + 1),
);
}
return {document};
}
const didDocument = await didResolver.get({ did: url });
return { document: didDocument }
}
return loaderCache[url];
});
}


const output = await vc.verifyCredential({
credential: emailCredential,
suite,
documentLoader,
purpose: {
validate: (proof) => {
return {
valid: proof.proofPurpose === "assertionMethod",
};
},
match: (proof, options /*{ document, documentLoader }*/) => {
return true;
},
}
documentLoader
});

console.log(JSON.stringify(output, null, 2));

0 comments on commit 6ac29fd

Please sign in to comment.