diff --git a/CHANGELOG.md b/CHANGELOG.md index f39020e..abd17bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ WIP 2.0.0 (2024-07-23) - add gs1 verification endpoint +- use gs1 endpoint on gs1 credential 1.7.8 (2024-06-13) --- diff --git a/api/src/services/verifier/gs1.ts b/api/src/services/verifier/gs1.ts index a96f999..d1fb16f 100644 --- a/api/src/services/verifier/gs1.ts +++ b/api/src/services/verifier/gs1.ts @@ -14,23 +14,7 @@ import { import { documentLoader } from "../documentLoader/index.js"; import { Verifier } from "./index.js"; -export const gs1CredentialTypes = [ - "OrganizationDataCredential", - "GS1PrefixLicenseCredential", - "GS1CompanyPrefixLicenseCredential", - "KeyCredential", - "ProductDataCredential", -]; -export const gs1CredentialContext = - "https://ref.gs1.org/gs1/vc/license-context"; - -export function isGs1Credential(credential: VerifiableCredential): boolean { - return ( - credential["@context"].includes(gs1CredentialContext) && - credential.type.some((type: string) => gs1CredentialTypes.includes(type)) - ); -} export function getVerifierFunction(challenge?: string, domain?: string) { return async function (verifiable: any) { return await Verifier.verify(verifiable, challenge, domain); diff --git a/api/src/services/verifier/index.ts b/api/src/services/verifier/index.ts index 80105ef..023fe2e 100644 --- a/api/src/services/verifier/index.ts +++ b/api/src/services/verifier/index.ts @@ -16,11 +16,6 @@ import { DataIntegrityProof } from "@digitalbazaar/data-integrity"; import jsigs from "jsonld-signatures"; import { documentLoader } from "../documentLoader/index.js"; -import { - isGs1Credential, - checkGS1Credential, - verifyGS1Credentials, -} from "./gs1.js"; const { createVerifyCryptosuite } = ecdsaSd2023Cryptosuite; const { diff --git a/frontend/src/api.js b/frontend/src/api.js index e067c0b..d9d5bd5 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -1,6 +1,6 @@ import axios from 'axios' const axiosInstance = axios.create({ - baseURL: process.env.VERIFIER_API || 'https://ssi.eecc.de/api/verifier', + baseURL: process.env.VERIFIER_API || 'http://localhost:3000/api/verifier', timeout: 5000, headers: { 'Accept': 'application/ld+json,application/json,*/*' diff --git a/frontend/src/components/Credential.vue b/frontend/src/components/Credential.vue index a63ff07..2a266c1 100644 --- a/frontend/src/components/Credential.vue +++ b/frontend/src/components/Credential.vue @@ -6,7 +6,8 @@
-
{{ getCredentialType(credential) }}
+
{{ getCredentialType(credential) }}
@@ -184,7 +185,7 @@ import { Tooltip } from 'bootstrap'; import pdfMake from "pdfmake/build/pdfmake"; import pdfFonts from "pdfmake/build/vfs_fonts"; import { credentialPDF } from '../pdf.js'; -import { getPlainCredential, getCredentialType } from '../utils.js'; +import { getPlainCredential, getCredentialType, isGs1Credential } from '../utils.js'; import * as JsHashes from 'jshashes'; pdfMake.vfs = pdfFonts.pdfMake.vfs; @@ -207,7 +208,8 @@ export default { return { toast: useToast(), getPlainCredential: getPlainCredential, - getCredentialType: getCredentialType + getCredentialType: getCredentialType, + isGs1Credential: isGs1Credential } }, mounted() { diff --git a/frontend/src/utils.js b/frontend/src/utils.js index f47bb08..6e7bc94 100644 --- a/frontend/src/utils.js +++ b/frontend/src/utils.js @@ -1,95 +1,119 @@ -import jsonld from 'jsonld'; -import { demoAuthPresentation } from './store/demoAuth'; +import jsonld from 'jsonld' +import { demoAuthPresentation } from './store/demoAuth' export const VerifiableType = { - CREDENTIAL: 'VerifiableCredential', - PRESENTATION: 'VerifiablePresentation' -}; + CREDENTIAL: 'VerifiableCredential', + PRESENTATION: 'VerifiablePresentation', +} const IPFS_GATEWAYS = ['ipfs.io', 'ipfs.ssi.eecc.de'] export function isURL(url) { - if (typeof url != 'string') return false; - return url.startsWith('https://'); + if (typeof url != 'string') return false + return url.startsWith('https://') } export function getCredentialValue(value) { - return typeof value === 'object' ? value.value || value['@value'] || JSON.stringify(value, null, 2) : value; + return typeof value === 'object' + ? value.value || value['@value'] || JSON.stringify(value, null, 2) + : value } export function getPlainCredential(credential) { - var clean_credential = { ...credential }; - delete clean_credential.verified; - delete clean_credential.revoked; - delete clean_credential.suspended; - delete clean_credential.status; - delete clean_credential.presentation; - delete clean_credential.context; - return clean_credential; + var clean_credential = { ...credential } + delete clean_credential.verified + delete clean_credential.revoked + delete clean_credential.suspended + delete clean_credential.status + delete clean_credential.presentation + delete clean_credential.context + return clean_credential } export function getVerifiableType(verifiable) { - if (verifiable.type.includes(VerifiableType.PRESENTATION)) return VerifiableType.PRESENTATION; - return VerifiableType.CREDENTIAL; + if (verifiable.type.includes(VerifiableType.PRESENTATION)) + return VerifiableType.PRESENTATION + return VerifiableType.CREDENTIAL } export function getCredentialType(credential) { - return credential.type.length > 1 ? credential.type.filter((c) => c != 'VerifiableCredential')[0] : credential.type[0]; + return credential.type.length > 1 + ? credential.type.filter((c) => c != 'VerifiableCredential')[0] + : credential.type[0] } export function getHolder(presentation) { - if (presentation.holder) return presentation.holder; - const proof = Array.isArray(presentation.proof) ? presentation.proof[0] : presentation.proof - return proof.verificationMethod.split('#')[0]; + if (presentation.holder) return presentation.holder + const proof = Array.isArray(presentation.proof) + ? presentation.proof[0] + : presentation.proof + return proof.verificationMethod.split('#')[0] } export async function fetchIPFS(IPFSUrl) { - - var document; - - await Promise.any(IPFS_GATEWAYS.map(async (gateway) => { - - return await fetch(`https://${gateway}/ipfs/${IPFSUrl.split('ipfs://')[1]}`); - - })) - .then((result) => { - - document = result; - - }) - .catch((error) => { - console.error(error) - }) - - if (!document) throw Error('Fetching from IPFS failed'); - - return document; - + var document + + await Promise.any( + IPFS_GATEWAYS.map(async (gateway) => { + return await fetch( + `https://${gateway}/ipfs/${IPFSUrl.split('ipfs://')[1]}`, + ) + }), + ) + .then((result) => { + document = result + }) + .catch((error) => { + console.error(error) + }) + + if (!document) throw Error('Fetching from IPFS failed') + + return document } - const documentLoader = async (url) => { - let document; - if (url.startsWith('ipfs://')) { - - document = await fetchIPFS(url) - - } else document = await fetch(url); - - return { - contextUrl: null, - document: await document.json(), - documentUrl: url - }; -}; - + let document + if (url.startsWith('ipfs://')) { + document = await fetchIPFS(url) + } else document = await fetch(url) + + return { + contextUrl: null, + document: await document.json(), + documentUrl: url, + } +} export async function getContext(credential) { - const resolved = await jsonld.processContext(await jsonld.processContext(null, null), credential, { documentLoader }); - return resolved.mappings; + const resolved = await jsonld.processContext( + await jsonld.processContext(null, null), + credential, + { documentLoader }, + ) + return resolved.mappings } export function isDemoAuth(auth) { - return auth != undefined && JSON.stringify(auth) == JSON.stringify(demoAuthPresentation); + return ( + auth != undefined && + JSON.stringify(auth) == JSON.stringify(demoAuthPresentation) + ) } +const gs1CredentialTypes = [ + 'OrganizationDataCredential', + 'GS1PrefixLicenseCredential', + 'GS1CompanyPrefixLicenseCredential', + 'KeyCredential', + 'ProductDataCredential', +] + +const gs1CredentialContext = 'https://ref.gs1.org/gs1/vc/license-context' + +export function isGs1Credential(credential) { + return ( + credential['@context'].includes(gs1CredentialContext) && + credential.type.some((type) => gs1CredentialTypes.includes(type)) + ) +} diff --git a/frontend/src/views/Verify.vue b/frontend/src/views/Verify.vue index c5dc78d..1327d04 100644 --- a/frontend/src/views/Verify.vue +++ b/frontend/src/views/Verify.vue @@ -35,7 +35,7 @@