npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@empe/verifier-common

v3.6.0

Published

A core library for working with Verifiable Presentations (VPs) and Presentation Definitions in the OIDC4VP (OpenID Connect for Verifiable Presentations) protocol. This package implements utilities for verifiable credential matching, presentation definitio

Readme

@empe/verifier-common

A core library for working with Verifiable Presentations (VPs) and Presentation Definitions in the OIDC4VP (OpenID Connect for Verifiable Presentations) protocol. This package implements utilities for verifiable credential matching, presentation definition building, and credential validation within the Empe SSI ecosystem.

Table of Contents

  1. Installation
  2. Key Features
  3. Usage
  4. Types
  5. Error Handling
  6. Advanced Filtering
  7. Integration with Verifier Service

Installation

npm install @empe/verifier-common
# or
yarn add @empe/verifier-common

Key Features

  • Presentation Definition Building: Create standardized presentation definitions for verifier requests
  • Credential Matching: Match verifiable credentials against presentation definitions using JSONPath expressions
  • Validation: Validate verifiable presentations, definitions, and submissions
  • JSON Schema Filtering: Apply complex filters to credential fields using JSON Schema validation

Usage

Building Presentation Definitions

Creating a presentation definition to request specific credential types:

import { buildPresentationDefinition, VPQueryParams } from '@empe/verifier-common';

// Simple request for a credential containing "ProofOfIdentity" in its type array
const simpleRequest: VPQueryParams[] = [
    {
        fields: [
            {
                path: ['$.type'],
                filter: {
                    type: 'array',
                    contains: { const: 'ProofOfIdentity' },
                },
            },
        ],
    },
];

// Create the presentation definition
const presentationDefinition = buildPresentationDefinition(simpleRequest);

console.log(presentationDefinition);
// Output:
// {
//   id: "1a2b3c...",  // auto-generated nanoid
//   input_descriptors: [
//     {
//       id: "descriptor-0",
//       constraints: {
//         limit_disclosure: "required",
//         fields: [
//           {
//             path: ["$.type"],
//             filter: { type: "array", contains: { const: "ProofOfIdentity" } }
//           }
//         ]
//       }
//     }
//   ]
// }

Matching Credentials

Match verifiable credentials against a presentation definition:

import { matchCredentialsToDefinition, buildPresentationDefinition } from '@empe/verifier-common';
import { VC } from '@empe/identity';

// Your array of verifiable credentials to match against
const userCredentials: VC[] = [
    /* ... */
];

// Create a presentation definition that requires credentials with nationality "Germany"
const presentationDefinition = buildPresentationDefinition([
    {
        fields: [
            {
                path: ['$.credentialSubject.nationality'],
                filter: {
                    type: 'string',
                    const: 'Germany',
                },
            },
        ],
    },
]);

// Match credentials against the definition
const matchedCredentials = matchCredentialsToDefinition(userCredentials, presentationDefinition);

console.log(`Found ${matchedCredentials.length} matching credentials`);

Creating Presentation Submissions

Create a presentation submission from a presentation definition:

import { createPresentationSubmission, buildPresentationDefinition } from '@empe/verifier-common';

// First, create a presentation definition
const presentationDefinition = buildPresentationDefinition([
    /* ... */
]);

// Then create a submission for it
const presentationSubmission = createPresentationSubmission(presentationDefinition);

console.log(presentationSubmission);
// Output:
// {
//   id: "submission-1a2b3c...",  // auto-generated ID
//   definition_id: "1a2b3c...",   // matches the presentation definition ID
//   descriptor_map: [
//     {
//       id: "descriptor-0",
//       path: "$.verifiableCredential[0]",
//       format: "jwt_vc"  // or other appropriate format
//     }
//   ]
// }

Validating Verifiable Presentations

Validate that a verifiable presentation meets a presentation definition:

import {
    validateVerifiablePresentation,
    buildPresentationDefinition,
    createPresentationSubmission,
    VP,
} from '@empe/verifier-common';

// Your verifiable presentation
const verifiablePresentation: VP = {
    /* ... */
};

// Create a presentation definition
const presentationDefinition = buildPresentationDefinition([
    /* ... */
]);

// Create a presentation submission
const presentationSubmission = createPresentationSubmission(presentationDefinition);

// Validate the presentation against the definition and submission
try {
    const isValid = validateVerifiablePresentation(
        presentationDefinition,
        verifiablePresentation,
        presentationSubmission
    );

    console.log('Presentation is valid:', isValid);
} catch (error) {
    console.error('Validation failed:', error.message);
}

Types

The package exports several TypeScript types:

// Definition of what credentials are being requested
type VPQueryParams = {
    fields: InputDescriptorField[];
};

// Field specification with JSONPath and optional filter
type InputDescriptorField = {
    path: string[];
    filter?: JSONSchema7; // JSON Schema for validation
};

// Structure describing requested credentials
type PresentationDefinition = {
    id: string;
    input_descriptors: InputDescriptor[];
};

// Mapping between the presentation definition and the actual credentials
type PresentationSubmission = {
    id: string;
    definition_id: string;
    descriptor_map: DescriptorMap[];
};

// Verifiable Presentation structure
type VP = {
    '@context': string[] | string;
    type: string | string[];
    verifiableCredential: VC[];
    id?: string;
    holder: string | { id: string };
    proof?: Proof;
};

Error handling example:

import { validatePresentationDefinition, PresentationDefinitionError } from '@empe/verifier-common';

try {
    validatePresentationDefinition(presentationDefinition);
} catch (error) {
    if (error instanceof PresentationDefinitionError) {
        console.error('Definition validation failed:', error.message);
        // Handle the specific error
    } else {
        // Handle other errors
        console.error('Unexpected error:', error);
    }
}

Advanced Filtering

The package supports complex JSON Schema-based filtering:

// Example: Request a credential where:
// - type array contains "ProofOfIdentity"
// - nationality is "Germany"
// - age is greater than 18
const complexFilter = buildPresentationDefinition([
    {
        fields: [
            {
                path: ['$.type'],
                filter: {
                    type: 'array',
                    contains: { const: 'ProofOfIdentity' },
                },
            },
            {
                path: ['$.credentialSubject.nationality'],
                filter: {
                    type: 'string',
                    const: 'Germany',
                },
            },
            {
                path: ['$.credentialSubject.age'],
                filter: {
                    type: 'number',
                    minimum: 18,
                },
            },
        ],
    },
]);

Integration with Verifier Client

This package forms the foundation for the @empe/verifier-client package, providing core functionality for credential verification. To implement a complete verifier service, you typically:

  1. Use this package to define what credentials you need to verify
  2. Generate a QR code for wallet scanning (via verifier-client)
  3. Match the presented credentials against your requirements
  4. Process the verification results in your application

See the @empe/verifier-client package documentation for complete implementation examples.

License

MIT