ebclient
Version:
Client library for using EnigmaBridge crypto services
5 lines • 249 kB
JavaScript
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.eb = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";var sjcl={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(t){this.toString=function(){return"CORRUPT: "+this.message},this.message=t},invalid:function(t){this.toString=function(){return"INVALID: "+this.message},this.message=t},bug:function(t){this.toString=function(){return"BUG: "+this.message},this.message=t},notReady:function(t){this.toString=function(){return"NOT READY: "+this.message},this.message=t}}};sjcl.cipher.aes=function(t){this._tables[0][0][0]||this._precompute();var e,s,i,r,n,o=this._tables[0][4],c=this._tables[1],l=t.length,a=1;if(4!==l&&6!==l&&8!==l)throw new sjcl.exception.invalid("invalid aes key size");for(this._key=[r=t.slice(0),n=[]],e=l;e<4*l+28;e++)i=r[e-1],(e%l==0||8===l&&e%l==4)&&(i=o[i>>>24]<<24^o[i>>16&255]<<16^o[i>>8&255]<<8^o[255&i],e%l==0&&(i=i<<8^i>>>24^a<<24,a=a<<1^283*(a>>7))),r[e]=r[e-l]^i;for(s=0;e;s++,e--)i=r[3&s?e:e-4],n[s]=e<=4||s<4?i:c[0][o[i>>>24]]^c[1][o[i>>16&255]]^c[2][o[i>>8&255]]^c[3][o[255&i]]},sjcl.cipher.aes.prototype={encrypt:function(t){return this._crypt(t,0)},decrypt:function(t){return this._crypt(t,1)},_tables:[[[],[],[],[],[]],[[],[],[],[],[]]],_precompute:function(){var t,e,s,i,r,n,o,c,l,a=this._tables[0],h=this._tables[1],u=a[4],f=h[4],d=[],p=[];for(t=0;t<256;t++)p[(d[t]=t<<1^283*(t>>7))^t]=t;for(e=s=0;!u[e];e^=i||1,s=p[s]||1)for(o=s^s<<1^s<<2^s<<3^s<<4,o=o>>8^255&o^99,u[e]=o,f[o]=e,n=d[r=d[i=d[e]]],l=16843009*n^65537*r^257*i^16843008*e,c=257*d[o]^16843008*o,t=0;t<4;t++)a[t][e]=c=c<<24^c>>>8,h[t][o]=l=l<<24^l>>>8;for(t=0;t<5;t++)a[t]=a[t].slice(0),h[t]=h[t].slice(0)},_crypt:function(t,e){if(4!==t.length)throw new sjcl.exception.invalid("invalid aes block size");var s,i,r,n,o=this._key[e],c=t[0]^o[0],l=t[e?3:1]^o[1],a=t[2]^o[2],h=t[e?1:3]^o[3],u=o.length/4-2,f=4,d=[0,0,0,0],p=this._tables[e],m=p[0],b=p[1],_=p[2],g=p[3],y=p[4];for(n=0;n<u;n++)s=m[c>>>24]^b[l>>16&255]^_[a>>8&255]^g[255&h]^o[f],i=m[l>>>24]^b[a>>16&255]^_[h>>8&255]^g[255&c]^o[f+1],r=m[a>>>24]^b[h>>16&255]^_[c>>8&255]^g[255&l]^o[f+2],h=m[h>>>24]^b[c>>16&255]^_[l>>8&255]^g[255&a]^o[f+3],f+=4,c=s,l=i,a=r;for(n=0;n<4;n++)d[e?3&-n:n]=y[c>>>24]<<24^y[l>>16&255]<<16^y[a>>8&255]<<8^y[255&h]^o[f++],s=c,c=l,l=a,a=h,h=s;return d}},sjcl.bitArray={bitSlice:function(t,e,s){return t=sjcl.bitArray._shiftRight(t.slice(e/32),32-(31&e)).slice(1),void 0===s?t:sjcl.bitArray.clamp(t,s-e)},extract:function(t,e,s){var i=Math.floor(-e-s&31);return(-32&(e+s-1^e)?t[e/32|0]<<32-i^t[e/32+1|0]>>>i:t[e/32|0]>>>i)&(1<<s)-1},concat:function(t,e){if(0===t.length||0===e.length)return t.concat(e);var s=t[t.length-1],i=sjcl.bitArray.getPartial(s);return 32===i?t.concat(e):sjcl.bitArray._shiftRight(e,i,0|s,t.slice(0,t.length-1))},bitLength:function(t){var e,s=t.length;return 0===s?0:(e=t[s-1],32*(s-1)+sjcl.bitArray.getPartial(e))},clamp:function(t,e){if(32*t.length<e)return t;t=t.slice(0,Math.ceil(e/32));var s=t.length;return e&=31,s>0&&e&&(t[s-1]=sjcl.bitArray.partial(e,t[s-1]&2147483648>>e-1,1)),t},partial:function(t,e,s){return 32===t?e:(s?0|e:e<<32-t)+1099511627776*t},getPartial:function(t){return Math.round(t/1099511627776)||32},equal:function(t,e){if(sjcl.bitArray.bitLength(t)!==sjcl.bitArray.bitLength(e))return!1;var s,i=0;for(s=0;s<t.length;s++)i|=t[s]^e[s];return 0===i},_shiftRight:function(t,e,s,i){var r,n,o=0;for(void 0===i&&(i=[]);e>=32;e-=32)i.push(s),s=0;if(0===e)return i.concat(t);for(r=0;r<t.length;r++)i.push(s|t[r]>>>e),s=t[r]<<32-e;return o=t.length?t[t.length-1]:0,n=sjcl.bitArray.getPartial(o),i.push(sjcl.bitArray.partial(e+n&31,e+n>32?s:i.pop(),1)),i},_xor4:function(t,e){return[t[0]^e[0],t[1]^e[1],t[2]^e[2],t[3]^e[3]]},byteswapM:function(t){var e,s;for(e=0;e<t.length;++e)s=t[e],t[e]=s>>>24|s>>>8&65280|(65280&s)<<8|s<<24;return t}},sjcl.codec.utf8String={fromBits:function(t){var e,s,i="",r=sjcl.bitArray.bitLength(t);for(e=0;e<r/8;e++)0==(3&e)&&(s=t[e/4]),i+=String.fromCharCode(s>>>8>>>8>>>8),s<<=8;return decodeURIComponent(escape(i))},toBits:function(t){t=unescape(encodeURIComponent(t));var e,s=[],i=0;for(e=0;e<t.length;e++)i=i<<8|t.charCodeAt(e),3==(3&e)&&(s.push(i),i=0);return 3&e&&s.push(sjcl.bitArray.partial(8*(3&e),i)),s}},sjcl.codec.hex={fromBits:function(t){var e,s="";for(e=0;e<t.length;e++)s+=(0xf00000000000+(0|t[e])).toString(16).substr(4);return s.substr(0,sjcl.bitArray.bitLength(t)/4)},toBits:function(t){var e,s,i=[];for(t=t.replace(/\s|0x/g,""),s=t.length,t+="00000000",e=0;e<t.length;e+=8)i.push(0^parseInt(t.substr(e,8),16));return sjcl.bitArray.clamp(i,4*s)}},sjcl.codec.base32={_chars:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",_hexChars:"0123456789ABCDEFGHIJKLMNOPQRSTUV",BITS:32,BASE:5,REMAINING:27,fromBits:function(t,e,s){var i,r=(sjcl.codec.base32.BITS,sjcl.codec.base32.BASE),n=sjcl.codec.base32.REMAINING,o="",c=0,l=sjcl.codec.base32._chars,a=0,h=sjcl.bitArray.bitLength(t);for(s&&(l=sjcl.codec.base32._hexChars),i=0;o.length*r<h;)o+=l.charAt((a^t[i]>>>c)>>>n),c<r?(a=t[i]<<r-c,c+=n,i++):(a<<=r,c-=r);for(;7&o.length&&!e;)o+="=";return o},toBits:function(t,e){t=t.replace(/\s|=/g,"").toUpperCase();var s,i,r=sjcl.codec.base32.BITS,n=sjcl.codec.base32.BASE,o=sjcl.codec.base32.REMAINING,c=[],l=0,a=sjcl.codec.base32._chars,h=0,u="base32";for(e&&(a=sjcl.codec.base32._hexChars,u="base32hex"),s=0;s<t.length;s++){if((i=a.indexOf(t.charAt(s)))<0){if(!e)try{return sjcl.codec.base32hex.toBits(t)}catch(t){}throw new sjcl.exception.invalid("this isn't "+u+"!")}l>o?(l-=o,c.push(h^i>>>l),h=i<<r-l):(l+=n,h^=i<<r-l)}return 56&l&&c.push(sjcl.bitArray.partial(56&l,h,1)),c}},sjcl.codec.base32hex={fromBits:function(t,e){return sjcl.codec.base32.fromBits(t,e,1)},toBits:function(t){return sjcl.codec.base32.toBits(t,1)}},sjcl.codec.base64={_chars:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",fromBits:function(t,e,s){var i,r="",n=0,o=sjcl.codec.base64._chars,c=0,l=sjcl.bitArray.bitLength(t);for(s&&(o=o.substr(0,62)+"-_"),i=0;6*r.length<l;)r+=o.charAt((c^t[i]>>>n)>>>26),n<6?(c=t[i]<<6-n,n+=26,i++):(c<<=6,n-=6);for(;3&r.length&&!e;)r+="=";return r},toBits:function(t,e){t=t.replace(/\s|=/g,"");var s,i,r=[],n=0,o=sjcl.codec.base64._chars,c=0;for(e&&(o=o.substr(0,62)+"-_"),s=0;s<t.length;s++){if((i=o.indexOf(t.charAt(s)))<0)throw new sjcl.exception.invalid("this isn't base64!");n>26?(n-=26,r.push(c^i>>>n),c=i<<32-n):(n+=6,c^=i<<32-n)}return 56&n&&r.push(sjcl.bitArray.partial(56&n,c,1)),r}},sjcl.codec.base64url={fromBits:function(t){return sjcl.codec.base64.fromBits(t,1,1)},toBits:function(t){return sjcl.codec.base64.toBits(t,1)}},sjcl.codec.bytes={fromBits:function(t){var e,s,i=[],r=sjcl.bitArray.bitLength(t);for(e=0;e<r/8;e++)0==(3&e)&&(s=t[e/4]),i.push(s>>>24),s<<=8;return i},toBits:function(t){var e,s=[],i=0;for(e=0;e<t.length;e++)i=i<<8|t[e],3==(3&e)&&(s.push(i),i=0);return 3&e&&s.push(sjcl.bitArray.partial(8*(3&e),i)),s}},sjcl.hash.sha256=function(t){this._key[0]||this._precompute(),t?(this._h=t._h.slice(0),this._buffer=t._buffer.slice(0),this._length=t._length):this.reset()},sjcl.hash.sha256.hash=function(t){return(new sjcl.hash.sha256).update(t).finalize()},sjcl.hash.sha256.prototype={blockSize:512,reset:function(){return this._h=this._init.slice(0),this._buffer=[],this._length=0,this},update:function(t){"string"==typeof t&&(t=sjcl.codec.utf8String.toBits(t));var e,s=this._buffer=sjcl.bitArray.concat(this._buffer,t),i=this._length,r=this._length=i+sjcl.bitArray.bitLength(t);if(r>9007199254740991)throw new sjcl.exception.invalid("Cannot hash more than 2^53 - 1 bits");if("undefined"!=typeof Uint32Array){var n=new Uint32Array(s),o=0;for(e=512+i-(512+i&511);e<=r;e+=512)this._block(n.subarray(16*o,16*(o+1))),o+=1;s.splice(0,16*o)}else for(e=512+i-(512+i&511);e<=r;e+=512)this._block(s.splice(0,16));return this},finalize:function(){var t,e=this._buffer,s=this._h;for(e=sjcl.bitArray.concat(e,[sjcl.bitArray.partial(1,1)]),t=e.length+2;15&t;t++)e.push(0);for(e.push(Math.floor(this._length/4294967296)),e.push(0|this._length);e.length;)this._block(e.splice(0,16));return this.reset(),s},_init:[],_key:[],_precompute:function(){function t(t){return 4294967296*(t-Math.floor(t))|0}for(var e,s,i=0,r=2;i<64;r++){for(s=!0,e=2;e*e<=r;e++)if(r%e==0){s=!1;break}s&&(i<8&&(this._init[i]=t(Math.pow(r,.5))),this._key[i]=t(Math.pow(r,1/3)),i++)}},_block:function(t){var e,s,i,r,n=this._h,o=this._key,c=n[0],l=n[1],a=n[2],h=n[3],u=n[4],f=n[5],d=n[6],p=n[7];for(e=0;e<64;e++)e<16?s=t[e]:(i=t[e+1&15],r=t[e+14&15],s=t[15&e]=(i>>>7^i>>>18^i>>>3^i<<25^i<<14)+(r>>>17^r>>>19^r>>>10^r<<15^r<<13)+t[15&e]+t[e+9&15]|0),s=s+p+(u>>>6^u>>>11^u>>>25^u<<26^u<<21^u<<7)+(d^u&(f^d))+o[e],p=d,d=f,f=u,u=h+s|0,h=a,a=l,l=c,c=s+(l&a^h&(l^a))+(l>>>2^l>>>13^l>>>22^l<<30^l<<19^l<<10)|0;n[0]=n[0]+c|0,n[1]=n[1]+l|0,n[2]=n[2]+a|0,n[3]=n[3]+h|0,n[4]=n[4]+u|0,n[5]=n[5]+f|0,n[6]=n[6]+d|0,n[7]=n[7]+p|0}},sjcl.hash.sha1=function(t){t?(this._h=t._h.slice(0),this._buffer=t._buffer.slice(0),this._length=t._length):this.reset()},sjcl.hash.sha1.hash=function(t){return(new sjcl.hash.sha1).update(t).finalize()},sjcl.hash.sha1.prototype={blockSize:512,reset:function(){return this._h=this._init.slice(0),this._buffer=[],this._length=0,this},update:function(t){"string"==typeof t&&(t=sjcl.codec.utf8String.toBits(t));var e,s=this._buffer=sjcl.bitArray.concat(this._buffer,t),i=this._length,r=this._length=i+sjcl.bitArray.bitLength(t);if(r>9007199254740991)throw new sjcl.exception.invalid("Cannot hash more than 2^53 - 1 bits");if("undefined"!=typeof Uint32Array){var n=new Uint32Array(s),o=0;for(e=this.blockSize+i-(this.blockSize+i&this.blockSize-1);e<=r;e+=this.blockSize)this._block(n.subarray(16*o,16*(o+1))),o+=1;s.splice(0,16*o)}else for(e=this.blockSize+i-(this.blockSize+i&this.blockSize-1);e<=r;e+=this.blockSize)this._block(s.splice(0,16));return this},finalize:function(){var t,e=this._buffer,s=this._h;for(e=sjcl.bitArray.concat(e,[sjcl.bitArray.partial(1,1)]),t=e.length+2;15&t;t++)e.push(0);for(e.push(Math.floor(this._length/4294967296)),e.push(0|this._length);e.length;)this._block(e.splice(0,16));return this.reset(),s},_init:[1732584193,4023233417,2562383102,271733878,3285377520],_key:[1518500249,1859775393,2400959708,3395469782],_f:function(t,e,s,i){return t<=19?e&s|~e&i:t<=39?e^s^i:t<=59?e&s|e&i|s&i:t<=79?e^s^i:void 0},_S:function(t,e){return e<<t|e>>>32-t},_block:function(t){var e,s,i,r,n,o,c,l,a=this._h;if("undefined"!=typeof Uint32Array){l=Array(80);for(var h=0;h<16;h++)l[h]=t[h]}else l=t;for(i=a[0],r=a[1],n=a[2],o=a[3],c=a[4],e=0;e<=79;e++)e>=16&&(l[e]=this._S(1,l[e-3]^l[e-8]^l[e-14]^l[e-16])),s=this._S(5,i)+this._f(e,r,n,o)+c+l[e]+this._key[Math.floor(e/20)]|0,c=o,o=n,n=this._S(30,r),r=i,i=s;a[0]=a[0]+i|0,a[1]=a[1]+r|0,a[2]=a[2]+n|0,a[3]=a[3]+o|0,a[4]=a[4]+c|0}},sjcl.mode.ccm={name:"ccm",_progressListeners:[],listenProgress:function(t){sjcl.mode.ccm._progressListeners.push(t)},unListenProgress:function(t){var e=sjcl.mode.ccm._progressListeners.indexOf(t);e>-1&&sjcl.mode.ccm._progressListeners.splice(e,1)},_callProgressListener:function(t){var e,s=sjcl.mode.ccm._progressListeners.slice();for(e=0;e<s.length;e+=1)s[e](t)},encrypt:function(t,e,s,i,r){var n,o,c=e.slice(0),l=sjcl.bitArray,a=l.bitLength(s)/8,h=l.bitLength(c)/8;if(r=r||64,i=i||[],a<7)throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes");for(n=2;n<4&&h>>>8*n;n++);return n<15-a&&(n=15-a),s=l.clamp(s,8*(15-n)),o=sjcl.mode.ccm._computeTag(t,e,s,i,r,n),c=sjcl.mode.ccm._ctrMode(t,c,s,o,r,n),l.concat(c.data,c.tag)},decrypt:function(t,e,s,i,r){r=r||64,i=i||[];var n,o,c=sjcl.bitArray,l=c.bitLength(s)/8,a=c.bitLength(e),h=c.clamp(e,a-r),u=c.bitSlice(e,a-r);if(a=(a-r)/8,l<7)throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes");for(n=2;n<4&&a>>>8*n;n++);if(n<15-l&&(n=15-l),s=c.clamp(s,8*(15-n)),h=sjcl.mode.ccm._ctrMode(t,h,s,u,r,n),o=sjcl.mode.ccm._computeTag(t,h.data,s,i,r,n),!c.equal(h.tag,o))throw new sjcl.exception.corrupt("ccm: tag doesn't match");return h.data},_macAdditionalData:function(t,e,s,i,r,n){var o,c,l,a=[],h=sjcl.bitArray,u=h._xor4;if(o=[h.partial(8,(e.length?64:0)|i-2<<2|n-1)],o=h.concat(o,s),o[3]|=r,o=t.encrypt(o),e.length)for(c=h.bitLength(e)/8,c<=65279?a=[h.partial(16,c)]:c<=4294967295&&(a=h.concat([h.partial(16,65534)],[c])),a=h.concat(a,e),l=0;l<a.length;l+=4)o=t.encrypt(u(o,a.slice(l,l+4).concat([0,0,0])));return o},_computeTag:function(t,e,s,i,r,n){var o,c,l=sjcl.bitArray,a=l._xor4;if((r/=8)%2||r<4||r>16)throw new sjcl.exception.invalid("ccm: invalid tag length");if(i.length>4294967295||e.length>4294967295)throw new sjcl.exception.bug("ccm: can't deal with 4GiB or more data");for(o=sjcl.mode.ccm._macAdditionalData(t,i,s,r,l.bitLength(e)/8,n),c=0;c<e.length;c+=4)o=t.encrypt(a(o,e.slice(c,c+4).concat([0,0,0])));return l.clamp(o,8*r)},_ctrMode:function(t,e,s,i,r,n){var o,c,l,a=sjcl.bitArray,h=a._xor4,u=e.length,f=a.bitLength(e),d=u/50,p=d;if(l=a.concat([a.partial(8,n-1)],s).concat([0,0,0]).slice(0,4),i=a.bitSlice(h(i,t.encrypt(l)),0,r),!u)return{tag:i,data:[]};for(c=0;c<u;c+=4)c>d&&(sjcl.mode.ccm._callProgressListener(c/u),d+=p),l[3]++,o=t.encrypt(l),e[c]^=o[0],e[c+1]^=o[1],e[c+2]^=o[2],e[c+3]^=o[3];return{tag:i,data:a.clamp(e,f)}}},sjcl.mode.ocb2={name:"ocb2",encrypt:function(t,e,s,i,r,n){if(128!==sjcl.bitArray.bitLength(s))throw new sjcl.exception.invalid("ocb iv must be 128 bits");var o,c,l,a,h=sjcl.mode.ocb2._times2,u=sjcl.bitArray,f=u._xor4,d=[0,0,0,0],p=h(t.encrypt(s)),m=[];for(i=i||[],r=r||64,o=0;o+4<e.length;o+=4)c=e.slice(o,o+4),d=f(d,c),m=m.concat(f(p,t.encrypt(f(p,c)))),p=h(p);return c=e.slice(o),l=u.bitLength(c),a=t.encrypt(f(p,[0,0,0,l])),c=u.clamp(f(c.concat([0,0,0]),a),l),d=f(d,f(c.concat([0,0,0]),a)),d=t.encrypt(f(d,f(p,h(p)))),i.length&&(d=f(d,n?i:sjcl.mode.ocb2.pmac(t,i))),m.concat(u.concat(c,u.clamp(d,r)))},decrypt:function(t,e,s,i,r,n){if(128!==sjcl.bitArray.bitLength(s))throw new sjcl.exception.invalid("ocb iv must be 128 bits");r=r||64;var o,c,l,a,h=sjcl.mode.ocb2._times2,u=sjcl.bitArray,f=u._xor4,d=[0,0,0,0],p=h(t.encrypt(s)),m=sjcl.bitArray.bitLength(e)-r,b=[];for(i=i||[],o=0;o+4<m/32;o+=4)c=f(p,t.decrypt(f(p,e.slice(o,o+4)))),d=f(d,c),b=b.concat(c),p=h(p);if(l=m-32*o,a=t.encrypt(f(p,[0,0,0,l])),c=f(a,u.clamp(e.slice(o),l).concat([0,0,0])),d=f(d,c),d=t.encrypt(f(d,f(p,h(p)))),i.length&&(d=f(d,n?i:sjcl.mode.ocb2.pmac(t,i))),!u.equal(u.clamp(d,r),u.bitSlice(e,m)))throw new sjcl.exception.corrupt("ocb: tag doesn't match");return b.concat(u.clamp(c,l))},pmac:function(t,e){var s,i,r=sjcl.mode.ocb2._times2,n=sjcl.bitArray,o=n._xor4,c=[0,0,0,0],l=t.encrypt([0,0,0,0]);for(l=o(l,r(r(l))),s=0;s+4<e.length;s+=4)l=r(l),c=o(c,t.encrypt(o(l,e.slice(s,s+4))));return i=e.slice(s),n.bitLength(i)<128&&(l=o(l,r(l)),i=n.concat(i,[-2147483648,0,0,0])),c=o(c,i),t.encrypt(o(r(o(l,r(l))),c))},_times2:function(t){return[t[0]<<1^t[1]>>>31,t[1]<<1^t[2]>>>31,t[2]<<1^t[3]>>>31,t[3]<<1^135*(t[0]>>>31)]}},sjcl.mode.gcm={name:"gcm",encrypt:function(t,e,s,i,r){var n,o=e.slice(0),c=sjcl.bitArray;return r=r||128,i=i||[],n=sjcl.mode.gcm._ctrMode(!0,t,o,i,s,r),c.concat(n.data,n.tag)},decrypt:function(t,e,s,i,r){var n,o,c=e.slice(0),l=sjcl.bitArray,a=l.bitLength(c);if(r=r||128,i=i||[],r<=a?(o=l.bitSlice(c,a-r),c=l.bitSlice(c,0,a-r)):(o=c,c=[]),n=sjcl.mode.gcm._ctrMode(!1,t,c,i,s,r),!l.equal(n.tag,o))throw new sjcl.exception.corrupt("gcm: tag doesn't match");return n.data},_galoisMultiply:function(t,e){var s,i,r,n,o,c,l=sjcl.bitArray,a=l._xor4;for(n=[0,0,0,0],o=e.slice(0),s=0;s<128;s++){for(r=0!=(t[Math.floor(s/32)]&1<<31-s%32),r&&(n=a(n,o)),c=0!=(1&o[3]),i=3;i>0;i--)o[i]=o[i]>>>1|(1&o[i-1])<<31;o[0]=o[0]>>>1,c&&(o[0]=o[0]^225<<24)}return n},_ghash:function(t,e,s){var i,r,n=s.length;for(i=e.slice(0),r=0;r<n;r+=4)i[0]^=4294967295&s[r],i[1]^=4294967295&s[r+1],i[2]^=4294967295&s[r+2],i[3]^=4294967295&s[r+3],i=sjcl.mode.gcm._galoisMultiply(i,t);return i},_ctrMode:function(t,e,s,i,r,n){var o,c,l,a,h,u,f,d,p,m,b,_,g=sjcl.bitArray;for(p=s.length,m=g.bitLength(s),b=g.bitLength(i),_=g.bitLength(r),o=e.encrypt([0,0,0,0]),96===_?(c=r.slice(0),c=g.concat(c,[1])):(c=sjcl.mode.gcm._ghash(o,[0,0,0,0],r),c=sjcl.mode.gcm._ghash(o,c,[0,0,Math.floor(_/4294967296),4294967295&_])),l=sjcl.mode.gcm._ghash(o,[0,0,0,0],i),u=c.slice(0),f=l.slice(0),t||(f=sjcl.mode.gcm._ghash(o,l,s)),h=0;h<p;h+=4)u[3]++,a=e.encrypt(u),s[h]^=a[0],s[h+1]^=a[1],s[h+2]^=a[2],s[h+3]^=a[3];return s=g.clamp(s,m),t&&(f=sjcl.mode.gcm._ghash(o,l,s)),d=[Math.floor(b/4294967296),4294967295&b,Math.floor(m/4294967296),4294967295&m],f=sjcl.mode.gcm._ghash(o,f,d),a=e.encrypt(c),f[0]^=a[0],f[1]^=a[1],f[2]^=a[2],f[3]^=a[3],{tag:g.bitSlice(f,0,n),data:s}}},sjcl.misc.hmac=function(t,e){this._hash=e=e||sjcl.hash.sha256;var s,i=[[],[]],r=e.prototype.blockSize/32;for(this._baseHash=[new e,new e],t.length>r&&(t=e.hash(t)),s=0;s<r;s++)i[0][s]=909522486^t[s],i[1][s]=1549556828^t[s];this._baseHash[0].update(i[0]),this._baseHash[1].update(i[1]),this._resultHash=new e(this._baseHash[0])},sjcl.misc.hmac.prototype.encrypt=sjcl.misc.hmac.prototype.mac=function(t){if(this._updated)throw new sjcl.exception.invalid("encrypt on already updated hmac called!");return this.update(t),this.digest(t)},sjcl.misc.hmac.prototype.reset=function(){this._resultHash=new this._hash(this._baseHash[0]),this._updated=!1},sjcl.misc.hmac.prototype.update=function(t){this._updated=!0,this._resultHash.update(t)},sjcl.misc.hmac.prototype.digest=function(){var t=this._resultHash.finalize(),e=new this._hash(this._baseHash[1]).update(t).finalize();return this.reset(),e},sjcl.misc.pbkdf2=function(t,e,s,i,r){if(s=s||1e4,i<0||s<0)throw new sjcl.exception.invalid("invalid params to pbkdf2");"string"==typeof t&&(t=sjcl.codec.utf8String.toBits(t)),"string"==typeof e&&(e=sjcl.codec.utf8String.toBits(e)),r=r||sjcl.misc.hmac;var n,o,c,l,a,h=new r(t),u=[],f=sjcl.bitArray;for(a=1;32*u.length<(i||1);a++){for(n=o=h.encrypt(f.concat(e,[a])),c=1;c<s;c++)for(o=h.encrypt(o),l=0;l<o.length;l++)n[l]^=o[l];u=u.concat(n)}return i&&(u=f.clamp(u,i)),u},sjcl.prng=function(t){this._pools=[new sjcl.hash.sha256],this._poolEntropy=[0],this._reseedCount=0,this._robins={},this._eventId=0,this._collectorIds={},this._collectorIdNext=0,this._strength=0,this._poolStrength=0,this._nextReseed=0,this._key=[0,0,0,0,0,0,0,0],this._counter=[0,0,0,0],this._cipher=void 0,this._defaultParanoia=t,this._collectorsStarted=!1,this._callbacks={progress:{},seeded:{}},this._callbackI=0,this._NOT_READY=0,this._READY=1,this._REQUIRES_RESEED=2,this._MAX_WORDS_PER_BURST=65536,this._PARANOIA_LEVELS=[0,48,64,96,128,192,256,384,512,768,1024],this._MILLISECONDS_PER_RESEED=3e4,this._BITS_PER_RESEED=80},sjcl.prng.prototype={randomWords:function(t,e){var s,i,r=[],n=this.isReady(e);if(n===this._NOT_READY)throw new sjcl.exception.notReady("generator isn't seeded");for(n&this._REQUIRES_RESEED&&this._reseedFromPools(!(n&this._READY)),s=0;s<t;s+=4)(s+1)%this._MAX_WORDS_PER_BURST==0&&this._gate(),i=this._gen4words(),r.push(i[0],i[1],i[2],i[3]);return this._gate(),r.slice(0,t)},setDefaultParanoia:function(t,e){if(0===t&&"Setting paranoia=0 will ruin your security; use it only for testing"!==e)throw new sjcl.exception.invalid("Setting paranoia=0 will ruin your security; use it only for testing");this._defaultParanoia=t},addEntropy:function(t,e,s){s=s||"user";var i,r,n,o,c=(new Date).valueOf(),l=this._robins[s],a=this.isReady(),h=0;switch(i=this._collectorIds[s],void 0===i&&(i=this._collectorIds[s]=this._collectorIdNext++),void 0===l&&(l=this._robins[s]=0),this._robins[s]=(this._robins[s]+1)%this._pools.length,typeof t){case"number":void 0===e&&(e=1),this._pools[l].update([i,this._eventId++,1,e,c,1,0|t]);break;case"object":if("[object Uint32Array]"===(o=Object.prototype.toString.call(t))){for(n=[],r=0;r<t.length;r++)n.push(t[r]);t=n}else for("[object Array]"!==o&&(h=1),r=0;r<t.length&&!h;r++)"number"!=typeof t[r]&&(h=1);if(!h){if(void 0===e)for(e=0,r=0;r<t.length;r++)for(n=t[r];n>0;)e++,n>>>=1;this._pools[l].update([i,this._eventId++,2,e,c,t.length].concat(t))}break;case"string":void 0===e&&(e=t.length),this._pools[l].update([i,this._eventId++,3,e,c,t.length]),this._pools[l].update(t);break;default:h=1}if(h)throw new sjcl.exception.bug("random: addEntropy only supports number, array of numbers or string");this._poolEntropy[l]+=e,this._poolStrength+=e,a===this._NOT_READY&&(this.isReady()!==this._NOT_READY&&this._fireEvent("seeded",Math.max(this._strength,this._poolStrength)),this._fireEvent("progress",this.getProgress()))},isReady:function(t){var e=this._PARANOIA_LEVELS[void 0!==t?t:this._defaultParanoia];return this._strength&&this._strength>=e?this._poolEntropy[0]>this._BITS_PER_RESEED&&(new Date).valueOf()>this._nextReseed?this._REQUIRES_RESEED|this._READY:this._READY:this._poolStrength>=e?this._REQUIRES_RESEED|this._NOT_READY:this._NOT_READY},getProgress:function(t){var e=this._PARANOIA_LEVELS[t||this._defaultParanoia];return this._strength>=e?1:this._poolStrength>e?1:this._poolStrength/e},startCollectors:function(){if(!this._collectorsStarted){if(this._eventListener={loadTimeCollector:this._bind(this._loadTimeCollector),mouseCollector:this._bind(this._mouseCollector),keyboardCollector:this._bind(this._keyboardCollector),accelerometerCollector:this._bind(this._accelerometerCollector),touchCollector:this._bind(this._touchCollector)},window.addEventListener)window.addEventListener("load",this._eventListener.loadTimeCollector,!1),window.addEventListener("mousemove",this._eventListener.mouseCollector,!1),window.addEventListener("keypress",this._eventListener.keyboardCollector,!1),window.addEventListener("devicemotion",this._eventListener.accelerometerCollector,!1),window.addEventListener("touchmove",this._eventListener.touchCollector,!1);else{if(!document.attachEvent)throw new sjcl.exception.bug("can't attach event");document.attachEvent("onload",this._eventListener.loadTimeCollector),document.attachEvent("onmousemove",this._eventListener.mouseCollector),document.attachEvent("keypress",this._eventListener.keyboardCollector)}this._collectorsStarted=!0}},stopCollectors:function(){this._collectorsStarted&&(window.removeEventListener?(window.removeEventListener("load",this._eventListener.loadTimeCollector,!1),window.removeEventListener("mousemove",this._eventListener.mouseCollector,!1),window.removeEventListener("keypress",this._eventListener.keyboardCollector,!1),window.removeEventListener("devicemotion",this._eventListener.accelerometerCollector,!1),window.removeEventListener("touchmove",this._eventListener.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this._eventListener.loadTimeCollector),document.detachEvent("onmousemove",this._eventListener.mouseCollector),document.detachEvent("keypress",this._eventListener.keyboardCollector)),this._collectorsStarted=!1)},addEventListener:function(t,e){this._callbacks[t][this._callbackI++]=e},removeEventListener:function(t,e){var s,i,r=this._callbacks[t],n=[];for(i in r)r.hasOwnProperty(i)&&r[i]===e&&n.push(i);for(s=0;s<n.length;s++)i=n[s],delete r[i]},_bind:function(t){var e=this;return function(){t.apply(e,arguments)}},_gen4words:function(){for(var t=0;t<4&&(this._counter[t]=this._counter[t]+1|0,!this._counter[t]);t++);return this._cipher.encrypt(this._counter)},_gate:function(){this._key=this._gen4words().concat(this._gen4words()),this._cipher=new sjcl.cipher.aes(this._key)},_reseed:function(t){this._key=sjcl.hash.sha256.hash(this._key.concat(t)),this._cipher=new sjcl.cipher.aes(this._key);for(var e=0;e<4&&(this._counter[e]=this._counter[e]+1|0,!this._counter[e]);e++);},_reseedFromPools:function(t){var e,s=[],i=0;for(this._nextReseed=s[0]=(new Date).valueOf()+this._MILLISECONDS_PER_RESEED,e=0;e<16;e++)s.push(4294967296*Math.random()|0);for(e=0;e<this._pools.length&&(s=s.concat(this._pools[e].finalize()),i+=this._poolEntropy[e],this._poolEntropy[e]=0,t||!(this._reseedCount&1<<e));e++);this._reseedCount>=1<<this._pools.length&&(this._pools.push(new sjcl.hash.sha256),this._poolEntropy.push(0)),this._poolStrength-=i,i>this._strength&&(this._strength=i),this._reseedCount++,this._reseed(s)},_keyboardCollector:function(){this._addCurrentTimeToEntropy(1)},_mouseCollector:function(t){var e,s;try{e=t.x||t.clientX||t.offsetX||0,s=t.y||t.clientY||t.offsetY||0}catch(t){e=0,s=0}0!=e&&0!=s&&this.addEntropy([e,s],2,"mouse"),this._addCurrentTimeToEntropy(0)},_touchCollector:function(t){var e=t.touches[0]||t.changedTouches[0],s=e.pageX||e.clientX,i=e.pageY||e.clientY;this.addEntropy([s,i],1,"touch"),this._addCurrentTimeToEntropy(0)},_loadTimeCollector:function(){this._addCurrentTimeToEntropy(2)},_addCurrentTimeToEntropy:function(t){"undefined"!=typeof window&&window.performance&&"function"==typeof window.performance.now?this.addEntropy(window.performance.now(),t,"loadtime"):this.addEntropy((new Date).valueOf(),t,"loadtime")},_accelerometerCollector:function(t){var e=t.accelerationIncludingGravity.x||t.accelerationIncludingGravity.y||t.accelerationIncludingGravity.z;if(window.orientation){var s=window.orientation;"number"==typeof s&&this.addEntropy(s,1,"accelerometer")}e&&this.addEntropy(e,2,"accelerometer"),this._addCurrentTimeToEntropy(0)},_fireEvent:function(t,e){var s,i=sjcl.random._callbacks[t],r=[];for(s in i)i.hasOwnProperty(s)&&r.push(i[s]);for(s=0;s<r.length;s++)r[s](e)}},sjcl.random=new sjcl.prng(6),function(){try{var t,e,s;if("undefined"!=typeof module&&module.exports&&(e=function(){try{return require("crypto")}catch(t){return null}}())&&e.randomBytes)t=e.randomBytes(128),t=new Uint32Array(new Uint8Array(t).buffer),sjcl.random.addEntropy(t,1024,"crypto.randomBytes");else if("undefined"!=typeof window&&"undefined"!=typeof Uint32Array){if(s=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(s);else{if(!window.msCrypto||!window.msCrypto.getRandomValues)return;window.msCrypto.getRandomValues(s)}sjcl.random.addEntropy(s,1024,"crypto.getRandomValues")}}catch(t){"undefined"!=typeof window&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(t))}}(),sjcl.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},_encrypt:function(t,e,s,i){s=s||{},i=i||{};var r,n,o,c=sjcl.json,l=c._add({iv:sjcl.random.randomWords(4,0)},c.defaults);if(c._add(l,s),o=l.adata,"string"==typeof l.salt&&(l.salt=sjcl.codec.base64.toBits(l.salt)),"string"==typeof l.iv&&(l.iv=sjcl.codec.base64.toBits(l.iv)),!sjcl.mode[l.mode]||!sjcl.cipher[l.cipher]||"string"==typeof t&&l.iter<=100||64!==l.ts&&96!==l.ts&&128!==l.ts||128!==l.ks&&192!==l.ks&&256!==l.ks||l.iv.length<2||l.iv.length>4)throw new sjcl.exception.invalid("json encrypt: invalid parameters");return"string"==typeof t?(r=sjcl.misc.cachedPbkdf2(t,l),t=r.key.slice(0,l.ks/32),l.salt=r.salt):sjcl.ecc&&t instanceof sjcl.ecc.elGamal.publicKey&&(r=t.kem(),l.kemtag=r.tag,t=r.key.slice(0,l.ks/32)),"string"==typeof e&&(e=sjcl.codec.utf8String.toBits(e)),"string"==typeof o&&(l.adata=o=sjcl.codec.utf8String.toBits(o)),n=new sjcl.cipher[l.cipher](t),c._add(i,l),i.key=t,"ccm"===l.mode&&sjcl.arrayBuffer&&sjcl.arrayBuffer.ccm&&e instanceof ArrayBuffer?l.ct=sjcl.arrayBuffer.ccm.encrypt(n,e,l.iv,o,l.ts):l.ct=sjcl.mode[l.mode].encrypt(n,e,l.iv,o,l.ts),l},encrypt:function(t,e,s,i){var r=sjcl.json,n=r._encrypt.apply(r,arguments);return r.encode(n)},_decrypt:function(t,e,s,i){s=s||{},i=i||{};var r,n,o,c=sjcl.json,l=c._add(c._add(c._add({},c.defaults),e),s,!0),a=l.adata;if("string"==typeof l.salt&&(l.salt=sjcl.codec.base64.toBits(l.salt)),"string"==typeof l.iv&&(l.iv=sjcl.codec.base64.toBits(l.iv)),!sjcl.mode[l.mode]||!sjcl.cipher[l.cipher]||"string"==typeof t&&l.iter<=100||64!==l.ts&&96!==l.ts&&128!==l.ts||128!==l.ks&&192!==l.ks&&256!==l.ks||!l.iv||l.iv.length<2||l.iv.length>4)throw new sjcl.exception.invalid("json decrypt: invalid parameters");return"string"==typeof t?(n=sjcl.misc.cachedPbkdf2(t,l),t=n.key.slice(0,l.ks/32),l.salt=n.salt):sjcl.ecc&&t instanceof sjcl.ecc.elGamal.secretKey&&(t=t.unkem(sjcl.codec.base64.toBits(l.kemtag)).slice(0,l.ks/32)),"string"==typeof a&&(a=sjcl.codec.utf8String.toBits(a)),o=new sjcl.cipher[l.cipher](t),r="ccm"===l.mode&&sjcl.arrayBuffer&&sjcl.arrayBuffer.ccm&&l.ct instanceof ArrayBuffer?sjcl.arrayBuffer.ccm.decrypt(o,l.ct,l.iv,l.tag,a,l.ts):sjcl.mode[l.mode].decrypt(o,l.ct,l.iv,a,l.ts),c._add(i,l),i.key=t,1===s.raw?r:sjcl.codec.utf8String.fromBits(r)},decrypt:function(t,e,s,i){var r=sjcl.json;return r._decrypt(t,r.decode(e),s,i)},encode:function(t){var e,s="{",i="";for(e in t)if(t.hasOwnProperty(e)){if(!e.match(/^[a-z0-9]+$/i))throw new sjcl.exception.invalid("json encode: invalid property name");switch(s+=i+'"'+e+'":',i=",",typeof t[e]){case"number":case"boolean":s+=t[e];break;case"string":s+='"'+escape(t[e])+'"';break;case"object":s+='"'+sjcl.codec.base64.fromBits(t[e],0)+'"';break;default:throw new sjcl.exception.bug("json encode: unsupported type")}}return s+"}"},decode:function(t){if(t=t.replace(/\s/g,""),!t.match(/^\{.*\}$/))throw new sjcl.exception.invalid("json decode: this isn't json!");var e,s,i=t.replace(/^\{|\}$/g,"").split(/,/),r={};for(e=0;e<i.length;e++){if(!(s=i[e].match(/^\s*(?:(["']?)([a-z][a-z0-9]*)\1)\s*:\s*(?:(-?\d+)|"([a-z0-9+\/%*_.@=\-]*)"|(true|false))$/i)))throw new sjcl.exception.invalid("json decode: this isn't json!");null!=s[3]?r[s[2]]=parseInt(s[3],10):null!=s[4]?r[s[2]]=s[2].match(/^(ct|adata|salt|iv)$/)?sjcl.codec.base64.toBits(s[4]):unescape(s[4]):null!=s[5]&&(r[s[2]]="true"===s[5])}return r},_add:function(t,e,s){if(void 0===t&&(t={}),void 0===e)return t;var i;for(i in e)if(e.hasOwnProperty(i)){if(s&&void 0!==t[i]&&t[i]!==e[i])throw new sjcl.exception.invalid("required parameter overridden");t[i]=e[i]}return t},_subtract:function(t,e){var s,i={};for(s in t)t.hasOwnProperty(s)&&t[s]!==e[s]&&(i[s]=t[s]);return i},_filter:function(t,e){var s,i={};for(s=0;s<e.length;s++)void 0!==t[e[s]]&&(i[e[s]]=t[e[s]]);return i}},sjcl.encrypt=sjcl.json.encrypt,sjcl.decrypt=sjcl.json.decrypt,sjcl.misc._pbkdf2Cache={},sjcl.misc.cachedPbkdf2=function(t,e){var s,i,r,n,o=sjcl.misc._pbkdf2Cache;return e=e||{},n=e.iter||1e3,i=o[t]=o[t]||{},s=i[n]=i[n]||{firstSalt:e.salt&&e.salt.length?e.salt.slice(0):sjcl.random.randomWords(2,0)},r=void 0===e.salt?s.firstSalt:e.salt,s[r]=s[r]||sjcl.misc.pbkdf2(t,r,e.iter),{key:s[r].slice(0),salt:r.slice(0)}},sjcl.bn=function(t){this.initWith(t)},sjcl.bn.prototype={radix:24,maxMul:8,_class:sjcl.bn,copy:function(){return new this._class(this)},initWith:function(t){var e,s=0;switch(typeof t){case"object":this.limbs=t.limbs.slice(0);break;case"number":this.limbs=[t],this.normalize();break;case"string":for(t=t.replace(/^0x/,""),this.limbs=[],e=this.radix/4,s=0;s<t.length;s+=e)this.limbs.push(parseInt(t.substring(Math.max(t.length-s-e,0),t.length-s),16));break;default:this.limbs=[0]}return this},equals:function(t){"number"==typeof t&&(t=new this._class(t));var e,s=0;for(this.fullReduce(),t.fullReduce(),e=0;e<this.limbs.length||e<t.limbs.length;e++)s|=this.getLimb(e)^t.getLimb(e);return 0===s},getLimb:function(t){return t>=this.limbs.length?0:this.limbs[t]},greaterEquals:function(t){"number"==typeof t&&(t=new this._class(t));var e,s,i,r=0,n=0;for(e=Math.max(this.limbs.length,t.limbs.length)-1;e>=0;e--)s=this.getLimb(e),i=t.getLimb(e),n|=i-s&~r,r|=s-i&~n;return(n|~r)>>>31},toString:function(){this.fullReduce();var t,e,s="",i=this.limbs;for(t=0;t<this.limbs.length;t++){for(e=i[t].toString(16);t<this.limbs.length-1&&e.length<6;)e="0"+e;s=e+s}return"0x"+s},addM:function(t){"object"!=typeof t&&(t=new this._class(t));var e,s=this.limbs,i=t.limbs;for(e=s.length;e<i.length;e++)s[e]=0;for(e=0;e<i.length;e++)s[e]+=i[e];return this},doubleM:function(){var t,e,s=0,i=this.radix,r=this.radixMask,n=this.limbs;for(t=0;t<n.length;t++)e=n[t],e=e+e+s,n[t]=e&r,s=e>>i;return s&&n.push(s),this},halveM:function(){var t,e,s=0,i=this.radix,r=this.limbs;for(t=r.length-1;t>=0;t--)e=r[t],r[t]=e+s>>1,s=(1&e)<<i;return r[r.length-1]||r.pop(),this},subM:function(t){"object"!=typeof t&&(t=new this._class(t));var e,s=this.limbs,i=t.limbs;for(e=s.length;e<i.length;e++)s[e]=0;for(e=0;e<i.length;e++)s[e]-=i[e];return this},mod:function(t){var e=!this.greaterEquals(new sjcl.bn(0))
;t=new sjcl.bn(t).normalize();var s=new sjcl.bn(this).normalize(),i=0;for(e&&(s=new sjcl.bn(0).subM(s).normalize());s.greaterEquals(t);i++)t.doubleM();for(e&&(s=t.sub(s).normalize());i>0;i--)t.halveM(),s.greaterEquals(t)&&s.subM(t).normalize();return s.trim()},inverseMod:function(t){var e,s,i=new sjcl.bn(1),r=new sjcl.bn(0),n=new sjcl.bn(this),o=new sjcl.bn(t),c=1;if(!(1&t.limbs[0]))throw new sjcl.exception.invalid("inverseMod: p must be odd");do{for(1&n.limbs[0]&&(n.greaterEquals(o)||(e=n,n=o,o=e,e=i,i=r,r=e),n.subM(o),n.normalize(),i.greaterEquals(r)||i.addM(t),i.subM(r)),n.halveM(),1&i.limbs[0]&&i.addM(t),i.normalize(),i.halveM(),s=c=0;s<n.limbs.length;s++)c|=n.limbs[s]}while(c);if(!o.equals(1))throw new sjcl.exception.invalid("inverseMod: p and x must be relatively prime");return r},add:function(t){return this.copy().addM(t)},sub:function(t){return this.copy().subM(t)},mul:function(t){"number"==typeof t&&(t=new this._class(t));var e,s,i,r=this.limbs,n=t.limbs,o=r.length,c=n.length,l=new this._class,a=l.limbs,h=this.maxMul;for(e=0;e<this.limbs.length+t.limbs.length+1;e++)a[e]=0;for(e=0;e<o;e++){for(i=r[e],s=0;s<c;s++)a[e+s]+=i*n[s];--h||(h=this.maxMul,l.cnormalize())}return l.cnormalize().reduce()},square:function(){return this.mul(this)},power:function(t){t=new sjcl.bn(t).normalize().trim().limbs;var e,s,i=new this._class(1),r=this;for(e=0;e<t.length;e++)for(s=0;s<this.radix&&(t[e]&1<<s&&(i=i.mul(r)),e!=t.length-1||t[e]>>s+1!=0);s++)r=r.square();return i},mulmod:function(t,e){return this.mod(e).mul(t.mod(e)).mod(e)},powermod:function(t,e){if(t=new sjcl.bn(t),e=new sjcl.bn(e),1==(1&e.limbs[0])){var s=this.montpowermod(t,e);if(0!=s)return s}var i,r,n=t.normalize().trim().limbs,o=new this._class(1),c=this;for(i=0;i<n.length;i++)for(r=0;r<this.radix&&(n[i]&1<<r&&(o=o.mulmod(c,e)),i!=n.length-1||n[i]>>r+1!=0);r++)c=c.mulmod(c,e);return o},montpowermod:function(t,e){t=new sjcl.bn(t).normalize().trim(),e=new sjcl.bn(e);var s,i,r,n,o,c=this.radix,l=new this._class(1),a=this.copy(),h=t.bitLength();for(r=new sjcl.bn({limbs:e.copy().normalize().trim().limbs.map(function(){return 0})}),n=this.radix;n>0;n--)if(1==(e.limbs[e.limbs.length-1]>>n&1)){r.limbs[r.limbs.length-1]=1<<n;break}if(0==h)return this;o=h<18?1:h<48?3:h<144?4:h<768?5:6;for(var u=r.copy(),f=e.copy(),d=new sjcl.bn(1),p=new sjcl.bn(0),m=r.copy();m.greaterEquals(1);)m.halveM(),0==(1&d.limbs[0])?(d.halveM(),p.halveM()):(d.addM(f),d.halveM(),p.halveM(),p.addM(u));d=d.normalize(),p=p.normalize(),u.doubleM();var b=u.mulmod(u,e);if(!u.mul(d).sub(e.mul(p)).equals(1))return!1;var _=function(t){return g(t,b)},g=function(t,s){var i,o,l,a,h=(1<<n+1)-1;for(o=t.mul(s),l=o.mul(p),l.limbs=l.limbs.slice(0,r.limbs.length),l.limbs.length==r.limbs.length&&(l.limbs[r.limbs.length-1]&=h),l=l.mul(e),a=o.add(l).normalize().trim(),a.limbs=a.limbs.slice(r.limbs.length-1),i=0;i<a.limbs.length;i++)i>0&&(a.limbs[i-1]|=(a.limbs[i]&h)<<c-n-1),a.limbs[i]=a.limbs[i]>>n+1;return a.greaterEquals(e)&&a.subM(e),a};a=_(a),l=_(l);var y,j={},v=(1<<o-1)-1;for(j[1]=a.copy(),j[2]=g(a,a),y=1;y<=v;y++)j[2*y+1]=g(j[2*y-1],j[2]);var w=function(t,e){var s=e%t.radix;return(t.limbs[Math.floor(e/t.radix)]&1<<s)>>s};for(s=t.bitLength()-1;s>=0;)if(0==w(t,s))l=g(l,l),s-=1;else{for(var E=s-o+1;0==w(t,E);)E++;var x=0;for(i=E;i<=s;i++)x+=w(t,i)<<i-E,l=g(l,l);l=g(l,j[x]),s=E-1}return function(t){return g(t,1)}(l)},trim:function(){var t,e=this.limbs;do{t=e.pop()}while(e.length&&0===t);return e.push(t),this},reduce:function(){return this},fullReduce:function(){return this.normalize()},normalize:function(){var t,e,s,i=0,r=this.placeVal,n=this.ipv,o=this.limbs,c=o.length,l=this.radixMask;for(t=0;t<c||0!==i&&-1!==i;t++)e=(o[t]||0)+i,s=o[t]=e&l,i=(e-s)*n;return-1===i&&(o[t-1]-=r),this.trim(),this},cnormalize:function(){var t,e,s,i=0,r=this.ipv,n=this.limbs,o=n.length,c=this.radixMask;for(t=0;t<o-1;t++)e=n[t]+i,s=n[t]=e&c,i=(e-s)*r;return n[t]+=i,this},toBits:function(t){this.fullReduce(),t=t||this.exponent||this.bitLength();var e=Math.floor((t-1)/24),s=sjcl.bitArray,i=(t+7&-8)%this.radix||this.radix,r=[s.partial(i,this.getLimb(e))];for(e--;e>=0;e--)r=s.concat(r,[s.partial(Math.min(this.radix,t),this.getLimb(e))]),t-=this.radix;return r},bitLength:function(){this.fullReduce();for(var t=this.radix*(this.limbs.length-1),e=this.limbs[this.limbs.length-1];e;e>>>=1)t++;return t+7&-8}},sjcl.bn.fromBits=function(t){var e=this,s=new e,i=[],r=sjcl.bitArray,n=this.prototype,o=Math.min(this.bitLength||4294967296,r.bitLength(t)),c=o%n.radix||n.radix;for(i[0]=r.extract(t,0,c);c<o;c+=n.radix)i.unshift(r.extract(t,c,n.radix));return s.limbs=i,s},sjcl.bn.prototype.ipv=1/(sjcl.bn.prototype.placeVal=Math.pow(2,sjcl.bn.prototype.radix)),sjcl.bn.prototype.radixMask=(1<<sjcl.bn.prototype.radix)-1,sjcl.bn.pseudoMersennePrime=function(t,e){function s(t){this.initWith(t)}var i,r,n,o=s.prototype=new sjcl.bn;for(n=o.modOffset=Math.ceil(r=t/o.radix),o.exponent=t,o.offset=[],o.factor=[],o.minOffset=n,o.fullMask=0,o.fullOffset=[],o.fullFactor=[],o.modulus=s.modulus=new sjcl.bn(Math.pow(2,t)),o.fullMask=0|-Math.pow(2,t%o.radix),i=0;i<e.length;i++)o.offset[i]=Math.floor(e[i][0]/o.radix-r),o.fullOffset[i]=Math.ceil(e[i][0]/o.radix-r),o.factor[i]=e[i][1]*Math.pow(.5,t-e[i][0]+o.offset[i]*o.radix),o.fullFactor[i]=e[i][1]*Math.pow(.5,t-e[i][0]+o.fullOffset[i]*o.radix),o.modulus.addM(new sjcl.bn(Math.pow(2,e[i][0])*e[i][1])),o.minOffset=Math.min(o.minOffset,-o.offset[i]);return o._class=s,o.modulus.cnormalize(),o.reduce=function(){var t,e,s,i,r=this.modOffset,n=this.limbs,o=this.offset,c=this.offset.length,l=this.factor;for(t=this.minOffset;n.length>r;){for(s=n.pop(),i=n.length,e=0;e<c;e++)n[i+o[e]]-=l[e]*s;t--,t||(n.push(0),this.cnormalize(),t=this.minOffset)}return this.cnormalize(),this},o._strongReduce=-1===o.fullMask?o.reduce:function(){var t,e,s=this.limbs,i=s.length-1;if(this.reduce(),i===this.modOffset-1){for(e=s[i]&this.fullMask,s[i]-=e,t=0;t<this.fullOffset.length;t++)s[i+this.fullOffset[t]]-=this.fullFactor[t]*e;this.normalize()}},o.fullReduce=function(){var t,e;for(this._strongReduce(),this.addM(this.modulus),this.addM(this.modulus),this.normalize(),this._strongReduce(),e=this.limbs.length;e<this.modOffset;e++)this.limbs[e]=0;for(t=this.greaterEquals(this.modulus),e=0;e<this.limbs.length;e++)this.limbs[e]-=this.modulus.limbs[e]*t;return this.cnormalize(),this},o.inverse=function(){return this.power(this.modulus.sub(2))},s.fromBits=sjcl.bn.fromBits,s};var sbp=sjcl.bn.pseudoMersennePrime;sjcl.bn.prime={p127:sbp(127,[[0,-1]]),p25519:sbp(255,[[0,-19]]),p192k:sbp(192,[[32,-1],[12,-1],[8,-1],[7,-1],[6,-1],[3,-1],[0,-1]]),p224k:sbp(224,[[32,-1],[12,-1],[11,-1],[9,-1],[7,-1],[4,-1],[1,-1],[0,-1]]),p256k:sbp(256,[[32,-1],[9,-1],[8,-1],[7,-1],[6,-1],[4,-1],[0,-1]]),p192:sbp(192,[[0,-1],[64,-1]]),p224:sbp(224,[[0,1],[96,-1]]),p256:sbp(256,[[0,-1],[96,1],[192,1],[224,-1]]),p384:sbp(384,[[0,-1],[32,1],[96,-1],[128,-1]]),p521:sbp(521,[[0,-1]])},sjcl.bn.random=function(t,e){"object"!=typeof t&&(t=new sjcl.bn(t));for(var s,i,r=t.limbs.length,n=t.limbs[r-1]+1,o=new sjcl.bn;;){do{s=sjcl.random.randomWords(r,e),s[r-1]<0&&(s[r-1]+=4294967296)}while(Math.floor(s[r-1]/n)===Math.floor(4294967296/n));for(s[r-1]%=n,i=0;i<r-1;i++)s[i]&=t.radixMask;if(o.limbs=s,!o.greaterEquals(t))return o}},"undefined"!=typeof module&&module.exports&&(module.exports=sjcl),"function"==typeof define&&define([],function(){return sjcl});
},{"crypto":undefined}],2:[function(require,module,exports){
"use strict";var sprintf=require("./eb-util-sprintf"),ebextend=require("./eb-util-extend"),inherit=require("./eb-util-inherit"),RetryHandler=require("./eb-util-retry"),sjcl=require("./built/sjcl/sjcl.max"),BigInteger=require("jsbn").BigInteger,superagent=require("superagent"),modurl=require("url"),Promise=require("bluebird");Function.prototype.inheritsFrom=function(e,t){return e.constructor===Function?(this.prototype=new e,this.prototype.constructor=this,this.prototype.parent=e.prototype,this.superclass=e.prototype,this.prototype=ebextend(this.prototype,t)):(this.prototype=e,this.prototype.constructor=this,this.prototype.parent=e,this.superclass=e),this};var eb={name:"EB",exception:{},codec:{},padding:{},math:{},comm:{},client:{}};eb.exception={corrupt:function(e){this.toString=function(){return"CORRUPT: "+this.message},this.message=e},invalid:function(e){this.toString=function(){return"INVALID: "+this.message},this.message=e}},eb.misc={name:"misc",MAX_SAFE_INTEGER:Math.pow(2,53)-1,MIN_SAFE_INTEGER:-(Math.pow(2,53)-1),EPSILON:2.220446049250313e-16,sprintf:sprintf,extend:ebextend,inherit:inherit,RetryHandler:RetryHandler,sjcl:sjcl,BigInteger:BigInteger,superagent:superagent,url:modurl,Promise:Promise,genNonce:function(e,t){var i="",s=t.length,o=0;for(o=0;o<e;o++)i+=t.charAt((65535&sjcl.random.randomWords(1)[0])%s);return i},genHexNonce:function(e){return this.genNonce(e,"0123456789abcdef")},genAlphaNonce:function(e){return this.genNonce(e,"0123456789abcdefghijklmnopqrstuvwxyz")},xor:function(e,t){return[e[0]^t[0],e[1]^t[1],e[2]^t[2],e[3]^t[3]]},xor8:function(e,t){return[e[0]^t[0],e[1]^t[1],e[2]^t[2],e[3]^t[3],e[4]^t[4],e[5]^t[5],e[6]^t[6],e[7]^t[7]]},absorb:function(e,t){if(void 0===t)return e;for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);return e},absorbKey:function(e,t,i){return void 0!==t&&i in t&&(e[i]=t[i]),e},absorbKeyEx:function(e,t,i,s){return void 0!==i&&s in i&&(e[t]=i[s]),e},absorbKeyIfNotSet:function(e,t,i,s){return!(void 0!==i&&s in i&&void 0!==i[s]&&void 0!==e)||t in e&&void 0!==e[t]||(e[t]=i[s]),e},absorbValue:function(e,t,i,s){void 0!==t?e[i]=t:void 0!==s&&(e[i]=s)},inputToBits:function(e){if("number"==typeof e)return sjcl.codec.hex.toBits(sprintf("%02x",e));if("string"==typeof e){if(e=e.trim().replace(/^0x/,""),!e.match(/^[0-9A-Fa-f]+$/))throw new eb.exception.invalid("Invalid hex coded number");return sjcl.codec.hex.toBits(e)}return e},inputToHex:function(e){if("number"==typeof e)return sprintf("%x",e);if("string"==typeof e){if(e=e.trim().replace(/^0x/,""),!e.match(/^[0-9A-Fa-f]+$/))throw new eb.exception.invalid("Invalid hex coded number");return e}return sjcl.codec.hex.fromBits(e)},inputToHexNum:function(e,t){if("number"==typeof e)return e;if("string"==typeof e){if(e=e.trim().replace(/^0x/,""),!e.match(/^[0-9A-Fa-f]+$/))throw new eb.exception.invalid("Invalid hex coded number");return parseInt(e,16)}if(void 0!==t&&t)return e;throw new eb.exception.invalid("Invalid argument - not a number or string")},getZeroBits:function(e){if(e<=0)return[];var t,i=[0,0,0,0,0,0,0,0];for(t=256;t<e;t+=32)i.push(0);return sjcl.bitArray.bitSlice(i,0,e)},getRandomBits:function(e){return sjcl.bitArray.clamp(sjcl.random.randomWords(Math.ceil(e/32)),e)},numberToBits:function(e,t){if(t>32)throw new eb.exception.invalid("num can be maximally 32bit wide");return 32==t?[e]:sjcl.bitArray.bitSlice([e],32-t,32)},replacePart:function(e,t,i,s){var o=sjcl.bitArray,n=o.concat(o.bitSlice(e,0,t),s);return n=o.concat(n,o.bitSlice(e,i))},transformPart:function(e,t,i,s){var o=sjcl.bitArray,n=o.bitSlice(e,t,i),r=o.concat(o.bitSlice(e,0,t),s(n));return r=o.concat(r,o.bitSlice(e,i))},serialize64bit:function(e){return[Math.floor(e/4294967296),0|e]},deserialize64bit:function(e,t){t=t||0;var i=sjcl.bitArray,s=i.extract32(e,t),o=i.extract32(e,t+32);return 4294967296*s+o+(o<0?4294967296:0)},padHexToEven:function(e){return e=e.trim().replace(/[\s]+/g,"").replace(/^0x/,""),1==(1&e.length)?"0"+e:e},padHexToSize:function(e,t){return e=e.trim().replace(/[\s]+/g,"").replace(/^0x/,""),e.length<t?"0".repeat(t-e.length)+e:e},padToBlockSize:function(e,t){return e+(t-e%t)},strByteLength:function(e){for(var t=e.length,i=e.length-1;i>=0;i--){var s=e.charCodeAt(i);s>127&&s<=2047?t++:s>2047&&s<=65535&&(t+=2),s>=56320&&s<=57343&&i--}return t},isDefined:function(e,t){return void 0!==e&&t in e&&void 0!==e[t]},genChecksumValue:function(e,t){var i,s=eb.misc.inputToBits(e),o=sjcl.codec.hex.fromBits(s)+","+t+","+sjcl.bitArray.bitLength(s),n=sjcl.hash.sha256.hash(o),r=sjcl.hash.sha256.hash(sjcl.codec.hex.fromBits(n)+o),c=[];for(i=0;i<8;i++)c[i]=n[i]^r[i];return sjcl.codec.base32.fromBits(c).substring(0,t)},genChecksumValueFromString:function(e,t){return eb.misc.genChecksumValue(sjcl.hash.sha256.hash(e),t)},assert:function(e,t){if(!e){if(t=t||"Assertion failed","undefined"!=typeof Error)throw new Error(t);throw t}},parseUrl:function(e,t){t=t||!1;var i=eb.misc.url.parse(e,t);if(void 0!==i.protocol){var s=i.protocol;i.scheme=":"===s.slice(-1)?s.substring(0,s.length-1):s}return i},regenerateCommKeys:function(e){var t=sjcl.bitArray,i=eb.misc.inputToBits(e);return{enc:sjcl.hash.sha256.hash(t.concat(i,[1])),mac:sjcl.hash.sha256.hash(t.concat(i,[2]))}},def:function(e,t){return void 0===e?t:e}},eb.codec.utf8={toHex:function(e,t){var i,s=e.length,o="";for(i=0;i<s;i++){var n=e.charAt(i),r=s-i-1;if("\\"!==n){var c,a,h=unescape(encodeURIComponent(n));for(c=0,a=h.length;c<a;c++){var u=Number(h.charCodeAt(c)).toString(16);1==(1&u.length)&&(u="0"+u),o+=u}}else{if(r>=3){var p=e.substring(i,i+4),d=/\\x([a-fA-F0-9]{2})/g,l=d.exec(p);if(l){o+=l[1],i+=3;continue}}if(r>=1){if("\\"===e.substring(i+1,i+2)){o+=Number("\\".charCodeAt(0)).toString(16),i+=1;continue}}}}return o},fromHex:function(e,t){var i,s,o,n=eb.codec.utf8.fromHexParse(e,t),r="";for(s=0,o=n.parsed.length;s<o;s++)i=n.parsed[s],r+=i.utf8?i.rep:i.enc;return r},fromHexParse:function(e,t){t=ebextend({acceptUtf8:!0,acceptOnlyUtf8:!1},t||{});var i=sjcl.codec.hex,s=t&&t.acceptUtf8,o=t&&t.acceptOnlyUtf8,n=e.length;1==(1&n)&&(n-=1);var r,c,a,h,u=0,p=[];for(r=0;r<n;r+=2)if(c=(e[r]+e[r+1]).toUpperCase(),a=i.toBits(c),h=sjcl.bitArray.extract(a,0,8),s&&0!=(128&h)){var d=(n-r-2)/2,l=!1,m=0;for(m=2;m<=6;m++){var b=Math.pow(2,m)-1<<1,f=h>>8-m-1;if(b===f){if(d<m-1)break;var g=i.toBits(sprintf("0000%x",h&(1<<8-m-1)-1)),y=sjcl.bitArray.bitLength(g);y>8-m-1&&(g=sjcl.bitArray.bitSlice(g,y-(8-m-1)));var _=0,v=!0;for(_=0;_<m-1;_++){var T=eb.codec.utf8.getByte(e,r+2+2*_);if(T>>>6!=2){v=!1;break}var R=i.toBits(sprintf("0000%x",63&T)),A=sjcl.bitArray.bitLength(R);A>=7&&(R=sjcl.bitArray.bitSlice(R,A-6)),g=sjcl.bitArray.concat(g,R)}if(!v)break;if(0!=(7&(y=sjcl.bitArray.bitLength(g)))){var x=8-(7&y);g=sjcl.bitArray.concat(sjcl.bitArray.bitSlice([0,0,0,0],0,x),g)}l=!0,p.push({b:m,utf8:!0,hex:c+e.substring(r+2,r+2+2*(m-1)),enc:"\\u"+i.fromBits(g),rep:String.fromCharCode(parseInt(i.fromBits(g),16))}),r+=2*(m-1);break}}l||o||(p.push({b:1,utf8:!1,hex:c,enc:"\\x"+c,rep:"\\x"+c}),u+=1)}else{var S=String.fromCharCode(h);"\\"===S&&(S="\\\\"),p.push({b:1,utf8:!0,hex:c,enc:String.fromCharCode(h),rep:h<32||h>=127?"\\x"+c:S})}return{nonUtf8Chars:u,parsed:p}},getByte:function(e,t){var i=e[t]+e[t+1],s=sjcl.codec.hex.toBits(i);return sjcl.bitArray.extract(s,0,8)}},eb.padding={name:"padding"},eb.padding.empty={name:"empty",pad:function(e,t){return e},unpad:function(e,t){return e}},eb.padding.pkcs7={name:"pkcs7",pad:function(e,t){if(!(t=t||16)||t&t-1)throw new sjcl.exception.corrupt("blocklength has to be power of 2");if(16!==t)throw new sjcl.exception.corrupt("blocklength different than 16 is not implemented yet");var i=sjcl.bitArray.bitLength(e),s=16-(i>>3&15),o=16843009*s;return sjcl.bitArray.concat(e,[o,o,o,o]).slice(0,(i>>3)+s>>2)},unpad:function(e,t){if(!(t=t||16)||t&t-1)throw new sjcl.exception.corrupt("blocklength has to be power of 2");if(16!==t)throw new sjcl.exception.corrupt("blocklength different than 16 is not implemented yet");var i=sjcl.bitArray,s=i.bitLength(e);if(127&s||!e.length)throw new sjcl.exception.corrupt("input must be a positive multiple of the block size");var o=255&e[(s>>3>>2)-1];if(0===o||o>16)throw new sjcl.exception.corrupt("pkcs#5 padding corrupt");var n=16843009*o;if(!i.equal(i.bitSlice([n,n,n,n],0,o<<3),i.bitSlice(e,(e.length<<5)-(o<<3),e.length<<5)))throw new sjcl.exception.corrupt("pkcs#5 padding corrupt");return i.bitSlice(e,0,(e.length<<5)-(o<<3))}},eb.padding.pkcs15={name:"pkcs1.5",pad:function(e,t,i){var s=sjcl.bitArray,o=s.bitLength(e),n=o/8;if(void 0===i&&(i=0),7&o||!e.length)throw new sjcl.exception.corrupt("input type has to have be byte padded, bl="+o);if(0!==i&&1!==i&&2!==i)throw new sjcl.exception.corrupt("invalid BT size");if(n+3>t)throw new sjcl.exception.corrupt("data to pad is too big for the padding block length");var r,c=t-3-n,a=[],h=0;for(r=0;r<c;r++){var u=0;if(1===i)u=255;else if(2===i)do{u=255&sjcl.random.randomWords(1)[0]}while(0===u);h=h<<8|u,3==(3&r)&&(a.push(h),h=0)}3&r&&a.push(sjcl.bitArray.partial(8*(3&r),h));var p=[sjcl.bitArray.partial(8,0)];return p=s.concat(p,[sjcl.bitArray.partial(8,i)]),p=s.concat(p,a),p=s.concat(p,[sjcl.bitArray.partial(8,0)]),s.concat(p,e)},unpad:function(e){var t=sjcl.bitArray,i=t.bitLength(e),s=i/8;if(7&i||s<3||!e.length)throw new sjcl.exception.corrupt("data size block is invalid");var o=0;if(0!==t.extract(e,o,8))throw new sjcl.exception.corrupt("data size block is invalid");o+=8;var n=t.extract(e,o,8);if(0!==n&&1!==n&&2!==n)throw new sjcl.exception.corrupt("Padding data error, BT is outside of the definition set");var r=-1,c=0,a=0;if(0===n){for(c=2;c<s;c++)if(0!==(a=t.extract(e,8*c,8))){r=c;break}}else if(1===n){var h=!0;for(c=2;c<s;c++)if(a=t.extract(e,8*c,8),0!==a&&255