Socket
Book a DemoInstallSign in
Socket

@mattrglobal/vc-cwt-verifier

Package Overview
Dependencies
Maintainers
4
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mattrglobal/vc-cwt-verifier

vc-cwt-verifier

latest
npmnpm
Version
1.0.4
Version published
Maintainers
4
Created
Source

vc-cwt-verifier

Table of Contents

  • Getting started
  • Usage
  • Licensing

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

FAQs

Package last updated on 21 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.