UNPKG

node-adyen-encrypt

Version:
1 lines 40.9 kB
var window={},navigator={},document={};!function(t,e){!function(){try{new Uint8Array(1),new Uint32Array(1),new Int32Array(1);return}catch(t){}function t(t,e){return this.slice(t,e)}function e(t,e){arguments.length<2&&(e=0);for(var n=0,r=t.length;n<r;++n,++e)this[e]=255&t[n]}function n(n){var r;if("number"==typeof n){r=new Array(n);for(var i=0;i<n;++i)r[i]=0}else r=n.slice(0);return r.subarray=t,r.buffer=r,r.byteLength=r.length,r.set=e,"object"==typeof n&&n.buffer&&(r.buffer=n.buffer),r}try{window.Uint8Array=n}catch(t){}try{window.Uint32Array=n}catch(t){}try{window.Int32Array=n}catch(t){}}(),function(){if(!("btoa"in window)){var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";window.btoa=function(e){var n,r,i="";for(n=0,r=e.length;n<r;n+=3){var o=255&e.charCodeAt(n),s=255&e.charCodeAt(n+1),a=255&e.charCodeAt(n+2),c=(3&o)<<4|s>>4,h=n+1<r?(15&s)<<2|a>>6:64,u=n+2<r?63&a:64;i+=t.charAt(o>>2)+t.charAt(c)+t.charAt(h)+t.charAt(u)}return i}}}();var n,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i="=";function o(t,e,n){null!=t&&("number"==typeof t?this.fromNumber(t,e,n):null==e&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,e))}function s(){return new o(null)}"Microsoft Internet Explorer"==navigator.appName?(o.prototype.am=function(t,e,n,r,i,o){for(var s=32767&e,a=e>>15;--o>=0;){var c=32767&this[t],h=this[t++]>>15,u=a*c+h*s;i=((c=s*c+((32767&u)<<15)+n[r]+(1073741823&i))>>>30)+(u>>>15)+a*h+(i>>>30),n[r++]=1073741823&c}return i},n=30):"Netscape"!=navigator.appName?(o.prototype.am=function(t,e,n,r,i,o){for(;--o>=0;){var s=e*this[t++]+n[r]+i;i=Math.floor(s/67108864),n[r++]=67108863&s}return i},n=26):(o.prototype.am=function(t,e,n,r,i,o){for(var s=16383&e,a=e>>14;--o>=0;){var c=16383&this[t],h=this[t++]>>14,u=a*c+h*s;i=((c=s*c+((16383&u)<<14)+n[r]+i)>>28)+(u>>14)+a*h,n[r++]=268435455&c}return i},n=28),o.prototype.DB=n,o.prototype.DM=(1<<n)-1,o.prototype.DV=1<<n;o.prototype.FV=Math.pow(2,52),o.prototype.F1=52-n,o.prototype.F2=2*n-52;var a,c,h="0123456789abcdefghijklmnopqrstuvwxyz",u=new Array;for(a="0".charCodeAt(0),c=0;c<=9;++c)u[a++]=c;for(a="a".charCodeAt(0),c=10;c<36;++c)u[a++]=c;for(a="A".charCodeAt(0),c=10;c<36;++c)u[a++]=c;function l(t){return h.charAt(t)}function f(t,e){var n=u[t.charCodeAt(e)];return null==n?-1:n}function p(t){var e=s();return e.fromInt(t),e}function d(t){var e,n=1;return 0!=(e=t>>>16)&&(t=e,n+=16),0!=(e=t>>8)&&(t=e,n+=8),0!=(e=t>>4)&&(t=e,n+=4),0!=(e=t>>2)&&(t=e,n+=2),0!=(e=t>>1)&&(t=e,n+=1),n}function m(t){this.m=t}function y(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}function v(){this.i=0,this.j=0,this.S=new Array}m.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},m.prototype.revert=function(t){return t},m.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},m.prototype.mulTo=function(t,e,n){t.multiplyTo(e,n),this.reduce(n)},m.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},y.prototype.convert=function(t){var e=s();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(o.ZERO)>0&&this.m.subTo(e,e),e},y.prototype.revert=function(t){var e=s();return t.copyTo(e),this.reduce(e),e},y.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e<this.m.t;++e){var n=32767&t[e],r=n*this.mpl+((n*this.mph+(t[e]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[n=e+this.m.t]+=this.m.am(0,r,t,e,0,this.m.t);t[n]>=t.DV;)t[n]-=t.DV,t[++n]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},y.prototype.mulTo=function(t,e,n){t.multiplyTo(e,n),this.reduce(n)},y.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},o.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},o.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},o.prototype.fromString=function(t,e){var n;if(16==e)n=4;else if(8==e)n=3;else if(256==e)n=8;else if(2==e)n=1;else if(32==e)n=5;else{if(4!=e)return void this.fromRadix(t,e);n=2}this.t=0,this.s=0;for(var r=t.length,i=!1,s=0;--r>=0;){var a=8==n?255&t[r]:f(t,r);a<0?"-"==t.charAt(r)&&(i=!0):(i=!1,0==s?this[this.t++]=a:s+n>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+=n)>=this.DB&&(s-=this.DB))}8==n&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<<this.DB-s)-1<<s)),this.clamp(),i&&o.ZERO.subTo(this,this)},o.prototype.clamp=function(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t},o.prototype.dlShiftTo=function(t,e){var n;for(n=this.t-1;n>=0;--n)e[n+t]=this[n];for(n=t-1;n>=0;--n)e[n]=0;e.t=this.t+t,e.s=this.s},o.prototype.drShiftTo=function(t,e){for(var n=t;n<this.t;++n)e[n-t]=this[n];e.t=Math.max(this.t-t,0),e.s=this.s},o.prototype.lShiftTo=function(t,e){var n,r=t%this.DB,i=this.DB-r,o=(1<<i)-1,s=Math.floor(t/this.DB),a=this.s<<r&this.DM;for(n=this.t-1;n>=0;--n)e[n+s+1]=this[n]>>i|a,a=(this[n]&o)<<r;for(n=s-1;n>=0;--n)e[n]=0;e[s]=a,e.t=this.t+s+1,e.s=this.s,e.clamp()},o.prototype.rShiftTo=function(t,e){e.s=this.s;var n=Math.floor(t/this.DB);if(n>=this.t)e.t=0;else{var r=t%this.DB,i=this.DB-r,o=(1<<r)-1;e[0]=this[n]>>r;for(var s=n+1;s<this.t;++s)e[s-n-1]|=(this[s]&o)<<i,e[s-n]=this[s]>>r;r>0&&(e[this.t-n-1]|=(this.s&o)<<i),e.t=this.t-n,e.clamp()}},o.prototype.subTo=function(t,e){for(var n=0,r=0,i=Math.min(t.t,this.t);n<i;)r+=this[n]-t[n],e[n++]=r&this.DM,r>>=this.DB;if(t.t<this.t){for(r-=t.s;n<this.t;)r+=this[n],e[n++]=r&this.DM,r>>=this.DB;r+=this.s}else{for(r+=this.s;n<t.t;)r-=t[n],e[n++]=r&this.DM,r>>=this.DB;r-=t.s}e.s=r<0?-1:0,r<-1?e[n++]=this.DV+r:r>0&&(e[n++]=r),e.t=n,e.clamp()},o.prototype.multiplyTo=function(t,e){var n=this.abs(),r=t.abs(),i=n.t;for(e.t=i+r.t;--i>=0;)e[i]=0;for(i=0;i<r.t;++i)e[i+n.t]=n.am(0,r[i],e,i,0,n.t);e.s=0,e.clamp(),this.s!=t.s&&o.ZERO.subTo(e,e)},o.prototype.squareTo=function(t){for(var e=this.abs(),n=t.t=2*e.t;--n>=0;)t[n]=0;for(n=0;n<e.t-1;++n){var r=e.am(n,e[n],t,2*n,0,1);(t[n+e.t]+=e.am(n+1,2*e[n],t,2*n+1,r,e.t-n-1))>=e.DV&&(t[n+e.t]-=e.DV,t[n+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(n,e[n],t,2*n,0,1)),t.s=0,t.clamp()},o.prototype.divRemTo=function(t,e,n){var r=t.abs();if(!(r.t<=0)){var i=this.abs();if(i.t<r.t)return null!=e&&e.fromInt(0),void(null!=n&&this.copyTo(n));null==n&&(n=s());var a=s(),c=this.s,h=t.s,u=this.DB-d(r[r.t-1]);u>0?(r.lShiftTo(u,a),i.lShiftTo(u,n)):(r.copyTo(a),i.copyTo(n));var l=a.t,f=a[l-1];if(0!=f){var p=f*(1<<this.F1)+(l>1?a[l-2]>>this.F2:0),m=this.FV/p,y=(1<<this.F1)/p,v=1<<this.F2,g=n.t,b=g-l,w=null==e?s():e;for(a.dlShiftTo(b,w),n.compareTo(w)>=0&&(n[n.t++]=1,n.subTo(w,n)),o.ONE.dlShiftTo(l,w),w.subTo(a,a);a.t<l;)a[a.t++]=0;for(;--b>=0;){var k=n[--g]==f?this.DM:Math.floor(n[g]*m+(n[g-1]+v)*y);if((n[g]+=a.am(0,k,n,b,0,l))<k)for(a.dlShiftTo(b,w),n.subTo(w,n);n[g]<--k;)n.subTo(w,n)}null!=e&&(n.drShiftTo(l,e),c!=h&&o.ZERO.subTo(e,e)),n.t=l,n.clamp(),u>0&&n.rShiftTo(u,n),c<0&&o.ZERO.subTo(n,n)}}},o.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=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e},o.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},o.prototype.exp=function(t,e){if(t>4294967295||t<1)return o.ONE;var n=s(),r=s(),i=e.convert(this),a=d(t)-1;for(i.copyTo(n);--a>=0;)if(e.sqrTo(n,r),(t&1<<a)>0)e.mulTo(r,i,n);else{var c=n;n=r,r=c}return e.revert(n)},o.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 n,r=(1<<e)-1,i=!1,o="",s=this.t,a=this.DB-s*this.DB%e;if(s-- >0)for(a<this.DB&&(n=this[s]>>a)>0&&(i=!0,o=l(n));s>=0;)a<e?(n=(this[s]&(1<<a)-1)<<e-a,n|=this[--s]>>(a+=this.DB-e)):(n=this[s]>>(a-=e)&r,a<=0&&(a+=this.DB,--s)),n>0&&(i=!0),i&&(o+=l(n));return i?o:"0"},o.prototype.negate=function(){var t=s();return o.ZERO.subTo(this,t),t},o.prototype.abs=function(){return this.s<0?this.negate():this},o.prototype.compareTo=function(t){var e=this.s-t.s;if(0!=e)return e;var n=this.t;if(0!=(e=n-t.t))return this.s<0?-e:e;for(;--n>=0;)if(0!=(e=this[n]-t[n]))return e;return 0},o.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+d(this[this.t-1]^this.s&this.DM)},o.prototype.mod=function(t){var e=s();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(o.ZERO)>0&&t.subTo(e,e),e},o.prototype.modPowInt=function(t,e){var n;return n=t<256||e.isEven()?new m(e):new y(e),this.exp(t,n)},o.ZERO=p(0),o.ONE=p(1),v.prototype.init=function(t){var e,n,r;for(e=0;e<256;++e)this.S[e]=e;for(n=0,e=0;e<256;++e)n=n+this.S[e]+t[e%t.length]&255,r=this.S[e],this.S[e]=this.S[n],this.S[n]=r;this.i=0,this.j=0},v.prototype.next=function(){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]};var g,b,w,k=256;function A(){var t;t=(new Date).getTime(),b[w++]^=255&t,b[w++]^=t>>8&255,b[w++]^=t>>16&255,b[w++]^=t>>24&255,w>=k&&(w-=k)}if(null==b){b=[],w=0;try{if(window.crypto&&window.crypto.getRandomValues){var C=new Uint8Array(32);for(window.crypto.getRandomValues(C),j=0;j<32;++j)b[w++]=C[j]}else if(window.msCrypto&&window.msCrypto.getRandomValues){C=new Uint8Array(32);for(window.msCrypto.getRandomValues(C),j=0;j<32;++j)b[w++]=C[j]}else if(window.crypto&&window.crypto.random){var B=window.crypto.random(32);for(j=0;j<B.length;++j)b[w++]=255&B.charCodeAt(j)}}catch(t){}for(;w<k;)j=Math.floor(65536*Math.random()),b[w++]=j>>>8,b[w++]=255&j;w=0,A()}function S(){if(null==g){for(A(),(g=new v).init(b),w=0;w<b.length;++w)b[w]=0;w=0}return g.next()}function T(){}function D(){this.n=null,this.e=0,this.d=null,this.p=null,this.q=null,this.dmp1=null,this.dmq1=null,this.coeff=null}function x(t){throw t}T.prototype.nextBytes=function(t){var e;for(e=0;e<t.length;++e)t[e]=S()},D.prototype.doPublic=function(t){return t.modPowInt(this.e,this.n)},D.prototype.setPublic=function(t,e){null!=t&&null!=e&&t.length>0&&e.length>0?(this.n=function(t,e){return new o(t,e)}(t,16),this.e=parseInt(e,16)):alert("Invalid RSA public key")},D.prototype.encrypt=function(t){var e=function(t,e){if(e<t.length+11)return alert("Message too long for RSA"),null;for(var n=new Array,r=t.length-1;r>=0&&e>0;)n[--e]=t[r--];n[--e]=0;for(var i=new T,s=new Array;e>2;){for(s[0]=0;0==s[0];)i.nextBytes(s);n[--e]=s[0]}return n[--e]=2,n[--e]=0,new o(n)}(t,this.n.bitLength()+7>>3);if(null==e)return null;var n=this.doPublic(e);if(null==n)return null;var r=n.toString(16);return 0==(1&r.length)?r:"0"+r},D.prototype.encrypt_b64=function(t){var e=this.encrypt(t);return e?function(t){var e,n,o="";for(e=0;e+3<=t.length;e+=3)n=parseInt(t.substring(e,e+3),16),o+=r.charAt(n>>6)+r.charAt(63&n);for(e+1==t.length?(n=parseInt(t.substring(e,e+1),16),o+=r.charAt(n<<2)):e+2==t.length&&(n=parseInt(t.substring(e,e+2),16),o+=r.charAt(n>>2)+r.charAt((3&n)<<4));(3&o.length)>0;)o+=i;return o}(e):null};var E,L,I,j=void 0,M=!1,O={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}}};function R(t,e,n){4!==e.length&&x(new O.exception.invalid("invalid aes block size"));var r=t.b[n],i=e[0]^r[0],o=e[n?3:1]^r[1],s=e[2]^r[2];e=e[n?1:3]^r[3];var a,c,h,u,l=r.length/4-2,f=4,p=[0,0,0,0];t=(a=t.k[n])[0];var d=a[1],m=a[2],y=a[3],v=a[4];for(u=0;u<l;u++)a=t[i>>>24]^d[o>>16&255]^m[s>>8&255]^y[255&e]^r[f],c=t[o>>>24]^d[s>>16&255]^m[e>>8&255]^y[255&i]^r[f+1],h=t[s>>>24]^d[e>>16&255]^m[i>>8&255]^y[255&o]^r[f+2],e=t[e>>>24]^d[i>>16&255]^m[o>>8&255]^y[255&s]^r[f+3],f+=4,i=a,o=c,s=h;for(u=0;4>u;u++)p[n?3&-u:u]=v[i>>>24]<<24^v[o>>16&255]<<16^v[s>>8&255]<<8^v[255&e]^r[f++],a=i,i=o,o=s,s=e,e=a;return p}function B(t,e){var n,r,i,o=e.slice(0),s=t.r,a=t.b,c=s[0],h=s[1],u=s[2],l=s[3],f=s[4],p=s[5],d=s[6],m=s[7];for(n=0;64>n;n++)16>n?r=o[n]:(r=o[n+1&15],i=o[n+14&15],r=o[15&n]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(i>>>17^i>>>19^i>>>10^i<<15^i<<13)+o[15&n]+o[n+9&15]|0),r=r+m+(f>>>6^f>>>11^f>>>25^f<<26^f<<21^f<<7)+(d^f&(p^d))+a[n],m=d,d=p,p=f,f=l+r|0,l=u,u=h,c=r+((h=c)&u^l&(h^u))+(h>>>2^h>>>13^h>>>22^h<<30^h<<19^h<<10)|0;s[0]=s[0]+c|0,s[1]=s[1]+h|0,s[2]=s[2]+u|0,s[3]=s[3]+l|0,s[4]=s[4]+f|0,s[5]=s[5]+p|0,s[6]=s[6]+d|0,s[7]=s[7]+m|0}function N(t,e){var n,r=O.random.w[t],i=[];for(n in r)r.hasOwnProperty(n)&&i.push(r[n]);for(n=0;n<i.length;n++)i[n](e)}function F(t){void 0!==window&&window.performance&&"function"==typeof window.performance.now?O.random.addEntropy(window.performance.now(),t,"loadtime"):O.random.addEntropy((new Date).valueOf(),t,"loadtime")}function P(t){t.b=V(t).concat(V(t)),t.A=new O.cipher.aes(t.b)}function V(t){for(var e=0;4>e&&(t.f[e]=t.f[e]+1|0,!t.f[e]);e++);return t.A.encrypt(t.f)}function q(t,e){return function(){e.apply(t,arguments)}}"undefined"!=typeof module&&module.exports&&(module.exports=O),O.cipher.aes=function(t){this.k[0][0][0]||this.D();var e,n,r,i,o=this.k[0][4],s=this.k[1],a=1;for(4!==(e=t.length)&&6!==e&&8!==e&&x(new O.exception.invalid("invalid aes key size")),this.b=[r=t.slice(0),i=[]],t=e;t<4*e+28;t++)n=r[t-1],(0==t%e||8===e&&4==t%e)&&(n=o[n>>>24]<<24^o[n>>16&255]<<16^o[n>>8&255]<<8^o[255&n],0==t%e&&(n=n<<8^n>>>24^a<<24,a=a<<1^283*(a>>7))),r[t]=r[t-e]^n;for(e=0;t;e++,t--)n=r[3&e?t:t-4],i[e]=4>=t||4>e?n:s[0][o[n>>>24]]^s[1][o[n>>16&255]]^s[2][o[n>>8&255]]^s[3][o[255&n]]},O.cipher.aes.prototype={encrypt:function(t){return R(this,t,0)},decrypt:function(t){return R(this,t,1)},k:[[[],[],[],[],[]],[[],[],[],[],[]]],D:function(){var t,e,n,r,i,o,s,a=this.k[0],c=this.k[1],h=a[4],u=c[4],l=[],f=[];for(t=0;256>t;t++)f[(l[t]=t<<1^283*(t>>7))^t]=t;for(e=n=0;!h[e];e^=r||1,n=f[n]||1)for(o=(o=n^n<<1^n<<2^n<<3^n<<4)>>8^255&o^99,h[e]=o,u[o]=e,s=16843009*(i=l[t=l[r=l[e]]])^65537*t^257*r^16843008*e,i=257*l[o]^16843008*o,t=0;4>t;t++)a[t][e]=i=i<<24^i>>>8,c[t][o]=s=s<<24^s>>>8;for(t=0;5>t;t++)a[t]=a[t].slice(0),c[t]=c[t].slice(0)}},O.bitArray={bitSlice:function(t,e,n){return t=O.bitArray.P(t.slice(e/32),32-(31&e)).slice(1),n===j?t:O.bitArray.clamp(t,n-e)},extract:function(t,e,n){var r=Math.floor(-e-n&31);return(-32&(e+n-1^e)?t[e/32|0]<<32-r^t[e/32+1|0]>>>r:t[e/32|0]>>>r)&(1<<n)-1},concat:function(t,e){if(0===t.length||0===e.length)return t.concat(e);var n=t[t.length-1],r=O.bitArray.getPartial(n);return 32===r?t.concat(e):O.bitArray.P(e,r,0|n,t.slice(0,t.length-1))},bitLength:function(t){var e=t.length;return 0===e?0:32*(e-1)+O.bitArray.getPartial(t[e-1])},clamp:function(t,e){if(32*t.length<e)return t;var n=(t=t.slice(0,Math.ceil(e/32))).length;return e&=31,0<n&&e&&(t[n-1]=O.bitArray.partial(e,t[n-1]&2147483648>>e-1,1)),t},partial:function(t,e,n){return 32===t?e:(n?0|e:e<<32-t)+1099511627776*t},getPartial:function(t){return Math.round(t/1099511627776)||32},equal:function(t,e){if(O.bitArray.bitLength(t)!==O.bitArray.bitLength(e))return M;var n,r=0;for(n=0;n<t.length;n++)r|=t[n]^e[n];return 0===r},P:function(t,e,n,r){var i;for(i=0,r===j&&(r=[]);32<=e;e-=32)r.push(n),n=0;if(0===e)return r.concat(t);for(i=0;i<t.length;i++)r.push(n|t[i]>>>e),n=t[i]<<32-e;return i=t.length?t[t.length-1]:0,t=O.bitArray.getPartial(i),r.push(O.bitArray.partial(e+t&31,32<e+t?n:r.pop(),1)),r},l: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,n;for(e=0;e<t.length;++e)n=t[e],t[e]=n>>>24|n>>>8&65280|(65280&n)<<8|n<<24;return t}},O.codec.utf8String={fromBits:function(t){var e,n,r="",i=O.bitArray.bitLength(t);for(e=0;e<i/8;e++)0==(3&e)&&(n=t[e/4]),r+=String.fromCharCode(n>>>24),n<<=8;return decodeURIComponent(escape(r))},toBits:function(t){t=unescape(encodeURIComponent(t));var e,n=[],r=0;for(e=0;e<t.length;e++)r=r<<8|t.charCodeAt(e),3==(3&e)&&(n.push(r),r=0);return 3&e&&n.push(O.bitArray.partial(8*(3&e),r)),n}},O.codec.hex={fromBits:function(t){var e,n="";for(e=0;e<t.length;e++)n+=(0xf00000000000+(0|t[e])).toString(16).substr(4);return n.substr(0,O.bitArray.bitLength(t)/4)},toBits:function(t){var e,n,r=[];for(n=(t=t.replace(/\s|0x/g,"")).length,t+="00000000",e=0;e<t.length;e+=8)r.push(0^parseInt(t.substr(e,8),16));return O.bitArray.clamp(r,4*n)}},O.codec.base64={J:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",fromBits:function(t,e,n){var r="",i=0,o=O.codec.base64.J,s=0,a=O.bitArray.bitLength(t);for(n&&(o=o.substr(0,62)+"-_"),n=0;6*r.length<a;)r+=o.charAt((s^t[n]>>>i)>>>26),6>i?(s=t[n]<<6-i,i+=26,n++):(s<<=6,i-=6);for(;3&r.length&&!e;)r+="=";return r},toBits:function(t,e){t=t.replace(/\s|=/g,"");var n,r,i=[],o=0,s=O.codec.base64.J,a=0;for(e&&(s=s.substr(0,62)+"-_"),n=0;n<t.length;n++)0>(r=s.indexOf(t.charAt(n)))&&x(new O.exception.invalid("this isn't base64!")),26<o?(o-=26,i.push(a^r>>>o),a=r<<32-o):a^=r<<32-(o+=6);return 56&o&&i.push(O.bitArray.partial(56&o,a,1)),i}},O.codec.base64url={fromBits:function(t){return O.codec.base64.fromBits(t,1,1)},toBits:function(t){return O.codec.base64.toBits(t,1)}},O.hash.sha256=function(t){this.b[0]||this.D(),t?(this.r=t.r.slice(0),this.o=t.o.slice(0),this.h=t.h):this.reset()},O.hash.sha256.hash=function(t){return(new O.hash.sha256).update(t).finalize()},O.hash.sha256.prototype={blockSize:512,reset:function(){return this.r=this.N.slice(0),this.o=[],this.h=0,this},update:function(t){"string"==typeof t&&(t=O.codec.utf8String.toBits(t));var e,n=this.o=O.bitArray.concat(this.o,t);for(e=this.h,t=this.h=e+O.bitArray.bitLength(t),e=512+e&-512;e<=t;e+=512)B(this,n.splice(0,16));return this},finalize:function(){var t,e=this.o,n=this.r;for(t=(e=O.bitArray.concat(e,[O.bitArray.partial(1,1)])).length+2;15&t;t++)e.push(0);for(e.push(Math.floor(this.h/4294967296)),e.push(0|this.h);e.length;)B(this,e.splice(0,16));return this.reset(),n},N:[],b:[],D:function(){function t(t){return 4294967296*(t-Math.floor(t))|0}var e,n=0,r=2;t:for(;64>n;r++){for(e=2;e*e<=r;e++)if(0==r%e)continue t;8>n&&(this.N[n]=t(Math.pow(r,.5))),this.b[n]=t(Math.pow(r,1/3)),n++}}},O.mode.ccm={name:"ccm",encrypt:function(t,e,n,r,i){var o,s=e.slice(0),a=O.bitArray,c=a.bitLength(n)/8,h=a.bitLength(s)/8;for(i=i||64,r=r||[],7>c&&x(new O.exception.invalid("ccm: iv must be at least 7 bytes")),o=2;4>o&&h>>>8*o;o++);return o<15-c&&(o=15-c),n=a.clamp(n,8*(15-o)),e=O.mode.ccm.L(t,e,n,r,i,o),s=O.mode.ccm.p(t,s,n,e,i,o),a.concat(s.data,s.tag)},decrypt:function(t,e,n,r,i){i=i||64,r=r||[];var o=O.bitArray,s=o.bitLength(n)/8,a=o.bitLength(e),c=o.clamp(e,a-i),h=o.bitSlice(e,a-i);a=(a-i)/8;for(7>s&&x(new O.exception.invalid("ccm: iv must be at least 7 bytes")),e=2;4>e&&a>>>8*e;e++);return e<15-s&&(e=15-s),n=o.clamp(n,8*(15-e)),c=O.mode.ccm.p(t,c,n,h,i,e),t=O.mode.ccm.L(t,c.data,n,r,i,e),o.equal(c.tag,t)||x(new O.exception.corrupt("ccm: tag doesn't match")),c.data},L:function(t,e,n,r,i,o){var s=[],a=O.bitArray,c=a.l;if(((i/=8)%2||4>i||16<i)&&x(new O.exception.invalid("ccm: invalid tag length")),(4294967295<r.length||4294967295<e.length)&&x(new O.exception.bug("ccm: can't deal with 4GiB or more data")),o=[a.partial(8,(r.length?64:0)|i-2<<2|o-1)],(o=a.concat(o,n))[3]|=a.bitLength(e)/8,o=t.encrypt(o),r.length)for(65279>=(n=a.bitLength(r)/8)?s=[a.partial(16,n)]:4294967295>=n&&(s=a.concat([a.partial(16,65534)],[n])),s=a.concat(s,r),r=0;r<s.length;r+=4)o=t.encrypt(c(o,s.slice(r,r+4).concat([0,0,0])));for(r=0;r<e.length;r+=4)o=t.encrypt(c(o,e.slice(r,r+4).concat([0,0,0])));return a.clamp(o,8*i)},p:function(t,e,n,r,i,o){var s,a=O.bitArray;s=a.l;var c=e.length,h=a.bitLength(e);if(n=a.concat([a.partial(8,o-1)],n).concat([0,0,0]).slice(0,4),r=a.bitSlice(s(r,t.encrypt(n)),0,i),!c)return{tag:r,data:[]};for(s=0;s<c;s+=4)n[3]++,i=t.encrypt(n),e[s]^=i[0],e[s+1]^=i[1],e[s+2]^=i[2],e[s+3]^=i[3];return{tag:r,data:a.clamp(e,h)}}},O.mode.ocb2={name:"ocb2",encrypt:function(t,e,n,r,i,o){128!==O.bitArray.bitLength(n)&&x(new O.exception.invalid("ocb iv must be 128 bits"));var s,a=O.mode.ocb2.H,c=O.bitArray,h=c.l,u=[0,0,0,0];n=a(t.encrypt(n));var l,f=[];for(r=r||[],i=i||64,s=0;s+4<e.length;s+=4)u=h(u,l=e.slice(s,s+4)),f=f.concat(h(n,t.encrypt(h(n,l)))),n=a(n);return l=e.slice(s),e=c.bitLength(l),s=t.encrypt(h(n,[0,0,0,e])),l=c.clamp(h(l.concat([0,0,0]),s),e),u=h(u,h(l.concat([0,0,0]),s)),u=t.encrypt(h(u,h(n,a(n)))),r.length&&(u=h(u,o?r:O.mode.ocb2.pmac(t,r))),f.concat(c.concat(l,c.clamp(u,i)))},decrypt:function(t,e,n,r,i,o){128!==O.bitArray.bitLength(n)&&x(new O.exception.invalid("ocb iv must be 128 bits")),i=i||64;var s,a,c=O.mode.ocb2.H,h=O.bitArray,u=h.l,l=[0,0,0,0],f=c(t.encrypt(n)),p=O.bitArray.bitLength(e)-i,d=[];for(r=r||[],n=0;n+4<p/32;n+=4)s=u(f,t.decrypt(u(f,e.slice(n,n+4)))),l=u(l,s),d=d.concat(s),f=c(f);return a=p-32*n,s=t.encrypt(u(f,[0,0,0,a])),s=u(s,h.clamp(e.slice(n),a).concat([0,0,0])),l=u(l,s),l=t.encrypt(u(l,u(f,c(f)))),r.length&&(l=u(l,o?r:O.mode.ocb2.pmac(t,r))),h.equal(h.clamp(l,i),h.bitSlice(e,p))||x(new O.exception.corrupt("ocb: tag doesn't match")),d.concat(h.clamp(s,a))},pmac:function(t,e){var n,r=O.mode.ocb2.H,i=O.bitArray,o=i.l,s=[0,0,0,0],a=o(a=t.encrypt([0,0,0,0]),r(r(a)));for(n=0;n+4<e.length;n+=4)a=r(a),s=o(s,t.encrypt(o(a,e.slice(n,n+4))));return n=e.slice(n),128>i.bitLength(n)&&(a=o(a,r(a)),n=i.concat(n,[-2147483648,0,0,0])),s=o(s,n),t.encrypt(o(r(o(a,r(a))),s))},H: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)]}},O.mode.gcm={name:"gcm",encrypt:function(t,e,n,r,i){var o=e.slice(0);return e=O.bitArray,r=r||[],t=O.mode.gcm.p(!0,t,o,r,n,i||128),e.concat(t.data,t.tag)},decrypt:function(t,e,n,r,i){var o=e.slice(0),s=O.bitArray,a=s.bitLength(o);return r=r||[],(i=i||128)<=a?(e=s.bitSlice(o,a-i),o=s.bitSlice(o,0,a-i)):(e=o,o=[]),t=O.mode.gcm.p(M,t,o,r,n,i),s.equal(t.tag,e)||x(new O.exception.corrupt("gcm: tag doesn't match")),t.data},Z:function(t,e){var n,r,i,o,s,a=O.bitArray.l;for(i=[0,0,0,0],o=e.slice(0),n=0;128>n;n++){for((r=0!=(t[Math.floor(n/32)]&1<<31-n%32))&&(i=a(i,o)),s=0!=(1&o[3]),r=3;0<r;r--)o[r]=o[r]>>>1|(1&o[r-1])<<31;o[0]>>>=1,s&&(o[0]^=-520093696)}return i},g:function(t,e,n){var r,i=n.length;for(e=e.slice(0),r=0;r<i;r+=4)e[0]^=4294967295&n[r],e[1]^=4294967295&n[r+1],e[2]^=4294967295&n[r+2],e[3]^=4294967295&n[r+3],e=O.mode.gcm.Z(e,t);return e},p:function(t,e,n,r,i,o){var s,a,c,h,u,l,f,p,d=O.bitArray;for(l=n.length,f=d.bitLength(n),p=d.bitLength(r),a=d.bitLength(i),s=e.encrypt([0,0,0,0]),96===a?(i=i.slice(0),i=d.concat(i,[1])):(i=O.mode.gcm.g(s,[0,0,0,0],i),i=O.mode.gcm.g(s,i,[0,0,Math.floor(a/4294967296),4294967295&a])),a=O.mode.gcm.g(s,[0,0,0,0],r),u=i.slice(0),r=a.slice(0),t||(r=O.mode.gcm.g(s,a,n)),h=0;h<l;h+=4)u[3]++,c=e.encrypt(u),n[h]^=c[0],n[h+1]^=c[1],n[h+2]^=c[2],n[h+3]^=c[3];return n=d.clamp(n,f),t&&(r=O.mode.gcm.g(s,a,n)),t=[Math.floor(p/4294967296),4294967295&p,Math.floor(f/4294967296),4294967295&f],r=O.mode.gcm.g(s,r,t),c=e.encrypt(i),r[0]^=c[0],r[1]^=c[1],r[2]^=c[2],r[3]^=c[3],{tag:d.bitSlice(r,0,o),data:n}}},O.misc.hmac=function(t,e){this.M=e=e||O.hash.sha256;var n,r=[[],[]],i=e.prototype.blockSize/32;for(this.n=[new e,new e],t.length>i&&(t=e.hash(t)),n=0;n<i;n++)r[0][n]=909522486^t[n],r[1][n]=1549556828^t[n];this.n[0].update(r[0]),this.n[1].update(r[1]),this.G=new e(this.n[0])},O.misc.hmac.prototype.encrypt=O.misc.hmac.prototype.mac=function(t){return this.Q&&x(new O.exception.invalid("encrypt on already updated hmac called!")),this.update(t),this.digest(t)},O.misc.hmac.prototype.reset=function(){this.G=new this.M(this.n[0]),this.Q=M},O.misc.hmac.prototype.update=function(t){this.Q=!0,this.G.update(t)},O.misc.hmac.prototype.digest=function(){var t=this.G.finalize();t=new this.M(this.n[1]).update(t).finalize();return this.reset(),t},O.misc.pbkdf2=function(t,e,n,r,i){n=n||1e3,(0>r||0>n)&&x(O.exception.invalid("invalid params to pbkdf2")),"string"==typeof t&&(t=O.codec.utf8String.toBits(t)),"string"==typeof e&&(e=O.codec.utf8String.toBits(e)),t=new(i=i||O.misc.hmac)(t);var o,s,a,c,h=[],u=O.bitArray;for(c=1;32*h.length<(r||1);c++){for(i=o=t.encrypt(u.concat(e,[c])),s=1;s<n;s++)for(o=t.encrypt(o),a=0;a<o.length;a++)i[a]^=o[a];h=h.concat(i)}return r&&(h=u.clamp(h,r)),h},O.prng=function(t){this.c=[new O.hash.sha256],this.i=[0],this.F=0,this.s={},this.C=0,this.K={},this.O=this.d=this.j=this.W=0,this.b=[0,0,0,0,0,0,0,0],this.f=[0,0,0,0],this.A=j,this.B=t,this.q=M,this.w={progress:{},seeded:{}},this.m=this.V=0,this.t=1,this.u=2,this.S=65536,this.I=[0,48,64,96,128,192,256,384,512,768,1024],this.T=3e4,this.R=80},O.prng.prototype={randomWords:function(t,e){var n,r,i=[];if((n=this.isReady(e))===this.m&&x(new O.exception.notReady("generator isn't seeded")),n&this.u){n=!(n&this.t),r=[];var o,s=0;for(this.O=r[0]=(new Date).valueOf()+this.T,o=0;16>o;o++)r.push(4294967296*Math.random()|0);for(o=0;o<this.c.length&&(r=r.concat(this.c[o].finalize()),s+=this.i[o],this.i[o]=0,n||!(this.F&1<<o));o++);for(this.F>=1<<this.c.length&&(this.c.push(new O.hash.sha256),this.i.push(0)),this.d-=s,s>this.j&&(this.j=s),this.F++,this.b=O.hash.sha256.hash(this.b.concat(r)),this.A=new O.cipher.aes(this.b),n=0;4>n&&(this.f[n]=this.f[n]+1|0,!this.f[n]);n++);}for(n=0;n<t;n+=4)0==(n+1)%this.S&&P(this),r=V(this),i.push(r[0],r[1],r[2],r[3]);return P(this),i.slice(0,t)},setDefaultParanoia:function(t,e){0===t&&"Setting paranoia=0 will ruin your security; use it only for testing"!==e&&x("Setting paranoia=0 will ruin your security; use it only for testing"),this.B=t},addEntropy:function(t,e,n){n=n||"user";var r,i,o=(new Date).valueOf(),s=this.s[n],a=this.isReady(),c=0;switch((r=this.K[n])===j&&(r=this.K[n]=this.W++),s===j&&(s=this.s[n]=0),this.s[n]=(this.s[n]+1)%this.c.length,typeof t){case"number":e===j&&(e=1),this.c[s].update([r,this.C++,1,e,o,1,0|t]);break;case"object":if("[object Uint32Array]"===(n=Object.prototype.toString.call(t))){for(i=[],n=0;n<t.length;n++)i.push(t[n]);t=i}else for("[object Array]"!==n&&(c=1),n=0;n<t.length&&!c;n++)"number"!=typeof t[n]&&(c=1);if(!c){if(e===j)for(n=e=0;n<t.length;n++)for(i=t[n];0<i;)e++,i>>>=1;this.c[s].update([r,this.C++,2,e,o,t.length].concat(t))}break;case"string":e===j&&(e=t.length),this.c[s].update([r,this.C++,3,e,o,t.length]),this.c[s].update(t);break;default:c=1}c&&x(new O.exception.bug("random: addEntropy only supports number, array of numbers or string")),this.i[s]+=e,this.d+=e,a===this.m&&(this.isReady()!==this.m&&N("seeded",Math.max(this.j,this.d)),N("progress",this.getProgress()))},isReady:function(t){return t=this.I[t!==j?t:this.B],this.j&&this.j>=t?this.i[0]>this.R&&(new Date).valueOf()>this.O?this.u|this.t:this.t:this.d>=t?this.u|this.m:this.m},getProgress:function(t){return t=this.I[t||this.B],this.j>=t?1:this.d>t?1:this.d/t},startCollectors:function(){this.q||(this.a={loadTimeCollector:q(this,this.aa),mouseCollector:q(this,this.ba),keyboardCollector:q(this,this.$),accelerometerCollector:q(this,this.U)},window.addEventListener?(window.addEventListener("load",this.a.loadTimeCollector,M),window.addEventListener("mousemove",this.a.mouseCollector,M),window.addEventListener("keypress",this.a.keyboardCollector,M),window.addEventListener("devicemotion",this.a.accelerometerCollector,M)):document.attachEvent?(document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector)):x(new O.exception.bug("can't attach event")),this.q=!0)},stopCollectors:function(){this.q&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,M),window.removeEventListener("mousemove",this.a.mouseCollector,M),window.removeEventListener("keypress",this.a.keyboardCollector,M),window.removeEventListener("devicemotion",this.a.accelerometerCollector,M)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.q=M)},addEventListener:function(t,e){this.w[t][this.V++]=e},removeEventListener:function(t,e){var n,r,i=this.w[t],o=[];for(r in i)i.hasOwnProperty(r)&&i[r]===e&&o.push(r);for(n=0;n<o.length;n++)delete i[r=o[n]]},$:function(){F(1)},ba:function(t){var e,n;try{e=t.x||t.clientX||t.offsetX||0,n=t.y||t.clientY||t.offsetY||0}catch(t){n=e=0}0!=e&&0!=n&&O.random.addEntropy([e,n],2,"mouse"),F(0)},aa:function(){F(2)},U:function(t){if(t=t.accelerationIncludingGravity.x||t.accelerationIncludingGravity.y||t.accelerationIncludingGravity.z,window.orientation){var e=window.orientation;"number"==typeof e&&O.random.addEntropy(e,1,"accelerometer")}t&&O.random.addEntropy(t,2,"accelerometer"),F(0)}},O.random=new O.prng(6);t:try{var U,K,z,$;if($="undefined"!=typeof module){var G;if(G=module.exports){var Y;try{Y=require("crypto")}catch(t){Y=null}G=(K=Y)&&K.randomBytes}$=G}if($)U=K.randomBytes(128),U=new Uint32Array(new Uint8Array(U).buffer),O.random.addEntropy(U,1024,"crypto['randomBytes']");else if(void 0!==window&&"undefined"!=typeof Uint32Array){if(z=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(z);else{if(!window.msCrypto||!window.msCrypto.getRandomValues)break t;window.msCrypto.getRandomValues(z)}O.random.addEntropy(z,1024,"crypto['getRandomValues']")}}catch(t){void 0!==window&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(t))}O.json={defaults:{v:1,iter:1e3,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},Y:function(t,e,n,r){n=n||{},r=r||{};var i,o=O.json,s=o.e({iv:O.random.randomWords(4,0)},o.defaults);return o.e(s,n),n=s.adata,"string"==typeof s.salt&&(s.salt=O.codec.base64.toBits(s.salt)),"string"==typeof s.iv&&(s.iv=O.codec.base64.toBits(s.iv)),(!O.mode[s.mode]||!O.cipher[s.cipher]||"string"==typeof t&&100>=s.iter||64!==s.ts&&96!==s.ts&&128!==s.ts||128!==s.ks&&192!==s.ks&&256!==s.ks||2>s.iv.length||4<s.iv.length)&&x(new O.exception.invalid("json encrypt: invalid parameters")),"string"==typeof t?(t=(i=O.misc.cachedPbkdf2(t,s)).key.slice(0,s.ks/32),s.salt=i.salt):O.ecc&&t instanceof O.ecc.elGamal.publicKey&&(i=t.kem(),s.kemtag=i.tag,t=i.key.slice(0,s.ks/32)),"string"==typeof e&&(e=O.codec.utf8String.toBits(e)),"string"==typeof n&&(n=O.codec.utf8String.toBits(n)),i=new O.cipher[s.cipher](t),o.e(r,s),r.key=t,s.ct=O.mode[s.mode].encrypt(i,e,s.iv,n,s.ts),s},encrypt:function(t,e,n,r){var i=O.json,o=i.Y.apply(i,arguments);return i.encode(o)},X:function(t,e,n,r){n=n||{},r=r||{};var i,o,s=O.json;return i=(e=s.e(s.e(s.e({},s.defaults),e),n,!0)).adata,"string"==typeof e.salt&&(e.salt=O.codec.base64.toBits(e.salt)),"string"==typeof e.iv&&(e.iv=O.codec.base64.toBits(e.iv)),(!O.mode[e.mode]||!O.cipher[e.cipher]||"string"==typeof t&&100>=e.iter||64!==e.ts&&96!==e.ts&&128!==e.ts||128!==e.ks&&192!==e.ks&&256!==e.ks||!e.iv||2>e.iv.length||4<e.iv.length)&&x(new O.exception.invalid("json decrypt: invalid parameters")),"string"==typeof t?(t=(o=O.misc.cachedPbkdf2(t,e)).key.slice(0,e.ks/32),e.salt=o.salt):O.ecc&&t instanceof O.ecc.elGamal.secretKey&&(t=t.unkem(O.codec.base64.toBits(e.kemtag)).slice(0,e.ks/32)),"string"==typeof i&&(i=O.codec.utf8String.toBits(i)),o=new O.cipher[e.cipher](t),i=O.mode[e.mode].decrypt(o,e.ct,e.iv,i,e.ts),s.e(r,e),r.key=t,1===n.raw?i:O.codec.utf8String.fromBits(i)},decrypt:function(t,e,n,r){var i=O.json;return i.X(t,i.decode(e),n,r)},encode:function(t){var e,n="{",r="";for(e in t)if(t.hasOwnProperty(e))switch(e.match(/^[a-z0-9]+$/i)||x(new O.exception.invalid("json encode: invalid property name")),n+=r+'"'+e+'":',r=",",typeof t[e]){case"number":case"boolean":n+=t[e];break;case"string":n+='"'+escape(t[e])+'"';break;case"object":n+='"'+O.codec.base64.fromBits(t[e],0)+'"';break;default:x(new O.exception.bug("json encode: unsupported type"))}return n+"}"},decode:function(t){(t=t.replace(/\s/g,"")).match(/^\{.*\}$/)||x(new O.exception.invalid("json decode: this isn't json!")),t=t.replace(/^\{|\}$/g,"").split(/,/);var e,n,r={};for(e=0;e<t.length;e++)(n=t[e].match(/^(?:(["']?)([a-z][a-z0-9]*)\1):(?:(\d+)|"([a-z0-9+\/%*_.@=\-]*)")$/i))||x(new O.exception.invalid("json decode: this isn't json!")),r[n[2]]=n[3]?parseInt(n[3],10):n[2].match(/^(ct|salt|iv)$/)?O.codec.base64.toBits(n[4]):unescape(n[4]);return r},e:function(t,e,n){if(t===j&&(t={}),e===j)return t;for(var r in e)e.hasOwnProperty(r)&&(n&&t[r]!==j&&t[r]!==e[r]&&x(new O.exception.invalid("required parameter overridden")),t[r]=e[r]);return t},ea:function(t,e){var n,r={};for(n in t)t.hasOwnProperty(n)&&t[n]!==e[n]&&(r[n]=t[n]);return r},da:function(t,e){var n,r={};for(n=0;n<e.length;n++)t[e[n]]!==j&&(r[e[n]]=t[e[n]]);return r}},O.encrypt=O.json.encrypt,O.decrypt=O.json.decrypt,O.misc.ca={},O.misc.cachedPbkdf2=function(t,e){var n,r=O.misc.ca;return n=(e=e||{}).iter||1e3,(n=(r=r[t]=r[t]||{})[n]=r[n]||{firstSalt:e.salt&&e.salt.length?e.salt.slice(0):O.random.randomWords(2,0)})[r=e.salt===j?n.firstSalt:e.salt]=n[r]||O.misc.pbkdf2(t,r,e.iter),{key:n[r].slice(0),salt:r.slice(0)}},(L=(E=O).codec.bytes=E.codec.bytes||{}).fromBits=L.fromBits||function(t){var e,n,r=[],i=E.bitArray.bitLength(t);for(e=0;e<i/8;e++)0==(3&e)&&(n=t[e/4]),r.push(n>>>24),n<<=8;return r},L.toBits=L.toBits||function(t){var e,n=[],r=0;for(e=0;e<t.length;e++)r=r<<8|t[e],3==(3&e)&&(n.push(r),r=0);return 3&e&&n.push(E.bitArray.partial(8*(3&e),r)),n},function(){var t,e=(new Date).getTime();function n(t,e,n,r){if("function"==typeof t.addEventListener)t.addEventListener(e,n,r);else{if(!t.attachEvent)throw new Error(W.errors.UNABLETOBIND+": Unable to bind "+e+"-event");t.attachEvent("on"+e,n)}}I=I||(t={},function(r,i,o){if("bind"===r)return I(o+"Bind"),n(i,"change",function(t){I(o+"FieldChangeCount"),I("log",o,"ch");try{I("set",o+"FieldEvHa",function(t){var e=function(){return{}};window.jQuery&&"function"==typeof window.jQuery._data&&(e=function(t){return window.jQuery._data(t,"events")});for(var n=t,r=0,i=[],o=["onmousedown","onmouseup","onmouseover","onmouseout","onclick","onmousemove","ondblclick","onerror","onresize","onscroll","onkeydown","onkeyup","onkeypress","onchange","onsubmit"],s=o.length;n&&n!==n.documentElement;){for(var a,c=s,h=(n.nodeName||n.tagName||"").toUpperCase().substring(0,3);c--;)l=o[c],n[name]&&(r++,i[l=l+(n===t?"Own":"Par")+h]=i[l]||0,i[l]++);var u=e(n);if("object"==typeof u)for(var l in u)u.hasOwnProperty(l)&&(a=u[l].length,i[l=l+(n===t?"Own":"Par")+h]=i[l]||0,i[l]+=a,r+=a);if(!n.parentNode)break;n=n.parentNode}var f=["total="+r];for(var p in i)i.hasOwnProperty(p)&&i[p]>0&&f.push(p+"="+i[p]);return f.join("&")}(i))}catch(t){I("set",o+"FieldEvHa","Err")}},!0),n(i,"click",function(){I(o+"FieldClickCount"),I("log",o,"cl")},!0),n(i,"focus",function(){I(o+"FieldFocusCount"),I("log",o,"fo")},!0),n(i,"blur",function(){I(o+"FieldBlurCount"),I("log",o,"bl")},!0),n(i,"touchstart",function(){I(o+"FieldTouchStartCount"),I("log",o,"Ts")},!0),n(i,"touchend",function(){I(o+"FieldTouchEndCount"),I("log",o,"Te")},!0),n(i,"touchcancel",function(){I(o+"FieldTouchCancelCount"),I("log",o,"Tc")},!0),n(i,"keyup",function(t){16==t.keyCode?I("log",o,"Su"):17==t.keyCode?I("log",o,"Cu"):18==t.keyCode&&I("log",o,"Au")}),void n(i,"keydown",function(t){switch(I(o+"FieldKeyCount"),t&&t.keyCode){case 8:I("log",o,"Kb");break;case 16:I("log",o,"Sd");break;case 17:I("log",o,"Cd");break;case 18:I("log",o,"Ad");break;case 37:I("log",o,"Kl");break;case 39:I("log",o,"Kr");break;case 46:I("log",o,"Kd");break;case 32:I("log",o,"Ks");break;default:t.keyCode>=48&&t.keyCode<=57||t.keyCode>=96&&t.keyCode<=105?I("log",o,"KN"):t.keyCode>=65&&t.keyCode<=90?I("log",o,"KL"):(I("log",o,"KU"),I("log",o+"UnkKeys",t.keyCode))}},!0);if("set"!==r){if("log"===r){var s=i+"FieldLog",a=(new Date).getTime()-e;return a=Math.round(a/100),t.hasOwnProperty(s)?t[s]+=","+o+"@"+a:t[s]=o+"@"+a,void(t[s].length>1500&&(t[s]=t[s].substring(t[s].length-1500),t[s]=t[s].substring(t[s].indexOf(",")+1)))}if("extend"!==r)t.hasOwnProperty(r)?t[r]++:t[r]=1;else for(var c in t)"number"!==c&&"expiryMonth"!==c&&"expiryYear"!==c&&"generationtime"!==c&&"holderName"!==c&&"cvc"!==c&&t.hasOwnProperty(c)&&(i[c]=""+t[c])}else t[i]=o}),window&&(window.attachEvent||window.addEventListener)&&(n(window,"focus",function(){I("activate")}),n(window,"blur",function(){I("deactivate")}))}();var Z=t.adyen=t.adyen||{},W=Z.encrypt=Z.encrypt||{createEncryption:function(t,e){return new Q(t,e)}};"function"==typeof e&&e.amd?e("adyen/encrypt",[],function(){return W}):"undefined"!=typeof module&&module.exports&&(module.exports=W),W.errors=W.errors||{},W.version="0_1_18";var _,H={};H.luhnCheck=(_={},function(){var t=arguments,e=arguments.length>0?t[0]:this.cardnumber;if(isNaN(parseInt(e,10)))return!1;var n=e.length,r=1&n,i=0;if(void 0===_[e]){n>=14&&I("luhnCount");for(var o=0;o<n;o++){var s=parseInt(e.charAt(o),10);1&o^r||(s*=2)>9&&(s-=9),i+=s}i%10==0?(I("luhnOkCount"),_[e]=!0):(I("luhnFailCount"),_[e]=!1)}var a=0;for(var c in _)_.hasOwnProperty(c)&&c.length===n&&a++;return I("set","luhnSameLengthCount",a),_[e]}),H.numberCheck=function(t){return!(!(t||"").replace(/[^\d]/g,"").match(/^\d{10,20}$/)||!H.luhnCheck(t))},H.cvcCheck=function(t){return!!(t&&t.match&&t.match(/^\d{3,4}$/))},H.yearCheck=function(t){if(!t||!t.match||!t.match(/^2\d{3}$/))return!1;var e=parseInt(t,10),n=(new Date).getFullYear();return e>=n-2&&e<=n+15},H.monthCheck=function(t){var e=(t||"").replace(/^0(\d)$/,"$1");return!!(e.match(/^([1-9]|10|11|12)$/)&&parseInt(e,10)>=1&&parseInt(e,10)<=12)},H.holderNameCheck=function(t){return!!(t&&t.match&&t.match(/\S/))};var Q=function(t,e){try{O.random.startCollectors()}catch(t){}if(this.key=t,this.options=e||{},void 0===this.options.numberIgnoreNonNumeric&&(this.options.numberIgnoreNonNumeric=!0),void 0!==this.options.cvcIgnoreFornumber&&delete this.options.cvcIgnoreFornumber,void 0===this.options.fourDigitCvcForBins&&(this.options.fourDigitCvcForBins="34,37"),void 0!==this.options.cvcLengthFornumber&&delete this.options.cvcLengthFornumber,"string"==typeof this.options.cvcIgnoreBins){var n=[];this.options.cvcIgnoreBins.replace(/\d+/g,function(t){return t.length>0&&!isNaN(parseInt(t,10))&&n.push(t),t}),n.length>0&&(this.options.cvcIgnoreFornumber=new RegExp("^\\s*("+n.join("|")+")"))}else void 0!==this.options.cvcIgnoreBins&&delete this.options.cvcIgnoreBins;if("string"==typeof this.options.fourDigitCvcForBins){var r=[];this.options.fourDigitCvcForBins.replace(/\d+/g,function(t){return t.length>0&&!isNaN(parseInt(t,10))&&r.push(t),t}),r.length>0&&(this.options.cvcLengthFornumber={matcher:new RegExp("^\\s*("+r.join("|")+")"),requiredLength:4})}delete this.options.fourDigitCvcForBins,I("initializeCount")};Q.prototype.createRSAKey=function(){var t=this.key.split("|");if(2!=t.length)throw"Malformed public key";var e=t[0],n=t[1],r=new D;return r.setPublic(n,e),r},Q.prototype.createAESKey=function(){return new J},Q.prototype.encrypt=function(t){var e,n,r,i,o,s={};if(void 0!==t.number&&(s.number=t.number),void 0!==t.cvc&&(s.cvc=t.cvc),void 0!==t.expiryMonth&&(s.month=t.expiryMonth),void 0!==t.expiryYear&&(s.year=t.expiryYear),void 0!==t.holderName&&(s.holderName=t.holderName),!1!==this.options.enableValidations&&!1===this.validate(s).valid)return!1;I("extend",t);try{t.dfValue=""}catch(t){}return e=this.createRSAKey(),r=(n=this.createAESKey()).encrypt(JSON.stringify(t)),i=O.codec.bytes.fromBits(n.key),o=e.encrypt_b64(i),["adyenjs_"+W.version+"$",o,"$",r].join("")},Q.prototype.validate=function(t){var e={valid:!0};if("object"!=typeof t)return e.valid=!1,e;for(var n in t)if(t.hasOwnProperty(n)&&void 0!==t[n]){var r=t[n];for(var i in this.options[n+"IgnoreNonNumeric"]&&(r=r.replace(/\D/g,"")),t)if(t.hasOwnProperty(i)){var o=this.options[n+"IgnoreFor"+i],s=this.options[n+"LengthFor"+i];if(o&&t[i].match(o)){e[n]=!0;continue}if(s&&s.matcher&&s.requiredLength&&t[i].match(s.matcher)&&r.length!==s.requiredLength){e[n]=!1;continue}}if(e.hasOwnProperty(n))e.valid=e.valid&&e[n];else switch(n){case"number":e.number=H.numberCheck(r),e.luhn=e.number,e.valid=e.valid&&e.number;break;case"expiryYear":case"year":e.year=H.yearCheck(r),e.expiryYear=e.year,e.valid=e.valid&&e.year;break;case"cvc":e.cvc=H.cvcCheck(r),e.valid=e.valid&&e.cvc;break;case"expiryMonth":case"month":e.month=H.monthCheck(r),e.expiryMonth=e.month,e.valid=e.valid&&e.month;break;case"holderName":e.holderName=H.holderNameCheck(r),e.valid=e.valid&&e.holderName;break;default:e.unknown=e.unknown||[],e.unknown.push(n),e.valid=!1}}return e};var J=function(){};J.prototype={constructor:J,key:O.random.randomWords(8,0),encrypt:function(t){return this.encryptWithIv(t,O.random.randomWords(3,0))},encryptWithIv:function(t,e){var n,r,i,o;return n=new O.cipher.aes(this.key),r=O.codec.utf8String.toBits(t),i=O.mode.ccm.encrypt(n,r,e),o=O.bitArray.concat(e,i),O.codec.base64.fromBits(o)}}}(this,"function"==typeof define?define:null);