Files
inji-wallet/shared/VCMetadata.ts
KiruthikaJeyashankar 703e03057d Sync release 0.21 (#2165)
* [INJIMOB-3622] Fix alignment in history screen  (#2140)

* [INJIMOB-3622]: clear the history page issue

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

* [INJIMOB-3622]: clear the history page issue

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

---------

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

* [INJIMOB-3647] refactor: enhance response structure of credential status check (#2145)

* [INJIMOB-3647] refactor: udpate vc verifier RN module

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

* [INJIMOB-3647] refactor: update reverification logic

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

* [INJIMOB-3647] refactor: modify status response structure

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

* [INJIMOB-3647] refactor: update response resolving of status check in swift bridge

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

* [INJIMOB-3647] refactor: update info logs to print status message

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

* [INJIMOB-3647] refactor: modify type from map to record

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

* [INJIMOB-3647] refactor: remove unnecessary async function

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

* [INJIMOB-3647] refactor: Credential summary result structure

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

---------

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

* Injimob-3651: revert all the branding changes (#2151)

* Revert "[INJIMOB-3622] Fix alignment in history screen  (#2140)"

This reverts commit a0b08914e5.

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

* Revert "Injimob [3622] [3627] - BANNER ISSUE AND BRANDING CHANGES ISSUES  (#2130)"

This reverts commit 522104811c.

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

* Revert "[INJIMOB-3633][INJIMOB-3636] fix icon bg color across app (#2134)"

This reverts commit d8d718693d.

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

* Revert "[INJIMOB-3633] fix search bar clear icon not apperaing (#2133)"

This reverts commit 6a202b11af.

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

* [INJIMOB-3651]: revert all the branding changes

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

* [INJIMOB-3651]: update all the snapshot

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

---------

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

* [INJIMOB-3647] refactor: update isRevoked data type (#2149)

* [INJIMOB-3647] refactor: modify data type of isRevoked to EvaluationStatus

Type representing any possible value of EvaluationStatus.

- "TRUE" → Condition was evaluated and is positively true
- "FALSE" → Condition was evaluated and is definitively false
- "UNDETERMINED" → Condition could not be evaluated due to an error

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

* [INJIMOB-3647] refactor: modify data type of isRevoked to EvaluationStatus

Type representing any possible value of EvaluationStatus.

- "TRUE" → Condition was evaluated and is positively true
- "FALSE" → Condition was evaluated and is definitively false
- "UNDETERMINED" → Condition could not be evaluated due to an error

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

* [INJIMOB-3647] refactor: change statuslistVC type to record from string

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

# Conflicts:
#	shared/vcjs/verifyCredential.ts

* [INJIMOB-3647] refactor: update status revoke check to check for null status

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

* [INJIMOB-3647] refactor: VCMetadat constructor isRevoked param

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

* [INJIMOB-3647] refactor: rename EvaluationStatus to RevocationStatus

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

* [INJIMOB-3647] refactor: modify revocation status logs

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

---------

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

* Injimob-3651: update the new branding changes (#2154)

* [INJIMOB-3622]: add the new branding changes

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

* [INJIMOB-3651]: update the new branding changes

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

* [INJIMOB-3651]: update the new snapshots

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

* [INJIMOB-3651]: update the changes mentioned deskcheck

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

---------

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>
Signed-off-by: jaswanthkumartw <jaswanthkumar.p@thoughtworks.com>

* [INJIMOB-3647] fix error condition in ios revocation (#2157)

Signed-off-by: Abhishek Paul <paul.apaul.abhishek.ap@gmail.com>

* [INJIMOB-3581] add doc for revocation support (#2158)

Signed-off-by: Abhishek Paul <paul.apaul.abhishek.ap@gmail.com>

* [INJIMOB-3658] update openid4vp dependencies to 0.6.0 (#2160)

Signed-off-by: Abhishek Paul <paul.apaul.abhishek.ap@gmail.com>

* INJIMOB-3659: Removing inji wallet ui automation folder from release-0.21.x branch (#2161)

Signed-off-by: maheswaras <maheswara.s@cyberpwn.com>

* INJIMOB-3659: Removing inji wallet ui automation folder from release-0.21.x branch (#2162)

* INJIMOB-3659: Removing inji wallet ui automation folder from release-0.21.x branch

Signed-off-by: maheswaras <maheswara.s@cyberpwn.com>

* INJIMOB-3659: Removing inji wallet ui automation folder from release-0.21.x branch

Signed-off-by: maheswaras <maheswara.s@cyberpwn.com>

---------

Signed-off-by: maheswaras <maheswara.s@cyberpwn.com>

* refactor: replace @expo-google-fonts/montserrat with @expo-google-fonts/inter in package-lock.json

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

* [INJIMOB-3647] fix: change inter to montserrat font

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

* [INJIMOB-3647] refcator: update useFont with montserrat font

Flows - first time VC receved by receiver

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>

---------

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>
Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>
Signed-off-by: jaswanthkumartw <jaswanthkumar.p@thoughtworks.com>
Signed-off-by: Abhishek Paul <paul.apaul.abhishek.ap@gmail.com>
Signed-off-by: maheswaras <maheswara.s@cyberpwn.com>
Co-authored-by: jaswanthkumartw <jaswanthkumar.p@thoughtworks.com>
Co-authored-by: abhip2565 <paul.apaul.abhishek.AP@gmail.com>
Co-authored-by: maheswaras <maheswara.s@cyberpwn.com>
2025-12-08 17:09:25 +05:30

199 lines
6.0 KiB
TypeScript

import {
Credential,
VC,
VcIdType,
VerifiableCredential,
} from '../machines/VerifiableCredential/VCMetaMachine/vc';
import {Protocols} from './openId4VCI/Utils';
import {getMosipIdentifier} from './commonUtil';
import {VCFormat} from './VCFormat';
import {isMosipVC, UUID} from './Utils';
import {getCredentialType} from '../components/VC/common/VCUtils';
import {RevocationStatus, RevocationStatusType} from './vcVerifier/VcVerifier';
const VC_KEY_PREFIX = 'VC';
const VC_ITEM_STORE_KEY_REGEX = '^VC_[a-zA-Z0-9_-]+$';
/** TODO: two identifiers requestId and id
* we have 2 fields in metadata - id, requestID
* requestID -> This will be holding the requestId required for OTP flow VCs and for OIDC flow it holds the generated UUID
* id -> holds UUID for both OTP based & OIDC flow
*/
export class VCMetadata {
static vcKeyRegExp = new RegExp(VC_ITEM_STORE_KEY_REGEX);
idType: VcIdType | string = '';
requestId = '';
isPinned = false;
id: string = '';
issuer?: string = '';
protocol?: string = '';
timestamp?: string = '';
isVerified: boolean = false;
mosipIndividualId: string = '';
format: string = '';
isExpired: boolean = false;
isRevoked: RevocationStatusType = RevocationStatus.FALSE;
downloadKeyType: string = '';
credentialType: string = '';
issuerHost: string = '';
lastKnownStatusTimestamp?: string = '';
constructor({
idType = '',
requestId = '',
isPinned = false,
id = '',
issuer = '',
protocol = '',
timestamp = '',
isVerified = false,
mosipIndividualId = '',
format = '',
downloadKeyType = '',
isExpired = false,
isRevoked = RevocationStatus.FALSE,
credentialType = '',
issuerHost = '',
lastKnownStatusTimestamp = '',
} = {}) {
this.idType = idType;
this.requestId = requestId;
this.isPinned = isPinned;
this.id = id;
this.protocol = protocol;
this.issuer = issuer;
this.timestamp = timestamp;
this.isVerified = isVerified;
this.mosipIndividualId = mosipIndividualId;
this.format = format;
this.downloadKeyType = downloadKeyType;
this.isExpired = isExpired;
this.isRevoked = isRevoked;
this.credentialType = credentialType;
this.issuerHost = issuerHost;
this.lastKnownStatusTimestamp = lastKnownStatusTimestamp;
}
//TODO: Remove any typing and use appropriate typing
static fromVC(vc: Partial<VC> | VCMetadata | any) {
return new VCMetadata({
idType: vc.idType,
format: vc.format || VCFormat.ldp_vc,
requestId: vc.requestId,
isPinned: vc.isPinned || false,
id: vc.id,
protocol: vc.protocol,
issuer: vc.issuer,
timestamp: vc.vcMetadata ? vc.vcMetadata.timestamp : vc.timestamp,
isVerified: vc.isVerified,
isExpired: vc.isExpired,
isRevoked: vc.isRevoked,
mosipIndividualId: vc.mosipIndividualId
? vc.mosipIndividualId
: vc.vcMetadata
? vc.vcMetadata.mosipIndividualId
: getMosipIndividualId(vc.verifiableCredential, vc.issuer),
downloadKeyType: vc.downloadKeyType,
credentialType: vc.credentialType,
issuerHost: vc.issuerHost,
lastKnownStatusTimestamp: vc.lastKnownStatusTimestamp,
});
}
static fromVcMetadataString(vcMetadataStr: string | object) {
try {
if (typeof vcMetadataStr === 'object')
return new VCMetadata(vcMetadataStr);
return new VCMetadata(JSON.parse(vcMetadataStr));
} catch (e) {
console.error('Failed to parse VC Metadata', e);
return new VCMetadata();
}
}
static isVCKey(key: string): boolean {
return VCMetadata.vcKeyRegExp.exec(key) != null;
}
isFromOpenId4VCI() {
return this.protocol === Protocols.OpenId4VCI;
}
// Used for mmkv storage purposes and as a key for components and vc maps
// Update VC_ITEM_STORE_KEY_REGEX in case of changes in vckey
getVcKey(): string {
return this.timestamp !== ''
? `${VC_KEY_PREFIX}_${this.timestamp}_${this.id}`
: `${VC_KEY_PREFIX}_${this.id}`;
}
equals(other: VCMetadata): boolean {
return this.getVcKey() === other.getVcKey();
}
}
export function parseMetadatas(metadataStrings: object[]) {
return metadataStrings.map(o => new VCMetadata(o));
}
export const getVCMetadata = (context: object, keyType: string) => {
const issuerHost =
context.selectedIssuer.credential_issuer_host ??
context.selectedIssuer.credential_issuer;
const issuer =
context.selectedIssuer.issuer_id ??
context.selectedIssuer.credential_issuer;
const credentialId = `${UUID.generate()}_${getIssuerName(issuerHost)}`;
function getIssuerName(issuerHost: string): string {
try {
const url = new URL(issuerHost);
return url.hostname.split('.')[0];
} catch (error) {
// Fallback to issuerHost if URL parsing fails
return issuerHost;
}
}
return VCMetadata.fromVC({
requestId: credentialId,
issuer: issuer,
protocol: context.selectedIssuer.protocol,
id: credentialId,
timestamp: context.timestamp ?? '',
isVerified: context.vcMetadata.isVerified ?? false,
isExpired: context.vcMetadata.isExpired ?? false,
isRevoked: context.vcMetadata.isRevoked ?? RevocationStatus.FALSE,
lastKnownStatusTimestamp: context.vcMetadata.lastKnownStatusTimestamp ?? '',
mosipIndividualId: getMosipIndividualId(
context['verifiableCredential'] as VerifiableCredential,
issuer,
),
format: context['credentialWrapper'].format,
downloadKeyType: keyType,
credentialType: getCredentialType(context.selectedCredentialType),
issuerHost: issuerHost,
});
};
const getMosipIndividualId = (
verifiableCredential: VerifiableCredential | Credential,
issuer: string,
) => {
try {
const credential = verifiableCredential?.credential
? verifiableCredential.credential
: verifiableCredential;
const credentialSubject = credential?.credentialSubject;
if (isMosipVC(issuer)) {
return credentialSubject ? getMosipIdentifier(credentialSubject) : '';
}
return '';
} catch (error) {
console.error('Error getting the display ID:', error);
return null;
}
};