forked from dsias/blockchain.info
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallet.min.js
1 lines (1 loc) · 64.4 KB
/
wallet.min.js
1
function precisionToSatoshiBN(a){return Bitcoin.Util.parseValue(a).divide(BigInteger.valueOf(Math.pow(10,sShift(symbol_btc)).toString()))}function precisionToBTC(a){return Bitcoin.Util.formatValue(precisionToSatoshiBN(a))}function precisionFromSatoshi(a){return Bitcoin.Util.formatValue(a.multiply(BigInteger.valueOf(Math.pow(10,sShift(symbol_btc)))))}function precisionFromBTC(a){return precisionFromSatoshi(Bitcoin.Util.parseValue(a))}function formatPrecision(a){return formatBTC(precisionToSatoshiBN(a).toString())}var MyWallet=new function(){var h=this;this.skip_init=false;var D="abcaa314-6f67-6705-b384-5d47fbe9d7cc";var ai;var M;var j;var aJ;var ak;var w;var d;var az=0;var S=0;var at=0;var K=0;var aU=0;var aH;var g={};var E=[];var F=false;var ax=0;var ar=0;var aC=1000;var I={};var aA;var am;var x=0.5;var ag=10;var P=ag;var b={};var q;var aP=0;var U;var Z=[];var B;var N=60000;var A=false;var aa;var aq=false;var X="en";var ao=2;var Q=0;var aM=0;var Y=false;var aE;var ap=false;var T=false;var aw=false;var s={pbkdf2_iterations:ag,fee_policy:0,html5_notifications:false,logout_time:600000,tx_display:0,always_keep_local_backup:false,transactions_per_page:30,additional_seeds:[]};this.setEncryptedWalletData=function(aW){if(!aW||aW.length==0){ai=null;aA=null;return}ai=aW;aA=ah();try{if(aP==0||s.always_keep_local_backup){MyStore.put("payload",ai)}}catch(aX){console.log(aX)}};this.setRealAuthType=function(aW){aP=aW};this.addAdditionalSeeds=function(aW){s.additional_seeds.push(aW)};this.getAdditionalSeeds=function(aW){return s.additional_seeds};this.getLanguage=function(){return X};this.setLanguage=function(aW){MyStore.put("language",aW);X=aW};this.addEventListener=function(aW){Z.push(aW)};this.getLogoutTime=function(){return s.logout_time};this.getSecondPasswordPbkdf2Iterations=function(){return s.pbkdf2_iterations};this.getMainPasswordPbkdf2Iterations=function(){return P};this.getDefaultPbkdf2Iterations=function(){return ag};this.getSharedcoinEndpoint=function(){return aE};this.disableLogout=function(aW){ap=aW};this.setLogoutTime=function(aW){s.logout_time=aW;clearInterval(U);U=setTimeout(h.logout,h.getLogoutTime())};this.getDoubleEncryption=function(){return F};this.getEncryptedWalletData=function(){return ai};this.getFeePolicy=function(){return s.fee_policy};this.setFeePolicy=function(aW){s.fee_policy=parseInt(aW)};this.setAlwaysKeepLocalBackup=function(aW){s.always_keep_local_backup=aW};this.getAlwaysKeepLocalBackup=function(){return s.always_keep_local_backup};this.setNTransactionsPerPage=function(aW){s.transactions_per_page=aW};this.getNTransactionsPerPage=function(){return s.transactions_per_page};this.getGuid=function(){return M};this.getHTML5Notifications=function(){return s.html5_notifications};this.setHTML5Notifications=function(aW){s.html5_notifications=aW};this.getTransactions=function(){return E};this.addressExists=function(aW){return I[aW]!=null};this.getAddressTag=function(aW){return I[aW].tag};this.setAddressTag=function(aX,aW){I[aX].tag=aW};this.getAddressBook=function(){return g};this.getAddressLabel=function(aW){return I[aW].label};this.setAddressLabel=function(aW,aX){I[aW].label=aX};this.setAddressBalance=function(aW,aX){I[aW].balance=aX};this.getAddressBookLabel=function(aW){return g[aW]};this.isWatchOnly=function(aW){return !I[aW]||I[aW].priv==null};this.getAddressBalance=function(aW){return I[aW].balance};this.getMixerFee=function(){return x};this.deleteAddress=function(aW){delete I[aW]};this.addAddressBookEntry=function(aX,aW){g[aX]=aW};this.getPrivateKey=function(aW){return I[aW].priv};this.setLabel=function(aW,aX){I[aW].label=aX;h.backupWalletDelayed();c()};this.securePost=function(aW,aZ,a6,a3){var a2=jQuery.extend({},aZ);if(!aZ.sharedKey){if(!d||d.length==0||d.length!=36){throw"Shared key is invalid"}var aX=new Date().getTime();var a1=parseInt((aX-aM)/10000);var a0=Crypto.SHA256(d.toLowerCase()+a1);var aY=0;var a5=a0.substring(aY,aY+=8)+"-"+a0.substring(aY,aY+=4)+"-"+a0.substring(aY,aY+=4)+"-"+a0.substring(aY,aY+=4)+"-"+a0.substring(aY,aY+=12);a2.sharedKey=a5;a2.sKTimestamp=a1;a2.sKDebugHexHash=a0;a2.sKDebugTimeOffset=aM;a2.sKDebugOriginalClientTime=aX;a2.sKDebugOriginalSharedKey=d}if(!aZ.guid){a2.guid=M}a2.format=aZ.format?aZ.format:"plain";var a4="text";if(aZ.format=="json"){a4="json"}$.ajax({dataType:a4,type:"POST",url:root+aW,data:a2,success:a6,error:a3})};this.isCorrectMainPassword=function(aW){return aJ==aW};function ae(aX,aZ){var aW=Crypto.SHA256(aX,{asBytes:true});for(var aY=1;aY<aZ;++aY){aW=Crypto.SHA256(aW,{asBytes:true})}return Crypto.util.bytesToHex(aW)}this.setPbkdf2Iterations=function(aW,aY){var aX=function(aZ){console.log("Panic "+aZ);window.location.reload()};h.getSecondPassword(function(){try{if(F){for(var aZ in I){var a1=I[aZ];if(a1.priv){a1.priv=h.encrypt(h.decryptPK(a1.priv),d+ak,aW);if(!a1.priv){throw"addr.priv is null"}}}s.pbkdf2_iterations=aW;w=ae(d+ak,aW)}Q=2;P=aW;h.backupWallet("update",function(){aY()},function(){aX(a0)})}catch(a0){aX(a0)}},function(aZ){aX(aZ)})};this.setDoubleEncryption=function(aY,aW,a0){var aX=function(a1){console.log("Panic "+a1);window.location.reload()};try{if(F==aY){return}if(aY){h.getSecondPassword(function(){try{F=true;ak=aW;for(var a1 in I){var a3=I[a1];if(a3.priv){a3.priv=i(B58.decode(a3.priv));if(!a3.priv){throw"addr.priv is null"}}}w=ae(d+ak,s.pbkdf2_iterations);ak=null;h.getSecondPassword(function(){try{h.checkAllKeys();h.backupWallet("update",function(){a0()},function(){aX(a4)})}catch(a4){aX(a4)}},function(a4){aX(a4)})}catch(a2){aX(a2)}},function(a1){aX(a1)})}else{h.getSecondPassword(function(){try{for(var a1 in I){var a3=I[a1];if(a3.priv){a3.priv=h.decryptPK(a3.priv);if(!a3.priv){throw"addr.priv is null"}}}F=false;ak=null;h.checkAllKeys();h.backupWallet("update",function(){a0()},function(){aX(a2)})}catch(a2){aX(a2)}},function(a1){aX(a1)})}}catch(aZ){aX(aZ)}};this.unArchiveAddr=function(aW){var aW=I[aW];if(aW.tag==2){aW.tag=null;c();h.backupWalletDelayed("update",function(){h.get_history()})}else{h.makeNotice("error","add-error","Cannot Unarchive This Address")}};this.archiveAddr=function(aW){if(h.getActiveAddresses().length<=1){h.makeNotice("error","add-error","You must leave at least one active address");return}var aW=I[aW];if(aW.tag==null||aW.tag==0){aW.tag=2;c();h.backupWalletDelayed("update",function(){h.get_history()})}else{h.makeNotice("error","add-error","Cannot Archive This Address")}};this.addWatchOnlyAddress=function(aW){return aS(aW)};this.addPrivateKey=function(aW,aY){if(aj()){return false}if(aW==null){throw"Cannot add null key."}if(aY==null){aY={}}var a1=aY.compressed?aW.getBitcoinAddressCompressed().toString():aW.getBitcoinAddress().toString();var a0=i(aW.priv);if(a0==null){throw"Error Encoding key"}var aX=new Bitcoin.ECKey(h.decodePK(a0));if(a1!=aX.getBitcoinAddress().toString()&&a1!=aX.getBitcoinAddressCompressed().toString()){throw"Decoded Key address does not match generated address"}if(aS(a1,a0)){I[a1].tag=1;I[a1].created_time=aY.created_time?aY.created_time:0;I[a1].created_device_name=aY.app_name?aY.app_name:APP_NAME;I[a1].created_device_version=aY.app_version?aY.app_version:APP_VERSION;if(I[a1].priv!=a0){throw"Address priv does not match encoded"}try{ws.send('{"op":"addr_sub", "addr":"'+a1+'"}')}catch(aZ){}}else{throw"Unable to add generated bitcoin address."}return a1};this._seed=function(aY){rng_seed_time();if(aJ||aY){var aW=Crypto.util.bytesToWords(Crypto.SHA256(aJ?aJ:aY,{asBytes:true}));for(var aX in aW){rng_seed_int(aW[aX])}}if(!aa){aa=$("body").data("extra-seed")}if(aa){var aW=Crypto.util.bytesToWords(Crypto.util.hexToBytes(aa));for(var aX in aW){rng_seed_int(aW[aX])}}};this.generateNewKey=function(aX){h._seed(aX);var aW=new Bitcoin.ECKey(false);if(h.addPrivateKey(aW)){return aW}};this.setLoadingText=function(aW){$(".loading-text").text(aW)};function L(){try{$(".popover").remove()}catch(aW){}}$(window).resize(function(){$(".modal:visible").center();L()});function aR(aX,aW){aX.click(function(){z(aW.txIndex,aW.result)});aX.find(".show-note").mouseover(function(){var aY=aW.note?aW.note:b[aW.hash];aL(this,aY,aW.hash)});aX.find(".add-note").mouseover(function(){m(this,aW.hash)});return aX}function t(aX,a3){var aW=0;for(var aZ=0;aZ<aX.inputs.length;++aZ){var aY=aX.inputs[aZ].prev_out;if(!aY||!aY.addr){continue}var a2=I[aY.addr];if(a2){var a1=parseInt(aY.value);aW-=a1;if(a3){S+=a1;a2.balance-=a1}}}for(var a0=0;a0<aX.out.length;++a0){var aY=aX.out[a0];if(!aY||!aY.addr){continue}var a2=I[aY.addr];if(a2){var a1=parseInt(aY.value);aW+=a1;if(a3){at+=a1;a2.balance+=a1}}}return aW}function ah(){return Crypto.util.bytesToHex(Crypto.SHA256(ai,{asBytes:true}))}function y(aW){var aX=null;aW.onmessage=function(a4){try{var a1=$.parseJSON(a4.data);if(a1.op=="on_change"){var a5=ah();var a3=a1.checksum;console.log("On change old "+a5+" == new "+a3);if(aX!=a3&&a5!=a3){aX=a3;J()}}else{if(a1.op=="utx"){var a2=TransactionFromJSON(a1.x);for(var a7 in E){if(E[a7].txIndex==a2.txIndex){return}}var a9=t(a2,true);if(h.getHTML5Notifications()){h.showNotification({title:a9>0?"Payment Received":"Payment Sent",body:"Transaction Value "+formatBTC(a9),iconUrl:resource+"cube48.png"})}a2.result=a9;az+=a9;K++;a2.setConfirmations(0);playSound("beep");if(ar==0&&ax==0){E.unshift(a2);var a6=false;if(E.length>h.getNTransactionsPerPage()){E.pop();a6=true}}var aZ=V();if("my-transactions"==aZ){if(ar==0&&ax==0){$("#no-transactions").hide();if(s.tx_display==0){var aY=$("#transactions-compact").show();aR($(C(a2,I,g)),a2).prependTo(aY.find("tbody")).find("div").hide().slideDown("slow");if(a6){aY.find("tbody tr:last-child").remove()}}else{var aY=$("#transactions-detailed").show();aY.prepend(a2.getHTML(I,g));if(a6){aY.find("div:last-child").remove()}setupSymbolToggle()}}}else{c()}}else{if(a1.op=="block"){for(var a0=0;a0<a1.x.txIndexes.length;++a0){for(var a8=0;a8<E.length;++a8){if(E[a8].txIndex==a1.x.txIndexes[a0]){if(E[a8].blockHeight==null||E[a8].blockHeight==0){E[a8].blockHeight=a1.x.height;break}}}}ay(BlockFromJSON(a1.x));W()}}}}catch(a4){console.log(a4);console.log(a4.data)}};aW.onopen=function(){au("ok");var a1='{"op":"blocks_sub"}';if(M!=null){a1+='{"op":"wallet_sub","guid":"'+M+'"}'}try{var aZ=h.getActiveAddresses();for(var aY in aZ){a1+='{"op":"addr_sub", "addr":"'+aZ[aY]+'"}'}}catch(a0){alert(a0)}aW.send(a1)};aW.onclose=function(){au("error")}}var aQ="ok";function au(aX){var aW=$("#logout");if(aX=="loading_start"){aW.attr("src",resource+"logout-orange.png");return}else{if(aX!="loading_stop"){aQ=aX}}if(aQ=="ok"){aW.attr("src",resource+"logout.png")}else{if(aQ=="error"){aW.attr("src",resource+"logout-red.png")}}}this.showNotification=function(aW,aX){try{var aZ;if(window.webkitNotifications&&webkitNotifications.checkPermission()==0){aZ=webkitNotifications.createNotification(aW.iconUrl,aW.title,aW.body);aZ.show()}else{if(window.Notification&&window.Notification.permissionLevel()=="granted"){aZ=new window.Notification(aW.title,aW).show()}}setTimeout(function(){aZ.cancel()},aX?aX:5000)}catch(aY){}};this.makeNotice=function(aX,a0,aZ,aY){if(aZ==null||aZ.length==0){return}console.log(aZ);var aW=$('<div class="alert alert-block alert-'+aX+'"></div>');aW.text(""+aZ);if($("#"+a0).length>0){aW.attr("id",a0);return}$("#notices").append(aW).hide().fadeIn(200);(function(){var a1=aW;setTimeout(function(){a1.fadeOut(250,function(){$(this).remove()})},aY?aY:5000)})()};this.pkBytesToSipa=function(aW,a0){var aX=new Bitcoin.ECKey(aW);while(aW.length<32){aW.unshift(0)}aW.unshift(128);if(aX.getBitcoinAddress().toString()==a0){}else{if(aX.getBitcoinAddressCompressed().toString()==a0){aW.push(1)}else{throw"Private Key does not match bitcoin address"+a0}}var aY=Crypto.SHA256(Crypto.SHA256(aW,{asBytes:true}),{asBytes:true});aW=aW.concat(aY.slice(0,4));var aZ=B58.encode(aW);return aZ};function aG(aW){return aW}function av(aW){return h.decryptPK(aW)}function ac(aW){var aX=h.decodePK(aW);return Crypto.util.bytesToBase64(aX)}function k(aW){var aX=h.decodePK(aW);return Crypto.util.bytesToHex(aX)}this.base58ToSipa=function(aW,aX){return h.pkBytesToSipa(h.decodePK(aW),aX)};this.makeWalletJSON=function(aW){return h.makeCustomWalletJSON(aW,M,d)};this.makeCustomWalletJSON=function(a1,aX,a3){var a0=aG;if(a1=="base64"){a0=ac}else{if(a1=="hex"){a0=k}else{if(a1=="sipa"){a0=h.base58ToSipa}else{if(a1=="base58"){a0=av}}}}var aW='{\n "guid" : "'+aX+'",\n "sharedKey" : "'+a3+'",\n';if(F&&w!=null&&a0==aG){aW+=' "double_encryption" : '+F+',\n "dpasswordhash" : "'+w+'",\n'}if(s){aW+=' "options" : '+JSON.stringify(s)+",\n"}aW+=' "keys" : [\n';for(var aZ in I){var a2=$.extend({},I[aZ]);if(a2.tag==1){delete a2.tag}if(a2.priv!=null){a2.priv=a0(a2.priv,a2.addr)}for(var aY in a2){if(a2[aY]===null||a2[aY]===undefined){delete a2[aY]}}delete a2.balance;aW+=JSON.stringify(a2)+",\n";atLeastOne=true}if(atLeastOne){aW=aW.substring(0,aW.length-2)}aW+="\n ]";if(aF(g)>0){aW+=',\n "address_book" : [\n';for(var aZ in g){aW+=' {"addr" : "'+aZ+'",\n';aW+=' "label" : "'+g[aZ]+'"},\n'}aW=aW.substring(0,aW.length-2);aW+="\n ]"}if(aF(b)>0){aW+=',\n "tx_notes" : '+JSON.stringify(b)}aW+="\n}";return aW};this.get_history=function(aX,aW){BlockchainAPI.get_history(function(aY){H(aY,false);if(E.length==0&&ax>0){h.setPage(0)}else{c()}if(aX){aX()}},function(){if(aW){aW()}},ar,ax*h.getNTransactionsPerPage(),h.getNTransactionsPerPage())};this.deleteAddressBook=function(aW){delete g[aW];h.backupWalletDelayed();$("#send-coins").find(".tab-pane").trigger("show",true)};function u(aW){$("#send-coins").find(".tab-pane.active").trigger("show",aW);if(aW){BlockchainAPI.get_ticker();$(".send").prop("disabled",false)}}function l(aW,aX,a1){var a0=aW.val();aW.empty();for(var aZ in I){var a2=I[aZ];if(!a2||a2.tag==2){continue}var aY=a2.label;if(!aY){aY=a2.addr.substring(0,15)+"..."}if(aX||a2.balance>0){aW.prepend('<option value="'+a2.addr+'">'+aY+" - "+formatBTC(a2.balance)+"</option>")}}aW.prepend('<option value="any" selected>Any Address</option>');if(!a1&&a0){aW.val(a0)}}function r(aY,aZ){l(aY.find('select[name="from"]'),false,aZ);l(aY.find('select[name="change"]'),true,aZ);aY.find('select[name="change"]').prepend('<option value="new">New Address</option>');aY.find(".local-symbol").text(symbol_local.symbol);aY.find(".btc-symbol").text(symbol_btc.symbol);if(aZ){aY.find("input").val("");aY.find(".send-value-usd").text(formatSymbol(0,symbol_local)).val("");aY.find(".amount-needed").text(0)}var aX=aY.find(".recipient-container");if(aZ){var a1=aX.find(".recipient:first-child").clone();aX.empty().append(a1)}function aW(){var a2=BigInteger.ZERO;aY.find(".send-value").each(function(){a2=a2.add(precisionToSatoshiBN($(this).val()))});return a2}function a0(a2){a2.find('input[name="send-to-address"]').typeahead({source:aB()}).next().unbind().click(function(){var a3=$(this).prev();h.scanQRCode(function(a4){console.log(a4);try{new Bitcoin.Address(a4);a3.val(a4)}catch(a5){h.handleURI(a4,a2)}},function(a4){h.makeNotice("error","misc-error",a4)})});a2.find(".send-value").unbind().bind("keyup change",function(a3){if(a3.keyCode=="9"){return}aY.find(".amount-needed").text(formatBTC(aW().toString()));a2.find(".send-value-usd").val(convert($(this).val()*symbol_btc.conversion,symbol_local.conversion)).text(formatSymbol($(this).val()*symbol_btc.conversion,symbol_local))});a2.find(".send-value-usd").text(formatSymbol(0,symbol_local)).unbind().bind("keyup change",function(a3){if(a3.keyCode=="9"){return}a2.find(".send-value").val(formatSatoshi(parseFloat($(this).val())*symbol_local.conversion,sShift(symbol_btc),true))})}aX.find(".recipient").each(function(){a0($(this))});aY.find(".remove-recipient").unbind().click(function(){var a2=aX.find(".recipient").length;if(a2>1){if(a2==2){$(this).hide(200)}aX.find(".recipient:last-child").remove()}});aY.find(".add-recipient").unbind().click(function(){var a2=aX.find(".recipient:first-child").clone();a2.appendTo(aX);a0(a2);aY.find(".remove-recipient").show(200)});aY.find('select[name="from"]').unbind().change(function(){var a4=0;var a2=$(this).val();for(var a3 in a2){if(a2[a3]=="any"){$(this).val("any");a4=az;break}else{var a5=I[a2[a3]];if(a5&&a5.balance){a4+=a5.balance}}}aY.find(".amount-available").text(formatBTC(a4))}).trigger("change")}this.getAllAddresses=function(){var aX=[];for(var aW in I){aX.push(aW)}return aX};this.getPreferredAddress=function(){var aX=null;for(var aW in I){var aY=I[aW];if(aX==null){aX=aY}if(aY.priv!=null){if(aX==null){aX=aY}if(aY.tag==null||aY.tag==0){aX=aY;break}}}return aX.addr};function aT(){var aW=$("#restore-backup-modal");aW.modal({keyboard:true,backdrop:"static",show:true});aW.find(".btn.btn-secondary").unbind().click(function(){aW.modal("hide")})}this.scanQRCode=function(aY,aW){var aX=$("#qr-code-reader-modal");aX.modal({keyboard:false,backdrop:"static",show:true});loadScript("wallet/qr.code.reader",function(){QRCodeReader.init(aX,function(aZ){aX.modal("hide");aY(aZ)},function(aZ){aX.modal("hide");aW(aZ)})},aW);aX.find(".btn.btn-secondary").unbind().click(function(){QRCodeReader.stop();aX.modal("hide");aW()})};this.getActiveAddresses=function(){var aY=[];for(var aW in I){var aX=I[aW];if(aX.tag!=2){aY.push(aX.addr)}}return aY};this.getArchivedAddresses=function(){var aY=[];for(var aW in I){var aX=I[aW];if(aX.tag==2){aY.push(aX.addr)}}return aY};function ay(aZ){if(aZ!=null){aH=aZ;for(var aX in E){var aW=E[aX];if(aW.blockHeight!=null&&aW.blockHeight>0){var aY=aH.height-aW.blockHeight+1;if(aY<=100){aW.setConfirmations(aH.height-aW.blockHeight+1)}else{aW.setConfirmations(null)}}else{aW.setConfirmations(0)}}}}function z(aX,aW){loadScript("wallet/frame-modal",function(){showFrameModal({title:"Transaction Summary",description:"",src:root+"tx-summary/"+aX+"?result="+aW+"&guid="+M})})}this.deleteNote=function(aW){delete b[aW];c();h.backupWalletDelayed()};function m(aW,aX){(function(aZ,a1){aZ=$(aZ);if(!aZ.data("popover")){aZ.popover({title:'Add Note <span style="float:right"><i class="icon-remove-sign"></i></span>',trigger:"manual",content:'<textarea style="width:97%;height:50px;margin-top:2px" placeholder="Enter the note here..."></textarea><div style="text-align:right"><button class="btn btn-small">Save</button></div>'})}else{if(aZ.data("popover").tip().is(":visible")){return}}aZ.popover("show");aZ.mouseleave(function(){if(!aZ.__timeout){aZ.__timeout=setTimeout(function(){aZ.popover("hide")},250)}});function aY(){if(aZ.__timeout){clearTimeout(aZ.__timeout);aZ.__timeout=null}}var a0=aZ.data("popover").tip().mouseenter(aY);a0.find("textarea").focus(aY);a0.mouseleave(function(){aZ.__timeout=setTimeout(function(){aZ.popover("hide")},250)});a0.find("i").unbind().click(function(){aZ.popover("hide")});a0.find("button").click(function(){var a2=stripHTML(a0.find("textarea").val()).replace(/'/g,"").replace(/"/g,"");a2=a2.replace(/(\r\n|\n|\r)/gm,"");if(a2.length>0){b[a1]=a2;h.backupWalletDelayed()}c()})})(aW,aX)}function aL(aW,aX,aY){(function(aZ,a0,a2){aZ=$(aZ);if(!aZ.data("popover")){var a3="Note";if(b[a2]){a3+=' <span style="float:right"><img src="'+resource+'delete.png" /></span>'}$(aZ).popover({title:a3,trigger:"manual",content:$("<div/>").html(a0).text()})}else{if(aZ.data("popover").tip().is(":visible")){return}}aZ.popover("show");aZ.mouseleave(function(){if(!aZ.__timeout){aZ.__timeout=setTimeout(function(){aZ.popover("hide")},250)}});var a1=aZ.data("popover").tip().mouseenter(function(){if(aZ.__timeout){clearTimeout(aZ.__timeout);aZ.__timeout=null}});a1.find("img").unbind().click(function(){h.deleteNote(a2)});a1.mouseleave(function(){aZ.__timeout=setTimeout(function(){aZ.popover("hide")},250)})})(aW,aX,aY)}function C(aZ,a4,a1){var a5=aZ.result;var a0='<tr class="pointer" id="tx-'+aZ.txIndex+'"><td class="hidden-phone" style="width:365px"><div><ul style="margin-left:0px;" class="short-addr">';var aX=true;if(a5>=0){for(var aY=0;aY<aZ.inputs.length;++aY){var aW=aZ.inputs[aY].prev_out;if(!aW||!aW.addr){aX=false;a0+='<span class="label">Newly Generated Coins</span>'}else{var a2=a4[aW.addr];if(a2){continue}aX=false;a0+=formatOutput(aW,a4,a1)}}}else{if(a5<0){for(var aY=0;aY<aZ.out.length;++aY){var aW=aZ.out[aY];var a2=a4[aW.addr];if(a2&&aW.type==0){continue}aX=false;a0+=formatOutput(aW,a4,a1)}}}if(aX){a0+='<span class="label">Moved Between Wallet</info>'}a0+="</ul></div></td><td><div>";var a3=aZ.note?aZ.note:b[aZ.hash];if(a3){a0+='<img src="'+resource+'note.png" class="show-note"> '}else{a0+='<img src="'+resource+'note_grey.png" class="add-note"> '}if(aZ.time>0){a0+=dateToString(new Date(aZ.time*1000))}if(aZ.confirmations==0){a0+=' <span class="label label-important hidden-phone">Unconfirmed Transaction!</span> '}else{if(aZ.confirmations>0){a0+=' <span class="label label-info hidden-phone">'+aZ.confirmations+" Confirmations</span> "}}a0+="</div></td>";if(a5>0){a0+='<td style="color:green"><div>'+formatMoney(a5,true)+"</div></td>"}else{if(a5<0){a0+='<td style="color:red"><div>'+formatMoney(a5,true)+"</div></td>"}else{a0+="<td><div>"+formatMoney(a5,true)+"</div></td>"}}if(aZ.balance==null){a0+="<td></td></tr>"}else{a0+='<td class="hidden-phone"><div>'+formatMoney(aZ.balance)+"</div></td></tr>"}return a0}function V(){L();if(az==null){$("#balance").html("Loading...")}else{$("#balance").html(formatSymbol(az,symbol,true));$("#balance2").html(formatSymbol(az,(symbol===symbol_local)?symbol_btc:symbol_local),true)}return j.attr("id")}function c(aW){var aX=V();if("send-coins"==aX){u(aW)}else{if("home-intro"==aX){f(aW)}else{if("receive-coins"==aX){aV(aW)}else{if("my-transactions"==aX){W(aW)}}}}}function f(aW){$("#summary-n-tx").html(K);$("#summary-received").html(formatMoney(at,true));$("#summary-sent").html(formatMoney(S,true));$("#summary-balance").html(formatMoney(az,symbol));var aY=h.getPreferredAddress();$(".paper-wallet-btn").unbind().click(function(){loadScript("wallet/paper-wallet",function(){PaperWallet.showModal()})});if(h.isWatchOnly(aY)){$(".no-watch-only").hide()}else{$(".no-watch-only").show();var aX=$("#my-primary-address");if(aX.text()!=aY){aX.text(aY);loadScript("wallet/jquery.qrcode",function(){$("#my-primary-addres-qr-code").empty().qrcode({width:125,height:125,text:aY})})}}}function R(){var aW=$("#export-warning").show();var aX=$("#import-export-content").hide();$("#show-import-export").unbind().click(function(){h.getMainPassword(function(){aW.hide();loadScript("wallet/import-export",function(){ImportExport.init(aX,function(){aX.show()},function(){af($("#home-intro"))})},function(aY){h.makeNotice("error","misc-error",aY);af($("#home-intro"))})},function(){af($("#home-intro"))})})}function W(){var aX=null;var aZ=0;if(aX!=null){clearInterval(aX);aX=null}var aW;if(s.tx_display==0){$("#transactions-detailed").hide();aW=$("#transactions-compact").show().find("tbody").empty()}else{$("#transactions-compact").hide();aW=$("#transactions-detailed").empty().show()}if(E.length==0){$("#transactions-detailed, #transactions-compact").hide();$("#no-transactions").show();return}else{$("#no-transactions").hide()}var aY=function(){for(var a3=aZ;a3<E.length&&a3<(aZ+h.getNTransactionsPerPage());++a3){var a2=E[a3];if(s.tx_display==0){aW.append(aR($(C(a2,I,g)),a2))}else{aW.append(a2.getHTML(I,g))}}aZ+=h.getNTransactionsPerPage();if(aZ<E.length){aX=setTimeout(aY,15)}else{setupSymbolToggle();L();var a1=$(".pagination ul").empty();if(ax==0&&E.length<h.getNTransactionsPerPage()){a1.hide();return}else{a1.show()}var a0=Math.ceil(aU/h.getNTransactionsPerPage());var a5=" disabled";if(ax>0){a5=""}var a6=10;var a4=Math.max(0,Math.min(ax-(a6/2),a0-a6));a1.append($('<li class="prev'+a5+'"><a>← Previous</a></li>').click(function(){h.setPage(ax-1)}));if(a4>0){a1.append($("<li><a>≤</a></li>").click(function(){h.setPage(0)}))}for(var a3=a4;a3<a0&&a3<a4+a6;++a3){(function(a7){var a8="";if(ax==a7){a8=' class="active"'}a1.append($("<li"+a8+'><a class="hidden-phone">'+(a7+1)+"</a></li>").click(function(){h.setPage(a7)}))})(a3)}if(a4+a6<a0){a1.append($("<li><a>≥</a></li>").click(function(){h.setPage(a0-1)}))}var a5=" disabled";if(ax<a0-1){a5=""}a1.append($('<li class="next'+a5+'"><a>Next →</a></li>').click(function(){h.setPage(ax+1)}))}};aY()}this.setPage=function(aW){ax=aW;scroll(0,0);h.get_history()};function v(){loadScript("wallet/frame-modal",function(){showFrameModal({title:"Export History",description:"",src:root+"export-history?active="+h.getActiveAddresses().join("|")+"&archived="+h.getArchivedAddresses().join("|")})})}function H(aZ,aY){if(!aY&&aZ.mixer_fee){x=aZ.mixer_fee}if(aZ.disable_mixer){$("#shared-addresses,#send-shared").hide()}aE=aZ.sharedcoin_endpoint;E.length=0;if(aZ.wallet==null){at=0;S=0;az=0;K=0;aU=0;return}at=aZ.wallet.total_received;S=aZ.wallet.total_sent;az=aZ.wallet.final_balance;K=aZ.wallet.n_tx;aU=aZ.wallet.n_tx_filtered;for(var aX=0;aX<aZ.addresses.length;++aX){if(I[aZ.addresses[aX].address]){I[aZ.addresses[aX].address].balance=aZ.addresses[aX].final_balance}}for(var aX=0;aX<aZ.txs.length;++aX){var aW=TransactionFromJSON(aZ.txs[aX]);aW.result=t(aW,false);E.push(aW)}if(aZ.info){$("#nodes-connected").html(aZ.info.nconnected);if(aZ.info.latest_block){ay(aZ.info.latest_block)}if(aZ.info.symbol_local){setLocalSymbol(aZ.info.symbol_local)}if(aZ.info.symbol_btc){setBTCSymbol(aZ.info.symbol_btc)}}}this.handleURI=function(aX,aW){loadScript("wallet/jsuri-1.1.1",function(){try{var aZ=new Uri(aX);var aY=new Bitcoin.Address(aZ.host());aW.find('input[name="send-to-address"]').val(aY.toString());var a0=parseFloat(aZ.getQueryParamValue("amount"));if(a0>0&&!isNaN(a0)){aW.find(".send-value").val(a0)}}catch(a1){console.log(a1);h.makeNotice("error","error","Invalid Bitcoin Address or URI")}},function(){h.makeNotice("error","error","Invalid Bitcoin Address or URI")})};function aN(){J();U=setTimeout(h.logout,h.getLogoutTime());for(var aY in Z){Z[aY]("did_decrypt")}MyStore.get("multiaddr",function(a0){if(a0!=null){H($.parseJSON(a0),true);c()}});h.get_history();$("#initial_error,#initial_success").remove();var aZ=decodeURIComponent(window.location.hash.replace("#",""));if(aZ.indexOf("bitcoin:")==0){var aW=$("#send-coins");af(aW);var aX=aW.find(".tab-pane.active").find(".recipient").first();h.handleURI(aZ,aX)}else{af($("#home-intro"))}window.location.hash=""}function J(aZ,aW){for(var aX in I){var a0=I[aX];if(a0.tag==1){alert("Warning! wallet data may have changed but cannot sync as you have un-saved keys");return}}console.log("Get wallet with checksum "+aA);var aY={method:"wallet.aes.json",format:"json"};if(aA&&aA.length>0){aY.checksum=aA}h.securePost("wallet",aY,function(a1){if(!a1.payload||a1.payload=="Not modified"){if(aZ){aZ()}return}console.log("Wallet data modified");h.setEncryptedWalletData(a1.payload);ab(function(){h.get_history();c();if(aZ){aZ()}},function(){if(aW){aW()}})},function(a1){if(aW){aW()}})}function ab(aX,aW){if(ai==null||ai.length==0){aW("No Wallet Data To Decrypt");return}h.decryptWallet(ai,aJ,function(a2,a0){try{d=a2.sharedKey;if(!d||d.length==0||d.length!=36){throw"Shared Key is invalid"}if(a0){Q=a0.version;P=a0.pbkdf2_iterations}if(a2.double_encryption&&a2.dpasswordhash){F=a2.double_encryption;w=a2.dpasswordhash}if(a2.options){$.extend(s,a2.options)}I={};for(var aZ=0;aZ<a2.keys.length;++aZ){var aY=a2.keys[aZ];if(aY.addr==null||aY.addr.length==0||aY.addr=="undefined"){h.makeNotice("error","null-error","Your wallet contains an undefined address. This is a sign of possible corruption, please double check all your BTC is accounted for. Backup your wallet to remove this error.",15000);continue}if(aY.tag==1){aY.tag=null}I[aY.addr]=aY}g={};if(a2.address_book){for(var aZ=0;aZ<a2.address_book.length;++aZ){h.addAddressBookEntry(a2.address_book[aZ].addr,a2.address_book[aZ].label)}}if(a2.tx_notes){b=a2.tx_notes}if(aA==null||aA.length==0){aA=ah()}e();aX()}catch(a1){aW(a1)}},aW)}this.getPassword=function(a1,a2,aZ){if(!a1.is(":visible")){a1.trigger("hidden");a1.unbind()}a1.modal({keyboard:false,backdrop:"static",show:true});a1.center();var a0=a1.find('input[name="password"]');var a4=a0,aW=false,a3=false;a1.find(".vkeyboard li").unbind().click(function(){var a7=$(this),a6=a7.html();if(a7.hasClass("left-shift")||a7.hasClass("right-shift")){$(".letter").toggleClass("uppercase");$(".symbol span").toggle();aW=(aW===true)?false:true;a3=false;return false}if(a7.hasClass("capslock")){$(".letter").toggleClass("uppercase");a3=true;return false}if(a7.hasClass("delete")){var a5=a4.val();a4.val(a5.substr(0,a5.length-1));return false}if(a7.hasClass("symbol")){a6=$("span:visible",a7).html()}if(a7.hasClass("space")){a6=" "}if(a7.hasClass("tab")){a6="\t"}if(a7.hasClass("return")){a6="\n"}if(a7.hasClass("uppercase")){a6=a6.toUpperCase()}if(aW===true){$(".symbol span").toggle();if(a3===false){$(".letter").toggleClass("uppercase")}aW=false}a4.val(a4.val()+a6)});a0.keypress(function(a5){if(a5.keyCode==13){a5.preventDefault();a1.find(".btn.btn-primary").click()}});a0.val("");var aX=a1.find(".btn.btn-primary");aX.click(function(){if(a2){aZ=null;var a5=a2;a2=null;setTimeout(function(){a1.modal("hide");a5(a0.val())},10)}else{a1.modal("hide")}});var aY=a1.find(".btn.btn-secondary");aY.click(function(){if(aZ){var a5=aZ;aZ=null;a2=null;setTimeout(function(){a1.modal("hide");try{a5()}catch(a6){h.makeNotice("error","misc-error",a6)}},10)}else{a1.modal("hide")}});a1.on("hidden",function(){a0.unbind();aY.unbind();aX.unbind();a1.unbind();if(aZ){var a5=aZ;aZ=null;a2=null;setTimeout(function(){try{a5()}catch(a6){h.makeNotice("error","misc-error",a6)}},10)}})};this.makePairingQRCode=function(aX,aW){h.getMainPassword(function(){loadScript("wallet/jquery.qrcode",function(){try{if(aW==1){h.securePost("wallet",{method:"pairing-encryption-password"},function(aZ){aX($("<div></div>").qrcode({width:300,height:300,text:"1|"+M+"|"+h.encrypt(d+"|"+Crypto.util.bytesToHex(UTF8.stringToBytes(aJ)),aZ,h.getDefaultPbkdf2Iterations())}))},function(aZ){h.makeNotice("error","misc-error",aZ)})}else{if(aW==0){aX($("<div></div>").qrcode({width:300,height:300,text:M+"|"+d+"|"+aJ}))}}}catch(aY){h.makeNotice("error","misc-error",aY)}})},function(){h.logout()})};this.getMainPassword=function(aX,aW){if(B>new Date().getTime()-N){return aX(aJ)}h.getPassword($("#main-password-modal"),function(aY){if(aJ==aY){B=new Date().getTime();if(aX){try{aX(aJ)}catch(aZ){h.makeNotice("error","misc-error",aZ)}}}else{h.makeNotice("error","misc-error","Password incorrect.");if(aW){try{aW()}catch(aZ){h.makeNotice("error","misc-error",aZ)}}}},aW)};this.getSecondPassword=function(aY,aW){if(!F||ak!=null){if(aY){try{aY(ak)}catch(aX){h.makeNotice("error","misc-error",aX)}}return}h.getPassword($("#second-password-modal"),function(aZ){try{if(aK(aZ)){if(aY){try{aY(aZ)}catch(a0){console.log(a0);h.makeNotice("error","misc-error",a0)}}}else{h.makeNotice("error","misc-error","Password incorrect.");if(aW){try{aW()}catch(a0){h.makeNotice("error","misc-error",a0)}}}}catch(a0){if(aW){try{aW()}catch(a0){h.makeNotice("error","misc-error",a0)}}}},aW)};function a(){if(A||aw){return}try{aw=true;var aW=$("#restore-password");aJ=aW.val();aW.val("");B=new Date().getTime();function aX(a0){aw=false;h.makeNotice("error","misc-error",a0)}if(ai==null||ai.length==0){h.setLoadingText("Validating Authentication key");var aY=$.trim($(".auth-"+q).find(".code").val());if(aY.length==0||aY.length>255){throw"You must enter a Two Factor Authentication code"}$.ajax({type:"POST",url:root+"wallet",data:{guid:M,payload:aY,length:aY.length,method:"get-wallet",format:"plain"},success:function(a0){try{if(a0==null||a0.length==0){throw"Server Return Empty Wallet Data"}if(a0!="Not modified"){h.setEncryptedWalletData(a0)}$(".auth-"+q).hide();$(".auth-0").show();ab(function(){aw=false;n();aN()},aX)}catch(a1){aX(a1)}},error:function(a0){aX(a0.responseText)}})}else{ab(function(){aw=false;n();aN()},aX)}}catch(aZ){aX(aZ)}}function O(){$("#not-synced-warning-modal").modal("show").find(".btn.btn-danger").unbind().click(function(){$(this).modal("hide");aq=true;c()})}function e(){au("error");webSocketConnect(y);A=true;$("#tech-faq").hide();$("#intro-text").hide();$("#large-summary").show()}this.quickSendNoUI=function(aY,aX,aW){loadScript("wallet/signer",function(){h.getSecondPassword(function(){try{var a0=initNewTx();a0.from_addresses=h.getActiveAddresses();a0.to_addresses.push({address:new Bitcoin.Address(aY),value:Bitcoin.Util.parseValue(aX)});a0.addListener(aW);a0.start()}catch(aZ){aW.on_error(aZ)}},function(aZ){aW.on_error(aZ)})})};function G(){h.setLoadingText("Sending email backup");h.securePost("wallet",{method:"email-backup"},function(aW){h.makeNotice("success","backup-success",aW)},function(aW){h.makeNotice("error","misc-error",aW.responseText)})}this.backupWalletDelayed=function(aZ,aY,aX,aW){if(am){clearInterval(am);am=null}am=setTimeout(function(){h.backupWallet(aZ,aY,aX,aW)},3000)};this.backupWallet=function(a2,a1,aX){if(am){clearInterval(am);am=null}var aW=function(a3){h.makeNotice("error","misc-error","Error Saving Wallet: "+a3,10000);c();if(aX!=null){aX(a3)}else{throw a3}};try{if(a2==null){a2="update"}if(aF(I)==0){return}var aY=h.makeWalletJSON();var a0=h.encryptWallet(aY,aJ);if(a0.length==0){throw"Error encrypting the JSON output"}h.decryptWallet(a0,aJ,function(a5){try{var a3=aA;h.setLoadingText("Saving wallet");h.setEncryptedWalletData(a0);h.securePost("wallet",{length:a0.length,payload:a0,checksum:aA,old_checksum:a3,method:a2,format:"plain"},function(a7){for(var a6 in I){var a8=I[a6];if(a8.tag==1){delete a8.tag}}h.makeNotice("success","misc-success",a7);c();if(a1!=null){a1()}},function(a7){for(var a6 in I){var a8=I[a6];if(a8.tag==1){O();break}}aW(a7.responseText)})}catch(a4){aW(a4)}})}catch(aZ){aW(aZ)}};function aO(aW){if(F){if(ak==null){throw"Cannot encrypt private key without a password"}return h.encrypt(aW,d+ak,h.getSecondPasswordPbkdf2Iterations())}else{return aW}return null}this.isBase58=function(aY,aX){for(var aW=0;aW<aY.length;++aW){if(aY[aW]<0||aY[aW]>58){return false}}return true};this.encrypt=function(aY,aX,aW){return Crypto.AES.encrypt(aY,aX,{mode:new Crypto.mode.CBC(Crypto.pad.iso10126),iterations:aW})};this.encryptWallet=function(aX,aW){if(Q==2){return JSON.stringify({pbkdf2_iterations:h.getMainPasswordPbkdf2Iterations(),version:Q,payload:h.encrypt(aX,aW,h.getMainPasswordPbkdf2Iterations())})}else{if(Q==0){return h.encrypt(aX,aW,h.getDefaultPbkdf2Iterations())}else{throw"Unknown encryption version "+Q}}};this.decryptWallet=function(aX,a3,a4,a0){try{var aW=null;try{var aW=$.parseJSON(aX)}catch(aY){console.log(aY)}var aZ=function(){try{var a6=Crypto.AES.decrypt(aW.payload,a3,{mode:new Crypto.mode.CBC(Crypto.pad.iso10126),iterations:aW.pbkdf2_iterations});var a5=$.parseJSON(a6);a4(a5,aW)}catch(a7){a0("Error Decrypting Wallet. Please check your password is correct.")}};if(aW&&aW.payload&&aW.pbkdf2_iterations){if(aW.version!=ao){throw"Wallet version "+aW.version+" not supported"}if(aW.pbkdf2_iterations>100){var a2=$("#decrypting-progress-modal");var a1=setTimeout(function(){a2.modal({keyboard:false,backdrop:"static",show:true});a2.center()},500);h.decryptWebWorker(aW.payload,a3,aW.pbkdf2_iterations,function(a6){clearTimeout(a1);a2.modal("hide");try{var a5=$.parseJSON(a6);a4(a5,aW)}catch(a7){aZ()}},function(){clearTimeout(a1);a2.modal("hide");aZ()})}else{aZ()}}else{h.decrypt(aX,a3,h.getDefaultPbkdf2Iterations(),function(a6){try{var a5=$.parseJSON(a6);try{a4(a5)}catch(a7){console.log(a7)}return true}catch(a7){return false}},function(){a0("Error Decrypting Wallet. Please check your password is correct.")})}}catch(aY){if(a0){a0(aY)}}};this.decryptWebWorker=function(aZ,a3,aY,a4,a2){var aW=false;var a1=function(a5){if(!aW){a2(a5);aW=true}};try{var aX=new Worker(resource+"wallet/signer"+(min?".min.js":".js"));aX.addEventListener("message",function(a6){var a5=a6.data;try{switch(a5.cmd){case"on_decrypt":a4(a5.data);aX.terminate();break;case"on_error":throw a5.e}}catch(a6){aX.terminate();a1(a6)}},false);aX.addEventListener("error",function(a5){a1(a5)});aX.postMessage({cmd:"load_resource",path:resource+"wallet/bitcoinjs"+(min?".min.js":".js")});aX.postMessage({cmd:"decrypt",data:aZ,password:a3,pbkdf2_iterations:aY})}catch(a0){a1(a0)}};this.decrypt=function(a0,aZ,aX,a2,aY){try{var aW=Crypto.AES.decrypt(a0,aZ,{mode:new Crypto.mode.CBC(Crypto.pad.iso10126),iterations:aX});if(aW!=null&&aW.length>0){if(a2(aW)){return aW}}}catch(a1){console.log(a1)}if(aX!=10){try{var aW=Crypto.AES.decrypt(a0,aZ,{mode:new Crypto.mode.CBC(Crypto.pad.iso10126),iterations:10});if(aW!=null&&aW.length>0){if(a2(aW)){return aW}}}catch(a1){console.log(a1)}}try{var aW=Crypto.AES.decrypt(a0,aZ);if(aW!=null&&aW.length>0){if(a2(aW)){return aW}}}catch(a1){console.log(a1)}try{var aW=Crypto.AES.decrypt(a0,aZ,{mode:new Crypto.mode.OFB(Crypto.pad.iso7816),iterations:1});if(aW!=null&&aW.length>0){if(a2(aW)){return aW}}}catch(a1){console.log(a1)}try{var aW=Crypto.AES.decrypt(a0,aZ,{mode:new Crypto.mode.CBC(Crypto.pad.iso10126),iterations:1});if(aW!=null&&aW.length>0){if(a2(aW)){return aW}}}catch(a1){console.log(a1)}if(aY){aY()}return null};this.handleNTPResponse=function(a0,a1){var aY=(new Date()).getTime();if(a0.clientTimeDiff&&a0.serverTime){var aW=aY-a0.serverTime;var aX=(a0.clientTimeDiff-aY+a1-aW)/2;var aZ=(aW-aX)/2;if(Y){aM=(aM+aZ)/2}else{aM=aZ;Y=true;MyStore.put("server_time_offset",""+aM)}console.log("Server Time offset "+aM+"ms - This offset "+aZ)}};this.setGUID=function(aY,aW){console.log("Set GUID "+aY);if(A){throw"Cannot Set GUID Once Initialized"}h.setLoadingText("Changing Wallet Identifier");$("#initial_error,#initial_success").remove();var aX=$("#restore-wallet-continue");aX.prop("disabled",true);var a0=(new Date()).getTime();var aZ={format:"json",resend_code:aW,ct:a0};if(aA){aZ.checksum=aA}$.ajax({type:"GET",dataType:"json",url:root+"wallet/"+aY,data:aZ,timeout:10000,success:function(a1){h.handleNTPResponse(a1,a0);aX.prop("disabled",false);if(!a1.guid){h.makeNotice("error","misc-error","Server returned null guid.");return}$(".auth-"+q).hide();aa=a1.extra_seed;M=a1.guid;q=a1.auth_type;aP=a1.real_auth_type;if(a1.payload&&a1.payload.length>0&&a1.payload!="Not modified"){h.setEncryptedWalletData(a1.payload)}war_checksum=a1.war_checksum;setLocalSymbol(a1.symbol_local);$("#restore-guid").val(M);$(".auth-"+q).show();if(a1.initial_error){h.makeNotice("error","misc-error",a1.initial_error)}if(a1.initial_success){h.makeNotice("success","misc-success",a1.initial_success)}MyStore.get("guid",function(a2){if(a2!=M){MyStore.remove("guid");MyStore.remove("payload");MyStore.remove("multiaddr");if(M!=D){MyStore.put("guid",M)}}});if(a1.language&&X!=a1.language){h.setLanguage(a1.language)}},error:function(a1){console.log("Set GUID Success");aX.prop("disabled",false);MyStore.get("guid",function(a2){if(a2==aY&&ai){h.makeNotice("error","misc-error","Error Contacting Server. Using Local Wallet Cache.");M=a2;aA=ah();q=0;$("#restore-guid").val(M);$(".auth-"+q).show();return}try{var a4=$.parseJSON(a1.responseText);if(a4.initial_error){h.makeNotice("error","misc-error",a4.initial_error);return}}catch(a3){}if(a1.responseText){h.makeNotice("error","misc-error",a1.responseText)}else{h.makeNotice("error","misc-error","Error changing wallet identifier")}})}})};function i(aW){var aX=B58.encode(aW);return aO(aX)}this.decryptPK=function(aW){if(F){if(ak==null){throw"Cannot decrypt private key without a password"}return h.decrypt(aW,d+ak,h.getSecondPasswordPbkdf2Iterations(),h.isBase58)}else{return aW}return null};this.decodePK=function(aX){if(!aX){throw"null PK passed to decodePK"}var aW=h.decryptPK(aX);if(aW!=null){return B58.decode(aW)}return null};this.signmessage=function(aW,aY){var a0=I[aW];if(!a0.priv){throw"Cannot sign a watch only address"}var aZ=h.decodePK(a0.priv);var aX=new Bitcoin.ECKey(aZ);return Bitcoin.Message.signMessage(aX,aY,a0.addr)};function aK(aX){var aW=Crypto.SHA256(d+aX,{asBytes:true});var a0=ae(aW,h.getSecondPasswordPbkdf2Iterations()-1);if(a0==w){ak=aX;return true}if(h.getSecondPasswordPbkdf2Iterations()!=10){var aY=ae(aW,10-1);if(aY==w){ak=aX;w=a0;return true}}if(Crypto.util.bytesToHex(aW)==w){ak=aX;w=a0;return true}var aZ=Crypto.SHA256(aX);if(aZ==w){ak=aX;w=a0;return true}return false}this.runCompressedCheck=function(){var aW=[];var aY={};for(var aZ in I){var a3=I[aZ];if(a3.priv!=null){var a2=h.decodePK(a3.priv);var a0=new Bitcoin.ECKey(a2);var aX=a0.getBitcoinAddress().toString();var a1=a0.getBitcoinAddressCompressed().toString();if(a3.addr!=aX){aY[aX]=a3.priv;aW.push(aX)}if(a3.addr!=a1){aY[a1]=a3.priv;aW.push(a1)}}}if(aW.length==0){alert("to_check length == 0")}BlockchainAPI.get_balances(aW,function(a7){var a8=0;for(var a6 in a7){var a9=a7[a6].final_balance;if(a9>0){var a5=new Bitcoin.ECKey(h.decodePK(aY[a6]));var a4=a5.getBitcoinAddress().toString();if(h.addPrivateKey(a5,{compressed:a4!=a6,app_name:IMPORTED_APP_NAME,app_version:IMPORTED_APP_VERSION})){alert(formatBTC(a9)+" claimable in address "+a6)}}a8+=a9}alert(formatBTC(a8)+" found in compressed addresses");if(a8>0){h.backupWallet("update",function(){h.get_history()})}})};this.checkAllKeys=function(aW){for(var aX in I){var a1=I[aX];if(a1.addr==null){throw"Null Address Found in wallet "+aX}if(a1.addr.toString()==null){throw"Error decoding wallet address "+a1.addr}if(a1.priv!=null){var a0=h.decodePK(a1.priv);var aZ=new Bitcoin.ECKey(a0);var aY=aZ.getBitcoinAddress().toString();if(aY!=a1.addr&&aZ.getBitcoinAddressCompressed().toString()!=a1.addr){throw"Private key does not match bitcoin address "+a1.addr+" != "+aY}if(aW){a1.priv=i(a0)}}}h.makeNotice("success","wallet-success","Wallet verified.")};this.setMainPassword=function(aW){h.getMainPassword(function(){aJ=aW;h.backupWallet("update",function(){h.logout()},function(){h.logout()})})};function af(aW){if(aW===j){return}if(j!=null){if($("#"+j.attr("id")+"-btn").length>0){$("#"+j.attr("id")+"-btn").parent().attr("class","")}j.hide()}j=aW;j.show();if($("#"+j.attr("id")+"-btn").length>0){$("#"+j.attr("id")+"-btn").parent().attr("class","active")}c(true)}function aF(aY){var aX=0,aW;for(aW in aY){aX++}return aX}function ad(aW){I[aW].priv=null}function aj(){if(aF(I)>=aC){h.makeNotice("error","misc-error","We currently support a maximum of "+aC+" private keys, please remove some unused ones.");return true}return false}function aS(aY,aW){var aX=I[aY];if(!aX||aX.length==0){I[aY]={addr:aY,priv:aW,balance:0};return true}else{if(!aX.priv&&aW){aX.priv=aW;return true}}return false}function o(){var aY=$("#add-address-book-entry-modal");aY.modal({keyboard:true,backdrop:"static",show:true});var aW=aY.find('input[name="label"]');var aX=aY.find('input[name="address"]');aW.val("");aX.val("");aY.find(".btn.btn-primary").unbind().click(function(){aY.modal("hide");var a0=stripHTML(aW.val());var aZ=stripHTML(aX.val());if(a0.length==0||aZ.length==0){h.makeNotice("error","misc-error","You must enter an address and label for the address book entry");return false}var a2;try{a2=new Bitcoin.Address(aZ);if(a2==null){throw"Null address"}}catch(a1){h.makeNotice("error","misc-error","Bitcoin address invalid, please make sure you entered it correctly");return false}if(g[aZ]!=null){h.makeNotice("error","misc-error","Bitcoin address already exists");return false}h.makeNotice("success","misc-success","Added Address book entry");h.addAddressBookEntry(aZ,a0);h.backupWalletDelayed();$("#send-coins").find(".tab-pane").trigger("show",true)});aY.find(".btn.btn-secondary").unbind().click(function(){aY.modal("hide")})}this.logout=function(){if(ap){return}if(M==D){window.location=root+"wallet/logout"}else{$.ajax({type:"GET",url:root+"wallet/logout",data:{format:"plain"},success:function(aW){window.location.reload()},error:function(){window.location.reload()}})}};function an(a2){var a4=$("#delete-address-modal");a4.modal({keyboard:true,backdrop:"static",show:true});a4.find(".btn.btn-primary").hide();a4.find(".btn.btn-danger").hide();$("#change-mind").hide();a4.find("#to-delete-address").html(a2.join(" "));a4.find("#delete-balance").empty();var aY=a4.find("#delete-balance");var aW=[];for(var a1 in a2){var a3=a2[a1];if(I[a3]&&I[a3].priv){aW.push(a2[a1])}}BlockchainAPI.get_balance(aW,function(a5){a4.find(".btn.btn-primary").show(200);a4.find(".btn.btn-danger").show(200);aY.html("Balance "+formatBTC(a5));if(a5>0){aY.css("color","red")}else{aY.css("color","black")}},function(){a4.find(".btn.btn-primary").show(200);a4.find(".btn.btn-danger").show(200);aY.text("Error Fetching Balance")});var aZ=false;var a1=0;var aX=null;var a0=10;changeMind=function(){$("#change-mind").show();$("#change-mind-time").text(a0-a1)};a4.find(".btn.btn-primary").unbind().click(function(){changeMind();a4.find(".btn.btn-primary").hide();a4.find(".btn.btn-danger").hide();aX=setInterval(function(){if(aZ){return}++a1;changeMind();if(a1==a0){$("#delete-address-modal").modal("hide");h.makeNotice("warning","warning-deleted","Private Key Removed From Wallet");for(var a5 in a2){ad(a2[a5])}c();h.backupWallet();clearInterval(aX)}},1000)});a4.find(".btn.btn-danger").unbind().click(function(){changeMind();a4.find(".btn.btn-primary").hide();a4.find(".btn.btn-danger").hide();aX=setInterval(function(){if(aZ){return}++a1;changeMind();if(a1==a0){try{$("#delete-address-modal").modal("hide");h.makeNotice("warning","warning-deleted","Address & Private Key Removed From Wallet");for(var a5 in a2){h.deleteAddress(a2[a5])}c();h.backupWallet("update",function(){h.get_history()})}finally{clearInterval(aX)}}},1000)});a4.unbind().on("hidden",function(){if(aX){aZ=true;clearInterval(aX);aX=null}});a4.find(".btn.btn-secondary").unbind().click(function(){a4.modal("hide")})}function aB(){var aY=[];for(var aW in g){aY.push(g[aW])}for(var aW in I){var aX=I[aW];if(aX.tag!=2&&aX.label){aY.push(aX.label)}}return aY}this.sweepAddressesModal=function(aX,aW){h.getSecondPassword(function(){var aZ=$("#sweep-address-modal");aZ.modal("show");BlockchainAPI.get_balance(aX,function(a0){aZ.find(".balance").text("Amount: "+formatBTC(a0))},function(){aZ.find(".balance").text("Error Fetching Balance")});var aY=aZ.find('select[name="change"]');l(aY,true);aZ.find(".btn.btn-primary").unbind().click(function(){loadScript("wallet/signer",function(){BlockchainAPI.get_balance(aX,function(a1){var a2=initNewTx();var a0=aY.val();if(a0=="any"){a0=h.getPreferredAddress()}a2.fee=a2.base_fee;a2.to_addresses.push({address:new Bitcoin.Address(a0),value:BigInteger.valueOf(a1).subtract(a2.fee)});a2.from_addresses=aX;a2.extra_private_keys=aW;a2.start()},function(){h.makeNotice("error","misc-error","Error Getting Address Balance")})});aZ.modal("hide")});aZ.find(".btn.btn-secondary").unbind().click(function(){aZ.modal("hide")})})};this.openWindow=function(aX){function aW(aZ){var aY=false;try{if(typeof aZ=="undefined"||!aZ){aY=true}else{if(aZ&&aZ.closed){aY=false}else{if(aZ&&aZ.test){aY=false}}}}catch(a0){}return aY}window.open(aX,null,"scroll=1,status=1,location=1,toolbar=1");if(aW(window)){h.makeNotice("error","misc-error","Popup Blocked. Try and click again.");return false}else{return true}};function aD(){try{$(".pop").popover({offset:10,placement:"bottom"})}catch(aW){}}function n(){if(T){return}T=true;$("#add-address-book-entry-btn").click(function(){o()});$("#home-intro-btn").click(function(){af($("#home-intro"))});$("#my-transactions-btn").click(function(){af($("#my-transactions"))});$("#send-coins-btn").click(function(){af($("#send-coins"))});$("#import-export-btn").click(function(){af($("#import-export"));R()});$("#chord-diagram").click(function(){loadScript("wallet/frame-modal",function(){showFrameModal({title:"Address Relationships",description:"",src:root+"taint/"+h.getActiveAddresses().join("|")})})});$("#verify-message").click(function(){loadScript("wallet/address_modal",function(){verifyMessageModal()})});$("#generate-cold-storage").click(function(){loadScript("wallet/paper-wallet",function(){PaperWallet.showColdStorageModal()},null,true)});$("#group-received").click(function(){loadScript("wallet/taint_grouping",function(){try{loadTaintData()}catch(aW){h.makeNotice("error","misc-error","Unable To Load Taint Grouping Data")}})});$("#my-account-btn").click(function(){af($("#my-account"));var aW=$("#account-settings-warning").show();var aX=$("#my-account-content").hide();$("#show-account-settings").unbind().click(function(){h.getMainPassword(function(){aW.hide();loadScript("wallet/account",function(){AccountSettings.init(aX,function(){aX.show()},function(){af($("#home-intro"))})},function(aY){h.makeNotice("error","misc-error",aY);af($("#home-intro"))})},function(){af($("#home-intro"))})})});$("#enable_archived_checkbox").change(function(){var aW=$(this).is(":checked");$(".archived_checkbox").prop("checked",false);$(".archived_checkbox").prop("disabled",!aW);$("#archived-sweep").prop("disabled",!aW);$("#archived-delete").prop("disabled",!aW)});$("#shared-addresses").on("show",function(){var aW=$(this);loadScript("wallet/shared-addresses",function(){buildSharedTable(aW)})});$("#active-addresses").on("show",function(){var a2=$(this).find("table:first");a2.find("tbody:gt(0)").remove();var aZ=a2.find("tbody").empty();for(var a1 in I){var a3=I[a1];if(a3.tag==2||(a3.tag==1&&!aq)){continue}var a0="";if(a3.tag==1){a0=' <font color="red" class="pop" title="Not Synced" data-content="This is a new address which has not yet been synced with our the server. Do not used this address yet.">(Not Synced)</font>'}else{if(a3.priv==null){a0=' <font color="red" class="pop" title="Watch Only" data-content="Watch Only means there is no private key associated with this bitcoin address. <br /><br /> Unless you have the private key stored elsewhere you do not own the funds at this address and can only observe the transactions.">(Watch Only)</font>'}}var aW="";var aY=a3.addr;if(a3.label!=null){aY=a3.label;aW='<span class="hidden-phone"> - '+a3.addr+"</span>"}var aX=$('<tr><td><div class="short-addr"><a href="'+root+"address/"+a3.addr+'" target="new">'+aY+"</a>"+aW+" "+a0+'<div></td><td><span style="color:green">'+formatMoney(a3.balance,true)+'</span></td> <td><div class="btn-group pull-right"><a class="btn btn-mini dropdown-toggle" data-toggle="dropdown" href="#"><span class="hidden-phone">Actions </span><span class="caret"></span></a><ul class="dropdown-menu"> <li><a href="#" class="pop act-archive" title="Archive Address" data-content="Click this button to hide the address from the main view. You can restore or delete later by finding it in the Archived addresses tab.">Archive Address</a></li> <li><a href="#" class="pop act-label" title="Label Address" data-content="Set the label for this address.">Label Address</a></li> <li><a href="#" class="pop act-qr" title="Show QR Code" data-content="Show a QR Code for this address.">QR Code</a></li> <li><a href="#" class="pop act-sign" title="Sign Message" data-content="Sign A message with this address.">Sign Message</a></li> <li><a href="#" class="pop act-request" title="Request Payment" data-content="Click here to create a new QR Code payment request. The QR Code can be scanned using most popular bitcoin software and mobile apps.">Create Payment Request</a></li> <li><a href="#" class="pop act-pubkey">Show Public Key</a></li> </ul></div></td></tr>');(function(a4){aX.find(".act-archive").click(function(){h.archiveAddr(a4)});aX.find(".act-label").click(function(){loadScript("wallet/address_modal",function(){showLabelAddressModal(a4)})});aX.find(".act-qr").click(function(){loadScript("wallet/address_modal",function(){showAddressModalQRCode(a4)})});aX.find(".act-pubkey").click(function(){h.getSecondPassword(function(){var a5=h.getPrivateKey(a4);if(a5==null){h.makeNotice("eror","misc-error","Public Key Unknown");return}var a6=new Bitcoin.ECKey(h.decodePK(a5));if(a6.getBitcoinAddressCompressed().toString()==a4){var a7=a6.getPubCompressed()}else{var a7=a6.getPub()}h.makeNotice("success","pub-key","Public Key of "+a4+" is "+Crypto.util.bytesToHex(a7),20000)})});aX.find(".act-sign").click(function(){loadScript("wallet/address_modal",function(){showAddressModalSignMessage(a4)})});aX.find(".act-request").click(function(){loadScript("wallet/frame-modal",function(){showFrameModal({title:"Create Payment Request",description:"Request Payment into address <b>"+a4+"</b>",src:root+"payment_request?address="+a4})})})})(a3.addr);if(a3.balance>0&&a3.priv){a2.prepend(aX)}else{a2.append(aX)}}aD()});$("#archived-addresses").on("show",function(){$("#enable_archived_checkbox").prop("checked",false);$("#archived-delete").prop("disabled",true);$("#archived-sweep").prop("disabled",true);$("#archived-addr tbody").empty();var aX=$(this).find("tbody");var aW=h.getArchivedAddresses();var aY=function(){aX.empty();for(var a2 in aW){var a4=I[aW[a2]];if(a4.tag!=2||(a4.tag==1&&!aq)){continue}var a1="";if(a4.priv==null){a1=' <font color="red">(Watch Only)</font>'}var aZ="";var a0=a4.addr;if(a4.label!=null){a0=a4.label;aZ='<span class="hidden-phone"> - '+a4.addr+"</span>"}var a3=$('<tr><td style="width:20px;"><input type="checkbox" class="archived_checkbox" value="'+a4.addr+'" disabled></td><td><div class="short-addr"><a href="'+root+"address/"+a4.addr+'" target="new">'+a0+"</a>"+aZ+" "+a1+'<div></td><td><span style="color:green">'+formatBTC(a4.balance)+'</span></td><td style="width:16px"><img src="'+resource+'unarchive.png" class="act-unarchive" /></td></tr>');(function(a5){a3.find(".act-unarchive").click(function(){h.unArchiveAddr(a5)})})(a4.addr);if(a4.balance>0&&a4.priv){aX.prepend(a3)}else{aX.append(a3)}}};aY();BlockchainAPI.get_balances(aW,function(aZ){aY()},function(aZ){h.makeNotice("error","misc-error",aZ)})});$("#archived-sweep").click(function(){var aW=[];$(".archived_checkbox:checked").each(function(){var aX=I[$(this).val()];if(aX.priv==null){h.makeNotice("error","misc-error","Cannot Sweep Watch Only Address");return}aW.push(aX.addr)});if(aW.length==0){return}h.sweepAddressesModal(aW)});$("#archived-delete").click(function(){var aW=[];$(".archived_checkbox:checked").each(function(){aW.push($(this).val())});if(aW.length==0){return}an(aW)});$("#shared-never-ask").click(function(){SetCookie("shared-never-ask",$(this).is(":checked"))});$(".deposit-btn").click(function(){var aY=$(this);var aX=h.getPreferredAddress();var aW=aY.data("extra");if(aW==null){aW=""}loadScript("wallet/frame-modal",function(){showFrameModal({title:aY.data("title"),description:"Deposit into address <b>"+aX+"</b>",top_right:'Have Questions? Read <a href="'+aY.data("link")+'" target="new">How It Works</a>',src:root+"deposit?address="+aX+"&ptype="+aY.data("type")+"&guid="+M+aW})})});$(".withdraw-btn").click(function(){var aW=$(this);h.getSecondPassword(function(){var aX=h.getPreferredAddress();loadScript("wallet/frame-modal",function(){showFrameModal({title:aW.data("title"),description:"Your Wallet Balance is <b>"+formatBTC(az)+"</b>",src:root+"withdraw?method="+aW.data("type")+"&address="+aX+"&balance="+az+"&guid="+M})})})});$("#logout").click(h.logout);$("#refresh").click(function(){J();h.get_history()});$("#summary-n-tx-chart").click(function(){loadScript("wallet/frame-modal",function(){showFrameModal({title:"Number of transactions",description:"",src:root+"charts/n-transactions?show_header=false&address="+h.getActiveAddresses().join("|")})})});$("#summary-received-chart").click(function(){loadScript("wallet/frame-modal",function(){showFrameModal({title:"BTC Received Per Day",description:"",src:root+"charts/received-per-day?show_header=false&address="+h.getActiveAddresses().join("|")})})});$("#summary-balance-chart").click(function(){loadScript("wallet/frame-modal",function(){showFrameModal({title:"Wallet Balance",description:"",src:root+"charts/balance?show_header=false&address="+h.getActiveAddresses().join("|")})})});$("#new-addr").click(function(){try{J(function(){h.getSecondPassword(function(){var aY=h.generateNewKey();if(!aY){return}var aX=aY.getBitcoinAddress().toString();h.backupWallet("update",function(){h.makeNotice("info","new-address","Generated new Bitcoin Address "+aX);loadScript("wallet/address_modal",function(){showLabelAddressModal(aX)})})})})}catch(aW){h.makeNotice("error","misc-error",aW)}});$(".tx_filter a").click(function(){ax=0;ar=$(this).data("value");h.get_history()});$(".tx_display a").click(function(){var aW=$(this).data("value");if(aW=="export"){v();return}s.tx_display=aW;c();h.backupWalletDelayed()});$("#email-backup-btn").click(function(){G()});$("#dropbox-backup-btn").click(function(){h.openWindow(root+"wallet/dropbox-login?guid="+M)});$("#gdrive-backup-btn").click(function(){h.openWindow(root+"wallet/gdrive-login?guid="+M)});$("#large-summary").click(function(){toggleSymbol();c()});$("#send-quick").on("show",function(aY,aX){var aW=$(this);r(aW,aX);aW.find(".send").unbind().click(function(){loadScript("wallet/signer",function(){startTxUI(aW,"quick",initNewTx())})})});$("#send-email").on("show",function(aY,aX){var aW=$(this);r(aW,aX);aW.find(".send").unbind().click(function(){loadScript("wallet/signer",function(){startTxUI(aW,"email",initNewTx())})})});$("#send-shared").on("show",function(aY,aX){var aW=$(this);r(aW,aX);aW.find(".mixer_fee").text(x);aW.find(".fees,.free,.bonus").show();if(x<0){aW.find(".fees,.free").hide()}else{if(x==0){aW.find(".fees,.bonus").hide()}else{aW.find(".free,.bonus").hide()}}aW.find(".send").unbind().click(function(){loadScript("wallet/signer",function(){startTxUI(aW,"shared",initNewTx())})});aW.find(".shared-fees").text("0.00");aW.find('input[name="send-before-fees"]').unbind().bind("keyup change",function(){var a0=parseFloat($(this).val());var aZ=0;if(a0>0){if(x>0){aZ=parseFloat(a0+((a0/100)*x))}else{aZ=parseFloat(a0);aW.find(".bonus-value").text(formatPrecision((Math.min(a0,precisionFromBTC(200))/100)*x))}}if(precisionToBTC(a0)<0.1||precisionToBTC(a0)>250){aW.find(".shared-fees").text("0.00");aW.find(".send").prop("disabled",true)}else{aW.find(".shared-fees").text(formatBTC(aZ*symbol_btc.conversion));aW.find(".send").prop("disabled",false)}aW.find(".send-value").val(aZ).trigger("keyup")})});$("#send-custom").on("show",function(aY,aX){var aW=$(this);r(aW,aX);aW.find(".send").unbind().click(function(){var aZ=false;if(aW.find('textarea[name="public-note"]').val()){aW.find(".send-value").each(function(){if($(this).val()<0.0001){h.makeNotice("error","misc-error","You cannot attach a note to a transaction with an output size less than 0.0001 BTC");aZ=true;return false}})}if(!aZ){loadScript("wallet/signer",function(){startTxUI(aW,"custom",initNewTx())})}});aW.find('input[name="fees"]').unbind().bind("keyup change",function(aZ){if(aZ.keyCode=="9"){return}$(this).parent().find(".send-value-usd").val(convert($(this).val()*symbol_btc.conversion,symbol_local.conversion)).text(formatSymbol($(this).val()*symbol_btc.conversion,symbol_local))});aW.find(".reset").unbind().click(function(){r(aW,true);aW.find('select[name="from"]').trigger("change")})});$("#send-satoshi-dice").on("show",function(aY,aX){var aW=this;loadScript("wallet/dicegames",function(){try{DICEGame.init($(aW))}catch(aZ){h.makeNotice("error","misc-error","Unable To Load Dice Bets")}},function(aZ){h.makeNotice("error","misc-error",aZ)})});$("#shared-coin").on("show",function(aY,aX){var aW=$(this);loadScript("wallet/sharedcoin",function(){try{r(aW);SharedCoin.init(aW)}catch(aZ){console.log(aZ);h.makeNotice("error","misc-error",aZ)}},function(aZ){h.makeNotice("error","misc-error",aZ)})});$("#send-sms").on("show",function(aY,aX){if(aX){return}var aW=$(this);r(aW);$.ajax({type:"GET",url:resource+"wallet/country_codes.html",success:function(aZ){aW.find('select[name="sms-country-code"]').html(aZ)},error:function(){h.makeNotice("error","misc-error","Error Downloading SMS Country Codes")}});aW.find(".send").unbind().click(function(){loadScript("wallet/signer",function(){var aZ=initNewTx();startTxUI(aW,"sms",aZ)})})});$("#address-book").on("show",function(){var aX=$("#address-book-tbl tbody");if(aF(g)>0){aX.empty();for(var aW in g){var aY=$("<tr><td>"+g[aW]+'</td><td><div class="addr-book-entry">'+aW+'</div></td><td style="width:16px" class="hidden-phone"><img src="'+resource+'delete.png" class="act-delete" /></td></tr>');(function(aZ){aY.find(".act-delete").click(function(){h.deleteAddressBook(aZ)})})(aW);aX.append(aY)}}});$('a[data-toggle="tab"]').unbind().on("show",function(aW){$(aW.target.hash).trigger("show")});$("#receive-coins-btn").click(function(){af($("#receive-coins"))});$("#cash-into-coins").click(function(){$(this).attr("href",$(this).attr("href")+h.getPreferredAddress())});$(".show_adv").click(function(){$(".modal:visible").center()});$(".download-backup-btn").show();aD()}function p(){$(".resend-code").click(function(){h.setGUID(M,true)});$("#reset-two-factor-btn").click(function(){h.openWindow(root+"wallet/reset-two-factor"+(M?"?guid="+M:""))});$(".recover-wallet-btn").click(function(){h.openWindow(root+"wallet/forgot-password"+(M?"?guid="+M:""))});$(".download-backup-btn").toggle(ai!=null).click(function(){if(!ai){h.makeNotice("error","error","No Wallet Data to Download");return}try{var aX=!!new Blob()}catch(aY){}if(aX){loadScript("wallet/filesaver",function(){var aZ=new Blob([ai],{type:"text/plain;charset=utf-8"});saveAs(aZ,"wallet.aes.json")})}else{var aW=window.open(null,null,"width=700,height=800,toolbar=0");aW.document.write('<!DOCTYPE html><html><head></head><body><div style="word-wrap:break-word;" >'+ai+"</div></body></html>")}aT()});$(".auth-0,.auth-1,.auth-2,.auth-3,.auth-4,.auth-5").unbind().keypress(function(aW){if(aW.keyCode==13){aW.preventDefault();$("#restore-wallet-continue").click()}});$("#restore-wallet-continue").unbind().click(function(aX){aX.preventDefault();var aW=$.trim($("#restore-guid").val());if(aW.length==0){return}if(M!=aW){h.setGUID(aW,false)}else{a()}});$(".modal").on("show",function(){L();$(this).center()}).on("hidden",function(){var aX=$(".modal:visible");var aW=$("#notices").remove();if(aX.length>0){aX.find(".modal-body").prepend(aW)}else{$("#main-notices-container").append(aW)}}).on("shown",function(){L();var aW=$(this);setTimeout(function(){if(aW.is(":visible")){aW.find(".modal-body").prepend($("#notices").remove())}},100);aW.center()})}function al(aX){var aY=Crypto.SHA256(aX+"?");switch(aY.slice(0,2)){case"00":var aZ=Crypto.SHA256(aX,{asBytes:true});return aZ;break;case"01":var aW=Crypto.util.hexToBytes(aY.slice(2,4))[0];var a0=Math.round(Math.pow(2,(aW/4)));var aZ=Crypto.PBKDF2(aX,"Satoshi Nakamoto",32,{iterations:a0,asBytes:true});return aZ;break;default:console.log("invalid key");break}}function aI(){var aY,aW="";if(window.getSelection){aY=window.getSelection();if(aY.rangeCount){var aZ=aY.getRangeAt(0).cloneContents();var aX=document.createElement("div");aX.appendChild(aZ);aW=aX.innerText}}else{if(document.selection&&document.selection.type=="Text"){aW=document.selection.createRange().htmlText}}return aW}this.detectPrivateKeyFormat=function(aX){if(/^5[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{50}$/.test(aX)){return"sipa"}if(/^[LK][123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(aX)){return"compsipa"}if(/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{44}$/.test(aX)||/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{43}$/.test(aX)){return"base58"}if(/^[A-Fa-f0-9]{64}$/.test(aX)){return"hex"}if(/^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789=+\/]{44}$/.test(aX)){return"base64"}if(/^6P[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{56}$/.test(aX)){return"bip38"}if(/^S[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{21}$/.test(aX)||/^S[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{25}$/.test(aX)||/^S[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{29}$/.test(aX)||/^S[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{30}$/.test(aX)){var aW=Crypto.SHA256(aX+"?",{asBytes:true});if(aW[0]===0||aW[0]===1){return"mini"}}throw"Unknown Key Format "+aX};this.privateKeyStringToKey=function(aX,aZ){var aW=null;if(aZ=="base58"){aW=B58.decode(aX)}else{if(aZ=="base64"){aW=Crypto.util.base64ToBytes(aX)}else{if(aZ=="hex"){aW=Crypto.util.hexToBytes(aX)}else{if(aZ=="mini"){aW=al(aX)}else{if(aZ=="sipa"){var aY=B58.decode(aX);aY.shift();aW=aY.slice(0,aY.length-4)}else{if(aZ=="compsipa"){var aY=B58.decode(aX);aY.shift();aY.pop();aW=aY.slice(0,aY.length-4)}else{throw"Unsupported Key Format"}}}}}}if(aW.length!=32){throw"Result not 32 bytes in length"}return new Bitcoin.ECKey(aW)};$(document).ready(function(){if(!$.isEmptyObject({})){h.makeNotice("error","error","Object.prototype has been extended by a browser extension. Please disable this extensions and reload the page.");return}$("input,button,select").attr("autocomplete","off");var a0=$(document.body);function a1(){if(M&&M.length==36){setTimeout(function(){h.setGUID(M,false)},10)}else{$("#signup-btn").show()}}M=a0.data("guid");d=a0.data("sharedkey");X=a0.data("language");if(h.skip_init){return}var a2=1;function aZ(){--a2;if(a2==-1){p()}}MyStore.get("payload",function(a5){if(!ai&&a5){ai=a5;aA=ah()}aZ()});MyStore.get("server_time_offset",function(a5){aM=parseInt(a5);if(isNaN(aM)){aM=0}});if((!M||M.length==0)&&(isExtension||window.location.href.indexOf("/login")>0)){++a2;MyStore.get("guid",function(a5){M=a5;a1();aZ()})}else{a1()}if(top.location!=self.location){top.location=self.location.href}a0.click(function(){if(U){clearTimeout(U);U=setTimeout(h.logout,h.getLogoutTime())}rng_seed_time()}).keypress(function(){if(U){clearTimeout(U);U=setTimeout(h.logout,h.getLogoutTime())}rng_seed_time()}).mousemove(function(a5){if(a5){rng_seed_int(a5.clientX*a5.clientY)}});aZ();$(".auth-"+q).show();j=$("#restore-wallet");j.show();var a4=false;var aX=17,aY=86,aW=67,a3=67;$(document).keydown(function(a6){try{if(a6.keyCode==aX||a6.keyCode==a3){a4=true}if(a4&&a6.keyCode==aW){var a5=$.trim(aI());var a7=I[a5];if(a7!=null){if(a7.priv==null){$("#watch-only-copy-warning-modal").modal("show")}else{if(a7.tag==1){O()}}}}}catch(a6){console.log(a6)}}).keyup(function(a5){if(a5.keyCode==aX||a5.keyCode==a3){a4=false}}).ajaxStart(function(){au("loading_start");$(".loading-indicator").fadeIn(200)}).ajaxStop(function(){au("loading_stop");$(".loading-indicator").hide()})});function aV(){$("#receive-coins").find(".tab-pane.active").trigger("show");setupToggle()}};