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

@dfinity/verifiable-credentials

v1.0.0

Published

Library to interact with the identity provider to get a credential presentation.

Downloads

1,858

Readme

Javascript SDK For Verifiable Credentials

At the moment, this library only contains a function to interact with an Identity Provider to get a credential presentation for a user.

The flow to request a credential is performed through a browser.

Installation

Install library

npm install @dfinity/verifiable-credentials

The bundle needs peer dependencies, be sure that following resources are available in your project as well.

npm install @dfinity/principal

Import per modules:

// import * from '@dfinity/verifiable-credentials'; // Error: use sub-imports, to ensure small app size
import { requestVerifiablePresentation } from "@dfinity/verifiable-credentials/request-verifiable-presentation";

Relying Party: Request Credentials

Use the function requestVerifiablePresentation to request credentials from an issuer.

Summary

The function performs the following steps:

  • Open a new window or tab with the Identity Provider.
  • Wait for a window post message from the Identity Provider.
  • Send a request to the Identity Provider through the window post message.
  • Wait for the response from the Identity Provider.
  • Call onSuccess callback when the flow was successful. Not necessarily that the credential was received.
  • Call onError callback when the flow has some technical error or the user closes the window.

More info in the Internet Identity Specification for Verifiable Credentials.

Usage

To start a flow, call the function with the expected parameters:

requestVerifiablePresentation({
  onSuccess: async (verifiablePresentation: VerifiablePresentationResponse) => {
    // Called when the flow finishes successfully.
  },
  onError() {
    // Called when there is a technical error.
  },
  issuerData: {
    origin: "<url of the origin>",
    canisterId: "<canister id>",
  },
  credentialData: {
    credentialSpec: {
      credentialType: '<credential type as expected by issuer>',
      arguments: {
        // Arguments to verify with the credential
      },
    },
    credentialSubject: "<user's principal>",
  },
  identityProvider: "<url identity provider>",
  derivationOrigin: "<[optional] origin for delegated identity>",
  windowOpenerFeatures: "<[optional] window opener config string>",
});

Paremeters

List of properties expected in the parameter when calling the function:

  • onSuccess: Function that will be called when the flow finishes. Not necessarily with the credential. This is also called if the user doesn't have the credential.
  • onError: Function that will be called when the flow failes due to a technical error. Also when the user interrupts the flow.
  • issuerData: Object with the origin and canisterId of the issuer.
  • credentialData: Object with the subbject and the credential requested.
  • identityProvider: URL of the Identity Provider. Ex: new URL("https://identity.ic0.app/").
  • derivationOrigin: Indicates an origin that should be used for principal derivation. It's the same value as the one used when logging in. More info.
  • windowOpenerFeatures The flow will open a new window or tab. Pass here a configuration string to customize it.