UNPKG

250 kBSource Map (JSON)View Raw
1{"version":3,"sources":["webpack:///webpack/bootstrap 0874b6e0c4104637981f","webpack:///./src/proteus/errors/DontCallConstructor.js","webpack:///./src/proteus/util/TypeUtil.js","webpack:///external \"CBOR\"","webpack:///./src/proteus/util/ClassUtil.js","webpack:///./src/proteus/keys/PublicKey.js","webpack:///external \"sodium\"","webpack:///./src/proteus/errors/ProteusError.js","webpack:///./src/proteus/keys/KeyPair.js","webpack:///./src/proteus/keys/IdentityKey.js","webpack:///./src/proteus/message/HeaderMessage.js","webpack:///./src/proteus/errors/DecryptError.js","webpack:///./src/proteus/keys/IdentityKeyPair.js","webpack:///./src/proteus/message/Message.js","webpack:///./src/proteus/message/PreKeyMessage.js","webpack:///./src/proteus/message/Envelope.js","webpack:///./src/proteus/derived/MacKey.js","webpack:///./src/proteus/util/MemoryUtil.js","webpack:///./src/proteus/derived/HeadKey.js","webpack:///./src/proteus/session/ChainKey.js","webpack:///./src/proteus/errors/DecodeError.js","webpack:///./src/proteus/errors/InputError.js","webpack:///./node_modules/ed2curve/ed2curve.js","webpack:///./src/proteus/keys/SecretKey.js","webpack:///./src/proteus/keys/PreKeyBundle.js","webpack:///./src/proteus/keys/PreKey.js","webpack:///./src/proteus/message/Header.js","webpack:///./src/proteus/derived/DerivedSecrets.js","webpack:///./src/proteus/derived/CipherKey.js","webpack:///./src/proteus/keys/PreKeyAuth.js","webpack:///./src/proteus/session/PreKeyStore.js","webpack:///./src/proteus/session/Session.js","webpack:///./src/proteus/util/ArrayUtil.js","webpack:///./src/proteus/session/MessageKeys.js","webpack:///./src/proteus.js","webpack:///./node_modules/tweetnacl/nacl-fast.js","webpack:///crypto (ignored)","webpack:///./src/proteus/session/SessionState.js","webpack:///./src/proteus/util/KeyDerivationUtil.js","webpack:///./src/proteus/session/RecvChain.js","webpack:///./src/proteus/session/RootKey.js","webpack:///./src/proteus/session/SendChain.js"],"names":[],"mappings":";;;AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAK;AACL;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;AAEA;AACA;;;;;;;;AC7DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,aAAa,oBAAoB;AACjC;AACA;AACA;;AAEA;AACA;AACA;AACA,wBAAwB,gCAAgC,UAAU,gCAAgC;AAClG;AACA;;AAEA;AACA,CAAC;;AAED;;;;;;;;ACxDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA,aAAa,EAAE;AACf,aAAa,EAAE;AACf,eAAe;AACf,cAAc;AACd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,+CAA+C,OAAO;AACtD;AACA,wDAAwD,YAAY,SAAS,sBAAsB;AACnG;AACA,sDAAsD,YAAY,SAAS,aAAa;AACxF,GAAG;AACH;AACA,aAAa,EAAE;AACf,eAAe;AACf,cAAc;AACd;AACA;AACA;AACA;AACA;AACA;AACA,+DAA+D,sBAAsB;AACrF;AACA,6DAA6D,aAAa;AAC1E,GAAG;AACH;;AAEA;;;;;;;AC7DA,sB;;;;;;;ACAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA,aAAa,EAAE;AACf,eAAe;AACf;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA,GAAG;AACH;;AAEA;;;;;;;;AC1CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,YAAY;AACzB,aAAa,YAAY;AACzB,eAAe,UAAU;AACzB;AACA;AACA;AACA;;AAEA,eAAe,UAAU;AACzB;;AAEA,eAAe,WAAW;AAC1B;AACA,eAAe,WAAW;AAC1B;AACA;AACA;;AAEA;AACA;AACA;AACA,aAAa,YAAY;AACzB,aAAa,QAAQ;AACrB,eAAe,QAAQ;AACvB;AACA;AACA;AACA;AACA;;AAEA,gBAAgB,OAAO;AACvB;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;;;;;;;ACjHA,wB;;;;;;;ACAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA,WAAW,QAAQ;AACnB,WAAW,OAAO;AAClB;AACA,aAAa,aAAa;AAC1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,CAAC;;AAED;;;;;;;;ACnDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA,gBAAgB,QAAQ;AACxB;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,aAAa,YAAY;AACzB,eAAe,eAAe;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,eAAe,OAAO;AACtB,aAAa,YAAY;AACzB,aAAa,YAAY;AACzB,aAAa,QAAQ;AACrB;AACA;AACA,aAAa,mBAAmB;AAChC;AACA,eAAe,eAAe;AAC9B;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;;;;;;;;AClIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,WAAW;AACxB,eAAe,YAAY;AAC3B;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA,gBAAgB,OAAO;AACvB;AACA;AACA;;AAEA,gBAAgB,OAAO;AACvB;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;;;;;;;ACnGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,YAAY;AACzB,aAAa,YAAY;AACzB,eAAe,cAAc;AAC7B;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA,yBAAyB,qBAAqB;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;;;;;;;ACnHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB;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,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;;AAED;;;;;;;;ACzKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA,gBAAgB,gBAAgB;AAChC;AACA;;AAEA,eAAe,gBAAgB;AAC/B;AACA;AACA;AACA;;AAEA;AACA;;AAEA,gBAAgB,YAAY;AAC5B;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,aAAa;AAC1B,eAAe;AACf;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;;;;;;;ACzHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA,gBAAgB,YAAY;AAC5B;AACA;AACA;AACA;AACA,KAAK;AACL;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;;AAEA;AACA,aAAa,aAAa;AAC1B,eAAe;AACf;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;;;;;;;AC/EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,QAAQ;AACrB,aAAa,gBAAgB;AAC7B,aAAa,kBAAkB;AAC/B,aAAa,uBAAuB;AACpC,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;;;;;;;AC1HA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,gBAAgB;AAC7B,aAAa,iBAAiB;AAC9B,eAAe;AACf;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,aAAa,gBAAgB;AAC7B,eAAe;AACf;AACA;AACA;AACA;AACA;;AAEA,gBAAgB,YAAY;AAC5B;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,aAAa;AAC1B,eAAe;AACf;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,yBAAyB,qBAAqB;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;;;;;;;;AC7JA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,YAAY;AACzB,eAAe,OAAO;AACtB;AACA;AACA;;AAEA;AACA,eAAe,WAAW;AAC1B;AACA;AACA;;AAEA;AACA;AACA,aAAa,qBAAqB;AAClC,eAAe;AACf;AACA;AACA;AACA;;AAEA;AACA;AACA,aAAa,YAAY;AACzB,aAAa,YAAY;AACzB,eAAe;AACf;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;;;;;;;ACzGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA,aAAa,iCAAiC;AAC9C,eAAe;AACf;AACA;AACA;AACA;AACA,KAAK;AACL;AACA,KAAK;AACL;AACA;AACA,GAAG;AACH;;AAEA;;;;;;;;ACzCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,YAAY;AACzB,eAAe,QAAQ;AACvB;AACA;AACA;;AAEA;AACA,eAAe,WAAW;AAC1B;AACA;AACA;;AAEA;AACA,aAAa,QAAQ;AACrB,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,aAAa;AAC1B,aAAa,YAAY;AACzB,eAAe,WAAW;AAC1B;AACA;AACA;;AAEA;AACA;;AAEA;AACA,aAAa,YAAY;AACzB,aAAa,YAAY;AACzB,eAAe;AACf;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;;;;;;;ACnHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,gBAAgB;AAC7B,aAAa,QAAQ;AACrB,eAAe;AACf;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,gBAAgB,SAAS;AACzB;AACA;AACA;AACA;AACA;AACA;;AAEA,gBAAgB,oBAAoB;AACpC;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;;;;;;;;AClHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,aAAa;AACb;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,CAAC;;AAED;;;;;;;;AC1FA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,aAAa;AACb;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,WAAW,OAAO;AAClB,WAAW,OAAO;AAClB,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,CAAC;;AAED;;;;;;;AC5EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD;AACA;;AAEA;;AAEA;AACA;AACA,yBAAyB,iBAAiB;AAC1C;AACA;;AAEA;AACA;AACA;AACA;;;;AAIA;AACA;AACA;AACA,eAAe,QAAQ;AACvB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,mBAAmB,QAAQ;AAC3B;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,eAAe,QAAQ;AACvB;AACA;;AAEA;AACA;AACA;AACA,eAAe,QAAQ;AACvB;;AAEA;AACA;AACA;AACA,eAAe,QAAQ;AACvB;;AAEA;AACA;AACA;AACA,eAAe,QAAQ;AACvB,eAAe,QAAQ;AACvB,iBAAiB,QAAQ;AACzB;AACA;AACA;AACA,eAAe,QAAQ;AACvB;AACA;AACA,eAAe,QAAQ;AACvB;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,eAAe,QAAQ;AACvB,iBAAiB,QAAQ;AACzB;AACA;AACA;AACA,eAAe,QAAQ;AACvB;;AAEA;AACA;AACA;AACA,eAAe,QAAQ;AACvB;AACA;AACA;AACA,eAAe,OAAO;AACtB;AACA,iBAAiB,QAAQ;AACzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,QAAQ;AACvB;AACA;AACA;AACA;;;AAGA;AACA;AACA;AACA;AACA;;;;AAIA;AACA;AACA,eAAe,OAAO;AACtB;AACA;;;AAGA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;;AAGA;AACA;AACA;AACA,eAAe,QAAQ;AACvB,iBAAiB,QAAQ;AACzB;AACA;AACA;AACA,eAAe,QAAQ;AACvB;;AAEA;AACA;AACA,eAAe,QAAQ;AACvB;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,sCAAsC;;AAEtC;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,QAAQ;AACvB,eAAe,QAAQ;AACvB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,CAAC;;;;;;;;ACjQD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,YAAY;AACzB,aAAa,YAAY;AACzB,eAAe,UAAU;AACzB;AACA;AACA;AACA;;AAEA;;AAEA,eAAe,WAAW;AAC1B;AACA,eAAe,WAAW;AAC1B;AACA;AACA;;AAEA;AACA;AACA,aAAa,QAAQ;AACrB,eAAe,WAAW;AAC1B;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,aAAa,gBAAgB;AAC7B,eAAe,WAAW;AAC1B;AACA;AACA;;AAEA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;;;;;;;;ACrHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,kBAAkB;AAC/B,aAAa,aAAa;AAC1B,eAAe,aAAa;AAC5B;AACA;AACA;AACA;;AAEA,eAAe,mBAAmB;AAClC;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA,aAAa,sBAAsB;AACnC,aAAa,aAAa;AAC1B,eAAe;AACf;AACA;AACA;AACA;;AAEA,eAAe,eAAe;AAC9B;AACA,eAAe,WAAW;AAC1B;;AAEA,eAAe,mBAAmB;AAClC;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA,gBAAgB,gBAAgB;AAChC;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,gBAAgB,YAAY;AAC5B;AACA;AACA;AACA;AACA;;AAEA;AACA,eAAe,OAAO;AACtB,gBAAgB,OAAO;AACvB,gBAAgB,OAAO;AACvB;AACA,gBAAgB,qBAAqB;AACrC;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,aAAa;AAC1B,eAAe;AACf;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;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;;AAEA;;;;;;;;ACvMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA,aAAa,OAAO;AACpB;AACA;AACA;;AAEA;AACA,aAAa,QAAQ;AACrB,eAAe,OAAO;AACtB,cAAc;AACd;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA,oCAAoC,WAAW,sCAAsC,qBAAqB;AAC1G;AACA;AACA;;AAEA,gBAAgB,OAAO;AACvB;AACA;AACA;;AAEA;AACA,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,eAAe;AACf,cAAc;AACd;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA,gBAAgB,YAAY;AAC5B;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,aAAa;AAC1B,eAAe;AACf;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;;;;;;;AChKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,aAAa,gBAAgB;AAC7B,eAAe,OAAO;AACtB;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA,gBAAgB,YAAY;AAC5B;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,aAAa;AAC1B,eAAe;AACf;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;;;;;;;AC9HA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,eAAe;AAC5B,aAAa,YAAY;AACzB,aAAa,QAAQ;AACrB,eAAe,eAAe;AAC9B;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA,eAAe,kBAAkB;AACjC;AACA,eAAe,eAAe;AAC9B;AACA,eAAe,gBAAgB;AAC/B;AACA,eAAe,gBAAgB;AAC/B;AACA;AACA;;AAEA;AACA,aAAa,eAAe;AAC5B,aAAa,YAAY;AACzB,aAAa,QAAQ;AACrB,eAAe,eAAe;AAC9B;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA,eAAe,kBAAkB;AACjC;AACA,eAAe,eAAe;AAC9B;AACA,eAAe,gBAAgB;AAC/B;AACA;AACA;;AAEA;AACA,aAAa,eAAe;AAC5B,aAAa,QAAQ;AACrB,eAAe;AACf;AACA;AACA;AACA;AACA;;AAEA;;;;;;;;AC5GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,YAAY;AACzB,eAAe,UAAU;AACzB;AACA;AACA;;AAEA;AACA,eAAe,WAAW;AAC1B;AACA;AACA;;AAEA;AACA,aAAa,iCAAiC;AAC9C,aAAa,YAAY;AACzB,eAAe,WAAW;AAC1B;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA,aAAa,YAAY;AACzB,aAAa,YAAY;AACzB,eAAe;AACf;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;;;;;;;AC5GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;;AAEA,aAAa,OAAO;AACpB;AACA;AACA;;AAEA,aAAa,OAAO;AACpB;AACA;AACA;;AAEA,aAAa,OAAO;AACpB;AACA;AACA;AACA;;AAEA;;;;;;;;AC1CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA,WAAW,cAAc;AACzB;;AAEA;AACA,WAAW,QAAQ;AACnB,aAAa;AACb,YAAY;AACZ;AACA;AACA;AACA;;AAEA;AACA,WAAW,QAAQ;AACnB,aAAa;AACb,YAAY;AACZ;AACA;AACA;AACA;;AAEA;;;;;;;;AChDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA,aAAa,OAAO;AACpB;AACA;AACA;;AAEA,aAAa,OAAO;AACpB;AACA;AACA;;AAEA;AACA,aAAa,sBAAsB;AACnC,aAAa,mBAAmB;AAChC,eAAe;AACf;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,KAAK;AACL;;AAEA;AACA,aAAa,sBAAsB;AACnC,aAAa,qBAAqB;AAClC,aAAa,kBAAkB;AAC/B,eAAe;AACf,cAAc;AACd,cAAc;AACd;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA,SAAS;AACT;AACA;AACA;AACA;AACA,OAAO;;AAEP;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA,+EAA+E,cAAc;AAC7F,WAAW;AACX,SAAS;AACT;AACA;AACA,OAAO;AACP,KAAK;AACL;;AAEA;AACA,aAAa,qBAAqB;AAClC,aAAa,uBAAuB;AACpC,eAAe;AACf;AACA,cAAc;AACd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA,aAAa,sBAAsB;AACnC,eAAe;AACf;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA,gBAAgB,eAAe;AAC/B;AACA;AACA;;AAEA;AACA,aAAa,qBAAqB;AAClC,aAAa,OAAO;AACpB,cAAc,0BAA0B;AACxC;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA,aAAa,qBAAqB;AAClC,aAAa,kBAAkB;AAC/B,eAAe;AACf,cAAc;AACd;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,OAAO;AACP;AACA;AACA;AACA,qEAAqE,qBAAqB,mBAAmB,mBAAmB;AAChI;AACA;AACA;AACA,OAAO;AACP;AACA;AACA,KAAK;AACL;;AAEA;AACA,aAAa,kBAAkB;AAC/B,aAAa,iBAAiB;AAC9B,aAAa,qBAAqB;AAClC;AACA,eAAe;AACf,cAAc;AACd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA,SAAS;AACT;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA,WAAW;AACX;;AAEA;AACA,KAAK;AACL;;AAEA;AACA,aAAa,kBAAkB;AAC/B,aAAa,iBAAiB;AAC9B,aAAa,QAAQ;AACrB;AACA,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA,aAAa,kBAAkB;AAC/B,aAAa,iBAAiB;AAC9B,aAAa,OAAO;AACpB;AACA,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;;AAEA;AACA;;AAEA;AACA,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,sBAAsB;AACnC,aAAa,aAAa;AAC1B,eAAe;AACf;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,aAAa,sBAAsB;AACnC,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;;AAEA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,6BAA6B,QAAQ;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;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;;;;;;;;AC7eA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA,aAAa,oBAAoB;AACjC,eAAe;AACf;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL,GAAG;;AAEH;AACA,aAAa,4BAA4B;AACzC,eAAe;AACf,cAAc;AACd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,GAAG;AACH;;AAEA;;;;;;;;ACjEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,mBAAmB;AAChC,aAAa,gBAAgB;AAC7B,aAAa,QAAQ;AACrB,eAAe,YAAY;AAC3B;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,qBAAqB;AAClC,eAAe;AACf;AACA;AACA;AACA;;AAEA;AACA,aAAa,YAAY;AACzB,eAAe;AACf;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;;;;;;;ACrIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA,GAAG;AACH;;;;;;;ACpDA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,uBAAuB,iBAAiB;AACxC;AACA;;AAEA;AACA,wCAAwC,4BAA4B;;AAEpE;AACA,4BAA4B;;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,aAAa,OAAO;AACpB;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA,iBAAiB,QAAQ;AACzB;AACA;AACA;AACA;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;;AAEA;AACA;AACA;AACA;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;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;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;;AAEA;AACA;AACA;;AAEA,iBAAiB,QAAQ;AACzB;AACA;AACA;AACA;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;;AAEA;AACA;AACA;AACA;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;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,OAAO;AACpB;AACA;AACA,eAAe,QAAQ;AACvB;AACA,eAAe,QAAQ;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO;AACtB;AACA;AACA;;AAEA;AACA;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,OAAO;AACpB;AACA;AACA,eAAe,QAAQ;AACvB;AACA,eAAe,QAAQ;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO;AACtB;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,iBAAiB,OAAO;AACxB;AACA;;AAEA;AACA;AACA;AACA;AACA,iBAAiB,OAAO;AACxB;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA,8CAA8C;AAC9C,8CAA8C;AAC9C,8CAA8C;AAC9C,8CAA8C;AAC9C,8CAA8C;AAC9C;AACA,8CAA8C;AAC9C,8CAA8C;AAC9C,8CAA8C;AAC9C;;AAEA;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;;AAEA;AACA,sDAAsD;AACtD,sDAAsD;AACtD,sDAAsD;AACtD,sDAAsD;AACtD,sDAAsD;AACtD;AACA,sDAAsD;AACtD,sDAAsD;AACtD,sDAAsD;AACtD;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB;AACpB;AACA;AACA;AACA;AACA;AACA,qBAAqB;;AAErB;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB;AACpB;AACA;AACA;AACA;AACA;AACA,qBAAqB;;AAErB;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB;AACpB;AACA;AACA;AACA;AACA;AACA,qBAAqB;;AAErB;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB;AACpB;AACA;AACA;AACA;AACA;AACA,qBAAqB;;AAErB;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB;AACpB;AACA;AACA;AACA;AACA;AACA,qBAAqB;;AAErB;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB;AACpB;AACA;AACA;AACA;AACA;AACA,qBAAqB;;AAErB;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB;AACpB;AACA;AACA;AACA;AACA;AACA,qBAAqB;;AAErB;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB;AACpB;AACA;AACA;AACA;AACA;AACA,qBAAqB;;AAErB;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB;AACpB;AACA;AACA;AACA;AACA;AACA,qBAAqB;;AAErB;AACA;AACA;AACA;AACA;AACA;AACA,oBAAoB;AACpB;AACA;AACA;AACA;AACA;AACA,qBAAqB;;AAErB;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;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA,UAAU,QAAQ;AAClB;AACA;AACA;;AAEA;AACA;AACA,aAAa,QAAQ;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,aAAa,QAAQ;AACrB;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,QAAQ;AACrB;AACA,aAAa,QAAQ;;AAErB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,aAAa,OAAO;AACpB;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA,eAAe,UAAU;AACzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,eAAe,WAAW;AAC1B;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB;AACA;;AAEA;AACA;AACA,aAAa,QAAQ;AACrB;;AAEA;AACA;AACA,aAAa,QAAQ;AACrB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,iBAAiB,QAAQ;AACzB;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,aAAa,QAAQ;AACrB;AACA;AACA;AACA,aAAa,OAAO;AACpB;AACA,eAAe,QAAQ;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,aAAa,QAAQ;AACrB;AACA;;AAEA;AACA,iBAAiB,QAAQ;AACzB;;AAEA;AACA,iBAAiB,QAAQ;AACzB;;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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;;AAEA;AACA;AACA,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD;;AAEA;AACA;AACA,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD,sBAAsB,2BAA2B;AACjD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA,aAAa,QAAQ;AACrB,eAAe,QAAQ;AACvB;AACA;AACA;AACA,aAAa,QAAQ;AACrB;;AAEA;AACA;AACA;AACA,aAAa,QAAQ;AACrB,eAAe,QAAQ;AACvB;AACA;AACA;AACA,aAAa,QAAQ;AACrB;;AAEA;AACA;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB;AACA;AACA;AACA,aAAa,QAAQ;AACrB;AACA;AACA;AACA;AACA,aAAa,MAAM;AACnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;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;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;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,eAAe,QAAQ;AACvB;AACA;AACA;AACA;AACA,eAAe,QAAQ;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA,qBAAqB;AACrB,qBAAqB;;AAErB;AACA;AACA;;AAEA,sBAAsB;AACtB,sBAAsB;;AAEtB;AACA;AACA;;AAEA,sBAAsB;AACtB,sBAAsB;;AAEtB;AACA;AACA;;AAEA,sBAAsB;AACtB,sBAAsB;;AAEtB;AACA;AACA;;AAEA,sBAAsB;AACtB,sBAAsB;;AAEtB;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA,qBAAqB;AACrB,qBAAqB;;AAErB;AACA;AACA;;AAEA,sBAAsB;AACtB,sBAAsB;;AAEtB;AACA;AACA;;AAEA,sBAAsB;AACtB,sBAAsB;;AAEtB;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA,qBAAqB;AACrB,qBAAqB;;AAErB;AACA;;AAEA,sBAAsB;AACtB,sBAAsB;;AAEtB;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,mBAAmB,QAAQ;AAC3B;AACA;AACA;;AAEA,yBAAyB;AACzB,yBAAyB;;AAEzB;AACA;;AAEA,0BAA0B;AAC1B,0BAA0B;;AAE1B;AACA;AACA;AACA;AACA;;AAEA,0BAA0B;AAC1B,0BAA0B;;AAE1B;AACA;AACA;AACA;AACA;;AAEA,0BAA0B;AAC1B,0BAA0B;;AAE1B;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA,mBAAmB;AACnB,mBAAmB;;AAEnB;AACA;;AAEA,oBAAoB;AACpB,oBAAoB;;AAEpB;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA,mBAAmB;AACnB,mBAAmB;;AAEnB;AACA;;AAEA,oBAAoB;AACpB,oBAAoB;;AAEpB;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA,mBAAmB;AACnB,mBAAmB;;AAEnB;AACA;;AAEA,oBAAoB;AACpB,oBAAoB;;AAEpB;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA,mBAAmB;AACnB,mBAAmB;;AAEnB;AACA;;AAEA,oBAAoB;AACpB,oBAAoB;;AAEpB;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA,mBAAmB;AACnB,mBAAmB;;AAEnB;AACA;;AAEA,oBAAoB;AACpB,oBAAoB;;AAEpB;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA,mBAAmB;AACnB,mBAAmB;;AAEnB;AACA;;AAEA,oBAAoB;AACpB,oBAAoB;;AAEpB;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA,mBAAmB;AACnB,mBAAmB;;AAEnB;AACA;;AAEA,oBAAoB;AACpB,oBAAoB;;AAEpB;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA,mBAAmB;AACnB,mBAAmB;;AAEnB;AACA;;AAEA,oBAAoB;AACpB,oBAAoB;;AAEpB;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA,aAAa,OAAO;AACpB;;AAEA;AACA;AACA;AACA;;AAEA,aAAa,OAAO;;AAEpB;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,aAAa,OAAO;AACpB;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,QAAQ;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA,aAAa,QAAQ;AACrB;AACA;;AAEA;;AAEA;AACA;AACA,cAAc,SAAS;AACvB;AACA,gCAAgC,OAAO;AACvC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB;AACA;AACA;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB;AACA;AACA;AACA;;AAEA;AACA;AACA,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,aAAa,OAAO;AACpB,aAAa,QAAQ;;AAErB;AACA;AACA;AACA;;AAEA,cAAc,QAAQ;AACtB;AACA;;AAEA,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,eAAe,QAAQ;AACvB;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA,aAAa,OAAO;AACpB,aAAa,QAAQ;AACrB;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,eAAe,OAAO;AACtB;AACA;;AAEA,aAAa,OAAO;AACpB;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA,aAAa,sBAAsB;AACnC;AACA;AACA;AACA;;AAEA;AACA,iBAAiB,gBAAgB;AACjC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,iBAAiB,gBAAgB;AACjC;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,iBAAiB,gBAAgB;AACjC;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA,UAAU;AACV;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,wDAAwD;AACxD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB,cAAc;AAC/B;AACA;;AAEA;AACA;AACA;AACA,iBAAiB,gBAAgB;AACjC;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,uBAAuB;AACpC,aAAa,gBAAgB;AAC7B;AACA;;AAEA;AACA;AACA;AACA;AACA,UAAU;AACV;;AAEA;AACA;AACA;AACA;AACA;AACA,iBAAiB,eAAe;AAChC,UAAU;AACV;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB,QAAQ;AACzB;AACA,UAAU;AACV;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB,OAAO;AACxB;AACA;AACA,iBAAiB,OAAO;AACxB;AACA,KAAK;AACL,GAAG;AACH;AACA;AACA;AACA;AACA;AACA,mBAAmB,OAAO;AAC1B;AACA,OAAO;AACP;AACA;AACA,CAAC;;AAED,CAAC,iGAAiG;;;;;;;ACn1ElG,e;;;;;;;ACAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA,aAAa,sBAAsB;AACnC,aAAa,gBAAgB;AAC7B,aAAa,mBAAmB;AAChC,eAAe;AACf;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,sBAAsB;AACnC,aAAa,cAAc;AAC3B,aAAa,kBAAkB;AAC/B,aAAa,gBAAgB;AAC7B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,aAAa,QAAQ;AACrB,eAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,+CAA+C,iCAAiC;AAChF;AACA;;AAEA;AACA;AACA;;AAEA;AACA,aAAa,kBAAkB;AAC/B,aAAa,8BAA8B;AAC3C,aAAa,qBAAqB;AAClC,aAAa,OAAO;AACpB,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA,KAAK;AACL;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,aAAa,kBAAkB;AAC/B,aAAa,uBAAuB;AACpC,eAAe;AACf;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA,OAAO;AACP;AACA;;AAEA;AACA;AACA;AACA,YAAY,0BAA0B;AACtC;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA,sHAAsH,QAAQ;AAC9H;;AAEA;AACA;AACA;;AAEA,KAAK;AACL;;AAEA;AACA,kIAAkI,QAAQ,kCAAkC,iBAAiB;AAC7L;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA,gBAAgB,YAAY;AAC5B;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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;;AAEA;AACA;AACA;;AAEA;;;;;;;;AC7YA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA,aAAa,qBAAqB;AAClC,aAAa,qBAAqB;AAClC,aAAa,qBAAqB;AAClC,aAAa,QAAQ;AACrB,eAAe,WAAW;AAC1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA,eAAe,EAAE;AACjB,iBAAiB;AACjB;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,eAAe,EAAE;AACjB,eAAe,EAAE;AACjB,iBAAiB;AACjB;AACA;AACA;AACA;;AAEA;AACA,eAAe,EAAE;AACjB,eAAe,EAAE;AACjB,eAAe,QAAQ;AACvB,iBAAiB;AACjB;AACA;AACA;AACA;AACA;;AAEA,qBAAqB,qBAAqB;AAC1C;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA,GAAG;AACH;;AAEA;;;;;;;;AC7GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,kBAAkB;AAC/B,aAAa,gBAAgB;AAC7B,aAAa,iBAAiB;AAC9B,eAAe;AACf;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,QAAQ;AACrB,aAAa,QAAQ;AACrB,aAAa,YAAY;AACzB,aAAa,iBAAiB;AAC9B,eAAe;AACf;AACA;AACA;AACA;AACA,+BAA+B,gBAAgB;AAC/C;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA;AACA,aAAa,YAAY;AACzB,aAAa,iBAAiB;AAC9B,eAAe;AACf;AACA;;AAEA;AACA;;AAEA;AACA,aAAa,YAAY;AACzB,eAAe;AACf;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA,aAAa,kBAAkB;AAC/B,aAAa,gBAAgB;AAC7B,aAAa,YAAY;AACzB,eAAe;AACf;AACA;AACA;AACA;AACA;;AAEA;AACA,kFAAkF,6BAA6B,8BAA8B,eAAe;AAC5J;AACA;;AAEA;AACA;AACA,KAAK;;AAEL;AACA;AACA;;AAEA;AACA;AACA,yGAAyG,eAAe,kCAAkC,mBAAmB;AAC7K;AACA;;AAEA;AACA;;AAEA;AACA,aAAa,gBAAgB;AAC7B,eAAe;AACf;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,iIAAiI,mBAAmB;AACpJ;;AAEA;AACA;;AAEA,mBAAmB,cAAc;AACjC;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,aAAa,4BAA4B;AACzC,eAAe;AACf;AACA;AACA;AACA;;AAEA;AACA,wDAAwD,YAAY,sCAAsC,0BAA0B;AACpI;;AAEA;;AAEA,mBAAmB,iBAAiB;AACpC;AACA;;AAEA;;AAEA;AACA,iGAAiG,0BAA0B;AAC3H;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;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;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA,WAAW,OAAO;AAClB;;AAEA;;;;;;;;ACpSA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,mBAAmB;AAChC,eAAe;AACf;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,aAAa,gBAAgB;AAC7B,eAAe;AACf;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;;AAEA;;AAEA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;;;;;;;AC5GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,kBAAkB;AAC/B,aAAa,cAAc;AAC3B,aAAa,iBAAiB;AAC9B,eAAe;AACf;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,aAAa,cAAc;AAC3B,eAAe;AACf;AACA;AACA;AACA;AACA;AACA,mBAAmB,iBAAiB;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA","file":"proteus.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 33);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 0874b6e0c4104637981f","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst ProteusError = require('./ProteusError');\n\n/** @module errors */\n\nconst _extend = function(child, parent) {\n for (let key in parent) {\n if ({}.hasOwnProperty.call(parent, key)) child[key] = parent[key];\n }\n const ctor = function() {\n this.constructor = child;\n };\n ctor.prototype = parent.prototype;\n child.prototype = new ctor();\n child.__super__ = parent.prototype;\n return child;\n};\n\n/**\n * @class DontCallConstructor\n * @extends Error\n * @returns {DontCallConstructor} - `this`\n */\nconst DontCallConstructor = (function(superClass) {\n _extend(func, superClass);\n\n function func(_instance) {\n this._instance = _instance;\n func.__super__.constructor.call(this,\n `Instead of 'new {this._instance.constructor.name}', use '${this._instance.constructor.name}.new'.`\n );\n }\n\n return func;\n})(ProteusError);\n\nmodule.exports = DontCallConstructor;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/errors/DontCallConstructor.js\n// module id = 0\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst InputError = require('../errors/InputError');\n\n/** @module util */\n\nconst TypeUtil = {\n /**\n * @param {*} classes\n * @param {*} inst\n * @returns {void}\n * @throws {errors.InputError.TypeError}\n */\n assert_is_instance(classes, inst) {\n if (!Array.isArray(classes)) {\n classes = [classes];\n }\n if (classes.some((k) => inst instanceof k || (inst && inst.prototype instanceof k))) {\n return;\n }\n const valid_types = classes.map((k) => `'${k.name}'`).join(' or ');\n if (inst) {\n throw new InputError.TypeError(`Expected one of ${valid_types}, got '${inst.constructor.name}'.`, InputError.CODE.CASE_401);\n }\n throw new InputError.TypeError(`Expected one of ${valid_types}, got '${String(inst)}'.`, InputError.CODE.CASE_402);\n },\n /**\n * @param {*} inst\n * @returns {boolean}\n * @throws {errors.InputError.TypeError}\n */\n assert_is_integer(inst) {\n if (Number.isInteger(inst)) {\n return true;\n }\n if (inst) {\n throw new InputError.TypeError(`Expected integer, got '${inst.constructor.name}'.`, InputError.CODE.CASE_403);\n }\n throw new InputError.TypeError(`Expected integer, got '${String(inst)}'.`, InputError.CODE.CASE_404);\n },\n};\n\nmodule.exports = TypeUtil;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/util/TypeUtil.js\n// module id = 1\n// module chunks = 0","module.exports = CBOR;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"CBOR\"\n// module id = 2\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst DontCallConstructor = require('../errors/DontCallConstructor');\n\n/** @module util */\n\nconst ClassUtil = {\n /**\n * @param {*} klass\n * @returns {Function}\n */\n new_instance(klass) {\n try {\n return new klass();\n } catch (e) {\n if (!(e instanceof DontCallConstructor)) {\n throw e;\n }\n return e._instance;\n }\n },\n};\n\nmodule.exports = ClassUtil;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/util/ClassUtil.js\n// module id = 3\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\nconst ed2curve = require('ed2curve');\nconst sodium = require('libsodium-wrappers-sumo');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst TypeUtil = require('../util/TypeUtil');\n\n/** @module keys */\n\n/**\n * @class PublicKey\n * @throws {DontCallConstructor}\n */\nclass PublicKey {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /**\n * @param {!Uint8Array} pub_edward\n * @param {!Uint8Array} pub_curve\n * @returns {PublicKey} - `this`\n */\n static new(pub_edward, pub_curve) {\n TypeUtil.assert_is_instance(Uint8Array, pub_edward);\n TypeUtil.assert_is_instance(Uint8Array, pub_curve);\n\n /** @type {PublicKey} */\n const pk = ClassUtil.new_instance(PublicKey);\n\n /** @type {Uint8Array} */\n pk.pub_edward = pub_edward;\n /** @type {Uint8Array} */\n pk.pub_curve = pub_curve;\n return pk;\n }\n\n /**\n * This function can be used to verify a message signature.\n *\n * @param {!Uint8Array} signature - The signature to verify\n * @param {!string} message - The message from which the signature was computed.\n * @returns {boolean} - `true` if the signature is valid, `false` otherwise.\n */\n verify(signature, message) {\n TypeUtil.assert_is_instance(Uint8Array, signature);\n return sodium.crypto_sign_verify_detached(signature, message, this.pub_edward);\n }\n\n /** @returns {string} */\n fingerprint() {\n return sodium.to_hex(this.pub_edward);\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n e.object(1);\n e.u8(0);\n return e.bytes(this.pub_edward);\n }\n\n /**\n * @param {!CBOR.Decoder} d\n * @returns {PublicKey}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n const self = ClassUtil.new_instance(PublicKey);\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0:\n self.pub_edward = new Uint8Array(d.bytes());\n break;\n default:\n d.skip();\n }\n }\n\n TypeUtil.assert_is_instance(Uint8Array, self.pub_edward);\n\n self.pub_curve = ed2curve.convertPublicKey(self.pub_edward);\n return self;\n }\n}\n\nmodule.exports = PublicKey;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/keys/PublicKey.js\n// module id = 4\n// module chunks = 0","module.exports = sodium;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"sodium\"\n// module id = 5\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\n/** @module errors */\n\n/**\n * @class ProteusError\n * @param {!string} message\n * @param {string} [code]\n * @extends Error\n * @returns {ProteusError} - `this`\n */\nconst ProteusError = (function() {\n const func = function(message, code = 1) {\n this.code = code;\n this.message = message;\n this.name = this.constructor.name;\n this.stack = (new Error).stack;\n };\n\n func.prototype = new Error;\n func.prototype.constructor = func;\n func.prototype.CODE = {\n CASE_100: 100,\n CASE_101: 101,\n CASE_102: 102,\n CASE_103: 103,\n CASE_104: 104,\n };\n\n return func;\n})();\n\nmodule.exports = ProteusError;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/errors/ProteusError.js\n// module id = 6\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\nconst ed2curve = require('ed2curve');\nconst sodium = require('libsodium-wrappers-sumo');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst TypeUtil = require('../util/TypeUtil');\n\nconst PublicKey = require('./PublicKey');\nconst SecretKey = require('./SecretKey');\n\n/** @module keys */\n\n/**\n * Construct an ephemeral key pair.\n * @class KeyPair\n * @throws {DontCallConstructor}\n */\nclass KeyPair {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /** @returns {KeyPair} - `this` */\n static new() {\n const ed25519_key_pair = sodium.crypto_sign_keypair();\n\n const kp = ClassUtil.new_instance(KeyPair);\n kp.secret_key = KeyPair.prototype._construct_private_key(ed25519_key_pair);\n kp.public_key = KeyPair.prototype._construct_public_key(ed25519_key_pair);\n\n return kp;\n }\n\n /**\n * @description Ed25519 keys can be converted to Curve25519 keys, so that the same key pair can be\n * used both for authenticated encryption (crypto_box) and for signatures (crypto_sign).\n * @param {!Uint8Array} ed25519_key_pair - Key pair based on Edwards-curve (Ed25519)\n * @returns {keys.SecretKey} - Constructed private key\n * @private\n * @see https://download.libsodium.org/doc/advanced/ed25519-curve25519.html\n */\n _construct_private_key(ed25519_key_pair) {\n const sk_ed25519 = ed25519_key_pair.privateKey;\n const sk_curve25519 = ed2curve.convertSecretKey(sk_ed25519);\n return SecretKey.new(sk_ed25519, sk_curve25519);\n }\n\n /**\n * @typedef {Object} libsodium_keypair\n * @param {!Uint8Array} publicKey\n * @param {!Uint8Array} privateKey\n * @param {!string} keyType\n */\n /**\n * @param {!libsodium_keypair} ed25519_key_pair - Key pair based on Edwards-curve (Ed25519)\n * @private\n * @returns {keys.PublicKey} - Constructed public key\n */\n _construct_public_key(ed25519_key_pair) {\n const pk_ed25519 = ed25519_key_pair.publicKey;\n const pk_curve25519 = ed2curve.convertPublicKey(pk_ed25519);\n return PublicKey.new(pk_ed25519, pk_curve25519);\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n e.object(2);\n\n e.u8(0);\n this.secret_key.encode(e);\n\n e.u8(1);\n return this.public_key.encode(e);\n }\n\n /**\n * @param {!CBOR.Decoder} d\n * @returns {KeyPair}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n const self = ClassUtil.new_instance(KeyPair);\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0:\n self.secret_key = SecretKey.decode(d);\n break;\n case 1:\n self.public_key = PublicKey.decode(d);\n break;\n default:\n d.skip();\n }\n }\n\n TypeUtil.assert_is_instance(SecretKey, self.secret_key);\n TypeUtil.assert_is_instance(PublicKey, self.public_key);\n\n return self;\n }\n}\n\nmodule.exports = KeyPair;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/keys/KeyPair.js\n// module id = 7\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\nconst sodium = require('libsodium-wrappers-sumo');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst TypeUtil = require('../util/TypeUtil');\n\nconst PublicKey = require('./PublicKey');\n\n/** @module keys */\n\n/**\n * Construct a long-term identity key pair.\n * @classdesc Every client has a long-term identity key pair.\n * Long-term identity keys are used to initialise \"sessions\" with other clients (triple DH).\n * @throws {DontCallConstructor}\n */\nclass IdentityKey {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /**\n * @param {!PublicKey} public_key\n * @returns {IdentityKey} - `this`\n */\n static new(public_key) {\n TypeUtil.assert_is_instance(PublicKey, public_key);\n\n const key = ClassUtil.new_instance(IdentityKey);\n key.public_key = public_key;\n return key;\n }\n\n /** @returns {string} */\n fingerprint() {\n return this.public_key.fingerprint();\n }\n\n /** @returns {string} */\n toString() {\n return sodium.to_hex(this.public_key);\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n e.object(1);\n e.u8(0);\n return this.public_key.encode(e);\n }\n\n /**\n * @param {!CBOR.Decoder} d\n * @returns {IdentityKey}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n let public_key = null;\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0:\n public_key = PublicKey.decode(d);\n break;\n default:\n d.skip();\n }\n }\n\n return IdentityKey.new(public_key);\n }\n}\n\nmodule.exports = IdentityKey;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/keys/IdentityKey.js\n// module id = 8\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst TypeUtil = require('../util/TypeUtil');\n\nconst Message = require('./Message');\n\n/** @module message */\n\n/**\n * @extends Message\n * @throws {DontCallConstructor}\n */\nclass HeaderMessage extends Message {\n constructor() {\n super();\n throw new DontCallConstructor(this);\n }\n\n /**\n * @param {!Uint8Array} encrypted_header - encrypted header\n * @param {!Uint8Array} cipher_text\n * @returns {HeaderMessage} - `this`\n */\n static new(encrypted_header, cipher_text) {\n TypeUtil.assert_is_instance(Uint8Array, encrypted_header);\n TypeUtil.assert_is_instance(Uint8Array, cipher_text);\n\n const hm = ClassUtil.new_instance(HeaderMessage);\n\n hm.header = encrypted_header;\n hm.cipher_text = cipher_text;\n\n Object.freeze(hm);\n return hm;\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n e.object(2);\n\n e.u8(0);\n e.object(1);\n e.u8(0);\n e.bytes(this.header);\n\n e.u8(1);\n return e.bytes(this.cipher_text);\n }\n\n /**\n * @param {!CBOR.Decoder} d\n * @returns {HeaderMessage}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n let header = null;\n let cipher_text = null;\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0: {\n const nprops_mac = d.object();\n for (let j = 0; j <= nprops_mac - 1; j++) {\n switch (d.u8()) {\n case 0:\n header = new Uint8Array(d.bytes());\n break;\n default:\n d.skip();\n }\n }\n break;\n }\n case 1: {\n cipher_text = new Uint8Array(d.bytes());\n break;\n }\n default: {\n d.skip();\n }\n }\n }\n\n return HeaderMessage.new(header, cipher_text);\n }\n}\n\nmodule.exports = HeaderMessage;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/message/HeaderMessage.js\n// module id = 9\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst ProteusError = require('./ProteusError');\n\n/** @module errors */\n\n/**\n * @extends ProteusError\n * @param {string} [message]\n * @param {string} [code]\n */\nclass DecryptError extends ProteusError {\n constructor(message = 'Unknown decryption error', code = 2) {\n super(message, code);\n }\n\n static get CODE() {\n return {\n CASE_200: 200,\n CASE_201: 201,\n CASE_202: 202,\n CASE_203: 203,\n CASE_204: 204,\n CASE_205: 205,\n CASE_206: 206,\n CASE_207: 207,\n CASE_208: 208,\n CASE_209: 209,\n CASE_210: 210,\n CASE_211: 211,\n CASE_212: 212,\n CASE_213: 213,\n CASE_214: 214,\n CASE_215: 215,\n CASE_216: 216,\n };\n }\n}\n\n/**\n * @extends DecryptError\n * @param {string} [message]\n * @param {string} [code]\n */\nclass RemoteIdentityChanged extends DecryptError {\n constructor(message = 'Remote identity changed', code) {\n super(message, code);\n }\n}\n\n/**\n * @extends DecryptError\n * @param {string} [message]\n * @param {string} [code]\n */\nclass InvalidSignature extends DecryptError {\n constructor(message = 'Invalid signature', code) {\n super(message, code);\n }\n}\n\n/**\n * @extends DecryptError\n * @param {string} [message]\n * @param {string} [code]\n */\nclass InvalidMessage extends DecryptError {\n constructor(message = 'Invalid message', code) {\n super(message, code);\n }\n}\n\n/**\n * @extends DecryptError\n * @param {string} [message]\n * @param {string} [code]\n */\nclass DuplicateMessage extends DecryptError {\n constructor(message = 'Duplicate message', code) {\n super(message, code);\n }\n}\n\n/**\n * @extends DecryptError\n * @param {string} [message]\n * @param {string} [code]\n */\nclass TooDistantFuture extends DecryptError {\n constructor(message = 'Message is from too distant in the future', code) {\n super(message, code);\n }\n}\n\n/**\n * @extends DecryptError\n * @param {string} [message]\n * @param {string} [code]\n */\nclass OutdatedMessage extends DecryptError {\n constructor(message = 'Outdated message', code) {\n super(message, code);\n }\n}\n\n/**\n * @extends DecryptError\n * @param {string} [message]\n * @param {string} [code]\n */\nclass PrekeyNotFound extends DecryptError {\n constructor(message = 'Pre-key not found', code) {\n super(message, code);\n }\n}\n\n/**\n * @extends DecryptError\n * @param {string} [message]\n * @param {string} [code]\n */\nclass HeaderDecryptionFailed extends DecryptError {\n constructor(message = 'Header descryption failed', code) {\n super(message, code);\n }\n}\n\n/**\n * @extends DecryptError\n * @param {string} [message]\n * @param {string} [code]\n */\nclass InvalidHeader extends DecryptError {\n constructor(message = 'Invalid header', code) {\n super(message, code);\n }\n}\n\nObject.assign(DecryptError, {\n RemoteIdentityChanged,\n InvalidSignature,\n InvalidMessage,\n DuplicateMessage,\n TooDistantFuture,\n OutdatedMessage,\n PrekeyNotFound,\n HeaderDecryptionFailed,\n InvalidHeader,\n});\n\nmodule.exports = ProteusError.DecryptError = DecryptError;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/errors/DecryptError.js\n// module id = 10\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst TypeUtil = require('../util/TypeUtil');\n\nconst IdentityKey = require('./IdentityKey');\nconst KeyPair = require('./KeyPair');\nconst SecretKey = require('./SecretKey');\n\n/** @module keys */\n\n/**\n * @class IdentityKeyPair\n * @throws {DontCallConstructor}\n */\nclass IdentityKeyPair {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /** @returns {IdentityKeyPair} - `this` */\n static new() {\n const key_pair = KeyPair.new();\n\n /** @type {IdentityKeyPair} */\n const ikp = ClassUtil.new_instance(IdentityKeyPair);\n ikp.version = 1;\n ikp.secret_key = key_pair.secret_key;\n ikp.public_key = IdentityKey.new(key_pair.public_key);\n\n return ikp;\n }\n\n /** @returns {ArrayBuffer} */\n serialise() {\n const e = new CBOR.Encoder();\n this.encode(e);\n return e.get_buffer();\n }\n\n /**\n * @param {!ArrayBuffer} buf\n * @returns {IdentityKeyPair}\n */\n static deserialise(buf) {\n TypeUtil.assert_is_instance(ArrayBuffer, buf);\n\n const d = new CBOR.Decoder(buf);\n return IdentityKeyPair.decode(d);\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n e.object(3);\n e.u8(0);\n e.u8(this.version);\n e.u8(1);\n this.secret_key.encode(e);\n e.u8(2);\n return this.public_key.encode(e);\n }\n\n /**\n * @param {!CBOR.Decoder} d\n * @returns {IdentityKeyPair}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n const self = ClassUtil.new_instance(IdentityKeyPair);\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0:\n self.version = d.u8();\n break;\n case 1:\n self.secret_key = SecretKey.decode(d);\n break;\n case 2:\n self.public_key = IdentityKey.decode(d);\n break;\n default:\n d.skip();\n }\n }\n\n TypeUtil.assert_is_integer(self.version);\n TypeUtil.assert_is_instance(SecretKey, self.secret_key);\n TypeUtil.assert_is_instance(IdentityKey, self.public_key);\n\n return self;\n }\n}\n\nmodule.exports = IdentityKeyPair;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/keys/IdentityKeyPair.js\n// module id = 11\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\n\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst TypeUtil = require('../util/TypeUtil');\n\nconst DecodeError = require('../errors/DecodeError');\n\n/** @module message */\n\n/**\n * @class Message\n * @throws {DontCallConstructor}\n */\nclass Message {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /** @returns {ArrayBuffer} */\n serialise() {\n const e = new CBOR.Encoder();\n if (this instanceof HeaderMessage) {\n e.u8(1);\n } else if (this instanceof PreKeyMessage) {\n e.u8(2);\n } else {\n throw new TypeError('Unexpected message type', 9);\n }\n\n this.encode(e);\n return e.get_buffer();\n }\n\n /**\n * @param {!ArrayBuffer} buf\n * @returns {message.HeaderMessage|message.PreKeyMessage}\n */\n static deserialise(buf) {\n TypeUtil.assert_is_instance(ArrayBuffer, buf);\n\n const d = new CBOR.Decoder(buf);\n\n switch (d.u8()) {\n case 1:\n return HeaderMessage.decode(d);\n case 2:\n return PreKeyMessage.decode(d);\n default:\n throw new DecodeError.InvalidType('Unrecognised message type', DecodeError.CODE.CASE_302);\n }\n }\n}\n\nmodule.exports = Message;\n\n// these require lines have to come after the Message definition because otherwise\n// it creates a circular dependency with the message subtypes\nconst HeaderMessage = require('./HeaderMessage');\nconst PreKeyMessage = require('./PreKeyMessage');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/message/Message.js\n// module id = 12\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst TypeUtil = require('../util/TypeUtil');\n\nconst IdentityKey = require('../keys/IdentityKey');\nconst PublicKey = require('../keys/PublicKey');\n\nconst HeaderMessage = require('./HeaderMessage');\nconst Message = require('./Message');\n\n/** @module message */\n\n/**\n * @extends Message\n * @throws {DontCallConstructor}\n */\nclass PreKeyMessage extends Message {\n constructor() {\n super();\n throw new DontCallConstructor(this);\n }\n\n /**\n * @param {!number} prekey_id\n * @param {!keys.PublicKey} base_key\n * @param {!keys.IdentityKey} identity_key\n * @param {!message.HeaderMessage} message\n * @returns {PreKeyMessage}\n */\n static new(prekey_id, base_key, identity_key, message) {\n TypeUtil.assert_is_integer(prekey_id);\n TypeUtil.assert_is_instance(PublicKey, base_key);\n TypeUtil.assert_is_instance(IdentityKey, identity_key);\n TypeUtil.assert_is_instance(HeaderMessage, message);\n\n const pkm = ClassUtil.new_instance(PreKeyMessage);\n\n pkm.prekey_id = prekey_id;\n pkm.base_key = base_key;\n pkm.identity_key = identity_key;\n pkm.message = message;\n\n Object.freeze(pkm);\n return pkm;\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n e.object(4);\n e.u8(0);\n e.u16(this.prekey_id);\n e.u8(1);\n this.base_key.encode(e);\n e.u8(2);\n this.identity_key.encode(e);\n e.u8(3);\n return this.message.encode(e);\n }\n\n /**\n * @param {!CBOR.Decoder} d\n * @returns {PreKeyMessage}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n let prekey_id = null;\n let base_key = null;\n let identity_key = null;\n let message = null;\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0:\n prekey_id = d.u16();\n break;\n case 1:\n base_key = PublicKey.decode(d);\n break;\n case 2:\n identity_key = IdentityKey.decode(d);\n break;\n case 3:\n message = HeaderMessage.decode(d);\n break;\n default:\n d.skip();\n }\n }\n\n // checks for missing variables happens in constructor\n return PreKeyMessage.new(prekey_id, base_key, identity_key, message);\n }\n}\n\nmodule.exports = PreKeyMessage;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/message/PreKeyMessage.js\n// module id = 13\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst TypeUtil = require('../util/TypeUtil');\n\nconst MacKey = require('../derived/MacKey');\nconst Message = require('./Message');\n\n/** @module message */\n\n/**\n * @class Envelope\n * @throws {DontCallConstructor}\n */\nclass Envelope {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /**\n * @param {!derived.MacKey} mac_key MacKey generated by derived secrets\n * @param {!message.Message} message\n * @returns {Envelope}\n */\n static new(mac_key, message) {\n TypeUtil.assert_is_instance(MacKey, mac_key);\n TypeUtil.assert_is_instance(Message, message);\n\n const serialized_message = new Uint8Array(message.serialise());\n\n const env = ClassUtil.new_instance(Envelope);\n\n env.version = 1;\n env.mac = mac_key.sign(serialized_message);\n env.message = message;\n env._message_enc = serialized_message;\n\n Object.freeze(env);\n return env;\n }\n\n /**\n * @param {!derived.MacKey} mac_key The remote party's MacKey\n * @returns {boolean}\n */\n verify(mac_key) {\n TypeUtil.assert_is_instance(MacKey, mac_key);\n return mac_key.verify(this.mac, this._message_enc);\n }\n\n /** @returns {ArrayBuffer} - The serialized message envelope */\n serialise() {\n const e = new CBOR.Encoder();\n this.encode(e);\n return e.get_buffer();\n }\n\n /**\n * @param {!ArrayBuffer} buf\n * @returns {Envelope}\n */\n static deserialise(buf) {\n TypeUtil.assert_is_instance(ArrayBuffer, buf);\n\n const d = new CBOR.Decoder(buf);\n return Envelope.decode(d);\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n e.object(3);\n e.u8(0);\n e.u8(this.version);\n\n e.u8(1);\n e.object(1);\n e.u8(0);\n e.bytes(this.mac);\n\n e.u8(2);\n return e.bytes(this._message_enc);\n }\n\n /**\n * @param {!CBOR.Decoder} d\n * @returns {Envelope}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n const env = ClassUtil.new_instance(Envelope);\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0: {\n env.version = d.u8();\n break;\n }\n case 1: {\n const nprops_mac = d.object();\n for (let j = 0; j <= nprops_mac - 1; j++) {\n switch (d.u8()) {\n case 0:\n env.mac = new Uint8Array(d.bytes());\n break;\n default:\n d.skip();\n }\n }\n break;\n }\n case 2: {\n env._message_enc = new Uint8Array(d.bytes());\n break;\n }\n default: {\n d.skip();\n }\n }\n }\n\n TypeUtil.assert_is_integer(env.version);\n TypeUtil.assert_is_instance(Uint8Array, env.mac);\n\n env.message = Message.deserialise(env._message_enc.buffer);\n\n Object.freeze(env);\n return env;\n }\n}\n\nmodule.exports = Envelope;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/message/Envelope.js\n// module id = 14\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\nconst sodium = require('libsodium-wrappers-sumo');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst TypeUtil = require('../util/TypeUtil');\n\n/** @module derived */\n\n/**\n * @class MacKey\n * @throws {DontCallConstructor}\n */\nclass MacKey {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /**\n * @param {!Uint8Array} key - Mac Key in byte array format generated by derived secrets\n * @returns {MacKey} - `this`\n */\n static new(key) {\n TypeUtil.assert_is_instance(Uint8Array, key);\n\n const mk = ClassUtil.new_instance(MacKey);\n /** @type {Uint8Array} */\n mk.key = key;\n return mk;\n }\n\n /**\n * Hash-based message authentication code\n * @param {!(string|Uint8Array)} msg\n * @returns {Uint8Array}\n */\n sign(msg) {\n return sodium.crypto_auth_hmacsha256(msg, this.key);\n }\n\n /**\n * Verifies the signature of a given message by resigning it.\n * @param {!Uint8Array} signature Mac signature (HMAC) which needs to get verified\n * @param {!Uint8Array} msg Unsigned message\n * @returns {boolean}\n */\n verify(signature, msg) {\n return sodium.crypto_auth_hmacsha256_verify(signature, msg, this.key);\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n e.object(1);\n e.u8(0);\n return e.bytes(this.key);\n }\n\n /**\n * @param {!CBOR.Decoder} d\n * @returns {MacKey}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n let key_bytes = null;\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0:\n key_bytes = new Uint8Array(d.bytes());\n break;\n default:\n d.skip();\n }\n }\n\n return MacKey.new(key_bytes);\n }\n}\n\nmodule.exports = MacKey;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/derived/MacKey.js\n// module id = 15\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst sodium = require('libsodium-wrappers-sumo');\n\n/** @module util */\n\nconst MemoryUtil = {\n /**\n * @param {!(Uint8Array|ArrayBuffer|Object)} object\n * @returns {void}\n */\n zeroize(object) {\n if (object instanceof Uint8Array) {\n sodium.memzero(object);\n } else if (object instanceof ArrayBuffer) {\n sodium.memzero(new Uint8Array(object));\n } else if (typeof object === 'object') {\n Object.keys(object).map((key) => object[key]).forEach((val) => this.zeroize(val));\n }\n },\n};\n\nmodule.exports = MemoryUtil;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/util/MemoryUtil.js\n// module id = 16\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\nconst sodium = require('libsodium-wrappers-sumo');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst TypeUtil = require('../util/TypeUtil');\n\n/** @module derived */\n\n/**\n * @class HeadKey\n * @throws {DontCallConstructor}\n */\nclass HeadKey {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /**\n * @param {!Uint8Array} key\n * @returns {HeadKey} - `this`\n */\n static new(key) {\n TypeUtil.assert_is_instance(Uint8Array, key);\n\n const hk = ClassUtil.new_instance(HeadKey);\n /** @type {Uint8Array} */\n hk.key = key;\n return hk;\n }\n\n /**\n * @param {!number} idx\n * @returns {Uint8Array}\n */\n static index_as_nonce(idx) {\n const nonce = new ArrayBuffer(8);\n new DataView(nonce).setUint32(0, idx);\n return new Uint8Array(nonce);\n }\n\n /**\n * @param {!ArrayBuffer} header - The serialized header to encrypt\n * @param {!Uint8Array} nonce\n * @returns {Uint8Array} - Encrypted payload\n */\n encrypt(header, nonce) {\n header = new Uint8Array(header);\n\n return sodium.crypto_stream_chacha20_xor(header, nonce, this.key, 'uint8array');\n }\n\n /**\n * @param {!Uint8Array} encrypted_header\n * @param {!Uint8Array} nonce\n * @returns {Uint8Array}\n */\n decrypt(encrypted_header, nonce) {\n return this.encrypt(encrypted_header, nonce);\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n e.object(1);\n e.u8(0);\n return e.bytes(this.key);\n }\n\n /**\n * @param {!CBOR.Encoder} d\n * @returns {HeadKey}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n let key_bytes = null;\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0:\n key_bytes = new Uint8Array(d.bytes());\n break;\n default:\n d.skip();\n }\n }\n return HeadKey.new(key_bytes);\n }\n}\n\nmodule.exports = HeadKey;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/derived/HeadKey.js\n// module id = 17\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst TypeUtil = require('../util/TypeUtil');\n\nconst DerivedSecrets = require('../derived/DerivedSecrets');\nconst MacKey = require('../derived/MacKey');\nconst MessageKeys = require('./MessageKeys');\n\n/** @module session */\n\n/**\n * @class ChainKey\n * @throws {DontCallConstructor}\n */\nclass ChainKey {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /**\n * @param {!derived.MacKey} key - Mac Key generated by derived secrets\n * @param {!number} counter\n * @returns {ChainKey}\n */\n static from_mac_key(key, counter) {\n TypeUtil.assert_is_instance(MacKey, key);\n TypeUtil.assert_is_integer(counter);\n\n const ck = ClassUtil.new_instance(ChainKey);\n ck.key = key;\n ck.idx = counter;\n return ck;\n }\n\n /** @returns {ChainKey} */\n next() {\n const ck = ClassUtil.new_instance(ChainKey);\n ck.key = MacKey.new(this.key.sign('1'));\n ck.idx = this.idx + 1;\n return ck;\n }\n\n /** @returns {session.MessageKeys} */\n message_keys() {\n const base = this.key.sign('0');\n const derived_secrets = DerivedSecrets.kdf_without_salt(base, 'hash_ratchet');\n return MessageKeys.new(derived_secrets.cipher_key, derived_secrets.mac_key, this.idx);\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n e.object(2);\n e.u8(0);\n this.key.encode(e);\n e.u8(1);\n return e.u32(this.idx);\n }\n\n /**\n * @param {!CBOR.Decoder} d\n * @returns {ChainKey}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n const self = ClassUtil.new_instance(ChainKey);\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0:\n self.key = MacKey.decode(d);\n break;\n case 1:\n self.idx = d.u32();\n break;\n default:\n d.skip();\n }\n }\n\n TypeUtil.assert_is_instance(MacKey, self.key);\n TypeUtil.assert_is_integer(self.idx);\n\n return self;\n }\n}\n\nmodule.exports = ChainKey;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/session/ChainKey.js\n// module id = 18\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n/* eslint no-unused-vars: \"off\" */\n\n'use strict';\n\nconst ProteusError = require('./ProteusError');\n\n/** @module errors */\n\n/**\n * @extends ProteusError\n * @param {string} [message]\n * @param {string} [code]\n * @returns {string}\n */\nclass DecodeError extends ProteusError {\n constructor(message = 'Unknown decoding error', code = 3) {\n super(message, code);\n }\n\n static get CODE() {\n return {\n CASE_300: 300,\n CASE_301: 301,\n CASE_302: 302,\n CASE_303: 303,\n };\n }\n}\n\n/**\n * @extends DecodeError\n * @param {string} [message]\n * @param {string} [code]\n * @returns {string}\n */\nclass InvalidType extends DecodeError {\n constructor(message = 'Invalid type', code) {\n super(message, code);\n }\n}\n\n/**\n * @extends DecodeError\n * @param {string} [message]\n * @param {string} [code]\n * @returns {string}\n */\nclass InvalidArrayLen extends DecodeError {\n constructor(message = 'Invalid array length', code) {\n super(message, code);\n }\n}\n\n/**\n * @extends DecodeError\n * @param {string} [message]\n * @param {string} [code]\n * @returns {string}\n */\nclass LocalIdentityChanged extends DecodeError {\n constructor(message = 'Local identity changed', code) {\n super(message, code);\n }\n}\n\nObject.assign(DecodeError, {\n InvalidType,\n InvalidArrayLen,\n LocalIdentityChanged,\n});\n\nmodule.exports = ProteusError.DecodeError = DecodeError;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/errors/DecodeError.js\n// module id = 19\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2017 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst ProteusError = require('./ProteusError');\n\n/** @module errors */\n\n/**\n * @extends ProteusError\n * @param {string} [message]\n * @param {string} [code]\n * @returns {string}\n */\nclass InputError extends ProteusError {\n constructor(message = 'Invalid input', code = 4) {\n super(message, code);\n }\n\n static get CODE() {\n return {\n CASE_400: 400,\n CASE_401: 401,\n CASE_402: 402,\n CASE_403: 403,\n CASE_404: 404,\n };\n }\n}\n\n/**\n * @extends InputError\n * @param {string} [message]\n * @param {string} [code]\n * @returns {string}\n */\nclass RangeError extends InputError {\n constructor(message = 'Invalid type', code) {\n super(message, code);\n }\n}\n\n/**\n * @extends InputError\n * @param {string} [message]\n * @param {string} [code]\n * @returns {string}\n */\nclass TypeError extends InputError {\n constructor(message = 'Invalid array length', code) {\n super(message, code);\n }\n}\n\nObject.assign(InputError, {\n RangeError,\n TypeError,\n});\n\nmodule.exports = ProteusError.InputError = InputError;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/errors/InputError.js\n// module id = 20\n// module chunks = 0","/*\n * ed2curve: convert Ed25519 signing key pair into Curve25519\n * key pair suitable for Diffie-Hellman key exchange.\n *\n * Written by Dmitry Chestnykh in 2014. Public domain.\n */\n/* jshint newcap: false */\n(function(root, f) {\n 'use strict';\n if (typeof module !== 'undefined' && module.exports) module.exports = f(require('tweetnacl/nacl-fast'));\n else root.ed2curve = f(root.nacl);\n}(this, function(nacl) {\n 'use strict';\n if (!nacl) throw new Error('tweetnacl not loaded');\n\n // -- Operations copied from TweetNaCl.js. --\n\n var gf = function(init) {\n var i, r = new Float64Array(16);\n if (init) for (i = 0; i < init.length; i++) r[i] = init[i];\n return r;\n };\n\n var gf0 = gf(),\n gf1 = gf([1]),\n D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]),\n I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);\n\n\n\n function car25519(o) {\n var c;\n var i;\n for (i = 0; i < 16; i++) {\n o[i] += 65536;\n c = Math.floor(o[i] / 65536);\n o[(i+1)*(i<15?1:0)] += c - 1 + 37 * (c-1) * (i===15?1:0);\n o[i] -= (c * 65536);\n }\n }\n\n function sel25519(p, q, b) {\n var t, c = ~(b-1);\n for (var i = 0; i < 16; i++) {\n t = c & (p[i] ^ q[i]);\n p[i] ^= t;\n q[i] ^= t;\n }\n }\n\n function unpack25519(o, n) {\n var i;\n for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8);\n o[15] &= 0x7fff;\n }\n\n // addition\n function A(o, a, b) {\n var i;\n for (i = 0; i < 16; i++) o[i] = (a[i] + b[i])|0;\n }\n\n // subtraction\n function Z(o, a, b) {\n var i;\n for (i = 0; i < 16; i++) o[i] = (a[i] - b[i])|0;\n }\n\n // multiplication\n function M(o, a, b) {\n var i, j, t = new Float64Array(31);\n for (i = 0; i < 31; i++) t[i] = 0;\n for (i = 0; i < 16; i++) {\n for (j = 0; j < 16; j++) {\n t[i+j] += a[i] * b[j];\n }\n }\n for (i = 0; i < 15; i++) {\n t[i] += 38 * t[i+16];\n }\n for (i = 0; i < 16; i++) o[i] = t[i];\n car25519(o);\n car25519(o);\n }\n\n // squaring\n function S(o, a) {\n M(o, a, a);\n }\n\n // inversion\n function inv25519(o, i) {\n var c = gf();\n var a;\n for (a = 0; a < 16; a++) c[a] = i[a];\n for (a = 253; a >= 0; a--) {\n S(c, c);\n if(a !== 2 && a !== 4) M(c, c, i);\n }\n for (a = 0; a < 16; a++) o[a] = c[a];\n }\n\n function pack25519(o, n) {\n var i, j, b;\n var m = gf(), t = gf();\n for (i = 0; i < 16; i++) t[i] = n[i];\n car25519(t);\n car25519(t);\n car25519(t);\n for (j = 0; j < 2; j++) {\n m[0] = t[0] - 0xffed;\n for (i = 1; i < 15; i++) {\n m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1);\n m[i-1] &= 0xffff;\n }\n m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1);\n b = (m[15]>>16) & 1;\n m[14] &= 0xffff;\n sel25519(t, m, 1-b);\n }\n for (i = 0; i < 16; i++) {\n o[2*i] = t[i] & 0xff;\n o[2*i+1] = t[i] >> 8;\n }\n }\n\n\n function par25519(a) {\n var d = new Uint8Array(32);\n pack25519(d, a);\n return d[0] & 1;\n }\n\n\n\n function vn(x, xi, y, yi, n) {\n var i, d = 0;\n for (i = 0; i < n; i++) d |= x[xi + i] ^ y[yi + i];\n return (1 & ((d - 1) >>> 8)) - 1;\n }\n\n\n function crypto_verify_32(x, xi, y, yi) {\n return vn(x, xi, y, yi, 32);\n }\n\n function neq25519(a, b) {\n var c = new Uint8Array(32), d = new Uint8Array(32);\n pack25519(c, a);\n pack25519(d, b);\n return crypto_verify_32(c, 0, d, 0);\n }\n\n\n function pow2523(o, i) {\n var c = gf();\n var a;\n for (a = 0; a < 16; a++) c[a] = i[a];\n for (a = 250; a >= 0; a--) {\n S(c, c);\n if (a !== 1) M(c, c, i);\n }\n for (a = 0; a < 16; a++) o[a] = c[a];\n }\n\n function set25519(r, a) {\n var i;\n for (i = 0; i < 16; i++) r[i] = a[i] | 0;\n }\n\n function unpackneg(r, p) {\n var t = gf(), chk = gf(), num = gf(),\n den = gf(), den2 = gf(), den4 = gf(),\n den6 = gf();\n\n set25519(r[2], gf1);\n unpack25519(r[1], p);\n S(num, r[1]);\n M(den, num, D);\n Z(num, num, r[2]);\n A(den, r[2], den);\n\n S(den2, den);\n S(den4, den2);\n M(den6, den4, den2);\n M(t, den6, num);\n M(t, t, den);\n\n pow2523(t, t);\n M(t, t, num);\n M(t, t, den);\n M(t, t, den);\n M(r[0], t, den);\n\n S(chk, r[0]);\n M(chk, chk, den);\n if (neq25519(chk, num)) M(r[0], r[0], I);\n\n S(chk, r[0]);\n M(chk, chk, den);\n if (neq25519(chk, num)) return -1;\n\n if (par25519(r[0]) === (p[31] >> 7)) Z(r[0], gf0, r[0]);\n\n M(r[3], r[0], r[1]);\n return 0;\n }\n\n // ----\n\n // Converts Ed25519 public key to Curve25519 public key.\n // montgomeryX = (edwardsY + 1)*inverse(1 - edwardsY) mod p\n function convertPublicKey(pk) {\n var z = new Uint8Array(32),\n q = [gf(), gf(), gf(), gf()],\n a = gf(), b = gf();\n\n if (unpackneg(q, pk)) return null; // reject invalid key\n\n var y = q[1];\n\n A(a, gf1, y);\n Z(b, gf1, y);\n inv25519(b, b);\n M(a, a, b);\n\n pack25519(z, a);\n return z;\n }\n\n // Converts Ed25519 secret key to Curve25519 secret key.\n function convertSecretKey(sk) {\n var d = new Uint8Array(64), o = new Uint8Array(32), i;\n nacl.lowlevel.crypto_hash(d, sk, 32);\n d[0] &= 248;\n d[31] &= 127;\n d[31] |= 64;\n for (i = 0; i < 32; i++) o[i] = d[i];\n for (i = 0; i < 64; i++) d[i] = 0;\n return o;\n }\n\n function convertKeyPair(edKeyPair) {\n var publicKey = convertPublicKey(edKeyPair.publicKey);\n if (!publicKey) return null;\n return {\n publicKey: publicKey,\n secretKey: convertSecretKey(edKeyPair.secretKey)\n };\n }\n\n return {\n convertPublicKey: convertPublicKey,\n convertSecretKey: convertSecretKey,\n convertKeyPair: convertKeyPair,\n };\n\n}));\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/ed2curve/ed2curve.js\n// module id = 21\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\nconst ed2curve = require('ed2curve');\nconst sodium = require('libsodium-wrappers-sumo');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst PublicKey = require('./PublicKey');\nconst TypeUtil = require('../util/TypeUtil');\n\n/** @module keys */\n\n/**\n * @class SecretKey\n * @throws {DontCallConstructor}\n */\nclass SecretKey {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /**\n * @param {!Uint8Array} sec_edward\n * @param {!Uint8Array} sec_curve\n * @returns {SecretKey} - `this`\n */\n static new(sec_edward, sec_curve) {\n TypeUtil.assert_is_instance(Uint8Array, sec_edward);\n TypeUtil.assert_is_instance(Uint8Array, sec_curve);\n\n const sk = ClassUtil.new_instance(SecretKey);\n\n /** @type {Uint8Array} */\n sk.sec_edward = sec_edward;\n /** @type {Uint8Array} */\n sk.sec_curve = sec_curve;\n return sk;\n }\n\n /**\n * This function can be used to compute a message signature.\n * @param {!string} message - Message to be signed\n * @returns {Uint8Array} - A message signature\n */\n sign(message) {\n return sodium.crypto_sign_detached(message, this.sec_edward);\n }\n\n /**\n * This function can be used to compute a shared secret given a user's secret key and another\n * user's public key.\n * @param {!keys.PublicKey} public_key - Another user's public key\n * @returns {Uint8Array} - Array buffer view of the computed shared secret\n */\n shared_secret(public_key) {\n TypeUtil.assert_is_instance(PublicKey, public_key);\n\n return sodium.crypto_scalarmult(this.sec_curve, public_key.pub_curve);\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n e.object(1);\n e.u8(0);\n return e.bytes(this.sec_edward);\n }\n\n /**\n * @param {!CBOR.Decoder} d\n * @returns {SecretKey}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n const self = ClassUtil.new_instance(SecretKey);\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0:\n self.sec_edward = new Uint8Array(d.bytes());\n break;\n default:\n d.skip();\n }\n }\n\n TypeUtil.assert_is_instance(Uint8Array, self.sec_edward);\n\n self.sec_curve = ed2curve.convertSecretKey(self.sec_edward);\n return self;\n }\n}\n\nmodule.exports = SecretKey;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/keys/SecretKey.js\n// module id = 22\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\nconst sodium = require('libsodium-wrappers-sumo');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst TypeUtil = require('../util/TypeUtil');\n\nconst IdentityKey = require('./IdentityKey');\nconst IdentityKeyPair = require('./IdentityKeyPair');\nconst PreKey = require('./PreKey');\nconst PreKeyAuth = require('./PreKeyAuth');\nconst PublicKey = require('./PublicKey');\n\n/** @module keys */\n\n/**\n * @class PreKeyBundle\n * @throws {DontCallConstructor}\n */\nclass PreKeyBundle {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /**\n * @param {!keys.IdentityKey} public_identity_key\n * @param {!keys.PreKey} prekey\n * @returns {PreKeyBundle} - `this`\n */\n static new(public_identity_key, prekey) {\n TypeUtil.assert_is_instance(IdentityKey, public_identity_key);\n TypeUtil.assert_is_instance(PreKey, prekey);\n\n /** @type {keys.PreyKeyBundle} */\n const bundle = ClassUtil.new_instance(PreKeyBundle);\n\n bundle.version = 1;\n bundle.prekey_id = prekey.key_id;\n bundle.public_key = prekey.key_pair.public_key;\n bundle.identity_key = public_identity_key;\n bundle.signature = null;\n\n return bundle;\n }\n\n /**\n * @param {!keys.IdentityKeyPair} identity_pair\n * @param {!keys.PreKey} prekey\n * @returns {PreKeyBundle}\n */\n static signed(identity_pair, prekey) {\n TypeUtil.assert_is_instance(IdentityKeyPair, identity_pair);\n TypeUtil.assert_is_instance(PreKey, prekey);\n\n /** @type {keys.PublicKey} */\n const ratchet_key = prekey.key_pair.public_key;\n /** @type {Uint8Array} */\n const signature = identity_pair.secret_key.sign(ratchet_key.pub_edward);\n\n /** @type {keys.PreyKeyBundle} */\n const bundle = ClassUtil.new_instance(PreKeyBundle);\n\n bundle.version = 1;\n bundle.prekey_id = prekey.key_id;\n bundle.public_key = ratchet_key;\n bundle.identity_key = identity_pair.public_key;\n bundle.signature = signature;\n\n return bundle;\n }\n\n /** @returns {keys.PreKeyAuth} */\n verify() {\n if (!this.signature) {\n return PreKeyAuth.UNKNOWN;\n }\n\n if (this.identity_key.public_key.verify(this.signature, this.public_key.pub_edward)) {\n return PreKeyAuth.VALID;\n }\n return PreKeyAuth.INVALID;\n }\n\n /** @returns {ArrayBuffer} */\n serialise() {\n const e = new CBOR.Encoder();\n this.encode(e);\n return e.get_buffer();\n }\n\n /**\n * @typedef {Object} type_serialised_json\n * @property {number} id\n * @property {string} key\n */\n /** @returns {type_serialised_json} */\n serialised_json() {\n return {\n 'id': this.prekey_id,\n 'key': sodium.to_base64(new Uint8Array(this.serialise()), true),\n };\n }\n\n /**\n * @param {!ArrayBuffer} buf\n * @returns {PreKeyBundle}\n */\n static deserialise(buf) {\n TypeUtil.assert_is_instance(ArrayBuffer, buf);\n return PreKeyBundle.decode(new CBOR.Decoder(buf));\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n TypeUtil.assert_is_instance(CBOR.Encoder, e);\n\n e.object(5);\n e.u8(0);\n e.u8(this.version);\n e.u8(1);\n e.u16(this.prekey_id);\n e.u8(2);\n this.public_key.encode(e);\n e.u8(3);\n this.identity_key.encode(e);\n\n e.u8(4);\n if (!this.signature) {\n return e.null();\n } else {\n return e.bytes(this.signature);\n }\n }\n\n /**\n * @param {!CBOR.Decoder} d\n * @returns {PreKeyBundle}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n const self = ClassUtil.new_instance(PreKeyBundle);\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0:\n self.version = d.u8();\n break;\n case 1:\n self.prekey_id = d.u16();\n break;\n case 2:\n self.public_key = PublicKey.decode(d);\n break;\n case 3:\n self.identity_key = IdentityKey.decode(d);\n break;\n case 4:\n self.signature = d.optional(() => new Uint8Array(d.bytes()));\n break;\n default:\n d.skip();\n }\n }\n\n TypeUtil.assert_is_integer(self.version);\n TypeUtil.assert_is_integer(self.prekey_id);\n TypeUtil.assert_is_instance(PublicKey, self.public_key);\n TypeUtil.assert_is_instance(IdentityKey, self.identity_key);\n\n return self;\n }\n}\n\nmodule.exports = PreKeyBundle;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/keys/PreKeyBundle.js\n// module id = 23\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst InputError = require('../errors/InputError');\nconst TypeUtil = require('../util/TypeUtil');\n\nconst KeyPair = require('./KeyPair');\n\n/** @module keys **/\n\n/**\n * @class PreKey\n * @classdesc Pre-generated (and regularly refreshed) pre-keys.\n * A Pre-Shared Key contains the public long-term identity and ephemeral handshake keys for the initial triple DH.\n * @throws {DontCallConstructor}\n */\nclass PreKey {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /** @type {number} */\n static get MAX_PREKEY_ID() {\n return 0xFFFF;\n }\n\n /**\n * @param {!number} pre_key_id\n * @returns {PreKey} - `this`\n * @throws {errors.InputError.RangeError}\n */\n static new(pre_key_id) {\n this.validate_pre_key_id(pre_key_id);\n\n const pk = ClassUtil.new_instance(PreKey);\n\n pk.version = 1;\n pk.key_id = pre_key_id;\n pk.key_pair = KeyPair.new();\n return pk;\n }\n\n static validate_pre_key_id(pre_key_id) {\n TypeUtil.assert_is_integer(pre_key_id);\n\n if (pre_key_id < 0 || pre_key_id > PreKey.MAX_PREKEY_ID) {\n const message = `PreKey ID (${pre_key_id}) must be between or equal to 0 and ${PreKey.MAX_PREKEY_ID}.`;\n throw new InputError.RangeError(message, InputError.CODE.CASE_400);\n }\n }\n\n /** @returns {PreKey} */\n static last_resort() {\n return PreKey.new(PreKey.MAX_PREKEY_ID);\n }\n\n /**\n * @param {!number} start\n * @param {!number} size\n * @returns {Array<PreKey>}\n * @throws {errors.InputError.RangeError}\n */\n static generate_prekeys(start, size) {\n this.validate_pre_key_id(start);\n this.validate_pre_key_id(size);\n\n if (size === 0) {\n return [];\n }\n\n return [...Array(size).keys()].map((x) => PreKey.new((start + x) % PreKey.MAX_PREKEY_ID));\n }\n\n /** @returns {ArrayBuffer} */\n serialise() {\n const e = new CBOR.Encoder();\n this.encode(e);\n return e.get_buffer();\n }\n\n /**\n * @param {!ArrayBuffer} buf\n * @returns {PreKey}\n */\n static deserialise(buf) {\n TypeUtil.assert_is_instance(ArrayBuffer, buf);\n return PreKey.decode(new CBOR.Decoder(buf));\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n TypeUtil.assert_is_instance(CBOR.Encoder, e);\n e.object(3);\n e.u8(0);\n e.u8(this.version);\n e.u8(1);\n e.u16(this.key_id);\n e.u8(2);\n return this.key_pair.encode(e);\n }\n\n /**\n * @param {!CBOR.Decoder} d\n * @returns {PreKey}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n const self = ClassUtil.new_instance(PreKey);\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0:\n self.version = d.u8();\n break;\n case 1:\n self.key_id = d.u16();\n break;\n case 2:\n self.key_pair = KeyPair.decode(d);\n break;\n default:\n d.skip();\n }\n }\n\n TypeUtil.assert_is_integer(self.version);\n TypeUtil.assert_is_integer(self.key_id);\n TypeUtil.assert_is_instance(KeyPair, self.key_pair);\n\n return self;\n }\n}\n\nmodule.exports = PreKey;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/keys/PreKey.js\n// module id = 24\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst TypeUtil = require('../util/TypeUtil');\n\nconst PublicKey = require('../keys/PublicKey');\n\n/** @module message */\n\n/**\n * @class Header\n * @throws {DontCallConstructor}\n */\nclass Header {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /**\n * @param {!number} counter\n * @param {!number} prev_counter\n * @param {!keys.PublicKey} ratchet_key\n * @returns {Header} - `this`\n */\n static new(counter, prev_counter, ratchet_key) {\n TypeUtil.assert_is_integer(counter);\n TypeUtil.assert_is_integer(prev_counter);\n TypeUtil.assert_is_instance(PublicKey, ratchet_key);\n\n const hd = ClassUtil.new_instance(Header);\n\n hd.counter = counter;\n hd.prev_counter = prev_counter;\n hd.ratchet_key = ratchet_key;\n\n Object.freeze(hd);\n return hd;\n }\n\n /** @returns {ArrayBuffer} - The serialized header */\n serialise() {\n const e = new CBOR.Encoder();\n this.encode(e);\n return e.get_buffer();\n }\n\n /**\n * @param {!ArrayBuffer} buf\n * @returns {Header}\n */\n static deserialise(buf) {\n TypeUtil.assert_is_instance(ArrayBuffer, buf);\n\n const d = new CBOR.Decoder(buf);\n return Header.decode(d);\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n e.object(3);\n e.u8(0);\n e.u32(this.counter);\n e.u8(1);\n e.u32(this.prev_counter);\n e.u8(2);\n return this.ratchet_key.encode(e);\n }\n\n /**\n * @param {!CBOR.Decoder} d\n * @returns {Header}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n let counter = null;\n let prev_counter = null;\n let ratchet_key = null;\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0:\n counter = d.u32();\n break;\n case 1:\n prev_counter = d.u32();\n break;\n case 2:\n ratchet_key = PublicKey.decode(d);\n break;\n\n default:\n d.skip();\n }\n }\n\n return Header.new(counter, prev_counter, ratchet_key);\n }\n}\n\nmodule.exports = Header;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/message/Header.js\n// module id = 25\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst KeyDerivationUtil = require('../util/KeyDerivationUtil');\nconst MemoryUtil = require('../util/MemoryUtil');\n\nconst CipherKey = require('./CipherKey');\nconst MacKey = require('./MacKey');\nconst HeadKey = require('./HeadKey');\n\n/** @module derived */\n\n/**\n * @class DerivedSecrets\n * @throws {DontCallConstructor}\n */\nclass DerivedSecrets {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /**\n * @param {!Array<number>} input\n * @param {!Uint8Array} salt\n * @param {!string} info\n * @returns {DerivedSecrets} - `this`\n */\n static kdf_init(input, salt, info) {\n const byte_length = 128;\n\n const output_key_material = KeyDerivationUtil.hkdf(salt, input, info, byte_length);\n\n const cipher_key = new Uint8Array(output_key_material.buffer.slice(0, 32));\n const mac_key = new Uint8Array(output_key_material.buffer.slice(32, 64));\n const head_key = new Uint8Array(output_key_material.buffer.slice(64, 96));\n const next_head_key = new Uint8Array(output_key_material.buffer.slice(96, 128));\n\n MemoryUtil.zeroize(output_key_material.buffer);\n\n const ds = ClassUtil.new_instance(DerivedSecrets);\n /** @type {derived.CipherKey} */\n ds.cipher_key = CipherKey.new(cipher_key);\n /** @type {derived.MacKey} */\n ds.mac_key = MacKey.new(mac_key);\n /** @type {derived.HeadKey} */\n ds.head_key_alice = HeadKey.new(head_key);\n /** @type {derived.HeadKey} */\n ds.next_head_key_bob = HeadKey.new(next_head_key);\n return ds;\n }\n\n /**\n * @param {!Array<number>} input\n * @param {!Uint8Array} salt\n * @param {!string} info\n * @returns {DerivedSecrets} - `this`\n */\n static kdf(input, salt, info) {\n const byte_length = 96;\n\n const output_key_material = KeyDerivationUtil.hkdf(salt, input, info, byte_length);\n\n const cipher_key = new Uint8Array(output_key_material.buffer.slice(0, 32));\n const mac_key = new Uint8Array(output_key_material.buffer.slice(32, 64));\n const next_head_key = new Uint8Array(output_key_material.buffer.slice(64, 96));\n\n MemoryUtil.zeroize(output_key_material.buffer);\n\n const ds = ClassUtil.new_instance(DerivedSecrets);\n /** @type {derived.CipherKey} */\n ds.cipher_key = CipherKey.new(cipher_key);\n /** @type {derived.MacKey} */\n ds.mac_key = MacKey.new(mac_key);\n /** @type {derived.HeadKey} */\n ds.next_head_key = HeadKey.new(next_head_key);\n return ds;\n }\n\n /**\n * @param {!Array<number>} input - Initial key material (usually the Master Key) in byte array format\n * @param {!string} info - Key Derivation Data\n * @returns {DerivedSecrets}\n */\n static kdf_without_salt(input, info) {\n return this.kdf_init(input, new Uint8Array(0), info);\n }\n}\n\nmodule.exports = DerivedSecrets;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/derived/DerivedSecrets.js\n// module id = 26\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\nconst sodium = require('libsodium-wrappers-sumo');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst TypeUtil = require('../util/TypeUtil');\n\n/** @module derived */\n\n/**\n * @class CipherKey\n * @throws {DontCallConstructor}\n */\nclass CipherKey {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /**\n * @param {!Uint8Array} key\n * @returns {CipherKey} - `this`\n */\n static new(key) {\n TypeUtil.assert_is_instance(Uint8Array, key);\n\n const ck = ClassUtil.new_instance(CipherKey);\n /** @type {Uint8Array} */\n ck.key = key;\n return ck;\n }\n\n /**\n * @param {!(ArrayBuffer|string|Uint8Array)} plaintext - The text to encrypt\n * @param {!Uint8Array} nonce - Counter as nonce\n * @returns {Uint8Array} - Encrypted payload\n */\n encrypt(plaintext, nonce) {\n // @todo Re-validate if the ArrayBuffer check is needed (Prerequisite: Integration tests)\n if (plaintext instanceof ArrayBuffer && plaintext.byteLength !== undefined) {\n plaintext = new Uint8Array(plaintext);\n }\n\n return sodium.crypto_stream_chacha20_xor(plaintext, nonce, this.key, 'uint8array');\n }\n\n /**\n * @param {!Uint8Array} ciphertext\n * @param {!Uint8Array} nonce\n * @returns {Uint8Array}\n */\n decrypt(ciphertext, nonce) {\n return this.encrypt(ciphertext, nonce);\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n e.object(1);\n e.u8(0);\n return e.bytes(this.key);\n }\n\n /**\n * @param {!CBOR.Encoder} d\n * @returns {CipherKey}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n let key_bytes = null;\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0:\n key_bytes = new Uint8Array(d.bytes());\n break;\n default:\n d.skip();\n }\n }\n return CipherKey.new(key_bytes);\n }\n}\n\nmodule.exports = CipherKey;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/derived/CipherKey.js\n// module id = 27\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\n/** @module keys */\n\n/** @class PreKeyAuth */\nclass PreKeyAuth {\n\n /** @type {string} */\n static get INVALID() {\n return 'Invalid';\n }\n\n /** @type {string} */\n static get UNKNOWN() {\n return 'Unknown';\n }\n\n /** @type {string} */\n static get VALID() {\n return 'Valid';\n }\n}\n\nmodule.exports = PreKeyAuth;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/keys/PreKeyAuth.js\n// module id = 28\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\n/** @module session */\n\n/** @class PreKeyStore */\nfunction PreKeyStore() {\n}\n\n/** @type {Array<number>} */\nPreKeyStore.prekeys = [];\n\n/**\n * @param {!number} prekey_id\n * @returns {void}\n * @throws {Error}\n */\nPreKeyStore.prototype.get_prekey = function (prekey_id) {\n throw Error('Virtual function unimplemented');\n};\n\n/**\n * @param {!number} prekey_id\n * @returns {void}\n * @throws {Error}\n */\nPreKeyStore.prototype.remove = function (prekey_id) {\n throw Error('Virtual function unimplemented');\n};\n\nmodule.exports = PreKeyStore;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/session/PreKeyStore.js\n// module id = 29\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst MemoryUtil = require('../util/MemoryUtil');\nconst TypeUtil = require('../util/TypeUtil');\n\nconst DecodeError = require('../errors/DecodeError');\nconst DecryptError = require('../errors/DecryptError');\nconst ProteusError = require('../errors/ProteusError');\n\nconst IdentityKey = require('../keys/IdentityKey');\nconst IdentityKeyPair = require('../keys/IdentityKeyPair');\nconst KeyPair = require('../keys/KeyPair');\nconst PreKey = require('../keys/PreKey');\nconst PreKeyBundle = require('../keys/PreKeyBundle');\nconst PublicKey = require('../keys/PublicKey');\n\nconst HeaderMessage = require('../message/HeaderMessage');\nconst Envelope = require('../message/Envelope');\nconst PreKeyMessage = require('../message/PreKeyMessage');\n\nconst PreKeyStore = require('./PreKeyStore');\n\n/** @module session */\n\n/**\n * @class Session\n * @throws {DontCallConstructor}\n */\nclass Session {\n constructor() {\n this.local_identity = null;\n this.pending_prekey = null;\n this.remote_identity = null;\n this.session_states = [];\n this.version = 1;\n\n throw new DontCallConstructor(this);\n }\n\n /** @type {number} */\n static get MAX_RECV_CHAINS() {\n return 5;\n }\n\n /** @type {number} */\n static get MAX_SESSION_STATES() {\n return 100;\n }\n\n /**\n * @param {!keys.IdentityKeyPair} local_identity - Alice's Identity Key Pair\n * @param {!keys.PreKeyBundle} remote_pkbundle - Bob's Pre-Key Bundle\n * @returns {Promise<Session>}\n */\n static init_from_prekey(local_identity, remote_pkbundle) {\n return new Promise((resolve) => {\n TypeUtil.assert_is_instance(IdentityKeyPair, local_identity);\n TypeUtil.assert_is_instance(PreKeyBundle, remote_pkbundle);\n\n const alice_base = KeyPair.new();\n\n const state = SessionState.init_as_alice(local_identity, alice_base, remote_pkbundle);\n\n const session = ClassUtil.new_instance(this);\n session.local_identity = local_identity;\n session.remote_identity = remote_pkbundle.identity_key;\n session.pending_prekey = [remote_pkbundle.prekey_id, alice_base.public_key];\n session.session_states = [];\n\n session._insert_session_state(state);\n return resolve(session);\n });\n }\n\n /**\n * @param {!keys.IdentityKeyPair} our_identity\n * @param {!session.PreKeyStore} prekey_store\n * @param {!message.Envelope} envelope\n * @returns {Promise<Array<Session|Uint8Array>>}\n * @throws {errors.DecryptError.InvalidMessage}\n * @throws {errors.DecryptError.PrekeyNotFound}\n */\n static init_from_message(our_identity, prekey_store, envelope) {\n return new Promise((resolve, reject) => {\n TypeUtil.assert_is_instance(IdentityKeyPair, our_identity);\n TypeUtil.assert_is_instance(PreKeyStore, prekey_store);\n TypeUtil.assert_is_instance(Envelope, envelope);\n\n const pkmsg = (() => {\n if (envelope.message instanceof HeaderMessage) {\n throw new DecryptError.InvalidMessage(\n 'Can\\'t initialise a session from a HeaderMessage.', DecryptError.CODE.CASE_201\n );\n } else if (envelope.message instanceof PreKeyMessage) {\n return envelope.message;\n } else {\n throw new DecryptError.InvalidMessage(\n 'Unknown message format: The message is neither a \"HeaderMessage\" nor a \"PreKeyMessage\".', DecryptError.CODE.CASE_202\n );\n }\n })();\n\n const session = ClassUtil.new_instance(Session);\n session.local_identity = our_identity;\n session.remote_identity = pkmsg.identity_key;\n session.pending_prekey = null;\n session.session_states = [];\n\n return session._new_state(prekey_store, pkmsg).then((state) => {\n const plain = state.decrypt(envelope, pkmsg.message);\n session._insert_session_state(state);\n\n if (pkmsg.prekey_id < PreKey.MAX_PREKEY_ID) {\n MemoryUtil.zeroize(prekey_store.prekeys[pkmsg.prekey_id]);\n return prekey_store.remove(pkmsg.prekey_id).then(() => resolve([session, plain])).catch((error) => {\n reject(new DecryptError.PrekeyNotFound(`Could not delete PreKey: ${error.message}`, DecryptError.CODE.CASE_203));\n });\n } else {\n return resolve([session, plain]);\n }\n }).catch(reject);\n });\n }\n\n /**\n * @param {!session.PreKeyStore} pre_key_store\n * @param {!message.PreKeyMessage} pre_key_message\n * @returns {Promise<session.SessionState>}\n * @private\n * @throws {errors.ProteusError}\n */\n _new_state(pre_key_store, pre_key_message) {\n return pre_key_store.get_prekey(pre_key_message.prekey_id).then((pre_key) => {\n if (pre_key) {\n return SessionState.init_as_bob(\n this.local_identity,\n pre_key.key_pair,\n pre_key_message.identity_key,\n pre_key_message.base_key\n );\n }\n throw new ProteusError('Unable to get PreKey from PreKey store.', ProteusError.prototype.CODE.CASE_101);\n });\n }\n\n /**\n * @param {!session.SessionState} state\n * @returns {boolean}\n * @private\n */\n _insert_session_state(state) {\n this.session_states.unshift(state);\n\n const size = this.session_states.length;\n if (size < Session.MAX_SESSION_STATES) {\n return true;\n }\n\n // if we get here, it means that we have more than MAX_SESSION_STATES and\n // we need to evict the oldest one.\n return delete this.session_states[size - 1];\n }\n\n /** @returns {keys.PublicKey} */\n get_local_identity() {\n return this.local_identity.public_key;\n }\n\n /**\n * @param {!(string|Uint8Array)} plaintext - The plaintext which needs to be encrypted\n * @param {number} confuse_pre_key_id - Use to create confused pre-key message\n * @return {Promise<message.Envelope>} Encrypted message\n */\n encrypt(plaintext, confuse_pre_key_id) {\n return new Promise((resolve, reject) => {\n const state = this.session_states[0];\n\n if (!state) {\n return reject(new ProteusError(\n 'Could not find session.', ProteusError.prototype.CODE.CASE_102\n ));\n }\n\n return resolve(state.encrypt(\n this.local_identity.public_key,\n this.pending_prekey,\n plaintext,\n confuse_pre_key_id\n ));\n });\n }\n\n /**\n * @param {!session.PreKeyStore} prekey_store\n * @param {!message.Envelope} envelope\n * @returns {Promise<Uint8Array>}\n * @throws {errors.DecryptError}\n */\n decrypt(prekey_store, envelope) {\n return new Promise((resolve) => {\n TypeUtil.assert_is_instance(PreKeyStore, prekey_store);\n TypeUtil.assert_is_instance(Envelope, envelope);\n\n const msg = envelope.message;\n if (msg instanceof HeaderMessage) {\n return resolve(this._try_decrypt_header_message(envelope, msg, 0));\n } else if (msg instanceof PreKeyMessage) {\n const actual_fingerprint = msg.identity_key.fingerprint();\n const expected_fingerprint = this.remote_identity.fingerprint();\n if (actual_fingerprint !== expected_fingerprint) {\n const message = `Fingerprints do not match: We expected '${expected_fingerprint}', but received '${actual_fingerprint}'.`;\n throw new DecryptError.RemoteIdentityChanged(message, DecryptError.CODE.CASE_204);\n }\n return resolve(this._decrypt_prekey_message(envelope, msg, prekey_store));\n } else {\n throw new DecryptError('Unknown message type.', DecryptError.CODE.CASE_200);\n }\n });\n }\n\n /**\n * @param {!message.Envelope} envelope\n * @param {!message.Message} msg\n * @param {!session.PreKeyStore} prekey_store\n * @private\n * @returns {Promise<Uint8Array>}\n * @throws {errors.DecryptError}\n */\n _decrypt_prekey_message(envelope, msg, prekey_store) {\n return Promise.resolve().then(() => this._decrypt_header_message(envelope, msg.message)).catch((error) => {\n const try_create_new_state_and_decrypt = () => {\n return this._new_state(prekey_store, msg).then((state) => {\n const plaintext = state.decrypt(envelope, msg.message);\n if (msg.prekey_id !== PreKey.MAX_PREKEY_ID) {\n MemoryUtil.zeroize(prekey_store.prekeys[msg.prekey_id]);\n prekey_store.remove(msg.prekey_id);\n }\n\n this._insert_session_state(state);\n this.pending_prekey = null;\n\n return plaintext;\n });\n };\n\n if (error instanceof DecryptError.InvalidMessage) {\n // session state not exist\n try_create_new_state_and_decrypt();\n }\n\n if (error instanceof DecryptError.HeaderDecryptionFailed) {\n // we had tried it once already\n let fail_counter = 1;\n const state_size = this.session_states.length;\n if (state_size === fail_counter) {\n return try_create_new_state_and_decrypt();\n }\n // start from index 1\n return this._try_decrypt_header_message(envelope, msg.message, 1)\n .catch((err) => {\n if (err instanceof DecryptError.HeaderDecryptionFailed) {\n return try_create_new_state_and_decrypt();\n } else {\n throw err;\n }\n });\n }\n\n throw error;\n });\n }\n\n /**\n * @param {!message.Envelope} envelope\n * @param {!message.Message} message\n * @param {!number} start\n * @private\n * @returns {Promise<Uint8Array>}\n */\n _try_decrypt_header_message(envelope, message, start) {\n return new Promise((resolve, reject) => {\n let fail_counter = start;\n const state_size = this.session_states.length;\n const HeaderDecryptionFailed = DecryptError.HeaderDecryptionFailed;\n\n const try_decrypt_header_message = () => this._decrypt_header_message(envelope, message, fail_counter);\n const handle_error = (err) => {\n if (err instanceof HeaderDecryptionFailed) {\n fail_counter++;\n if (fail_counter === state_size) {\n reject(new HeaderDecryptionFailed('All states failed', DecryptError.CODE.CASE_216));\n }\n Promise.resolve()\n .then(try_decrypt_header_message)\n .then(resolve)\n .catch(handle_error);\n } else {\n // if we get here, it means that we had decrypted header, but something else has gone wrong\n reject(err);\n }\n };\n\n Promise.resolve()\n .then(try_decrypt_header_message)\n .then(resolve)\n .catch(handle_error);\n });\n }\n\n /**\n * @param {!message.Envelope} envelope\n * @param {!message.Message} msg\n * @param {number} state_index\n * @private\n * @returns {Uint8Array}\n */\n _decrypt_header_message(envelope, msg, state_index = 0) {\n let state = this.session_states[state_index];\n if (!state) {\n throw new DecryptError.InvalidMessage('Local session not found.', DecryptError.CODE.CASE_205);\n }\n\n // serialise and de-serialise for a deep clone\n // THIS IS IMPORTANT, DO NOT MUTATE THE SESSION STATE IN-PLACE\n // mutating in-place can lead to undefined behavior and undefined state in edge cases\n state = SessionState.deserialise(state.serialise());\n\n const plaintext = state.decrypt(envelope, msg);\n\n this.pending_prekey = null;\n\n // Avoid `unshift` operation when possible\n if (state_index === 0) {\n this.session_states[0] = state;\n } else {\n this.session_states.splice(state_index, 1);\n this._insert_session_state(state);\n }\n\n return plaintext;\n }\n\n /**\n * @returns {ArrayBuffer}\n */\n serialise() {\n const e = new CBOR.Encoder();\n this.encode(e);\n return e.get_buffer();\n }\n\n /**\n * @param {!keys.IdentityKeyPair} local_identity\n * @param {!ArrayBuffer} buf\n * @returns {Session}\n */\n static deserialise(local_identity, buf) {\n TypeUtil.assert_is_instance(IdentityKeyPair, local_identity);\n TypeUtil.assert_is_instance(ArrayBuffer, buf);\n\n const d = new CBOR.Decoder(buf);\n return this.decode(local_identity, d);\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {void}\n */\n encode(e) {\n e.object(5);\n e.u8(0);\n e.u8(this.version);\n e.u8(1);\n this.local_identity.public_key.encode(e);\n e.u8(2);\n this.remote_identity.encode(e);\n\n e.u8(3);\n if (this.pending_prekey) {\n e.object(2);\n e.u8(0);\n e.u16(this.pending_prekey[0]);\n e.u8(1);\n this.pending_prekey[1].encode(e);\n } else {\n e.null();\n }\n\n e.u8(4);\n e.array(this.session_states.length);\n this.session_states.map((session_state) => session_state.encode(e));\n }\n\n /**\n * @param {!keys.IdentityKeyPair} local_identity\n * @param {!CBOR.Decoder} d\n * @returns {Session}\n */\n static decode(local_identity, d) {\n TypeUtil.assert_is_instance(IdentityKeyPair, local_identity);\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n const self = ClassUtil.new_instance(this);\n\n const nprops = d.object();\n for (let n = 0; n <= nprops - 1; n++) {\n switch (d.u8()) {\n case 0: {\n self.version = d.u8();\n break;\n }\n case 1: {\n const ik = IdentityKey.decode(d);\n if (local_identity.public_key.fingerprint() !== ik.fingerprint()) {\n throw new DecodeError.LocalIdentityChanged(null, DecodeError.CODE.CASE_300);\n }\n self.local_identity = local_identity;\n break;\n }\n case 2: {\n self.remote_identity = IdentityKey.decode(d);\n break;\n }\n case 3: {\n switch (d.optional(() => d.object())) {\n case null:\n self.pending_prekey = null;\n break;\n case 2:\n self.pending_prekey = [null, null];\n for (let k = 0; k <= 1; ++k) {\n switch (d.u8()) {\n case 0:\n self.pending_prekey[0] = d.u16();\n break;\n case 1:\n self.pending_prekey[1] = PublicKey.decode(d);\n }\n }\n break;\n default:\n throw new DecodeError.InvalidType(null, DecodeError.CODE.CASE_301);\n }\n break;\n }\n case 4: {\n self.session_states = [];\n let len = d.array();\n while (len--) {\n self.session_states.push(SessionState.decode(d));\n }\n break;\n }\n default: {\n d.skip();\n }\n }\n }\n\n TypeUtil.assert_is_integer(self.version);\n TypeUtil.assert_is_instance(IdentityKeyPair, self.local_identity);\n TypeUtil.assert_is_instance(IdentityKey, self.remote_identity);\n TypeUtil.assert_is_instance(Array, self.session_states);\n\n return self;\n }\n}\n\nmodule.exports = Session;\n\nconst SessionState = require('./SessionState');\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/session/Session.js\n// module id = 30\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst ProteusError = require('../errors/ProteusError');\nconst TypeUtil = require('../util/TypeUtil');\n\n/** @module util */\n\n/**\n * Concatenates array buffers (usually 8-bit unsigned).\n */\nconst ArrayUtil = {\n /**\n * @param {!Array<ArrayBuffer>} buffers\n * @returns {Array<ArrayBuffer>}\n */\n concatenate_array_buffers(buffers) {\n TypeUtil.assert_is_instance(Array, buffers);\n\n return buffers.reduce((a, b) => {\n const buf = new a.constructor(a.byteLength + b.byteLength);\n buf.set(a, 0);\n buf.set(b, a.byteLength);\n return buf;\n });\n },\n\n /**\n * @param {!(Array<number>|Uint8Array)} array\n * @returns {void}\n * @throws {errors.ProteusError}\n */\n assert_is_not_zeros(array) {\n let only_zeroes = true;\n for (let val in array) {\n if (val > 0) {\n only_zeroes = false;\n break;\n }\n }\n\n if (only_zeroes === true) {\n throw new ProteusError('Array consists only of zeroes.', ProteusError.prototype.CODE.CASE_100);\n }\n },\n};\n\nmodule.exports = ArrayUtil;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/util/ArrayUtil.js\n// module id = 31\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst TypeUtil = require('../util/TypeUtil');\n\nconst CipherKey = require('../derived/CipherKey');\nconst MacKey = require('../derived/MacKey');\n\n/** @module session */\n\n/**\n * @class MessageKeys\n * @throws {DontCallConstructor}\n */\nclass MessageKeys {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /**\n * @param {!derived.CipherKey} cipher_key\n * @param {!derived.MacKey} mac_key\n * @param {!number} counter\n * @returns {MessageKeys} - `this`\n */\n static new(cipher_key, mac_key, counter) {\n TypeUtil.assert_is_instance(CipherKey, cipher_key);\n TypeUtil.assert_is_instance(MacKey, mac_key);\n TypeUtil.assert_is_integer(counter);\n\n const mk = ClassUtil.new_instance(MessageKeys);\n mk.cipher_key = cipher_key;\n mk.mac_key = mac_key;\n mk.counter = counter;\n return mk;\n }\n\n /**\n * @returns {Uint8Array}\n * @private\n */\n _counter_as_nonce() {\n const nonce = new ArrayBuffer(8);\n new DataView(nonce).setUint32(0, this.counter);\n return new Uint8Array(nonce);\n }\n\n /**\n * @param {!(string|Uint8Array)} plaintext\n * @returns {Uint8Array}\n */\n encrypt(plaintext) {\n return this.cipher_key.encrypt(plaintext, this._counter_as_nonce());\n }\n\n /**\n * @param {!Uint8Array} ciphertext\n * @returns {Uint8Array}\n */\n decrypt(ciphertext) {\n return this.cipher_key.decrypt(ciphertext, this._counter_as_nonce());\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n e.object(3);\n e.u8(0);\n this.cipher_key.encode(e);\n e.u8(1);\n this.mac_key.encode(e);\n e.u8(2);\n return e.u32(this.counter);\n }\n\n /**\n * @param {!CBOR.Decoder} d\n * @returns {MessageKeys}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n const self = ClassUtil.new_instance(MessageKeys);\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0:\n self.cipher_key = CipherKey.decode(d);\n break;\n case 1:\n self.mac_key = MacKey.decode(d);\n break;\n case 2:\n self.counter = d.u32();\n break;\n default:\n d.skip();\n }\n }\n\n TypeUtil.assert_is_instance(CipherKey, self.cipher_key);\n TypeUtil.assert_is_instance(MacKey, self.mac_key);\n TypeUtil.assert_is_integer(self.counter);\n\n return self;\n }\n}\n\nmodule.exports = MessageKeys;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/session/MessageKeys.js\n// module id = 32\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nmodule.exports = {\n errors: {\n ProteusError: require('./proteus/errors/ProteusError'),\n DecodeError: require('./proteus/errors/DecodeError'),\n DecryptError: require('./proteus/errors/DecryptError'),\n InputError: require('./proteus/errors/InputError'),\n },\n\n keys: {\n IdentityKey: require('./proteus/keys/IdentityKey'),\n IdentityKeyPair: require('./proteus/keys/IdentityKeyPair'),\n KeyPair: require('./proteus/keys/KeyPair'),\n PreKeyAuth: require('./proteus/keys/PreKeyAuth'),\n PreKeyBundle: require('./proteus/keys/PreKeyBundle'),\n PreKey: require('./proteus/keys/PreKey'),\n PublicKey: require('./proteus/keys/PublicKey'),\n SecretKey: require('./proteus/keys/SecretKey'),\n },\n\n message: {\n Message: require('./proteus/message/Message'),\n PreKeyMessage: require('./proteus/message/PreKeyMessage'),\n Envelope: require('./proteus/message/Envelope'),\n Header: require('./proteus/message/Header'),\n HeaderMessage: require('./proteus/message/HeaderMessage'),\n },\n\n session: {\n PreKeyStore: require('./proteus/session/PreKeyStore'),\n Session: require('./proteus/session/Session'),\n },\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus.js\n// module id = 33\n// module chunks = 0","(function(nacl) {\n'use strict';\n\n// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri.\n// Public domain.\n//\n// Implementation derived from TweetNaCl version 20140427.\n// See for details: http://tweetnacl.cr.yp.to/\n\nvar gf = function(init) {\n var i, r = new Float64Array(16);\n if (init) for (i = 0; i < init.length; i++) r[i] = init[i];\n return r;\n};\n\n// Pluggable, initialized in high-level API below.\nvar randombytes = function(/* x, n */) { throw new Error('no PRNG'); };\n\nvar _0 = new Uint8Array(16);\nvar _9 = new Uint8Array(32); _9[0] = 9;\n\nvar gf0 = gf(),\n gf1 = gf([1]),\n _121665 = gf([0xdb41, 1]),\n D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]),\n D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]),\n X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]),\n Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]),\n I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);\n\nfunction ts64(x, i, h, l) {\n x[i] = (h >> 24) & 0xff;\n x[i+1] = (h >> 16) & 0xff;\n x[i+2] = (h >> 8) & 0xff;\n x[i+3] = h & 0xff;\n x[i+4] = (l >> 24) & 0xff;\n x[i+5] = (l >> 16) & 0xff;\n x[i+6] = (l >> 8) & 0xff;\n x[i+7] = l & 0xff;\n}\n\nfunction vn(x, xi, y, yi, n) {\n var i,d = 0;\n for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i];\n return (1 & ((d - 1) >>> 8)) - 1;\n}\n\nfunction crypto_verify_16(x, xi, y, yi) {\n return vn(x,xi,y,yi,16);\n}\n\nfunction crypto_verify_32(x, xi, y, yi) {\n return vn(x,xi,y,yi,32);\n}\n\nfunction core_salsa20(o, p, k, c) {\n var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,\n j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,\n j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,\n j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,\n j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,\n j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,\n j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,\n j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,\n j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,\n j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,\n j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,\n j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,\n j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,\n j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,\n j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,\n j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;\n\n var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,\n x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,\n x15 = j15, u;\n\n for (var i = 0; i < 20; i += 2) {\n u = x0 + x12 | 0;\n x4 ^= u<<7 | u>>>(32-7);\n u = x4 + x0 | 0;\n x8 ^= u<<9 | u>>>(32-9);\n u = x8 + x4 | 0;\n x12 ^= u<<13 | u>>>(32-13);\n u = x12 + x8 | 0;\n x0 ^= u<<18 | u>>>(32-18);\n\n u = x5 + x1 | 0;\n x9 ^= u<<7 | u>>>(32-7);\n u = x9 + x5 | 0;\n x13 ^= u<<9 | u>>>(32-9);\n u = x13 + x9 | 0;\n x1 ^= u<<13 | u>>>(32-13);\n u = x1 + x13 | 0;\n x5 ^= u<<18 | u>>>(32-18);\n\n u = x10 + x6 | 0;\n x14 ^= u<<7 | u>>>(32-7);\n u = x14 + x10 | 0;\n x2 ^= u<<9 | u>>>(32-9);\n u = x2 + x14 | 0;\n x6 ^= u<<13 | u>>>(32-13);\n u = x6 + x2 | 0;\n x10 ^= u<<18 | u>>>(32-18);\n\n u = x15 + x11 | 0;\n x3 ^= u<<7 | u>>>(32-7);\n u = x3 + x15 | 0;\n x7 ^= u<<9 | u>>>(32-9);\n u = x7 + x3 | 0;\n x11 ^= u<<13 | u>>>(32-13);\n u = x11 + x7 | 0;\n x15 ^= u<<18 | u>>>(32-18);\n\n u = x0 + x3 | 0;\n x1 ^= u<<7 | u>>>(32-7);\n u = x1 + x0 | 0;\n x2 ^= u<<9 | u>>>(32-9);\n u = x2 + x1 | 0;\n x3 ^= u<<13 | u>>>(32-13);\n u = x3 + x2 | 0;\n x0 ^= u<<18 | u>>>(32-18);\n\n u = x5 + x4 | 0;\n x6 ^= u<<7 | u>>>(32-7);\n u = x6 + x5 | 0;\n x7 ^= u<<9 | u>>>(32-9);\n u = x7 + x6 | 0;\n x4 ^= u<<13 | u>>>(32-13);\n u = x4 + x7 | 0;\n x5 ^= u<<18 | u>>>(32-18);\n\n u = x10 + x9 | 0;\n x11 ^= u<<7 | u>>>(32-7);\n u = x11 + x10 | 0;\n x8 ^= u<<9 | u>>>(32-9);\n u = x8 + x11 | 0;\n x9 ^= u<<13 | u>>>(32-13);\n u = x9 + x8 | 0;\n x10 ^= u<<18 | u>>>(32-18);\n\n u = x15 + x14 | 0;\n x12 ^= u<<7 | u>>>(32-7);\n u = x12 + x15 | 0;\n x13 ^= u<<9 | u>>>(32-9);\n u = x13 + x12 | 0;\n x14 ^= u<<13 | u>>>(32-13);\n u = x14 + x13 | 0;\n x15 ^= u<<18 | u>>>(32-18);\n }\n x0 = x0 + j0 | 0;\n x1 = x1 + j1 | 0;\n x2 = x2 + j2 | 0;\n x3 = x3 + j3 | 0;\n x4 = x4 + j4 | 0;\n x5 = x5 + j5 | 0;\n x6 = x6 + j6 | 0;\n x7 = x7 + j7 | 0;\n x8 = x8 + j8 | 0;\n x9 = x9 + j9 | 0;\n x10 = x10 + j10 | 0;\n x11 = x11 + j11 | 0;\n x12 = x12 + j12 | 0;\n x13 = x13 + j13 | 0;\n x14 = x14 + j14 | 0;\n x15 = x15 + j15 | 0;\n\n o[ 0] = x0 >>> 0 & 0xff;\n o[ 1] = x0 >>> 8 & 0xff;\n o[ 2] = x0 >>> 16 & 0xff;\n o[ 3] = x0 >>> 24 & 0xff;\n\n o[ 4] = x1 >>> 0 & 0xff;\n o[ 5] = x1 >>> 8 & 0xff;\n o[ 6] = x1 >>> 16 & 0xff;\n o[ 7] = x1 >>> 24 & 0xff;\n\n o[ 8] = x2 >>> 0 & 0xff;\n o[ 9] = x2 >>> 8 & 0xff;\n o[10] = x2 >>> 16 & 0xff;\n o[11] = x2 >>> 24 & 0xff;\n\n o[12] = x3 >>> 0 & 0xff;\n o[13] = x3 >>> 8 & 0xff;\n o[14] = x3 >>> 16 & 0xff;\n o[15] = x3 >>> 24 & 0xff;\n\n o[16] = x4 >>> 0 & 0xff;\n o[17] = x4 >>> 8 & 0xff;\n o[18] = x4 >>> 16 & 0xff;\n o[19] = x4 >>> 24 & 0xff;\n\n o[20] = x5 >>> 0 & 0xff;\n o[21] = x5 >>> 8 & 0xff;\n o[22] = x5 >>> 16 & 0xff;\n o[23] = x5 >>> 24 & 0xff;\n\n o[24] = x6 >>> 0 & 0xff;\n o[25] = x6 >>> 8 & 0xff;\n o[26] = x6 >>> 16 & 0xff;\n o[27] = x6 >>> 24 & 0xff;\n\n o[28] = x7 >>> 0 & 0xff;\n o[29] = x7 >>> 8 & 0xff;\n o[30] = x7 >>> 16 & 0xff;\n o[31] = x7 >>> 24 & 0xff;\n\n o[32] = x8 >>> 0 & 0xff;\n o[33] = x8 >>> 8 & 0xff;\n o[34] = x8 >>> 16 & 0xff;\n o[35] = x8 >>> 24 & 0xff;\n\n o[36] = x9 >>> 0 & 0xff;\n o[37] = x9 >>> 8 & 0xff;\n o[38] = x9 >>> 16 & 0xff;\n o[39] = x9 >>> 24 & 0xff;\n\n o[40] = x10 >>> 0 & 0xff;\n o[41] = x10 >>> 8 & 0xff;\n o[42] = x10 >>> 16 & 0xff;\n o[43] = x10 >>> 24 & 0xff;\n\n o[44] = x11 >>> 0 & 0xff;\n o[45] = x11 >>> 8 & 0xff;\n o[46] = x11 >>> 16 & 0xff;\n o[47] = x11 >>> 24 & 0xff;\n\n o[48] = x12 >>> 0 & 0xff;\n o[49] = x12 >>> 8 & 0xff;\n o[50] = x12 >>> 16 & 0xff;\n o[51] = x12 >>> 24 & 0xff;\n\n o[52] = x13 >>> 0 & 0xff;\n o[53] = x13 >>> 8 & 0xff;\n o[54] = x13 >>> 16 & 0xff;\n o[55] = x13 >>> 24 & 0xff;\n\n o[56] = x14 >>> 0 & 0xff;\n o[57] = x14 >>> 8 & 0xff;\n o[58] = x14 >>> 16 & 0xff;\n o[59] = x14 >>> 24 & 0xff;\n\n o[60] = x15 >>> 0 & 0xff;\n o[61] = x15 >>> 8 & 0xff;\n o[62] = x15 >>> 16 & 0xff;\n o[63] = x15 >>> 24 & 0xff;\n}\n\nfunction core_hsalsa20(o,p,k,c) {\n var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,\n j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,\n j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,\n j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,\n j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,\n j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,\n j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,\n j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,\n j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,\n j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,\n j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,\n j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,\n j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,\n j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,\n j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,\n j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;\n\n var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,\n x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,\n x15 = j15, u;\n\n for (var i = 0; i < 20; i += 2) {\n u = x0 + x12 | 0;\n x4 ^= u<<7 | u>>>(32-7);\n u = x4 + x0 | 0;\n x8 ^= u<<9 | u>>>(32-9);\n u = x8 + x4 | 0;\n x12 ^= u<<13 | u>>>(32-13);\n u = x12 + x8 | 0;\n x0 ^= u<<18 | u>>>(32-18);\n\n u = x5 + x1 | 0;\n x9 ^= u<<7 | u>>>(32-7);\n u = x9 + x5 | 0;\n x13 ^= u<<9 | u>>>(32-9);\n u = x13 + x9 | 0;\n x1 ^= u<<13 | u>>>(32-13);\n u = x1 + x13 | 0;\n x5 ^= u<<18 | u>>>(32-18);\n\n u = x10 + x6 | 0;\n x14 ^= u<<7 | u>>>(32-7);\n u = x14 + x10 | 0;\n x2 ^= u<<9 | u>>>(32-9);\n u = x2 + x14 | 0;\n x6 ^= u<<13 | u>>>(32-13);\n u = x6 + x2 | 0;\n x10 ^= u<<18 | u>>>(32-18);\n\n u = x15 + x11 | 0;\n x3 ^= u<<7 | u>>>(32-7);\n u = x3 + x15 | 0;\n x7 ^= u<<9 | u>>>(32-9);\n u = x7 + x3 | 0;\n x11 ^= u<<13 | u>>>(32-13);\n u = x11 + x7 | 0;\n x15 ^= u<<18 | u>>>(32-18);\n\n u = x0 + x3 | 0;\n x1 ^= u<<7 | u>>>(32-7);\n u = x1 + x0 | 0;\n x2 ^= u<<9 | u>>>(32-9);\n u = x2 + x1 | 0;\n x3 ^= u<<13 | u>>>(32-13);\n u = x3 + x2 | 0;\n x0 ^= u<<18 | u>>>(32-18);\n\n u = x5 + x4 | 0;\n x6 ^= u<<7 | u>>>(32-7);\n u = x6 + x5 | 0;\n x7 ^= u<<9 | u>>>(32-9);\n u = x7 + x6 | 0;\n x4 ^= u<<13 | u>>>(32-13);\n u = x4 + x7 | 0;\n x5 ^= u<<18 | u>>>(32-18);\n\n u = x10 + x9 | 0;\n x11 ^= u<<7 | u>>>(32-7);\n u = x11 + x10 | 0;\n x8 ^= u<<9 | u>>>(32-9);\n u = x8 + x11 | 0;\n x9 ^= u<<13 | u>>>(32-13);\n u = x9 + x8 | 0;\n x10 ^= u<<18 | u>>>(32-18);\n\n u = x15 + x14 | 0;\n x12 ^= u<<7 | u>>>(32-7);\n u = x12 + x15 | 0;\n x13 ^= u<<9 | u>>>(32-9);\n u = x13 + x12 | 0;\n x14 ^= u<<13 | u>>>(32-13);\n u = x14 + x13 | 0;\n x15 ^= u<<18 | u>>>(32-18);\n }\n\n o[ 0] = x0 >>> 0 & 0xff;\n o[ 1] = x0 >>> 8 & 0xff;\n o[ 2] = x0 >>> 16 & 0xff;\n o[ 3] = x0 >>> 24 & 0xff;\n\n o[ 4] = x5 >>> 0 & 0xff;\n o[ 5] = x5 >>> 8 & 0xff;\n o[ 6] = x5 >>> 16 & 0xff;\n o[ 7] = x5 >>> 24 & 0xff;\n\n o[ 8] = x10 >>> 0 & 0xff;\n o[ 9] = x10 >>> 8 & 0xff;\n o[10] = x10 >>> 16 & 0xff;\n o[11] = x10 >>> 24 & 0xff;\n\n o[12] = x15 >>> 0 & 0xff;\n o[13] = x15 >>> 8 & 0xff;\n o[14] = x15 >>> 16 & 0xff;\n o[15] = x15 >>> 24 & 0xff;\n\n o[16] = x6 >>> 0 & 0xff;\n o[17] = x6 >>> 8 & 0xff;\n o[18] = x6 >>> 16 & 0xff;\n o[19] = x6 >>> 24 & 0xff;\n\n o[20] = x7 >>> 0 & 0xff;\n o[21] = x7 >>> 8 & 0xff;\n o[22] = x7 >>> 16 & 0xff;\n o[23] = x7 >>> 24 & 0xff;\n\n o[24] = x8 >>> 0 & 0xff;\n o[25] = x8 >>> 8 & 0xff;\n o[26] = x8 >>> 16 & 0xff;\n o[27] = x8 >>> 24 & 0xff;\n\n o[28] = x9 >>> 0 & 0xff;\n o[29] = x9 >>> 8 & 0xff;\n o[30] = x9 >>> 16 & 0xff;\n o[31] = x9 >>> 24 & 0xff;\n}\n\nfunction crypto_core_salsa20(out,inp,k,c) {\n core_salsa20(out,inp,k,c);\n}\n\nfunction crypto_core_hsalsa20(out,inp,k,c) {\n core_hsalsa20(out,inp,k,c);\n}\n\nvar sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);\n // \"expand 32-byte k\"\n\nfunction crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) {\n var z = new Uint8Array(16), x = new Uint8Array(64);\n var u, i;\n for (i = 0; i < 16; i++) z[i] = 0;\n for (i = 0; i < 8; i++) z[i] = n[i];\n while (b >= 64) {\n crypto_core_salsa20(x,z,k,sigma);\n for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i];\n u = 1;\n for (i = 8; i < 16; i++) {\n u = u + (z[i] & 0xff) | 0;\n z[i] = u & 0xff;\n u >>>= 8;\n }\n b -= 64;\n cpos += 64;\n mpos += 64;\n }\n if (b > 0) {\n crypto_core_salsa20(x,z,k,sigma);\n for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i];\n }\n return 0;\n}\n\nfunction crypto_stream_salsa20(c,cpos,b,n,k) {\n var z = new Uint8Array(16), x = new Uint8Array(64);\n var u, i;\n for (i = 0; i < 16; i++) z[i] = 0;\n for (i = 0; i < 8; i++) z[i] = n[i];\n while (b >= 64) {\n crypto_core_salsa20(x,z,k,sigma);\n for (i = 0; i < 64; i++) c[cpos+i] = x[i];\n u = 1;\n for (i = 8; i < 16; i++) {\n u = u + (z[i] & 0xff) | 0;\n z[i] = u & 0xff;\n u >>>= 8;\n }\n b -= 64;\n cpos += 64;\n }\n if (b > 0) {\n crypto_core_salsa20(x,z,k,sigma);\n for (i = 0; i < b; i++) c[cpos+i] = x[i];\n }\n return 0;\n}\n\nfunction crypto_stream(c,cpos,d,n,k) {\n var s = new Uint8Array(32);\n crypto_core_hsalsa20(s,n,k,sigma);\n var sn = new Uint8Array(8);\n for (var i = 0; i < 8; i++) sn[i] = n[i+16];\n return crypto_stream_salsa20(c,cpos,d,sn,s);\n}\n\nfunction crypto_stream_xor(c,cpos,m,mpos,d,n,k) {\n var s = new Uint8Array(32);\n crypto_core_hsalsa20(s,n,k,sigma);\n var sn = new Uint8Array(8);\n for (var i = 0; i < 8; i++) sn[i] = n[i+16];\n return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s);\n}\n\n/*\n* Port of Andrew Moon's Poly1305-donna-16. Public domain.\n* https://github.com/floodyberry/poly1305-donna\n*/\n\nvar poly1305 = function(key) {\n this.buffer = new Uint8Array(16);\n this.r = new Uint16Array(10);\n this.h = new Uint16Array(10);\n this.pad = new Uint16Array(8);\n this.leftover = 0;\n this.fin = 0;\n\n var t0, t1, t2, t3, t4, t5, t6, t7;\n\n t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff;\n t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff;\n t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03;\n t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff;\n t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff;\n this.r[5] = ((t4 >>> 1)) & 0x1ffe;\n t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff;\n t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81;\n t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff;\n this.r[9] = ((t7 >>> 5)) & 0x007f;\n\n this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8;\n this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8;\n this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8;\n this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8;\n this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8;\n this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8;\n this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8;\n this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8;\n};\n\npoly1305.prototype.blocks = function(m, mpos, bytes) {\n var hibit = this.fin ? 0 : (1 << 11);\n var t0, t1, t2, t3, t4, t5, t6, t7, c;\n var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;\n\n var h0 = this.h[0],\n h1 = this.h[1],\n h2 = this.h[2],\n h3 = this.h[3],\n h4 = this.h[4],\n h5 = this.h[5],\n h6 = this.h[6],\n h7 = this.h[7],\n h8 = this.h[8],\n h9 = this.h[9];\n\n var r0 = this.r[0],\n r1 = this.r[1],\n r2 = this.r[2],\n r3 = this.r[3],\n r4 = this.r[4],\n r5 = this.r[5],\n r6 = this.r[6],\n r7 = this.r[7],\n r8 = this.r[8],\n r9 = this.r[9];\n\n while (bytes >= 16) {\n t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff;\n t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff;\n t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff;\n t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff;\n t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff;\n h5 += ((t4 >>> 1)) & 0x1fff;\n t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff;\n t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff;\n t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff;\n h9 += ((t7 >>> 5)) | hibit;\n\n c = 0;\n\n d0 = c;\n d0 += h0 * r0;\n d0 += h1 * (5 * r9);\n d0 += h2 * (5 * r8);\n d0 += h3 * (5 * r7);\n d0 += h4 * (5 * r6);\n c = (d0 >>> 13); d0 &= 0x1fff;\n d0 += h5 * (5 * r5);\n d0 += h6 * (5 * r4);\n d0 += h7 * (5 * r3);\n d0 += h8 * (5 * r2);\n d0 += h9 * (5 * r1);\n c += (d0 >>> 13); d0 &= 0x1fff;\n\n d1 = c;\n d1 += h0 * r1;\n d1 += h1 * r0;\n d1 += h2 * (5 * r9);\n d1 += h3 * (5 * r8);\n d1 += h4 * (5 * r7);\n c = (d1 >>> 13); d1 &= 0x1fff;\n d1 += h5 * (5 * r6);\n d1 += h6 * (5 * r5);\n d1 += h7 * (5 * r4);\n d1 += h8 * (5 * r3);\n d1 += h9 * (5 * r2);\n c += (d1 >>> 13); d1 &= 0x1fff;\n\n d2 = c;\n d2 += h0 * r2;\n d2 += h1 * r1;\n d2 += h2 * r0;\n d2 += h3 * (5 * r9);\n d2 += h4 * (5 * r8);\n c = (d2 >>> 13); d2 &= 0x1fff;\n d2 += h5 * (5 * r7);\n d2 += h6 * (5 * r6);\n d2 += h7 * (5 * r5);\n d2 += h8 * (5 * r4);\n d2 += h9 * (5 * r3);\n c += (d2 >>> 13); d2 &= 0x1fff;\n\n d3 = c;\n d3 += h0 * r3;\n d3 += h1 * r2;\n d3 += h2 * r1;\n d3 += h3 * r0;\n d3 += h4 * (5 * r9);\n c = (d3 >>> 13); d3 &= 0x1fff;\n d3 += h5 * (5 * r8);\n d3 += h6 * (5 * r7);\n d3 += h7 * (5 * r6);\n d3 += h8 * (5 * r5);\n d3 += h9 * (5 * r4);\n c += (d3 >>> 13); d3 &= 0x1fff;\n\n d4 = c;\n d4 += h0 * r4;\n d4 += h1 * r3;\n d4 += h2 * r2;\n d4 += h3 * r1;\n d4 += h4 * r0;\n c = (d4 >>> 13); d4 &= 0x1fff;\n d4 += h5 * (5 * r9);\n d4 += h6 * (5 * r8);\n d4 += h7 * (5 * r7);\n d4 += h8 * (5 * r6);\n d4 += h9 * (5 * r5);\n c += (d4 >>> 13); d4 &= 0x1fff;\n\n d5 = c;\n d5 += h0 * r5;\n d5 += h1 * r4;\n d5 += h2 * r3;\n d5 += h3 * r2;\n d5 += h4 * r1;\n c = (d5 >>> 13); d5 &= 0x1fff;\n d5 += h5 * r0;\n d5 += h6 * (5 * r9);\n d5 += h7 * (5 * r8);\n d5 += h8 * (5 * r7);\n d5 += h9 * (5 * r6);\n c += (d5 >>> 13); d5 &= 0x1fff;\n\n d6 = c;\n d6 += h0 * r6;\n d6 += h1 * r5;\n d6 += h2 * r4;\n d6 += h3 * r3;\n d6 += h4 * r2;\n c = (d6 >>> 13); d6 &= 0x1fff;\n d6 += h5 * r1;\n d6 += h6 * r0;\n d6 += h7 * (5 * r9);\n d6 += h8 * (5 * r8);\n d6 += h9 * (5 * r7);\n c += (d6 >>> 13); d6 &= 0x1fff;\n\n d7 = c;\n d7 += h0 * r7;\n d7 += h1 * r6;\n d7 += h2 * r5;\n d7 += h3 * r4;\n d7 += h4 * r3;\n c = (d7 >>> 13); d7 &= 0x1fff;\n d7 += h5 * r2;\n d7 += h6 * r1;\n d7 += h7 * r0;\n d7 += h8 * (5 * r9);\n d7 += h9 * (5 * r8);\n c += (d7 >>> 13); d7 &= 0x1fff;\n\n d8 = c;\n d8 += h0 * r8;\n d8 += h1 * r7;\n d8 += h2 * r6;\n d8 += h3 * r5;\n d8 += h4 * r4;\n c = (d8 >>> 13); d8 &= 0x1fff;\n d8 += h5 * r3;\n d8 += h6 * r2;\n d8 += h7 * r1;\n d8 += h8 * r0;\n d8 += h9 * (5 * r9);\n c += (d8 >>> 13); d8 &= 0x1fff;\n\n d9 = c;\n d9 += h0 * r9;\n d9 += h1 * r8;\n d9 += h2 * r7;\n d9 += h3 * r6;\n d9 += h4 * r5;\n c = (d9 >>> 13); d9 &= 0x1fff;\n d9 += h5 * r4;\n d9 += h6 * r3;\n d9 += h7 * r2;\n d9 += h8 * r1;\n d9 += h9 * r0;\n c += (d9 >>> 13); d9 &= 0x1fff;\n\n c = (((c << 2) + c)) | 0;\n c = (c + d0) | 0;\n d0 = c & 0x1fff;\n c = (c >>> 13);\n d1 += c;\n\n h0 = d0;\n h1 = d1;\n h2 = d2;\n h3 = d3;\n h4 = d4;\n h5 = d5;\n h6 = d6;\n h7 = d7;\n h8 = d8;\n h9 = d9;\n\n mpos += 16;\n bytes -= 16;\n }\n this.h[0] = h0;\n this.h[1] = h1;\n this.h[2] = h2;\n this.h[3] = h3;\n this.h[4] = h4;\n this.h[5] = h5;\n this.h[6] = h6;\n this.h[7] = h7;\n this.h[8] = h8;\n this.h[9] = h9;\n};\n\npoly1305.prototype.finish = function(mac, macpos) {\n var g = new Uint16Array(10);\n var c, mask, f, i;\n\n if (this.leftover) {\n i = this.leftover;\n this.buffer[i++] = 1;\n for (; i < 16; i++) this.buffer[i] = 0;\n this.fin = 1;\n this.blocks(this.buffer, 0, 16);\n }\n\n c = this.h[1] >>> 13;\n this.h[1] &= 0x1fff;\n for (i = 2; i < 10; i++) {\n this.h[i] += c;\n c = this.h[i] >>> 13;\n this.h[i] &= 0x1fff;\n }\n this.h[0] += (c * 5);\n c = this.h[0] >>> 13;\n this.h[0] &= 0x1fff;\n this.h[1] += c;\n c = this.h[1] >>> 13;\n this.h[1] &= 0x1fff;\n this.h[2] += c;\n\n g[0] = this.h[0] + 5;\n c = g[0] >>> 13;\n g[0] &= 0x1fff;\n for (i = 1; i < 10; i++) {\n g[i] = this.h[i] + c;\n c = g[i] >>> 13;\n g[i] &= 0x1fff;\n }\n g[9] -= (1 << 13);\n\n mask = (c ^ 1) - 1;\n for (i = 0; i < 10; i++) g[i] &= mask;\n mask = ~mask;\n for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i];\n\n this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff;\n this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff;\n this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff;\n this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff;\n this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff;\n this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff;\n this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff;\n this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff;\n\n f = this.h[0] + this.pad[0];\n this.h[0] = f & 0xffff;\n for (i = 1; i < 8; i++) {\n f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0;\n this.h[i] = f & 0xffff;\n }\n\n mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff;\n mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff;\n mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff;\n mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff;\n mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff;\n mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff;\n mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff;\n mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff;\n mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff;\n mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff;\n mac[macpos+10] = (this.h[5] >>> 0) & 0xff;\n mac[macpos+11] = (this.h[5] >>> 8) & 0xff;\n mac[macpos+12] = (this.h[6] >>> 0) & 0xff;\n mac[macpos+13] = (this.h[6] >>> 8) & 0xff;\n mac[macpos+14] = (this.h[7] >>> 0) & 0xff;\n mac[macpos+15] = (this.h[7] >>> 8) & 0xff;\n};\n\npoly1305.prototype.update = function(m, mpos, bytes) {\n var i, want;\n\n if (this.leftover) {\n want = (16 - this.leftover);\n if (want > bytes)\n want = bytes;\n for (i = 0; i < want; i++)\n this.buffer[this.leftover + i] = m[mpos+i];\n bytes -= want;\n mpos += want;\n this.leftover += want;\n if (this.leftover < 16)\n return;\n this.blocks(this.buffer, 0, 16);\n this.leftover = 0;\n }\n\n if (bytes >= 16) {\n want = bytes - (bytes % 16);\n this.blocks(m, mpos, want);\n mpos += want;\n bytes -= want;\n }\n\n if (bytes) {\n for (i = 0; i < bytes; i++)\n this.buffer[this.leftover + i] = m[mpos+i];\n this.leftover += bytes;\n }\n};\n\nfunction crypto_onetimeauth(out, outpos, m, mpos, n, k) {\n var s = new poly1305(k);\n s.update(m, mpos, n);\n s.finish(out, outpos);\n return 0;\n}\n\nfunction crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {\n var x = new Uint8Array(16);\n crypto_onetimeauth(x,0,m,mpos,n,k);\n return crypto_verify_16(h,hpos,x,0);\n}\n\nfunction crypto_secretbox(c,m,d,n,k) {\n var i;\n if (d < 32) return -1;\n crypto_stream_xor(c,0,m,0,d,n,k);\n crypto_onetimeauth(c, 16, c, 32, d - 32, c);\n for (i = 0; i < 16; i++) c[i] = 0;\n return 0;\n}\n\nfunction crypto_secretbox_open(m,c,d,n,k) {\n var i;\n var x = new Uint8Array(32);\n if (d < 32) return -1;\n crypto_stream(x,0,32,n,k);\n if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1;\n crypto_stream_xor(m,0,c,0,d,n,k);\n for (i = 0; i < 32; i++) m[i] = 0;\n return 0;\n}\n\nfunction set25519(r, a) {\n var i;\n for (i = 0; i < 16; i++) r[i] = a[i]|0;\n}\n\nfunction car25519(o) {\n var i, v, c = 1;\n for (i = 0; i < 16; i++) {\n v = o[i] + c + 65535;\n c = Math.floor(v / 65536);\n o[i] = v - c * 65536;\n }\n o[0] += c-1 + 37 * (c-1);\n}\n\nfunction sel25519(p, q, b) {\n var t, c = ~(b-1);\n for (var i = 0; i < 16; i++) {\n t = c & (p[i] ^ q[i]);\n p[i] ^= t;\n q[i] ^= t;\n }\n}\n\nfunction pack25519(o, n) {\n var i, j, b;\n var m = gf(), t = gf();\n for (i = 0; i < 16; i++) t[i] = n[i];\n car25519(t);\n car25519(t);\n car25519(t);\n for (j = 0; j < 2; j++) {\n m[0] = t[0] - 0xffed;\n for (i = 1; i < 15; i++) {\n m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1);\n m[i-1] &= 0xffff;\n }\n m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1);\n b = (m[15]>>16) & 1;\n m[14] &= 0xffff;\n sel25519(t, m, 1-b);\n }\n for (i = 0; i < 16; i++) {\n o[2*i] = t[i] & 0xff;\n o[2*i+1] = t[i]>>8;\n }\n}\n\nfunction neq25519(a, b) {\n var c = new Uint8Array(32), d = new Uint8Array(32);\n pack25519(c, a);\n pack25519(d, b);\n return crypto_verify_32(c, 0, d, 0);\n}\n\nfunction par25519(a) {\n var d = new Uint8Array(32);\n pack25519(d, a);\n return d[0] & 1;\n}\n\nfunction unpack25519(o, n) {\n var i;\n for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8);\n o[15] &= 0x7fff;\n}\n\nfunction A(o, a, b) {\n for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];\n}\n\nfunction Z(o, a, b) {\n for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];\n}\n\nfunction M(o, a, b) {\n var v, c,\n t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0,\n t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0,\n t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0,\n t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0,\n b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5],\n b6 = b[6],\n b7 = b[7],\n b8 = b[8],\n b9 = b[9],\n b10 = b[10],\n b11 = b[11],\n b12 = b[12],\n b13 = b[13],\n b14 = b[14],\n b15 = b[15];\n\n v = a[0];\n t0 += v * b0;\n t1 += v * b1;\n t2 += v * b2;\n t3 += v * b3;\n t4 += v * b4;\n t5 += v * b5;\n t6 += v * b6;\n t7 += v * b7;\n t8 += v * b8;\n t9 += v * b9;\n t10 += v * b10;\n t11 += v * b11;\n t12 += v * b12;\n t13 += v * b13;\n t14 += v * b14;\n t15 += v * b15;\n v = a[1];\n t1 += v * b0;\n t2 += v * b1;\n t3 += v * b2;\n t4 += v * b3;\n t5 += v * b4;\n t6 += v * b5;\n t7 += v * b6;\n t8 += v * b7;\n t9 += v * b8;\n t10 += v * b9;\n t11 += v * b10;\n t12 += v * b11;\n t13 += v * b12;\n t14 += v * b13;\n t15 += v * b14;\n t16 += v * b15;\n v = a[2];\n t2 += v * b0;\n t3 += v * b1;\n t4 += v * b2;\n t5 += v * b3;\n t6 += v * b4;\n t7 += v * b5;\n t8 += v * b6;\n t9 += v * b7;\n t10 += v * b8;\n t11 += v * b9;\n t12 += v * b10;\n t13 += v * b11;\n t14 += v * b12;\n t15 += v * b13;\n t16 += v * b14;\n t17 += v * b15;\n v = a[3];\n t3 += v * b0;\n t4 += v * b1;\n t5 += v * b2;\n t6 += v * b3;\n t7 += v * b4;\n t8 += v * b5;\n t9 += v * b6;\n t10 += v * b7;\n t11 += v * b8;\n t12 += v * b9;\n t13 += v * b10;\n t14 += v * b11;\n t15 += v * b12;\n t16 += v * b13;\n t17 += v * b14;\n t18 += v * b15;\n v = a[4];\n t4 += v * b0;\n t5 += v * b1;\n t6 += v * b2;\n t7 += v * b3;\n t8 += v * b4;\n t9 += v * b5;\n t10 += v * b6;\n t11 += v * b7;\n t12 += v * b8;\n t13 += v * b9;\n t14 += v * b10;\n t15 += v * b11;\n t16 += v * b12;\n t17 += v * b13;\n t18 += v * b14;\n t19 += v * b15;\n v = a[5];\n t5 += v * b0;\n t6 += v * b1;\n t7 += v * b2;\n t8 += v * b3;\n t9 += v * b4;\n t10 += v * b5;\n t11 += v * b6;\n t12 += v * b7;\n t13 += v * b8;\n t14 += v * b9;\n t15 += v * b10;\n t16 += v * b11;\n t17 += v * b12;\n t18 += v * b13;\n t19 += v * b14;\n t20 += v * b15;\n v = a[6];\n t6 += v * b0;\n t7 += v * b1;\n t8 += v * b2;\n t9 += v * b3;\n t10 += v * b4;\n t11 += v * b5;\n t12 += v * b6;\n t13 += v * b7;\n t14 += v * b8;\n t15 += v * b9;\n t16 += v * b10;\n t17 += v * b11;\n t18 += v * b12;\n t19 += v * b13;\n t20 += v * b14;\n t21 += v * b15;\n v = a[7];\n t7 += v * b0;\n t8 += v * b1;\n t9 += v * b2;\n t10 += v * b3;\n t11 += v * b4;\n t12 += v * b5;\n t13 += v * b6;\n t14 += v * b7;\n t15 += v * b8;\n t16 += v * b9;\n t17 += v * b10;\n t18 += v * b11;\n t19 += v * b12;\n t20 += v * b13;\n t21 += v * b14;\n t22 += v * b15;\n v = a[8];\n t8 += v * b0;\n t9 += v * b1;\n t10 += v * b2;\n t11 += v * b3;\n t12 += v * b4;\n t13 += v * b5;\n t14 += v * b6;\n t15 += v * b7;\n t16 += v * b8;\n t17 += v * b9;\n t18 += v * b10;\n t19 += v * b11;\n t20 += v * b12;\n t21 += v * b13;\n t22 += v * b14;\n t23 += v * b15;\n v = a[9];\n t9 += v * b0;\n t10 += v * b1;\n t11 += v * b2;\n t12 += v * b3;\n t13 += v * b4;\n t14 += v * b5;\n t15 += v * b6;\n t16 += v * b7;\n t17 += v * b8;\n t18 += v * b9;\n t19 += v * b10;\n t20 += v * b11;\n t21 += v * b12;\n t22 += v * b13;\n t23 += v * b14;\n t24 += v * b15;\n v = a[10];\n t10 += v * b0;\n t11 += v * b1;\n t12 += v * b2;\n t13 += v * b3;\n t14 += v * b4;\n t15 += v * b5;\n t16 += v * b6;\n t17 += v * b7;\n t18 += v * b8;\n t19 += v * b9;\n t20 += v * b10;\n t21 += v * b11;\n t22 += v * b12;\n t23 += v * b13;\n t24 += v * b14;\n t25 += v * b15;\n v = a[11];\n t11 += v * b0;\n t12 += v * b1;\n t13 += v * b2;\n t14 += v * b3;\n t15 += v * b4;\n t16 += v * b5;\n t17 += v * b6;\n t18 += v * b7;\n t19 += v * b8;\n t20 += v * b9;\n t21 += v * b10;\n t22 += v * b11;\n t23 += v * b12;\n t24 += v * b13;\n t25 += v * b14;\n t26 += v * b15;\n v = a[12];\n t12 += v * b0;\n t13 += v * b1;\n t14 += v * b2;\n t15 += v * b3;\n t16 += v * b4;\n t17 += v * b5;\n t18 += v * b6;\n t19 += v * b7;\n t20 += v * b8;\n t21 += v * b9;\n t22 += v * b10;\n t23 += v * b11;\n t24 += v * b12;\n t25 += v * b13;\n t26 += v * b14;\n t27 += v * b15;\n v = a[13];\n t13 += v * b0;\n t14 += v * b1;\n t15 += v * b2;\n t16 += v * b3;\n t17 += v * b4;\n t18 += v * b5;\n t19 += v * b6;\n t20 += v * b7;\n t21 += v * b8;\n t22 += v * b9;\n t23 += v * b10;\n t24 += v * b11;\n t25 += v * b12;\n t26 += v * b13;\n t27 += v * b14;\n t28 += v * b15;\n v = a[14];\n t14 += v * b0;\n t15 += v * b1;\n t16 += v * b2;\n t17 += v * b3;\n t18 += v * b4;\n t19 += v * b5;\n t20 += v * b6;\n t21 += v * b7;\n t22 += v * b8;\n t23 += v * b9;\n t24 += v * b10;\n t25 += v * b11;\n t26 += v * b12;\n t27 += v * b13;\n t28 += v * b14;\n t29 += v * b15;\n v = a[15];\n t15 += v * b0;\n t16 += v * b1;\n t17 += v * b2;\n t18 += v * b3;\n t19 += v * b4;\n t20 += v * b5;\n t21 += v * b6;\n t22 += v * b7;\n t23 += v * b8;\n t24 += v * b9;\n t25 += v * b10;\n t26 += v * b11;\n t27 += v * b12;\n t28 += v * b13;\n t29 += v * b14;\n t30 += v * b15;\n\n t0 += 38 * t16;\n t1 += 38 * t17;\n t2 += 38 * t18;\n t3 += 38 * t19;\n t4 += 38 * t20;\n t5 += 38 * t21;\n t6 += 38 * t22;\n t7 += 38 * t23;\n t8 += 38 * t24;\n t9 += 38 * t25;\n t10 += 38 * t26;\n t11 += 38 * t27;\n t12 += 38 * t28;\n t13 += 38 * t29;\n t14 += 38 * t30;\n // t15 left as is\n\n // first car\n c = 1;\n v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;\n v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;\n v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;\n v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;\n v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;\n v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;\n v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;\n v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;\n v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;\n v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;\n v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;\n v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;\n v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;\n v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;\n v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;\n v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;\n t0 += c-1 + 37 * (c-1);\n\n // second car\n c = 1;\n v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;\n v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;\n v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;\n v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;\n v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;\n v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;\n v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;\n v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;\n v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;\n v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;\n v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;\n v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;\n v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;\n v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;\n v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;\n v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;\n t0 += c-1 + 37 * (c-1);\n\n o[ 0] = t0;\n o[ 1] = t1;\n o[ 2] = t2;\n o[ 3] = t3;\n o[ 4] = t4;\n o[ 5] = t5;\n o[ 6] = t6;\n o[ 7] = t7;\n o[ 8] = t8;\n o[ 9] = t9;\n o[10] = t10;\n o[11] = t11;\n o[12] = t12;\n o[13] = t13;\n o[14] = t14;\n o[15] = t15;\n}\n\nfunction S(o, a) {\n M(o, a, a);\n}\n\nfunction inv25519(o, i) {\n var c = gf();\n var a;\n for (a = 0; a < 16; a++) c[a] = i[a];\n for (a = 253; a >= 0; a--) {\n S(c, c);\n if(a !== 2 && a !== 4) M(c, c, i);\n }\n for (a = 0; a < 16; a++) o[a] = c[a];\n}\n\nfunction pow2523(o, i) {\n var c = gf();\n var a;\n for (a = 0; a < 16; a++) c[a] = i[a];\n for (a = 250; a >= 0; a--) {\n S(c, c);\n if(a !== 1) M(c, c, i);\n }\n for (a = 0; a < 16; a++) o[a] = c[a];\n}\n\nfunction crypto_scalarmult(q, n, p) {\n var z = new Uint8Array(32);\n var x = new Float64Array(80), r, i;\n var a = gf(), b = gf(), c = gf(),\n d = gf(), e = gf(), f = gf();\n for (i = 0; i < 31; i++) z[i] = n[i];\n z[31]=(n[31]&127)|64;\n z[0]&=248;\n unpack25519(x,p);\n for (i = 0; i < 16; i++) {\n b[i]=x[i];\n d[i]=a[i]=c[i]=0;\n }\n a[0]=d[0]=1;\n for (i=254; i>=0; --i) {\n r=(z[i>>>3]>>>(i&7))&1;\n sel25519(a,b,r);\n sel25519(c,d,r);\n A(e,a,c);\n Z(a,a,c);\n A(c,b,d);\n Z(b,b,d);\n S(d,e);\n S(f,a);\n M(a,c,a);\n M(c,b,e);\n A(e,a,c);\n Z(a,a,c);\n S(b,a);\n Z(c,d,f);\n M(a,c,_121665);\n A(a,a,d);\n M(c,c,a);\n M(a,d,f);\n M(d,b,x);\n S(b,e);\n sel25519(a,b,r);\n sel25519(c,d,r);\n }\n for (i = 0; i < 16; i++) {\n x[i+16]=a[i];\n x[i+32]=c[i];\n x[i+48]=b[i];\n x[i+64]=d[i];\n }\n var x32 = x.subarray(32);\n var x16 = x.subarray(16);\n inv25519(x32,x32);\n M(x16,x16,x32);\n pack25519(q,x16);\n return 0;\n}\n\nfunction crypto_scalarmult_base(q, n) {\n return crypto_scalarmult(q, n, _9);\n}\n\nfunction crypto_box_keypair(y, x) {\n randombytes(x, 32);\n return crypto_scalarmult_base(y, x);\n}\n\nfunction crypto_box_beforenm(k, y, x) {\n var s = new Uint8Array(32);\n crypto_scalarmult(s, x, y);\n return crypto_core_hsalsa20(k, _0, s, sigma);\n}\n\nvar crypto_box_afternm = crypto_secretbox;\nvar crypto_box_open_afternm = crypto_secretbox_open;\n\nfunction crypto_box(c, m, d, n, y, x) {\n var k = new Uint8Array(32);\n crypto_box_beforenm(k, y, x);\n return crypto_box_afternm(c, m, d, n, k);\n}\n\nfunction crypto_box_open(m, c, d, n, y, x) {\n var k = new Uint8Array(32);\n crypto_box_beforenm(k, y, x);\n return crypto_box_open_afternm(m, c, d, n, k);\n}\n\nvar K = [\n 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,\n 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,\n 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,\n 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,\n 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,\n 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,\n 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,\n 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,\n 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,\n 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,\n 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,\n 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,\n 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,\n 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,\n 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,\n 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,\n 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,\n 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,\n 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,\n 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,\n 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,\n 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,\n 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,\n 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,\n 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,\n 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,\n 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,\n 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,\n 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,\n 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,\n 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,\n 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,\n 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,\n 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,\n 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,\n 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,\n 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,\n 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,\n 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,\n 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817\n];\n\nfunction crypto_hashblocks_hl(hh, hl, m, n) {\n var wh = new Int32Array(16), wl = new Int32Array(16),\n bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7,\n bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7,\n th, tl, i, j, h, l, a, b, c, d;\n\n var ah0 = hh[0],\n ah1 = hh[1],\n ah2 = hh[2],\n ah3 = hh[3],\n ah4 = hh[4],\n ah5 = hh[5],\n ah6 = hh[6],\n ah7 = hh[7],\n\n al0 = hl[0],\n al1 = hl[1],\n al2 = hl[2],\n al3 = hl[3],\n al4 = hl[4],\n al5 = hl[5],\n al6 = hl[6],\n al7 = hl[7];\n\n var pos = 0;\n while (n >= 128) {\n for (i = 0; i < 16; i++) {\n j = 8 * i + pos;\n wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3];\n wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7];\n }\n for (i = 0; i < 80; i++) {\n bh0 = ah0;\n bh1 = ah1;\n bh2 = ah2;\n bh3 = ah3;\n bh4 = ah4;\n bh5 = ah5;\n bh6 = ah6;\n bh7 = ah7;\n\n bl0 = al0;\n bl1 = al1;\n bl2 = al2;\n bl3 = al3;\n bl4 = al4;\n bl5 = al5;\n bl6 = al6;\n bl7 = al7;\n\n // add\n h = ah7;\n l = al7;\n\n a = l & 0xffff; b = l >>> 16;\n c = h & 0xffff; d = h >>> 16;\n\n // Sigma1\n h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32))));\n l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32))));\n\n a += l & 0xffff; b += l >>> 16;\n c += h & 0xffff; d += h >>> 16;\n\n // Ch\n h = (ah4 & ah5) ^ (~ah4 & ah6);\n l = (al4 & al5) ^ (~al4 & al6);\n\n a += l & 0xffff; b += l >>> 16;\n c += h & 0xffff; d += h >>> 16;\n\n // K\n h = K[i*2];\n l = K[i*2+1];\n\n a += l & 0xffff; b += l >>> 16;\n c += h & 0xffff; d += h >>> 16;\n\n // w\n h = wh[i%16];\n l = wl[i%16];\n\n a += l & 0xffff; b += l >>> 16;\n c += h & 0xffff; d += h >>> 16;\n\n b += a >>> 16;\n c += b >>> 16;\n d += c >>> 16;\n\n th = c & 0xffff | d << 16;\n tl = a & 0xffff | b << 16;\n\n // add\n h = th;\n l = tl;\n\n a = l & 0xffff; b = l >>> 16;\n c = h & 0xffff; d = h >>> 16;\n\n // Sigma0\n h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32))));\n l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32))));\n\n a += l & 0xffff; b += l >>> 16;\n c += h & 0xffff; d += h >>> 16;\n\n // Maj\n h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2);\n l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2);\n\n a += l & 0xffff; b += l >>> 16;\n c += h & 0xffff; d += h >>> 16;\n\n b += a >>> 16;\n c += b >>> 16;\n d += c >>> 16;\n\n bh7 = (c & 0xffff) | (d << 16);\n bl7 = (a & 0xffff) | (b << 16);\n\n // add\n h = bh3;\n l = bl3;\n\n a = l & 0xffff; b = l >>> 16;\n c = h & 0xffff; d = h >>> 16;\n\n h = th;\n l = tl;\n\n a += l & 0xffff; b += l >>> 16;\n c += h & 0xffff; d += h >>> 16;\n\n b += a >>> 16;\n c += b >>> 16;\n d += c >>> 16;\n\n bh3 = (c & 0xffff) | (d << 16);\n bl3 = (a & 0xffff) | (b << 16);\n\n ah1 = bh0;\n ah2 = bh1;\n ah3 = bh2;\n ah4 = bh3;\n ah5 = bh4;\n ah6 = bh5;\n ah7 = bh6;\n ah0 = bh7;\n\n al1 = bl0;\n al2 = bl1;\n al3 = bl2;\n al4 = bl3;\n al5 = bl4;\n al6 = bl5;\n al7 = bl6;\n al0 = bl7;\n\n if (i%16 === 15) {\n for (j = 0; j < 16; j++) {\n // add\n h = wh[j];\n l = wl[j];\n\n a = l & 0xffff; b = l >>> 16;\n c = h & 0xffff; d = h >>> 16;\n\n h = wh[(j+9)%16];\n l = wl[(j+9)%16];\n\n a += l & 0xffff; b += l >>> 16;\n c += h & 0xffff; d += h >>> 16;\n\n // sigma0\n th = wh[(j+1)%16];\n tl = wl[(j+1)%16];\n h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7);\n l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7)));\n\n a += l & 0xffff; b += l >>> 16;\n c += h & 0xffff; d += h >>> 16;\n\n // sigma1\n th = wh[(j+14)%16];\n tl = wl[(j+14)%16];\n h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6);\n l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6)));\n\n a += l & 0xffff; b += l >>> 16;\n c += h & 0xffff; d += h >>> 16;\n\n b += a >>> 16;\n c += b >>> 16;\n d += c >>> 16;\n\n wh[j] = (c & 0xffff) | (d << 16);\n wl[j] = (a & 0xffff) | (b << 16);\n }\n }\n }\n\n // add\n h = ah0;\n l = al0;\n\n a = l & 0xffff; b = l >>> 16;\n c = h & 0xffff; d = h >>> 16;\n\n h = hh[0];\n l = hl[0];\n\n a += l & 0xffff; b += l >>> 16;\n c += h & 0xffff; d += h >>> 16;\n\n b += a >>> 16;\n c += b >>> 16;\n d += c >>> 16;\n\n hh[0] = ah0 = (c & 0xffff) | (d << 16);\n hl[0] = al0 = (a & 0xffff) | (b << 16);\n\n h = ah1;\n l = al1;\n\n a = l & 0xffff; b = l >>> 16;\n c = h & 0xffff; d = h >>> 16;\n\n h = hh[1];\n l = hl[1];\n\n a += l & 0xffff; b += l >>> 16;\n c += h & 0xffff; d += h >>> 16;\n\n b += a >>> 16;\n c += b >>> 16;\n d += c >>> 16;\n\n hh[1] = ah1 = (c & 0xffff) | (d << 16);\n hl[1] = al1 = (a & 0xffff) | (b << 16);\n\n h = ah2;\n l = al2;\n\n a = l & 0xffff; b = l >>> 16;\n c = h & 0xffff; d = h >>> 16;\n\n h = hh[2];\n l = hl[2];\n\n a += l & 0xffff; b += l >>> 16;\n c += h & 0xffff; d += h >>> 16;\n\n b += a >>> 16;\n c += b >>> 16;\n d += c >>> 16;\n\n hh[2] = ah2 = (c & 0xffff) | (d << 16);\n hl[2] = al2 = (a & 0xffff) | (b << 16);\n\n h = ah3;\n l = al3;\n\n a = l & 0xffff; b = l >>> 16;\n c = h & 0xffff; d = h >>> 16;\n\n h = hh[3];\n l = hl[3];\n\n a += l & 0xffff; b += l >>> 16;\n c += h & 0xffff; d += h >>> 16;\n\n b += a >>> 16;\n c += b >>> 16;\n d += c >>> 16;\n\n hh[3] = ah3 = (c & 0xffff) | (d << 16);\n hl[3] = al3 = (a & 0xffff) | (b << 16);\n\n h = ah4;\n l = al4;\n\n a = l & 0xffff; b = l >>> 16;\n c = h & 0xffff; d = h >>> 16;\n\n h = hh[4];\n l = hl[4];\n\n a += l & 0xffff; b += l >>> 16;\n c += h & 0xffff; d += h >>> 16;\n\n b += a >>> 16;\n c += b >>> 16;\n d += c >>> 16;\n\n hh[4] = ah4 = (c & 0xffff) | (d << 16);\n hl[4] = al4 = (a & 0xffff) | (b << 16);\n\n h = ah5;\n l = al5;\n\n a = l & 0xffff; b = l >>> 16;\n c = h & 0xffff; d = h >>> 16;\n\n h = hh[5];\n l = hl[5];\n\n a += l & 0xffff; b += l >>> 16;\n c += h & 0xffff; d += h >>> 16;\n\n b += a >>> 16;\n c += b >>> 16;\n d += c >>> 16;\n\n hh[5] = ah5 = (c & 0xffff) | (d << 16);\n hl[5] = al5 = (a & 0xffff) | (b << 16);\n\n h = ah6;\n l = al6;\n\n a = l & 0xffff; b = l >>> 16;\n c = h & 0xffff; d = h >>> 16;\n\n h = hh[6];\n l = hl[6];\n\n a += l & 0xffff; b += l >>> 16;\n c += h & 0xffff; d += h >>> 16;\n\n b += a >>> 16;\n c += b >>> 16;\n d += c >>> 16;\n\n hh[6] = ah6 = (c & 0xffff) | (d << 16);\n hl[6] = al6 = (a & 0xffff) | (b << 16);\n\n h = ah7;\n l = al7;\n\n a = l & 0xffff; b = l >>> 16;\n c = h & 0xffff; d = h >>> 16;\n\n h = hh[7];\n l = hl[7];\n\n a += l & 0xffff; b += l >>> 16;\n c += h & 0xffff; d += h >>> 16;\n\n b += a >>> 16;\n c += b >>> 16;\n d += c >>> 16;\n\n hh[7] = ah7 = (c & 0xffff) | (d << 16);\n hl[7] = al7 = (a & 0xffff) | (b << 16);\n\n pos += 128;\n n -= 128;\n }\n\n return n;\n}\n\nfunction crypto_hash(out, m, n) {\n var hh = new Int32Array(8),\n hl = new Int32Array(8),\n x = new Uint8Array(256),\n i, b = n;\n\n hh[0] = 0x6a09e667;\n hh[1] = 0xbb67ae85;\n hh[2] = 0x3c6ef372;\n hh[3] = 0xa54ff53a;\n hh[4] = 0x510e527f;\n hh[5] = 0x9b05688c;\n hh[6] = 0x1f83d9ab;\n hh[7] = 0x5be0cd19;\n\n hl[0] = 0xf3bcc908;\n hl[1] = 0x84caa73b;\n hl[2] = 0xfe94f82b;\n hl[3] = 0x5f1d36f1;\n hl[4] = 0xade682d1;\n hl[5] = 0x2b3e6c1f;\n hl[6] = 0xfb41bd6b;\n hl[7] = 0x137e2179;\n\n crypto_hashblocks_hl(hh, hl, m, n);\n n %= 128;\n\n for (i = 0; i < n; i++) x[i] = m[b-n+i];\n x[n] = 128;\n\n n = 256-128*(n<112?1:0);\n x[n-9] = 0;\n ts64(x, n-8, (b / 0x20000000) | 0, b << 3);\n crypto_hashblocks_hl(hh, hl, x, n);\n\n for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]);\n\n return 0;\n}\n\nfunction add(p, q) {\n var a = gf(), b = gf(), c = gf(),\n d = gf(), e = gf(), f = gf(),\n g = gf(), h = gf(), t = gf();\n\n Z(a, p[1], p[0]);\n Z(t, q[1], q[0]);\n M(a, a, t);\n A(b, p[0], p[1]);\n A(t, q[0], q[1]);\n M(b, b, t);\n M(c, p[3], q[3]);\n M(c, c, D2);\n M(d, p[2], q[2]);\n A(d, d, d);\n Z(e, b, a);\n Z(f, d, c);\n A(g, d, c);\n A(h, b, a);\n\n M(p[0], e, f);\n M(p[1], h, g);\n M(p[2], g, f);\n M(p[3], e, h);\n}\n\nfunction cswap(p, q, b) {\n var i;\n for (i = 0; i < 4; i++) {\n sel25519(p[i], q[i], b);\n }\n}\n\nfunction pack(r, p) {\n var tx = gf(), ty = gf(), zi = gf();\n inv25519(zi, p[2]);\n M(tx, p[0], zi);\n M(ty, p[1], zi);\n pack25519(r, ty);\n r[31] ^= par25519(tx) << 7;\n}\n\nfunction scalarmult(p, q, s) {\n var b, i;\n set25519(p[0], gf0);\n set25519(p[1], gf1);\n set25519(p[2], gf1);\n set25519(p[3], gf0);\n for (i = 255; i >= 0; --i) {\n b = (s[(i/8)|0] >> (i&7)) & 1;\n cswap(p, q, b);\n add(q, p);\n add(p, p);\n cswap(p, q, b);\n }\n}\n\nfunction scalarbase(p, s) {\n var q = [gf(), gf(), gf(), gf()];\n set25519(q[0], X);\n set25519(q[1], Y);\n set25519(q[2], gf1);\n M(q[3], X, Y);\n scalarmult(p, q, s);\n}\n\nfunction crypto_sign_keypair(pk, sk, seeded) {\n var d = new Uint8Array(64);\n var p = [gf(), gf(), gf(), gf()];\n var i;\n\n if (!seeded) randombytes(sk, 32);\n crypto_hash(d, sk, 32);\n d[0] &= 248;\n d[31] &= 127;\n d[31] |= 64;\n\n scalarbase(p, d);\n pack(pk, p);\n\n for (i = 0; i < 32; i++) sk[i+32] = pk[i];\n return 0;\n}\n\nvar L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]);\n\nfunction modL(r, x) {\n var carry, i, j, k;\n for (i = 63; i >= 32; --i) {\n carry = 0;\n for (j = i - 32, k = i - 12; j < k; ++j) {\n x[j] += carry - 16 * x[i] * L[j - (i - 32)];\n carry = (x[j] + 128) >> 8;\n x[j] -= carry * 256;\n }\n x[j] += carry;\n x[i] = 0;\n }\n carry = 0;\n for (j = 0; j < 32; j++) {\n x[j] += carry - (x[31] >> 4) * L[j];\n carry = x[j] >> 8;\n x[j] &= 255;\n }\n for (j = 0; j < 32; j++) x[j] -= carry * L[j];\n for (i = 0; i < 32; i++) {\n x[i+1] += x[i] >> 8;\n r[i] = x[i] & 255;\n }\n}\n\nfunction reduce(r) {\n var x = new Float64Array(64), i;\n for (i = 0; i < 64; i++) x[i] = r[i];\n for (i = 0; i < 64; i++) r[i] = 0;\n modL(r, x);\n}\n\n// Note: difference from C - smlen returned, not passed as argument.\nfunction crypto_sign(sm, m, n, sk) {\n var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);\n var i, j, x = new Float64Array(64);\n var p = [gf(), gf(), gf(), gf()];\n\n crypto_hash(d, sk, 32);\n d[0] &= 248;\n d[31] &= 127;\n d[31] |= 64;\n\n var smlen = n + 64;\n for (i = 0; i < n; i++) sm[64 + i] = m[i];\n for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];\n\n crypto_hash(r, sm.subarray(32), n+32);\n reduce(r);\n scalarbase(p, r);\n pack(sm, p);\n\n for (i = 32; i < 64; i++) sm[i] = sk[i];\n crypto_hash(h, sm, n + 64);\n reduce(h);\n\n for (i = 0; i < 64; i++) x[i] = 0;\n for (i = 0; i < 32; i++) x[i] = r[i];\n for (i = 0; i < 32; i++) {\n for (j = 0; j < 32; j++) {\n x[i+j] += h[i] * d[j];\n }\n }\n\n modL(sm.subarray(32), x);\n return smlen;\n}\n\nfunction unpackneg(r, p) {\n var t = gf(), chk = gf(), num = gf(),\n den = gf(), den2 = gf(), den4 = gf(),\n den6 = gf();\n\n set25519(r[2], gf1);\n unpack25519(r[1], p);\n S(num, r[1]);\n M(den, num, D);\n Z(num, num, r[2]);\n A(den, r[2], den);\n\n S(den2, den);\n S(den4, den2);\n M(den6, den4, den2);\n M(t, den6, num);\n M(t, t, den);\n\n pow2523(t, t);\n M(t, t, num);\n M(t, t, den);\n M(t, t, den);\n M(r[0], t, den);\n\n S(chk, r[0]);\n M(chk, chk, den);\n if (neq25519(chk, num)) M(r[0], r[0], I);\n\n S(chk, r[0]);\n M(chk, chk, den);\n if (neq25519(chk, num)) return -1;\n\n if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]);\n\n M(r[3], r[0], r[1]);\n return 0;\n}\n\nfunction crypto_sign_open(m, sm, n, pk) {\n var i, mlen;\n var t = new Uint8Array(32), h = new Uint8Array(64);\n var p = [gf(), gf(), gf(), gf()],\n q = [gf(), gf(), gf(), gf()];\n\n mlen = -1;\n if (n < 64) return -1;\n\n if (unpackneg(q, pk)) return -1;\n\n for (i = 0; i < n; i++) m[i] = sm[i];\n for (i = 0; i < 32; i++) m[i+32] = pk[i];\n crypto_hash(h, m, n);\n reduce(h);\n scalarmult(p, q, h);\n\n scalarbase(q, sm.subarray(32));\n add(p, q);\n pack(t, p);\n\n n -= 64;\n if (crypto_verify_32(sm, 0, t, 0)) {\n for (i = 0; i < n; i++) m[i] = 0;\n return -1;\n }\n\n for (i = 0; i < n; i++) m[i] = sm[i + 64];\n mlen = n;\n return mlen;\n}\n\nvar crypto_secretbox_KEYBYTES = 32,\n crypto_secretbox_NONCEBYTES = 24,\n crypto_secretbox_ZEROBYTES = 32,\n crypto_secretbox_BOXZEROBYTES = 16,\n crypto_scalarmult_BYTES = 32,\n crypto_scalarmult_SCALARBYTES = 32,\n crypto_box_PUBLICKEYBYTES = 32,\n crypto_box_SECRETKEYBYTES = 32,\n crypto_box_BEFORENMBYTES = 32,\n crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES,\n crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES,\n crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES,\n crypto_sign_BYTES = 64,\n crypto_sign_PUBLICKEYBYTES = 32,\n crypto_sign_SECRETKEYBYTES = 64,\n crypto_sign_SEEDBYTES = 32,\n crypto_hash_BYTES = 64;\n\nnacl.lowlevel = {\n crypto_core_hsalsa20: crypto_core_hsalsa20,\n crypto_stream_xor: crypto_stream_xor,\n crypto_stream: crypto_stream,\n crypto_stream_salsa20_xor: crypto_stream_salsa20_xor,\n crypto_stream_salsa20: crypto_stream_salsa20,\n crypto_onetimeauth: crypto_onetimeauth,\n crypto_onetimeauth_verify: crypto_onetimeauth_verify,\n crypto_verify_16: crypto_verify_16,\n crypto_verify_32: crypto_verify_32,\n crypto_secretbox: crypto_secretbox,\n crypto_secretbox_open: crypto_secretbox_open,\n crypto_scalarmult: crypto_scalarmult,\n crypto_scalarmult_base: crypto_scalarmult_base,\n crypto_box_beforenm: crypto_box_beforenm,\n crypto_box_afternm: crypto_box_afternm,\n crypto_box: crypto_box,\n crypto_box_open: crypto_box_open,\n crypto_box_keypair: crypto_box_keypair,\n crypto_hash: crypto_hash,\n crypto_sign: crypto_sign,\n crypto_sign_keypair: crypto_sign_keypair,\n crypto_sign_open: crypto_sign_open,\n\n crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES,\n crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES,\n crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES,\n crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES,\n crypto_scalarmult_BYTES: crypto_scalarmult_BYTES,\n crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES,\n crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES,\n crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES,\n crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES,\n crypto_box_NONCEBYTES: crypto_box_NONCEBYTES,\n crypto_box_ZEROBYTES: crypto_box_ZEROBYTES,\n crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES,\n crypto_sign_BYTES: crypto_sign_BYTES,\n crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES,\n crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES,\n crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES,\n crypto_hash_BYTES: crypto_hash_BYTES\n};\n\n/* High-level API */\n\nfunction checkLengths(k, n) {\n if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size');\n if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size');\n}\n\nfunction checkBoxLengths(pk, sk) {\n if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size');\n if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size');\n}\n\nfunction checkArrayTypes() {\n var t, i;\n for (i = 0; i < arguments.length; i++) {\n if ((t = Object.prototype.toString.call(arguments[i])) !== '[object Uint8Array]')\n throw new TypeError('unexpected type ' + t + ', use Uint8Array');\n }\n}\n\nfunction cleanup(arr) {\n for (var i = 0; i < arr.length; i++) arr[i] = 0;\n}\n\n// TODO: Completely remove this in v0.15.\nif (!nacl.util) {\n nacl.util = {};\n nacl.util.decodeUTF8 = nacl.util.encodeUTF8 = nacl.util.encodeBase64 = nacl.util.decodeBase64 = function() {\n throw new Error('nacl.util moved into separate package: https://github.com/dchest/tweetnacl-util-js');\n };\n}\n\nnacl.randomBytes = function(n) {\n var b = new Uint8Array(n);\n randombytes(b, n);\n return b;\n};\n\nnacl.secretbox = function(msg, nonce, key) {\n checkArrayTypes(msg, nonce, key);\n checkLengths(key, nonce);\n var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);\n var c = new Uint8Array(m.length);\n for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i];\n crypto_secretbox(c, m, m.length, nonce, key);\n return c.subarray(crypto_secretbox_BOXZEROBYTES);\n};\n\nnacl.secretbox.open = function(box, nonce, key) {\n checkArrayTypes(box, nonce, key);\n checkLengths(key, nonce);\n var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);\n var m = new Uint8Array(c.length);\n for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i];\n if (c.length < 32) return false;\n if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return false;\n return m.subarray(crypto_secretbox_ZEROBYTES);\n};\n\nnacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;\nnacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;\nnacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;\n\nnacl.scalarMult = function(n, p) {\n checkArrayTypes(n, p);\n if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');\n if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size');\n var q = new Uint8Array(crypto_scalarmult_BYTES);\n crypto_scalarmult(q, n, p);\n return q;\n};\n\nnacl.scalarMult.base = function(n) {\n checkArrayTypes(n);\n if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');\n var q = new Uint8Array(crypto_scalarmult_BYTES);\n crypto_scalarmult_base(q, n);\n return q;\n};\n\nnacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;\nnacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;\n\nnacl.box = function(msg, nonce, publicKey, secretKey) {\n var k = nacl.box.before(publicKey, secretKey);\n return nacl.secretbox(msg, nonce, k);\n};\n\nnacl.box.before = function(publicKey, secretKey) {\n checkArrayTypes(publicKey, secretKey);\n checkBoxLengths(publicKey, secretKey);\n var k = new Uint8Array(crypto_box_BEFORENMBYTES);\n crypto_box_beforenm(k, publicKey, secretKey);\n return k;\n};\n\nnacl.box.after = nacl.secretbox;\n\nnacl.box.open = function(msg, nonce, publicKey, secretKey) {\n var k = nacl.box.before(publicKey, secretKey);\n return nacl.secretbox.open(msg, nonce, k);\n};\n\nnacl.box.open.after = nacl.secretbox.open;\n\nnacl.box.keyPair = function() {\n var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);\n var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);\n crypto_box_keypair(pk, sk);\n return {publicKey: pk, secretKey: sk};\n};\n\nnacl.box.keyPair.fromSecretKey = function(secretKey) {\n checkArrayTypes(secretKey);\n if (secretKey.length !== crypto_box_SECRETKEYBYTES)\n throw new Error('bad secret key size');\n var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);\n crypto_scalarmult_base(pk, secretKey);\n return {publicKey: pk, secretKey: new Uint8Array(secretKey)};\n};\n\nnacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;\nnacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;\nnacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;\nnacl.box.nonceLength = crypto_box_NONCEBYTES;\nnacl.box.overheadLength = nacl.secretbox.overheadLength;\n\nnacl.sign = function(msg, secretKey) {\n checkArrayTypes(msg, secretKey);\n if (secretKey.length !== crypto_sign_SECRETKEYBYTES)\n throw new Error('bad secret key size');\n var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length);\n crypto_sign(signedMsg, msg, msg.length, secretKey);\n return signedMsg;\n};\n\nnacl.sign.open = function(signedMsg, publicKey) {\n if (arguments.length !== 2)\n throw new Error('nacl.sign.open accepts 2 arguments; did you mean to use nacl.sign.detached.verify?');\n checkArrayTypes(signedMsg, publicKey);\n if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)\n throw new Error('bad public key size');\n var tmp = new Uint8Array(signedMsg.length);\n var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);\n if (mlen < 0) return null;\n var m = new Uint8Array(mlen);\n for (var i = 0; i < m.length; i++) m[i] = tmp[i];\n return m;\n};\n\nnacl.sign.detached = function(msg, secretKey) {\n var signedMsg = nacl.sign(msg, secretKey);\n var sig = new Uint8Array(crypto_sign_BYTES);\n for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];\n return sig;\n};\n\nnacl.sign.detached.verify = function(msg, sig, publicKey) {\n checkArrayTypes(msg, sig, publicKey);\n if (sig.length !== crypto_sign_BYTES)\n throw new Error('bad signature size');\n if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)\n throw new Error('bad public key size');\n var sm = new Uint8Array(crypto_sign_BYTES + msg.length);\n var m = new Uint8Array(crypto_sign_BYTES + msg.length);\n var i;\n for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];\n for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i];\n return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0);\n};\n\nnacl.sign.keyPair = function() {\n var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);\n var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);\n crypto_sign_keypair(pk, sk);\n return {publicKey: pk, secretKey: sk};\n};\n\nnacl.sign.keyPair.fromSecretKey = function(secretKey) {\n checkArrayTypes(secretKey);\n if (secretKey.length !== crypto_sign_SECRETKEYBYTES)\n throw new Error('bad secret key size');\n var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);\n for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i];\n return {publicKey: pk, secretKey: new Uint8Array(secretKey)};\n};\n\nnacl.sign.keyPair.fromSeed = function(seed) {\n checkArrayTypes(seed);\n if (seed.length !== crypto_sign_SEEDBYTES)\n throw new Error('bad seed size');\n var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);\n var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);\n for (var i = 0; i < 32; i++) sk[i] = seed[i];\n crypto_sign_keypair(pk, sk, true);\n return {publicKey: pk, secretKey: sk};\n};\n\nnacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;\nnacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;\nnacl.sign.seedLength = crypto_sign_SEEDBYTES;\nnacl.sign.signatureLength = crypto_sign_BYTES;\n\nnacl.hash = function(msg) {\n checkArrayTypes(msg);\n var h = new Uint8Array(crypto_hash_BYTES);\n crypto_hash(h, msg, msg.length);\n return h;\n};\n\nnacl.hash.hashLength = crypto_hash_BYTES;\n\nnacl.verify = function(x, y) {\n checkArrayTypes(x, y);\n // Zero length arguments are considered not equal.\n if (x.length === 0 || y.length === 0) return false;\n if (x.length !== y.length) return false;\n return (vn(x, 0, y, 0, x.length) === 0) ? true : false;\n};\n\nnacl.setPRNG = function(fn) {\n randombytes = fn;\n};\n\n(function() {\n // Initialize PRNG if environment provides CSPRNG.\n // If not, methods calling randombytes will throw.\n var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null;\n if (crypto && crypto.getRandomValues) {\n // Browsers.\n var QUOTA = 65536;\n nacl.setPRNG(function(x, n) {\n var i, v = new Uint8Array(n);\n for (i = 0; i < n; i += QUOTA) {\n crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));\n }\n for (i = 0; i < n; i++) x[i] = v[i];\n cleanup(v);\n });\n } else if (typeof require !== 'undefined') {\n // Node.js.\n crypto = require('crypto');\n if (crypto && crypto.randomBytes) {\n nacl.setPRNG(function(x, n) {\n var i, v = crypto.randomBytes(n);\n for (i = 0; i < n; i++) x[i] = v[i];\n cleanup(v);\n });\n }\n }\n})();\n\n})(typeof module !== 'undefined' && module.exports ? module.exports : (self.nacl = self.nacl || {}));\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./node_modules/tweetnacl/nacl-fast.js\n// module id = 34\n// module chunks = 0","/* (ignored) */\n\n\n//////////////////\n// WEBPACK FOOTER\n// crypto (ignored)\n// module id = 35\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\n\nconst ArrayUtil = require('../util/ArrayUtil');\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst MemoryUtil = require('../util/MemoryUtil');\nconst TypeUtil = require('../util/TypeUtil');\n\nconst DecryptError = require('../errors/DecryptError');\n\nconst DerivedSecrets = require('../derived/DerivedSecrets');\nconst HeadKey = require('../derived/HeadKey');\n\nconst IdentityKey = require('../keys/IdentityKey');\nconst IdentityKeyPair = require('../keys/IdentityKeyPair');\nconst KeyPair = require('../keys/KeyPair');\nconst PreKeyBundle = require('../keys/PreKeyBundle');\nconst PublicKey = require('../keys/PublicKey');\n\nconst Header = require('../message/Header');\nconst HeaderMessage = require('../message/HeaderMessage');\nconst Envelope = require('../message/Envelope');\nconst PreKeyMessage = require('../message/PreKeyMessage');\n\nconst ChainKey = require('./ChainKey');\nconst RecvChain = require('./RecvChain');\nconst RootKey = require('./RootKey');\nconst SendChain = require('./SendChain');\nconst Session = require('./Session');\n\n/** @module session */\n\n/** @class SessionState */\nclass SessionState {\n constructor() {\n this.recv_chains = [];\n this.send_chain = null;\n this.root_key = null;\n this.prev_counter = null;\n this.next_send_head_key = null;\n this.next_recv_head_key = null;\n\n throw new DontCallConstructor(this);\n }\n\n /**\n * @param {!keys.IdentityKeyPair} alice_identity_pair\n * @param {!keys.PublicKey} alice_base\n * @param {!keys.PreKeyBundle} bob_pkbundle\n * @returns {SessionState}\n */\n static init_as_alice(alice_identity_pair, alice_base, bob_pkbundle) {\n TypeUtil.assert_is_instance(IdentityKeyPair, alice_identity_pair);\n TypeUtil.assert_is_instance(KeyPair, alice_base);\n TypeUtil.assert_is_instance(PreKeyBundle, bob_pkbundle);\n\n const master_key = ArrayUtil.concatenate_array_buffers([\n alice_identity_pair.secret_key.shared_secret(bob_pkbundle.public_key),\n alice_base.secret_key.shared_secret(bob_pkbundle.identity_key.public_key),\n alice_base.secret_key.shared_secret(bob_pkbundle.public_key),\n ]);\n\n const derived_secrets = DerivedSecrets.kdf_without_salt(master_key, 'handshake');\n MemoryUtil.zeroize(master_key);\n\n const rootkey = RootKey.from_cipher_key(derived_secrets.cipher_key);\n const chainkey = ChainKey.from_mac_key(derived_secrets.mac_key, 0);\n const head_key_alice = derived_secrets.head_key_alice;\n const next_head_key_Bob = derived_secrets.next_head_key_bob;\n\n const send_ratchet = KeyPair.new();\n const [rok, chk, nextHeadKey] = rootkey.dh_ratchet(send_ratchet, bob_pkbundle.public_key);\n const recv_chains = [RecvChain.new(chainkey, bob_pkbundle.public_key, next_head_key_Bob)];\n const send_chain = SendChain.new(chk, send_ratchet, head_key_alice);\n\n const state = ClassUtil.new_instance(SessionState);\n state.next_send_head_key = nextHeadKey;\n state.recv_chains = recv_chains;\n state.next_recv_head_key = next_head_key_Bob;\n state.send_chain = send_chain;\n state.root_key = rok;\n state.prev_counter = 0;\n return state;\n }\n\n /**\n * @param {!keys.IdentityKeyPair} bob_ident\n * @param {!keys.KeyPair} bob_prekey\n * @param {!keys.IdentityKey} alice_ident\n * @param {!keys.PublicKey} alice_base\n * @returns {SessionState}\n */\n static init_as_bob(bob_ident, bob_prekey, alice_ident, alice_base) {\n TypeUtil.assert_is_instance(IdentityKeyPair, bob_ident);\n TypeUtil.assert_is_instance(KeyPair, bob_prekey);\n TypeUtil.assert_is_instance(IdentityKey, alice_ident);\n TypeUtil.assert_is_instance(PublicKey, alice_base);\n\n const master_key = ArrayUtil.concatenate_array_buffers([\n bob_prekey.secret_key.shared_secret(alice_ident.public_key),\n bob_ident.secret_key.shared_secret(alice_base),\n bob_prekey.secret_key.shared_secret(alice_base),\n ]);\n\n const derived_secrets = DerivedSecrets.kdf_without_salt(master_key, 'handshake');\n MemoryUtil.zeroize(master_key);\n\n const rootkey = RootKey.from_cipher_key(derived_secrets.cipher_key);\n const chainkey = ChainKey.from_mac_key(derived_secrets.mac_key, 0);\n const head_key_alice = derived_secrets.head_key_alice;\n const next_head_key_bob = derived_secrets.next_head_key_bob;\n const send_chain = SendChain.new(chainkey, bob_prekey, next_head_key_bob);\n\n const state = ClassUtil.new_instance(SessionState);\n state.next_send_head_key = next_head_key_bob;\n state.next_recv_head_key = head_key_alice;\n state.send_chain = send_chain;\n state.root_key = rootkey;\n state.prev_counter = 0;\n return state;\n }\n\n /**\n * @param {!keys.KeyPair} ratchet_key\n * @param {!number} prev_counter\n * @returns {void}\n */\n ratchet(ratchet_key, prev_counter) {\n const new_ratchet = KeyPair.new();\n\n const [recv_root_key, recv_chain_key, next_recv_head_key] =\n this.root_key.dh_ratchet(this.send_chain.ratchet_key, ratchet_key);\n\n const [send_root_key, send_chain_key, next_send_head_key] =\n recv_root_key.dh_ratchet(new_ratchet, ratchet_key);\n\n const recv_chain = RecvChain.new(recv_chain_key, ratchet_key, this.next_recv_head_key);\n const send_chain = SendChain.new(send_chain_key, new_ratchet, this.next_send_head_key);\n\n this.root_key = send_root_key;\n this.prev_counter = this.send_chain.chain_key.idx;\n this.send_chain = send_chain;\n this.next_send_head_key = next_send_head_key;\n this.next_recv_head_key = next_recv_head_key;\n\n // save last chains counter\n const last_chain = this.recv_chains[0];\n if (last_chain) {\n last_chain.final_count = prev_counter;\n }\n this.recv_chains.unshift(recv_chain);\n\n if (this.recv_chains.length > Session.MAX_RECV_CHAINS) {\n for (let index = Session.MAX_RECV_CHAINS; index < this.recv_chains.length; index++) {\n MemoryUtil.zeroize(this.recv_chains[index]);\n }\n\n this.recv_chains = this.recv_chains.slice(0, Session.MAX_RECV_CHAINS);\n }\n }\n\n /**\n * @param {!keys.IdentityKey} identity_key - Public identity key of the local identity key pair\n * @param {!Array<number|keys.PublicKey>} pending - Pending pre-key\n * @param {!(string|Uint8Array)} plaintext - The plaintext to encrypt\n * @param {number} confuse_pre_key_id - Use to create confused pre-key message\n * @returns {message.Envelope}\n */\n encrypt(identity_key, pending, plaintext, confuse_pre_key_id) {\n if (pending) {\n TypeUtil.assert_is_integer(pending[0]);\n TypeUtil.assert_is_instance(PublicKey, pending[1]);\n }\n TypeUtil.assert_is_instance(IdentityKey, identity_key);\n\n const message_index = this.send_chain.chain_key.idx;\n const msgkeys = this.send_chain.chain_key.message_keys();\n const head_key = this.send_chain.head_key;\n\n const header = Header.new(\n message_index,\n this.prev_counter,\n this.send_chain.ratchet_key.public_key\n ).serialise();\n\n let message = HeaderMessage.new(\n head_key.encrypt(header, HeadKey.index_as_nonce(message_index)),\n msgkeys.encrypt(plaintext)\n );\n\n if (pending) {\n message = PreKeyMessage.new(pending[0], pending[1], identity_key, message);\n } else if (confuse_pre_key_id !== undefined) {\n // create a confused pre-key message\n message = PreKeyMessage.new(confuse_pre_key_id, KeyPair.new().public_key, identity_key, message);\n }\n\n const env = Envelope.new(msgkeys.mac_key, message);\n this.send_chain.chain_key = this.send_chain.chain_key.next();\n return env;\n }\n\n /**\n * @param {!message.Envelope} envelope\n * @param {!message.HeaderMessage} msg\n * @returns {Uint8Array}\n */\n decrypt(envelope, msg) {\n TypeUtil.assert_is_instance(Envelope, envelope);\n TypeUtil.assert_is_instance(HeaderMessage, msg);\n\n const encrypted_header = msg.header;\n\n const [header, recv_chain] = (() => {\n // Try next_head_key first, run a DH-ratchet step and create a new receiving chain if it succeeded.\n try {\n return [RecvChain.try_next_head_key(encrypted_header, this.next_recv_head_key), null];\n } catch (err) {\n handleHeaderDecryptionError(err);\n }\n\n // Otherwise, try old receving chains.\n const recv_chains_length = this.recv_chains.length;\n let idx = 0;\n for (; idx < recv_chains_length; idx++) {\n const _recv_chain = this.recv_chains[idx];\n try {\n return [_recv_chain.try_head_key(encrypted_header), _recv_chain];\n } catch (err) {\n handleHeaderDecryptionError(err);\n }\n }\n\n return [null, null];\n\n function handleHeaderDecryptionError(err) {\n if (!(err instanceof DecryptError.HeaderDecryptionFailed)) {\n throw err;\n }\n }\n })();\n\n if (!header) {\n throw new DecryptError.HeaderDecryptionFailed('All chains failed', DecryptError.CODE.CASE_215);\n }\n\n const rc = (() => {\n if (!recv_chain) {\n this.ratchet(header.ratchet_key, header.prev_counter);\n return this.recv_chains[0];\n }\n return recv_chain;\n })();\n\n const cipher_text = msg.cipher_text;\n const counter = header.counter;\n const recv_chain_index = rc.chain_key.idx;\n if (counter < recv_chain_index) {\n return rc.try_message_keys(envelope, header, cipher_text);\n } else if (counter == recv_chain_index) {\n const mks = rc.chain_key.message_keys();\n\n if (!envelope.verify(mks.mac_key)) {\n throw new DecryptError.InvalidSignature(`Envelope verification failed for message with counters in sync at '${counter}'`, DecryptError.CODE.CASE_206);\n }\n\n const plain = mks.decrypt(cipher_text);\n rc.chain_key = rc.chain_key.next();\n return plain;\n\n } else if (counter > recv_chain_index) {\n const [chk, mk, mks] = rc.stage_message_keys(header);\n\n if (!envelope.verify(mk.mac_key)) {\n throw new DecryptError.InvalidSignature(`Envelope verification failed for message with counter ahead. Message index is '${counter}' while receive chain index is '${recv_chain_index}'.`, DecryptError.CODE.CASE_207);\n }\n\n const plain = mk.decrypt(cipher_text);\n\n rc.chain_key = chk.next();\n rc.commit_message_keys(mks);\n\n return plain;\n }\n }\n\n /** @returns {ArrayBuffer} */\n serialise() {\n const e = new CBOR.Encoder();\n this.encode(e);\n return e.get_buffer();\n }\n\n static deserialise(buf) {\n TypeUtil.assert_is_instance(ArrayBuffer, buf);\n return SessionState.decode(new CBOR.Decoder(buf));\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n e.object(6);\n e.u8(0);\n this.next_send_head_key.encode(e);\n e.u8(1);\n this.next_recv_head_key.encode(e);\n e.u8(2);\n e.array(this.recv_chains.length);\n this.recv_chains.map((rch) => rch.encode(e));\n e.u8(3);\n this.send_chain.encode(e);\n e.u8(4);\n this.root_key.encode(e);\n e.u8(5);\n return e.u32(this.prev_counter);\n }\n\n /**\n * @param {!CBOR.Decoder} d\n * @returns {SessionState}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n const self = ClassUtil.new_instance(SessionState);\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0: {\n self.next_send_head_key = HeadKey.decode(d);\n break;\n }\n case 1: {\n self.next_recv_head_key = HeadKey.decode(d);\n break;\n }\n case 2: {\n self.recv_chains = [];\n let len = d.array();\n while (len--) {\n self.recv_chains.push(RecvChain.decode(d));\n }\n break;\n }\n case 3: {\n self.send_chain = SendChain.decode(d);\n break;\n }\n case 4: {\n self.root_key = RootKey.decode(d);\n break;\n }\n case 5: {\n self.prev_counter = d.u32();\n break;\n }\n default: {\n d.skip();\n }\n }\n }\n\n TypeUtil.assert_is_instance(HeadKey, self.next_send_head_key);\n TypeUtil.assert_is_instance(HeadKey, self.next_recv_head_key);\n TypeUtil.assert_is_instance(SendChain, self.send_chain);\n TypeUtil.assert_is_instance(Array, self.recv_chains);\n TypeUtil.assert_is_instance(RootKey, self.root_key);\n TypeUtil.assert_is_integer(self.prev_counter);\n\n return self;\n }\n}\n\nmodule.exports = SessionState;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/session/SessionState.js\n// module id = 36\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst sodium = require('libsodium-wrappers-sumo');\n\nconst ArrayUtil = require('../util/ArrayUtil');\nconst MemoryUtil = require('../util/MemoryUtil');\nconst TypeUtil = require('../util/TypeUtil');\n\n/** @module util */\n\nconst KeyDerivationUtil = {\n /**\n * HMAC-based Key Derivation Function\n *\n * @param {!(Uint8Array|string)} salt\n * @param {!(Uint8Array|string)} input - Initial Keying Material (IKM)\n * @param {!(Uint8Array|string)} info - Key Derivation Data (Info)\n * @param {!number} length - Length of the derived key in bytes (L)\n * @returns {Uint8Array} - Output Keying Material (OKM)\n */\n hkdf(salt, input, info, length) {\n const convert_type = (value) => {\n if (typeof value === 'string') {\n return sodium.from_string(value);\n }\n TypeUtil.assert_is_instance(Uint8Array, value);\n return value;\n };\n\n salt = convert_type(salt);\n input = convert_type(input);\n info = convert_type(info);\n\n TypeUtil.assert_is_integer(length);\n\n const HASH_LEN = 32;\n\n /**\n * @param {*} received_salt\n * @returns {Uint8Array}\n */\n const salt_to_key = (received_salt) => {\n const keybytes = sodium.crypto_auth_hmacsha256_KEYBYTES;\n if (received_salt.length > keybytes) {\n return sodium.crypto_hash_sha256(received_salt);\n }\n\n const key = new Uint8Array(keybytes);\n key.set(received_salt);\n return key;\n };\n\n /**\n * @param {*} received_salt\n * @param {*} received_input\n * @returns {*}\n */\n const extract = (received_salt, received_input) => {\n return sodium.crypto_auth_hmacsha256(received_input, salt_to_key(received_salt));\n };\n\n /**\n * @param {*} tag\n * @param {*} received_info\n * @param {!number} received_length\n * @returns {Uint8Array}\n */\n const expand = (tag, received_info, received_length) => {\n let num_blocks = Math.ceil(received_length / HASH_LEN);\n let hmac = new Uint8Array(0);\n let result = new Uint8Array(0);\n\n for (let i = 0; i <= num_blocks - 1; i++) {\n const buf = ArrayUtil.concatenate_array_buffers([hmac, received_info, new Uint8Array([i + 1])]);\n hmac = sodium.crypto_auth_hmacsha256(buf, tag);\n result = ArrayUtil.concatenate_array_buffers([result, hmac]);\n }\n\n return new Uint8Array(result.buffer.slice(0, received_length));\n };\n\n const key = extract(salt, input);\n\n MemoryUtil.zeroize(input);\n MemoryUtil.zeroize(salt);\n\n return expand(key, info, length);\n },\n};\n\nmodule.exports = KeyDerivationUtil;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/util/KeyDerivationUtil.js\n// module id = 37\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst TypeUtil = require('../util/TypeUtil');\n\nconst PublicKey = require('../keys/PublicKey');\n\nconst DecryptError = require('../errors/DecryptError');\nconst ProteusError = require('../errors/ProteusError');\n\nconst Header = require('../message/Header');\nconst Envelope = require('../message/Envelope');\n\nconst ChainKey = require('./ChainKey');\nconst HeadKey = require('../derived/HeadKey');\nconst MessageKeys = require('./MessageKeys');\n\n/** @module session */\n\n/**\n * @class RecvChain\n * @throws {DontCallConstructor}\n */\nclass RecvChain {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /**\n * @param {!session.ChainKey} chain_key\n * @param {!keys.PublicKey} public_key\n * @param {!derived.HeadKey} head_key\n * @returns {RecvChain}\n */\n static new(chain_key, public_key, head_key) {\n TypeUtil.assert_is_instance(ChainKey, chain_key);\n TypeUtil.assert_is_instance(PublicKey, public_key);\n\n const rc = ClassUtil.new_instance(RecvChain);\n rc.chain_key = chain_key;\n rc.ratchet_key = public_key;\n rc.head_key = head_key;\n rc.final_count = null;\n rc.message_keys = [];\n return rc;\n }\n\n /**\n * @param {!number} start_index\n * @param {!number} end_index\n * @param {!Uint8Array} encrypted_header - encrypted header\n * @param {!derived.HeadKey} head_key\n * @returns {message.Header}\n * @private\n */\n static _try_head_key(start_index, end_index, encrypted_header, head_key) {\n const [header, index] = (() => {\n for (let i = start_index; i <= end_index; i++) {\n try {\n const header_typed_array = head_key.decrypt(encrypted_header, HeadKey.index_as_nonce(i));\n return [Header.deserialise(header_typed_array.buffer), i];\n } catch (err) {\n // noop\n }\n }\n return [null, 0];\n })();\n\n if (!header) {\n throw new DecryptError.HeaderDecryptionFailed('Head key not match', DecryptError.CODE.CASE_213);\n }\n\n if (header.counter !== index) {\n throw new DecryptError.InvalidHeader('Invalid header', DecryptError.CODE.CASE_214);\n }\n\n return header;\n }\n\n /**\n * @param {!Uint8Array} encrypted_header - encrypted header\n * @param {!derived.HeadKey} next_head_key\n * @returns {message.Header}\n */\n static try_next_head_key(encrypted_header, next_head_key) {\n\n return RecvChain._try_head_key(0, RecvChain.MAX_COUNTER_GAP, encrypted_header, next_head_key);\n }\n\n /**\n * @param {!Uint8Array} encrypted_header - encrypted header\n * @returns {message.Header}\n */\n try_head_key(encrypted_header) {\n const final_count = this.final_count;\n\n const start_index = this.message_keys.length > 0\n ? this.message_keys[0].counter\n : this.chain_key.idx;\n const end_index = final_count !== null\n ? final_count - 1\n : start_index + RecvChain.MAX_COUNTER_GAP;\n\n return RecvChain._try_head_key(start_index, end_index, encrypted_header, this.head_key);\n }\n\n /**\n * @param {!message.Envelope} envelope\n * @param {!message.Header} header\n * @param {!Uint8Array} cipher_text\n * @returns {Uint8Array}\n */\n try_message_keys(envelope, header, cipher_text) {\n TypeUtil.assert_is_instance(Envelope, envelope);\n TypeUtil.assert_is_instance(Header, header);\n TypeUtil.assert_is_instance(Uint8Array, cipher_text);\n\n if (this.message_keys[0] && this.message_keys[0].counter > header.counter) {\n const message = `Message too old. Counter for oldest staged chain key is '${this.message_keys[0].counter}' while message counter is '${header.counter}'.`;\n throw new DecryptError.OutdatedMessage(message, DecryptError.CODE.CASE_208);\n }\n\n const idx = this.message_keys.findIndex((mk) => {\n return mk.counter === header.counter;\n });\n\n if (idx === -1) {\n throw new DecryptError.DuplicateMessage(null, DecryptError.CODE.CASE_209);\n }\n\n const mk = this.message_keys.splice(idx, 1)[0];\n if (!envelope.verify(mk.mac_key)) {\n const message = `Envelope verification failed for message with counter behind. Message index is '${header.counter}' while receive chain index is '${this.chain_key.idx}'.`;\n throw new DecryptError.InvalidSignature(message, DecryptError.CODE.CASE_210);\n }\n\n return mk.decrypt(cipher_text);\n }\n\n /**\n * @param {!message.Header} header\n * @returns {Array<session.ChainKey>|session.MessageKeys}\n */\n stage_message_keys(header) {\n TypeUtil.assert_is_instance(Header, header);\n\n const num = header.counter - this.chain_key.idx;\n if (num > RecvChain.MAX_COUNTER_GAP) {\n if (this.chain_key.idx === 0) {\n throw new DecryptError.TooDistantFuture('Skipped too many message at the beginning of a receive chain.', DecryptError.CODE.CASE_211);\n }\n throw new DecryptError.TooDistantFuture(`Skipped too many message within a used receive chain. Receive chain counter is '${this.chain_key.idx}'`, DecryptError.CODE.CASE_212);\n }\n\n let keys = [];\n let chk = this.chain_key;\n\n for (let i = 0; i <= num - 1; i++) {\n keys.push(chk.message_keys());\n chk = chk.next();\n }\n\n const mk = chk.message_keys();\n return [chk, mk, keys];\n }\n\n /**\n * @param {!Array<session.MessageKeys>} keys\n * @returns {void}\n */\n commit_message_keys(keys) {\n TypeUtil.assert_is_instance(Array, keys);\n keys.map((k) => TypeUtil.assert_is_instance(MessageKeys, k));\n\n if (keys.length > RecvChain.MAX_COUNTER_GAP) {\n throw new ProteusError(`Number of message keys (${keys.length}) exceed message chain counter gap (${RecvChain.MAX_COUNTER_GAP}).`, ProteusError.prototype.CODE.CASE_103);\n }\n\n const excess = this.message_keys.length + keys.length - RecvChain.MAX_COUNTER_GAP;\n\n for (let i = 0; i <= excess - 1; i++) {\n this.message_keys.shift();\n }\n\n keys.map((k) => this.message_keys.push(k));\n\n if (keys.length > RecvChain.MAX_COUNTER_GAP) {\n throw new ProteusError(`Skipped message keys which exceed the message chain counter gap (${RecvChain.MAX_COUNTER_GAP}).`, ProteusError.prototype.CODE.CASE_104);\n }\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {Array<CBOR.Encoder>}\n */\n encode(e) {\n e.object(5);\n e.u8(0);\n this.chain_key.encode(e);\n e.u8(1);\n this.ratchet_key.encode(e);\n e.u8(2);\n this.head_key.encode(e);\n e.u8(3);\n if (this.final_count !== null) {\n e.u32(this.final_count);\n } else {\n e.null();\n }\n\n e.u8(4);\n e.array(this.message_keys.length);\n return this.message_keys.map((k) => k.encode(e));\n }\n\n /**\n * @param {!CBOR.Decoder} d\n * @returns {RecvChain}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n const self = ClassUtil.new_instance(RecvChain);\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0: {\n self.chain_key = ChainKey.decode(d);\n break;\n }\n case 1: {\n self.ratchet_key = PublicKey.decode(d);\n break;\n }\n case 2: {\n self.head_key = HeadKey.decode(d);\n break;\n }\n case 3: {\n self.final_count = d.optional(() => d.u32());\n break;\n }\n case 4: {\n self.message_keys = [];\n\n let len = d.array();\n while (len--) {\n self.message_keys.push(MessageKeys.decode(d));\n }\n break;\n }\n default: {\n d.skip();\n }\n }\n }\n\n TypeUtil.assert_is_instance(ChainKey, self.chain_key);\n TypeUtil.assert_is_instance(PublicKey, self.ratchet_key);\n TypeUtil.assert_is_instance(HeadKey, self.head_key);\n TypeUtil.assert_is_instance(Array, self.message_keys);\n\n return self;\n }\n}\n\n/** @type {number} */\nRecvChain.MAX_COUNTER_GAP = 1000;\n\nmodule.exports = RecvChain;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/session/RecvChain.js\n// module id = 38\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst TypeUtil = require('../util/TypeUtil');\n\nconst ChainKey = require('./ChainKey');\nconst CipherKey = require('../derived/CipherKey');\nconst DerivedSecrets = require('../derived/DerivedSecrets');\nconst KeyPair = require('../keys/KeyPair');\nconst PublicKey = require('../keys/PublicKey');\n\n/** @module session */\n\n/**\n * @class RootKey\n * @throws {DontCallConstructor}\n */\nclass RootKey {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /**\n * @param {!derived.CipherKey} cipher_key - Cipher key generated by derived secrets\n * @returns {RootKey}\n */\n static from_cipher_key(cipher_key) {\n TypeUtil.assert_is_instance(CipherKey, cipher_key);\n\n const rk = ClassUtil.new_instance(RootKey);\n rk.key = cipher_key;\n return rk;\n }\n\n /**\n * @param {!keys.KeyPair} ours - Our key pair\n * @param {!keys.PublicKey} theirs - Their public key\n * @returns {Array<RootKey|session.ChainKey|derived.HeadKey>}\n */\n dh_ratchet(ours, theirs) {\n TypeUtil.assert_is_instance(KeyPair, ours);\n TypeUtil.assert_is_instance(PublicKey, theirs);\n\n const secret = ours.secret_key.shared_secret(theirs);\n const derived_secrets = DerivedSecrets.kdf(secret, this.key.key, 'dh_ratchet');\n\n return [\n RootKey.from_cipher_key(derived_secrets.cipher_key),\n ChainKey.from_mac_key(derived_secrets.mac_key, 0),\n derived_secrets.next_head_key,\n ];\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n e.object(1);\n e.u8(0);\n return this.key.encode(e);\n }\n\n /**\n * @param {!CBOR.Decoder} d\n * @returns {RootKey}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n\n let cipher_key = null;\n\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0:\n cipher_key = CipherKey.decode(d);\n break;\n default:\n d.skip();\n }\n }\n return RootKey.from_cipher_key(cipher_key);\n }\n}\n\nmodule.exports = RootKey;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/session/RootKey.js\n// module id = 39\n// module chunks = 0","/*\n * Wire\n * Copyright (C) 2016 Wire Swiss GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see http://www.gnu.org/licenses/.\n *\n */\n\n'use strict';\n\nconst CBOR = require('wire-webapp-cbor');\n\nconst ClassUtil = require('../util/ClassUtil');\nconst DontCallConstructor = require('../errors/DontCallConstructor');\nconst TypeUtil = require('../util/TypeUtil');\n\nconst ChainKey = require('./ChainKey');\nconst HeadKey = require('../derived/HeadKey');\nconst KeyPair = require('../keys/KeyPair');\n\n/** @module session */\n\n/**\n * @class SendChain\n * @throws {DontCallConstructor}\n */\nclass SendChain {\n constructor() {\n throw new DontCallConstructor(this);\n }\n\n /**\n * @param {!session.ChainKey} chain_key\n * @param {!keys.KeyPair} keypair\n * @param {!derived.HeadKey} head_key\n * @returns {session.SendChain}\n */\n static new(chain_key, keypair, head_key) {\n TypeUtil.assert_is_instance(ChainKey, chain_key);\n TypeUtil.assert_is_instance(KeyPair, keypair);\n TypeUtil.assert_is_instance(HeadKey, head_key);\n\n const sc = ClassUtil.new_instance(SendChain);\n sc.chain_key = chain_key;\n sc.ratchet_key = keypair;\n sc.head_key = head_key;\n return sc;\n }\n\n /**\n * @param {!CBOR.Encoder} e\n * @returns {CBOR.Encoder}\n */\n encode(e) {\n e.object(3);\n e.u8(0);\n this.chain_key.encode(e);\n e.u8(1);\n this.ratchet_key.encode(e);\n e.u8(2);\n return this.head_key.encode(e);\n }\n\n /**\n * @param {!CBOR.Decoder} d\n * @returns {SendChain}\n */\n static decode(d) {\n TypeUtil.assert_is_instance(CBOR.Decoder, d);\n const self = ClassUtil.new_instance(SendChain);\n const nprops = d.object();\n for (let i = 0; i <= nprops - 1; i++) {\n switch (d.u8()) {\n case 0:\n self.chain_key = ChainKey.decode(d);\n break;\n case 1:\n self.ratchet_key = KeyPair.decode(d);\n break;\n case 2:\n self.head_key = HeadKey.decode(d);\n break;\n default:\n d.skip();\n }\n }\n TypeUtil.assert_is_instance(ChainKey, self.chain_key);\n TypeUtil.assert_is_instance(KeyPair, self.ratchet_key);\n TypeUtil.assert_is_instance(HeadKey, self.head_key);\n return self;\n }\n}\n\nmodule.exports = SendChain;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./src/proteus/session/SendChain.js\n// module id = 40\n// module chunks = 0"],"sourceRoot":""}
\No newline at end of file