169 lines
184 KiB
JavaScript
169 lines
184 KiB
JavaScript
|
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 =
|
||
|
"<div class='public'>" +
|
||
|
"<div id='qrcode_public" + i + "' class='qrcode_public'></div>" +
|
||
|
"<div class='pubaddress'>" +
|
||
|
"<span class='label'>" + ninja.translator.get("paperlabelbitcoinaddress") + "</span>" +
|
||
|
"<span class='output' id='btcaddress" + i + "'></span>" +
|
||
|
"</div>" +
|
||
|
"</div>" +
|
||
|
"<div class='private'>" +
|
||
|
"<div id='qrcode_private" + i + "' class='qrcode_private'></div>" +
|
||
|
"<div class='privwif'>" +
|
||
|
"<span class='label'>" + ninja.translator.get("paperlabelprivatekey") + "</span>" +
|
||
|
"<span class='output' id='btcprivwif" + i + "'></span>" +
|
||
|
"</div>" +
|
||
|
"</div>";
|
||
|
return walletHtml;
|
||
|
},
|
||
|
|
||
|
showWallet: function (idPostFix, bitcoinAddress, privateKeyWif) {
|
||
|
document.getElementById("btcaddress" + idPostFix).innerHTML = bitcoinAddress;
|
||
|
document.getElementById("btcprivwif" + idPostFix).innerHTML = privateKeyWif;
|
||
|
var keyValuePair = {};
|
||
|
keyValuePair["qrcode_public" + idPostFix] = bitcoinAddress;
|
||
|
keyValuePair["qrcode_private" + idPostFix] = privateKeyWif;
|
||
|
ninja.qrCode.showQrCode(keyValuePair);
|
||
|
document.getElementById("keyarea" + idPostFix).style.display = "block";
|
||
|
},
|
||
|
|
||
|
templateArtisticHtml: function (i) {
|
||
|
var walletHtml =
|
||
|
"<div class='artwallet' id='artwallet" + i + "'>" +
|
||
|
//"<iframe src='bitcoin-wallet-01.svg' id='papersvg" + i + "' class='papersvg' ></iframe>" +
|
||
|
"<img id='papersvg" + i + "' class='papersvg' src='data:image/png;base64,iVBORw0KGgoAAA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5R1vQlxgiRiKkXZ8Q9JQksKUADNzgrIREfbhFzZi0exIepicElQJc8SyhwgVHLsi7ehWVr8Pn5h8svVKvj1MB6bGIdEq3sXHVdFecR515RjLnFOVsCa6sYdZP9F7Jo+TYgNdPw6szbtyuxm5Uc32iznamNI7Pf1O1+5sQBAIAkyZg4cxSJzj50dPdj885rVgTMJIeB0CowKe8WA+EX8pMUOQZENwHWNGAn37dpRNQigAbg3DHE0tJ31rMkQAI5aQIYkDSGpAtw8kyQnRPKJ/sVA8MtgiP9QrGV9YAvwuJv3xVuVXMeJaOEFR2sRkBmkiAbTJ4F1hNiwWYfKEwD4V7hGnaygGuKbzAgN0VkGwdO7aHdrzxJn/rVP/S7BtZjdvoMstksF1mDPT+GTZsv4+5EBy/MjdHc9HGsX7WakZ8AK1FAi7NwrQNMCogtQfDKF4RiooSZtZhQPEDCgrYWhXvbtUDWgnCNSwrId8GhPvF7axFwsgStjVmNgZyM8LSiKLDBTAqFINTNPmmYGD9GJ47twfiZQ1QorNDwAwBmWHYRll1EenGOJsaDtYOIEolejKzayGvWbObunmGwpIPDfSArXUtcWy6SClbC4tgGHJnyFPT2JeQtWVjivl22xMEMllWhsHhF8eybeKbrk79WIisFZt8+f7ftUvHdmk0zZ/ZR78j2c1uTg1jS4twZhKId0EOx6v3NiFDlYy4QBpoBu283JxM0g6CmgN9gn52tz0B3i/Xn4WQBNVa7vZ
|
||
|
"<div id='qrcode_public" + i + "' class='qrcode_public'></div>" +
|
||
|
"<div id='qrcode_private" + i + "' class='qrcode_private'></div>" +
|
||
|
"<div class='btcaddress' id='btcaddress" + i + "'></div>" +
|
||
|
"<div class='btcprivwif' id='btcprivwif" + i + "'></div>" +
|
||
|
"</div>";
|
||
|
return walletHtml;
|
||
|
},
|
||
|
|
||
|
showArtisticWallet: function (idPostFix, bitcoinAddress, privateKeyWif) {
|
||
|
var keyValuePair = {};
|
||
|
keyValuePair["qrcode_public" + idPostFix] = bitcoinAddress;
|
||
|
keyValuePair["qrcode_private" + idPostFix] = privateKeyWif;
|
||
|
ninja.qrCode.showQrCode(keyValuePair, 2.5);
|
||
|
document.getElementById("btcaddress" + idPostFix).innerHTML = bitcoinAddress;
|
||
|
document.getElementById("btcprivwif" + idPostFix).innerHTML = privateKeyWif;
|
||
|
|
||
|
// CODE to modify SVG DOM elements
|
||
|
//var paperSvg = document.getElementById("papersvg" + idPostFix);
|
||
|
//if (paperSvg) {
|
||
|
// svgDoc = paperSvg.contentDocument;
|
||
|
// if (svgDoc) {
|
||
|
// var bitcoinAddressElement = svgDoc.getElementById("bitcoinaddress");
|
||
|
// var privateKeyElement = svgDoc.getElementById("privatekey");
|
||
|
// if (bitcoinAddressElement && privateKeyElement) {
|
||
|
// bitcoinAddressElement.textContent = bitcoinAddress;
|
||
|
// privateKeyElement.textContent = privateKeyWif;
|
||
|
// }
|
||
|
// }
|
||
|
//}
|
||
|
},
|
||
|
|
||
|
toggleArt: function (element) {
|
||
|
if (!element.checked) {
|
||
|
// show Art
|
||
|
document.getElementById("paperlimitperpage").value = ninja.wallets.paperwallet.pageBreakAtArtisticDefault;
|
||
|
document.getElementById("paperlimit").value = ninja.wallets.paperwallet.pageBreakAtArtisticDefault;
|
||
|
}
|
||
|
else {
|
||
|
// hide Art
|
||
|
document.getElementById("paperlimitperpage").value = ninja.wallets.paperwallet.pageBreakAtDefault;
|
||
|
document.getElementById("paperlimit").value = ninja.wallets.paperwallet.pageBreakAtDefault;
|
||
|
}
|
||
|
}
|
||
|
};
|