@mosip/react-inji-verify-sdk 0.14.0-beta.8 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Readme.md CHANGED
@@ -1,275 +1,236 @@
1
1
  # INJI VERIFY SDK
2
2
 
3
- Inji Verify SDK is a library which exposes React components for integrating Inji Verify features seamlessly into any relaying party application.
3
+ Inji Verify SDK provides ready-to-use **React components** to integrate [OpenID4VP](https://openid.net/specs/openid-4-verifiable-presentations-1_0.html)-based **Verifiable Credential (VC) and Verifiable Presentation (VP) verification** into any React TypeScript web application.
4
4
 
5
- ## Features
6
5
 
7
- - OpenId4VP component that creates QR code and performs OpenId4Vp sharing backend flow.
6
+ ## Usage Guide
8
7
 
9
- ## Usage
10
- `npm i @mosip/react-inji-verify-sdk`
11
-
12
- [npm](https://www.npmjs.com/package/@mosip/react-inji-verify-sdk)
13
-
14
- ## Local Publishing Guide
15
-
16
- Install the dependencies
17
- `npm install`
18
-
19
- Build the project
20
- `npm run build`
21
-
22
- Publish the npm package using Verdaccio
23
- We use [verdaccio](https://verdaccio.org/docs/what-is-verdaccio). `npm link` or `yarn link` won't work as we have peer dependencies. Follow the docs to setup Verdaccio. Then run
24
- `npm publish --registry http://localhost:<VERADACCIO_PORT>`
25
-
26
- ## Integration Guide
27
-
28
- ### OpenID4VPVerification
29
-
30
- This guide walks you through integrating the OpenID4VPVerification component into your React TypeScript project. It facilitates Verifiable Presentation (VP) verification using the OpenID4VP protocol and supports flexible workflows, including client-side and backend-to-backend verification.
31
-
32
- #### Prerequisites
33
-
34
- - Ract Project Setup
35
-
36
- > **NOTE**
37
- The component does not support other frontend frameworks like Angular, Vue, or React Native.
38
- The component is written in React + TypeScript
8
+ ### Step 1: Install the Package
9
+ ```bash
10
+ npm i @mosip/react-inji-verify-sdk
11
+ ```
39
12
 
13
+ ### Step 2: Import and Use
14
+ ```javascript
15
+ import { OpenID4VPVerification, QRCodeVerification } from "@mosip/react-inji-verify-sdk";
16
+ ```
40
17
 
41
- #### Backend Requirements
18
+ ### Step 3: Choose Your Verification Method
42
19
 
43
- To use the component, you must host a verification backend that implements the OpenID4VP protocol. This backend is referred to as the [inji-verify-service]("../Readme.md"). It also needs to adehere to the OpenAPI spec defined [here]("../docs/api-documentation-openapi.yaml") in case if the backend service is not inji-verify-service.
20
+ **Option A: QR Code Verification (Scan & Upload)**
21
+ ```javascript
22
+ function MyApp() {
23
+ return (
24
+ <QRCodeVerification
25
+ verifyServiceUrl="https://your-backend.com/verify"
26
+ onVCProcessed={(result) => {
27
+ console.log("Verification complete:", result);
28
+ // Handle the verification result here
29
+ }}
30
+ onError={(error) => {
31
+ console.log("Something went wrong:", error);
32
+ }}
33
+ triggerElement={<button>📷 Scan ID Document</button>}
34
+ />
35
+ );
36
+ }
37
+ ```
44
38
 
45
- > ⚠️ Important: The component expects these endpoints to be accessible via a base URL (verifyServiceUrl).
46
- Example:
47
- If you deploy the inji-verify/verify-service at:
48
- https://injiverify-service.example.com
49
- Then use this as the verifyServiceUrl in the component:
50
- verifyServiceUrl="https://injiverify-service.example.com/v1/verify"
39
+ **Option B: OpenID4VP Verification**
40
+ ```javascript
41
+ function MyApp() {
42
+ return (
43
+ <OpenID4VPVerification
44
+ verifyServiceUrl="https://your-backend.com/v1/verify"
45
+ presentationDefinitionId="your-definition-id"
46
+ onVpProcessed={(result) => {
47
+ console.log("Wallet verification complete:", result);
48
+ // Handle the verification result here
49
+ }}
50
+ onQrCodeExpired={() => alert("QR code expired, please try again")}
51
+ onError={(error) => console.log("Error:", error)}
52
+ triggerElement={<button>📱 Verify with Digital Wallet</button>}
53
+ />
54
+ );
55
+ }
56
+ ```
51
57
 
52
- #### Installation
58
+ ## Response Received
53
59
 
54
- `npm i @mosip/react-inji-verify-sdk`
60
+ When verification is completed, the response received is as below:
55
61
 
56
- #### Component Props
62
+ ```javascript
63
+ {
64
+ vcResults: [
65
+ {
66
+ vc: { /* Your verified credential data */ },
67
+ vcStatus: "SUCCESS" // or "INVALID", "EXPIRED"
68
+ }
69
+ ],
70
+ vpResultStatus: "SUCCESS" // Overall verification status
71
+ }
72
+ ```
73
+ >**Security Recommendation**
74
+ >
75
+ >Avoid consuming results directly from VPProcessed or VCProcessed.
76
+ Instead, use VPReceived or VCReceived events to capture the txnId, then retrieve the verification results securely from your backend's verification service endpoint.
77
+ This ensures data integrity and prevents reliance on client-side verification data for final decisions.
57
78
 
58
- ##### Exclusive Verification Flows
59
- <br/>
60
- > Only one of the following should be provided:
79
+ ## Pre-requisites
61
80
 
81
+ ### What You Need:
82
+ 1. **A React project** (TypeScript recommended)
83
+ 2. **A verification backend** - You need a server that can verify credentials
84
+ 3. **Camera permissions** - For QR scanning features
62
85
 
63
- | Prop | Description |
64
- |----------------------------------------------|---------------------------------------------------|
65
- | `onVPReceived(txnId: string)` | Use when your backend fetches the VP result later |
66
- | `onVPProcessed(vpResult: VerificationResults)` | Use when the frontend needs the result directly |
86
+ ### Backend Requirements:
87
+ Your backend must support the OpenID4VP protocol. You can either:
88
+ - Use the official `inji-verify-service`
89
+ - Build your own following [this specification](https://openid.net/specs/openid-4-verifiable-presentations-1_0-ID3.html)
67
90
 
68
- ##### Presentation Definition Options
69
- <br/>
70
- > Only one of the following should be provided:
91
+ **Important:** Your backend URL should look like:
92
+ ```
93
+ https://your-backend.com
94
+ ```
71
95
 
72
- | Prop | Description |
73
- |----------------------------------------------|---------------------------------------------------|
74
- | `presentationDefinitionId` | Fetch a predefined definition from the backend |
75
- | `presentationDefinition` | Provide the full definition inline as a JSON object |
96
+ ## 📖 Detailed Component Guide
76
97
 
98
+ ### QRCodeVerification Component
77
99
 
78
- ##### Required Props
79
- <br/>
100
+ **Perfect for:** Scanning QR codes from documents or uploading QR codes (PNG, JPEG, JPG, PDF)
80
101
 
81
- | Prop | Type | Description |
82
- |------------------|----------------------|----------------------------------------|
83
- | `verifyServiceUrl` | `string` | Base URL for your verification backend |
84
- | `protocol` | `string` | Protocol for QR (e.g.: `"openid4vp://"`) |
85
- | `onQrCodeExpired` | `() => void` | Callback when QR expires |
86
- | `onError` | `(err: Error) => void` | Error handler callback |
102
+ #### Basic Setup:
103
+ ```javascript
104
+ <QRCodeVerification
105
+ verifyServiceUrl="https://your-backend.com"
106
+ onVCProcessed={(result) => handleResult(result)}
107
+ onError={(error) => handleError(error)}
108
+ triggerElement={<button>Start Verification</button>}
109
+ />
110
+ ```
87
111
 
88
- ##### Optional Props
89
- <br/>
112
+ #### All Available Options:
113
+ ```javascript
114
+ <QRCodeVerification
115
+ // Required
116
+ verifyServiceUrl="https://your-backend.com"
117
+ onVCProcessed={(result) => console.log(result)} // OR use onVCReceived
118
+ onError={(error) => console.log(error)}
119
+
120
+ // Optional
121
+ triggerElement={<button>Custom Trigger</button>}
122
+ transactionId="your-tracking-id" //Optional
123
+ uploadButtonId="my-upload-btn"
124
+ uploadButtonStyle={{ backgroundColor: 'blue' }}
125
+ isEnableUpload={true} // Allow file uploads
126
+ isEnableScan={true} // Allow camera scanning
127
+ isEnableZoom={true} // Allow camera zoom
128
+ />
129
+ ```
90
130
 
91
- | Prop | Type | Description |
92
- |----------------|-----------------|-----------------------------------------------------|
93
- | `triggerElement` | `React.ReactNode` | Element that triggers verification (e.g., a button) |
94
- | `transactionId` | `string` | Optional external tracking ID |
95
- | `qrCodeStyles` | `object` | Customize QR appearance (size, color, margin, etc.) |
131
+ **Choose One Callback:**
132
+ - `onVCProcessed`: Get full verification results immediately
133
+ - `onVCReceived`: Get just a transaction ID (your backend handles the rest)
96
134
 
97
- #### Integration Examples
135
+ ### OpenID4VPVerification Component
98
136
 
99
- ##### VP Result via UI (frontend receives result)
100
- <br/>
137
+ **Perfect for:** Integrating with digital wallets (like mobile ID apps)
101
138
 
102
- ```
139
+ #### Basic Setup:
140
+ ```javascript
103
141
  <OpenID4VPVerification
104
- triggerElement={<button>Start VP Verification</button>}
105
- protocol="openid4vp://"
106
- verifyServiceUrl="https://verifier.example.com/v1/verify"
107
- presentationDefinitionId="example-definition-id"
108
- onVPProcessed={(vpResult) => {
109
- console.log("VP Verified:", vpResult);
110
- }}
111
- onQrCodeExpired={() => alert("QR expired")}
112
- onError={(err) => console.error("Verification error:", err)}
142
+ verifyServiceUrl="https://your-backend.com"
143
+ presentationDefinitionId="what-you-want-to-verify"
144
+ onVpProcessed={(result) => handleResult(result)}
145
+ onQrCodeExpired={() => alert("Please try again")}
146
+ onError={(error) => handleError(error)}
113
147
  />
114
148
  ```
115
149
 
116
- ##### VP Result via Backend (frontend just gets txnId)
117
- <br/>
118
-
119
- ```
150
+ #### With Presentation Definition:
151
+ ```javascript
120
152
  <OpenID4VPVerification
121
- triggerElement={<button>Verify using Wallet</button>}
122
- protocol="openid4vp://"
123
- verifyServiceUrl="https://verifier.example.com/v1/verify"
124
- presentationDefinition={{
125
- id: "custom-def",
126
- input_descriptors: [/* your PD here */],
127
- }}
128
- onVPReceived={(txnId) => {
129
- // Send txnId to your backend to fetch the result later
130
- console.log("VP submission received, txn ID:", txnId);
131
- }}
153
+ verifyServiceUrl="https://your-backend.com"
154
+ presentationDefinition={"Refer Option 2 below"}
155
+ onVpProcessed={(result) => console.log(result)}
132
156
  onQrCodeExpired={() => alert("QR expired")}
133
- onError={(err) => console.error("Verification error:", err)}
157
+ onError={(error) => console.error(error)}
158
+ triggerElement={<button>🔐 Verify Credentials</button>}
134
159
  />
135
160
  ```
136
161
 
137
- #### Testing the Component (for QA)
138
-
139
- - **Simulate Wallet Scan** : Use a mobile wallet app that supports OpenID4VP, or use mock tools to scan the QR code.
140
-
141
- - **Trigger Expiry** : Don't scan the QR and wait for expiry to ensure onQrCodeExpired fires.
142
-
143
- - **Force Errors** :
144
- - Stop the backend or simulate a 500 error.
145
- - Try missing required props or using both callbacks to see validation.
146
-
147
- ### QRCodeVerification
148
-
149
- This guide walks you through integrating the QRCodeVerification component into your React TypeScript project. It facilitates QR code scanning and image upload to verify Verifiable Credentials (VCs) in your React application, including client-side and backend-to-backend verification.
150
-
151
- #### Component Props
152
- ✅ Required Props
153
- <br/>
154
-
155
- | Prop | Type | Description |
156
- |--------|------| ------------|
157
- | `verifyServiceUrl` | string | Backend service URL for VC submission or verification.|
158
- | `onError` | (error: Error) => void | Callback triggered on errors during scanning/upload.|
159
- |`onVCReceived or onVCProcessed` | See below |See below
160
-
161
- Only one of these callbacks should be provided.
162
-
163
- #### 📌 Callback Types
164
- Use one of the following:
165
-
166
- ##### onVCReceived
162
+ #### Define What to Verify:
167
163
 
168
- ```onVCReceived: (txnId: string) => void; ```
169
-
170
- Called when a Verifiable Presentation (VP) is received and submitted to the backend, returning the transaction ID
171
-
172
- ##### onVCProcessed
173
-
174
- ``` onVCProcessed: (vpResult: VerificationResults) => void; ```
175
-
176
- Called when the VP is verified, returning an array of verification result objects:
177
-
178
- ```type VerificationResult = { vc: unknown; vcStatus: "SUCCESS" | "INVALID" | "EXPIRED"; }; ```
179
-
180
- ``` type VerificationResults = VerificationResult[]; ```
181
-
182
- **⚠️ onVCReceived and onVCProcessed cannot be used simultaneously.**
183
-
184
- #### 🛠️ Optional Props
185
- <br/>
186
-
187
- | Prop | Type | Default | Description |
188
- |------------------|--------------------|-----------------|-----------------------------------------------------|
189
- | `triggerElement` | `React.ReactNode` | null | Optional trigger to initiate the scan/upload (e.g., a button or label). |
190
- | `transactionId` | string | null | Optional external tracking ID |
191
- | `uploadButtonId` | `string` | "upload-qr" | Custom ID for upload button. |
192
- | `uploadButtonStyle` | `React.CSSProperties` | "upload-button-default" | Inline style object to apply custom styling to the upload button. |
193
- | `isEnableUpload` | boolean | true | Enables/disables QR-CODE image upload. |
194
- | `isEnableScan` | boolean | true | Enables/disables camera scanning. |
195
- | `isEnableZoom` | boolean | true | Enables camera zoom on mobile devices. |
196
-
197
- #### Upload Support
198
- Upload supports the following image types:
199
-
200
- - PNG
201
-
202
- - JPEG
203
-
204
- - JPG
205
-
206
- - PDF
207
-
208
- You can customize the upload button’s style using uploadButtonStyle, and control its placement with uploadButtonId.
209
-
210
- #### Callback Behaviour
211
-
212
- **onVCReceived** : Used when you want the VC sent to a backend and just need a txnId response.
213
-
214
- **onVCProcessed** : Used for apps that handle VC verification client-side and want full VC + status.
215
-
216
- **onError** : Handles all runtime, parsing, and scanning errors.
217
-
218
- The component will clean up camera streams and timers on unmount.
219
-
220
- #### Example with onVCProcessed
221
-
222
- ```
223
- <QRCodeVerification
224
- verifyServiceUrl="https://your-api/verify"
225
- onVCProcessed={(vpResult) => { console.log("VC + Status:", vpResult)}}
226
- onError={(e) => console.error("Error:", e.message)}
227
- triggerElement={<div className="btn-primary">Verify Now</div>}
228
- />
164
+ **Option 1: Use a predefined template**
165
+ ```javascript
166
+ presentationDefinitionId="drivers-license-check"
229
167
  ```
230
168
 
231
- #### Basic Usage
232
-
169
+ **Option 2: Define exactly what you want**
170
+ ```javascript
171
+ presentationDefinition={{
172
+ id: "custom-verification",
173
+ purpose: "We need to verify your identity",
174
+ format: {
175
+ ldp_vc: {
176
+ proof_type: ["Ed25519Signature2020"],
177
+ },
178
+ },
179
+ input_descriptors: [
180
+ {
181
+ id: "id-card-check",
182
+ constraints: {
183
+ fields: [
184
+ {
185
+ path: ["$.type"],
186
+ filter: {
187
+ type: "object",
188
+ pattern: "DriverLicenseCredential",
189
+ },
190
+ },
191
+ ],
192
+ },
193
+ },
194
+ ],
195
+ }}
233
196
  ```
234
- import {QRCodeVerification} from "@mosip/react-inji-verify-sdk";
235
- const App = () => {
236
- const handleVCReceived = (txnId: string) => {
237
- console.log("txnId received from VC submission:", txnId);
238
- };
239
- const handleError = (error: Error) => {
240
- console.error("Verification Error:", error.message);
241
- };
242
- return (
243
- <QRCodeVerification
244
- verifyServiceUrl="https://your-backend/verify"
245
- onVCReceived={handleVCReceived}
246
- onError={handleError}
247
- triggerElement={<button>Start Verification</button>}
248
- />
249
- );
250
- };
251
- ```
252
-
253
- #### Redirect Behavior
254
- When using Online Share QR Code, the user is redirected to the client (issuer) server for processing, and then sent back to the RP’s root path (/) with the vp_token in the URL fragment:
255
-
256
-
257
- ```
258
- https://your-rp-domain.com/#vp_token=<base64url-encoded-token>
259
- ```
260
-
261
- ### Compatibility & Scope
262
-
263
- ##### Supported
264
-
265
- - ✅ ReactJS (with TypeScript)
266
-
267
- - ✅ Modern React projects (17+)
268
-
269
- ##### Not Supported
270
-
271
- - ❌ React Native
272
-
273
- - ❌ Angular, Vue, or other frontend frameworks
274
197
 
275
- - SSR frameworks like Next.js without customization
198
+ ## 🎛️ Component Options Reference
199
+
200
+ ### Common Props (Both Components)
201
+
202
+ | Property | Type | Required | Description |
203
+ |--------------------|---------------|----------|---------------------------------------------|
204
+ | `verifyServiceUrl` | string | ✅ | Your backend verification URL |
205
+ | `onError` | function | ✅ | What to do when something goes wrong |
206
+ | `triggerElement` | React element | ❌ | Custom button/element to start verification |
207
+ | `transactionId` | string | ❌ | Your own tracking ID |
208
+
209
+ ### QRCodeVerification Specific
210
+
211
+ | Property | Type | Default | Description |
212
+ |---------------------|----------|---------|------------------------------|
213
+ | `onVCProcessed` | function | - | Get full results immediately |
214
+ | `onVCReceived` | function | - | Get transaction ID only |
215
+ | `isEnableUpload` | boolean | true | Allow file uploads |
216
+ | `isEnableScan` | boolean | true | Allow camera scanning |
217
+ | `isEnableZoom` | boolean | true | Allow camera zoom |
218
+ | `uploadButtonStyle` | object | - | Custom upload button styling |
219
+
220
+ ### OpenID4VPVerification Specific
221
+
222
+ | Property | Type | Default | Description |
223
+ |----------------------------|----------|----------------|------------------------------------|
224
+ | `protocol` | string | "openid4vp://" | Protocol for QR codes (optional) |
225
+ | `presentationDefinitionId` | string | - | Predefined verification template |
226
+ | `presentationDefinition` | object | - | Custom verification rules |
227
+ | `onVpProcessed` | function | - | Get full results immediately |
228
+ | `onVpReceived` | function | - | Get transaction ID only |
229
+ | `onQrCodeExpired` | function | - | Handle QR code expiration |
230
+ | `isEnableSameDeviceFlow` | boolean | true | Enable same-device flow (optional) |
231
+ | `qrCodeStyles` | object | - | Customize QR code appearance |
232
+
233
+ ## ⚠️ Important Limitations
234
+
235
+ - **React Only:** Won't work with Angular, Vue, or React Native
236
+ - **Backend Required:** You must have a verification service running
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
2
  import { OpenID4VPVerificationProps } from "./OpenID4VPVerification.types";
3
+ import "./OpenID4VPVerification.css";
3
4
  declare const OpenID4VPVerification: React.FC<OpenID4VPVerificationProps>;
4
5
  export default OpenID4VPVerification;
@@ -40,11 +40,6 @@ export interface VPRequestBody {
40
40
  presentationDefinitionId?: string;
41
41
  presentationDefinition?: PresentationDefinition;
42
42
  }
43
- export interface Wallet {
44
- name: string;
45
- scheme: string;
46
- icon: string;
47
- }
48
43
  type ExclusivePresentationDefinition =
49
44
  /**
50
45
  * ID of the presentation definition used for verification.
@@ -79,14 +74,6 @@ type ExclusiveCallbacks =
79
74
  onVPProcessed: (VPResult: VerificationResults) => void;
80
75
  onVPReceived?: never;
81
76
  };
82
- type SameDeviceFlowEnabledProps = {
83
- isEnableSameDeviceFlow: true;
84
- supportedWallets: Wallet[];
85
- };
86
- type SameDeviceFlowDisabledProps = {
87
- isEnableSameDeviceFlow?: false | undefined;
88
- supportedWallets?: Wallet[];
89
- };
90
77
  interface InputDescriptor {
91
78
  id: string;
92
79
  format?: {
@@ -106,7 +93,7 @@ export interface PresentationDefinition {
106
93
  };
107
94
  input_descriptors: InputDescriptor[];
108
95
  }
109
- type BaseProps = ExclusivePresentationDefinition & ExclusiveCallbacks & {
96
+ export type OpenID4VPVerificationProps = ExclusivePresentationDefinition & ExclusiveCallbacks & {
110
97
  /**
111
98
 
112
99
  React element that triggers the verification process (e.g., a button).
@@ -120,9 +107,9 @@ type BaseProps = ExclusivePresentationDefinition & ExclusiveCallbacks & {
120
107
  */
121
108
  verifyServiceUrl: string;
122
109
  /**
123
-
124
- The client identifier for relaying party.
125
- */
110
+
111
+ The client identifier for relaying party.
112
+ */
126
113
  clientId: string;
127
114
  /**
128
115
 
@@ -135,6 +122,11 @@ type BaseProps = ExclusivePresentationDefinition & ExclusiveCallbacks & {
135
122
  */
136
123
  transactionId?: string;
137
124
  /**
125
+ Indicates whether the same device flow is enabled.
126
+ Defaults to true, allowing verification on the same device.
127
+ */
128
+ isEnableSameDeviceFlow?: boolean;
129
+ /**
138
130
 
139
131
  Styling options for the QR code.
140
132
  */
@@ -156,5 +148,4 @@ type BaseProps = ExclusivePresentationDefinition & ExclusiveCallbacks & {
156
148
  */
157
149
  onError: (error: Error) => void;
158
150
  };
159
- export type OpenID4VPVerificationProps = (BaseProps & SameDeviceFlowEnabledProps) | (BaseProps & SameDeviceFlowDisabledProps);
160
151
  export {};
@@ -56,6 +56,8 @@ export type QRCodeVerificationProps = ExclusiveCallbacks & {
56
56
  * Defaults to true.
57
57
  */
58
58
  isEnableScan?: boolean;
59
+ onClose?: () => void;
60
+ scannerActive?: boolean;
59
61
  };
60
62
  interface VerificationResult {
61
63
  /**