A TypeScript library providing core utilities and modules for OID4VC (OpenID for Verifiable Credentials) implementations.
npm install @vecrea/oid4vc-coreA TypeScript library providing core utilities and modules for OID4VC (OpenID for Verifiable Credentials) implementations.
- Utility Functions: Error handling and result management utilities
- DynamoDB Integration: Simplified DynamoDB operations with Cloudflare Workers compatibility
- TypeScript Support: Full TypeScript support with comprehensive type definitions
- Modular Design: Import only what you need with subpath exports
``bash`
npm install @vecrea/oid4vc-core
Error handling and result management utilities.
`typescript
import {
Result,
runCatching,
getErrorMessage,
convertToError,
} from '@vecrea/oid4vc-core/utils';
// Using Result for safe operations
const result = runCatching(() => {
// Your potentially throwing code here
return 'success';
});
if (result.isSuccess()) {
console.log(result.value); // 'success'
} else {
console.error(result.error.message);
}
// Error utilities
const message = getErrorMessage(new Error('Test error')); // 'Test error'
const error = convertToError('Something went wrong');
`
Simplified DynamoDB operations with Cloudflare Workers compatibility.
`typescript
import { DynamoDB } from '@vecrea/oid4vc-core/dynamodb';
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
// Initialize
const client = new DynamoDBDocumentClient({ region: 'us-east-1' });
const dynamodb = new DynamoDB(client, 'your-table-name');
// Basic operations
await dynamodb.put('user:123', JSON.stringify({ name: 'John', age: 30 }));
const userData = await dynamodb.get('user:123');
await dynamodb.delete('user:123');
`
A monadic Result type for handling operations that can succeed or fail.
#### Static Methods
- Result.success - Creates a successful resultResult.failure
- - Creates a failure result
#### Instance Methods
- isSuccess(): this is { value: T } - Checks if the result is successfulisFailure(): this is { error: Error }
- - Checks if the result is a failuregetOrThrow(): T
- - Returns the value or throws the errorgetOrDefault(defaultValue: T): T
- - Returns the value or a defaultgetOrElse(transfer: (error: Error) => T): T
- - Returns the value or a computed defaultonSuccess(f: (value: T) => void): Result
- - Executes a function on successonFailure(f: (error: Error) => void): Result
- - Executes a function on failurerecover(transform: (error: Error) => T): Result
- - Recovers from failurerecoverAsync(transform: (error: Error) => Promise
- - Async recovery
- runCatching - Safely executes a functionrunAsyncCatching
- - Safely executes an async functiongetErrorMessage(e: unknown): string
- - Converts any value to an error messageconvertToError(e: unknown): Error
- - Converts any value to an Error object
A class for simplified DynamoDB operations.
#### Constructor
`typescript`
constructor(client: DynamoDBDocumentClient, tableName: string)
#### Methods
- get(key: string): Promise - Retrieves a value by keyput(key: string, value: string, options?: PutOptions): Promise
- - Stores a valuedelete(key: string): Promise
- - Deletes an item by key
#### Types
- DynamoDBItem - Interface for DynamoDB itemsPutOptions
- - Options for put operations, extending KVNamespacePutOptions
- Node.js 18+
- npm or yarn
`bash`
git clone
cd oid4vc-core
npm install
- npm run build - Build the librarynpm test
- - Run tests
The library uses Vitest for testing. Test files are located in __tests__ directories alongside the source files.
`bash``
npm test
MIT License - see LICENSE file for details.
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests for new functionality
5. Run the test suite
6. Submit a pull request
For issues and questions, please use the GitHub issue tracker.