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

@mattrglobal/vc-cwt-verifier

v1.0.4

Published

vc-cwt-verifier

Downloads

45

Readme

vc-cwt-verifier

Table of Contents

Getting started

Install dependencies

Add the module as a dependency to your application or library.

yarn add @mattrglobal/vc-cwt-verifier

or

npm install @mattrglobal/vc-cwt-verifier

Usage

Verify a credential

import { verify } from "@mattrglobal/vc-cwt-verifier";
import * as hex from "@stablelib/hex";

const payload: Uint8Array = hex.decode(
  "d2844aa204456b65792d310126a0590137a50178376469643a7765623a6d61747472676c6f62616c2e6769746875622e696f3a6e7a63703a71766e6e6b38396b696a726f65696e6478613375051a6178cc15041a74477215627663a46840636f6e7465787482782668747470733a2f2f7777772e77332e6f72672f323031382f63726564656e7469616c732f7631782768747470733a2f2f6865616c74682e676f76742e6e7a2f63726564656e7469616c732f63706e7a6776657273696f6e65312e302e306474797065827456657269666961626c6543726564656e7469616c6f5075626c6963436f766964506173737163726564656e7469616c5375626a656374a369676976656e4e616d65644a61636b6a66616d696c794e616d656753706172726f7763646f626a313936302d30342d313607d84050e6060795d65f4f85a3924bc4380a30c75840ef52b04644273e9757b2418fea39fae5eac99dd354eaf862f8f8f7c842a85550a0ff485c6999fc29527075686eeceaff36775e4ef031ef94dbc13e6e9f6a83ab"
);

const verifyResult = await verify({ payload });

if (verifyResult.isErr()) {
  const { error } = verifyResult;
  // handle error unable to verify
  return;
}
const verifyResponse = verifyResult.value;
if (!verifyResponse.verified) {
  const { reason } = verifyResponse;
  // show or handle verification fail reason
}

const { payload, header } = verifyResponse;
// show or handle verified payload & header

Verify a credential with a list of trusted issuers

import { verify } from "@mattrglobal/vc-cwt-verifier";

const verifyResult = await verify({
  trustedIssuers: ["did:web:example.com", "did:web:mattrglobal.github.io:test:example"],
  payload: {},
});

const verifyResponse = verifyResult.value;
if (!verifyResponse.verified) {
  const { reason } = verifyResponse;
  // show or handle verification fail reason
}

const { payload, header } = verifyResponse;
// show or handle verified payload & header

Verify a credential skipping expiry and not before checks

If assertExpiry or assertNotBefore are omitted they will be checked against the current date and time by default

import { verify } from "@mattrglobal/vc-cwt-verifier";

const verifyResult = await verify({
  assertExpiry: false,
  assertNotBefore: false,
  payload: ...
});

const verifyResponse = verifyResult.value;
if (!verifyResponse.verified) {
  const { reason } = verifyResponse;
  // show or handle verification fail reason
}

const { payload, header } = verifyResponse;
// show or handle verified payload & header

Provide custom cache for issuer resolution

By default an in memory cache will be provided. This can be overwritten by passing a different cache instance.

import { verify, getDefaultIssuerResolver } from "@mattrglobal/vc-cwt-verifier";


const issuerResolver = getDefaultIssuerResolver({ cache: myCache });


const verifyResult = await verify({
  payload: ...,
  issuerResolver
});

Error handling

Functions that have an error path return a Neverthrow Result that represents either success or failure. All functions can throw exceptions for unexpected and unrecoverable errors.

Licensing

See here for licence information