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

@privacybydesign/irma-backend

v0.1.5

Published

Backend library to use API endpoints of the IRMA server

Downloads

7

Readme

IRMA backend

This module can be used for handling messages from and to the irma server in the following way:

const IrmaBackend = require('@privacybydesign/irma-backend');
const irmaBackend = new IrmaBackend(serverUrl, options);

Constructor parameters

  • serverUrl should be the URL where your irma server is running.
  • options (optional) specifies a struct where additional options can be specified. We currently support the following options:
    • serverToken field to enable requestor authentication. By default this field is set to false, meaning that no authorization headers will be sent. The default setting can only be used if the IRMA server is configured to accept unauthenticated requests or when only sending signed JWT session requests.
    • debugging field to enable printing helpful output to the console for debugging. By default this field is set to false.

Available methods

startSession(request)

This method starts a session at the IRMA server. The request parameter may either be a session request object or a signed JWT session request. The function returns a promise which on resolve gives the session identifiers {sessionPtr: ..., token: ...}.

cancelSession(sessionToken)

This method cancels the session with token sessionToken at the IRMA server. The parameter sessionToken concerns the token as being returned by startSession. It returns a promise. On resolve the session is cancelled successfully.

getSessionResult(sessionToken)

This method fetches the session result object. The parameter sessionToken concerns the token as being returned by startSession. It returns a promise which on resolve gives the session result object. When the result is not available yet, the promise is rejected.

getSessionResultJwt(sessionToken)

This method behaves the same as getSessionResult, but fetches the session result JWT instead.

getSessionStatus(sessionToken)

This method fetches the current status of the IRMA session. The parameter sessionToken concerns the token as being returned by startSession. The function returns a promise which on resolve gives the current session status. A struct with the possible values for the session status can be retrieved using the static call IrmaBackend.SessionStatus.

getServerPublicKey()

This method fetches the JWT public key of the IRMA server. It returns a promise which on resolve gives the public key in a PEM encoded string. When no JWT public key is configured at the IRMA server, the promise will be rejected.

Important remark: when using method hmac for JWT signing, the same key is used for both signing and verification. This means in this case there is no public key and therefore this function will also not return one.

subscribeStatusEvents(sessionToken, eventCallback)

With this method you can subscribe on receiving events on status updates of a particular IRMA session. The parameter sessionToken concerns the token as being returned by startSession. The parameter eventCallback concerns a 'error-first' callback function to receive the events.

The callback function signature is (error, status) => {}. When error is being null, the status parameter will contain the new session status. A struct with the possible values for the session status can be retrieved using the static call IrmaBackend.SessionStatus.

Code example

Below a small example of how irma-backend can be used:

const IrmaBackend = require('@privacybydesign/irma-backend');
const irmaBackend = new IrmaBackend(serverUrl, options);

const irmaRequest = {
  '@context': 'https://irma.app/ld/request/disclosure/v2',
  'disclose': [
    [
      [ 'irma-demo.MijnOverheid.ageLower.over18' ]
    ]
  ]
};

irmaBackend.startSession(irmaRequest)
.then(({sessionPtr, token}) => {

  // Send sessionPtr to the frontend

  // Fetch the result if present
  irmaBackend.subscribeStatusEvents(token, (error, status) => {
    if (error != null) {
      throw error;
    }
    if (status === IrmaBackend.SessionStatus.Done) {
      irmaBackend.getSessionResult(token)
      .then( result => { 
        // Do something with result
      });
    }
  });
});