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

@bloomprotocol/vc

v0.1.5

Published

TypeScript types, JSON schemas, and signing and verifying functions for Verifiable Credentials and Presentations.

Downloads

750

Readme

VC

TypeScript types, JSON schemas, and signing and verifying functions for Verifiable Credentials and Presentations.

Installation

npm i @bloomprotocol/vc

OR

yarn add @bloomprotocol/vc

Usage

Signing

signVC

signVC takes a single parameter with the following properties:

| Name | Description | Type | | ------------------- | ------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | unsigned | The unsigned VC to be signed | Omit<VC, 'proof'> | | suite | Signing suite that is compatible with jsonld-signatures | Class that is compatible with LinkedDataSignature | | documentLoader | Function that resolves context URLs and DIDs | (url: string) => Promise<{document: null \| Record<string, unknown>, documentUrl: string}> \| {document: null \| Record<string, unknown>, documentUrl: string} | | proofPurposeOptions | Additional options to pass to the proof purpose class | undefined \| Record<string, unknown> |

import { signVC, VC } from '@bloomprotocol/vc'

const { Ed25519VerificationKey2020 } = require('@digitalbazaar/ed25519-verification-key-2020')
const { Ed25519Signature2020 } = require('@digitalbazaar/ed25519-signature-2020')

const unsignedVC: Omit<VC, 'proof'> = {
  '@context': ['https://www.w3.org/2018/credentials/v1', 'https://w3id.org/security/suites/ed25519-2020/v1'],
  id: 'urn:uuid:9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d',
  type: ['VerifiableCredential'],
  issuanceDate: new Date().toISOString(),
  issuer: 'did:example:issuer',
  credentialSubject: {},
}

const suite = new Ed25519Signature2020({
  key: new Ed25519VerificationKey2020(keyPair),
})

const vc = await signVC({
  unsigned: unsigngedVC,
  suite,
  documentLoader: (url: string) => {
    //...
  },
})

signVP

signVP takes a single parameter with the following properties:

| Name | Description | Type | | ------------------- | ------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | unsigned | The unsigned VP to be signed | Omit<VP, 'proof'> | | suite | Signing suite that is compatible with jsonld-signatures | Class that is compatible with LinkedDataSignature | | documentLoader | Function that resolves context URLs and DIDs | (url: string) => Promise<{document: null \| Record<string, unknown>, documentUrl: string}> \| {document: null \| Record<string, unknown>, documentUrl: string} | | proofPurposeOptions | Additional options to pass to the proof purpose class | {challenge: string, domain: string, [k: string]?: unknown} |

import { signVC, VC } from '@bloomprotocol/vc'

const { Ed25519VerificationKey2020 } = require('@digitalbazaar/ed25519-verification-key-2020')
const { Ed25519Signature2020 } = require('@digitalbazaar/ed25519-signature-2020')

const unsignedVP: Omit<VP, 'proof'> = {
  '@context': ['https://www.w3.org/2018/credentials/v1', 'https://w3id.org/security/suites/ed25519-2020/v1'],
  id: 'urn:uuid:9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d',
  type: ['VerifiablePresentation'],
  holder: 'did:example:holder',
  verifiableCredential: [vc]
}

const suite = new Ed25519Signature2020({
  key: new Ed25519VerificationKey2020(keyPair),
})

const vp = await signVP({
  unsigned: unsigngedVP,
  suite,
  proofPurposeOptions: {
    challenge: '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed',
    domain: 'https://example.com'
  },
  documentLoader: (url: string) => {
    //...
  },
})

Verifying

verifyVC

verifyVC takes a single parameter with the following properties:

| Name | Description | Type | Required | Default | | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------ | | vc | The VC to be verified | unknown | Yes | - | | getSuite | Function that returns a signing suite that is compatible with jsonld-signatures | (options: { verificationMethod: string, controller: string, proofType: string }) => any \| Promise<any> | Yes | - | | documentLoader | Function that resolves context URLs and DIDs | (url: string) => Promise<{document: null \| Record<string, unknown>, documentUrl: string}> \| {document: null \| Record<string, unknown>, documentUrl: string} | Yes | - | | getProofPurposeOptions | Function that returns additional options to pass to the proof purpose class | (options: { proofPurpose: string, verificationMethod: string, controller: string }) => Record<string, unknown> \| Promise<Record<string, unknown>> | No | - | | schema | Custom json schema to validate the vc against | JSONSchema | No | vcSchema | | ajv | Custom Ajv instance to use when validating the vc | Ajv | No | - | | schemaKey | Custom key to use for Ajv caching of schemas | string | No | "vcSchema" |

On success verifyVC returns:

type VerifyVCResponseSuccess<VCType extends VC> = {
  success: true
  vc: VCType
}

And on failure returns:

type VerifyVCResposeFailure = {
  success: false
  schemaErrors?: ErrorObject[]
  proofErrors?: ProofError[]
  issuanceErrors?: IssuanceError[]
}
  • schemaErrors are errors returned from Ajv
  • proofErrors are errors returned from jsonld-signatures
  • issuanceErrors are errors about the VC's issuance and expiration date

verifyVP

verifyVP takes a single parameter with the following properties:

| Name | Description | Type | Required | Default | | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------ | | vp | The VP to be verified | unknown | Yes | - | | getSuite | Function that returns a signing suite that is compatible with jsonld-signatures | (options: { verificationMethod: string, controller: string, proofType: string }) => any \| Promise<any> | Yes | - | | documentLoader | Function that resolves context URLs and DIDs | (url: string) => Promise<{document: null \| Record<string, unknown>, documentUrl: string}> \| {document: null \| Record<string, unknown>, documentUrl: string} | Yes | - | | getProofPurposeOptions | Function that returns additional options to pass to the proof purpose class | (options: { proofPurpose: string, verificationMethod: string, controller: string }) => Record<string, unknown> \| Promise<Record<string, unknown>> | No | - | | schema | Custom json schema to validate the vp against | JSONSchema | No | vpSchema | | ajv | Custom Ajv instance to use when validating the vp | Ajv | No | - | | schemaKey | Custom key to use for Ajv caching of schemas | string | No | "vpSchema" |

On success verifyVC returns:

type VerifyVPResponseSuccess<VPType extends VP> = {
  success: true
  vp: VPType
}

And on failure returns:

type VerifyVPResposeFailure = {
  success: false
  schemaErrors?: ErrorObject[]
  proofErrors?: ProofError[]
  credentialProofErrors?: {id: string, errors: ProofError[]}[]
  credentialiIssuanceErrors?: {id: string, errors: IssuanceError[]}[]
}
  • schemaErrors are errors returned from Ajv
  • proofErrors are errors returned from jsonld-signatures for the VP
  • credentialProofErrors are errors returned from jsonld-signatures for the VCs within the VP
  • credentialIssuanceErrors are errors about the issuance and expiration date for the VCs within the VP