Socket
Socket
Sign inDemoInstall

@privacybydesign/irma-client

Package Overview
Dependencies
11
Maintainers
4
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.1-rc.2 to 0.1.1-rc.3

71

index.js

@@ -10,3 +10,3 @@ const ServerSession = require('./server-session');

this._options = this._sanitizeOptions(options);
this._session = new ServerSession(this._options.session);
this._session = this._options.session ? new ServerSession(this._options.session) : false;
}

@@ -38,18 +38,20 @@

_startNewSession() {
this._session.start()
.then(qr => {
if (this._stateMachine.currentState() == 'Loading') {
this._stateMachine.transition('loaded', qr);
} else {
// State was changed while loading, so cancel again.
this._serverState = new ServerState(qr.u, this._options.state);
this._serverCancelSession();
}
})
.catch(error => {
if ( this._options.debugging )
console.error("Error starting a new session on the server:", error);
if (this._session) {
this._session.start()
.then(qr => {
if (this._stateMachine.currentState() == 'Loading') {
this._stateMachine.transition('loaded', qr);
} else {
// State was changed while loading, so cancel again.
this._serverState = new ServerState(qr.u, this._options.state);
this._serverCancelSession();
}
})
.catch(error => {
if (this._options.debugging)
console.error("Error starting a new session on the server:", error);
this._handleNoSuccess('fail');
})
this._handleNoSuccess('fail', error);
})
}
}

@@ -66,3 +68,3 @@

this._handleNoSuccess('fail');
this._handleNoSuccess('fail', error);
}

@@ -85,3 +87,3 @@ }

this._handleNoSuccess('fail');
this._handleNoSuccess('fail', error);
}

@@ -114,16 +116,19 @@

_successStateReached() {
this._session.result()
.then(result => this._stateMachine.transition('succeed', result))
.catch(error => {
if ( this._options.debugging )
console.error("Error fetching session result from the server:", error);
if (this._session) {
return this._session.result()
.then(result => this._stateMachine.transition('succeed', result))
.catch(error => {
if (this._options.debugging)
console.error("Error fetching session result from the server:", error);
this._handleNoSuccess('fail');
});
this._handleNoSuccess('fail', error);
});
}
this._stateMachine.transition('succeed');
}
_handleNoSuccess(transition) {
_handleNoSuccess(transition, payload) {
if (this._options.session.start)
return this._stateMachine.transition(transition);
this._stateMachine.finalTransition(transition);
return this._stateMachine.transition(transition, payload);
this._stateMachine.finalTransition(transition, payload);
}

@@ -137,6 +142,5 @@

url: o => `${o.url}/session`,
body: null,
method: 'POST',
headers: { 'Content-Type': 'application/json' },
parseResponse: r => r.json()
// And default custom settings for fetch()'s init parameter
// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
},

@@ -149,6 +153,5 @@ mapping: {

url: (o, {sessionToken}) => `${o.url}/session/${sessionToken}/result`,
body: null,
method: 'GET',
headers: { 'Content-Type': 'application/json' },
parseResponse: r => r.json()
// And default custom settings for fetch()'s init parameter
// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
}

@@ -155,0 +158,0 @@ },

{
"name": "@privacybydesign/irma-client",
"version": "0.1.1-rc.2",
"version": "0.1.1-rc.3",
"description": "A plugin to allow your IRMA flows to communicate with a server",

@@ -10,3 +10,3 @@ "main": "index.js",

"eventsource": "^1.0.7",
"isomorphic-fetch": "^2.2.1"
"isomorphic-fetch": "^3.0.0"
},

@@ -13,0 +13,0 @@ "repository": {

@@ -23,7 +23,12 @@ # IRMA client

start: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
"@context": "https://irma.app/ld/request/disclosure/v2",
"disclose": [
'@context': 'https://irma.app/ld/request/disclosure/v2',
'disclose': [
[
[ "pbdf.pbdf.email.email" ]
[ 'pbdf.pbdf.email.email' ],
[ 'pbdf.sidn-pbdf.email.email' ],
]

@@ -49,4 +54,4 @@ ]

The `session` option is the only required one. The `session` options contains
three property structs corresponding to the three phases session handling has:
The `session` options contains three property structs corresponding to
the three phases session handling has:
- `start` dealing with fetching session information from a remote server;

@@ -61,8 +66,34 @@ - `mapping` dealing with parsing the needed information out of the fetched

All property structs have default values set matching the flow when directly using the
[`irma server`](https://irma.app/docs/irma-server/) for handling sessions.
If you need more fine grained control over how the session is started and how
the result from the session is fetched on the server, you can override (parts
of) `start` and/or `result`.
All property structs have default values set for fetching the session pointer
(on state `Loading`) and fetching the session result (on state `Success`)
with a GET request on respectively the endpoints `${o.url}/session` and
`${o.url}/session/${sessionToken}/result`. In this `o.url` is the value of
the `url` option as described above.
For fetching we use the `fetch()`
[default settings](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch).
The `start` and `result` property structs are passed as custom options
to `fetch()`. This means you can use [all options](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch)
of `fetch()`to customize the request `irma-client` does for you. For example,
in case you want a specific POST request to be done instead of the default
GET request, you can do so.
```javascript
start: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
'@context': 'https://irma.app/ld/request/disclosure/v2',
'disclose': [
[
[ 'pbdf.pbdf.email.email' ],
[ 'pbdf.sidn-pbdf.email.email' ],
]
]
})
}
```
If you don't need your Javascript to fetch the session result, you can set

@@ -114,6 +145,5 @@ `result` to `false`. The Promise will then just resolve when the session is done.

url: o => `${o.url}/session`,
body: null,
method: 'POST',
headers: { 'Content-Type': 'application/json' },
parseResponse: r => r.json()
// And the custom settings for fetch()'s init parameter
// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
},

@@ -128,6 +158,5 @@

url: (o, {sessionPtr, sessionToken}) => `${o.url}/session/${sessionToken}/result`,
body: null,
method: 'GET',
headers: { 'Content-Type': 'application/json' },
parseResponse: r => r.json()
// And the custom settings for fetch()'s init parameter
// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
}

@@ -137,2 +166,8 @@ }

If you want to use another plugin for starting IRMA sessions, you can disable
the session functionality of `irma-client` by saying `session: false`. In this
case `irma-client` will not request the `this._stateMachine.transition('loaded', qr)`
transition at the state machine while it is in the `Loading` state. This means you
have to specify a custom plugin that requests this transition instead.
### state

@@ -171,3 +206,3 @@

Note that in the `url` functions, `o.url` in this case isn't `session.url`, but
rather the `u` property from the QR code object (or `sessionPtr.u`). So by
rather the `u` property from the QR code object (so `sessionPtr.u`). By
default these URLs **will** point to your IRMA server, which is okay.
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc