verifiable-credentials-utils
TypeScript icon, indicating that this package has built-in type declarations

1.5.1 • Public • Published

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 .env file 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 install

Usage

Build the Project

To build the project, use the following command:

bun run build

This 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 keygen

Creating 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 .env management.
    • 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.

Readme

Keywords

none

Package Sidebar

Install

npm i verifiable-credentials-utils

Weekly Downloads

0

Version

1.5.1

License

none

Unpacked Size

22.3 kB

Total Files

24

Last publish

Collaborators

  • remi_guan