Skip to content

Commit

Permalink
Issuer-Client Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek Singh authored and dmitrizagidulin committed Nov 8, 2024
1 parent f9fb8e2 commit b2a35a2
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 12 deletions.
5 changes: 2 additions & 3 deletions components/ResultLog/ResultLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ export const ResultLog = ({ verificationResult }: ResultLogProps) => {
</span>
<div>
{verified ? positiveMessage : negativeMessage}
{ issuer ?
{ issuer ?
<ul className={styles.issuerList}>
{verificationResult.registryName ?
<li>{verificationResult.registryName}</li>
{verificationResult.registryName ? verificationResult.registryName.map((registry:string) => { return <li key={registry}>{registry}</li>})
: null
}
</ul> :
Expand Down
22 changes: 22 additions & 0 deletions data/knownRegistries.ts
Original file line number Diff line number Diff line change
@@ -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',
},
];
30 changes: 30 additions & 0 deletions lib/registryManager.ts
Original file line number Diff line number Diff line change
@@ -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;
}
33 changes: 26 additions & 7 deletions lib/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 })
Expand All @@ -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 = '';

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion types/credential.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,5 @@ export type VerifyResponse = {
hasStatusError?: any;
verified: boolean;
results: VerifyResult[];
registryName?: string;
registryName?: string[];
}

0 comments on commit b2a35a2

Please sign in to comment.