Skip to content

Commit

Permalink
feat(exp): remove method for expiration check; decrease test await
Browse files Browse the repository at this point in the history
  • Loading branch information
whitneypurdum committed Jul 26, 2022
1 parent e7a50a5 commit 9ae092c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 42 deletions.
23 changes: 1 addition & 22 deletions docs/api/classes/modules_claims.ClaimsService.md
Expand Up @@ -20,7 +20,6 @@ claimsService.getClaimById(claim.id);

### Methods

- [claimIsExpired](modules_claims.ClaimsService.md#claimisexpired)
- [claimRevocationDetails](modules_claims.ClaimsService.md#claimrevocationdetails)
- [createClaimRequest](modules_claims.ClaimsService.md#createclaimrequest)
- [createDelegateProof](modules_claims.ClaimsService.md#createdelegateproof)
Expand Down Expand Up @@ -70,26 +69,6 @@ claimsService.getClaimById(claim.id);

## Methods

### claimIsExpired

**claimIsExpired**(`date`): `boolean`

Verifies if a date is expired (occurs before given date)

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `date` | `number` | to be verified |

#### Returns

`boolean`

Boolean indicating if a date is expired

___

### claimRevocationDetails

**claimRevocationDetails**(`options`): `Promise`<`undefined` \| [`ClaimRevocationDetailsResult`](../interfaces/modules_claims.ClaimRevocationDetailsResult.md)\>
Expand Down Expand Up @@ -280,7 +259,7 @@ Fetch a credential from storage

`Promise`<`undefined` \| `VerifiableCredential`<`RoleCredentialSubject`\> \| `RoleEIP191JWT`\>

Resolved Credetiantial of type VerifiableCredential<RoleCredentialSubject> || RoleEIP191JWT or undefined
credential if available or undefined if not

___

Expand Down
12 changes: 6 additions & 6 deletions e2e/claims.service.e2e.ts
Expand Up @@ -948,7 +948,7 @@ describe('Сlaim tests', () => {
],
publishOnChain: true,
issuerFields: [],
expirationTimestamp: Date.now() + 10000,
expirationTimestamp: Date.now() + 7000,
});
await signerService.connect(rootOwner, ProviderType.PrivateKey);
const subjectDoc = await didRegistry.getDidDocument({
Expand All @@ -960,7 +960,7 @@ describe('Сlaim tests', () => {
claim: { token: issuedToken },
});
const delay = (ms) => new Promise((res) => setTimeout(res, ms));
await delay(9000);
await delay(8000);
await signerService.connect(staticIssuer, ProviderType.PrivateKey);
const result = await claimsService.resolveCredentialAndVerify(
rootOwnerDID,
Expand Down Expand Up @@ -990,13 +990,13 @@ describe('Сlaim tests', () => {
const vc = await createExampleSignedCredential(
issuerFields,
`${vcExpired}.${root}`,
new Date(Date.now() + 10000)
new Date(Date.now() + 8000)
);
nock(vc.credentialStatus?.statusListCredential as string)
.get('')
.reply(200, undefined);
const delay = (ms) => new Promise((res) => setTimeout(res, ms));
await delay(11000);
await delay(8000);
const result = await claimsService.verifyVc(vc);
expect(result.errors).toContain('Verifiable Credential is expired.');
expect(result.isVerified).toBe(false);
Expand All @@ -1012,7 +1012,7 @@ describe('Сlaim tests', () => {
],
publishOnChain: true,
issuerFields: [],
expirationTimestamp: Date.now() + 10000,
expirationTimestamp: Date.now() + 7000,
});
await signerService.connect(rootOwner, ProviderType.PrivateKey);
const subjectDoc = await didRegistry.getDidDocument({
Expand All @@ -1024,7 +1024,7 @@ describe('Сlaim tests', () => {
claim: { token: issuedToken },
});
const delay = (ms) => new Promise((res) => setTimeout(res, ms));
await delay(11000);
await delay(8000);
await signerService.connect(staticIssuer, ProviderType.PrivateKey);
const credential = await claimsService.fetchCredential(
rootOwnerDID,
Expand Down
16 changes: 2 additions & 14 deletions src/modules/claims/claims.service.ts
Expand Up @@ -1423,16 +1423,6 @@ export class ClaimsService {
);
}

/**
* Verifies if a date is expired (occurs before given date)
* @param {Number} date to be verified
* @return Boolean indicating if a date is expired
*
*/
claimIsExpired(date: number): boolean {
return !!date && date < Date.now();
}

/**
* Verifies:
* - That credential proof is valid
Expand Down Expand Up @@ -1511,12 +1501,10 @@ export class ClaimsService {
if (!proofVerified) {
errors.push(ERROR_MESSAGES.PROOF_NOT_VERIFIED);
}
const isExpired = payload?.exp && this.claimIsExpired(payload.exp);
if (payload?.exp) {
const isExpired = payload?.exp && (payload?.exp * 1000) < Date.now();
if (isExpired) {
errors.push(ERROR_MESSAGES.CREDENTIAL_EXPIRED);
}
}
return {
errors: errors,
isVerified: !!proofVerified && !!issuerVerified && !isExpired,
Expand All @@ -1528,7 +1516,7 @@ export class ClaimsService {
*
* @param subjectDID The DID to try to resolve a credential for
* @param roleNamesapce The role to try to get a credential for. Should be a full role namespace (for example, "myrole.roles.myorg.auth.ewc")
* @return Resolved Credetiantial of type VerifiableCredential<RoleCredentialSubject> || RoleEIP191JWT or undefined
* @return credential if available or undefined if not
*/
async fetchCredential(
subjectDID: string,
Expand Down

0 comments on commit 9ae092c

Please sign in to comment.