summaryrefslogtreecommitdiff
path: root/spec/frontend/u2f/mock_u2f_device.js
blob: ec8425a4e3e5c7c3c9c34c8f702caebfe4796bbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* eslint-disable no-unused-expressions */

export default class MockU2FDevice {
  constructor() {
    this.respondToAuthenticateRequest = this.respondToAuthenticateRequest.bind(this);
    this.respondToRegisterRequest = this.respondToRegisterRequest.bind(this);
    window.u2f || (window.u2f = {});
    window.u2f.register = (appId, registerRequests, signRequests, callback) => {
      this.registerCallback = callback;
    };
    window.u2f.sign = (appId, challenges, signRequests, callback) => {
      this.authenticateCallback = callback;
    };
  }

  respondToRegisterRequest(params) {
    return this.registerCallback(params);
  }

  respondToAuthenticateRequest(params) {
    return this.authenticateCallback(params);
  }
}