From 6ac29fdae57f46024c1daf660e4583c6a8d37e24 Mon Sep 17 00:00:00 2001 From: Wes Biggs Date: Fri, 30 Aug 2024 16:20:35 -0500 Subject: [PATCH] Minimal code for verification --- verify.js | 55 ++++++++++--------------------------------------------- 1 file changed, 10 insertions(+), 45 deletions(-) diff --git a/verify.js b/verify.js index 0f322b7..1884855 100644 --- a/verify.js +++ b/verify.js @@ -1,31 +1,20 @@ -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, @@ -33,46 +22,22 @@ addToCache({ }); }); -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));