ninja.wallets.paperwallet = { open: function () { document.getElementById("main").setAttribute("class", "paper"); // add 'paper' class to main div var paperArea = document.getElementById("paperarea"); paperArea.style.display = "block"; var perPageLimitElement = document.getElementById("paperlimitperpage"); var limitElement = document.getElementById("paperlimit"); var pageBreakAt = (ninja.wallets.paperwallet.useArtisticWallet) ? ninja.wallets.paperwallet.pageBreakAtArtisticDefault : ninja.wallets.paperwallet.pageBreakAtDefault; if (perPageLimitElement && perPageLimitElement.value < 1) { perPageLimitElement.value = pageBreakAt; } if (limitElement && limitElement.value < 1) { limitElement.value = pageBreakAt; } if (document.getElementById("paperkeyarea").innerHTML == "") { ninja.wallets.paperwallet.build(pageBreakAt, pageBreakAt, !document.getElementById('paperart').checked); } }, close: function () { document.getElementById("paperarea").style.display = "none"; document.getElementById("main").setAttribute("class", ""); // remove 'paper' class from main div }, remaining: null, // use to keep track of how many addresses are left to process when building the paper wallet count: 0, pageBreakAtDefault: 7, pageBreakAtArtisticDefault: 3, useArtisticWallet: true, pageBreakAt: null, build: function (numWallets, pageBreakAt, useArtisticWallet) { if (numWallets < 1) numWallets = 1; if (pageBreakAt < 1) pageBreakAt = 1; ninja.wallets.paperwallet.remaining = numWallets; ninja.wallets.paperwallet.count = 0; ninja.wallets.paperwallet.useArtisticWallet = useArtisticWallet; ninja.wallets.paperwallet.pageBreakAt = pageBreakAt; document.getElementById("paperkeyarea").innerHTML = ""; setTimeout(ninja.wallets.paperwallet.batch, 0); }, batch: function () { if (ninja.wallets.paperwallet.remaining > 0) { var paperArea = document.getElementById("paperkeyarea"); ninja.wallets.paperwallet.count++; var i = ninja.wallets.paperwallet.count; var pageBreakAt = ninja.wallets.paperwallet.pageBreakAt; var div = document.createElement("div"); div.setAttribute("id", "keyarea" + i); if (ninja.wallets.paperwallet.useArtisticWallet) { div.innerHTML = ninja.wallets.paperwallet.templateArtisticHtml(i); div.setAttribute("class", "keyarea art"); } else { div.innerHTML = ninja.wallets.paperwallet.templateHtml(i); div.setAttribute("class", "keyarea"); } if (paperArea.innerHTML != "") { // page break if ((i - 1) % pageBreakAt == 0 && i >= pageBreakAt) { var pBreak = document.createElement("div"); pBreak.setAttribute("class", "pagebreak"); document.getElementById("paperkeyarea").appendChild(pBreak); div.style.pageBreakBefore = "always"; if (!ninja.wallets.paperwallet.useArtisticWallet) { div.style.borderTop = "2px solid green"; } } } document.getElementById("paperkeyarea").appendChild(div); ninja.wallets.paperwallet.generateNewWallet(i); ninja.wallets.paperwallet.remaining--; setTimeout(ninja.wallets.paperwallet.batch, 0); } }, // generate bitcoin address, private key, QR Code and update information in the HTML // idPostFix: 1, 2, 3, etc. generateNewWallet: function (idPostFix) { var key = new Bitcoin.ECKey(false); var bitcoinAddress = key.getBitcoinAddress(); var privateKeyWif = key.getBitcoinWalletImportFormat(); if (ninja.wallets.paperwallet.useArtisticWallet) { ninja.wallets.paperwallet.showArtisticWallet(idPostFix, bitcoinAddress, privateKeyWif); } else { ninja.wallets.paperwallet.showWallet(idPostFix, bitcoinAddress, privateKeyWif); } }, templateHtml: function (i) { var walletHtml = "