(function(){functiono(e,t,n,r){return0<=e&&e<=15?t^n^r:16<=e&&e<=31?t&n|~t&r:32<=e&&e<=47?(t|~n)^r:48<=e&&e<=63?t&r|n&~r:64<=e&&e<=79?t^(n|~r):"rmd160_f: j out of range"}functionu(e){return0<=e&&e<=15?0:16<=e&&e<=31?1518500249:32<=e&&e<=47?1859775393:48<=e&&e<=63?2400959708:64<=e&&e<=79?2840853838:"rmd160_K1: j out of range"}functiona(e){return0<=e&&e<=15?1352829926:16<=e&&e<=31?1548603684:32<=e&&e<=47?1836072691:48<=e&&e<=63?2053994217:64<=e&&e<=79?0:"rmd160_K2: j out of range"}functionp(e,t){varn=(e&65535)+(t&65535),r=(e>>16)+(t>>16)+(n>>16);returnr<<16|n&65535}functiond(e,t){returne<<t|e>>>32-t}vare=Crypto,t=e.util,n=e.charenc,r=n.UTF8,i=n.Binary;t.bytesToLWords=function(e){vart=Array(e.length>>2);for(varn=0;n<t.length;n++)t[n]=0;for(varn=0;n<e.length*8;n+=8)t[n>>5]|=(e[n/8]&255)<<n%32;returnt},t.lWordsToBytes=function(e){vart=[];for(varn=0;n<e.length*32;n+=8)t.push(e[n>>5]>>>n%32&255);returnt};vars=e.RIPEMD160=function(e,n){varr=t.lWordsToBytes(s._rmd160(e));returnn&&n.asBytes?r:n&&n.asString?i.bytesToString(r):t.bytesToHex(r)};s._rmd160=function(e){e.constructor==String&&(e=r.stringToBytes(e));varn=t.bytesToLWords(e),i=e.length*8;n[i>>5]|=128<<i%32,n[(i+64>>>9<<4)+14]=i;vars=1732584193,v=4023233417,m=2562383102,g=271733878,y=3285377520;for(varb=0;b<n.length;b+=16){varw,E=s,S=v,x=m,T=g,N=y,C=s,k=v,L=m,A=g,O=y;for(varM=0;M<=79;++M)w=p(E,o(M,S,x,T)),w=p(w,n[b+f[M]]),w=p(w,u(M)),w=p(d(w,c[M]),N),E=N,N=T,T=d(x,10),x=S,S=w,w=p(C,o(79-M,k,L,A)),w=p(w,n[b+l[M]]),w=p(w,a(M)),w=p(d(w,h[M]),O),C=O,O=A,A=d(L,10),L=k,k=w;w=p(v,p(x,A)),v=p(m,p(T,O)),m=p(g,p(N,C)),g=p(y,p(E,k)),y=p(s,p(S,L)),s=w}return[s,v,m,g,y]};varf=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],l=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],c=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],h=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]})();
Bitcoin.Address=function(e){"string"==typeofe&&(e=Bitcoin.Address.decodeString(e)),this.hash=e,this.version=0},Bitcoin.Address.prototype.toString=function(){vare=this.hash.slice(0);e.unshift(this.version);vart=Crypto.SHA256(Crypto.SHA256(e,{asBytes:!0}),{asBytes:!0}),n=e.concat(t.slice(0,4));returnBitcoin.Base58.encode(n)},Bitcoin.Address.prototype.getHashBase64=function(){returnCrypto.util.bytesToBase64(this.hash)},Bitcoin.Address.decodeString=function(e){vart=Bitcoin.Base58.decode(e),n=t.slice(0,21),r=Crypto.SHA256(Crypto.SHA256(n,{asBytes:!0}),{asBytes:!0});if(r[0]!=t[21]||r[1]!=t[22]||r[2]!=t[23]||r[3]!=t[24])throw"Checksum validation failed!";vari=n.shift();if(i!=0)throw"Version "+i+" not supported!";returnn};
functionintegerToBytes(e,t){varn=e.toByteArrayUnsigned();if(t<n.length)n=n.slice(n.length-t);elsewhile(t>n.length)n.unshift(0);returnn}functiondmp(e){returneinstanceofBigInteger||(e=e.toBigInteger()),Crypto.util.bytesToHex(e.toByteArrayUnsigned())}ECFieldElementFp.prototype.getByteLength=function(){returnMath.floor((this.toBigInteger().bitLength()+7)/8)},ECPointFp.prototype.getEncoded=function(e){vart=this.getX().toBigInteger(),n=this.getY().toBigInteger(),r=integerToBytes(t,32);returne?n.isEven()?r.unshift(2):r.unshift(3):(r.unshift(4),r=r.concat(integerToBytes(n,32))),r},ECPointFp.decodeFrom=function(e,t){varn=t[0],r=t.length-1,i=t.slice(1,1+r/2),s=t.slice(1+r/2,1+r);i.unshift(0),s.unshift(0);varo=newBigInteger(i),u=newBigInteger(s);returnnewECPointFp(e,e.fromBigInteger(o),e.fromBigInteger(u))},ECPointFp.prototype.add2D=function(e){if(this.isInfinity())returne;if(e.isInfinity())returnthis;if(this.x.equals(e.x))returnthis.y.equals(e.y)?this.twice():this.curve.getInfinity();vart=e.x.subtract(this.x),n=e.y.subtract(this.y),r=n.divide(t),i=r.square().subtract(this.x).subtract(e.x),s=r.multiply(this.x.subtract(i)).subtract(this.y);returnnewECPointFp(this.curve,i,s)},ECPointFp.prototype.twice2D=function(){if(this.isInfinity())returnthis;if(this.y.toBigInteger().signum()==0)returnthis.curve.getInfinity();vare=this.curve.fromBigInteger(BigInteger.valueOf(2)),t=this.curve.fromBigInteger(BigInteger.valueOf(3)),n=this.x.square().multiply(t).add(this.curve.a).divide(this.y.multiply(e)),r=n.square().subtract(this.x.multiply(e)),i=n.multiply(this.x.subtract(r)).subtract(this.y);returnnewECPointFp(this.curve,r,i)},ECPointFp.prototype.multiply2D=function(e){if(this.isInfinity())returnthis;if(e.signum()==0)returnthis.curve.getInfinity();vart=e,n=t.multiply(newBigInteger("3")),r=this.negate(),i=this,s;for(s=n.bitLength()-2;s>0;--s){i=i.twice();varo=n.testBit(s),u=t.testBit(s);o!=u&&(i=i.add2D(o?this:r))}returni},ECPointFp.prototype.isOnCurve=function(){vare=this.getX().toBigInteger(),t=this.getY().toBigInteger(),n=this.curve.getA().toBigInteger(),r=this.curve.getB().toBigInteger(),i=this.curve.getQ(),s=t.multiply(t).mod(i),o=e.multiply(e).multiply(e).add(n.multiply(e)).add(r).mod(i);returns.equals(o)},ECPointFp.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"},ECPointFp.prototype.validate=function(){vare=this.curve.getQ();if(this.isInfinity())thrownewError("Point is at infinity.");vart=this.getX().toBigInteger(),n=this.getY().toBigInteger();if(t.compareTo(BigInteger.ONE)<0||t.compareTo(e.subtract(BigInteger.ONE))>0)thrownewError("x coordinate out of bounds");if(n.compareTo(BigInteger.ONE)<0||n.compareTo(e.subtract(BigInteger.ONE))>0)thrownewError("y coordinate out of bounds");if(!this.isOnCurve())thrownewError("Point is not on the curve.");if(this.multiply(e).isInfinity())thrownewError("Point is not a scalar multiple of G.");return!0},Bitcoin.ECDSA=function(){functionr(e,t,n,r){vari=Math.max(t.bitLength(),r.bitLength()),s=e.add2D(n),o=e.curve.getInfinity();for(varu=i-1;u>=0;--u)o=o.twice2D(),o.z=BigInteger.ONE,t.testBit(u)?r.testBit(u)?o=o.add2D(s):o=o.add2D(e):r.testBit(u)&&(o=o.add2D(n));returno}vare=getSECCurveByName("secp256k1"),t=newSecureRandom,n=null,i={getBigRandom:function(e){return(newBigInteger(e.bitLength(),t)).mod(e.subtract(BigInteger.ONE)).add(BigInteger.ONE)},sign:function(t,n){varr=n,s=e.getN(),o=BigInteger.fromByteArrayUnsigned(t);dovaru=i.getBigRandom(s),a=e.getG(),f=a.multiply(u),l=f.getX().toBigInteger().mod(s);while(l.compareTo(BigInteger.ZERO)<=0);varc=u.modInverse(s).multiply(o.add(r.multiply(l))).mod(s);returni.serializeSig(l,c)},verify:function(t,n,r){vars,o;if(Bitcoin.Util.isArray(n)){varu=i.parseSig(n);s=u.r,o=u.s}else{if("object"!=typeofn||!n.r||!n.s)throw"Invalid value for signature";s=n.r,o=n.s}vara;if(rinstanceofECPointFp)a=r;else{if(!Bitcoin.Util.isArray(r))throw"Invalid format for pubkey value, must be byte array or ECPointFp";a=ECPointFp.decodeFrom(e.getCurve(),r
Bitcoin.ECKey=function(){vare=Bitcoin.ECDSA,t=getSECCurveByName("secp256k1"),n=newSecureRandom,r=function(n){if(!n){vari=t.getN();this.priv=e.getBigRandom(i)}elseninstanceofBigInteger?this.priv=n:Bitcoin.Util.isArray(n)?this.priv=BigInteger.fromByteArrayUnsigned(n):"string"==typeofn&&(n.length==51&&n[0]=="5"?this.priv=BigInteger.fromByteArrayUnsigned(r.decodeString(n)):this.priv=BigInteger.fromByteArrayUnsigned(Crypto.util.base64ToBytes(n)));this.compressed=!!r.compressByDefault};returnr.compressByDefault=!1,r.prototype.setCompressed=function(e){this.compressed=!!e},r.prototype.getPub=function(){returnthis.getPubPoint().getEncoded(this.compressed)},r.prototype.getPubPoint=function(){returnthis.pub||(this.pub=t.getG().multiply(this.priv)),this.pub},r.prototype.getPubKeyHash=function(){returnthis.pubKeyHash?this.pubKeyHash:this.pubKeyHash=Bitcoin.Util.sha256ripe160(this.getPub())},r.prototype.getBitcoinAddress=function(){vare=this.getPubKeyHash(),t=newBitcoin.Address(e);returnt},r.prototype.getExportedPrivateKey=function(){vare=this.priv.toByteArrayUnsigned();while(e.length<32)e.unshift(0);e.unshift(128);vart=Crypto.SHA256(Crypto.SHA256(e,{asBytes:!0}),{asBytes:!0}),n=e.concat(t.slice(0,4));returnBitcoin.Base58.encode(n)},r.prototype.setPub=function(e){this.pub=ECPointFp.decodeFrom(t.getCurve(),e)},r.prototype.toString=function(e){returne==="base64"?Crypto.util.bytesToBase64(this.priv.toByteArrayUnsigned()):Crypto.util.bytesToHex(this.priv.toByteArrayUnsigned())},r.prototype.sign=function(t){returne.sign(t,this.priv)},r.prototype.verify=function(t,n){returne.verify(t,n,this.getPub())},r.decodeString=function(e){vart=Bitcoin.Base58.decode(e),n=t.slice(0,33),r=Crypto.SHA256(Crypto.SHA256(n,{asBytes:!0}),{asBytes:!0});if(r[0]!=t[33]||r[1]!=t[34]||r[2]!=t[35]||r[3]!=t[36])throw"Checksum validation failed!";vari=n.shift();if(i!=128)throw"Version "+i+" not supported!";returnn},r}();
(function(){varOpcode=Bitcoin.Opcode;for(variinOpcode.map)eval("var "+i+" = "+Opcode.map[i]+";");varScript=Bitcoin.Script=function(e){if(!e)this.buffer=[];elseif("string"==typeofe)this.buffer=Crypto.util.base64ToBytes(e);elseif(Bitcoin.Util.isArray(e))this.buffer=e;else{if(!(einstanceofScript))thrownewError("Invalid script");this.buffer=e.buffer}this.parse()};Script.prototype.parse=function(){functionn(n){e.chunks.push(e.buffer.slice(t,t+n)),t+=n}vare=this;this.chunks=[];vart=0;while(t<this.buffer.length){varr=this.buffer[t++];r>=240&&(r=r<<8|this.buffer[t++]);vari;r>0&&r<OP_PUSHDATA1?n(r):r==OP_PUSHDATA1?(i=this.buffer[t++],n(i)):r==OP_PUSHDATA2?(i=this.buffer[t++]<<8|this.buffer[t++],n(i)):r==OP_PUSHDATA4?(i=this.buffer[t++]<<24|this.buffer[t++]<<16|this.buffer[t++]<<8|this.buffer[t++],n(i)):this.chunks.push(r)}},Script.prototype.getOutType=function(){returnthis.chunks[this.chunks.length-1]==OP_CHECKMULTISIG&&this.chunks[this.chunks.length-2]<=3?"Multisig":this.chunks.length==5&&this.chunks[0]==OP_DUP&&this.chunks[1]==OP_HASH160&&this.chunks[3]==OP_EQUALVERIFY&&this.chunks[4]==OP_CHECKSIG?"Address":this.chunks.length==2&&this.chunks[1]==OP_CHECKSIG?"Pubkey":"Strange"},Script.prototype.simpleOutHash=function(){switch(this.getOutType()){case"Address":returnthis.chunks[2];case"Pubkey":returnBitcoin.Util.sha256ripe160(this.chunks[0]);default:thrownewError("Encountered non-standard scriptPubKey")}},Script.prototype.simpleOutPubKeyHash=Script.prototype.simpleOutHash,Script.prototype.getInType=function(){returnthis.chunks.length==1&&Bitcoin.Util.isArray(this.chunks[0])?"Pubkey":this.chunks.length==2&&Bitcoin.Util.isArray(this.chunks[0])&&Bitcoin.Util.isArray(this.chunks[1])?"Address":"Strange"},Script.prototype.simpleInPubKey=function(){switch(this.getInType()){case"Address":returnthis.chunks[1];case"Pubkey":thrownewError("Script does not contain pubkey.");default:thrownewError("Encountered non-standard scriptSig")}},Script.prototype.simpleInHash=function(){returnBitcoin.Util.sha256ripe160(this.simpleInPubKey())},Script.prototype.simpleInPubKeyHash=Script.prototype.simpleInHash,Script.prototype.writeOp=function(e){this.buffer.push(e),this.chunks.push(e)},Script.prototype.writeBytes=function(e){e.length<OP_PUSHDATA1?this.buffer.push(e.length):e.length<=255?(this.buffer.push(OP_PUSHDATA1),this.buffer.push(e.length)):e.length<=65535?(this.buffer.push(OP_PUSHDATA2),this.buffer.push(e.length&255),this.buffer.push(e.length>>>8&255)):(this.buffer.push(OP_PUSHDATA4),this.buffer.push(e.length&255),this.buffer.push(e.length>>>8&255),this.buffer.push(e.length>>>16&255),this.buffer.push(e.length>>>24&255)),this.buffer=this.buffer.concat(e),this.chunks.push(e)},Script.createOutputScript=function(e){vart=newScript;returnt.writeOp(OP_DUP),t.writeOp(OP_HASH160),t.writeBytes(e.hash),t.writeOp(OP_EQUALVERIFY),t.writeOp(OP_CHECKSIG),t},Script.prototype.extractAddresses=function(e){switch(this.getOutType()){case"Address":returne.push(newAddress(this.chunks[2])),1;case"Pubkey":returne.push(newAddress(Util.sha256ripe160(this.chunks[0]))),1;case"Multisig":for(vart=1;t<this.chunks.length-2;++t)e.push(newAddress(Util.sha256ripe160(this.chunks[t])));returnthis.chunks[0]-OP_1+1;default:thrownewError("Encountered non-standard scriptPubKey")}},Script.createMultiSigOutputScript=function(e,t){varn=newBitcoin.Script;n.writeOp(OP_1+e-1);for(varr=0;r<t.length;++r)n.writeBytes(t[r]);returnn.writeOp(OP_1+t.length-1),n.writeOp(OP_CHECKMULTISIG),n},Script.createInputScript=function(e,t){varn=newScript;returnn.writeBytes(e),n.writeBytes(t),n},Script.prototype.clone=function(){returnnewScript(this.buffer)}})();
(function(){vare=Bitcoin.Script,t=Bitcoin.Transaction=function(e){this.version=1,this.lock_time=0,this.ins=[],this.outs=[],this.timestamp=null,this.block=null;if(e){e.hash&&(this.hash=e.hash),e.version&&(this.version=e.version),e.lock_time&&(this.lock_time=e.lock_time);if(e.ins&&e.ins.length)for(vart=0;t<e.ins.length;t++)this.addInput(newu(e.ins[t]));if(e.outs&&e.outs.length)for(vart=0;t<e.outs.length;t++)this.addOutput(newa(e.outs[t]));e.timestamp&&(this.timestamp=e.timestamp),e.block&&(this.block=e.block)}};t.objectify=function(e){varn=[];for(varr=0;r<e.length;r++)n.push(newt(e[r]));returnn},t.prototype.addInput=function(e,t){arguments[0]instanceofu?this.ins.push(arguments[0]):this.ins.push(newu({outpoint:{hash:e.hash,index:t},script:newBitcoin.Script,sequence:4294967295}))},t.prototype.addOutput=function(t,n){if(arguments[0]instanceofa)this.outs.push(arguments[0]);else{if(ninstanceofBigInteger){n=n.toByteArrayUnsigned().reverse();while(n.length<8)n.push(0)}elseBitcoin.Util.isArray(n);this.outs.push(newa({value:n,script:e.createOutputScript(t)}))}},t.prototype.serialize=function(){vare=[];e=e.concat(Crypto.util.wordsToBytes([parseInt(this.version)]).reverse()),e=e.concat(Bitcoin.Util.numToVarInt(this.ins.length));for(vart=0;t<this.ins.length;t++){varn=this.ins[t];e=e.concat(Crypto.util.base64ToBytes(n.outpoint.hash)),e=e.concat(Crypto.util.wordsToBytes([parseInt(n.outpoint.index)]).reverse());varr=n.script.buffer;e=e.concat(Bitcoin.Util.numToVarInt(r.length)),e=e.concat(r),e=e.concat(Crypto.util.wordsToBytes([parseInt(n.sequence)]).reverse())}e=e.concat(Bitcoin.Util.numToVarInt(this.outs.length));for(vart=0;t<this.outs.length;t++){vari=this.outs[t];e=e.concat(i.value);varr=i.script.buffer;e=e.concat(Bitcoin.Util.numToVarInt(r.length)),e=e.concat(r)}returne=e.concat(Crypto.util.wordsToBytes([parseInt(this.lock_time)]).reverse()),e};varn=171,r=1,i=2,s=3,o=80;t.prototype.hashTransactionForSignature=function(t,n,r){varu=this.clone();for(vara=0;a<u.ins.length;a++)u.ins[a].script=newe;u.ins[n].script=t;if((r&31)==i){u.outs=[];for(vara=0;a<u.ins.length;a++)a!=n&&(u.ins[a].sequence=0)}else(r&31)==s;r&o&&(u.ins=[u.ins[n]]);varf=u.serialize();f=f.concat(Crypto.util.wordsToBytes([parseInt(r)]).reverse());varl=Crypto.SHA256(f,{asBytes:!0});returnCrypto.SHA256(l,{asBytes:!0})},t.prototype.getHash=function(){vare=this.serialize();returnCrypto.SHA256(Crypto.SHA256(e,{asBytes:!0}),{asBytes:!0})},t.prototype.clone=function(){vare=newt;e.version=this.version,e.lock_time=this.lock_time;for(varn=0;n<this.ins.length;n++){varr=this.ins[n].clone();e.addInput(r)}for(varn=0;n<this.outs.length;n++){vari=this.outs[n].clone();e.addOutput(i)}returne},t.prototype.analyze=function(e){if(einstanceofBitcoin.Wallet){vart=!0,n=!0,r=null,i=null,s=null;for(varo=this.outs.length-1;o>=0;o--){varu=this.outs[o],a=u.script.simpleOutPubKeyHash();e.hasHash(a)?i=a:n=!1,r=a}for(varo=this.ins.length-1;o>=0;o--){varf=this.ins[o];s=f.script.simpleInPubKeyHash();if(!e.hasHash(s)){t=!1;break}}varl=this.calcImpact(e),c={};returnc.impact=l,l.sign>0&&l.value.compareTo(BigInteger.ZERO)>0?(c.type="recv",c.addr=newBitcoin.Address(i)):t&&n?c.type="self":t?(c.type="sent",c.addr=newBitcoin.Address(r)):c.type="other",c}returnnull},t.prototype.getDescription=function(e){vart=this.analyze(e);if(!t)return"";switch(t.type){case"recv":return"Received with "+t.addr;case"sent":return"Payment to "+t.addr;case"self":return"Payment to yourself";case"other":default:return""}},t.prototype.getTotalOutValue=function(){vare=BigInteger.ZERO;for(vart=0;t<this.outs.length;t++){varn=this.outs[t];e=e.add(Bitcoin.Util.valueToBigInt(n.value))}returne},t.prototype.getTotalValue=t.prototype.getTotalOutValue,t.prototype.calcImpact=function(e){if(einstanceofBitcoin.Wallet){vart=BigInteger.ZERO;for(varn=0;n<this.outs.length;n++){varr=this.outs[n],i=Crypto.util.bytesToBase64(r.script.simpleOutPubKeyHash());e.hasHash(i)&&(t=t.add(Bitcoin.Util.valueToBigInt(r.value)))}vars=BigInteger.ZERO;for(varn=0;n<this.ins.length;n++){varo=this.ins[n],i=
Bitcoin.Wallet=function(){vare=Bitcoin.Script,t=Bitcoin.TransactionIn,n=Bitcoin.TransactionOut,r=function(){vare=[];this.addressHashes=[],this.txIndex={},this.unspentOuts=[],this.addressPointer=0,this.addKey=function(t,n){tinstanceofBitcoin.ECKey||(t=newBitcoin.ECKey(t)),e.push(t),n&&("string"==typeofn&&(n=Crypto.util.base64ToBytes(n)),t.setPub(n)),this.addressHashes.push(t.getBitcoinAddress().getHashBase64())},this.addKeys=function(e,t){"string"==typeofe&&(e=e.split(",")),"string"==typeoft&&(t=t.split(","));varn;if(Array.isArray(t)&&e.length==t.length)for(n=0;n<e.length;n++)this.addKey(e[n],t[n]);elsefor(n=0;n<e.length;n++)this.addKey(e[n])},this.getKeys=function(){vart=[];for(varn=0;n<e.length;n++)t.push(e[n].toString("base64"));returnt},this.getPubKeys=function(){vart=[];for(varn=0;n<e.length;n++)t.push(Crypto.util.bytesToBase64(e[n].getPub()));returnt},this.clear=function(){e=[]},this.getLength=function(){returne.length},this.getAllAddresses=function(){vart=[];for(varn=0;n<e.length;n++)t.push(e[n].getBitcoinAddress());returnt},this.getCurAddress=function(){returne[this.addressPointer]?e[this.addressPointer].getBitcoinAddress():null},this.getNextAddress=function(){returnthis.addressPointer++,e[this.addressPointer]||this.generateAddress(),e[this.addressPointer].getBitcoinAddress()},this.signWithKey=function(t,n){t=Crypto.util.bytesToBase64(t);for(varr=0;r<this.addressHashes.length;r++)if(this.addressHashes[r]==t)returne[r].sign(n);thrownewError("Missing key for signature")},this.getPubKeyFromHash=function(t){t=Crypto.util.bytesToBase64(t);for(varn=0;n<this.addressHashes.length;n++)if(this.addressHashes[n]==t)returne[n].getPub();thrownewError("Hash unknown")}};returnr.prototype.generateAddress=function(){this.addKey(newBitcoin.ECKey)},r.prototype.process=function(e){if(this.txIndex[e.hash])return;varr,i,s;for(r=0;r<e.outs.length;r++){varo=newn(e.outs[r]);s=Crypto.util.bytesToBase64(o.script.simpleOutPubKeyHash());for(i=0;i<this.addressHashes.length;i++)if(this.addressHashes[i]===s){this.unspentOuts.push({tx:e,index:r,out:o});break}}for(r=0;r<e.ins.length;r++){varu=newt(e.ins[r]),a=u.script.simpleInPubKey();s=Crypto.util.bytesToBase64(Bitcoin.Util.sha256ripe160(a));for(i=0;i<this.addressHashes.length;i++)if(this.addressHashes[i]===s){for(varf=0;f<this.unspentOuts.length;f++)u.outpoint.hash==this.unspentOuts[f].tx.hash&&u.outpoint.index==this.unspentOuts[f].index&&this.unspentOuts.splice(f,1);break}}this.txIndex[e.hash]=e},r.prototype.getBalance=function(){vare=BigInteger.valueOf(0);for(vart=0;t<this.unspentOuts.length;t++){varn=this.unspentOuts[t].out;e=e.add(Bitcoin.Util.valueToBigInt(n.value))}returne},r.prototype.createSend=function(t,n,r){vari=[],s=n.add(r),o=BigInteger.ZERO,u;for(u=0;u<this.unspentOuts.length;u++){i.push(this.unspentOuts[u]),o=o.add(Bitcoin.Util.valueToBigInt(this.unspentOuts[u].out.value));if(o.compareTo(s)>=0)break}if(o.compareTo(s)<0)thrownewError("Insufficient funds.");vara=o.subtract(s),f=newBitcoin.Transaction;for(u=0;u<i.length;u++)f.addInput(i[u].tx,i[u].index);f.addOutput(t,n),a.compareTo(BigInteger.ZERO)>0&&f.addOutput(this.getNextAddress(),a);varl=1;for(u=0;u<f.ins.length;u++){varc=f.hashTransactionForSignature(i[u].out.script,u,l),h=i[u].out.script.simpleOutPubKeyHash(),p=this.signWithKey(h,c);p.push(parseInt(l,10)),f.ins[u].script=e.createInputScript(p,this.getPubKeyFromHash(h))}returnf},r.prototype.clearTransactions=function(){this.txIndex={},this.unspentOuts=[]},r.prototype.hasHash=function(e){Bitcoin.Util.isArray(e)&&(e=Crypto.util.bytesToBase64(e));for(vart=0;t<this.addressHashes.length;t++)if(this.addressHashes[t]===e)return!0;return!1},r}();