Skip to content

Commit

Permalink
implements unsuspendCredential; fixes credential issuance counter che…
Browse files Browse the repository at this point in the history
…cking logic
  • Loading branch information
kezike committed Mar 12, 2024
1 parent 814fc94 commit eb9217f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ console.log(statusCredential);
*/
```

**Note:** You can also call `revokeCredential(credentialId)` to achieve the same effect as `updateStatus({ credentialId, statusPurpose: 'revocation', invalidate: true })` and `suspendCredential(credentialId)` to achieve the same effect as `updateStatus({ credentialId, statusPurpose: 'suspension', invalidate: true })`.
**Note:** You can also call `revokeCredential(credentialId)` to achieve the same effect as `updateStatus({ credentialId, statusPurpose: 'revocation', invalidate: true })` and `suspendCredential(credentialId)` to achieve the same effect as `updateStatus({ credentialId, statusPurpose: 'suspension', invalidate: true })`. Also note that `unsuspendCredential(credentialId)` will lift a suspension from a credential, while there is no equivalent reversal logic for revocation, since it is not allowed.

### Check status of credential

Expand Down
14 changes: 13 additions & 1 deletion src/credential-status-manager-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,15 @@ export abstract class BaseCredentialStatusManager {
});
}

// lifts suspension from credential
async unsuspendCredential(credentialId: string): Promise<VerifiableCredential> {
return this.updateStatus({
credentialId,
statusPurpose: StatusPurpose.Suspension,
invalidate: false
});
}

// retrieves status of credential with given ID
async getStatus(credentialId: string, options?: DatabaseConnectionOptions): Promise<CredentialStatusInfo> {
// retrieve user credential record
Expand Down Expand Up @@ -966,6 +975,7 @@ export abstract class BaseCredentialStatusManager {

// examine info for all status purposes
const statusPurposes = Object.keys(statusCredentialInfo) as StatusPurpose[];
const statusPurposesCounter = statusPurposes.length;
let credsIssuedCounter = 0;
for (const statusPurpose of statusPurposes) {
const {
Expand Down Expand Up @@ -1039,7 +1049,9 @@ export abstract class BaseCredentialStatusManager {
const credentialIds = await this.getAllUserCredentialIds(options);
const credentialIdsCounter = credentialIds.length;
const hasValidIssuedCounterCredentialToConfig = credentialIdsCounter === credentialsIssuedCounter;
const hasValidIssuedCounterConfigToReality = credentialsIssuedCounter === credsIssuedCounter;
const hasValidIssuedCounterConfigToReality =
credentialsIssuedCounter <= credsIssuedCounter &&
credsIssuedCounter <= credentialsIssuedCounter * statusPurposesCounter;

// check if credential issuance counter matches between
// credential table and config table
Expand Down

0 comments on commit eb9217f

Please sign in to comment.