|
|
|
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Bitcoin=e()}}(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(_dereq_,module,exports){var util=_dereq_("util/");var pSlice=Array.prototype.slice;var hasOwn=Object.prototype.hasOwnProperty;var assert=module.exports=ok;assert.AssertionError=function AssertionError(options){this.name="AssertionError";this.actual=options.actual;this.expected=options.expected;this.operator=options.operator;if(options.message){this.message=options.message;this.generatedMessage=false}else{this.message=getMessage(this);this.generatedMessage=true}var stackStartFunction=options.stackStartFunction||fail;if(Error.captureStackTrace){Error.captureStackTrace(this,stackStartFunction)}else{var err=new Error;if(err.stack){var out=err.stack;var fn_name=stackStartFunction.name;var idx=out.indexOf("\n"+fn_name);if(idx>=0){var next_line=out.indexOf("\n",idx+1);out=out.substring(next_line+1)}this.stack=out}}};util.inherits(assert.AssertionError,Error);function replacer(key,value){if(util.isUndefined(value)){return""+value}if(util.isNumber(value)&&(isNaN(value)||!isFinite(value))){return value.toString()}if(util.isFunction(value)||util.isRegExp(value)){return value.toString()}return value}function truncate(s,n){if(util.isString(s)){return s.length<n?s:s.slice(0,n)}else{return s}}function getMessage(self){return truncate(JSON.stringify(self.actual,replacer),128)+" "+self.operator+" "+truncate(JSON.stringify(self.expected,replacer),128)}function fail(actual,expected,message,operator,stackStartFunction){throw new assert.AssertionError({message:message,actual:actual,expected:expected,operator:operator,stackStartFunction:stackStartFunction})}assert.fail=fail;function ok(value,message){if(!value)fail(value,true,message,"==",assert.ok)}assert.ok=ok;assert.equal=function equal(actual,expected,message){if(actual!=expected)fail(actual,expected,message,"==",assert.equal)};assert.notEqual=function notEqual(actual,expected,message){if(actual==expected){fail(actual,expected,message,"!=",assert.notEqual)}};assert.deepEqual=function deepEqual(actual,expected,message){if(!_deepEqual(actual,expected)){fail(actual,expected,message,"deepEqual",assert.deepEqual)}};function _deepEqual(actual,expected){if(actual===expected){return true}else if(util.isBuffer(actual)&&util.isBuffer(expected)){if(actual.length!=expected.length)return false;for(var i=0;i<actual.length;i++){if(actual[i]!==expected[i])return false}return true}else if(util.isDate(actual)&&util.isDate(expected)){return actual.getTime()===expected.getTime()}else if(util.isRegExp(actual)&&util.isRegExp(expected)){return actual.source===expected.source&&actual.global===expected.global&&actual.multiline===expected.multiline&&actual.lastIndex===expected.lastIndex&&actual.ignoreCase===expected.ignoreCase}else if(!util.isObject(actual)&&!util.isObject(expected)){return actual==expected}else{return objEquiv(actual,expected)}}function isArguments(object){return Object.prototype.toString.call(object)=="[object Arguments]"}function objEquiv(a,b){if(util.isNullOrUndefined(a)||util.isNullOrUndefined(b))return false;if(a.prototype!==b.prototype)return false;if(isArguments(a)){if(!isArguments(b)){return false}a=pSlice.call(a);b=pSlice.call(b);return _deepEqual(a,b)}try{var ka=objectKeys(a),kb=objectKeys(b),key,i}catch(e){return false}if(ka.length!=kb.length)return false;ka.sort();kb.sort();for(i=ka.length-1;i>=0;i--){if(ka[i]!=kb[i])return false}for(i=ka.length-1;i>=0;i--){key=ka[i];if(!_deepEqual(a
|
|
|
|
var Wi7h=Wi7[0];var Wi7l=Wi7[1];var Wi16=W[i-16];var Wi16h=Wi16[0];var Wi16l=Wi16[1];var Wil=gamma0l+Wi7l;var Wih=gamma0h+Wi7h+(Wil>>>0<gamma0l>>>0?1:0);var Wil=Wil+gamma1l;var Wih=Wih+gamma1h+(Wil>>>0<gamma1l>>>0?1:0);var Wil=Wil+Wi16l;var Wih=Wih+Wi16h+(Wil>>>0<Wi16l>>>0?1:0);Wi[0]=Wih;Wi[1]=Wil}var chh=eh&fh^~eh&gh;var chl=el&fl^~el≷var majh=ah&bh^ah&ch^bh&ch;var majl=al&bl^al&cl^bl&cl;var sigma0h=(ah>>>28|al<<4)^(ah<<30|al>>>2)^(ah<<25|al>>>7);var sigma0l=(al>>>28|ah<<4)^(al<<30|ah>>>2)^(al<<25|ah>>>7);var sigma1h=(eh>>>14|el<<18)^(eh>>>18|el<<14)^(eh<<23|el>>>9);var sigma1l=(el>>>14|eh<<18)^(el>>>18|eh<<14)^(el<<23|eh>>>9);var Ki=K[i];var Kih=Ki[0];var Kil=Ki[1];var t1l=hl+sigma1l;var t1h=hh+sigma1h+(t1l>>>0<hl>>>0?1:0);var t1l=t1l+chl;var t1h=t1h+chh+(t1l>>>0<chl>>>0?1:0);var t1l=t1l+Kil;var t1h=t1h+Kih+(t1l>>>0<Kil>>>0?1:0);var t1l=t1l+Wil;var t1h=t1h+Wih+(t1l>>>0<Wil>>>0?1:0);var t2l=sigma0l+majl;var t2h=sigma0h+majh+(t2l>>>0<sigma0l>>>0?1:0);hh=gh;hl=gl;gh=fh;gl=fl;fh=eh;fl=el;el=dl+t1l|0;eh=dh+t1h+(el>>>0<dl>>>0?1:0)|0;dh=ch;dl=cl;ch=bh;cl=bl;bh=ah;bl=al;al=t1l+t2l|0;ah=t1h+t2h+(al>>>0<t1l>>>0?1:0)|0}H0l=H0[1]=H0l+al;H0[0]=H0h+ah+(H0l>>>0<al>>>0?1:0);H1l=H1[1]=H1l+bl;H1[0]=H1h+bh+(H1l>>>0<bl>>>0?1:0);H2l=H2[1]=H2l+cl;H2[0]=H2h+ch+(H2l>>>0<cl>>>0?1:0);H3l=H3[1]=H3l+dl;H3[0]=H3h+dh+(H3l>>>0<dl>>>0?1:0);H4l=H4[1]=H4l+el;H4[0]=H4h+eh+(H4l>>>0<el>>>0?1:0);H5l=H5[1]=H5l+fl;H5[0]=H5h+fh+(H5l>>>0<fl>>>0?1:0);H6l=H6[1]=H6l+gl;H6[0]=H6h+gh+(H6l>>>0<gl>>>0?1:0);H7l=H7[1]=H7l+hl;H7[0]=H7h+hh+(H7l>>>0<hl>>>0?1:0);return H};module.exports=function(message,options){var H=[[1779033703,4089235720],[3144134277,2227873595],[1013904242,4271175723],[2773480762,1595750129],[1359893119,2917565137],[2600822924,725511199],[528734635,4215389547],[1541459225,327033209]];if(message.constructor===String){message=conv.stringToBytes(message)}var m=util.bytesToWords(message);var l=message.length*8;m[l>>5]|=128<<24-l%32;m[(l+64>>10<<5)+31]=l;for(var i=0;i<m.length;i+=32){processBlock(H,m,i)}var digestbytes=util.wordsToBytes(Array.prototype.concat.apply([],H));return options&&options.asBytes?digestbytes:options&&options.asString?Binary.bytesToString(digestbytes):conv.bytesToHex(digestbytes)};module.exports._blocksize=128},{"../convert":10,"../util":29}],16:[function(_dereq_,module,exports){var sec=_dereq_("./jsbn/sec");var util=_dereq_("./util");var SecureRandom=_dereq_("./jsbn/rng");var BigInteger=_dereq_("./jsbn/jsbn");var conv=_dereq_("./convert");var Crypto=_dereq_("./crypto-js/crypto.js");var ECPointFp=_dereq_("./jsbn/ec").ECPointFp;var rng=new SecureRandom;var ecparams=sec("secp256k1");var P_OVER_FOUR=null;function implShamirsTrick(P,k,Q,l){var m=Math.max(k.bitLength(),l.bitLength());var Z=P.add2D(Q);var R=P.curve.getInfinity();for(var i=m-1;i>=0;--i){R=R.twice2D();R.z=BigInteger.ONE;if(k.testBit(i)){if(l.testBit(i)){R=R.add2D(Z)}else{R=R.add2D(P)}}else{if(l.testBit(i)){R=R.add2D(Q)}}}return R}function deterministicGenerateK(hash,key){var v=[];var k=[];for(var i=0;i<32;i++)v.push(1);for(var i=0;i<32;i++)k.push(0);k=Crypto.HMAC(Crypto.SHA256,v.concat([0]).concat(key).concat(hash),k,{asBytes:true});v=Crypto.HMAC(Crypto.SHA256,v,k,{asBytes:true});k=Crypto.HMAC(Crypto.SHA256,v.concat([1]).concat(key).concat(hash),k,{asBytes:true});v=Crypto.HMAC(Crypto.SHA256,v,k,{asBytes:true});v=Crypto.HMAC(Crypto.SHA256,v,k,{asBytes:true});return BigInteger.fromByteArrayUnsigned(v)}var ECDSA={getBigRandom:function(limit){return new BigInteger(limit.bitLength(),rng).mod(limit.subtract(BigInteger.ONE)).add(BigInteger.ONE)},sign:function(hash,priv){var d=priv;var n=ecparams.getN();var e=BigInteger.fromByteArrayUnsigned(hash);var k=deterministicGenerateK(hash,priv.toByteArrayUnsigned());var G=ecparams.getG();var Q=G.multiply(k);var r=Q.getX().toBigInteger().mod(n);var s=k.modInverse(n).multiply(e.add(d.multiply(r))).mod(n);return ECDSA.serializeSig(r,s)},verify:function(hash,sig,pubkey){var r,s;if(util.isArray(sig)){var obj=ECDSA.parseSig(sig);r=obj.r;s=obj.s}else if("object"===typeof sig&&sig.r&&sig.s){r=sig.r;s=sig.s}else{throw new Error("Invalid value fo
|
|
|
|
}if((t=x>>2)!=0){x=t;r+=2}if((t=x>>1)!=0){x=t;r+=1}return r}function bnBitLength(){if(this.t<=0)return 0;return this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)}function bnpDLShiftTo(n,r){var i;for(i=this.t-1;i>=0;--i)r[i+n]=this[i];for(i=n-1;i>=0;--i)r[i]=0;r.t=this.t+n;r.s=this.s}function bnpDRShiftTo(n,r){for(var i=n;i<this.t;++i)r[i-n]=this[i];r.t=Math.max(this.t-n,0);r.s=this.s}function bnpLShiftTo(n,r){var self=this;var bs=n%self.DB;var cbs=self.DB-bs;var bm=(1<<cbs)-1;var ds=Math.floor(n/self.DB),c=self.s<<bs&self.DM,i;for(i=self.t-1;i>=0;--i){r[i+ds+1]=self[i]>>cbs|c;c=(self[i]&bm)<<bs}for(i=ds-1;i>=0;--i)r[i]=0;r[ds]=c;r.t=self.t+ds+1;r.s=self.s;r.clamp()}function bnpRShiftTo(n,r){var self=this;r.s=self.s;var ds=Math.floor(n/self.DB);if(ds>=self.t){r.t=0;return}var bs=n%self.DB;var cbs=self.DB-bs;var bm=(1<<bs)-1;r[0]=self[ds]>>bs;for(var i=ds+1;i<self.t;++i){r[i-ds-1]|=(self[i]&bm)<<cbs;r[i-ds]=self[i]>>bs}if(bs>0)r[self.t-ds-1]|=(self.s&bm)<<cbs;r.t=self.t-ds;r.clamp()}function bnpSubTo(a,r){var self=this;var i=0,c=0,m=Math.min(a.t,self.t);while(i<m){c+=self[i]-a[i];r[i++]=c&self.DM;c>>=self.DB}if(a.t<self.t){c-=a.s;while(i<self.t){c+=self[i];r[i++]=c&self.DM;c>>=self.DB}c+=self.s}else{c+=self.s;while(i<a.t){c-=a[i];r[i++]=c&self.DM;c>>=self.DB}c-=a.s}r.s=c<0?-1:0;if(c<-1)r[i++]=self.DV+c;else if(c>0)r[i++]=c;r.t=i;r.clamp()}function bnpMultiplyTo(a,r){var x=this.abs(),y=a.abs();var i=x.t;r.t=i+y.t;while(--i>=0)r[i]=0;for(i=0;i<y.t;++i)r[i+x.t]=x.am(0,y[i],r,i,0,x.t);r.s=0;r.clamp();if(this.s!=a.s)BigInteger.ZERO.subTo(r,r)}function bnpSquareTo(r){var x=this.abs();var i=r.t=2*x.t;while(--i>=0)r[i]=0;for(i=0;i<x.t-1;++i){var c=x.am(i,x[i],r,2*i,0,1);if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1))>=x.DV){r[i+x.t]-=x.DV;r[i+x.t+1]=1}}if(r.t>0)r[r.t-1]+=x.am(i,x[i],r,2*i,0,1);r.s=0;r.clamp()}function bnpDivRemTo(m,q,r){var self=this;var pm=m.abs();if(pm.t<=0)return;var pt=self.abs();if(pt.t<pm.t){if(q!=null)q.fromInt(0);if(r!=null)self.copyTo(r);return}if(r==null)r=nbi();var y=nbi(),ts=self.s,ms=m.s;var nsh=self.DB-nbits(pm[pm.t-1]);if(nsh>0){pm.lShiftTo(nsh,y);pt.lShiftTo(nsh,r)}else{pm.copyTo(y);pt.copyTo(r)}var ys=y.t;var y0=y[ys-1];if(y0==0)return;var yt=y0*(1<<self.F1)+(ys>1?y[ys-2]>>self.F2:0);var d1=self.FV/yt,d2=(1<<self.F1)/yt,e=1<<self.F2;var i=r.t,j=i-ys,t=q==null?nbi():q;y.dlShiftTo(j,t);if(r.compareTo(t)>=0){r[r.t++]=1;r.subTo(t,r)}BigInteger.ONE.dlShiftTo(ys,t);t.subTo(y,y);while(y.t<ys)y[y.t++]=0;while(--j>=0){var qd=r[--i]==y0?self.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);if((r[i]+=y.am(0,qd,r,j,0,ys))<qd){y.dlShiftTo(j,t);r.subTo(t,r);while(r[i]<--qd)r.subTo(t,r)}}if(q!=null){r.drShiftTo(ys,q);if(ts!=ms)BigInteger.ZERO.subTo(q,q)}r.t=ys;r.clamp();if(nsh>0)r.rShiftTo(nsh,r);if(ts<0)BigInteger.ZERO.subTo(r,r)}function bnMod(a){var r=nbi();this.abs().divRemTo(a,null,r);if(this.s<0&&r.compareTo(BigInteger.ZERO)>0)a.subTo(r,r);return r}function Classic(m){this.m=m}function cConvert(x){if(x.s<0||x.compareTo(this.m)>=0)return x.mod(this.m);else return x}function cRevert(x){return x}function cReduce(x){x.divRemTo(this.m,null,x)}function cMulTo(x,y,r){x.multiplyTo(y,r);this.reduce(r)}function cSqrTo(x,r){x.squareTo(r);this.reduce(r)}Classic.prototype.convert=cConvert;Classic.prototype.revert=cRevert;Classic.prototype.reduce=cReduce;Classic.prototype.mulTo=cMulTo;Classic.prototype.sqrTo=cSqrTo;function bnpInvDigit(){if(this.t<1)return 0;var x=this[0];if((x&1)==0)return 0;var y=x&3;y=y*(2-(x&15)*y)&15;y=y*(2-(x&255)*y)&255;y=y*(2-((x&65535)*y&65535))&65535;y=y*(2-x*y%this.DV)%this.DV;return y>0?this.DV-y:-y}function Montgomery(m){this.m=m;this.mp=m.invDigit();this.mpl=this.mp&32767;this.mph=this.mp>>15;this.um=(1<<m.DB-15)-1;this.mt2=2*m.t}function montConvert(x){var r=nbi();x.abs().dlShiftTo(this.m.t,r);r.divRemTo(this.m,null,r);if(x.s<0&&r.compareTo(BigInteger.ZERO)>0)this.m.subTo(r,r);return r}function montRevert(x){var r=nbi();x.copyTo(r);this.reduce(r);return r}function montReduce(x){while(x.t<=this.mt2)x[x.t++]=0;for(var i=0;i<this.m.t;++i){var j=x[i]&32767;var u0=j*this.mpl+((j*this.mph+(x[i]>>1
|
|
|
|
var util=_dereq_("./util");var conv=_dereq_("./convert");var Crypto=_dereq_("./crypto-js/crypto");var Wallet=_dereq_("./wallet");var ECKey=_dereq_("./eckey").ECKey;var ECDSA=_dereq_("./ecdsa");var Address=_dereq_("./address");var Transaction=function(doc){if(!(this instanceof Transaction)){return new Transaction(doc)}this.version=1;this.lock_time=0;this.ins=[];this.outs=[];this.timestamp=null;this.block=null;if(doc){if(typeof doc=="string"||util.isArray(doc)){doc=Transaction.deserialize(doc)}if(doc.hash)this.hash=doc.hash;if(doc.version)this.version=doc.version;if(doc.lock_time)this.lock_time=doc.lock_time;if(doc.ins&&doc.ins.length){for(var i=0;i<doc.ins.length;i++){this.addInput(new TransactionIn(doc.ins[i]))}}if(doc.outs&&doc.outs.length){for(var i=0;i<doc.outs.length;i++){this.addOutput(new TransactionOut(doc.outs[i]))}}if(doc.timestamp)this.timestamp=doc.timestamp;if(doc.block)this.block=doc.block}};Transaction.objectify=function(txs){var objs=[];for(var i=0;i<txs.length;i++){objs.push(new Transaction(txs[i]))}return objs};Transaction.prototype.addInput=function(tx,outIndex){if(arguments[0]instanceof TransactionIn){this.ins.push(arguments[0])}else if(arguments[0].length>65){var args=arguments[0].split(":");return this.addInput(args[0],args[1])}else{this.ins.push(new TransactionIn({outpoint:{hash:tx.hash||tx,index:outIndex},script:new Script,sequence:4294967295}))}};Transaction.prototype.addOutput=function(address,value){if(arguments[0]instanceof TransactionOut){this.outs.push(arguments[0]);return}if(arguments[0].indexOf(":")>=0){var args=arguments[0].split(":");address=args[0];value=parseInt(args[1])}this.outs.push(new TransactionOut({value:value,script:Script.createOutputScript(address)}))};Transaction.prototype.serialize=function(){var buffer=[];buffer=buffer.concat(util.numToBytes(parseInt(this.version),4));buffer=buffer.concat(util.numToVarInt(this.ins.length));for(var i=0;i<this.ins.length;i++){var txin=this.ins[i];buffer=buffer.concat(conv.hexToBytes(txin.outpoint.hash).reverse());buffer=buffer.concat(util.numToBytes(parseInt(txin.outpoint.index),4));var scriptBytes=txin.script.buffer;buffer=buffer.concat(util.numToVarInt(scriptBytes.length));buffer=buffer.concat(scriptBytes);buffer=buffer.concat(util.numToBytes(parseInt(txin.sequence),4))}buffer=buffer.concat(util.numToVarInt(this.outs.length));for(var i=0;i<this.outs.length;i++){var txout=this.outs[i];buffer=buffer.concat(util.numToBytes(txout.value,8));var scriptBytes=txout.script.buffer;buffer=buffer.concat(util.numToVarInt(scriptBytes.length));buffer=buffer.concat(scriptBytes)}buffer=buffer.concat(util.numToBytes(parseInt(this.lock_time),4));return buffer};Transaction.prototype.serializeHex=function(){return conv.bytesToHex(this.serialize())};var OP_CODESEPARATOR=171;var SIGHASH_ALL=1;var SIGHASH_NONE=2;var SIGHASH_SINGLE=3;var SIGHASH_ANYONECANPAY=80;Transaction.prototype.hashTransactionForSignature=function(connectedScript,inIndex,hashType){var txTmp=this.clone();for(var i=0;i<txTmp.ins.length;i++){txTmp.ins[i].script=new Script}txTmp.ins[inIndex].script=connectedScript;if((hashType&31)==SIGHASH_NONE){txTmp.outs=[];for(var i=0;i<txTmp.ins.length;i++)if(i!=inIndex)txTmp.ins[i].sequence=0}else if((hashType&31)==SIGHASH_SINGLE){}if(hashType&SIGHASH_ANYONECANPAY){txTmp.ins=[txTmp.ins[inIndex]]}var buffer=txTmp.serialize();buffer=buffer.concat(util.numToBytes(parseInt(hashType),4));var hash1=Crypto.SHA256(buffer,{asBytes:true});return Crypto.SHA256(hash1,{asBytes:true})};Transaction.prototype.getHash=function(){var buffer=this.serialize();return Crypto.SHA256(Crypto.SHA256(buffer,{asBytes:true}),{asBytes:true}).reverse()};Transaction.prototype.clone=function(){var newTx=new Transaction;newTx.version=this.version;newTx.lock_time=this.lock_time;for(var i=0;i<this.ins.length;i++){var txin=this.ins[i].clone();newTx.addInput(txin)}for(var i=0;i<this.outs.length;i++){var txout=this.outs[i].clone();newTx.addOutput(txout)}return newTx};Transaction.prototype.analyze=function(wallet){if(!(wallet instanceof Wallet))return null;var allFromMe=true,allToMe=true,firstRecv
|