20 lines
69 KiB
JavaScript
20 lines
69 KiB
JavaScript
/*! Licensed to the Apache Software Foundation (ASF) under one or more
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
* this work for additional information regarding copyright ownership.
|
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
* (the "License"); you may not use this file except in compliance with
|
|
* the License. You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
(function(e,t){function r(e,t,r){if(4!==t.length)throw new h.exception.invalid("invalid aes block size");var n=e.c[r],a=t[0]^n[0],i=t[r?3:1]^n[1],s=t[2]^n[2];t=t[r?1:3]^n[3];var o,c,u,f,l=n.length/4-2,d=4,p=[0,0,0,0];o=e.n[r],e=o[0];var g=o[1],m=o[2],y=o[3],b=o[4];for(f=0;l>f;f++)o=e[a>>>24]^g[255&i>>16]^m[255&s>>8]^y[255&t]^n[d],c=e[i>>>24]^g[255&s>>16]^m[255&t>>8]^y[255&a]^n[d+1],u=e[s>>>24]^g[255&t>>16]^m[255&a>>8]^y[255&i]^n[d+2],t=e[t>>>24]^g[255&a>>16]^m[255&i>>8]^y[255&s]^n[d+3],d+=4,a=o,i=c,s=u;for(f=0;4>f;f++)p[r?3&-f:f]=b[a>>>24]<<24^b[255&i>>16]<<16^b[255&s>>8]<<8^b[255&t]^n[d++],o=a,a=i,i=s,s=t,t=o;return p}function n(e,t){var r,n,a,i=t.slice(0),s=e.u,o=e.c,c=s[0],u=s[1],h=s[2],f=s[3],l=s[4],d=s[5],p=s[6],g=s[7];for(r=0;64>r;r++)16>r?n=i[r]:(n=i[15&r+1],a=i[15&r+14],n=i[15&r]=0|(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(a>>>17^a>>>19^a>>>10^a<<15^a<<13)+i[15&r]+i[15&r+9]),n=n+g+(l>>>6^l>>>11^l>>>25^l<<26^l<<21^l<<7)+(p^l&(d^p))+o[r],g=p,p=d,d=l,l=0|f+n,f=h,h=u,u=c,c=0|n+(u&h^f&(u^h))+(u>>>2^u>>>13^u>>>22^u<<30^u<<19^u<<10);s[0]=0|s[0]+c,s[1]=0|s[1]+u,s[2]=0|s[2]+h,s[3]=0|s[3]+f,s[4]=0|s[4]+l,s[5]=0|s[5]+d,s[6]=0|s[6]+p,s[7]=0|s[7]+g}function a(e,t){var r,n=h.random.F[e],a=[];for(r in n)n.hasOwnProperty(r)&&a.push(n[r]);for(r=0;a.length>r;r++)a[r](t)}function i(e){e.c=s(e).concat(s(e)),e.H=new h.cipher.aes(e.c)}function s(e){for(var t=0;4>t&&(e.h[t]=0|e.h[t]+1,!e.h[t]);t++);return e.H.encrypt(e.h)}this.AeroGear={},AeroGear.Core=function(){if(this instanceof AeroGear.Core)throw"Invalid instantiation of base class AeroGear.Core";this.add=function(e){var t,r,n=this[this.collectionName]||{};if(this[this.collectionName]=n,!e)return this;if("string"==typeof e)n[e]=AeroGear[this.lib].adapters[this.type](e,this.config);else if(AeroGear.isArray(e))for(t=0;e.length>t;t++)r=e[t],"string"==typeof r?n[r]=AeroGear[this.lib].adapters[this.type](r,this.config):r.name&&(r.settings=AeroGear.extend(r.settings||{},this.config),r.settings.recordId=r.settings.recordId||r.recordId,n[r.name]=AeroGear[this.lib].adapters[r.type||this.type](r.name,r.settings));else{if(!e.name)return this;e.settings=AeroGear.extend(e.settings||{},this.config),e.settings.recordId=e.settings.recordId||e.recordId,n[e.name]=AeroGear[this.lib].adapters[e.type||this.type](e.name,e.settings)}return this[this.collectionName]=n,this},this.remove=function(e){var t,r,n=this[this.collectionName]||{};if("string"==typeof e)delete n[e];else if(AeroGear.isArray(e))for(t=0;e.length>t;t++)r=e[t],"string"==typeof r?delete n[r]:delete n[r.name];else e&&delete n[e.name];return this[this.collectionName]=n,this}},AeroGear.isArray=function(e){return"[object Array]"==={}.toString.call(e)},AeroGear.extend=function(e,t){var r;for(r in t)e[r]=t[r];return e},function(){function e(e,t,r){var n=t&&r||0,a=0;for(t=t||[],e.toLowerCase().replace(/[0-9a-f]{2}/g,function(e){16>a&&(t[n+a++]=g[e])});16>a;)t[n+a++]=0;return t}function t(e,t){var r=t||0,n=p;return n[e[r++]]+n[e[r++]]+n[e[r++]]+n[e[r++]]+"-"+n[e[r++]]+n[e[r++]]+"-"+n[e[r++]]+n[e[r++]]+"-"+n[e[r++]]+n[e[r++]]+"-"+n[e[r++]]+n[e[r++]]+n[e[r++]]+n[e[r++]]+n[e[r++]]+n[e[r++]]}function r(e,r,n){var a=r&&n||0,i=r||[];e=e||{};var s=null!=e.clockseq?e.clockseq:v,o=null!=e.msecs?e.msecs:(new Date).getTime(),c=null!=e.nsecs?e.nsecs:x+1,u=o-A+(c-x)/1e4;if(0>u&&null==e.clockseq&&(s=16383&s+1),(0>u||o>A)&&null==e.nsecs&&(c=0),c>=1e4)throw Error("uuid.v1(): Can't create more than 10M uuids/sec");A=o,x=c,v=s,o+=122192928e5;var h=(1e4*(268435455&o)+c)%4294967296;i[a++]=255&h>>>24,i[a++]=255&h>>>16,i[a++]=255&h>>>8,i[a++]=255&h;var f=268435455&1e4*(o/4294967296);i[a++]=255&f>>>8,i[a++]=255&f,i[a++]=16|15&f>>>24,i[a++]=255&f>>>16,i[a++]=128|s>>>8,i[a++]=255&s;for(var l=e.node||b,d=0;6>d;d++)i[a+d]=l[d];return r?r:t(i)}function n(e,r,n){var a=r&&n||0;"string"==typeof e&&(r="binary"==e?new d(16):null,e=null),e=e||{};var i=e.random||(e.rng||l)();if(i[6]=64|15&i[6],i[8]=128|63&i[8],r)for(var s=0;16>s;s++)r[a+s]=i[s];return r||t(i)}var a,i,s,o=this,c=Array(16);if(a=function(){for(var e,e,t=c,r=0,r=0;16>r;r++)0==(3&r)&&(e=4294967296*Math.random()),t[r]=255&e>>>((3&r)<<3);return t},o.crypto&&crypto.getRandomValues){var u=new Uint32Array(4);s=function(){crypto.getRandomValues(u);for(var e=0;16>e;e++)c[e]=255&u[e>>2]>>>8*(3&e);return c}}try{var h=require("crypto").randomBytes;i=h&&function(){return h(16)}}catch(f){}for(var l=i||s||a,d="function"==typeof Buffer?Buffer:Array,p=[],g={},m=0;256>m;m++)p[m]=(m+256).toString(16).substr(1),g[p[m]]=m;var y=l(),b=[1|y[0],y[1],y[2],y[3],y[4],y[5]],v=16383&(y[6]<<8|y[7]),A=0,x=0,S=n;if(S.v1=r,S.v4=n,S.parse=e,S.unparse=t,S.BufferClass=d,S.mathRNG=a,S.nodeRNG=i,S.whatwgRNG=s,"undefined"!=typeof module)module.exports=S;else{var G=o.uuid;S.noConflict=function(){return o.uuid=G,S},o.uuid=S}}(),function(){var r=e!==t?e:exports,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",a=function(){try{document.createElement("$")}catch(e){return e}}();r.btoa||(r.btoa=function(e){for(var t,r,i=0,s=n,o="";e.charAt(0|i)||(s="=",i%1);o+=s.charAt(63&t>>8-8*(i%1))){if(r=e.charCodeAt(i+=.75),r>255)throw a;t=t<<8|r}return o}),r.atob||(r.atob=function(e){if(e=e.replace(/=+$/,""),1==e.length%4)throw a;for(var t,r,i=0,s=0,o="";r=e.charAt(s++);~r&&(t=i%4?64*t+r:r,i++%4)?o+=String.fromCharCode(255&t>>(6&-2*i)):0)r=n.indexOf(r);return o})}();var o=void 0,c=!0,u=!1,h={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=h),h.cipher.aes=function(e){this.n[0][0][0]||this.K();var t,r,n,a,i=this.n[0][4],s=this.n[1];t=e.length;var o=1;if(4!==t&&6!==t&&8!==t)throw new h.exception.invalid("invalid aes key size");for(this.c=[n=e.slice(0),a=[]],e=t;4*t+28>e;e++)r=n[e-1],(0===e%t||8===t&&4===e%t)&&(r=i[r>>>24]<<24^i[255&r>>16]<<16^i[255&r>>8]<<8^i[255&r],0===e%t&&(r=r<<8^r>>>24^o<<24,o=o<<1^283*(o>>7))),n[e]=n[e-t]^r;for(t=0;e;t++,e--)r=n[3&t?e:e-4],a[t]=4>=e||4>t?r:s[0][i[r>>>24]]^s[1][i[255&r>>16]]^s[2][i[255&r>>8]]^s[3][i[255&r]]},h.cipher.aes.prototype={encrypt:function(e){return r(this,e,0)},decrypt:function(e){return r(this,e,1)},n:[[[],[],[],[],[]],[[],[],[],[],[]]],K:function(){var e,t,r,n,a,i,s,o=this.n[0],c=this.n[1],u=o[4],h=c[4],f=[],l=[];for(e=0;256>e;e++)l[(f[e]=e<<1^283*(e>>7))^e]=e;for(t=r=0;!u[t];t^=n||1,r=l[r]||1)for(i=r^r<<1^r<<2^r<<3^r<<4,i=99^(i>>8^255&i),u[t]=i,h[i]=t,a=f[e=f[n=f[t]]],s=16843009*a^65537*e^257*n^16843008*t,a=257*f[i]^16843008*i,e=0;4>e;e++)o[e][t]=a=a<<24^a>>>8,c[e][i]=s=s<<24^s>>>8;for(e=0;5>e;e++)o[e]=o[e].slice(0),c[e]=c[e].slice(0)}},h.bitArray={bitSlice:function(e,t,r){return e=h.bitArray.U(e.slice(t/32),32-(31&t)).slice(1),r===o?e:h.bitArray.clamp(e,r-t)},extract:function(e,t,r){var n=Math.floor(31&-t-r);return(-32&(t+r-1^t)?e[0|t/32]<<32-n^e[0|t/32+1]>>>n:e[0|t/32]>>>n)&(1<<r)-1},concat:function(e,t){if(0===e.length||0===t.length)return e.concat(t);var r=e[e.length-1],n=h.bitArray.getPartial(r);return 32===n?e.concat(t):h.bitArray.U(t,n,0|r,e.slice(0,e.length-1))},bitLength:function(e){var t=e.length;return 0===t?0:32*(t-1)+h.bitArray.getPartial(e[t-1])},clamp:function(e,t){if(t>32*e.length)return e;e=e.slice(0,Math.ceil(t/32));var r=e.length;return t&=31,r>0&&t&&(e[r-1]=h.bitArray.partial(t,e[r-1]&2147483648>>t-1,1)),e},partial:function(e,t,r){return 32===e?t:(r?0|t:t<<32-e)+1099511627776*e},getPartial:function(e){return Math.round(e/1099511627776)||32},equal:function(e,t){if(h.bitArray.bitLength(e)!==h.bitArray.bitLength(t))return u;var r,n=0;for(r=0;e.length>r;r++)n|=e[r]^t[r];return 0===n},U:function(e,t,r,n){var a;for(a=0,n===o&&(n=[]);t>=32;t-=32)n.push(r),r=0;if(0===t)return n.concat(e);for(a=0;e.length>a;a++)n.push(r|e[a]>>>t),r=e[a]<<32-t;return a=e.length?e[e.length-1]:0,e=h.bitArray.getPartial(a),n.push(h.bitArray.partial(31&t+e,t+e>32?r:n.pop(),1)),n},ba:function(e,t){return[e[0]^t[0],e[1]^t[1],e[2]^t[2],e[3]^t[3]]}},h.codec.utf8String={fromBits:function(e){var t,r,n="",a=h.bitArray.bitLength(e);for(t=0;a/8>t;t++)0===(3&t)&&(r=e[t/4]),n+=String.fromCharCode(r>>>24),r<<=8;return decodeURIComponent(escape(n))},toBits:function(e){e=unescape(encodeURIComponent(e));var t,r=[],n=0;for(t=0;e.length>t;t++)n=n<<8|e.charCodeAt(t),3===(3&t)&&(r.push(n),n=0);return 3&t&&r.push(h.bitArray.partial(8*(3&t),n)),r}},h.codec.hex={fromBits:function(e){var t,r="";for(t=0;e.length>t;t++)r+=((0|e[t])+0xf00000000000).toString(16).substr(4);return r.substr(0,h.bitArray.bitLength(e)/4)},toBits:function(e){var t,r,n=[];for(e=e.replace(/\s|0x/g,""),r=e.length,e+="00000000",t=0;e.length>t;t+=8)n.push(0^parseInt(e.substr(t,8),16));return h.bitArray.clamp(n,4*r)}},h.hash.sha256=function(e){this.c[0]||this.K(),e?(this.u=e.u.slice(0),this.p=e.p.slice(0),this.k=e.k):this.reset()},h.hash.sha256.hash=function(e){return(new h.hash.sha256).update(e).finalize()},h.hash.sha256.prototype={blockSize:512,reset:function(){return this.u=this.R.slice(0),this.p=[],this.k=0,this},update:function(e){"string"==typeof e&&(e=h.codec.utf8String.toBits(e));var t,r=this.p=h.bitArray.concat(this.p,e);for(t=this.k,e=this.k=t+h.bitArray.bitLength(e),t=-512&512+t;e>=t;t+=512)n(this,r.splice(0,16));return this},finalize:function(){var e,t=this.p,r=this.u,t=h.bitArray.concat(t,[h.bitArray.partial(1,1)]);for(e=t.length+2;15&e;e++)t.push(0);for(t.push(Math.floor(this.k/4294967296)),t.push(0|this.k);t.length;)n(this,t.splice(0,16));return this.reset(),r},R:[],c:[],K:function(){function e(e){return 0|4294967296*(e-Math.floor(e))}var t,r=0,n=2;e:for(;64>r;n++){for(t=2;n>=t*t;t++)if(0===n%t)continue e;8>r&&(this.R[r]=e(Math.pow(n,.5))),this.c[r]=e(Math.pow(n,1/3)),r++}}},h.mode.gcm={name:"gcm",encrypt:function(e,t,r,n,a){var i=t.slice(0);return t=h.bitArray,n=n||[],e=h.mode.gcm.O(c,e,i,n,r,a||128),t.concat(e.data,e.tag)},decrypt:function(e,t,r,n,a){var i=t.slice(0),s=h.bitArray,o=s.bitLength(i);if(a=a||128,n=n||[],o>=a?(t=s.bitSlice(i,o-a),i=s.bitSlice(i,0,o-a)):(t=i,i=[]),e=h.mode.gcm.O(u,e,i,n,r,a),!s.equal(e.tag,t))throw new h.exception.corrupt("gcm: tag doesn't match");return e.data},aa:function(e,t){var r,n,a,i,s,o=h.bitArray.ba;for(a=[0,0,0,0],i=t.slice(0),r=0;128>r;r++){for((n=0!==(e[Math.floor(r/32)]&1<<31-r%32))&&(a=o(a,i)),s=0!==(1&i[3]),n=3;n>0;n--)i[n]=i[n]>>>1|(1&i[n-1])<<31;i[0]>>>=1,s&&(i[0]^=-520093696)}return a},j:function(e,t,r){var n,a=r.length;for(t=t.slice(0),n=0;a>n;n+=4)t[0]^=4294967295&r[n],t[1]^=4294967295&r[n+1],t[2]^=4294967295&r[n+2],t[3]^=4294967295&r[n+3],t=h.mode.gcm.aa(t,e);return t},O:function(e,t,r,n,a,i){var s,o,c,u,f,l,d,p,g=h.bitArray;for(l=r.length,d=g.bitLength(r),p=g.bitLength(n),o=g.bitLength(a),s=t.encrypt([0,0,0,0]),96===o?(a=a.slice(0),a=g.concat(a,[1])):(a=h.mode.gcm.j(s,[0,0,0,0],a),a=h.mode.gcm.j(s,a,[0,0,Math.floor(o/4294967296),4294967295&o])),o=h.mode.gcm.j(s,[0,0,0,0],n),f=a.slice(0),n=o.slice(0),e||(n=h.mode.gcm.j(s,o,r)),u=0;l>u;u+=4)f[3]++,c=t.encrypt(f),r[u]^=c[0],r[u+1]^=c[1],r[u+2]^=c[2],r[u+3]^=c[3];return r=g.clamp(r,d),e&&(n=h.mode.gcm.j(s,o,r)),e=[Math.floor(p/4294967296),4294967295&p,Math.floor(d/4294967296),4294967295&d],n=h.mode.gcm.j(s,n,e),c=t.encrypt(a),n[0]^=c[0],n[1]^=c[1],n[2]^=c[2],n[3]^=c[3],{tag:g.bitSlice(n,0,i),data:r}}},h.misc.hmac=function(e,t){this.Q=t=t||h.hash.sha256;var r,n=[[],[]],a=t.prototype.blockSize/32;for(this.q=[new t,new t],e.length>a&&(e=t.hash(e)),r=0;a>r;r++)n[0][r]=909522486^e[r],n[1][r]=1549556828^e[r];this.q[0].update(n[0]),this.q[1].update(n[1])},h.misc.hmac.prototype.encrypt=h.misc.hmac.prototype.mac=function(e){return e=new this.Q(this.q[0]).update(e).finalize(),new this.Q(this.q[1]).update(e).finalize()},h.misc.pbkdf2=function(e,t,r,n,a){if(r=r||1e3,0>n||0>r)throw h.exception.invalid("invalid params to pbkdf2");"string"==typeof e&&(e=h.codec.utf8String.toBits(e)),"string"==typeof t&&(t=h.codec.utf8String.toBits(t)),a=a||h.misc.hmac,e=new a(e);var i,s,o,c,u=[],f=h.bitArray;for(c=1;(n||1)>32*u.length;c++){for(a=i=e.encrypt(f.concat(t,[c])),s=1;r>s;s++)for(i=e.encrypt(i),o=0;i.length>o;o++)a[o]^=i[o];u=u.concat(a)}return n&&(u=f.clamp(u,n)),u},h.prng=function(e){this.e=[new h.hash.sha256],this.l=[0],this.L=0,this.B={},this.J=0,this.N={},this.T=this.g=this.m=this.$=0,this.c=[0,0,0,0,0,0,0,0],this.h=[0,0,0,0],this.H=o,this.I=e,this.s=u,this.F={progress:{},seeded:{}},this.o=this.Z=0,this.C=1,this.D=2,this.X=65536,this.M=[0,48,64,96,128,192,256,384,512,768,1024],this.Y=3e4,this.W=80},h.prng.prototype={randomWords:function(e,t){var r,n=[];r=this.isReady(t);var a;if(r===this.o)throw new h.exception.notReady("generator isn't seeded");if(r&this.D){r=!(r&this.C),a=[];var o,c=0;for(this.T=a[0]=(new Date).valueOf()+this.Y,o=0;16>o;o++)a.push(0|4294967296*Math.random());for(o=0;this.e.length>o&&(a=a.concat(this.e[o].finalize()),c+=this.l[o],this.l[o]=0,!(!r&&this.L&1<<o));o++);for(this.L>=1<<this.e.length&&(this.e.push(new h.hash.sha256),this.l.push(0)),this.g-=c,c>this.m&&(this.m=c),this.L++,this.c=h.hash.sha256.hash(this.c.concat(a)),this.H=new h.cipher.aes(this.c),r=0;4>r&&(this.h[r]=0|this.h[r]+1,!this.h[r]);r++);}for(r=0;e>r;r+=4)0===(r+1)%this.X&&i(this),a=s(this),n.push(a[0],a[1],a[2],a[3]);return i(this),n.slice(0,e)},setDefaultParanoia:function(e){this.I=e},addEntropy:function(e,t,r){r=r||"user";var n,i,s=(new Date).valueOf(),c=this.B[r],u=this.isReady(),f=0;switch(n=this.N[r],n===o&&(n=this.N[r]=this.$++),c===o&&(c=this.B[r]=0),this.B[r]=(this.B[r]+1)%this.e.length,typeof e){case"number":t===o&&(t=1),this.e[c].update([n,this.J++,1,t,s,1,0|e]);break;case"object":if(r=Object.prototype.toString.call(e),"[object Uint32Array]"===r){for(i=[],r=0;e.length>r;r++)i.push(e[r]);e=i}else for("[object Array]"!==r&&(f=1),r=0;e.length>r&&!f;r++)"number"!=typeof e[r]&&(f=1);if(!f){if(t===o)for(r=t=0;e.length>r;r++)for(i=e[r];i>0;)t++,i>>>=1;this.e[c].update([n,this.J++,2,t,s,e.length].concat(e))}break;case"string":t===o&&(t=e.length),this.e[c].update([n,this.J++,3,t,s,e.length]),this.e[c].update(e);break;default:f=1}if(f)throw new h.exception.bug("random: addEntropy only supports number, array of numbers or string");this.l[c]+=t,this.g+=t,u===this.o&&(this.isReady()!==this.o&&a("seeded",Math.max(this.m,this.g)),a("progress",this.getProgress()))},isReady:function(e){return e=this.M[e!==o?e:this.I],this.m&&this.m>=e?this.l[0]>this.W&&(new Date).valueOf()>this.T?this.D|this.C:this.C:this.g>=e?this.D|this.o:this.o},getProgress:function(e){return e=this.M[e?e:this.I],this.m>=e?1:this.g>e?1:this.g/e},startCollectors:function(){if(!this.s){if(e.addEventListener)e.addEventListener("load",this.v,u),e.addEventListener("mousemove",this.w,u);else{if(!document.attachEvent)throw new h.exception.bug("can't attach event");document.attachEvent("onload",this.v),document.attachEvent("onmousemove",this.w)}this.s=c}},stopCollectors:function(){this.s&&(e.removeEventListener?(e.removeEventListener("load",this.v,u),e.removeEventListener("mousemove",this.w,u)):e.detachEvent&&(e.detachEvent("onload",this.v),e.detachEvent("onmousemove",this.w)),this.s=u)},addEventListener:function(e,t){this.F[e][this.Z++]=t},removeEventListener:function(e,t){var r,n,a=this.F[e],i=[];for(n in a)a.hasOwnProperty(n)&&a[n]===t&&i.push(n);for(r=0;i.length>r;r++)n=i[r],delete a[n]},w:function(e){h.random.addEntropy([e.x||e.clientX||e.offsetX||0,e.y||e.clientY||e.offsetY||0],2,"mouse")},v:function(){h.random.addEntropy((new Date).valueOf(),2,"loadtime")}},h.random=new h.prng(6);try{if("undefined"!=typeof module&&module.exports){var f=require("crypto").randomBytes(128);h.random.addEntropy(f,1024,"crypto['randomBytes']")}else if(e&&e.crypto&&e.crypto.getRandomValues){var l=new Uint32Array(32);e.crypto.getRandomValues(l),h.random.addEntropy(l,1024,"crypto['getRandomValues']")}}catch(d){}h.bn=function(e){this.initWith(e)},h.bn.prototype={radix:24,maxMul:8,d:h.bn,copy:function(){return new this.d(this)},initWith:function(e){var t,r=0;switch(typeof e){case"object":this.limbs=e.limbs.slice(0);break;case"number":this.limbs=[e],this.normalize();break;case"string":for(e=e.replace(/^0x/,""),this.limbs=[],t=this.radix/4,r=0;e.length>r;r+=t)this.limbs.push(parseInt(e.substring(Math.max(e.length-r-t,0),e.length-r),16));break;default:this.limbs=[0]}return this},equals:function(e){"number"==typeof e&&(e=new this.d(e));var t,r=0;for(this.fullReduce(),e.fullReduce(),t=0;this.limbs.length>t||e.limbs.length>t;t++)r|=this.getLimb(t)^e.getLimb(t);return 0===r},getLimb:function(e){return e>=this.limbs.length?0:this.limbs[e]},greaterEquals:function(e){"number"==typeof e&&(e=new this.d(e));var t,r,n,a=0,i=0;for(t=Math.max(this.limbs.length,e.limbs.length)-1;t>=0;t--)r=this.getLimb(t),n=e.getLimb(t),i|=n-r&~a,a|=r-n&~i;return(i|~a)>>>31},toString:function(){this.fullReduce();var e,t,r="",n=this.limbs;for(e=0;this.limbs.length>e;e++){for(t=n[e].toString(16);this.limbs.length-1>e&&6>t.length;)t="0"+t;r=t+r}return"0x"+r},addM:function(e){"object"!=typeof e&&(e=new this.d(e));var t=this.limbs,r=e.limbs;for(e=t.length;r.length>e;e++)t[e]=0;for(e=0;r.length>e;e++)t[e]+=r[e];return this},doubleM:function(){var e,t,r=0,n=this.radix,a=this.radixMask,i=this.limbs;for(e=0;i.length>e;e++)t=i[e],t=t+t+r,i[e]=t&a,r=t>>n;return r&&i.push(r),this},halveM:function(){var e,t,r=0,n=this.radix,a=this.limbs;for(e=a.length-1;e>=0;e--)t=a[e],a[e]=t+r>>1,r=(1&t)<<n;return a[a.length-1]||a.pop(),this},subM:function(e){"object"!=typeof e&&(e=new this.d(e));var t=this.limbs,r=e.limbs;for(e=t.length;r.length>e;e++)t[e]=0;for(e=0;r.length>e;e++)t[e]-=r[e];return this},mod:function(e){var t=!this.greaterEquals(new h.bn(0));e=new h.bn(e).normalize();var r=new h.bn(this).normalize(),n=0;for(t&&(r=new h.bn(0).subM(r).normalize());r.greaterEquals(e);n++)e.doubleM();for(t&&(r=e.sub(r).normalize());n>0;n--)e.halveM(),r.greaterEquals(e)&&r.subM(e).normalize();return r.trim()},inverseMod:function(e){var t,r=new h.bn(1),n=new h.bn(0),a=new h.bn(this),i=new h.bn(e),s=1;if(!(1&e.limbs[0]))throw new h.exception.invalid("inverseMod: p must be odd");do for(1&a.limbs[0]&&(a.greaterEquals(i)||(t=a,a=i,i=t,t=r,r=n,n=t),a.subM(i),a.normalize(),r.greaterEquals(n)||r.addM(e),r.subM(n)),a.halveM(),1&r.limbs[0]&&r.addM(e),r.normalize(),r.halveM(),t=s=0;a.limbs.length>t;t++)s|=a.limbs[t];while(s);if(!i.equals(1))throw new h.exception.invalid("inverseMod: p and x must be relatively prime");return n},add:function(e){return this.copy().addM(e)},sub:function(e){return this.copy().subM(e)},mul:function(e){"number"==typeof e&&(e=new this.d(e));var t,r,n=this.limbs,a=e.limbs,i=n.length,s=a.length,o=new this.d,c=o.limbs,u=this.maxMul;for(t=0;this.limbs.length+e.limbs.length+1>t;t++)c[t]=0;for(t=0;i>t;t++){for(r=n[t],e=0;s>e;e++)c[t+e]+=r*a[e];--u||(u=this.maxMul,o.cnormalize())}return o.cnormalize().reduce()},square:function(){return this.mul(this)},power:function(e){"number"==typeof e?e=[e]:e.limbs!==o&&(e=e.normalize().limbs);var t,r,n=new this.d(1),a=this;for(t=0;e.length>t;t++)for(r=0;this.radix>r;r++)e[t]&1<<r&&(n=n.mul(a)),a=a.square();return n},mulmod:function(e,t){return this.mod(t).mul(e.mod(t)).mod(t)},powermod:function(e,t){for(var r=new h.bn(1),n=new h.bn(this),a=new h.bn(e);1&a.limbs[0]&&(r=r.mulmod(n,t)),a.halveM(),!a.equals(0);)n=n.mulmod(n,t);return r.normalize().reduce()},trim:function(){var e,t=this.limbs;do e=t.pop();while(t.length&&0===e);return t.push(e),this},reduce:function(){return this},fullReduce:function(){return this.normalize()},normalize:function(){var e,t,r=0,n=this.ipv,a=this.limbs,i=a.length,s=this.radixMask;for(e=0;i>e||0!==r&&-1!==r;e++)r=(a[e]||0)+r,t=a[e]=r&s,r=(r-t)*n;return-1===r&&(a[e-1]-=this.placeVal),this},cnormalize:function(){var e,t,r=0,n=this.ipv,a=this.limbs,i=a.length,s=this.radixMask;for(e=0;i-1>e;e++)r=a[e]+r,t=a[e]=r&s,r=(r-t)*n;return a[e]+=r,this},toBits:function(e){this.fullReduce(),e=e||this.exponent||this.bitLength();var t=Math.floor((e-1)/24),r=h.bitArray,n=[r.partial((-8&e+7)%this.radix||this.radix,this.getLimb(t))];for(t--;t>=0;t--)n=r.concat(n,[r.partial(Math.min(this.radix,e),this.getLimb(t))]),e-=this.radix;return n},bitLength:function(){this.fullReduce();for(var e=this.radix*(this.limbs.length-1),t=this.limbs[this.limbs.length-1];t;t>>>=1)e++;return-8&e+7}},h.bn.fromBits=function(e){var t=new this,r=[],n=h.bitArray,a=this.prototype,i=Math.min(this.bitLength||4294967296,n.bitLength(e)),s=i%a.radix||a.radix;for(r[0]=n.extract(e,0,s);i>s;s+=a.radix)r.unshift(n.extract(e,s,a.radix));return t.limbs=r,t},h.bn.prototype.ipv=1/(h.bn.prototype.placeVal=Math.pow(2,h.bn.prototype.radix)),h.bn.prototype.radixMask=(1<<h.bn.prototype.radix)-1,h.bn.pseudoMersennePrime=function(e,t){function r(e){this.initWith(e)}var n,a,i=r.prototype=new h.bn;for(n=i.modOffset=Math.ceil(a=e/i.radix),i.exponent=e,i.offset=[],i.factor=[],i.minOffset=n,i.fullMask=0,i.fullOffset=[],i.fullFactor=[],i.modulus=r.modulus=new h.bn(Math.pow(2,e)),i.fullMask=0|-Math.pow(2,e%i.radix),n=0;t.length>n;n++)i.offset[n]=Math.floor(t[n][0]/i.radix-a),i.fullOffset[n]=Math.ceil(t[n][0]/i.radix-a),i.factor[n]=t[n][1]*Math.pow(.5,e-t[n][0]+i.offset[n]*i.radix),i.fullFactor[n]=t[n][1]*Math.pow(.5,e-t[n][0]+i.fullOffset[n]*i.radix),i.modulus.addM(new h.bn(Math.pow(2,t[n][0])*t[n][1])),i.minOffset=Math.min(i.minOffset,-i.offset[n]);return i.d=r,i.modulus.cnormalize(),i.reduce=function(){var e,t,r,n,a=this.modOffset,i=this.limbs,s=this.offset,o=this.offset.length,c=this.factor;for(e=this.minOffset;i.length>a;){for(r=i.pop(),n=i.length,t=0;o>t;t++)i[n+s[t]]-=c[t]*r;e--,e||(i.push(0),this.cnormalize(),e=this.minOffset)}return this.cnormalize(),this},i.V=-1===i.fullMask?i.reduce:function(){var e,t,r=this.limbs,n=r.length-1;if(this.reduce(),n===this.modOffset-1){for(t=r[n]&this.fullMask,r[n]-=t,e=0;this.fullOffset.length>e;e++)r[n+this.fullOffset[e]]-=this.fullFactor[e]*t;this.normalize()}},i.fullReduce=function(){var e,t;for(this.V(),this.addM(this.modulus),this.addM(this.modulus),this.normalize(),this.V(),t=this.limbs.length;this.modOffset>t;t++)this.limbs[t]=0;for(e=this.greaterEquals(this.modulus),t=0;this.limbs.length>t;t++)this.limbs[t]-=this.modulus.limbs[t]*e;return this.cnormalize(),this},i.inverse=function(){return this.power(this.modulus.sub(2))},r.fromBits=h.bn.fromBits,r};var p=h.bn.pseudoMersennePrime;h.bn.prime={p127:p(127,[[0,-1]]),p25519:p(255,[[0,-19]]),p192k:p(192,[[32,-1],[12,-1],[8,-1],[7,-1],[6,-1],[3,-1],[0,-1]]),p224k:p(224,[[32,-1],[12,-1],[11,-1],[9,-1],[7,-1],[4,-1],[1,-1],[0,-1]]),p256k:p(256,[[32,-1],[9,-1],[8,-1],[7,-1],[6,-1],[4,-1],[0,-1]]),p192:p(192,[[0,-1],[64,-1]]),p224:p(224,[[0,1],[96,-1]]),p256:p(256,[[0,-1],[96,1],[192,1],[224,-1]]),p384:p(384,[[0,-1],[32,1],[96,-1],[128,-1]]),p521:p(521,[[0,-1]])},h.bn.random=function(e,t){"object"!=typeof e&&(e=new h.bn(e));for(var r,n,a=e.limbs.length,i=e.limbs[a-1]+1,s=new h.bn;;){do r=h.random.randomWords(a,t),0>r[a-1]&&(r[a-1]+=4294967296);while(Math.floor(r[a-1]/i)===Math.floor(4294967296/i));for(r[a-1]%=i,n=0;a-1>n;n++)r[n]&=e.radixMask;if(s.limbs=r,!s.greaterEquals(e))return s}},h.ecc={},h.ecc.point=function(e,t,r){t===o?this.isIdentity=c:(this.x=t,this.y=r,this.isIdentity=u),this.curve=e},h.ecc.point.prototype={toJac:function(){return new h.ecc.pointJac(this.curve,this.x,this.y,new this.curve.field(1))},mult:function(e){return this.toJac().mult(e,this).toAffine()},mult2:function(e,t,r){return this.toJac().mult2(e,this,t,r).toAffine()},multiples:function(){var e,t,r;if(this.S===o)for(r=this.toJac().doubl(),e=this.S=[new h.ecc.point(this.curve),this,r.toAffine()],t=3;16>t;t++)r=r.add(this),e.push(r.toAffine());return this.S},isValid:function(){return this.y.square().equals(this.curve.b.add(this.x.mul(this.curve.a.add(this.x.square()))))},toBits:function(){return h.bitArray.concat(this.x.toBits(),this.y.toBits())}},h.ecc.pointJac=function(e,t,r,n){t===o?this.isIdentity=c:(this.x=t,this.y=r,this.z=n,this.isIdentity=u),this.curve=e},h.ecc.pointJac.prototype={add:function(e){var t,r,n,a;if(this.curve!==e.curve)throw"sjcl['ecc']['add'](): Points must be on the same curve to add them!";return this.isIdentity?e.toJac():e.isIdentity?this:(t=this.z.square(),r=e.x.mul(t).subM(this.x),r.equals(0)?this.y.equals(e.y.mul(t.mul(this.z)))?this.doubl():new h.ecc.pointJac(this.curve):(t=e.y.mul(t.mul(this.z)).subM(this.y),n=r.square(),e=t.square(),a=r.square().mul(r).addM(this.x.add(this.x).mul(n)),e=e.subM(a),t=this.x.mul(n).subM(e).mul(t),n=this.y.mul(r.square().mul(r)),t=t.subM(n),r=this.z.mul(r),new h.ecc.pointJac(this.curve,e,t,r)))},doubl:function(){if(this.isIdentity)return this;var e=this.y.square(),t=e.mul(this.x.mul(4)),r=e.square().mul(8),e=this.z.square(),n=""+this.curve.a==""+new h.bn(-3)?this.x.sub(e).mul(3).mul(this.x.add(e)):this.x.square().mul(3).add(e.square().mul(this.curve.a)),e=n.square().subM(t).subM(t),t=t.sub(e).mul(n).subM(r),r=this.y.add(this.y).mul(this.z);return new h.ecc.pointJac(this.curve,e,t,r)},toAffine:function(){if(this.isIdentity||this.z.equals(0))return new h.ecc.point(this.curve);var e=this.z.inverse(),t=e.square();return new h.ecc.point(this.curve,this.x.mul(t).fullReduce(),this.y.mul(t.mul(e)).fullReduce())},mult:function(e,t){"number"==typeof e?e=[e]:e.limbs!==o&&(e=e.normalize().limbs);var r,n,a=new h.ecc.point(this.curve).toJac(),i=t.multiples();for(r=e.length-1;r>=0;r--)for(n=h.bn.prototype.radix-4;n>=0;n-=4)a=a.doubl().doubl().doubl().doubl().add(i[15&e[r]>>n]);return a},mult2:function(e,t,r,n){"number"==typeof e?e=[e]:e.limbs!==o&&(e=e.normalize().limbs),"number"==typeof r?r=[r]:r.limbs!==o&&(r=r.normalize().limbs);var a,i=new h.ecc.point(this.curve).toJac();t=t.multiples();var s,c,u=n.multiples();for(n=Math.max(e.length,r.length)-1;n>=0;n--)for(s=0|e[n],c=0|r[n],a=h.bn.prototype.radix-4;a>=0;a-=4)i=i.doubl().doubl().doubl().doubl().add(t[15&s>>a]).add(u[15&c>>a]);return i},isValid:function(){var e=this.z.square(),t=e.square(),e=t.mul(e);return this.y.square().equals(this.curve.b.mul(e).add(this.x.mul(this.curve.a.mul(t).add(this.x.square()))))}},h.ecc.curve=function(e,t,r,n,a,i){this.field=e,this.r=new h.bn(t),this.a=new e(r),this.b=new e(n),this.G=new h.ecc.point(this,new e(a),new e(i))},h.ecc.curve.prototype.fromBits=function(e){var t=h.bitArray,r=-8&this.field.prototype.exponent+7;if(e=new h.ecc.point(this,this.field.fromBits(t.bitSlice(e,0,r)),this.field.fromBits(t.bitSlice(e,r,2*r))),!e.isValid())throw new h.exception.corrupt("not on the curve!");return e},h.ecc.curves={c192:new h.ecc.curve(h.bn.prime.p192,"0xffffffffffffffffffffffff99def836146bc9b1b4d22831",-3,"0x64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1","0x188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012","0x07192b95ffc8da78631011ed6b24cdd573f977a11e794811"),c224:new h.ecc.curve(h.bn.prime.p224,"0xffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d",-3,"0xb4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4","0xb70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21","0xbd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34"),c256:new h.ecc.curve(h.bn.prime.p256,"0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551",-3,"0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b","0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296","0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),c384:new h.ecc.curve(h.bn.prime.p384,"0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973",-3,"0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef","0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7","0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f"),k192:new h.ecc.curve(h.bn.prime.p192k,"0xfffffffffffffffffffffffe26f2fc170f69466a74defd8d",0,3,"0xdb4ff10ec057e9ae26b07d0280b7f4341da5d1b1eae06c7d","0x9b2f2f6d9c5628a7844163d015be86344082aa88d95e2f9d"),k224:new h.ecc.curve(h.bn.prime.p224k,"0x010000000000000000000000000001dce8d2ec6184caf0a971769fb1f7",0,5,"0xa1455b334df099df30fc28a169a467e9e47075a90f7e650eb6b7a45c","0x7e089fed7fba344282cafbd6f7e319f7c0b0bd59e2ca4bdb556d61a5"),k256:new h.ecc.curve(h.bn.prime.p256k,"0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",0,7,"0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},h.ecc.P=function(e){h.ecc[e]={publicKey:function(e,t){this.f=e,this.i=e.r.bitLength(),this.A=t instanceof Array?e.fromBits(t):t,this.get=function(){var e=this.A.toBits(),t=h.bitArray.bitLength(e),r=h.bitArray.bitSlice(e,0,t/2),e=h.bitArray.bitSlice(e,t/2);return{x:r,y:e}}},secretKey:function(e,t){this.f=e,this.i=e.r.bitLength(),this.t=t,this.get=function(){return this.t.toBits()}},generateKeys:function(t,r,n){if(t===o&&(t=256),"number"==typeof t&&(t=h.ecc.curves["c"+t],t===o))throw new h.exception.invalid("no such curve");return n===o&&(n=h.bn.random(t.r,r)),r=t.G.mult(n),{pub:new h.ecc[e].publicKey(t,r),sec:new h.ecc[e].secretKey(t,n)}}}},h.ecc.P("elGamal"),h.ecc.elGamal.publicKey.prototype={kem:function(e){e=h.bn.random(this.f.r,e);var t=this.f.G.mult(e).toBits();return{key:h.hash.sha256.hash(this.A.mult(e).toBits()),tag:t}}},h.ecc.elGamal.secretKey.prototype={unkem:function(e){return h.hash.sha256.hash(this.f.fromBits(e).mult(this.t).toBits())},dh:function(e){return h.hash.sha256.hash(e.A.mult(this.t).toBits())}},h.ecc.P("ecdsa"),h.ecc.ecdsa.secretKey.prototype={sign:function(e,t,r,n){h.bitArray.bitLength(e)>this.i&&(e=h.bitArray.clamp(e,this.i));var a=this.f.r,i=a.bitLength();return n=n||h.bn.random(a.sub(1),t).add(1),t=this.f.G.mult(n).x.mod(a),e=h.bn.fromBits(e).add(t.mul(this.t)),r=r?e.inverseMod(a).mul(n).mod(a):e.mul(n.inverseMod(a)).mod(a),h.bitArray.concat(t.toBits(i),r.toBits(i))}},h.ecc.ecdsa.publicKey.prototype={verify:function(e,t,r){h.bitArray.bitLength(e)>this.i&&(e=h.bitArray.clamp(e,this.i));var n=h.bitArray,a=this.f.r,i=this.i,s=h.bn.fromBits(n.bitSlice(t,0,i)),n=h.bn.fromBits(n.bitSlice(t,i,2*i)),u=r?n:n.inverseMod(a),i=h.bn.fromBits(e).mul(u).mod(a),u=s.mul(u).mod(a),i=this.f.G.mult2(i,u,this.A).x;if(s.equals(0)||n.equals(0)||s.greaterEquals(a)||n.greaterEquals(a)||!i.equals(s)){if(r===o)return this.verify(e,t,c);throw new h.exception.corrupt("signature didn't check out")}return c}},AeroGear.Pipeline=function(e){return this instanceof AeroGear.Pipeline?(AeroGear.Core.call(this),this.config=e||{},this.lib="Pipeline",this.type=e?e.type||"Rest":"Rest",this.collectionName="pipes",this.add(e),t):new AeroGear.Pipeline(e)},AeroGear.Pipeline.prototype=AeroGear.Core,AeroGear.Pipeline.constructor=AeroGear.Pipeline,AeroGear.Pipeline.adapters={},AeroGear.Pipeline.adapters.Rest=function(e,r){if(!(this instanceof AeroGear.Pipeline.adapters.Rest))return new AeroGear.Pipeline.adapters.Rest(e,r);r=r||{};var n=r.endpoint||e,a={url:r.baseURL?r.baseURL+n:n,contentType:r.contentType||"application/json",dataType:r.dataType||"json",xhrFields:r.xhrFields},i=r.recordId||"id",s=r.authenticator||null,o=r.authorizer||null,c=r.pageConfig,u=r.timeout?1e3*r.timeout:6e4;this.getAjaxSettings=function(){return a},this.getAuthenticator=function(){return s},this.getAuthorizer=function(){return o},this.getRecordId=function(){return i},this.getTimeout=function(){return u},this.getPageConfig=function(){return c},this.updatePageConfig=function(e,t){t?(c={},c.metadataLocation=e.metadataLocation?e.metadataLocation:"webLinking",c.previousIdentifier=e.previousIdentifier?e.previousIdentifier:"previous",c.nextIdentifier=e.nextIdentifier?e.nextIdentifier:"next",c.parameterProvider=e.parameterProvider?e.parameterProvider:null):jQuery.extend(c,e)},c&&this.updatePageConfig(c,!0),this.webLinkingPageParser=function(e){var r,n,a,i,s,o={};n=e.getResponseHeader("Link").split(",");
|
|
for(var u in n){r=n[u].trim().split(";");for(var h in r)a=r[h].trim(),0===a.indexOf("<")&&a.lastIndexOf(">")===r[h].length-1?i=a.substr(1,a.length-2).split("?")[1]:0===a.indexOf("rel=")&&(a.indexOf(c.previousIdentifier)>=0?s=c.previousIdentifier:a.indexOf(c.nextIdentifier)>=0&&(s=c.nextIdentifier));s&&(o[s]=i,s=t)}return o},this.headerPageParser=function(e){var t=e.getResponseHeader(c.previousIdentifier),r=e.getResponseHeader(c.nextIdentifier),n={},a={};return c.parameterProvider?(n=c.parameterProvider(e),a[c.previousIdentifier]=n[c.previousIdentifier],a[c.nextIdentifier]=n[c.nextIdentifier]):(a[c.previousIdentifier]=t?t.split("?")[1]:null,a[c.nextIdentifier]=r?r.split("?")[1]:null),a},this.bodyPageParser=function(e){var t={},r={};return c.parameterProvider?(r=c.parameterProvider(e),t[c.previousIdentifier]=r[c.previousIdentifier],t[c.nextIdentifier]=r[c.nextIdentifier]):(t[c.previousIdentifier]=e[c.previousIdentifier],t[c.nextIdentifier]=e[c.nextIdentifier]),t},this.formatJSONError=function(e){if("json"===this.getAjaxSettings().dataType)try{e.responseJSON=JSON.parse(e.responseText)}catch(t){}return e}},AeroGear.Pipeline.adapters.Rest.prototype.read=function(e){var r,n,a,i,s=this,o=this.getRecordId(),c=this.getAjaxSettings(),u=this.getPageConfig();if(e=e?e:{},e.query=e.query?e.query:{},r=e[o]?c.url+"/"+e[o]:c.url,u&&e.paging!==!1){e.paging||(e.paging={offset:e.offsetValue||0,limit:e.limitValue||10}),e.query=e.query||{};for(var h in e.paging)e.query[h]=e.paging[h]}return n=function(r,n,a){var i;u&&e.paging!==!1&&(i=s[u.metadataLocation+"PageParser"]("body"===u.metadataLocation?r:a),["previous","next"].forEach(function(n){r[n]=function(e,r,n){return function(a){return n.paging=!0,n.offsetValue=n.limitValue=t,n.query=r,n.success=a&&a.success?a.success:n.success,n.error=a&&a.error?a.error:n.error,e.read(n)}}(s,i[u[n+"Identifier"]],e)})),e.success&&e.success.apply(this,arguments)},a=function(t){t=s.formatJSONError(t),e.error&&e.error.apply(this,arguments)},i={type:"GET",data:e.query,success:n,error:a,url:r,statusCode:e.statusCode,complete:e.complete,headers:e.headers,timeout:this.getTimeout()},e.jsonp&&(i.dataType="jsonp",i.jsonp=e.jsonp.callback?e.jsonp.callback:"callback",e.jsonp.customCallback&&(i.jsonpCallback=e.jsonp.customCallback)),this.getAuthorizer()?this.getAuthorizer().execute(jQuery.extend({},e,i)):jQuery.ajax(jQuery.extend({},this.getAjaxSettings(),i))},AeroGear.Pipeline.adapters.Rest.prototype.save=function(t,r){var n,a,i,s,o,c,u,h=this,f=this.getRecordId(),l=this.getAjaxSettings();if(t=t||{},r=r||{},n=t[f]?"PUT":"POST",a=t[f]?l.url+"/"+t[f]:l.url,i=function(){r.success&&r.success.apply(this,arguments)},s=function(e){e=h.formatJSONError(e),r.error&&r.error.apply(this,arguments)},o=jQuery.extend({},l,{data:t,type:n,url:a,success:i,error:s,statusCode:r.statusCode,complete:r.complete,headers:r.headers,timeout:this.getTimeout()}),"FormData"in e){c=new FormData;for(u in t)c.append(u,t[u]),(t[u]instanceof File||t[u]instanceof Blob)&&(o.contentType=!1,o.processData=!1);o.contentType===!1&&(o.data=c),o.xhr=function(){var e=jQuery.ajaxSettings.xhr();return e.upload&&e.upload.addEventListener("progress",function(){r.progress&&r.progress.apply(this,arguments)},!1),e}}return"application/json"===o.contentType&&o.data&&"string"!=typeof o.data&&(o.data=JSON.stringify(o.data)),this.getAuthorizer()?this.getAuthorizer().execute(jQuery.extend({},r,o)):jQuery.ajax(jQuery.extend({},this.getAjaxSettings(),o))},AeroGear.Pipeline.adapters.Rest.prototype.remove=function(e,t){var r,n,a,i,s,o=this,c=this.getRecordId(),u=this.getAjaxSettings(),h="";return"string"==typeof e||"number"==typeof e?r=e:e&&e[c]?r=e[c]:e&&!t&&(t=e),t=t||{},h=r?"/"+r:"",n=u.url+h,a=function(){t.success&&t.success.apply(this,arguments)},i=function(e){e=o.formatJSONError(e),t.error&&t.error.apply(this,arguments)},s={type:"DELETE",url:n,success:a,error:i,statusCode:t.statusCode,complete:t.complete,headers:t.headers,timeout:this.getTimeout()},this.getAuthorizer()?this.getAuthorizer().execute(jQuery.extend({},t,s)):jQuery.ajax(jQuery.extend({},this.getAjaxSettings(),s))},AeroGear.DataManager=function(e){return this instanceof AeroGear.DataManager?(this.add=function(e){e=e||{};var t,r,n,a,i;e=AeroGear.isArray(e)?e:[e],e=e.map(function(e){if(i=e.settings||{},n=i.fallback===!1?!1:!0,n&&(a=i.preferred?i.preferred:AeroGear.DataManager.preferred,"string"!=typeof e&&(r=e.type||"Memory",!(r in AeroGear.DataManager.validAdapters))))for(t=0;a.length>t;t++)if(a[t]in AeroGear.DataManager.validAdapters)return("IndexedDB"===r||"WebSQL"===r)&&(e.settings=AeroGear.extend(e.settings||{},{async:!0})),e.type=a[t],e;return e},this),AeroGear.Core.call(this),this.add(e),this.add=this._add},this._add=this.add,this.remove=function(e){AeroGear.Core.call(this),this.remove(e),this.remove=this._remove},this._remove=this.remove,this.lib="DataManager",this.type=e?e.type||"Memory":"Memory",this.collectionName="stores",this.add(e),t):new AeroGear.DataManager(e)},AeroGear.DataManager.prototype=AeroGear.Core,AeroGear.DataManager.constructor=AeroGear.DataManager,AeroGear.DataManager.validAdapters={},AeroGear.DataManager.preferred=["IndexedDB","WebSQL","SessionLocal","Memory"],AeroGear.DataManager.validateAdapter=function(e,t){t.isValid()&&(AeroGear.DataManager.validAdapters[e]=t)},AeroGear.DataManager.adapters={},AeroGear.DataManager.STATUS_NEW=1,AeroGear.DataManager.STATUS_MODIFIED=2,AeroGear.DataManager.STATUS_REMOVED=0,AeroGear.DataManager.adapters.base=function(t,r){if(this instanceof AeroGear.DataManager.adapters.base)throw"Invalid instantiation of base class AeroGear.DataManager.adapters.base";r=r||{};var n=null,a=r.recordId?r.recordId:"id",i=r.crypto||{},s=i.options||{};this.getData=function(){return n||[]},this.setData=function(e){n=e},this.getRecordId=function(){return a},this.always=function(e,t,r){r&&r.call(this,e,t)},this.encrypt=function(r){var n;return i.agcrypto?(s.data=h.codec.utf8String.toBits(JSON.stringify(r)),n={id:r[a],data:i.agcrypto.encrypt(s)},e.localStorage.setItem("ag-"+t+"-IV",JSON.stringify({id:i.agcrypto.getIV()})),n):r},this.decrypt=function(r,n){var a,o;return i.agcrypto?(o=JSON.parse(e.localStorage.getItem("ag-"+t+"-IV"))||{},s.IV=o.id,r=AeroGear.isArray(r)?r:[r],a=r.map(function(e){return s.data=e.data,JSON.parse(h.codec.utf8String.fromBits(i.agcrypto.decrypt(s)))}),n?a[0]:a):r}},AeroGear.DataManager.adapters.Memory=function(e,r){return this instanceof AeroGear.DataManager.adapters.Memory?(AeroGear.DataManager.adapters.base.apply(this,arguments),this.emptyData=function(){this.setData(null)},this.addDataRecord=function(e){this.getData().push(e)},this.updateDataRecord=function(e,t){this.getData()[e]=t},this.removeDataRecord=function(e){this.getData().splice(e,1)},this.always=function(e,t,r){r&&r.call(this,e,t)},this.getAsync=function(){return r&&r.async?!0:!1},this.open=function(e){return jQuery.Deferred().resolve(t,"success",e&&e.success)},this.close=function(){},this.traverseObjects=function(e,t,r){for(;"object"==typeof t&&r;)e=Object.keys(t)[0],t=t[e],r=r[e];return t===r?!0:!1},t):new AeroGear.DataManager.adapters.Memory(e,r)},AeroGear.DataManager.adapters.Memory.isValid=function(){return!0},AeroGear.DataManager.adapters.Memory.prototype.read=function(e,r){var n,a={},i=jQuery.Deferred(),s=this.getAsync();return a[this.getRecordId()]=e,e?s?this.filter(a).then(function(e){n=e}):n=this.filter(a):n=this.getData(),s?(i.always(this.always),i.resolve(n,"success",r?r.success:t)):n},AeroGear.DataManager.adapters.Memory.prototype.save=function(e,r){var n=!1,a=jQuery.Deferred(),i=this.getAsync();if(e=AeroGear.isArray(e)?e:[e],r&&r.reset)this.setData(e);else if(this.getData()&&0!==this.getData().length)for(var s=0;e.length>s;s++){for(var o in this.getData())if(this.getData()[o][this.getRecordId()]===e[s][this.getRecordId()]){this.updateDataRecord(o,e[s]),n=!0;break}n||this.addDataRecord(e[s]),n=!1}else this.setData(e);return i?(a.always(this.always),a.resolve(this.getData(),"success",r?r.success:t)):this.getData()},AeroGear.DataManager.adapters.Memory.prototype.remove=function(e,r){var n,a,i,s=jQuery.Deferred(),o=this.getAsync();if(s.always(this.always),!e)return this.emptyData(),o?s.resolve(this.getData(),"success",r?r.success:t):this.getData();e=AeroGear.isArray(e)?e:[e];for(var c=0;e.length>c;c++){if("string"==typeof e[c]||"number"==typeof e[c])n=e[c];else{if(!e)continue;n=e[c][this.getRecordId()]}a=this.getData(!0);for(i in a)a[i][this.getRecordId()]===n&&this.removeDataRecord(i)}return o?s.resolve(this.getData(),"success",r?r.success:t):this.getData()},AeroGear.DataManager.adapters.Memory.prototype.filter=function(e,r,n){var a,i,s,o,c,u=this,h=jQuery.Deferred(),f=this.getAsync();return h.always(this.always),e?(a=this.getData().filter(function(t){var n,a,h=r?!1:!0,f=Object.keys(e);for(i=0;f.length>i;i++){if(e[f[i]].data)for(n=e[f[i]],a=n.matchAny?!1:!0,s=0;n.data.length>s;s++)if(AeroGear.isArray(t[f[i]]))if(t[f[i]].length){if(0===jQuery(t[f]).not(n.data).length&&0===jQuery(n.data).not(t[f]).length){a=!0;break}for(o=0;t[f[i]].length>o;o++){if(n.matchAny&&n.data[s]===t[f[i]][o]){if(a=!0,r)break;for(c=0;t[f[i]].length>c;c++)if(!r&&n.data[s]!==t[f[i]][c]){a=!1;break}}if(!n.matchAny&&n.data[s]!==t[f[i]][o]){a=!1;break}}}else a=!1;else if("object"==typeof n.data[s]){if(n.matchAny&&u.traverseObjects(f[i],n.data[s],t[f[i]])){a=!0;break}if(!n.matchAny&&!u.traverseObjects(f[i],n.data[s],t[f[i]])){a=!1;break}}else{if(n.matchAny&&n.data[s]===t[f[i]]){a=!0;break}if(!n.matchAny&&n.data[s]!==t[f[i]]){a=!1;break}}else if(AeroGear.isArray(t[f[i]]))if(a=r?!1:!0,t[f[i]].length)for(s=0;t[f[i]].length>s;s++){if(r&&e[f[i]]===t[f[i]][s]){a=!0;break}if(!r&&e[f[i]]!==t[f[i]][s]){a=!1;break}}else a=!1;else a="object"==typeof e[f[i]]?u.traverseObjects(f[i],e[f[i]],t[f[i]]):e[f[i]]===t[f[i]]?!0:!1;if(r&&a){h=!0;break}if(!r&&!a){h=!1;break}}return h}),f?h.resolve(a,"success",n?n.success:t):a):(a=this.getData()||[],f?h.resolve(a,"success",n?n.success:t):a)},AeroGear.DataManager.validateAdapter("Memory",AeroGear.DataManager.adapters.Memory),AeroGear.DataManager.adapters.SessionLocal=function(t,r){if(!(this instanceof AeroGear.DataManager.adapters.SessionLocal))return new AeroGear.DataManager.adapters.SessionLocal(t,r);AeroGear.DataManager.adapters.Memory.apply(this,arguments);var n=r.storageType||"sessionStorage",a=t,i=document.location.pathname.replace(/[\/\.]/g,"-"),s=a+i,o=e[n].getItem(s),c=o?this.decrypt(JSON.parse(o),!0):null;c&&AeroGear.DataManager.adapters.Memory.prototype.save.call(this,c,!0),this.getStoreType=function(){return n},this.getStoreKey=function(){return s}},AeroGear.DataManager.adapters.SessionLocal.isValid=function(){return!(!e.localStorage||!e.sessionStorage)},AeroGear.DataManager.adapters.SessionLocal.prototype=Object.create(new AeroGear.DataManager.adapters.Memory,{save:{value:function(r,n){var a,i=jQuery.Deferred(),s=n&&n.reset?n.reset:!1,o=e[this.getStoreType()].getItem(this.getStoreKey()),c=this.getAsync();c?AeroGear.DataManager.adapters.Memory.prototype.save.apply(this,[arguments[0],{reset:s,async:c}]).then(function(e){a=e}):a=AeroGear.DataManager.adapters.Memory.prototype.save.apply(this,[arguments[0],{reset:s}]),i.always(this.always);try{e[this.getStoreType()].setItem(this.getStoreKey(),JSON.stringify(this.encrypt(a))),n&&n.success&&n.storageSuccess(a)}catch(u){if(o=o?JSON.parse(o):[],c?AeroGear.DataManager.adapters.Memory.prototype.save.apply(this,[o,{reset:s,async:c}]).then(function(e){a=e}):a=AeroGear.DataManager.adapters.Memory.prototype.save.apply(this,[o,{reset:s}]),n&&n.error)return c?i.reject(r,"error",n?n.error:t):n.error(u,r);throw c&&i.reject(),u}return c?i.resolve(a,"success",n?n.success:t):a},enumerable:!0,configurable:!0,writable:!0},remove:{value:function(r,n){var a,i=jQuery.Deferred(),s=this.getAsync();return s?AeroGear.DataManager.adapters.Memory.prototype.remove.apply(this,[arguments[0],{async:!0}]).then(function(e){a=e}):a=AeroGear.DataManager.adapters.Memory.prototype.remove.apply(this,arguments),e[this.getStoreType()].setItem(this.getStoreKey(),JSON.stringify(this.encrypt(a))),s?(i.always(this.always),i.resolve(a,status,n?n.success:t)):a},enumerable:!0,configurable:!0,writable:!0}}),AeroGear.DataManager.validateAdapter("SessionLocal",AeroGear.DataManager.adapters.SessionLocal),AeroGear.DataManager.adapters.IndexedDB=function(t,r){if(!e.indexedDB)throw"Your browser doesn't support IndexedDB";if(!(this instanceof AeroGear.DataManager.adapters.IndexedDB))return new AeroGear.DataManager.adapters.IndexedDB(t,r);AeroGear.DataManager.adapters.base.apply(this,arguments),r=r||{};var n,a=r.auto;this.getDatabase=function(){return n},this.setDatabase=function(e){n=e},this.getStoreName=function(){return t},this.getAsync=function(){return!0},this.run=function(e){var t=this;if(n)e.call(this,n);else{if(!a)throw"Database not opened";this.open().always(function(r,a){if("error"===a)throw"Database not opened";e.call(t,n)})}}},AeroGear.DataManager.adapters.IndexedDB.isValid=function(){return!!e.indexedDB},AeroGear.DataManager.adapters.IndexedDB.prototype.open=function(t){t=t||{};var r,n,a=this,i=this.getStoreName(),s=this.getRecordId(),o=jQuery.Deferred();return r=e.indexedDB.open(i),r.onsuccess=function(e){n=e.target.result,a.setDatabase(n),o.resolve(n,"success",t.success)},r.onerror=function(e){o.reject(e,"error",t.error)},r.onupgradeneeded=function(e){n=e.target.result,n.createObjectStore(i,{keyPath:s})},o.always(this.always),o.promise()},AeroGear.DataManager.adapters.IndexedDB.prototype.read=function(e,t){t=t||{};var r,n,a,i,s,o=this,c=[],u=(this.getDatabase(),this.getStoreName()),h=jQuery.Deferred();return s=function(s){s.objectStoreNames.contains(u)||h.resolve([],"success",t.success),r=s.transaction(u),n=r.objectStore(u),e?(i=n.get(e),i.onsuccess=function(){c.push(i.result)}):(a=n.openCursor(),a.onsuccess=function(e){var t=e.target.result;t&&(c.push(t.value),t.continue())}),r.oncomplete=function(){h.resolve(o.decrypt(c),"success",t.success)},r.onerror=function(e){h.reject(e,"error",t.error)}},this.run.call(this,s),h.always(this.always),h.promise()},AeroGear.DataManager.adapters.IndexedDB.prototype.save=function(e,t){t=t||{};var r,n,a,i=this,s=(this.getDatabase(),this.getStoreName()),o=jQuery.Deferred(),c=0;return a=function(a){if(r=a.transaction(s,"readwrite"),n=r.objectStore(s),t.reset&&n.clear(),AeroGear.isArray(e))for(c;e.length>c;c++)n.put(this.encrypt(e[c]));else n.put(this.encrypt(e));r.oncomplete=function(){i.read().done(function(e,r){"success"===r?o.resolve(e,r,t.success):o.reject(e,r,t.error)})},r.onerror=function(e){o.reject(e,"error",t.error)}},this.run.call(this,a),o.always(this.always),o.promise()},AeroGear.DataManager.adapters.IndexedDB.prototype.remove=function(e,t){t=t||{};var r,n,a,i=this,s=this.getDatabase(),o=this.getStoreName(),c=jQuery.Deferred(),u=0;return a=function(){if(n=s.transaction(o,"readwrite"),r=n.objectStore(o),e)for(e=AeroGear.isArray(e)?e:[e],u;e.length>u;u++)if("string"==typeof e[u]||"number"==typeof e[u])r.delete(e[u]);else{if(!e)continue;r.delete(e[u][this.getRecordId()])}else r.clear();n.oncomplete=function(){i.read().done(function(e,r){"success"===r?c.resolve(e,r,t.success):c.reject(e,r,t.error)})},n.onerror=function(e){c.reject(e,"error",t.error)}},this.run.call(this,a),c.always(this.always),c.promise()},AeroGear.DataManager.adapters.IndexedDB.prototype.filter=function(e,r,n){n=n||{};var a,i=this,s=jQuery.Deferred();return this.getDatabase(),a=function(){this.read().then(function(a,o){return"success"!==o?(s.reject(a,o,n.error),t):(AeroGear.DataManager.adapters.Memory.prototype.save.call(i,a,!0),AeroGear.DataManager.adapters.Memory.prototype.filter.call(i,e,r).then(function(e){s.resolve(e,"success",n.success)}),t)})},this.run.call(this,a),s.always(this.always),s.promise()},AeroGear.DataManager.adapters.IndexedDB.prototype.close=function(){var e=this.getDatabase();e&&e.close()},AeroGear.DataManager.validateAdapter("IndexedDB",AeroGear.DataManager.adapters.IndexedDB),AeroGear.DataManager.adapters.WebSQL=function(t,r){if(!e.openDatabase)throw"Your browser doesn't support WebSQL";if(!(this instanceof AeroGear.DataManager.adapters.WebSQL))return new AeroGear.DataManager.adapters.WebSQL(t,r);AeroGear.DataManager.adapters.base.apply(this,arguments),r=r||{};var n,a=r.auto;this.getDatabase=function(){return n},this.setDatabase=function(e){n=e},this.getStoreName=function(){return t},this.getAsync=function(){return!0},this.run=function(e){var t=this;if(n)e.call(this,n);else{if(!a)throw"Database not opened";this.open().always(function(r,a){if("error"===a)throw"Database not opened";e.call(t,n)})}}},AeroGear.DataManager.adapters.WebSQL.isValid=function(){return!!e.openDatabase},AeroGear.DataManager.adapters.WebSQL.prototype.open=function(t){t=t||{};var r,n,a,i=this,s="1",o=2097152,c=this.getRecordId(),u=this.getStoreName(),h=jQuery.Deferred();return a=e.openDatabase(u,s,"AeroGear WebSQL Store",o),n=function(e,r){h.reject(r,"error",t.error)},r=function(){i.setDatabase(a),h.resolve(a,"success",t.success)},a.transaction(function(e){e.executeSql("CREATE TABLE IF NOT EXISTS "+u+" ( "+c+" REAL UNIQUE, json)",[],r,n)}),h.always(this.always),h.promise()},AeroGear.DataManager.adapters.WebSQL.prototype.read=function(e,t){t=t||{};var r,n,a,i,s=this,o=[],c=this.getStoreName(),u=(this.getDatabase(),jQuery.Deferred()),h=0;return i=function(i){n=function(e,r){u.reject(r,"error",t.error)},r=function(e,r){var n=r.rows.length;for(h;n>h;h++)o.push(JSON.parse(r.rows.item(h).json));u.resolve(s.decrypt(o),"success",t.success)},a="SELECT * FROM "+c,e&&(a+=" WHERE ID = '"+e+"'"),i.transaction(function(e){e.executeSql(a,[],r,n)})},this.run.call(this,i),u.always(this.always),u.promise()},AeroGear.DataManager.adapters.WebSQL.prototype.save=function(e,t){t=t||{};var r,n,a,i=this,s=this.getRecordId(),o=(this.getDatabase(),this.getStoreName()),c=jQuery.Deferred();return a=function(a){r=function(e,r){c.reject(r,"error",t.error)},n=function(){i.read().done(function(e,r){"success"===r?c.resolve(e,r,t.success):c.reject(e,r,t.error)})},e=AeroGear.isArray(e)?e:[e],a.transaction(function(r){t.reset&&(r.executeSql("DROP TABLE "+o),r.executeSql("CREATE TABLE IF NOT EXISTS "+o+" ( "+s+" REAL UNIQUE, json)")),e.forEach(function(e){e=i.encrypt(e),r.executeSql("INSERT OR REPLACE INTO "+o+" ( id, json ) VALUES ( ?, ? ) ",[e[s],JSON.stringify(e)])})},r,n)},this.run.call(this,a),c.always(this.always),c.promise()},AeroGear.DataManager.adapters.WebSQL.prototype.remove=function(e,t){t=t||{};var r,n,a,i,s=this,o=this.getStoreName(),c=(this.getDatabase(),jQuery.Deferred()),u=0;return i=function(i){a=function(e,r){c.reject(r,"error",t.error)},n=function(){s.read().done(function(e,r){"success"===r?c.resolve(e,r,t.success):c.reject(e,r,t.error)})},r="DELETE FROM "+o,e?(e=AeroGear.isArray(e)?e:[e],i.transaction(function(t){for(u;e.length>u;u++)if("string"==typeof e[u]||"number"==typeof e[u])t.executeSql(r+" WHERE ID = ? ",[e[u]]);else{if(!e)continue;t.executeSql(r+" WHERE ID = ? ",[e[u][this.getRecordId()]])}},a,n)):i.transaction(function(e){e.executeSql(r,[],n,a)})},this.run.call(this,i),c.always(this.always),c.promise()},AeroGear.DataManager.adapters.WebSQL.prototype.filter=function(e,r,n){n=n||{};var a,i=this,s=jQuery.Deferred();return this.getDatabase(),a=function(){this.read().then(function(a,o){return"success"!==o?(s.reject(a,o,n.error),t):(AeroGear.DataManager.adapters.Memory.prototype.save.call(i,a,!0),AeroGear.DataManager.adapters.Memory.prototype.filter.call(i,e,r).then(function(e){s.resolve(e,"success",n.success)}),t)})},this.run.call(this,a),s.always(this.always),s.promise()},AeroGear.DataManager.validateAdapter("WebSQL",AeroGear.DataManager.adapters.WebSQL),AeroGear.Auth=function(e){return this instanceof AeroGear.Auth?(AeroGear.Core.call(this),this.lib="Auth",this.type=e?e.type||"Rest":"Rest",this.collectionName="modules",this.add(e),t):new AeroGear.Auth(e)},AeroGear.Auth.prototype=AeroGear.Core,AeroGear.Auth.constructor=AeroGear.Auth,AeroGear.Auth.adapters={},AeroGear.Auth.adapters.Rest=function(e,t){if(!(this instanceof AeroGear.Auth.adapters.Rest))return new AeroGear.Auth.adapters.Rest(e,t);t=t||{};var r=t.endpoints||{},n=e,a=t.baseURL||"";this.getSettings=function(){return t},this.getEndpoints=function(){return r},this.getName=function(){return n},this.getBaseURL=function(){return a},this.processOptions=function(e){var t={};return e.contentType&&(t.contentType=e.contentType),e.dataType&&(t.dataType=e.dataType),t.url=e.baseURL?e.baseURL:a,e.xhrFields&&(t.xhrFields=e.xhrFields),t}},AeroGear.Auth.adapters.Rest.prototype.enroll=function(e,t){t=t||{};var r=(this.getName(),this.getEndpoints()),n=function(){t.success&&t.success.apply(this,arguments)},a=function(e,r,n){var a;try{e.responseJSON=JSON.parse(e.responseText),a=[e,r,n]}catch(i){a=arguments}t.error&&t.error.apply(this,a)},i=jQuery.extend({},this.processOptions(t),{complete:t.complete,success:n,error:a,data:e});return i.url+=r.enroll?r.enroll:"auth/enroll","application/json"===i.contentType&&i.data&&"string"!=typeof i.data&&(i.data=JSON.stringify(i.data)),jQuery.ajax(jQuery.extend({},this.getSettings(),{type:"POST"},i))},AeroGear.Auth.adapters.Rest.prototype.login=function(e,t){t=t||{};var r=(this.getName(),this.getEndpoints()),n=function(){t.success&&t.success.apply(this,arguments)},a=function(e,r,n){var a;try{e.responseJSON=JSON.parse(e.responseText),a=[e,r,n]}catch(i){a=arguments}t.error&&t.error.apply(this,a)},i=jQuery.extend({},this.processOptions(t),{complete:t.complete,success:n,error:a,data:e});return i.url+=r.login?r.login:"auth/login","application/json"===i.contentType&&i.data&&"string"!=typeof i.data&&(i.data=JSON.stringify(i.data)),jQuery.ajax(jQuery.extend({},this.getSettings(),{type:"POST"},i))},AeroGear.Auth.adapters.Rest.prototype.logout=function(e){e=e||{};var t=(this.getName(),this.getEndpoints()),r=function(){e.success&&e.success.apply(this,arguments)},n=function(t,r,n){var a;try{t.responseJSON=JSON.parse(t.responseText),a=[t,r,n]}catch(i){a=arguments}e.error&&e.error.apply(this,a)},a=jQuery.extend({},this.processOptions(e),{complete:e.complete,success:r,error:n});return a.url+=t.logout?t.logout:"auth/logout",jQuery.ajax(jQuery.extend({},this.getSettings(),{type:"POST"},a))},AeroGear.Authorization=function(e){return this instanceof AeroGear.Authorization?(AeroGear.Core.call(this),this.lib="Authorization",this.type=e?e.type||"OAuth2":"OAuth2",this.collectionName="services",this.add(e),t):new AeroGear.Authorization(e)},AeroGear.Authorization.prototype=AeroGear.Core,AeroGear.Authorization.constructor=AeroGear.Authorization,AeroGear.Authorization.adapters={},AeroGear.Authorization.adapters.OAuth2=function(e,t){if(!(this instanceof AeroGear.Authorization.adapters.OAuth2))return new AeroGear.Authorization.adapters.OAuth2(e,t);t=t||{};var r,n=uuid(),a=t.clientId,i=t.redirectURL,s=t.validationEndpoint,o=t.scopes,c="ag-oauth2-"+a,u=t.authEndpoint+"?"+"response_type=token"+"&redirect_uri="+encodeURIComponent(i)+"&scope="+encodeURIComponent(o)+"&state="+encodeURIComponent(n)+"&client_id="+encodeURIComponent(a);this.getAccessToken=function(){return localStorage[c]&&(r=JSON.parse(localStorage[c]).accessToken),r},this.getState=function(){return n},this.getClientId=function(){return a},this.getLocalStorageName=function(){return c},this.getValidationEndpoint=function(){return s},this.createError=function(e){return e=e||{},AeroGear.extend(e,{authURL:u})},this.parseQueryString=function(e){for(var t,r={},n=e.substr(e.indexOf("#")+1),a=/([^&=]+)=([^&]*)/g;t=a.exec(n);)r[decodeURIComponent(t[1])]=decodeURIComponent(t[2]);return r}},AeroGear.Authorization.adapters.OAuth2.prototype.validate=function(e,r){r=r||{};var n,a,i=this,s=this.parseQueryString(e),o=this.getState();return a=function(){localStorage.setItem(i.getLocalStorageName(),JSON.stringify({accessToken:s.access_token})),r.success&&r.success.apply(this,arguments)},n=function(e){r.error&&r.error.call(this,i.createError(e))},s.error?(n.call(this,s),t):s.state!==o?(n.call(this,{error:"invalid_request",state:o,error_description:"state's do not match"}),t):(this.getValidationEndpoint()?jQuery.ajax({url:this.getValidationEndpoint()+"?access_token="+s.access_token,success:function(e){return i.getClientId()!==e.audience?(n.call(this,{error:"invalid_token"}),t):(a.call(this,s),t)},error:function(){n.call(this,{error:"invalid_token"})}}):a.call(this,s),t)},AeroGear.Authorization.adapters.OAuth2.prototype.execute=function(e){e=e||{};var t,r,n=this,a=e.url+"?access_token="+this.getAccessToken(),i="application/x-www-form-urlencoded";return t=function(){e.success&&e.success.apply(this,arguments)},r=function(t){e.error&&e.error.call(this,n.createError(t))},jQuery.ajax({url:a,type:e.type,contentType:i,success:t,error:r})},AeroGear.Notifier=function(e){return this instanceof AeroGear.Notifier?(AeroGear.Core.call(this),this.lib="Notifier",this.type=e?e.type||"vertx":"vertx",this.collectionName="clients",this.add(e),t):new AeroGear.Notifier(e)},AeroGear.Notifier.prototype=AeroGear.Core,AeroGear.Notifier.constructor=AeroGear.Notifier,AeroGear.Notifier.adapters={},AeroGear.Notifier.CONNECTING=0,AeroGear.Notifier.CONNECTED=1,AeroGear.Notifier.DISCONNECTING=2,AeroGear.Notifier.DISCONNECTED=3,AeroGear.Notifier.adapters.SimplePush=function(e,t){if(!(this instanceof AeroGear.Notifier.adapters.SimplePush))return new AeroGear.Notifier.adapters.SimplePush(e,t);t=t||{};var r=e,n=t.connectURL||"",a=t.useNative||!1,i=null,s=JSON.parse(localStorage.getItem("ag-push-store")||"{}");s.channels=s.channels||[];for(var o in s.channels)s.channels[o].state="available";localStorage.setItem("ag-push-store",JSON.stringify(s)),this.getSettings=function(){return t},this.getName=function(){return r},this.getConnectURL=function(){return n},this.setConnectURL=function(e){n=e},this.getUseNative=function(){return a},this.getClient=function(){return i},this.setClient=function(e){i=e},this.getPushStore=function(){return s},this.setPushStore=function(e){s=e,localStorage.setItem("ag-push-store",JSON.stringify(e))},this.processMessage=function(e){var t,r;if("register"===e.messageType&&200===e.status)t={channelID:e.channelID,version:e.version,state:"used"},s.channels=this.updateChannel(s.channels,t),this.setPushStore(s),t.pushEndpoint=e.pushEndpoint,jQuery(navigator.push).trigger(jQuery.Event(e.channelID+"-success",{target:{result:t}}));else{if("register"===e.messageType)throw"SimplePushRegistrationError";if("unregister"===e.messageType&&200===e.status)s.channels.splice(this.findChannelIndex(s.channels,"channelID",e.channelID),1),this.setPushStore(s);else{if("unregister"===e.messageType)throw"SimplePushUnregistrationError";if("notification"===e.messageType){r=e.updates;for(var n=0,a=r.length;a>n;n++)jQuery(navigator.push).trigger(jQuery.Event("push",{message:r[n]}));e.messageType="ack",i.send(JSON.stringify(e))}}}},this.generateHello=function(){var e=s.channels,t={messageType:"hello",uaid:"",channelIDs:[]};if(s.uaid&&(t.uaid=s.uaid),e&&""!==t.uaid)for(var r=e.length,n=r-1;n>-1;n--)t.channelIDs.push(s.channels[n].channelID);return JSON.stringify(t)},this.findChannelIndex=function(e,t,r){for(var n=0;e.length>n;n++)if(e[n][t]===r)return n},this.updateChannel=function(e,t){for(var r=0;e.length>r;r++)if(e[r].channelID===t.channelID){e[r].version=t.version,e[r].state=t.state;break}return e},this.bindSubscribeSuccess=function(e,t){jQuery(navigator.push).off(e+"-success"),jQuery(navigator.push).on(e+"-success",function(e){t.onsuccess(e)})}},AeroGear.Notifier.adapters.SimplePush.prototype.connect=function(e){e=e||{};var t=this,r=this.getUseNative()?new WebSocket(e.url||this.getConnectURL()):new SockJS(e.url||this.getConnectURL());r.onopen=function(){r.send(t.generateHello())},r.onerror=function(){e.onConnectError&&e.onConnectError.apply(this,arguments)},r.onmessage=function(r){var n=t.getPushStore();r=JSON.parse(r.data),"hello"===r.messageType?(r.uaid!==n.uaid&&(n.uaid=r.uaid,t.setPushStore(n)),e.onConnect&&e.onConnect(r)):t.processMessage(r)},r.onclose=function(){e.onClose&&e.onClose.apply(this,arguments)},this.setClient(r)},AeroGear.Notifier.adapters.SimplePush.prototype.disconnect=function(e){var t=this.getClient();t.close(),e&&e()},AeroGear.Notifier.adapters.SimplePush.prototype.subscribe=function(e,r){var n,a,i=!1,s=this.getClient(),o=this.getPushStore();r&&this.unsubscribe(this.getChannels()),e=AeroGear.isArray(e)?e:[e],o.channels=o.channels||[],a=o.channels.length;for(var c=0;e.length>c;c++)a&&(n=this.findChannelIndex(o.channels,"state","available"),n!==t&&(this.bindSubscribeSuccess(o.channels[n].channelID,e[c].requestObject),e[c].channelID=o.channels[n].channelID,e[c].state="used",setTimeout(function(e){return function(){jQuery(navigator.push).trigger(jQuery.Event(e.channelID+"-success",{target:{result:e}}))}}(e[c]),0),o.channels[n]=e[c],i=!0)),i||(e[c].channelID=e[c].channelID||uuid(),e[c].state="used",this.bindSubscribeSuccess(e[c].channelID,e[c].requestObject),s.send('{"messageType": "register", "channelID": "'+e[c].channelID+'"}'),o.channels.push(e[c])),i=!1;this.setPushStore(o)},AeroGear.Notifier.adapters.SimplePush.prototype.unsubscribe=function(e){var t=this.getClient();e=AeroGear.isArray(e)?e:[e];for(var r=0;e.length>r;r++)t.send('{"messageType": "unregister", "channelID": "'+e[r].channelID+'"}')},AeroGear.Notifier.adapters.vertx=function(e,t){if(!(this instanceof AeroGear.Notifier.adapters.vertx))return new AeroGear.Notifier.adapters.vertx(e,t);t=t||{};var r=t.channels||[],n=!!t.autoConnect||r.length,a=t.connectURL||"",i=AeroGear.Notifier.CONNECTING,s=null;this.getConnectURL=function(){return a},this.setConnectURL=function(e){a=e},this.getChannels=function(){return r},this.addChannel=function(e){r.push(e)},this.getChannelIndex=function(e){for(var t=0;r.length>t;t++)if(r[t].address===e)return t;return-1},this.removeChannel=function(e){var t=this.getChannelIndex(e.address);t>=0&&r.splice(t,1)},this.getState=function(){return i},this.setState=function(e){i=e},this.getBus=function(){return s},this.setBus=function(e){s=e},(n||r.length)&&this.connect({url:a,onConnect:t.onConnect,onDisconnect:t.onDisconnect,onConnectError:t.onConnectError})},AeroGear.Notifier.adapters.vertx.prototype.connect=function(e){e=e||{};var t=this,r=new vertx.EventBus(e.url||this.getConnectURL());r.onopen=function(){var r=t.getChannels().slice(0);t.setState(AeroGear.Notifier.CONNECTED),t.subscribe(r,!0),e.onConnect&&e.onConnect.apply(this,arguments)},r.onclose=function(){t.getState()===AeroGear.Notifier.DISCONNECTING?(t.setState(AeroGear.Notifier.DISCONNECTED),e.onDisconnect&&e.onDisconnect.apply(this,arguments)):e.onConnectError&&e.onConnectError.apply(this,arguments)},this.setBus(r)},AeroGear.Notifier.adapters.vertx.prototype.disconnect=function(){var e=this.getBus();this.getState()===AeroGear.Notifier.CONNECTED&&(this.setState(AeroGear.Notifier.DISCONNECTING),e.close())},AeroGear.Notifier.adapters.vertx.prototype.subscribe=function(e,t){var r=this.getBus();t&&this.unsubscribe(this.getChannels()),e=AeroGear.isArray(e)?e:[e];for(var n=0;e.length>n;n++)this.addChannel(e[n]),r.registerHandler(e[n].address,e[n].callback)},AeroGear.Notifier.adapters.vertx.prototype.unsubscribe=function(e){var t=this.getBus();e=AeroGear.isArray(e)?e:[e];for(var r=0;e.length>r;r++)this.removeChannel(e[r]),t.unregisterHandler(e[r].address,e[r].callback)},AeroGear.Notifier.adapters.vertx.prototype.send=function(e,t,r){var n=this.getBus();typeof t!==Boolean||r||(r=t,t=""),t=t||"",n[r?"publish":"send"](e,t)},AeroGear.Notifier.adapters.stompws=function(e,t){if(!(this instanceof AeroGear.Notifier.adapters.stompws))return new AeroGear.Notifier.adapters.stompws(e,t);t=t||{};var r=t.channels||[],n=!!t.autoConnect||r.length,a=t.connectURL||"",i=AeroGear.Notifier.CONNECTING,s=null;this.getConnectURL=function(){return a},this.setConnectURL=function(e){a=e},this.getChannels=function(){return r},this.addChannel=function(e){r.push(e)},this.getChannelIndex=function(e){for(var t=0;r.length>t;t++)if(r[t].address===e)return t;return-1},this.removeChannel=function(e){var t=this.getChannelIndex(e.address);
|
|
t>=0&&r.splice(t,1)},this.getState=function(){return i},this.setState=function(e){i=e},this.getClient=function(){return s},this.setClient=function(e){s=e},!n&&!r.length||t.login||t.password||this.connect({url:a,onConnect:t.onConnect,onConnectError:t.onConnectError})},AeroGear.Notifier.adapters.stompws.prototype.connect=function(e){e=e||{};var t=this,r=new Stomp.client(e.url||this.getConnectURL(),e.protocol||"v11.stomp"),n=function(){var r=t.getChannels().slice(0);t.setState(AeroGear.Notifier.CONNECTED),t.subscribe(r,!0),e.onConnect&&e.onConnect.apply(this,arguments)},a=function(){t.setState(AeroGear.Notifier.DISCONNECTED),e.onConnectError&&e.onConnectError.apply(this,arguments)};r.connect(e.login,e.password,n,a,e.host),this.setClient(r)},AeroGear.Notifier.adapters.stompws.prototype.disconnect=function(e){var t=this,r=this.getClient(),n=function(){t.getState()===AeroGear.Notifier.DISCONNECTING&&(t.setState(AeroGear.Notifier.DISCONNECTED),e&&e.apply(this,arguments))};this.getState()===AeroGear.Notifier.CONNECTED&&(this.setState(AeroGear.Notifier.DISCONNECTING),r.disconnect(n))},AeroGear.Notifier.adapters.stompws.prototype.subscribe=function(e,t){var r=this.getClient();t&&this.unsubscribe(this.getChannels()),e=AeroGear.isArray(e)?e:[e];for(var n=0;e.length>n;n++)e[n].id=r.subscribe(e[n].address,e[n].callback),this.addChannel(e[n])},AeroGear.Notifier.adapters.stompws.prototype.debug=function(e){var t=this.getClient(),r=function(){e&&e.apply(this,arguments)};t&&(t.debug=r)},AeroGear.Notifier.adapters.stompws.prototype.unsubscribe=function(e){var t=this.getClient(),r=this.getChannels();e=AeroGear.isArray(e)?e:[e];for(var n=0;e.length>n;n++)t.unsubscribe(e[n].id||r[this.getChannelIndex(e[n].address)].id),this.removeChannel(e[n])},AeroGear.Notifier.adapters.stompws.prototype.send=function(e,t){var r={},n=this.getClient();t=t||"",t.headers&&(r=t.headers,t=t.body),n.send(e,r,t)},function(r,n){r.UnifiedPushClient=function(a,i,s){if(!a||!i||!s)throw"UnifiedPushClientException";return this instanceof r.UnifiedPushClient?(this.registerWithPushServer=function(t){t=t||{};var o=t.metadata||{};if(!o.deviceToken)throw"UnifiedPushRegistrationException";return o.categories=r.isArray(o.categories)?o.categories:o.categories?[o.categories]:[],n.ajax({contentType:"application/json",dataType:"json",type:"POST",url:s,headers:{Authorization:"Basic "+e.btoa(a+":"+i)},data:JSON.stringify(o),success:t.success,error:t.error,complete:t.complete})},this.unregisterWithPushServer=function(t,r){return r=r||{},n.ajax({contentType:"application/json",dataType:"json",type:"DELETE",url:s+"/"+t,headers:{Authorization:"Basic "+e.btoa(a+":"+i)},success:r.success,error:r.error,complete:r.complete})},t):new r.UnifiedPushClient(a,i,s)}}(AeroGear,jQuery),function(t,r){t.SimplePushClient=function(n){if(!(this instanceof t.SimplePushClient))return new t.SimplePushClient(n);if(this.options=n||{},!navigator.push||!this.options.useNative){if(this.options.useNative)if("WebSocket"in e)this.options.simplePushServerURL="wss://push.services.mozilla.com";else{if(!this.options.simplePushServerURL)throw"SimplePushConfigurationError";this.options.useNative=!1}var a=this,i={onConnect:function(){navigator.push=function(){return{register:function(){var e={onsuccess:function(){}};if(!a.simpleNotifier)throw"SimplePushConnectionError";return a.simpleNotifier.subscribe({requestObject:e,callback:function(e){r(navigator.push).trigger({type:"push",message:e})}}),e},unregister:function(e){a.simpleNotifier.unsubscribe(e)},reconnect:function(){a.simpleNotifier.connect(i)}}}(),navigator.setMessageHandler=function(e,t){r(navigator.push).on(e,function(e){var r=e.message;t.call(this,r)})},a.options.onConnect&&a.options.onConnect()},onClose:function(){a.simpleNotifier.disconnect(a.options.onClose)}};a.simpleNotifier=t.Notifier({name:"agPushNetwork",type:"SimplePush",settings:{connectURL:a.options.simplePushServerURL,useNative:a.options.useNative}}).clients.agPushNetwork,a.simpleNotifier.connect(i)}}}(AeroGear,jQuery),AeroGear.Crypto=function(){if(!e.crypto||!e.crypto.getRandomValues)throw"Your browser does not support the Web Crypto API";if(!(this instanceof AeroGear.Crypto))return new AeroGear.Crypto;var t,r,n,a;this.getSalt=function(){return a},this.getIV=function(){return n},this.getPrivateKey=function(){return t},this.getPublicKey=function(){return r},this.getRandomValue=function(){var e=new Uint32Array(1);return crypto.getRandomValues(e),e[0]},this.deriveKey=function(e,t){a=t||(a?a:this.getRandomValue());var r=h.codec.utf8String,n=2048;return h.misc.pbkdf2(e,r.toBits(a),n)},this.encrypt=function(e){e=e||{};var t=h.mode.gcm,r=new h.cipher.aes(e.key);return n=e.IV||(n?n:this.getRandomValue()),t.encrypt(r,e.data,n,e.aad,128)},this.decrypt=function(e){e=e||{};var t=h.mode.gcm,r=new h.cipher.aes(e.key);return t.decrypt(r,e.data,e.IV||n,e.aad,128)},this.hash=function(e){return h.hash.sha256.hash(e)},this.sign=function(e){e=e||{};var t=e.keys||h.ecc.ecdsa.generateKeys(192),r=h.hash.sha256.hash(e.message);return t.sec.sign(r)},this.verify=function(e){e=e||{};var t=h.hash.sha256.hash(e.message);return e.keys.pub.verify(t,e.signature)},this.KeyPair=function(e,n){var a,i;return e&&n?(t=e,r=n):(a=h.ecc.elGamal.generateKeys(192,0),i=a.pub.kem(),r=i.key,t=a.sec.unkem(i.tag)),this}}})(this);
|
|
//@ sourceMappingURL=aerogear.js.map
|