{"version":3,"file":"app/vendors-node_modules_node-html-parser_dist_index_js-node_modules_node-jose_lib_index_js-node_-22482b.56ca0879.js","mappings":";;;;;;;;;AAAa;AACb,8CAA6C,EAAE,aAAa,EAAC;AAC7D;AACA;AACA;AACA,kBAAe;;;;;;;;;;;;ACLF;AACb,8CAA6C,EAAE,aAAa,EAAC;AAC7D,gBAAgB,mBAAO,CAAC,kFAAiB;AACzC,mBAAmB;AACnB,aAAa,mBAAO,CAAC,4EAAc;AACnC,mBAAmB;AACnB,aAAa;AACb,kBAAe;AACf,aAAa,mBAAO,CAAC,4EAAc;AACnC,YAAY;AACZ,aAAa,mBAAO,CAAC,4EAAc;AACnC,gBAAgB;AAChB,aAAa,mBAAO,CAAC,4EAAc;AACnC,gBAAgB;;;;;;;;;;;;ACbH;AACb,8CAA6C,EAAE,aAAa,EAAC;AAC7D;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,uCAAuC,gBAAgB;AACvD;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA,uCAAuC,gBAAgB;AACvD;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT,0CAA0C,gBAAgB,MAAM,2CAA2C;AAC3G;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA,uCAAuC,gBAAgB;AACvD;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,QAAQ;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,0CAA0C;AAC1C;AACA;AACA;AACA;AACA;AACA;AACA,uGAAuG,EAAE;AACzG;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kFAAkF,GAAG;AACrF;AACA;AACA;AACA;AACA;AACA,gEAAgE,uBAAuB,wBAAwB,cAAc,SAAS,eAAe,MAAM,GAAG,eAAe,aAAa,EAAE;AAC5L;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sGAAsG,EAAE;AACxG;AACA;AACA;AACA;AACA;AACA,qFAAqF,gBAAgB,4DAA4D,EAAE;AACnK;AACA;AACA,sCAAsC,EAAE;AACxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA,gBAAgB,aAAa;AAC7B,gBAAgB,gBAAgB;AAChC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB,MAAM;AAC1B;AACA;AACA;AACA,SAAS;AACT;AACA;AACA,KAAK;AACL;AACA;AACA,gBAAgB,QAAQ;AACxB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,kBAAe;;;;;;;;;;;;ACvPF;AACb;AACA;AACA;AACA,eAAe,gBAAgB,sCAAsC,kBAAkB;AACvF,8BAA8B;AAC9B;AACA;AACA;AACA;AACA,wBAAwB;AACxB;AACA;AACA,CAAC;AACD;AACA,6CAA6C;AAC7C;AACA,8CAA6C,EAAE,aAAa,EAAC;AAC7D,6BAA6B,mBAAO,CAAC,sEAAQ;AAC7C,6BAA6B,mBAAO,CAAC,sEAAQ;AAC7C;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB,QAAQ;AAC5B;AACA;AACA;AACA,SAAS;AACT;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA,CAAC;AACD,kBAAe;;;;;;;;;;;;AChDF;AACb;AACA;AACA;AACA,eAAe,gBAAgB,sCAAsC,kBAAkB;AACvF,8BAA8B;AAC9B;AACA;AACA;AACA;AACA,wBAAwB;AACxB;AACA;AACA,CAAC;AACD;AACA,6CAA6C;AAC7C;AACA,8CAA6C,EAAE,aAAa,EAAC;AAC7D,WAAW,mBAAO,CAAC,qEAAI;AACvB,6BAA6B,mBAAO,CAAC,sEAAQ;AAC7C,6BAA6B,mBAAO,CAAC,sEAAQ;AAC7C,6BAA6B,mBAAO,CAAC,sEAAQ;AAC7C,gCAAgC,mBAAO,CAAC,uEAAY;AACpD,6BAA6B,mBAAO,CAAC,iEAAS;AAC9C,gCAAgC,mBAAO,CAAC,4EAAW;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mCAAmC;AACnC,qCAAqC;AACrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,aAAa;AAC5B;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA,eAAe,aAAa;AAC5B,eAAe,aAAa;AAC5B;AACA;AACA;AACA,wBAAwB,4BAA4B;AACpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB,QAAQ;AAC5B;AACA;AACA;AACA;AACA,aAAa;AACb,SAAS;AACT;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,oBAAoB,QAAQ;AAC5B;AACA;AACA;AACA,SAAS;AACT;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,oBAAoB,QAAQ;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,yDAAyD,GAAG;AAC5D,aAAa;AACb,iDAAiD;AACjD,SAAS;AACT;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb,SAAS;AACT;AACA;AACA,KAAK;AACL;AACA,kCAAkC;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA,KAAK;AACL;AACA;AACA,gBAAgB,QAAQ;AACxB,gBAAgB,gBAAgB;AAChC;AACA;AACA,wBAAwB,4BAA4B;AACpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB,QAAQ;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA,KAAK;AACL;AACA;AACA,gBAAgB,aAAa;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA,gBAAgB,gBAAgB;AAChC,gBAAgB,gBAAgB;AAChC,gBAAgB,gBAAgB;AAChC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qBAAqB;AACrB,iBAAiB;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mDAAmD;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA,gBAAgB,gBAAgB;AAChC,gBAAgB,gBAAgB;AAChC,gBAAgB,gBAAgB;AAChC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,+CAA+C,gBAAgB;AAC/D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAgB,MAAM;AACtB,gBAAgB,WAAW;AAC3B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB,MAAM;AAC1B;AACA;AACA;AACA,SAAS;AACT;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,oBAAoB,MAAM;AAC1B;AACA;AACA;AACA,SAAS;AACT;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,oBAAoB,QAAQ;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,oBAAoB,QAAQ;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA,gBAAgB,QAAQ;AACxB;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,QAAQ;AACvB,eAAe,QAAQ;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA,eAAe,YAAY;AAC3B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,kBAAe;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAU,UAAU;AACpB,SAAS,oBAAoB;AAC7B,SAAS,WAAW;AACpB,UAAU,oBAAoB;AAC9B,UAAU,oBAAoB;AAC9B,UAAU,UAAU;AACpB,UAAU,UAAU;AACpB,UAAU,UAAU;AACpB,UAAU,UAAU;AACpB,UAAU,UAAU;AACpB,UAAU;AACV;AACA;AACA,UAAU,oBAAoB;AAC9B,SAAS,WAAW;AACpB,SAAS,WAAW;AACpB,SAAS,WAAW;AACpB,SAAS,WAAW;AACpB,UAAU,uBAAuB;AACjC,UAAU;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,8BAA8B;AAC9B,uCAAuC;AACvC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,wCAAwC,4CAA4C;AACpF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qBAAqB;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qBAAqB;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;;;;;;;;;;;;ACnyBA;AACb,8CAA6C,EAAE,aAAa,EAAC;AAC7D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,kBAAe;;;;;;;;;;;;ACXF;AACb;AACA;AACA;AACA,eAAe,gBAAgB,sCAAsC,kBAAkB;AACvF,8BAA8B;AAC9B;AACA;AACA;AACA;AACA,wBAAwB;AACxB;AACA;AACA,CAAC;AACD;AACA,6CAA6C;AAC7C;AACA,8CAA6C,EAAE,aAAa,EAAC;AAC7D,6BAA6B,mBAAO,CAAC,sEAAQ;AAC7C,6BAA6B,mBAAO,CAAC,sEAAQ;AAC7C;AACA;AACA,WAAW,QAAQ;AACnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB,QAAQ;AAC5B;AACA;AACA;AACA,SAAS;AACT;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,oBAAoB;AACpB;AACA;AACA,+BAA+B;AAC/B,SAAS;AACT;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA,CAAC;AACD,kBAAe;;;;;;;;;;;;AC/DF;AACb,8CAA6C,EAAE,aAAa,EAAC;AAC7D;AACA;AACA;AACA;AACA;AACA,CAAC,4BAA4B;AAC7B,kBAAe;;;;;;;;;;;;ACRf;AACA,CAAC;;AAED;AACA,mBAAmB,KAA0B;;AAE7C;AACA,kBAAkB,KAAyB;AAC3C;;AAEA;AACA;AACA,yBAAyB,qBAAM,gBAAgB,qBAAM;AACrD;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,kBAAkB,8iBAA8iB,wZAAwZ,WAAW;;AAEn+B;AACA;AACA,cAAc;AACd,aAAa;AACb,eAAe;AACf,YAAY;AACZ;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA,cAAc;AACd;;AAEA;AACA;AACA,gCAAgC,yBAAyB,mBAAmB;AAC5E,kBAAkB,4teAA4te,wKAAwK,2uZAA2uZ,wKAAwK,6gFAA6gF;AACtz9B,wBAAwB;AACxB,yBAAyB;AACzB;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,sCAAsC;AACtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,0DAA0D;AAC1D;;AAEA;AACA,8BAA8B;AAC9B;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,wCAAwC;AACxC;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA,mBAAmB,iBAAiB;AACpC,mBAAmB,iBAAiB;AACpC,qBAAqB,MAAM,YAAY;AACvC;AACA;AACA;AACA;AACA;AACA;AACA,wCAAwC;AACxC,KAAK;AACL;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA,wCAAwC,GAAG;AAC3C,KAAK;AACL;AACA;AACA;AACA;AACA,kBAAkB,iBAAiB;AACnC,kBAAkB,iBAAiB;AACnC;AACA;AACA;AACA,uCAAuC;AACvC,IAAI;AACJ,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,8CAA8C;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kDAAkD;AAClD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,yDAAyD,eAAe;AACxE;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,2DAA2D;AAC3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,GAAG;AACH;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,EAAE,IAEU;AACZ;AACA,EAAE,mCAAO;AACT;AACA,GAAG;AAAA,kGAAC;AACJ,GAAG,KAAK,YAUN;;AAEF,CAAC;;;;;;;;;;;;;ACrVD;AACA;AACA;AACA;AACA;AACa;;AAEb,cAAc,mBAAO,CAAC,4EAAc;AACpC,WAAW,mBAAO,CAAC,sEAAW;AAC9B,UAAU,mBAAO,CAAC,oEAAU;AAC5B,YAAY,mBAAO,CAAC,wEAAkB;AACtC,iBAAiB,mBAAO,CAAC,kFAAuB;AAChD,WAAW,mBAAO,CAAC,+DAAS;;AAE5B;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA,kBAAkB,OAAO;;AAEzB;AACA;AACA;AACA;AACA,OAAO;;AAEP;AACA;AACA;AACA,eAAe,OAAO;AACtB;;AAEA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA,kBAAkB,OAAO;;AAEzB;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA,kBAAkB,OAAO;;AAEzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA,kBAAkB,OAAO;;AAEzB;AACA;AACA;AACA;AACA,OAAO;;AAEP;AACA;AACA;AACA,eAAe,OAAO;AACtB;;AAEA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA,kBAAkB,OAAO;;AAEzB;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA,kBAAkB,OAAO;;AAEzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA,KAAK;;AAEL;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;AACA;AACA;AACA;AACA;;AAEA,kBAAkB,OAAO;;AAEzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA,OAAO;AACP;AACA;AACA,OAAO;AACP;AACA,KAAK;;AAEL;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA,gBAAgB,OAAO;;AAEvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,GAAG;;AAEH;AACA;AACA;AACA,KAAK;AACL,GAAG;AACH,YAAY,OAAO;;AAEnB;AACA;;AAEA;AACA;AACA;AACA,gBAAgB,OAAO;;AAEvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,GAAG;;AAEH;AACA;AACA;AACA,KAAK;AACL,GAAG;AACH,YAAY,OAAO;;AAEnB;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,kBAAkB,OAAO;AACzB;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,OAAO;AACpB,QAAQ,OAAO;AACf,mDAAmD,cAAc;AACjE;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,kBAAkB,OAAO;AACzB;AACA;AACA,KAAK;;;AAGL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,SAAS;AACT,QAAQ;AACR;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;;;;;;;;;;;;;ACtfA;AACA;AACA;AACA;AACA;AACa;;AAEb,cAAc,mBAAO,CAAC,4EAAc;AACpC,WAAW,mBAAO,CAAC,+DAAS;AAC5B,gBAAgB,mBAAO,CAAC,gFAAgB;AACxC,UAAU,mBAAO,CAAC,+FAAyB;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA,sBAAsB,OAAO;AAC7B;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT,OAAO;AACP,KAAK;;AAEL;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,KAAK;AACL;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA,OAAO;AACP,KAAK;;AAEL;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;;AAEA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA,sBAAsB,OAAO;AAC7B;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,UAAU;AACV;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA,OAAO;AACP,KAAK;;AAEL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA,MAAM;AACN;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;;;;;;;;;;;;;ACrXA;AACA;AACA;AACA;AACA;AACa;;AAEb,cAAc,mBAAO,CAAC,4EAAc;AACpC,YAAY,mBAAO,CAAC,wEAAkB;AACtC,iBAAiB,mBAAO,CAAC,kFAAuB;;AAEhD;;AAEA;AACA;AACA;AACA;AACA,oBAAoB,WAAW;AAC/B;AACA;AACA;AACA;;AAEA;AACA;AACA,oBAAoB,oBAAoB;AACxC;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,SAAS;AAC/B,wBAAwB,gBAAgB;AACxC;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,OAAO;AAClB;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;AACA;AACA;AACA;AACA,qDAAqD,+BAA+B;AACpF;AACA;AACA,cAAc,OAAO;AACrB;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,SAAS;AAC/B,wBAAwB,gBAAgB;AACxC;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,OAAO;AAClB;AACA,KAAK;AACL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,UAAU;AAChC,mCAAmC,UAAU;AAC7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,aAAa,OAAO;AACpB;AACA;AACA,WAAW,OAAO;AAClB;AACA;AACA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;AACA;AACA;AACA;AACA;AACA,qEAAqE,8BAA8B;AACnG,KAAK;AACL;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,UAAU;AAChC,mCAAmC,UAAU;AAC7C;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,aAAa,OAAO;AACpB;AACA;AACA,WAAW,OAAO;AAClB;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;;;;;;;;;;;;;AC/RA;AACA;AACA;AACA;AACA;AACa;;AAEb,gBAAgB,mBAAO,CAAC,gFAAgB;AACxC,UAAU,mBAAO,CAAC,oEAAU;;AAE5B;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,aAAa,OAAO;AACpB;;AAEA;AACA;AACA,aAAa,OAAO;AACpB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;;;;;;;;;;;;ACtEA;AACA;AACA;AACA;AACA;AACA,CAAc;;AAEd;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;ACnDA;AACA;AACA;AACA;AACA;AACa;;AAEb;AACA;AACA;AACA,SAAS,OAAO;AAChB;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA,SAAS,OAAO;AAChB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;;;;;;;;;;;AChCA;AACA;AACA;AACA;AACA;AACa;;AAEb,YAAY,mBAAO,CAAC,wDAAc;AAClC,UAAU,mBAAO,CAAC,uEAAa;AAC/B,YAAY,mBAAO,CAAC,wEAAkB;AACtC,WAAW,mBAAO,CAAC,+DAAS;;AAE5B;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB,mBAAmB;AACtC;AACA;AACA;AACA;AACA;AACA,uBAAuB,uBAAuB;AAC9C;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;ACnQA;AACA;AACA;AACA;AACA;AACa;;AAEb,YAAY,mBAAO,CAAC,qEAAe;AACnC,WAAW,mBAAO,CAAC,+DAAS;AAC5B,aAAa,mBAAO,CAAC,4EAAc;AACnC,WAAW,mBAAO,CAAC,sEAAW;AAC9B,aAAa,mBAAO,CAAC,0EAAa;AAClC,YAAY,mBAAO,CAAC,0EAAa;AACjC,cAAc,mBAAO,CAAC,4EAAc;AACpC,gBAAgB,mBAAO,CAAC,gFAAgB;;AAExC,YAAY,mBAAO,CAAC,wDAAc;AAClC,WAAW,mBAAO,CAAC,sDAAa;AAChC,WAAW,mBAAO,CAAC,sDAAa;;AAEhC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,aAAa,OAAO;AACpB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,OAAO;AAClB;;AAEA;AACA;AACA;AACA;AACA,eAAe,KAAK;AACpB,eAAe,cAAc;AAC7B;;AAEA;AACA;AACA,UAAU,QAAQ;;AAElB;AACA;AACA;AACA;AACA,iBAAiB,OAAO;AACxB;AACA;AACA;;AAEA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,SAAS;;AAET,eAAe,KAAK;AACpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,eAAe,cAAc;AAC7B;AACA;AACA,UAAU,QAAQ;AAClB;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL,YAAY,OAAO;AACnB;AACA;AACA;;AAEA;AACA;AACA,OAAO;AACP;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO;AACtB;;AAEA,eAAe,KAAK;AACpB,eAAe,cAAc;AAC7B;;AAEA;AACA;AACA,UAAU,QAAQ;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB,OAAO;AACxB;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;AACA;AACA,mCAAmC,OAAO;AAC1C;AACA;AACA;AACA,qCAAqC,OAAO;AAC5C;AACA,KAAK;AACL;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;AACA;AACA,mCAAmC,OAAO;AAC1C;AACA;AACA;AACA,qCAAqC,OAAO;AAC5C;AACA,KAAK;AACL;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,QAAQ,WAAW;AACnB;AACA,aAAa,OAAO;AACpB;AACA;;AAEA,QAAQ,KAAK;AACb;AACA,aAAa,OAAO;AACpB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,QAAQ,WAAW;AACnB;AACA,aAAa,OAAO;AACpB;AACA;;AAEA,QAAQ,KAAK;AACb;AACA,aAAa,OAAO;AACpB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,QAAQ,WAAW;AACnB;AACA,aAAa,OAAO;AACpB;AACA;;AAEA,QAAQ,KAAK;AACb;AACA,aAAa,OAAO;AACpB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,QAAQ,WAAW;AACnB;AACA,aAAa,OAAO;AACpB;AACA;;AAEA,QAAQ,KAAK;AACb;AACA,aAAa,OAAO;AACpB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA,CAAC;AACD;;;;;;;;;;;;;AChdA;AACA;AACA;AACA;AACA;AACa;;AAEb,aAAa,mBAAO,CAAC,4EAAc;AACnC,cAAc,mBAAO,CAAC,4EAAc;AACpC,UAAU,mBAAO,CAAC,oEAAU;;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,aAAa,OAAO;AACpB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA,aAAa,OAAO;AACpB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO;AACtB;;AAEA;AACA,gBAAgB,OAAO;AACvB;AACA;AACA;AACA,OAAO;;AAEP;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,OAAO;;AAEP;AACA;AACA;AACA;AACA;AACA,OAAO;;AAEP;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,aAAa,OAAO;AACpB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO;AACtB;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA,aAAa,OAAO;AACpB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA,eAAe,OAAO;AACtB;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,gBAAgB,OAAO;AACvB;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;;AAEP;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA,CAAC;;AAED;;;;;;;;;;;;;ACpQA;AACA;AACA;AACA;AACA;AACA;AACa;;AAEb,WAAW,OAAO;AAClB,EAAE,uGAA+B;AACjC;;AAEA;AACA,qBAAqB;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,qBAAqB;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,aAAa,mBAAO,CAAC,qBAAQ;AAC7B,IAAI;AACJ;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA,gDAA+C;AAC/C;AACA;;AAEA;AACA;AACA,MAAM;AACN;AACA;;AAEA;AACA,GAAG;AACH;AACA,CAAC,EAAC;AACF,8CAA6C;AAC7C;AACA;;AAEA;AACA;AACA,MAAM;AACN;AACA;;AAEA;AACA,GAAG;AACH;AACA,CAAC,EAAC;;AAEF,qBAAqB;AACrB;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,eAAe,OAAO;AACtB;;AAEA;AACA,kBAAkB,OAAO;AACzB,QAAQ;AACR;AACA;;AAEA;AACA;AACA,IAAI;AACJ;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,cAAc,OAAO;AACrB;;AAEA;AACA;AACA;AACA,QAAQ;AACR;AACA;;AAEA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;;;;;;;;;;;;ACrJA;AACA;AACA;AACA;AACA;AACa;;AAEb,gBAAgB,mBAAO,CAAC,gFAAgB;AACxC,WAAW,mBAAO,CAAC,sEAAW;;AAE9B;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,OAAO;AACP;AACA;;AAEA;AACA,8BAA8B,yBAAyB;AACvD;AACA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;;;;;;;;;;;;;ACrFA;AACA;AACA;AACA;AACA;AACa;;AAEb,gBAAgB,mBAAO,CAAC,6EAAa;AACrC,YAAY,mBAAO,CAAC,wEAAkB;AACtC,iBAAiB,mBAAO,CAAC,kFAAuB;AAChD,cAAc,mBAAO,CAAC,4EAAc;;AAEpC;AACA;AACA;;AAEA;AACA;AACA;AACA,aAAa,OAAO;AACpB;;AAEA,WAAW,OAAO;AAClB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA,sBAAsB,WAAW;AACjC;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,aAAa,OAAO;AACpB;AACA;AACA;AACA,OAAO;AACP,MAAM;AACN,aAAa,OAAO;AACpB;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA,OAAO;AACP,MAAM;AACN;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA,eAAe,OAAO;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;;;;;;;;;;;;;AC5MA;AACA;AACA;AACA;AACA;AACa;;AAEb;AACA;AACA,EAAE,mBAAO,CAAC,gGAAwB;AAClC,EAAE,mBAAO,CAAC,4EAAc;AACxB,EAAE,mBAAO,CAAC,0EAAa;AACvB,EAAE,mBAAO,CAAC,0EAAa;AACvB,EAAE,mBAAO,CAAC,oEAAU;AACpB,EAAE,mBAAO,CAAC,sEAAW;AACrB,EAAE,mBAAO,CAAC,wEAAY;AACtB,EAAE,mBAAO,CAAC,sEAAW;AACrB,EAAE,mBAAO,CAAC,sEAAW;AACrB,EAAE,mBAAO,CAAC,wEAAY;AACtB,EAAE,mBAAO,CAAC,wEAAY;AACtB,EAAE,mBAAO,CAAC,0EAAa;AACvB,EAAE,mBAAO,CAAC,oEAAU;AACpB;;AAEA;AACA;AACA,kBAAkB;AAClB;AACA,iBAAiB;AACjB;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH,CAAC;;AAED;AACA,cAAc;AACd;AACA;AACA,WAAW,OAAO;AAClB;;AAEA;AACA;;AAEA,cAAc;AACd;AACA;AACA,WAAW,OAAO;AAClB;;AAEA;AACA;;AAEA,YAAY;AACZ;AACA;AACA,WAAW,OAAO;AAClB;;AAEA,mCAAmC;AACnC;;AAEA,cAAc;AACd;AACA;AACA,WAAW,OAAO;AAClB;;AAEA,wCAAwC;AACxC;;AAEA,eAAe;AACf;AACA;AACA,WAAW,OAAO;AAClB;;AAEA,mCAAmC;AACnC;;AAEA,eAAe;AACf;AACA;AACA,WAAW,OAAO;AAClB;;AAEA,mCAAmC;AACnC;;;;;;;;;;;;;AC7GA;AACA;AACA;AACA;AACA;AACa;;AAEb,YAAY,mBAAO,CAAC,wEAAkB;AACtC,YAAY,mBAAO,CAAC,wEAAkB;AACtC,WAAW,mBAAO,CAAC,+DAAS;AAC5B,cAAc,mBAAO,CAAC,4EAAc;AACpC,gBAAgB,mBAAO,CAAC,gFAAgB;AACxC,SAAS,mBAAO,CAAC,0EAAa;;AAE9B;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;AACA;AACA;;AAEA,sBAAsB,OAAO;AAC7B;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;AACA;AACA;;AAEA,kBAAkB,OAAO;AACzB;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,KAAK;AACL;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;;AAEA;AACA;AACA;;AAEA;AACA,sBAAsB,OAAO;AAC7B;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL,kBAAkB,OAAO;AACzB;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;AACL;AACA;AACA,iDAAiD;AACjD;AACA,KAAK;;AAEL;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA,aAAa,OAAO;AACpB;;AAEA;AACA,aAAa,OAAO;AACpB;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL,kBAAkB,OAAO;;AAEzB;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;;;;;;;;;;;;ACpQA;AACA;AACA;AACA;AACA;AACa;;AAEb,YAAY,mBAAO,CAAC,wDAAc;AAClC,YAAY,mBAAO,CAAC,wEAAkB;AACtC,WAAW,mBAAO,CAAC,+DAAS;;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA,yCAAyC,cAAc;AACvD;AACA;;AAEA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;ACzEA;AACA;AACA;AACA;AACA;AACa;;AAEb,YAAY,mBAAO,CAAC,wEAAkB;AACtC,cAAc,mBAAO,CAAC,4EAAc;AACpC,iBAAiB,mBAAO,CAAC,kFAAuB;AAChD,cAAc,mBAAO,CAAC,8EAAe;;AAErC;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA,WAAW,OAAO;AAClB;AACA,KAAK;AACL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA,OAAO;;AAEP;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO;;AAEP;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA,WAAW,OAAO;AAClB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA,OAAO;;AAEP;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA,gCAAgC;AAChC;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA,IAAI,sDAAsD;AAC1D;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;;;;;;;;;;;;;ACvMA;AACA;AACA;AACA;AACA;AACa;;AAEb,YAAY,mBAAO,CAAC,wEAAkB;AACtC,gBAAgB,mBAAO,CAAC,6EAAa;AACrC,cAAc,mBAAO,CAAC,4EAAc;AACpC,cAAc,mBAAO,CAAC,8EAAe;;AAErC;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA,WAAW,OAAO;AAClB;AACA;AACA,KAAK;AACL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,aAAa,OAAO;AACpB;AACA,WAAW,OAAO;AAClB;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA,eAAe,OAAO;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA;;AAEA,WAAW,OAAO;AAClB;AACA;AACA,KAAK;AACL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,OAAO;;AAEP;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA,aAAa,OAAO;AACpB;AACA,WAAW,OAAO;AAClB;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA,eAAe,OAAO;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA,eAAe,OAAO;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;;;;;;;;;;;;;ACpWA;AACA;AACA;AACA;AACA;AACa;;AAEb,YAAY,mBAAO,CAAC,wEAAkB;AACtC,cAAc,mBAAO,CAAC,4EAAc;;AAEpC;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,WAAW,OAAO;AAClB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;;;;;;;;;;;;AC7DA;AACA;AACA;AACA;AACA;AACa;;AAEb,WAAW,mBAAO,CAAC,kDAAM;AACzB,WAAW,mBAAO,CAAC,sDAAa;AAChC,WAAW,mBAAO,CAAC,6EAAY;;AAE/B;AACA;AACA;;AAEA;AACA;;AAEA,kBAAkB,SAAS;AAC3B;AACA,oBAAoB,QAAQ;AAC5B;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;;AAEA;AACA,MAAM;AACN,sBAAsB,YAAY;AAClC;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;;AAEA;AACA;;AAEA,sBAAsB,WAAW;AACjC;AACA;AACA;AACA;AACA;;AAEA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA,oBAAoB,OAAO;AAC3B;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;;AAEA,oBAAoB,OAAO;AAC3B;AACA,uBAAuB,QAAQ;AAC/B;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACjQA;AACA;AACA;AACA;AACA;AACA,CAAc;;AAEd,WAAW,mBAAO,CAAC,kDAAM;AACzB,YAAY,mBAAO,CAAC,8EAAwB;AAC5C,kBAAkB,mBAAO,CAAC,8FAAkB;AAC5C,cAAc,mBAAO,CAAC,sFAAc;AACpC,WAAW,mBAAO,CAAC,6EAAY;AAC/B,iBAAiB,mBAAO,CAAC,wFAA6B;AACtD,oBAAoB,mBAAO,CAAC,mFAAe;;AAE3C;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;;AAEA;AACA,kBAAkB,SAAS;AAC3B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,mBAAmB,SAAS;AAC5B;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,uBAAuB,QAAQ;AAC/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;;;;;;;;;;;AClTA;AACA;AACA;AACA;AACA;AACA,CAAc;;AAEd,cAAc,mBAAO,CAAC,sFAAc;AACpC,WAAW,mBAAO,CAAC,6EAAY;;;AAG/B;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAgB,QAAQ;AACxB;AACA,kBAAkB,QAAQ;AAC1B;AACA,oBAAoB,OAAO;AAC3B;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA,cAAc,QAAQ;AACtB;AACA;AACA;;AAEA,cAAc,QAAQ;AACtB;AACA;;AAEA;AACA,SAAS;AACT,gBAAgB,QAAQ;AACxB,kBAAkB,OAAO;AACzB;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,kBAAkB,OAAO;AACzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB,QAAQ;AAC3B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;;AAGA;AACA;AACA;;;;;;;;;;;;AC5FA;AACA;AACA;AACA;AACA;AACa;;AAEb,WAAW,mBAAO,CAAC,4EAAW;;AAE9B;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;;;;;;;;;;;ACpBA;AACA;AACA;AACA;AACA;AACa;;AAEb,WAAW,mBAAO,CAAC,kDAAM;;AAEzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,cAAc;AACxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B,cAAc;AACxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,wBAAwB,eAAe;AACvC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,wBAAwB,eAAe;AACvC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACtHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACa;;AAEb;;AAEA,iBAAiB,oGAAgC;AACjD,SAAS,mBAAO,CAAC,oEAAW;;AAE5B;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA,sBAAsB;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;;;;;;;;;;;AC5GA;AACA;AACA;AACA;AACA;AACa;;AAEb,YAAY,mBAAO,CAAC,wEAAkB;AACtC;AACA,SAAS,mBAAO,CAAC,oEAAW;AAC5B,aAAa,mBAAO,CAAC,wEAAa;;AAElC;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA,WAAW,QAAQ;AACnB,WAAW,YAAY;AACvB,WAAW,YAAY;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA,WAAW,QAAQ;AACnB,WAAW,QAAQ;AACnB;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA,IAAI;;AAEJ;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,uBAAuB;AACvB;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,mBAAmB;AACnB;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;AACA,oBAAoB;AACpB;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;;;;;;;;;;;;ACvPA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACa;;AAEb;AACA;AACA;;AAEA,iBAAiB,oGAAgC;;AAEjD;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,SAAS,eAAe,aAAa,gBAAgB;AACrD;;AAEA,4BAA4B;;AAE5B;AACA;AACA,iBAAiB;AACjB;AACA,yBAAyB,kBAAkB;AAC3C;AACA;AACA;AACA;AACA;AACA;;AAEA,kBAAkB;AAClB,6BAA6B,eAAe;;AAE5C,kBAAkB;AAClB,+BAA+B,mBAAmB;;AAElD;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA,2BAA2B;AAC3B;AACA,qCAAqC;AACrC;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA,6BAA6B,OAAO;AACpC;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACzcA;AACA;AACA;AACA;AACA;AACa;;AAEb,YAAY,mBAAO,CAAC,+FAAsB;AAC1C,mBAAO,CAAC,2FAAoB;AAC5B,mBAAO,CAAC,6FAAqB;AAC7B,mBAAO,CAAC,iGAAuB;AAC/B,mBAAO,CAAC,6FAAqB;AAC7B,mBAAO,CAAC,6FAAqB;AAC7B,mBAAO,CAAC,iGAAuB;AAC/B,mBAAO,CAAC,2FAAoB;AAC5B,mBAAO,CAAC,+FAAsB;AAC9B,mBAAO,CAAC,+FAAsB;AAC9B,mBAAO,CAAC,2FAAoB;AAC5B,mBAAO,CAAC,+FAAsB;AAC9B,mBAAO,CAAC,6FAAqB;AAC7B,mBAAO,CAAC,2FAAoB;AAC5B,mBAAO,CAAC,iGAAuB;AAC/B,mBAAO,CAAC,6FAAqB;AAC7B,mBAAO,CAAC,iGAAuB;AAC/B,mBAAO,CAAC,iGAAuB;AAC/B,mBAAO,CAAC,6FAAqB;;AAE7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA,aAAa,kBAAkB;AAC/B;AACA;;AAEA;AACA;;AAEA;AACA,aAAa,kBAAkB;AAC/B;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA,aAAa,kBAAkB;AAC/B;AACA;;AAEA;AACA;;AAEA;AACA,aAAa,kBAAkB;AAC/B;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,yBAAyB;AACzB;AACA,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;;;;;;;;;;;;;ACnGA;AACA;AACA;AACA;AACA;AACa;;AAEb,WAAW,OAAO;AAClB,EAAE,uGAA+B;AACjC;;AAEA;AACA,GAAG,qBAAM,qBAAqB,gFAAwB;AACtD;;AAEA,WAAW,OAAO;AAClB,GAAG,qBAAM,sBAAsB,mBAAO,CAAC,sDAAS;AAChD;;AAEA,KAAK,OAAO;AACZ,EAAE,OAAO;AACT;;AAEA,UAAU,mBAAO,CAAC,4DAAO;;AAEzB;AACA,OAAO,mBAAO,CAAC,0EAAc;AAC7B,OAAO,mBAAO,CAAC,4DAAO;AACtB,OAAO,mBAAO,CAAC,4DAAO;AACtB;AACA,QAAQ,mBAAO,CAAC,8DAAQ;AACxB,SAAS,mBAAO,CAAC,gEAAS;AAC1B;AACA;;;;;;;;;;;;;ACjCA;AACA;AACA;AACA;AACA;AACa;;AAEb,gBAAgB,mBAAO,CAAC,6EAAmB;AAC3C,gBAAgB,mBAAO,CAAC,6EAAmB;AAC3C,UAAU,mBAAO,CAAC,6DAAQ;AAC1B,YAAY,mBAAO,CAAC,qEAAe;AACnC,WAAW,mBAAO,CAAC,8CAAM;;AAEzB;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,wBAAwB;AACjC;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,IAAI;AACJ;AACA,IAAI;AACJ;AACA;;AAEA,uBAAuB;;AAEvB;AACA;AACA;AACA,MAAM,KAAK;AACX,8CAA8C,kBAAkB;AAChE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,eAAe;AAC5B,aAAa,QAAQ;AACrB,eAAe,SAAS;AACxB;AACA;AACA;AACA,qBAAqB,wBAAwB;AAC7C;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA,4CAA4C;AAC5C,gBAAgB,OAAO;;AAEvB;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,qBAAqB,OAAO;AAC5B;AACA,8BAA8B,mBAAmB;AACjD;AACA,uBAAuB,OAAO;AAC9B;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA,8CAA8C;;AAE9C;AACA,wBAAwB,OAAO;AAC/B;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,qBAAqB,OAAO;AAC5B,aAAa;AACb;AACA;AACA;AACA,qBAAqB,OAAO;AAC5B,aAAa;AACb;;AAEA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA,aAAa;AACb;AACA;AACA;AACA,WAAW;AACX,SAAS;;AAET,eAAe,OAAO;AACtB,OAAO;;AAEP;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB,OAAO;AAC1B;AACA;AACA;AACA;AACA;AACA;;AAEA,6BAA6B,OAAO;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe;AACf;AACA;AACA,gBAAgB;AAChB,uBAAuB,OAAO;AAC9B;AACA,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA,SAAS;AACT,OAAO;;AAEP;AACA;AACA;AACA;AACA;;AAEA;AACA,OAAO;;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA,4BAA4B,OAAO;AACnC;AACA,SAAS;AACT,eAAe,OAAO;AACtB;AACA,qBAAqB,KAAK;AAC1B;AACA,SAAS;AACT,OAAO;;AAEP;AACA;AACA;AACA;AACA;;AAEA;AACA,OAAO;;AAEP;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe;AACf,WAAW;AACX,OAAO;;AAEP;AACA;AACA;AACA,qBAAqB,OAAO;AAC5B;AACA;;AAEA;AACA;AACA,cAAc;AACd;AACA;AACA,WAAW;AACX;;AAEA;AACA,OAAO;;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B,OAAO;AACnC;AACA,SAAS;AACT,eAAe,OAAO;AACtB;AACA,qBAAqB,KAAK;AAC1B;AACA,SAAS;AACT,OAAO;;AAEP;AACA;AACA,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACA,IAAI,KAAK;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sEAAsE;AACtE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,wDAAwD;AACxD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,sBAAsB;AACjC,WAAW,QAAQ;AACnB,aAAa,eAAe;AAC5B;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;;;;;;;;;;;ACnXA;AACA;AACA;AACA;AACA;AACa;;AAEb;AACA;AACA,4BAA4B,wBAAwB;AACpD;AACA,cAAc,gBAAgB;AAC9B;AACA;AACA;AACA,cAAc,QAAQ;AACtB;AACA;AACA;AACA;AACA,cAAc,SAAS;AACvB;AACA;AACA,cAAc,QAAQ;AACtB;AACA,cAAc,iBAAiB;AAC/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;;;;;;;;;;;;ACrCA;AACA;AACA;AACA;AACA;AACa;;AAEb,WAAW,mBAAO,CAAC,+DAAS;AAC5B,kBAAkB,qGAAgC;AAClD,UAAU,mBAAO,CAAC,6DAAQ;AAC1B,YAAY,+FAA0B;AACtC,WAAW,mBAAO,CAAC,8CAAM;AACzB,gBAAgB,mBAAO,CAAC,yFAAyB;;AAEjD,aAAa,mBAAO,CAAC,0DAAe;AACpC,YAAY,mBAAO,CAAC,wDAAc;AAClC,eAAe,mBAAO,CAAC,oEAAY;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA,uEAAuE;AACvE,qBAAqB;AACrB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,cAAc,QAAQ;AACtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA,GAAG;AACH;AACA,cAAc,SAAS;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB,8BAA8B;AACpD;AACA,GAAG;AACH;AACA,cAAc,QAAQ;AACtB;AACA;AACA;AACA;AACA;AACA,sBAAsB,gBAAgB;AACtC;AACA,GAAG;AACH;AACA,cAAc,UAAU;AACxB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA,GAAG;AACH;AACA,cAAc,QAAQ;AACtB;AACA;AACA;AACA,MAAM,+BAA+B;AACrC;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,MAAM,cAAc,UAAU,wBAAwB,MAAM;AACrE,0CAA0C,SAAS;AACnD;AACA,aAAa,eAAe;AAC5B,aAAa,QAAQ;AACrB,eAAe,eAAe;AAC9B,cAAc,OAAO;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;;AAEA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA,wCAAwC,6BAA6B;AACrE;AACA;AACA,aAAa,eAAe;AAC5B,aAAa,QAAQ;AACrB;AACA,eAAe,SAAS;AACxB,cAAc,OAAO;AACrB;AACA;AACA;AACA;AACA,eAAe,OAAO;AACtB;;AAEA;AACA;;AAEA;AACA;AACA,oBAAoB,OAAO,WAAW;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;;AAEP;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,yBAAyB,OAAO;AAChC;AACA;AACA;AACA,iBAAiB;AACjB,cAAc;AACd;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA,YAAY;AACZ,uBAAuB,OAAO;AAC9B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,uBAAuB,OAAO;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe;AACf,cAAc;AACd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe;AACf;AACA;AACA,eAAe;AACf;AACA;AACA,WAAW;AACX;AACA;AACA,qBAAqB,OAAO;AAC5B;;AAEA,yBAAyB;AACzB;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,eAAe;AACf,cAAc;AACd;AACA;AACA;;AAEA;AACA,gDAAgD;AAChD;AACA;AACA,oDAAoD;AACpD;AACA;;AAEA;AACA,YAAY;AACZ;AACA;;AAEA,gBAAgB,OAAO;AACvB;AACA;AACA;AACA;AACA,WAAW;AACX,iBAAiB,OAAO;AACxB,SAAS;AACT;AACA,sDAAsD,aAAa;AACnE;AACA,SAAS;AACT;AACA,OAAO;;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,6BAA6B;AAC7B;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW;;AAEX;AACA;AACA;AACA;AACA;AACA,oCAAoC;AACpC,eAAe;AACf;AACA;AACA;AACA;AACA;AACA,WAAW;AACX;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,OAAO;;AAEP;AACA;AACA;AACA;AACA;AACA;AACA,UAAU;AACV,qBAAqB,OAAO;AAC5B;AACA;;AAEA;AACA;AACA,cAAc;AACd;AACA;AACA,WAAW;AACX;AACA,eAAe,OAAO;AACtB,OAAO;;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW;AACX;AACA,SAAS;AACT,OAAO;;AAEP;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,WAAW;AACX;AACA;AACA;AACA,8BAA8B;AAC9B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,2BAA2B;AAC3B,kCAAkC;AAClC,8BAA8B;AAC9B,iFAAiF;AACjF;AACA,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,WAAW;AACX;AACA;AACA;AACA;AACA;AACA,+CAA+C;AAC/C;AACA,aAAa;AACb,6DAA6D,gBAAgB;AAC7E;AACA;AACA,cAAc;AACd;AACA;;AAEA;AACA,WAAW;AACX;;AAEA;AACA;AACA,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA,yCAAyC;AACzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA,IAAI;AACJ;AACA,IAAI;AACJ;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP,MAAM;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP,MAAM;AACN,UAAU,OAAO;AACjB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW;AACX,OAAO;AACP;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO;AACtB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA,QAAQ;AACR;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB,OAAO;AAC1B;AACA;AACA,UAAU;AACV;AACA;AACA;;AAEA;AACA;AACA;AACA,KAAK;;AAEL;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;;;;;;;;;;;ACpqBA;AACA;AACA;AACA;AACA;AACa;;AAEb,gBAAgB,mBAAO,CAAC,yFAAyB;AACjD,UAAU,mBAAO,CAAC,6DAAQ;;AAE1B;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;;;;;;;;;;;ACxBA;AACA;AACA;AACA;AACA;AACa;;AAEb;AACA,iBAAiB,uGAAkC;AACnD,iBAAiB,uGAAkC;AACnD;;AAEA;;;;;;;;;;;;;ACZA;AACA;AACA;AACA;AACA;AACa;;AAEb,YAAY,mBAAO,CAAC,qEAAe;AACnC,QAAQ,aAAa,EAAE,mBAAO,CAAC,2FAAM;;AAErC,aAAa,mBAAO,CAAC,0DAAe;AACpC,YAAY,mBAAO,CAAC,wDAAc;AAClC,cAAc,mBAAO,CAAC,4DAAgB;AACtC,mBAAmB,mBAAO,CAAC,sEAAqB;AAChD,WAAW,mBAAO,CAAC,sDAAa;AAChC,WAAW,mBAAO,CAAC,sDAAa;AAChC,WAAW,mBAAO,CAAC,sDAAa;;AAEhC,iBAAiB,mBAAO,CAAC,2EAAe;AACxC,gBAAgB,mBAAO,CAAC,yEAAgB;AACxC,cAAc,mBAAO,CAAC,qEAAc;AACpC,WAAW,mBAAO,CAAC,+DAAS;;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,gBAAgB,GAAG,uBAAuB;AAC9C,IAAI,4BAA4B;AAChC;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;;AAEA;AACA,eAAe;AACf,eAAe;AACf;AACA;;AAEA;AACA;AACA,oBAAoB,+CAA+C;AACnE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;;AAEA;AACA;AACA;AACA,GAAG;AACH;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA,cAAc,cAAc;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA,cAAc,QAAQ;AACtB;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA,cAAc,QAAQ;AACtB;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA,cAAc,QAAQ;AACtB;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA,cAAc,QAAQ;AACtB;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA,cAAc,QAAQ;AACtB;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB,eAAe,SAAS;AACxB;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO;AACtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB,eAAe,UAAU;AACzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;;AAEA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,eAAe,SAAS,WAAW,KAAK;AACxC;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,SAAS;AACtB;AACA,eAAe,SAAS,0CAA0C;AAClE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,mBAAmB;AACzB;AACA,aAAa,QAAQ;AACrB,aAAa,SAAS;AACtB;AACA,eAAe,KAAK;AACpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA,QAAQ;AACR;AACA,QAAQ;AACR;AACA;AACA;;AAEA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,SAAS;AACtB;AACA,aAAa,UAAU;AACvB;AACA,eAAe,QAAQ;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,wFAAwF;AACxF;AACA;;AAEA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA,aAAa,SAAS;AACtB;AACA,eAAe,QAAQ;AACvB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,SAAS;AACtB;AACA,aAAa,UAAU;AACvB;AACA,eAAe,QAAQ;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,wFAAwF;AACxF;AACA;;AAEA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA,wDAAwD;AACxD;AACA;AACA;AACA;AACA;AACA,mEAAmE,KAAK;AACxE;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,eAAe;AAC5B,aAAa,QAAQ;AACrB;AACA,eAAe,SAAS;AACxB,cAAc,OAAO,IAAI,KAAK,iCAAiC;AAC/D;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO;AACtB;AACA;AACA;AACA,eAAe,OAAO;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA,6DAA6D;AAC7D;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ,KAAK;AACb;AACA,WAAW,IAAI;AACf,6BAA6B,KAAK,cAAc,KAAK;AACrD;AACA,aAAa,QAAQ;AACrB,aAAa,eAAe;AAC5B,aAAa,eAAe;AAC5B,aAAa,QAAQ;AACrB;AACA,eAAe,SAAS;AACxB,cAAc,OAAO,IAAI,KAAK,iCAAiC;AAC/D;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO;AACtB;AACA;AACA;AACA,eAAe,OAAO;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA,2DAA2D;AAC3D;AACA;AACA,2DAA2D;AAC3D,kBAAkB;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,eAAe;AAC5B,aAAa,QAAQ;AACrB;AACA,eAAe,SAAS;AACxB,cAAc,OAAO,IAAI,KAAK,iCAAiC;AAC/D;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO;AACtB;AACA;AACA;AACA,eAAe,OAAO;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA,2DAA2D;AAC3D;AACA;AACA,2DAA2D;AAC3D,oBAAoB;AACpB;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,eAAe;AAC5B,aAAa,QAAQ;AACrB,eAAe,SAAS;AACxB,cAAc,OAAO,IAAI,KAAK,iCAAiC;AAC/D;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO;AACtB;AACA;AACA;AACA,eAAe,OAAO;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA,2DAA2D;AAC3D;AACA;AACA,2DAA2D;AAC3D,qBAAqB;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,eAAe;AAC5B,aAAa,QAAQ;AACrB;AACA,eAAe,SAAS;AACxB,cAAc,OAAO,IAAI,KAAK,iCAAiC;AAC/D;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO;AACtB;AACA;AACA;AACA,eAAe,OAAO;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA,uDAAuD;AACvD;AACA;AACA,2DAA2D;AAC3D,qBAAqB;AACrB;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,eAAe;AAC5B,aAAa,QAAQ;AACrB,eAAe,SAAS;AACxB,cAAc,OAAO,IAAI,KAAK,iCAAiC;AAC/D;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO;AACtB;AACA;AACA;AACA,eAAe,OAAO;AACtB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;;AAEA;;;;;;;;;;;;AC5rBA;AACA;AACA;AACA;AACA;AACa;;AAEb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;ACdA;AACA;AACA;AACA;AACA;AACa;;AAEb,aAAa,mBAAO,CAAC,wFAA0B;AAC/C,YAAY,mBAAO,CAAC,qEAAe;AACnC,cAAc,mBAAO,CAAC,uEAAa;;AAEnC;AACA,WAAW,mBAAO,CAAC,qEAAc;AACjC,WAAW,mBAAO,CAAC,qEAAc;AACjC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO,4BAA4B;AACnC,OAAO,0BAA0B;AACjC,OAAO;AACP;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;;AAEA;AACA,GAAG;AACH;AACA;AACA,OAAO,4BAA4B;AACnC,OAAO,0BAA0B;AACjC,OAAO,0BAA0B;AACjC,OAAO;AACP;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;;AAEA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA,GAAG;;AAEH;AACA;AACA,GAAG;AACH;AACA;AACA,GAAG;;AAEH;AACA;AACA,GAAG;AACH;AACA;AACA,GAAG;;AAEH;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY,OAAO;AACnB;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,OAAO;AAClB,GAAG;AACH;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,sBAAsB;AACtB;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;AACA;AACA;AACA,CAAC,EAAE,oGAA8B;;;;;;;;;;;;;ACxVjC;AACA;AACA;AACA;AACA;AACa;;AAEb,YAAY,mBAAO,CAAC,wDAAc;AAClC,WAAW,mBAAO,CAAC,+DAAS;AAC5B,YAAY,mBAAO,CAAC,qEAAe;;AAEnC,iBAAiB,mBAAO,CAAC,2EAAe;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA,aAAa,OAAO;AACpB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL,cAAc,wBAAwB;AACtC;AACA;AACA,MAAM;AACN,aAAa,OAAO;AACpB;AACA,GAAG;AACH;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA,gCAAgC;AAChC;AACA,YAAY;;AAEZ;AACA,GAAG;AACH;AACA,KAAK,4BAA4B;AACjC,KAAK,4BAA4B;AACjC,KAAK,4BAA4B;AACjC,KAAK,4BAA4B;AACjC,KAAK,2BAA2B;AAChC,KAAK,4BAA4B;AACjC,KAAK,4BAA4B;AACjC,KAAK;AACL;AACA;AACA;;;;;;;;;;;;AChYA;AACA;AACA;AACA;AACA;AACa;;AAEb,eAAe,mBAAO,CAAC,uEAAe;;AAEtC;AACA;AACA;AACA,CAAC;;AAED;AACA,gBAAgB,mBAAO,CAAC,yEAAgB;AACxC;AACA;AACA,CAAC;;AAED;AACA,mBAAO,CAAC,mEAAa;AACrB,mBAAO,CAAC,mEAAa;AACrB,mBAAO,CAAC,iEAAY;;;;;;;;;;;;;ACvBpB;AACA;AACA;AACA;AACA;AACa;;AAEb,YAAY,mBAAO,CAAC,wDAAc;AAClC,YAAY,mBAAO,CAAC,qEAAe;AACnC,YAAY,mBAAO,CAAC,qEAAe;AACnC,WAAW,mBAAO,CAAC,+DAAS;;AAE5B;AACA,WAAW,mBAAO,CAAC,qEAAc;AACjC,WAAW,mBAAO,CAAC,qEAAc;AACjC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW;AACX;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA,kDAAkD,kBAAkB;AACpE;AACA,GAAG;AACH;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL,GAAG;;AAEH;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB;AAClB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,uEAAuE;AACvE,sBAAsB;AACtB;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,kBAAkB,MAAM,yBAAyB,IAAI;AACrD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,wBAAwB,OAAO;AAC/B;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,eAAe;AAC5B,aAAa,QAAQ;AACrB;AACA,eAAe,SAAS;AACxB,cAAc,OAAO,IAAI,KAAK;AAC9B;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO;AACtB;;AAEA,+BAA+B;AAC/B;;AAEA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA,OAAO;AACP;AACA,GAAG;AACH;AACA;AACA;AACA,sCAAsC,KAAK;AAC3C,0CAA0C,KAAK;AAC/C;AACA;AACA;AACA,aAAa,eAAe;AAC5B,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,eAAe,SAAS;AACxB;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;AACA,cAAc;AACd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb,YAAY;AACZ,mBAAmB,OAAO;AAC1B;AACA;AACA,QAAQ;AACR;AACA;AACA,QAAQ;AACR;AACA;;AAEA;AACA;AACA,eAAe,OAAO;AACtB;;AAEA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;;AAEA;AACA,OAAO;AACP;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA,kCAAkC,UAAU;AAC5C;AACA,aAAa,SAAS;AACtB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,OAAO;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,SAAS;AACtB;AACA;AACA;AACA,eAAe,WAAW;AAC1B;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,OAAO;;AAEP;AACA;AACA;;AAEA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA,qDAAqD,IAAI;AACzD;AACA,MAAM,oBAAoB;AAC1B,eAAe,IAAI,MAAM,KAAK;AAC9B;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,aAAa,SAAS;AACtB;AACA;AACA;AACA,eAAe,SAAS,kBAAkB,KAAK,KAAK,MAAM;AAC1D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA,eAAe,cAAc;AAC7B;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA,wBAAwB,2BAA2B;AACnD;AACA,aAAa,SAAS;AACtB;AACA,eAAe,QAAQ;AACvB;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,SAAS;AACT;AACA,OAAO;;AAEP;AACA;AACA;AACA;AACA,GAAG;AACH;;AAEA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,aAAa,SAAS,WAAW,KAAK;AACtC;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,aAAa,cAAc;AAC3B;AACA;AACA;AACA;;AAEA;AACA;AACA,wBAAwB,GAAG;AAC3B;AACA,UAAU,IAAI;AACd,UAAU,IAAI;AACd,UAAU,IAAI,sDAAsD;AACpE,wBAAwB,yBAAyB,IAAI;AACrD,UAAU,IAAI,2DAA2D;AACzE,wBAAwB;AACxB;AACA,WAAW,eAAe;AAC1B;AACA,aAAa,uBAAuB;AACpC;AACA;AACA;AACA,WAAW,OAAO;AAClB;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,IAAI;AACJ;AACA,IAAI;AACJ,WAAW,OAAO;AAClB;;AAEA;AACA;AACA,GAAG;;AAEH,gBAAgB,OAAO;AACvB;AACA;AACA,GAAG;;AAEH;AACA;;;AAGA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,uBAAuB,KAAK;AAC5B;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,WAAW,eAAe;AAC1B,WAAW,QAAQ;AACnB;AACA,aAAa,SAAS;AACtB,YAAY,OAAO,IAAI,KAAK;AAC5B;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,4CAA4C,KAAK;AACjD;AACA,2BAA2B,wBAAwB;AACnD;AACA,WAAW,eAAe;AAC1B,WAAW,QAAQ;AACnB,WAAW,QAAQ;AACnB,aAAa,kBAAkB;AAC/B;AACA;AACA;AACA,WAAW,OAAO;AAClB;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;AC5rBA;AACA;AACA;AACA;AACA;AACa;;AAEb,WAAW,mBAAO,CAAC,+DAAS;;AAE5B;AACA,WAAW,mBAAO,CAAC,qEAAc;AACjC,WAAW,mBAAO,CAAC,qEAAc;AACjC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA,GAAG;AACH;AACA;AACA,OAAO;AACP;;AAEA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;;AAEA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA,8BAA8B;AAC9B;AACA;AACA;AACA,2BAA2B;AAC3B;AACA,WAAW;AACX;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;;AAEA;AACA,GAAG;AACH;AACA;AACA,GAAG;AACH;;AAEA;AACA;AACA,GAAG;AACH;;AAEA;AACA;AACA,GAAG;AACH;;AAEA;AACA;AACA,GAAG;AACH;;AAEA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY,OAAO;AACnB;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA,GAAG;AACH;AACA;AACA;;AAEA,WAAW,OAAO;AAClB;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;AACA,CAAC;;AAED;AACA;AACA;AACA,CAAC,EAAE,oGAA8B;;;;;;;;;;;;;AC9NjC;AACA;AACA;AACA;AACA;AACa;;AAEb,YAAY,mBAAO,CAAC,wEAAkB;AACtC,WAAW,mBAAO,CAAC,uFAAwB;AAC3C,iBAAiB,uHAA2C;;AAE5D;AACA,WAAW,mBAAO,CAAC,qEAAc;AACjC,WAAW,mBAAO,CAAC,qEAAc;AACjC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO,0BAA0B;AACjC,OAAO;AACP;AACA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;;AAEA;AACA,GAAG;AACH;AACA;AACA,OAAO,0BAA0B;AACjC,OAAO,0BAA0B;AACjC,OAAO,0BAA0B;AACjC,OAAO,0BAA0B;AACjC,OAAO,0BAA0B;AACjC,OAAO,2BAA2B;AAClC,OAAO,2BAA2B;AAClC,OAAO;AACP;;AAEA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;;AAEA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,GAAG;;AAEH;AACA;AACA,GAAG;AACH;AACA;AACA,GAAG;;AAEH;AACA;AACA,GAAG;AACH;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY,OAAO;AACnB;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA,GAAG;AACH;AACA;AACA;;AAEA;AACA,oBAAoB,OAAO;AAC3B;AACA;AACA;AACA,SAAS;AACT;AACA;AACA,SAAS;AACT,OAAO;AACP,MAAM;AACN;AACA;AACA;AACA,OAAO;AACP,gBAAgB,OAAO;AACvB;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,+BAA+B;AACxC,SAAS,+BAA+B;AACxC,SAAS;AACT;AACA;AACA;;AAEA;AACA;AACA,UAAU;AACV;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO;;AAEP;AACA,KAAK;AACL,GAAG;AACH;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB;AACtB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,CAAC;;AAED;AACA;AACA;AACA,CAAC,EAAE,oGAA8B;;;;;;;;;;;;AC5WjC;AACA;AACA;AACA;AACA;AACa;;AAEb;AACA;AACA,4BAA4B,qBAAqB;AACjD;AACA,cAAc,SAAS;AACvB;AACA;AACA,cAAc,iBAAiB;AAC/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;;;;;;;;;;;ACxBA;AACA;AACA;AACA;AACA;AACa;;AAEb;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACXA;AACA;AACA;AACA;AACA;AACa;;AAEb;AACA,cAAc,8FAA4B;AAC1C,gBAAgB,oGAAgC;AAChD;;AAEA;;;;;;;;;;;;;ACZA;AACA;AACA;AACA;AACA;AACa;;AAEb,YAAY,mBAAO,CAAC,qEAAe;AACnC,WAAW,mBAAO,CAAC,+DAAS;AAC5B,UAAU,mBAAO,CAAC,6DAAQ;AAC1B,YAAY,+FAA0B;;AAEtC,YAAY,mBAAO,CAAC,wDAAc;AAClC,WAAW,mBAAO,CAAC,sDAAa;;AAEhC,eAAe,mBAAO,CAAC,oEAAY;;AAEnC;AACA;AACA;AACA;AACA;AACA,uEAAuE;AACvE,kBAAkB;AAClB;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,SAAS;AACtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA,GAAG;AACH;AACA;AACA;AACA,KAAK;AACL;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ,MAAM,cAAc,UAAU,wBAAwB,MAAM;AACpE,yCAAyC,SAAS;AAClD;AACA,YAAY,eAAe;AAC3B,YAAY,QAAQ,qCAAqC,KAAK;AAC9D,cAAc,YAAY;AAC1B,aAAa,OAAO;AACpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;;AAEA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA,uCAAuC,yBAAyB;AAChE,0CAA0C,yBAAyB;AACnE;AACA;AACA,YAAY,eAAe;AAC3B,YAAY,QAAQ;AACpB;AACA,cAAc,SAAS;AACvB,aAAa,OAAO;AACpB;AACA;AACA;AACA;AACA,eAAe,OAAO;AACtB;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,gBAAgB,OAAO;AACvB;AACA;AACA;;AAEA;AACA;AACA,0BAA0B;AAC1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW;AACX;AACA;AACA;AACA,YAAY;AACZ;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW;AACX;AACA,SAAS;AACT,gBAAgB,OAAO;AACvB,eAAe,OAAO;AACtB,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW;AACX;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,WAAW;AACX;AACA;;AAEA;AACA;AACA,GAAG;AACH;;;AAGA;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,WAAW,SAAS;AACpB,WAAW,QAAQ;AACnB;AACA,WAAW,QAAQ;AACnB,WAAW,oBAAoB;AAC/B,6BAA6B;AAC7B;AACA,WAAW,SAAS;AACpB,WAAW,QAAQ;AACnB,WAAW,QAAQ;AACnB,WAAW,iBAAiB;AAC5B;AACA,aAAa,YAAY;AACzB,YAAY,OAAO;AACnB;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP,MAAM;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP,MAAM;AACN,UAAU,OAAO;AACjB;;AAEA;AACA;AACA;;AAEA;AACA;AACA,6BAA6B;AAC7B;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA,QAAQ;AACR;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB,OAAO;AAC1B;AACA;AACA,UAAU;AACV;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA,QAAQ;AACR;AACA,QAAQ;AACR;AACA,QAAQ;AACR,eAAe,OAAO;AACtB;AACA;AACA;;AAEA;AACA;AACA;AACA,KAAK;;AAEL;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;;;;;;;;;;;;AClXA;AACA;AACA;AACA;AACA;AACa;;AAEb,YAAY,mBAAO,CAAC,wDAAc;AAClC,YAAY,mBAAO,CAAC,qEAAe;AACnC,gBAAgB,mBAAO,CAAC,6EAAmB;AAC3C,gBAAgB,mBAAO,CAAC,6EAAmB;AAC3C,UAAU,mBAAO,CAAC,6DAAQ;;AAE1B;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,uEAAuE;AACvE,oBAAoB;AACpB;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,IAAI;AACJ;AACA,IAAI;AACJ;AACA;;AAEA;;AAEA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA,qBAAqB,wBAAwB;AAC7C;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,2CAA2C;;AAE3C;AACA;AACA,yCAAyC;AACzC;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,iBAAiB,OAAO;AACxB;;AAEA;AACA;AACA;AACA;AACA,mBAAmB,OAAO;AAC1B;AACA,4BAA4B,mBAAmB;AAC/C;AACA,qBAAqB,OAAO;AAC5B;AACA;AACA;AACA;AACA;AACA;;AAEA,eAAe,OAAO;AACtB;AACA;AACA;AACA;AACA,SAAS;AACT,OAAO;;AAEP,oBAAoB,OAAO;AAC3B;AACA,mBAAmB,OAAO;AAC1B;AACA;AACA;AACA;AACA;AACA;;AAEA,0BAA0B;AAC1B;AACA,aAAa;AACb,oBAAoB,OAAO;AAC3B;AACA;AACA;AACA;AACA;AACA;AACA,gBAAgB;AAChB;AACA;AACA;AACA;AACA,gBAAgB;AAChB,yBAAyB,OAAO;AAChC;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA,yBAAyB,OAAO;AAChC;AACA;AACA;AACA,eAAe;AACf,aAAa;;AAEb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB;AAClB;AACA;AACA;AACA,kCAAkC,OAAO;AACzC;AACA,eAAe;AACf,qBAAqB,OAAO;AAC5B;AACA,2BAA2B,KAAK;AAChC;AACA,eAAe;AACf,aAAa;;AAEb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,gBAAgB;AAChB;AACA;AACA;AACA;AACA,aAAa;;AAEb;AACA;AACA;AACA;AACA,aAAa;;AAEb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;;AAEb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kCAAkC,OAAO;AACzC;AACA,eAAe;AACf,qBAAqB,OAAO;AAC5B;AACA,2BAA2B,KAAK;AAChC;AACA,eAAe;AACf,aAAa;AACb;AACA;AACA;AACA,SAAS;AACT,OAAO;AACP;AACA;AACA,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACA,WAAW,sBAAsB;AACjC,aAAa,cAAc;AAC3B;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;;;;;;;;;;;AC9QA;AACA;AACA;AACA;AACA;AACa;;AAEb;AACA,OAAO,mBAAO,CAAC,6DAAQ;AACvB,OAAO,mBAAO,CAAC,6DAAQ;AACvB,QAAQ,mBAAO,CAAC,+DAAS;AACzB;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;;;;;;;;;;;ACjDA;AACA;AACA;AACA;AACA;AACa;;AAEb,cAAc,mBAAO,CAAC,oEAAW;AACjC,WAAW,mBAAO,CAAC,8DAAQ;;AAE3B;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA,IAAI;AACJ;AACA,IAAI;AACJ;AACA;AACA;;AAEA;AACA;;;;;;;;;;;;ACxBA;AACA;AACA;AACA;AACA;AACa;;AAEb,YAAY,mBAAO,CAAC,qEAAe;;AAEnC;AACA,OAAO,mBAAO,CAAC,6DAAQ;AACvB,OAAO,mBAAO,CAAC,6DAAQ;AACvB,QAAQ,mBAAO,CAAC,+DAAS;AACzB;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe;AACf;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,KAAK;AACL,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,qCAAqC;AACrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,KAAK;AACL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;;;;;;;;;;;AC9FA;AACA;AACA;AACA;AACA;AACa;;AAEb;AACA,sCAAsC;AACtC;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;AACA;AACA,cAAc;;AAEd;AACA;AACA,kBAAkB;;AAElB;AACA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,GAAG;AACH;;AAEA;;;;;;;;;;;;AC5FA;AACA;AACA;AACA;AACA;AACa;;AAEb,WAAW,mBAAO,CAAC,wDAAW;;AAE9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,OAAO,mBAAmB,UAAU;AAC7C,MAAM,UAAU;AAChB;AACA,aAAa,eAAe;AAC5B,aAAa,QAAQ;AACrB,eAAe,QAAQ,2BAA2B,MAAM;AACxD;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,GAAG;AACH;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB,eAAe,eAAe,2BAA2B,MAAM;AAC/D;AACA;AACA;;AAEA;;;;;;;;;;;;AChDA;AACA;AACA;AACA;AACA;AACa;;AAEb,YAAY,mBAAO,CAAC,wEAAkB;AACtC,gBAAgB,mBAAO,CAAC,0EAAgB;;AAExC;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA,IAAI;AACJ;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,IAAI;AACJ;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA,4BAA4B,kBAAkB;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;AACA,IAAI;AACJ;AACA,IAAI;AACJ;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;;;;;;;;;;;ACzdA;AACA;AACA;AACA;AACA;AACa;;AAEb,YAAY,mBAAO,CAAC,wEAAkB;;AAEtC;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,aAAa,mBAAO,CAAC,0EAAgB;AACrC,QAAQ,mBAAO,CAAC,gEAAW;AAC3B;AACA;AACA;AACA;;;;;;;;;;;;ACjDA;AACA;AACA;AACA;AACA;AACa;;AAEb,mBAAmB,mBAAO,CAAC,sEAAqB;AAChD,YAAY,mBAAO,CAAC,wDAAc;;AAElC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;AACA;AACA,oBAAoB,uCAAuC;AAC3D;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;;;;;;;;;;;;AC7DA;AACA;AACA;AACA;AACA;AACa;;AAEb;;AAEA;AACA;AACA,yCAAyC,EAAE;AAC3C;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;;AAEA;AACA;;;;;;;;;;;AC1BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY,mBAAO,CAAC,kFAAS;AAC7B,mBAAO,CAAC,oFAAU;AAClB,mBAAO,CAAC,8FAAe;AACvB,mBAAO,CAAC,gFAAQ;;AAEhB;AACA;;AAEA;AACA;AACA;AACA;AACA,iBAAiB,OAAO;AACxB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACA,mBAAmB,OAAO;AAC1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA,mBAAmB,gBAAgB;AACnC;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,qBAAqB,SAAS;AAC9B;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA,kBAAkB;AAClB,kBAAkB;AAClB,kBAAkB;AAClB,kBAAkB;AAClB,kBAAkB;AAClB,kBAAkB;AAClB,kBAAkB;;AAElB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gDAAgD,GAAG;AACnD,cAAc,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK;AAC1C,cAAc,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG;AAC7C;AACA;AACA;AACA;AACA;AACA,mCAAmC,IAAI,UAAU,GAAG;AACpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,IAAI,IAAI;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,cAAc,GAAG,EAAE,GAAG,EAAE,GAAG;AAC3B;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,iBAAiB,SAAS;AAC1B;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,iBAAiB,OAAO;AACxB;AACA;AACA;AACA;AACA,iBAAiB,SAAS;AAC1B;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,0CAA0C,IAAI,IAAI,SAAS;;AAE3D;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qBAAqB;AACrB;AACA;AACA;AACA;AACA,8BAA8B;AAC9B;AACA,mBAAmB,OAAO;AAC1B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,kBAAkB,SAAS;AAC3B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kCAAkC,SAAS;AAC3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA;AACA;AACA;AACA,uBAAuB,QAAQ;AAC/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,qBAAqB,YAAY;AACjC;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;;;;;;;;;;AClkCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oCAAoC;AACpC,mCAAmC;AACnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY,mBAAO,CAAC,kFAAS;AAC7B,mBAAO,CAAC,gFAAQ;AAChB,mBAAO,CAAC,gFAAQ;;AAEhB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,mBAAmB,kBAAkB;AACrC;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,mBAAmB,gBAAgB;AACnC;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW;AACX;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW;AACX;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,YAAY,YAAY;AACxB;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;;AAEA;AACA,mBAAmB,sBAAsB;AACzC;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA,qBAAqB,sBAAsB;AAC3C;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;;AAEN;AACA;AACA;;AAEA;AACA;AACA,qCAAqC,QAAQ;AAC7C;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,iBAAiB,mBAAmB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;;AAEN;AACA,uCAAuC,QAAQ;AAC/C;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,+CAA+C;AAC/C;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA,QAAQ;AACR;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,mDAAmD;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,IAAI;AACJ;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qBAAqB;AACrB;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,iBAAiB,mBAAmB;AACpC;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qBAAqB;AACrB;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,iBAAiB,mBAAmB;AACpC;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4CAA4C;AAC5C;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,wCAAwC;AACxC;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,uBAAuB,4BAA4B;AACnD;AACA;AACA;AACA;AACA;AACA,cAAc;AACd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA,iBAAiB,yBAAyB;AAC1C;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,mBAAmB,sBAAsB;AACzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA,QAAQ;AACR;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA,MAAM;AACN;AACA;AACA,MAAM;AACN;AACA,MAAM;AACN;AACA,MAAM;AACN;AACA;AACA;;AAEA;AACA;;;;;;;;;;;ACz5CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA,eAAe,kBAAkB;AACjC,uCAAuC,mBAAmB;AAC1D;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA,eAAe,wCAAwC;AACvD;AACA;AACA;AACA,+BAA+B,QAAQ;AACvC;AACA;AACA;;AAEA;AACA,8BAA8B,kBAAkB;AAChD;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,mBAAmB,qBAAqB;AACxC;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,iBAAiB,kBAAkB;AACnC;AACA;AACA;AACA;;AAEA,kCAAkC,kBAAkB;AACpD;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA,iBAAiB,4CAA4C;AAC7D;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,aAAa,oBAAoB;AACjC,wCAAwC,mBAAmB;AAC3D;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA,aAAa,6CAA6C;AAC1D;AACA;AACA;AACA,6BAA6B,QAAQ;AACrC;AACA;;AAEA;AACA;;;;;;;;;;;ACzLA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY,mBAAO,CAAC,kFAAS;AAC7B,mBAAO,CAAC,gFAAQ;;AAEhB;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;;;;;;;;;;ACrOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY,mBAAO,CAAC,kFAAS;AAC7B,mBAAO,CAAC,gFAAQ;;AAEhB;;AAEA;AACA;;AAEA,+CAA+C;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA,iBAAiB,gBAAgB;AACjC;AACA;;AAEA;AACA;;AAEA;AACA,iBAAiB,gBAAgB;AACjC;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA,iBAAiB,gBAAgB;AACjC;AACA;;AAEA;AACA;;AAEA;AACA,iBAAiB,gBAAgB;AACjC;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,iBAAiB,gBAAgB;AACjC;AACA;;AAEA;AACA;;AAEA;AACA,iBAAiB,gBAAgB;AACjC;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA,iBAAiB,gBAAgB;AACjC;AACA;;AAEA;AACA;;AAEA;AACA;AACA,iBAAiB,gBAAgB;AACjC;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,mBAAmB,gBAAgB;AACnC;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,iBAAiB,gBAAgB;AACjC;AACA;AACA;;AAEA;AACA;AACA;AACA,IAAI;AACJ;AACA,mBAAmB,gBAAgB;AACnC;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,mBAAmB,gBAAgB;AACnC;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,iBAAiB,gBAAgB;AACjC;AACA;AACA;;AAEA;AACA;AACA;AACA,IAAI;AACJ;AACA,mBAAmB,gBAAgB;AACnC;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,mBAAmB,gBAAgB;AACnC;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,iBAAiB,gBAAgB;AACjC;AACA;;AAEA;AACA;AACA;AACA,IAAI;AACJ;AACA,mBAAmB,gBAAgB;AACnC;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,mBAAmB,gBAAgB;AACnC;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,mBAAmB,gBAAgB;AACnC;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,mBAAmB,gBAAgB;AACnC;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,mBAAmB,gBAAgB;AACnC;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA;;AAEA;AACA,qBAAqB,gBAAgB;AACrC;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,iBAAiB,gBAAgB;AACjC;AACA;;AAEA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,iBAAiB,gBAAgB;AACjC;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,iBAAiB,SAAS;AAC1B,uBAAuB,KAAK;AAC5B,eAAe,KAAK;AACpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,iBAAiB,OAAO;AACxB;AACA;AACA;AACA;;AAEA;AACA,sBAAsB,6CAA6C;AACnE;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,iBAAiB,QAAQ;AACzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB,UAAU;AAC3B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB,OAAO;AAC1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB,UAAU;AAC9B;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,mBAAmB,gBAAgB;AACnC;AACA;AACA;;AAEA;AACA;AACA,0BAA0B;AAC1B;AACA;;AAEA;AACA;AACA;AACA;AACA,mBAAmB,YAAY;AAC/B;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;;;;;;;;;;ACt+BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAgB,+BAA+B;AAC/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY,mBAAO,CAAC,kFAAS;AAC7B,mBAAO,CAAC,oFAAU;AAClB,mBAAO,CAAC,8FAAe;AACvB,mBAAO,CAAC,gFAAQ;;AAEhB;AACA;;AAEA;AACA;AACA;AACA;AACA,iBAAiB,OAAO;AACxB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACA,mBAAmB,OAAO;AAC1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA;AACA,GAAG;AACH;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA,iBAAiB,gBAAgB;AACjC;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,mBAAmB,mBAAmB;AACtC;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA,iBAAiB,gBAAgB;AACjC;AACA;;AAEA;AACA,4BAA4B,cAAc;AAC1C;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,IAAI;AACJ;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;;;;;;;;;;;;;;;;;;;;AC/e0E;AACrB;AAC9C;AACA;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACO;AACP;AACA;AACA;AACA,UAAU,+DAAiB;AAC3B;AACA;AACA;;;;;;;;;;;;;;;;AC3BO;AACP","sources":["webpack://@agentx/agentx/../../node_modules/node-html-parser/dist/back.js","webpack://@agentx/agentx/../../node_modules/node-html-parser/dist/index.js","webpack://@agentx/agentx/../../node_modules/node-html-parser/dist/matcher.js","webpack://@agentx/agentx/../../node_modules/node-html-parser/dist/nodes/comment.js","webpack://@agentx/agentx/../../node_modules/node-html-parser/dist/nodes/html.js","webpack://@agentx/agentx/../../node_modules/node-html-parser/dist/nodes/node.js","webpack://@agentx/agentx/../../node_modules/node-html-parser/dist/nodes/text.js","webpack://@agentx/agentx/../../node_modules/node-html-parser/dist/nodes/type.js","webpack://@agentx/agentx/../../node_modules/node-html-parser/node_modules/he/he.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/algorithms/aes-cbc-hmac-sha2.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/algorithms/aes-gcm.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/algorithms/aes-kw.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/algorithms/concat.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/algorithms/constants.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/algorithms/dir.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/algorithms/ec-util.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/algorithms/ecdh.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/algorithms/ecdsa.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/algorithms/helpers.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/algorithms/hkdf.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/algorithms/hmac.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/algorithms/index.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/algorithms/pbes2.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/algorithms/rsa-util.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/algorithms/rsaes.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/algorithms/rsassa.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/algorithms/sha.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/deps/ciphermodes/gcm/helpers.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/deps/ciphermodes/gcm/index.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/deps/ciphermodes/gcm/multipliers.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/deps/ciphermodes/helpers.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/deps/ciphermodes/pack.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/deps/ecc/curves.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/deps/ecc/index.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/deps/ecc/math.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/deps/forge.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/index.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/jwe/decrypt.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/jwe/defaults.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/jwe/encrypt.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/jwe/helpers.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/jwe/index.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/jwk/basekey.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/jwk/constants.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/jwk/eckey.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/jwk/helpers.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/jwk/index.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/jwk/keystore.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/jwk/octkey.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/jwk/rsakey.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/jws/defaults.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/jws/helpers.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/jws/index.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/jws/sign.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/jws/verify.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/parse/compact.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/parse/index.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/parse/json.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/util/algconfig.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/util/base64url.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/util/databuffer.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/util/index.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/util/merge.js","webpack://@agentx/agentx/../../node_modules/node-jose/lib/util/utf8.js","webpack://@agentx/agentx/../../node_modules/node-jose/node_modules/node-forge/lib/aes.js","webpack://@agentx/agentx/../../node_modules/node-jose/node_modules/node-forge/lib/asn1.js","webpack://@agentx/agentx/../../node_modules/node-jose/node_modules/node-forge/lib/baseN.js","webpack://@agentx/agentx/../../node_modules/node-jose/node_modules/node-forge/lib/cipher.js","webpack://@agentx/agentx/../../node_modules/node-jose/node_modules/node-forge/lib/cipherModes.js","webpack://@agentx/agentx/../../node_modules/node-jose/node_modules/node-forge/lib/des.js","webpack://@agentx/agentx/../../node_modules/nanoid/index.browser.js","webpack://@agentx/agentx/../../node_modules/nanoid/url-alphabet/index.js"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nfunction arr_back(arr) {\n return arr[arr.length - 1];\n}\nexports.default = arr_back;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar comment_1 = require(\"./nodes/comment\");\nexports.CommentNode = comment_1.default;\nvar html_1 = require(\"./nodes/html\");\nexports.HTMLElement = html_1.default;\nexports.parse = html_1.parse;\nexports.default = html_1.parse;\nvar node_1 = require(\"./nodes/node\");\nexports.Node = node_1.default;\nvar text_1 = require(\"./nodes/text\");\nexports.TextNode = text_1.default;\nvar type_1 = require(\"./nodes/type\");\nexports.NodeType = type_1.default;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n/**\n * Cache to store generated match functions\n * @type {Object}\n */\nvar pMatchFunctionCache = {};\n/**\n * Function cache\n */\nvar functionCache = {\n f145: function (el, tagName, classes) {\n 'use strict';\n tagName = tagName || '';\n classes = classes || [];\n if (el.id !== tagName.substr(1)) {\n return false;\n }\n for (var cls = classes, i = 0; i < cls.length; i++) {\n if (el.classNames.indexOf(cls[i]) === -1) {\n return false;\n }\n }\n return true;\n },\n f45: function (el, tagName, classes) {\n 'use strict';\n tagName = tagName || '';\n classes = classes || [];\n for (var cls = classes, i = 0; i < cls.length; i++) {\n if (el.classNames.indexOf(cls[i]) === -1) {\n return false;\n }\n }\n return true;\n },\n f15: function (el, tagName) {\n 'use strict';\n tagName = tagName || '';\n if (el.id !== tagName.substr(1)) {\n return false;\n }\n return true;\n },\n f1: function (el, tagName) {\n 'use strict';\n tagName = tagName || '';\n if (el.id !== tagName.substr(1)) {\n return false;\n }\n },\n f5: function () {\n 'use strict';\n return true;\n },\n f55: function (el, tagName, classes, attr_key) {\n 'use strict';\n tagName = tagName || '';\n classes = classes || [];\n attr_key = attr_key || '';\n var attrs = el.attributes;\n return attrs.hasOwnProperty(attr_key);\n },\n f245: function (el, tagName, classes, attr_key, value) {\n 'use strict';\n tagName = tagName || '';\n classes = classes || [];\n attr_key = attr_key || '';\n value = value || '';\n var attrs = el.attributes;\n return Object.keys(attrs).some(function (key) {\n var val = attrs[key];\n return key === attr_key && val === value;\n });\n // for (let cls = classes, i = 0; i < cls.length; i++) {if (el.classNames.indexOf(cls[i]) === -1){ return false;}}\n // return true;\n },\n f25: function (el, tagName, classes, attr_key, value) {\n 'use strict';\n tagName = tagName || '';\n classes = classes || [];\n attr_key = attr_key || '';\n value = value || '';\n var attrs = el.attributes;\n return Object.keys(attrs).some(function (key) {\n var val = attrs[key];\n return key === attr_key && val === value;\n });\n // return true;\n },\n f2: function (el, tagName, classes, attr_key, value) {\n 'use strict';\n tagName = tagName || '';\n classes = classes || [];\n attr_key = attr_key || '';\n value = value || '';\n var attrs = el.attributes;\n return Object.keys(attrs).some(function (key) {\n var val = attrs[key];\n return key === attr_key && val === value;\n });\n },\n f345: function (el, tagName, classes) {\n 'use strict';\n tagName = tagName || '';\n classes = classes || [];\n if (el.tagName !== tagName) {\n return false;\n }\n for (var cls = classes, i = 0; i < cls.length; i++) {\n if (el.classNames.indexOf(cls[i]) === -1) {\n return false;\n }\n }\n return true;\n },\n f35: function (el, tagName) {\n 'use strict';\n tagName = tagName || '';\n return el.tagName === tagName;\n },\n f3: function (el, tagName) {\n 'use strict';\n tagName = tagName || '';\n if (el.tagName !== tagName) {\n return false;\n }\n }\n};\n/**\n * Matcher class to make CSS match\n *\n * @class Matcher\n */\nvar Matcher = /** @class */ (function () {\n /**\n * Creates an instance of Matcher.\n * @param {string} selector\n *\n * @memberof Matcher\n */\n function Matcher(selector) {\n this.nextMatch = 0;\n functionCache.f5 = functionCache.f5;\n this.matchers = selector.split(' ').map(function (matcher) {\n if (pMatchFunctionCache[matcher])\n return pMatchFunctionCache[matcher];\n var parts = matcher.split('.');\n var tagName = parts[0];\n var classes = parts.slice(1).sort();\n // let source = '\"use strict\";';\n var function_name = 'f';\n var attr_key = '';\n var value = '';\n if (tagName && tagName !== '*') {\n var reg = void 0;\n if (tagName.startsWith('#')) {\n // source += 'if (el.id != ' + JSON.stringify(tagName.substr(1)) + ') return false;';// 1\n function_name += '1';\n }\n else {\n reg = /^\\[\\s*(\\S+)\\s*(=|!=)\\s*(((([\"'])([^\\6]*)\\6))|(\\S*?))\\]\\s*/.exec(tagName);\n if (reg) {\n attr_key = reg[1];\n var method = reg[2];\n if (method !== '=' && method !== '!=') {\n throw new Error('Selector not supported, Expect [key${op}value].op must be =,!=');\n }\n if (method === '=') {\n method = '==';\n }\n value = reg[7] || reg[8];\n // source += `let attrs = el.attributes;for (let key in attrs){const val = attrs[key]; if (key == \"${attr_key}\" && val == \"${value}\"){return true;}} return false;`;// 2\n function_name += '2';\n }\n else if (reg = /^\\[(.*?)\\]/.exec(tagName)) {\n attr_key = reg[1];\n function_name += '5';\n }\n else {\n // source += 'if (el.tagName != ' + JSON.stringify(tagName) + ') return false;';// 3\n function_name += '3';\n }\n }\n }\n if (classes.length > 0) {\n // source += 'for (let cls = ' + JSON.stringify(classes) + ', i = 0; i < cls.length; i++) if (el.classNames.indexOf(cls[i]) === -1) return false;';// 4\n function_name += '4';\n }\n // source += 'return true;';// 5\n function_name += '5';\n var obj = {\n func: functionCache[function_name],\n tagName: tagName || '',\n classes: classes || '',\n attr_key: attr_key || '',\n value: value || ''\n };\n // source = source || '';\n return pMatchFunctionCache[matcher] = obj;\n });\n }\n /**\n * Trying to advance match pointer\n * @param {HTMLElement} el element to make the match\n * @return {bool} true when pointer advanced.\n */\n Matcher.prototype.advance = function (el) {\n if (this.nextMatch < this.matchers.length &&\n this.matchers[this.nextMatch].func(el, this.matchers[this.nextMatch].tagName, this.matchers[this.nextMatch].classes, this.matchers[this.nextMatch].attr_key, this.matchers[this.nextMatch].value)) {\n this.nextMatch++;\n return true;\n }\n return false;\n };\n /**\n * Rewind the match pointer\n */\n Matcher.prototype.rewind = function () {\n this.nextMatch--;\n };\n Object.defineProperty(Matcher.prototype, \"matched\", {\n /**\n * Trying to determine if match made.\n * @return {bool} true when the match is made\n */\n get: function () {\n return this.nextMatch === this.matchers.length;\n },\n enumerable: true,\n configurable: true\n });\n /**\n * Rest match pointer.\n * @return {[type]} [description]\n */\n Matcher.prototype.reset = function () {\n this.nextMatch = 0;\n };\n /**\n * flush cache to free memory\n */\n Matcher.prototype.flushCache = function () {\n pMatchFunctionCache = {};\n };\n return Matcher;\n}());\nexports.default = Matcher;\n","\"use strict\";\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar node_1 = __importDefault(require(\"./node\"));\nvar type_1 = __importDefault(require(\"./type\"));\nvar CommentNode = /** @class */ (function (_super) {\n __extends(CommentNode, _super);\n function CommentNode(value) {\n var _this = _super.call(this) || this;\n /**\n * Node Type declaration.\n * @type {Number}\n */\n _this.nodeType = type_1.default.COMMENT_NODE;\n _this.rawText = value;\n return _this;\n }\n Object.defineProperty(CommentNode.prototype, \"text\", {\n /**\n * Get unescaped text value of current node and its children.\n * @return {string} text content\n */\n get: function () {\n return this.rawText;\n },\n enumerable: true,\n configurable: true\n });\n CommentNode.prototype.toString = function () {\n return \"\";\n };\n return CommentNode;\n}(node_1.default));\nexports.default = CommentNode;\n","\"use strict\";\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar he_1 = require(\"he\");\nvar node_1 = __importDefault(require(\"./node\"));\nvar type_1 = __importDefault(require(\"./type\"));\nvar text_1 = __importDefault(require(\"./text\"));\nvar matcher_1 = __importDefault(require(\"../matcher\"));\nvar back_1 = __importDefault(require(\"../back\"));\nvar comment_1 = __importDefault(require(\"./comment\"));\nvar kBlockElements = {\n div: true,\n p: true,\n // ul: true,\n // ol: true,\n li: true,\n // table: true,\n // tr: true,\n td: true,\n section: true,\n br: true\n};\n/**\n * HTMLElement, which contains a set of children.\n *\n * Note: this is a minimalist implementation, no complete tree\n * structure provided (no parentNode, nextSibling,\n * previousSibling etc).\n * @class HTMLElement\n * @extends {Node}\n */\nvar HTMLElement = /** @class */ (function (_super) {\n __extends(HTMLElement, _super);\n /**\n * Creates an instance of HTMLElement.\n * @param keyAttrs\tid and class attribute\n * @param [rawAttrs]\tattributes in string\n *\n * @memberof HTMLElement\n */\n function HTMLElement(tagName, keyAttrs, rawAttrs, parentNode) {\n if (rawAttrs === void 0) { rawAttrs = ''; }\n if (parentNode === void 0) { parentNode = null; }\n var _this = _super.call(this) || this;\n _this.tagName = tagName;\n _this.rawAttrs = rawAttrs;\n _this.parentNode = parentNode;\n _this.classNames = [];\n /**\n * Node Type declaration.\n */\n _this.nodeType = type_1.default.ELEMENT_NODE;\n _this.rawAttrs = rawAttrs || '';\n _this.parentNode = parentNode || null;\n _this.childNodes = [];\n if (keyAttrs.id) {\n _this.id = keyAttrs.id;\n if (!rawAttrs) {\n _this.rawAttrs = \"id=\\\"\" + keyAttrs.id + \"\\\"\";\n }\n }\n if (keyAttrs.class) {\n _this.classNames = keyAttrs.class.split(/\\s+/);\n if (!rawAttrs) {\n var cls = \"class=\\\"\" + _this.classNames.join(' ') + \"\\\"\";\n if (_this.rawAttrs) {\n _this.rawAttrs += \" \" + cls;\n }\n else {\n _this.rawAttrs = cls;\n }\n }\n }\n return _this;\n }\n /**\n * Remove Child element from childNodes array\n * @param {HTMLElement} node node to remove\n */\n HTMLElement.prototype.removeChild = function (node) {\n this.childNodes = this.childNodes.filter(function (child) {\n return (child !== node);\n });\n };\n /**\n * Exchanges given child with new child\n * @param {HTMLElement} oldNode node to exchange\n * @param {HTMLElement} newNode new node\n */\n HTMLElement.prototype.exchangeChild = function (oldNode, newNode) {\n var idx = -1;\n for (var i = 0; i < this.childNodes.length; i++) {\n if (this.childNodes[i] === oldNode) {\n idx = i;\n break;\n }\n }\n this.childNodes[idx] = newNode;\n };\n Object.defineProperty(HTMLElement.prototype, \"rawText\", {\n /**\n * Get escpaed (as-it) text value of current node and its children.\n * @return {string} text content\n */\n get: function () {\n return this.childNodes.reduce(function (pre, cur) {\n return pre += cur.rawText;\n }, '');\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(HTMLElement.prototype, \"text\", {\n /**\n * Get unescaped text value of current node and its children.\n * @return {string} text content\n */\n get: function () {\n return he_1.decode(this.rawText);\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(HTMLElement.prototype, \"structuredText\", {\n /**\n * Get structured Text (with '\\n' etc.)\n * @return {string} structured text\n */\n get: function () {\n var currentBlock = [];\n var blocks = [currentBlock];\n function dfs(node) {\n if (node.nodeType === type_1.default.ELEMENT_NODE) {\n if (kBlockElements[node.tagName]) {\n if (currentBlock.length > 0) {\n blocks.push(currentBlock = []);\n }\n node.childNodes.forEach(dfs);\n if (currentBlock.length > 0) {\n blocks.push(currentBlock = []);\n }\n }\n else {\n node.childNodes.forEach(dfs);\n }\n }\n else if (node.nodeType === type_1.default.TEXT_NODE) {\n if (node.isWhitespace) {\n // Whitespace node, postponed output\n currentBlock.prependWhitespace = true;\n }\n else {\n var text = node.text;\n if (currentBlock.prependWhitespace) {\n text = ' ' + text;\n currentBlock.prependWhitespace = false;\n }\n currentBlock.push(text);\n }\n }\n }\n dfs(this);\n return blocks\n .map(function (block) {\n // Normalize each line's whitespace\n return block.join('').trim().replace(/\\s{2,}/g, ' ');\n })\n .join('\\n').replace(/\\s+$/, ''); // trimRight;\n },\n enumerable: true,\n configurable: true\n });\n HTMLElement.prototype.toString = function () {\n var tag = this.tagName;\n if (tag) {\n var is_void = /^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/i.test(tag);\n var attrs = this.rawAttrs ? ' ' + this.rawAttrs : '';\n if (is_void) {\n return \"<\" + tag + attrs + \">\";\n }\n else {\n return \"<\" + tag + attrs + \">\" + this.innerHTML + \"\";\n }\n }\n else {\n return this.innerHTML;\n }\n };\n Object.defineProperty(HTMLElement.prototype, \"innerHTML\", {\n get: function () {\n return this.childNodes.map(function (child) {\n return child.toString();\n }).join('');\n },\n enumerable: true,\n configurable: true\n });\n HTMLElement.prototype.set_content = function (content, options) {\n if (options === void 0) { options = {}; }\n if (content instanceof node_1.default) {\n content = [content];\n }\n else if (typeof content == 'string') {\n var r = parse(content, options);\n content = r.childNodes.length ? r.childNodes : [new text_1.default(content)];\n }\n this.childNodes = content;\n };\n Object.defineProperty(HTMLElement.prototype, \"outerHTML\", {\n get: function () {\n return this.toString();\n },\n enumerable: true,\n configurable: true\n });\n /**\n * Trim element from right (in block) after seeing pattern in a TextNode.\n * @param {RegExp} pattern pattern to find\n * @return {HTMLElement} reference to current node\n */\n HTMLElement.prototype.trimRight = function (pattern) {\n for (var i = 0; i < this.childNodes.length; i++) {\n var childNode = this.childNodes[i];\n if (childNode.nodeType === type_1.default.ELEMENT_NODE) {\n childNode.trimRight(pattern);\n }\n else {\n var index = childNode.rawText.search(pattern);\n if (index > -1) {\n childNode.rawText = childNode.rawText.substr(0, index);\n // trim all following nodes.\n this.childNodes.length = i + 1;\n }\n }\n }\n return this;\n };\n Object.defineProperty(HTMLElement.prototype, \"structure\", {\n /**\n * Get DOM structure\n * @return {string} strucutre\n */\n get: function () {\n var res = [];\n var indention = 0;\n function write(str) {\n res.push(' '.repeat(indention) + str);\n }\n function dfs(node) {\n var idStr = node.id ? ('#' + node.id) : '';\n var classStr = node.classNames.length ? ('.' + node.classNames.join('.')) : '';\n write(node.tagName + idStr + classStr);\n indention++;\n node.childNodes.forEach(function (childNode) {\n if (childNode.nodeType === type_1.default.ELEMENT_NODE) {\n dfs(childNode);\n }\n else if (childNode.nodeType === type_1.default.TEXT_NODE) {\n if (!childNode.isWhitespace)\n write('#text');\n }\n });\n indention--;\n }\n dfs(this);\n return res.join('\\n');\n },\n enumerable: true,\n configurable: true\n });\n /**\n * Remove whitespaces in this sub tree.\n * @return {HTMLElement} pointer to this\n */\n HTMLElement.prototype.removeWhitespace = function () {\n var _this = this;\n var o = 0;\n this.childNodes.forEach(function (node) {\n if (node.nodeType === type_1.default.TEXT_NODE) {\n if (node.isWhitespace) {\n return;\n }\n node.rawText = node.rawText.trim();\n }\n else if (node.nodeType === type_1.default.ELEMENT_NODE) {\n node.removeWhitespace();\n }\n _this.childNodes[o++] = node;\n });\n this.childNodes.length = o;\n return this;\n };\n /**\n * Query CSS selector to find matching nodes.\n * @param {string} selector Simplified CSS selector\n * @param {Matcher} selector A Matcher instance\n * @return {HTMLElement[]} matching elements\n */\n HTMLElement.prototype.querySelectorAll = function (selector) {\n var _this = this;\n var matcher;\n if (selector instanceof matcher_1.default) {\n matcher = selector;\n matcher.reset();\n }\n else {\n if (selector.includes(',')) {\n var selectors = selector.split(',');\n return Array.from(selectors.reduce(function (pre, cur) {\n var result = _this.querySelectorAll(cur.trim());\n return result.reduce(function (p, c) {\n return p.add(c);\n }, pre);\n }, new Set()));\n }\n matcher = new matcher_1.default(selector);\n }\n var stack = [];\n return this.childNodes.reduce(function (res, cur) {\n stack.push([cur, 0, false]);\n while (stack.length) {\n var state = back_1.default(stack); // get last element\n var el = state[0];\n if (state[1] === 0) {\n // Seen for first time.\n if (el.nodeType !== type_1.default.ELEMENT_NODE) {\n stack.pop();\n continue;\n }\n var html_el = el;\n state[2] = matcher.advance(html_el);\n if (state[2]) {\n if (matcher.matched) {\n res.push(html_el);\n res.push.apply(res, (html_el.querySelectorAll(selector)));\n // no need to go further.\n matcher.rewind();\n stack.pop();\n continue;\n }\n }\n }\n if (state[1] < el.childNodes.length) {\n stack.push([el.childNodes[state[1]++], 0, false]);\n }\n else {\n if (state[2]) {\n matcher.rewind();\n }\n stack.pop();\n }\n }\n return res;\n }, []);\n };\n /**\n * Query CSS Selector to find matching node.\n * @param {string} selector Simplified CSS selector\n * @param {Matcher} selector A Matcher instance\n * @return {HTMLElement} matching node\n */\n HTMLElement.prototype.querySelector = function (selector) {\n var matcher;\n if (selector instanceof matcher_1.default) {\n matcher = selector;\n matcher.reset();\n }\n else {\n matcher = new matcher_1.default(selector);\n }\n var stack = [];\n for (var _i = 0, _a = this.childNodes; _i < _a.length; _i++) {\n var node = _a[_i];\n stack.push([node, 0, false]);\n while (stack.length) {\n var state = back_1.default(stack);\n var el = state[0];\n if (state[1] === 0) {\n // Seen for first time.\n if (el.nodeType !== type_1.default.ELEMENT_NODE) {\n stack.pop();\n continue;\n }\n state[2] = matcher.advance(el);\n if (state[2]) {\n if (matcher.matched) {\n return el;\n }\n }\n }\n if (state[1] < el.childNodes.length) {\n stack.push([el.childNodes[state[1]++], 0, false]);\n }\n else {\n if (state[2])\n matcher.rewind();\n stack.pop();\n }\n }\n }\n return null;\n };\n /**\n * Append a child node to childNodes\n * @param {Node} node node to append\n * @return {Node} node appended\n */\n HTMLElement.prototype.appendChild = function (node) {\n // node.parentNode = this;\n this.childNodes.push(node);\n if (node instanceof HTMLElement) {\n node.parentNode = this;\n }\n return node;\n };\n Object.defineProperty(HTMLElement.prototype, \"firstChild\", {\n /**\n * Get first child node\n * @return {Node} first child node\n */\n get: function () {\n return this.childNodes[0];\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(HTMLElement.prototype, \"lastChild\", {\n /**\n * Get last child node\n * @return {Node} last child node\n */\n get: function () {\n return back_1.default(this.childNodes);\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(HTMLElement.prototype, \"attributes\", {\n /**\n * Get attributes\n * @return {Object} parsed and unescaped attributes\n */\n get: function () {\n if (this._attrs) {\n return this._attrs;\n }\n this._attrs = {};\n var attrs = this.rawAttributes;\n for (var key in attrs) {\n var val = attrs[key] || '';\n this._attrs[key] = he_1.decode(val);\n }\n return this._attrs;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(HTMLElement.prototype, \"rawAttributes\", {\n /**\n * Get escaped (as-it) attributes\n * @return {Object} parsed attributes\n */\n get: function () {\n if (this._rawAttrs)\n return this._rawAttrs;\n var attrs = {};\n if (this.rawAttrs) {\n var re = /\\b([a-z][a-z0-9\\-]*)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|(\\S+)))?/ig;\n var match = void 0;\n while (match = re.exec(this.rawAttrs)) {\n attrs[match[1]] = match[2] || match[3] || match[4] || null;\n }\n }\n this._rawAttrs = attrs;\n return attrs;\n },\n enumerable: true,\n configurable: true\n });\n HTMLElement.prototype.removeAttribute = function (key) {\n var attrs = this.rawAttributes;\n delete attrs[key];\n // Update this.attribute\n if (this._attrs) {\n delete this._attrs[key];\n }\n // Update rawString\n this.rawAttrs = Object.keys(attrs).map(function (name) {\n var val = JSON.stringify(attrs[name]);\n if (val === undefined || val === 'null') {\n return name;\n }\n else {\n return name + '=' + val;\n }\n }).join(' ');\n };\n HTMLElement.prototype.hasAttribute = function (key) {\n return key in this.attributes;\n };\n /**\n * Get an attribute\n * @return {string} value of the attribute\n */\n HTMLElement.prototype.getAttribute = function (key) {\n return this.attributes[key];\n };\n /**\n * Set an attribute value to the HTMLElement\n * @param {string} key The attribute name\n * @param {string} value The value to set, or null / undefined to remove an attribute\n */\n HTMLElement.prototype.setAttribute = function (key, value) {\n if (arguments.length < 2) {\n throw new Error('Failed to execute \\'setAttribute\\' on \\'Element\\'');\n }\n var attrs = this.rawAttributes;\n attrs[key] = String(value);\n if (this._attrs) {\n this._attrs[key] = he_1.decode(attrs[key]);\n }\n // Update rawString\n this.rawAttrs = Object.keys(attrs).map(function (name) {\n var val = JSON.stringify(attrs[name]);\n if (val === 'null' || val === '\"\"') {\n return name;\n }\n else {\n return name + '=' + val;\n }\n }).join(' ');\n };\n /**\n * Replace all the attributes of the HTMLElement by the provided attributes\n * @param {Attributes} attributes the new attribute set\n */\n HTMLElement.prototype.setAttributes = function (attributes) {\n // Invalidate current this.attributes\n if (this._attrs) {\n delete this._attrs;\n }\n // Invalidate current this.rawAttributes\n if (this._rawAttrs) {\n delete this._rawAttrs;\n }\n // Update rawString\n this.rawAttrs = Object.keys(attributes).map(function (name) {\n var val = attributes[name];\n if (val === 'null' || val === '\"\"') {\n return name;\n }\n else {\n return name + '=' + JSON.stringify(String(val));\n }\n }).join(' ');\n };\n HTMLElement.prototype.insertAdjacentHTML = function (where, html) {\n var _a, _b;\n var _this = this;\n if (arguments.length < 2) {\n throw new Error('2 arguments required');\n }\n var p = parse(html);\n if (where === 'afterend') {\n p.childNodes.forEach(function (n) {\n _this.parentNode.appendChild(n);\n });\n }\n else if (where === 'afterbegin') {\n (_a = this.childNodes).unshift.apply(_a, p.childNodes);\n }\n else if (where === 'beforeend') {\n p.childNodes.forEach(function (n) {\n _this.appendChild(n);\n });\n }\n else if (where === 'beforebegin') {\n (_b = this.parentNode.childNodes).unshift.apply(_b, p.childNodes);\n }\n else {\n throw new Error(\"The value provided ('\" + where + \"') is not one of 'beforebegin', 'afterbegin', 'beforeend', or 'afterend'\");\n }\n if (!where || html === undefined || html === null) {\n return;\n }\n };\n return HTMLElement;\n}(node_1.default));\nexports.default = HTMLElement;\n// https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name\nvar kMarkupPattern = /)-->|<(\\/?)([a-z][-.:0-9_a-z]*)\\s*([^>]*?)(\\/?)>/ig;\nvar kAttributePattern = /(^|\\s)(id|class)\\s*=\\s*(\"([^\"]+)\"|'([^']+)'|(\\S+))/ig;\nvar kSelfClosingElements = {\n area: true,\n base: true,\n br: true,\n col: true,\n hr: true,\n img: true,\n input: true,\n link: true,\n meta: true,\n source: true\n};\nvar kElementsClosedByOpening = {\n li: { li: true },\n p: { p: true, div: true },\n b: { div: true },\n td: { td: true, th: true },\n th: { td: true, th: true },\n h1: { h1: true },\n h2: { h2: true },\n h3: { h3: true },\n h4: { h4: true },\n h5: { h5: true },\n h6: { h6: true }\n};\nvar kElementsClosedByClosing = {\n li: { ul: true, ol: true },\n a: { div: true },\n b: { div: true },\n i: { div: true },\n p: { div: true },\n td: { tr: true, table: true },\n th: { tr: true, table: true }\n};\nvar kBlockTextElements = {\n script: true,\n noscript: true,\n style: true,\n pre: true\n};\nvar frameflag = 'documentfragmentcontainer';\nfunction parse(data, options) {\n if (options === void 0) { options = {}; }\n var root = new HTMLElement(null, {});\n var currentParent = root;\n var stack = [root];\n var lastTextPos = -1;\n var match;\n // https://github.com/taoqf/node-html-parser/issues/38\n data = \"<\" + frameflag + \">\" + data + \"\";\n var _loop_1 = function () {\n if (lastTextPos > -1) {\n if (lastTextPos + match[0].length < kMarkupPattern.lastIndex) {\n // if has content\n var text = data.substring(lastTextPos, kMarkupPattern.lastIndex - match[0].length);\n currentParent.appendChild(new text_1.default(text));\n }\n }\n lastTextPos = kMarkupPattern.lastIndex;\n if (match[2] === frameflag) {\n return \"continue\";\n }\n if (match[0][1] === '!') {\n // this is a comment\n if (options.comment) {\n // Only keep what is in between \n var text = data.substring(lastTextPos - 3, lastTextPos - match[0].length + 4);\n currentParent.appendChild(new comment_1.default(text));\n }\n return \"continue\";\n }\n if (options.lowerCaseTagName) {\n match[2] = match[2].toLowerCase();\n }\n if (!match[1]) {\n // not or ...\n var closeMarkup_1 = '';\n var index = (function () {\n if (options.lowerCaseTagName) {\n return data.toLocaleLowerCase().indexOf(closeMarkup_1, kMarkupPattern.lastIndex);\n }\n else {\n return data.indexOf(closeMarkup_1, kMarkupPattern.lastIndex);\n }\n })();\n if (options[match[2]]) {\n var text = void 0;\n if (index === -1) {\n // there is no matching ending for the text element.\n text = data.substr(kMarkupPattern.lastIndex);\n }\n else {\n text = data.substring(kMarkupPattern.lastIndex, index);\n }\n if (text.length > 0) {\n currentParent.appendChild(new text_1.default(text));\n }\n }\n if (index === -1) {\n lastTextPos = kMarkupPattern.lastIndex = data.length + 1;\n }\n else {\n lastTextPos = kMarkupPattern.lastIndex = index + closeMarkup_1.length;\n match[1] = 'true';\n }\n }\n }\n if (match[1] || match[4] || kSelfClosingElements[match[2]]) {\n // or
etc.\n while (true) {\n if (currentParent.tagName === match[2]) {\n stack.pop();\n currentParent = back_1.default(stack);\n break;\n }\n else {\n var tagName = currentParent.tagName;\n // Trying to close current tag, and move on\n if (kElementsClosedByClosing[tagName]) {\n if (kElementsClosedByClosing[tagName][match[2]]) {\n stack.pop();\n currentParent = back_1.default(stack);\n continue;\n }\n }\n // Use aggressive strategy to handle unmatching markups.\n break;\n }\n }\n }\n };\n while (match = kMarkupPattern.exec(data)) {\n _loop_1();\n }\n var valid = !!(stack.length === 1);\n if (!options.noFix) {\n var response = root;\n response.valid = valid;\n var _loop_2 = function () {\n // Handle each error elements.\n var last = stack.pop();\n var oneBefore = back_1.default(stack);\n if (last.parentNode && last.parentNode.parentNode) {\n if (last.parentNode === oneBefore && last.tagName === oneBefore.tagName) {\n // Pair error case

handle : Fixes to

\n oneBefore.removeChild(last);\n last.childNodes.forEach(function (child) {\n oneBefore.parentNode.appendChild(child);\n });\n stack.pop();\n }\n else {\n // Single error

handle: Just removes

\n oneBefore.removeChild(last);\n last.childNodes.forEach(function (child) {\n oneBefore.appendChild(child);\n });\n }\n }\n else {\n // If it's final element just skip.\n }\n };\n while (stack.length > 1) {\n _loop_2();\n }\n response.childNodes.forEach(function (node) {\n if (node instanceof HTMLElement) {\n node.parentNode = null;\n }\n });\n return response;\n }\n else {\n var response = new text_1.default(data);\n response.valid = valid;\n return response;\n }\n}\nexports.parse = parse;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n/**\n * Node Class as base class for TextNode and HTMLElement.\n */\nvar Node = /** @class */ (function () {\n function Node() {\n this.childNodes = [];\n }\n return Node;\n}());\nexports.default = Node;\n","\"use strict\";\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar type_1 = __importDefault(require(\"./type\"));\nvar node_1 = __importDefault(require(\"./node\"));\n/**\n * TextNode to contain a text element in DOM tree.\n * @param {string} value [description]\n */\nvar TextNode = /** @class */ (function (_super) {\n __extends(TextNode, _super);\n function TextNode(value) {\n var _this = _super.call(this) || this;\n /**\n * Node Type declaration.\n * @type {Number}\n */\n _this.nodeType = type_1.default.TEXT_NODE;\n _this.rawText = value;\n return _this;\n }\n Object.defineProperty(TextNode.prototype, \"text\", {\n /**\n * Get unescaped text value of current node and its children.\n * @return {string} text content\n */\n get: function () {\n return this.rawText;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(TextNode.prototype, \"isWhitespace\", {\n /**\n * Detect if the node contains only white space.\n * @return {bool}\n */\n get: function () {\n return /^(\\s| )*$/.test(this.rawText);\n },\n enumerable: true,\n configurable: true\n });\n TextNode.prototype.toString = function () {\n return this.text;\n };\n return TextNode;\n}(node_1.default));\nexports.default = TextNode;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar NodeType;\n(function (NodeType) {\n NodeType[NodeType[\"ELEMENT_NODE\"] = 1] = \"ELEMENT_NODE\";\n NodeType[NodeType[\"TEXT_NODE\"] = 3] = \"TEXT_NODE\";\n NodeType[NodeType[\"COMMENT_NODE\"] = 8] = \"COMMENT_NODE\";\n})(NodeType || (NodeType = {}));\nexports.default = NodeType;\n","/*! https://mths.be/he v1.1.1 by @mathias | MIT license */\n;(function(root) {\n\n\t// Detect free variables `exports`.\n\tvar freeExports = typeof exports == 'object' && exports;\n\n\t// Detect free variable `module`.\n\tvar freeModule = typeof module == 'object' && module &&\n\t\tmodule.exports == freeExports && module;\n\n\t// Detect free variable `global`, from Node.js or Browserified code,\n\t// and use it as `root`.\n\tvar freeGlobal = typeof global == 'object' && global;\n\tif (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {\n\t\troot = freeGlobal;\n\t}\n\n\t/*--------------------------------------------------------------------------*/\n\n\t// All astral symbols.\n\tvar regexAstralSymbols = /[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]/g;\n\t// All ASCII symbols (not just printable ASCII) except those listed in the\n\t// first column of the overrides table.\n\t// https://html.spec.whatwg.org/multipage/syntax.html#table-charref-overrides\n\tvar regexAsciiWhitelist = /[\\x01-\\x7F]/g;\n\t// All BMP symbols that are not ASCII newlines, printable ASCII symbols, or\n\t// code points listed in the first column of the overrides table on\n\t// https://html.spec.whatwg.org/multipage/syntax.html#table-charref-overrides.\n\tvar regexBmpWhitelist = /[\\x01-\\t\\x0B\\f\\x0E-\\x1F\\x7F\\x81\\x8D\\x8F\\x90\\x9D\\xA0-\\uFFFF]/g;\n\n\tvar regexEncodeNonAscii = /<\\u20D2|=\\u20E5|>\\u20D2|\\u205F\\u200A|\\u219D\\u0338|\\u2202\\u0338|\\u2220\\u20D2|\\u2229\\uFE00|\\u222A\\uFE00|\\u223C\\u20D2|\\u223D\\u0331|\\u223E\\u0333|\\u2242\\u0338|\\u224B\\u0338|\\u224D\\u20D2|\\u224E\\u0338|\\u224F\\u0338|\\u2250\\u0338|\\u2261\\u20E5|\\u2264\\u20D2|\\u2265\\u20D2|\\u2266\\u0338|\\u2267\\u0338|\\u2268\\uFE00|\\u2269\\uFE00|\\u226A\\u0338|\\u226A\\u20D2|\\u226B\\u0338|\\u226B\\u20D2|\\u227F\\u0338|\\u2282\\u20D2|\\u2283\\u20D2|\\u228A\\uFE00|\\u228B\\uFE00|\\u228F\\u0338|\\u2290\\u0338|\\u2293\\uFE00|\\u2294\\uFE00|\\u22B4\\u20D2|\\u22B5\\u20D2|\\u22D8\\u0338|\\u22D9\\u0338|\\u22DA\\uFE00|\\u22DB\\uFE00|\\u22F5\\u0338|\\u22F9\\u0338|\\u2933\\u0338|\\u29CF\\u0338|\\u29D0\\u0338|\\u2A6D\\u0338|\\u2A70\\u0338|\\u2A7D\\u0338|\\u2A7E\\u0338|\\u2AA1\\u0338|\\u2AA2\\u0338|\\u2AAC\\uFE00|\\u2AAD\\uFE00|\\u2AAF\\u0338|\\u2AB0\\u0338|\\u2AC5\\u0338|\\u2AC6\\u0338|\\u2ACB\\uFE00|\\u2ACC\\uFE00|\\u2AFD\\u20E5|[\\xA0-\\u0113\\u0116-\\u0122\\u0124-\\u012B\\u012E-\\u014D\\u0150-\\u017E\\u0192\\u01B5\\u01F5\\u0237\\u02C6\\u02C7\\u02D8-\\u02DD\\u0311\\u0391-\\u03A1\\u03A3-\\u03A9\\u03B1-\\u03C9\\u03D1\\u03D2\\u03D5\\u03D6\\u03DC\\u03DD\\u03F0\\u03F1\\u03F5\\u03F6\\u0401-\\u040C\\u040E-\\u044F\\u0451-\\u045C\\u045E\\u045F\\u2002-\\u2005\\u2007-\\u2010\\u2013-\\u2016\\u2018-\\u201A\\u201C-\\u201E\\u2020-\\u2022\\u2025\\u2026\\u2030-\\u2035\\u2039\\u203A\\u203E\\u2041\\u2043\\u2044\\u204F\\u2057\\u205F-\\u2063\\u20AC\\u20DB\\u20DC\\u2102\\u2105\\u210A-\\u2113\\u2115-\\u211E\\u2122\\u2124\\u2127-\\u2129\\u212C\\u212D\\u212F-\\u2131\\u2133-\\u2138\\u2145-\\u2148\\u2153-\\u215E\\u2190-\\u219B\\u219D-\\u21A7\\u21A9-\\u21AE\\u21B0-\\u21B3\\u21B5-\\u21B7\\u21BA-\\u21DB\\u21DD\\u21E4\\u21E5\\u21F5\\u21FD-\\u2205\\u2207-\\u2209\\u220B\\u220C\\u220F-\\u2214\\u2216-\\u2218\\u221A\\u221D-\\u2238\\u223A-\\u2257\\u2259\\u225A\\u225C\\u225F-\\u2262\\u2264-\\u228B\\u228D-\\u229B\\u229D-\\u22A5\\u22A7-\\u22B0\\u22B2-\\u22BB\\u22BD-\\u22DB\\u22DE-\\u22E3\\u22E6-\\u22F7\\u22F9-\\u22FE\\u2305\\u2306\\u2308-\\u2310\\u2312\\u2313\\u2315\\u2316\\u231C-\\u231F\\u2322\\u2323\\u232D\\u232E\\u2336\\u233D\\u233F\\u237C\\u23B0\\u23B1\\u23B4-\\u23B6\\u23DC-\\u23DF\\u23E2\\u23E7\\u2423\\u24C8\\u2500\\u2502\\u250C\\u2510\\u2514\\u2518\\u251C\\u2524\\u252C\\u2534\\u253C\\u2550-\\u256C\\u2580\\u2584\\u2588\\u2591-\\u2593\\u25A1\\u25AA\\u25AB\\u25AD\\u25AE\\u25B1\\u25B3-\\u25B5\\u25B8\\u25B9\\u25BD-\\u25BF\\u25C2\\u25C3\\u25CA\\u25CB\\u25EC\\u25EF\\u25F8-\\u25FC\\u2605\\u2606\\u260E\\u2640\\u2642\\u2660\\u2663\\u2665\\u2666\\u266A\\u266D-\\u266F\\u2713\\u2717\\u2720\\u2736\\u2758\\u2772\\u2773\\u27C8\\u27C9\\u27E6-\\u27ED\\u27F5-\\u27FA\\u27FC\\u27FF\\u2902-\\u2905\\u290C-\\u2913\\u2916\\u2919-\\u2920\\u2923-\\u292A\\u2933\\u2935-\\u2939\\u293C\\u293D\\u2945\\u2948-\\u294B\\u294E-\\u2976\\u2978\\u2979\\u297B-\\u297F\\u2985\\u2986\\u298B-\\u2996\\u299A\\u299C\\u299D\\u29A4-\\u29B7\\u29B9\\u29BB\\u29BC\\u29BE-\\u29C5\\u29C9\\u29CD-\\u29D0\\u29DC-\\u29DE\\u29E3-\\u29E5\\u29EB\\u29F4\\u29F6\\u2A00-\\u2A02\\u2A04\\u2A06\\u2A0C\\u2A0D\\u2A10-\\u2A17\\u2A22-\\u2A27\\u2A29\\u2A2A\\u2A2D-\\u2A31\\u2A33-\\u2A3C\\u2A3F\\u2A40\\u2A42-\\u2A4D\\u2A50\\u2A53-\\u2A58\\u2A5A-\\u2A5D\\u2A5F\\u2A66\\u2A6A\\u2A6D-\\u2A75\\u2A77-\\u2A9A\\u2A9D-\\u2AA2\\u2AA4-\\u2AB0\\u2AB3-\\u2AC8\\u2ACB\\u2ACC\\u2ACF-\\u2ADB\\u2AE4\\u2AE6-\\u2AE9\\u2AEB-\\u2AF3\\u2AFD\\uFB00-\\uFB04]|\\uD835[\\uDC9C\\uDC9E\\uDC9F\\uDCA2\\uDCA5\\uDCA6\\uDCA9-\\uDCAC\\uDCAE-\\uDCB9\\uDCBB\\uDCBD-\\uDCC3\\uDCC5-\\uDCCF\\uDD04\\uDD05\\uDD07-\\uDD0A\\uDD0D-\\uDD14\\uDD16-\\uDD1C\\uDD1E-\\uDD39\\uDD3B-\\uDD3E\\uDD40-\\uDD44\\uDD46\\uDD4A-\\uDD50\\uDD52-\\uDD6B]/g;\n\tvar encodeMap = {'\\xAD':'shy','\\u200C':'zwnj','\\u200D':'zwj','\\u200E':'lrm','\\u2063':'ic','\\u2062':'it','\\u2061':'af','\\u200F':'rlm','\\u200B':'ZeroWidthSpace','\\u2060':'NoBreak','\\u0311':'DownBreve','\\u20DB':'tdot','\\u20DC':'DotDot','\\t':'Tab','\\n':'NewLine','\\u2008':'puncsp','\\u205F':'MediumSpace','\\u2009':'thinsp','\\u200A':'hairsp','\\u2004':'emsp13','\\u2002':'ensp','\\u2005':'emsp14','\\u2003':'emsp','\\u2007':'numsp','\\xA0':'nbsp','\\u205F\\u200A':'ThickSpace','\\u203E':'oline','_':'lowbar','\\u2010':'dash','\\u2013':'ndash','\\u2014':'mdash','\\u2015':'horbar',',':'comma',';':'semi','\\u204F':'bsemi',':':'colon','\\u2A74':'Colone','!':'excl','\\xA1':'iexcl','?':'quest','\\xBF':'iquest','.':'period','\\u2025':'nldr','\\u2026':'mldr','\\xB7':'middot','\\'':'apos','\\u2018':'lsquo','\\u2019':'rsquo','\\u201A':'sbquo','\\u2039':'lsaquo','\\u203A':'rsaquo','\"':'quot','\\u201C':'ldquo','\\u201D':'rdquo','\\u201E':'bdquo','\\xAB':'laquo','\\xBB':'raquo','(':'lpar',')':'rpar','[':'lsqb',']':'rsqb','{':'lcub','}':'rcub','\\u2308':'lceil','\\u2309':'rceil','\\u230A':'lfloor','\\u230B':'rfloor','\\u2985':'lopar','\\u2986':'ropar','\\u298B':'lbrke','\\u298C':'rbrke','\\u298D':'lbrkslu','\\u298E':'rbrksld','\\u298F':'lbrksld','\\u2990':'rbrkslu','\\u2991':'langd','\\u2992':'rangd','\\u2993':'lparlt','\\u2994':'rpargt','\\u2995':'gtlPar','\\u2996':'ltrPar','\\u27E6':'lobrk','\\u27E7':'robrk','\\u27E8':'lang','\\u27E9':'rang','\\u27EA':'Lang','\\u27EB':'Rang','\\u27EC':'loang','\\u27ED':'roang','\\u2772':'lbbrk','\\u2773':'rbbrk','\\u2016':'Vert','\\xA7':'sect','\\xB6':'para','@':'commat','*':'ast','/':'sol','undefined':null,'&':'amp','#':'num','%':'percnt','\\u2030':'permil','\\u2031':'pertenk','\\u2020':'dagger','\\u2021':'Dagger','\\u2022':'bull','\\u2043':'hybull','\\u2032':'prime','\\u2033':'Prime','\\u2034':'tprime','\\u2057':'qprime','\\u2035':'bprime','\\u2041':'caret','`':'grave','\\xB4':'acute','\\u02DC':'tilde','^':'Hat','\\xAF':'macr','\\u02D8':'breve','\\u02D9':'dot','\\xA8':'die','\\u02DA':'ring','\\u02DD':'dblac','\\xB8':'cedil','\\u02DB':'ogon','\\u02C6':'circ','\\u02C7':'caron','\\xB0':'deg','\\xA9':'copy','\\xAE':'reg','\\u2117':'copysr','\\u2118':'wp','\\u211E':'rx','\\u2127':'mho','\\u2129':'iiota','\\u2190':'larr','\\u219A':'nlarr','\\u2192':'rarr','\\u219B':'nrarr','\\u2191':'uarr','\\u2193':'darr','\\u2194':'harr','\\u21AE':'nharr','\\u2195':'varr','\\u2196':'nwarr','\\u2197':'nearr','\\u2198':'searr','\\u2199':'swarr','\\u219D':'rarrw','\\u219D\\u0338':'nrarrw','\\u219E':'Larr','\\u219F':'Uarr','\\u21A0':'Rarr','\\u21A1':'Darr','\\u21A2':'larrtl','\\u21A3':'rarrtl','\\u21A4':'mapstoleft','\\u21A5':'mapstoup','\\u21A6':'map','\\u21A7':'mapstodown','\\u21A9':'larrhk','\\u21AA':'rarrhk','\\u21AB':'larrlp','\\u21AC':'rarrlp','\\u21AD':'harrw','\\u21B0':'lsh','\\u21B1':'rsh','\\u21B2':'ldsh','\\u21B3':'rdsh','\\u21B5':'crarr','\\u21B6':'cularr','\\u21B7':'curarr','\\u21BA':'olarr','\\u21BB':'orarr','\\u21BC':'lharu','\\u21BD':'lhard','\\u21BE':'uharr','\\u21BF':'uharl','\\u21C0':'rharu','\\u21C1':'rhard','\\u21C2':'dharr','\\u21C3':'dharl','\\u21C4':'rlarr','\\u21C5':'udarr','\\u21C6':'lrarr','\\u21C7':'llarr','\\u21C8':'uuarr','\\u21C9':'rrarr','\\u21CA':'ddarr','\\u21CB':'lrhar','\\u21CC':'rlhar','\\u21D0':'lArr','\\u21CD':'nlArr','\\u21D1':'uArr','\\u21D2':'rArr','\\u21CF':'nrArr','\\u21D3':'dArr','\\u21D4':'iff','\\u21CE':'nhArr','\\u21D5':'vArr','\\u21D6':'nwArr','\\u21D7':'neArr','\\u21D8':'seArr','\\u21D9':'swArr','\\u21DA':'lAarr','\\u21DB':'rAarr','\\u21DD':'zigrarr','\\u21E4':'larrb','\\u21E5':'rarrb','\\u21F5':'duarr','\\u21FD':'loarr','\\u21FE':'roarr','\\u21FF':'hoarr','\\u2200':'forall','\\u2201':'comp','\\u2202':'part','\\u2202\\u0338':'npart','\\u2203':'exist','\\u2204':'nexist','\\u2205':'empty','\\u2207':'Del','\\u2208':'in','\\u2209':'notin','\\u220B':'ni','\\u220C':'notni','\\u03F6':'bepsi','\\u220F':'prod','\\u2210':'coprod','\\u2211':'sum','+':'plus','\\xB1':'pm','\\xF7':'div','\\xD7':'times','<':'lt','\\u226E':'nlt','<\\u20D2':'nvlt','=':'equals','\\u2260':'ne','=\\u20E5':'bne','\\u2A75':'Equal','>':'gt','\\u226F':'ngt','>\\u20D2':'nvgt','\\xAC':'not','|':'vert','\\xA6':'brvbar','\\u2212':'minus','\\u2213':'mp','\\u2214':'plusdo','\\u2044':'frasl','\\u2216':'setmn','\\u2217':'lowast','\\u2218':'compfn','\\u221A':'Sqrt','\\u221D':'prop','\\u221E':'infin','\\u221F':'angrt','\\u2220':'ang','\\u2220\\u20D2':'nang','\\u2221':'angmsd','\\u2222':'angsph','\\u2223':'mid','\\u2224':'nmid','\\u2225':'par','\\u2226':'npar','\\u2227':'and','\\u2228':'or','\\u2229':'cap','\\u2229\\uFE00':'caps','\\u222A':'cup','\\u222A\\uFE00':'cups','\\u222B':'int','\\u222C':'Int','\\u222D':'tint','\\u2A0C':'qint','\\u222E':'oint','\\u222F':'Conint','\\u2230':'Cconint','\\u2231':'cwint','\\u2232':'cwconint','\\u2233':'awconint','\\u2234':'there4','\\u2235':'becaus','\\u2236':'ratio','\\u2237':'Colon','\\u2238':'minusd','\\u223A':'mDDot','\\u223B':'homtht','\\u223C':'sim','\\u2241':'nsim','\\u223C\\u20D2':'nvsim','\\u223D':'bsim','\\u223D\\u0331':'race','\\u223E':'ac','\\u223E\\u0333':'acE','\\u223F':'acd','\\u2240':'wr','\\u2242':'esim','\\u2242\\u0338':'nesim','\\u2243':'sime','\\u2244':'nsime','\\u2245':'cong','\\u2247':'ncong','\\u2246':'simne','\\u2248':'ap','\\u2249':'nap','\\u224A':'ape','\\u224B':'apid','\\u224B\\u0338':'napid','\\u224C':'bcong','\\u224D':'CupCap','\\u226D':'NotCupCap','\\u224D\\u20D2':'nvap','\\u224E':'bump','\\u224E\\u0338':'nbump','\\u224F':'bumpe','\\u224F\\u0338':'nbumpe','\\u2250':'doteq','\\u2250\\u0338':'nedot','\\u2251':'eDot','\\u2252':'efDot','\\u2253':'erDot','\\u2254':'colone','\\u2255':'ecolon','\\u2256':'ecir','\\u2257':'cire','\\u2259':'wedgeq','\\u225A':'veeeq','\\u225C':'trie','\\u225F':'equest','\\u2261':'equiv','\\u2262':'nequiv','\\u2261\\u20E5':'bnequiv','\\u2264':'le','\\u2270':'nle','\\u2264\\u20D2':'nvle','\\u2265':'ge','\\u2271':'nge','\\u2265\\u20D2':'nvge','\\u2266':'lE','\\u2266\\u0338':'nlE','\\u2267':'gE','\\u2267\\u0338':'ngE','\\u2268\\uFE00':'lvnE','\\u2268':'lnE','\\u2269':'gnE','\\u2269\\uFE00':'gvnE','\\u226A':'ll','\\u226A\\u0338':'nLtv','\\u226A\\u20D2':'nLt','\\u226B':'gg','\\u226B\\u0338':'nGtv','\\u226B\\u20D2':'nGt','\\u226C':'twixt','\\u2272':'lsim','\\u2274':'nlsim','\\u2273':'gsim','\\u2275':'ngsim','\\u2276':'lg','\\u2278':'ntlg','\\u2277':'gl','\\u2279':'ntgl','\\u227A':'pr','\\u2280':'npr','\\u227B':'sc','\\u2281':'nsc','\\u227C':'prcue','\\u22E0':'nprcue','\\u227D':'sccue','\\u22E1':'nsccue','\\u227E':'prsim','\\u227F':'scsim','\\u227F\\u0338':'NotSucceedsTilde','\\u2282':'sub','\\u2284':'nsub','\\u2282\\u20D2':'vnsub','\\u2283':'sup','\\u2285':'nsup','\\u2283\\u20D2':'vnsup','\\u2286':'sube','\\u2288':'nsube','\\u2287':'supe','\\u2289':'nsupe','\\u228A\\uFE00':'vsubne','\\u228A':'subne','\\u228B\\uFE00':'vsupne','\\u228B':'supne','\\u228D':'cupdot','\\u228E':'uplus','\\u228F':'sqsub','\\u228F\\u0338':'NotSquareSubset','\\u2290':'sqsup','\\u2290\\u0338':'NotSquareSuperset','\\u2291':'sqsube','\\u22E2':'nsqsube','\\u2292':'sqsupe','\\u22E3':'nsqsupe','\\u2293':'sqcap','\\u2293\\uFE00':'sqcaps','\\u2294':'sqcup','\\u2294\\uFE00':'sqcups','\\u2295':'oplus','\\u2296':'ominus','\\u2297':'otimes','\\u2298':'osol','\\u2299':'odot','\\u229A':'ocir','\\u229B':'oast','\\u229D':'odash','\\u229E':'plusb','\\u229F':'minusb','\\u22A0':'timesb','\\u22A1':'sdotb','\\u22A2':'vdash','\\u22AC':'nvdash','\\u22A3':'dashv','\\u22A4':'top','\\u22A5':'bot','\\u22A7':'models','\\u22A8':'vDash','\\u22AD':'nvDash','\\u22A9':'Vdash','\\u22AE':'nVdash','\\u22AA':'Vvdash','\\u22AB':'VDash','\\u22AF':'nVDash','\\u22B0':'prurel','\\u22B2':'vltri','\\u22EA':'nltri','\\u22B3':'vrtri','\\u22EB':'nrtri','\\u22B4':'ltrie','\\u22EC':'nltrie','\\u22B4\\u20D2':'nvltrie','\\u22B5':'rtrie','\\u22ED':'nrtrie','\\u22B5\\u20D2':'nvrtrie','\\u22B6':'origof','\\u22B7':'imof','\\u22B8':'mumap','\\u22B9':'hercon','\\u22BA':'intcal','\\u22BB':'veebar','\\u22BD':'barvee','\\u22BE':'angrtvb','\\u22BF':'lrtri','\\u22C0':'Wedge','\\u22C1':'Vee','\\u22C2':'xcap','\\u22C3':'xcup','\\u22C4':'diam','\\u22C5':'sdot','\\u22C6':'Star','\\u22C7':'divonx','\\u22C8':'bowtie','\\u22C9':'ltimes','\\u22CA':'rtimes','\\u22CB':'lthree','\\u22CC':'rthree','\\u22CD':'bsime','\\u22CE':'cuvee','\\u22CF':'cuwed','\\u22D0':'Sub','\\u22D1':'Sup','\\u22D2':'Cap','\\u22D3':'Cup','\\u22D4':'fork','\\u22D5':'epar','\\u22D6':'ltdot','\\u22D7':'gtdot','\\u22D8':'Ll','\\u22D8\\u0338':'nLl','\\u22D9':'Gg','\\u22D9\\u0338':'nGg','\\u22DA\\uFE00':'lesg','\\u22DA':'leg','\\u22DB':'gel','\\u22DB\\uFE00':'gesl','\\u22DE':'cuepr','\\u22DF':'cuesc','\\u22E6':'lnsim','\\u22E7':'gnsim','\\u22E8':'prnsim','\\u22E9':'scnsim','\\u22EE':'vellip','\\u22EF':'ctdot','\\u22F0':'utdot','\\u22F1':'dtdot','\\u22F2':'disin','\\u22F3':'isinsv','\\u22F4':'isins','\\u22F5':'isindot','\\u22F5\\u0338':'notindot','\\u22F6':'notinvc','\\u22F7':'notinvb','\\u22F9':'isinE','\\u22F9\\u0338':'notinE','\\u22FA':'nisd','\\u22FB':'xnis','\\u22FC':'nis','\\u22FD':'notnivc','\\u22FE':'notnivb','\\u2305':'barwed','\\u2306':'Barwed','\\u230C':'drcrop','\\u230D':'dlcrop','\\u230E':'urcrop','\\u230F':'ulcrop','\\u2310':'bnot','\\u2312':'profline','\\u2313':'profsurf','\\u2315':'telrec','\\u2316':'target','\\u231C':'ulcorn','\\u231D':'urcorn','\\u231E':'dlcorn','\\u231F':'drcorn','\\u2322':'frown','\\u2323':'smile','\\u232D':'cylcty','\\u232E':'profalar','\\u2336':'topbot','\\u233D':'ovbar','\\u233F':'solbar','\\u237C':'angzarr','\\u23B0':'lmoust','\\u23B1':'rmoust','\\u23B4':'tbrk','\\u23B5':'bbrk','\\u23B6':'bbrktbrk','\\u23DC':'OverParenthesis','\\u23DD':'UnderParenthesis','\\u23DE':'OverBrace','\\u23DF':'UnderBrace','\\u23E2':'trpezium','\\u23E7':'elinters','\\u2423':'blank','\\u2500':'boxh','\\u2502':'boxv','\\u250C':'boxdr','\\u2510':'boxdl','\\u2514':'boxur','\\u2518':'boxul','\\u251C':'boxvr','\\u2524':'boxvl','\\u252C':'boxhd','\\u2534':'boxhu','\\u253C':'boxvh','\\u2550':'boxH','\\u2551':'boxV','\\u2552':'boxdR','\\u2553':'boxDr','\\u2554':'boxDR','\\u2555':'boxdL','\\u2556':'boxDl','\\u2557':'boxDL','\\u2558':'boxuR','\\u2559':'boxUr','\\u255A':'boxUR','\\u255B':'boxuL','\\u255C':'boxUl','\\u255D':'boxUL','\\u255E':'boxvR','\\u255F':'boxVr','\\u2560':'boxVR','\\u2561':'boxvL','\\u2562':'boxVl','\\u2563':'boxVL','\\u2564':'boxHd','\\u2565':'boxhD','\\u2566':'boxHD','\\u2567':'boxHu','\\u2568':'boxhU','\\u2569':'boxHU','\\u256A':'boxvH','\\u256B':'boxVh','\\u256C':'boxVH','\\u2580':'uhblk','\\u2584':'lhblk','\\u2588':'block','\\u2591':'blk14','\\u2592':'blk12','\\u2593':'blk34','\\u25A1':'squ','\\u25AA':'squf','\\u25AB':'EmptyVerySmallSquare','\\u25AD':'rect','\\u25AE':'marker','\\u25B1':'fltns','\\u25B3':'xutri','\\u25B4':'utrif','\\u25B5':'utri','\\u25B8':'rtrif','\\u25B9':'rtri','\\u25BD':'xdtri','\\u25BE':'dtrif','\\u25BF':'dtri','\\u25C2':'ltrif','\\u25C3':'ltri','\\u25CA':'loz','\\u25CB':'cir','\\u25EC':'tridot','\\u25EF':'xcirc','\\u25F8':'ultri','\\u25F9':'urtri','\\u25FA':'lltri','\\u25FB':'EmptySmallSquare','\\u25FC':'FilledSmallSquare','\\u2605':'starf','\\u2606':'star','\\u260E':'phone','\\u2640':'female','\\u2642':'male','\\u2660':'spades','\\u2663':'clubs','\\u2665':'hearts','\\u2666':'diams','\\u266A':'sung','\\u2713':'check','\\u2717':'cross','\\u2720':'malt','\\u2736':'sext','\\u2758':'VerticalSeparator','\\u27C8':'bsolhsub','\\u27C9':'suphsol','\\u27F5':'xlarr','\\u27F6':'xrarr','\\u27F7':'xharr','\\u27F8':'xlArr','\\u27F9':'xrArr','\\u27FA':'xhArr','\\u27FC':'xmap','\\u27FF':'dzigrarr','\\u2902':'nvlArr','\\u2903':'nvrArr','\\u2904':'nvHarr','\\u2905':'Map','\\u290C':'lbarr','\\u290D':'rbarr','\\u290E':'lBarr','\\u290F':'rBarr','\\u2910':'RBarr','\\u2911':'DDotrahd','\\u2912':'UpArrowBar','\\u2913':'DownArrowBar','\\u2916':'Rarrtl','\\u2919':'latail','\\u291A':'ratail','\\u291B':'lAtail','\\u291C':'rAtail','\\u291D':'larrfs','\\u291E':'rarrfs','\\u291F':'larrbfs','\\u2920':'rarrbfs','\\u2923':'nwarhk','\\u2924':'nearhk','\\u2925':'searhk','\\u2926':'swarhk','\\u2927':'nwnear','\\u2928':'toea','\\u2929':'tosa','\\u292A':'swnwar','\\u2933':'rarrc','\\u2933\\u0338':'nrarrc','\\u2935':'cudarrr','\\u2936':'ldca','\\u2937':'rdca','\\u2938':'cudarrl','\\u2939':'larrpl','\\u293C':'curarrm','\\u293D':'cularrp','\\u2945':'rarrpl','\\u2948':'harrcir','\\u2949':'Uarrocir','\\u294A':'lurdshar','\\u294B':'ldrushar','\\u294E':'LeftRightVector','\\u294F':'RightUpDownVector','\\u2950':'DownLeftRightVector','\\u2951':'LeftUpDownVector','\\u2952':'LeftVectorBar','\\u2953':'RightVectorBar','\\u2954':'RightUpVectorBar','\\u2955':'RightDownVectorBar','\\u2956':'DownLeftVectorBar','\\u2957':'DownRightVectorBar','\\u2958':'LeftUpVectorBar','\\u2959':'LeftDownVectorBar','\\u295A':'LeftTeeVector','\\u295B':'RightTeeVector','\\u295C':'RightUpTeeVector','\\u295D':'RightDownTeeVector','\\u295E':'DownLeftTeeVector','\\u295F':'DownRightTeeVector','\\u2960':'LeftUpTeeVector','\\u2961':'LeftDownTeeVector','\\u2962':'lHar','\\u2963':'uHar','\\u2964':'rHar','\\u2965':'dHar','\\u2966':'luruhar','\\u2967':'ldrdhar','\\u2968':'ruluhar','\\u2969':'rdldhar','\\u296A':'lharul','\\u296B':'llhard','\\u296C':'rharul','\\u296D':'lrhard','\\u296E':'udhar','\\u296F':'duhar','\\u2970':'RoundImplies','\\u2971':'erarr','\\u2972':'simrarr','\\u2973':'larrsim','\\u2974':'rarrsim','\\u2975':'rarrap','\\u2976':'ltlarr','\\u2978':'gtrarr','\\u2979':'subrarr','\\u297B':'suplarr','\\u297C':'lfisht','\\u297D':'rfisht','\\u297E':'ufisht','\\u297F':'dfisht','\\u299A':'vzigzag','\\u299C':'vangrt','\\u299D':'angrtvbd','\\u29A4':'ange','\\u29A5':'range','\\u29A6':'dwangle','\\u29A7':'uwangle','\\u29A8':'angmsdaa','\\u29A9':'angmsdab','\\u29AA':'angmsdac','\\u29AB':'angmsdad','\\u29AC':'angmsdae','\\u29AD':'angmsdaf','\\u29AE':'angmsdag','\\u29AF':'angmsdah','\\u29B0':'bemptyv','\\u29B1':'demptyv','\\u29B2':'cemptyv','\\u29B3':'raemptyv','\\u29B4':'laemptyv','\\u29B5':'ohbar','\\u29B6':'omid','\\u29B7':'opar','\\u29B9':'operp','\\u29BB':'olcross','\\u29BC':'odsold','\\u29BE':'olcir','\\u29BF':'ofcir','\\u29C0':'olt','\\u29C1':'ogt','\\u29C2':'cirscir','\\u29C3':'cirE','\\u29C4':'solb','\\u29C5':'bsolb','\\u29C9':'boxbox','\\u29CD':'trisb','\\u29CE':'rtriltri','\\u29CF':'LeftTriangleBar','\\u29CF\\u0338':'NotLeftTriangleBar','\\u29D0':'RightTriangleBar','\\u29D0\\u0338':'NotRightTriangleBar','\\u29DC':'iinfin','\\u29DD':'infintie','\\u29DE':'nvinfin','\\u29E3':'eparsl','\\u29E4':'smeparsl','\\u29E5':'eqvparsl','\\u29EB':'lozf','\\u29F4':'RuleDelayed','\\u29F6':'dsol','\\u2A00':'xodot','\\u2A01':'xoplus','\\u2A02':'xotime','\\u2A04':'xuplus','\\u2A06':'xsqcup','\\u2A0D':'fpartint','\\u2A10':'cirfnint','\\u2A11':'awint','\\u2A12':'rppolint','\\u2A13':'scpolint','\\u2A14':'npolint','\\u2A15':'pointint','\\u2A16':'quatint','\\u2A17':'intlarhk','\\u2A22':'pluscir','\\u2A23':'plusacir','\\u2A24':'simplus','\\u2A25':'plusdu','\\u2A26':'plussim','\\u2A27':'plustwo','\\u2A29':'mcomma','\\u2A2A':'minusdu','\\u2A2D':'loplus','\\u2A2E':'roplus','\\u2A2F':'Cross','\\u2A30':'timesd','\\u2A31':'timesbar','\\u2A33':'smashp','\\u2A34':'lotimes','\\u2A35':'rotimes','\\u2A36':'otimesas','\\u2A37':'Otimes','\\u2A38':'odiv','\\u2A39':'triplus','\\u2A3A':'triminus','\\u2A3B':'tritime','\\u2A3C':'iprod','\\u2A3F':'amalg','\\u2A40':'capdot','\\u2A42':'ncup','\\u2A43':'ncap','\\u2A44':'capand','\\u2A45':'cupor','\\u2A46':'cupcap','\\u2A47':'capcup','\\u2A48':'cupbrcap','\\u2A49':'capbrcup','\\u2A4A':'cupcup','\\u2A4B':'capcap','\\u2A4C':'ccups','\\u2A4D':'ccaps','\\u2A50':'ccupssm','\\u2A53':'And','\\u2A54':'Or','\\u2A55':'andand','\\u2A56':'oror','\\u2A57':'orslope','\\u2A58':'andslope','\\u2A5A':'andv','\\u2A5B':'orv','\\u2A5C':'andd','\\u2A5D':'ord','\\u2A5F':'wedbar','\\u2A66':'sdote','\\u2A6A':'simdot','\\u2A6D':'congdot','\\u2A6D\\u0338':'ncongdot','\\u2A6E':'easter','\\u2A6F':'apacir','\\u2A70':'apE','\\u2A70\\u0338':'napE','\\u2A71':'eplus','\\u2A72':'pluse','\\u2A73':'Esim','\\u2A77':'eDDot','\\u2A78':'equivDD','\\u2A79':'ltcir','\\u2A7A':'gtcir','\\u2A7B':'ltquest','\\u2A7C':'gtquest','\\u2A7D':'les','\\u2A7D\\u0338':'nles','\\u2A7E':'ges','\\u2A7E\\u0338':'nges','\\u2A7F':'lesdot','\\u2A80':'gesdot','\\u2A81':'lesdoto','\\u2A82':'gesdoto','\\u2A83':'lesdotor','\\u2A84':'gesdotol','\\u2A85':'lap','\\u2A86':'gap','\\u2A87':'lne','\\u2A88':'gne','\\u2A89':'lnap','\\u2A8A':'gnap','\\u2A8B':'lEg','\\u2A8C':'gEl','\\u2A8D':'lsime','\\u2A8E':'gsime','\\u2A8F':'lsimg','\\u2A90':'gsiml','\\u2A91':'lgE','\\u2A92':'glE','\\u2A93':'lesges','\\u2A94':'gesles','\\u2A95':'els','\\u2A96':'egs','\\u2A97':'elsdot','\\u2A98':'egsdot','\\u2A99':'el','\\u2A9A':'eg','\\u2A9D':'siml','\\u2A9E':'simg','\\u2A9F':'simlE','\\u2AA0':'simgE','\\u2AA1':'LessLess','\\u2AA1\\u0338':'NotNestedLessLess','\\u2AA2':'GreaterGreater','\\u2AA2\\u0338':'NotNestedGreaterGreater','\\u2AA4':'glj','\\u2AA5':'gla','\\u2AA6':'ltcc','\\u2AA7':'gtcc','\\u2AA8':'lescc','\\u2AA9':'gescc','\\u2AAA':'smt','\\u2AAB':'lat','\\u2AAC':'smte','\\u2AAC\\uFE00':'smtes','\\u2AAD':'late','\\u2AAD\\uFE00':'lates','\\u2AAE':'bumpE','\\u2AAF':'pre','\\u2AAF\\u0338':'npre','\\u2AB0':'sce','\\u2AB0\\u0338':'nsce','\\u2AB3':'prE','\\u2AB4':'scE','\\u2AB5':'prnE','\\u2AB6':'scnE','\\u2AB7':'prap','\\u2AB8':'scap','\\u2AB9':'prnap','\\u2ABA':'scnap','\\u2ABB':'Pr','\\u2ABC':'Sc','\\u2ABD':'subdot','\\u2ABE':'supdot','\\u2ABF':'subplus','\\u2AC0':'supplus','\\u2AC1':'submult','\\u2AC2':'supmult','\\u2AC3':'subedot','\\u2AC4':'supedot','\\u2AC5':'subE','\\u2AC5\\u0338':'nsubE','\\u2AC6':'supE','\\u2AC6\\u0338':'nsupE','\\u2AC7':'subsim','\\u2AC8':'supsim','\\u2ACB\\uFE00':'vsubnE','\\u2ACB':'subnE','\\u2ACC\\uFE00':'vsupnE','\\u2ACC':'supnE','\\u2ACF':'csub','\\u2AD0':'csup','\\u2AD1':'csube','\\u2AD2':'csupe','\\u2AD3':'subsup','\\u2AD4':'supsub','\\u2AD5':'subsub','\\u2AD6':'supsup','\\u2AD7':'suphsub','\\u2AD8':'supdsub','\\u2AD9':'forkv','\\u2ADA':'topfork','\\u2ADB':'mlcp','\\u2AE4':'Dashv','\\u2AE6':'Vdashl','\\u2AE7':'Barv','\\u2AE8':'vBar','\\u2AE9':'vBarv','\\u2AEB':'Vbar','\\u2AEC':'Not','\\u2AED':'bNot','\\u2AEE':'rnmid','\\u2AEF':'cirmid','\\u2AF0':'midcir','\\u2AF1':'topcir','\\u2AF2':'nhpar','\\u2AF3':'parsim','\\u2AFD':'parsl','\\u2AFD\\u20E5':'nparsl','\\u266D':'flat','\\u266E':'natur','\\u266F':'sharp','\\xA4':'curren','\\xA2':'cent','$':'dollar','\\xA3':'pound','\\xA5':'yen','\\u20AC':'euro','\\xB9':'sup1','\\xBD':'half','\\u2153':'frac13','\\xBC':'frac14','\\u2155':'frac15','\\u2159':'frac16','\\u215B':'frac18','\\xB2':'sup2','\\u2154':'frac23','\\u2156':'frac25','\\xB3':'sup3','\\xBE':'frac34','\\u2157':'frac35','\\u215C':'frac38','\\u2158':'frac45','\\u215A':'frac56','\\u215D':'frac58','\\u215E':'frac78','\\uD835\\uDCB6':'ascr','\\uD835\\uDD52':'aopf','\\uD835\\uDD1E':'afr','\\uD835\\uDD38':'Aopf','\\uD835\\uDD04':'Afr','\\uD835\\uDC9C':'Ascr','\\xAA':'ordf','\\xE1':'aacute','\\xC1':'Aacute','\\xE0':'agrave','\\xC0':'Agrave','\\u0103':'abreve','\\u0102':'Abreve','\\xE2':'acirc','\\xC2':'Acirc','\\xE5':'aring','\\xC5':'angst','\\xE4':'auml','\\xC4':'Auml','\\xE3':'atilde','\\xC3':'Atilde','\\u0105':'aogon','\\u0104':'Aogon','\\u0101':'amacr','\\u0100':'Amacr','\\xE6':'aelig','\\xC6':'AElig','\\uD835\\uDCB7':'bscr','\\uD835\\uDD53':'bopf','\\uD835\\uDD1F':'bfr','\\uD835\\uDD39':'Bopf','\\u212C':'Bscr','\\uD835\\uDD05':'Bfr','\\uD835\\uDD20':'cfr','\\uD835\\uDCB8':'cscr','\\uD835\\uDD54':'copf','\\u212D':'Cfr','\\uD835\\uDC9E':'Cscr','\\u2102':'Copf','\\u0107':'cacute','\\u0106':'Cacute','\\u0109':'ccirc','\\u0108':'Ccirc','\\u010D':'ccaron','\\u010C':'Ccaron','\\u010B':'cdot','\\u010A':'Cdot','\\xE7':'ccedil','\\xC7':'Ccedil','\\u2105':'incare','\\uD835\\uDD21':'dfr','\\u2146':'dd','\\uD835\\uDD55':'dopf','\\uD835\\uDCB9':'dscr','\\uD835\\uDC9F':'Dscr','\\uD835\\uDD07':'Dfr','\\u2145':'DD','\\uD835\\uDD3B':'Dopf','\\u010F':'dcaron','\\u010E':'Dcaron','\\u0111':'dstrok','\\u0110':'Dstrok','\\xF0':'eth','\\xD0':'ETH','\\u2147':'ee','\\u212F':'escr','\\uD835\\uDD22':'efr','\\uD835\\uDD56':'eopf','\\u2130':'Escr','\\uD835\\uDD08':'Efr','\\uD835\\uDD3C':'Eopf','\\xE9':'eacute','\\xC9':'Eacute','\\xE8':'egrave','\\xC8':'Egrave','\\xEA':'ecirc','\\xCA':'Ecirc','\\u011B':'ecaron','\\u011A':'Ecaron','\\xEB':'euml','\\xCB':'Euml','\\u0117':'edot','\\u0116':'Edot','\\u0119':'eogon','\\u0118':'Eogon','\\u0113':'emacr','\\u0112':'Emacr','\\uD835\\uDD23':'ffr','\\uD835\\uDD57':'fopf','\\uD835\\uDCBB':'fscr','\\uD835\\uDD09':'Ffr','\\uD835\\uDD3D':'Fopf','\\u2131':'Fscr','\\uFB00':'fflig','\\uFB03':'ffilig','\\uFB04':'ffllig','\\uFB01':'filig','fj':'fjlig','\\uFB02':'fllig','\\u0192':'fnof','\\u210A':'gscr','\\uD835\\uDD58':'gopf','\\uD835\\uDD24':'gfr','\\uD835\\uDCA2':'Gscr','\\uD835\\uDD3E':'Gopf','\\uD835\\uDD0A':'Gfr','\\u01F5':'gacute','\\u011F':'gbreve','\\u011E':'Gbreve','\\u011D':'gcirc','\\u011C':'Gcirc','\\u0121':'gdot','\\u0120':'Gdot','\\u0122':'Gcedil','\\uD835\\uDD25':'hfr','\\u210E':'planckh','\\uD835\\uDCBD':'hscr','\\uD835\\uDD59':'hopf','\\u210B':'Hscr','\\u210C':'Hfr','\\u210D':'Hopf','\\u0125':'hcirc','\\u0124':'Hcirc','\\u210F':'hbar','\\u0127':'hstrok','\\u0126':'Hstrok','\\uD835\\uDD5A':'iopf','\\uD835\\uDD26':'ifr','\\uD835\\uDCBE':'iscr','\\u2148':'ii','\\uD835\\uDD40':'Iopf','\\u2110':'Iscr','\\u2111':'Im','\\xED':'iacute','\\xCD':'Iacute','\\xEC':'igrave','\\xCC':'Igrave','\\xEE':'icirc','\\xCE':'Icirc','\\xEF':'iuml','\\xCF':'Iuml','\\u0129':'itilde','\\u0128':'Itilde','\\u0130':'Idot','\\u012F':'iogon','\\u012E':'Iogon','\\u012B':'imacr','\\u012A':'Imacr','\\u0133':'ijlig','\\u0132':'IJlig','\\u0131':'imath','\\uD835\\uDCBF':'jscr','\\uD835\\uDD5B':'jopf','\\uD835\\uDD27':'jfr','\\uD835\\uDCA5':'Jscr','\\uD835\\uDD0D':'Jfr','\\uD835\\uDD41':'Jopf','\\u0135':'jcirc','\\u0134':'Jcirc','\\u0237':'jmath','\\uD835\\uDD5C':'kopf','\\uD835\\uDCC0':'kscr','\\uD835\\uDD28':'kfr','\\uD835\\uDCA6':'Kscr','\\uD835\\uDD42':'Kopf','\\uD835\\uDD0E':'Kfr','\\u0137':'kcedil','\\u0136':'Kcedil','\\uD835\\uDD29':'lfr','\\uD835\\uDCC1':'lscr','\\u2113':'ell','\\uD835\\uDD5D':'lopf','\\u2112':'Lscr','\\uD835\\uDD0F':'Lfr','\\uD835\\uDD43':'Lopf','\\u013A':'lacute','\\u0139':'Lacute','\\u013E':'lcaron','\\u013D':'Lcaron','\\u013C':'lcedil','\\u013B':'Lcedil','\\u0142':'lstrok','\\u0141':'Lstrok','\\u0140':'lmidot','\\u013F':'Lmidot','\\uD835\\uDD2A':'mfr','\\uD835\\uDD5E':'mopf','\\uD835\\uDCC2':'mscr','\\uD835\\uDD10':'Mfr','\\uD835\\uDD44':'Mopf','\\u2133':'Mscr','\\uD835\\uDD2B':'nfr','\\uD835\\uDD5F':'nopf','\\uD835\\uDCC3':'nscr','\\u2115':'Nopf','\\uD835\\uDCA9':'Nscr','\\uD835\\uDD11':'Nfr','\\u0144':'nacute','\\u0143':'Nacute','\\u0148':'ncaron','\\u0147':'Ncaron','\\xF1':'ntilde','\\xD1':'Ntilde','\\u0146':'ncedil','\\u0145':'Ncedil','\\u2116':'numero','\\u014B':'eng','\\u014A':'ENG','\\uD835\\uDD60':'oopf','\\uD835\\uDD2C':'ofr','\\u2134':'oscr','\\uD835\\uDCAA':'Oscr','\\uD835\\uDD12':'Ofr','\\uD835\\uDD46':'Oopf','\\xBA':'ordm','\\xF3':'oacute','\\xD3':'Oacute','\\xF2':'ograve','\\xD2':'Ograve','\\xF4':'ocirc','\\xD4':'Ocirc','\\xF6':'ouml','\\xD6':'Ouml','\\u0151':'odblac','\\u0150':'Odblac','\\xF5':'otilde','\\xD5':'Otilde','\\xF8':'oslash','\\xD8':'Oslash','\\u014D':'omacr','\\u014C':'Omacr','\\u0153':'oelig','\\u0152':'OElig','\\uD835\\uDD2D':'pfr','\\uD835\\uDCC5':'pscr','\\uD835\\uDD61':'popf','\\u2119':'Popf','\\uD835\\uDD13':'Pfr','\\uD835\\uDCAB':'Pscr','\\uD835\\uDD62':'qopf','\\uD835\\uDD2E':'qfr','\\uD835\\uDCC6':'qscr','\\uD835\\uDCAC':'Qscr','\\uD835\\uDD14':'Qfr','\\u211A':'Qopf','\\u0138':'kgreen','\\uD835\\uDD2F':'rfr','\\uD835\\uDD63':'ropf','\\uD835\\uDCC7':'rscr','\\u211B':'Rscr','\\u211C':'Re','\\u211D':'Ropf','\\u0155':'racute','\\u0154':'Racute','\\u0159':'rcaron','\\u0158':'Rcaron','\\u0157':'rcedil','\\u0156':'Rcedil','\\uD835\\uDD64':'sopf','\\uD835\\uDCC8':'sscr','\\uD835\\uDD30':'sfr','\\uD835\\uDD4A':'Sopf','\\uD835\\uDD16':'Sfr','\\uD835\\uDCAE':'Sscr','\\u24C8':'oS','\\u015B':'sacute','\\u015A':'Sacute','\\u015D':'scirc','\\u015C':'Scirc','\\u0161':'scaron','\\u0160':'Scaron','\\u015F':'scedil','\\u015E':'Scedil','\\xDF':'szlig','\\uD835\\uDD31':'tfr','\\uD835\\uDCC9':'tscr','\\uD835\\uDD65':'topf','\\uD835\\uDCAF':'Tscr','\\uD835\\uDD17':'Tfr','\\uD835\\uDD4B':'Topf','\\u0165':'tcaron','\\u0164':'Tcaron','\\u0163':'tcedil','\\u0162':'Tcedil','\\u2122':'trade','\\u0167':'tstrok','\\u0166':'Tstrok','\\uD835\\uDCCA':'uscr','\\uD835\\uDD66':'uopf','\\uD835\\uDD32':'ufr','\\uD835\\uDD4C':'Uopf','\\uD835\\uDD18':'Ufr','\\uD835\\uDCB0':'Uscr','\\xFA':'uacute','\\xDA':'Uacute','\\xF9':'ugrave','\\xD9':'Ugrave','\\u016D':'ubreve','\\u016C':'Ubreve','\\xFB':'ucirc','\\xDB':'Ucirc','\\u016F':'uring','\\u016E':'Uring','\\xFC':'uuml','\\xDC':'Uuml','\\u0171':'udblac','\\u0170':'Udblac','\\u0169':'utilde','\\u0168':'Utilde','\\u0173':'uogon','\\u0172':'Uogon','\\u016B':'umacr','\\u016A':'Umacr','\\uD835\\uDD33':'vfr','\\uD835\\uDD67':'vopf','\\uD835\\uDCCB':'vscr','\\uD835\\uDD19':'Vfr','\\uD835\\uDD4D':'Vopf','\\uD835\\uDCB1':'Vscr','\\uD835\\uDD68':'wopf','\\uD835\\uDCCC':'wscr','\\uD835\\uDD34':'wfr','\\uD835\\uDCB2':'Wscr','\\uD835\\uDD4E':'Wopf','\\uD835\\uDD1A':'Wfr','\\u0175':'wcirc','\\u0174':'Wcirc','\\uD835\\uDD35':'xfr','\\uD835\\uDCCD':'xscr','\\uD835\\uDD69':'xopf','\\uD835\\uDD4F':'Xopf','\\uD835\\uDD1B':'Xfr','\\uD835\\uDCB3':'Xscr','\\uD835\\uDD36':'yfr','\\uD835\\uDCCE':'yscr','\\uD835\\uDD6A':'yopf','\\uD835\\uDCB4':'Yscr','\\uD835\\uDD1C':'Yfr','\\uD835\\uDD50':'Yopf','\\xFD':'yacute','\\xDD':'Yacute','\\u0177':'ycirc','\\u0176':'Ycirc','\\xFF':'yuml','\\u0178':'Yuml','\\uD835\\uDCCF':'zscr','\\uD835\\uDD37':'zfr','\\uD835\\uDD6B':'zopf','\\u2128':'Zfr','\\u2124':'Zopf','\\uD835\\uDCB5':'Zscr','\\u017A':'zacute','\\u0179':'Zacute','\\u017E':'zcaron','\\u017D':'Zcaron','\\u017C':'zdot','\\u017B':'Zdot','\\u01B5':'imped','\\xFE':'thorn','\\xDE':'THORN','\\u0149':'napos','\\u03B1':'alpha','\\u0391':'Alpha','\\u03B2':'beta','\\u0392':'Beta','\\u03B3':'gamma','\\u0393':'Gamma','\\u03B4':'delta','\\u0394':'Delta','\\u03B5':'epsi','\\u03F5':'epsiv','\\u0395':'Epsilon','\\u03DD':'gammad','\\u03DC':'Gammad','\\u03B6':'zeta','\\u0396':'Zeta','\\u03B7':'eta','\\u0397':'Eta','\\u03B8':'theta','\\u03D1':'thetav','\\u0398':'Theta','\\u03B9':'iota','\\u0399':'Iota','\\u03BA':'kappa','\\u03F0':'kappav','\\u039A':'Kappa','\\u03BB':'lambda','\\u039B':'Lambda','\\u03BC':'mu','\\xB5':'micro','\\u039C':'Mu','\\u03BD':'nu','\\u039D':'Nu','\\u03BE':'xi','\\u039E':'Xi','\\u03BF':'omicron','\\u039F':'Omicron','\\u03C0':'pi','\\u03D6':'piv','\\u03A0':'Pi','\\u03C1':'rho','\\u03F1':'rhov','\\u03A1':'Rho','\\u03C3':'sigma','\\u03A3':'Sigma','\\u03C2':'sigmaf','\\u03C4':'tau','\\u03A4':'Tau','\\u03C5':'upsi','\\u03A5':'Upsilon','\\u03D2':'Upsi','\\u03C6':'phi','\\u03D5':'phiv','\\u03A6':'Phi','\\u03C7':'chi','\\u03A7':'Chi','\\u03C8':'psi','\\u03A8':'Psi','\\u03C9':'omega','\\u03A9':'ohm','\\u0430':'acy','\\u0410':'Acy','\\u0431':'bcy','\\u0411':'Bcy','\\u0432':'vcy','\\u0412':'Vcy','\\u0433':'gcy','\\u0413':'Gcy','\\u0453':'gjcy','\\u0403':'GJcy','\\u0434':'dcy','\\u0414':'Dcy','\\u0452':'djcy','\\u0402':'DJcy','\\u0435':'iecy','\\u0415':'IEcy','\\u0451':'iocy','\\u0401':'IOcy','\\u0454':'jukcy','\\u0404':'Jukcy','\\u0436':'zhcy','\\u0416':'ZHcy','\\u0437':'zcy','\\u0417':'Zcy','\\u0455':'dscy','\\u0405':'DScy','\\u0438':'icy','\\u0418':'Icy','\\u0456':'iukcy','\\u0406':'Iukcy','\\u0457':'yicy','\\u0407':'YIcy','\\u0439':'jcy','\\u0419':'Jcy','\\u0458':'jsercy','\\u0408':'Jsercy','\\u043A':'kcy','\\u041A':'Kcy','\\u045C':'kjcy','\\u040C':'KJcy','\\u043B':'lcy','\\u041B':'Lcy','\\u0459':'ljcy','\\u0409':'LJcy','\\u043C':'mcy','\\u041C':'Mcy','\\u043D':'ncy','\\u041D':'Ncy','\\u045A':'njcy','\\u040A':'NJcy','\\u043E':'ocy','\\u041E':'Ocy','\\u043F':'pcy','\\u041F':'Pcy','\\u0440':'rcy','\\u0420':'Rcy','\\u0441':'scy','\\u0421':'Scy','\\u0442':'tcy','\\u0422':'Tcy','\\u045B':'tshcy','\\u040B':'TSHcy','\\u0443':'ucy','\\u0423':'Ucy','\\u045E':'ubrcy','\\u040E':'Ubrcy','\\u0444':'fcy','\\u0424':'Fcy','\\u0445':'khcy','\\u0425':'KHcy','\\u0446':'tscy','\\u0426':'TScy','\\u0447':'chcy','\\u0427':'CHcy','\\u045F':'dzcy','\\u040F':'DZcy','\\u0448':'shcy','\\u0428':'SHcy','\\u0449':'shchcy','\\u0429':'SHCHcy','\\u044A':'hardcy','\\u042A':'HARDcy','\\u044B':'ycy','\\u042B':'Ycy','\\u044C':'softcy','\\u042C':'SOFTcy','\\u044D':'ecy','\\u042D':'Ecy','\\u044E':'yucy','\\u042E':'YUcy','\\u044F':'yacy','\\u042F':'YAcy','\\u2135':'aleph','\\u2136':'beth','\\u2137':'gimel','\\u2138':'daleth'};\n\n\tvar regexEscape = /[\"&'<>`]/g;\n\tvar escapeMap = {\n\t\t'\"': '"',\n\t\t'&': '&',\n\t\t'\\'': ''',\n\t\t'<': '<',\n\t\t// See https://mathiasbynens.be/notes/ambiguous-ampersands: in HTML, the\n\t\t// following is not strictly necessary unless it’s part of a tag or an\n\t\t// unquoted attribute value. We’re only escaping it to support those\n\t\t// situations, and for XML support.\n\t\t'>': '>',\n\t\t// In Internet Explorer ≤ 8, the backtick character can be used\n\t\t// to break out of (un)quoted attribute values or HTML comments.\n\t\t// See http://html5sec.org/#102, http://html5sec.org/#108, and\n\t\t// http://html5sec.org/#133.\n\t\t'`': '`'\n\t};\n\n\tvar regexInvalidEntity = /&#(?:[xX][^a-fA-F0-9]|[^0-9xX])/;\n\tvar regexInvalidRawCodePoint = /[\\0-\\x08\\x0B\\x0E-\\x1F\\x7F-\\x9F\\uFDD0-\\uFDEF\\uFFFE\\uFFFF]|[\\uD83F\\uD87F\\uD8BF\\uD8FF\\uD93F\\uD97F\\uD9BF\\uD9FF\\uDA3F\\uDA7F\\uDABF\\uDAFF\\uDB3F\\uDB7F\\uDBBF\\uDBFF][\\uDFFE\\uDFFF]|[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF]/;\n\tvar regexDecode = /&#([0-9]+)(;?)|&#[xX]([a-fA-F0-9]+)(;?)|&([0-9a-zA-Z]+);|&(Aacute|Agrave|Atilde|Ccedil|Eacute|Egrave|Iacute|Igrave|Ntilde|Oacute|Ograve|Oslash|Otilde|Uacute|Ugrave|Yacute|aacute|agrave|atilde|brvbar|ccedil|curren|divide|eacute|egrave|frac12|frac14|frac34|iacute|igrave|iquest|middot|ntilde|oacute|ograve|oslash|otilde|plusmn|uacute|ugrave|yacute|AElig|Acirc|Aring|Ecirc|Icirc|Ocirc|THORN|Ucirc|acirc|acute|aelig|aring|cedil|ecirc|icirc|iexcl|laquo|micro|ocirc|pound|raquo|szlig|thorn|times|ucirc|Auml|COPY|Euml|Iuml|Ouml|QUOT|Uuml|auml|cent|copy|euml|iuml|macr|nbsp|ordf|ordm|ouml|para|quot|sect|sup1|sup2|sup3|uuml|yuml|AMP|ETH|REG|amp|deg|eth|not|reg|shy|uml|yen|GT|LT|gt|lt)([=a-zA-Z0-9])?/g;\n\tvar decodeMap = {'aacute':'\\xE1','Aacute':'\\xC1','abreve':'\\u0103','Abreve':'\\u0102','ac':'\\u223E','acd':'\\u223F','acE':'\\u223E\\u0333','acirc':'\\xE2','Acirc':'\\xC2','acute':'\\xB4','acy':'\\u0430','Acy':'\\u0410','aelig':'\\xE6','AElig':'\\xC6','af':'\\u2061','afr':'\\uD835\\uDD1E','Afr':'\\uD835\\uDD04','agrave':'\\xE0','Agrave':'\\xC0','alefsym':'\\u2135','aleph':'\\u2135','alpha':'\\u03B1','Alpha':'\\u0391','amacr':'\\u0101','Amacr':'\\u0100','amalg':'\\u2A3F','amp':'&','AMP':'&','and':'\\u2227','And':'\\u2A53','andand':'\\u2A55','andd':'\\u2A5C','andslope':'\\u2A58','andv':'\\u2A5A','ang':'\\u2220','ange':'\\u29A4','angle':'\\u2220','angmsd':'\\u2221','angmsdaa':'\\u29A8','angmsdab':'\\u29A9','angmsdac':'\\u29AA','angmsdad':'\\u29AB','angmsdae':'\\u29AC','angmsdaf':'\\u29AD','angmsdag':'\\u29AE','angmsdah':'\\u29AF','angrt':'\\u221F','angrtvb':'\\u22BE','angrtvbd':'\\u299D','angsph':'\\u2222','angst':'\\xC5','angzarr':'\\u237C','aogon':'\\u0105','Aogon':'\\u0104','aopf':'\\uD835\\uDD52','Aopf':'\\uD835\\uDD38','ap':'\\u2248','apacir':'\\u2A6F','ape':'\\u224A','apE':'\\u2A70','apid':'\\u224B','apos':'\\'','ApplyFunction':'\\u2061','approx':'\\u2248','approxeq':'\\u224A','aring':'\\xE5','Aring':'\\xC5','ascr':'\\uD835\\uDCB6','Ascr':'\\uD835\\uDC9C','Assign':'\\u2254','ast':'*','asymp':'\\u2248','asympeq':'\\u224D','atilde':'\\xE3','Atilde':'\\xC3','auml':'\\xE4','Auml':'\\xC4','awconint':'\\u2233','awint':'\\u2A11','backcong':'\\u224C','backepsilon':'\\u03F6','backprime':'\\u2035','backsim':'\\u223D','backsimeq':'\\u22CD','Backslash':'\\u2216','Barv':'\\u2AE7','barvee':'\\u22BD','barwed':'\\u2305','Barwed':'\\u2306','barwedge':'\\u2305','bbrk':'\\u23B5','bbrktbrk':'\\u23B6','bcong':'\\u224C','bcy':'\\u0431','Bcy':'\\u0411','bdquo':'\\u201E','becaus':'\\u2235','because':'\\u2235','Because':'\\u2235','bemptyv':'\\u29B0','bepsi':'\\u03F6','bernou':'\\u212C','Bernoullis':'\\u212C','beta':'\\u03B2','Beta':'\\u0392','beth':'\\u2136','between':'\\u226C','bfr':'\\uD835\\uDD1F','Bfr':'\\uD835\\uDD05','bigcap':'\\u22C2','bigcirc':'\\u25EF','bigcup':'\\u22C3','bigodot':'\\u2A00','bigoplus':'\\u2A01','bigotimes':'\\u2A02','bigsqcup':'\\u2A06','bigstar':'\\u2605','bigtriangledown':'\\u25BD','bigtriangleup':'\\u25B3','biguplus':'\\u2A04','bigvee':'\\u22C1','bigwedge':'\\u22C0','bkarow':'\\u290D','blacklozenge':'\\u29EB','blacksquare':'\\u25AA','blacktriangle':'\\u25B4','blacktriangledown':'\\u25BE','blacktriangleleft':'\\u25C2','blacktriangleright':'\\u25B8','blank':'\\u2423','blk12':'\\u2592','blk14':'\\u2591','blk34':'\\u2593','block':'\\u2588','bne':'=\\u20E5','bnequiv':'\\u2261\\u20E5','bnot':'\\u2310','bNot':'\\u2AED','bopf':'\\uD835\\uDD53','Bopf':'\\uD835\\uDD39','bot':'\\u22A5','bottom':'\\u22A5','bowtie':'\\u22C8','boxbox':'\\u29C9','boxdl':'\\u2510','boxdL':'\\u2555','boxDl':'\\u2556','boxDL':'\\u2557','boxdr':'\\u250C','boxdR':'\\u2552','boxDr':'\\u2553','boxDR':'\\u2554','boxh':'\\u2500','boxH':'\\u2550','boxhd':'\\u252C','boxhD':'\\u2565','boxHd':'\\u2564','boxHD':'\\u2566','boxhu':'\\u2534','boxhU':'\\u2568','boxHu':'\\u2567','boxHU':'\\u2569','boxminus':'\\u229F','boxplus':'\\u229E','boxtimes':'\\u22A0','boxul':'\\u2518','boxuL':'\\u255B','boxUl':'\\u255C','boxUL':'\\u255D','boxur':'\\u2514','boxuR':'\\u2558','boxUr':'\\u2559','boxUR':'\\u255A','boxv':'\\u2502','boxV':'\\u2551','boxvh':'\\u253C','boxvH':'\\u256A','boxVh':'\\u256B','boxVH':'\\u256C','boxvl':'\\u2524','boxvL':'\\u2561','boxVl':'\\u2562','boxVL':'\\u2563','boxvr':'\\u251C','boxvR':'\\u255E','boxVr':'\\u255F','boxVR':'\\u2560','bprime':'\\u2035','breve':'\\u02D8','Breve':'\\u02D8','brvbar':'\\xA6','bscr':'\\uD835\\uDCB7','Bscr':'\\u212C','bsemi':'\\u204F','bsim':'\\u223D','bsime':'\\u22CD','bsol':'\\\\','bsolb':'\\u29C5','bsolhsub':'\\u27C8','bull':'\\u2022','bullet':'\\u2022','bump':'\\u224E','bumpe':'\\u224F','bumpE':'\\u2AAE','bumpeq':'\\u224F','Bumpeq':'\\u224E','cacute':'\\u0107','Cacute':'\\u0106','cap':'\\u2229','Cap':'\\u22D2','capand':'\\u2A44','capbrcup':'\\u2A49','capcap':'\\u2A4B','capcup':'\\u2A47','capdot':'\\u2A40','CapitalDifferentialD':'\\u2145','caps':'\\u2229\\uFE00','caret':'\\u2041','caron':'\\u02C7','Cayleys':'\\u212D','ccaps':'\\u2A4D','ccaron':'\\u010D','Ccaron':'\\u010C','ccedil':'\\xE7','Ccedil':'\\xC7','ccirc':'\\u0109','Ccirc':'\\u0108','Cconint':'\\u2230','ccups':'\\u2A4C','ccupssm':'\\u2A50','cdot':'\\u010B','Cdot':'\\u010A','cedil':'\\xB8','Cedilla':'\\xB8','cemptyv':'\\u29B2','cent':'\\xA2','centerdot':'\\xB7','CenterDot':'\\xB7','cfr':'\\uD835\\uDD20','Cfr':'\\u212D','chcy':'\\u0447','CHcy':'\\u0427','check':'\\u2713','checkmark':'\\u2713','chi':'\\u03C7','Chi':'\\u03A7','cir':'\\u25CB','circ':'\\u02C6','circeq':'\\u2257','circlearrowleft':'\\u21BA','circlearrowright':'\\u21BB','circledast':'\\u229B','circledcirc':'\\u229A','circleddash':'\\u229D','CircleDot':'\\u2299','circledR':'\\xAE','circledS':'\\u24C8','CircleMinus':'\\u2296','CirclePlus':'\\u2295','CircleTimes':'\\u2297','cire':'\\u2257','cirE':'\\u29C3','cirfnint':'\\u2A10','cirmid':'\\u2AEF','cirscir':'\\u29C2','ClockwiseContourIntegral':'\\u2232','CloseCurlyDoubleQuote':'\\u201D','CloseCurlyQuote':'\\u2019','clubs':'\\u2663','clubsuit':'\\u2663','colon':':','Colon':'\\u2237','colone':'\\u2254','Colone':'\\u2A74','coloneq':'\\u2254','comma':',','commat':'@','comp':'\\u2201','compfn':'\\u2218','complement':'\\u2201','complexes':'\\u2102','cong':'\\u2245','congdot':'\\u2A6D','Congruent':'\\u2261','conint':'\\u222E','Conint':'\\u222F','ContourIntegral':'\\u222E','copf':'\\uD835\\uDD54','Copf':'\\u2102','coprod':'\\u2210','Coproduct':'\\u2210','copy':'\\xA9','COPY':'\\xA9','copysr':'\\u2117','CounterClockwiseContourIntegral':'\\u2233','crarr':'\\u21B5','cross':'\\u2717','Cross':'\\u2A2F','cscr':'\\uD835\\uDCB8','Cscr':'\\uD835\\uDC9E','csub':'\\u2ACF','csube':'\\u2AD1','csup':'\\u2AD0','csupe':'\\u2AD2','ctdot':'\\u22EF','cudarrl':'\\u2938','cudarrr':'\\u2935','cuepr':'\\u22DE','cuesc':'\\u22DF','cularr':'\\u21B6','cularrp':'\\u293D','cup':'\\u222A','Cup':'\\u22D3','cupbrcap':'\\u2A48','cupcap':'\\u2A46','CupCap':'\\u224D','cupcup':'\\u2A4A','cupdot':'\\u228D','cupor':'\\u2A45','cups':'\\u222A\\uFE00','curarr':'\\u21B7','curarrm':'\\u293C','curlyeqprec':'\\u22DE','curlyeqsucc':'\\u22DF','curlyvee':'\\u22CE','curlywedge':'\\u22CF','curren':'\\xA4','curvearrowleft':'\\u21B6','curvearrowright':'\\u21B7','cuvee':'\\u22CE','cuwed':'\\u22CF','cwconint':'\\u2232','cwint':'\\u2231','cylcty':'\\u232D','dagger':'\\u2020','Dagger':'\\u2021','daleth':'\\u2138','darr':'\\u2193','dArr':'\\u21D3','Darr':'\\u21A1','dash':'\\u2010','dashv':'\\u22A3','Dashv':'\\u2AE4','dbkarow':'\\u290F','dblac':'\\u02DD','dcaron':'\\u010F','Dcaron':'\\u010E','dcy':'\\u0434','Dcy':'\\u0414','dd':'\\u2146','DD':'\\u2145','ddagger':'\\u2021','ddarr':'\\u21CA','DDotrahd':'\\u2911','ddotseq':'\\u2A77','deg':'\\xB0','Del':'\\u2207','delta':'\\u03B4','Delta':'\\u0394','demptyv':'\\u29B1','dfisht':'\\u297F','dfr':'\\uD835\\uDD21','Dfr':'\\uD835\\uDD07','dHar':'\\u2965','dharl':'\\u21C3','dharr':'\\u21C2','DiacriticalAcute':'\\xB4','DiacriticalDot':'\\u02D9','DiacriticalDoubleAcute':'\\u02DD','DiacriticalGrave':'`','DiacriticalTilde':'\\u02DC','diam':'\\u22C4','diamond':'\\u22C4','Diamond':'\\u22C4','diamondsuit':'\\u2666','diams':'\\u2666','die':'\\xA8','DifferentialD':'\\u2146','digamma':'\\u03DD','disin':'\\u22F2','div':'\\xF7','divide':'\\xF7','divideontimes':'\\u22C7','divonx':'\\u22C7','djcy':'\\u0452','DJcy':'\\u0402','dlcorn':'\\u231E','dlcrop':'\\u230D','dollar':'$','dopf':'\\uD835\\uDD55','Dopf':'\\uD835\\uDD3B','dot':'\\u02D9','Dot':'\\xA8','DotDot':'\\u20DC','doteq':'\\u2250','doteqdot':'\\u2251','DotEqual':'\\u2250','dotminus':'\\u2238','dotplus':'\\u2214','dotsquare':'\\u22A1','doublebarwedge':'\\u2306','DoubleContourIntegral':'\\u222F','DoubleDot':'\\xA8','DoubleDownArrow':'\\u21D3','DoubleLeftArrow':'\\u21D0','DoubleLeftRightArrow':'\\u21D4','DoubleLeftTee':'\\u2AE4','DoubleLongLeftArrow':'\\u27F8','DoubleLongLeftRightArrow':'\\u27FA','DoubleLongRightArrow':'\\u27F9','DoubleRightArrow':'\\u21D2','DoubleRightTee':'\\u22A8','DoubleUpArrow':'\\u21D1','DoubleUpDownArrow':'\\u21D5','DoubleVerticalBar':'\\u2225','downarrow':'\\u2193','Downarrow':'\\u21D3','DownArrow':'\\u2193','DownArrowBar':'\\u2913','DownArrowUpArrow':'\\u21F5','DownBreve':'\\u0311','downdownarrows':'\\u21CA','downharpoonleft':'\\u21C3','downharpoonright':'\\u21C2','DownLeftRightVector':'\\u2950','DownLeftTeeVector':'\\u295E','DownLeftVector':'\\u21BD','DownLeftVectorBar':'\\u2956','DownRightTeeVector':'\\u295F','DownRightVector':'\\u21C1','DownRightVectorBar':'\\u2957','DownTee':'\\u22A4','DownTeeArrow':'\\u21A7','drbkarow':'\\u2910','drcorn':'\\u231F','drcrop':'\\u230C','dscr':'\\uD835\\uDCB9','Dscr':'\\uD835\\uDC9F','dscy':'\\u0455','DScy':'\\u0405','dsol':'\\u29F6','dstrok':'\\u0111','Dstrok':'\\u0110','dtdot':'\\u22F1','dtri':'\\u25BF','dtrif':'\\u25BE','duarr':'\\u21F5','duhar':'\\u296F','dwangle':'\\u29A6','dzcy':'\\u045F','DZcy':'\\u040F','dzigrarr':'\\u27FF','eacute':'\\xE9','Eacute':'\\xC9','easter':'\\u2A6E','ecaron':'\\u011B','Ecaron':'\\u011A','ecir':'\\u2256','ecirc':'\\xEA','Ecirc':'\\xCA','ecolon':'\\u2255','ecy':'\\u044D','Ecy':'\\u042D','eDDot':'\\u2A77','edot':'\\u0117','eDot':'\\u2251','Edot':'\\u0116','ee':'\\u2147','efDot':'\\u2252','efr':'\\uD835\\uDD22','Efr':'\\uD835\\uDD08','eg':'\\u2A9A','egrave':'\\xE8','Egrave':'\\xC8','egs':'\\u2A96','egsdot':'\\u2A98','el':'\\u2A99','Element':'\\u2208','elinters':'\\u23E7','ell':'\\u2113','els':'\\u2A95','elsdot':'\\u2A97','emacr':'\\u0113','Emacr':'\\u0112','empty':'\\u2205','emptyset':'\\u2205','EmptySmallSquare':'\\u25FB','emptyv':'\\u2205','EmptyVerySmallSquare':'\\u25AB','emsp':'\\u2003','emsp13':'\\u2004','emsp14':'\\u2005','eng':'\\u014B','ENG':'\\u014A','ensp':'\\u2002','eogon':'\\u0119','Eogon':'\\u0118','eopf':'\\uD835\\uDD56','Eopf':'\\uD835\\uDD3C','epar':'\\u22D5','eparsl':'\\u29E3','eplus':'\\u2A71','epsi':'\\u03B5','epsilon':'\\u03B5','Epsilon':'\\u0395','epsiv':'\\u03F5','eqcirc':'\\u2256','eqcolon':'\\u2255','eqsim':'\\u2242','eqslantgtr':'\\u2A96','eqslantless':'\\u2A95','Equal':'\\u2A75','equals':'=','EqualTilde':'\\u2242','equest':'\\u225F','Equilibrium':'\\u21CC','equiv':'\\u2261','equivDD':'\\u2A78','eqvparsl':'\\u29E5','erarr':'\\u2971','erDot':'\\u2253','escr':'\\u212F','Escr':'\\u2130','esdot':'\\u2250','esim':'\\u2242','Esim':'\\u2A73','eta':'\\u03B7','Eta':'\\u0397','eth':'\\xF0','ETH':'\\xD0','euml':'\\xEB','Euml':'\\xCB','euro':'\\u20AC','excl':'!','exist':'\\u2203','Exists':'\\u2203','expectation':'\\u2130','exponentiale':'\\u2147','ExponentialE':'\\u2147','fallingdotseq':'\\u2252','fcy':'\\u0444','Fcy':'\\u0424','female':'\\u2640','ffilig':'\\uFB03','fflig':'\\uFB00','ffllig':'\\uFB04','ffr':'\\uD835\\uDD23','Ffr':'\\uD835\\uDD09','filig':'\\uFB01','FilledSmallSquare':'\\u25FC','FilledVerySmallSquare':'\\u25AA','fjlig':'fj','flat':'\\u266D','fllig':'\\uFB02','fltns':'\\u25B1','fnof':'\\u0192','fopf':'\\uD835\\uDD57','Fopf':'\\uD835\\uDD3D','forall':'\\u2200','ForAll':'\\u2200','fork':'\\u22D4','forkv':'\\u2AD9','Fouriertrf':'\\u2131','fpartint':'\\u2A0D','frac12':'\\xBD','frac13':'\\u2153','frac14':'\\xBC','frac15':'\\u2155','frac16':'\\u2159','frac18':'\\u215B','frac23':'\\u2154','frac25':'\\u2156','frac34':'\\xBE','frac35':'\\u2157','frac38':'\\u215C','frac45':'\\u2158','frac56':'\\u215A','frac58':'\\u215D','frac78':'\\u215E','frasl':'\\u2044','frown':'\\u2322','fscr':'\\uD835\\uDCBB','Fscr':'\\u2131','gacute':'\\u01F5','gamma':'\\u03B3','Gamma':'\\u0393','gammad':'\\u03DD','Gammad':'\\u03DC','gap':'\\u2A86','gbreve':'\\u011F','Gbreve':'\\u011E','Gcedil':'\\u0122','gcirc':'\\u011D','Gcirc':'\\u011C','gcy':'\\u0433','Gcy':'\\u0413','gdot':'\\u0121','Gdot':'\\u0120','ge':'\\u2265','gE':'\\u2267','gel':'\\u22DB','gEl':'\\u2A8C','geq':'\\u2265','geqq':'\\u2267','geqslant':'\\u2A7E','ges':'\\u2A7E','gescc':'\\u2AA9','gesdot':'\\u2A80','gesdoto':'\\u2A82','gesdotol':'\\u2A84','gesl':'\\u22DB\\uFE00','gesles':'\\u2A94','gfr':'\\uD835\\uDD24','Gfr':'\\uD835\\uDD0A','gg':'\\u226B','Gg':'\\u22D9','ggg':'\\u22D9','gimel':'\\u2137','gjcy':'\\u0453','GJcy':'\\u0403','gl':'\\u2277','gla':'\\u2AA5','glE':'\\u2A92','glj':'\\u2AA4','gnap':'\\u2A8A','gnapprox':'\\u2A8A','gne':'\\u2A88','gnE':'\\u2269','gneq':'\\u2A88','gneqq':'\\u2269','gnsim':'\\u22E7','gopf':'\\uD835\\uDD58','Gopf':'\\uD835\\uDD3E','grave':'`','GreaterEqual':'\\u2265','GreaterEqualLess':'\\u22DB','GreaterFullEqual':'\\u2267','GreaterGreater':'\\u2AA2','GreaterLess':'\\u2277','GreaterSlantEqual':'\\u2A7E','GreaterTilde':'\\u2273','gscr':'\\u210A','Gscr':'\\uD835\\uDCA2','gsim':'\\u2273','gsime':'\\u2A8E','gsiml':'\\u2A90','gt':'>','Gt':'\\u226B','GT':'>','gtcc':'\\u2AA7','gtcir':'\\u2A7A','gtdot':'\\u22D7','gtlPar':'\\u2995','gtquest':'\\u2A7C','gtrapprox':'\\u2A86','gtrarr':'\\u2978','gtrdot':'\\u22D7','gtreqless':'\\u22DB','gtreqqless':'\\u2A8C','gtrless':'\\u2277','gtrsim':'\\u2273','gvertneqq':'\\u2269\\uFE00','gvnE':'\\u2269\\uFE00','Hacek':'\\u02C7','hairsp':'\\u200A','half':'\\xBD','hamilt':'\\u210B','hardcy':'\\u044A','HARDcy':'\\u042A','harr':'\\u2194','hArr':'\\u21D4','harrcir':'\\u2948','harrw':'\\u21AD','Hat':'^','hbar':'\\u210F','hcirc':'\\u0125','Hcirc':'\\u0124','hearts':'\\u2665','heartsuit':'\\u2665','hellip':'\\u2026','hercon':'\\u22B9','hfr':'\\uD835\\uDD25','Hfr':'\\u210C','HilbertSpace':'\\u210B','hksearow':'\\u2925','hkswarow':'\\u2926','hoarr':'\\u21FF','homtht':'\\u223B','hookleftarrow':'\\u21A9','hookrightarrow':'\\u21AA','hopf':'\\uD835\\uDD59','Hopf':'\\u210D','horbar':'\\u2015','HorizontalLine':'\\u2500','hscr':'\\uD835\\uDCBD','Hscr':'\\u210B','hslash':'\\u210F','hstrok':'\\u0127','Hstrok':'\\u0126','HumpDownHump':'\\u224E','HumpEqual':'\\u224F','hybull':'\\u2043','hyphen':'\\u2010','iacute':'\\xED','Iacute':'\\xCD','ic':'\\u2063','icirc':'\\xEE','Icirc':'\\xCE','icy':'\\u0438','Icy':'\\u0418','Idot':'\\u0130','iecy':'\\u0435','IEcy':'\\u0415','iexcl':'\\xA1','iff':'\\u21D4','ifr':'\\uD835\\uDD26','Ifr':'\\u2111','igrave':'\\xEC','Igrave':'\\xCC','ii':'\\u2148','iiiint':'\\u2A0C','iiint':'\\u222D','iinfin':'\\u29DC','iiota':'\\u2129','ijlig':'\\u0133','IJlig':'\\u0132','Im':'\\u2111','imacr':'\\u012B','Imacr':'\\u012A','image':'\\u2111','ImaginaryI':'\\u2148','imagline':'\\u2110','imagpart':'\\u2111','imath':'\\u0131','imof':'\\u22B7','imped':'\\u01B5','Implies':'\\u21D2','in':'\\u2208','incare':'\\u2105','infin':'\\u221E','infintie':'\\u29DD','inodot':'\\u0131','int':'\\u222B','Int':'\\u222C','intcal':'\\u22BA','integers':'\\u2124','Integral':'\\u222B','intercal':'\\u22BA','Intersection':'\\u22C2','intlarhk':'\\u2A17','intprod':'\\u2A3C','InvisibleComma':'\\u2063','InvisibleTimes':'\\u2062','iocy':'\\u0451','IOcy':'\\u0401','iogon':'\\u012F','Iogon':'\\u012E','iopf':'\\uD835\\uDD5A','Iopf':'\\uD835\\uDD40','iota':'\\u03B9','Iota':'\\u0399','iprod':'\\u2A3C','iquest':'\\xBF','iscr':'\\uD835\\uDCBE','Iscr':'\\u2110','isin':'\\u2208','isindot':'\\u22F5','isinE':'\\u22F9','isins':'\\u22F4','isinsv':'\\u22F3','isinv':'\\u2208','it':'\\u2062','itilde':'\\u0129','Itilde':'\\u0128','iukcy':'\\u0456','Iukcy':'\\u0406','iuml':'\\xEF','Iuml':'\\xCF','jcirc':'\\u0135','Jcirc':'\\u0134','jcy':'\\u0439','Jcy':'\\u0419','jfr':'\\uD835\\uDD27','Jfr':'\\uD835\\uDD0D','jmath':'\\u0237','jopf':'\\uD835\\uDD5B','Jopf':'\\uD835\\uDD41','jscr':'\\uD835\\uDCBF','Jscr':'\\uD835\\uDCA5','jsercy':'\\u0458','Jsercy':'\\u0408','jukcy':'\\u0454','Jukcy':'\\u0404','kappa':'\\u03BA','Kappa':'\\u039A','kappav':'\\u03F0','kcedil':'\\u0137','Kcedil':'\\u0136','kcy':'\\u043A','Kcy':'\\u041A','kfr':'\\uD835\\uDD28','Kfr':'\\uD835\\uDD0E','kgreen':'\\u0138','khcy':'\\u0445','KHcy':'\\u0425','kjcy':'\\u045C','KJcy':'\\u040C','kopf':'\\uD835\\uDD5C','Kopf':'\\uD835\\uDD42','kscr':'\\uD835\\uDCC0','Kscr':'\\uD835\\uDCA6','lAarr':'\\u21DA','lacute':'\\u013A','Lacute':'\\u0139','laemptyv':'\\u29B4','lagran':'\\u2112','lambda':'\\u03BB','Lambda':'\\u039B','lang':'\\u27E8','Lang':'\\u27EA','langd':'\\u2991','langle':'\\u27E8','lap':'\\u2A85','Laplacetrf':'\\u2112','laquo':'\\xAB','larr':'\\u2190','lArr':'\\u21D0','Larr':'\\u219E','larrb':'\\u21E4','larrbfs':'\\u291F','larrfs':'\\u291D','larrhk':'\\u21A9','larrlp':'\\u21AB','larrpl':'\\u2939','larrsim':'\\u2973','larrtl':'\\u21A2','lat':'\\u2AAB','latail':'\\u2919','lAtail':'\\u291B','late':'\\u2AAD','lates':'\\u2AAD\\uFE00','lbarr':'\\u290C','lBarr':'\\u290E','lbbrk':'\\u2772','lbrace':'{','lbrack':'[','lbrke':'\\u298B','lbrksld':'\\u298F','lbrkslu':'\\u298D','lcaron':'\\u013E','Lcaron':'\\u013D','lcedil':'\\u013C','Lcedil':'\\u013B','lceil':'\\u2308','lcub':'{','lcy':'\\u043B','Lcy':'\\u041B','ldca':'\\u2936','ldquo':'\\u201C','ldquor':'\\u201E','ldrdhar':'\\u2967','ldrushar':'\\u294B','ldsh':'\\u21B2','le':'\\u2264','lE':'\\u2266','LeftAngleBracket':'\\u27E8','leftarrow':'\\u2190','Leftarrow':'\\u21D0','LeftArrow':'\\u2190','LeftArrowBar':'\\u21E4','LeftArrowRightArrow':'\\u21C6','leftarrowtail':'\\u21A2','LeftCeiling':'\\u2308','LeftDoubleBracket':'\\u27E6','LeftDownTeeVector':'\\u2961','LeftDownVector':'\\u21C3','LeftDownVectorBar':'\\u2959','LeftFloor':'\\u230A','leftharpoondown':'\\u21BD','leftharpoonup':'\\u21BC','leftleftarrows':'\\u21C7','leftrightarrow':'\\u2194','Leftrightarrow':'\\u21D4','LeftRightArrow':'\\u2194','leftrightarrows':'\\u21C6','leftrightharpoons':'\\u21CB','leftrightsquigarrow':'\\u21AD','LeftRightVector':'\\u294E','LeftTee':'\\u22A3','LeftTeeArrow':'\\u21A4','LeftTeeVector':'\\u295A','leftthreetimes':'\\u22CB','LeftTriangle':'\\u22B2','LeftTriangleBar':'\\u29CF','LeftTriangleEqual':'\\u22B4','LeftUpDownVector':'\\u2951','LeftUpTeeVector':'\\u2960','LeftUpVector':'\\u21BF','LeftUpVectorBar':'\\u2958','LeftVector':'\\u21BC','LeftVectorBar':'\\u2952','leg':'\\u22DA','lEg':'\\u2A8B','leq':'\\u2264','leqq':'\\u2266','leqslant':'\\u2A7D','les':'\\u2A7D','lescc':'\\u2AA8','lesdot':'\\u2A7F','lesdoto':'\\u2A81','lesdotor':'\\u2A83','lesg':'\\u22DA\\uFE00','lesges':'\\u2A93','lessapprox':'\\u2A85','lessdot':'\\u22D6','lesseqgtr':'\\u22DA','lesseqqgtr':'\\u2A8B','LessEqualGreater':'\\u22DA','LessFullEqual':'\\u2266','LessGreater':'\\u2276','lessgtr':'\\u2276','LessLess':'\\u2AA1','lesssim':'\\u2272','LessSlantEqual':'\\u2A7D','LessTilde':'\\u2272','lfisht':'\\u297C','lfloor':'\\u230A','lfr':'\\uD835\\uDD29','Lfr':'\\uD835\\uDD0F','lg':'\\u2276','lgE':'\\u2A91','lHar':'\\u2962','lhard':'\\u21BD','lharu':'\\u21BC','lharul':'\\u296A','lhblk':'\\u2584','ljcy':'\\u0459','LJcy':'\\u0409','ll':'\\u226A','Ll':'\\u22D8','llarr':'\\u21C7','llcorner':'\\u231E','Lleftarrow':'\\u21DA','llhard':'\\u296B','lltri':'\\u25FA','lmidot':'\\u0140','Lmidot':'\\u013F','lmoust':'\\u23B0','lmoustache':'\\u23B0','lnap':'\\u2A89','lnapprox':'\\u2A89','lne':'\\u2A87','lnE':'\\u2268','lneq':'\\u2A87','lneqq':'\\u2268','lnsim':'\\u22E6','loang':'\\u27EC','loarr':'\\u21FD','lobrk':'\\u27E6','longleftarrow':'\\u27F5','Longleftarrow':'\\u27F8','LongLeftArrow':'\\u27F5','longleftrightarrow':'\\u27F7','Longleftrightarrow':'\\u27FA','LongLeftRightArrow':'\\u27F7','longmapsto':'\\u27FC','longrightarrow':'\\u27F6','Longrightarrow':'\\u27F9','LongRightArrow':'\\u27F6','looparrowleft':'\\u21AB','looparrowright':'\\u21AC','lopar':'\\u2985','lopf':'\\uD835\\uDD5D','Lopf':'\\uD835\\uDD43','loplus':'\\u2A2D','lotimes':'\\u2A34','lowast':'\\u2217','lowbar':'_','LowerLeftArrow':'\\u2199','LowerRightArrow':'\\u2198','loz':'\\u25CA','lozenge':'\\u25CA','lozf':'\\u29EB','lpar':'(','lparlt':'\\u2993','lrarr':'\\u21C6','lrcorner':'\\u231F','lrhar':'\\u21CB','lrhard':'\\u296D','lrm':'\\u200E','lrtri':'\\u22BF','lsaquo':'\\u2039','lscr':'\\uD835\\uDCC1','Lscr':'\\u2112','lsh':'\\u21B0','Lsh':'\\u21B0','lsim':'\\u2272','lsime':'\\u2A8D','lsimg':'\\u2A8F','lsqb':'[','lsquo':'\\u2018','lsquor':'\\u201A','lstrok':'\\u0142','Lstrok':'\\u0141','lt':'<','Lt':'\\u226A','LT':'<','ltcc':'\\u2AA6','ltcir':'\\u2A79','ltdot':'\\u22D6','lthree':'\\u22CB','ltimes':'\\u22C9','ltlarr':'\\u2976','ltquest':'\\u2A7B','ltri':'\\u25C3','ltrie':'\\u22B4','ltrif':'\\u25C2','ltrPar':'\\u2996','lurdshar':'\\u294A','luruhar':'\\u2966','lvertneqq':'\\u2268\\uFE00','lvnE':'\\u2268\\uFE00','macr':'\\xAF','male':'\\u2642','malt':'\\u2720','maltese':'\\u2720','map':'\\u21A6','Map':'\\u2905','mapsto':'\\u21A6','mapstodown':'\\u21A7','mapstoleft':'\\u21A4','mapstoup':'\\u21A5','marker':'\\u25AE','mcomma':'\\u2A29','mcy':'\\u043C','Mcy':'\\u041C','mdash':'\\u2014','mDDot':'\\u223A','measuredangle':'\\u2221','MediumSpace':'\\u205F','Mellintrf':'\\u2133','mfr':'\\uD835\\uDD2A','Mfr':'\\uD835\\uDD10','mho':'\\u2127','micro':'\\xB5','mid':'\\u2223','midast':'*','midcir':'\\u2AF0','middot':'\\xB7','minus':'\\u2212','minusb':'\\u229F','minusd':'\\u2238','minusdu':'\\u2A2A','MinusPlus':'\\u2213','mlcp':'\\u2ADB','mldr':'\\u2026','mnplus':'\\u2213','models':'\\u22A7','mopf':'\\uD835\\uDD5E','Mopf':'\\uD835\\uDD44','mp':'\\u2213','mscr':'\\uD835\\uDCC2','Mscr':'\\u2133','mstpos':'\\u223E','mu':'\\u03BC','Mu':'\\u039C','multimap':'\\u22B8','mumap':'\\u22B8','nabla':'\\u2207','nacute':'\\u0144','Nacute':'\\u0143','nang':'\\u2220\\u20D2','nap':'\\u2249','napE':'\\u2A70\\u0338','napid':'\\u224B\\u0338','napos':'\\u0149','napprox':'\\u2249','natur':'\\u266E','natural':'\\u266E','naturals':'\\u2115','nbsp':'\\xA0','nbump':'\\u224E\\u0338','nbumpe':'\\u224F\\u0338','ncap':'\\u2A43','ncaron':'\\u0148','Ncaron':'\\u0147','ncedil':'\\u0146','Ncedil':'\\u0145','ncong':'\\u2247','ncongdot':'\\u2A6D\\u0338','ncup':'\\u2A42','ncy':'\\u043D','Ncy':'\\u041D','ndash':'\\u2013','ne':'\\u2260','nearhk':'\\u2924','nearr':'\\u2197','neArr':'\\u21D7','nearrow':'\\u2197','nedot':'\\u2250\\u0338','NegativeMediumSpace':'\\u200B','NegativeThickSpace':'\\u200B','NegativeThinSpace':'\\u200B','NegativeVeryThinSpace':'\\u200B','nequiv':'\\u2262','nesear':'\\u2928','nesim':'\\u2242\\u0338','NestedGreaterGreater':'\\u226B','NestedLessLess':'\\u226A','NewLine':'\\n','nexist':'\\u2204','nexists':'\\u2204','nfr':'\\uD835\\uDD2B','Nfr':'\\uD835\\uDD11','nge':'\\u2271','ngE':'\\u2267\\u0338','ngeq':'\\u2271','ngeqq':'\\u2267\\u0338','ngeqslant':'\\u2A7E\\u0338','nges':'\\u2A7E\\u0338','nGg':'\\u22D9\\u0338','ngsim':'\\u2275','ngt':'\\u226F','nGt':'\\u226B\\u20D2','ngtr':'\\u226F','nGtv':'\\u226B\\u0338','nharr':'\\u21AE','nhArr':'\\u21CE','nhpar':'\\u2AF2','ni':'\\u220B','nis':'\\u22FC','nisd':'\\u22FA','niv':'\\u220B','njcy':'\\u045A','NJcy':'\\u040A','nlarr':'\\u219A','nlArr':'\\u21CD','nldr':'\\u2025','nle':'\\u2270','nlE':'\\u2266\\u0338','nleftarrow':'\\u219A','nLeftarrow':'\\u21CD','nleftrightarrow':'\\u21AE','nLeftrightarrow':'\\u21CE','nleq':'\\u2270','nleqq':'\\u2266\\u0338','nleqslant':'\\u2A7D\\u0338','nles':'\\u2A7D\\u0338','nless':'\\u226E','nLl':'\\u22D8\\u0338','nlsim':'\\u2274','nlt':'\\u226E','nLt':'\\u226A\\u20D2','nltri':'\\u22EA','nltrie':'\\u22EC','nLtv':'\\u226A\\u0338','nmid':'\\u2224','NoBreak':'\\u2060','NonBreakingSpace':'\\xA0','nopf':'\\uD835\\uDD5F','Nopf':'\\u2115','not':'\\xAC','Not':'\\u2AEC','NotCongruent':'\\u2262','NotCupCap':'\\u226D','NotDoubleVerticalBar':'\\u2226','NotElement':'\\u2209','NotEqual':'\\u2260','NotEqualTilde':'\\u2242\\u0338','NotExists':'\\u2204','NotGreater':'\\u226F','NotGreaterEqual':'\\u2271','NotGreaterFullEqual':'\\u2267\\u0338','NotGreaterGreater':'\\u226B\\u0338','NotGreaterLess':'\\u2279','NotGreaterSlantEqual':'\\u2A7E\\u0338','NotGreaterTilde':'\\u2275','NotHumpDownHump':'\\u224E\\u0338','NotHumpEqual':'\\u224F\\u0338','notin':'\\u2209','notindot':'\\u22F5\\u0338','notinE':'\\u22F9\\u0338','notinva':'\\u2209','notinvb':'\\u22F7','notinvc':'\\u22F6','NotLeftTriangle':'\\u22EA','NotLeftTriangleBar':'\\u29CF\\u0338','NotLeftTriangleEqual':'\\u22EC','NotLess':'\\u226E','NotLessEqual':'\\u2270','NotLessGreater':'\\u2278','NotLessLess':'\\u226A\\u0338','NotLessSlantEqual':'\\u2A7D\\u0338','NotLessTilde':'\\u2274','NotNestedGreaterGreater':'\\u2AA2\\u0338','NotNestedLessLess':'\\u2AA1\\u0338','notni':'\\u220C','notniva':'\\u220C','notnivb':'\\u22FE','notnivc':'\\u22FD','NotPrecedes':'\\u2280','NotPrecedesEqual':'\\u2AAF\\u0338','NotPrecedesSlantEqual':'\\u22E0','NotReverseElement':'\\u220C','NotRightTriangle':'\\u22EB','NotRightTriangleBar':'\\u29D0\\u0338','NotRightTriangleEqual':'\\u22ED','NotSquareSubset':'\\u228F\\u0338','NotSquareSubsetEqual':'\\u22E2','NotSquareSuperset':'\\u2290\\u0338','NotSquareSupersetEqual':'\\u22E3','NotSubset':'\\u2282\\u20D2','NotSubsetEqual':'\\u2288','NotSucceeds':'\\u2281','NotSucceedsEqual':'\\u2AB0\\u0338','NotSucceedsSlantEqual':'\\u22E1','NotSucceedsTilde':'\\u227F\\u0338','NotSuperset':'\\u2283\\u20D2','NotSupersetEqual':'\\u2289','NotTilde':'\\u2241','NotTildeEqual':'\\u2244','NotTildeFullEqual':'\\u2247','NotTildeTilde':'\\u2249','NotVerticalBar':'\\u2224','npar':'\\u2226','nparallel':'\\u2226','nparsl':'\\u2AFD\\u20E5','npart':'\\u2202\\u0338','npolint':'\\u2A14','npr':'\\u2280','nprcue':'\\u22E0','npre':'\\u2AAF\\u0338','nprec':'\\u2280','npreceq':'\\u2AAF\\u0338','nrarr':'\\u219B','nrArr':'\\u21CF','nrarrc':'\\u2933\\u0338','nrarrw':'\\u219D\\u0338','nrightarrow':'\\u219B','nRightarrow':'\\u21CF','nrtri':'\\u22EB','nrtrie':'\\u22ED','nsc':'\\u2281','nsccue':'\\u22E1','nsce':'\\u2AB0\\u0338','nscr':'\\uD835\\uDCC3','Nscr':'\\uD835\\uDCA9','nshortmid':'\\u2224','nshortparallel':'\\u2226','nsim':'\\u2241','nsime':'\\u2244','nsimeq':'\\u2244','nsmid':'\\u2224','nspar':'\\u2226','nsqsube':'\\u22E2','nsqsupe':'\\u22E3','nsub':'\\u2284','nsube':'\\u2288','nsubE':'\\u2AC5\\u0338','nsubset':'\\u2282\\u20D2','nsubseteq':'\\u2288','nsubseteqq':'\\u2AC5\\u0338','nsucc':'\\u2281','nsucceq':'\\u2AB0\\u0338','nsup':'\\u2285','nsupe':'\\u2289','nsupE':'\\u2AC6\\u0338','nsupset':'\\u2283\\u20D2','nsupseteq':'\\u2289','nsupseteqq':'\\u2AC6\\u0338','ntgl':'\\u2279','ntilde':'\\xF1','Ntilde':'\\xD1','ntlg':'\\u2278','ntriangleleft':'\\u22EA','ntrianglelefteq':'\\u22EC','ntriangleright':'\\u22EB','ntrianglerighteq':'\\u22ED','nu':'\\u03BD','Nu':'\\u039D','num':'#','numero':'\\u2116','numsp':'\\u2007','nvap':'\\u224D\\u20D2','nvdash':'\\u22AC','nvDash':'\\u22AD','nVdash':'\\u22AE','nVDash':'\\u22AF','nvge':'\\u2265\\u20D2','nvgt':'>\\u20D2','nvHarr':'\\u2904','nvinfin':'\\u29DE','nvlArr':'\\u2902','nvle':'\\u2264\\u20D2','nvlt':'<\\u20D2','nvltrie':'\\u22B4\\u20D2','nvrArr':'\\u2903','nvrtrie':'\\u22B5\\u20D2','nvsim':'\\u223C\\u20D2','nwarhk':'\\u2923','nwarr':'\\u2196','nwArr':'\\u21D6','nwarrow':'\\u2196','nwnear':'\\u2927','oacute':'\\xF3','Oacute':'\\xD3','oast':'\\u229B','ocir':'\\u229A','ocirc':'\\xF4','Ocirc':'\\xD4','ocy':'\\u043E','Ocy':'\\u041E','odash':'\\u229D','odblac':'\\u0151','Odblac':'\\u0150','odiv':'\\u2A38','odot':'\\u2299','odsold':'\\u29BC','oelig':'\\u0153','OElig':'\\u0152','ofcir':'\\u29BF','ofr':'\\uD835\\uDD2C','Ofr':'\\uD835\\uDD12','ogon':'\\u02DB','ograve':'\\xF2','Ograve':'\\xD2','ogt':'\\u29C1','ohbar':'\\u29B5','ohm':'\\u03A9','oint':'\\u222E','olarr':'\\u21BA','olcir':'\\u29BE','olcross':'\\u29BB','oline':'\\u203E','olt':'\\u29C0','omacr':'\\u014D','Omacr':'\\u014C','omega':'\\u03C9','Omega':'\\u03A9','omicron':'\\u03BF','Omicron':'\\u039F','omid':'\\u29B6','ominus':'\\u2296','oopf':'\\uD835\\uDD60','Oopf':'\\uD835\\uDD46','opar':'\\u29B7','OpenCurlyDoubleQuote':'\\u201C','OpenCurlyQuote':'\\u2018','operp':'\\u29B9','oplus':'\\u2295','or':'\\u2228','Or':'\\u2A54','orarr':'\\u21BB','ord':'\\u2A5D','order':'\\u2134','orderof':'\\u2134','ordf':'\\xAA','ordm':'\\xBA','origof':'\\u22B6','oror':'\\u2A56','orslope':'\\u2A57','orv':'\\u2A5B','oS':'\\u24C8','oscr':'\\u2134','Oscr':'\\uD835\\uDCAA','oslash':'\\xF8','Oslash':'\\xD8','osol':'\\u2298','otilde':'\\xF5','Otilde':'\\xD5','otimes':'\\u2297','Otimes':'\\u2A37','otimesas':'\\u2A36','ouml':'\\xF6','Ouml':'\\xD6','ovbar':'\\u233D','OverBar':'\\u203E','OverBrace':'\\u23DE','OverBracket':'\\u23B4','OverParenthesis':'\\u23DC','par':'\\u2225','para':'\\xB6','parallel':'\\u2225','parsim':'\\u2AF3','parsl':'\\u2AFD','part':'\\u2202','PartialD':'\\u2202','pcy':'\\u043F','Pcy':'\\u041F','percnt':'%','period':'.','permil':'\\u2030','perp':'\\u22A5','pertenk':'\\u2031','pfr':'\\uD835\\uDD2D','Pfr':'\\uD835\\uDD13','phi':'\\u03C6','Phi':'\\u03A6','phiv':'\\u03D5','phmmat':'\\u2133','phone':'\\u260E','pi':'\\u03C0','Pi':'\\u03A0','pitchfork':'\\u22D4','piv':'\\u03D6','planck':'\\u210F','planckh':'\\u210E','plankv':'\\u210F','plus':'+','plusacir':'\\u2A23','plusb':'\\u229E','pluscir':'\\u2A22','plusdo':'\\u2214','plusdu':'\\u2A25','pluse':'\\u2A72','PlusMinus':'\\xB1','plusmn':'\\xB1','plussim':'\\u2A26','plustwo':'\\u2A27','pm':'\\xB1','Poincareplane':'\\u210C','pointint':'\\u2A15','popf':'\\uD835\\uDD61','Popf':'\\u2119','pound':'\\xA3','pr':'\\u227A','Pr':'\\u2ABB','prap':'\\u2AB7','prcue':'\\u227C','pre':'\\u2AAF','prE':'\\u2AB3','prec':'\\u227A','precapprox':'\\u2AB7','preccurlyeq':'\\u227C','Precedes':'\\u227A','PrecedesEqual':'\\u2AAF','PrecedesSlantEqual':'\\u227C','PrecedesTilde':'\\u227E','preceq':'\\u2AAF','precnapprox':'\\u2AB9','precneqq':'\\u2AB5','precnsim':'\\u22E8','precsim':'\\u227E','prime':'\\u2032','Prime':'\\u2033','primes':'\\u2119','prnap':'\\u2AB9','prnE':'\\u2AB5','prnsim':'\\u22E8','prod':'\\u220F','Product':'\\u220F','profalar':'\\u232E','profline':'\\u2312','profsurf':'\\u2313','prop':'\\u221D','Proportion':'\\u2237','Proportional':'\\u221D','propto':'\\u221D','prsim':'\\u227E','prurel':'\\u22B0','pscr':'\\uD835\\uDCC5','Pscr':'\\uD835\\uDCAB','psi':'\\u03C8','Psi':'\\u03A8','puncsp':'\\u2008','qfr':'\\uD835\\uDD2E','Qfr':'\\uD835\\uDD14','qint':'\\u2A0C','qopf':'\\uD835\\uDD62','Qopf':'\\u211A','qprime':'\\u2057','qscr':'\\uD835\\uDCC6','Qscr':'\\uD835\\uDCAC','quaternions':'\\u210D','quatint':'\\u2A16','quest':'?','questeq':'\\u225F','quot':'\"','QUOT':'\"','rAarr':'\\u21DB','race':'\\u223D\\u0331','racute':'\\u0155','Racute':'\\u0154','radic':'\\u221A','raemptyv':'\\u29B3','rang':'\\u27E9','Rang':'\\u27EB','rangd':'\\u2992','range':'\\u29A5','rangle':'\\u27E9','raquo':'\\xBB','rarr':'\\u2192','rArr':'\\u21D2','Rarr':'\\u21A0','rarrap':'\\u2975','rarrb':'\\u21E5','rarrbfs':'\\u2920','rarrc':'\\u2933','rarrfs':'\\u291E','rarrhk':'\\u21AA','rarrlp':'\\u21AC','rarrpl':'\\u2945','rarrsim':'\\u2974','rarrtl':'\\u21A3','Rarrtl':'\\u2916','rarrw':'\\u219D','ratail':'\\u291A','rAtail':'\\u291C','ratio':'\\u2236','rationals':'\\u211A','rbarr':'\\u290D','rBarr':'\\u290F','RBarr':'\\u2910','rbbrk':'\\u2773','rbrace':'}','rbrack':']','rbrke':'\\u298C','rbrksld':'\\u298E','rbrkslu':'\\u2990','rcaron':'\\u0159','Rcaron':'\\u0158','rcedil':'\\u0157','Rcedil':'\\u0156','rceil':'\\u2309','rcub':'}','rcy':'\\u0440','Rcy':'\\u0420','rdca':'\\u2937','rdldhar':'\\u2969','rdquo':'\\u201D','rdquor':'\\u201D','rdsh':'\\u21B3','Re':'\\u211C','real':'\\u211C','realine':'\\u211B','realpart':'\\u211C','reals':'\\u211D','rect':'\\u25AD','reg':'\\xAE','REG':'\\xAE','ReverseElement':'\\u220B','ReverseEquilibrium':'\\u21CB','ReverseUpEquilibrium':'\\u296F','rfisht':'\\u297D','rfloor':'\\u230B','rfr':'\\uD835\\uDD2F','Rfr':'\\u211C','rHar':'\\u2964','rhard':'\\u21C1','rharu':'\\u21C0','rharul':'\\u296C','rho':'\\u03C1','Rho':'\\u03A1','rhov':'\\u03F1','RightAngleBracket':'\\u27E9','rightarrow':'\\u2192','Rightarrow':'\\u21D2','RightArrow':'\\u2192','RightArrowBar':'\\u21E5','RightArrowLeftArrow':'\\u21C4','rightarrowtail':'\\u21A3','RightCeiling':'\\u2309','RightDoubleBracket':'\\u27E7','RightDownTeeVector':'\\u295D','RightDownVector':'\\u21C2','RightDownVectorBar':'\\u2955','RightFloor':'\\u230B','rightharpoondown':'\\u21C1','rightharpoonup':'\\u21C0','rightleftarrows':'\\u21C4','rightleftharpoons':'\\u21CC','rightrightarrows':'\\u21C9','rightsquigarrow':'\\u219D','RightTee':'\\u22A2','RightTeeArrow':'\\u21A6','RightTeeVector':'\\u295B','rightthreetimes':'\\u22CC','RightTriangle':'\\u22B3','RightTriangleBar':'\\u29D0','RightTriangleEqual':'\\u22B5','RightUpDownVector':'\\u294F','RightUpTeeVector':'\\u295C','RightUpVector':'\\u21BE','RightUpVectorBar':'\\u2954','RightVector':'\\u21C0','RightVectorBar':'\\u2953','ring':'\\u02DA','risingdotseq':'\\u2253','rlarr':'\\u21C4','rlhar':'\\u21CC','rlm':'\\u200F','rmoust':'\\u23B1','rmoustache':'\\u23B1','rnmid':'\\u2AEE','roang':'\\u27ED','roarr':'\\u21FE','robrk':'\\u27E7','ropar':'\\u2986','ropf':'\\uD835\\uDD63','Ropf':'\\u211D','roplus':'\\u2A2E','rotimes':'\\u2A35','RoundImplies':'\\u2970','rpar':')','rpargt':'\\u2994','rppolint':'\\u2A12','rrarr':'\\u21C9','Rrightarrow':'\\u21DB','rsaquo':'\\u203A','rscr':'\\uD835\\uDCC7','Rscr':'\\u211B','rsh':'\\u21B1','Rsh':'\\u21B1','rsqb':']','rsquo':'\\u2019','rsquor':'\\u2019','rthree':'\\u22CC','rtimes':'\\u22CA','rtri':'\\u25B9','rtrie':'\\u22B5','rtrif':'\\u25B8','rtriltri':'\\u29CE','RuleDelayed':'\\u29F4','ruluhar':'\\u2968','rx':'\\u211E','sacute':'\\u015B','Sacute':'\\u015A','sbquo':'\\u201A','sc':'\\u227B','Sc':'\\u2ABC','scap':'\\u2AB8','scaron':'\\u0161','Scaron':'\\u0160','sccue':'\\u227D','sce':'\\u2AB0','scE':'\\u2AB4','scedil':'\\u015F','Scedil':'\\u015E','scirc':'\\u015D','Scirc':'\\u015C','scnap':'\\u2ABA','scnE':'\\u2AB6','scnsim':'\\u22E9','scpolint':'\\u2A13','scsim':'\\u227F','scy':'\\u0441','Scy':'\\u0421','sdot':'\\u22C5','sdotb':'\\u22A1','sdote':'\\u2A66','searhk':'\\u2925','searr':'\\u2198','seArr':'\\u21D8','searrow':'\\u2198','sect':'\\xA7','semi':';','seswar':'\\u2929','setminus':'\\u2216','setmn':'\\u2216','sext':'\\u2736','sfr':'\\uD835\\uDD30','Sfr':'\\uD835\\uDD16','sfrown':'\\u2322','sharp':'\\u266F','shchcy':'\\u0449','SHCHcy':'\\u0429','shcy':'\\u0448','SHcy':'\\u0428','ShortDownArrow':'\\u2193','ShortLeftArrow':'\\u2190','shortmid':'\\u2223','shortparallel':'\\u2225','ShortRightArrow':'\\u2192','ShortUpArrow':'\\u2191','shy':'\\xAD','sigma':'\\u03C3','Sigma':'\\u03A3','sigmaf':'\\u03C2','sigmav':'\\u03C2','sim':'\\u223C','simdot':'\\u2A6A','sime':'\\u2243','simeq':'\\u2243','simg':'\\u2A9E','simgE':'\\u2AA0','siml':'\\u2A9D','simlE':'\\u2A9F','simne':'\\u2246','simplus':'\\u2A24','simrarr':'\\u2972','slarr':'\\u2190','SmallCircle':'\\u2218','smallsetminus':'\\u2216','smashp':'\\u2A33','smeparsl':'\\u29E4','smid':'\\u2223','smile':'\\u2323','smt':'\\u2AAA','smte':'\\u2AAC','smtes':'\\u2AAC\\uFE00','softcy':'\\u044C','SOFTcy':'\\u042C','sol':'/','solb':'\\u29C4','solbar':'\\u233F','sopf':'\\uD835\\uDD64','Sopf':'\\uD835\\uDD4A','spades':'\\u2660','spadesuit':'\\u2660','spar':'\\u2225','sqcap':'\\u2293','sqcaps':'\\u2293\\uFE00','sqcup':'\\u2294','sqcups':'\\u2294\\uFE00','Sqrt':'\\u221A','sqsub':'\\u228F','sqsube':'\\u2291','sqsubset':'\\u228F','sqsubseteq':'\\u2291','sqsup':'\\u2290','sqsupe':'\\u2292','sqsupset':'\\u2290','sqsupseteq':'\\u2292','squ':'\\u25A1','square':'\\u25A1','Square':'\\u25A1','SquareIntersection':'\\u2293','SquareSubset':'\\u228F','SquareSubsetEqual':'\\u2291','SquareSuperset':'\\u2290','SquareSupersetEqual':'\\u2292','SquareUnion':'\\u2294','squarf':'\\u25AA','squf':'\\u25AA','srarr':'\\u2192','sscr':'\\uD835\\uDCC8','Sscr':'\\uD835\\uDCAE','ssetmn':'\\u2216','ssmile':'\\u2323','sstarf':'\\u22C6','star':'\\u2606','Star':'\\u22C6','starf':'\\u2605','straightepsilon':'\\u03F5','straightphi':'\\u03D5','strns':'\\xAF','sub':'\\u2282','Sub':'\\u22D0','subdot':'\\u2ABD','sube':'\\u2286','subE':'\\u2AC5','subedot':'\\u2AC3','submult':'\\u2AC1','subne':'\\u228A','subnE':'\\u2ACB','subplus':'\\u2ABF','subrarr':'\\u2979','subset':'\\u2282','Subset':'\\u22D0','subseteq':'\\u2286','subseteqq':'\\u2AC5','SubsetEqual':'\\u2286','subsetneq':'\\u228A','subsetneqq':'\\u2ACB','subsim':'\\u2AC7','subsub':'\\u2AD5','subsup':'\\u2AD3','succ':'\\u227B','succapprox':'\\u2AB8','succcurlyeq':'\\u227D','Succeeds':'\\u227B','SucceedsEqual':'\\u2AB0','SucceedsSlantEqual':'\\u227D','SucceedsTilde':'\\u227F','succeq':'\\u2AB0','succnapprox':'\\u2ABA','succneqq':'\\u2AB6','succnsim':'\\u22E9','succsim':'\\u227F','SuchThat':'\\u220B','sum':'\\u2211','Sum':'\\u2211','sung':'\\u266A','sup':'\\u2283','Sup':'\\u22D1','sup1':'\\xB9','sup2':'\\xB2','sup3':'\\xB3','supdot':'\\u2ABE','supdsub':'\\u2AD8','supe':'\\u2287','supE':'\\u2AC6','supedot':'\\u2AC4','Superset':'\\u2283','SupersetEqual':'\\u2287','suphsol':'\\u27C9','suphsub':'\\u2AD7','suplarr':'\\u297B','supmult':'\\u2AC2','supne':'\\u228B','supnE':'\\u2ACC','supplus':'\\u2AC0','supset':'\\u2283','Supset':'\\u22D1','supseteq':'\\u2287','supseteqq':'\\u2AC6','supsetneq':'\\u228B','supsetneqq':'\\u2ACC','supsim':'\\u2AC8','supsub':'\\u2AD4','supsup':'\\u2AD6','swarhk':'\\u2926','swarr':'\\u2199','swArr':'\\u21D9','swarrow':'\\u2199','swnwar':'\\u292A','szlig':'\\xDF','Tab':'\\t','target':'\\u2316','tau':'\\u03C4','Tau':'\\u03A4','tbrk':'\\u23B4','tcaron':'\\u0165','Tcaron':'\\u0164','tcedil':'\\u0163','Tcedil':'\\u0162','tcy':'\\u0442','Tcy':'\\u0422','tdot':'\\u20DB','telrec':'\\u2315','tfr':'\\uD835\\uDD31','Tfr':'\\uD835\\uDD17','there4':'\\u2234','therefore':'\\u2234','Therefore':'\\u2234','theta':'\\u03B8','Theta':'\\u0398','thetasym':'\\u03D1','thetav':'\\u03D1','thickapprox':'\\u2248','thicksim':'\\u223C','ThickSpace':'\\u205F\\u200A','thinsp':'\\u2009','ThinSpace':'\\u2009','thkap':'\\u2248','thksim':'\\u223C','thorn':'\\xFE','THORN':'\\xDE','tilde':'\\u02DC','Tilde':'\\u223C','TildeEqual':'\\u2243','TildeFullEqual':'\\u2245','TildeTilde':'\\u2248','times':'\\xD7','timesb':'\\u22A0','timesbar':'\\u2A31','timesd':'\\u2A30','tint':'\\u222D','toea':'\\u2928','top':'\\u22A4','topbot':'\\u2336','topcir':'\\u2AF1','topf':'\\uD835\\uDD65','Topf':'\\uD835\\uDD4B','topfork':'\\u2ADA','tosa':'\\u2929','tprime':'\\u2034','trade':'\\u2122','TRADE':'\\u2122','triangle':'\\u25B5','triangledown':'\\u25BF','triangleleft':'\\u25C3','trianglelefteq':'\\u22B4','triangleq':'\\u225C','triangleright':'\\u25B9','trianglerighteq':'\\u22B5','tridot':'\\u25EC','trie':'\\u225C','triminus':'\\u2A3A','TripleDot':'\\u20DB','triplus':'\\u2A39','trisb':'\\u29CD','tritime':'\\u2A3B','trpezium':'\\u23E2','tscr':'\\uD835\\uDCC9','Tscr':'\\uD835\\uDCAF','tscy':'\\u0446','TScy':'\\u0426','tshcy':'\\u045B','TSHcy':'\\u040B','tstrok':'\\u0167','Tstrok':'\\u0166','twixt':'\\u226C','twoheadleftarrow':'\\u219E','twoheadrightarrow':'\\u21A0','uacute':'\\xFA','Uacute':'\\xDA','uarr':'\\u2191','uArr':'\\u21D1','Uarr':'\\u219F','Uarrocir':'\\u2949','ubrcy':'\\u045E','Ubrcy':'\\u040E','ubreve':'\\u016D','Ubreve':'\\u016C','ucirc':'\\xFB','Ucirc':'\\xDB','ucy':'\\u0443','Ucy':'\\u0423','udarr':'\\u21C5','udblac':'\\u0171','Udblac':'\\u0170','udhar':'\\u296E','ufisht':'\\u297E','ufr':'\\uD835\\uDD32','Ufr':'\\uD835\\uDD18','ugrave':'\\xF9','Ugrave':'\\xD9','uHar':'\\u2963','uharl':'\\u21BF','uharr':'\\u21BE','uhblk':'\\u2580','ulcorn':'\\u231C','ulcorner':'\\u231C','ulcrop':'\\u230F','ultri':'\\u25F8','umacr':'\\u016B','Umacr':'\\u016A','uml':'\\xA8','UnderBar':'_','UnderBrace':'\\u23DF','UnderBracket':'\\u23B5','UnderParenthesis':'\\u23DD','Union':'\\u22C3','UnionPlus':'\\u228E','uogon':'\\u0173','Uogon':'\\u0172','uopf':'\\uD835\\uDD66','Uopf':'\\uD835\\uDD4C','uparrow':'\\u2191','Uparrow':'\\u21D1','UpArrow':'\\u2191','UpArrowBar':'\\u2912','UpArrowDownArrow':'\\u21C5','updownarrow':'\\u2195','Updownarrow':'\\u21D5','UpDownArrow':'\\u2195','UpEquilibrium':'\\u296E','upharpoonleft':'\\u21BF','upharpoonright':'\\u21BE','uplus':'\\u228E','UpperLeftArrow':'\\u2196','UpperRightArrow':'\\u2197','upsi':'\\u03C5','Upsi':'\\u03D2','upsih':'\\u03D2','upsilon':'\\u03C5','Upsilon':'\\u03A5','UpTee':'\\u22A5','UpTeeArrow':'\\u21A5','upuparrows':'\\u21C8','urcorn':'\\u231D','urcorner':'\\u231D','urcrop':'\\u230E','uring':'\\u016F','Uring':'\\u016E','urtri':'\\u25F9','uscr':'\\uD835\\uDCCA','Uscr':'\\uD835\\uDCB0','utdot':'\\u22F0','utilde':'\\u0169','Utilde':'\\u0168','utri':'\\u25B5','utrif':'\\u25B4','uuarr':'\\u21C8','uuml':'\\xFC','Uuml':'\\xDC','uwangle':'\\u29A7','vangrt':'\\u299C','varepsilon':'\\u03F5','varkappa':'\\u03F0','varnothing':'\\u2205','varphi':'\\u03D5','varpi':'\\u03D6','varpropto':'\\u221D','varr':'\\u2195','vArr':'\\u21D5','varrho':'\\u03F1','varsigma':'\\u03C2','varsubsetneq':'\\u228A\\uFE00','varsubsetneqq':'\\u2ACB\\uFE00','varsupsetneq':'\\u228B\\uFE00','varsupsetneqq':'\\u2ACC\\uFE00','vartheta':'\\u03D1','vartriangleleft':'\\u22B2','vartriangleright':'\\u22B3','vBar':'\\u2AE8','Vbar':'\\u2AEB','vBarv':'\\u2AE9','vcy':'\\u0432','Vcy':'\\u0412','vdash':'\\u22A2','vDash':'\\u22A8','Vdash':'\\u22A9','VDash':'\\u22AB','Vdashl':'\\u2AE6','vee':'\\u2228','Vee':'\\u22C1','veebar':'\\u22BB','veeeq':'\\u225A','vellip':'\\u22EE','verbar':'|','Verbar':'\\u2016','vert':'|','Vert':'\\u2016','VerticalBar':'\\u2223','VerticalLine':'|','VerticalSeparator':'\\u2758','VerticalTilde':'\\u2240','VeryThinSpace':'\\u200A','vfr':'\\uD835\\uDD33','Vfr':'\\uD835\\uDD19','vltri':'\\u22B2','vnsub':'\\u2282\\u20D2','vnsup':'\\u2283\\u20D2','vopf':'\\uD835\\uDD67','Vopf':'\\uD835\\uDD4D','vprop':'\\u221D','vrtri':'\\u22B3','vscr':'\\uD835\\uDCCB','Vscr':'\\uD835\\uDCB1','vsubne':'\\u228A\\uFE00','vsubnE':'\\u2ACB\\uFE00','vsupne':'\\u228B\\uFE00','vsupnE':'\\u2ACC\\uFE00','Vvdash':'\\u22AA','vzigzag':'\\u299A','wcirc':'\\u0175','Wcirc':'\\u0174','wedbar':'\\u2A5F','wedge':'\\u2227','Wedge':'\\u22C0','wedgeq':'\\u2259','weierp':'\\u2118','wfr':'\\uD835\\uDD34','Wfr':'\\uD835\\uDD1A','wopf':'\\uD835\\uDD68','Wopf':'\\uD835\\uDD4E','wp':'\\u2118','wr':'\\u2240','wreath':'\\u2240','wscr':'\\uD835\\uDCCC','Wscr':'\\uD835\\uDCB2','xcap':'\\u22C2','xcirc':'\\u25EF','xcup':'\\u22C3','xdtri':'\\u25BD','xfr':'\\uD835\\uDD35','Xfr':'\\uD835\\uDD1B','xharr':'\\u27F7','xhArr':'\\u27FA','xi':'\\u03BE','Xi':'\\u039E','xlarr':'\\u27F5','xlArr':'\\u27F8','xmap':'\\u27FC','xnis':'\\u22FB','xodot':'\\u2A00','xopf':'\\uD835\\uDD69','Xopf':'\\uD835\\uDD4F','xoplus':'\\u2A01','xotime':'\\u2A02','xrarr':'\\u27F6','xrArr':'\\u27F9','xscr':'\\uD835\\uDCCD','Xscr':'\\uD835\\uDCB3','xsqcup':'\\u2A06','xuplus':'\\u2A04','xutri':'\\u25B3','xvee':'\\u22C1','xwedge':'\\u22C0','yacute':'\\xFD','Yacute':'\\xDD','yacy':'\\u044F','YAcy':'\\u042F','ycirc':'\\u0177','Ycirc':'\\u0176','ycy':'\\u044B','Ycy':'\\u042B','yen':'\\xA5','yfr':'\\uD835\\uDD36','Yfr':'\\uD835\\uDD1C','yicy':'\\u0457','YIcy':'\\u0407','yopf':'\\uD835\\uDD6A','Yopf':'\\uD835\\uDD50','yscr':'\\uD835\\uDCCE','Yscr':'\\uD835\\uDCB4','yucy':'\\u044E','YUcy':'\\u042E','yuml':'\\xFF','Yuml':'\\u0178','zacute':'\\u017A','Zacute':'\\u0179','zcaron':'\\u017E','Zcaron':'\\u017D','zcy':'\\u0437','Zcy':'\\u0417','zdot':'\\u017C','Zdot':'\\u017B','zeetrf':'\\u2128','ZeroWidthSpace':'\\u200B','zeta':'\\u03B6','Zeta':'\\u0396','zfr':'\\uD835\\uDD37','Zfr':'\\u2128','zhcy':'\\u0436','ZHcy':'\\u0416','zigrarr':'\\u21DD','zopf':'\\uD835\\uDD6B','Zopf':'\\u2124','zscr':'\\uD835\\uDCCF','Zscr':'\\uD835\\uDCB5','zwj':'\\u200D','zwnj':'\\u200C'};\n\tvar decodeMapLegacy = {'aacute':'\\xE1','Aacute':'\\xC1','acirc':'\\xE2','Acirc':'\\xC2','acute':'\\xB4','aelig':'\\xE6','AElig':'\\xC6','agrave':'\\xE0','Agrave':'\\xC0','amp':'&','AMP':'&','aring':'\\xE5','Aring':'\\xC5','atilde':'\\xE3','Atilde':'\\xC3','auml':'\\xE4','Auml':'\\xC4','brvbar':'\\xA6','ccedil':'\\xE7','Ccedil':'\\xC7','cedil':'\\xB8','cent':'\\xA2','copy':'\\xA9','COPY':'\\xA9','curren':'\\xA4','deg':'\\xB0','divide':'\\xF7','eacute':'\\xE9','Eacute':'\\xC9','ecirc':'\\xEA','Ecirc':'\\xCA','egrave':'\\xE8','Egrave':'\\xC8','eth':'\\xF0','ETH':'\\xD0','euml':'\\xEB','Euml':'\\xCB','frac12':'\\xBD','frac14':'\\xBC','frac34':'\\xBE','gt':'>','GT':'>','iacute':'\\xED','Iacute':'\\xCD','icirc':'\\xEE','Icirc':'\\xCE','iexcl':'\\xA1','igrave':'\\xEC','Igrave':'\\xCC','iquest':'\\xBF','iuml':'\\xEF','Iuml':'\\xCF','laquo':'\\xAB','lt':'<','LT':'<','macr':'\\xAF','micro':'\\xB5','middot':'\\xB7','nbsp':'\\xA0','not':'\\xAC','ntilde':'\\xF1','Ntilde':'\\xD1','oacute':'\\xF3','Oacute':'\\xD3','ocirc':'\\xF4','Ocirc':'\\xD4','ograve':'\\xF2','Ograve':'\\xD2','ordf':'\\xAA','ordm':'\\xBA','oslash':'\\xF8','Oslash':'\\xD8','otilde':'\\xF5','Otilde':'\\xD5','ouml':'\\xF6','Ouml':'\\xD6','para':'\\xB6','plusmn':'\\xB1','pound':'\\xA3','quot':'\"','QUOT':'\"','raquo':'\\xBB','reg':'\\xAE','REG':'\\xAE','sect':'\\xA7','shy':'\\xAD','sup1':'\\xB9','sup2':'\\xB2','sup3':'\\xB3','szlig':'\\xDF','thorn':'\\xFE','THORN':'\\xDE','times':'\\xD7','uacute':'\\xFA','Uacute':'\\xDA','ucirc':'\\xFB','Ucirc':'\\xDB','ugrave':'\\xF9','Ugrave':'\\xD9','uml':'\\xA8','uuml':'\\xFC','Uuml':'\\xDC','yacute':'\\xFD','Yacute':'\\xDD','yen':'\\xA5','yuml':'\\xFF'};\n\tvar decodeMapNumeric = {'0':'\\uFFFD','128':'\\u20AC','130':'\\u201A','131':'\\u0192','132':'\\u201E','133':'\\u2026','134':'\\u2020','135':'\\u2021','136':'\\u02C6','137':'\\u2030','138':'\\u0160','139':'\\u2039','140':'\\u0152','142':'\\u017D','145':'\\u2018','146':'\\u2019','147':'\\u201C','148':'\\u201D','149':'\\u2022','150':'\\u2013','151':'\\u2014','152':'\\u02DC','153':'\\u2122','154':'\\u0161','155':'\\u203A','156':'\\u0153','158':'\\u017E','159':'\\u0178'};\n\tvar invalidReferenceCodePoints = [1,2,3,4,5,6,7,8,11,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,64976,64977,64978,64979,64980,64981,64982,64983,64984,64985,64986,64987,64988,64989,64990,64991,64992,64993,64994,64995,64996,64997,64998,64999,65000,65001,65002,65003,65004,65005,65006,65007,65534,65535,131070,131071,196606,196607,262142,262143,327678,327679,393214,393215,458750,458751,524286,524287,589822,589823,655358,655359,720894,720895,786430,786431,851966,851967,917502,917503,983038,983039,1048574,1048575,1114110,1114111];\n\n\t/*--------------------------------------------------------------------------*/\n\n\tvar stringFromCharCode = String.fromCharCode;\n\n\tvar object = {};\n\tvar hasOwnProperty = object.hasOwnProperty;\n\tvar has = function(object, propertyName) {\n\t\treturn hasOwnProperty.call(object, propertyName);\n\t};\n\n\tvar contains = function(array, value) {\n\t\tvar index = -1;\n\t\tvar length = array.length;\n\t\twhile (++index < length) {\n\t\t\tif (array[index] == value) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t};\n\n\tvar merge = function(options, defaults) {\n\t\tif (!options) {\n\t\t\treturn defaults;\n\t\t}\n\t\tvar result = {};\n\t\tvar key;\n\t\tfor (key in defaults) {\n\t\t\t// A `hasOwnProperty` check is not needed here, since only recognized\n\t\t\t// option names are used anyway. Any others are ignored.\n\t\t\tresult[key] = has(options, key) ? options[key] : defaults[key];\n\t\t}\n\t\treturn result;\n\t};\n\n\t// Modified version of `ucs2encode`; see https://mths.be/punycode.\n\tvar codePointToSymbol = function(codePoint, strict) {\n\t\tvar output = '';\n\t\tif ((codePoint >= 0xD800 && codePoint <= 0xDFFF) || codePoint > 0x10FFFF) {\n\t\t\t// See issue #4:\n\t\t\t// “Otherwise, if the number is in the range 0xD800 to 0xDFFF or is\n\t\t\t// greater than 0x10FFFF, then this is a parse error. Return a U+FFFD\n\t\t\t// REPLACEMENT CHARACTER.”\n\t\t\tif (strict) {\n\t\t\t\tparseError('character reference outside the permissible Unicode range');\n\t\t\t}\n\t\t\treturn '\\uFFFD';\n\t\t}\n\t\tif (has(decodeMapNumeric, codePoint)) {\n\t\t\tif (strict) {\n\t\t\t\tparseError('disallowed character reference');\n\t\t\t}\n\t\t\treturn decodeMapNumeric[codePoint];\n\t\t}\n\t\tif (strict && contains(invalidReferenceCodePoints, codePoint)) {\n\t\t\tparseError('disallowed character reference');\n\t\t}\n\t\tif (codePoint > 0xFFFF) {\n\t\t\tcodePoint -= 0x10000;\n\t\t\toutput += stringFromCharCode(codePoint >>> 10 & 0x3FF | 0xD800);\n\t\t\tcodePoint = 0xDC00 | codePoint & 0x3FF;\n\t\t}\n\t\toutput += stringFromCharCode(codePoint);\n\t\treturn output;\n\t};\n\n\tvar hexEscape = function(codePoint) {\n\t\treturn '&#x' + codePoint.toString(16).toUpperCase() + ';';\n\t};\n\n\tvar decEscape = function(codePoint) {\n\t\treturn '&#' + codePoint + ';';\n\t};\n\n\tvar parseError = function(message) {\n\t\tthrow Error('Parse error: ' + message);\n\t};\n\n\t/*--------------------------------------------------------------------------*/\n\n\tvar encode = function(string, options) {\n\t\toptions = merge(options, encode.options);\n\t\tvar strict = options.strict;\n\t\tif (strict && regexInvalidRawCodePoint.test(string)) {\n\t\t\tparseError('forbidden code point');\n\t\t}\n\t\tvar encodeEverything = options.encodeEverything;\n\t\tvar useNamedReferences = options.useNamedReferences;\n\t\tvar allowUnsafeSymbols = options.allowUnsafeSymbols;\n\t\tvar escapeCodePoint = options.decimal ? decEscape : hexEscape;\n\n\t\tvar escapeBmpSymbol = function(symbol) {\n\t\t\treturn escapeCodePoint(symbol.charCodeAt(0));\n\t\t};\n\n\t\tif (encodeEverything) {\n\t\t\t// Encode ASCII symbols.\n\t\t\tstring = string.replace(regexAsciiWhitelist, function(symbol) {\n\t\t\t\t// Use named references if requested & possible.\n\t\t\t\tif (useNamedReferences && has(encodeMap, symbol)) {\n\t\t\t\t\treturn '&' + encodeMap[symbol] + ';';\n\t\t\t\t}\n\t\t\t\treturn escapeBmpSymbol(symbol);\n\t\t\t});\n\t\t\t// Shorten a few escapes that represent two symbols, of which at least one\n\t\t\t// is within the ASCII range.\n\t\t\tif (useNamedReferences) {\n\t\t\t\tstring = string\n\t\t\t\t\t.replace(/>\\u20D2/g, '>⃒')\n\t\t\t\t\t.replace(/<\\u20D2/g, '<⃒')\n\t\t\t\t\t.replace(/fj/g, 'fj');\n\t\t\t}\n\t\t\t// Encode non-ASCII symbols.\n\t\t\tif (useNamedReferences) {\n\t\t\t\t// Encode non-ASCII symbols that can be replaced with a named reference.\n\t\t\t\tstring = string.replace(regexEncodeNonAscii, function(string) {\n\t\t\t\t\t// Note: there is no need to check `has(encodeMap, string)` here.\n\t\t\t\t\treturn '&' + encodeMap[string] + ';';\n\t\t\t\t});\n\t\t\t}\n\t\t\t// Note: any remaining non-ASCII symbols are handled outside of the `if`.\n\t\t} else if (useNamedReferences) {\n\t\t\t// Apply named character references.\n\t\t\t// Encode `<>\"'&` using named character references.\n\t\t\tif (!allowUnsafeSymbols) {\n\t\t\t\tstring = string.replace(regexEscape, function(string) {\n\t\t\t\t\treturn '&' + encodeMap[string] + ';'; // no need to check `has()` here\n\t\t\t\t});\n\t\t\t}\n\t\t\t// Shorten escapes that represent two symbols, of which at least one is\n\t\t\t// `<>\"'&`.\n\t\t\tstring = string\n\t\t\t\t.replace(/>\\u20D2/g, '>⃒')\n\t\t\t\t.replace(/<\\u20D2/g, '<⃒');\n\t\t\t// Encode non-ASCII symbols that can be replaced with a named reference.\n\t\t\tstring = string.replace(regexEncodeNonAscii, function(string) {\n\t\t\t\t// Note: there is no need to check `has(encodeMap, string)` here.\n\t\t\t\treturn '&' + encodeMap[string] + ';';\n\t\t\t});\n\t\t} else if (!allowUnsafeSymbols) {\n\t\t\t// Encode `<>\"'&` using hexadecimal escapes, now that they’re not handled\n\t\t\t// using named character references.\n\t\t\tstring = string.replace(regexEscape, escapeBmpSymbol);\n\t\t}\n\t\treturn string\n\t\t\t// Encode astral symbols.\n\t\t\t.replace(regexAstralSymbols, function($0) {\n\t\t\t\t// https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae\n\t\t\t\tvar high = $0.charCodeAt(0);\n\t\t\t\tvar low = $0.charCodeAt(1);\n\t\t\t\tvar codePoint = (high - 0xD800) * 0x400 + low - 0xDC00 + 0x10000;\n\t\t\t\treturn escapeCodePoint(codePoint);\n\t\t\t})\n\t\t\t// Encode any remaining BMP symbols that are not printable ASCII symbols\n\t\t\t// using a hexadecimal escape.\n\t\t\t.replace(regexBmpWhitelist, escapeBmpSymbol);\n\t};\n\t// Expose default options (so they can be overridden globally).\n\tencode.options = {\n\t\t'allowUnsafeSymbols': false,\n\t\t'encodeEverything': false,\n\t\t'strict': false,\n\t\t'useNamedReferences': false,\n\t\t'decimal' : false\n\t};\n\n\tvar decode = function(html, options) {\n\t\toptions = merge(options, decode.options);\n\t\tvar strict = options.strict;\n\t\tif (strict && regexInvalidEntity.test(html)) {\n\t\t\tparseError('malformed character reference');\n\t\t}\n\t\treturn html.replace(regexDecode, function($0, $1, $2, $3, $4, $5, $6, $7) {\n\t\t\tvar codePoint;\n\t\t\tvar semicolon;\n\t\t\tvar decDigits;\n\t\t\tvar hexDigits;\n\t\t\tvar reference;\n\t\t\tvar next;\n\t\t\tif ($1) {\n\t\t\t\t// Decode decimal escapes, e.g. `𝌆`.\n\t\t\t\tdecDigits = $1;\n\t\t\t\tsemicolon = $2;\n\t\t\t\tif (strict && !semicolon) {\n\t\t\t\t\tparseError('character reference was not terminated by a semicolon');\n\t\t\t\t}\n\t\t\t\tcodePoint = parseInt(decDigits, 10);\n\t\t\t\treturn codePointToSymbol(codePoint, strict);\n\t\t\t}\n\t\t\tif ($3) {\n\t\t\t\t// Decode hexadecimal escapes, e.g. `𝌆`.\n\t\t\t\thexDigits = $3;\n\t\t\t\tsemicolon = $4;\n\t\t\t\tif (strict && !semicolon) {\n\t\t\t\t\tparseError('character reference was not terminated by a semicolon');\n\t\t\t\t}\n\t\t\t\tcodePoint = parseInt(hexDigits, 16);\n\t\t\t\treturn codePointToSymbol(codePoint, strict);\n\t\t\t}\n\t\t\tif ($5) {\n\t\t\t\t// Decode named character references with trailing `;`, e.g. `©`.\n\t\t\t\treference = $5;\n\t\t\t\tif (has(decodeMap, reference)) {\n\t\t\t\t\treturn decodeMap[reference];\n\t\t\t\t} else {\n\t\t\t\t\t// Ambiguous ampersand. https://mths.be/notes/ambiguous-ampersands\n\t\t\t\t\tif (strict) {\n\t\t\t\t\t\tparseError(\n\t\t\t\t\t\t\t'named character reference was not terminated by a semicolon'\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn $0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If we’re still here, it’s a legacy reference for sure. No need for an\n\t\t\t// extra `if` check.\n\t\t\t// Decode named character references without trailing `;`, e.g. `&`\n\t\t\t// This is only a parse error if it gets converted to `&`, or if it is\n\t\t\t// followed by `=` in an attribute context.\n\t\t\treference = $6;\n\t\t\tnext = $7;\n\t\t\tif (next && options.isAttributeValue) {\n\t\t\t\tif (strict && next == '=') {\n\t\t\t\t\tparseError('`&` did not start a character reference');\n\t\t\t\t}\n\t\t\t\treturn $0;\n\t\t\t} else {\n\t\t\t\tif (strict) {\n\t\t\t\t\tparseError(\n\t\t\t\t\t\t'named character reference was not terminated by a semicolon'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// Note: there is no need to check `has(decodeMapLegacy, reference)`.\n\t\t\t\treturn decodeMapLegacy[reference] + (next || '');\n\t\t\t}\n\t\t});\n\t};\n\t// Expose default options (so they can be overridden globally).\n\tdecode.options = {\n\t\t'isAttributeValue': false,\n\t\t'strict': false\n\t};\n\n\tvar escape = function(string) {\n\t\treturn string.replace(regexEscape, function($0) {\n\t\t\t// Note: there is no need to check `has(escapeMap, $0)` here.\n\t\t\treturn escapeMap[$0];\n\t\t});\n\t};\n\n\t/*--------------------------------------------------------------------------*/\n\n\tvar he = {\n\t\t'version': '1.1.1',\n\t\t'encode': encode,\n\t\t'decode': decode,\n\t\t'escape': escape,\n\t\t'unescape': decode\n\t};\n\n\t// Some AMD build optimizers, like r.js, check for specific condition patterns\n\t// like the following:\n\tif (\n\t\ttypeof define == 'function' &&\n\t\ttypeof define.amd == 'object' &&\n\t\tdefine.amd\n\t) {\n\t\tdefine(function() {\n\t\t\treturn he;\n\t\t});\n\t}\telse if (freeExports && !freeExports.nodeType) {\n\t\tif (freeModule) { // in Node.js, io.js, or RingoJS v0.8.0+\n\t\t\tfreeModule.exports = he;\n\t\t} else { // in Narwhal or RingoJS v0.7.0-\n\t\t\tfor (var key in he) {\n\t\t\t\thas(he, key) && (freeExports[key] = he[key]);\n\t\t\t}\n\t\t}\n\t} else { // in Rhino or a web browser\n\t\troot.he = he;\n\t}\n\n}(this));\n","/*!\n * algorithms/aes-cbc-hmac-sha2.js - AES-CBC-HMAC-SHA2 Composited Encryption\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar helpers = require(\"./helpers.js\"),\n HMAC = require(\"./hmac.js\"),\n sha = require(\"./sha.js\"),\n forge = require(\"../deps/forge.js\"),\n DataBuffer = require(\"../util/databuffer.js\"),\n util = require(\"../util\");\n\nfunction checkIv(iv) {\n if (16 !== iv.length) {\n throw new Error(\"invalid iv\");\n }\n}\n\nfunction commonCbcEncryptFN(size) {\n // ### 'fallback' implementation -- uses forge\n var fallback = function(encKey, pdata, iv) {\n try {\n checkIv(iv);\n } catch (err) {\n return Promise.reject(err);\n }\n\n var promise = Promise.resolve();\n\n promise = promise.then(function() {\n var cipher = forge.cipher.createCipher(\"AES-CBC\", new DataBuffer(encKey));\n cipher.start({\n iv: new DataBuffer(iv)\n });\n\n // TODO: chunk data\n cipher.update(new DataBuffer(pdata));\n if (!cipher.finish()) {\n return Promise.reject(new Error(\"encryption failed\"));\n }\n\n var cdata = Buffer.from(cipher.output.bytes(), \"binary\");\n return cdata;\n });\n\n return promise;\n };\n\n // ### WebCryptoAPI implementation\n // TODO: cache CryptoKey sooner\n var webcrypto = function(encKey, pdata, iv) {\n try {\n checkIv(iv);\n } catch (err) {\n return Promise.reject(err);\n }\n\n var promise = Promise.resolve();\n\n promise = promise.then(function() {\n var alg = {\n name: \"AES-CBC\"\n };\n return helpers.subtleCrypto.importKey(\"raw\", encKey, alg, true, [\"encrypt\"]);\n });\n promise = promise.then(function(key) {\n var alg = {\n name: \"AES-CBC\",\n iv: iv\n };\n return helpers.subtleCrypto.encrypt(alg, key, pdata);\n });\n promise = promise.then(function(cdata) {\n cdata = Buffer.from(cdata);\n return cdata;\n });\n\n return promise;\n };\n\n // ### NodeJS implementation\n var nodejs = function(encKey, pdata, iv) {\n try {\n checkIv(iv);\n } catch (err) {\n return Promise.reject(err);\n }\n\n var promise = Promise.resolve(pdata);\n\n promise = promise.then(function(pdata) {\n var name = \"AES-\" + size + \"-CBC\";\n var cipher = helpers.nodeCrypto.createCipheriv(name, encKey, iv);\n var cdata = Buffer.concat([\n cipher.update(pdata),\n cipher.final()\n ]);\n return cdata;\n });\n\n return promise;\n };\n\n return helpers.setupFallback(nodejs, webcrypto, fallback);\n}\n\nfunction commonCbcDecryptFN(size) {\n // ### 'fallback' implementation -- uses forge\n var fallback = function(encKey, cdata, iv) {\n // validate inputs\n try {\n checkIv(iv);\n } catch (err) {\n return Promise.reject(err);\n }\n\n var promise = Promise.resolve();\n\n promise = promise.then(function() {\n var cipher = forge.cipher.createDecipher(\"AES-CBC\", new DataBuffer(encKey));\n cipher.start({\n iv: new DataBuffer(iv)\n });\n\n // TODO: chunk data\n cipher.update(new DataBuffer(cdata));\n if (!cipher.finish()) {\n return Promise.reject(new Error(\"encryption failed\"));\n }\n\n var pdata = Buffer.from(cipher.output.bytes(), \"binary\");\n return pdata;\n });\n\n return promise;\n };\n\n // ### WebCryptoAPI implementation\n // TODO: cache CryptoKey sooner\n var webcrypto = function(encKey, cdata, iv) {\n // validate inputs\n try {\n checkIv(iv);\n } catch (err) {\n return Promise.reject(err);\n }\n\n var promise = Promise.resolve();\n\n promise = promise.then(function() {\n var alg = {\n name: \"AES-CBC\"\n };\n return helpers.subtleCrypto.importKey(\"raw\", encKey, alg, true, [\"decrypt\"]);\n });\n promise = promise.then(function(key) {\n var alg = {\n name: \"AES-CBC\",\n iv: iv\n };\n return helpers.subtleCrypto.decrypt(alg, key, cdata);\n });\n promise = promise.then(function(pdata) {\n pdata = Buffer.from(pdata);\n return pdata;\n });\n\n return promise;\n };\n\n // ### NodeJS implementation\n var nodejs = function(encKey, cdata, iv) {\n // validate inputs\n try {\n checkIv(iv);\n } catch (err) {\n return Promise.reject(err);\n }\n\n var promise = Promise.resolve();\n\n promise = promise.then(function() {\n var name = \"AES-\" + size + \"-CBC\";\n var cipher = helpers.nodeCrypto.createDecipheriv(name, encKey, iv);\n var pdata = Buffer.concat([\n cipher.update(cdata),\n cipher.final()\n ]);\n return pdata;\n });\n\n return promise;\n };\n\n return helpers.setupFallback(nodejs, webcrypto, fallback);\n}\n\nfunction checkKey(key, size) {\n if ((size << 1) !== (key.length << 3)) {\n throw new Error(\"invalid encryption key size\");\n }\n}\n\nfunction cbcHmacEncryptFN(size) {\n var commonEncrypt = commonCbcEncryptFN(size);\n return function(key, pdata, props) {\n // validate inputs\n try {\n checkKey(key, size);\n } catch (err) {\n return Promise.reject(err);\n }\n\n var eKey = key.slice(size / 8),\n iKey = key.slice(0, size / 8),\n iv = props.iv || Buffer.alloc(0),\n adata = props.aad || props.adata || Buffer.alloc(0);\n\n // STEP 1 -- Encrypt\n var promise = commonEncrypt(eKey, pdata, iv);\n\n // STEP 2 -- MAC\n promise = promise.then(function(cdata){\n var mdata = Buffer.concat([\n adata,\n iv,\n cdata,\n helpers.int64ToBuffer(adata.length * 8)\n ]);\n\n var promise;\n promise = HMAC[\"HS\" + (size * 2)].sign(iKey, mdata, {\n length: size\n });\n promise = promise.then(function(result) {\n // TODO: move slice to hmac.js\n var tag = result.mac.slice(0, size / 8);\n return {\n data: cdata,\n tag: tag\n };\n });\n return promise;\n });\n\n return promise;\n };\n}\n\nfunction cbcHmacDecryptFN(size) {\n var commonDecrypt = commonCbcDecryptFN(size);\n\n return function(key, cdata, props) {\n // validate inputs\n try {\n checkKey(key, size);\n } catch (err) {\n return Promise.reject(err);\n }\n\n var eKey = key.slice(size / 8),\n iKey = key.slice(0, size / 8),\n iv = props.iv || Buffer.alloc(0),\n adata = props.aad || props.adata || Buffer.alloc(0),\n tag = props.tag || props.mac || Buffer.alloc(0);\n\n var promise = Promise.resolve();\n\n // STEP 1 -- MAC\n promise = promise.then(function() {\n var promise;\n // construct MAC input\n var mdata = Buffer.concat([\n adata,\n iv,\n cdata,\n helpers.int64ToBuffer(adata.length * 8)\n ]);\n promise = HMAC[\"HS\" + (size * 2)].verify(iKey, mdata, tag, {\n length: size\n });\n promise = promise.then(function() {\n return cdata;\n }, function() {\n // failure -- invalid tag error\n throw new Error(\"mac check failed\");\n });\n return promise;\n });\n\n // STEP 2 -- Decrypt\n promise = promise.then(function(){\n return commonDecrypt(eKey, cdata, iv);\n });\n\n return promise;\n };\n}\n\nvar EncryptionLabel = Buffer.from(\"Encryption\", \"utf8\");\nvar IntegrityLabel = Buffer.from(\"Integrity\", \"utf8\");\nvar DotLabel = Buffer.from(\".\", \"utf8\");\n\nfunction generateCek(masterKey, alg, epu, epv) {\n var masterSize = masterKey.length * 8;\n var cekSize = masterSize / 2;\n var promise = Promise.resolve();\n\n promise = promise.then(function(){\n var input = Buffer.concat([\n helpers.int32ToBuffer(1),\n masterKey,\n helpers.int32ToBuffer(cekSize),\n Buffer.from(alg, \"utf8\"),\n epu,\n epv,\n EncryptionLabel\n ]);\n\n return input;\n });\n\n promise = promise.then( function(input) {\n return sha[\"SHA-\" + masterSize].digest(input).then(function(digest) {\n return digest.slice(0, cekSize / 8);\n });\n });\n promise = Promise.resolve(promise);\n\n return promise;\n}\n\nfunction generateCik(masterKey, alg, epu, epv) {\n var masterSize = masterKey.length * 8;\n var cikSize = masterSize;\n var promise = Promise.resolve();\n\n promise = promise.then(function(){\n var input = Buffer.concat([\n helpers.int32ToBuffer(1),\n masterKey,\n helpers.int32ToBuffer(cikSize),\n Buffer.from(alg, \"utf8\"),\n epu,\n epv,\n IntegrityLabel\n ]);\n\n return input;\n });\n\n promise = promise.then( function(input) {\n return sha[\"SHA-\" + masterSize].digest(input).then(function(digest) {\n return digest.slice(0, cikSize / 8);\n });\n });\n promise = Promise.resolve(promise);\n\n return promise;\n}\n\nfunction concatKdfCbcHmacEncryptFN(size, alg) {\n var commonEncrypt = commonCbcEncryptFN(size);\n\n return function(key, pdata, props) {\n var epu = props.epu || helpers.int32ToBuffer(0),\n epv = props.epv || helpers.int32ToBuffer(0),\n iv = props.iv || Buffer.alloc(0),\n adata = props.aad || props.adata || Buffer.alloc(0),\n kdata = props.kdata || Buffer.alloc(0);\n\n // Pre Step 1 -- Generate Keys\n var promises = [\n generateCek(key, alg, epu, epv),\n generateCik(key, alg, epu, epv)\n ];\n\n var cek,\n cik;\n var promise = Promise.all(promises).then(function(keys) {\n cek = keys[0];\n cik = keys[1];\n });\n\n // STEP 1 -- Encrypt\n promise = promise.then(function(){\n return commonEncrypt(cek, pdata, iv);\n });\n\n // STEP 2 -- Mac\n promise = promise.then(function(cdata){\n var mdata = Buffer.concat([\n adata,\n DotLabel,\n Buffer.from(kdata),\n DotLabel,\n Buffer.from(util.base64url.encode(iv), \"utf8\"),\n DotLabel,\n Buffer.from(util.base64url.encode(cdata), \"utf8\")\n ]);\n return Promise.all([\n Promise.resolve(cdata),\n HMAC[\"HS\" + (size * 2)].sign(cik, mdata, { length: size })\n ]);\n });\n promise = promise.then(function(result){\n return {\n data: result[0],\n tag: result[1].mac\n };\n });\n\n return promise;\n };\n}\n\nfunction concatKdfCbcHmacDecryptFN(size, alg) {\n var commonDecrypt = commonCbcDecryptFN(size);\n\n return function(key, cdata, props) {\n var epu = props.epu || helpers.int32ToBuffer(0),\n epv = props.epv || helpers.int32ToBuffer(0),\n iv = props.iv || Buffer.alloc(0),\n adata = props.aad || props.adata || Buffer.alloc(0),\n kdata = props.kdata || Buffer.alloc(0),\n tag = props.tag || props.mac || Buffer.alloc(0);\n\n // Pre Step 1 -- Generate Keys\n var promises = [\n generateCek(key, alg, epu, epv),\n generateCik(key, alg, epu, epv)\n ];\n\n var cek,\n cik;\n var promise = Promise.all(promises).then(function(keys){\n cek = keys[0];\n cik = keys[1];\n });\n\n\n // STEP 1 -- MAC\n promise = promise.then(function() {\n // construct MAC input\n var mdata = Buffer.concat([\n adata,\n DotLabel,\n Buffer.from(kdata),\n DotLabel,\n Buffer.from(util.base64url.encode(iv), \"utf8\"),\n DotLabel,\n Buffer.from(util.base64url.encode(cdata), \"utf8\")\n ]);\n\n try {\n return HMAC[\"HS\" + (size * 2)].verify(cik, mdata, tag, {\n loose: false\n });\n } catch (e) {\n throw new Error(\"mac check failed\");\n }\n });\n\n // STEP 2 -- Decrypt\n promise = promise.then(function(){\n return commonDecrypt(cek, cdata, iv);\n });\n\n return promise;\n };\n}\n\n// ### Public API\n// * [name].encrypt\n// * [name].decrypt\nvar aesCbcHmacSha2 = {};\n[\n \"A128CBC-HS256\",\n \"A192CBC-HS384\",\n \"A256CBC-HS512\"\n].forEach(function(alg) {\n var size = parseInt(/A(\\d+)CBC-HS(\\d+)?/g.exec(alg)[1]);\n aesCbcHmacSha2[alg] = {\n encrypt: cbcHmacEncryptFN(size),\n decrypt: cbcHmacDecryptFN(size)\n };\n});\n\n[\n \"A128CBC+HS256\",\n \"A192CBC+HS384\",\n \"A256CBC+HS512\"\n].forEach(function(alg) {\n var size = parseInt(/A(\\d+)CBC\\+HS(\\d+)?/g.exec(alg)[1]);\n aesCbcHmacSha2[alg] = {\n encrypt: concatKdfCbcHmacEncryptFN(size, alg),\n decrypt: concatKdfCbcHmacDecryptFN(size, alg)\n };\n});\n\nmodule.exports = aesCbcHmacSha2;\n","/*!\n * algorithms/aes-gcm.js - AES-GCM Encryption and Key-Wrapping\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar helpers = require(\"./helpers.js\"),\n util = require(\"../util\"),\n CONSTANTS = require(\"./constants.js\"),\n GCM = require(\"../deps/ciphermodes/gcm\");\n\nfunction gcmEncryptFN(size, wrap) {\n function commonChecks(key, iv) {\n if (size !== (key.length << 3)) {\n throw new Error(\"invalid key size\");\n }\n if (!iv && !wrap) {\n throw new Error(\"invalid iv\");\n }\n if (iv && 12 !== iv.length) {\n throw new Error(\"invalid iv\");\n }\n }\n\n function prepareResults(results) {\n if (wrap) {\n var iv = util.base64url.encode(results.iv);\n var tag = util.base64url.encode(results.tag);\n\n results = {\n data: results.data,\n header: {\n iv: iv,\n tag: tag\n }\n };\n }\n\n return results;\n }\n\n // ### 'fallback' implementation -- uses forge\n var fallback = function(key, pdata, props) {\n var iv = props.iv,\n adata = props.aad || props.adata || Buffer.alloc(0),\n cipher,\n cdata;\n\n // validate inputs\n try {\n commonChecks(key, iv, adata);\n } catch (err) {\n return Promise.reject(err);\n }\n\n iv = iv || util.randomBytes(12);\n\n // setup cipher\n cipher = GCM.createCipher({\n key: key,\n iv: iv,\n additionalData: adata\n });\n // ciphertext is the same length as plaintext\n cdata = Buffer.alloc(pdata.length);\n\n var promise = new Promise(function(resolve, reject) {\n var amt = CONSTANTS.CHUNK_SIZE,\n clen = 0,\n poff = 0;\n\n (function doChunk() {\n var plen = Math.min(amt, pdata.length - poff);\n clen += cipher.update(pdata,\n poff,\n plen,\n cdata,\n clen);\n poff += plen;\n if (pdata.length > poff) {\n setTimeout(doChunk, 0);\n return;\n }\n\n // finish it\n clen += cipher.finish(cdata, clen);\n if (clen !== pdata.length) {\n reject(new Error(\"encryption failed\"));\n return;\n }\n\n // resolve with output\n var tag = cipher.tag;\n resolve(prepareResults({\n data: cdata,\n iv: iv,\n tag: tag\n }));\n })();\n });\n\n return promise;\n };\n\n // ### WebCryptoAPI implementation\n // TODO: cache CryptoKey sooner\n var webcrypto = function(key, pdata, props) {\n var iv = props.iv,\n adata = props.aad || props.adata || Buffer.alloc(0);\n\n try {\n commonChecks(key, iv, adata);\n } catch (err) {\n return Promise.reject(err);\n }\n\n iv = iv || util.randomBytes(12);\n\n var alg = {\n name: \"AES-GCM\"\n };\n var promise;\n promise = helpers.subtleCrypto.importKey(\"raw\", key, alg, true, [\"encrypt\"]);\n promise = promise.then(function(key) {\n alg.iv = iv;\n alg.tagLength = 128;\n if (adata.length) {\n alg.additionalData = adata;\n }\n\n return helpers.subtleCrypto.encrypt(alg, key, pdata);\n });\n promise = promise.then(function(result) {\n var tagStart = result.byteLength - 16;\n\n var tag = result.slice(tagStart);\n tag = Buffer.from(tag);\n\n var cdata = result.slice(0, tagStart);\n cdata = Buffer.from(cdata);\n\n return prepareResults({\n data: cdata,\n iv: iv,\n tag: tag\n });\n });\n\n return promise;\n };\n\n // ### NodeJS implementation\n var nodejs = function(key, pdata, props) {\n var iv = props.iv,\n adata = props.aad || props.adata || Buffer.alloc(0);\n\n try {\n commonChecks(key, iv, adata);\n } catch (err) {\n return Promise.reject(err);\n }\n\n iv = iv || util.randomBytes(12);\n\n var alg = \"aes-\" + (key.length * 8) + \"-gcm\";\n var cipher;\n try {\n cipher = helpers.nodeCrypto.createCipheriv(alg, key, iv);\n } catch (err) {\n throw new Error(\"unsupported algorithm: \" + alg);\n }\n if (\"function\" !== typeof cipher.setAAD) {\n throw new Error(\"unsupported algorithm: \" + alg);\n }\n if (adata.length) {\n cipher.setAAD(adata);\n }\n\n var cdata = Buffer.concat([\n cipher.update(pdata),\n cipher.final()\n ]);\n var tag = cipher.getAuthTag();\n\n return prepareResults({\n data: cdata,\n iv: iv,\n tag: tag\n });\n };\n\n return helpers.setupFallback(nodejs, webcrypto, fallback);\n}\n\nfunction gcmDecryptFN(size) {\n function commonChecks(key, iv, tag) {\n if (size !== (key.length << 3)) {\n throw new Error(\"invalid key size\");\n }\n if (12 !== iv.length) {\n throw new Error(\"invalid iv\");\n }\n if (16 !== tag.length) {\n throw new Error(\"invalid tag length\");\n }\n }\n\n // ### fallback implementation -- uses forge\n var fallback = function(key, cdata, props) {\n var adata = props.aad || props.adata || Buffer.alloc(0),\n iv = props.iv || Buffer.alloc(0),\n tag = props.tag || props.mac || Buffer.alloc(0),\n cipher,\n pdata;\n\n // validate inputs\n try {\n commonChecks(key, iv, tag);\n } catch (err) {\n return Promise.reject(err);\n }\n\n // setup cipher\n cipher = GCM.createDecipher({\n key: key,\n iv: iv,\n additionalData: adata,\n tag: tag\n });\n // plaintext is the same length as ciphertext\n pdata = Buffer.alloc(cdata.length);\n\n var promise = new Promise(function(resolve, reject) {\n var amt = CONSTANTS.CHUNK_SIZE,\n plen = 0,\n coff = 0;\n\n (function doChunk() {\n var clen = Math.min(amt, cdata.length - coff);\n plen += cipher.update(cdata,\n coff,\n clen,\n pdata,\n plen);\n coff += clen;\n if (cdata.length > coff) {\n setTimeout(doChunk, 0);\n return;\n }\n\n try {\n plen += cipher.finish(pdata, plen);\n } catch (err) {\n reject(new Error(\"decryption failed\"));\n return;\n }\n\n if (plen !== cdata.length) {\n reject(new Error(\"decryption failed\"));\n return;\n }\n\n // resolve with output\n resolve(pdata);\n })();\n });\n\n return promise;\n };\n\n // ### WebCryptoAPI implementation\n // TODO: cache CryptoKey sooner\n var webcrypto = function(key, cdata, props) {\n var adata = props.aad || props.adata || Buffer.alloc(0),\n iv = props.iv || Buffer.alloc(0),\n tag = props.tag || props.mac || Buffer.alloc(0);\n\n // validate inputs\n try {\n commonChecks(key, iv, tag);\n } catch (err) {\n return Promise.reject(err);\n }\n\n var alg = {\n name: \"AES-GCM\"\n };\n var promise;\n promise = helpers.subtleCrypto.importKey(\"raw\", key, alg, true, [\"decrypt\"]);\n promise = promise.then(function(key) {\n alg.iv = iv;\n alg.tagLength = 128;\n if (adata.length) {\n alg.additionalData = adata;\n }\n\n // concatenate cdata and tag\n cdata = Buffer.concat([cdata, tag], cdata.length + tag.length);\n\n return helpers.subtleCrypto.decrypt(alg, key, cdata);\n });\n promise = promise.then(function(pdata) {\n pdata = Buffer.from(pdata);\n return pdata;\n });\n\n return promise;\n };\n\n var nodejs = function(key, cdata, props) {\n var adata = props.aad || props.adata || Buffer.alloc(0),\n iv = props.iv || Buffer.alloc(0),\n tag = props.tag || props.mac || Buffer.alloc(0);\n\n // validate inputs\n try {\n commonChecks(key, iv, tag);\n } catch (err) {\n return Promise.reject(err);\n }\n\n var alg = \"aes-\" + (key.length * 8) + \"-gcm\";\n var cipher;\n try {\n cipher = helpers.nodeCrypto.createDecipheriv(alg, key, iv);\n } catch(err) {\n throw new Error(\"unsupported algorithm: \" + alg);\n }\n if (\"function\" !== typeof cipher.setAAD) {\n throw new Error(\"unsupported algorithm: \" + alg);\n }\n cipher.setAuthTag(tag);\n if (adata.length) {\n cipher.setAAD(adata);\n }\n\n try {\n var pdata = Buffer.concat([\n cipher.update(cdata),\n cipher.final()\n ]);\n\n return pdata;\n } catch (err) {\n throw new Error(\"decryption failed\");\n }\n };\n\n return helpers.setupFallback(nodejs, webcrypto, fallback);\n}\n\n// ### Public API\n// * [name].encrypt\n// * [name].decrypt\nvar aesGcm = {};\n[\n \"A128GCM\",\n \"A192GCM\",\n \"A256GCM\",\n \"A128GCMKW\",\n \"A192GCMKW\",\n \"A256GCMKW\"\n].forEach(function(alg) {\n var parts = /A(\\d+)GCM(KW)?/g.exec(alg);\n var size = parseInt(parts[1]);\n var wrap = (parts[2] === \"KW\");\n aesGcm[alg] = {\n encrypt: gcmEncryptFN(size, wrap),\n decrypt: gcmDecryptFN(size, wrap)\n };\n});\n\nmodule.exports = aesGcm;\n","/*!\n * algorithms/aes-kw.js - AES-KW Key-Wrapping\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar helpers = require(\"./helpers.js\"),\n forge = require(\"../deps/forge.js\"),\n DataBuffer = require(\"../util/databuffer.js\");\n\nvar A0 = Buffer.from(\"a6a6a6a6a6a6a6a6\", \"hex\");\n\n// ### helpers\nfunction xor(a, b) {\n var len = Math.max(a.length, b.length);\n var result = Buffer.alloc(len);\n for (var idx = 0; len > idx; idx++) {\n result[idx] = (a[idx] || 0) ^ (b[idx] || 0);\n }\n return result;\n}\n\nfunction split(input, size) {\n var output = [];\n for (var idx = 0; input.length > idx; idx += size) {\n output.push(input.slice(idx, idx + size));\n }\n return output;\n}\n\nfunction longToBigEndian(input) {\n var hi = Math.floor(input / 4294967296),\n lo = input % 4294967296;\n var output = Buffer.alloc(8);\n output[0] = 0xff & (hi >>> 24);\n output[1] = 0xff & (hi >>> 16);\n output[2] = 0xff & (hi >>> 8);\n output[3] = 0xff & (hi >>> 0);\n output[4] = 0xff & (lo >>> 24);\n output[5] = 0xff & (lo >>> 16);\n output[6] = 0xff & (lo >>> 8);\n output[7] = 0xff & (lo >>> 0);\n return output;\n}\n\nfunction kwEncryptFN(size) {\n function commonChecks(key, data) {\n if (size !== (key.length << 3)) {\n throw new Error(\"invalid key size\");\n }\n if (0 < data.length && 0 !== (data.length % 8)) {\n throw new Error(\"invalid data length\");\n }\n }\n\n // ### 'fallback' implementation -- uses forge\n var fallback = function(key, pdata) {\n try {\n commonChecks(key, pdata);\n } catch (err) {\n return Promise.reject(err);\n }\n\n // setup cipher\n var cipher = forge.cipher.createCipher(\"AES\", new DataBuffer(key));\n\n // split input into chunks\n var R = split(pdata, 8);\n var A,\n B,\n count;\n A = A0;\n for (var jdx = 0; 6 > jdx; jdx++) {\n for (var idx = 0; R.length > idx; idx++) {\n count = (R.length * jdx) + idx + 1;\n B = Buffer.concat([A, R[idx]]);\n cipher.start();\n cipher.update(new DataBuffer(B));\n cipher.finish();\n B = Buffer.from(cipher.output.bytes(), \"binary\");\n\n A = xor(B.slice(0, 8),\n longToBigEndian(count));\n R[idx] = B.slice(8, 16);\n }\n }\n R = [A].concat(R);\n var cdata = Buffer.concat(R);\n return Promise.resolve({\n data: cdata\n });\n };\n // ### WebCryptoAPI implementation\n var webcrypto = function(key, pdata) {\n try {\n commonChecks(key, pdata);\n } catch (err) {\n return Promise.reject(err);\n }\n\n var alg = {\n name: \"AES-KW\"\n };\n var promise = [\n helpers.subtleCrypto.importKey(\"raw\", pdata, { name: \"HMAC\", hash: \"SHA-256\" }, true, [\"sign\"]),\n helpers.subtleCrypto.importKey(\"raw\", key, alg, true, [\"wrapKey\"])\n ];\n promise = Promise.all(promise);\n promise = promise.then(function(keys) {\n return helpers.subtleCrypto.wrapKey(\"raw\",\n keys[0], // key\n keys[1], // wrappingKey\n alg);\n });\n promise = promise.then(function(result) {\n result = Buffer.from(result);\n\n return {\n data: result\n };\n });\n return promise;\n };\n var node = function(key, pdata) {\n try {\n commonChecks(key, pdata);\n } catch (err) {\n return Promise.reject(err);\n }\n\n // split input into chunks\n var R = split(pdata, 8),\n iv = Buffer.alloc(16);\n var A,\n B,\n count;\n A = A0;\n for (var jdx = 0; 6 > jdx; jdx++) {\n for (var idx = 0; R.length > idx; idx++) {\n count = (R.length * jdx) + idx + 1;\n B = Buffer.concat([A, R[idx]]);\n var cipher = helpers.nodeCrypto.createCipheriv(\"AES\" + size, key, iv);\n B = cipher.update(B);\n\n A = xor(B.slice(0, 8),\n longToBigEndian(count));\n R[idx] = B.slice(8, 16);\n }\n }\n R = [A].concat(R);\n var cdata = Buffer.concat(R);\n return Promise.resolve({\n data: cdata\n });\n };\n\n return helpers.setupFallback(node, webcrypto, fallback);\n}\nfunction kwDecryptFN(size) {\n function commonChecks(key, data) {\n if (size !== (key.length << 3)) {\n throw new Error(\"invalid key size\");\n }\n if (0 < (data.length - 8) && 0 !== (data.length % 8)) {\n throw new Error(\"invalid data length\");\n }\n }\n\n // ### 'fallback' implementation -- uses forge\n var fallback = function(key, cdata) {\n try {\n commonChecks(key, cdata);\n } catch (err) {\n return Promise.reject(err);\n }\n\n // setup cipher\n var cipher = forge.cipher.createDecipher(\"AES\", new DataBuffer(key));\n\n // prepare inputs\n var R = split(cdata, 8),\n A,\n B,\n count;\n A = R[0];\n R = R.slice(1);\n for (var jdx = 5; 0 <= jdx; --jdx) {\n for (var idx = R.length - 1; 0 <= idx; --idx) {\n count = (R.length * jdx) + idx + 1;\n B = xor(A,\n longToBigEndian(count));\n B = Buffer.concat([B, R[idx]]);\n cipher.start();\n cipher.update(new DataBuffer(B));\n cipher.finish();\n B = Buffer.from(cipher.output.bytes(), \"binary\");\n\n A = B.slice(0, 8);\n R[idx] = B.slice(8, 16);\n }\n }\n if (A.toString() !== A0.toString()) {\n return Promise.reject(new Error(\"decryption failed\"));\n }\n var pdata = Buffer.concat(R);\n return Promise.resolve(pdata);\n };\n // ### WebCryptoAPI implementation\n var webcrypto = function(key, cdata) {\n try {\n commonChecks(key, cdata);\n } catch (err) {\n return Promise.reject(err);\n }\n\n var alg = {\n name: \"AES-KW\"\n };\n var promise = helpers.subtleCrypto.importKey(\"raw\", key, alg, true, [\"unwrapKey\"]);\n promise = promise.then(function(key) {\n return helpers.subtleCrypto.unwrapKey(\"raw\", cdata, key, alg, {name: \"HMAC\", hash: \"SHA-256\"}, true, [\"sign\"]);\n });\n promise = promise.then(function(result) {\n // unwrapped CryptoKey -- extract raw\n return helpers.subtleCrypto.exportKey(\"raw\", result);\n });\n promise = promise.then(function(result) {\n result = Buffer.from(result);\n return result;\n });\n return promise;\n };\n var node = function(key, cdata) {\n try {\n commonChecks(key, cdata);\n } catch (err) {\n return Promise.reject(err);\n }\n\n // prepare inputs\n var R = split(cdata, 8),\n iv = Buffer.alloc(16),\n A,\n B,\n count;\n A = R[0];\n R = R.slice(1);\n for (var jdx = 5; 0 <= jdx; --jdx) {\n for (var idx = R.length - 1; 0 <= idx; --idx) {\n count = (R.length * jdx) + idx + 1;\n B = xor(A,\n longToBigEndian(count));\n B = Buffer.concat([B, R[idx], iv]);\n var cipher = helpers.nodeCrypto.createDecipheriv(\"AES\" + size, key, iv);\n B = cipher.update(B);\n\n A = B.slice(0, 8);\n R[idx] = B.slice(8, 16);\n }\n }\n if (A.toString() !== A0.toString()) {\n return Promise.reject(new Error(\"decryption failed\"));\n }\n var pdata = Buffer.concat(R);\n return Promise.resolve(pdata);\n };\n\n return helpers.setupFallback(node, webcrypto, fallback);\n}\n\n// ### Public API\n// * [name].encrypt\n// * [name].decrypt\nvar aesKw = {};\n[\n \"A128KW\",\n \"A192KW\",\n \"A256KW\"\n].forEach(function(alg) {\n var size = parseInt(/A(\\d+)KW/g.exec(alg)[1]);\n aesKw[alg] = {\n encrypt: kwEncryptFN(size),\n decrypt: kwDecryptFN(size)\n };\n});\n\nmodule.exports = aesKw;\n","/*!\n * algorithms/concat.js - Concat Key Derivation\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar CONSTANTS = require(\"./constants.js\"),\n sha = require(\"./sha.js\");\n\nfunction concatDeriveFn(name) {\n name = name.replace(\"CONCAT-\", \"\");\n\n // NOTE: no nodejs/webcrypto/fallback model, since ConcatKDF is\n // implemented using the SHA algorithms\n\n var fn = function(key, props) {\n props = props || {};\n\n var keyLen = props.length,\n hashLen = CONSTANTS.HASHLENGTH[name];\n if (!keyLen) {\n return Promise.reject(new Error(\"invalid key length\"));\n }\n\n // setup otherInfo\n if (!props.otherInfo) {\n return Promise.reject(new Error(\"invalid otherInfo\"));\n }\n var otherInfo = props.otherInfo;\n\n var op = sha[name].digest;\n var N = Math.ceil(keyLen / hashLen),\n idx = 0,\n okm = [];\n function step() {\n if (N === idx++) {\n return Buffer.concat(okm).slice(0, keyLen);\n }\n\n var T = Buffer.alloc(4 + key.length + otherInfo.length);\n T.writeUInt32BE(idx, 0);\n key.copy(T, 4);\n otherInfo.copy(T, 4 + key.length);\n return op(T).then(function(result) {\n okm.push(result);\n return step();\n });\n }\n\n return step();\n };\n\n return fn;\n}\n\n// Public API\n// * [name].derive\nvar concat = {};\n[\n \"CONCAT-SHA-1\",\n \"CONCAT-SHA-256\",\n \"CONCAT-SHA-384\",\n \"CONCAT-SHA-512\"\n].forEach(function(name) {\n concat[name] = {\n derive: concatDeriveFn(name)\n };\n});\n\nmodule.exports = concat;\n","/*!\n * algorithms/constants.js - Constants used in Cryptographic Algorithms\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n \"use strict\";\n\nmodule.exports = {\n CHUNK_SIZE: 1024,\n HASHLENGTH: {\n \"SHA-1\": 160,\n \"SHA-256\": 256,\n \"SHA-384\": 384,\n \"SHA-512\": 512\n },\n ENCLENGTH: {\n \"AES-128-CBC\": 128,\n \"AES-192-CBC\": 192,\n \"AES-256-CBC\": 256,\n \"AES-128-KW\": 128,\n \"AES-192-KW\": 192,\n \"AES-256-KW\": 256\n },\n KEYLENGTH: {\n \"A128CBC-HS256\": 256,\n \"A192CBC-HS384\": 384,\n \"A256CBC-HS512\": 512,\n \"A128CBC+HS256\": 256,\n \"A192CBC+HS384\": 384,\n \"A256CBC+HS512\": 512,\n \"A128GCM\": 128,\n \"A192GCM\": 192,\n \"A256GCM\": 256,\n \"A128KW\": 128,\n \"A192KW\": 192,\n \"A256KW\": 256,\n \"ECDH-ES+A128KW\": 128,\n \"ECDH-ES+A192KW\": 192,\n \"ECDH-ES+A256KW\": 256\n },\n NONCELENGTH: {\n \"A128CBC-HS256\": 128,\n \"A192CBC-HS384\": 128,\n \"A256CBC-HS512\": 128,\n \"A128CBC+HS256\": 128,\n \"A192CBC+HS384\": 128,\n \"A256CBC+HS512\": 128,\n \"A128GCM\": 96,\n \"A192GCM\": 96,\n \"A256GCM\": 96\n }\n};\n","/*!\n * algorithms/dir.js - Direct key mode\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nfunction dirEncryptFN(key) {\n // NOTE: pdata unused\n // NOTE: props unused\n return Promise.resolve({\n data: key,\n once: true,\n direct: true\n });\n}\nfunction dirDecryptFN(key) {\n // NOTE: pdata unused\n // NOTE: props unused\n return Promise.resolve(key);\n}\n\n// ### Public API\n// * [name].encrypt\n// * [name].decrypt\nvar direct = {\n dir: {\n encrypt: dirEncryptFN,\n decrypt: dirDecryptFN\n }\n};\n\nmodule.exports = direct;\n","/*!\n * algorithms/ec-util.js - Elliptic Curve Utility Functions\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar clone = require(\"lodash/clone\"),\n ecc = require(\"../deps/ecc\"),\n forge = require(\"../deps/forge.js\"),\n util = require(\"../util\");\n\nvar EC_KEYSIZES = {\n \"P-256\": 256,\n \"P-384\": 384,\n \"P-521\": 521\n};\n\nfunction convertToForge(key, isPublic) {\n var parts = isPublic ?\n [\"x\", \"y\"] :\n [\"d\"];\n parts = parts.map(function(f) {\n return new forge.jsbn.BigInteger(key[f].toString(\"hex\"), 16);\n });\n // prefix with curve\n parts = [key.crv].concat(parts);\n var fn = isPublic ?\n ecc.asPublicKey :\n ecc.asPrivateKey;\n return fn.apply(ecc, parts);\n}\n\nfunction convertToJWK(key, isPublic) {\n var result = clone(key);\n var parts = isPublic ?\n [\"x\", \"y\"] :\n [\"x\", \"y\", \"d\"];\n parts.forEach(function(f) {\n result[f] = util.base64url.encode(result[f]);\n });\n\n // remove potentially troublesome properties\n delete result.key_ops;\n delete result.use;\n delete result.alg;\n\n if (isPublic) {\n delete result.d;\n }\n\n return result;\n}\n\nfunction convertToObj(key, isPublic) {\n var result = clone(key);\n var parts = isPublic ?\n [\"x\", \"y\"] :\n [\"d\"];\n parts.forEach(function(f) {\n // assume string if base64url-encoded\n result[f] = util.asBuffer(result[f], \"base64url\");\n });\n\n return result;\n}\n\nvar UNCOMPRESSED = Buffer.from([0x04]);\nfunction convertToBuffer(key, isPublic) {\n key = convertToObj(key, isPublic);\n var result = isPublic ?\n Buffer.concat([UNCOMPRESSED, key.x, key.y]) :\n key.d;\n return result;\n}\n\nfunction curveSize(crv) {\n return EC_KEYSIZES[crv || \"\"] || NaN;\n}\n\nfunction curveNameToOid(crv) {\n switch (crv) {\n case \"P-256\":\n return \"1.2.840.10045.3.1.7\";\n case \"P-384\":\n return \"1.3.132.0.34\";\n case \"P-521\":\n return \"1.3.132.0.35\";\n default:\n return null;\n }\n}\n\nvar EC_OID = \"1.2.840.10045.2.1\";\nfunction convertToPEM(key, isPrivate) {\n // curveName to OID\n var oid = key.crv;\n oid = curveNameToOid(oid);\n oid = forge.asn1.oidToDer(oid);\n // key as bytes\n var type,\n pub,\n asn1;\n if (isPrivate) {\n type = \"EC PRIVATE KEY\";\n pub = Buffer.concat([\n Buffer.from([0x00, 0x04]),\n key.x,\n key.y\n ]).toString(\"binary\");\n key = key.d.toString(\"binary\");\n asn1 = forge.asn1.create(forge.asn1.Class.UNIVERSAL, forge.asn1.Type.SEQUENCE, true, [\n forge.asn1.create(forge.asn1.Class.UNIVERSAL, forge.asn1.Type.INTEGER, false, \"\\u0001\"),\n forge.asn1.create(forge.asn1.Class.UNIVERSAL, forge.asn1.Type.OCTETSTRING, false, key),\n forge.asn1.create(forge.asn1.Class.CONTEXT_SPECIFIC, 0, true, [\n forge.asn1.create(forge.asn1.Class.UNIVERSAL, forge.asn1.Type.OID, false, oid.bytes())\n ]),\n forge.asn1.create(forge.asn1.Class.CONTEXT_SPECIFIC, 1, true, [\n forge.asn1.create(forge.asn1.Class.UNIVERSAL, forge.asn1.Type.BITSTRING, false, pub)\n ])\n ]);\n } else {\n type = \"PUBLIC KEY\";\n key = Buffer.concat([\n Buffer.from([0x00, 0x04]),\n key.x,\n key.y\n ]).toString(\"binary\");\n asn1 = forge.asn1.create(forge.asn1.Class.UNIVERSAL, forge.asn1.Type.SEQUENCE, true, [\n forge.asn1.create(forge.asn1.Class.UNIVERSAL, forge.asn1.Type.SEQUENCE, true, [\n forge.asn1.create(forge.asn1.Class.UNIVERSAL, forge.asn1.Type.OID, false, forge.asn1.oidToDer(EC_OID).bytes()),\n forge.asn1.create(forge.asn1.Class.UNIVERSAL, forge.asn1.Type.OID, false, oid.bytes())\n ]),\n forge.asn1.create(forge.asn1.Class.UNIVERSAL, forge.asn1.Type.BITSTRING, false, key)\n ]);\n }\n asn1 = forge.asn1.toDer(asn1).bytes();\n var pem = forge.pem.encode({\n type: type,\n body: asn1\n });\n return pem;\n}\n\n// Inspired by teifip/node-webtokens/blob/master/lib/ecdsa.js\nvar ERR_MSG = \"Could not extract parameters from DER signature\";\nfunction derToConcat(signature, size) {\n var offset = 0;\n if (signature[offset++] !== 0x30) {\n throw new Error(ERR_MSG);\n }\n var seqLength = signature[offset++];\n if (seqLength === 0x81) {\n seqLength = signature[offset++];\n }\n if (seqLength > signature.length - offset) {\n throw new Error(ERR_MSG);\n }\n if (signature[offset++] !== 0x02) {\n throw new Error(ERR_MSG);\n }\n var rLength = signature[offset++];\n if (rLength > signature.length - offset - 2) {\n throw new Error(ERR_MSG);\n }\n if (rLength > size + 1) {\n throw new Error(ERR_MSG);\n }\n var rOffset = offset;\n offset += rLength;\n if (signature[offset++] !== 0x02) {\n throw new Error(ERR_MSG);\n }\n var sLength = signature[offset++];\n if (sLength !== signature.length - offset) {\n throw new Error(ERR_MSG);\n }\n if (sLength > size + 1) {\n throw new Error(ERR_MSG);\n }\n var sOffset = offset;\n offset += sLength;\n if (offset !== signature.length) {\n throw new Error(ERR_MSG);\n }\n var rPadding = size - rLength;\n var sPadding = size - sLength;\n var dst = Buffer.alloc(rPadding + rLength + sPadding + sLength);\n for (offset = 0; offset < rPadding; ++offset) {\n dst[offset] = 0;\n }\n var rPad = Math.max(-rPadding, 0);\n signature.copy(dst, offset, rOffset + rPad, rOffset + rLength);\n offset = size;\n for (var o = offset; offset < o + sPadding; ++offset) {\n dst[offset] = 0;\n }\n var sPad = Math.max(-sPadding, 0);\n signature.copy(dst, offset, sOffset + sPad, sOffset + sLength);\n return dst;\n}\n\nfunction countPadding(buf, start, stop) {\n var padding = 0;\n while (start + padding < stop && buf[start + padding] === 0) {\n ++padding;\n }\n var needsSign = buf[start + padding] >= 0x80;\n if (needsSign) {\n --padding;\n }\n return padding;\n}\n\nfunction concatToDer(signature, size) {\n var rPadding = countPadding(signature, 0, size);\n var sPadding = countPadding(signature, size, signature.length);\n var rLength = size - rPadding;\n var sLength = size - sPadding;\n var rsBytes = rLength + sLength + 4;\n var shortLength = rsBytes < 0x80;\n var dst = Buffer.alloc((shortLength ? 2 : 3) + rsBytes);\n var offset = 0;\n dst[offset++] = 0x30;\n if (shortLength) {\n dst[offset++] = rsBytes;\n } else {\n dst[offset++] = 0x81;\n dst[offset++] = rsBytes & 0xFF;\n }\n dst[offset++] = 0x02;\n dst[offset++] = rLength;\n if (rPadding < 0) {\n dst[offset++] = 0;\n offset += signature.copy(dst, offset, 0, size);\n } else {\n offset += signature.copy(dst, offset, rPadding, size);\n }\n dst[offset++] = 0x02;\n dst[offset++] = sLength;\n if (sPadding < 0) {\n dst[offset++] = 0;\n signature.copy(dst, offset, size);\n } else {\n signature.copy(dst, offset, size + sPadding);\n }\n return dst;\n}\n\nmodule.exports = {\n convertToForge: convertToForge,\n convertToJWK: convertToJWK,\n convertToObj: convertToObj,\n convertToBuffer: convertToBuffer,\n curveSize: curveSize,\n derToConcat: derToConcat,\n concatToDer: concatToDer,\n convertToPEM: convertToPEM,\n EC_OID: EC_OID\n};\n","/*!\n * algorithms/ecdh.js - Elliptic Curve Diffie-Hellman algorithms\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar merge = require(\"../util/merge\"),\n util = require(\"../util\"),\n ecUtil = require(\"./ec-util.js\"),\n hkdf = require(\"./hkdf.js\"),\n concat = require(\"./concat.js\"),\n aesKw = require(\"./aes-kw.js\"),\n helpers = require(\"./helpers.js\"),\n CONSTANTS = require(\"./constants.js\");\n\nvar clone = require(\"lodash/clone\");\nvar omit = require(\"lodash/omit\");\nvar pick = require(\"lodash/pick\");\n\nfunction idealHash(curve) {\n switch (curve) {\n case \"P-256\":\n return \"SHA-256\";\n case \"P-384\":\n return \"SHA-384\";\n case \"P-521\":\n return \"SHA-512\";\n default:\n throw new Error(\"unsupported curve: \" + curve);\n }\n}\n\n// ### Exported\nvar ecdh = module.exports = {};\n\n// ### Derivation algorithms\n// ### \"raw\" ECDH\nfunction ecdhDeriveFn() {\n var alg = {\n name: \"ECDH\"\n };\n\n var validatePublic = function(pk, form) {\n var pubKey = pk && ecUtil.convertToForge(pk, true);\n if (!pubKey || !pubKey.isValid()) {\n return Promise.reject(new Error(\"invalid EC public key\"));\n }\n\n switch (form) {\n case \"jwk\":\n pubKey = ecUtil.convertToJWK(pk, true);\n break;\n case \"buffer\":\n pubKey = ecUtil.convertToBuffer(pk, true);\n break;\n }\n return Promise.resolve(pubKey);\n }\n\n // ### fallback implementation -- uses ecc + forge\n var fallback = function(key, props) {\n props = props || {};\n var keyLen = props.length || 0;\n // assume {key} is privateKey\n // assume {props.public} is publicKey\n var privKey = ecUtil.convertToForge(key, false);\n\n var p = validatePublic(props.public, \"forge\");\n p = p.then(function(pubKey) {\n // {pubKey} is \"forge\"\n\n var secret = privKey.computeSecret(pubKey);\n if (keyLen) {\n // truncate to requested key length\n if (secret.length < keyLen) {\n return Promise.reject(new Error(\"key length too large: \" + keyLen));\n }\n secret = secret.slice(0, keyLen);\n }\n\n return secret;\n });\n return p;\n };\n\n // ### WebCryptoAPI implementation\n // TODO: cache CryptoKey sooner\n var webcrypto = function(key, props) {\n key = key || {};\n props = props || {};\n\n var keyLen = props.length || 0,\n algParams = merge(clone(alg), {\n namedCurve: key.crv\n });\n\n // assume {key} is privateKey\n if (!keyLen) {\n // calculate key length from private key size\n keyLen = key.d.length;\n }\n var privKey = ecUtil.convertToJWK(key, false);\n privKey = helpers.subtleCrypto.importKey(\"jwk\",\n privKey,\n algParams,\n false,\n [ \"deriveBits\" ]);\n\n // assume {props.public} is publicKey\n var pubKey = validatePublic(props.public, \"jwk\");\n pubKey = pubKey.then(function(pubKey) {\n // {pubKey} is \"jwk\"\n return helpers.subtleCrypto.importKey(\"jwk\",\n pubKey,\n algParams,\n false,\n []);\n });\n\n var p = Promise.all([privKey, pubKey]);\n p = p.then(function(keypair) {\n var privKey = keypair[0],\n pubKey = keypair[1];\n\n var algParams = merge(clone(alg), {\n public: pubKey\n });\n return helpers.subtleCrypto.deriveBits(algParams, privKey, keyLen * 8);\n });\n p = p.then(function(result) {\n result = Buffer.from(result);\n return result;\n });\n return p;\n };\n\n var nodejs = function(key, props) {\n if (\"function\" !== typeof helpers.nodeCrypto.createECDH) {\n throw new Error(\"unsupported algorithm: ECDH\");\n }\n\n props = props || {};\n var keyLen = props.length || 0;\n var curve;\n switch (key.crv) {\n case \"P-256\":\n curve = \"prime256v1\";\n break;\n case \"P-384\":\n curve = \"secp384r1\";\n break;\n case \"P-521\":\n curve = \"secp521r1\";\n break;\n default:\n return Promise.reject(new Error(\"invalid curve: \" + curve));\n }\n\n // assume {key} is privateKey\n // assume {props.public} is publicKey\n var privKey = ecUtil.convertToBuffer(key, false);\n\n var p = validatePublic(props.public, \"buffer\");\n p = p.then(function(pubKey) {\n // {pubKey} is \"buffer\"\n var ecdh = helpers.nodeCrypto.createECDH(curve);\n // dummy call so computeSecret doesn't fail\n // ecdh.generateKeys();\n ecdh.setPrivateKey(privKey);\n var secret = ecdh.computeSecret(pubKey);\n if (keyLen) {\n if (secret.length < keyLen) {\n return Promise.reject(new Error(\"key length too large: \" + keyLen));\n }\n secret = secret.slice(0, keyLen);\n }\n return secret;\n });\n return p;\n };\n\n return helpers.setupFallback(nodejs, webcrypto, fallback);\n}\n\nfunction ecdhConcatDeriveFn() {\n // NOTE: no nodejs/webcrypto/fallback model, since this algorithm is\n // implemented using other primitives\n\n var fn = function(key, props) {\n props = props || {};\n\n var hash;\n try {\n hash = props.hash || idealHash(key.crv);\n if (!hash) {\n throw new Error(\"invalid hash: \" + hash);\n }\n hash.toUpperCase();\n } catch (ex) {\n return Promise.reject(ex);\n }\n\n var params = [\"public\"];\n // derive shared secret\n // NOTE: whitelist items from {props} for ECDH\n var promise = ecdh.ECDH.derive(key, pick(props, params));\n // expand\n promise = promise.then(function(shared) {\n // NOTE: blacklist items from {props} for ECDH\n return concat[\"CONCAT-\" + hash].derive(shared, omit(props, params));\n });\n return promise;\n };\n\n return fn;\n}\n\nfunction ecdhHkdfDeriveFn() {\n // NOTE: no nodejs/webcrypto/fallback model, since this algorithm is\n // implemented using other primitives\n\n var fn = function(key, props) {\n props = props || {};\n\n var hash;\n try {\n hash = props.hash || idealHash(key.crv);\n if (!hash) {\n throw new Error(\"invalid hash: \" + hash);\n }\n hash.toUpperCase();\n } catch (ex) {\n return Promise.reject(ex);\n }\n\n var params = [\"public\"];\n // derive shared secret\n // NOTE: whitelist items from {props} for ECDH\n var promise = ecdh.ECDH.derive(key, pick(props, params));\n // extract-and-expand\n promise = promise.then(function(shared) {\n // NOTE: blacklist items from {props} for ECDH\n return hkdf[\"HKDF-\" + hash].derive(shared, omit(props, params));\n });\n return promise;\n };\n\n return fn;\n}\n\n// ### Wrap/Unwrap algorithms\nfunction doEcdhesCommonDerive(privKey, pubKey, props) {\n function prependLen(input) {\n return Buffer.concat([\n helpers.int32ToBuffer(input.length),\n input\n ]);\n }\n\n var algId = props.algorithm || \"\",\n keyLen = CONSTANTS.KEYLENGTH[algId],\n apu = util.asBuffer(props.apu || \"\", \"base64url\"),\n apv = util.asBuffer(props.apv || \"\", \"base64url\");\n var otherInfo = Buffer.concat([\n prependLen(Buffer.from(algId, \"utf8\")),\n prependLen(apu),\n prependLen(apv),\n helpers.int32ToBuffer(keyLen)\n ]);\n\n var params = {\n public: pubKey,\n length: keyLen / 8,\n hash: \"SHA-256\",\n otherInfo: otherInfo\n };\n return ecdh[\"ECDH-CONCAT\"].derive(privKey, params);\n}\n\nfunction ecdhesDirEncryptFn() {\n // NOTE: no nodejs/webcrypto/fallback model, since this algorithm is\n // implemented using other primitives\n var fn = function(key, pdata, props) {\n props = props || {};\n\n // {props.epk} is private\n if (!props.epk || !props.epk.d) {\n return Promise.reject(new Error(\"missing ephemeral private key\"));\n }\n var epk = ecUtil.convertToObj(props.epk, false);\n\n // {key} is public\n if (!key || !key.x || !key.y) {\n return Promise.reject(new Error(\"missing static public key\"));\n }\n var spk = ecUtil.convertToObj(key, true);\n\n // derive ECDH shared\n var promise = doEcdhesCommonDerive(epk, spk, {\n algorithm: props.enc,\n apu: props.apu,\n apv: props.apv\n });\n promise = promise.then(function(shared) {\n return {\n data: shared,\n once: true,\n direct: true\n };\n });\n return promise;\n };\n\n return fn;\n}\nfunction ecdhesDirDecryptFn() {\n // NOTE: no nodejs/webcrypto/fallback model, since this algorithm is\n // implemented using other primitives\n var fn = function(key, cdata, props) {\n props = props || {};\n\n // {props.epk} is public\n if (!props.epk || !props.epk.x || !props.epk.y) {\n return Promise.reject(new Error(\"missing ephemeral public key\"));\n }\n var epk = ecUtil.convertToObj(props.epk, true);\n\n // {key} is private\n if (!key || !key.d) {\n return Promise.reject(new Error(\"missing static private key\"));\n }\n var spk = ecUtil.convertToObj(key, false);\n\n // derive ECDH shared\n var promise = doEcdhesCommonDerive(spk, epk, {\n algorithm: props.enc,\n apu: props.apu,\n apv: props.apv\n });\n promise = promise.then(function(shared) {\n return shared;\n });\n return promise;\n };\n\n return fn;\n}\n\nfunction ecdhesKwEncryptFn(wrap) {\n // NOTE: no nodejs/webcrypto/fallback model, since this algorithm is\n // implemented using other primitives\n var fn = function(key, pdata, props) {\n props = props || {};\n\n // {props.epk} is private\n if (!props.epk || !props.epk.d) {\n return Promise.reject(new Error(\"missing ephemeral private key\"));\n }\n var epk = ecUtil.convertToObj(props.epk, false);\n\n // {key} is public\n if (!key || !key.x || !key.y) {\n return Promise.reject(new Error(\"missing static public key\"));\n }\n var spk = ecUtil.convertToObj(key, true);\n\n // derive ECDH shared\n var promise = doEcdhesCommonDerive(epk, spk, {\n algorithm: props.alg,\n apu: props.apu,\n apv: props.apv\n });\n promise = promise.then(function(shared) {\n // wrap provided key with ECDH shared\n return wrap(shared, pdata);\n });\n return promise;\n };\n\n return fn;\n}\n\nfunction ecdhesKwDecryptFn(unwrap) {\n // NOTE: no nodejs/webcrypto/fallback model, since this algorithm is\n // implemented using other primitives\n var fn = function(key, cdata, props) {\n props = props || {};\n\n // {props.epk} is public\n if (!props.epk || !props.epk.x || !props.epk.y) {\n return Promise.reject(new Error(\"missing ephemeral public key\"));\n }\n var epk = ecUtil.convertToObj(props.epk, true);\n\n // {key} is private\n if (!key || !key.d) {\n return Promise.reject(new Error(\"missing static private key\"));\n }\n var spk = ecUtil.convertToObj(key, false);\n\n // derive ECDH shared\n var promise = doEcdhesCommonDerive(spk, epk, {\n algorithm: props.alg,\n apu: props.apu,\n apv: props.apv\n });\n promise = promise.then(function(shared) {\n // unwrap provided key with ECDH shared\n return unwrap(shared, cdata);\n });\n return promise;\n };\n\n return fn;\n}\n\n// ### Public API\n// * [name].derive\n[\n \"ECDH\",\n \"ECDH-HKDF\",\n \"ECDH-CONCAT\"\n].forEach(function(name) {\n var kdf = /^ECDH(?:-(\\w+))?$/g.exec(name || \"\")[1];\n var op = ecdh[name] = ecdh[name] || {};\n switch (kdf || \"\") {\n case \"CONCAT\":\n op.derive = ecdhConcatDeriveFn();\n break;\n case \"HKDF\":\n op.derive = ecdhHkdfDeriveFn();\n break;\n case \"\":\n op.derive = ecdhDeriveFn();\n break;\n default:\n op.derive = null;\n }\n});\n\n// * [name].encrypt\n// * [name].decrypt\n[\n \"ECDH-ES\",\n \"ECDH-ES+A128KW\",\n \"ECDH-ES+A192KW\",\n \"ECDH-ES+A256KW\"\n].forEach(function(name) {\n var kw = /^ECDH-ES(?:\\+(.+))?/g.exec(name || \"\")[1];\n var op = ecdh[name] = ecdh[name] || {};\n if (!kw) {\n op.encrypt = ecdhesDirEncryptFn();\n op.decrypt = ecdhesDirDecryptFn();\n } else {\n kw = aesKw[kw];\n if (kw) {\n op.encrypt = ecdhesKwEncryptFn(kw.encrypt);\n op.decrypt = ecdhesKwDecryptFn(kw.decrypt);\n } else {\n op.ecrypt = op.decrypt = null;\n }\n }\n});\n//*/\n","/*!\n * algorithms/ecdsa.js - Elliptic Curve Digitial Signature Algorithms\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar ecUtil = require(\"./ec-util.js\"),\n helpers = require(\"./helpers.js\"),\n sha = require(\"./sha.js\");\n\nfunction idealCurve(hash) {\n switch (hash) {\n case \"SHA-256\":\n return \"P-256\";\n case \"SHA-384\":\n return \"P-384\";\n case \"SHA-512\":\n return \"P-521\";\n default:\n throw new Error(\"unsupported hash: \" + hash);\n }\n}\n\nfunction ecdsaSignFN(hash) {\n var curve = idealCurve(hash);\n\n // ### Fallback implementation -- uses forge\n var fallback = function(key, pdata /*, props */) {\n if (curve !== key.crv) {\n return Promise.reject(new Error(\"invalid curve\"));\n }\n var pk = ecUtil.convertToForge(key, false);\n\n var promise;\n // generate hash\n promise = sha[hash].digest(pdata);\n // sign hash\n promise = promise.then(function(result) {\n result = pk.sign(result);\n result = Buffer.concat([result.r, result.s]);\n return {\n data: pdata,\n mac: result\n };\n });\n return promise;\n };\n\n // ### WebCrypto API implementation\n var webcrypto = function(key, pdata /*, props */) {\n if (curve !== key.crv) {\n return Promise.reject(new Error(\"invalid curve\"));\n }\n var pk = ecUtil.convertToJWK(key, false);\n\n var promise;\n var alg = {\n name: \"ECDSA\",\n namedCurve: pk.crv,\n hash: {\n name: hash\n }\n };\n promise = helpers.subtleCrypto.importKey(\"jwk\",\n pk,\n alg,\n true,\n [ \"sign\" ]);\n promise = promise.then(function(key) {\n return helpers.subtleCrypto.sign(alg, key, pdata);\n });\n promise = promise.then(function(result) {\n result = Buffer.from(result);\n return {\n data: pdata,\n mac: result\n };\n });\n return promise;\n };\n\n var nodejs;\n var nodeHash = hash.toLowerCase().replace(\"-\", \"\");\n if (helpers.nodeCrypto && helpers.nodeCrypto.getHashes().indexOf(nodeHash) > -1) {\n nodejs = function(key, pdata) {\n if (curve !== key.crv) {\n return Promise.reject(new Error(\"invalid curve\"));\n }\n\n var promise;\n promise = Promise.resolve(helpers.nodeCrypto.createSign(nodeHash));\n promise = promise.then(function (sign) {\n sign.update(pdata);\n return sign;\n });\n\n var size;\n\n switch (nodeHash.slice(-3)) {\n case \"384\":\n size = 48;\n break;\n case \"512\":\n size = 66;\n break;\n default:\n size = 32;\n }\n\n promise = promise.then(function (sign) {\n return ecUtil.derToConcat(sign.sign(ecUtil.convertToPEM(key, true)), size);\n });\n\n promise = promise.then(function (result) {\n return {\n data: pdata,\n mac: result\n };\n });\n\n return promise;\n };\n }\n\n return helpers.setupFallback(nodejs, webcrypto, fallback);\n}\n\nfunction ecdsaVerifyFN(hash) {\n var curve = idealCurve(hash);\n\n // ### Fallback implementation -- uses forge\n var fallback = function(key, pdata, mac /*, props */) {\n if (curve !== key.crv) {\n return Promise.reject(new Error(\"invalid curve\"));\n }\n var pk = ecUtil.convertToForge(key, true);\n\n var promise;\n // generate hash\n promise = sha[hash].digest(pdata);\n // verify hash\n promise = promise.then(function(result) {\n var len = mac.length / 2;\n var rs = {\n r: mac.slice(0, len),\n s: mac.slice(len)\n };\n if (!pk.verify(result, rs)) {\n return Promise.reject(new Error(\"verification failed\"));\n }\n return {\n data: pdata,\n mac: mac,\n valid: true\n };\n });\n return promise;\n };\n\n // ### WebCrypto API implementation\n var webcrypto = function(key, pdata, mac /* , props */) {\n if (curve !== key.crv) {\n return Promise.reject(new Error(\"invalid curve\"));\n }\n var pk = ecUtil.convertToJWK(key, true);\n\n var promise;\n var alg = {\n name: \"ECDSA\",\n namedCurve: pk.crv,\n hash: {\n name: hash\n }\n };\n promise = helpers.subtleCrypto.importKey(\"jwk\",\n pk,\n alg,\n true,\n [\"verify\"]);\n promise = promise.then(function(key) {\n return helpers.subtleCrypto.verify(alg, key, mac, pdata);\n });\n promise = promise.then(function(result) {\n if (!result) {\n return Promise.reject(new Error(\"verification failed\"));\n }\n return {\n data: pdata,\n mac: mac,\n valid: true\n };\n });\n return promise;\n };\n\n var nodejs;\n var nodeHash = hash.toLowerCase().replace(\"-\", \"\");\n if (helpers.nodeCrypto && helpers.nodeCrypto.getHashes().indexOf(nodeHash) > -1) {\n nodejs = function(key, pdata, mac /* , props */) {\n if (curve !== key.crv) {\n return Promise.reject(new Error(\"invalid curve\"));\n }\n\n var size;\n switch (nodeHash.slice(-3)) {\n case \"384\":\n size = 48;\n break;\n case \"512\":\n size = 66;\n break;\n default:\n size = 32;\n }\n\n var promise;\n promise = Promise.resolve(helpers.nodeCrypto.createVerify(nodeHash));\n promise = promise.then(function (verify) {\n verify.update(pdata);\n verify.end();\n return verify.verify(ecUtil.convertToPEM(key, false), ecUtil.concatToDer(mac, size));\n });\n promise = promise.then(function (result) {\n if (!result) {\n throw new Error(\"verification failed\");\n }\n return {\n data: pdata,\n mac: mac,\n valid: true\n };\n });\n\n return promise;\n };\n }\n\n return helpers.setupFallback(nodejs, webcrypto, fallback);\n}\n\n// ### Public API\nvar ecdsa = {};\n\n// * [name].sign\n// * [name].verify\n[\n \"ES256\",\n \"ES384\",\n \"ES512\"\n].forEach(function(name) {\n var hash = name.replace(/ES(\\d+)/g, function(m, size) {\n return \"SHA-\" + size;\n });\n ecdsa[name] = {\n sign: ecdsaSignFN(hash),\n verify: ecdsaVerifyFN(hash)\n };\n});\n\nmodule.exports = ecdsa;\n","/*!\n * algorithms/helpers.js - Internal functions and fields used in Cryptographic\n * Algorithms\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nif (typeof Promise === \"undefined\") {\n require(\"es6-promise\").polyfill();\n}\n\n// ###\nexports.int32ToBuffer = function(v, b) {\n b = b || Buffer.alloc(4);\n b[0] = (v >>> 24) & 0xff;\n b[1] = (v >>> 16) & 0xff;\n b[2] = (v >>> 8) & 0xff;\n b[3] = v & 0xff;\n return b;\n};\n\nvar MAX_INT32 = Math.pow(2, 32);\nexports.int64ToBuffer = function(v, b) {\n b = b || Buffer.alloc(8);\n var hi = Math.floor(v / MAX_INT32),\n lo = v % MAX_INT32;\n hi = exports.int32ToBuffer(hi);\n lo = exports.int32ToBuffer(lo);\n b = Buffer.concat([hi, lo]);\n return b;\n};\n\n// ### crypto and DOMException in browsers ###\n/* global crypto:false, DOMException:false */\n\nfunction getCryptoSubtle() {\n if (\"undefined\" !== typeof crypto) {\n if (\"undefined\" !== typeof crypto.subtle) {\n return crypto.subtle;\n }\n }\n\n return undefined;\n}\nfunction getCryptoNodeJS() {\n var crypto;\n try {\n crypto = require(\"crypto\");\n } catch (err) {\n return undefined;\n }\n\n if (!Object.keys(crypto).length) {\n // treat empty the same as missing\n return undefined;\n }\n\n return crypto;\n}\n\nvar supported = {};\nObject.defineProperty(exports, \"subtleCrypto\", {\n get: function() {\n var result;\n\n if (\"subtleCrypto\" in supported) {\n result = supported.subtleCrypto;\n } else {\n result = supported.subtleCrypto = getCryptoSubtle();\n }\n\n return result;\n },\n enumerable: true\n});\nObject.defineProperty(exports, \"nodeCrypto\", {\n get: function() {\n var result;\n\n if (\"nodeCrypto\" in supported) {\n result = supported.nodeCrypto;\n } else {\n result = supported.nodeCrypto = getCryptoNodeJS();\n }\n\n return result;\n },\n enumerable: true\n});\n\nexports.setupFallback = function(nodejs, webcrypto, fallback) {\n var impl;\n\n if (nodejs && exports.nodeCrypto) {\n impl = function main() {\n var args = arguments,\n promise;\n\n function check(err) {\n if (0 === err.message.indexOf(\"unsupported algorithm:\")) {\n impl = fallback;\n return impl.apply(null, args);\n }\n\n return Promise.reject(err);\n }\n\n try {\n promise = Promise.resolve(nodejs.apply(null, args));\n } catch(err) {\n promise = check(err);\n }\n\n return promise;\n };\n } else if (webcrypto && exports.subtleCrypto) {\n impl = function main() {\n var args = arguments,\n promise;\n\n function check(err) {\n if (err.code === DOMException.NOT_SUPPORTED_ERR ||\n // Firefox rejects some operations erroneously complaining about inputs\n err.message === \"Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData\" ||\n // MS Edge rejects with not an Error\n !(err instanceof Error)) {\n // not actually supported -- always use fallback\n impl = fallback;\n return impl.apply(null, args);\n }\n\n return Promise.reject(err);\n }\n\n try {\n promise = webcrypto.apply(null, args);\n promise = promise.catch(check);\n } catch(err) {\n promise = check(err);\n }\n\n return promise;\n };\n } else {\n impl = fallback;\n }\n\n return impl;\n};\n","/*!\n * algorithms/hkdf.js - HMAC-based Extract-and-Expand Key Derivation\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar CONSTANTS = require(\"./constants.js\"),\n hmac = require(\"./hmac.js\");\n\nfunction hkdfDeriveFn(name) {\n var hash = name.replace(\"HKDF-\", \"\"),\n op = name.replace(\"HKDF-SHA-\", \"HS\");\n\n // NOTE: no nodejs/webcrypto/fallback model, since this HKDF is\n // implemented using the HMAC algorithms\n\n var fn = function(key, props) {\n var hashLen = CONSTANTS.HASHLENGTH[hash] / 8;\n\n if (\"string\" === typeof op) {\n op = hmac[op].sign;\n }\n\n // prepare options\n props = props || {};\n var salt = props.salt;\n if (!salt || 0 === salt.length) {\n salt = Buffer.alloc(hashLen);\n }\n var info = props.info || Buffer.alloc(0);\n var keyLen = props.length || hashLen;\n\n var promise;\n\n // Setup Expansion\n var N = Math.ceil(keyLen / hashLen),\n okm = [],\n idx = 0;\n function expand(key, T) {\n if (N === idx++) {\n return Buffer.concat(okm).slice(0, keyLen);\n }\n\n if (!T) {\n T = Buffer.alloc(0);\n }\n T = Buffer.concat([T, info, Buffer.from([idx])]);\n T = op(key, T);\n T = T.then(function(result) {\n T = result.mac;\n okm.push(T);\n\n return expand(key, T);\n });\n return T;\n }\n\n // Step 1: Extract\n promise = op(salt, key, { length: salt.length * 8 });\n promise = promise.then(function(result) {\n // Step 2: Expand\n return expand(result.mac);\n });\n\n return promise;\n };\n\n return fn;\n}\n\n// Public API\n// * [name].derive\nvar hkdf = {};\n[\n \"HKDF-SHA-1\",\n \"HKDF-SHA-256\",\n \"HKDF-SHA-384\",\n \"HKDF-SHA-512\"\n].forEach(function(name) {\n hkdf[name] = {\n derive: hkdfDeriveFn(name)\n };\n});\n\nmodule.exports = hkdf;\n","/*!\n * algorithms/hmac.js - HMAC-based \"signatures\"\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar CONSTANTS = require(\"./constants\"),\n forge = require(\"../deps/forge.js\"),\n DataBuffer = require(\"../util/databuffer.js\"),\n helpers = require(\"./helpers.js\");\n\nfunction hmacSignFN(name) {\n var md = name.replace(\"HS\", \"SHA\").toLowerCase(),\n hash = name.replace(\"HS\", \"SHA-\");\n\n function checkKeyLength(len, key) {\n len = (len || CONSTANTS.HASHLENGTH[hash]) / 8;\n if (len > key.length) {\n return Promise.reject(new Error(\"invalid key length\"));\n }\n\n return Promise.resolve(key);\n }\n\n // ### Fallback Implementation -- uses forge\n var fallback = function(key, pdata, props) {\n props = props || {};\n var promise;\n promise = checkKeyLength(props.length, key);\n promise = promise.then(function() {\n var sig = forge.hmac.create();\n sig.start(md, key.toString(\"binary\"));\n sig.update(pdata.toString(\"binary\"));\n sig = Buffer.from(sig.digest().bytes(), \"binary\");\n\n return {\n data: pdata,\n mac: sig\n }\n });\n return promise;\n };\n\n // ### WebCryptoAPI Implementation\n var webcrypto = function(key, pdata, props) {\n props = props || {};\n\n var alg = {\n name: \"HMAC\",\n hash: {\n name: hash\n }\n };\n var promise;\n promise = checkKeyLength(props.length, key);\n promise = promise.then(function() {\n return helpers.subtleCrypto.importKey(\"raw\", key, alg, true, [\"sign\"]);\n });\n promise = promise.then(function(key) {\n return helpers.subtleCrypto.sign(alg, key, pdata);\n });\n promise = promise.then(function(result) {\n var sig = Buffer.from(result);\n return {\n data: pdata,\n mac: sig\n };\n });\n\n return promise;\n };\n\n // ### NodeJS implementation\n var nodejs = function(key, pdata, props) {\n props = props || {};\n\n var promise;\n promise = checkKeyLength(props.length, key);\n promise = promise.then(function() {\n var hmac = helpers.nodeCrypto.createHmac(md, key);\n hmac.update(pdata);\n\n var sig = hmac.digest();\n return {\n data: pdata,\n mac: sig\n };\n });\n return promise;\n };\n\n return helpers.setupFallback(nodejs, webcrypto, fallback);\n}\n\nfunction hmacVerifyFN(name) {\n var md = name.replace(\"HS\", \"SHA\").toLowerCase(),\n hash = name.replace(\"HS\", \"SHA-\");\n\n function compare(len, expected, actual) {\n len = (len || CONSTANTS.HASHLENGTH[hash]) / 8;\n var valid = true;\n for (var idx = 0; len > idx; idx++) {\n valid = valid && (expected[idx] === actual[idx]);\n }\n return valid;\n }\n\n // ### Fallback Implementation -- uses forge\n var fallback = function(key, pdata, mac, props) {\n props = props || {};\n\n var vrfy = forge.hmac.create();\n vrfy.start(md, new DataBuffer(key));\n vrfy.update(pdata.toString(\"binary\"));\n vrfy = Buffer.from(vrfy.digest().bytes(), \"binary\");\n\n if (compare(props.length, mac, vrfy)) {\n return Promise.resolve({\n data: pdata,\n mac: mac,\n valid: true\n });\n } else {\n return Promise.reject(new Error(\"verification failed\"));\n }\n };\n\n var webcrypto = function(key, pdata, mac, props) {\n props = props || {};\n\n var alg = {\n name: \"HMAC\",\n hash: {\n name: hash\n }\n };\n var promise;\n if (props.length) {\n promise = helpers.subtleCrypto.importKey(\"raw\", key, alg, true, [\"sign\"]);\n promise = promise.then(function(key) {\n return helpers.subtleCrypto.sign(alg, key, pdata);\n });\n promise = promise.then(function(result) {\n var sig = Buffer.from(result);\n return compare(props.length, mac, sig);\n });\n } else {\n promise = helpers.subtleCrypto.importKey(\"raw\", key, alg, true, [\"verify\"]);\n promise = promise.then(function(key) {\n return helpers.subtleCrypto.verify(alg, key, mac, pdata);\n });\n }\n promise = promise.then(function(result) {\n if (!result) {\n return Promise.reject(new Error(\"verifaction failed\"));\n }\n\n return {\n data: pdata,\n mac: mac,\n valid: true\n };\n });\n\n return promise;\n };\n\n var nodejs = function(key, pdata, mac, props) {\n props = props || {};\n\n var hmac = helpers.nodeCrypto.createHmac(md, key);\n hmac.update(pdata);\n\n var sig = hmac.digest();\n if (!compare(props.length, mac, sig)) {\n throw new Error(\"verification failed\");\n }\n return {\n data: pdata,\n mac: sig,\n valid: true\n };\n };\n\n return helpers.setupFallback(nodejs, webcrypto, fallback);\n}\n\n// ### Public API\n// * [name].sign\n// * [name].verify\nvar hmac = {};\n[\n \"HS1\",\n \"HS256\",\n \"HS384\",\n \"HS512\"\n].forEach(function(alg) {\n hmac[alg] = {\n sign: hmacSignFN(alg),\n verify: hmacVerifyFN(alg)\n };\n});\n\nmodule.exports = hmac;\n","/*!\n * algorithms/index.js - Cryptographic Algorithms Entry Point\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\n// setup implementations\nvar implementations = [\n require(\"./aes-cbc-hmac-sha2.js\"),\n require(\"./aes-gcm.js\"),\n require(\"./aes-kw.js\"),\n require(\"./concat.js\"),\n require(\"./dir.js\"),\n require(\"./ecdh.js\"),\n require(\"./ecdsa.js\"),\n require(\"./hkdf.js\"),\n require(\"./hmac.js\"),\n require(\"./pbes2.js\"),\n require(\"./rsaes.js\"),\n require(\"./rsassa.js\"),\n require(\"./sha.js\")\n];\n\nvar ALGS_DIGEST = {};\nvar ALGS_DERIVE = {};\nvar ALGS_SIGN = {},\n ALGS_VRFY = {};\nvar ALGS_ENC = {},\n ALGS_DEC = {};\n\nimplementations.forEach(function(mod) {\n Object.keys(mod).forEach(function(alg) {\n var op = mod[alg];\n\n if (\"function\" === typeof op.encrypt) {\n ALGS_ENC[alg] = op.encrypt;\n }\n if (\"function\" === typeof op.decrypt) {\n ALGS_DEC[alg] = op.decrypt;\n }\n if (\"function\" === typeof op.sign) {\n ALGS_SIGN[alg] = op.sign;\n }\n if (\"function\" === typeof op.verify) {\n ALGS_VRFY[alg] = op.verify;\n }\n if (\"function\" === typeof op.digest) {\n ALGS_DIGEST[alg] = op.digest;\n }\n if (\"function\" === typeof op.derive) {\n ALGS_DERIVE[alg] = op.derive;\n }\n });\n});\n\n// public API\nexports.digest = function(alg, data, props) {\n var op = ALGS_DIGEST[alg];\n if (!op) {\n return Promise.reject(new Error(\"unsupported algorithm: \" + alg));\n }\n\n return op(data, props);\n};\n\nexports.derive = function(alg, key, props) {\n var op = ALGS_DERIVE[alg];\n if (!op) {\n return Promise.reject(new Error(\"unsupported algorithm: \" + alg));\n }\n\n return op(key, props);\n};\n\nexports.sign = function(alg, key, pdata, props) {\n var op = ALGS_SIGN[alg];\n if (!op) {\n return Promise.reject(new Error(\"unsupported algorithm: \" + alg));\n }\n\n return op(key, pdata, props || {});\n};\n\nexports.verify = function(alg, key, pdata, mac, props) {\n var op = ALGS_VRFY[alg];\n if (!op) {\n return Promise.reject(new Error(\"unsupported algorithm: \" + alg));\n }\n\n return op(key, pdata, mac, props || {});\n};\n\nexports.encrypt = function(alg, key, pdata, props) {\n var op = ALGS_ENC[alg];\n if (!op) {\n return Promise.reject(new Error(\"unsupported algorithm: \" + alg));\n }\n\n return op(key, pdata, props || {});\n};\n\nexports.decrypt = function(alg, key, cdata, props) {\n var op = ALGS_DEC[alg];\n if (!op) {\n return Promise.reject(new Error(\"unsupported algorithm: \" + alg));\n }\n\n return op(key, cdata, props || {});\n};\n","/*!\n * algorithms/pbes2.js - Password-Based Encryption (v2) Algorithms\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar forge = require(\"../deps/forge.js\"),\n merge = require(\"../util/merge.js\"),\n util = require(\"../util\"),\n helpers = require(\"./helpers.js\"),\n CONSTANTS = require(\"./constants.js\"),\n KW = require(\"./aes-kw.js\");\n\nvar NULL_BUFFER = Buffer.from([0]);\nvar DEFAULT_ITERATIONS = 8192;\nvar DEFAULT_SALT_LENGTH = 16;\n\nfunction fixSalt(hmac, kw, salt) {\n var alg = \"PBES2-\" + hmac + \"+\" + kw;\n var output = [\n Buffer.from(alg, \"utf8\"),\n NULL_BUFFER,\n salt\n ];\n return Buffer.concat(output);\n}\n\nfunction pbkdf2Fn(hash) {\n function prepareProps(props) {\n props = props || {};\n var keyLen = props.length || 0;\n var salt = util.asBuffer(props.salt || Buffer.alloc(0), \"base64u4l\"),\n itrs = props.iterations || 0;\n\n if (0 >= keyLen) {\n throw new Error(\"invalid key length\");\n }\n if (0 >= itrs) {\n throw new Error(\"invalid iteration count\");\n }\n\n props.length = keyLen;\n props.salt = salt;\n props.iterations = itrs;\n\n return props;\n }\n\n var fallback = function(key, props) {\n try {\n props = prepareProps(props);\n } catch (err) {\n return Promise.reject(err);\n }\n\n var keyLen = props.length,\n salt = props.salt,\n itrs = props.iterations;\n\n var promise = new Promise(function(resolve, reject) {\n var md = forge.md[hash.replace(\"-\", \"\").toLowerCase()].create();\n var cb = function(err, dk) {\n if (err) {\n reject(err);\n } else {\n dk = Buffer.from(dk, \"binary\");\n resolve(dk);\n }\n };\n\n forge.pkcs5.pbkdf2(key.toString(\"binary\"),\n salt.toString(\"binary\"),\n itrs,\n keyLen,\n md,\n cb);\n });\n return promise;\n };\n var webcrypto = function(key, props) {\n try {\n props = prepareProps(props);\n } catch (err) {\n return Promise.reject(err);\n }\n\n var keyLen = props.length,\n salt = props.salt,\n itrs = props.iterations;\n\n var promise = Promise.resolve(key);\n promise = promise.then(function(keyval) {\n return helpers.subtleCrypto.importKey(\"raw\", keyval, \"PBKDF2\", false, [\"deriveBits\"]);\n });\n promise = promise.then(function(key) {\n var mainAlgo = {\n name: \"PBKDF2\",\n salt: new Uint8Array(salt),\n iterations: itrs,\n hash: hash\n };\n\n return helpers.subtleCrypto.deriveBits(mainAlgo, key, keyLen * 8);\n });\n promise = promise.then(function(result) {\n return util.asBuffer(result);\n });\n return promise;\n };\n var nodejs = function(key, props) {\n if (6 > helpers.nodeCrypto.pbkdf2.length) {\n throw new Error(\"unsupported algorithm: PBKDF2-\" + hash);\n }\n\n try {\n props = prepareProps(props);\n } catch (err) {\n return Promise.reject(err);\n }\n\n var keyLen = props.length,\n salt = props.salt,\n itrs = props.iterations;\n\n var md = hash.replace(\"-\", \"\");\n var promise = new Promise(function(resolve, reject) {\n function cb(err, dk) {\n if (err) {\n reject(err);\n } else {\n resolve(dk);\n }\n }\n helpers.nodeCrypto.pbkdf2(key, salt, itrs, keyLen, md, cb);\n });\n return promise;\n };\n\n return helpers.setupFallback(nodejs, webcrypto, fallback);\n}\n\nfunction pbes2EncryptFN(hmac, kw) {\n var deriveAlg = \"PBKDF2-\" + hmac.replace(\"HS\", \"SHA-\");\n var keyLen = CONSTANTS.KEYLENGTH[kw] / 8;\n\n return function(key, pdata, props) {\n props = props || {};\n\n var salt = util.asBuffer(props.p2s || Buffer.alloc(0), \"base64url\"),\n itrs = props.p2c || DEFAULT_ITERATIONS;\n\n if (0 >= itrs) {\n throw new Error(\"invalid iteration count\");\n }\n if (0 === salt.length) {\n salt = util.randomBytes(DEFAULT_SALT_LENGTH);\n } else if (8 > salt.length) {\n throw new Error(\"salt too small\");\n }\n var header = {\n p2s: util.base64url.encode(salt),\n p2c: itrs\n };\n salt = fixSalt(hmac, kw, salt);\n props = merge(props, {\n salt: salt,\n iterations: itrs,\n length: keyLen\n });\n\n var promise = Promise.resolve(key);\n // STEP 1: derive shared key\n promise = promise.then(function (key) {\n return pbes2[deriveAlg].derive(key, props);\n });\n // STEP 2: encrypt cek\n promise = promise.then(function (dk) {\n return KW[kw].encrypt(dk, pdata);\n });\n // STEP 3: (re-)apply headers\n promise = promise.then(function (results) {\n results.header = merge(results.header || {}, header);\n return results;\n });\n\n return promise;\n };\n}\n\nfunction pbes2DecryptFN(hmac, kw) {\n var deriveAlg = \"PBKDF2-\" + hmac.replace(\"HS\", \"SHA-\");\n var keyLen = CONSTANTS.KEYLENGTH[kw] / 8;\n\n return function(key, cdata, props) {\n props = props || {};\n\n var salt = util.asBuffer(props.p2s || Buffer.alloc(0), \"base64url\"),\n itrs = props.p2c || 0;\n\n if (0 >= itrs) {\n return Promise.reject(new Error(\"invalid iteration count\"));\n }\n\n if (8 > salt.length) {\n return Promise.reject(new Error(\"salt too small\"));\n }\n salt = fixSalt(hmac, kw, salt);\n props = merge(props, {\n salt: salt,\n iterations: itrs,\n length: keyLen\n });\n\n var promise = Promise.resolve(key);\n\n // STEP 1: derived shared key\n promise = promise.then(function(key) {\n return pbes2[deriveAlg].derive(key, props);\n });\n // STEP 2: decrypt cek\n promise = promise.then(function(dk) {\n return KW[kw].decrypt(dk, cdata);\n });\n\n return promise;\n };\n}\n\n// ### Public API\nvar pbes2 = {};\n\n// * [name].derive\n[\n \"PBKDF2-SHA-256\",\n \"PBKDF2-SHA-384\",\n \"PBKDF2-SHA-512\"\n].forEach(function(alg) {\n var hash = alg.replace(\"PBKDF2-\", \"\");\n pbes2[alg] = {\n derive: pbkdf2Fn(hash)\n };\n});\n\n// [name].encrypt\n// [name].decrypt\n[\n \"PBES2-HS256+A128KW\",\n \"PBES2-HS384+A192KW\",\n \"PBES2-HS512+A256KW\"\n].forEach(function(alg) {\n var parts = /PBES2-(HS\\d+)\\+(A\\d+KW)/g.exec(alg);\n var hmac = parts[1],\n kw = parts[2];\n pbes2[alg] = {\n encrypt: pbes2EncryptFN(hmac, kw),\n decrypt: pbes2DecryptFN(hmac, kw)\n };\n});\n\nmodule.exports = pbes2;\n","/*!\n * algorithms/rsa-util.js - RSA Utility Functions\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar clone = require(\"lodash/clone\"),\n forge = require(\"../deps/forge.js\"),\n util = require(\"../util\");\n\n// ### RSA-specific Helpers\nfunction convertToForge(key, isPublic) {\n var parts = isPublic ?\n [\"n\", \"e\"] :\n [\"n\", \"e\", \"d\", \"p\", \"q\", \"dp\", \"dq\", \"qi\"];\n parts = parts.map(function(f) {\n return new forge.jsbn.BigInteger(key[f].toString(\"hex\"), 16);\n });\n\n var fn = isPublic ?\n forge.pki.rsa.setPublicKey :\n forge.pki.rsa.setPrivateKey;\n return fn.apply(forge.pki.rsa, parts);\n}\n\nfunction convertToJWK(key, isPublic) {\n var result = clone(key);\n var parts = isPublic ?\n [\"n\", \"e\"] :\n [\"n\", \"e\", \"d\", \"p\", \"q\", \"dp\", \"dq\", \"qi\"];\n parts.forEach(function(f) {\n result[f] = util.base64url.encode(result[f]);\n });\n\n // remove potentially troublesome properties\n delete result.key_ops;\n delete result.use;\n delete result.alg;\n\n if (isPublic) {\n delete result.d;\n delete result.p;\n delete result.q;\n delete result.dp;\n delete result.dq;\n delete result.qi;\n }\n\n return result;\n}\n\nfunction convertToPem(key, isPublic) {\n var cacheKey = isPublic ? \"__cachedPublicPem\" : \"__cachedPrivatePem\";\n if (key[cacheKey]) {\n return key[cacheKey];\n }\n\n var value;\n if (isPublic) {\n value = forge.pki.publicKeyToPem(convertToForge(key, isPublic));\n } else {\n value = forge.pki.privateKeyToPem(convertToForge(key, isPublic));\n }\n\n Object.defineProperty(key, cacheKey, { value: value });\n return value;\n}\n\nmodule.exports = {\n convertToForge: convertToForge,\n convertToJWK: convertToJWK,\n convertToPem: convertToPem\n};\n","/*!\n * algorithms/rsaes.js - RSA Signatures\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar forge = require(\"../deps/forge.js\"),\n helpers = require(\"./helpers.js\"),\n DataBuffer = require(\"../util/databuffer.js\"),\n rsaUtil = require(\"./rsa-util.js\");\n\nvar nodeSupport = {\n \"RSA-OAEP\": \"RSA_PKCS1_OAEP_PADDING\",\n RSA1_5: \"RSA_PKCS1_PADDING\"\n};\n\nfunction nodeSupportCheck(name) {\n return helpers.nodeCrypto && helpers.nodeCrypto.constants && Object.keys(nodeSupport).indexOf(name) !== -1;\n}\n\n// ### RSAES-PKCS1-v1_5\n\n// ### RSAES-OAEP\nfunction rsaesEncryptFn(name) {\n var alg = {\n name: name\n };\n\n if (\"RSA-OAEP-256\" === name) {\n alg.name = \"RSA-OAEP\";\n alg.hash = {\n name: \"SHA-256\"\n };\n } else if (\"RSA-OAEP\" === name) {\n alg.hash = {\n name: \"SHA-1\"\n };\n } else {\n alg.name = \"RSAES-PKCS1-v1_5\";\n }\n\n // ### Fallback Implementation -- uses forge\n var fallback = function(key, pdata) {\n // convert pdata to byte string\n pdata = new DataBuffer(pdata).bytes();\n\n // encrypt it\n var pki = rsaUtil.convertToForge(key, true),\n params = {};\n if (\"RSA-OAEP\" === alg.name) {\n params.md = alg.hash.name.toLowerCase().replace(/-/g, \"\");\n params.md = forge.md[params.md].create();\n }\n var cdata = pki.encrypt(pdata, alg.name.toUpperCase(), params);\n\n // convert cdata to Buffer\n cdata = new DataBuffer(cdata).native();\n\n return Promise.resolve({\n data: cdata\n });\n };\n\n // ### WebCryptoAPI Implementation\n var webcrypto;\n if (\"RSAES-PKCS1-v1_5\" !== alg.name) {\n webcrypto = function(key, pdata) {\n key = rsaUtil.convertToJWK(key, true);\n var promise;\n promise = helpers.subtleCrypto.importKey(\"jwk\", key, alg, true, [\"encrypt\"]);\n promise = promise.then(function(key) {\n return helpers.subtleCrypto.encrypt(alg, key, pdata);\n });\n promise = promise.then(function(result) {\n var cdata = Buffer.from(result);\n return {\n data: cdata\n };\n });\n\n return promise;\n };\n } else {\n webcrypto = null;\n }\n\n var nodejs;\n if (nodeSupportCheck(name)) {\n nodejs = function (key, pdata) {\n key = rsaUtil.convertToPem(key, true);\n\n var cdata = helpers.nodeCrypto.publicEncrypt({\n key: key,\n padding: helpers.nodeCrypto.constants[nodeSupport[name]]\n }, pdata);\n\n return {\n data: cdata\n };\n };\n }\n\n return helpers.setupFallback(nodejs, webcrypto, fallback);\n}\n\nfunction rsaesDecryptFn(name) {\n var alg = {\n name: name\n };\n\n if (\"RSA-OAEP-256\" === name) {\n alg.name = \"RSA-OAEP\";\n alg.hash = {\n name: \"SHA-256\"\n };\n } else if (\"RSA-OAEP\" === name) {\n alg.hash = {\n name: \"SHA-1\"\n };\n } else {\n alg.name = \"RSAES-PKCS1-v1_5\";\n }\n\n // ### Fallback Implementation -- uses forge\n var fallback = function(key, cdata) {\n // convert cdata to byte string\n cdata = new DataBuffer(cdata).bytes();\n\n // decrypt it\n var pki = rsaUtil.convertToForge(key, false),\n params = {};\n if (\"RSA-OAEP\" === alg.name) {\n params.md = alg.hash.name.toLowerCase().replace(/-/g, \"\");\n params.md = forge.md[params.md].create();\n }\n var pdata = pki.decrypt(cdata, alg.name.toUpperCase(), params);\n\n // convert pdata to Buffer\n pdata = new DataBuffer(pdata).native();\n\n return Promise.resolve(pdata);\n };\n\n // ### WebCryptoAPI Implementation\n var webcrypto;\n if (\"RSAES-PKCS1-v1_5\" !== alg.name) {\n webcrypto = function(key, pdata) {\n key = rsaUtil.convertToJWK(key, false);\n var promise;\n promise = helpers.subtleCrypto.importKey(\"jwk\", key, alg, true, [\"decrypt\"]);\n promise = promise.then(function(key) {\n return helpers.subtleCrypto.decrypt(alg, key, pdata);\n });\n promise = promise.then(function(result) {\n var pdata = Buffer.from(result);\n return pdata;\n });\n\n return promise;\n };\n } else {\n webcrypto = null;\n }\n\n var nodejs;\n if (nodeSupportCheck(name)) { // node ^6.12.0 || >= 8.0.0\n nodejs = function(key, pdata) {\n key = rsaUtil.convertToPem(key, false);\n return helpers.nodeCrypto.privateDecrypt({\n key: key,\n padding: helpers.nodeCrypto.constants[nodeSupport[name]]\n }, pdata);\n };\n } else if (helpers.nodeCrypto && name === \"RSA-OAEP\") { // node (>= 6.0.0 && < 6.12.0) || ^7.0.0\n nodejs = function(key, pdata) {\n key = rsaUtil.convertToPem(key, false);\n return helpers.nodeCrypto.privateDecrypt(key, pdata);\n };\n }\n\n return helpers.setupFallback(nodejs, webcrypto, fallback);\n}\n\n// ### Public API\n// * [name].encrypt\n// * [name].decrypt\nvar rsaes = {};\n[\n \"RSA-OAEP\",\n \"RSA-OAEP-256\",\n \"RSA1_5\"\n].forEach(function(name) {\n rsaes[name] = {\n encrypt: rsaesEncryptFn(name),\n decrypt: rsaesDecryptFn(name)\n };\n});\n\nmodule.exports = rsaes;\n","/*!\n * algorithms/rsassa.js - RSA Signatures\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar forge = require(\"../deps/forge.js\"),\n CONSTANTS = require(\"./constants\"),\n helpers = require(\"./helpers.js\"),\n rsaUtil = require(\"./rsa-util.js\");\n\nfunction nodePSSsupport() {\n return helpers.nodeCrypto && helpers.nodeCrypto.constants && helpers.nodeCrypto.constants.RSA_PSS_SALTLEN_DIGEST;\n}\n\n// ### RSASSA-PKCS1-v1_5\n\nfunction rsassaV15SignFn(name) {\n var md = name.replace(\"RS\", \"SHA\").toLowerCase(),\n hash = name.replace(\"RS\", \"SHA-\");\n\n var alg = {\n name: \"RSASSA-PKCS1-V1_5\",\n hash: {\n name: hash\n }\n };\n\n // ### Fallback Implementation -- uses forge\n var fallback = function(key, pdata) {\n // create the digest\n var digest = forge.md[md].create();\n digest.start();\n digest.update(pdata);\n\n // sign it\n var pki = rsaUtil.convertToForge(key, false);\n var sig = pki.sign(digest, \"RSASSA-PKCS1-V1_5\");\n sig = Buffer.from(sig, \"binary\");\n\n return Promise.resolve({\n data: pdata,\n mac: sig\n });\n };\n\n // ### WebCryptoAPI Implementation\n var webcrypto = function(key, pdata) {\n key = rsaUtil.convertToJWK(key, false);\n var promise;\n promise = helpers.subtleCrypto.importKey(\"jwk\", key, alg, true, [\"sign\"]);\n promise = promise.then(function(key) {\n return helpers.subtleCrypto.sign(alg, key, pdata);\n });\n promise = promise.then(function(result) {\n var sig = Buffer.from(result);\n return {\n data: pdata,\n mac: sig\n };\n });\n\n return promise;\n };\n\n var nodejs;\n var nodeHash = \"RSA-\" + hash.replace(\"-\", \"\");\n if (helpers.nodeCrypto && helpers.nodeCrypto.getHashes().indexOf(nodeHash) > -1) {\n nodejs = function(key, pdata) {\n var sign = helpers.nodeCrypto.createSign(nodeHash);\n sign.update(pdata);\n\n return {\n data: pdata,\n mac: sign.sign(rsaUtil.convertToPem(key, false))\n };\n };\n }\n\n return helpers.setupFallback(nodejs, webcrypto, fallback);\n}\n\nfunction rsassaV15VerifyFn(name) {\n var md = name.replace(\"RS\", \"SHA\").toLowerCase(),\n hash = name.replace(\"RS\", \"SHA-\");\n var alg = {\n name: \"RSASSA-PKCS1-V1_5\",\n hash: {\n name: hash\n }\n };\n\n // ### Fallback implementation -- uses forge\n var fallback = function(key, pdata, mac) {\n // create the digest\n var digest = forge.md[md].create();\n digest.start();\n digest.update(pdata);\n digest = digest.digest().bytes();\n\n // verify it\n var pki = rsaUtil.convertToForge(key, true);\n var sig = mac.toString(\"binary\");\n var result = pki.verify(digest, sig, \"RSASSA-PKCS1-V1_5\");\n if (!result) {\n return Promise.reject(new Error(\"verification failed\"));\n }\n return Promise.resolve({\n data: pdata,\n mac: mac,\n valid: true\n });\n };\n\n // ### WebCryptoAPI Implementation\n var webcrypto = function(key, pdata, mac) {\n key = rsaUtil.convertToJWK(key, true);\n var promise;\n promise = helpers.subtleCrypto.importKey(\"jwk\", key, alg, true, [\"verify\"]);\n promise = promise.then(function(key) {\n return helpers.subtleCrypto.verify(alg, key, mac, pdata);\n });\n promise = promise.then(function(result) {\n if (!result) {\n return Promise.reject(new Error(\"verification failed\"));\n }\n\n return {\n data: pdata,\n mac: mac,\n valid: true\n };\n });\n\n return promise;\n };\n\n var nodejs;\n if (helpers.nodeCrypto && helpers.nodeCrypto.getHashes().indexOf(md) > -1) {\n nodejs = function(key, pdata, mac) {\n var verify = helpers.nodeCrypto.createVerify(md);\n verify.update(pdata);\n verify.end();\n var result = verify.verify(rsaUtil.convertToPem(key, true), mac);\n if (!result) {\n return Promise.reject(new Error(\"verification failed\"));\n }\n\n return {\n data: pdata,\n mac: mac,\n valid: true\n };\n };\n }\n\n return helpers.setupFallback(nodejs, webcrypto, fallback);\n}\n\n// ### RSA-PSS\nfunction rsassaPssSignFn(name) {\n var md = name.replace(\"PS\", \"SHA\").toLowerCase(),\n hash = name.replace(\"PS\", \"SHA-\");\n\n var alg = {\n name: \"RSA-PSS\",\n hash: {\n name: hash\n },\n saltLength: CONSTANTS.HASHLENGTH[hash] / 8\n };\n\n // ### Fallback implementation -- uses forge\n var fallback = function (key, pdata) {\n // create the digest\n var digest = forge.md[md].create();\n digest.start();\n digest.update(pdata);\n\n // setup padding\n var pss = forge.pss.create({\n md: forge.md[md].create(),\n mgf: forge.mgf.mgf1.create(forge.md[md].create()),\n saltLength: CONSTANTS.HASHLENGTH[hash] / 8\n });\n\n // sign it\n var pki = rsaUtil.convertToForge(key, false);\n var sig = pki.sign(digest, pss);\n sig = Buffer.from(sig, \"binary\");\n\n return Promise.resolve({\n data: pdata,\n mac: sig\n });\n };\n\n // ### WebCryptoAPI Implementation\n var webcrypto = function(key, pdata) {\n key = rsaUtil.convertToJWK(key, false);\n var promise;\n promise = helpers.subtleCrypto.importKey(\"jwk\", key, alg, true, [\"sign\"]);\n promise = promise.then(function (key) {\n return helpers.subtleCrypto.sign(alg, key, pdata);\n });\n promise = promise.then(function (result) {\n var sig = Buffer.from(result);\n return {\n data: pdata,\n mac: sig\n };\n });\n\n return promise;\n };\n\n var nodejs;\n var nodeHash = \"RSA-\" + hash.replace(\"-\", \"\");\n if (nodePSSsupport()) {\n nodejs = function(key, pdata) {\n var sign = helpers.nodeCrypto.createSign(nodeHash);\n sign.update(pdata);\n\n var sig = sign.sign({\n key: rsaUtil.convertToPem(key, false),\n padding: helpers.nodeCrypto.constants.RSA_PKCS1_PSS_PADDING,\n saltLength: helpers.nodeCrypto.constants.RSA_PSS_SALTLEN_DIGEST\n });\n\n return {\n data: pdata,\n mac: sig\n };\n };\n }\n\n return helpers.setupFallback(nodejs, webcrypto, fallback);\n}\n\nfunction rsassaPssVerifyFn(name) {\n var md = name.replace(\"PS\", \"SHA\").toLowerCase(),\n hash = name.replace(\"PS\", \"SHA-\");\n\n var alg = {\n name: \"RSA-PSS\",\n hash: {\n name: hash\n },\n saltLength: CONSTANTS.HASHLENGTH[hash] / 8\n };\n\n // ### Fallback implementation -- uses forge\n var fallback = function (key, pdata, mac) {\n // create the digest\n var digest = forge.md[md].create();\n digest.start();\n digest.update(pdata);\n digest = digest.digest().bytes();\n\n // setup padding\n var pss = forge.pss.create({\n md: forge.md[md].create(),\n mgf: forge.mgf.mgf1.create(forge.md[md].create()),\n saltLength: CONSTANTS.HASHLENGTH[hash] / 8\n });\n\n // verify it\n var pki = rsaUtil.convertToForge(key, true);\n var sig = mac.toString(\"binary\");\n var result = pki.verify(digest, sig, pss);\n if (!result) {\n return Promise.reject(new Error(\"verification failed\"));\n }\n return Promise.resolve({\n data: pdata,\n mac: mac,\n valid: true\n });\n };\n\n // ### WebCryptoAPI Implementation\n var webcrypto = function(key, pdata, mac) {\n key = rsaUtil.convertToJWK(key, true);\n var promise;\n promise = helpers.subtleCrypto.importKey(\"jwk\", key, alg, true, [\"verify\"]);\n promise = promise.then(function (key) {\n return helpers.subtleCrypto.verify(alg, key, mac, pdata);\n });\n promise = promise.then(function (result) {\n if (!result) {\n return Promise.reject(new Error(\"verification failed\"));\n }\n\n return {\n data: pdata,\n mac: mac,\n valid: true\n };\n });\n\n return promise;\n };\n\n var nodejs;\n if (nodePSSsupport()) {\n nodejs = function(key, pdata, mac) {\n var verify = helpers.nodeCrypto.createVerify(md);\n verify.update(pdata);\n verify.end();\n var result = verify.verify({\n key: rsaUtil.convertToPem(key, true),\n padding: helpers.nodeCrypto.constants.RSA_PKCS1_PSS_PADDING,\n saltLength: helpers.nodeCrypto.constants.RSA_PSS_SALTLEN_DIGEST\n }, mac);\n if (!result) {\n return Promise.reject(new Error(\"verification failed\"));\n }\n\n return {\n data: pdata,\n mac: mac,\n valid: true\n };\n };\n }\n\n return helpers.setupFallback(nodejs, webcrypto, fallback);\n}\n\n// ### Public API\n// * [name].sign\n// * [name].verify\nvar rsassa = {};\n[\n \"PS256\",\n \"PS384\",\n \"PS512\"\n].forEach(function(name) {\n rsassa[name] = {\n sign: rsassaPssSignFn(name),\n verify: rsassaPssVerifyFn(name)\n };\n});\n\n[\n \"RS256\",\n \"RS384\",\n \"RS512\"\n].forEach(function(name) {\n rsassa[name] = {\n sign: rsassaV15SignFn(name),\n verify: rsassaV15VerifyFn(name)\n };\n});\n\nmodule.exports = rsassa;\n","/*!\n * algorithms/sha.js - Cryptographic Secure Hash Algorithms, versions 1 and 2\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar forge = require(\"../deps/forge.js\"),\n helpers = require(\"./helpers.js\");\n\nfunction hashDigestFN(hash) {\n var md = hash.replace(\"SHA-\", \"SHA\").toLowerCase();\n\n var alg = {\n name: hash\n };\n\n // ### Fallback Implementation -- uses forge\n var fallback = function(pdata /* props */) {\n var digest = forge.md[md].create();\n digest.update(pdata.toString(\"binary\"));\n digest = Buffer.from(digest.digest().bytes(), \"binary\");\n\n return Promise.resolve(digest);\n };\n\n // ### WebCryptoAPI Implementation\n var webcrypto = function(pdata /* props */) {\n var promise;\n promise = helpers.subtleCrypto.digest(alg, pdata);\n promise = promise.then(function(result) {\n result = Buffer.from(result);\n return result;\n });\n return promise;\n };\n\n // ### nodejs Implementation\n var nodejs = function(pdata /* props */) {\n var digest = helpers.nodeCrypto.createHash(md);\n digest.update(pdata);\n return digest.digest();\n };\n\n return helpers.setupFallback(nodejs, webcrypto, fallback);\n}\n\n// Public API\n// * [name].digest\nvar sha = {};\n[\n \"SHA-1\",\n \"SHA-256\",\n \"SHA-384\",\n \"SHA-512\"\n].forEach(function(name) {\n sha[name] = {\n digest: hashDigestFN(name)\n };\n});\n\nmodule.exports = sha;\n","/*!\n * deps/ciphermodes/gcm/helpers.js - AES-GCM Helper Functions\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar Long = require(\"long\"),\n fill = require(\"lodash/fill\"),\n pack = require(\"../pack.js\");\n\nvar E1 = 0xe1000000,\n E1B = 0xe1,\n E1L = new Long(E1 >> 8);\n\nfunction generateLookup() {\n var lookup = [];\n\n for (var c = 0; c < 256; ++c) {\n var v = 0;\n for (var i = 7; i >= 0; --i) {\n if ((c & (1 << i)) !== 0) {\n v ^= (E1 >>> (7 - i));\n }\n }\n lookup.push(v);\n }\n\n return lookup;\n}\n\nvar helpers = module.exports = {\n // ### Constants\n E1: E1,\n E1B: E1B,\n E1L: E1L,\n LOOKUP: generateLookup(),\n\n // ### Array Helpers\n arrayCopy: function(src, srcPos, dest, destPos, length) {\n // Start by checking for negatives since arrays in JS auto-expand\n if (srcPos < 0 || destPos < 0 || length < 0) {\n throw new TypeError(\"Invalid input.\");\n }\n\n if (dest instanceof Uint8Array) {\n // Check for overflow if dest is a typed-array\n if (destPos >= dest.length || (destPos + length) > dest.length) {\n throw new TypeError(\"Invalid input.\");\n }\n\n if (srcPos !== 0 || length < src.length) {\n if (src instanceof Uint8Array) {\n src = src.subarray(srcPos, srcPos + length);\n } else {\n src = src.slice(srcPos, srcPos + length);\n }\n }\n\n dest.set(src, destPos);\n } else {\n for (var i = 0; i < length; ++i) {\n dest[destPos + i] = src[srcPos + i];\n }\n }\n },\n arrayEqual: function(a1, a2) {\n a1 = a1 || [];\n a2 = a2 || [];\n\n var len = Math.min(a1.length, a2.length),\n result = (a1.length === a2.length);\n\n for (var idx = 0; idx < len; idx++) {\n result = result &&\n (\"undefined\" !== typeof a1[idx]) &&\n (\"undefined\" !== typeof a2[idx]) &&\n (a1[idx] === a2[idx]);\n }\n\n return result;\n },\n\n // ### Conversions\n asBytes: function(x, z) {\n switch (arguments.length) {\n case 1:\n z = Buffer.alloc(16);\n pack.intToBigEndian(x, z, 0);\n return z;\n case 2:\n pack.intToBigEndian(x, z, 0);\n break;\n default:\n throw new TypeError(\"Expected 1 or 2 arguments.\");\n }\n },\n asInts: function(x, z) {\n switch (arguments.length) {\n case 1:\n z = [];\n fill(z, 0, 0, 4);\n pack.bigEndianToInt(x, 0, z);\n return z;\n case 2:\n pack.bigEndianToInt(x, 0, z);\n break;\n default:\n throw new TypeError(\"Expected 1 or 2 arguments.\");\n }\n },\n oneAsInts: function() {\n var tmp = [];\n for (var c = 0; c < 4; ++c) {\n tmp.push(1 << 31);\n }\n return tmp;\n },\n\n // ## Bit-wise\n shiftRight: function(x, z) {\n var b, c;\n switch (arguments.length) {\n case 1:\n b = x[0];\n x[0] = b >>> 1;\n c = b << 31;\n b = x[1];\n x[1] = (b >>> 1) | c;\n c = b << 31;\n b = x[2];\n x[2] = (b >>> 1) | c;\n c = b << 31;\n b = x[3];\n x[3] = (b >>> 1) | c;\n return (b << 31) & 0xffffffff;\n case 2:\n b = x[0];\n z[0] = b >>> 1;\n c = b << 31;\n b = x[1];\n z[1] = (b >>> 1) | c;\n c = b << 31;\n b = x[2];\n z[2] = (b >>> 1) | c;\n c = b << 31;\n b = x[3];\n z[3] = (b >>> 1) | c;\n return (b << 31) & 0xffffffff;\n default:\n throw new TypeError(\"Expected 1 or 2 arguments.\");\n }\n },\n shiftRightN: function(x, n, z) {\n var nInv, b, c;\n switch (arguments.length) {\n case 2:\n b = x[0];\n nInv = 32 - n;\n x[0] = b >>> n;\n c = b << nInv;\n b = x[1];\n x[1] = (b >>> n) | c;\n c = b << nInv;\n b = x[2];\n x[2] = (b >>> n) | c;\n c = b << nInv;\n b = x[3];\n x[3] = (b >>> n) | c;\n return b << nInv;\n case 3:\n b = x[0];\n nInv = 32 - n;\n z[0] = b >>> n;\n c = b << nInv;\n b = x[1];\n z[1] = (b >>> n) | c;\n c = b << nInv;\n b = x[2];\n z[2] = (b >>> n) | c;\n c = b << nInv;\n b = x[3];\n z[3] = (b >>> n) | c;\n return b << nInv;\n default:\n throw new TypeError(\"Expected 2 or 3 arguments.\");\n }\n },\n xor: function(x, y, z) {\n switch (arguments.length) {\n case 2:\n x[0] ^= y[0];\n x[1] ^= y[1];\n x[2] ^= y[2];\n x[3] ^= y[3];\n break;\n case 3:\n z[0] = x[0] ^ y[0];\n z[1] = x[1] ^ y[1];\n z[2] = x[2] ^ y[2];\n z[3] = x[3] ^ y[3];\n break;\n default:\n throw new TypeError(\"Expected 2 or 3 arguments.\");\n }\n },\n\n multiply: function(x, y) {\n var r0 = x.slice();\n var r1 = [];\n\n for (var i = 0; i < 4; ++i) {\n var bits = y[i];\n for (var j = 31; j >= 0; --j) {\n if ((bits & (1 << j)) !== 0) {\n helpers.xor(r1, r0);\n }\n\n if (helpers.shiftRight(r0) !== 0) {\n r0[0] ^= helpers.E1;\n }\n }\n }\n\n helpers.arrayCopy(r1, 0, x, 0, 4);\n },\n multiplyP: function(x, y) {\n switch (arguments.length) {\n case 1:\n if (helpers.shiftRight(x) !== 0) {\n x[0] ^= helpers.E1;\n }\n break;\n case 2:\n if (helpers.shiftRight(x, y) !== 0) {\n y[0] ^= helpers.E1;\n }\n break;\n default:\n throw new TypeError(\"Expected 1 or 2 arguments.\");\n }\n },\n multiplyP8: function(x, y) {\n var c;\n switch (arguments.length) {\n case 1:\n c = helpers.shiftRightN(x, 8);\n x[0] ^= helpers.LOOKUP[c >>> 24];\n break;\n case 2:\n c = helpers.shiftRightN(x, 8, y);\n y[0] ^= helpers.LOOKUP[c >>> 24];\n break;\n default:\n throw new TypeError(\"Expected 1 or 2 arguments.\");\n }\n }\n};\n","/*!\n * deps/ciphermodes/gcm/index.js - AES-GCM implementation Entry Point\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n \"use strict\";\n\nvar Long = require(\"long\"),\n forge = require(\"../../../deps/forge.js\"),\n multipliers = require(\"./multipliers.js\"),\n helpers = require(\"./helpers.js\"),\n pack = require(\"../pack.js\"),\n DataBuffer = require(\"../../../util/databuffer.js\"),\n cipherHelpers = require(\"../helpers.js\");\n\nvar BLOCK_SIZE = 16;\n\n// ### GCM Mode\n// ### Constructor\nfunction Gcm(options) {\n options = options || {};\n\n this.name = \"GCM\";\n this.cipher = options.cipher;\n this.blockSize = this.blockSize || 16;\n}\n\n// ### exports\nmodule.exports = {\n createCipher: function(options) {\n var alg = new forge.aes.Algorithm(\"AES-GCM\", Gcm);\n alg.initialize({\n key: new DataBuffer(options.key)\n });\n alg.mode.start(options);\n\n return alg.mode;\n },\n createDecipher: function(options) {\n var alg = new forge.aes.Algorithm(\"AES-GCM\", Gcm);\n alg.initialize({\n key: new DataBuffer(options.key)\n });\n alg.mode._decrypt = true;\n alg.mode.start(options);\n\n return alg.mode;\n }\n};\n\n// ### Public API\nGcm.prototype.start = function(options) {\n this.tag = null;\n\n options = options || {};\n\n if (!(\"iv\" in options)) {\n throw new Error(\"Gcm needs ParametersWithIV or AEADParameters\");\n }\n this.nonce = options.iv;\n if (this.nonce == null || this.nonce.length < 1) {\n throw new Error(\"IV must be at least 1 byte\");\n }\n\n // TODO: variable tagLength?\n this.tagLength = 16;\n\n // TODO: validate tag\n if (\"tag\" in options) {\n this.tag = Buffer.from(options.tag);\n }\n\n var bufLength = !this._decrypt ?\n this.blockSize :\n (this.blockSize + this.tagLength);\n this.bufBlock = Buffer.alloc(bufLength);\n\n var multiplier = options.multiplier;\n if (multiplier == null) {\n multiplier = new (multipliers[\"8k\"])();\n }\n this.multiplier = multiplier;\n\n this.H = this.zeroBlock();\n cipherHelpers.encrypt(this.cipher, this.H, 0, this.H, 0);\n\n // GcmMultiplier tables don\"t change unless the key changes\n // (and are expensive to init)\n this.multiplier.init(this.H);\n this.exp = null;\n\n this.J0 = this.zeroBlock();\n\n if (this.nonce.length === 12) {\n this.nonce.copy(this.J0, 0, 0, this.nonce.length);\n this.J0[this.blockSize - 1] = 0x01;\n } else {\n this.gHASH(this.J0, this.nonce, this.nonce.length);\n var X = this.zeroBlock();\n pack.longToBigEndian(new Long(this.nonce.length).\n multiply(8), X, 8);\n this.gHASHBlock(this.J0, X);\n }\n\n this.S = this.zeroBlock();\n this.SAt = this.zeroBlock();\n this.SAtPre = this.zeroBlock();\n this.atBlock = this.zeroBlock();\n this.atBlockPos = 0;\n this.atLength = Long.ZERO;\n this.atLengthPre = Long.ZERO;\n this.counter = Buffer.from(this.J0);\n this.bufOff = 0;\n this.totalLength = Long.ZERO;\n\n if (\"additionalData\" in options) {\n this.processAADBytes(options.additionalData, 0, options.additionalData.length);\n }\n};\n\nGcm.prototype.update = function(inV, inOff, len, out, outOff) {\n var resultLen = 0;\n\n while (len > 0) {\n var inLen = Math.min(len, this.bufBlock.length - this.bufOff);\n inV.copy(this.bufBlock, this.bufOff, inOff, inOff + inLen);\n len -= inLen;\n inOff += inLen;\n this.bufOff += inLen;\n if (this.bufOff === this.bufBlock.length) {\n this.outputBlock(out, outOff + resultLen);\n resultLen += this.blockSize;\n }\n }\n\n return resultLen;\n};\nGcm.prototype.finish = function(out, outOff) {\n var resultLen = 0;\n\n if (this._decrypt) {\n // append tag\n resultLen += this.update(this.tag, 0, this.tag.length, out, outOff);\n }\n\n if (this.totalLength.isZero()) {\n this.initCipher();\n }\n\n var extra = this.bufOff;\n if (this._decrypt) {\n if (extra < this.tagLength) {\n throw new Error(\"data too short\");\n }\n extra -= this.tagLength;\n }\n\n if (extra > 0) {\n this.gCTRPartial(this.bufBlock, 0, extra, out, outOff + resultLen);\n resultLen += extra;\n }\n\n this.atLength = this.atLength.add(this.atBlockPos);\n\n // Final gHASH\n var X = this.zeroBlock();\n pack.longToBigEndian(this.atLength.multiply(8),\n X,\n 0);\n pack.longToBigEndian(this.totalLength.multiply(8),\n X,\n 8);\n\n this.gHASHBlock(this.S, X);\n\n // TODO Fix this if tagLength becomes configurable\n // T = MSBt(GCTRk(J0,S))\n var tag = Buffer.alloc(this.blockSize);\n cipherHelpers.encrypt(this.cipher, this.J0, 0, tag, 0);\n this.xor(tag, this.S);\n\n if (this._decrypt) {\n if (!helpers.arrayEqual(this.tag, tag)) {\n throw new Error(\"mac check in Gcm failed\");\n }\n } else {\n // We place into tag our calculated value for T\n this.tag = Buffer.alloc(this.tagLength);\n tag.copy(this.tag, 0, 0, this.tagLength);\n }\n\n return resultLen;\n};\n\n// ### \"Internal\" Helper Functions\nGcm.prototype.initCipher = function() {\n if (this.atLength.greaterThan(Long.ZERO)) {\n this.SAt.copy(this.SAtPre, 0, 0, this.blockSize);\n this.atLengthPre = this.atLength.add(Long.ZERO);\n }\n\n // Finish hash for partial AAD block\n if (this.atBlockPos > 0) {\n this.gHASHPartial(this.SAtPre, this.atBlock, 0, this.atBlockPos);\n this.atLengthPre = this.atLengthPre.add(this.atBlockPos);\n }\n\n if (this.atLengthPre.greaterThan(Long.ZERO)) {\n this.SAtPre.copy(this.S, 0, 0, this.blockSize);\n }\n};\n\nGcm.prototype.outputBlock = function(output, offset) {\n if (this.totalLength.isZero()) {\n this.initCipher();\n }\n this.gCTRBlock(this.bufBlock, output, offset);\n if (!this._decrypt) {\n this.bufOff = 0;\n } else {\n this.bufBlock.copy(this.bufBlock, 0, this.blockSize, this.blockSize + this.tagLength);\n this.bufOff = this.tagLength;\n }\n};\n\nGcm.prototype.processAADBytes = function(inV, inOff, len) {\n for (var i = 0; i < len; ++i) {\n this.atBlock[this.atBlockPos] = inV[inOff + i];\n if (++this.atBlockPos === this.blockSize) {\n // Hash each block as it fills\n this.gHASHBlock(this.SAt, this.atBlock);\n this.atBlockPos = 0;\n this.atLength = this.atLength.add(this.blockSize);\n }\n }\n};\n\nGcm.prototype.getNextCounterBlock = function() {\n for (var i = 15; i >= 12; --i) {\n var b = ((this.counter[i] + 1) & 0xff);\n this.counter[i] = b;\n\n if (b !== 0) {\n break;\n }\n }\n\n // encrypt counter\n var outb = Buffer.alloc(this.blockSize);\n cipherHelpers.encrypt(this.cipher, this.counter, 0, outb, 0);\n\n return outb;\n};\n\nGcm.prototype.gCTRBlock = function(block, out, outOff) {\n var tmp = this.getNextCounterBlock();\n\n this.xor(tmp, block);\n tmp.copy(out, outOff, 0, this.blockSize);\n\n this.gHASHBlock(this.S, !this._decrypt ? tmp : block);\n\n this.totalLength = this.totalLength.add(this.blockSize);\n};\nGcm.prototype.gCTRPartial = function(buf, off, len, out, outOff) {\n var tmp = this.getNextCounterBlock();\n\n this.xor(tmp, buf, off, len);\n tmp.copy(out, outOff, 0, len);\n\n this.gHASHPartial(this.S, !this._decrypt ? tmp : buf, 0, len);\n\n this.totalLength = this.totalLength.add(len);\n};\n\nGcm.prototype.gHASHBlock = function(Y, b) {\n this.xor(Y, b);\n this.multiplier.multiplyH(Y);\n};\nGcm.prototype.gHASHPartial = function(Y, b, off, len) {\n this.xor(Y, b, off, len);\n this.multiplier.multiplyH(Y);\n};\n\nGcm.prototype.xor = function(block, val, off, len) {\n switch (arguments.length) {\n case 2:\n for (var i = 15; i >= 0; --i) {\n block[i] ^= val[i];\n }\n break;\n case 4:\n while (len-- > 0) {\n block[len] ^= val[off + len];\n }\n break;\n default:\n throw new TypeError(\"Expected 2 or 4 arguments.\");\n }\n\n return block;\n};\n\nGcm.prototype.zeroBlock = function() {\n var block = Buffer.alloc(BLOCK_SIZE);\n return block;\n};\n","/*!\n * deps/ciphermodes/gcm/multipliers.js - AES-GCM Multipliers\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n \"use strict\";\n\nvar helpers = require(\"./helpers.js\"),\n pack = require(\"../pack.js\");\n\n\n// ### 8K Table Multiplier\nfunction Gcm8KMultiplier() {\n this.H = [];\n this.M = null;\n}\n\nGcm8KMultiplier.prototype.init = function(H) {\n var i, j, k;\n if (this.M == null) {\n // sc: I realize this UGLY...\n //M = new int[32][16][4];\n this.M = [];\n for (i = 0; i < 32; ++i) {\n this.M[i] = [];\n for (j = 0; j < 16; ++j) {\n this.M[i][j] = [];\n for (k = 0; k < 4; ++k) {\n this.M[i][j][k] = 0;\n }\n }\n }\n } else if (helpers.arrayEqual(this.H, H)) {\n return;\n }\n\n this.H = H.slice();\n\n // M[0][0] is ZEROES;\n // M[1][0] is ZEROES;\n helpers.asInts(H, this.M[1][8]);\n\n for (j = 4; j >= 1; j >>= 1) {\n helpers.multiplyP(this.M[1][j + j], this.M[1][j]);\n }\n helpers.multiplyP(this.M[1][1], this.M[0][8]);\n\n for (j = 4; j >= 1; j >>= 1) {\n helpers.multiplyP(this.M[0][j + j], this.M[0][j]);\n }\n\n i = 0;\n for (;;) {\n for (j = 2; j < 16; j += j) {\n for (k = 1; k < j; ++k) {\n helpers.xor(this.M[i][j], this.M[i][k], this.M[i][j + k]);\n }\n }\n\n if (++i === 32) {\n return;\n }\n\n if (i > 1) {\n // M[i][0] is ZEROES;\n for (j = 8; j > 0; j >>= 1) {\n helpers.multiplyP8(this.M[i - 2][j], this.M[i][j]);\n }\n }\n }\n};\nGcm8KMultiplier.prototype.multiplyH = function(x) {\n var z = [];\n for (var i = 15; i >= 0; --i) {\n var m = this.M[i + i][x[i] & 0x0f];\n z[0] ^= m[0];\n z[1] ^= m[1];\n z[2] ^= m[2];\n z[3] ^= m[3];\n m = this.M[i + i + 1][(x[i] & 0xf0) >>> 4];\n z[0] ^= m[0];\n z[1] ^= m[1];\n z[2] ^= m[2];\n z[3] ^= m[3];\n }\n\n pack.intToBigEndian(z, x, 0);\n};\n\n\nmodule.exports = {\n \"8k\": Gcm8KMultiplier\n};\n","/*!\n * deps/ciphermodes/helpers.js - Cipher Helper Functions\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar pack = require(\"./pack.js\");\n\nfunction doEncrypt(cipher, inb, inOff, outb, outOff) {\n var input = new Array(4),\n output = new Array(4);\n\n pack.bigEndianToInt(inb, inOff, input);\n cipher.encrypt(input, output);\n pack.intToBigEndian(output, outb, outOff);\n}\n\nmodule.exports = {\n encrypt: doEncrypt\n};\n","/*!\n * deps/ciphermodes/pack.js - Pack/Unpack Functions\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar Long = require(\"long\");\n\nvar pack = module.exports = {\n intToBigEndian: function(n, bs, off) {\n if (typeof n === \"number\") {\n switch (arguments.length) {\n case 1:\n bs = Buffer.alloc(4);\n pack.intToBigEndian(n, bs, 0);\n break;\n case 3:\n bs[off] = 0xff & (n >>> 24);\n bs[++off] = 0xff & (n >>> 16);\n bs[++off] = 0xff & (n >>> 8);\n bs[++off] = 0xff & (n);\n break;\n default:\n throw new TypeError(\"Expected 1 or 3 arguments.\");\n }\n } else {\n switch (arguments.length) {\n case 1:\n bs = Buffer.alloc(4 * n.length);\n pack.intToBigEndian(n, bs, 0);\n break;\n case 3:\n for (var i = 0; i < n.length; ++i) {\n pack.intToBigEndian(n[i], bs, off);\n off += 4;\n }\n break;\n default:\n throw new TypeError(\"Expected 1 or 3 arguments.\");\n }\n }\n\n return bs;\n },\n longToBigEndian: function(n, bs, off) {\n if (!Array.isArray(n)) {\n // Single\n switch (arguments.length) {\n case 1:\n bs = Buffer.alloc(8);\n pack.longToBigEndian(n, bs, 0);\n break;\n case 3:\n var lo = n.low,\n hi = n.high;\n pack.intToBigEndian(hi, bs, off);\n pack.intToBigEndian(lo, bs, off + 4);\n break;\n default:\n throw new TypeError(\"Expected 1 or 3 arguments.\");\n }\n } else {\n // Array\n switch (arguments.length) {\n case 1:\n bs = Buffer.alloc(8 * n.length);\n pack.longToBigEndian(n, bs, 0);\n break;\n case 3:\n for (var i = 0; i < n.length; ++i) {\n pack.longToBigEndian(n[i], bs, off);\n off += 8;\n }\n break;\n default:\n throw new TypeError(\"Expected 1 or 3 arguments.\");\n }\n }\n\n return bs;\n },\n\n bigEndianToInt: function(bs, off, ns) {\n switch (arguments.length) {\n case 2:\n var n = bs[off] << 24;\n n |= (bs[++off] & 0xff) << 16;\n n |= (bs[++off] & 0xff) << 8;\n n |= (bs[++off] & 0xff);\n return n;\n case 3:\n for (var i = 0; i < ns.length; ++i) {\n ns[i] = pack.bigEndianToInt(bs, off);\n off += 4;\n }\n break;\n default:\n throw new TypeError(\"Expected 2 or 3 arguments.\");\n }\n },\n bigEndianToLong: function(bs, off, ns) {\n switch (arguments.length) {\n case 2:\n var hi = pack.bigEndianToInt(bs, off);\n var lo = pack.bigEndianToInt(bs, off + 4);\n var num = new Long(lo, hi);\n return num;\n case 3:\n for (var i = 0; i < ns.length; ++i) {\n ns[i] = pack.bigEndianToLong(bs, off);\n off += 8;\n }\n break;\n default:\n throw new TypeError(\"Expected 2 or 3 arguments.\");\n }\n }\n};\n","/**\n * deps/ecc/curves.js - Elliptic Curve NIST/SECG/X9.62 Parameters\n * Original Copyright (c) 2003-2005 Tom Wu.\n * Modifications Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n *\n * Ported from Tom Wu, which is ported from BouncyCastle\n * Modified to reuse existing external NPM modules, restricted to the\n * NIST//SECG/X9.62 prime curves only, and formatted to match project\n * coding styles.\n */\n\"use strict\";\n\n// Named EC curves\n\nvar BigInteger = require(\"../../deps/forge\").jsbn.BigInteger,\n ec = require(\"./math.js\");\n\n// ----------------\n// X9ECParameters\n\n// constructor\nfunction X9ECParameters(curve, g, n, h) {\n this.curve = curve;\n this.g = g;\n this.n = n;\n this.h = h;\n}\n\nfunction x9getCurve() {\n return this.curve;\n}\n\nfunction x9getG() {\n return this.g;\n}\n\nfunction x9getN() {\n return this.n;\n}\n\nfunction x9getH() {\n return this.h;\n}\n\nX9ECParameters.prototype.getCurve = x9getCurve;\nX9ECParameters.prototype.getG = x9getG;\nX9ECParameters.prototype.getN = x9getN;\nX9ECParameters.prototype.getH = x9getH;\n\n// ----------------\n// SECNamedCurves\n\nfunction fromHex(s) { return new BigInteger(s, 16); }\n\nfunction secp256r1() {\n // p = 2^224 (2^32 - 1) + 2^192 + 2^96 - 1\n var p = fromHex(\"FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF\");\n var a = fromHex(\"FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC\");\n var b = fromHex(\"5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B\");\n var n = fromHex(\"FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551\");\n var h = BigInteger.ONE;\n var curve = new ec.ECCurveFp(p, a, b);\n var G = curve.decodePointHex(\"04\"\n + \"6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296\"\n + \"4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5\");\n return new X9ECParameters(curve, G, n, h);\n}\n\nfunction secp384r1() {\n // p = 2^384 - 2^128 - 2^96 + 2^32 - 1\n var p = fromHex(\"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF\");\n var a = fromHex(\"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC\");\n var b = fromHex(\"B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF\");\n var n = fromHex(\"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973\");\n var h = BigInteger.ONE;\n var curve = new ec.ECCurveFp(p, a, b);\n var G = curve.decodePointHex(\"04\"\n + \"AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7\"\n + \"3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A147CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F\");\n return new X9ECParameters(curve, G, n, h);\n}\n\nfunction secp521r1() {\n // p = 2^521 - 1\n var p = fromHex(\"01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\");\n var a = fromHex(\"01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC\");\n var b = fromHex(\"0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00\");\n var n = fromHex(\"01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409\");\n var h = BigInteger.ONE;\n var curve = new ec.ECCurveFp(p, a, b);\n var G = curve.decodePointHex(\"04\"\n + \"00C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66\"\n + \"011839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650\");\n return new X9ECParameters(curve, G, n, h);\n}\n\n// ----------------\n// Public API\n\nvar CURVES = module.exports = {\n \"secp256r1\": secp256r1(),\n \"secp384r1\": secp384r1(),\n \"secp521r1\": secp521r1()\n};\n\n// also export NIST names\nCURVES[\"P-256\"] = CURVES.secp256r1;\nCURVES[\"P-384\"] = CURVES.secp384r1;\nCURVES[\"P-521\"] = CURVES.secp521r1;\n","/**\n * deps/ecc/index.js - Elliptic Curve Entry Point\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar forge = require(\"../../deps/forge\"),\n BigInteger = forge.jsbn.BigInteger,\n ec = require(\"./math.js\"),\n CURVES = require(\"./curves.js\");\n\n// ### Helpers\nfunction hex2bn(s) {\n return new BigInteger(s, 16);\n}\n\nfunction bn2bin(bn, len) {\n if (!len) {\n len = Math.ceil(bn.bitLength() / 8);\n }\n len = len * 2;\n\n var hex = bn.toString(16);\n // truncate-left if too large\n hex = hex.substring(Math.max(hex.length - len, 0));\n // pad-left if too small\n while (len > hex.length) {\n hex = \"0\" + hex;\n }\n\n return Buffer.from(hex, \"hex\");\n}\nfunction bin2bn(s) {\n if (\"string\" === typeof s) {\n s = Buffer.from(s, \"binary\");\n }\n return hex2bn(s.toString(\"hex\"));\n}\n\nfunction keySizeBytes(params) {\n return Math.ceil(params.getN().bitLength() / 8);\n}\n\nfunction namedCurve(curve) {\n var params = CURVES[curve];\n if (!params) {\n throw new TypeError(\"unsupported named curve: \" + curve);\n }\n\n return params;\n}\n\nfunction normalizeEcdsa(params, md) {\n var log2n = params.getN().bitLength(),\n mdLen = md.length * 8;\n\n var e = bin2bn(md);\n if (log2n < mdLen) {\n e = e.shiftRight(mdLen - log2n);\n }\n\n return e;\n}\n\n// ### EC Public Key\n\n/**\n *\n * @param {String} curve The named curve\n * @param {BigInteger} x The X coordinate\n * @param {BigInteger} y The Y coordinate\n */\nfunction ECPublicKey(curve, x, y) {\n var params = namedCurve(curve),\n c = params.getCurve();\n var key = new ec.ECPointFp(c,\n c.fromBigInteger(x),\n c.fromBigInteger(y));\n\n this.curve = curve;\n this.params = params;\n this.point = key;\n\n var size = keySizeBytes(params);\n this.x = bn2bin(x, size);\n this.y = bn2bin(y, size);\n}\n\n// basics\nECPublicKey.prototype.isValid = function() {\n return this.params.curve.contains(this.point);\n}\n\n// ECDSA\nECPublicKey.prototype.verify = function(md, sig) {\n var N = this.params.getN(),\n G = this.params.getG();\n\n // prepare and validate (r, s)\n var r = bin2bn(sig.r),\n s = bin2bn(sig.s);\n if (r.compareTo(BigInteger.ONE) < 0 || r.compareTo(N) >= 0) {\n return false;\n }\n if (s.compareTo(BigInteger.ONE) < 0 || r.compareTo(N) >= 0) {\n return false;\n }\n\n // normalize input\n var e = normalizeEcdsa(this.params, md);\n // verify (r, s)\n var w = s.modInverse(N),\n u1 = e.multiply(w).mod(N),\n u2 = r.multiply(w).mod(N);\n\n var v = G.multiplyTwo(u1, this.point, u2).getX().toBigInteger();\n v = v.mod(N);\n\n return v.equals(r);\n};\n\n// ### EC Private Key\n\n/**\n * @param {String} curve The named curve\n * @param {Buffer} key The private key value\n */\nfunction ECPrivateKey(curve, key) {\n var params = namedCurve(curve);\n this.curve = curve;\n this.params = params;\n\n var size = keySizeBytes(params);\n this.d = bn2bin(key, size);\n}\n\nECPrivateKey.prototype.toPublicKey = function() {\n var d = bin2bn(this.d);\n var P = this.params.getG().multiply(d);\n return new ECPublicKey(this.curve,\n P.getX().toBigInteger(),\n P.getY().toBigInteger());\n};\n\n// ECDSA\nECPrivateKey.prototype.sign = function(md) {\n var keysize = keySizeBytes(this.params),\n N = this.params.getN(),\n G = this.params.getG(),\n e = normalizeEcdsa(this.params, md),\n d = bin2bn(this.d);\n\n var r, s;\n var k, x1, z;\n do {\n do {\n // determine random nonce\n do {\n k = bin2bn(forge.random.getBytes(keysize));\n } while (k.equals(BigInteger.ZERO) || k.compareTo(N) >= 0);\n // (x1, y1) = k * G\n x1 = G.multiply(k).getX().toBigInteger();\n // r = x1 mod N\n r = x1.mod(N);\n } while (r.equals(BigInteger.ZERO));\n // s = (k^-1 * (e + r * d)) mod N\n z = d.multiply(r);\n z = e.add(z);\n s = k.modInverse(N).multiply(z).mod(N);\n } while (s.equals(BigInteger.ONE));\n\n // convert (r, s) to bytes\n var len = keySizeBytes(this.params);\n r = bn2bin(r, len);\n s = bn2bin(s, len);\n\n return {\n r: r,\n s: s\n };\n};\n\n// basics\nECPrivateKey.prototype.isValid = function() {\n var d = bin2bn(this.d),\n n1 = this.params.getN().subtract(BigInteger.ONE);\n\n return (d.compareTo(BigInteger.ONE) >= 0) &&\n (d.compareTo(n1) < 0);\n}\n\n// ECDH\nECPrivateKey.prototype.computeSecret = function(pubkey) {\n var d = bin2bn(this.d);\n var S = pubkey.point.multiply(d).getX().toBigInteger();\n S = bn2bin(S, keySizeBytes(this.params));\n return S;\n};\n\n// ### Public API\nexports.generateKeyPair = function(curve) {\n var params = namedCurve(curve),\n n = params.getN();\n\n // generate random within range [1, N-1)\n var r = forge.random.getBytes(keySizeBytes(params));\n r = bin2bn(r);\n\n var n1 = n.subtract(BigInteger.ONE);\n var d = r.mod(n1).add(BigInteger.ONE);\n\n var privkey = new ECPrivateKey(curve, d),\n pubkey = privkey.toPublicKey();\n\n return {\n \"private\": privkey,\n \"public\": pubkey\n };\n};\n\nexports.asPublicKey = function(curve, x, y) {\n if (\"string\" === typeof x) {\n x = hex2bn(x);\n } else if (Buffer.isBuffer(x)) {\n x = bin2bn(x);\n }\n\n if (\"string\" === typeof y) {\n y = hex2bn(y);\n } else if (Buffer.isBuffer(y)) {\n y = bin2bn(y);\n }\n\n var pubkey = new ECPublicKey(curve, x, y);\n return pubkey;\n};\nexports.asPrivateKey = function(curve, d) {\n // Elaborate way to get to a Buffer from a (String|Buffer|BigInteger)\n if (\"string\" === typeof d) {\n d = hex2bn(d);\n } else if (Buffer.isBuffer(d)) {\n d = bin2bn(d);\n }\n\n var privkey = new ECPrivateKey(curve, d);\n return privkey;\n};\n","/**\n * deps/ecc/math.js - Elliptic Curve Math\n * Original Copyright (c) 2003-2005 Tom Wu.\n * Modifications Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n *\n * Ported from Tom Wu, which is ported from BouncyCastle\n * Modified to reuse existing external NPM modules, restricted to the\n * NIST//SECG/X9.62 prime curves only, and formatted to match project\n * coding styles.\n */\n\"use strict\";\n\n// Basic Javascript Elliptic Curve implementation\n// Ported loosely from BouncyCastle's Java EC code\n// Only Fp curves implemented for now\n\nvar BigInteger = require(\"../../deps/forge\").jsbn.BigInteger;\n\n// ----------------\n// Helpers\n\nfunction nbi() {\n return new BigInteger(null);\n}\n\n// ----------------\n// Barrett modular reduction\n\n// constructor\nfunction Barrett(m) {\n // setup Barrett\n this.r2 = nbi();\n this.q3 = nbi();\n BigInteger.ONE.dlShiftTo(2*m.t,this.r2);\n this.mu = this.r2.divide(m);\n this.m = m;\n}\n\nfunction barrettConvert(x) {\n if(x.s < 0 || x.t > 2*this.m.t) return x.mod(this.m);\n else if(x.compareTo(this.m) < 0) return x;\n else { var r = nbi(); x.copyTo(r); this.reduce(r); return r; }\n}\n\nfunction barrettRevert(x) { return x; }\n\n// x = x mod m (HAC 14.42)\nfunction barrettReduce(x) {\n if (x.s < 0) { throw Error(\"Barrett reduction on negative input\"); }\n x.drShiftTo(this.m.t-1,this.r2);\n if(x.t > this.m.t+1) { x.t = this.m.t+1; x.clamp(); }\n this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3);\n this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);\n while(x.compareTo(this.r2) < 0) x.dAddOffset(1,this.m.t+1);\n x.subTo(this.r2,x);\n while(x.compareTo(this.m) >= 0) x.subTo(this.m,x);\n}\n\n// r = x^2 mod m; x != r\nfunction barrettSqrTo(x,r) { x.squareTo(r); this.reduce(r); }\n\n// r = x*y mod m; x,y != r\nfunction barrettMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }\n\nBarrett.prototype.convert = barrettConvert;\nBarrett.prototype.revert = barrettRevert;\nBarrett.prototype.reduce = barrettReduce;\nBarrett.prototype.mulTo = barrettMulTo;\nBarrett.prototype.sqrTo = barrettSqrTo;\n\n// ----------------\n// ECFieldElementFp\n\n// constructor\nfunction ECFieldElementFp(q, x) {\n this.x = x;\n // TODO if(x.compareTo(q) >= 0) error\n this.p = q;\n}\n\nfunction feFpEquals(other) {\n if (other === this) {\n return true;\n }\n return (this.p.equals(other.p) && this.x.equals(other.x));\n}\n\nfunction feFpToBigInteger() {\n return this.x;\n}\n\nfunction feFpNegate() {\n return new ECFieldElementFp(this.p, this.x.negate().mod(this.p));\n}\n\nfunction feFpAdd(b) {\n return new ECFieldElementFp(this.p, this.x.add(b.toBigInteger()).mod(this.p));\n}\n\nfunction feFpSubtract(b) {\n return new ECFieldElementFp(this.p, this.x.subtract(b.toBigInteger()).mod(this.p));\n}\n\nfunction feFpMultiply(b) {\n return new ECFieldElementFp(this.p, this.x.multiply(b.toBigInteger()).mod(this.p));\n}\n\nfunction feFpSquare() {\n return new ECFieldElementFp(this.p, this.x.pow(2).mod(this.p));\n}\n\nfunction feFpDivide(b) {\n return new ECFieldElementFp(this.p, this.x.multiply(b.toBigInteger().modInverse(this.p)).mod(this.p));\n}\n\nECFieldElementFp.prototype.equals = feFpEquals;\nECFieldElementFp.prototype.toBigInteger = feFpToBigInteger;\nECFieldElementFp.prototype.negate = feFpNegate;\nECFieldElementFp.prototype.add = feFpAdd;\nECFieldElementFp.prototype.subtract = feFpSubtract;\nECFieldElementFp.prototype.multiply = feFpMultiply;\nECFieldElementFp.prototype.square = feFpSquare;\nECFieldElementFp.prototype.divide = feFpDivide;\n\n// ----------------\n// ECPointFp\n\n// constructor\nfunction ECPointFp(curve, x, y, z) {\n this.curve = curve;\n this.x = x;\n this.y = y;\n // Projective coordinates: either zinv == null or z * zinv == 1\n // z and zinv are just BigIntegers, not fieldElements\n if (!z) {\n this.z = BigInteger.ONE;\n } else {\n this.z = z;\n }\n this.zinv = null;\n //TODO: compression flag\n}\n\nfunction pointFpGetX() {\n if(!this.zinv) {\n this.zinv = this.z.modInverse(this.curve.p);\n }\n var r = this.x.toBigInteger().multiply(this.zinv);\n this.curve.reduce(r);\n return this.curve.fromBigInteger(r);\n}\n\nfunction pointFpGetY() {\n if(!this.zinv) {\n this.zinv = this.z.modInverse(this.curve.p);\n }\n var r = this.y.toBigInteger().multiply(this.zinv);\n this.curve.reduce(r);\n return this.curve.fromBigInteger(r);\n}\n\nfunction pointFpEquals(other) {\n if (other === this) {\n return true;\n }\n if (this.isInfinity()) {\n return other.isInfinity();\n }\n if (other.isInfinity()) {\n return this.isInfinity();\n }\n var u, v;\n // u = Y2 * Z1 - Y1 * Z2\n u = other.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(other.z)).mod(this.curve.p);\n if (!u.equals(BigInteger.ZERO)) {\n return false;\n }\n // v = X2 * Z1 - X1 * Z2\n v = other.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(other.z)).mod(this.curve.p);\n return v.equals(BigInteger.ZERO);\n}\n\nfunction pointFpIsInfinity() {\n if ((this.x == null) && (this.y == null)) {\n return true;\n }\n return (this.z.equals(BigInteger.ZERO) && !this.y.toBigInteger().equals(BigInteger.ZERO));\n}\n\nfunction pointFpNegate() {\n return new ECPointFp(this.curve, this.x, this.y.negate(), this.z);\n}\n\nfunction pointFpAdd(b) {\n if (this.isInfinity()) {\n return b;\n }\n if (b.isInfinity()) {\n return this;\n }\n\n // u = Y2 * Z1 - Y1 * Z2\n var u = b.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(b.z)).mod(this.curve.p);\n // v = X2 * Z1 - X1 * Z2\n var v = b.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(b.z)).mod(this.curve.p);\n\n if (BigInteger.ZERO.equals(v)) {\n if (BigInteger.ZERO.equals(u)) {\n return this.twice(); // this == b, so double\n }\n return this.curve.getInfinity(); // this = -b, so infinity\n }\n\n var THREE = new BigInteger(\"3\");\n var x1 = this.x.toBigInteger();\n var y1 = this.y.toBigInteger();\n\n var v2 = v.pow(2);\n var v3 = v2.multiply(v);\n var x1v2 = x1.multiply(v2);\n var zu2 = u.pow(2).multiply(this.z);\n\n // x3 = v * (z2 * (z1 * u^2 - 2 * x1 * v^2) - v^3)\n var x3 = zu2.subtract(x1v2.shiftLeft(1)).multiply(b.z).subtract(v3).multiply(v).mod(this.curve.p);\n // y3 = z2 * (3 * x1 * u * v^2 - y1 * v^3 - z1 * u^3) + u * v^3\n var y3 = x1v2.multiply(THREE).multiply(u).subtract(y1.multiply(v3)).subtract(zu2.multiply(u)).multiply(b.z).add(u.multiply(v3)).mod(this.curve.p);\n // z3 = v^3 * z1 * z2\n var z3 = v3.multiply(this.z).multiply(b.z).mod(this.curve.p);\n\n return new ECPointFp(this.curve, this.curve.fromBigInteger(x3), this.curve.fromBigInteger(y3), z3);\n}\n\nfunction pointFpTwice() {\n if(this.isInfinity()) {\n return this;\n }\n if (this.y.toBigInteger().signum() === 0) {\n return this.curve.getInfinity();\n }\n\n // TODO: optimized handling of constants\n var THREE = new BigInteger(\"3\");\n var x1 = this.x.toBigInteger();\n var y1 = this.y.toBigInteger();\n\n var y1z1 = y1.multiply(this.z);\n var y1sqz1 = y1z1.multiply(y1).mod(this.curve.p);\n var a = this.curve.a.toBigInteger();\n\n // w = 3 * x1^2 + a * z1^2\n var w = x1.pow(2).multiply(THREE);\n if (!BigInteger.ZERO.equals(a)) {\n w = w.add(this.z.pow(2).multiply(a));\n }\n w = w.mod(this.curve.p);\n //this.curve.reduce(w);\n // x3 = 2 * y1 * z1 * (w^2 - 8 * x1 * y1^2 * z1)\n var x3 = w.pow(2).subtract(x1.shiftLeft(3).multiply(y1sqz1)).shiftLeft(1).multiply(y1z1).mod(this.curve.p);\n // y3 = 4 * y1^2 * z1 * (3 * w * x1 - 2 * y1^2 * z1) - w^3\n var y3 = w.multiply(THREE).multiply(x1).subtract(y1sqz1.shiftLeft(1)).shiftLeft(2).multiply(y1sqz1).subtract(w.pow(2).multiply(w)).mod(this.curve.p);\n // z3 = 8 * (y1 * z1)^3\n var z3 = y1z1.pow(2).multiply(y1z1).shiftLeft(3).mod(this.curve.p);\n\n return new ECPointFp(this.curve, this.curve.fromBigInteger(x3), this.curve.fromBigInteger(y3), z3);\n}\n\n// Simple NAF (Non-Adjacent Form) multiplication algorithm\n// TODO: modularize the multiplication algorithm\nfunction pointFpMultiply(k) {\n if (this.isInfinity()) {\n return this;\n }\n if (k.signum() === 0) {\n return this.curve.getInfinity();\n }\n\n var e = k;\n var h = e.multiply(new BigInteger(\"3\"));\n\n var neg = this.negate();\n var R = this;\n\n var i;\n for(i = h.bitLength() - 2; i > 0; --i) {\n R = R.twice();\n\n var hBit = h.testBit(i);\n var eBit = e.testBit(i);\n\n if (hBit !== eBit) {\n R = R.add(hBit ? this : neg);\n }\n }\n\n return R;\n}\n\n// Compute this*j + x*k (simultaneous multiplication)\nfunction pointFpMultiplyTwo(j, x, k) {\n var i;\n if (j.bitLength() > k.bitLength()) {\n i = j.bitLength() - 1;\n } else {\n i = k.bitLength() - 1;\n }\n\n var R = this.curve.getInfinity();\n var both = this.add(x);\n while (i >= 0) {\n R = R.twice();\n if (j.testBit(i)) {\n if (k.testBit(i)) {\n R = R.add(both);\n }\n else {\n R = R.add(this);\n }\n }\n else {\n if (k.testBit(i)) {\n R = R.add(x);\n }\n }\n --i;\n }\n\n return R;\n}\n\nECPointFp.prototype.getX = pointFpGetX;\nECPointFp.prototype.getY = pointFpGetY;\nECPointFp.prototype.equals = pointFpEquals;\nECPointFp.prototype.isInfinity = pointFpIsInfinity;\nECPointFp.prototype.negate = pointFpNegate;\nECPointFp.prototype.add = pointFpAdd;\nECPointFp.prototype.twice = pointFpTwice;\nECPointFp.prototype.multiply = pointFpMultiply;\nECPointFp.prototype.multiplyTwo = pointFpMultiplyTwo;\n\n// ----------------\n// ECCurveFp\n\n// constructor\nfunction ECCurveFp(p, a, b) {\n this.p = p;\n this.a = this.fromBigInteger(a);\n this.b = this.fromBigInteger(b);\n this.infinity = new ECPointFp(this, null, null);\n this.reducer = new Barrett(this.p);\n}\n\nfunction curveFpgetP() {\n return this.p;\n}\n\nfunction curveFpGetA() {\n return this.a;\n}\n\nfunction curveFpGetB() {\n return this.b;\n}\n\nfunction curveFpEquals(other) {\n if (other === this) {\n return true;\n }\n return (this.p.equals(other.p) && this.a.equals(other.a) && this.b.equals(other.b));\n}\n\nfunction curveFpContains(pt) {\n // y^2 = x^3 + a*x + b mod p\n var x = pt.getX().toBigInteger(),\n y = pt.getY().toBigInteger(),\n a = this.a.toBigInteger(),\n b = this.b.toBigInteger(),\n p = this.p;\n\n var left = y.pow(2).mod(p),\n right = x.pow(3).add(a.multiply(x)).add(b).mod(p)\n\n return left.equals(right);\n}\n\nfunction curveFpGetInfinity() {\n return this.infinity;\n}\n\nfunction curveFpFromBigInteger(x) {\n return new ECFieldElementFp(this.p, x);\n}\n\nfunction curveReduce(x) {\n this.reducer.reduce(x);\n}\n\n// for now, work with hex strings because they're easier in JS\nfunction curveFpDecodePointHex(s) {\n switch (parseInt(s.substring(0, 2), 16)) {\n // first byte\n case 0:\n return this.infinity;\n case 2:\n case 3:\n // point compression not supported yet\n return null;\n case 4:\n case 6:\n case 7:\n var len = (s.length - 2) / 2;\n var xHex = s.substr(2, len);\n var yHex = s.substr(len + 2, len);\n\n return new ECPointFp(this,\n this.fromBigInteger(new BigInteger(xHex, 16)),\n this.fromBigInteger(new BigInteger(yHex, 16)));\n\n default: // unsupported\n return null;\n }\n}\n\nfunction curveFpEncodePointHex(p) {\n if (p.isInfinity()) {\n return \"00\";\n }\n var xHex = p.getX().toBigInteger().toString(16);\n var yHex = p.getY().toBigInteger().toString(16);\n var oLen = this.getP().toString(16).length;\n if ((oLen % 2) !== 0) {\n oLen++;\n }\n while (xHex.length < oLen) {\n xHex = \"0\" + xHex;\n }\n while (yHex.length < oLen) {\n yHex = \"0\" + yHex;\n }\n return \"04\" + xHex + yHex;\n}\n\nECCurveFp.prototype.getP = curveFpgetP;\nECCurveFp.prototype.getA = curveFpGetA;\nECCurveFp.prototype.getB = curveFpGetB;\nECCurveFp.prototype.equals = curveFpEquals;\nECCurveFp.prototype.contains = curveFpContains;\nECCurveFp.prototype.getInfinity = curveFpGetInfinity;\nECCurveFp.prototype.fromBigInteger = curveFpFromBigInteger;\nECCurveFp.prototype.reduce = curveReduce;\nECCurveFp.prototype.decodePointHex = curveFpDecodePointHex;\nECCurveFp.prototype.encodePointHex = curveFpEncodePointHex;\n\n// Exports\nmodule.exports = {\n ECFieldElementFp: ECFieldElementFp,\n ECPointFp: ECPointFp,\n ECCurveFp: ECCurveFp\n};\n","/*!\n * deps/forge.js - Forge Package Customization\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar forge = require(\"node-forge/lib/forge\");\nrequire(\"node-forge/lib/aes\");\nrequire(\"node-forge/lib/asn1\");\nrequire(\"node-forge/lib/cipher\");\nrequire(\"node-forge/lib/hmac\");\nrequire(\"node-forge/lib/mgf1\");\nrequire(\"node-forge/lib/pbkdf2\");\nrequire(\"node-forge/lib/pem\");\nrequire(\"node-forge/lib/pkcs1\");\nrequire(\"node-forge/lib/pkcs7\");\nrequire(\"node-forge/lib/pki\");\nrequire(\"node-forge/lib/prime\");\nrequire(\"node-forge/lib/prng\");\nrequire(\"node-forge/lib/pss\");\nrequire(\"node-forge/lib/random\");\nrequire(\"node-forge/lib/sha1\");\nrequire(\"node-forge/lib/sha256\");\nrequire(\"node-forge/lib/sha512\");\nrequire(\"node-forge/lib/util\");\n\n// Define AES \"raw\" cipher mode\nfunction modeRaw(options) {\n options = options || {};\n this.name = \"\";\n this.cipher = options.cipher;\n this.blockSize = options.blockSize || 16;\n this._blocks = this.blockSize / 4;\n this._inBlock = new Array(this._blocks);\n this._outBlock = new Array(this._blocks);\n}\n\nmodeRaw.prototype.start = function() {};\n\nmodeRaw.prototype.encrypt = function(input, output, finish) {\n if(input.length() < this.blockSize && !(finish && input.length() > 0)) {\n return true;\n }\n\n var i;\n\n // get next block\n for(i = 0; i < this._blocks; ++i) {\n this._inBlock[i] = input.getInt32();\n }\n\n // encrypt block\n this.cipher.encrypt(this._inBlock, this._outBlock);\n\n // write output\n for(i = 0; i < this._blocks; ++i) {\n output.putInt32(this._outBlock[i]);\n }\n};\n\nmodeRaw.prototype.decrypt = function(input, output, finish) {\n if(input.length() < this.blockSize && !(finish && input.length() > 0)) {\n return true;\n }\n\n var i;\n\n // get next block\n for(i = 0; i < this._blocks; ++i) {\n this._inBlock[i] = input.getInt32();\n }\n\n // decrypt block\n this.cipher.decrypt(this._inBlock, this._outBlock);\n\n // write output\n for(i = 0; i < this._blocks; ++i) {\n output.putInt32(this._outBlock[i]);\n }\n};\n\n(function() {\n var name = \"AES\",\n mode = modeRaw,\n factory;\n factory = function() { return new forge.aes.Algorithm(name, mode); };\n forge.cipher.registerAlgorithm(name, factory);\n})();\n\n// Ensure that the jsbn modInverse function always returns a positive result\nconst originalModInverse = forge.jsbn.BigInteger.prototype.modInverse;\nconst positiveModInverse = function(m) {\n const inv = originalModInverse.apply(this, [m]);\n return inv.mod(m);\n}\n\nforge.jsbn.BigInteger.prototype.modInverse = positiveModInverse;\n\nmodule.exports = forge;\n","/*!\n * index.js - Main Entry Point\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nif (typeof Promise === \"undefined\") {\n require(\"es6-promise\").polyfill();\n}\n\nif (typeof Buffer === \"undefined\") {\n (global || window).Buffer = require(\"buffer\").Buffer;\n}\n\nif (typeof process === \"undefined\") {\n (global || window).process = require(\"process\");\n}\n\nif (!process.version) {\n process.version = \"\";\n}\n\nvar JWS = require(\"./jws\");\n\nmodule.exports = {\n JWA: require(\"./algorithms\"),\n JWE: require(\"./jwe\"),\n JWK: require(\"./jwk\"),\n JWS: JWS,\n util: require(\"./util\"),\n parse: require(\"./parse\"),\n canYouSee: JWS.createVerify\n};\n","/*!\n * jwe/decrypt.js - Decrypt from a JWE\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar base64url = require(\"../util/base64url\"),\n AlgConfig = require(\"../util/algconfig\"),\n JWK = require(\"../jwk\"),\n merge = require(\"../util/merge\"),\n pako = require(\"pako\");\n\nvar DEFAULT_OPTIONS = {\n algorithms: \"*\"\n};\n\n/**\n * @class JWE.Decrypter\n * @classdesc Processor of encrypted data.\n *\n * @description\n * **NOTE:** This class cannot be instantiated directly. Instead\n * call {@link JWE.createDecrypt}.\n */\nfunction JWEDecrypter(ks, globalOpts) {\n var assumedKey,\n keystore;\n\n if (JWK.isKey(ks)) {\n assumedKey = ks;\n keystore = assumedKey.keystore;\n } else if (JWK.isKeyStore(ks)) {\n keystore = ks;\n } else {\n throw new TypeError(\"Keystore must be provided\");\n }\n\n globalOpts = merge({}, DEFAULT_OPTIONS, globalOpts);\n\n /**\n * Decrypts the given input.\n *\n * {opts}, if provided, is used to customize this specific decrypt operation.\n * This argument has the same semantics as {JWE.createDecrypt}, and takes\n * precedence over those options.\n *\n * The returned PRomise, when fulfilled, returns an object with the\n * following members:\n *\n * - `header` - The JOSE Header, combined from the relevant \"header\" and\n * \"protected\" fields from the original JWE object.\n * - `protected` - An array containing the names of the protected fields\n * - `key` - The used to decrypt the content\n * - `payload` - The decrypted content (as a Buffer)\n * - `plaintext` - An alias for `payload`\n *\n * @param {Object|String} input The encrypted content\n * @param {Object} [opts] The options for this decryption operation.\n * @returns {Promise} A promise for the decyprted plaintext\n */\n Object.defineProperty(this, \"decrypt\", {\n value: function(input, opts) {\n opts = merge({}, globalOpts, opts || {});\n var extraHandlers = opts.handlers || {};\n var handlerKeys = Object.keys(extraHandlers);\n var algSpec = new AlgConfig(opts.algorithms);\n\n /* eslint camelcase: [0] */\n if (typeof input === \"string\") {\n input = input.split(\".\");\n input = {\n protected: input[0],\n recipients: [\n {\n encrypted_key: input[1]\n }\n ],\n iv: input[2],\n ciphertext: input[3],\n tag: input[4]\n };\n } else if (!input || typeof input !== \"object\") {\n throw new Error(\"invalid input\");\n }\n if (\"encrypted_key\" in input) {\n input.recipients = [\n {\n encrypted_key: input.encrypted_key\n }\n ];\n }\n\n var promise;\n\n // ensure recipients exists\n var rcptList = input.recipients || [{}];\n promise = Promise.resolve(rcptList);\n\n //combine fields\n var fields,\n protect;\n promise = promise.then(function(rcptList) {\n if (input.protected) {\n protect = base64url.decode(input.protected).toString(\"utf8\");\n protect = JSON.parse(protect);\n\n // verify \"crit\" field first\n var crit = protect.crit;\n if (crit) {\n if (!Array.isArray(crit)) {\n return Promise.reject(new Error(\"Invalid 'crit' header\"));\n }\n for (var idx = 0; crit.length > idx; idx++) {\n if (-1 === handlerKeys.indexOf(crit[idx])) {\n return Promise.reject(new Error(\n \"Critical extension is not supported: \" + crit[idx]\n ));\n }\n }\n }\n\n fields = protect;\n protect = Object.keys(protect);\n } else {\n fields = {};\n protect = [];\n }\n fields = merge(input.unprotected || {}, fields);\n\n rcptList = rcptList.map(function(r) {\n var promise = Promise.resolve();\n var header = r.header || {};\n header = merge(header, fields);\n r.header = header;\n r.protected = protect;\n\n // check on allowed algorithms\n if (!algSpec.match(header.alg)) {\n promise = promise.then(function() {\n return Promise.reject(new Error(\"Algorithm not allowed: \" + header.alg));\n });\n }\n if (!algSpec.match(header.enc)) {\n promise = promise.then(function () {\n return Promise.reject(new Error(\"Algorithm not allowed: \" + header.enc));\n });\n }\n\n if (header.epk) {\n promise = promise.then(function() {\n return JWK.asKey(header.epk);\n });\n promise = promise.then(function(epk) {\n header.epk = epk.toObject(false);\n });\n }\n return promise.then(function() {\n return r;\n });\n });\n\n return Promise.all(rcptList);\n });\n\n // decrypt with first key found\n var algKey,\n encKey,\n kdata;\n promise = promise.then(function(rcptList) {\n var jwe = {};\n return new Promise(function(resolve, reject) {\n var processKey = function() {\n var rcpt = rcptList.shift();\n if (!rcpt) {\n reject(new Error(\"no key found\"));\n return;\n }\n\n var algPromise = Promise.resolve(rcpt);\n algPromise = algPromise.then(function(rcpt) {\n // try to unwrap encrypted key\n var prekey = kdata = rcpt.encrypted_key || \"\";\n prekey = base64url.decode(prekey);\n algKey = assumedKey || keystore.get({\n use: \"enc\",\n alg: rcpt.header.alg,\n kid: rcpt.header.kid\n });\n if (algKey) {\n return algKey.unwrap(rcpt.header.alg, prekey, rcpt.header);\n } else {\n return Promise.reject();\n }\n });\n algPromise = algPromise.then(function(key) {\n encKey = {\n \"kty\": \"oct\",\n \"k\": base64url.encode(key)\n };\n encKey = JWK.asKey(encKey);\n jwe.key = algKey;\n jwe.header = rcpt.header;\n jwe.protected = rcpt.protected;\n resolve(jwe);\n });\n algPromise.catch(processKey);\n };\n processKey();\n });\n });\n\n // assign decipher inputs\n promise = promise.then(function(jwe) {\n jwe.iv = input.iv;\n jwe.tag = input.tag;\n jwe.ciphertext = input.ciphertext;\n\n return jwe;\n });\n\n // process any prepare-decrypt handlers\n promise = promise.then(function(jwe) {\n var processing = [];\n handlerKeys.forEach(function(h) {\n h = extraHandlers[h];\n var p;\n if (\"function\" === typeof h) {\n p = h(jwe);\n } else if (\"object\" === typeof h && \"function\" === typeof h.prepare) {\n p = h.prepare(jwe);\n }\n if (p) {\n processing.push(Promise.resolve(p));\n }\n });\n return Promise.all(processing).then(function() {\n // don't actually care about individual handler results\n // assume {jwe} is updated\n return jwe;\n });\n });\n\n // prepare decrypt inputs\n promise = promise.then(function(jwe) {\n if (!Buffer.isBuffer(jwe.ciphertext)) {\n jwe.ciphertext = base64url.decode(jwe.ciphertext);\n }\n\n return jwe;\n });\n\n // decrypt it!\n promise = promise.then(function(jwe) {\n var adata = input.protected;\n if (\"aad\" in input && null != input.aad) {\n adata += \".\" + input.aad;\n }\n\n var params = {\n iv: jwe.iv,\n adata: adata,\n tag: jwe.tag,\n kdata: kdata,\n epu: jwe.epu,\n epv: jwe.epv\n };\n var cdata = jwe.ciphertext;\n\n delete jwe.iv;\n delete jwe.tag;\n delete jwe.ciphertext;\n\n return encKey.\n then(function(enkKey) {\n return enkKey.decrypt(jwe.header.enc, cdata, params).\n then(function(pdata) {\n jwe.payload = jwe.plaintext = pdata;\n return jwe;\n });\n });\n });\n\n // (OPTIONAL) decompress plaintext\n promise = promise.then(function(jwe) {\n if (\"DEF\" === jwe.header.zip) {\n return new Promise(function(resolve, reject) {\n try {\n var data = pako.inflateRaw(Buffer.from(jwe.plaintext))\n\n jwe.payload = jwe.plaintext = Buffer.from(data);\n resolve(jwe);\n } catch (err) {\n reject(err);\n }\n });\n }\n\n return jwe;\n });\n\n // process any post-decrypt handlers\n promise = promise.then(function(jwe) {\n var processing = [];\n handlerKeys.forEach(function(h) {\n h = extraHandlers[h];\n var p;\n if (\"object\" === typeof h && \"function\" === typeof h.complete) {\n p = h.complete(jwe);\n }\n if (p) {\n processing.push(Promise.resolve(p));\n }\n });\n return Promise.all(processing).then(function() {\n // don't actually care about individual handler results\n // assume {jwe} is updated\n return jwe;\n });\n });\n\n return promise;\n }\n });\n}\n\n/**\n * @description\n * Creates a new Decrypter for the given Key or KeyStore.\n *\n * {opts}, when provided, is used to customize decryption processes. The\n * following options are currently supported:\n *\n * - `handlers` - An object where each name is a JOSE header member name and\n * the value can be a boolean, function, or an object.\n *\n * Handlers are intended to support 'crit' extensions. When a boolean value,\n * the member is expected to be processed once decryption is fully complete.\n * When a function, it is called just before the ciphertext is decrypted\n * (processed as if it were a `prepare` handler, as decribed below). When an\n * object, it can contain any of the following members:\n *\n * - `recipient` - A function called after a valid key is determined; it takes\n * an object describing the recipient, and returns a Promise that is\n * fulfilled once the handler's processing is complete.\n * - `prepare` - A function called just prior to decrypting the ciphertext;\n * it takes an object describing the decryption result (but containing\n * `ciphertext` and `tag' instead of `payload` and `plaintext`), and\n * returns a Promise that is fulfilled once the handler's processing is\n * complete.\n * - `complete` - A function called once decryption is complete, just prior\n * to fulfilling the Promise returned by `decrypt()`; it takes the object\n * that will be returned by `decrypt()`'s fulfilled Promise, and returns\n * a Promise that is fulfilled once the handler's processing is complete.\n *\n * Note that normal processing of `decrypt()` does not continue until all\n * relevant handlers have completed. Any changes handlers make to the\n * provided objects affects `decrypt()`'s processing.\n *\n * @param {JWK.Key|JWK.KeyStore} ks The Key or KeyStore to use for decryption.\n * @param {Object} [opts] The options for this Decrypter.\n * @returns {JWE.Decrypter} The new Decrypter.\n */\nfunction createDecrypt(ks, opts) {\n var dec = new JWEDecrypter(ks, opts);\n return dec;\n}\n\nmodule.exports = {\n decrypter: JWEDecrypter,\n createDecrypt: createDecrypt\n};\n","/*!\n * jwe/defaults.js - Defaults for JWEs\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\n/**\n * @description\n * The default options for {@link JWE.createEncrypt}.\n *\n * @property {Boolean|String} zip Determines the compression algorithm to\n * apply to the plaintext (if any) before it is encrypted. This can\n * also be `true` (which is equivalent to `\"DEF\"`) or **`false`**\n * (the default, which is equivalent to no compression).\n * @property {String} format Determines the serialization format of the\n * output. Expected to be `\"general\"` for general JSON\n * Serialization, `\"flattened\"` for flattened JSON Serialization,\n * or `\"compact\"` for Compact Serialization (default is\n * **`\"general\"`**).\n * @property {Boolean} compact Determines if the output is the Compact\n * serialization (`true`) or the JSON serialization (**`false`**,\n * the default).\n * @property {String} contentAlg The algorithm used to encrypt the plaintext\n * (default is **`\"A128CBC-HS256\"`**).\n * @property {String|String[]} protect The names of the headers to integrity\n * protect. The value `\"\"` means that none of the header parameters\n * are integrity protected, while `\"*\"` (the default) means that all\n * header parameters are integrity protected.\n */\nvar JWEDefaults = {\n zip: false,\n format: \"general\",\n contentAlg: \"A128CBC-HS256\",\n protect: \"*\"\n};\n\nmodule.exports = JWEDefaults;\n","/*!\n * jwe/encrypt.js - Encrypt to a JWE\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar util = require(\"../util\"),\n generateCEK = require(\"./helpers\").generateCEK,\n JWK = require(\"../jwk\"),\n slice = require(\"./helpers\").slice,\n pako = require(\"pako\"),\n CONSTANTS = require(\"../algorithms/constants\");\n\nvar assign = require(\"lodash/assign\");\nvar clone = require(\"lodash/clone\");\nvar DEFAULTS = require(\"./defaults\");\n\n/**\n * @class JWE.Encrypter\n * @classdesc\n * Generator of encrypted data.\n *\n * @description\n * **NOTE:** This class cannot be instantiated directly. Instead call {@link\n * JWE.createEncrypt}.\n */\nfunction JWEEncrypter(cfg, fields, recipients) {\n var finalized = false,\n format = cfg.format || \"general\",\n protectAll = !!cfg.protectAll,\n content = Buffer.alloc(0);\n\n /**\n * @member {String} JWE.Encrypter#zip\n * @readonly\n * @description\n * Indicates the compression algorithm applied to the plaintext\n * before it is encrypted. The possible values are:\n *\n * + **`\"DEF\"`**: Compress the plaintext using the DEFLATE algorithm.\n * + **`\"\"`**: Do not compress the plaintext.\n */\n Object.defineProperty(this, \"zip\", {\n get: function() {\n return fields.zip || \"\";\n },\n enumerable: true\n });\n /**\n * @member {Boolean} JWE.Encrypter#compact\n * @readonly\n * @description\n * Indicates whether the output of this encryption generator is\n * using the Compact serialization (`true`) or the JSON\n * serialization (`false`).\n */\n Object.defineProperty(this, \"compact\", {\n get: function() { return \"compact\" === format; },\n enumerable: true\n });\n /**\n * @member {String} JWE.Encrypter#format\n * @readonly\n * @description\n * Indicates the format the output of this encryption generator takes.\n */\n Object.defineProperty(this, \"format\", {\n get: function() { return format; },\n enumerable: true\n });\n /**\n * @member {String[]} JWE.Encrypter#protected\n * @readonly\n * @description\n * The header parameter names that are protected. Protected header fields\n * are first serialized to UTF-8 then encoded as util.base64url, then used as\n * the additional authenticated data in the encryption operation.\n */\n Object.defineProperty(this, \"protected\", {\n get: function() {\n return clone(cfg.protect);\n },\n enumerable: true\n });\n /**\n * @member {Object} JWE.Encrypter#header\n * @readonly\n * @description\n * The global header parameters, both protected and unprotected. Call\n * {@link JWE.Encrypter#protected} to determine which parameters will\n * be protected.\n */\n Object.defineProperty(this, \"header\", {\n get: function() {\n return clone(fields);\n },\n enumerable: true\n });\n\n /**\n * @method JWE.Encrypter#update\n * @description\n * Updates the plaintext data for the encryption generator. The plaintext\n * is appended to the end of any other plaintext already applied.\n *\n * If {data} is a Buffer, {encoding} is ignored. Otherwise, {data} is\n * converted to a Buffer internally to {encoding}.\n *\n * @param {Buffer|String} [data] The plaintext to apply.\n * @param {String} [encoding] The encoding of the plaintext.\n * @returns {JWE.Encrypter} This encryption generator.\n * @throws {Error} If ciphertext has already been generated.\n */\n Object.defineProperty(this, \"update\", {\n value: function(data, encoding) {\n if (finalized) {\n throw new Error(\"already final\");\n }\n if (data != null) {\n data = util.asBuffer(data, encoding);\n if (content.length) {\n content = Buffer.concat([content, data],\n content.length + data.length);\n } else {\n content = data;\n }\n }\n\n return this;\n }\n });\n /**\n * @method JWE.Encrypter#final\n * @description\n * Finishes the encryption operation.\n *\n * The returned Promise, when fulfilled, is the JSON Web Encryption (JWE)\n * object, either in the Compact (if {@link JWE.Encrypter#compact} is\n * `true`) or the JSON serialization.\n *\n * @param {Buffer|String} [data] The final plaintext data to apply.\n * @param {String} [encoding] The encoding of the final plaintext data\n * (if any).\n * @returns {Promise} A promise for the encryption operation.\n * @throws {Error} If ciphertext has already been generated.\n */\n Object.defineProperty(this, \"final\", {\n value: function(data, encoding) {\n if (finalized) {\n return Promise.reject(new Error(\"already final\"));\n }\n\n // last-minute data\n this.update(data, encoding);\n\n // mark as done...ish\n finalized = true;\n var promise = Promise.resolve({});\n\n // determine CEK and IV\n var encAlg = fields.enc;\n var encKey;\n promise = promise.then(function(jwe) {\n if (cfg.cek) {\n encKey = JWK.asKey(cfg.cek);\n }\n return jwe;\n });\n\n // process recipients\n promise = promise.then(function(jwe) {\n var procR = function(r, one) {\n var props = {};\n props = assign(props, fields);\n props = assign(props, r.header);\n\n var algKey = r.key,\n algAlg = props.alg;\n\n // generate Ephemeral EC Key\n var tks,\n rpromise;\n if ((props.alg || \"\").indexOf(\"ECDH-ES\") === 0) {\n tks = algKey.keystore.temp();\n if (r.epk) {\n rpromise = Promise.resolve(r.epk).\n then(function(epk) {\n r.header.epk = epk.toJSON(false, [\"kid\"]);\n props.epk = epk.toObject(true, [\"kid\"]);\n });\n } else {\n rpromise = tks.generate(\"EC\", algKey.get(\"crv\")).\n then(function(epk) {\n r.header.epk = epk.toJSON(false, [\"kid\"]);\n props.epk = epk.toObject(true, [\"kid\"]);\n });\n }\n } else {\n rpromise = Promise.resolve();\n }\n\n // encrypt the CEK\n rpromise = rpromise.then(function() {\n var cek,\n p;\n // special case 'alg=dir'\n if (\"dir\" === algAlg && one) {\n encKey = Promise.resolve(algKey);\n p = encKey.then(function(jwk) {\n // fixup encAlg\n if (!encAlg) {\n props.enc = fields.enc = encAlg = jwk.algorithms(JWK.MODE_ENCRYPT)[0];\n }\n return {\n once: true,\n direct: true\n };\n });\n } else {\n if (!encKey) {\n if (!encAlg) {\n props.enc = fields.enc = encAlg = cfg.contentAlg;\n }\n encKey = generateCEK(encAlg);\n }\n p = encKey.then(function(jwk) {\n cek = jwk.get(\"k\", true);\n // algKey may or may not be a promise\n return algKey;\n });\n p = p.then(function(algKey) {\n return algKey.wrap(algAlg, cek, props);\n });\n }\n return p;\n });\n rpromise = rpromise.then(function(wrapped) {\n if (wrapped.once && !one) {\n return Promise.reject(new Error(\"cannot use 'alg':'\" + algAlg + \"' with multiple recipients\"));\n }\n\n var rjwe = {},\n cek;\n if (wrapped.data) {\n cek = wrapped.data;\n cek = util.base64url.encode(cek);\n }\n\n if (wrapped.direct && cek) {\n // replace content key\n encKey = JWK.asKey({\n kty: \"oct\",\n k: cek\n });\n } else if (cek) {\n /* eslint camelcase: [0] */\n rjwe.encrypted_key = cek;\n }\n\n if (r.header && Object.keys(r.header).length) {\n rjwe.header = clone(r.header || {});\n }\n if (wrapped.header) {\n rjwe.header = assign(rjwe.header || {},\n wrapped.header);\n }\n\n return rjwe;\n });\n return rpromise;\n };\n\n var p = Promise.all(recipients);\n p = p.then(function(rcpts) {\n var single = (1 === rcpts.length);\n rcpts = rcpts.map(function(r) {\n return procR(r, single);\n });\n return Promise.all(rcpts);\n });\n p = p.then(function(rcpts) {\n jwe.recipients = rcpts.filter(function(r) { return !!r; });\n return jwe;\n });\n return p;\n });\n\n // normalize headers\n var props = {};\n promise = promise.then(function(jwe) {\n var protect,\n lenProtect,\n unprotect,\n lenUnprotect;\n\n unprotect = clone(fields);\n if ((protectAll && jwe.recipients.length === 1) || \"compact\" === format) {\n // merge single recipient into fields\n protect = {};\n protect = assign({},\n unprotect,\n jwe.recipients[0].header);\n lenProtect = Object.keys(protect).length;\n\n unprotect = undefined;\n lenUnprotect = 0;\n\n delete jwe.recipients[0].header;\n if (Object.keys(jwe.recipients[0]).length === 0) {\n jwe.recipients.splice(0, 1);\n }\n } else {\n protect = {};\n lenProtect = 0;\n lenUnprotect = Object.keys(unprotect).length;\n cfg.protect.forEach(function(f) {\n // remove protected header values from body unprotected header\n if (!(f in unprotect)) {\n return;\n }\n protect[f] = unprotect[f];\n lenProtect++;\n\n delete unprotect[f];\n lenUnprotect--;\n });\n\n jwe.recipients = (jwe.recipients || []).map(function(rcpt) {\n rcpt = rcpt || {};\n var header = rcpt.header;\n if (header) {\n Object.keys(header).forEach(function (f) {\n if (f in protect) { delete header[f]; }\n });\n if (!Object.keys(header).length) {\n delete rcpt.header;\n }\n }\n return rcpt;\n });\n }\n\n if (!jwe.recipients || jwe.recipients.length === 0) {\n delete jwe.recipients;\n }\n\n // \"serialize\" (and setup merged props)\n if (unprotect && lenUnprotect > 0) {\n props = assign(props, unprotect);\n jwe.unprotected = unprotect;\n }\n if (protect && lenProtect > 0) {\n props = assign(props, protect);\n protect = JSON.stringify(protect);\n jwe.protected = util.base64url.encode(protect, \"utf8\");\n }\n\n return jwe;\n });\n\n // (OPTIONAL) compress plaintext\n promise = promise.then(function(jwe) {\n var pdata = content;\n if (!props.zip) {\n jwe.plaintext = pdata;\n return jwe;\n } else if (props.zip === \"DEF\") {\n return new Promise(function(resolve, reject) {\n try {\n var data = pako.deflateRaw(Buffer.from(pdata, \"binary\"));\n\n jwe.plaintext = Buffer.from(data);\n resolve(jwe);\n } catch (error) {\n reject(error);\n }\n });\n }\n return Promise.reject(new Error(\"unsupported 'zip' mode\"));\n });\n\n // encrypt plaintext\n promise = promise.then(function(jwe) {\n props.adata = jwe.protected;\n if (\"aad\" in cfg && cfg.aad != null) {\n props.adata += \".\" + cfg.aad;\n props.adata = Buffer.from(props.adata, \"utf8\");\n }\n // calculate IV\n var iv = cfg.iv ||\n util.randomBytes(CONSTANTS.NONCELENGTH[encAlg] / 8);\n if (\"string\" === typeof iv) {\n iv = util.base64url.decode(iv);\n }\n props.iv = iv;\n\n if (\"recipients\" in jwe && jwe.recipients.length === 1) {\n props.kdata = jwe.recipients[0].encrypted_key;\n }\n\n if (\"epu\" in cfg && cfg.epu != null) {\n props.epu = cfg.epu;\n }\n\n if (\"epv\" in cfg && cfg.epv != null) {\n props.epv = cfg.epv;\n }\n\n var pdata = jwe.plaintext;\n delete jwe.plaintext;\n return encKey.then(function(encKey) {\n var p = encKey.encrypt(encAlg, pdata, props);\n p = p.then(function(result) {\n jwe.iv = util.base64url.encode(iv, \"binary\");\n if (\"aad\" in cfg && cfg.aad != null) {\n jwe.aad = cfg.aad;\n }\n jwe.ciphertext = util.base64url.encode(result.data, \"binary\");\n jwe.tag = util.base64url.encode(result.tag, \"binary\");\n return jwe;\n });\n return p;\n });\n });\n\n // (OPTIONAL) compact/flattened results\n switch (format) {\n case \"compact\":\n promise = promise.then(function(jwe) {\n var compact = new Array(5);\n\n compact[0] = jwe.protected;\n if (jwe.recipients && jwe.recipients[0]) {\n compact[1] = jwe.recipients[0].encrypted_key;\n }\n\n compact[2] = jwe.iv;\n compact[3] = jwe.ciphertext;\n compact[4] = jwe.tag;\n compact = compact.join(\".\");\n\n return compact;\n });\n break;\n case \"flattened\":\n promise = promise.then(function(jwe) {\n var flattened = {},\n rcpt = jwe.recipients && jwe.recipients[0];\n\n if (jwe.protected) {\n flattened.protected = jwe.protected;\n }\n if (jwe.unprotected) {\n flattened.unprotected = jwe.unprotected;\n }\n [\"header\", \"encrypted_key\"].forEach(function(f) {\n if (!rcpt) { return; }\n if (!(f in rcpt)) { return; }\n if (!rcpt[f]) { return; }\n if (\"object\" === typeof rcpt[f] && !Object.keys(rcpt[f]).length) { return; }\n flattened[f] = rcpt[f];\n });\n if (jwe.aad) {\n flattened.aad = jwe.aad;\n }\n flattened.iv = jwe.iv;\n flattened.ciphertext = jwe.ciphertext;\n flattened.tag = jwe.tag;\n\n return flattened;\n });\n break;\n case \"general\":\n promise = promise.then(function(jwe) {\n var recipients = jwe.recipients || [];\n recipients = recipients.map(function (rcpt) {\n if (!Object.keys(rcpt).length) { return undefined; }\n return rcpt;\n });\n recipients = recipients.filter(function (rcpt) { return !!rcpt; });\n if (recipients.length) {\n jwe.recipients = recipients;\n } else {\n delete jwe.recipients;\n }\n\n return jwe;\n });\n }\n\n return promise;\n }\n });\n}\n\nfunction createEncrypt(opts, rcpts) {\n // fixup recipients\n var options = opts,\n rcptStart = 1,\n rcptList = rcpts;\n\n if (arguments.length === 0) {\n throw new Error(\"at least one recipient must be provided\");\n }\n if (arguments.length === 1) {\n // assume opts is the recipient list\n rcptList = opts;\n rcptStart = 0;\n options = {};\n } else if (JWK.isKey(opts) ||\n (opts && \"kty\" in opts) ||\n (opts && \"key\" in opts &&\n (JWK.isKey(opts.key) || \"kty\" in opts.key))) {\n rcptList = opts;\n rcptStart = 0;\n options = {};\n } else {\n options = clone(opts);\n }\n if (!Array.isArray(rcptList)) {\n rcptList = slice(arguments, rcptStart);\n }\n\n // fixup options\n options = assign(clone(DEFAULTS), options);\n\n // setup header fields\n var fields = clone(options.fields || {});\n if (options.zip) {\n fields.zip = (typeof options.zip === \"boolean\") ?\n (options.zip ? \"DEF\" : false) :\n options.zip;\n }\n options.format = (options.compact ? \"compact\" : options.format) || \"general\";\n switch (options.format) {\n case \"compact\":\n if (\"aad\" in opts) {\n throw new Error(\"additional authenticated data cannot be used for compact serialization\");\n }\n /* eslint no-fallthrough: [0] */\n case \"flattened\":\n if (rcptList.length > 1) {\n throw new Error(\"too many recipients for compact serialization\");\n }\n break;\n }\n\n // note protected fields (globally)\n // protected fields are global only\n var protectAll = false;\n if (\"compact\" === options.format || \"*\" === options.protect) {\n protectAll = true;\n options.protect = Object.keys(fields).concat(\"enc\");\n } else if (typeof options.protect === \"string\") {\n options.protect = [options.protect];\n } else if (Array.isArray(options.protect)) {\n options.protect = options.protect.concat();\n } else if (!options.protect) {\n options.protect = [];\n } else {\n throw new Error(\"protect must be a list of fields\");\n }\n\n if (protectAll && 1 < rcptList.length) {\n throw new Error(\"too many recipients to protect all header parameters\");\n }\n\n rcptList = rcptList.map(function(r, idx) {\n var p;\n\n // resolve a key\n if (r && \"kty\" in r) {\n p = JWK.asKey(r);\n p = p.then(function(k) {\n return {\n key: k\n };\n });\n } else if (r) {\n p = JWK.asKey(r.key);\n p = p.then(function(k) {\n return {\n header: r.header,\n reference: r.reference,\n key: k\n };\n });\n } else {\n p = Promise.reject(new Error(\"missing key for recipient \" + idx));\n }\n\n // convert ephemeral key (if present)\n if (r.epk) {\n p = p.then(function(recipient) {\n return JWK.asKey(r.epk).\n then(function(epk) {\n recipient.epk = epk;\n return recipient;\n });\n });\n }\n\n // resolve the complete recipient\n p = p.then(function(recipient) {\n var key = recipient.key;\n\n // prepare the recipient header\n var header = recipient.header || {};\n recipient.header = header;\n var props = {};\n props = assign(props, fields);\n props = assign(props, recipient.header);\n\n // ensure key protection algorithm is set\n if (!props.alg) {\n props.alg = key.algorithms(JWK.MODE_WRAP)[0];\n header.alg = props.alg;\n }\n if (!props.alg) {\n return Promise.reject(new Error(\"key not valid for encrypting to recipient \" + idx));\n }\n header.alg = props.alg;\n\n // determine the key reference\n var ref = recipient.reference;\n delete recipient.reference;\n if (undefined === ref) {\n // header already contains the key reference\n ref = [\"kid\", \"jku\", \"x5c\", \"x5t\", \"x5u\"].some(function(k) {\n return (k in header);\n });\n ref = !ref ? \"kid\" : null;\n } else if (\"boolean\" === typeof ref) {\n // explicit (positive | negative) request for key reference\n ref = ref ? \"kid\" : null;\n }\n var jwk;\n if (ref) {\n jwk = key.toJSON();\n if (\"jwk\" === ref) {\n if (\"oct\" === key.kty) {\n return Promise.reject(new Error(\"cannot embed key\"));\n }\n header.jwk = jwk;\n } else if (ref in jwk) {\n header[ref] = jwk[ref];\n }\n }\n\n // freeze recipient\n recipient = Object.freeze(recipient);\n return recipient;\n });\n\n return p;\n });\n\n // create and configure encryption\n var cfg = {\n aad: (\"aad\" in options) ? util.base64url.encode(options.aad || \"\") : null,\n contentAlg: options.contentAlg,\n format: options.format,\n protect: options.protect,\n cek: options.cek,\n iv: options.iv,\n protectAll: protectAll\n };\n var enc = new JWEEncrypter(cfg, fields, rcptList);\n\n return enc;\n}\n\nmodule.exports = {\n encrypter: JWEEncrypter,\n createEncrypt: createEncrypt\n};\n","/*!\n * jwe/helpers.js - JWE Internal Helper Functions\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar CONSTANTS = require(\"../algorithms/constants\"),\n JWK = require(\"../jwk\");\n\nmodule.exports = {\n slice: function(input, start) {\n return Array.prototype.slice.call(input, start || 0);\n },\n generateCEK: function(enc) {\n var ks = JWK.createKeyStore();\n var len = CONSTANTS.KEYLENGTH[enc];\n\n if (len) {\n return ks.generate(\"oct\", len);\n }\n\n throw new Error(\"unsupported encryption algorithm\");\n }\n};\n","/*!\n * jwe/index.js - JSON Web Encryption (JWE) Entry Point\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar JWE = {\n createEncrypt: require(\"./encrypt\").createEncrypt,\n createDecrypt: require(\"./decrypt\").createDecrypt\n};\n\nmodule.exports = JWE;\n","/*!\n * jwk/basekey.js - JWK Key Base Class Implementation\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar merge = require(\"../util/merge\");\nconst { v4: uuidv4 } = require(\"uuid\");\n\nvar assign = require(\"lodash/assign\");\nvar clone = require(\"lodash/clone\");\nvar flatten = require(\"lodash/flatten\");\nvar intersection = require(\"lodash/intersection\");\nvar omit = require(\"lodash/omit\");\nvar pick = require(\"lodash/pick\");\nvar uniq = require(\"lodash/uniq\");\n\nvar ALGORITHMS = require(\"../algorithms\"),\n CONSTANTS = require(\"./constants.js\"),\n HELPERS = require(\"./helpers.js\"),\n UTIL = require(\"../util\");\n\n/**\n * @class JWK.Key\n * @classdesc\n * Represents a JSON Web Key instance.\n *\n * @description\n * **NOTE:** This class cannot be instantiated directly. Instead call\n * {@link JWK.asKey}, {@link JWK.KeyStore#add}, or\n * {@link JWK.KeyStore#generate}.\n */\nvar JWKBaseKeyObject = function(kty, ks, props, cfg) {\n // ### validate/coerce arguments ###\n if (!kty) {\n throw new Error(\"kty cannot be null\");\n }\n\n if (!ks) {\n throw new Error(\"keystore cannot be null\");\n }\n\n if (!props) {\n throw new Error(\"props cannot be null\");\n } else if (\"string\" === typeof props) {\n props = JSON.parse(props);\n }\n\n if (!cfg) {\n throw new Error(\"cfg cannot be null\");\n }\n\n var excluded = [];\n var keys = {},\n json = {},\n prints,\n kid;\n\n props = clone(props);\n // strip thumbprints if present\n prints = assign({}, props[HELPERS.INTERNALS.THUMBPRINT_KEY] || {});\n delete props[HELPERS.INTERNALS.THUMBPRINT_KEY];\n Object.keys(prints).forEach(function(a) {\n var h = prints[a];\n if (!kid) {\n kid = h;\n if (Buffer.isBuffer(kid)) {\n kid = UTIL.base64url.encode(kid);\n }\n }\n if (!Buffer.isBuffer(h)) {\n h = UTIL.base64url.decode(h);\n prints[a] = h;\n }\n });\n\n // force certain values\n props.kty = kty;\n props.kid = props.kid || kid || uuidv4();\n\n // setup base info\n var included = Object.keys(HELPERS.COMMON_PROPS).map(function(p) {\n return HELPERS.COMMON_PROPS[p].name;\n });\n json.base = pick(props, included);\n excluded = excluded.concat(Object.keys(json.base));\n\n // setup public information\n json.public = clone(props);\n keys.public = cfg.publicKey(json.public);\n if (keys.public) {\n // exclude public values from extra\n excluded = excluded.concat(Object.keys(json.public));\n }\n\n // setup private information\n json.private = clone(props);\n keys.private = cfg.privateKey(json.private);\n if (keys.private) {\n // exclude private values from extra\n excluded = excluded.concat(Object.keys(json.private));\n }\n\n // setup extra information\n json.extra = omit(props, excluded);\n\n // TODO: validate 'alg' against supported algorithms\n\n // setup calculated values\n var keyLen;\n if (keys.public && (\"length\" in keys.public)) {\n keyLen = keys.public.length;\n } else if (keys.private && (\"length\" in keys.private)) {\n keyLen = keys.private.length;\n } else {\n keyLen = NaN;\n }\n\n // ### Public Properties ###\n /**\n * @member {JWK.KeyStore} JWK.Key#keystore\n * @description\n * The owning keystore.\n */\n Object.defineProperty(this, \"keystore\", {\n value: ks,\n enumerable: true\n });\n /**\n * @member {Number} JWK.Key#length\n * @description\n * The size of this Key, in bits.\n */\n Object.defineProperty(this, \"length\", {\n value: keyLen,\n enumerable: true\n });\n /**\n * @member {String} JWK.Key#kty\n * @description\n * The type of Key.\n */\n Object.defineProperty(this, \"kty\", {\n value: kty,\n enumerable: true\n });\n\n /**\n * @member {String} JWK.Key#kid\n * @description\n * The identifier for this Key.\n */\n Object.defineProperty(this, \"kid\", {\n value: json.base.kid,\n enumerable: true\n });\n /**\n * @member {String} JWK.Key#use\n * @description\n * The usage for this Key.\n */\n Object.defineProperty(this, \"use\", {\n value: json.base.use || \"\",\n enumerable: true\n });\n /**\n * @member {String} JWK.Key#alg\n * @description\n * The sole algorithm this key can be used for.\n */\n Object.defineProperty(this, \"alg\", {\n value: json.base.alg || \"\",\n enumerable: true\n });\n\n // ### Public Methods ###\n /**\n * Generates the thumbprint of this Key.\n *\n * @param {String} [] The hash algorithm to use\n * @returns {Promise} The promise for the thumbprint generation.\n */\n Object.defineProperty(this, \"thumbprint\", {\n value: function(hash) {\n hash = (hash || HELPERS.INTERNALS.THUMBPRINT_HASH).toUpperCase();\n if (prints[hash]) {\n // return cached value\n return Promise.resolve(prints[hash]);\n }\n var p = HELPERS.thumbprint(cfg, json, hash);\n p = p.then(function(result) {\n if (result) {\n prints[hash] = result;\n }\n return result;\n });\n return p;\n }\n });\n /**\n * @method JWK.Key#algorithms\n * @description\n * The possible algorithms this Key can be used for. The returned\n * list is not any particular order, but is filtered based on the\n * Key's intended usage.\n *\n * @param {String} mode The operation mode\n * @returns {String[]} The list of supported algorithms\n * @see JWK.Key#supports\n */\n Object.defineProperty(this, \"algorithms\", {\n value: function(mode) {\n var modes = [];\n if (!this.use || this.use === \"sig\") {\n if (!mode || CONSTANTS.MODE_SIGN === mode) {\n modes.push(CONSTANTS.MODE_SIGN);\n }\n if (!mode || CONSTANTS.MODE_VERIFY === mode) {\n modes.push(CONSTANTS.MODE_VERIFY);\n }\n }\n if (!this.use || this.use === \"enc\") {\n if (!mode || CONSTANTS.MODE_ENCRYPT === mode) {\n modes.push(CONSTANTS.MODE_ENCRYPT);\n }\n if (!mode || CONSTANTS.MODE_DECRYPT === mode) {\n modes.push(CONSTANTS.MODE_DECRYPT);\n }\n if (!mode || CONSTANTS.MODE_WRAP === mode) {\n modes.push(CONSTANTS.MODE_WRAP);\n }\n if (!mode || CONSTANTS.MODE_UNWRAP === mode) {\n modes.push(CONSTANTS.MODE_UNWRAP);\n }\n }\n\n var self = this;\n var algs = modes.map(function(m) {\n return cfg.algorithms.call(self, keys, m);\n });\n algs = flatten(algs);\n algs = uniq(algs);\n if (this.alg) {\n // TODO: fix this correctly\n var valid;\n if (\"oct\" === kty) {\n valid = [this.alg, \"dir\"];\n } else {\n valid = [this.alg];\n }\n algs = intersection(algs, valid);\n }\n\n return algs;\n }\n });\n /**\n * @method JWK.Key#supports\n * @description\n * Determines if the given algorithm is supported.\n *\n * @param {String} alg The algorithm in question\n * @param {String} [mode] The operation mode\n * @returns {Boolean} `true` if {alg} is supported, and `false` otherwise.\n * @see JWK.Key#algorithms\n */\n Object.defineProperty(this, \"supports\", {\n value: function(alg, mode) {\n return (this.algorithms(mode).indexOf(alg) !== -1);\n }\n });\n /**\n * @method JWK.Key#has\n * @description\n * Determines if this Key contains the given parameter.\n *\n * @param {String} name The name of the parameter\n * @param {Boolean} [isPrivate=false] `true` if private parameters should be\n * checked.\n * @returns {Boolean} `true` if the given parameter is present; `false`\n * otherwise.\n */\n Object.defineProperty(this, \"has\", {\n value: function(name, isPrivate) {\n var contains = false;\n contains = contains || !!(json.base &&\n (name in json.base));\n contains = contains || !!(keys.public &&\n (name in keys.public));\n contains = contains || !!(json.extra &&\n (name in json.extra));\n contains = contains || !!(isPrivate &&\n keys.private &&\n (name in keys.private));\n // TODO: check for export restrictions\n\n return contains;\n }\n });\n /**\n * @method JWK.Key#get\n * @description\n * Retrieves the value of the given parameter. The value returned by this\n * method is in its natural format, which might not exactly match its\n * JSON encoding (e.g., a binary string rather than a base64url-encoded\n * string).\n *\n * **NOTE:** This method can return `false`. Call\n * {@link JWK.Key#has} to determine if the parameter is present.\n *\n * @param {String} name The name of the parameter\n * @param {Boolean} [isPrivate=false] `true` if private parameters should\n * be checked.\n * @returns {any} The value of the named parameter, or undefined if\n * it is not present.\n */\n Object.defineProperty(this, \"get\", {\n value: function(name, isPrivate) {\n var src;\n if (json.base && (name in json.base)) {\n src = json.base;\n } else if (keys.public && (name in keys.public)) {\n src = keys.public;\n } else if (json.extra && (name in json.extra)) {\n src = json.extra;\n } else if (isPrivate && keys.private && (name in keys.private)) {\n // TODO: check for export restrictions\n src = keys.private;\n }\n\n return src && src[name] || null;\n }\n });\n /**\n * @method JWK.Key#toJSON\n * @description\n * Returns the JSON representation of this Key. All properties of the\n * returned JSON object are properly encoded (e.g., base64url encoding for\n * any binary strings).\n *\n * @param {Boolean} [isPrivate=false] `true` if private parameters should be\n * included.\n * @param {String[]} [excluded] The list of parameters to exclude from\n * the returned JSON.\n * @returns {Object} The plain JSON object\n */\n Object.defineProperty(this, \"toJSON\", {\n value: function(isPrivate, excluded) {\n // coerce arguments\n if (Array.isArray(isPrivate)) {\n excluded = isPrivate;\n isPrivate = false;\n }\n var result = {};\n\n // TODO: check for export restrictions\n result = merge(result,\n json.base,\n json.public,\n (\"boolean\" === typeof isPrivate && isPrivate) ? json.private : {},\n json.extra);\n result = omit(result, excluded || []);\n\n return result;\n }\n });\n\n /**\n * @method JWK.Key#toPEM\n * @description\n * Returns the PEM representation of this Key as a string.\n *\n * @param {Boolean} [isPrivate=false] `true` if private parameters should be\n * included.\n * @returns {string} The PEM-encoded string\n */\n Object.defineProperty(this, \"toPEM\", {\n value: function(isPrivate) {\n if (isPrivate === null) {\n isPrivate = false;\n }\n\n if (!cfg.convertToPEM) {\n throw new Error(\"Unsupported key type for PEM encoding\");\n }\n var k = (isPrivate) ? keys.private : keys.public;\n if (!k) {\n throw new Error(\"Invalid key\");\n }\n return cfg.convertToPEM.call(this, k, isPrivate);\n }\n });\n\n /**\n * @method JWK.Key#toObject\n * @description\n * Returns the plain object representing this Key. All properties of the\n * returned object are in their natural encoding (e.g., binary strings\n * instead of base64url encoded).\n *\n * @param {Boolean} [isPrivate=false] `true` if private parameters should be\n * included.\n * @param {String[]} [excluded] The list of parameters to exclude from\n * the returned object.\n * @returns {Object} The plain Object.\n */\n Object.defineProperty(this, \"toObject\", {\n value: function(isPrivate, excluded) {\n // coerce arguments\n if (Array.isArray(isPrivate)) {\n excluded = isPrivate;\n isPrivate = false;\n }\n var result = {};\n\n // TODO: check for export restrictions\n result = merge(result,\n json.base,\n keys.public,\n (\"boolean\" === typeof isPrivate && isPrivate) ? keys.private : {},\n json.extra);\n result = omit(result, (excluded || []).concat(\"length\"));\n\n return result;\n }\n });\n\n /**\n * @method JWK.Key#sign\n * @description\n * Sign the given data using the specified algorithm.\n *\n * **NOTE:** This is the primitive signing operation; the output is\n * _**NOT**_ a JSON Web Signature (JWS) object.\n *\n * The Promise, when fulfilled, returns an Object with the following\n * properties:\n *\n * + **data**: The data that was signed (and should be equal to {data}).\n * + **mac**: The signature or message authentication code (MAC).\n *\n * @param {String} alg The signing algorithm\n * @param {String|Buffer} data The data to sign\n * @param {Object} [props] Additional properties for the signing\n * algorithm.\n * @returns {Promise} The promise for the signing operation.\n * @throws {Error} If {alg} is not appropriate for this Key; or if\n * this Key does not contain the appropriate parameters.\n */\n Object.defineProperty(this, \"sign\", {\n value: function(alg, data, props) {\n // validate appropriateness\n if (this.algorithms(\"sign\").indexOf(alg) === -1) {\n return Promise.reject(new Error(\"unsupported algorithm\"));\n }\n var k = cfg.signKey.call(this, alg, keys);\n if (!k) {\n return Promise.reject(new Error(\"improper key\"));\n }\n\n // prepare properties (if any)\n props = (props) ?\n clone(props) :\n {};\n if (cfg.signProps) {\n props = merge(props, cfg.signProps.call(this, alg, props));\n }\n return ALGORITHMS.sign(alg, k, data, props);\n }\n });\n /**\n * @method JWK.Key#verify\n * @description\n * Verify the given data and signature using the specified algorithm.\n *\n * **NOTE:** This is the primitive verification operation; the input is\n * _**NOT**_ a JSON Web Signature.

\n *\n * The Promise, when fulfilled, returns an Object with the following\n * properties:\n *\n * + **data**: The data that was verified (and should be equal to\n * {data}).\n * + **mac**: The signature or MAC that was verified (and should be equal\n * to {mac}).\n * + **valid**: `true` if {mac} is valid for {data}.\n *\n * @param {String} alg The verification algorithm\n * @param {String|Buffer} data The data to verify\n * @param {String|Buffer} mac The signature or MAC to verify\n * @param {Object} [props] Additional properties for the verification\n * algorithm.\n * @returns {Promise} The promise for the verification operation.\n * @throws {Error} If {alg} is not appropriate for this Key; or if\n * the Key does not contain the appropriate properties.\n */\n Object.defineProperty(this, \"verify\", {\n value: function(alg, data, mac, props) {\n // validate appropriateness\n if (this.algorithms(\"verify\").indexOf(alg) === -1) {\n return Promise.reject(new Error(\"unsupported algorithm\"));\n }\n var k = cfg.verifyKey.call(this, alg, keys);\n if (!k) {\n return Promise.reject(new Error(\"improper key\"));\n }\n\n // prepare properties (if any)\n props = (props) ?\n clone(props) :\n {};\n if (cfg.verifyProps) {\n props = merge(props, cfg.verifyProps.call(this, alg, props));\n }\n return ALGORITHMS.verify(alg, k, data, mac, props);\n }\n });\n\n /**\n * @method JWK.Key#encrypt\n * @description\n * Encrypts the given data using the specified algorithm.\n *\n * **NOTE:** This is the primitive encryption operation; the output is\n * _**NOT**_ a JSON Web Encryption (JWE) object.\n *\n * **NOTE:** This operation is treated as distinct from {@link\n * JWK.Key#wrap}, as different algorithms and properties are often\n * used for wrapping a key versues encrypting arbitrary data.\n *\n * The Promise, when fulfilled, returns an object with the following\n * properties:\n *\n * + **data**: The ciphertext data\n * + **mac**: The associated message authentication code (MAC).\n *\n * @param {String} alg The encryption algorithm\n * @param {Buffer|String} data The data to encrypt\n * @param {Object} [props] Additional properties for the encryption\n * algorithm.\n * @returns {Promise} The promise for the encryption operation.\n * @throws {Error} If {alg} is not appropriate for this Key; or if\n * this Key does not contain the appropriate parameters.\n */\n Object.defineProperty(this, \"encrypt\", {\n value: function(alg, data, props) {\n // validate appropriateness\n if (this.algorithms(\"encrypt\").indexOf(alg) === -1) {\n return Promise.reject(new Error(\"unsupported algorithm\"));\n }\n var k = cfg.encryptKey.call(this, alg, keys);\n if (!k) {\n return Promise.reject(new Error(\"improper key\"));\n }\n\n // prepare properties (if any)\n props = (props) ?\n clone(props) :\n {};\n if (cfg.encryptProps) {\n props = merge(props, cfg.encryptProps.call(this, alg, props));\n }\n return ALGORITHMS.encrypt(alg, k, data, props);\n }\n });\n /**\n * @method JWK.Key#decrypt\n * @description\n * Decrypts the given data using the specified algorithm.\n *\n * **NOTE:** This is the primitive decryption operation; the input is\n * _**NOT**_ a JSON Web Encryption (JWE) object.\n *\n * **NOTE:** This operation is treated as distinct from {@link\n * JWK.Key#unwrap}, as different algorithms and properties are often used\n * for unwrapping a key versues decrypting arbitrary data.\n *\n * The Promise, when fulfilled, returns the plaintext data.\n *\n * @param {String} alg The decryption algorithm.\n * @param {Buffer|String} data The data to decypt.\n * @param {Object} [props] Additional data for the decryption operation.\n * @returns {Promise} The promise for the decryption operation.\n * @throws {Error} If {alg} is not appropriate for this Key; or if\n * the Key does not contain the appropriate properties.\n */\n Object.defineProperty(this, \"decrypt\", {\n value: function(alg, data, props) {\n // validate appropriateness\n if (this.algorithms(\"decrypt\").indexOf(alg) === -1) {\n return Promise.reject(new Error(\"unsupported algorithm\"));\n }\n var k = cfg.decryptKey.call(this, alg, keys);\n if (!k) {\n return Promise.reject(new Error(\"improper key\"));\n }\n\n // prepare properties (if any)\n props = (props) ?\n clone(props) :\n {};\n if (cfg.decryptProps) {\n props = merge(props, cfg.decryptProps.call(this, alg, props));\n }\n return ALGORITHMS.decrypt(alg, k, data, props);\n }\n });\n\n /**\n * @method JWK.Key#wrap\n * @description\n * Wraps the given key using the specified algorithm.\n *\n * **NOTE:** This is the primitive encryption operation; the output is\n * _**NOT**_ a JSON Web Encryption (JWE) object.\n *\n * **NOTE:** This operation is treated as distinct from {@link\n * JWK.Key#encrypt}, as different algorithms and properties are\n * often used for wrapping a key versues encrypting arbitrary data.\n *\n * The Promise, when fulfilled, returns an object with the following\n * properties:\n *\n * + **data**: The ciphertext data\n * + **headers**: The additional header parameters to apply to a JWE.\n *\n * @param {String} alg The encryption algorithm\n * @param {Buffer|String} data The data to encrypt\n * @param {Object} [props] Additional properties for the encryption\n * algorithm.\n * @returns {Promise} The promise for the encryption operation.\n * @throws {Error} If {alg} is not appropriate for this Key; or if\n * this Key does not contain the appropriate parameters.\n */\n Object.defineProperty(this, \"wrap\", {\n value: function(alg, data, props) {\n // validate appropriateness\n if (this.algorithms(\"wrap\").indexOf(alg) === -1) {\n return Promise.reject(new Error(\"unsupported algorithm\"));\n }\n var k = cfg.wrapKey.call(this, alg, keys);\n if (!k) {\n return Promise.reject(new Error(\"improper key\"));\n }\n\n // prepare properties (if any)\n props = (props) ?\n clone(props) :\n {};\n if (cfg.wrapProps) {\n props = merge(props, cfg.wrapProps.call(this, alg, props));\n }\n return ALGORITHMS.encrypt(alg, k, data, props);\n }\n });\n /**\n * @method JWK.Key#unwrap\n * @description\n * Unwraps the given key using the specified algorithm.\n *\n * **NOTE:** This is the primitive unwrap operation; the input is\n * _**NOT**_ a JSON Web Encryption (JWE) object.\n *\n * **NOTE:** This operation is treated as distinct from {@link\n * JWK.Key#decrypt}, as different algorithms and properties are often used\n * for unwrapping a key versues decrypting arbitrary data.\n *\n * The Promise, when fulfilled, returns the unwrapped key.\n *\n * @param {String} alg The unwrap algorithm.\n * @param {Buffer|String} data The data to unwrap.\n * @param {Object} [props] Additional data for the unwrap operation.\n * @returns {Promise} The promise for the unwrap operation.\n * @throws {Error} If {alg} is not appropriate for this Key; or if\n * the Key does not contain the appropriate properties.\n */\n Object.defineProperty(this, \"unwrap\", {\n value: function(alg, data, props) {\n // validate appropriateness\n if (this.algorithms(\"unwrap\").indexOf(alg) === -1) {\n return Promise.reject(new Error(\"unsupported algorithm\"));\n }\n var k = cfg.unwrapKey.call(this, alg, keys);\n if (!k) {\n return Promise.reject(new Error(\"improper key\"));\n }\n\n // prepare properties (if any)\n props = (props) ?\n clone(props) :\n {};\n if (cfg.unwrapProps) {\n props = merge(props, cfg.unwrapProps.call(this, alg, props));\n }\n return ALGORITHMS.decrypt(alg, k, data, props);\n }\n });\n};\n\nmodule.exports = JWKBaseKeyObject;\n","/*!\n * jwk/constants.js - Constants for JWKs\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nmodule.exports = {\n MODE_SIGN: \"sign\",\n MODE_VERIFY: \"verify\",\n MODE_ENCRYPT: \"encrypt\",\n MODE_DECRYPT: \"decrypt\",\n MODE_WRAP: \"wrap\",\n MODE_UNWRAP: \"unwrap\"\n};\n","/*!\n * jwk/rsa.js - RSA Key Representation\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar ecutil = require(\"../algorithms/ec-util.js\"),\n forge = require(\"../deps/forge\"),\n depsecc = require(\"../deps/ecc\");\n\nvar JWK = {\n BaseKey: require(\"./basekey.js\"),\n helpers: require(\"./helpers.js\")\n};\n\nvar SIG_ALGS = [\n \"ES256\",\n \"ES384\",\n \"ES512\"\n];\nvar WRAP_ALGS = [\n \"ECDH-ES\",\n \"ECDH-ES+A128KW\",\n \"ECDH-ES+A192KW\",\n \"ECDH-ES+A256KW\"\n];\n\nvar EC_OID = ecutil.EC_OID;\nfunction oidToCurveName(oid) {\n switch (oid) {\n case \"1.2.840.10045.3.1.7\":\n return \"P-256\";\n case \"1.3.132.0.34\":\n return \"P-384\";\n case \"1.3.132.0.35\":\n return \"P-521\";\n default:\n return null;\n }\n}\n\nvar JWKEcCfg = {\n publicKey: function(props) {\n var fields = JWK.helpers.COMMON_PROPS.concat([\n {name: \"crv\", type: \"string\"},\n {name: \"x\", type: \"binary\"},\n {name: \"y\", type: \"binary\"}\n ]);\n var pk = JWK.helpers.unpackProps(props, fields);\n if (pk && pk.crv && pk.x && pk.y) {\n pk.length = ecutil.curveSize(pk.crv);\n } else {\n delete pk.crv;\n delete pk.x;\n delete pk.y;\n }\n\n return pk;\n },\n privateKey: function(props) {\n var fields = JWK.helpers.COMMON_PROPS.concat([\n {name: \"crv\", type: \"string\"},\n {name: \"x\", type: \"binary\"},\n {name: \"y\", type: \"binary\"},\n {name: \"d\", type: \"binary\"}\n ]);\n var pk = JWK.helpers.unpackProps(props, fields);\n if (pk && pk.crv && pk.x && pk.y && pk.d) {\n pk.length = ecutil.curveSize(pk.crv);\n } else {\n pk = undefined;\n }\n\n return pk;\n },\n thumbprint: function(json) {\n if (json.public) {\n json = json.public;\n }\n var fields = {\n crv: json.crv,\n kty: \"EC\",\n x: json.x,\n y: json.y\n };\n return fields;\n },\n algorithms: function(keys, mode) {\n var len = (keys.public && keys.public.length) ||\n (keys.private && keys.private.length) ||\n 0;\n // NOTE: 521 is the actual, but 512 is the expected\n if (len === 521) {\n len = 512;\n }\n\n switch (mode) {\n case \"encrypt\":\n case \"decrypt\":\n return [];\n case \"wrap\":\n return (keys.public && WRAP_ALGS) || [];\n case \"unwrap\":\n return (keys.private && WRAP_ALGS) || [];\n case \"sign\":\n if (!keys.private) {\n return [];\n }\n return SIG_ALGS.filter(function(a) {\n return (a === (\"ES\" + len));\n });\n case \"verify\":\n if (!keys.public) {\n return [];\n }\n return SIG_ALGS.filter(function(a) {\n return (a === (\"ES\" + len));\n });\n }\n },\n\n encryptKey: function(alg, keys) {\n return keys.public;\n },\n decryptKey: function(alg, keys) {\n return keys.private;\n },\n\n wrapKey: function(alg, keys) {\n return keys.public;\n },\n unwrapKey: function(alg, keys) {\n return keys.private;\n },\n\n signKey: function(alg, keys) {\n return keys.private;\n },\n verifyKey: function(alg, keys) {\n return keys.public;\n }\n};\nJWKEcCfg.convertToPEM = ecutil.convertToPEM;\n\n// Inspired by digitalbaazar/node-forge/js/rsa.js\nvar validators = {\n oid: EC_OID,\n privateKey: {\n // ECPrivateKey\n name: \"ECPrivateKey\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.SEQUENCE,\n constructed: true,\n value: [\n {\n // EC version\n name: \"ECPrivateKey.version\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.INTEGER,\n constructed: false\n },\n {\n // private value (d)\n name: \"ECPrivateKey.private\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.OCTETSTRING,\n constructed: false,\n capture: \"d\"\n },\n {\n // EC parameters\n tagClass: forge.asn1.Class.CONTEXT_SPECIFIC,\n name: \"ECPrivateKey.parameters\",\n constructed: true,\n value: [\n {\n // namedCurve (crv)\n name: \"ECPrivateKey.namedCurve\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.OID,\n constructed: false,\n capture: \"crv\"\n }\n ]\n },\n {\n // publicKey\n name: \"ECPrivateKey.publicKey\",\n tagClass: forge.asn1.Class.CONTEXT_SPECIFIC,\n constructed: true,\n value: [\n {\n name: \"ECPrivateKey.point\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.BITSTRING,\n constructed: false,\n capture: \"point\"\n }\n ]\n }\n ]\n },\n embeddedPrivateKey: {\n // ECPrivateKey\n name: \"ECPrivateKey\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.SEQUENCE,\n constructed: true,\n value: [\n {\n // EC version\n name: \"ECPrivateKey.version\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.INTEGER,\n constructed: false\n },\n {\n // private value (d)\n name: \"ECPrivateKey.private\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.OCTETSTRING,\n constructed: false,\n capture: \"d\"\n },\n {\n // publicKey\n name: \"ECPrivateKey.publicKey\",\n tagClass: forge.asn1.Class.CONTEXT_SPECIFIC,\n constructed: true,\n value: [\n {\n name: \"ECPrivateKey.point\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.BITSTRING,\n constructed: false,\n capture: \"point\"\n }\n ]\n }\n ]\n }\n};\n\nvar JWKEcFactory = {\n kty: \"EC\",\n validators: validators,\n prepare: function(props) {\n // TODO: validate key properties\n var cfg = JWKEcCfg;\n var p = Promise.resolve(props);\n p = p.then(function(json) {\n return JWK.helpers.thumbprint(cfg, json);\n });\n p = p.then(function(hash) {\n var prints = {};\n prints[JWK.helpers.INTERNALS.THUMBPRINT_HASH] = hash;\n props[JWK.helpers.INTERNALS.THUMBPRINT_KEY] = prints;\n return cfg;\n });\n return p;\n },\n generate: function(size) {\n var keypair = depsecc.generateKeyPair(size);\n var result = {\n \"crv\": size,\n \"x\": keypair.public.x,\n \"y\": keypair.public.y,\n \"d\": keypair.private.d\n };\n return Promise.resolve(result);\n },\n import: function(input) {\n if (validators.oid !== input.keyOid) {\n return null;\n }\n\n // coerce key params to OID\n var crv;\n if (input.keyParams && forge.asn1.Type.OID === input.keyParams.type) {\n crv = forge.asn1.derToOid(input.keyParams.value);\n crv = oidToCurveName(crv);\n } else if (input.crv) {\n crv = forge.asn1.derToOid(input.crv);\n crv = oidToCurveName(crv);\n }\n if (!crv) {\n return null;\n }\n\n if (!input.parsed) {\n var capture = {},\n errors = [];\n if (\"private\" === input.type) {\n // coerce capture.value to DER *iff* private\n if (\"string\" === typeof input.keyValue) {\n input.keyValue = forge.asn1.fromDer(input.keyValue);\n } else if (Array.isArray(input.keyValue)) {\n input.keyValue = input.keyValue[0];\n }\n\n if (!forge.asn1.validate(input.keyValue,\n validators.embeddedPrivateKey,\n capture,\n errors)) {\n return null;\n }\n } else {\n capture.point = input.keyValue;\n }\n input = capture;\n }\n\n // convert factors to Buffers\n var output = {\n kty: \"EC\",\n crv: crv\n };\n if (input.d) {\n output.d = Buffer.from(input.d, \"binary\");\n }\n if (input.point) {\n var pt = Buffer.from(input.point, \"binary\");\n // only support uncompressed\n if (4 !== pt.readUInt16BE(0)) {\n return null;\n }\n pt = pt.slice(2);\n var len = pt.length / 2;\n output.x = pt.slice(0, len);\n output.y = pt.slice(len);\n }\n return output;\n }\n};\n// public API\nmodule.exports = Object.freeze({\n config: JWKEcCfg,\n factory: JWKEcFactory\n});\n\n// registration\n(function(REGISTRY) {\n REGISTRY.register(JWKEcFactory);\n})(require(\"./keystore\").registry);\n","/*!\n * jwk/helpers.js - JWK Internal Helper Functions and Constants\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar clone = require(\"lodash/clone\"),\n util = require(\"../util\"),\n forge = require(\"../deps/forge\");\n\nvar ALGORITHMS = require(\"../algorithms\");\n\n// ### ASN.1 Validators\n// Adapted from digitalbazaar/node-forge/js/asn1.js\n// PrivateKeyInfo\nvar privateKeyValidator = {\n name: \"PrivateKeyInfo\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.SEQUENCE,\n constructed: true,\n value: [\n {\n // Version (INTEGER)\n name: \"PrivateKeyInfo.version\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.INTEGER,\n constructed: false,\n capture: \"keyVersion\"\n },\n {\n name: \"PrivateKeyInfo.privateKeyAlgorithm\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.SEQUENCE,\n constructed: true,\n value: [\n {\n name: \"AlgorithmIdentifier.algorithm\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.OID,\n constructed: false,\n capture: \"keyOid\"\n },\n {\n name: \"AlgorithmIdentifier.parameters\",\n captureAsn1: \"keyParams\"\n }\n ]\n },\n {\n name: \"PrivateKeyInfo\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.OCTETSTRING,\n constructed: false,\n capture: \"keyValue\"\n }\n ]\n};\n// Adapted from digitalbazaar/node-forge/x509.js\nvar publicKeyValidator = {\n name: \"SubjectPublicKeyInfo\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.SEQUENCE,\n constructed: true,\n value: [\n {\n name: \"SubjectPublicKeyInfo.AlgorithmIdentifier\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.SEQUENCE,\n constructed: true,\n value: [\n {\n name: \"AlgorithmIdentifier.algorithm\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.OID,\n constructed: false,\n capture: \"keyOid\"\n },\n {\n name: \"AlgorithmIdentifier.parameters\",\n captureAsn1: \"keyParams\"\n }\n ]\n },\n {\n name: \"SubjectPublicKeyInfo.subjectPublicKey\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.BITSTRING,\n constructed: false,\n capture: \"keyValue\"\n }\n ]\n};\n// Adapted from digitalbazaar/node-forge/x509.js\nvar X509CertificateValidator = {\n name: \"Certificate\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.SEQUENCE,\n constructed: true,\n value: [\n {\n name: \"Certificate.TBSCertificate\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.SEQUENCE,\n constructed: true,\n captureAsn1: \"certificate\",\n value: [\n {\n name: \"Certificate.TBSCertificate.version\",\n tagClass: forge.asn1.Class.CONTEXT_SPECIFIC,\n type: 0,\n constructed: true,\n optional: true,\n value: [\n {\n name: \"Certificate.TBSCertificate.version.integer\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.INTEGER,\n constructed: false,\n capture: \"certVersion\"\n }\n ]\n },\n {\n name: \"Certificate.TBSCertificate.serialNumber\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.INTEGER,\n constructed: false,\n capture: \"certSerialNumber\"\n },\n {\n name: \"Certificate.TBSCertificate.signature\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.SEQUENCE,\n constructed: true,\n value: [\n {\n name: \"Certificate.TBSCertificate.signature.algorithm\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.OID,\n constructed: false,\n capture: \"certSignatureOid\"\n }, {\n name: \"Certificate.TBSCertificate.signature.parameters\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n optional: true,\n captureAsn1: \"certSignatureParams\"\n }\n ]\n },\n {\n name: \"Certificate.TBSCertificate.issuer\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.SEQUENCE,\n constructed: true,\n captureAsn1: \"certIssuer\"\n },\n {\n name: \"Certificate.TBSCertificate.validity\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.SEQUENCE,\n constructed: true,\n // Note: UTC and generalized times may both appear so the capture\n // names are based on their detected order, the names used below\n // are only for the common case, which validity time really means\n // \"notBefore\" and which means \"notAfter\" will be determined by order\n value: [\n {\n // notBefore (Time) (UTC time case)\n name: \"Certificate.TBSCertificate.validity.notBefore (utc)\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.UTCTIME,\n constructed: false,\n optional: true,\n capture: \"certValidity1UTCTime\"\n },\n {\n // notBefore (Time) (generalized time case)\n name: \"Certificate.TBSCertificate.validity.notBefore (generalized)\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.GENERALIZEDTIME,\n constructed: false,\n optional: true,\n capture: \"certValidity2GeneralizedTime\"\n },\n {\n // notAfter (Time) (only UTC time is supported)\n name: \"Certificate.TBSCertificate.validity.notAfter (utc)\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.UTCTIME,\n constructed: false,\n optional: true,\n capture: \"certValidity3UTCTime\"\n },\n {\n // notAfter (Time) (only UTC time is supported)\n name: \"Certificate.TBSCertificate.validity.notAfter (generalized)\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.GENERALIZEDTIME,\n constructed: false,\n optional: true,\n capture: \"certValidity4GeneralizedTime\"\n }\n ]\n }, {\n // Name (subject) (RDNSequence)\n name: \"Certificate.TBSCertificate.subject\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.SEQUENCE,\n constructed: true,\n captureAsn1: \"certSubject\"\n },\n // SubjectPublicKeyInfo\n publicKeyValidator,\n {\n // issuerUniqueID (optional)\n name: \"Certificate.TBSCertificate.issuerUniqueID\",\n tagClass: forge.asn1.Class.CONTEXT_SPECIFIC,\n type: 1,\n constructed: true,\n optional: true,\n value: [\n {\n name: \"Certificate.TBSCertificate.issuerUniqueID.id\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.BITSTRING,\n constructed: false,\n capture: \"certIssuerUniqueId\"\n }\n ]\n },\n {\n // subjectUniqueID (optional)\n name: \"Certificate.TBSCertificate.subjectUniqueID\",\n tagClass: forge.asn1.Class.CONTEXT_SPECIFIC,\n type: 2,\n constructed: true,\n optional: true,\n value: [\n {\n name: \"Certificate.TBSCertificate.subjectUniqueID.id\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.BITSTRING,\n constructed: false,\n capture: \"certSubjectUniqueId\"\n }\n ]\n },\n {\n // Extensions (optional)\n name: \"Certificate.TBSCertificate.extensions\",\n tagClass: forge.asn1.Class.CONTEXT_SPECIFIC,\n type: 3,\n constructed: true,\n captureAsn1: \"certExtensions\",\n optional: true\n }\n ]\n },\n {\n // AlgorithmIdentifier (signature algorithm)\n name: \"Certificate.signatureAlgorithm\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.SEQUENCE,\n constructed: true,\n value: [\n {\n // algorithm\n name: \"Certificate.signatureAlgorithm.algorithm\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.OID,\n constructed: false,\n capture: \"certSignatureOid\"\n },\n {\n name: \"Certificate.TBSCertificate.signature.parameters\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n optional: true,\n captureAsn1: \"certSignatureParams\"\n }\n ]\n },\n {\n // SignatureValue\n name: \"Certificate.signatureValue\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.BITSTRING,\n constructed: false,\n capture: \"certSignature\"\n }\n ]\n};\n\nvar INTERNALS = {\n THUMBPRINT_KEY: \"internal\\u0000thumbprint\",\n THUMBPRINT_HASH: \"SHA-256\"\n};\n\nmodule.exports = {\n validators: {\n privateKey: privateKeyValidator,\n publicKey: publicKeyValidator,\n certificate: X509CertificateValidator\n },\n\n thumbprint: function(cfg, json, hash) {\n if (\"function\" !== typeof cfg.thumbprint) {\n return Promise.reject(new Error(\"thumbprint not supported\"));\n }\n\n hash = (hash || INTERNALS.THUMBPRINT_HASH).toUpperCase();\n var fields = cfg.thumbprint(json);\n var input = Object.keys(fields).\n sort().\n map(function(k) {\n var v = fields[k];\n if (Buffer.isBuffer(v)) {\n v = util.base64url.encode(v);\n }\n return JSON.stringify(k) + \":\" + JSON.stringify(v);\n });\n input = \"{\" + input.join(\",\") + \"}\";\n try {\n return ALGORITHMS.digest(hash, Buffer.from(input, \"utf8\"));\n } catch (err) {\n return Promise.reject(err);\n }\n },\n unpackProps: function(props, allowed) {\n var output;\n\n // apply all of the existing values\n allowed.forEach(function(cfg) {\n if (!(cfg.name in props)) {\n return;\n }\n output = output || {};\n var value = props[cfg.name];\n switch (cfg.type) {\n case \"binary\":\n if (Buffer.isBuffer(value)) {\n props[cfg.name] = util.base64url.encode(value);\n } else {\n value = util.base64url.decode(value);\n }\n break;\n case \"string\":\n case \"number\":\n case \"boolean\":\n break;\n case \"array\":\n value = [].concat(value);\n break;\n case \"object\":\n value = clone(value);\n break;\n default:\n // TODO: deep clone?\n break;\n }\n output[cfg.name] = value;\n });\n\n // remove any from json that didn't apply\n var check = output || {};\n Object.keys(props).\n forEach(function(n) {\n if (n in check) { return; }\n delete props[n];\n });\n\n return output;\n },\n COMMON_PROPS: [\n {name: \"kty\", type: \"string\"},\n {name: \"kid\", type: \"string\"},\n {name: \"use\", type: \"string\"},\n {name: \"alg\", type: \"string\"},\n {name: \"x5c\", type: \"array\"},\n {name: \"x5t\", type: \"binary\"},\n {name: \"x5u\", type: \"string\"},\n {name: \"key_ops\", type: \"array\"}\n ],\n INTERNALS: INTERNALS\n};\n","/*!\n * jwk/index.js - JSON Web Key (JWK) Entry Point\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar JWKStore = require(\"./keystore.js\");\n\n// Public API -- Key and KeyStore methods\nObject.keys(JWKStore.KeyStore).forEach(function(name) {\n exports[name] = JWKStore.KeyStore[name];\n});\n\n// Public API -- constants\nvar CONSTANTS = require(\"./constants.js\");\nObject.keys(CONSTANTS).forEach(function(name) {\n exports[name] = CONSTANTS[name];\n});\n\n// Registered Key Types\nrequire(\"./octkey.js\");\nrequire(\"./rsakey.js\");\nrequire(\"./eckey.js\");\n","/*!\n * jwk/keystore.js - JWK KeyStore Implementation\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar clone = require(\"lodash/clone\"),\n merge = require(\"../util/merge\"),\n forge = require(\"../deps/forge\"),\n util = require(\"../util\");\n\nvar JWK = {\n BaseKey: require(\"./basekey.js\"),\n helpers: require(\"./helpers.js\")\n};\n\n/**\n * @class JWK.KeyStoreRegistry\n * @classdesc\n * A registry of JWK.Key types that can be used.\n *\n * @description\n * **NOTE:** This constructor cannot be called directly. Instead use the\n * global {JWK.registry}\n */\nvar JWKRegistry = function() {\n var types = {};\n\n Object.defineProperty(this, \"register\", {\n value: function(factory) {\n if (!factory || \"string\" !== typeof factory.kty || !factory.kty) {\n throw new Error(\"invalid Key factory\");\n }\n\n var kty = factory.kty;\n types[kty] = factory;\n return this;\n }\n });\n Object.defineProperty(this, \"unregister\", {\n value: function(factory) {\n if (!factory || \"string\" !== typeof factory.kty || !factory.kty) {\n throw new Error(\"invalid Key factory\");\n }\n\n var kty = factory.kty;\n if (factory === types[kty]) {\n delete types[kty];\n }\n return this;\n }\n });\n\n Object.defineProperty(this, \"get\", {\n value: function(kty) {\n return types[kty || \"\"] || undefined;\n }\n });\n Object.defineProperty(this, \"all\", {\n value: function() {\n return Object.keys(types).map(function(t) { return types[t]; });\n }\n });\n};\n\n// Globals\nvar GLOBAL_REGISTRY = new JWKRegistry();\n\n// importer\nfunction processCert(input) {\n // convert certIssuer to readable attributes\n [\"certIssuer\", \"certSubject\"].forEach(function(field) {\n /* eslint new-cap: [0] */\n var attrs = forge.pki.RDNAttributesAsArray(input[field]);\n var result = input[field] = {};\n attrs.forEach(function(a) {\n result[a.name || a.type] = a.value;\n });\n });\n\n return input;\n}\n\nfunction fromPEM(input) {\n var result = {};\n var pems = forge.pem.decode(input);\n var found = pems.some(function(p) {\n switch (p.type) {\n case \"CERTIFICATE\":\n result.form = \"pkix\";\n break;\n case \"PUBLIC KEY\":\n result.form = \"spki\";\n break;\n case \"PRIVATE KEY\":\n result.form = \"pkcs8\";\n break;\n case \"EC PRIVATE KEY\":\n /* eslint no-fallthrough: [0] */\n case \"RSA PRIVATE KEY\":\n result.form = \"private\";\n break;\n default:\n return false;\n }\n\n result.body = p.body;\n return true;\n });\n if (!found) {\n throw new Error(\"supported PEM type not found\");\n }\n return result;\n}\nfunction importFrom(registry, input) {\n // form can be one of:\n // 'private' | 'pkcs8' | 'public' | 'spki' | 'pkix' | 'x509'\n var capture = {},\n errors = [],\n result;\n\n // conver from DER to ASN1\n var form = input.form,\n der = input.body,\n thumbprint = null;\n input = forge.asn1.fromDer(der);\n switch(form) {\n case \"private\":\n registry.all().some(function(factory) {\n if (result) {\n return false;\n }\n if (!factory.validators) {\n return false;\n }\n\n var oid = factory.validators.oid,\n validator = factory.validators.privateKey;\n if (!validator) {\n return false;\n }\n capture = {};\n errors = [];\n result = forge.asn1.validate(input, validator, capture, errors);\n if (result) {\n capture.keyOid = forge.asn1.oidToDer(oid);\n capture.parsed = true;\n }\n return result;\n });\n capture.type = \"private\";\n break;\n case \"pkcs8\":\n result = forge.asn1.validate(input, JWK.helpers.validators.privateKey, capture, errors);\n capture.type = \"private\";\n break;\n case \"public\":\n // eslint no-fallthrough: [0] */\n case \"spki\":\n result = forge.asn1.validate(input, JWK.helpers.validators.publicKey, capture, errors);\n capture.type = \"public\";\n break;\n case \"pkix\":\n /* eslint no-fallthrough: [0] */\n case \"x509\":\n result = forge.asn1.validate(input, JWK.helpers.validators.certificate, capture, errors);\n if (result) {\n capture = processCert(capture);\n var md = forge.md.sha1.create();\n md.update(der);\n thumbprint = util.base64url.encode(Buffer.from(md.digest().toHex(), \"hex\"));\n }\n capture.type = \"public\";\n break;\n }\n if (!result) {\n return null;\n }\n\n // convert oids\n if (capture.keyOid) {\n capture.keyOid = forge.asn1.derToOid(capture.keyOid);\n }\n\n // find and invoke the importer\n result = null;\n GLOBAL_REGISTRY.all().forEach(function(factory) {\n if (result) {\n return;\n }\n if (!factory) {\n return;\n }\n if (\"function\" !== typeof factory.import) {\n return;\n }\n result = factory.import(capture);\n });\n if (result && capture.certSubject && capture.certSubject.commonName) {\n result.kid = capture.certSubject.commonName;\n }\n if (result && thumbprint) {\n result.x5t = thumbprint;\n }\n return result;\n}\n\n/**\n * @class JWK.KeyStore\n * @classdesc\n * Represents a collection of Keys.\n *\n * @description\n * **NOTE:** This constructor cannot be called directly. Instead call {@link\n * JWK.createKeyStore}.\n */\nvar JWKStore = function(registry, parent) {\n var keysets = {};\n\n /**\n * @method JWK.KeyStore#generate\n * @description\n * Generates a new random Key into this KeyStore.\n *\n * The type of {size} depends on the value of {kty}:\n *\n * + **`EC`**: String naming the curve to use, which can be one of:\n * `\"P-256\"`, `\"P-384\"`, or `\"P-521\"` (default is **`\"P-256\"`**).\n * + **`RSA`**: Number describing the size of the key, in bits (default is\n * **`2048`**).\n * + **`oct`**: Number describing the size of the key, in bits (default is\n * **`256`**).\n *\n * Any properties in {props} are applied before the key is generated,\n * and are expected to be data types acceptable in JSON. This allows the\n * generated key to have a specific key identifier, or to specify its\n * acceptable usage.\n *\n * The returned Promise, when fulfilled, returns the generated Key.\n *\n * @param {String} kty The type of generated key\n * @param {String|Number} [size] The size of the generated key\n * @param {Object} [props] Additional properties to apply to the generated\n * key.\n * @returns {Promise} The promise for the generated Key\n * @throws {Error} If {kty} is not supported\n */\n Object.defineProperty(this, \"generate\", {\n value: function(kty, size, props) {\n var keytype = registry.get(kty);\n if (!keytype) {\n return Promise.reject(new Error(\"unsupported key type\"));\n }\n\n props = clone(props || {});\n props.kty = kty;\n\n var self = this,\n promise = keytype.generate(size);\n return promise.then(function(jwk) {\n jwk = merge(props, jwk, {\n kty: kty\n });\n return self.add(jwk);\n });\n }\n });\n /**\n * @method JWK.KeyStore#add\n * @description\n * Adds a Key to this KeyStore. If {jwk} is a string, it is first\n * parsed into a plain JSON object. If {jwk} is already an instance\n * of JWK.Key, its (public) JSON representation is first obtained\n * then applied to a new JWK.Key object within this KeyStore.\n *\n * @param {String|Object} jwk The JSON Web Key (JWK)\n * @param {String} [form] The format of a String key to expect\n * @param {Object} [extras] extra jwk fields inserted when importing from a non json string (eg \"pem\")\n * @returns {Promise} The promise for the added key\n */\n Object.defineProperty(this, \"add\", {\n value: function(jwk, form, extras) {\n extras = extras || {};\n\n var factors;\n if (Buffer.isBuffer(jwk) || typeof jwk === \"string\") {\n // form can be 'json', 'pkcs8', 'spki', 'pkix', 'x509', 'pem'\n form = (form || \"json\").toLowerCase();\n if (\"json\" === form) {\n jwk = JSON.parse(jwk.toString(\"utf8\"));\n } else {\n try {\n if (\"pem\" === form) {\n // convert *first* PEM -> DER\n factors = fromPEM(jwk);\n } else {\n factors = {\n body: jwk.toString(\"binary\"),\n form: form\n };\n }\n jwk = importFrom(registry, factors);\n if (!jwk) {\n throw new Error(\"no importer for key\");\n }\n Object.keys(extras).forEach(function(field){\n jwk[field] = extras[field];\n });\n } catch (err) {\n return Promise.reject(err);\n }\n }\n } else if (JWKStore.isKey(jwk)) {\n // assume a complete duplicate is desired\n jwk = jwk.toJSON(true);\n } else {\n jwk = clone(jwk);\n }\n\n var keytype = registry.get(jwk.kty);\n if (!keytype) {\n return Promise.reject(new Error(\"unsupported key type\"));\n }\n\n var self = this,\n promise = keytype.prepare(jwk);\n return promise.then(function(cfg) {\n return new JWK.BaseKey(jwk.kty, self, jwk, cfg);\n }).then(function(jwk) {\n var kid = jwk.kid || \"\";\n var keys = keysets[kid] = keysets[kid] || [];\n keys.push(jwk);\n\n return jwk;\n });\n }\n });\n /**\n * @method JWK.KeyStore#remove\n * @description\n * Removes a Key from this KeyStore.\n *\n * **NOTE:** The removed Key's {keystore} property is not changed.\n *\n * @param {JWK.Key} jwk The key to remove.\n */\n Object.defineProperty(this, \"remove\", {\n value: function(jwk) {\n if (!jwk) {\n return;\n }\n\n var keys = keysets[jwk.kid];\n if (!keys) {\n return;\n }\n\n var pos = keys.indexOf(jwk);\n if (pos === -1) {\n return;\n }\n\n keys.splice(pos, 1);\n if (!keys.length) {\n delete keysets[jwk.kid];\n }\n }\n });\n\n /**\n * @method JWK.KeyStore#all\n * @description\n * Retrieves all of the contained Keys that optinally match all of the\n * given properties.\n *\n * If {props} are specified, this method only returns Keys which exactly\n * match the given properties. The properties can be any of the\n * following:\n *\n * + **alg**: The algorithm for the Key.\n * + **use**: The usage for the Key.\n * + **kid**: The identifier for the Key.\n *\n * If no properties are given, this method returns all of the Keys for this\n * KeyStore.\n *\n * @param {Object} [props] The properties to match against\n * @param {Boolean} [local = false] `true` if only the Keys\n * directly contained by this KeyStore should be returned, or\n * `false` if it should return all Keys of this KeyStore and\n * its ancestors.\n * @returns {JWK.Key[]} The list of matching Keys, or an empty array if no\n * matches are found.\n */\n Object.defineProperty(this, \"all\", {\n value: function(props, local) {\n props = props || {};\n\n // workaround for issues/109\n if (props.kid !== undefined && props.kid !== null && typeof props.kid !== \"string\") {\n props.kid = String(props.kid);\n }\n\n var candidates = [];\n var matches = function(key) {\n // match on 'kty'\n if (props.kty &&\n key.kty &&\n props.kty !== key.kty) {\n return false;\n }\n // match on 'use'\n if (props.use &&\n key.use &&\n props.use !== key.use) {\n return false;\n }\n // match on 'alg'\n if (props.alg) {\n if (props.alg !== \"dir\" &&\n key.alg &&\n props.alg !== key.alg) {\n return false;\n }\n return key.supports(props.alg);\n }\n //TODO: match on 'key_ops'\n\n return true;\n };\n Object.keys(keysets).forEach(function(id) {\n if (props.kid && props.kid !== id) {\n return;\n }\n\n var keys = keysets[id].filter(matches);\n if (keys.length) {\n candidates = candidates.concat(keys);\n }\n });\n\n if (!local && parent) {\n candidates = candidates.concat(parent.all(props));\n }\n\n return candidates;\n }\n });\n /**\n * @method JWK.KeyStore#get\n * @description\n * Retrieves the contained Key matching the given {kid}, and optionally\n * all of the given properties. This method equivalent to calling\n * {@link JWK.Store#all}, then returning the first Key whose\n * \"kid\" is {kid}. If {kid} is undefined, then the first Key that\n * is returned from `all()` is returned.\n *\n * @param {String} [kid] The key identifier to match against.\n * @param {Object} [props] The properties to match against.\n * @param {Boolean} [local = false] `true` if only the Keys\n * directly contained by this KeyStore should be returned, or\n * `false` if it should return all Keys of this KeyStore and\n * its ancestors.\n * @returns {JWK.Key} The Key matching {kid} and {props}, or `null`\n * if no match is found.\n */\n Object.defineProperty(this, \"get\", {\n value: function(kid, props, local) {\n // reconcile arguments\n if (typeof kid === \"boolean\") {\n local = kid;\n props = kid = null;\n } else if (typeof kid === \"object\") {\n local = props;\n props = kid;\n kid = null;\n }\n\n // fixup props\n props = props || {};\n if (kid) {\n props.kid = kid;\n }\n\n // workaround for issues/109\n if (props.kid !== undefined && props.kid !== null && typeof props.kid !== \"string\") {\n props.kid = String(props.kid);\n }\n\n var candidates = this.all(props, true);\n if (!candidates.length && parent && !local) {\n candidates = parent.get(props, local);\n }\n return candidates[0] || null;\n }\n });\n\n /**\n * @method JWK.KeyStore#temp\n * @description\n * Creates a temporary KeyStore based on this KeyStore.\n *\n * @returns {JWK.KeyStore} The temporary KeyStore.\n */\n Object.defineProperty(this, \"temp\", {\n value: function() {\n return new JWKStore(registry, this);\n }\n });\n\n /**\n * @method JWK.KeyStore#toJSON\n * @description\n * Generates a JSON representation of this KeyStore, which conforms\n * to a JWK Set from {I-D.ietf-jose-json-web-key}.\n *\n * @param {Boolean} [isPrivate = false] `true` if the private fields\n * of stored keys are to be included.\n * @returns {Object} The JSON representation of this KeyStore.\n */\n Object.defineProperty(this, \"toJSON\", {\n value: function(isPrivate) {\n var keys = [];\n\n Object.keys(keysets).forEach(function(kid) {\n var items = keysets[kid].map(function(k) {\n return k.toJSON(isPrivate);\n });\n keys = keys.concat(items);\n });\n\n return {\n keys: keys\n };\n }\n });\n};\n\n/**\n * Determines if the given object is an instance of JWK.KeyStore.\n *\n * @param {Object} obj The object to test\n * @returns {Boolean} `true` if {obj} is an instance of JWK.KeyStore,\n * and `false` otherwise.\n */\nJWKStore.isKeyStore = function(obj) {\n if (!obj) {\n return false;\n }\n\n if (\"object\" !== typeof obj) {\n return false;\n }\n\n if (\"function\" !== typeof obj.get ||\n \"function\" !== typeof obj.all ||\n \"function\" !== typeof obj.generate ||\n \"function\" !== typeof obj.add ||\n \"function\" !== typeof obj.remove) {\n return false;\n }\n\n return true;\n};\n\n/**\n * Creates a new empty KeyStore.\n *\n * @returns {JWK.KeyStore} The empty KeyStore.\n */\nJWKStore.createKeyStore = function() {\n return new JWKStore(GLOBAL_REGISTRY);\n};\n\n/**\n * Coerces the given object into a KeyStore. This method uses the following\n * algorithm to coerce {ks}:\n *\n * 1. if {ks} is an instance of JWK.KeyStore, it is returned directly\n * 2. if {ks} is a string, it is parsed into a JSON value\n * 3. if {ks} is an array, it creates a new JWK.KeyStore and calls {@link\n * JWK.KeyStore#add} for each element in the {ks} array.\n * 4. if {ks} is a JSON object, it creates a new JWK.KeyStore and calls {@link\n * JWK.KeyStore#add} for each element in the \"keys\" property.\n *\n * @param {Object|String} ks The value to coerce into a\n * KeyStore\n * @returns {Promise(JWK.KeyStore)} A promise for the coerced KeyStore.\n */\nJWKStore.asKeyStore = function(ks) {\n if (JWKStore.isKeyStore(ks)) {\n return Promise.resolve(ks);\n }\n\n var store = JWKStore.createKeyStore(),\n keys;\n\n if (typeof ks === \"string\") {\n ks = JSON.parse(ks);\n }\n\n if (Array.isArray(ks)) {\n keys = ks;\n } else if (\"keys\" in ks) {\n keys = ks.keys;\n } else {\n return Promise.reject(new Error(\"invalid keystore\"));\n }\n\n keys = keys.map(function(k) {\n return store.add(k);\n });\n\n var promise = Promise.all(keys);\n promise = promise.then(function() {\n return store;\n });\n\n return promise;\n};\n\n\n/**\n * Determines if the given object is a JWK.Key instance.\n *\n * @param {Object} obj The object to test\n * @returns `true` if {obj} is a JWK.Key\n */\nJWKStore.isKey = function(obj) {\n if (!obj) {\n return false;\n }\n\n if (\"object\" !== typeof obj) {\n return false;\n }\n\n if (!JWKStore.isKeyStore(obj.keystore)) {\n return false;\n }\n\n if (\"string\" !== typeof obj.kty ||\n \"number\" !== typeof obj.length ||\n \"function\" !== typeof obj.algorithms ||\n \"function\" !== typeof obj.supports ||\n \"function\" !== typeof obj.encrypt ||\n \"function\" !== typeof obj.decrypt ||\n \"function\" !== typeof obj.wrap ||\n \"function\" !== typeof obj.unwrap ||\n \"function\" !== typeof obj.sign ||\n \"function\" !== typeof obj.verify) {\n return false;\n }\n\n return true;\n};\n\n/**\n * Creates a new key with the given properties. This method is a convenience\n * to calling `JWK.createKeyStore()` then `generate()` on the returned keystore.\n *\n * @param {String} kty The type of generated key\n * @param {String|Number} [size] The size of the generated key\n * @param {Object} [props] Additional properties to apply to the generated\n * key.\n * @returns {Promise} The promise for the generated Key\n * @throws {Error} If {kty} is not supported\n * @see JWKStore#generate\n */\nJWKStore.createKey = function(kty, size, props) {\n var ks = JWKStore.createKeyStore();\n return ks.generate(kty, size, props);\n}\n\n/**\n * Coerces the given object into a Key. If {key} is an instance of JWK.Key,\n * it is returned directly. Otherwise, this method first creates a new\n * JWK.KeyStore and calls {@link JWK.KeyStore#add} on this new KeyStore.\n *\n * @param {Object|String} key The value to coerce into a Key\n * @param {String} [form] The format of a String Key to expect\n * @param {Object} [extras] extra jwk fields inserted when importing from a non json string (eg \"pem\")\n * @returns {Promise(JWK.Key)} A promise for the coerced Key.\n */\nJWKStore.asKey = function(key, form, extras) {\n if (JWKStore.isKey(key)) {\n return Promise.resolve(key);\n }\n\n var ks = JWKStore.createKeyStore();\n key = ks.add(key, form, extras);\n\n return key;\n};\n\nmodule.exports = {\n KeyRegistry: JWKRegistry,\n KeyStore: JWKStore,\n registry: GLOBAL_REGISTRY\n};\n","/*!\n * jwk/octkey.js - Symmetric Octet Key Representation\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar util = require(\"../util\");\n\nvar JWK = {\n BaseKey: require(\"./basekey.js\"),\n helpers: require(\"./helpers.js\")\n};\n\nvar SIG_ALGS = [\n \"HS256\",\n \"HS384\",\n \"HS512\"\n];\nvar ENC_ALGS = [\n \"A128GCM\",\n \"A192GCM\",\n \"A256GCM\",\n \"A128CBC-HS256\",\n \"A192CBC-HS384\",\n \"A256CBC-HS512\",\n \"A128CBC+HS256\",\n \"A192CBC+HS384\",\n \"A256CBC+HS512\"\n];\nvar WRAP_ALGS = [\n \"A128KW\",\n \"A192KW\",\n \"A256KW\",\n \"A128GCMKW\",\n \"A192GCMKW\",\n \"A256GCMKW\",\n \"PBES2-HS256+A128KW\",\n \"PBES2-HS384+A192KW\",\n \"PBES2-HS512+A256KW\",\n \"dir\"\n];\n\nfunction adjustDecryptProps(alg, props) {\n if (\"iv\" in props) {\n props.iv = Buffer.isBuffer(props.iv) ?\n props.iv :\n util.base64url.decode(props.iv || \"\");\n }\n if (\"adata\" in props) {\n props.adata = Buffer.isBuffer(props.adata) ?\n props.adata :\n Buffer.from(props.adata || \"\", \"utf8\");\n }\n if (\"mac\" in props) {\n props.mac = Buffer.isBuffer(props.mac) ?\n props.mac :\n util.base64url.decode(props.mac || \"\");\n }\n if (\"tag\" in props) {\n props.tag = Buffer.isBuffer(props.tag) ?\n props.tag :\n util.base64url.decode(props.tag || \"\");\n }\n\n return props;\n}\nfunction adjustEncryptProps(alg, props) {\n if (\"iv\" in props) {\n props.iv = Buffer.isBuffer(props.iv) ?\n props.iv :\n util.base64url.decode(props.iv || \"\");\n }\n if (\"adata\" in props) {\n props.adata = Buffer.isBuffer(props.adata) ?\n props.adata :\n Buffer.from(props.adata || \"\", \"utf8\");\n }\n\n return props;\n}\n\nvar JWKOctetCfg = {\n publicKey: function(props) {\n var fields = JWK.helpers.COMMON_PROPS.concat([\n ]);\n\n var pk;\n pk = JWK.helpers.unpackProps(props, fields);\n\n return pk;\n },\n privateKey: function(props) {\n var fields = JWK.helpers.COMMON_PROPS.concat([\n {name: \"k\", type: \"binary\"}\n ]);\n\n var pk;\n pk = JWK.helpers.unpackProps(props, fields);\n if (pk && pk.k) {\n pk.length = pk.k.length * 8;\n } else {\n pk = undefined;\n }\n\n return pk;\n },\n\n thumbprint: function(json) {\n if (json.private) {\n json = json.private;\n }\n var fields;\n fields = {\n k: json.k || \"\",\n kty: \"oct\"\n };\n return fields;\n },\n algorithms: function(keys, mode) {\n var len = keys.private && (keys.private.k.length * 8);\n var mins = [256, 384, 512];\n\n if (!len) {\n return [];\n }\n switch (mode) {\n case \"encrypt\":\n case \"decrypt\":\n return ENC_ALGS.filter(function(a) {\n return (a === (\"A\" + (len / 2) + \"CBC-HS\" + len)) ||\n (a === (\"A\" + (len / 2) + \"CBC+HS\" + len)) ||\n (a === (\"A\" + len + \"GCM\"));\n });\n case \"sign\":\n case \"verify\":\n // TODO: allow for HS{less-than-keysize}\n return SIG_ALGS.filter(function(a) {\n var result = false;\n mins.forEach(function(m) {\n if (m > len) { return; }\n result = result | (a === (\"HS\" + m));\n });\n return result;\n });\n case \"wrap\":\n case \"unwrap\":\n return WRAP_ALGS.filter(function(a) {\n return (a === (\"A\" + len + \"KW\")) ||\n (a === (\"A\" + len + \"GCMKW\")) ||\n (a.indexOf(\"PBES2-\") === 0) ||\n (a === \"dir\");\n });\n }\n\n return [];\n },\n encryptKey: function(alg, keys) {\n return keys.private && keys.private.k;\n },\n encryptProps: adjustEncryptProps,\n\n decryptKey: function(alg, keys) {\n return keys.private && keys.private.k;\n },\n decryptProps: adjustDecryptProps,\n\n wrapKey: function(alg, keys) {\n return keys.private && keys.private.k;\n },\n wrapProps: adjustEncryptProps,\n\n unwrapKey: function(alg, keys) {\n return keys.private && keys.private.k;\n },\n unwrapProps: adjustDecryptProps,\n\n signKey: function(alg, keys) {\n return keys.private && keys.private.k;\n },\n verifyKey: function(alg, keys) {\n return keys.private && keys.private.k;\n }\n};\n\n// Factory\nvar JWKOctetFactory = {\n kty: \"oct\",\n prepare: function(props) {\n // TODO: validate key properties\n var cfg = JWKOctetCfg;\n var p = Promise.resolve(props);\n p = p.then(function(json) {\n return JWK.helpers.thumbprint(cfg, json);\n });\n p = p.then(function(hash) {\n var prints = {};\n prints[JWK.helpers.INTERNALS.THUMBPRINT_HASH] = hash;\n props[JWK.helpers.INTERNALS.THUMBPRINT_KEY] = prints;\n return cfg;\n });\n return p;\n },\n generate: function(size) {\n // TODO: validate key sizes\n var key = util.randomBytes(size / 8);\n\n return Promise.resolve({\n k: key\n });\n }\n};\n\n// public API\nmodule.exports = Object.freeze({\n config: JWKOctetCfg,\n factory: JWKOctetFactory\n});\n\n// registration\n(function(REGISTRY) {\n REGISTRY.register(JWKOctetFactory);\n})(require(\"./keystore\").registry);\n","/*!\n * jwk/rsa.js - RSA Key Representation\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar forge = require(\"../deps/forge.js\"),\n rsau = require(\"../algorithms/rsa-util\"),\n nodeCrypto = require(\"../algorithms/helpers\").nodeCrypto;\n\nvar JWK = {\n BaseKey: require(\"./basekey.js\"),\n helpers: require(\"./helpers.js\")\n};\n\nvar SIG_ALGS = [\n \"RS256\",\n \"RS384\",\n \"RS512\",\n \"PS256\",\n \"PS384\",\n \"PS512\"\n];\nvar WRAP_ALGS = [\n \"RSA-OAEP\",\n \"RSA-OAEP-256\",\n \"RSA1_5\"\n];\n\nvar JWKRsaCfg = {\n publicKey: function(props) {\n var fields = JWK.helpers.COMMON_PROPS.concat([\n {name: \"n\", type: \"binary\"},\n {name: \"e\", type: \"binary\"}\n ]);\n var pk;\n pk = JWK.helpers.unpackProps(props, fields);\n if (pk && pk.n && pk.e) {\n pk.length = pk.n.length * 8;\n } else {\n delete pk.e;\n delete pk.n;\n }\n\n return pk;\n },\n privateKey: function(props) {\n var fields = JWK.helpers.COMMON_PROPS.concat([\n {name: \"n\", type: \"binary\"},\n {name: \"e\", type: \"binary\"},\n {name: \"d\", type: \"binary\"},\n {name: \"p\", type: \"binary\"},\n {name: \"q\", type: \"binary\"},\n {name: \"dp\", type: \"binary\"},\n {name: \"dq\", type: \"binary\"},\n {name: \"qi\", type: \"binary\"}\n ]);\n\n var pk;\n pk = JWK.helpers.unpackProps(props, fields);\n if (pk && pk.d && pk.n && pk.e && pk.p && pk.q && pk.dp && pk.dq && pk.qi) {\n pk.length = pk.d.length * 8;\n } else {\n pk = undefined;\n }\n\n return pk;\n },\n thumbprint: function(json) {\n if (json.public) {\n json = json.public;\n }\n var fields = {\n e: json.e,\n kty: \"RSA\",\n n: json.n\n };\n return fields;\n },\n algorithms: function(keys, mode) {\n switch (mode) {\n case \"encrypt\":\n case \"decrypt\":\n return [];\n case \"wrap\":\n return (keys.public && WRAP_ALGS.slice()) || [];\n case \"unwrap\":\n return (keys.private && WRAP_ALGS.slice()) || [];\n case \"sign\":\n return (keys.private && SIG_ALGS.slice()) || [];\n case \"verify\":\n return (keys.public && SIG_ALGS.slice()) || [];\n }\n\n return [];\n },\n\n wrapKey: function(alg, keys) {\n return keys.public;\n },\n unwrapKey: function(alg, keys) {\n return keys.private;\n },\n\n signKey: function(alg, keys) {\n return keys.private;\n },\n verifyKey: function(alg, keys) {\n return keys.public;\n },\n\n convertToPEM: function(key, isPrivate) {\n var k = rsau.convertToForge(key, !isPrivate);\n if (!isPrivate) {\n return forge.pki.publicKeyToPem(k);\n }\n return forge.pki.privateKeyToPem(k);\n }\n};\n\nfunction convertBNtoBuffer(bn) {\n bn = bn.toString(16);\n if (bn.length % 2) {\n bn = \"0\" + bn;\n }\n return Buffer.from(bn, \"hex\");\n}\n\n// Adapted from digitalbaazar/node-forge/js/rsa.js\nvar validators = {\n oid: \"1.2.840.113549.1.1.1\",\n privateKey: {\n name: \"RSAPrivateKey\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.SEQUENCE,\n constructed: true,\n value: [\n {\n // Version (INTEGER)\n name: \"RSAPrivateKey.version\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.INTEGER,\n constructed: false,\n capture: \"version\"\n },\n {\n // modulus (n)\n name: \"RSAPrivateKey.modulus\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.INTEGER,\n constructed: false,\n capture: \"n\"\n },\n {\n // publicExponent (e)\n name: \"RSAPrivateKey.publicExponent\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.INTEGER,\n constructed: false,\n capture: \"e\"\n },\n {\n // privateExponent (d)\n name: \"RSAPrivateKey.privateExponent\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.INTEGER,\n constructed: false,\n capture: \"d\"\n },\n {\n // prime1 (p)\n name: \"RSAPrivateKey.prime1\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.INTEGER,\n constructed: false,\n capture: \"p\"\n },\n {\n // prime2 (q)\n name: \"RSAPrivateKey.prime2\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.INTEGER,\n constructed: false,\n capture: \"q\"\n },\n {\n // exponent1 (d mod (p-1))\n name: \"RSAPrivateKey.exponent1\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.INTEGER,\n constructed: false,\n capture: \"dp\"\n },\n {\n // exponent2 (d mod (q-1))\n name: \"RSAPrivateKey.exponent2\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.INTEGER,\n constructed: false,\n capture: \"dq\"\n },\n {\n // coefficient ((inverse of q) mod p)\n name: \"RSAPrivateKey.coefficient\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.INTEGER,\n constructed: false,\n capture: \"qi\"\n }\n ]\n },\n publicKey: {\n // RSAPublicKey\n name: \"RSAPublicKey\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.SEQUENCE,\n constructed: true,\n value: [\n {\n // modulus (n)\n name: \"RSAPublicKey.modulus\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.INTEGER,\n constructed: false,\n capture: \"n\"\n },\n {\n // publicExponent (e)\n name: \"RSAPublicKey.exponent\",\n tagClass: forge.asn1.Class.UNIVERSAL,\n type: forge.asn1.Type.INTEGER,\n constructed: false,\n capture: \"e\"\n }\n ]\n }\n};\n\n// Factory\nvar JWKRsaFactory = {\n kty: \"RSA\",\n validators: validators,\n prepare: function(props) {\n // TODO: validate key properties\n var cfg = JWKRsaCfg;\n var p = Promise.resolve(props);\n p = p.then(function(json) {\n return JWK.helpers.thumbprint(cfg, json);\n });\n p = p.then(function(hash) {\n var prints = {};\n prints[JWK.helpers.INTERNALS.THUMBPRINT_HASH] = hash;\n props[JWK.helpers.INTERNALS.THUMBPRINT_KEY] = prints;\n return cfg;\n });\n return p;\n },\n generate: function(size) {\n // TODO: validate key sizes\n var promise;\n\n if (nodeCrypto) {\n promise = new Promise(function (resolve, reject) {\n forge.pki.rsa.generateKeyPair({\n bits: size,\n e: 0x010001\n }, function (err, key) {\n if (err) return reject(err);\n resolve(key.privateKey);\n });\n });\n } else {\n var key = forge.pki.rsa.generateKeyPair({\n bits: size,\n e: 0x010001\n });\n promise = Promise.resolve(key.privateKey);\n }\n\n return promise.then(function (key) {\n\n // convert to JSON-ish\n var result = {};\n [\n \"e\",\n \"n\",\n \"d\",\n \"p\",\n \"q\",\n {incoming: \"dP\", outgoing: \"dp\"},\n {incoming: \"dQ\", outgoing: \"dq\"},\n {incoming: \"qInv\", outgoing: \"qi\"}\n ].forEach(function(f) {\n var incoming,\n outgoing;\n\n if (\"string\" === typeof f) {\n incoming = outgoing = f;\n } else {\n incoming = f.incoming;\n outgoing = f.outgoing;\n }\n\n if (incoming in key) {\n result[outgoing] = convertBNtoBuffer(key[incoming]);\n }\n });\n\n return result;\n });\n },\n import: function(input) {\n if (validators.oid !== input.keyOid) {\n return null;\n }\n\n if (!input.parsed) {\n // coerce capture.keyValue to DER\n if (\"string\" === typeof input.keyValue) {\n input.keyValue = forge.asn1.fromDer(input.keyValue);\n } else if (Array.isArray(input.keyValue)) {\n input.keyValue = input.keyValue[0];\n }\n // capture key factors\n var validator = (\"private\" === input.type) ?\n validators.privateKey :\n validators.publicKey;\n var capture = {},\n errors = [];\n if (!forge.asn1.validate(input.keyValue, validator, capture, errors)) {\n return null;\n }\n input = capture;\n }\n\n // convert factors to Buffers\n var output = {\n kty: \"RSA\"\n };\n [\"n\", \"e\", \"d\", \"p\", \"q\", \"dp\", \"dq\", \"qi\"].forEach(function(f) {\n if (!(f in input)) {\n return;\n }\n var b = Buffer.from(input[f], \"binary\");\n // remove leading zero padding if any\n if (0 === b[0]) {\n b = b.slice(1);\n }\n output[f] = b;\n });\n return output;\n }\n};\n\n// public API\nmodule.exports = Object.freeze({\n config: JWKRsaCfg,\n factory: JWKRsaFactory\n});\n\n// registration\n(function(REGISTRY) {\n REGISTRY.register(JWKRsaFactory);\n})(require(\"./keystore\").registry);\n","/*!\n * jws/defaults.js - Defaults for JWSs\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\n/**\n * @description\n * The default options for {@link JWS.createSign}.\n *\n * @property {Boolean} compact Determines if the output is the Compact\n * serialization (`true`) or the JSON serialization (**`false`**,\n * the default).\n * @property {String|String[]} protect The names of the headers to integrity\n * protect. The value `\"\"` means that none of header parameters\n * are integrity protected, while `\"*\"` (the default) means that all\n * headers parameter sare integrity protected.\n */\nvar JWSDefaults = {\n compact: false,\n protect: \"*\"\n};\n\nmodule.exports = JWSDefaults;\n","/*!\n * jws/helpers.js - JWS Internal Helper Functions\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nmodule.exports = {\n slice: function(input, start) {\n return Array.prototype.slice.call(input, start || 0);\n }\n};\n","/*!\n * jws/index.js - JSON Web Signature (JWS) Entry Point\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar JWS = {\n createSign: require(\"./sign\").createSign,\n createVerify: require(\"./verify\").createVerify\n};\n\nmodule.exports = JWS;\n","/*!\n * jws/sign.js - Sign to JWS\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar merge = require(\"../util/merge\"),\n util = require(\"../util\"),\n JWK = require(\"../jwk\"),\n slice = require(\"./helpers\").slice;\n\nvar clone = require(\"lodash/clone\");\nvar uniq = require(\"lodash/uniq\");\n\nvar DEFAULTS = require(\"./defaults\");\n\n/**\n * @class JWS.Signer\n * @classdesc Generator of signed content.\n *\n * @description\n * **NOTE:** this class cannot be instantiated directly. Instead call {@link\n * JWS.createSign}.\n */\nvar JWSSigner = function(cfg, signatories) {\n var finalized = false,\n format = cfg.format || \"general\",\n content = Buffer.alloc(0);\n\n /**\n * @member {Boolean} JWS.Signer#compact\n * @description\n * Indicates whether the outuput of this signature generator is using\n * the Compact serialization (`true`) or the JSON serialization\n * (`false`).\n */\n Object.defineProperty(this, \"compact\", {\n get: function() {\n return \"compact\" === format;\n },\n enumerable: true\n });\n Object.defineProperty(this, \"format\", {\n get: function() {\n return format;\n },\n enumerable: true\n });\n\n /**\n * @method JWS.Signer#update\n * @description\n * Updates the signing content for this signature content. The content\n * is appended to the end of any other content already applied.\n *\n * If {data} is a Buffer, {encoding} is ignored. Otherwise, {data} is\n * converted to a Buffer internally to {encoding}.\n *\n * @param {Buffer|String} data The data to sign.\n * @param {String} [encoding=\"binary\"] The encoding of {data}.\n * @returns {JWS.Signer} This signature generator.\n * @throws {Error} If a signature has already been generated.\n */\n Object.defineProperty(this, \"update\", {\n value: function(data, encoding) {\n if (finalized) {\n throw new Error(\"already final\");\n }\n if (data != null) {\n data = util.asBuffer(data, encoding);\n if (content.length) {\n content = Buffer.concat([content, data],\n content.length + data.length);\n } else {\n content = data;\n }\n }\n\n return this;\n }\n });\n /**\n * @method JWS.Signer#final\n * @description\n * Finishes the signature operation.\n *\n * The returned Promise, when fulfilled, is the JSON Web Signature (JWS)\n * object, either in the Compact (if {@link JWS.Signer#format} is\n * `\"compact\"`), the flattened JSON (if {@link JWS.Signer#format} is\n * \"flattened\"), or the general JSON serialization.\n *\n * @param {Buffer|String} [data] The final content to apply.\n * @param {String} [encoding=\"binary\"] The encoding of the final content\n * (if any).\n * @returns {Promise} The promise for the signatures\n * @throws {Error} If a signature has already been generated.\n */\n Object.defineProperty(this, \"final\", {\n value: function(data, encoding) {\n if (finalized) {\n return Promise.reject(new Error(\"already final\"));\n }\n\n // last-minute data\n this.update(data, encoding);\n\n // mark as done...ish\n finalized = true;\n var promise;\n\n // map signatory promises to just signatories\n promise = Promise.all(signatories);\n promise = promise.then(function(sigs) {\n // prepare content\n content = util.base64url.encode(content);\n\n sigs = sigs.map(function(s) {\n // prepare protected\n var protect = {},\n lenProtect = 0,\n unprotect = clone(s.header),\n lenUnprotect = Object.keys(unprotect).length;\n s.protected.forEach(function(h) {\n if (!(h in unprotect)) {\n return;\n }\n protect[h] = unprotect[h];\n lenProtect++;\n delete unprotect[h];\n lenUnprotect--;\n });\n if (lenProtect > 0) {\n protect = JSON.stringify(protect);\n protect = util.base64url.encode(protect);\n } else {\n protect = \"\";\n }\n\n // signit!\n var data = Buffer.from(protect + \".\" + content, \"ascii\");\n s = s.key.sign(s.header.alg, data, s.header);\n s = s.then(function(result) {\n var sig = {};\n if (0 < lenProtect) {\n sig.protected = protect;\n }\n if (0 < lenUnprotect) {\n sig.header = unprotect;\n }\n sig.signature = util.base64url.encode(result.mac);\n return sig;\n });\n return s;\n });\n sigs = [Promise.resolve(content)].concat(sigs);\n return Promise.all(sigs);\n });\n promise = promise.then(function(results) {\n var content = results[0];\n return {\n payload: content,\n signatures: results.slice(1)\n };\n });\n switch (format) {\n case \"compact\":\n promise = promise.then(function(jws) {\n var compact = [\n jws.signatures[0].protected,\n jws.payload,\n jws.signatures[0].signature\n ];\n compact = compact.join(\".\");\n return compact;\n });\n break;\n case \"flattened\":\n promise = promise.then(function(jws) {\n var flattened = {};\n flattened.payload = jws.payload;\n\n var sig = jws.signatures[0];\n if (sig.protected) {\n flattened.protected = sig.protected;\n }\n if (sig.header) {\n flattened.header = sig.header;\n }\n flattened.signature = sig.signature;\n\n return flattened;\n });\n break;\n }\n\n return promise;\n }\n });\n};\n\n\n/**\n * @description\n * Creates a new JWS.Signer with the given options and signatories.\n *\n * @param {Object} [opts] The signing options\n * @param {Boolean} [opts.compact] Use compact serialization?\n * @param {String} [opts.format] The serialization format to use (\"compact\",\n * \"flattened\", \"general\")\n * @param {Object} [opts.fields] Additional header fields\n * @param {JWK.Key[]|Object[]} [signs] Signatories, either as an array of\n * JWK.Key instances; or an array of objects, each with the following\n * properties\n * @param {JWK.Key} signs.key Key used to sign content\n * @param {Object} [signs.header] Per-signatory header fields\n * @param {String} [signs.reference] Reference field to identify the key\n * @param {String[]|String} [signs.protect] List of fields to integrity\n * protect (\"*\" to protect all fields)\n * @returns {JWS.Signer} The signature generator.\n * @throws {Error} If Compact serialization is requested but there are\n * multiple signatories\n */\nfunction createSign(opts, signs) {\n // fixup signatories\n var options = opts,\n signStart = 1,\n signList = signs;\n\n if (arguments.length === 0) {\n throw new Error(\"at least one signatory must be provided\");\n }\n if (arguments.length === 1) {\n signList = opts;\n signStart = 0;\n options = {};\n } else if (JWK.isKey(opts) ||\n (opts && \"kty\" in opts) ||\n (opts && \"key\" in opts &&\n (JWK.isKey(opts.key) || \"kty\" in opts.key))) {\n signList = opts;\n signStart = 0;\n options = {};\n } else {\n options = clone(opts);\n }\n if (!Array.isArray(signList)) {\n signList = slice(arguments, signStart);\n }\n\n // fixup options\n options = merge(clone(DEFAULTS), options);\n\n // setup header fields\n var allFields = options.fields || {};\n // setup serialization format\n var format = options.format;\n if (!format) {\n format = options.compact ? \"compact\" : \"general\";\n }\n if ((\"compact\" === format || \"flattened\" === format) && 1 < signList.length) {\n throw new Error(\"too many signatories for compact or flattened JSON serialization\");\n }\n\n // note protected fields (globally)\n // protected fields are per signature\n var protectAll = (\"*\" === options.protect);\n if (options.compact) {\n protectAll = true;\n }\n\n signList = signList.map(function(s, idx) {\n var p;\n\n // resolve a key\n if (s && \"kty\" in s) {\n p = JWK.asKey(s);\n p = p.then(function(k) {\n return {\n key: k\n };\n });\n } else if (s) {\n p = JWK.asKey(s.key);\n p = p.then(function(k) {\n return {\n header: s.header,\n reference: s.reference,\n protect: s.protect,\n key: k\n };\n });\n } else {\n p = Promise.reject(new Error(\"missing key for signatory \" + idx));\n }\n\n // resolve the complete signatory\n p = p.then(function(signatory) {\n var key = signatory.key;\n\n // make sure there is a header\n var header = signatory.header || {};\n header = merge(merge({}, allFields), header);\n signatory.header = header;\n\n // ensure an algorithm\n if (!header.alg) {\n header.alg = key.algorithms(JWK.MODE_SIGN)[0] || \"\";\n }\n\n // determine the key reference\n var ref = signatory.reference;\n delete signatory.reference;\n if (undefined === ref) {\n // header already contains the key reference\n ref = [\"kid\", \"jku\", \"x5c\", \"x5t\", \"x5u\"].some(function(k) {\n return (k in header);\n });\n ref = !ref ? \"kid\" : null;\n } else if (\"boolean\" === typeof ref) {\n // explicit (positive | negative) request for key reference\n ref = ref ? \"kid\" : null;\n }\n var jwk;\n if (ref) {\n jwk = key.toJSON();\n if (\"jwk\" === ref) {\n if (\"oct\" === key.kty) {\n return Promise.reject(new Error(\"cannot embed key\"));\n }\n header.jwk = jwk;\n } else if (ref in jwk) {\n header[ref] = jwk[ref];\n }\n }\n\n // determine protected fields\n var protect = signatory.protect;\n if (protectAll || \"*\" === protect) {\n protect = Object.keys(header);\n } else if (\"string\" === protect) {\n protect = [protect];\n } else if (Array.isArray(protect)) {\n protect = protect.concat();\n } else if (!protect) {\n protect = [];\n } else {\n return Promise.reject(new Error(\"protect must be a list of fields\"));\n }\n protect = uniq(protect);\n signatory.protected = protect;\n\n // freeze signatory\n signatory = Object.freeze(signatory);\n return signatory;\n });\n\n return p;\n });\n\n var cfg = {\n format: format\n };\n return new JWSSigner(cfg,\n signList);\n}\n\nmodule.exports = {\n signer: JWSSigner,\n createSign: createSign\n};\n","/*!\n * jws/verify.js - Verifies from a JWS\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar clone = require(\"lodash/clone\"),\n merge = require(\"../util/merge\"),\n base64url = require(\"../util/base64url\"),\n AlgConfig = require(\"../util/algconfig\"),\n JWK = require(\"../jwk\");\n\nvar DEFAULT_OPTIONS = {\n algorithms: \"*\",\n allowEmbeddedKey: false\n};\n\n/**\n * @class JWS.Verifier\n * @classdesc Parser of signed content.\n *\n * @description\n * **NOTE:** this class cannot be instantiated directly. Instead call {@link\n * JWS.createVerify}.\n */\nvar JWSVerifier = function(ks, globalOpts) {\n var assumedKey,\n keystore;\n\n if (JWK.isKey(ks)) {\n assumedKey = ks;\n keystore = assumedKey.keystore;\n } else if (JWK.isKeyStore(ks)) {\n keystore = ks;\n } else {\n keystore = JWK.createKeyStore();\n }\n\n globalOpts = merge(DEFAULT_OPTIONS, globalOpts);\n\n Object.defineProperty(this, \"defaultKey\", {\n value: assumedKey || undefined,\n enumerable: true\n });\n Object.defineProperty(this, \"keystore\", {\n value: keystore,\n enumerable: true\n });\n\n Object.defineProperty(this, \"verify\", {\n value: function(input, opts) {\n opts = merge({}, globalOpts, opts || {});\n var extraHandlers = opts.handlers || {};\n var handlerKeys = Object.keys(extraHandlers);\n var algSpec = new AlgConfig(opts.algorithms);\n\n if (\"string\" === typeof input) {\n input = input.split(\".\");\n input = {\n payload: input[1],\n signatures: [\n {\n protected: input[0],\n signature: input[2]\n }\n ]\n };\n } else if (!input || \"object\" !== typeof input) {\n throw new Error(\"invalid input\");\n }\n\n // fixup \"flattened JSON\" to look like \"general JSON\"\n if (input.signature) {\n input.signatures = [\n {\n protected: input.protected || undefined,\n header: input.header || undefined,\n signature: input.signature\n }\n ];\n }\n\n // ensure signatories exists\n var sigList = input.signatures || [{}];\n\n // combine fields and decode signature per signatory\n sigList = sigList.map(function(s) {\n var header = clone(s.header || {});\n var protect = s.protected ?\n JSON.parse(base64url.decode(s.protected, \"utf8\")) :\n {};\n header = merge(header, protect);\n var signature = base64url.decode(s.signature);\n\n // process allowed algorithims\n if (!algSpec.match(header.alg)) {\n return Promise.reject(new Error(\"Algorithm not allowed: \" + header.alg));\n }\n\n // process \"crit\" first\n var crit = protect.crit;\n if (crit) {\n if (!Array.isArray(crit)) {\n return Promise.reject(new Error(\"Invalid 'crit' header\"));\n }\n for (var idx = 0; crit.length > idx; idx++) {\n if (-1 === handlerKeys.indexOf(crit[idx])) {\n return Promise.reject(new Error(\n \"Critical extension is not supported: \" + crit[idx]\n ));\n }\n }\n }\n protect = Object.keys(protect);\n\n return Promise.resolve({\n protected: protect,\n aad: s.protected || \"\",\n header: header,\n signature: signature\n });\n });\n\n var promise = Promise.all(sigList);\n promise = promise.then(function(sigList) {\n return new Promise(function(resolve, reject) {\n var processSig = function() {\n var sig = sigList.shift();\n if (!sig) {\n reject(new Error(\"no key found\"));\n return;\n }\n\n sig = merge({}, sig, {\n payload: input.payload\n });\n var p = Promise.resolve(sig);\n // find the key\n p = p.then(function(sig) {\n var algKey;\n // TODO: resolve jku, x5c, x5u\n if (opts.allowEmbeddedKey && sig.header.jwk) {\n algKey = JWK.asKey(sig.header.jwk);\n } else if (opts.allowEmbeddedKey && sig.header.x5c) {\n algKey = sig.header.x5c[0];\n algKey = Buffer.from(algKey, \"base64\");\n // TODO: callback to validate chain\n algKey = JWK.asKey(algKey, \"pkix\");\n } else {\n algKey = Promise.resolve(assumedKey || keystore.get({\n use: \"sig\",\n alg: sig.header.alg,\n kid: sig.header.kid\n }));\n }\n return algKey.then(function(k) {\n if (!k) {\n return Promise.reject(new Error(\"key does not match\"));\n }\n sig.key = k;\n return sig;\n });\n });\n\n // process any prepare-verify handlers\n p = p.then(function(sig) {\n var processing = [];\n handlerKeys.forEach(function(h) {\n h = extraHandlers[h];\n var p;\n if (\"function\" === typeof h) {\n p = h(sig);\n } else if (\"object\" === typeof h && \"function\" === typeof h.prepare) {\n p = h.prepare(sig);\n }\n if (p) {\n processing.push(Promise.resolve(p));\n }\n });\n return Promise.all(processing).then(function() {\n // don't actually care about individual handler results\n // assume {sig} is updated\n return sig;\n });\n });\n\n // prepare verify inputs\n p = p.then(function(sig) {\n var aad = sig.aad || \"\",\n payload = sig.payload || \"\";\n var content = Buffer.alloc(1 + aad.length + payload.length),\n pos = 0;\n content.write(aad, pos, \"ascii\");\n pos += aad.length;\n content.write(\".\", pos, \"ascii\");\n pos++;\n\n if (Buffer.isBuffer(payload)) {\n payload.copy(content, pos);\n } else {\n content.write(payload, pos, \"binary\");\n }\n sig.content = content;\n return sig;\n });\n\n p = p.then(function(sig) {\n return sig.key.verify(sig.header.alg,\n sig.content,\n sig.signature);\n });\n\n p = p.then(function(result) {\n var payload = sig.payload;\n payload = base64url.decode(payload);\n return {\n protected: sig.protected,\n header: sig.header,\n payload: payload,\n signature: result.mac,\n key: sig.key\n };\n });\n\n // process any post-verify handlers\n p = p.then(function(jws) {\n var processing = [];\n handlerKeys.forEach(function(h) {\n h = extraHandlers[h];\n var p;\n if (\"object\" === typeof h && \"function\" === typeof h.complete) {\n p = h.complete(jws);\n }\n if (p) {\n processing.push(Promise.resolve(p));\n }\n });\n return Promise.all(processing).then(function() {\n // don't actually care about individual handler results\n // assume {jws} is updated\n return jws;\n });\n });\n p.then(resolve, processSig);\n };\n processSig();\n });\n });\n return promise;\n }\n });\n};\n\n/**\n * @description\n * Creates a new JWS.Verifier with the given Key or KeyStore.\n *\n * @param {JWK.Key|JWK.KeyStore} ks The Key or KeyStore to use for verification.\n * @returns {JWS.Verifier} The new Verifier.\n */\nfunction createVerify(ks, opts) {\n var vfy = new JWSVerifier(ks, opts);\n\n return vfy;\n}\n\nmodule.exports = {\n verifier: JWSVerifier,\n createVerify: createVerify\n};\n","/*!\n * parse/compact.js - JOSE Compact Serialization Parser\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar jose = {\n JWE: require(\"../jwe\"),\n JWS: require(\"../jws\"),\n util: require(\"../util\")\n};\n\nfunction parseCompact(input) {\n var parts = input.split(\".\");\n\n var type,\n op;\n if (3 === parts.length) {\n // JWS\n type = \"JWS\";\n op = function(ks, opts) {\n return jose.JWS.createVerify(ks).\n verify(input, opts);\n };\n } else if (5 === parts.length) {\n // JWE\n type = \"JWE\";\n op = function(ks, opts) {\n return jose.JWE.createDecrypt(ks).\n decrypt(input, opts);\n };\n } else {\n throw new TypeError(\"invalid jose serialization\");\n }\n\n // parse header\n var header;\n header = jose.util.base64url.decode(parts[0], \"utf8\");\n header = JSON.parse(header);\n return {\n type: type,\n format: \"compact\",\n input: input,\n header: header,\n perform: op\n };\n}\n\nmodule.exports = parseCompact;\n","/*!\n * parse/index.js - JOSE Parser Entry Point\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar compact = require(\"./compact\"),\n json = require(\"./json\");\n\nvar parse = module.exports = function(input) {\n if (Buffer.isBuffer(input)) {\n // assume buffer holds a Compact Serialization string\n return compact(input.toString(\"ascii\"));\n } else if (\"string\" === typeof input) {\n return compact(input);\n } else if (input) {\n return json(input);\n } else {\n throw new TypeError(\"invalid input\");\n }\n};\n\nparse.compact = compact;\nparse.json = json;\n","/*!\n * parse/compact.js - JOSE JSON Serialization Parser\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar merge = require(\"../util/merge\");\n\nvar jose = {\n JWE: require(\"../jwe\"),\n JWS: require(\"../jws\"),\n util: require(\"../util\")\n};\n\nfunction parseJSON(input) {\n var type,\n op,\n headers;\n\n if (\"signatures\" in input || \"signature\" in input) {\n // JWS\n type = \"JWS\";\n op = function(ks, opts) {\n return jose.JWS.createVerify(ks).\n verify(input, opts);\n };\n // headers can be (signatures[].protected, signatures[].header, signature.protected, signature.header)\n headers = input.signatures ||\n [ {\n protected: input.protected,\n header: input.header,\n signature: input.signature\n }];\n headers = headers.map(function(sig) {\n var all = {};\n if (sig.header) {\n all = merge(all, sig.header);\n }\n\n var prot;\n if (sig.protected) {\n prot = sig.protected;\n prot = jose.util.base64url.decode(prot, \"utf8\");\n prot = JSON.parse(prot);\n all = merge(all, prot);\n }\n\n return all;\n });\n } else if (\"ciphertext\" in input) {\n // JWE\n type = \"JWE\";\n op = function(ks, opts) {\n return jose.JWE.createDecrypt(ks).\n decrypt(input, opts);\n };\n // headers can be (protected, unprotected, recipients[].header)\n var root = {};\n if (input.protected) {\n root.protected = input.protected;\n root.protected = jose.util.base64url.decode(root.protected, \"utf8\");\n root.protected = JSON.parse(root.protected);\n }\n if (input.unprotected) {\n root.unprotected = input.unprotected;\n }\n\n headers = input.recipients || [{}];\n headers = headers.map(function(rcpt) {\n var all = {};\n if (rcpt.header) {\n all = merge(all, rcpt.header);\n }\n if (root.unprotected) {\n all = merge(all, root.unprotected);\n }\n if (root.protected) {\n all = merge(all, root.protected);\n }\n\n return all;\n });\n }\n\n return {\n type: type,\n format: \"json\",\n input: input,\n all: headers,\n perform: op\n };\n}\n\nmodule.exports = parseJSON;\n","/*!\n * util/algconfig.js - Functions for managing algorithm set options\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nfunction quoteRE(str) {\n return str.replace(/[.?*+^$[\\]\\\\(){}|-]/g, \"\\\\$&\");\n}\n\nfunction makeRE(prefix, wildcard, suffix) {\n var parts = [];\n\n parts.push(\"^\");\n if (prefix) {\n prefix = quoteRE(prefix);\n parts.push(prefix);\n }\n if (wildcard) {\n parts.push((prefix || suffix) ? \".*\" : \".+\");\n }\n if (suffix) {\n suffix = quoteRE(suffix);\n parts.push(suffix);\n }\n parts.push(\"$\");\n\n return parts.join(\"\");\n}\n\nvar AlgConfig = function(algspec) {\n if (!algspec) {\n algspec = [];\n } else if (\"string\" === typeof algspec) {\n algspec = algspec.split(\" \");\n }\n\n var specAllowed = [], specDisallowed = [];\n var ptnAllowed = [], ptnDisallowed = [];\n var ptn = /^(!)?([^*]*)(\\*?)([^*]*)$/, fmt;\n algspec.forEach(function (a) {\n if (!a) { return; }\n\n ptn.lastIndex = 0;\n var parts = ptn.exec(a);\n if (!parts) { return; }\n\n fmt = \"(\" + makeRE(parts[2], parts[3], parts[4]) + \")\";\n if (!parts[1]) {\n // allowed pattern\n ptnAllowed.push(fmt);\n specAllowed.push(parts[0]);\n } else {\n // disallowed pattern\n ptnDisallowed.push(fmt);\n specDisallowed.push(parts[0]);\n }\n });\n\n ptnAllowed = (ptnAllowed.length) ?\n new RegExp(ptnAllowed.join(\"|\")) :\n null;\n ptnDisallowed = (ptnDisallowed.length) ?\n new RegExp(ptnDisallowed.join(\"|\")) :\n null;\n if (!specAllowed.length) {\n specAllowed = [\"*\"];\n }\n\n Object.defineProperty(this, \"spec\", {\n value: specAllowed.join(\" \") + \" \" + specDisallowed.join(\" \"),\n enumerable: true\n });\n Object.defineProperty(this, \"match\", {\n value: function(alg) {\n var result = Boolean(alg);\n\n if (result && ptnAllowed) {\n ptnAllowed.lastIndex = 0;\n result = ptnAllowed.test(alg);\n }\n if (result && ptnDisallowed) {\n ptnDisallowed.lastIndex = 0;\n result = !ptnDisallowed.test(alg);\n }\n\n return result;\n }\n });\n}\n\nmodule.exports = AlgConfig;\n","/*!\n * util/base64url.js - Implementation of web-safe Base64 Encoder/Decoder\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar impl = require(\"base64url\");\n\n/**\n * @namespace base64url\n * @description\n * Provides methods to encode and decode data according to the\n * base64url alphabet.\n */\nvar base64url = {\n /**\n * @function\n * Encodes the input to base64url.\n *\n * If {input} is a Buffer, then {encoding} is ignored. Otherwise,\n * {encoding} can be one of \"binary\", \"base64\", \"hex\", \"utf8\".\n *\n * @param {Buffer|String} input The data to encode.\n * @param {String} [encoding = binary] The input encoding format.\n * @returns {String} the base64url encoding of {input}.\n */\n encode: function encode(buffer, encoding) {\n if (buffer instanceof ArrayBuffer) {\n buffer = new Uint8Array(buffer);\n }\n\n if (!Buffer.isBuffer(buffer)) {\n buffer = Buffer.from(buffer, encoding);\n }\n\n return impl.encode(buffer);\n },\n /**\n * @function\n * Decodes the input from base64url.\n *\n * @param {String} input The data to decode.\n * @returns {Buffer|String} the base64url decoding of {input}.\n */\n decode: impl.toBuffer\n};\n\nmodule.exports = base64url;\n","/*!\n * util/databuffer.js - Forge-compatible Buffer based on Node.js Buffers\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar forge = require(\"../deps/forge.js\"),\n base64url = require(\"./base64url.js\");\n\n/**\n *\n */\nfunction DataBuffer(b, options) {\n options = options || {};\n\n // treat (views of) (Array)Buffers special\n // NOTE: default implementation creates copies, but efficiently\n // wherever possible\n if (Buffer.isBuffer(b)) {\n this.data = b;\n } else if (forge.util.isArrayBuffer(b)) {\n b = new Uint8Array(b);\n this.data = Buffer.from(b);\n } else if (forge.util.isArrayBufferView(b)) {\n b = new Uint8Array(b.buffer, b.byteOffset, b.byteLength);\n this.data = Buffer.from(b);\n }\n\n if (this.data) {\n this.write = this.data.length;\n b = undefined;\n }\n\n // setup growth rate\n this.growSize = options.growSize || DataBuffer.DEFAULT_GROW_SIZE;\n\n // initialize pointers and data\n this.write = this.write || 0;\n this.read = this.read || 0;\n if (b) {\n this.putBytes(b);\n } else if (!this.data) {\n this.accommodate(0);\n }\n\n // massage read/write pointers\n options.readOffset = (\"readOffset\" in options) ?\n options.readOffset :\n this.read;\n this.write = (\"writeOffset\" in options) ?\n options.writeOffset :\n this.write;\n this.read = Math.min(options.readOffset, this.write);\n}\nDataBuffer.DEFAULT_GROW_SIZE = 16;\n\nDataBuffer.prototype.length = function() {\n return this.write - this.read;\n};\nDataBuffer.prototype.available = function() {\n return this.data.length - this.write;\n};\nDataBuffer.prototype.isEmpty = function() {\n return this.length() <= 0;\n};\n\nDataBuffer.prototype.accommodate = function(length) {\n if (!this.data) {\n // initializes a new buffer\n length = Math.max(this.write + length, this.growSize);\n\n this.data = Buffer.alloc(length);\n } else if (this.available() < length) {\n length = Math.max(length, this.growSize);\n\n // create a new empty buffer, and copy current one into it\n var src = this.data;\n var dst = Buffer.alloc(src.length + length);\n src.copy(dst, 0);\n\n // set data as the new buffer\n this.data = dst;\n }\n // ensure the rest is 0\n this.data.fill(0, this.write);\n\n return this;\n};\nDataBuffer.prototype.clear = function() {\n this.read = this.write = 0;\n this.data = Buffer.alloc(0);\n return this;\n};\nDataBuffer.prototype.truncate = function(count) {\n // chop off bytes from the end\n this.write = this.read + Math.max(0, this.length() - count);\n // ensure the remainder is 0\n this.data.fill(0, this.write);\n return this;\n};\nDataBuffer.prototype.compact = function() {\n if (this.read > 0) {\n if (this.write === this.read) {\n this.read = this.write = 0;\n } else {\n this.data.copy(this.data, 0, this.read, this.write);\n this.write = this.write - this.read;\n this.read = 0;\n }\n // ensure remainder is 0\n this.data.fill(0, this.write);\n }\n return this;\n};\nDataBuffer.prototype.copy = function() {\n return new DataBuffer(this, {\n readOffset: this.read,\n writeOffset: this.write,\n growSize: this.growSize\n });\n};\n\nDataBuffer.prototype.equals = function(test) {\n if (!DataBuffer.isBuffer(test)) {\n return false;\n }\n\n if (test.length() !== this.length()) {\n return false;\n }\n\n var rval = true,\n delta = this.read - test.read;\n // constant time\n for (var idx = test.read; test.write > idx; idx++) {\n rval = rval && (this.data[idx + delta] === test.data[idx]);\n }\n return rval;\n};\nDataBuffer.prototype.at = function(idx) {\n return this.data[this.read + idx];\n};\nDataBuffer.prototype.setAt = function(idx, b) {\n this.data[this.read + idx] = b;\n return this;\n};\nDataBuffer.prototype.last = function() {\n return this.data[this.write - 1];\n};\nDataBuffer.prototype.bytes = function(count) {\n var rval;\n if (undefined === count) {\n count = this.length();\n } else if (count) {\n count = Math.min(count, this.length());\n }\n\n if (0 === count) {\n rval = \"\";\n } else {\n var begin = this.read,\n end = begin + count,\n data = this.data.slice(begin, end);\n rval = String.fromCharCode.apply(null, data);\n }\n\n return rval;\n};\nDataBuffer.prototype.buffer = function(count) {\n var rval;\n if (undefined === count) {\n count = this.length();\n } else if (count) {\n count = Math.min(count, this.length());\n }\n\n if (0 === count) {\n rval = new ArrayBuffer(0);\n } else {\n var begin = this.read,\n end = begin + count,\n data = this.data.slice(begin, end);\n rval = new Uint8Array(end - begin);\n rval.set(data);\n }\n\n return rval;\n};\nDataBuffer.prototype.native = function(count) {\n var rval;\n if (\"undefined\" === typeof count) {\n count = this.length();\n } else if (count) {\n count = Math.min(count, this.length());\n }\n\n if (0 === count) {\n rval = Buffer.alloc(0);\n } else {\n var begin = this.read,\n end = begin + count;\n rval = this.data.slice(begin, end);\n }\n\n return rval;\n};\n\nDataBuffer.prototype.toHex = function() {\n return this.toString(\"hex\");\n};\nDataBuffer.prototype.toString = function(encoding) {\n // short circuit empty string\n if (0 === this.length()) {\n return \"\";\n }\n\n var view = this.data.slice(this.read, this.write);\n encoding = encoding || \"utf8\";\n // special cases, then built-in support\n switch (encoding) {\n case \"raw\":\n return view.toString(\"binary\");\n case \"base64url\":\n return base64url.encode(view);\n case \"utf16\":\n return view.toString(\"ucs2\");\n default:\n return view.toString(encoding);\n }\n};\n\nDataBuffer.prototype.fillWithByte = function(b, n) {\n if (!n) {\n n = this.available();\n }\n this.accommodate(n);\n this.data.fill(b, this.write, this.write + n);\n this.write += n;\n\n return this;\n};\n\nDataBuffer.prototype.getBuffer = function(count) {\n var rval = this.buffer(count);\n this.read += rval.byteLength;\n\n return rval;\n};\nDataBuffer.prototype.putBuffer = function(bytes) {\n return this.putBytes(bytes);\n};\n\nDataBuffer.prototype.getBytes = function(count) {\n var rval = this.bytes(count);\n this.read += rval.length;\n return rval;\n};\nDataBuffer.prototype.putBytes = function(bytes, encoding) {\n if (\"string\" === typeof bytes) {\n // fixup encoding\n encoding = encoding || \"binary\";\n switch (encoding) {\n case \"utf16\":\n // treat as UCS-2/UTF-16BE\n encoding = \"ucs-2\";\n break;\n case \"raw\":\n encoding = \"binary\";\n break;\n case \"base64url\":\n // NOTE: this returns a Buffer\n bytes = base64url.decode(bytes);\n break;\n }\n\n // replace bytes with decoded Buffer (if not already)\n if (!Buffer.isBuffer(bytes)) {\n bytes = Buffer.from(bytes, encoding);\n }\n }\n\n var src, dst;\n if (bytes instanceof DataBuffer) {\n // be slightly more efficient\n var orig = bytes;\n bytes = orig.data.slice(orig.read, orig.write);\n orig.read = orig.write;\n } else if (bytes instanceof forge.util.ByteStringBuffer) {\n bytes = bytes.getBytes();\n }\n\n // process array\n if (Buffer.isBuffer(bytes)) {\n src = bytes;\n } else if (Array.isArray(bytes)) {\n src = Buffer.from(bytes);\n } else if (forge.util.isArrayBuffer(bytes)) {\n src = new Uint8Array(bytes);\n src = Buffer.from(src);\n } else if (forge.util.isArrayBufferView(bytes)) {\n src = (bytes instanceof Uint8Array) ?\n bytes :\n new Uint8Array(bytes.buffer,\n bytes.byteOffset,\n bytes.byteLength);\n src = Buffer.from(src);\n } else {\n throw new TypeError(\"invalid source type\");\n }\n\n this.accommodate(src.length);\n dst = this.data;\n src.copy(dst, this.write);\n this.write += src.length;\n\n return this;\n};\n\nDataBuffer.prototype.getNative = function(count) {\n var rval = this.native(count);\n this.read += rval.length;\n return rval;\n};\nDataBuffer.prototype.putNative = DataBuffer.prototype.putBuffer;\n\nDataBuffer.prototype.getByte = function() {\n var b = this.data[this.read];\n this.read = Math.min(this.read + 1, this.write);\n return b;\n};\nDataBuffer.prototype.putByte = function(b) {\n this.accommodate(1);\n this.data[this.write] = b & 0xff;\n this.write++;\n\n return this;\n};\n\nDataBuffer.prototype.getInt16 = function() {\n var n = (this.data[this.read] << 8) ^\n (this.data[this.read + 1]);\n this.read = Math.min(this.read + 2, this.write);\n return n;\n};\nDataBuffer.prototype.putInt16 = function(n) {\n this.accommodate(2);\n this.data[this.write] = (n >>> 8) & 0xff;\n this.data[this.write + 1] = n & 0xff;\n this.write += 2;\n return this;\n};\n\nDataBuffer.prototype.getInt24 = function() {\n var n = (this.data[this.read] << 16) ^\n (this.data[this.read + 1] << 8) ^\n this.data[this.read + 2];\n this.read = Math.min(this.read + 3, this.write);\n return n;\n};\nDataBuffer.prototype.putInt24 = function(n) {\n this.accommodate(3);\n this.data[this.write] = (n >>> 16) & 0xff;\n this.data[this.write + 1] = (n >>> 8) & 0xff;\n this.data[this.write + 2] = n & 0xff;\n this.write += 3;\n return this;\n};\n\nDataBuffer.prototype.getInt32 = function() {\n var n = (this.data[this.read] << 24) ^\n (this.data[this.read + 1] << 16) ^\n (this.data[this.read + 2] << 8) ^\n this.data[this.read + 3];\n this.read = Math.min(this.read + 4, this.write);\n return n;\n};\nDataBuffer.prototype.putInt32 = function(n) {\n this.accommodate(4);\n this.data[this.write] = (n >>> 24) & 0xff;\n this.data[this.write + 1] = (n >>> 16) & 0xff;\n this.data[this.write + 2] = (n >>> 8) & 0xff;\n this.data[this.write + 3] = n & 0xff;\n this.write += 4;\n return this;\n};\n\nDataBuffer.prototype.getInt16Le = function() {\n var n = (this.data[this.read + 1] << 8) ^\n this.data[this.read];\n this.read = Math.min(this.read + 2, this.write);\n return n;\n};\nDataBuffer.prototype.putInt16Le = function(n) {\n this.accommodate(2);\n this.data[this.write + 1] = (n >>> 8) & 0xff;\n this.data[this.write] = n & 0xff;\n this.write += 2;\n return this;\n};\n\nDataBuffer.prototype.getInt24Le = function() {\n var n = (this.data[this.read + 2] << 16) ^\n (this.data[this.read + 1] << 8) ^\n this.data[this.read];\n this.read = Math.min(this.read + 3, this.write);\n return n;\n};\nDataBuffer.prototype.putInt24Le = function(n) {\n this.accommodate(3);\n this.data[this.write + 2] = (n >>> 16) & 0xff;\n this.data[this.write + 1] = (n >>> 8) & 0xff;\n this.data[this.write] = n & 0xff;\n this.write += 3;\n return this;\n};\nDataBuffer.prototype.getInt32Le = function() {\n var n = (this.data[this.read + 3] << 24) ^\n (this.data[this.read + 2] << 16) ^\n (this.data[this.read + 1] << 8) ^\n this.data[this.read];\n this.read = Math.min(this.read + 4, this.write);\n return n;\n};\nDataBuffer.prototype.putInt32Le = function(n) {\n this.accommodate(4);\n this.data[this.write + 3] = (n >>> 24) & 0xff;\n this.data[this.write + 2] = (n >>> 16) & 0xff;\n this.data[this.write + 1] = (n >>> 8) & 0xff;\n this.data[this.write] = n & 0xff;\n this.write += 4;\n return this;\n};\n\nDataBuffer.prototype.getInt = function(bits) {\n var rval = 0;\n do {\n rval = (rval << 8) | this.getByte();\n bits -= 8;\n } while (bits > 0);\n return rval;\n};\nDataBuffer.prototype.putInt = function(n, bits) {\n this.accommodate(Math.ceil(bits / 8));\n do {\n bits -= 8;\n this.putByte((n >> bits) & 0xff);\n } while (bits > 0);\n return this;\n};\n\nDataBuffer.prototype.putSignedInt = function(n, bits) {\n if (n < 0) {\n n += 2 << (bits - 1);\n }\n return this.putInt(n, bits);\n};\n\nDataBuffer.prototype.putString = function(str) {\n return this.putBytes(str, \"utf16\");\n};\n\nDataBuffer.isBuffer = function(test) {\n return (test instanceof DataBuffer);\n};\nDataBuffer.asBuffer = function(orig) {\n return DataBuffer.isBuffer(orig) ?\n orig :\n orig ?\n new DataBuffer(orig) :\n new DataBuffer();\n};\n\nmodule.exports = DataBuffer;\n","/*!\n * util/index.js - Utilities Entry Point\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar forge = require(\"../deps/forge.js\");\n\nvar util;\n\nfunction asBuffer(input, encoding) {\n if (Buffer.isBuffer(input)) {\n return input;\n }\n\n if (\"string\" === typeof input) {\n encoding = encoding || \"binary\";\n if (\"base64url\" === encoding) {\n return util.base64url.decode(input);\n }\n return Buffer.from(input, encoding);\n }\n\n // assume input is an Array, ArrayBuffer, or ArrayBufferView\n if (forge.util.isArrayBufferView(input)) {\n input = (input instanceof Uint8Array) ?\n input :\n new Uint8Array(input.buffer, input.byteOffset, input.byteOffset + input.byteLength);\n } else if (forge.util.isArrayBuffer(input)) {\n input = new Uint8Array(input);\n }\n\n var output;\n output = Buffer.from(input);\n\n return output;\n}\n\nfunction randomBytes(len) {\n return Buffer.from(forge.random.getBytes(len), \"binary\");\n}\n\nutil = {\n base64url: require(\"./base64url.js\"),\n utf8: require(\"./utf8.js\"),\n asBuffer: asBuffer,\n randomBytes: randomBytes\n};\nmodule.exports = util;\n","/*!\n * util/utf8.js - Implementation of UTF-8 Encoder/Decoder\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar partialRight = require(\"lodash/partialRight\");\nvar merge = require(\"lodash/merge\");\n\nvar typedArrayCtors = (function() {\n var ctors = [];\n if (\"undefined\" !== typeof Uint8ClampedArray) {\n ctors.push(Uint8ClampedArray);\n }\n if (\"undefined\" !== typeof Uint8Array) {\n ctors.push(Uint8Array);\n }\n if (\"undefined\" !== typeof Uint16Array) {\n ctors.push(Uint16Array);\n }\n if (\"undefined\" !== typeof Uint32Array) {\n ctors.push(Uint32Array);\n }\n if (\"undefined\" !== typeof Float32Array) {\n ctors.push(Float32Array);\n }\n if (\"undefined\" !== typeof Float64Array) {\n ctors.push(Float64Array);\n }\n return ctors;\n})();\n\nfunction findTypedArrayFor(ta) {\n var ctor;\n for (var idx = 0; !ctor && typedArrayCtors.length > idx; idx++) {\n if (ta instanceof typedArrayCtors[idx]) {\n ctor = typedArrayCtors[idx];\n }\n }\n return ctor;\n}\n\nfunction mergeBuffer(a, b) {\n // TODO: should this be a copy, or the reference itself?\n if (Buffer.isBuffer(b)) {\n b = Buffer.from(b);\n } else {\n var Ctor = findTypedArrayFor(b);\n b = Ctor ?\n new Ctor(b, b.byteOffset, b.byteLength) :\n undefined;\n }\n\n // TODO: QUESTION: create a merged ??\n // for now, a is b\n a = b;\n\n return b;\n}\n\nmodule.exports = partialRight(merge, mergeBuffer);\n","/*!\n * util/utf8.js - Implementation of UTF-8 Encoder/Decoder\n *\n * Copyright (c) 2015 Cisco Systems, Inc. See LICENSE file.\n */\n\"use strict\";\n\nvar utf8 = exports;\n\nutf8.encode = function(input) {\n var output = encodeURIComponent(input || \"\");\n output = output.replace(/%([0-9a-fA-F]{2})/g, function(m, code) {\n code = parseInt(code, 16);\n return String.fromCharCode(code);\n });\n\n return output;\n};\nutf8.decode = function(input) {\n var output = (input || \"\").replace(/[\\u0080-\\u00ff]/g, function(m) {\n var code = (0x100 | m.charCodeAt(0)).toString(16).substring(1);\n return \"%\" + code;\n });\n output = decodeURIComponent(output);\n\n return output;\n};\n","/**\n * Advanced Encryption Standard (AES) implementation.\n *\n * This implementation is based on the public domain library 'jscrypto' which\n * was written by:\n *\n * Emily Stark (estark@stanford.edu)\n * Mike Hamburg (mhamburg@stanford.edu)\n * Dan Boneh (dabo@cs.stanford.edu)\n *\n * Parts of this code are based on the OpenSSL implementation of AES:\n * http://www.openssl.org\n *\n * @author Dave Longley\n *\n * Copyright (c) 2010-2014 Digital Bazaar, Inc.\n */\nvar forge = require('./forge');\nrequire('./cipher');\nrequire('./cipherModes');\nrequire('./util');\n\n/* AES API */\nmodule.exports = forge.aes = forge.aes || {};\n\n/**\n * Deprecated. Instead, use:\n *\n * var cipher = forge.cipher.createCipher('AES-', key);\n * cipher.start({iv: iv});\n *\n * Creates an AES cipher object to encrypt data using the given symmetric key.\n * The output will be stored in the 'output' member of the returned cipher.\n *\n * The key and iv may be given as a string of bytes, an array of bytes,\n * a byte buffer, or an array of 32-bit words.\n *\n * @param key the symmetric key to use.\n * @param iv the initialization vector to use.\n * @param output the buffer to write to, null to create one.\n * @param mode the cipher mode to use (default: 'CBC').\n *\n * @return the cipher.\n */\nforge.aes.startEncrypting = function(key, iv, output, mode) {\n var cipher = _createCipher({\n key: key,\n output: output,\n decrypt: false,\n mode: mode\n });\n cipher.start(iv);\n return cipher;\n};\n\n/**\n * Deprecated. Instead, use:\n *\n * var cipher = forge.cipher.createCipher('AES-', key);\n *\n * Creates an AES cipher object to encrypt data using the given symmetric key.\n *\n * The key may be given as a string of bytes, an array of bytes, a\n * byte buffer, or an array of 32-bit words.\n *\n * @param key the symmetric key to use.\n * @param mode the cipher mode to use (default: 'CBC').\n *\n * @return the cipher.\n */\nforge.aes.createEncryptionCipher = function(key, mode) {\n return _createCipher({\n key: key,\n output: null,\n decrypt: false,\n mode: mode\n });\n};\n\n/**\n * Deprecated. Instead, use:\n *\n * var decipher = forge.cipher.createDecipher('AES-', key);\n * decipher.start({iv: iv});\n *\n * Creates an AES cipher object to decrypt data using the given symmetric key.\n * The output will be stored in the 'output' member of the returned cipher.\n *\n * The key and iv may be given as a string of bytes, an array of bytes,\n * a byte buffer, or an array of 32-bit words.\n *\n * @param key the symmetric key to use.\n * @param iv the initialization vector to use.\n * @param output the buffer to write to, null to create one.\n * @param mode the cipher mode to use (default: 'CBC').\n *\n * @return the cipher.\n */\nforge.aes.startDecrypting = function(key, iv, output, mode) {\n var cipher = _createCipher({\n key: key,\n output: output,\n decrypt: true,\n mode: mode\n });\n cipher.start(iv);\n return cipher;\n};\n\n/**\n * Deprecated. Instead, use:\n *\n * var decipher = forge.cipher.createDecipher('AES-', key);\n *\n * Creates an AES cipher object to decrypt data using the given symmetric key.\n *\n * The key may be given as a string of bytes, an array of bytes, a\n * byte buffer, or an array of 32-bit words.\n *\n * @param key the symmetric key to use.\n * @param mode the cipher mode to use (default: 'CBC').\n *\n * @return the cipher.\n */\nforge.aes.createDecryptionCipher = function(key, mode) {\n return _createCipher({\n key: key,\n output: null,\n decrypt: true,\n mode: mode\n });\n};\n\n/**\n * Creates a new AES cipher algorithm object.\n *\n * @param name the name of the algorithm.\n * @param mode the mode factory function.\n *\n * @return the AES algorithm object.\n */\nforge.aes.Algorithm = function(name, mode) {\n if(!init) {\n initialize();\n }\n var self = this;\n self.name = name;\n self.mode = new mode({\n blockSize: 16,\n cipher: {\n encrypt: function(inBlock, outBlock) {\n return _updateBlock(self._w, inBlock, outBlock, false);\n },\n decrypt: function(inBlock, outBlock) {\n return _updateBlock(self._w, inBlock, outBlock, true);\n }\n }\n });\n self._init = false;\n};\n\n/**\n * Initializes this AES algorithm by expanding its key.\n *\n * @param options the options to use.\n * key the key to use with this algorithm.\n * decrypt true if the algorithm should be initialized for decryption,\n * false for encryption.\n */\nforge.aes.Algorithm.prototype.initialize = function(options) {\n if(this._init) {\n return;\n }\n\n var key = options.key;\n var tmp;\n\n /* Note: The key may be a string of bytes, an array of bytes, a byte\n buffer, or an array of 32-bit integers. If the key is in bytes, then\n it must be 16, 24, or 32 bytes in length. If it is in 32-bit\n integers, it must be 4, 6, or 8 integers long. */\n\n if(typeof key === 'string' &&\n (key.length === 16 || key.length === 24 || key.length === 32)) {\n // convert key string into byte buffer\n key = forge.util.createBuffer(key);\n } else if(forge.util.isArray(key) &&\n (key.length === 16 || key.length === 24 || key.length === 32)) {\n // convert key integer array into byte buffer\n tmp = key;\n key = forge.util.createBuffer();\n for(var i = 0; i < tmp.length; ++i) {\n key.putByte(tmp[i]);\n }\n }\n\n // convert key byte buffer into 32-bit integer array\n if(!forge.util.isArray(key)) {\n tmp = key;\n key = [];\n\n // key lengths of 16, 24, 32 bytes allowed\n var len = tmp.length();\n if(len === 16 || len === 24 || len === 32) {\n len = len >>> 2;\n for(var i = 0; i < len; ++i) {\n key.push(tmp.getInt32());\n }\n }\n }\n\n // key must be an array of 32-bit integers by now\n if(!forge.util.isArray(key) ||\n !(key.length === 4 || key.length === 6 || key.length === 8)) {\n throw new Error('Invalid key parameter.');\n }\n\n // encryption operation is always used for these modes\n var mode = this.mode.name;\n var encryptOp = (['CFB', 'OFB', 'CTR', 'GCM'].indexOf(mode) !== -1);\n\n // do key expansion\n this._w = _expandKey(key, options.decrypt && !encryptOp);\n this._init = true;\n};\n\n/**\n * Expands a key. Typically only used for testing.\n *\n * @param key the symmetric key to expand, as an array of 32-bit words.\n * @param decrypt true to expand for decryption, false for encryption.\n *\n * @return the expanded key.\n */\nforge.aes._expandKey = function(key, decrypt) {\n if(!init) {\n initialize();\n }\n return _expandKey(key, decrypt);\n};\n\n/**\n * Updates a single block. Typically only used for testing.\n *\n * @param w the expanded key to use.\n * @param input an array of block-size 32-bit words.\n * @param output an array of block-size 32-bit words.\n * @param decrypt true to decrypt, false to encrypt.\n */\nforge.aes._updateBlock = _updateBlock;\n\n/** Register AES algorithms **/\n\nregisterAlgorithm('AES-ECB', forge.cipher.modes.ecb);\nregisterAlgorithm('AES-CBC', forge.cipher.modes.cbc);\nregisterAlgorithm('AES-CFB', forge.cipher.modes.cfb);\nregisterAlgorithm('AES-OFB', forge.cipher.modes.ofb);\nregisterAlgorithm('AES-CTR', forge.cipher.modes.ctr);\nregisterAlgorithm('AES-GCM', forge.cipher.modes.gcm);\n\nfunction registerAlgorithm(name, mode) {\n var factory = function() {\n return new forge.aes.Algorithm(name, mode);\n };\n forge.cipher.registerAlgorithm(name, factory);\n}\n\n/** AES implementation **/\n\nvar init = false; // not yet initialized\nvar Nb = 4; // number of words comprising the state (AES = 4)\nvar sbox; // non-linear substitution table used in key expansion\nvar isbox; // inversion of sbox\nvar rcon; // round constant word array\nvar mix; // mix-columns table\nvar imix; // inverse mix-columns table\n\n/**\n * Performs initialization, ie: precomputes tables to optimize for speed.\n *\n * One way to understand how AES works is to imagine that 'addition' and\n * 'multiplication' are interfaces that require certain mathematical\n * properties to hold true (ie: they are associative) but they might have\n * different implementations and produce different kinds of results ...\n * provided that their mathematical properties remain true. AES defines\n * its own methods of addition and multiplication but keeps some important\n * properties the same, ie: associativity and distributivity. The\n * explanation below tries to shed some light on how AES defines addition\n * and multiplication of bytes and 32-bit words in order to perform its\n * encryption and decryption algorithms.\n *\n * The basics:\n *\n * The AES algorithm views bytes as binary representations of polynomials\n * that have either 1 or 0 as the coefficients. It defines the addition\n * or subtraction of two bytes as the XOR operation. It also defines the\n * multiplication of two bytes as a finite field referred to as GF(2^8)\n * (Note: 'GF' means \"Galois Field\" which is a field that contains a finite\n * number of elements so GF(2^8) has 256 elements).\n *\n * This means that any two bytes can be represented as binary polynomials;\n * when they multiplied together and modularly reduced by an irreducible\n * polynomial of the 8th degree, the results are the field GF(2^8). The\n * specific irreducible polynomial that AES uses in hexadecimal is 0x11b.\n * This multiplication is associative with 0x01 as the identity:\n *\n * (b * 0x01 = GF(b, 0x01) = b).\n *\n * The operation GF(b, 0x02) can be performed at the byte level by left\n * shifting b once and then XOR'ing it (to perform the modular reduction)\n * with 0x11b if b is >= 128. Repeated application of the multiplication\n * of 0x02 can be used to implement the multiplication of any two bytes.\n *\n * For instance, multiplying 0x57 and 0x13, denoted as GF(0x57, 0x13), can\n * be performed by factoring 0x13 into 0x01, 0x02, and 0x10. Then these\n * factors can each be multiplied by 0x57 and then added together. To do\n * the multiplication, values for 0x57 multiplied by each of these 3 factors\n * can be precomputed and stored in a table. To add them, the values from\n * the table are XOR'd together.\n *\n * AES also defines addition and multiplication of words, that is 4-byte\n * numbers represented as polynomials of 3 degrees where the coefficients\n * are the values of the bytes.\n *\n * The word [a0, a1, a2, a3] is a polynomial a3x^3 + a2x^2 + a1x + a0.\n *\n * Addition is performed by XOR'ing like powers of x. Multiplication\n * is performed in two steps, the first is an algebriac expansion as\n * you would do normally (where addition is XOR). But the result is\n * a polynomial larger than 3 degrees and thus it cannot fit in a word. So\n * next the result is modularly reduced by an AES-specific polynomial of\n * degree 4 which will always produce a polynomial of less than 4 degrees\n * such that it will fit in a word. In AES, this polynomial is x^4 + 1.\n *\n * The modular product of two polynomials 'a' and 'b' is thus:\n *\n * d(x) = d3x^3 + d2x^2 + d1x + d0\n * with\n * d0 = GF(a0, b0) ^ GF(a3, b1) ^ GF(a2, b2) ^ GF(a1, b3)\n * d1 = GF(a1, b0) ^ GF(a0, b1) ^ GF(a3, b2) ^ GF(a2, b3)\n * d2 = GF(a2, b0) ^ GF(a1, b1) ^ GF(a0, b2) ^ GF(a3, b3)\n * d3 = GF(a3, b0) ^ GF(a2, b1) ^ GF(a1, b2) ^ GF(a0, b3)\n *\n * As a matrix:\n *\n * [d0] = [a0 a3 a2 a1][b0]\n * [d1] [a1 a0 a3 a2][b1]\n * [d2] [a2 a1 a0 a3][b2]\n * [d3] [a3 a2 a1 a0][b3]\n *\n * Special polynomials defined by AES (0x02 == {02}):\n * a(x) = {03}x^3 + {01}x^2 + {01}x + {02}\n * a^-1(x) = {0b}x^3 + {0d}x^2 + {09}x + {0e}.\n *\n * These polynomials are used in the MixColumns() and InverseMixColumns()\n * operations, respectively, to cause each element in the state to affect\n * the output (referred to as diffusing).\n *\n * RotWord() uses: a0 = a1 = a2 = {00} and a3 = {01}, which is the\n * polynomial x3.\n *\n * The ShiftRows() method modifies the last 3 rows in the state (where\n * the state is 4 words with 4 bytes per word) by shifting bytes cyclically.\n * The 1st byte in the second row is moved to the end of the row. The 1st\n * and 2nd bytes in the third row are moved to the end of the row. The 1st,\n * 2nd, and 3rd bytes are moved in the fourth row.\n *\n * More details on how AES arithmetic works:\n *\n * In the polynomial representation of binary numbers, XOR performs addition\n * and subtraction and multiplication in GF(2^8) denoted as GF(a, b)\n * corresponds with the multiplication of polynomials modulo an irreducible\n * polynomial of degree 8. In other words, for AES, GF(a, b) will multiply\n * polynomial 'a' with polynomial 'b' and then do a modular reduction by\n * an AES-specific irreducible polynomial of degree 8.\n *\n * A polynomial is irreducible if its only divisors are one and itself. For\n * the AES algorithm, this irreducible polynomial is:\n *\n * m(x) = x^8 + x^4 + x^3 + x + 1,\n *\n * or {01}{1b} in hexadecimal notation, where each coefficient is a bit:\n * 100011011 = 283 = 0x11b.\n *\n * For example, GF(0x57, 0x83) = 0xc1 because\n *\n * 0x57 = 87 = 01010111 = x^6 + x^4 + x^2 + x + 1\n * 0x85 = 131 = 10000101 = x^7 + x + 1\n *\n * (x^6 + x^4 + x^2 + x + 1) * (x^7 + x + 1)\n * = x^13 + x^11 + x^9 + x^8 + x^7 +\n * x^7 + x^5 + x^3 + x^2 + x +\n * x^6 + x^4 + x^2 + x + 1\n * = x^13 + x^11 + x^9 + x^8 + x^6 + x^5 + x^4 + x^3 + 1 = y\n * y modulo (x^8 + x^4 + x^3 + x + 1)\n * = x^7 + x^6 + 1.\n *\n * The modular reduction by m(x) guarantees the result will be a binary\n * polynomial of less than degree 8, so that it can fit in a byte.\n *\n * The operation to multiply a binary polynomial b with x (the polynomial\n * x in binary representation is 00000010) is:\n *\n * b_7x^8 + b_6x^7 + b_5x^6 + b_4x^5 + b_3x^4 + b_2x^3 + b_1x^2 + b_0x^1\n *\n * To get GF(b, x) we must reduce that by m(x). If b_7 is 0 (that is the\n * most significant bit is 0 in b) then the result is already reduced. If\n * it is 1, then we can reduce it by subtracting m(x) via an XOR.\n *\n * It follows that multiplication by x (00000010 or 0x02) can be implemented\n * by performing a left shift followed by a conditional bitwise XOR with\n * 0x1b. This operation on bytes is denoted by xtime(). Multiplication by\n * higher powers of x can be implemented by repeated application of xtime().\n *\n * By adding intermediate results, multiplication by any constant can be\n * implemented. For instance:\n *\n * GF(0x57, 0x13) = 0xfe because:\n *\n * xtime(b) = (b & 128) ? (b << 1 ^ 0x11b) : (b << 1)\n *\n * Note: We XOR with 0x11b instead of 0x1b because in javascript our\n * datatype for b can be larger than 1 byte, so a left shift will not\n * automatically eliminate bits that overflow a byte ... by XOR'ing the\n * overflow bit with 1 (the extra one from 0x11b) we zero it out.\n *\n * GF(0x57, 0x02) = xtime(0x57) = 0xae\n * GF(0x57, 0x04) = xtime(0xae) = 0x47\n * GF(0x57, 0x08) = xtime(0x47) = 0x8e\n * GF(0x57, 0x10) = xtime(0x8e) = 0x07\n *\n * GF(0x57, 0x13) = GF(0x57, (0x01 ^ 0x02 ^ 0x10))\n *\n * And by the distributive property (since XOR is addition and GF() is\n * multiplication):\n *\n * = GF(0x57, 0x01) ^ GF(0x57, 0x02) ^ GF(0x57, 0x10)\n * = 0x57 ^ 0xae ^ 0x07\n * = 0xfe.\n */\nfunction initialize() {\n init = true;\n\n /* Populate the Rcon table. These are the values given by\n [x^(i-1),{00},{00},{00}] where x^(i-1) are powers of x (and x = 0x02)\n in the field of GF(2^8), where i starts at 1.\n\n rcon[0] = [0x00, 0x00, 0x00, 0x00]\n rcon[1] = [0x01, 0x00, 0x00, 0x00] 2^(1-1) = 2^0 = 1\n rcon[2] = [0x02, 0x00, 0x00, 0x00] 2^(2-1) = 2^1 = 2\n ...\n rcon[9] = [0x1B, 0x00, 0x00, 0x00] 2^(9-1) = 2^8 = 0x1B\n rcon[10] = [0x36, 0x00, 0x00, 0x00] 2^(10-1) = 2^9 = 0x36\n\n We only store the first byte because it is the only one used.\n */\n rcon = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1B, 0x36];\n\n // compute xtime table which maps i onto GF(i, 0x02)\n var xtime = new Array(256);\n for(var i = 0; i < 128; ++i) {\n xtime[i] = i << 1;\n xtime[i + 128] = (i + 128) << 1 ^ 0x11B;\n }\n\n // compute all other tables\n sbox = new Array(256);\n isbox = new Array(256);\n mix = new Array(4);\n imix = new Array(4);\n for(var i = 0; i < 4; ++i) {\n mix[i] = new Array(256);\n imix[i] = new Array(256);\n }\n var e = 0, ei = 0, e2, e4, e8, sx, sx2, me, ime;\n for(var i = 0; i < 256; ++i) {\n /* We need to generate the SubBytes() sbox and isbox tables so that\n we can perform byte substitutions. This requires us to traverse\n all of the elements in GF, find their multiplicative inverses,\n and apply to each the following affine transformation:\n\n bi' = bi ^ b(i + 4) mod 8 ^ b(i + 5) mod 8 ^ b(i + 6) mod 8 ^\n b(i + 7) mod 8 ^ ci\n for 0 <= i < 8, where bi is the ith bit of the byte, and ci is the\n ith bit of a byte c with the value {63} or {01100011}.\n\n It is possible to traverse every possible value in a Galois field\n using what is referred to as a 'generator'. There are many\n generators (128 out of 256): 3,5,6,9,11,82 to name a few. To fully\n traverse GF we iterate 255 times, multiplying by our generator\n each time.\n\n On each iteration we can determine the multiplicative inverse for\n the current element.\n\n Suppose there is an element in GF 'e'. For a given generator 'g',\n e = g^x. The multiplicative inverse of e is g^(255 - x). It turns\n out that if use the inverse of a generator as another generator\n it will produce all of the corresponding multiplicative inverses\n at the same time. For this reason, we choose 5 as our inverse\n generator because it only requires 2 multiplies and 1 add and its\n inverse, 82, requires relatively few operations as well.\n\n In order to apply the affine transformation, the multiplicative\n inverse 'ei' of 'e' can be repeatedly XOR'd (4 times) with a\n bit-cycling of 'ei'. To do this 'ei' is first stored in 's' and\n 'x'. Then 's' is left shifted and the high bit of 's' is made the\n low bit. The resulting value is stored in 's'. Then 'x' is XOR'd\n with 's' and stored in 'x'. On each subsequent iteration the same\n operation is performed. When 4 iterations are complete, 'x' is\n XOR'd with 'c' (0x63) and the transformed value is stored in 'x'.\n For example:\n\n s = 01000001\n x = 01000001\n\n iteration 1: s = 10000010, x ^= s\n iteration 2: s = 00000101, x ^= s\n iteration 3: s = 00001010, x ^= s\n iteration 4: s = 00010100, x ^= s\n x ^= 0x63\n\n This can be done with a loop where s = (s << 1) | (s >> 7). However,\n it can also be done by using a single 16-bit (in this case 32-bit)\n number 'sx'. Since XOR is an associative operation, we can set 'sx'\n to 'ei' and then XOR it with 'sx' left-shifted 1,2,3, and 4 times.\n The most significant bits will flow into the high 8 bit positions\n and be correctly XOR'd with one another. All that remains will be\n to cycle the high 8 bits by XOR'ing them all with the lower 8 bits\n afterwards.\n\n At the same time we're populating sbox and isbox we can precompute\n the multiplication we'll need to do to do MixColumns() later.\n */\n\n // apply affine transformation\n sx = ei ^ (ei << 1) ^ (ei << 2) ^ (ei << 3) ^ (ei << 4);\n sx = (sx >> 8) ^ (sx & 255) ^ 0x63;\n\n // update tables\n sbox[e] = sx;\n isbox[sx] = e;\n\n /* Mixing columns is done using matrix multiplication. The columns\n that are to be mixed are each a single word in the current state.\n The state has Nb columns (4 columns). Therefore each column is a\n 4 byte word. So to mix the columns in a single column 'c' where\n its rows are r0, r1, r2, and r3, we use the following matrix\n multiplication:\n\n [2 3 1 1]*[r0,c]=[r'0,c]\n [1 2 3 1] [r1,c] [r'1,c]\n [1 1 2 3] [r2,c] [r'2,c]\n [3 1 1 2] [r3,c] [r'3,c]\n\n r0, r1, r2, and r3 are each 1 byte of one of the words in the\n state (a column). To do matrix multiplication for each mixed\n column c' we multiply the corresponding row from the left matrix\n with the corresponding column from the right matrix. In total, we\n get 4 equations:\n\n r0,c' = 2*r0,c + 3*r1,c + 1*r2,c + 1*r3,c\n r1,c' = 1*r0,c + 2*r1,c + 3*r2,c + 1*r3,c\n r2,c' = 1*r0,c + 1*r1,c + 2*r2,c + 3*r3,c\n r3,c' = 3*r0,c + 1*r1,c + 1*r2,c + 2*r3,c\n\n As usual, the multiplication is as previously defined and the\n addition is XOR. In order to optimize mixing columns we can store\n the multiplication results in tables. If you think of the whole\n column as a word (it might help to visualize by mentally rotating\n the equations above by counterclockwise 90 degrees) then you can\n see that it would be useful to map the multiplications performed on\n each byte (r0, r1, r2, r3) onto a word as well. For instance, we\n could map 2*r0,1*r0,1*r0,3*r0 onto a word by storing 2*r0 in the\n highest 8 bits and 3*r0 in the lowest 8 bits (with the other two\n respectively in the middle). This means that a table can be\n constructed that uses r0 as an index to the word. We can do the\n same with r1, r2, and r3, creating a total of 4 tables.\n\n To construct a full c', we can just look up each byte of c in\n their respective tables and XOR the results together.\n\n Also, to build each table we only have to calculate the word\n for 2,1,1,3 for every byte ... which we can do on each iteration\n of this loop since we will iterate over every byte. After we have\n calculated 2,1,1,3 we can get the results for the other tables\n by cycling the byte at the end to the beginning. For instance\n we can take the result of table 2,1,1,3 and produce table 3,2,1,1\n by moving the right most byte to the left most position just like\n how you can imagine the 3 moved out of 2,1,1,3 and to the front\n to produce 3,2,1,1.\n\n There is another optimization in that the same multiples of\n the current element we need in order to advance our generator\n to the next iteration can be reused in performing the 2,1,1,3\n calculation. We also calculate the inverse mix column tables,\n with e,9,d,b being the inverse of 2,1,1,3.\n\n When we're done, and we need to actually mix columns, the first\n byte of each state word should be put through mix[0] (2,1,1,3),\n the second through mix[1] (3,2,1,1) and so forth. Then they should\n be XOR'd together to produce the fully mixed column.\n */\n\n // calculate mix and imix table values\n sx2 = xtime[sx];\n e2 = xtime[e];\n e4 = xtime[e2];\n e8 = xtime[e4];\n me =\n (sx2 << 24) ^ // 2\n (sx << 16) ^ // 1\n (sx << 8) ^ // 1\n (sx ^ sx2); // 3\n ime =\n (e2 ^ e4 ^ e8) << 24 ^ // E (14)\n (e ^ e8) << 16 ^ // 9\n (e ^ e4 ^ e8) << 8 ^ // D (13)\n (e ^ e2 ^ e8); // B (11)\n // produce each of the mix tables by rotating the 2,1,1,3 value\n for(var n = 0; n < 4; ++n) {\n mix[n][e] = me;\n imix[n][sx] = ime;\n // cycle the right most byte to the left most position\n // ie: 2,1,1,3 becomes 3,2,1,1\n me = me << 24 | me >>> 8;\n ime = ime << 24 | ime >>> 8;\n }\n\n // get next element and inverse\n if(e === 0) {\n // 1 is the inverse of 1\n e = ei = 1;\n } else {\n // e = 2e + 2*2*2*(10e)) = multiply e by 82 (chosen generator)\n // ei = ei + 2*2*ei = multiply ei by 5 (inverse generator)\n e = e2 ^ xtime[xtime[xtime[e2 ^ e8]]];\n ei ^= xtime[xtime[ei]];\n }\n }\n}\n\n/**\n * Generates a key schedule using the AES key expansion algorithm.\n *\n * The AES algorithm takes the Cipher Key, K, and performs a Key Expansion\n * routine to generate a key schedule. The Key Expansion generates a total\n * of Nb*(Nr + 1) words: the algorithm requires an initial set of Nb words,\n * and each of the Nr rounds requires Nb words of key data. The resulting\n * key schedule consists of a linear array of 4-byte words, denoted [wi ],\n * with i in the range 0 <= i < Nb(Nr + 1).\n *\n * KeyExpansion(byte key[4*Nk], word w[Nb*(Nr+1)], Nk)\n * AES-128 (Nb=4, Nk=4, Nr=10)\n * AES-192 (Nb=4, Nk=6, Nr=12)\n * AES-256 (Nb=4, Nk=8, Nr=14)\n * Note: Nr=Nk+6.\n *\n * Nb is the number of columns (32-bit words) comprising the State (or\n * number of bytes in a block). For AES, Nb=4.\n *\n * @param key the key to schedule (as an array of 32-bit words).\n * @param decrypt true to modify the key schedule to decrypt, false not to.\n *\n * @return the generated key schedule.\n */\nfunction _expandKey(key, decrypt) {\n // copy the key's words to initialize the key schedule\n var w = key.slice(0);\n\n /* RotWord() will rotate a word, moving the first byte to the last\n byte's position (shifting the other bytes left).\n\n We will be getting the value of Rcon at i / Nk. 'i' will iterate\n from Nk to (Nb * Nr+1). Nk = 4 (4 byte key), Nb = 4 (4 words in\n a block), Nr = Nk + 6 (10). Therefore 'i' will iterate from\n 4 to 44 (exclusive). Each time we iterate 4 times, i / Nk will\n increase by 1. We use a counter iNk to keep track of this.\n */\n\n // go through the rounds expanding the key\n var temp, iNk = 1;\n var Nk = w.length;\n var Nr1 = Nk + 6 + 1;\n var end = Nb * Nr1;\n for(var i = Nk; i < end; ++i) {\n temp = w[i - 1];\n if(i % Nk === 0) {\n // temp = SubWord(RotWord(temp)) ^ Rcon[i / Nk]\n temp =\n sbox[temp >>> 16 & 255] << 24 ^\n sbox[temp >>> 8 & 255] << 16 ^\n sbox[temp & 255] << 8 ^\n sbox[temp >>> 24] ^ (rcon[iNk] << 24);\n iNk++;\n } else if(Nk > 6 && (i % Nk === 4)) {\n // temp = SubWord(temp)\n temp =\n sbox[temp >>> 24] << 24 ^\n sbox[temp >>> 16 & 255] << 16 ^\n sbox[temp >>> 8 & 255] << 8 ^\n sbox[temp & 255];\n }\n w[i] = w[i - Nk] ^ temp;\n }\n\n /* When we are updating a cipher block we always use the code path for\n encryption whether we are decrypting or not (to shorten code and\n simplify the generation of look up tables). However, because there\n are differences in the decryption algorithm, other than just swapping\n in different look up tables, we must transform our key schedule to\n account for these changes:\n\n 1. The decryption algorithm gets its key rounds in reverse order.\n 2. The decryption algorithm adds the round key before mixing columns\n instead of afterwards.\n\n We don't need to modify our key schedule to handle the first case,\n we can just traverse the key schedule in reverse order when decrypting.\n\n The second case requires a little work.\n\n The tables we built for performing rounds will take an input and then\n perform SubBytes() and MixColumns() or, for the decrypt version,\n InvSubBytes() and InvMixColumns(). But the decrypt algorithm requires\n us to AddRoundKey() before InvMixColumns(). This means we'll need to\n apply some transformations to the round key to inverse-mix its columns\n so they'll be correct for moving AddRoundKey() to after the state has\n had its columns inverse-mixed.\n\n To inverse-mix the columns of the state when we're decrypting we use a\n lookup table that will apply InvSubBytes() and InvMixColumns() at the\n same time. However, the round key's bytes are not inverse-substituted\n in the decryption algorithm. To get around this problem, we can first\n substitute the bytes in the round key so that when we apply the\n transformation via the InvSubBytes()+InvMixColumns() table, it will\n undo our substitution leaving us with the original value that we\n want -- and then inverse-mix that value.\n\n This change will correctly alter our key schedule so that we can XOR\n each round key with our already transformed decryption state. This\n allows us to use the same code path as the encryption algorithm.\n\n We make one more change to the decryption key. Since the decryption\n algorithm runs in reverse from the encryption algorithm, we reverse\n the order of the round keys to avoid having to iterate over the key\n schedule backwards when running the encryption algorithm later in\n decryption mode. In addition to reversing the order of the round keys,\n we also swap each round key's 2nd and 4th rows. See the comments\n section where rounds are performed for more details about why this is\n done. These changes are done inline with the other substitution\n described above.\n */\n if(decrypt) {\n var tmp;\n var m0 = imix[0];\n var m1 = imix[1];\n var m2 = imix[2];\n var m3 = imix[3];\n var wnew = w.slice(0);\n end = w.length;\n for(var i = 0, wi = end - Nb; i < end; i += Nb, wi -= Nb) {\n // do not sub the first or last round key (round keys are Nb\n // words) as no column mixing is performed before they are added,\n // but do change the key order\n if(i === 0 || i === (end - Nb)) {\n wnew[i] = w[wi];\n wnew[i + 1] = w[wi + 3];\n wnew[i + 2] = w[wi + 2];\n wnew[i + 3] = w[wi + 1];\n } else {\n // substitute each round key byte because the inverse-mix\n // table will inverse-substitute it (effectively cancel the\n // substitution because round key bytes aren't sub'd in\n // decryption mode) and swap indexes 3 and 1\n for(var n = 0; n < Nb; ++n) {\n tmp = w[wi + n];\n wnew[i + (3&-n)] =\n m0[sbox[tmp >>> 24]] ^\n m1[sbox[tmp >>> 16 & 255]] ^\n m2[sbox[tmp >>> 8 & 255]] ^\n m3[sbox[tmp & 255]];\n }\n }\n }\n w = wnew;\n }\n\n return w;\n}\n\n/**\n * Updates a single block (16 bytes) using AES. The update will either\n * encrypt or decrypt the block.\n *\n * @param w the key schedule.\n * @param input the input block (an array of 32-bit words).\n * @param output the updated output block.\n * @param decrypt true to decrypt the block, false to encrypt it.\n */\nfunction _updateBlock(w, input, output, decrypt) {\n /*\n Cipher(byte in[4*Nb], byte out[4*Nb], word w[Nb*(Nr+1)])\n begin\n byte state[4,Nb]\n state = in\n AddRoundKey(state, w[0, Nb-1])\n for round = 1 step 1 to Nr-1\n SubBytes(state)\n ShiftRows(state)\n MixColumns(state)\n AddRoundKey(state, w[round*Nb, (round+1)*Nb-1])\n end for\n SubBytes(state)\n ShiftRows(state)\n AddRoundKey(state, w[Nr*Nb, (Nr+1)*Nb-1])\n out = state\n end\n\n InvCipher(byte in[4*Nb], byte out[4*Nb], word w[Nb*(Nr+1)])\n begin\n byte state[4,Nb]\n state = in\n AddRoundKey(state, w[Nr*Nb, (Nr+1)*Nb-1])\n for round = Nr-1 step -1 downto 1\n InvShiftRows(state)\n InvSubBytes(state)\n AddRoundKey(state, w[round*Nb, (round+1)*Nb-1])\n InvMixColumns(state)\n end for\n InvShiftRows(state)\n InvSubBytes(state)\n AddRoundKey(state, w[0, Nb-1])\n out = state\n end\n */\n\n // Encrypt: AddRoundKey(state, w[0, Nb-1])\n // Decrypt: AddRoundKey(state, w[Nr*Nb, (Nr+1)*Nb-1])\n var Nr = w.length / 4 - 1;\n var m0, m1, m2, m3, sub;\n if(decrypt) {\n m0 = imix[0];\n m1 = imix[1];\n m2 = imix[2];\n m3 = imix[3];\n sub = isbox;\n } else {\n m0 = mix[0];\n m1 = mix[1];\n m2 = mix[2];\n m3 = mix[3];\n sub = sbox;\n }\n var a, b, c, d, a2, b2, c2;\n a = input[0] ^ w[0];\n b = input[decrypt ? 3 : 1] ^ w[1];\n c = input[2] ^ w[2];\n d = input[decrypt ? 1 : 3] ^ w[3];\n var i = 3;\n\n /* In order to share code we follow the encryption algorithm when both\n encrypting and decrypting. To account for the changes required in the\n decryption algorithm, we use different lookup tables when decrypting\n and use a modified key schedule to account for the difference in the\n order of transformations applied when performing rounds. We also get\n key rounds in reverse order (relative to encryption). */\n for(var round = 1; round < Nr; ++round) {\n /* As described above, we'll be using table lookups to perform the\n column mixing. Each column is stored as a word in the state (the\n array 'input' has one column as a word at each index). In order to\n mix a column, we perform these transformations on each row in c,\n which is 1 byte in each word. The new column for c0 is c'0:\n\n m0 m1 m2 m3\n r0,c'0 = 2*r0,c0 + 3*r1,c0 + 1*r2,c0 + 1*r3,c0\n r1,c'0 = 1*r0,c0 + 2*r1,c0 + 3*r2,c0 + 1*r3,c0\n r2,c'0 = 1*r0,c0 + 1*r1,c0 + 2*r2,c0 + 3*r3,c0\n r3,c'0 = 3*r0,c0 + 1*r1,c0 + 1*r2,c0 + 2*r3,c0\n\n So using mix tables where c0 is a word with r0 being its upper\n 8 bits and r3 being its lower 8 bits:\n\n m0[c0 >> 24] will yield this word: [2*r0,1*r0,1*r0,3*r0]\n ...\n m3[c0 & 255] will yield this word: [1*r3,1*r3,3*r3,2*r3]\n\n Therefore to mix the columns in each word in the state we\n do the following (& 255 omitted for brevity):\n c'0,r0 = m0[c0 >> 24] ^ m1[c1 >> 16] ^ m2[c2 >> 8] ^ m3[c3]\n c'0,r1 = m0[c0 >> 24] ^ m1[c1 >> 16] ^ m2[c2 >> 8] ^ m3[c3]\n c'0,r2 = m0[c0 >> 24] ^ m1[c1 >> 16] ^ m2[c2 >> 8] ^ m3[c3]\n c'0,r3 = m0[c0 >> 24] ^ m1[c1 >> 16] ^ m2[c2 >> 8] ^ m3[c3]\n\n However, before mixing, the algorithm requires us to perform\n ShiftRows(). The ShiftRows() transformation cyclically shifts the\n last 3 rows of the state over different offsets. The first row\n (r = 0) is not shifted.\n\n s'_r,c = s_r,(c + shift(r, Nb) mod Nb\n for 0 < r < 4 and 0 <= c < Nb and\n shift(1, 4) = 1\n shift(2, 4) = 2\n shift(3, 4) = 3.\n\n This causes the first byte in r = 1 to be moved to the end of\n the row, the first 2 bytes in r = 2 to be moved to the end of\n the row, the first 3 bytes in r = 3 to be moved to the end of\n the row:\n\n r1: [c0 c1 c2 c3] => [c1 c2 c3 c0]\n r2: [c0 c1 c2 c3] [c2 c3 c0 c1]\n r3: [c0 c1 c2 c3] [c3 c0 c1 c2]\n\n We can make these substitutions inline with our column mixing to\n generate an updated set of equations to produce each word in the\n state (note the columns have changed positions):\n\n c0 c1 c2 c3 => c0 c1 c2 c3\n c0 c1 c2 c3 c1 c2 c3 c0 (cycled 1 byte)\n c0 c1 c2 c3 c2 c3 c0 c1 (cycled 2 bytes)\n c0 c1 c2 c3 c3 c0 c1 c2 (cycled 3 bytes)\n\n Therefore:\n\n c'0 = 2*r0,c0 + 3*r1,c1 + 1*r2,c2 + 1*r3,c3\n c'0 = 1*r0,c0 + 2*r1,c1 + 3*r2,c2 + 1*r3,c3\n c'0 = 1*r0,c0 + 1*r1,c1 + 2*r2,c2 + 3*r3,c3\n c'0 = 3*r0,c0 + 1*r1,c1 + 1*r2,c2 + 2*r3,c3\n\n c'1 = 2*r0,c1 + 3*r1,c2 + 1*r2,c3 + 1*r3,c0\n c'1 = 1*r0,c1 + 2*r1,c2 + 3*r2,c3 + 1*r3,c0\n c'1 = 1*r0,c1 + 1*r1,c2 + 2*r2,c3 + 3*r3,c0\n c'1 = 3*r0,c1 + 1*r1,c2 + 1*r2,c3 + 2*r3,c0\n\n ... and so forth for c'2 and c'3. The important distinction is\n that the columns are cycling, with c0 being used with the m0\n map when calculating c0, but c1 being used with the m0 map when\n calculating c1 ... and so forth.\n\n When performing the inverse we transform the mirror image and\n skip the bottom row, instead of the top one, and move upwards:\n\n c3 c2 c1 c0 => c0 c3 c2 c1 (cycled 3 bytes) *same as encryption\n c3 c2 c1 c0 c1 c0 c3 c2 (cycled 2 bytes)\n c3 c2 c1 c0 c2 c1 c0 c3 (cycled 1 byte) *same as encryption\n c3 c2 c1 c0 c3 c2 c1 c0\n\n If you compare the resulting matrices for ShiftRows()+MixColumns()\n and for InvShiftRows()+InvMixColumns() the 2nd and 4th columns are\n different (in encrypt mode vs. decrypt mode). So in order to use\n the same code to handle both encryption and decryption, we will\n need to do some mapping.\n\n If in encryption mode we let a=c0, b=c1, c=c2, d=c3, and r be\n a row number in the state, then the resulting matrix in encryption\n mode for applying the above transformations would be:\n\n r1: a b c d\n r2: b c d a\n r3: c d a b\n r4: d a b c\n\n If we did the same in decryption mode we would get:\n\n r1: a d c b\n r2: b a d c\n r3: c b a d\n r4: d c b a\n\n If instead we swap d and b (set b=c3 and d=c1), then we get:\n\n r1: a b c d\n r2: d a b c\n r3: c d a b\n r4: b c d a\n\n Now the 1st and 3rd rows are the same as the encryption matrix. All\n we need to do then to make the mapping exactly the same is to swap\n the 2nd and 4th rows when in decryption mode. To do this without\n having to do it on each iteration, we swapped the 2nd and 4th rows\n in the decryption key schedule. We also have to do the swap above\n when we first pull in the input and when we set the final output. */\n a2 =\n m0[a >>> 24] ^\n m1[b >>> 16 & 255] ^\n m2[c >>> 8 & 255] ^\n m3[d & 255] ^ w[++i];\n b2 =\n m0[b >>> 24] ^\n m1[c >>> 16 & 255] ^\n m2[d >>> 8 & 255] ^\n m3[a & 255] ^ w[++i];\n c2 =\n m0[c >>> 24] ^\n m1[d >>> 16 & 255] ^\n m2[a >>> 8 & 255] ^\n m3[b & 255] ^ w[++i];\n d =\n m0[d >>> 24] ^\n m1[a >>> 16 & 255] ^\n m2[b >>> 8 & 255] ^\n m3[c & 255] ^ w[++i];\n a = a2;\n b = b2;\n c = c2;\n }\n\n /*\n Encrypt:\n SubBytes(state)\n ShiftRows(state)\n AddRoundKey(state, w[Nr*Nb, (Nr+1)*Nb-1])\n\n Decrypt:\n InvShiftRows(state)\n InvSubBytes(state)\n AddRoundKey(state, w[0, Nb-1])\n */\n // Note: rows are shifted inline\n output[0] =\n (sub[a >>> 24] << 24) ^\n (sub[b >>> 16 & 255] << 16) ^\n (sub[c >>> 8 & 255] << 8) ^\n (sub[d & 255]) ^ w[++i];\n output[decrypt ? 3 : 1] =\n (sub[b >>> 24] << 24) ^\n (sub[c >>> 16 & 255] << 16) ^\n (sub[d >>> 8 & 255] << 8) ^\n (sub[a & 255]) ^ w[++i];\n output[2] =\n (sub[c >>> 24] << 24) ^\n (sub[d >>> 16 & 255] << 16) ^\n (sub[a >>> 8 & 255] << 8) ^\n (sub[b & 255]) ^ w[++i];\n output[decrypt ? 1 : 3] =\n (sub[d >>> 24] << 24) ^\n (sub[a >>> 16 & 255] << 16) ^\n (sub[b >>> 8 & 255] << 8) ^\n (sub[c & 255]) ^ w[++i];\n}\n\n/**\n * Deprecated. Instead, use:\n *\n * forge.cipher.createCipher('AES-', key);\n * forge.cipher.createDecipher('AES-', key);\n *\n * Creates a deprecated AES cipher object. This object's mode will default to\n * CBC (cipher-block-chaining).\n *\n * The key and iv may be given as a string of bytes, an array of bytes, a\n * byte buffer, or an array of 32-bit words.\n *\n * @param options the options to use.\n * key the symmetric key to use.\n * output the buffer to write to.\n * decrypt true for decryption, false for encryption.\n * mode the cipher mode to use (default: 'CBC').\n *\n * @return the cipher.\n */\nfunction _createCipher(options) {\n options = options || {};\n var mode = (options.mode || 'CBC').toUpperCase();\n var algorithm = 'AES-' + mode;\n\n var cipher;\n if(options.decrypt) {\n cipher = forge.cipher.createDecipher(algorithm, options.key);\n } else {\n cipher = forge.cipher.createCipher(algorithm, options.key);\n }\n\n // backwards compatible start API\n var start = cipher.start;\n cipher.start = function(iv, options) {\n // backwards compatibility: support second arg as output buffer\n var output = null;\n if(options instanceof forge.util.ByteBuffer) {\n output = options;\n options = {};\n }\n options = options || {};\n options.output = output;\n options.iv = iv;\n start.call(cipher, options);\n };\n\n return cipher;\n}\n","/**\n * Javascript implementation of Abstract Syntax Notation Number One.\n *\n * @author Dave Longley\n *\n * Copyright (c) 2010-2015 Digital Bazaar, Inc.\n *\n * An API for storing data using the Abstract Syntax Notation Number One\n * format using DER (Distinguished Encoding Rules) encoding. This encoding is\n * commonly used to store data for PKI, i.e. X.509 Certificates, and this\n * implementation exists for that purpose.\n *\n * Abstract Syntax Notation Number One (ASN.1) is used to define the abstract\n * syntax of information without restricting the way the information is encoded\n * for transmission. It provides a standard that allows for open systems\n * communication. ASN.1 defines the syntax of information data and a number of\n * simple data types as well as a notation for describing them and specifying\n * values for them.\n *\n * The RSA algorithm creates public and private keys that are often stored in\n * X.509 or PKCS#X formats -- which use ASN.1 (encoded in DER format). This\n * class provides the most basic functionality required to store and load DSA\n * keys that are encoded according to ASN.1.\n *\n * The most common binary encodings for ASN.1 are BER (Basic Encoding Rules)\n * and DER (Distinguished Encoding Rules). DER is just a subset of BER that\n * has stricter requirements for how data must be encoded.\n *\n * Each ASN.1 structure has a tag (a byte identifying the ASN.1 structure type)\n * and a byte array for the value of this ASN1 structure which may be data or a\n * list of ASN.1 structures.\n *\n * Each ASN.1 structure using BER is (Tag-Length-Value):\n *\n * | byte 0 | bytes X | bytes Y |\n * |--------|---------|----------\n * | tag | length | value |\n *\n * ASN.1 allows for tags to be of \"High-tag-number form\" which allows a tag to\n * be two or more octets, but that is not supported by this class. A tag is\n * only 1 byte. Bits 1-5 give the tag number (ie the data type within a\n * particular 'class'), 6 indicates whether or not the ASN.1 value is\n * constructed from other ASN.1 values, and bits 7 and 8 give the 'class'. If\n * bits 7 and 8 are both zero, the class is UNIVERSAL. If only bit 7 is set,\n * then the class is APPLICATION. If only bit 8 is set, then the class is\n * CONTEXT_SPECIFIC. If both bits 7 and 8 are set, then the class is PRIVATE.\n * The tag numbers for the data types for the class UNIVERSAL are listed below:\n *\n * UNIVERSAL 0 Reserved for use by the encoding rules\n * UNIVERSAL 1 Boolean type\n * UNIVERSAL 2 Integer type\n * UNIVERSAL 3 Bitstring type\n * UNIVERSAL 4 Octetstring type\n * UNIVERSAL 5 Null type\n * UNIVERSAL 6 Object identifier type\n * UNIVERSAL 7 Object descriptor type\n * UNIVERSAL 8 External type and Instance-of type\n * UNIVERSAL 9 Real type\n * UNIVERSAL 10 Enumerated type\n * UNIVERSAL 11 Embedded-pdv type\n * UNIVERSAL 12 UTF8String type\n * UNIVERSAL 13 Relative object identifier type\n * UNIVERSAL 14-15 Reserved for future editions\n * UNIVERSAL 16 Sequence and Sequence-of types\n * UNIVERSAL 17 Set and Set-of types\n * UNIVERSAL 18-22, 25-30 Character string types\n * UNIVERSAL 23-24 Time types\n *\n * The length of an ASN.1 structure is specified after the tag identifier.\n * There is a definite form and an indefinite form. The indefinite form may\n * be used if the encoding is constructed and not all immediately available.\n * The indefinite form is encoded using a length byte with only the 8th bit\n * set. The end of the constructed object is marked using end-of-contents\n * octets (two zero bytes).\n *\n * The definite form looks like this:\n *\n * The length may take up 1 or more bytes, it depends on the length of the\n * value of the ASN.1 structure. DER encoding requires that if the ASN.1\n * structure has a value that has a length greater than 127, more than 1 byte\n * will be used to store its length, otherwise just one byte will be used.\n * This is strict.\n *\n * In the case that the length of the ASN.1 value is less than 127, 1 octet\n * (byte) is used to store the \"short form\" length. The 8th bit has a value of\n * 0 indicating the length is \"short form\" and not \"long form\" and bits 7-1\n * give the length of the data. (The 8th bit is the left-most, most significant\n * bit: also known as big endian or network format).\n *\n * In the case that the length of the ASN.1 value is greater than 127, 2 to\n * 127 octets (bytes) are used to store the \"long form\" length. The first\n * byte's 8th bit is set to 1 to indicate the length is \"long form.\" Bits 7-1\n * give the number of additional octets. All following octets are in base 256\n * with the most significant digit first (typical big-endian binary unsigned\n * integer storage). So, for instance, if the length of a value was 257, the\n * first byte would be set to:\n *\n * 10000010 = 130 = 0x82.\n *\n * This indicates there are 2 octets (base 256) for the length. The second and\n * third bytes (the octets just mentioned) would store the length in base 256:\n *\n * octet 2: 00000001 = 1 * 256^1 = 256\n * octet 3: 00000001 = 1 * 256^0 = 1\n * total = 257\n *\n * The algorithm for converting a js integer value of 257 to base-256 is:\n *\n * var value = 257;\n * var bytes = [];\n * bytes[0] = (value >>> 8) & 0xFF; // most significant byte first\n * bytes[1] = value & 0xFF; // least significant byte last\n *\n * On the ASN.1 UNIVERSAL Object Identifier (OID) type:\n *\n * An OID can be written like: \"value1.value2.value3...valueN\"\n *\n * The DER encoding rules:\n *\n * The first byte has the value 40 * value1 + value2.\n * The following bytes, if any, encode the remaining values. Each value is\n * encoded in base 128, most significant digit first (big endian), with as\n * few digits as possible, and the most significant bit of each byte set\n * to 1 except the last in each value's encoding. For example: Given the\n * OID \"1.2.840.113549\", its DER encoding is (remember each byte except the\n * last one in each encoding is OR'd with 0x80):\n *\n * byte 1: 40 * 1 + 2 = 42 = 0x2A.\n * bytes 2-3: 128 * 6 + 72 = 840 = 6 72 = 6 72 = 0x0648 = 0x8648\n * bytes 4-6: 16384 * 6 + 128 * 119 + 13 = 6 119 13 = 0x06770D = 0x86F70D\n *\n * The final value is: 0x2A864886F70D.\n * The full OID (including ASN.1 tag and length of 6 bytes) is:\n * 0x06062A864886F70D\n */\nvar forge = require('./forge');\nrequire('./util');\nrequire('./oids');\n\n/* ASN.1 API */\nvar asn1 = module.exports = forge.asn1 = forge.asn1 || {};\n\n/**\n * ASN.1 classes.\n */\nasn1.Class = {\n UNIVERSAL: 0x00,\n APPLICATION: 0x40,\n CONTEXT_SPECIFIC: 0x80,\n PRIVATE: 0xC0\n};\n\n/**\n * ASN.1 types. Not all types are supported by this implementation, only\n * those necessary to implement a simple PKI are implemented.\n */\nasn1.Type = {\n NONE: 0,\n BOOLEAN: 1,\n INTEGER: 2,\n BITSTRING: 3,\n OCTETSTRING: 4,\n NULL: 5,\n OID: 6,\n ODESC: 7,\n EXTERNAL: 8,\n REAL: 9,\n ENUMERATED: 10,\n EMBEDDED: 11,\n UTF8: 12,\n ROID: 13,\n SEQUENCE: 16,\n SET: 17,\n PRINTABLESTRING: 19,\n IA5STRING: 22,\n UTCTIME: 23,\n GENERALIZEDTIME: 24,\n BMPSTRING: 30\n};\n\n/**\n * Creates a new asn1 object.\n *\n * @param tagClass the tag class for the object.\n * @param type the data type (tag number) for the object.\n * @param constructed true if the asn1 object is in constructed form.\n * @param value the value for the object, if it is not constructed.\n * @param [options] the options to use:\n * [bitStringContents] the plain BIT STRING content including padding\n * byte.\n *\n * @return the asn1 object.\n */\nasn1.create = function(tagClass, type, constructed, value, options) {\n /* An asn1 object has a tagClass, a type, a constructed flag, and a\n value. The value's type depends on the constructed flag. If\n constructed, it will contain a list of other asn1 objects. If not,\n it will contain the ASN.1 value as an array of bytes formatted\n according to the ASN.1 data type. */\n\n // remove undefined values\n if(forge.util.isArray(value)) {\n var tmp = [];\n for(var i = 0; i < value.length; ++i) {\n if(value[i] !== undefined) {\n tmp.push(value[i]);\n }\n }\n value = tmp;\n }\n\n var obj = {\n tagClass: tagClass,\n type: type,\n constructed: constructed,\n composed: constructed || forge.util.isArray(value),\n value: value\n };\n if(options && 'bitStringContents' in options) {\n // TODO: copy byte buffer if it's a buffer not a string\n obj.bitStringContents = options.bitStringContents;\n // TODO: add readonly flag to avoid this overhead\n // save copy to detect changes\n obj.original = asn1.copy(obj);\n }\n return obj;\n};\n\n/**\n * Copies an asn1 object.\n *\n * @param obj the asn1 object.\n * @param [options] copy options:\n * [excludeBitStringContents] true to not copy bitStringContents\n *\n * @return the a copy of the asn1 object.\n */\nasn1.copy = function(obj, options) {\n var copy;\n\n if(forge.util.isArray(obj)) {\n copy = [];\n for(var i = 0; i < obj.length; ++i) {\n copy.push(asn1.copy(obj[i], options));\n }\n return copy;\n }\n\n if(typeof obj === 'string') {\n // TODO: copy byte buffer if it's a buffer not a string\n return obj;\n }\n\n copy = {\n tagClass: obj.tagClass,\n type: obj.type,\n constructed: obj.constructed,\n composed: obj.composed,\n value: asn1.copy(obj.value, options)\n };\n if(options && !options.excludeBitStringContents) {\n // TODO: copy byte buffer if it's a buffer not a string\n copy.bitStringContents = obj.bitStringContents;\n }\n return copy;\n};\n\n/**\n * Compares asn1 objects for equality.\n *\n * Note this function does not run in constant time.\n *\n * @param obj1 the first asn1 object.\n * @param obj2 the second asn1 object.\n * @param [options] compare options:\n * [includeBitStringContents] true to compare bitStringContents\n *\n * @return true if the asn1 objects are equal.\n */\nasn1.equals = function(obj1, obj2, options) {\n if(forge.util.isArray(obj1)) {\n if(!forge.util.isArray(obj2)) {\n return false;\n }\n if(obj1.length !== obj2.length) {\n return false;\n }\n for(var i = 0; i < obj1.length; ++i) {\n if(!asn1.equals(obj1[i], obj2[i])) {\n return false;\n }\n }\n return true;\n }\n\n if(typeof obj1 !== typeof obj2) {\n return false;\n }\n\n if(typeof obj1 === 'string') {\n return obj1 === obj2;\n }\n\n var equal = obj1.tagClass === obj2.tagClass &&\n obj1.type === obj2.type &&\n obj1.constructed === obj2.constructed &&\n obj1.composed === obj2.composed &&\n asn1.equals(obj1.value, obj2.value);\n if(options && options.includeBitStringContents) {\n equal = equal && (obj1.bitStringContents === obj2.bitStringContents);\n }\n\n return equal;\n};\n\n/**\n * Gets the length of a BER-encoded ASN.1 value.\n *\n * In case the length is not specified, undefined is returned.\n *\n * @param b the BER-encoded ASN.1 byte buffer, starting with the first\n * length byte.\n *\n * @return the length of the BER-encoded ASN.1 value or undefined.\n */\nasn1.getBerValueLength = function(b) {\n // TODO: move this function and related DER/BER functions to a der.js\n // file; better abstract ASN.1 away from der/ber.\n var b2 = b.getByte();\n if(b2 === 0x80) {\n return undefined;\n }\n\n // see if the length is \"short form\" or \"long form\" (bit 8 set)\n var length;\n var longForm = b2 & 0x80;\n if(!longForm) {\n // length is just the first byte\n length = b2;\n } else {\n // the number of bytes the length is specified in bits 7 through 1\n // and each length byte is in big-endian base-256\n length = b.getInt((b2 & 0x7F) << 3);\n }\n return length;\n};\n\n/**\n * Check if the byte buffer has enough bytes. Throws an Error if not.\n *\n * @param bytes the byte buffer to parse from.\n * @param remaining the bytes remaining in the current parsing state.\n * @param n the number of bytes the buffer must have.\n */\nfunction _checkBufferLength(bytes, remaining, n) {\n if(n > remaining) {\n var error = new Error('Too few bytes to parse DER.');\n error.available = bytes.length();\n error.remaining = remaining;\n error.requested = n;\n throw error;\n }\n}\n\n/**\n * Gets the length of a BER-encoded ASN.1 value.\n *\n * In case the length is not specified, undefined is returned.\n *\n * @param bytes the byte buffer to parse from.\n * @param remaining the bytes remaining in the current parsing state.\n *\n * @return the length of the BER-encoded ASN.1 value or undefined.\n */\nvar _getValueLength = function(bytes, remaining) {\n // TODO: move this function and related DER/BER functions to a der.js\n // file; better abstract ASN.1 away from der/ber.\n // fromDer already checked that this byte exists\n var b2 = bytes.getByte();\n remaining--;\n if(b2 === 0x80) {\n return undefined;\n }\n\n // see if the length is \"short form\" or \"long form\" (bit 8 set)\n var length;\n var longForm = b2 & 0x80;\n if(!longForm) {\n // length is just the first byte\n length = b2;\n } else {\n // the number of bytes the length is specified in bits 7 through 1\n // and each length byte is in big-endian base-256\n var longFormBytes = b2 & 0x7F;\n _checkBufferLength(bytes, remaining, longFormBytes);\n length = bytes.getInt(longFormBytes << 3);\n }\n // FIXME: this will only happen for 32 bit getInt with high bit set\n if(length < 0) {\n throw new Error('Negative length: ' + length);\n }\n return length;\n};\n\n/**\n * Parses an asn1 object from a byte buffer in DER format.\n *\n * @param bytes the byte buffer to parse from.\n * @param [strict] true to be strict when checking value lengths, false to\n * allow truncated values (default: true).\n * @param [options] object with options or boolean strict flag\n * [strict] true to be strict when checking value lengths, false to\n * allow truncated values (default: true).\n * [parseAllBytes] true to ensure all bytes are parsed\n * (default: true)\n * [decodeBitStrings] true to attempt to decode the content of\n * BIT STRINGs (not OCTET STRINGs) using strict mode. Note that\n * without schema support to understand the data context this can\n * erroneously decode values that happen to be valid ASN.1. This\n * flag will be deprecated or removed as soon as schema support is\n * available. (default: true)\n *\n * @throws Will throw an error for various malformed input conditions.\n *\n * @return the parsed asn1 object.\n */\nasn1.fromDer = function(bytes, options) {\n if(options === undefined) {\n options = {\n strict: true,\n parseAllBytes: true,\n decodeBitStrings: true\n };\n }\n if(typeof options === 'boolean') {\n options = {\n strict: options,\n parseAllBytes: true,\n decodeBitStrings: true\n };\n }\n if(!('strict' in options)) {\n options.strict = true;\n }\n if(!('parseAllBytes' in options)) {\n options.parseAllBytes = true;\n }\n if(!('decodeBitStrings' in options)) {\n options.decodeBitStrings = true;\n }\n\n // wrap in buffer if needed\n if(typeof bytes === 'string') {\n bytes = forge.util.createBuffer(bytes);\n }\n\n var byteCount = bytes.length();\n var value = _fromDer(bytes, bytes.length(), 0, options);\n if(options.parseAllBytes && bytes.length() !== 0) {\n var error = new Error('Unparsed DER bytes remain after ASN.1 parsing.');\n error.byteCount = byteCount;\n error.remaining = bytes.length();\n throw error;\n }\n return value;\n};\n\n/**\n * Internal function to parse an asn1 object from a byte buffer in DER format.\n *\n * @param bytes the byte buffer to parse from.\n * @param remaining the number of bytes remaining for this chunk.\n * @param depth the current parsing depth.\n * @param options object with same options as fromDer().\n *\n * @return the parsed asn1 object.\n */\nfunction _fromDer(bytes, remaining, depth, options) {\n // temporary storage for consumption calculations\n var start;\n\n // minimum length for ASN.1 DER structure is 2\n _checkBufferLength(bytes, remaining, 2);\n\n // get the first byte\n var b1 = bytes.getByte();\n // consumed one byte\n remaining--;\n\n // get the tag class\n var tagClass = (b1 & 0xC0);\n\n // get the type (bits 1-5)\n var type = b1 & 0x1F;\n\n // get the variable value length and adjust remaining bytes\n start = bytes.length();\n var length = _getValueLength(bytes, remaining);\n remaining -= start - bytes.length();\n\n // ensure there are enough bytes to get the value\n if(length !== undefined && length > remaining) {\n if(options.strict) {\n var error = new Error('Too few bytes to read ASN.1 value.');\n error.available = bytes.length();\n error.remaining = remaining;\n error.requested = length;\n throw error;\n }\n // Note: be lenient with truncated values and use remaining state bytes\n length = remaining;\n }\n\n // value storage\n var value;\n // possible BIT STRING contents storage\n var bitStringContents;\n\n // constructed flag is bit 6 (32 = 0x20) of the first byte\n var constructed = ((b1 & 0x20) === 0x20);\n if(constructed) {\n // parse child asn1 objects from the value\n value = [];\n if(length === undefined) {\n // asn1 object of indefinite length, read until end tag\n for(;;) {\n _checkBufferLength(bytes, remaining, 2);\n if(bytes.bytes(2) === String.fromCharCode(0, 0)) {\n bytes.getBytes(2);\n remaining -= 2;\n break;\n }\n start = bytes.length();\n value.push(_fromDer(bytes, remaining, depth + 1, options));\n remaining -= start - bytes.length();\n }\n } else {\n // parsing asn1 object of definite length\n while(length > 0) {\n start = bytes.length();\n value.push(_fromDer(bytes, length, depth + 1, options));\n remaining -= start - bytes.length();\n length -= start - bytes.length();\n }\n }\n }\n\n // if a BIT STRING, save the contents including padding\n if(value === undefined && tagClass === asn1.Class.UNIVERSAL &&\n type === asn1.Type.BITSTRING) {\n bitStringContents = bytes.bytes(length);\n }\n\n // determine if a non-constructed value should be decoded as a composed\n // value that contains other ASN.1 objects. BIT STRINGs (and OCTET STRINGs)\n // can be used this way.\n if(value === undefined && options.decodeBitStrings &&\n tagClass === asn1.Class.UNIVERSAL &&\n // FIXME: OCTET STRINGs not yet supported here\n // .. other parts of forge expect to decode OCTET STRINGs manually\n (type === asn1.Type.BITSTRING /*|| type === asn1.Type.OCTETSTRING*/) &&\n length > 1) {\n // save read position\n var savedRead = bytes.read;\n var savedRemaining = remaining;\n var unused = 0;\n if(type === asn1.Type.BITSTRING) {\n /* The first octet gives the number of bits by which the length of the\n bit string is less than the next multiple of eight (this is called\n the \"number of unused bits\").\n\n The second and following octets give the value of the bit string\n converted to an octet string. */\n _checkBufferLength(bytes, remaining, 1);\n unused = bytes.getByte();\n remaining--;\n }\n // if all bits are used, maybe the BIT/OCTET STRING holds ASN.1 objs\n if(unused === 0) {\n try {\n // attempt to parse child asn1 object from the value\n // (stored in array to signal composed value)\n start = bytes.length();\n var subOptions = {\n // enforce strict mode to avoid parsing ASN.1 from plain data\n strict: true,\n decodeBitStrings: true\n };\n var composed = _fromDer(bytes, remaining, depth + 1, subOptions);\n var used = start - bytes.length();\n remaining -= used;\n if(type == asn1.Type.BITSTRING) {\n used++;\n }\n\n // if the data all decoded and the class indicates UNIVERSAL or\n // CONTEXT_SPECIFIC then assume we've got an encapsulated ASN.1 object\n var tc = composed.tagClass;\n if(used === length &&\n (tc === asn1.Class.UNIVERSAL || tc === asn1.Class.CONTEXT_SPECIFIC)) {\n value = [composed];\n }\n } catch(ex) {\n }\n }\n if(value === undefined) {\n // restore read position\n bytes.read = savedRead;\n remaining = savedRemaining;\n }\n }\n\n if(value === undefined) {\n // asn1 not constructed or composed, get raw value\n // TODO: do DER to OID conversion and vice-versa in .toDer?\n\n if(length === undefined) {\n if(options.strict) {\n throw new Error('Non-constructed ASN.1 object of indefinite length.');\n }\n // be lenient and use remaining state bytes\n length = remaining;\n }\n\n if(type === asn1.Type.BMPSTRING) {\n value = '';\n for(; length > 0; length -= 2) {\n _checkBufferLength(bytes, remaining, 2);\n value += String.fromCharCode(bytes.getInt16());\n remaining -= 2;\n }\n } else {\n value = bytes.getBytes(length);\n remaining -= length;\n }\n }\n\n // add BIT STRING contents if available\n var asn1Options = bitStringContents === undefined ? null : {\n bitStringContents: bitStringContents\n };\n\n // create and return asn1 object\n return asn1.create(tagClass, type, constructed, value, asn1Options);\n}\n\n/**\n * Converts the given asn1 object to a buffer of bytes in DER format.\n *\n * @param asn1 the asn1 object to convert to bytes.\n *\n * @return the buffer of bytes.\n */\nasn1.toDer = function(obj) {\n var bytes = forge.util.createBuffer();\n\n // build the first byte\n var b1 = obj.tagClass | obj.type;\n\n // for storing the ASN.1 value\n var value = forge.util.createBuffer();\n\n // use BIT STRING contents if available and data not changed\n var useBitStringContents = false;\n if('bitStringContents' in obj) {\n useBitStringContents = true;\n if(obj.original) {\n useBitStringContents = asn1.equals(obj, obj.original);\n }\n }\n\n if(useBitStringContents) {\n value.putBytes(obj.bitStringContents);\n } else if(obj.composed) {\n // if composed, use each child asn1 object's DER bytes as value\n // turn on 6th bit (0x20 = 32) to indicate asn1 is constructed\n // from other asn1 objects\n if(obj.constructed) {\n b1 |= 0x20;\n } else {\n // type is a bit string, add unused bits of 0x00\n value.putByte(0x00);\n }\n\n // add all of the child DER bytes together\n for(var i = 0; i < obj.value.length; ++i) {\n if(obj.value[i] !== undefined) {\n value.putBuffer(asn1.toDer(obj.value[i]));\n }\n }\n } else {\n // use asn1.value directly\n if(obj.type === asn1.Type.BMPSTRING) {\n for(var i = 0; i < obj.value.length; ++i) {\n value.putInt16(obj.value.charCodeAt(i));\n }\n } else {\n // ensure integer is minimally-encoded\n // TODO: should all leading bytes be stripped vs just one?\n // .. ex '00 00 01' => '01'?\n if(obj.type === asn1.Type.INTEGER &&\n obj.value.length > 1 &&\n // leading 0x00 for positive integer\n ((obj.value.charCodeAt(0) === 0 &&\n (obj.value.charCodeAt(1) & 0x80) === 0) ||\n // leading 0xFF for negative integer\n (obj.value.charCodeAt(0) === 0xFF &&\n (obj.value.charCodeAt(1) & 0x80) === 0x80))) {\n value.putBytes(obj.value.substr(1));\n } else {\n value.putBytes(obj.value);\n }\n }\n }\n\n // add tag byte\n bytes.putByte(b1);\n\n // use \"short form\" encoding\n if(value.length() <= 127) {\n // one byte describes the length\n // bit 8 = 0 and bits 7-1 = length\n bytes.putByte(value.length() & 0x7F);\n } else {\n // use \"long form\" encoding\n // 2 to 127 bytes describe the length\n // first byte: bit 8 = 1 and bits 7-1 = # of additional bytes\n // other bytes: length in base 256, big-endian\n var len = value.length();\n var lenBytes = '';\n do {\n lenBytes += String.fromCharCode(len & 0xFF);\n len = len >>> 8;\n } while(len > 0);\n\n // set first byte to # bytes used to store the length and turn on\n // bit 8 to indicate long-form length is used\n bytes.putByte(lenBytes.length | 0x80);\n\n // concatenate length bytes in reverse since they were generated\n // little endian and we need big endian\n for(var i = lenBytes.length - 1; i >= 0; --i) {\n bytes.putByte(lenBytes.charCodeAt(i));\n }\n }\n\n // concatenate value bytes\n bytes.putBuffer(value);\n return bytes;\n};\n\n/**\n * Converts an OID dot-separated string to a byte buffer. The byte buffer\n * contains only the DER-encoded value, not any tag or length bytes.\n *\n * @param oid the OID dot-separated string.\n *\n * @return the byte buffer.\n */\nasn1.oidToDer = function(oid) {\n // split OID into individual values\n var values = oid.split('.');\n var bytes = forge.util.createBuffer();\n\n // first byte is 40 * value1 + value2\n bytes.putByte(40 * parseInt(values[0], 10) + parseInt(values[1], 10));\n // other bytes are each value in base 128 with 8th bit set except for\n // the last byte for each value\n var last, valueBytes, value, b;\n for(var i = 2; i < values.length; ++i) {\n // produce value bytes in reverse because we don't know how many\n // bytes it will take to store the value\n last = true;\n valueBytes = [];\n value = parseInt(values[i], 10);\n do {\n b = value & 0x7F;\n value = value >>> 7;\n // if value is not last, then turn on 8th bit\n if(!last) {\n b |= 0x80;\n }\n valueBytes.push(b);\n last = false;\n } while(value > 0);\n\n // add value bytes in reverse (needs to be in big endian)\n for(var n = valueBytes.length - 1; n >= 0; --n) {\n bytes.putByte(valueBytes[n]);\n }\n }\n\n return bytes;\n};\n\n/**\n * Converts a DER-encoded byte buffer to an OID dot-separated string. The\n * byte buffer should contain only the DER-encoded value, not any tag or\n * length bytes.\n *\n * @param bytes the byte buffer.\n *\n * @return the OID dot-separated string.\n */\nasn1.derToOid = function(bytes) {\n var oid;\n\n // wrap in buffer if needed\n if(typeof bytes === 'string') {\n bytes = forge.util.createBuffer(bytes);\n }\n\n // first byte is 40 * value1 + value2\n var b = bytes.getByte();\n oid = Math.floor(b / 40) + '.' + (b % 40);\n\n // other bytes are each value in base 128 with 8th bit set except for\n // the last byte for each value\n var value = 0;\n while(bytes.length() > 0) {\n b = bytes.getByte();\n value = value << 7;\n // not the last byte for the value\n if(b & 0x80) {\n value += b & 0x7F;\n } else {\n // last byte\n oid += '.' + (value + b);\n value = 0;\n }\n }\n\n return oid;\n};\n\n/**\n * Converts a UTCTime value to a date.\n *\n * Note: GeneralizedTime has 4 digits for the year and is used for X.509\n * dates past 2049. Parsing that structure hasn't been implemented yet.\n *\n * @param utc the UTCTime value to convert.\n *\n * @return the date.\n */\nasn1.utcTimeToDate = function(utc) {\n /* The following formats can be used:\n\n YYMMDDhhmmZ\n YYMMDDhhmm+hh'mm'\n YYMMDDhhmm-hh'mm'\n YYMMDDhhmmssZ\n YYMMDDhhmmss+hh'mm'\n YYMMDDhhmmss-hh'mm'\n\n Where:\n\n YY is the least significant two digits of the year\n MM is the month (01 to 12)\n DD is the day (01 to 31)\n hh is the hour (00 to 23)\n mm are the minutes (00 to 59)\n ss are the seconds (00 to 59)\n Z indicates that local time is GMT, + indicates that local time is\n later than GMT, and - indicates that local time is earlier than GMT\n hh' is the absolute value of the offset from GMT in hours\n mm' is the absolute value of the offset from GMT in minutes */\n var date = new Date();\n\n // if YY >= 50 use 19xx, if YY < 50 use 20xx\n var year = parseInt(utc.substr(0, 2), 10);\n year = (year >= 50) ? 1900 + year : 2000 + year;\n var MM = parseInt(utc.substr(2, 2), 10) - 1; // use 0-11 for month\n var DD = parseInt(utc.substr(4, 2), 10);\n var hh = parseInt(utc.substr(6, 2), 10);\n var mm = parseInt(utc.substr(8, 2), 10);\n var ss = 0;\n\n // not just YYMMDDhhmmZ\n if(utc.length > 11) {\n // get character after minutes\n var c = utc.charAt(10);\n var end = 10;\n\n // see if seconds are present\n if(c !== '+' && c !== '-') {\n // get seconds\n ss = parseInt(utc.substr(10, 2), 10);\n end += 2;\n }\n }\n\n // update date\n date.setUTCFullYear(year, MM, DD);\n date.setUTCHours(hh, mm, ss, 0);\n\n if(end) {\n // get +/- after end of time\n c = utc.charAt(end);\n if(c === '+' || c === '-') {\n // get hours+minutes offset\n var hhoffset = parseInt(utc.substr(end + 1, 2), 10);\n var mmoffset = parseInt(utc.substr(end + 4, 2), 10);\n\n // calculate offset in milliseconds\n var offset = hhoffset * 60 + mmoffset;\n offset *= 60000;\n\n // apply offset\n if(c === '+') {\n date.setTime(+date - offset);\n } else {\n date.setTime(+date + offset);\n }\n }\n }\n\n return date;\n};\n\n/**\n * Converts a GeneralizedTime value to a date.\n *\n * @param gentime the GeneralizedTime value to convert.\n *\n * @return the date.\n */\nasn1.generalizedTimeToDate = function(gentime) {\n /* The following formats can be used:\n\n YYYYMMDDHHMMSS\n YYYYMMDDHHMMSS.fff\n YYYYMMDDHHMMSSZ\n YYYYMMDDHHMMSS.fffZ\n YYYYMMDDHHMMSS+hh'mm'\n YYYYMMDDHHMMSS.fff+hh'mm'\n YYYYMMDDHHMMSS-hh'mm'\n YYYYMMDDHHMMSS.fff-hh'mm'\n\n Where:\n\n YYYY is the year\n MM is the month (01 to 12)\n DD is the day (01 to 31)\n hh is the hour (00 to 23)\n mm are the minutes (00 to 59)\n ss are the seconds (00 to 59)\n .fff is the second fraction, accurate to three decimal places\n Z indicates that local time is GMT, + indicates that local time is\n later than GMT, and - indicates that local time is earlier than GMT\n hh' is the absolute value of the offset from GMT in hours\n mm' is the absolute value of the offset from GMT in minutes */\n var date = new Date();\n\n var YYYY = parseInt(gentime.substr(0, 4), 10);\n var MM = parseInt(gentime.substr(4, 2), 10) - 1; // use 0-11 for month\n var DD = parseInt(gentime.substr(6, 2), 10);\n var hh = parseInt(gentime.substr(8, 2), 10);\n var mm = parseInt(gentime.substr(10, 2), 10);\n var ss = parseInt(gentime.substr(12, 2), 10);\n var fff = 0;\n var offset = 0;\n var isUTC = false;\n\n if(gentime.charAt(gentime.length - 1) === 'Z') {\n isUTC = true;\n }\n\n var end = gentime.length - 5, c = gentime.charAt(end);\n if(c === '+' || c === '-') {\n // get hours+minutes offset\n var hhoffset = parseInt(gentime.substr(end + 1, 2), 10);\n var mmoffset = parseInt(gentime.substr(end + 4, 2), 10);\n\n // calculate offset in milliseconds\n offset = hhoffset * 60 + mmoffset;\n offset *= 60000;\n\n // apply offset\n if(c === '+') {\n offset *= -1;\n }\n\n isUTC = true;\n }\n\n // check for second fraction\n if(gentime.charAt(14) === '.') {\n fff = parseFloat(gentime.substr(14), 10) * 1000;\n }\n\n if(isUTC) {\n date.setUTCFullYear(YYYY, MM, DD);\n date.setUTCHours(hh, mm, ss, fff);\n\n // apply offset\n date.setTime(+date + offset);\n } else {\n date.setFullYear(YYYY, MM, DD);\n date.setHours(hh, mm, ss, fff);\n }\n\n return date;\n};\n\n/**\n * Converts a date to a UTCTime value.\n *\n * Note: GeneralizedTime has 4 digits for the year and is used for X.509\n * dates past 2049. Converting to a GeneralizedTime hasn't been\n * implemented yet.\n *\n * @param date the date to convert.\n *\n * @return the UTCTime value.\n */\nasn1.dateToUtcTime = function(date) {\n // TODO: validate; currently assumes proper format\n if(typeof date === 'string') {\n return date;\n }\n\n var rval = '';\n\n // create format YYMMDDhhmmssZ\n var format = [];\n format.push(('' + date.getUTCFullYear()).substr(2));\n format.push('' + (date.getUTCMonth() + 1));\n format.push('' + date.getUTCDate());\n format.push('' + date.getUTCHours());\n format.push('' + date.getUTCMinutes());\n format.push('' + date.getUTCSeconds());\n\n // ensure 2 digits are used for each format entry\n for(var i = 0; i < format.length; ++i) {\n if(format[i].length < 2) {\n rval += '0';\n }\n rval += format[i];\n }\n rval += 'Z';\n\n return rval;\n};\n\n/**\n * Converts a date to a GeneralizedTime value.\n *\n * @param date the date to convert.\n *\n * @return the GeneralizedTime value as a string.\n */\nasn1.dateToGeneralizedTime = function(date) {\n // TODO: validate; currently assumes proper format\n if(typeof date === 'string') {\n return date;\n }\n\n var rval = '';\n\n // create format YYYYMMDDHHMMSSZ\n var format = [];\n format.push('' + date.getUTCFullYear());\n format.push('' + (date.getUTCMonth() + 1));\n format.push('' + date.getUTCDate());\n format.push('' + date.getUTCHours());\n format.push('' + date.getUTCMinutes());\n format.push('' + date.getUTCSeconds());\n\n // ensure 2 digits are used for each format entry\n for(var i = 0; i < format.length; ++i) {\n if(format[i].length < 2) {\n rval += '0';\n }\n rval += format[i];\n }\n rval += 'Z';\n\n return rval;\n};\n\n/**\n * Converts a javascript integer to a DER-encoded byte buffer to be used\n * as the value for an INTEGER type.\n *\n * @param x the integer.\n *\n * @return the byte buffer.\n */\nasn1.integerToDer = function(x) {\n var rval = forge.util.createBuffer();\n if(x >= -0x80 && x < 0x80) {\n return rval.putSignedInt(x, 8);\n }\n if(x >= -0x8000 && x < 0x8000) {\n return rval.putSignedInt(x, 16);\n }\n if(x >= -0x800000 && x < 0x800000) {\n return rval.putSignedInt(x, 24);\n }\n if(x >= -0x80000000 && x < 0x80000000) {\n return rval.putSignedInt(x, 32);\n }\n var error = new Error('Integer too large; max is 32-bits.');\n error.integer = x;\n throw error;\n};\n\n/**\n * Converts a DER-encoded byte buffer to a javascript integer. This is\n * typically used to decode the value of an INTEGER type.\n *\n * @param bytes the byte buffer.\n *\n * @return the integer.\n */\nasn1.derToInteger = function(bytes) {\n // wrap in buffer if needed\n if(typeof bytes === 'string') {\n bytes = forge.util.createBuffer(bytes);\n }\n\n var n = bytes.length() * 8;\n if(n > 32) {\n throw new Error('Integer too large; max is 32-bits.');\n }\n return bytes.getSignedInt(n);\n};\n\n/**\n * Validates that the given ASN.1 object is at least a super set of the\n * given ASN.1 structure. Only tag classes and types are checked. An\n * optional map may also be provided to capture ASN.1 values while the\n * structure is checked.\n *\n * To capture an ASN.1 value, set an object in the validator's 'capture'\n * parameter to the key to use in the capture map. To capture the full\n * ASN.1 object, specify 'captureAsn1'. To capture BIT STRING bytes, including\n * the leading unused bits counter byte, specify 'captureBitStringContents'.\n * To capture BIT STRING bytes, without the leading unused bits counter byte,\n * specify 'captureBitStringValue'.\n *\n * Objects in the validator may set a field 'optional' to true to indicate\n * that it isn't necessary to pass validation.\n *\n * @param obj the ASN.1 object to validate.\n * @param v the ASN.1 structure validator.\n * @param capture an optional map to capture values in.\n * @param errors an optional array for storing validation errors.\n *\n * @return true on success, false on failure.\n */\nasn1.validate = function(obj, v, capture, errors) {\n var rval = false;\n\n // ensure tag class and type are the same if specified\n if((obj.tagClass === v.tagClass || typeof(v.tagClass) === 'undefined') &&\n (obj.type === v.type || typeof(v.type) === 'undefined')) {\n // ensure constructed flag is the same if specified\n if(obj.constructed === v.constructed ||\n typeof(v.constructed) === 'undefined') {\n rval = true;\n\n // handle sub values\n if(v.value && forge.util.isArray(v.value)) {\n var j = 0;\n for(var i = 0; rval && i < v.value.length; ++i) {\n rval = v.value[i].optional || false;\n if(obj.value[j]) {\n rval = asn1.validate(obj.value[j], v.value[i], capture, errors);\n if(rval) {\n ++j;\n } else if(v.value[i].optional) {\n rval = true;\n }\n }\n if(!rval && errors) {\n errors.push(\n '[' + v.name + '] ' +\n 'Tag class \"' + v.tagClass + '\", type \"' +\n v.type + '\" expected value length \"' +\n v.value.length + '\", got \"' +\n obj.value.length + '\"');\n }\n }\n }\n\n if(rval && capture) {\n if(v.capture) {\n capture[v.capture] = obj.value;\n }\n if(v.captureAsn1) {\n capture[v.captureAsn1] = obj;\n }\n if(v.captureBitStringContents && 'bitStringContents' in obj) {\n capture[v.captureBitStringContents] = obj.bitStringContents;\n }\n if(v.captureBitStringValue && 'bitStringContents' in obj) {\n var value;\n if(obj.bitStringContents.length < 2) {\n capture[v.captureBitStringValue] = '';\n } else {\n // FIXME: support unused bits with data shifting\n var unused = obj.bitStringContents.charCodeAt(0);\n if(unused !== 0) {\n throw new Error(\n 'captureBitStringValue only supported for zero unused bits');\n }\n capture[v.captureBitStringValue] = obj.bitStringContents.slice(1);\n }\n }\n }\n } else if(errors) {\n errors.push(\n '[' + v.name + '] ' +\n 'Expected constructed \"' + v.constructed + '\", got \"' +\n obj.constructed + '\"');\n }\n } else if(errors) {\n if(obj.tagClass !== v.tagClass) {\n errors.push(\n '[' + v.name + '] ' +\n 'Expected tag class \"' + v.tagClass + '\", got \"' +\n obj.tagClass + '\"');\n }\n if(obj.type !== v.type) {\n errors.push(\n '[' + v.name + '] ' +\n 'Expected type \"' + v.type + '\", got \"' + obj.type + '\"');\n }\n }\n return rval;\n};\n\n// regex for testing for non-latin characters\nvar _nonLatinRegex = /[^\\\\u0000-\\\\u00ff]/;\n\n/**\n * Pretty prints an ASN.1 object to a string.\n *\n * @param obj the object to write out.\n * @param level the level in the tree.\n * @param indentation the indentation to use.\n *\n * @return the string.\n */\nasn1.prettyPrint = function(obj, level, indentation) {\n var rval = '';\n\n // set default level and indentation\n level = level || 0;\n indentation = indentation || 2;\n\n // start new line for deep levels\n if(level > 0) {\n rval += '\\n';\n }\n\n // create indent\n var indent = '';\n for(var i = 0; i < level * indentation; ++i) {\n indent += ' ';\n }\n\n // print class:type\n rval += indent + 'Tag: ';\n switch(obj.tagClass) {\n case asn1.Class.UNIVERSAL:\n rval += 'Universal:';\n break;\n case asn1.Class.APPLICATION:\n rval += 'Application:';\n break;\n case asn1.Class.CONTEXT_SPECIFIC:\n rval += 'Context-Specific:';\n break;\n case asn1.Class.PRIVATE:\n rval += 'Private:';\n break;\n }\n\n if(obj.tagClass === asn1.Class.UNIVERSAL) {\n rval += obj.type;\n\n // known types\n switch(obj.type) {\n case asn1.Type.NONE:\n rval += ' (None)';\n break;\n case asn1.Type.BOOLEAN:\n rval += ' (Boolean)';\n break;\n case asn1.Type.INTEGER:\n rval += ' (Integer)';\n break;\n case asn1.Type.BITSTRING:\n rval += ' (Bit string)';\n break;\n case asn1.Type.OCTETSTRING:\n rval += ' (Octet string)';\n break;\n case asn1.Type.NULL:\n rval += ' (Null)';\n break;\n case asn1.Type.OID:\n rval += ' (Object Identifier)';\n break;\n case asn1.Type.ODESC:\n rval += ' (Object Descriptor)';\n break;\n case asn1.Type.EXTERNAL:\n rval += ' (External or Instance of)';\n break;\n case asn1.Type.REAL:\n rval += ' (Real)';\n break;\n case asn1.Type.ENUMERATED:\n rval += ' (Enumerated)';\n break;\n case asn1.Type.EMBEDDED:\n rval += ' (Embedded PDV)';\n break;\n case asn1.Type.UTF8:\n rval += ' (UTF8)';\n break;\n case asn1.Type.ROID:\n rval += ' (Relative Object Identifier)';\n break;\n case asn1.Type.SEQUENCE:\n rval += ' (Sequence)';\n break;\n case asn1.Type.SET:\n rval += ' (Set)';\n break;\n case asn1.Type.PRINTABLESTRING:\n rval += ' (Printable String)';\n break;\n case asn1.Type.IA5String:\n rval += ' (IA5String (ASCII))';\n break;\n case asn1.Type.UTCTIME:\n rval += ' (UTC time)';\n break;\n case asn1.Type.GENERALIZEDTIME:\n rval += ' (Generalized time)';\n break;\n case asn1.Type.BMPSTRING:\n rval += ' (BMP String)';\n break;\n }\n } else {\n rval += obj.type;\n }\n\n rval += '\\n';\n rval += indent + 'Constructed: ' + obj.constructed + '\\n';\n\n if(obj.composed) {\n var subvalues = 0;\n var sub = '';\n for(var i = 0; i < obj.value.length; ++i) {\n if(obj.value[i] !== undefined) {\n subvalues += 1;\n sub += asn1.prettyPrint(obj.value[i], level + 1, indentation);\n if((i + 1) < obj.value.length) {\n sub += ',';\n }\n }\n }\n rval += indent + 'Sub values: ' + subvalues + sub;\n } else {\n rval += indent + 'Value: ';\n if(obj.type === asn1.Type.OID) {\n var oid = asn1.derToOid(obj.value);\n rval += oid;\n if(forge.pki && forge.pki.oids) {\n if(oid in forge.pki.oids) {\n rval += ' (' + forge.pki.oids[oid] + ') ';\n }\n }\n }\n if(obj.type === asn1.Type.INTEGER) {\n try {\n rval += asn1.derToInteger(obj.value);\n } catch(ex) {\n rval += '0x' + forge.util.bytesToHex(obj.value);\n }\n } else if(obj.type === asn1.Type.BITSTRING) {\n // TODO: shift bits as needed to display without padding\n if(obj.value.length > 1) {\n // remove unused bits field\n rval += '0x' + forge.util.bytesToHex(obj.value.slice(1));\n } else {\n rval += '(none)';\n }\n // show unused bit count\n if(obj.value.length > 0) {\n var unused = obj.value.charCodeAt(0);\n if(unused == 1) {\n rval += ' (1 unused bit shown)';\n } else if(unused > 1) {\n rval += ' (' + unused + ' unused bits shown)';\n }\n }\n } else if(obj.type === asn1.Type.OCTETSTRING) {\n if(!_nonLatinRegex.test(obj.value)) {\n rval += '(' + obj.value + ') ';\n }\n rval += '0x' + forge.util.bytesToHex(obj.value);\n } else if(obj.type === asn1.Type.UTF8) {\n try {\n rval += forge.util.decodeUtf8(obj.value);\n } catch(e) {\n if(e.message === 'URI malformed') {\n rval +=\n '0x' + forge.util.bytesToHex(obj.value) + ' (malformed UTF8)';\n } else {\n throw e;\n }\n }\n } else if(obj.type === asn1.Type.PRINTABLESTRING ||\n obj.type === asn1.Type.IA5String) {\n rval += obj.value;\n } else if(_nonLatinRegex.test(obj.value)) {\n rval += '0x' + forge.util.bytesToHex(obj.value);\n } else if(obj.value.length === 0) {\n rval += '[null]';\n } else {\n rval += obj.value;\n }\n }\n\n return rval;\n};\n","/**\n * Base-N/Base-X encoding/decoding functions.\n *\n * Original implementation from base-x:\n * https://github.com/cryptocoinjs/base-x\n *\n * Which is MIT licensed:\n *\n * The MIT License (MIT)\n *\n * Copyright base-x contributors (c) 2016\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n * DEALINGS IN THE SOFTWARE.\n */\nvar api = {};\nmodule.exports = api;\n\n// baseN alphabet indexes\nvar _reverseAlphabets = {};\n\n/**\n * BaseN-encodes a Uint8Array using the given alphabet.\n *\n * @param input the Uint8Array to encode.\n * @param maxline the maximum number of encoded characters per line to use,\n * defaults to none.\n *\n * @return the baseN-encoded output string.\n */\napi.encode = function(input, alphabet, maxline) {\n if(typeof alphabet !== 'string') {\n throw new TypeError('\"alphabet\" must be a string.');\n }\n if(maxline !== undefined && typeof maxline !== 'number') {\n throw new TypeError('\"maxline\" must be a number.');\n }\n\n var output = '';\n\n if(!(input instanceof Uint8Array)) {\n // assume forge byte buffer\n output = _encodeWithByteBuffer(input, alphabet);\n } else {\n var i = 0;\n var base = alphabet.length;\n var first = alphabet.charAt(0);\n var digits = [0];\n for(i = 0; i < input.length; ++i) {\n for(var j = 0, carry = input[i]; j < digits.length; ++j) {\n carry += digits[j] << 8;\n digits[j] = carry % base;\n carry = (carry / base) | 0;\n }\n\n while(carry > 0) {\n digits.push(carry % base);\n carry = (carry / base) | 0;\n }\n }\n\n // deal with leading zeros\n for(i = 0; input[i] === 0 && i < input.length - 1; ++i) {\n output += first;\n }\n // convert digits to a string\n for(i = digits.length - 1; i >= 0; --i) {\n output += alphabet[digits[i]];\n }\n }\n\n if(maxline) {\n var regex = new RegExp('.{1,' + maxline + '}', 'g');\n output = output.match(regex).join('\\r\\n');\n }\n\n return output;\n};\n\n/**\n * Decodes a baseN-encoded (using the given alphabet) string to a\n * Uint8Array.\n *\n * @param input the baseN-encoded input string.\n *\n * @return the Uint8Array.\n */\napi.decode = function(input, alphabet) {\n if(typeof input !== 'string') {\n throw new TypeError('\"input\" must be a string.');\n }\n if(typeof alphabet !== 'string') {\n throw new TypeError('\"alphabet\" must be a string.');\n }\n\n var table = _reverseAlphabets[alphabet];\n if(!table) {\n // compute reverse alphabet\n table = _reverseAlphabets[alphabet] = [];\n for(var i = 0; i < alphabet.length; ++i) {\n table[alphabet.charCodeAt(i)] = i;\n }\n }\n\n // remove whitespace characters\n input = input.replace(/\\s/g, '');\n\n var base = alphabet.length;\n var first = alphabet.charAt(0);\n var bytes = [0];\n for(var i = 0; i < input.length; i++) {\n var value = table[input.charCodeAt(i)];\n if(value === undefined) {\n return;\n }\n\n for(var j = 0, carry = value; j < bytes.length; ++j) {\n carry += bytes[j] * base;\n bytes[j] = carry & 0xff;\n carry >>= 8;\n }\n\n while(carry > 0) {\n bytes.push(carry & 0xff);\n carry >>= 8;\n }\n }\n\n // deal with leading zeros\n for(var k = 0; input[k] === first && k < input.length - 1; ++k) {\n bytes.push(0);\n }\n\n if(typeof Buffer !== 'undefined') {\n return Buffer.from(bytes.reverse());\n }\n\n return new Uint8Array(bytes.reverse());\n};\n\nfunction _encodeWithByteBuffer(input, alphabet) {\n var i = 0;\n var base = alphabet.length;\n var first = alphabet.charAt(0);\n var digits = [0];\n for(i = 0; i < input.length(); ++i) {\n for(var j = 0, carry = input.at(i); j < digits.length; ++j) {\n carry += digits[j] << 8;\n digits[j] = carry % base;\n carry = (carry / base) | 0;\n }\n\n while(carry > 0) {\n digits.push(carry % base);\n carry = (carry / base) | 0;\n }\n }\n\n var output = '';\n\n // deal with leading zeros\n for(i = 0; input.at(i) === 0 && i < input.length() - 1; ++i) {\n output += first;\n }\n // convert digits to a string\n for(i = digits.length - 1; i >= 0; --i) {\n output += alphabet[digits[i]];\n }\n\n return output;\n}\n","/**\n * Cipher base API.\n *\n * @author Dave Longley\n *\n * Copyright (c) 2010-2014 Digital Bazaar, Inc.\n */\nvar forge = require('./forge');\nrequire('./util');\n\nmodule.exports = forge.cipher = forge.cipher || {};\n\n// registered algorithms\nforge.cipher.algorithms = forge.cipher.algorithms || {};\n\n/**\n * Creates a cipher object that can be used to encrypt data using the given\n * algorithm and key. The algorithm may be provided as a string value for a\n * previously registered algorithm or it may be given as a cipher algorithm\n * API object.\n *\n * @param algorithm the algorithm to use, either a string or an algorithm API\n * object.\n * @param key the key to use, as a binary-encoded string of bytes or a\n * byte buffer.\n *\n * @return the cipher.\n */\nforge.cipher.createCipher = function(algorithm, key) {\n var api = algorithm;\n if(typeof api === 'string') {\n api = forge.cipher.getAlgorithm(api);\n if(api) {\n api = api();\n }\n }\n if(!api) {\n throw new Error('Unsupported algorithm: ' + algorithm);\n }\n\n // assume block cipher\n return new forge.cipher.BlockCipher({\n algorithm: api,\n key: key,\n decrypt: false\n });\n};\n\n/**\n * Creates a decipher object that can be used to decrypt data using the given\n * algorithm and key. The algorithm may be provided as a string value for a\n * previously registered algorithm or it may be given as a cipher algorithm\n * API object.\n *\n * @param algorithm the algorithm to use, either a string or an algorithm API\n * object.\n * @param key the key to use, as a binary-encoded string of bytes or a\n * byte buffer.\n *\n * @return the cipher.\n */\nforge.cipher.createDecipher = function(algorithm, key) {\n var api = algorithm;\n if(typeof api === 'string') {\n api = forge.cipher.getAlgorithm(api);\n if(api) {\n api = api();\n }\n }\n if(!api) {\n throw new Error('Unsupported algorithm: ' + algorithm);\n }\n\n // assume block cipher\n return new forge.cipher.BlockCipher({\n algorithm: api,\n key: key,\n decrypt: true\n });\n};\n\n/**\n * Registers an algorithm by name. If the name was already registered, the\n * algorithm API object will be overwritten.\n *\n * @param name the name of the algorithm.\n * @param algorithm the algorithm API object.\n */\nforge.cipher.registerAlgorithm = function(name, algorithm) {\n name = name.toUpperCase();\n forge.cipher.algorithms[name] = algorithm;\n};\n\n/**\n * Gets a registered algorithm by name.\n *\n * @param name the name of the algorithm.\n *\n * @return the algorithm, if found, null if not.\n */\nforge.cipher.getAlgorithm = function(name) {\n name = name.toUpperCase();\n if(name in forge.cipher.algorithms) {\n return forge.cipher.algorithms[name];\n }\n return null;\n};\n\nvar BlockCipher = forge.cipher.BlockCipher = function(options) {\n this.algorithm = options.algorithm;\n this.mode = this.algorithm.mode;\n this.blockSize = this.mode.blockSize;\n this._finish = false;\n this._input = null;\n this.output = null;\n this._op = options.decrypt ? this.mode.decrypt : this.mode.encrypt;\n this._decrypt = options.decrypt;\n this.algorithm.initialize(options);\n};\n\n/**\n * Starts or restarts the encryption or decryption process, whichever\n * was previously configured.\n *\n * For non-GCM mode, the IV may be a binary-encoded string of bytes, an array\n * of bytes, a byte buffer, or an array of 32-bit integers. If the IV is in\n * bytes, then it must be Nb (16) bytes in length. If the IV is given in as\n * 32-bit integers, then it must be 4 integers long.\n *\n * Note: an IV is not required or used in ECB mode.\n *\n * For GCM-mode, the IV must be given as a binary-encoded string of bytes or\n * a byte buffer. The number of bytes should be 12 (96 bits) as recommended\n * by NIST SP-800-38D but another length may be given.\n *\n * @param options the options to use:\n * iv the initialization vector to use as a binary-encoded string of\n * bytes, null to reuse the last ciphered block from a previous\n * update() (this \"residue\" method is for legacy support only).\n * additionalData additional authentication data as a binary-encoded\n * string of bytes, for 'GCM' mode, (default: none).\n * tagLength desired length of authentication tag, in bits, for\n * 'GCM' mode (0-128, default: 128).\n * tag the authentication tag to check if decrypting, as a\n * binary-encoded string of bytes.\n * output the output the buffer to write to, null to create one.\n */\nBlockCipher.prototype.start = function(options) {\n options = options || {};\n var opts = {};\n for(var key in options) {\n opts[key] = options[key];\n }\n opts.decrypt = this._decrypt;\n this._finish = false;\n this._input = forge.util.createBuffer();\n this.output = options.output || forge.util.createBuffer();\n this.mode.start(opts);\n};\n\n/**\n * Updates the next block according to the cipher mode.\n *\n * @param input the buffer to read from.\n */\nBlockCipher.prototype.update = function(input) {\n if(input) {\n // input given, so empty it into the input buffer\n this._input.putBuffer(input);\n }\n\n // do cipher operation until it needs more input and not finished\n while(!this._op.call(this.mode, this._input, this.output, this._finish) &&\n !this._finish) {}\n\n // free consumed memory from input buffer\n this._input.compact();\n};\n\n/**\n * Finishes encrypting or decrypting.\n *\n * @param pad a padding function to use in CBC mode, null for default,\n * signature(blockSize, buffer, decrypt).\n *\n * @return true if successful, false on error.\n */\nBlockCipher.prototype.finish = function(pad) {\n // backwards-compatibility w/deprecated padding API\n // Note: will overwrite padding functions even after another start() call\n if(pad && (this.mode.name === 'ECB' || this.mode.name === 'CBC')) {\n this.mode.pad = function(input) {\n return pad(this.blockSize, input, false);\n };\n this.mode.unpad = function(output) {\n return pad(this.blockSize, output, true);\n };\n }\n\n // build options for padding and afterFinish functions\n var options = {};\n options.decrypt = this._decrypt;\n\n // get # of bytes that won't fill a block\n options.overflow = this._input.length() % this.blockSize;\n\n if(!this._decrypt && this.mode.pad) {\n if(!this.mode.pad(this._input, options)) {\n return false;\n }\n }\n\n // do final update\n this._finish = true;\n this.update();\n\n if(this._decrypt && this.mode.unpad) {\n if(!this.mode.unpad(this.output, options)) {\n return false;\n }\n }\n\n if(this.mode.afterFinish) {\n if(!this.mode.afterFinish(this.output, options)) {\n return false;\n }\n }\n\n return true;\n};\n","/**\n * Supported cipher modes.\n *\n * @author Dave Longley\n *\n * Copyright (c) 2010-2014 Digital Bazaar, Inc.\n */\nvar forge = require('./forge');\nrequire('./util');\n\nforge.cipher = forge.cipher || {};\n\n// supported cipher modes\nvar modes = module.exports = forge.cipher.modes = forge.cipher.modes || {};\n\n/** Electronic codebook (ECB) (Don't use this; it's not secure) **/\n\nmodes.ecb = function(options) {\n options = options || {};\n this.name = 'ECB';\n this.cipher = options.cipher;\n this.blockSize = options.blockSize || 16;\n this._ints = this.blockSize / 4;\n this._inBlock = new Array(this._ints);\n this._outBlock = new Array(this._ints);\n};\n\nmodes.ecb.prototype.start = function(options) {};\n\nmodes.ecb.prototype.encrypt = function(input, output, finish) {\n // not enough input to encrypt\n if(input.length() < this.blockSize && !(finish && input.length() > 0)) {\n return true;\n }\n\n // get next block\n for(var i = 0; i < this._ints; ++i) {\n this._inBlock[i] = input.getInt32();\n }\n\n // encrypt block\n this.cipher.encrypt(this._inBlock, this._outBlock);\n\n // write output\n for(var i = 0; i < this._ints; ++i) {\n output.putInt32(this._outBlock[i]);\n }\n};\n\nmodes.ecb.prototype.decrypt = function(input, output, finish) {\n // not enough input to decrypt\n if(input.length() < this.blockSize && !(finish && input.length() > 0)) {\n return true;\n }\n\n // get next block\n for(var i = 0; i < this._ints; ++i) {\n this._inBlock[i] = input.getInt32();\n }\n\n // decrypt block\n this.cipher.decrypt(this._inBlock, this._outBlock);\n\n // write output\n for(var i = 0; i < this._ints; ++i) {\n output.putInt32(this._outBlock[i]);\n }\n};\n\nmodes.ecb.prototype.pad = function(input, options) {\n // add PKCS#7 padding to block (each pad byte is the\n // value of the number of pad bytes)\n var padding = (input.length() === this.blockSize ?\n this.blockSize : (this.blockSize - input.length()));\n input.fillWithByte(padding, padding);\n return true;\n};\n\nmodes.ecb.prototype.unpad = function(output, options) {\n // check for error: input data not a multiple of blockSize\n if(options.overflow > 0) {\n return false;\n }\n\n // ensure padding byte count is valid\n var len = output.length();\n var count = output.at(len - 1);\n if(count > (this.blockSize << 2)) {\n return false;\n }\n\n // trim off padding bytes\n output.truncate(count);\n return true;\n};\n\n/** Cipher-block Chaining (CBC) **/\n\nmodes.cbc = function(options) {\n options = options || {};\n this.name = 'CBC';\n this.cipher = options.cipher;\n this.blockSize = options.blockSize || 16;\n this._ints = this.blockSize / 4;\n this._inBlock = new Array(this._ints);\n this._outBlock = new Array(this._ints);\n};\n\nmodes.cbc.prototype.start = function(options) {\n // Note: legacy support for using IV residue (has security flaws)\n // if IV is null, reuse block from previous processing\n if(options.iv === null) {\n // must have a previous block\n if(!this._prev) {\n throw new Error('Invalid IV parameter.');\n }\n this._iv = this._prev.slice(0);\n } else if(!('iv' in options)) {\n throw new Error('Invalid IV parameter.');\n } else {\n // save IV as \"previous\" block\n this._iv = transformIV(options.iv, this.blockSize);\n this._prev = this._iv.slice(0);\n }\n};\n\nmodes.cbc.prototype.encrypt = function(input, output, finish) {\n // not enough input to encrypt\n if(input.length() < this.blockSize && !(finish && input.length() > 0)) {\n return true;\n }\n\n // get next block\n // CBC XOR's IV (or previous block) with plaintext\n for(var i = 0; i < this._ints; ++i) {\n this._inBlock[i] = this._prev[i] ^ input.getInt32();\n }\n\n // encrypt block\n this.cipher.encrypt(this._inBlock, this._outBlock);\n\n // write output, save previous block\n for(var i = 0; i < this._ints; ++i) {\n output.putInt32(this._outBlock[i]);\n }\n this._prev = this._outBlock;\n};\n\nmodes.cbc.prototype.decrypt = function(input, output, finish) {\n // not enough input to decrypt\n if(input.length() < this.blockSize && !(finish && input.length() > 0)) {\n return true;\n }\n\n // get next block\n for(var i = 0; i < this._ints; ++i) {\n this._inBlock[i] = input.getInt32();\n }\n\n // decrypt block\n this.cipher.decrypt(this._inBlock, this._outBlock);\n\n // write output, save previous ciphered block\n // CBC XOR's IV (or previous block) with ciphertext\n for(var i = 0; i < this._ints; ++i) {\n output.putInt32(this._prev[i] ^ this._outBlock[i]);\n }\n this._prev = this._inBlock.slice(0);\n};\n\nmodes.cbc.prototype.pad = function(input, options) {\n // add PKCS#7 padding to block (each pad byte is the\n // value of the number of pad bytes)\n var padding = (input.length() === this.blockSize ?\n this.blockSize : (this.blockSize - input.length()));\n input.fillWithByte(padding, padding);\n return true;\n};\n\nmodes.cbc.prototype.unpad = function(output, options) {\n // check for error: input data not a multiple of blockSize\n if(options.overflow > 0) {\n return false;\n }\n\n // ensure padding byte count is valid\n var len = output.length();\n var count = output.at(len - 1);\n if(count > (this.blockSize << 2)) {\n return false;\n }\n\n // trim off padding bytes\n output.truncate(count);\n return true;\n};\n\n/** Cipher feedback (CFB) **/\n\nmodes.cfb = function(options) {\n options = options || {};\n this.name = 'CFB';\n this.cipher = options.cipher;\n this.blockSize = options.blockSize || 16;\n this._ints = this.blockSize / 4;\n this._inBlock = null;\n this._outBlock = new Array(this._ints);\n this._partialBlock = new Array(this._ints);\n this._partialOutput = forge.util.createBuffer();\n this._partialBytes = 0;\n};\n\nmodes.cfb.prototype.start = function(options) {\n if(!('iv' in options)) {\n throw new Error('Invalid IV parameter.');\n }\n // use IV as first input\n this._iv = transformIV(options.iv, this.blockSize);\n this._inBlock = this._iv.slice(0);\n this._partialBytes = 0;\n};\n\nmodes.cfb.prototype.encrypt = function(input, output, finish) {\n // not enough input to encrypt\n var inputLength = input.length();\n if(inputLength === 0) {\n return true;\n }\n\n // encrypt block\n this.cipher.encrypt(this._inBlock, this._outBlock);\n\n // handle full block\n if(this._partialBytes === 0 && inputLength >= this.blockSize) {\n // XOR input with output, write input as output\n for(var i = 0; i < this._ints; ++i) {\n this._inBlock[i] = input.getInt32() ^ this._outBlock[i];\n output.putInt32(this._inBlock[i]);\n }\n return;\n }\n\n // handle partial block\n var partialBytes = (this.blockSize - inputLength) % this.blockSize;\n if(partialBytes > 0) {\n partialBytes = this.blockSize - partialBytes;\n }\n\n // XOR input with output, write input as partial output\n this._partialOutput.clear();\n for(var i = 0; i < this._ints; ++i) {\n this._partialBlock[i] = input.getInt32() ^ this._outBlock[i];\n this._partialOutput.putInt32(this._partialBlock[i]);\n }\n\n if(partialBytes > 0) {\n // block still incomplete, restore input buffer\n input.read -= this.blockSize;\n } else {\n // block complete, update input block\n for(var i = 0; i < this._ints; ++i) {\n this._inBlock[i] = this._partialBlock[i];\n }\n }\n\n // skip any previous partial bytes\n if(this._partialBytes > 0) {\n this._partialOutput.getBytes(this._partialBytes);\n }\n\n if(partialBytes > 0 && !finish) {\n output.putBytes(this._partialOutput.getBytes(\n partialBytes - this._partialBytes));\n this._partialBytes = partialBytes;\n return true;\n }\n\n output.putBytes(this._partialOutput.getBytes(\n inputLength - this._partialBytes));\n this._partialBytes = 0;\n};\n\nmodes.cfb.prototype.decrypt = function(input, output, finish) {\n // not enough input to decrypt\n var inputLength = input.length();\n if(inputLength === 0) {\n return true;\n }\n\n // encrypt block (CFB always uses encryption mode)\n this.cipher.encrypt(this._inBlock, this._outBlock);\n\n // handle full block\n if(this._partialBytes === 0 && inputLength >= this.blockSize) {\n // XOR input with output, write input as output\n for(var i = 0; i < this._ints; ++i) {\n this._inBlock[i] = input.getInt32();\n output.putInt32(this._inBlock[i] ^ this._outBlock[i]);\n }\n return;\n }\n\n // handle partial block\n var partialBytes = (this.blockSize - inputLength) % this.blockSize;\n if(partialBytes > 0) {\n partialBytes = this.blockSize - partialBytes;\n }\n\n // XOR input with output, write input as partial output\n this._partialOutput.clear();\n for(var i = 0; i < this._ints; ++i) {\n this._partialBlock[i] = input.getInt32();\n this._partialOutput.putInt32(this._partialBlock[i] ^ this._outBlock[i]);\n }\n\n if(partialBytes > 0) {\n // block still incomplete, restore input buffer\n input.read -= this.blockSize;\n } else {\n // block complete, update input block\n for(var i = 0; i < this._ints; ++i) {\n this._inBlock[i] = this._partialBlock[i];\n }\n }\n\n // skip any previous partial bytes\n if(this._partialBytes > 0) {\n this._partialOutput.getBytes(this._partialBytes);\n }\n\n if(partialBytes > 0 && !finish) {\n output.putBytes(this._partialOutput.getBytes(\n partialBytes - this._partialBytes));\n this._partialBytes = partialBytes;\n return true;\n }\n\n output.putBytes(this._partialOutput.getBytes(\n inputLength - this._partialBytes));\n this._partialBytes = 0;\n};\n\n/** Output feedback (OFB) **/\n\nmodes.ofb = function(options) {\n options = options || {};\n this.name = 'OFB';\n this.cipher = options.cipher;\n this.blockSize = options.blockSize || 16;\n this._ints = this.blockSize / 4;\n this._inBlock = null;\n this._outBlock = new Array(this._ints);\n this._partialOutput = forge.util.createBuffer();\n this._partialBytes = 0;\n};\n\nmodes.ofb.prototype.start = function(options) {\n if(!('iv' in options)) {\n throw new Error('Invalid IV parameter.');\n }\n // use IV as first input\n this._iv = transformIV(options.iv, this.blockSize);\n this._inBlock = this._iv.slice(0);\n this._partialBytes = 0;\n};\n\nmodes.ofb.prototype.encrypt = function(input, output, finish) {\n // not enough input to encrypt\n var inputLength = input.length();\n if(input.length() === 0) {\n return true;\n }\n\n // encrypt block (OFB always uses encryption mode)\n this.cipher.encrypt(this._inBlock, this._outBlock);\n\n // handle full block\n if(this._partialBytes === 0 && inputLength >= this.blockSize) {\n // XOR input with output and update next input\n for(var i = 0; i < this._ints; ++i) {\n output.putInt32(input.getInt32() ^ this._outBlock[i]);\n this._inBlock[i] = this._outBlock[i];\n }\n return;\n }\n\n // handle partial block\n var partialBytes = (this.blockSize - inputLength) % this.blockSize;\n if(partialBytes > 0) {\n partialBytes = this.blockSize - partialBytes;\n }\n\n // XOR input with output\n this._partialOutput.clear();\n for(var i = 0; i < this._ints; ++i) {\n this._partialOutput.putInt32(input.getInt32() ^ this._outBlock[i]);\n }\n\n if(partialBytes > 0) {\n // block still incomplete, restore input buffer\n input.read -= this.blockSize;\n } else {\n // block complete, update input block\n for(var i = 0; i < this._ints; ++i) {\n this._inBlock[i] = this._outBlock[i];\n }\n }\n\n // skip any previous partial bytes\n if(this._partialBytes > 0) {\n this._partialOutput.getBytes(this._partialBytes);\n }\n\n if(partialBytes > 0 && !finish) {\n output.putBytes(this._partialOutput.getBytes(\n partialBytes - this._partialBytes));\n this._partialBytes = partialBytes;\n return true;\n }\n\n output.putBytes(this._partialOutput.getBytes(\n inputLength - this._partialBytes));\n this._partialBytes = 0;\n};\n\nmodes.ofb.prototype.decrypt = modes.ofb.prototype.encrypt;\n\n/** Counter (CTR) **/\n\nmodes.ctr = function(options) {\n options = options || {};\n this.name = 'CTR';\n this.cipher = options.cipher;\n this.blockSize = options.blockSize || 16;\n this._ints = this.blockSize / 4;\n this._inBlock = null;\n this._outBlock = new Array(this._ints);\n this._partialOutput = forge.util.createBuffer();\n this._partialBytes = 0;\n};\n\nmodes.ctr.prototype.start = function(options) {\n if(!('iv' in options)) {\n throw new Error('Invalid IV parameter.');\n }\n // use IV as first input\n this._iv = transformIV(options.iv, this.blockSize);\n this._inBlock = this._iv.slice(0);\n this._partialBytes = 0;\n};\n\nmodes.ctr.prototype.encrypt = function(input, output, finish) {\n // not enough input to encrypt\n var inputLength = input.length();\n if(inputLength === 0) {\n return true;\n }\n\n // encrypt block (CTR always uses encryption mode)\n this.cipher.encrypt(this._inBlock, this._outBlock);\n\n // handle full block\n if(this._partialBytes === 0 && inputLength >= this.blockSize) {\n // XOR input with output\n for(var i = 0; i < this._ints; ++i) {\n output.putInt32(input.getInt32() ^ this._outBlock[i]);\n }\n } else {\n // handle partial block\n var partialBytes = (this.blockSize - inputLength) % this.blockSize;\n if(partialBytes > 0) {\n partialBytes = this.blockSize - partialBytes;\n }\n\n // XOR input with output\n this._partialOutput.clear();\n for(var i = 0; i < this._ints; ++i) {\n this._partialOutput.putInt32(input.getInt32() ^ this._outBlock[i]);\n }\n\n if(partialBytes > 0) {\n // block still incomplete, restore input buffer\n input.read -= this.blockSize;\n }\n\n // skip any previous partial bytes\n if(this._partialBytes > 0) {\n this._partialOutput.getBytes(this._partialBytes);\n }\n\n if(partialBytes > 0 && !finish) {\n output.putBytes(this._partialOutput.getBytes(\n partialBytes - this._partialBytes));\n this._partialBytes = partialBytes;\n return true;\n }\n\n output.putBytes(this._partialOutput.getBytes(\n inputLength - this._partialBytes));\n this._partialBytes = 0;\n }\n\n // block complete, increment counter (input block)\n inc32(this._inBlock);\n};\n\nmodes.ctr.prototype.decrypt = modes.ctr.prototype.encrypt;\n\n/** Galois/Counter Mode (GCM) **/\n\nmodes.gcm = function(options) {\n options = options || {};\n this.name = 'GCM';\n this.cipher = options.cipher;\n this.blockSize = options.blockSize || 16;\n this._ints = this.blockSize / 4;\n this._inBlock = new Array(this._ints);\n this._outBlock = new Array(this._ints);\n this._partialOutput = forge.util.createBuffer();\n this._partialBytes = 0;\n\n // R is actually this value concatenated with 120 more zero bits, but\n // we only XOR against R so the other zeros have no effect -- we just\n // apply this value to the first integer in a block\n this._R = 0xE1000000;\n};\n\nmodes.gcm.prototype.start = function(options) {\n if(!('iv' in options)) {\n throw new Error('Invalid IV parameter.');\n }\n // ensure IV is a byte buffer\n var iv = forge.util.createBuffer(options.iv);\n\n // no ciphered data processed yet\n this._cipherLength = 0;\n\n // default additional data is none\n var additionalData;\n if('additionalData' in options) {\n additionalData = forge.util.createBuffer(options.additionalData);\n } else {\n additionalData = forge.util.createBuffer();\n }\n\n // default tag length is 128 bits\n if('tagLength' in options) {\n this._tagLength = options.tagLength;\n } else {\n this._tagLength = 128;\n }\n\n // if tag is given, ensure tag matches tag length\n this._tag = null;\n if(options.decrypt) {\n // save tag to check later\n this._tag = forge.util.createBuffer(options.tag).getBytes();\n if(this._tag.length !== (this._tagLength / 8)) {\n throw new Error('Authentication tag does not match tag length.');\n }\n }\n\n // create tmp storage for hash calculation\n this._hashBlock = new Array(this._ints);\n\n // no tag generated yet\n this.tag = null;\n\n // generate hash subkey\n // (apply block cipher to \"zero\" block)\n this._hashSubkey = new Array(this._ints);\n this.cipher.encrypt([0, 0, 0, 0], this._hashSubkey);\n\n // generate table M\n // use 4-bit tables (32 component decomposition of a 16 byte value)\n // 8-bit tables take more space and are known to have security\n // vulnerabilities (in native implementations)\n this.componentBits = 4;\n this._m = this.generateHashTable(this._hashSubkey, this.componentBits);\n\n // Note: support IV length different from 96 bits? (only supporting\n // 96 bits is recommended by NIST SP-800-38D)\n // generate J_0\n var ivLength = iv.length();\n if(ivLength === 12) {\n // 96-bit IV\n this._j0 = [iv.getInt32(), iv.getInt32(), iv.getInt32(), 1];\n } else {\n // IV is NOT 96-bits\n this._j0 = [0, 0, 0, 0];\n while(iv.length() > 0) {\n this._j0 = this.ghash(\n this._hashSubkey, this._j0,\n [iv.getInt32(), iv.getInt32(), iv.getInt32(), iv.getInt32()]);\n }\n this._j0 = this.ghash(\n this._hashSubkey, this._j0, [0, 0].concat(from64To32(ivLength * 8)));\n }\n\n // generate ICB (initial counter block)\n this._inBlock = this._j0.slice(0);\n inc32(this._inBlock);\n this._partialBytes = 0;\n\n // consume authentication data\n additionalData = forge.util.createBuffer(additionalData);\n // save additional data length as a BE 64-bit number\n this._aDataLength = from64To32(additionalData.length() * 8);\n // pad additional data to 128 bit (16 byte) block size\n var overflow = additionalData.length() % this.blockSize;\n if(overflow) {\n additionalData.fillWithByte(0, this.blockSize - overflow);\n }\n this._s = [0, 0, 0, 0];\n while(additionalData.length() > 0) {\n this._s = this.ghash(this._hashSubkey, this._s, [\n additionalData.getInt32(),\n additionalData.getInt32(),\n additionalData.getInt32(),\n additionalData.getInt32()\n ]);\n }\n};\n\nmodes.gcm.prototype.encrypt = function(input, output, finish) {\n // not enough input to encrypt\n var inputLength = input.length();\n if(inputLength === 0) {\n return true;\n }\n\n // encrypt block\n this.cipher.encrypt(this._inBlock, this._outBlock);\n\n // handle full block\n if(this._partialBytes === 0 && inputLength >= this.blockSize) {\n // XOR input with output\n for(var i = 0; i < this._ints; ++i) {\n output.putInt32(this._outBlock[i] ^= input.getInt32());\n }\n this._cipherLength += this.blockSize;\n } else {\n // handle partial block\n var partialBytes = (this.blockSize - inputLength) % this.blockSize;\n if(partialBytes > 0) {\n partialBytes = this.blockSize - partialBytes;\n }\n\n // XOR input with output\n this._partialOutput.clear();\n for(var i = 0; i < this._ints; ++i) {\n this._partialOutput.putInt32(input.getInt32() ^ this._outBlock[i]);\n }\n\n if(partialBytes <= 0 || finish) {\n // handle overflow prior to hashing\n if(finish) {\n // get block overflow\n var overflow = inputLength % this.blockSize;\n this._cipherLength += overflow;\n // truncate for hash function\n this._partialOutput.truncate(this.blockSize - overflow);\n } else {\n this._cipherLength += this.blockSize;\n }\n\n // get output block for hashing\n for(var i = 0; i < this._ints; ++i) {\n this._outBlock[i] = this._partialOutput.getInt32();\n }\n this._partialOutput.read -= this.blockSize;\n }\n\n // skip any previous partial bytes\n if(this._partialBytes > 0) {\n this._partialOutput.getBytes(this._partialBytes);\n }\n\n if(partialBytes > 0 && !finish) {\n // block still incomplete, restore input buffer, get partial output,\n // and return early\n input.read -= this.blockSize;\n output.putBytes(this._partialOutput.getBytes(\n partialBytes - this._partialBytes));\n this._partialBytes = partialBytes;\n return true;\n }\n\n output.putBytes(this._partialOutput.getBytes(\n inputLength - this._partialBytes));\n this._partialBytes = 0;\n }\n\n // update hash block S\n this._s = this.ghash(this._hashSubkey, this._s, this._outBlock);\n\n // increment counter (input block)\n inc32(this._inBlock);\n};\n\nmodes.gcm.prototype.decrypt = function(input, output, finish) {\n // not enough input to decrypt\n var inputLength = input.length();\n if(inputLength < this.blockSize && !(finish && inputLength > 0)) {\n return true;\n }\n\n // encrypt block (GCM always uses encryption mode)\n this.cipher.encrypt(this._inBlock, this._outBlock);\n\n // increment counter (input block)\n inc32(this._inBlock);\n\n // update hash block S\n this._hashBlock[0] = input.getInt32();\n this._hashBlock[1] = input.getInt32();\n this._hashBlock[2] = input.getInt32();\n this._hashBlock[3] = input.getInt32();\n this._s = this.ghash(this._hashSubkey, this._s, this._hashBlock);\n\n // XOR hash input with output\n for(var i = 0; i < this._ints; ++i) {\n output.putInt32(this._outBlock[i] ^ this._hashBlock[i]);\n }\n\n // increment cipher data length\n if(inputLength < this.blockSize) {\n this._cipherLength += inputLength % this.blockSize;\n } else {\n this._cipherLength += this.blockSize;\n }\n};\n\nmodes.gcm.prototype.afterFinish = function(output, options) {\n var rval = true;\n\n // handle overflow\n if(options.decrypt && options.overflow) {\n output.truncate(this.blockSize - options.overflow);\n }\n\n // handle authentication tag\n this.tag = forge.util.createBuffer();\n\n // concatenate additional data length with cipher length\n var lengths = this._aDataLength.concat(from64To32(this._cipherLength * 8));\n\n // include lengths in hash\n this._s = this.ghash(this._hashSubkey, this._s, lengths);\n\n // do GCTR(J_0, S)\n var tag = [];\n this.cipher.encrypt(this._j0, tag);\n for(var i = 0; i < this._ints; ++i) {\n this.tag.putInt32(this._s[i] ^ tag[i]);\n }\n\n // trim tag to length\n this.tag.truncate(this.tag.length() % (this._tagLength / 8));\n\n // check authentication tag\n if(options.decrypt && this.tag.bytes() !== this._tag) {\n rval = false;\n }\n\n return rval;\n};\n\n/**\n * See NIST SP-800-38D 6.3 (Algorithm 1). This function performs Galois\n * field multiplication. The field, GF(2^128), is defined by the polynomial:\n *\n * x^128 + x^7 + x^2 + x + 1\n *\n * Which is represented in little-endian binary form as: 11100001 (0xe1). When\n * the value of a coefficient is 1, a bit is set. The value R, is the\n * concatenation of this value and 120 zero bits, yielding a 128-bit value\n * which matches the block size.\n *\n * This function will multiply two elements (vectors of bytes), X and Y, in\n * the field GF(2^128). The result is initialized to zero. For each bit of\n * X (out of 128), x_i, if x_i is set, then the result is multiplied (XOR'd)\n * by the current value of Y. For each bit, the value of Y will be raised by\n * a power of x (multiplied by the polynomial x). This can be achieved by\n * shifting Y once to the right. If the current value of Y, prior to being\n * multiplied by x, has 0 as its LSB, then it is a 127th degree polynomial.\n * Otherwise, we must divide by R after shifting to find the remainder.\n *\n * @param x the first block to multiply by the second.\n * @param y the second block to multiply by the first.\n *\n * @return the block result of the multiplication.\n */\nmodes.gcm.prototype.multiply = function(x, y) {\n var z_i = [0, 0, 0, 0];\n var v_i = y.slice(0);\n\n // calculate Z_128 (block has 128 bits)\n for(var i = 0; i < 128; ++i) {\n // if x_i is 0, Z_{i+1} = Z_i (unchanged)\n // else Z_{i+1} = Z_i ^ V_i\n // get x_i by finding 32-bit int position, then left shift 1 by remainder\n var x_i = x[(i / 32) | 0] & (1 << (31 - i % 32));\n if(x_i) {\n z_i[0] ^= v_i[0];\n z_i[1] ^= v_i[1];\n z_i[2] ^= v_i[2];\n z_i[3] ^= v_i[3];\n }\n\n // if LSB(V_i) is 1, V_i = V_i >> 1\n // else V_i = (V_i >> 1) ^ R\n this.pow(v_i, v_i);\n }\n\n return z_i;\n};\n\nmodes.gcm.prototype.pow = function(x, out) {\n // if LSB(x) is 1, x = x >>> 1\n // else x = (x >>> 1) ^ R\n var lsb = x[3] & 1;\n\n // always do x >>> 1:\n // starting with the rightmost integer, shift each integer to the right\n // one bit, pulling in the bit from the integer to the left as its top\n // most bit (do this for the last 3 integers)\n for(var i = 3; i > 0; --i) {\n out[i] = (x[i] >>> 1) | ((x[i - 1] & 1) << 31);\n }\n // shift the first integer normally\n out[0] = x[0] >>> 1;\n\n // if lsb was not set, then polynomial had a degree of 127 and doesn't\n // need to divided; otherwise, XOR with R to find the remainder; we only\n // need to XOR the first integer since R technically ends w/120 zero bits\n if(lsb) {\n out[0] ^= this._R;\n }\n};\n\nmodes.gcm.prototype.tableMultiply = function(x) {\n // assumes 4-bit tables are used\n var z = [0, 0, 0, 0];\n for(var i = 0; i < 32; ++i) {\n var idx = (i / 8) | 0;\n var x_i = (x[idx] >>> ((7 - (i % 8)) * 4)) & 0xF;\n var ah = this._m[i][x_i];\n z[0] ^= ah[0];\n z[1] ^= ah[1];\n z[2] ^= ah[2];\n z[3] ^= ah[3];\n }\n return z;\n};\n\n/**\n * A continuing version of the GHASH algorithm that operates on a single\n * block. The hash block, last hash value (Ym) and the new block to hash\n * are given.\n *\n * @param h the hash block.\n * @param y the previous value for Ym, use [0, 0, 0, 0] for a new hash.\n * @param x the block to hash.\n *\n * @return the hashed value (Ym).\n */\nmodes.gcm.prototype.ghash = function(h, y, x) {\n y[0] ^= x[0];\n y[1] ^= x[1];\n y[2] ^= x[2];\n y[3] ^= x[3];\n return this.tableMultiply(y);\n //return this.multiply(y, h);\n};\n\n/**\n * Precomputes a table for multiplying against the hash subkey. This\n * mechanism provides a substantial speed increase over multiplication\n * performed without a table. The table-based multiplication this table is\n * for solves X * H by multiplying each component of X by H and then\n * composing the results together using XOR.\n *\n * This function can be used to generate tables with different bit sizes\n * for the components, however, this implementation assumes there are\n * 32 components of X (which is a 16 byte vector), therefore each component\n * takes 4-bits (so the table is constructed with bits=4).\n *\n * @param h the hash subkey.\n * @param bits the bit size for a component.\n */\nmodes.gcm.prototype.generateHashTable = function(h, bits) {\n // TODO: There are further optimizations that would use only the\n // first table M_0 (or some variant) along with a remainder table;\n // this can be explored in the future\n var multiplier = 8 / bits;\n var perInt = 4 * multiplier;\n var size = 16 * multiplier;\n var m = new Array(size);\n for(var i = 0; i < size; ++i) {\n var tmp = [0, 0, 0, 0];\n var idx = (i / perInt) | 0;\n var shft = ((perInt - 1 - (i % perInt)) * bits);\n tmp[idx] = (1 << (bits - 1)) << shft;\n m[i] = this.generateSubHashTable(this.multiply(tmp, h), bits);\n }\n return m;\n};\n\n/**\n * Generates a table for multiplying against the hash subkey for one\n * particular component (out of all possible component values).\n *\n * @param mid the pre-multiplied value for the middle key of the table.\n * @param bits the bit size for a component.\n */\nmodes.gcm.prototype.generateSubHashTable = function(mid, bits) {\n // compute the table quickly by minimizing the number of\n // POW operations -- they only need to be performed for powers of 2,\n // all other entries can be composed from those powers using XOR\n var size = 1 << bits;\n var half = size >>> 1;\n var m = new Array(size);\n m[half] = mid.slice(0);\n var i = half >>> 1;\n while(i > 0) {\n // raise m0[2 * i] and store in m0[i]\n this.pow(m[2 * i], m[i] = []);\n i >>= 1;\n }\n i = 2;\n while(i < half) {\n for(var j = 1; j < i; ++j) {\n var m_i = m[i];\n var m_j = m[j];\n m[i + j] = [\n m_i[0] ^ m_j[0],\n m_i[1] ^ m_j[1],\n m_i[2] ^ m_j[2],\n m_i[3] ^ m_j[3]\n ];\n }\n i *= 2;\n }\n m[0] = [0, 0, 0, 0];\n /* Note: We could avoid storing these by doing composition during multiply\n calculate top half using composition by speed is preferred. */\n for(i = half + 1; i < size; ++i) {\n var c = m[i ^ half];\n m[i] = [mid[0] ^ c[0], mid[1] ^ c[1], mid[2] ^ c[2], mid[3] ^ c[3]];\n }\n return m;\n};\n\n/** Utility functions */\n\nfunction transformIV(iv, blockSize) {\n if(typeof iv === 'string') {\n // convert iv string into byte buffer\n iv = forge.util.createBuffer(iv);\n }\n\n if(forge.util.isArray(iv) && iv.length > 4) {\n // convert iv byte array into byte buffer\n var tmp = iv;\n iv = forge.util.createBuffer();\n for(var i = 0; i < tmp.length; ++i) {\n iv.putByte(tmp[i]);\n }\n }\n\n if(iv.length() < blockSize) {\n throw new Error(\n 'Invalid IV length; got ' + iv.length() +\n ' bytes and expected ' + blockSize + ' bytes.');\n }\n\n if(!forge.util.isArray(iv)) {\n // convert iv byte buffer into 32-bit integer array\n var ints = [];\n var blocks = blockSize / 4;\n for(var i = 0; i < blocks; ++i) {\n ints.push(iv.getInt32());\n }\n iv = ints;\n }\n\n return iv;\n}\n\nfunction inc32(block) {\n // increment last 32 bits of block only\n block[block.length - 1] = (block[block.length - 1] + 1) & 0xFFFFFFFF;\n}\n\nfunction from64To32(num) {\n // convert 64-bit number to two BE Int32s\n return [(num / 0x100000000) | 0, num & 0xFFFFFFFF];\n}\n","/**\n * DES (Data Encryption Standard) implementation.\n *\n * This implementation supports DES as well as 3DES-EDE in ECB and CBC mode.\n * It is based on the BSD-licensed implementation by Paul Tero:\n *\n * Paul Tero, July 2001\n * http://www.tero.co.uk/des/\n *\n * Optimised for performance with large blocks by\n * Michael Hayworth, November 2001\n * http://www.netdealing.com\n *\n * THIS SOFTWARE IS PROVIDED \"AS IS\" AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH DAMAGE.\n *\n * @author Stefan Siegl\n * @author Dave Longley\n *\n * Copyright (c) 2012 Stefan Siegl \n * Copyright (c) 2012-2014 Digital Bazaar, Inc.\n */\nvar forge = require('./forge');\nrequire('./cipher');\nrequire('./cipherModes');\nrequire('./util');\n\n/* DES API */\nmodule.exports = forge.des = forge.des || {};\n\n/**\n * Deprecated. Instead, use:\n *\n * var cipher = forge.cipher.createCipher('DES-', key);\n * cipher.start({iv: iv});\n *\n * Creates an DES cipher object to encrypt data using the given symmetric key.\n * The output will be stored in the 'output' member of the returned cipher.\n *\n * The key and iv may be given as binary-encoded strings of bytes or\n * byte buffers.\n *\n * @param key the symmetric key to use (64 or 192 bits).\n * @param iv the initialization vector to use.\n * @param output the buffer to write to, null to create one.\n * @param mode the cipher mode to use (default: 'CBC' if IV is\n * given, 'ECB' if null).\n *\n * @return the cipher.\n */\nforge.des.startEncrypting = function(key, iv, output, mode) {\n var cipher = _createCipher({\n key: key,\n output: output,\n decrypt: false,\n mode: mode || (iv === null ? 'ECB' : 'CBC')\n });\n cipher.start(iv);\n return cipher;\n};\n\n/**\n * Deprecated. Instead, use:\n *\n * var cipher = forge.cipher.createCipher('DES-', key);\n *\n * Creates an DES cipher object to encrypt data using the given symmetric key.\n *\n * The key may be given as a binary-encoded string of bytes or a byte buffer.\n *\n * @param key the symmetric key to use (64 or 192 bits).\n * @param mode the cipher mode to use (default: 'CBC').\n *\n * @return the cipher.\n */\nforge.des.createEncryptionCipher = function(key, mode) {\n return _createCipher({\n key: key,\n output: null,\n decrypt: false,\n mode: mode\n });\n};\n\n/**\n * Deprecated. Instead, use:\n *\n * var decipher = forge.cipher.createDecipher('DES-', key);\n * decipher.start({iv: iv});\n *\n * Creates an DES cipher object to decrypt data using the given symmetric key.\n * The output will be stored in the 'output' member of the returned cipher.\n *\n * The key and iv may be given as binary-encoded strings of bytes or\n * byte buffers.\n *\n * @param key the symmetric key to use (64 or 192 bits).\n * @param iv the initialization vector to use.\n * @param output the buffer to write to, null to create one.\n * @param mode the cipher mode to use (default: 'CBC' if IV is\n * given, 'ECB' if null).\n *\n * @return the cipher.\n */\nforge.des.startDecrypting = function(key, iv, output, mode) {\n var cipher = _createCipher({\n key: key,\n output: output,\n decrypt: true,\n mode: mode || (iv === null ? 'ECB' : 'CBC')\n });\n cipher.start(iv);\n return cipher;\n};\n\n/**\n * Deprecated. Instead, use:\n *\n * var decipher = forge.cipher.createDecipher('DES-', key);\n *\n * Creates an DES cipher object to decrypt data using the given symmetric key.\n *\n * The key may be given as a binary-encoded string of bytes or a byte buffer.\n *\n * @param key the symmetric key to use (64 or 192 bits).\n * @param mode the cipher mode to use (default: 'CBC').\n *\n * @return the cipher.\n */\nforge.des.createDecryptionCipher = function(key, mode) {\n return _createCipher({\n key: key,\n output: null,\n decrypt: true,\n mode: mode\n });\n};\n\n/**\n * Creates a new DES cipher algorithm object.\n *\n * @param name the name of the algorithm.\n * @param mode the mode factory function.\n *\n * @return the DES algorithm object.\n */\nforge.des.Algorithm = function(name, mode) {\n var self = this;\n self.name = name;\n self.mode = new mode({\n blockSize: 8,\n cipher: {\n encrypt: function(inBlock, outBlock) {\n return _updateBlock(self._keys, inBlock, outBlock, false);\n },\n decrypt: function(inBlock, outBlock) {\n return _updateBlock(self._keys, inBlock, outBlock, true);\n }\n }\n });\n self._init = false;\n};\n\n/**\n * Initializes this DES algorithm by expanding its key.\n *\n * @param options the options to use.\n * key the key to use with this algorithm.\n * decrypt true if the algorithm should be initialized for decryption,\n * false for encryption.\n */\nforge.des.Algorithm.prototype.initialize = function(options) {\n if(this._init) {\n return;\n }\n\n var key = forge.util.createBuffer(options.key);\n if(this.name.indexOf('3DES') === 0) {\n if(key.length() !== 24) {\n throw new Error('Invalid Triple-DES key size: ' + key.length() * 8);\n }\n }\n\n // do key expansion to 16 or 48 subkeys (single or triple DES)\n this._keys = _createKeys(key);\n this._init = true;\n};\n\n/** Register DES algorithms **/\n\nregisterAlgorithm('DES-ECB', forge.cipher.modes.ecb);\nregisterAlgorithm('DES-CBC', forge.cipher.modes.cbc);\nregisterAlgorithm('DES-CFB', forge.cipher.modes.cfb);\nregisterAlgorithm('DES-OFB', forge.cipher.modes.ofb);\nregisterAlgorithm('DES-CTR', forge.cipher.modes.ctr);\n\nregisterAlgorithm('3DES-ECB', forge.cipher.modes.ecb);\nregisterAlgorithm('3DES-CBC', forge.cipher.modes.cbc);\nregisterAlgorithm('3DES-CFB', forge.cipher.modes.cfb);\nregisterAlgorithm('3DES-OFB', forge.cipher.modes.ofb);\nregisterAlgorithm('3DES-CTR', forge.cipher.modes.ctr);\n\nfunction registerAlgorithm(name, mode) {\n var factory = function() {\n return new forge.des.Algorithm(name, mode);\n };\n forge.cipher.registerAlgorithm(name, factory);\n}\n\n/** DES implementation **/\n\nvar spfunction1 = [0x1010400,0,0x10000,0x1010404,0x1010004,0x10404,0x4,0x10000,0x400,0x1010400,0x1010404,0x400,0x1000404,0x1010004,0x1000000,0x4,0x404,0x1000400,0x1000400,0x10400,0x10400,0x1010000,0x1010000,0x1000404,0x10004,0x1000004,0x1000004,0x10004,0,0x404,0x10404,0x1000000,0x10000,0x1010404,0x4,0x1010000,0x1010400,0x1000000,0x1000000,0x400,0x1010004,0x10000,0x10400,0x1000004,0x400,0x4,0x1000404,0x10404,0x1010404,0x10004,0x1010000,0x1000404,0x1000004,0x404,0x10404,0x1010400,0x404,0x1000400,0x1000400,0,0x10004,0x10400,0,0x1010004];\nvar spfunction2 = [-0x7fef7fe0,-0x7fff8000,0x8000,0x108020,0x100000,0x20,-0x7fefffe0,-0x7fff7fe0,-0x7fffffe0,-0x7fef7fe0,-0x7fef8000,-0x80000000,-0x7fff8000,0x100000,0x20,-0x7fefffe0,0x108000,0x100020,-0x7fff7fe0,0,-0x80000000,0x8000,0x108020,-0x7ff00000,0x100020,-0x7fffffe0,0,0x108000,0x8020,-0x7fef8000,-0x7ff00000,0x8020,0,0x108020,-0x7fefffe0,0x100000,-0x7fff7fe0,-0x7ff00000,-0x7fef8000,0x8000,-0x7ff00000,-0x7fff8000,0x20,-0x7fef7fe0,0x108020,0x20,0x8000,-0x80000000,0x8020,-0x7fef8000,0x100000,-0x7fffffe0,0x100020,-0x7fff7fe0,-0x7fffffe0,0x100020,0x108000,0,-0x7fff8000,0x8020,-0x80000000,-0x7fefffe0,-0x7fef7fe0,0x108000];\nvar spfunction3 = [0x208,0x8020200,0,0x8020008,0x8000200,0,0x20208,0x8000200,0x20008,0x8000008,0x8000008,0x20000,0x8020208,0x20008,0x8020000,0x208,0x8000000,0x8,0x8020200,0x200,0x20200,0x8020000,0x8020008,0x20208,0x8000208,0x20200,0x20000,0x8000208,0x8,0x8020208,0x200,0x8000000,0x8020200,0x8000000,0x20008,0x208,0x20000,0x8020200,0x8000200,0,0x200,0x20008,0x8020208,0x8000200,0x8000008,0x200,0,0x8020008,0x8000208,0x20000,0x8000000,0x8020208,0x8,0x20208,0x20200,0x8000008,0x8020000,0x8000208,0x208,0x8020000,0x20208,0x8,0x8020008,0x20200];\nvar spfunction4 = [0x802001,0x2081,0x2081,0x80,0x802080,0x800081,0x800001,0x2001,0,0x802000,0x802000,0x802081,0x81,0,0x800080,0x800001,0x1,0x2000,0x800000,0x802001,0x80,0x800000,0x2001,0x2080,0x800081,0x1,0x2080,0x800080,0x2000,0x802080,0x802081,0x81,0x800080,0x800001,0x802000,0x802081,0x81,0,0,0x802000,0x2080,0x800080,0x800081,0x1,0x802001,0x2081,0x2081,0x80,0x802081,0x81,0x1,0x2000,0x800001,0x2001,0x802080,0x800081,0x2001,0x2080,0x800000,0x802001,0x80,0x800000,0x2000,0x802080];\nvar spfunction5 = [0x100,0x2080100,0x2080000,0x42000100,0x80000,0x100,0x40000000,0x2080000,0x40080100,0x80000,0x2000100,0x40080100,0x42000100,0x42080000,0x80100,0x40000000,0x2000000,0x40080000,0x40080000,0,0x40000100,0x42080100,0x42080100,0x2000100,0x42080000,0x40000100,0,0x42000000,0x2080100,0x2000000,0x42000000,0x80100,0x80000,0x42000100,0x100,0x2000000,0x40000000,0x2080000,0x42000100,0x40080100,0x2000100,0x40000000,0x42080000,0x2080100,0x40080100,0x100,0x2000000,0x42080000,0x42080100,0x80100,0x42000000,0x42080100,0x2080000,0,0x40080000,0x42000000,0x80100,0x2000100,0x40000100,0x80000,0,0x40080000,0x2080100,0x40000100];\nvar spfunction6 = [0x20000010,0x20400000,0x4000,0x20404010,0x20400000,0x10,0x20404010,0x400000,0x20004000,0x404010,0x400000,0x20000010,0x400010,0x20004000,0x20000000,0x4010,0,0x400010,0x20004010,0x4000,0x404000,0x20004010,0x10,0x20400010,0x20400010,0,0x404010,0x20404000,0x4010,0x404000,0x20404000,0x20000000,0x20004000,0x10,0x20400010,0x404000,0x20404010,0x400000,0x4010,0x20000010,0x400000,0x20004000,0x20000000,0x4010,0x20000010,0x20404010,0x404000,0x20400000,0x404010,0x20404000,0,0x20400010,0x10,0x4000,0x20400000,0x404010,0x4000,0x400010,0x20004010,0,0x20404000,0x20000000,0x400010,0x20004010];\nvar spfunction7 = [0x200000,0x4200002,0x4000802,0,0x800,0x4000802,0x200802,0x4200800,0x4200802,0x200000,0,0x4000002,0x2,0x4000000,0x4200002,0x802,0x4000800,0x200802,0x200002,0x4000800,0x4000002,0x4200000,0x4200800,0x200002,0x4200000,0x800,0x802,0x4200802,0x200800,0x2,0x4000000,0x200800,0x4000000,0x200800,0x200000,0x4000802,0x4000802,0x4200002,0x4200002,0x2,0x200002,0x4000000,0x4000800,0x200000,0x4200800,0x802,0x200802,0x4200800,0x802,0x4000002,0x4200802,0x4200000,0x200800,0,0x2,0x4200802,0,0x200802,0x4200000,0x800,0x4000002,0x4000800,0x800,0x200002];\nvar spfunction8 = [0x10001040,0x1000,0x40000,0x10041040,0x10000000,0x10001040,0x40,0x10000000,0x40040,0x10040000,0x10041040,0x41000,0x10041000,0x41040,0x1000,0x40,0x10040000,0x10000040,0x10001000,0x1040,0x41000,0x40040,0x10040040,0x10041000,0x1040,0,0,0x10040040,0x10000040,0x10001000,0x41040,0x40000,0x41040,0x40000,0x10041000,0x1000,0x40,0x10040040,0x1000,0x41040,0x10001000,0x40,0x10000040,0x10040000,0x10040040,0x10000000,0x40000,0x10001040,0,0x10041040,0x40040,0x10000040,0x10040000,0x10001000,0x10001040,0,0x10041040,0x41000,0x41000,0x1040,0x1040,0x40040,0x10000000,0x10041000];\n\n/**\n * Create necessary sub keys.\n *\n * @param key the 64-bit or 192-bit key.\n *\n * @return the expanded keys.\n */\nfunction _createKeys(key) {\n var pc2bytes0 = [0,0x4,0x20000000,0x20000004,0x10000,0x10004,0x20010000,0x20010004,0x200,0x204,0x20000200,0x20000204,0x10200,0x10204,0x20010200,0x20010204],\n pc2bytes1 = [0,0x1,0x100000,0x100001,0x4000000,0x4000001,0x4100000,0x4100001,0x100,0x101,0x100100,0x100101,0x4000100,0x4000101,0x4100100,0x4100101],\n pc2bytes2 = [0,0x8,0x800,0x808,0x1000000,0x1000008,0x1000800,0x1000808,0,0x8,0x800,0x808,0x1000000,0x1000008,0x1000800,0x1000808],\n pc2bytes3 = [0,0x200000,0x8000000,0x8200000,0x2000,0x202000,0x8002000,0x8202000,0x20000,0x220000,0x8020000,0x8220000,0x22000,0x222000,0x8022000,0x8222000],\n pc2bytes4 = [0,0x40000,0x10,0x40010,0,0x40000,0x10,0x40010,0x1000,0x41000,0x1010,0x41010,0x1000,0x41000,0x1010,0x41010],\n pc2bytes5 = [0,0x400,0x20,0x420,0,0x400,0x20,0x420,0x2000000,0x2000400,0x2000020,0x2000420,0x2000000,0x2000400,0x2000020,0x2000420],\n pc2bytes6 = [0,0x10000000,0x80000,0x10080000,0x2,0x10000002,0x80002,0x10080002,0,0x10000000,0x80000,0x10080000,0x2,0x10000002,0x80002,0x10080002],\n pc2bytes7 = [0,0x10000,0x800,0x10800,0x20000000,0x20010000,0x20000800,0x20010800,0x20000,0x30000,0x20800,0x30800,0x20020000,0x20030000,0x20020800,0x20030800],\n pc2bytes8 = [0,0x40000,0,0x40000,0x2,0x40002,0x2,0x40002,0x2000000,0x2040000,0x2000000,0x2040000,0x2000002,0x2040002,0x2000002,0x2040002],\n pc2bytes9 = [0,0x10000000,0x8,0x10000008,0,0x10000000,0x8,0x10000008,0x400,0x10000400,0x408,0x10000408,0x400,0x10000400,0x408,0x10000408],\n pc2bytes10 = [0,0x20,0,0x20,0x100000,0x100020,0x100000,0x100020,0x2000,0x2020,0x2000,0x2020,0x102000,0x102020,0x102000,0x102020],\n pc2bytes11 = [0,0x1000000,0x200,0x1000200,0x200000,0x1200000,0x200200,0x1200200,0x4000000,0x5000000,0x4000200,0x5000200,0x4200000,0x5200000,0x4200200,0x5200200],\n pc2bytes12 = [0,0x1000,0x8000000,0x8001000,0x80000,0x81000,0x8080000,0x8081000,0x10,0x1010,0x8000010,0x8001010,0x80010,0x81010,0x8080010,0x8081010],\n pc2bytes13 = [0,0x4,0x100,0x104,0,0x4,0x100,0x104,0x1,0x5,0x101,0x105,0x1,0x5,0x101,0x105];\n\n // how many iterations (1 for des, 3 for triple des)\n // changed by Paul 16/6/2007 to use Triple DES for 9+ byte keys\n var iterations = key.length() > 8 ? 3 : 1;\n\n // stores the return keys\n var keys = [];\n\n // now define the left shifts which need to be done\n var shifts = [0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0];\n\n var n = 0, tmp;\n for(var j = 0; j < iterations; j++) {\n var left = key.getInt32();\n var right = key.getInt32();\n\n tmp = ((left >>> 4) ^ right) & 0x0f0f0f0f;\n right ^= tmp;\n left ^= (tmp << 4);\n\n tmp = ((right >>> -16) ^ left) & 0x0000ffff;\n left ^= tmp;\n right ^= (tmp << -16);\n\n tmp = ((left >>> 2) ^ right) & 0x33333333;\n right ^= tmp;\n left ^= (tmp << 2);\n\n tmp = ((right >>> -16) ^ left) & 0x0000ffff;\n left ^= tmp;\n right ^= (tmp << -16);\n\n tmp = ((left >>> 1) ^ right) & 0x55555555;\n right ^= tmp;\n left ^= (tmp << 1);\n\n tmp = ((right >>> 8) ^ left) & 0x00ff00ff;\n left ^= tmp;\n right ^= (tmp << 8);\n\n tmp = ((left >>> 1) ^ right) & 0x55555555;\n right ^= tmp;\n left ^= (tmp << 1);\n\n // right needs to be shifted and OR'd with last four bits of left\n tmp = (left << 8) | ((right >>> 20) & 0x000000f0);\n\n // left needs to be put upside down\n left = ((right << 24) | ((right << 8) & 0xff0000) |\n ((right >>> 8) & 0xff00) | ((right >>> 24) & 0xf0));\n right = tmp;\n\n // now go through and perform these shifts on the left and right keys\n for(var i = 0; i < shifts.length; ++i) {\n //shift the keys either one or two bits to the left\n if(shifts[i]) {\n left = (left << 2) | (left >>> 26);\n right = (right << 2) | (right >>> 26);\n } else {\n left = (left << 1) | (left >>> 27);\n right = (right << 1) | (right >>> 27);\n }\n left &= -0xf;\n right &= -0xf;\n\n // now apply PC-2, in such a way that E is easier when encrypting or\n // decrypting this conversion will look like PC-2 except only the last 6\n // bits of each byte are used rather than 48 consecutive bits and the\n // order of lines will be according to how the S selection functions will\n // be applied: S2, S4, S6, S8, S1, S3, S5, S7\n var lefttmp = (\n pc2bytes0[left >>> 28] | pc2bytes1[(left >>> 24) & 0xf] |\n pc2bytes2[(left >>> 20) & 0xf] | pc2bytes3[(left >>> 16) & 0xf] |\n pc2bytes4[(left >>> 12) & 0xf] | pc2bytes5[(left >>> 8) & 0xf] |\n pc2bytes6[(left >>> 4) & 0xf]);\n var righttmp = (\n pc2bytes7[right >>> 28] | pc2bytes8[(right >>> 24) & 0xf] |\n pc2bytes9[(right >>> 20) & 0xf] | pc2bytes10[(right >>> 16) & 0xf] |\n pc2bytes11[(right >>> 12) & 0xf] | pc2bytes12[(right >>> 8) & 0xf] |\n pc2bytes13[(right >>> 4) & 0xf]);\n tmp = ((righttmp >>> 16) ^ lefttmp) & 0x0000ffff;\n keys[n++] = lefttmp ^ tmp;\n keys[n++] = righttmp ^ (tmp << 16);\n }\n }\n\n return keys;\n}\n\n/**\n * Updates a single block (1 byte) using DES. The update will either\n * encrypt or decrypt the block.\n *\n * @param keys the expanded keys.\n * @param input the input block (an array of 32-bit words).\n * @param output the updated output block.\n * @param decrypt true to decrypt the block, false to encrypt it.\n */\nfunction _updateBlock(keys, input, output, decrypt) {\n // set up loops for single or triple DES\n var iterations = keys.length === 32 ? 3 : 9;\n var looping;\n if(iterations === 3) {\n looping = decrypt ? [30, -2, -2] : [0, 32, 2];\n } else {\n looping = (decrypt ?\n [94, 62, -2, 32, 64, 2, 30, -2, -2] :\n [0, 32, 2, 62, 30, -2, 64, 96, 2]);\n }\n\n var tmp;\n\n var left = input[0];\n var right = input[1];\n\n // first each 64 bit chunk of the message must be permuted according to IP\n tmp = ((left >>> 4) ^ right) & 0x0f0f0f0f;\n right ^= tmp;\n left ^= (tmp << 4);\n\n tmp = ((left >>> 16) ^ right) & 0x0000ffff;\n right ^= tmp;\n left ^= (tmp << 16);\n\n tmp = ((right >>> 2) ^ left) & 0x33333333;\n left ^= tmp;\n right ^= (tmp << 2);\n\n tmp = ((right >>> 8) ^ left) & 0x00ff00ff;\n left ^= tmp;\n right ^= (tmp << 8);\n\n tmp = ((left >>> 1) ^ right) & 0x55555555;\n right ^= tmp;\n left ^= (tmp << 1);\n\n // rotate left 1 bit\n left = ((left << 1) | (left >>> 31));\n right = ((right << 1) | (right >>> 31));\n\n for(var j = 0; j < iterations; j += 3) {\n var endloop = looping[j + 1];\n var loopinc = looping[j + 2];\n\n // now go through and perform the encryption or decryption\n for(var i = looping[j]; i != endloop; i += loopinc) {\n var right1 = right ^ keys[i];\n var right2 = ((right >>> 4) | (right << 28)) ^ keys[i + 1];\n\n // passing these bytes through the S selection functions\n tmp = left;\n left = right;\n right = tmp ^ (\n spfunction2[(right1 >>> 24) & 0x3f] |\n spfunction4[(right1 >>> 16) & 0x3f] |\n spfunction6[(right1 >>> 8) & 0x3f] |\n spfunction8[right1 & 0x3f] |\n spfunction1[(right2 >>> 24) & 0x3f] |\n spfunction3[(right2 >>> 16) & 0x3f] |\n spfunction5[(right2 >>> 8) & 0x3f] |\n spfunction7[right2 & 0x3f]);\n }\n // unreverse left and right\n tmp = left;\n left = right;\n right = tmp;\n }\n\n // rotate right 1 bit\n left = ((left >>> 1) | (left << 31));\n right = ((right >>> 1) | (right << 31));\n\n // now perform IP-1, which is IP in the opposite direction\n tmp = ((left >>> 1) ^ right) & 0x55555555;\n right ^= tmp;\n left ^= (tmp << 1);\n\n tmp = ((right >>> 8) ^ left) & 0x00ff00ff;\n left ^= tmp;\n right ^= (tmp << 8);\n\n tmp = ((right >>> 2) ^ left) & 0x33333333;\n left ^= tmp;\n right ^= (tmp << 2);\n\n tmp = ((left >>> 16) ^ right) & 0x0000ffff;\n right ^= tmp;\n left ^= (tmp << 16);\n\n tmp = ((left >>> 4) ^ right) & 0x0f0f0f0f;\n right ^= tmp;\n left ^= (tmp << 4);\n\n output[0] = left;\n output[1] = right;\n}\n\n/**\n * Deprecated. Instead, use:\n *\n * forge.cipher.createCipher('DES-', key);\n * forge.cipher.createDecipher('DES-', key);\n *\n * Creates a deprecated DES cipher object. This object's mode will default to\n * CBC (cipher-block-chaining).\n *\n * The key may be given as a binary-encoded string of bytes or a byte buffer.\n *\n * @param options the options to use.\n * key the symmetric key to use (64 or 192 bits).\n * output the buffer to write to.\n * decrypt true for decryption, false for encryption.\n * mode the cipher mode to use (default: 'CBC').\n *\n * @return the cipher.\n */\nfunction _createCipher(options) {\n options = options || {};\n var mode = (options.mode || 'CBC').toUpperCase();\n var algorithm = 'DES-' + mode;\n\n var cipher;\n if(options.decrypt) {\n cipher = forge.cipher.createDecipher(algorithm, options.key);\n } else {\n cipher = forge.cipher.createCipher(algorithm, options.key);\n }\n\n // backwards compatible start API\n var start = cipher.start;\n cipher.start = function(iv, options) {\n // backwards compatibility: support second arg as output buffer\n var output = null;\n if(options instanceof forge.util.ByteBuffer) {\n output = options;\n options = {};\n }\n options = options || {};\n options.output = output;\n options.iv = iv;\n start.call(cipher, options);\n };\n\n return cipher;\n}\n","import { urlAlphabet as scopedUrlAlphabet } from './url-alphabet/index.js'\nexport { urlAlphabet } from './url-alphabet/index.js'\nexport let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))\nexport let customRandom = (alphabet, defaultSize, getRandom) => {\n let mask = (2 << Math.log2(alphabet.length - 1)) - 1\n let step = -~((1.6 * mask * defaultSize) / alphabet.length)\n return (size = defaultSize) => {\n let id = ''\n while (true) {\n let bytes = getRandom(step)\n let j = step | 0\n while (j--) {\n id += alphabet[bytes[j] & mask] || ''\n if (id.length >= size) return id\n }\n }\n }\n}\nexport let customAlphabet = (alphabet, size = 21) =>\n customRandom(alphabet, size | 0, random)\nexport let nanoid = (size = 21) => {\n let id = ''\n let bytes = crypto.getRandomValues(new Uint8Array((size |= 0)))\n while (size--) {\n id += scopedUrlAlphabet[bytes[size] & 63]\n }\n return id\n}\n","export const urlAlphabet =\n 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'\n"],"names":[],"sourceRoot":""}