{"version":3,"file":"otpauth.cjs.min.js","sources":["src/utils.js","sjcl/sjcl.js","src/crypto.js","src/secret.js","src/otp.js","src/uri.js","src/version.js"],"sourcesContent":["/**\n * An object containing some utilities.\n * @type {Object}\n */\nexport const Utils = {\n\n\t/**\n\t * UInt conversion.\n\t * @type {Object}\n\t */\n\tuint: {\n\n\t\t/**\n\t\t * Converts an ArrayBuffer to an integer.\n\t\t * @param {ArrayBuffer} buf ArrayBuffer.\n\t\t * @returns {number} Integer.\n\t\t */\n\t\tfromBuf: buf => {\n\t\t\tconst arr = new Uint8Array(buf);\n\t\t\tlet num = 0;\n\n\t\t\tfor (let i = 0; i < arr.length; i++) {\n\t\t\t\tif (arr[i] !== 0) {\n\t\t\t\t\tnum *= 256;\n\t\t\t\t\tnum += arr[i];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn num;\n\t\t},\n\n\t\t/**\n\t\t * Converts an integer to an ArrayBuffer.\n\t\t * @param {number} num Integer.\n\t\t * @returns {ArrayBuffer} ArrayBuffer.\n\t\t */\n\t\ttoBuf: num => {\n\t\t\tconst buf = new ArrayBuffer(8);\n\t\t\tconst arr = new Uint8Array(buf);\n\t\t\tlet acc = num;\n\n\t\t\tfor (let i = 7; i >= 0; i--) {\n\t\t\t\tif (acc === 0) break;\n\n\t\t\t\tarr[i] = acc & 255;\n\t\t\t\tacc -= arr[i];\n\t\t\t\tacc /= 256;\n\t\t\t}\n\n\t\t\treturn buf;\n\t\t}\n\n\t},\n\n\t/**\n\t * Raw string conversion.\n\t * @type {Object}\n\t */\n\traw: {\n\n\t\t/**\n\t\t * Converts an ArrayBuffer to a string.\n\t\t * @param {ArrayBuffer} buf ArrayBuffer.\n\t\t * @returns {string} String.\n\t\t */\n\t\tfromBuf: buf => {\n\t\t\tconst arr = new Uint8Array(buf);\n\t\t\tlet str = '';\n\n\t\t\tfor (let i = 0; i < arr.length; i++) {\n\t\t\t\tstr += String.fromCharCode(arr[i]);\n\t\t\t}\n\n\t\t\treturn str;\n\t\t},\n\n\t\t/**\n\t\t * Converts a string to an ArrayBuffer.\n\t\t * @param {string} str String.\n\t\t * @returns {ArrayBuffer} ArrayBuffer.\n\t\t */\n\t\ttoBuf: str => {\n\t\t\tconst buf = new ArrayBuffer(str.length);\n\t\t\tconst arr = new Uint8Array(buf);\n\n\t\t\tfor (let i = 0; i < str.length; i++) {\n\t\t\t\tarr[i] = str.charCodeAt(i);\n\t\t\t}\n\n\t\t\treturn buf;\n\t\t}\n\n\t},\n\n\t/**\n\t * Base32 string conversion.\n\t * @type {Object}\n\t */\n\tb32: {\n\n\t\t/**\n\t\t * RFC 4648 base32 alphabet without pad.\n\t\t * @type {string}\n\t\t */\n\t\talphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',\n\n\t\t/**\n\t\t * Converts an ArrayBuffer to a base32 string (RFC 4648)\n\t\t * (https://github.com/LinusU/base32-encode).\n\t\t * @param {ArrayBuffer} buf ArrayBuffer.\n\t\t * @returns {string} Base32 string.\n\t\t */\n\t\tfromBuf: buf => {\n\t\t\tconst arr = new Uint8Array(buf);\n\n\t\t\tlet bits = 0;\n\t\t\tlet value = 0;\n\t\t\tlet str = '';\n\n\t\t\tfor (let i = 0; i < arr.length; i++) {\n\t\t\t\tvalue = (value << 8) | arr[i];\n\t\t\t\tbits += 8;\n\n\t\t\t\twhile (bits >= 5) {\n\t\t\t\t\tstr += Utils.b32.alphabet[(value >>> bits - 5) & 31];\n\t\t\t\t\tbits -= 5;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (bits > 0) {\n\t\t\t\tstr += Utils.b32.alphabet[(value << 5 - bits) & 31];\n\t\t\t}\n\n\t\t\treturn str;\n\t\t},\n\n\t\t/**\n\t\t * Converts a base32 string to an ArrayBuffer (RFC 4648)\n\t\t * (https://github.com/LinusU/base32-decode).\n\t\t * @param {string} str Base32 string.\n\t\t * @returns {ArrayBuffer} ArrayBuffer.\n\t\t */\n\t\ttoBuf: str => {\n\t\t\t// Canonicalize to all upper case and remove padding if it exists.\n\t\t\tstr = str.toUpperCase().replace(/=+$/, '');\n\n\t\t\tconst buf = new ArrayBuffer((str.length * 5) / 8 | 0);\n\t\t\tconst arr = new Uint8Array(buf);\n\n\t\t\tlet bits = 0;\n\t\t\tlet value = 0;\n\t\t\tlet index = 0;\n\n\t\t\tfor (let i = 0; i < str.length; i++) {\n\t\t\t\tconst idx = Utils.b32.alphabet.indexOf(str[i]);\n\t\t\t\tif (idx === -1) throw new TypeError(`Invalid character found: ${str[i]}`);\n\n\t\t\t\tvalue = (value << 5) | idx;\n\t\t\t\tbits += 5;\n\n\t\t\t\tif (bits >= 8) {\n\t\t\t\t\tarr[index++] = (value >>> bits - 8) & 255;\n\t\t\t\t\tbits -= 8;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn buf;\n\t\t}\n\n\t},\n\n\t/**\n\t * Hexadecimal string conversion.\n\t * @type {Object}\n\t */\n\thex: {\n\n\t\t/**\n\t\t * Converts an ArrayBuffer to a hexadecimal string.\n\t\t * @param {ArrayBuffer} buf ArrayBuffer.\n\t\t * @returns {string} Hexadecimal string.\n\t\t */\n\t\tfromBuf: buf => {\n\t\t\tconst arr = new Uint8Array(buf);\n\t\t\tlet str = '';\n\n\t\t\tfor (let i = 0; i < arr.length; i++) {\n\t\t\t\tconst hex = arr[i].toString(16);\n\t\t\t\tstr += hex.length === 2 ? hex : `0${hex}`;\n\t\t\t}\n\n\t\t\treturn str.toUpperCase();\n\t\t},\n\n\t\t/**\n\t\t * Converts a hexadecimal string to an ArrayBuffer.\n\t\t * @param {string} str Hexadecimal string.\n\t\t * @returns {ArrayBuffer} ArrayBuffer.\n\t\t */\n\t\ttoBuf: str => {\n\t\t\tconst buf = new ArrayBuffer(str.length / 2);\n\t\t\tconst arr = new Uint8Array(buf);\n\n\t\t\tfor (let i = 0, j = 0; i < arr.length; i += 1, j += 2) {\n\t\t\t\tarr[i] = parseInt(str.substr(j, 2), 16);\n\t\t\t}\n\n\t\t\treturn buf;\n\t\t}\n\n\t},\n\n\t/**\n\t * Pads a number with leading zeros.\n\t * @param {number|string} num Number.\n\t * @param {number} digits Digits.\n\t * @returns {string} Padded number.\n\t */\n\tpad: (num, digits) => {\n\t\tlet prefix = '';\n\t\tlet repeat = digits - String(num).length;\n\t\twhile (repeat-- > 0) prefix += '0';\n\t\treturn `${prefix}${num}`;\n\t}\n\n};\n\n/**\n * An object containing some utilities (for internal use only).\n * @private\n * @type {Object}\n */\nexport const InternalUtils = {\n\n\t/**\n\t * \"globalThis\" ponyfill\n\t * (https://mathiasbynens.be/notes/globalthis).\n\t * @type {Object}\n\t */\n\tget globalThis() {\n\t\tlet _globalThis;\n\n\t\t/* eslint-disable no-extend-native, no-restricted-globals, no-undef */\n\t\tif (typeof globalThis === 'object') {\n\t\t\t_globalThis = globalThis;\n\t\t} else {\n\t\t\tObject.defineProperty(Object.prototype, '__magicalGlobalThis__', {\n\t\t\t\tget() { return this; },\n\t\t\t\tconfigurable: true\n\t\t\t});\n\t\t\ttry {\n\t\t\t\t_globalThis = __magicalGlobalThis__;\n\t\t\t} finally {\n\t\t\t\tdelete Object.prototype.__magicalGlobalThis__;\n\t\t\t}\n\t\t}\n\n\t\tif (typeof _globalThis === 'undefined') {\n\t\t\t// Still unable to determine \"globalThis\", fall back to a naive method.\n\t\t\tif (typeof self !== 'undefined') {\n\t\t\t\t_globalThis = self;\n\t\t\t} else if (typeof window !== 'undefined') {\n\t\t\t\t_globalThis = window;\n\t\t\t} else if (typeof global !== 'undefined') {\n\t\t\t\t_globalThis = global;\n\t\t\t}\n\t\t}\n\t\t/* eslint-enable */\n\n\t\tObject.defineProperty(this, 'globalThis', {\n\t\t\tenumerable: true,\n\t\t\tvalue: _globalThis\n\t\t});\n\n\t\treturn this.globalThis;\n\t},\n\n\t/**\n\t * \"console\" ponyfill.\n\t * @type {Object}\n\t */\n\tget console() {\n\t\tconst _console = {};\n\n\t\tconst methods = [\n\t\t\t'assert', 'clear', 'context', 'count', 'countReset', 'debug', 'dir', 'dirxml',\n\t\t\t'error', 'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'profile',\n\t\t\t'profileEnd', 'table', 'time', 'timeEnd', 'timeLog', 'timeStamp', 'trace', 'warn'\n\t\t];\n\n\t\tif (typeof InternalUtils.globalThis.console === 'object') {\n\t\t\tfor (const method of methods) {\n\t\t\t\t_console[method] = typeof InternalUtils.globalThis.console[method] === 'function'\n\t\t\t\t\t? InternalUtils.globalThis.console[method]\n\t\t\t\t\t: () => {};\n\t\t\t}\n\t\t} else {\n\t\t\tfor (const method of methods) {\n\t\t\t\t_console[method] = () => {};\n\t\t\t}\n\t\t}\n\n\t\tObject.defineProperty(this, 'console', {\n\t\t\tenumerable: true,\n\t\t\tvalue: _console\n\t\t});\n\n\t\treturn this.console;\n\t},\n\n\t/**\n\t * Detect if running in \"Node.js\".\n\t * @type {boolean}\n\t */\n\tget isNode() {\n\t\tconst _isNode = Object.prototype.toString.call(InternalUtils.globalThis.process) === '[object process]';\n\n\t\tObject.defineProperty(this, 'isNode', {\n\t\t\tenumerable: true,\n\t\t\tvalue: _isNode\n\t\t});\n\n\t\treturn this.isNode;\n\t},\n\n\t/**\n\t * Dynamically import \"Node.js\" modules.\n\t * (`eval` is used to prevent bundlers from including the module,\n\t * e.g., [webpack/webpack#8826](https://github.com/webpack/webpack/issues/8826))\n\t * @type {Function}\n\t */\n\tget nodeRequire() {\n\t\tconst _nodeRequire = InternalUtils.isNode\n\t\t\t// eslint-disable-next-line no-eval\n\t\t\t? eval('require')\n\t\t\t: () => {};\n\n\t\tObject.defineProperty(this, 'nodeRequire', {\n\t\t\tenumerable: true,\n\t\t\tvalue: _nodeRequire\n\t\t});\n\n\t\treturn this.nodeRequire;\n\t}\n\n};\n","/** @fileOverview Javascript cryptography implementation.\n *\n * Crush to remove comments, shorten variable names and\n * generally reduce transmission size.\n *\n * @author Emily Stark\n * @author Mike Hamburg\n * @author Dan Boneh\n */\n\n\"use strict\";\n/*jslint indent: 2, bitwise: false, nomen: false, plusplus: false, white: false, regexp: false */\n/*global document, window, escape, unescape, module, require, Uint32Array */\n\n/**\n * The Stanford Javascript Crypto Library, top-level namespace.\n * @namespace\n */\nvar sjcl = {\n /**\n * Symmetric ciphers.\n * @namespace\n */\n cipher: {},\n\n /**\n * Hash functions. Right now only SHA256 is implemented.\n * @namespace\n */\n hash: {},\n\n /**\n * Key exchange functions. Right now only SRP is implemented.\n * @namespace\n */\n keyexchange: {},\n \n /**\n * Cipher modes of operation.\n * @namespace\n */\n mode: {},\n\n /**\n * Miscellaneous. HMAC and PBKDF2.\n * @namespace\n */\n misc: {},\n \n /**\n * Bit array encoders and decoders.\n * @namespace\n *\n * @description\n * The members of this namespace are functions which translate between\n * SJCL's bitArrays and other objects (usually strings). Because it\n * isn't always clear which direction is encoding and which is decoding,\n * the method names are \"fromBits\" and \"toBits\".\n */\n codec: {},\n \n /**\n * Exceptions.\n * @namespace\n */\n exception: {\n /**\n * Ciphertext is corrupt.\n * @constructor\n */\n corrupt: function(message) {\n this.toString = function() { return \"CORRUPT: \"+this.message; };\n this.message = message;\n },\n \n /**\n * Invalid parameter.\n * @constructor\n */\n invalid: function(message) {\n this.toString = function() { return \"INVALID: \"+this.message; };\n this.message = message;\n },\n \n /**\n * Bug or missing feature in SJCL.\n * @constructor\n */\n bug: function(message) {\n this.toString = function() { return \"BUG: \"+this.message; };\n this.message = message;\n },\n\n /**\n * Something isn't ready.\n * @constructor\n */\n notReady: function(message) {\n this.toString = function() { return \"NOT READY: \"+this.message; };\n this.message = message;\n }\n }\n};\n/** @fileOverview Arrays of bits, encoded as arrays of Numbers.\n *\n * @author Emily Stark\n * @author Mike Hamburg\n * @author Dan Boneh\n */\n\n/**\n * Arrays of bits, encoded as arrays of Numbers.\n * @namespace\n * @description\n *
\n * These objects are the currency accepted by SJCL's crypto functions.\n *
\n *\n *\n * Most of our crypto primitives operate on arrays of 4-byte words internally,\n * but many of them can take arguments that are not a multiple of 4 bytes.\n * This library encodes arrays of bits (whose size need not be a multiple of 8\n * bits) as arrays of 32-bit words. The bits are packed, big-endian, into an\n * array of words, 32 bits at a time. Since the words are double-precision\n * floating point numbers, they fit some extra data. We use this (in a private,\n * possibly-changing manner) to encode the number of bits actually present\n * in the last word of the array.\n *
\n *\n *\n * Because bitwise ops clear this out-of-band data, these arrays can be passed\n * to ciphers like AES which want arrays of words.\n *
\n */\nsjcl.bitArray = {\n /**\n * Array slices in units of bits.\n * @param {bitArray} a The array to slice.\n * @param {Number} bstart The offset to the start of the slice, in bits.\n * @param {Number} bend The offset to the end of the slice, in bits. If this is undefined,\n * slice until the end of the array.\n * @return {bitArray} The requested slice.\n */\n bitSlice: function (a, bstart, bend) {\n a = sjcl.bitArray._shiftRight(a.slice(bstart/32), 32 - (bstart & 31)).slice(1);\n return (bend === undefined) ? a : sjcl.bitArray.clamp(a, bend-bstart);\n },\n\n /**\n * Extract a number packed into a bit array.\n * @param {bitArray} a The array to slice.\n * @param {Number} bstart The offset to the start of the slice, in bits.\n * @param {Number} blength The length of the number to extract.\n * @return {Number} The requested slice.\n */\n extract: function(a, bstart, blength) {\n // FIXME: this Math.floor is not necessary at all, but for some reason\n // seems to suppress a bug in the Chromium JIT.\n var x, sh = Math.floor((-bstart-blength) & 31);\n if ((bstart + blength - 1 ^ bstart) & -32) {\n // it crosses a boundary\n x = (a[bstart/32|0] << (32 - sh)) ^ (a[bstart/32+1|0] >>> sh);\n } else {\n // within a single word\n x = a[bstart/32|0] >>> sh;\n }\n return x & ((1<