diff --git a/components/ResultLog/ResultLog.tsx b/components/ResultLog/ResultLog.tsx index b32acf5..edd5d2e 100644 --- a/components/ResultLog/ResultLog.tsx +++ b/components/ResultLog/ResultLog.tsx @@ -22,10 +22,9 @@ export const ResultLog = ({ verificationResult }: ResultLogProps) => {
{verified ? positiveMessage : negativeMessage} - { issuer ? + { issuer ? : diff --git a/data/knownRegistries.ts b/data/knownRegistries.ts new file mode 100644 index 0000000..de85a9f --- /dev/null +++ b/data/knownRegistries.ts @@ -0,0 +1,22 @@ +export const KnownDidRegistries = [ + { + name: 'DCC Pilot Registry', + url: 'https://digitalcredentials.github.io/issuer-registry/registry.json', + }, + { + name: 'DCC Sandbox Registry', + url: 'https://digitalcredentials.github.io/sandbox-registry/registry.json', + }, + { + name: 'DCC Community Registry', + url: 'https://digitalcredentials.github.io/community-registry/registry.json', + }, + { + name: 'DCC Registry', + url: 'https://digitalcredentials.github.io/dcc-registry/registry.json', + }, + { + name: 'My Skills Registry', + url: 'https://sandbox-issuer.myskillspocket.com/registry.json', + }, +]; diff --git a/lib/registryManager.ts b/lib/registryManager.ts new file mode 100644 index 0000000..7f285e8 --- /dev/null +++ b/lib/registryManager.ts @@ -0,0 +1,30 @@ +import { RegistryClient } from '@digitalcredentials/issuer-registry-client'; +import { KnownDidRegistries } from 'data/knownRegistries'; + +/** + * Loads remote Known Issuer / Known Verifier DID registries from config. + */ +async function loadKnownDidRegistries({ + client, +}: { + client: RegistryClient; +}) { + await client.load({ config: KnownDidRegistries }); + // Now available for usage through the cachedRegistryClient. +} + +// Cache for storing the data +let didRegistryClient: RegistryClient = new RegistryClient(); + +// Function to fetch and cache the data +async function fetchRegistries() { + try { + await loadKnownDidRegistries({ client: didRegistryClient }); + } catch (error) { + console.error('Error fetching data:', error); + } +} +export async function getCachedRegistryClient(){ + await fetchRegistries(); + return didRegistryClient; +} diff --git a/lib/validate.ts b/lib/validate.ts index c85e3d6..7a8fc4e 100644 --- a/lib/validate.ts +++ b/lib/validate.ts @@ -5,7 +5,8 @@ import { VerifiablePresentation, PresentationError } from 'types/presentation.d' import { VerifiableCredential, CredentialError, CredentialErrorTypes } from 'types/credential.d'; import { securityLoader } from '@digitalcredentials/security-document-loader'; import { extractCredentialsFrom } from './verifiableObject'; -import { registryCollections } from '@digitalcredentials/issuer-registry-client'; +import { RegistryClient } from '@digitalcredentials/issuer-registry-client'; +import { getCachedRegistryClient } from './registryManager'; import { getCredentialStatusChecker } from './credentialStatus'; const documentLoader = securityLoader({ fetchRemoteContexts: true }).build() @@ -111,12 +112,13 @@ export async function verifyCredential(credential: VerifiableCredential): Promis } } - const issuerDid = typeof issuer === 'string' ? issuer : issuer.id; - await registryCollections.issuerDid.fetchRegistries(); - const isInRegistry = await registryCollections.issuerDid.isInRegistryCollection(issuerDid); - if (isInRegistry) { - const registryInfo = await registryCollections.issuerDid.registriesFor(issuerDid) - result.registryName = registryInfo[0].name; + const registries = await getCachedRegistryClient(); + const registryNames = issuerInRegistries({ + issuer, + registries, + }); + if (registryNames) { + result.registryName = registryNames; } else { result.verified = false; (result.results[0].log ??= []).push({ id: 'issuer_did_resolves', valid: false }) @@ -131,6 +133,23 @@ export async function verifyCredential(credential: VerifiableCredential): Promis } } +function issuerInRegistries({ + issuer, + registries, +}: { + issuer: string | any; + registries: RegistryClient; +}): string[] | null { + const issuerDid = typeof issuer === 'string' ? issuer : issuer.id; + const issuerInfo = registries.didEntry(issuerDid); + + // See if the issuer DID appears in any of the known registries + // If yes, assemble a list of registries it appears in + return issuerInfo?.inRegistries + ? Array.from(issuerInfo.inRegistries).map((r) => r.name) + : null; +} + function checkMalformed(credential: VerifiableCredential) { let message = ''; diff --git a/package.json b/package.json index 02c3c16..35d7302 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "dependencies": { "@digitalcredentials/ed25519-signature-2020": "^6.0.0", - "@digitalcredentials/issuer-registry-client": "^1.0.0", + "@digitalcredentials/issuer-registry-client": "^3.0.0", "@digitalcredentials/security-document-loader": "^6.0.0", "@digitalcredentials/vc": "^9.0.1", "@digitalcredentials/vc-bitstring-status-list": "^1.0.0", diff --git a/types/credential.d.ts b/types/credential.d.ts index 1a201dd..c666671 100644 --- a/types/credential.d.ts +++ b/types/credential.d.ts @@ -168,5 +168,5 @@ export type VerifyResponse = { hasStatusError?: any; verified: boolean; results: VerifyResult[]; - registryName?: string; + registryName?: string[]; }