mirror of
https://github.com/mosip/inji-wallet.git
synced 2026-01-10 05:58:01 -05:00
* feat(inji-344): Use VC Key class instead of separate functions for managing vc key * feat(inji-344): Use properties from VcKey Class instead of reading from vckey string * feat(inji-344): Rename vcKey to vcMetadata * feat(inji-344): Use vc's unique id or vckey instead of joined string of vc metadata * feat(inji-344): Use vc key instead of unique id to avoid confusion. Fix issues reg parsing vc metadata * feat(inji-344):fix redownloading issue Co-authored-by: Tilak <tilakpuli15@gmail.com> * feat(inji-344): Remove vc getting stored on update of pin status * feat(inji-344): update other vc's pin status to false when any vc is pinned * feat(inji-344): remove hash ID for UIN * feat(inji-344): revert google services json * feat(inji-344): remove mmkv logs added for debugging * feat(inji-344): fix received vcs not getting displayed on reopen of app * feat(inji-344): fix id not shown in revoke component --------- Co-authored-by: Sri Kanth Kola <srikanthsri7447@gmail.com>
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import {VC, VcIdType} from '../types/vc';
|
|
|
|
const VC_KEY_PREFIX = 'VC';
|
|
const VC_ITEM_STORE_KEY_REGEX = '^VC_[a-z0-9-]+$';
|
|
|
|
export class VCMetadata {
|
|
idType: VcIdType | string = '';
|
|
requestId = '';
|
|
isPinned = false;
|
|
id: string = '';
|
|
static vcKeyRegExp = new RegExp(VC_ITEM_STORE_KEY_REGEX);
|
|
|
|
constructor({idType = '', requestId = '', isPinned = false, id = ''} = {}) {
|
|
this.idType = idType;
|
|
this.requestId = requestId;
|
|
this.isPinned = isPinned;
|
|
this.id = id;
|
|
}
|
|
|
|
static fromVC(vc: Partial<VC>) {
|
|
return new VCMetadata({
|
|
idType: vc.idType,
|
|
requestId: vc.requestId,
|
|
isPinned: vc.isPinned || false,
|
|
id: vc.id,
|
|
});
|
|
}
|
|
|
|
static fromVcMetadataString(vcMetadataStr: string) {
|
|
try {
|
|
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;
|
|
}
|
|
|
|
// 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 `${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));
|
|
}
|