Guest User

Untitled

a guest
Jun 28th, 2017
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function e(t, n, r) {
  2.     function s(o, u) {
  3.         if (!n[o]) {
  4.             if (!t[o]) {
  5.                 var a = typeof require == "function" && require;
  6.                 if (!u && a) return a(o, !0);
  7.                 if (i) return i(o, !0);
  8.                 var f = new Error("Cannot find module '" + o + "'");
  9.                 throw f.code = "MODULE_NOT_FOUND", f
  10.             }
  11.             var l = n[o] = {
  12.                 exports: {}
  13.             };
  14.             t[o][0].call(l.exports, function(e) {
  15.                 var n = t[o][1][e];
  16.                 return s(n ? n : e)
  17.             }, l, l.exports, e, t, n, r)
  18.         }
  19.         return n[o].exports
  20.     }
  21.     var i = typeof require == "function" && require;
  22.     for (var o = 0; o < r.length; o++) s(r[o]);
  23.     return s
  24. })({
  25.     16: [function(require, module, exports) {
  26.         'use strict'
  27.  
  28.         exports.toByteArray = toByteArray
  29.  
  30.         var lookup = []
  31.         var revLookup = []
  32.         var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  33.  
  34.         var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  35.         for (var i = 0, len = code.length; i < len; ++i) {
  36.             lookup[i] = code[i]
  37.             revLookup[code.charCodeAt(i)] = i
  38.         }
  39.  
  40.         revLookup['-'.charCodeAt(0)] = 62
  41.         revLookup['_'.charCodeAt(0)] = 63
  42.  
  43.         function placeHoldersCount(b64) {
  44.             var len = b64.length
  45.             if (len % 4 > 0) {
  46.                 throw new Error('Invalid string. Length must be a multiple of 4')
  47.             }
  48.  
  49.             // the number of equal signs (place holders)
  50.             // if there are two placeholders, than the two characters before it
  51.             // represent one byte
  52.             // if there is only one, then the three characters before it represent 2 bytes
  53.             // this is just a cheap hack to not do indexOf twice
  54.             return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
  55.         }
  56.  
  57.         function toByteArray(b64) {
  58.             var i, l, tmp, placeHolders, arr
  59.             var len = b64.length
  60.             placeHolders = placeHoldersCount(b64)
  61.  
  62.             arr = new Arr((len * 3 / 4) - placeHolders)
  63.  
  64.             // if there are placeholders, only get up to the last complete 4 chars
  65.             l = placeHolders > 0 ? len - 4 : len
  66.  
  67.             var L = 0
  68.  
  69.             for (i = 0; i < l; i += 4) {
  70.                 tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
  71.                 arr[L++] = (tmp >> 16) & 0xFF
  72.                 arr[L++] = (tmp >> 8) & 0xFF
  73.                 arr[L++] = tmp & 0xFF
  74.             }
  75.  
  76.             if (placeHolders === 2) {
  77.                 tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
  78.                 arr[L++] = tmp & 0xFF
  79.             } else if (placeHolders === 1) {
  80.                 tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
  81.                 arr[L++] = (tmp >> 8) & 0xFF
  82.                 arr[L++] = tmp & 0xFF
  83.             }
  84.  
  85.             return arr
  86.         }
  87.     }, {}],
  88.     46: [function(require, module, exports) {
  89.         /*!
  90.          * The buffer module from node.js, for the browser.
  91.          *
  92.          * @author   Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  93.          * @license  MIT
  94.          */
  95.         /* eslint-disable no-proto */
  96.  
  97.         'use strict'
  98.  
  99.         var base64 = require('base64-js')
  100.  
  101.         exports.Buffer = Buffer
  102.         exports.INSPECT_MAX_BYTES = 50
  103.  
  104.         var K_MAX_LENGTH = 0x7fffffff
  105.         exports.kMaxLength = K_MAX_LENGTH
  106.  
  107.         /**
  108.          * If `Buffer.TYPED_ARRAY_SUPPORT`:
  109.          *   === true    Use Uint8Array implementation (fastest)
  110.          *   === false   Print warning and recommend using `buffer` v4.x which has an Object
  111.          *               implementation (most compatible, even IE6)
  112.          *
  113.          * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  114.          * Opera 11.6+, iOS 4.2+.
  115.          *
  116.          * We report that the browser does not support typed arrays if the are not subclassable
  117.          * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
  118.          * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
  119.          * for __proto__ and has a buggy typed array implementation.
  120.          */
  121.         Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
  122.  
  123.         if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
  124.             typeof console.error === 'function') {
  125.             console.error(
  126.                 'This browser lacks typed array (Uint8Array) support which is required by ' +
  127.                 '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
  128.             )
  129.         }
  130.  
  131.         function typedArraySupport() {
  132.             // Can typed array instances can be augmented?
  133.             try {
  134.                 var arr = new Uint8Array(1)
  135.                 arr.__proto__ = {
  136.                     __proto__: Uint8Array.prototype,
  137.                     foo: function() {
  138.                         return 42
  139.                     }
  140.                 }
  141.                 return arr.foo() === 42
  142.             } catch (e) {
  143.                 return false
  144.             }
  145.         }
  146.  
  147.         function createBuffer(length) {
  148.             if (length > K_MAX_LENGTH) {
  149.                 throw new RangeError('Invalid typed array length')
  150.             }
  151.             // Return an augmented `Uint8Array` instance
  152.             var buf = new Uint8Array(length)
  153.             buf.__proto__ = Buffer.prototype
  154.             return buf
  155.         }
  156.  
  157.         /**
  158.          * The Buffer constructor returns instances of `Uint8Array` that have their
  159.          * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  160.          * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  161.          * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  162.          * returns a single octet.
  163.          *
  164.          * The `Uint8Array` prototype remains unmodified.
  165.          */
  166.  
  167.         function Buffer(arg, encodingOrOffset, length) {
  168.             // Common case.
  169.             if (typeof arg === 'number') {
  170.                 if (typeof encodingOrOffset === 'string') {
  171.                     throw new Error(
  172.                         'If encoding is specified then the first argument must be a string'
  173.                     )
  174.                 }
  175.                 return allocUnsafe(arg)
  176.             }
  177.             return from(arg, encodingOrOffset, length)
  178.         }
  179.  
  180.         // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  181.         if (typeof Symbol !== 'undefined' && Symbol.species &&
  182.             Buffer[Symbol.species] === Buffer) {
  183.             Object.defineProperty(Buffer, Symbol.species, {
  184.                 value: null,
  185.                 configurable: true,
  186.                 enumerable: false,
  187.                 writable: false
  188.             })
  189.         }
  190.  
  191.         Buffer.poolSize = 8192 // not used by this implementation
  192.  
  193.         function from(value, encodingOrOffset, length) {
  194.             if (typeof value === 'number') {
  195.                 throw new TypeError('"value" argument must not be a number')
  196.             }
  197.  
  198.             if (value instanceof ArrayBuffer) {
  199.                 return fromArrayBuffer(value, encodingOrOffset, length)
  200.             }
  201.  
  202.             if (typeof value === 'string') {
  203.                 return fromString(value, encodingOrOffset)
  204.             }
  205.  
  206.             return fromObject(value)
  207.         }
  208.  
  209.         // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
  210.         // https://github.com/feross/buffer/pull/148
  211.         Buffer.prototype.__proto__ = Uint8Array.prototype
  212.         Buffer.__proto__ = Uint8Array
  213.  
  214.         function assertSize(size) {
  215.             if (typeof size !== 'number') {
  216.                 throw new TypeError('"size" argument must be a number')
  217.             } else if (size < 0) {
  218.                 throw new RangeError('"size" argument must not be negative')
  219.             }
  220.         }
  221.  
  222.         function allocUnsafe(size) {
  223.             assertSize(size)
  224.             return createBuffer(size < 0 ? 0 : checked(size) | 0)
  225.         }
  226.  
  227.         /**
  228.          * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  229.          * */
  230.         Buffer.allocUnsafe = function(size) {
  231.             return allocUnsafe(size)
  232.         }
  233.        
  234.         function fromString(string, encoding) {
  235.             if (typeof encoding !== 'string' || encoding === '') {
  236.                 encoding = 'utf8'
  237.             }
  238.  
  239.             if (!Buffer.isEncoding(encoding)) {
  240.                 throw new TypeError('"encoding" must be a valid string encoding')
  241.             }
  242.  
  243.             var length = byteLength(string, encoding) | 0
  244.             var buf = createBuffer(length)
  245.  
  246.             var actual = buf.write(string, encoding)
  247.  
  248.             if (actual !== length) {
  249.                 // Writing a hex string, for example, that contains invalid characters will
  250.                 // cause everything after the first invalid character to be ignored. (e.g.
  251.                 // 'abxxcd' will be treated as 'ab')
  252.                 buf = buf.slice(0, actual)
  253.             }
  254.  
  255.             return buf
  256.         }
  257.  
  258.         function fromArrayLike(array) {
  259.             var length = array.length < 0 ? 0 : checked(array.length) | 0
  260.             var buf = createBuffer(length)
  261.             for (var i = 0; i < length; i += 1) {
  262.                 buf[i] = array[i] & 255
  263.             }
  264.             return buf
  265.         }
  266.  
  267.         function fromArrayBuffer(array, byteOffset, length) {
  268.             if (byteOffset < 0 || array.byteLength < byteOffset) {
  269.                 throw new RangeError('\'offset\' is out of bounds')
  270.             }
  271.  
  272.             if (array.byteLength < byteOffset + (length || 0)) {
  273.                 throw new RangeError('\'length\' is out of bounds')
  274.             }
  275.  
  276.             var buf
  277.             if (byteOffset === undefined && length === undefined) {
  278.                 buf = new Uint8Array(array)
  279.             } else if (length === undefined) {
  280.                 buf = new Uint8Array(array, byteOffset)
  281.             } else {
  282.                 buf = new Uint8Array(array, byteOffset, length)
  283.             }
  284.  
  285.             // Return an augmented `Uint8Array` instance
  286.             buf.__proto__ = Buffer.prototype
  287.             return buf
  288.         }
  289.  
  290.         function fromObject(obj) {
  291.             if (Buffer.isBuffer(obj)) {
  292.                 var len = checked(obj.length) | 0
  293.                 var buf = createBuffer(len)
  294.  
  295.                 if (buf.length === 0) {
  296.                     return buf
  297.                 }
  298.  
  299.                 obj.copy(buf, 0, 0, len)
  300.                 return buf
  301.             }
  302.  
  303.             if (obj) {
  304.                 if (isArrayBufferView(obj) || 'length' in obj) {
  305.                     if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
  306.                         return createBuffer(0)
  307.                     }
  308.                     return fromArrayLike(obj)
  309.                 }
  310.  
  311.                 if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
  312.                     return fromArrayLike(obj.data)
  313.                 }
  314.             }
  315.  
  316.             throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  317.         }
  318.  
  319.         function checked(length) {
  320.             // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  321.             // length is NaN (which is otherwise coerced to zero.)
  322.             if (length >= K_MAX_LENGTH) {
  323.                 throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  324.                     'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
  325.             }
  326.             return length | 0
  327.         }
  328.  
  329.         Buffer.isBuffer = function isBuffer(b) {
  330.             return b != null && b._isBuffer === true
  331.         }
  332.  
  333.         Buffer.isEncoding = function isEncoding(encoding) {
  334.             switch (String(encoding).toLowerCase()) {
  335.                 case 'hex':
  336.                 case 'utf8':
  337.                 case 'utf-8':
  338.                 case 'ascii':
  339.                 case 'latin1':
  340.                 case 'binary':
  341.                 case 'base64':
  342.                 case 'ucs2':
  343.                 case 'ucs-2':
  344.                 case 'utf16le':
  345.                 case 'utf-16le':
  346.                     return true
  347.                 default:
  348.                     return false
  349.             }
  350.         }
  351.  
  352.         Buffer.concat = function concat(list, length) {
  353.             if (!Array.isArray(list)) {
  354.                 throw new TypeError('"list" argument must be an Array of Buffers')
  355.             }
  356.  
  357.             if (list.length === 0) {
  358.                 return Buffer.alloc(0)
  359.             }
  360.  
  361.             var i
  362.             if (length === undefined) {
  363.                 length = 0
  364.                 for (i = 0; i < list.length; ++i) {
  365.                     length += list[i].length
  366.                 }
  367.             }
  368.  
  369.             var buffer = Buffer.allocUnsafe(length)
  370.             var pos = 0
  371.             for (i = 0; i < list.length; ++i) {
  372.                 var buf = list[i]
  373.                 if (!Buffer.isBuffer(buf)) {
  374.                     throw new TypeError('"list" argument must be an Array of Buffers')
  375.                 }
  376.                 buf.copy(buffer, pos)
  377.                 pos += buf.length
  378.             }
  379.             return buffer
  380.         }
  381.  
  382.         function byteLength(string, encoding) {
  383.             if (Buffer.isBuffer(string)) {
  384.                 return string.length
  385.             }
  386.             if (isArrayBufferView(string) || string instanceof ArrayBuffer) {
  387.                 return string.byteLength
  388.             }
  389.             if (typeof string !== 'string') {
  390.                 string = '' + string
  391.             }
  392.  
  393.             var len = string.length
  394.             if (len === 0) return 0
  395.  
  396.             // Use a for loop to avoid recursion
  397.             var loweredCase = false
  398.             for (;;) {
  399.                 switch (encoding) {
  400.                     case 'ascii':
  401.                     case 'latin1':
  402.                     case 'binary':
  403.                         return len
  404.                     case 'utf8':
  405.                     case 'utf-8':
  406.                     case undefined:
  407.                         return utf8ToBytes(string).length
  408.                     case 'ucs2':
  409.                     case 'ucs-2':
  410.                     case 'utf16le':
  411.                     case 'utf-16le':
  412.                         return len * 2
  413.                     case 'hex':
  414.                         return len >>> 1
  415.                     case 'base64':
  416.                         return base64ToBytes(string).length
  417.                     default:
  418.                         if (loweredCase) return utf8ToBytes(string).length // assume utf8
  419.                         encoding = ('' + encoding).toLowerCase()
  420.                         loweredCase = true
  421.                 }
  422.             }
  423.         }
  424.         Buffer.byteLength = byteLength
  425.  
  426.         function slowToString(encoding, start, end) {
  427.             var loweredCase = false
  428.  
  429.             // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  430.             // property of a typed array.
  431.  
  432.             // This behaves neither like String nor Uint8Array in that we set start/end
  433.             // to their upper/lower bounds if the value passed is out of range.
  434.             // undefined is handled specially as per ECMA-262 6th Edition,
  435.             // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  436.             if (start === undefined || start < 0) {
  437.                 start = 0
  438.             }
  439.             // Return early if start > this.length. Done here to prevent potential uint32
  440.             // coercion fail below.
  441.             if (start > this.length) {
  442.                 return ''
  443.             }
  444.  
  445.             if (end === undefined || end > this.length) {
  446.                 end = this.length
  447.             }
  448.  
  449.             if (end <= 0) {
  450.                 return ''
  451.             }
  452.  
  453.             // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  454.             end >>>= 0
  455.             start >>>= 0
  456.  
  457.             if (end <= start) {
  458.                 return ''
  459.             }
  460.  
  461.             if (!encoding) encoding = 'utf8'
  462.  
  463.             while (true) {
  464.                 switch (encoding) {
  465.                     case 'hex':
  466.                         return hexSlice(this, start, end)
  467.  
  468.                     case 'utf8':
  469.                     case 'utf-8':
  470.                         return utf8Slice(this, start, end)
  471.  
  472.                     case 'ascii':
  473.                         return asciiSlice(this, start, end)
  474.  
  475.                     case 'latin1':
  476.                     case 'binary':
  477.                         return latin1Slice(this, start, end)
  478.  
  479.                     case 'base64':
  480.                         return base64Slice(this, start, end)
  481.  
  482.                     case 'ucs2':
  483.                     case 'ucs-2':
  484.                     case 'utf16le':
  485.                     case 'utf-16le':
  486.                         return utf16leSlice(this, start, end)
  487.  
  488.                     default:
  489.                         if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  490.                         encoding = (encoding + '').toLowerCase()
  491.                         loweredCase = true
  492.                 }
  493.             }
  494.         }
  495.  
  496.         // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
  497.         // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
  498.         // reliably in a browserify context because there could be multiple different
  499.         // copies of the 'buffer' package in use. This method works even for Buffer
  500.         // instances that were created from another copy of the `buffer` package.
  501.         // See: https://github.com/feross/buffer/issues/154
  502.         Buffer.prototype._isBuffer = true
  503.  
  504.         Buffer.prototype.toString = function toString() {
  505.             var length = this.length
  506.             if (length === 0) return ''
  507.             if (arguments.length === 0) return utf8Slice(this, 0, length)
  508.             return slowToString.apply(this, arguments)
  509.         }
  510.  
  511.        
  512.         function hexWrite(buf, string, offset, length) {
  513.             offset = Number(offset) || 0
  514.             var remaining = buf.length - offset
  515.             if (!length) {
  516.                 length = remaining
  517.             } else {
  518.                 length = Number(length)
  519.                 if (length > remaining) {
  520.                     length = remaining
  521.                 }
  522.             }
  523.  
  524.             // must be an even number of digits
  525.             var strLen = string.length
  526.             if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
  527.  
  528.             if (length > strLen / 2) {
  529.                 length = strLen / 2
  530.             }
  531.             for (var i = 0; i < length; ++i) {
  532.                 var parsed = parseInt(string.substr(i * 2, 2), 16)
  533.                 if (numberIsNaN(parsed)) return i
  534.                 buf[offset + i] = parsed
  535.             }
  536.             return i
  537.         }
  538.  
  539.         function utf8Write(buf, string, offset, length) {
  540.             return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  541.         }
  542.  
  543.         function base64Write(buf, string, offset, length) {
  544.             return blitBuffer(base64ToBytes(string), buf, offset, length)
  545.         }
  546.  
  547.         Buffer.prototype.write = function write(string, offset, length, encoding) {
  548.             // Buffer#write(string)
  549.             if (offset === undefined) {
  550.                 encoding = 'utf8'
  551.                 length = this.length
  552.                 offset = 0
  553.                 // Buffer#write(string, encoding)
  554.             } else if (length === undefined && typeof offset === 'string') {
  555.                 encoding = offset
  556.                 length = this.length
  557.                 offset = 0
  558.                 // Buffer#write(string, offset[, length][, encoding])
  559.             } else if (isFinite(offset)) {
  560.                 offset = offset >>> 0
  561.                 if (isFinite(length)) {
  562.                     length = length >>> 0
  563.                     if (encoding === undefined) encoding = 'utf8'
  564.                 } else {
  565.                     encoding = length
  566.                     length = undefined
  567.                 }
  568.             } else {
  569.                 throw new Error(
  570.                     'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  571.                 )
  572.             }
  573.  
  574.             var remaining = this.length - offset
  575.             if (length === undefined || length > remaining) length = remaining
  576.  
  577.             if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  578.                 throw new RangeError('Attempt to write outside buffer bounds')
  579.             }
  580.  
  581.             if (!encoding) encoding = 'utf8'
  582.  
  583.             var loweredCase = false
  584.             for (;;) {
  585.                 switch (encoding) {
  586.                     case 'hex':
  587.                         return hexWrite(this, string, offset, length)
  588.  
  589.                     case 'utf8':
  590.                     case 'utf-8':
  591.                         return utf8Write(this, string, offset, length)
  592.  
  593.                     case 'ascii':
  594.                         return asciiWrite(this, string, offset, length)
  595.  
  596.                     case 'latin1':
  597.                     case 'binary':
  598.                         return latin1Write(this, string, offset, length)
  599.  
  600.                     case 'base64':
  601.                         // Warning: maxLength not taken into account in base64Write
  602.                         return base64Write(this, string, offset, length)
  603.  
  604.                     case 'ucs2':
  605.                     case 'ucs-2':
  606.                     case 'utf16le':
  607.                     case 'utf-16le':
  608.                         return ucs2Write(this, string, offset, length)
  609.  
  610.                     default:
  611.                         if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  612.                         encoding = ('' + encoding).toLowerCase()
  613.                         loweredCase = true
  614.                 }
  615.             }
  616.         }
  617.  
  618.         function utf8Slice(buf, start, end) {
  619.             end = Math.min(buf.length, end)
  620.             var res = []
  621.  
  622.             var i = start
  623.             while (i < end) {
  624.                 var firstByte = buf[i]
  625.                 var codePoint = null
  626.                 var bytesPerSequence = (firstByte > 0xEF) ? 4 :
  627.                     (firstByte > 0xDF) ? 3 :
  628.                     (firstByte > 0xBF) ? 2 :
  629.                     1
  630.  
  631.                 if (i + bytesPerSequence <= end) {
  632.                     var secondByte, thirdByte, fourthByte, tempCodePoint
  633.  
  634.                     switch (bytesPerSequence) {
  635.                         case 1:
  636.                             if (firstByte < 0x80) {
  637.                                 codePoint = firstByte
  638.                             }
  639.                             break
  640.                         case 2:
  641.                             secondByte = buf[i + 1]
  642.                             if ((secondByte & 0xC0) === 0x80) {
  643.                                 tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  644.                                 if (tempCodePoint > 0x7F) {
  645.                                     codePoint = tempCodePoint
  646.                                 }
  647.                             }
  648.                             break
  649.                         case 3:
  650.                             secondByte = buf[i + 1]
  651.                             thirdByte = buf[i + 2]
  652.                             if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  653.                                 tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  654.                                 if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  655.                                     codePoint = tempCodePoint
  656.                                 }
  657.                             }
  658.                             break
  659.                         case 4:
  660.                             secondByte = buf[i + 1]
  661.                             thirdByte = buf[i + 2]
  662.                             fourthByte = buf[i + 3]
  663.                             if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  664.                                 tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  665.                                 if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  666.                                     codePoint = tempCodePoint
  667.                                 }
  668.                             }
  669.                     }
  670.                 }
  671.  
  672.                 if (codePoint === null) {
  673.                     // we did not generate a valid codePoint so insert a
  674.                     // replacement char (U+FFFD) and advance only 1 byte
  675.                     codePoint = 0xFFFD
  676.                     bytesPerSequence = 1
  677.                 } else if (codePoint > 0xFFFF) {
  678.                     // encode to utf16 (surrogate pair dance)
  679.                     codePoint -= 0x10000
  680.                     res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  681.                     codePoint = 0xDC00 | codePoint & 0x3FF
  682.                 }
  683.  
  684.                 res.push(codePoint)
  685.                 i += bytesPerSequence
  686.             }
  687.  
  688.             return decodeCodePointsArray(res)
  689.         }
  690.  
  691.         // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  692.         // the lowest limit is Chrome, with 0x10000 args.
  693.         // We go 1 magnitude less, for safety
  694.         var MAX_ARGUMENTS_LENGTH = 0x1000
  695.  
  696.         function decodeCodePointsArray(codePoints) {
  697.             var len = codePoints.length
  698.             if (len <= MAX_ARGUMENTS_LENGTH) {
  699.                 return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  700.             }
  701.  
  702.             // Decode in chunks to avoid "call stack size exceeded".
  703.             var res = ''
  704.             var i = 0
  705.             while (i < len) {
  706.                 res += String.fromCharCode.apply(
  707.                     String,
  708.                     codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  709.                 )
  710.             }
  711.             return res
  712.         }
  713.  
  714.         Buffer.prototype.slice = function slice(start, end) {
  715.             var len = this.length
  716.             start = ~~start
  717.             end = end === undefined ? len : ~~end
  718.  
  719.             if (start < 0) {
  720.                 start += len
  721.                 if (start < 0) start = 0
  722.             } else if (start > len) {
  723.                 start = len
  724.             }
  725.  
  726.             if (end < 0) {
  727.                 end += len
  728.                 if (end < 0) end = 0
  729.             } else if (end > len) {
  730.                 end = len
  731.             }
  732.  
  733.             if (end < start) end = start
  734.  
  735.             var newBuf = this.subarray(start, end)
  736.             // Return an augmented `Uint8Array` instance
  737.             newBuf.__proto__ = Buffer.prototype
  738.             return newBuf
  739.         }
  740.  
  741.         // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  742.         Buffer.prototype.copy = function copy(target, targetStart, start, end) {
  743.             if (!start) start = 0
  744.             if (!end && end !== 0) end = this.length
  745.             if (targetStart >= target.length) targetStart = target.length
  746.             if (!targetStart) targetStart = 0
  747.             if (end > 0 && end < start) end = start
  748.  
  749.             // Copy 0 bytes; we're done
  750.             if (end === start) return 0
  751.             if (target.length === 0 || this.length === 0) return 0
  752.  
  753.             // Fatal error conditions
  754.             if (targetStart < 0) {
  755.                 throw new RangeError('targetStart out of bounds')
  756.             }
  757.             if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  758.             if (end < 0) throw new RangeError('sourceEnd out of bounds')
  759.  
  760.             // Are we oob?
  761.             if (end > this.length) end = this.length
  762.             if (target.length - targetStart < end - start) {
  763.                 end = target.length - targetStart + start
  764.             }
  765.  
  766.             var len = end - start
  767.             var i
  768.  
  769.             if (this === target && start < targetStart && targetStart < end) {
  770.                 // descending copy from end
  771.                 for (i = len - 1; i >= 0; --i) {
  772.                     target[i + targetStart] = this[i + start]
  773.                 }
  774.             } else if (len < 1000) {
  775.                 // ascending copy from start
  776.                 for (i = 0; i < len; ++i) {
  777.                     target[i + targetStart] = this[i + start]
  778.                 }
  779.             } else {
  780.                 Uint8Array.prototype.set.call(
  781.                     target,
  782.                     this.subarray(start, start + len),
  783.                     targetStart
  784.                 )
  785.             }
  786.  
  787.             return len
  788.         }
  789.  
  790.         // HELPER FUNCTIONS
  791.         // ================
  792.  
  793.         var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
  794.  
  795.         function base64clean(str) {
  796.             // Node strips out invalid characters like \n and \t from the string, base64-js does not
  797.             str = str.trim().replace(INVALID_BASE64_RE, '')
  798.             // Node converts strings with length < 2 to ''
  799.             if (str.length < 2) return ''
  800.             // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  801.             while (str.length % 4 !== 0) {
  802.                 str = str + '='
  803.             }
  804.             return str
  805.         }
  806.  
  807.         function utf8ToBytes(string, units) {
  808.             units = units || Infinity
  809.             var codePoint
  810.             var length = string.length
  811.             var leadSurrogate = null
  812.             var bytes = []
  813.  
  814.             for (var i = 0; i < length; ++i) {
  815.                 codePoint = string.charCodeAt(i)
  816.  
  817.                 // is surrogate component
  818.                 if (codePoint > 0xD7FF && codePoint < 0xE000) {
  819.                     // last char was a lead
  820.                     if (!leadSurrogate) {
  821.                         // no lead yet
  822.                         if (codePoint > 0xDBFF) {
  823.                             // unexpected trail
  824.                             if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  825.                             continue
  826.                         } else if (i + 1 === length) {
  827.                             // unpaired lead
  828.                             if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  829.                             continue
  830.                         }
  831.  
  832.                         // valid lead
  833.                         leadSurrogate = codePoint
  834.  
  835.                         continue
  836.                     }
  837.  
  838.                     // 2 leads in a row
  839.                     if (codePoint < 0xDC00) {
  840.                         if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  841.                         leadSurrogate = codePoint
  842.                         continue
  843.                     }
  844.  
  845.                     // valid surrogate pair
  846.                     codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  847.                 } else if (leadSurrogate) {
  848.                     // valid bmp char, but last char was a lead
  849.                     if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  850.                 }
  851.  
  852.                 leadSurrogate = null
  853.  
  854.                 // encode utf8
  855.                 if (codePoint < 0x80) {
  856.                     if ((units -= 1) < 0) break
  857.                     bytes.push(codePoint)
  858.                 } else if (codePoint < 0x800) {
  859.                     if ((units -= 2) < 0) break
  860.                     bytes.push(
  861.                         codePoint >> 0x6 | 0xC0,
  862.                         codePoint & 0x3F | 0x80
  863.                     )
  864.                 } else if (codePoint < 0x10000) {
  865.                     if ((units -= 3) < 0) break
  866.                     bytes.push(
  867.                         codePoint >> 0xC | 0xE0,
  868.                         codePoint >> 0x6 & 0x3F | 0x80,
  869.                         codePoint & 0x3F | 0x80
  870.                     )
  871.                 } else if (codePoint < 0x110000) {
  872.                     if ((units -= 4) < 0) break
  873.                     bytes.push(
  874.                         codePoint >> 0x12 | 0xF0,
  875.                         codePoint >> 0xC & 0x3F | 0x80,
  876.                         codePoint >> 0x6 & 0x3F | 0x80,
  877.                         codePoint & 0x3F | 0x80
  878.                     )
  879.                 } else {
  880.                     throw new Error('Invalid code point')
  881.                 }
  882.             }
  883.  
  884.             return bytes
  885.         }
  886.  
  887.         function base64ToBytes(str) {
  888.             return base64.toByteArray(base64clean(str))
  889.         }
  890.  
  891.         function blitBuffer(src, dst, offset, length) {
  892.             for (var i = 0; i < length; ++i) {
  893.                 if ((i + offset >= dst.length) || (i >= src.length)) break
  894.                 dst[i + offset] = src[i]
  895.             }
  896.             return i
  897.         }
  898.  
  899.         // Node 0.10 supports `ArrayBuffer` but lacks `ArrayBuffer.isView`
  900.         function isArrayBufferView(obj) {
  901.             return (typeof ArrayBuffer.isView === 'function') && ArrayBuffer.isView(obj)
  902.         }
  903.  
  904.         function numberIsNaN(obj) {
  905.             return obj !== obj // eslint-disable-line no-self-compare
  906.         }
  907.  
  908.     }, {
  909.         "base64-js": 16
  910.     }],
  911.     56: [function(require, module, exports) {
  912.         'use strict'
  913.  
  914.         exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes')
  915.  
  916.         var p = require('pbkdf2')
  917.         exports.pbkdf2 = p.pbkdf2
  918.         exports.pbkdf2Sync = p.pbkdf2Sync
  919.  
  920.     }, {
  921.         "pbkdf2": 112,
  922.         "randombytes": 125
  923.     }],
  924.     112: [function(require, module, exports) {
  925.  
  926.         exports.pbkdf2 = require('./lib/async')
  927.  
  928.         exports.pbkdf2Sync = require('./lib/sync')
  929.  
  930.     }, {
  931.         "./lib/async": 113,
  932.         "./lib/sync": 116
  933.     }],
  934.     113: [function(require, module, exports) {}, {}],
  935.     116: [function(require, module, exports) {}, {}],
  936.     118: [function(require, module, exports) {}, {}],
  937.     125: [function(require, module, exports) {
  938.         (function(process, global) {
  939.             'use strict'
  940.  
  941.             var Buffer = require('buffer').Buffer
  942.             var crypto = global.crypto || global.msCrypto
  943.  
  944.             if (crypto && crypto.getRandomValues) {
  945.                 module.exports = randomBytes
  946.             } else {
  947.                 module.exports = oldBrowser
  948.             }
  949.  
  950.             function randomBytes(size, cb) {
  951.                 // phantomjs needs to throw
  952.                 if (size > 65536) throw new Error('requested too many random bytes')
  953.                 // in case browserify  isn't using the Uint8Array version
  954.                 var rawBytes = new global.Uint8Array(size)
  955.  
  956.                 // This will not work in older browsers.
  957.                 // See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
  958.                 if (size > 0) { // getRandomValues fails on IE if size == 0
  959.                     crypto.getRandomValues(rawBytes)
  960.                 }
  961.  
  962.                 // XXX: phantomjs doesn't like a buffer being passed here
  963.                 var bytes = Buffer.from(rawBytes.buffer)
  964.  
  965.                 if (typeof cb === 'function') {
  966.                     return process.nextTick(function() {
  967.                         cb(null, bytes)
  968.                     })
  969.                 }
  970.  
  971.                 return bytes
  972.             }
  973.  
  974.         }).call(this, require('_process'), typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  975.     }, {
  976.         "_process": 118,
  977.         "buffer": 46
  978.     }],
  979.     156: [function(require, module, exports) {
  980.         (function(Buffer) {
  981.             'use strict';
  982.                        
  983.                         var pkcs1 = require('./pkcs1');
  984.                         var pkcs8 = require('./pkcs8');
  985.             var _ = require('./utils')._;
  986.             var utils = require('./utils');
  987.             var BigInteger = require('./jsbn.js');
  988.  
  989.                         var rsa = {};
  990.             rsa.Key = (function() {
  991.                 /**
  992.                  * RSA key constructor
  993.                  *
  994.                  * n - modulus
  995.                  * e - publicExponent
  996.                  * d - privateExponent
  997.                  * p - prime1
  998.                  * q - prime2
  999.                  * dmp1 - exponent1 -- d mod (p1)
  1000.                  * dmq1 - exponent2 -- d mod (q-1)
  1001.                  * coeff - coefficient -- (inverse of q) mod p
  1002.                  */
  1003.                 function RSAKey() {
  1004.                     this.n = null;
  1005.                     this.e = 0;
  1006.                     this.d = null;
  1007.                     this.p = null;
  1008.                     this.q = null;
  1009.                     this.dmp1 = null;
  1010.                     this.dmq1 = null;
  1011.                     this.coeff = null;
  1012.                 }
  1013.  
  1014.                 RSAKey.prototype.setOptions = function(options) {
  1015.                     var encryptionSchemeProvider = pkcs1;
  1016.                                        
  1017.                                         this.encryptionScheme = encryptionSchemeProvider.makeScheme(this, options);
  1018.                                        
  1019.                                         var pkcs1Scheme = pkcs1.makeScheme(this, options);
  1020.                                         this.encryptEngine = {
  1021.                                                 encrypt: function(buffer, usePrivate) {
  1022.                                                         var m, c;
  1023.                                                         if (usePrivate) {
  1024.                                                                 /* Type 1: zeros padding for private key encrypt */
  1025.                                                                 m = new BigInteger(pkcs1Scheme.encPad(buffer, {
  1026.                                                                         type: 1
  1027.                                                                 }));
  1028.                                                                 c = this.$doPrivate(m);
  1029.                                                         } else {
  1030.                                                                 m = new BigInteger(this.encryptionScheme.encPad(buffer));
  1031.                                                                 c = this.$doPublic(m);
  1032.                                                         }
  1033.                                                         return c.toBuffer(this.encryptedDataLength);
  1034.                                                 }.bind(this)
  1035.                                         };
  1036.                 };
  1037.  
  1038.                 /**
  1039.                  * Set the public key fields N and e from hex strings
  1040.                  * @param N
  1041.                  * @param E
  1042.                  */
  1043.                 RSAKey.prototype.setPublic = function(N, E) {
  1044.                     if (N && E && N.length > 0 && (_.isNumber(E) || E.length > 0)) {
  1045.                         this.n = new BigInteger(N);
  1046.                         this.e = _.isNumber(E) ? E : utils.get32IntFromBuffer(E, 0);
  1047.                         this.$$recalculateCache();
  1048.                     } else {
  1049.                         throw Error("Invalid RSA public key");
  1050.                     }
  1051.                 };
  1052.  
  1053.                 /**
  1054.                  * private
  1055.                  * Perform raw public operation on "x": return x^e (mod n)
  1056.                  *
  1057.                  * @param x
  1058.                  * @returns {*}
  1059.                  */
  1060.                 RSAKey.prototype.$doPublic = function(x) {
  1061.                     return x.modPowInt(this.e, this.n);
  1062.                 };
  1063.  
  1064.                 /**
  1065.                  * Return the PKCS#1 RSA encryption of buffer
  1066.                  * @param buffer {Buffer}
  1067.                  * @returns {Buffer}
  1068.                  */
  1069.                 RSAKey.prototype.encrypt = function(buffer, usePrivate) {
  1070.                     var buffers = [];
  1071.                     var results = [];
  1072.                     var bufferSize = buffer.length;
  1073.                     var buffersCount = Math.ceil(bufferSize / this.maxMessageLength) || 1; // total buffers count for encrypt
  1074.                     var dividedSize = Math.ceil(bufferSize / buffersCount || 1); // each buffer size
  1075.  
  1076.                     if (buffersCount == 1) {
  1077.                         buffers.push(buffer);
  1078.                     } else {
  1079.                         for (var bufNum = 0; bufNum < buffersCount; bufNum++) {
  1080.                             buffers.push(buffer.slice(bufNum * dividedSize, (bufNum + 1) * dividedSize));
  1081.                         }
  1082.                     }
  1083.  
  1084.                     for (var i = 0; i < buffers.length; i++) {
  1085.                         results.push(this.encryptEngine.encrypt(buffers[i], usePrivate));
  1086.                     }
  1087.  
  1088.                     return Buffer.concat(results);
  1089.                 };
  1090.  
  1091.  
  1092.                 Object.defineProperty(RSAKey.prototype, 'encryptedDataLength', {
  1093.                     get: function() {
  1094.                         return this.cache.keyByteLength;
  1095.                     }
  1096.                 });
  1097.  
  1098.                 Object.defineProperty(RSAKey.prototype, 'maxMessageLength', {
  1099.                     get: function() {
  1100.                         return this.encryptionScheme.maxMessageLength();
  1101.                     }
  1102.                 });
  1103.  
  1104.                 /**
  1105.                  * Caching key data
  1106.                  */
  1107.                 RSAKey.prototype.$$recalculateCache = function() {
  1108.                     this.cache = this.cache || {};
  1109.                     // Bit & byte length
  1110.                     this.cache.keyBitLength = this.n.bitLength();
  1111.                     this.cache.keyByteLength = (this.cache.keyBitLength + 6) >> 3;
  1112.                 };
  1113.  
  1114.                 return RSAKey;
  1115.             })();
  1116.                        
  1117.                        
  1118.  
  1119.             var RsaWrap = (function() {
  1120.                 /**
  1121.                  * @param key {string|buffer|object} Key in PEM format, or data for generate key {b: bits, e: exponent}
  1122.                  * @constructor
  1123.                  */
  1124.                 function NodeRSA(key, format, options) {
  1125.                     this.$options = {
  1126.                         signingScheme: "pkcs1",
  1127.                         signingSchemeOptions: {
  1128.                             hash: 'sha256',
  1129.                             saltLength: null
  1130.                         },
  1131.                         encryptionScheme: "pkcs1",
  1132.                         encryptionSchemeOptions: {},
  1133.                         environment: "browser",
  1134.                         rsaUtils: this
  1135.                     };
  1136.                     this.keyPair = new rsa.Key();
  1137.                 }
  1138.  
  1139.                 /**
  1140.                  * Set and validate options for key instance
  1141.                  * @param options
  1142.                  */
  1143.                 NodeRSA.prototype.setOptions = function(options) {
  1144.                     if (options.encryptionScheme) {
  1145.                                             this.$options.encryptionScheme = options.encryptionScheme.toLowerCase();
  1146.                                             this.$options.encryptionSchemeOptions = {};
  1147.                     }
  1148.  
  1149.                     this.keyPair.setOptions(this.$options);
  1150.                 };
  1151.  
  1152.                 /**
  1153.                  * Importing key
  1154.                  * @param keyData {string|buffer|Object}
  1155.                  * @param format {string}
  1156.                  */
  1157.                 NodeRSA.prototype.importKey = function(keyData, format) {
  1158.                                         pkcs8.publicImport(this.keyPair, keyData, "pem");
  1159.                 };
  1160.  
  1161.                 /**
  1162.                  * Encrypting data method with public key
  1163.                  *
  1164.                  * @param buffer {string|number|object|array|Buffer} - data for encrypting. Object and array will convert to JSON string.
  1165.                  * @param encoding {string} - optional. Encoding for output result, may be 'buffer', 'binary', 'hex' or 'base64'. Default 'buffer'.
  1166.                  * @param source_encoding {string} - optional. Encoding for given string. Default utf8.
  1167.                  * @returns {string|Buffer}
  1168.                  */
  1169.                 NodeRSA.prototype.encrypt = function(buffer, encoding, source_encoding) {
  1170.                                         try {
  1171.                         return this.keyPair.encrypt(buffer, false);
  1172.                     } catch (e) {
  1173.                         throw Error('Error during encryption. Original error: ' + e);
  1174.                     }
  1175.                 };
  1176.  
  1177.                 return NodeRSA;
  1178.             })();
  1179.  
  1180.             function createPublicKey(pem) {
  1181.                 var rsa = new RsaWrap();
  1182.                 pem = new Buffer(pem, "utf8");
  1183.                 try {
  1184.                     rsa.importKey(pem, "pkcs8-public-pem");
  1185.                 } catch (ex) {
  1186.                     throw "uuuum";
  1187.                 }
  1188.  
  1189.                 return rsa;
  1190.             }
  1191.  
  1192.             window.test = function(publicKey, verifyToken) {
  1193.                 var sharedSecret = new Uint8Array(Array.from({length: 16},function(){return Math.floor(Math.random()*256);}));
  1194.  
  1195.                 const pubKey = mcPubKeyToURsa(publicKey);
  1196.                 const encryptedSharedSecretBuffer = encrypt(sharedSecret, pubKey);
  1197.                 const encryptedVerifyTokenBuffer = encrypt(verifyToken, pubKey);
  1198.                 console.log(encryptedSharedSecretBuffer, encryptedVerifyTokenBuffer);
  1199.                 console.log(sharedSecret);
  1200.             };
  1201.  
  1202.             function mcPubKeyToURsa(mcPubKeyBuffer) {
  1203.                 let pem = "-----BEGIN PUBLIC KEY-----\n";
  1204.                 let base64PubKey = btoa(String.fromCharCode.apply(null, new Uint8Array(mcPubKeyBuffer)));
  1205.                 const maxLineLength = 65;
  1206.                 while (base64PubKey.length > 0) {
  1207.                     pem += base64PubKey.substring(0, maxLineLength) + "\n";
  1208.                     base64PubKey = base64PubKey.substring(maxLineLength);
  1209.                 }
  1210.                 pem += "-----END PUBLIC KEY-----\n";
  1211.                 return createPublicKey(pem);
  1212.             }
  1213.                        
  1214.                         function encrypt(buf, rsa) {
  1215.                             buf = new Buffer(buf, "utf8");
  1216.                             rsa.setOptions({
  1217.                                     encryptionScheme: "pkcs1"
  1218.                             });
  1219.                             return rsa.encrypt(buf);
  1220.                         }
  1221.         }).call(this, require("buffer").Buffer)
  1222.     }, {
  1223.         "./jsbn.js": 172,
  1224.         "./pkcs8": 171,
  1225.         "./utils": 178,
  1226.         "buffer": 46,
  1227.         "./pkcs1": 175
  1228.     }],
  1229.     157: [function(require, module, exports) {}, {}],
  1230.     158: [function(require, module, exports) {
  1231.         // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
  1232.  
  1233.         var errors = require('./errors');
  1234.         var types = require('./types');
  1235.  
  1236.         var Reader = require('./reader');
  1237.         var Writer = require('./writer');
  1238.  
  1239.  
  1240.         ///--- Exports
  1241.  
  1242.         module.exports = {
  1243.  
  1244.             Reader: Reader,
  1245.  
  1246.             Writer: Writer
  1247.  
  1248.         };
  1249.  
  1250.         for (var t in types) {
  1251.             if (types.hasOwnProperty(t))
  1252.                 module.exports[t] = types[t];
  1253.         }
  1254.         for (var e in errors) {
  1255.             if (errors.hasOwnProperty(e))
  1256.                 module.exports[e] = errors[e];
  1257.         }
  1258.  
  1259.     }, {
  1260.         "./errors": 157,
  1261.         "./reader": 159,
  1262.         "./types": 160,
  1263.         "./writer": 161
  1264.     }],
  1265.     159: [function(require, module, exports) {
  1266.         (function(Buffer) {
  1267.             // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
  1268.  
  1269.             var ASN1 = require('./types');
  1270.             var errors = require('./errors');
  1271.  
  1272.  
  1273.             ///--- Globals
  1274.  
  1275.             var newInvalidAsn1Error = errors.newInvalidAsn1Error;
  1276.  
  1277.  
  1278.  
  1279.             ///--- API
  1280.  
  1281.             function Reader(data) {
  1282.                 if (!data || !Buffer.isBuffer(data))
  1283.                     throw new TypeError('data must be a node Buffer');
  1284.  
  1285.                 this._buf = data;
  1286.                 this._size = data.length;
  1287.  
  1288.                 // These hold the "current" state
  1289.                 this._len = 0;
  1290.                 this._offset = 0;
  1291.             }
  1292.  
  1293.             Object.defineProperty(Reader.prototype, 'length', {
  1294.                 enumerable: true,
  1295.                 get: function() {
  1296.                     return (this._len);
  1297.                 }
  1298.             });
  1299.  
  1300.  
  1301.             /**
  1302.              * Reads a single byte and advances offset; you can pass in `true` to make this
  1303.              * a "peek" operation (i.e., get the byte, but don't advance the offset).
  1304.              *
  1305.              * @param {Boolean} peek true means don't move offset.
  1306.              * @return {Number} the next byte, null if not enough data.
  1307.              */
  1308.             Reader.prototype.readByte = function(peek) {
  1309.                 if (this._size - this._offset < 1)
  1310.                     return null;
  1311.  
  1312.                 var b = this._buf[this._offset] & 0xff;
  1313.  
  1314.                 if (!peek)
  1315.                     this._offset += 1;
  1316.  
  1317.                 return b;
  1318.             };
  1319.  
  1320.  
  1321.             Reader.prototype.peek = function() {
  1322.                 return this.readByte(true);
  1323.             };
  1324.  
  1325.  
  1326.             /**
  1327.              * Reads a (potentially) variable length off the BER buffer.  This call is
  1328.              * not really meant to be called directly, as callers have to manipulate
  1329.              * the internal buffer afterwards.
  1330.              *
  1331.              * As a result of this call, you can call `Reader.length`, until the
  1332.              * next thing called that does a readLength.
  1333.              *
  1334.              * @return {Number} the amount of offset to advance the buffer.
  1335.              * @throws {InvalidAsn1Error} on bad ASN.1
  1336.              */
  1337.             Reader.prototype.readLength = function(offset) {
  1338.                 if (offset === undefined)
  1339.                     offset = this._offset;
  1340.  
  1341.                 if (offset >= this._size)
  1342.                     return null;
  1343.  
  1344.                 var lenB = this._buf[offset++] & 0xff;
  1345.                 if (lenB === null)
  1346.                     return null;
  1347.  
  1348.                 if ((lenB & 0x80) == 0x80) {
  1349.                     lenB &= 0x7f;
  1350.  
  1351.                     if (lenB == 0)
  1352.                         throw newInvalidAsn1Error('Indefinite length not supported');
  1353.  
  1354.                     if (lenB > 4)
  1355.                         throw newInvalidAsn1Error('encoding too long');
  1356.  
  1357.                     if (this._size - offset < lenB)
  1358.                         return null;
  1359.  
  1360.                     this._len = 0;
  1361.                     for (var i = 0; i < lenB; i++)
  1362.                         this._len = (this._len << 8) + (this._buf[offset++] & 0xff);
  1363.  
  1364.                 } else {
  1365.                     // Wasn't a variable length
  1366.                     this._len = lenB;
  1367.                 }
  1368.  
  1369.                 return offset;
  1370.             };
  1371.  
  1372.  
  1373.             /**
  1374.              * Parses the next sequence in this BER buffer.
  1375.              *
  1376.              * To get the length of the sequence, call `Reader.length`.
  1377.              *
  1378.              * @return {Number} the sequence's tag.
  1379.              */
  1380.             Reader.prototype.readSequence = function(tag) {
  1381.                 var seq = this.peek();
  1382.                 if (seq === null)
  1383.                     return null;
  1384.                 if (tag !== undefined && tag !== seq)
  1385.                     throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) +
  1386.                         ': got 0x' + seq.toString(16));
  1387.  
  1388.                 var o = this.readLength(this._offset + 1); // stored in `length`
  1389.                 if (o === null)
  1390.                     return null;
  1391.  
  1392.                 this._offset = o;
  1393.                 return seq;
  1394.             };
  1395.  
  1396.  
  1397.  
  1398.             Reader.prototype.readString = function(tag, retbuf) {
  1399.                 if (!tag)
  1400.                     tag = ASN1.OctetString;
  1401.  
  1402.                 var b = this.peek();
  1403.                 if (b === null)
  1404.                     return null;
  1405.  
  1406.                 if (b !== tag)
  1407.                     throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) +
  1408.                         ': got 0x' + b.toString(16));
  1409.  
  1410.                 var o = this.readLength(this._offset + 1); // stored in `length`
  1411.  
  1412.                 if (o === null)
  1413.                     return null;
  1414.  
  1415.                 if (this.length > this._size - o)
  1416.                     return null;
  1417.  
  1418.                 this._offset = o;
  1419.  
  1420.                 if (this.length === 0)
  1421.                     return retbuf ? new Buffer(0) : '';
  1422.  
  1423.                 var str = this._buf.slice(this._offset, this._offset + this.length);
  1424.                 this._offset += this.length;
  1425.  
  1426.                 return retbuf ? str : str.toString('utf8');
  1427.             };
  1428.  
  1429.             Reader.prototype.readOID = function(tag) {
  1430.                 if (!tag)
  1431.                     tag = ASN1.OID;
  1432.  
  1433.                 var b = this.readString(tag, true);
  1434.                 if (b === null)
  1435.                     return null;
  1436.  
  1437.                 var values = [];
  1438.                 var value = 0;
  1439.  
  1440.                 for (var i = 0; i < b.length; i++) {
  1441.                     var byte = b[i] & 0xff;
  1442.  
  1443.                     value <<= 7;
  1444.                     value += byte & 0x7f;
  1445.                     if ((byte & 0x80) == 0) {
  1446.                         values.push(value);
  1447.                         value = 0;
  1448.                     }
  1449.                 }
  1450.  
  1451.                 value = values.shift();
  1452.                 values.unshift(value % 40);
  1453.                 values.unshift((value / 40) >> 0);
  1454.  
  1455.                 return values.join('.');
  1456.             };
  1457.  
  1458.  
  1459.             ///--- Exported API
  1460.  
  1461.             module.exports = Reader;
  1462.  
  1463.         }).call(this, require("buffer").Buffer)
  1464.     }, {
  1465.         "./errors": 157,
  1466.         "./types": 160,
  1467.         "buffer": 46
  1468.     }],
  1469.     160: [function(require, module, exports) {
  1470.         // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
  1471.  
  1472.  
  1473.         module.exports = {
  1474.             EOC: 0,
  1475.             Boolean: 1,
  1476.             Integer: 2,
  1477.             BitString: 3,
  1478.             OctetString: 4,
  1479.             Null: 5,
  1480.             OID: 6,
  1481.             ObjectDescriptor: 7,
  1482.             External: 8,
  1483.             Real: 9, // float
  1484.             Enumeration: 10,
  1485.             PDV: 11,
  1486.             Utf8String: 12,
  1487.             RelativeOID: 13,
  1488.             Sequence: 16,
  1489.             Set: 17,
  1490.             NumericString: 18,
  1491.             PrintableString: 19,
  1492.             T61String: 20,
  1493.             VideotexString: 21,
  1494.             IA5String: 22,
  1495.             UTCTime: 23,
  1496.             GeneralizedTime: 24,
  1497.             GraphicString: 25,
  1498.             VisibleString: 26,
  1499.             GeneralString: 28,
  1500.             UniversalString: 29,
  1501.             CharacterString: 30,
  1502.             BMPString: 31,
  1503.             Constructor: 32,
  1504.             Context: 128
  1505.         };
  1506.  
  1507.     }, {}],
  1508.     161: [function(require, module, exports) {}, {}],
  1509.     162: [function(require, module, exports) {
  1510.         // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
  1511.  
  1512.         // If you have no idea what ASN.1 or BER is, see this:
  1513.         // ftp://ftp.rsa.com/pub/pkcs/ascii/layman.asc
  1514.  
  1515.         var Ber = require('./ber/index');
  1516.  
  1517.  
  1518.  
  1519.         ///--- Exported API
  1520.  
  1521.         module.exports = {
  1522.  
  1523.             Ber: Ber,
  1524.  
  1525.             BerReader: Ber.Reader,
  1526.  
  1527.             BerWriter: Ber.Writer
  1528.  
  1529.         };
  1530.  
  1531.     }, {
  1532.         "./ber/index": 158
  1533.     }],
  1534.     171: [function(require, module, exports) {
  1535.         (function(Buffer) {
  1536.             var ber = require('asn1').Ber;
  1537.             var _ = require('../utils')._;
  1538.             var PUBLIC_RSA_OID = '1.2.840.113549.1.1.1';
  1539.  
  1540.             module.exports = {
  1541.                 publicImport: function(key, data, options) {
  1542.                     options = options || {};
  1543.                     var buffer;
  1544.  
  1545.                     if (options.type !== 'der') {
  1546.                         if (Buffer.isBuffer(data)) {
  1547.                             data = data.toString('utf8');
  1548.                         }
  1549.  
  1550.                         if (_.isString(data)) {
  1551.                             var pem = data.replace('-----BEGIN PUBLIC KEY-----', '')
  1552.                                 .replace('-----END PUBLIC KEY-----', '')
  1553.                                 .replace(/\s+|\n\r|\n|\r$/gm, '');
  1554.                             buffer = new Buffer(pem, 'base64');
  1555.                         }
  1556.                     } else if (Buffer.isBuffer(data)) {
  1557.                         buffer = data;
  1558.                     } else {
  1559.                         throw Error('Unsupported key format');
  1560.                     }
  1561.  
  1562.                     var reader = new ber.Reader(buffer);
  1563.                     reader.readSequence();
  1564.                     var header = new ber.Reader(reader.readString(0x30, true));
  1565.  
  1566.                     if (header.readOID(0x06, true) !== PUBLIC_RSA_OID) {
  1567.                         throw Error('Invalid Public key format');
  1568.                     }
  1569.  
  1570.                     var body = new ber.Reader(reader.readString(0x03, true));
  1571.                     body.readByte();
  1572.                     body.readSequence();
  1573.                     key.setPublic(
  1574.                         body.readString(0x02, true), // modulus
  1575.                         body.readString(0x02, true) // publicExponent
  1576.                     );
  1577.                 }
  1578.             };
  1579.  
  1580.         }).call(this, require("buffer").Buffer)
  1581.     }, {
  1582.                 "../utils": 178,
  1583.         "asn1": 162,
  1584.         "buffer": 46
  1585.     }],
  1586.     172: [function(require, module, exports) {
  1587.         (function(Buffer) {
  1588.             /*
  1589.              * Basic JavaScript BN library - subset useful for RSA encryption.
  1590.              *
  1591.              * Copyright (c) 2003-2005  Tom Wu
  1592.              * All Rights Reserved.
  1593.              *
  1594.              * Permission is hereby granted, free of charge, to any person obtaining
  1595.              * a copy of this software and associated documentation files (the
  1596.              * "Software"), to deal in the Software without restriction, including
  1597.              * without limitation the rights to use, copy, modify, merge, publish,
  1598.              * distribute, sublicense, and/or sell copies of the Software, and to
  1599.              * permit persons to whom the Software is furnished to do so, subject to
  1600.              * the following conditions:
  1601.              *
  1602.              * The above copyright notice and this permission notice shall be
  1603.              * included in all copies or substantial portions of the Software.
  1604.              *
  1605.              * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  1606.              * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  1607.              * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  1608.              *
  1609.              * IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  1610.              * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
  1611.              * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
  1612.              * THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
  1613.              * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1614.              *
  1615.              * In addition, the following condition applies:
  1616.              *
  1617.              * All redistributions must retain an intact copy of this copyright notice
  1618.              * and disclaimer.
  1619.              */
  1620.  
  1621.             /*
  1622.              * Added Node.js Buffers support
  1623.              * 2014 rzcoder
  1624.              */
  1625.  
  1626.             var _ = require('../utils')._;
  1627.  
  1628.             // Bits per digit
  1629.             var dbits;
  1630.  
  1631.             // JavaScript engine analysis
  1632.             var canary = 0xdeadbeefcafe;
  1633.             var j_lm = ((canary & 0xffffff) == 0xefcafe);
  1634.  
  1635.             // (public) Constructor
  1636.             function BigInteger(a, b) {
  1637.                 if (a != null) {
  1638.                     if ("number" == typeof a) {
  1639.                         this.fromNumber(a, b);
  1640.                     } else if (Buffer.isBuffer(a)) {
  1641.                         this.fromBuffer(a);
  1642.                     } else if (b == null && "string" != typeof a) {
  1643.                         this.fromByteArray(a);
  1644.                     } else {
  1645.                         this.fromString(a, b);
  1646.                     }
  1647.                 }
  1648.             }
  1649.  
  1650.             // return new, unset BigInteger
  1651.             function nbi() {
  1652.                 return new BigInteger(null);
  1653.             }
  1654.  
  1655.             // am: Compute w_j += (x*this_i), propagate carries,
  1656.             // c is initial carry, returns final carry.
  1657.             // c < 3*dvalue, x < 2*dvalue, this_i < dvalue
  1658.             // We need to select the fastest one that works in this environment.
  1659.                        
  1660.                         // Alternately, set max digit bits to 28 since some
  1661.             // browsers slow down when dealing with 32-bit numbers.
  1662.             function am3(i, x, w, j, c, n) {
  1663.                 var xl = x & 0x3fff,
  1664.                     xh = x >> 14;
  1665.                 while (--n >= 0) {
  1666.                     var l = this[i] & 0x3fff;
  1667.                     var h = this[i++] >> 14;
  1668.                     var m = xh * l + h * xl;
  1669.                     l = xl * l + ((m & 0x3fff) << 14) + w[j] + c;
  1670.                     c = (l >> 28) + (m >> 14) + xh * h;
  1671.                     w[j++] = l & 0xfffffff;
  1672.                 }
  1673.                 return c;
  1674.             }
  1675.  
  1676.             // For node.js, we pick am3 with max dbits to 28.
  1677.             BigInteger.prototype.am = am3;
  1678.             dbits = 28;
  1679.  
  1680.             BigInteger.prototype.DB = dbits;
  1681.             BigInteger.prototype.DM = ((1 << dbits) - 1);
  1682.             BigInteger.prototype.DV = (1 << dbits);
  1683.  
  1684.             var BI_FP = 52;
  1685.             BigInteger.prototype.FV = Math.pow(2, BI_FP);
  1686.             BigInteger.prototype.F1 = BI_FP - dbits;
  1687.             BigInteger.prototype.F2 = 2 * dbits - BI_FP;
  1688.  
  1689.             // Digit conversions
  1690.             var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
  1691.             var BI_RC = new Array();
  1692.             var rr, vv;
  1693.             rr = "0".charCodeAt(0);
  1694.             for (vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
  1695.             rr = "a".charCodeAt(0);
  1696.             for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
  1697.             rr = "A".charCodeAt(0);
  1698.             for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
  1699.  
  1700.  
  1701.             // (protected) copy this to r
  1702.             function bnpCopyTo(r) {
  1703.                 for (var i = this.t - 1; i >= 0; --i) r[i] = this[i];
  1704.                 r.t = this.t;
  1705.                 r.s = this.s;
  1706.             }
  1707.  
  1708.             // (protected) set from integer value x, -DV <= x < DV
  1709.             function bnpFromInt(x) {
  1710.                 this.t = 1;
  1711.                 this.s = (x < 0) ? -1 : 0;
  1712.                 if (x > 0) this[0] = x;
  1713.                 else if (x < -1) this[0] = x + DV;
  1714.                 else this.t = 0;
  1715.             }
  1716.  
  1717.             // return bigint initialized to value
  1718.             function nbv(i) {
  1719.                 var r = nbi();
  1720.                 r.fromInt(i);
  1721.                 return r;
  1722.             }
  1723.  
  1724.             // (protected) set from string and radix
  1725.             function bnpFromString(data, radix, unsigned) {
  1726.                 var k;
  1727.                 switch (radix) {
  1728.                     case 2:
  1729.                         k = 1;
  1730.                         break;
  1731.                     case 4:
  1732.                         k = 2;
  1733.                         break;
  1734.                     case 8:
  1735.                         k = 3;
  1736.                         break;
  1737.                     case 16:
  1738.                         k = 4;
  1739.                         break;
  1740.                     case 32:
  1741.                         k = 5;
  1742.                         break;
  1743.                     case 256:
  1744.                         k = 8;
  1745.                         break;
  1746.                     default:
  1747.                         this.fromRadix(data, radix);
  1748.                         return;
  1749.                 }
  1750.  
  1751.                 this.t = 0;
  1752.                 this.s = 0;
  1753.  
  1754.                 var i = data.length;
  1755.                 var mi = false;
  1756.                 var sh = 0;
  1757.  
  1758.                 while (--i >= 0) {
  1759.                     var x = (k == 8) ? data[i] & 0xff : intAt(data, i);
  1760.                     if (x < 0) {
  1761.                         if (data.charAt(i) == "-") mi = true;
  1762.                         continue;
  1763.                     }
  1764.                     mi = false;
  1765.                     if (sh === 0)
  1766.                         this[this.t++] = x;
  1767.                     else if (sh + k > this.DB) {
  1768.                         this[this.t - 1] |= (x & ((1 << (this.DB - sh)) - 1)) << sh;
  1769.                         this[this.t++] = (x >> (this.DB - sh));
  1770.                     } else
  1771.                         this[this.t - 1] |= x << sh;
  1772.                     sh += k;
  1773.                     if (sh >= this.DB) sh -= this.DB;
  1774.                 }
  1775.                 if ((!unsigned) && k == 8 && (data[0] & 0x80) != 0) {
  1776.                     this.s = -1;
  1777.                     if (sh > 0) this[this.t - 1] |= ((1 << (this.DB - sh)) - 1) << sh;
  1778.                 }
  1779.                 this.clamp();
  1780.                 if (mi) BigInteger.ZERO.subTo(this, this);
  1781.             }
  1782.  
  1783.  
  1784.             function bnpFromBuffer(a) {
  1785.                 this.fromString(a, 256, true)
  1786.             }
  1787.  
  1788.             // (protected) clamp off excess high words
  1789.             function bnpClamp() {
  1790.                 var c = this.s & this.DM;
  1791.                 while (this.t > 0 && this[this.t - 1] == c) --this.t;
  1792.             }
  1793.  
  1794.             // (public) |this|
  1795.             function bnAbs() {
  1796.                 return (this.s < 0) ? this.negate() : this;
  1797.             }
  1798.  
  1799.             // (public) return + if this > a, - if this < a, 0 if equal
  1800.             function bnCompareTo(a) {
  1801.                 var r = this.s - a.s;
  1802.                 if (r != 0) return r;
  1803.                 var i = this.t;
  1804.                 r = i - a.t;
  1805.                 if (r != 0) return (this.s < 0) ? -r : r;
  1806.                 while (--i >= 0)
  1807.                     if ((r = this[i] - a[i]) != 0) return r;
  1808.                 return 0;
  1809.             }
  1810.  
  1811.             // returns bit length of the integer x
  1812.             function nbits(x) {
  1813.                 var r = 1,
  1814.                     t;
  1815.                 if ((t = x >>> 16) != 0) {
  1816.                     x = t;
  1817.                     r += 16;
  1818.                 }
  1819.                 if ((t = x >> 8) != 0) {
  1820.                     x = t;
  1821.                     r += 8;
  1822.                 }
  1823.                 if ((t = x >> 4) != 0) {
  1824.                     x = t;
  1825.                     r += 4;
  1826.                 }
  1827.                 if ((t = x >> 2) != 0) {
  1828.                     x = t;
  1829.                     r += 2;
  1830.                 }
  1831.                 if ((t = x >> 1) != 0) {
  1832.                     x = t;
  1833.                     r += 1;
  1834.                 }
  1835.                 return r;
  1836.             }
  1837.  
  1838.             // (public) return the number of bits in "this"
  1839.             function bnBitLength() {
  1840.                 if (this.t <= 0) return 0;
  1841.                 return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ (this.s & this.DM));
  1842.             }
  1843.  
  1844.             // (protected) r = this << n*DB
  1845.             function bnpDLShiftTo(n, r) {
  1846.                 var i;
  1847.                 for (i = this.t - 1; i >= 0; --i) r[i + n] = this[i];
  1848.                 for (i = n - 1; i >= 0; --i) r[i] = 0;
  1849.                 r.t = this.t + n;
  1850.                 r.s = this.s;
  1851.             }
  1852.  
  1853.             // (protected) r = this >> n*DB
  1854.             function bnpDRShiftTo(n, r) {
  1855.                 for (var i = n; i < this.t; ++i) r[i - n] = this[i];
  1856.                 r.t = Math.max(this.t - n, 0);
  1857.                 r.s = this.s;
  1858.             }
  1859.  
  1860.             // (protected) r = this << n
  1861.             function bnpLShiftTo(n, r) {
  1862.                 var bs = n % this.DB;
  1863.                 var cbs = this.DB - bs;
  1864.                 var bm = (1 << cbs) - 1;
  1865.                 var ds = Math.floor(n / this.DB),
  1866.                     c = (this.s << bs) & this.DM,
  1867.                     i;
  1868.                 for (i = this.t - 1; i >= 0; --i) {
  1869.                     r[i + ds + 1] = (this[i] >> cbs) | c;
  1870.                     c = (this[i] & bm) << bs;
  1871.                 }
  1872.                 for (i = ds - 1; i >= 0; --i) r[i] = 0;
  1873.                 r[ds] = c;
  1874.                 r.t = this.t + ds + 1;
  1875.                 r.s = this.s;
  1876.                 r.clamp();
  1877.             }
  1878.  
  1879.             // (protected) r = this >> n
  1880.             function bnpRShiftTo(n, r) {
  1881.                 r.s = this.s;
  1882.                 var ds = Math.floor(n / this.DB);
  1883.                 if (ds >= this.t) {
  1884.                     r.t = 0;
  1885.                     return;
  1886.                 }
  1887.                 var bs = n % this.DB;
  1888.                 var cbs = this.DB - bs;
  1889.                 var bm = (1 << bs) - 1;
  1890.                 r[0] = this[ds] >> bs;
  1891.                 for (var i = ds + 1; i < this.t; ++i) {
  1892.                     r[i - ds - 1] |= (this[i] & bm) << cbs;
  1893.                     r[i - ds] = this[i] >> bs;
  1894.                 }
  1895.                 if (bs > 0) r[this.t - ds - 1] |= (this.s & bm) << cbs;
  1896.                 r.t = this.t - ds;
  1897.                 r.clamp();
  1898.             }
  1899.  
  1900.             // (protected) r = this - a
  1901.             function bnpSubTo(a, r) {
  1902.                 var i = 0,
  1903.                     c = 0,
  1904.                     m = Math.min(a.t, this.t);
  1905.                 while (i < m) {
  1906.                     c += this[i] - a[i];
  1907.                     r[i++] = c & this.DM;
  1908.                     c >>= this.DB;
  1909.                 }
  1910.                 if (a.t < this.t) {
  1911.                     c -= a.s;
  1912.                     while (i < this.t) {
  1913.                         c += this[i];
  1914.                         r[i++] = c & this.DM;
  1915.                         c >>= this.DB;
  1916.                     }
  1917.                     c += this.s;
  1918.                 } else {
  1919.                     c += this.s;
  1920.                     while (i < a.t) {
  1921.                         c -= a[i];
  1922.                         r[i++] = c & this.DM;
  1923.                         c >>= this.DB;
  1924.                     }
  1925.                     c -= a.s;
  1926.                 }
  1927.                 r.s = (c < 0) ? -1 : 0;
  1928.                 if (c < -1) r[i++] = this.DV + c;
  1929.                 else if (c > 0) r[i++] = c;
  1930.                 r.t = i;
  1931.                 r.clamp();
  1932.             }
  1933.  
  1934.             // (protected) r = this * a, r != this,a (HAC 14.12)
  1935.             // "this" should be the larger one if appropriate.
  1936.             function bnpMultiplyTo(a, r) {
  1937.                 var x = this.abs(),
  1938.                     y = a.abs();
  1939.                 var i = x.t;
  1940.                 r.t = i + y.t;
  1941.                 while (--i >= 0) r[i] = 0;
  1942.                 for (i = 0; i < y.t; ++i) r[i + x.t] = x.am(0, y[i], r, i, 0, x.t);
  1943.                 r.s = 0;
  1944.                 r.clamp();
  1945.                 if (this.s != a.s) BigInteger.ZERO.subTo(r, r);
  1946.             }
  1947.  
  1948.             // (protected) r = this^2, r != this (HAC 14.16)
  1949.             function bnpSquareTo(r) {
  1950.                 var x = this.abs();
  1951.                 var i = r.t = 2 * x.t;
  1952.                 while (--i >= 0) r[i] = 0;
  1953.                 for (i = 0; i < x.t - 1; ++i) {
  1954.                     var c = x.am(i, x[i], r, 2 * i, 0, 1);
  1955.                     if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) {
  1956.                         r[i + x.t] -= x.DV;
  1957.                         r[i + x.t + 1] = 1;
  1958.                     }
  1959.                 }
  1960.                 if (r.t > 0) r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1);
  1961.                 r.s = 0;
  1962.                 r.clamp();
  1963.             }
  1964.  
  1965.             // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
  1966.             // r != q, this != m.  q or r may be null.
  1967.             function bnpDivRemTo(m, q, r) {
  1968.                 var pm = m.abs();
  1969.                 if (pm.t <= 0) return;
  1970.                 var pt = this.abs();
  1971.                 if (pt.t < pm.t) {
  1972.                     if (q != null) q.fromInt(0);
  1973.                     if (r != null) this.copyTo(r);
  1974.                     return;
  1975.                 }
  1976.                 if (r == null) r = nbi();
  1977.                 var y = nbi(),
  1978.                     ts = this.s,
  1979.                     ms = m.s;
  1980.                 var nsh = this.DB - nbits(pm[pm.t - 1]); // normalize modulus
  1981.                 if (nsh > 0) {
  1982.                     pm.lShiftTo(nsh, y);
  1983.                     pt.lShiftTo(nsh, r);
  1984.                 } else {
  1985.                     pm.copyTo(y);
  1986.                     pt.copyTo(r);
  1987.                 }
  1988.                 var ys = y.t;
  1989.                 var y0 = y[ys - 1];
  1990.                 if (y0 === 0) return;
  1991.                 var yt = y0 * (1 << this.F1) + ((ys > 1) ? y[ys - 2] >> this.F2 : 0);
  1992.                 var d1 = this.FV / yt,
  1993.                     d2 = (1 << this.F1) / yt,
  1994.                     e = 1 << this.F2;
  1995.                 var i = r.t,
  1996.                     j = i - ys,
  1997.                     t = (q == null) ? nbi() : q;
  1998.                 y.dlShiftTo(j, t);
  1999.                 if (r.compareTo(t) >= 0) {
  2000.                     r[r.t++] = 1;
  2001.                     r.subTo(t, r);
  2002.                 }
  2003.                 BigInteger.ONE.dlShiftTo(ys, t);
  2004.                 t.subTo(y, y); // "negative" y so we can replace sub with am later
  2005.                 while (y.t < ys) y[y.t++] = 0;
  2006.                 while (--j >= 0) {
  2007.                     // Estimate quotient digit
  2008.                     var qd = (r[--i] == y0) ? this.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2);
  2009.                     if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) { // Try it out
  2010.                         y.dlShiftTo(j, t);
  2011.                         r.subTo(t, r);
  2012.                         while (r[i] < --qd) r.subTo(t, r);
  2013.                     }
  2014.                 }
  2015.                 if (q != null) {
  2016.                     r.drShiftTo(ys, q);
  2017.                     if (ts != ms) BigInteger.ZERO.subTo(q, q);
  2018.                 }
  2019.                 r.t = ys;
  2020.                 r.clamp();
  2021.                 if (nsh > 0) r.rShiftTo(nsh, r); // Denormalize remainder
  2022.                 if (ts < 0) BigInteger.ZERO.subTo(r, r);
  2023.             }
  2024.  
  2025.  
  2026.             // (protected) return "-1/this % 2^DB"; useful for Mont. reduction
  2027.             // justification:
  2028.             //         xy == 1 (mod m)
  2029.             //         xy =  1+km
  2030.             //   xy(2-xy) = (1+km)(1-km)
  2031.             // x[y(2-xy)] = 1-k^2m^2
  2032.             // x[y(2-xy)] == 1 (mod m^2)
  2033.             // if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
  2034.             // should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
  2035.             // JS multiply "overflows" differently from C/C++, so care is needed here.
  2036.             function bnpInvDigit() {
  2037.                 if (this.t < 1) return 0;
  2038.                 var x = this[0];
  2039.                 if ((x & 1) === 0) return 0;
  2040.                 var y = x & 3; // y == 1/x mod 2^2
  2041.                 y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4
  2042.                 y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8
  2043.                 y = (y * (2 - (((x & 0xffff) * y) & 0xffff))) & 0xffff; // y == 1/x mod 2^16
  2044.                 // last step - calculate inverse mod DV directly;
  2045.                 // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
  2046.                 y = (y * (2 - x * y % this.DV)) % this.DV; // y == 1/x mod 2^dbits
  2047.                 // we really want the negative inverse, and -DV < y < DV
  2048.                 return (y > 0) ? this.DV - y : -y;
  2049.             }
  2050.  
  2051.             // Montgomery reduction
  2052.             function Montgomery(m) {
  2053.                 this.m = m;
  2054.                 this.mp = m.invDigit();
  2055.                 this.mpl = this.mp & 0x7fff;
  2056.                 this.mph = this.mp >> 15;
  2057.                 this.um = (1 << (m.DB - 15)) - 1;
  2058.                 this.mt2 = 2 * m.t;
  2059.             }
  2060.  
  2061.             // xR mod m
  2062.             function montConvert(x) {
  2063.                 var r = nbi();
  2064.                 x.abs().dlShiftTo(this.m.t, r);
  2065.                 r.divRemTo(this.m, null, r);
  2066.                 if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r, r);
  2067.                 return r;
  2068.             }
  2069.  
  2070.             // x/R mod m
  2071.             function montRevert(x) {
  2072.                 var r = nbi();
  2073.                 x.copyTo(r);
  2074.                 this.reduce(r);
  2075.                 return r;
  2076.             }
  2077.  
  2078.             // x = x/R mod m (HAC 14.32)
  2079.             function montReduce(x) {
  2080.                 while (x.t <= this.mt2) // pad x so am has enough room later
  2081.                     x[x.t++] = 0;
  2082.                 for (var i = 0; i < this.m.t; ++i) {
  2083.                     // faster way of calculating u0 = x[i]*mp mod DV
  2084.                     var j = x[i] & 0x7fff;
  2085.                     var u0 = (j * this.mpl + (((j * this.mph + (x[i] >> 15) * this.mpl) & this.um) << 15)) & x.DM;
  2086.                     // use am to combine the multiply-shift-add into one call
  2087.                     j = i + this.m.t;
  2088.                     x[j] += this.m.am(0, u0, x, i, 0, this.m.t);
  2089.                     // propagate carry
  2090.                     while (x[j] >= x.DV) {
  2091.                         x[j] -= x.DV;
  2092.                         x[++j]++;
  2093.                     }
  2094.                 }
  2095.                 x.clamp();
  2096.                 x.drShiftTo(this.m.t, x);
  2097.                 if (x.compareTo(this.m) >= 0) x.subTo(this.m, x);
  2098.             }
  2099.  
  2100.             // r = "x^2/R mod m"; x != r
  2101.             function montSqrTo(x, r) {
  2102.                 x.squareTo(r);
  2103.                 this.reduce(r);
  2104.             }
  2105.  
  2106.             // r = "xy/R mod m"; x,y != r
  2107.             function montMulTo(x, y, r) {
  2108.                 x.multiplyTo(y, r);
  2109.                 this.reduce(r);
  2110.             }
  2111.  
  2112.             Montgomery.prototype.convert = montConvert;
  2113.             Montgomery.prototype.revert = montRevert;
  2114.             Montgomery.prototype.reduce = montReduce;
  2115.             Montgomery.prototype.mulTo = montMulTo;
  2116.             Montgomery.prototype.sqrTo = montSqrTo;
  2117.  
  2118.             // (protected) true iff this is even
  2119.             function bnpIsEven() {
  2120.                 return ((this.t > 0) ? (this[0] & 1) : this.s) === 0;
  2121.             }
  2122.  
  2123.             // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
  2124.             function bnpExp(e, z) {
  2125.                 if (e > 0xffffffff || e < 1) return BigInteger.ONE;
  2126.                 var r = nbi(),
  2127.                     r2 = nbi(),
  2128.                     g = z.convert(this),
  2129.                     i = nbits(e) - 1;
  2130.                 g.copyTo(r);
  2131.                 while (--i >= 0) {
  2132.                     z.sqrTo(r, r2);
  2133.                     if ((e & (1 << i)) > 0) z.mulTo(r2, g, r);
  2134.                     else {
  2135.                         var t = r;
  2136.                         r = r2;
  2137.                         r2 = t;
  2138.                     }
  2139.                 }
  2140.                 return z.revert(r);
  2141.             }
  2142.  
  2143.             // (public) this^e % m, 0 <= e < 2^32
  2144.             function bnModPowInt(e, m) {
  2145.                 var z;
  2146.                 if (e < 256 || m.isEven()) z = new Classic(m);
  2147.                 else z = new Montgomery(m);
  2148.                 return this.exp(e, z);
  2149.             }
  2150.  
  2151.             // Copyright (c) 2005-2009  Tom Wu
  2152.             // All Rights Reserved.
  2153.             // See "LICENSE" for details.
  2154.  
  2155.             // Extended JavaScript BN functions, required for RSA private ops.
  2156.  
  2157.             // Version 1.1: new BigInteger("0", 10) returns "proper" zero
  2158.             // Version 1.2: square() API, isProbablePrime fix
  2159.  
  2160.             //(public) convert to bigendian byte array
  2161.             function bnToByteArray() {
  2162.                 var i = this.t,
  2163.                     r = new Array();
  2164.                 r[0] = this.s;
  2165.                 var p = this.DB - (i * this.DB) % 8,
  2166.                     d, k = 0;
  2167.                 if (i-- > 0) {
  2168.                     if (p < this.DB && (d = this[i] >> p) != (this.s & this.DM) >> p)
  2169.                         r[k++] = d | (this.s << (this.DB - p));
  2170.                     while (i >= 0) {
  2171.                         if (p < 8) {
  2172.                             d = (this[i] & ((1 << p) - 1)) << (8 - p);
  2173.                             d |= this[--i] >> (p += this.DB - 8);
  2174.                         } else {
  2175.                             d = (this[i] >> (p -= 8)) & 0xff;
  2176.                             if (p <= 0) {
  2177.                                 p += this.DB;
  2178.                                 --i;
  2179.                             }
  2180.                         }
  2181.                         if ((d & 0x80) != 0) d |= -256;
  2182.                         if (k === 0 && (this.s & 0x80) != (d & 0x80)) ++k;
  2183.                         if (k > 0 || d != this.s) r[k++] = d;
  2184.                     }
  2185.                 }
  2186.                 return r;
  2187.             }
  2188.  
  2189.             /**
  2190.              * return Buffer object
  2191.              * @param trim {boolean} slice buffer if first element == 0
  2192.              * @returns {Buffer}
  2193.              */
  2194.             function bnToBuffer(trimOrSize) {
  2195.                 var res = new Buffer(this.toByteArray());
  2196.                 if (trimOrSize === true && res[0] === 0) {
  2197.                     res = res.slice(1);
  2198.                 } else if (_.isNumber(trimOrSize)) {
  2199.                     if (res.length > trimOrSize) {
  2200.                         for (var i = 0; i < res.length - trimOrSize; i++) {
  2201.                             if (res[i] !== 0) {
  2202.                                 return null;
  2203.                             }
  2204.                         }
  2205.                         return res.slice(res.length - trimOrSize);
  2206.                     } else if (res.length < trimOrSize) {
  2207.                         var padded = new Buffer(trimOrSize);
  2208.                         padded.fill(0, 0, trimOrSize - res.length);
  2209.                         res.copy(padded, trimOrSize - res.length);
  2210.                         return padded;
  2211.                     }
  2212.                 }
  2213.                 return res;
  2214.             }
  2215.  
  2216.  
  2217.             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];
  2218.             var lplim = (1 << 26) / lowprimes[lowprimes.length - 1];
  2219.  
  2220.             // protected
  2221.             BigInteger.prototype.copyTo = bnpCopyTo;
  2222.             BigInteger.prototype.fromInt = bnpFromInt;
  2223.             BigInteger.prototype.fromString = bnpFromString;
  2224.             BigInteger.prototype.fromBuffer = bnpFromBuffer;
  2225.             BigInteger.prototype.clamp = bnpClamp;
  2226.             BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
  2227.             BigInteger.prototype.drShiftTo = bnpDRShiftTo;
  2228.             BigInteger.prototype.lShiftTo = bnpLShiftTo;
  2229.             BigInteger.prototype.rShiftTo = bnpRShiftTo;
  2230.             BigInteger.prototype.subTo = bnpSubTo;
  2231.             BigInteger.prototype.multiplyTo = bnpMultiplyTo;
  2232.             BigInteger.prototype.squareTo = bnpSquareTo;
  2233.             BigInteger.prototype.divRemTo = bnpDivRemTo;
  2234.             BigInteger.prototype.invDigit = bnpInvDigit;
  2235.             BigInteger.prototype.isEven = bnpIsEven;
  2236.             BigInteger.prototype.exp = bnpExp;
  2237.  
  2238.  
  2239.             // public
  2240.                         BigInteger.prototype.bitLength = bnBitLength;
  2241.                         BigInteger.prototype.modPowInt = bnModPowInt;
  2242.                         BigInteger.prototype.abs = bnAbs;
  2243.                         BigInteger.prototype.compareTo = bnCompareTo;
  2244.                         BigInteger.prototype.toBuffer = bnToBuffer;
  2245.                         BigInteger.prototype.toByteArray = bnToByteArray;
  2246.  
  2247.             // "constants"
  2248.             BigInteger.ZERO = nbv(0);
  2249.             BigInteger.ONE = nbv(1);
  2250.  
  2251.             // JSBN-specific extension
  2252.  
  2253.             //BigInteger interfaces not implemented in jsbn:
  2254.  
  2255.             //BigInteger(int signum, byte[] magnitude)
  2256.             //double doubleValue()
  2257.             //float floatValue()
  2258.             //int hashCode()
  2259.             //long longValue()
  2260.             //static BigInteger valueOf(long val)
  2261.  
  2262.             module.exports = BigInteger;
  2263.         }).call(this, require("buffer").Buffer)
  2264.     }, {
  2265.         "../utils": 178,
  2266.         "buffer": 46
  2267.     }],
  2268.     174: [function(require, module, exports) {}, {}],
  2269.     175: [function(require, module, exports) {
  2270.         (function(Buffer) {
  2271.             /**
  2272.              * PKCS1 padding and signature scheme
  2273.              */
  2274.  
  2275.             var BigInteger = require('../libs/jsbn');
  2276.             var crypt = require('crypto');
  2277.             var SIGN_INFO_HEAD = {
  2278.                 md2: new Buffer('3020300c06082a864886f70d020205000410', 'hex'),
  2279.                 md5: new Buffer('3020300c06082a864886f70d020505000410', 'hex'),
  2280.                 sha1: new Buffer('3021300906052b0e03021a05000414', 'hex'),
  2281.                 sha224: new Buffer('302d300d06096086480165030402040500041c', 'hex'),
  2282.                 sha256: new Buffer('3031300d060960864801650304020105000420', 'hex'),
  2283.                 sha384: new Buffer('3041300d060960864801650304020205000430', 'hex'),
  2284.                 sha512: new Buffer('3051300d060960864801650304020305000440', 'hex'),
  2285.                 ripemd160: new Buffer('3021300906052b2403020105000414', 'hex'),
  2286.                 rmd160: new Buffer('3021300906052b2403020105000414', 'hex')
  2287.             };
  2288.  
  2289.             var SIGN_ALG_TO_HASH_ALIASES = {
  2290.                 'ripemd160': 'rmd160'
  2291.             };
  2292.  
  2293.             var DEFAULT_HASH_FUNCTION = 'sha256';
  2294.  
  2295.             module.exports = {
  2296.                 isEncryption: true,
  2297.                 isSignature: true
  2298.             };
  2299.  
  2300.             module.exports.makeScheme = function(key, options) {
  2301.                 function Scheme(key, options) {
  2302.                     this.key = key;
  2303.                     this.options = options;
  2304.                 }
  2305.  
  2306.                 Scheme.prototype.maxMessageLength = function() {
  2307.                     if (this.options.encryptionSchemeOptions && this.options.encryptionSchemeOptions.padding == 3) {
  2308.                         return this.key.encryptedDataLength;
  2309.                     }
  2310.                     return this.key.encryptedDataLength - 11;
  2311.                 };
  2312.  
  2313.                 /**
  2314.                  * Pad input Buffer to encryptedDataLength bytes, and return new Buffer
  2315.                  * alg: PKCS#1
  2316.                  * @param buffer
  2317.                  * @returns {Buffer}
  2318.                  */
  2319.                 Scheme.prototype.encPad = function(buffer, options) {
  2320.                     options = options || {};
  2321.                     var filled;
  2322.                     if (buffer.length > this.key.maxMessageLength) {
  2323.                         throw new Error("Message too long for RSA (n=" + this.key.encryptedDataLength + ", l=" + buffer.length + ")");
  2324.                     }
  2325.                     if (this.options.encryptionSchemeOptions && this.options.encryptionSchemeOptions.padding == 3) {
  2326.                         //RSA_NO_PADDING treated like JAVA left pad with zero character
  2327.                         return this.pkcs0pad(buffer);
  2328.                     }
  2329.  
  2330.                     /* Type 1: zeros padding for private key encrypt */
  2331.                     if (options.type === 1) {
  2332.                         filled = new Buffer(this.key.encryptedDataLength - buffer.length - 1);
  2333.                         filled.fill(0xff, 0, filled.length - 1);
  2334.                         filled[0] = 1;
  2335.                         filled[filled.length - 1] = 0;
  2336.  
  2337.                         return Buffer.concat([filled, buffer]);
  2338.                     } else {
  2339.                         /* random padding for public key encrypt */
  2340.                         filled = new Buffer(this.key.encryptedDataLength - buffer.length);
  2341.                         filled[0] = 0;
  2342.                         filled[1] = 2;
  2343.                         var rand = crypt.randomBytes(filled.length - 3);
  2344.                         for (var i = 0; i < rand.length; i++) {
  2345.                             var r = rand[i];
  2346.                             while (r === 0) { // non-zero only
  2347.                                 r = crypt.randomBytes(1)[0];
  2348.                             }
  2349.                             filled[i + 2] = r;
  2350.                         }
  2351.                         filled[filled.length - 1] = 0;
  2352.                         return Buffer.concat([filled, buffer]);
  2353.                     }
  2354.                 };
  2355.  
  2356.                 return new Scheme(key, options);
  2357.             };
  2358.  
  2359.  
  2360.  
  2361.         }).call(this, require("buffer").Buffer)
  2362.     }, {
  2363.         "../libs/jsbn": 172,
  2364.         "buffer": 46,
  2365.         "crypto": 56
  2366.     }],
  2367.     178: [function(require, module, exports) {
  2368.                 /**
  2369.                  * Trying get a 32-bit unsigned integer from the partial buffer
  2370.                  * @param buffer
  2371.                  * @param offset
  2372.                  * @returns {Number}
  2373.                  */
  2374.                 module.exports.get32IntFromBuffer = function(buffer, offset) {
  2375.                         offset = offset || 0;
  2376.                         var size = 0;
  2377.                         if ((size = buffer.length - offset) > 0) {
  2378.                                 if (size >= 4) {
  2379.                                         return buffer.readUInt32BE(offset);
  2380.                                 } else {
  2381.                                         var res = 0;
  2382.                                         for (var i = offset + size, d = 0; i > offset; i--, d += 2) {
  2383.                                                 res += buffer[i - 1] * Math.pow(16, d);
  2384.                                         }
  2385.                                         return res;
  2386.                                 }
  2387.                         } else {
  2388.                                 return NaN;
  2389.                         }
  2390.                 };
  2391.  
  2392.                 module.exports._ = {
  2393.                         isString: function(value) {
  2394.                                 return typeof value == 'string' || value instanceof String;
  2395.                         },
  2396.  
  2397.                         isNumber: function(value) {
  2398.                                 return typeof value == 'number' || !isNaN(parseFloat(value)) && isFinite(value);
  2399.                         }
  2400.                 };
  2401.     }, {}]
  2402. }, {}, [156]);
Add Comment
Please, Sign In to add comment