Skip to content

Commit

Permalink
[INJIMOB-2471] set UUID as vc identifier (#1745)
Browse files Browse the repository at this point in the history
* [INJIMOB-2471] make identifier of Vc as random UUID

Previously, we were relying on the id feild of the Vc to construct the unique identifier for VC component and file name for storing VC, this identifier in now replaced with random generated UUID. This was made since id property of VC is optional field as per w3c data-model 1.1.

We are using UUID version 4 to ensure randomness and collision-resistance.

Signed-off-by: KiruthikaJeyashankar <[email protected]>

* [INJIMOB-2471] maintain consistency in setting VCMetadata ID

Signed-off-by: KiruthikaJeyashankar <[email protected]>

* [INJICERT-2471] use VC metadata id as VC key

This VC key will be used for storing file name, component key & other identifier for VCs

Signed-off-by: KiruthikaJeyashankar <[email protected]>

* [INJIMOB-2471] remove setting identifier field in credential wrapper

The identitifier in credentialWrapper having the value "$issuer:$protocol:$UUID" was used to construct VC metadata id, issuer and protocol field which is already available in context param. This is now replaced with constructing VC metadata with the required fields available in machine context.

Signed-off-by: KiruthikaJeyashankar <[email protected]>

* [INJIMOB-2471] use context VCMetadata instead of calling function for accessing in issuersMachine

Signed-off-by: KiruthikaJeyashankar <[email protected]>

* [INJIMOB-2471] optimize import

Signed-off-by: KiruthikaJeyashankar <[email protected]>

---------

Signed-off-by: KiruthikaJeyashankar <[email protected]>
  • Loading branch information
KiruthikaJeyashankar authored Dec 24, 2024
1 parent b30cd6b commit 82740bc
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 116 deletions.
14 changes: 7 additions & 7 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fileignoreconfig:
- filename: package.json
checksum: 5b4fcb5ddc7cc96cc2d1733b544d56ea66e88cdab995a1052fbf9ac0e9c2dc21
- filename: package-lock.json
checksum: e448b633936de692ebdbadfac3a5a1ae3c2a2a55a8cc3ea7440bd5ec1dd9cef5
checksum: 8925d62a7011241371e295553f7bbe1af468c7f3f4d051436a30c8885a12d0a5
- filename: lib/jsonld-signatures/suites/ed255192018/ed25519.ts
checksum: 493b6e31144116cb612c24d98b97d8adcad5609c0a52c865a6847ced0a0ddc3a
- filename: components/PasscodeVerify.tsx
Expand Down Expand Up @@ -156,7 +156,7 @@ fileignoreconfig:
- filename: injitest/README.md
checksum: 82974a6b9363512472272245e9b433f92e63377e58ba306980876b745181a09c
- filename: shared/VCMetadata.ts
checksum: 4c0f2acc58894e5a427e1317b38d04daff91f64d1e61d6ee2f246ee516ef97ca
checksum: c76bd3c825931ac241d8e4f76b8a7444789f49e3b4e45a599b4dcd574f7971c8
- filename: ios/Podfile.lock
checksum: 43bd4742f2ba13357d8b9c44430bfa3cca0bf9bf8341984fd81174a929c85955
- filename: components/BackupAndRestoreBannerNotification.tsx
Expand Down Expand Up @@ -268,7 +268,7 @@ fileignoreconfig:
- filename: machines/Issuers/IssuersGuards.ts
checksum: 21783a057207ad04facdb4c71884f49b0230490def04158419d730e0cc60eb83
- filename: machines/Issuers/IssuersActions.ts
checksum: 4414aa10588d2305293b1902982c5969895c858355e4b91d01dfaa8601c2dd62
checksum: 03949a8a7f66f9b94a57b6b817b6c425e8438a7c796d75c00692d030342102b1
- filename: injitest/automation_trigger.sh
checksum: f2f34839c99cb1b871dde17aed8508a071345d22738796e005ff709d2dab8644
- filename: machines/Issuers/IssuersService.ts
Expand Down Expand Up @@ -344,7 +344,7 @@ fileignoreconfig:
checksum: e1814f6ac8fe15794f26e96de887bc196ffcb37b434d46ffb69a9497d2683667
- filename: injitest/src/main/resources/Vids.json
checksum: 8bcffed7a6dd565ae695e1b29de0655e10bd5c5420af2718defd593a687b8817
- filename: injitest/src/main/java/inji/utils/UpdateNetworkSettings.java
- filename: injitest/src/main/java/inji/utils/UpdateNetworkSettings.java
checksum: e249ce3e6b7f47abc183fe5a3637bb39ccb06900ef75b9b2f08426d1535e22aa
- filename: App.tsx
checksum: d16d4a40b246abe25a5d2da7ec65163b5756fe8ba9390608a7fc7f8e721b2ed1
Expand All @@ -358,8 +358,8 @@ fileignoreconfig:
checksum: c91348eceec5edbffa03ba03f3f52a8e90ff7f942816c9609080d1647052fd66
- filename: ios/RNPixelpassModule.swift
checksum: 822a2421798d5c0669f4ab1b983194eb770cbef2aa30bf212d06bd959738c4ca
- filename: injitest/src/test/java/androidTestCases/VerifyHistoryTest.java
checksum: dffc4741b251b42c81d5bdac7d649c02b37bb9045285590b29f86c2d5f526fd1
- filename: injitest/src/test/java/androidTestCases/VerifyHistoryTest.java
checksum: dffc4741b251b42c81d5bdac7d649c02b37bb9045285590b29f86c2d5f526fd1
- filename: android/app/src/main/java/io/mosip/residentapp/RNPixelpassModule.java
checksum: cef9be4bfafb54e2c885b2459f2819554cad6448b5dc372976706894df704e5d
- filename: android/app/src/main/AndroidManifest.xml
Expand All @@ -372,7 +372,7 @@ fileignoreconfig:
checksum: 947b6d75543e2bf959ca2d95dd7224051e0b4ec2c28f7515f923701e22a932f0
- filename: components/FaceScanner/LivenessDetection.tsx
checksum: d4140a42ee9ca0f7c90e490f762d181a723fd9dd20db891cbbe53bfbd8f81632
- filename: machines/VerifiableCredential/VCItemMachine/VCItemActions.ts
- filename: machines/VerifiableCredential/VCItemMachine/VCItemActions.ts
checksum: bc11e275227ccf93c5e869b47bb2b63454758983b8fc0e105004fefa1b169091
- filename: machines/app.ts
checksum: 5da59bb384d04e29c7745d773108903fa144275c57edc1aca1898fcae7baea84
Expand Down
14 changes: 5 additions & 9 deletions machines/Issuers/IssuersActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,7 @@ export const IssuersActions = (model: any) => {
},

storeVerifiableCredentialMeta: send(
context =>
StoreEvents.PREPEND(
MY_VCS_STORE_KEY,
getVCMetadata(context, context.keyType),
),
context => StoreEvents.PREPEND(MY_VCS_STORE_KEY, context.vcMetadata),
{
to: (context: any) => context.serviceRefs.store,
},
Expand All @@ -180,7 +176,7 @@ export const IssuersActions = (model: any) => {

storeVerifiableCredentialData: send(
(context: any) => {
const vcMetadata = getVCMetadata(context, context.keyType);
const vcMetadata = context.vcMetadata;
const {
verifiableCredential: {
processedCredential,
Expand All @@ -206,7 +202,7 @@ export const IssuersActions = (model: any) => {
context => {
return {
type: 'VC_ADDED',
vcMetadata: getVCMetadata(context, context.keyType),
vcMetadata: context.vcMetadata,
};
},
{
Expand All @@ -218,7 +214,7 @@ export const IssuersActions = (model: any) => {
(context: any) => {
return {
type: 'VC_DOWNLOADED',
vcMetadata: getVCMetadata(context, context.keyType),
vcMetadata: context.vcMetadata,
vc: context.credentialWrapper,
};
},
Expand Down Expand Up @@ -293,7 +289,7 @@ export const IssuersActions = (model: any) => {

logDownloaded: send(
context => {
const vcMetadata = getVCMetadata(context, context.keyType);
const vcMetadata = context.vcMetadata;
return ActivityLogEvents.LOG_ACTIVITY(
VCActivityLog.getLogFromObject({
_vcKey: vcMetadata.getVcKey(),
Expand Down
9 changes: 3 additions & 6 deletions machines/VerifiableCredential/VCItemMachine/VCItemActions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {assign, send} from 'xstate';
import {CommunicationDetails} from '../../../shared/Utils';
import {CommunicationDetails, UUID} from '../../../shared/Utils';
import {StoreEvents} from '../../store';
import {VCMetadata} from '../../../shared/VCMetadata';
import {MIMOTO_BASE_URL, MY_VCS_STORE_KEY} from '../../../shared/constants';
Expand Down Expand Up @@ -124,11 +124,8 @@ export const VCItemActions = model => {
setContext: model.assign((context, event) => {
const vcMetadata = VCMetadata.fromVC(context.vcMetadata);
if (!vcMetadata.id) {
const verifiableCredentialId = event.response.verifiableCredential.id;
const credId = verifiableCredentialId.startsWith('did')
? verifiableCredentialId.split(':')
: verifiableCredentialId.split('/');
vcMetadata.id = `${credId[credId.length - 1]} - ${vcMetadata.issuer}`;
const credId = UUID.generate();
vcMetadata.id = `${credId}_${vcMetadata.issuer}`;
}
return {
...context,
Expand Down
35 changes: 18 additions & 17 deletions machines/VerifiableCredential/VCMetaMachine/vc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,24 @@ export interface CredentialSubject {

type VCContext = (string | Record<string, unknown>)[];

export type Credential = {
credentialConfigurationId: any;
'@context': VCContext;
credentialSubject: CredentialSubject;
id: string;
issuanceDate: string;
issuer: string;
proof: {
created: string;
jws: string;
proofPurpose: 'assertionMethod' | string;
type: 'RsaSignature2018' | string;
verificationMethod: string;
};
type: string[];
} | string
export type Credential =
| {
credentialConfigurationId: any;
'@context': VCContext;
credentialSubject: CredentialSubject;
id: string;
issuanceDate: string;
issuer: string;
proof: {
created: string;
jws: string;
proofPurpose: 'assertionMethod' | string;
type: 'RsaSignature2018' | string;
verificationMethod: string;
};
type: string[];
}
| string;

export interface VerifiableCredential {
issuerLogo: logoType;
Expand All @@ -81,7 +83,6 @@ export interface VerifiableCredentialData {
export interface CredentialWrapper {
verifiableCredential: VerifiableCredential;
format: string;
identifier: string;
generatedOn: Date;
vcMetadata: VCMetadata;
}
Expand Down
100 changes: 92 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"simple-pem2jwk": "^0.2.4",
"telemetry-sdk": "git://github.com/mosip/sunbird-telemetry-sdk.git#f762be5732ee552c0c70bdd540aa4e2701554c71",
"text-encoding": "^0.7.0",
"uuid": "^11.0.3",
"xstate": "^4.35.0"
},
"devDependencies": {
Expand Down
15 changes: 11 additions & 4 deletions shared/Utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { VCMetadata } from './VCMetadata';
import { NETWORK_REQUEST_FAILED } from './constants';
import { groupBy } from './javascript';
import { Issuers } from './openId4VCI/Utils';
import {VCMetadata} from './VCMetadata';
import {NETWORK_REQUEST_FAILED} from './constants';
import {groupBy} from './javascript';
import {Issuers} from './openId4VCI/Utils';
import {v4 as uuid} from 'uuid';

export const getVCsOrderedByPinStatus = (vcMetadatas: VCMetadata[]) => {
const [pinned, unpinned] = groupBy(
Expand Down Expand Up @@ -54,3 +55,9 @@ export const parseJSON = (input: any) => {
export const isNetworkError = (error: string) => {
return error.includes(NETWORK_REQUEST_FAILED);
};

export class UUID {
public static generate(): string {
return uuid();
}
}
Loading

0 comments on commit 82740bc

Please sign in to comment.