bitaddress.org/src/ninja.brainwallet.js

68 lines
2.6 KiB
JavaScript
Raw Normal View History

2013-08-28 04:05:31 +02:00
ninja.wallets.brainwallet = {
2015-07-05 23:14:49 +02:00
isOpen: function () {
return (document.getElementById("brainwallet").className.indexOf("selected") != -1);
},
2013-08-28 04:05:31 +02:00
open: function () {
document.getElementById("brainarea").style.display = "block";
document.getElementById("brainpassphrase").focus();
2013-11-03 21:27:03 +01:00
document.getElementById("brainwarning").innerHTML = ninja.translator.get("brainalertpassphrasewarning");
2013-08-28 04:05:31 +02:00
},
close: function () {
document.getElementById("brainarea").style.display = "none";
},
minPassphraseLength: 15,
view: function () {
var key = document.getElementById("brainpassphrase").value.toString()
2013-08-28 04:05:31 +02:00
document.getElementById("brainpassphrase").value = key;
var keyConfirm = document.getElementById("brainpassphraseconfirm").value.toString()
2013-08-28 04:05:31 +02:00
document.getElementById("brainpassphraseconfirm").value = keyConfirm;
if (key == keyConfirm || document.getElementById("brainpassphraseshow").checked) {
// enforce a minimum passphrase length
if (key.length >= ninja.wallets.brainwallet.minPassphraseLength) {
var bytes = Crypto.SHA256(key, { asBytes: true });
var btcKey = new Bitcoin.ECKey(bytes);
var isCompressed = document.getElementById("braincompressed").checked;
btcKey.setCompressed(isCompressed);
2013-08-28 04:05:31 +02:00
var bitcoinAddress = btcKey.getBitcoinAddress();
var privWif = btcKey.getBitcoinWalletImportFormat();
document.getElementById("brainbtcaddress").innerHTML = bitcoinAddress;
document.getElementById("brainbtcprivwif").innerHTML = privWif;
ninja.qrCode.showQrCode({
"brainqrcodepublic": bitcoinAddress,
"brainqrcodeprivate": privWif
});
document.getElementById("brainkeyarea").style.visibility = "visible";
}
else {
2013-11-03 21:27:03 +01:00
alert(ninja.translator.get("brainalertpassphrasetooshort") + ninja.translator.get("brainalertpassphrasewarning"));
2013-08-28 04:05:31 +02:00
ninja.wallets.brainwallet.clear();
}
}
else {
alert(ninja.translator.get("brainalertpassphrasedoesnotmatch"));
ninja.wallets.brainwallet.clear();
}
},
clear: function () {
document.getElementById("brainkeyarea").style.visibility = "hidden";
},
showToggle: function (element) {
if (element.checked) {
document.getElementById("brainpassphrase").setAttribute("type", "text");
document.getElementById("brainpassphraseconfirm").style.visibility = "hidden";
document.getElementById("brainlabelconfirm").style.visibility = "hidden";
}
else {
document.getElementById("brainpassphrase").setAttribute("type", "password");
document.getElementById("brainpassphraseconfirm").style.visibility = "visible";
document.getElementById("brainlabelconfirm").style.visibility = "visible";
}
}
};