diff --git a/bitcoinjs-min.js b/bitcoinjs-min.js index 687eead..35d3e51 100644 --- a/bitcoinjs-min.js +++ b/bitcoinjs-min.js @@ -1,4 +1,4 @@ -!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=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=0;i--){if(ka[i]!=kb[i])return false}for(i=ka.length-1;i>=0;i--){key=ka[i];if(!_deepEqual(a[key],b[key]))return false}return true}assert.notDeepEqual=function notDeepEqual(actual,expected,message){if(_deepEqual(actual,expected)){fail(actual,expected,message,"notDeepEqual",assert.notDeepEqual)}};assert.strictEqual=function strictEqual(actual,expected,message){if(actual!==expected){fail(actual,expected,message,"===",assert.strictEqual)}};assert.notStrictEqual=function notStrictEqual(actual,expected,message){if(actual===expected){fail(actual,expected,message,"!==",assert.notStrictEqual)}};function expectedException(actual,expected){if(!actual||!expected){return false}if(Object.prototype.toString.call(expected)=="[object RegExp]"){return expected.test(actual)}else if(actual instanceof expected){return true}else if(expected.call({},actual)===true){return true}return false}function _throws(shouldThrow,block,expected,message){var actual;if(util.isString(expected)){message=expected;expected=null}try{block()}catch(e){actual=e}message=(expected&&expected.name?" ("+expected.name+").":".")+(message?" "+message:".");if(shouldThrow&&!actual){fail(actual,expected,"Missing expected exception"+message)}if(!shouldThrow&&expectedException(actual,expected)){fail(actual,expected,"Got unwanted exception"+message)}if(shouldThrow&&actual&&expected&&!expectedException(actual,expected)||!shouldThrow&&actual){throw actual}}assert.throws=function(block,error,message){_throws.apply(this,[true].concat(pSlice.call(arguments)))};assert.doesNotThrow=function(block,message){_throws.apply(this,[false].concat(pSlice.call(arguments)))};assert.ifError=function(err){if(err){throw err}};var objectKeys=Object.keys||function(obj){var keys=[];for(var key in obj){if(hasOwn.call(obj,key))keys.push(key)}return keys}},{"util/":3}],2:[function(_dereq_,module,exports){module.exports=function isBuffer(arg){return arg&&typeof arg==="object"&&typeof arg.copy==="function"&&typeof arg.fill==="function"&&typeof arg.readUInt8==="function"}},{}],3:[function(_dereq_,module,exports){(function(process,global){var formatRegExp=/%[sdj%]/g;exports.format=function(f){if(!isString(f)){var objects=[];for(var i=0;i=len)return x;switch(x){case"%s":return String(args[i++]);case"%d":return Number(args[i++]);case"%j":try{return JSON.stringify(args[i++])}catch(_){return"[Circular]"}default:return x}});for(var x=args[i];i=3)ctx.depth=arguments[2];if(arguments.length>=4)ctx.colors=arguments[3];if(isBoolean(opts)){ctx.showHidden=opts}else if(opts){exports._extend(ctx,opts)}if(isUndefined(ctx.showHidden))ctx.showHidden=false;if(isUndefined(ctx.depth))ctx.depth=2;if(isUndefined(ctx.colors))ctx.colors=false;if(isUndefined(ctx.customInspect))ctx.customInspect=true;if(ctx.colors)ctx.stylize=stylizeWithColor;return formatValue(ctx,obj,ctx.depth)}exports.inspect=inspect;inspect.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]};inspect.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"};function stylizeWithColor(str,styleType){var style=inspect.styles[styleType];if(style){return"["+inspect.colors[style][0]+"m"+str+"["+inspect.colors[style][1]+"m"}else{return str}}function stylizeNoColor(str,styleType){return str}function arrayToHash(array){var hash={};array.forEach(function(val,idx){hash[val]=true});return hash}function formatValue(ctx,value,recurseTimes){if(ctx.customInspect&&value&&isFunction(value.inspect)&&value.inspect!==exports.inspect&&!(value.constructor&&value.constructor.prototype===value)){var ret=value.inspect(recurseTimes,ctx);if(!isString(ret)){ret=formatValue(ctx,ret,recurseTimes)}return ret}var primitive=formatPrimitive(ctx,value);if(primitive){return primitive}var keys=Object.keys(value);var visibleKeys=arrayToHash(keys);if(ctx.showHidden){keys=Object.getOwnPropertyNames(value)}if(isError(value)&&(keys.indexOf("message")>=0||keys.indexOf("description")>=0)){return formatError(value)}if(keys.length===0){if(isFunction(value)){var name=value.name?": "+value.name:"";return ctx.stylize("[Function"+name+"]","special")}if(isRegExp(value)){return ctx.stylize(RegExp.prototype.toString.call(value),"regexp")}if(isDate(value)){return ctx.stylize(Date.prototype.toString.call(value),"date")}if(isError(value)){return formatError(value)}}var base="",array=false,braces=["{","}"];if(isArray(value)){array=true;braces=["[","]"]}if(isFunction(value)){var n=value.name?": "+value.name:"";base=" [Function"+n+"]"}if(isRegExp(value)){base=" "+RegExp.prototype.toString.call(value)}if(isDate(value)){base=" "+Date.prototype.toUTCString.call(value)}if(isError(value)){base=" "+formatError(value)}if(keys.length===0&&(!array||value.length==0)){return braces[0]+base+braces[1]}if(recurseTimes<0){if(isRegExp(value)){return ctx.stylize(RegExp.prototype.toString.call(value),"regexp")}else{return ctx.stylize("[Object]","special")}}ctx.seen.push(value);var output;if(array){output=formatArray(ctx,value,recurseTimes,visibleKeys,keys)}else{output=keys.map(function(key){return formatProperty(ctx,value,recurseTimes,visibleKeys,key,array)})}ctx.seen.pop();return reduceToSingleString(output,base,braces)}function formatPrimitive(ctx,value){if(isUndefined(value))return ctx.stylize("undefined","undefined");if(isString(value)){var simple="'"+JSON.stringify(value).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return ctx.stylize(simple,"string")}if(isNumber(value))return ctx.stylize(""+value,"number");if(isBoolean(value))return ctx.stylize(""+value,"boolean");if(isNull(value))return ctx.stylize("null","null")}function formatError(value){return"["+Error.prototype.toString.call(value)+"]"}function formatArray(ctx,value,recurseTimes,visibleKeys,keys){var output=[];for(var i=0,l=value.length;i-1){if(array){str=str.split("\n").map(function(line){return" "+line}).join("\n").substr(2)}else{str="\n"+str.split("\n").map(function(line){return" "+line}).join("\n")}}}else{str=ctx.stylize("[Circular]","special")}}if(isUndefined(name)){if(array&&key.match(/^\d+$/)){return str}name=JSON.stringify(""+key);if(name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)){name=name.substr(1,name.length-2);name=ctx.stylize(name,"name")}else{name=name.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'");name=ctx.stylize(name,"string")}}return name+": "+str}function reduceToSingleString(output,base,braces){var numLinesEst=0;var length=output.reduce(function(prev,cur){numLinesEst++;if(cur.indexOf("\n")>=0)numLinesEst++;return prev+cur.replace(/\u001b\[\d\d?m/g,"").length+1},0);if(length>60){return braces[0]+(base===""?"":base+"\n ")+" "+output.join(",\n ")+" "+braces[1]}return braces[0]+base+" "+output.join(", ")+" "+braces[1]}function isArray(ar){return Array.isArray(ar)}exports.isArray=isArray;function isBoolean(arg){return typeof arg==="boolean"}exports.isBoolean=isBoolean;function isNull(arg){return arg===null}exports.isNull=isNull;function isNullOrUndefined(arg){return arg==null}exports.isNullOrUndefined=isNullOrUndefined;function isNumber(arg){return typeof arg==="number"}exports.isNumber=isNumber;function isString(arg){return typeof arg==="string"}exports.isString=isString;function isSymbol(arg){return typeof arg==="symbol"}exports.isSymbol=isSymbol;function isUndefined(arg){return arg===void 0}exports.isUndefined=isUndefined;function isRegExp(re){return isObject(re)&&objectToString(re)==="[object RegExp]"}exports.isRegExp=isRegExp;function isObject(arg){return typeof arg==="object"&&arg!==null}exports.isObject=isObject;function isDate(d){return isObject(d)&&objectToString(d)==="[object Date]"}exports.isDate=isDate;function isError(e){return isObject(e)&&(objectToString(e)==="[object Error]"||e instanceof Error)}exports.isError=isError;function isFunction(arg){return typeof arg==="function"}exports.isFunction=isFunction;function isPrimitive(arg){return arg===null||typeof arg==="boolean"||typeof arg==="number"||typeof arg==="string"||typeof arg==="symbol"||typeof arg==="undefined"}exports.isPrimitive=isPrimitive;exports.isBuffer=_dereq_("./support/isBuffer");function objectToString(o){return Object.prototype.toString.call(o)}function pad(n){return n<10?"0"+n.toString(10):n.toString(10)}var months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function timestamp(){var d=new Date;var time=[pad(d.getHours()),pad(d.getMinutes()),pad(d.getSeconds())].join(":");return[d.getDate(),months[d.getMonth()],time].join(" ")}exports.log=function(){console.log("%s - %s",timestamp(),exports.format.apply(exports,arguments))};exports.inherits=_dereq_("inherits");exports._extend=function(origin,add){if(!add||!isObject(add))return origin;var keys=Object.keys(add);var i=keys.length;while(i--){origin[keys[i]]=add[keys[i]]}return origin};function hasOwnProperty(obj,prop){return Object.prototype.hasOwnProperty.call(obj,prop)}}).call(this,_dereq_("/tmp/bitcoinjs-lib/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"),typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./support/isBuffer":2,"/tmp/bitcoinjs-lib/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":5,inherits:4}],4:[function(_dereq_,module,exports){if(typeof Object.create==="function"){module.exports=function inherits(ctor,superCtor){ctor.super_=superCtor;ctor.prototype=Object.create(superCtor.prototype,{constructor:{value:ctor,enumerable:false,writable:true,configurable:true}})}}else{module.exports=function inherits(ctor,superCtor){ctor.super_=superCtor;var TempCtor=function(){};TempCtor.prototype=superCtor.prototype;ctor.prototype=new TempCtor;ctor.prototype.constructor=ctor}}},{}],5:[function(_dereq_,module,exports){var process=module.exports={};process.nextTick=function(){var canSetImmediate=typeof window!=="undefined"&&window.setImmediate;var canPost=typeof window!=="undefined"&&window.postMessage&&window.addEventListener;if(canSetImmediate){return function(f){return window.setImmediate(f)}}if(canPost){var queue=[];window.addEventListener("message",function(ev){var source=ev.source;if((source===window||source===null)&&ev.data==="process-tick"){ev.stopPropagation();if(queue.length>0){var fn=queue.shift();fn()}}},true);return function nextTick(fn){queue.push(fn);window.postMessage("process-tick","*")}}return function nextTick(fn){setTimeout(fn,0)}}();process.title="browser";process.browser=true;process.env={};process.argv=[];process.binding=function(name){throw new Error("process.binding is not supported")};process.cwd=function(){return"/"};process.chdir=function(dir){throw new Error("process.chdir is not supported")}},{}],6:[function(_dereq_,module,exports){module.exports=_dereq_(2)},{}],7:[function(_dereq_,module,exports){module.exports=_dereq_(3)},{"./support/isBuffer":6,"/tmp/bitcoinjs-lib/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":5,inherits:4}],8:[function(_dereq_,module,exports){var base58=_dereq_("./base58");var Crypto=_dereq_("./crypto-js/crypto");var conv=_dereq_("./convert");var util=_dereq_("./util");var address_types={prod:0,testnet:111};var p2sh_types={prod:5,testnet:196};var Address=function(bytes,version){if(!(this instanceof Address)){return new Address(bytes,version)}if(arguments[0]instanceof Address){this.hash=arguments[0].hash;this.version=arguments[0].version}else if(typeof bytes==="string"){this.hash=bytes.length<=34?base58.checkDecode(bytes):bytes.length<=40?conv.hexToBytes(bytes):util.error("Bad input");this.version=version||this.hash.version||0}else{this.hash=bytes;this.version=version||0}};Address.prototype.toString=function(){return base58.checkEncode(this.hash.slice(0),this.version)};Address.prototype.getHash=function(){return conv.bytesToHex(this.hash)};Address.getVersion=function(string){return base58.decode(string)[0]};Address.validate=function(string){try{base58.checkDecode(string);return true}catch(e){return false}};Address.decodeString=function(string){return base58.checkDecode(string)};module.exports=Address},{"./base58":9,"./convert":10,"./crypto-js/crypto":11,"./util":29}],9:[function(_dereq_,module,exports){var BigInteger=_dereq_("./jsbn/jsbn");var Crypto=_dereq_("./crypto-js/crypto");var conv=_dereq_("./convert");var alphabet="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var base=BigInteger.valueOf(58);var positions={};for(var i=0;i=0){var mod=bi.mod(base);chars.push(alphabet[mod.intValue()]);bi=bi.subtract(mod).divide(base)}chars.push(alphabet[bi.intValue()]);for(var i=0;i0){bytes.unshift(0)}return bytes};module.exports.decodeHex=function(input){return module.exports.decode(conv.hexToBytes(input))};module.exports.checkEncode=function(input,vbyte){vbyte=vbyte||0;var front=[vbyte].concat(input);var checksum=Crypto.SHA256(Crypto.SHA256(front,{asBytes:true}),{asBytes:true}).slice(0,4);return module.exports.encode(front.concat(checksum))};module.exports.checkEncodeHex=function(input,vbyte){return conv.bytesToHex(module.exports.encode(input))};module.exports.checkDecode=function(input){var bytes=module.exports.decode(input),front=bytes.slice(0,bytes.length-4),back=bytes.slice(bytes.length-4);var checksum=Crypto.SHA256(Crypto.SHA256(front,{asBytes:true}),{asBytes:true}).slice(0,4);if(""+checksum!=""+back){throw new Error("Checksum failed")}var o=front.slice(1);o.version=front[0];return o};module.exports.checkDecodeHex=function(input){return module.exports.checkDecode(conv.hexToBytes(input))}},{"./convert":10,"./crypto-js/crypto":11,"./jsbn/jsbn":21}],10:[function(_dereq_,module,exports){var base64map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";String.prototype.lpad=function(padString,length){var str=this;while(str.length>>6*(3-j)&63));else base64.push("=")}}return base64.join("")};module.exports.base64ToBytes=function(base64){base64=base64.replace(/[^A-Z0-9+\/]/gi,"");for(var bytes=[],i=0,imod4=0;i>>6-imod4*2)}return bytes};module.exports.coerceToBytes=function(input){if(typeof input=="string")return module.exports.hexToBytes(input);return input};module.exports.binToBytes=function(bin){return bin.match(/......../g).map(function(x){return parseInt(x,2)})};module.exports.bytesToBin=function(bytes){return bytes.map(function(x){return x.toString(2).lpad("0",8)}).join("")};module.exports.bytesToString=function(bytes){return bytes.map(function(x){return String.fromCharCode(x)}).join("")};module.exports.stringToBytes=function(string){return string.split("").map(function(x){return x.charCodeAt(0)})}},{}],11:[function(_dereq_,module,exports){var Crypto=module.exports={};var util=Crypto.util={randomBytes:function(n){for(var bytes=[];n>0;n--)bytes.push(Math.floor(Math.random()*256));return bytes}};Crypto.mode={};var charenc=Crypto.charenc={};var UTF8=charenc.UTF8={stringToBytes:function(str){return Binary.stringToBytes(unescape(encodeURIComponent(str)))},bytesToString:function(bytes){return decodeURIComponent(escape(Binary.bytesToString(bytes)))}};var Binary=charenc.Binary={stringToBytes:function(str){for(var bytes=[],i=0;ihasher._blocksize)key=hasher(key,{asBytes:true});var okey=key.slice(0),ikey=key.slice(0);for(var i=0;i>>5]|=bytes[i]<<24-b%32}return words};var wordsToBytes=function(words){var bytes=[];for(var b=0;b>>5]>>>24-b%32&255)}return bytes};var processBlock=function(H,M,offset){for(var i=0;i<16;i++){var offset_i=offset+i;var M_offset_i=M[offset_i];M[offset_i]=(M_offset_i<<8|M_offset_i>>>24)&16711935|(M_offset_i<<24|M_offset_i>>>8)&4278255360}var al,bl,cl,dl,el;var ar,br,cr,dr,er;ar=al=H[0];br=bl=H[1];cr=cl=H[2];dr=dl=H[3];er=el=H[4];var t;for(var i=0;i<80;i+=1){t=al+M[offset+zl[i]]|0;if(i<16){t+=f1(bl,cl,dl)+hl[0]}else if(i<32){t+=f2(bl,cl,dl)+hl[1]}else if(i<48){t+=f3(bl,cl,dl)+hl[2]}else if(i<64){t+=f4(bl,cl,dl)+hl[3]}else{t+=f5(bl,cl,dl)+hl[4]}t=t|0;t=rotl(t,sl[i]);t=t+el|0;al=el;el=dl;dl=rotl(cl,10);cl=bl;bl=t;t=ar+M[offset+zr[i]]|0;if(i<16){t+=f5(br,cr,dr)+hr[0]}else if(i<32){t+=f4(br,cr,dr)+hr[1]}else if(i<48){t+=f3(br,cr,dr)+hr[2]}else if(i<64){t+=f2(br,cr,dr)+hr[3]}else{t+=f1(br,cr,dr)+hr[4]}t=t|0;t=rotl(t,sr[i]);t=t+er|0;ar=er;er=dr;dr=rotl(cr,10);cr=br;br=t}t=H[1]+cl+dr|0;H[1]=H[2]+dl+er|0;H[2]=H[3]+el+ar|0;H[3]=H[4]+al+br|0;H[4]=H[0]+bl+cr|0;H[0]=t};function f1(x,y,z){return x^y^z}function f2(x,y,z){return x&y|~x&z}function f3(x,y,z){return(x|~y)^z}function f4(x,y,z){return x&z|y&~z}function f5(x,y,z){return x^(y|~z)}function rotl(x,n){return x<>>32-n}module.exports=function(message,options){if(message.constructor===String){message=UTF8.stringToBytes(message)}var H=[1732584193,4023233417,2562383102,271733878,3285377520];var m=bytesToWords(message);var nBitsLeft=message.length*8;var nBitsTotal=message.length*8;m[nBitsLeft>>>5]|=128<<24-nBitsLeft%32;m[(nBitsLeft+64>>>9<<4)+14]=(nBitsTotal<<8|nBitsTotal>>>24)&16711935|(nBitsTotal<<24|nBitsTotal>>>8)&4278255360;for(var i=0;i>>24)&16711935|(H_i<<24|H_i>>>8)&4278255360}var digestbytes=wordsToBytes(H);return options&&options.asBytes?digestbytes:options&&options.asString?Binary.bytesToString(digestbytes):conv.bytesToHex(digestbytes)}},{"../convert":10,"./crypto":11}],14:[function(_dereq_,module,exports){var conv=_dereq_("../convert"),util=_dereq_("../util");var K=[];(function(){function isPrime(n){var sqrtN=Math.sqrt(n);for(var factor=2;factor<=sqrtN;factor++){if(!(n%factor)){return false}}return true}function getFractionalBits(n){return(n-(n|0))*4294967296|0}var n=2;var nPrime=0;while(nPrime<64){if(isPrime(n)){K[nPrime]=getFractionalBits(Math.pow(n,1/3));nPrime++}n++}})();var W=[];var processBlock=function(H,M,offset){var a=H[0];var b=H[1];var c=H[2];var d=H[3];var e=H[4];var f=H[5];var g=H[6];var h=H[7];for(var i=0;i<64;i++){if(i<16){W[i]=M[offset+i]|0}else{var gamma0x=W[i-15];var gamma0=(gamma0x<<25|gamma0x>>>7)^(gamma0x<<14|gamma0x>>>18)^gamma0x>>>3;var gamma1x=W[i-2];var gamma1=(gamma1x<<15|gamma1x>>>17)^(gamma1x<<13|gamma1x>>>19)^gamma1x>>>10;W[i]=gamma0+W[i-7]+gamma1+W[i-16]}var ch=e&f^~e&g;var maj=a&b^a&c^b&c;var sigma0=(a<<30|a>>>2)^(a<<19|a>>>13)^(a<<10|a>>>22);var sigma1=(e<<26|e>>>6)^(e<<21|e>>>11)^(e<<7|e>>>25);var t1=h+sigma1+ch+K[i]+W[i];var t2=sigma0+maj;h=g;g=f;f=e;e=d+t1|0;d=c;c=b;b=a;a=t1+t2|0}H[0]=H[0]+a|0;H[1]=H[1]+b|0;H[2]=H[2]+c|0;H[3]=H[3]+d|0;H[4]=H[4]+e|0;H[5]=H[5]+f|0;H[6]=H[6]+g|0;H[7]=H[7]+h|0};module.exports=function(message,options){var H=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];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>>9<<4)+15]=l;for(var i=0;i>>1|gamma0xl<<31)^(gamma0xh>>>8|gamma0xl<<24)^gamma0xh>>>7;var gamma0l=(gamma0xl>>>1|gamma0xh<<31)^(gamma0xl>>>8|gamma0xh<<24)^(gamma0xl>>>7|gamma0xh<<25);var gamma1x=W[i-2];var gamma1xh=gamma1x[0];var gamma1xl=gamma1x[1];var gamma1h=(gamma1xh>>>19|gamma1xl<<13)^(gamma1xh<<3|gamma1xl>>>29)^gamma1xh>>>6;var gamma1l=(gamma1xl>>>19|gamma1xh<<13)^(gamma1xl<<3|gamma1xh>>>29)^(gamma1xl>>>6|gamma1xh<<26);var Wi7=W[i-7]; -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>>0?1:0);var Wil=Wil+gamma1l;var Wih=Wih+gamma1h+(Wil>>>0>>0?1:0);var Wil=Wil+Wi16l;var Wih=Wih+Wi16h+(Wil>>>0>>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>>0?1:0);var t1l=t1l+chl;var t1h=t1h+chh+(t1l>>>0>>0?1:0);var t1l=t1l+Kil;var t1h=t1h+Kih+(t1l>>>0>>0?1:0);var t1l=t1l+Wil;var t1h=t1h+Wih+(t1l>>>0>>0?1:0);var t2l=sigma0l+majl;var t2h=sigma0h+majh+(t2l>>>0>>0?1:0);hh=gh;hl=gl;gh=fh;gl=fl;fh=eh;fl=el;el=dl+t1l|0;eh=dh+t1h+(el>>>0
>>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>>0?1:0)|0}H0l=H0[1]=H0l+al;H0[0]=H0h+ah+(H0l>>>0>>0?1:0);H1l=H1[1]=H1l+bl;H1[0]=H1h+bh+(H1l>>>0>>0?1:0);H2l=H2[1]=H2l+cl;H2[0]=H2h+ch+(H2l>>>0>>0?1:0);H3l=H3[1]=H3l+dl;H3[0]=H3h+dh+(H3l>>>0
>>0?1:0);H4l=H4[1]=H4l+el;H4[0]=H4h+eh+(H4l>>>0>>0?1:0);H5l=H5[1]=H5l+fl;H5[0]=H5h+fh+(H5l>>>0>>0?1:0);H6l=H6[1]=H6l+gl;H6[0]=H6h+gh+(H6l>>>0>>0?1:0);H7l=H7[1]=H7l+hl;H7[0]=H7h+hh+(H7l>>>0>>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=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 for signature")}var Q;if(pubkey instanceof ECPointFp){Q=pubkey}else if(util.isArray(pubkey)){Q=ECPointFp.decodeFrom(ecparams.getCurve(),pubkey)}else{throw new Error("Invalid format for pubkey value, must be byte array or ECPointFp")}var e=BigInteger.fromByteArrayUnsigned(hash);return ECDSA.verifyRaw(e,r,s,Q)},verifyRaw:function(e,r,s,Q){var n=ecparams.getN();var G=ecparams.getG();if(r.compareTo(BigInteger.ONE)<0||r.compareTo(n)>=0)return false;if(s.compareTo(BigInteger.ONE)<0||s.compareTo(n)>=0)return false;var c=s.modInverse(n);var u1=e.multiply(c).mod(n);var u2=r.multiply(c).mod(n);var point=G.multiply(u1).add(Q.multiply(u2));var v=point.getX().toBigInteger().mod(n);return v.equals(r)},serializeSig:function(r,s){var rBa=r.toByteArraySigned();var sBa=s.toByteArraySigned();var sequence=[];sequence.push(2);sequence.push(rBa.length);sequence=sequence.concat(rBa);sequence.push(2);sequence.push(sBa.length);sequence=sequence.concat(sBa);sequence.unshift(sequence.length);sequence.unshift(48);return sequence},parseSig:function(sig){var cursor;if(sig[0]!=48)throw new Error("Signature not a valid DERSequence");cursor=2;if(sig[cursor]!=2)throw new Error("First element in signature must be a DERInteger");var rBa=sig.slice(cursor+2,cursor+2+sig[cursor+1]);cursor+=2+sig[cursor+1];if(sig[cursor]!=2)throw new Error("Second element in signature must be a DERInteger");var sBa=sig.slice(cursor+2,cursor+2+sig[cursor+1]);cursor+=2+sig[cursor+1];var r=BigInteger.fromByteArrayUnsigned(rBa);var s=BigInteger.fromByteArrayUnsigned(sBa);return{r:r,s:s}},parseSigCompact:function(sig){if(sig.length!==65){throw new Error("Signature has the wrong length")}var i=sig[0]-27;if(i<0||i>7){throw new Error("Invalid signature type")}var n=ecparams.getN();var r=BigInteger.fromByteArrayUnsigned(sig.slice(1,33)).mod(n);var s=BigInteger.fromByteArrayUnsigned(sig.slice(33,65)).mod(n);return{r:r,s:s,i:i}},recoverPubKey:function(r,s,hash,i){i=i&3;var isYEven=i&1;var isSecondKey=i>>1;var n=ecparams.getN();var G=ecparams.getG();var curve=ecparams.getCurve();var p=curve.getQ();var a=curve.getA().toBigInteger();var b=curve.getB().toBigInteger();if(!P_OVER_FOUR){P_OVER_FOUR=p.add(BigInteger.ONE).divide(BigInteger.valueOf(4))}var x=isSecondKey?r.add(n):r;var alpha=x.multiply(x).multiply(x).add(a.multiply(x)).add(b).mod(p);var beta=alpha.modPow(P_OVER_FOUR,p);var xorOdd=beta.isEven()?i%2:(i+1)%2;var y=(beta.isEven()?!isYEven:isYEven)?beta:p.subtract(beta);var R=new ECPointFp(curve,curve.fromBigInteger(x),curve.fromBigInteger(y));R.validate();var e=BigInteger.fromByteArrayUnsigned(hash);var eNeg=BigInteger.ZERO.subtract(e).mod(n);var rInv=r.modInverse(n);var Q=implShamirsTrick(R,s,G,eNeg).multiply(rInv);Q.validate();if(!ECDSA.verifyRaw(e,r,s,Q)){throw new Error("Pubkey recovery unsuccessful")}var ECPubKey=_dereq_("./eckey").ECPubKey;return ECPubKey(Q)},calcPubkeyRecoveryParam:function(origPubkey,r,s,hash){var address=origPubkey.getBitcoinAddress().toString();for(var i=0;i<4;i++){var pubkey=ECDSA.recoverPubKey(r,s,hash,i);pubkey.compressed=origPubkey.compressed;if(pubkey.getBitcoinAddress().toString()==address){return i}}throw new Error("Unable to find valid recovery factor")}};module.exports=ECDSA},{"./convert":10,"./crypto-js/crypto.js":11,"./eckey":17,"./jsbn/ec":20,"./jsbn/jsbn":21,"./jsbn/rng":23,"./jsbn/sec":24,"./util":29}],17:[function(_dereq_,module,exports){var BigInteger=_dereq_("./jsbn/jsbn");var sec=_dereq_("./jsbn/sec");var base58=_dereq_("./base58");var Crypto=_dereq_("./crypto-js/crypto");var util=_dereq_("./util");var conv=_dereq_("./convert");var Address=_dereq_("./address");var ecdsa=_dereq_("./ecdsa");var ECPointFp=_dereq_("./jsbn/ec").ECPointFp;var ecparams=sec("secp256k1");var ECKey=function(input,compressed){if(!(this instanceof ECKey)){return new ECKey(input,compressed)}if(!input){var n=ecparams.getN();this.priv=ecdsa.getBigRandom(n);this.compressed=compressed||false}else this.import(input,compressed)};ECKey.prototype.import=function(input,compressed){function has(li,v){return li.indexOf(v)>=0}function fromBin(x){return BigInteger.fromByteArrayUnsigned(x)}this.priv=input instanceof ECKey?input.priv:input instanceof BigInteger?input.mod(ecparams.getN()):util.isArray(input)?fromBin(input.slice(0,32)):typeof input!="string"?null:input.length==44?fromBin(conv.base64ToBytes(input)):input.length==51&&input[0]=="5"?fromBin(base58.checkDecode(input)):input.length==52&&has("LK",input[0])?fromBin(base58.checkDecode(input).slice(0,32)):has([64,65],input.length)?fromBin(conv.hexToBytes(input.slice(0,64))):null;this.compressed=compressed!==undefined?compressed:input instanceof ECKey?input.compressed:input instanceof BigInteger?false:util.isArray(input)?false:typeof input!="string"?null:input.length==44?false:input.length==51&&input[0]=="5"?false:input.length==52&&has("LK",input[0])?true:input.length==64?false:input.length==65?true:null};ECKey.prototype.getPub=function(compressed){if(compressed===undefined)compressed=this.compressed;return ECPubKey(ecparams.getG().multiply(this.priv),compressed)};ECKey.prototype["export"]=function(format){format||(format="hex");return this["to"+format.substr(0,1).toUpperCase()+format.substr(1)]()};ECKey.prototype.toBin=function(){return conv.bytesToString(this.toBytes())};ECKey.prototype.toBase58=function(){return base58.checkEncode(this.toBytes(),128)};ECKey.prototype.toWif=ECKey.prototype.toBase58;ECKey.prototype.toHex=function(){return conv.bytesToHex(this.toBytes())};ECKey.prototype.toBytes=function(){var bytes=this.priv.toByteArrayUnsigned();if(this.compressed)bytes.push(1);return bytes};ECKey.prototype.toString=ECKey.prototype.toBase58;ECKey.prototype.getBitcoinAddress=function(v){return this.getPub().getBitcoinAddress(v)};ECKey.prototype.add=function(key){return ECKey(this.priv.add(ECKey(key).priv),this.compressed)};ECKey.prototype.multiply=function(key){return ECKey(this.priv.multiply(ECKey(key).priv),this.compressed)};var ECPubKey=function(input,compressed){if(!(this instanceof ECPubKey)){return new ECPubKey(input,compressed)}if(!input){var n=ecparams.getN();this.pub=ecparams.getG().multiply(ecdsa.getBigRandom(n));this.compressed=compressed||false}else this.import(input,compressed)};ECPubKey.prototype.import=function(input,compressed){var decode=function(x){return ECPointFp.decodeFrom(ecparams.getCurve(),x)};this.pub=input instanceof ECPointFp?input:input instanceof ECKey?ecparams.getG().multiply(input.priv):input instanceof ECPubKey?input.pub:typeof input=="string"?decode(conv.hexToBytes(input)):util.isArray(input)?decode(input):ecparams.getG().multiply(ecdsa.getBigRandom(ecparams.getN()));this.compressed=arguments.length>1?compressed:input instanceof ECPointFp?input.compressed:input instanceof ECPubKey?input.compressed:this.pub[0]<4};ECPubKey.prototype.add=function(key){return ECPubKey(this.pub.add(ECPubKey(key).pub),this.compressed)};ECPubKey.prototype.multiply=function(key){return ECPubKey(this.pub.multiply(ECKey(key).priv),this.compressed)};ECPubKey.prototype["export"]=function(format){format||(format="hex");return this["to"+format.substr(0,1).toUpperCase()+format.substr(1)]()};ECPubKey.prototype.toBytes=function(compressed){if(compressed===undefined)compressed=this.compressed;return this.pub.getEncoded(compressed)};ECPubKey.prototype.toHex=function(){return conv.bytesToHex(this.toBytes())};ECPubKey.prototype.toBin=function(){return conv.bytesToString(this.toBytes())};ECPubKey.prototype.toBase58=function(){return base58.checkEncode(this.toBytes(),128)};ECPubKey.prototype.toWif=ECPubKey.prototype.toBase58;ECPubKey.prototype.toString=function(){return this.getBitcoinAddress().toString()};ECPubKey.prototype.getBitcoinAddress=function(v){return new Address(util.sha256ripe160(this.toBytes()),v)};ECKey.prototype.sign=function(hash){return ecdsa.sign(hash,this.priv)};ECKey.prototype.verify=function(hash,sig){return ecdsa.verify(hash,sig,this.getPub()["export"]("bytes"))};module.exports={ECKey:ECKey,ECPubKey:ECPubKey}},{"./address":8,"./base58":9,"./convert":10,"./crypto-js/crypto":11,"./ecdsa":16,"./jsbn/ec":20,"./jsbn/jsbn":21,"./jsbn/sec":24,"./util":29}],18:[function(_dereq_,module,exports){var convert=_dereq_("./convert.js"),base58=_dereq_("./base58.js"),assert=_dereq_("assert"),format=_dereq_("util").format,util=_dereq_("./util.js"),Crypto=_dereq_("./crypto-js/crypto.js"),ECKey=_dereq_("./eckey.js").ECKey,ECPubKey=_dereq_("./eckey.js").ECPubKey,Address=_dereq_("./address.js");var HDWallet=module.exports=function(seed,network){if(seed===undefined)return;var I=Crypto.HMAC(Crypto.SHA512,seed,"Bitcoin seed",{asBytes:true});this.chaincode=I.slice(32);this.priv=new ECKey(I.slice(0,32).concat([1]),true);this.pub=this.priv.getPub();this.network=network||"Bitcoin";this.index=0;this.depth=0};HDWallet.HIGHEST_BIT=2147483648;HDWallet.LENGTH=78;HDWallet.VERSIONS={Bitcoin:[76067358,76066276],BitcoinTest:[70617039,70615956]};function arrayEqual(a,b){return!(ab)}HDWallet.getChecksum=function(buffer){assert.equal(buffer.length,HDWallet.LENGTH);return Crypto.SHA256(Crypto.SHA256(buffer,{asBytes:true}),{asBytes:true}).slice(0,4)};HDWallet.fromMasterHex=function(hex){var bytes=convert.hexToBytes(hex);return new HDWallet(convert.bytesToString(bytes))};HDWallet.fromBase58=function(input){var buffer=base58.decode(input);if(buffer.length==HDWallet.LENGTH+4){var expectedChecksum=buffer.slice(HDWallet.LENGTH,HDWallet.LENGTH+4);buffer=buffer.slice(0,HDWallet.LENGTH);var actualChecksum=HDWallet.getChecksum(buffer);if(!arrayEqual(expectedChecksum,actualChecksum)){throw new Error("Checksum mismatch")}}return HDWallet.fromBytes(buffer)};HDWallet.fromHex=function(input){return HDWallet.fromBytes(convert.hexToBytes(input))};HDWallet.fromBytes=function(input){if(input.length!=HDWallet.LENGTH){throw new Error(format("Invalid input length, %s. Expected %s.",input.length,HDWallet.LENGTH))}var hd=new HDWallet;var versionBytes=input.slice(0,4),versionWord=util.bytesToWords(versionBytes)[0],type;Object.keys(HDWallet.VERSIONS).forEach(function(name){HDWallet.VERSIONS[name].forEach(function(word,i){if(versionWord!=word)return;type=i?"private":"public";hd.network=name})});if(!hd.network){throw new Error(format("Could not find version %s",convert.bytesToHex(versionBytes)))}hd.depth=input[4];hd.parentFingerprint=input.slice(5,9);assert(hd.depth===0==arrayEqual(hd.parentFingerprint,[0,0,0,0]));hd.index=util.bytesToNum(input.slice(9,13).reverse());assert(hd.depth>0||hd.index===0);hd.chaincode=input.slice(13,45);if(type=="private"){hd.priv=new ECKey(input.slice(46,78).concat([1]),true);hd.pub=hd.priv.getPub()}else{hd.pub=new ECPubKey(input.slice(45,78),true)}return hd};HDWallet.prototype.getIdentifier=function(){return util.sha256ripe160(this.pub.toBytes())};HDWallet.prototype.getFingerprint=function(){return this.getIdentifier().slice(0,4)};HDWallet.prototype.getBitcoinAddress=function(){var test=this.network.match(/Test$/);return new Address(util.sha256ripe160(this.pub.toBytes()),test?111:0)};HDWallet.prototype.toBytes=function(priv){var buffer=[];var vBytes=util.wordsToBytes([HDWallet.VERSIONS[this.network][priv?1:0]]);buffer=buffer.concat(vBytes);assert.equal(buffer.length,4);buffer.push(this.depth);assert.equal(buffer.length,4+1);buffer=buffer.concat(this.depth?this.parentFingerprint:[0,0,0,0]);assert.equal(buffer.length,4+1+4);buffer=buffer.concat(util.numToBytes(this.index,4).reverse());assert.equal(buffer.length,4+1+4+4);buffer=buffer.concat(this.chaincode);assert.equal(buffer.length,4+1+4+4+32);if(priv){assert(this.priv,"Cannot serialize to private without private key");buffer.push(0);buffer=buffer.concat(this.priv.toBytes().slice(0,32))}else{buffer=buffer.concat(this.pub.toBytes(true))}return buffer};HDWallet.prototype.toHex=function(priv){var bytes=this.toBytes(priv);return convert.bytesToHex(bytes)};HDWallet.prototype.toBase58=function(priv){var buffer=this.toBytes(priv),checksum=HDWallet.getChecksum(buffer);buffer=buffer.concat(checksum);return base58.encode(buffer)};HDWallet.prototype.derive=function(i){var I,iBytes=util.numToBytes(i,4).reverse(),cPar=this.chaincode,usePriv=i>=HDWallet.HIGHEST_BIT;if(usePriv){assert(this.priv,"Private derive on public key");var kPar=this.priv.toBytes().slice(0,32);I=Crypto.HMAC(Crypto.SHA512,[0].concat(kPar,iBytes),cPar,{asBytes:true})}else{var KPar=this.pub.toBytes(true);I=Crypto.HMAC(Crypto.SHA512,KPar.concat(iBytes),cPar,{asBytes:true})}var IL=I.slice(0,32),IR=I.slice(32);var hd=new HDWallet;hd.network=this.network;if(this.priv){hd.priv=this.priv.add(new ECKey(IL.concat([1])));hd.priv.compressed=true;hd.pub=hd.priv.getPub()}else{hd.pub=this.pub.add(new ECKey(IL.concat([1])).getPub())}hd.chaincode=IR;hd.parentFingerprint=this.getFingerprint();hd.depth=this.depth+1;hd.index=i;hd.pub.compressed=true;return hd};HDWallet.prototype.derivePrivate=function(index){return this.derive(index+HDWallet.HIGHEST_BIT)};HDWallet.prototype.toString=HDWallet.prototype.toBase58},{"./address.js":8,"./base58.js":9,"./convert.js":10,"./crypto-js/crypto.js":11,"./eckey.js":17,"./util.js":29,assert:1,util:7}],19:[function(_dereq_,module,exports){var rotl=function(n,b){return n<>>32-b};var rotr=function(n,b){return n<<32-b|n>>>b};var endian=function(n){if(n.constructor==Number){return rotl(n,8)&16711935|rotl(n,24)&4278255360}for(var i=0;i0;--i){R=R.twice();var hBit=h.testBit(i);var eBit=e.testBit(i);if(hBit!=eBit){R=R.add(hBit?this:neg)}}return R}function pointFpMultiplyTwo(j,x,k){var i;if(j.bitLength()>k.bitLength())i=j.bitLength()-1;else i=k.bitLength()-1;var R=this.curve.getInfinity();var both=this.add(x);while(i>=0){R=R.twice();if(j.testBit(i)){if(k.testBit(i)){R=R.add(both)}else{R=R.add(this)}}else{if(k.testBit(i)){R=R.add(x)}}--i}return R}ECPointFp.prototype.getX=pointFpGetX;ECPointFp.prototype.getY=pointFpGetY;ECPointFp.prototype.equals=pointFpEquals;ECPointFp.prototype.isInfinity=pointFpIsInfinity;ECPointFp.prototype.negate=pointFpNegate;ECPointFp.prototype.add=pointFpAdd;ECPointFp.prototype.twice=pointFpTwice;ECPointFp.prototype.multiply=pointFpMultiply;ECPointFp.prototype.multiplyTwo=pointFpMultiplyTwo;function ECCurveFp(q,a,b){this.q=q;this.a=this.fromBigInteger(a);this.b=this.fromBigInteger(b);this.infinity=new ECPointFp(this,null,null)}function curveFpGetQ(){return this.q}function curveFpGetA(){return this.a}function curveFpGetB(){return this.b}function curveFpEquals(other){if(other==this)return true;return this.q.equals(other.q)&&this.a.equals(other.a)&&this.b.equals(other.b)}function curveFpGetInfinity(){return this.infinity}function curveFpFromBigInteger(x){return new ECFieldElementFp(this.q,x)}function curveFpDecodePointHex(s){switch(parseInt(s.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:return null;case 4:case 6:case 7:var len=(s.length-2)/2;var xHex=s.substr(2,len);var yHex=s.substr(len+2,len);return new ECPointFp(this,this.fromBigInteger(new BigInteger(xHex,16)),this.fromBigInteger(new BigInteger(yHex,16)));default:return null}}ECCurveFp.prototype.getQ=curveFpGetQ;ECCurveFp.prototype.getA=curveFpGetA;ECCurveFp.prototype.getB=curveFpGetB;ECCurveFp.prototype.equals=curveFpEquals;ECCurveFp.prototype.getInfinity=curveFpGetInfinity;ECCurveFp.prototype.fromBigInteger=curveFpFromBigInteger;ECCurveFp.prototype.decodePointHex=curveFpDecodePointHex;function integerToBytes(i,len){var bytes=i.toByteArrayUnsigned();if(lenbytes.length){bytes.unshift(0)}return bytes}ECFieldElementFp.prototype.getByteLength=function(){return Math.floor((this.toBigInteger().bitLength()+7)/8)};ECPointFp.prototype.getEncoded=function(compressed){var x=this.getX().toBigInteger();var y=this.getY().toBigInteger();var enc=integerToBytes(x,32);if(compressed){if(y.isEven()){enc.unshift(2)}else{enc.unshift(3)}}else{enc.unshift(4);enc=enc.concat(integerToBytes(y,32))}return enc};ECPointFp.decodeFrom=function(ecparams,enc){var type=enc[0];var dataLen=enc.length-1;if(type==4){var xBa=enc.slice(1,1+dataLen/2),yBa=enc.slice(1+dataLen/2,1+dataLen),x=BigInteger.fromByteArrayUnsigned(xBa),y=BigInteger.fromByteArrayUnsigned(yBa)}else{var xBa=enc.slice(1),x=BigInteger.fromByteArrayUnsigned(xBa),p=ecparams.getQ(),xCubedPlus7=x.multiply(x).multiply(x).add(new BigInteger("7")).mod(p),pPlus1Over4=p.add(new BigInteger("1")).divide(new BigInteger("4")),y=xCubedPlus7.modPow(pPlus1Over4,p);if(y.mod(new BigInteger("2")).toString()!=""+type%2){y=p.subtract(y)}}return new ECPointFp(ecparams,ecparams.fromBigInteger(x),ecparams.fromBigInteger(y))};ECPointFp.prototype.add2D=function(b){if(this.isInfinity())return b;if(b.isInfinity())return this;if(this.x.equals(b.x)){if(this.y.equals(b.y)){return this.twice()}return this.curve.getInfinity()}var x_x=b.x.subtract(this.x);var y_y=b.y.subtract(this.y);var gamma=y_y.divide(x_x);var x3=gamma.square().subtract(this.x).subtract(b.x);var y3=gamma.multiply(this.x.subtract(x3)).subtract(this.y);return new ECPointFp(this.curve,x3,y3)};ECPointFp.prototype.twice2D=function(){if(this.isInfinity())return this;if(this.y.toBigInteger().signum()==0){return this.curve.getInfinity()}var TWO=this.curve.fromBigInteger(BigInteger.valueOf(2));var THREE=this.curve.fromBigInteger(BigInteger.valueOf(3));var gamma=this.x.square().multiply(THREE).add(this.curve.a).divide(this.y.multiply(TWO));var x3=gamma.square().subtract(this.x.multiply(TWO));var y3=gamma.multiply(this.x.subtract(x3)).subtract(this.y);return new ECPointFp(this.curve,x3,y3)};ECPointFp.prototype.multiply2D=function(k){if(this.isInfinity())return this;if(k.signum()==0)return this.curve.getInfinity();var e=k;var h=e.multiply(new BigInteger("3"));var neg=this.negate();var R=this;var i;for(i=h.bitLength()-2;i>0;--i){R=R.twice();var hBit=h.testBit(i);var eBit=e.testBit(i);if(hBit!=eBit){R=R.add2D(hBit?this:neg)}}return R};ECPointFp.prototype.isOnCurve=function(){var x=this.getX().toBigInteger();var y=this.getY().toBigInteger();var a=this.curve.getA().toBigInteger();var b=this.curve.getB().toBigInteger();var n=this.curve.getQ();var lhs=y.multiply(y).mod(n);var rhs=x.multiply(x).multiply(x).add(a.multiply(x)).add(b).mod(n);return lhs.equals(rhs)};ECPointFp.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"};ECPointFp.prototype.validate=function(){var n=this.curve.getQ();if(this.isInfinity()){throw new Error("Point is at infinity.")}var x=this.getX().toBigInteger();var y=this.getY().toBigInteger();if(x.compareTo(BigInteger.ONE)<0||x.compareTo(n.subtract(BigInteger.ONE))>0){throw new Error("x coordinate out of bounds")}if(y.compareTo(BigInteger.ONE)<0||y.compareTo(n.subtract(BigInteger.ONE))>0){throw new Error("y coordinate out of bounds")}if(!this.isOnCurve()){throw new Error("Point is not on the curve.")}if(this.multiply(n).isInfinity()){throw new Error("Point is not a scalar multiple of G.")}return true};module.exports=ECCurveFp;module.exports.ECPointFp=ECPointFp},{"./jsbn":21,"./sec":24}],21:[function(_dereq_,module,exports){var dbits;var canary=0xdeadbeefcafe;var j_lm=(canary&16777215)==15715070;function BigInteger(a,b,c){if(!(this instanceof BigInteger)){return new BigInteger(a,b,c)}if(a!=null){if("number"==typeof a)this.fromNumber(a,b,c);else if(b==null&&"string"!=typeof a)this.fromString(a,256);else this.fromString(a,b)}}var proto=BigInteger.prototype;function nbi(){return new BigInteger(null)}function am1(i,x,w,j,c,n){while(--n>=0){var v=x*this[i++]+w[j]+c;c=Math.floor(v/67108864);w[j++]=v&67108863}return c}function am2(i,x,w,j,c,n){var xl=x&32767,xh=x>>15;while(--n>=0){var l=this[i]&32767;var h=this[i++]>>15;var m=xh*l+h*xl;l=xl*l+((m&32767)<<15)+w[j]+(c&1073741823);c=(l>>>30)+(m>>>15)+xh*h+(c>>>30);w[j++]=l&1073741823}return c}function am3(i,x,w,j,c,n){var xl=x&16383,xh=x>>14;while(--n>=0){var l=this[i]&16383;var h=this[i++]>>14;var m=xh*l+h*xl;l=xl*l+((m&16383)<<14)+w[j]+c;c=(l>>28)+(m>>14)+xh*h;w[j++]=l&268435455}return c}BigInteger.prototype.am=am1;dbits=26;BigInteger.prototype.DB=dbits;BigInteger.prototype.DM=(1<=0;--i)r[i]=this[i];r.t=this.t;r.s=this.s}function bnpFromInt(x){this.t=1;this.s=x<0?-1:0;if(x>0)this[0]=x;else if(x<-1)this[0]=x+DV;else this.t=0}function nbv(i){var r=nbi();r.fromInt(i);return r}function bnpFromString(s,b){var self=this;var k;if(b==16)k=4;else if(b==8)k=3;else if(b==256)k=8;else if(b==2)k=1;else if(b==32)k=5;else if(b==4)k=2;else{self.fromRadix(s,b);return}self.t=0;self.s=0;var i=s.length,mi=false,sh=0;while(--i>=0){var x=k==8?s[i]&255:intAt(s,i);if(x<0){if(s.charAt(i)=="-")mi=true;continue}mi=false;if(sh==0)self[self.t++]=x;else if(sh+k>self.DB){self[self.t-1]|=(x&(1<>self.DB-sh}else self[self.t-1]|=x<=self.DB)sh-=self.DB}if(k==8&&(s[0]&128)!=0){self.s=-1;if(sh>0)self[self.t-1]|=(1<0&&this[this.t-1]==c)--this.t}function bnToString(b){var self=this;if(self.s<0)return"-"+self.negate().toString(b);var k;if(b==16)k=4;else if(b==8)k=3;else if(b==2)k=1;else if(b==32)k=5;else if(b==4)k=2;else return self.toRadix(b);var km=(1<0){if(p>p)>0){m=true;r=int2char(d)}while(i>=0){if(p>(p+=self.DB-k)}else{d=self[i]>>(p-=k)&km;if(p<=0){p+=self.DB;--i}}if(d>0)m=true;if(m)r+=int2char(d)}}return m?r:"0"}function bnNegate(){var r=nbi();BigInteger.ZERO.subTo(this,r);return r}function bnAbs(){return this.s<0?this.negate():this}function bnCompareTo(a){var r=this.s-a.s;if(r!=0)return r;var i=this.t;r=i-a.t;if(r!=0)return this.s<0?-r:r;while(--i>=0)if((r=this[i]-a[i])!=0)return r;return 0}function nbits(x){var r=1,t;if((t=x>>>16)!=0){x=t;r+=16}if((t=x>>8)!=0){x=t;r+=8}if((t=x>>4)!=0){x=t;r+=4 -}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=0;--i){r[i+ds+1]=self[i]>>cbs|c;c=(self[i]&bm)<=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;for(var i=ds+1;i>bs}if(bs>0)r[self.t-ds-1]|=(self.s&bm)<>=self.DB}if(a.t>=self.DB}c+=self.s}else{c+=self.s;while(i>=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=0)r[i]=0;for(i=0;i=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.t0){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<1?y[ys-2]>>self.F2:0);var d1=self.FV/yt,d2=(1<=0){r[r.t++]=1;r.subTo(t,r)}BigInteger.ONE.dlShiftTo(ys,t);t.subTo(y,y);while(y.t=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))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<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>15)*this.mpl&this.um)<<15)&x.DM;j=i+this.m.t;x[j]+=this.m.am(0,u0,x,i,0,this.m.t);while(x[j]>=x.DV){x[j]-=x.DV;x[++j]++}}x.clamp();x.drShiftTo(this.m.t,x);if(x.compareTo(this.m)>=0)x.subTo(this.m,x)}function montSqrTo(x,r){x.squareTo(r);this.reduce(r)}function montMulTo(x,y,r){x.multiplyTo(y,r);this.reduce(r)}Montgomery.prototype.convert=montConvert;Montgomery.prototype.revert=montRevert;Montgomery.prototype.reduce=montReduce;Montgomery.prototype.mulTo=montMulTo;Montgomery.prototype.sqrTo=montSqrTo;function bnpIsEven(){return(this.t>0?this[0]&1:this.s)==0}function bnpExp(e,z){if(e>4294967295||e<1)return BigInteger.ONE;var r=nbi(),r2=nbi(),g=z.convert(this),i=nbits(e)-1;g.copyTo(r);while(--i>=0){z.sqrTo(r,r2);if((e&1<0)z.mulTo(r2,g,r);else{var t=r;r=r2;r2=t}}return z.revert(r)}function bnModPowInt(e,m){var z;if(e<256||m.isEven())z=new Classic(m);else z=new Montgomery(m);return this.exp(e,z)}proto.copyTo=bnpCopyTo;proto.fromInt=bnpFromInt;proto.fromString=bnpFromString;proto.clamp=bnpClamp;proto.dlShiftTo=bnpDLShiftTo;proto.drShiftTo=bnpDRShiftTo;proto.lShiftTo=bnpLShiftTo;proto.rShiftTo=bnpRShiftTo;proto.subTo=bnpSubTo;proto.multiplyTo=bnpMultiplyTo;proto.squareTo=bnpSquareTo;proto.divRemTo=bnpDivRemTo;proto.invDigit=bnpInvDigit;proto.isEven=bnpIsEven;proto.exp=bnpExp;proto.toString=bnToString;proto.negate=bnNegate;proto.abs=bnAbs;proto.compareTo=bnCompareTo;proto.bitLength=bnBitLength;proto.mod=bnMod;proto.modPowInt=bnModPowInt;function nbi(){return new BigInteger(null)}function bnClone(){var r=nbi();this.copyTo(r);return r}function bnIntValue(){if(this.s<0){if(this.t==1)return this[0]-this.DV;else if(this.t==0)return-1}else if(this.t==1)return this[0];else if(this.t==0)return 0;return(this[1]&(1<<32-this.DB)-1)<>24}function bnShortValue(){return this.t==0?this.s:this[0]<<16>>16}function bnpChunkSize(r){return Math.floor(Math.LN2*this.DB/Math.log(r))}function bnSigNum(){if(this.s<0)return-1;else if(this.t<=0||this.t==1&&this[0]<=0)return 0;else return 1}function bnpToRadix(b){if(b==null)b=10;if(this.signum()==0||b<2||b>36)return"0";var cs=this.chunkSize(b);var a=Math.pow(b,cs);var d=nbv(a),y=nbi(),z=nbi(),r="";this.divRemTo(d,y,z);while(y.signum()>0){r=(a+z.intValue()).toString(b).substr(1)+r;y.divRemTo(d,y,z)}return z.intValue().toString(b)+r}function bnpFromRadix(s,b){var self=this;self.fromInt(0);if(b==null)b=10;var cs=self.chunkSize(b);var d=Math.pow(b,cs),mi=false,j=0,w=0;for(var i=0;i=cs){self.dMultiply(d);self.dAddOffset(w,0);j=0;w=0}}if(j>0){self.dMultiply(Math.pow(b,j));self.dAddOffset(w,0)}if(mi)BigInteger.ZERO.subTo(self,self)}function bnpFromNumber(a,b,c){var self=this;if("number"==typeof b){if(a<2)self.fromInt(1);else{self.fromNumber(a,c);if(!self.testBit(a-1))self.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,self);if(self.isEven())self.dAddOffset(1,0);while(!self.isProbablePrime(b)){self.dAddOffset(2,0);if(self.bitLength()>a)self.subTo(BigInteger.ONE.shiftLeft(a-1),self)}}}else{var x=new Array,t=a&7;x.length=(a>>3)+1;b.nextBytes(x);if(t>0)x[0]&=(1<0){if(p>p)!=(self.s&self.DM)>>p)r[k++]=d|self.s<=0){if(p<8){d=(self[i]&(1<>(p+=self.DB-8)}else{d=self[i]>>(p-=8)&255;if(p<=0){p+=self.DB;--i}}if((d&128)!=0)d|=-256;if(k===0&&(self.s&128)!=(d&128))++k;if(k>0||d!=self.s)r[k++]=d}}return r}function bnEquals(a){return this.compareTo(a)==0}function bnMin(a){return this.compareTo(a)<0?this:a}function bnMax(a){return this.compareTo(a)>0?this:a}function bnpBitwiseTo(a,op,r){var self=this;var i,f,m=Math.min(a.t,self.t);for(i=0;i>=16;r+=16}if((x&255)==0){x>>=8;r+=8}if((x&15)==0){x>>=4;r+=4}if((x&3)==0){x>>=2;r+=2}if((x&1)==0)++r;return r}function bnGetLowestSetBit(){for(var i=0;i=this.t)return this.s!=0;return(this[j]&1<>=self.DB}if(a.t>=self.DB}c+=self.s}else{c+=self.s;while(i>=self.DB}c+=a.s}r.s=c<0?-1:0;if(c>0)r[i++]=c;else if(c<-1)r[i++]=self.DV+c;r.t=i;r.clamp()}function bnAdd(a){var r=nbi();this.addTo(a,r);return r}function bnSubtract(a){var r=nbi();this.subTo(a,r);return r}function bnMultiply(a){var r=nbi();this.multiplyTo(a,r);return r}function bnSquare(){var r=nbi();this.squareTo(r);return r}function bnDivide(a){var r=nbi();this.divRemTo(a,r,null);return r}function bnRemainder(a){var r=nbi();this.divRemTo(a,null,r);return r}function bnDivideAndRemainder(a){var q=nbi(),r=nbi();this.divRemTo(a,q,r);return new Array(q,r)}function bnpDMultiply(n){this[this.t]=this.am(0,n-1,this,0,0,this.t);++this.t;this.clamp()}function bnpDAddOffset(n,w){if(n==0)return;while(this.t<=w)this[this.t++]=0;this[w]+=n;while(this[w]>=this.DV){this[w]-=this.DV;if(++w>=this.t)this[this.t++]=0;++this[w]}}function NullExp(){}function nNop(x){return x}function nMulTo(x,y,r){x.multiplyTo(y,r)}function nSqrTo(x,r){x.squareTo(r)}NullExp.prototype.convert=nNop;NullExp.prototype.revert=nNop;NullExp.prototype.mulTo=nMulTo;NullExp.prototype.sqrTo=nSqrTo;function bnPow(e){return this.exp(e,new NullExp)}function bnpMultiplyLowerTo(a,n,r){var i=Math.min(this.t+a.t,n);r.s=0;r.t=i;while(i>0)r[--i]=0;var j;for(j=r.t-this.t;i=0)r[i]=0;for(i=Math.max(n-this.t,0);i2*this.m.t)return x.mod(this.m);else if(x.compareTo(this.m)<0)return x;else{var r=nbi();x.copyTo(r);this.reduce(r);return r}}function barrettRevert(x){return x}function barrettReduce(x){var self=this;x.drShiftTo(self.m.t-1,self.r2);if(x.t>self.m.t+1){x.t=self.m.t+1;x.clamp()}self.mu.multiplyUpperTo(self.r2,self.m.t+1,self.q3);self.m.multiplyLowerTo(self.q3,self.m.t+1,self.r2);while(x.compareTo(self.r2)<0)x.dAddOffset(1,self.m.t+1);x.subTo(self.r2,x);while(x.compareTo(self.m)>=0)x.subTo(self.m,x)}function barrettSqrTo(x,r){x.squareTo(r);this.reduce(r)}function barrettMulTo(x,y,r){x.multiplyTo(y,r);this.reduce(r)}Barrett.prototype.convert=barrettConvert;Barrett.prototype.revert=barrettRevert;Barrett.prototype.reduce=barrettReduce;Barrett.prototype.mulTo=barrettMulTo;Barrett.prototype.sqrTo=barrettSqrTo;function bnModPow(e,m){var i=e.bitLength(),k,r=nbv(1),z;if(i<=0)return r;else if(i<18)k=1;else if(i<48)k=3;else if(i<144)k=4;else if(i<768)k=5;else k=6;if(i<8)z=new Classic(m);else if(m.isEven())z=new Barrett(m);else z=new Montgomery(m);var g=new Array,n=3,k1=k-1,km=(1<1){var g2=nbi();z.sqrTo(g[1],g2);while(n<=km){g[n]=nbi();z.mulTo(g2,g[n-2],g[n]);n+=2}}var j=e.t-1,w,is1=true,r2=nbi(),t;i=nbits(e[j])-1;while(j>=0){if(i>=k1)w=e[j]>>i-k1&km;else{w=(e[j]&(1<0)w|=e[j-1]>>this.DB+i-k1}n=k;while((w&1)==0){w>>=1;--n}if((i-=n)<0){i+=this.DB;--j}if(is1){g[w].copyTo(r);is1=false}else{while(n>1){z.sqrTo(r,r2);z.sqrTo(r2,r);n-=2}if(n>0)z.sqrTo(r,r2);else{t=r;r=r2;r2=t}z.mulTo(r2,g[w],r)}while(j>=0&&(e[j]&1<0){x.rShiftTo(g,x);y.rShiftTo(g,y)}while(x.signum()>0){if((i=x.getLowestSetBit())>0)x.rShiftTo(i,x);if((i=y.getLowestSetBit())>0)y.rShiftTo(i,y);if(x.compareTo(y)>=0){x.subTo(y,x);x.rShiftTo(1,x)}else{y.subTo(x,y);y.rShiftTo(1,y)}}if(g>0)y.lShiftTo(g,y);return y}function bnpModInt(n){if(n<=0)return 0;var d=this.DV%n,r=this.s<0?n-1:0;if(this.t>0)if(d==0)r=this[0]%n;else for(var i=this.t-1;i>=0;--i)r=(d*r+this[i])%n;return r}function bnModInverse(m){var ac=m.isEven();if(this.isEven()&&ac||m.signum()==0)return BigInteger.ZERO;var u=m.clone(),v=this.clone();var a=nbv(1),b=nbv(0),c=nbv(0),d=nbv(1);while(u.signum()!=0){while(u.isEven()){u.rShiftTo(1,u);if(ac){if(!a.isEven()||!b.isEven()){a.addTo(this,a);b.subTo(m,b)}a.rShiftTo(1,a)}else if(!b.isEven())b.subTo(m,b);b.rShiftTo(1,b)}while(v.isEven()){v.rShiftTo(1,v);if(ac){if(!c.isEven()||!d.isEven()){c.addTo(this,c);d.subTo(m,d)}c.rShiftTo(1,c)}else if(!d.isEven())d.subTo(m,d);d.rShiftTo(1,d)}if(u.compareTo(v)>=0){u.subTo(v,u);if(ac)a.subTo(c,a);b.subTo(d,b)}else{v.subTo(u,v);if(ac)c.subTo(a,c);d.subTo(b,d)}}if(v.compareTo(BigInteger.ONE)!=0)return BigInteger.ZERO;if(d.compareTo(m)>=0)return d.subtract(m);if(d.signum()<0)d.addTo(m,d);else return d;if(d.signum()<0)return d.add(m);else return d}proto.chunkSize=bnpChunkSize;proto.toRadix=bnpToRadix;proto.fromRadix=bnpFromRadix;proto.fromNumber=bnpFromNumber;proto.bitwiseTo=bnpBitwiseTo;proto.changeBit=bnpChangeBit;proto.addTo=bnpAddTo;proto.dMultiply=bnpDMultiply;proto.dAddOffset=bnpDAddOffset;proto.multiplyLowerTo=bnpMultiplyLowerTo;proto.multiplyUpperTo=bnpMultiplyUpperTo;proto.modInt=bnpModInt;proto.clone=bnClone;proto.intValue=bnIntValue;proto.byteValue=bnByteValue;proto.shortValue=bnShortValue;proto.signum=bnSigNum;proto.toByteArray=bnToByteArray;proto.equals=bnEquals;proto.min=bnMin;proto.max=bnMax;proto.and=bnAnd;proto.or=bnOr;proto.xor=bnXor;proto.andNot=bnAndNot;proto.not=bnNot;proto.shiftLeft=bnShiftLeft;proto.shiftRight=bnShiftRight;proto.getLowestSetBit=bnGetLowestSetBit;proto.bitCount=bnBitCount;proto.testBit=bnTestBit;proto.setBit=bnSetBit;proto.clearBit=bnClearBit;proto.flipBit=bnFlipBit;proto.add=bnAdd;proto.subtract=bnSubtract;proto.multiply=bnMultiply;proto.divide=bnDivide;proto.remainder=bnRemainder;proto.divideAndRemainder=bnDivideAndRemainder;proto.modPow=bnModPow;proto.modInverse=bnModInverse;proto.pow=bnPow;proto.gcd=bnGCD;proto.square=bnSquare;BigInteger.ZERO=nbv(0);BigInteger.ONE=nbv(1);BigInteger.valueOf=nbv;BigInteger.fromByteArrayUnsigned=function(ba){if(!ba.length){return new BigInteger.valueOf(0)}else if(ba[0]&128){return new BigInteger([0].concat(ba))}else{return new BigInteger(ba)}};BigInteger.fromByteArraySigned=function(ba){if(ba[0]&128){ba[0]&=127;return BigInteger.fromByteArrayUnsigned(ba).negate()}else{return BigInteger.fromByteArrayUnsigned(ba)}};BigInteger.prototype.toByteArrayUnsigned=function(){var ba=this.abs().toByteArray();if(!ba.length){return ba}if(ba[0]===0){ba=ba.slice(1)}for(var i=0;i>8&255;rng_pool[rng_pptr++]^=x>>16&255;rng_pool[rng_pptr++]^=x>>24&255;if(rng_pptr>=rng_psize)rng_pptr-=rng_psize}function rng_seed_time(){rng_seed_int((new Date).getTime())}if(rng_pool==null){rng_pool=new Array;rng_pptr=0;var t;while(rng_pptr>>8;rng_pool[rng_pptr++]=t&255}rng_pptr=0;rng_seed_time()}function rng_get_byte(){if(rng_state==null){rng_seed_time();rng_state=prng_newstate();rng_state.init(rng_pool);for(rng_pptr=0;rng_pptr=240){opcode=opcode<<8|this.buffer[i++]}var len;if(opcode>0&&opcode>>8&255)}else{this.buffer.push(Opcode.map.OP_PUSHDATA4);this.buffer.push(data.length&255);this.buffer.push(data.length>>>8&255);this.buffer.push(data.length>>>16&255);this.buffer.push(data.length>>>24&255)}this.buffer=this.buffer.concat(data);this.chunks.push(data)};Script.createOutputScript=function(address){var script=new Script;address=new Address(address);if(!address.version){script.writeOp(Opcode.map.OP_DUP);script.writeOp(Opcode.map.OP_HASH160);script.writeBytes(address.hash);script.writeOp(Opcode.map.OP_EQUALVERIFY);script.writeOp(Opcode.map.OP_CHECKSIG)}else{script.writeOp(Opcode.map.OP_HASH160);script.writeBytes(address.hash);script.writeOp(Opcode.map.OP_EQUAL)}return script};Script.prototype.extractPubkeys=function(){return this.chunks.filter(function(chunk){return chunk[0]==4&&chunk.length==65||chunk[0]<4&&chunk.length==33})};Script.createMultiSigOutputScript=function(m,pubkeys){var script=new Script;pubkeys=pubkeys.sort();script.writeOp(Opcode.map.OP_1+m-1);for(var i=0;i65){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=0;i--){var txout=this.outs[i];var hash=txout.script.simpleOutPubKeyHash();if(!wallet.hasHash(hash)){allToMe=false}else{firstMeRecvHash=hash}firstRecvHash=hash}for(var i=this.ins.length-1;i>=0;i--){var txin=this.ins[i];firstSendHash=txin.script.simpleInPubKeyHash();if(!wallet.hasHash(firstSendHash)){allFromMe=false;break}}var impact=this.calcImpact(wallet);var analysis={};analysis.impact=impact;if(impact.sign>0&&impact.value>0){analysis.type="recv";analysis.addr=new Address(firstMeRecvHash)}else if(allFromMe&&allToMe){analysis.type="self"}else if(allFromMe){analysis.type="sent";analysis.addr=new Address(firstRecvHash)}else{analysis.type="other"}return analysis};Transaction.prototype.getDescription=function(wallet){var analysis=this.analyze(wallet);if(!analysis)return"";switch(analysis.type){case"recv":return"Received with "+analysis.addr;break;case"sent":return"Payment to "+analysis.addr;break;case"self":return"Payment to yourself";break;case"other":default:return""}};Transaction.prototype.getTotalOutValue=function(){return this.outs.reduce(function(t,o){return t+o.value},0)};Transaction.prototype.getTotalValue=Transaction.prototype.getTotalOutValue;Transaction.prototype.calcImpact=function(wallet){if(!(wallet instanceof Wallet))return 0;var valueOut=this.outs.filter(function(o){return wallet.hasHash(conv.bytesToHex(o.script.simpleOutPubKeyHash()))}).reduce(function(t,o){return t+o.value},0);var valueIn=this.ins.filter(function(i){return wallet.hasHash(conv.bytesToHex(i.script.simpleInPubKeyHash()))&&wallet.txIndex[i.outpoint.hash]}).reduce(function(t,i){return t+wallet.txIndex[i.outpoint.hash].outs[i.outpoint.index].value},0);if(valueOut>valueIn){return{sign:1,value:valueOut-valueIn}}else{return{sign:-1,value:valueIn-valueOut}}};Transaction.deserialize=function(buffer){if(typeof buffer=="string"){buffer=conv.hexToBytes(buffer)}var pos=0;var readAsInt=function(bytes){if(bytes==0)return 0;pos++;return buffer[pos-1]+readAsInt(bytes-1)*256};var readVarInt=function(){pos++;if(buffer[pos-1]<253){return buffer[pos-1]}return readAsInt(buffer[pos-1]-251)};var readBytes=function(bytes){pos+=bytes;return buffer.slice(pos-bytes,pos)};var readVarString=function(){var size=readVarInt();return readBytes(size)};var obj={ins:[],outs:[]};obj.version=readAsInt(4);var ins=readVarInt();for(var i=0;i0)this.address=this.script.toAddress();this.value=util.isArray(data.value)?util.bytesToNum(data.value):"string"==typeof data.value?parseInt(data.value):data.value instanceof BigInteger?parseInt(data.value.toString()):data.value};TransactionOut.prototype.clone=function(){var newTxout=new TransactionOut({script:this.script.clone(),value:this.value});return newTxout};module.exports.Transaction=Transaction;module.exports.TransactionIn=TransactionIn;module.exports.TransactionOut=TransactionOut},{"./address":8,"./convert":10,"./crypto-js/crypto":11,"./ecdsa":16,"./eckey":17,"./jsbn/jsbn":21,"./script":27,"./util":29,"./wallet":30}],29:[function(_dereq_,module,exports){var Crypto=_dereq_("./crypto-js/crypto");exports.isArray=Array.isArray||function(o){return Object.prototype.toString.call(o)==="[object Array]"};exports.numToBytes=function(num,bytes){if(bytes===undefined)bytes=8;if(bytes===0)return[];return[num%256].concat(module.exports.numToBytes(Math.floor(num/256),bytes-1))};exports.bytesToNum=function(bytes){if(bytes.length===0)return 0;return bytes[0]+256*module.exports.bytesToNum(bytes.slice(1))};exports.numToVarInt=function(num){if(num<253)return[num];if(num<65536)return[253].concat(exports.numToBytes(num,2));if(num<4294967296)return[254].concat(exports.numToBytes(num,4));return[253].concat(exports.numToBytes(num,8))};exports.bytesToWords=function(bytes){var words=[];for(var i=0,b=0;i>>5]|=bytes[i]<<24-b%32}return words};exports.wordsToBytes=function(words){var bytes=[];for(var b=0;b>>5]>>>24-b%32&255)}return bytes},exports.sha256ripe160=function(data){return Crypto.RIPEMD160(Crypto.SHA256(data,{asBytes:true}),{asBytes:true})};exports.error=function(msg){throw new Error(msg)}},{"./crypto-js/crypto":11}],30:[function(_dereq_,module,exports){var Script=_dereq_("./script");var ECKey=_dereq_("./eckey").ECKey;var conv=_dereq_("./convert");var util=_dereq_("./util");var BigInteger=_dereq_("./jsbn/jsbn");var Transaction=_dereq_("./transaction").Transaction;var TransactionIn=_dereq_("./transaction").TransactionIn;var TransactionOut=_dereq_("./transaction").TransactionOut;var HDWallet=_dereq_("./hdwallet.js");var SecureRandom=_dereq_("./jsbn/rng");var rng=new SecureRandom;var Wallet=function(seed){if(!(this instanceof Wallet)){return new Wallet(seed)}var keys=[];var masterkey=null;var me=this;this.addresses=[];this.outputs={};this.newMasterKey=function(seed){if(!seed){var seedBytes=new Array(32);rng.nextBytes(seedBytes);seed=conv.bytesToString(seedBytes)}masterkey=new HDWallet(seed);keys=[]};this.newMasterKey(seed);this.generateAddress=function(){keys.push(masterkey.ckd(keys.length).key);this.addresses.push(keys[keys.length-1].getBitcoinAddress().toString());return this.addresses[this.addresses.length-1]};this.processTx=function(tx,verified){var txhash=conv.bytesToHex(tx.getHash());for(var i=0;i=0){me.outputs[txhash+":"+i]={output:txhash+":"+i,value:tx.outs[i].value,address:tx.outs[i].address.toString(),timestamp:(new Date).getTime()/1e3,pending:true}}}for(var i=0;io.timestamp+1200)delete this.outputs[o];if(o.spendpending&&t>o.timestamp+1200){o.spendpending=false;o.spend=false;delete o.timestamp}}};var peoInterval=setInterval(this.processExistingOutputs,1e4);this.getUtxoToPay=function(value){var h=[];for(var out in this.outputs)h.push(this.outputs[out]);var utxo=h.filter(function(x){return!x.spend});var valuecompare=function(a,b){return a.value>b.value};var high=utxo.filter(function(o){return o.value>=value}).sort(valuecompare);if(high.length>0)return[high[0]];utxo.sort(valuecompare);var totalval=0;for(var i=0;i=value)return utxo.slice(0,i+1)}throw"Not enough money to send funds including transaction fee. Have: "+totalval/1e8+", needed: "+value/1e8};this.mkSend=function(to,value,fee){var utxo=this.getUtxoToPay(value+fee);var sum=utxo.reduce(function(t,o){return t+o.value},0),remainder=sum-value-fee;if(value<5430)throw new Error("Amount below dust threshold!");var unspentOuts=0;for(var o in this.outputs){if(!this.outputs[o].spend)unspentOuts+=1;if(unspentOuts>=5)return}var change=this.addresses[this.addresses.length-1];var toOut={address:to,value:value},changeOut={address:change,value:remainder};halfChangeOut={address:change,value:Math.floor(remainder/2)};var outs=remainder<5430?[toOut]:remainder<10860?[toOut,changeOut]:unspentOuts==5?[toOut,changeOut]:[toOut,halfChangeOut,halfChangeOut];var tx=new Bitcoin.Transaction({ins:utxo.map(function(x){return x.output}),outs:outs});this.sign(tx);return tx};this.mkSendToOutputs=function(outputs,changeIndex,fee){var value=outputs.reduce(function(t,o){return t+o.value},0),utxo=this.getUtxoToPay(value+fee),sum=utxo.reduce(function(t,p){return t+o.value},0);utxo[changeIndex].value+=sum-value-fee;var tx=new Bitcoin.Transaction({ins:utxo.map(function(x){return x.output}),outs:outputs});this.sign(tx);return tx};this.sign=function(tx){tx.ins.map(function(inp,i){var inp=inp.outpoint.hash+":"+inp.outpoint.index;if(me.outputs[inp]){var address=me.outputs[inp].address,ind=me.addresses.indexOf(address);if(ind>=0){var key=keys[ind];tx.sign(ind,key)}}});return tx};this.getMasterKey=function(){return masterkey};this.getPrivateKey=function(index){if(typeof index=="string")return keys.filter(function(i,k){return addresses[i]==index})[0];else return keys[index]};this.getPrivateKeys=function(){return keys}};module.exports=Wallet},{"./convert":10,"./eckey":17,"./hdwallet.js":18,"./jsbn/jsbn":21,"./jsbn/rng":23,"./script":27,"./transaction":28,"./util":29}]},{},[19])(19)}); \ No newline at end of file +!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=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=0;i--){if(ka[i]!=kb[i])return false}for(i=ka.length-1;i>=0;i--){key=ka[i];if(!_deepEqual(a[key],b[key]))return false}return true}assert.notDeepEqual=function notDeepEqual(actual,expected,message){if(_deepEqual(actual,expected)){fail(actual,expected,message,"notDeepEqual",assert.notDeepEqual)}};assert.strictEqual=function strictEqual(actual,expected,message){if(actual!==expected){fail(actual,expected,message,"===",assert.strictEqual)}};assert.notStrictEqual=function notStrictEqual(actual,expected,message){if(actual===expected){fail(actual,expected,message,"!==",assert.notStrictEqual)}};function expectedException(actual,expected){if(!actual||!expected){return false}if(Object.prototype.toString.call(expected)=="[object RegExp]"){return expected.test(actual)}else if(actual instanceof expected){return true}else if(expected.call({},actual)===true){return true}return false}function _throws(shouldThrow,block,expected,message){var actual;if(util.isString(expected)){message=expected;expected=null}try{block()}catch(e){actual=e}message=(expected&&expected.name?" ("+expected.name+").":".")+(message?" "+message:".");if(shouldThrow&&!actual){fail(actual,expected,"Missing expected exception"+message)}if(!shouldThrow&&expectedException(actual,expected)){fail(actual,expected,"Got unwanted exception"+message)}if(shouldThrow&&actual&&expected&&!expectedException(actual,expected)||!shouldThrow&&actual){throw actual}}assert.throws=function(block,error,message){_throws.apply(this,[true].concat(pSlice.call(arguments)))};assert.doesNotThrow=function(block,message){_throws.apply(this,[false].concat(pSlice.call(arguments)))};assert.ifError=function(err){if(err){throw err}};var objectKeys=Object.keys||function(obj){var keys=[];for(var key in obj){if(hasOwn.call(obj,key))keys.push(key)}return keys}},{"util/":3}],2:[function(_dereq_,module,exports){module.exports=function isBuffer(arg){return arg&&typeof arg==="object"&&typeof arg.copy==="function"&&typeof arg.fill==="function"&&typeof arg.readUInt8==="function"}},{}],3:[function(_dereq_,module,exports){(function(process,global){var formatRegExp=/%[sdj%]/g;exports.format=function(f){if(!isString(f)){var objects=[];for(var i=0;i=len)return x;switch(x){case"%s":return String(args[i++]);case"%d":return Number(args[i++]);case"%j":try{return JSON.stringify(args[i++])}catch(_){return"[Circular]"}default:return x}});for(var x=args[i];i=3)ctx.depth=arguments[2];if(arguments.length>=4)ctx.colors=arguments[3];if(isBoolean(opts)){ctx.showHidden=opts}else if(opts){exports._extend(ctx,opts)}if(isUndefined(ctx.showHidden))ctx.showHidden=false;if(isUndefined(ctx.depth))ctx.depth=2;if(isUndefined(ctx.colors))ctx.colors=false;if(isUndefined(ctx.customInspect))ctx.customInspect=true;if(ctx.colors)ctx.stylize=stylizeWithColor;return formatValue(ctx,obj,ctx.depth)}exports.inspect=inspect;inspect.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]};inspect.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"};function stylizeWithColor(str,styleType){var style=inspect.styles[styleType];if(style){return"["+inspect.colors[style][0]+"m"+str+"["+inspect.colors[style][1]+"m"}else{return str}}function stylizeNoColor(str,styleType){return str}function arrayToHash(array){var hash={};array.forEach(function(val,idx){hash[val]=true});return hash}function formatValue(ctx,value,recurseTimes){if(ctx.customInspect&&value&&isFunction(value.inspect)&&value.inspect!==exports.inspect&&!(value.constructor&&value.constructor.prototype===value)){var ret=value.inspect(recurseTimes,ctx);if(!isString(ret)){ret=formatValue(ctx,ret,recurseTimes)}return ret}var primitive=formatPrimitive(ctx,value);if(primitive){return primitive}var keys=Object.keys(value);var visibleKeys=arrayToHash(keys);if(ctx.showHidden){keys=Object.getOwnPropertyNames(value)}if(isError(value)&&(keys.indexOf("message")>=0||keys.indexOf("description")>=0)){return formatError(value)}if(keys.length===0){if(isFunction(value)){var name=value.name?": "+value.name:"";return ctx.stylize("[Function"+name+"]","special")}if(isRegExp(value)){return ctx.stylize(RegExp.prototype.toString.call(value),"regexp")}if(isDate(value)){return ctx.stylize(Date.prototype.toString.call(value),"date")}if(isError(value)){return formatError(value)}}var base="",array=false,braces=["{","}"];if(isArray(value)){array=true;braces=["[","]"]}if(isFunction(value)){var n=value.name?": "+value.name:"";base=" [Function"+n+"]"}if(isRegExp(value)){base=" "+RegExp.prototype.toString.call(value)}if(isDate(value)){base=" "+Date.prototype.toUTCString.call(value)}if(isError(value)){base=" "+formatError(value)}if(keys.length===0&&(!array||value.length==0)){return braces[0]+base+braces[1]}if(recurseTimes<0){if(isRegExp(value)){return ctx.stylize(RegExp.prototype.toString.call(value),"regexp")}else{return ctx.stylize("[Object]","special")}}ctx.seen.push(value);var output;if(array){output=formatArray(ctx,value,recurseTimes,visibleKeys,keys)}else{output=keys.map(function(key){return formatProperty(ctx,value,recurseTimes,visibleKeys,key,array)})}ctx.seen.pop();return reduceToSingleString(output,base,braces)}function formatPrimitive(ctx,value){if(isUndefined(value))return ctx.stylize("undefined","undefined");if(isString(value)){var simple="'"+JSON.stringify(value).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return ctx.stylize(simple,"string")}if(isNumber(value))return ctx.stylize(""+value,"number");if(isBoolean(value))return ctx.stylize(""+value,"boolean");if(isNull(value))return ctx.stylize("null","null")}function formatError(value){return"["+Error.prototype.toString.call(value)+"]"}function formatArray(ctx,value,recurseTimes,visibleKeys,keys){var output=[];for(var i=0,l=value.length;i-1){if(array){str=str.split("\n").map(function(line){return" "+line}).join("\n").substr(2)}else{str="\n"+str.split("\n").map(function(line){return" "+line}).join("\n")}}}else{str=ctx.stylize("[Circular]","special")}}if(isUndefined(name)){if(array&&key.match(/^\d+$/)){return str}name=JSON.stringify(""+key);if(name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)){name=name.substr(1,name.length-2);name=ctx.stylize(name,"name")}else{name=name.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'");name=ctx.stylize(name,"string")}}return name+": "+str}function reduceToSingleString(output,base,braces){var numLinesEst=0;var length=output.reduce(function(prev,cur){numLinesEst++;if(cur.indexOf("\n")>=0)numLinesEst++;return prev+cur.replace(/\u001b\[\d\d?m/g,"").length+1},0);if(length>60){return braces[0]+(base===""?"":base+"\n ")+" "+output.join(",\n ")+" "+braces[1]}return braces[0]+base+" "+output.join(", ")+" "+braces[1]}function isArray(ar){return Array.isArray(ar)}exports.isArray=isArray;function isBoolean(arg){return typeof arg==="boolean"}exports.isBoolean=isBoolean;function isNull(arg){return arg===null}exports.isNull=isNull;function isNullOrUndefined(arg){return arg==null}exports.isNullOrUndefined=isNullOrUndefined;function isNumber(arg){return typeof arg==="number"}exports.isNumber=isNumber;function isString(arg){return typeof arg==="string"}exports.isString=isString;function isSymbol(arg){return typeof arg==="symbol"}exports.isSymbol=isSymbol;function isUndefined(arg){return arg===void 0}exports.isUndefined=isUndefined;function isRegExp(re){return isObject(re)&&objectToString(re)==="[object RegExp]"}exports.isRegExp=isRegExp;function isObject(arg){return typeof arg==="object"&&arg!==null}exports.isObject=isObject;function isDate(d){return isObject(d)&&objectToString(d)==="[object Date]"}exports.isDate=isDate;function isError(e){return isObject(e)&&(objectToString(e)==="[object Error]"||e instanceof Error)}exports.isError=isError;function isFunction(arg){return typeof arg==="function"}exports.isFunction=isFunction;function isPrimitive(arg){return arg===null||typeof arg==="boolean"||typeof arg==="number"||typeof arg==="string"||typeof arg==="symbol"||typeof arg==="undefined"}exports.isPrimitive=isPrimitive;exports.isBuffer=_dereq_("./support/isBuffer");function objectToString(o){return Object.prototype.toString.call(o)}function pad(n){return n<10?"0"+n.toString(10):n.toString(10)}var months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function timestamp(){var d=new Date;var time=[pad(d.getHours()),pad(d.getMinutes()),pad(d.getSeconds())].join(":");return[d.getDate(),months[d.getMonth()],time].join(" ")}exports.log=function(){console.log("%s - %s",timestamp(),exports.format.apply(exports,arguments))};exports.inherits=_dereq_("inherits");exports._extend=function(origin,add){if(!add||!isObject(add))return origin;var keys=Object.keys(add);var i=keys.length;while(i--){origin[keys[i]]=add[keys[i]]}return origin};function hasOwnProperty(obj,prop){return Object.prototype.hasOwnProperty.call(obj,prop)}}).call(this,_dereq_("/home/michael/Development/bitcoinjs-lib/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"),typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./support/isBuffer":2,"/home/michael/Development/bitcoinjs-lib/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":5,inherits:4}],4:[function(_dereq_,module,exports){if(typeof Object.create==="function"){module.exports=function inherits(ctor,superCtor){ctor.super_=superCtor;ctor.prototype=Object.create(superCtor.prototype,{constructor:{value:ctor,enumerable:false,writable:true,configurable:true}})}}else{module.exports=function inherits(ctor,superCtor){ctor.super_=superCtor;var TempCtor=function(){};TempCtor.prototype=superCtor.prototype;ctor.prototype=new TempCtor;ctor.prototype.constructor=ctor}}},{}],5:[function(_dereq_,module,exports){var process=module.exports={};process.nextTick=function(){var canSetImmediate=typeof window!=="undefined"&&window.setImmediate;var canPost=typeof window!=="undefined"&&window.postMessage&&window.addEventListener;if(canSetImmediate){return function(f){return window.setImmediate(f)}}if(canPost){var queue=[];window.addEventListener("message",function(ev){var source=ev.source;if((source===window||source===null)&&ev.data==="process-tick"){ev.stopPropagation();if(queue.length>0){var fn=queue.shift();fn()}}},true);return function nextTick(fn){queue.push(fn);window.postMessage("process-tick","*")}}return function nextTick(fn){setTimeout(fn,0)}}();process.title="browser";process.browser=true;process.env={};process.argv=[];process.binding=function(name){throw new Error("process.binding is not supported")};process.cwd=function(){return"/"};process.chdir=function(dir){throw new Error("process.chdir is not supported")}},{}],6:[function(_dereq_,module,exports){module.exports=_dereq_(2)},{}],7:[function(_dereq_,module,exports){module.exports=_dereq_(3)},{"./support/isBuffer":6,"/home/michael/Development/bitcoinjs-lib/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":5,inherits:4}],8:[function(_dereq_,module,exports){var base58=_dereq_("./base58");var Crypto=_dereq_("./crypto-js/crypto");var conv=_dereq_("./convert");var util=_dereq_("./util");var Address=function(bytes,version){if(!(this instanceof Address)){return new Address(bytes,version)}if(arguments[0]instanceof Address){this.hash=arguments[0].hash;this.version=arguments[0].version}else if(typeof bytes==="string"){this.hash=bytes.length<=34?base58.checkDecode(bytes):bytes.length<=40?conv.hexToBytes(bytes):util.error("Bad input");this.version=version||this.hash.version||Address.address_types.prod}else{this.hash=bytes;this.version=version||bytes.version||Address.address_types.prod}};Address.prototype.toString=function(){return base58.checkEncode(this.hash.slice(0),this.version)};Address.prototype.getHash=function(){return conv.bytesToHex(this.hash)};Address.getVersion=function(string){return base58.decode(string)[0]};Address.validate=function(string){try{base58.checkDecode(string);return true}catch(e){return false}};Address.decodeString=function(string){return base58.checkDecode(string)};Address.address_types={prod:0,testnet:111};Address.p2sh_types={prod:5,testnet:196};module.exports=Address},{"./base58":9,"./convert":10,"./crypto-js/crypto":11,"./util":29}],9:[function(_dereq_,module,exports){var BigInteger=_dereq_("./jsbn/jsbn");var Crypto=_dereq_("./crypto-js/crypto");var conv=_dereq_("./convert");var alphabet="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var base=BigInteger.valueOf(58);var positions={};for(var i=0;i=0){var mod=bi.mod(base);chars.push(alphabet[mod.intValue()]);bi=bi.subtract(mod).divide(base)}chars.push(alphabet[bi.intValue()]);for(var i=0;i0){bytes.unshift(0)}return bytes};module.exports.decodeHex=function(input){return module.exports.decode(conv.hexToBytes(input))};module.exports.checkEncode=function(input,vbyte){vbyte=vbyte||0;var front=[vbyte].concat(input);var checksum=Crypto.SHA256(Crypto.SHA256(front,{asBytes:true}),{asBytes:true}).slice(0,4);return module.exports.encode(front.concat(checksum))};module.exports.checkEncodeHex=function(input,vbyte){return conv.bytesToHex(module.exports.encode(input))};module.exports.checkDecode=function(input){var bytes=module.exports.decode(input),front=bytes.slice(0,bytes.length-4),back=bytes.slice(bytes.length-4);var checksum=Crypto.SHA256(Crypto.SHA256(front,{asBytes:true}),{asBytes:true}).slice(0,4);if(""+checksum!=""+back){throw new Error("Checksum failed")}var o=front.slice(1);o.version=front[0];return o};module.exports.checkDecodeHex=function(input){return module.exports.checkDecode(conv.hexToBytes(input))}},{"./convert":10,"./crypto-js/crypto":11,"./jsbn/jsbn":21}],10:[function(_dereq_,module,exports){var base64map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";String.prototype.lpad=function(padString,length){var str=this;while(str.length>>6*(3-j)&63));else base64.push("=")}}return base64.join("")};module.exports.base64ToBytes=function(base64){base64=base64.replace(/[^A-Z0-9+\/]/gi,"");for(var bytes=[],i=0,imod4=0;i>>6-imod4*2)}return bytes};module.exports.coerceToBytes=function(input){if(typeof input=="string")return module.exports.hexToBytes(input);return input};module.exports.binToBytes=function(bin){return bin.match(/......../g).map(function(x){return parseInt(x,2)})};module.exports.bytesToBin=function(bytes){return bytes.map(function(x){return x.toString(2).lpad("0",8)}).join("")};module.exports.bytesToString=function(bytes){return bytes.map(function(x){return String.fromCharCode(x)}).join("")};module.exports.stringToBytes=function(string){return string.split("").map(function(x){return x.charCodeAt(0)})}},{}],11:[function(_dereq_,module,exports){var Crypto=module.exports={};var util=Crypto.util={randomBytes:function(n){for(var bytes=[];n>0;n--)bytes.push(Math.floor(Math.random()*256));return bytes}};Crypto.mode={};var charenc=Crypto.charenc={};var UTF8=charenc.UTF8={stringToBytes:function(str){return Binary.stringToBytes(unescape(encodeURIComponent(str)))},bytesToString:function(bytes){return decodeURIComponent(escape(Binary.bytesToString(bytes)))}};var Binary=charenc.Binary={stringToBytes:function(str){for(var bytes=[],i=0;ihasher._blocksize)key=hasher(key,{asBytes:true});var okey=key.slice(0),ikey=key.slice(0);for(var i=0;i>>5]|=bytes[i]<<24-b%32}return words};var wordsToBytes=function(words){var bytes=[];for(var b=0;b>>5]>>>24-b%32&255)}return bytes};var processBlock=function(H,M,offset){for(var i=0;i<16;i++){var offset_i=offset+i;var M_offset_i=M[offset_i];M[offset_i]=(M_offset_i<<8|M_offset_i>>>24)&16711935|(M_offset_i<<24|M_offset_i>>>8)&4278255360}var al,bl,cl,dl,el;var ar,br,cr,dr,er;ar=al=H[0];br=bl=H[1];cr=cl=H[2];dr=dl=H[3];er=el=H[4];var t;for(var i=0;i<80;i+=1){t=al+M[offset+zl[i]]|0;if(i<16){t+=f1(bl,cl,dl)+hl[0]}else if(i<32){t+=f2(bl,cl,dl)+hl[1]}else if(i<48){t+=f3(bl,cl,dl)+hl[2]}else if(i<64){t+=f4(bl,cl,dl)+hl[3]}else{t+=f5(bl,cl,dl)+hl[4]}t=t|0;t=rotl(t,sl[i]);t=t+el|0;al=el;el=dl;dl=rotl(cl,10);cl=bl;bl=t;t=ar+M[offset+zr[i]]|0;if(i<16){t+=f5(br,cr,dr)+hr[0]}else if(i<32){t+=f4(br,cr,dr)+hr[1]}else if(i<48){t+=f3(br,cr,dr)+hr[2]}else if(i<64){t+=f2(br,cr,dr)+hr[3]}else{t+=f1(br,cr,dr)+hr[4]}t=t|0;t=rotl(t,sr[i]);t=t+er|0;ar=er;er=dr;dr=rotl(cr,10);cr=br;br=t}t=H[1]+cl+dr|0;H[1]=H[2]+dl+er|0;H[2]=H[3]+el+ar|0;H[3]=H[4]+al+br|0;H[4]=H[0]+bl+cr|0;H[0]=t};function f1(x,y,z){return x^y^z}function f2(x,y,z){return x&y|~x&z}function f3(x,y,z){return(x|~y)^z}function f4(x,y,z){return x&z|y&~z}function f5(x,y,z){return x^(y|~z)}function rotl(x,n){return x<>>32-n}module.exports=function(message,options){if(message.constructor===String){message=UTF8.stringToBytes(message)}var H=[1732584193,4023233417,2562383102,271733878,3285377520];var m=bytesToWords(message);var nBitsLeft=message.length*8;var nBitsTotal=message.length*8;m[nBitsLeft>>>5]|=128<<24-nBitsLeft%32;m[(nBitsLeft+64>>>9<<4)+14]=(nBitsTotal<<8|nBitsTotal>>>24)&16711935|(nBitsTotal<<24|nBitsTotal>>>8)&4278255360;for(var i=0;i>>24)&16711935|(H_i<<24|H_i>>>8)&4278255360}var digestbytes=wordsToBytes(H);return options&&options.asBytes?digestbytes:options&&options.asString?Binary.bytesToString(digestbytes):conv.bytesToHex(digestbytes)}},{"../convert":10,"./crypto":11}],14:[function(_dereq_,module,exports){var conv=_dereq_("../convert"),util=_dereq_("../util");var K=[];(function(){function isPrime(n){var sqrtN=Math.sqrt(n);for(var factor=2;factor<=sqrtN;factor++){if(!(n%factor)){return false}}return true}function getFractionalBits(n){return(n-(n|0))*4294967296|0}var n=2;var nPrime=0;while(nPrime<64){if(isPrime(n)){K[nPrime]=getFractionalBits(Math.pow(n,1/3));nPrime++}n++}})();var W=[];var processBlock=function(H,M,offset){var a=H[0];var b=H[1];var c=H[2];var d=H[3];var e=H[4];var f=H[5];var g=H[6];var h=H[7];for(var i=0;i<64;i++){if(i<16){W[i]=M[offset+i]|0}else{var gamma0x=W[i-15];var gamma0=(gamma0x<<25|gamma0x>>>7)^(gamma0x<<14|gamma0x>>>18)^gamma0x>>>3;var gamma1x=W[i-2];var gamma1=(gamma1x<<15|gamma1x>>>17)^(gamma1x<<13|gamma1x>>>19)^gamma1x>>>10;W[i]=gamma0+W[i-7]+gamma1+W[i-16]}var ch=e&f^~e&g;var maj=a&b^a&c^b&c;var sigma0=(a<<30|a>>>2)^(a<<19|a>>>13)^(a<<10|a>>>22);var sigma1=(e<<26|e>>>6)^(e<<21|e>>>11)^(e<<7|e>>>25);var t1=h+sigma1+ch+K[i]+W[i];var t2=sigma0+maj;h=g;g=f;f=e;e=d+t1|0;d=c;c=b;b=a;a=t1+t2|0}H[0]=H[0]+a|0;H[1]=H[1]+b|0;H[2]=H[2]+c|0;H[3]=H[3]+d|0;H[4]=H[4]+e|0;H[5]=H[5]+f|0;H[6]=H[6]+g|0;H[7]=H[7]+h|0};module.exports=function(message,options){var H=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];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>>9<<4)+15]=l;for(var i=0;i>>1|gamma0xl<<31)^(gamma0xh>>>8|gamma0xl<<24)^gamma0xh>>>7;var gamma0l=(gamma0xl>>>1|gamma0xh<<31)^(gamma0xl>>>8|gamma0xh<<24)^(gamma0xl>>>7|gamma0xh<<25);var gamma1x=W[i-2];var gamma1xh=gamma1x[0];var gamma1xl=gamma1x[1];var gamma1h=(gamma1xh>>>19|gamma1xl<<13)^(gamma1xh<<3|gamma1xl>>>29)^gamma1xh>>>6; +var gamma1l=(gamma1xl>>>19|gamma1xh<<13)^(gamma1xl<<3|gamma1xh>>>29)^(gamma1xl>>>6|gamma1xh<<26);var Wi7=W[i-7];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>>0?1:0);var Wil=Wil+gamma1l;var Wih=Wih+gamma1h+(Wil>>>0>>0?1:0);var Wil=Wil+Wi16l;var Wih=Wih+Wi16h+(Wil>>>0>>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>>0?1:0);var t1l=t1l+chl;var t1h=t1h+chh+(t1l>>>0>>0?1:0);var t1l=t1l+Kil;var t1h=t1h+Kih+(t1l>>>0>>0?1:0);var t1l=t1l+Wil;var t1h=t1h+Wih+(t1l>>>0>>0?1:0);var t2l=sigma0l+majl;var t2h=sigma0h+majh+(t2l>>>0>>0?1:0);hh=gh;hl=gl;gh=fh;gl=fl;fh=eh;fl=el;el=dl+t1l|0;eh=dh+t1h+(el>>>0
>>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>>0?1:0)|0}H0l=H0[1]=H0l+al;H0[0]=H0h+ah+(H0l>>>0>>0?1:0);H1l=H1[1]=H1l+bl;H1[0]=H1h+bh+(H1l>>>0>>0?1:0);H2l=H2[1]=H2l+cl;H2[0]=H2h+ch+(H2l>>>0>>0?1:0);H3l=H3[1]=H3l+dl;H3[0]=H3h+dh+(H3l>>>0
>>0?1:0);H4l=H4[1]=H4l+el;H4[0]=H4h+eh+(H4l>>>0>>0?1:0);H5l=H5[1]=H5l+fl;H5[0]=H5h+fh+(H5l>>>0>>0?1:0);H6l=H6[1]=H6l+gl;H6[0]=H6h+gh+(H6l>>>0>>0?1:0);H7l=H7[1]=H7l+hl;H7[0]=H7h+hh+(H7l>>>0>>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=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 for signature")}var Q;if(pubkey instanceof ECPointFp){Q=pubkey}else if(util.isArray(pubkey)){Q=ECPointFp.decodeFrom(ecparams.getCurve(),pubkey)}else{throw new Error("Invalid format for pubkey value, must be byte array or ECPointFp")}var e=BigInteger.fromByteArrayUnsigned(hash);return ECDSA.verifyRaw(e,r,s,Q)},verifyRaw:function(e,r,s,Q){var n=ecparams.getN();var G=ecparams.getG();if(r.compareTo(BigInteger.ONE)<0||r.compareTo(n)>=0)return false;if(s.compareTo(BigInteger.ONE)<0||s.compareTo(n)>=0)return false;var c=s.modInverse(n);var u1=e.multiply(c).mod(n);var u2=r.multiply(c).mod(n);var point=G.multiply(u1).add(Q.multiply(u2));var v=point.getX().toBigInteger().mod(n);return v.equals(r)},serializeSig:function(r,s){var rBa=r.toByteArraySigned();var sBa=s.toByteArraySigned();var sequence=[];sequence.push(2);sequence.push(rBa.length);sequence=sequence.concat(rBa);sequence.push(2);sequence.push(sBa.length);sequence=sequence.concat(sBa);sequence.unshift(sequence.length);sequence.unshift(48);return sequence},parseSig:function(sig){var cursor;if(sig[0]!=48)throw new Error("Signature not a valid DERSequence");cursor=2;if(sig[cursor]!=2)throw new Error("First element in signature must be a DERInteger");var rBa=sig.slice(cursor+2,cursor+2+sig[cursor+1]);cursor+=2+sig[cursor+1];if(sig[cursor]!=2)throw new Error("Second element in signature must be a DERInteger");var sBa=sig.slice(cursor+2,cursor+2+sig[cursor+1]);cursor+=2+sig[cursor+1];var r=BigInteger.fromByteArrayUnsigned(rBa);var s=BigInteger.fromByteArrayUnsigned(sBa);return{r:r,s:s}},parseSigCompact:function(sig){if(sig.length!==65){throw new Error("Signature has the wrong length")}var i=sig[0]-27;if(i<0||i>7){throw new Error("Invalid signature type")}var n=ecparams.getN();var r=BigInteger.fromByteArrayUnsigned(sig.slice(1,33)).mod(n);var s=BigInteger.fromByteArrayUnsigned(sig.slice(33,65)).mod(n);return{r:r,s:s,i:i}},recoverPubKey:function(r,s,hash,i){i=i&3;var isYEven=i&1;var isSecondKey=i>>1;var n=ecparams.getN();var G=ecparams.getG();var curve=ecparams.getCurve();var p=curve.getQ();var a=curve.getA().toBigInteger();var b=curve.getB().toBigInteger();if(!P_OVER_FOUR){P_OVER_FOUR=p.add(BigInteger.ONE).divide(BigInteger.valueOf(4))}var x=isSecondKey?r.add(n):r;var alpha=x.multiply(x).multiply(x).add(a.multiply(x)).add(b).mod(p);var beta=alpha.modPow(P_OVER_FOUR,p);var xorOdd=beta.isEven()?i%2:(i+1)%2;var y=(beta.isEven()?!isYEven:isYEven)?beta:p.subtract(beta);var R=new ECPointFp(curve,curve.fromBigInteger(x),curve.fromBigInteger(y));R.validate();var e=BigInteger.fromByteArrayUnsigned(hash);var eNeg=BigInteger.ZERO.subtract(e).mod(n);var rInv=r.modInverse(n);var Q=implShamirsTrick(R,s,G,eNeg).multiply(rInv);Q.validate();if(!ECDSA.verifyRaw(e,r,s,Q)){throw new Error("Pubkey recovery unsuccessful")}var ECPubKey=_dereq_("./eckey").ECPubKey;return ECPubKey(Q)},calcPubkeyRecoveryParam:function(origPubkey,r,s,hash){var address=origPubkey.getBitcoinAddress().toString();for(var i=0;i<4;i++){var pubkey=ECDSA.recoverPubKey(r,s,hash,i);pubkey.compressed=origPubkey.compressed;if(pubkey.getBitcoinAddress().toString()==address){return i}}throw new Error("Unable to find valid recovery factor")}};module.exports=ECDSA},{"./convert":10,"./crypto-js/crypto.js":11,"./eckey":17,"./jsbn/ec":20,"./jsbn/jsbn":21,"./jsbn/rng":23,"./jsbn/sec":24,"./util":29}],17:[function(_dereq_,module,exports){var BigInteger=_dereq_("./jsbn/jsbn");var sec=_dereq_("./jsbn/sec");var base58=_dereq_("./base58");var Crypto=_dereq_("./crypto-js/crypto");var util=_dereq_("./util");var conv=_dereq_("./convert");var Address=_dereq_("./address");var ecdsa=_dereq_("./ecdsa");var ECPointFp=_dereq_("./jsbn/ec").ECPointFp;var ecparams=sec("secp256k1");var ECKey=function(input,compressed,version){if(!(this instanceof ECKey)){return new ECKey(input,compressed)}if(!input){var n=ecparams.getN();this.priv=ecdsa.getBigRandom(n);this.compressed=compressed||false;this.version=version||Address.address_types.prod}else this.import(input,compressed,version)};ECKey.prototype.import=function(input,compressed,version){function has(li,v){return li.indexOf(v)>=0}function fromBin(x){return BigInteger.fromByteArrayUnsigned(x)}this.priv=input instanceof ECKey?input.priv:input instanceof BigInteger?input.mod(ecparams.getN()):util.isArray(input)?fromBin(input.slice(0,32)):typeof input!="string"?null:input.length==44?fromBin(conv.base64ToBytes(input)):input.length==51&&input[0]=="5"?fromBin(base58.checkDecode(input)):input.length==51&&input[0]=="9"?fromBin(base58.checkDecode(input)):input.length==52&&has("LK",input[0])?fromBin(base58.checkDecode(input).slice(0,32)):input.length==52&&input[0]=="c"?fromBin(base58.checkDecode(input).slice(0,32)):has([64,65],input.length)?fromBin(conv.hexToBytes(input.slice(0,64))):null;this.compressed=compressed!==undefined?compressed:input instanceof ECKey?input.compressed:input instanceof BigInteger?false:util.isArray(input)?false:typeof input!="string"?null:input.length==44?false:input.length==51&&input[0]=="5"?false:input.length==51&&input[0]=="9"?false:input.length==52&&has("LK",input[0])?true:input.length==52&&input[0]=="c"?true:input.length==64?false:input.length==65?true:null;this.version=version!==undefined?version:input instanceof ECKey?input.version:input instanceof BigInteger?Address.address_types.prod:util.isArray(input)?Address.address_types.prod:typeof input!="string"?null:input.length==44?Address.address_types.prod:input.length==51&&input[0]=="5"?Address.address_types.prod:input.length==51&&input[0]=="9"?Address.address_types.testnet:input.length==52&&has("LK",input[0])?Address.address_types.prod:input.length==52&&input[0]=="c"?Address.address_types.testnet:input.length==64?Address.address_types.prod:input.length==65?Address.address_types.prod:null};ECKey.prototype.getPub=function(compressed){if(compressed===undefined)compressed=this.compressed;return ECPubKey(ecparams.getG().multiply(this.priv),compressed,this.version)};ECKey.prototype["export"]=function(format){format||(format="hex");return this["to"+format.substr(0,1).toUpperCase()+format.substr(1)]()};ECKey.prototype.toBin=function(){return conv.bytesToString(this.toBytes())};ECKey.prototype.toBase58=function(){return base58.checkEncode(this.toBytes(),ECKey.version_bytes[this.version])};ECKey.prototype.toWif=ECKey.prototype.toBase58;ECKey.prototype.toHex=function(){return conv.bytesToHex(this.toBytes())};ECKey.prototype.toBytes=function(){var bytes=this.priv.toByteArrayUnsigned();if(this.compressed)bytes.push(1);return bytes};ECKey.prototype.toBase64=function(){return conv.bytesToBase64(this.toBytes())};ECKey.prototype.toString=ECKey.prototype.toBase58;ECKey.prototype.getBitcoinAddress=function(){return this.getPub().getBitcoinAddress(this.version)};ECKey.prototype.add=function(key){return ECKey(this.priv.add(ECKey(key).priv),this.compressed)};ECKey.prototype.multiply=function(key){return ECKey(this.priv.multiply(ECKey(key).priv),this.compressed)};ECKey.version_bytes={0:128,111:239};var ECPubKey=function(input,compressed,version){if(!(this instanceof ECPubKey)){return new ECPubKey(input,compressed,version)}if(!input){var n=ecparams.getN();this.pub=ecparams.getG().multiply(ecdsa.getBigRandom(n));this.compressed=compressed||false;this.version=version||Address.address_types.prod}else this.import(input,compressed,version)};ECPubKey.prototype.import=function(input,compressed,version){var decode=function(x){return ECPointFp.decodeFrom(ecparams.getCurve(),x)};this.pub=input instanceof ECPointFp?input:input instanceof ECKey?ecparams.getG().multiply(input.priv):input instanceof ECPubKey?input.pub:typeof input=="string"?decode(conv.hexToBytes(input)):util.isArray(input)?decode(input):ecparams.getG().multiply(ecdsa.getBigRandom(ecparams.getN()));this.compressed=compressed?compressed:input instanceof ECPointFp?input.compressed:input instanceof ECPubKey?input.compressed:this.pub[0]<4;this.version=version?version:input instanceof ECPointFp?input.version:input instanceof ECPubKey?input.version:Address.address_types.prod};ECPubKey.prototype.add=function(key){return ECPubKey(this.pub.add(ECPubKey(key).pub),this.compressed,this.version)};ECPubKey.prototype.multiply=function(key){return ECPubKey(this.pub.multiply(ECKey(key).priv),this.compressed,this.version)};ECPubKey.prototype["export"]=function(format){format||(format="hex");return this["to"+format.substr(0,1).toUpperCase()+format.substr(1)]()};ECPubKey.prototype.toBytes=function(compressed){if(compressed===undefined)compressed=this.compressed;return this.pub.getEncoded(compressed)};ECPubKey.prototype.toHex=function(){return conv.bytesToHex(this.toBytes())};ECPubKey.prototype.toBin=function(){return conv.bytesToString(this.toBytes())};ECPubKey.prototype.toBase58=function(){return base58.checkEncode(this.toBytes(),this.version)};ECPubKey.prototype.toWif=ECPubKey.prototype.toBase58;ECPubKey.prototype.toString=function(){return this.getBitcoinAddress().toString()};ECPubKey.prototype.getBitcoinAddress=function(){return new Address(util.sha256ripe160(this.toBytes()),this.version)};ECKey.prototype.sign=function(hash){return ecdsa.sign(hash,this.priv)};ECKey.prototype.verify=function(hash,sig){return ecdsa.verify(hash,sig,this.getPub()["export"]("bytes"))};module.exports={ECKey:ECKey,ECPubKey:ECPubKey}},{"./address":8,"./base58":9,"./convert":10,"./crypto-js/crypto":11,"./ecdsa":16,"./jsbn/ec":20,"./jsbn/jsbn":21,"./jsbn/sec":24,"./util":29}],18:[function(_dereq_,module,exports){var convert=_dereq_("./convert.js"),base58=_dereq_("./base58.js"),assert=_dereq_("assert"),format=_dereq_("util").format,util=_dereq_("./util.js"),Crypto=_dereq_("./crypto-js/crypto.js"),ECKey=_dereq_("./eckey.js").ECKey,ECPubKey=_dereq_("./eckey.js").ECPubKey,Address=_dereq_("./address.js");var HDWallet=module.exports=function(seed,network){if(seed===undefined)return;var I=Crypto.HMAC(Crypto.SHA512,seed,"Bitcoin seed",{asBytes:true});this.chaincode=I.slice(32);this.priv=new ECKey(I.slice(0,32).concat([1]),true);this.pub=this.priv.getPub();this.network=network||"Bitcoin";this.index=0;this.depth=0};HDWallet.HIGHEST_BIT=2147483648;HDWallet.LENGTH=78;HDWallet.VERSIONS={Bitcoin:[76067358,76066276],BitcoinTest:[70617039,70615956]};function arrayEqual(a,b){return!(ab)}HDWallet.getChecksum=function(buffer){assert.equal(buffer.length,HDWallet.LENGTH);return Crypto.SHA256(Crypto.SHA256(buffer,{asBytes:true}),{asBytes:true}).slice(0,4)};HDWallet.fromMasterHex=function(hex){var bytes=convert.hexToBytes(hex);return new HDWallet(convert.bytesToString(bytes))};HDWallet.fromBase58=function(input){var buffer=base58.decode(input);if(buffer.length==HDWallet.LENGTH+4){var expectedChecksum=buffer.slice(HDWallet.LENGTH,HDWallet.LENGTH+4);buffer=buffer.slice(0,HDWallet.LENGTH);var actualChecksum=HDWallet.getChecksum(buffer);if(!arrayEqual(expectedChecksum,actualChecksum)){throw new Error("Checksum mismatch")}}return HDWallet.fromBytes(buffer)};HDWallet.fromHex=function(input){return HDWallet.fromBytes(convert.hexToBytes(input))};HDWallet.fromBytes=function(input){if(input.length!=HDWallet.LENGTH){throw new Error(format("Invalid input length, %s. Expected %s.",input.length,HDWallet.LENGTH))}var hd=new HDWallet;var versionBytes=input.slice(0,4),versionWord=util.bytesToWords(versionBytes)[0],type;Object.keys(HDWallet.VERSIONS).forEach(function(name){HDWallet.VERSIONS[name].forEach(function(word,i){if(versionWord!=word)return;type=i?"private":"public";hd.network=name})});if(!hd.network){throw new Error(format("Could not find version %s",convert.bytesToHex(versionBytes)))}hd.depth=input[4];hd.parentFingerprint=input.slice(5,9);assert(hd.depth===0==arrayEqual(hd.parentFingerprint,[0,0,0,0]));hd.index=util.bytesToNum(input.slice(9,13).reverse());assert(hd.depth>0||hd.index===0);hd.chaincode=input.slice(13,45);if(type=="private"){hd.priv=new ECKey(input.slice(46,78).concat([1]),true);hd.pub=hd.priv.getPub()}else{hd.pub=new ECPubKey(input.slice(45,78),true)}return hd};HDWallet.prototype.getIdentifier=function(){return util.sha256ripe160(this.pub.toBytes())};HDWallet.prototype.getFingerprint=function(){return this.getIdentifier().slice(0,4)};HDWallet.prototype.getBitcoinAddress=function(){var test=this.network.match(/Test$/);return new Address(util.sha256ripe160(this.pub.toBytes()),test?111:0)};HDWallet.prototype.toBytes=function(priv){var buffer=[];var vBytes=util.wordsToBytes([HDWallet.VERSIONS[this.network][priv?1:0]]);buffer=buffer.concat(vBytes);assert.equal(buffer.length,4);buffer.push(this.depth);assert.equal(buffer.length,4+1);buffer=buffer.concat(this.depth?this.parentFingerprint:[0,0,0,0]);assert.equal(buffer.length,4+1+4);buffer=buffer.concat(util.numToBytes(this.index,4).reverse());assert.equal(buffer.length,4+1+4+4);buffer=buffer.concat(this.chaincode);assert.equal(buffer.length,4+1+4+4+32);if(priv){assert(this.priv,"Cannot serialize to private without private key");buffer.push(0);buffer=buffer.concat(this.priv.toBytes().slice(0,32))}else{buffer=buffer.concat(this.pub.toBytes(true))}return buffer};HDWallet.prototype.toHex=function(priv){var bytes=this.toBytes(priv);return convert.bytesToHex(bytes)};HDWallet.prototype.toBase58=function(priv){var buffer=this.toBytes(priv),checksum=HDWallet.getChecksum(buffer);buffer=buffer.concat(checksum);return base58.encode(buffer)};HDWallet.prototype.derive=function(i){var I,iBytes=util.numToBytes(i,4).reverse(),cPar=this.chaincode,usePriv=i>=HDWallet.HIGHEST_BIT;if(usePriv){assert(this.priv,"Private derive on public key");var kPar=this.priv.toBytes().slice(0,32);I=Crypto.HMAC(Crypto.SHA512,[0].concat(kPar,iBytes),cPar,{asBytes:true})}else{var KPar=this.pub.toBytes(true);I=Crypto.HMAC(Crypto.SHA512,KPar.concat(iBytes),cPar,{asBytes:true})}var IL=I.slice(0,32),IR=I.slice(32);var hd=new HDWallet;hd.network=this.network;if(this.priv){hd.priv=this.priv.add(new ECKey(IL.concat([1])));hd.priv.compressed=true;hd.pub=hd.priv.getPub()}else{hd.pub=this.pub.add(new ECKey(IL.concat([1])).getPub())}hd.chaincode=IR;hd.parentFingerprint=this.getFingerprint();hd.depth=this.depth+1;hd.index=i;hd.pub.compressed=true;return hd};HDWallet.prototype.derivePrivate=function(index){return this.derive(index+HDWallet.HIGHEST_BIT)};HDWallet.prototype.toString=HDWallet.prototype.toBase58},{"./address.js":8,"./base58.js":9,"./convert.js":10,"./crypto-js/crypto.js":11,"./eckey.js":17,"./util.js":29,assert:1,util:7}],19:[function(_dereq_,module,exports){var rotl=function(n,b){return n<>>32-b};var rotr=function(n,b){return n<<32-b|n>>>b};var endian=function(n){if(n.constructor==Number){return rotl(n,8)&16711935|rotl(n,24)&4278255360}for(var i=0;i0;--i){R=R.twice();var hBit=h.testBit(i);var eBit=e.testBit(i);if(hBit!=eBit){R=R.add(hBit?this:neg)}}return R}function pointFpMultiplyTwo(j,x,k){var i;if(j.bitLength()>k.bitLength())i=j.bitLength()-1;else i=k.bitLength()-1;var R=this.curve.getInfinity();var both=this.add(x);while(i>=0){R=R.twice();if(j.testBit(i)){if(k.testBit(i)){R=R.add(both)}else{R=R.add(this)}}else{if(k.testBit(i)){R=R.add(x)}}--i}return R}ECPointFp.prototype.getX=pointFpGetX;ECPointFp.prototype.getY=pointFpGetY;ECPointFp.prototype.equals=pointFpEquals;ECPointFp.prototype.isInfinity=pointFpIsInfinity;ECPointFp.prototype.negate=pointFpNegate;ECPointFp.prototype.add=pointFpAdd;ECPointFp.prototype.twice=pointFpTwice;ECPointFp.prototype.multiply=pointFpMultiply;ECPointFp.prototype.multiplyTwo=pointFpMultiplyTwo;function ECCurveFp(q,a,b){this.q=q;this.a=this.fromBigInteger(a);this.b=this.fromBigInteger(b);this.infinity=new ECPointFp(this,null,null)}function curveFpGetQ(){return this.q}function curveFpGetA(){return this.a}function curveFpGetB(){return this.b}function curveFpEquals(other){if(other==this)return true;return this.q.equals(other.q)&&this.a.equals(other.a)&&this.b.equals(other.b)}function curveFpGetInfinity(){return this.infinity}function curveFpFromBigInteger(x){return new ECFieldElementFp(this.q,x)}function curveFpDecodePointHex(s){switch(parseInt(s.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:return null;case 4:case 6:case 7:var len=(s.length-2)/2;var xHex=s.substr(2,len);var yHex=s.substr(len+2,len);return new ECPointFp(this,this.fromBigInteger(new BigInteger(xHex,16)),this.fromBigInteger(new BigInteger(yHex,16)));default:return null}}ECCurveFp.prototype.getQ=curveFpGetQ;ECCurveFp.prototype.getA=curveFpGetA;ECCurveFp.prototype.getB=curveFpGetB;ECCurveFp.prototype.equals=curveFpEquals;ECCurveFp.prototype.getInfinity=curveFpGetInfinity;ECCurveFp.prototype.fromBigInteger=curveFpFromBigInteger;ECCurveFp.prototype.decodePointHex=curveFpDecodePointHex;function integerToBytes(i,len){var bytes=i.toByteArrayUnsigned();if(lenbytes.length){bytes.unshift(0)}return bytes}ECFieldElementFp.prototype.getByteLength=function(){return Math.floor((this.toBigInteger().bitLength()+7)/8)};ECPointFp.prototype.getEncoded=function(compressed){var x=this.getX().toBigInteger();var y=this.getY().toBigInteger();var enc=integerToBytes(x,32);if(compressed){if(y.isEven()){enc.unshift(2)}else{enc.unshift(3)}}else{enc.unshift(4);enc=enc.concat(integerToBytes(y,32))}return enc};ECPointFp.decodeFrom=function(ecparams,enc){var type=enc[0];var dataLen=enc.length-1;if(type==4){var xBa=enc.slice(1,1+dataLen/2),yBa=enc.slice(1+dataLen/2,1+dataLen),x=BigInteger.fromByteArrayUnsigned(xBa),y=BigInteger.fromByteArrayUnsigned(yBa)}else{var xBa=enc.slice(1),x=BigInteger.fromByteArrayUnsigned(xBa),p=ecparams.getQ(),xCubedPlus7=x.multiply(x).multiply(x).add(new BigInteger("7")).mod(p),pPlus1Over4=p.add(new BigInteger("1")).divide(new BigInteger("4")),y=xCubedPlus7.modPow(pPlus1Over4,p);if(y.mod(new BigInteger("2")).toString()!=""+type%2){y=p.subtract(y)}}return new ECPointFp(ecparams,ecparams.fromBigInteger(x),ecparams.fromBigInteger(y))};ECPointFp.prototype.add2D=function(b){if(this.isInfinity())return b;if(b.isInfinity())return this;if(this.x.equals(b.x)){if(this.y.equals(b.y)){return this.twice()}return this.curve.getInfinity()}var x_x=b.x.subtract(this.x);var y_y=b.y.subtract(this.y);var gamma=y_y.divide(x_x);var x3=gamma.square().subtract(this.x).subtract(b.x);var y3=gamma.multiply(this.x.subtract(x3)).subtract(this.y);return new ECPointFp(this.curve,x3,y3)};ECPointFp.prototype.twice2D=function(){if(this.isInfinity())return this;if(this.y.toBigInteger().signum()==0){return this.curve.getInfinity()}var TWO=this.curve.fromBigInteger(BigInteger.valueOf(2));var THREE=this.curve.fromBigInteger(BigInteger.valueOf(3));var gamma=this.x.square().multiply(THREE).add(this.curve.a).divide(this.y.multiply(TWO));var x3=gamma.square().subtract(this.x.multiply(TWO));var y3=gamma.multiply(this.x.subtract(x3)).subtract(this.y);return new ECPointFp(this.curve,x3,y3)};ECPointFp.prototype.multiply2D=function(k){if(this.isInfinity())return this;if(k.signum()==0)return this.curve.getInfinity();var e=k;var h=e.multiply(new BigInteger("3"));var neg=this.negate();var R=this;var i;for(i=h.bitLength()-2;i>0;--i){R=R.twice();var hBit=h.testBit(i);var eBit=e.testBit(i);if(hBit!=eBit){R=R.add2D(hBit?this:neg)}}return R};ECPointFp.prototype.isOnCurve=function(){var x=this.getX().toBigInteger();var y=this.getY().toBigInteger();var a=this.curve.getA().toBigInteger();var b=this.curve.getB().toBigInteger();var n=this.curve.getQ();var lhs=y.multiply(y).mod(n);var rhs=x.multiply(x).multiply(x).add(a.multiply(x)).add(b).mod(n);return lhs.equals(rhs)};ECPointFp.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"};ECPointFp.prototype.validate=function(){var n=this.curve.getQ();if(this.isInfinity()){throw new Error("Point is at infinity.")}var x=this.getX().toBigInteger();var y=this.getY().toBigInteger();if(x.compareTo(BigInteger.ONE)<0||x.compareTo(n.subtract(BigInteger.ONE))>0){throw new Error("x coordinate out of bounds")}if(y.compareTo(BigInteger.ONE)<0||y.compareTo(n.subtract(BigInteger.ONE))>0){throw new Error("y coordinate out of bounds")}if(!this.isOnCurve()){throw new Error("Point is not on the curve.")}if(this.multiply(n).isInfinity()){throw new Error("Point is not a scalar multiple of G.")}return true};module.exports=ECCurveFp;module.exports.ECPointFp=ECPointFp},{"./jsbn":21,"./sec":24}],21:[function(_dereq_,module,exports){var dbits;var canary=0xdeadbeefcafe;var j_lm=(canary&16777215)==15715070;function BigInteger(a,b,c){if(!(this instanceof BigInteger)){return new BigInteger(a,b,c)}if(a!=null){if("number"==typeof a)this.fromNumber(a,b,c);else if(b==null&&"string"!=typeof a)this.fromString(a,256);else this.fromString(a,b)}}var proto=BigInteger.prototype;function nbi(){return new BigInteger(null)}function am1(i,x,w,j,c,n){while(--n>=0){var v=x*this[i++]+w[j]+c;c=Math.floor(v/67108864);w[j++]=v&67108863}return c}function am2(i,x,w,j,c,n){var xl=x&32767,xh=x>>15;while(--n>=0){var l=this[i]&32767;var h=this[i++]>>15;var m=xh*l+h*xl;l=xl*l+((m&32767)<<15)+w[j]+(c&1073741823);c=(l>>>30)+(m>>>15)+xh*h+(c>>>30);w[j++]=l&1073741823}return c}function am3(i,x,w,j,c,n){var xl=x&16383,xh=x>>14;while(--n>=0){var l=this[i]&16383;var h=this[i++]>>14;var m=xh*l+h*xl;l=xl*l+((m&16383)<<14)+w[j]+c;c=(l>>28)+(m>>14)+xh*h;w[j++]=l&268435455}return c}BigInteger.prototype.am=am1;dbits=26;BigInteger.prototype.DB=dbits;BigInteger.prototype.DM=(1<=0;--i)r[i]=this[i];r.t=this.t;r.s=this.s}function bnpFromInt(x){this.t=1;this.s=x<0?-1:0;if(x>0)this[0]=x;else if(x<-1)this[0]=x+DV;else this.t=0}function nbv(i){var r=nbi();r.fromInt(i);return r}function bnpFromString(s,b){var self=this;var k;if(b==16)k=4;else if(b==8)k=3;else if(b==256)k=8;else if(b==2)k=1;else if(b==32)k=5;else if(b==4)k=2;else{self.fromRadix(s,b);return}self.t=0;self.s=0; +var i=s.length,mi=false,sh=0;while(--i>=0){var x=k==8?s[i]&255:intAt(s,i);if(x<0){if(s.charAt(i)=="-")mi=true;continue}mi=false;if(sh==0)self[self.t++]=x;else if(sh+k>self.DB){self[self.t-1]|=(x&(1<>self.DB-sh}else self[self.t-1]|=x<=self.DB)sh-=self.DB}if(k==8&&(s[0]&128)!=0){self.s=-1;if(sh>0)self[self.t-1]|=(1<0&&this[this.t-1]==c)--this.t}function bnToString(b){var self=this;if(self.s<0)return"-"+self.negate().toString(b);var k;if(b==16)k=4;else if(b==8)k=3;else if(b==2)k=1;else if(b==32)k=5;else if(b==4)k=2;else return self.toRadix(b);var km=(1<0){if(p>p)>0){m=true;r=int2char(d)}while(i>=0){if(p>(p+=self.DB-k)}else{d=self[i]>>(p-=k)&km;if(p<=0){p+=self.DB;--i}}if(d>0)m=true;if(m)r+=int2char(d)}}return m?r:"0"}function bnNegate(){var r=nbi();BigInteger.ZERO.subTo(this,r);return r}function bnAbs(){return this.s<0?this.negate():this}function bnCompareTo(a){var r=this.s-a.s;if(r!=0)return r;var i=this.t;r=i-a.t;if(r!=0)return this.s<0?-r:r;while(--i>=0)if((r=this[i]-a[i])!=0)return r;return 0}function nbits(x){var r=1,t;if((t=x>>>16)!=0){x=t;r+=16}if((t=x>>8)!=0){x=t;r+=8}if((t=x>>4)!=0){x=t;r+=4}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=0;--i){r[i+ds+1]=self[i]>>cbs|c;c=(self[i]&bm)<=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;for(var i=ds+1;i>bs}if(bs>0)r[self.t-ds-1]|=(self.s&bm)<>=self.DB}if(a.t>=self.DB}c+=self.s}else{c+=self.s;while(i>=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=0)r[i]=0;for(i=0;i=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.t0){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<1?y[ys-2]>>self.F2:0);var d1=self.FV/yt,d2=(1<=0){r[r.t++]=1;r.subTo(t,r)}BigInteger.ONE.dlShiftTo(ys,t);t.subTo(y,y);while(y.t=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))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<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>15)*this.mpl&this.um)<<15)&x.DM;j=i+this.m.t;x[j]+=this.m.am(0,u0,x,i,0,this.m.t);while(x[j]>=x.DV){x[j]-=x.DV;x[++j]++}}x.clamp();x.drShiftTo(this.m.t,x);if(x.compareTo(this.m)>=0)x.subTo(this.m,x)}function montSqrTo(x,r){x.squareTo(r);this.reduce(r)}function montMulTo(x,y,r){x.multiplyTo(y,r);this.reduce(r)}Montgomery.prototype.convert=montConvert;Montgomery.prototype.revert=montRevert;Montgomery.prototype.reduce=montReduce;Montgomery.prototype.mulTo=montMulTo;Montgomery.prototype.sqrTo=montSqrTo;function bnpIsEven(){return(this.t>0?this[0]&1:this.s)==0}function bnpExp(e,z){if(e>4294967295||e<1)return BigInteger.ONE;var r=nbi(),r2=nbi(),g=z.convert(this),i=nbits(e)-1;g.copyTo(r);while(--i>=0){z.sqrTo(r,r2);if((e&1<0)z.mulTo(r2,g,r);else{var t=r;r=r2;r2=t}}return z.revert(r)}function bnModPowInt(e,m){var z;if(e<256||m.isEven())z=new Classic(m);else z=new Montgomery(m);return this.exp(e,z)}proto.copyTo=bnpCopyTo;proto.fromInt=bnpFromInt;proto.fromString=bnpFromString;proto.clamp=bnpClamp;proto.dlShiftTo=bnpDLShiftTo;proto.drShiftTo=bnpDRShiftTo;proto.lShiftTo=bnpLShiftTo;proto.rShiftTo=bnpRShiftTo;proto.subTo=bnpSubTo;proto.multiplyTo=bnpMultiplyTo;proto.squareTo=bnpSquareTo;proto.divRemTo=bnpDivRemTo;proto.invDigit=bnpInvDigit;proto.isEven=bnpIsEven;proto.exp=bnpExp;proto.toString=bnToString;proto.negate=bnNegate;proto.abs=bnAbs;proto.compareTo=bnCompareTo;proto.bitLength=bnBitLength;proto.mod=bnMod;proto.modPowInt=bnModPowInt;function nbi(){return new BigInteger(null)}function bnClone(){var r=nbi();this.copyTo(r);return r}function bnIntValue(){if(this.s<0){if(this.t==1)return this[0]-this.DV;else if(this.t==0)return-1}else if(this.t==1)return this[0];else if(this.t==0)return 0;return(this[1]&(1<<32-this.DB)-1)<>24}function bnShortValue(){return this.t==0?this.s:this[0]<<16>>16}function bnpChunkSize(r){return Math.floor(Math.LN2*this.DB/Math.log(r))}function bnSigNum(){if(this.s<0)return-1;else if(this.t<=0||this.t==1&&this[0]<=0)return 0;else return 1}function bnpToRadix(b){if(b==null)b=10;if(this.signum()==0||b<2||b>36)return"0";var cs=this.chunkSize(b);var a=Math.pow(b,cs);var d=nbv(a),y=nbi(),z=nbi(),r="";this.divRemTo(d,y,z);while(y.signum()>0){r=(a+z.intValue()).toString(b).substr(1)+r;y.divRemTo(d,y,z)}return z.intValue().toString(b)+r}function bnpFromRadix(s,b){var self=this;self.fromInt(0);if(b==null)b=10;var cs=self.chunkSize(b);var d=Math.pow(b,cs),mi=false,j=0,w=0;for(var i=0;i=cs){self.dMultiply(d);self.dAddOffset(w,0);j=0;w=0}}if(j>0){self.dMultiply(Math.pow(b,j));self.dAddOffset(w,0)}if(mi)BigInteger.ZERO.subTo(self,self)}function bnpFromNumber(a,b,c){var self=this;if("number"==typeof b){if(a<2)self.fromInt(1);else{self.fromNumber(a,c);if(!self.testBit(a-1))self.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,self);if(self.isEven())self.dAddOffset(1,0);while(!self.isProbablePrime(b)){self.dAddOffset(2,0);if(self.bitLength()>a)self.subTo(BigInteger.ONE.shiftLeft(a-1),self)}}}else{var x=new Array,t=a&7;x.length=(a>>3)+1;b.nextBytes(x);if(t>0)x[0]&=(1<0){if(p>p)!=(self.s&self.DM)>>p)r[k++]=d|self.s<=0){if(p<8){d=(self[i]&(1<>(p+=self.DB-8)}else{d=self[i]>>(p-=8)&255;if(p<=0){p+=self.DB;--i}}if((d&128)!=0)d|=-256;if(k===0&&(self.s&128)!=(d&128))++k;if(k>0||d!=self.s)r[k++]=d}}return r}function bnEquals(a){return this.compareTo(a)==0}function bnMin(a){return this.compareTo(a)<0?this:a}function bnMax(a){return this.compareTo(a)>0?this:a}function bnpBitwiseTo(a,op,r){var self=this;var i,f,m=Math.min(a.t,self.t);for(i=0;i>=16;r+=16}if((x&255)==0){x>>=8;r+=8}if((x&15)==0){x>>=4;r+=4}if((x&3)==0){x>>=2;r+=2}if((x&1)==0)++r;return r}function bnGetLowestSetBit(){for(var i=0;i=this.t)return this.s!=0;return(this[j]&1<>=self.DB}if(a.t>=self.DB}c+=self.s}else{c+=self.s;while(i>=self.DB}c+=a.s}r.s=c<0?-1:0;if(c>0)r[i++]=c;else if(c<-1)r[i++]=self.DV+c;r.t=i;r.clamp()}function bnAdd(a){var r=nbi();this.addTo(a,r);return r}function bnSubtract(a){var r=nbi();this.subTo(a,r);return r}function bnMultiply(a){var r=nbi();this.multiplyTo(a,r);return r}function bnSquare(){var r=nbi();this.squareTo(r);return r}function bnDivide(a){var r=nbi();this.divRemTo(a,r,null);return r}function bnRemainder(a){var r=nbi();this.divRemTo(a,null,r);return r}function bnDivideAndRemainder(a){var q=nbi(),r=nbi();this.divRemTo(a,q,r);return new Array(q,r)}function bnpDMultiply(n){this[this.t]=this.am(0,n-1,this,0,0,this.t);++this.t;this.clamp()}function bnpDAddOffset(n,w){if(n==0)return;while(this.t<=w)this[this.t++]=0;this[w]+=n;while(this[w]>=this.DV){this[w]-=this.DV;if(++w>=this.t)this[this.t++]=0;++this[w]}}function NullExp(){}function nNop(x){return x}function nMulTo(x,y,r){x.multiplyTo(y,r)}function nSqrTo(x,r){x.squareTo(r)}NullExp.prototype.convert=nNop;NullExp.prototype.revert=nNop;NullExp.prototype.mulTo=nMulTo;NullExp.prototype.sqrTo=nSqrTo;function bnPow(e){return this.exp(e,new NullExp)}function bnpMultiplyLowerTo(a,n,r){var i=Math.min(this.t+a.t,n);r.s=0;r.t=i;while(i>0)r[--i]=0;var j;for(j=r.t-this.t;i=0)r[i]=0;for(i=Math.max(n-this.t,0);i2*this.m.t)return x.mod(this.m);else if(x.compareTo(this.m)<0)return x;else{var r=nbi();x.copyTo(r);this.reduce(r);return r}}function barrettRevert(x){return x}function barrettReduce(x){var self=this;x.drShiftTo(self.m.t-1,self.r2);if(x.t>self.m.t+1){x.t=self.m.t+1;x.clamp()}self.mu.multiplyUpperTo(self.r2,self.m.t+1,self.q3);self.m.multiplyLowerTo(self.q3,self.m.t+1,self.r2);while(x.compareTo(self.r2)<0)x.dAddOffset(1,self.m.t+1);x.subTo(self.r2,x);while(x.compareTo(self.m)>=0)x.subTo(self.m,x)}function barrettSqrTo(x,r){x.squareTo(r);this.reduce(r)}function barrettMulTo(x,y,r){x.multiplyTo(y,r);this.reduce(r)}Barrett.prototype.convert=barrettConvert;Barrett.prototype.revert=barrettRevert;Barrett.prototype.reduce=barrettReduce;Barrett.prototype.mulTo=barrettMulTo;Barrett.prototype.sqrTo=barrettSqrTo;function bnModPow(e,m){var i=e.bitLength(),k,r=nbv(1),z;if(i<=0)return r;else if(i<18)k=1;else if(i<48)k=3;else if(i<144)k=4;else if(i<768)k=5;else k=6;if(i<8)z=new Classic(m);else if(m.isEven())z=new Barrett(m);else z=new Montgomery(m);var g=new Array,n=3,k1=k-1,km=(1<1){var g2=nbi();z.sqrTo(g[1],g2);while(n<=km){g[n]=nbi();z.mulTo(g2,g[n-2],g[n]);n+=2}}var j=e.t-1,w,is1=true,r2=nbi(),t;i=nbits(e[j])-1;while(j>=0){if(i>=k1)w=e[j]>>i-k1&km;else{w=(e[j]&(1<0)w|=e[j-1]>>this.DB+i-k1}n=k;while((w&1)==0){w>>=1;--n}if((i-=n)<0){i+=this.DB;--j}if(is1){g[w].copyTo(r);is1=false}else{while(n>1){z.sqrTo(r,r2);z.sqrTo(r2,r);n-=2}if(n>0)z.sqrTo(r,r2);else{t=r;r=r2;r2=t}z.mulTo(r2,g[w],r)}while(j>=0&&(e[j]&1<0){x.rShiftTo(g,x);y.rShiftTo(g,y)}while(x.signum()>0){if((i=x.getLowestSetBit())>0)x.rShiftTo(i,x);if((i=y.getLowestSetBit())>0)y.rShiftTo(i,y);if(x.compareTo(y)>=0){x.subTo(y,x);x.rShiftTo(1,x)}else{y.subTo(x,y);y.rShiftTo(1,y)}}if(g>0)y.lShiftTo(g,y);return y}function bnpModInt(n){if(n<=0)return 0;var d=this.DV%n,r=this.s<0?n-1:0;if(this.t>0)if(d==0)r=this[0]%n;else for(var i=this.t-1;i>=0;--i)r=(d*r+this[i])%n;return r}function bnModInverse(m){var ac=m.isEven();if(this.isEven()&&ac||m.signum()==0)return BigInteger.ZERO;var u=m.clone(),v=this.clone();var a=nbv(1),b=nbv(0),c=nbv(0),d=nbv(1);while(u.signum()!=0){while(u.isEven()){u.rShiftTo(1,u);if(ac){if(!a.isEven()||!b.isEven()){a.addTo(this,a);b.subTo(m,b)}a.rShiftTo(1,a)}else if(!b.isEven())b.subTo(m,b);b.rShiftTo(1,b)}while(v.isEven()){v.rShiftTo(1,v);if(ac){if(!c.isEven()||!d.isEven()){c.addTo(this,c);d.subTo(m,d)}c.rShiftTo(1,c)}else if(!d.isEven())d.subTo(m,d);d.rShiftTo(1,d)}if(u.compareTo(v)>=0){u.subTo(v,u);if(ac)a.subTo(c,a);b.subTo(d,b)}else{v.subTo(u,v);if(ac)c.subTo(a,c);d.subTo(b,d)}}if(v.compareTo(BigInteger.ONE)!=0)return BigInteger.ZERO;if(d.compareTo(m)>=0)return d.subtract(m);if(d.signum()<0)d.addTo(m,d);else return d;if(d.signum()<0)return d.add(m);else return d}proto.chunkSize=bnpChunkSize;proto.toRadix=bnpToRadix;proto.fromRadix=bnpFromRadix;proto.fromNumber=bnpFromNumber;proto.bitwiseTo=bnpBitwiseTo;proto.changeBit=bnpChangeBit;proto.addTo=bnpAddTo;proto.dMultiply=bnpDMultiply;proto.dAddOffset=bnpDAddOffset;proto.multiplyLowerTo=bnpMultiplyLowerTo;proto.multiplyUpperTo=bnpMultiplyUpperTo;proto.modInt=bnpModInt;proto.clone=bnClone;proto.intValue=bnIntValue;proto.byteValue=bnByteValue;proto.shortValue=bnShortValue;proto.signum=bnSigNum;proto.toByteArray=bnToByteArray;proto.equals=bnEquals;proto.min=bnMin;proto.max=bnMax;proto.and=bnAnd;proto.or=bnOr;proto.xor=bnXor;proto.andNot=bnAndNot;proto.not=bnNot;proto.shiftLeft=bnShiftLeft;proto.shiftRight=bnShiftRight;proto.getLowestSetBit=bnGetLowestSetBit;proto.bitCount=bnBitCount;proto.testBit=bnTestBit;proto.setBit=bnSetBit;proto.clearBit=bnClearBit;proto.flipBit=bnFlipBit;proto.add=bnAdd;proto.subtract=bnSubtract;proto.multiply=bnMultiply;proto.divide=bnDivide;proto.remainder=bnRemainder;proto.divideAndRemainder=bnDivideAndRemainder;proto.modPow=bnModPow;proto.modInverse=bnModInverse;proto.pow=bnPow;proto.gcd=bnGCD;proto.square=bnSquare;BigInteger.ZERO=nbv(0);BigInteger.ONE=nbv(1);BigInteger.valueOf=nbv;BigInteger.fromByteArrayUnsigned=function(ba){if(!ba.length){return new BigInteger.valueOf(0)}else if(ba[0]&128){return new BigInteger([0].concat(ba))}else{return new BigInteger(ba)}};BigInteger.fromByteArraySigned=function(ba){if(ba[0]&128){ba[0]&=127;return BigInteger.fromByteArrayUnsigned(ba).negate()}else{return BigInteger.fromByteArrayUnsigned(ba)}};BigInteger.prototype.toByteArrayUnsigned=function(){var ba=this.abs().toByteArray();if(!ba.length){return ba}if(ba[0]===0){ba=ba.slice(1)}for(var i=0;i>8&255;rng_pool[rng_pptr++]^=x>>16&255;rng_pool[rng_pptr++]^=x>>24&255;if(rng_pptr>=rng_psize)rng_pptr-=rng_psize}function rng_seed_time(){rng_seed_int((new Date).getTime())}if(rng_pool==null){rng_pool=new Array;rng_pptr=0;var t;while(rng_pptr>>8;rng_pool[rng_pptr++]=t&255}rng_pptr=0;rng_seed_time()}function rng_get_byte(){if(rng_state==null){rng_seed_time();rng_state=prng_newstate();rng_state.init(rng_pool);for(rng_pptr=0;rng_pptr=240){opcode=opcode<<8|this.buffer[i++]}var len;if(opcode>0&&opcode>>8&255)}else{this.buffer.push(Opcode.map.OP_PUSHDATA4);this.buffer.push(data.length&255);this.buffer.push(data.length>>>8&255);this.buffer.push(data.length>>>16&255);this.buffer.push(data.length>>>24&255)}this.buffer=this.buffer.concat(data);this.chunks.push(data)};Script.createOutputScript=function(address){var script=new Script;address=new Address(address);if(!address.version){script.writeOp(Opcode.map.OP_DUP);script.writeOp(Opcode.map.OP_HASH160); +script.writeBytes(address.hash);script.writeOp(Opcode.map.OP_EQUALVERIFY);script.writeOp(Opcode.map.OP_CHECKSIG)}else{script.writeOp(Opcode.map.OP_HASH160);script.writeBytes(address.hash);script.writeOp(Opcode.map.OP_EQUAL)}return script};Script.prototype.extractPubkeys=function(){return this.chunks.filter(function(chunk){return chunk[0]==4&&chunk.length==65||chunk[0]<4&&chunk.length==33})};Script.createMultiSigOutputScript=function(m,pubkeys){var script=new Script;pubkeys=pubkeys.sort();script.writeOp(Opcode.map.OP_1+m-1);for(var i=0;i65){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=0;i--){var txout=this.outs[i];var hash=txout.script.simpleOutPubKeyHash();if(!wallet.hasHash(hash)){allToMe=false}else{firstMeRecvHash=hash}firstRecvHash=hash}for(var i=this.ins.length-1;i>=0;i--){var txin=this.ins[i];firstSendHash=txin.script.simpleInPubKeyHash();if(!wallet.hasHash(firstSendHash)){allFromMe=false;break}}var impact=this.calcImpact(wallet);var analysis={};analysis.impact=impact;if(impact.sign>0&&impact.value>0){analysis.type="recv";analysis.addr=new Address(firstMeRecvHash)}else if(allFromMe&&allToMe){analysis.type="self"}else if(allFromMe){analysis.type="sent";analysis.addr=new Address(firstRecvHash)}else{analysis.type="other"}return analysis};Transaction.prototype.getDescription=function(wallet){var analysis=this.analyze(wallet);if(!analysis)return"";switch(analysis.type){case"recv":return"Received with "+analysis.addr;break;case"sent":return"Payment to "+analysis.addr;break;case"self":return"Payment to yourself";break;case"other":default:return""}};Transaction.prototype.getTotalOutValue=function(){return this.outs.reduce(function(t,o){return t+o.value},0)};Transaction.prototype.getTotalValue=Transaction.prototype.getTotalOutValue;Transaction.prototype.calcImpact=function(wallet){if(!(wallet instanceof Wallet))return 0;var valueOut=this.outs.filter(function(o){return wallet.hasHash(conv.bytesToHex(o.script.simpleOutPubKeyHash()))}).reduce(function(t,o){return t+o.value},0);var valueIn=this.ins.filter(function(i){return wallet.hasHash(conv.bytesToHex(i.script.simpleInPubKeyHash()))&&wallet.txIndex[i.outpoint.hash]}).reduce(function(t,i){return t+wallet.txIndex[i.outpoint.hash].outs[i.outpoint.index].value},0);if(valueOut>valueIn){return{sign:1,value:valueOut-valueIn}}else{return{sign:-1,value:valueIn-valueOut}}};Transaction.deserialize=function(buffer){if(typeof buffer=="string"){buffer=conv.hexToBytes(buffer)}var pos=0;var readAsInt=function(bytes){if(bytes==0)return 0;pos++;return buffer[pos-1]+readAsInt(bytes-1)*256};var readVarInt=function(){pos++;if(buffer[pos-1]<253){return buffer[pos-1]}return readAsInt(buffer[pos-1]-251)};var readBytes=function(bytes){pos+=bytes;return buffer.slice(pos-bytes,pos)};var readVarString=function(){var size=readVarInt();return readBytes(size)};var obj={ins:[],outs:[]};obj.version=readAsInt(4);var ins=readVarInt();for(var i=0;i0)this.address=this.script.toAddress();this.value=util.isArray(data.value)?util.bytesToNum(data.value):"string"==typeof data.value?parseInt(data.value):data.value instanceof BigInteger?parseInt(data.value.toString()):data.value};TransactionOut.prototype.clone=function(){var newTxout=new TransactionOut({script:this.script.clone(),value:this.value});return newTxout};module.exports.Transaction=Transaction;module.exports.TransactionIn=TransactionIn;module.exports.TransactionOut=TransactionOut},{"./address":8,"./convert":10,"./crypto-js/crypto":11,"./ecdsa":16,"./eckey":17,"./jsbn/jsbn":21,"./script":27,"./util":29,"./wallet":30}],29:[function(_dereq_,module,exports){var Crypto=_dereq_("./crypto-js/crypto");exports.isArray=Array.isArray||function(o){return Object.prototype.toString.call(o)==="[object Array]"};exports.numToBytes=function(num,bytes){if(bytes===undefined)bytes=8;if(bytes===0)return[];return[num%256].concat(module.exports.numToBytes(Math.floor(num/256),bytes-1))};exports.bytesToNum=function(bytes){if(bytes.length===0)return 0;return bytes[0]+256*module.exports.bytesToNum(bytes.slice(1))};exports.numToVarInt=function(num){if(num<253)return[num];if(num<65536)return[253].concat(exports.numToBytes(num,2));if(num<4294967296)return[254].concat(exports.numToBytes(num,4));return[253].concat(exports.numToBytes(num,8))};exports.bytesToWords=function(bytes){var words=[];for(var i=0,b=0;i>>5]|=bytes[i]<<24-b%32}return words};exports.wordsToBytes=function(words){var bytes=[];for(var b=0;b>>5]>>>24-b%32&255)}return bytes},exports.sha256ripe160=function(data){return Crypto.RIPEMD160(Crypto.SHA256(data,{asBytes:true}),{asBytes:true})};exports.error=function(msg){throw new Error(msg)}},{"./crypto-js/crypto":11}],30:[function(_dereq_,module,exports){var Script=_dereq_("./script");var ECKey=_dereq_("./eckey").ECKey;var conv=_dereq_("./convert");var util=_dereq_("./util");var BigInteger=_dereq_("./jsbn/jsbn");var Transaction=_dereq_("./transaction").Transaction;var TransactionIn=_dereq_("./transaction").TransactionIn;var TransactionOut=_dereq_("./transaction").TransactionOut;var HDWallet=_dereq_("./hdwallet.js");var SecureRandom=_dereq_("./jsbn/rng");var rng=new SecureRandom;var Wallet=function(seed){if(!(this instanceof Wallet)){return new Wallet(seed)}var keys=[];var masterkey=null;var me=this;this.addresses=[];this.outputs={};this.newMasterKey=function(seed){if(!seed){var seedBytes=new Array(32);rng.nextBytes(seedBytes);seed=conv.bytesToString(seedBytes)}masterkey=new HDWallet(seed);keys=[]};this.newMasterKey(seed);this.generateAddress=function(){keys.push(masterkey.ckd(keys.length).key);this.addresses.push(keys[keys.length-1].getBitcoinAddress().toString());return this.addresses[this.addresses.length-1]};this.processTx=function(tx,verified){var txhash=conv.bytesToHex(tx.getHash());for(var i=0;i=0){me.outputs[txhash+":"+i]={output:txhash+":"+i,value:tx.outs[i].value,address:tx.outs[i].address.toString(),timestamp:(new Date).getTime()/1e3,pending:true}}}for(var i=0;io.timestamp+1200)delete this.outputs[o];if(o.spendpending&&t>o.timestamp+1200){o.spendpending=false;o.spend=false;delete o.timestamp}}};var peoInterval=setInterval(this.processExistingOutputs,1e4);this.getUtxoToPay=function(value){var h=[];for(var out in this.outputs)h.push(this.outputs[out]);var utxo=h.filter(function(x){return!x.spend});var valuecompare=function(a,b){return a.value>b.value};var high=utxo.filter(function(o){return o.value>=value}).sort(valuecompare);if(high.length>0)return[high[0]];utxo.sort(valuecompare);var totalval=0;for(var i=0;i=value)return utxo.slice(0,i+1)}throw"Not enough money to send funds including transaction fee. Have: "+totalval/1e8+", needed: "+value/1e8};this.mkSend=function(to,value,fee){var utxo=this.getUtxoToPay(value+fee);var sum=utxo.reduce(function(t,o){return t+o.value},0),remainder=sum-value-fee;if(value<5430)throw new Error("Amount below dust threshold!");var unspentOuts=0;for(var o in this.outputs){if(!this.outputs[o].spend)unspentOuts+=1;if(unspentOuts>=5)return}var change=this.addresses[this.addresses.length-1];var toOut={address:to,value:value},changeOut={address:change,value:remainder};halfChangeOut={address:change,value:Math.floor(remainder/2)};var outs=remainder<5430?[toOut]:remainder<10860?[toOut,changeOut]:unspentOuts==5?[toOut,changeOut]:[toOut,halfChangeOut,halfChangeOut];var tx=new Bitcoin.Transaction({ins:utxo.map(function(x){return x.output}),outs:outs});this.sign(tx);return tx};this.mkSendToOutputs=function(outputs,changeIndex,fee){var value=outputs.reduce(function(t,o){return t+o.value},0),utxo=this.getUtxoToPay(value+fee),sum=utxo.reduce(function(t,p){return t+o.value},0);utxo[changeIndex].value+=sum-value-fee;var tx=new Bitcoin.Transaction({ins:utxo.map(function(x){return x.output}),outs:outputs});this.sign(tx);return tx};this.sign=function(tx){tx.ins.map(function(inp,i){var inp=inp.outpoint.hash+":"+inp.outpoint.index;if(me.outputs[inp]){var address=me.outputs[inp].address,ind=me.addresses.indexOf(address);if(ind>=0){var key=keys[ind];tx.sign(ind,key)}}});return tx};this.getMasterKey=function(){return masterkey};this.getPrivateKey=function(index){if(typeof index=="string")return keys.filter(function(i,k){return addresses[i]==index})[0];else return keys[index]};this.getPrivateKeys=function(){return keys}};module.exports=Wallet},{"./convert":10,"./eckey":17,"./hdwallet.js":18,"./jsbn/jsbn":21,"./jsbn/rng":23,"./script":27,"./transaction":28,"./util":29}]},{},[19])(19)}); \ No newline at end of file