Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function e(t, n, r) {
- function s(o, u) {
- if (!n[o]) {
- if (!t[o]) {
- var a = typeof require == "function" && require;
- if (!u && a) return a(o, !0);
- if (i) return i(o, !0);
- var f = new Error("Cannot find module '" + o + "'");
- throw f.code = "MODULE_NOT_FOUND", f
- }
- var l = n[o] = {
- exports: {}
- };
- t[o][0].call(l.exports, function(e) {
- var n = t[o][1][e];
- return s(n ? n : e)
- }, l, l.exports, e, t, n, r)
- }
- return n[o].exports
- }
- var i = typeof require == "function" && require;
- for (var o = 0; o < r.length; o++) s(r[o]);
- return s
- })({
- 16: [function(require, module, exports) {
- 'use strict'
- exports.toByteArray = toByteArray
- var lookup = []
- var revLookup = []
- var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
- var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
- for (var i = 0, len = code.length; i < len; ++i) {
- lookup[i] = code[i]
- revLookup[code.charCodeAt(i)] = i
- }
- revLookup['-'.charCodeAt(0)] = 62
- revLookup['_'.charCodeAt(0)] = 63
- function placeHoldersCount(b64) {
- var len = b64.length
- if (len % 4 > 0) {
- throw new Error('Invalid string. Length must be a multiple of 4')
- }
- // the number of equal signs (place holders)
- // if there are two placeholders, than the two characters before it
- // represent one byte
- // if there is only one, then the three characters before it represent 2 bytes
- // this is just a cheap hack to not do indexOf twice
- return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
- }
- function toByteArray(b64) {
- var i, l, tmp, placeHolders, arr
- var len = b64.length
- placeHolders = placeHoldersCount(b64)
- arr = new Arr((len * 3 / 4) - placeHolders)
- // if there are placeholders, only get up to the last complete 4 chars
- l = placeHolders > 0 ? len - 4 : len
- var L = 0
- for (i = 0; i < l; i += 4) {
- tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
- arr[L++] = (tmp >> 16) & 0xFF
- arr[L++] = (tmp >> 8) & 0xFF
- arr[L++] = tmp & 0xFF
- }
- if (placeHolders === 2) {
- tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
- arr[L++] = tmp & 0xFF
- } else if (placeHolders === 1) {
- tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
- arr[L++] = (tmp >> 8) & 0xFF
- arr[L++] = tmp & 0xFF
- }
- return arr
- }
- }, {}],
- 46: [function(require, module, exports) {
- /*!
- * The buffer module from node.js, for the browser.
- *
- * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
- * @license MIT
- */
- /* eslint-disable no-proto */
- 'use strict'
- var base64 = require('base64-js')
- exports.Buffer = Buffer
- exports.INSPECT_MAX_BYTES = 50
- var K_MAX_LENGTH = 0x7fffffff
- exports.kMaxLength = K_MAX_LENGTH
- /**
- * If `Buffer.TYPED_ARRAY_SUPPORT`:
- * === true Use Uint8Array implementation (fastest)
- * === false Print warning and recommend using `buffer` v4.x which has an Object
- * implementation (most compatible, even IE6)
- *
- * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
- * Opera 11.6+, iOS 4.2+.
- *
- * We report that the browser does not support typed arrays if the are not subclassable
- * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
- * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
- * for __proto__ and has a buggy typed array implementation.
- */
- Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
- if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
- typeof console.error === 'function') {
- console.error(
- 'This browser lacks typed array (Uint8Array) support which is required by ' +
- '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
- )
- }
- function typedArraySupport() {
- // Can typed array instances can be augmented?
- try {
- var arr = new Uint8Array(1)
- arr.__proto__ = {
- __proto__: Uint8Array.prototype,
- foo: function() {
- return 42
- }
- }
- return arr.foo() === 42
- } catch (e) {
- return false
- }
- }
- function createBuffer(length) {
- if (length > K_MAX_LENGTH) {
- throw new RangeError('Invalid typed array length')
- }
- // Return an augmented `Uint8Array` instance
- var buf = new Uint8Array(length)
- buf.__proto__ = Buffer.prototype
- return buf
- }
- /**
- * The Buffer constructor returns instances of `Uint8Array` that have their
- * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
- * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
- * and the `Uint8Array` methods. Square bracket notation works as expected -- it
- * returns a single octet.
- *
- * The `Uint8Array` prototype remains unmodified.
- */
- function Buffer(arg, encodingOrOffset, length) {
- // Common case.
- if (typeof arg === 'number') {
- if (typeof encodingOrOffset === 'string') {
- throw new Error(
- 'If encoding is specified then the first argument must be a string'
- )
- }
- return allocUnsafe(arg)
- }
- return from(arg, encodingOrOffset, length)
- }
- // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
- if (typeof Symbol !== 'undefined' && Symbol.species &&
- Buffer[Symbol.species] === Buffer) {
- Object.defineProperty(Buffer, Symbol.species, {
- value: null,
- configurable: true,
- enumerable: false,
- writable: false
- })
- }
- Buffer.poolSize = 8192 // not used by this implementation
- function from(value, encodingOrOffset, length) {
- if (typeof value === 'number') {
- throw new TypeError('"value" argument must not be a number')
- }
- if (value instanceof ArrayBuffer) {
- return fromArrayBuffer(value, encodingOrOffset, length)
- }
- if (typeof value === 'string') {
- return fromString(value, encodingOrOffset)
- }
- return fromObject(value)
- }
- // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
- // https://github.com/feross/buffer/pull/148
- Buffer.prototype.__proto__ = Uint8Array.prototype
- Buffer.__proto__ = Uint8Array
- function assertSize(size) {
- if (typeof size !== 'number') {
- throw new TypeError('"size" argument must be a number')
- } else if (size < 0) {
- throw new RangeError('"size" argument must not be negative')
- }
- }
- function allocUnsafe(size) {
- assertSize(size)
- return createBuffer(size < 0 ? 0 : checked(size) | 0)
- }
- /**
- * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
- * */
- Buffer.allocUnsafe = function(size) {
- return allocUnsafe(size)
- }
- function fromString(string, encoding) {
- if (typeof encoding !== 'string' || encoding === '') {
- encoding = 'utf8'
- }
- if (!Buffer.isEncoding(encoding)) {
- throw new TypeError('"encoding" must be a valid string encoding')
- }
- var length = byteLength(string, encoding) | 0
- var buf = createBuffer(length)
- var actual = buf.write(string, encoding)
- if (actual !== length) {
- // Writing a hex string, for example, that contains invalid characters will
- // cause everything after the first invalid character to be ignored. (e.g.
- // 'abxxcd' will be treated as 'ab')
- buf = buf.slice(0, actual)
- }
- return buf
- }
- function fromArrayLike(array) {
- var length = array.length < 0 ? 0 : checked(array.length) | 0
- var buf = createBuffer(length)
- for (var i = 0; i < length; i += 1) {
- buf[i] = array[i] & 255
- }
- return buf
- }
- function fromArrayBuffer(array, byteOffset, length) {
- if (byteOffset < 0 || array.byteLength < byteOffset) {
- throw new RangeError('\'offset\' is out of bounds')
- }
- if (array.byteLength < byteOffset + (length || 0)) {
- throw new RangeError('\'length\' is out of bounds')
- }
- var buf
- if (byteOffset === undefined && length === undefined) {
- buf = new Uint8Array(array)
- } else if (length === undefined) {
- buf = new Uint8Array(array, byteOffset)
- } else {
- buf = new Uint8Array(array, byteOffset, length)
- }
- // Return an augmented `Uint8Array` instance
- buf.__proto__ = Buffer.prototype
- return buf
- }
- function fromObject(obj) {
- if (Buffer.isBuffer(obj)) {
- var len = checked(obj.length) | 0
- var buf = createBuffer(len)
- if (buf.length === 0) {
- return buf
- }
- obj.copy(buf, 0, 0, len)
- return buf
- }
- if (obj) {
- if (isArrayBufferView(obj) || 'length' in obj) {
- if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
- return createBuffer(0)
- }
- return fromArrayLike(obj)
- }
- if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
- return fromArrayLike(obj.data)
- }
- }
- throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
- }
- function checked(length) {
- // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
- // length is NaN (which is otherwise coerced to zero.)
- if (length >= K_MAX_LENGTH) {
- throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
- 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
- }
- return length | 0
- }
- Buffer.isBuffer = function isBuffer(b) {
- return b != null && b._isBuffer === true
- }
- Buffer.isEncoding = function isEncoding(encoding) {
- switch (String(encoding).toLowerCase()) {
- case 'hex':
- case 'utf8':
- case 'utf-8':
- case 'ascii':
- case 'latin1':
- case 'binary':
- case 'base64':
- case 'ucs2':
- case 'ucs-2':
- case 'utf16le':
- case 'utf-16le':
- return true
- default:
- return false
- }
- }
- Buffer.concat = function concat(list, length) {
- if (!Array.isArray(list)) {
- throw new TypeError('"list" argument must be an Array of Buffers')
- }
- if (list.length === 0) {
- return Buffer.alloc(0)
- }
- var i
- if (length === undefined) {
- length = 0
- for (i = 0; i < list.length; ++i) {
- length += list[i].length
- }
- }
- var buffer = Buffer.allocUnsafe(length)
- var pos = 0
- for (i = 0; i < list.length; ++i) {
- var buf = list[i]
- if (!Buffer.isBuffer(buf)) {
- throw new TypeError('"list" argument must be an Array of Buffers')
- }
- buf.copy(buffer, pos)
- pos += buf.length
- }
- return buffer
- }
- function byteLength(string, encoding) {
- if (Buffer.isBuffer(string)) {
- return string.length
- }
- if (isArrayBufferView(string) || string instanceof ArrayBuffer) {
- return string.byteLength
- }
- if (typeof string !== 'string') {
- string = '' + string
- }
- var len = string.length
- if (len === 0) return 0
- // Use a for loop to avoid recursion
- var loweredCase = false
- for (;;) {
- switch (encoding) {
- case 'ascii':
- case 'latin1':
- case 'binary':
- return len
- case 'utf8':
- case 'utf-8':
- case undefined:
- return utf8ToBytes(string).length
- case 'ucs2':
- case 'ucs-2':
- case 'utf16le':
- case 'utf-16le':
- return len * 2
- case 'hex':
- return len >>> 1
- case 'base64':
- return base64ToBytes(string).length
- default:
- if (loweredCase) return utf8ToBytes(string).length // assume utf8
- encoding = ('' + encoding).toLowerCase()
- loweredCase = true
- }
- }
- }
- Buffer.byteLength = byteLength
- function slowToString(encoding, start, end) {
- var loweredCase = false
- // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
- // property of a typed array.
- // This behaves neither like String nor Uint8Array in that we set start/end
- // to their upper/lower bounds if the value passed is out of range.
- // undefined is handled specially as per ECMA-262 6th Edition,
- // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
- if (start === undefined || start < 0) {
- start = 0
- }
- // Return early if start > this.length. Done here to prevent potential uint32
- // coercion fail below.
- if (start > this.length) {
- return ''
- }
- if (end === undefined || end > this.length) {
- end = this.length
- }
- if (end <= 0) {
- return ''
- }
- // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
- end >>>= 0
- start >>>= 0
- if (end <= start) {
- return ''
- }
- if (!encoding) encoding = 'utf8'
- while (true) {
- switch (encoding) {
- case 'hex':
- return hexSlice(this, start, end)
- case 'utf8':
- case 'utf-8':
- return utf8Slice(this, start, end)
- case 'ascii':
- return asciiSlice(this, start, end)
- case 'latin1':
- case 'binary':
- return latin1Slice(this, start, end)
- case 'base64':
- return base64Slice(this, start, end)
- case 'ucs2':
- case 'ucs-2':
- case 'utf16le':
- case 'utf-16le':
- return utf16leSlice(this, start, end)
- default:
- if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
- encoding = (encoding + '').toLowerCase()
- loweredCase = true
- }
- }
- }
- // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
- // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
- // reliably in a browserify context because there could be multiple different
- // copies of the 'buffer' package in use. This method works even for Buffer
- // instances that were created from another copy of the `buffer` package.
- // See: https://github.com/feross/buffer/issues/154
- Buffer.prototype._isBuffer = true
- Buffer.prototype.toString = function toString() {
- var length = this.length
- if (length === 0) return ''
- if (arguments.length === 0) return utf8Slice(this, 0, length)
- return slowToString.apply(this, arguments)
- }
- function hexWrite(buf, string, offset, length) {
- offset = Number(offset) || 0
- var remaining = buf.length - offset
- if (!length) {
- length = remaining
- } else {
- length = Number(length)
- if (length > remaining) {
- length = remaining
- }
- }
- // must be an even number of digits
- var strLen = string.length
- if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
- if (length > strLen / 2) {
- length = strLen / 2
- }
- for (var i = 0; i < length; ++i) {
- var parsed = parseInt(string.substr(i * 2, 2), 16)
- if (numberIsNaN(parsed)) return i
- buf[offset + i] = parsed
- }
- return i
- }
- function utf8Write(buf, string, offset, length) {
- return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
- }
- function base64Write(buf, string, offset, length) {
- return blitBuffer(base64ToBytes(string), buf, offset, length)
- }
- Buffer.prototype.write = function write(string, offset, length, encoding) {
- // Buffer#write(string)
- if (offset === undefined) {
- encoding = 'utf8'
- length = this.length
- offset = 0
- // Buffer#write(string, encoding)
- } else if (length === undefined && typeof offset === 'string') {
- encoding = offset
- length = this.length
- offset = 0
- // Buffer#write(string, offset[, length][, encoding])
- } else if (isFinite(offset)) {
- offset = offset >>> 0
- if (isFinite(length)) {
- length = length >>> 0
- if (encoding === undefined) encoding = 'utf8'
- } else {
- encoding = length
- length = undefined
- }
- } else {
- throw new Error(
- 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
- )
- }
- var remaining = this.length - offset
- if (length === undefined || length > remaining) length = remaining
- if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
- throw new RangeError('Attempt to write outside buffer bounds')
- }
- if (!encoding) encoding = 'utf8'
- var loweredCase = false
- for (;;) {
- switch (encoding) {
- case 'hex':
- return hexWrite(this, string, offset, length)
- case 'utf8':
- case 'utf-8':
- return utf8Write(this, string, offset, length)
- case 'ascii':
- return asciiWrite(this, string, offset, length)
- case 'latin1':
- case 'binary':
- return latin1Write(this, string, offset, length)
- case 'base64':
- // Warning: maxLength not taken into account in base64Write
- return base64Write(this, string, offset, length)
- case 'ucs2':
- case 'ucs-2':
- case 'utf16le':
- case 'utf-16le':
- return ucs2Write(this, string, offset, length)
- default:
- if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
- encoding = ('' + encoding).toLowerCase()
- loweredCase = true
- }
- }
- }
- function utf8Slice(buf, start, end) {
- end = Math.min(buf.length, end)
- var res = []
- var i = start
- while (i < end) {
- var firstByte = buf[i]
- var codePoint = null
- var bytesPerSequence = (firstByte > 0xEF) ? 4 :
- (firstByte > 0xDF) ? 3 :
- (firstByte > 0xBF) ? 2 :
- 1
- if (i + bytesPerSequence <= end) {
- var secondByte, thirdByte, fourthByte, tempCodePoint
- switch (bytesPerSequence) {
- case 1:
- if (firstByte < 0x80) {
- codePoint = firstByte
- }
- break
- case 2:
- secondByte = buf[i + 1]
- if ((secondByte & 0xC0) === 0x80) {
- tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
- if (tempCodePoint > 0x7F) {
- codePoint = tempCodePoint
- }
- }
- break
- case 3:
- secondByte = buf[i + 1]
- thirdByte = buf[i + 2]
- if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
- tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
- if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
- codePoint = tempCodePoint
- }
- }
- break
- case 4:
- secondByte = buf[i + 1]
- thirdByte = buf[i + 2]
- fourthByte = buf[i + 3]
- if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
- tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
- if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
- codePoint = tempCodePoint
- }
- }
- }
- }
- if (codePoint === null) {
- // we did not generate a valid codePoint so insert a
- // replacement char (U+FFFD) and advance only 1 byte
- codePoint = 0xFFFD
- bytesPerSequence = 1
- } else if (codePoint > 0xFFFF) {
- // encode to utf16 (surrogate pair dance)
- codePoint -= 0x10000
- res.push(codePoint >>> 10 & 0x3FF | 0xD800)
- codePoint = 0xDC00 | codePoint & 0x3FF
- }
- res.push(codePoint)
- i += bytesPerSequence
- }
- return decodeCodePointsArray(res)
- }
- // Based on http://stackoverflow.com/a/22747272/680742, the browser with
- // the lowest limit is Chrome, with 0x10000 args.
- // We go 1 magnitude less, for safety
- var MAX_ARGUMENTS_LENGTH = 0x1000
- function decodeCodePointsArray(codePoints) {
- var len = codePoints.length
- if (len <= MAX_ARGUMENTS_LENGTH) {
- return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
- }
- // Decode in chunks to avoid "call stack size exceeded".
- var res = ''
- var i = 0
- while (i < len) {
- res += String.fromCharCode.apply(
- String,
- codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
- )
- }
- return res
- }
- Buffer.prototype.slice = function slice(start, end) {
- var len = this.length
- start = ~~start
- end = end === undefined ? len : ~~end
- if (start < 0) {
- start += len
- if (start < 0) start = 0
- } else if (start > len) {
- start = len
- }
- if (end < 0) {
- end += len
- if (end < 0) end = 0
- } else if (end > len) {
- end = len
- }
- if (end < start) end = start
- var newBuf = this.subarray(start, end)
- // Return an augmented `Uint8Array` instance
- newBuf.__proto__ = Buffer.prototype
- return newBuf
- }
- // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
- Buffer.prototype.copy = function copy(target, targetStart, start, end) {
- if (!start) start = 0
- if (!end && end !== 0) end = this.length
- if (targetStart >= target.length) targetStart = target.length
- if (!targetStart) targetStart = 0
- if (end > 0 && end < start) end = start
- // Copy 0 bytes; we're done
- if (end === start) return 0
- if (target.length === 0 || this.length === 0) return 0
- // Fatal error conditions
- if (targetStart < 0) {
- throw new RangeError('targetStart out of bounds')
- }
- if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
- if (end < 0) throw new RangeError('sourceEnd out of bounds')
- // Are we oob?
- if (end > this.length) end = this.length
- if (target.length - targetStart < end - start) {
- end = target.length - targetStart + start
- }
- var len = end - start
- var i
- if (this === target && start < targetStart && targetStart < end) {
- // descending copy from end
- for (i = len - 1; i >= 0; --i) {
- target[i + targetStart] = this[i + start]
- }
- } else if (len < 1000) {
- // ascending copy from start
- for (i = 0; i < len; ++i) {
- target[i + targetStart] = this[i + start]
- }
- } else {
- Uint8Array.prototype.set.call(
- target,
- this.subarray(start, start + len),
- targetStart
- )
- }
- return len
- }
- // HELPER FUNCTIONS
- // ================
- var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
- function base64clean(str) {
- // Node strips out invalid characters like \n and \t from the string, base64-js does not
- str = str.trim().replace(INVALID_BASE64_RE, '')
- // Node converts strings with length < 2 to ''
- if (str.length < 2) return ''
- // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
- while (str.length % 4 !== 0) {
- str = str + '='
- }
- return str
- }
- function utf8ToBytes(string, units) {
- units = units || Infinity
- var codePoint
- var length = string.length
- var leadSurrogate = null
- var bytes = []
- for (var i = 0; i < length; ++i) {
- codePoint = string.charCodeAt(i)
- // is surrogate component
- if (codePoint > 0xD7FF && codePoint < 0xE000) {
- // last char was a lead
- if (!leadSurrogate) {
- // no lead yet
- if (codePoint > 0xDBFF) {
- // unexpected trail
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
- continue
- } else if (i + 1 === length) {
- // unpaired lead
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
- continue
- }
- // valid lead
- leadSurrogate = codePoint
- continue
- }
- // 2 leads in a row
- if (codePoint < 0xDC00) {
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
- leadSurrogate = codePoint
- continue
- }
- // valid surrogate pair
- codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
- } else if (leadSurrogate) {
- // valid bmp char, but last char was a lead
- if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
- }
- leadSurrogate = null
- // encode utf8
- if (codePoint < 0x80) {
- if ((units -= 1) < 0) break
- bytes.push(codePoint)
- } else if (codePoint < 0x800) {
- if ((units -= 2) < 0) break
- bytes.push(
- codePoint >> 0x6 | 0xC0,
- codePoint & 0x3F | 0x80
- )
- } else if (codePoint < 0x10000) {
- if ((units -= 3) < 0) break
- bytes.push(
- codePoint >> 0xC | 0xE0,
- codePoint >> 0x6 & 0x3F | 0x80,
- codePoint & 0x3F | 0x80
- )
- } else if (codePoint < 0x110000) {
- if ((units -= 4) < 0) break
- bytes.push(
- codePoint >> 0x12 | 0xF0,
- codePoint >> 0xC & 0x3F | 0x80,
- codePoint >> 0x6 & 0x3F | 0x80,
- codePoint & 0x3F | 0x80
- )
- } else {
- throw new Error('Invalid code point')
- }
- }
- return bytes
- }
- function base64ToBytes(str) {
- return base64.toByteArray(base64clean(str))
- }
- function blitBuffer(src, dst, offset, length) {
- for (var i = 0; i < length; ++i) {
- if ((i + offset >= dst.length) || (i >= src.length)) break
- dst[i + offset] = src[i]
- }
- return i
- }
- // Node 0.10 supports `ArrayBuffer` but lacks `ArrayBuffer.isView`
- function isArrayBufferView(obj) {
- return (typeof ArrayBuffer.isView === 'function') && ArrayBuffer.isView(obj)
- }
- function numberIsNaN(obj) {
- return obj !== obj // eslint-disable-line no-self-compare
- }
- }, {
- "base64-js": 16
- }],
- 56: [function(require, module, exports) {
- 'use strict'
- exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes')
- var p = require('pbkdf2')
- exports.pbkdf2 = p.pbkdf2
- exports.pbkdf2Sync = p.pbkdf2Sync
- }, {
- "pbkdf2": 112,
- "randombytes": 125
- }],
- 112: [function(require, module, exports) {
- exports.pbkdf2 = require('./lib/async')
- exports.pbkdf2Sync = require('./lib/sync')
- }, {
- "./lib/async": 113,
- "./lib/sync": 116
- }],
- 113: [function(require, module, exports) {}, {}],
- 116: [function(require, module, exports) {}, {}],
- 118: [function(require, module, exports) {}, {}],
- 125: [function(require, module, exports) {
- (function(process, global) {
- 'use strict'
- var Buffer = require('buffer').Buffer
- var crypto = global.crypto || global.msCrypto
- if (crypto && crypto.getRandomValues) {
- module.exports = randomBytes
- } else {
- module.exports = oldBrowser
- }
- function randomBytes(size, cb) {
- // phantomjs needs to throw
- if (size > 65536) throw new Error('requested too many random bytes')
- // in case browserify isn't using the Uint8Array version
- var rawBytes = new global.Uint8Array(size)
- // This will not work in older browsers.
- // See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
- if (size > 0) { // getRandomValues fails on IE if size == 0
- crypto.getRandomValues(rawBytes)
- }
- // XXX: phantomjs doesn't like a buffer being passed here
- var bytes = Buffer.from(rawBytes.buffer)
- if (typeof cb === 'function') {
- return process.nextTick(function() {
- cb(null, bytes)
- })
- }
- return bytes
- }
- }).call(this, require('_process'), typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
- }, {
- "_process": 118,
- "buffer": 46
- }],
- 156: [function(require, module, exports) {
- (function(Buffer) {
- 'use strict';
- var pkcs1 = require('./pkcs1');
- var pkcs8 = require('./pkcs8');
- var _ = require('./utils')._;
- var utils = require('./utils');
- var BigInteger = require('./jsbn.js');
- var rsa = {};
- rsa.Key = (function() {
- /**
- * RSA key constructor
- *
- * n - modulus
- * e - publicExponent
- * d - privateExponent
- * p - prime1
- * q - prime2
- * dmp1 - exponent1 -- d mod (p1)
- * dmq1 - exponent2 -- d mod (q-1)
- * coeff - coefficient -- (inverse of q) mod p
- */
- function RSAKey() {
- this.n = null;
- this.e = 0;
- this.d = null;
- this.p = null;
- this.q = null;
- this.dmp1 = null;
- this.dmq1 = null;
- this.coeff = null;
- }
- RSAKey.prototype.setOptions = function(options) {
- var encryptionSchemeProvider = pkcs1;
- this.encryptionScheme = encryptionSchemeProvider.makeScheme(this, options);
- var pkcs1Scheme = pkcs1.makeScheme(this, options);
- this.encryptEngine = {
- encrypt: function(buffer, usePrivate) {
- var m, c;
- if (usePrivate) {
- /* Type 1: zeros padding for private key encrypt */
- m = new BigInteger(pkcs1Scheme.encPad(buffer, {
- type: 1
- }));
- c = this.$doPrivate(m);
- } else {
- m = new BigInteger(this.encryptionScheme.encPad(buffer));
- c = this.$doPublic(m);
- }
- return c.toBuffer(this.encryptedDataLength);
- }.bind(this)
- };
- };
- /**
- * Set the public key fields N and e from hex strings
- * @param N
- * @param E
- */
- RSAKey.prototype.setPublic = function(N, E) {
- if (N && E && N.length > 0 && (_.isNumber(E) || E.length > 0)) {
- this.n = new BigInteger(N);
- this.e = _.isNumber(E) ? E : utils.get32IntFromBuffer(E, 0);
- this.$$recalculateCache();
- } else {
- throw Error("Invalid RSA public key");
- }
- };
- /**
- * private
- * Perform raw public operation on "x": return x^e (mod n)
- *
- * @param x
- * @returns {*}
- */
- RSAKey.prototype.$doPublic = function(x) {
- return x.modPowInt(this.e, this.n);
- };
- /**
- * Return the PKCS#1 RSA encryption of buffer
- * @param buffer {Buffer}
- * @returns {Buffer}
- */
- RSAKey.prototype.encrypt = function(buffer, usePrivate) {
- var buffers = [];
- var results = [];
- var bufferSize = buffer.length;
- var buffersCount = Math.ceil(bufferSize / this.maxMessageLength) || 1; // total buffers count for encrypt
- var dividedSize = Math.ceil(bufferSize / buffersCount || 1); // each buffer size
- if (buffersCount == 1) {
- buffers.push(buffer);
- } else {
- for (var bufNum = 0; bufNum < buffersCount; bufNum++) {
- buffers.push(buffer.slice(bufNum * dividedSize, (bufNum + 1) * dividedSize));
- }
- }
- for (var i = 0; i < buffers.length; i++) {
- results.push(this.encryptEngine.encrypt(buffers[i], usePrivate));
- }
- return Buffer.concat(results);
- };
- Object.defineProperty(RSAKey.prototype, 'encryptedDataLength', {
- get: function() {
- return this.cache.keyByteLength;
- }
- });
- Object.defineProperty(RSAKey.prototype, 'maxMessageLength', {
- get: function() {
- return this.encryptionScheme.maxMessageLength();
- }
- });
- /**
- * Caching key data
- */
- RSAKey.prototype.$$recalculateCache = function() {
- this.cache = this.cache || {};
- // Bit & byte length
- this.cache.keyBitLength = this.n.bitLength();
- this.cache.keyByteLength = (this.cache.keyBitLength + 6) >> 3;
- };
- return RSAKey;
- })();
- var RsaWrap = (function() {
- /**
- * @param key {string|buffer|object} Key in PEM format, or data for generate key {b: bits, e: exponent}
- * @constructor
- */
- function NodeRSA(key, format, options) {
- this.$options = {
- signingScheme: "pkcs1",
- signingSchemeOptions: {
- hash: 'sha256',
- saltLength: null
- },
- encryptionScheme: "pkcs1",
- encryptionSchemeOptions: {},
- environment: "browser",
- rsaUtils: this
- };
- this.keyPair = new rsa.Key();
- }
- /**
- * Set and validate options for key instance
- * @param options
- */
- NodeRSA.prototype.setOptions = function(options) {
- if (options.encryptionScheme) {
- this.$options.encryptionScheme = options.encryptionScheme.toLowerCase();
- this.$options.encryptionSchemeOptions = {};
- }
- this.keyPair.setOptions(this.$options);
- };
- /**
- * Importing key
- * @param keyData {string|buffer|Object}
- * @param format {string}
- */
- NodeRSA.prototype.importKey = function(keyData, format) {
- pkcs8.publicImport(this.keyPair, keyData, "pem");
- };
- /**
- * Encrypting data method with public key
- *
- * @param buffer {string|number|object|array|Buffer} - data for encrypting. Object and array will convert to JSON string.
- * @param encoding {string} - optional. Encoding for output result, may be 'buffer', 'binary', 'hex' or 'base64'. Default 'buffer'.
- * @param source_encoding {string} - optional. Encoding for given string. Default utf8.
- * @returns {string|Buffer}
- */
- NodeRSA.prototype.encrypt = function(buffer, encoding, source_encoding) {
- try {
- return this.keyPair.encrypt(buffer, false);
- } catch (e) {
- throw Error('Error during encryption. Original error: ' + e);
- }
- };
- return NodeRSA;
- })();
- function createPublicKey(pem) {
- var rsa = new RsaWrap();
- pem = new Buffer(pem, "utf8");
- try {
- rsa.importKey(pem, "pkcs8-public-pem");
- } catch (ex) {
- throw "uuuum";
- }
- return rsa;
- }
- window.test = function(publicKey, verifyToken) {
- var sharedSecret = new Uint8Array(Array.from({length: 16},function(){return Math.floor(Math.random()*256);}));
- const pubKey = mcPubKeyToURsa(publicKey);
- const encryptedSharedSecretBuffer = encrypt(sharedSecret, pubKey);
- const encryptedVerifyTokenBuffer = encrypt(verifyToken, pubKey);
- console.log(encryptedSharedSecretBuffer, encryptedVerifyTokenBuffer);
- console.log(sharedSecret);
- };
- function mcPubKeyToURsa(mcPubKeyBuffer) {
- let pem = "-----BEGIN PUBLIC KEY-----\n";
- let base64PubKey = btoa(String.fromCharCode.apply(null, new Uint8Array(mcPubKeyBuffer)));
- const maxLineLength = 65;
- while (base64PubKey.length > 0) {
- pem += base64PubKey.substring(0, maxLineLength) + "\n";
- base64PubKey = base64PubKey.substring(maxLineLength);
- }
- pem += "-----END PUBLIC KEY-----\n";
- return createPublicKey(pem);
- }
- function encrypt(buf, rsa) {
- buf = new Buffer(buf, "utf8");
- rsa.setOptions({
- encryptionScheme: "pkcs1"
- });
- return rsa.encrypt(buf);
- }
- }).call(this, require("buffer").Buffer)
- }, {
- "./jsbn.js": 172,
- "./pkcs8": 171,
- "./utils": 178,
- "buffer": 46,
- "./pkcs1": 175
- }],
- 157: [function(require, module, exports) {}, {}],
- 158: [function(require, module, exports) {
- // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
- var errors = require('./errors');
- var types = require('./types');
- var Reader = require('./reader');
- var Writer = require('./writer');
- ///--- Exports
- module.exports = {
- Reader: Reader,
- Writer: Writer
- };
- for (var t in types) {
- if (types.hasOwnProperty(t))
- module.exports[t] = types[t];
- }
- for (var e in errors) {
- if (errors.hasOwnProperty(e))
- module.exports[e] = errors[e];
- }
- }, {
- "./errors": 157,
- "./reader": 159,
- "./types": 160,
- "./writer": 161
- }],
- 159: [function(require, module, exports) {
- (function(Buffer) {
- // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
- var ASN1 = require('./types');
- var errors = require('./errors');
- ///--- Globals
- var newInvalidAsn1Error = errors.newInvalidAsn1Error;
- ///--- API
- function Reader(data) {
- if (!data || !Buffer.isBuffer(data))
- throw new TypeError('data must be a node Buffer');
- this._buf = data;
- this._size = data.length;
- // These hold the "current" state
- this._len = 0;
- this._offset = 0;
- }
- Object.defineProperty(Reader.prototype, 'length', {
- enumerable: true,
- get: function() {
- return (this._len);
- }
- });
- /**
- * Reads a single byte and advances offset; you can pass in `true` to make this
- * a "peek" operation (i.e., get the byte, but don't advance the offset).
- *
- * @param {Boolean} peek true means don't move offset.
- * @return {Number} the next byte, null if not enough data.
- */
- Reader.prototype.readByte = function(peek) {
- if (this._size - this._offset < 1)
- return null;
- var b = this._buf[this._offset] & 0xff;
- if (!peek)
- this._offset += 1;
- return b;
- };
- Reader.prototype.peek = function() {
- return this.readByte(true);
- };
- /**
- * Reads a (potentially) variable length off the BER buffer. This call is
- * not really meant to be called directly, as callers have to manipulate
- * the internal buffer afterwards.
- *
- * As a result of this call, you can call `Reader.length`, until the
- * next thing called that does a readLength.
- *
- * @return {Number} the amount of offset to advance the buffer.
- * @throws {InvalidAsn1Error} on bad ASN.1
- */
- Reader.prototype.readLength = function(offset) {
- if (offset === undefined)
- offset = this._offset;
- if (offset >= this._size)
- return null;
- var lenB = this._buf[offset++] & 0xff;
- if (lenB === null)
- return null;
- if ((lenB & 0x80) == 0x80) {
- lenB &= 0x7f;
- if (lenB == 0)
- throw newInvalidAsn1Error('Indefinite length not supported');
- if (lenB > 4)
- throw newInvalidAsn1Error('encoding too long');
- if (this._size - offset < lenB)
- return null;
- this._len = 0;
- for (var i = 0; i < lenB; i++)
- this._len = (this._len << 8) + (this._buf[offset++] & 0xff);
- } else {
- // Wasn't a variable length
- this._len = lenB;
- }
- return offset;
- };
- /**
- * Parses the next sequence in this BER buffer.
- *
- * To get the length of the sequence, call `Reader.length`.
- *
- * @return {Number} the sequence's tag.
- */
- Reader.prototype.readSequence = function(tag) {
- var seq = this.peek();
- if (seq === null)
- return null;
- if (tag !== undefined && tag !== seq)
- throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) +
- ': got 0x' + seq.toString(16));
- var o = this.readLength(this._offset + 1); // stored in `length`
- if (o === null)
- return null;
- this._offset = o;
- return seq;
- };
- Reader.prototype.readString = function(tag, retbuf) {
- if (!tag)
- tag = ASN1.OctetString;
- var b = this.peek();
- if (b === null)
- return null;
- if (b !== tag)
- throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) +
- ': got 0x' + b.toString(16));
- var o = this.readLength(this._offset + 1); // stored in `length`
- if (o === null)
- return null;
- if (this.length > this._size - o)
- return null;
- this._offset = o;
- if (this.length === 0)
- return retbuf ? new Buffer(0) : '';
- var str = this._buf.slice(this._offset, this._offset + this.length);
- this._offset += this.length;
- return retbuf ? str : str.toString('utf8');
- };
- Reader.prototype.readOID = function(tag) {
- if (!tag)
- tag = ASN1.OID;
- var b = this.readString(tag, true);
- if (b === null)
- return null;
- var values = [];
- var value = 0;
- for (var i = 0; i < b.length; i++) {
- var byte = b[i] & 0xff;
- value <<= 7;
- value += byte & 0x7f;
- if ((byte & 0x80) == 0) {
- values.push(value);
- value = 0;
- }
- }
- value = values.shift();
- values.unshift(value % 40);
- values.unshift((value / 40) >> 0);
- return values.join('.');
- };
- ///--- Exported API
- module.exports = Reader;
- }).call(this, require("buffer").Buffer)
- }, {
- "./errors": 157,
- "./types": 160,
- "buffer": 46
- }],
- 160: [function(require, module, exports) {
- // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
- module.exports = {
- EOC: 0,
- Boolean: 1,
- Integer: 2,
- BitString: 3,
- OctetString: 4,
- Null: 5,
- OID: 6,
- ObjectDescriptor: 7,
- External: 8,
- Real: 9, // float
- Enumeration: 10,
- PDV: 11,
- Utf8String: 12,
- RelativeOID: 13,
- Sequence: 16,
- Set: 17,
- NumericString: 18,
- PrintableString: 19,
- T61String: 20,
- VideotexString: 21,
- IA5String: 22,
- UTCTime: 23,
- GeneralizedTime: 24,
- GraphicString: 25,
- VisibleString: 26,
- GeneralString: 28,
- UniversalString: 29,
- CharacterString: 30,
- BMPString: 31,
- Constructor: 32,
- Context: 128
- };
- }, {}],
- 161: [function(require, module, exports) {}, {}],
- 162: [function(require, module, exports) {
- // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
- // If you have no idea what ASN.1 or BER is, see this:
- // ftp://ftp.rsa.com/pub/pkcs/ascii/layman.asc
- var Ber = require('./ber/index');
- ///--- Exported API
- module.exports = {
- Ber: Ber,
- BerReader: Ber.Reader,
- BerWriter: Ber.Writer
- };
- }, {
- "./ber/index": 158
- }],
- 171: [function(require, module, exports) {
- (function(Buffer) {
- var ber = require('asn1').Ber;
- var _ = require('../utils')._;
- var PUBLIC_RSA_OID = '1.2.840.113549.1.1.1';
- module.exports = {
- publicImport: function(key, data, options) {
- options = options || {};
- var buffer;
- if (options.type !== 'der') {
- if (Buffer.isBuffer(data)) {
- data = data.toString('utf8');
- }
- if (_.isString(data)) {
- var pem = data.replace('-----BEGIN PUBLIC KEY-----', '')
- .replace('-----END PUBLIC KEY-----', '')
- .replace(/\s+|\n\r|\n|\r$/gm, '');
- buffer = new Buffer(pem, 'base64');
- }
- } else if (Buffer.isBuffer(data)) {
- buffer = data;
- } else {
- throw Error('Unsupported key format');
- }
- var reader = new ber.Reader(buffer);
- reader.readSequence();
- var header = new ber.Reader(reader.readString(0x30, true));
- if (header.readOID(0x06, true) !== PUBLIC_RSA_OID) {
- throw Error('Invalid Public key format');
- }
- var body = new ber.Reader(reader.readString(0x03, true));
- body.readByte();
- body.readSequence();
- key.setPublic(
- body.readString(0x02, true), // modulus
- body.readString(0x02, true) // publicExponent
- );
- }
- };
- }).call(this, require("buffer").Buffer)
- }, {
- "../utils": 178,
- "asn1": 162,
- "buffer": 46
- }],
- 172: [function(require, module, exports) {
- (function(Buffer) {
- /*
- * Basic JavaScript BN library - subset useful for RSA encryption.
- *
- * Copyright (c) 2003-2005 Tom Wu
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
- * IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
- * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
- * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
- * THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
- * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * In addition, the following condition applies:
- *
- * All redistributions must retain an intact copy of this copyright notice
- * and disclaimer.
- */
- /*
- * Added Node.js Buffers support
- * 2014 rzcoder
- */
- var _ = require('../utils')._;
- // Bits per digit
- var dbits;
- // JavaScript engine analysis
- var canary = 0xdeadbeefcafe;
- var j_lm = ((canary & 0xffffff) == 0xefcafe);
- // (public) Constructor
- function BigInteger(a, b) {
- if (a != null) {
- if ("number" == typeof a) {
- this.fromNumber(a, b);
- } else if (Buffer.isBuffer(a)) {
- this.fromBuffer(a);
- } else if (b == null && "string" != typeof a) {
- this.fromByteArray(a);
- } else {
- this.fromString(a, b);
- }
- }
- }
- // return new, unset BigInteger
- function nbi() {
- return new BigInteger(null);
- }
- // am: Compute w_j += (x*this_i), propagate carries,
- // c is initial carry, returns final carry.
- // c < 3*dvalue, x < 2*dvalue, this_i < dvalue
- // We need to select the fastest one that works in this environment.
- // Alternately, set max digit bits to 28 since some
- // browsers slow down when dealing with 32-bit numbers.
- function am3(i, x, w, j, c, n) {
- var xl = x & 0x3fff,
- xh = x >> 14;
- while (--n >= 0) {
- var l = this[i] & 0x3fff;
- var h = this[i++] >> 14;
- var m = xh * l + h * xl;
- l = xl * l + ((m & 0x3fff) << 14) + w[j] + c;
- c = (l >> 28) + (m >> 14) + xh * h;
- w[j++] = l & 0xfffffff;
- }
- return c;
- }
- // For node.js, we pick am3 with max dbits to 28.
- BigInteger.prototype.am = am3;
- dbits = 28;
- BigInteger.prototype.DB = dbits;
- BigInteger.prototype.DM = ((1 << dbits) - 1);
- BigInteger.prototype.DV = (1 << dbits);
- var BI_FP = 52;
- BigInteger.prototype.FV = Math.pow(2, BI_FP);
- BigInteger.prototype.F1 = BI_FP - dbits;
- BigInteger.prototype.F2 = 2 * dbits - BI_FP;
- // Digit conversions
- var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
- var BI_RC = new Array();
- var rr, vv;
- rr = "0".charCodeAt(0);
- for (vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
- rr = "a".charCodeAt(0);
- for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
- rr = "A".charCodeAt(0);
- for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
- // (protected) copy this to r
- function bnpCopyTo(r) {
- for (var i = this.t - 1; i >= 0; --i) r[i] = this[i];
- r.t = this.t;
- r.s = this.s;
- }
- // (protected) set from integer value x, -DV <= x < DV
- function bnpFromInt(x) {
- this.t = 1;
- this.s = (x < 0) ? -1 : 0;
- if (x > 0) this[0] = x;
- else if (x < -1) this[0] = x + DV;
- else this.t = 0;
- }
- // return bigint initialized to value
- function nbv(i) {
- var r = nbi();
- r.fromInt(i);
- return r;
- }
- // (protected) set from string and radix
- function bnpFromString(data, radix, unsigned) {
- var k;
- switch (radix) {
- case 2:
- k = 1;
- break;
- case 4:
- k = 2;
- break;
- case 8:
- k = 3;
- break;
- case 16:
- k = 4;
- break;
- case 32:
- k = 5;
- break;
- case 256:
- k = 8;
- break;
- default:
- this.fromRadix(data, radix);
- return;
- }
- this.t = 0;
- this.s = 0;
- var i = data.length;
- var mi = false;
- var sh = 0;
- while (--i >= 0) {
- var x = (k == 8) ? data[i] & 0xff : intAt(data, i);
- if (x < 0) {
- if (data.charAt(i) == "-") mi = true;
- continue;
- }
- mi = false;
- if (sh === 0)
- this[this.t++] = x;
- else if (sh + k > this.DB) {
- this[this.t - 1] |= (x & ((1 << (this.DB - sh)) - 1)) << sh;
- this[this.t++] = (x >> (this.DB - sh));
- } else
- this[this.t - 1] |= x << sh;
- sh += k;
- if (sh >= this.DB) sh -= this.DB;
- }
- if ((!unsigned) && k == 8 && (data[0] & 0x80) != 0) {
- this.s = -1;
- if (sh > 0) this[this.t - 1] |= ((1 << (this.DB - sh)) - 1) << sh;
- }
- this.clamp();
- if (mi) BigInteger.ZERO.subTo(this, this);
- }
- function bnpFromBuffer(a) {
- this.fromString(a, 256, true)
- }
- // (protected) clamp off excess high words
- function bnpClamp() {
- var c = this.s & this.DM;
- while (this.t > 0 && this[this.t - 1] == c) --this.t;
- }
- // (public) |this|
- function bnAbs() {
- return (this.s < 0) ? this.negate() : this;
- }
- // (public) return + if this > a, - if this < a, 0 if equal
- function bnCompareTo(a) {
- var r = this.s - a.s;
- if (r != 0) return r;
- var i = this.t;
- r = i - a.t;
- if (r != 0) return (this.s < 0) ? -r : r;
- while (--i >= 0)
- if ((r = this[i] - a[i]) != 0) return r;
- return 0;
- }
- // returns bit length of the integer x
- function nbits(x) {
- var r = 1,
- t;
- if ((t = x >>> 16) != 0) {
- x = t;
- r += 16;
- }
- if ((t = x >> 8) != 0) {
- x = t;
- r += 8;
- }
- if ((t = x >> 4) != 0) {
- x = t;
- r += 4;
- }
- if ((t = x >> 2) != 0) {
- x = t;
- r += 2;
- }
- if ((t = x >> 1) != 0) {
- x = t;
- r += 1;
- }
- return r;
- }
- // (public) return the number of bits in "this"
- function bnBitLength() {
- if (this.t <= 0) return 0;
- return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ (this.s & this.DM));
- }
- // (protected) r = this << n*DB
- function bnpDLShiftTo(n, r) {
- var i;
- for (i = this.t - 1; i >= 0; --i) r[i + n] = this[i];
- for (i = n - 1; i >= 0; --i) r[i] = 0;
- r.t = this.t + n;
- r.s = this.s;
- }
- // (protected) r = this >> n*DB
- function bnpDRShiftTo(n, r) {
- for (var i = n; i < this.t; ++i) r[i - n] = this[i];
- r.t = Math.max(this.t - n, 0);
- r.s = this.s;
- }
- // (protected) r = this << n
- function bnpLShiftTo(n, r) {
- var bs = n % this.DB;
- var cbs = this.DB - bs;
- var bm = (1 << cbs) - 1;
- var ds = Math.floor(n / this.DB),
- c = (this.s << bs) & this.DM,
- i;
- for (i = this.t - 1; i >= 0; --i) {
- r[i + ds + 1] = (this[i] >> cbs) | c;
- c = (this[i] & bm) << bs;
- }
- for (i = ds - 1; i >= 0; --i) r[i] = 0;
- r[ds] = c;
- r.t = this.t + ds + 1;
- r.s = this.s;
- r.clamp();
- }
- // (protected) r = this >> n
- function bnpRShiftTo(n, r) {
- r.s = this.s;
- var ds = Math.floor(n / this.DB);
- if (ds >= this.t) {
- r.t = 0;
- return;
- }
- var bs = n % this.DB;
- var cbs = this.DB - bs;
- var bm = (1 << bs) - 1;
- r[0] = this[ds] >> bs;
- for (var i = ds + 1; i < this.t; ++i) {
- r[i - ds - 1] |= (this[i] & bm) << cbs;
- r[i - ds] = this[i] >> bs;
- }
- if (bs > 0) r[this.t - ds - 1] |= (this.s & bm) << cbs;
- r.t = this.t - ds;
- r.clamp();
- }
- // (protected) r = this - a
- function bnpSubTo(a, r) {
- var i = 0,
- c = 0,
- m = Math.min(a.t, this.t);
- while (i < m) {
- c += this[i] - a[i];
- r[i++] = c & this.DM;
- c >>= this.DB;
- }
- if (a.t < this.t) {
- c -= a.s;
- while (i < this.t) {
- c += this[i];
- r[i++] = c & this.DM;
- c >>= this.DB;
- }
- c += this.s;
- } else {
- c += this.s;
- while (i < a.t) {
- c -= a[i];
- r[i++] = c & this.DM;
- c >>= this.DB;
- }
- c -= a.s;
- }
- r.s = (c < 0) ? -1 : 0;
- if (c < -1) r[i++] = this.DV + c;
- else if (c > 0) r[i++] = c;
- r.t = i;
- r.clamp();
- }
- // (protected) r = this * a, r != this,a (HAC 14.12)
- // "this" should be the larger one if appropriate.
- function bnpMultiplyTo(a, r) {
- var x = this.abs(),
- y = a.abs();
- var i = x.t;
- r.t = i + y.t;
- while (--i >= 0) r[i] = 0;
- for (i = 0; i < y.t; ++i) r[i + x.t] = x.am(0, y[i], r, i, 0, x.t);
- r.s = 0;
- r.clamp();
- if (this.s != a.s) BigInteger.ZERO.subTo(r, r);
- }
- // (protected) r = this^2, r != this (HAC 14.16)
- function bnpSquareTo(r) {
- var x = this.abs();
- var i = r.t = 2 * x.t;
- while (--i >= 0) r[i] = 0;
- for (i = 0; i < x.t - 1; ++i) {
- var c = x.am(i, x[i], r, 2 * i, 0, 1);
- if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) {
- r[i + x.t] -= x.DV;
- r[i + x.t + 1] = 1;
- }
- }
- if (r.t > 0) r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1);
- r.s = 0;
- r.clamp();
- }
- // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
- // r != q, this != m. q or r may be null.
- function bnpDivRemTo(m, q, r) {
- var pm = m.abs();
- if (pm.t <= 0) return;
- var pt = this.abs();
- if (pt.t < pm.t) {
- if (q != null) q.fromInt(0);
- if (r != null) this.copyTo(r);
- return;
- }
- if (r == null) r = nbi();
- var y = nbi(),
- ts = this.s,
- ms = m.s;
- var nsh = this.DB - nbits(pm[pm.t - 1]); // normalize modulus
- if (nsh > 0) {
- pm.lShiftTo(nsh, y);
- pt.lShiftTo(nsh, r);
- } else {
- pm.copyTo(y);
- pt.copyTo(r);
- }
- var ys = y.t;
- var y0 = y[ys - 1];
- if (y0 === 0) return;
- var yt = y0 * (1 << this.F1) + ((ys > 1) ? y[ys - 2] >> this.F2 : 0);
- var d1 = this.FV / yt,
- d2 = (1 << this.F1) / yt,
- e = 1 << this.F2;
- var i = r.t,
- j = i - ys,
- t = (q == null) ? nbi() : q;
- y.dlShiftTo(j, t);
- if (r.compareTo(t) >= 0) {
- r[r.t++] = 1;
- r.subTo(t, r);
- }
- BigInteger.ONE.dlShiftTo(ys, t);
- t.subTo(y, y); // "negative" y so we can replace sub with am later
- while (y.t < ys) y[y.t++] = 0;
- while (--j >= 0) {
- // Estimate quotient digit
- var qd = (r[--i] == y0) ? this.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2);
- if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) { // Try it out
- y.dlShiftTo(j, t);
- r.subTo(t, r);
- while (r[i] < --qd) r.subTo(t, r);
- }
- }
- if (q != null) {
- r.drShiftTo(ys, q);
- if (ts != ms) BigInteger.ZERO.subTo(q, q);
- }
- r.t = ys;
- r.clamp();
- if (nsh > 0) r.rShiftTo(nsh, r); // Denormalize remainder
- if (ts < 0) BigInteger.ZERO.subTo(r, r);
- }
- // (protected) return "-1/this % 2^DB"; useful for Mont. reduction
- // justification:
- // xy == 1 (mod m)
- // xy = 1+km
- // xy(2-xy) = (1+km)(1-km)
- // x[y(2-xy)] = 1-k^2m^2
- // x[y(2-xy)] == 1 (mod m^2)
- // if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
- // should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
- // JS multiply "overflows" differently from C/C++, so care is needed here.
- function bnpInvDigit() {
- if (this.t < 1) return 0;
- var x = this[0];
- if ((x & 1) === 0) return 0;
- var y = x & 3; // y == 1/x mod 2^2
- y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4
- y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8
- y = (y * (2 - (((x & 0xffff) * y) & 0xffff))) & 0xffff; // y == 1/x mod 2^16
- // last step - calculate inverse mod DV directly;
- // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
- y = (y * (2 - x * y % this.DV)) % this.DV; // y == 1/x mod 2^dbits
- // we really want the negative inverse, and -DV < y < DV
- return (y > 0) ? this.DV - y : -y;
- }
- // Montgomery reduction
- function Montgomery(m) {
- this.m = m;
- this.mp = m.invDigit();
- this.mpl = this.mp & 0x7fff;
- this.mph = this.mp >> 15;
- this.um = (1 << (m.DB - 15)) - 1;
- this.mt2 = 2 * m.t;
- }
- // xR mod m
- function montConvert(x) {
- var r = nbi();
- x.abs().dlShiftTo(this.m.t, r);
- r.divRemTo(this.m, null, r);
- if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r, r);
- return r;
- }
- // x/R mod m
- function montRevert(x) {
- var r = nbi();
- x.copyTo(r);
- this.reduce(r);
- return r;
- }
- // x = x/R mod m (HAC 14.32)
- function montReduce(x) {
- while (x.t <= this.mt2) // pad x so am has enough room later
- x[x.t++] = 0;
- for (var i = 0; i < this.m.t; ++i) {
- // faster way of calculating u0 = x[i]*mp mod DV
- var j = x[i] & 0x7fff;
- var u0 = (j * this.mpl + (((j * this.mph + (x[i] >> 15) * this.mpl) & this.um) << 15)) & x.DM;
- // use am to combine the multiply-shift-add into one call
- j = i + this.m.t;
- x[j] += this.m.am(0, u0, x, i, 0, this.m.t);
- // propagate carry
- while (x[j] >= x.DV) {
- x[j] -= x.DV;
- x[++j]++;
- }
- }
- x.clamp();
- x.drShiftTo(this.m.t, x);
- if (x.compareTo(this.m) >= 0) x.subTo(this.m, x);
- }
- // r = "x^2/R mod m"; x != r
- function montSqrTo(x, r) {
- x.squareTo(r);
- this.reduce(r);
- }
- // r = "xy/R mod m"; x,y != r
- function montMulTo(x, y, r) {
- x.multiplyTo(y, r);
- this.reduce(r);
- }
- Montgomery.prototype.convert = montConvert;
- Montgomery.prototype.revert = montRevert;
- Montgomery.prototype.reduce = montReduce;
- Montgomery.prototype.mulTo = montMulTo;
- Montgomery.prototype.sqrTo = montSqrTo;
- // (protected) true iff this is even
- function bnpIsEven() {
- return ((this.t > 0) ? (this[0] & 1) : this.s) === 0;
- }
- // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
- function bnpExp(e, z) {
- if (e > 0xffffffff || e < 1) return BigInteger.ONE;
- var r = nbi(),
- r2 = nbi(),
- g = z.convert(this),
- i = nbits(e) - 1;
- g.copyTo(r);
- while (--i >= 0) {
- z.sqrTo(r, r2);
- if ((e & (1 << i)) > 0) z.mulTo(r2, g, r);
- else {
- var t = r;
- r = r2;
- r2 = t;
- }
- }
- return z.revert(r);
- }
- // (public) this^e % m, 0 <= e < 2^32
- function bnModPowInt(e, m) {
- var z;
- if (e < 256 || m.isEven()) z = new Classic(m);
- else z = new Montgomery(m);
- return this.exp(e, z);
- }
- // Copyright (c) 2005-2009 Tom Wu
- // All Rights Reserved.
- // See "LICENSE" for details.
- // Extended JavaScript BN functions, required for RSA private ops.
- // Version 1.1: new BigInteger("0", 10) returns "proper" zero
- // Version 1.2: square() API, isProbablePrime fix
- //(public) convert to bigendian byte array
- function bnToByteArray() {
- var i = this.t,
- r = new Array();
- r[0] = this.s;
- var p = this.DB - (i * this.DB) % 8,
- d, k = 0;
- if (i-- > 0) {
- if (p < this.DB && (d = this[i] >> p) != (this.s & this.DM) >> p)
- r[k++] = d | (this.s << (this.DB - p));
- while (i >= 0) {
- if (p < 8) {
- d = (this[i] & ((1 << p) - 1)) << (8 - p);
- d |= this[--i] >> (p += this.DB - 8);
- } else {
- d = (this[i] >> (p -= 8)) & 0xff;
- if (p <= 0) {
- p += this.DB;
- --i;
- }
- }
- if ((d & 0x80) != 0) d |= -256;
- if (k === 0 && (this.s & 0x80) != (d & 0x80)) ++k;
- if (k > 0 || d != this.s) r[k++] = d;
- }
- }
- return r;
- }
- /**
- * return Buffer object
- * @param trim {boolean} slice buffer if first element == 0
- * @returns {Buffer}
- */
- function bnToBuffer(trimOrSize) {
- var res = new Buffer(this.toByteArray());
- if (trimOrSize === true && res[0] === 0) {
- res = res.slice(1);
- } else if (_.isNumber(trimOrSize)) {
- if (res.length > trimOrSize) {
- for (var i = 0; i < res.length - trimOrSize; i++) {
- if (res[i] !== 0) {
- return null;
- }
- }
- return res.slice(res.length - trimOrSize);
- } else if (res.length < trimOrSize) {
- var padded = new Buffer(trimOrSize);
- padded.fill(0, 0, trimOrSize - res.length);
- res.copy(padded, trimOrSize - res.length);
- return padded;
- }
- }
- return res;
- }
- var lowprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997];
- var lplim = (1 << 26) / lowprimes[lowprimes.length - 1];
- // protected
- BigInteger.prototype.copyTo = bnpCopyTo;
- BigInteger.prototype.fromInt = bnpFromInt;
- BigInteger.prototype.fromString = bnpFromString;
- BigInteger.prototype.fromBuffer = bnpFromBuffer;
- BigInteger.prototype.clamp = bnpClamp;
- BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
- BigInteger.prototype.drShiftTo = bnpDRShiftTo;
- BigInteger.prototype.lShiftTo = bnpLShiftTo;
- BigInteger.prototype.rShiftTo = bnpRShiftTo;
- BigInteger.prototype.subTo = bnpSubTo;
- BigInteger.prototype.multiplyTo = bnpMultiplyTo;
- BigInteger.prototype.squareTo = bnpSquareTo;
- BigInteger.prototype.divRemTo = bnpDivRemTo;
- BigInteger.prototype.invDigit = bnpInvDigit;
- BigInteger.prototype.isEven = bnpIsEven;
- BigInteger.prototype.exp = bnpExp;
- // public
- BigInteger.prototype.bitLength = bnBitLength;
- BigInteger.prototype.modPowInt = bnModPowInt;
- BigInteger.prototype.abs = bnAbs;
- BigInteger.prototype.compareTo = bnCompareTo;
- BigInteger.prototype.toBuffer = bnToBuffer;
- BigInteger.prototype.toByteArray = bnToByteArray;
- // "constants"
- BigInteger.ZERO = nbv(0);
- BigInteger.ONE = nbv(1);
- // JSBN-specific extension
- //BigInteger interfaces not implemented in jsbn:
- //BigInteger(int signum, byte[] magnitude)
- //double doubleValue()
- //float floatValue()
- //int hashCode()
- //long longValue()
- //static BigInteger valueOf(long val)
- module.exports = BigInteger;
- }).call(this, require("buffer").Buffer)
- }, {
- "../utils": 178,
- "buffer": 46
- }],
- 174: [function(require, module, exports) {}, {}],
- 175: [function(require, module, exports) {
- (function(Buffer) {
- /**
- * PKCS1 padding and signature scheme
- */
- var BigInteger = require('../libs/jsbn');
- var crypt = require('crypto');
- var SIGN_INFO_HEAD = {
- md2: new Buffer('3020300c06082a864886f70d020205000410', 'hex'),
- md5: new Buffer('3020300c06082a864886f70d020505000410', 'hex'),
- sha1: new Buffer('3021300906052b0e03021a05000414', 'hex'),
- sha224: new Buffer('302d300d06096086480165030402040500041c', 'hex'),
- sha256: new Buffer('3031300d060960864801650304020105000420', 'hex'),
- sha384: new Buffer('3041300d060960864801650304020205000430', 'hex'),
- sha512: new Buffer('3051300d060960864801650304020305000440', 'hex'),
- ripemd160: new Buffer('3021300906052b2403020105000414', 'hex'),
- rmd160: new Buffer('3021300906052b2403020105000414', 'hex')
- };
- var SIGN_ALG_TO_HASH_ALIASES = {
- 'ripemd160': 'rmd160'
- };
- var DEFAULT_HASH_FUNCTION = 'sha256';
- module.exports = {
- isEncryption: true,
- isSignature: true
- };
- module.exports.makeScheme = function(key, options) {
- function Scheme(key, options) {
- this.key = key;
- this.options = options;
- }
- Scheme.prototype.maxMessageLength = function() {
- if (this.options.encryptionSchemeOptions && this.options.encryptionSchemeOptions.padding == 3) {
- return this.key.encryptedDataLength;
- }
- return this.key.encryptedDataLength - 11;
- };
- /**
- * Pad input Buffer to encryptedDataLength bytes, and return new Buffer
- * alg: PKCS#1
- * @param buffer
- * @returns {Buffer}
- */
- Scheme.prototype.encPad = function(buffer, options) {
- options = options || {};
- var filled;
- if (buffer.length > this.key.maxMessageLength) {
- throw new Error("Message too long for RSA (n=" + this.key.encryptedDataLength + ", l=" + buffer.length + ")");
- }
- if (this.options.encryptionSchemeOptions && this.options.encryptionSchemeOptions.padding == 3) {
- //RSA_NO_PADDING treated like JAVA left pad with zero character
- return this.pkcs0pad(buffer);
- }
- /* Type 1: zeros padding for private key encrypt */
- if (options.type === 1) {
- filled = new Buffer(this.key.encryptedDataLength - buffer.length - 1);
- filled.fill(0xff, 0, filled.length - 1);
- filled[0] = 1;
- filled[filled.length - 1] = 0;
- return Buffer.concat([filled, buffer]);
- } else {
- /* random padding for public key encrypt */
- filled = new Buffer(this.key.encryptedDataLength - buffer.length);
- filled[0] = 0;
- filled[1] = 2;
- var rand = crypt.randomBytes(filled.length - 3);
- for (var i = 0; i < rand.length; i++) {
- var r = rand[i];
- while (r === 0) { // non-zero only
- r = crypt.randomBytes(1)[0];
- }
- filled[i + 2] = r;
- }
- filled[filled.length - 1] = 0;
- return Buffer.concat([filled, buffer]);
- }
- };
- return new Scheme(key, options);
- };
- }).call(this, require("buffer").Buffer)
- }, {
- "../libs/jsbn": 172,
- "buffer": 46,
- "crypto": 56
- }],
- 178: [function(require, module, exports) {
- /**
- * Trying get a 32-bit unsigned integer from the partial buffer
- * @param buffer
- * @param offset
- * @returns {Number}
- */
- module.exports.get32IntFromBuffer = function(buffer, offset) {
- offset = offset || 0;
- var size = 0;
- if ((size = buffer.length - offset) > 0) {
- if (size >= 4) {
- return buffer.readUInt32BE(offset);
- } else {
- var res = 0;
- for (var i = offset + size, d = 0; i > offset; i--, d += 2) {
- res += buffer[i - 1] * Math.pow(16, d);
- }
- return res;
- }
- } else {
- return NaN;
- }
- };
- module.exports._ = {
- isString: function(value) {
- return typeof value == 'string' || value instanceof String;
- },
- isNumber: function(value) {
- return typeof value == 'number' || !isNaN(parseFloat(value)) && isFinite(value);
- }
- };
- }, {}]
- }, {}, [156]);
Add Comment
Please, Sign In to add comment