@prove-identity/prove-auth 2.15.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +2 -2
  2. package/build/bundle/release/prove-auth.js +1 -1
  3. package/build/lib/index.d.ts +7 -3
  4. package/build/lib/index.js +23 -9
  5. package/build/lib/proveauth/authenticator-builder.d.ts +9 -11
  6. package/build/lib/proveauth/authenticator-builder.js +54 -114
  7. package/build/lib/proveauth/common/base64.js +2 -1
  8. package/build/lib/proveauth/common/logger.js +2 -2
  9. package/build/lib/proveauth/device-context-options.d.ts +0 -8
  10. package/build/lib/proveauth/device-context-options.js +2 -12
  11. package/build/lib/proveauth/device-role.d.ts +4 -0
  12. package/build/lib/proveauth/device-role.js +8 -0
  13. package/build/lib/proveauth/docv.d.ts +11 -0
  14. package/build/lib/proveauth/docv.js +2 -0
  15. package/build/lib/proveauth/instantlink.js +1 -1
  16. package/build/lib/proveauth/internal/auth-request.d.ts +6 -1
  17. package/build/lib/proveauth/internal/auth-response-status.js +1 -1
  18. package/build/lib/proveauth/internal/auth-response.d.ts +6 -0
  19. package/build/lib/proveauth/internal/auth-session.d.ts +1 -2
  20. package/build/lib/proveauth/internal/auth-session.js +57 -32
  21. package/build/lib/proveauth/internal/auth-token-claims.d.ts +4 -0
  22. package/build/lib/proveauth/internal/auth-token-claims.js +1 -1
  23. package/build/lib/proveauth/internal/device-passive-step.d.ts +2 -1
  24. package/build/lib/proveauth/internal/device-passive-step.js +6 -6
  25. package/build/lib/proveauth/internal/device-universal-redirect-steps.js +2 -2
  26. package/build/lib/proveauth/internal/external-integrations.d.ts +34 -0
  27. package/build/lib/proveauth/internal/external-integrations.js +49 -0
  28. package/build/lib/proveauth/internal/fido-options-error.js +1 -1
  29. package/build/lib/proveauth/internal/main-authenticator.d.ts +2 -0
  30. package/build/lib/proveauth/internal/main-authenticator.js +3 -0
  31. package/build/lib/proveauth/internal/mobile-instant-step.d.ts +2 -3
  32. package/build/lib/proveauth/internal/mobile-instant-step.js +61 -67
  33. package/build/lib/proveauth/internal/platform.d.ts +9 -13
  34. package/build/lib/proveauth/internal/platform.js +7 -6
  35. package/build/lib/proveauth/internal/report-error-step.d.ts +1 -0
  36. package/build/lib/proveauth/internal/report-error-step.js +8 -3
  37. package/build/lib/proveauth/internal/user-docv-steps.d.ts +13 -0
  38. package/build/lib/proveauth/internal/user-docv-steps.js +104 -0
  39. package/build/lib/proveauth/internal/user-ppb-steps.js +37 -33
  40. package/build/lib/proveauth/internal/web-device-auth.js +4 -1
  41. package/build/lib/proveauth/internal/web-platform.d.ts +6 -6
  42. package/build/lib/proveauth/internal/web-platform.js +11 -93
  43. package/build/lib/proveauth/internal/web-socket-close-reasons.js +1 -1
  44. package/build/lib/proveauth/otp.js +1 -1
  45. package/build/lib/proveauth/version.d.ts +2 -2
  46. package/build/lib/proveauth/version.js +1 -1
  47. package/package.json +35 -39
  48. package/build/lib/proveauth/external/@authid/web-component/authid-web-component.d.ts +0 -3
  49. package/build/lib/proveauth/external/@authid/web-component/authid-web-component.js +0 -55
@@ -26,6 +26,9 @@ export interface UniversalAuthenticator {
26
26
  export interface PpbAuthenticator {
27
27
  endp: string;
28
28
  }
29
+ export interface DocVAuthenticator {
30
+ endp: string;
31
+ }
29
32
  export interface DeviceAuthenticators {
30
33
  pasv?: PassiveAuthenticator;
31
34
  unvsl?: UniversalAuthenticator;
@@ -41,6 +44,7 @@ export interface UserAuthenticators {
41
44
  pasv?: PassiveAuthenticator;
42
45
  prst?: PresentAuthenticator;
43
46
  ppb?: PpbAuthenticator;
47
+ docv?: DocVAuthenticator;
44
48
  }
45
49
  export interface Signals {
46
50
  fpt?: boolean;
@@ -6,4 +6,4 @@ var UserVerificationLevel;
6
6
  UserVerificationLevel["Discouraged"] = "none";
7
7
  UserVerificationLevel["Preferred"] = "pref";
8
8
  UserVerificationLevel["Required"] = "req";
9
- })(UserVerificationLevel = exports.UserVerificationLevel || (exports.UserVerificationLevel = {}));
9
+ })(UserVerificationLevel || (exports.UserVerificationLevel = UserVerificationLevel = {}));
@@ -1,6 +1,7 @@
1
1
  import AuthSession from './auth-session';
2
2
  import AuthStep from './auth-step';
3
- import { DeviceRole, PasskeyAlreadyExistCallback } from '../authenticator-builder';
3
+ import { PasskeyAlreadyExistCallback } from '../authenticator-builder';
4
+ import { DeviceRole } from '../device-role';
4
5
  import { AuthStatusActions } from './auth-status-actions';
5
6
  import { Signals } from './auth-request';
6
7
  export declare class DevicePassiveActions extends AuthStatusActions {
@@ -9,7 +9,7 @@ const base64_1 = __importDefault(require("../common/base64"));
9
9
  const device_passive_silent_step_1 = __importDefault(require("./device-passive-silent-step"));
10
10
  const auth_token_claims_1 = require("./auth-token-claims");
11
11
  const auth_error_1 = __importDefault(require("./auth-error"));
12
- const authenticator_builder_1 = require("../authenticator-builder");
12
+ const device_role_1 = require("../device-role");
13
13
  const auth_status_actions_1 = require("./auth-status-actions");
14
14
  const fido_options_error_1 = require("./fido-options-error");
15
15
  const auth_response_status_1 = require("./auth-response-status");
@@ -195,19 +195,19 @@ class DevicePassiveActions extends auth_status_actions_1.AuthStatusActions {
195
195
  });
196
196
  }
197
197
  }
198
+ exports.DevicePassiveActions = DevicePassiveActions;
198
199
  DevicePassiveActions.NO_REQUEST_CREDS_FOUND = 'Passkey has already been registered but found no CredentialRequestOptions in the fido/register/start response payload';
199
200
  DevicePassiveActions.NO_CREDS_FOUND = 'Neither credCreateOptions nor credRequestOptions are found in the fido/register/start response payload';
200
201
  DevicePassiveActions.USER_NOT_ACCEPTING_RESPONSE = 'User not accepting to continue by reusing the existing passkey with user response';
201
- exports.DevicePassiveActions = DevicePassiveActions;
202
202
  class DevicePassiveStep extends DevicePassiveActions {
203
203
  constructor(getDisplayName, handler, role) {
204
204
  super(getDisplayName, handler);
205
205
  this.name = DevicePassiveStep.NAME;
206
- this.role = role !== null && role !== void 0 ? role : authenticator_builder_1.DeviceRole.Primary;
206
+ this.role = role !== null && role !== void 0 ? role : device_role_1.DeviceRole.Primary;
207
207
  this.log = logger_1.LoggerFactory.getLogger('device-passive-step');
208
208
  }
209
209
  execute(session) {
210
- if (this.role == authenticator_builder_1.DeviceRole.Secondary) {
210
+ if (this.role == device_role_1.DeviceRole.Secondary) {
211
211
  return this.waitForStatus(session);
212
212
  }
213
213
  if (!session.platform.isFidoSupported() ||
@@ -222,7 +222,7 @@ class DevicePassiveStep extends DevicePassiveActions {
222
222
  }
223
223
  return new Promise((resolve, reject) => {
224
224
  session
225
- .getFingerprintData()
225
+ .getDeviceContextData()
226
226
  .then((signal) => {
227
227
  const signals = {
228
228
  fingerprint: signal,
@@ -230,7 +230,7 @@ class DevicePassiveStep extends DevicePassiveActions {
230
230
  this.register(session, signals).then(resolve).catch(reject);
231
231
  })
232
232
  .catch((error) => {
233
- const errorMsg = `Unexpected error happened during Fingerprint data collection: ${error.message}`;
233
+ const errorMsg = `Unexpected error happened during Device Context data collection: ${error.message}`;
234
234
  this.log.warn(errorMsg);
235
235
  this.log.warn(error);
236
236
  const signals = {
@@ -43,13 +43,13 @@ class DeviceUniversalRedirectFinishStep extends DeviceUniversalRedirectBaseStep
43
43
  this.name = DeviceUniversalRedirectFinishStep.NAME;
44
44
  }
45
45
  }
46
- DeviceUniversalRedirectFinishStep.NAME = 'redirect/finish';
47
46
  exports.DeviceUniversalRedirectFinishStep = DeviceUniversalRedirectFinishStep;
47
+ DeviceUniversalRedirectFinishStep.NAME = 'redirect/finish';
48
48
  class DeviceUniversalRedirectExchangeStep extends DeviceUniversalRedirectBaseStep {
49
49
  constructor() {
50
50
  super(...arguments);
51
51
  this.name = DeviceUniversalRedirectExchangeStep.NAME;
52
52
  }
53
53
  }
54
- DeviceUniversalRedirectExchangeStep.NAME = 'redirect/exchange';
55
54
  exports.DeviceUniversalRedirectExchangeStep = DeviceUniversalRedirectExchangeStep;
55
+ DeviceUniversalRedirectExchangeStep.NAME = 'redirect/exchange';
@@ -0,0 +1,34 @@
1
+ import DeviceContextOptions from '../device-context-options';
2
+ export declare abstract class ExternalIntegration {
3
+ protected static readonly log: import("../common/logger").Logger;
4
+ private static readonly instances;
5
+ private readonly name;
6
+ protected constructor(name: string);
7
+ protected static getInstance(name: string): ExternalIntegration;
8
+ protected static activate(instance: ExternalIntegration): void;
9
+ }
10
+ export interface PpbResult {
11
+ authIdSuccess?: boolean;
12
+ }
13
+ export interface PpbOptions {
14
+ endpointUrl?: string;
15
+ ppbOperation?: string;
16
+ operationId?: string;
17
+ oneTimeSecret?: string;
18
+ }
19
+ export declare abstract class PpbIntegration extends ExternalIntegration {
20
+ static readonly NAME = "PPB";
21
+ static get instance(): PpbIntegration;
22
+ constructor();
23
+ abstract activateWebComponent(options: PpbOptions): Promise<PpbResult>;
24
+ }
25
+ export interface DataCollector {
26
+ getCollectedData(): Promise<string | undefined>;
27
+ }
28
+ export declare abstract class DeviceContextIntegration extends ExternalIntegration {
29
+ static readonly NAME = "DeviceContext";
30
+ static get instance(): DeviceContextIntegration;
31
+ constructor();
32
+ abstract init(options: DeviceContextOptions): void;
33
+ abstract getDataCollector(): Promise<DataCollector | undefined>;
34
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeviceContextIntegration = exports.PpbIntegration = exports.ExternalIntegration = void 0;
4
+ const logger_1 = require("../common/logger");
5
+ class ExternalIntegration {
6
+ constructor(name) {
7
+ this.name = name;
8
+ ExternalIntegration.activate(this);
9
+ }
10
+ static getInstance(name) {
11
+ const instances = ExternalIntegration.instances;
12
+ if (!instances.has(name)) {
13
+ throw new Error(`${name} integration is not available`);
14
+ }
15
+ return instances.get(name);
16
+ }
17
+ static activate(instance) {
18
+ if (!ExternalIntegration.instances.has(instance.name)) {
19
+ ExternalIntegration.instances.set(instance.name, instance);
20
+ ExternalIntegration.log.info(`${instance.name} integration activated`);
21
+ }
22
+ else {
23
+ ExternalIntegration.log.debug(`${instance.name} integration already activated, ignoring`);
24
+ }
25
+ }
26
+ }
27
+ exports.ExternalIntegration = ExternalIntegration;
28
+ ExternalIntegration.log = logger_1.LoggerFactory.getLogger('external-integrations');
29
+ ExternalIntegration.instances = new Map();
30
+ class PpbIntegration extends ExternalIntegration {
31
+ static get instance() {
32
+ return ExternalIntegration.getInstance(PpbIntegration.NAME);
33
+ }
34
+ constructor() {
35
+ super(PpbIntegration.NAME);
36
+ }
37
+ }
38
+ exports.PpbIntegration = PpbIntegration;
39
+ PpbIntegration.NAME = 'PPB';
40
+ class DeviceContextIntegration extends ExternalIntegration {
41
+ static get instance() {
42
+ return ExternalIntegration.getInstance(DeviceContextIntegration.NAME);
43
+ }
44
+ constructor() {
45
+ super(DeviceContextIntegration.NAME);
46
+ }
47
+ }
48
+ exports.DeviceContextIntegration = DeviceContextIntegration;
49
+ DeviceContextIntegration.NAME = 'DeviceContext';
@@ -146,6 +146,7 @@ class FidoOptionsError extends Error {
146
146
  return error;
147
147
  }
148
148
  }
149
+ exports.FidoOptionsError = FidoOptionsError;
149
150
  FidoOptionsError.MISSING_PUBLIC_KEY_PROPERTY = 'options missing publicKey property';
150
151
  FidoOptionsError.ABORT_SIGNAL = 'Authentication was sent an abort signal';
151
152
  FidoOptionsError.INVALID_STATE_ERROR = 'The authenticator was already registered';
@@ -158,4 +159,3 @@ FidoOptionsError.NO_MATCHING_AUTHENTICATOR = 'User verification is required but
158
159
  FidoOptionsError.INVALID_CRED_PARAMS = 'No entry in pubKeyCredParams having the type of public-key';
159
160
  FidoOptionsError.NO_MATCHING_AUTHENTICATOR_FOR_PARAMS_ALGO = 'No available authenticator supported any of the specified pubKeyCredParams algorithms';
160
161
  FidoOptionsError.INVALID_USER_ID_LENGTH = 'User ID has invalid length';
161
- exports.FidoOptionsError = FidoOptionsError;
@@ -5,6 +5,7 @@ import Platform from './platform';
5
5
  import CancelablePromise from '../common/cancelable-promise';
6
6
  import AuthSession from './auth-session';
7
7
  import AuthStep from './auth-step';
8
+ import DeviceContextOptions from '../device-context-options';
8
9
  export default class MainAuthenticator implements Authenticator {
9
10
  static readonly AUTH_DONE = "done";
10
11
  static readonly AUTH_EMPTY = "";
@@ -14,6 +15,7 @@ export default class MainAuthenticator implements Authenticator {
14
15
  protected readonly platform: Platform;
15
16
  protected readonly settings: Settings;
16
17
  protected readonly authFinishStep?: AuthFinishStep;
18
+ protected readonly deviceContextOptions?: DeviceContextOptions;
17
19
  constructor(platform: Platform, settings: Settings, finishStep?: AuthFinishStep, steps?: Array<AuthStep>);
18
20
  isPasskeyRegistered(): boolean;
19
21
  isFidoSupported(): boolean;
@@ -18,6 +18,9 @@ class MainAuthenticator {
18
18
  this.settings = settings;
19
19
  if (steps) {
20
20
  for (let step of steps) {
21
+ if (step.name in this.steps) {
22
+ throw new Error(`Step ${step.name} is already registered`);
23
+ }
21
24
  this.steps.set(step.name, step);
22
25
  }
23
26
  }
@@ -7,9 +7,8 @@ export default class MobileInstantStep implements AuthStep {
7
7
  protected log: import("../common/logger").Logger;
8
8
  private readonly implementation;
9
9
  private readonly getDeviceIp;
10
- private readonly deviceIpDetection;
11
- private errorCodeBak?;
12
- private nextBak?;
10
+ private executeStartStep;
11
+ private executeFinishStep;
13
12
  constructor(implementation: MobileAuthImplementation, getDeviceIp?: () => string | null);
14
13
  execute(session: AuthSession): Promise<string>;
15
14
  }
@@ -7,92 +7,86 @@ const auth_error_1 = __importDefault(require("./auth-error"));
7
7
  const logger_1 = require("../common/logger");
8
8
  const authenticator_builder_1 = require("../authenticator-builder");
9
9
  const error_code_1 = __importDefault(require("./error-code"));
10
+ const device_descriptor_1 = __importDefault(require("@prove-identity/mobile-auth/build/lib/mobileauth/process/device-descriptor"));
10
11
  class MobileInstantStep {
12
+ executeStartStep(session) {
13
+ return new Promise((resolve, reject) => {
14
+ const ip = this.getDeviceIp();
15
+ session
16
+ .fetchFromBackend('/v1/client/mobile/instant/start', {
17
+ cellularIp: ip,
18
+ implementation: this.implementation,
19
+ })
20
+ .then((response) => {
21
+ if (response.error) {
22
+ reject(new auth_error_1.default(response.error.message, response.error.code, response.next, false));
23
+ }
24
+ else {
25
+ const data = response.data;
26
+ if (data === null || data === void 0 ? void 0 : data.redirectUrl) {
27
+ resolve(data.redirectUrl);
28
+ }
29
+ else {
30
+ reject(new auth_error_1.default('No redirect URL found in start response', undefined, response.next, true));
31
+ }
32
+ }
33
+ })
34
+ .catch(reject);
35
+ });
36
+ }
37
+ executeFinishStep(session, vfpValues) {
38
+ return new Promise((resolve, reject) => {
39
+ session
40
+ .fetchFromBackend('/v1/client/mobile/instant/finish', { vfp: vfpValues })
41
+ .then((response) => {
42
+ if (response.error) {
43
+ reject(new auth_error_1.default(response.error.message, response.error.code, response.next, false));
44
+ }
45
+ else {
46
+ resolve(response.next);
47
+ }
48
+ })
49
+ .catch(reject);
50
+ });
51
+ }
11
52
  constructor(implementation, getDeviceIp) {
12
53
  this.name = MobileInstantStep.NAME;
13
54
  this.log = logger_1.LoggerFactory.getLogger('mobile-instant-step');
14
- this.errorCodeBak = error_code_1.default.ERROR_AUTHENTICATION_CLIENT_FAILURE;
15
55
  this.implementation = implementation;
16
- if (getDeviceIp) {
17
- this.getDeviceIp = getDeviceIp;
18
- this.deviceIpDetection = false;
19
- }
20
- else {
21
- this.getDeviceIp = () => null;
22
- this.deviceIpDetection = true;
23
- }
56
+ this.getDeviceIp = getDeviceIp !== null && getDeviceIp !== void 0 ? getDeviceIp : (() => null);
24
57
  }
25
58
  execute(session) {
26
59
  return new Promise((resolve, reject) => {
27
- let builder = session.platform
28
- .getMobileAuthBuilder()
29
- .withDeviceIpDetection(this.deviceIpDetection);
60
+ let builder = session.platform.getMobileAuthBuilder();
30
61
  switch (this.implementation) {
31
62
  case authenticator_builder_1.MobileAuthImplementation.Pixel: {
32
63
  builder = builder.withPixelImplementation();
33
64
  break;
34
65
  }
35
66
  case authenticator_builder_1.MobileAuthImplementation.Fetch: {
36
- builder = builder.withFetchImplementation().withFinishStep((input) => {
37
- return new Promise((resolve, reject) => {
38
- session
39
- .fetchFromBackend('/v1/client/mobile/instant/finish', {
40
- vfp: input.vfp,
41
- })
42
- .then(resolve)
43
- .catch(reject);
44
- });
45
- });
67
+ builder = builder.withFetchImplementation();
46
68
  break;
47
69
  }
48
70
  }
49
- builder = builder.withStartStep((input) => {
50
- return new Promise((resolve, reject) => {
51
- const ip = this.deviceIpDetection ? input.deviceDescriptor.ip : this.getDeviceIp();
52
- session
53
- .fetchFromBackend('/v1/client/mobile/instant/start', {
54
- cellularIp: ip,
55
- implementation: this.implementation,
56
- })
57
- .then((response) => {
58
- if (response.error) {
59
- this.nextBak = response.next;
60
- this.errorCodeBak = response.error.code;
61
- reject(new auth_error_1.default(response.error.message, response.error.code, response.next, false));
62
- }
63
- else {
64
- const data = response.data;
65
- resolve({
66
- authUrl: data ? data.redirectUrl : undefined,
67
- });
68
- }
69
- })
70
- .catch(reject);
71
- });
72
- });
71
+ builder = builder
72
+ .withStartStep(() => Promise.reject(new auth_error_1.default("StartStep shouldn't be executed in MobileAuth SDK layer for non-orchestrated flow")))
73
+ .withFinishStep(() => Promise.reject(new auth_error_1.default("FinishStep shouldn't be executed in MobileAuth SDK layer for non-orchestrated flow")));
73
74
  const authenticator = builder.build();
74
- authenticator
75
- .authenticate()
76
- .then((response) => {
77
- if (response) {
78
- const authResponse = response;
79
- if (authResponse.error) {
80
- reject(new auth_error_1.default(response.error.message, response.error.code, response.next, false));
81
- }
82
- resolve(authResponse.next);
83
- }
84
- else {
85
- session
86
- .fetchFromBackend('/v1/client/mobile/instant/finish', {})
87
- .then((response) => resolve(response.next))
88
- .catch((error) => {
89
- reject(new auth_error_1.default(response.error.message, response.error.code, response.next, false));
90
- });
91
- }
75
+ const deviceDescriptor = new device_descriptor_1.default(this.getDeviceIp());
76
+ this.executeStartStep(session)
77
+ .then((authUrl) => {
78
+ authenticator
79
+ .authenticateWithRedirect(deviceDescriptor, authUrl)
80
+ .then((vfp) => {
81
+ this.executeFinishStep(session, vfp).then(resolve).catch(reject);
82
+ })
83
+ .catch((error) => {
84
+ var _a;
85
+ const message = (_a = auth_error_1.default.extractMessage(error)) !== null && _a !== void 0 ? _a : 'Mobile Auth Midlle Step failed at authenticateWithRedirect';
86
+ reject(new auth_error_1.default(message, error_code_1.default.ERROR_AUTHENTICATION_CLIENT_FAILURE));
87
+ });
92
88
  })
93
- .catch((error) => {
94
- reject(new auth_error_1.default(error, this.errorCodeBak, this.nextBak, false));
95
- });
89
+ .catch(reject);
96
90
  });
97
91
  }
98
92
  }
@@ -1,10 +1,9 @@
1
- /// <reference types="webappsec-credential-management" />
2
1
  import { AuthenticatorBuilder } from '@prove-identity/mobile-auth';
3
2
  import { AuthRequest } from './auth-request';
4
3
  import AuthResponse from './auth-response';
5
4
  import DeviceAuth, { DeviceRegistration } from './device-auth';
6
- import { Agent } from '@fingerprintjs/fingerprintjs-pro';
7
- import { PpbOperation } from '../ppb';
5
+ import DeviceContextOptions from '../device-context-options';
6
+ import { PpbOptions, PpbResult, DataCollector } from './external-integrations';
8
7
  export declare const DEVICE_CAPABILITY_WEBAUTHN = "webauthn";
9
8
  export interface MessageChannel {
10
9
  addEventListener: (type: string, listener: (event: any) => void) => void;
@@ -28,14 +27,11 @@ export interface AuthSessionIntegration {
28
27
  getDeviceRegistration: () => Promise<DeviceRegistration | null>;
29
28
  fetchFromBackend: (query: string, body: AuthRequest) => Promise<AuthResponse>;
30
29
  }
31
- export interface PpbAuthResult {
32
- authIdSuccess?: boolean;
30
+ export interface DocVOptions {
31
+ documentTypeId: string;
32
+ accountNumber: string;
33
33
  }
34
- export interface PpbAuthOptions {
35
- authIdEndpointUrl?: string;
36
- authIdOperation?: PpbOperation;
37
- authIdOperationId?: string;
38
- authIdOneTimeSecret?: string;
34
+ export interface DocVResult {
39
35
  }
40
36
  export default interface Platform {
41
37
  readonly webauthn: WebAuthN;
@@ -50,10 +46,10 @@ export default interface Platform {
50
46
  getMobileAuthBuilder: () => AuthenticatorBuilder<any>;
51
47
  exit: (code?: number) => void;
52
48
  urlRedirect: (url: string) => void;
53
- getFpPromise: () => Promise<Agent> | undefined;
54
- setFpPromise: (fpPromise: Promise<Agent>) => void;
55
49
  getOrigin: () => string;
56
- ppbAuthenticate: (options: PpbAuthOptions) => Promise<PpbAuthResult>;
50
+ activatePpb: (options: PpbOptions) => Promise<PpbResult>;
51
+ initDeviceContext: (options: DeviceContextOptions) => void;
52
+ getDataCollector: () => Promise<DataCollector | undefined>;
57
53
  }
58
54
  export declare function stringToArrayBuffer(input: string): ArrayBuffer;
59
55
  export declare function arrayBufferToString(input: ArrayBuffer): string;
@@ -1,20 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUnixTime = exports.arrayBufferToHexString = exports.arrayBufferToString = exports.stringToArrayBuffer = exports.DEVICE_CAPABILITY_WEBAUTHN = void 0;
3
+ exports.DEVICE_CAPABILITY_WEBAUTHN = void 0;
4
+ exports.stringToArrayBuffer = stringToArrayBuffer;
5
+ exports.arrayBufferToString = arrayBufferToString;
6
+ exports.arrayBufferToHexString = arrayBufferToHexString;
7
+ exports.getUnixTime = getUnixTime;
4
8
  exports.DEVICE_CAPABILITY_WEBAUTHN = 'webauthn';
5
9
  function stringToArrayBuffer(input) {
6
- return new TextEncoder().encode(input);
10
+ const uint8Array = new TextEncoder().encode(input);
11
+ return uint8Array.buffer.slice(uint8Array.byteOffset, uint8Array.byteOffset + uint8Array.byteLength);
7
12
  }
8
- exports.stringToArrayBuffer = stringToArrayBuffer;
9
13
  function arrayBufferToString(input) {
10
14
  return String.fromCharCode.apply(null, Array.from(new Uint8Array(input)));
11
15
  }
12
- exports.arrayBufferToString = arrayBufferToString;
13
16
  function arrayBufferToHexString(input) {
14
17
  return Array.from(new Uint8Array(input), (x) => ('00' + x.toString(16)).slice(-2)).join('');
15
18
  }
16
- exports.arrayBufferToHexString = arrayBufferToHexString;
17
19
  function getUnixTime() {
18
20
  return Math.floor(Date.now() / 1000);
19
21
  }
20
- exports.getUnixTime = getUnixTime;
@@ -2,6 +2,7 @@ import AuthSession from './auth-session';
2
2
  import AuthStep from './auth-step';
3
3
  export default class ReportErrorStep implements AuthStep {
4
4
  private static readonly endpointMap;
5
+ private static readonly DEFAULT_MESSAGE;
5
6
  private readonly logger;
6
7
  private _message;
7
8
  private _code?;
@@ -17,10 +17,11 @@ const user_present_step_1 = __importDefault(require("./user-present-step"));
17
17
  const device_passive_stepup_step_1 = __importDefault(require("./device-passive-stepup-step"));
18
18
  const device_universal_redirect_steps_1 = require("./device-universal-redirect-steps");
19
19
  const user_ppb_steps_1 = require("./user-ppb-steps");
20
+ const user_docv_steps_1 = require("./user-docv-steps");
20
21
  class ReportErrorStep {
21
22
  constructor(error) {
22
23
  this.logger = logger_1.LoggerFactory.getLogger('report-error-step');
23
- this._message = 'Unknown error';
24
+ this._message = ReportErrorStep.DEFAULT_MESSAGE;
24
25
  this.reportable = true;
25
26
  this.name = 'error';
26
27
  if (error instanceof auth_error_1.default) {
@@ -44,6 +45,7 @@ class ReportErrorStep {
44
45
  return this._message;
45
46
  }
46
47
  execute(session) {
48
+ var _a;
47
49
  let logMessage = `Authentication step ${session.lastStep} failed`;
48
50
  if (this._code) {
49
51
  logMessage = logMessage + ', code: ' + this._code;
@@ -58,7 +60,7 @@ class ReportErrorStep {
58
60
  const endpoint = session.lastStep
59
61
  ? ReportErrorStep.endpointMap.get(session.lastStep)
60
62
  : undefined;
61
- if (endpoint && (this.reportable || !this.nextStep)) {
63
+ if (endpoint && this.reportable) {
62
64
  return new Promise((resolve, reject) => {
63
65
  session
64
66
  .fetchFromBackend(`/v1/client/${endpoint}/error`, {
@@ -73,7 +75,8 @@ class ReportErrorStep {
73
75
  return Promise.resolve(this.nextStep);
74
76
  }
75
77
  else {
76
- return Promise.reject(new auth_error_1.default('Cannot determine the next auth step'));
78
+ const errorMessage = (_a = this._message) !== null && _a !== void 0 ? _a : ReportErrorStep.DEFAULT_MESSAGE;
79
+ return Promise.reject(new auth_error_1.default(errorMessage, this._code, undefined, false));
77
80
  }
78
81
  }
79
82
  }
@@ -91,5 +94,7 @@ ReportErrorStep.endpointMap = new Map([
91
94
  [user_present_step_1.default.NAME, 'user/mobileactive'],
92
95
  [user_ppb_steps_1.UserPpbEnrollStep.NAME, 'user/ppb'],
93
96
  [user_ppb_steps_1.UserPpbVerifyStep.NAME, 'user/ppb'],
97
+ [user_docv_steps_1.UserDocVerifyStep.NAME, 'user/docv'],
94
98
  ]);
99
+ ReportErrorStep.DEFAULT_MESSAGE = 'Unexpected error, authentication cannot continue';
95
100
  exports.default = ReportErrorStep;
@@ -0,0 +1,13 @@
1
+ import AuthStep from './auth-step';
2
+ import AuthSession from './auth-session';
3
+ import { DocVFinishStep, DocVStartStep } from '../docv';
4
+ export declare class UserDocVerifyStep implements AuthStep {
5
+ static readonly NAME = "user/docv";
6
+ readonly name = "user/docv";
7
+ private readonly log;
8
+ private readonly enabled;
9
+ private readonly startStep;
10
+ private readonly finishStep;
11
+ constructor(enabled: boolean, startStep?: DocVStartStep, finishStep?: DocVFinishStep);
12
+ execute(session: AuthSession): Promise<string>;
13
+ }
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.UserDocVerifyStep = void 0;
7
+ const logger_1 = require("../common/logger");
8
+ const auth_error_1 = __importDefault(require("./auth-error"));
9
+ class UserDocVerifyStep {
10
+ constructor(enabled, startStep, finishStep) {
11
+ this.name = UserDocVerifyStep.NAME;
12
+ this.log = logger_1.LoggerFactory.getLogger('user-docv-verify-step');
13
+ this.enabled = enabled;
14
+ this.startStep = startStep;
15
+ this.finishStep = finishStep;
16
+ }
17
+ execute(session) {
18
+ if (!this.enabled) {
19
+ return Promise.reject(new auth_error_1.default('Document Verification is not enabled'));
20
+ }
21
+ if (!this.startStep) {
22
+ return Promise.reject(new auth_error_1.default('Document Verification start step is required'));
23
+ }
24
+ const callStart = () => new Promise((resolve, reject) => {
25
+ this.startStep
26
+ .execute()
27
+ .then((output) => {
28
+ session
29
+ .fetchFromBackend('/v1/client/user/docv/start', {
30
+ requestId: crypto.randomUUID(),
31
+ documentType: output.documentType,
32
+ })
33
+ .catch(reject)
34
+ .then((response) => {
35
+ var _a, _b;
36
+ const docvResponse = response;
37
+ if (docvResponse.error) {
38
+ reject(new auth_error_1.default(docvResponse.error.message, docvResponse.error.code, docvResponse.next, false));
39
+ }
40
+ const respData = docvResponse.data;
41
+ resolve({
42
+ documentType: output.documentType,
43
+ operationId: (_a = respData.docv) === null || _a === void 0 ? void 0 : _a.operationId,
44
+ oneTimeSecret: (_b = respData.docv) === null || _b === void 0 ? void 0 : _b.oneTimeSecret,
45
+ });
46
+ });
47
+ })
48
+ .catch(reject);
49
+ });
50
+ const callFinish = (error) => {
51
+ try {
52
+ if (this.finishStep) {
53
+ return this.finishStep.execute(error);
54
+ }
55
+ else {
56
+ return Promise.resolve();
57
+ }
58
+ }
59
+ catch (e) {
60
+ this.log.warn('Document Verification finish step has failed:', e);
61
+ return Promise.reject(e);
62
+ }
63
+ };
64
+ return new Promise((resolve, reject) => {
65
+ callStart()
66
+ .then((startResult) => {
67
+ var _a, _b, _c;
68
+ this.log.debug('Activating PPB web component');
69
+ session.platform
70
+ .activatePpb({
71
+ endpointUrl: (_c = (_b = (_a = session.claims) === null || _a === void 0 ? void 0 : _a.auth.subs.usr) === null || _b === void 0 ? void 0 : _b.auths.docv) === null || _c === void 0 ? void 0 : _c.endp,
72
+ operationId: startResult.operationId,
73
+ oneTimeSecret: startResult.oneTimeSecret,
74
+ })
75
+ .catch((e) => {
76
+ this.log.error('PPB web component failed:', e);
77
+ callFinish(e).then(() => reject(e));
78
+ })
79
+ .then((result) => {
80
+ this.log.info('DocV authentication result', result);
81
+ return session.fetchFromBackend('/v1/client/user/docv/finish', {
82
+ requestId: crypto.randomUUID(),
83
+ operationId: startResult.operationId,
84
+ });
85
+ })
86
+ .then((response) => {
87
+ var _a, _b;
88
+ const docvResponse = response;
89
+ if (docvResponse.error) {
90
+ const message = (_b = (_a = response.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : 'Document verification failed';
91
+ callFinish(new Error(message)).then(() => reject(new auth_error_1.default(response.error.message, response.error.code, response.next, false)));
92
+ }
93
+ else {
94
+ callFinish().then(() => resolve(docvResponse.next));
95
+ }
96
+ })
97
+ .catch(reject);
98
+ })
99
+ .catch(reject);
100
+ });
101
+ }
102
+ }
103
+ exports.UserDocVerifyStep = UserDocVerifyStep;
104
+ UserDocVerifyStep.NAME = 'user/docv';