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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@spherity/ethr-revocation-registry-veramo-plugin

v2.1.1

Published

A plugin for the Veramo agent enabling it to resolve EthrStatusRegistry VC revocation information

Downloads

219

Readme

EthrRevocationRegistry Veramo Plugin

A CredentialStatusPlugin plugin for the Veramo agent enabling it to resolve the status of a Verifiable Credential using the EthrRevocationRegistry revocation method. It leverages @spherity/ethr-revocation-registry-controller to interact with an EIP-5539-compliant revocation regsitry on Ethereum.

Setup

  1. Install this plugin

    npm install --save @spherity/ethr-revocation-registry-veramo-plugin @veramo/credential-status
  2. Add the plugin to your agent

    import { CredentialStatusPlugin } from "@veramo/credential-status";
    import { EthrRevocationRegistry } from "@spherity/ethr-revocation-registry-veramo-plugin;
    ...
       
    export const veramoAgent = createAgent<VeramoAgent>({
      ...,
      plugins: [
        new CredentialStatusPlugin({
          ...new EthrRevocationRegistry({
            infuraProjectId: "abcde123"
          }).asStatusMethod,
          // OR
          ...new EthrRevocationRegistry({
            chainConnectionInstruction: [
              {
                chainId: 1337,
                address: "0x",
                provider: new ethers.providers.JsonRpcProvider('http://127.0.0.1:8545')
              },
              {
                chainId: 1,
                address: "0x",
                provider: new ethers.providers.JsonRpcProvider('http://example.mainnet.quiknode.pro/token/')
              },             
            ]
          }).asStatusMethod
        }),           
      ],
    });

Usage

The revocation check can happen in two ways:

  • Implicitly: When using Veramo's agent.verifyCredential({...}) on LD-credentials, the verification will automatically do a revocation check in the background. In those cases, you have to wrap this call in a try-catch block as a failed verification will results in Veramo throwing an error (Error: Error verifying LD Verifiable Credential). Doing a verification on a credential with a JWT proof won't make this implicit check.
  • Explicit: An LD or JWT-credentials revocation status can also be checked explicitly via veramoAgent.checkCredentialStatus({credential: vc} where the vc can either be a credential object or a JWT string. This will return a CredentialStatus object that has a revoked property.

Example

import { CredentialPayload, W3CVerifiableCredential } from '@veramo/core'
import { veramoAgent } from './setup';

async function main() {
  const did = "did:ethr:rinkeby:0x036dffee0bfd09d6a542f57e457cacbb4b0df91fc02bdb478f05d6db085a1da8e8"
  const credential: CredentialPayload = {
    "@context": [
      "https://www.w3.org/2018/credentials/v1",
      "https://www.w3.org/2018/credentials/examples/v1",
      "https://raw.githubusercontent.com/spherity/vc-ethr-revocation-registry/contexts/ethr-revocation-registry.jsonld"
    ],
    "id": "http://example.edu/credentials/58473",
    "type": ["VerifiableCredential", "UniversityDegreeCredential"],
    "issuer": {"id": did},
    "issuanceDate": "2010-01-01T00:00:00Z",
    "credentialSubject": {
      "id": did,
      "degree": {
        "type": "BachelorDegree",
      }
    },
    "credentialStatus": {
      "id": "...",
      "type": "EthrRevocationRegistry",
      "registry": "0x0000000000000000000000000000000000000000" // optional. defaults to defaultRegistryAddress
      "chainId": 5, // optional. defaults to 1 (mainnet)
      "namespace": "0x6B6B873eaB06D331fFA6c431aC874Ff954A2c317",
      "revocationList": "0x3458b9bfc7963978b7d40ef225177c45193c2889902357db3b043a4e319a9628",
      "revocationKey": "0x89343794d2fb7dd5d0fba9593a4bb13beaff93a61577029176d0117b0c53b8e6"
    }
  };

  const verifiableCredential = await veramoAgent.createVerifiableCredential({ credential, proofFormat: "lds", });
   
  // Implicit: Revocation status of LD-credentials are automatically checked during verification
  try {
    await veramoAgent.verifyCredential({credential: verifiableCredential});
    console.log("Valid VC");
  } catch (e) {
    console.log("Invalid VC");
  }
  
  // Explicit: Revocation status of LD-credentials can also be checked explicitly. Mandatory for JWT-credentials.
  const revoked = await veramoAgent.checkCredentialStatus({credential: verifiableCredential})
}

main().catch(console.log)