UNPKG

@nevis-security/nevis-mobile-authentication-sdk-react

Version:

React Native plugin for Nevis Mobile Authentication SDK. Supports only mobile.

378 lines (347 loc) 15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UserInteractionPlatformOperationImpl = exports.UserInteractionPlatformOperation = void 0; var _PlatformOperation = require("./PlatformOperation"); var _Aaid = require("../../localData/Aaid"); var _MobileAuthenticationSdk = _interopRequireDefault(require("../../MobileAuthenticationSdk")); var _PasswordValidatedMessage = require("../../model/messages/out/PasswordValidatedMessage"); var _PinValidatedMessage = require("../../model/messages/out/PinValidatedMessage"); var _PasswordChangeHandler = require("../../operations/password/PasswordChangeHandler"); var _PasswordEnrollmentHandler = require("../../operations/password/PasswordEnrollmentHandler"); var _PinChangeHandler = require("../../operations/pin/PinChangeHandler"); var _PinEnrollmentHandler = require("../../operations/pin/PinEnrollmentHandler"); var _AccountSelectionHandler = require("../../operations/selection/AccountSelectionHandler"); var _AuthenticatorSelectionHandler = require("../../operations/selection/AuthenticatorSelectionHandler"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** * Copyright © 2023-2024 Nevis Security AG. All rights reserved. */ /** * Helps in following the states of user interaction operations during method * channel calls. */ class UserInteractionPlatformOperation extends _PlatformOperation.PlatformOperation { /** * The {@link AccountSelector} given when an operation is started. * * E.g.: During an out-of-band process. */ /** * The {@link AuthenticatorSelector} given when an operation is started. * * E.g.: During an out-of-band process. */ /** * The {@link PinEnroller} given when an operation is started. * * E.g.: During an out-of-band process. */ /** * The {@link PasswordEnroller} given when an operation is started. * * E.g.: During an out-of-band process. */ /** * The {@link PinChanger} given when an operation is started. */ /** * The {@link PasswordChanger} given when an operation is started. */ /** * The {@link PinUserVerifier} given when an operation is started. * * E.g.: During an out-of-band process. */ /** * The {@link PasswordUserVerifier} given when an operation is started. * * E.g.: During an out-of-band process. */ /** * The {@link BiometricUserVerifier} given when an operation is started. * * E.g.: During an out-of-band process. */ /** * The {@link DevicePasscodeUserVerifier} given when an operation is started. * * E.g.: During an out-of-band process. */ /** * The {@link FingerprintUserVerifier} given when an operation is started. * * E.g.: During an out-of-band process. */ /** * The {@link AccountSelectionHandler} given when an operation is started. * * E.g.: During an out-of-band process. * This is generated automatically based on the {@link operationId}. */ /** * The {@link AuthenticatorSelectionHandler} given when an operation is started. * * E.g.: During an out-of-band process. * This is generated automatically based on the {@link operationId}. */ /** * The {@link PinEnrollmentHandler} given when an operation is started. * * E.g.: During an out-of-band process. * This is generated automatically based on the {@link operationId}. */ /** * The {@link PasswordEnrollmentHandler} given when an operation is started. * * E.g.: During an out-of-band process. * This is generated automatically based on the {@link operationId}. */ /** * The {@link PinChangeHandler} given when an operation is started. * * E.g.: During a pin change. * This is generated automatically based on the {@link operationId}. */ /** * The {@link PasswordChangeHandler} given when an operation is started. * * E.g.: During a password change. * This is generated automatically based on the {@link operationId}. */ /** * The {@link UserVerificationHandler} given when an operation is in the state of user verification. */ /** * The account selection interaction. * * The implementing class must ask the user to choose one of the accounts * exposed by the {@link AccountSelectionContext} and provide the choice to the * {@link AccountSelectionHandler}. * * @param context the object containing the list of existing accounts and authenticators. */ selectAccount(context) { this.accountSelector?.selectAccount(context, this.accountSelectionHandler); } /** * The authenticator selection interaction. * * The implementing class must ask the user to choose one of the authenticators * exposed by the {@link AuthenticatorSelectionContext} and provide the choice to the * {@link AuthenticatorSelectionHandler}. * * Note, that in the case of transaction confirmation (which can be considered * a special case of authentication) the implementing classes must present * the contents of the transaction (if any) to the user for verification * @see {@link AuthenticatorSelectionContext.transactionConfirmationData} * * @param context the object containing the list of existing authenticators. */ selectAuthenticator(context) { this.authenticatorSelector?.selectAuthenticator(context, this.authenticatorSelectionHandler); } /** * The method that will be invoked till either the user provides a PIN that * conforms with the format specified by the {@link PinPolicy} or till the * operation is cancelled (through the {@link PinEnrollmentHandler.cancel}). * * @param context the context. */ enrollPin(context) { this.pinEnroller?.enrollPin(context, this.pinEnrollmentHandler); } /** * The method that will be invoked till either the user provides a password that * conforms with the format specified by the {@link PasswordPolicy} or till the * operation is cancelled (through the {@link PasswordEnrollmentHandler.cancel}). * * @param context the context. */ enrollPassword(context) { this.passwordEnroller?.enrollPassword(context, this.passwordEnrollmentHandler); } /** * The method that will be invoked till either the user provides the old PIN * and a new PIN that conforms with the format specified by the {@link PinPolicy}, * or till the operation is cancelled (through the {@link PinChangeHandler.cancel}), * or till the PIN authenticator is permanently locked because the user provided * too many times an invalid PIN. * * @param context the context. */ changePin(context) { this.pinChanger?.changePin(context, this.pinChangeHandler); } /** * The method that will be invoked till either the user provides the old password * and a new password that conforms with the format specified by the {@link PasswordPolicy}, * or till the operation is cancelled (through the {@link PasswordChangeHandler.cancel}), * or till the password authenticator is permanently locked because the user provided * too many times an invalid password. * * @param context the context. */ changePassword(context) { this.passwordChanger?.changePassword(context, this.passwordChangeHandler); } /** * The user verification interaction. * * In the case of the registration the user must provide credentials again as * required by the FIDO UAF protocol. * In the case of the authentication, this is invoked for the user to provide * credentials. * * If the user provided invalid credentials, and it results in a non-recoverable * error, then `onSuccess` method will be invoked. * * @param context the object providing the information required for the verification * process. * @param handler the object that must be notified with the result of the interaction. */ verifyUser(context, handler) { switch (context.authenticator.aaid) { case _Aaid.Aaid.PIN.rawValue(): return this.pinUserVerifier.verifyPin(context, handler); case _Aaid.Aaid.PASSWORD.rawValue(): return this.passwordUserVerifier.verifyPassword(context, handler); case _Aaid.Aaid.BIOMETRIC.rawValue(): return this.biometricUserVerifier.verifyBiometric(context, handler); case _Aaid.Aaid.DEVICE_PASSCODE.rawValue(): return this.devicePasscodeUserVerifier.verifyDevicePasscode(context, handler); case _Aaid.Aaid.FINGERPRINT.rawValue(): return this.fingerprintUserVerifier.verifyFingerprint(context, handler); } return Promise.reject(new Error(`No verifier found for Authenticator aaid ${context.authenticator.aaid} when verifying the user.`)); } /** * This method is invoked when either valid local system credentials (biometric, * fingerprint) or valid SDK-managed credentials (PIN, password) were provided * and verified locally. * * This method can be used for instance to display some progress message * indicating that the operation is ongoing. * * Note that invoking this method does not mean that the UAF operation completed * successfully (this is notified through `onSuccess` methods once the FIDO UAF * server validates the request generated with the credentials). * * @param authenticator the object describing the authenticator where credentials * were validated. */ onValidCredentialsProvided(authenticator) { switch (authenticator.aaid) { case _Aaid.Aaid.PIN.rawValue(): return this.pinUserVerifier?.onValidCredentialsProvided(); case _Aaid.Aaid.PASSWORD.rawValue(): return this.passwordUserVerifier?.onValidCredentialsProvided(); case _Aaid.Aaid.BIOMETRIC.rawValue(): return this.biometricUserVerifier?.onValidCredentialsProvided(); case _Aaid.Aaid.DEVICE_PASSCODE.rawValue(): return this.devicePasscodeUserVerifier?.onValidCredentialsProvided(); case _Aaid.Aaid.FINGERPRINT.rawValue(): return this.fingerprintUserVerifier?.onValidCredentialsProvided(); } throw new Error(`No verifier found for Authenticator aaid ${authenticator.aaid} when valid credentials provided.`); } /** * Performs validation other than the minimum and maximum PIN length during PIN enrollment. * * @param pin the PIN to be validated. */ validatePinForEnrollment(pin) { this.pinEnroller?.pinPolicy.validatePinForEnrollment(pin, () => { (async () => { const message = new _PinValidatedMessage.PinValidatedMessage(this.operationId, undefined, undefined); await _MobileAuthenticationSdk.default.pinValidatedForEnrollment(message); })(); }, error => { (async () => { const message = new _PinValidatedMessage.PinValidatedMessage(this.operationId, error.description, error.cause); await _MobileAuthenticationSdk.default.pinValidatedForEnrollment(message); })(); }); } /** * Performs validation during password enrollment. * * @param password the password to be validated. */ validatePasswordForEnrollment(password) { this.passwordEnroller?.passwordPolicy.validatePasswordForEnrollment(password, () => { (async () => { const message = new _PasswordValidatedMessage.PasswordValidatedMessage(this.operationId, undefined, undefined); await _MobileAuthenticationSdk.default.passwordValidatedForEnrollment(message); })(); }, error => { (async () => { const message = new _PasswordValidatedMessage.PasswordValidatedMessage(this.operationId, error.description, error.cause); await _MobileAuthenticationSdk.default.passwordValidatedForEnrollment(message); })(); }); } /** * Performs validation other than the minimum and maximum PIN length during PIN change. * * @param pin the PIN to be validated. */ validatePinForPinChange(pin) { this.pinChanger?.pinPolicy.validatePinForPinChange(pin, () => { (async () => { const message = new _PinValidatedMessage.PinValidatedMessage(this.operationId, undefined, undefined); await _MobileAuthenticationSdk.default.pinValidatedForPinChange(message); })(); }, error => { (async () => { const message = new _PinValidatedMessage.PinValidatedMessage(this.operationId, error.description, error.cause); await _MobileAuthenticationSdk.default.pinValidatedForPinChange(message); })(); }); } /** * Performs validation during password enrollment. * * @param password the password to be validated. */ validatePasswordForPasswordChange(password) { this.passwordChanger?.passwordPolicy.validatePasswordForPasswordChange(password, () => { (async () => { const message = new _PasswordValidatedMessage.PasswordValidatedMessage(this.operationId, undefined, undefined); await _MobileAuthenticationSdk.default.passwordValidatedForPasswordChange(message); })(); }, error => { (async () => { const message = new _PasswordValidatedMessage.PasswordValidatedMessage(this.operationId, error.description, error.cause); await _MobileAuthenticationSdk.default.passwordValidatedForPasswordChange(message); })(); }); } } exports.UserInteractionPlatformOperation = UserInteractionPlatformOperation; class UserInteractionPlatformOperationImpl extends UserInteractionPlatformOperation { constructor(operationId, accountSelector, authenticatorSelector, pinEnroller, passwordEnroller, pinChanger, passwordChanger, pinUserVerifier, passwordUserVerifier, biometricUserVerifier, devicePasscodeUserVerifier, fingerprintUserVerifier) { super(); this.operationId = operationId; this.accountSelector = accountSelector; this.authenticatorSelector = authenticatorSelector; this.pinEnroller = pinEnroller; this.passwordEnroller = passwordEnroller; this.pinChanger = pinChanger; this.passwordChanger = passwordChanger; this.pinUserVerifier = pinUserVerifier; this.passwordUserVerifier = passwordUserVerifier; this.biometricUserVerifier = biometricUserVerifier; this.devicePasscodeUserVerifier = devicePasscodeUserVerifier; this.fingerprintUserVerifier = fingerprintUserVerifier; this.accountSelectionHandler = new _AccountSelectionHandler.AccountSelectionHandlerImpl(operationId); this.authenticatorSelectionHandler = new _AuthenticatorSelectionHandler.AuthenticatorSelectionHandlerImpl(operationId); this.pinEnrollmentHandler = new _PinEnrollmentHandler.PinEnrollmentHandlerImpl(operationId); this.passwordEnrollmentHandler = new _PasswordEnrollmentHandler.PasswordEnrollmentHandlerImpl(operationId); this.pinChangeHandler = new _PinChangeHandler.PinChangeHandlerImpl(operationId); this.passwordChangeHandler = new _PasswordChangeHandler.PasswordChangeHandlerImpl(operationId); } } exports.UserInteractionPlatformOperationImpl = UserInteractionPlatformOperationImpl; //# sourceMappingURL=UserInteractionPlatformOperation.js.map