@vecrea/oid4vc-prex
v0.1.0
Published
A TypeScript library for handling OpenID for Verifiable Credentials (OID4VC) Presentation Exchange operations
Maintainers
Readme
OID4VC Presentation Exchange Library
A TypeScript library for handling OpenID for Verifiable Credentials (OID4VC) Presentation Exchange operations, providing comprehensive support for Presentation Definitions and Presentation Submissions according to the Presentation Exchange specification.
Features
- Presentation Definition Support: Full implementation of Presentation Definition types and validation
- Presentation Submission Handling: Parse and validate Presentation Submissions from various embed locations
- JSON Path Operations: Utilities for JSON Path validation and extraction
- Type Safety: Complete TypeScript support with comprehensive type definitions
- Multiple Embed Locations: Support for JWT, OIDC, DIDComms, VP, and CHAPI embed locations
Installation
npm install @vecrea/oid4vc-prexQuick Start
import { PresentationExchange, JsonPathOps } from '@vecrea/oid4vc-prex';
// Parse a Presentation Submission
const jsonString = '{"presentation_submission": {...}}';
const result =
await PresentationExchange.jsonParse.decodePresentationSubmission(jsonString);
if (result.isSuccess()) {
const submission = result.value;
console.log('Submission ID:', submission.id);
} else {
console.error('Failed to parse:', result.error);
}
// Validate JSON Path
const isValid = JsonPathOps.isValid('$.credential.credentialSubject.id');
console.log('Is valid JSON Path:', isValid);
// Extract data using JSON Path
const jsonData =
'{"credential": {"credentialSubject": {"id": "did:example:123"}}}';
const extracted = JsonPathOps.getJsonAtPath(
'$.credential.credentialSubject.id',
jsonData
);
console.log('Extracted value:', extracted);API Reference
PresentationExchange
The main entry point for the library.
jsonParse.decodePresentationSubmission(input)
Parses a Presentation Submission from a JSON string or ReadableStream.
Parameters:
input:string | ReadableStream<Uint8Array>- The JSON input
Returns: Promise<Result<PresentationSubmission>>
Example:
const result =
await PresentationExchange.jsonParse.decodePresentationSubmission(jsonString);JsonPathOps
Utility class for JSON Path operations.
JsonPathOps.isValid(path)
Validates if a string is a valid JSON Path.
Parameters:
path:string- The JSON Path to validate
Returns: boolean
JsonPathOps.getJsonAtPath(jsonPath, jsonString)
Extracts data from JSON using a JSON Path.
Parameters:
jsonPath:string- The JSON Path expressionjsonString:string- The JSON string to extract from
Returns: string - The extracted value as a JSON string
Types
The library exports comprehensive TypeScript types for all Presentation Exchange components:
JSONSchema- JSON Schema type alias for version 7Constraints- Constraint definitions for input descriptorsDescriptorMap- Descriptor mapping specificationsFieldConstraint- Field-level constraint definitionsFilter- Filter specifications for credential filteringFormat- Format definitions for credential formatsFrom- Source specification for credentialsGroup- Group definitions for organizing input descriptorsId- Identifier typesInputDescriptor- Input descriptor specificationsInputDescriptorId- Input descriptor identifier typesJsonObject- JSON object type definitionsJsonPath- JSON Path type definitionsName- Name type definitionsNonEmptySet- Non-empty set type definitionsPresentationDefinition- Core presentation definition structurePresentationSubmission- Presentation submission dataPurpose- Purpose definitions for input descriptorsRule- Rule definitions for constraintsSubmissionRequirement- Submission requirement specifications
Embed Locations
The library supports parsing Presentation Submissions from various embed locations:
- JWT: Embedded in JWT tokens
- OIDC: Embedded in OpenID Connect flows
- DIDComms: Embedded in DID Communication messages
- VP: Embedded in Verifiable Presentations
- CHAPI: Embedded in Credential Handler API responses
Development
Prerequisites
- Node.js 18+
- npm or yarn
Setup
npm installBuild
npm run buildTesting
npm testType Checking
npm run typecheckLinting
npm run lintLicense
Licensed under the Apache License, Version 2.0. See the LICENSE file for details.
Contributing
This project follows the Presentation Exchange specification. When contributing, please ensure compliance with the specification and maintain type safety.
