Skip to content

Commit

Permalink
make knownRegistryList an argument of verifyCredential
Browse files Browse the repository at this point in the history
  • Loading branch information
jchartrand committed Jan 10, 2025
1 parent a59c4fa commit 711d7b1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .knownDidRegistries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const knownDidRegistries = [
export const knownDIDRegistries = [
{
name: 'DCC Pilot Registry',
url: 'https://digitalcredentials.github.io/issuer-registry/registry.json'
Expand Down
4 changes: 2 additions & 2 deletions src/Verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const suite = new Ed25519Signature2020();



export async function verifyCredential({credential, reloadIssuerRegistry = true}:{credential: Credential, reloadIssuerRegistry: boolean}): Promise<VerificationResponse> {
export async function verifyCredential({credential, knownDIDRegistries, reloadIssuerRegistry = true}:{credential: Credential, knownDIDRegistries: object, reloadIssuerRegistry: boolean}): Promise<VerificationResponse> {


const fatalErrorMessage = checkForFatalErrors(credential)
Expand Down Expand Up @@ -58,7 +58,7 @@ export async function verifyCredential({credential, reloadIssuerRegistry = true}
delete verificationResponse.statusResult

const { issuer } = credential
await addTrustedIssuersToVerificationResponse({verificationResponse, reloadIssuerRegistry, issuer})
await addTrustedIssuersToVerificationResponse({verificationResponse, knownDIDRegistries,reloadIssuerRegistry, issuer})


return verificationResponse;
Expand Down
13 changes: 7 additions & 6 deletions src/issuerRegistries.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {RegistryClient} from '@digitalcredentials/issuer-registry-client';

Check failure on line 1 in src/issuerRegistries.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

Cannot find module './types/result' or its corresponding type declarations.

Check failure on line 1 in src/issuerRegistries.ts

View workflow job for this annotation

GitHub Actions / test-node (18.x)

Cannot find module './types/result' or its corresponding type declarations.

Check failure on line 1 in src/issuerRegistries.ts

View workflow job for this annotation

GitHub Actions / test-karma (18.x)

Cannot find module './types/result' or its corresponding type declarations.
import {knownDidRegistries} from '../.knownDidRegistries'
import { VerificationResponse } from './types/result';
const registries = new RegistryClient()
const registryNotYetLoaded = true;
Expand All @@ -9,13 +8,14 @@ const registryNotYetLoaded = true;
* @returns A list of the names of the DID registries in which the issuer appears.
*/

export async function getTrustedRegistryListForIssuer({ issuer, reloadIssuerRegistry = false }: {
export async function getTrustedRegistryListForIssuer({ issuer, knownDIDRegistries, reloadIssuerRegistry = false }: {
issuer: string | any,
knownDIDRegistries: object,
reloadIssuerRegistry: boolean | null
}): Promise<string[] | null> {

if (reloadIssuerRegistry ?? registryNotYetLoaded) {
await registries.load({ config: knownDidRegistries })
await registries.load({ config: knownDIDRegistries })
}
const issuerDid = typeof issuer === 'string' ? issuer : issuer.id;
const issuerInfo = registries.didEntry(issuerDid);
Expand All @@ -26,13 +26,14 @@ export async function getTrustedRegistryListForIssuer({ issuer, reloadIssuerRegi
: null;
}

export async function addTrustedIssuersToVerificationResponse( {issuer, reloadIssuerRegistry = false, verificationResponse} :{
export async function addTrustedIssuersToVerificationResponse( {issuer, knownDIDRegistries, reloadIssuerRegistry = false, verificationResponse} :{
issuer: string | any,
reloadIssuerRegistry: boolean | null
reloadIssuerRegistry: boolean | null,
knownDIDRegistries: object,
verificationResponse: VerificationResponse
}) : Promise<void>
{
const foundInRegistries = await getTrustedRegistryListForIssuer( {issuer, reloadIssuerRegistry});
const foundInRegistries = await getTrustedRegistryListForIssuer( {issuer, knownDIDRegistries, reloadIssuerRegistry});

const registryStep = {
"id": "registered_issuer",
Expand Down
15 changes: 8 additions & 7 deletions test/Verify.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
//import { expect } from 'chai'
import { expect } from 'chai'
import { strict as assert } from 'assert';
import { verifyCredential } from '../src/Verify'
import { getVCv2Expired, getVCv1Tampered, getVCv2ValidStatus } from '../src/test-fixtures/vc'
import { knownDIDRegistries } from '../.knownDidRegistries';

describe('Verify', () => {
it('verifies with valid status', async () => {
//const signedVC : any = getSignedVC()
const signedVC2Unrevoked : any = getVCv2ValidStatus()
const result = await verifyCredential({credential: signedVC2Unrevoked, reloadIssuerRegistry: true})
const credential : any = getVCv2ValidStatus()
const result = await verifyCredential({credential, reloadIssuerRegistry: true, knownDIDRegistries})
// console.log("result returned from verifyCredential call:")
//console.log(JSON.stringify(result,null,2))
assert.ok(result.verified);
//expect(result.verified).to.be.true
//assert.ok(result.verified);
expect(result.verified).to.be.true
})

it('returns fatal error when tampered', async () => {
const tamperedVC1 : any = getVCv1Tampered()
const result = await verifyCredential({credential: tamperedVC1, reloadIssuerRegistry: true})
const result = await verifyCredential({credential: tamperedVC1, reloadIssuerRegistry: true, knownDIDRegistries})
// console.log("result returned from verifyCredential call:")
// console.log(JSON.stringify(result,null,2))
assert.ok(result.verified === false);
Expand All @@ -25,7 +26,7 @@ describe('Verify', () => {

it('returns unverified when expired', async () => {
const expiredVC2 : any = getVCv2Expired()
const result = await verifyCredential({credential: expiredVC2, reloadIssuerRegistry: true})
const result = await verifyCredential({credential: expiredVC2, reloadIssuerRegistry: true, knownDIDRegistries})
//console.log("result returned from verifyCredential call:")
// console.log(JSON.stringify(result,null,2))
assert.ok(result.verified === false);
Expand Down

0 comments on commit 711d7b1

Please sign in to comment.