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

didauth

v1.2.0

Published

DID Authentication Library.

Downloads

20

Readme

DID Authentication

npm NpmLicense npm bundle size (minified) npm bundle size (minified + gzip)

didauth is a JavaScript NPM libray for building DID authentication. Library uses JSDoc and Typescript typings for your convinience.

Example Demo Website

DID Authentication didauth.meet-martin.com

Demo Website Github Repository

Get Started

Installation

To use with Node.js:

$ npm install --save didauth

MATTR Platform Dependency

To use the library, you will need to have an account at MATTR, which provides all the necessary plumbing to support decentralized identifiers and a digital wallet.

Authentication

authentication is a pure function that creates an authentication request URL for DID Authentication with your MATTR tenant. The resulting URL is intended to be used to redirect the user.

As a result, MATTR platform calls supplied callback URL with the result that connects to your request by a supplied Challenge ID.

We return a monad @7urtle/lambda.AsyncEffect as the output of the function: https://www.7urtle.com/documentation-7urtle-lambda#lambda-AsyncEffect. On success the monad will hold a string with a redirect URL with JWS intended for the digital wallet. On failure it with hold a string describing the error.

import { authentication } from 'didauth';

const payload = {
    clientId: 'client id', // client id provided by MATTR
    clientSecret: 'client secret', // client secret provided by MATTR
    tenant: 'your-tenant.vii.mattr.global', // your tenant provided by MATTR
    did: 'did:method:code', // your verifier DID representing your application created in MATTR platform
    challengeId: 'your-challenge-id', // custom ID provided by your application to connect request internally
    templateId: 'presentation template id', // presentation template ID created in MATTR platform
    callbackURL: 'https://your-domain.tld/didauth/callback' // callback url of your website that the digital wallet will call
};

authentication(payload)
.trigger
(errors => console.log(errors) || ({
    statusCode: 500,
    body: 'Internal Server Error'
}))
(JWSURL => ({
    statusCode: 301,
    headers: {
        locations: JWSURL
    }
}));

Push Authentication

pushAuthentication is a pure function that creates an authentication digital wallet push request for DID Authentication with your MATTR tenant. It uses the recipientDID stored in your system to find the user's digital wallet and ask them for authentication through a push request on their phone.

As a result, MATTR platform calls supplied callback URL with the result that connects to your request by a supplied Challenge ID.

We return a monad @7urtle/lambda.AsyncEffect as the output of the function: https://www.7urtle.com/documentation-7urtle-lambda#lambda-AsyncEffect. On success the monad will hold the string 'Success' indicating that the authentication request was sent to a digital wallet. On failure it with hold a string describing the error.

import { pushAuthentication } from 'didauth';

const payload = {
    clientId: 'client id', // client id provided by MATTR
    clientSecret: 'client secret', // client secret provided by MATTR
    tenant: 'your-tenant.vii.mattr.global', // your tenant provided by MATTR
    did: 'did:method:code', // your verifier DID representing your application created in MATTR platform
    recipientDid: 'did:method:code', // users DID store by your application
    challengeId: 'your-challenge-id', // custom ID provided by your application to connect request internally
    templateId: 'presentation template id', // presentation template ID created in MATTR platform
    callbackURL: 'https://your-domain.tld/didauth/callback' // callback url of your website that the digital wallet will call
};

pushAuthentication(payload)
.trigger
(errors => console.log(errors) || ({
    statusCode: 500,
    body: 'Internal Server Error'
}))
(() => ({
    statusCode: 204
}));

Run Tests

The library has 100 % test coverage with unit tests and integration tests.

test-coverage

To run unit tests locally, call:

npm run unit-test

To run integration tests locally as well you will need .env file setup connected to your website and using your MATTR credentials. Please either reach out directly to MATTR to obtain them or open an issue in this repository to get help.

npm test

How Is The Library Built

didauth is built using functional programming principles on top of 7urtle/lambda. The library internally uses functional monads and therefor the output of the function calls are monads as well.

The library itself is written in pure JavaScript and uses Babel and Webpack to build. However, for your convinience Typescript typings and JSDoc are provided with the library.

The node code is build using ESM with support for both import and require and optimized for three-shaking to reduce your package sizes.

Contributors

Contributors

Made with contributors-img.

Changelog

1.2.0

  • Library type changed to module using ESM imports/exports. Still supports commonjs require through webpack/babel build.
  • Optimizations for tree-shakeability of the library for both ESM and CJS.
  • Declaring Node support from version 12.16 (current node is 17.4.0, LTS is 16.13.2, and AWS Lambda defaults to node 14).
  • These changes were heavily tested with different configurations. However, if you encounter any issues, please report them on GitHub.