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

@privacybydesign/irma-dummy

Package Overview
Dependencies
Maintainers
4
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@privacybydesign/irma-dummy - npm Package Compare versions

Comparing version 0.3.3 to 0.4.0

137

index.js
const merge = require('deepmerge');
module.exports = class IrmaDummy {
constructor({stateMachine, options}) {
constructor({ stateMachine, options }) {
this._stateMachine = stateMachine;
this._options = this._sanitizeOptions(options);
this._options = this._sanitizeOptions(options);
}
stateChange({newState}) {
switch(newState) {
stateChange({ newState, payload }) {
switch (newState) {
case 'Loading':
return this._startNewSession();
this._startNewSession();
break;
case 'CheckingUserAgent':
switch (this._options.dummy) {
case 'mobile':
this._doTransition('prepareButton');
break;
default:
this._doTransition('prepareQRCode');
break;
}
break;
case 'PreparingQRCode':
setTimeout(
() =>
this._doTransition('showQRCode', {
qr: JSON.stringify(this._options.qrPayload),
}),
this._options.timing.prepare
);
break;
case 'PreparingIrmaButton':
setTimeout(
() =>
this._doTransition('showIrmaButton', {
mobile: JSON.stringify(this._options.qrPayload),
}),
this._options.timing.prepare
);
break;
case 'ShowingQRCode':
case 'ShowingQRCodeInstead':
return this._waitForScanning();
this._waitForScanning();
break;
case 'Pairing':
setTimeout(() => {
if (this._options.pairingCode === payload.enteredPairingCode) {
this._doTransition('appConnected');
} else {
this._doTransition('pairingRejected', payload);
}
}, this._options.timing.pairing);
break;
case 'ContinueOn2ndDevice':
return this._waitForUserAction();
this._waitForUserAction();
break;
case 'PreparingResult':
setTimeout(() => this._doTransition('succeed', this._options.successPayload), this._options.timing.prepare);
break;
}

@@ -23,11 +64,16 @@ }

start() {
if ( this._options.debugging )
console.log(`🧙🏼‍♂️ Initializing fake IRMA flow`);
if (this._options.debugging) console.log(`🧙🏼‍♂️ Initializing fake IRMA flow`);
switch(this._options.dummy) {
case 'browser unsupported':
return this._stateMachine.transition('browserError', 'Browser not supported, need magic feature');
default:
return this._stateMachine.transition('initialize', {canRestart: true});
}
return this._stateMachine.selectTransition(({ state }) => {
if (state !== 'Uninitialized') throw new Error('State machine is already initialized by another plugin');
switch (this._options.dummy) {
case 'browser unsupported':
return {
transition: 'browserError',
payload: 'Browser not supported, need magic feature',
};
default:
return { transition: 'initialize', payload: { canRestart: true } };
}
});
}

@@ -37,11 +83,9 @@

setTimeout(() => {
// Stop when already being in end state
if (this._stateMachine.isEndState())
return;
switch(this._options.dummy) {
switch (this._options.dummy) {
case 'connection error':
return this._stateMachine.transition('fail', new Error('Dummy connection error'));
return this._doTransition('fail', new Error('Dummy connection error'));
default:
return this._stateMachine.transition('loaded', this._options.qrPayload);
return this._doTransition('loaded', {
sessionPtr: this._options.qrPayload,
});
}

@@ -51,13 +95,20 @@ }, this._options.timing.start);

_doTransition(transition, payload) {
return this._stateMachine.selectTransition(({ validTransitions }) => {
if (validTransitions.includes(transition)) return { transition, payload };
return false;
});
}
_waitForScanning() {
setTimeout(() => {
// Stop when already being in end state
if (this._stateMachine.isEndState())
return;
switch(this._options.dummy) {
switch (this._options.dummy) {
case 'pairing':
return this._doTransition('appPairing', {
pairingCode: this._options.pairingCode,
});
case 'timeout':
return this._stateMachine.transition('timeout');
return this._doTransition('timeout');
default:
return this._stateMachine.transition('appConnected');
return this._doTransition('appConnected');
}

@@ -69,11 +120,7 @@ }, this._options.timing.scan);

setTimeout(() => {
// Stop when already being in end state
if (this._stateMachine.isEndState())
return;
switch(this._options.dummy) {
switch (this._options.dummy) {
case 'cancel':
return this._stateMachine.transition('cancel');
return this._doTransition('cancel');
default:
return this._stateMachine.transition('succeed', this._options.successPayload);
return this._doTransition('prepareResult');
}

@@ -87,12 +134,15 @@ }, this._options.timing.app);

qrPayload: {
message: 'Just be patient ;)'
message: 'Just be patient ;)',
},
successPayload: {
disclosed: 'Some attributes'
disclosed: 'Some attributes',
},
pairingCode: '1234',
timing: {
start: 1000,
prepare: 1000,
scan: 2000,
app: 2000
}
pairing: 500,
app: 2000,
},
};

@@ -102,3 +152,2 @@

}
}
};
{
"name": "@privacybydesign/irma-dummy",
"version": "0.3.3",
"version": "0.4.0",
"description": "A dummy back-end for IRMA flows. Useful for testing without an actual server",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -32,2 +32,4 @@ # IRMA dummy

* `happy path` ⸺ Fake everything just working™️
* `pairing` ⸺ Fake everything just working with pairing enabled™️
* `mobile` ⸺ Fake everything just working for scanning a QR on mobile™️
* `timeout` ⸺ Fake a session time out on the server

@@ -34,0 +36,0 @@ * `cancel` ⸺ Fake cancellation in the IRMA app (don't have attributes or reject disclosure)

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