Skip to content

Commit

Permalink
Add getExpirationStatus function
Browse files Browse the repository at this point in the history
  • Loading branch information
yue jun law committed Sep 11, 2023
1 parent 0e268d4 commit 3a6bd41
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.0.8 11 Sep 2023:

- Add getExpirationStatus function

## 0.0.7 22 Aug 2023:

- Fix test stub data
Expand Down
12 changes: 12 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const MyInfoVcVerifier = require("../index.js");

//stub data
const signedVC = require("./stub/signedVC.json");
const expiredVC = require("./stub/expiredVC.json");
const notExpiredVC = require("./stub/notExpiredVC.json");
const invalidVC = require("./stub/invalidVC.json");
const revokedVC = require("./stub/revokedVC.json");
const verifyresult = require("./stub/result.json");
Expand Down Expand Up @@ -94,4 +96,14 @@ describe("Test VC verifier", () => {
const result = await MyInfoVcVerifier.verify(signedSDVC);
expect(result.verified).toStrictEqual(true);
}, 5000);

it("should validate expirationStatus as expired", async () => {
const result = MyInfoVcVerifier.getExpirationStatus(expiredVC);
expect(result).toStrictEqual(true);
});

it("should validate expirationStatus as not expired", async () => {
const result = MyInfoVcVerifier.getExpirationStatus(notExpiredVC);
expect(result).toStrictEqual(false);
});
});
34 changes: 34 additions & 0 deletions __tests__/stub/expiredVC.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"@context": [
"https://w3id.org/security/bbs/v1",
"https://www.w3.org/2018/credentials/v1",
"https://stg.issuer.myinfo.gov.sg/myinfo/schema/age/v1",
"https://w3id.org/vc/status-list/2021/v1"
],
"id": "https://stg.issuer.myinfo.gov.sg/myinfo202304-01/credentials/78f3b60c-7411-41eb-9345-24167d9a93c4",
"type": ["VerifiableCredential", "AgeCredential"],
"issuer": "did:web:stg.issuer.myinfo.gov.sg:myinfo202304-01",
"credentialSubject": {
"AtLeast18YearsOld": true,
"AtLeast21YearsOld": true,
"type": ["Age"],
"id": "did:key:z6Mkk7yqnGF3YwTrLpqrW6PGsKci7dNqh1CjnvMbzrMerSeL"
},
"name": "Age",
"description": "Age Over Indicators",
"expirationDate": "1970-01-21T06:54:46Z",
"credentialStatus": {
"id": "https://stg.issuer.myinfo.gov.sg/myinfo202304-01/status/1#10271",
"type": "StatusList2021Entry",
"statusListIndex": "10271",
"statusListCredential": "https://stg.issuer.myinfo.gov.sg/myinfo202304-01/status/1"
},
"issuanceDate": "2023-08-21T07:49:35Z",
"proof": {
"type": "BbsBlsSignature2020",
"created": "2023-08-21T07:49:35Z",
"proofPurpose": "assertionMethod",
"proofValue": "tm69iIYQ5R6uRALgYcDcmMiG6rSwkvYUnAf0aHk90w31YksGOJHkHMGZcRUp3oSaYUHlKfzccE4m7waZyoLEkBLFiK2g54Q2i+CdtYBgDdkUDsoULSBMcH1MwGHwdjfXpldFNFrHFx/IAvLVniyeMQ==",
"verificationMethod": "did:web:stg.issuer.myinfo.gov.sg:myinfo202304-01#21402a47-6416-4b95-b180-dff0e1f44d67"
}
}
60 changes: 60 additions & 0 deletions __tests__/stub/notExpiredVC.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"credentialSubject": {
"birthcountry": "SINGAPORE",
"passtype": "",
"race": "CHINESE",
"passexpirydate": "",
"regadd": {
"country": "SINGAPORE",
"unit": "340",
"street": "WOODLANDS RING ROAD",
"block": "635",
"id": "urn:bnid:_:c14n0",
"postal": "730635",
"floor": "17",
"building": ""
},
"sex": "FEMALE",
"employmentsector": "INFORMATION TECHNOLOGY",
"employment": "GOVTECH PTE LTD",
"residentialstatus": "CITIZEN",
"type": "Personal",
"hanyupinyinname": "",
"hanyupinyinaliasname": "",
"marriedname": "",
"aliasname": "CLARISSA DEWANARA VANASAMIN",
"passstatus": "",
"uinfin": "S9590367C",
"nationality": "SINGAPORE CITIZEN",
"dob": "1950-04-19",
"name": "Lim Mark",
"id": "did:key:z6MkkuJtybrsUYQvS3UsF3a2amMzs9MraCGdn9etp4afaDN8"
},
"issuanceDate": "2023-09-08T04:28:57Z",
"name": "Personal",
"description": "Basic Details of Personal Profile",
"id": "https://stg.issuer.myinfo.gov.sg/myinfo202304-01/credentials/3dbfdc79-d4c5-4601-b46d-b851583c9452",
"proof": {
"proofPurpose": "assertionMethod",
"proofValue": "ACoD//////+4U1nfSoiA1Yg+i6YeTPYCYjTDHe4a7gGvTg6naxQiaLoSen3TCzFOM44FWHxJSYG4i7EfLsKyL0mrmbYTQiIomvA0Lc2z3S12c5J7N+IWmdCONfFAmwgT5nU2CUquZYmGNU/77Ptw5qNwqhxImHJLp2iuqLXTxRuHo6HddgIDTNyNCqAVHQzy2Zp/+tklhW8AAAB0gPiVrF7UKsJXkKDu6xJZZK2jWSjBtnUxnip1lXTFlOJpXgfVaIGxXgAhV052/GuEAAAAAjPHaHNm4IVYFfR1+/lEu2tRohAbE9E5TzDyNo4jDBrnINn28EKTsoy8Zqt6q3KjyjJC99WP4vtSypUEFvewo0iANZ9VVX3AmKOchx3Lakfkm6FLy1i+HP4BePJL7glRfkk9+3RMsC5IJZMmxWEghsgAAAACE8uk6ZnI2edZzoLVyUEt6RT+qxL4KoYrD/xYTXDYkr0MZY3Sb5GwtxHgkGkgxA32hMPzFFkACOj697lpVQrtag==",
"type": "BbsBlsSignatureProof2020",
"verificationMethod": "did:web:stg.issuer.myinfo.gov.sg:myinfo202304-01#21402a47-6416-4b95-b180-dff0e1f44d67",
"nonce": "4clK7QibKG8Qsg0TvN1xLeXWXqBkTCe4d0M2EKyKMxwl4kDynGq00m7hMoO5OevuSHk=",
"created": "2023-09-08T04:28:57Z"
},
"type": ["PersonalCredential", "VerifiableCredential"],
"@context": [
"https://w3id.org/security/bbs/v1",
"https://www.w3.org/2018/credentials/v1",
"https://stg.issuer.myinfo.gov.sg/myinfo/schema/personal/v1",
"https://w3id.org/vc/status-list/2021/v1"
],
"issuer": "did:web:stg.issuer.myinfo.gov.sg:myinfo202304-01",
"credentialStatus": {
"statusListIndex": "10908",
"id": "https://stg.issuer.myinfo.gov.sg/myinfo202304-01/status/1#10908",
"statusListCredential": "https://stg.issuer.myinfo.gov.sg/myinfo202304-01/status/1",
"type": "StatusList2021Entry"
},
"expirationDate": "2025-09-08T04:28:41Z"
}
15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,19 @@ MyInfoVcVerifier.ethereumSign = function (privateKey, message) {
return rpcSignature.substring(2, rpcSignature.length);
};

/**
* [VC Expiration Check]
* @param {Object} VerifiableCredential object [signed verifiable credential]
* @return {Boolean} [the expiration status] TRUE - expired, False - Not expired
*/
MyInfoVcVerifier.getExpirationStatus = function (credential) {
if (credential.expirationDate) {
let now = Date.now();
let expirationDate = new Date(credential.expirationDate).getTime();
return now > expirationDate;
} else {
throw "No expirationDate";
}
};

module.exports = MyInfoVcVerifier;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "myinfo-vc-verifier",
"version": "0.0.7",
"version": "0.0.8",
"description": "This package provides the functionality to verify a verifiable credential using @mattrglobal jsonld-signatures-bbs.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 3a6bd41

Please sign in to comment.