verifiable-credentials-utils
v1.5.1
Published
This project provides a set of utilities for handling verifiable credentials, including creating, signing, verifying, and managing cryptographic keys. The utilities are designed to work with Bun, a fast JavaScript runtime.
Readme
Verifiable Credentials Utils
This project provides a set of utilities for handling verifiable credentials, including creating, signing, verifying, and managing cryptographic keys. The utilities are designed to work with Bun, a fast JavaScript runtime.
Features
- Key Generation: Generate RSA key pairs and automatically update the
.envfile with the generated keys. - Credential Creation: Create verifiable credentials in compliance with W3C standards.
- Signing and Verification: Sign credentials and verify their authenticity using RSA signatures.
- Command-Line Interface (CLI): A CLI tool for key generation and other utilities.
Installation
To install the dependencies, use Bun:
bun installUsage
Build the Project
To build the project, use the following command:
bun run buildThis will generate the JavaScript files and TypeScript declaration files in the dist directory.
Key Generation
You can generate RSA keys and update the .env file using the CLI:
bunx verifiable-credentials-utils keygenCreating a Credential
Use the createCoinCredential function to create a new verifiable credential:
import { createCoinCredential } from './create';
const credential = createCoinCredential({
type: 'Coin',
amount: 100,
holder: 'https://example.com/holder',
});Signing a Credential
To sign a credential, use the signCredential function:
import { signCredential } from './sign';
import { VerifiableCredential } from './schemas';
const signedCredential = signCredential<VerifiableCredential>(credential);Verifying a Credential
To verify the authenticity of a signed credential:
import { verifyCredential } from './verify';
const isValid = verifyCredential(signedCredential);Development
Project Structure
- src/: Contains the TypeScript source files.
- cli.ts: The entry point for the CLI.
- constants.ts: Common constants used throughout the project.
- create.ts: Logic for creating verifiable credentials.
- keygen.ts: Key generation logic and
.envmanagement. - schemas.ts: Zod schemas for data validation.
- sign.ts: Functions for signing credentials.
- verify.ts: Functions for verifying credentials.
- utils.ts: Utility functions.
Scripts
- build: Build the project using Bun.
- version: Bump the version before committing and pushing.
- prepublishOnly: Ensure the project is built before publishing.
Husky Hooks
- pre-commit: Runs the build script before committing changes.
- pre-push: Bumps the version before pushing to the remote repository.
License
This project is licensed under the MIT License.
