Liferay.Loader.define("multi-factor-authentication-fido2-web@1.0.0/js/webauthn", ['module', 'exports', 'require', './base64url'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    function _typeof(obj) {
      "@babel/helpers - typeof";
      if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
        _typeof = function _typeof(obj) {
          return typeof obj;
        };
      } else {
        _typeof = function _typeof(obj) {
          return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
        };
      }return _typeof(obj);
    }

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.create = create;
    exports.credentialToObject = credentialToObject;
    exports.get = get;

    var base64Url = _interopRequireWildcard(require("./base64url"));

    function _getRequireWildcardCache() {
      if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function _getRequireWildcardCache() {
        return cache;
      };return cache;
    }

    function _interopRequireWildcard(obj) {
      if (obj && obj.__esModule) {
        return obj;
      }if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
        return { default: obj };
      }var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {
        return cache.get(obj);
      }var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {
            Object.defineProperty(newObj, key, desc);
          } else {
            newObj[key] = obj[key];
          }
        }
      }newObj.default = obj;if (cache) {
        cache.set(obj, newObj);
      }return newObj;
    }

    function ownKeys(object, enumerableOnly) {
      var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {
          return Object.getOwnPropertyDescriptor(object, sym).enumerable;
        });keys.push.apply(keys, symbols);
      }return keys;
    }

    function _objectSpread(target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {
          ownKeys(Object(source), true).forEach(function (key) {
            _defineProperty(target, key, source[key]);
          });
        } else if (Object.getOwnPropertyDescriptors) {
          Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
        } else {
          ownKeys(Object(source)).forEach(function (key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
          });
        }
      }return target;
    }

    function _defineProperty(obj, key, value) {
      if (key in obj) {
        Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
      } else {
        obj[key] = value;
      }return obj;
    }

    /**
     * Creates a credential
     *
     * @param {Object} options A PublicKeyCredentialCreationOptions object,
     *	where binary values are base64url encoded strings instead of byte arrays
     *
     * @returns {Promise<Credential|null>}
     */
    function create(options) {
      return navigator.credentials.create({
        publicKey: decodeCredentialCreationOptions(options)
      });
    }
    /**
     * Convert a PublicKeyCredential into an Object with base64 encoded binary values
     *
     * @param {PublicKeyCredential} credential The PublicKeyCredential to convert
     *
     * @returns {Object}
     */

    function credentialToObject(credential) {
      var clientExtensionResults = {};

      try {
        clientExtensionResults = credential.getClientExtensionResults();
      } catch (e) {
        console.error('getClientExtensionResults failed', e);
      }

      var id = credential.id,
          response = credential.response,
          type = credential.type;

      if (response.attestationObject) {
        return {
          clientExtensionResults: clientExtensionResults,
          id: id,
          response: {
            attestationObject: base64Url.fromByteArray(response.attestationObject),
            clientDataJSON: base64Url.fromByteArray(response.clientDataJSON)
          },
          type: type
        };
      } else {
        return {
          clientExtensionResults: clientExtensionResults,
          id: id,
          response: {
            authenticatorData: base64Url.fromByteArray(response.authenticatorData),
            clientDataJSON: base64Url.fromByteArray(response.clientDataJSON),
            signature: base64Url.fromByteArray(response.signature),
            userHandle: response.userHandle && base64Url.fromByteArray(response.userHandle)
          },
          type: type
        };
      }
    }

    function decodeCredentialCreationOptions(request) {
      var excludeCredentials = request.excludeCredentials.map(function (credential) {
        return _objectSpread(_objectSpread({}, credential), {}, {
          id: base64Url.toByteArray(credential.id)
        });
      });
      return _objectSpread(_objectSpread({}, request), {}, {
        attestation: 'direct',
        challenge: base64Url.toByteArray(request.challenge),
        excludeCredentials: excludeCredentials,
        user: _objectSpread(_objectSpread({}, request.user), {}, {
          id: base64Url.toByteArray(request.user.id)
        })
      });
    }

    function decodeCredentialRequestOptions(request) {
      var allowCredentials = request.allowCredentials && request.allowCredentials.map(function (credential) {
        return _objectSpread(_objectSpread({}, credential), {}, {
          id: base64Url.toByteArray(credential.id)
        });
      });
      return _objectSpread(_objectSpread({}, request), {}, {
        allowCredentials: allowCredentials,
        challenge: base64Url.toByteArray(request.challenge)
      });
    }
    /**
     * Returns a Promise to a single Credential instance that matches the provided parameters.
     * If no match is found the Promise will resolve to null.
     *
     * @param {CredentialRequestOptions} options PublicKeyCredentialRequestOptions object
     *
     * @returns {Promise<Credential|null>}
     */

    function get(options) {
      return navigator.credentials.get({
        publicKey: decodeCredentialRequestOptions(options)
      });
    }
    //# sourceMappingURL=webauthn.js.map
  }
});
//# sourceMappingURL=webauthn.js.map