Skip to content

Commit

Permalink
refactor gs verifier
Browse files Browse the repository at this point in the history
Signed-off-by: F-Node-Karlsruhe <christian.fries@eecc.de>
  • Loading branch information
F-Node-Karlsruhe committed Jul 23, 2024
1 parent df97ff2 commit 94b29b7
Show file tree
Hide file tree
Showing 5 changed files with 301 additions and 142 deletions.
114 changes: 114 additions & 0 deletions api/__tests__/gs1.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import request from "supertest";

import server from "../src/index";

afterAll((done) => {
server.close();
done();
});

const licenceKeyCredential: any = {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://ref.gs1.org/gs1/vc/license-context",
"https://w3id.org/security/suites/ed25519-2020/v1",
{
name: "https://schema.org/name",
description: "https://schema.org/description",
image: "https://schema.org/image",
},
"https://w3id.org/vc-revocation-list-2020/v1",
],
id: "https://id.gs1.org/vc/license/gs1_prefix/08",
type: ["VerifiableCredential", "GS1PrefixLicenseCredential"],
issuer: "did:web:id.gs1.org",
name: "GS1 Prefix License",
description:
"FOR DEMONSTRATION PURPOSES ONLY: NOT TO BE USED FOR PRODUCTION GRADE SYSTEMS! A company prefix that complies with GS1 Standards (a “GS1 Company Prefix”) is a unique identification number that is assigned to just your company by GS1 US. It’s the foundation of GS1 Standards and can be found in all of the GS1 Identification Numbers.",
issuanceDate: "2023-05-19T13:39:41.368Z",
credentialSubject: {
id: "did:web:cbpvsvip-vc.gs1us.org",
organization: {
"gs1:partyGLN": "0614141000005",
"gs1:organizationName": "GS1 US",
},
licenseValue: "08",
alternativeLicenseValue: "8",
},
proof: {
type: "Ed25519Signature2020",
created: "2023-05-19T13:39:41Z",
verificationMethod:
"did:web:id.gs1.org#z6MkkzYByKSsaWusRbYNZGAMvdd5utsPqsGKvrc7T9jyvUrN",
proofPurpose: "assertionMethod",
proofValue:
"z56N5j6WZRwAng8f12RNNPStBBmGLaozHkdPtDmMLwZmqo1EXW3juFZYpeyU7QRh6NRGxJtxMJvAXPq4PveR2bR7m",
},
};

const companyPrefixCredential: any = {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://ref.gs1.org/gs1/vc/license-context",
"https://w3id.org/security/suites/ed25519-2020/v1",
{
name: "https://schema.org/name",
description: "https://schema.org/description",
image: "https://schema.org/image",
},
"https://w3id.org/vc-revocation-list-2020/v1",
],
issuer: "did:web:cbpvsvip-vc.gs1us.org",
name: "GS1 Company Prefix License",
description:
"THIS GS1 DIGITAL LICENSE CREDENTIAL IS FOR TESTING PURPOSES ONLY. A GS1 Company Prefix License is issued by a GS1 Member Organization or GS1 Global Office and allocated to a user company or to itself for the purpose of generating tier 1 GS1 identification keys.",
issuanceDate: "2021-05-11T10:50:36.701Z",
id: "http://did-vc.gs1us.org/vc/license/08600057694",
type: ["VerifiableCredential", "GS1CompanyPrefixLicenseCredential"],
credentialSubject: {
id: "did:key:z6Mkfb3kW3kBP4UGqaBEQoCLBUJjdzuuuPsmdJ2LcPMvUreS/1",
organization: {
"gs1:partyGLN": "0860005769407",
"gs1:organizationName": "Healthy Tots",
},
extendsCredential: "https://id.gs1.org/vc/license/gs1_prefix/08",
licenseValue: "08600057694",
alternativeLicenseValue: "8600057694",
},
credentialStatus: {
id: "https://cbpvsvip-vc.dev.gs1us.org/status/2c0a1f02-d545-481b-902a-1e919cd706e2/1193",
type: "RevocationList2020Status",
revocationListIndex: 1193,
revocationListCredential:
"https://cbpvsvip-vc.dev.gs1us.org/status/2c0a1f02-d545-481b-902a-1e919cd706e2/",
},
proof: {
type: "Ed25519Signature2020",
created: "2023-05-22T16:55:59Z",
verificationMethod:
"did:web:cbpvsvip-vc.gs1us.org#z6Mkig1nTEAxna86Pjb71SZdbX3jEdKRqG1krDdKDatiHVxt",
proofPurpose: "assertionMethod",
proofValue:
"zfWTiZ9CRLJBUUHRFa82adMZFwiAvYCsTwRjX7JaTpUnVuCTj44f9ErSGbTBWezv89MyKQ3jTLFgWUbUvB6nuJCN",
},
};

describe("Verifier API Test for GS1 Credentials", () => {
test("Verify GS1 licence prefix credentials", async () => {
const res = await request(server)
.post("/api/verifier/gs1")
.send(licenceKeyCredential);
expect(res.statusCode).toEqual(200);
expect(res.body).toHaveProperty("verified");
expect(res.body.verified).toBe(true);
});

test("Verify GS1 company licence prefix credentials", async () => {
const res = await request(server)
.post("/api/verifier/gs1")
.send(companyPrefixCredential);
expect(res.statusCode).toEqual(200);
expect(res.body).toHaveProperty("verified");
expect(res.body.verified).toBe(true);
});
});
20 changes: 9 additions & 11 deletions api/src/routers/verify/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { Router } from 'express';
import { VerifyRoutes } from '../../routes/index.js';

import { Router } from "express";
import { VerifyRoutes } from "../../routes/index.js";

const verifyRoutes = new VerifyRoutes();
const { fetchAndVerify, verify, verifySubjectsVCs } = verifyRoutes
const { fetchAndVerify, verify, verifySubjectsVCs, verifyGS1 } = verifyRoutes;

export const verifyRouter = Router();


/**
* API model of a credentialSubject
* @summary The minimal form of a credential subject
* @typedef {object} CredentialSubject
* @property {string} id.required - The identifier of the identity which the credential refers to
*/


/**
* API model of a signed credential
* @summary Refers to W3C Credential
Expand All @@ -24,8 +21,8 @@ export const verifyRouter = Router();
* @property {string} id - The id of the the credential as an IRI
* @property {array<string>} type.required - The types of the credential
* @property {string} issuer.required - The DID of the issuer of the credential
* @property {string} issuanceDate.required - The issuance date of the credential in ISO format 2022-09-26T09:01:07.437Z
* @property {string} expirationDate - The expiration date of the credential in ISO format 2022-09-26T09:01:07.437Z
* @property {string} issuanceDate.required - The issuance date of the credential in ISO format 2022-09-26T09:01:07.437Z
* @property {string} expirationDate - The expiration date of the credential in ISO format 2022-09-26T09:01:07.437Z
* @property {CredentialSubject} credentialSubject.required - The actual claim of the credential
* @property {object} proof.required - The cryptographic signature of the issuer over the credential
*/
Expand Down Expand Up @@ -104,7 +101,7 @@ export const verifyRouter = Router();
]
}
*/
verifyRouter.get('/vc/:vcid', fetchAndVerify);
verifyRouter.get("/vc/:vcid", fetchAndVerify);

/**
* POST /api/verifier
Expand Down Expand Up @@ -464,7 +461,7 @@ verifyRouter.get('/vc/:vcid', fetchAndVerify);
}
]
*/
verifyRouter.post('/', verify);
verifyRouter.post("/", verify);

/**
* GET /api/verifier/id/{subjectId}
Expand Down Expand Up @@ -512,5 +509,6 @@ verifyRouter.post('/', verify);
}
]
*/
verifyRouter.get('/id/:subjectId', verifySubjectsVCs);
verifyRouter.get("/id/:subjectId", verifySubjectsVCs);

verifyRouter.post("/gs1", verifyGS1);
Loading

0 comments on commit 94b29b7

Please sign in to comment.