diff --git a/HostedCSE.md b/HostedCSE.md new file mode 100644 index 0000000..0f25bae --- /dev/null +++ b/HostedCSE.md @@ -0,0 +1,38 @@ +# Adyen Hosted Form Based Integration + +A variant to the HTML / Form based integration is to have the library hosted by Adyen, after which you do no longer need to take care of keeping your codebase and encryption key in sync with adyen systems as it will be injected by Adyen. + +The syntax is similar to the HTML integration, but instead of downloading and hosting the `adyen.encrypt.min.js` on your own servers, you use a CSE url that is unique for the webservice user you use to post to Adyen. The CSE url can be retrieved from the webservice user page, where you also retrieve your CSE public key. + +*The script URL of the CSE library differs per webservice user. You can retrieve yours from the Edit Webservice User in the Adyen Customer Area. Please note that the url is only visible in the Edit Webservice user page when there is a CSE key generated. If there is none, save the webservice user once to have one generated.* + +The HTML template is the same as the HTML based integration shown earlier. However instead of hosting `adyen.encrypt.min.js` on your own server, you include a reference to the Adyen hosted Client-side encryption library. + + + +```` html + + +```` + +Initialze the clientside encryption form as in the normal HTML Form based integration. *Note that the AMD style is not yet available for the hosted CSE library.* + +```` javascript +// the form element to encrypt +var form = document.getElementById('adyen-encrypted-form'); + +// See adyen.encrypt.simple.html for details on the options to use +var options = {}; + +// Create the form. +// Note that the method is on the Adyen object, not the adyen.encrypt object. +adyen.createEncryptedForm( form, options); + +```` + +# Known limitations +- Currently the hosted CSE does not offer a AMD style. We will update this page when it does. \ No newline at end of file diff --git a/Options.md b/Options.md new file mode 100644 index 0000000..0f71c99 --- /dev/null +++ b/Options.md @@ -0,0 +1,43 @@ + # Options + + The `createEncryption ( key , `*`options`*` )` and `createEncryptedForm ( form, key, `*`options`*` )` methods currently support the following fields. + + +* **boolean `[enableValidations = true] `** + + Enable basic field validations. Disable the submit button when the form is not valid + +* **boolean `[submitButtonAlwaysEnabled = false]`** + + Force the submit button to be enabled, even when the front-end validation fails. + +* **boolean `[numberIgnoreNonNumeric = true]`** + + When validating the credit card number, ignore non numeric characters like spaces + +* **string `[fieldNameAttribute = 'data-encrypted-name']`** + + Configure the attribute to identify fields to be encrypted. Useful when you have multiple payment options within the same form, and want to bind each set to it's own CSE handler. + +* **function `[onsubmit]`** + + Custom handler to be called on submit of the form. + +* **HTMLElement `[cardTypeElement]`** + + Placeholder element to place card type detection results on, when the card type detection addon is enabled. + +* **string `[cvcIgnoreBins = '']`** + + A comma separated string of bins for which the CVC code validation should be ignored. + + For example `cvcIgnoreBins = '6703'`) to ignore CVC validation for BCMC. + + +## Option in createEncryptedForm() +Supported fields: `enabledValidations`, `numberIgnoreNonNumeric`, `cvcIgnoreBins`, `submitButtonsAlwaysEnabled`, `fieldNameAttribute`, `onsubmit` + +When the card type detection addon is being enabled, the `cardTypeElement` option is also supported. + +## Option in createEncryption() +Currently `enabledValidations`, `numberIgnoreNonNumeric` and `cvcIgnoreBins` are supported. diff --git a/README.md b/README.md index 7be8295..dfb5c75 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,142 @@ -client-side-encryption -========== -Sample code for client-side encryption - -[![Build Status](https://travis-ci.org/Adyen/CSE-iOS.svg)](https://travis-ci.org/Adyen/CSE-iOS) +# Client-Side Encryption (CSE) + +This repository contains sample code for adding Adyen Payments using Client-side encryption (CSE). + +The library currently offers two integration methods: + +- [HTML based integration]() in which a HTML form is enriched, encrypting data on submit +- [JavaScript only integration]() in which data can be encrypted using a JavaScript only API. + +The library currently has three inclusion / loading styling: +- Download `adyen.encrypt.min.js` and host it yourself. Both HTML based as JavaScript only integration is supported. +- Download `adyen.encrypt.nodom.min.js` and host it yourself. Only supports JavaScript only integration. +- Adyen Hosted version in which the public key is embedded in the JavaScript. This integration makes sure you always have the latest security patches, and don't have to keep your public key in sync with the Adyen servers manually. See [Adyen Hosted Form Based Integration](HostedCSE.md) for more details. + + +## HTML based integration + +This integration binds to existing HTML in the page, adding a hidden input containing the encrypted card data to the form on the moment the form is submitted. + +The complete integration requires HTML markup to be present in the page, as well as accompanying JavaScript to enable the behavior. + +### HTML Template + +Create your payment form, and make sure to add a way to reference to your form from JavaScript. For example by adding `id="adyen-encrypted-form"`. + +Note that card input fields should not have a `name=` attribute, but are annotated by the `data-encrypted-name=` attribute, to mark them for encryption. This makes sure that the input values are never send to the server. +````html +
+ + + + + + + +
+```` + +### JavaScript +Accompanying the above the HTML template, there are two variants to including the CSE library. The original plain JavaScript variant relies on a global `adyen.encrypt` object, while on popular demand a AMD style module has been added. + +#### Plain JavaScript +Include the Adyen Clientside Encryption Library to your page +````html + +```` +Enricht a form in your page with the CSE onSubmit and (optionally) validation behaviors +````javascript +// The form element to encrypt +var form = document.getElementById('adyen-encrypted-form'); +// The public key +var key = "your key as retrieved from the Adyen Customer Area Web Service User page"; +// Form and encryption options. See adyen.encrypt.simple.html for details +var options = {}; +// Bind encryption to the form +adyen.encrypt.createEncryptedForm( form, key, options); +```` + +#### RequireJS +Make sure you include requirejs or a alternative AMD module loader in your page +````html + +```` +You can either rename the `adyen.encrypt.min.js` into `adyen/encrypt.js`, or add a paths configuration: +````javascript +// Your paths config, or rename the adyen.encrypt.min.js to adyen/encrypt.js +require.config({ + paths: { + 'adyen/encrypt' : '../simple/js/adyen.encrypt.min' + } +}); +```` + +In the `main.js` or similar file, enrich the form using a `require` call. + +````javascript +require(['adyen/encrypt'], function(adyenEncrypt) { + // The form element to encrypt + var form = document.getElementById('adyen-encrypted-form'); + // The public key + var key = "your key as retrieved from the Adyen Customer Area Web Service User page"; + // Form and encryption options. See adyen.encrypt.simple.html for details + var options = {}; + // Bind encryption to the form + adyenEncrypt.createEncryptedForm( form, key, options ); +}); + +```` + +## JavaScript only integration + +In case the HTML integration is troublesome in your setup, the library has been split up into two parts since release V0_1_11. The newly introduced part is a HTML independant encryption. + +*As with all CSE integrations, make sure that no card data is send to your server unencrypted* + +````html + + +```` + + +# Version History + +JavaScript version 0_1_11 +------- + +* Introduce `adyen.encrypt.createEncryption(key, options)` to split out the DOM handling from the encryption. Allowing easier integration for UI frameworks like Angular or Backbone. + +* Add a first structure of behavior tracking to the client side encryption which will be embedded as meta data to the encrypted object and use for fraud detection. + +* Add `options.cvcIgnoreBins` to allow CVC validation to be skipped for certain bins. + +* Add reference to `adyen.createEncryption(form, options)` which can be used with the [Adyen Hosted Form Based Integration](HostedCSE.md). JavaScript version 0_1_10 --- diff --git a/adyen.encrypt.nodom.html b/adyen.encrypt.nodom.html new file mode 100644 index 0000000..a6685fd --- /dev/null +++ b/adyen.encrypt.nodom.html @@ -0,0 +1,102 @@ + + + + Example Payment Form + + + + + +
+ + +
+ + + + + + + + + \ No newline at end of file diff --git a/adyen.encrypt.simple.html b/adyen.encrypt.simple.html index 16a7be4..e206a00 100644 --- a/adyen.encrypt.simple.html +++ b/adyen.encrypt.simple.html @@ -6,6 +6,7 @@ +
Card Details @@ -44,12 +45,16 @@
+ - - + + \ No newline at end of file diff --git a/js/addOns/adyen.cardtype.js b/js/addOns/adyen.cardtype.js index bac1245..5fabf39 100644 --- a/js/addOns/adyen.cardtype.js +++ b/js/addOns/adyen.cardtype.js @@ -44,7 +44,7 @@ var adyen = window.adyen = window.adyen || {}, cardTypes = ( function () { /* adyen-hpp.cc.js */ - var Cards=new makeArray(22);Cards[0]=new CardType("mc","51,52,53,54,55","16");var MasterCard=Cards[0];Cards[1]=new CardType("visadankort","4571","16");var VisaDankort=Cards[1];Cards[2]=new CardType("visa","4","13,16");var VisaCard=Cards[2];Cards[3]=new CardType("amex","34,37","15");var AmExCard=Cards[3];Cards[4]=new CardType("vias","9","16");var AdyenCard=Cards[4];Cards[5]=new CardType("diners","36","14");var DinersClubCard=Cards[5];Cards[6]=new CardType("maestrouk","6759","16,18,19");var MaestroUKCard=Cards[6];Cards[7]=new CardType("solo","6767","16,18,19");var SoloCard=Cards[7];Cards[8]=new CardType("laser","6304,6706,677117,677120","16,17,18,19");var LaserCard=Cards[8];Cards[9]=new CardType("discover","6011,644,645,646,647,648,649,65","16");var DiscoverCard=Cards[9];Cards[10]=new CardType("jcb","3528,3529,353,354,355,356,357,358","16,19");var JCBCard=Cards[10];Cards[11]=new CardType("bcmc","6703","16,17,18,19");var Bcmc=Cards[11];Cards[12]=new CardType("bijcard","5100081","16");var BijCard=Cards[12];Cards[13]=new CardType("dankort","5019","16");var Dankort=Cards[13];Cards[14]=new CardType("hipercard","606282","16");var Hipercard=Cards[14];Cards[15]=new CardType("maestro","50,56,57,58,6","16");var MaestroCard=Cards[15];Cards[16]=new CardType("elo","506699,50670,50671,50672,50673,50674,50675,50676,506770,506771,506772,506773,506774,506775,506776,506777,506778,401178,438935,451416,457631,457632,504175,627780,636297,636368","16");var Elo=Cards[16];Cards[17]=new CardType("uatp","1","15");var Uatp=Cards[17];Cards[18]=new CardType("cup","62","14,15,16,17,18,19");var Cup=Cards[18];Cards[19]=new CardType("cartebancaire","4,5,6","16");var CarteBancaire=Cards[19];Cards[20]=new CardType("visaalphabankbonus","450903","16");var VisAlphaBankBonus=Cards[20];Cards[21]=new CardType("mcalphabankbonus","510099","16");var McAlphaBankBonus=Cards[21];var LuhnCheckSum=Cards[21]=new CardType();function CheckCardNumber(cardNumber,expYear,expMon,cardType){var tmpyear;if(cardNumber.length==0){alert("Please enter a Card Number.");return false}if(expYear.length==0){alert("Please enter the Expiration Year.");return false}if(expYear>96){tmpyear="19"+expYear}else{if(expYear<21){tmpyear="20"+expYear}else{alert("The Expiration Year is not valid.");return false}}tmpmonth=expMon;if(!(new CardType()).isExpiryDate(tmpyear,tmpmonth)){alert("This card has already expired.");return false}card=cardType;var retval=eval(card+'.checkCardNumber("'+cardNumber+'", '+tmpyear+", "+tmpmonth+");");cardname="";if(retval){return true}else{for(var n=0;n0){alert("This looks like a "+cardname+" number, not a "+card+" number.")}else{alert("This card number is not valid.")}}}function CardType(){var f;var a=CardType.arguments;var d=CardType.arguments.length;this.objname="object CardType";var c=(d>0)?a[0]:"CardObject";var e=(d>1)?a[1]:"0,1,2,3,4,5,6,7,8,9";var b=(d>2)?a[2]:"13,14,15,16,19";this.setCardNumber=setCardNumber;this.setCardType=setCardType;this.setLen=setLen;this.setRules=setRules;this.setExpiryDate=setExpiryDate;this.setCardType(c);this.setLen(b);this.setRules(e);if(d>4){this.setExpiryDate(a[3],a[4])}this.checkCardNumber=checkCardNumber;this.getExpiryDate=getExpiryDate;this.getCardType=getCardType;this.isCardNumber=isCardNumber;this.isExpiryDate=isExpiryDate;this.luhnCheck=luhnCheck;return this}function checkCardNumber(){var a=checkCardNumber.arguments;var e=checkCardNumber.arguments.length;var c=(e>0)?a[0]:this.cardnumber;var b=(e>1)?a[1]:this.year;var d=(e>2)?a[2]:this.month;this.setCardNumber(c);this.setExpiryDate(b,d);if(!this.isCardNumber()){return false}if(!this.isExpiryDate()){return false}return true}function getCardType(){return this.cardtype}function getExpiryDate(){return this.month+"/"+this.year}function isCardNumber(){var b=isCardNumber.arguments;var d=isCardNumber.arguments.length;var c=(d>0)?b[0]:this.cardnumber;if(!this.luhnCheck()){return false}for(var f=0;f0?a[0]:this.year;month=b>1?a[1]:this.month;if(!isNum(year+"")){return false}if(!isNum(month+"")){return false}today=new Date();expiry=new Date(year,month);if(today.getTime()>expiry.getTime()){return false}else{return true}}function isNum(a){a=a.toString();if(a.length==0){return false}for(var b=0;b"9"){return false}}return true}function luhnCheck(){var a=luhnCheck.arguments;var g=luhnCheck.arguments.length;var c=g>0?a[0]:this.cardnumber;if(!isNum(c)){return false}var b=c.length;var d=b&1;var e=0;for(var f=0;f9){h-=9}}e+=h}if(e%10==0){return true}else{return false}}function makeArray(a){this.size=a;return this}function setCardNumber(a){this.cardnumber=a;return this}function setCardType(a){this.cardtype=a;return this}function setExpiryDate(a,b){this.year=a;this.month=b;return this}function setLen(a){if(a.length==0||a==null){a="13,14,15,16,19"}var c=a;n=1;while(c.indexOf(",")!=-1){c=c.substring(c.indexOf(",")+1,c.length);n++}this.len=new makeArray(n);n=0;while(a.indexOf(",")!=-1){var b=a.substring(0,a.indexOf(","));this.len[n]=b;a=a.substring(a.indexOf(",")+1,a.length);n++}this.len[n]=a;return this}function setRules(c){if(c.length==0||c==null){c="0,1,2,3,4,5,6,7,8,9"}var b=c;n=1;while(b.indexOf(",")!=-1){b=b.substring(b.indexOf(",")+1,b.length);n++}this.rules=new makeArray(n);n=0;while(c.indexOf(",")!=-1){var a=c.substring(0,c.indexOf(","));this.rules[n]=a;c=c.substring(c.indexOf(",")+1,c.length);n++}this.rules[n]=c;return this}function contains(b,d){var c=b.length;while(c--){if(b[c]===d){return true}}return false}function getBaseCard(e,c){for(var d=0;d<(Cards.size-1);d++){for(var h=0;he.toString().length){b=e.toString().length}var g=e.substring(0,b);var f=Cards[d].rules[a].toString().substring(0,b);if(g===f){if(contains(c,Cards[d].cardtype)){return Cards[d]}if(contains(c,MasterCard.cardtype)){if(Cards[d].cardtype===MaestroCard.cardtype){return MasterCard}}}}}}}return null}function getBaseCardByType(b){for(var a=0;a<(Cards.size-1);a++){if(Cards[a].cardtype==b){return Cards[a]}}return null};/* */ + var Cards=new makeArray(22);Cards[0]=new CardType("mc","51,52,53,54,55","16");var MasterCard=Cards[0];Cards[1]=new CardType("visadankort","4571","16");var VisaDankort=Cards[1];Cards[2]=new CardType("visa","4","13,16");var VisaCard=Cards[2];Cards[3]=new CardType("amex","34,37","15");var AmExCard=Cards[3];Cards[4]=new CardType("vias","9","16");var AdyenCard=Cards[4];Cards[5]=new CardType("diners","36","14");var DinersClubCard=Cards[5];Cards[6]=new CardType("maestrouk","6759","16,18,19");var MaestroUKCard=Cards[6];Cards[7]=new CardType("solo","6767","16,18,19");var SoloCard=Cards[7];Cards[8]=new CardType("laser","6304,6706,677117,677120","16,17,18,19");var LaserCard=Cards[8];Cards[9]=new CardType("discover","6011,644,645,646,647,648,649,65","16");var DiscoverCard=Cards[9];Cards[10]=new CardType("jcb","3528,3529,353,354,355,356,357,358","16,19");var JCBCard=Cards[10];Cards[11]=new CardType("bcmc","6703","16,17,18,19");var Bcmc=Cards[11];Cards[12]=new CardType("bijcard","5100081","16");var BijCard=Cards[12];Cards[13]=new CardType("dankort","5019","16");var Dankort=Cards[13];Cards[14]=new CardType("hipercard","606282","16");var Hipercard=Cards[14];Cards[15]=new CardType("maestro","50,56,57,58,6","16");var MaestroCard=Cards[15];Cards[16]=new CardType("elo","506699,50670,50671,50672,50673,50674,50675,50676,506770,506771,506772,506773,506774,506775,506776,506777,506778,401178,438935,451416,457631,457632,504175,627780,636297,636368","16");var Elo=Cards[16];Cards[17]=new CardType("uatp","1","15");var Uatp=Cards[17];Cards[18]=new CardType("cup","62","14,15,16,17,18,19");var Cup=Cards[18];Cards[19]=new CardType("cartebancaire","4,5,6","16");var CarteBancaire=Cards[19];Cards[20]=new CardType("visaalphabankbonus","450903","16");var VisAlphaBankBonus=Cards[20];Cards[21]=new CardType("mcalphabankbonus","510099","16");var McAlphaBankBonus=Cards[21];var LuhnCheckSum=Cards[21]=new CardType();function CheckCardNumber(cardNumber,expYear,expMon,cardType){var tmpyear;if(cardNumber.length==0){alert("Please enter a Card Number.");return false}if(expYear.length==0){alert("Please enter the Expiration Year.");return false}if(expYear>96){tmpyear="19"+expYear}else{if(expYear<21){tmpyear="20"+expYear}else{alert("The Expiration Year is not valid.");return false}}tmpmonth=expMon;if(!(new CardType()).isExpiryDate(tmpyear,tmpmonth)){alert("This card has already expired.");return false}card=cardType;var retval=eval(card+'.checkCardNumber("'+cardNumber+'", '+tmpyear+", "+tmpmonth+");");cardname="";if(retval){return true}else{for(var n=0;n0){alert("This looks like a "+cardname+" number, not a "+card+" number.")}else{alert("This card number is not valid.")}}}function CardType(){var f;var a=CardType.arguments;var d=CardType.arguments.length;this.objname="object CardType";var c=(d>0)?a[0]:"CardObject";var e=(d>1)?a[1]:"0,1,2,3,4,5,6,7,8,9";var b=(d>2)?a[2]:"13,14,15,16,19";this.setCardNumber=setCardNumber;this.setCardType=setCardType;this.setLen=setLen;this.setRules=setRules;this.setExpiryDate=setExpiryDate;this.setCardType(c);this.setLen(b);this.setRules(e);if(d>4){this.setExpiryDate(a[3],a[4])}this.checkCardNumber=checkCardNumber;this.getExpiryDate=getExpiryDate;this.getCardType=getCardType;this.isCardNumber=isCardNumber;this.isExpiryDate=isExpiryDate;this.luhnCheck=luhnCheck;return this}function checkCardNumber(){var a=checkCardNumber.arguments;var e=checkCardNumber.arguments.length;var c=(e>0)?a[0]:this.cardnumber;var b=(e>1)?a[1]:this.year;var d=(e>2)?a[2]:this.month;this.setCardNumber(c);this.setExpiryDate(b,d);if(!this.isCardNumber()){return false}if(!this.isExpiryDate()){return false}return true}function getCardType(){return this.cardtype}function getExpiryDate(){return this.month+"/"+this.year}function isCardNumber(){var b=isCardNumber.arguments;var d=isCardNumber.arguments.length;var c=(d>0)?b[0]:this.cardnumber;if(!this.luhnCheck()){return false}for(var f=0;f0?a[0]:this.year;month=b>1?a[1]:this.month;if(!isNum(year+"")){return false}if(!isNum(month+"")){return false}today=new Date();expiry=new Date(year,month);if(today.getTime()>expiry.getTime()){return false}else{return true}}function isNum(a){a=a.toString();if(a.length==0){return false}for(var b=0;b"9"){return false}}return true}function luhnCheck(){var a=luhnCheck.arguments;var g=luhnCheck.arguments.length;var c=g>0?a[0]:this.cardnumber;if(!isNum(c)){return false}var b=c.length;var d=b&1;var e=0;for(var f=0;f9){h-=9}}e+=h}if(e%10==0){return true}else{return false}}function makeArray(a){this.size=a;return this}function setCardNumber(a){this.cardnumber=a;return this}function setCardType(a){this.cardtype=a;return this}function setExpiryDate(a,b){this.year=a;this.month=b;return this}function setLen(a){if(a.length==0||a==null){a="13,14,15,16,19"}var c=a;n=1;while(c.indexOf(",")!=-1){c=c.substring(c.indexOf(",")+1,c.length);n++}this.len=new makeArray(n);n=0;while(a.indexOf(",")!=-1){var b=a.substring(0,a.indexOf(","));this.len[n]=b;a=a.substring(a.indexOf(",")+1,a.length);n++}this.len[n]=a;return this}function setRules(c){if(c.length==0||c==null){c="0,1,2,3,4,5,6,7,8,9"}var b=c;n=1;while(b.indexOf(",")!=-1){b=b.substring(b.indexOf(",")+1,b.length);n++}this.rules=new makeArray(n);n=0;while(c.indexOf(",")!=-1){var a=c.substring(0,c.indexOf(","));this.rules[n]=a;c=c.substring(c.indexOf(",")+1,c.length);n++}this.rules[n]=c;return this}function contains(b,d){var c=b.length;while(c--){if(b[c]===d){return true}}return false}function getBaseCard(e,c){for(var d=0;d<(Cards.size-1);d++){for(var h=0;he.toString().length){b=e.toString().length}var g=e.substring(0,b);var f=Cards[d].rules[a].toString().substring(0,b);if(g===f){if(contains(c,Cards[d].cardtype)){return Cards[d]}if(contains(c,MasterCard.cardtype)){if(Cards[d].cardtype===MaestroCard.cardtype){return MasterCard}}}}}}}return null}function getBaseCardByType(b){for(var a=0;a<(Cards.size-1);a++){if(Cards[a].cardtype==b){return Cards[a]}}return null}; var availableTypes = []; @@ -83,7 +83,7 @@ }; adyen.CardTypeDetection = { - version : '0_1_9', + version : '0_1_11', getHandler : function ( cardTypeElement ) { return function ( ev ) { diff --git a/js/addOns/adyen.cardtype.min.js b/js/addOns/adyen.cardtype.min.js index 83a1656..2c18eb8 100644 --- a/js/addOns/adyen.cardtype.min.js +++ b/js/addOns/adyen.cardtype.min.js @@ -1 +1 @@ -(function(){var adyen=window.adyen=window.adyen||{},cardTypes=(function(){var Cards=new makeArray(22);Cards[0]=new CardType("mc","51,52,53,54,55","16");var MasterCard=Cards[0];Cards[1]=new CardType("visadankort","4571","16");var VisaDankort=Cards[1];Cards[2]=new CardType("visa","4","13,16");var VisaCard=Cards[2];Cards[3]=new CardType("amex","34,37","15");var AmExCard=Cards[3];Cards[4]=new CardType("vias","9","16");var AdyenCard=Cards[4];Cards[5]=new CardType("diners","36","14");var DinersClubCard=Cards[5];Cards[6]=new CardType("maestrouk","6759","16,18,19");var MaestroUKCard=Cards[6];Cards[7]=new CardType("solo","6767","16,18,19");var SoloCard=Cards[7];Cards[8]=new CardType("laser","6304,6706,677117,677120","16,17,18,19");var LaserCard=Cards[8];Cards[9]=new CardType("discover","6011,644,645,646,647,648,649,65","16");var DiscoverCard=Cards[9];Cards[10]=new CardType("jcb","3528,3529,353,354,355,356,357,358","16,19");var JCBCard=Cards[10];Cards[11]=new CardType("bcmc","6703","16,17,18,19");var Bcmc=Cards[11];Cards[12]=new CardType("bijcard","5100081","16");var BijCard=Cards[12];Cards[13]=new CardType("dankort","5019","16");var Dankort=Cards[13];Cards[14]=new CardType("hipercard","606282","16");var Hipercard=Cards[14];Cards[15]=new CardType("maestro","50,56,57,58,6","16");var MaestroCard=Cards[15];Cards[16]=new CardType("elo","506699,50670,50671,50672,50673,50674,50675,50676,506770,506771,506772,506773,506774,506775,506776,506777,506778,401178,438935,451416,457631,457632,504175,627780,636297,636368","16");var Elo=Cards[16];Cards[17]=new CardType("uatp","1","15");var Uatp=Cards[17];Cards[18]=new CardType("cup","62","14,15,16,17,18,19");var Cup=Cards[18];Cards[19]=new CardType("cartebancaire","4,5,6","16");var CarteBancaire=Cards[19];Cards[20]=new CardType("visaalphabankbonus","450903","16");var VisAlphaBankBonus=Cards[20];Cards[21]=new CardType("mcalphabankbonus","510099","16");var McAlphaBankBonus=Cards[21];var LuhnCheckSum=Cards[21]=new CardType();function CheckCardNumber(cardNumber,expYear,expMon,cardType){var tmpyear;if(cardNumber.length==0){alert("Please enter a Card Number.");return false}if(expYear.length==0){alert("Please enter the Expiration Year.");return false}if(expYear>96){tmpyear="19"+expYear}else{if(expYear<21){tmpyear="20"+expYear}else{alert("The Expiration Year is not valid.");return false}}tmpmonth=expMon;if(!(new CardType()).isExpiryDate(tmpyear,tmpmonth)){alert("This card has already expired.");return false}card=cardType;var retval=eval(card+'.checkCardNumber("'+cardNumber+'", '+tmpyear+", "+tmpmonth+");");cardname="";if(retval){return true}else{for(var n=0;n0){alert("This looks like a "+cardname+" number, not a "+card+" number.")}else{alert("This card number is not valid.")}}}function CardType(){var f;var a=CardType.arguments;var d=CardType.arguments.length;this.objname="object CardType";var c=(d>0)?a[0]:"CardObject";var e=(d>1)?a[1]:"0,1,2,3,4,5,6,7,8,9";var b=(d>2)?a[2]:"13,14,15,16,19";this.setCardNumber=setCardNumber;this.setCardType=setCardType;this.setLen=setLen;this.setRules=setRules;this.setExpiryDate=setExpiryDate;this.setCardType(c);this.setLen(b);this.setRules(e);if(d>4){this.setExpiryDate(a[3],a[4])}this.checkCardNumber=checkCardNumber;this.getExpiryDate=getExpiryDate;this.getCardType=getCardType;this.isCardNumber=isCardNumber;this.isExpiryDate=isExpiryDate;this.luhnCheck=luhnCheck;return this}function checkCardNumber(){var a=checkCardNumber.arguments;var e=checkCardNumber.arguments.length;var c=(e>0)?a[0]:this.cardnumber;var b=(e>1)?a[1]:this.year;var d=(e>2)?a[2]:this.month;this.setCardNumber(c);this.setExpiryDate(b,d);if(!this.isCardNumber()){return false}if(!this.isExpiryDate()){return false}return true}function getCardType(){return this.cardtype}function getExpiryDate(){return this.month+"/"+this.year}function isCardNumber(){var b=isCardNumber.arguments;var d=isCardNumber.arguments.length;var c=(d>0)?b[0]:this.cardnumber;if(!this.luhnCheck()){return false}for(var f=0;f0?a[0]:this.year;month=b>1?a[1]:this.month;if(!isNum(year+"")){return false}if(!isNum(month+"")){return false}today=new Date();expiry=new Date(year,month);if(today.getTime()>expiry.getTime()){return false}else{return true}}function isNum(a){a=a.toString();if(a.length==0){return false}for(var b=0;b"9"){return false}}return true}function luhnCheck(){var a=luhnCheck.arguments;var g=luhnCheck.arguments.length;var c=g>0?a[0]:this.cardnumber;if(!isNum(c)){return false}var b=c.length;var d=b&1;var e=0;for(var f=0;f9){h-=9}}e+=h}if(e%10==0){return true}else{return false}}function makeArray(a){this.size=a;return this}function setCardNumber(a){this.cardnumber=a;return this}function setCardType(a){this.cardtype=a;return this}function setExpiryDate(a,b){this.year=a;this.month=b;return this}function setLen(a){if(a.length==0||a==null){a="13,14,15,16,19"}var c=a;n=1;while(c.indexOf(",")!=-1){c=c.substring(c.indexOf(",")+1,c.length);n++}this.len=new makeArray(n);n=0;while(a.indexOf(",")!=-1){var b=a.substring(0,a.indexOf(","));this.len[n]=b;a=a.substring(a.indexOf(",")+1,a.length);n++}this.len[n]=a;return this}function setRules(c){if(c.length==0||c==null){c="0,1,2,3,4,5,6,7,8,9"}var b=c;n=1;while(b.indexOf(",")!=-1){b=b.substring(b.indexOf(",")+1,b.length);n++}this.rules=new makeArray(n);n=0;while(c.indexOf(",")!=-1){var a=c.substring(0,c.indexOf(","));this.rules[n]=a;c=c.substring(c.indexOf(",")+1,c.length);n++}this.rules[n]=c;return this}function contains(b,d){var c=b.length;while(c--){if(b[c]===d){return true}}return false}function getBaseCard(e,c){for(var d=0;d<(Cards.size-1);d++){for(var h=0;he.toString().length){b=e.toString().length}var g=e.substring(0,b);var f=Cards[d].rules[a].toString().substring(0,b);if(g===f){if(contains(c,Cards[d].cardtype)){return Cards[d]}if(contains(c,MasterCard.cardtype)){if(Cards[d].cardtype===MaestroCard.cardtype){return MasterCard}}}}}}}return null}function getBaseCardByType(b){for(var a=0;a<(Cards.size-1);a++){if(Cards[a].cardtype==b){return Cards[a]}}return null}var availableTypes=[];for(var i=Cards.size;i-->0;){availableTypes.push(Cards[i].cardtype)}Cards.determine=function(variant){return getBaseCard(variant,availableTypes)};return Cards}()),nameForType={mc:"MasterCard",visadankort:"Visa Dankort",visa:"VISA",amex:"American Express",vias:"Adyen Card",diners:"Diners Club",maestrouk:"Maestro UK",solo:"Solo",laser:"Laser",discover:"Discover",jcb:"JCB",bcmc:"Bancontact/Mister Cash",bijcard:"de Bijenkorf Card",dankort:"Dankort",hipercard:"HiperCard",maestro:"Maestro",elo:"ELO",uatp:"UATP",cup:"China Union Pay",cartebancaire:"Carte Bancaire",visaalphabankbonus:"Alpha Bank Visa Bonus",mcalphabankbonus:"Alpha Bank Mastercard Bonus"};adyen.CardTypeDetection={version:"0_1_9",getHandler:function(cardTypeElement){return function(ev){if(ev.cardTypeDetermined){return}ev.cardTypeDetermined=true;var type=null,node=ev.target||ev.srcElement,val=(node||{}).value||"";val=val.replace(/\D/g,"");if(val.length>2){type=cardTypes.determine(val)}var finalType=type&&type.cardtype||"unknown";if(typeof cardTypeElement==="function"){cardTypeElement(finalType,nameForType[finalType])}else{cardTypeElement.innerHTML=''+(nameForType[finalType]||finalType)+"";cardTypeElement.className=(cardTypeElement.className||"").replace(/(^|\s)cse-cardtype-\w+/ig,"").replace(/^\s+|\s+$/g,"")+" cse-cardtype-"+finalType}}}}}()); \ No newline at end of file +(function(){var adyen=window.adyen=window.adyen||{},cardTypes=(function(){var Cards=new makeArray(22);Cards[0]=new CardType("mc","51,52,53,54,55","16");var MasterCard=Cards[0];Cards[1]=new CardType("visadankort","4571","16");var VisaDankort=Cards[1];Cards[2]=new CardType("visa","4","13,16");var VisaCard=Cards[2];Cards[3]=new CardType("amex","34,37","15");var AmExCard=Cards[3];Cards[4]=new CardType("vias","9","16");var AdyenCard=Cards[4];Cards[5]=new CardType("diners","36","14");var DinersClubCard=Cards[5];Cards[6]=new CardType("maestrouk","6759","16,18,19");var MaestroUKCard=Cards[6];Cards[7]=new CardType("solo","6767","16,18,19");var SoloCard=Cards[7];Cards[8]=new CardType("laser","6304,6706,677117,677120","16,17,18,19");var LaserCard=Cards[8];Cards[9]=new CardType("discover","6011,644,645,646,647,648,649,65","16");var DiscoverCard=Cards[9];Cards[10]=new CardType("jcb","3528,3529,353,354,355,356,357,358","16,19");var JCBCard=Cards[10];Cards[11]=new CardType("bcmc","6703","16,17,18,19");var Bcmc=Cards[11];Cards[12]=new CardType("bijcard","5100081","16");var BijCard=Cards[12];Cards[13]=new CardType("dankort","5019","16");var Dankort=Cards[13];Cards[14]=new CardType("hipercard","606282","16");var Hipercard=Cards[14];Cards[15]=new CardType("maestro","50,56,57,58,6","16");var MaestroCard=Cards[15];Cards[16]=new CardType("elo","506699,50670,50671,50672,50673,50674,50675,50676,506770,506771,506772,506773,506774,506775,506776,506777,506778,401178,438935,451416,457631,457632,504175,627780,636297,636368","16");var Elo=Cards[16];Cards[17]=new CardType("uatp","1","15");var Uatp=Cards[17];Cards[18]=new CardType("cup","62","14,15,16,17,18,19");var Cup=Cards[18];Cards[19]=new CardType("cartebancaire","4,5,6","16");var CarteBancaire=Cards[19];Cards[20]=new CardType("visaalphabankbonus","450903","16");var VisAlphaBankBonus=Cards[20];Cards[21]=new CardType("mcalphabankbonus","510099","16");var McAlphaBankBonus=Cards[21];var LuhnCheckSum=Cards[21]=new CardType();function CheckCardNumber(cardNumber,expYear,expMon,cardType){var tmpyear;if(cardNumber.length==0){alert("Please enter a Card Number.");return false}if(expYear.length==0){alert("Please enter the Expiration Year.");return false}if(expYear>96){tmpyear="19"+expYear}else{if(expYear<21){tmpyear="20"+expYear}else{alert("The Expiration Year is not valid.");return false}}tmpmonth=expMon;if(!(new CardType()).isExpiryDate(tmpyear,tmpmonth)){alert("This card has already expired.");return false}card=cardType;var retval=eval(card+'.checkCardNumber("'+cardNumber+'", '+tmpyear+", "+tmpmonth+");");cardname="";if(retval){return true}else{for(var n=0;n0){alert("This looks like a "+cardname+" number, not a "+card+" number.")}else{alert("This card number is not valid.")}}}function CardType(){var f;var a=CardType.arguments;var d=CardType.arguments.length;this.objname="object CardType";var c=(d>0)?a[0]:"CardObject";var e=(d>1)?a[1]:"0,1,2,3,4,5,6,7,8,9";var b=(d>2)?a[2]:"13,14,15,16,19";this.setCardNumber=setCardNumber;this.setCardType=setCardType;this.setLen=setLen;this.setRules=setRules;this.setExpiryDate=setExpiryDate;this.setCardType(c);this.setLen(b);this.setRules(e);if(d>4){this.setExpiryDate(a[3],a[4])}this.checkCardNumber=checkCardNumber;this.getExpiryDate=getExpiryDate;this.getCardType=getCardType;this.isCardNumber=isCardNumber;this.isExpiryDate=isExpiryDate;this.luhnCheck=luhnCheck;return this}function checkCardNumber(){var a=checkCardNumber.arguments;var e=checkCardNumber.arguments.length;var c=(e>0)?a[0]:this.cardnumber;var b=(e>1)?a[1]:this.year;var d=(e>2)?a[2]:this.month;this.setCardNumber(c);this.setExpiryDate(b,d);if(!this.isCardNumber()){return false}if(!this.isExpiryDate()){return false}return true}function getCardType(){return this.cardtype}function getExpiryDate(){return this.month+"/"+this.year}function isCardNumber(){var b=isCardNumber.arguments;var d=isCardNumber.arguments.length;var c=(d>0)?b[0]:this.cardnumber;if(!this.luhnCheck()){return false}for(var f=0;f0?a[0]:this.year;month=b>1?a[1]:this.month;if(!isNum(year+"")){return false}if(!isNum(month+"")){return false}today=new Date();expiry=new Date(year,month);if(today.getTime()>expiry.getTime()){return false}else{return true}}function isNum(a){a=a.toString();if(a.length==0){return false}for(var b=0;b"9"){return false}}return true}function luhnCheck(){var a=luhnCheck.arguments;var g=luhnCheck.arguments.length;var c=g>0?a[0]:this.cardnumber;if(!isNum(c)){return false}var b=c.length;var d=b&1;var e=0;for(var f=0;f9){h-=9}}e+=h}if(e%10==0){return true}else{return false}}function makeArray(a){this.size=a;return this}function setCardNumber(a){this.cardnumber=a;return this}function setCardType(a){this.cardtype=a;return this}function setExpiryDate(a,b){this.year=a;this.month=b;return this}function setLen(a){if(a.length==0||a==null){a="13,14,15,16,19"}var c=a;n=1;while(c.indexOf(",")!=-1){c=c.substring(c.indexOf(",")+1,c.length);n++}this.len=new makeArray(n);n=0;while(a.indexOf(",")!=-1){var b=a.substring(0,a.indexOf(","));this.len[n]=b;a=a.substring(a.indexOf(",")+1,a.length);n++}this.len[n]=a;return this}function setRules(c){if(c.length==0||c==null){c="0,1,2,3,4,5,6,7,8,9"}var b=c;n=1;while(b.indexOf(",")!=-1){b=b.substring(b.indexOf(",")+1,b.length);n++}this.rules=new makeArray(n);n=0;while(c.indexOf(",")!=-1){var a=c.substring(0,c.indexOf(","));this.rules[n]=a;c=c.substring(c.indexOf(",")+1,c.length);n++}this.rules[n]=c;return this}function contains(b,d){var c=b.length;while(c--){if(b[c]===d){return true}}return false}function getBaseCard(e,c){for(var d=0;d<(Cards.size-1);d++){for(var h=0;he.toString().length){b=e.toString().length}var g=e.substring(0,b);var f=Cards[d].rules[a].toString().substring(0,b);if(g===f){if(contains(c,Cards[d].cardtype)){return Cards[d]}if(contains(c,MasterCard.cardtype)){if(Cards[d].cardtype===MaestroCard.cardtype){return MasterCard}}}}}}}return null}function getBaseCardByType(b){for(var a=0;a<(Cards.size-1);a++){if(Cards[a].cardtype==b){return Cards[a]}}return null}var availableTypes=[];for(var i=Cards.size;i-->0;){availableTypes.push(Cards[i].cardtype)}Cards.determine=function(variant){return getBaseCard(variant,availableTypes)};return Cards}()),nameForType={mc:"MasterCard",visadankort:"Visa Dankort",visa:"VISA",amex:"American Express",vias:"Adyen Card",diners:"Diners Club",maestrouk:"Maestro UK",solo:"Solo",laser:"Laser",discover:"Discover",jcb:"JCB",bcmc:"Bancontact/Mister Cash",bijcard:"de Bijenkorf Card",dankort:"Dankort",hipercard:"HiperCard",maestro:"Maestro",elo:"ELO",uatp:"UATP",cup:"China Union Pay",cartebancaire:"Carte Bancaire",visaalphabankbonus:"Alpha Bank Visa Bonus",mcalphabankbonus:"Alpha Bank Mastercard Bonus"};adyen.CardTypeDetection={version:"0_1_11",getHandler:function(cardTypeElement){return function(ev){if(ev.cardTypeDetermined){return}ev.cardTypeDetermined=true;var type=null,node=ev.target||ev.srcElement,val=(node||{}).value||"";val=val.replace(/\D/g,"");if(val.length>2){type=cardTypes.determine(val)}var finalType=type&&type.cardtype||"unknown";if(typeof cardTypeElement==="function"){cardTypeElement(finalType,nameForType[finalType])}else{cardTypeElement.innerHTML=''+(nameForType[finalType]||finalType)+"";cardTypeElement.className=(cardTypeElement.className||"").replace(/(^|\s)cse-cardtype-\w+/ig,"").replace(/^\s+|\s+$/g,"")+" cse-cardtype-"+finalType}}}}}()); \ No newline at end of file diff --git a/js/adyen.encrypt.js b/js/adyen.encrypt.js index d647779..7d290fa 100644 --- a/js/adyen.encrypt.js +++ b/js/adyen.encrypt.js @@ -7,7 +7,7 @@ * * Stanford Javascript Crypto Library | http://crypto.stanford.edu/sjcl/ * * JSON in JavaScript | http://www.JSON.org/ * - * Version: 0_1_10 + * Version: 0_1_11 * Author: ADYEN (c) 2014 @@ -18,6 +18,7 @@ +
Card Details @@ -56,12 +57,16 @@
+ - - + + @@ -114,43 +128,61 @@ * */ -( function () { +( function (root, fnDefine) { + + // Prevent libraries to die on AMD patterns + var define, exports; /* typedarray.js */ - (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,b=((k&3)<<4)|(j>>4);var m=f+1>6):64;var l=f+2>2,b=((k&3)<<4)|(j>>4);var m=f+1>6):64;var l=f+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>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);/* */ + var dbits;var canary=244837814094590;var j_lm=((canary&16777215)==15715070);function BigInteger(e,d,f){if(e!=null){if("number"==typeof e){this.fromNumber(e,d,f)}else{if(d==null&&"string"!=typeof e){this.fromString(e,256)}else{this.fromString(e,d)}}}}function nbi(){return new BigInteger(null)}function am1(f,a,b,e,h,g){while(--g>=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); /* prng4.js */ - 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;/* */ + 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; /* rng.js */ - 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>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;/* */ + function parseBigInt(b,a){return new BigInteger(b,a)}function pkcs1pad2(c,g){if(g=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; /* sjcl.js */ - "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);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]<<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);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>>24);e<<=8}return d};b.toBits=b.toBits||function(c){var d=[],f,e=0;for(f=0;f= 14) { + evLog('luhnCount'); + } for ( var count = 0; count < no_digit; count++ ) { var digit = parseInt( CardNumber.charAt( count ), 10 ); @@ -290,17 +326,195 @@ }; validations.cvcCheck = function ( val ) { - return val && val.match && val.match( /^\d{3,4}$/ ); + return (val && val.match && val.match( /^\d{3,4}$/ )) ? true : false; }; validations.yearCheck = function ( val ) { - return val && val.match && val.match( /^\d{4}$/ ); + return (val && val.match && val.match( /^\d{4}$/ )) ? true : false; }; validations.monthCheck = function ( val ) { - return val && val.match && val.match( /^\d{2}$/ ) && parseInt( val, 10 ) >= 1 && parseInt( val, 10 ) <= 12; + return (val && val.match && val.match( /^\d{2}$/ ) && parseInt( val, 10 ) >= 1 && parseInt( val, 10 ) <= 12) ? true : false; + }; + + var Encryption = function ( key, options ) { + try { + sjcl.random.startCollectors(); + } catch ( e ) { + // what to do? + } + + this.key = key; + + this.options = options || {}; + + // Defaults + if ( typeof this.options.numberIgnoreNonNumeric === "undefined" ) { + this.options.numberIgnoreNonNumeric = true; + } + + if ( typeof this.options.cvcIgnoreFornumber !== "undefined" ) { + delete this.options.cvcIgnoreFornumber; + } + + 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.ignoreCvcBins !== "undefined" ) { + delete this.options.ignoreCvcBins; + } + + evLog("initializeCount"); + }; + + /* + * Creates an RSA key based on the public key. + * + * @returns rsa {RSAKey} An RSAKey based on the public key provided. + * + */ + 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 ]; + + // would be better to put it in a package. + var rsa = new RSAKey(); + rsa.setPublic( mod, exp ); + + return rsa; + + } + + /* + * Creates an AES key. + * + * @returns aes {Object} An AESKey with encryption methods. + * + */ + Encryption.prototype.createAESKey = function () { + return new AESKey(); + }; + + /* + * Encrypts data + * + * @return data {String} The data in the form as encrypted and serialized + * JSON. + * + */ + + Encryption.prototype.encrypt = function ( data ) { + + var rsa, aes, cipher, keybytes, encrypted, prefix, validationObject = { + number : data.number, + cvc : data.cvc, + month: data.expiryMonth, + year : data.expiryYear + }; + + if ( this.options.enableValidations !== false && this.validate(validationObject).valid === false) { + + return false; + + } + + 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" ) { + for ( var field in data ) { + if ( data.hasOwnProperty( field ) ) { + + var val = data[ field ]; + + if ( this.options[ field + 'IgnoreNonNumeric' ] ) { + val = val.replace( /\D/g, '' ); + } + + var shouldIgnore = false; + + for ( var relatedField in data ) { + if ( data.hasOwnProperty(relatedField) ) { + + var possibleOption = this.options[field + 'IgnoreFor' + relatedField] ; + + if ( possibleOption && val && data[relatedField].match(possibleOption)) { + shouldIgnore = true; + } + } + } + + if (shouldIgnore) { + result[field] = true; + result.valid = result.valid && result[field]; + continue; + } + + switch ( field ) { + case 'number': + result.number = validations.luhnCheck( val ); + result.valid = result.valid && result.number; + break; + case 'year': + result.year = validations.yearCheck( val ); + result.valid = result.valid && result.year; + break; + case 'cvc': + result.cvc = validations.cvcCheck( val ); + result.valid = result.valid && result.cvc; + break; + case 'month': + result.month = validations.monthCheck( val ); + result.valid = result.valid && result.month; + break; + default: + result.unknown = result.unknown || []; + result.unknown.push( field ); + result.valid = false; + } + + } + } + } else { + result.valid = false; + } + + return result; }; + validations.createChangeHandler = function ( cse, type, allowEmpty ) { return function ( ev ) { var node = ev.target || ev.srcElement, val = ( node || {} ).value || '', field = getAttribute( node, 'data-encrypted-name' ); @@ -336,6 +550,8 @@ }; }; + var DEFAULT_FIELDNAME_ATTRIBUTE = "data-encrypted-name"; + /* * @constructor EncryptedForm * @@ -346,17 +562,9 @@ * * @return form {EncryptedForm} The instance of EncryptedForm. * - */ - - var DEFAULT_FIELDNAME_ATTRIBUTE = "data-encrypted-name"; + */ - var EncryptedForm = /* encrypt.EncryptedForm = */function ( element, key, options ) { - - try { - sjcl.random.startCollectors(); - } catch ( e ) { - // what to do? - } + var EncryptedForm = function ( element, key, options ) { if ( typeof element !== 'object' || typeof element.ownerDocument !== 'object' ) { @@ -371,21 +579,24 @@ this.element = element; this.key = key; this.validity = {}; - + + // event logging + evLog("initializeFormCount"); + // create an empty object if options don't exist this.options = options = options || {}; if ( typeof options !== 'object' ) { throw new Error( 'Expected options to be an object' ); } - + // Defaults if ( typeof options.numberIgnoreNonNumeric === "undefined" ) { options.numberIgnoreNonNumeric = true; } - + // Validate the custom data field name - if ( typeof options.fieldNameAttribute !== 'string' || !options.fieldNameAttribute.match(/^data(-\w+)+$/i)) { + if ( typeof options.fieldNameAttribute !== 'string' || !options.fieldNameAttribute.match( /^data(-\w+)+$/i ) ) { options.fieldNameAttribute = DEFAULT_FIELDNAME_ATTRIBUTE; } @@ -394,6 +605,10 @@ this.onsubmit = options.onsubmit || function () { }; + // Boot encrypion object + this.encryption = new Encryption( key, options ); + + // Binding if ( this.element.addEventListener ) { this.element.addEventListener( 'submit', this.handleSubmit.bind( this ), false ); } else if ( this.element.attachEvent ) { @@ -403,6 +618,17 @@ if ( options.enableValidations !== false ) { this.addValidations(); } + + for (var i = 0, c = element.elements.length; i < c; i++) { + if (!element.elements[i]) { + continue; + } + var attr = getAttribute(element.elements[i], this.options.fieldNameAttribute); + if (typeof attr !== 'undefined' && attr !== null && attr !== '' ) { + evLog('bind', element.elements[i], attr); + } + } + }; @@ -460,43 +686,6 @@ this.onsubmit( e ); }, - /* - * Creates an RSA key based on the public key. - * - * @returns rsa {RSAKey} An RSAKey based on the public key provided. - * - */ - - createRSAKey : function () { - - var k = this.key.split( '|' ); - - if ( k.length != 2 ) { - throw 'Malformed public key'; - } - - var exp = k[ 0 ]; - var mod = k[ 1 ]; - - // would be better to put it in a package. - var rsa = new RSAKey(); - rsa.setPublic( mod, exp ); - - return rsa; - - }, - - /* - * Creates an AES key. - * - * @returns aes {Object} An AESKey with encryption methods. - * - */ - - createAESKey : function () { - return new AESKey(); - }, - /* * Gets all encrypted fields from a root node ( usually the form element ). * @@ -511,7 +700,7 @@ */ getEncryptedFields : function ( node, fields ) { - + if ( node.querySelectorAll ) { return node.querySelectorAll( '[' + this.fieldNameAttribute + ']' ); } @@ -544,7 +733,6 @@ * @return data {JSON} The data as JavaScript Object Notation * */ - toJSON : function ( fields ) { var field, data = {}, key, value; @@ -556,10 +744,10 @@ field.removeAttribute( 'name' ); key = field.getAttribute( this.fieldNameAttribute ); value = field.value; - + // Cater for select boxes - if (field.options && typeof field.selectedIndex !== "undefined") { - value = field.options[field.selectedIndex].value; + if ( field.options && typeof field.selectedIndex !== "undefined" ) { + value = field.options[ field.selectedIndex ].value; } data[ key ] = value; @@ -580,19 +768,7 @@ encrypt : function () { - var data = this.toJSON( this.getEncryptedFields( this.element ) ); - - var rsa, aes, cipher, keybytes, encrypted, prefix; - - 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( '' ); + return this.encryption.encrypt( this.toJSON( this.getEncryptedFields( this.element ) ) ); }, @@ -656,13 +832,13 @@ } }, - 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"); + 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 updateCardTypeDetection = adyen.CardTypeDetection.getHandler( cardTypeElement ); var cse = this, elements = this.element.elements, c = elements.length, element, handlers = {}; @@ -708,9 +884,14 @@ return valid; + }, + + getVersion : function () { + return encrypt.version; } }; + /* * @@ -751,4 +932,4 @@ }; -} )(); \ No newline at end of file +} )(this, typeof define === "function" ? define : null); \ No newline at end of file diff --git a/js/adyen.encrypt.min.js b/js/adyen.encrypt.min.js index a55ce24..d364db5 100644 --- a/js/adyen.encrypt.min.js +++ b/js/adyen.encrypt.min.js @@ -7,9 +7,9 @@ * * Stanford Javascript Crypto Library | http://crypto.stanford.edu/sjcl/ * * JSON in JavaScript | http://www.JSON.org/ * - * Version: 0_1_10 + * Version: 0_1_11 * Author: ADYEN (c) 2014 */ -(function(){(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,b=((k&3)<<4)|(j>>4);var m=f+1>6):64;var l=f+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);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=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_10";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 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;for(var count=0;count9){digit-=9}}sum+=digit}if(sum%10===0){return true}else{return false}};validations.cvcCheck=function(val){return val&&val.match&&val.match(/^\d{3,4}$/)};validations.yearCheck=function(val){return val&&val.match&&val.match(/^\d{4}$/)};validations.monthCheck=function(val){return val&&val.match&&val.match(/^\d{2}$/)&&parseInt(val,10)>=1&&parseInt(val,10)<=12};validations.createChangeHandler=function(cse,type,allowEmpty){return function(ev){var node=ev.target||ev.srcElement,val=(node||{}).value||"",field=getAttribute(node,"data-encrypted-name");if(node.options&&typeof node.selectedIndex!=="undefined"){val=node.options[node.selectedIndex].value}if(cse.options[field+"IgnoreNonNumeric"]){val=val.replace(/\D/g,"")}if(validations[type+"Check"](val)){cse.validity[type]=true;removeClass(node,"invalid-"+type);addClass(node,"valid-"+type)}else{cse.validity[type]=false;addClass(node,"invalid-"+type);removeClass(node,"valid-"+type)}if(allowEmpty&&val===""){removeClass(node,"valid-"+type);removeClass(node,"invalid-"+type)}if((node.className||"").match(/invalid-/)){addClass(node,"invalid")}else{removeClass(node,"invalid")}cse.toggleSubmit()}};var DEFAULT_FIELDNAME_ATTRIBUTE="data-encrypted-name";var EncryptedForm=function(element,key,options){try{sjcl.random.startCollectors()}catch(e){}if(typeof element!=="object"||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={};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}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(){};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()}};EncryptedForm.prototype={constructor:EncryptedForm,hasAttribute:document.documentElement.hasAttribute?function(node,attrName){return node.hasAttribute(attrName)}:function(node,attrName){return node.attributes&&node.attributes[attrName]},handleSubmit:function(e){if(this.options.enableValidations!==false){if(!this.isValid()){if(e.preventDefault){e.preventDefault()}if(window.event){window.event.returnValue=false}if(e.originalEvent){e.originalEvent.returnValue=false}e.returnValue=false;return false}}this.createEncryptedField(this.encrypt());this.onsubmit(e)},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},createAESKey:function(){return new AESKey()},getEncryptedFields:function(node,fields){if(node.querySelectorAll){return node.querySelectorAll("["+this.fieldNameAttribute+"]")}fields=fields||[];var children=node.children;var child;for(var i=0;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(){var data=this.toJSON(this.getEncryptedFields(this.element));var rsa,aes,cipher,keybytes,encrypted,prefix;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("")},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={}; -for(;c-->0;){element=elements[c];if(!element||!element.getAttribute){continue}else{if(element.getAttribute(this.fieldNameAttribute)==="number"){handlers.luhnHandler=handlers.luhnHandler||validations.createChangeHandler(cse,"luhn",true);addEvent(element,"change",handlers.luhnHandler,false);handlers.luhnHandler({target:element})}else{if(element.getAttribute(this.fieldNameAttribute)==="cvc"){handlers.cvcHandler=handlers.cvcHandler||validations.createChangeHandler(cse,"cvc",true);addEvent(element,"change",handlers.cvcHandler,false);handlers.cvcHandler({target:element})}else{if(element.getAttribute(this.fieldNameAttribute)==="expiryYear"){handlers.expiryYearHandler=handlers.expiryYearHandler||validations.createChangeHandler(cse,"year",true);addEvent(element,"change",handlers.expiryYearHandler,false);handlers.expiryYearHandler({target:element})}else{if(element.getAttribute(this.fieldNameAttribute)==="expiryMonth"){handlers.expiryMonthHandler=handlers.expiryMonthHandler||validations.createChangeHandler(cse,"month",true);addEvent(element,"change",handlers.expiryMonthHandler,false);handlers.expiryMonthHandler({target:element})}}}}}}},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})}}}},isValid:function(){var valid=true,elements=this.element.elements,enabled;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}}return valid}};var AESKey=function(){};AESKey.prototype={constructor:AESKey,key:sjcl.random.randomWords(8,0),encrypt:function(text){return this.encryptWithIv(text,sjcl.random.randomWords(3,0))},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)}}})(); \ No newline at end of file +(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,b=((k&3)<<4)|(j>>4);var m=f+1>6):64;var l=f+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);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=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_11";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 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(no_digit>=14){evLog("luhnCount")}for(var count=0;count9){digit-=9}}sum+=digit}if(sum%10===0){return true}else{return false}};validations.cvcCheck=function(val){return(val&&val.match&&val.match(/^\d{3,4}$/))?true:false};validations.yearCheck=function(val){return(val&&val.match&&val.match(/^\d{4}$/))?true:false};validations.monthCheck=function(val){return(val&&val.match&&val.match(/^\d{2}$/)&&parseInt(val,10)>=1&&parseInt(val,10)<=12)?true:false};var Encryption=function(key,options){try{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.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.ignoreCvcBins!=="undefined"){delete this.options.ignoreCvcBins}}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(data){var rsa,aes,cipher,keybytes,encrypted,prefix,validationObject={number:data.number,cvc:data.cvc,month:data.expiryMonth,year:data.expiryYear};if(this.options.enableValidations!==false&&this.validate(validationObject).valid===false){return false}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"){for(var field in data){if(data.hasOwnProperty(field)){var val=data[field];if(this.options[field+"IgnoreNonNumeric"]){val=val.replace(/\D/g,"")}var shouldIgnore=false;for(var relatedField in data){if(data.hasOwnProperty(relatedField)){var possibleOption=this.options[field+"IgnoreFor"+relatedField];if(possibleOption&&val&&data[relatedField].match(possibleOption)){shouldIgnore=true}}}if(shouldIgnore){result[field]=true;result.valid=result.valid&&result[field];continue}switch(field){case"number":result.number=validations.luhnCheck(val);result.valid=result.valid&&result.number;break;case"year":result.year=validations.yearCheck(val);result.valid=result.valid&&result.year;break;case"cvc":result.cvc=validations.cvcCheck(val);result.valid=result.valid&&result.cvc;break;case"month":result.month=validations.monthCheck(val);result.valid=result.valid&&result.month;break;default:result.unknown=result.unknown||[];result.unknown.push(field);result.valid=false}}}}else{result.valid=false}return result};validations.createChangeHandler=function(cse,type,allowEmpty){return function(ev){var node=ev.target||ev.srcElement,val=(node||{}).value||"",field=getAttribute(node,"data-encrypted-name");if(node.options&&typeof node.selectedIndex!=="undefined"){val=node.options[node.selectedIndex].value}if(cse.options[field+"IgnoreNonNumeric"]){val=val.replace(/\D/g,"")}if(validations[type+"Check"](val)){cse.validity[type]=true;removeClass(node,"invalid-"+type); +addClass(node,"valid-"+type)}else{cse.validity[type]=false;addClass(node,"invalid-"+type);removeClass(node,"valid-"+type)}if(allowEmpty&&val===""){removeClass(node,"valid-"+type);removeClass(node,"invalid-"+type)}if((node.className||"").match(/invalid-/)){addClass(node,"invalid")}else{removeClass(node,"invalid")}cse.toggleSubmit()}};var DEFAULT_FIELDNAME_ATTRIBUTE="data-encrypted-name";var EncryptedForm=function(element,key,options){if(typeof element!=="object"||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}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={};for(;c-->0;){element=elements[c];if(!element||!element.getAttribute){continue}else{if(element.getAttribute(this.fieldNameAttribute)==="number"){handlers.luhnHandler=handlers.luhnHandler||validations.createChangeHandler(cse,"luhn",true);addEvent(element,"change",handlers.luhnHandler,false);handlers.luhnHandler({target:element})}else{if(element.getAttribute(this.fieldNameAttribute)==="cvc"){handlers.cvcHandler=handlers.cvcHandler||validations.createChangeHandler(cse,"cvc",true);addEvent(element,"change",handlers.cvcHandler,false);handlers.cvcHandler({target:element})}else{if(element.getAttribute(this.fieldNameAttribute)==="expiryYear"){handlers.expiryYearHandler=handlers.expiryYearHandler||validations.createChangeHandler(cse,"year",true);addEvent(element,"change",handlers.expiryYearHandler,false);handlers.expiryYearHandler({target:element})}else{if(element.getAttribute(this.fieldNameAttribute)==="expiryMonth"){handlers.expiryMonthHandler=handlers.expiryMonthHandler||validations.createChangeHandler(cse,"month",true);addEvent(element,"change",handlers.expiryMonthHandler,false);handlers.expiryMonthHandler({target:element})}}}}}}},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})}}}},isValid:function(){var valid=true,elements=this.element.elements,enabled;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}}return valid},getVersion:function(){return encrypt.version}};var AESKey=function(){};AESKey.prototype={constructor:AESKey,key:sjcl.random.randomWords(8,0),encrypt:function(text){return this.encryptWithIv(text,sjcl.random.randomWords(3,0))},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); \ No newline at end of file diff --git a/js/adyen.encrypt.nodom.js b/js/adyen.encrypt.nodom.js new file mode 100644 index 0000000..67b1b6f --- /dev/null +++ b/js/adyen.encrypt.nodom.js @@ -0,0 +1,450 @@ +/* + * + * Client Encryption of Forms. + * + * Includes: + * * RSA and ECC in JavaScript | http://www-cs-students.stanford.edu/~tjw/jsbn/ + * * Stanford Javascript Crypto Library | http://crypto.stanford.edu/sjcl/ + * * JSON in JavaScript | http://www.JSON.org/ + * + * Version: 0_1_11 + * Author: ADYEN (c) 2014 + + + + + Example Payment Form + + + + + +
+ + +
+ + + + + + + + + + + * + */ + +( function (root, fnDefine) { + + // Prevent libraries to die on AMD patterns + var define, exports; + + /* typedarray.js */ + (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,b=((k&3)<<4)|(j>>4);var m=f+1>6):64;var l=f+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); + + /* prng4.js */ + 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; + + /* rng.js */ + 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; + + /* sjcl.js */ + "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);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 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 (no_digit >= 14) { + evLog('luhnCount'); + } + + for ( var count = 0; count < no_digit; count++ ) { + var digit = parseInt( CardNumber.charAt( count ), 10 ); + if ( ! ( ( count & 1 ) ^ oddoeven ) ) { + digit *= 2; + if ( digit > 9 ) + digit -= 9; + } + sum += digit; + } + + if ( sum % 10 === 0 ) { + return true; + } else { + return false; + } + }; + + validations.cvcCheck = function ( val ) { + return (val && val.match && val.match( /^\d{3,4}$/ )) ? true : false; + }; + + validations.yearCheck = function ( val ) { + return (val && val.match && val.match( /^\d{4}$/ )) ? true : false; + }; + + validations.monthCheck = function ( val ) { + return (val && val.match && val.match( /^\d{2}$/ ) && parseInt( val, 10 ) >= 1 && parseInt( val, 10 ) <= 12) ? true : false; + }; + + var Encryption = function ( key, options ) { + try { + sjcl.random.startCollectors(); + } catch ( e ) { + // what to do? + } + + this.key = key; + + this.options = options || {}; + + // Defaults + if ( typeof this.options.numberIgnoreNonNumeric === "undefined" ) { + this.options.numberIgnoreNonNumeric = true; + } + + if ( typeof this.options.cvcIgnoreFornumber !== "undefined" ) { + delete this.options.cvcIgnoreFornumber; + } + + 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.ignoreCvcBins !== "undefined" ) { + delete this.options.ignoreCvcBins; + } + + evLog("initializeCount"); + }; + + /* + * Creates an RSA key based on the public key. + * + * @returns rsa {RSAKey} An RSAKey based on the public key provided. + * + */ + 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 ]; + + // would be better to put it in a package. + var rsa = new RSAKey(); + rsa.setPublic( mod, exp ); + + return rsa; + + } + + /* + * Creates an AES key. + * + * @returns aes {Object} An AESKey with encryption methods. + * + */ + Encryption.prototype.createAESKey = function () { + return new AESKey(); + }; + + /* + * Encrypts data + * + * @return data {String} The data in the form as encrypted and serialized + * JSON. + * + */ + + Encryption.prototype.encrypt = function ( data ) { + + var rsa, aes, cipher, keybytes, encrypted, prefix, validationObject = { + number : data.number, + cvc : data.cvc, + month: data.expiryMonth, + year : data.expiryYear + }; + + if ( this.options.enableValidations !== false && this.validate(validationObject).valid === false) { + + return false; + + } + + 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" ) { + for ( var field in data ) { + if ( data.hasOwnProperty( field ) ) { + + var val = data[ field ]; + + if ( this.options[ field + 'IgnoreNonNumeric' ] ) { + val = val.replace( /\D/g, '' ); + } + + var shouldIgnore = false; + + for ( var relatedField in data ) { + if ( data.hasOwnProperty(relatedField) ) { + + var possibleOption = this.options[field + 'IgnoreFor' + relatedField] ; + + if ( possibleOption && val && data[relatedField].match(possibleOption)) { + shouldIgnore = true; + } + } + } + + if (shouldIgnore) { + result[field] = true; + result.valid = result.valid && result[field]; + continue; + } + + switch ( field ) { + case 'number': + result.number = validations.luhnCheck( val ); + result.valid = result.valid && result.number; + break; + case 'year': + result.year = validations.yearCheck( val ); + result.valid = result.valid && result.year; + break; + case 'cvc': + result.cvc = validations.cvcCheck( val ); + result.valid = result.valid && result.cvc; + break; + case 'month': + result.month = validations.monthCheck( val ); + result.valid = result.valid && result.month; + break; + default: + result.unknown = result.unknown || []; + result.unknown.push( field ); + result.valid = false; + } + + } + } + } else { + result.valid = false; + } + + return result; + }; + + + + /* + * + * @constructor AESKey + * + * @return aes {AESKey} An AESKey with encryption methods. + * + */ + + var AESKey = function () { + // empty constructor + }; + + AESKey.prototype = { + + constructor : AESKey, + + key : sjcl.random.randomWords( 8, 0 ), + + encrypt : function ( text ) { + + return this.encryptWithIv( text, sjcl.random.randomWords( 3, 0 ) ); + + }, + + 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); \ No newline at end of file diff --git a/js/adyen.encrypt.nodom.min.js b/js/adyen.encrypt.nodom.min.js new file mode 100644 index 0000000..08f0085 --- /dev/null +++ b/js/adyen.encrypt.nodom.min.js @@ -0,0 +1,14 @@ +/* + * + * Client Encryption of Forms. + * + * Includes: + * * RSA and ECC in JavaScript | http://www-cs-students.stanford.edu/~tjw/jsbn/ + * * Stanford Javascript Crypto Library | http://crypto.stanford.edu/sjcl/ + * * JSON in JavaScript | http://www.JSON.org/ + * + * Version: 0_1_11 + * Author: ADYEN (c) 2014 + */ +(function(bc,av){var aw,ao;(function(){try{var e=[new Uint8Array(1),new Uint32Array(1),new Int32Array(1)];return}catch(q){}function t(A,z){return this.slice(A,z)}function y(A,C){if(arguments.length<2){C=0}for(var z=0,B=A.length;z>2,F=((u&3)<<4)|(y>>4);var q=B+1>6):64;var t=B+2>6)+aU.charAt(u&63)}if(q+1==y.length){u=parseInt(y.substring(q,q+1),16);t+=aU.charAt(u<<2)}else{if(q+2==y.length){u=parseInt(y.substring(q,q+2),16);t+=aU.charAt(u>>2)+aU.charAt((u&3)<<4)}}while((t.length&3)>0){t+=aP}return t}function d(u){var z="";var y;var t=0;var q;for(y=0;y>2);q=v&3;t=1}else{if(t==1){z+=bo((q<<2)|(v>>4));q=v&15;t=2}else{if(t==2){z+=bo(q);z+=bo(v>>2);q=v&3;t=3}else{z+=bo((q<<2)|(v>>4));z+=bo(v&15);t=0}}}}if(t==1){z+=bo(q<<2)}return z}function aH(t){var u=d(t);var y;var q=new Array();for(y=0;2*y=0){var B=t*this[z++]+q[A]+u;u=Math.floor(B/67108864);q[A++]=B&67108863}return u}function bn(C,u,t,D,z,G){var A=u&32767,y=u>>15;while(--G>=0){var E=this[C]&32767;var B=this[C++]>>15;var F=y*E+B*A;E=A*E+((F&32767)<<15)+t[D]+(z&1073741823);z=(E>>>30)+(F>>>15)+y*B+(z>>>30);t[D++]=E&1073741823}return z}function bm(C,u,t,D,z,G){var A=u&16383,y=u>>14;while(--G>=0){var E=this[C]&16383;var B=this[C++]>>14;var F=y*E+B*A;E=A*E+((F&16383)<<14)+t[D]+z;z=(E>>28)+(F>>14)+y*B;t[D++]=E&268435455}return z}if(aT&&(navigator.appName=="Microsoft Internet Explorer")){bg.prototype.am=bn;bk=30}else{if(aT&&(navigator.appName!="Netscape")){bg.prototype.am=c;bk=26}else{bg.prototype.am=bm;bk=28}}bg.prototype.DB=bk;bg.prototype.DM=((1<=0;--q){e[q]=this[q]}e.t=this.t;e.s=this.s}function x(e){this.t=1;this.s=(e<0)?-1:0;if(e>0){this[0]=e}else{if(e<-1){this[0]=e+this.DV}else{this.t=0}}}function f(q){var e=m();e.fromInt(q);return e}function T(t,B){var z;if(B==16){z=4}else{if(B==8){z=3}else{if(B==256){z=8}else{if(B==2){z=1}else{if(B==32){z=5}else{if(B==4){z=2}else{this.fromRadix(t,B);return}}}}}}this.t=0;this.s=0;var u=t.length,A=false,y=0;while(--u>=0){var q=(z==8)?t[u]&255:W(t,u);if(q<0){if(t.charAt(u)=="-"){A=true}continue}A=false;if(y==0){this[this.t++]=q}else{if(y+z>this.DB){this[this.t-1]|=(q&((1<<(this.DB-y))-1))<>(this.DB-y))}else{this[this.t-1]|=q<=this.DB){y-=this.DB}}if(z==8&&(t[0]&128)!=0){this.s=-1;if(y>0){this[this.t-1]|=((1<<(this.DB-y))-1)<0&&this[this.t-1]==e){--this.t}}function P(C){if(this.s<0){return"-"+this.negate().toString(C)}var B;if(C==16){B=4}else{if(C==8){B=3}else{if(C==2){B=1}else{if(C==32){B=5}else{if(C==4){B=2}else{return this.toRadix(C)}}}}}var z=(1<0){if(u>u)>0){q=true;y=bo(t)}while(A>=0){if(u>(u+=this.DB-B)}else{t=(this[A]>>(u-=B))&z;if(u<=0){u+=this.DB;--A}}if(t>0){q=true}if(q){y+=bo(t)}}}return q?y:"0"}function at(){var e=m();bg.ZERO.subTo(this,e);return e}function a9(){return(this.s<0)?this.negate():this}function ad(e){var q=this.s-e.s;if(q!=0){return q}var t=this.t;q=t-e.t;if(q!=0){return(this.s<0)?-q:q}while(--t>=0){if((q=this[t]-e[t])!=0){return q}}return 0}function o(q){var t=1,e;if((e=q>>>16)!=0){q=e;t+=16}if((e=q>>8)!=0){q=e;t+=8}if((e=q>>4)!=0){q=e;t+=4}if((e=q>>2)!=0){q=e;t+=2}if((e=q>>1)!=0){q=e;t+=1}return t}function R(){if(this.t<=0){return 0}return this.DB*(this.t-1)+o(this[this.t-1]^(this.s&this.DM))}function bf(t,e){var q;for(q=this.t-1;q>=0;--q){e[q+t]=this[q]}for(q=t-1;q>=0;--q){e[q]=0}e.t=this.t+t;e.s=this.s}function aR(t,e){for(var q=t;q=0;--C){B[C+A+1]=(this[C]>>t)|y;y=(this[C]&z)<=0;--C){B[C]=0}B[A]=y;B.t=this.t+A+1;B.s=this.s;B.clamp()}function s(u,A){A.s=this.s;var z=Math.floor(u/this.DB);if(z>=this.t){A.t=0;return}var q=u%this.DB;var t=this.DB-q;var y=(1<>q;for(var B=z+1;B>q}if(q>0){A[this.t-z-1]|=(this.s&y)<>=this.DB}if(z.t>=this.DB}t+=this.s}else{t+=this.s;while(y>=this.DB}t-=z.s}u.s=(t<0)?-1:0;if(t<-1){u[y++]=this.DV+t}else{if(t>0){u[y++]=t}}u.t=y;u.clamp()}function Z(z,u){var q=this.abs(),t=z.abs();var y=q.t;u.t=y+t.t;while(--y>=0){u[y]=0}for(y=0;y=0){y[q]=0}for(q=0;q=t.DV){y[q+t.t]-=t.DV;y[q+t.t+1]=1}}if(y.t>0){y[y.t-1]+=t.am(q,t[q],y,2*q,0,1)}y.s=0;y.clamp()}function aa(G,J,K){var t=G.abs();if(t.t<=0){return}var I=this.abs();if(I.t0){t.lShiftTo(y,M);I.lShiftTo(y,K)}else{t.copyTo(M);I.copyTo(K)}var E=M.t;var bq=M[E-1];if(bq==0){return}var F=bq*(1<1)?M[E-2]>>this.F2:0);var D=this.FV/F,e=(1<=0){K[K.t++]=1;K.subTo(L,K)}bg.ONE.dlShiftTo(E,L);L.subTo(M,M);while(M.t=0){var bp=(K[--B]==bq)?this.DM:Math.floor(K[B]*D+(K[B-1]+q)*e);if((K[B]+=M.am(0,bp,K,C,0,E))0){K.rShiftTo(y,K)}if(br<0){bg.ZERO.subTo(K,K)}}function am(e){var q=m();this.abs().divRemTo(e,null,q);if(this.s<0&&q.compareTo(bg.ZERO)>0){e.subTo(q,q)}return q}function aj(e){this.m=e}function aL(e){if(e.s<0||e.compareTo(this.m)>=0){return e.mod(this.m)}else{return e}}function a8(e){return e}function ah(e){e.divRemTo(this.m,null,e)}function ae(q,t,e){q.multiplyTo(t,e);this.reduce(e)}function bi(q,e){q.squareTo(e);this.reduce(e)}aj.prototype.convert=aL;aj.prototype.revert=a8;aj.prototype.reduce=ah;aj.prototype.mulTo=ae;aj.prototype.sqrTo=bi;function X(){if(this.t<1){return 0}var q=this[0];if((q&1)==0){return 0}var e=q&3;e=(e*(2-(q&15)*e))&15;e=(e*(2-(q&255)*e))&255;e=(e*(2-(((q&65535)*e)&65535)))&65535;e=(e*(2-q*e%this.DV))%this.DV;return(e>0)?this.DV-e:-e}function j(e){this.m=e;this.mp=e.invDigit();this.mpl=this.mp&32767;this.mph=this.mp>>15;this.um=(1<<(e.DB-15))-1;this.mt2=2*e.t}function a7(q){var e=m();q.abs().dlShiftTo(this.m.t,e);e.divRemTo(this.m,null,e);if(q.s<0&&e.compareTo(bg.ZERO)>0){this.m.subTo(e,e)}return e}function bh(q){var e=m();q.copyTo(e);this.reduce(e);return e}function aq(q){while(q.t<=this.mt2){q[q.t++]=0}for(var u=0;u>15)*this.mpl)&this.um)<<15))&q.DM;e=u+this.m.t;q[e]+=this.m.am(0,t,q,u,0,this.m.t);while(q[e]>=q.DV){q[e]-=q.DV;q[++e]++}}q.clamp();q.drShiftTo(this.m.t,q);if(q.compareTo(this.m)>=0){q.subTo(this.m,q)}}function ba(q,e){q.squareTo(e);this.reduce(e)}function V(q,t,e){q.multiplyTo(t,e);this.reduce(e)}j.prototype.convert=a7;j.prototype.revert=bh;j.prototype.reduce=aq;j.prototype.mulTo=V;j.prototype.sqrTo=ba;function n(){return((this.t>0)?(this[0]&1):this.s)==0}function U(u,t){if(u>4294967295||u<1){return bg.ONE}var y=m(),q=m(),z=t.convert(this),A=o(u)-1;z.copyTo(y);while(--A>=0){t.sqrTo(y,q);if((u&(1<0){t.mulTo(q,z,y)}else{var e=y;y=q;q=e}}return t.revert(y)}function bb(e,q){var t;if(e<256||q.isEven()){t=new aj(q)}else{t=new j(q)}return this.exp(e,t)}bg.prototype.copyTo=aS;bg.prototype.fromInt=x;bg.prototype.fromString=T;bg.prototype.clamp=an;bg.prototype.dlShiftTo=bf;bg.prototype.drShiftTo=aR;bg.prototype.lShiftTo=Q;bg.prototype.rShiftTo=s;bg.prototype.subTo=aW;bg.prototype.multiplyTo=Z;bg.prototype.squareTo=ar;bg.prototype.divRemTo=aa;bg.prototype.invDigit=X;bg.prototype.isEven=n;bg.prototype.exp=U;bg.prototype.toString=P;bg.prototype.negate=at;bg.prototype.abs=a9;bg.prototype.compareTo=ad;bg.prototype.bitLength=R;bg.prototype.mod=am;bg.prototype.modPowInt=bb;bg.ZERO=f(0);bg.ONE=f(1);function r(){this.i=0;this.j=0;this.S=new Array}function h(u){var q,t,e;for(q=0;q<256;++q){this.S[q]=q}t=0;for(q=0;q<256;++q){t=t+this.S[q]+u[q%u.length]&255;e=this.S[q];this.S[q]=this.S[t];this.S[t]=e}this.i=0;this.j=0}function b(){var e;this.i=this.i+1&255;this.j=this.j+this.S[this.i]&255;e=this.S[this.i];this.S[this.i]=this.S[this.j];this.S[this.j]=e;return this.S[e+this.S[this.i]&255]}function bd(){return new r}r.prototype.init=h;r.prototype.next=b;var al=256;var w;var az;var aX;function g(e){az[aX++]^=e&255;az[aX++]^=(e>>8)&255;az[aX++]^=(e>>16)&255;az[aX++]^=(e>>24)&255;if(aX>=al){aX-=al}}function ay(){g(new Date().getTime())}if(az==null){az=[];aX=0;var ag;try{if(window.crypto&&window.crypto.getRandomValues){var au=new Uint8Array(32);window.crypto.getRandomValues(au);for(ag=0;ag<32;++ag){az[aX++]=au[ag]}}else{if(window.msCrypto&&window.msCrypto.getRandomValues){var au=new Uint8Array(32);window.msCrypto.getRandomValues(au);for(ag=0;ag<32;++ag){az[aX++]=au[ag]}}else{if(window.crypto&&window.crypto.random){var ab=window.crypto.random(32);for(ag=0;ag>>8;az[aX++]=ag&255}aX=0;ay()}function Y(){if(w==null){ay();w=bd();w.init(az);for(aX=0;aX=0&&t>0){u[--t]=A[y--]}u[--t]=0;var z=new aZ();var q=new Array();while(t>2){q[0]=0;while(q[0]==0){z.nextBytes(q)}u[--t]=q[0]}u[--t]=2;u[--t]=0;return new bg(u)}function ak(){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 N(e,q){if(e!=null&&q!=null&&e.length>0&&q.length>0){this.n=l(e,16);this.e=parseInt(q,16)}else{alert("Invalid RSA public key")}}function aQ(e){return e.modPowInt(this.e,this.n)}function O(q){var t=a3(q,(this.n.bitLength()+7)>>3);if(t==null){return null}var u=this.doPublic(t);if(u==null){return null}var y=u.toString(16);if((y.length&1)==0){return y}else{return"0"+y}}function i(q){var e=this.encrypt(q);if(e){return a0(e)}else{return null}}ak.prototype.doPublic=aQ;ak.prototype.setPublic=N;ak.prototype.encrypt=O;ak.prototype.encrypt_b64=i;"use strict";function ai(e){throw e}var ag=void 0,af=!1;var k={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(e){this.toString=function(){return"CORRUPT: "+this.message};this.message=e},invalid:function(e){this.toString=function(){return"INVALID: "+this.message};this.message=e},bug:function(e){this.toString=function(){return"BUG: "+this.message};this.message=e},notReady:function(e){this.toString=function(){return"NOT READY: "+this.message};this.message=e}}};"undefined"!==typeof module&&module.exports&&(module.exports=k);"function"===typeof aw&&aw([],function(){return k});k.cipher.aes=function(u){this.k[0][0][0]||this.D();var y,z,A,B,e=this.k[0][4],q=this.k[1];y=u.length;var t=1;4!==y&&(6!==y&&8!==y)&&ai(new k.exception.invalid("invalid aes key size"));this.b=[A=u.slice(0),B=[]];for(u=y;u<4*y+28;u++){z=A[u-1];if(0===u%y||8===y&&4===u%y){z=e[z>>>24]<<24^e[z>>16&255]<<16^e[z>>8&255]<<8^e[z&255],0===u%y&&(z=z<<8^z>>>24^t<<24,t=t<<1^283*(t>>7))}A[u]=A[u-y]^z}for(y=0;u;y++,u--){z=A[y&3?u:u-4],B[y]=4>=u||4>y?z:q[0][e[z>>>24]]^q[1][e[z>>16&255]]^q[2][e[z>>8&255]]^q[3][e[z&255]]}};k.cipher.aes.prototype={encrypt:function(e){return ac(this,e,0)},decrypt:function(e){return ac(this,e,1)},k:[[[],[],[],[],[]],[[],[],[],[],[]]],D:function(){var y=this.k[0],z=this.k[1],A=y[4],B=z[4],C,D,E,F=[],e=[],G,t,q,u;for(C=0;256>C;C++){e[(F[C]=C<<1^283*(C>>7))^C]=C}for(D=E=0;!A[D];D^=G||1,E=e[E]||1){q=E^E<<1^E<<2^E<<3^E<<4;q=q>>8^q&255^99;A[D]=q;B[q]=D;t=F[C=F[G=F[D]]];u=16843009*t^65537*C^257*G^16843008*D;t=257*F[q]^16843008*q;for(C=0;4>C;C++){y[C][D]=t=t<<24^t>>>8,z[C][q]=u=u<<24^u>>>8}}for(C=0;5>C;C++){y[C]=y[C].slice(0),z[C]=z[C].slice(0)}}};function ac(K,L,e){4!==L.length&&ai(new k.exception.invalid("invalid aes block size"));var q=K.b[e],t=L[0]^q[0],u=L[e?3:1]^q[1],y=L[2]^q[2];L=L[e?1:3]^q[3];var z,B,A,D=q.length/4-2,C,E=4,G=[0,0,0,0];z=K.k[e];K=z[0];var F=z[1],H=z[2],I=z[3],J=z[4];for(C=0;C>>24]^F[u>>16&255]^H[y>>8&255]^I[L&255]^q[E],B=K[u>>>24]^F[y>>16&255]^H[L>>8&255]^I[t&255]^q[E+1],A=K[y>>>24]^F[L>>16&255]^H[t>>8&255]^I[u&255]^q[E+2],L=K[L>>>24]^F[t>>16&255]^H[u>>8&255]^I[y&255]^q[E+3],E+=4,t=z,u=B,y=A}for(C=0;4>C;C++){G[e?3&-C:C]=J[t>>>24]<<24^J[u>>16&255]<<16^J[y>>8&255]<<8^J[L&255]^q[E++],z=t,t=u,u=y,y=L,L=z}return G}k.bitArray={bitSlice:function(t,u,q){t=k.bitArray.P(t.slice(u/32),32-(u&31)).slice(1);return q===ag?t:k.bitArray.clamp(t,q-u)},extract:function(u,y,q){var t=Math.floor(-y-q&31);return((y+q-1^y)&-32?u[y/32|0]<<32-t^u[y/32+1|0]>>>t:u[y/32|0]>>>t)&(1<>u-1,1));return t},partial:function(t,u,q){return 32===t?u:(q?u|0:u<<32-t)+1099511627776*t},getPartial:function(e){return Math.round(e/1099511627776)||32},equal:function(u,y){if(k.bitArray.bitLength(u)!==k.bitArray.bitLength(y)){return af}var q=0,t;for(t=0;t>>y),e=u[t]<<32-y}t=u.length?u[u.length-1]:0;u=k.bitArray.getPartial(t);q.push(k.bitArray.partial(y+u&31,32>>24|q>>>8&65280|(q&65280)<<8|q<<24}return t}};k.codec.utf8String={fromBits:function(u){var y="",e=k.bitArray.bitLength(u),q,t;for(q=0;q>>24),t<<=8}return decodeURIComponent(escape(y))},toBits:function(u){u=unescape(encodeURIComponent(u));var y=[],q,t=0;for(q=0;q>>B)>>>26),6>B?(q=u[z]<<6-B,B+=26,z++):(q<<=6,B-=6)}for(;A.length&3&&!y;){A+="="}return A},toBits:function(u,y){u=u.replace(/\s|=/g,"");var z=[],A,B=0,e=k.codec.base64.J,q=0,t;y&&(e=e.substr(0,62)+"-_");for(A=0;At&&ai(new k.exception.invalid("this isn't base64!")),26>>B),q=t<<32-B):(B+=6,q^=t<<32-B)}B&56&&z.push(k.bitArray.partial(B&56,q,1));return z}};k.codec.base64url={fromBits:function(e){return k.codec.base64.fromBits(e,1,1)},toBits:function(e){return k.codec.base64.toBits(e,1)}};k.hash.sha256=function(e){this.b[0]||this.D();e?(this.r=e.r.slice(0),this.o=e.o.slice(0),this.h=e.h):this.reset()};k.hash.sha256.hash=function(e){return(new k.hash.sha256).update(e).finalize()};k.hash.sha256.prototype={blockSize:512,reset:function(){this.r=this.N.slice(0);this.o=[];this.h=0;return this},update:function(t){"string"===typeof t&&(t=k.codec.utf8String.toBits(t));var u,q=this.o=k.bitArray.concat(this.o,t);u=this.h;t=this.h=u+k.bitArray.bitLength(t);for(u=512+u&-512;u<=t;u+=512){ab(this,q.splice(0,16))}return this},finalize:function(){var t,u=this.o,q=this.r,u=k.bitArray.concat(u,[k.bitArray.partial(1,1)]);for(t=u.length+2;t&15;t++){u.push(0)}u.push(Math.floor(this.h/4294967296));for(u.push(this.h|0);u.length;){ab(this,u.splice(0,16))}this.reset();return q},N:[],b:[],D:function(){function u(e){return 4294967296*(e-Math.floor(e))|0}var y=0,q=2,t;u:for(;64>y;q++){for(t=2;t*t<=q;t++){if(0===q%t){continue u}}8>y&&(this.N[y]=u(Math.pow(q,0.5)));this.b[y]=u(Math.pow(q,1/3));y++}}};function ab(u,y){var z,B,D,E=y.slice(0),F=u.r,G=u.b,I=F[0],H=F[1],q=F[2],J=F[3],A=F[4],e=F[5],C=F[6],t=F[7];for(z=0;64>z;z++){16>z?B=E[z]:(B=E[z+1&15],D=E[z+14&15],B=E[z&15]=(B>>>7^B>>>18^B>>>3^B<<25^B<<14)+(D>>>17^D>>>19^D>>>10^D<<15^D<<13)+E[z&15]+E[z+9&15]|0),B=B+t+(A>>>6^A>>>11^A>>>25^A<<26^A<<21^A<<7)+(C^A&(e^C))+G[z],t=C,C=e,e=A,A=J+B|0,J=q,q=H,H=I,I=B+(H&q^J&(H^q))+(H>>>2^H>>>13^H>>>22^H<<30^H<<19^H<<10)|0}F[0]=F[0]+I|0;F[1]=F[1]+H|0;F[2]=F[2]+q|0;F[3]=F[3]+J|0;F[4]=F[4]+A|0;F[5]=F[5]+e|0;F[6]=F[6]+C|0;F[7]=F[7]+t|0}k.mode.ccm={name:"ccm",encrypt:function(B,C,D,e,q){var t,u=C.slice(0),y=k.bitArray,A=y.bitLength(D)/8,z=y.bitLength(u)/8;q=q||64;e=e||[];7>A&&ai(new k.exception.invalid("ccm: iv must be at least 7 bytes"));for(t=2;4>t&&z>>>8*t;t++){}t<15-A&&(t=15-A);D=y.clamp(D,8*(15-t));C=k.mode.ccm.L(B,C,D,e,q,t);u=k.mode.ccm.p(B,u,D,C,q,t);return y.concat(u.data,u.tag)},decrypt:function(B,C,D,e,q){q=q||64;e=e||[];var t=k.bitArray,u=t.bitLength(D)/8,y=t.bitLength(C),A=t.clamp(C,y-q),z=t.bitSlice(C,y-q),y=(y-q)/8;7>u&&ai(new k.exception.invalid("ccm: iv must be at least 7 bytes"));for(C=2;4>C&&y>>>8*C;C++){}C<15-u&&(C=15-u);D=t.clamp(D,8*(15-C));A=k.mode.ccm.p(B,A,D,z,q,C);B=k.mode.ccm.L(B,A.data,D,e,q,C);t.equal(A.tag,B)||ai(new k.exception.corrupt("ccm: tag doesn't match"));return A.data},L:function(C,e,q,t,u,y){var z=[],A=k.bitArray,B=A.l;u/=8;(u%2||4>u||16=q?z=[A.partial(16,q)]:4294967295>=q&&(z=A.concat([A.partial(16,65534)],[q]));z=A.concat(z,t);for(t=0;tB.bitLength(z)&&(t=e(t,A(t)),z=B.concat(z,[-2147483648,0,0,0]));q=e(q,z);return u.encrypt(e(A(e(t,A(t))),q))},H:function(e){return[e[0]<<1^e[1]>>>31,e[1]<<1^e[2]>>>31,e[2]<<1^e[3]>>>31,e[3]<<1^135*(e[0]>>>31)]}};k.mode.gcm={name:"gcm",encrypt:function(y,z,e,q,t){var u=z.slice(0);z=k.bitArray;q=q||[];y=k.mode.gcm.p(!0,y,u,q,e,t||128);return z.concat(y.data,y.tag)},decrypt:function(u,y,z,A,B){var e=y.slice(0),q=k.bitArray,t=q.bitLength(e);B=B||128;A=A||[];B<=t?(y=q.bitSlice(e,t-B),e=q.bitSlice(e,0,t-B)):(y=e,e=[]);u=k.mode.gcm.p(af,u,e,A,z,B);q.equal(u.tag,y)||ai(new k.exception.corrupt("gcm: tag doesn't match"));return u.data},Z:function(u,y){var z,A,B,e,q,t=k.bitArray.l;B=[0,0,0,0];e=y.slice(0);for(z=0;128>z;z++){(A=0!==(u[Math.floor(z/32)]&1<<31-z%32))&&(B=t(B,e));q=0!==(e[3]&1);for(A=3;0>>1|(e[A-1]&1)<<31}e[0]>>>=1;q&&(e[0]^=-520093696)}return B},g:function(u,y,e){var q,t=e.length;y=y.slice(0);for(q=0;qt&&(u=y.hash(u));for(q=0;qD||0>C)&&ai(k.exception.invalid("invalid params to pbkdf2"));"string"===typeof A&&(A=k.codec.utf8String.toBits(A));"string"===typeof B&&(B=k.codec.utf8String.toBits(B));E=E||k.misc.hmac;A=new E(A);var e,q,t,y,u=[],z=k.bitArray;for(y=1;32*u.length<(D||1);y++){E=e=A.encrypt(z.concat(B,[y]));for(q=1;qu;u++){q.push(4294967296*Math.random()|0)}for(u=0;u=1<this.j&&(this.j=t);this.F++;this.b=k.hash.sha256.hash(this.b.concat(q));this.A=new k.cipher.aes(this.b);for(e=0;4>e&&!(this.f[e]=this.f[e]+1|0,this.f[e]);e++){}}for(e=0;e>>=1}}}this.c[z].update([t,this.C++,2,e,y,C.length].concat(C))}break;case"string":e===ag&&(e=C.length);this.c[z].update([t,this.C++,3,e,y,C.length]);this.c[z].update(C);break;default:B=1}B&&ai(new k.exception.bug("random: addEntropy only supports number, array of numbers or string"));this.i[z]+=e;this.d+=e;A===this.m&&(this.isReady()!==this.m&&aM("seeded",Math.max(this.j,this.d)),aM("progress",this.getProgress()))},isReady:function(e){e=this.I[e!==ag?e:this.B];return this.j&&this.j>=e?this.i[0]>this.R&&(new Date).valueOf()>this.O?this.u|this.t:this.t:this.d>=e?this.u|this.m:this.m},getProgress:function(e){e=this.I[e?e:this.B];return this.j>=e?1:this.d>e?1:this.d/e},startCollectors:function(){this.q||(this.a={loadTimeCollector:aK(this,this.aa),mouseCollector:aK(this,this.ba),keyboardCollector:aK(this,this.$),accelerometerCollector:aK(this,this.U)},window.addEventListener?(window.addEventListener("load",this.a.loadTimeCollector,af),window.addEventListener("mousemove",this.a.mouseCollector,af),window.addEventListener("keypress",this.a.keyboardCollector,af),window.addEventListener("devicemotion",this.a.accelerometerCollector,af)):document.attachEvent?(document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector)):ai(new k.exception.bug("can't attach event")),this.q=!0)},stopCollectors:function(){this.q&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,af),window.removeEventListener("mousemove",this.a.mouseCollector,af),window.removeEventListener("keypress",this.a.keyboardCollector,af),window.removeEventListener("devicemotion",this.a.accelerometerCollector,af)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.q=af)},addEventListener:function(e,q){this.w[e][this.V++]=q},removeEventListener:function(y,z){var e,q,t=this.w[y],u=[];for(q in t){t.hasOwnProperty(q)&&t[q]===z&&u.push(q)}for(e=0;eq&&!(e.f[q]=e.f[q]+1|0,e.f[q]);q++){}return e.A.encrypt(e.f)}function aK(e,q){return function(){q.apply(e,arguments)}}k.random=new k.prng(6);a:try{var aI,aG,aF,aE;if(aE="undefined"!==typeof module){var aD;if(aD=module.exports){var aC;try{aC=require("crypto")}catch(aB){aC=null}aD=(aG=aC)&&aG.randomBytes}aE=aD}if(aE){aI=aG.randomBytes(128),aI=new Uint32Array((new Uint8Array(aI)).buffer),k.random.addEntropy(aI,1024,"crypto['randomBytes']")}else{if("undefined"!==typeof window&&"undefined"!==typeof Uint32Array){aF=new Uint32Array(32);if(window.crypto&&window.crypto.getRandomValues){window.crypto.getRandomValues(aF)}else{if(window.msCrypto&&window.msCrypto.getRandomValues){window.msCrypto.getRandomValues(aF)}else{break a}}k.random.addEntropy(aF,1024,"crypto['getRandomValues']")}}}catch(aA){"undefined"!==typeof window&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(aA))}k.json={defaults:{v:1,iter:1000,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},Y:function(y,z,A,e){A=A||{};e=e||{};var q=k.json,t=q.e({iv:k.random.randomWords(4,0)},q.defaults),u;q.e(t,A);A=t.adata;"string"===typeof t.salt&&(t.salt=k.codec.base64.toBits(t.salt));"string"===typeof t.iv&&(t.iv=k.codec.base64.toBits(t.iv));(!k.mode[t.mode]||!k.cipher[t.cipher]||"string"===typeof y&&100>=t.iter||64!==t.ts&&96!==t.ts&&128!==t.ts||128!==t.ks&&192!==t.ks&&256!==t.ks||2>t.iv.length||4=z.iter||64!==z.ts&&96!==z.ts&&128!==z.ts||128!==z.ks&&192!==z.ks&&256!==z.ks||!z.iv||2>z.iv.length||4>>24);y<<=8}return z};e.toBits=e.toBits||function(z){var y=[],t,u=0;for(t=0;t0?e[0]:this.cardnumber;if(isNaN(parseInt(t,10))){return false}var q=t.length;var u=q&1;var y=0;if(q>=14){p("luhnCount")}for(var z=0;z9){B-=9}}y+=B}if(y%10===0){return true}else{return false}};aY.cvcCheck=function(e){return(e&&e.match&&e.match(/^\d{3,4}$/))?true:false};aY.yearCheck=function(e){return(e&&e.match&&e.match(/^\d{4}$/))?true:false};aY.monthCheck=function(e){return(e&&e.match&&e.match(/^\d{2}$/)&&parseInt(e,10)>=1&&parseInt(e,10)<=12)?true:false};var a2=function(t,q){try{k.random.startCollectors()}catch(u){}this.key=t;this.options=q||{};if(typeof this.options.numberIgnoreNonNumeric==="undefined"){this.options.numberIgnoreNonNumeric=true}if(typeof this.options.cvcIgnoreFornumber!=="undefined"){delete this.options.cvcIgnoreFornumber}if(typeof this.options.cvcIgnoreBins==="string"){var y=[];this.options.cvcIgnoreBins.replace(/\d+/g,function(e){if(e.length>0&&!isNaN(parseInt(e,10))){y.push(e)}return e});if(y.length>0){this.options.cvcIgnoreFornumber=new RegExp("^\\s*("+y.join("|")+")")}}else{if(typeof this.options.ignoreCvcBins!=="undefined"){delete this.options.ignoreCvcBins}}p("initializeCount")};a2.prototype.createRSAKey=function(){var e=this.key.split("|");if(e.length!=2){throw"Malformed public key"}var u=e[0];var q=e[1];var t=new ak();t.setPublic(q,u);return t};a2.prototype.createAESKey=function(){return new bl()};a2.prototype.encrypt=function(B){var u,t,e,A,z,y,q={number:B.number,cvc:B.cvc,month:B.expiryMonth,year:B.expiryYear};if(this.options.enableValidations!==false&&this.validate(q).valid===false){return false}p("extend",B);u=this.createRSAKey();t=this.createAESKey();e=t.encrypt(JSON.stringify(B));A=k.codec.bytes.fromBits(t.key);z=u.encrypt_b64(A);y="adyenjs_"+a5.version+"$";return[y,z,"$",e].join("")};a2.prototype.validate=function(y){var e={};e.valid=true;if(typeof y==="object"){for(var z in y){if(y.hasOwnProperty(z)){var A=y[z];if(this.options[z+"IgnoreNonNumeric"]){A=A.replace(/\D/g,"")}var t=false;for(var u in y){if(y.hasOwnProperty(u)){var q=this.options[z+"IgnoreFor"+u];if(q&&A&&y[u].match(q)){t=true}}}if(t){e[z]=true;e.valid=e.valid&&e[z];continue}switch(z){case"number":e.number=aY.luhnCheck(A);e.valid=e.valid&&e.number;break;case"year":e.year=aY.yearCheck(A);e.valid=e.valid&&e.year;break;case"cvc":e.cvc=aY.cvcCheck(A);e.valid=e.valid&&e.cvc;break;case"month":e.month=aY.monthCheck(A);e.valid=e.valid&&e.month;break;default:e.unknown=e.unknown||[];e.unknown.push(z);e.valid=false}}}}else{e.valid=false}return e};var bl=function(){};bl.prototype={constructor:bl,key:k.random.randomWords(8,0),encrypt:function(e){return this.encryptWithIv(e,k.random.randomWords(3,0))},encryptWithIv:function(z,q){var t,u,e,y;t=new k.cipher.aes(this.key);u=k.codec.utf8String.toBits(z);e=k.mode.ccm.encrypt(t,u,q);y=k.bitArray.concat(q,e);return k.codec.base64.fromBits(y)}}})(this,typeof define==="function"?define:null); \ No newline at end of file