{"version":3,"sources":["node_modules/text-encoding-utf-8/lib/encoding.lib.mjs","node_modules/matrix-react-sdk/lib/utils/MegolmExportEncryption.js"],"names":["inRange","a","min","max","ToDictionary","o","undefined","Object","TypeError","__webpack_require__","r","__webpack_exports__","d","TextEncoder","TextDecoder","end_of_stream","Stream","tokens","this","slice","call","prototype","endOfStream","length","read","shift","prepend","token","Array","isArray","unshift","pop","push","finished","decoderError","fatal","opt_code_point","DEFAULT_ENCODING","encoding","options","String","toLowerCase","Error","_streaming","_BOMseen","_decoder","_fatal","Boolean","_ignoreBOM","defineProperty","value","_encoder","_options","decode","input","bytes","ArrayBuffer","Uint8Array","buffer","byteOffset","byteLength","utf8_code_point","utf8_bytes_seen","utf8_bytes_needed","utf8_lower_boundary","utf8_upper_boundary","handler","stream","bite","code_point","result","input_stream","code_points","apply","indexOf","s","i","cp","fromCharCode","codePointsToString","encode","opt_string","count","offset","temp","string","n","u","c","charCodeAt","b","stringToCodePoints","exports","encryptMegolmKeyFile","decryptMegolmKeyFile","_promise2","_interopRequireDefault","_regenerator2","_slicedToArray3","_bluebird","deriveKeys","_ref","coroutine","default","mark","_callee","data","password","body","ciphertextLength","salt","iv","iterations","ciphertext","hmac","_ref2","_ref3","aesKey","hmacKey","toVerify","isValid","plaintext","wrap","_context","prev","next","unpackMegolmKeyFile","friendlyError","_languageHandler","_t","subarray","resolve","sent","subtleCrypto","verify","name","t0","cryptoFailMsg","decrypt","counter","t1","abrupt","stop","_x","_x2","arguments","_ref4","_callee2","kdfRounds","_ref5","_ref6","encodedData","cipherArray","bodyLength","resultBuffer","idx","toSign","hmacArray","_context2","kdf_rounds","window","crypto","getRandomValues","encrypt","set","sign","packMegolmKeyFile","_x3","_x4","_x5","_ref7","_callee3","start","key","keybits","now","aesProm","hmacProm","_context3","Date","importKey","deriveBits","hash","console","log","catch","e","all","_x6","_x7","_x8","TextEncodingUtf8","obj","__esModule","newObj","hasOwnProperty","_interopRequireWildcard","subtle","webkitSubtle","msg","friendlyText","HEADER_LINE","TRAILER_LINE","fileStr","lineStart","lineEnd","line","trim","dataStart","_lineEnd","dataEnd","base64","latin1String","atob","uint8Array","decodeBase64","nLines","Math","ceil","lines","encodeBase64","join","btoa"],"mappings":"0FAeA,SAAAA,EAAAC,EAAAC,EAAAC,GACA,OAAAD,GAAAD,MAAAE,EAOA,SAAAC,EAAAC,GACA,QAAAC,IAAAD,EAAA,SACA,GAAAA,IAAAE,OAAAF,GAAA,OAAAA,EACA,MAAAG,UAAA,4CA1BAC,EAAAC,EAAAC,GAAAF,EAAAG,EAAAD,EAAA,gCAAAE,IAAAJ,EAAAG,EAAAD,EAAA,gCAAAG,IAiJA,IAAAC,GAAA,EASA,SAAAC,EAAAC,GAEAC,KAAAD,UAAAE,MAAAC,KAAAH,GAGAD,EAAAK,WAIAC,YAAA,WACA,OAAAJ,KAAAD,OAAAM,QAWAC,KAAA,WACA,OAAAN,KAAAD,OAAAM,OAEAL,KAAAD,OAAAQ,QADAV,GAWAW,QAAA,SAAAC,GACA,GAAAC,MAAAC,QAAAF,GAEA,IADA,IAAAV,EAA6C,EAC7CA,EAAAM,QACAL,KAAAD,OAAAa,QAAAb,EAAAc,YAEAb,KAAAD,OAAAa,QAAAH,IAWAK,KAAA,SAAAL,GACA,GAAAC,MAAAC,QAAAF,GAEA,IADA,IAAAV,EAA6C,EAC7CA,EAAAM,QACAL,KAAAD,OAAAe,KAAAf,EAAAQ,cAEAP,KAAAD,OAAAe,KAAAL,KAYA,IAAAM,GAAA,EAOA,SAAAC,EAAAC,EAAAC,GACA,GAAAD,EACA,MAAA3B,UAAA,iBACA,OAAA4B,GAAA,MA+BA,IAAAC,EAAA,QAUA,SAAAvB,EAAAwB,EAAAC,GACA,KAAArB,gBAAAJ,GACA,WAAAA,EAAAwB,EAAAC,GAGA,IADAD,OAAAhC,IAAAgC,EAAAE,OAAAF,GAAAG,cAAAJ,KACAA,EACA,UAAAK,MAAA,mDAEAH,EAAAnC,EAAAmC,GAGArB,KAAAyB,YA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GACA,GAAAC,EAAA,EACA,UAAAnK,MAAA,yBAEA,IAAAoK,EAAAH,EAAAxL,MAAAyL,EAAAC,GAAAE,OAKA,GAFAH,EAAAC,EAAA,EAEAC,IAAAL,EACA,MAOA,IAHA,IAAAO,EAAAJ,IAGA,CACA,IAAAK,EAAAN,EAAAjI,QAAA,KAAAkI,GAEA,GADAD,EAAAxL,MAAAyL,EAAAK,EAAA,OAAA3M,EAAA2M,GAAAF,SACAL,EACA,MAGA,GAAAO,EAAA,EACA,UAAAvK,MAAA,0BAIAkK,EAAAK,EAAA,EAGA,IAAAC,EAAAN,EACA,OA+CA,SAAAO,GAKA,IAHA,IAAAC,EAAApD,OAAAqD,KAAAF,GAEAG,EAAA,IAAA7J,WAAA2J,EAAA7L,QACAqD,EAAA,EAAmBA,EAAAwI,EAAA7L,OAAyBqD,IAC5C0I,EAAA1I,GAAAwI,EAAA3H,WAAAb,GAEA,OAAA0I,EAvDAC,CAAAZ,EAAAxL,MAAA6L,EAAAE,IAWA,SAAA5C,EAAA5D,GAGA,IACA8G,EAAAC,KAAAC,KAAAhH,EAAAnF,OADA,IAEAoM,EAAA,IAAA/L,MAAA4L,EAAA,GACAG,EAAA,GAAAlB,EACA,IAAApM,EAAA,EACAuE,OAAA,EACA,IAAAA,EAAA,EAAeA,GAAA4I,EAAa5I,IAC5B+I,EAAA/I,GAAAgJ,EAAAlH,EAAAwB,SAAA7H,IAPA,KAQAA,GARA,GAYA,OAFAsN,EAAA/I,KAAA8H,EACAiB,EAAA/I,GAAA,IACA,IAAA/D,GAAAmE,OAAA2I,EAAAE,KAAA,OAAAnK,OAQA,SAAAkK,EAAAN,GAGA,IAAAF,EAAA5K,OAAAsC,aAAAL,MAAA,KAAA6I,GAEA,OAAAtD,OAAA8D,KAAAV","file":"bundles/c2932262ed6106cd4535/0.js","sourcesContent":["'use strict';\n\n// This is free and unencumbered software released into the public domain.\n// See LICENSE.md for more information.\n\n//\n// Utilities\n//\n\n/**\n * @param {number} a The number to test.\n * @param {number} min The minimum value in the range, inclusive.\n * @param {number} max The maximum value in the range, inclusive.\n * @return {boolean} True if a >= min and a <= max.\n */\nfunction inRange(a, min, max) {\n return min <= a && a <= max;\n}\n\n/**\n * @param {*} o\n * @return {Object}\n */\nfunction ToDictionary(o) {\n if (o === undefined) return {};\n if (o === Object(o)) return o;\n throw TypeError('Could not convert argument to dictionary');\n}\n\n/**\n * @param {string} string Input string of UTF-16 code units.\n * @return {!Array.} Code points.\n */\nfunction stringToCodePoints(string) {\n // https://heycam.github.io/webidl/#dfn-obtain-unicode\n\n // 1. Let S be the DOMString value.\n var s = String(string);\n\n // 2. Let n be the length of S.\n var n = s.length;\n\n // 3. Initialize i to 0.\n var i = 0;\n\n // 4. Initialize U to be an empty sequence of Unicode characters.\n var u = [];\n\n // 5. While i < n:\n while (i < n) {\n\n // 1. Let c be the code unit in S at index i.\n var c = s.charCodeAt(i);\n\n // 2. Depending on the value of c:\n\n // c < 0xD800 or c > 0xDFFF\n if (c < 0xD800 || c > 0xDFFF) {\n // Append to U the Unicode character with code point c.\n u.push(c);\n }\n\n // 0xDC00 ≤ c ≤ 0xDFFF\n else if (0xDC00 <= c && c <= 0xDFFF) {\n // Append to U a U+FFFD REPLACEMENT CHARACTER.\n u.push(0xFFFD);\n }\n\n // 0xD800 ≤ c ≤ 0xDBFF\n else if (0xD800 <= c && c <= 0xDBFF) {\n // 1. If i = n−1, then append to U a U+FFFD REPLACEMENT\n // CHARACTER.\n if (i === n - 1) {\n u.push(0xFFFD);\n }\n // 2. Otherwise, i < n−1:\n else {\n // 1. Let d be the code unit in S at index i+1.\n var d = string.charCodeAt(i + 1);\n\n // 2. If 0xDC00 ≤ d ≤ 0xDFFF, then:\n if (0xDC00 <= d && d <= 0xDFFF) {\n // 1. Let a be c & 0x3FF.\n var a = c & 0x3FF;\n\n // 2. Let b be d & 0x3FF.\n var b = d & 0x3FF;\n\n // 3. Append to U the Unicode character with code point\n // 2^16+2^10*a+b.\n u.push(0x10000 + (a << 10) + b);\n\n // 4. Set i to i+1.\n i += 1;\n }\n\n // 3. Otherwise, d < 0xDC00 or d > 0xDFFF. Append to U a\n // U+FFFD REPLACEMENT CHARACTER.\n else {\n u.push(0xFFFD);\n }\n }\n }\n\n // 3. Set i to i+1.\n i += 1;\n }\n\n // 6. Return U.\n return u;\n}\n\n/**\n * @param {!Array.} code_points Array of code points.\n * @return {string} string String of UTF-16 code units.\n */\nfunction codePointsToString(code_points) {\n var s = '';\n for (var i = 0; i < code_points.length; ++i) {\n var cp = code_points[i];\n if (cp <= 0xFFFF) {\n s += String.fromCharCode(cp);\n } else {\n cp -= 0x10000;\n s += String.fromCharCode((cp >> 10) + 0xD800,\n (cp & 0x3FF) + 0xDC00);\n }\n }\n return s;\n}\n\n\n//\n// Implementation of Encoding specification\n// https://encoding.spec.whatwg.org/\n//\n\n//\n// 3. Terminology\n//\n\n/**\n * End-of-stream is a special token that signifies no more tokens\n * are in the stream.\n * @const\n */ var end_of_stream = -1;\n\n/**\n * A stream represents an ordered sequence of tokens.\n *\n * @constructor\n * @param {!(Array.|Uint8Array)} tokens Array of tokens that provide the\n * stream.\n */\nfunction Stream(tokens) {\n /** @type {!Array.} */\n this.tokens = [].slice.call(tokens);\n}\n\nStream.prototype = {\n /**\n * @return {boolean} True if end-of-stream has been hit.\n */\n endOfStream: function() {\n return !this.tokens.length;\n },\n\n /**\n * When a token is read from a stream, the first token in the\n * stream must be returned and subsequently removed, and\n * end-of-stream must be returned otherwise.\n *\n * @return {number} Get the next token from the stream, or\n * end_of_stream.\n */\n read: function() {\n if (!this.tokens.length)\n return end_of_stream;\n return this.tokens.shift();\n },\n\n /**\n * When one or more tokens are prepended to a stream, those tokens\n * must be inserted, in given order, before the first token in the\n * stream.\n *\n * @param {(number|!Array.)} token The token(s) to prepend to the stream.\n */\n prepend: function(token) {\n if (Array.isArray(token)) {\n var tokens = /**@type {!Array.}*/(token);\n while (tokens.length)\n this.tokens.unshift(tokens.pop());\n } else {\n this.tokens.unshift(token);\n }\n },\n\n /**\n * When one or more tokens are pushed to a stream, those tokens\n * must be inserted, in given order, after the last token in the\n * stream.\n *\n * @param {(number|!Array.)} token The tokens(s) to prepend to the stream.\n */\n push: function(token) {\n if (Array.isArray(token)) {\n var tokens = /**@type {!Array.}*/(token);\n while (tokens.length)\n this.tokens.push(tokens.shift());\n } else {\n this.tokens.push(token);\n }\n }\n};\n\n//\n// 4. Encodings\n//\n\n// 4.1 Encoders and decoders\n\n/** @const */\nvar finished = -1;\n\n/**\n * @param {boolean} fatal If true, decoding errors raise an exception.\n * @param {number=} opt_code_point Override the standard fallback code point.\n * @return {number} The code point to insert on a decoding error.\n */\nfunction decoderError(fatal, opt_code_point) {\n if (fatal)\n throw TypeError('Decoder error');\n return opt_code_point || 0xFFFD;\n}\n\n/** @interface */\nfunction Decoder() {}\nDecoder.prototype = {\n /**\n * @param {Stream} stream The stream of bytes being decoded.\n * @param {number} bite The next byte read from the stream.\n * @return {?(number|!Array.)} The next code point(s)\n * decoded, or null if not enough data exists in the input\n * stream to decode a complete code point, or |finished|.\n */\n handler: function(stream, bite) {}\n};\n\n/** @interface */\nfunction Encoder() {}\nEncoder.prototype = {\n /**\n * @param {Stream} stream The stream of code points being encoded.\n * @param {number} code_point Next code point read from the stream.\n * @return {(number|!Array.)} Byte(s) to emit, or |finished|.\n */\n handler: function(stream, code_point) {}\n};\n\n//\n// 7. API\n//\n\n/** @const */ var DEFAULT_ENCODING = 'utf-8';\n\n// 7.1 Interface TextDecoder\n\n/**\n * @constructor\n * @param {string=} encoding The label of the encoding;\n * defaults to 'utf-8'.\n * @param {Object=} options\n */\nfunction TextDecoder(encoding, options) {\n if (!(this instanceof TextDecoder)) {\n return new TextDecoder(encoding, options);\n }\n encoding = encoding !== undefined ? String(encoding).toLowerCase() : DEFAULT_ENCODING;\n if (encoding !== DEFAULT_ENCODING) {\n throw new Error('Encoding not supported. Only utf-8 is supported');\n }\n options = ToDictionary(options);\n\n /** @private @type {boolean} */\n this._streaming = false;\n /** @private @type {boolean} */\n this._BOMseen = false;\n /** @private @type {?Decoder} */\n this._decoder = null;\n /** @private @type {boolean} */\n this._fatal = Boolean(options['fatal']);\n /** @private @type {boolean} */\n this._ignoreBOM = Boolean(options['ignoreBOM']);\n\n Object.defineProperty(this, 'encoding', {value: 'utf-8'});\n Object.defineProperty(this, 'fatal', {value: this._fatal});\n Object.defineProperty(this, 'ignoreBOM', {value: this._ignoreBOM});\n}\n\nTextDecoder.prototype = {\n /**\n * @param {ArrayBufferView=} input The buffer of bytes to decode.\n * @param {Object=} options\n * @return {string} The decoded string.\n */\n decode: function decode(input, options) {\n var bytes;\n if (typeof input === 'object' && input instanceof ArrayBuffer) {\n bytes = new Uint8Array(input);\n } else if (typeof input === 'object' && 'buffer' in input &&\n input.buffer instanceof ArrayBuffer) {\n bytes = new Uint8Array(input.buffer,\n input.byteOffset,\n input.byteLength);\n } else {\n bytes = new Uint8Array(0);\n }\n\n options = ToDictionary(options);\n\n if (!this._streaming) {\n this._decoder = new UTF8Decoder({fatal: this._fatal});\n this._BOMseen = false;\n }\n this._streaming = Boolean(options['stream']);\n\n var input_stream = new Stream(bytes);\n\n var code_points = [];\n\n /** @type {?(number|!Array.)} */\n var result;\n\n while (!input_stream.endOfStream()) {\n result = this._decoder.handler(input_stream, input_stream.read());\n if (result === finished)\n break;\n if (result === null)\n continue;\n if (Array.isArray(result))\n code_points.push.apply(code_points, /**@type {!Array.}*/(result));\n else\n code_points.push(result);\n }\n if (!this._streaming) {\n do {\n result = this._decoder.handler(input_stream, input_stream.read());\n if (result === finished)\n break;\n if (result === null)\n continue;\n if (Array.isArray(result))\n code_points.push.apply(code_points, /**@type {!Array.}*/(result));\n else\n code_points.push(result);\n } while (!input_stream.endOfStream());\n this._decoder = null;\n }\n\n if (code_points.length) {\n // If encoding is one of utf-8, utf-16be, and utf-16le, and\n // ignore BOM flag and BOM seen flag are unset, run these\n // subsubsteps:\n if (['utf-8'].indexOf(this.encoding) !== -1 &&\n !this._ignoreBOM && !this._BOMseen) {\n // If token is U+FEFF, set BOM seen flag.\n if (code_points[0] === 0xFEFF) {\n this._BOMseen = true;\n code_points.shift();\n } else {\n // Otherwise, if token is not end-of-stream, set BOM seen\n // flag and append token to output.\n this._BOMseen = true;\n }\n }\n }\n\n return codePointsToString(code_points);\n }\n};\n\n// 7.2 Interface TextEncoder\n\n/**\n * @constructor\n * @param {string=} encoding The label of the encoding;\n * defaults to 'utf-8'.\n * @param {Object=} options\n */\nfunction TextEncoder(encoding, options) {\n if (!(this instanceof TextEncoder))\n return new TextEncoder(encoding, options);\n encoding = encoding !== undefined ? String(encoding).toLowerCase() : DEFAULT_ENCODING;\n if (encoding !== DEFAULT_ENCODING) {\n throw new Error('Encoding not supported. Only utf-8 is supported');\n }\n options = ToDictionary(options);\n\n /** @private @type {boolean} */\n this._streaming = false;\n /** @private @type {?Encoder} */\n this._encoder = null;\n /** @private @type {{fatal: boolean}} */\n this._options = {fatal: Boolean(options['fatal'])};\n\n Object.defineProperty(this, 'encoding', {value: 'utf-8'});\n}\n\nTextEncoder.prototype = {\n /**\n * @param {string=} opt_string The string to encode.\n * @param {Object=} options\n * @return {Uint8Array} Encoded bytes, as a Uint8Array.\n */\n encode: function encode(opt_string, options) {\n opt_string = opt_string ? String(opt_string) : '';\n options = ToDictionary(options);\n\n // NOTE: This option is nonstandard. None of the encodings\n // permitted for encoding (i.e. UTF-8, UTF-16) are stateful,\n // so streaming is not necessary.\n if (!this._streaming)\n this._encoder = new UTF8Encoder(this._options);\n this._streaming = Boolean(options['stream']);\n\n var bytes = [];\n var input_stream = new Stream(stringToCodePoints(opt_string));\n /** @type {?(number|!Array.)} */\n var result;\n while (!input_stream.endOfStream()) {\n result = this._encoder.handler(input_stream, input_stream.read());\n if (result === finished)\n break;\n if (Array.isArray(result))\n bytes.push.apply(bytes, /**@type {!Array.}*/(result));\n else\n bytes.push(result);\n }\n if (!this._streaming) {\n while (true) {\n result = this._encoder.handler(input_stream, input_stream.read());\n if (result === finished)\n break;\n if (Array.isArray(result))\n bytes.push.apply(bytes, /**@type {!Array.}*/(result));\n else\n bytes.push(result);\n }\n this._encoder = null;\n }\n return new Uint8Array(bytes);\n }\n};\n\n//\n// 8. The encoding\n//\n\n// 8.1 utf-8\n\n/**\n * @constructor\n * @implements {Decoder}\n * @param {{fatal: boolean}} options\n */\nfunction UTF8Decoder(options) {\n var fatal = options.fatal;\n\n // utf-8's decoder's has an associated utf-8 code point, utf-8\n // bytes seen, and utf-8 bytes needed (all initially 0), a utf-8\n // lower boundary (initially 0x80), and a utf-8 upper boundary\n // (initially 0xBF).\n var /** @type {number} */ utf8_code_point = 0,\n /** @type {number} */ utf8_bytes_seen = 0,\n /** @type {number} */ utf8_bytes_needed = 0,\n /** @type {number} */ utf8_lower_boundary = 0x80,\n /** @type {number} */ utf8_upper_boundary = 0xBF;\n\n /**\n * @param {Stream} stream The stream of bytes being decoded.\n * @param {number} bite The next byte read from the stream.\n * @return {?(number|!Array.)} The next code point(s)\n * decoded, or null if not enough data exists in the input\n * stream to decode a complete code point.\n */\n this.handler = function(stream, bite) {\n // 1. If byte is end-of-stream and utf-8 bytes needed is not 0,\n // set utf-8 bytes needed to 0 and return error.\n if (bite === end_of_stream && utf8_bytes_needed !== 0) {\n utf8_bytes_needed = 0;\n return decoderError(fatal);\n }\n\n // 2. If byte is end-of-stream, return finished.\n if (bite === end_of_stream)\n return finished;\n\n // 3. If utf-8 bytes needed is 0, based on byte:\n if (utf8_bytes_needed === 0) {\n\n // 0x00 to 0x7F\n if (inRange(bite, 0x00, 0x7F)) {\n // Return a code point whose value is byte.\n return bite;\n }\n\n // 0xC2 to 0xDF\n if (inRange(bite, 0xC2, 0xDF)) {\n // Set utf-8 bytes needed to 1 and utf-8 code point to byte\n // − 0xC0.\n utf8_bytes_needed = 1;\n utf8_code_point = bite - 0xC0;\n }\n\n // 0xE0 to 0xEF\n else if (inRange(bite, 0xE0, 0xEF)) {\n // 1. If byte is 0xE0, set utf-8 lower boundary to 0xA0.\n if (bite === 0xE0)\n utf8_lower_boundary = 0xA0;\n // 2. If byte is 0xED, set utf-8 upper boundary to 0x9F.\n if (bite === 0xED)\n utf8_upper_boundary = 0x9F;\n // 3. Set utf-8 bytes needed to 2 and utf-8 code point to\n // byte − 0xE0.\n utf8_bytes_needed = 2;\n utf8_code_point = bite - 0xE0;\n }\n\n // 0xF0 to 0xF4\n else if (inRange(bite, 0xF0, 0xF4)) {\n // 1. If byte is 0xF0, set utf-8 lower boundary to 0x90.\n if (bite === 0xF0)\n utf8_lower_boundary = 0x90;\n // 2. If byte is 0xF4, set utf-8 upper boundary to 0x8F.\n if (bite === 0xF4)\n utf8_upper_boundary = 0x8F;\n // 3. Set utf-8 bytes needed to 3 and utf-8 code point to\n // byte − 0xF0.\n utf8_bytes_needed = 3;\n utf8_code_point = bite - 0xF0;\n }\n\n // Otherwise\n else {\n // Return error.\n return decoderError(fatal);\n }\n\n // Then (byte is in the range 0xC2 to 0xF4) set utf-8 code\n // point to utf-8 code point << (6 × utf-8 bytes needed) and\n // return continue.\n utf8_code_point = utf8_code_point << (6 * utf8_bytes_needed);\n return null;\n }\n\n // 4. If byte is not in the range utf-8 lower boundary to utf-8\n // upper boundary, run these substeps:\n if (!inRange(bite, utf8_lower_boundary, utf8_upper_boundary)) {\n\n // 1. Set utf-8 code point, utf-8 bytes needed, and utf-8\n // bytes seen to 0, set utf-8 lower boundary to 0x80, and set\n // utf-8 upper boundary to 0xBF.\n utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0;\n utf8_lower_boundary = 0x80;\n utf8_upper_boundary = 0xBF;\n\n // 2. Prepend byte to stream.\n stream.prepend(bite);\n\n // 3. Return error.\n return decoderError(fatal);\n }\n\n // 5. Set utf-8 lower boundary to 0x80 and utf-8 upper boundary\n // to 0xBF.\n utf8_lower_boundary = 0x80;\n utf8_upper_boundary = 0xBF;\n\n // 6. Increase utf-8 bytes seen by one and set utf-8 code point\n // to utf-8 code point + (byte − 0x80) << (6 × (utf-8 bytes\n // needed − utf-8 bytes seen)).\n utf8_bytes_seen += 1;\n utf8_code_point += (bite - 0x80) << (6 * (utf8_bytes_needed - utf8_bytes_seen));\n\n // 7. If utf-8 bytes seen is not equal to utf-8 bytes needed,\n // continue.\n if (utf8_bytes_seen !== utf8_bytes_needed)\n return null;\n\n // 8. Let code point be utf-8 code point.\n var code_point = utf8_code_point;\n\n // 9. Set utf-8 code point, utf-8 bytes needed, and utf-8 bytes\n // seen to 0.\n utf8_code_point = utf8_bytes_needed = utf8_bytes_seen = 0;\n\n // 10. Return a code point whose value is code point.\n return code_point;\n };\n}\n\n/**\n * @constructor\n * @implements {Encoder}\n * @param {{fatal: boolean}} options\n */\nfunction UTF8Encoder(options) {\n var fatal = options.fatal;\n /**\n * @param {Stream} stream Input stream.\n * @param {number} code_point Next code point read from the stream.\n * @return {(number|!Array.)} Byte(s) to emit.\n */\n this.handler = function(stream, code_point) {\n // 1. If code point is end-of-stream, return finished.\n if (code_point === end_of_stream)\n return finished;\n\n // 2. If code point is in the range U+0000 to U+007F, return a\n // byte whose value is code point.\n if (inRange(code_point, 0x0000, 0x007f))\n return code_point;\n\n // 3. Set count and offset based on the range code point is in:\n var count, offset;\n // U+0080 to U+07FF: 1 and 0xC0\n if (inRange(code_point, 0x0080, 0x07FF)) {\n count = 1;\n offset = 0xC0;\n }\n // U+0800 to U+FFFF: 2 and 0xE0\n else if (inRange(code_point, 0x0800, 0xFFFF)) {\n count = 2;\n offset = 0xE0;\n }\n // U+10000 to U+10FFFF: 3 and 0xF0\n else if (inRange(code_point, 0x10000, 0x10FFFF)) {\n count = 3;\n offset = 0xF0;\n }\n\n // 4.Let bytes be a byte sequence whose first byte is (code\n // point >> (6 × count)) + offset.\n var bytes = [(code_point >> (6 * count)) + offset];\n\n // 5. Run these substeps while count is greater than 0:\n while (count > 0) {\n\n // 1. Set temp to code point >> (6 × (count − 1)).\n var temp = code_point >> (6 * (count - 1));\n\n // 2. Append to bytes 0x80 | (temp & 0x3F).\n bytes.push(0x80 | (temp & 0x3F));\n\n // 3. Decrease count by one.\n count -= 1;\n }\n\n // 6. Return bytes bytes, in order.\n return bytes;\n };\n}\n\nexport {TextEncoder, TextDecoder};\n","/*\nCopyright 2017 Vector Creations Ltd\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n\"use strict\";\n\n// polyfill textencoder if necessary\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.encryptMegolmKeyFile = exports.decryptMegolmKeyFile = undefined;\n\nvar _promise = require('babel-runtime/core-js/promise');\n\nvar _promise2 = _interopRequireDefault(_promise);\n\nvar _regenerator = require('babel-runtime/regenerator');\n\nvar _regenerator2 = _interopRequireDefault(_regenerator);\n\nvar _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');\n\nvar _slicedToArray3 = _interopRequireDefault(_slicedToArray2);\n\nvar _bluebird = require('bluebird');\n\n/**\n * Decrypt a megolm key file\n *\n * @param {ArrayBuffer} data file to decrypt\n * @param {String} password\n * @return {Promise} promise for decrypted output\n *\n *\n */\nvar decryptMegolmKeyFile = exports.decryptMegolmKeyFile = function () {\n var _ref = (0, _bluebird.coroutine)( /*#__PURE__*/_regenerator2.default.mark(function _callee(data, password) {\n var body, version, ciphertextLength, salt, iv, iterations, ciphertext, hmac, _ref2, _ref3, aesKey, hmacKey, toVerify, isValid, plaintext;\n\n return _regenerator2.default.wrap(function _callee$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n body = unpackMegolmKeyFile(data);\n\n // check we have a version byte\n\n if (!(body.length < 1)) {\n _context.next = 3;\n break;\n }\n\n throw friendlyError('Invalid file: too short', (0, _languageHandler._t)('Not a valid Riot keyfile'));\n\n case 3:\n version = body[0];\n\n if (!(version !== 1)) {\n _context.next = 6;\n break;\n }\n\n throw friendlyError('Unsupported version', (0, _languageHandler._t)('Not a valid Riot keyfile'));\n\n case 6:\n ciphertextLength = body.length - (1 + 16 + 16 + 4 + 32);\n\n if (!(ciphertextLength < 0)) {\n _context.next = 9;\n break;\n }\n\n throw friendlyError('Invalid file: too short', (0, _languageHandler._t)('Not a valid Riot keyfile'));\n\n case 9:\n salt = body.subarray(1, 1 + 16);\n iv = body.subarray(17, 17 + 16);\n iterations = body[33] << 24 | body[34] << 16 | body[35] << 8 | body[36];\n ciphertext = body.subarray(37, 37 + ciphertextLength);\n hmac = body.subarray(-32);\n _context.next = 16;\n return (0, _bluebird.resolve)(deriveKeys(salt, iterations, password));\n\n case 16:\n _ref2 = _context.sent;\n _ref3 = (0, _slicedToArray3.default)(_ref2, 2);\n aesKey = _ref3[0];\n hmacKey = _ref3[1];\n toVerify = body.subarray(0, -32);\n isValid = void 0;\n _context.prev = 22;\n _context.next = 25;\n return (0, _bluebird.resolve)(subtleCrypto.verify({ name: 'HMAC' }, hmacKey, hmac, toVerify));\n\n case 25:\n isValid = _context.sent;\n _context.next = 31;\n break;\n\n case 28:\n _context.prev = 28;\n _context.t0 = _context['catch'](22);\n throw friendlyError('subtleCrypto.verify failed: ' + _context.t0, cryptoFailMsg());\n\n case 31:\n if (isValid) {\n _context.next = 33;\n break;\n }\n\n throw friendlyError('hmac mismatch', (0, _languageHandler._t)('Authentication check failed: incorrect password?'));\n\n case 33:\n plaintext = void 0;\n _context.prev = 34;\n _context.next = 37;\n return (0, _bluebird.resolve)(subtleCrypto.decrypt({\n name: \"AES-CTR\",\n counter: iv,\n length: 64\n }, aesKey, ciphertext));\n\n case 37:\n plaintext = _context.sent;\n _context.next = 43;\n break;\n\n case 40:\n _context.prev = 40;\n _context.t1 = _context['catch'](34);\n throw friendlyError('subtleCrypto.decrypt failed: ' + _context.t1, cryptoFailMsg());\n\n case 43:\n return _context.abrupt('return', new TextDecoder().decode(new Uint8Array(plaintext)));\n\n case 44:\n case 'end':\n return _context.stop();\n }\n }\n }, _callee, this, [[22, 28], [34, 40]]);\n }));\n\n return function decryptMegolmKeyFile(_x, _x2) {\n return _ref.apply(this, arguments);\n };\n}();\n\n/**\n * Encrypt a megolm key file\n *\n * @param {String} data\n * @param {String} password\n * @param {Object=} options\n * @param {Nunber=} options.kdf_rounds Number of iterations to perform of the\n * key-derivation function.\n * @return {Promise} promise for encrypted output\n */\n\n\nvar encryptMegolmKeyFile = exports.encryptMegolmKeyFile = function () {\n var _ref4 = (0, _bluebird.coroutine)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(data, password, options) {\n var kdfRounds, salt, iv, _ref5, _ref6, aesKey, hmacKey, encodedData, ciphertext, cipherArray, bodyLength, resultBuffer, idx, toSign, hmac, hmacArray;\n\n return _regenerator2.default.wrap(function _callee2$(_context2) {\n while (1) {\n switch (_context2.prev = _context2.next) {\n case 0:\n options = options || {};\n kdfRounds = options.kdf_rounds || 500000;\n salt = new Uint8Array(16);\n\n window.crypto.getRandomValues(salt);\n\n iv = new Uint8Array(16);\n\n window.crypto.getRandomValues(iv);\n\n // clear bit 63 of the IV to stop us hitting the 64-bit counter boundary\n // (which would mean we wouldn't be able to decrypt on Android). The loss\n // of a single bit of iv is a price we have to pay.\n iv[9] &= 0x7f;\n\n _context2.next = 9;\n return (0, _bluebird.resolve)(deriveKeys(salt, kdfRounds, password));\n\n case 9:\n _ref5 = _context2.sent;\n _ref6 = (0, _slicedToArray3.default)(_ref5, 2);\n aesKey = _ref6[0];\n hmacKey = _ref6[1];\n encodedData = new TextEncoder().encode(data);\n ciphertext = void 0;\n _context2.prev = 15;\n _context2.next = 18;\n return (0, _bluebird.resolve)(subtleCrypto.encrypt({\n name: \"AES-CTR\",\n counter: iv,\n length: 64\n }, aesKey, encodedData));\n\n case 18:\n ciphertext = _context2.sent;\n _context2.next = 24;\n break;\n\n case 21:\n _context2.prev = 21;\n _context2.t0 = _context2['catch'](15);\n throw friendlyError('subtleCrypto.encrypt failed: ' + _context2.t0, cryptoFailMsg());\n\n case 24:\n cipherArray = new Uint8Array(ciphertext);\n bodyLength = 1 + salt.length + iv.length + 4 + cipherArray.length + 32;\n resultBuffer = new Uint8Array(bodyLength);\n idx = 0;\n\n resultBuffer[idx++] = 1; // version\n resultBuffer.set(salt, idx);idx += salt.length;\n resultBuffer.set(iv, idx);idx += iv.length;\n resultBuffer[idx++] = kdfRounds >> 24;\n resultBuffer[idx++] = kdfRounds >> 16 & 0xff;\n resultBuffer[idx++] = kdfRounds >> 8 & 0xff;\n resultBuffer[idx++] = kdfRounds & 0xff;\n resultBuffer.set(cipherArray, idx);idx += cipherArray.length;\n\n toSign = resultBuffer.subarray(0, idx);\n hmac = void 0;\n _context2.prev = 41;\n _context2.next = 44;\n return (0, _bluebird.resolve)(subtleCrypto.sign({ name: 'HMAC' }, hmacKey, toSign));\n\n case 44:\n hmac = _context2.sent;\n _context2.next = 50;\n break;\n\n case 47:\n _context2.prev = 47;\n _context2.t1 = _context2['catch'](41);\n throw friendlyError('subtleCrypto.sign failed: ' + _context2.t1, cryptoFailMsg());\n\n case 50:\n hmacArray = new Uint8Array(hmac);\n\n resultBuffer.set(hmacArray, idx);\n return _context2.abrupt('return', packMegolmKeyFile(resultBuffer));\n\n case 53:\n case 'end':\n return _context2.stop();\n }\n }\n }, _callee2, this, [[15, 21], [41, 47]]);\n }));\n\n return function encryptMegolmKeyFile(_x3, _x4, _x5) {\n return _ref4.apply(this, arguments);\n };\n}();\n\n/**\n * Derive the AES and HMAC-SHA-256 keys for the file\n *\n * @param {Unit8Array} salt salt for pbkdf\n * @param {Number} iterations number of pbkdf iterations\n * @param {String} password password\n * @return {Promise<[CryptoKey, CryptoKey]>} promise for [aes key, hmac key]\n */\n\n\nvar deriveKeys = function () {\n var _ref7 = (0, _bluebird.coroutine)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(salt, iterations, password) {\n var start, key, keybits, now, aesKey, hmacKey, aesProm, hmacProm;\n return _regenerator2.default.wrap(function _callee3$(_context3) {\n while (1) {\n switch (_context3.prev = _context3.next) {\n case 0:\n start = new Date();\n key = void 0;\n _context3.prev = 2;\n _context3.next = 5;\n return (0, _bluebird.resolve)(subtleCrypto.importKey('raw', new TextEncoder().encode(password), { name: 'PBKDF2' }, false, ['deriveBits']));\n\n case 5:\n key = _context3.sent;\n _context3.next = 11;\n break;\n\n case 8:\n _context3.prev = 8;\n _context3.t0 = _context3['catch'](2);\n throw friendlyError('subtleCrypto.importKey failed: ' + _context3.t0, cryptoFailMsg());\n\n case 11:\n keybits = void 0;\n _context3.prev = 12;\n _context3.next = 15;\n return (0, _bluebird.resolve)(subtleCrypto.deriveBits({\n name: 'PBKDF2',\n salt: salt,\n iterations: iterations,\n hash: 'SHA-512'\n }, key, 512));\n\n case 15:\n keybits = _context3.sent;\n _context3.next = 21;\n break;\n\n case 18:\n _context3.prev = 18;\n _context3.t1 = _context3['catch'](12);\n throw friendlyError('subtleCrypto.deriveBits failed: ' + _context3.t1, cryptoFailMsg());\n\n case 21:\n now = new Date();\n\n console.log(\"E2e import/export: deriveKeys took \" + (now - start) + \"ms\");\n\n aesKey = keybits.slice(0, 32);\n hmacKey = keybits.slice(32);\n aesProm = subtleCrypto.importKey('raw', aesKey, { name: 'AES-CTR' }, false, ['encrypt', 'decrypt']).catch(function (e) {\n throw friendlyError('subtleCrypto.importKey failed for AES key: ' + e, cryptoFailMsg());\n });\n hmacProm = subtleCrypto.importKey('raw', hmacKey, {\n name: 'HMAC',\n hash: { name: 'SHA-256' }\n }, false, ['sign', 'verify']).catch(function (e) {\n throw friendlyError('subtleCrypto.importKey failed for HMAC key: ' + e, cryptoFailMsg());\n });\n _context3.next = 29;\n return (0, _bluebird.resolve)(_promise2.default.all([aesProm, hmacProm]));\n\n case 29:\n return _context3.abrupt('return', _context3.sent);\n\n case 30:\n case 'end':\n return _context3.stop();\n }\n }\n }, _callee3, this, [[2, 8], [12, 18]]);\n }));\n\n return function deriveKeys(_x6, _x7, _x8) {\n return _ref7.apply(this, arguments);\n };\n}();\n\nvar _textEncodingUtf = require('text-encoding-utf-8');\n\nvar TextEncodingUtf8 = _interopRequireWildcard(_textEncodingUtf);\n\nvar _languageHandler = require('../languageHandler');\n\nfunction _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nvar TextEncoder = window.TextEncoder;\nif (!TextEncoder) {\n TextEncoder = TextEncodingUtf8.TextEncoder;\n}\nvar TextDecoder = window.TextDecoder;\nif (!TextDecoder) {\n TextDecoder = TextEncodingUtf8.TextDecoder;\n}\n\nvar subtleCrypto = window.crypto.subtle || window.crypto.webkitSubtle;\n\n/**\n * Make an Error object which has a friendlyText property which is already\n * translated and suitable for showing to the user.\n *\n * @param {string} msg message for the exception\n * @param {string} friendlyText\n * @returns {Error}\n */\nfunction friendlyError(msg, friendlyText) {\n var e = new Error(msg);\n e.friendlyText = friendlyText;\n return e;\n}\n\nfunction cryptoFailMsg() {\n return (0, _languageHandler._t)('Your browser does not support the required cryptography extensions');\n}\n\nvar HEADER_LINE = '-----BEGIN MEGOLM SESSION DATA-----';\nvar TRAILER_LINE = '-----END MEGOLM SESSION DATA-----';\n\n/**\n * Unbase64 an ascii-armoured megolm key file\n *\n * Strips the header and trailer lines, and unbase64s the content\n *\n * @param {ArrayBuffer} data input file\n * @return {Uint8Array} unbase64ed content\n */\nfunction unpackMegolmKeyFile(data) {\n // parse the file as a great big String. This should be safe, because there\n // should be no non-ASCII characters, and it means that we can do string\n // comparisons to find the header and footer, and feed it into window.atob.\n var fileStr = new TextDecoder().decode(new Uint8Array(data));\n\n // look for the start line\n var lineStart = 0;\n while (1) {\n var lineEnd = fileStr.indexOf('\\n', lineStart);\n if (lineEnd < 0) {\n throw new Error('Header line not found');\n }\n var line = fileStr.slice(lineStart, lineEnd).trim();\n\n // start the next line after the newline\n lineStart = lineEnd + 1;\n\n if (line === HEADER_LINE) {\n break;\n }\n }\n\n var dataStart = lineStart;\n\n // look for the end line\n while (1) {\n var _lineEnd = fileStr.indexOf('\\n', lineStart);\n var _line = fileStr.slice(lineStart, _lineEnd < 0 ? undefined : _lineEnd).trim();\n if (_line === TRAILER_LINE) {\n break;\n }\n\n if (_lineEnd < 0) {\n throw new Error('Trailer line not found');\n }\n\n // start the next line after the newline\n lineStart = _lineEnd + 1;\n }\n\n var dataEnd = lineStart;\n return decodeBase64(fileStr.slice(dataStart, dataEnd));\n}\n\n/**\n * ascii-armour a megolm key file\n *\n * base64s the content, and adds header and trailer lines\n *\n * @param {Uint8Array} data raw data\n * @return {ArrayBuffer} formatted file\n */\nfunction packMegolmKeyFile(data) {\n // we split into lines before base64ing, because encodeBase64 doesn't deal\n // terribly well with large arrays.\n var LINE_LENGTH = 72 * 4 / 3;\n var nLines = Math.ceil(data.length / LINE_LENGTH);\n var lines = new Array(nLines + 3);\n lines[0] = HEADER_LINE;\n var o = 0;\n var i = void 0;\n for (i = 1; i <= nLines; i++) {\n lines[i] = encodeBase64(data.subarray(o, o + LINE_LENGTH));\n o += LINE_LENGTH;\n }\n lines[i++] = TRAILER_LINE;\n lines[i] = '';\n return new TextEncoder().encode(lines.join('\\n')).buffer;\n}\n\n/**\n * Encode a typed array of uint8 as base64.\n * @param {Uint8Array} uint8Array The data to encode.\n * @return {string} The base64.\n */\nfunction encodeBase64(uint8Array) {\n // Misinterpt the Uint8Array as Latin-1.\n // window.btoa expects a unicode string with codepoints in the range 0-255.\n var latin1String = String.fromCharCode.apply(null, uint8Array);\n // Use the builtin base64 encoder.\n return window.btoa(latin1String);\n}\n\n/**\n * Decode a base64 string to a typed array of uint8.\n * @param {string} base64 The base64 to decode.\n * @return {Uint8Array} The decoded data.\n */\nfunction decodeBase64(base64) {\n // window.atob returns a unicode string with codepoints in the range 0-255.\n var latin1String = window.atob(base64);\n // Encode the string as a Uint8Array\n var uint8Array = new Uint8Array(latin1String.length);\n for (var i = 0; i < latin1String.length; i++) {\n uint8Array[i] = latin1String.charCodeAt(i);\n }\n return uint8Array;\n}\n//# sourceMappingURL=MegolmExportEncryption.js.map"],"sourceRoot":""}