UNPKG

rollup-plugin-node-polyfills

Version:
2,032 lines (1,664 loc) 430 kB
import buffer$1 from 'buffer'; import stream from 'stream'; import string_decoder from 'string_decoder'; import crypto$1 from 'crypto'; import vm from 'vm'; var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; function createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } function getCjsExportFromNamespace (n) { return n && n['default'] || n; } var safeBuffer = createCommonjsModule(function (module, exports) { /* eslint-disable node/no-deprecated-api */ var Buffer = buffer$1.Buffer; // alternative to using Object.keys for old browsers function copyProps (src, dst) { for (var key in src) { dst[key] = src[key]; } } if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { module.exports = buffer$1; } else { // Copy properties from require('buffer') copyProps(buffer$1, exports); exports.Buffer = SafeBuffer; } function SafeBuffer (arg, encodingOrOffset, length) { return Buffer(arg, encodingOrOffset, length) } // Copy static methods from Buffer copyProps(Buffer, SafeBuffer); SafeBuffer.from = function (arg, encodingOrOffset, length) { if (typeof arg === 'number') { throw new TypeError('Argument must not be a number') } return Buffer(arg, encodingOrOffset, length) }; SafeBuffer.alloc = function (size, fill, encoding) { if (typeof size !== 'number') { throw new TypeError('Argument must be a number') } var buf = Buffer(size); if (fill !== undefined) { if (typeof encoding === 'string') { buf.fill(fill, encoding); } else { buf.fill(fill); } } else { buf.fill(0); } return buf }; SafeBuffer.allocUnsafe = function (size) { if (typeof size !== 'number') { throw new TypeError('Argument must be a number') } return Buffer(size) }; SafeBuffer.allocUnsafeSlow = function (size) { if (typeof size !== 'number') { throw new TypeError('Argument must be a number') } return buffer$1.SlowBuffer(size) }; }); var safeBuffer_1 = safeBuffer.Buffer; var browser = createCommonjsModule(function (module) { // limit of Crypto.getRandomValues() // https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues var MAX_BYTES = 65536; // Node supports requesting up to this number of bytes // https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js#L48 var MAX_UINT32 = 4294967295; function oldBrowser () { throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11') } var Buffer = safeBuffer.Buffer; var crypto = commonjsGlobal.crypto || commonjsGlobal.msCrypto; if (crypto && crypto.getRandomValues) { module.exports = randomBytes; } else { module.exports = oldBrowser; } function randomBytes (size, cb) { // phantomjs needs to throw if (size > MAX_UINT32) throw new RangeError('requested too many random bytes') var bytes = Buffer.allocUnsafe(size); if (size > 0) { // getRandomValues fails on IE if size == 0 if (size > MAX_BYTES) { // this is the max bytes crypto.getRandomValues // can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues for (var generated = 0; generated < size; generated += MAX_BYTES) { // buffer.slice automatically checks if the end is past the end of // the buffer so we don't have to here crypto.getRandomValues(bytes.slice(generated, generated + MAX_BYTES)); } } else { crypto.getRandomValues(bytes); } } if (typeof cb === 'function') { return process.nextTick(function () { cb(null, bytes); }) } return bytes } }); var inherits_browser = createCommonjsModule(function (module) { if (typeof Object.create === 'function') { // implementation from standard node.js 'util' module module.exports = function inherits(ctor, superCtor) { ctor.super_ = superCtor; ctor.prototype = Object.create(superCtor.prototype, { constructor: { value: ctor, enumerable: false, writable: true, configurable: true } }); }; } else { // old school shim for old browsers module.exports = function inherits(ctor, superCtor) { ctor.super_ = superCtor; var TempCtor = function () {}; TempCtor.prototype = superCtor.prototype; ctor.prototype = new TempCtor(); ctor.prototype.constructor = ctor; }; } }); var Buffer$1 = safeBuffer.Buffer; var Transform = stream.Transform; function throwIfNotStringOrBuffer (val, prefix) { if (!Buffer$1.isBuffer(val) && typeof val !== 'string') { throw new TypeError(prefix + ' must be a string or a buffer') } } function HashBase (blockSize) { Transform.call(this); this._block = Buffer$1.allocUnsafe(blockSize); this._blockSize = blockSize; this._blockOffset = 0; this._length = [0, 0, 0, 0]; this._finalized = false; } inherits_browser(HashBase, Transform); HashBase.prototype._transform = function (chunk, encoding, callback) { var error = null; try { this.update(chunk, encoding); } catch (err) { error = err; } callback(error); }; HashBase.prototype._flush = function (callback) { var error = null; try { this.push(this.digest()); } catch (err) { error = err; } callback(error); }; HashBase.prototype.update = function (data, encoding) { throwIfNotStringOrBuffer(data, 'Data'); if (this._finalized) throw new Error('Digest already called') if (!Buffer$1.isBuffer(data)) data = Buffer$1.from(data, encoding); // consume data var block = this._block; var offset = 0; while (this._blockOffset + data.length - offset >= this._blockSize) { for (var i = this._blockOffset; i < this._blockSize;) block[i++] = data[offset++]; this._update(); this._blockOffset = 0; } while (offset < data.length) block[this._blockOffset++] = data[offset++]; // update length for (var j = 0, carry = data.length * 8; carry > 0; ++j) { this._length[j] += carry; carry = (this._length[j] / 0x0100000000) | 0; if (carry > 0) this._length[j] -= 0x0100000000 * carry; } return this }; HashBase.prototype._update = function () { throw new Error('_update is not implemented') }; HashBase.prototype.digest = function (encoding) { if (this._finalized) throw new Error('Digest already called') this._finalized = true; var digest = this._digest(); if (encoding !== undefined) digest = digest.toString(encoding); // reset state this._block.fill(0); this._blockOffset = 0; for (var i = 0; i < 4; ++i) this._length[i] = 0; return digest }; HashBase.prototype._digest = function () { throw new Error('_digest is not implemented') }; var hashBase = HashBase; var Buffer$2 = safeBuffer.Buffer; var ARRAY16 = new Array(16); function MD5 () { hashBase.call(this, 64); // state this._a = 0x67452301; this._b = 0xefcdab89; this._c = 0x98badcfe; this._d = 0x10325476; } inherits_browser(MD5, hashBase); MD5.prototype._update = function () { var M = ARRAY16; for (var i = 0; i < 16; ++i) M[i] = this._block.readInt32LE(i * 4); var a = this._a; var b = this._b; var c = this._c; var d = this._d; a = fnF(a, b, c, d, M[0], 0xd76aa478, 7); d = fnF(d, a, b, c, M[1], 0xe8c7b756, 12); c = fnF(c, d, a, b, M[2], 0x242070db, 17); b = fnF(b, c, d, a, M[3], 0xc1bdceee, 22); a = fnF(a, b, c, d, M[4], 0xf57c0faf, 7); d = fnF(d, a, b, c, M[5], 0x4787c62a, 12); c = fnF(c, d, a, b, M[6], 0xa8304613, 17); b = fnF(b, c, d, a, M[7], 0xfd469501, 22); a = fnF(a, b, c, d, M[8], 0x698098d8, 7); d = fnF(d, a, b, c, M[9], 0x8b44f7af, 12); c = fnF(c, d, a, b, M[10], 0xffff5bb1, 17); b = fnF(b, c, d, a, M[11], 0x895cd7be, 22); a = fnF(a, b, c, d, M[12], 0x6b901122, 7); d = fnF(d, a, b, c, M[13], 0xfd987193, 12); c = fnF(c, d, a, b, M[14], 0xa679438e, 17); b = fnF(b, c, d, a, M[15], 0x49b40821, 22); a = fnG(a, b, c, d, M[1], 0xf61e2562, 5); d = fnG(d, a, b, c, M[6], 0xc040b340, 9); c = fnG(c, d, a, b, M[11], 0x265e5a51, 14); b = fnG(b, c, d, a, M[0], 0xe9b6c7aa, 20); a = fnG(a, b, c, d, M[5], 0xd62f105d, 5); d = fnG(d, a, b, c, M[10], 0x02441453, 9); c = fnG(c, d, a, b, M[15], 0xd8a1e681, 14); b = fnG(b, c, d, a, M[4], 0xe7d3fbc8, 20); a = fnG(a, b, c, d, M[9], 0x21e1cde6, 5); d = fnG(d, a, b, c, M[14], 0xc33707d6, 9); c = fnG(c, d, a, b, M[3], 0xf4d50d87, 14); b = fnG(b, c, d, a, M[8], 0x455a14ed, 20); a = fnG(a, b, c, d, M[13], 0xa9e3e905, 5); d = fnG(d, a, b, c, M[2], 0xfcefa3f8, 9); c = fnG(c, d, a, b, M[7], 0x676f02d9, 14); b = fnG(b, c, d, a, M[12], 0x8d2a4c8a, 20); a = fnH(a, b, c, d, M[5], 0xfffa3942, 4); d = fnH(d, a, b, c, M[8], 0x8771f681, 11); c = fnH(c, d, a, b, M[11], 0x6d9d6122, 16); b = fnH(b, c, d, a, M[14], 0xfde5380c, 23); a = fnH(a, b, c, d, M[1], 0xa4beea44, 4); d = fnH(d, a, b, c, M[4], 0x4bdecfa9, 11); c = fnH(c, d, a, b, M[7], 0xf6bb4b60, 16); b = fnH(b, c, d, a, M[10], 0xbebfbc70, 23); a = fnH(a, b, c, d, M[13], 0x289b7ec6, 4); d = fnH(d, a, b, c, M[0], 0xeaa127fa, 11); c = fnH(c, d, a, b, M[3], 0xd4ef3085, 16); b = fnH(b, c, d, a, M[6], 0x04881d05, 23); a = fnH(a, b, c, d, M[9], 0xd9d4d039, 4); d = fnH(d, a, b, c, M[12], 0xe6db99e5, 11); c = fnH(c, d, a, b, M[15], 0x1fa27cf8, 16); b = fnH(b, c, d, a, M[2], 0xc4ac5665, 23); a = fnI(a, b, c, d, M[0], 0xf4292244, 6); d = fnI(d, a, b, c, M[7], 0x432aff97, 10); c = fnI(c, d, a, b, M[14], 0xab9423a7, 15); b = fnI(b, c, d, a, M[5], 0xfc93a039, 21); a = fnI(a, b, c, d, M[12], 0x655b59c3, 6); d = fnI(d, a, b, c, M[3], 0x8f0ccc92, 10); c = fnI(c, d, a, b, M[10], 0xffeff47d, 15); b = fnI(b, c, d, a, M[1], 0x85845dd1, 21); a = fnI(a, b, c, d, M[8], 0x6fa87e4f, 6); d = fnI(d, a, b, c, M[15], 0xfe2ce6e0, 10); c = fnI(c, d, a, b, M[6], 0xa3014314, 15); b = fnI(b, c, d, a, M[13], 0x4e0811a1, 21); a = fnI(a, b, c, d, M[4], 0xf7537e82, 6); d = fnI(d, a, b, c, M[11], 0xbd3af235, 10); c = fnI(c, d, a, b, M[2], 0x2ad7d2bb, 15); b = fnI(b, c, d, a, M[9], 0xeb86d391, 21); this._a = (this._a + a) | 0; this._b = (this._b + b) | 0; this._c = (this._c + c) | 0; this._d = (this._d + d) | 0; }; MD5.prototype._digest = function () { // create padding and handle blocks this._block[this._blockOffset++] = 0x80; if (this._blockOffset > 56) { this._block.fill(0, this._blockOffset, 64); this._update(); this._blockOffset = 0; } this._block.fill(0, this._blockOffset, 56); this._block.writeUInt32LE(this._length[0], 56); this._block.writeUInt32LE(this._length[1], 60); this._update(); // produce result var buffer = Buffer$2.allocUnsafe(16); buffer.writeInt32LE(this._a, 0); buffer.writeInt32LE(this._b, 4); buffer.writeInt32LE(this._c, 8); buffer.writeInt32LE(this._d, 12); return buffer }; function rotl (x, n) { return (x << n) | (x >>> (32 - n)) } function fnF (a, b, c, d, m, k, s) { return (rotl((a + ((b & c) | ((~b) & d)) + m + k) | 0, s) + b) | 0 } function fnG (a, b, c, d, m, k, s) { return (rotl((a + ((b & d) | (c & (~d))) + m + k) | 0, s) + b) | 0 } function fnH (a, b, c, d, m, k, s) { return (rotl((a + (b ^ c ^ d) + m + k) | 0, s) + b) | 0 } function fnI (a, b, c, d, m, k, s) { return (rotl((a + ((c ^ (b | (~d)))) + m + k) | 0, s) + b) | 0 } var md5_js = MD5; var Buffer$3 = buffer$1.Buffer; var ARRAY16$1 = new Array(16); var zl = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 ]; var zr = [ 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 ]; var sl = [ 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]; var sr = [ 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]; var hl = [0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e]; var hr = [0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000]; function RIPEMD160 () { hashBase.call(this, 64); // state this._a = 0x67452301; this._b = 0xefcdab89; this._c = 0x98badcfe; this._d = 0x10325476; this._e = 0xc3d2e1f0; } inherits_browser(RIPEMD160, hashBase); RIPEMD160.prototype._update = function () { var words = ARRAY16$1; for (var j = 0; j < 16; ++j) words[j] = this._block.readInt32LE(j * 4); var al = this._a | 0; var bl = this._b | 0; var cl = this._c | 0; var dl = this._d | 0; var el = this._e | 0; var ar = this._a | 0; var br = this._b | 0; var cr = this._c | 0; var dr = this._d | 0; var er = this._e | 0; // computation for (var i = 0; i < 80; i += 1) { var tl; var tr; if (i < 16) { tl = fn1(al, bl, cl, dl, el, words[zl[i]], hl[0], sl[i]); tr = fn5(ar, br, cr, dr, er, words[zr[i]], hr[0], sr[i]); } else if (i < 32) { tl = fn2(al, bl, cl, dl, el, words[zl[i]], hl[1], sl[i]); tr = fn4(ar, br, cr, dr, er, words[zr[i]], hr[1], sr[i]); } else if (i < 48) { tl = fn3(al, bl, cl, dl, el, words[zl[i]], hl[2], sl[i]); tr = fn3(ar, br, cr, dr, er, words[zr[i]], hr[2], sr[i]); } else if (i < 64) { tl = fn4(al, bl, cl, dl, el, words[zl[i]], hl[3], sl[i]); tr = fn2(ar, br, cr, dr, er, words[zr[i]], hr[3], sr[i]); } else { // if (i<80) { tl = fn5(al, bl, cl, dl, el, words[zl[i]], hl[4], sl[i]); tr = fn1(ar, br, cr, dr, er, words[zr[i]], hr[4], sr[i]); } al = el; el = dl; dl = rotl$1(cl, 10); cl = bl; bl = tl; ar = er; er = dr; dr = rotl$1(cr, 10); cr = br; br = tr; } // update state var t = (this._b + cl + dr) | 0; this._b = (this._c + dl + er) | 0; this._c = (this._d + el + ar) | 0; this._d = (this._e + al + br) | 0; this._e = (this._a + bl + cr) | 0; this._a = t; }; RIPEMD160.prototype._digest = function () { // create padding and handle blocks this._block[this._blockOffset++] = 0x80; if (this._blockOffset > 56) { this._block.fill(0, this._blockOffset, 64); this._update(); this._blockOffset = 0; } this._block.fill(0, this._blockOffset, 56); this._block.writeUInt32LE(this._length[0], 56); this._block.writeUInt32LE(this._length[1], 60); this._update(); // produce result var buffer = Buffer$3.alloc ? Buffer$3.alloc(20) : new Buffer$3(20); buffer.writeInt32LE(this._a, 0); buffer.writeInt32LE(this._b, 4); buffer.writeInt32LE(this._c, 8); buffer.writeInt32LE(this._d, 12); buffer.writeInt32LE(this._e, 16); return buffer }; function rotl$1 (x, n) { return (x << n) | (x >>> (32 - n)) } function fn1 (a, b, c, d, e, m, k, s) { return (rotl$1((a + (b ^ c ^ d) + m + k) | 0, s) + e) | 0 } function fn2 (a, b, c, d, e, m, k, s) { return (rotl$1((a + ((b & c) | ((~b) & d)) + m + k) | 0, s) + e) | 0 } function fn3 (a, b, c, d, e, m, k, s) { return (rotl$1((a + ((b | (~c)) ^ d) + m + k) | 0, s) + e) | 0 } function fn4 (a, b, c, d, e, m, k, s) { return (rotl$1((a + ((b & d) | (c & (~d))) + m + k) | 0, s) + e) | 0 } function fn5 (a, b, c, d, e, m, k, s) { return (rotl$1((a + (b ^ (c | (~d))) + m + k) | 0, s) + e) | 0 } var ripemd160 = RIPEMD160; var Buffer$4 = safeBuffer.Buffer; // prototype class for hash functions function Hash (blockSize, finalSize) { this._block = Buffer$4.alloc(blockSize); this._finalSize = finalSize; this._blockSize = blockSize; this._len = 0; } Hash.prototype.update = function (data, enc) { if (typeof data === 'string') { enc = enc || 'utf8'; data = Buffer$4.from(data, enc); } var block = this._block; var blockSize = this._blockSize; var length = data.length; var accum = this._len; for (var offset = 0; offset < length;) { var assigned = accum % blockSize; var remainder = Math.min(length - offset, blockSize - assigned); for (var i = 0; i < remainder; i++) { block[assigned + i] = data[offset + i]; } accum += remainder; offset += remainder; if ((accum % blockSize) === 0) { this._update(block); } } this._len += length; return this }; Hash.prototype.digest = function (enc) { var rem = this._len % this._blockSize; this._block[rem] = 0x80; // zero (rem + 1) trailing bits, where (rem + 1) is the smallest // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize this._block.fill(0, rem + 1); if (rem >= this._finalSize) { this._update(this._block); this._block.fill(0); } var bits = this._len * 8; // uint32 if (bits <= 0xffffffff) { this._block.writeUInt32BE(bits, this._blockSize - 4); // uint64 } else { var lowBits = (bits & 0xffffffff) >>> 0; var highBits = (bits - lowBits) / 0x100000000; this._block.writeUInt32BE(highBits, this._blockSize - 8); this._block.writeUInt32BE(lowBits, this._blockSize - 4); } this._update(this._block); var hash = this._hash(); return enc ? hash.toString(enc) : hash }; Hash.prototype._update = function () { throw new Error('_update must be implemented by subclass') }; var hash = Hash; /* * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined * in FIPS PUB 180-1 * This source code is derived from sha1.js of the same repository. * The difference between SHA-0 and SHA-1 is just a bitwise rotate left * operation was added. */ var Buffer$5 = safeBuffer.Buffer; var K = [ 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0 ]; var W = new Array(80); function Sha () { this.init(); this._w = W; hash.call(this, 64, 56); } inherits_browser(Sha, hash); Sha.prototype.init = function () { this._a = 0x67452301; this._b = 0xefcdab89; this._c = 0x98badcfe; this._d = 0x10325476; this._e = 0xc3d2e1f0; return this }; function rotl5 (num) { return (num << 5) | (num >>> 27) } function rotl30 (num) { return (num << 30) | (num >>> 2) } function ft (s, b, c, d) { if (s === 0) return (b & c) | ((~b) & d) if (s === 2) return (b & c) | (b & d) | (c & d) return b ^ c ^ d } Sha.prototype._update = function (M) { var W = this._w; var a = this._a | 0; var b = this._b | 0; var c = this._c | 0; var d = this._d | 0; var e = this._e | 0; for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4); for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; for (var j = 0; j < 80; ++j) { var s = ~~(j / 20); var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0; e = d; d = c; c = rotl30(b); b = a; a = t; } this._a = (a + this._a) | 0; this._b = (b + this._b) | 0; this._c = (c + this._c) | 0; this._d = (d + this._d) | 0; this._e = (e + this._e) | 0; }; Sha.prototype._hash = function () { var H = Buffer$5.allocUnsafe(20); H.writeInt32BE(this._a | 0, 0); H.writeInt32BE(this._b | 0, 4); H.writeInt32BE(this._c | 0, 8); H.writeInt32BE(this._d | 0, 12); H.writeInt32BE(this._e | 0, 16); return H }; var sha = Sha; /* * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined * in FIPS PUB 180-1 * Version 2.1a Copyright Paul Johnston 2000 - 2002. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet * Distributed under the BSD License * See http://pajhome.org.uk/crypt/md5 for details. */ var Buffer$6 = safeBuffer.Buffer; var K$1 = [ 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0 ]; var W$1 = new Array(80); function Sha1 () { this.init(); this._w = W$1; hash.call(this, 64, 56); } inherits_browser(Sha1, hash); Sha1.prototype.init = function () { this._a = 0x67452301; this._b = 0xefcdab89; this._c = 0x98badcfe; this._d = 0x10325476; this._e = 0xc3d2e1f0; return this }; function rotl1 (num) { return (num << 1) | (num >>> 31) } function rotl5$1 (num) { return (num << 5) | (num >>> 27) } function rotl30$1 (num) { return (num << 30) | (num >>> 2) } function ft$1 (s, b, c, d) { if (s === 0) return (b & c) | ((~b) & d) if (s === 2) return (b & c) | (b & d) | (c & d) return b ^ c ^ d } Sha1.prototype._update = function (M) { var W = this._w; var a = this._a | 0; var b = this._b | 0; var c = this._c | 0; var d = this._d | 0; var e = this._e | 0; for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4); for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]); for (var j = 0; j < 80; ++j) { var s = ~~(j / 20); var t = (rotl5$1(a) + ft$1(s, b, c, d) + e + W[j] + K$1[s]) | 0; e = d; d = c; c = rotl30$1(b); b = a; a = t; } this._a = (a + this._a) | 0; this._b = (b + this._b) | 0; this._c = (c + this._c) | 0; this._d = (d + this._d) | 0; this._e = (e + this._e) | 0; }; Sha1.prototype._hash = function () { var H = Buffer$6.allocUnsafe(20); H.writeInt32BE(this._a | 0, 0); H.writeInt32BE(this._b | 0, 4); H.writeInt32BE(this._c | 0, 8); H.writeInt32BE(this._d | 0, 12); H.writeInt32BE(this._e | 0, 16); return H }; var sha1 = Sha1; /** * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined * in FIPS 180-2 * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet * */ var Buffer$7 = safeBuffer.Buffer; var K$2 = [ 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2 ]; var W$2 = new Array(64); function Sha256 () { this.init(); this._w = W$2; // new Array(64) hash.call(this, 64, 56); } inherits_browser(Sha256, hash); Sha256.prototype.init = function () { this._a = 0x6a09e667; this._b = 0xbb67ae85; this._c = 0x3c6ef372; this._d = 0xa54ff53a; this._e = 0x510e527f; this._f = 0x9b05688c; this._g = 0x1f83d9ab; this._h = 0x5be0cd19; return this }; function ch (x, y, z) { return z ^ (x & (y ^ z)) } function maj (x, y, z) { return (x & y) | (z & (x | y)) } function sigma0 (x) { return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10) } function sigma1 (x) { return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7) } function gamma0 (x) { return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3) } function gamma1 (x) { return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10) } Sha256.prototype._update = function (M) { var W = this._w; var a = this._a | 0; var b = this._b | 0; var c = this._c | 0; var d = this._d | 0; var e = this._e | 0; var f = this._f | 0; var g = this._g | 0; var h = this._h | 0; for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4); for (; i < 64; ++i) W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0; for (var j = 0; j < 64; ++j) { var T1 = (h + sigma1(e) + ch(e, f, g) + K$2[j] + W[j]) | 0; var T2 = (sigma0(a) + maj(a, b, c)) | 0; h = g; g = f; f = e; e = (d + T1) | 0; d = c; c = b; b = a; a = (T1 + T2) | 0; } this._a = (a + this._a) | 0; this._b = (b + this._b) | 0; this._c = (c + this._c) | 0; this._d = (d + this._d) | 0; this._e = (e + this._e) | 0; this._f = (f + this._f) | 0; this._g = (g + this._g) | 0; this._h = (h + this._h) | 0; }; Sha256.prototype._hash = function () { var H = Buffer$7.allocUnsafe(32); H.writeInt32BE(this._a, 0); H.writeInt32BE(this._b, 4); H.writeInt32BE(this._c, 8); H.writeInt32BE(this._d, 12); H.writeInt32BE(this._e, 16); H.writeInt32BE(this._f, 20); H.writeInt32BE(this._g, 24); H.writeInt32BE(this._h, 28); return H }; var sha256 = Sha256; /** * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined * in FIPS 180-2 * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet * */ var Buffer$8 = safeBuffer.Buffer; var W$3 = new Array(64); function Sha224 () { this.init(); this._w = W$3; // new Array(64) hash.call(this, 64, 56); } inherits_browser(Sha224, sha256); Sha224.prototype.init = function () { this._a = 0xc1059ed8; this._b = 0x367cd507; this._c = 0x3070dd17; this._d = 0xf70e5939; this._e = 0xffc00b31; this._f = 0x68581511; this._g = 0x64f98fa7; this._h = 0xbefa4fa4; return this }; Sha224.prototype._hash = function () { var H = Buffer$8.allocUnsafe(28); H.writeInt32BE(this._a, 0); H.writeInt32BE(this._b, 4); H.writeInt32BE(this._c, 8); H.writeInt32BE(this._d, 12); H.writeInt32BE(this._e, 16); H.writeInt32BE(this._f, 20); H.writeInt32BE(this._g, 24); return H }; var sha224 = Sha224; var Buffer$9 = safeBuffer.Buffer; var K$3 = [ 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817 ]; var W$4 = new Array(160); function Sha512 () { this.init(); this._w = W$4; hash.call(this, 128, 112); } inherits_browser(Sha512, hash); Sha512.prototype.init = function () { this._ah = 0x6a09e667; this._bh = 0xbb67ae85; this._ch = 0x3c6ef372; this._dh = 0xa54ff53a; this._eh = 0x510e527f; this._fh = 0x9b05688c; this._gh = 0x1f83d9ab; this._hh = 0x5be0cd19; this._al = 0xf3bcc908; this._bl = 0x84caa73b; this._cl = 0xfe94f82b; this._dl = 0x5f1d36f1; this._el = 0xade682d1; this._fl = 0x2b3e6c1f; this._gl = 0xfb41bd6b; this._hl = 0x137e2179; return this }; function Ch (x, y, z) { return z ^ (x & (y ^ z)) } function maj$1 (x, y, z) { return (x & y) | (z & (x | y)) } function sigma0$1 (x, xl) { return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25) } function sigma1$1 (x, xl) { return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23) } function Gamma0 (x, xl) { return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7) } function Gamma0l (x, xl) { return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25) } function Gamma1 (x, xl) { return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6) } function Gamma1l (x, xl) { return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26) } function getCarry (a, b) { return (a >>> 0) < (b >>> 0) ? 1 : 0 } Sha512.prototype._update = function (M) { var W = this._w; var ah = this._ah | 0; var bh = this._bh | 0; var ch = this._ch | 0; var dh = this._dh | 0; var eh = this._eh | 0; var fh = this._fh | 0; var gh = this._gh | 0; var hh = this._hh | 0; var al = this._al | 0; var bl = this._bl | 0; var cl = this._cl | 0; var dl = this._dl | 0; var el = this._el | 0; var fl = this._fl | 0; var gl = this._gl | 0; var hl = this._hl | 0; for (var i = 0; i < 32; i += 2) { W[i] = M.readInt32BE(i * 4); W[i + 1] = M.readInt32BE(i * 4 + 4); } for (; i < 160; i += 2) { var xh = W[i - 15 * 2]; var xl = W[i - 15 * 2 + 1]; var gamma0 = Gamma0(xh, xl); var gamma0l = Gamma0l(xl, xh); xh = W[i - 2 * 2]; xl = W[i - 2 * 2 + 1]; var gamma1 = Gamma1(xh, xl); var gamma1l = Gamma1l(xl, xh); // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] var Wi7h = W[i - 7 * 2]; var Wi7l = W[i - 7 * 2 + 1]; var Wi16h = W[i - 16 * 2]; var Wi16l = W[i - 16 * 2 + 1]; var Wil = (gamma0l + Wi7l) | 0; var Wih = (gamma0 + Wi7h + getCarry(Wil, gamma0l)) | 0; Wil = (Wil + gamma1l) | 0; Wih = (Wih + gamma1 + getCarry(Wil, gamma1l)) | 0; Wil = (Wil + Wi16l) | 0; Wih = (Wih + Wi16h + getCarry(Wil, Wi16l)) | 0; W[i] = Wih; W[i + 1] = Wil; } for (var j = 0; j < 160; j += 2) { Wih = W[j]; Wil = W[j + 1]; var majh = maj$1(ah, bh, ch); var majl = maj$1(al, bl, cl); var sigma0h = sigma0$1(ah, al); var sigma0l = sigma0$1(al, ah); var sigma1h = sigma1$1(eh, el); var sigma1l = sigma1$1(el, eh); // t1 = h + sigma1 + ch + K[j] + W[j] var Kih = K$3[j]; var Kil = K$3[j + 1]; var chh = Ch(eh, fh, gh); var chl = Ch(el, fl, gl); var t1l = (hl + sigma1l) | 0; var t1h = (hh + sigma1h + getCarry(t1l, hl)) | 0; t1l = (t1l + chl) | 0; t1h = (t1h + chh + getCarry(t1l, chl)) | 0; t1l = (t1l + Kil) | 0; t1h = (t1h + Kih + getCarry(t1l, Kil)) | 0; t1l = (t1l + Wil) | 0; t1h = (t1h + Wih + getCarry(t1l, Wil)) | 0; // t2 = sigma0 + maj var t2l = (sigma0l + majl) | 0; var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0; hh = gh; hl = gl; gh = fh; gl = fl; fh = eh; fl = el; el = (dl + t1l) | 0; eh = (dh + t1h + getCarry(el, dl)) | 0; dh = ch; dl = cl; ch = bh; cl = bl; bh = ah; bl = al; al = (t1l + t2l) | 0; ah = (t1h + t2h + getCarry(al, t1l)) | 0; } this._al = (this._al + al) | 0; this._bl = (this._bl + bl) | 0; this._cl = (this._cl + cl) | 0; this._dl = (this._dl + dl) | 0; this._el = (this._el + el) | 0; this._fl = (this._fl + fl) | 0; this._gl = (this._gl + gl) | 0; this._hl = (this._hl + hl) | 0; this._ah = (this._ah + ah + getCarry(this._al, al)) | 0; this._bh = (this._bh + bh + getCarry(this._bl, bl)) | 0; this._ch = (this._ch + ch + getCarry(this._cl, cl)) | 0; this._dh = (this._dh + dh + getCarry(this._dl, dl)) | 0; this._eh = (this._eh + eh + getCarry(this._el, el)) | 0; this._fh = (this._fh + fh + getCarry(this._fl, fl)) | 0; this._gh = (this._gh + gh + getCarry(this._gl, gl)) | 0; this._hh = (this._hh + hh + getCarry(this._hl, hl)) | 0; }; Sha512.prototype._hash = function () { var H = Buffer$9.allocUnsafe(64); function writeInt64BE (h, l, offset) { H.writeInt32BE(h, offset); H.writeInt32BE(l, offset + 4); } writeInt64BE(this._ah, this._al, 0); writeInt64BE(this._bh, this._bl, 8); writeInt64BE(this._ch, this._cl, 16); writeInt64BE(this._dh, this._dl, 24); writeInt64BE(this._eh, this._el, 32); writeInt64BE(this._fh, this._fl, 40); writeInt64BE(this._gh, this._gl, 48); writeInt64BE(this._hh, this._hl, 56); return H }; var sha512 = Sha512; var Buffer$a = safeBuffer.Buffer; var W$5 = new Array(160); function Sha384 () { this.init(); this._w = W$5; hash.call(this, 128, 112); } inherits_browser(Sha384, sha512); Sha384.prototype.init = function () { this._ah = 0xcbbb9d5d; this._bh = 0x629a292a; this._ch = 0x9159015a; this._dh = 0x152fecd8; this._eh = 0x67332667; this._fh = 0x8eb44a87; this._gh = 0xdb0c2e0d; this._hh = 0x47b5481d; this._al = 0xc1059ed8; this._bl = 0x367cd507; this._cl = 0x3070dd17; this._dl = 0xf70e5939; this._el = 0xffc00b31; this._fl = 0x68581511; this._gl = 0x64f98fa7; this._hl = 0xbefa4fa4; return this }; Sha384.prototype._hash = function () { var H = Buffer$a.allocUnsafe(48); function writeInt64BE (h, l, offset) { H.writeInt32BE(h, offset); H.writeInt32BE(l, offset + 4); } writeInt64BE(this._ah, this._al, 0); writeInt64BE(this._bh, this._bl, 8); writeInt64BE(this._ch, this._cl, 16); writeInt64BE(this._dh, this._dl, 24); writeInt64BE(this._eh, this._el, 32); writeInt64BE(this._fh, this._fl, 40); return H }; var sha384 = Sha384; var sha_js = createCommonjsModule(function (module) { var exports = module.exports = function SHA (algorithm) { algorithm = algorithm.toLowerCase(); var Algorithm = exports[algorithm]; if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)') return new Algorithm() }; exports.sha = sha; exports.sha1 = sha1; exports.sha224 = sha224; exports.sha256 = sha256; exports.sha384 = sha384; exports.sha512 = sha512; }); var Buffer$b = safeBuffer.Buffer; var Transform$1 = stream.Transform; var StringDecoder = string_decoder.StringDecoder; function CipherBase (hashMode) { Transform$1.call(this); this.hashMode = typeof hashMode === 'string'; if (this.hashMode) { this[hashMode] = this._finalOrDigest; } else { this.final = this._finalOrDigest; } if (this._final) { this.__final = this._final; this._final = null; } this._decoder = null; this._encoding = null; } inherits_browser(CipherBase, Transform$1); CipherBase.prototype.update = function (data, inputEnc, outputEnc) { if (typeof data === 'string') { data = Buffer$b.from(data, inputEnc); } var outData = this._update(data); if (this.hashMode) return this if (outputEnc) { outData = this._toString(outData, outputEnc); } return outData }; CipherBase.prototype.setAutoPadding = function () {}; CipherBase.prototype.getAuthTag = function () { throw new Error('trying to get auth tag in unsupported state') }; CipherBase.prototype.setAuthTag = function () { throw new Error('trying to set auth tag in unsupported state') }; CipherBase.prototype.setAAD = function () { throw new Error('trying to set aad in unsupported state') }; CipherBase.prototype._transform = function (data, _, next) { var err; try { if (this.hashMode) { this._update(data); } else { this.push(this._update(data)); } } catch (e) { err = e; } finally { next(err); } }; CipherBase.prototype._flush = function (done) { var err; try { this.push(this.__final()); } catch (e) { err = e; } done(err); }; CipherBase.prototype._finalOrDigest = function (outputEnc) { var outData = this.__final() || Buffer$b.alloc(0); if (outputEnc) { outData = this._toString(outData, outputEnc, true); } return outData }; CipherBase.prototype._toString = function (value, enc, fin) { if (!this._decoder) { this._decoder = new StringDecoder(enc); this._encoding = enc; } if (this._encoding !== enc) throw new Error('can\'t switch encodings') var out = this._decoder.write(value); if (fin) { out += this._decoder.end(); } return out }; var cipherBase = CipherBase; function Hash$1 (hash) { cipherBase.call(this, 'digest'); this._hash = hash; } inherits_browser(Hash$1, cipherBase); Hash$1.prototype._update = function (data) { this._hash.update(data); }; Hash$1.prototype._final = function () { return this._hash.digest() }; var browser$1 = function createHash (alg) { alg = alg.toLowerCase(); if (alg === 'md5') return new md5_js() if (alg === 'rmd160' || alg === 'ripemd160') return new ripemd160() return new Hash$1(sha_js(alg)) }; var Buffer$c = safeBuffer.Buffer; var ZEROS = Buffer$c.alloc(128); var blocksize = 64; function Hmac (alg, key) { cipherBase.call(this, 'digest'); if (typeof key === 'string') { key = Buffer$c.from(key); } this._alg = alg; this._key = key; if (key.length > blocksize) { key = alg(key); } else if (key.length < blocksize) { key = Buffer$c.concat([key, ZEROS], blocksize); } var ipad = this._ipad = Buffer$c.allocUnsafe(blocksize); var opad = this._opad = Buffer$c.allocUnsafe(blocksize); for (var i = 0; i < blocksize; i++) { ipad[i] = key[i] ^ 0x36; opad[i] = key[i] ^ 0x5C; } this._hash = [ipad]; } inherits_browser(Hmac, cipherBase); Hmac.prototype._update = function (data) { this._hash.push(data); }; Hmac.prototype._final = function () { var h = this._alg(Buffer$c.concat(this._hash)); return this._alg(Buffer$c.concat([this._opad, h])) }; var legacy = Hmac; var md5 = function (buffer) { return new md5_js().update(buffer).digest() }; var Buffer$d = safeBuffer.Buffer; var ZEROS$1 = Buffer$d.alloc(128); function Hmac$1 (alg, key) { cipherBase.call(this, 'digest'); if (typeof key === 'string') { key = Buffer$d.from(key); } var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64; this._alg = alg; this._key = key; if (key.length > blocksize) { var hash = alg === 'rmd160' ? new ripemd160() : sha_js(alg); key = hash.update(key).digest(); } else if (key.length < blocksize) { key = Buffer$d.concat([key, ZEROS$1], blocksize); } var ipad = this._ipad = Buffer$d.allocUnsafe(blocksize); var opad = this._opad = Buffer$d.allocUnsafe(blocksize); for (var i = 0; i < blocksize; i++) { ipad[i] = key[i] ^ 0x36; opad[i] = key[i] ^ 0x5C; } this._hash = alg === 'rmd160' ? new ripemd160() : sha_js(alg); this._hash.update(ipad); } inherits_browser(Hmac$1, cipherBase); Hmac$1.prototype._update = function (data) { this._hash.update(data); }; Hmac$1.prototype._final = function () { var h = this._hash.digest(); var hash = this._alg === 'rmd160' ? new ripemd160() : sha_js(this._alg); return hash.update(this._opad).update(h).digest() }; var browser$2 = function createHmac (alg, key) { alg = alg.toLowerCase(); if (alg === 'rmd160' || alg === 'ripemd160') { return new Hmac$1('rmd160', key) } if (alg === 'md5') { return new legacy(md5, key) } return new Hmac$1(alg, key) }; var sha224WithRSAEncryption = { sign: "rsa", hash: "sha224", id: "302d300d06096086480165030402040500041c" }; var sha256WithRSAEncryption = { sign: "rsa", hash: "sha256", id: "3031300d060960864801650304020105000420" }; var sha384WithRSAEncryption = { sign: "rsa", hash: "sha384", id: "3041300d060960864801650304020205000430" }; var sha512WithRSAEncryption = { sign: "rsa", hash: "sha512", id: "3051300d060960864801650304020305000440" }; var sha256$1 = { sign: "ecdsa", hash: "sha256", id: "" }; var sha224$1 = { sign: "ecdsa", hash: "sha224", id: "" }; var sha384$1 = { sign: "ecdsa", hash: "sha384", id: "" }; var sha512$1 = { sign: "ecdsa", hash: "sha512", id: "" }; var DSA = { sign: "dsa", hash: "sha1", id: "" }; var ripemd160WithRSA = { sign: "rsa", hash: "rmd160", id: "3021300906052b2403020105000414" }; var md5WithRSAEncryption = { sign: "rsa", hash: "md5", id: "3020300c06082a864886f70d020505000410" }; var algorithms = { sha224WithRSAEncryption: sha224WithRSAEncryption, "RSA-SHA224": { sign: "ecdsa/rsa", hash: "sha224", id: "302d300d06096086480165030402040500041c" }, sha256WithRSAEncryption: sha256WithRSAEncryption, "RSA-SHA256": { sign: "ecdsa/rsa", hash: "sha256", id: "3031300d060960864801650304020105000420" }, sha384WithRSAEncryption: sha384WithRSAEncryption, "RSA-SHA384": { sign: "ecdsa/rsa", hash: "sha384", id: "3041300d060960864801650304020205000430" }, sha512WithRSAEncryption: sha512WithRSAEncryption, "RSA-SHA512": { sign: "ecdsa/rsa", hash: "sha512", id: "3051300d060960864801650304020305000440" }, "RSA-SHA1": { sign: "rsa", hash: "sha1", id: "3021300906052b0e03021a05000414" }, "ecdsa-with-SHA1": { sign: "ecdsa", hash: "sha1", id: "" }, sha256: sha256$1, sha224: sha224$1, sha384: sha384$1, sha512: sha512$1, "DSA-SHA": { sign: "dsa", hash: "sha1", id: "" }, "DSA-SHA1": { sign: "dsa", hash: "sha1", id: "" }, DSA: DSA, "DSA-WITH-SHA224": { sign: "dsa", hash: "sha224", id: "" }, "DSA-SHA224": { sign: "dsa", hash: "sha224", id: "" }, "DSA-WITH-SHA256": { sign: "dsa", hash: "sha256", id: "" }, "DSA-SHA256": { sign: "dsa", hash: "sha256", id: "" }, "DSA-WITH-SHA384": { sign: "dsa", hash: "sha384", id: "" }, "DSA-SHA384": { sign: "dsa", hash: "sha384", id: "" }, "DSA-WITH-SHA512": { sign: "dsa", hash: "sha512", id: "" }, "DSA-SHA512": { sign: "dsa", hash: "sha512", id: "" }, "DSA-RIPEMD160": { sign: "dsa", hash: "rmd160", id: "" }, ripemd160WithRSA: ripemd160WithRSA, "RSA-RIPEMD160": { sign: "rsa", hash: "rmd160", id: "3021300906052b2403020105000414" }, md5WithRSAEncryption: md5WithRSAEncryption, "RSA-MD5": { sign: "rsa", hash: "md5", id: "3020300c06082a864886f70d020505000410" } }; var algorithms$1 = /*#__PURE__*/Object.freeze({ sha224WithRSAEncryption: sha224WithRSAEncryption, sha256WithRSAEncryption: sha256WithRSAEncryption, sha384WithRSAEncryption: sha384WithRSAEncryption, sha512WithRSAEncryption: sha512WithRSAEncryption, sha256: sha256$1, sha224: sha224$1, sha384: sha384$1, sha512: sha512$1, DSA: DSA, ripemd160WithRSA: ripemd160WithRSA, md5WithRSAEncryption: md5WithRSAEncryption, 'default': algorithms }); var algorithms$2 = getCjsExportFromNamespace(algorithms$1); var algos = algorithms$2; var MAX_ALLOC = Math.pow(2, 30) - 1; // default in iojs function checkBuffer (buf, name) { if (typeof buf !== 'string' && !Buffer.isBuffer(buf)) { throw new TypeError(name + ' must be a buffer or string') } } var precondition = function (password, salt, iterations, keylen) { checkBuffer(password, 'Password'); checkBuffer(salt, 'Salt'); if (typeof iterations !== 'number') { throw new TypeError('Iterations not a number') } if (iterations < 0) { throw new TypeError('Bad iterations') } if (typeof keylen !== 'number') { throw new TypeError('Key length not a number') } if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) { /* eslint no-self-compare: 0 */ throw new TypeError('Bad key length') } }; var defaultEncoding; /* istanbul ignore next */ if (process.browser) { defaultEncoding = 'utf-8'; } else { var pVersionMajor = parseInt(process.version.split('.')[0].slice(1), 10); defaultEncoding = pVersionMajor >= 6 ? 'utf-8' : 'binary'; } var defaultEncoding_1 = defaultEncoding; var Buffer$e = safeBuffer.Buffer; var ZEROS$2 = Buffer$e.alloc(128); var sizes = { md5: 16, sha1: 20, sha224: 28, sha256: 32, sha384: 48, sha512: 64, rmd160: 20, ripemd160: 20 }; function Hmac$2 (alg, key, saltLen) { var hash = getDigest(alg); var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64; if (key.length > blocksize) { key = hash(key); } else if (key.length < blocksize) { key = Buffer$e.concat([key, ZEROS$2], blocksize); } var ipad = Buffer$e.allocUnsafe(blocksize + sizes[alg]); var opad = Buffer$e.allocUnsafe(blocksize + sizes[alg]); for (var i = 0; i < blocksize; i++) { ipad[i] = key[i] ^ 0x36; opad[i] = key[i] ^ 0x5C; } var ipad1 = Buffer$e.allocUnsafe(blocksize + saltLen + 4); ipad.copy(ipad1, 0, 0, blocksize); this.ipad1 = ipad1; this.ipad2 = ipad; this.opad = opad; this.alg = alg; this.blocksize = blocksize; this.hash = hash; this.size = sizes[alg]; } Hmac$2.prototype.run = function (data, ipad) { data.copy(ipad, this.blocksize); var h = this.hash(ipad); h.copy(this.opad, this.blocksize); return this.hash(this.opad) }; function getDigest (alg) { function shaFunc (data) { return sha_js(alg).update(data).digest() } function rmd160Func (data) { return new ripemd160().update(data).digest() } if (alg === 'rmd160' || alg === 'ripemd160') return rmd160Func if (alg === 'md5') return md5 return shaFunc } function pbkdf2 (password, salt, iterations, keylen, digest) { precondition(password, salt, iterations, keylen); if (!Buffer$e.isBuffer(password)) password = Buffer$e.from(password, defaultEncoding_1); if (!Buffer$e.isBuffer(salt)) salt = Buffer$e.from(salt, defaultEncoding_1); digest = digest || 'sha1'; var hmac = new Hmac$2(digest, password, salt.length); var DK = Buffer$e.allocUnsafe(keylen); var block1 = Buffer$e.allocUnsafe(salt.length + 4); salt.copy(block1, 0, 0, salt.length); var destPos = 0; var hLen = sizes[digest]; var l = Math.ceil(keylen / hLen); for (var i = 1; i <= l; i++) { block1.writeUInt32BE(i, salt.length); var T = hmac.run(block1, hmac.ipad1); var U = T; for (var j = 1; j < iterations; j++) { U = hmac.run(U, hmac.ipad2); for (var k = 0; k < hLen; k++) T[k] ^= U[k]; } T.copy(DK, destPos); destPos += hLen; } return DK } var syncBrowser = pbkdf2; var Buffer$f = safeBuffer.Buffer; var ZERO_BUF; var subtle = commonjsGlobal.crypto && commonjsGlobal.crypto.subtle; var toBrowser = { 'sha': 'SHA-1', 'sha-1': 'SHA-1', 'sha1': 'SHA-1', 'sha256': 'SHA-256', 'sha-256': 'SHA-256', 'sha384': 'SHA-384', 'sha-384': 'SHA-384', 'sha-512': 'SHA-512', 'sha512': 'SHA-512' }; var checks = []; function checkNative (algo) { if (commonjsGlobal.process && !commonjsGlobal.process.browser) { return Promise.resolve(false) } if (!subtle || !subtle.importKey || !subtle.deriveBits) { return Promise.resolve(false) } if (checks[algo] !== undefined) { return checks[algo] } ZERO_BUF = ZERO_BUF || Buffer$f.alloc(8); var prom = browserPbkdf2(ZERO_BUF, ZERO_BUF, 10, 128, algo) .then(function () { return true }).catch(function () { return false }); checks[algo] = prom; return prom } function browserPbkdf2 (password, salt, iterations, length, algo) { return subtle.importKey( 'raw', password, {name: 'PBKDF2'}, false, ['deriveBits'] ).then(function (key) { return subtle.deriveBits({ name: 'PBKDF2', salt: salt, iterations: iterations, hash: { name: algo } }, key, length << 3) }).then(function (res) { return Buffer$f.from(res) }) } function resolvePromise (promise, callback) { promise.then(function (out) { process.nextTick(function () { callback(null, out); }); }, function (e) { process.nextTick(function () { callback(e); }); }); } var async = function (password, salt, iterations, keylen, digest, callback) { if (typeof digest === 'function') { callback = digest; digest = undefined; } digest = digest || 'sha1'; var algo = toBrowser[digest.toLowerCase()]; if (!algo || typeof commonjsGlobal.Promise !== 'function') { return process.nextTick(function () { var out; try { out = syncBrowser(password, salt, iterations, keylen, digest); } catch (e) { return callback(e) } callback(null, out); }) } precondition(password, salt, iterations, keylen); if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2') if (!Buffer$f.isBuffer(password)) password = Buffer$f.from(password, defaultEncoding_1); if (!Buffer$f.isBuffer(salt)) salt = Buffer$f.from(salt, defaultEncoding_1); resolvePromise(checkNative(algo).then(function (resp) { if (resp) return browserPbkdf2(password, salt, iterations, keylen, algo) return syncBrowser(password, salt, iterations, keylen, digest) }), callback); }; var pbkdf2$1 = async; var pbkdf2Sync = syncBrowser; var browser$3 = { pbkdf2: pbkdf2$1, pbkdf2Sync: pbkdf2Sync }; var readUInt32BE = function readUInt32BE(bytes, off) { var res = (bytes[0 + off] << 24) | (bytes[1 + off] << 16) | (bytes[2 + off] << 8) | bytes[3 + off]; return res >>> 0; }; var writeUInt32BE = function writeUInt32BE(bytes, value, off) { bytes[0 + off] = value >>> 24; bytes[