├── .editorconfig ├── .gitignore ├── LICENSE ├── README.md ├── index.js ├── lib ├── 0_1_18.js ├── 0_1_22.js ├── 0_1_23.js ├── 0_1_24.js └── 0_1_25.js ├── package-lock.json ├── package.json └── tests └── index.test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | # General 5 | indent_style = space 6 | indent_size = 4 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | end_of_line = lf 11 | max_line_length = 120 12 | tab_width = 4 13 | 14 | # Jetbrains 15 | ij_typescript_spaces_within_object_literal_braces = true 16 | ij_typescript_spaces_within_imports = true 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | .idea/ 61 | 62 | .idea 63 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Danilo Pedrosa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Classic Adyen Client-Side Encryption (CSE) on Node

2 | 3 | > **[DEPRECATED]** This module is deprecated since the original Adyen CSE project is deprecated and this encrytion method will not work with latest versions of Adyen SDK. Please use the official [Adyen Web Components](https://github.com/Adyen/adyen-web) for Credit Card integration. 4 | 5 | > A NodeJS helper to encrypt data with the Adyen CSE 6 | 7 | ## Prerequisites: 8 | 9 | You will need a `Adyen Key` 10 | 11 | ## Install 12 | 13 | ```sh 14 | npm install node-adyen-encrypt 15 | ``` 16 | 17 | ## Specific Version import 18 | 19 | ```js 20 | const adyenEncrypt = require('node-adyen-encrypt')(25); 21 | // this will import the 0_1_25 version 22 | const adyenEncrypt = require('node-adyen-encrypt')(24); 23 | // this will import the 0_1_24 version 24 | const adyenEncrypt = require('node-adyen-encrypt')(23); 25 | // this will import the 0_1_23 version 26 | const adyenEncrypt = require('node-adyen-encrypt')(22); 27 | // this will import the 0_1_22 version 28 | ``` 29 | 30 | ## Usage 31 | 32 | ```js 33 | const adyenEncrypt = require('node-adyen-encrypt')(24); 34 | //this will import the 0_1_24 version 35 | 36 | const adyenKey = "your key as retrieved from the Adyen Customer Area Web Service User page"; 37 | const options = {}; 38 | const cardData = { 39 | number : cardNumber, // 'xxxx xxxx xxxx xxxx' 40 | cvc : cvc, //'xxx' 41 | holderName : holderName, // 'John Doe' 42 | expiryMonth : expiryMonth, //'MM' 43 | expiryYear : expiryYear, // 'YYYY' 44 | generationtime : generationtime // new Date().toISOString() 45 | }; 46 | const cseInstance = adyenEncrypt.createEncryption(adyenKey, options); 47 | cseInstance.validate(cardData); 48 | const dataEncrypted = cseInstance.encrypt(cardData); 49 | ``` 50 | 51 | ## Author 52 | 53 | 👤 **Danilo Pedrosa** 54 | 55 | - Github: [@dmop](https://github.com/dmop) 56 | 57 | ## Show your support 58 | 59 | Give a ⭐️ if this project helped you! 60 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const adyenEncrypt = (versionParam) => { 2 | const version = getVersion(~~versionParam); 3 | return require("./lib/0_1_" + version); 4 | }; 5 | 6 | const availableVersions = [18, 22, 23, 24, 25]; 7 | 8 | const getVersion = (version) => { 9 | return availableVersions.includes(version) ? version : 24; 10 | }; 11 | 12 | module.exports = adyenEncrypt; 13 | -------------------------------------------------------------------------------- /lib/0_1_18.js: -------------------------------------------------------------------------------- 1 | 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>4,h=n+1>6:64,u=n+2>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<>>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<=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>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):this[this.t-1]|=a<=this.DB&&(s-=this.DB))}8==n&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<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=0;--n)e[n+s+1]=this[n]>>i|a,a=(this[n]&o)<=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;for(var s=n+1;s>r;r>0&&(e[this.t-n-1]|=(this.s&o)<>=this.DB;if(t.t>=this.DB;r+=this.s}else{for(r+=this.s;n>=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=0;)t[n]=0;for(n=0;n=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.t0?(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<1?a[l-2]>>this.F2:0),m=this.FV/p,y=(1<=0&&(n[n.t++]=1,n.subTo(w,n)),o.ONE.dlShiftTo(l,w),w.subTo(a,a);a.t=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))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<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<0)for(a>a)>0&&(i=!0,o=l(n));s>=0;)a>(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>>8,b[w++]=255&j;w=0,A()}function S(){if(null==g){for(A(),(g=new v).init(b),w=0;w0&&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=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>>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;ne&&(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<>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>>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>>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>>24),n<<=8;return decodeURIComponent(escape(r))},toBits:function(t){t=unescape(encodeURIComponent(t));var e,n=[],r=0;for(e=0;e>>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(r=s.indexOf(t.charAt(n)))&&x(new O.exception.invalid("this isn't base64!")),26>>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=(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;ri.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>>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;ri&&(t=e.hash(t)),n=0;nr||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;so;o++)r.push(4294967296*Math.random()|0);for(o=0;o=1<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>>=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=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=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>>24),n<<=8;return r},L.toBits=L.toBits||function(t){var e,n=[],r=0;for(e=0;e0&&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;o9&&(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); -------------------------------------------------------------------------------- /lib/0_1_22.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Client Encryption of Forms. 4 | * 5 | * Includes: 6 | * * RSA and ECC in JavaScript | http://www-cs-students.stanford.edu/~tjw/jsbn/ 7 | * * Stanford Javascript Crypto Library | http://crypto.stanford.edu/sjcl/ 8 | * * JSON in JavaScript | http://www.JSON.org/ 9 | * 10 | * Version: 0_1_22 11 | * Author: ADYEN (c) 2014 12 | */ 13 | var window = {};var navigator = {};var document = {};(function(root,fnDefine){var define,exports,df=function(){return""};(function(){try{var b=[new Uint8Array(1),new Uint32Array(1),new Int32Array(1)];return}catch(g){}function f(e,a){return this.slice(e,a)}function c(j,e){if(arguments.length<2){e=0}for(var a=0,h=j.length;a>2,c=((l&3)<<4)|(k>>4);var o=g+1>6):64;var m=g+2>6)+b64map.charAt(e&63)}if(b+1==d.length){e=parseInt(d.substring(b,b+1),16);a+=b64map.charAt(e<<2)}else{if(b+2==d.length){e=parseInt(d.substring(b,b+2),16);a+=b64map.charAt(e>>2)+b64map.charAt((e&3)<<4)}}while((a.length&3)>0){a+=b64padchar}return a}function b64tohex(e){var c="";var d;var a=0;var b;for(d=0;d>2);b=v&3;a=1}else{if(a==1){c+=int2char((b<<2)|(v>>4));b=v&15;a=2}else{if(a==2){c+=int2char(b);c+=int2char(v>>2);b=v&3;a=3}else{c+=int2char((b<<2)|(v>>4));c+=int2char(v&15);a=0}}}}if(a==1){c+=int2char(b<<2)}return c}function b64toBA(e){var d=b64tohex(e);var c;var b=new Array();for(c=0;2*c=0){var d=a*this[f++]+b[e]+h;h=Math.floor(d/67108864);b[e++]=d&67108863}return h}function am2(f,q,r,e,o,a){var k=q&32767,p=q>>15;while(--a>=0){var d=this[f]&32767;var g=this[f++]>>15;var b=p*d+g*k;d=k*d+((b&32767)<<15)+r[e]+(o&1073741823);o=(d>>>30)+(b>>>15)+p*g+(o>>>30);r[e++]=d&1073741823}return o}function am3(f,q,r,e,o,a){var k=q&16383,p=q>>14;while(--a>=0){var d=this[f]&16383;var g=this[f++]>>14;var b=p*d+g*k;d=k*d+((b&16383)<<14)+r[e]+o;o=(d>>28)+(b>>14)+p*g;r[e++]=d&268435455}return o}if(j_lm&&(navigator.appName=="Microsoft Internet Explorer")){BigInteger.prototype.am=am2;dbits=30}else{if(j_lm&&(navigator.appName!="Netscape")){BigInteger.prototype.am=am1;dbits=26}else{BigInteger.prototype.am=am3;dbits=28}}BigInteger.prototype.DB=dbits;BigInteger.prototype.DM=((1<=0;--a){b[a]=this[a]}b.t=this.t;b.s=this.s}function bnpFromInt(a){this.t=1;this.s=(a<0)?-1:0;if(a>0){this[0]=a}else{if(a<-1){this[0]=a+this.DV}else{this.t=0}}}function nbv(a){var b=nbi();b.fromInt(a);return b}function bnpFromString(h,c){var e;if(c==16){e=4}else{if(c==8){e=3}else{if(c==256){e=8}else{if(c==2){e=1}else{if(c==32){e=5}else{if(c==4){e=2}else{this.fromRadix(h,c);return}}}}}}this.t=0;this.s=0;var g=h.length,d=false,f=0;while(--g>=0){var a=(e==8)?h[g]&255:intAt(h,g);if(a<0){if(h.charAt(g)=="-"){d=true}continue}d=false;if(f==0){this[this.t++]=a}else{if(f+e>this.DB){this[this.t-1]|=(a&((1<<(this.DB-f))-1))<>(this.DB-f))}else{this[this.t-1]|=a<=this.DB){f-=this.DB}}if(e==8&&(h[0]&128)!=0){this.s=-1;if(f>0){this[this.t-1]|=((1<<(this.DB-f))-1)<0&&this[this.t-1]==a){--this.t}}function bnToString(c){if(this.s<0){return"-"+this.negate().toString(c)}var e;if(c==16){e=4}else{if(c==8){e=3}else{if(c==2){e=1}else{if(c==32){e=5}else{if(c==4){e=2}else{return this.toRadix(c)}}}}}var g=(1<0){if(j>j)>0){a=true;h=int2char(l)}while(f>=0){if(j>(j+=this.DB-e)}else{l=(this[f]>>(j-=e))&g;if(j<=0){j+=this.DB;--f}}if(l>0){a=true}if(a){h+=int2char(l)}}}return a?h:"0"}function bnNegate(){var a=nbi();BigInteger.ZERO.subTo(this,a);return a}function bnAbs(){return(this.s<0)?this.negate():this}function bnCompareTo(b){var d=this.s-b.s;if(d!=0){return d}var c=this.t;d=c-b.t;if(d!=0){return(this.s<0)?-d:d}while(--c>=0){if((d=this[c]-b[c])!=0){return d}}return 0}function nbits(a){var c=1,b;if((b=a>>>16)!=0){a=b;c+=16}if((b=a>>8)!=0){a=b;c+=8}if((b=a>>4)!=0){a=b;c+=4}if((b=a>>2)!=0){a=b;c+=2}if((b=a>>1)!=0){a=b;c+=1}return c}function bnBitLength(){if(this.t<=0){return 0}return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM))}function bnpDLShiftTo(c,b){var a;for(a=this.t-1;a>=0;--a){b[a+c]=this[a]}for(a=c-1;a>=0;--a){b[a]=0}b.t=this.t+c;b.s=this.s}function bnpDRShiftTo(c,b){for(var a=c;a=0;--d){e[d+f+1]=(this[d]>>a)|h;h=(this[d]&g)<=0;--d){e[d]=0}e[f]=h;e.t=this.t+f+1;e.s=this.s;e.clamp()}function bnpRShiftTo(g,d){d.s=this.s;var e=Math.floor(g/this.DB);if(e>=this.t){d.t=0;return}var b=g%this.DB;var a=this.DB-b;var f=(1<>b;for(var c=e+1;c>b}if(b>0){d[this.t-e-1]|=(this.s&f)<>=this.DB}if(d.t>=this.DB}g+=this.s}else{g+=this.s;while(e>=this.DB}g-=d.s}f.s=(g<0)?-1:0;if(g<-1){f[e++]=this.DV+g}else{if(g>0){f[e++]=g}}f.t=e;f.clamp()}function bnpMultiplyTo(c,e){var b=this.abs(),f=c.abs();var d=b.t;e.t=d+f.t;while(--d>=0){e[d]=0}for(d=0;d=0){d[b]=0}for(b=0;b=a.DV){d[b+a.t]-=a.DV;d[b+a.t+1]=1}}if(d.t>0){d[d.t-1]+=a.am(b,a[b],d,2*b,0,1)}d.s=0;d.clamp()}function bnpDivRemTo(n,h,g){var w=n.abs();if(w.t<=0){return}var k=this.abs();if(k.t0){w.lShiftTo(v,d);k.lShiftTo(v,g)}else{w.copyTo(d);k.copyTo(g)}var p=d.t;var b=d[p-1];if(b==0){return}var o=b*(1<1)?d[p-2]>>this.F2:0);var A=this.FV/o,z=(1<=0){g[g.t++]=1;g.subTo(f,g)}BigInteger.ONE.dlShiftTo(p,f);f.subTo(d,d);while(d.t=0){var c=(g[--u]==b)?this.DM:Math.floor(g[u]*A+(g[u-1]+x)*z);if((g[u]+=d.am(0,c,g,s,0,p))0){g.rShiftTo(v,g)}if(a<0){BigInteger.ZERO.subTo(g,g)}}function bnMod(b){var c=nbi();this.abs().divRemTo(b,null,c);if(this.s<0&&c.compareTo(BigInteger.ZERO)>0){b.subTo(c,c)}return c}function Classic(a){this.m=a}function cConvert(a){if(a.s<0||a.compareTo(this.m)>=0){return a.mod(this.m)}else{return a}}function cRevert(a){return a}function cReduce(a){a.divRemTo(this.m,null,a)}function cMulTo(a,c,b){a.multiplyTo(c,b);this.reduce(b)}function cSqrTo(a,b){a.squareTo(b);this.reduce(b)}Classic.prototype.convert=cConvert;Classic.prototype.revert=cRevert;Classic.prototype.reduce=cReduce;Classic.prototype.mulTo=cMulTo;Classic.prototype.sqrTo=cSqrTo;function bnpInvDigit(){if(this.t<1){return 0}var a=this[0];if((a&1)==0){return 0}var b=a&3;b=(b*(2-(a&15)*b))&15;b=(b*(2-(a&255)*b))&255;b=(b*(2-(((a&65535)*b)&65535)))&65535;b=(b*(2-a*b%this.DV))%this.DV;return(b>0)?this.DV-b:-b}function Montgomery(a){this.m=a;this.mp=a.invDigit();this.mpl=this.mp&32767;this.mph=this.mp>>15;this.um=(1<<(a.DB-15))-1;this.mt2=2*a.t}function montConvert(a){var b=nbi();a.abs().dlShiftTo(this.m.t,b);b.divRemTo(this.m,null,b);if(a.s<0&&b.compareTo(BigInteger.ZERO)>0){this.m.subTo(b,b)}return b}function montRevert(a){var b=nbi();a.copyTo(b);this.reduce(b);return b}function montReduce(a){while(a.t<=this.mt2){a[a.t++]=0}for(var c=0;c>15)*this.mpl)&this.um)<<15))&a.DM;b=c+this.m.t;a[b]+=this.m.am(0,d,a,c,0,this.m.t);while(a[b]>=a.DV){a[b]-=a.DV;a[++b]++}}a.clamp();a.drShiftTo(this.m.t,a);if(a.compareTo(this.m)>=0){a.subTo(this.m,a)}}function montSqrTo(a,b){a.squareTo(b);this.reduce(b)}function montMulTo(a,c,b){a.multiplyTo(c,b);this.reduce(b)}Montgomery.prototype.convert=montConvert;Montgomery.prototype.revert=montRevert;Montgomery.prototype.reduce=montReduce;Montgomery.prototype.mulTo=montMulTo;Montgomery.prototype.sqrTo=montSqrTo;function bnpIsEven(){return((this.t>0)?(this[0]&1):this.s)==0}function bnpExp(h,j){if(h>4294967295||h<1){return BigInteger.ONE}var f=nbi(),a=nbi(),d=j.convert(this),c=nbits(h)-1;d.copyTo(f);while(--c>=0){j.sqrTo(f,a);if((h&(1<0){j.mulTo(a,d,f)}else{var b=f;f=a;a=b}}return j.revert(f)}function bnModPowInt(b,a){var c;if(b<256||a.isEven()){c=new Classic(a)}else{c=new Montgomery(a)}return this.exp(b,c)}BigInteger.prototype.copyTo=bnpCopyTo;BigInteger.prototype.fromInt=bnpFromInt;BigInteger.prototype.fromString=bnpFromString;BigInteger.prototype.clamp=bnpClamp;BigInteger.prototype.dlShiftTo=bnpDLShiftTo;BigInteger.prototype.drShiftTo=bnpDRShiftTo;BigInteger.prototype.lShiftTo=bnpLShiftTo;BigInteger.prototype.rShiftTo=bnpRShiftTo;BigInteger.prototype.subTo=bnpSubTo;BigInteger.prototype.multiplyTo=bnpMultiplyTo;BigInteger.prototype.squareTo=bnpSquareTo;BigInteger.prototype.divRemTo=bnpDivRemTo;BigInteger.prototype.invDigit=bnpInvDigit;BigInteger.prototype.isEven=bnpIsEven;BigInteger.prototype.exp=bnpExp;BigInteger.prototype.toString=bnToString;BigInteger.prototype.negate=bnNegate;BigInteger.prototype.abs=bnAbs;BigInteger.prototype.compareTo=bnCompareTo;BigInteger.prototype.bitLength=bnBitLength;BigInteger.prototype.mod=bnMod;BigInteger.prototype.modPowInt=bnModPowInt;BigInteger.ZERO=nbv(0);BigInteger.ONE=nbv(1);function Arcfour(){this.i=0;this.j=0;this.S=new Array}function ARC4init(c){var a,d,b;for(a=0;a<256;++a){this.S[a]=a}d=0;for(a=0;a<256;++a){d=d+this.S[a]+c[a%c.length]&255;b=this.S[a];this.S[a]=this.S[d];this.S[d]=b}this.i=0;this.j=0}function ARC4next(){var a;this.i=this.i+1&255;this.j=this.j+this.S[this.i]&255;a=this.S[this.i];this.S[this.i]=this.S[this.j];this.S[this.j]=a;return this.S[a+this.S[this.i]&255]}function prng_newstate(){return new Arcfour}Arcfour.prototype.init=ARC4init;Arcfour.prototype.next=ARC4next;var rng_psize=256;var rng_state;var rng_pool;var rng_pptr;function rng_seed_int(a){rng_pool[rng_pptr++]^=a&255;rng_pool[rng_pptr++]^=(a>>8)&255;rng_pool[rng_pptr++]^=(a>>16)&255;rng_pool[rng_pptr++]^=(a>>24)&255;if(rng_pptr>=rng_psize){rng_pptr-=rng_psize}}function rng_seed_time(){rng_seed_int(new Date().getTime())}if(rng_pool==null){rng_pool=[];rng_pptr=0;var t;try{if(window.crypto&&window.crypto.getRandomValues){var ua=new Uint8Array(32);window.crypto.getRandomValues(ua);for(t=0;t<32;++t){rng_pool[rng_pptr++]=ua[t]}}else{if(window.msCrypto&&window.msCrypto.getRandomValues){var ua=new Uint8Array(32);window.msCrypto.getRandomValues(ua);for(t=0;t<32;++t){rng_pool[rng_pptr++]=ua[t]}}else{if(window.crypto&&window.crypto.random){var z=window.crypto.random(32);for(t=0;t>>8;rng_pool[rng_pptr++]=t&255}rng_pptr=0;rng_seed_time()}function rng_get_byte(){if(rng_state==null){rng_seed_time();rng_state=prng_newstate();rng_state.init(rng_pool);for(rng_pptr=0;rng_pptr=0&&g>0){f[--g]=c[e--]}f[--g]=0;var d=new SecureRandom();var a=new Array();while(g>2){a[0]=0;while(a[0]==0){d.nextBytes(a)}f[--g]=a[0]}f[--g]=2;f[--g]=0;return new BigInteger(f)}function RSAKey(){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 RSASetPublic(b,a){if(b!=null&&a!=null&&b.length>0&&a.length>0){this.n=parseBigInt(b,16);this.e=parseInt(a,16)}else{alert("Invalid RSA public key")}}function RSADoPublic(a){return a.modPowInt(this.e,this.n)}function RSAEncrypt(b){var a=pkcs1pad2(b,(this.n.bitLength()+7)>>3);if(a==null){return null}var e=this.doPublic(a);if(e==null){return null}var d=e.toString(16);if((d.length&1)==0){return d}else{return"0"+d}}function RSAEncryptB64(a){var b=this.encrypt(a);if(b){return hex2b64(b)}else{return null}}RSAKey.prototype.doPublic=RSADoPublic;RSAKey.prototype.setPublic=RSASetPublic;RSAKey.prototype.encrypt=RSAEncrypt;RSAKey.prototype.encrypt_b64=RSAEncryptB64;"use strict";function q(b){throw b}var t=void 0,u=!1;var sjcl={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(b){this.toString=function(){return"CORRUPT: "+this.message};this.message=b},invalid:function(b){this.toString=function(){return"INVALID: "+this.message};this.message=b},bug:function(b){this.toString=function(){return"BUG: "+this.message};this.message=b},notReady:function(b){this.toString=function(){return"NOT READY: "+this.message};this.message=b}}};"undefined"!==typeof module&&module.exports&&(module.exports=sjcl);"function"===typeof define&&define([],function(){return sjcl});sjcl.cipher.aes=function(j){this.k[0][0][0]||this.D();var i,p,o,n,m=this.k[0][4],l=this.k[1];i=j.length;var k=1;4!==i&&(6!==i&&8!==i)&&q(new sjcl.exception.invalid("invalid aes key size"));this.b=[o=j.slice(0),n=[]];for(j=i;j<4*i+28;j++){p=o[j-1];if(0===j%i||8===i&&4===j%i){p=m[p>>>24]<<24^m[p>>16&255]<<16^m[p>>8&255]<<8^m[p&255],0===j%i&&(p=p<<8^p>>>24^k<<24,k=k<<1^283*(k>>7))}o[j]=o[j-i]^p}for(i=0;j;i++,j--){p=o[i&3?j:j-4],n[i]=4>=j||4>i?p:l[0][m[p>>>24]]^l[1][m[p>>16&255]]^l[2][m[p>>8&255]]^l[3][m[p&255]]}};sjcl.cipher.aes.prototype={encrypt:function(b){return y(this,b,0)},decrypt:function(b){return y(this,b,1)},k:[[[],[],[],[],[]],[[],[],[],[],[]]],D:function(){var R=this.k[0],Q=this.k[1],P=R[4],O=Q[4],N,x,w,v=[],r=[],s,j,o,i;for(N=0;256>N;N++){r[(v[N]=N<<1^283*(N>>7))^N]=N}for(x=w=0;!P[x];x^=s||1,w=r[w]||1){o=w^w<<1^w<<2^w<<3^w<<4;o=o>>8^o&255^99;P[x]=o;O[o]=x;j=v[N=v[s=v[x]]];i=16843009*j^65537*N^257*s^16843008*x;j=257*v[o]^16843008*o;for(N=0;4>N;N++){R[N][x]=j=j<<24^j>>>8,Q[N][o]=i=i<<24^i>>>8}}for(N=0;5>N;N++){R[N]=R[N].slice(0),Q[N]=Q[N].slice(0)}}};function y(ab,aa,Z){4!==aa.length&&q(new sjcl.exception.invalid("invalid aes block size"));var Y=ab.b[Z],X=aa[0]^Y[0],W=aa[Z?3:1]^Y[1],V=aa[2]^Y[2];aa=aa[Z?1:3]^Y[3];var U,S,T,Q=Y.length/4-2,R,P=4,N=[0,0,0,0];U=ab.k[Z];ab=U[0];var O=U[1],o=U[2],j=U[3],i=U[4];for(R=0;R>>24]^O[W>>16&255]^o[V>>8&255]^j[aa&255]^Y[P],S=ab[W>>>24]^O[V>>16&255]^o[aa>>8&255]^j[X&255]^Y[P+1],T=ab[V>>>24]^O[aa>>16&255]^o[X>>8&255]^j[W&255]^Y[P+2],aa=ab[aa>>>24]^O[X>>16&255]^o[W>>8&255]^j[V&255]^Y[P+3],P+=4,X=U,W=S,V=T}for(R=0;4>R;R++){N[Z?3&-R:R]=i[X>>>24]<<24^i[W>>16&255]<<16^i[V>>8&255]<<8^i[aa&255]^Y[P++],U=X,X=W,W=V,V=aa,aa=U}return N}sjcl.bitArray={bitSlice:function(e,d,f){e=sjcl.bitArray.P(e.slice(d/32),32-(d&31)).slice(1);return f===t?e:sjcl.bitArray.clamp(e,f-d)},extract:function(f,e,h){var g=Math.floor(-e-h&31);return((e+h-1^e)&-32?f[e/32|0]<<32-g^f[e/32+1|0]>>>g:f[e/32|0]>>>g)&(1<>d-1,1));return e},partial:function(e,d,f){return 32===e?d:(f?d|0:d<<32-e)+1099511627776*e},getPartial:function(b){return Math.round(b/1099511627776)||32},equal:function(f,e){if(sjcl.bitArray.bitLength(f)!==sjcl.bitArray.bitLength(e)){return u}var h=0,g;for(g=0;g>>f),j=g[h]<<32-f}h=g.length?g[g.length-1]:0;g=sjcl.bitArray.getPartial(h);i.push(sjcl.bitArray.partial(f+g&31,32>>24|f>>>8&65280|(f&65280)<<8|f<<24}return e}};sjcl.codec.utf8String={fromBits:function(g){var f="",j=sjcl.bitArray.bitLength(g),i,h;for(i=0;i>>24),h<<=8}return decodeURIComponent(escape(f))},toBits:function(f){f=unescape(encodeURIComponent(f));var e=[],h,g=0;for(h=0;h>>n)>>>26),6>n?(l=j[p]<<6-n,n+=26,p++):(l<<=6,n-=6)}for(;o.length&3&&!i;){o+="="}return o},toBits:function(j,i){j=j.replace(/\s|=/g,"");var p=[],o,n=0,m=sjcl.codec.base64.J,l=0,k;i&&(m=m.substr(0,62)+"-_");for(o=0;ok&&q(new sjcl.exception.invalid("this isn't base64!")),26>>n),l=k<<32-n):(n+=6,l^=k<<32-n)}n&56&&p.push(sjcl.bitArray.partial(n&56,l,1));return p}};sjcl.codec.base64url={fromBits:function(b){return sjcl.codec.base64.fromBits(b,1,1)},toBits:function(b){return sjcl.codec.base64.toBits(b,1)}};sjcl.hash.sha256=function(b){this.b[0]||this.D();b?(this.r=b.r.slice(0),this.o=b.o.slice(0),this.h=b.h):this.reset()};sjcl.hash.sha256.hash=function(b){return(new sjcl.hash.sha256).update(b).finalize()};sjcl.hash.sha256.prototype={blockSize:512,reset:function(){this.r=this.N.slice(0);this.o=[];this.h=0;return this},update:function(e){"string"===typeof e&&(e=sjcl.codec.utf8String.toBits(e));var d,f=this.o=sjcl.bitArray.concat(this.o,e);d=this.h;e=this.h=d+sjcl.bitArray.bitLength(e);for(d=512+d&-512;d<=e;d+=512){z(this,f.splice(0,16))}return this},finalize:function(){var e,d=this.o,f=this.r,d=sjcl.bitArray.concat(d,[sjcl.bitArray.partial(1,1)]);for(e=d.length+2;e&15;e++){d.push(0)}d.push(Math.floor(this.h/4294967296)); 14 | for(d.push(this.h|0);d.length;){z(this,d.splice(0,16))}this.reset();return f},N:[],b:[],D:function(){function f(b){return 4294967296*(b-Math.floor(b))|0}var e=0,h=2,g;f:for(;64>e;h++){for(g=2;g*g<=h;g++){if(0===h%g){continue f}}8>e&&(this.N[e]=f(Math.pow(h,0.5)));this.b[e]=f(Math.pow(h,1/3));e++}}};function z(V,U){var T,S,R,Q=U.slice(0),P=V.r,O=V.b,x=P[0],N=P[1],o=P[2],w=P[3],j=P[4],X=P[5],i=P[6],W=P[7];for(T=0;64>T;T++){16>T?S=Q[T]:(S=Q[T+1&15],R=Q[T+14&15],S=Q[T&15]=(S>>>7^S>>>18^S>>>3^S<<25^S<<14)+(R>>>17^R>>>19^R>>>10^R<<15^R<<13)+Q[T&15]+Q[T+9&15]|0),S=S+W+(j>>>6^j>>>11^j>>>25^j<<26^j<<21^j<<7)+(i^j&(X^i))+O[T],W=i,i=X,X=j,j=w+S|0,w=o,o=N,N=x,x=S+(N&o^w&(N^o))+(N>>>2^N>>>13^N>>>22^N<<30^N<<19^N<<10)|0}P[0]=P[0]+x|0;P[1]=P[1]+N|0;P[2]=P[2]+o|0;P[3]=P[3]+w|0;P[4]=P[4]+j|0;P[5]=P[5]+X|0;P[6]=P[6]+i|0;P[7]=P[7]+W|0}sjcl.mode.ccm={name:"ccm",encrypt:function(w,v,s,r,p){var o,n=v.slice(0),m=sjcl.bitArray,i=m.bitLength(s)/8,j=m.bitLength(n)/8;p=p||64;r=r||[];7>i&&q(new sjcl.exception.invalid("ccm: iv must be at least 7 bytes"));for(o=2;4>o&&j>>>8*o;o++){}o<15-i&&(o=15-i);s=m.clamp(s,8*(15-o));v=sjcl.mode.ccm.L(w,v,s,r,p,o);n=sjcl.mode.ccm.p(w,n,s,v,p,o);return m.concat(n.data,n.tag)},decrypt:function(w,v,s,r,p){p=p||64;r=r||[];var o=sjcl.bitArray,n=o.bitLength(s)/8,m=o.bitLength(v),i=o.clamp(v,m-p),j=o.bitSlice(v,m-p),m=(m-p)/8;7>n&&q(new sjcl.exception.invalid("ccm: iv must be at least 7 bytes"));for(v=2;4>v&&m>>>8*v;v++){}v<15-n&&(v=15-n);s=o.clamp(s,8*(15-v));i=sjcl.mode.ccm.p(w,i,s,j,p,v);w=sjcl.mode.ccm.L(w,i.data,s,r,p,v);o.equal(i.tag,w)||q(new sjcl.exception.corrupt("ccm: tag doesn't match"));return i.data},L:function(s,r,p,o,n,m){var k=[],j=sjcl.bitArray,i=j.l;n/=8;(n%2||4>n||16=p?k=[j.partial(16,p)]:4294967295>=p&&(k=j.concat([j.partial(16,65534)],[p]));k=j.concat(k,o);for(o=0;on.bitLength(p)&&(k=m(k,o(k)),p=n.concat(p,[-2147483648,0,0,0]));l=m(l,p);return j.encrypt(m(o(m(k,o(k))),l))},H:function(b){return[b[0]<<1^b[1]>>>31,b[1]<<1^b[2]>>>31,b[2]<<1^b[3]>>>31,b[3]<<1^135*(b[0]>>>31)]}};sjcl.mode.gcm={name:"gcm",encrypt:function(h,g,l,k,j){var i=g.slice(0);g=sjcl.bitArray;k=k||[];h=sjcl.mode.gcm.p(!0,h,i,k,l,j||128);return g.concat(h.data,h.tag)},decrypt:function(j,i,p,o,n){var m=i.slice(0),l=sjcl.bitArray,k=l.bitLength(m);n=n||128;o=o||[];n<=k?(i=l.bitSlice(m,k-n),m=l.bitSlice(m,0,k-n)):(i=m,m=[]);j=sjcl.mode.gcm.p(u,j,m,o,p,n);l.equal(j.tag,i)||q(new sjcl.exception.corrupt("gcm: tag doesn't match"));return j.data},Z:function(j,i){var p,o,n,m,l,k=sjcl.bitArray.l;n=[0,0,0,0];m=i.slice(0);for(p=0;128>p;p++){(o=0!==(j[Math.floor(p/32)]&1<<31-p%32))&&(n=k(n,m));l=0!==(m[3]&1);for(o=3;0>>1|(m[o-1]&1)<<31}m[0]>>>=1;l&&(m[0]^=-520093696)}return n},g:function(g,f,j){var i,h=j.length;f=f.slice(0);for(i=0;ih&&(g=f.hash(g));for(i=0;iv||0>w)&&q(sjcl.exception.invalid("invalid params to pbkdf2"));"string"===typeof N&&(N=sjcl.codec.utf8String.toBits(N));"string"===typeof x&&(x=sjcl.codec.utf8String.toBits(x));s=s||sjcl.misc.hmac;N=new s(N);var r,p,o,j,m=[],i=sjcl.bitArray;for(j=1;32*m.length<(v||1);j++){s=r=N.encrypt(i.concat(x,[j]));for(p=1;pj;j++){l.push(4294967296*Math.random()|0)}for(j=0;j=1<this.j&&(this.j=k);this.F++;this.b=sjcl.hash.sha256.hash(this.b.concat(l));this.A=new sjcl.cipher.aes(this.b);for(m=0;4>m&&!(this.f[m]=this.f[m]+1|0,this.f[m]);m++){}}for(m=0;m>>=1}}}this.c[k].update([o,this.C++,2,r,m,s.length].concat(s))}break;case"string":r===t&&(r=s.length);this.c[k].update([o,this.C++,3,r,m,s.length]);this.c[k].update(s);break;default:i=1}i&&q(new sjcl.exception.bug("random: addEntropy only supports number, array of numbers or string"));this.i[k]+=r;this.d+=r;j===this.m&&(this.isReady()!==this.m&&C("seeded",Math.max(this.j,this.d)),C("progress",this.getProgress()))},isReady:function(b){b=this.I[b!==t?b:this.B];return this.j&&this.j>=b?this.i[0]>this.R&&(new Date).valueOf()>this.O?this.u|this.t:this.t:this.d>=b?this.u|this.m:this.m},getProgress:function(b){b=this.I[b?b:this.B];return this.j>=b?1:this.d>b?1:this.d/b},startCollectors:function(){this.q||(this.a={loadTimeCollector:D(this,this.aa),mouseCollector:D(this,this.ba),keyboardCollector:D(this,this.$),accelerometerCollector:D(this,this.U)},window.addEventListener?(window.addEventListener("load",this.a.loadTimeCollector,u),window.addEventListener("mousemove",this.a.mouseCollector,u),window.addEventListener("keypress",this.a.keyboardCollector,u),window.addEventListener("devicemotion",this.a.accelerometerCollector,u)):document.attachEvent?(document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector)):q(new sjcl.exception.bug("can't attach event")),this.q=!0)},stopCollectors:function(){this.q&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,u),window.removeEventListener("mousemove",this.a.mouseCollector,u),window.removeEventListener("keypress",this.a.keyboardCollector,u),window.removeEventListener("devicemotion",this.a.accelerometerCollector,u)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.q=u)},addEventListener:function(d,c){this.w[d][this.V++]=c},removeEventListener:function(h,g){var l,k,j=this.w[h],i=[];for(k in j){j.hasOwnProperty(k)&&j[k]===g&&i.push(k)}for(l=0;lc&&!(d.f[c]=d.f[c]+1|0,d.f[c]);c++){}return d.A.encrypt(d.f)}function D(d,c){return function(){c.apply(d,arguments)}}sjcl.random=new sjcl.prng(6);a:try{var F,G,H,I;if(I="undefined"!==typeof module){var J;if(J=module.exports){var K;try{K=require("crypto")}catch(L){K=null}J=(G=K)&&G.randomBytes}I=J}if(I){F=G.randomBytes(128),F=new Uint32Array((new Uint8Array(F)).buffer),sjcl.random.addEntropy(F,1024,"crypto['randomBytes']")}else{if("undefined"!==typeof window&&"undefined"!==typeof Uint32Array){H=new Uint32Array(32);if(window.crypto&&window.crypto.getRandomValues){window.crypto.getRandomValues(H)}else{if(window.msCrypto&&window.msCrypto.getRandomValues){window.msCrypto.getRandomValues(H)}else{break a}}sjcl.random.addEntropy(H,1024,"crypto['getRandomValues']")}}}catch(M){"undefined"!==typeof window&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(M))}sjcl.json={defaults:{v:1,iter:1000,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},Y:function(i,h,n,m){n=n||{};m=m||{};var l=sjcl.json,k=l.e({iv:sjcl.random.randomWords(4,0)},l.defaults),j;l.e(k,n);n=k.adata;"string"===typeof k.salt&&(k.salt=sjcl.codec.base64.toBits(k.salt));"string"===typeof k.iv&&(k.iv=sjcl.codec.base64.toBits(k.iv));(!sjcl.mode[k.mode]||!sjcl.cipher[k.cipher]||"string"===typeof i&&100>=k.iter||64!==k.ts&&96!==k.ts&&128!==k.ts||128!==k.ks&&192!==k.ks&&256!==k.ks||2>k.iv.length||4=h.iter||64!==h.ts&&96!==h.ts&&128!==h.ts||128!==h.ks&&192!==h.ks&&256!==h.ks||!h.iv||2>h.iv.length||4>>24);e<<=8}return d};b.toBits=b.toBits||function(c){var d=[],f,e=0;for(f=0;f=48&&i.keyCode<=57||i.keyCode>=96&&i.keyCode<=105){evLog("log",e,"KN")}else{if(i.keyCode>=65&&i.keyCode<=90){evLog("log",e,"KL")}else{evLog("log",e,"KU");evLog("log",e+"UnkKeys",i.keyCode)}}break}},true);return}if(j==="set"){d[h]=e;return}if(j==="log"){var k=h+"FieldLog";var f=(new Date().getTime())-a;f=Math.round(f/100);if(!d.hasOwnProperty(k)){d[k]=e+"@"+f}else{d[k]+=","+e+"@"+f}if(d[k].length>1500){d[k]=d[k].substring(d[k].length-1500);d[k]=d[k].substring(d[k].indexOf(",")+1)}return}if(j==="extend"){for(var g in d){if(g==="number"||g==="expiryMonth"||g==="expiryYear"||g==="generationtime"||g==="holderName"||g==="cvc"){continue}if(d.hasOwnProperty(g)){h[g]=""+d[g]}}return}if(!d.hasOwnProperty(j)){d[j]=1}else{d[j]++}}})();function b(j){var p=function(){return{}};if(window.jQuery&&typeof window.jQuery._data=="function"){p=function(o){return window.jQuery._data(o,"events")}}var n=j,d=0,q=[],u=["onmousedown","onmouseup","onmouseover","onmouseout","onclick","onmousemove","ondblclick","onerror","onresize","onscroll","onkeydown","onkeyup","onkeypress","onchange","onsubmit"],k="Own",s="Par",t=u.length;var i=0;while(n&&n!==n.documentElement){i++;var m=t,g,l,h=(n.nodeName||n.tagName||"").toUpperCase().substring(0,3);while(m--){g=u[m];if(n[name]){g=g+((n===j)?k:s)+h;d++;q[g]=q[g]||0;q[g]++}}var r=p(n);if(typeof r==="object"){for(var g in r){if(r.hasOwnProperty(g)){l=r[g].length;g=g+((n===j)?k:s)+h;q[g]=q[g]||0;q[g]+=l;d+=l}}}if(!n.parentNode){break}n=n.parentNode}var e=["total="+d];for(var f in q){if(q.hasOwnProperty(f)&&q[f]>0){e.push(f+"="+q[f])}}return e.join("&")}if(window&&(window.attachEvent||window.addEventListener)){c(window,"focus",function(){evLog("activate");if(window.location&&typeof window.location.href=="string"){evLog("set","referrer",window.location.href)}});c(window,"blur",function(){evLog("deactivate")})}}());var adyen=root.adyen=root.adyen||{};var encrypt=adyen.encrypt=adyen.encrypt||{createEncryptedForm:function(form,key,options){return new EncryptedForm(form,key,options)},createEncryption:function(key,options){return new Encryption(key,options)}};if(typeof fnDefine==="function"&&fnDefine.amd){fnDefine("adyen/encrypt",[],function(){return encrypt})}else{if(typeof module!=="undefined"&&module.exports){module.exports=encrypt}}(function(document,window){if(document&&window&&document.getElementsByTagName){var _=_?_:{};_.X=function(d,h,g,f){f=new (window.ActiveXObject?ActiveXObject:XMLHttpRequest)("Microsoft.XMLHTTP");f.open(g?"POST":"GET",d,1);g?f.setRequestHeader("Content-type","application/x-www-form-urlencoded"):0;f.onreadystatechange=function(){f.readyState>3&&h?h(f.responseText,f):0};f.send(g)};_.E=function(g,f,h,e){if(g.attachEvent?(e?g.detachEvent("on"+f,g[f+h]):!0):(e?g.removeEventListener(f,h,!1):g.addEventListener(f,h,!1))){g["e"+f+h]=h;g[f+h]=function(){g["e"+f+h](window.event)};g.attachEvent("on"+f,g[f+h])}};_.G=function(b){return b.style?b:document.getElementById(b)};_.A=function(g,h,i,c,j){if(c===undefined){var c=new Object();c.value=0}c.value?0:c.value=0;return j.value=setInterval(function(){i(c.value/g);++c.value>g?clearInterval(j.value):0},h)};_.F=function(g,d,h,f){g=g=="in";_.A(h?h:15,f?f:50,function(a){a=(g?0:1)+(g?1:-1)*a;d.style.opacity=a;d.style.filter="alpha(opacity="+100*a+")"})};_.S=function(h,o,i,p,f,d,c){h=h=="in";_.A(i?i:15,p?p:50,function(a){a=(h?0:1)+(h?1:-1)*a;o.style.width=parseInt(a*f)+"px"},c,d)};_.Q=function(k){var i=new Object();var m=new Array();for(var f=0;f0){var G=y.pop();var A=false;for(z=0;zD){return padString("",10)}v.style.fontFamily=G+","+u[z];C.appendChild(v);var H=(v.offsetWidth!==t[u[z]]||v.offsetHeight!==I[u[z]]);C.removeChild(v);A=A||H}if(A){F.push(G)}}return F.join(";")}catch(w){return padString("",10)}}function dfGetProp(){var E={};var s={};s.plugins=10;s.nrOfPlugins=3;s.fonts=10;s.nrOfFonts=3;s.timeZone=10;s.video=10;s.superCookies=10;s.userAgent=10;s.mimeTypes=10;s.nrOfMimeTypes=3;s.canvas=10;s.cpuClass=5;s.platform=5;s.doNotTrack=5;s.webglFp=10;s.jsFonts=10;try{try{var B=dfGetPlug();E.plugins=padString(calculateMd5_b64(B.obj),s.plugins);E.nrOfPlugins=padString(String(B.nr),s.nrOfPlugins)}catch(u){E.plugins=padString("",s.plugins);E.nrOfPlugins=padString("",s.nrOfPlugins)}E.fonts=padString("",s.fonts);E.nrOfFonts=padString("",s.nrOfFonts);try{var e=new Date();e.setDate(1);e.setMonth(5);var C=e.getTimezoneOffset();e.setMonth(11);var D=e.getTimezoneOffset();E.timeZone=padString(calculateMd5_b64(C+"**"+D),s.timeZone)}catch(u){E.timeZone=padString("",s.timeZone)}try{E.video=padString(String((screen.width+7)*(screen.height+7)*screen.colorDepth),s.video)}catch(u){E.video=padString("",s.video)}E.superCookies=padString(calculateMd5_b64(dfGetDS()),Math.floor(s.superCookies/2))+padString(calculateMd5_b64(dfGetIEUD()),Math.floor(s.superCookies/2));E.userAgent=padString(calculateMd5_b64(navigator.userAgent),s.userAgent);var v="";var y=0;if(navigator.mimeTypes){y=navigator.mimeTypes.length;for(var z=0;z=0){return"20"}}}return"40"}function dfSet(m,e){try{var i=dfGetProp();var p=dfHashConcat(i);var j=dfGetEntropy();var k=_.G(m);k.value=p+":"+j}catch(o){}}function dfHashConcat(e){try{var f="";f=e.plugins+e.nrOfPlugins+e.fonts+e.nrOfFonts+e.timeZone+e.video+e.superCookies+e.userAgent+e.mimeTypes+e.nrOfMimeTypes+e.canvas+e.cpuClass+e.platform+e.doNotTrack+e.webglFp+e.jsFonts;f=f.replace(/\+/g,"G").replace(/\//g,"D");return f}catch(d){return""}}function dfDo(d){try{var f=_.G(d);if(!f){return}if(f.value){return}dfInitDS();_.R(function(){setTimeout(function(){dfSet(d,0)},500)})}catch(e){}}function padString(f,e){if(f.length>=e){return(f.substring(0,e))}else{for(var d="";d.length>5]|=128<<((a)%32);g[(((a+64)>>>9)<<4)+14]=a;var h=1732584193;var i=-271733879;var j=-1732584194;var y=271733878;for(var e=0;e>16)+(a>>16)+(b>>16);return(h<<16)|(b&65535)}function md5_bit_rol(a,b){return(a<>>(32-b))}function md5_s2b(c){var h=Array();var a=(1<<8)-1;for(var b=0;b>5]|=(c.charCodeAt(b/8)&a)<<(b%32)}return h}function md5_binl2b64(i){var c="";var j="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var p="";for(var b=0;b>2]>>8*(b%4))&255)<<16)|(((i[b+1>>2]>>8*((b+1)%4))&255)<<8)|((i[b+2>>2]>>8*((b+2)%4))&255);for(var d=0;d<4;d++){if(b*8+d*6>i.length*32){p+=c}else{p+=j.charAt((a>>6*(3-d))&63)}}}return p}var PluginDetect={version:"0.7.5",name:"PluginDetect",handler:function(a,c,b){return function(){a(c,b)}},isDefined:function(b){return typeof b!="undefined"},isArray:function(b){return(/array/i).test(Object.prototype.toString.call(b))},isFunc:function(b){return typeof b=="function"},isString:function(b){return typeof b=="string"},isNum:function(b){return typeof b=="number"},isStrNum:function(b){return(typeof b=="string"&&(/\d/).test(b))},getNumRegx:/[\d][\d\.\_,-]*/,splitNumRegx:/[\.\_,-]/g,getNum:function(d,a){var b=this,c=b.isStrNum(d)?(b.isDefined(a)?new RegExp(a):b.getNumRegx).exec(d):null;return c?c[0]:null},compareNums:function(b,h,f){var g=this,e,d,c,a=parseInt;if(g.isStrNum(b)&&g.isStrNum(h)){if(g.isDefined(f)&&f.compareNums){return f.compareNums(b,h)}e=b.split(g.splitNumRegx);d=h.split(g.splitNumRegx);for(c=0;ca(d[c],10)){return 1}if(a(e[c],10)a||!(/\d/).test(c[d])){c[d]="0"}}return c.slice(0,4).join(",")},$hasMimeType:function(a){return function(d){if(!a.isIE&&d){var c,b,e,f=a.isString(d)?[d]:d;if(!f||!f.length){return null}for(e=0;e2||!h||!h.version||!(g=b.getNum(h.version))){return d}if(!d){return g}g=b.formatNum(g);d=b.formatNum(d);f=d.split(b.splitNumRegx);a=g.split(b.splitNumRegx);for(c=0;c-1&&c>e&&f[c]!="0"){return d}if(a[c]!=f[c]){if(e==-1){e=c}if(f[c]!="0"){return d}}}return g},AXO:window.ActiveXObject,getAXO:function(f){var c=null,b,a=this,d;try{c=new a.AXO(f)}catch(b){}return c},convertFuncs:function(b){var d,c,a,g=/^[\$][\$]/,h={},f=this;for(d in b){if(g.test(d)){h[d]=1}}for(d in h){try{c=d.slice(2);if(c.length>0&&!b[c]){b[c]=b[d](b);delete b[d]}}catch(a){}}},initScript:function(){var i=this,g=navigator,a="/",e=g.userAgent||"",c=g.vendor||"",h=g.platform||"",d=g.product||"";i.OS=100;if(h){var b,j=["Win",1,"Mac",2,"Linux",3,"FreeBSD",4,"iPhone",21.1,"iPod",21.2,"iPad",21.3,"Win.*CE",22.1,"Win.*Mobile",22.2,"Pocket\\s*PC",22.3,"",100];for(b=j.length-2;b>=0;b=b-2){if(j[b]&&new RegExp(j[b],"i").test(h)){i.OS=j[b+1];break}}}i.convertFuncs(i);i.isIE=(function(){var m=(function(u,ae){var q="0.7.10",o="",p="?",U="function",ac="undefined",ag="object",W="string",af="major",R="model",ad="name",Y="type",Q="vendor",t="version",ai="architecture",ab="console",V="mobile",s="tablet",Z="smarttv",r="wearable",T="embedded";var ah={extend:function(z,w){for(var y in w){if("browser cpu device engine os".indexOf(y)!==-1&&w[y].length%2===0){z[y]=w[y].concat(z[y])}}return z},has:function(w,y){if(typeof w==="string"){return y.toLowerCase().indexOf(w.toLowerCase())!==-1}else{return false}},lowerize:function(w){return w.toLowerCase()},major:function(w){return typeof(w)===W?w.split(".")[0]:ae}};var v={rgx:function(){var w,D=0,E,F,G,H,C,B,A=arguments;while(D0){if(H.length==2){if(typeof H[1]==U){w[H[0]]=H[1].call(this,B)}else{w[H[0]]=H[1]}}else{if(H.length==3){if(typeof H[1]===U&&!(H[1].exec&&H[1].test)){w[H[0]]=B?H[1].call(this,B,H[2]):ae}else{w[H[0]]=B?B.replace(H[1],H[2]):ae}}else{if(H.length==4){w[H[0]]=B?H[3].call(this,B.replace(H[1],H[2])):ae}}}}else{w[H]=B?B:ae}}}}D+=2}return w},str:function(w,y){for(var z in y){if(typeof y[z]===ag&&y[z].length>0){for(var A=0;A0&&a.isFunc(c[0])))){b.push(c)}},callArray:function(c){var a=this,b;if(a.isArray(c)){for(b=0;b0&&c.isFunc(a[0])){a[0](c,b>1?a[1]:0,b>2?a[2]:0,b>3?a[3]:0)}else{if(c.isFunc(a)){a(c)}}},getVersionDelimiter:",",$getVersion:function(a){return function(e,h,g){var b=a.init(e),d,c,f;if(b<0){return null}d=a.plugin;if(d.getVersionDone!=1){d.getVersion(null,h,g);if(d.getVersionDone===null){d.getVersionDone=1}}a.cleanup();c=(d.version||d.version0);c=c?c.replace(a.splitNumRegx,a.getVersionDelimiter):c;return c}},cleanup:function(){var a=this;if(a.garbage&&a.isDefined(window.CollectGarbage)){window.CollectGarbage()}},isActiveXObject:function(a,g){var b=this,d=false,c,f="<",h=f+'object width="1" height="1" style="display:none" '+a.getCodeBaseVersion(g)+">"+a.HTML+f+"/object>";if(!b.head){return d}if(b.head.firstChild){b.head.insertBefore(document.createElement("object"),b.head.firstChild)}else{b.head.appendChild(document.createElement("object"))}b.head.firstChild.outerHTML=h;try{b.head.firstChild.classid=a.classID}catch(c){}try{if(b.head.firstChild.object){d=true}}catch(c){}try{if(d&&b.head.firstChild.readyState<4){b.garbage=true}}catch(c){}b.head.removeChild(b.head.firstChild);return d},codebaseSearch:function(h,b){var c=this;if(!c.ActiveXEnabled||!h){return null}if(h.BIfuncs&&h.BIfuncs.length&&h.BIfuncs[h.BIfuncs.length-1]!==null){c.callArray(h.BIfuncs)}var e,f=h.SEARCH,d;if(c.isStrNum(b)){if(f.match&&f.min&&c.compareNums(b,f.min)<=0){return true}if(f.match&&f.max&&c.compareNums(b,f.max)>=0){return false}e=c.isActiveXObject(h,b);if(e&&(!f.min||c.compareNums(b,f.min)>0)){f.min=b}if(!e&&(!f.max||c.compareNums(b,f.max)<0)){f.max=b}return e}var g=[0,0,0,0],o=[].concat(f.digits),G=f.min?1:0,m,k,j,i,F,a=function(r,q){var p=[].concat(g);p[r]=q;return c.isActiveXObject(h,p.join(","))};if(f.max){i=f.max.split(c.splitNumRegx);for(m=0;mg[0]){g[0]=F[0]}}if(F&&i){for(m=1;mg[m]){g[m]=F[m]}}}if(f.max){for(m=1;m0&&o[m]==0&&o[m-1]=0;d--){e=a.div.childNodes[d];if(e&&e.childNodes){if(b==0){for(c=e.childNodes.length-1;c>=0;c--){e.removeChild(e.childNodes[c])}a.div.removeChild(e)}else{}}}}},DONEfuncs:[],onDoneEmptyDiv:function(){var a=this,b,c;if(!a.winLoaded){return}if(a.WLfuncs&&a.WLfuncs.length&&a.WLfuncs[a.WLfuncs.length-1]!==null){return}for(b in a){c=a[b];if(c&&c.funcs){if(c.OTF==3){return}if(c.funcs.length&&c.funcs[c.funcs.length-1]!==null){return}}}for(b=0;b=a){return -1}try{if(d==i.pluginSize&&(!i.isIE||i.getDOMobj(f).readyState==4)){if(!f.winLoaded&&i.winLoaded){return 1}if(f.winLoaded&&i.isNum(h)){if(!i.isNum(f.count)){f.count=h}if(h-f.count>=10){return 1}}}}catch(k){}return 0},getDOMobj:function(d,f){var c,b=this,a=d?d.span:0,g=a&&a.firstChild?1:0;try{if(g&&f){a.firstChild.focus()}}catch(c){}return g?a.firstChild:null},setStyle:function(g,d){var c=g.style,f,b,a=this;if(c&&d){for(f=0;fo'+g+"/div>");d=h.getElementById(a)}catch(i){}}c=(h.getElementsByTagName("body")[0]||h.body);if(c){if(c.firstChild&&f.isDefined(c.insertBefore)){c.insertBefore(b,c.firstChild)}else{c.appendChild(b)}if(d){c.removeChild(d)}}else{}},insertHTML:function(k,f,m,b,D){var E,a=document,q=this,i,h=a.createElement("span"),c,o,j="<";var g=["outlineStyle","none","borderStyle","none","padding","0px","margin","0px","visibility","visible"];if(!q.isDefined(b)){b=""}if(q.isString(k)&&(/[^\s]/).test(k)){i=j+k+' width="'+q.pluginSize+'" height="'+q.pluginSize+'" ';for(c=0;c'}}i+=b+j+"/"+k+">"}else{i=b}if(!q.div){q.div=a.createElement("div");o=a.getElementById("plugindetect");if(o){q.div=o}else{q.div.id="plugindetect";q.insertDivInBody(q.div)}q.setStyle(q.div,g.concat(["width",q.divWidth+"px","height",(q.pluginSize+3)+"px","fontSize",(q.pluginSize+3)+"px","lineHeight",(q.pluginSize+3)+"px","verticalAlign","baseline","display","block"]));if(!o){q.setStyle(q.div,["position","absolute","right","0px","top","0px"])}}if(q.div&&q.div.parentNode){q.div.appendChild(h);q.setStyle(h,g.concat(["fontSize",(q.pluginSize+3)+"px","lineHeight",(q.pluginSize+3)+"px","verticalAlign","baseline","display","inline"]));try{if(h&&h.parentNode){h.focus()}}catch(E){}try{h.innerHTML=i}catch(E){}if(h.childNodes.length==1&&!(q.isGecko&&q.compareNums(q.verGecko,"1,5,0,0")<0)){q.setStyle(h.firstChild,g.concat(["display","inline"]))}return{span:h,winLoaded:q.winLoaded,tagName:(q.isString(k)?k:"")}}return{span:null,winLoaded:q.winLoaded,tagName:""}},quicktime:{mimeType:["video/quicktime","application/x-quicktimeplayer","image/x-macpaint","image/x-quicktime"],progID:"QuickTimeCheckObject.QuickTimeCheck.1",progID0:"QuickTime.QuickTime",classID:"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B",minIEver:7,HTML:("<")+'param name="src" value="" />'+("<")+'param name="controller" value="false" />',getCodeBaseVersion:function(a){return'codebase="#version='+a+'"'},SEARCH:{min:0,max:0,match:0,digits:[16,128,128,0]},getVersion:function(a){var d=this,b=d.$,e=null,c=null,f;if(!b.isIE){if(b.hasMimeType(d.mimeType)){c=b.OS!=3?b.findNavPlugin("QuickTime.*Plug-?in",0):null;if(c&&c.name){e=b.getNum(c.name)}}}else{if(b.isStrNum(a)){f=a.split(b.splitNumRegx);if(f.length>3&&parseInt(f[3],10)>0){f[3]="9999"}a=f.join(",")}if(b.isStrNum(a)&&b.verIE>=d.minIEver&&d.canUseIsMin()>0){d.installed=d.isMin(a);d.getVersionDone=0;return}d.getVersionDone=1;if(!e&&b.verIE>=d.minIEver){e=d.CDBASE2VER(b.codebaseSearch(d))}if(!e){c=b.getAXO(d.progID);if(c&&c.QuickTimeVersion){e=c.QuickTimeVersion.toString(16);e=parseInt(e.charAt(0),16)+"."+parseInt(e.charAt(1),16)+"."+parseInt(e.charAt(2),16)}}}d.installed=e?1:(c?0:-1);d.version=b.formatNum(e,3)},cdbaseUpper:["7,60,0,0","0,0,0,0"],cdbaseLower:["7,50,0,0",null],cdbase2ver:[function(a,c){var b=c.split(a.$.splitNumRegx);return[b[0],b[1].charAt(0),b[1].charAt(1),b[2]].join(",")},null],CDBASE2VER:function(d){var c=this,a=c.$,f,e=c.cdbaseUpper,b=c.cdbaseLower;if(d){d=a.formatNum(d);for(f=0;f=0&&c.cdbase2ver[f]){return c.cdbase2ver[f](c,d)}}}return d},canUseIsMin:function(){var d=this,b=d.$,f,a=d.canUseIsMin,e=d.cdbaseUpper,c=d.cdbaseLower;if(!a.value){a.value=-1;for(f=0;f2;d--){a=c.getAXO(f.progID+"."+d);if(a){j=d.toString();break}}if(j=="6"){try{a.AllowScriptAccess="always"}catch(g){return"6,0,21,0"}}try{h=k(a.GetVariable("$version"))}catch(g){}if(!h&&j){h=j}}f.installed=h?1:-1;f.version=c.formatNum(h);return true}},shockwave:{mimeType:"application/x-director",progID:"SWCtl.SWCtl",classID:"clsid:166B1BCA-3F9C-11CF-8075-444553540000",getVersion:function(){var f=null,g=null,d,c,b=this,a=b.$;if(!a.isIE){c=a.findNavPlugin("Shockwave\\s*for\\s*Director");if(c&&c.description&&a.hasMimeType(b.mimeType)){f=a.getNum(c.description)}if(f){f=a.getPluginFileVersion(c,f)}}else{try{g=a.getAXO(b.progID).ShockwaveVersion("")}catch(d){}if(a.isString(g)&&g.length>0){f=a.getNum(g)}else{if(a.getAXO(b.progID+".8")){f="8"}else{if(a.getAXO(b.progID+".7")){f="7"}else{if(a.getAXO(b.progID+".1")){f="6"}}}}}b.installed=f?1:-1;b.version=a.formatNum(f)}},windowsmediaplayer:{mimeType:["application/x-mplayer2","application/asx","application/x-ms-wmp"],progID:"wmplayer.ocx",classID:"clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6",getVersion:function(){var f=this,e=null,c=f.$,b,d=null,a;f.installed=-1;if(!c.isIE){if(c.hasMimeType(f.mimeType)){d=c.findNavPlugin("Windows\\s*Media.*Plug-?in",0,"Totem")||c.findNavPlugin("Flip4Mac.*Windows\\s*Media.*Plug-?in",0,"Totem");b=(c.isGecko&&c.compareNums(c.verGecko,c.formatNum("1.8"))<0);b=b||(c.isOpera&&c.verOpera<10);if(!b&&c.getMimeEnabledPlugin(f.mimeType[2],"Windows\\s*Media.*Firefox.*Plug-?in")){a=c.getDOMobj(c.insertHTML("object",["type",f.mimeType[2],"data",""],["src",""],"",f));if(a){e=a.versionInfo}}}}else{d=c.getAXO(f.progID);if(d){e=d.versionInfo}}f.installed=d&&e?1:(d?0:-1);f.version=c.formatNum(e)}},silverlight:{mimeType:"application/x-silverlight",progID:"AgControl.AgControl",digits:[20,20,9,12,31],getVersion:function(){var K=this,u=K.$,i=document,f=null,q=null,a=null,e=true,o=[1,0,1,1,1],k=[1,0,1,1,1],h=function(d){return(d<10?"0":"")+d.toString()},r=function(t,s,d,p,v){return(t+"."+s+"."+d+h(p)+h(v)+".0")},J=function(d,s,p){return g(d,(s==0?p:k[0]),(s==1?p:k[1]),(s==2?p:k[2]),(s==3?p:k[3]),(s==4?p:k[4]))},g=function(d,v,t,s,p,w){var w;try{return d.IsVersionSupported(r(v,t,s,p,w))}catch(w){}return false};if(!u.isIE){var b;if(u.hasMimeType(K.mimeType)){b=u.isGecko&&u.compareNums(u.verGecko,u.formatNum("1.6"))<=0;if(u.isGecko&&b){e=false}a=u.findNavPlugin("Silverlight.*Plug-?in",0);if(a&&a.description){f=u.formatNum(a.description)}if(f){k=f.split(u.splitNumRegx);if(parseInt(k[2],10)>=30226&&parseInt(k[0],10)<2){k[0]="2"}f=k.join(",")}}K.installed=a&&e&&f?1:(a&&e?0:(a?-0.2:-1))}else{q=u.getAXO(K.progID);var m,j,c;if(q&&g(q,o[0],o[1],o[2],o[3],o[4])){for(m=0;mc){return 1}if(hd[0].length?b.slice(d[0].length):[];if(e.compare(i,d[1])>0||e.compare(i,d[d.length-1])<0){return g}for(f=d.length-1;f>=1;f--){if(f==1){break}if(e.compare(d[f],i)==0&&e.compare(d[f],d[f-1])==0){break}if(e.compare(i,d[f])>=0&&e.compare(i,d[f-1])<0){break}}return c[0].join(".")+"."+c[f].join(".")},getVersion:function(b,d){var r=this,s=null,f=0,k=0,g=r.$,m,q,M,a;if(g.isString(d)&&/[^\s]/.test(d)){a=d}else{d=null;a=r.mimeType[0]}if(g.isDefined(r.INSTALLED[a])){r.installed=r.INSTALLED[a];return}if(!g.isIE){var t="RealPlayer.*Plug-?in",o=g.hasMimeType(r.mimeType),h=g.findNavPlugin(t,0);if(o&&h){f=1;if(d){if(g.getMimeEnabledPlugin(d,t)){k=1}else{k=0}}else{k=1}}if(r.getVersionDone!==0){r.getVersionDone=0;if(o){var j=1,c=null,L=null;M=g.hasMimeType("application/vnd.rn-realplayer-javascript");if(M){c=g.formatNum(g.getNum(M.enabledPlugin.description))}if(g.OS==1&&c){var i=c.split(g.splitNumRegx);L=true;if(r.compare(i,[6,0,12,200])<0){L=false}else{if(r.compare(i,[6,0,12,1739])<=0&&r.compare(i,[6,0,12,857])>=0){L=false}}}if(L===false){j=0}if(g.OS<=2){if(g.isGecko&&g.compareNums(g.verGecko,g.formatNum("1,8"))<0){j=0}if(g.isChrome){j=0}if(g.isOpera&&g.verOpera<10){j=0}}else{j=0}if(j){M=g.insertHTML("object",["type",r.mimeType[0]],["src","","autostart","false","imagestatus","false","controls","stopbutton"],"",r);M=g.getDOMobj(M);try{s=g.getNum(M.GetVersionInfo())}catch(m){}g.setStyle(M,["display","none"])}if(!s&&c&&L===false){M=r.convertNum(c,r.q3,r.q1);s=M?M:c}}}else{s=r.version}r.installed=f&&k&&s?1:(f&&k?0:(f?-0.2:-1))}else{M=null;for(q=0;q=0){newClass=newClass.replace(" "+className+" "," ")}elem.className=newClass.replace(/^\s+|\s+$/g,"")}}function getAttribute(node,attribute,defaultValue){if(node&&node.getAttribute){return node.getAttribute(attribute)||defaultValue}else{return defaultValue}}encrypt.version="0_1_22";if(!Function.prototype.bind){Function.prototype.bind=function(oThis){if(typeof this!=="function"){throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable")}var aArgs=Array.prototype.slice.call(arguments,1),fToBind=this,fNOP=function(){},fBound=function(){return fToBind.apply(this instanceof fNOP&&oThis?this:oThis,aArgs.concat(Array.prototype.slice.call(arguments)))};fNOP.prototype=this.prototype;fBound.prototype=new fNOP();return fBound}}if(!Date.prototype.toISOString){(function(){function pad(number){if(number<10){return"0"+number}return number}Date.prototype.toISOString=function(){return this.getUTCFullYear()+"-"+pad(this.getUTCMonth()+1)+"-"+pad(this.getUTCDate())+"T"+pad(this.getUTCHours())+":"+pad(this.getUTCMinutes())+":"+pad(this.getUTCSeconds())+"."+(this.getUTCMilliseconds()/1000).toFixed(3).slice(2,5)+"Z"}}())}var validations={};validations.luhnCheck=(function(){var luhnCache={};return function(){var argv=arguments;var argc=arguments.length;var CardNumber=argc>0?argv[0]:this.cardnumber;if(isNaN(parseInt(CardNumber,10))){return false}var no_digit=CardNumber.length;var oddoeven=no_digit&1;var sum=0;if(typeof luhnCache[CardNumber]==="undefined"){if(no_digit>=14){evLog("luhnCount")}for(var count=0;count9){digit-=9}}sum+=digit}if(sum%10===0){evLog("luhnOkCount");luhnCache[CardNumber]=true}else{evLog("luhnFailCount");luhnCache[CardNumber]=false}}var luhnCacheTries=0;for(var i in luhnCache){if(luhnCache.hasOwnProperty(i)&&i.length===no_digit){luhnCacheTries++}}evLog("set","luhnSameLengthCount",luhnCacheTries);return luhnCache[CardNumber]}})();validations.numberCheck=function(val){return((val||"").replace(/[^\d]/g,"").match(/^\d{10,20}$/)&&validations.luhnCheck(val))?true:false};validations.cvcCheck=function(val){return(val&&val.match&&val.match(/^\d{3,4}$/))?true:false};validations.yearCheck=function(val){if(!val||!val.match||!val.match(/^2\d{3}$/)){return false}var year=parseInt(val,10),currentYear=(new Date()).getFullYear();return year>=currentYear-2&&year<=currentYear+15};validations.monthCheck=function(val){var myVal=(val||"").replace(/^0(\d)$/,"$1");return(myVal.match(/^([1-9]|10|11|12)$/)&&parseInt(myVal,10)>=1&&parseInt(myVal,10)<=12)?true:false};validations.holderNameCheck=function(val){return(val&&val.match&&val.match(/\S/))?true:false};validations.generationTimeValidDate=function(val){if(typeof val!=="string"){return false}var m=val.match(/^(\d{4})-?(\d{2})-?(\d{2})$/);return(m&&(""+m[1]).match(/^20[1-9][0-9]$/)&&(""+m[2]).match(/^(12|11|10|0[1-9])$/)&&(""+m[3]).match(/^(31|30|20|10|[012][1-9])$/))?true:false};validations.generationTimeValidTime=function(val){if(typeof val!=="string"){return false}var reZone=/(Z|[\+\-][012345][0-9]:?[012345][0-9])$/;var withoutZoneAndMs=val.replace(reZone,"").replace(/\.\d+$/,"");return withoutZoneAndMs.match(/^[012345][0-9]:?[012345][0-9]:?[012345][0-9]$/)};validations.generationTimeCheck=function(val){if(typeof val!=="string"){return false}var parts=val.split("T");return(parts.length===2&&validations.generationTimeValidDate(parts[0])&&validations.generationTimeValidTime(parts[1]))?true:false};var Encryption=function(key,options){try{if(options.randomBytes){sjcl.random.addEntropy(options.randomBytes,1024,"crypto.randomBytes")}sjcl.random.startCollectors()}catch(e){}try{df()}catch(e){}this.key=key;this.options=options||{};if(typeof this.options.numberIgnoreNonNumeric==="undefined"){this.options.numberIgnoreNonNumeric=true}if(typeof this.options.cvcIgnoreFornumber!=="undefined"){delete this.options.cvcIgnoreFornumber}if(typeof this.options.fourDigitCvcForBins==="undefined"){this.options.fourDigitCvcForBins="34,37"}if(typeof this.options.cvcLengthFornumber!=="undefined"){delete this.options.cvcLengthFornumber}if(typeof this.options.cvcIgnoreBins==="string"){var binsToIgnore=[];this.options.cvcIgnoreBins.replace(/\d+/g,function(m){if(m.length>0&&!isNaN(parseInt(m,10))){binsToIgnore.push(m)}return m});if(binsToIgnore.length>0){this.options.cvcIgnoreFornumber=new RegExp("^\\s*("+binsToIgnore.join("|")+")")}}else{if(typeof this.options.cvcIgnoreBins!=="undefined"){delete this.options.cvcIgnoreBins}}if(typeof this.options.fourDigitCvcForBins==="string"){var cvcGroups=[];this.options.fourDigitCvcForBins.replace(/\d+/g,function(m){if(m.length>0&&!isNaN(parseInt(m,10))){cvcGroups.push(m)}return m});if(cvcGroups.length>0){this.options.cvcLengthFornumber={matcher:new RegExp("^\\s*("+cvcGroups.join("|")+")"),requiredLength:4}}}delete this.options.fourDigitCvcForBins;evLog("initializeCount")};Encryption.prototype.createRSAKey=function(){var k=this.key.split("|");if(k.length!==2){throw"Malformed public key"}var exp=k[0];var mod=k[1];var rsa=new RSAKey();rsa.setPublic(mod,exp);return rsa};Encryption.prototype.createAESKey=function(){return new AESKey()};Encryption.prototype.encrypt=function(original){var data={};for(var i in original){if(original.hasOwnProperty(i)){data[i]=original[i]}}var rsa,aes,cipher,keybytes,encrypted,prefix,validationObject={};if(typeof data.number!=="undefined"){validationObject.number=data.number}if(typeof data.cvc!=="undefined"){validationObject.cvc=data.cvc}if(typeof data.expiryMonth!=="undefined"){validationObject.month=data.expiryMonth}if(typeof data.expiryYear!=="undefined"){validationObject.year=data.expiryYear}if(typeof data.holderName!=="undefined"){validationObject.holderName=data.holderName}if(typeof data.generationtime!=="undefined"){validationObject.generationtime=data.generationtime}if(this.options.enableValidations!==false&&this.validate(validationObject).valid===false){return false}for(var s=0;s<11;s++){if(sjcl.random&&sjcl.random.isReady(s)){evLog("set","sjclStrength",s)}else{break}}evLog("extend",data);try{data.dfValue=df() 17 | }catch(e){}rsa=this.createRSAKey();aes=this.createAESKey();cipher=aes.encrypt(JSON.stringify(data));keybytes=sjcl.codec.bytes.fromBits(aes.key());encrypted=rsa.encrypt_b64(keybytes);prefix="adyenjs_"+encrypt.version+"$";return[prefix,encrypted,"$",cipher].join("")};Encryption.prototype.validate=function(data){var result={};result.valid=true;if(typeof data!=="object"){result.valid=false;return result}for(var field in data){if(!data.hasOwnProperty(field)||typeof data[field]==="undefined"){continue}var val=data[field];if(this.options[field+"IgnoreNonNumeric"]){val=val.replace(/\D/g,"")}if(this.options[field+"SkipValidation"]){continue}for(var relatedField in data){if(data.hasOwnProperty(relatedField)){var possibleOption=this.options[field+"IgnoreFor"+relatedField];var lengthOption=this.options[field+"LengthFor"+relatedField];if(possibleOption&&data[relatedField].match(possibleOption)){result[field]=true;continue}else{if(lengthOption&&lengthOption.matcher&&lengthOption.requiredLength&&data[relatedField].match(lengthOption.matcher)){if(val.length!==lengthOption.requiredLength){result[field]=false;continue}}}}}if(result.hasOwnProperty(field)){result.valid=result.valid&&result[field];continue}switch(field){case"number":result.number=validations.numberCheck(val);result.luhn=result.number;result.valid=result.valid&&result.number;break;case"expiryYear":case"year":result.year=validations.yearCheck(val);result.expiryYear=result.year;result.valid=result.valid&&result.year;break;case"cvc":result.cvc=validations.cvcCheck(val);result.valid=result.valid&&result.cvc;break;case"expiryMonth":case"month":result.month=validations.monthCheck(val);result.expiryMonth=result.month;result.valid=result.valid&&result.month;break;case"holderName":result.holderName=validations.holderNameCheck(val);result.valid=result.valid&&result.holderName;break;case"generationtime":result.generationtime=validations.generationTimeCheck(val);result.valid=result.valid&&result.generationtime;break;default:result.unknown=result.unknown||[];result.unknown.push(field);result.valid=false}}return result};Encryption.prototype.monitor=function(field,node){if(typeof field!=="string"||(field!=="number"&&field!=="cvc"&&field!=="holderName")){throw new Error("invalid fieldname. Expected 'number', 'cvc' or 'holderName', but received '"+field+"'")}evLog("bind",node,field)};validations.createChangeHandler=function(cse,field,allowEmpty){var ceConfig={chained:false};var ce=function(ev){var node=ev.target||ev.srcElement,val=(node||{}).value||"";var isInitializing=(typeof ev.isInitializing==="boolean"&&ev.isInitializing);if(node.options&&typeof node.selectedIndex!=="undefined"){val=node.options[node.selectedIndex].value}if(cse.options[field+"IgnoreNonNumeric"]){val=val.replace(/\D/g,"")}var fieldData=cse.toJSON(cse.getEncryptedFields(cse.element));var validationData={year:fieldData.expiryYear,month:fieldData.expiryMonth,number:fieldData.number,cvc:fieldData.cvc,holderName:fieldData.holderName};var validationResult=cse.encryption.validate(validationData);for(var i in validationResult){if(validationResult.hasOwnProperty(i)){cse.validity[i]=validationResult[i]}}if(cse.validity[field]){removeClass(node,"invalid-"+field);addClass(node,"valid-"+field)}else{if(!isInitializing||val!==""){addClass(node,"invalid-"+field)}removeClass(node,"valid-"+field)}cse.validity.luhn=cse.validity.number;if((node.className||"").match(/invalid-number/)){addClass(node,"invalid-luhn");removeClass(node,"valid-luhn")}else{if((node.className||"").match(/valid-number/)){removeClass(node,"invalid-luhn");addClass(node,"valid-luhn")}}if(allowEmpty&&val===""){removeClass(node,"valid-"+field);removeClass(node,"invalid-"+field)}if((node.className||"").match(/invalid-/)){addClass(node,"invalid")}else{removeClass(node,"invalid")}if(cse.options.disabledValidClass!==true){if((node.className||"").match(/invalid-/)){removeClass(node,"valid")}else{addClass(node,"valid")}}if(typeof ceConfig.chained==="function"){ceConfig.chained(ev)}else{if(!isInitializing){cse.toggleSubmit()}}};ce.chain=function(handler){ceConfig.chained=handler};return ce};var DEFAULT_FIELDNAME_ATTRIBUTE="data-encrypted-name";var EncryptedForm=function(element,key,options){if(typeof element!=="object"||element===null||typeof element.ownerDocument!=="object"){throw new Error("Expected target element to be a HTML Form element")}if("form"!==(element.nodeName||element.tagName||"").toLowerCase()){throw new Error("Expected target element to be a HTML Form element")}this.element=element;this.key=key;this.validity={};evLog("initializeFormCount");this.options=options=options||{};if(typeof options!=="object"){throw new Error("Expected options to be an object")}if(typeof options.numberIgnoreNonNumeric==="undefined"){options.numberIgnoreNonNumeric=true}options.generationtimeSkipValidation=(options.generationtimeSkipValidation===true);options.cvcSkipValidation=(options.cvcSkipValidation===true);if(typeof options.fieldNameAttribute!=="string"||!options.fieldNameAttribute.match(/^data(-\w+)+$/i)){options.fieldNameAttribute=DEFAULT_FIELDNAME_ATTRIBUTE}this.name=options.name||"adyen-encrypted-data";this.fieldNameAttribute=options.fieldNameAttribute||DEFAULT_FIELDNAME_ATTRIBUTE;this.onsubmit=options.onsubmit||function(){};this.encryption=new Encryption(key,options);if(this.element.addEventListener){this.element.addEventListener("submit",this.handleSubmit.bind(this),false)}else{if(this.element.attachEvent){this.element.attachEvent("onsubmit",this.handleSubmit.bind(this))}}if(options.enableValidations!==false){this.addValidations()}for(var i=0,c=element.elements.length;i=0;i--){field=fields[i];field.removeAttribute("name");key=field.getAttribute(this.fieldNameAttribute);value=field.value;if(field.options&&typeof field.selectedIndex!=="undefined"){value=field.options[field.selectedIndex].value}data[key]=value}return data},encrypt:function(){return this.encryption.encrypt(this.toJSON(this.getEncryptedFields(this.element)))},createEncryptedField:function(data){var element=document.getElementById(this.name);if(!element){element=document.createElement("input");element.type="hidden";element.name=element.id=this.name;this.element.appendChild(element)}element.setAttribute("value",data)},addValidations:function(){var cse=this,elements=this.element.elements,c=elements.length,element,handlers={},elementsByName={};for(;c-->0;){element=elements[c];if(!element||!element.getAttribute){continue}var fieldName=element.getAttribute(this.fieldNameAttribute);elementsByName[fieldName]=element;if(fieldName==="number"){handlers.luhnHandler=handlers.luhnHandler||validations.createChangeHandler(cse,"number",true);addEvent(element,"change",handlers.luhnHandler,false);addEvent(element,"keyup",handlers.luhnHandler,false);addEvent(element,"blur",handlers.luhnHandler,false);handlers.luhnHandler({target:element,isInitializing:true})}else{if(fieldName==="cvc"){handlers.cvcHandler=handlers.cvcHandler||validations.createChangeHandler(cse,"cvc",true);addEvent(element,"change",handlers.cvcHandler,false);addEvent(element,"keyup",handlers.cvcHandler,false);addEvent(element,"blur",handlers.cvcHandler,false);handlers.cvcHandler({target:element,isInitializing:true})}else{if(fieldName==="expiryYear"){handlers.expiryYearHandler=handlers.expiryYearHandler||validations.createChangeHandler(cse,"year",true);addEvent(element,"change",handlers.expiryYearHandler,false);addEvent(element,"keyup",handlers.expiryYearHandler,false);addEvent(element,"blur",handlers.expiryYearHandler,false);handlers.expiryYearHandler({target:element,isInitializing:true})}else{if(fieldName==="expiryMonth"){handlers.expiryMonthHandler=handlers.expiryMonthHandler||validations.createChangeHandler(cse,"month",true);addEvent(element,"change",handlers.expiryMonthHandler,false);addEvent(element,"keyup",handlers.expiryMonthHandler,false);addEvent(element,"blur",handlers.expiryMonthHandler,false);handlers.expiryMonthHandler({target:element,isInitializing:true})}else{if(fieldName==="holderName"){handlers.holderNameHandler=handlers.holderNameHandler||validations.createChangeHandler(cse,"holderName",false);addEvent(element,"change",handlers.holderNameHandler,false);addEvent(element,"keyup",handlers.holderNameHandler,false);addEvent(element,"blur",handlers.holderNameHandler,false);handlers.holderNameHandler({target:element,isInitializing:true})}}}}}}if(handlers.luhnHandler&&handlers.cvcHandler&&elementsByName.number&&elementsByName.cvc){handlers.luhnHandler.chain(function(ev){handlers.cvcHandler({target:elementsByName.cvc,originalEvent:ev,type:(ev||{}).type,isInitializing:(ev||{}).isInitializing})})}},addCardTypeDetection:function(cardTypeElement){if(typeof adyen.CardTypeDetection==="undefined"||typeof adyen.CardTypeDetection.getHandler!=="function"){return window.console&&window.console.warn("[CSE] Card type detection not available")}var updateCardTypeDetection=adyen.CardTypeDetection.getHandler(cardTypeElement);var cse=this,elements=this.element.elements,c=elements.length,element,handlers={};for(;c-->0;){element=elements[c];if(!element||!element.getAttribute){continue}else{if(element.getAttribute(this.fieldNameAttribute)==="number"){addEvent(element,"change",updateCardTypeDetection,false);addEvent(element,"input",updateCardTypeDetection,false);addEvent(element,"keyup",updateCardTypeDetection,false);updateCardTypeDetection({target:element})}}}},validate:function(){var fields=this.toJSON(this.getEncryptedFields(this.element));delete fields.generationtime;return this.encryption.validate(fields)||{valid:false}},isValid:function(){var valid=this.validate().valid;for(var i in this.validity){if(this.validity.hasOwnProperty(i)){valid=valid&&this.validity[i]}}return valid},toggleSubmit:function(){var valid=this.isValid(),elements=this.element.elements,enabled;enabled=valid===true||(this.options&&this.options.submitButtonAlwaysEnabled===true);for(var c=elements.length;c-->0;){if(elements[c]&&(elements[c].type||"").toLowerCase()==="submit"){elements[c].disabled=!enabled}}if(typeof this.options.onvalidate==="function"){try{this.options.onvalidate(this.validity)}catch(e){if(window.console&&window.console.warn&&window.console.log){console.warn("[CSE] Error in custom validationComplete handler");console.log("Caught error was ",e)}}}return valid},getVersion:function(){return encrypt.version}};var AESKey=function(){};AESKey.prototype={constructor:AESKey,key:function(){this._key=this._key||sjcl.random.randomWords(8,6);return this._key},encrypt:function(text){return this.encryptWithIv(text,sjcl.random.randomWords(3,6))},encryptWithIv:function(text,iv){var aes,bits,cipher,cipherIV;aes=new sjcl.cipher.aes(this.key());bits=sjcl.codec.utf8String.toBits(text);cipher=sjcl.mode.ccm.encrypt(aes,bits,iv);cipherIV=sjcl.bitArray.concat(iv,cipher);return sjcl.codec.base64.fromBits(cipherIV)}}})(this,typeof define==="function"?define:null); 18 | -------------------------------------------------------------------------------- /lib/0_1_25.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Client Encryption of Forms. 4 | * 5 | * Includes: 6 | * * RSA and ECC in JavaScript | http://www-cs-students.stanford.edu/~tjw/jsbn/ 7 | * * Stanford Javascript Crypto Library | http://crypto.stanford.edu/sjcl/ 8 | * * JSON in JavaScript | http://www.JSON.org/ 9 | * 10 | * Version: 0_1_25 11 | * Author: ADYEN (c) 2014 12 | */ 13 | var window = {};var navigator = {};var document = {};(function(root,fnDefine){var define,exports;(function(){try{var b=[new Uint8Array(1),new Uint32Array(1),new Int32Array(1)];return}catch(g){}function f(e,a){return this.slice(e,a)}function c(j,e){if(arguments.length<2){e=0}for(var a=0,h=j.length;a>2,c=((l&3)<<4)|(k>>4);var o=g+1>6):64;var m=g+2>6)+b64map.charAt(e&63)}if(b+1==d.length){e=parseInt(d.substring(b,b+1),16);a+=b64map.charAt(e<<2)}else{if(b+2==d.length){e=parseInt(d.substring(b,b+2),16);a+=b64map.charAt(e>>2)+b64map.charAt((e&3)<<4)}}while((a.length&3)>0){a+=b64padchar}return a}function b64tohex(e){var c="";var d;var a=0;var b;for(d=0;d>2);b=v&3;a=1}else{if(a==1){c+=int2char((b<<2)|(v>>4));b=v&15;a=2}else{if(a==2){c+=int2char(b);c+=int2char(v>>2);b=v&3;a=3}else{c+=int2char((b<<2)|(v>>4));c+=int2char(v&15);a=0}}}}if(a==1){c+=int2char(b<<2)}return c}function b64toBA(e){var d=b64tohex(e);var c;var b=new Array();for(c=0;2*c=0){var d=a*this[f++]+b[e]+h;h=Math.floor(d/67108864);b[e++]=d&67108863}return h}function am2(f,q,r,e,o,a){var k=q&32767,p=q>>15;while(--a>=0){var d=this[f]&32767;var g=this[f++]>>15;var b=p*d+g*k;d=k*d+((b&32767)<<15)+r[e]+(o&1073741823);o=(d>>>30)+(b>>>15)+p*g+(o>>>30);r[e++]=d&1073741823}return o}function am3(f,q,r,e,o,a){var k=q&16383,p=q>>14;while(--a>=0){var d=this[f]&16383;var g=this[f++]>>14;var b=p*d+g*k;d=k*d+((b&16383)<<14)+r[e]+o;o=(d>>28)+(b>>14)+p*g;r[e++]=d&268435455}return o}if(j_lm&&(navigator.appName=="Microsoft Internet Explorer")){BigInteger.prototype.am=am2;dbits=30}else{if(j_lm&&(navigator.appName!="Netscape")){BigInteger.prototype.am=am1;dbits=26}else{BigInteger.prototype.am=am3;dbits=28}}BigInteger.prototype.DB=dbits;BigInteger.prototype.DM=((1<=0;--a){b[a]=this[a]}b.t=this.t;b.s=this.s}function bnpFromInt(a){this.t=1;this.s=(a<0)?-1:0;if(a>0){this[0]=a}else{if(a<-1){this[0]=a+this.DV}else{this.t=0}}}function nbv(a){var b=nbi();b.fromInt(a);return b}function bnpFromString(h,c){var e;if(c==16){e=4}else{if(c==8){e=3}else{if(c==256){e=8}else{if(c==2){e=1}else{if(c==32){e=5}else{if(c==4){e=2}else{this.fromRadix(h,c);return}}}}}}this.t=0;this.s=0;var g=h.length,d=false,f=0;while(--g>=0){var a=(e==8)?h[g]&255:intAt(h,g);if(a<0){if(h.charAt(g)=="-"){d=true}continue}d=false;if(f==0){this[this.t++]=a}else{if(f+e>this.DB){this[this.t-1]|=(a&((1<<(this.DB-f))-1))<>(this.DB-f))}else{this[this.t-1]|=a<=this.DB){f-=this.DB}}if(e==8&&(h[0]&128)!=0){this.s=-1;if(f>0){this[this.t-1]|=((1<<(this.DB-f))-1)<0&&this[this.t-1]==a){--this.t}}function bnToString(c){if(this.s<0){return"-"+this.negate().toString(c)}var e;if(c==16){e=4}else{if(c==8){e=3}else{if(c==2){e=1}else{if(c==32){e=5}else{if(c==4){e=2}else{return this.toRadix(c)}}}}}var g=(1<0){if(j>j)>0){a=true;h=int2char(l)}while(f>=0){if(j>(j+=this.DB-e)}else{l=(this[f]>>(j-=e))&g;if(j<=0){j+=this.DB;--f}}if(l>0){a=true}if(a){h+=int2char(l)}}}return a?h:"0"}function bnNegate(){var a=nbi();BigInteger.ZERO.subTo(this,a);return a}function bnAbs(){return(this.s<0)?this.negate():this}function bnCompareTo(b){var d=this.s-b.s;if(d!=0){return d}var c=this.t;d=c-b.t;if(d!=0){return(this.s<0)?-d:d}while(--c>=0){if((d=this[c]-b[c])!=0){return d}}return 0}function nbits(a){var c=1,b;if((b=a>>>16)!=0){a=b;c+=16}if((b=a>>8)!=0){a=b;c+=8}if((b=a>>4)!=0){a=b;c+=4}if((b=a>>2)!=0){a=b;c+=2}if((b=a>>1)!=0){a=b;c+=1}return c}function bnBitLength(){if(this.t<=0){return 0}return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM))}function bnpDLShiftTo(c,b){var a;for(a=this.t-1;a>=0;--a){b[a+c]=this[a]}for(a=c-1;a>=0;--a){b[a]=0}b.t=this.t+c;b.s=this.s}function bnpDRShiftTo(c,b){for(var a=c;a=0;--d){e[d+f+1]=(this[d]>>a)|h;h=(this[d]&g)<=0;--d){e[d]=0}e[f]=h;e.t=this.t+f+1;e.s=this.s;e.clamp()}function bnpRShiftTo(g,d){d.s=this.s;var e=Math.floor(g/this.DB);if(e>=this.t){d.t=0;return}var b=g%this.DB;var a=this.DB-b;var f=(1<>b;for(var c=e+1;c>b}if(b>0){d[this.t-e-1]|=(this.s&f)<>=this.DB}if(d.t>=this.DB}g+=this.s}else{g+=this.s;while(e>=this.DB}g-=d.s}f.s=(g<0)?-1:0;if(g<-1){f[e++]=this.DV+g}else{if(g>0){f[e++]=g}}f.t=e;f.clamp()}function bnpMultiplyTo(c,e){var b=this.abs(),f=c.abs();var d=b.t;e.t=d+f.t;while(--d>=0){e[d]=0}for(d=0;d=0){d[b]=0}for(b=0;b=a.DV){d[b+a.t]-=a.DV;d[b+a.t+1]=1}}if(d.t>0){d[d.t-1]+=a.am(b,a[b],d,2*b,0,1)}d.s=0;d.clamp()}function bnpDivRemTo(n,h,g){var w=n.abs();if(w.t<=0){return}var k=this.abs();if(k.t0){w.lShiftTo(v,d);k.lShiftTo(v,g)}else{w.copyTo(d);k.copyTo(g)}var p=d.t;var b=d[p-1];if(b==0){return}var o=b*(1<1)?d[p-2]>>this.F2:0);var A=this.FV/o,z=(1<=0){g[g.t++]=1;g.subTo(f,g)}BigInteger.ONE.dlShiftTo(p,f);f.subTo(d,d);while(d.t=0){var c=(g[--u]==b)?this.DM:Math.floor(g[u]*A+(g[u-1]+x)*z);if((g[u]+=d.am(0,c,g,s,0,p))0){g.rShiftTo(v,g)}if(a<0){BigInteger.ZERO.subTo(g,g)}}function bnMod(b){var c=nbi();this.abs().divRemTo(b,null,c);if(this.s<0&&c.compareTo(BigInteger.ZERO)>0){b.subTo(c,c)}return c}function Classic(a){this.m=a}function cConvert(a){if(a.s<0||a.compareTo(this.m)>=0){return a.mod(this.m)}else{return a}}function cRevert(a){return a}function cReduce(a){a.divRemTo(this.m,null,a)}function cMulTo(a,c,b){a.multiplyTo(c,b);this.reduce(b)}function cSqrTo(a,b){a.squareTo(b);this.reduce(b)}Classic.prototype.convert=cConvert;Classic.prototype.revert=cRevert;Classic.prototype.reduce=cReduce;Classic.prototype.mulTo=cMulTo;Classic.prototype.sqrTo=cSqrTo;function bnpInvDigit(){if(this.t<1){return 0}var a=this[0];if((a&1)==0){return 0}var b=a&3;b=(b*(2-(a&15)*b))&15;b=(b*(2-(a&255)*b))&255;b=(b*(2-(((a&65535)*b)&65535)))&65535;b=(b*(2-a*b%this.DV))%this.DV;return(b>0)?this.DV-b:-b}function Montgomery(a){this.m=a;this.mp=a.invDigit();this.mpl=this.mp&32767;this.mph=this.mp>>15;this.um=(1<<(a.DB-15))-1;this.mt2=2*a.t}function montConvert(a){var b=nbi();a.abs().dlShiftTo(this.m.t,b);b.divRemTo(this.m,null,b);if(a.s<0&&b.compareTo(BigInteger.ZERO)>0){this.m.subTo(b,b)}return b}function montRevert(a){var b=nbi();a.copyTo(b);this.reduce(b);return b}function montReduce(a){while(a.t<=this.mt2){a[a.t++]=0}for(var c=0;c>15)*this.mpl)&this.um)<<15))&a.DM;b=c+this.m.t;a[b]+=this.m.am(0,d,a,c,0,this.m.t);while(a[b]>=a.DV){a[b]-=a.DV;a[++b]++}}a.clamp();a.drShiftTo(this.m.t,a);if(a.compareTo(this.m)>=0){a.subTo(this.m,a)}}function montSqrTo(a,b){a.squareTo(b);this.reduce(b)}function montMulTo(a,c,b){a.multiplyTo(c,b);this.reduce(b)}Montgomery.prototype.convert=montConvert;Montgomery.prototype.revert=montRevert;Montgomery.prototype.reduce=montReduce;Montgomery.prototype.mulTo=montMulTo;Montgomery.prototype.sqrTo=montSqrTo;function bnpIsEven(){return((this.t>0)?(this[0]&1):this.s)==0}function bnpExp(h,j){if(h>4294967295||h<1){return BigInteger.ONE}var f=nbi(),a=nbi(),d=j.convert(this),c=nbits(h)-1;d.copyTo(f);while(--c>=0){j.sqrTo(f,a);if((h&(1<0){j.mulTo(a,d,f)}else{var b=f;f=a;a=b}}return j.revert(f)}function bnModPowInt(b,a){var c;if(b<256||a.isEven()){c=new Classic(a)}else{c=new Montgomery(a)}return this.exp(b,c)}BigInteger.prototype.copyTo=bnpCopyTo;BigInteger.prototype.fromInt=bnpFromInt;BigInteger.prototype.fromString=bnpFromString;BigInteger.prototype.clamp=bnpClamp;BigInteger.prototype.dlShiftTo=bnpDLShiftTo;BigInteger.prototype.drShiftTo=bnpDRShiftTo;BigInteger.prototype.lShiftTo=bnpLShiftTo;BigInteger.prototype.rShiftTo=bnpRShiftTo;BigInteger.prototype.subTo=bnpSubTo;BigInteger.prototype.multiplyTo=bnpMultiplyTo;BigInteger.prototype.squareTo=bnpSquareTo;BigInteger.prototype.divRemTo=bnpDivRemTo;BigInteger.prototype.invDigit=bnpInvDigit;BigInteger.prototype.isEven=bnpIsEven;BigInteger.prototype.exp=bnpExp;BigInteger.prototype.toString=bnToString;BigInteger.prototype.negate=bnNegate;BigInteger.prototype.abs=bnAbs;BigInteger.prototype.compareTo=bnCompareTo;BigInteger.prototype.bitLength=bnBitLength;BigInteger.prototype.mod=bnMod;BigInteger.prototype.modPowInt=bnModPowInt;BigInteger.ZERO=nbv(0);BigInteger.ONE=nbv(1);function Arcfour(){this.i=0;this.j=0;this.S=new Array}function ARC4init(c){var a,d,b;for(a=0;a<256;++a){this.S[a]=a}d=0;for(a=0;a<256;++a){d=d+this.S[a]+c[a%c.length]&255;b=this.S[a];this.S[a]=this.S[d];this.S[d]=b}this.i=0;this.j=0}function ARC4next(){var a;this.i=this.i+1&255;this.j=this.j+this.S[this.i]&255;a=this.S[this.i];this.S[this.i]=this.S[this.j];this.S[this.j]=a;return this.S[a+this.S[this.i]&255]}function prng_newstate(){return new Arcfour}Arcfour.prototype.init=ARC4init;Arcfour.prototype.next=ARC4next;var rng_psize=256;var rng_state;var rng_pool;var rng_pptr;function rng_seed_int(a){rng_pool[rng_pptr++]^=a&255;rng_pool[rng_pptr++]^=(a>>8)&255;rng_pool[rng_pptr++]^=(a>>16)&255;rng_pool[rng_pptr++]^=(a>>24)&255;if(rng_pptr>=rng_psize){rng_pptr-=rng_psize}}function rng_seed_time(){rng_seed_int(new Date().getTime())}if(rng_pool==null){rng_pool=[];rng_pptr=0;var t;try{if(window.crypto&&window.crypto.getRandomValues){var ua=new Uint8Array(32);window.crypto.getRandomValues(ua);for(t=0;t<32;++t){rng_pool[rng_pptr++]=ua[t]}}else{if(window.msCrypto&&window.msCrypto.getRandomValues){var ua=new Uint8Array(32);window.msCrypto.getRandomValues(ua);for(t=0;t<32;++t){rng_pool[rng_pptr++]=ua[t]}}else{if(window.crypto&&window.crypto.random){var z=window.crypto.random(32);for(t=0;t>>8;rng_pool[rng_pptr++]=t&255}rng_pptr=0;rng_seed_time()}function rng_get_byte(){if(rng_state==null){rng_seed_time();rng_state=prng_newstate();rng_state.init(rng_pool);for(rng_pptr=0;rng_pptr=0&&g>0){f[--g]=c[e--]}f[--g]=0;var d=new SecureRandom();var a=new Array();while(g>2){a[0]=0;while(a[0]==0){d.nextBytes(a)}f[--g]=a[0]}f[--g]=2;f[--g]=0;return new BigInteger(f)}function RSAKey(){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 RSASetPublic(b,a){if(b!=null&&a!=null&&b.length>0&&a.length>0){this.n=parseBigInt(b,16);this.e=parseInt(a,16)}else{alert("Invalid RSA public key")}}function RSADoPublic(a){return a.modPowInt(this.e,this.n)}function RSAEncrypt(b){var a=pkcs1pad2(b,(this.n.bitLength()+7)>>3);if(a==null){return null}var e=this.doPublic(a);if(e==null){return null}var d=e.toString(16);if((d.length&1)==0){return d}else{return"0"+d}}function RSAEncryptB64(a){var b=this.encrypt(a);if(b){return hex2b64(b)}else{return null}}RSAKey.prototype.doPublic=RSADoPublic;RSAKey.prototype.setPublic=RSASetPublic;RSAKey.prototype.encrypt=RSAEncrypt;RSAKey.prototype.encrypt_b64=RSAEncryptB64;"use strict";function q(b){throw b}var t=void 0,u=!1;var sjcl={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(b){this.toString=function(){return"CORRUPT: "+this.message};this.message=b},invalid:function(b){this.toString=function(){return"INVALID: "+this.message};this.message=b},bug:function(b){this.toString=function(){return"BUG: "+this.message};this.message=b},notReady:function(b){this.toString=function(){return"NOT READY: "+this.message};this.message=b}}};"undefined"!==typeof module&&module.exports&&(module.exports=sjcl);"function"===typeof define&&define([],function(){return sjcl});sjcl.cipher.aes=function(j){this.k[0][0][0]||this.D();var i,p,o,n,m=this.k[0][4],l=this.k[1];i=j.length;var k=1;4!==i&&(6!==i&&8!==i)&&q(new sjcl.exception.invalid("invalid aes key size"));this.b=[o=j.slice(0),n=[]];for(j=i;j<4*i+28;j++){p=o[j-1];if(0===j%i||8===i&&4===j%i){p=m[p>>>24]<<24^m[p>>16&255]<<16^m[p>>8&255]<<8^m[p&255],0===j%i&&(p=p<<8^p>>>24^k<<24,k=k<<1^283*(k>>7))}o[j]=o[j-i]^p}for(i=0;j;i++,j--){p=o[i&3?j:j-4],n[i]=4>=j||4>i?p:l[0][m[p>>>24]]^l[1][m[p>>16&255]]^l[2][m[p>>8&255]]^l[3][m[p&255]]}};sjcl.cipher.aes.prototype={encrypt:function(b){return y(this,b,0)},decrypt:function(b){return y(this,b,1)},k:[[[],[],[],[],[]],[[],[],[],[],[]]],D:function(){var R=this.k[0],Q=this.k[1],P=R[4],O=Q[4],N,x,w,v=[],r=[],s,j,o,i;for(N=0;256>N;N++){r[(v[N]=N<<1^283*(N>>7))^N]=N}for(x=w=0;!P[x];x^=s||1,w=r[w]||1){o=w^w<<1^w<<2^w<<3^w<<4;o=o>>8^o&255^99;P[x]=o;O[o]=x;j=v[N=v[s=v[x]]];i=16843009*j^65537*N^257*s^16843008*x;j=257*v[o]^16843008*o;for(N=0;4>N;N++){R[N][x]=j=j<<24^j>>>8,Q[N][o]=i=i<<24^i>>>8}}for(N=0;5>N;N++){R[N]=R[N].slice(0),Q[N]=Q[N].slice(0)}}};function y(ab,aa,Z){4!==aa.length&&q(new sjcl.exception.invalid("invalid aes block size"));var Y=ab.b[Z],X=aa[0]^Y[0],W=aa[Z?3:1]^Y[1],V=aa[2]^Y[2];aa=aa[Z?1:3]^Y[3];var U,S,T,Q=Y.length/4-2,R,P=4,N=[0,0,0,0];U=ab.k[Z];ab=U[0];var O=U[1],o=U[2],j=U[3],i=U[4];for(R=0;R>>24]^O[W>>16&255]^o[V>>8&255]^j[aa&255]^Y[P],S=ab[W>>>24]^O[V>>16&255]^o[aa>>8&255]^j[X&255]^Y[P+1],T=ab[V>>>24]^O[aa>>16&255]^o[X>>8&255]^j[W&255]^Y[P+2],aa=ab[aa>>>24]^O[X>>16&255]^o[W>>8&255]^j[V&255]^Y[P+3],P+=4,X=U,W=S,V=T}for(R=0;4>R;R++){N[Z?3&-R:R]=i[X>>>24]<<24^i[W>>16&255]<<16^i[V>>8&255]<<8^i[aa&255]^Y[P++],U=X,X=W,W=V,V=aa,aa=U}return N}sjcl.bitArray={bitSlice:function(e,d,f){e=sjcl.bitArray.P(e.slice(d/32),32-(d&31)).slice(1);return f===t?e:sjcl.bitArray.clamp(e,f-d)},extract:function(f,e,h){var g=Math.floor(-e-h&31);return((e+h-1^e)&-32?f[e/32|0]<<32-g^f[e/32+1|0]>>>g:f[e/32|0]>>>g)&(1<>d-1,1));return e},partial:function(e,d,f){return 32===e?d:(f?d|0:d<<32-e)+1099511627776*e},getPartial:function(b){return Math.round(b/1099511627776)||32},equal:function(f,e){if(sjcl.bitArray.bitLength(f)!==sjcl.bitArray.bitLength(e)){return u}var h=0,g;for(g=0;g>>f),j=g[h]<<32-f}h=g.length?g[g.length-1]:0;g=sjcl.bitArray.getPartial(h);i.push(sjcl.bitArray.partial(f+g&31,32>>24|f>>>8&65280|(f&65280)<<8|f<<24}return e}};sjcl.codec.utf8String={fromBits:function(g){var f="",j=sjcl.bitArray.bitLength(g),i,h;for(i=0;i>>24),h<<=8}return decodeURIComponent(escape(f))},toBits:function(f){f=unescape(encodeURIComponent(f));var e=[],h,g=0;for(h=0;h>>n)>>>26),6>n?(l=j[p]<<6-n,n+=26,p++):(l<<=6,n-=6)}for(;o.length&3&&!i;){o+="="}return o},toBits:function(j,i){j=j.replace(/\s|=/g,"");var p=[],o,n=0,m=sjcl.codec.base64.J,l=0,k;i&&(m=m.substr(0,62)+"-_");for(o=0;ok&&q(new sjcl.exception.invalid("this isn't base64!")),26>>n),l=k<<32-n):(n+=6,l^=k<<32-n)}n&56&&p.push(sjcl.bitArray.partial(n&56,l,1));return p}};sjcl.codec.base64url={fromBits:function(b){return sjcl.codec.base64.fromBits(b,1,1)},toBits:function(b){return sjcl.codec.base64.toBits(b,1)}};sjcl.hash.sha256=function(b){this.b[0]||this.D();b?(this.r=b.r.slice(0),this.o=b.o.slice(0),this.h=b.h):this.reset()};sjcl.hash.sha256.hash=function(b){return(new sjcl.hash.sha256).update(b).finalize()};sjcl.hash.sha256.prototype={blockSize:512,reset:function(){this.r=this.N.slice(0);this.o=[];this.h=0;return this},update:function(e){"string"===typeof e&&(e=sjcl.codec.utf8String.toBits(e));var d,f=this.o=sjcl.bitArray.concat(this.o,e);d=this.h;e=this.h=d+sjcl.bitArray.bitLength(e);for(d=512+d&-512;d<=e;d+=512){z(this,f.splice(0,16))}return this},finalize:function(){var e,d=this.o,f=this.r,d=sjcl.bitArray.concat(d,[sjcl.bitArray.partial(1,1)]);for(e=d.length+2;e&15;e++){d.push(0)}d.push(Math.floor(this.h/4294967296));for(d.push(this.h|0); 14 | d.length;){z(this,d.splice(0,16))}this.reset();return f},N:[],b:[],D:function(){function f(b){return 4294967296*(b-Math.floor(b))|0}var e=0,h=2,g;f:for(;64>e;h++){for(g=2;g*g<=h;g++){if(0===h%g){continue f}}8>e&&(this.N[e]=f(Math.pow(h,0.5)));this.b[e]=f(Math.pow(h,1/3));e++}}};function z(V,U){var T,S,R,Q=U.slice(0),P=V.r,O=V.b,x=P[0],N=P[1],o=P[2],w=P[3],j=P[4],X=P[5],i=P[6],W=P[7];for(T=0;64>T;T++){16>T?S=Q[T]:(S=Q[T+1&15],R=Q[T+14&15],S=Q[T&15]=(S>>>7^S>>>18^S>>>3^S<<25^S<<14)+(R>>>17^R>>>19^R>>>10^R<<15^R<<13)+Q[T&15]+Q[T+9&15]|0),S=S+W+(j>>>6^j>>>11^j>>>25^j<<26^j<<21^j<<7)+(i^j&(X^i))+O[T],W=i,i=X,X=j,j=w+S|0,w=o,o=N,N=x,x=S+(N&o^w&(N^o))+(N>>>2^N>>>13^N>>>22^N<<30^N<<19^N<<10)|0}P[0]=P[0]+x|0;P[1]=P[1]+N|0;P[2]=P[2]+o|0;P[3]=P[3]+w|0;P[4]=P[4]+j|0;P[5]=P[5]+X|0;P[6]=P[6]+i|0;P[7]=P[7]+W|0}sjcl.mode.ccm={name:"ccm",encrypt:function(w,v,s,r,p){var o,n=v.slice(0),m=sjcl.bitArray,i=m.bitLength(s)/8,j=m.bitLength(n)/8;p=p||64;r=r||[];7>i&&q(new sjcl.exception.invalid("ccm: iv must be at least 7 bytes"));for(o=2;4>o&&j>>>8*o;o++){}o<15-i&&(o=15-i);s=m.clamp(s,8*(15-o));v=sjcl.mode.ccm.L(w,v,s,r,p,o);n=sjcl.mode.ccm.p(w,n,s,v,p,o);return m.concat(n.data,n.tag)},decrypt:function(w,v,s,r,p){p=p||64;r=r||[];var o=sjcl.bitArray,n=o.bitLength(s)/8,m=o.bitLength(v),i=o.clamp(v,m-p),j=o.bitSlice(v,m-p),m=(m-p)/8;7>n&&q(new sjcl.exception.invalid("ccm: iv must be at least 7 bytes"));for(v=2;4>v&&m>>>8*v;v++){}v<15-n&&(v=15-n);s=o.clamp(s,8*(15-v));i=sjcl.mode.ccm.p(w,i,s,j,p,v);w=sjcl.mode.ccm.L(w,i.data,s,r,p,v);o.equal(i.tag,w)||q(new sjcl.exception.corrupt("ccm: tag doesn't match"));return i.data},L:function(s,r,p,o,n,m){var k=[],j=sjcl.bitArray,i=j.l;n/=8;(n%2||4>n||16=p?k=[j.partial(16,p)]:4294967295>=p&&(k=j.concat([j.partial(16,65534)],[p]));k=j.concat(k,o);for(o=0;on.bitLength(p)&&(k=m(k,o(k)),p=n.concat(p,[-2147483648,0,0,0]));l=m(l,p);return j.encrypt(m(o(m(k,o(k))),l))},H:function(b){return[b[0]<<1^b[1]>>>31,b[1]<<1^b[2]>>>31,b[2]<<1^b[3]>>>31,b[3]<<1^135*(b[0]>>>31)]}};sjcl.mode.gcm={name:"gcm",encrypt:function(h,g,l,k,j){var i=g.slice(0);g=sjcl.bitArray;k=k||[];h=sjcl.mode.gcm.p(!0,h,i,k,l,j||128);return g.concat(h.data,h.tag)},decrypt:function(j,i,p,o,n){var m=i.slice(0),l=sjcl.bitArray,k=l.bitLength(m);n=n||128;o=o||[];n<=k?(i=l.bitSlice(m,k-n),m=l.bitSlice(m,0,k-n)):(i=m,m=[]);j=sjcl.mode.gcm.p(u,j,m,o,p,n);l.equal(j.tag,i)||q(new sjcl.exception.corrupt("gcm: tag doesn't match"));return j.data},Z:function(j,i){var p,o,n,m,l,k=sjcl.bitArray.l;n=[0,0,0,0];m=i.slice(0);for(p=0;128>p;p++){(o=0!==(j[Math.floor(p/32)]&1<<31-p%32))&&(n=k(n,m));l=0!==(m[3]&1);for(o=3;0>>1|(m[o-1]&1)<<31}m[0]>>>=1;l&&(m[0]^=-520093696)}return n},g:function(g,f,j){var i,h=j.length;f=f.slice(0);for(i=0;ih&&(g=f.hash(g));for(i=0;iv||0>w)&&q(sjcl.exception.invalid("invalid params to pbkdf2"));"string"===typeof N&&(N=sjcl.codec.utf8String.toBits(N));"string"===typeof x&&(x=sjcl.codec.utf8String.toBits(x));s=s||sjcl.misc.hmac;N=new s(N);var r,p,o,j,m=[],i=sjcl.bitArray;for(j=1;32*m.length<(v||1);j++){s=r=N.encrypt(i.concat(x,[j]));for(p=1;pj;j++){l.push(4294967296*Math.random()|0)}for(j=0;j=1<this.j&&(this.j=k);this.F++;this.b=sjcl.hash.sha256.hash(this.b.concat(l));this.A=new sjcl.cipher.aes(this.b);for(m=0;4>m&&!(this.f[m]=this.f[m]+1|0,this.f[m]);m++){}}for(m=0;m>>=1}}}this.c[k].update([o,this.C++,2,r,m,s.length].concat(s))}break;case"string":r===t&&(r=s.length);this.c[k].update([o,this.C++,3,r,m,s.length]);this.c[k].update(s);break;default:i=1}i&&q(new sjcl.exception.bug("random: addEntropy only supports number, array of numbers or string"));this.i[k]+=r;this.d+=r;j===this.m&&(this.isReady()!==this.m&&C("seeded",Math.max(this.j,this.d)),C("progress",this.getProgress()))},isReady:function(b){b=this.I[b!==t?b:this.B];return this.j&&this.j>=b?this.i[0]>this.R&&(new Date).valueOf()>this.O?this.u|this.t:this.t:this.d>=b?this.u|this.m:this.m},getProgress:function(b){b=this.I[b?b:this.B];return this.j>=b?1:this.d>b?1:this.d/b},startCollectors:function(){this.q||(this.a={loadTimeCollector:D(this,this.aa),mouseCollector:D(this,this.ba),keyboardCollector:D(this,this.$),accelerometerCollector:D(this,this.U)},window.addEventListener?(window.addEventListener("load",this.a.loadTimeCollector,u),window.addEventListener("mousemove",this.a.mouseCollector,u),window.addEventListener("keypress",this.a.keyboardCollector,u),window.addEventListener("devicemotion",this.a.accelerometerCollector,u)):document.attachEvent?(document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector)):q(new sjcl.exception.bug("can't attach event")),this.q=!0)},stopCollectors:function(){this.q&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,u),window.removeEventListener("mousemove",this.a.mouseCollector,u),window.removeEventListener("keypress",this.a.keyboardCollector,u),window.removeEventListener("devicemotion",this.a.accelerometerCollector,u)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.q=u)},addEventListener:function(d,c){this.w[d][this.V++]=c},removeEventListener:function(h,g){var l,k,j=this.w[h],i=[];for(k in j){j.hasOwnProperty(k)&&j[k]===g&&i.push(k)}for(l=0;lc&&!(d.f[c]=d.f[c]+1|0,d.f[c]);c++){}return d.A.encrypt(d.f)}function D(d,c){return function(){c.apply(d,arguments)}}sjcl.random=new sjcl.prng(6);a:try{var F,G,H,I;if(I="undefined"!==typeof module){var J;if(J=module.exports){var K;try{K=require("crypto")}catch(L){K=null}J=(G=K)&&G.randomBytes}I=J}if(I){F=G.randomBytes(128),F=new Uint32Array((new Uint8Array(F)).buffer),sjcl.random.addEntropy(F,1024,"crypto['randomBytes']")}else{if("undefined"!==typeof window&&"undefined"!==typeof Uint32Array){H=new Uint32Array(32);if(window.crypto&&window.crypto.getRandomValues){window.crypto.getRandomValues(H)}else{if(window.msCrypto&&window.msCrypto.getRandomValues){window.msCrypto.getRandomValues(H)}else{break a}}sjcl.random.addEntropy(H,1024,"crypto['getRandomValues']")}}}catch(M){"undefined"!==typeof window&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(M))}sjcl.json={defaults:{v:1,iter:1000,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},Y:function(i,h,n,m){n=n||{};m=m||{};var l=sjcl.json,k=l.e({iv:sjcl.random.randomWords(4,0)},l.defaults),j;l.e(k,n);n=k.adata;"string"===typeof k.salt&&(k.salt=sjcl.codec.base64.toBits(k.salt));"string"===typeof k.iv&&(k.iv=sjcl.codec.base64.toBits(k.iv));(!sjcl.mode[k.mode]||!sjcl.cipher[k.cipher]||"string"===typeof i&&100>=k.iter||64!==k.ts&&96!==k.ts&&128!==k.ts||128!==k.ks&&192!==k.ks&&256!==k.ks||2>k.iv.length||4=h.iter||64!==h.ts&&96!==h.ts&&128!==h.ts||128!==h.ks&&192!==h.ks&&256!==h.ks||!h.iv||2>h.iv.length||4>>24);e<<=8}return d};b.toBits=b.toBits||function(c){var d=[],f,e=0;for(f=0;f=48&&i.keyCode<=57||i.keyCode>=96&&i.keyCode<=105){evLog("log",e,"KN")}else{if(i.keyCode>=65&&i.keyCode<=90){evLog("log",e,"KL")}else{evLog("log",e,"KU");evLog("log",e+"UnkKeys",i.keyCode)}}break}},true);return}if(j==="set"){d[h]=e;return}if(j==="log"){var k=h+"FieldLog";var f=(new Date().getTime())-a;f=Math.round(f/100);if(!d.hasOwnProperty(k)){d[k]=e+"@"+f}else{d[k]+=","+e+"@"+f}if(d[k].length>1500){d[k]=d[k].substring(d[k].length-1500);d[k]=d[k].substring(d[k].indexOf(",")+1)}return}if(j==="extend"){for(var g in d){if(g==="number"||g==="expiryMonth"||g==="expiryYear"||g==="generationtime"||g==="holderName"||g==="cvc"){continue}if(d.hasOwnProperty(g)){h[g]=""+d[g]}}return}if(!d.hasOwnProperty(j)){d[j]=1}else{d[j]++}}})();function b(j){var p=function(){return{}};if(window.jQuery&&typeof window.jQuery._data=="function"){p=function(o){return window.jQuery._data(o,"events")}}var n=j,d=0,q=[],u=["onmousedown","onmouseup","onmouseover","onmouseout","onclick","onmousemove","ondblclick","onerror","onresize","onscroll","onkeydown","onkeyup","onkeypress","onchange","onsubmit"],k="Own",s="Par",t=u.length;var i=0;while(n&&n!==n.documentElement){i++;var m=t,g,l,h=(n.nodeName||n.tagName||"").toUpperCase().substring(0,3);while(m--){g=u[m];if(n[name]){g=g+((n===j)?k:s)+h;d++;q[g]=q[g]||0;q[g]++}}var r=p(n);if(typeof r==="object"){for(var g in r){if(r.hasOwnProperty(g)){l=r[g].length;g=g+((n===j)?k:s)+h;q[g]=q[g]||0;q[g]+=l;d+=l}}}if(!n.parentNode){break}n=n.parentNode}var e=["total="+d];for(var f in q){if(q.hasOwnProperty(f)&&q[f]>0){e.push(f+"="+q[f])}}return e.join("&")}if(window&&(window.attachEvent||window.addEventListener)){c(window,"focus",function(){evLog("activate");if(window.location&&typeof window.location.href=="string"){evLog("set","referrer",window.location.href)}});c(window,"blur",function(){evLog("deactivate")})}}());var adyen=root.adyen=root.adyen||{};var encrypt=adyen.encrypt=adyen.encrypt||{createEncryptedForm:function(form,key,options){return new EncryptedForm(form,key,options)},createEncryption:function(key,options){return new Encryption(key,options)}};if(typeof fnDefine==="function"&&fnDefine.amd){fnDefine("adyen/encrypt",[],function(){return encrypt})}else{if(typeof module!=="undefined"&&module.exports){module.exports=encrypt}}encrypt.errors=encrypt.errors||{};encrypt.errors.UNABLETOBIND="CSEB01";function addEvent(element,event,callback,capture){if(typeof element.addEventListener==="function"){element.addEventListener(event,callback,capture)}else{if(element.attachEvent){element.attachEvent("on"+event,callback)}else{throw new Error(encrypt.errors.UNABLETOBIND+": Unable to bind "+event+"-event")}}}function hasClass(elem,className){return elem&&new RegExp(" "+className+" ").test(" "+(elem.className||"")+" ")}function addClass(elem,className){if(!elem){return}if(!hasClass(elem,className)){elem.className+=" "+className}}function removeClass(elem,className){if(!elem){return}var newClass=" "+elem.className.replace(/[\t\r\n]/g," ")+" ";if(hasClass(elem,className)){while(newClass.indexOf(" "+className+" ")>=0){newClass=newClass.replace(" "+className+" "," ")}elem.className=newClass.replace(/^\s+|\s+$/g,"")}}function getAttribute(node,attribute,defaultValue){if(node&&node.getAttribute){return node.getAttribute(attribute)||defaultValue}else{return defaultValue}}encrypt.version="0_1_25";if(!Date.prototype.toISOString){(function(){function pad(number){if(number<10){return"0"+number}return number}Date.prototype.toISOString=function(){return this.getUTCFullYear()+"-"+pad(this.getUTCMonth()+1)+"-"+pad(this.getUTCDate())+"T"+pad(this.getUTCHours())+":"+pad(this.getUTCMinutes())+":"+pad(this.getUTCSeconds())+"."+(this.getUTCMilliseconds()/1000).toFixed(3).slice(2,5)+"Z"}}())}var validations={};validations.luhnCheck=(function(){var luhnCache={};return function(){var argv=arguments;var argc=arguments.length;var CardNumber=argc>0?argv[0]:this.cardnumber;if(isNaN(parseInt(CardNumber,10))){return false}var no_digit=CardNumber.length;var oddoeven=no_digit&1;var sum=0;if(typeof luhnCache[CardNumber]==="undefined"){if(no_digit>=14){evLog("luhnCount")}for(var count=0;count9){digit-=9}}sum+=digit}if(sum%10===0){evLog("luhnOkCount");luhnCache[CardNumber]=true}else{evLog("luhnFailCount");luhnCache[CardNumber]=false}}var luhnCacheTries=0;for(var i in luhnCache){if(luhnCache.hasOwnProperty(i)&&i.length===no_digit){luhnCacheTries++}}evLog("set","luhnSameLengthCount",luhnCacheTries);return luhnCache[CardNumber]}})();validations.numberCheck=function(val){return((val||"").replace(/[^\d]/g,"").match(/^\d{10,20}$/)&&validations.luhnCheck(val))?true:false};validations.cvcCheck=function(val){return(val&&val.match&&val.match(/^\d{3,4}$/))?true:false};validations.yearCheck=function(val){if(!val||!val.match||!val.match(/^2\d{3}$/)){return false}var year=parseInt(val,10),currentYear=(new Date()).getFullYear();return year>=currentYear-2&&year<=currentYear+15};validations.monthCheck=function(val){var myVal=(val||"").replace(/^0(\d)$/,"$1");return(myVal.match(/^([1-9]|10|11|12)$/)&&parseInt(myVal,10)>=1&&parseInt(myVal,10)<=12)?true:false};validations.holderNameCheck=function(val){return(val&&val.match&&val.match(/\S/))?true:false};validations.generationTimeValidDate=function(val){if(typeof val!=="string"){return false}var m=val.match(/^(\d{4})-?(\d{2})-?(\d{2})$/); 15 | return(m&&(""+m[1]).match(/^20[1-9][0-9]$/)&&(""+m[2]).match(/^(12|11|10|0[1-9])$/)&&(""+m[3]).match(/^(31|30|20|10|[012][1-9])$/))?true:false};validations.generationTimeValidTime=function(val){if(typeof val!=="string"){return false}var reZone=/(Z|[\+\-][012345][0-9]:?[012345][0-9])$/;var withoutZoneAndMs=val.replace(reZone,"").replace(/\.\d+$/,"");return withoutZoneAndMs.match(/^[012345][0-9]:?[012345][0-9]:?[012345][0-9]$/)};validations.generationTimeCheck=function(val){if(typeof val!=="string"){return false}var parts=val.split("T");return(parts.length===2&&validations.generationTimeValidDate(parts[0])&&validations.generationTimeValidTime(parts[1]))?true:false};var Encryption=function(key,options){try{if(options.randomBytes){sjcl.random.addEntropy(options.randomBytes,1024,"crypto.randomBytes")}sjcl.random.startCollectors()}catch(e){}this.key=key;this.options=options||{};if(typeof this.options.numberIgnoreNonNumeric==="undefined"){this.options.numberIgnoreNonNumeric=true}if(typeof this.options.cvcIgnoreFornumber!=="undefined"){delete this.options.cvcIgnoreFornumber}if(typeof this.options.fourDigitCvcForBins==="undefined"){this.options.fourDigitCvcForBins="34,37"}if(typeof this.options.cvcLengthFornumber!=="undefined"){delete this.options.cvcLengthFornumber}if(typeof this.options.cvcIgnoreBins==="string"){var binsToIgnore=[];this.options.cvcIgnoreBins.replace(/\d+/g,function(m){if(m.length>0&&!isNaN(parseInt(m,10))){binsToIgnore.push(m)}return m});if(binsToIgnore.length>0){this.options.cvcIgnoreFornumber=new RegExp("^\\s*("+binsToIgnore.join("|")+")")}}else{if(typeof this.options.cvcIgnoreBins!=="undefined"){delete this.options.cvcIgnoreBins}}if(typeof this.options.fourDigitCvcForBins==="string"){var cvcGroups=[];this.options.fourDigitCvcForBins.replace(/\d+/g,function(m){if(m.length>0&&!isNaN(parseInt(m,10))){cvcGroups.push(m)}return m});if(cvcGroups.length>0){this.options.cvcLengthFornumber={matcher:new RegExp("^\\s*("+cvcGroups.join("|")+")"),requiredLength:4}}}delete this.options.fourDigitCvcForBins;evLog("initializeCount")};Encryption.prototype.createRSAKey=function(){var k=this.key.split("|");if(k.length!==2){throw"Malformed public key"}var exp=k[0];var mod=k[1];var rsa=new RSAKey();rsa.setPublic(mod,exp);return rsa};Encryption.prototype.createAESKey=function(){return new AESKey()};Encryption.prototype.encrypt=function(original){var data={};for(var i in original){if(original.hasOwnProperty(i)){data[i]=original[i]}}var rsa,aes,cipher,keybytes,encrypted,prefix,validationObject={};if(typeof data.number!=="undefined"){validationObject.number=data.number}if(typeof data.cvc!=="undefined"){validationObject.cvc=data.cvc}if(typeof data.expiryMonth!=="undefined"){validationObject.month=data.expiryMonth}if(typeof data.expiryYear!=="undefined"){validationObject.year=data.expiryYear}if(typeof data.holderName!=="undefined"){validationObject.holderName=data.holderName}if(typeof data.generationtime!=="undefined"){validationObject.generationtime=data.generationtime}if(this.options.enableValidations!==false&&this.validate(validationObject).valid===false){return false}for(var s=0;s<11;s++){if(sjcl.random&&sjcl.random.isReady(s)){evLog("set","sjclStrength",s)}else{break}}evLog("extend",data);rsa=this.createRSAKey();aes=this.createAESKey();cipher=aes.encrypt(JSON.stringify(data));keybytes=sjcl.codec.bytes.fromBits(aes.key());encrypted=rsa.encrypt_b64(keybytes);prefix="adyenjs_"+encrypt.version+"$";return[prefix,encrypted,"$",cipher].join("")};Encryption.prototype.validate=function(data){var result={};result.valid=true;if(typeof data!=="object"){result.valid=false;return result}for(var field in data){if(!data.hasOwnProperty(field)||typeof data[field]==="undefined"){continue}var val=data[field];if(this.options[field+"IgnoreNonNumeric"]){val=val.replace(/\D/g,"")}if(this.options[field+"SkipValidation"]){continue}for(var relatedField in data){if(data.hasOwnProperty(relatedField)){var possibleOption=this.options[field+"IgnoreFor"+relatedField];var lengthOption=this.options[field+"LengthFor"+relatedField];if(possibleOption&&data[relatedField].match(possibleOption)){result[field]=true;continue}else{if(lengthOption&&lengthOption.matcher&&lengthOption.requiredLength&&data[relatedField].match(lengthOption.matcher)){if(val.length!==lengthOption.requiredLength){result[field]=false;continue}}}}}if(result.hasOwnProperty(field)){result.valid=result.valid&&result[field];continue}switch(field){case"number":result.number=validations.numberCheck(val);result.luhn=result.number;result.valid=result.valid&&result.number;break;case"expiryYear":case"year":result.year=validations.yearCheck(val);result.expiryYear=result.year;result.valid=result.valid&&result.year;break;case"cvc":result.cvc=validations.cvcCheck(val);result.valid=result.valid&&result.cvc;break;case"expiryMonth":case"month":result.month=validations.monthCheck(val);result.expiryMonth=result.month;result.valid=result.valid&&result.month;break;case"holderName":result.holderName=validations.holderNameCheck(val);result.valid=result.valid&&result.holderName;break;case"generationtime":result.generationtime=validations.generationTimeCheck(val);result.valid=result.valid&&result.generationtime;break;default:result.unknown=result.unknown||[];result.unknown.push(field);result.valid=false}}return result};Encryption.prototype.monitor=function(field,node){if(typeof field!=="string"||(field!=="number"&&field!=="cvc"&&field!=="holderName")){throw new Error("invalid fieldname. Expected 'number', 'cvc' or 'holderName', but received '"+field+"'")}evLog("bind",node,field)};validations.createChangeHandler=function(cse,field,allowEmpty){var ceConfig={chained:false};var ce=function(ev){var node=ev.target||ev.srcElement,val=(node||{}).value||"";var isInitializing=(typeof ev.isInitializing==="boolean"&&ev.isInitializing);if(node.options&&typeof node.selectedIndex!=="undefined"){val=node.options[node.selectedIndex].value}if(cse.options[field+"IgnoreNonNumeric"]){val=val.replace(/\D/g,"")}var fieldData=cse.toJSON(cse.getEncryptedFields(cse.element));var validationData={year:fieldData.expiryYear,month:fieldData.expiryMonth,number:fieldData.number,cvc:fieldData.cvc,holderName:fieldData.holderName};var validationResult=cse.encryption.validate(validationData);for(var i in validationResult){if(validationResult.hasOwnProperty(i)){cse.validity[i]=validationResult[i]}}if(cse.validity[field]){removeClass(node,"invalid-"+field);addClass(node,"valid-"+field)}else{if(!isInitializing||val!==""){addClass(node,"invalid-"+field)}removeClass(node,"valid-"+field)}cse.validity.luhn=cse.validity.number;if((node.className||"").match(/invalid-number/)){addClass(node,"invalid-luhn");removeClass(node,"valid-luhn")}else{if((node.className||"").match(/valid-number/)){removeClass(node,"invalid-luhn");addClass(node,"valid-luhn")}}if(allowEmpty&&val===""){removeClass(node,"valid-"+field);removeClass(node,"invalid-"+field)}if((node.className||"").match(/invalid-/)){addClass(node,"invalid")}else{removeClass(node,"invalid")}if(cse.options.disabledValidClass!==true){if((node.className||"").match(/invalid-/)){removeClass(node,"valid")}else{addClass(node,"valid")}}if(typeof ceConfig.chained==="function"){ceConfig.chained(ev)}else{if(!isInitializing){cse.toggleSubmit()}}};ce.chain=function(handler){ceConfig.chained=handler};return ce};var DEFAULT_FIELDNAME_ATTRIBUTE="data-encrypted-name";var EncryptedForm=function(element,key,options){if(typeof element!=="object"||element===null||typeof element.ownerDocument!=="object"){throw new Error("Expected target element to be a HTML Form element")}if("form"!==(element.nodeName||element.tagName||"").toLowerCase()){throw new Error("Expected target element to be a HTML Form element")}this.element=element;this.key=key;this.validity={};evLog("initializeFormCount");this.options=options=options||{};if(typeof options!=="object"){throw new Error("Expected options to be an object")}if(typeof options.numberIgnoreNonNumeric==="undefined"){options.numberIgnoreNonNumeric=true}options.generationtimeSkipValidation=(options.generationtimeSkipValidation===true);options.cvcSkipValidation=(options.cvcSkipValidation===true);if(typeof options.fieldNameAttribute!=="string"||!options.fieldNameAttribute.match(/^data(-\w+)+$/i)){options.fieldNameAttribute=DEFAULT_FIELDNAME_ATTRIBUTE}this.name=options.name||"adyen-encrypted-data";this.fieldNameAttribute=options.fieldNameAttribute||DEFAULT_FIELDNAME_ATTRIBUTE;this.onsubmit=options.onsubmit||function(){};this.encryption=new Encryption(key,options);if(this.element.addEventListener){this.element.addEventListener("submit",this.handleSubmit.bind(this),false)}else{if(this.element.attachEvent){this.element.attachEvent("onsubmit",this.handleSubmit.bind(this))}}if(options.enableValidations!==false){this.addValidations()}for(var i=0,c=element.elements.length;i=0;i--){field=fields[i];field.removeAttribute("name");key=field.getAttribute(this.fieldNameAttribute);value=field.value;if(field.options&&typeof field.selectedIndex!=="undefined"){value=field.options[field.selectedIndex].value}data[key]=value}return data},encrypt:function(){return this.encryption.encrypt(this.toJSON(this.getEncryptedFields(this.element)))},createEncryptedField:function(data){var element=document.getElementById(this.name);if(!element){element=document.createElement("input");element.type="hidden";element.name=element.id=this.name;this.element.appendChild(element)}element.setAttribute("value",data)},addValidations:function(){var cse=this,elements=this.element.elements,c=elements.length,element,handlers={},elementsByName={};for(;c-->0;){element=elements[c];if(!element||!element.getAttribute){continue}var fieldName=element.getAttribute(this.fieldNameAttribute);elementsByName[fieldName]=element;if(fieldName==="number"){handlers.luhnHandler=handlers.luhnHandler||validations.createChangeHandler(cse,"number",true);addEvent(element,"change",handlers.luhnHandler,false);addEvent(element,"keyup",handlers.luhnHandler,false);addEvent(element,"blur",handlers.luhnHandler,false);handlers.luhnHandler({target:element,isInitializing:true})}else{if(fieldName==="cvc"){handlers.cvcHandler=handlers.cvcHandler||validations.createChangeHandler(cse,"cvc",true);addEvent(element,"change",handlers.cvcHandler,false);addEvent(element,"keyup",handlers.cvcHandler,false);addEvent(element,"blur",handlers.cvcHandler,false);handlers.cvcHandler({target:element,isInitializing:true})}else{if(fieldName==="expiryYear"){handlers.expiryYearHandler=handlers.expiryYearHandler||validations.createChangeHandler(cse,"year",true);addEvent(element,"change",handlers.expiryYearHandler,false);addEvent(element,"keyup",handlers.expiryYearHandler,false);addEvent(element,"blur",handlers.expiryYearHandler,false);handlers.expiryYearHandler({target:element,isInitializing:true})}else{if(fieldName==="expiryMonth"){handlers.expiryMonthHandler=handlers.expiryMonthHandler||validations.createChangeHandler(cse,"month",true);addEvent(element,"change",handlers.expiryMonthHandler,false);addEvent(element,"keyup",handlers.expiryMonthHandler,false);addEvent(element,"blur",handlers.expiryMonthHandler,false);handlers.expiryMonthHandler({target:element,isInitializing:true})}else{if(fieldName==="holderName"){handlers.holderNameHandler=handlers.holderNameHandler||validations.createChangeHandler(cse,"holderName",false);addEvent(element,"change",handlers.holderNameHandler,false);addEvent(element,"keyup",handlers.holderNameHandler,false);addEvent(element,"blur",handlers.holderNameHandler,false);handlers.holderNameHandler({target:element,isInitializing:true})}}}}}}if(handlers.luhnHandler&&handlers.cvcHandler&&elementsByName.number&&elementsByName.cvc){handlers.luhnHandler.chain(function(ev){handlers.cvcHandler({target:elementsByName.cvc,originalEvent:ev,type:(ev||{}).type,isInitializing:(ev||{}).isInitializing})})}},addCardTypeDetection:function(cardTypeElement){if(typeof adyen.CardTypeDetection==="undefined"||typeof adyen.CardTypeDetection.getHandler!=="function"){return window.console&&window.console.warn("[CSE] Card type detection not available")}var updateCardTypeDetection=adyen.CardTypeDetection.getHandler(cardTypeElement);var cse=this,elements=this.element.elements,c=elements.length,element,handlers={};for(;c-->0;){element=elements[c];if(!element||!element.getAttribute){continue}else{if(element.getAttribute(this.fieldNameAttribute)==="number"){addEvent(element,"change",updateCardTypeDetection,false);addEvent(element,"input",updateCardTypeDetection,false);addEvent(element,"keyup",updateCardTypeDetection,false);updateCardTypeDetection({target:element})}}}},validate:function(){var fields=this.toJSON(this.getEncryptedFields(this.element));delete fields.generationtime;return this.encryption.validate(fields)||{valid:false}},isValid:function(){var valid=this.validate().valid;for(var i in this.validity){if(this.validity.hasOwnProperty(i)){valid=valid&&this.validity[i]}}return valid},toggleSubmit:function(){var valid=this.isValid(),elements=this.element.elements,enabled;enabled=valid===true||(this.options&&this.options.submitButtonAlwaysEnabled===true);for(var c=elements.length;c-->0;){if(elements[c]&&(elements[c].type||"").toLowerCase()==="submit"){elements[c].disabled=!enabled}}if(typeof this.options.onvalidate==="function"){try{this.options.onvalidate(this.validity)}catch(e){if(window.console&&window.console.warn&&window.console.log){console.warn("[CSE] Error in custom validationComplete handler");console.log("Caught error was ",e)}}}return valid},getVersion:function(){return encrypt.version}};var AESKey=function(){};AESKey.prototype={constructor:AESKey,key:function(){this._key=this._key||sjcl.random.randomWords(8,6);return this._key},encrypt:function(text){return this.encryptWithIv(text,sjcl.random.randomWords(3,6))},encryptWithIv:function(text,iv){var aes,bits,cipher,cipherIV;aes=new sjcl.cipher.aes(this.key());bits=sjcl.codec.utf8String.toBits(text);cipher=sjcl.mode.ccm.encrypt(aes,bits,iv);cipherIV=sjcl.bitArray.concat(iv,cipher);return sjcl.codec.base64.fromBits(cipherIV)}}})(this,typeof define==="function"?define:null); 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-adyen-encrypt", 3 | "version": "2.3.1", 4 | "description": "Adyen encryption for Node.js.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test-dev": "jest" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/dmop/node-adyen-encrypt.git" 12 | }, 13 | "keywords": [ 14 | "Adyen", 15 | "node", 16 | "encrypt", 17 | "cse", 18 | "web", 19 | "javascript" 20 | ], 21 | "author": "dmop", 22 | "license": "ISC", 23 | "bugs": { 24 | "url": "https://github.com/dmop/node-adyen-encrypt/issues" 25 | }, 26 | "homepage": "https://github.com/dmop/node-adyen-encrypt#readme", 27 | "devDependencies": { 28 | "jest": "^26.6.3" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/index.test.js: -------------------------------------------------------------------------------- 1 | const adyenKey = 2 | "10001|90C7821C961865FB4AD23F172E220F726A5CC7B9956BC3458E2788" + 3 | "F9D725B07536E297B89243081916AAF29E26B7624453FC84CB10FC7DF386" + 4 | "31B3FA0C2C01765D884B0DA90145FCE217446BCDCE4771E30E6E5630E797" + 5 | "EE289D3A712F93C676994D2746CBCD0BEDD7D29618AF45FA6230C1D41FE1" + 6 | "DB0193B8FA6613F1BD145EA339DAC449603096A40DC4BF8FACD84A5D2CA5" + 7 | "ECFC59B90B928F31715A7034E7B674E221F1EB1D696CC8B734DF7DE2E309" + 8 | "E6E8CF94156686558522629E8AF59620CBDE58327E9D84F29965E4CD0FAF" + 9 | "A38C632B244287EA1F7F70DAA445D81C216D3286B09205F6650262CAB415" + 10 | "5F024B3294A933F4DC514DE0B5686F6C2A6A2E"; 11 | 12 | const cardData = { 13 | number: "5369 6587 0410 7605", 14 | cvc: "855", 15 | holderName: "Bob Dylan", 16 | expiryMonth: "12", 17 | expiryYear: "2022", 18 | generationtime: "2020-11-30T14:38:25.124Z", 19 | }; 20 | 21 | const validationResponse = { 22 | valid: true, 23 | number: true, 24 | luhn: true, 25 | cvc: true, 26 | holderName: true, 27 | month: true, 28 | expiryMonth: true, 29 | year: true, 30 | expiryYear: true, 31 | generationtime: true, 32 | }; 33 | 34 | describe("app()", () => { 35 | it("should works with v18", () => { 36 | const adyenEncrypt = require("../index")(18); 37 | 38 | // apparently those weren't supported on v18? 39 | delete cardData.generationtime; 40 | delete validationResponse.generationtime; 41 | 42 | const cseInstance = adyenEncrypt.createEncryption(adyenKey, {}); 43 | const validation = cseInstance.validate(cardData); 44 | 45 | expect(validation).toEqual(validationResponse); 46 | }); 47 | 48 | it("should works with v22", () => { 49 | const adyenEncrypt = require("../index")(22); 50 | 51 | const cseInstance = adyenEncrypt.createEncryption(adyenKey, {}); 52 | const validation = cseInstance.validate(cardData); 53 | 54 | expect(validation).toEqual(validationResponse); 55 | }); 56 | 57 | it("should works with v23", () => { 58 | const adyenEncrypt = require("../index")(23); 59 | 60 | const cseInstance = adyenEncrypt.createEncryption(adyenKey, {}); 61 | const validation = cseInstance.validate(cardData); 62 | 63 | expect(validation).toEqual(validationResponse); 64 | }); 65 | 66 | it("should works with v24", () => { 67 | const adyenEncrypt = require("../index")(24); 68 | 69 | const cseInstance = adyenEncrypt.createEncryption(adyenKey, {}); 70 | const validation = cseInstance.validate(cardData); 71 | 72 | expect(validation).toEqual(validationResponse); 73 | }); 74 | 75 | it("should works with v25", () => { 76 | const adyenEncrypt = require("../index")(25); 77 | 78 | const cseInstance = adyenEncrypt.createEncryption(adyenKey, {}); 79 | const validation = cseInstance.validate(cardData); 80 | 81 | expect(validation).toEqual(validationResponse); 82 | }); 83 | }); 84 | --------------------------------------------------------------------------------