Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@privacybydesign/irma-backend

Package Overview
Dependencies
Maintainers
4
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@privacybydesign/irma-backend

Backend library to use API endpoints of the IRMA server

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
4
Weekly downloads
 
Created
Source

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
      });
    }
  });
});

FAQs

Package last updated on 12 Oct 2020

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc