From 06317d1812219c592e3340715120cfc454792498 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 30 Apr 2018 21:34:41 -0600 Subject: [PATCH] conditionally load forge --- authenticator.js | 17 ++++++++++++++++- index.html | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/authenticator.js b/authenticator.js index 1512174..dbbd79c 100644 --- a/authenticator.js +++ b/authenticator.js @@ -5,7 +5,14 @@ var Authenticator = exports.Authenticator || exports; var Unibabel = window.Unibabel; // || require('unibabel'); var totp = window.totp; // || require('notp').totp; -if (!window.crypto) { +function loadForge() { + var script = document.createElement('script'); + script.src = 'demo/bower_components/forge/dist/forge.min.js'; + script.addEventListener('load', collectRandom); + document.body.appendChild(script); +} + +function collectRandom() { document.addEventListener('mousemove', function (event) { var ev = event || window.event; @@ -14,6 +21,14 @@ if (!window.crypto) { }); } +if (!window.crypto) { + if (!window.forge) { + loadForge(); + } else { + collectRandom(); + } +} + // Generate a key function generateOtpKey() { // 20 cryptographically random binary bytes (160-bit key) diff --git a/index.html b/index.html index b48f353..ddb85f5 100644 --- a/index.html +++ b/index.html @@ -93,7 +93,9 @@ +