5 lines
128 KiB
JavaScript
5 lines
128 KiB
JavaScript
(function(t){"use strict";t.cryptocoin=("undefined"==typeof floGlobals?null:floGlobals.blockchain)||"FLO";const e=function(){if("function"==typeof require){const t=require("crypto");return function(e){var r=t.randomBytes(e.length);return e.set(r),e}}if(t.crypto&&t.crypto.getRandomValues)return function(e){return t.crypto.getRandomValues(e)};throw Error("Unable to define getRandomBytes")}();var r,n,s,a,u,c,h,f,p,l,y,d,g,m;t.securedMathRandom=function(){if("function"==typeof require){const t=require("crypto");return function(){return t.randomBytes(4).readUInt32LE()/4294967295}}if(t.crypto&&t.crypto.getRandomValues)return function(){return t.crypto.getRandomValues(new Uint32Array(1))[0]/4294967295};throw Error("Unable to define securedMathRandom")}(),function(){var e,r,i,n,s,o,a,u,c,h,f,p=t.Crypto={};e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r=p.util={rotl:function(t,e){return t<<e|t>>>32-e},rotr:function(t,e){return t<<32-e|t>>>e},endian:function(t){if(t.constructor==Number)return 16711935&r.rotl(t,8)|4278255360&r.rotl(t,24);for(var e=0;e<t.length;e++)t[e]=r.endian(t[e]);return t},randomBytes:function(t){for(var e=[];t>0;t--)e.push(Math.floor(256*securedMathRandom()));return e},bytesToWords:function(t){for(var e=[],r=0,i=0;r<t.length;r++,i+=8)e[i>>>5]|=(255&t[r])<<24-i%32;return e},wordsToBytes:function(t){for(var e=[],r=0;r<32*t.length;r+=8)e.push(t[r>>>5]>>>24-r%32&255);return e},bytesToHex:function(t){for(var e=[],r=0;r<t.length;r++)e.push((t[r]>>>4).toString(16)),e.push((15&t[r]).toString(16));return e.join("")},hexToBytes:function(t){for(var e=[],r=0;r<t.length;r+=2)e.push(parseInt(t.substr(r,2),16));return e},bytesToBase64:function(t){for(var r=[],i=0;i<t.length;i+=3)for(var n=t[i]<<16|t[i+1]<<8|t[i+2],s=0;s<4;s++)8*i+6*s<=8*t.length?r.push(e.charAt(n>>>6*(3-s)&63)):r.push("=");return r.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/gi,"");for(var r=[],i=0,n=0;i<t.length;n=++i%4)0!=n&&r.push((e.indexOf(t.charAt(i-1))&Math.pow(2,-2*n+8)-1)<<2*n|e.indexOf(t.charAt(i))>>>6-2*n);return r}},i=p.charenc={},i.UTF8={stringToBytes:function(t){return n.stringToBytes(unescape(encodeURIComponent(t)))},bytesToString:function(t){return decodeURIComponent(escape(n.bytesToString(t)))}},n=i.Binary={stringToBytes:function(t){for(var e=[],r=0;r<t.length;r++)e.push(255&t.charCodeAt(r));return e},bytesToString:function(t){for(var e=[],r=0;r<t.length;r++)e.push(String.fromCharCode(t[r]));return e.join("")}},function(){var t=p,e=t.util,r=t.charenc,i=r.UTF8,n=r.Binary,s=t.SHA1=function(t,r){var i=e.wordsToBytes(s._sha1(t));return r&&r.asBytes?i:r&&r.asString?n.bytesToString(i):e.bytesToHex(i)};s._sha1=function(t){t.constructor==String&&(t=i.stringToBytes(t));var r=e.bytesToWords(t),n=8*t.length,s=[],o=1732584193,a=-271733879,u=-1732584194,c=271733878,h=-1009589776;r[n>>5]|=128<<24-n%32,r[15+(n+64>>>9<<4)]=n;for(var f=0;f<r.length;f+=16){for(var p=o,l=a,y=u,d=c,g=h,v=0;v<80;v++){if(v<16)s[v]=r[f+v];else{var m=s[v-3]^s[v-8]^s[v-14]^s[v-16];s[v]=m<<1|m>>>31}var b=(o<<5|o>>>27)+h+(s[v]>>>0)+(v<20?1518500249+(a&u|~a&c):v<40?1859775393+(a^u^c):v<60?(a&u|a&c|u&c)-1894007588:(a^u^c)-899497514);h=c,c=u,u=a<<30|a>>>2,a=o,o=b}o+=p,a+=l,u+=y,c+=d,h+=g}return[o,a,u,c,h]},s._blocksize=16,s._digestsize=20}(),function(){var t=p,e=t.util,r=t.charenc,i=r.UTF8,n=r.Binary;t.HMAC=function(t,r,s,o){r.constructor==String&&(r=i.stringToBytes(r)),s.constructor==String&&(s=i.stringToBytes(s)),s.length>4*t._blocksize&&(s=t(s,{asBytes:!0}));for(var a=s.slice(0),u=s.slice(0),c=0;c<4*t._blocksize;c++)a[c]^=92,u[c]^=54;var h=t(a.concat(t(u.concat(r),{asBytes:!0})),{asBytes:!0});return o&&o.asBytes?h:o&&o.asString?n.bytesToString(h):e.bytesToHex(h)}}(),s=p,o=s.util,a=s.charenc,u=a.UTF8,c=a.Binary,h=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],f=s.SHA256=function(t,e){var r=o.wordsToBytes(f._sha256(t));return e&&e.asBytes?r:e&&e.asString?c.bytesToString(r):o.bytesToHex(r)},f._sha256=function(t){t.constructor==String&&(t=u.stringToBytes(t));var e,r,i,n,s,a,c,f,p,l,y,d=o.bytesToWords(t),g=8*t.length,v=(t=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],[]);for(d[g>>5]|=128<<24-g%32,d[15+(g+64>>9<<4)]=g,f=0;f<d.length;f+=16){for(g=t[0],e=t[1],r=t[2],i=t[3],n=t[4],s=t[5],a=t[6],c=t[7],p=0;p<64;p++){p<16?v[p]=d[p+f]:(l=v[p-15],y=v[p-2],v[p]=((l<<25|l>>>7)^(l<<14|l>>>18)^l>>>3)+(v[p-7]>>>0)+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+(v[p-16]>>>0)),y=g&e^g&r^e&r;var m=(g<<30|g>>>2)^(g<<19|g>>>13)^(g<<10|g>>>22);l=(c>>>0)+((n<<26|n>>>6)^(n<<21|n>>>11)^(n<<7|n>>>25))+(n&s^~n&a)+h[p]+(v[p]>>>0),y=m+y,c=a,a=s,s=n,n=i+l>>>0,i=r,r=e,e=g,g=l+y>>>0}t[0]+=g,t[1]+=e,t[2]+=r,t[3]+=i,t[4]+=n,t[5]+=s,t[6]+=a,t[7]+=c}return t},f._blocksize=16,f._digestsize=32,function(){var t=p,e=t.util,r=t.charenc,i=r.UTF8,n=r.Binary;t.HMAC=function(t,r,s,o){r.constructor==String&&(r=i.stringToBytes(r)),s.constructor==String&&(s=i.stringToBytes(s)),s.length>4*t._blocksize&&(s=t(s,{asBytes:!0}));for(var a=s.slice(0),u=(s=s.slice(0),0);u<4*t._blocksize;u++)a[u]^=92,s[u]^=54;return t=t(a.concat(t(s.concat(r),{asBytes:!0})),{asBytes:!0}),o&&o.asBytes?t:o&&o.asString?n.bytesToString(t):e.bytesToHex(t)}}()}(),function(){var r=t.SecureRandom=function(){};if(r.state,r.pool,r.pptr,r.poolCopyOnInit,r.poolSize=256,r.prototype.nextBytes=function(i){var n;if(e&&t.Uint8Array)try{var s=new Uint8Array(i.length);for(e(s),n=0;n<i.length;++n)i[n]=r.getByte()^s[n];return}catch(t){alert(t)}for(n=0;n<i.length;++n)i[n]=r.getByte()},r.seedTime=function(){r.seedInt((new Date).getTime())},r.getByte=function(){if(null==r.state){for(r.seedTime(),r.state=r.ArcFour(),r.state.init(r.pool),r.poolCopyOnInit=[],r.pptr=0;r.pptr<r.pool.length;++r.pptr)r.poolCopyOnInit[r.pptr]=r.pool[r.pptr];r.pptr=0}return r.state.next()},r.seedInt=function(t){r.seedInt8(t),r.seedInt8(t>>8),r.seedInt8(t>>16),r.seedInt8(t>>24)},r.seedInt16=function(t){r.seedInt8(t),r.seedInt8(t>>8)},r.seedInt8=function(t){r.pool[r.pptr++]^=255&t,r.pptr>=r.poolSize&&(r.pptr-=r.poolSize)},r.ArcFour=function(){function t(){this.i=0,this.j=0,this.S=new Array}function e(t){var e,r,i;for(e=0;e<256;++e)this.S[e]=e;for(r=0,e=0;e<256;++e)r=r+this.S[e]+t[e%t.length]&255,i=this.S[e],this.S[e]=this.S[r],this.S[r]=i;this.i=0,this.j=0}function r(){var t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]}return t.prototype.init=e,t.prototype.next=r,new t},null==r.pool){var i;if(r.pool=new Array,r.pptr=0,e&&t.Uint8Array)try{var n=new Uint8Array(r.poolSize);for(e(n),i=0;i<r.poolSize;++i)r.pool[r.pptr++]=n[i]}catch(t){alert(t)}for(;r.pptr<r.poolSize;)i=Math.floor(65536*securedMathRandom()),r.pool[r.pptr++]=i>>>8,r.pool[r.pptr++]=255&i;r.pptr=Math.floor(r.poolSize*securedMathRandom()),r.seedTime();var s="";s+=t.screen.height*t.screen.width*t.screen.colorDepth,s+=t.screen.availHeight*t.screen.availWidth*t.screen.pixelDepth;var o=new Date,a=o.getTimezoneOffset();s+=a,s+=navigator.userAgent;for(var u="",c=0;c<navigator.plugins.length;c++)u+=navigator.plugins[c].name+" "+navigator.plugins[c].filename+" "+navigator.plugins[c].description+" "+navigator.plugins[c].version+", ";var h="";for(c=0;c<navigator.mimeTypes.length;c++)h+=navigator.mimeTypes[c].description+" "+navigator.mimeTypes[c].type+" "+navigator.mimeTypes[c].suffixes+", ";s+=u+h,s+=navigator.cookieEnabled+typeof sessionStorage+typeof localStorage,s+=navigator.language,s+=t.history.length,s+=t.location;var f=Crypto.SHA256(s,{asBytes:!0});for(c=0;c<f.length;c++)r.seedInt8(f[c])}}(),function(){function e(t,e,r){return t^e^r}function r(t,e,r){return t&e|~t&r}function i(t,e,r){return(t|~e)^r}function n(t,e,r){return t&r|e&~r}function s(t,e,r){return t^(e|~r)}function o(t,e){return t<<e|t>>>32-e}var a=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],u=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],c=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],h=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11],f=[0,1518500249,1859775393,2400959708,2840853838],p=[1352829926,1548603684,1836072691,2053994217,0],l=function(t){for(var e=[],r=0,i=0;r<t.length;r++,i+=8)e[i>>>5]|=t[r]<<24-i%32;return e},y=function(t){for(var e=[],r=0;r<32*t.length;r+=8)e.push(t[r>>>5]>>>24-r%32&255);return e},d=function(t,l,y){for(var d=0;d<16;d++){var g=y+d,v=l[g];l[g]=16711935&(v<<8|v>>>24)|4278255360&(v<<24|v>>>8)}var m,b,B,w,T,C,S,k,I,F,A;C=m=t[0],S=b=t[1],k=B=t[2],I=w=t[3],F=T=t[4];for(d=0;d<80;d+=1)A=m+l[y+a[d]]|0,A+=d<16?e(b,B,w)+f[0]:d<32?r(b,B,w)+f[1]:d<48?i(b,B,w)+f[2]:d<64?n(b,B,w)+f[3]:s(b,B,w)+f[4],A|=0,A=o(A,c[d]),A=A+T|0,m=T,T=w,w=o(B,10),B=b,b=A,A=C+l[y+u[d]]|0,A+=d<16?s(S,k,I)+p[0]:d<32?n(S,k,I)+p[1]:d<48?i(S,k,I)+p[2]:d<64?r(S,k,I)+p[3]:e(S,k,I)+p[4],A|=0,A=o(A,h[d]),A=A+F|0,C=F,F=I,I=o(k,10),k=S,S=A;A=t[1]+B+I|0,t[1]=t[2]+w+F|0,t[2]=t[3]+T+C|0,t[3]=t[4]+m+S|0,t[4]=t[0]+b+k|0,t[0]=A};t.ripemd160=function(t){var e=[1732584193,4023233417,2562383102,271733878,3285377520],r=l(t),i=8*t.length,n=8*t.length;r[i>>>5]|=128<<24-i%32,r[14+(i+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8);for(var s=0;s<r.length;s+=16)d(e,r,s);for(s=0;s<5;s++){var o=e[s];e[s]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}var a=y(e);return a}}(),function(){function e(){return new g(null)}function r(t,e,r,i,n,s){for(;--s>=0;){var o=e*this[t++]+r[i]+n;n=Math.floor(o/67108864),r[i++]=67108863&o}return n}function i(t,e,r,i,n,s){for(var o=32767&e,a=e>>15;--s>=0;){var u=32767&this[t],c=this[t++]>>15,h=a*u+c*o;u=o*u+((32767&h)<<15)+r[i]+(1073741823&n),n=(u>>>30)+(h>>>15)+a*c+(n>>>30),r[i++]=1073741823&u}return n}function n(t,e,r,i,n,s){for(var o=16383&e,a=e>>14;--s>=0;){var u=16383&this[t],c=this[t++]>>14,h=a*u+c*o;u=o*u+((16383&h)<<14)+r[i]+n,n=(u>>28)+(h>>14)+a*c,r[i++]=268435455&u}return n}function s(t){return T.charAt(t)}function o(t,e){var r=C[t.charCodeAt(e)];return null==r?-1:r}function a(t){var r=e();return r.fromInt(t),r}function u(t){var e,r=1;return 0!=(e=t>>>16)&&(t=e,r+=16),0!=(e=t>>8)&&(t=e,r+=8),0!=(e=t>>4)&&(t=e,r+=4),0!=(e=t>>2)&&(t=e,r+=2),0!=(e=t>>1)&&(t=e,r+=1),r}function c(t){if(0==t)return-1;var e=0;return 0==(65535&t)&&(t>>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function h(t){for(var e=0;0!=t;)t&=t-1,++e;return e}function f(t,e){return t&e}function p(t,e){return t|e}function l(t,e){return t^e}function y(t,e){return t&~e}var d,g=t.BigInteger=function t(e,r,i){if(!(this instanceof t))return new t(e,r,i);null!=e&&("number"==typeof e?this.fromNumber(e,r,i):null==r&&"string"!=typeof e?this.fromString(e,256):this.fromString(e,r))},v=0xdeadbeefcafe,m=15715070==(16777215&v);m&&"Microsoft Internet Explorer"==navigator.appName?(g.prototype.am=i,d=30):m&&"Netscape"!=navigator.appName?(g.prototype.am=r,d=26):(g.prototype.am=n,d=28),g.prototype.DB=d,g.prototype.DM=(1<<d)-1,g.prototype.DV=1<<d;var b=52;g.prototype.FV=Math.pow(2,b),g.prototype.F1=b-d,g.prototype.F2=2*d-b;var B,w,T="0123456789abcdefghijklmnopqrstuvwxyz",C=new Array;for(B="0".charCodeAt(0),w=0;w<=9;++w)C[B++]=w;for(B="a".charCodeAt(0),w=10;w<36;++w)C[B++]=w;for(B="A".charCodeAt(0),w=10;w<36;++w)C[B++]=w;g.prototype.copyTo=function(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s},g.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},g.prototype.fromString=function(t,e){var r;if(16==e)r=4;else if(8==e)r=3;else if(256==e)r=8;else if(2==e)r=1;else if(32==e)r=5;else{if(4!=e)return void this.fromRadix(t,e);r=2}this.t=0,this.s=0;for(var i=t.length,n=!1,s=0;--i>=0;){var a=8==r?255&t[i]:o(t,i);a<0?"-"==t.charAt(i)&&(n=!0):(n=!1,0==s?this[this.t++]=a:s+r>this.DB?(this[this.t-1]|=(a&(1<<this.DB-s)-1)<<s,this[this.t++]=a>>this.DB-s):this[this.t-1]|=a<<s,s+=r,s>=this.DB&&(s-=this.DB))}8==r&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<<this.DB-s)-1<<s)),this.clamp(),n&&g.ZERO.subTo(this,this)},g.prototype.clamp=function(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t},g.prototype.dlShiftTo=function(t,e){var r;for(r=this.t-1;r>=0;--r)e[r+t]=this[r];for(r=t-1;r>=0;--r)e[r]=0;e.t=this.t+t,e.s=this.s},g.prototype.drShiftTo=function(t,e){for(var r=t;r<this.t;++r)e[r-t]=this[r];e.t=Math.max(this.t-t,0),e.s=this.s},g.prototype.lShiftTo=function(t,e){var r,i=t%this.DB,n=this.DB-i,s=(1<<n)-1,o=Math.floor(t/this.DB),a=this.s<<i&this.DM;for(r=this.t-1;r>=0;--r)e[r+o+1]=this[r]>>n|a,a=(this[r]&s)<<i;for(r=o-1;r>=0;--r)e[r]=0;e[o]=a,e.t=this.t+o+1,e.s=this.s,e.clamp()},g.prototype.rShiftTo=function(t,e){e.s=this.s;var r=Math.floor(t/this.DB);if(r>=this.t)e.t=0;else{var i=t%this.DB,n=this.DB-i,s=(1<<i)-1;e[0]=this[r]>>i;for(var o=r+1;o<this.t;++o)e[o-r-1]|=(this[o]&s)<<n,e[o-r]=this[o]>>i;i>0&&(e[this.t-r-1]|=(this.s&s)<<n),e.t=this.t-r,e.clamp()}},g.prototype.subTo=function(t,e){for(var r=0,i=0,n=Math.min(t.t,this.t);r<n;)i+=this[r]-t[r],e[r++]=i&this.DM,i>>=this.DB;if(t.t<this.t){for(i-=t.s;r<this.t;)i+=this[r],e[r++]=i&this.DM,i>>=this.DB;i+=this.s}else{for(i+=this.s;r<t.t;)i-=t[r],e[r++]=i&this.DM,i>>=this.DB;i-=t.s}e.s=i<0?-1:0,i<-1?e[r++]=this.DV+i:i>0&&(e[r++]=i),e.t=r,e.clamp()},g.prototype.multiplyTo=function(t,e){var r=this.abs(),i=t.abs(),n=r.t;for(e.t=n+i.t;--n>=0;)e[n]=0;for(n=0;n<i.t;++n)e[n+r.t]=r.am(0,i[n],e,n,0,r.t);e.s=0,e.clamp(),this.s!=t.s&&g.ZERO.subTo(e,e)},g.prototype.squareTo=function(t){for(var e=this.abs(),r=t.t=2*e.t;--r>=0;)t[r]=0;for(r=0;r<e.t-1;++r){var i=e.am(r,e[r],t,2*r,0,1);(t[r+e.t]+=e.am(r+1,2*e[r],t,2*r+1,i,e.t-r-1))>=e.DV&&(t[r+e.t]-=e.DV,t[r+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(r,e[r],t,2*r,0,1)),t.s=0,t.clamp()},g.prototype.divRemTo=function(t,r,i){var n=t.abs();if(!(n.t<=0)){var s=this.abs();if(s.t<n.t)return null!=r&&r.fromInt(0),void(null!=i&&this.copyTo(i));null==i&&(i=e());var o=e(),a=this.s,c=t.s,h=this.DB-u(n[n.t-1]);h>0?(n.lShiftTo(h,o),s.lShiftTo(h,i)):(n.copyTo(o),s.copyTo(i));var f=o.t,p=o[f-1];if(0!=p){var l=p*(1<<this.F1)+(f>1?o[f-2]>>this.F2:0),y=this.FV/l,d=(1<<this.F1)/l,v=1<<this.F2,m=i.t,b=m-f,B=null==r?e():r;for(o.dlShiftTo(b,B),i.compareTo(B)>=0&&(i[i.t++]=1,i.subTo(B,i)),g.ONE.dlShiftTo(f,B),B.subTo(o,o);o.t<f;)o[o.t++]=0;for(;--b>=0;){var w=i[--m]==p?this.DM:Math.floor(i[m]*y+(i[m-1]+v)*d);if((i[m]+=o.am(0,w,i,b,0,f))<w)for(o.dlShiftTo(b,B),i.subTo(B,i);i[m]<--w;)i.subTo(B,i)}null!=r&&(i.drShiftTo(f,r),a!=c&&g.ZERO.subTo(r,r)),i.t=f,i.clamp(),h>0&&i.rShiftTo(h,i),a<0&&g.ZERO.subTo(i,i)}}},g.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var e=3&t;return e=e*(2-(15&t)*e)&15,e=e*(2-(255&t)*e)&255,e=e*(2-((65535&t)*e&65535))&65535,e=e*(2-t*e%this.DV)%this.DV,e>0?this.DV-e:-e},g.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},g.prototype.exp=function(t,r){if(t>4294967295||t<1)return g.ONE;var i=e(),n=e(),s=r.convert(this),o=u(t)-1;for(s.copyTo(i);--o>=0;)if(r.sqrTo(i,n),(t&1<<o)>0)r.mulTo(n,s,i);else{var a=i;i=n,n=a}return r.revert(i)},g.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var r,i=(1<<e)-1,n=!1,o="",a=this.t,u=this.DB-a*this.DB%e;if(a-- >0)for(u<this.DB&&(r=this[a]>>u)>0&&(n=!0,o=s(r));a>=0;)u<e?(r=(this[a]&(1<<u)-1)<<e-u,r|=this[--a]>>(u+=this.DB-e)):(r=this[a]>>(u-=e)&i,u<=0&&(u+=this.DB,--a)),r>0&&(n=!0),n&&(o+=s(r));return n?o:"0"},g.prototype.negate=function(){var t=e();return g.ZERO.subTo(this,t),t},g.prototype.abs=function(){return this.s<0?this.negate():this},g.prototype.compareTo=function(t){var e=this.s-t.s;if(0!=e)return e;var r=this.t;if(e=r-t.t,0!=e)return this.s<0?-e:e;for(;--r>=0;)if(0!=(e=this[r]-t[r]))return e;return 0},g.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+u(this[this.t-1]^this.s&this.DM)},g.prototype.mod=function(t){var r=e();return this.abs().divRemTo(t,null,r),this.s<0&&r.compareTo(g.ZERO)>0&&t.subTo(r,r),r},g.prototype.modPowInt=function(t,e){var r;return r=t<256||e.isEven()?new I(e):new F(e),this.exp(t,r)},g.ZERO=a(0),g.ONE=a(1);var S=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],k=(1<<26)/S[S.length-1];g.prototype.chunkSize=function(t){return Math.floor(Math.LN2*this.DB/Math.log(t))},g.prototype.toRadix=function(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var r=this.chunkSize(t),i=Math.pow(t,r),n=a(i),s=e(),o=e(),u="";for(this.divRemTo(n,s,o);s.signum()>0;)u=(i+o.intValue()).toString(t).substr(1)+u,s.divRemTo(n,s,o);return o.intValue().toString(t)+u},g.prototype.fromRadix=function(t,e){this.fromInt(0),null==e&&(e=10);for(var r=this.chunkSize(e),i=Math.pow(e,r),n=!1,s=0,a=0,u=0;u<t.length;++u){var c=o(t,u);c<0?"-"==t.charAt(u)&&0==this.signum()&&(n=!0):(a=e*a+c,++s>=r&&(this.dMultiply(i),this.dAddOffset(a,0),s=0,a=0))}s>0&&(this.dMultiply(Math.pow(e,s)),this.dAddOffset(a,0)),n&&g.ZERO.subTo(this,this)},g.prototype.fromNumber=function(t,e,r){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,r),this.testBit(t-1)||this.bitwiseTo(g.ONE.shiftLeft(t-1),p,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(g.ONE.shiftLeft(t-1),this);else{var i=new Array,n=7&t;i.length=1+(t>>3),e.nextBytes(i),n>0?i[0]&=(1<<n)-1:i[0]=0,this.fromString(i,256)}},g.prototype.bitwiseTo=function(t,e,r){var i,n,s=Math.min(t.t,this.t);for(i=0;i<s;++i)r[i]=e(this[i],t[i]);if(t.t<this.t){for(n=t.s&this.DM,i=s;i<this.t;++i)r[i]=e(this[i],n);r.t=this.t}else{for(n=this.s&this.DM,i=s;i<t.t;++i)r[i]=e(n,t[i]);r.t=t.t}r.s=e(this.s,t.s),r.clamp()},g.prototype.changeBit=function(t,e){var r=g.ONE.shiftLeft(t);return this.bitwiseTo(r,e,r),r},g.prototype.addTo=function(t,e){for(var r=0,i=0,n=Math.min(t.t,this.t);r<n;)i+=this[r]+t[r],e[r++]=i&this.DM,i>>=this.DB;if(t.t<this.t){for(i+=t.s;r<this.t;)i+=this[r],e[r++]=i&this.DM,i>>=this.DB;i+=this.s}else{for(i+=this.s;r<t.t;)i+=t[r],e[r++]=i&this.DM,i>>=this.DB;i+=t.s}e.s=i<0?-1:0,i>0?e[r++]=i:i<-1&&(e[r++]=this.DV+i),e.t=r,e.clamp()},g.prototype.dMultiply=function(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},g.prototype.dAddOffset=function(t,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}},g.prototype.multiplyLowerTo=function(t,e,r){var i,n=Math.min(this.t+t.t,e);for(r.s=0,r.t=n;n>0;)r[--n]=0;for(i=r.t-this.t;n<i;++n)r[n+this.t]=this.am(0,t[n],r,n,0,this.t);for(i=Math.min(t.t,e);n<i;++n)this.am(0,t[n],r,n,0,e-n);r.clamp()},g.prototype.multiplyUpperTo=function(t,e,r){--e;var i=r.t=this.t+t.t-e;for(r.s=0;--i>=0;)r[i]=0;for(i=Math.max(e-this.t,0);i<t.t;++i)r[this.t+i-e]=this.am(e-i,t[i],r,0,0,this.t+i-e);r.clamp(),r.drShiftTo(1,r)},g.prototype.modInt=function(t){if(t<=0)return 0;var e=this.DV%t,r=this.s<0?t-1:0;if(this.t>0)if(0==e)r=this[0]%t;else for(var i=this.t-1;i>=0;--i)r=(e*r+this[i])%t;return r},g.prototype.millerRabin=function(t){var r=this.subtract(g.ONE),i=r.getLowestSetBit();if(i<=0)return!1;var n=r.shiftRight(i);t=t+1>>1,t>S.length&&(t=S.length);for(var s=e(),o=0;o<t;++o){s.fromInt(S[Math.floor(securedMathRandom()*S.length)]);var a=s.modPow(n,this);if(0!=a.compareTo(g.ONE)&&0!=a.compareTo(r)){for(var u=1;u++<i&&0!=a.compareTo(r);)if(a=a.modPowInt(2,this),0==a.compareTo(g.ONE))return!1;if(0!=a.compareTo(r))return!1}}return!0},g.prototype.clone=function(){var t=e();return this.copyTo(t),t},g.prototype.intValue=function(){if(this.s<0){if(1==this.t)return this[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this[0];if(0==this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]},g.prototype.byteValue=function(){return 0==this.t?this.s:this[0]<<24>>24},g.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},g.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},g.prototype.toByteArray=function(){var t=this.t,e=new Array;e[0]=this.s;var r,i=this.DB-t*this.DB%8,n=0;if(t-- >0)for(i<this.DB&&(r=this[t]>>i)!=(this.s&this.DM)>>i&&(e[n++]=r|this.s<<this.DB-i);t>=0;)i<8?(r=(this[t]&(1<<i)-1)<<8-i,r|=this[--t]>>(i+=this.DB-8)):(r=this[t]>>(i-=8)&255,i<=0&&(i+=this.DB,--t)),0!=(128&r)&&(r|=-256),0==n&&(128&this.s)!=(128&r)&&++n,(n>0||r!=this.s)&&(e[n++]=r);return e},g.prototype.equals=function(t){return 0==this.compareTo(t)},g.prototype.min=function(t){return this.compareTo(t)<0?this:t},g.prototype.max=function(t){return this.compareTo(t)>0?this:t},g.prototype.and=function(t){var r=e();return this.bitwiseTo(t,f,r),r},g.prototype.or=function(t){var r=e();return this.bitwiseTo(t,p,r),r},g.prototype.xor=function(t){var r=e();return this.bitwiseTo(t,l,r),r},g.prototype.andNot=function(t){var r=e();return this.bitwiseTo(t,y,r),r},g.prototype.not=function(){for(var t=e(),r=0;r<this.t;++r)t[r]=this.DM&~this[r];return t.t=this.t,t.s=~this.s,t},g.prototype.shiftLeft=function(t){var r=e();return t<0?this.rShiftTo(-t,r):this.lShiftTo(t,r),r},g.prototype.shiftRight=function(t){var r=e();return t<0?this.lShiftTo(-t,r):this.rShiftTo(t,r),r},g.prototype.getLowestSetBit=function(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+c(this[t]);return this.s<0?this.t*this.DB:-1},g.prototype.bitCount=function(){for(var t=0,e=this.s&this.DM,r=0;r<this.t;++r)t+=h(this[r]^e);return t},g.prototype.testBit=function(t){var e=Math.floor(t/this.DB);return e>=this.t?0!=this.s:0!=(this[e]&1<<t%this.DB)},g.prototype.setBit=function(t){return this.changeBit(t,p)},g.prototype.clearBit=function(t){return this.changeBit(t,y)},g.prototype.flipBit=function(t){return this.changeBit(t,l)},g.prototype.add=function(t){var r=e();return this.addTo(t,r),r},g.prototype.subtract=function(t){var r=e();return this.subTo(t,r),r},g.prototype.multiply=function(t){var r=e();return this.multiplyTo(t,r),r},g.prototype.divide=function(t){var r=e();return this.divRemTo(t,r,null),r},g.prototype.remainder=function(t){var r=e();return this.divRemTo(t,null,r),r},g.prototype.divideAndRemainder=function(t){var r=e(),i=e();return this.divRemTo(t,r,i),new Array(r,i)},g.prototype.modPow=function(t,r){var i,n,s=t.bitLength(),o=a(1);if(s<=0)return o;i=s<18?1:s<48?3:s<144?4:s<768?5:6,n=s<8?new I(r):r.isEven()?new x(r):new F(r);var c=new Array,h=3,f=i-1,p=(1<<i)-1;if(c[1]=n.convert(this),i>1){var l=e();for(n.sqrTo(c[1],l);h<=p;)c[h]=e(),n.mulTo(l,c[h-2],c[h]),h+=2}var y,d,g=t.t-1,v=!0,m=e();for(s=u(t[g])-1;g>=0;){for(s>=f?y=t[g]>>s-f&p:(y=(t[g]&(1<<s+1)-1)<<f-s,g>0&&(y|=t[g-1]>>this.DB+s-f)),h=i;0==(1&y);)y>>=1,--h;if((s-=h)<0&&(s+=this.DB,--g),v)c[y].copyTo(o),v=!1;else{for(;h>1;)n.sqrTo(o,m),n.sqrTo(m,o),h-=2;h>0?n.sqrTo(o,m):(d=o,o=m,m=d),n.mulTo(m,c[y],o)}for(;g>=0&&0==(t[g]&1<<s);)n.sqrTo(o,m),d=o,o=m,m=d,--s<0&&(s=this.DB-1,--g)}return n.revert(o)},g.prototype.modInverse=function(t){var e=t.isEven();if(0===this.signum())throw new Error("division by zero");if(this.isEven()&&e||0==t.signum())return g.ZERO;for(var r=t.clone(),i=this.clone(),n=a(1),s=a(0),o=a(0),u=a(1);0!=r.signum();){for(;r.isEven();)r.rShiftTo(1,r),e?(n.isEven()&&s.isEven()||(n.addTo(this,n),s.subTo(t,s)),n.rShiftTo(1,n)):s.isEven()||s.subTo(t,s),s.rShiftTo(1,s);for(;i.isEven();)i.rShiftTo(1,i),e?(o.isEven()&&u.isEven()||(o.addTo(this,o),u.subTo(t,u)),o.rShiftTo(1,o)):u.isEven()||u.subTo(t,u),u.rShiftTo(1,u);r.compareTo(i)>=0?(r.subTo(i,r),e&&n.subTo(o,n),s.subTo(u,s)):(i.subTo(r,i),e&&o.subTo(n,o),u.subTo(s,u))}if(0!=i.compareTo(g.ONE))return g.ZERO;for(;u.compareTo(t)>=0;)u.subTo(t,u);for(;u.signum()<0;)u.addTo(t,u);return u},g.prototype.pow=function(t){return this.exp(t,new A)},g.prototype.gcd=function(t){var e=this.s<0?this.negate():this.clone(),r=t.s<0?t.negate():t.clone();if(e.compareTo(r)<0){var i=e;e=r,r=i}var n=e.getLowestSetBit(),s=r.getLowestSetBit();if(s<0)return e;for(n<s&&(s=n),s>0&&(e.rShiftTo(s,e),r.rShiftTo(s,r));e.signum()>0;)(n=e.getLowestSetBit())>0&&e.rShiftTo(n,e),(n=r.getLowestSetBit())>0&&r.rShiftTo(n,r),e.compareTo(r)>=0?(e.subTo(r,e),e.rShiftTo(1,e)):(r.subTo(e,r),r.rShiftTo(1,r));return s>0&&r.lShiftTo(s,r),r},g.prototype.isProbablePrime=function(t){var e,r=this.abs();if(1==r.t&&r[0]<=S[S.length-1]){for(e=0;e<S.length;++e)if(r[0]==S[e])return!0;return!1}if(r.isEven())return!1;for(e=1;e<S.length;){for(var i=S[e],n=e+1;n<S.length&&i<k;)i*=S[n++];for(i=r.modInt(i);e<n;)if(i%S[e++]==0)return!1}return r.millerRabin(t)},g.prototype.square=function(){var t=e();return this.squareTo(t),t},g.valueOf=a,g.prototype.toByteArrayUnsigned=function(){var t=this.abs().toByteArray();return t.length?(0==t[0]&&(t=t.slice(1)),t.map(function(t){return t<0?t+256:t})):t},g.fromByteArrayUnsigned=function(t){return t.length?128&t[0]?new g([0].concat(t)):new g(t):t.valueOf(0)},g.prototype.toByteArraySigned=function(){var t=this.abs().toByteArrayUnsigned(),e=this.compareTo(g.ZERO)<0;return e?128&t[0]?t.unshift(128):t[0]|=128:128&t[0]&&t.unshift(0),t},g.fromByteArraySigned=function(t){return 128&t[0]?(t[0]&=127,g.fromByteArrayUnsigned(t).negate()):g.fromByteArrayUnsigned(t)};var I=t.Classic=function(t){this.m=t};I.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},I.prototype.revert=function(t){return t},I.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},I.prototype.mulTo=function(t,e,r){t.multiplyTo(e,r),this.reduce(r)},I.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var F=t.Montgomery=function(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t};F.prototype.convert=function(t){var r=e();return t.abs().dlShiftTo(this.m.t,r),r.divRemTo(this.m,null,r),t.s<0&&r.compareTo(g.ZERO)>0&&this.m.subTo(r,r),r},F.prototype.revert=function(t){var r=e();return t.copyTo(r),this.reduce(r),r},F.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e<this.m.t;++e){var r=32767&t[e],i=r*this.mpl+((r*this.mph+(t[e]>>15)*this.mpl&this.um)<<15)&t.DM;for(r=e+this.m.t,t[r]+=this.m.am(0,i,t,e,0,this.m.t);t[r]>=t.DV;)t[r]-=t.DV,t[++r]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},F.prototype.mulTo=function(t,e,r){t.multiplyTo(e,r),this.reduce(r)},F.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var A=t.NullExp=function(){};A.prototype.convert=function(t){return t},A.prototype.revert=function(t){return t},A.prototype.mulTo=function(t,e,r){t.multiplyTo(e,r)},A.prototype.sqrTo=function(t,e){t.squareTo(e)};var x=t.Barrett=function(t){this.r2=e(),this.q3=e(),g.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t};x.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var r=e();return t.copyTo(r),this.reduce(r),r},x.prototype.revert=function(t){return t},x.prototype.reduce=function(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)},x.prototype.mulTo=function(t,e,r){t.multiplyTo(e,r),this.reduce(r)},x.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)}}(),f=t.EllipticCurve=function(){},f.FieldElementFp=function(t,e){this.x=e,this.q=t},f.FieldElementFp.prototype.equals=function(t){return t==this||this.q.equals(t.q)&&this.x.equals(t.x)},f.FieldElementFp.prototype.toBigInteger=function(){return this.x},f.FieldElementFp.prototype.negate=function(){return new f.FieldElementFp(this.q,this.x.negate().mod(this.q))},f.FieldElementFp.prototype.add=function(t){return new f.FieldElementFp(this.q,this.x.add(t.toBigInteger()).mod(this.q))},f.FieldElementFp.prototype.subtract=function(t){return new f.FieldElementFp(this.q,this.x.subtract(t.toBigInteger()).mod(this.q))},f.FieldElementFp.prototype.multiply=function(t){return new f.FieldElementFp(this.q,this.x.multiply(t.toBigInteger()).mod(this.q))},f.FieldElementFp.prototype.square=function(){return new f.FieldElementFp(this.q,this.x.square().mod(this.q))},f.FieldElementFp.prototype.divide=function(t){return new f.FieldElementFp(this.q,this.x.multiply(t.toBigInteger().modInverse(this.q)).mod(this.q))},f.FieldElementFp.prototype.getByteLength=function(){return Math.floor((this.toBigInteger().bitLength()+7)/8)},f.FieldElementFp.prototype.sqrt=function(){if(!this.q.testBit(0))throw new Error("even value of q");if(this.q.testBit(1)){var t=new f.FieldElementFp(this.q,this.x.modPow(this.q.shiftRight(2).add(BigInteger.ONE),this.q));return t.square().equals(this)?t:null}var e=this.q.subtract(BigInteger.ONE),r=e.shiftRight(1);if(!this.x.modPow(r,this.q).equals(BigInteger.ONE))return null;var i,n,s=e.shiftRight(2),o=s.shiftLeft(1).add(BigInteger.ONE),a=this.x,u=a.shiftLeft(2).mod(this.q);do{var c,h=new SecureRandom;do{c=new BigInteger(this.q.bitLength(),h)}while(c.compareTo(this.q)>=0||!c.multiply(c).subtract(u).modPow(r,this.q).equals(e));var p=f.FieldElementFp.fastLucasSequence(this.q,c,a,o);if(i=p[0],n=p[1],n.multiply(n).mod(this.q).equals(u))return n.testBit(0)&&(n=n.add(this.q)),n=n.shiftRight(1),new f.FieldElementFp(this.q,n)}while(i.equals(BigInteger.ONE)||i.equals(e));return null},function(t){function e(t,e){var r=4*t._blocksize,i=r-e.length%r;return i}var r=t.pad={},i=function(t,e,r,i){var n=e.pop();if(0==n)throw new Error("Invalid zero-length padding specified for "+r+". Wrong cipher specification or key used?");var s=4*t._blocksize;if(n>s)throw new Error("Invalid padding length of "+n+" specified for "+r+". Wrong cipher specification or key used?");for(var o=1;o<n;o++){var a=e.pop();if(null!=i&&i!=a)throw new Error("Invalid padding byte of 0x"+a.toString(16)+" specified for "+r+". Wrong cipher specification or key used?")}};r.NoPadding={pad:function(t,e){},unpad:function(t,e){}},r.ZeroPadding={pad:function(t,e){var r=4*t._blocksize,i=e.length%r;if(0!=i)for(i=r-i;i>0;i--)e.push(0)},unpad:function(t,e){for(;0==e[e.length-1];)e.pop()}},r.iso7816={pad:function(t,r){var i=e(t,r);for(r.push(128);i>1;i--)r.push(0)},unpad:function(t,e){var r;for(r=4*t._blocksize;r>0;r--){var i=e.pop();if(128==i)return
|
|
;if(0!=i)throw new Error("ISO-7816 padding byte must be 0, not 0x"+i.toString(16)+". Wrong cipher specification or key used?")}throw new Error("ISO-7816 padded beyond cipher block size. Wrong cipher specification or key used?")}},r.ansix923={pad:function(t,r){for(var i=e(t,r),n=1;n<i;n++)r.push(0);r.push(i)},unpad:function(t,e){i(t,e,"ANSI X.923",0)}},r.iso10126={pad:function(t,r){for(var i=e(t,r),n=1;n<i;n++)r.push(Math.floor(256*securedMathRandom()));r.push(i)},unpad:function(t,e){i(t,e,"ISO 10126",void 0)}},r.pkcs7={pad:function(t,r){for(var i=e(t,r),n=0;n<i;n++)r.push(i)},unpad:function(t,e){i(t,e,"PKCS 7",e[e.length-1])}};var n=t.mode={},s=n.Mode=function(t){t&&(this._padding=t)};s.prototype={encrypt:function(t,e,r){this._padding.pad(t,e),this._doEncrypt(t,e,r)},decrypt:function(t,e,r){this._doDecrypt(t,e,r),this._padding.unpad(t,e)},_padding:r.iso7816};var o=n.ECB=function(){s.apply(this,arguments)},a=o.prototype=new s;a._doEncrypt=function(t,e,r){for(var i=4*t._blocksize,n=0;n<e.length;n+=i)t._encryptblock(e,n)},a._doDecrypt=function(t,e,r){for(var i=4*t._blocksize,n=0;n<e.length;n+=i)t._decryptblock(e,n)},a.fixOptions=function(t){t.iv=[]};var u=n.CBC=function(){s.apply(this,arguments)},c=u.prototype=new s;c._doEncrypt=function(t,e,r){for(var i=4*t._blocksize,n=0;n<e.length;n+=i){if(0==n)for(var s=0;s<i;s++)e[s]^=r[s];else for(s=0;s<i;s++)e[n+s]^=e[n+s-i];t._encryptblock(e,n)}},c._doDecrypt=function(t,e,r){for(var i=4*t._blocksize,n=r,s=0;s<e.length;s+=i){var o=e.slice(s,s+i);t._decryptblock(e,s);for(var a=0;a<i;a++)e[s+a]^=n[a];n=o}};var h=n.CFB=function(){s.apply(this,arguments)},f=h.prototype=new s;f._padding=r.NoPadding,f._doEncrypt=function(t,e,r){for(var i=4*t._blocksize,n=r.slice(0),s=0;s<e.length;s++){var o=s%i;0==o&&t._encryptblock(n,0),e[s]^=n[o],n[o]=e[s]}},f._doDecrypt=function(t,e,r){for(var i=4*t._blocksize,n=r.slice(0),s=0;s<e.length;s++){var o=s%i;0==o&&t._encryptblock(n,0);var a=e[s];e[s]^=n[o],n[o]=a}};var p=n.OFB=function(){s.apply(this,arguments)},l=p.prototype=new s;l._padding=r.NoPadding,l._doEncrypt=function(t,e,r){for(var i=4*t._blocksize,n=r.slice(0),s=0;s<e.length;s++)s%i==0&&t._encryptblock(n,0),e[s]^=n[s%i]},l._doDecrypt=l._doEncrypt;var y=n.CTR=function(){s.apply(this,arguments)},d=y.prototype=new s;d._padding=r.NoPadding,d._doEncrypt=function(t,e,r){for(var i=4*t._blocksize,n=r.slice(0),s=0;s<e.length;){var o=n.slice(0);t._encryptblock(o,0);for(var a=0;s<e.length&&a<i;a++,s++)e[s]^=o[a];256==++n[i-1]&&(n[i-1]=0,256==++n[i-2]&&(n[i-2]=0,256==++n[i-3]&&(n[i-3]=0,++n[i-4])))}},d._doDecrypt=d._doEncrypt}(Crypto),r=Crypto,n=r.util,s=r.charenc,a=s.UTF8,u=s.Binary,r.PBKDF2=function(t,e,i,s){function o(t,e){return r.HMAC(c,e,t,{asBytes:!0})}t.constructor==String&&(t=a.stringToBytes(t)),e.constructor==String&&(e=a.stringToBytes(e));for(var c=s&&s.hasher||r.SHA1,h=s&&s.iterations||1,f=[],p=1;f.length<i;){for(var l=o(t,e.concat(n.wordsToBytes([p]))),y=l,d=1;d<h;d++){y=o(t,y);for(var g=0;g<l.length;g++)l[g]^=y[g]}f=f.concat(l),p++}return f.length=i,s&&s.asBytes?f:s&&s.asString?u.bytesToString(f):n.bytesToHex(f)},c=2147483647,h=null,t.Crypto_scrypt=function(e,r,i,n,s,o,a){function u(){function t(t,r,i,n,s,o){var c,f=0,p=128*i;for(h(t,r,o,f,p),c=0;c<n;c++)h(o,f,s,c*p,p),e(o,f,p,i);for(c=0;c<n;c++){var l=u(o,f,i)&n-1;a(s,l*p,o,f,p),e(o,f,p,i)}h(o,f,t,r,p)}function e(t,e,r,i){var n,s=[];for(h(t,e+64*(2*i-1),s,0,64),n=0;n<2*i;n++)a(t,64*n,s,0,64),o(s),h(s,0,t,r+64*n,64);for(n=0;n<i;n++)h(t,r+2*n*64,t,e+64*n,64);for(n=0;n<i;n++)h(t,r+64*(2*n+1),t,e+64*(n+i),64)}function r(t,e){return t<<e|t>>>32-e}function o(t){var e,i=new Array(32),n=new Array(32);for(e=0;e<16;e++)i[e]=(255&t[4*e+0])<<0,i[e]|=(255&t[4*e+1])<<8,i[e]|=(255&t[4*e+2])<<16,i[e]|=(255&t[4*e+3])<<24;for(c(i,0,n,0,16),e=8;e>0;e-=2)n[4]^=r(n[0]+n[12],7),n[8]^=r(n[4]+n[0],9),n[12]^=r(n[8]+n[4],13),n[0]^=r(n[12]+n[8],18),n[9]^=r(n[5]+n[1],7),n[13]^=r(n[9]+n[5],9),n[1]^=r(n[13]+n[9],13),n[5]^=r(n[1]+n[13],18),n[14]^=r(n[10]+n[6],7),n[2]^=r(n[14]+n[10],9),n[6]^=r(n[2]+n[14],13),n[10]^=r(n[6]+n[2],18),n[3]^=r(n[15]+n[11],7),n[7]^=r(n[3]+n[15],9),n[11]^=r(n[7]+n[3],13),n[15]^=r(n[11]+n[7],18),n[1]^=r(n[0]+n[3],7),n[2]^=r(n[1]+n[0],9),n[3]^=r(n[2]+n[1],13),n[0]^=r(n[3]+n[2],18),n[6]^=r(n[5]+n[4],7),n[7]^=r(n[6]+n[5],9),n[4]^=r(n[7]+n[6],13),n[5]^=r(n[4]+n[7],18),n[11]^=r(n[10]+n[9],7),n[8]^=r(n[11]+n[10],9),n[9]^=r(n[8]+n[11],13),n[10]^=r(n[9]+n[8],18),n[12]^=r(n[15]+n[14],7),n[13]^=r(n[12]+n[15],9),n[14]^=r(n[13]+n[12],13),n[15]^=r(n[14]+n[13],18);for(e=0;e<16;++e)i[e]=n[e]+i[e];for(e=0;e<16;e++){var s=4*e;t[s+0]=i[e]>>0&255,t[s+1]=i[e]>>8&255,t[s+2]=i[e]>>16&255,t[s+3]=i[e]>>24&255}}function a(t,e,r,i,n){for(var s=n>>6;s--;)r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++],r[i++]^=t[e++]}function u(t,e,r){var i;return e+=64*(2*r-1),i=(255&t[e+0])<<0,i|=(255&t[e+1])<<8,i|=(255&t[e+2])<<16,i|=(255&t[e+3])<<24,i}function c(t,e,r,i,n){for(;n--;)r[i++]=t[e++]}function h(t,e,r,i,n){for(var s=n>>5;s--;)r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++],r[i++]=t[e++]}var f=[],l=[];if(void 0===p)onmessage=function(e){var r=e.data,i=r[0],n=r[1],s=(r[2],r[3]),o=r[4],a=[];h(s,128*o*n,a,0,128*n),t(a,0,n,i,l,f),postMessage([o,a])};else for(var y=0;y<s;y++)t(p,128*y*n,n,i,l,f)}if(0==i||0!=(i&i-1))throw Error("N must be > 0 and a power of 2");if(i>c/128/n)throw Error("Parameter N is too large");if(n>c/128/s)throw Error("Parameter r is too large");var f={iterations:1,hasher:Crypto.SHA256,asBytes:!0},p=Crypto.PBKDF2(e,r,128*s*n,f);try{var l=0,y=0,d=function(){if(!h){var r,c="("+u.toString()+")()";try{r=new Blob([c],{type:"text/javascript"})}catch(e){t.BlobBuilder=t.BlobBuilder||t.WebKitBlobBuilder||t.MozBlobBuilder||t.MSBlobBuilder,r=new BlobBuilder,r.append(c),r=r.getBlob("text/javascript")}h=URL.createObjectURL(r)}var d=new Worker(h);return d.onmessage=function(t){var r=t.data[0],u=t.data[1];y++,l<s&&d.postMessage([i,n,s,p,l++]);for(var c=u.length,h=128*r*n,g=0;c--;)p[h++]=u[g++];y==s&&a(Crypto.PBKDF2(e,p,o,f))},d},g=[d(),d()];g[0].postMessage([i,n,s,p,l++]),s>1&&g[1].postMessage([i,n,s,p,l++])}catch(r){t.setTimeout(function(){u(),a(Crypto.PBKDF2(e,p,o,f))},0)}},function(){function t(t,e){for(var r=0,i=0;i<8;i++){1&e&&(r^=t);var n=128&t;t=t<<1&255,n&&(t^=27),e>>>=1}return r}for(var e=Crypto,r=e.util,i=e.charenc,n=i.UTF8,s=[99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22],o=[],a=0;a<256;a++)o[s[a]]=a;var u=[],c=[],h=[],f=[],p=[],l=[];for(a=0;a<256;a++)u[a]=t(a,2),c[a]=t(a,3),h[a]=t(a,9),f[a]=t(a,11),p[a]=t(a,13),l[a]=t(a,14);var y,d,g,v=[0,1,2,4,8,16,32,64,128,27,54],m=[[],[],[],[]],b=e.AES={encrypt:function(t,i,s){s=s||{};var o=s.mode||new e.mode.OFB;o.fixOptions&&o.fixOptions(s);var a=t.constructor==String?n.stringToBytes(t):t,u=s.iv||r.randomBytes(4*b._blocksize),c=i.constructor==String?e.PBKDF2(i,u,32,{asBytes:!0}):i;return b._init(c),o.encrypt(b,a,u),a=s.iv?a:u.concat(a),s&&s.asBytes?a:r.bytesToBase64(a)},decrypt:function(t,i,s){s=s||{};var o=s.mode||new e.mode.OFB;o.fixOptions&&o.fixOptions(s);var a=t.constructor==String?r.base64ToBytes(t):t,u=s.iv||a.splice(0,4*b._blocksize),c=i.constructor==String?e.PBKDF2(i,u,32,{asBytes:!0}):i;return b._init(c),o.decrypt(b,a,u),s&&s.asBytes?a:n.bytesToString(a)},_blocksize:4,_encryptblock:function(t,e){for(var r=0;r<b._blocksize;r++)for(var i=0;i<4;i++)m[r][i]=t[e+4*i+r];for(r=0;r<4;r++)for(i=0;i<4;i++)m[r][i]^=g[i][r];for(var n=1;n<d;n++){for(r=0;r<4;r++)for(i=0;i<4;i++)m[r][i]=s[m[r][i]];for(m[1].push(m[1].shift()),m[2].push(m[2].shift()),m[2].push(m[2].shift()),m[3].unshift(m[3].pop()),i=0;i<4;i++){var o=m[0][i],a=m[1][i],h=m[2][i],f=m[3][i];m[0][i]=u[o]^c[a]^h^f,m[1][i]=o^u[a]^c[h]^f,m[2][i]=o^a^u[h]^c[f],m[3][i]=c[o]^a^h^u[f]}for(r=0;r<4;r++)for(i=0;i<4;i++)m[r][i]^=g[4*n+i][r]}for(r=0;r<4;r++)for(i=0;i<4;i++)m[r][i]=s[m[r][i]];for(m[1].push(m[1].shift()),m[2].push(m[2].shift()),m[2].push(m[2].shift()),m[3].unshift(m[3].pop()),r=0;r<4;r++)for(i=0;i<4;i++)m[r][i]^=g[4*d+i][r];for(r=0;r<b._blocksize;r++)for(i=0;i<4;i++)t[e+4*i+r]=m[r][i]},_decryptblock:function(t,e){for(var r=0;r<b._blocksize;r++)for(var i=0;i<4;i++)m[r][i]=t[e+4*i+r];for(r=0;r<4;r++)for(i=0;i<4;i++)m[r][i]^=g[4*d+i][r];for(var n=1;n<d;n++){for(m[1].unshift(m[1].pop()),m[2].push(m[2].shift()),m[2].push(m[2].shift()),m[3].push(m[3].shift()),r=0;r<4;r++)for(i=0;i<4;i++)m[r][i]=o[m[r][i]];for(r=0;r<4;r++)for(i=0;i<4;i++)m[r][i]^=g[4*(d-n)+i][r];for(i=0;i<4;i++){var s=m[0][i],a=m[1][i],u=m[2][i],c=m[3][i];m[0][i]=l[s]^f[a]^p[u]^h[c],m[1][i]=h[s]^l[a]^f[u]^p[c],m[2][i]=p[s]^h[a]^l[u]^f[c],m[3][i]=f[s]^p[a]^h[u]^l[c]}}for(m[1].unshift(m[1].pop()),m[2].push(m[2].shift()),m[2].push(m[2].shift()),m[3].push(m[3].shift()),r=0;r<4;r++)for(i=0;i<4;i++)m[r][i]=o[m[r][i]];for(r=0;r<4;r++)for(i=0;i<4;i++)m[r][i]^=g[i][r];for(r=0;r<b._blocksize;r++)for(i=0;i<4;i++)t[e+4*i+r]=m[r][i]},_init:function(t){y=t.length/4,d=y+6,b._keyexpansion(t)},_keyexpansion:function(t){g=[];for(var e=0;e<y;e++)g[e]=[t[4*e],t[4*e+1],t[4*e+2],t[4*e+3]];for(e=y;e<b._blocksize*(d+1);e++){var r=[g[e-1][0],g[e-1][1],g[e-1][2],g[e-1][3]];e%y==0?(r.push(r.shift()),r[0]=s[r[0]],r[1]=s[r[1]],r[2]=s[r[2]],r[3]=s[r[3]],r[0]^=v[e/y]):y>6&&e%y==4&&(r[0]=s[r[0]],r[1]=s[r[1]],r[2]=s[r[2]],r[3]=s[r[3]]),g[e]=[g[e-y][0]^r[0],g[e-y][1]^r[1],g[e-y][2]^r[2],g[e-y][3]^r[3]]}}}}(),f.FieldElementFp.fastLucasSequence=function(t,e,r,i){for(var n=i.bitLength(),s=i.getLowestSetBit(),o=BigInteger.ONE,a=BigInteger.TWO,u=e,c=BigInteger.ONE,h=BigInteger.ONE,f=n-1;f>=s+1;--f)c=c.multiply(h).mod(t),i.testBit(f)?(h=c.multiply(r).mod(t),o=o.multiply(u).mod(t),a=u.multiply(a).subtract(e.multiply(c)).mod(t),u=u.multiply(u).subtract(h.shiftLeft(1)).mod(t)):(h=c,o=o.multiply(a).subtract(c).mod(t),u=u.multiply(a).subtract(e.multiply(c)).mod(t),a=a.multiply(a).subtract(c.shiftLeft(1)).mod(t));for(c=c.multiply(h).mod(t),h=c.multiply(r).mod(t),o=o.multiply(a).subtract(c).mod(t),a=u.multiply(a).subtract(e.multiply(c)).mod(t),c=c.multiply(h).mod(t),f=1;f<=s;++f)o=o.multiply(a).mod(t),a=a.multiply(a).subtract(c.shiftLeft(1)).mod(t),c=c.multiply(c).mod(t);return[o,a]},f.PointFp=function(t,e,r,i,n){this.curve=t,this.x=e,this.y=r,this.z=null==i?BigInteger.ONE:i,this.zinv=null,this.compressed=!!n},f.PointFp.prototype.getX=function(){null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q));var t=this.x.toBigInteger().multiply(this.zinv);return this.curve.reduce(t),this.curve.fromBigInteger(t)},f.PointFp.prototype.getY=function(){null==this.zinv&&(this.zinv=this.z.modInverse(this.curve.q));var t=this.y.toBigInteger().multiply(this.zinv);return this.curve.reduce(t),this.curve.fromBigInteger(t)},f.PointFp.prototype.equals=function(t){return t==this||(this.isInfinity()?t.isInfinity():t.isInfinity()?this.isInfinity():(e=t.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(t.z)).mod(this.curve.q),!!e.equals(BigInteger.ZERO)&&(r=t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q),r.equals(BigInteger.ZERO))));var e,r},f.PointFp.prototype.isInfinity=function(){return null==this.x&&null==this.y||this.z.equals(BigInteger.ZERO)&&!this.y.toBigInteger().equals(BigInteger.ZERO)},f.PointFp.prototype.negate=function(){return new f.PointFp(this.curve,this.x,this.y.negate(),this.z)},f.PointFp.prototype.add=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;var e=t.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(t.z)).mod(this.curve.q),r=t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q);if(BigInteger.ZERO.equals(r))return BigInteger.ZERO.equals(e)?this.twice():this.curve.getInfinity();var i=new BigInteger("3"),n=this.x.toBigInteger(),s=this.y.toBigInteger(),o=(t.x.toBigInteger(),t.y.toBigInteger(),r.square()),a=o.multiply(r),u=n.multiply(o),c=e.square().multiply(this.z),h=c.subtract(u.shiftLeft(1)).multiply(t.z).subtract(a).multiply(r).mod(this.curve.q),p=u.multiply(i).multiply(e).subtract(s.multiply(a)).subtract(c.multiply(e)).multiply(t.z).add(e.multiply(a)).mod(this.curve.q),l=a.multiply(this.z).multiply(t.z).mod(this.curve.q);return new f.PointFp(this.curve,this.curve.fromBigInteger(h),this.curve.fromBigInteger(p),l)},f.PointFp.prototype.twice=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var t=new BigInteger("3"),e=this.x.toBigInteger(),r=this.y.toBigInteger(),i=r.multiply(this.z),n=i.multiply(r).mod(this.curve.q),s=this.curve.a.toBigInteger(),o=e.square().multiply(t);BigInteger.ZERO.equals(s)||(o=o.add(this.z.square().multiply(s))),o=o.mod(this.curve.q);var a=o.square().subtract(e.shiftLeft(3).multiply(n)).shiftLeft(1).multiply(i).mod(this.curve.q),u=o.multiply(t).multiply(e).subtract(n.shiftLeft(1)).shiftLeft(2).multiply(n).subtract(o.square().multiply(o)).mod(this.curve.q),c=i.square().multiply(i).shiftLeft(3).mod(this.curve.q);return new f.PointFp(this.curve,this.curve.fromBigInteger(a),this.curve.fromBigInteger(u),c)},f.PointFp.prototype.multiply=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,r=t,i=r.multiply(new BigInteger("3")),n=this.negate(),s=this;for(e=i.bitLength()-2;e>0;--e){s=s.twice();var o=i.testBit(e),a=r.testBit(e);o!=a&&(s=s.add(o?this:n))}return s},f.PointFp.prototype.multiplyTwo=function(t,e,r){var i;i=t.bitLength()>r.bitLength()?t.bitLength()-1:r.bitLength()-1;for(var n=this.curve.getInfinity(),s=this.add(e);i>=0;)n=n.twice(),t.testBit(i)?n=r.testBit(i)?n.add(s):n.add(this):r.testBit(i)&&(n=n.add(e)),--i;return n},f.PointFp.prototype.getEncoded=function(t){var e=this.getX().toBigInteger(),r=this.getY().toBigInteger(),i=32,n=f.integerToBytes(e,i);return t?r.isEven()?n.unshift(2):n.unshift(3):(n.unshift(4),n=n.concat(f.integerToBytes(r,i))),n},f.PointFp.decodeFrom=function(t,e){e[0];var r=e.length-1,i=e.slice(1,1+r/2),n=e.slice(1+r/2,1+r);i.unshift(0),n.unshift(0);var s=new BigInteger(i),o=new BigInteger(n);return new f.PointFp(t,t.fromBigInteger(s),t.fromBigInteger(o))},f.PointFp.prototype.add2D=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;if(this.x.equals(t.x))return this.y.equals(t.y)?this.twice():this.curve.getInfinity();var e=t.x.subtract(this.x),r=t.y.subtract(this.y),i=r.divide(e),n=i.square().subtract(this.x).subtract(t.x),s=i.multiply(this.x.subtract(n)).subtract(this.y);return new f.PointFp(this.curve,n,s)},f.PointFp.prototype.twice2D=function(){if(this.isInfinity())return this;if(0==this.y.toBigInteger().signum())return this.curve.getInfinity();var t=this.curve.fromBigInteger(BigInteger.valueOf(2)),e=this.curve.fromBigInteger(BigInteger.valueOf(3)),r=this.x.square().multiply(e).add(this.curve.a).divide(this.y.multiply(t)),i=r.square().subtract(this.x.multiply(t)),n=r.multiply(this.x.subtract(i)).subtract(this.y);return new f.PointFp(this.curve,i,n)},f.PointFp.prototype.multiply2D=function(t){if(this.isInfinity())return this;if(0==t.signum())return this.curve.getInfinity();var e,r=t,i=r.multiply(new BigInteger("3")),n=this.negate(),s=this;for(e=i.bitLength()-2;e>0;--e){s=s.twice();var o=i.testBit(e),a=r.testBit(e);o!=a&&(s=s.add2D(o?this:n))}return s},f.PointFp.prototype.isOnCurve=function(){var t=this.getX().toBigInteger(),e=this.getY().toBigInteger(),r=this.curve.getA().toBigInteger(),i=this.curve.getB().toBigInteger(),n=this.curve.getQ(),s=e.multiply(e).mod(n),o=t.multiply(t).multiply(t).add(r.multiply(t)).add(i).mod(n);return s.equals(o)},f.PointFp.prototype.toString=function(){return"("+this.getX().toBigInteger().toString()+","+this.getY().toBigInteger().toString()+")"},f.PointFp.prototype.validate=function(){var t=this.curve.getQ();if(this.isInfinity())throw new Error("Point is at infinity.");var e=this.getX().toBigInteger(),r=this.getY().toBigInteger();if(e.compareTo(BigInteger.ONE)<0||e.compareTo(t.subtract(BigInteger.ONE))>0)throw new Error("x coordinate out of bounds");if(r.compareTo(BigInteger.ONE)<0||r.compareTo(t.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(t).isInfinity())throw new Error("Point is not a scalar multiple of G.");return!0},f.CurveFp=function(t,e,r){this.q=t,this.a=this.fromBigInteger(e),this.b=this.fromBigInteger(r),this.infinity=new f.PointFp(this,null,null),this.reducer=new Barrett(this.q)},f.CurveFp.prototype.getQ=function(){return this.q},f.CurveFp.prototype.getA=function(){return this.a},f.CurveFp.prototype.getB=function(){return this.b},f.CurveFp.prototype.equals=function(t){return t==this||this.q.equals(t.q)&&this.a.equals(t.a)&&this.b.equals(t.b)},f.CurveFp.prototype.getInfinity=function(){return this.infinity},f.CurveFp.prototype.fromBigInteger=function(t){return new f.FieldElementFp(this.q,t)},f.CurveFp.prototype.reduce=function(t){this.reducer.reduce(t)},f.CurveFp.prototype.decodePointHex=function(t){var e=parseInt(t.substr(0,2),16);switch(e){case 0:return this.infinity;case 2:case 3:var r=1&e,i=t.substr(2,t.length-2),n=new BigInteger(i,16);return this.decompressPoint(r,n);case 4:case 6:case 7:var s=(t.length-2)/2,o=(i=t.substr(2,s),t.substr(s+2,s));return new f.PointFp(this,this.fromBigInteger(new BigInteger(i,16)),this.fromBigInteger(new BigInteger(o,16)));default:return null}},f.CurveFp.prototype.encodePointHex=function(t){if(t.isInfinity())return"00";var e=t.getX().toBigInteger().toString(16),r=t.getY().toBigInteger().toString(16),i=this.getQ().toString(16).length;for(i%2!=0&&i++;e.length<i;)e="0"+e;for(;r.length<i;)r="0"+r;return"04"+e+r},f.CurveFp.prototype.decompressPoint=function(t,e){var r=this.fromBigInteger(e),i=r.multiply(r.square().add(this.getA())).add(this.getB()),n=i.sqrt();if(null==n)throw new Error("Invalid point compression");var s=n.toBigInteger(),o=s.testBit(0)?1:0;return o!=t&&(n=this.fromBigInteger(this.getQ().subtract(s))),new f.PointFp(this,r,n,null,!0)},f.fromHex=function(t){return new BigInteger(t,16)},f.integerToBytes=function(t,e){var r=t.toByteArrayUnsigned();if(e<r.length)r=r.slice(r.length-e);else for(;e>r.length;)r.unshift(0);return r},f.X9Parameters=function(t,e,r,i){this.curve=t,this.g=e,this.n=r,this.h=i},f.X9Parameters.prototype.getCurve=function(){return this.curve},f.X9Parameters.prototype.getG=function(){return this.g},f.X9Parameters.prototype.getN=function(){return this.n},f.X9Parameters.prototype.getH=function(){return this.h},f.secNamedCurves={secp256k1:function(){var t=f.fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F"),e=BigInteger.ZERO,r=f.fromHex("7"),i=f.fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"),n=BigInteger.ONE,s=new f.CurveFp(t,e,r),o=s.decodePointHex("0479BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8");return new f.X9Parameters(s,o,i,n)}},f.getSECCurveByName=function(t){return null==f.secNamedCurves[t]?null:f.secNamedCurves[t]()},function(){function e(t){for(var e=[],r=0,i=t.length;r<i;r++){var n=Number(t.charCodeAt(r)).toString(16);e.push(n)}return e.join("")}var r=t.bitjs=function(){};r.pub=35,r.priv=163,r.compressed=!1,r.privkey2wif=function(t){var e=Crypto.util.hexToBytes(t);1==r.compressed&&e.push(1),e.unshift(r.priv);var n=Crypto.SHA256(Crypto.SHA256(e,{asBytes:!0}),{asBytes:!0}),s=n.slice(0,4);return i.encode(e.concat(s))},r.wif2privkey=function(t){var e=!1,r=i.decode(t),n=r.slice(0,r.length-4);return n=n.slice(1,n.length),n.length>=33&&1==n[n.length-1]&&(n=n.slice(0,n.length-1),e=!0),{privkey:Crypto.util.bytesToHex(n),compressed:e}},r.wif2pubkey=function(t){var e=r.compressed,i=r.wif2privkey(t);r.compressed=i.compressed;var n=r.newPubkey(i.privkey);return r.compressed=e,{pubkey:n,compressed:i.compressed}},r.wif2address=function(t){var e=r.wif2pubkey(t);return{address:r.pubkey2address(e.pubkey),compressed:e.compressed}},r.newPubkey=function(t){var e=BigInteger.fromByteArrayUnsigned(Crypto.util.hexToBytes(t)),i=EllipticCurve.getSECCurveByName("secp256k1"),n=i.getG().multiply(e),s=n.getX().toBigInteger(),o=n.getY().toBigInteger(),a=EllipticCurve.integerToBytes(s,32);if(a=a.concat(EllipticCurve.integerToBytes(o,32)),a.unshift(4),1==r.compressed){var u=EllipticCurve.integerToBytes(s,32);return o.isEven()?u.unshift(2):u.unshift(3),Crypto.util.bytesToHex(u)}return Crypto.util.bytesToHex(a)},r.pubkey2address=function(t,e){var n=ripemd160(Crypto.SHA256(Crypto.util.hexToBytes(t),{asBytes:!0}));n.unshift(e||r.pub);var s=Crypto.SHA256(Crypto.SHA256(n,{asBytes:!0}),{asBytes:!0}),o=s.slice(0,4);return i.encode(n.concat(o))},r.transaction=function(){var t={version:2,inputs:[],outputs:[],locktime:0,floData:"",addinput:function(e,r,i,n){var s={};return s.outpoint={hash:e,index:r},s.script=Crypto.util.hexToBytes(i),s.sequence=n||(0==t.locktime?4294967295:0),this.inputs.push(s)},addoutput:function(e,r){var i={},n=[],s=t.addressDecode(e);return i.value=new BigInteger(""+Math.round(1*r*1e8),10),n.push(118),n.push(169),n.push(s.length),n=n.concat(s),n.push(136),n.push(172),i.script=n,this.outputs.push(i)},addflodata:function(t){return this.floData=t,this.floData},addressDecode:function(t){var e=i.decode(t),r=e.slice(0,e.length-4),n=e.slice(e.length-4),s=Crypto.SHA256(Crypto.SHA256(r,{asBytes:!0}),{asBytes:!0}).slice(0,4);if(s+""==n+"")return r.slice(1)},transactionHash:function(t,e){for(var i=r.clone(this),n=e||1,s=0;s<i.inputs.length;s++)t!=s&&(i.inputs[s].script=[]);if(i.inputs&&i.inputs[t]){if(1==n);else if(2==n){i.outputs=[];for(s=0;s<i.inputs.length;s++)t!=s&&(i.inputs[s].sequence=0)}else if(3==n){i.outputs.length=t+1;for(s=0;s<t;s++)i.outputs[s].value=-1,i.outputs[s].script=[];for(s=0;s<i.inputs.length;s++)t!=s&&(i.inputs[s].sequence=0)}else if(n>=128)if(i.inputs=[i.inputs[t]],129==n);else if(130==n)i.outputs=[];else if(131==n){i.outputs.length=t+1;for(s=0;s<t;s++)i.outputs[s].value=-1,i.outputs[s].script=[]}var o=Crypto.util.hexToBytes(i.serialize());o=o.concat(r.numToBytes(parseInt(n),4));var a=Crypto.SHA256(o,{asBytes:!0}),u=Crypto.util.bytesToHex(Crypto.SHA256(a,{asBytes:!0}));return u}return!1},transactionSig:function(t,e,i,n){function s(t,e){var r=t.toByteArraySigned(),i=e.toByteArraySigned(),n=[];return n.push(2),n.push(r.length),n=n.concat(r),n.push(2),n.push(i.length),n=n.concat(i),n.unshift(n.length),n.unshift(48),n}var o=i||1,a=n||Crypto.util.hexToBytes(this.transactionHash(t,o));if(a){var u=EllipticCurve.getSECCurveByName("secp256k1"),c=r.wif2privkey(e),h=BigInteger.fromByteArrayUnsigned(Crypto.util.hexToBytes(c.privkey)),f=u.getN(),p=BigInteger.fromByteArrayUnsigned(a),l=0;do{var y=this.deterministicK(e,a,l),d=u.getG(),g=d.multiply(y),v=g.getX().toBigInteger().mod(f),m=y.modInverse(f).multiply(p.add(h.multiply(v))).mod(f);l++}while(v.compareTo(BigInteger.ZERO)<=0||m.compareTo(BigInteger.ZERO)<=0);var b=f.shiftRight(1);m.compareTo(b)>0&&(m=f.subtract(m));var B=s(v,m);return B.push(parseInt(o,10)),Crypto.util.bytesToHex(B)}return!1},deterministicK:function(t,e,i){i=i||0;var n=r.wif2privkey(t),s=Crypto.util.hexToBytes(n.privkey),o=EllipticCurve.getSECCurveByName("secp256k1"),a=o.getN(),u=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];c=Crypto.HMAC(Crypto.SHA256,u.concat([0]).concat(s).concat(e),c,{asBytes:!0}),u=Crypto.HMAC(Crypto.SHA256,u,c,{asBytes:!0}),c=Crypto.HMAC(Crypto.SHA256,u.concat([1]).concat(s).concat(e),c,{asBytes:!0}),u=Crypto.HMAC(Crypto.SHA256,u,c,{asBytes:!0});var h=[];u=Crypto.HMAC(Crypto.SHA256,u,c,{asBytes:!0}),h=u;for(var f=BigInteger.fromByteArrayUnsigned(h),p=0;f.compareTo(a)>=0||f.compareTo(BigInteger.ZERO)<=0||p<i;)c=Crypto.HMAC(Crypto.SHA256,u.concat([0]),c,{asBytes:!0}),u=Crypto.HMAC(Crypto.SHA256,u,c,{asBytes:!0}),u=Crypto.HMAC(Crypto.SHA256,u,c,{asBytes:!0}),h=u,f=BigInteger.fromByteArrayUnsigned(h),p++;return f},signinput:function(t,e,i){var n=r.wif2pubkey(e),s=i||1,o=this.transactionSig(t,e,s),a=[],u=Crypto.util.hexToBytes(o);a.push(u.length),a=a.concat(u);var c=Crypto.util.hexToBytes(n.pubkey);return a.push(c.length),a=a.concat(c),this.inputs[t].script=a,!0},sign:function(t,e){for(var r=e||1,i=0;i<this.inputs.length;i++)this.signinput(i,t,r);return this.serialize()},serialize:function(){var t=[];t=t.concat(r.numToBytes(parseInt(this.version),4)),t=t.concat(r.numToVarInt(this.inputs.length));for(var i=0;i<this.inputs.length;i++){var n=this.inputs[i];t=t.concat(Crypto.util.hexToBytes(n.outpoint.hash).reverse()),t=t.concat(r.numToBytes(parseInt(n.outpoint.index),4));var s=n.script;t=t.concat(r.numToVarInt(s.length)),t=t.concat(s),t=t.concat(r.numToBytes(parseInt(n.sequence),4))}t=t.concat(r.numToVarInt(this.outputs.length));for(i=0;i<this.outputs.length;i++){var o=this.outputs[i];t=t.concat(r.numToBytes(o.value,8));s=o.script;t=t.concat(r.numToVarInt(s.length)),t=t.concat(s)}t=t.concat(r.numToBytes(parseInt(this.locktime),4));var a,u=e(this.floData),c=this.floData.length;if(c<16)a=c.toString(16),a="0"+a;else if(c<253)a=c.toString(16);else if(c<=1040){let t=c-253+parseInt("0xfd00fd"),e=t.toString(16);a=e.substr(0,2)+e.substr(4,2)+e.substr(2,2)}else a="Character Limit Exceeded";return Crypto.util.bytesToHex(t)+a+u}};return t},r.numToBytes=function(t,e){return void 0===e&&(e=8),0==e?[]:-1==t?Crypto.util.hexToBytes("ffffffffffffffff"):[t%256].concat(r.numToBytes(Math.floor(t/256),e-1))},r.numToByteArray=function(t){return t<=256?[t]:[t%256].concat(r.numToByteArray(Math.floor(t/256)))},r.numToVarInt=function(t){return t<253?[t]:t<65536?[253].concat(r.numToBytes(t,2)):t<4294967296?[254].concat(r.numToBytes(t,4)):[255].concat(r.numToBytes(t,8))},r.bytesToNum=function(t){return 0==t.length?0:t[0]+256*r.bytesToNum(t.slice(1))},r.clone=function(t){if(null==t||"object"!=typeof t)return t;var e=new t.constructor;for(var i in t)t.hasOwnProperty(i)&&(e[i]=r.clone(t[i]));return e};var i=r.Base58={alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",validRegex:/^[1-9A-HJ-NP-Za-km-z]+$/,base:BigInteger.valueOf(58),encode:function(t){for(var e=BigInteger.fromByteArrayUnsigned(t),r=[];e.compareTo(i.base)>=0;){var n=e.mod(i.base);r.unshift(i.alphabet[n.intValue()]),e=e.subtract(n).divide(i.base)}r.unshift(i.alphabet[e.intValue()]);for(var s=0;s<t.length&&0==t[s];s++)r.unshift(i.alphabet[0]);return r.join("")},decode:function(t){for(var e=BigInteger.valueOf(0),r=0,n=t.length-1;n>=0;n--){var s=i.alphabet.indexOf(t[n]);if(s<0)throw"Invalid character";e=e.add(BigInteger.valueOf(s).multiply(i.base.pow(t.length-1-n))),"1"==t[n]?r++:r=0}for(var o=e.toByteArrayUnsigned();r-- >0;)o.unshift(0);return o}}}(),y=t.Bitcoin={},d=y.Base58={alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",validRegex:/^[1-9A-HJ-NP-Za-km-z]+$/,base:BigInteger.valueOf(58),encode:function(t){for(var e=BigInteger.fromByteArrayUnsigned(t),r=[];e.compareTo(d.base)>=0;){var i=e.mod(d.base);r.unshift(d.alphabet[i.intValue()]),e=e.subtract(i).divide(d.base)}r.unshift(d.alphabet[e.intValue()]);for(var n=0;n<t.length&&0==t[n];n++)r.unshift(d.alphabet[0]);return r.join("")},decode:function(t){for(var e=BigInteger.valueOf(0),r=0,i=t.length-1;i>=0;i--){var n=d.alphabet.indexOf(t[i]);if(n<0)throw"Invalid character";e=e.add(BigInteger.valueOf(n).multiply(d.base.pow(t.length-1-i))),"1"==t[i]?r++:r=0}for(var s=e.toByteArrayUnsigned();r-- >0;)s.unshift(0);return s}},y.Address=function(e){"FLO"==t.cryptocoin?this.version=35:"FLO_TEST"==t.cryptocoin&&(this.version=115),"string"==typeof e&&(e=y.Address.decodeString(e,this.version)),this.hash=e},y.Address.networkVersion=35,y.Address.prototype.toString=function(t=null){var e=this.hash.slice(0);e.unshift(null!==t?t:this.version);var r=Crypto.SHA256(Crypto.SHA256(e,{asBytes:!0}),{asBytes:!0}),i=e.concat(r.slice(0,4));return y.Base58.encode(i)},y.Address.prototype.getHashBase64=function(){return Crypto.util.bytesToBase64(this.hash)},y.Address.decodeString=function(t,e){var r=y.Base58.decode(t),i=r.slice(0,21),n=Crypto.SHA256(Crypto.SHA256(i,{asBytes:!0}),{asBytes:!0});if(n[0]!=r[21]||n[1]!=r[22]||n[2]!=r[23]||n[3]!=r[24])throw"Checksum validation failed!";if(e!=i.shift())throw"Version "+i.shift()+" not supported!";return i},y.ECDSA=function(){function t(t,e,r,i){for(var n=Math.max(e.bitLength(),i.bitLength()),s=t.add2D(r),o=t.curve.getInfinity(),a=n-1;a>=0;--a)o=o.twice2D(),o.z=BigInteger.ONE,e.testBit(a)?o=i.testBit(a)?o.add2D(s):o.add2D(t):i.testBit(a)&&(o=o.add2D(r));return o}var e=EllipticCurve.getSECCurveByName("secp256k1"),r=new SecureRandom,i=null,n={getBigRandom:function(t){return new BigInteger(t.bitLength(),r).mod(t.subtract(BigInteger.ONE)).add(BigInteger.ONE)},sign:function(t,r){var i=r,s=e.getN(),o=BigInteger.fromByteArrayUnsigned(t);do{var a=n.getBigRandom(s),u=e.getG(),c=u.multiply(a),h=c.getX().toBigInteger().mod(s)}while(h.compareTo(BigInteger.ZERO)<=0);var f=a.modInverse(s).multiply(o.add(i.multiply(h))).mod(s);return n.serializeSig(h,f)},verify:function(t,r,i){var s,o,a;if(y.Util.isArray(r)){var u=n.parseSig(r);s=u.r,o=u.s}else{if("object"!=typeof r||!r.r||!r.s)throw"Invalid value for signature";s=r.r,o=r.s}if(i instanceof EllipticCurve.PointFp)a=i;else{if(!y.Util.isArray(i))throw"Invalid format for pubkey value, must be byte array or ec.PointFp";a=EllipticCurve.PointFp.decodeFrom(e.getCurve(),i)}var c=BigInteger.fromByteArrayUnsigned(t);return n.verifyRaw(c,s,o,a)},verifyRaw:function(t,r,i,n){var s=e.getN(),o=e.getG();if(r.compareTo(BigInteger.ONE)<0||r.compareTo(s)>=0)return!1;if(i.compareTo(BigInteger.ONE)<0||i.compareTo(s)>=0)return!1;var a=i.modInverse(s),u=t.multiply(a).mod(s),c=r.multiply(a).mod(s),h=o.multiply(u).add(n.multiply(c)),f=h.getX().toBigInteger().mod(s);return f.equals(r)},serializeSig:function(t,e){var r=t.toByteArraySigned(),i=e.toByteArraySigned(),n=[];return n.push(2),n.push(r.length),n=n.concat(r),n.push(2),n.push(i.length),n=n.concat(i),n.unshift(n.length),
|
|
n.unshift(48),n},parseSig:function(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(e=2,2!=t[e])throw new Error("First element in signature must be a DERInteger");var r=t.slice(e+2,e+2+t[e+1]);if(e+=2+t[e+1],2!=t[e])throw new Error("Second element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);e+=2+t[e+1];var n=BigInteger.fromByteArrayUnsigned(r),s=BigInteger.fromByteArrayUnsigned(i);return{r:n,s:s}},parseSigCompact:function(t){if(65!==t.length)throw"Signature has the wrong length";var r=t[0]-27;if(r<0||r>7)throw"Invalid signature type";var i=e.getN(),n=BigInteger.fromByteArrayUnsigned(t.slice(1,33)).mod(i),s=BigInteger.fromByteArrayUnsigned(t.slice(33,65)).mod(i);return{r:n,s:s,i:r}},recoverPubKey:function(r,s,o,a){a&=3;var u=1&a,c=a>>1,h=e.getN(),f=e.getG(),p=e.getCurve(),l=p.getQ(),d=p.getA().toBigInteger(),g=p.getB().toBigInteger();i||(i=l.add(BigInteger.ONE).divide(BigInteger.valueOf(4)));var v=c?r.add(h):r,m=v.multiply(v).multiply(v).add(d.multiply(v)).add(g).mod(l),b=m.modPow(i,l),B=(b.isEven(),(b.isEven()?!u:u)?b:l.subtract(b)),w=new EllipticCurve.PointFp(p,p.fromBigInteger(v),p.fromBigInteger(B));w.validate();var T=BigInteger.fromByteArrayUnsigned(o),C=BigInteger.ZERO.subtract(T).mod(h),S=r.modInverse(h),k=t(w,s,f,C).multiply(S);if(k.validate(),!n.verifyRaw(T,r,s,k))throw"Pubkey recovery unsuccessful";var I=new y.ECKey;return I.pub=k,I},calcPubkeyRecoveryParam:function(t,e,r,i){for(var n=0;n<4;n++)try{var s=y.ECDSA.recoverPubKey(e,r,i,n);if(s.getBitcoinAddress().toString()==t)return n}catch(t){}throw"Unable to find valid recovery factor"}};return n}(),y.KeyPool=(p=function(){return this.keyArray=[],this.push=function(t){if(null!=t&&null!=t.priv){var e=!0;for(var r in this.keyArray){var i=this.keyArray[r];if(null!=i&&null!=i.priv&&t.getBitcoinAddress()==i.getBitcoinAddress()){e=!1;break}}e&&this.keyArray.push(t)}},this.reset=function(){this.keyArray=[]},this.getArray=function(){return this.keyArray.slice(0)},this.setArray=function(t){this.keyArray=t},this.length=function(){return this.keyArray.length},this.toString=function(){var t="# = "+this.length()+"\n",e=this.getArray();for(var r in e){var i=e[r];y.Util.hasMethods(i,"getBitcoinAddress","toString")&&null!=i&&(t+='"'+i.getBitcoinAddress()+'", "'+i.toString("wif")+'"\n')}return t},this},new p),y.Bip38Key=(l=function(t,e){this.address=t,this.priv=e},l.prototype.getBitcoinAddress=function(){return this.address},l.prototype.toString=function(){return this.priv},l),y.ECKey=function(){var e=y.ECDSA,r=y.KeyPool,i=EllipticCurve.getSECCurveByName("secp256k1"),n=function(t){if(t){if(t instanceof BigInteger)this.priv=t;else if(y.Util.isArray(t))this.priv=BigInteger.fromByteArrayUnsigned(t);else if("string"==typeof t){var s=null;try{/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{52}$/.test(t)?(s=n.decodeCompressedWalletImportFormat(t),this.compressed=!0):n.isHexFormat(t)&&(s=Crypto.util.hexToBytes(t))}catch(t){this.setError(t)}n.isBase6Format(t)?this.priv=new BigInteger(t,6):null==s||32!=s.length?this.priv=null:this.priv=BigInteger.fromByteArrayUnsigned(s)}}else{var o=i.getN();this.priv=e.getBigRandom(o)}this.compressed=null==this.compressed?!!n.compressByDefault:this.compressed;try{null!=this.priv&&0==BigInteger.ZERO.compareTo(this.priv)&&this.setError("Error: BigInteger equal to zero.");var a="FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140",u=Crypto.util.hexToBytes(a),c=BigInteger.fromByteArrayUnsigned(u);null!=this.priv&&c.compareTo(this.priv)<0&&this.setError("Error: BigInteger outside of curve range."),null!=this.priv&&r.push(this)}catch(t){this.setError(t)}};return"FLO"==t.cryptocoin?n.privateKeyPrefix=163:"FLO_TEST"==t.cryptocoin&&(n.privateKeyPrefix=239),n.compressByDefault=!1,n.prototype.setError=function(t){return this.error=t,this.priv=null,this},n.prototype.setCompressed=function(t){return this.compressed=!!t,this.pubPoint&&(this.pubPoint.compressed=this.compressed),this},n.prototype.getPub=function(){return this.compressed?this.pubComp?this.pubComp:this.pubComp=this.getPubPoint().getEncoded(1):this.pubUncomp?this.pubUncomp:this.pubUncomp=this.getPubPoint().getEncoded(0)},n.prototype.getPubPoint=function(){return this.pubPoint||(this.pubPoint=i.getG().multiply(this.priv),this.pubPoint.compressed=this.compressed),this.pubPoint},n.prototype.getPubKeyHex=function(){return this.compressed?this.pubKeyHexComp?this.pubKeyHexComp:this.pubKeyHexComp=Crypto.util.bytesToHex(this.getPub()).toString().toUpperCase():this.pubKeyHexUncomp?this.pubKeyHexUncomp:this.pubKeyHexUncomp=Crypto.util.bytesToHex(this.getPub()).toString().toUpperCase()},n.prototype.getPubKeyHash=function(){return this.compressed?this.pubKeyHashComp?this.pubKeyHashComp:this.pubKeyHashComp=y.Util.sha256ripe160(this.getPub()):this.pubKeyHashUncomp?this.pubKeyHashUncomp:this.pubKeyHashUncomp=y.Util.sha256ripe160(this.getPub())},n.prototype.getBitcoinAddress=function(){var t=this.getPubKeyHash(),e=new y.Address(t);return e.toString()},n.prototype.setPub=function(t){y.Util.isArray(t)&&(t=Crypto.util.bytesToHex(t).toString().toUpperCase());var e=i.getCurve().decodePointHex(t);return this.setCompressed(e.compressed),this.pubPoint=e,this},n.prototype.getBitcoinWalletImportFormat=function(){var t=this.getBitcoinPrivateKeyByteArray();if(null==t)return"";t.unshift(n.privateKeyPrefix),this.compressed&&t.push(1);var e=Crypto.SHA256(Crypto.SHA256(t,{asBytes:!0}),{asBytes:!0});t=t.concat(e.slice(0,4));var r=y.Base58.encode(t);return r},n.prototype.getBitcoinHexFormat=function(){return Crypto.util.bytesToHex(this.getBitcoinPrivateKeyByteArray()).toString().toUpperCase()},n.prototype.getBitcoinBase64Format=function(){return Crypto.util.bytesToBase64(this.getBitcoinPrivateKeyByteArray())},n.prototype.getBitcoinPrivateKeyByteArray=function(){if(null==this.priv)return null;for(var t=this.priv.toByteArrayUnsigned();t.length<32;)t.unshift(0);return t},n.prototype.toString=function(t){return t=t||"","base64"==t.toString().toLowerCase()||"b64"==t.toString().toLowerCase()?this.getBitcoinBase64Format():"wif"==t.toString().toLowerCase()?this.getBitcoinWalletImportFormat():this.getBitcoinHexFormat()},n.prototype.sign=function(t){return e.sign(t,this.priv)},n.prototype.verify=function(t,r){return e.verify(t,r,this.getPub())},n.decodeWalletImportFormat=function(t){var e=y.Base58.decode(t),r=e.slice(0,33),i=Crypto.SHA256(Crypto.SHA256(r,{asBytes:!0}),{asBytes:!0});if(i[0]!=e[33]||i[1]!=e[34]||i[2]!=e[35]||i[3]!=e[36])throw"Checksum validation failed!";return r.shift(),r},n.decodeCompressedWalletImportFormat=function(t){var e=y.Base58.decode(t),r=e.slice(0,34),i=Crypto.SHA256(Crypto.SHA256(r,{asBytes:!0}),{asBytes:!0});if(i[0]!=e[34]||i[1]!=e[35]||i[2]!=e[36]||i[3]!=e[37])throw"Checksum validation failed!";return r.shift(),r.pop(),r},n.isHexFormat=function(t){return t=t.toString(),/^[A-Fa-f0-9]{64}$/.test(t)},n.isWalletImportFormat=function(t){return t=t.toString(),128==n.privateKeyPrefix?/^5[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{50}$/.test(t):/^R[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{50}$/.test(t)},n.isCompressedWalletImportFormat=function(t){return t=t.toString(),128==n.privateKeyPrefix?/^[LK][123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(t):/^R[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(t)},n.isBase64Format=function(t){return t=t.toString(),/^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789=+\/]{44}$/.test(t)},n.isBase6Format=function(t){return t=t.toString(),/^[012345]{99}$/.test(t)},n.isMiniFormat=function(t){t=t.toString();var e=/^S[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{21}$/.test(t),r=/^S[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{25}$/.test(t),i=/^S[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{29}$/.test(t),n=Crypto.SHA256(t+"?",{asBytes:!0});return(0===n[0]||1===n[0])&&(e||r||i)},n}(),y.Util={isArray:Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)},makeFilledArray:function(t,e){for(var r=[],i=0;i<t;)r[i++]=e;return r},numToVarInt:function(t){return t<253?[t]:t<=65536?[253,t>>>8,255&t]:t<=1?[254].concat(Crypto.util.wordsToBytes([t])):[255].concat(Crypto.util.wordsToBytes([t>>>32,t]))},valueToBigInt:function(t){return t instanceof BigInteger?t:BigInteger.fromByteArrayUnsigned(t)},formatValue:function(t){for(var e=this.valueToBigInt(t).toString(),r=e.length>8?e.substr(0,e.length-8):"0",i=e.length>8?e.substr(e.length-8):e;i.length<8;)i="0"+i;for(i=i.replace(/0*$/,"");i.length<2;)i+="0";return r+"."+i},parseValue:function(t){for(var e=t.split("."),r=e[0],i=e[1]||"0";i.length<8;)i+="0";i=i.replace(/^0+/g,"");var n=BigInteger.valueOf(parseInt(r));return n=n.multiply(BigInteger.valueOf(1e8)),n=n.add(BigInteger.valueOf(parseInt(i))),n},sha256ripe160:function(t){return ripemd160(Crypto.SHA256(t,{asBytes:!0}),{asBytes:!0})},dsha256:function(t){return Crypto.SHA256(Crypto.SHA256(t,{asBytes:!0}),{asBytes:!0})},hasMethods:function(t){for(var e,r=1;e=arguments[r++];)if("function"!=typeof t[e])return!1;return!0}},g="secp256k1",m=t.ellipticCurveEncryption=function(){},m.rng=new SecureRandom,m.getCurveParameters=function(t){t=void 0!==t?t:"secp256k1";var e=EllipticCurve.getSECCurveByName(t),r={Q:"",A:"",B:"",GX:"",GY:"",N:""};return r.Q=e.getCurve().getQ().toString(),r.A=e.getCurve().getA().toBigInteger().toString(),r.B=e.getCurve().getB().toBigInteger().toString(),r.GX=e.getG().getX().toBigInteger().toString(),r.GY=e.getG().getY().toBigInteger().toString(),r.N=e.getN().toString(),r},m.selectedCurve=m.getCurveParameters(g),m.get_curve=function(){return new EllipticCurve.CurveFp(new BigInteger(this.selectedCurve.Q),new BigInteger(this.selectedCurve.A),new BigInteger(this.selectedCurve.B))},m.get_G=function(t){return new EllipticCurve.PointFp(t,t.fromBigInteger(new BigInteger(this.selectedCurve.GX)),t.fromBigInteger(new BigInteger(this.selectedCurve.GY)))},m.pick_rand=function(){var t=new BigInteger(this.selectedCurve.N),e=t.subtract(BigInteger.ONE),r=new BigInteger(t.bitLength(),this.rng);return r.mod(e).add(BigInteger.ONE)},m.senderRandom=function(){var t=this.pick_rand();return t.toString()},m.receiverRandom=function(){var t=this.pick_rand();return t.toString()},m.senderPublicString=function(t){var e={},r=this.get_curve(),i=this.get_G(r),n=new BigInteger(t),s=i.multiply(n);return e.XValuePublicString=s.getX().toBigInteger().toString(),e.YValuePublicString=s.getY().toBigInteger().toString(),e},m.receiverPublicString=function(t){var e={},r=this.get_curve(),i=this.get_G(r),n=new BigInteger(t),s=i.multiply(n);return e.XValuePublicString=s.getX().toBigInteger().toString(),e.YValuePublicString=s.getY().toBigInteger().toString(),e},m.senderSharedKeyDerivation=function(t,e,r){var i={},n=this.get_curve(),s=new EllipticCurve.PointFp(n,n.fromBigInteger(new BigInteger(t)),n.fromBigInteger(new BigInteger(e))),o=new BigInteger(r),a=s.multiply(o);return i.XValue=a.getX().toBigInteger().toString(),i.YValue=a.getY().toBigInteger().toString(),i},m.receiverSharedKeyDerivation=function(t,e,r){var i={},n=this.get_curve(),s=new EllipticCurve.PointFp(n,n.fromBigInteger(new BigInteger(t)),n.fromBigInteger(new BigInteger(e))),o=new BigInteger(r),a=s.multiply(o);return i.XValue=a.getX().toBigInteger().toString(),i.YValue=a.getY().toBigInteger().toString(),i},function(){function e(t){throw t}function r(t,e){this.a=t,this.b=e}function i(t,e){var r,i=[],n=(1<<e)-1,s=t.length*e;for(r=0;r<s;r+=e)i[r>>>5]|=(t.charCodeAt(r/e)&n)<<32-e-r%32;return{value:i,binLen:s}}function n(t){var r,i,n=[],s=t.length;for(0!=s%2&&e("String of HEX type must be in byte increments"),r=0;r<s;r+=2)i=parseInt(t.substr(r,2),16),isNaN(i)&&e("String of HEX type contains invalid characters"),n[r>>>3]|=i<<24-r%8*4;return{value:n,binLen:4*s}}function s(t){var r,i,n,s,o,a=[],u=0;for(-1===t.search(/^[a-zA-Z0-9=+\/]+$/)&&e("Invalid character in base-64 string"),r=t.indexOf("="),t=t.replace(/\=/g,""),-1!==r&&r<t.length&&e("Invalid '=' found in base-64 string"),i=0;i<t.length;i+=4){for(o=t.substr(i,4),n=s=0;n<o.length;n+=1)r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(o[n]),s|=r<<18-6*n;for(n=0;n<o.length-1;n+=1)a[u>>2]|=(s>>>16-8*n&255)<<24-u%4*8,u+=1}return{value:a,binLen:8*u}}function o(t,e){var r,i,n="",s=4*t.length;for(r=0;r<s;r+=1)i=t[r>>>2]>>>8*(3-r%4),n+="0123456789abcdef".charAt(i>>>4&15)+"0123456789abcdef".charAt(15&i);return e.outputUpper?n.toUpperCase():n}function a(t,e){var r,i,n,s="",o=4*t.length;for(r=0;r<o;r+=3)for(n=(t[r>>>2]>>>8*(3-r%4)&255)<<16|(t[r+1>>>2]>>>8*(3-(r+1)%4)&255)<<8|t[r+2>>>2]>>>8*(3-(r+2)%4)&255,i=0;4>i;i+=1)s=8*r+6*i<=32*t.length?s+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(n>>>6*(3-i)&63):s+e.b64Pad;return s}function u(t){var r={outputUpper:!1,b64Pad:"="};try{t.hasOwnProperty("outputUpper")&&(r.outputUpper=t.outputUpper),t.hasOwnProperty("b64Pad")&&(r.b64Pad=t.b64Pad)}catch(t){}return"boolean"!=typeof r.outputUpper&&e("Invalid outputUpper formatting option"),"string"!=typeof r.b64Pad&&e("Invalid b64Pad formatting option"),r}function c(t,e){var i=w;i=new r(t.a,t.b);return 32>=e?new r(i.a>>>e|i.b<<32-e&4294967295,i.b>>>e|i.a<<32-e&4294967295):new r(i.b>>>e-32|i.a<<64-e&4294967295,i.a>>>e-32|i.b<<64-e&4294967295)}function h(t,e){return 32>=e?new r(t.a>>>e,t.b>>>e|t.a<<32-e&4294967295):new r(0,t.a>>>e-32)}function f(t,e,i){return new r(t.a&e.a^~t.a&i.a,t.b&e.b^~t.b&i.b)}function p(t,e,i){return new r(t.a&e.a^t.a&i.a^e.a&i.a,t.b&e.b^t.b&i.b^e.b&i.b)}function l(t){var e=c(t,28),i=c(t,34);return t=c(t,39),new r(e.a^i.a^t.a,e.b^i.b^t.b)}function y(t){var e=c(t,14),i=c(t,18);return t=c(t,41),new r(e.a^i.a^t.a,e.b^i.b^t.b)}function d(t){var e=c(t,1),i=c(t,8);return t=h(t,7),new r(e.a^i.a^t.a,e.b^i.b^t.b)}function g(t){var e=c(t,19),i=c(t,61);return t=h(t,6),new r(e.a^i.a^t.a,e.b^i.b^t.b)}function v(t,e){var i,n,s;return i=(65535&t.b)+(65535&e.b),n=(t.b>>>16)+(e.b>>>16)+(i>>>16),s=(65535&n)<<16|65535&i,i=(65535&t.a)+(65535&e.a)+(n>>>16),n=(t.a>>>16)+(e.a>>>16)+(i>>>16),new r((65535&n)<<16|65535&i,s)}function m(t,e,i,n){var s,o,a;return s=(65535&t.b)+(65535&e.b)+(65535&i.b)+(65535&n.b),o=(t.b>>>16)+(e.b>>>16)+(i.b>>>16)+(n.b>>>16)+(s>>>16),a=(65535&o)<<16|65535&s,s=(65535&t.a)+(65535&e.a)+(65535&i.a)+(65535&n.a)+(o>>>16),o=(t.a>>>16)+(e.a>>>16)+(i.a>>>16)+(n.a>>>16)+(s>>>16),new r((65535&o)<<16|65535&s,a)}function b(t,e,i,n,s){var o,a,u;return o=(65535&t.b)+(65535&e.b)+(65535&i.b)+(65535&n.b)+(65535&s.b),a=(t.b>>>16)+(e.b>>>16)+(i.b>>>16)+(n.b>>>16)+(s.b>>>16)+(o>>>16),u=(65535&a)<<16|65535&o,o=(65535&t.a)+(65535&e.a)+(65535&i.a)+(65535&n.a)+(65535&s.a)+(a>>>16),a=(t.a>>>16)+(e.a>>>16)+(i.a>>>16)+(n.a>>>16)+(s.a>>>16)+(o>>>16),new r((65535&a)<<16|65535&o,u)}function B(t,i,n){var s,o,a,u,c,h,B,w,T,C,S,k,I,F,A,x,E,H,P,_,O,N,D,q,M,R,U,z,L=[];for("SHA-384"===n||"SHA-512"===n?(S=80,s=31+(i+128>>>10<<5),F=32,A=2,M=r,x=v,E=m,H=b,P=d,_=g,O=l,N=y,q=p,D=f,R=[new M(1116352408,3609767458),new M(1899447441,602891725),new M(3049323471,3964484399),new M(3921009573,2173295548),new M(961987163,4081628472),new M(1508970993,3053834265),new M(2453635748,2937671579),new M(2870763221,3664609560),new M(3624381080,2734883394),new M(310598401,1164996542),new M(607225278,1323610764),new M(1426881987,3590304994),new M(1925078388,4068182383),new M(2162078206,991336113),new M(2614888103,633803317),new M(3248222580,3479774868),new M(3835390401,2666613458),new M(4022224774,944711139),new M(264347078,2341262773),new M(604807628,2007800933),new M(770255983,1495990901),new M(1249150122,1856431235),new M(1555081692,3175218132),new M(1996064986,2198950837),new M(2554220882,3999719339),new M(2821834349,766784016),new M(2952996808,2566594879),new M(3210313671,3203337956),new M(3336571891,1034457026),new M(3584528711,2466948901),new M(113926993,3758326383),new M(338241895,168717936),new M(666307205,1188179964),new M(773529912,1546045734),new M(1294757372,1522805485),new M(1396182291,2643833823),new M(1695183700,2343527390),new M(1986661051,1014477480),new M(2177026350,1206759142),new M(2456956037,344077627),new M(2730485921,1290863460),new M(2820302411,3158454273),new M(3259730800,3505952657),new M(3345764771,106217008),new M(3516065817,3606008344),new M(3600352804,1432725776),new M(4094571909,1467031594),new M(275423344,851169720),new M(430227734,3100823752),new M(506948616,1363258195),new M(659060556,3750685593),new M(883997877,3785050280),new M(958139571,3318307427),new M(1322822218,3812723403),new M(1537002063,2003034995),new M(1747873779,3602036899),new M(1955562222,1575990012),new M(2024104815,1125592928),new M(2227730452,2716904306),new M(2361852424,442776044),new M(2428436474,593698344),new M(2756734187,3733110249),new M(3204031479,2999351573),new M(3329325298,3815920427),new M(3391569614,3928383900),new M(3515267271,566280711),new M(3940187606,3454069534),new M(4118630271,4000239992),new M(116418474,1914138554),new M(174292421,2731055270),new M(289380356,3203993006),new M(460393269,320620315),new M(685471733,587496836),new M(852142971,1086792851),new M(1017036298,365543100),new M(1126000580,2618297676),new M(1288033470,3409855158),new M(1501505948,4234509866),new M(1607167915,987167468),new M(1816402316,1246189591)],C="SHA-384"===n?[new M(3418070365,3238371032),new M(1654270250,914150663),new M(2438529370,812702999),new M(355462360,4144912697),new M(1731405415,4290775857),new M(41048885895,1750603025),new M(3675008525,1694076839),new M(1203062813,3204075428)]:[new M(1779033703,4089235720),new M(3144134277,2227873595),new M(1013904242,4271175723),new M(2773480762,1595750129),new M(1359893119,2917565137),new M(2600822924,725511199),new M(528734635,4215389547),new M(1541459225,327033209)]):e("Unexpected error in SHA-2 implementation"),t[i>>>5]|=128<<24-i%32,t[s]=i,U=t.length,k=0;k<U;k+=F){for(i=C[0],s=C[1],o=C[2],a=C[3],u=C[4],c=C[5],h=C[6],B=C[7],I=0;I<S;I+=1)L[I]=16>I?new M(t[I*A+k],t[I*A+k+1]):E(_(L[I-2]),L[I-7],P(L[I-15]),L[I-16]),w=H(B,N(u),D(u,c,h),R[I],L[I]),T=x(O(i),q(i,s,o)),B=h,h=c,c=u,u=x(a,w),a=o,o=s,s=i,i=x(w,T);C[0]=x(i,C[0]),C[1]=x(s,C[1]),C[2]=x(o,C[2]),C[3]=x(a,C[3]),C[4]=x(u,C[4]),C[5]=x(c,C[5]),C[6]=x(h,C[6]),C[7]=x(B,C[7])}return"SHA-384"===n?z=[C[0].a,C[0].b,C[1].a,C[1].b,C[2].a,C[2].b,C[3].a,C[3].b,C[4].a,C[4].b,C[5].a,C[5].b]:"SHA-512"===n?z=[C[0].a,C[0].b,C[1].a,C[1].b,C[2].a,C[2].b,C[3].a,C[3].b,C[4].a,C[4].b,C[5].a,C[5].b,C[6].a,C[6].b,C[7].a,C[7].b]:e("Unexpected error in SHA-2 implementation"),z}var w=null;t.jsSHA=function(t,r,c){var h=w,f=w,p=0,l=[0],y=0,d=w;y=void 0!==c?c:8;8===y||16===y||e("charSize must be 8 or 16"),"HEX"===r?(0!=t.length%2&&e("srcString of HEX type must be in byte increments"),d=n(t),p=d.binLen,l=d.value):"ASCII"===r||"TEXT"===r?(d=i(t,y),p=d.binLen,l=d.value):"B64"===r?(d=s(t),p=d.binLen,l=d.value):e("inputFormat must be HEX, TEXT, ASCII, or B64"),this.getHash=function(t,r,i){var n=w,s=l.slice(),c="";switch(r){case"HEX":n=o;break;case"B64":n=a;break;default:e("format must be HEX or B64")}return"SHA-384"===t?(w===h&&(h=B(s,p,t)),c=n(h,u(i))):"SHA-512"===t?(w===f&&(f=B(s,p,t)),c=n(f,u(i))):e("Chosen SHA variant is not supported"),c},this.getHMAC=function(t,r,c,h,f){var d,g,v,m,b,T=[],C=[],S=w;switch(h){case"HEX":d=o;break;case"B64":d=a;break;default:e("outputFormat must be HEX or B64")}for("SHA-384"===c?(v=128,b=384):"SHA-512"===c?(v=128,b=512):e("Chosen SHA variant is not supported"),"HEX"===r?(S=n(t),m=S.binLen,g=S.value):"ASCII"===r||"TEXT"===r?(S=i(t,y),m=S.binLen,g=S.value):"B64"===r?(S=s(t),m=S.binLen,g=S.value):e("inputFormat must be HEX, TEXT, ASCII, or B64"),t=8*v,r=v/4-1,v<m/8?(g=B(g,m,c),g[r]&=4294967040):v>m/8&&(g[r]&=4294967040),v=0;v<=r;v+=1)T[v]=909522486^g[v],C[v]=1549556828^g[v];return c=B(C.concat(B(T.concat(l),t+p,c)),t+b,c),d(c,u(f))}}}(),function(){function e(t){return t>2147483647?5:t>8388607?4:t>32767?3:t>127?2:t>0?1:0}var r=t.coinjs=function(){};r.pub=0,r.priv=128,r.multisig=5,r.hdkey={prv:76066276,pub:76067358},r.bech32={charset:"qpzry9x8gf2tvdw0s3jn54khce6mua7l",version:0,hrp:"bc"},r.compressed=!1,r.developer="33tht1bKDgZVxb39MnZsWa8oxHXHvUYE4G",r.newKeys=function(t){var e=t?Crypto.SHA256(t):this.newPrivkey(),r=this.newPubkey(e);return{privkey:e,pubkey:r,address:this.pubkey2address(r),wif:this.privkey2wif(e),compressed:this.compressed}},r.newPrivkey=function(){var e=t.location;e+=t.screen.height*t.screen.width*t.screen.colorDepth,e+=r.random(64),e+=t.screen.availHeight*t.screen.availWidth*t.screen.pixelDepth,e+=navigator.language,e+=t.history.length,e+=r.random(64),e+=navigator.userAgent,e+="coinb.in",e+=Crypto.util.randomBytes(64).join(""),e+=e.length;var i=new Date;e+=i.getTimezoneOffset(),e+=r.random(64),e+=document.getElementById("entropybucket")?document.getElementById("entropybucket").innerHTML:"",e+=e+""+e;var n=e;for(let t=0;t<e.length/25;t++)n=Crypto.SHA256(n.concat(e));for(var s=new BigInteger(n),o=new BigInteger("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");s.compareTo(o)>=0||s.equals(BigInteger.ZERO)||s.equals(BigInteger.ONE);)n=Crypto.SHA256(n.concat(e)),s=new BigInteger(n);return n},r.newPubkey=function(t){var e=BigInteger.fromByteArrayUnsigned(Crypto.util.hexToBytes(t)),i=EllipticCurve.getSECCurveByName("secp256k1"),n=i.getG().multiply(e),s=n.getX().toBigInteger(),o=n.getY().toBigInteger(),a=EllipticCurve.integerToBytes(s,32);if(a=a.concat(EllipticCurve.integerToBytes(o,32)),a.unshift(4),1==r.compressed){var u=EllipticCurve.integerToBytes(s,32);return o.isEven()?u.unshift(2):u.unshift(3),Crypto.util.bytesToHex(u)}return Crypto.util.bytesToHex(a)},r.pubkey2address=function(t,e){var i=ripemd160(Crypto.SHA256(Crypto.util.hexToBytes(t),{asBytes:!0}));i.unshift(e||r.pub);var n=Crypto.SHA256(Crypto.SHA256(i,{asBytes:!0}),{asBytes:!0}),s=n.slice(0,4);return r.base58encode(i.concat(s))},r.scripthash2address=function(t){var e=Crypto.util.hexToBytes(t);e.unshift(r.pub);var i=e;i=Crypto.SHA256(Crypto.SHA256(i,{asBytes:!0}),{asBytes:!0});var n=i.slice(0,4);return r.base58encode(e.concat(n))},r.pubkeys2MultisigAddress=function(t,e){var i=r.script();i.writeOp(81+1*e-1);for(var n=0;n<t.length;++n)i.writeBytes(Crypto.util.hexToBytes(t[n]));i.writeOp(81+t.length-1),i.writeOp(174);var s=ripemd160(Crypto.SHA256(i.buffer,{asBytes:!0}),{asBytes:!0});s.unshift(r.multisig);var o=s;o=Crypto.SHA256(Crypto.SHA256(o,{asBytes:!0}),{asBytes:!0});var a=o.slice(0,4),u=Crypto.util.bytesToHex(i.buffer),c=r.base58encode(s.concat(a));return i.buffer.length>520&&(c="invalid",u="invalid"),{address:c,redeemScript:u,size:i.buffer.length}},r.simpleHodlAddress=function(t,e){if(e<0)throw"Parameter for OP_CHECKLOCKTIMEVERIFY is negative.";var i=r.script();e<=16&&e>=1?i.writeOp(80+e):i.writeBytes(r.numToScriptNumBytes(e)),i.writeOp(177),i.writeOp(117),i.writeBytes(Crypto.util.hexToBytes(t)),i.writeOp(172);var n=ripemd160(Crypto.SHA256(i.buffer,{asBytes:!0}),{asBytes:!0});n.unshift(r.multisig);var s=n;s=Crypto.SHA256(Crypto.SHA256(s,{asBytes:!0}),{asBytes:!0});var o=s.slice(0,4),a=Crypto.util.bytesToHex(i.buffer),u=r.base58encode(n.concat(o));return{address:u,redeemScript:a}},r.segwitAddress=function(t){var e=[0,20].concat(ripemd160(Crypto.SHA256(Crypto.util.hexToBytes(t),{asBytes:!0}),{asBytes:!0})),i=ripemd160(Crypto.SHA256(e,{asBytes:!0}),{asBytes:!0});i.unshift(r.multisig);var n=i;n=Crypto.SHA256(Crypto.SHA256(n,{asBytes:!0}),{asBytes:!0});var s=n.slice(0,4),o=r.base58encode(i.concat(s));return{address:o,type:"segwit",redeemscript:Crypto.util.bytesToHex(e)}},r.bech32Address=function(t){var e=ripemd160(Crypto.SHA256(Crypto.util.hexToBytes(t),{asBytes:!0}),{asBytes:!0}),i=r.bech32_encode(r.bech32.hrp,[r.bech32.version].concat(r.bech32_convert(e,8,5,!0)));return{address:i,type:"bech32",redeemscript:Crypto.util.bytesToHex(e)}},r.bech32redeemscript=function(t){var e=!1,i=r.bech32_decode(t);return i?(i.data.shift(),Crypto.util.bytesToHex(r.bech32_convert(i.data,5,8,!1))):e},r.privkey2wif=function(t){var e=Crypto.util.hexToBytes(t);1==r.compressed&&e.push(1),e.unshift(r.priv);var i=Crypto.SHA256(Crypto.SHA256(e,{asBytes:!0}),{asBytes:!0}),n=i.slice(0,4);return r.base58encode(e.concat(n))},r.wif2privkey=function(t){var e=!1,i=r.base58decode(t),n=i.slice(0,i.length-4);return n=n.slice(1,n.length),n.length>=33&&1==n[n.length-1]&&(n=n.slice(0,n.length-1),e=!0),{privkey:Crypto.util.bytesToHex(n),compressed:e}},r.wif2pubkey=function(t){var e=r.compressed,i=r.wif2privkey(t);r.compressed=i.compressed;var n=r.newPubkey(i.privkey);return r.compressed=e,{pubkey:n,compressed:i.compressed}},r.wif2address=function(t){var e=r.wif2pubkey(t);return{address:r.pubkey2address(e.pubkey),compressed:e.compressed}},r.addressDecode=function(t){try{var e=r.base58decode(t),i=e.slice(0,e.length-4),n=e.slice(e.length-4),s=Crypto.SHA256(Crypto.SHA256(i,{asBytes:!0}),{asBytes:!0}).slice(0,4);if(s+""==n+""){var o={};if(o.bytes=i.slice(1),o.version=i[0],o.version==r.pub)o.type="standard";else if(o.version==r.multisig)o.type="multisig";else if(o.version==r.priv)o.type="wifkey";else if(42==o.version){if(o.type="stealth",o.option=i[1],0!=o.option)return alert("Stealth Address option other than 0 is currently not supported!"),!1;if(o.scankey=Crypto.util.bytesToHex(i.slice(2,35)),o.n=i[35],o.n>1)return alert("Stealth Multisig is currently not supported!"),!1;if(o.spendkey=Crypto.util.bytesToHex(i.slice(36,69)),o.m=i[69],o.prefixlen=i[70],o.prefixlen>0)return alert("Stealth Address Prefixes are currently not supported!"),!1;o.prefix=i.slice(71)}else o.type="other";return o}throw"Invalid checksum"}catch(e){let i=r.bech32redeemscript(t);return!!i&&{type:"bech32",redeemscript:i}}},r.addressBalance=function(t,e){r.ajax(r.host+"?uid="+r.uid+"&key="+r.key+"&setmodule=addresses&request=bal&address="+t+"&r="+securedMathRandom(),e,"GET")},r.pubkeydecompress=function(t){if("string"==typeof t&&t.match(/^[a-f0-9]+$/i)){var e=EllipticCurve.getSECCurveByName("secp256k1");try{var r=e.curve.decodePointHex(t),i=r.getX().toBigInteger(),n=r.getY().toBigInteger(),s=EllipticCurve.integerToBytes(i,32);return s=s.concat(EllipticCurve.integerToBytes(n,32)),s.unshift(4),Crypto.util.bytesToHex(s)}catch(t){return!1}}return!1},r.bech32_polymod=function(t){for(var e=1,r=[996825010,642813549,513874426,1027748829,705979059],i=0;i<t.length;++i){var n=e>>25;e=(33554431&e)<<5^t[i];for(var s=0;s<5;++s)n>>s&1&&(e^=r[s])}return e},r.bech32_hrpExpand=function(t){var e,r=[];for(e=0;e<t.length;++e)r.push(t.charCodeAt(e)>>5);for(r.push(0),e=0;e<t.length;++e)r.push(31&t.charCodeAt(e));return r},r.bech32_verifyChecksum=function(t,e){return 1===r.bech32_polymod(r.bech32_hrpExpand(t).concat(e))},r.bech32_createChecksum=function(t,e){for(var i=r.bech32_hrpExpand(t).concat(e).concat([0,0,0,0,0,0]),n=1^r.bech32_polymod(i),s=[],o=0;o<6;++o)s.push(n>>5*(5-o)&31);return s},r.bech32_encode=function(t,e){for(var i=e.concat(r.bech32_createChecksum(t,e)),n=t+"1",s=0;s<i.length;++s)n+=r.bech32.charset.charAt(i[s]);return n},r.bech32_decode=function(t){var e,i=!1,n=!1;for(e=0;e<t.length;++e){if(t.charCodeAt(e)<33||t.charCodeAt(e)>126)return null;t.charCodeAt(e)>=97&&t.charCodeAt(e)<=122&&(i=!0),t.charCodeAt(e)>=65&&t.charCodeAt(e)<=90&&(n=!0)}if(i&&n)return null;t=t.toLowerCase();var s=t.lastIndexOf("1");if(s<1||s+7>t.length||t.length>90)return null;var o=t.substring(0,s),a=[];for(e=s+1;e<t.length;++e){var u=r.bech32.charset.indexOf(t.charAt(e));if(-1===u)return null;a.push(u)}return r.bech32_verifyChecksum(o,a)?{hrp:o,data:a.slice(0,a.length-6)}:null},r.bech32_convert=function(t,e,r,i){for(var n=0,s=0,o=(1<<r)-1,a=[],u=0;u<t.length;++u)for(n=n<<e|t[u],s+=e;s>=r;)s-=r,a.push(n>>s&o);if(i)s>0&&a.push(n<<r-s&o);else{if(s>=e)throw new Error("Excess padding");if(n<<r-s&o)throw new Error("Non-zero padding")}return a},r.testdeterministicK=function(){var t=r.transaction(),e=[{message:"test data",privkey:"fee0a1f7afebf9d2a5a80c0c98a31c709681cce195cbcd06342b517970c0be1e",k_bad00:"fcce1de7a9bcd6b2d3defade6afa1913fb9229e3b7ddf4749b55c4848b2a196e",k_bad01:"727fbcb59eb48b1d7d46f95a04991fc512eb9dbf9105628e3aec87428df28fd8",k_bad15:"398f0e2c9f79728f7b3d84d447ac3a86d8b2083c8f234a0ffa9c4043d68bd258"},{message:"Everything should be made as simple as possible, but not simpler.",privkey:"0000000000000000000000000000000000000000000000000000000000000001",k_bad00:"ec633bd56a5774a0940cb97e27a9e4e51dc94af737596a0c5cbb3d30332d92a5",k_bad01:"df55b6d1b5c48184622b0ead41a0e02bfa5ac3ebdb4c34701454e80aabf36f56",k_bad15:"def007a9a3c2f7c769c75da9d47f2af84075af95cadd1407393dc1e26086ef87"},{message:"Satoshi Nakamoto",privkey:"0000000000000000000000000000000000000000000000000000000000000002",k_bad00:"d3edc1b8224e953f6ee05c8bbf7ae228f461030e47caf97cde91430b4607405e",k_bad01:"f86d8e43c09a6a83953f0ab6d0af59fb7446b4660119902e9967067596b58374",k_bad15:"241d1f57d6cfd2f73b1ada7907b199951f95ef5ad362b13aed84009656e0254a"},{message:"Diffie Hellman",privkey:"7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f",k_bad00:"c378a41cb17dce12340788dd3503635f54f894c306d52f6e9bc4b8f18d27afcc",k_bad01:"90756c96fef41152ac9abe08819c4e95f16da2af472880192c69a2b7bac29114",k_bad15:"7b3f53300ab0ccd0f698f4d67db87c44cf3e9e513d9df61137256652b2e94e7c"},{message:"Japan",privkey:"8080808080808080808080808080808080808080808080808080808080808080",k_bad00:"f471e61b51d2d8db78f3dae19d973616f57cdc54caaa81c269394b8c34edcf59",k_bad01:"6819d85b9730acc876fdf59e162bf309e9f63dd35550edf20869d23c2f3e6d17",k_bad15:"d8e8bae3ee330a198d1f5e00ad7c5f9ed7c24c357c0a004322abca5d9cd17847"},{message:"Bitcoin",privkey:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",k_bad00:"36c848ffb2cbecc5422c33a994955b807665317c1ce2a0f59c689321aaa631cc",k_bad01:"4ed8de1ec952a4f5b3bd79d1ff96446bcd45cabb00fc6ca127183e14671bcb85",k_bad15:"56b6f47babc1662c011d3b1f93aa51a6e9b5f6512e9f2e16821a238d450a31f8"},{message:"i2FLPP8WEus5WPjpoHwheXOMSobUJVaZM1JPMQZq",privkey:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",k_bad00:"6e9b434fcc6bbb081a0463c094356b47d62d7efae7da9c518ed7bac23f4e2ed6",k_bad01:"ae5323ae338d6117ce8520a43b92eacd2ea1312ae514d53d8e34010154c593bb",k_bad15:"3eaa1b61d1b8ab2f1ca71219c399f2b8b3defa624719f1e96fe3957628c2c4ea"},{message:"lEE55EJNP7aLrMtjkeJKKux4Yg0E8E1SAJnWTCEh",privkey:"3881e5286abc580bb6139fe8e83d7c8271c6fe5e5c2d640c1f0ed0e1ee37edc9",k_bad00:"5b606665a16da29cc1c5411d744ab554640479dd8abd3c04ff23bd6b302e7034",k_bad01:"f8b25263152c042807c992eacd2ac2cc5790d1e9957c394f77ea368e3d9923bd",k_bad15:"ea624578f7e7964ac1d84adb5b5087dd14f0ee78b49072aa19051cc15dab6f33"},{message:"2SaVPvhxkAPrayIVKcsoQO5DKA8Uv5X/esZFlf+y",privkey:"7259dff07922de7f9c4c5720d68c9745e230b32508c497dd24cb95ef18856631",k_bad00:"3ab6c19ab5d3aea6aa0c6da37516b1d6e28e3985019b3adb388714e8f536686b",k_bad01:"19af21b05004b0ce9cdca82458a371a9d2cf0dc35a813108c557b551c08eb52e",k_bad15:"117a32665fca1b7137a91c4739ac5719fec0cf2e146f40f8e7c21b45a07ebc6a"},{message:"00A0OwO2THi7j5Z/jp0FmN6nn7N/DQd6eBnCS+/b",privkey:"0d6ea45d62b334777d6995052965c795a4f8506044b4fd7dc59c15656a28f7aa",k_bad00:"79487de0c8799158294d94c0eb92ee4b567e4dc7ca18addc86e49d31ce1d2db6",k_bad01:"9561d2401164a48a8f600882753b3105ebdd35e2358f4f808c4f549c91490009",k_bad15:"b0d273634129ff4dbdf0df317d4062a1dbc58818f88878ffdb4ec511c77976c0"}],n="\n----------------------\nResults\n----------------------\n\n";for(i=0;i<e.length;i++){var s=Crypto.SHA256(e[i].message.split("").map(function(t){return t.charCodeAt(0)}),{asBytes:!0}),o=r.privkey2wif(e[i].privkey),a=t.deterministicK(o,s),u=t.deterministicK(o,s,0),c=t.deterministicK(o,s,1),h=t.deterministicK(o,s,15),f=Crypto.util.bytesToHex(a.toByteArrayUnsigned()),p=Crypto.util.bytesToHex(u.toByteArrayUnsigned()),l=Crypto.util.bytesToHex(c.toByteArrayUnsigned()),y=Crypto.util.bytesToHex(h.toByteArrayUnsigned())
|
|
;f!=e[i].k_bad00?n+="Failed Test #"+(i+1)+"\n K = "+f+"\nExpected = "+e[i].k_bad00+"\n\n":p!=e[i].k_bad00?n+="Failed Test #"+(i+1)+"\n K0 = "+p+"\nExpected = "+e[i].k_bad00+"\n\n":l!=e[i].k_bad01?n+="Failed Test #"+(i+1)+"\n K1 = "+l+"\nExpected = "+e[i].k_bad01+"\n\n":y!=e[i].k_bad15&&(n+="Failed Test #"+(i+1)+"\n K15 = "+y+"\nExpected = "+e[i].k_bad15+"\n\n")}return n.length<60&&(n="All Tests OK!"),n},r.hd=function(t){var e={parse:function(){var i=[];if("string"==typeof t){var n=r.base58decode(t);if(82==n.length){var s=n.slice(78,82),o=Crypto.SHA256(Crypto.SHA256(n.slice(0,78),{asBytes:!0}),{asBytes:!0});s[0]==o[0]&&s[1]==o[1]&&s[2]==o[2]&&s[3]==o[3]&&(i=n.slice(0,78))}}if(i&&i.length>0){e.version=r.uint(i.slice(0,4),4),e.depth=r.uint(i.slice(4,5),1),e.parent_fingerprint=i.slice(5,9),e.child_index=r.uint(i.slice(9,13),4),e.chain_code=i.slice(13,45),e.key_bytes=i.slice(45,78);var a=r.compressed;if(r.compressed=!0,0==e.key_bytes[0]){e.type="private";var u=e.key_bytes.slice(1,33),c=Crypto.util.bytesToHex(u),h=r.newPubkey(c);e.keys={privkey:c,pubkey:h,address:r.pubkey2address(h),wif:r.privkey2wif(c)}}else if(2==e.key_bytes[0]||3==e.key_bytes[0]){e.type="public";var f=Crypto.util.bytesToHex(e.key_bytes);e.keys={pubkey:f,address:r.pubkey2address(f)}}else e.type="invalid";e.keys_extended=e.extend(),r.compressed=a}return e},extend:function(){var t=r.hd();return t.make({depth:1*this.depth+1,parent_fingerprint:this.parent_fingerprint,child_index:this.child_index,chain_code:this.chain_code,privkey:this.keys.privkey,pubkey:this.keys.pubkey})},derive_path:function(t){if("m"==t||"M"==t||"m'"==t||"M'"==t)return this;var e=t.split("/"),i=r.clone(this);for(var n in e)if((0!=n||"m"==s)&&"remove"!=n){var s=e[n],o=s.length>1&&"'"==s[s.length-1],a=2147483647&parseInt(o?s.slice(0,s.length-1):s);o&&(a+=2147483648),i=i.derive(a);var u=i.keys_extended.privkey&&""!=i.keys_extended.privkey?i.keys_extended.privkey:i.keys_extended.pubkey;i=r.hd(u)}return i},derive:function(t){t=t||0;var i,n,s,o,a=Crypto.util.hexToBytes(this.keys.pubkey).concat(r.numToBytes(t,4).reverse()),u=new jsSHA(Crypto.util.bytesToHex(a),"HEX"),c=u.getHMAC(Crypto.util.bytesToHex(e.chain_code),"HEX","SHA-512","HEX"),h=new BigInteger(c.slice(0,64),16),f=Crypto.util.hexToBytes(c.slice(64,128)),p=EllipticCurve.getSECCurveByName("secp256k1");p.getCurve();if(o=r.clone(this),o.chain_code=f,o.child_index=t,"private"==this.type)i=h.add(new BigInteger([0].concat(Crypto.util.hexToBytes(this.keys.privkey)))).mod(p.getN()),n=Crypto.util.bytesToHex(i.toByteArrayUnsigned()),s=r.newPubkey(n),o.keys={privkey:n,pubkey:s,wif:r.privkey2wif(n),address:r.pubkey2address(s)};else if("public"==this.type){q=p.curve.decodePointHex(this.keys.pubkey);var l=p.getG().multiply(h).add(q),y=l.getX().toBigInteger(),d=l.getY().toBigInteger(),g=EllipticCurve.integerToBytes(y,32);d.isEven()?g.unshift(2):g.unshift(3),s=Crypto.util.bytesToHex(g),o.keys={pubkey:s,address:r.pubkey2address(s)}}return o.parent_fingerprint=ripemd160(Crypto.SHA256(Crypto.util.hexToBytes(e.keys.pubkey),{asBytes:!0}),{asBytes:!0}).slice(0,4),o.keys_extended=o.extend(),o},master:function(t){var e=t?Crypto.SHA256(t):r.newPrivkey(),i=new jsSHA(e,"HEX"),n=i.getHMAC("Bitcoin seed","TEXT","SHA-512","HEX"),s=(Crypto.util.hexToBytes(n.slice(0,64)),Crypto.util.hexToBytes(n.slice(64,128))),o=r.hd();return o.make({depth:0,parent_fingerprint:[0,0,0,0],child_index:0,chain_code:s,privkey:n.slice(0,64),pubkey:r.newPubkey(n.slice(0,64))})},make:function(t){var e=[];e.push(1*t.depth),e=e.concat(t.parent_fingerprint),e=e.concat(r.numToBytes(t.child_index,4).reverse()),e=e.concat(t.chain_code);var i={};if(t.privkey){var n=r.numToBytes(r.hdkey.prv,4).reverse();n=n.concat(e),n.push(0),n=n.concat(Crypto.util.hexToBytes(t.privkey));var s=Crypto.SHA256(Crypto.SHA256(n,{asBytes:!0}),{asBytes:!0}),o=s.slice(0,4),a=n.concat(o);i.privkey=r.base58encode(a)}if(t.pubkey){var u=r.numToBytes(r.hdkey.pub,4).reverse();u=u.concat(e),u=u.concat(Crypto.util.hexToBytes(t.pubkey));s=Crypto.SHA256(Crypto.SHA256(u,{asBytes:!0}),{asBytes:!0}),o=s.slice(0,4),a=u.concat(o);i.pubkey=r.base58encode(a)}return i}};return e.parse()},r.script=function(t){var e={};return t?"string"==typeof t?e.buffer=Crypto.util.hexToBytes(t):r.isArray(t)?e.buffer=t:t instanceof r.script?e.buffer=t.buffer:e.buffer=t:e.buffer=[],e.parse=function(){function t(t){r.chunks.push(r.buffer.slice(i,i+t)),i+=t}var r=this;e.chunks=[];for(var i=0;i<this.buffer.length;){var n,s=this.buffer[i++];if(s>=240&&(s=s<<8|this.buffer[i++]),s>0&&s<76?t(s):76==s?(n=this.buffer[i++],t(n)):77==s?(n=this.buffer[i++]<<8|this.buffer[i++],t(n)):78==s?(n=this.buffer[i++]<<24|this.buffer[i++]<<16|this.buffer[i++]<<8|this.buffer[i++],t(n)):this.chunks.push(s),i<0)break}return!0},e.decodeRedeemScript=function(t){var e=!1;try{var i=r.script(Crypto.util.hexToBytes(t));if(i.chunks.length>=3&&174==i.chunks[i.chunks.length-1]){e={},e.signaturesRequired=i.chunks[0]-80;for(var n=[],s=1;s<i.chunks.length-2;s++)n.push(Crypto.util.bytesToHex(i.chunks[s]));e.pubkeys=n;var o=r.pubkeys2MultisigAddress(n,e.signaturesRequired);e.address=o.address,e.type="multisig__";var a=Crypto.util.bytesToHex(i.buffer);e.redeemscript=a}else if(2==i.chunks.length&&0==i.buffer[0]&&20==i.buffer[1]){e={},e.type="segwit__";a=Crypto.util.bytesToHex(i.buffer);e.address=r.pubkey2address(a,r.multisig),e.redeemscript=a}else if(5==i.chunks.length&&177==i.chunks[1]&&117==i.chunks[2]&&172==i.chunks[4]){e={},e.pubkey=Crypto.util.bytesToHex(i.chunks[3]),e.checklocktimeverify=r.bytesToNum(i.chunks[0].slice()),e.address=r.simpleHodlAddress(e.pubkey,e.checklocktimeverify).address;a=Crypto.util.bytesToHex(i.buffer);e.redeemscript=a,e.type="hodl__"}}catch(t){e=!1}return e},e.spendToScript=function(t){var e=r.addressDecode(t),i=r.script();return"bech32"==e.type?(i.writeOp(0),i.writeBytes(Crypto.util.hexToBytes(e.redeemscript))):e.version==r.multisig?(i.writeOp(169),i.writeBytes(e.bytes),i.writeOp(135)):(i.writeOp(118),i.writeOp(169),i.writeBytes(e.bytes),i.writeOp(136),i.writeOp(172)),i},e.pubkeyHash=function(t){var e=r.addressDecode(t),i=r.script();return i.writeOp(118),i.writeOp(169),i.writeBytes(e.bytes),i.writeOp(136),i.writeOp(172),i},e.writeOp=function(t){return this.buffer.push(t),this.chunks.push(t),!0},e.writeBytes=function(t){return t.length<76?this.buffer.push(t.length):t.length<=255?(this.buffer.push(76),this.buffer.push(t.length)):t.length<=65535?(this.buffer.push(77),this.buffer.push(255&t.length),this.buffer.push(t.length>>>8&255)):(this.buffer.push(78),this.buffer.push(255&t.length),this.buffer.push(t.length>>>8&255),this.buffer.push(t.length>>>16&255),this.buffer.push(t.length>>>24&255)),this.buffer=this.buffer.concat(t),this.chunks.push(t),!0},e.parse(),e},r.transaction=function(){var e={version:1,lock_time:0,ins:[],outs:[],witness:!1,timestamp:null,block:null,addinput:function(t,i,n,s){var o={};return o.outpoint={hash:t,index:i},o.script=r.script(n||[]),o.sequence=s||(0==e.lock_time?4294967295:0),this.ins.push(o)},addoutput:function(t,e){var i={};i.value=new BigInteger(""+Math.round(1*e*1e8),10);var n=r.script();return i.script=n.spendToScript(t),this.outs.push(i)},addstealth:function(t,e){var i=BigInteger.fromByteArrayUnsigned(Crypto.util.hexToBytes(r.newPrivkey())),n=EllipticCurve.getSECCurveByName("secp256k1"),s=EllipticCurve.fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F"),o=BigInteger.ZERO,a=EllipticCurve.fromHex("7"),u=new EllipticCurve.CurveFp(s,o,a),c=n.getG().multiply(i),h=u.decodePointHex(t.scankey),f=h.multiply(i),p=BigInteger.fromByteArrayUnsigned(Crypto.SHA256(f.getEncoded(!0),{asBytes:!0})),l=n.getG().multiply(p),y=u.decodePointHex(t.spendkey),d=y.add(l),g=r.pubkey2address(Crypto.util.bytesToHex(d.getEncoded(!0))),m=[6].concat(Crypto.util.randomBytes(4)).concat(c.getEncoded(!0)),b=r.script();b.writeOp(106),b.writeBytes(m),v={},v.value=0,v.script=b,this.outs.push(v);var B={};B.value=new BigInteger(""+Math.round(1*e*1e8),10);var w=r.script();return B.script=w.spendToScript(g),this.outs.push(B)},adddata:function(t){var e=!1;if(t.match(/^[a-f0-9]+$/gi)&&t.length<160&&t.length%2==0){var i=r.script();return i.writeOp(106),i.writeBytes(Crypto.util.hexToBytes(t)),o={},o.value=0,o.script=i,this.outs.push(o)}return e},listUnspent:function(t,e){r.ajax(r.host+"?uid="+r.uid+"&key="+r.key+"&setmodule=addresses&request=unspent&address="+t+"&r="+securedMathRandom(),e,"GET")},getTransaction:function(t,e){r.ajax(r.host+"?uid="+r.uid+"&key="+r.key+"&setmodule=bitcoin&request=gettransaction&txid="+t+"&r="+securedMathRandom(),e,"GET")},addUnspent:function(e,n,s,o,a){var u=this;this.listUnspent(e,function(e){var c=r.script(),h=0,f=0,p={};t.DOMParser?(parser=new DOMParser,xmlDoc=parser.parseFromString(e,"text/xml")):(xmlDoc=new ActiveXObject("Microsoft.XMLDOM"),xmlDoc.async=!1,xmlDoc.loadXML(e));var l=xmlDoc.getElementsByTagName("unspent")[0];if(l)for(i=1;i<=l.childElementCount;i++){var y=xmlDoc.getElementsByTagName("unspent_"+i)[0],d=y.getElementsByTagName("tx_hash")[0].childNodes[0].nodeValue.match(/.{1,2}/g).reverse().join("")+"",g=y.getElementsByTagName("tx_output_n")[0].childNodes[0].nodeValue,v=s||y.getElementsByTagName("script")[0].childNodes[0].nodeValue;o&&(c=r.script(),c.writeBytes(Crypto.util.hexToBytes(s)),c.writeOp(0),c.writeBytes(r.numToBytes(1*y.getElementsByTagName("value")[0].childNodes[0].nodeValue,8)),v=Crypto.util.bytesToHex(c.buffer));var m=a||!1;u.addinput(d,g,v,m),h+=1*y.getElementsByTagName("value")[0].childNodes[0].nodeValue,f++}return p.result=xmlDoc.getElementsByTagName("result")[0].childNodes[0].nodeValue,p.unspent=l,p.value=h,p.total=f,p.response=xmlDoc.getElementsByTagName("response")[0].childNodes[0].nodeValue,n(p)})},addUnspentAndSign:function(t,e){var i=this,n=r.wif2address(t);i.addUnspent(n.address,function(r){return i.sign(t),e(r)})},broadcast:function(t,e){var i=e||this.serialize();r.ajax(r.host+"?uid="+r.uid+"&key="+r.key+"&setmodule=bitcoin&request=sendrawtransaction",t,"POST",["rawtx="+i])},transactionHash:function(t,e){for(var i=r.clone(this),n=e||1,s=0;s<i.ins.length;s++)t!=s&&(i.ins[s].script=r.script());var o=this.extractScriptKey(t);if(i.ins[t].script=r.script(o.script),i.ins&&i.ins[t]){if(1==n);else if(2==n){i.outs=[];for(s=0;s<i.ins.length;s++)t!=s&&(i.ins[s].sequence=0)}else if(3==n){i.outs.length=t+1;for(s=0;s<t;s++)i.outs[s].value=-1,i.outs[s].script.buffer=[];for(s=0;s<i.ins.length;s++)t!=s&&(i.ins[s].sequence=0)}else if(n>=128)if(i.ins=[i.ins[t]],129==n);else if(130==n)i.outs=[];else if(131==n){i.outs.length=t+1;for(s=0;s<t;s++)i.outs[s].value=-1,i.outs[s].script.buffer=[]}var a=Crypto.util.hexToBytes(i.serialize());a=a.concat(r.numToBytes(parseInt(n),4));var u=Crypto.SHA256(a,{asBytes:!0}),c=Crypto.util.bytesToHex(Crypto.SHA256(u,{asBytes:!0}));return c}return!1},transactionHashSegWitV0:function(t,e){var i=this.extractScriptKey(t);if("segwit"!=i.type)return{result:0,fail:"redeemscript",response:"redeemscript missing or not valid for segwit"};if(-1==i.value)return{result:0,fail:"value",response:"unable to generate a valid segwit hash without a value"};var n=Crypto.util.hexToBytes(i.script);20==n.length&&(n=[0,20].concat(n)),22==n.length&&(n=n.slice(1),n.unshift(25,118,169),n.push(136,172));var s=r.numToBytes(i.value,8),o=r.numToBytes(0,32),a=r.numToBytes(parseInt(this.version),4),u=[];if(!(e>=80))for(var c=0;c<this.ins.length;c++)u=u.concat(Crypto.util.hexToBytes(this.ins[c].outpoint.hash).reverse()),u=u.concat(r.numToBytes(this.ins[c].outpoint.index,4));var h=u.length>=1?Crypto.SHA256(Crypto.SHA256(u,{asBytes:!0}),{asBytes:!0}):o;u=[];if(!(e>=80)&&2!=e&&3!=e)for(c=0;c<this.ins.length;c++)u=u.concat(r.numToBytes(this.ins[c].sequence,4));var f=u.length>=1?Crypto.SHA256(Crypto.SHA256(u,{asBytes:!0}),{asBytes:!0}):o,p=Crypto.util.hexToBytes(this.ins[t].outpoint.hash).reverse();p=p.concat(r.numToBytes(this.ins[t].outpoint.index,4));var l=r.numToBytes(this.ins[t].sequence,4),y=o;u=[];if(2!=e&&3!=e){for(c=0;c<this.outs.length;c++)u=u.concat(r.numToBytes(this.outs[c].value,8)),u=u.concat(r.numToVarInt(this.outs[c].script.buffer.length)),u=u.concat(this.outs[c].script.buffer);y=Crypto.SHA256(Crypto.SHA256(u,{asBytes:!0}),{asBytes:!0})}else 2==e&&t<this.outs.length&&(u=u.concat(r.numToBytes(this.outs[t].value,8)),u=u.concat(r.numToVarInt(this.outs[c].script.buffer.length)),u=u.concat(this.outs[t].script.buffer),y=Crypto.SHA256(Crypto.SHA256(u,{asBytes:!0}),{asBytes:!0}));var d=r.numToBytes(this.lock_time,4),g=r.numToBytes(e,4),v=[];v=v.concat(a),v=v.concat(h),v=v.concat(f),v=v.concat(p),v=v.concat(n),v=v.concat(s),v=v.concat(l),v=v.concat(y),v=v.concat(d),v=v.concat(g);var m=Crypto.SHA256(v,{asBytes:!0});return{result:1,hash:Crypto.util.bytesToHex(Crypto.SHA256(m,{asBytes:!0})),response:"hash generated"}},extractScriptKey:function(t){if(this.ins[t]){if(5==this.ins[t].script.chunks.length&&172==this.ins[t].script.chunks[4]&&r.isArray(this.ins[t].script.chunks[2]))return{type:"scriptpubkey",signed:"false",signatures:0,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)};if(2==this.ins[t].script.chunks.length&&48==this.ins[t].script.chunks[0][0]&&5==this.ins[t].script.chunks[1].length&&177==this.ins[t].script.chunks[1][1])return{type:"hodl",signed:"true",signatures:1,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)};if(2==this.ins[t].script.chunks.length&&48==this.ins[t].script.chunks[0][0])return{type:"scriptpubkey",signed:"true",signatures:1,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)};if(5==this.ins[t].script.chunks.length&&177==this.ins[t].script.chunks[1])return{type:"hodl",signed:"false",signatures:0,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)};if(this.ins[t].script.chunks.length<=3&&this.ins[t].script.chunks.length>0&&(22==this.ins[t].script.chunks[0].length&&0==this.ins[t].script.chunks[0][0]||20==this.ins[t].script.chunks[0].length&&0==this.ins[t].script.chunks[1])){var e=this.witness[t]&&2==this.witness[t].length?"true":"false",i="true"==e?1:0,n=-1;return this.ins[t].script.chunks[2]&&8==this.ins[t].script.chunks[2].length&&(n=r.bytesToNum(this.ins[t].script.chunks[2])),{type:"segwit",signed:e,signatures:i,script:Crypto.util.bytesToHex(this.ins[t].script.chunks[0]),value:n}}if(0==this.ins[t].script.chunks[0]&&174==this.ins[t].script.chunks[this.ins[t].script.chunks.length-1][this.ins[t].script.chunks[this.ins[t].script.chunks.length-1].length-1]){var s=0;for(let e=1;e<this.ins[t].script.chunks.length-1;e++)0!=this.ins[t].script.chunks[e]&&s++;return{type:"multisig",signed:"true",signatures:s,script:Crypto.util.bytesToHex(this.ins[t].script.chunks[this.ins[t].script.chunks.length-1])}}if(this.ins[t].script.chunks[0]>=80&&174==this.ins[t].script.chunks[this.ins[t].script.chunks.length-1])return{type:"multisig",signed:"false",signatures:0,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)};if(0==this.ins[t].script.chunks.length){e=this.witness[t]&&2==this.witness[t].length?"true":"false",i="true"==e?1:0;return{type:"empty",signed:e,signatures:i,script:""}}return{type:"unknown",signed:"false",signatures:0,script:Crypto.util.bytesToHex(this.ins[t].script.buffer)}}return!1},transactionSig:function(t,e,i,n){function s(t,e){var r=t.toByteArraySigned(),i=e.toByteArraySigned(),n=[];return n.push(2),n.push(r.length),n=n.concat(r),n.push(2),n.push(i.length),n=n.concat(i),n.unshift(n.length),n.unshift(48),n}var o=i||1,a=n||Crypto.util.hexToBytes(this.transactionHash(t,o));if(a){var u=EllipticCurve.getSECCurveByName("secp256k1"),c=r.wif2privkey(e),h=BigInteger.fromByteArrayUnsigned(Crypto.util.hexToBytes(c.privkey)),f=u.getN(),p=BigInteger.fromByteArrayUnsigned(a),l=0;do{var y=this.deterministicK(e,a,l),d=u.getG(),g=d.multiply(y),v=g.getX().toBigInteger().mod(f),m=y.modInverse(f).multiply(p.add(h.multiply(v))).mod(f);l++}while(v.compareTo(BigInteger.ZERO)<=0||m.compareTo(BigInteger.ZERO)<=0);var b=f.shiftRight(1);m.compareTo(b)>0&&(m=f.subtract(m));var B=s(v,m);return B.push(parseInt(o,10)),Crypto.util.bytesToHex(B)}return!1},deterministicK:function(t,e,i){i=i||0;var n=r.wif2privkey(t),s=Crypto.util.hexToBytes(n.privkey),o=EllipticCurve.getSECCurveByName("secp256k1"),a=o.getN(),u=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];c=Crypto.HMAC(Crypto.SHA256,u.concat([0]).concat(s).concat(e),c,{asBytes:!0}),u=Crypto.HMAC(Crypto.SHA256,u,c,{asBytes:!0}),c=Crypto.HMAC(Crypto.SHA256,u.concat([1]).concat(s).concat(e),c,{asBytes:!0}),u=Crypto.HMAC(Crypto.SHA256,u,c,{asBytes:!0});var h=[];u=Crypto.HMAC(Crypto.SHA256,u,c,{asBytes:!0}),h=u;for(var f=BigInteger.fromByteArrayUnsigned(h),p=0;f.compareTo(a)>=0||f.compareTo(BigInteger.ZERO)<=0||p<i;)c=Crypto.HMAC(Crypto.SHA256,u.concat([0]),c,{asBytes:!0}),u=Crypto.HMAC(Crypto.SHA256,u,c,{asBytes:!0}),u=Crypto.HMAC(Crypto.SHA256,u,c,{asBytes:!0}),h=u,f=BigInteger.fromByteArrayUnsigned(h),p++;return f},signinput:function(t,e,i){var n=r.wif2pubkey(e),s=i||1,o=this.transactionSig(t,e,s),a=r.script();return a.writeBytes(Crypto.util.hexToBytes(o)),a.writeBytes(Crypto.util.hexToBytes(n.pubkey)),this.ins[t].script=a,!0},signhodl:function(t,e,i){var n=i||1,s=this.transactionSig(t,e,n),o=this.ins[t].script.buffer,a=r.script();return a.writeBytes(Crypto.util.hexToBytes(s)),a.writeBytes(o),this.ins[t].script=a,!0},signmultisig:function(t,e,i){function n(t){for(var e={},i=1;i<t.chunks.length-2;i++)e[i]=Crypto.util.hexToBytes(r.pubkeydecompress(Crypto.util.bytesToHex(t.chunks[i])));return e}function s(t){var e={},r=0;if(0==t.chunks[0]&&174==t.chunks[t.chunks.length-1][t.chunks[t.chunks.length-1].length-1])for(var i=1;i<t.chunks.length-1;i++)0!=t.chunks[i]&&(r++,e[r]=t.chunks[i]);return e}var o=174==this.ins[t].script.chunks[this.ins[t].script.chunks.length-1]?this.ins[t].script.buffer:this.ins[t].script.chunks[this.ins[t].script.chunks.length-1],a=n(r.script(o)),u=s(this.ins[t].script),c=i||1,h=Crypto.util.hexToBytes(this.transactionHash(t,c)),f=Crypto.util.hexToBytes(this.transactionSig(t,e,c));u[r.countObject(u)+1]=f;var p=r.script();p.writeOp(0);for(let e in a)for(let i in u)this.ins[t].script.buffer=o,h=Crypto.util.hexToBytes(this.transactionHash(t,1*u[i].slice(-1)[0])),r.verifySignature(h,u[i],a[e])&&p.writeBytes(u[i]);return p.writeBytes(o),this.ins[t].script=p,!0},signsegwit:function(t,e,i){var n=i||1,s=r.wif2pubkey(e),o=r.segwitAddress(s.pubkey),a=r.bech32Address(s.pubkey);if(o.redeemscript==Crypto.util.bytesToHex(this.ins[t].script.chunks[0])||a.redeemscript==Crypto.util.bytesToHex(this.ins[t].script.chunks[0])){var u=this.transactionHashSegWitV0(t,n);if(1==u.result){var c=Crypto.util.hexToBytes(u.hash),h=this.transactionSig(t,e,n,c),f=r.script();f.writeBytes(this.ins[t].script.chunks[0]),this.ins[t].script=f,r.isArray(this.witness)||(this.witness=new Array(this.ins.length),this.witness.fill([])),this.witness[t]=[h,s.pubkey],a.redeemscript==Crypto.util.bytesToHex(this.ins[t].script.chunks[0])&&(this.ins[t].script=r.script())}}return!0},sign:function(t,e){for(var i=e||1,n=0;n<this.ins.length;n++){var s=this.extractScriptKey(n),o=r.wif2address(t),a=r.script(),u=a.pubkeyHash(o.address);("scriptpubkey"==s.type&&s.script==Crypto.util.bytesToHex(u.buffer)||"empty"==s.type)&&"false"==s.signed?this.signinput(n,t,i):"hodl"==s.type&&"false"==s.signed?this.signhodl(n,t,i):"multisig"==s.type?this.signmultisig(n,t,i):"segwit"==s.type&&this.signsegwit(n,t,i)}return this.serialize()},serialize:function(){var t=[];t=t.concat(r.numToBytes(parseInt(this.version),4)),r.isArray(this.witness)&&(t=t.concat([0,1])),t=t.concat(r.numToVarInt(this.ins.length));for(var e=0;e<this.ins.length;e++){var i=this.ins[e];t=t.concat(Crypto.util.hexToBytes(i.outpoint.hash).reverse()),t=t.concat(r.numToBytes(parseInt(i.outpoint.index),4));var n=i.script.buffer;t=t.concat(r.numToVarInt(n.length)),t=t.concat(n),t=t.concat(r.numToBytes(parseInt(i.sequence),4))}t=t.concat(r.numToVarInt(this.outs.length));for(e=0;e<this.outs.length;e++){var s=this.outs[e];t=t.concat(r.numToBytes(s.value,8));n=s.script.buffer;t=t.concat(r.numToVarInt(n.length)),t=t.concat(n)}if(r.isArray(this.witness)&&this.witness.length>=1)for(e=0;e<this.witness.length;e++){t=t.concat(r.numToVarInt(this.witness[e].length));for(var o=0;o<this.witness[e].length;o++)t=t.concat(r.numToVarInt(Crypto.util.hexToBytes(this.witness[e][o]).length)),t=t.concat(Crypto.util.hexToBytes(this.witness[e][o]))}return t=t.concat(r.numToBytes(parseInt(this.lock_time),4)),Crypto.util.bytesToHex(t)},deserialize:function(t){"string"==typeof t&&(t=Crypto.util.hexToBytes(t));var e=0,i=!1,n=function(r){return 0==r?0:(e++,t[e-1]+256*n(r-1))},s=function(){return e++,t[e-1]<253?t[e-1]:n(t[e-1]-251)},o=function(r){return e+=r,t.slice(e-r,e)},a=function(){var t=s();return o(t)},u=new r.transaction;u.version=n(4),0==t[e]&&1==t[e+1]&&(i=!0,u.witness=[],e+=2);for(var c=s(),h=0;h<c;h++)u.ins.push({outpoint:{hash:Crypto.util.bytesToHex(o(32).reverse()),index:n(4)},script:r.script(a()),sequence:n(4)});var f=s();for(h=0;h<f;h++)u.outs.push({value:r.bytesToNum(o(8)),script:r.script(a())});if(1==i)for(h=0;h<c;++h){var p=s();r.isArray(u.witness[h])||(u.witness[h]=[]);for(var l=0;l<p;l++){var y=s();e+=y,u.witness[h].push(Crypto.util.bytesToHex(t.slice(e-y,e)))}}return u.lock_time=n(4),u},size:function(){return(this.serialize().length/2).toFixed(0)}};return e},r.verifySignature=function(t,e,i){function n(t){var e;if(48!=t[0])throw new Error("Signature not a valid DERSequence");if(e=2,2!=t[e])throw new Error("First element in signature must be a DERInteger");var r=t.slice(e+2,e+2+t[e+1]);if(e+=2+t[e+1],2!=t[e])throw new Error("Second element in signature must be a DERInteger");var i=t.slice(e+2,e+2+t[e+1]);e+=2+t[e+1];var n=BigInteger.fromByteArrayUnsigned(r),s=BigInteger.fromByteArrayUnsigned(i);return{r:n,s:s}}var s,o,a;if(r.isArray(e)){var u=n(e);s=u.r,o=u.s}else{if("object"!=typeof e||!e.r||!e.s)throw"Invalid value for signature";s=e.r,o=e.s}if(!r.isArray(i))throw"Invalid format for pubkey value, must be byte array";var c=EllipticCurve.getSECCurveByName("secp256k1");a=EllipticCurve.PointFp.decodeFrom(c.getCurve(),i);var h=BigInteger.fromByteArrayUnsigned(t);return r.verifySignatureRaw(h,s,o,a)},r.verifySignatureRaw=function(t,e,r,i){var n=EllipticCurve.getSECCurveByName("secp256k1"),s=n.getN(),o=n.getG();if(e.compareTo(BigInteger.ONE)<0||e.compareTo(s)>=0)return!1;if(r.compareTo(BigInteger.ONE)<0||r.compareTo(s)>=0)return!1;var a=r.modInverse(s),u=t.multiply(a).mod(s),c=e.multiply(a).mod(s),h=o.multiply(u).add(i.multiply(c)),f=h.getX().toBigInteger().mod(s);return f.equals(e)},r.base58encode=function(t){for(var e="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",r=BigInteger.valueOf(58),i=BigInteger.fromByteArrayUnsigned(t),n=[];i.compareTo(r)>=0;){var s=i.mod(r);n.unshift(e[s.intValue()]),i=i.subtract(s).divide(r)}n.unshift(e[i.intValue()]);for(var o=0;o<t.length&&0==t[o];o++)n.unshift(e[0]);return n.join("")},r.base58decode=function(t){for(var e="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",r=BigInteger.valueOf(58),i=BigInteger.valueOf(0),n=0,s=t.length-1;s>=0;s--){var o=e.indexOf(t[s]);if(o<0)throw"Invalid character";i=i.add(BigInteger.valueOf(o).multiply(r.pow(t.length-1-s))),"1"==t[s]?n++:n=0}for(var a=i.toByteArrayUnsigned();n-- >0;)a.unshift(0);return a},r.ajax=function(t,e,r,i){var n=!1;try{n=new ActiveXObject("Msxml2.XMLHTTP")}catch(t){try{n=new ActiveXObject("Microsoft.XMLHTTP")}catch(t){n=new XMLHttpRequest}}if(0==n)return!1;n.open(r,t,!0),n.onreadystatechange=function(){4==n.readyState&&e&&e(n.responseText)},"POST"==r&&n.setRequestHeader("Content-type","application/x-www-form-urlencoded"),n.send(i)},r.clone=function(t){if(null==t||"object"!=typeof t)return t;var e=new t.constructor;for(var i in t)t.hasOwnProperty(i)&&(e[i]=r.clone(t[i]));return e},r.numToBytes=function(t,e){return void 0===e&&(e=8),0==e?[]:-1==t?Crypto.util.hexToBytes("ffffffffffffffff"):[t%256].concat(r.numToBytes(Math.floor(t/256),e-1))},r.numToScriptNumBytes=function(t){for(var r=Math.abs(t),i=e(r),n=[],s=0;s<i;++s)n.push(0);var o=t<0;for(s=0;s<i;++s)n[s]=255&r,r=Math.floor(r/256);return o&&(n[i-1]|=128),n},r.numToVarInt=function(t){return t<253?[t]:t<65536?[253].concat(r.numToBytes(t,2)):t<4294967296?[254].concat(r.numToBytes(t,4)):[255].concat(r.numToBytes(t,8))},r.bytesToNum=function(t){return 0==t.length?0:t[0]+256*r.bytesToNum(t.slice(1))},r.uint=function(t,e){if(t.length<e)throw new Error("not enough data");for(var r=0,i=0;i<e;i++)r*=256,r+=t[i];return r},r.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)},r.countObject=function(t){var e,r=0;for(e in t)t.hasOwnProperty(e)&&r++;return r},r.random=function(t){var e="",r=t||25,i="!$%^&*()_+{}:@~?><|./;'#][=-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";for(let t=0;t<r;t++)e+=i.charAt(Math.floor(62*securedMathRandom()));return e}}(),function(){function e(t){if(t&&("number"!=typeof t||t%1!=0||t<g.minBits||t>g.maxBits))throw new Error("Number of bits must be an integer between "+g.minBits+" and "+g.maxBits+", inclusive.");v.radix=g.radix,v.bits=t||g.bits,v.size=Math.pow(2,v.bits),v.max=v.size-1;for(var e=[],r=[],i=1,n=g.primitivePolynomials[v.bits],s=0;s<v.size;s++)r[s]=i,e[i]=s,i<<=1,i>=v.size&&(i^=n,i&=v.max);v.logs=e,v.exps=r}function r(){return!!(v.bits&&v.size&&v.max&&v.logs&&v.exps&&v.logs.length===v.size&&v.exps.length===v.size)}function i(){function e(t,e,r,i){for(var n="",s=0,o=e.length-1;s<o||n.length<t;)n+=p(parseInt(e[s],r).toString(2),i),s++;return n=n.substr(-t),(n.match(/0/g)||[]).length===n.length?null:n}var r;if("function"==typeof require)return function(t){for(var r=Math.ceil(t/8),i=null;null===i;)i=e(t,require("crypto").randomBytes(r).toString("hex"),16,4);return i};if(t.crypto&&"function"==typeof t.crypto.getRandomValues&&"function"==typeof t.Uint32Array)return r=t.crypto,function(i){for(var n=Math.ceil(i/32),s=null,o=new t.Uint32Array(n);null===s;)r.getRandomValues(o),s=e(i,o,10,32);return s};v.unsafePRNG=!0,n();var i=32,s=Math.pow(2,i)-1;return function(t){for(var r=Math.ceil(t/i),n=[],o=null;null===o;){for(var a=0;a<r;a++)n[a]=Math.floor(securedMathRandom()*s+1);o=e(t,n,10,i)}return o}}function n(){t.console.warn(g.warning),"function"==typeof t.alert&&v.alert&&t.alert(g.warning)}function s(){return"function"==typeof v.rng}function o(t,e){for(var r=v.logs[t],i=0,n=e.length-1;n>=0;n--)i=0!==i?v.exps[(r+v.logs[i])%v.max]^e[n]:e[n];return i}function a(t,e){for(var r=0,i=t.length;r<i;r++)if(t[r]===e)return!0;return!1}function u(t){var e=parseInt(t[0],36);if(e&&("number"!=typeof e||e%1!=0||e<g.minBits||e>g.maxBits))throw new Error("Number of bits must be an integer between "+g.minBits+" and "+g.maxBits+", inclusive.");var r=Math.pow(2,e)-1,i=r.toString(v.radix).length,n=parseInt(t.substr(1,i),v.radix);if("number"!=typeof n||n%1!=0||n<1||n>r)throw new Error("Share id must be an integer between 1 and "+v.max+", inclusive.");if(t=t.substr(i+1),!t.length)throw new Error("Invalid share: zero-length share.");return{bits:e,id:n,value:t}}function c(t,r){for(var i,n,s=[],o=[],c="",d=0,g=r.length;d<g;d++){if(n=u(r[d]),void 0===i)i=n.bits;else if(n.bits!==i)throw new Error("Mismatched shares: Different bit settings.");if(v.bits!==i&&e(i),!a(s,n.id)){B=s.push(n.id)-1,n=f(l(n.value));for(var m=0,b=n.length;m<b;m++)o[m]=o[m]||[],o[m][B]=n[m]}}for(d=0,g=o.length;d<g;d++)c=p(h(t,s,o[d]).toString(2))+c;if(0===t){var B=c.indexOf("1");return y(c.slice(B+1))}return y(c)}function h(t,e,r){for(var i,n=0,s=0,o=e.length;s<o;s++)if(r[s]){i=v.logs[r[s]];for(var a=0;a<o;a++)if(s!==a){if(t===e[a]){i=-1;break}i=(i+v.logs[t^e[a]]-v.logs[e[s]^e[a]]+v.max)%v.max}n=-1===i?n:n^v.exps[i]}return n}function f(t,e){e&&(t=p(t,e));for(var r=[],i=t.length;i>v.bits;i-=v.bits)r.push(parseInt(t.slice(i-v.bits,i),2));return r.push(parseInt(t.slice(0,i),2)),r}function p(t,e){e=e||v.bits;var r=t.length%e;return(r?new Array(e-r+1).join("0"):"")+t}function l(t){for(var e,r="",i=t.length-1;i>=0;i--){if(e=parseInt(t[i],16),isNaN(e))throw new Error("Invalid hex character.");r=p(e.toString(2),4)+r}return r}function y(t){var e,r="";t=p(t,4);for(var i=t.length;i>=4;i-=4){if(e=parseInt(t.slice(i-4,i),2),isNaN(e))throw new Error("Invalid binary character.");r=e.toString(16)+r}return r}var d=t.shamirSecretShare={},g={bits:8,radix:16,minBits:3,maxBits:20,bytesPerChar:2,maxBytesPerChar:6,primitivePolynomials:[null,null,1,3,3,5,3,3,29,17,9,5,83,27,43,3,45,9,39,39,9,5,3,33,27,9,71,39,9,5,83],warning:"WARNING:\nA secure random number generator was not found.\nUsing securedMathRandom(), which is NOT cryptographically strong!"},v={};d.getConfig=function(){return{bits:v.bits,unsafePRNG:v.unsafePRNG}},d.init=e,d.setRNG=function(t,e){if(r()||this.init(),v.unsafePRNG=!1,t=t||i(),"function"!=typeof t||"string"!=typeof t(v.bits)||!parseInt(t(v.bits),2)||t(v.bits).length>v.bits||t(v.bits).length<v.bits)throw new Error("Random number generator is invalid. Supply an RNG of the form function(bits){} that returns a string containing 'bits' number of random 1's and 0's.");return v.rng=t,v.alert=!!e,!!v.unsafePRNG},d.random=function(t){if(s()||this.setRNG(),"number"!=typeof t||t%1!=0||t<2)throw new Error("Number of bits must be an integer greater than 1.");return v.unsafePRNG&&n(),y(v.rng(t))},d.share=function(t,e,i,o,a){if(r()||this.init(),s()||this.setRNG(),o=o||0,"string"!=typeof t)throw new Error("Secret must be a string.");if("number"!=typeof e||e%1!=0||e<2)throw new Error("Number of shares must be an integer between 2 and 2^bits-1 ("+v.max+"), inclusive.");if(e>v.max){var u=Math.ceil(Math.log(e+1)/Math.LN2);throw new Error("Number of shares must be an integer between 2 and 2^bits-1 ("+v.max+"), inclusive. To create "+e+" shares, use at least "+u+" bits.")}if("number"!=typeof i||i%1!=0||i<2)throw new Error("Threshold number of shares must be an integer between 2 and 2^bits-1 ("+v.max+"), inclusive.");if(i>v.max){u=Math.ceil(Math.log(i+1)/Math.LN2);throw new Error("Threshold number of shares must be an integer between 2 and 2^bits-1 ("+v.max+"), inclusive. To use a threshold of "+i+", use at least "+u+" bits.")}if("number"!=typeof o||o%1!=0)throw new Error("Zero-pad length must be an integer greater than 1.");v.unsafePRNG&&n(),t="1"+l(t),t=f(t,o);for(var c=new Array(e),h=new Array(e),d=0,g=t.length;d<g;d++)for(var m=this._getShares(t[d],e,i),b=0;b<e;b++)c[b]=c[b]||m[b].x.toString(v.radix),h[b]=p(m[b].y.toString(2))+(h[b]?h[b]:"");var B=v.max.toString(v.radix).length;if(a)for(d=0;d<e;d++)c[d]=y(h[d]);else for(d=0;d<e;d++)c[d]=v.bits.toString(36).toUpperCase()+p(c[d],B)+y(h[d]);return c},d._getShares=function(t,e,r){for(var i=[],n=[t],s=1;s<r;s++)n[s]=parseInt(v.rng(v.bits),2);s=1;for(var a=e+1;s<a;s++)i[s-1]={x:s,y:o(s,n)};return i},d._processShare=u,d.combine=function(t){return c(0,t)},d.newShare=function(t,e){"string"==typeof t&&(t=parseInt(t,v.radix));var r=u(e[0]),i=Math.pow(2,r.bits)-1;if("number"!=typeof t||t%1!=0||t<1||t>i)throw new Error("Share id must be an integer between 1 and "+v.max+", inclusive.");var n=i.toString(v.radix).length;return v.bits.toString(36).toUpperCase()+p(t.toString(v.radix),n)+c(t,e)},d._lagrange=h,d.str2hex=function(t,e){if("string"!=typeof t)throw new Error("Input must be a character string.");if(e=e||g.bytesPerChar,"number"!=typeof e||e%1!=0||e<1||e>g.maxBytesPerChar)throw new Error("Bytes per character must be an integer between 1 and "+g.maxBytesPerChar+", inclusive.");for(var r,i=2*e,n=Math.pow(16,i)-1,s="",o=0,a=t.length;o<a;o++){if(r=t[o].charCodeAt(),isNaN(r))throw new Error("Invalid character: "+t[o]);if(r>n){var u=Math.ceil(Math.log(r+1)/Math.log(256));throw new Error("Invalid character code ("+r+"). Maximum allowable is 256^bytes-1 ("+n+"). To convert this character, use at least "+u+" bytes.")}s=p(r.toString(16),i)+s}return s},d.hex2str=function(t,e){if("string"!=typeof t)throw new Error("Input must be a hexadecimal string.");if(e=e||g.bytesPerChar,
|
|
"number"!=typeof e||e%1!=0||e<1||e>g.maxBytesPerChar)throw new Error("Bytes per character must be an integer between 1 and "+g.maxBytesPerChar+", inclusive.");var r=2*e,i="";t=p(t,r);for(var n=0,s=t.length;n<s;n+=r)i=String.fromCharCode(parseInt(t.slice(n,n+r),16))+i;return i},d.init()}(),t.BuildKBucket=function t(r={}){if(!(this instanceof t))return new t(r);this.localNodeId=r.localNodeId||e(new Uint8Array(20)),this.numberOfNodesPerKBucket=r.numberOfNodesPerKBucket||20,this.numberOfNodesToPing=r.numberOfNodesToPing||3,this.distance=r.distance||this.distance,this.arbiter=r.arbiter||this.arbiter,this.metadata=Object.assign({},r.metadata),this.createNode=function(){return{contacts:[],dontSplit:!1,left:null,right:null}},this.ensureInt8=function(t,e){if(!(e instanceof Uint8Array))throw new TypeError(t+" is not a Uint8Array")},this.arrayEquals=function(t,e){if(t===e)return!0;if(t.length!==e.length)return!1;for(let r=0,i=t.length;r<i;++r)if(t[r]!==e[r])return!1;return!0},this.ensureInt8("option.localNodeId as parameter 1",this.localNodeId),this.root=this.createNode(),this.arbiter=function(t,e){return t.vectorClock>e.vectorClock?t:e},this.distance=function(t,e){let r=0,i=0;const n=Math.min(t.length,e.length),s=Math.max(t.length,e.length);for(;i<n;++i)r=256*r+(t[i]^e[i]);for(;i<s;++i)r=256*r+255;return r},this.add=function(t){this.ensureInt8("contact.id",(t||{}).id);let e=0,r=this.root;for(;null===r.contacts;)r=this._determineNode(r,t.id,e++);const i=this._indexOf(r,t.id);return i>=0?(this._update(r,i,t),this):r.contacts.length<this.numberOfNodesPerKBucket?(r.contacts.push(t),this):r.dontSplit?this:(this._split(r,e),this.add(t))},this.closest=function(t,e=1/0){if(this.ensureInt8("id",t),!Number.isInteger(e)&&e!==1/0||e<=0)throw new TypeError("n is not positive number");let r=[];for(let i=[this.root],n=0;i.length>0&&r.length<e;){const e=i.pop();if(null===e.contacts){const r=this._determineNode(e,t,n++);i.push(e.left===r?e.right:e.left),i.push(r)}else r=r.concat(e.contacts)}return r.map(e=>[this.distance(e.id,t),e]).sort((t,e)=>t[0]-e[0]).slice(0,e).map(t=>t[1])},this.count=function(){let t=0;for(const e=[this.root];e.length>0;){const r=e.pop();null===r.contacts?e.push(r.right,r.left):t+=r.contacts.length}return t},this._determineNode=function(t,e,r){const i=r>>3,n=r%8;if(e.length<=i&&0!==n)return t.left;const s=e[i];return s&1<<7-n?t.right:t.left},this.get=function(t){this.ensureInt8("id",t);let e=0,r=this.root;for(;null===r.contacts;)r=this._determineNode(r,t,e++);const i=this._indexOf(r,t);return i>=0?r.contacts[i]:null},this._indexOf=function(t,e){for(let r=0;r<t.contacts.length;++r)if(this.arrayEquals(t.contacts[r].id,e))return r;return-1},this.remove=function(t){this.ensureInt8("the id as parameter 1",t);let e=0,r=this.root;for(;null===r.contacts;)r=this._determineNode(r,t,e++);const i=this._indexOf(r,t);return i>=0&&r.contacts.splice(i,1)[0],this},this._split=function(t,e){t.left=this.createNode(),t.right=this.createNode();for(const r of t.contacts)this._determineNode(t,r.id,e).contacts.push(r);t.contacts=null;const r=this._determineNode(t,this.localNodeId,e),i=t.left===r?t.right:t.left;i.dontSplit=!0},this.toArray=function(){let t=[];for(const e=[this.root];e.length>0;){const r=e.pop();null===r.contacts?e.push(r.right,r.left):t=t.concat(r.contacts)}return t},this._update=function(t,e,r){if(!this.arrayEquals(t.contacts[e].id,r.id))throw new Error("wrong index for _update");const i=t.contacts[e],n=this.arbiter(i,r);n===i&&i!==r||(t.contacts.splice(e,1),t.contacts.push(n))}}})("undefined"!=typeof global?global:window); |