ninja.seeder = { // number of mouse movements to wait for seedLimit: (function () { var num = Crypto.util.randomBytes(12)[11]; return 200 + Math.floor(num); })(), seedCount: 0, // counter // seed function exists to wait for mouse movement to add more entropy before generating an address seed: function (evt) { if (!evt) var evt = window.event; // seed a bunch (minimum seedLimit) of times based on mouse moves SecureRandom.seedTime(); // seed mouse position X and Y if (evt) SecureRandom.seedInt16((evt.clientX * evt.clientY)); ninja.seeder.seedCount++; // seeding is over now we generate and display the address if (ninja.seeder.seedCount == ninja.seeder.seedLimit) { ninja.wallets.singlewallet.open(); // UI document.getElementById("generate").style.display = "none"; document.getElementById("menu").style.visibility = "visible"; } if (SecureRandom.poolCopyOnInit != null) { document.getElementById("seedpool").innerHTML = Crypto.util.bytesToHex(SecureRandom.poolCopyOnInit); } else { document.getElementById("seedpool").innerHTML = Crypto.util.bytesToHex(SecureRandom.pool); } }, // If user has not moved the mouse or if they are on a mobile device // we will force the generation after a random period of time. forceGenerate: function () { // if the mouse has not moved enough if (ninja.seeder.seedCount < ninja.seeder.seedLimit) { SecureRandom.seedTime(); ninja.seeder.seedCount = ninja.seeder.seedLimit - 1; ninja.seeder.seed(); } } }; ninja.qrCode = { // determine which type number is big enough for the input text length getTypeNumber: function (text) { var lengthCalculation = text.length * 8 + 12; // length as calculated by the QRCode if (lengthCalculation < 72) { return 1; } else if (lengthCalculation < 128) { return 2; } else if (lengthCalculation < 208) { return 3; } else if (lengthCalculation < 288) { return 4; } else if (lengthCalculation < 368) { return 5; } else if (lengthCalculation < 480) { return 6; } else if (lengthCalculation < 528) { return 7; } else if (lengthCalculation < 688) { return 8; } else if (lengthCalculation < 800) { return 9; } else if (lengthCalculation < 976) { return 10; } return null; }, createCanvas: function (text, sizeMultiplier) { sizeMultiplier = (sizeMultiplier == undefined) ? 2 : sizeMultiplier; // default 2 // create the qrcode itself var typeNumber = ninja.qrCode.getTypeNumber(text); var qrcode = new QRCode(typeNumber, QRCode.ErrorCorrectLevel.H); qrcode.addData(text); qrcode.make(); var width = qrcode.getModuleCount() * sizeMultiplier; var height = qrcode.getModuleCount() * sizeMultiplier; // create canvas element var canvas = document.createElement('canvas'); var scale = 10.0; canvas.width = width * scale; canvas.height = height * scale; canvas.style.width = width + 'px'; canvas.style.height = height + 'px'; var ctx = canvas.getContext('2d'); ctx.scale(scale, scale); // compute tileW/tileH based on width/height var tileW = width / qrcode.getModuleCount(); var tileH = height / qrcode.getModuleCount(); // draw in the canvas for (var row = 0; row < qrcode.getModuleCount(); row++) { for (var col = 0; col < qrcode.getModuleCount(); col++) { ctx.fillStyle = qrcode.isDark(row, col) ? "#000000" : "#ffffff"; ctx.fillRect(col * tileW, row * tileH, tileW, tileH); } } // return just built canvas return canvas; }, // generate a QRCode and return it's representation as an Html table createTableHtml: function (text) { var typeNumber = ninja.qrCode.getTypeNumber(text); var qr = new QRCode(typeNumber, QRCode.ErrorCorrectLevel.H); qr.addData(text); qr.make(); var tableHtml = "
"; } else { tableHtml += " | "; } } tableHtml += " |