mirror of
https://github.com/mosip/inji-wallet.git
synced 2026-01-09 13:38:01 -05:00
* [INJIMOB-2670]: Enable Auto Vc Activation (#1) * [INJIMOB-2670]: Enable Auto Vc Activation (#1759) * [INJIMOB-2670]: Hide Success Banner during Auto Activation. Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Locales for Auto Activation Error message Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Enable Auto Vc Activation and handle error scenarios Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Remove activation sections from Help content Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Update Event name to be generic Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Remove communication details and add default OTP into constants Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> --------- Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Removing Mosip specific condition for mosipInidividualId Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> --------- Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * add spanish language (#2) Signed-off-by: Sk Mijan Hossain <skmijanhossain@gmail.com> Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Individual Id fix and add prefix to face image (#4) * [INJIMOB-2670]: Individual Id fix and appending image format for face image. Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Add Utils to append Png Base64 Prefix to faceImage. Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> --------- Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Update artifact Id and App name in fastlane scripts and build.gradle. (#3) Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Add enable_auth and remove lilveness_detection in internal-build yml (#5) Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Spanish locale updates. (#6) Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Liveness detection flag type changed to string Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> --------- Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> Signed-off-by: Sk Mijan Hossain <skmijanhossain@gmail.com> Co-authored-by: mijan32 <74153970+mijan32@users.noreply.github.com>
163 lines
4.6 KiB
TypeScript
163 lines
4.6 KiB
TypeScript
import {
|
|
Credential,
|
|
CredentialTypes,
|
|
VC,
|
|
VcIdType,
|
|
VerifiableCredential,
|
|
} from '../machines/VerifiableCredential/VCMetaMachine/vc';
|
|
import {Protocols} from './openId4VCI/Utils';
|
|
import {getMosipIdentifier} from './commonUtil';
|
|
import {VCFormat} from './VCFormat';
|
|
import {isMosipVC} from './Utils';
|
|
import {getCredentialType} from '../components/VC/common/VCUtils';
|
|
|
|
const VC_KEY_PREFIX = 'VC';
|
|
const VC_ITEM_STORE_KEY_REGEX = '^VC_[a-zA-Z0-9_-]+$';
|
|
|
|
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;
|
|
|
|
downloadKeyType: string = '';
|
|
credentialType: string = '';
|
|
constructor({
|
|
idType = '',
|
|
requestId = '',
|
|
isPinned = false,
|
|
id = '',
|
|
issuer = '',
|
|
protocol = '',
|
|
timestamp = '',
|
|
isVerified = false,
|
|
mosipIndividualId = '',
|
|
format = '',
|
|
downloadKeyType = '',
|
|
isExpired = false,
|
|
credentialType = '',
|
|
} = {}) {
|
|
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.credentialType = credentialType;
|
|
}
|
|
|
|
//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,
|
|
mosipIndividualId: vc.mosipIndividualId
|
|
? vc.mosipIndividualId
|
|
: vc.vcMetadata
|
|
? vc.vcMetadata.mosipIndividualId
|
|
: getMosipIndividualId(vc.verifiableCredential, vc.issuer),
|
|
downloadKeyType: vc.downloadKeyType,
|
|
credentialType: vc.credentialType,
|
|
});
|
|
}
|
|
|
|
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.requestId}`
|
|
: `${VC_KEY_PREFIX}_${this.requestId}`;
|
|
}
|
|
|
|
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,
|
|
credType: CredentialTypes,
|
|
) => {
|
|
const [issuer, protocol, credentialId] =
|
|
context.credentialWrapper?.identifier.split(':');
|
|
|
|
return VCMetadata.fromVC({
|
|
requestId: credentialId ?? null,
|
|
issuer: issuer,
|
|
protocol: protocol,
|
|
id: `${credentialId} + '_' + ${issuer}`,
|
|
timestamp: context.timestamp ?? '',
|
|
isVerified: context.vcMetadata.isVerified ?? false,
|
|
isExpired: context.vcMetadata.isExpired ?? false,
|
|
mosipIndividualId: getMosipIndividualId(
|
|
context['verifiableCredential'] as VerifiableCredential,
|
|
issuer,
|
|
),
|
|
format: context['credentialWrapper'].format,
|
|
downloadKeyType: keyType,
|
|
credentialType: getCredentialType(context.selectedCredentialType),
|
|
});
|
|
};
|
|
|
|
const getMosipIndividualId = (
|
|
verifiableCredential: VerifiableCredential | Credential,
|
|
issuer: string,
|
|
) => {
|
|
try {
|
|
const credential = verifiableCredential?.credential
|
|
? verifiableCredential.credential
|
|
: verifiableCredential;
|
|
const credentialSubject = credential?.credentialSubject;
|
|
return credentialSubject ? getMosipIdentifier(credentialSubject) : '';
|
|
} catch (error) {
|
|
console.error('Error getting the display ID:', error);
|
|
return null;
|
|
}
|
|
};
|