didwebvh-ts
provides developers with a comprehensive library for working with Decentralized Identifiers (DIDs) following the did:webvh
method specification. This Typescript-based toolkit is designed to facilitate the integration and management of DIDs within web applications, enabling secure identity verification and authentication processes. It includes functions for creating, resolving, updating and deactivating DIDs by managing DID documents. The package is built to ensure compatibility with the latest web development standards, offering a straightforward API that makes it easy to implement DID-based features in a variety of projects.
The didwebvh-ts
implementation of the did:webvh
specification aims to be compatible with the did:webvh
v0.5 specification.
The examples
directory contains sample code demonstrating how to use the library:
-
Crypto Examples: The
examples/crypto
directory shows how to use the injectable signer and verifier functionality in thedidwebvh-ts
library. These examples demonstrate how to implement custom cryptographic operations, integrate with external key management systems (KMS), use hardware security modules (HSM), and create your own signing and verification logic. See the crypto examples README for more information. -
Resolver Examples: The
examples/resolvers
directory contains examples of how to implement a DID resolver using thedidwebvh-ts
library with different web frameworks (Elysia, Express). See the resolver examples README for more information.
Install bun.sh
curl -fsSL https://bun.sh/install | bash
bun install
The following commands are defined in the package.json
file:
-
dev
: Run the Elysia resolver example in development mode with debugging enabled.bun run dev
This command runs:
bun --watch --inspect-wait ./examples/resolvers/elysia/resolver.ts
-
server
: Run the Elysia resolver example in watch mode for development.bun run server
This command runs:
bun --watch ./examples/resolvers/elysia/resolver.ts
-
test
: Run all tests.bun run test
-
test:watch
: Run tests in watch mode.bun run test:watch
-
test:bail
: Run tests in watch mode with bail and verbose options.bun run test:bail
-
test:log
: Run tests and save logs to a file.bun run test:log
-
cli
: Run the CLI tool.bun run cli
-
build
: Build the package.bun run build
-
build:clean
: Clean the build directory.bun run build:clean
The didwebvh-ts
library provides the core functionality for resolving DIDs, but it does not include a built-in HTTP resolver. You can create your own resolver using your preferred web framework by following these steps:
-
Import the
resolveDID
function from thedidwebvh-ts
library:import { resolveDID } from 'didwebvh-ts';
-
Create endpoints for resolving DIDs:
// Example using Express app.get('/resolve/:id', async (req, res) => { try { const result = await resolveDID(req.params.id); res.json(result); } catch (error) { res.status(400).json({ error: 'Resolution failed', details: error.message }); } });
-
Implement file retrieval logic for DID documents and associated resources.
For complete examples, see the resolver examples directory.
-
resolveDID(did: string, options?: ResolutionOptions): Promise<{did: string, doc: any, meta: DIDResolutionMeta, controlled: boolean}>
Resolves a DID to its DID document. -
createDID(options: CreateDIDInterface): Promise<{did: string, doc: any, meta: DIDResolutionMeta, log: DIDLog}>
Creates a new DID. -
updateDID(options: UpdateDIDInterface): Promise<{did: string, doc: any, meta: DIDResolutionMeta, log: DIDLog}>
Updates an existing DID. -
deactivateDID(options: DeactivateDIDInterface): Promise<{did: string, doc: any, meta: DIDResolutionMeta, log: DIDLog}>
Deactivates an existing DID.
-
createDocumentSigner(options: SignerOptions): Signer
Creates a signer for signing DID documents. -
prepareDataForSigning(data: any): Uint8Array
Prepares data for signing. -
createProof(options: SigningInput): Promise<SigningOutput>
Creates a proof for a DID document. -
createSigner(options: SignerOptions): Signer
Creates a signer for signing data. -
AbstractCrypto
An abstract class for implementing custom signers.
This project is licensed under the MIT License.