@mosip/react-inji-verify-sdk
Version:
A react component library to perform Inji verify tasks, such as OpenId4VP sharing, Reading VC QR codes
145 lines (136 loc) • 3.61 kB
TypeScript
/// <reference types="react" />
export type OpenID4VPError = {
message: string;
code?: string;
details?: unknown;
};
export type VerificationStatus = "success" | "invalid" | "expired";
type vpResultStatus = "SUCCESS" | "FAILED";
export interface VerificationResult {
/**
Verified credential data (structured per implementation).
*/
vc: Record<string, unknown>;
/**
The status of the verification.
*/
vcStatus: VerificationStatus;
}
export interface VerificationResults {
vcResults: VerificationResult[];
vpResultStatus: vpResultStatus;
}
export interface QrData {
transactionId: string;
requestId: string;
authorizationDetails: {
responseType: string;
clientId: string;
presentationDefinition: Record<string, unknown>;
presentationDefinitionUri?: string;
responseUri: string;
nonce: string;
iat: number;
};
expiresAt: number;
}
export interface VPRequestBody {
clientId: string;
nonce: string;
transactionId?: string;
presentationDefinitionId?: string;
presentationDefinition?: PresentationDefinition;
}
type ExclusivePresentationDefinition =
/**
* ID of the presentation definition used for verification.
* Required for some verification flows.
*/
{
presentationDefinitionId: string;
presentationDefinition?: never;
}
/**
* The full presentation definition JSON string.
* If provided, it will be used instead of fetching from the backend.
*/
| {
presentationDefinition?: PresentationDefinition;
presentationDefinitionId?: never;
};
type ExclusiveCallbacks =
/**
* Callback triggered when the verification presentation (VP) is received.
* Provides the associated transaction ID.
*/
{
onVPReceived: (transactionId: string) => void;
onVPProcessed?: never;
}
/**
* Callback triggered when the VP is successfully processed.
* Provides the verification result data.
*/
| {
onVPProcessed: (vpResult: VerificationResults) => void;
onVPReceived?: never;
};
interface InputDescriptor {
id: string;
format?: {
ldp_vc: {
proof_type: string[];
};
};
constraints?: {};
}
interface PresentationDefinition {
id?: string;
purpose: string;
format?: {
ldp_vc: {
proof_type: string[];
};
};
input_descriptors: InputDescriptor[];
}
export type OpenID4VPVerificationProps = ExclusivePresentationDefinition & ExclusiveCallbacks & {
/**
React element that triggers the verification process (e.g., a button).
If not provided, the component may automatically start the process.
*/
triggerElement?: React.ReactNode;
/**
The backend service URL where the verification request will be sent.
*/
verifyServiceUrl: string;
/**
The protocol being used for verification (e.g., OpenID4VP).
*/
protocol?: string;
/**
A unique identifier for the transaction.
*/
transactionId?: string;
/**
Styling options for the QR code.
*/
qrCodeStyles?: {
size?: number;
level?: "L" | "M" | "Q" | "H";
bgColor?: string;
fgColor?: string;
margin?: number;
borderRadius?: number;
};
/**
* Callback triggered when the QR code expires before verification is completed.
*/
onQrCodeExpired: () => void;
/**
* Callback triggered when an error occurs during the verification process.
* This is a required field to ensure proper error handling.
*/
onError: (error: Error) => void;
};
export {};