-
Notifications
You must be signed in to change notification settings - Fork 239
feat: support w3c revocation #2072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GHkrishna
wants to merge
16
commits into
openwallet-foundation:main
Choose a base branch
from
GHkrishna:feat/support-w3c-revocation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
10c8696
chore: add missing test script in package-core
GHkrishna c6d050d
Merge branch 'openwallet-foundation:main' into main
GHkrishna 926909f
feat: support w3c revocation
GHkrishna c50074e
fix: rebasing conflicts
GHkrishna 60dd875
fix: as discussed in the call we would need to keep the logic for rev…
GHkrishna 178ca90
fix: as discussed in the call we would need to keep the logic for rev…
GHkrishna 59f49ed
chore: remove comments
GHkrishna 748731e
fix: remove unnecessay imports
GHkrishna 2941920
fix: consistency with other interface
GHkrishna 6fdad0f
fix: expose CredentialStatusBasedOnType to easily access it
GHkrishna 5454eda
chore: remove commented code
GHkrishna 3f4e03b
Merge branch 'main' into feat/support-w3c-revocation
GHkrishna 8c2dc94
fix: import path change
GHkrishna 1100c63
fix: add and fix existing test cases
GHkrishna 05ea39e
fix: package lock
GHkrishna 3ab1d73
fix: linting issues
GHkrishna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/core/src/modules/vc/data-integrity/libraries/credentialStatus.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import type { AgentContext } from '../../../../agent' | ||
| import type { W3cCredentialStatus } from '../../models/credential/w3c-credential-status/W3cCredentialStatus' | ||
|
|
||
|
|
||
| import { CredoError } from '../../../../error/CredoError' | ||
| import { | ||
| BitStringStatusListEntry, | ||
| verifyBitStringCredentialStatus, | ||
| } from '../../models/credential/w3c-credential-status' | ||
| import { W3cCredentialStatusSupportedTypes } from '../../models/credential/w3c-credential-status/W3cCredentialStatus' | ||
| import { SingleOrArray } from '../../../../utils' | ||
| import { ClaimFormat } from '../../models' | ||
|
|
||
| // Function to validate the status using the updated method | ||
| export const validateStatus = async ( | ||
| credentialStatus: SingleOrArray<W3cCredentialStatus>, | ||
| agentContext: AgentContext, | ||
| credentialFormat: ClaimFormat.JwtVc | ClaimFormat.LdpVc | ||
| ): Promise<boolean> => { | ||
|
|
||
| if (Array.isArray(credentialStatus)) { | ||
| agentContext.config.logger.debug('Credential status type is array') | ||
| throw new CredoError( | ||
| 'Invalid credential status type. Currently only a single credentialStatus is supported per credential' | ||
| ) | ||
| } | ||
|
|
||
| switch (credentialStatus.type) { | ||
| case W3cCredentialStatusSupportedTypes.BitstringStatusListEntry: | ||
| agentContext.config.logger.debug('Credential status type is BitstringStatusListEntry') | ||
| try { | ||
| await verifyBitStringCredentialStatus( | ||
| credentialStatus as unknown as BitStringStatusListEntry, | ||
| agentContext, | ||
| credentialFormat | ||
| ) | ||
| } catch (errors) { | ||
| throw new CredoError(`Error while validating credential status`, errors) | ||
| } | ||
| break | ||
| default: | ||
| throw new CredoError( | ||
| `Invalid credential status type. Supported types are: ${Object.values(W3cCredentialStatusSupportedTypes).join( | ||
| ', ' | ||
| )}` | ||
| ) | ||
| } | ||
| return true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
packages/core/src/modules/vc/models/credential/W3cCredentialStatus.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/core/src/modules/vc/models/credential/w3c-credential-status/W3cCredentialStatus.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { IsEnum, IsString } from 'class-validator' | ||
|
|
||
| import { IsUri } from '../../../../../utils/validators' | ||
| import { BitStringStatusListEntry } from './bitstring-status-list'; | ||
|
|
||
| export interface W3cCredentialStatusOptions { | ||
| id: string | ||
| type: string | ||
| } | ||
|
|
||
| export type CredentialStatusBasedOnType = W3cCredentialStatus extends { type: 'BitstringStatusListEntry' } | ||
| ? BitStringStatusListEntry | ||
| : W3cCredentialStatus | BitStringStatusListEntry | ||
|
|
||
| export enum W3cCredentialStatusSupportedTypes { | ||
| BitstringStatusListEntry = 'BitstringStatusListEntry', | ||
| } | ||
|
|
||
| export class W3cCredentialStatus { | ||
| public constructor(options: W3cCredentialStatusOptions) { | ||
| if (options) { | ||
| this.id = options.id | ||
| this.type = options.type | ||
| } | ||
| } | ||
|
|
||
| @IsUri() | ||
| @IsString() | ||
| public id!: string | ||
|
|
||
| @IsString() | ||
| // @IsEnum(W3cCredentialStatusSupportedTypes, { message: 'Invalid credential status type' }) | ||
GHkrishna marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public type!: string | ||
| } | ||
|
|
||
131 changes: 131 additions & 0 deletions
131
...s/vc/models/credential/w3c-credential-status/bitstring-status-list/BitStringStatusList.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| import { Type } from 'class-transformer' | ||
| import { | ||
| IsNumberString, | ||
| IsString, | ||
| registerDecorator, | ||
| ValidationArguments, | ||
| ValidationOptions, | ||
| } from 'class-validator' | ||
|
|
||
| import { W3cCredentialStatus } from '../W3cCredentialStatus' | ||
| import { BitstringStatusListCredentialStatusPurpose } from './BitStringStatusListCredential' | ||
| import { JsonTransformer } from '../../../../../../utils' | ||
|
|
||
|
|
||
| export interface BitStringStatusListMessageOptions { | ||
| // a string representing the hexadecimal value of the status prefixed with 0x | ||
| status: string | ||
| // a string used by software developers to assist with debugging which SHOULD NOT be displayed to end users | ||
| message?: string | ||
| [key: string]: unknown | ||
| } | ||
|
|
||
| export class BitStringStatusListMessage { | ||
| public constructor(options: BitStringStatusListMessageOptions) { | ||
| if (options) { | ||
| this.status = options.status | ||
| this.message = options.message | ||
| } | ||
| } | ||
|
|
||
| @IsString() | ||
| public status!: string | ||
|
|
||
| @IsString() | ||
| public message?: string; | ||
|
|
||
| [key: string]: unknown | undefined | ||
| } | ||
|
|
||
| /** | ||
| * Status list Entry, used to check status of a credential being issued or verified during presentaton. | ||
| * | ||
| * @see https://www.w3.org/TR/vc-bitstring-status-list/#bitstringstatuslistentry | ||
| */ | ||
| export class BitStringStatusListEntry extends W3cCredentialStatus { | ||
| public static type = 'BitstringStatusListEntry' | ||
|
|
||
| public constructor(options: IBitStringStatusListEntryOptions) { | ||
| super({ id: options.id, type: BitStringStatusListEntry.type }) | ||
|
|
||
| if (options) { | ||
| this.statusPurpose = options.statusPurpose | ||
| this.statusListCredential = options.statusListCredential | ||
| this.statusListIndex = options.statusListIndex | ||
|
|
||
| if (options.statusSize) this.statusSize = options.statusSize | ||
| if (options.statusMessage) this.statusMessage = options.statusMessage | ||
| } | ||
| } | ||
|
|
||
| @IsSupportedStatusPurpose({ message: 'Invalid statusPurpose value' }) | ||
| public statusPurpose!: string | ||
|
|
||
| @IsString() | ||
| public statusListIndex!: string | ||
|
|
||
| @IsString() | ||
| public statusListCredential!: string | ||
|
|
||
| @IsNumberString() | ||
| public statusSize?: string | ||
|
|
||
| @Type(() => BitStringStatusListMessage) | ||
| public statusMessage?: BitStringStatusListStatusMessage[] | ||
|
|
||
|
|
||
| public static fromJson(json: Record<string, unknown>) { | ||
| return JsonTransformer.fromJSON(json, BitStringStatusListEntry) | ||
| } | ||
| } | ||
|
|
||
| export interface BitStringStatusListStatusMessage { | ||
| // a string representing the hexadecimal value of the status prefixed with 0x | ||
| status: string | ||
| // a string used by software developers to assist with debugging which SHOULD NOT be displayed to end users | ||
| message?: string | ||
| // We can have some key value pairs as well | ||
| [key: string]: unknown | ||
| } | ||
|
|
||
| export interface IBitStringStatusListEntryOptions { | ||
GHkrishna marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| id: string | ||
| type: string | ||
| statusPurpose: string | ||
| // Unique identifier for specific credential | ||
| statusListIndex: string | ||
| // Must be url referencing to a VC of type 'BitstringStatusListCredential' | ||
| statusListCredential: string | ||
| // The statusSize indicates the size of the status entry in bits | ||
| statusSize?: string | ||
| // Must be preset if statusPurpose is message | ||
| /** | ||
| * the length of which MUST equal the number of possible status messages indicated by statusSize | ||
| * (e.g., statusMessage array MUST have 2 elements if statusSize has 1 bit, | ||
| * 4 elements if statusSize has 2 bits, 8 elements if statusSize has 3 bits, etc.). | ||
| */ | ||
| statusMessage?: BitStringStatusListStatusMessage[] | ||
| // An implementer MAY include the statusReference property. If present, its value MUST be a URL or an array of URLs [URL] which dereference to material related to the status | ||
| statusReference?: string | string[] | ||
| } | ||
|
|
||
| export function IsSupportedStatusPurpose(validationOptions?: ValidationOptions) { | ||
| return function (object: Object, propertyName: string) { | ||
| registerDecorator({ | ||
| name: 'isSupportedStatusPurpose', | ||
| target: object.constructor, | ||
| propertyName: propertyName, | ||
| options: validationOptions, | ||
| validator: { | ||
| validate(value: any, args: ValidationArguments) { | ||
| return Object.values(BitstringStatusListCredentialStatusPurpose).includes(value) | ||
| }, | ||
| defaultMessage(args: ValidationArguments) { | ||
| return `The statusPurpose must be one of the following: ${Object.values( | ||
| BitstringStatusListCredentialStatusPurpose | ||
| ).join(', ')}` | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does pako work fine in react native? How does it compare with other modules such as fflate? I'm asking this because we want core to be as smaller as possible and it looks like pako is a bit heavy.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, that's a good suggestion, I'm all in on keeping core as small as possible,
Pako did work fine with an android device.
I was not aware about fflate, will have a look at it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pako is also used by SD-JWT JS library, works in react native, and since we already depend on it is maybe not a bad choice. I have no idea on the size .