@the-hashgraph-group-ag/verifier
v0.4.5-alpha.0
Published
This package is a powerful TypeScript/JavaScript library designed to streamline the verification of verifiable credentials. This package provides a flexible and extensible framework for verifying verifiable credentials with support for multiple formats an
Keywords
Readme
Features
- Multiple Credential Formats: Support for Linked Data Proof (LDP) Verifiable Credentials/Presentations with extensible architecture for additional formats
- Policy-Based Verification: Configurable business rules and verification policies (e.g., required subject) to ensure compliance
- Cryptographic Flexibility: Works with pluggable verifiers and cryptosuites, including Ed25519
- Presentation Requests: Build requests describing required policies and credential constraints
- TypeScript Support: Full TypeScript definitions for enhanced developer experience and type safety
Installation
npm install @the-hashgraph-group-ag/verifierQuick Start
Basic Usage
import {
createCredentialVerifier,
LdpHandler,
LdpRequiredSubjectPolicy,
} from '@the-hashgraph-group-ag/verifier';
import { InternalEd25519Verifier } from '@the-hashgraph-group-ag/signer-internal-ed25519';
import { Ed25519ProofVerifier } from '@the-hashgraph-group-ag/cryptosuites-eddsa-v1';
// Create cryptographic components
const verifier = new InternalEd25519Verifier();
const cryptoSuites = [new Ed25519ProofVerifier()];
// Provide verifier options, including a way to resolve public keys
const verifierOptions = {
verificationMethodResolver: async (verificationMethod: string) => {
// Resolve and return the raw public key bytes for the verificationMethod
// e.g., from DID Documents or your key registry
return new Uint8Array(/* public key bytes */);
},
};
// Create an LDP verification handler
const ldpHandler = new LdpHandler({
cryptoSuites,
verifier,
verifierOptions,
});
// Create verification policies
const subjectPolicy = new LdpRequiredSubjectPolicy({
subject: 'did:example:alice',
});
// Create the credential verifier
const credentialVerifier = createCredentialVerifier({
handlers: [ldpHandler],
policies: [subjectPolicy],
});
// Create a presentation request that references configured policies
const request = await credentialVerifier.createRequest({
policies: ['LdpRequiredSubjectPolicy'],
});
// Verify a Verifiable Presentation (or a single Verifiable Credential)
const vp = {
'@context': ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiablePresentation'],
holder: 'did:example:alice',
verifiableCredential: [
/* your LDP VC(s) here */
],
proof: {
/* LDP proof */
},
};
const verification = await credentialVerifier.verify(vp, request);
if (verification.verified) {
console.log(
'Presentation verified. Policy results:',
verification.policyResults,
);
} else {
console.error('Verification failed:', verification.error);
}Contributing
Contributions are welcome! Please see the main project repository for contribution guidelines.
License
This SDK is licensed under the Apache License 2.0.
Support
For support and questions:
- Check the documentation
- Open an issue on GitHub
- Contact the development team
