[INJIMOB-2471] set UUID as vc identifier (#1745)

* [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 <kiruthikavjshankar@gmail.com>

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

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

* [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 <kiruthikavjshankar@gmail.com>

* [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 <kiruthikavjshankar@gmail.com>

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

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

* [INJIMOB-2471] optimize import

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

---------

Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com>
This commit is contained in:
KiruthikaJeyashankar
2024-12-24 10:00:27 +05:30
committed by GitHub
parent b30cd6b809
commit 82740bcc36
9 changed files with 179 additions and 116 deletions

View File

@@ -2,7 +2,7 @@ fileignoreconfig:
- filename: package.json - filename: package.json
checksum: 5b4fcb5ddc7cc96cc2d1733b544d56ea66e88cdab995a1052fbf9ac0e9c2dc21 checksum: 5b4fcb5ddc7cc96cc2d1733b544d56ea66e88cdab995a1052fbf9ac0e9c2dc21
- filename: package-lock.json - filename: package-lock.json
checksum: e448b633936de692ebdbadfac3a5a1ae3c2a2a55a8cc3ea7440bd5ec1dd9cef5 checksum: 8925d62a7011241371e295553f7bbe1af468c7f3f4d051436a30c8885a12d0a5
- filename: lib/jsonld-signatures/suites/ed255192018/ed25519.ts - filename: lib/jsonld-signatures/suites/ed255192018/ed25519.ts
checksum: 493b6e31144116cb612c24d98b97d8adcad5609c0a52c865a6847ced0a0ddc3a checksum: 493b6e31144116cb612c24d98b97d8adcad5609c0a52c865a6847ced0a0ddc3a
- filename: components/PasscodeVerify.tsx - filename: components/PasscodeVerify.tsx
@@ -156,7 +156,7 @@ fileignoreconfig:
- filename: injitest/README.md - filename: injitest/README.md
checksum: 82974a6b9363512472272245e9b433f92e63377e58ba306980876b745181a09c checksum: 82974a6b9363512472272245e9b433f92e63377e58ba306980876b745181a09c
- filename: shared/VCMetadata.ts - filename: shared/VCMetadata.ts
checksum: 4c0f2acc58894e5a427e1317b38d04daff91f64d1e61d6ee2f246ee516ef97ca checksum: c76bd3c825931ac241d8e4f76b8a7444789f49e3b4e45a599b4dcd574f7971c8
- filename: ios/Podfile.lock - filename: ios/Podfile.lock
checksum: 43bd4742f2ba13357d8b9c44430bfa3cca0bf9bf8341984fd81174a929c85955 checksum: 43bd4742f2ba13357d8b9c44430bfa3cca0bf9bf8341984fd81174a929c85955
- filename: components/BackupAndRestoreBannerNotification.tsx - filename: components/BackupAndRestoreBannerNotification.tsx
@@ -268,7 +268,7 @@ fileignoreconfig:
- filename: machines/Issuers/IssuersGuards.ts - filename: machines/Issuers/IssuersGuards.ts
checksum: 21783a057207ad04facdb4c71884f49b0230490def04158419d730e0cc60eb83 checksum: 21783a057207ad04facdb4c71884f49b0230490def04158419d730e0cc60eb83
- filename: machines/Issuers/IssuersActions.ts - filename: machines/Issuers/IssuersActions.ts
checksum: 4414aa10588d2305293b1902982c5969895c858355e4b91d01dfaa8601c2dd62 checksum: 03949a8a7f66f9b94a57b6b817b6c425e8438a7c796d75c00692d030342102b1
- filename: injitest/automation_trigger.sh - filename: injitest/automation_trigger.sh
checksum: f2f34839c99cb1b871dde17aed8508a071345d22738796e005ff709d2dab8644 checksum: f2f34839c99cb1b871dde17aed8508a071345d22738796e005ff709d2dab8644
- filename: machines/Issuers/IssuersService.ts - filename: machines/Issuers/IssuersService.ts
@@ -344,7 +344,7 @@ fileignoreconfig:
checksum: e1814f6ac8fe15794f26e96de887bc196ffcb37b434d46ffb69a9497d2683667 checksum: e1814f6ac8fe15794f26e96de887bc196ffcb37b434d46ffb69a9497d2683667
- filename: injitest/src/main/resources/Vids.json - filename: injitest/src/main/resources/Vids.json
checksum: 8bcffed7a6dd565ae695e1b29de0655e10bd5c5420af2718defd593a687b8817 checksum: 8bcffed7a6dd565ae695e1b29de0655e10bd5c5420af2718defd593a687b8817
- filename: injitest/src/main/java/inji/utils/UpdateNetworkSettings.java - filename: injitest/src/main/java/inji/utils/UpdateNetworkSettings.java
checksum: e249ce3e6b7f47abc183fe5a3637bb39ccb06900ef75b9b2f08426d1535e22aa checksum: e249ce3e6b7f47abc183fe5a3637bb39ccb06900ef75b9b2f08426d1535e22aa
- filename: App.tsx - filename: App.tsx
checksum: d16d4a40b246abe25a5d2da7ec65163b5756fe8ba9390608a7fc7f8e721b2ed1 checksum: d16d4a40b246abe25a5d2da7ec65163b5756fe8ba9390608a7fc7f8e721b2ed1
@@ -358,8 +358,8 @@ fileignoreconfig:
checksum: c91348eceec5edbffa03ba03f3f52a8e90ff7f942816c9609080d1647052fd66 checksum: c91348eceec5edbffa03ba03f3f52a8e90ff7f942816c9609080d1647052fd66
- filename: ios/RNPixelpassModule.swift - filename: ios/RNPixelpassModule.swift
checksum: 822a2421798d5c0669f4ab1b983194eb770cbef2aa30bf212d06bd959738c4ca checksum: 822a2421798d5c0669f4ab1b983194eb770cbef2aa30bf212d06bd959738c4ca
- filename: injitest/src/test/java/androidTestCases/VerifyHistoryTest.java - filename: injitest/src/test/java/androidTestCases/VerifyHistoryTest.java
checksum: dffc4741b251b42c81d5bdac7d649c02b37bb9045285590b29f86c2d5f526fd1 checksum: dffc4741b251b42c81d5bdac7d649c02b37bb9045285590b29f86c2d5f526fd1
- filename: android/app/src/main/java/io/mosip/residentapp/RNPixelpassModule.java - filename: android/app/src/main/java/io/mosip/residentapp/RNPixelpassModule.java
checksum: cef9be4bfafb54e2c885b2459f2819554cad6448b5dc372976706894df704e5d checksum: cef9be4bfafb54e2c885b2459f2819554cad6448b5dc372976706894df704e5d
- filename: android/app/src/main/AndroidManifest.xml - filename: android/app/src/main/AndroidManifest.xml
@@ -372,7 +372,7 @@ fileignoreconfig:
checksum: 947b6d75543e2bf959ca2d95dd7224051e0b4ec2c28f7515f923701e22a932f0 checksum: 947b6d75543e2bf959ca2d95dd7224051e0b4ec2c28f7515f923701e22a932f0
- filename: components/FaceScanner/LivenessDetection.tsx - filename: components/FaceScanner/LivenessDetection.tsx
checksum: d4140a42ee9ca0f7c90e490f762d181a723fd9dd20db891cbbe53bfbd8f81632 checksum: d4140a42ee9ca0f7c90e490f762d181a723fd9dd20db891cbbe53bfbd8f81632
- filename: machines/VerifiableCredential/VCItemMachine/VCItemActions.ts - filename: machines/VerifiableCredential/VCItemMachine/VCItemActions.ts
checksum: bc11e275227ccf93c5e869b47bb2b63454758983b8fc0e105004fefa1b169091 checksum: bc11e275227ccf93c5e869b47bb2b63454758983b8fc0e105004fefa1b169091
- filename: machines/app.ts - filename: machines/app.ts
checksum: 5da59bb384d04e29c7745d773108903fa144275c57edc1aca1898fcae7baea84 checksum: 5da59bb384d04e29c7745d773108903fa144275c57edc1aca1898fcae7baea84

View File

@@ -155,11 +155,7 @@ export const IssuersActions = (model: any) => {
}, },
storeVerifiableCredentialMeta: send( storeVerifiableCredentialMeta: send(
context => context => StoreEvents.PREPEND(MY_VCS_STORE_KEY, context.vcMetadata),
StoreEvents.PREPEND(
MY_VCS_STORE_KEY,
getVCMetadata(context, context.keyType),
),
{ {
to: (context: any) => context.serviceRefs.store, to: (context: any) => context.serviceRefs.store,
}, },
@@ -180,7 +176,7 @@ export const IssuersActions = (model: any) => {
storeVerifiableCredentialData: send( storeVerifiableCredentialData: send(
(context: any) => { (context: any) => {
const vcMetadata = getVCMetadata(context, context.keyType); const vcMetadata = context.vcMetadata;
const { const {
verifiableCredential: { verifiableCredential: {
processedCredential, processedCredential,
@@ -206,7 +202,7 @@ export const IssuersActions = (model: any) => {
context => { context => {
return { return {
type: 'VC_ADDED', type: 'VC_ADDED',
vcMetadata: getVCMetadata(context, context.keyType), vcMetadata: context.vcMetadata,
}; };
}, },
{ {
@@ -218,7 +214,7 @@ export const IssuersActions = (model: any) => {
(context: any) => { (context: any) => {
return { return {
type: 'VC_DOWNLOADED', type: 'VC_DOWNLOADED',
vcMetadata: getVCMetadata(context, context.keyType), vcMetadata: context.vcMetadata,
vc: context.credentialWrapper, vc: context.credentialWrapper,
}; };
}, },
@@ -293,7 +289,7 @@ export const IssuersActions = (model: any) => {
logDownloaded: send( logDownloaded: send(
context => { context => {
const vcMetadata = getVCMetadata(context, context.keyType); const vcMetadata = context.vcMetadata;
return ActivityLogEvents.LOG_ACTIVITY( return ActivityLogEvents.LOG_ACTIVITY(
VCActivityLog.getLogFromObject({ VCActivityLog.getLogFromObject({
_vcKey: vcMetadata.getVcKey(), _vcKey: vcMetadata.getVcKey(),

View File

@@ -1,5 +1,5 @@
import {assign, send} from 'xstate'; import {assign, send} from 'xstate';
import {CommunicationDetails} from '../../../shared/Utils'; import {CommunicationDetails, UUID} from '../../../shared/Utils';
import {StoreEvents} from '../../store'; import {StoreEvents} from '../../store';
import {VCMetadata} from '../../../shared/VCMetadata'; import {VCMetadata} from '../../../shared/VCMetadata';
import {MIMOTO_BASE_URL, MY_VCS_STORE_KEY} from '../../../shared/constants'; import {MIMOTO_BASE_URL, MY_VCS_STORE_KEY} from '../../../shared/constants';
@@ -124,11 +124,8 @@ export const VCItemActions = model => {
setContext: model.assign((context, event) => { setContext: model.assign((context, event) => {
const vcMetadata = VCMetadata.fromVC(context.vcMetadata); const vcMetadata = VCMetadata.fromVC(context.vcMetadata);
if (!vcMetadata.id) { if (!vcMetadata.id) {
const verifiableCredentialId = event.response.verifiableCredential.id; const credId = UUID.generate();
const credId = verifiableCredentialId.startsWith('did') vcMetadata.id = `${credId}_${vcMetadata.issuer}`;
? verifiableCredentialId.split(':')
: verifiableCredentialId.split('/');
vcMetadata.id = `${credId[credId.length - 1]} - ${vcMetadata.issuer}`;
} }
return { return {
...context, ...context,

View File

@@ -43,22 +43,24 @@ export interface CredentialSubject {
type VCContext = (string | Record<string, unknown>)[]; type VCContext = (string | Record<string, unknown>)[];
export type Credential = { export type Credential =
credentialConfigurationId: any; | {
'@context': VCContext; credentialConfigurationId: any;
credentialSubject: CredentialSubject; '@context': VCContext;
id: string; credentialSubject: CredentialSubject;
issuanceDate: string; id: string;
issuer: string; issuanceDate: string;
proof: { issuer: string;
created: string; proof: {
jws: string; created: string;
proofPurpose: 'assertionMethod' | string; jws: string;
type: 'RsaSignature2018' | string; proofPurpose: 'assertionMethod' | string;
verificationMethod: string; type: 'RsaSignature2018' | string;
}; verificationMethod: string;
type: string[]; };
} | string type: string[];
}
| string;
export interface VerifiableCredential { export interface VerifiableCredential {
issuerLogo: logoType; issuerLogo: logoType;
@@ -81,7 +83,6 @@ export interface VerifiableCredentialData {
export interface CredentialWrapper { export interface CredentialWrapper {
verifiableCredential: VerifiableCredential; verifiableCredential: VerifiableCredential;
format: string; format: string;
identifier: string;
generatedOn: Date; generatedOn: Date;
vcMetadata: VCMetadata; vcMetadata: VCMetadata;
} }

100
package-lock.json generated
View File

@@ -100,6 +100,7 @@
"simple-pem2jwk": "^0.2.4", "simple-pem2jwk": "^0.2.4",
"telemetry-sdk": "git://github.com/mosip/sunbird-telemetry-sdk.git#f762be5732ee552c0c70bdd540aa4e2701554c71", "telemetry-sdk": "git://github.com/mosip/sunbird-telemetry-sdk.git#f762be5732ee552c0c70bdd540aa4e2701554c71",
"text-encoding": "^0.7.0", "text-encoding": "^0.7.0",
"uuid": "^11.0.3",
"xstate": "^4.35.0" "xstate": "^4.35.0"
}, },
"devDependencies": { "devDependencies": {
@@ -14126,6 +14127,16 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/expo-auth-session/node_modules/uuid": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",
"integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==",
"deprecated": "Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.",
"license": "MIT",
"bin": {
"uuid": "bin/uuid"
}
},
"node_modules/expo-barcode-scanner": { "node_modules/expo-barcode-scanner": {
"version": "12.3.2", "version": "12.3.2",
"resolved": "https://registry.npmjs.org/expo-barcode-scanner/-/expo-barcode-scanner-12.3.2.tgz", "resolved": "https://registry.npmjs.org/expo-barcode-scanner/-/expo-barcode-scanner-12.3.2.tgz",
@@ -14161,6 +14172,16 @@
"expo": "*" "expo": "*"
} }
}, },
"node_modules/expo-constants/node_modules/uuid": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",
"integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==",
"deprecated": "Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.",
"license": "MIT",
"bin": {
"uuid": "bin/uuid"
}
},
"node_modules/expo-crypto": { "node_modules/expo-crypto": {
"version": "12.6.0", "version": "12.6.0",
"resolved": "https://registry.npmjs.org/expo-crypto/-/expo-crypto-12.6.0.tgz", "resolved": "https://registry.npmjs.org/expo-crypto/-/expo-crypto-12.6.0.tgz",
@@ -14196,6 +14217,16 @@
"expo": "*" "expo": "*"
} }
}, },
"node_modules/expo-file-system/node_modules/uuid": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",
"integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==",
"deprecated": "Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.",
"license": "MIT",
"bin": {
"uuid": "bin/uuid"
}
},
"node_modules/expo-font": { "node_modules/expo-font": {
"version": "11.1.1", "version": "11.1.1",
"resolved": "https://registry.npmjs.org/expo-font/-/expo-font-11.1.1.tgz", "resolved": "https://registry.npmjs.org/expo-font/-/expo-font-11.1.1.tgz",
@@ -14397,6 +14428,16 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/expo-linking/node_modules/uuid": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",
"integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==",
"deprecated": "Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.",
"license": "MIT",
"bin": {
"uuid": "bin/uuid"
}
},
"node_modules/expo-local-authentication": { "node_modules/expo-local-authentication": {
"version": "13.3.0", "version": "13.3.0",
"resolved": "https://registry.npmjs.org/expo-local-authentication/-/expo-local-authentication-13.3.0.tgz", "resolved": "https://registry.npmjs.org/expo-local-authentication/-/expo-local-authentication-13.3.0.tgz",
@@ -14880,6 +14921,16 @@
"node": ">= 10.0.0" "node": ">= 10.0.0"
} }
}, },
"node_modules/expo/node_modules/uuid": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",
"integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==",
"deprecated": "Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.",
"license": "MIT",
"bin": {
"uuid": "bin/uuid"
}
},
"node_modules/extend": { "node_modules/extend": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz",
@@ -29274,12 +29325,16 @@
} }
}, },
"node_modules/uuid": { "node_modules/uuid": {
"version": "3.4.0", "version": "11.0.3",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.0.3.tgz",
"integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", "integrity": "sha512-d0z310fCWv5dJwnX1Y/MncBAqGMKEzlBb1AOf7z9K8ALnd0utBX/msg/fA0+sbyN1ihbMsLhrBlnl1ak7Wa0rg==",
"deprecated": "Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.", "funding": [
"https://github.com/sponsors/broofa",
"https://github.com/sponsors/ctavan"
],
"license": "MIT",
"bin": { "bin": {
"uuid": "bin/uuid" "uuid": "dist/esm/bin/uuid"
} }
}, },
"node_modules/v8-to-istanbul": { "node_modules/v8-to-istanbul": {
@@ -40399,6 +40454,11 @@
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
"integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==" "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw=="
},
"uuid": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",
"integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A=="
} }
} }
}, },
@@ -40561,6 +40621,11 @@
"requires": { "requires": {
"has-flag": "^4.0.0" "has-flag": "^4.0.0"
} }
},
"uuid": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",
"integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A=="
} }
} }
}, },
@@ -40587,6 +40652,13 @@
"requires": { "requires": {
"@expo/config": "~8.1.0", "@expo/config": "~8.1.0",
"uuid": "^3.3.2" "uuid": "^3.3.2"
},
"dependencies": {
"uuid": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",
"integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A=="
}
} }
}, },
"expo-crypto": { "expo-crypto": {
@@ -40614,6 +40686,13 @@
"integrity": "sha512-xy61KaTaDgXhT/dllwYDHm3ch026EyO8j4eC6wSVr/yE12MMMxAC09yGwy4f7kkOs6ztGVQF5j7ldRzNLN4l0Q==", "integrity": "sha512-xy61KaTaDgXhT/dllwYDHm3ch026EyO8j4eC6wSVr/yE12MMMxAC09yGwy4f7kkOs6ztGVQF5j7ldRzNLN4l0Q==",
"requires": { "requires": {
"uuid": "^3.4.0" "uuid": "^3.4.0"
},
"dependencies": {
"uuid": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",
"integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A=="
}
} }
}, },
"expo-font": { "expo-font": {
@@ -40773,6 +40852,11 @@
"requires": { "requires": {
"has-flag": "^4.0.0" "has-flag": "^4.0.0"
} }
},
"uuid": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",
"integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A=="
} }
} }
}, },
@@ -51856,9 +51940,9 @@
"integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM="
}, },
"uuid": { "uuid": {
"version": "3.4.0", "version": "11.0.3",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.0.3.tgz",
"integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==" "integrity": "sha512-d0z310fCWv5dJwnX1Y/MncBAqGMKEzlBb1AOf7z9K8ALnd0utBX/msg/fA0+sbyN1ihbMsLhrBlnl1ak7Wa0rg=="
}, },
"v8-to-istanbul": { "v8-to-istanbul": {
"version": "9.1.0", "version": "9.1.0",

View File

@@ -103,6 +103,7 @@
"simple-pem2jwk": "^0.2.4", "simple-pem2jwk": "^0.2.4",
"telemetry-sdk": "git://github.com/mosip/sunbird-telemetry-sdk.git#f762be5732ee552c0c70bdd540aa4e2701554c71", "telemetry-sdk": "git://github.com/mosip/sunbird-telemetry-sdk.git#f762be5732ee552c0c70bdd540aa4e2701554c71",
"text-encoding": "^0.7.0", "text-encoding": "^0.7.0",
"uuid": "^11.0.3",
"xstate": "^4.35.0" "xstate": "^4.35.0"
}, },
"devDependencies": { "devDependencies": {

View File

@@ -1,7 +1,8 @@
import { VCMetadata } from './VCMetadata'; import {VCMetadata} from './VCMetadata';
import { NETWORK_REQUEST_FAILED } from './constants'; import {NETWORK_REQUEST_FAILED} from './constants';
import { groupBy } from './javascript'; import {groupBy} from './javascript';
import { Issuers } from './openId4VCI/Utils'; import {Issuers} from './openId4VCI/Utils';
import {v4 as uuid} from 'uuid';
export const getVCsOrderedByPinStatus = (vcMetadatas: VCMetadata[]) => { export const getVCsOrderedByPinStatus = (vcMetadatas: VCMetadata[]) => {
const [pinned, unpinned] = groupBy( const [pinned, unpinned] = groupBy(
@@ -54,3 +55,9 @@ export const parseJSON = (input: any) => {
export const isNetworkError = (error: string) => { export const isNetworkError = (error: string) => {
return error.includes(NETWORK_REQUEST_FAILED); return error.includes(NETWORK_REQUEST_FAILED);
}; };
export class UUID {
public static generate(): string {
return uuid();
}
}

View File

@@ -1,6 +1,5 @@
import { import {
Credential, Credential,
CredentialTypes,
VC, VC,
VcIdType, VcIdType,
VerifiableCredential, VerifiableCredential,
@@ -8,12 +7,17 @@ import {
import {Protocols} from './openId4VCI/Utils'; import {Protocols} from './openId4VCI/Utils';
import {getMosipIdentifier} from './commonUtil'; import {getMosipIdentifier} from './commonUtil';
import {VCFormat} from './VCFormat'; import {VCFormat} from './VCFormat';
import {isMosipVC} from './Utils'; import {isMosipVC, UUID} from './Utils';
import {getCredentialType} from '../components/VC/common/VCUtils'; import {getCredentialType} from '../components/VC/common/VCUtils';
const VC_KEY_PREFIX = 'VC'; const VC_KEY_PREFIX = 'VC';
const VC_ITEM_STORE_KEY_REGEX = '^VC_[a-zA-Z0-9_-]+$'; 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 { export class VCMetadata {
static vcKeyRegExp = new RegExp(VC_ITEM_STORE_KEY_REGEX); static vcKeyRegExp = new RegExp(VC_ITEM_STORE_KEY_REGEX);
idType: VcIdType | string = ''; idType: VcIdType | string = '';
@@ -111,8 +115,8 @@ export class VCMetadata {
// Update VC_ITEM_STORE_KEY_REGEX in case of changes in vckey // Update VC_ITEM_STORE_KEY_REGEX in case of changes in vckey
getVcKey(): string { getVcKey(): string {
return this.timestamp !== '' return this.timestamp !== ''
? `${VC_KEY_PREFIX}_${this.timestamp}_${this.requestId}` ? `${VC_KEY_PREFIX}_${this.timestamp}_${this.id}`
: `${VC_KEY_PREFIX}_${this.requestId}`; : `${VC_KEY_PREFIX}_${this.id}`;
} }
equals(other: VCMetadata): boolean { equals(other: VCMetadata): boolean {
@@ -124,19 +128,15 @@ export function parseMetadatas(metadataStrings: object[]) {
return metadataStrings.map(o => new VCMetadata(o)); return metadataStrings.map(o => new VCMetadata(o));
} }
export const getVCMetadata = ( export const getVCMetadata = (context: object, keyType: string) => {
context: object, const issuer = context.selectedIssuer.credential_issuer;
keyType: string, const credentialId = `${UUID.generate()}_${issuer}`;
credType: CredentialTypes,
) => {
const [issuer, protocol, credentialId] =
context.credentialWrapper?.identifier.split(':');
return VCMetadata.fromVC({ return VCMetadata.fromVC({
requestId: credentialId ?? null, requestId: credentialId,
issuer: issuer, issuer: issuer,
protocol: protocol, protocol: context.selectedIssuer.protocol,
id: `${credentialId} + '_' + ${issuer}`, id: credentialId,
timestamp: context.timestamp ?? '', timestamp: context.timestamp ?? '',
isVerified: context.vcMetadata.isVerified ?? false, isVerified: context.vcMetadata.isVerified ?? false,
isExpired: context.vcMetadata.isExpired ?? false, isExpired: context.vcMetadata.isExpired ?? false,

View File

@@ -2,34 +2,39 @@ import base64url from 'base64url';
import i18next from 'i18next'; import i18next from 'i18next';
import jwtDecode from 'jwt-decode'; import jwtDecode from 'jwt-decode';
import jose from 'node-jose'; import jose from 'node-jose';
import { NativeModules } from 'react-native'; import {NativeModules} from 'react-native';
import { vcVerificationBannerDetails } from '../../components/BannerNotificationContainer'; import {vcVerificationBannerDetails} from '../../components/BannerNotificationContainer';
import { VCProcessor } from '../../components/VC/common/VCProcessor'; import {VCProcessor} from '../../components/VC/common/VCProcessor';
import { import {
BOTTOM_SECTION_FIELDS_WITH_DETAILED_ADDRESS_FIELDS, BOTTOM_SECTION_FIELDS_WITH_DETAILED_ADDRESS_FIELDS,
DETAIL_VIEW_ADD_ON_FIELDS, DETAIL_VIEW_ADD_ON_FIELDS,
getCredentialTypeFromWellKnown, getCredentialTypeFromWellKnown,
} from '../../components/VC/common/VCUtils'; } from '../../components/VC/common/VCUtils';
import i18n from '../../i18n'; import i18n from '../../i18n';
import { displayType, issuerType } from '../../machines/Issuers/IssuersMachine'; import {displayType, issuerType} from '../../machines/Issuers/IssuersMachine';
import { getVerifiableCredential } from '../../machines/VerifiableCredential/VCItemMachine/VCItemSelectors';
import { import {
Credential, Credential,
CredentialTypes, CredentialTypes,
CredentialWrapper, CredentialWrapper,
VerifiableCredential, VerifiableCredential,
} from '../../machines/VerifiableCredential/VCMetaMachine/vc'; } from '../../machines/VerifiableCredential/VCMetaMachine/vc';
import getAllConfigurations, { CACHED_API } from '../api'; import getAllConfigurations, {CACHED_API} from '../api';
import { isIOS } from '../constants'; import {isIOS} from '../constants';
import { getJWT } from '../cryptoutil/cryptoUtil'; import {getJWT} from '../cryptoutil/cryptoUtil';
import { KeyTypes } from '../cryptoutil/KeyTypes'; import {isMockVC} from '../Utils';
import { UnsupportedVcFormat } from '../error/UnsupportedVCFormat'; import {
import { TelemetryConstants } from '../telemetry/TelemetryConstants'; VerificationErrorMessage,
import { getErrorEventData, sendErrorEvent } from '../telemetry/TelemetryUtils'; VerificationErrorType,
import { isMockVC } from '../Utils'; verifyCredential,
import { VCFormat } from '../VCFormat'; } from '../vcjs/verifyCredential';
import { VerificationErrorMessage, VerificationErrorType, verifyCredential } from '../vcjs/verifyCredential'; import {getVerifiableCredential} from '../../machines/VerifiableCredential/VCItemMachine/VCItemSelectors';
import { VCMetadata } from '../VCMetadata'; import {getErrorEventData, sendErrorEvent} from '../telemetry/TelemetryUtils';
import {TelemetryConstants} from '../telemetry/TelemetryConstants';
import {KeyTypes} from '../cryptoutil/KeyTypes';
import {VCFormat} from '../VCFormat';
import {UnsupportedVcFormat} from '../error/UnsupportedVCFormat';
import {VCMetadata} from '../VCMetadata';
import {UUID} from '../Utils';
export const Protocols = { export const Protocols = {
OpenId4VCI: 'OpenId4VCI', OpenId4VCI: 'OpenId4VCI',
@@ -65,31 +70,6 @@ export const isActivationNeeded = (issuer: string) => {
export const Issuers_Key_Ref = 'OpenId4VCI_KeyPair'; export const Issuers_Key_Ref = 'OpenId4VCI_KeyPair';
export const getIdentifier = (
context,
credential: VerifiableCredential,
format: string,
) => {
let credentialIdentifier = '';
if (format === VCFormat.mso_mdoc) {
credentialIdentifier = credential?.processedCredential?.['id'] ?? '';
} else if (typeof credential.credential !== 'string') {
credentialIdentifier = credential.credential.id;
}
const credId =
credentialIdentifier.startsWith('did') ||
credentialIdentifier.startsWith('urn:')
? credentialIdentifier.split(':')
: credentialIdentifier.split('/');
return (
context.selectedIssuer.issuer_id +
':' +
context.selectedIssuer.protocol +
':' +
credId[credId.length - 1]
);
};
export const updateCredentialInformation = async ( export const updateCredentialInformation = async (
context, context,
credential: VerifiableCredential, credential: VerifiableCredential,
@@ -113,11 +93,6 @@ export const updateCredentialInformation = async (
return { return {
verifiableCredential, verifiableCredential,
format: context.selectedCredentialType.format, format: context.selectedCredentialType.format,
identifier: getIdentifier(
context,
verifiableCredential,
context.selectedCredentialType.format,
),
generatedOn: new Date(), generatedOn: new Date(),
vcMetadata: { vcMetadata: {
...context.vcMetadata, ...context.vcMetadata,
@@ -448,12 +423,14 @@ export function getMatchingCredentialIssuerMetadata(
export async function verifyCredentialData( export async function verifyCredentialData(
credential: Credential, credential: Credential,
credentialFormat: string, credentialFormat: string,
issuerId: string issuerId: string,
) { ) {
if (credentialFormat === VCFormat.mso_mdoc || !isMockVC(issuerId)) { if (credentialFormat === VCFormat.mso_mdoc || !isMockVC(issuerId)) {
const verificationResult = await verifyCredential(credential, credentialFormat); const verificationResult = await verifyCredential(
credential,
credentialFormat,
);
return verificationResult; return verificationResult;
} else { } else {
return { return {
@@ -462,4 +439,4 @@ export async function verifyCredentialData(
verificationErrorCode: VerificationErrorType.NO_ERROR, verificationErrorCode: VerificationErrorType.NO_ERROR,
}; };
} }
} }